diff --git a/.asf.yaml b/.asf.yaml index 4e7b260a7..31267a11d 100644 --- a/.asf.yaml +++ b/.asf.yaml @@ -1,9 +1,10 @@ -# Reference: https://github.com/apache/infrastructure-asfyaml. github: description: "Apache NuttX Apps is a collection of tools, shells, network utilities, libraries, interpreters and can be used with the NuttX RTOS" homepage: https://nuttx.apache.org/ features: + # Enable issues management issues: true + # Enable project for project management boards projects: true labels: - nuttx @@ -13,22 +14,9 @@ github: - mcu - microcontroller enabled_merge_buttons: - squash: false - merge: false - rebase: true - protected_branches: - master: - required_status_checks: - strict: false -# Contexts cause hanging CI etc disable for now. -# contexts: -# - Check -# - Lint -# - Build - required_pull_request_reviews: - dismiss_stale_reviews: true - require_last_push_approval: true - required_approving_review_count: 2 - required_linear_history: true - required_signatures: false - required_conversation_resolution: true + # disable squash button: + squash: false + # disable merge button: + merge: false + # enable rebase button: + rebase: true diff --git a/.codespell-ignore-lines b/.codespell-ignore-lines deleted file mode 100644 index 5902decae..000000000 --- a/.codespell-ignore-lines +++ /dev/null @@ -1,16 +0,0 @@ - mynewt-nimble/nimble/host/services/ans/src/ble_svc_ans.c - mynewt-nimble/nimble/host/services/ans/include -#include "services/ans/ble_svc_ans.h" -#include "crypto/controlse/ccertificate.hxx" - * notifications for the ANS Unread Alert Status characteristic - object = new Controlse::CCertificate( - Controlse::CCertificate cert(se, settings->key_id); - auto certificate = Controlse::CCertificate( - * |---------- [-rw-r--r-- 15] afile.txt - g_afile.name = "afile.txt"; - "*.deh", "*.hhe", "*.seh", NULL); - MUSIC("introa"), MUSIC("runnin"), MUSIC("stalks"), MUSIC("countd"), - MUSIC("betwee"), MUSIC("doom"), MUSIC("the_da"), MUSIC("shawn"), - MUSIC("messag"), MUSIC("count2"), MUSIC("ddtbl3"), MUSIC("ampie"), - MUSIC("tense"), MUSIC("shawn3"), MUSIC("openin"), MUSIC("evil"), -/* ANS service */ diff --git a/.codespellrc b/.codespellrc deleted file mode 100644 index 743ab2a75..000000000 --- a/.codespellrc +++ /dev/null @@ -1,16 +0,0 @@ -[codespell] - -# Add complete lines to be ignored to this file. -# Example for ignoring all current occurrences of (verifiably correct) word usage: -# grep -hirw "emac" | sort | uniq >>.codespell-ignore-lines -exclude-file = .codespell-ignore-lines - -# Ignore complete files (e.g. legal text or other immutable material). -skip = - LICENSE, - examples/webpanel/content/www/xterm.min.js, - **/games/NXDoom/src/doom/d_englsh.h, - **/games/NXDoom/src/doom/d_french.h - -# Ignore words list (FTP protocol commands and technical terms) -ignore-words-list = ALLO, ARCHTYPE, parm, shiftIn diff --git a/.github/ISSUE_TEMPLATE/001_bug_report.yml b/.github/ISSUE_TEMPLATE/001_bug_report.yml deleted file mode 100644 index 1206aa1ea..000000000 --- a/.github/ISSUE_TEMPLATE/001_bug_report.yml +++ /dev/null @@ -1,166 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -name: Bug report -description: Report a bug to improve NuttX stability -title: "[BUG] " -labels: [๐Ÿ‘€ needs triage, "Type: Bug"] -body: - - type: markdown - attributes: - value: | - Hello NuttX Community member! Please keep things tidy by putting your post in the proper place: - - Reporting a bug: use this form. - Asking a question or getting help: use the [General Help](https://github.com/apache/nuttx-apps/issues/new?assignees=&labels=Community%3A+Question&projects=&template=003_help.yml&title=%5BHELP%5D+%3Ctitle%3E) form or [Mailing list](https://nuttx.apache.org/community/). - Requesting a new feature: use the [Feature request](https://github.com/apache/nuttx-apps/issues/new?assignees=&labels=Type%3A+Enhancement&projects=&template=002_feature_request.yml&title=%5BFEATURE%5D+%3Ctitle%3E) form. - - type: textarea - attributes: - label: "Description / Steps to reproduce the issue" - description: "A clear and concise description of what the bug is, and why you consider it to be a bug, and steps for how to reproduce it" - placeholder: | - A description with steps to reproduce the issue. - May include logs, images, or videos. - 1. Step 1 - 2. Step 2 - validations: - required: true - - - type: markdown - attributes: - value: | - ### Environment - Please specify your environment. - - - type: dropdown - id: os - attributes: - label: On which OS does this issue occur? - multiple: true - options: - - "[OS: BSD]" - - "[OS: Linux]" - - "[OS: Mac]" - - "[OS: Windows]" - - "[OS: Other]" - validations: - required: true - - - type: input - id: os_version - attributes: - label: What is the version of your OS? - description: Please fill out the distro or OS version from the previous dropdown - placeholder: "MacOS 14, Ubuntu 23.10, Windows 10/MSYS_NT-10.0-19045, ecc" - validations: - required: true - - - type: input - attributes: - label: NuttX Version - placeholder: "e.g., master, 12.5.1, ecc" - validations: - required: true - - - type: dropdown - id: architecture - attributes: - label: Issue Architecture - description: What architecture(s) are you seeing the problem on? - multiple: true - options: - - "[Arch: all]" - - "[Arch: arm]" - - "[Arch: arm64]" - - "[Arch: avr]" - - "[Arch: ceva]" - - "[Arch: hc]" - - "[Arch: mips]" - - "[Arch: misoc]" - - "[Arch: openrisc]" - - "[Arch: renesas]" - - "[Arch: risc-v]" - - "[Arch: simulator]" - - "[Arch: sparc]" - - "[Arch: tricore]" - - "[Arch: x86]" - - "[Arch: x86_64]" - - "[Arch: xtensa]" - - "[Arch: z16]" - - "[Arch: z80]" - validations: - required: true - - - type: dropdown - id: area - attributes: - label: Issue Area - description: What area(s) are you seeing the problem on? - multiple: true - options: - - "[Area: Audio]" - - "[Area: Benchmarks]" - - "[Area: Boot]" - - "[Area: CAN]" - - "[Area: Binfmt]" - - "[Area: Crypto]" - - "[Area: Database]" - - "[Area: Examples]" - - "[Area: File System]" - - "[Area: Games]" - - "[Area: Graphics]" - - "[Area: Industry]" - - "[Area: Inertial]" - - "[Area: Interpreters]" - - "[Area: Logging]" - - "[Area: LTE]" - - "[Area: Math]" - - "[Area: Mlearing]" - - "[Area: Modbus]" - - "[Area: Networking]" - - "[Area: NSH]" - - "[Area: SDR]" - - "[Area: System]" - - "[Area: Testing]" - - "[Area: Video]" - - "[Area: Wireless]" - - "[Area: Build System]" - - "[Area: Tools]" - - "[Area: Other]" - - "[Area: Posix]" - validations: - required: true - - - type: textarea - attributes: - label: "Host information" - description: "What is the output of `make host_info` command while your buggy configuration selected and if possible device connected to your system?" - validations: - required: false - - - type: markdown - attributes: - value: | - ### Before You Submit - - Please verify that you've followed these steps: - - Confirm the problem is reproducible on [**master**](https://github.com/apache/nuttx-apps) or [**latest stable**](https://nuttx.apache.org/download) release. - - Run `make distclean` when encountering build issues. - - Search [existing issues](https://github.com/apache/nuttx-apps/issues) (including [closed](https://github.com/apache/nuttx-apps/issues?q=is%3Aissue+is%3Aclosed)) - - Read the [FAQ](https://nuttx.apache.org/docs/latest/faq/index.html). - - - type: checkboxes - attributes: - label: "Verification" - options: - - label: "I have verified before submitting the report." - required: true diff --git a/.github/ISSUE_TEMPLATE/002_feature_request.yml b/.github/ISSUE_TEMPLATE/002_feature_request.yml deleted file mode 100644 index 1edb675cb..000000000 --- a/.github/ISSUE_TEMPLATE/002_feature_request.yml +++ /dev/null @@ -1,62 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -name: Feature request -description: Request an enhancement for NuttX -title: "[FEATURE] <title>" -labels: ["Type: Enhancement"] -body: - - type: markdown - attributes: - value: | - Hello NuttX Community member! Please keep things tidy by putting your post in the proper place: - - Requesting a new feature: use this form. - Asking a question or getting help: use the [General Help](https://github.com/apache/nuttx-apps/issues/new?assignees=&labels=Community%3A+Question&projects=&template=003_help.yml&title=%5BHELP%5D+%3Ctitle%3E) form or [Mailing list](https://nuttx.apache.org/community/). - Reporting a bug: use the [Bug report](https://github.com/apache/nuttx-apps/issues/new?assignees=&labels=%F0%9F%91%80+needs+triage%2CType%3A+Bug&projects=&template=001_bug_report.yml&title=%5BBUG%5D+%3Ctitle%3E) form. - - - type: textarea - id: question-description - attributes: - label: Is your feature request related to a problem? Please describe. - description: Please provide a clear and concise description of what the problem is. Add relevant issue link. - validations: - required: true - - - type: textarea - id: solution - attributes: - label: Describe the solution you'd like - description: Please provide a clear and concise description of what you want to happen. - validations: - required: true - - - type: textarea - id: alternatives - attributes: - label: Describe alternatives you've considered - description: Please provide a clear and concise description of any alternative solutions or features you've considered. - - - type: markdown - attributes: - value: | - ### Before You Submit - - Please verify that you've followed these steps: - - Search [existing feature requests](https://github.com/apache/nuttx-apps/issues) (including [closed](https://github.com/apache/nuttx-apps/issues?q=is%3Aissue+is%3Aclosed)) - - - type: checkboxes - attributes: - label: "Verification" - options: - - label: "I have verified before submitting the report." - required: true diff --git a/.github/ISSUE_TEMPLATE/003_help.yml b/.github/ISSUE_TEMPLATE/003_help.yml deleted file mode 100644 index 0d4f82858..000000000 --- a/.github/ISSUE_TEMPLATE/003_help.yml +++ /dev/null @@ -1,54 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -name: General Help -description: Get general support regarding NuttX -title: "[HELP] <title>" -labels: ["Community: Question"] -body: - - type: markdown - attributes: - value: | - Hello NuttX Community member! Please keep things tidy by putting your post in the proper place: - - Asking a question or getting help: use this form or [Mailing list](https://nuttx.apache.org/community/). - Reporting a bug: use the [Bug report](https://github.com/apache/nuttx-apps/issues/new?assignees=&labels=%F0%9F%91%80+needs+triage%2CType%3A+Bug&projects=&template=001_bug_report.yml&title=%5BBUG%5D+%3Ctitle%3E) form. - Requesting a new feature: use the [Feature request](https://github.com/apache/nuttx-apps/issues/new?assignees=&labels=Type%3A+Enhancement&projects=&template=002_feature_request.yml&title=%5BFEATURE%5D+%3Ctitle%3E) form - - - type: markdown - attributes: - value: | - ### Whether you're a beginner or an experienced developer, NuttX Help is here to assist you with all your NuttX questions and concerns. - - - type: textarea - id: question-description - attributes: - label: Description - description: Explain the background or context of your question. This helps others understand your problem or inquiry better. - validations: - required: true - - - type: markdown - attributes: - value: | - ### Before You Submit - - Please verify that you've followed these steps: - - I have searched [NuttX Documentation](https://nuttx.apache.org/docs/latest/) and didn't find an answer to my question. - - Search [existing issues](https://github.com/apache/nuttx-apps/issues) (including [closed](https://github.com/apache/nuttx-apps/issues?q=is%3Aissue+is%3Aclosed)) - - - type: checkboxes - attributes: - label: "Verification" - options: - - label: "I have verified before submitting the report." - required: true diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml deleted file mode 100644 index 3ba13e0ce..000000000 --- a/.github/ISSUE_TEMPLATE/config.yml +++ /dev/null @@ -1 +0,0 @@ -blank_issues_enabled: false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index d95cfcec5..f0c731226 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,21 +1,6 @@ -*Note: Please adhere to [Contributing Guidelines](https://github.com/apache/nuttx/blob/master/CONTRIBUTING.md).* - ## Summary -*Update this section with information on why change is necessary, - what it exactly does and how, if new feature shows up, provide - references (dependencies, similar problems and solutions), etc.* - ## Impact -*Update this section, where applicable, on how change affects users, - build process, hardware, documentation, security, compatibility, etc.* - ## Testing -*Update this section with details on how did you verify the change, - what Host was used for build (OS, CPU, compiler, ..), what Target was - used for verification (arch, board:config, ..), etc. Providing build - and runtime logs from before and after change is highly appreciated.* - - diff --git a/.github/SECURITY.md b/.github/SECURITY.md deleted file mode 100644 index 89213a4c0..000000000 --- a/.github/SECURITY.md +++ /dev/null @@ -1,21 +0,0 @@ -# Security Policy - -## Supported Versions - -| Version | Supported | -| ------- | ------------------ | -| 11.0.x | :heavy_check_mark: | -| 10.3.x | :heavy_check_mark: | -| 10.2.x | :heavy_check_mark: | -| 10.1.x | :heavy_check_mark: | -| 10.0.x | :heavy_check_mark: | -| 9.1.x | :heavy_check_mark: | -| < 9.1 | :x: | - -## Reporting a Vulnerability - -If you think you have found a possible vulnerability please reach out to the _private_ project mailing list -private@nuttx.apache.org or the Apache Security list security@apache.org. - -Please **DO NOT** create a GitHub issue or email the project dev list as they are public. -This project follows the Apache Vulnerability Handling Policy documented [here](https://www.apache.org/security/committers.html#vulnerability-handling). diff --git a/.github/dependabot.yml b/.github/dependabot.yml deleted file mode 100644 index 5ace4600a..000000000 --- a/.github/dependabot.yml +++ /dev/null @@ -1,6 +0,0 @@ -version: 2 -updates: - - package-ecosystem: "github-actions" - directory: "/" - schedule: - interval: "weekly" diff --git a/.github/labeler.yml b/.github/labeler.yml deleted file mode 100644 index 278cc551a..000000000 --- a/.github/labeler.yml +++ /dev/null @@ -1,171 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# -# Note: NuttX PR Labeler only supports a subset of the -# `actions/labeler` syntax: `changed-files` and -# `any-glob-to-any-file`. See .github/workflows/labeler.yml - -# add arch labels - -"Area: Audio": - - changed-files: - - any-glob-to-any-file: 'audioutils/**' - - any-glob-to-any-file: 'include/audioutils/**' - -"Area: Benchmarks": - - changed-files: - - any-glob-to-any-file: 'benchmarks/**' - - any-glob-to-any-file: 'include/benchmarks/**' - -"Area: Boot": - - changed-files: - - any-glob-to-any-file: 'boot/**' - - any-glob-to-any-file: 'include/boot/**' - -"Area: CAN": - - changed-files: - - any-glob-to-any-file: 'canutils/**' - - any-glob-to-any-file: 'include/canutils/**' - -"Area: Binfmt": - - changed-files: - - any-glob-to-any-file: 'builtin/**' - - any-glob-to-any-file: 'include/builtin/**' - -"Area: Crypto": - - changed-files: - - any-glob-to-any-file: 'crypto/**' - - any-glob-to-any-file: 'include/crypto/**' - -"Area: Database": - - changed-files: - - any-glob-to-any-file: 'database/**' - - any-glob-to-any-file: 'include/database/**' - -"Area: Examples": - - changed-files: - - any-glob-to-any-file: 'examples/**' - -"Area: File System": - - changed-files: - - any-glob-to-any-file: 'fsutils/**' - - any-glob-to-any-file: 'include/fsutils/**' - -"Area: Games": - - changed-files: - - any-glob-to-any-file: 'games/**' - - any-glob-to-any-file: 'include/games/**' - -"Area: Graphics": - - changed-files: - - any-glob-to-any-file: 'graphics/**' - - any-glob-to-any-file: 'include/graphics/**' - -"Area: Industry": - - changed-files: - - any-glob-to-any-file: 'industry/**' - - any-glob-to-any-file: 'include/industry/**' - -"Area: Inertial": - - changed-files: - - any-glob-to-any-file: 'inertial/**' - - any-glob-to-any-file: 'include/inertial/**' - -"Area: Interpreters": - - changed-files: - - any-glob-to-any-file: 'interpreters/**' - - any-glob-to-any-file: 'include/interpreters/**' - -"Area: Logging": - - changed-files: - - any-glob-to-any-file: 'logging/**' - - any-glob-to-any-file: 'include/logging/**' - -"Area: LTE": - - changed-files: - - any-glob-to-any-file: 'lte/**' - - any-glob-to-any-file: 'include/lte/**' - -"Area: Math": - - changed-files: - - any-glob-to-any-file: 'math/**' - - any-glob-to-any-file: 'include/math/**' - -"Area: Mlearning": - - changed-files: - - any-glob-to-any-file: 'mlearning/**' - - any-glob-to-any-file: 'include/mlearning/**' - -"Area: Modbus": - - changed-files: - - any-glob-to-any-file: 'modbus/**' - - any-glob-to-any-file: 'include/modbus/**' - -"Area: Networking": - - changed-files: - - any-glob-to-any-file: 'netutils/**' - - any-glob-to-any-file: 'include/netuitls/**' - -"Area: NSH": - - changed-files: - - any-glob-to-any-file: 'nshlib/**' - - any-glob-to-any-file: 'include/nshlib/**' - -"Area: SDR": - - changed-files: - - any-glob-to-any-file: 'sdr/**' - - any-glob-to-any-file: 'include/sdr/**' - -"Area: System": - - changed-files: - - any-glob-to-any-file: 'system/**' - - any-glob-to-any-file: 'include/system/**' - -"Area: Testing": - - changed-files: - - any-glob-to-any-file: 'testing/**' - - any-glob-to-any-file: 'include/testing/**' - -"Area: Video": - - changed-files: - - any-glob-to-any-file: 'videotuils/**' - - any-glob-to-any-file: 'include/videotuils/**' - -"Area: Wireless": - - changed-files: - - any-glob-to-any-file: 'wireless/**' - - any-glob-to-any-file: 'include/wireless/**' - -"Area: Build system": - - changed-files: - - any-glob-to-any-file: 'Makefile' - - any-glob-to-any-file: 'Make.defs' - - any-glob-to-any-file: '*.mk' - - any-glob-to-any-file: 'CMakeLists.txt' - - any-glob-to-any-file: 'cmake/**' - - any-glob-to-any-file: 'import/**' - - any-glob-to-any-file: 'staging/**' - -"Area: Tools": - - changed-files: - - any-glob-to-any-file: 'tools/**' - -"Area: CI": - - changed-files: - - any-glob-to-any-file: '.github/**' diff --git a/.github/linters/setup.cfg b/.github/linters/setup.cfg deleted file mode 100644 index a8b142d93..000000000 --- a/.github/linters/setup.cfg +++ /dev/null @@ -1,10 +0,0 @@ -[flake8] -ignore = W503,W605,E203,E704 -max-complexity = 27 -max-line-length = 125 -multi_line_output=3 -show-source = True -statistics = True - -[isort] -profile = black diff --git a/.github/workflows/arch.yml b/.github/workflows/arch.yml deleted file mode 100644 index 02e39ab2b..000000000 --- a/.github/workflows/arch.yml +++ /dev/null @@ -1,260 +0,0 @@ -# Identify the Arch for the PR and select the applicable builds -name: Arch - -on: - workflow_call: - inputs: - os: - description: "Operating System hosting the build: Linux, macOS or msys2" - required: true - type: string - boards: - description: "List of All Builds: [arm-01, risc-v-01, xtensa-01, ...]" - required: true - type: string - outputs: - skip_all_builds: - description: "Set to 1 if all builds should be skipped" - value: ${{ jobs.Select-Builds.outputs.skip_all_builds }} - selected_builds: - description: "Selected Builds for the PR: [arm-01, risc-v-01, xtensa-01, ...]" - value: ${{ jobs.Select-Builds.outputs.selected_builds }} - -jobs: - Select-Builds: - runs-on: ubuntu-latest - - outputs: - skip_all_builds: ${{ steps.select-builds.outputs.skip_all_builds }} - selected_builds: ${{ steps.select-builds.outputs.selected_builds }} - - steps: - - # Get the Arch for the PR: arm, arm64, risc-v, xtensa, ... - - name: Get arch - id: get-arch - run: | - - # If PR is Not Created or Modified: Build all targets - pr=${{github.event.pull_request.number}} - if [[ "$pr" == "" ]]; then - echo "Not a Created or Modified PR, will build all targets" - exit - fi - - # Ignore the Label "Area: Documentation", because it won't affect the Build Targets - query='.labels | map(select(.name != "Area: Documentation")) | ' - select_name='.[].name' - select_length='length' - - # Get the Labels for the PR: "Arch: risc-v \n Board: risc-v \n Size: XS" - # If GitHub CLI Fails: Build all targets - labels=$(gh pr view $pr --repo $GITHUB_REPOSITORY --json labels --jq "$query$select_name" || echo "") - numlabels=$(gh pr view $pr --repo $GITHUB_REPOSITORY --json labels --jq "$query$select_length" || echo "") - echo "labels=$labels" - echo "numlabels=$numlabels" | tee -a $GITHUB_OUTPUT - - # Identify the Size, Arch and Board Labels - if [[ "$labels" == *"Size: "* ]]; then - echo 'labels_contain_size=1' | tee -a $GITHUB_OUTPUT - fi - if [[ "$labels" == *"Arch: "* ]]; then - echo 'labels_contain_arch=1' | tee -a $GITHUB_OUTPUT - fi - if [[ "$labels" == *"Board: "* ]]; then - echo 'labels_contain_board=1' | tee -a $GITHUB_OUTPUT - fi - - # Get the Arch Label - if [[ "$labels" == *"Arch: arm64"* ]]; then - echo 'arch_contains_arm64=1' | tee -a $GITHUB_OUTPUT - elif [[ "$labels" == *"Arch: arm"* ]]; then - echo 'arch_contains_arm=1' | tee -a $GITHUB_OUTPUT - elif [[ "$labels" == *"Arch: risc-v"* ]]; then - echo 'arch_contains_riscv=1' | tee -a $GITHUB_OUTPUT - elif [[ "$labels" == *"Arch: simulator"* ]]; then - echo 'arch_contains_sim=1' | tee -a $GITHUB_OUTPUT - elif [[ "$labels" == *"Arch: x86_64"* ]]; then - echo 'arch_contains_x86_64=1' | tee -a $GITHUB_OUTPUT - elif [[ "$labels" == *"Arch: x86"* ]]; then - echo 'arch_contains_x86=1' | tee -a $GITHUB_OUTPUT - elif [[ "$labels" == *"Arch: xtensa"* ]]; then - echo 'arch_contains_xtensa=1' | tee -a $GITHUB_OUTPUT - fi - - # Get the Board Label - if [[ "$labels" == *"Board: arm64"* ]]; then - echo 'board_contains_arm64=1' | tee -a $GITHUB_OUTPUT - elif [[ "$labels" == *"Board: arm"* ]]; then - echo 'board_contains_arm=1' | tee -a $GITHUB_OUTPUT - elif [[ "$labels" == *"Board: risc-v"* ]]; then - echo 'board_contains_riscv=1' | tee -a $GITHUB_OUTPUT - elif [[ "$labels" == *"Board: simulator"* ]]; then - echo 'board_contains_sim=1' | tee -a $GITHUB_OUTPUT - elif [[ "$labels" == *"Board: x86_64"* ]]; then - echo 'board_contains_x86_64=1' | tee -a $GITHUB_OUTPUT - elif [[ "$labels" == *"Board: x86"* ]]; then - echo 'board_contains_x86=1' | tee -a $GITHUB_OUTPUT - elif [[ "$labels" == *"Board: xtensa"* ]]; then - echo 'board_contains_xtensa=1' | tee -a $GITHUB_OUTPUT - fi - - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - # Select the Builds for the PR: arm-01, risc-v-01, xtensa-01, ... - - name: Select builds - id: select-builds - run: | - - # Skip all macOS Builds - if [[ "${{ inputs.os }}" == "macOS" ]]; then - echo "Skipping all macOS Builds" - echo "skip_all_builds=1" | tee -a $GITHUB_OUTPUT - exit - fi - - # Fetch the outputs from the previous step - numlabels=${{ steps.get-arch.outputs.numlabels }} - labels_contain_size=${{ steps.get-arch.outputs.labels_contain_size }} - labels_contain_arch=${{ steps.get-arch.outputs.labels_contain_arch }} - labels_contain_board=${{ steps.get-arch.outputs.labels_contain_board }} - arch_contains_arm=${{ steps.get-arch.outputs.arch_contains_arm }} - arch_contains_arm64=${{ steps.get-arch.outputs.arch_contains_arm64 }} - arch_contains_riscv=${{ steps.get-arch.outputs.arch_contains_riscv }} - arch_contains_sim=${{ steps.get-arch.outputs.arch_contains_sim }} - arch_contains_x86=${{ steps.get-arch.outputs.arch_contains_x86 }} - arch_contains_x86_64=${{ steps.get-arch.outputs.arch_contains_x86_64 }} - arch_contains_xtensa=${{ steps.get-arch.outputs.arch_contains_xtensa }} - board_contains_arm=${{ steps.get-arch.outputs.board_contains_arm }} - board_contains_arm64=${{ steps.get-arch.outputs.board_contains_arm64 }} - board_contains_riscv=${{ steps.get-arch.outputs.board_contains_riscv }} - board_contains_sim=${{ steps.get-arch.outputs.board_contains_sim }} - board_contains_x86=${{ steps.get-arch.outputs.board_contains_x86 }} - board_contains_x86_64=${{ steps.get-arch.outputs.board_contains_x86_64 }} - board_contains_xtensa=${{ steps.get-arch.outputs.board_contains_xtensa }} - - # inputs.boards is a JSON Array: ["arm-01", "risc-v-01", "xtensa-01", ...] - # We compact and remove the newlines - boards=$( echo '${{ inputs.boards }}' | jq --compact-output ".") - numboards=$( echo "$boards" | jq "length" ) - - # We consider only Simple PRs with: - # Arch + Size Labels Only - # Board + Size Labels Only - # Arch + Board + Size Labels Only - if [[ "$labels_contain_size" != "1" ]]; then - echo "Size Label Missing, will build all targets" - quit=1 - elif [[ "$numlabels" == "2" && "$labels_contain_arch" == "1" ]]; then - echo "Arch + Size Labels Only" - elif [[ "$numlabels" == "2" && "$labels_contain_board" == "1" ]]; then - echo "Board + Size Labels Only" - elif [[ "$numlabels" == "3" && "$labels_contain_arch" == "1" && "$labels_contain_board" == "1" ]]; then - # Arch and Board must be the same - if [[ - "$arch_contains_arm" != "$board_contains_arm" || - "$arch_contains_arm64" != "$board_contains_arm64" || - "$arch_contains_riscv" != "$board_contains_riscv" || - "$arch_contains_sim" != "$board_contains_sim" || - "$arch_contains_x86" != "$board_contains_x86" || - "$arch_contains_x86_64" != "$board_contains_x86_64" || - "$arch_contains_xtensa" != "$board_contains_xtensa" - ]]; then - echo "Arch and Board are not the same, will build all targets" - quit=1 - else - echo "Arch + Board + Size Labels Only" - fi - else - echo "Not a Simple PR, will build all targets" - quit=1 - fi - - # If Not a Simple PR: Build all targets - if [[ "$quit" == "1" ]]; then - # If PR was Created or Modified: Include all boards - pr=${{github.event.pull_request.number}} - if [[ "$pr" != "" ]]; then - echo "Include all boards" - boards=$( - echo '${{ inputs.boards }}' | - jq --compact-output \ - '.' - ) - fi - echo "selected_builds=$boards" | tee -a $GITHUB_OUTPUT - exit - fi - - # For every board - for (( i=0; i<numboards; i++ )) - do - # Fetch the board - board=$( echo "$boards" | jq ".[$i]" ) - skip_build=0 - - # For "Arch / Board: arm": Build arm-01, arm-02, ... - if [[ "$arch_contains_arm" == "1" || "$board_contains_arm" == "1" ]]; then - if [[ "$board" != *"arm-"* ]]; then - skip_build=1 - fi - - # For "Arch / Board: arm64": Build arm64-01 - elif [[ "$arch_contains_arm64" == "1" || "$board_contains_arm64" == "1" ]]; then - if [[ "$board" != *"arm64-"* ]]; then - skip_build=1 - fi - - # For "Arch / Board: risc-v": Build risc-v-01, risc-v-02, ... - elif [[ "$arch_contains_riscv" == "1" || "$board_contains_riscv" == "1" ]]; then - if [[ "$board" != *"risc-v-"* ]]; then - skip_build=1 - fi - - # For "Arch / Board: simulator": Build sim-01, sim-02 - elif [[ "$arch_contains_sim" == "1" || "$board_contains_sim" == "1" ]]; then - if [[ "$board" != *"sim-"* ]]; then - skip_build=1 - fi - - # For "Arch / Board: x86": Build other - elif [[ "$arch_contains_x86" == "1" || "$board_contains_x86" == "1" ]]; then - if [[ "$board" != *"other"* ]]; then - skip_build=1 - fi - - # For "Arch / Board: x86_64": Build x86_64-01 - elif [[ "$arch_contains_x86_64" == "1" || "$board_contains_x86_64" == "1" ]]; then - if [[ "$board" != *"x86_64-"* ]]; then - skip_build=1 - fi - - # For "Arch / Board: xtensa": Build xtensa-01, xtensa-02, xtensa-03 - elif [[ "$arch_contains_xtensa" == "1" || "$board_contains_xtensa" == "1" ]]; then - if [[ "$board" != *"xtensa-"* ]]; then - skip_build=1 - fi - - # For Other Arch: Allow the build - else - echo Build by default: $board - fi - - # Add the board to the selected builds - if [[ "$skip_build" == "0" ]]; then - echo Add $board to selected_builds - if [[ "$selected_builds" == "" ]]; then - selected_builds=$board - else - selected_builds=$selected_builds,$board - fi - fi - done - - # Return the selected builds as JSON Array - # If Selected Builds is empty: Skip all builds - echo "selected_builds=[$selected_builds]" | tee -a $GITHUB_OUTPUT - if [[ "$selected_builds" == "" ]]; then - echo "skip_all_builds=1" | tee -a $GITHUB_OUTPUT - fi diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f9ac66a20..7775dcbf9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -16,19 +16,15 @@ on: pull_request: push: branches: + - master - 'releases/*' tags: -permissions: - contents: read - concurrency: group: build-${{ github.event.pull_request.number || github.ref }} cancel-in-progress: true jobs: - - # Fetch the source from nuttx and nuttx-apps repos Fetch-Source: runs-on: ubuntu-latest steps: @@ -63,13 +59,13 @@ jobs: # Determine the repo and leave that unset to use the normal checkout behavior # of using the merge commit instead of HEAD case $GITHUB_REPOSITORY in - "apache/nuttx") + "apache/incubator-nuttx") # OS echo "Triggered by change in OS" APPS_REF=$REF_NAME ;; - "apache/nuttx-apps" ) + "apache/incubator-nuttx-apps" ) # APPS OS_REF=$REF_NAME echo "Triggered by change in APPS" @@ -81,13 +77,13 @@ jobs: esac fi - echo "os_ref=$OS_REF" >> $GITHUB_OUTPUT - echo "apps_ref=$APPS_REF" >> $GITHUB_OUTPUT + echo ::set-output name=os_ref::$OS_REF + echo ::set-output name=apps_ref::$APPS_REF - name: Checkout nuttx repo - uses: actions/checkout@v7 + uses: actions/checkout@v2 with: - repository: apache/nuttx + repository: apache/incubator-nuttx ref: ${{ steps.gittargets.outputs.os_ref }} path: sources/nuttx fetch-depth: 1 @@ -95,390 +91,105 @@ jobs: run: git -C sources/nuttx fetch --tags - name: Checkout apps repo - uses: actions/checkout@v7 + uses: actions/checkout@v2 with: - repository: apache/nuttx-apps + repository: apache/incubator-nuttx-apps ref: ${{ steps.gittargets.outputs.apps_ref }} path: sources/apps fetch-depth: 1 - name: Tar sources run: tar zcf sources.tar.gz sources - - name: Archive Source Bundle - uses: actions/upload-artifact@v7.0.1 + uses: actions/upload-artifact@v1 with: name: source-bundle path: sources.tar.gz - # Select the Linux Builds based on PR Arch Label - Linux-Arch: - uses: apache/nuttx-apps/.github/workflows/arch.yml@master - needs: Fetch-Source - with: - os: Linux - boards: | - [ - "arm-01", "risc-v-01", "sim-01", "xtensa-01", "arm64-01", "x86_64-01", "other", - "arm-02", "risc-v-02", "sim-02", "xtensa-02", - "arm-03", "risc-v-03", "sim-03", "xtensa-03", - "arm-04", "risc-v-04", - "arm-05", "risc-v-05", - "arm-06", "risc-v-06", - "arm-07", "arm-08", "arm-09", "arm-10", "arm-11", "arm-12", "arm-13", "arm-14" - ] - - # Run the selected Linux Builds Linux: - needs: Linux-Arch - if: ${{ needs.Linux-Arch.outputs.skip_all_builds != '1' }} + needs: Fetch-Source runs-on: ubuntu-latest env: DOCKER_BUILDKIT: 1 - # Documented sim/login CI test credential (not a production secret). - # Used when CONFIG_BOARD_ETC_ROMFS_PASSWD_ENABLE=y and defconfig omits - # the password. See nuttx tools/update_romfs_password.sh. - NUTTX_ROMFS_PASSWD_PASSWORD: NuttXSimLogin1! strategy: - max-parallel: 12 matrix: - boards: ${{ fromJSON(needs.Linux-Arch.outputs.selected_builds) }} + boards: [arm-01, arm-02, arm-03, arm-04, arm-05, arm-06, arm-07, arm-08, arm-09, arm-10, arm-11, arm-12, arm-13, other, risc-v, sim-01, sim-02, xtensa] steps: - - - name: Show Disk Space - run: df -h - - - name: Free Disk Space (Ubuntu) - run: | - sudo rm -rf /usr/local/lib/android - - - name: After CLEAN-UP Disk Space - run: df -h - - name: Download Source Artifact - uses: actions/download-artifact@v8 + uses: actions/download-artifact@v1 with: name: source-bundle path: . - - name: Extract sources run: tar zxf sources.tar.gz - - name: Docker Login - uses: docker/login-action@abd2ef45e78c5afb21d64d4ca52ee8550d9572c7 # v4.5.1 + uses: azure/docker-login@v1 with: - registry: ghcr.io - username: ${{ github.actor }} + login-server: ghcr.io + username: ${GITHUB_ACTOR} password: ${{ secrets.GITHUB_TOKEN }} - name: Docker Pull - run: docker pull ghcr.io/apache/nuttx/apache-nuttx-ci-linux - + run: docker pull ghcr.io/apache/incubator-nuttx/apache-nuttx-ci-linux - name: Export NuttX Repo SHA run: echo "nuttx_sha=`git -C sources/nuttx rev-parse HEAD`" >> $GITHUB_ENV - - name: Run builds uses: ./sources/nuttx/.github/actions/ci-container env: BLOBDIR: /tools/blobs - NUTTX_ROMFS_PASSWD_PASSWORD: NuttXSimLogin1! with: run: | - export NUTTX_ROMFS_PASSWD_PASSWORD=NuttXSimLogin1! - export ARTIFACTDIR=`pwd`/buildartifacts - - for i in 1 2 3; do - python -m pip install \ - --default-timeout=100 \ - --retries 10 \ - ntfc==0.0.1 && break - echo "Retry $i failed..." - sleep 5 - done - - mkdir /github/workspace/nuttx-ntfc - mkdir /github/workspace/nuttx-ntfc/external - cd /github/workspace/nuttx-ntfc - # get NTFC test cases - cd external - for i in 1 2 3 4 5; do - git clone -b release-0.0.1 https://github.com/apache/nuttx-ntfc-testing && break - if [ "$i" -eq 5 ]; then - echo "Failed to clone nuttx-ntfc-testing after $i attempts" - exit 1 - fi - - delay=$((i * 10)) - echo "Clone attempt $i failed; retrying in ${delay}s..." - rm -rf nuttx-ntfc-testing - sleep "$delay" - done - mv nuttx-ntfc-testing nuttx-testing - export NTFCDIR=/github/workspace/nuttx-ntfc - echo "::add-matcher::sources/nuttx/.github/gcc.json" - git config --global --add safe.directory /github/workspace/sources/nuttx - git config --global --add safe.directory /github/workspace/sources/apps - cd /github/workspace/sources/nuttx/tools/ci - if [ "X${{matrix.boards}}" = "Xcodechecker" ]; then - ./cibuild.sh -c -A -N -R --codechecker testlist/${{matrix.boards}}.dat - else - ( sleep 7200 ; echo Killing pytest after timeout... ; pkill -f pytest )& - ./cibuild.sh -c -A -N -R -S testlist/${{matrix.boards}}.dat - fi - - - name: Post-build Disk Space - if: always() - run: df -h - - - uses: actions/upload-artifact@v7.0.1 - if: ${{ always() }} + export CCACHE_DIR=`pwd`/ccache + mkdir $CCACHE_DIR + export ARTIFACTDIR=`pwd`/buildartifacts + cd sources/nuttx/tools/ci + ./cibuild.sh -A -c testlist/${{matrix.boards}}.dat + ccache -s + - uses: actions/upload-artifact@v2 with: - name: linux-${{matrix.boards}}-builds + name: linux-builds path: buildartifacts/ continue-on-error: true - # Test the out-of-tree build - OOT-Build: - needs: Linux - runs-on: ubuntu-latest - env: - DOCKER_BUILDKIT: 1 - steps: - - name: Download Source Artifact - uses: actions/download-artifact@v8 - with: - name: source-bundle - path: . - - - name: Extract sources - run: tar zxf sources.tar.gz - - - name: Docker Login - uses: docker/login-action@abd2ef45e78c5afb21d64d4ca52ee8550d9572c7 # v4.5.1 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Export NuttX Repo SHA - run: echo "nuttx_sha=`git -C sources/nuttx rev-parse HEAD`" >> $GITHUB_ENV - - - name: Run Out-of-Tree Build Test - uses: ./sources/nuttx/.github/actions/ci-container - env: - BLOBDIR: /tools/blobs - with: - run: | - echo "::add-matcher::sources/nuttx/.github/gcc.json" - git config --global --add safe.directory /github/workspace/sources/nuttx - git config --global --add safe.directory /github/workspace/sources/apps - cd sources/nuttx - ./tools/ci/cibuild-oot.sh - - - uses: actions/upload-artifact@v7.0.1 - if: ${{ always() }} - with: - name: oot-build-artifacts - path: sources/apps/testing/cxx-oot-build - continue-on-error: true - - # Select the macOS Builds based on PR Arch Label - macOS-Arch: - uses: apache/nuttx-apps/.github/workflows/arch.yml@master - needs: Fetch-Source - with: - os: macOS - boards: | - ["macos", "sim-01", "sim-02", "sim-03"] - - # Run the selected macOS Builds macOS: - permissions: - contents: none - runs-on: macos-15-intel - needs: macOS-Arch - if: ${{ needs.macOS-Arch.outputs.skip_all_builds != '1' }} - env: - NUTTX_ROMFS_PASSWD_PASSWORD: NuttXSimLogin1! + runs-on: macos-10.15 + needs: Fetch-Source strategy: - max-parallel: 2 matrix: - boards: ${{ fromJSON(needs.macOS-Arch.outputs.selected_builds) }} + boards: [macos, sim-01, sim-02] steps: - name: Download Source Artifact - uses: actions/download-artifact@v8 + uses: actions/download-artifact@v1 with: name: source-bundle path: . - - name: Extract sources run: tar zxf sources.tar.gz - - name: Restore Tools Cache id: cache-tools - uses: actions/cache@v6 + uses: actions/cache@v2 env: cache-name: ${{ runner.os }}-cache-tools with: - path: ./sources/tools - key: ${{ runner.os }}-tools-${{ hashFiles('./sources/nuttx/tools/ci/platforms/darwin.sh') }} + path: prebuilt + key: ${{ runner.os }}-tools-${{ hashFiles('./sources/nuttx/tools/ci/cibuild.sh') }} - name: Export NuttX Repo SHA run: echo "nuttx_sha=`git -C sources/nuttx rev-parse HEAD`" >> $GITHUB_ENV - - # Released version of Cython has issues with Python 11. Set runner to use Python 3.10 - # https://github.com/cython/cython/issues/4500 - - uses: actions/setup-python@v7 - with: - python-version: '3.10' - name: Run Builds run: | echo "::add-matcher::sources/nuttx/.github/gcc.json" - export NUTTX_ROMFS_PASSWD_PASSWORD=NuttXSimLogin1! + export CCACHE_DIR=`pwd`/ccache + mkdir $CCACHE_DIR export ARTIFACTDIR=`pwd`/buildartifacts cd sources/nuttx/tools/ci - ./cibuild.sh -i -c -A -R testlist/${{matrix.boards}}.dat - - - uses: actions/upload-artifact@v7.0.1 + ./cibuild.sh -i -A -c testlist/${{matrix.boards}}.dat + ccache -s + - uses: actions/upload-artifact@v2 with: - name: macos-${{matrix.boards}}-builds + name: macos-builds path: buildartifacts/ continue-on-error: true - - # Select the msys2 Builds based on PR Arch Label - msys2-Arch: - uses: apache/nuttx-apps/.github/workflows/arch.yml@master - needs: Fetch-Source - with: - os: msys2 - boards: | - ["msys2"] - - # Run the selected msys2 Builds - msys2: - needs: msys2-Arch - if: ${{ needs.msys2-Arch.outputs.skip_all_builds != '1' }} - runs-on: windows-latest - strategy: - fail-fast: false - max-parallel: 1 - matrix: - boards: ${{ fromJSON(needs.msys2-Arch.outputs.selected_builds) }} - - defaults: - run: - shell: msys2 {0} - steps: - - uses: actions/checkout@v7 - - uses: msys2/setup-msys2@v2 - with: - msystem: MSYS - update: false - cache: false - install: >- - base-devel - gcc - gperf - automake - autoconf - git - python3 - ncurses-devel - unzip - zip - tio - zlib-devel - cmake - ninja - python-pip - vim - genromfs - - - name: pip3 install - run: | - python3 -m venv --system-site-packages /usr/local - pip3 install --root-user-action=ignore --no-cache-dir pyelftools cxxfilt kconfiglib - - - run: git config --global core.autocrlf false - - - name: Download Source Artifact - uses: actions/download-artifact@v8 - with: - name: source-bundle - path: . - - - name: Extract sources - run: tar zxf sources.tar.gz - - - name: Export NuttX Repo SHA - run: echo "nuttx_sha=`git -C sources/nuttx rev-parse HEAD`" >> $GITHUB_ENV - - - name: Run Builds - run: | - echo "::add-matcher::sources/nuttx/.github/gcc.json" - export ARTIFACTDIR=`pwd`/buildartifacts - git config --global --add safe.directory /github/workspace/sources/nuttx - git config --global --add safe.directory /github/workspace/sources/apps - cd sources/nuttx/tools/ci - ./cibuild.sh -g -i -A -C -N -R testlist/${{matrix.boards}}.dat - - - uses: actions/upload-artifact@v7.0.1 - with: - name: msys2-${{matrix.boards}}-builds - path: buildartifacts/ - continue-on-error: true - - # Select the msvc Builds based on PR Arch Label - msvc-Arch: - uses: apache/nuttx-apps/.github/workflows/arch.yml@master - needs: Fetch-Source - with: - os: msvc - boards: | - ["msvc_placeholder_with_sim_keyword"] - - # Build with MSVC in Windows native - msvc: - needs: msvc-Arch - if: ${{ needs.msvc-Arch.outputs.skip_all_builds != '1' }} - runs-on: windows-2022 - steps: - - uses: actions/checkout@v7 - # Set up Python environment and install kconfiglib - - name: Set up Python and install kconfiglib - uses: actions/setup-python@v7 - with: - python-version: '3.10' - - name: Install kconfiglib - run: | - pip install kconfiglib - - - run: git config --global core.autocrlf false - - - name: Download Source Artifact - uses: actions/download-artifact@v8 - with: - name: source-bundle - path: . - - - name: Extract sources - run: | - 7z x sources.tar.gz -y - 7z x sources.tar -y -snld - - - name: Run Builds - run: | - "ARTIFACTDIR=${{github.workspace}}\sources\buildartifacts" >> $env:GITHUB_ENV - git config --global --add safe.directory ${{github.workspace}}\sources\nuttx - git config --global --add safe.directory ${{github.workspace}}\sources\apps - cd sources\nuttx\tools\ci - .\cibuild.ps1 -n -i -A -C -N testlist\windows.dat - - - uses: actions/upload-artifact@v7.0.1 - with: - name: msvc-builds - path: ./sources/buildartifacts/ - continue-on-error: true diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index a183d0c12..4ab5c1086 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -19,36 +19,30 @@ concurrency: group: check-${{ github.event.pull_request.number || github.ref }} cancel-in-progress: true -permissions: - contents: read - jobs: check: - runs-on: ubuntu-latest + runs-on: ubuntu-18.04 steps: - name: Checkout nuttx repo - uses: actions/checkout@v7 + uses: actions/checkout@v2 with: - repository: apache/nuttx + repository: apache/incubator-nuttx path: nuttx fetch-depth: 0 - name: Checkout apps repo - uses: actions/checkout@v7 + uses: actions/checkout@v2 with: - repository: apache/nuttx-apps + repository: apache/incubator-nuttx-apps path: apps fetch-depth: 0 - name: Check Pull Request run: | echo "::add-matcher::nuttx/.github/nxstyle.json" - python3 -m venv .venv - source .venv/bin/activate - pip install codespell cmake-format black isort flake8 cvt2utf cd apps commits="${{ github.event.pull_request.base.sha }}..HEAD" git log --oneline $commits - echo "../nuttx/tools/checkpatch.sh -c -u -m -g $commits" - ../nuttx/tools/checkpatch.sh -c -u -m -g $commits + echo "../nuttx/tools/checkpatch.sh -g $commits" + ../nuttx/tools/checkpatch.sh -g $commits diff --git a/.github/workflows/issue_labeler.yml b/.github/workflows/issue_labeler.yml deleted file mode 100644 index 2965bf5a6..000000000 --- a/.github/workflows/issue_labeler.yml +++ /dev/null @@ -1,53 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -name: Issue Labeler - -on: - issues: - types: [opened] - -jobs: - label: - runs-on: ubuntu-latest - permissions: - issues: write - steps: - - name: Add labels issues automatically based on their body. - uses: actions/github-script@v9.0.0 - with: - script: | - const body = context.payload.issue.body; - const bodySplit = body.split(/\[|\]/).map(e => e.toLowerCase()); - const oskeywords = ['os: other', 'os: bsd', 'os: linux', 'os: mac', 'os: windows']; - const archkeywords1 = ['arch: all', 'arch: arm', 'arch: arm64', 'arch: avr', 'arch: ceva']; - const archkeywords2 = ['arch: hc', 'arch: mips', 'arch: misoc', 'arch: openrisc', 'arch:renesas']; - const archkeywords3 = ['arch: risc-v', 'arch: simulator', 'arch: sparc', 'arch: tricore']; - const archkeywords4 = ['arch: x86', 'arch: x86_64', 'arch: xtensa', 'arch: z16', 'arch: z80', 'arch:renesas']; - const areakeywords1 = ['area: applications', 'area: api', 'area: board support', 'area: build system']; - const areakeywords2 = ['area: configuring', 'area: debugging', 'area: drivers', 'area: file system', 'area: installing', 'area: kconfig']; - const areakeywords3 = ['area: kernel', 'area: memory management', 'area: native port', 'area: networking']; - const areakeywords4 = ['area: os components', 'area: posix', 'area: sensors', 'area: specific peripheral']; - var keywordsfound = new Set(); - for (const keyword of keywords) { - if (bodySplit.includes(keyword)) { - keywordsfound.add(keyword) - } - } - if (keywordsfound.size !== 0) { - github.rest.issues.addLabels({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: context.issue.number, - labels: Array.from(keywordsfound) - }) - } diff --git a/.github/workflows/labeler.yml b/.github/workflows/labeler.yml deleted file mode 100644 index 4c6bb3ef7..000000000 --- a/.github/workflows/labeler.yml +++ /dev/null @@ -1,150 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# This workflow will fetch the updated PR filenames, compute the Size Label -# and Arch Labels, then save the PR Labels into a PR Artifact. The -# PR Labels will be written to the PR inside the "workflow_run" trigger -# (pr_labeler.yml), because this "pull_request" trigger has read-only -# permission. Don't use "pull_request_target", it's unsafe. -# See https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=321719166#GitHubActionsSecurity-Buildstriggeredwithpull_request_target -name: "Pull Request Labeler" -on: - - pull_request - -jobs: - labeler: - permissions: - contents: read - pull-requests: read - issues: read - runs-on: ubuntu-latest - steps: - # Checkout one file from our trusted source: .github/labeler.yml - # Never checkout and execute any untrusted code from the PR. - - name: Checkout labeler config - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 - with: - repository: apache/nuttx-apps - ref: master - path: labeler - fetch-depth: 1 - persist-credentials: false - sparse-checkout: .github/labeler.yml - sparse-checkout-cone-mode: false - - # Fetch the updated PR filenames. Compute the Size Label and Arch Labels. - - name: Compute PR labels - uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - script: | - const owner = context.repo.owner; - const repo = context.repo.repo; - const pull_number = context.issue.number; - - // Fetch the array of updated PR filenames: - // { status: 'added', filename: 'arch/arm/test.txt', additions: 3, deletions: 0, changes: 3 } - // { status: 'removed', filename: 'Documentation/legacy_README.md', additions: 0, deletions: 2531, changes: 2531 } - // { status: 'modified', filename: 'Documentation/security.rst', additions: 1, deletions: 0, changes: 1 } - const listFilesOptions = github.rest.pulls.listFiles - .endpoint.merge({ owner, repo, pull_number }); - const listFilesResponse = await github.paginate(listFilesOptions); - - // Sum up the number of lines changed - const sizeFiles = listFilesResponse - .filter(f => (f.status != 'removed')); // Ignore deleted files - var linesChanged = 0; - for (const file of sizeFiles) { - linesChanged += file.changes; - } - console.log({ linesChanged }); - - // Compute the Size Label - const sizeLabel = - (linesChanged <= 10) ? 'Size: XS' - : (linesChanged <= 100) ? 'Size: S' - : (linesChanged <= 500) ? 'Size: M' - : (linesChanged <= 1000) ? 'Size: L' - : 'Size: XL'; - var prLabels = [ sizeLabel ]; - - // Parse the Arch Label Patterns in .github/labeler.yml. Condense into: - // "Arch: arm": - // - any-glob-to-any-file: 'arch/arm/**' - // - any-glob-to-any-file: ... - const fs = require('fs'); - const config = fs.readFileSync('labeler/.github/labeler.yml', 'utf8') - .split('\n') // Split by newline - .map(s => s.trim()) // Remove leading and trailing spaces - .filter(s => (s != '')) // Remove empty lines - .filter(s => !s.startsWith('#')) // Remove comments - .filter(s => !s.startsWith('- changed-files:')); // Remove "changed-files" - - // Convert the Arch Label Patterns from config to archLabels. - // archLabels will contain the mappings for Arch Label and Filename Pattern: - // { label: "Arch: arm", pattern: "arch/arm/.*" }, - // { label: "Arch: arm64", pattern: "arch/arm64/.*" }, ... - var archLabels = []; - var label = ""; - for (const c of config) { - // Get the Arch Label - if (c.startsWith('"')) { // "Arch: arm": - label = c.split('"')[1]; // Arch: arm - - } else if (c.startsWith('- any-glob-to-any-file:')) { // - any-glob-to-any-file: 'arch/arm/**' - // Convert the Glob Pattern to Regex Pattern - const pattern = c.split("'")[1] // arch/arm/** - .split('.').join('\\.') // . becomes \. - .split('*').join('[^/]*') // * becomes [^/]* - .split('[^/]*[^/]*').join('.*'); // ** becomes .* - archLabels.push({ - label, // Arch: arm - pattern: '^' + pattern + '$' // Match the Line Start and Line End - }); - - } else { - // We don't support all rules of `actions/labeler` - throw new Error('.github/labeler.yml should contain only changed-files and any-glob-to-any-file, not: ' + c); - } - } - - // Search the filenames for matching Arch Labels - for (const archLabel of archLabels) { - if (prLabels.includes(archLabel.label)) { - break; - } - for (const file of listFilesResponse) { - const re = new RegExp(archLabel.pattern); - const match = re.test(file.filename); - if (match && !prLabels.includes(archLabel.label)) { - prLabels.push(archLabel.label); - break; - } - } - } - console.log({ prLabels }); - - // Save the PR Number and PR Labels into a PR Artifact - // e.g. 'Size: XS\nArch: avr\n' - const dir = 'pr'; - fs.mkdirSync(dir); - fs.writeFileSync(dir + '/pr-id.txt', pull_number + '\n'); - fs.writeFileSync(dir + '/pr-labels.txt', prLabels.join('\n') + '\n'); - - # Upload the PR Artifact as pr.zip - - name: Upload PR artifact - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 - with: - name: pr - path: pr/ diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 9a82b0362..94256ee1a 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -1,4 +1,4 @@ -name: Lint +name: โ„๏ธ Lint on: [pull_request] @@ -6,29 +6,14 @@ concurrency: group: lint-${{ github.event.pull_request.number || github.ref }} cancel-in-progress: true -permissions: - contents: read - jobs: - lint: - permissions: - contents: read # for actions/checkout to fetch code - statuses: write # for github/super-linter to mark status of each linter run - name: Lint + yamllint: + name: ๐Ÿบ YAML runs-on: ubuntu-latest steps: - - uses: actions/checkout@v7 - with: - fetch-depth: 0 - - run: mkdir super-linter.report - - name: Lint - uses: github/super-linter@v7 + - uses: actions/checkout@v2 + - name: ๐Ÿงน YAML Lint + uses: github/super-linter@v4 env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - VALIDATE_ALL_CODEBASE: false - VALIDATE_PYTHON_BLACK: true - VALIDATE_PYTHON_FLAKE8: true - PYTHON_FLAKE8_CONFIG_FILE: setup.cfg - VALIDATE_PYTHON_ISORT: true - PYTHON_ISORT_CONFIG_FILE: setup.cfg VALIDATE_YAML: true + FILTER_REGEX_INCLUDE: .*\.github/.* diff --git a/.github/workflows/pr_labeler.yml b/.github/workflows/pr_labeler.yml deleted file mode 100644 index 26ed16441..000000000 --- a/.github/workflows/pr_labeler.yml +++ /dev/null @@ -1,90 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# This workflow will fetch the PR Labels from the PR Artifact, and write -# the PR Labels into the PR. The workflow is called after the -# "pull_request" trigger (labeler.yml). This "workflow_run" trigger uses a -# GitHub Token with Write Permission, so we must never run any untrusted -# code from the PR, and we must always extract and use the PR Artifact -# safely. See https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=321719166#GitHubActionsSecurity-Buildstriggeredwithworkflow_run -name: "Set Pull Request Labels" -on: - workflow_run: - workflows: ["Pull Request Labeler"] - types: - - completed - -jobs: - pr_labeler: - permissions: - contents: read - pull-requests: write - issues: write - runs-on: ubuntu-latest - if: > - github.event.workflow_run.event == 'pull_request' && - github.event.workflow_run.conclusion == 'success' - steps: - # Download the PR Artifact, containing PR Number and PR Labels - - name: Download PR artifact - uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 - with: - script: | - const artifacts = await github.rest.actions.listWorkflowRunArtifacts({ - owner: context.repo.owner, - repo: context.repo.repo, - run_id: ${{ github.event.workflow_run.id }}, - }); - const matchArtifact = artifacts.data.artifacts.filter((artifact) => { - return artifact.name == "pr" - })[0]; - const download = await github.rest.actions.downloadArtifact({ - owner: context.repo.owner, - repo: context.repo.repo, - artifact_id: matchArtifact.id, - archive_format: 'zip', - }); - const fs = require('fs'); - fs.writeFileSync('${{github.workspace}}/pr.zip', Buffer.from(download.data)); - - # Unzip the PR Artifact - - name: Unzip PR artifact - run: unzip pr.zip - - # Write the PR Labels into the PR - - name: Write PR labels - uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - script: | - const owner = context.repo.owner; - const repo = context.repo.repo; - const fs = require('fs'); - - // Read the PR Number and PR Labels from the PR Artifact - // e.g. 'Size: XS\nArch: avr\n' - const issue_number = Number(fs.readFileSync('pr-id.txt')); - const labels = fs.readFileSync('pr-labels.txt', 'utf8') - .split('\n') // Split by newline - .filter(s => (s != '')); // Remove empty lines - console.log({ issue_number, labels }); - - // Write the PR Labels into the PR - // e.g. [ 'Size: XS', 'Arch: avr' ] - await github.rest.issues.setLabels({ - owner, - repo, - issue_number, - labels - }); diff --git a/.gitignore b/.gitignore index d0382885b..0ae73233a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,51 +1,30 @@ *.a -*.dbo -*.dba *.adb *.asm +*.d *.dSYM *.exe -*.gcno -*.gcda *.hobj *.i -*.inf *.lib *.lst *.o -*.wo *.obj *.rel *.src *.swp *.sym -*.su -*.map *~ -.built -.context .depend .kconfig -*.lock /bin -/bin_debug /boot_romfsimg.h /external /Kconfig /romfs.img -/staging /symtab_apps.c -/wasm cscope.out Make.dep .context # nuttx/$(TOPDIR)/Makefile.[unix|win]::$(DIRLINKS_EXTERNAL_DIRS) .dirlinks -.vscode -.DS_Store -build -.ccls-cache -compile_commands.json -.aider* -.clang-format -.cache diff --git a/Application.mk b/Application.mk index bc83121a9..b03ff59c0 100644 --- a/Application.mk +++ b/Application.mk @@ -1,8 +1,6 @@ ############################################################################ # apps/Application.mk # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -25,18 +23,12 @@ # has the value "m" ifneq ($(MAINSRC),) - ifeq ($(DYNLIB),y) + ifeq ($(MODULE),m) + BUILD_MODULE = y + endif + + ifeq ($(CONFIG_BUILD_KERNEL),y) BUILD_MODULE = y - MODAELFFLAGS = $(CMODULELFFLAGS) - MODCFLAGS = $(CMODULEFLAGS) - MODCXXFLAGS = $(CXXMODULEFLAGS) - MODLDFLAGS = $(LDMODULEFLAGS) - else ifneq ($(or $(filter y,$(CONFIG_BUILD_KERNEL)), $(filter m,$(MODULE))),) - BUILD_MODULE = y - MODAELFFLAGS = $(AELFFLAGS) - MODCFLAGS = $(CELFFLAGS) - MODCXXFLAGS = $(CXXELFFLAGS) - MODLDFLAGS = $(LDELFFLAGS) endif endif @@ -45,18 +37,16 @@ endif # we need to fix up the path so the DELIM will match the actual delimiter. ifeq ($(CONFIG_WINDOWS_NATIVE),y) - CWD = $(strip ${shell echo %CD% | cut -d: -f2}) +CWD = $(strip ${shell echo %CD% | cut -d: -f2}) else - CWD = $(CURDIR) +CWD = $(CURDIR) endif -SUFFIX ?= $(subst $(DELIM),.,$(CWD)) - -PROGNAME := $(subst ",,$(PROGNAME)) - -# Add the static application library to the linked libraries. - -LDLIBS += $(call CONVERT_PATH,$(BIN)) +# Add the static application library to the linked libraries. Don't do this +# with CONFIG_BUILD_KERNEL as there is no static app library +ifneq ($(CONFIG_BUILD_KERNEL),y) + LDLIBS += $(call CONVERT_PATH,$(BIN)) +endif # When building a module, link with the compiler runtime. # This should be linked after libapps. Consider that mbedtls in libapps @@ -65,125 +55,39 @@ ifeq ($(BUILD_MODULE),y) # Revisit: This only works for gcc and clang. # Do other compilers have similar? COMPILER_RT_LIB = $(shell $(CC) $(ARCHCPUFLAGS) --print-libgcc-file-name) - ifeq ($(wildcard $(COMPILER_RT_LIB)),) - # if "--print-libgcc-file-name" unable to find the correct libgcc PATH - # then go ahead and try "--print-file-name" - COMPILER_RT_LIB := $(wildcard $(shell $(CC) $(ARCHCPUFLAGS) --print-file-name $(notdir $(COMPILER_RT_LIB)))) + ifneq ($(COMPILER_RT_LIB),) + LDLIBS += $(COMPILER_RT_LIB) endif - LDLIBS += $(COMPILER_RT_LIB) endif -# Apps compilation can achieve out-of-tree intermediate products -# by specifying "PREFIX" to a directory in its own Makefile. -# Default value is NULL, -# Make sure the out-of-tree directory exists and ends with $(DELIM) when setting it. - -PREFIX ?= +SUFFIX = $(subst $(DELIM),.,$(CWD)) +PROGNAME := $(shell echo $(PROGNAME)) # Object files RASRCS = $(filter %.s,$(ASRCS)) CASRCS = $(filter %.S,$(ASRCS)) -RAOBJS = $(RASRCS:%=$(PREFIX)%$(SUFFIX)$(OBJEXT)) -CAOBJS = $(CASRCS:%=$(PREFIX)%$(SUFFIX)$(OBJEXT)) -COBJS = $(CSRCS:%=$(PREFIX)%$(SUFFIX)$(OBJEXT)) -CXXOBJS = $(CXXSRCS:%=$(PREFIX)%$(SUFFIX)$(OBJEXT)) -RUSTOBJS = $(RUSTSRCS:%=$(PREFIX)%$(SUFFIX)$(OBJEXT)) -ZIGOBJS = $(ZIGSRCS:%=$(PREFIX)%$(SUFFIX)$(OBJEXT)) -DOBJS = $(DSRCS:%=$(PREFIX)%$(SUFFIX)$(OBJEXT)) -SWIFTOBJS = $(SWIFTSRCS:%=$(PREFIX)%$(SUFFIX)$(OBJEXT)) +RAOBJS = $(RASRCS:=$(SUFFIX)$(OBJEXT)) +CAOBJS = $(CASRCS:=$(SUFFIX)$(OBJEXT)) +COBJS = $(CSRCS:=$(SUFFIX)$(OBJEXT)) +CXXOBJS = $(CXXSRCS:=$(SUFFIX)$(OBJEXT)) +RUSTOBJS = $(RUSTSRCS:=$(SUFFIX)$(OBJEXT)) MAINCXXSRCS = $(filter %$(CXXEXT),$(MAINSRC)) MAINCSRCS = $(filter %.c,$(MAINSRC)) MAINRUSTSRCS = $(filter %$(RUSTEXT),$(MAINSRC)) -MAINZIGSRCS = $(filter %$(ZIGEXT),$(MAINSRC)) -MAINDSRCS = $(filter %$(DEXT),$(MAINSRC)) -MAINSWIFTSRCS = $(filter %$(SWIFTEXT),$(MAINSRC)) -MAINCXXOBJ = $(MAINCXXSRCS:%=$(PREFIX)%$(SUFFIX)$(OBJEXT)) -MAINCOBJ = $(MAINCSRCS:%=$(PREFIX)%$(SUFFIX)$(OBJEXT)) -MAINRUSTOBJ = $(MAINRUSTSRCS:%=$(PREFIX)%$(SUFFIX)$(OBJEXT)) -MAINZIGOBJ = $(MAINZIGSRCS:%=$(PREFIX)%$(SUFFIX)$(OBJEXT)) -MAINDOBJ = $(MAINDSRCS:%=$(PREFIX)%$(SUFFIX)$(OBJEXT)) -MAINSWIFTOBJ = $(MAINSWIFTSRCS:%=$(PREFIX)%$(SUFFIX)$(OBJEXT)) +MAINCXXOBJ = $(MAINCXXSRCS:=$(SUFFIX)$(OBJEXT)) +MAINCOBJ = $(MAINCSRCS:=$(SUFFIX)$(OBJEXT)) +MAINRUSTOBJ = $(MAINRUSTSRCS:=$(SUFFIX)$(OBJEXT)) SRCS = $(ASRCS) $(CSRCS) $(CXXSRCS) $(MAINSRC) -OBJS = $(RAOBJS) $(CAOBJS) $(COBJS) $(CXXOBJS) $(RUSTOBJS) $(ZIGOBJS) $(DOBJS) $(SWIFTOBJS) $(EXTOBJS) +OBJS = $(RAOBJS) $(CAOBJS) $(COBJS) $(CXXOBJS) $(RUSTOBJS) ifneq ($(BUILD_MODULE),y) - OBJS += $(MAINCOBJ) $(MAINCXXOBJ) $(MAINRUSTOBJ) $(MAINZIGOBJ) $(MAINDOBJ) $(MAINSWIFTOBJ) + OBJS += $(MAINCOBJ) $(MAINCXXOBJ) $(MAINRUSTOBJ) endif -ifneq ($(strip $(PROGNAME)),) - PROGOBJ := $(MAINCOBJ) $(MAINCXXOBJ) $(MAINRUSTOBJ) $(MAINZIGOBJ) $(MAINDOBJ) $(MAINSWIFTOBJ) - PROGLIST := $(addprefix $(BINDIR)$(DELIM),$(PROGNAME)) - REGLIST := $(addprefix $(BUILTIN_REGISTRY)$(DELIM),$(addsuffix .bdat,$(PROGNAME))) - - NLIST := $(shell seq 1 $(words $(PROGNAME))) - $(foreach i, $(NLIST), \ - $(eval PROGNAME_$(word $i,$(PROGOBJ)) := $(word $i,$(PROGNAME))) \ - $(eval PROGSYM_$(word $i,$(PROGOBJ)) := $(subst -,_,$(word $i,$(PROGNAME)))) \ - $(eval PROGOBJ_$(word $i,$(PROGLIST)) := $(word $i,$(PROGOBJ))) \ - $(eval PRIORITY_$(word $i,$(REGLIST)) := \ - $(if $(word $i,$(PRIORITY)),$(word $i,$(PRIORITY)),$(lastword $(PRIORITY)))) \ - $(eval STACKSIZE_$(word $i,$(REGLIST)) := \ - $(if $(word $i,$(STACKSIZE)),$(word $i,$(STACKSIZE)),$(lastword $(STACKSIZE)))) \ - $(eval UID_$(word $i,$(REGLIST)) := \ - $(if $(word $i,$(UID)),$(word $i,$(UID)),$(lastword $(UID)))) \ - $(eval GID_$(word $i,$(REGLIST)) := \ - $(if $(word $i,$(GID)),$(word $i,$(GID)),$(lastword $(GID)))) \ - $(eval MODE_$(word $i,$(REGLIST)) := \ - $(if $(word $i,$(MODE)),$(word $i,$(MODE)),$(lastword $(MODE)))) \ - $(eval STACKSIZE_$(word $i,$(PROGLIST)) := $(STACKSIZE_$(word $i,$(REGLIST)))) \ - $(eval PRIORITY_$(word $i,$(PROGLIST)) := $(PRIORITY_$(word $i,$(REGLIST)))) \ - $(eval UID_$(word $i,$(PROGLIST)) := $(UID_$(word $i,$(REGLIST)))) \ - $(eval GID_$(word $i,$(PROGLIST)) := $(GID_$(word $i,$(REGLIST)))) \ - $(eval MODE_$(word $i,$(PROGLIST)) := $(MODE_$(word $i,$(REGLIST)))) \ - ) - - # Emit the application's configured attributes as absolute ELF symbols - # (nx_stacksize, nx_priority, and nx_uid/nx_gid/nx_mode under - # CONFIG_SCHED_USER_IDENTITY) so the binary loader can recover them. - # Per-target so each PROGLIST entry picks up its own STACKSIZE_/PRIORITY_. - - $(PROGLIST): MODLDFLAGS += \ - $(if $(STACKSIZE_$@),--defsym nx_stacksize=$(STACKSIZE_$@)) \ - $(if $(filter-out SCHED_PRIORITY_DEFAULT,$(PRIORITY_$@)),--defsym nx_priority=$(PRIORITY_$@)) -ifeq ($(CONFIG_SCHED_USER_IDENTITY),y) - $(PROGLIST): MODLDFLAGS += \ - $(if $(UID_$@),--defsym nx_uid=$(UID_$@)) \ - $(if $(GID_$@),--defsym nx_gid=$(GID_$@)) \ - $(if $(MODE_$@),--defsym nx_mode=$(MODE_$@)) -endif - - # Keep the attribute symbols through --strip-unneeded so the binary loader - # can still read them from the stripped runtime image in bin/. - $(PROGLIST): NX_KEEP = $(if $(STACKSIZE_$@),-K nx_stacksize) $(if $(filter-out SCHED_PRIORITY_DEFAULT,$(PRIORITY_$@)),-K nx_priority) $(if $(UID_$@),-K nx_uid) $(if $(GID_$@),-K nx_gid) $(if $(MODE_$@),-K nx_mode) -endif - -# Condition flags - -DO_REGISTRATION ?= y - -ifeq ($(PROGNAME),) - DO_REGISTRATION = n -endif - -ifeq ($(WASM_BUILD),y) - DO_REGISTRATION = n -endif - -ifeq ($(BUILD_MODULE),y) - DO_REGISTRATION = n -endif - -# Compile flags, notice the default flags only suitable for flat build - -ZIGELFFLAGS ?= $(ZIGFLAGS) -RUSTELFFLAGS ?= $(RUSTFLAGS) -DELFFLAGS ?= $(DFLAGS) -SWIFTELFFLAGS ?= $(SWIFTFLAGS) - DEPPATH += --dep-path . DEPPATH += --obj-path . @@ -191,239 +95,141 @@ VPATH += :. # Targets follow -all:: $(PREFIX).built - @: +all:: $(OBJS) .PHONY: clean depend distclean .PRECIOUS: $(BIN) define ELFASSEMBLE - $(ECHO_BEGIN)"AS: $1 " - $(Q) $(MODULECC) -c $(MODAELFFLAGS) $($(strip $1)_AELFFLAGS) $1 -o $2 - $(ECHO_END) + @echo "AS: $1" + $(Q) $(CC) -c $(AELFFLAGS) $($(strip $1)_AELFFLAGS) $1 -o $2 endef define ELFCOMPILE - $(ECHO_BEGIN)"CC: $1 " - $(Q) $(MODULECC) -c $(MODCFLAGS) $($(strip $1)_CELFFLAGS) $1 -o $2 - $(ECHO_END) + @echo "CC: $1" + $(Q) $(CC) -c $(CELFFLAGS) $($(strip $1)_CELFFLAGS) $1 -o $2 endef define ELFCOMPILEXX - $(ECHO_BEGIN)"CXX: $1 " - $(Q) $(CXX) -c $(MODCXXFLAGS) $($(strip $1)_CXXELFFLAGS) $1 -o $2 - $(ECHO_END) + @echo "CXX: $1" + $(Q) $(CXX) -c $(CXXELFFLAGS) $($(strip $1)_CXXELFFLAGS) $1 -o $2 endef define ELFCOMPILERUST - $(ECHO_BEGIN)"RUSTC: $1 " + @echo "RUSTC: $1" $(Q) $(RUSTC) --emit obj $(RUSTELFFLAGS) $($(strip $1)_RUSTELFFLAGS) $1 -o $2 - $(ECHO_END) -endef - -# Remove target suffix here since zig compiler add .o automatically -define ELFCOMPILEZIG - $(ECHO_BEGIN)"ZIG: $1 " - $(Q) $(ZIG) build-obj $(ZIGELFFLAGS) $($(strip $1)_ZIGELFFLAGS) --name $(basename $2) $1 - $(ECHO_END) -endef - -define ELFCOMPILED - $(ECHO_BEGIN)"DC: $1 " - $(Q) $(DC) -c $(DELFFLAGS) $($(strip $1)_DELFFLAGS) $1 -of $2 - $(ECHO_END) -endef - -define ELFCOMPILESWIFT - $(ECHO_BEGIN)"SWIFTC: $1 " - $(Q) $(SWIFTC) -c $(SWIFTELFFLAGS) $($(strip $1)_SWIFTELFFLAGS) $1 -o $2 - $(ECHO_END) endef define ELFLD - $(ECHO_BEGIN)"LD: $2 " - $(Q) $(MODULELD) $(MODLDFLAGS) $(LDMAP) $(LDLIBPATH) $(ARCHCRT0OBJ) $1 $(LDSTARTGROUP) $(LDLIBS) $(LDENDGROUP) -o $2 - $(ECHO_END) + @echo "LD: $2" + $(Q) $(LD) $(LDELFFLAGS) $(LDLIBPATH) $(ARCHCRT0OBJ) $1 $(LDLIBS) -o $2 endef -# rename "main()" in $1 to "xxx_main()" and save to $2 -define RENAMEMAIN - $(ECHO_BEGIN)"Rename main() in $1 and save to $2" - $(Q) ${shell cat $1 | sed -e "s/fn[ ]\+main/fn $(addsuffix _main,$(PROGSYM_$@))/" > $2} - $(ECHO_END) -endef - -$(RAOBJS): $(PREFIX)%.s$(SUFFIX)$(OBJEXT): %.s - $(if $(and $(CONFIG_MODULES),$(MODAELFFLAGS)), \ +$(RAOBJS): %.s$(SUFFIX)$(OBJEXT): %.s + $(if $(and $(CONFIG_BUILD_LOADABLE),$(AELFFLAGS)), \ $(call ELFASSEMBLE, $<, $@), $(call ASSEMBLE, $<, $@)) -$(CAOBJS): $(PREFIX)%.S$(SUFFIX)$(OBJEXT): %.S - $(if $(and $(CONFIG_MODULES),$(MODAELFFLAGS)), \ +$(CAOBJS): %.S$(SUFFIX)$(OBJEXT): %.S + $(if $(and $(CONFIG_BUILD_LOADABLE),$(AELFFLAGS)), \ $(call ELFASSEMBLE, $<, $@), $(call ASSEMBLE, $<, $@)) -$(COBJS): $(PREFIX)%.c$(SUFFIX)$(OBJEXT): %.c - $(if $(and $(CONFIG_MODULES),$(MODCFLAGS)), \ +$(COBJS): %.c$(SUFFIX)$(OBJEXT): %.c + $(if $(and $(CONFIG_BUILD_LOADABLE),$(CELFFLAGS)), \ $(call ELFCOMPILE, $<, $@), $(call COMPILE, $<, $@)) -$(CXXOBJS): $(PREFIX)%$(CXXEXT)$(SUFFIX)$(OBJEXT): %$(CXXEXT) - $(if $(and $(CONFIG_MODULES),$(MODCXXFLAGS)), \ +$(CXXOBJS): %$(CXXEXT)$(SUFFIX)$(OBJEXT): %$(CXXEXT) + $(if $(and $(CONFIG_BUILD_LOADABLE),$(CXXELFFLAGS)), \ $(call ELFCOMPILEXX, $<, $@), $(call COMPILEXX, $<, $@)) -$(RUSTOBJS): $(PREFIX)%$(RUSTEXT)$(SUFFIX)$(OBJEXT): %$(RUSTEXT) - $(if $(and $(CONFIG_MODULES),$(CELFFLAGS)), \ +$(RUSTOBJS): %$(RUSTEXT)$(SUFFIX)$(OBJEXT): %$(RUSTEXT) + $(if $(and $(CONFIG_BUILD_LOADABLE),$(CELFFLAGS)), \ $(call ELFCOMPILERUST, $<, $@), $(call COMPILERUST, $<, $@)) -$(ZIGOBJS): $(PREFIX)%$(ZIGEXT)$(SUFFIX)$(OBJEXT): %$(ZIGEXT) - $(if $(and $(CONFIG_MODULES), $(CELFFLAGS)), \ - $(call ELFCOMPILEZIG, $<, $@), $(call COMPILEZIG, $<, $@)) - -$(DOBJS): $(PREFIX)%$(DEXT)$(SUFFIX)$(OBJEXT): %$(DEXT) - $(if $(and $(CONFIG_MODULES), $(CELFFLAGS)), \ - $(call ELFCOMPILED, $<, $@), $(call COMPILED, $<, $@)) - -$(SWIFTOBJS): $(PREFIX)%$(SWIFTEXT)$(SUFFIX)$(OBJEXT): %$(SWIFTEXT) - $(if $(and $(CONFIG_MODULES), $(CELFFLAGS)), \ - $(call ELFCOMPILESWIFT, $<, $@), $(call COMPILESWIFT, $<, $@)) - -AROBJS := -ifneq ($(OBJS),) -SORTOBJS := $(sort $(OBJS)) -$(eval $(call SPLITVARIABLE,OBJS_SPILT,$(SORTOBJS),100)) -$(foreach BATCH, $(OBJS_SPILT_TOTAL), \ - $(foreach obj, $(OBJS_SPILT_$(BATCH)), \ - $(eval substitute := $(patsubst %$(OBJEXT),%_$(BATCH)$(OBJEXT),$(obj))) \ - $(eval AROBJS += $(substitute)) \ - $(eval $(call AROBJSRULES, $(substitute),$(obj))) \ - ) \ -) -endif - -$(PREFIX).built: $(AROBJS) - $(call SPLITVARIABLE,ALL_OBJS,$(AROBJS),100) - $(foreach BATCH, $(ALL_OBJS_TOTAL), \ - $(if $(strip $(ALL_OBJS_$(BATCH))), \ - $(shell $(call ARLOCK, $(call CONVERT_PATH,$(BIN)), $(ALL_OBJS_$(BATCH)))) \ - ) \ - ) - $(Q) touch $@ +archive: + $(call ARCHIVE_ADD, $(call CONVERT_PATH,$(BIN)), $(OBJS)) ifeq ($(BUILD_MODULE),y) -$(MAINCXXOBJ): $(PREFIX)%$(CXXEXT)$(SUFFIX)$(OBJEXT): %$(CXXEXT) - $(if $(and $(CONFIG_MODULES),$(MODCXXFLAGS)), \ +$(MAINCXXOBJ): %$(CXXEXT)$(SUFFIX)$(OBJEXT): %$(CXXEXT) + $(if $(and $(CONFIG_BUILD_LOADABLE),$(CXXELFFLAGS)), \ $(call ELFCOMPILEXX, $<, $@), $(call COMPILEXX, $<, $@)) -$(MAINCOBJ): $(PREFIX)%.c$(SUFFIX)$(OBJEXT): %.c - $(if $(and $(CONFIG_MODULES),$(MODCFLAGS)), \ +$(MAINCOBJ): %.c$(SUFFIX)$(OBJEXT): %.c + $(if $(and $(CONFIG_BUILD_LOADABLE),$(CELFFLAGS)), \ $(call ELFCOMPILE, $<, $@), $(call COMPILE, $<, $@)) -$(MAINZIGOBJ): $(PREFIX)%$(ZIGEXT)$(SUFFIX)$(OBJEXT): %$(ZIGEXT) - $(if $(and $(CONFIG_MODULES),$(CELFFLAGS)), \ - $(call ELFCOMPILEZIG, $<, $@), $(call COMPILEZIG, $<, $@)) +PROGLIST := $(wordlist 1,$(words $(MAINCOBJ) $(MAINCXXOBJ) $(MAINRUSTOBJ)),$(PROGNAME)) +PROGLIST := $(addprefix $(BINDIR)$(DELIM),$(PROGLIST)) +PROGOBJ := $(MAINCOBJ) $(MAINCXXOBJ) $(MAINRUSTOBJ) -$(MAINDOBJ): $(PREFIX)%$(DEXT)$(SUFFIX)$(OBJEXT): %$(DEXT) - $(if $(and $(CONFIG_MODULES),$(CELFFLAGS)), \ - $(call ELFCOMPILED, $<, $@), $(call COMPILED, $<, $@)) - -$(MAINSWIFTOBJ): $(PREFIX)%$(SWIFTEXT)$(SUFFIX)$(OBJEXT): %$(SWIFTEXT) - $(if $(and $(CONFIG_MODULES),$(CELFFLAGS)), \ - $(call ELFCOMPILESWIFT, $<, $@), $(call COMPILESWIFT, $<, $@)) - -$(PROGLIST): $(MAINCOBJ) $(MAINCXXOBJ) $(MAINRUSTOBJ) $(MAINZIGOBJ) $(MAINDOBJ) $(MAINSWIFTOBJ) +$(PROGLIST): $(MAINCOBJ) $(MAINCXXOBJ) $(MAINRUSTOBJ) $(Q) mkdir -p $(BINDIR) - $(call ELFLD, $(PROGOBJ_$@), $(call CONVERT_PATH,$@)) - $(Q) chmod +x $@ -ifneq ($(CONFIG_DEBUG_SYMBOLS),) - $(Q) mkdir -p $(BINDIR_DEBUG) - $(Q) cp $@ $(BINDIR_DEBUG) - $(Q) $(MODULESTRIP) $(NX_KEEP) $@ + $(call ELFLD,$(firstword $(PROGOBJ)),$(call CONVERT_PATH,$(firstword $(PROGLIST)))) + $(Q) chmod +x $(firstword $(PROGLIST)) +ifneq ($(CONFIG_DEBUG_SYMBOLS),y) + $(Q) $(STRIP) $(firstword $(PROGLIST)) endif + $(eval PROGLIST=$(filter-out $(firstword $(PROGLIST)),$(PROGLIST))) + $(eval PROGOBJ=$(filter-out $(firstword $(PROGOBJ)),$(PROGOBJ))) install:: $(PROGLIST) - @: else -$(MAINCXXOBJ): $(PREFIX)%$(CXXEXT)$(SUFFIX)$(OBJEXT): %$(CXXEXT) - $(eval $<_CXXFLAGS += ${shell $(DEFINE) "$(CXX)" main=$(addsuffix _main,$(PROGSYM_$@))}) - $(eval $<_CXXELFFLAGS += ${shell $(DEFINE) "$(CXX)" main=$(addsuffix _main,$(PROGSYM_$@))}) - $(if $(and $(CONFIG_MODULES),$(MODCXXFLAGS)), \ +MAINNAME := $(addsuffix _main,$(PROGNAME)) + +$(MAINCXXOBJ): %$(CXXEXT)$(SUFFIX)$(OBJEXT): %$(CXXEXT) + $(eval $<_CXXFLAGS += ${shell $(DEFINE) "$(CXX)" main=$(firstword $(MAINNAME))}) + $(eval $<_CXXELFFLAGS += ${shell $(DEFINE) "$(CXX)" main=$(firstword $(MAINNAME))}) + $(eval MAINNAME=$(filter-out $(firstword $(MAINNAME)),$(MAINNAME))) + $(if $(and $(CONFIG_BUILD_LOADABLE),$(CXXELFFLAGS)), \ $(call ELFCOMPILEXX, $<, $@), $(call COMPILEXX, $<, $@)) -$(MAINCOBJ): $(PREFIX)%.c$(SUFFIX)$(OBJEXT): %.c - $(eval $<_CFLAGS += ${DEFINE_PREFIX}main=$(addsuffix _main,$(PROGSYM_$@))) - $(eval $<_CELFFLAGS += ${DEFINE_PREFIX}main=$(addsuffix _main,$(PROGSYM_$@))) - $(if $(and $(CONFIG_MODULES),$(MODCFLAGS)), \ +$(MAINCOBJ): %.c$(SUFFIX)$(OBJEXT): %.c + $(eval $<_CFLAGS += ${shell $(DEFINE) "$(CC)" main=$(firstword $(MAINNAME))}) + $(eval $<_CELFFLAGS += ${shell $(DEFINE) "$(CC)" main=$(firstword $(MAINNAME))}) + $(eval MAINNAME=$(filter-out $(firstword $(MAINNAME)),$(MAINNAME))) + $(if $(and $(CONFIG_BUILD_LOADABLE),$(CELFFLAGS)), \ $(call ELFCOMPILE, $<, $@), $(call COMPILE, $<, $@)) -$(MAINRUSTOBJ): $(PREFIX)%$(RUSTEXT)$(SUFFIX)$(OBJEXT): %$(RUSTEXT) - $(if $(and $(CONFIG_MODULES),$(CELFFLAGS)), \ +$(MAINRUSTOBJ): %$(RUSTEXT)$(SUFFIX)$(OBJEXT): %$(RUSTEXT) + $(if $(and $(CONFIG_BUILD_LOADABLE),$(CELFFLAGS)), \ $(call ELFCOMPILERUST, $<, $@), $(call COMPILERUST, $<, $@)) -$(MAINZIGOBJ): $(PREFIX)%$(ZIGEXT)$(SUFFIX)$(OBJEXT): %$(ZIGEXT) - $(Q) $(call RENAMEMAIN, $<, $(basename $<)_tmp.zig) - $(if $(and $(CONFIG_MODULES),$(CELFFLAGS)), \ - $(call ELFCOMPILEZIG, $(basename $<)_tmp.zig, $@), $(call COMPILEZIG, $(basename $<)_tmp.zig, $@)) - $(Q) rm -f $(basename $<)_tmp.zig - -$(MAINDOBJ): $(PREFIX)%$(DEXT)$(SUFFIX)$(OBJEXT): %$(DEXT) - $(if $(and $(CONFIG_MODULES),$(CELFFLAGS)), \ - $(call ELFCOMPILED, $<, $@), $(call COMPILED, $<, $@)) - -$(MAINSWIFTOBJ): $(PREFIX)%$(SWIFTEXT)$(SUFFIX)$(OBJEXT): %$(SWIFTEXT) - $(if $(and $(CONFIG_MODULES),$(CELFFLAGS)), \ - $(call ELFCOMPILESWIFT, $<, $@), $(call COMPILESWIFT, $<, $@)) - install:: - @: endif # BUILD_MODULE -postinstall:: - @: - context:: -ifeq ($(DO_REGISTRATION),y) +ifneq ($(PROGNAME),) + +REGLIST := $(addprefix $(BUILTIN_REGISTRY)$(DELIM),$(addsuffix .bdat,$(PROGNAME))) +APPLIST := $(PROGNAME) $(REGLIST): $(DEPCONFIG) Makefile - $(eval PROGNAME_$@ := $(basename $(notdir $@))) - $(eval PROGSYM_$@ := $(subst -,_,$(PROGNAME_$@))) -ifeq ($(CONFIG_SCHED_USER_IDENTITY),y) - $(call REGISTER,$(PROGNAME_$@),$(PRIORITY_$@),$(STACKSIZE_$@),$(if $(BUILD_MODULE),,$(PROGSYM_$@)_main),$(UID_$@),$(GID_$@),$(MODE_$@)) -else - $(call REGISTER,$(PROGNAME_$@),$(PRIORITY_$@),$(STACKSIZE_$@),$(if $(BUILD_MODULE),,$(PROGSYM_$@)_main)) -endif + $(call REGISTER,$(firstword $(APPLIST)),$(firstword $(PRIORITY)),$(firstword $(STACKSIZE)),$(if $(BUILD_MODULE),,$(firstword $(APPLIST))_main)) + $(eval APPLIST=$(filter-out $(firstword $(APPLIST)),$(APPLIST))) + $(if $(filter-out $(firstword $(PRIORITY)),$(PRIORITY)),$(eval PRIORITY=$(filter-out $(firstword $(PRIORITY)),$(PRIORITY)))) + $(if $(filter-out $(firstword $(STACKSIZE)),$(STACKSIZE)),$(eval STACKSIZE=$(filter-out $(firstword $(STACKSIZE)),$(STACKSIZE)))) register:: $(REGLIST) - @: else register:: - @: endif -$(PREFIX).depend: Makefile $(wildcard $(foreach SRC, $(SRCS), $(addsuffix /$(SRC), $(subst :, ,$(VPATH))))) $(DEPCONFIG) - $(shell echo "# Gen Make.dep automatically" >$(PREFIX)Make.dep) - $(call SPLITVARIABLE,ALL_DEP_OBJS,$^,100) - $(foreach BATCH, $(ALL_DEP_OBJS_TOTAL), \ - $(shell $(MKDEP) $(DEPPATH) --obj-suffix .c$(SUFFIX)$(OBJEXT) "$(CC)" -- $(CFLAGS) -- $(filter %.c,$(ALL_DEP_OBJS_$(BATCH))) >>$(PREFIX)Make.dep) \ - $(shell $(MKDEP) $(DEPPATH) --obj-suffix .S$(SUFFIX)$(OBJEXT) "$(CC)" -- $(CFLAGS) -- $(filter %.S,$(ALL_DEP_OBJS_$(BATCH))) >>$(PREFIX)Make.dep) \ - $(shell $(MKDEP) $(DEPPATH) --obj-suffix $(CXXEXT)$(SUFFIX)$(OBJEXT) "$(CXX)" -- $(CXXFLAGS) -- $(filter %$(CXXEXT),$(ALL_DEP_OBJS_$(BATCH))) >>$(PREFIX)Make.dep) \ - ) +.depend: Makefile $(wildcard $(foreach SRC, $(SRCS), $(addsuffix /$(SRC), $(subst :, ,$(VPATH))))) $(DEPCONFIG) + $(Q) $(MKDEP) $(DEPPATH) --obj-suffix .c$(SUFFIX)$(OBJEXT) "$(CC)" -- $(CFLAGS) -- $(filter %.c,$^) >Make.dep + $(Q) $(MKDEP) $(DEPPATH) --obj-suffix .S$(SUFFIX)$(OBJEXT) "$(CC)" -- $(CFLAGS) -- $(filter %.S,$^) >>Make.dep + $(Q) $(MKDEP) $(DEPPATH) --obj-suffix $(CXXEXT)$(SUFFIX)$(OBJEXT) "$(CXX)" -- $(CXXFLAGS) -- $(filter %$(CXXEXT),$^) >>Make.dep $(Q) touch $@ -depend:: $(PREFIX).depend - @: +depend:: .depend clean:: - $(call DELFILE, .built) - $(call CLEANAROBJS) $(call CLEAN) + distclean:: clean - $(call DELFILE, .kconfig) $(call DELFILE, Make.dep) $(call DELFILE, .depend) --include $(PREFIX)Make.dep - -# Include Wasm specific definitions -include $(APPDIR)/tools/Wasm.mk +-include Make.dep diff --git a/CMakeLists.txt b/CMakeLists.txt deleted file mode 100644 index 55110defb..000000000 --- a/CMakeLists.txt +++ /dev/null @@ -1,83 +0,0 @@ -# ############################################################################## -# apps/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -# ~~~ -# Important note: -# This CMakeLists.txt is not meant as a top-level CMakeLists.txt. Instead, -# CMake must be run using the top-level CMakeLists.txt from the nuttx -# repository and point to this directory via NUTTX_APPS_DIR. For example: -# cmake -S <nuttx-dir> -B <build-dir> [...] -DNUTTX_APPS_DIR=<apps-dir> -# ~~~ - -if(CONFIG_APPS_DIR) - # add apps cmake modules - list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake) - include(nuttx_add_luamod) - include(nuttx_add_wamrmod) - include(nuttx_add_rust) - include(nuttx_wasm_interface) - nuttx_add_library(apps) - if(NOT EXISTS {NUTTX_APPS_BINDIR}/dummy.c) - file(TOUCH ${NUTTX_APPS_BINDIR}/dummy.c) - endif() - target_sources(apps PRIVATE ${NUTTX_APPS_BINDIR}/dummy.c) -endif() - -file(MAKE_DIRECTORY ${NUTTX_APPS_BINDIR}/include) -include_directories(include) -include_directories(${NUTTX_APPS_BINDIR}/include) - -add_subdirectory(audioutils) -add_subdirectory(benchmarks) -add_subdirectory(boot) -add_subdirectory(canutils) -add_subdirectory(crypto) -add_subdirectory(fsutils) -add_subdirectory(games) -add_subdirectory(graphics) -add_subdirectory(industry) -add_subdirectory(inertial) -add_subdirectory(interpreters) -add_subdirectory(logging) -add_subdirectory(lte) -add_subdirectory(math) -add_subdirectory(mlearning) -add_subdirectory(netutils) -add_subdirectory(nshlib) -add_subdirectory(platform) -add_subdirectory(sdr) -add_subdirectory(system) -add_subdirectory(tee) -add_subdirectory(testing) -add_subdirectory(videoutils) -add_subdirectory(wireless) - -# add examples and external at the end to allow library dependencies -add_subdirectory(examples) -if(EXISTS ${CMAKE_CURRENT_LIST_DIR}/external) - add_subdirectory(external) -endif() - -add_subdirectory(tools) # after traversing all subdirectories -add_subdirectory(builtin) # must be last - -nuttx_generate_kconfig() diff --git a/DISCLAIMER b/DISCLAIMER new file mode 100644 index 000000000..7cf2deeb4 --- /dev/null +++ b/DISCLAIMER @@ -0,0 +1,6 @@ +Apache NuttX is an effort undergoing incubation at The Apache Software Foundation (ASF), +sponsored by the Apache Incubator. Incubation is required of all newly accepted projects +until a further review indicates that the infrastructure, communications, and decision +making process have stabilized in a manner consistent with other successful ASF projects. +While incubation status is not necessarily a reflection of the completeness or stability +of the code, it does indicate that the project has yet to be fully endorsed by the ASF. diff --git a/Directory.mk b/Directory.mk index ff42d2390..0b3ed7dee 100644 --- a/Directory.mk +++ b/Directory.mk @@ -1,8 +1,6 @@ ############################################################################ # apps/Directory.mk # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -24,16 +22,11 @@ include $(APPDIR)/Make.defs # Sub-directories that have been built or configured. -SUBDIRS := $(dir $(wildcard */Makefile)) -CONFIGSUBDIRS := $(filter-out $(dir $(wildcard */Kconfig)),$(SUBDIRS)) -CLEANSUBDIRS := $(dir $(wildcard *$(DELIM).built)) -CLEANSUBDIRS += $(dir $(wildcard */.depend)) -CLEANSUBDIRS += $(dir $(wildcard */.kconfig)) +SUBDIRS := $(dir $(wildcard *$(DELIM)Makefile)) +CONFIGSUBDIRS := $(filter-out $(dir $(wildcard *$(DELIM)Kconfig)),$(SUBDIRS)) +CLEANSUBDIRS += $(dir $(wildcard *$(DELIM).depend)) +CLEANSUBDIRS += $(dir $(wildcard *$(DELIM).kconfig)) CLEANSUBDIRS := $(sort $(CLEANSUBDIRS)) -ifeq ($(CONFIG_WINDOWS_NATIVE),y) - CONFIGSUBDIRS := $(subst /,\,$(CONFIGSUBDIRS)) - CLEANSUBDIRS := $(subst /,\,$(CLEANSUBDIRS)) -endif all: nothing @@ -50,16 +43,15 @@ install: preconfig: $(foreach SDIR, $(CONFIGSUBDIRS), $(SDIR)_preconfig) ifneq ($(MENUDESC),) $(Q) $(MKKCONFIG) -m $(MENUDESC) -endif $(Q) touch .kconfig +endif clean: $(foreach SDIR, $(CLEANSUBDIRS), $(SDIR)_clean) - @: distclean: $(foreach SDIR, $(CLEANSUBDIRS), $(SDIR)_distclean) ifneq ($(MENUDESC),) $(call DELFILE, Kconfig) -endif $(call DELFILE, .kconfig) +endif -include Make.dep diff --git a/LICENSE b/LICENSE index 84b5055da..c9c999015 100644 --- a/LICENSE +++ b/LICENSE @@ -1282,7 +1282,7 @@ apps/system/telnet/telnet_client.c Copyright (C) 2017 Gregory Nutt. All rights reserved. Author: Gregory Nutt <gnutt@nuttx.org> - The original authors of libtelnet are listed below. Per their license, + The original authors of libtelnet are listed below. Per their licesne, "The author or authors of this code dedicate any and all copyright interest in this code to the public domain. We make this dedication for the benefit of the public at large and to the detriment of our heirs and @@ -1723,554 +1723,3 @@ apps/netutils/chat/chat.h LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -apps/testing/crypto/3descbc.c -========================= - $OpenBSD: des3.c,v 1.8 2010/10/15 10:39:12 jsg Exp $ - Copyright (c) 2002 Markus Friedl. All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -apps/testing/crypto/aesctr.c -========================= - $OpenBSD: aesctr.c,v 1.1 2005/05/25 05:47:53 markus Exp $ - Copyright (c) 2005 Markus Friedl <markus@openbsd.org> - - Permission to use, copy, modify, and distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -apps/testing/crypto/aesxts.c -========================= - $OpenBSD: aes_xts.c,v 1.2 2013/10/06 16:59:34 jsing Exp $ - Copyright (c) 2002 Markus Friedl. All rights reserved. - Copyright (c) 2008 Damien Miller. All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -apps/testing/crypto/hmac.c -========================= - Copyright (c) 2008 Damien Bergamini <damien.bergamini@free.fr> - - Permission to use, copy, modify, and distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -apps/crypto/tinydtls -====================== - /******************************************************************************* - * Copyright (c) 2011, 2012, 2013, 2014, 2015, 2016 Olaf Bergmann (TZI) and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and Eclipse Distribution License v. 1.0 which accompanies this distribution. - * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html - * and the Eclipse Distribution License is available at - * http://www.eclipse.org/org/documents/edl-v10.php. - * Contributors: - * Olaf Bergmann - initial API and implementation - * Hauke Mehrtens - memory optimization, ECC integration - *******************************************************************************/ - -apps/netutils/wakaama -===================== - *Eclipse Distribution License - v 1.0* - - Copyright (c) 2007, Eclipse Foundation, Inc. and its licensors. - - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - * Neither the name of the Eclipse Foundation, Inc. nor the names of - its contributors may be used to endorse or promote products derived - from this software without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS - IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -apps/crypto/libsodium -===================== - ISC License - - Copyright (c) 2013-2023 - Frank Denis <j at pureftpd dot org> - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -apps/crypto/wolfssl -=================== - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1989, 1991 Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change free -software--to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Lesser General Public License instead.) You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -this service if you wish), that you receive source code or can get it -if you want it, that you can change the software or use pieces of it -in new free programs; and that you know you can do these things. - - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if you -distribute copies of the software, or if you modify it. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must give the recipients all the rights that -you have. You must make sure that they, too, receive or can get the -source code. And you must show them these terms so they know their -rights. - - We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. - - Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, we -want its recipients to know that what they have is not the original, so -that any problems introduced by others will not reflect on the original -authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at all. - - The precise terms and conditions for copying, distribution and -modification follow. - - GNU GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License applies to any program or other work which contains -a notice placed by the copyright holder saying it may be distributed -under the terms of this General Public License. The "Program", below, -refers to any such program or work, and a "work based on the Program" -means either the Program or any derivative work under copyright law: -that is to say, a work containing the Program or a portion of it, -either verbatim or with modifications and/or translated into another -language. (Hereinafter, translation is included without limitation in -the term "modification".) Each licensee is addressed as "you". - -Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the -Program (independent of having been made by running the Program). -Whether that is true depends on what the Program does. - - 1. You may copy and distribute verbatim copies of the Program's -source code as you receive it, in any medium, provided that you -conspicuously and appropriately publish on each copy an appropriate -copyright notice and disclaimer of warranty; keep intact all the -notices that refer to this License and to the absence of any warranty; -and give any other recipients of the Program a copy of this License -along with the Program. - -You may charge a fee for the physical act of transferring a copy, and -you may at your option offer warranty protection in exchange for a fee. - - 2. You may modify your copy or copies of the Program or any portion -of it, thus forming a work based on the Program, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) You must cause the modified files to carry prominent notices - stating that you changed the files and the date of any change. - - b) You must cause any work that you distribute or publish, that in - whole or in part contains or is derived from the Program or any - part thereof, to be licensed as a whole at no charge to all third - parties under the terms of this License. - - c) If the modified program normally reads commands interactively - when run, you must cause it, when started running for such - interactive use in the most ordinary way, to print or display an - announcement including an appropriate copyright notice and a - notice that there is no warranty (or else, saying that you provide - a warranty) and that users may redistribute the program under - these conditions, and telling the user how to view a copy of this - License. (Exception: if the Program itself is interactive but - does not normally print such an announcement, your work based on - the Program is not required to print an announcement.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Program, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Program. - -In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: - - a) Accompany it with the complete corresponding machine-readable - source code, which must be distributed under the terms of Sections - 1 and 2 above on a medium customarily used for software interchange; or, - - b) Accompany it with a written offer, valid for at least three - years, to give any third party, for a charge no more than your - cost of physically performing source distribution, a complete - machine-readable copy of the corresponding source code, to be - distributed under the terms of Sections 1 and 2 above on a medium - customarily used for software interchange; or, - - c) Accompany it with the information you received as to the offer - to distribute corresponding source code. (This alternative is - allowed only for noncommercial distribution and only if you - received the program in object code or executable form with such - an offer, in accord with Subsection b above.) - -The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, complete source -code means all the source code for all modules it contains, plus any -associated interface definition files, plus the scripts used to -control compilation and installation of the executable. However, as a -special exception, the source code distributed need not include -anything that is normally distributed (in either source or binary -form) with the major components (compiler, kernel, and so on) of the -operating system on which the executable runs, unless that component -itself accompanies the executable. - -If distribution of executable or object code is made by offering -access to copy from a designated place, then offering equivalent -access to copy the source code from the same place counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. - - 4. You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense or distribute the Program is -void, and will automatically terminate your rights under this License. -However, parties who have received copies, or rights, from you under -this License will not have their licenses terminated so long as such -parties remain in full compliance. - - 5. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. - - 6. Each time you redistribute the Program (or any work based on the -Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program subject to -these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to -this License. - - 7. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Program at all. For example, if a patent -license would not permit royalty-free redistribution of the Program by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Program. - -If any portion of this section is held invalid or unenforceable under -any particular circumstance, the balance of the section is intended to -apply and the section as a whole is intended to apply in other -circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system, which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 8. If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program under this License -may add an explicit geographical distribution limitation excluding -those countries, so that distribution is permitted only in or among -countries not thus excluded. In such case, this License incorporates -the limitation as if written in the body of this License. - - 9. The Free Software Foundation may publish revised and/or new versions -of the General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - -Each version is given a distinguishing version number. If the Program -specifies a version number of this License which applies to it and "any -later version", you have the option of following the terms and conditions -either of that version or of any later version published by the Free -Software Foundation. If the Program does not specify a version number of -this License, you may choose any version ever published by the Free Software -Foundation. - - 10. If you wish to incorporate parts of the Program into other free -programs whose distribution conditions are different, write to the author -to ask for permission. For software which is copyrighted by the Free -Software Foundation, write to the Free Software Foundation; we sometimes -make exceptions for this. Our decision will be guided by the two goals -of preserving the free status of all derivatives of our free software and -of promoting the sharing and reuse of software generally. - - NO WARRANTY - - 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY -FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN -OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES -PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED -OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS -TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE -PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, -REPAIR OR CORRECTION. - - 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR -REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, -INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING -OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED -TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY -YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER -PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE -POSSIBILITY OF SUCH DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - <one line to give the program's name and a brief idea of what it does.> - Copyright (C) <year> <name of author> - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -Also add information on how to contact you by electronic and paper mail. - -If the program is interactive, make it output a short notice like this -when it starts in an interactive mode: - - Gnomovision version 69, Copyright (C) year name of author - Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, the commands you use may -be called something other than `show w' and `show c'; they could even be -mouse-clicks or menu items--whatever suits your program. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the program, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the program - `Gnomovision' (which makes passes at compilers) written by James Hacker. - - <signature of Ty Coon>, 1 April 1989 - Ty Coon, President of Vice - -This General Public License does not permit incorporating your program into -proprietary programs. If your program is a subroutine library, you may -consider it more useful to permit linking proprietary applications with the -library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. - -apps/testing/sd_stress -apps/testing/sd_bench -=================== - -Copyright (c) 2016-2021 PX4 Development Team. All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions -are met: - -1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. -2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in - the documentation and/or other materials provided with the - distribution. -3. Neither the name PX4 nor the names of its contributors may be - used to endorse or promote products derived from this software - without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. - - -netutils/bare/ -============== - -MIT License - -Copyright (c) 2022 Frank Smit - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/Make.defs b/Make.defs index ab79ce71c..0cfa55529 100644 --- a/Make.defs +++ b/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -21,7 +19,17 @@ ############################################################################ TOPDIR ?= $(APPDIR)/import --include $(TOPDIR)/Make.defs +include $(TOPDIR)/Make.defs + +# The GNU make CURDIR will always be a POSIX-like path with forward slashes +# as path segment separators. This is fine for the above inclusions but +# will cause problems later for the native build. If we know that this is +# a native build, then we need to fix up the APPDIR path for subsequent +# use + +ifeq ($(CONFIG_WINDOWS_NATIVE),y) +APPDIR := ${shell echo %CD%} +endif # Application Directories @@ -29,16 +37,11 @@ TOPDIR ?= $(APPDIR)/import # CLEANDIRS is the list of all top-level directories containing Makefiles. # It is used only for cleaning. -BUILDIRS := $(dir $(wildcard $(APPDIR)/*/Make.defs)) -BUILDIRS := $(filter-out $(APPDIR)/import/,$(BUILDIRS)) -CONFIGDIRS := $(filter-out $(APPDIR)/builtin/,$(BUILDIRS)) -CONFIGDIRS := $(filter-out $(dir $(wildcard $(APPDIR)/*/Kconfig)),$(CONFIGDIRS)) -CLEANDIRS := $(dir $(wildcard $(APPDIR)/*/Makefile)) -ifeq ($(CONFIG_WINDOWS_NATIVE),y) - BUILDIRS := $(subst /,\,$(BUILDIRS)) - CONFIGDIRS := $(subst /,\,$(CONFIGDIRS)) - CLEANDIRS := $(subst /,\,$(CLEANDIRS)) -endif +BUILDIRS := $(dir $(wildcard $(APPDIR)$(DELIM)*$(DELIM)Make.defs)) +BUILDIRS := $(filter-out $(APPDIR)$(DELIM)import$(DELIM),$(BUILDIRS)) +CONFIGDIRS := $(filter-out $(APPDIR)$(DELIM)builtin$(DELIM),$(BUILDIRS)) +CONFIGDIRS := $(filter-out $(dir $(wildcard $(APPDIR)$(DELIM)*$(DELIM)Kconfig)),$(CONFIGDIRS)) +CLEANDIRS := $(dir $(wildcard $(APPDIR)$(DELIM)*$(DELIM)Makefile)) # CONFIGURED_APPS is the application directories that should be built in # the current configuration. @@ -46,7 +49,7 @@ endif CONFIGURED_APPS := define Add_Application - include $(1)Make.defs + include $(1)Make.defs endef $(foreach BDIR, $(BUILDIRS), $(eval $(call Add_Application,$(BDIR)))) @@ -55,9 +58,6 @@ $(foreach BDIR, $(BUILDIRS), $(eval $(call Add_Application,$(BDIR)))) CXXEXT ?= .cxx RUSTEXT ?= .rs -ZIGEXT ?= .zig -DEXT ?= .d -SWIFTEXT ?= .swift # Library path @@ -66,12 +66,10 @@ LIBPATH ?= $(TOPDIR)$(DELIM)staging # The install path BINDIR ?= $(APPDIR)$(DELIM)bin -BINDIR_DEBUG ?= $(APPDIR)$(DELIM)bin_debug # The final build target -BIN ?= $(APPDIR)$(DELIM)libapps$(LIBEXT) -WBIN ?= $(APPDIR)$(DELIM)wasm$(DELIM)libwasm$(LIBEXT) +BIN ?= $(APPDIR)$(DELIM)libapps$(LIBEXT) # Tools @@ -83,108 +81,21 @@ endif # Builtin Registration -BUILTIN_REGISTRY ?= $(APPDIR)$(DELIM)builtin$(DELIM)registry -DEPCONFIG ?= $(TOPDIR)$(DELIM).config +BUILTIN_REGISTRY = $(APPDIR)$(DELIM)builtin$(DELIM)registry +DEPCONFIG = $(TOPDIR)$(DELIM).config -ifeq ($(CONFIG_WINDOWS_NATIVE),y) -ifeq ($(CONFIG_SCHED_USER_IDENTITY),y) define REGISTER $(Q) echo Register: $1 - $(Q) echo { "$(subst ",,$(1))", $2, $3, $(patsubst ,0,$(subst ",,$(4))), $(patsubst ,0,$(5)), $(patsubst ,0,$(6)), $(patsubst ,0555,$(7))}, > "$(BUILTIN_REGISTRY)$(DELIM)$1.bdat" - $(Q) echo int $(subst ",,$(4))(int argc, char *argv[]); > "$(BUILTIN_REGISTRY)$(DELIM)$1.pdat" - - $(Q) touch $(BUILTIN_REGISTRY)$(DELIM).updated" -endef -else -define REGISTER - $(Q) echo Register: $1 - $(Q) echo { "$(subst ",,$(1))", $2, $3, $(subst ",,$(4)) }, > "$(BUILTIN_REGISTRY)$(DELIM)$1.bdat" - $(Q) echo int $(subst ",,$(4))(int argc, char *argv[]); > "$(BUILTIN_REGISTRY)$(DELIM)$1.pdat" - - $(Q) touch $(BUILTIN_REGISTRY)$(DELIM).updated" -endef -endif -else -ifeq ($(CONFIG_SCHED_USER_IDENTITY),y) -define REGISTER - $(Q) echo "{ \"$1\", $2, $3, $(patsubst ,0,$(4)), $(patsubst ,0,$(5)), $(patsubst ,0,$(6)), $(patsubst ,0555,$(7)) }," > "$(BUILTIN_REGISTRY)$(DELIM)$1.bdat" + $(Q) echo { \"$1\", $2, $3, $4 }, > "$(BUILTIN_REGISTRY)$(DELIM)$1.bdat" $(Q) if [ ! -z $4 ]; then \ echo "int $4(int argc, char *argv[]);" > "$(BUILTIN_REGISTRY)$(DELIM)$1.pdat"; \ fi; $(Q) touch "$(BUILTIN_REGISTRY)$(DELIM).updated" endef -else -define REGISTER - $(Q) echo "Register: $1" - $(Q) echo "{ \"$1\", $2, $3, $4 }," > "$(BUILTIN_REGISTRY)$(DELIM)$1.bdat" - $(Q) if [ ! -z $4 ]; then \ - echo "int $4(int argc, char *argv[]);" > "$(BUILTIN_REGISTRY)$(DELIM)$1.pdat"; \ - fi; - $(Q) touch "$(BUILTIN_REGISTRY)$(DELIM).updated" -endef -endif -endif # Standard include path -CFLAGS += ${INCDIR_PREFIX}"$(APPDIR)$(DELIM)include" -CXXFLAGS += ${INCDIR_PREFIX}"$(APPDIR)$(DELIM)include" +CFLAGS += ${shell $(INCDIR) "$(CC)" "$(APPDIR)$(DELIM)include"} +CXXFLAGS += ${shell $(INCDIR) "$(CC)" "$(APPDIR)$(DELIM)include"} NUTTXLIB ?= $(call CONVERT_PATH,$(TOPDIR)$(DELIM)staging) - -# SPLITVARIABLE - Split long variables into specified batches -# Usage: $(call SPLITVARIABLE, variable-def, variable-ref, batch-size) -# -# Example: VAR:= a b c x y z foo bar -# $(call SPLITVARIABLE, VAR, $(VAR), 3) -# $(foreach, num, $(VAR_TOTAL), $(shell echo $(VAR_$(num)))) -# Return new variable definition: -# $(variable-def)_TOTAL : total split sequence , start with 1. -# $(variable-def)_$(num) : newly defined variable , ended with batch num. -# In the case above: -# $(VAR_TOTAL) = 1 2 3 -# $(VAR_1) = a b c -# $(VAR_2) = x y z -# $(VAR_3) = foo bar - -define SPLITVARIABLE - $(eval SPLITVARIABLE_PREFIX = $(1)) - $(eval BATCH_SIZE = $(3)) - $(eval TOTAL_BATCH = $(shell expr $(words $(2)) / $(BATCH_SIZE) + 1)) - $(eval $(SPLITVARIABLE_PREFIX)_TOTAL = $(shell seq 1 $(TOTAL_BATCH))) - $(foreach idx, $($(SPLITVARIABLE_PREFIX)_TOTAL), \ - $(eval FROMINDEX=$(shell expr 1 + $(idx) \* $(BATCH_SIZE) - $(BATCH_SIZE))) \ - $(eval $(SPLITVARIABLE_PREFIX)_$(idx)=$(wordlist $(FROMINDEX), $(shell expr $(FROMINDEX) + $(BATCH_SIZE) - 1), $(2))) \ - ) -endef - -define ARLOCK - flock $1.lock $(call ARCHIVE, $1, $(2)) -endef - -# dynamic AR target - -define AROBJSRULES -$(1) : $(2) - @ cp $(2) $(1) -endef - -# CLEANAROBJS - del AR target files exclusively - -ifeq ($(CONFIG_WINDOWS_NATIVE),y) -define CLEANAROBJS - $(call DELFILE,$(subst /,\,$(AROBJS))) - $(call DELFILE,$(subst /,\,$(OBJS))) - $(eval OBJS :=) -endef -else -define CLEANAROBJS - $(call SPLITVARIABLE,CLEAN_AROBJS,${AROBJS},100) - $(foreach BATCH, $(CLEAN_AROBJS_TOTAL), \ - $(shell rm -rf $(CLEAN_AROBJS_$(BATCH)))) - $(call SPLITVARIABLE,CLEAN_OBJS,${OBJS},100) - $(foreach BATCH, $(CLEAN_OBJS_TOTAL), \ - $(shell rm -rf $(CLEAN_OBJS_$(BATCH)))) - $(eval OBJS :=) -endef -endif diff --git a/Makefile b/Makefile index 5a3570538..f33a9cffc 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -22,20 +20,8 @@ export APPDIR = $(CURDIR) include $(APPDIR)/Make.defs -include $(APPDIR)/tools/Wasm.mk - -# The GNU make CURDIR will always be a POSIX-like path with forward slashes -# as path segment separators. This is fine for the above inclusions but -# will cause problems later for the native build. If we know that this is -# a native build, then we need to fix up the APPDIR path for subsequent -# use - -ifeq ($(CONFIG_WINDOWS_NATIVE),y) - export APPDIR = $(subst /,\,$(CURDIR)) -endif # Symbol table for loadable apps. -# SYMTABEXT: Extra arguments for mksymtab.sh SYMTABSRC = symtab_apps.c SYMTABOBJ = $(SYMTABSRC:.c=$(OBJEXT)) @@ -45,15 +31,16 @@ SYMTABOBJ = $(SYMTABSRC:.c=$(OBJEXT)) # We first remove libapps.a before letting the other rules add objects to it # so that we ensure libapps.a does not contain objects from prior build -all: $(BIN) +all: + $(RM) $(BIN) + $(MAKE) $(BIN) .PHONY: import install dirlinks export .depdirs preconfig depend clean distclean -.PHONY: context postinstall clean_context context_all postinstall_all register register_all +.PHONY: context clean_context context_all register register_all .PRECIOUS: $(BIN) $(foreach SDIR, $(CONFIGURED_APPS), $(eval $(call SDIR_template,$(SDIR),all))) $(foreach SDIR, $(CONFIGURED_APPS), $(eval $(call SDIR_template,$(SDIR),install))) -$(foreach SDIR, $(CONFIGURED_APPS), $(eval $(call SDIR_template,$(SDIR),postinstall))) $(foreach SDIR, $(CONFIGURED_APPS), $(eval $(call SDIR_template,$(SDIR),context))) $(foreach SDIR, $(CONFIGURED_APPS), $(eval $(call SDIR_template,$(SDIR),register))) $(foreach SDIR, $(CONFIGURED_APPS), $(eval $(call SDIR_template,$(SDIR),depend))) @@ -68,25 +55,6 @@ $(INCDIR): $(TOPDIR)/tools/incdir.c IMPORT_TOOLS = $(MKDEP) $(INCDIR) -ifeq ($(CONFIG_TOOLS_WASM_BUILD),y) - -configure_wasm: - $(Q) cmake -B$(APPDIR)$(DELIM)tools$(DELIM)Wasm$(DELIM)build \ - $(APPDIR)$(DELIM)tools$(DELIM)Wasm \ - -DAPPDIR=$(APPDIR) -DTOPDIR=$(TOPDIR) \ - -DWASI_SDK_PATH=$(WASI_SDK_PATH) \ - -DKCONFIG_FILE_PATH=$(TOPDIR)$(DELIM).config - -context_wasm: configure_wasm - $(Q) cmake --build $(APPDIR)$(DELIM)tools$(DELIM)Wasm$(DELIM)build - -else - -context_wasm: - -endif - - # In the KERNEL build, we must build and install all of the modules. No # symbol table is needed @@ -94,12 +62,12 @@ ifeq ($(CONFIG_BUILD_KERNEL),y) install: $(foreach SDIR, $(CONFIGURED_APPS), $(SDIR)_install) -$(BIN): $(foreach SDIR, $(CONFIGURED_APPS), $(SDIR)_all) - -.import: $(BIN) +.import: $(foreach SDIR, $(CONFIGURED_APPS), $(SDIR)_all) + $(Q) for app in ${CONFIGURED_APPS}; do \ + $(MAKE) -C "$${app}" archive ; \ + done $(Q) install libapps.a $(APPDIR)$(DELIM)import$(DELIM)libs $(Q) $(MAKE) install - $(Q) $(MAKE) postinstall import: $(IMPORT_TOOLS) $(Q) $(MAKE) context TOPDIR="$(APPDIR)$(DELIM)import" @@ -112,37 +80,32 @@ else # In FLAT and protected modes, the modules have already been created. A # symbol table is required. -ifeq ($(CONFIG_MODULES),) -ifeq ($(CONFIG_WINDOWS_NATIVE),y) +ifeq ($(CONFIG_BUILD_LOADABLE),) + $(BIN): $(foreach SDIR, $(CONFIGURED_APPS), $(SDIR)_all) -else -$(BIN): $(foreach SDIR, $(CONFIGURED_APPS), $(SDIR)_all) - $(call LINK_WASM) -endif + $(Q) for app in ${CONFIGURED_APPS}; do \ + $(MAKE) -C "$${app}" archive ; \ + done else $(SYMTABSRC): $(foreach SDIR, $(CONFIGURED_APPS), $(SDIR)_all) + $(Q) for app in ${CONFIGURED_APPS}; do \ + $(MAKE) -C "$${app}" archive ; \ + done $(Q) $(MAKE) install - $(Q) $(APPDIR)$(DELIM)tools$(DELIM)mksymtab.sh $(BINDIR) $(SYMTABEXT) >$@.tmp + $(Q) $(APPDIR)$(DELIM)tools$(DELIM)mksymtab.sh $(BINDIR) >$@.tmp $(Q) $(call TESTANDREPLACEFILE, $@.tmp, $@) -ifneq ($(CONFIG_ARM_TOOLCHAIN_GHS),y) $(SYMTABOBJ): %$(OBJEXT): %.c - $(call COMPILE, $<, $@, -fno-lto -fno-builtin) -else -$(SYMTABOBJ): %$(OBJEXT): %.c - $(call COMPILE, $<, $@, -Onolink) -endif + $(call COMPILE, -fno-lto $<, $@) $(BIN): $(SYMTABOBJ) - $(call ARLOCK, $(call CONVERT_PATH,$(BIN)), $^) - $(call LINK_WASM) + $(call ARCHIVE_ADD, $(call CONVERT_PATH,$(BIN)), $^) -endif # !CONFIG_MODULES +endif # !CONFIG_BUILD_LOADABLE install: $(foreach SDIR, $(CONFIGURED_APPS), $(SDIR)_install) - $(Q) $(MAKE) postinstall_all # Link nuttx @@ -178,15 +141,10 @@ dirlinks: context_all: $(foreach SDIR, $(CONFIGURED_APPS), $(SDIR)_context) register_all: $(foreach SDIR, $(CONFIGURED_APPS), $(SDIR)_register) -postinstall_all: $(foreach SDIR, $(CONFIGURED_APPS), $(SDIR)_postinstall) -staging: - $(Q) mkdir -p $@ - -context: | staging +context: $(Q) $(MAKE) context_all $(Q) $(MAKE) register_all - $(Q) $(MAKE) context_wasm Kconfig: $(foreach SDIR, $(CONFIGDIRS), $(call MAKE_template,$(SDIR),preconfig)) @@ -200,9 +158,7 @@ ifneq ($(EXPORTDIR),) ifneq ($(CONFIG_BUILD_KERNEL),y) ifneq ($(BUILTIN_REGISTRY),) for f in "${BUILTIN_REGISTRY}"$(DELIM)*.bdat "${BUILTIN_REGISTRY}"$(DELIM)*.pdat ; do \ - if [ -f "$${f}" ]; then \ - cp -f "$${f}" "${EXPORTDIR}"$(DELIM)registry ; \ - fi \ + [ -f "$${f}" ] && cp -f "$${f}" "${EXPORTDIR}"$(DELIM)registry ; \ done endif endif @@ -225,18 +181,27 @@ clean: $(foreach SDIR, $(CLEANDIRS), $(SDIR)_clean) $(call DELFILE, $(BIN)) $(call DELFILE, Kconfig) $(call DELDIR, $(BINDIR)) - $(call DELDIR, $(BINDIR_DEBUG)) $(call CLEAN) distclean: $(foreach SDIR, $(CLEANDIRS), $(SDIR)_distclean) - $(call DELFILE, *.lock) +ifeq ($(CONFIG_WINDOWS_NATIVE),y) + $(Q) ( if exist external ( \ + echo ********************************************************" \ + echo * The external directory/link must be removed manually *" \ + echo ********************************************************" \ + ) +else + $(Q) ( if [ -e external ]; then \ + echo "********************************************************"; \ + echo "* The external directory/link must be removed manually *"; \ + echo "********************************************************"; \ + fi; \ + ) +endif $(call DELFILE, .depend) $(call DELFILE, $(SYMTABSRC)) $(call DELFILE, $(SYMTABOBJ)) $(call DELFILE, $(BIN)) $(call DELFILE, Kconfig) $(call DELDIR, $(BINDIR)) - $(call DELDIR, staging) - $(call DELDIR, wasm) - $(call DELDIR, $(APPDIR)$(DELIM)tools$(DELIM)Wasm$(DELIM)build) $(call CLEAN) diff --git a/README.md b/README.md index 204931977..d6f72c208 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ NuttX directory. Like: If all of the above conditions are TRUE, then NuttX will be able to find the application directory. If your application directory has a different name or is -located at a different position, then you will have to inform the NuttX build +location at a different position, then you will have to inform the NuttX build system of that location. There are several ways to do that: 1) You can define `CONFIG_APPS_DIR` to be the full path to your application @@ -140,7 +140,7 @@ project. One must: main() ``` - 4. Set the requirements in the file: `Makefile`, specifically the lines: + 4. Set the requirements in the file: `Makefile`, specially the lines: ```makefile PROGNAME = progname @@ -181,8 +181,10 @@ A: Here are three: You can copy any pieces that you like from the old apps/directory to your custom apps directory as necessary. - This is documented in `NuttX/boards/README.txt` and `NuttX Porting Guide` - online at <https://cwiki.apache.org/confluence/display/NUTTX/Porting+Guide>. + This is documented in `NuttX/boards/README.txt` and + `nuttx/Documentation/NuttXPortingGuide.html` (Online at + https://bitbucket.org/nuttx/nuttx/src/master/Documentation/NuttXPortingGuide.html#apndxconfigs + under _Build options_). And in the `apps/README.txt` file. 3) If you like the random collection of stuff in the `apps/` directory but just want to expand the existing components with your own, external @@ -254,5 +256,4 @@ Technology Software Unrestricted (TSU) exception (see the BIS Export Administrat Regulations, Section 740.13) for both object code and source code. The following provides more details on the included cryptographic software: -https://tls.mbed.org/supported-ssl-ciphersuites. -https://github.com/intel/tinycrypt +https://tls.mbed.org/supported-ssl-ciphersuites. \ No newline at end of file diff --git a/audioutils/CMakeLists.txt b/audioutils/CMakeLists.txt deleted file mode 100644 index 06428bfbb..000000000 --- a/audioutils/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -# ############################################################################## -# apps/audioutils/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -nuttx_add_subdirectory() - -nuttx_generate_kconfig(MENUDESC "Audio Utility libraries") diff --git a/audioutils/Make.defs b/audioutils/Make.defs deleted file mode 100644 index c61302297..000000000 --- a/audioutils/Make.defs +++ /dev/null @@ -1,23 +0,0 @@ -############################################################################ -# apps/audioutils/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(wildcard $(APPDIR)/audioutils/*/Make.defs) diff --git a/audioutils/Makefile b/audioutils/Makefile deleted file mode 100644 index 698b58c20..000000000 --- a/audioutils/Makefile +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/audioutils/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -MENUDESC = "Audio Utility libraries" - -include $(APPDIR)/Directory.mk diff --git a/audioutils/fmsynth/CMakeLists.txt b/audioutils/fmsynth/CMakeLists.txt deleted file mode 100644 index 839793f3e..000000000 --- a/audioutils/fmsynth/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -# ############################################################################## -# apps/audioutils/fmsynth/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_AUDIOUTILS_FMSYNTH_LIB) - target_sources(apps PRIVATE fmsynth.c fmsynth_eg.c fmsynth_op.c) -endif() diff --git a/audioutils/fmsynth/Kconfig b/audioutils/fmsynth/Kconfig deleted file mode 100644 index 81d7977d0..000000000 --- a/audioutils/fmsynth/Kconfig +++ /dev/null @@ -1,10 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config AUDIOUTILS_FMSYNTH_LIB - bool "FM Synthesizer Library" - default n - ---help--- - Enable support for the FM Synthesizer library. diff --git a/audioutils/fmsynth/Make.defs b/audioutils/fmsynth/Make.defs deleted file mode 100644 index e53b36887..000000000 --- a/audioutils/fmsynth/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/audioutils/fmsynth/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_AUDIOUTILS_FMSYNTH_LIB),) -CONFIGURED_APPS += $(APPDIR)/audioutils/fmsynth -endif diff --git a/audioutils/fmsynth/Makefile b/audioutils/fmsynth/Makefile deleted file mode 100644 index 2ce054331..000000000 --- a/audioutils/fmsynth/Makefile +++ /dev/null @@ -1,27 +0,0 @@ -############################################################################ -# apps/audioutils/fmsynth/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -CSRCS = fmsynth.c fmsynth_eg.c fmsynth_op.c - -include $(APPDIR)/Application.mk diff --git a/audioutils/fmsynth/fmsynth.c b/audioutils/fmsynth/fmsynth.c deleted file mode 100644 index 883ad4680..000000000 --- a/audioutils/fmsynth/fmsynth.c +++ /dev/null @@ -1,270 +0,0 @@ -/**************************************************************************** - * apps/audioutils/fmsynth/fmsynth.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <stdlib.h> -#include <audioutils/fmsynth.h> - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define WRAP_ROUND_TIME_SEC (10) - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static int max_phase_time; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * name: fetch_feedback - ****************************************************************************/ - -static void fetch_feedback(FAR fmsynth_op_t *ops) -{ - while (ops != NULL) - { - fmsynthop_update_feedback(ops); - ops = ops->parallelop; - } -} - -/**************************************************************************** - * name: update_phase - ****************************************************************************/ - -static void update_phase(FAR fmsynth_sound_t *snd) -{ - snd->phase_time++; - if (snd->phase_time >= max_phase_time) - { - snd->phase_time = 0; - } -} - -/**************************************************************************** - * name: sound_modulate - ****************************************************************************/ - -static int sound_modulate(FAR fmsynth_sound_t *snd) -{ - int out = 0; - FAR fmsynth_op_t *op; - - if (snd->operators == NULL) - { - return out; - } - - fetch_feedback(snd->operators); - - for (op = snd->operators; op != NULL; op = op->parallelop) - { - out += fmsynthop_operate(op, snd->phase_time); - } - - update_phase(snd); - - return out * snd->volume / FMSYNTH_MAX_VOLUME; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * name: fmsynth_initialize - ****************************************************************************/ - -int fmsynth_initialize(int fs) -{ - max_phase_time = fs * WRAP_ROUND_TIME_SEC; - return fmsynthop_set_samplerate(fs); -} - -/**************************************************************************** - * name: create_fmsynthsnd - ****************************************************************************/ - -FAR fmsynth_sound_t *create_fmsynthsnd(FAR fmsynth_sound_t *snd) -{ - if (snd) - { - snd->own_allocate = 0; - snd->phase_time = 0; - snd->volume = FMSYNTH_MAX_VOLUME; - snd->operators = NULL; - snd->next_sound = NULL; - } - - return snd; -} - -/**************************************************************************** - * name: fmsynthsnd_create - ****************************************************************************/ - -FAR fmsynth_sound_t *fmsynthsnd_create(void) -{ - FAR fmsynth_sound_t *ret; - ret = (FAR fmsynth_sound_t *)malloc(sizeof(fmsynth_sound_t)); - - if (ret) - { - create_fmsynthsnd(ret); - ret->own_allocate = 1; - } - - return ret; -} - -/**************************************************************************** - * name: fmsynthsnd_delete - ****************************************************************************/ - -void fmsynthsnd_delete(FAR fmsynth_sound_t *snd) -{ - if (snd != NULL && snd->own_allocate == 1) - { - free(snd); - } -} - -/**************************************************************************** - * name: fmsynthsnd_set_operator - ****************************************************************************/ - -int fmsynthsnd_set_operator(FAR fmsynth_sound_t *snd, FAR fmsynth_op_t *op) -{ - snd->operators = op; - - return OK; -} - -/**************************************************************************** - * name: fmsynthsnd_set_soundfreq - ****************************************************************************/ - -void fmsynthsnd_set_soundfreq(FAR fmsynth_sound_t *snd, float freq) -{ - FAR fmsynth_op_t *op; - - for (op = snd->operators; op != NULL; op = op->parallelop) - { - fmsynthop_set_soundfreq(op, freq); - fmsynthop_start(op); - } -} - -/**************************************************************************** - * name: fmsynthsnd_stop - ****************************************************************************/ - -void fmsynthsnd_stop(FAR fmsynth_sound_t *snd) -{ - FAR fmsynth_op_t *op; - - for (op = snd->operators; op != NULL; op = op->parallelop) - { - fmsynthop_stop(op); - } -} - -/**************************************************************************** - * name: fmsynthsnd_set_volume - ****************************************************************************/ - -void fmsynthsnd_set_volume(FAR fmsynth_sound_t *snd, float vol) -{ - snd->volume = vol * FMSYNTH_MAX_VOLUME; -} - -/**************************************************************************** - * name: fmsynthsnd_add_subsound - ****************************************************************************/ - -int fmsynthsnd_add_subsound(FAR fmsynth_sound_t *top, - FAR fmsynth_sound_t *sub) -{ - FAR fmsynth_sound_t *s = top; - - if (!top || !sub) - { - return ERROR; - } - - for (s = top; s->next_sound; s = s->next_sound); - - s->next_sound = sub; - - return OK; -} - -/**************************************************************************** - * name: fmsynth_rendering - ****************************************************************************/ - -int fmsynth_rendering(FAR fmsynth_sound_t *snd, - FAR int16_t *sample, int sample_num, int chnum, - fmsynth_tickcb_t cb, unsigned long cbarg) -{ - int i; - int ch; - int out; - FAR fmsynth_sound_t *itr; - - for (i = 0; i < sample_num; i += chnum) - { - out = 0; - for (itr = snd; itr != NULL; itr = itr->next_sound) - { - out = out + sound_modulate(itr); - } - - for (ch = 0; ch < chnum; ch++) - { - *sample++ = (int16_t)out; - } - - if (cb != NULL) - { - cb(cbarg); - } - } - - if (i > sample_num) - { - i -= chnum; - } - - /* Return total bytes stored in the buffer */ - - return i * sizeof(int16_t); -} diff --git a/audioutils/fmsynth/fmsynth_eg.c b/audioutils/fmsynth/fmsynth_eg.c deleted file mode 100644 index 849e35a5d..000000000 --- a/audioutils/fmsynth/fmsynth_eg.c +++ /dev/null @@ -1,209 +0,0 @@ -/**************************************************************************** - * apps/audioutils/fmsynth/fmsynth_eg.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <stdlib.h> -#include <limits.h> - -#include <audioutils/fmsynth_eg.h> - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define CONVERT_INITVAL(lv) (int)((lv) * FMSYNTH_MAX_EGLEVEL) - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * name: set_egparams - ****************************************************************************/ - -static int set_egparams(int fs, - FAR fmsynth_egparam_t *param, - FAR struct fmsynth_eglevel_s *target_level, - FAR struct fmsynth_eglevel_s *last_level) -{ - param->initval = CONVERT_INITVAL(last_level->level); - param->period = fs * target_level->period_ms / 1000; - param->diff2next = CONVERT_INITVAL(target_level->level) - - CONVERT_INITVAL(last_level->level); - - if (param->initval < -FMSYNTH_MAX_EGLEVEL || - param->initval > FMSYNTH_MAX_EGLEVEL || param->period < 0) - { - return -1; - } - - return 0; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * name: create_fmsyntheg - ****************************************************************************/ - -FAR fmsynth_eg_t *create_fmsyntheg(FAR fmsynth_eg_t *eg) -{ - int i; - - if (eg) - { - eg->state = EGSTATE_RELEASED; - eg->state_counter = 0; - for (i = 0; i < EGSTATE_MAX; i++) - { - eg->state_params[i].initval = 0; - eg->state_params[i].period = 0; - } - - eg->state_params[EGSTATE_RELEASED].initval = FMSYNTH_MAX_EGLEVEL; - } - - return eg; -} - -/**************************************************************************** - * name: fmsyntheg_create - ****************************************************************************/ - -FAR fmsynth_eg_t *fmsyntheg_create(void) -{ - FAR fmsynth_eg_t *ret = (FAR fmsynth_eg_t *)malloc(sizeof(fmsynth_eg_t)); - - return create_fmsyntheg(ret); -} - -/**************************************************************************** - * name: fmsyntheg_delete - ****************************************************************************/ - -void fmsyntheg_delete(FAR fmsynth_eg_t *eg) -{ - if (eg != NULL) - { - free(eg); - } -} - -/**************************************************************************** - * name: fmsyntheg_set_param - ****************************************************************************/ - -int fmsyntheg_set_param(FAR fmsynth_eg_t *eg, - int fs, FAR fmsynth_eglevels_t *levels) -{ - int errcnt = 0; - - if (fs <= 0) - { - return ERROR; - } - - errcnt += set_egparams(fs, &eg->state_params[EGSTATE_ATTACK], - &levels->attack, &levels->release); - - errcnt += set_egparams(fs, &eg->state_params[EGSTATE_DECAYBREAK], - &levels->decaybrk, &levels->attack); - - errcnt += set_egparams(fs, &eg->state_params[EGSTATE_DECAY], - &levels->decay, &levels->decaybrk); - - errcnt += set_egparams(fs, &eg->state_params[EGSTATE_SUSTAIN], - &levels->sustain, &levels->decay); - - errcnt += set_egparams(fs, &eg->state_params[EGSTATE_RELEASE], - &levels->release, &levels->sustain); - - eg->state_params[EGSTATE_RELEASED].initval = - CONVERT_INITVAL(levels->release.level); - - return errcnt ? ERROR : OK; -} - -/**************************************************************************** - * name: fmsyntheg_start - ****************************************************************************/ - -void fmsyntheg_start(FAR fmsynth_eg_t *eg) -{ - eg->state = EGSTATE_ATTACK; - eg->state_counter = 0; -} - -/**************************************************************************** - * name: fmsyntheg_stop - ****************************************************************************/ - -void fmsyntheg_stop(FAR fmsynth_eg_t *eg) -{ - eg->state = EGSTATE_RELEASED; - eg->state_counter = 0; -} - -/**************************************************************************** - * name: fmsyntheg_operate - ****************************************************************************/ - -int fmsyntheg_operate(FAR fmsynth_eg_t *eg) -{ - int val; - FAR fmsynth_egparam_t *param = &eg->state_params[eg->state]; - - val = param->initval; - - if (eg->state != EGSTATE_RELEASED) - { - if (eg->state_counter >= eg->state_params[eg->state].period) - { - /* Reset the counter */ - - eg->state_counter = 0; - - /* Search next available state */ - - do - { - eg->state++; - } - while (eg->state < EGSTATE_RELEASED - && eg->state_params[eg->state].period == 0); - - val = eg->state_params[eg->state].initval; - } - else - { - val = val + param->diff2next * eg->state_counter / param->period; - eg->state_counter++; - } - } - - return val; -} diff --git a/audioutils/fmsynth/fmsynth_op.c b/audioutils/fmsynth/fmsynth_op.c deleted file mode 100644 index a86e7402e..000000000 --- a/audioutils/fmsynth/fmsynth_op.c +++ /dev/null @@ -1,548 +0,0 @@ -/**************************************************************************** - * apps/audioutils/fmsynth/fmsynth_op.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <stdlib.h> -#include <audioutils/fmsynth_op.h> - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define PHASE_ADJUST(th) \ - (((th) < 0 ? (FMSYNTH_PI) - (th) : (th)) % (FMSYNTH_PI * 2)) - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static const short s_sintbl[] = -{ - 0xff37, /* Extra data for linear completion */ - - /* Actual sin table of half PI [256] */ - - 0x0000, 0x00c9, 0x0192, 0x025b, - 0x0324, 0x03ed, 0x04b6, 0x057e, - 0x0647, 0x0710, 0x07d9, 0x08a1, - 0x096a, 0x0a32, 0x0afb, 0x0bc3, - 0x0c8b, 0x0d53, 0x0e1b, 0x0ee3, - 0x0fab, 0x1072, 0x1139, 0x1200, - 0x12c7, 0x138e, 0x1455, 0x151b, - 0x15e1, 0x16a7, 0x176d, 0x1833, - 0x18f8, 0x19bd, 0x1a82, 0x1b46, - 0x1c0b, 0x1ccf, 0x1d93, 0x1e56, - 0x1f19, 0x1fdc, 0x209f, 0x2161, - 0x2223, 0x22e4, 0x23a6, 0x2467, - 0x2527, 0x25e7, 0x26a7, 0x2767, - 0x2826, 0x28e5, 0x29a3, 0x2a61, - 0x2b1e, 0x2bdb, 0x2c98, 0x2d54, - 0x2e10, 0x2ecc, 0x2f86, 0x3041, - 0x30fb, 0x31b4, 0x326d, 0x3326, - 0x33de, 0x3496, 0x354d, 0x3603, - 0x36b9, 0x376f, 0x3824, 0x38d8, - 0x398c, 0x3a3f, 0x3af2, 0x3ba4, - 0x3c56, 0x3d07, 0x3db7, 0x3e67, - 0x3f16, 0x3fc5, 0x4073, 0x4120, - 0x41cd, 0x4279, 0x4325, 0x43d0, - 0x447a, 0x4523, 0x45cc, 0x4674, - 0x471c, 0x47c3, 0x4869, 0x490e, - 0x49b3, 0x4a57, 0x4afa, 0x4b9d, - 0x4c3f, 0x4ce0, 0x4d80, 0x4e20, - 0x4ebf, 0x4f5d, 0x4ffa, 0x5097, - 0x5133, 0x51ce, 0x5268, 0x5301, - 0x539a, 0x5432, 0x54c9, 0x555f, - 0x55f4, 0x5689, 0x571d, 0x57b0, - 0x5842, 0x58d3, 0x5963, 0x59f3, - 0x5a81, 0x5b0f, 0x5b9c, 0x5c28, - 0x5cb3, 0x5d3d, 0x5dc6, 0x5e4f, - 0x5ed6, 0x5f5d, 0x5fe2, 0x6067, - 0x60eb, 0x616e, 0x61f0, 0x6271, - 0x62f1, 0x6370, 0x63ee, 0x646b, - 0x64e7, 0x6562, 0x65dd, 0x6656, - 0x66ce, 0x6745, 0x67bc, 0x6831, - 0x68a5, 0x6919, 0x698b, 0x69fc, - 0x6a6c, 0x6adb, 0x6b4a, 0x6bb7, - 0x6c23, 0x6c8e, 0x6cf8, 0x6d61, - 0x6dc9, 0x6e30, 0x6e95, 0x6efa, - 0x6f5e, 0x6fc0, 0x7022, 0x7082, - 0x70e1, 0x7140, 0x719d, 0x71f9, - 0x7254, 0x72ae, 0x7306, 0x735e, - 0x73b5, 0x740a, 0x745e, 0x74b1, - 0x7503, 0x7554, 0x75a4, 0x75f3, - 0x7640, 0x768d, 0x76d8, 0x7722, - 0x776b, 0x77b3, 0x77f9, 0x783f, - 0x7883, 0x78c6, 0x7908, 0x7949, - 0x7989, 0x79c7, 0x7a04, 0x7a41, - 0x7a7c, 0x7ab5, 0x7aee, 0x7b25, - 0x7b5c, 0x7b91, 0x7bc4, 0x7bf7, - 0x7c29, 0x7c59, 0x7c88, 0x7cb6, - 0x7ce2, 0x7d0e, 0x7d38, 0x7d61, - 0x7d89, 0x7db0, 0x7dd5, 0x7df9, - 0x7e1c, 0x7e3e, 0x7e5e, 0x7e7e, - 0x7e9c, 0x7eb9, 0x7ed4, 0x7eef, - 0x7f08, 0x7f20, 0x7f37, 0x7f4c, - 0x7f61, 0x7f74, 0x7f86, 0x7f96, - 0x7fa6, 0x7fb4, 0x7fc1, 0x7fcd, - 0x7fd7, 0x7fe0, 0x7fe8, 0x7fef, - 0x7ff5, 0x7ff9, 0x7ffc, 0x7ffe, - - 0x7fff, /* Extra data for linear completion */ -}; - -static int local_fs; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * name: pseudo_sin256 - ****************************************************************************/ - -static int pseudo_sin256(int theta) -{ - int short_sin; - int rest; - int phase; - int tblidx; - - theta = PHASE_ADJUST(theta); - - rest = theta & 0x7f; - phase = theta / (FMSYNTH_PI / 2); - tblidx = (theta % (FMSYNTH_PI / 2)) >> 7; - - if (phase & 0x01) - { - tblidx = 257 - tblidx; - short_sin = s_sintbl[tblidx]; - short_sin = short_sin - + (((s_sintbl[tblidx - 1] - short_sin) * rest) >> 7); - } - else - { - short_sin = s_sintbl[tblidx + 1]; - short_sin = short_sin - + (((s_sintbl[tblidx + 2] - short_sin) * rest) >> 7); - } - - return phase & 0x02 ? -short_sin : short_sin; -} - -/**************************************************************************** - * name: triangle_wave - ****************************************************************************/ - -static int triangle_wave(int theta) -{ - int ret = 0; - int phase; - int offset; - int slope; - - theta = PHASE_ADJUST(theta); - phase = theta / (FMSYNTH_PI / 2); - offset = theta % (FMSYNTH_PI / 2); - - switch (phase) - { - case 0: - ret = 0; - slope = SHRT_MAX; - break; - case 1: - ret = SHRT_MAX; - slope = -SHRT_MAX; - break; - case 2: - ret = 0; - slope = -SHRT_MAX; - break; - case 3: - ret = -SHRT_MAX; - slope = SHRT_MAX; - break; - default: - ret = 0; - slope = SHRT_MAX; - break; - } - - return ret + ((slope * offset) >> 15); -} - -/**************************************************************************** - * name: sawtooth_wave - ****************************************************************************/ - -static int sawtooth_wave(int theta) -{ - theta = PHASE_ADJUST(theta); - return (theta >> 1) - SHRT_MAX; -} - -/**************************************************************************** - * name: square_wave - ****************************************************************************/ - -static int square_wave(int theta) -{ - theta = PHASE_ADJUST(theta); - return theta < FMSYNTH_PI ? SHRT_MAX : -SHRT_MAX; -} - -/**************************************************************************** - * name: update_parameters - ****************************************************************************/ - -static void update_parameters(FAR fmsynth_op_t *op) -{ - if (local_fs != 0) - { - op->delta_phase = 2 * FMSYNTH_PI * op->sound_freq * op->freq_rate - / (float)local_fs; - } - else - { - op->delta_phase = 0.f; - } -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * name: fmsynthop_set_samplerate - ****************************************************************************/ - -int fmsynthop_set_samplerate(int fs) -{ - if (fs < 0) - { - return ERROR; - } - - local_fs = fs; - return OK; -} - -/**************************************************************************** - * name: create_fmsynthop - ****************************************************************************/ - -FAR fmsynth_op_t *create_fmsynthop(FAR fmsynth_op_t *op, - FAR fmsynth_eg_t *eg) -{ - if (op) - { - op->eg = eg; - - op->own_allocate = 0; - op->wavegen = NULL; - op->cascadeop = NULL; - op->parallelop = NULL; - op->feedback_ref = NULL; - op->feedback_val = 0; - op->feedbackrate = 0; - op->last_sigval = 0; - op->freq_rate = 1.f; - op->sound_freq = 0.f; - op->delta_phase = 0.f; - op->current_phase = 0.f; - } - - return op; -} - -/**************************************************************************** - * name: fmsynthop_create - ****************************************************************************/ - -FAR fmsynth_op_t *fmsynthop_create(void) -{ - FAR fmsynth_op_t *ret; - - ret = (FAR fmsynth_op_t *)malloc(sizeof(fmsynth_op_t)); - - if (ret) - { - ret->eg = fmsyntheg_create(); - if (!ret->eg) - { - free(ret); - return NULL; - } - - create_fmsynthop(ret, ret->eg); - ret->own_allocate = 1; - } - - return ret; -} - -/**************************************************************************** - * name: fmsynthop_delete - ****************************************************************************/ - -void fmsynthop_delete(FAR fmsynth_op_t *op) -{ - if (op != NULL && op->own_allocate == 1) - { - if (op->eg) - { - fmsyntheg_delete(op->eg); - } - - free(op); - } -} - -/**************************************************************************** - * name: fmsynthop_select_opfunc - ****************************************************************************/ - -int fmsynthop_select_opfunc(FAR fmsynth_op_t *op, int type) -{ - int ret = ERROR; - - if (op != NULL) - { - switch (type) - { - case FMSYNTH_OPFUNC_SIN: - op->wavegen = pseudo_sin256; - ret = OK; - break; - - case FMSYNTH_OPFUNC_TRIANGLE: - op->wavegen = triangle_wave; - ret = OK; - break; - - case FMSYNTH_OPFUNC_SAWTOOTH: - op->wavegen = sawtooth_wave; - ret = OK; - break; - - case FMSYNTH_OPFUNC_SQUARE: - op->wavegen = square_wave; - ret = OK; - break; - } - } - - return ret; -} - -/**************************************************************************** - * name: fmsynthop_set_envelope - ****************************************************************************/ - -int fmsynthop_set_envelope(FAR fmsynth_op_t *op, - FAR fmsynth_eglevels_t *levels) -{ - if (local_fs >= 0 && op && levels) - { - return fmsyntheg_set_param(op->eg, local_fs, levels); - } - - return ERROR; -} - -/**************************************************************************** - * name: fmsynthop_cascade_subop - ****************************************************************************/ - -int fmsynthop_cascade_subop(FAR fmsynth_op_t *op, - FAR fmsynth_op_t *subop) -{ - FAR fmsynth_op_t *tmp; - - if (!op || !subop) - { - return ERROR; - } - - for (tmp = op; tmp->cascadeop; tmp = tmp->cascadeop); - - tmp->cascadeop = subop; - - return OK; -} - -/**************************************************************************** - * name: fmsynthop_parallel_subop - ****************************************************************************/ - -int fmsynthop_parallel_subop(FAR fmsynth_op_t *op, - FAR fmsynth_op_t *subop) -{ - FAR fmsynth_op_t *tmp; - - if (!op || !subop) - { - return ERROR; - } - - for (tmp = op; tmp->parallelop; tmp = tmp->parallelop); - - tmp->parallelop = subop; - - return OK; -} - -/**************************************************************************** - * name: fmsynthop_bind_feedback - ****************************************************************************/ - -int fmsynthop_bind_feedback(FAR fmsynth_op_t *op, - FAR fmsynth_op_t *subop, float ratio) -{ - if (!op || !subop) - { - return ERROR; - } - - op->feedbackrate = (int)((float)FMSYNTH_MAX_EGLEVEL * ratio); - op->feedback_ref = &subop->last_sigval; - - return OK; -} - -/**************************************************************************** - * name: fmsynthop_update_feedback - ****************************************************************************/ - -int fmsynthop_update_feedback(FAR fmsynth_op_t *op) -{ - FAR fmsynth_op_t *tmp; - - for (tmp = op->cascadeop; tmp != NULL; tmp = tmp->parallelop) - { - fmsynthop_update_feedback(tmp); - } - - if (op->feedback_ref) - { - op->feedback_val = *op->feedback_ref * op->feedbackrate - / FMSYNTH_MAX_EGLEVEL; - } - - return OK; -} - -/**************************************************************************** - * name: fmsynthop_set_soundfreq - ****************************************************************************/ - -void fmsynthop_set_soundfreq(FAR fmsynth_op_t *op, float freq) -{ - FAR fmsynth_op_t *tmp; - - op->sound_freq = freq; - update_parameters(op); - - for (tmp = op->cascadeop; tmp != NULL; tmp = tmp->parallelop) - { - fmsynthop_set_soundfreq(tmp, freq); - } -} - -/**************************************************************************** - * name: fmsynthop_set_soundfreqrate - ****************************************************************************/ - -void fmsynthop_set_soundfreqrate(FAR fmsynth_op_t *op, float rate) -{ - op->freq_rate = rate; - update_parameters(op); -} - -/**************************************************************************** - * name: fmsynthop_start - ****************************************************************************/ - -void fmsynthop_start(FAR fmsynth_op_t *op) -{ - FAR fmsynth_op_t *tmp; - - fmsyntheg_start(op->eg); - - for (tmp = op->cascadeop; tmp; tmp = tmp->parallelop) - { - fmsynthop_start(tmp); - } -} - -/**************************************************************************** - * name: fmsynthop_stop - ****************************************************************************/ - -void fmsynthop_stop(FAR fmsynth_op_t *op) -{ - FAR fmsynth_op_t *tmp; - - fmsyntheg_stop(op->eg); - - for (tmp = op->cascadeop; tmp; tmp = tmp->parallelop) - { - fmsynthop_stop(tmp); - } -} - -/**************************************************************************** - * name: fmsynthop_operate - ****************************************************************************/ - -int fmsynthop_operate(FAR fmsynth_op_t *op, int phase_time) -{ - int val; - int val2; - int phase; - FAR fmsynth_op_t *subop; - - op->current_phase = phase_time ? op->current_phase + op->delta_phase : 0.f; - - val = (int)op->current_phase; - val2 = (val / (2 * FMSYNTH_PI)); - - phase = (int)val + op->feedback_val; - op->current_phase = op->current_phase - (float)(val2 * (2 * FMSYNTH_PI)); - - subop = op->cascadeop; - - while (subop) - { - phase += fmsynthop_operate(subop, phase_time); - subop = subop->parallelop; - } - - op->last_sigval = fmsyntheg_operate(op->eg) * op->wavegen(phase) - / FMSYNTH_MAX_EGLEVEL; - - return op->last_sigval; -} diff --git a/audioutils/fmsynth/test/.gitignore b/audioutils/fmsynth/test/.gitignore deleted file mode 100644 index 34211c6ab..000000000 --- a/audioutils/fmsynth/test/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -/fmsynth_alsa -/fmsynth_test -/fmsyntheg_test -/fmsynthop_test -/opfunctest diff --git a/audioutils/fmsynth/test/Makefile b/audioutils/fmsynth/test/Makefile deleted file mode 100644 index 74118d918..000000000 --- a/audioutils/fmsynth/test/Makefile +++ /dev/null @@ -1,46 +0,0 @@ -############################################################################ -# apps/audioutils/fmsynth/test/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -SRCS = ../fmsynth_eg.c ../fmsynth_op.c ../fmsynth.c -CFLAGS = -DFAR= -DCODE= -DOK=0 -DERROR=-1 -I .. -I ../../../include -g - -TARGETS = opfunctest fmsyntheg_test fmsynthop_test fmsynth_test fmsynth_alsa - -all: $(TARGETS) - -opfunctest: $(SRCS) opfunc_test.c - gcc $(CFLAGS) -o $@ $^ -lm - -fmsyntheg_test: $(SRCS) fmsynth_eg_test.c - gcc $(CFLAGS) -o $@ $^ - -fmsynthop_test: $(SRCS) fmsynth_op_test.c - gcc $(CFLAGS) -o $@ $^ - -fmsynth_test: $(SRCS) fmsynth_test.c - gcc $(CFLAGS) -o $@ $^ - -fmsynth_alsa: $(SRCS) fmsynth_alsa_test.c - gcc $(CFLAGS) -o $@ $^ -lasound - -clean: - rm -rf $(TARGETS) diff --git a/audioutils/fmsynth/test/fmsynth_alsa_test.c b/audioutils/fmsynth/test/fmsynth_alsa_test.c deleted file mode 100644 index 4644ce1b0..000000000 --- a/audioutils/fmsynth/test/fmsynth_alsa_test.c +++ /dev/null @@ -1,326 +0,0 @@ -/**************************************************************************** - * apps/audioutils/fmsynth/test/fmsynth_alsa_test.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <stdio.h> -#include <stdint.h> -#include <termios.h> -#include <fcntl.h> - -#include <alsa/asoundlib.h> - -#include <audioutils/fmsynth_eg.h> -#include <audioutils/fmsynth_op.h> -#include <audioutils/fmsynth.h> - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define FS (48000) - -#define CHANNEL_NUM (2) -#define RESAMPLING_ALSA (1) -#define LATENCY_ALSA (10000) - -#define SAMPLE_NUM (FS / 20) -#define BUFF_LENGTH (SAMPLE_NUM * CHANNEL_NUM) - -#define CODE_C_FREQ (261.625565f) -#define CODE_D_FREQ (293.6647674f) -#define CODE_E_FREQ (329.6275561f) -#define CODE_F_FREQ (349.2282305f) -#define CODE_G_FREQ (391.9954347f) -#define CODE_A_FREQ (440.f) -#define CODE_B_FREQ (493.8833009f) - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static int16_t samples[BUFF_LENGTH]; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * name: init_alsa - ****************************************************************************/ - -static snd_pcm_t *init_alsa(int fs) -{ - int ret; - snd_pcm_t *hndl = NULL; - - ret = snd_pcm_open(&hndl, "default", SND_PCM_STREAM_PLAYBACK, 0); - if (ret < 0) - { - printf("sdn_pcm_open error\n"); - return NULL; - } - - ret = snd_pcm_set_params(hndl, - SND_PCM_FORMAT_S16, - SND_PCM_ACCESS_RW_INTERLEAVED, - CHANNEL_NUM, fs, RESAMPLING_ALSA, LATENCY_ALSA); - if (ret != 0) - { - printf("sdn_pcm_set_params error\n"); - snd_pcm_close(hndl); - return NULL; - } - - return hndl; -} - -/**************************************************************************** - * name: set_nonblocking - ****************************************************************************/ - -static int set_nonblocking(struct termios *saved) -{ - struct termios settings; - - tcgetattr(0, saved); - settings = *saved; - - settings.c_lflag &= ~(ECHO | ICANON); - settings.c_cc[VTIME] = 0; - settings.c_cc[VMIN] = 1; - tcsetattr(0, TCSANOW, &settings); - fcntl(0, F_SETFL, O_NONBLOCK); - - return OK; -} - -/**************************************************************************** - * name: store_setting - ****************************************************************************/ - -static void store_setting(struct termios *saved) -{ - tcsetattr(0, TCSANOW, saved); -} - -/**************************************************************************** - * name: set_levels - ****************************************************************************/ - -static fmsynth_eglevels_t *set_levels(fmsynth_eglevels_t *level, - float atk_lvl, int atk_peri, - float decbrk_lvl, int decbrk_peri, - float dec_lvl, int dec_peri, - float sus_lvl, int sus_peri, - float rel_lvl, int rel_peri) -{ - level->attack.level = atk_lvl; - level->attack.period_ms = atk_peri; - level->decaybrk.level = decbrk_lvl; - level->decaybrk.period_ms = decbrk_peri; - level->decay.level = dec_lvl; - level->decay.period_ms = dec_peri; - level->sustain.level = sus_lvl; - level->sustain.period_ms = sus_peri; - level->release.level = rel_lvl; - level->release.period_ms = rel_peri; - - return level; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * name: main - ****************************************************************************/ - -int main(void) -{ - int running; - int dump_count = 0; - int dump_enable = 0; - - fmsynth_eglevels_t levels; - fmsynth_sound_t *snd1; - fmsynth_op_t *envop; - fmsynth_op_t *fbop; - snd_pcm_t *hndl = NULL; - - struct termios save_param; - - hndl = init_alsa(FS); - if (!hndl) - { - printf("Init alsa error\n"); - return -1; - } - - /* Initialize FM synthesizer */ - - fmsynth_initialize(FS); - - /* Operator setup */ - - envop = fmsynthop_create(); - fbop = fmsynthop_create(); - - set_levels(&levels, 0.6f, 100, 0.3f, 300, 0.1f, 500, 0.f, 0, 0.f, 70); - - fmsynthop_set_envelope(envop, &levels); - fmsynthop_select_opfunc(envop, FMSYNTH_OPFUNC_SIN); - - fmsynthop_set_envelope(fbop, &levels); - fmsynthop_select_opfunc(fbop, FMSYNTH_OPFUNC_SIN); - fmsynthop_bind_feedback(fbop, fbop, 0.6f); - - fmsynthop_parallel_subop(envop, fbop); - - /* Sound setup */ - - snd1 = fmsynthsnd_create(); - fmsynthsnd_set_operator(snd1, envop); - fmsynthsnd_set_soundfreq(snd1, CODE_C_FREQ); - - set_nonblocking(&save_param); - running = 1; - while (running) - { - switch (getchar()) - { - case 'c': - fmsynthsnd_set_soundfreq(snd1, CODE_C_FREQ); - if (dump_enable) - { - dump_count = FS; - dump_enable = 0; - printf("DUMP: "); - } - - printf("Do\n"); - break; - case 'd': - fmsynthsnd_set_soundfreq(snd1, CODE_D_FREQ); - if (dump_enable) - { - dump_count = FS; - dump_enable = 0; - printf("DUMP: "); - } - - printf("Le\n"); - break; - case 'e': - fmsynthsnd_set_soundfreq(snd1, CODE_E_FREQ); - if (dump_enable) - { - dump_count = FS; - dump_enable = 0; - printf("DUMP: "); - } - - printf("Mi\n"); - break; - case 'f': - fmsynthsnd_set_soundfreq(snd1, CODE_F_FREQ); - if (dump_enable) - { - dump_count = FS; - dump_enable = 0; - printf("DUMP: "); - } - - printf("Fha\n"); - break; - case 'g': - fmsynthsnd_set_soundfreq(snd1, CODE_G_FREQ); - if (dump_enable) - { - dump_count = FS; - dump_enable = 0; - printf("DUMP: "); - } - - printf("So\n"); - break; - case 'a': - fmsynthsnd_set_soundfreq(snd1, CODE_A_FREQ); - if (dump_enable) - { - dump_count = FS; - dump_enable = 0; - printf("DUMP: "); - } - - printf("Ra\n"); - break; - case 'b': - fmsynthsnd_set_soundfreq(snd1, CODE_B_FREQ); - if (dump_enable) - { - dump_count = FS; - dump_enable = 0; - printf("DUMP: "); - } - - printf("Shi\n"); - break; - case 'z': - dump_enable = 1; - printf("Dump next code\n"); - break; - case 'q': - running = 0; - break; - } - - fmsynth_rendering(snd1, samples, BUFF_LENGTH, CHANNEL_NUM, NULL, 0); - - if (dump_count) - { - for (int i = 0; i < BUFF_LENGTH; i += 2) - { - printf("%d\n", samples[i]); - } - - dump_count -= SAMPLE_NUM; - } - - snd_pcm_writei(hndl, samples, SAMPLE_NUM); - } - - snd_pcm_drain(hndl); - snd_pcm_close(hndl); - - fmsynthop_delete(envop); - fmsynthop_delete(fbop); - - fmsynthsnd_delete(snd1); - - store_setting(&save_param); - - return 0; -} diff --git a/audioutils/fmsynth/test/fmsynth_eg_test.c b/audioutils/fmsynth/test/fmsynth_eg_test.c deleted file mode 100644 index 1a0641231..000000000 --- a/audioutils/fmsynth/test/fmsynth_eg_test.c +++ /dev/null @@ -1,129 +0,0 @@ -/**************************************************************************** - * apps/audioutils/fmsynth/test/fmsynth_eg_test.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <stdio.h> - -#include <audioutils/fmsynth_eg.h> - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define FS (48000) - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * name: state_name - ****************************************************************************/ - -static const char *state_name(int s) -{ - switch (s) - { - case EGSTATE_ATTACK: - return "Attack "; - case EGSTATE_DECAYBREAK: - return "DecayBreak"; - case EGSTATE_DECAY: - return "Decay "; - case EGSTATE_SUSTAIN: - return "Sustain "; - case EGSTATE_RELEASE: - return "Release "; - case EGSTATE_RELEASED: - case -1: - return "RELEASED.."; - } - - return ""; -} - -/**************************************************************************** - * name: dump_eg - ****************************************************************************/ - -static void dump_eg(fmsynth_eg_t *env) -{ - int i; - fmsynth_egparam_t *last = &env->state_params[EGSTATE_RELEASED]; - - printf("===== STATE : %s =======\n", state_name(env->state)); - for (i = -1; i < EGSTATE_RELEASED; i++) - { - printf(" [%s] %5d <--------------> [%s] %5d\n", - state_name(i), last->initval, - state_name(i + 1), env->state_params[i + 1].initval); - printf(" per %d\n", env->state_params[i + 1].period); - printf(" dlt %d\n", env->state_params[i + 1].diff2next); - last = &env->state_params[i + 1]; - } - - printf("\n"); -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * name: main - ****************************************************************************/ - -int main(void) -{ - fmsynth_eg_t *eg; - fmsynth_eglevels_t levels; - - levels.attack.level = 0.6f; - levels.attack.period_ms = 10; - levels.decaybrk.level = 0.3f; - levels.decaybrk.period_ms = 20; - levels.decay.level = 0.5f; - levels.decay.period_ms = 15; - levels.sustain.level = 0.65f; - levels.sustain.period_ms = 5; - levels.release.level = 0.f; - levels.release.period_ms = 70; - - eg = fmsyntheg_create(); - fmsyntheg_set_param(eg, FS, &levels); - dump_eg(eg); - - fmsyntheg_start(eg); - dump_eg(eg); - - while (eg->state != EGSTATE_RELEASED) - { - printf("%d\n", fmsyntheg_operate(eg)); - } - - fmsyntheg_delete(eg); - - return 0; -} diff --git a/audioutils/fmsynth/test/fmsynth_op_test.c b/audioutils/fmsynth/test/fmsynth_op_test.c deleted file mode 100644 index cf1eff42b..000000000 --- a/audioutils/fmsynth/test/fmsynth_op_test.c +++ /dev/null @@ -1,145 +0,0 @@ -/**************************************************************************** - * apps/audioutils/fmsynth/test/fmsynth_op_test.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <stdio.h> - -#include <audioutils/fmsynth_op.h> - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define FS (48000) -#define SOUNDFREQ (261.f) -#define TEST_LOOP (FS * (30 + 10 + 100 + 30 + 1) / 1000) - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * name: set_levels - ****************************************************************************/ - -static fmsynth_eglevels_t *set_levels(fmsynth_eglevels_t *level, - float atk_lvl, int atk_peri, - float decbrk_lvl, int decbrk_peri, - float dec_lvl, int dec_peri, - float sus_lvl, int sus_peri, - float rel_lvl, int rel_peri) -{ - level->attack.level = atk_lvl; - level->attack.period_ms = atk_peri; - level->decaybrk.level = decbrk_lvl; - level->decaybrk.period_ms = decbrk_peri; - level->decay.level = dec_lvl; - level->decay.period_ms = dec_peri; - level->sustain.level = sus_lvl; - level->sustain.period_ms = sus_peri; - level->release.level = rel_lvl; - level->release.period_ms = rel_peri; - - return level; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * name: main - ****************************************************************************/ - -int main(void) -{ - int phase_time; - fmsynth_eglevels_t levels; - - fmsynth_op_t *envop; - fmsynth_op_t *fbop; - fmsynth_op_t *triop; - fmsynth_op_t *mainop; - fmsynth_op_t *subop; - - fmsynth_op_t *conv1; - fmsynth_op_t *conv2; - - phase_time = 0; - fmsynthop_set_samplerate(FS); - - set_levels(&levels, 0.12f, 10, 0.06f, 20, 0.1f, 16, 0.1f, 5, 0.f, 70); - - envop = fmsynthop_create(); - fmsynthop_set_envelope(envop, &levels); - fmsynthop_select_opfunc(envop, FMSYNTH_OPFUNC_SIN); - fmsynthop_set_soundfreq(envop, SOUNDFREQ); - fmsynthop_start(envop); - - triop = fmsynthop_create(); - fmsynthop_select_opfunc(triop, FMSYNTH_OPFUNC_TRIANGLE); - fmsynthop_set_soundfreq(triop, SOUNDFREQ); - fmsynthop_start(triop); - - fbop = fmsynthop_create(); - fmsynthop_select_opfunc(fbop, FMSYNTH_OPFUNC_SIN); - fmsynthop_set_soundfreq(fbop, SOUNDFREQ); - fmsynthop_bind_feedback(fbop, fbop, 0.6f); - fmsynthop_start(fbop); - - mainop = fmsynthop_create(); - subop = fmsynthop_create(); - fmsynthop_select_opfunc(mainop, FMSYNTH_OPFUNC_SIN); - fmsynthop_select_opfunc(subop, FMSYNTH_OPFUNC_SIN); - fmsynthop_cascade_subop(mainop, subop); - fmsynthop_set_soundfreq(mainop, SOUNDFREQ); - fmsynthop_set_soundfreqrate(subop, 2.f); - fmsynthop_start(mainop); - - printf("idx,EnvTest,FeedbackTest,CascadeTest,Triangle\n"); - while (phase_time < TEST_LOOP) - { - fmsynthop_update_feedback(envop); - fmsynthop_update_feedback(fbop); - fmsynthop_update_feedback(mainop); - fmsynthop_update_feedback(triop); - - printf("%d,%d,%d,%d,%d\n", - phase_time, - fmsynthop_operate(envop, phase_time), - fmsynthop_operate(fbop, phase_time), - fmsynthop_operate(mainop, phase_time), - fmsynthop_operate(triop, phase_time)); - - phase_time++; - } - - fmsynthop_delete(envop); - fmsynthop_delete(fbop); - fmsynthop_delete(mainop); - fmsynthop_delete(subop); - - return 0; -} diff --git a/audioutils/fmsynth/test/fmsynth_test.c b/audioutils/fmsynth/test/fmsynth_test.c deleted file mode 100644 index ae03f2e6c..000000000 --- a/audioutils/fmsynth/test/fmsynth_test.c +++ /dev/null @@ -1,132 +0,0 @@ -/**************************************************************************** - * apps/audioutils/fmsynth/test/fmsynth_test.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <stdio.h> -#include <stdint.h> - -#include <audioutils/fmsynth_eg.h> -#include <audioutils/fmsynth_op.h> -#include <audioutils/fmsynth.h> - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define FS (48000) -#define SOUNDFREQ (3000.f) -#define TEST_LENGTH ((FS / 1000) * (10 + 20 + 16 + 5 + 30)) - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static int16_t my_sample[TEST_LENGTH]; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * name: set_levels - ****************************************************************************/ - -static fmsynth_eglevels_t *set_levels(fmsynth_eglevels_t *level, - int atk_lvl, int atk_peri, - int decbrk_lvl, int decbrk_peri, - int dec_lvl, int dec_peri, - int sus_lvl, int sus_peri, - int rel_lvl, int rel_peri) -{ - level->attack.level = atk_lvl; - level->attack.period_ms = atk_peri; - level->decaybrk.level = decbrk_lvl; - level->decaybrk.period_ms = decbrk_peri; - level->decay.level = dec_lvl; - level->decay.period_ms = dec_peri; - level->sustain.level = sus_lvl; - level->sustain.period_ms = sus_peri; - level->release.level = rel_lvl; - level->release.period_ms = rel_peri; - - return level; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * name: main - ****************************************************************************/ - -int main(void) -{ - int phase_time; - - fmsynth_eglevels_t levels; - fmsynth_sound_t *snd1; - fmsynth_op_t *envop; - fmsynth_op_t *fbop; - - /* Initialize FM synthesizer */ - - fmsynth_initialize(FS); - - /* Operator setup */ - - envop = fmsynthop_create(); - fbop = fmsynthop_create(); - - set_levels(&levels, 0.12f, 10, 0.06f, 20, 0.1f, 16, 0.1f, 5, 0.f, 70); - - fmsynthop_set_envelope(envop, &levels); - fmsynthop_select_opfunc(envop, FMSYNTH_OPFUNC_SIN); - - fmsynthop_select_opfunc(fbop, FMSYNTH_OPFUNC_SIN); - fmsynthop_bind_feedback(fbop, fbop, 0.6f); - - fmsynthop_parallel_subop(envop, fbop); - - /* Sound setup */ - - snd1 = fmsynthsnd_create(); - fmsynthsnd_set_operator(snd1, envop); - fmsynthsnd_set_soundfreq(snd1, SOUNDFREQ); - - fmsynth_rendering(snd1, my_sample, TEST_LENGTH, 1, NULL, 0); - - for (int i = 0; i < TEST_LENGTH; i++) - { - printf("%d\n", my_sample[i]); - } - - fmsynthop_delete(envop); - fmsynthop_delete(fbop); - - fmsynthsnd_delete(snd1); - - return 0; -} diff --git a/audioutils/fmsynth/test/opfunc_test.c b/audioutils/fmsynth/test/opfunc_test.c deleted file mode 100644 index d972bf290..000000000 --- a/audioutils/fmsynth/test/opfunc_test.c +++ /dev/null @@ -1,167 +0,0 @@ -/**************************************************************************** - * apps/audioutils/fmsynth/test/opfunc_test.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <stdio.h> -#include <stdlib.h> -#include <math.h> -#include <limits.h> - -#include <audioutils/fmsynth_op.h> - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define FS (48000) -#define DUMP_PERIOD (FS * 3 / 2000) -#define ACCURACY_TEST_PERIOD (FS * 3) - -#define HZ (4186) - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static opfunc_t func_sin; -static opfunc_t func_tri; -static opfunc_t func_saw; -static opfunc_t func_sqa; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * name: prepare_opfuncs - ****************************************************************************/ - -static void prepare_opfuncs(void) -{ - fmsynth_op_t *op; - - op = fmsynthop_create(); - - fmsynthop_select_opfunc(op, FMSYNTH_OPFUNC_SIN); - func_sin = op->wavegen; - - fmsynthop_select_opfunc(op, FMSYNTH_OPFUNC_TRIANGLE); - func_tri = op->wavegen; - - fmsynthop_select_opfunc(op, FMSYNTH_OPFUNC_SAWTOOTH); - func_saw = op->wavegen; - - fmsynthop_select_opfunc(op, FMSYNTH_OPFUNC_SQUARE); - func_sqa = op->wavegen; - - fmsynthop_delete(op); -} - -/**************************************************************************** - * name: wavegen_dump - ****************************************************************************/ - -static void wavegen_dump(void) -{ - int t; - float deltaact; - - deltaact = (float)FMSYNTH_PI * 2. * (float)HZ / (float)FS; - - printf("===== Wave generator Dump ====\n"); - printf("SIN, TRIANGLE, SAWTOOTH, SQUARE\n"); - for (t = 0; t < DUMP_PERIOD; t++) - { - printf("%d, %d, %d, %d\n", - func_sin((int)(deltaact * t)), - func_tri((int)(deltaact * t)), - func_saw((int)(deltaact * t)), - func_sqa((int)(deltaact * t)) - ); - } - - printf("\n"); -} - -/**************************************************************************** - * name: sin_accuracy_test - ****************************************************************************/ - -static void sin_accuracy_test(void) -{ - int t; - float delta; - float deltaact; - float max_diff = 0.f; - float ref_sin; - int sin_val; - float norm_sin; - float diff; - - delta = M_PI * 2. * (float)HZ / (float)FS; - deltaact = (float)FMSYNTH_PI * 2. * (float)HZ / (float)FS; - - printf("===== Local SIN function ACCURACY TEST ====\n"); - for (t = 0; t < ACCURACY_TEST_PERIOD; t++) - { - sin_val = func_sin((int)(deltaact * t)); - ref_sin = sinf(delta * t); - - norm_sin = (float)sin_val / (float)SHRT_MAX; - printf("t=%d, operator-sin(%d)=%d, norm_sin=%f, sinf(%f)=%f ", - t, (int)(deltaact * t), sin_val, norm_sin, delta * t, ref_sin); - - diff = fabsf(norm_sin - ref_sin); - max_diff = max_diff < diff ? diff : max_diff; - - if (diff >= 0.005) - { - printf(" BIG-DIFF : %f\n", diff); - } - else - { - printf("\n"); - } - } - - printf("\n\nMAX DIFF = %f\n\n", max_diff); -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * name: main - ****************************************************************************/ - -int main(void) -{ - prepare_opfuncs(); - sin_accuracy_test(); - wavegen_dump(); - - return 0; -} diff --git a/audioutils/lame/.gitignore b/audioutils/lame/.gitignore deleted file mode 100644 index 746d2f0dd..000000000 --- a/audioutils/lame/.gitignore +++ /dev/null @@ -1 +0,0 @@ -lame diff --git a/audioutils/lame/CMakeLists.txt b/audioutils/lame/CMakeLists.txt deleted file mode 100644 index f963cbf3d..000000000 --- a/audioutils/lame/CMakeLists.txt +++ /dev/null @@ -1,139 +0,0 @@ -# ############################################################################## -# apps/audioutils/lame/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_AUDIOUTILS_LAME) - - # Determine destination path - if(NOT DEFINED DST_PATH) - set(DST_PATH ${CMAKE_CURRENT_BINARY_DIR}/lame) - else() - set(DST_PATH ${DST_PATH}) - endif() - - # Set configuration commands - set(CFG_CMDS "") - if(NOT "${CONFIG_ARCH}" STREQUAL "sim") - list(APPEND CFG_CMDS "--host=${CONFIG_ARCH}") - list(APPEND CFG_CMDS "--cross-prefix=${CROSSDEV}") - endif() - - # The revision to check out. See the comment in Makefile: an unpinned - # checkout stops linking on the day lame's trunk grows its next vector tier. - # Raise this deliberately, together with the vector source list below. - - if(NOT DEFINED LAME_VERSION) - set(LAME_VERSION 6720) - endif() - - # # Download lame if no lame/configure found - if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/lame/configure") - execute_process( - COMMAND "svn" "checkout" "-r" "${LAME_VERSION}" - "https://svn.code.sf.net/p/lame/svn/trunk/lame" "lame" - WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") - endif() - - # Set source path - set(SRC_PATH "${CMAKE_CURRENT_SOURCE_DIR}/lame") - - # Add compiler flags - set(CFLAGS -DHAVE_CONFIG_H -Dfast_log2=lame_fast_log2) - set(CFLAGS - ${CFLAGS} - -Wno-address - -Wno-array-parameter - -Wno-builtin-declaration-mismatch - -Wno-incompatible-pointer-types - -Wno-implicit-function-declaration - -Wno-shadow - -Wno-stringop-overflow - -Wno-unused-variable - -Wno-unused-but-set-variable - -msse) - - set(INCDIR ${INCDIR_PREFIX}${DST_PATH} ${INCDIR_PREFIX}${SRC_PATH}/include - ${INCDIR_PREFIX}${SRC_PATH}/libmp3lame) - - # Set source files - set(CSRCS - "${SRC_PATH}/libmp3lame/bitstream.c" - "${SRC_PATH}/libmp3lame/encoder.c" - "${SRC_PATH}/libmp3lame/fft.c" - "${SRC_PATH}/libmp3lame/gain_analysis.c" - "${SRC_PATH}/libmp3lame/id3tag.c" - "${SRC_PATH}/libmp3lame/lame.c" - "${SRC_PATH}/libmp3lame/newmdct.c" - "${SRC_PATH}/libmp3lame/psymodel.c" - "${SRC_PATH}/libmp3lame/quantize.c" - "${SRC_PATH}/libmp3lame/quantize_pvt.c" - "${SRC_PATH}/libmp3lame/set_get.c" - "${SRC_PATH}/libmp3lame/vbrquantize.c" - "${SRC_PATH}/libmp3lame/reservoir.c" - "${SRC_PATH}/libmp3lame/tables.c" - "${SRC_PATH}/libmp3lame/takehiro.c" - "${SRC_PATH}/libmp3lame/util.c" - "${SRC_PATH}/libmp3lame/VbrTag.c" - "${SRC_PATH}/libmp3lame/version.c" - "${SRC_PATH}/libmp3lame/presets.c") - - if(CONFIG_HOST_X86 OR CONFIG_HOST_X86_64) - list( - APPEND - CSRCS - "${SRC_PATH}/libmp3lame/vector/xmm_quantize_sub.c" - "${SRC_PATH}/libmp3lame/vector/xmm_choose_table.c" - "${SRC_PATH}/libmp3lame/vector/xmm_quantize_lines.c" - "${SRC_PATH}/libmp3lame/vector/xmm_calc_sfb_noise.c" - "${SRC_PATH}/libmp3lame/vector/avx2_choose_table.c" - "${SRC_PATH}/libmp3lame/vector/avx2_quantize_lines.c" - "${SRC_PATH}/libmp3lame/vector/avx512_choose_table.c" - "${SRC_PATH}/libmp3lame/vector/avx512_quantize_lines.c" - "${SRC_PATH}/libmp3lame/vector/avx512_calc_sfb_noise.c") - endif() - - # Add custom target to generate config_h - set(CONFIG_H_FILE "${CMAKE_CURRENT_SOURCE_DIR}/lame/configure") - set(CONFIG_OPTIONS - --disable-cpml - --disable-decoder - --disable-efence - --disable-frontend - --disable-mp3x - --disable-gtktest - --disable-ipv6 - --disable-rpath - --enable-static - ${CFG_CMDS}) - add_custom_command( - OUTPUT "${DST_PATH}/config.h" - COMMAND ${CONFIG_H_FILE} ${CONFIG_OPTIONS} - WORKING_DIRECTORY "${DST_PATH}" - COMMENT "Generating config.h file") - add_custom_target(generate_config_h DEPENDS "${DST_PATH}/config.h") - - nuttx_add_library(libmp3lame STATIC) - add_dependencies(libmp3lame generate_config_h) - target_sources(libmp3lame PRIVATE ${CSRCS}) - target_include_directories(libmp3lame PRIVATE ${INCDIR}) - target_compile_options(libmp3lame PRIVATE ${CFLAGS}) - -endif() diff --git a/audioutils/lame/Kconfig b/audioutils/lame/Kconfig deleted file mode 100644 index 47adb3219..000000000 --- a/audioutils/lame/Kconfig +++ /dev/null @@ -1,8 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config AUDIOUTILS_LAME - bool "Enable LAME MP3 Encoder" - default n diff --git a/audioutils/lame/Make.defs b/audioutils/lame/Make.defs deleted file mode 100644 index e1f47123f..000000000 --- a/audioutils/lame/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/audioutils/lame/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_AUDIOUTILS_LAME),) -CONFIGURED_APPS += $(APPDIR)/audioutils/lame -endif diff --git a/audioutils/lame/Makefile b/audioutils/lame/Makefile deleted file mode 100644 index cf2daf24e..000000000 --- a/audioutils/lame/Makefile +++ /dev/null @@ -1,132 +0,0 @@ -############################################################################ -# apps/audioutils/lame/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -# The revision to check out. lame's trunk grows vector tiers over time -- -# SSE2, then AVX2, then AVX-512 -- and each one adds sources that this file -# and CMakeLists.txt have to name, so an unpinned checkout stops linking on -# the day upstream adds the next one. Raise this deliberately, together with -# the vector source list below. - -LAME_VERSION ?= 6720 - -# Download lame if no lame/configure found -lame-svn: - $(Q) echo "svn checkout lame ..." - $(Q) svn checkout -r $(LAME_VERSION) \ - https://svn.code.sf.net/p/lame/svn/trunk/lame lame - -ifeq ($(wildcard lame/configure),) -context:: lame-svn -distclean:: - $(call DELDIR, lame) -endif - -ifeq ($(DST_PATH),) - include $(APPDIR)/Make.defs - # configure in place - DST_PATH := lame -else - # configure out of tree - DST_PATH := $(realpath $(DST_PATH)) - include $(DST_PATH)/Make.defs - BIN := $(DST_PATH)/libmp3lame.a - # enable Application.mk PREFIX - PREFIX := $(DST_PATH)$(DELIM) -endif - -ifneq ($(CONFIG_ARCH),sim) - CFG_CMDS += --host=$(CONFIG_ARCH) - CFG_CMDS += --cross-prefix=$(CROSSDEV) -endif - -SRC_PATH := lame - -CFLAGS += -DHAVE_CONFIG_H -D'fast_log2=lame_fast_log2' -CFLAGS += $(INCDIR_PREFIX)$(DST_PATH) \ - $(INCDIR_PREFIX)$(SRC_PATH)/include \ - $(INCDIR_PREFIX)$(SRC_PATH)/libmp3lame -CFLAGS += -Wno-address -Wno-array-parameter \ - -Wno-builtin-declaration-mismatch \ - -Wno-incompatible-pointer-types \ - -Wno-implicit-function-declaration -Wno-shadow \ - -Wno-stringop-overflow -Wno-unused-variable \ - -Wno-unused-but-set-variable \ - -msse - -CSRCS += $(SRC_PATH)/libmp3lame/bitstream.c \ - $(SRC_PATH)/libmp3lame/encoder.c \ - $(SRC_PATH)/libmp3lame/fft.c \ - $(SRC_PATH)/libmp3lame/gain_analysis.c \ - $(SRC_PATH)/libmp3lame/id3tag.c \ - $(SRC_PATH)/libmp3lame/lame.c \ - $(SRC_PATH)/libmp3lame/newmdct.c \ - $(SRC_PATH)/libmp3lame/psymodel.c \ - $(SRC_PATH)/libmp3lame/quantize.c \ - $(SRC_PATH)/libmp3lame/quantize_pvt.c \ - $(SRC_PATH)/libmp3lame/set_get.c \ - $(SRC_PATH)/libmp3lame/vbrquantize.c \ - $(SRC_PATH)/libmp3lame/reservoir.c \ - $(SRC_PATH)/libmp3lame/tables.c \ - $(SRC_PATH)/libmp3lame/takehiro.c \ - $(SRC_PATH)/libmp3lame/util.c \ - $(SRC_PATH)/libmp3lame/VbrTag.c \ - $(SRC_PATH)/libmp3lame/version.c \ - $(SRC_PATH)/libmp3lame/presets.c - -# lame's configure enables the SSE2, AVX2 and AVX-512 dispatch paths whenever -# the host compiler accepts their per-function target attributes, and the -# scalar code then calls into them, so the whole group has to be built on an -# x86 host. Other hosts keep lame's scalar implementation. - -ifneq ($(CONFIG_HOST_X86)$(CONFIG_HOST_X86_64),) -CSRCS += $(SRC_PATH)/libmp3lame/vector/xmm_quantize_sub.c \ - $(SRC_PATH)/libmp3lame/vector/xmm_choose_table.c \ - $(SRC_PATH)/libmp3lame/vector/xmm_quantize_lines.c \ - $(SRC_PATH)/libmp3lame/vector/xmm_calc_sfb_noise.c \ - $(SRC_PATH)/libmp3lame/vector/avx2_choose_table.c \ - $(SRC_PATH)/libmp3lame/vector/avx2_quantize_lines.c \ - $(SRC_PATH)/libmp3lame/vector/avx512_choose_table.c \ - $(SRC_PATH)/libmp3lame/vector/avx512_quantize_lines.c \ - $(SRC_PATH)/libmp3lame/vector/avx512_calc_sfb_noise.c -endif - -LAME_CONFIG_SCRIPT := $(CURDIR)$(DELIM)lame$(DELIM)configure - -$(DST_PATH)/config.h: - $(Q)echo "lame configure... $(CONFIG_ARCH)" - $(Q)cd $(DST_PATH) && $(LAME_CONFIG_SCRIPT) \ - --disable-cpml --disable-decoder --disable-efence \ - --disable-frontend --disable-mp3x --disable-gtktest \ - --disable-ipv6 --disable-rpath --enable-static \ - $(CFG_CMDS) - -context:: $(DST_PATH)/config.h - -ifneq ($(PREFIX),) - @$(eval ALL_SRCS = $(CSRCS)) - @$(foreach src,$(ALL_SRCS),$(shell mkdir -p $(PREFIX)$(dir $(src)))) -endif - -distclean:: - $(Q)if [ -d $(DST_PATH) ]; then cd $(DST_PATH) && $(MAKE) distclean; fi - -include $(APPDIR)/Application.mk diff --git a/audioutils/libmad/.gitignore b/audioutils/libmad/.gitignore deleted file mode 100644 index e54b58b51..000000000 --- a/audioutils/libmad/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/libmad -/*.zip \ No newline at end of file diff --git a/audioutils/libmad/CMakeLists.txt b/audioutils/libmad/CMakeLists.txt deleted file mode 100644 index 354f42818..000000000 --- a/audioutils/libmad/CMakeLists.txt +++ /dev/null @@ -1,60 +0,0 @@ -# ############################################################################## -# apps/audioutils/libmad/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_AUDIOUTILS_LIBMAD) - - # Download and unpack libmad if no libmad found - if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/libmad/configure) - set(VERSION "master") - set(LIBMAD_URL - "https://github.com/markjeee/libmad/archive/refs/heads/master.zip") - - file(DOWNLOAD ${LIBMAD_URL} ${CMAKE_CURRENT_SOURCE_DIR}/libmad.zip) - execute_process( - COMMAND ${CMAKE_COMMAND} -E tar -xf ${CMAKE_CURRENT_SOURCE_DIR}/libmad.zip - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) - execute_process( - COMMAND - ${CMAKE_COMMAND} -E rename - ${CMAKE_CURRENT_SOURCE_DIR}/libmad-${VERSION} - ${CMAKE_CURRENT_SOURCE_DIR}/libmad) - - add_custom_target( - distclean - COMMAND ${CMAKE_COMMAND} -E remove_directory - ${CMAKE_CURRENT_SOURCE_DIR}/libmad - COMMAND ${CMAKE_COMMAND} -E remove ${CMAKE_CURRENT_SOURCE_DIR}/libmad.zip) - endif() - - nuttx_add_library(libmad STATIC) - - file(GLOB LIBMAD_SRCS libmad/*.c) - set(CSRCS ${LIBMAD_SRCS}) - set(CFLAGS -Wno-shadow -Wno-stringop-overflow -DFPM_DEFAULT -DSIZEOF_INT=4) - set(INCDIR ${CMAKE_CURRENT_LIST_DIR}/libmad - ${CMAKE_CURRENT_LIST_DIR}/libmad/msvc++) - - target_sources(libmad PRIVATE ${CSRCS}) - target_include_directories(libmad PRIVATE ${INCDIR}) - target_compile_options(libmad PRIVATE ${CFLAGS}) - -endif() diff --git a/audioutils/libmad/Kconfig b/audioutils/libmad/Kconfig deleted file mode 100644 index 13732d4bf..000000000 --- a/audioutils/libmad/Kconfig +++ /dev/null @@ -1,8 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config AUDIOUTILS_LIBMAD - bool "Enable libmad" - default n diff --git a/audioutils/libmad/Make.defs b/audioutils/libmad/Make.defs deleted file mode 100644 index b3ff27474..000000000 --- a/audioutils/libmad/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/audioutils/libmad/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_AUDIOUTILS_LIBMAD),) -CONFIGURED_APPS += $(APPDIR)/audioutils/libmad -endif diff --git a/audioutils/libmad/Makefile b/audioutils/libmad/Makefile deleted file mode 100644 index ea7fce751..000000000 --- a/audioutils/libmad/Makefile +++ /dev/null @@ -1,45 +0,0 @@ -############################################################################ -# apps/audioutils/libmad/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -CSRCS += $(wildcard libmad/*.c) -CFLAGS += -DFPM_DEFAULT -DSIZEOF_INT=4 -CFLAGS += -Wno-shadow -Wno-stringop-overflow - -# Download and unpack libmad if no git repo found -ifeq ($(wildcard libmad/.git),) -VERSION ?= master -libmad.zip: - $(Q) curl -L https://github.com/markjeee/libmad/archive/refs/heads/master.zip -o libmad.zip - $(Q) unzip -o libmad.zip - $(Q) mv libmad-$(VERSION) libmad - -context:: libmad.zip - -distclean:: - $(call DELDIR, libmad) - $(call DELFILE, libmad.zip) - -endif - -include $(APPDIR)/Application.mk diff --git a/audioutils/mml_parser/CMakeLists.txt b/audioutils/mml_parser/CMakeLists.txt deleted file mode 100644 index 72d2f8cfb..000000000 --- a/audioutils/mml_parser/CMakeLists.txt +++ /dev/null @@ -1,24 +0,0 @@ -# ############################################################################## -# apps/audioutils/mml_parser/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## -if(CONFIG_AUDIOUTILS_MMLPARSER_LIB) - target_sources(apps PRIVATE mml_parser.c) -endif() diff --git a/audioutils/mml_parser/Kconfig b/audioutils/mml_parser/Kconfig deleted file mode 100644 index 2fe9d3681..000000000 --- a/audioutils/mml_parser/Kconfig +++ /dev/null @@ -1,10 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config AUDIOUTILS_MMLPARSER_LIB - bool "Music Macro Language(MML) Library" - default n - ---help--- - Enable support for the Music Macro Language library. diff --git a/audioutils/mml_parser/Make.defs b/audioutils/mml_parser/Make.defs deleted file mode 100644 index 39bad3019..000000000 --- a/audioutils/mml_parser/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/audioutils/mml_parser/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_AUDIOUTILS_MMLPARSER_LIB),) -CONFIGURED_APPS += $(APPDIR)/audioutils/mml_parser -endif diff --git a/audioutils/mml_parser/mml_parser.c b/audioutils/mml_parser/mml_parser.c deleted file mode 100644 index 033bbbfde..000000000 --- a/audioutils/mml_parser/mml_parser.c +++ /dev/null @@ -1,870 +0,0 @@ -/**************************************************************************** - * apps/audioutils/mml_parser/mml_parser.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <stdlib.h> -#include <string.h> -#include <ctype.h> -#include <stdbool.h> -#include <errno.h> - -#include <audioutils/mml_parser.h> - -#ifdef DEBUG_ON -#include <stdio.h> -#endif - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define LENGTH_STATE_IDLE (0) -#define LENGTH_STATE_NUMBERD (1) -#define LENGTH_STATE_PLUS (2) - -#define CHORD_START '[' -#define CHORD_END ']' - -#define TUPLET_START '{' -#define TUPLET_END '}' - -#ifdef DEBUG_ON -#define DEBUG printf -#else -#define DEBUG(...) -#endif - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * name: skip_space - ****************************************************************************/ - -static char *skip_space(char *str) -{ - while (isspace(*str)) - { - str++; - } - - return str; -} - -/**************************************************************************** - * name: next_code - ****************************************************************************/ - -static char next_code(char **score) -{ - char ret; - *score = skip_space(*score); - ret = **score; - *score += 1; - return ret; -} - -/**************************************************************************** - * name: note_index - ****************************************************************************/ - -static int note_index(char code) -{ - int i; - const char *code_types = "C+D+EF+G+A+B"; - - for (i = 0; i < 12; i++) - { - if (code_types[i] == code) - { - return i; - } - } - - return -1; -} - -/**************************************************************************** - * name: halfscale - ****************************************************************************/ - -static int halfscale(char **score) -{ - int ret = 0; - - while (1) - { - switch (**score) - { - case '+': - case '#': - ret++; - break; - case '-': - ret--; - break; - default: - return ret; - } - - *score += 1; - } - - return ret; -} - -/**************************************************************************** - * name: strlendigits - ****************************************************************************/ - -static int strlendigits(FAR const char *str) -{ - int ret = 0; - - while (isdigit(*str)) - { - str++; - ret++; - } - - return ret; -} - -/**************************************************************************** - * name: calc_samples - ****************************************************************************/ - -static int calc_samples(int fs, int tempo, int num, int dots) -{ - int div = 0; - int n = 0; - int mul = 16; - - DEBUG("fs=%d, tempo=%d, num=%d, dots=%d\n", fs, tempo, num, dots); - - switch (num) - { - case 0: - n = 3; - break; - case 1: - n = 2; - break; - case 2: - n = 1; - break; - case 4: - n = 0; - break; - case 8: - div = 1; - break; - case 16: - div = 2; - break; - case 32: - div = 3; - break; - case 64: - div = 4; - break; - default: - div = -1; - break; - } - - if (dots <= 4) - { - while (dots) - { - mul += (1 << (4 - dots)); - dots--; - } - } - else - { - dots = -1; - } - - if (div < 0 || dots < 0) - { - return -EINVAL; - } - - return (((15 * fs * mul) << n) >> (2 + div)) / tempo; -} - -/**************************************************************************** - * name: get_samples - ****************************************************************************/ - -static int get_samples(FAR struct music_macro_lang_s *mml, - int samples, int num, int dots, bool plus_mode) -{ - int len; - - num = num < 0 ? mml->def_length : num; - len = calc_samples(mml->fs, mml->cur_tempo, num, dots); - - if (len > 0) - { - return plus_mode ? samples + len : len; - } - - return len; -} - -/**************************************************************************** - * name: is_qualifire - ****************************************************************************/ - -static bool is_qualifire(char c) -{ - if (isdigit(c) || c == '.') - { - return true; - } - - return false; -} - -/**************************************************************************** - * name: sample_length - ****************************************************************************/ - -static int sample_length(FAR struct music_macro_lang_s *mml, - FAR char **score) -{ - int dots = 0; - int samples = 0; - int state = LENGTH_STATE_IDLE; - bool plus_mode = false; - bool parsing = true; - int num = -1; - - samples = get_samples(mml, samples, num, dots, plus_mode); - - if (!is_qualifire(**score)) - { - return samples; - } - - while (parsing) - { - DEBUG("In Length parser\n"); - switch (state) - { - case LENGTH_STATE_IDLE: - if (isdigit(**score)) - { - DEBUG("state[IDLE]: Digits\n"); - num = atoi(*score); - *score += strlendigits(*score); - state = LENGTH_STATE_NUMBERD; - } - else if (**score == '.') - { - DEBUG("state[IDLE]: Dot\n"); - state = LENGTH_STATE_NUMBERD; - dots++; - *score += 1; - } - else - { - DEBUG("state[IDLE]: Other\n"); - samples = get_samples(mml, samples, num, dots, plus_mode); - parsing = false; - } - - case LENGTH_STATE_NUMBERD: - if (**score == '.') - { - DEBUG("state[NUM]: Dot\n"); - dots++; - *score += 1; - } - else if (**score == '+') - { - DEBUG("state[NUM]: PLUS\n"); - samples = get_samples(mml, samples, num, dots, plus_mode); - if (samples < 0) - { - parsing = false; - } - - plus_mode = true; - num = -1; - *score += 1; - state = LENGTH_STATE_PLUS; - } - else - { - DEBUG("state[NUM]: Other\n"); - samples = get_samples(mml, samples, num, dots, plus_mode); - parsing = false; - } - - break; - - case LENGTH_STATE_PLUS: - if (isdigit(**score)) - { - num = atoi(*score); - *score += strlendigits(*score); - DEBUG("state[PLUS]: Digits num=%d, restscore=%s," - " parsing=%s\n", - num, *score, parsing ? "True" : "False"); - state = LENGTH_STATE_NUMBERD; - } - else - { - DEBUG("state[PLUS]: Other\n"); - samples = -EINVAL; - parsing = false; - } - - break; - - default: - parsing = false; - samples = -EPROTO; - break; - } - - DEBUG("Out switch : state[%s]: Digits num=%d, restscore=%s," - " parse=%s\n", - state == LENGTH_STATE_IDLE ? "IDLE" : - state == LENGTH_STATE_NUMBERD ? "NUM" : - state == LENGTH_STATE_PLUS ? "PLUS" : "Unknown", - num, *score, parsing ? "True" : "False"); - } - - DEBUG("Out while\n"); - - return samples; -} - -/**************************************************************************** - * name: tuple_length - ****************************************************************************/ - -static int tuplet_length(FAR struct music_macro_lang_s *mml) -{ - int ret; - - ret = mml->tuplet_length / mml->tuplet_notes; - mml->cur_tuplet++; - if (mml->cur_tuplet == mml->tuplet_notes) - { - /* Adjust surplus */ - - ret = mml->tuplet_length - (ret * (mml->tuplet_notes - 1)); - } - - return ret; -} - -/**************************************************************************** - * name: handle_note - ****************************************************************************/ - -static int handle_note(FAR struct music_macro_lang_s *mml, char code, - FAR char **score, FAR struct mml_result_s *result) -{ - result->note_idx[0] = note_index(code) + halfscale(score) - + mml->cur_octave * 12; - result->length = sample_length(mml, score); - - return result->length < 0 ? MML_TYPE_NOTE_ERROR : MML_TYPE_NOTE; -} - -/**************************************************************************** - * name: handle_rest - ****************************************************************************/ - -static int handle_rest(FAR struct music_macro_lang_s *mml, - FAR char **score, FAR struct mml_result_s *result) -{ - if (mml->state == MML_STATE_TUPLET) - { - DEBUG("Tuplet : TTL %d, CUR %d\n", mml->tuplet_notes, mml->cur_tuplet); - result->length = tuplet_length(mml); - return MML_TYPE_REST; - } - else - { - result->length = sample_length(mml, score); - return result->length < 0 ? MML_TYPE_REST_ERROR : MML_TYPE_REST; - } -} - -/**************************************************************************** - * name: handle_tempo - ****************************************************************************/ - -static int handle_tempo(FAR struct music_macro_lang_s *mml, - FAR char **score, FAR struct mml_result_s *result) -{ - int ret = MML_TYPE_TEMPO; - - if (isdigit(**score)) - { - mml->cur_tempo = result->length = atoi(*score); - *score += strlendigits(*score); - } - else - { - ret = MML_TYPE_TEMPO_ERROR; - } - - return ret; -} - -/**************************************************************************** - * name: handle_length - ****************************************************************************/ - -static int handle_length(FAR struct music_macro_lang_s *mml, - FAR char **score, FAR struct mml_result_s *result) -{ - int ret = MML_TYPE_LENGTH_ERROR; - - DEBUG("length str : %c\n", **score); - if (isdigit(**score)) - { - mml->def_length = result->length = atoi(*score); - *score += strlendigits(*score); - ret = MML_TYPE_LENGTH; - } - - return ret; -} - -/**************************************************************************** - * name: handle_octave - ****************************************************************************/ - -static int handle_octave(FAR struct music_macro_lang_s *mml, char code, - FAR char **score, FAR struct mml_result_s *result) -{ - int ret = MML_TYPE_OCTAVE; - - switch (code) - { - case '>': - mml->cur_octave++; - result->length = mml->cur_octave; - break; - - case '<': - mml->cur_octave--; - result->length = mml->cur_octave; - break; - - default: - if (isdigit(**score)) - { - mml->cur_octave = result->length = atoi(*score); - *score += strlendigits(*score); - } - else - { - ret = MML_TYPE_OCTAVE_ERROR; - } - - break; - } - - return ret; -} - -/**************************************************************************** - * name: handle_volume - ****************************************************************************/ - -static int handle_volume(FAR struct music_macro_lang_s *mml, - FAR char **score, FAR struct mml_result_s *result) -{ - int ret = MML_TYPE_VOLUME; - - result->length = atoi(*score); - *score += strlendigits(*score); - - if (result->length < 0 || result->length > 100) - { - ret = MML_TYPE_VOLUME_ERROR; - } - - return ret; -} - -/**************************************************************************** - * name: skip_until - ****************************************************************************/ - -static char *skip_until(FAR char *score, char until) -{ - while (*score != until && *score != '\0') - { - score++; - } - - return score; -} - -/**************************************************************************** - * name: count_tupletnotes - ****************************************************************************/ - -static int count_tupletnotes(FAR struct music_macro_lang_s *mml, - FAR char *score) -{ - const char *notes = "CDEFGABR"; - - score = skip_space(score); - - while (*score != TUPLET_END) - { - if (strchr(notes, *score)) - { - mml->tuplet_notes++; - } - else if (*score == CHORD_START) - { - score = skip_until(score, CHORD_END); - mml->tuplet_notes++; - } - - if (*score == '\0') - { - return -EINVAL; - } - - score++; - score = skip_space(score); - } - - score++; /* Skip TUPLET_END */ - mml->tuplet_length = sample_length(mml, &score); - - return mml->tuplet_notes != 0 ? OK : -EINVAL; -} - -/**************************************************************************** - * name: handle_starttuplet - ****************************************************************************/ - -static int handle_starttuplet(FAR struct music_macro_lang_s *mml, - FAR char **score, - FAR struct mml_result_s *result) -{ - int ret; - - if (mml->state != MML_STATE_NORMAL) - { - return MML_TYPE_ILLIGAL_DOUBLE_TUPLET; - } - - mml->tuplet_notes = 0; - ret = count_tupletnotes(mml, *score); - if (ret < 0 || mml->tuplet_notes == 0) - { - return MML_TYPE_TUPLET_ERROR; - } - - mml->state = MML_STATE_TUPLET; - mml->cur_tuplet = 0; - - result->length = mml->tuplet_length; - - return MML_TYPE_TUPLETSTART; -} - -/**************************************************************************** - * name: handle_stoptuplet - ****************************************************************************/ - -static int handle_stoptuplet(FAR struct music_macro_lang_s *mml, - FAR char **score, - FAR struct mml_result_s *result) -{ - int ret = MML_TYPE_TUPLETDONE; - - mml->state = MML_STATE_NORMAL; - - /* Just for skip of length block */ - - sample_length(mml, score); - - if (mml->cur_tuplet != mml->tuplet_notes) - { - ret = MML_TYPE_ILLIGAL_TOOFEW_NOTES; - } - - return ret; -} - -/**************************************************************************** - * name: handle_tupletnote - ****************************************************************************/ - -static int handle_tupletnote(FAR struct music_macro_lang_s *mml, char code, - FAR char **score, - FAR struct mml_result_s *result) -{ - int ret = MML_TYPE_NOTE; - - DEBUG("Tuplet : TTL %d, CUR %d\n", mml->tuplet_notes, mml->cur_tuplet); - if (mml->cur_tuplet < mml->tuplet_notes) - { - result->note_idx[0] = note_index(code) + halfscale(score) - + mml->cur_octave * 12; - result->length = tuplet_length(mml); - } - else - { - ret = MML_TYPE_ILLIGAL_TOOMANY_NOTES; - } - - return ret; -} - -/**************************************************************************** - * name: handle_notes - ****************************************************************************/ - -static int handle_notes(FAR struct music_macro_lang_s *mml, char code, - FAR char **score, - FAR struct mml_result_s *result) -{ - int ret; - - result->chord_notes = 1; - - if (mml->state == MML_STATE_TUPLET) - { - ret = handle_tupletnote(mml, code, score, result); - } - else - { - ret = handle_note(mml, code, score, result); - } - - return ret; -} - -/**************************************************************************** - * name: handle_startchord - ****************************************************************************/ - -static int handle_startchord(FAR struct music_macro_lang_s *mml, - FAR char **score, - FAR struct mml_result_s *result) -{ - char code; - int note_idx; - - code = next_code(score); - - while (code != CHORD_END && code != '\0') - { - DEBUG("CHORD: %c\n", code); - note_idx = note_index(code); - DEBUG("CHORD note_idx = %d\n", note_idx); - if (note_idx >= 0) - { - note_idx += halfscale(score) + mml->cur_octave * 12; - - if (result->chord_notes < MAX_CHORD_NOTES) - { - result->note_idx[result->chord_notes] = note_idx; - result->chord_notes++; - } - - /* In case of chord notes are over than MAX_CHORD_NOTES, - * just ignore overflowed notes. Not behave as an error. - */ - } - else - { - switch (code) - { - case 'O': - case '>': - case '<': - if (handle_octave(mml, code, score, result) < 0) - { - return MML_TYPE_CHORD_ERROR; - } - break; - - default: - return MML_TYPE_CHORD_ERROR; - break; - } - } - - code = next_code(score); - } - - if (code == '\0') - { - return MML_TYPE_CHORD_ERROR; - } - - if (mml->state == MML_STATE_TUPLET) - { - result->length = tuplet_length(mml); - } - else - { - result->length = sample_length(mml, score); - } - - return result->length < 0 ? MML_TYPE_CHORD_ERROR : MML_TYPE_CHORD; -} - -/**************************************************************************** - * name: handle_tone - ****************************************************************************/ - -static int handle_tone(FAR struct music_macro_lang_s *mml, - FAR char **score, FAR struct mml_result_s *result) -{ - int ret = MML_TYPE_TONE_ERROR; - - if (isdigit(**score)) - { - result->note_idx[0] = atoi(*score); - *score += strlendigits(*score); - ret = MML_TYPE_TONE; - } - - return ret; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * name: init_mml - ****************************************************************************/ - -int init_mml(FAR struct music_macro_lang_s *mml, int fs, - int tempo, int octave, int length) -{ - mml->fs = fs; - mml->cur_tempo = tempo; - mml->cur_octave = octave; - mml->def_length = length; - - mml->state = MML_STATE_NORMAL; - mml->cur_tuplet = 0; - mml->tuplet_notes = 0; - mml->tuplet_length = 0; - - return 0; -} - -/**************************************************************************** - * name: parse_mml - ****************************************************************************/ - -int parse_mml(FAR struct music_macro_lang_s *mml, FAR char **score, - FAR struct mml_result_s *result) -{ - int ret; - char code; - - code = next_code(score); - DEBUG("code=%c\n", code); - result->chord_notes = 0; - - switch (code) - { - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - ret = handle_notes(mml, code, score, result); - break; - - case 'R': - ret = handle_rest(mml, score, result); - break; - - case 'T': - ret = handle_tempo(mml, score, result); - break; - - case 'L': - ret = handle_length(mml, score, result); - break; - - case 'O': - case '>': - case '<': - ret = handle_octave(mml, code, score, result); - break; - - case 'V': - ret = handle_volume(mml, score, result); - break; - - case CHORD_START: - ret = handle_startchord(mml, score, result); - break; - - case TUPLET_START: - ret = handle_starttuplet(mml, score, result); - break; - - case TUPLET_END: - ret = handle_stoptuplet(mml, score, result); - break; - - case '@': - ret = handle_tone(mml, score, result); - break; - - case '\0': - ret = MML_TYPE_EOF; - *score -= 1; /* Backward */ - break; - - default: - ret = MML_TYPE_ILLIGAL_COMPOSITION; - break; - } - - return ret; -} diff --git a/audioutils/morsey/.gitignore b/audioutils/morsey/.gitignore deleted file mode 100644 index 26b43c946..000000000 --- a/audioutils/morsey/.gitignore +++ /dev/null @@ -1 +0,0 @@ -morsey diff --git a/audioutils/morsey/Kconfig b/audioutils/morsey/Kconfig deleted file mode 100644 index 4f8b2f98d..000000000 --- a/audioutils/morsey/Kconfig +++ /dev/null @@ -1,6 +0,0 @@ -config AUDIOUTILS_MORSEY - bool "Morse code playing library" - default n - ---help--- - Simple library for parsing ASCII text into playable Morse code. Not - necessarily restricted to audio. diff --git a/audioutils/morsey/Make.defs b/audioutils/morsey/Make.defs deleted file mode 100644 index 9fab9a304..000000000 --- a/audioutils/morsey/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/audioutils/morsey/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_AUDIOUTILS_MORSEY),) -CONFIGURED_APPS += $(APPDIR)/audioutils/morsey -endif diff --git a/audioutils/morsey/Makefile b/audioutils/morsey/Makefile deleted file mode 100644 index 04f454e64..000000000 --- a/audioutils/morsey/Makefile +++ /dev/null @@ -1,50 +0,0 @@ -############################################################################ -# apps/audioutils/morsey/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -CSRCS = $(MORSEY_DIR)/morsey.c - -MORSEY_DIR = morsey -MORSEY_VERSION = v1.0.1 -MORSEY_MORSEY_H_SHA256 = 55f45e7b9a4d810f928ffe3ee9bea4cc318e28b1f49abf9512aee2638bd1dbfa -MORSEY_MORSEY_C_SHA256 = 12babc90d3518e026c344c38dc3701287c41fd6b41a3ec96fb36c77907be78f8 - -$(MORSEY_DIR): - $(Q) echo "Cloning Morsey repo..." - $(Q) git clone --depth=1 --branch=$(MORSEY_VERSION) https://github.com/linguini1/morsey.git - $(Q) touch $(MORSEY_DIR) - $(Q) echo "Checking Morsey hashes..." - $(Q) $(APPDIR)/tools/check-hash.sh sha256 $(MORSEY_MORSEY_H_SHA256) $@/morsey.h - $(Q) $(APPDIR)/tools/check-hash.sh sha256 $(MORSEY_MORSEY_C_SHA256) $@/morsey.c - -create_includes: $(MORSEY_DIR)/morsey.h - $(Q) cp $< $(APPDIR)/include/audioutils - -context:: $(MORSEY_DIR) - $(Q) $(MAKE) create_includes - -distclean:: - $(call DELFILE, $(APPDIR)/include/audioutils/morsey.h) - $(call DELDIR, morsey) - -include $(APPDIR)/Application.mk diff --git a/audioutils/nxaudio/CMakeLists.txt b/audioutils/nxaudio/CMakeLists.txt deleted file mode 100644 index cd7c017ca..000000000 --- a/audioutils/nxaudio/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -# ############################################################################## -# apps/audioutils/nxaudio/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_AUDIOUTILS_NXAUDIO_LIB) - target_sources(apps PRIVATE nxaudio.c) -endif() diff --git a/audioutils/nxaudio/Kconfig b/audioutils/nxaudio/Kconfig deleted file mode 100644 index e3828aff9..000000000 --- a/audioutils/nxaudio/Kconfig +++ /dev/null @@ -1,26 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config AUDIOUTILS_NXAUDIO_LIB - bool "NX Audio Library" - default n - ---help--- - Enable support for the NX Audio library. - -if AUDIOUTILS_NXAUDIO_LIB - -config AUDIOUTILS_NXAUDIO_DEVPATH - string "Audio Device file path" - default "/dev/audio/pcm1" - ---help--- - Audio device file path of target audio device. - -config AUDIOUTILS_NXAUDIO_MSGQNAME - string "Message queue name" - default "/tmp/fmaudio_mq" - ---help--- - Message queue name (file path) to communicate with audio message loop. - -endif diff --git a/audioutils/nxaudio/Make.defs b/audioutils/nxaudio/Make.defs deleted file mode 100644 index 2677f926e..000000000 --- a/audioutils/nxaudio/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/audioutils/nxaudio/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_AUDIOUTILS_NXAUDIO_LIB),) -CONFIGURED_APPS += $(APPDIR)/audioutils/nxaudio -endif diff --git a/audioutils/nxaudio/Makefile b/audioutils/nxaudio/Makefile deleted file mode 100644 index 561cecc89..000000000 --- a/audioutils/nxaudio/Makefile +++ /dev/null @@ -1,27 +0,0 @@ -############################################################################ -# apps/audioutils/nxaudio/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -CSRCS = nxaudio.c - -include $(APPDIR)/Application.mk diff --git a/audioutils/nxaudio/nxaudio.c b/audioutils/nxaudio/nxaudio.c deleted file mode 100644 index 3871a1a93..000000000 --- a/audioutils/nxaudio/nxaudio.c +++ /dev/null @@ -1,353 +0,0 @@ -/**************************************************************************** - * apps/audioutils/nxaudio/nxaudio.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <stdint.h> -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <fcntl.h> -#include <mqueue.h> -#include <sys/ioctl.h> -#include <nuttx/audio/audio.h> - -#include <errno.h> - -#include <audioutils/nxaudio.h> - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * name: configure_audio - ****************************************************************************/ - -static int configure_audio(int fd, int ch, int fs, int bps, int chmap) -{ - struct audio_caps_desc_s cap; - - cap.caps.ac_len = sizeof(struct audio_caps_s); - cap.caps.ac_type = AUDIO_TYPE_OUTPUT; - cap.caps.ac_channels = ch; - cap.caps.ac_chmap = chmap; - cap.caps.ac_controls.hw[0] = fs; - cap.caps.ac_controls.b[2] = bps; - cap.caps.ac_controls.b[3] = 0; /* Just set 0 */ - - return ioctl(fd, AUDIOIOC_CONFIGURE, (unsigned long)(uintptr_t)&cap); -} - -/**************************************************************************** - * name: create_audiomq - ****************************************************************************/ - -static mqd_t create_audiomq(const char *mqname, int fd, int buf_num) -{ - mqd_t ret; - struct mq_attr attr; - - attr.mq_maxmsg = buf_num; - attr.mq_msgsize = sizeof(struct audio_msg_s); - attr.mq_curmsgs = 0; - attr.mq_flags = 0; - - ret = mq_open(mqname, O_RDWR | O_CREAT, 0644, &attr); - if (ret >= (mqd_t)0) - { - int rr; - if ((rr = ioctl(fd, AUDIOIOC_REGISTERMQ, (unsigned long)ret)) < 0) - { - printf("mq register failed: %d, %d\n", rr, errno); - } - } - - return ret; -} - -/**************************************************************************** - * name: create_audio_buffers - ****************************************************************************/ - -static FAR struct ap_buffer_s **create_audio_buffers(int fd, int num, int sz) -{ - int i; - struct audio_buf_desc_s desc; - FAR struct ap_buffer_s **ret; - - ret = (FAR struct ap_buffer_s **)calloc(num, sizeof(FAR void *)); - - for (i = 0; i < num; i++) - { - desc.numbytes = sz; - desc.u.pbuffer = &ret[i]; - - ioctl(fd, AUDIOIOC_ALLOCBUFFER, (unsigned long)(uintptr_t)&desc); - } - - return ret; -} - -/**************************************************************************** - * name: free_audio_buffers - ****************************************************************************/ - -static void free_audio_buffers(FAR struct nxaudio_s *nxaudio) -{ - int x; - struct audio_buf_desc_s desc; - - for (x = 0; x < nxaudio->abufnum; x++) - { - if (nxaudio->abufs[x] != NULL) - { - desc.u.buffer = nxaudio->abufs[x]; - ioctl(nxaudio->fd, AUDIOIOC_FREEBUFFER, - (unsigned long)(uintptr_t)&desc); - } - } - - free(nxaudio->abufs); -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * name: fin_nxaudio - ****************************************************************************/ - -void fin_nxaudio(FAR struct nxaudio_s *nxaudio) -{ - ioctl(nxaudio->fd, AUDIOIOC_SHUTDOWN, 0); - ioctl(nxaudio->fd, AUDIOIOC_UNREGISTERMQ, (unsigned long)nxaudio->mq); - ioctl(nxaudio->fd, AUDIOIOC_RELEASE, 0); - free_audio_buffers(nxaudio); - close(nxaudio->fd); - mq_close(nxaudio->mq); - mq_unlink(CONFIG_AUDIOUTILS_NXAUDIO_MSGQNAME); -} - -/**************************************************************************** - * name: init_nxaudio - ****************************************************************************/ - -int init_nxaudio(FAR struct nxaudio_s *nxaudio, - int fs, int bps, int chnum) -{ - return init_nxaudio_devname(nxaudio, fs, bps, chnum, - CONFIG_AUDIOUTILS_NXAUDIO_DEVPATH, - CONFIG_AUDIOUTILS_NXAUDIO_MSGQNAME); -} - -/**************************************************************************** - * name: init_nxaudio_devname - ****************************************************************************/ - -int init_nxaudio_devname(FAR struct nxaudio_s *nxaudio, - int fs, int bps, int chnum, - const char *devname, const char *mqname) -{ - struct ap_buffer_info_s buf_info; - - nxaudio->fd = open(devname, O_RDWR | O_CLOEXEC); - if (nxaudio->fd >= 0) - { - if (ioctl(nxaudio->fd, AUDIOIOC_RESERVE, 0) < 0) - { - close(nxaudio->fd); - return -1; - } - - /* Audio configuration: set channel num, FS and bps */ - - configure_audio(nxaudio->fd, chnum, fs, bps, 0); - - nxaudio->chnum = chnum; - - ioctl(nxaudio->fd, AUDIOIOC_GETBUFFERINFO, - (unsigned long)(uintptr_t)&buf_info); - - /* Create message queue to communicate with audio driver */ - - nxaudio->mq = create_audiomq(mqname, nxaudio->fd, - buf_info.nbuffers + 8); - - /* Create audio buffers to inject audio sample */ - - nxaudio->abufs = create_audio_buffers(nxaudio->fd, - buf_info.nbuffers, buf_info.buffer_size); - nxaudio->abufnum = buf_info.nbuffers; - - return 0; - } - else - { - return -1; - } -} - -/**************************************************************************** - * name: nxaudio_enqbuffer - ****************************************************************************/ - -int nxaudio_enqbuffer(FAR struct nxaudio_s *nxaudio, - FAR struct ap_buffer_s *apb) -{ - struct audio_buf_desc_s desc; - - desc.numbytes = apb->nbytes; - desc.u.buffer = apb; - - return ioctl(nxaudio->fd, AUDIOIOC_ENQUEUEBUFFER, - (unsigned long)(uintptr_t)&desc); -} - -/**************************************************************************** - * name: nxaudio_pause - ****************************************************************************/ - -int nxaudio_pause(FAR struct nxaudio_s *nxaudio) -{ - return ioctl(nxaudio->fd, AUDIOIOC_PAUSE, 0); -} - -/**************************************************************************** - * name: nxaudio_resume - ****************************************************************************/ - -int nxaudio_resume(FAR struct nxaudio_s *nxaudio) -{ - return ioctl(nxaudio->fd, AUDIOIOC_RESUME, 0); -} - -/**************************************************************************** - * name: nxaudio_setvolume - ****************************************************************************/ - -int nxaudio_setvolume(FAR struct nxaudio_s *nxaudio, uint16_t vol) -{ - struct audio_caps_desc_s cap_desc; - - cap_desc.caps.ac_len = sizeof(struct audio_caps_s); - cap_desc.caps.ac_type = AUDIO_TYPE_FEATURE; - cap_desc.caps.ac_format.hw = AUDIO_FU_VOLUME; - cap_desc.caps.ac_controls.hw[0] = vol; - - return ioctl(nxaudio->fd, AUDIOIOC_CONFIGURE, - (unsigned long)(uintptr_t)&cap_desc); -} - -/**************************************************************************** - * name: nxaudio_start - ****************************************************************************/ - -int nxaudio_start(FAR struct nxaudio_s *nxaudio) -{ - return ioctl(nxaudio->fd, AUDIOIOC_START, 0); -} - -/**************************************************************************** - * name: nxaudio_start - ****************************************************************************/ - -int nxaudio_stop(FAR struct nxaudio_s *nxaudio) -{ - struct audio_msg_s term_msg; - - term_msg.msg_id = AUDIO_MSG_STOP; - term_msg.u.data = 0; - mq_send(nxaudio->mq, (FAR const char *)&term_msg, sizeof(term_msg), 0); - - ioctl(nxaudio->fd, AUDIOIOC_STOP, 0); - - return OK; -} - -/**************************************************************************** - * name: nxaudio_msgloop - ****************************************************************************/ - -int nxaudio_msgloop(FAR struct nxaudio_s *nxaudio, - FAR struct nxaudio_callbacks_s *cbs, - unsigned long arg) -{ - bool running = true; - struct audio_msg_s msg; - unsigned int prio; - ssize_t size; - - if (!cbs) - { - return -1; - } - - while (running) - { - size = mq_receive(nxaudio->mq, (FAR char *)&msg, sizeof(msg), &prio); - if (size != sizeof(msg)) - { - continue; - } - - switch (msg.msg_id) - { - case AUDIO_MSG_DEQUEUE: - if (cbs->dequeue) - { - cbs->dequeue(arg, msg.u.ptr); - } - break; - case AUDIO_MSG_COMPLETE: - if (cbs->complete) - { - cbs->complete(arg); - } - break; - - case AUDIO_MSG_STOP: - running = false; - break; - - case AUDIO_MSG_USER: - if (cbs->user) - { - cbs->user(arg, &msg, &running); - } - break; - default: - break; - } - } - - return 0; -} diff --git a/audioutils/rtttl-c/.gitignore b/audioutils/rtttl-c/.gitignore deleted file mode 100644 index 554f93513..000000000 --- a/audioutils/rtttl-c/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/rtttl-c diff --git a/audioutils/rtttl-c/Kconfig b/audioutils/rtttl-c/Kconfig deleted file mode 100644 index 8ea3355d5..000000000 --- a/audioutils/rtttl-c/Kconfig +++ /dev/null @@ -1,21 +0,0 @@ -config AUDIOUTILS_RTTTL_C - bool "RTTTL parsing library" - default n - ---help--- - Simple library for parsing Ring Tone Text Transfer Language (RTTTL) - - Define how to make a sound: - - void - play_tone(struct rtttl_tone tone) - { - /* TODO: Make a sound with - * tone.frequency_100hz - * tone.period_us - * tone.duration_us - */ - } - - and then play RTTTL string: - - rtttl_play("...", play_tone); diff --git a/audioutils/rtttl-c/Make.defs b/audioutils/rtttl-c/Make.defs deleted file mode 100644 index fa9aa98f8..000000000 --- a/audioutils/rtttl-c/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/audioutils/rtttl-c/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_AUDIOUTILS_RTTTL_C),) -CONFIGURED_APPS += $(APPDIR)/audioutils/rtttl-c -endif diff --git a/audioutils/rtttl-c/Makefile b/audioutils/rtttl-c/Makefile deleted file mode 100644 index aa290169d..000000000 --- a/audioutils/rtttl-c/Makefile +++ /dev/null @@ -1,50 +0,0 @@ -############################################################################ -# apps/audioutils/rtttl-c/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -CSRCS = $(RTTTL_C_DIR)/rtttl.c - -RTTTL_C_DIR = rtttl-c -RTTTL_C_VERSION = v0.1.0 -RTTTL_C_RTTTL_H_SHA256 = 6331174ae34a419ad427d9755f8ba9d3b6a92c09ecc4f36bbe07ec5e4d0cc007 -RTTTL_C_RTTTL_C_SHA256 = f0db64ef0b68136bac24616a3d62508bcc54ccdd68265d6447d99b264653b7b9 - -$(RTTTL_C_DIR): - $(Q) echo "Cloning rtttl-c repo..." - $(Q) git clone --depth=1 --branch=$(RTTTL_C_VERSION) https://git.sr.ht/~qeef/rtttl-c - $(Q) touch $(RTTTL_C_DIR) - $(Q) echo "Checking rtttl-c hashes..." - $(Q) $(APPDIR)/tools/check-hash.sh sha256 $(RTTTL_C_RTTTL_H_SHA256) $@/rtttl.h - $(Q) $(APPDIR)/tools/check-hash.sh sha256 $(RTTTL_C_RTTTL_C_SHA256) $@/rtttl.c - -create_includes: $(RTTTL_C_DIR)/rtttl.h - $(Q) cp $< $(APPDIR)/include/audioutils - -context:: $(RTTTL_C_DIR) - $(Q) $(MAKE) create_includes - -distclean:: - $(call DELFILE, $(APPDIR)/include/audioutils/rtttl.h) - $(call DELDIR, rtttl-c) - -include $(APPDIR)/Application.mk diff --git a/benchmarks/.gitignore b/benchmarks/.gitignore deleted file mode 100644 index 9e1d2593e..000000000 --- a/benchmarks/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/Kconfig diff --git a/benchmarks/CMakeLists.txt b/benchmarks/CMakeLists.txt deleted file mode 100644 index 9f3c66bf5..000000000 --- a/benchmarks/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -# ############################################################################## -# apps/benchmarks/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -nuttx_add_subdirectory() - -nuttx_generate_kconfig(MENUDESC "Benchmark Applications") diff --git a/benchmarks/Make.defs b/benchmarks/Make.defs deleted file mode 100644 index cfe7377d9..000000000 --- a/benchmarks/Make.defs +++ /dev/null @@ -1,23 +0,0 @@ -############################################################################ -# apps/benchmarks/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(wildcard $(APPDIR)/benchmarks/*/Make.defs) diff --git a/benchmarks/Makefile b/benchmarks/Makefile deleted file mode 100644 index 389f6c5a7..000000000 --- a/benchmarks/Makefile +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/benchmarks/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -MENUDESC = "Benchmark Applications" - -include $(APPDIR)/Directory.mk diff --git a/benchmarks/cachespeed/CMakeLists.txt b/benchmarks/cachespeed/CMakeLists.txt deleted file mode 100644 index 18a2a39d4..000000000 --- a/benchmarks/cachespeed/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# ############################################################################## -# apps/benchmarks/cachespeed/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_BENCHMARK_CACHESPEED) - nuttx_add_application( - NAME - ${CONFIG_BENCHMARK_CACHESPEED_PROGNAME} - SRCS - cachespeed_main.c - STACKSIZE - ${CONFIG_BENCHMARK_CACHESPEED_STACKSIZE} - PRIORITY - ${CONFIG_BENCHMARK_CACHESPEED_PRIORITY}) -endif() diff --git a/benchmarks/cachespeed/Kconfig b/benchmarks/cachespeed/Kconfig deleted file mode 100644 index 0b6f8fc78..000000000 --- a/benchmarks/cachespeed/Kconfig +++ /dev/null @@ -1,44 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config BENCHMARK_CACHESPEED - tristate "CACHE Speed Test" - depends on ARCH_ICACHE && ARCH_DCACHE - default n - ---help--- - Enable a simple CACHE speed test. - -if BENCHMARK_CACHESPEED - -config BENCHMARK_CACHESPEED_PROGNAME - string "Program name" - default "cachespeed" - ---help--- - This is the name of the program that will be used when the NSH ELF - program is installed. - -config BENCHMARK_CACHESPEED_PRIORITY - int "CACHE speed test task priority" - default 100 - -config BENCHMARK_CACHESPEED_STACKSIZE - int "CACHE speed test stack size" - default DEFAULT_TASK_STACKSIZE - -config CACHESPEED_MONOTONIC_TIME - bool "Using Clock Gettime" - default n - ---help--- - When you turn on this option, your test loop will go from 10000 -> 1000 times - Please consider the following scenario: - 1. By default (PERFTIME) will have a relatively high precision, but this also - tends to cause failure in getting values on some smaller bytes, so reducing - the precision with this option can make it easier to get data values. - 2. whether to compare data with the content of other tools (using CLOCK - GETTIME method), if so, it is recommended to turn on, so as to ensure that - the data precision of both consistent. - -endif - diff --git a/benchmarks/cachespeed/Make.defs b/benchmarks/cachespeed/Make.defs deleted file mode 100644 index 5a26c8938..000000000 --- a/benchmarks/cachespeed/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/benchmarks/cachespeed/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_BENCHMARK_CACHESPEED),) -CONFIGURED_APPS += $(APPDIR)/benchmarks/cachespeed -endif diff --git a/benchmarks/cachespeed/Makefile b/benchmarks/cachespeed/Makefile deleted file mode 100644 index 4491b514c..000000000 --- a/benchmarks/cachespeed/Makefile +++ /dev/null @@ -1,38 +0,0 @@ -############################################################################ -# apps/benchmarks/cachespeed/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -#CACHE speed test - -ifneq ($(CONFIG_CACHESPEED_MONOTONIC_TIME),y) - CFLAGS += -DCACHESPEED_PERFTIME -endif - -PROGNAME = $(CONFIG_BENCHMARK_CACHESPEED_PROGNAME) -PRIORITY = $(CONFIG_BENCHMARK_CACHESPEED_PRIORITY) -STACKSIZE = $(CONFIG_BENCHMARK_CACHESPEED_STACKSIZE) -MODULE = $(CONFIG_BENCHMARK_CACHESPEED) - -MAINSRC = cachespeed_main.c - -include $(APPDIR)/Application.mk diff --git a/benchmarks/cachespeed/cachespeed_main.c b/benchmarks/cachespeed/cachespeed_main.c deleted file mode 100644 index c895c3b8f..000000000 --- a/benchmarks/cachespeed/cachespeed_main.c +++ /dev/null @@ -1,254 +0,0 @@ -/**************************************************************************** - * apps/benchmarks/cachespeed/cachespeed_main.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/arch.h> -#include <nuttx/cache.h> -#include <nuttx/config.h> -#include <nuttx/irq.h> - -#include <inttypes.h> -#include <malloc.h> -#include <stdio.h> -#include <stdlib.h> -#include <time.h> - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define CACHESPEED_PREFIX "CACHE Speed: " -#define REPEAT_NUM 1000 - -#ifdef CACHESPEED_PERFTIME - #define TIME uint64_t - - #define CONVERT(cost) \ - do \ - { \ - struct timespec ts; \ - perf_convert(cost, &ts); \ - cost = ts.tv_sec * 1000000000 + ts.tv_nsec; \ - } while (0) - - #define TIMESTAMP(x) (x) = perf_gettime() -#else - #define TIME time_t - - #define CONVERT(cost) - - #define TIMESTAMP(x) \ - do \ - { \ - struct timespec ts; \ - clock_gettime(CLOCK_MONOTONIC, &ts); \ - x = ts.tv_sec * 1000000000 + ts.tv_nsec; \ - } while (0) -#endif - -#define GET_DCACHE_LINE up_get_dcache_linesize() -#define GET_ICACHE_LINE up_get_icache_linesize() -#define GET_DCACHE_SIZE up_get_dcache_size() -#define GET_ICACHE_SIZE up_get_icache_size() - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -struct cachespeed_s -{ - uintptr_t addr; - size_t alloc; -}; - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: setup - ****************************************************************************/ - -static void setup(FAR struct cachespeed_s *cs) -{ - struct mallinfo info = mallinfo(); - - /* Get the currently available memory from the system. We want the - * memset range to be as large as possible in our tests to ensure - * that the cache is filled with our dirty data - */ - - cs->alloc = info.fordblks / 2; - cs->addr = (uintptr_t)malloc(cs->alloc); - if (cs->addr == 0) - { - printf(CACHESPEED_PREFIX "Unable to request memory.\n"); - exit(EXIT_FAILURE); - } - - /* Let's export the test message */ - - printf(CACHESPEED_PREFIX "address src: %" PRIxPTR "\n", cs->addr); -} - -/**************************************************************************** - * Name: teardown - ****************************************************************************/ - -static void teardown(FAR struct cachespeed_s *cs) -{ - free((void *)cs->addr); - printf(CACHESPEED_PREFIX "Done!\n"); -} - -/**************************************************************************** - * Name: report_line - ****************************************************************************/ - -static void report_line(size_t bytes, TIME cost) -{ - double rate; - - /* There is a situation: if the time is 0, then the - * calculated speed is wrong. - */ - - CONVERT(cost); - - if (cost == 0) - { - printf(CACHESPEED_PREFIX "%zu bytes cost time too small!\n", bytes); - return; - } - - /* rate = Test Data Size / Execution Time */ - - rate = 1.00 * bytes * REPEAT_NUM / cost; - - printf("%zu Bytes: %4lf, %4" PRIu64", %4" PRIu64"\n\r", - bytes, rate, cost / REPEAT_NUM, cost); -} - -/**************************************************************************** - * Name: test_skeleton - ****************************************************************************/ - -static void test_skeleton(FAR struct cachespeed_s *cs, - const size_t cache_size, - const size_t cache_line_size, int align, - void (*func)(uintptr_t, uintptr_t), - const char *name) -{ - size_t update_size; - printf("** %s [rate, avg, cost] in nanoseconds(bytes/nesc) %s **\n", - name, align ? "align" : "unalign"); - - if (!align) - { - update_size = cache_line_size - 1; - } - else - { - update_size = cache_line_size; - } - - for (size_t bytes = update_size; - bytes <= cache_size; bytes = 2 * bytes) - { - irqstate_t irq; - TIME start; - TIME end; - TIME cost = 0; - - /* Make sure that test with all the contents - * of our address in the cache. - */ - - up_flush_dcache_all(); - - irq = enter_critical_section(); - for (int i = 0; i < REPEAT_NUM; i++) - { - memset((void *)cs->addr, 1, cs->alloc); - TIMESTAMP(start); - func(cs->addr, (uintptr_t)(cs->addr + bytes)); - TIMESTAMP(end); - cost += end - start; - } - - leave_critical_section(irq); - report_line(bytes, cost); - } -} - -/**************************************************************************** - * Name: cachespeed_common - ****************************************************************************/ - -static void cachespeed_common(struct cachespeed_s *cs) -{ - test_skeleton(cs, GET_DCACHE_SIZE, GET_DCACHE_LINE, 1, - up_invalidate_dcache, "dcache invalidate"); - test_skeleton(cs, GET_DCACHE_SIZE, GET_DCACHE_LINE, 0, - up_invalidate_dcache, "dcache invalidate"); - test_skeleton(cs, GET_DCACHE_SIZE, GET_DCACHE_LINE, 1, - up_clean_dcache, "dcache clean"); - test_skeleton(cs, GET_DCACHE_SIZE, GET_DCACHE_LINE, 0, - up_clean_dcache, "dcache clean"); - test_skeleton(cs, GET_DCACHE_SIZE, GET_DCACHE_LINE, 1, - up_flush_dcache, "dcache flush"); - test_skeleton(cs, GET_DCACHE_SIZE, GET_DCACHE_LINE, 0, - up_flush_dcache, "dcache flush"); - test_skeleton(cs, GET_ICACHE_SIZE, GET_ICACHE_LINE, 1, - up_invalidate_icache, "icache invalidate"); - test_skeleton(cs, GET_ICACHE_SIZE, GET_ICACHE_LINE, 0, - up_invalidate_icache, "icache invalidate"); -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: cachespeed_main - ****************************************************************************/ - -int main(int argc, FAR char *argv[]) -{ - struct cachespeed_s cs = - { - .addr = 0, - .alloc = 0 - }; - - setup(&cs); - cachespeed_common(&cs); - teardown(&cs); - return 0; -} diff --git a/benchmarks/coremark-pro/.gitignore b/benchmarks/coremark-pro/.gitignore deleted file mode 100644 index 617cd88b8..000000000 --- a/benchmarks/coremark-pro/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/coremark-pro diff --git a/benchmarks/coremark-pro/CMakeLists.txt b/benchmarks/coremark-pro/CMakeLists.txt deleted file mode 100644 index 5cd19227b..000000000 --- a/benchmarks/coremark-pro/CMakeLists.txt +++ /dev/null @@ -1,333 +0,0 @@ -# ############################################################################## -# apps/benchmarks/coremark-pro/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_BENCHMARK_COREMARK_PRO) - - set(COREMARKAPP_DIR ${CMAKE_CURRENT_LIST_DIR}/coremark-pro) - - if(NOT EXISTS ${COREMARKAPP_DIR}) - FetchContent_Declare( - coremark_fetch - URL https://github.com/eembc/coremark-pro/archive/refs/heads/main.zip - SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/coremark-pro BINARY_DIR - ${CMAKE_BINARY_DIR}/apps/benchmarks/coremark/coremark-pro - DOWNLOAD_NO_PROGRESS true - TIMEOUT 30) - - FetchContent_GetProperties(coremark_fetch) - if(NOT coremark_fetch_POPULATED) - FetchContent_Populate(coremark_fetch) - endif() - endif() - - nuttx_add_library(coremark_pro STATIC) - - set(CSRCS - coremark-pro/mith/src/md5.c - coremark-pro/mith/src/mith_lib.c - coremark-pro/mith/src/mith_workload.c - coremark-pro/mith/src/th_bignum.c - coremark-pro/mith/src/th_encode.c - coremark-pro/mith/src/th_lib.c - coremark-pro/mith/src/th_math.c - coremark-pro/mith/src/th_rand.c) - - file(GLOB MITH_AL_SRCS coremark-pro/mith/al/src/*.c) - - list(APPEND CSRCS ${MITH_AL_SRCS}) - - set(CFLAGS - -Wno-undef - -Wno-strict-prototypes - -Wno-unused-variable - -Wno-pointer-sign - -Wno-unused-but-set-variable - -Wno-shadow - -DNDEBUG - -DHOST_EXAMPLE_CODE=1 - -DHAVE_SYS_STAT_H=1 - -DGCC_INLINE_MACRO=1 - -DMAX_CONTEXTS=100 - -DEE_SIZEOF_INT=4 - -DUSE_FP128=0) - - set(INCDIR ${CMAKE_CURRENT_LIST_DIR}/coremark-pro/mith/include - ${CMAKE_CURRENT_LIST_DIR}/coremark-pro/mith/al/include) - - if(CONFIG_BENCHMARK_COREMARK_PRO_USE_SINGLE_CONTEXT) - list(APPEND CFLAGS -DUSE_SINGLE_CONTEXT=1 -DHAVE_PTHREAD=0 - -DUSE_NATIVE_PTHREAD=0) - else() - list(APPEND CFLAGS -DUSE_SINGLE_CONTEXT=0 -DHAVE_PTHREAD=1 - -DUSE_NATIVE_PTHREAD=1) - endif() - - if(CONFIG_BENCHMARK_COREMARK_PRO_SMP) - list(APPEND CFLAGS -DHAVE_PTHREAD_SETAFFINITY_NP=1 -DHAVE_PTHREAD_SELF=1) - endif() - - if(CONFIG_BENCHMARK_COREMARK_PRO_64BIT) - list(APPEND CFLAGS -DEE_SIZEOF_PTR=8 -DEE_PTR_ALIGN=8 -DEE_SIZEOF_LONG=8) - endif() - - if(CONFIG_BENCHMARK_COREMARK_PRO_USE_FP64) - - list(APPEND CFLAGS -DUSE_FP64=1 -DUSE_FP32=0) - list(APPEND CSRCS coremark-pro/benchmarks/fp/linpack/ref/inputs_f64.c) - - else() - list(APPEND CFLAGS -DUSE_FP32=1 -DUSE_FP64=0) - list(APPEND CSRCS coremark-pro/benchmarks/fp/linpack/ref/inputs_f32.c) - endif() - - if(CONFIG_BENCHMARK_COREMARK_PRO_CORE_TEST) - file(GLOB CORE_TEST_SRCS coremark-pro/benchmarks/core/*.c) - set(CORE_TEST_CSRCS coremark-pro/workloads/core/core.c ${CORE_TEST_SRCS}) - nuttx_add_application( - NAME - core - PRIORITY - ${CONFIG_BENCHMARK_COREMARK_PRO_PRIORITY} - STACKSIZE - ${CONFIG_BENCHMARK_COREMARK_PRO_STACKSIZE} - MODULE - ${CONFIG_BENCHMARK_COREMARK_PRO} - COMPILE_FLAGS - ${CFLAGS} - SRCS - ${CORE_TEST_CSRCS} - INCLUDE_DIRECTORIES - ${INCDIR} - DEPENDS - coremark_pro) - endif() - - if(CONFIG_BENCHMARK_COREMARK_PRO_CJPEG_TEST) - file(GLOB CJPEG_SRCS coremark-pro/benchmarks/consumer_v2/cjpeg/*.c) - set(CJPEG_CSRCS - coremark-pro/workloads/cjpeg-rose7-preset/cjpeg-rose7-preset.c - coremark-pro/benchmarks/consumer_v2/cjpeg/data/Rose256_bmp.c - ${CJPEG_SRCS}) - nuttx_add_application( - NAME - cjpeg_rose7_preset - PRIORITY - ${CONFIG_BENCHMARK_COREMARK_PRO_PRIORITY} - STACKSIZE - ${CONFIG_BENCHMARK_COREMARK_PRO_STACKSIZE} - MODULE - ${CONFIG_BENCHMARK_COREMARK_PRO} - COMPILE_FLAGS - ${CFLAGS} - SRCS - ${CJPEG_CSRCS} - INCLUDE_DIRECTORIES - ${INCDIR} - DEPENDS - coremark_pro) - endif() - - if(CONFIG_BENCHMARK_COREMARK_PRO_SHA_TEST) - file(GLOB SHA_TEST_SRCS coremark-pro/benchmarks/darkmark/sha/*.c) - set(SHA_TEST_CSRCS coremark-pro/workloads/sha-test/sha-test.c - ${SHA_TEST_SRCS}) - nuttx_add_application( - NAME - sha_test - PRIORITY - ${CONFIG_BENCHMARK_COREMARK_PRO_PRIORITY} - STACKSIZE - ${CONFIG_BENCHMARK_COREMARK_PRO_STACKSIZE} - MODULE - ${CONFIG_BENCHMARK_COREMARK_PRO} - COMPILE_FLAGS - ${CFLAGS} - SRCS - ${SHA_TEST_CSRCS} - INCLUDE_DIRECTORIES - ${INCDIR} - DEPENDS - coremark_pro) - endif() - - if(CONFIG_BENCHMARK_COREMARK_PRO_ZIP_TEST) - set(ZIP_TEST_CSRCS coremark-pro/workloads/zip-test/zip-test.c - coremark-pro/benchmarks/darkmark/zip/zip_darkmark.c) - set(ZIP_TEST_FLAGS ${CFLAGS} -Dgzclose_r=coremark_zip_gzclose_r - -Dgzclose_w=coremark_zip_gzclose_w) - set(ZIP_TEST_INCDIR ${INCDIR} ${NUTTX_APPS_DIR}/system/zlib/zlib) - nuttx_add_application( - NAME - zip_test - PRIORITY - ${CONFIG_BENCHMARK_COREMARK_PRO_PRIORITY} - STACKSIZE - ${CONFIG_BENCHMARK_COREMARK_PRO_STACKSIZE} - MODULE - ${CONFIG_BENCHMARK_COREMARK_PRO} - COMPILE_FLAGS - ${ZIP_TEST_FLAGS} - SRCS - ${ZIP_TEST_CSRCS} - INCLUDE_DIRECTORIES - ${ZIP_TEST_INCDIR} - DEPENDS - coremark_pro) - endif() - - if(CONFIG_BENCHMARK_COREMARK_PRO_LINEAR_ALG_MID_TEST) - set(ALG_MID_CSRCS - coremark-pro/workloads/linear_alg-mid-100x100-sp/linear_alg-mid-100x100-sp.c - coremark-pro/benchmarks/fp/linpack/linpack.c) - nuttx_add_application( - NAME - linear_alg_mid_100x100_sp - PRIORITY - ${CONFIG_BENCHMARK_COREMARK_PRO_PRIORITY} - STACKSIZE - ${CONFIG_BENCHMARK_COREMARK_PRO_STACKSIZE} - MODULE - ${CONFIG_BENCHMARK_COREMARK_PRO} - COMPILE_FLAGS - ${CFLAGS} - SRCS - ${ALG_MID_CSRCS} - INCLUDE_DIRECTORIES - ${INCDIR} - DEPENDS - coremark_pro) - endif() - - if(CONFIG_BENCHMARK_COREMARK_PRO_RADIX_TEST) - if(CONFIG_BENCHMARK_COREMARK_PRO_USE_FP64) - file(GLOB RADIX_SRCS coremark-pro/benchmarks/fp/fft_radix2/ref/*.c) - else() - file(GLOB RADIX_SRCS coremark-pro/benchmarks/fp/fft_radix2/ref-sp/*.c) - endif() - - set(RADIX_CSRCS - coremark-pro/workloads/radix2-big-64k/radix2-big-64k.c - coremark-pro/benchmarks/fp/fft_radix2/fft_radix2.c ${RADIX_SRCS}) - nuttx_add_application( - NAME - radix2_big_64k - PRIORITY - ${CONFIG_BENCHMARK_COREMARK_PRO_PRIORITY} - STACKSIZE - ${CONFIG_BENCHMARK_COREMARK_PRO_STACKSIZE} - MODULE - ${CONFIG_BENCHMARK_COREMARK_PRO} - COMPILE_FLAGS - ${CFLAGS} - SRCS - ${RADIX_CSRCS} - INCLUDE_DIRECTORIES - ${INCDIR} - DEPENDS - coremark_pro) - endif() - - if(CONFIG_BENCHMARK_COREMARK_PRO_LOOPS_ALL_MID_TEST) - if(CONFIG_BENCHMARK_COREMARK_PRO_USE_FP64) - file(GLOB MID_SRCS coremark-pro/benchmarks/fp/loops/ref/*.c) - else() - file(GLOB MID_SRCS coremark-pro/benchmarks/fp/loops/ref-sp/*.c) - endif() - - set(MID_CSRCS - coremark-pro/workloads/loops-all-mid-10k-sp/loops-all-mid-10k-sp.c - coremark-pro/benchmarks/fp/loops/loops.c ${MID_SRCS}) - nuttx_add_application( - NAME - loops_all_mid_10k_sp - PRIORITY - ${CONFIG_BENCHMARK_COREMARK_PRO_PRIORITY} - STACKSIZE - ${CONFIG_BENCHMARK_COREMARK_PRO_STACKSIZE} - MODULE - ${CONFIG_BENCHMARK_COREMARK_PRO} - COMPILE_FLAGS - ${CFLAGS} - SRCS - ${MID_CSRCS} - INCLUDE_DIRECTORIES - ${INCDIR} - DEPENDS - coremark_pro) - endif() - - if(CONFIG_BENCHMARK_COREMARK_PRO_NNET_TEST) - if(CONFIG_BENCHMARK_COREMARK_PRO_USE_FP64) - file(GLOB NNET_SRCS coremark-pro/benchmarks/fp/nnet/ref/*.c) - else() - file(GLOB NNET_SRCS coremark-pro/benchmarks/fp/nnet/ref-sp/*.c) - endif() - file(GLOB FP_NNET_SRCS coremark-pro/benchmarks/fp/nnet/*.c) - set(NNET_CSRCS coremark-pro/workloads/nnet_test/nnet_test.c ${FP_NNET_SRCS} - ${NNET_SRCS}) - nuttx_add_application( - NAME - nnet_test - PRIORITY - ${CONFIG_BENCHMARK_COREMARK_PRO_PRIORITY} - STACKSIZE - ${CONFIG_BENCHMARK_COREMARK_PRO_STACKSIZE} - MODULE - ${CONFIG_BENCHMARK_COREMARK_PRO} - COMPILE_FLAGS - ${CFLAGS} - SRCS - ${NNET_CSRCS} - INCLUDE_DIRECTORIES - ${INCDIR} - DEPENDS - coremark_pro) - endif() - - if(CONFIG_BENCHMARK_COREMARK_PRO_PARSER_125K) - file(GLOB PARSER_SRCS coremark-pro/benchmarks/darkmark/parser/*.c) - set(PARSER_CSRCS coremark-pro/workloads/parser-125k/parser-125k.c - ${PARSER_SRCS}) - nuttx_add_application( - NAME - parser_125k - PRIORITY - ${CONFIG_BENCHMARK_COREMARK_PRO_PRIORITY} - STACKSIZE - ${CONFIG_BENCHMARK_COREMARK_PRO_STACKSIZE} - MODULE - ${CONFIG_BENCHMARK_COREMARK_PRO} - COMPILE_FLAGS - ${CFLAGS} - SRCS - ${PARSER_CSRCS} - INCLUDE_DIRECTORIES - ${INCDIR} - DEPENDS - coremark_pro) - endif() - - target_sources(coremark_pro PRIVATE ${CSRCS}) - target_include_directories(coremark_pro PRIVATE ${INCDIR}) - target_compile_options(coremark_pro PRIVATE ${CFLAGS}) - -endif() diff --git a/benchmarks/coremark-pro/Kconfig b/benchmarks/coremark-pro/Kconfig deleted file mode 100644 index a4027787f..000000000 --- a/benchmarks/coremark-pro/Kconfig +++ /dev/null @@ -1,81 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -menuconfig BENCHMARK_COREMARK_PRO - tristate "Coremark Pro Benchmark" - default n - depends on LIBC_FLOATINGPOINT - -if BENCHMARK_COREMARK_PRO - -config BENCHMARK_COREMARK_PRO_STACKSIZE - int "Coremark Pro stack size" - default 131072 - -config BENCHMARK_COREMARK_PRO_PRIORITY - int "Coremark Pro priority" - default 100 - -config BENCHMARK_COREMARK_PRO_USE_SINGLE_CONTEXT - bool "use single context" - default n - -config BENCHMARK_COREMARK_PRO_SMP - bool "Relevant configurations in case of SMP" - default n - depends on SMP && !BENCHMARK_COREMARK_PRO_USE_SINGLE_CONTEXT - -config BENCHMARK_COREMARK_PRO_64BIT - bool "Running on 64-bit operating systems" - default n - -config BENCHMARK_COREMARK_PRO_USE_FP64 - bool "USE FP64 Data for Test" - default n - -config BENCHMARK_COREMARK_PRO_CORE_TEST - bool "Core Test" - default n - -config BENCHMARK_COREMARK_PRO_CJPEG_TEST - bool "cjpeg-rose7-preset" - default n - ---help--- - Before using this case, place the files in coremark-pro/benchmarks/libbmp - and coremark-pro/benchmarks/libjpeg in /data/libbmp and /data/libjpeg - respectively - -config BENCHMARK_COREMARK_PRO_LINEAR_ALG_MID_TEST - bool "Linear_alg_mid TEST" - default n - -config BENCHMARK_COREMARK_PRO_SHA_TEST - bool "SHA Test" - default n - -config BENCHMARK_COREMARK_PRO_ZIP_TEST - bool "Zip Test" - depends on LIB_ZLIB - default n - -choice - prompt "Coremark Pro FP Test Case configuration" - default BENCHMARK_COREMARK_PRO_RADIX_TEST - -config BENCHMARK_COREMARK_PRO_RADIX_TEST - bool "Radix Test" - -config BENCHMARK_COREMARK_PRO_LOOPS_ALL_MID_TEST - bool "Loops-all-mid test" - -config BENCHMARK_COREMARK_PRO_NNET_TEST - bool "Nnet Test" - -config BENCHMARK_COREMARK_PRO_PARSER_125K - bool "Parser 125K Test" - -endchoice - -endif diff --git a/benchmarks/coremark-pro/Make.defs b/benchmarks/coremark-pro/Make.defs deleted file mode 100644 index 144f4ce3d..000000000 --- a/benchmarks/coremark-pro/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/benchmarks/coremark-pro/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_BENCHMARK_COREMARK_PRO),) -CONFIGURED_APPS += $(APPDIR)/benchmarks/coremark-pro -endif diff --git a/benchmarks/coremark-pro/Makefile b/benchmarks/coremark-pro/Makefile deleted file mode 100644 index ccc6d5bbb..000000000 --- a/benchmarks/coremark-pro/Makefile +++ /dev/null @@ -1,160 +0,0 @@ -############################################################################ -# apps/benchmarks/coremark-pro/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -PRIORITY = $(CONFIG_BENCHMARK_COREMARK_PRO_PRIORITY) -STACKSIZE = $(CONFIG_BENCHMARK_COREMARK_PRO_STACKSIZE) -MODULE = $(CONFIG_BENCHMARK_COREMARK_PRO) - -CFLAGS += -Wno-undef -Wno-strict-prototypes -Wno-unused-variable \ - -Wno-pointer-sign -Wno-unused-but-set-variable -Wno-shadow -CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/benchmarks/coremark-pro/coremark-pro/mith/include -CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/benchmarks/coremark-pro/coremark-pro/mith/al/include -CFLAGS += -DNDEBUG -DHOST_EXAMPLE_CODE=1 -DHAVE_SYS_STAT_H=1 \ - -DGCC_INLINE_MACRO=1 -DMAX_CONTEXTS=100 -DEE_SIZEOF_INT=4 \ - -DUSE_FP128=0 - -ifneq ($(CONFIG_BENCHMARK_COREMARK_PRO_USE_SINGLE_CONTEXT),) - CFLAGS += -DUSE_SINGLE_CONTEXT=1 -DHAVE_PTHREAD=0 -DUSE_NATIVE_PTHREAD=0 -else - CFLAGS += -DUSE_SINGLE_CONTEXT=0 -DHAVE_PTHREAD=1 -DUSE_NATIVE_PTHREAD=1 -endif - -ifneq ($(CONFIG_BENCHMARK_COREMARK_PRO_SMP),) - CFLAGS += -DHAVE_PTHREAD_SETAFFINITY_NP=1 -DHAVE_PTHREAD_SELF=1 -endif - -ifneq ($(CONFIG_BENCHMARK_COREMARK_PRO_64BIT),) - CFLAGS += -DEE_SIZEOF_PTR=8 -DEE_PTR_ALIGN=8 -DEE_SIZEOF_LONG=8 -endif - -ifneq ($(CONFIG_BENCHMARK_COREMARK_PRO_USE_FP64),) - CFLAGS += -DUSE_FP64=1 -DUSE_FP32=0 - CSRCS += coremark-pro/benchmarks/fp/linpack/ref/inputs_f64.c -else - CFLAGS += -DUSE_FP32=1 -DUSE_FP64=0 - CSRCS += coremark-pro/benchmarks/fp/linpack/ref/inputs_f32.c -endif - -CSRCS += coremark-pro/mith/src/md5.c -CSRCS += coremark-pro/mith/src/mith_lib.c -CSRCS += coremark-pro/mith/src/mith_workload.c -CSRCS += coremark-pro/mith/src/th_bignum.c -CSRCS += coremark-pro/mith/src/th_encode.c -CSRCS += coremark-pro/mith/src/th_lib.c -CSRCS += coremark-pro/mith/src/th_math.c -CSRCS += coremark-pro/mith/src/th_rand.c - -CSRCS += $(wildcard coremark-pro/mith/al/src/*.c) - -ifneq ($(CONFIG_BENCHMARK_COREMARK_PRO_CORE_TEST),) - CSRCS += $(wildcard coremark-pro/benchmarks/core/*.c) - MAINSRC += coremark-pro/workloads/core/core.c - PROGNAME += core -endif - -ifneq ($(CONFIG_BENCHMARK_COREMARK_PRO_CJPEG_TEST),) - CSRCS += $(wildcard coremark-pro/benchmarks/consumer_v2/cjpeg/*.c) - CSRCS += $(wildcard coremark-pro/benchmarks/consumer_v2/cjpeg/data/Rose256_bmp.c) - MAINSRC += coremark-pro/workloads/cjpeg-rose7-preset/cjpeg-rose7-preset.c - PROGNAME += cjpeg_rose7_preset -endif - -ifneq ($(CONFIG_BENCHMARK_COREMARK_PRO_SHA_TEST),) - CSRCS += $(wildcard coremark-pro/benchmarks/darkmark/sha/*.c) - MAINSRC += coremark-pro/workloads/sha-test/sha-test.c - PROGNAME += sha_test -endif - -ifneq ($(CONFIG_BENCHMARK_COREMARK_PRO_ZIP_TEST),) - CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/system/zlib/zlib - CFLAGS += -Dgzclose_r=coremark_zip_gzclose_r -Dgzclose_w=coremark_zip_gzclose_w - CSRCS += coremark-pro/benchmarks/darkmark/zip/zip_darkmark.c - MAINSRC += coremark-pro/workloads/zip-test/zip-test.c - PROGNAME += zip_test -endif - -ifneq ($(CONFIG_BENCHMARK_COREMARK_PRO_LINEAR_ALG_MID_TEST),) - CSRCS += coremark-pro/benchmarks/fp/linpack/linpack.c - MAINSRC += coremark-pro/workloads/linear_alg-mid-100x100-sp/linear_alg-mid-100x100-sp.c - PROGNAME += linear_alg_mid_100x100_sp -endif - -ifneq ($(CONFIG_BENCHMARK_COREMARK_PRO_RADIX_TEST),) - ifneq ($(CONFIG_BENCHMARK_COREMARK_PRO_USE_FP64),) - CSRCS += $(wildcard coremark-pro/benchmarks/fp/fft_radix2/ref/*.c) - else - CSRCS += $(wildcard coremark-pro/benchmarks/fp/fft_radix2/ref-sp/*.c) - endif - - CSRCS += coremark-pro/benchmarks/fp/fft_radix2/fft_radix2.c - MAINSRC += coremark-pro/workloads/radix2-big-64k/radix2-big-64k.c - PROGNAME += radix2_big_64k -endif - -ifneq ($(CONFIG_BENCHMARK_COREMARK_PRO_LOOPS_ALL_MID_TEST),) - ifneq ($(CONFIG_BENCHMARK_COREMARK_PRO_USE_FP64),) - CSRCS += $(wildcard coremark-pro/benchmarks/fp/loops/ref/*.c) - else - CSRCS += $(wildcard coremark-pro/benchmarks/fp/loops/ref-sp/*.c) - endif - - CSRCS += coremark-pro/benchmarks/fp/loops/loops.c - MAINSRC += coremark-pro/workloads/loops-all-mid-10k-sp/loops-all-mid-10k-sp.c - PROGNAME += loops_all_mid_10k_sp -endif - -ifneq ($(CONFIG_BENCHMARK_COREMARK_PRO_NNET_TEST),) - ifneq ($(CONFIG_BENCHMARK_COREMARK_PRO_USE_FP64),) - CSRCS += $(wildcard coremark-pro/benchmarks/fp/nnet/ref/*.c) - else - CSRCS += $(wildcard coremark-pro/benchmarks/fp/nnet/ref-sp/*.c) - endif - - CSRCS += $(wildcard coremark-pro/benchmarks/fp/nnet/*.c) - MAINSRC += coremark-pro/workloads/nnet_test/nnet_test.c - PROGNAME += nnet_test -endif - -ifneq ($(CONFIG_BENCHMARK_COREMARK_PRO_PARSER_125K),) - CSRCS += $(wildcard coremark-pro/benchmarks/darkmark/parser/*.c) - MAINSRC += coremark-pro/workloads/parser-125k/parser-125k.c - PROGNAME += parser_125k -endif - -ifeq ($(wildcard coremark-pro/.git),) -VERSION ?= main -coremark-pro.zip: - $(Q) curl -L https://github.com/eembc/coremark-pro/archive/refs/heads/main.zip -o coremark-pro.zip - $(Q) unzip -o coremark-pro.zip - $(Q) mv coremark-pro-$(VERSION) coremark-pro - -context:: coremark-pro.zip - -distclean:: - $(call DELDIR, coremark-pro) - $(call DELFILE, coremark-pro.zip) - -endif - -include $(APPDIR)/Application.mk diff --git a/benchmarks/coremark/.gitignore b/benchmarks/coremark/.gitignore deleted file mode 100644 index f8968384b..000000000 --- a/benchmarks/coremark/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/coremark -/*.zip diff --git a/benchmarks/coremark/CMakeLists.txt b/benchmarks/coremark/CMakeLists.txt deleted file mode 100644 index 3aef2967a..000000000 --- a/benchmarks/coremark/CMakeLists.txt +++ /dev/null @@ -1,153 +0,0 @@ -# ############################################################################## -# apps/benchmarks/coremark/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_BENCHMARK_COREMARK) - - # ############################################################################ - # Config and Fetch Coremark application - # ############################################################################ - - set(COREMARKAPP_DIR ${CMAKE_CURRENT_LIST_DIR}/coremark) - - if(NOT EXISTS ${COREMARKAPP_DIR}) - FetchContent_Declare( - coremark_fetch - URL https://github.com/eembc/coremark/archive/main.zip SOURCE_DIR - ${CMAKE_CURRENT_LIST_DIR}/coremark BINARY_DIR - ${CMAKE_BINARY_DIR}/apps/benchmarks/coremark/coremark - DOWNLOAD_NO_PROGRESS true - TIMEOUT 30) - - FetchContent_GetProperties(coremark_fetch) - if(NOT coremark_fetch_POPULATED) - FetchContent_Populate(coremark_fetch) - endif() - endif() - - if(CONFIG_COREMARK_MULTITHREAD_OVERRIDE) - set(COREMARK_NTHREADS ${CONFIG_COREMARK_MULTITHREAD_COUNT}) - endif() - - if(CONFIG_SMP_NCPUS) - set(COREMARK_NTHREADS ${CONFIG_SMP_NCPUS}) - else() - set(COREMARK_NTHREADS 1) - endif() - - if(CONFIG_COREMARK_PRINT_ARGS) - set(COREMARK_PRINT_ARGS 1) - else() - set(COREMARK_PRINT_ARGS 0) - endif() - - # ############################################################################ - # Flags - # ############################################################################ - - if(CONFIG_COREMARK_MULTITHREAD_OVERRIDE) - set(COREMARK_NTHREADS ${CONFIG_COREMARK_MULTITHREAD_COUNT}) - else() - if(CONFIG_SMP_NCPUS) - set(COREMARK_NTHREADS ${CONFIG_SMP_NCPUS}) - else() - set(COREMARK_NTHREADS 1) - endif() - endif() - - if(CONFIG_COREMARK_PRINT_ARGS) - set(COREMARK_PRINT_ARGS 1) - else() - set(COREMARK_PRINT_ARGS 0) - endif() - - get_target_property(FLAGS_STR_LIST nuttx COMPILE_OPTIONS) - list(JOIN FLAGS_STR_LIST " " FLAGS_STR) - - set(CFLAGS -Dcrc16=coremark_crc16 -Wno-strict-prototypes -Wno-undef) - - if("${CONFIG_COREMARK_MEM_METHOD}" STREQUAL "1") - list(APPEND CFLAGS -DMEM_LOCATION=\"HEAP\") - elseif("${CONFIG_COREMARK_MEM_METHOD}" STREQUAL "2") - list(APPEND CFLAGS -DMEM_LOCATION=\"STACK\") - else() - list(APPEND CFLAGS -DMEM_LOCATION=\"GLOBAL\") - endif() - - list( - APPEND - CFLAGS - -DCALLGRIND_RUN=0 - -DCOMPILER_REQUIRES_SORT_RETURN=0 - -DCORE_DEBUG=${CONFIG_COREMARK_DEBUG} - -DFLAGS_STR="${FLAGS_STR}" - -DMEM_METHOD=${CONFIG_COREMARK_MEM_METHOD} - -DMICA=0 - -DMULTITHREAD=${COREMARK_NTHREADS} - -DPERFORMANCE_RUN=1 - -DPRINT_ARGS=${COREMARK_PRINT_ARGS} - -DSEED_METHOD=${CONFIG_COREMARK_SEED_METHOD} - -DUSE_CLOCK=1 - -DUSE_PTHREAD) - - if(CONFIG_COREMARK_ITERATIONS_OVERRIDE) - list(APPEND CFLAGS -DITERATIONS=${CONFIG_COREMARK_ITERATIONS_COUNT}) - else() - list(APPEND CFLAGS -DITERATIONS=0) - - endif() - - # ############################################################################ - # Sources - # ############################################################################ - - set(CSRCS - ${COREMARKAPP_DIR}/core_main.c ${COREMARKAPP_DIR}/core_list_join.c - ${COREMARKAPP_DIR}/core_matrix.c ${COREMARKAPP_DIR}/core_state.c - ${COREMARKAPP_DIR}/core_util.c ${COREMARKAPP_DIR}/posix/core_portme.c) - - # ############################################################################ - # Include Directory - # ############################################################################ - - set(INCDIR ${COREMARKAPP_DIR} ${COREMARKAPP_DIR}/posix) - - # ############################################################################ - # Applications Configuration - # ############################################################################ - - nuttx_add_application( - NAME - ${CONFIG_COREMARK_PROGNAME} - PRIORITY - ${CONFIG_COREMARK_PRIORITY} - STACKSIZE - ${CONFIG_COREMARK_STACKSIZE} - MODULE - ${CONFIG_BENCHMARK_COREMARK} - COMPILE_FLAGS - ${CFLAGS} - SRCS - ${CSRCS} - INCLUDE_DIRECTORIES - ${INCDIR}) - -endif() diff --git a/benchmarks/coremark/Kconfig b/benchmarks/coremark/Kconfig deleted file mode 100644 index 206be8eca..000000000 --- a/benchmarks/coremark/Kconfig +++ /dev/null @@ -1,86 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -menuconfig BENCHMARK_COREMARK - tristate "CoreMark Benchmark" - select LIBC_FLOATINGPOINT - default n - ---help--- - Enable support for the EEMBC's CoreMark benchmark application. - -if BENCHMARK_COREMARK - -config COREMARK_PROGNAME - string "CoreMark program name" - default "coremark" - ---help--- - This is the name of the program that will be used when the NSH ELF - program is installed. - -config COREMARK_PRIORITY - int "CoreMark task priority" - default 100 - -config COREMARK_STACKSIZE - int "CoreMark task stack size" - default 4096 - -config COREMARK_SEED_METHOD - int "Coremark Seed Method" - default 2 - ---help--- - Set Coremark Seed Method: - 0: SEED_ARG - 1: SEED_FUNC - 2: SEED_VOLATILE - -config COREMARK_MEM_METHOD - int "Coremark Memory Method" - default 1 - ---help--- - Set Coremark Memory Method: - 0: MEM_STATIC - 1: MEM_MALLOC - 2: MEM_STACK - -config COREMARK_DEBUG - int "Coremark Core Debug" - default 0 - ---help--- - Enable the Core Debug: - 0: Disable - 1: Enable - -config COREMARK_PRINT_ARGS - bool "Print CoreMark arguments when executing" - default n - ---help--- - Print the command line arguments passed on to coremark. - -config COREMARK_MULTITHREAD_OVERRIDE - bool "Override number of threads" - default n - ---help--- - Override the default number of threads to be executed. - The default value is the same as the number of CPU cores. - -config COREMARK_MULTITHREAD_COUNT - depends on COREMARK_MULTITHREAD_OVERRIDE - int "Number of threads to be executed" - default 1 - -config COREMARK_ITERATIONS_OVERRIDE - bool "Override number of iterations" - default n - ---help--- - Override the default number of iterations for the benchmark. - The default value is defined by the application based on the system. - -config COREMARK_ITERATIONS_COUNT - depends on COREMARK_ITERATIONS_OVERRIDE - int "Number of iterations" - default 100 - -endif # BENCHMARK_COREMARK diff --git a/benchmarks/coremark/Make.defs b/benchmarks/coremark/Make.defs deleted file mode 100644 index 971b261df..000000000 --- a/benchmarks/coremark/Make.defs +++ /dev/null @@ -1,27 +0,0 @@ -############################################################################ -# apps/benchmarks/coremark/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_BENCHMARK_COREMARK),) -CONFIGURED_APPS += $(APPDIR)/benchmarks/coremark -CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/benchmarks/coremark/coremark -CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/benchmarks/coremark/coremark/posix -endif diff --git a/benchmarks/coremark/Makefile b/benchmarks/coremark/Makefile deleted file mode 100644 index c1b02e5f0..000000000 --- a/benchmarks/coremark/Makefile +++ /dev/null @@ -1,145 +0,0 @@ -############################################################################ -# apps/benchmarks/coremark/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -# Coremark application - -############################################################################ -# Flags -############################################################################ - -COREMARK_URL ?= "https://github.com/eembc/coremark/archive" - -COREMARK_VERSION = main -COREMARK_ZIP = $(COREMARK_VERSION).zip - -COREMARK_UNPACKNAME = coremark -UNPACK ?= unzip -q -o - -VPATH += $(COREMARK_UNPACKNAME) -VPATH += $(COREMARK_UNPACKNAME)$(DELIM)posix -DEPPATH += --dep-path $(COREMARK_UNPACKNAME) -DEPPATH += --dep-path $(COREMARK_UNPACKNAME)$(DELIM)posix - -CFLAGS += -Dcrc16=coremark_crc16 -CFLAGS += -Wno-strict-prototypes -Wno-undef - -ifeq ($(CONFIG_COREMARK_MULTITHREAD_OVERRIDE),y) -COREMARK_NTHREADS = $(CONFIG_COREMARK_MULTITHREAD_COUNT) -else -ifneq ($(CONFIG_SMP_NCPUS),) -COREMARK_NTHREADS = $(CONFIG_SMP_NCPUS) -else -COREMARK_NTHREADS = 1 -endif -endif - -ifeq ($(CONFIG_COREMARK_PRINT_ARGS),y) -COREMARK_PRINT_ARGS = 1 -else -COREMARK_PRINT_ARGS = 0 -endif - -ifeq ($(CONFIG_COREMARK_MEM_METHOD), 1) -CFLAGS += ${DEFINE_PREFIX}MEM_LOCATION=\"HEAP\" -else ifeq ($(CONFIG_COREMARK_MEM_METHOD), 2) -CFLAGS += ${DEFINE_PREFIX}MEM_LOCATION=\"STACK\" -else -CFLAGS += ${DEFINE_PREFIX}MEM_LOCATION=\"GLOBAL\" -endif - -CFLAGS += ${DEFINE_PREFIX}CALLGRIND_RUN=0 -CFLAGS += ${DEFINE_PREFIX}COMPILER_REQUIRES_SORT_RETURN=0 -CFLAGS += ${DEFINE_PREFIX}CORE_DEBUG=$(CONFIG_COREMARK_DEBUG) -CFLAGS += ${DEFINE_PREFIX}FLAGS_STR=\""$(ARCHOPTIMIZATION)\"" -CFLAGS += ${DEFINE_PREFIX}MEM_METHOD=$(CONFIG_COREMARK_MEM_METHOD) -CFLAGS += ${DEFINE_PREFIX}MICA=0 -CFLAGS += ${DEFINE_PREFIX}MULTITHREAD=$(COREMARK_NTHREADS) -CFLAGS += ${DEFINE_PREFIX}PERFORMANCE_RUN=1 -CFLAGS += ${DEFINE_PREFIX}PRINT_ARGS=$(COREMARK_PRINT_ARGS) -CFLAGS += ${DEFINE_PREFIX}SEED_METHOD=$(CONFIG_COREMARK_SEED_METHOD) -CFLAGS += ${DEFINE_PREFIX}USE_CLOCK=1 -CFLAGS += ${DEFINE_PREFIX}USE_PTHREAD - -ifeq ($(CONFIG_COREMARK_ITERATIONS_OVERRIDE),y) -CFLAGS += ${DEFINE_PREFIX}ITERATIONS=$(CONFIG_COREMARK_ITERATIONS_COUNT) -else -CFLAGS += ${DEFINE_PREFIX}ITERATIONS=0 -endif - -CFLAGS += ${DEFINE_PREFIX}crcu8=coremark_crcu8 -CFLAGS += ${DEFINE_PREFIX}crcu16=coremark_crcu16 -CFLAGS += ${DEFINE_PREFIX}crcu32=coremark_crcu32 -CFLAGS += ${DEFINE_PREFIX}crc16=coremark_crc16 - -CSRCS += core_list_join.c -CSRCS += core_matrix.c -CSRCS += core_state.c -CSRCS += core_util.c -CSRCS += core_portme.c - -############################################################################ -# Targets -############################################################################ - -$(COREMARK_ZIP): - @echo "Downloading: $(COREMARK_URL)/$(COREMARK_ZIP)" - $(Q) curl -O -L $(COREMARK_URL)/$(COREMARK_ZIP) - -$(COREMARK_UNPACKNAME): $(COREMARK_ZIP) - @echo "Unpacking: $(COREMARK_ZIP) -> $(COREMARK_UNPACKNAME)" - $(Q) $(UNPACK) $(COREMARK_ZIP) - $(Q) mv coremark-$(COREMARK_VERSION) $(COREMARK_UNPACKNAME) - $(Q) patch -p0 < add_init_message.patch # Update init message - $(Q) touch $(COREMARK_UNPACKNAME) - -clean:: - $(call DELFILE, $(OBJS)) - -# Download and unpack tarball if no git repo found - -ifeq ($(wildcard $(COREMARK_UNPACKNAME)/.git),) -context:: $(COREMARK_UNPACKNAME) - -distclean:: - $(call DELDIR, $(COREMARK_UNPACKNAME)) - $(call DELFILE, $(COREMARK_ZIP)) -endif - -############################################################################ -# Applications Configuration -############################################################################ - -MODULE = $(CONFIG_BENCHMARK_COREMARK) - -PROGNAME += $(CONFIG_COREMARK_PROGNAME) -PRIORITY += $(CONFIG_COREMARK_PRIORITY) -STACKSIZE += $(CONFIG_COREMARK_STACKSIZE) - -MAINSRC += core_main.c - -# Build with WebAssembly when CONFIG_INTERPRETERS_WAMR is enabled - -WASM_BUILD = both - -include $(APPDIR)/Application.mk diff --git a/benchmarks/coremark/add_init_message.patch b/benchmarks/coremark/add_init_message.patch deleted file mode 100644 index 6ceecc063..000000000 --- a/benchmarks/coremark/add_init_message.patch +++ /dev/null @@ -1,12 +0,0 @@ ---- coremark/posix/core_portme.c -+++ coremark/posix/core_portme.c -@@ -208,6 +208,9 @@ ee_u32 default_num_contexts = MULTITHREAD; - void - portable_init(core_portable *p, int *argc, char *argv[]) - { -+ -+ ee_printf("Running CoreMark...\n"); -+ - #if PRINT_ARGS - int i; - for (i = 0; i < *argc; i++) diff --git a/benchmarks/cyclictest/CMakeLists.txt b/benchmarks/cyclictest/CMakeLists.txt deleted file mode 100644 index 59cfd2cf8..000000000 --- a/benchmarks/cyclictest/CMakeLists.txt +++ /dev/null @@ -1,55 +0,0 @@ -# ############################################################################## -# apps/benchmarks/cyclictest/CMakeLists.txt -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_BENCHMARK_CYCLICTEST) - - # ############################################################################ - # Config and Fetch Coremark application - # ############################################################################ - - set(CYCLICTEST_DIR ${CMAKE_CURRENT_LIST_DIR}) - - # ############################################################################ - # Sources - # ############################################################################ - - set(CSRCS ${CYCLICTEST_DIR}/cyclictest.c) - - # ############################################################################ - # Applications Configuration - # ############################################################################ - - nuttx_add_application( - NAME - cyclictest - PRIORITY - ${CONFIG_CYCLICTEST_PRIORITY} - STACKSIZE - ${CONFIG_CYCLICTEST_STACKSIZE} - MODULE - ${CONFIG_BENCHMARK_CYCLICTEST} - COMPILE_FLAGS - ${CFLAGS} - SRCS - ${CSRCS} - INCLUDE_DIRECTORIES - ${INCDIR}) - -endif() diff --git a/benchmarks/cyclictest/Kconfig b/benchmarks/cyclictest/Kconfig deleted file mode 100644 index 10f80734b..000000000 --- a/benchmarks/cyclictest/Kconfig +++ /dev/null @@ -1,29 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -menuconfig BENCHMARK_CYCLICTEST - bool "Cyclictest" - default n - ---help--- - Enable the cyclictest application. - -if BENCHMARK_CYCLICTEST - -config BENCHMARK_CYCLICTEST_PROGNAME - string "Cyclictest App Name" - default "cyclictest" - ---help--- - This is the name of the program that will be used when the NSH ELF - program is installed. - -config BENCHMARK_CYCLICTEST_PRIORITY - int "Cyclictest task priority" - default 100 - -config BENCHMARK_CYCLICTEST_STACKSIZE - int "Cyclictest task stack size" - default 4096 - -endif # BENCHMARK_CYCLICTEST diff --git a/benchmarks/cyclictest/Makefile b/benchmarks/cyclictest/Makefile deleted file mode 100644 index b7f516919..000000000 --- a/benchmarks/cyclictest/Makefile +++ /dev/null @@ -1,39 +0,0 @@ -############################################################################ -# apps/benchmarks/cyclictest/Makefile -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -# spinlock_bench application - -############################################################################ -# Applications Configuration -############################################################################ - -MODULE = $(CONFIG_BENCHMARK_CYCLICTEST) - -PROGNAME += $(CONFIG_BENCHMARK_CYCLICTEST_PROGNAME) -PRIORITY += $(CONFIG_BENCHMARK_CYCLICTEST_PRIORITY) -STACKSIZE += $(CONFIG_BENCHMARK_CYCLICTEST_STACKSIZE) - -MAINSRC += cyclictest.c - -# Build with WebAssembly when CONFIG_INTERPRETERS_WAMR is enabled - -include $(APPDIR)/Application.mk diff --git a/benchmarks/cyclictest/cyclictest.c b/benchmarks/cyclictest/cyclictest.c deleted file mode 100644 index fb9382dd5..000000000 --- a/benchmarks/cyclictest/cyclictest.c +++ /dev/null @@ -1,1115 +0,0 @@ -/**************************************************************************** - * apps/benchmarks/cyclictest/cyclictest.c - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * A NuttX port of the cyclictest rt-tests utility for Linux. - * As of writing this piece of software (Feb 2025), clock_gettime - * and clock_nanosleep are tightly tied to systemtick by default. - * Yes, the time resolution can be achieved by using TICKLESS, but for high - * resolution waiting and measurement we can use other methods. - * - * This piece of software includes configurable waiting methods: - * - clock_nanosleep - * - systemtick hook: it is assumed your BSP supports a board_timerhook - * function where a sem_t g_waitsem is posted. - * - WARNING: only one task (thread) can wait for the semaphore. - * - NuttX Timer API: waiting for the timer to expire. - * - WARNING: only one task (thread) can wait for the timer to expire. - * - * Available time measuring methods: - * - clock_gettime - * - NuttX Timer API - * - * Authors of the NuttX port: Stepan Pressl <pressl.stepan@gmail.com> - * <pressste@fel.cvut.cz> - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <sched.h> -#include <limits.h> -#include <stdint.h> -#include <stdio.h> -#include <getopt.h> -#include <stdlib.h> -#include <assert.h> -#include <stdbool.h> -#include <string.h> -#include <sys/types.h> -#include <sys/ioctl.h> -#include <time.h> -#include <unistd.h> -#include <pthread.h> -#include <poll.h> -#include <fcntl.h> - -#include <nuttx/timers/timer.h> - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -enum meas_method_e -{ - M_GETTIME = 0, - M_TIMER_API, - M_COUNT -}; - -enum wait_method_e -{ - W_NANOSLEEP = 0, - W_DEVTIMER, - W_COUNT -}; - -struct cyclictest_config_s -{ - int clock; - int distance; - int duration; - int histogram; - int histofall; - unsigned long interval; - unsigned long loops; - int threads; - int policy; - int prio; - bool quiet; - char *timer_dev; - enum meas_method_e meas_method; - enum wait_method_e wait_method; -}; - -struct thread_param_s -{ - int prio; - int policy; - unsigned long interval; - unsigned long max_cycles; - struct thread_stats_s *stats; - int clock; -}; - -struct thread_stats_s -{ - long *hist_array; - long hist_overflow; - long min; - long max; - long act; - double avg; - unsigned long cycles; - pthread_t id; - int tid; - bool ended; -}; - -static bool running; -static struct cyclictest_config_s config; -static int timerfd; -static struct pollfd polltimer[1]; - -static const struct option optargs[] = -{ - {"clock", optional_argument, 0, 'c'}, - {"distance", optional_argument, 0, 'd'}, - {"duration", optional_argument, 0, 'D'}, - {"help", optional_argument, 0, 'e'}, - {"histogram", optional_argument, 0, 'h'}, - {"histofall", optional_argument, 0, 'H'}, - {"interval", optional_argument, 0, 'i'}, - {"loops", optional_argument, 0, 'l'}, - {"measurement", optional_argument, 0, 'm'}, - {"nanosleep", optional_argument, 0, 'n'}, - {"prio", optional_argument, 0, 'p'}, - {"quiet", optional_argument, 0, 'q'}, - {"threads", optional_argument, 0, 't'}, - {"timer-device", optional_argument, 0, 'T'}, - {"policy", optional_argument, 0, 'y'}, - {0, 0, 0, 0} -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static void print_help(void) -{ - puts( - "The Cyclictest Benchmark Utility\n" - "Usage:\n" - " -c --clock [CLOCK]: selects the clock: 0 selects CLOCK_REALTIME, " - "1 selects CLOCK_MONOTONIC (default).\n" - " -d --distance [US]: The distance of thread intervals. " - "Default is 500us.\n" - " -D --duration [TIME]: Test duration length in seconds. " - "Default is 0 (endless).\n" - " -e --help: Display this help and quit.\n" - " -h --histogram [US]: Output the histogram data to stdout. " - "US is the maximum value to be printed.\n" - " -H --histofall: Same as -h except that an additional histogram " - "column\n" - " is displayed at the right that contains summary data of all thread" - " histograms.\n" - " If cyclictest runs a single thread only, the -H option is " - "equivalent to -h.\n" - " -i --interval [US]: The thread interval. Default is 1000us.\n" - " -l --loops [N]: The number of measurement loops. Default is 0 " - "(endless).\n" - " -m --measurement [METHOD]: Set the time measurement method:\n" - " 0 selects clock_gettime, 1 uses the NuttX timer API.\n" - " WARNING:\n" - " If METHOD 1 is selected, you need to specify a timer device " - "(e.g. /dev/timer0) in -T.\n" - " -n --nanosleep [METHOD]: Set the waiting method: 0 selects " - "clock_nanosleep,\n" - " 1 waits for the POLLIN flag on a timer device. Default is 0.\n" - " WARNING:\n" - " Choosing 1 works only with one thread, " - "the -t value is therefore set to 1.\n" - " If METHOD 1 is selected, you need to specify a timer device " - "(e.g. /dev/timer0) in -T.\n" - " -p --prio: Set the priority of the first thread.\n" - " -q --quiet: Print a summary only on exit.\n" - " -t --threads [N]: The number of test threads to be created. " - "Default is 1.\n" - " -T --timer-device [DEV]: The measuring timer device.\n" - " Must be specified when -m=1 or -n=1.\n" - " -y --policy [NAME]: Set the scheduler policy, where NAME is \n" - " fifo, rr, batch, idle, normal, other.\n" - ); -} - -static long arg_decimal(char *arg) -{ - long ret; - char *endptr; - ret = strtol(arg, &endptr, 10); - if (endptr == arg) - { - return -1; - } - - return ret; -} - -static bool parse_args(int argc, char * const argv[]) -{ - int longindex; - int opt; - long decimal; - while ((opt = getopt_long(argc, argv, "c:d:D:h:Hi:l:m:n:p:qt:T:", - optargs, &longindex)) != -1) - { - switch (opt) - { - case 'c': - decimal = arg_decimal(optarg); - if (decimal < 0) - { - return false; - } - else if (decimal == CLOCK_MONOTONIC || decimal == CLOCK_REALTIME) - { - config.clock = decimal; - } - break; - case 'd': - decimal = arg_decimal(optarg); - if (decimal >= 0) - { - config.distance = decimal; - } - else - { - return false; - } - break; - case 'D': - decimal = arg_decimal(optarg); - if (decimal >= 0) - { - config.duration = decimal; - } - else - { - return false; - } - break; - case 'e': - return true; - case 'h': - decimal = arg_decimal(optarg); - if (decimal >= 0) - { - config.histogram = decimal; - } - else - { - return false; - } - break; - case 'H': - config.histofall = true; - break; - case 'i': - decimal = arg_decimal(optarg); - if (decimal >= 0) - { - config.interval = decimal; - } - else - { - return false; - } - break; - case 'l': - decimal = arg_decimal(optarg); - if (decimal >= 0) - { - config.loops = decimal; - } - else - { - return false; - } - break; - case 'm': - decimal = arg_decimal(optarg); - if (decimal >= 0) - { - config.meas_method = decimal; - } - else - { - return false; - } - break; - case 'n': - decimal = arg_decimal(optarg); - if (decimal >= 0) - { - config.wait_method = decimal; - } - else - { - return false; - } - break; - case 'p': - decimal = arg_decimal(optarg); - if (decimal >= 0 && decimal <= 255) - { - config.prio = decimal; - } - else - { - return false; - } - break; - case 'q': - config.quiet = true; - break; - case 't': - decimal = arg_decimal(optarg); - if (decimal > 0) - { - config.threads = decimal; - } - else - { - return false; - } - break; - case 'T': - config.timer_dev = optarg; - break; - case 'y': - if (strcmp(optarg, "other") == 0) - { - config.policy = SCHED_OTHER; - } - else if (strcmp(optarg, "normal") == 0) - { - config.policy = SCHED_NORMAL; - } - else if (strcmp(optarg, "batch") == 0) - { - config.policy = SCHED_BATCH; - } - else if (strcmp(optarg, "idle") == 0) - { - config.policy = SCHED_IDLE; - } - else if (strcmp(optarg, "fifo") == 0) - { - config.policy = SCHED_FIFO; - } - else if (strcmp(optarg, "rr") == 0) - { - config.policy = SCHED_RR; - } - else - { - return false; - } - break; - case '?': - return false; - default: - break; - } - } - - if (optind < argc) - { - return false; - } - - return true; -} - -static bool check_args_logic(void) -{ - /* Check if -T option was passed */ - - if (config.wait_method == W_DEVTIMER || config.meas_method == M_TIMER_API) - { - if (config.timer_dev == NULL) - { - fprintf(stderr, "Specify timer device!\n"); - return false; - } - } - - /* Works only with one thread */ - - if (config.wait_method == W_DEVTIMER) - { - config.threads = 1; - } - - /* If the priority was not loaded, default to number of threads. */ - - if (config.prio == 0) - { - config.prio = config.threads; - } - - if (config.wait_method >= W_COUNT) - { - return false; - } - - if (config.meas_method >= M_COUNT) - { - return false; - } - - return true; -} - -static inline void tsnorm(struct timespec *ts) -{ - while (ts->tv_nsec >= NSEC_PER_SEC) - { - ts->tv_nsec -= NSEC_PER_SEC; - ts->tv_sec++; - } -} - -static inline int64_t timediff_us(struct timespec t1, struct timespec t2) -{ - int64_t ret; - ret = 1000000 * (t1.tv_sec - t2.tv_sec); - ret += (t1.tv_nsec - t2.tv_nsec) / 1000; - return ret; -} - -static inline int64_t timediff_us_timer(struct timer_status_s after, - struct timer_status_s before) -{ - int64_t ret = 0; - uint32_t t1; - uint32_t t2; - t1 = before.timeleft; - t2 = after.timeleft; - if (t2 < t1) - { - ret = t1 - t2; - } - else - { - ret = after.timeout - (t2 - t1); - } - - return ret; -} - -static inline int timerdev_getstatus(struct timer_status_s *st) -{ - return ioctl(timerfd, TCIOC_GETSTATUS, (unsigned long)((uintptr_t)st)); -} - -static void *testthread(void *arg) -{ - int ret; - int32_t newint; - int64_t diff = 0; - struct timer_status_s stamp1; - struct timer_status_s stamp2; - struct timespec now; - struct timespec next; - struct timespec interval; - struct timespec endtime; - struct sched_param schedp; - struct thread_param_s *param = (struct thread_param_s *)arg; - struct thread_stats_s *stats = param->stats; - - stats->tid = gettid(); - stats->min = LONG_MAX; - interval.tv_sec = param->interval / 1000000; - interval.tv_nsec = (param->interval % 1000000) * 1000; - - /* Set priority and policy */ - - schedp.sched_priority = param->prio; - ret = pthread_setschedparam(pthread_self(), param->policy, &schedp); - if (ret < 0) - { - goto threadend; - } - - if (config.wait_method == W_DEVTIMER) - { - /* Start the timer here (we know the thread is only one) */ - - ret = ioctl(timerfd, TCIOC_START); - if (ret < 0) - { - perror("TCIOC_START"); - goto threadend; - } - } - - /* We can use clock_gettime for the endtime. */ - - if ((ret = clock_gettime(param->clock, &now)) < 0) - { - goto threadend; - } - - endtime.tv_sec = now.tv_sec + config.duration; - endtime.tv_nsec = now.tv_nsec; - - while (running) - { - /* This initializes the stamp1.timeout field */ - - if (config.meas_method == M_TIMER_API) - { - ret = timerdev_getstatus(&stamp1); - if (ret < 0) - { - perror("TCIOC_GETSTAUS"); - goto threadend; - } - } - - switch (config.wait_method) - { - case W_NANOSLEEP: - if (config.meas_method == M_TIMER_API) - { - /* If we measure using the TIMER_API, compute - * the expected timestamp when the thread should wake up. - */ - - newint = stamp1.timeleft - param->interval; - if (newint < 0) - { - stamp1.timeleft = stamp1.timeout + newint; - } - } - - next = now; - next.tv_sec += interval.tv_sec; - next.tv_nsec += interval.tv_nsec; - tsnorm(&next); - ret = clock_nanosleep(param->clock, TIMER_ABSTIME, &next, NULL); - if (ret < 0) - { - goto threadend; - } - break; - case W_DEVTIMER: - if (config.meas_method == M_TIMER_API) - { - /* We suppose the timer resets itself when it - * overflows. So the first timestamp is timeout. - */ - - stamp1.timeleft = stamp1.timeout; - } - else if (config.meas_method == M_GETTIME) - { - /* If we measure using the POSIX API, we must get the - * microseconds in which the currently running timer - * is supposed to timeout. We then convert this - * to the timespec struct, indicating the start. - */ - - ret = timerdev_getstatus(&stamp1); - if (ret < 0) - { - perror("TCIOC_GETSTATUS"); - goto threadend; - } - - ret = clock_gettime(param->clock, &next); - if (ret < 0) - { - goto threadend; - } - - next.tv_sec += (stamp1.timeleft) / 1000000; - next.tv_nsec += (stamp1.timeleft % 1000000) * 1000; - tsnorm(&next); - } - - if ((ret = poll(polltimer, 1, -1)) < 0) - { - goto threadend; - } - break; - default: - break; - } - - /* Time Stamp 2 */ - - switch (config.meas_method) - { - case M_GETTIME: - if ((ret = clock_gettime(param->clock, &now)) < 0) - { - goto threadend; - } - - diff = timediff_us(now, next); - break; - case M_TIMER_API: - ret = timerdev_getstatus(&stamp2); - if (ret < 0) - { - perror("TCIOC_GETSTAUS"); - goto threadend; - } - - diff = timediff_us_timer(stamp2, stamp1); - break; - default: - break; - } - - stats->act = diff; - if (diff < stats->min) - { - stats->min = diff; - } - - if (diff > stats->max) - { - stats->max = diff; - } - - stats->avg += (double) diff; - - if (config.histogram) - { - if (diff < config.histogram && diff >= 0) - { - stats->hist_array[diff] += 1; - } - else - { - stats->hist_overflow += 1; - } - } - - ++stats->cycles; - if (param->max_cycles != 0 && stats->cycles >= param->max_cycles) - { - stats->ended = true; - break; - } - - if (config.duration != 0) - { - if ((ret = clock_gettime(param->clock, &now)) < 0) - { - goto threadend; - } - - if (timediff_us(now, endtime) >= 0) - { - stats->ended = true; - break; - } - } - } - -threadend: - return NULL; -} - -static inline void init_thread_param(struct thread_param_s *param, - unsigned long interval, - unsigned long max_cycles, - int policy, - int prio, - struct thread_stats_s *stats, - int clock) -{ - stats->avg = 0.0; - stats->cycles = 0; - stats->max = -LONG_MAX; - stats->min = LONG_MAX; - stats->hist_overflow = 0; - stats->ended = false; - - param->interval = interval; - param->max_cycles = max_cycles; - param->policy = policy; - param->prio = prio; - param->stats = stats; - param->clock = clock; -} - -/* Copied from the original rt-tests/cyclictest. - * This way, the output is compatible with the original cyclictest. - */ - -static void print_hist(struct thread_param_s *par[], int nthreads) -{ - int i; - int j; - unsigned long long int log_entries[nthreads + 1]; - unsigned long maxmax; - unsigned long alloverflows; - - bzero(log_entries, sizeof(log_entries)); - - printf("# Histogram\n"); - for (i = 0; i < config.histogram; i++) - { - unsigned long long int allthreads = 0; - - printf("%06d ", i); - - for (j = 0; j < nthreads; j++) - { - unsigned long curr_latency = par[j]->stats->hist_array[i]; - printf("%06lu", curr_latency); - if (j < nthreads - 1) - { - printf("\t"); - } - - log_entries[j] += curr_latency; - allthreads += curr_latency; - } - - if (config.histofall && nthreads > 1) - { - printf("\t%06llu", allthreads); - log_entries[nthreads] += allthreads; - } - - printf("\n"); - } - - printf("# Total:"); - - for (j = 0; j < nthreads; j++) - { - printf(" %09llu", log_entries[j]); - } - - if (config.histofall && nthreads > 1) - { - printf(" %09llu", log_entries[nthreads]); - } - - printf("\n"); - printf("# Min Latencies:"); - - for (j = 0; j < nthreads; j++) - { - printf(" %05lu", par[j]->stats->min); - } - - printf("\n"); - printf("# Avg Latencies:"); - - for (j = 0; j < nthreads; j++) - { - printf(" %05lu", par[j]->stats->cycles ? - (long)(par[j]->stats->avg / par[j]->stats->cycles) : 0); - } - - printf("\n"); - printf("# Max Latencies:"); - - maxmax = 0; - for (j = 0; j < nthreads; j++) - { - printf(" %05lu", par[j]->stats->max); - if (par[j]->stats->max > maxmax) - { - maxmax = par[j]->stats->max; - } - } - - if (config.histofall && nthreads > 1) - { - printf(" %05lu", maxmax); - } - - printf("\n"); - printf("# Histogram Overflows:"); - - alloverflows = 0; - for (j = 0; j < nthreads; j++) - { - printf(" %05lu", par[j]->stats->hist_overflow); - alloverflows += par[j]->stats->hist_overflow; - } - - if (config.histofall && nthreads > 1) - { - printf(" %05lu", alloverflows); - } - - printf("\n"); -} - -/* Copied from the original rt-tests/cyclictest. - * This way, the output is compatible with the original cyclictest. - */ - -static void print_stat(struct thread_param_s *par, int index) -{ - struct thread_stats_s *stat = par->stats; - char *fmt; - fmt = "T:%2d (%5d) P:%2d I:%ld C:%7lu " - "Min:%7ld Act:%5ld Avg:%5ld Max:%8ld\n"; - printf(fmt, index, stat->tid, par->prio, par->interval, stat->cycles, - stat->min, stat->act, - stat->cycles ? (long)(stat->avg / stat->cycles) : 0, stat->max); -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -int main(int argc, char *argv[]) -{ - int i; - int ret; - struct thread_param_s **params = NULL; - struct thread_stats_s **stats = NULL; - struct sigevent event; - struct timer_notify_s tnotify; - uint32_t maxtimeout_timer; - uint32_t reqtimeout_timer; - - running = true; - config.clock = CLOCK_MONOTONIC; - config.distance = 500; - config.duration = 0; - config.histogram = 0; - config.histofall = 0; - config.interval = 1000; - config.loops = 0; - config.threads = 1; - config.prio = 0; - config.policy = SCHED_FIFO; - config.meas_method = M_GETTIME; - config.wait_method = W_NANOSLEEP; - config.timer_dev = NULL; - config.quiet = false; - - if (!parse_args(argc, argv)) - { - print_help(); - return ERROR; - } - - if (!check_args_logic()) - { - print_help(); - return ERROR; - } - - /* Timer must be configured */ - - if (config.wait_method == W_DEVTIMER || config.meas_method == M_TIMER_API) - { - timerfd = open(config.timer_dev, O_RDWR); - if (timerfd < 0) - { - perror("Failed to open the device timer"); - return ERROR; - } - - /* Configure the timer notification */ - - polltimer[0].fd = timerfd; - polltimer[0].events = POLLIN; - - /* Fill in the notify struct - * We do not want any signalling. But we must configure it, - * because without it the timer will not start. - */ - - memset(&event, 0, sizeof(event)); - event.sigev_notify = SIGEV_NONE; - - tnotify.periodic = true; - tnotify.pid = getpid(); - tnotify.event = event; - - /* Now set timeout of the timer. - * This depends on several factors. - * - * If wait_method == W_DEVTIMER, the timeout is set to config.interval - * (to achieve periodic operation). The extra time is measured by - * NANOSLEEP or the timer itself. If the timer is used, the timer - * zeroes itself when the timeout is reached, so we just get - * the timer value after poll has stopped blocking. - * - * If wait_method != W_DEVTIMER, we must set the timeout to at least - * the double of the maximum of all thread intervals - * (if you're not sure, please consult Claude Shannon). - * - * This raises the question: what if wait_method == W_DEVTIMER - * and meas_method == W_TIMER_API and the thread wakes up later - * then the timer's timeout? The solution is to have a different - * timer which runs slower and can measure overruns. - * But this would overcomplicate things. - */ - - if (config.wait_method == W_DEVTIMER) - { - reqtimeout_timer = config.interval; - } - else - { - /* Multiply by 3 instead of 2, just to be sure */ - - reqtimeout_timer = 3 * (config.interval + - (config.threads - 1) * config.distance); - } - - ret = ioctl(timerfd, TCIOC_MAXTIMEOUT, - (unsigned long)((uintptr_t)&maxtimeout_timer)); - if (ret < 0) - { - perror("TCIOC_MAXTIMEOUT"); - goto errtimer; - } - - if (reqtimeout_timer > maxtimeout_timer) - { - fprintf(stderr, "The timer cannot measure such periods!\n"); - goto errtimer; - } - - ret = ioctl(timerfd, TCIOC_SETTIMEOUT, - (unsigned long)reqtimeout_timer); - if (ret < 0) - { - perror("TCIOC_SETTIMEOUT"); - goto errtimer; - } - - ret = ioctl(timerfd, TCIOC_NOTIFICATION, - (unsigned long)((uintptr_t)&tnotify)); - if (ret < 0) - { - perror("TCIOC_NOTIFICATION"); - goto errtimer; - } - - /* If the timer is used only for measurement, start it here, otherwise - * start it only in one thread. - */ - - if (config.wait_method != W_DEVTIMER) - { - ret = ioctl(timerfd, TCIOC_START); - if (ret < 0) - { - perror("TCIOC_START"); - goto errtimer; - } - } - } - - params = calloc(config.threads, sizeof(struct thread_param_s *)); - if (params == NULL) - { - perror("params"); - ret = ERROR; - goto main_error; - } - - stats = calloc(config.threads, sizeof(struct thread_stats_s *)); - if (stats == NULL) - { - perror("stats"); - ret = ERROR; - goto main_error; - } - - for (i = 0; i < config.threads; ++i) - { - params[i] = malloc(sizeof(struct thread_param_s)); - if (params == NULL) - { - perror("params[i]"); - ret = ERROR; - goto main_error; - } - - stats[i] = malloc(sizeof(struct thread_stats_s)); - if (params == NULL) - { - perror("stats[i]"); - ret = ERROR; - goto main_error; - } - - stats[i]->hist_array = calloc(config.histogram, sizeof(long)); - if (stats[i]->hist_array == NULL) - { - perror("hist_array"); - ret = ERROR; - goto main_error; - } - - init_thread_param(params[i], config.interval, config.loops, - config.policy, config.prio, stats[i], config.clock); - - pthread_create(&stats[i]->id, NULL, testthread, params[i]); - config.interval += config.distance; - if (config.prio > 1) - { - config.prio--; - } - } - - while (running) - { - /* Periodically update the output */ - - usleep(100 * 1000); - int ended = 0; - for (i = 0; i < config.threads; ++i) - { - if (!config.quiet) - { - print_stat(params[i], i); - } - - if (stats[i]->ended) - { - ended += 1; - } - } - - if (ended == config.threads) - { - running = false; - } - else if (!config.quiet) - { - printf("\x1B[%dA", config.threads); - } - } - - for (i = 0; i < config.threads; ++i) - { - pthread_join(stats[i]->id, NULL); - } - - if (config.histogram) - { - print_hist(params, config.threads); - } - - ret = OK; - if (config.wait_method == W_DEVTIMER || config.meas_method == M_TIMER_API) - { - ret = ioctl(timerfd, TCIOC_STOP); - if (ret < 0) - { - perror("TCIOC_STOP"); - ret = ERROR; - } - - close(timerfd); - } - -main_error: - if (stats != NULL) - { - for (i = 0; i < config.threads; ++i) - { - if (params[i] != NULL) - { - free(params[i]); - } - - if (stats[i] != NULL) - { - if (stats[i]->hist_array != NULL) - { - free(stats[i]->hist_array); - } - - free(stats[i]); - } - } - } - - free(stats); - return ret; - -errtimer: - close(timerfd); - return ERROR; -} diff --git a/benchmarks/dhrystone/.gitignore b/benchmarks/dhrystone/.gitignore deleted file mode 100644 index 33030069c..000000000 --- a/benchmarks/dhrystone/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/dhrystone -/dhrystone.zip diff --git a/benchmarks/dhrystone/0001-dry2.2-Fix-malloc-type-mismatch.patch b/benchmarks/dhrystone/0001-dry2.2-Fix-malloc-type-mismatch.patch deleted file mode 100644 index 7007764b2..000000000 --- a/benchmarks/dhrystone/0001-dry2.2-Fix-malloc-type-mismatch.patch +++ /dev/null @@ -1,28 +0,0 @@ -From b5376f06c41e9460044500b24137928c83e06244 Mon Sep 17 00:00:00 2001 -From: chenrun1 <chenrun1@xiaomi.com> -Date: Mon, 12 Jun 2023 23:07:37 +0800 -Subject: [PATCH 1/2] dry2.2:Fix 'malloc' type mismatch - -'extern char *malloc' is a form from the early days of c that is no longer recommended in modern C implementations. This type of declaration can lead to type mismatch problems - -Signed-off-by: chenrun1 <chenrun1@xiaomi.com> ---- - v2.2/dry.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/v2.2/dry.c b/v2.2/dry.c -index 602572a..e0fa391 100644 ---- dhrystone/v2.2/dry.c -+++ dhrystone/v2.2/dry.c -@@ -500,7 +500,7 @@ char Ch_1_Glob, - int Arr_1_Glob [50]; - int Arr_2_Glob [50] [50]; - --extern char *malloc (); -+extern void *malloc (); - Enumeration Func_1 (); - /* forward declaration necessary since Enumeration may not simply be int */ - --- -2.34.1 - diff --git a/benchmarks/dhrystone/0002-dhrystone-fix-redefine-warning.patch b/benchmarks/dhrystone/0002-dhrystone-fix-redefine-warning.patch deleted file mode 100644 index 1616abee1..000000000 --- a/benchmarks/dhrystone/0002-dhrystone-fix-redefine-warning.patch +++ /dev/null @@ -1,67 +0,0 @@ -From ed7f8720aed17febe5d802cda53b38b80d0d5164 Mon Sep 17 00:00:00 2001 -From: chenrun1 <chenrun1@xiaomi.com> -Date: Fri, 29 Mar 2024 10:48:37 +0800 -Subject: [PATCH 2/2] dhrystone:fix redefine warning - -redefine: -dhrystone/v2.2/dry.c:458: warning: "true" redefined - 458 | #define true 1 - | -In file included from /home/crafcat7/ext2/vela/vela-dev/nuttx/include/nuttx/fs/fs.h:34, - from /home/crafcat7/ext2/vela/vela-dev/nuttx/include/stdio.h:34, - from dhrystone/v2.2/dry.c:453: -/home/crafcat7/ext2/vela/vela-dev/nuttx/include/stdbool.h:77: note: this is the location of the previous definition - 77 | # define true (bool)1 - | -dhrystone/v2.2/dry.c:459: warning: "false" redefined - -Signed-off-by: chenrun1 <chenrun1@xiaomi.com> ---- - v2.1/dhry.h | 8 ++++++++ - v2.2/dry.c | 7 +++++++ - 2 files changed, 15 insertions(+) - -diff --git a/v2.1/dhry.h b/v2.1/dhry.h -index 404adb4..ee848d8 100644 ---- dhrystone/v2.1/dhry.h -+++ dhrystone/v2.1/dhry.h -@@ -396,8 +396,16 @@ - - #define Null 0 - /* Value of a Null pointer */ -+ -+#ifdef true -+#undef true - #define true 1 -+#endif -+ -+#ifdef false -+#undef false - #define false 0 -+#endif - - typedef int One_Thirty; - typedef int One_Fifty; -diff --git a/v2.2/dry.c b/v2.2/dry.c -index e0fa391..2994c13 100644 ---- dhrystone/v2.2/dry.c -+++ dhrystone/v2.2/dry.c -@@ -455,8 +455,15 @@ struct tms time_info; - - #define Null 0 - /* Value of a Null pointer */ -+#ifdef true -+#undef true - #define true 1 -+#endif -+ -+#ifdef false -+#undef false - #define false 0 -+#endif - - typedef int One_Thirty; - typedef int One_Fifty; --- -2.34.1 - diff --git a/benchmarks/dhrystone/CMakeLists.txt b/benchmarks/dhrystone/CMakeLists.txt deleted file mode 100644 index 166692d36..000000000 --- a/benchmarks/dhrystone/CMakeLists.txt +++ /dev/null @@ -1,68 +0,0 @@ -# ############################################################################## -# apps/benchmarks/dhrystone/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_BENCHMARK_DHRYSTONE) - - set(DHRYSTONE_DIR ${CMAKE_CURRENT_LIST_DIR}/dhrystone) - - if(NOT EXISTS ${DHRYSTONE_DIR}) - FetchContent_Declare( - dhrystone_fetch - URL https://github.com/Keith-S-Thompson/dhrystone/archive/refs/heads/master.zip - SOURCE_DIR - ${CMAKE_CURRENT_LIST_DIR}/dhrystone - BINARY_DIR - ${CMAKE_BINARY_DIR}/apps/benchmarks/coremark/dhrystone - PATCH_COMMAND - patch -p0 -d ${CMAKE_CURRENT_LIST_DIR} < - ${CMAKE_CURRENT_LIST_DIR}/0001-dry2.2-Fix-malloc-type-mismatch.patch && - patch -p0 -d ${CMAKE_CURRENT_LIST_DIR} < - ${CMAKE_CURRENT_LIST_DIR}/0002-dhrystone-fix-redefine-warning.patch - DOWNLOAD_NO_PROGRESS true - TIMEOUT 30) - - FetchContent_GetProperties(dhrystone_fetch) - if(NOT dhrystone_fetch_POPULATED) - FetchContent_Populate(dhrystone_fetch) - endif() - endif() - - set(CFLAGS - -DMSC_CLOCK -Wno-maybe-uninitialized -Wno-implicit-int - -Wno-strict-prototypes -Wno-implicit-function-declaration - -Wno-return-type) - set(SRCS dhrystone/v2.2/dry.c dhrystone/v2.1/dhry_2.c) - - nuttx_add_application( - NAME - ${CONFIG_BENCHMARK_DHRYSTONE_PROGNAME} - PRIORITY - ${CONFIG_BENCHMARK_DHRYSTONE_PRIORITY} - STACKSIZE - ${CONFIG_BENCHMARK_DHRYSTONE_STACKSIZE} - MODULE - ${CONFIG_BENCHMARK_DHRYSTONE} - COMPILE_FLAGS - ${CFLAGS} - SRCS - ${SRCS}) -endif() diff --git a/benchmarks/dhrystone/Kconfig b/benchmarks/dhrystone/Kconfig deleted file mode 100644 index 92965c3b5..000000000 --- a/benchmarks/dhrystone/Kconfig +++ /dev/null @@ -1,28 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config BENCHMARK_DHRYSTONE - tristate "dhrystone benchmark" - default n - ---help--- - Dhrystone is one of the most common benchmark programs - for measuring the computing power of processors and is commonly - used to measure the performance of integer computing on processors. - -if BENCHMARK_DHRYSTONE - -config BENCHMARK_DHRYSTONE_PROGNAME - string "Program Name" - default "dhrystone" - -config BENCHMARK_DHRYSTONE_STACKSIZE - int "utils dhrystone stack size" - default DEFAULT_TASK_STACKSIZE - -config BENCHMARK_DHRYSTONE_PRIORITY - int "Task PRIORITY" - default 100 - -endif diff --git a/benchmarks/dhrystone/Make.defs b/benchmarks/dhrystone/Make.defs deleted file mode 100644 index 2662abde0..000000000 --- a/benchmarks/dhrystone/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/benchmarks/dhrystone/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_BENCHMARK_DHRYSTONE),) -CONFIGURED_APPS += $(APPDIR)/benchmarks/dhrystone -endif diff --git a/benchmarks/dhrystone/Makefile b/benchmarks/dhrystone/Makefile deleted file mode 100644 index 6e175ac15..000000000 --- a/benchmarks/dhrystone/Makefile +++ /dev/null @@ -1,55 +0,0 @@ -############################################################################ -# apps/benchmarks/dhrystone/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -#dhrystone - -PROGNAME = $(CONFIG_BENCHMARK_DHRYSTONE_PROGNAME) -PRIORITY = $(CONFIG_BENCHMARK_DHRYSTONE_PRIORITY) -STACKSIZE = $(CONFIG_BENCHMARK_DHRYSTONE_STACKSIZE) -MODULE = $(CONFIG_BENCHMARK_DHRYSTONE) - -CFLAGS += -DMSC_CLOCK -Wno-implicit-int -Wno-strict-prototypes -CFLAGS += -Wno-implicit-function-declaration -Wno-return-type -CFLAGS += -Wno-maybe-uninitialized - -CSRCS += dhrystone/v2.1/dhry_2.c -MAINSRC = dhrystone/v2.2/dry.c - -ifeq ($(wildcard dhrystone/.git),) -VERSION ?= master -dhrystone.zip: - $(Q) curl -L https://github.com/Keith-S-Thompson/dhrystone/archive/refs/heads/master.zip -o dhrystone.zip - $(Q) unzip -o dhrystone.zip - $(Q) mv dhrystone-$(VERSION) dhrystone - $(Q) patch -p0 < 0001-dry2.2-Fix-malloc-type-mismatch.patch - $(Q) patch -p0 < 0002-dhrystone-fix-redefine-warning.patch - -context:: dhrystone.zip - -distclean:: - $(call DELDIR, dhrystone) - $(call DELFILE, dhrystone.zip) -endif - -include $(APPDIR)/Application.mk diff --git a/benchmarks/fio/.gitignore b/benchmarks/fio/.gitignore deleted file mode 100644 index 97c3b30d0..000000000 --- a/benchmarks/fio/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/fio diff --git a/benchmarks/fio/0001-external-fio-fix-compile-warning.patch b/benchmarks/fio/0001-external-fio-fix-compile-warning.patch deleted file mode 100644 index 3161db25d..000000000 --- a/benchmarks/fio/0001-external-fio-fix-compile-warning.patch +++ /dev/null @@ -1,193 +0,0 @@ -From b51436a258fc010a0ac15b551a9b010e54fccb11 Mon Sep 17 00:00:00 2001 -From: dongjiuzhu1 <dongjiuzhu1@xiaomi.com> -Date: Tue, 30 May 2023 22:01:51 +0800 -Subject: [PATCH 01/10] external/fio: fix compile warning - -Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com> ---- - backend.c | 2 +- - init.c | 4 ++-- - server.c | 2 +- - stat.c | 28 +++++++++++++++------------- - zbd.c | 2 +- - 5 files changed, 20 insertions(+), 18 deletions(-) - -diff --git fio/backend.c fio/backend.c -index fe614f6e..0fa10657 100644 ---- fio/backend.c -+++ fio/backend.c -@@ -1950,7 +1950,7 @@ static void *thread_main(void *data) - * another thread is checking its io_u's for overlap - */ - if (td_offload_overlap(td)) { -- int res = pthread_mutex_lock(&overlap_check); -+ res = pthread_mutex_lock(&overlap_check); - assert(res == 0); - } - td_set_runstate(td, TD_FINISHING); -diff --git fio/init.c fio/init.c -index f6a8056a..de9d9d27 100644 ---- fio/init.c -+++ fio/init.c -@@ -2524,12 +2524,12 @@ static void show_closest_option(const char *name) - log_err("Did you mean %s?\n", l_opts[best_option].name); - } - --static int parse_output_format(const char *optarg) -+static int parse_output_format(const char *arg) - { - char *p, *orig, *opt; - int ret = 0; - -- p = orig = strdup(optarg); -+ p = orig = strdup(arg); - - output_format = 0; - -diff --git fio/server.c fio/server.c -index b453be5f..23da2ecf 100644 ---- fio/server.c -+++ fio/server.c -@@ -356,7 +356,7 @@ static int verify_convert_cmd(struct fio_net_cmd *cmd) - } - - if (cmd->pdu_len > FIO_SERVER_MAX_FRAGMENT_PDU) { -- log_err("fio: command payload too large: %u\n", cmd->pdu_len); -+ log_err("fio: command payload too large: %"PRIu32"\n", cmd->pdu_len); - return 1; - } - -diff --git fio/stat.c fio/stat.c -index 949af5ed..6a39ae6e 100644 ---- fio/stat.c -+++ fio/stat.c -@@ -45,10 +45,12 @@ void update_rusage_stat(struct thread_data *td) - &td->ru_end.ru_utime); - ts->sys_time += mtime_since_tv(&td->ru_start.ru_stime, - &td->ru_end.ru_stime); -+#ifndef __NuttX__ - ts->ctx += td->ru_end.ru_nvcsw + td->ru_end.ru_nivcsw - - (td->ru_start.ru_nvcsw + td->ru_start.ru_nivcsw); - ts->minf += td->ru_end.ru_minflt - td->ru_start.ru_minflt; - ts->majf += td->ru_end.ru_majflt - td->ru_start.ru_majflt; -+#endif - - memcpy(&td->ru_start, &td->ru_end, sizeof(td->ru_end)); - } -@@ -346,7 +348,7 @@ void show_group_stats(struct group_run_stats *rs, struct buf_output *out) - const char *str[] = { " READ", " WRITE" , " TRIM"}; - int i; - -- log_buf(out, "\nRun status group %d (all jobs):\n", rs->groupid); -+ log_buf(out, "\nRun status group %"PRIu32" (all jobs):\n", rs->groupid); - - for (i = 0; i < DDIR_RWDIR_CNT; i++) { - const int i2p = is_power_of_2(rs->kb_base); -@@ -595,7 +597,7 @@ static void show_ddir_status(struct group_run_stats *rs, struct thread_stat *ts, - char buf[64]; - - snprintf(buf, sizeof(buf), -- "%s prio %u/%u", -+ "%s prio %"PRIu32"/%"PRIu32"", - clat_type, - ts->clat_prio[ddir][i].ioprio >> 13, - ts->clat_prio[ddir][i].ioprio & 7); -@@ -636,7 +638,7 @@ static void show_ddir_status(struct group_run_stats *rs, struct thread_stat *ts, - - if (prio_samples > 0) { - snprintf(prio_name, sizeof(prio_name), -- "%s prio %u/%u (%.2f%% of IOs)", -+ "%s prio %"PRIu32"/%"PRIu32" (%.2f%% of IOs)", - clat_type, - ts->clat_prio[ddir][i].ioprio >> 13, - ts->clat_prio[ddir][i].ioprio & 7, -@@ -896,7 +898,7 @@ static void show_block_infos(int nr_block_infos, uint32_t *block_infos, - uint32_t block_info = percentiles[i]; - #define LINE_LENGTH 75 - char str[LINE_LENGTH]; -- int strln = snprintf(str, LINE_LENGTH, " %3.2fth=%u%c", -+ int strln = snprintf(str, LINE_LENGTH, " %3.2fth=%"PRIu32"%c", - plist[i].u.f, block_info, - i == len - 1 ? '\n' : ','); - assert(strln < LINE_LENGTH); -@@ -1177,11 +1179,11 @@ static void show_thread_status_normal(struct thread_stat *ts, - os_ctime_r((const time_t *) &time_p, time_buf, sizeof(time_buf)); - - if (!ts->error) { -- log_buf(out, "%s: (groupid=%d, jobs=%d): err=%2d: pid=%d: %s", -+ log_buf(out, "%s: (groupid=%"PRIu32", jobs=%"PRIu32"): err=%2"PRIu32": pid=%d: %s", - ts->name, ts->groupid, ts->members, - ts->error, (int) ts->pid, time_buf); - } else { -- log_buf(out, "%s: (groupid=%d, jobs=%d): err=%2d (%s): pid=%d: %s", -+ log_buf(out, "%s: (groupid=%"PRIu32", jobs=%"PRIu32"): err=%2"PRIu32" (%s): pid=%d: %s", - ts->name, ts->groupid, ts->members, - ts->error, ts->verror, (int) ts->pid, - time_buf); -@@ -1253,13 +1255,13 @@ static void show_thread_status_normal(struct thread_stat *ts, - (unsigned long long) ts->drop_io_u[1], - (unsigned long long) ts->drop_io_u[2]); - if (ts->continue_on_error) { -- log_buf(out, " errors : total=%llu, first_error=%d/<%s>\n", -+ log_buf(out, " errors : total=%llu, first_error=%"PRIu32"/<%s>\n", - (unsigned long long)ts->total_err_count, - ts->first_error, - strerror(ts->first_error)); - } - if (ts->latency_depth) { -- log_buf(out, " latency : target=%llu, window=%llu, percentile=%.2f%%, depth=%u\n", -+ log_buf(out, " latency : target=%llu, window=%llu, percentile=%.2f%%, depth=%"PRIu32"\n", - (unsigned long long)ts->latency_target, - (unsigned long long)ts->latency_window, - ts->latency_percentile.u.f, -@@ -1589,9 +1591,9 @@ static void show_thread_status_terse_all(struct thread_stat *ts, - - /* General Info */ - if (ver == 2) -- log_buf(out, "2;%s;%d;%d", ts->name, ts->groupid, ts->error); -+ log_buf(out, "2;%s;%"PRIu32";%"PRIu32"", ts->name, ts->groupid, ts->error); - else -- log_buf(out, "%d;%s;%s;%d;%d", ver, fio_version_string, -+ log_buf(out, "%d;%s;%s;%"PRIu32";%"PRIu32"", ver, fio_version_string, - ts->name, ts->groupid, ts->error); - - /* Log Read Status, or mixed if unified_rw_rep = 1 */ -@@ -1644,7 +1646,7 @@ static void show_thread_status_terse_all(struct thread_stat *ts, - - /* Additional output if continue_on_error set - default off*/ - if (ts->continue_on_error) -- log_buf(out, ";%llu;%d", (unsigned long long) ts->total_err_count, ts->first_error); -+ log_buf(out, ";%llu;%"PRIu32"", (unsigned long long) ts->total_err_count, ts->first_error); - - /* Additional output if description is set */ - if (strlen(ts->description)) { -@@ -2519,11 +2521,11 @@ void __show_run_stats(void) - ts->unified_rw_rep = td->o.unified_rw_rep; - } else if (ts->kb_base != td->o.kb_base && !kb_base_warned) { - log_info("fio: kb_base differs for jobs in group, using" -- " %u as the base\n", ts->kb_base); -+ " %"PRIu32" as the base\n", ts->kb_base); - kb_base_warned = true; - } else if (ts->unit_base != td->o.unit_base && !unit_base_warned) { - log_info("fio: unit_base differs for jobs in group, using" -- " %u as the base\n", ts->unit_base); -+ " %"PRIu32" as the base\n", ts->unit_base); - unit_base_warned = true; - } - -diff --git fio/zbd.c fio/zbd.c -index 627fb968..114fb665 100644 ---- fio/zbd.c -+++ fio/zbd.c -@@ -1491,7 +1491,7 @@ static struct fio_zone_info *zbd_replay_write_order(struct thread_data *td, - } - - if (z->verify_block * min_bs >= z->capacity) { -- log_err("%s: %d * %"PRIu64" >= %"PRIu64"\n", -+ log_err("%s: %"PRIu32" * %"PRIu64" >= %"PRIu64"\n", - f->file_name, z->verify_block, min_bs, z->capacity); - /* - * If the assertion below fails during a test run, adding --- -2.34.1 - diff --git a/benchmarks/fio/0002-external-fio-add-os-nuttx-support.patch b/benchmarks/fio/0002-external-fio-add-os-nuttx-support.patch deleted file mode 100644 index d103fb719..000000000 --- a/benchmarks/fio/0002-external-fio-add-os-nuttx-support.patch +++ /dev/null @@ -1,81 +0,0 @@ -From 8f78b1199f814ad18e1902edf8d9fbf23b05b4d3 Mon Sep 17 00:00:00 2001 -From: dongjiuzhu1 <dongjiuzhu1@xiaomi.com> -Date: Mon, 5 Jun 2023 16:00:49 +0800 -Subject: [PATCH 02/10] external/fio: add os-nuttx support - -Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com> ---- - os/os-nuttx.h | 39 +++++++++++++++++++++++++++++++++++++++ - os/os.h | 3 +++ - 2 files changed, 42 insertions(+) - create mode 100644 os/os-nuttx.h - -diff --git fio/os/os-nuttx.h fio/os/os-nuttx.h -new file mode 100644 -index 00000000..c81ea32c ---- /dev/null -+++ fio/os/os-nuttx.h -@@ -0,0 +1,39 @@ -+#ifndef FIO_OS_NUTTX_H -+#define FIO_OS_NUTTX_H -+ -+#include <errno.h> -+#include <malloc.h> -+#include <sys/mman.h> -+#include <sys/ioctl.h> -+ -+#include <nuttx/fs/ioctl.h> -+ -+#include "../file.h" -+ -+#define FIO_OS os_nuttx -+#define OS_MAP_ANON MAP_ANON -+ -+#define fio_swap16(x) bswap16(x) -+#define fio_swap32(x) bswap32(x) -+#define fio_swap64(x) bswap64(x) -+ -+static inline unsigned long long os_phys_mem(void) -+{ -+ struct mallinfo info; -+ -+ info = mallinfo(); -+ return (unsigned long long)info.arena; -+} -+ -+static inline int blockdev_invalidate_cache(struct fio_file *f) -+{ -+ return ioctl(f->fd, BIOC_FLUSH, 0); -+} -+ -+static inline pid_t setsid(void) -+{ -+ errno = ENOSYS; -+ return -1; -+} -+ -+#endif -diff --git fio/os/os.h fio/os/os.h -index aba6813f..dddff7c1 100644 ---- fio/os/os.h -+++ fio/os/os.h -@@ -24,6 +24,7 @@ enum { - os_windows, - os_android, - os_dragonfly, -+ os_nuttx, - - os_nr, - }; -@@ -53,6 +54,8 @@ typedef enum { - #include "os-windows.h" - #elif defined (__DragonFly__) - #include "os-dragonfly.h" -+#elif defined (__NuttX__) -+#include "os-nuttx.h" - #else - #error "unsupported os" - #endif --- -2.34.1 - diff --git a/benchmarks/fio/0003-external-fio-modify-smaller-size-for-nuttx.patch b/benchmarks/fio/0003-external-fio-modify-smaller-size-for-nuttx.patch deleted file mode 100644 index c869ffd81..000000000 --- a/benchmarks/fio/0003-external-fio-modify-smaller-size-for-nuttx.patch +++ /dev/null @@ -1,65 +0,0 @@ -From c39410be0f4516cd06f6d3597daf025db2efcba1 Mon Sep 17 00:00:00 2001 -From: dongjiuzhu1 <dongjiuzhu1@xiaomi.com> -Date: Mon, 5 Jun 2023 16:02:10 +0800 -Subject: [PATCH 03/10] external/fio: modify smaller size for nuttx - -Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com> ---- - filehash.c | 2 ++ - lib/memcpy.c | 2 ++ - smalloc.c | 7 +++++++ - 3 files changed, 11 insertions(+) - -diff --git fio/filehash.c fio/filehash.c -index 71ec7b18..f13740d2 100644 ---- fio/filehash.c -+++ fio/filehash.c -@@ -11,7 +11,9 @@ - #define HASH_BUCKETS 512 - #define HASH_MASK (HASH_BUCKETS - 1) - -+#ifndef BLOOM_SIZE - #define BLOOM_SIZE 16*1024*1024 -+#endif - - static unsigned int file_hash_size = HASH_BUCKETS * sizeof(struct flist_head); - -diff --git fio/lib/memcpy.c fio/lib/memcpy.c -index a5521343..1b3466c1 100644 ---- fio/lib/memcpy.c -+++ fio/lib/memcpy.c -@@ -9,7 +9,9 @@ - #include "../gettime.h" - #include "../os/os.h" - -+#ifndef BUF_SIZE - #define BUF_SIZE 32 * 1024 * 1024ULL -+#endif - - #define NR_ITERS 64 - -diff --git fio/smalloc.c fio/smalloc.c -index 23243054..142e03d2 100644 ---- fio/smalloc.c -+++ fio/smalloc.c -@@ -18,10 +18,17 @@ - #define SMALLOC_BPI (sizeof(unsigned int) * 8) - #define SMALLOC_BPL (SMALLOC_BPB * SMALLOC_BPI) - -+#ifndef INITIAL_SIZE - #define INITIAL_SIZE 16*1024*1024 /* new pool size */ -+#endif -+ -+#ifndef INITIAL_POOLS - #define INITIAL_POOLS 8 /* maximum number of pools to setup */ -+#endif - -+#ifndef MAX_POOLS - #define MAX_POOLS 16 -+#endif - - #define SMALLOC_PRE_RED 0xdeadbeefU - #define SMALLOC_POST_RED 0x5aa55aa5U --- -2.34.1 - diff --git a/benchmarks/fio/0004-external-fio-fix-runtime-error-by-asan.patch b/benchmarks/fio/0004-external-fio-fix-runtime-error-by-asan.patch deleted file mode 100644 index 49750cdaa..000000000 --- a/benchmarks/fio/0004-external-fio-fix-runtime-error-by-asan.patch +++ /dev/null @@ -1,32 +0,0 @@ -From 02df0c8355b0adf01696e831f319c60f9ae6efb7 Mon Sep 17 00:00:00 2001 -From: dongjiuzhu1 <dongjiuzhu1@xiaomi.com> -Date: Fri, 9 Jun 2023 14:39:49 +0800 -Subject: [PATCH 04/10] external/fio: fix runtime error by asan - -/home/djz/workspace/test/vela_new/external/fio/fio/arch/arch-x86-common.h:11:7: runtime error: store to -misaligned address 0xf41f0d47 for type 'unsigned int', which requires 4 byte alignment -0xf41f0d47: note: pointer points here - 16 00 00 00 00 bc 0d 1f f4 00 d4 bd 1a 00 00 00 00 5c 2e 44 57 98 0d 1f f4 26 ab b8 56 18 0e 1f - ^ - -Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com> ---- - arch/arch-x86-common.h | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git fio/arch/arch-x86-common.h fio/arch/arch-x86-common.h -index f32835cc..fe97cf64 100644 ---- fio/arch/arch-x86-common.h -+++ fio/arch/arch-x86-common.h -@@ -59,7 +59,7 @@ static inline void arch_init_amd(void) - static inline void arch_init(char *envp[]) - { - unsigned int level; -- char str[13]; -+ char str[13] __attribute__((aligned(0x8))); - - arch_random = tsc_reliable = 0; - --- -2.34.1 - diff --git a/benchmarks/fio/0005-external-fio-fix-compile-warning.patch b/benchmarks/fio/0005-external-fio-fix-compile-warning.patch deleted file mode 100644 index 827d3f397..000000000 --- a/benchmarks/fio/0005-external-fio-fix-compile-warning.patch +++ /dev/null @@ -1,172 +0,0 @@ -From a69a23fb0cf6f9e0ad0cb857dda74e6e9b4bc6da Mon Sep 17 00:00:00 2001 -From: dongjiuzhu1 <dongjiuzhu1@xiaomi.com> -Date: Sat, 10 Jun 2023 18:34:17 +0800 -Subject: [PATCH 05/10] external/fio: fix compile warning - -io/compiler/compiler.h:25:25: warning: comparison of distinct pointer types lacks a cast - 25 | (void)(&__dummy == &__dummy2); \ - | ^~ -fio/os/os.h:291:9: note: in expansion of macro 'typecheck' - 291 | typecheck(uint32_t, val); \ - | ^~~~~~~~~ -fio/verify.c:1628:48: note: in expansion of macro 'cpu_to_le32' - 1628 | s->rand.state32.s[0] = cpu_to_le32(td->random_state.state32.s1); - | ^~~~~~~~~~~ - -Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com> ---- - client.c | 2 +- - engines/fileoperations.c | 4 ++-- - eta.c | 6 +++--- - iolog.c | 2 +- - os/os.h | 2 -- - verify.c | 6 +++--- - zbd.c | 2 +- - 7 files changed, 11 insertions(+), 13 deletions(-) - -diff --git fio/client.c fio/client.c -index 37da74bc..f9a3247e 100644 ---- fio/client.c -+++ fio/client.c -@@ -1406,7 +1406,7 @@ static void client_flush_hist_samples(FILE *f, int hist_coarseness, void *sample - entry = s->data.plat_entry; - io_u_plat = entry->io_u_plat; - -- fprintf(f, "%lu, %u, %llu, ", (unsigned long) s->time, -+ fprintf(f, "%lu, %"PRIu32", %llu, ", (unsigned long) s->time, - io_sample_ddir(s), (unsigned long long) s->bs); - for (j = 0; j < FIO_IO_U_PLAT_NR - stride; j += stride) { - fprintf(f, "%llu, ", (unsigned long long)hist_sum(j, stride, io_u_plat, NULL)); -diff --git fio/engines/fileoperations.c fio/engines/fileoperations.c -index 1db60da1..ed0456c0 100644 ---- fio/engines/fileoperations.c -+++ fio/engines/fileoperations.c -@@ -109,7 +109,7 @@ static int stat_file(struct thread_data *td, struct fio_file *f) - struct timespec start; - int do_lat = !td->o.disable_lat; - struct stat statbuf; --#ifndef WIN32 -+#if !defined(WIN32) && !defined(__NuttX__) - struct statx statxbuf; - char *abspath; - #endif -@@ -137,7 +137,7 @@ static int stat_file(struct thread_data *td, struct fio_file *f) - ret = lstat(f->file_name, &statbuf); - break; - case FIO_FILESTAT_STATX: --#ifndef WIN32 -+#if !defined(WIN32) && !defined(__NuttX__) - abspath = realpath(f->file_name, NULL); - if (abspath) { - ret = statx(-1, abspath, 0, STATX_ALL, &statxbuf); -diff --git fio/eta.c fio/eta.c -index 6017ca31..2df3bd5d 100644 ---- fio/eta.c -+++ fio/eta.c -@@ -344,7 +344,7 @@ static void calc_rate(int unified_rw_rep, unsigned long mtime, - - static void calc_iops(int unified_rw_rep, unsigned long mtime, - unsigned long long *io_iops, -- unsigned long long *prev_io_iops, unsigned int *iops) -+ unsigned long long *prev_io_iops, uint32_t *iops) - { - int i; - -@@ -594,7 +594,7 @@ void display_thread_status(struct jobs_eta *je) - p += sprintf(p, "\n"); - } - -- p += sprintf(p, "Jobs: %d (f=%d)", je->nr_running, je->files_open); -+ p += sprintf(p, "Jobs: %"PRIi32" (f=%"PRIi32")", je->nr_running, je->files_open); - - /* rate limits, if any */ - if (je->m_rate[0] || je->m_rate[1] || je->m_rate[2] || -@@ -611,7 +611,7 @@ void display_thread_status(struct jobs_eta *je) - free(mr); - } else if (je->m_iops[0] || je->m_iops[1] || je->m_iops[2] || - je->t_iops[0] || je->t_iops[1] || je->t_iops[2]) { -- p += sprintf(p, ", %d-%d IOPS", -+ p += sprintf(p, ", %"PRIi32"-%"PRIi32" IOPS", - je->m_iops[0] + je->m_iops[1] + je->m_iops[2], - je->t_iops[0] + je->t_iops[1] + je->t_iops[2]); - } -diff --git fio/iolog.c fio/iolog.c -index aa9c3bb1..cdb24a2b 100644 ---- fio/iolog.c -+++ fio/iolog.c -@@ -952,7 +952,7 @@ static void flush_hist_samples(FILE *f, int hist_coarseness, void *samples, - entry_before = flist_first_entry(&entry->list, struct io_u_plat_entry, list); - io_u_plat_before = entry_before->io_u_plat; - -- fprintf(f, "%lu, %u, %llu, ", (unsigned long) s->time, -+ fprintf(f, "%lu, %"PRIu32", %llu, ", (unsigned long) s->time, - io_sample_ddir(s), (unsigned long long) s->bs); - for (j = 0; j < FIO_IO_U_PLAT_NR - stride; j += stride) { - fprintf(f, "%llu, ", (unsigned long long) -diff --git fio/os/os.h fio/os/os.h -index dddff7c1..4d8c7537 100644 ---- fio/os/os.h -+++ fio/os/os.h -@@ -262,7 +262,6 @@ static inline uint64_t fio_swap64(uint64_t val) - __le16_to_cpu(val); \ - }) - #define le32_to_cpu(val) ({ \ -- typecheck(uint32_t, val); \ - __le32_to_cpu(val); \ - }) - #define le64_to_cpu(val) ({ \ -@@ -288,7 +287,6 @@ static inline uint64_t fio_swap64(uint64_t val) - __cpu_to_le16(val); \ - }) - #define cpu_to_le32(val) ({ \ -- typecheck(uint32_t, val); \ - __cpu_to_le32(val); \ - }) - #define cpu_to_le64(val) ({ \ -diff --git fio/verify.c fio/verify.c -index 0e1e4639..ea414749 100644 ---- fio/verify.c -+++ fio/verify.c -@@ -341,7 +341,7 @@ static void log_verify_failure(struct verify_header *hdr, struct vcont *vc) - - offset = vc->io_u->verify_offset; - offset += vc->hdr_num * hdr->len; -- log_err("%.8s: verify failed at file %s offset %llu, length %u" -+ log_err("%.8s: verify failed at file %s offset %llu, length %"PRIu32"" - " (requested block: offset=%llu, length=%llu, flags=%x)\n", - vc->name, vc->io_u->file->file_name, offset, hdr->len, - vc->io_u->verify_offset, vc->io_u->buflen, vc->io_u->flags); -@@ -819,7 +819,7 @@ static int verify_header(struct io_u *io_u, struct thread_data *td, - goto err; - } - if (hdr->len != hdr_len) { -- log_err("verify: bad header length %u, wanted %u", -+ log_err("verify: bad header length %"PRIu32", wanted %u", - hdr->len, hdr_len); - goto err; - } -@@ -854,7 +854,7 @@ static int verify_header(struct io_u *io_u, struct thread_data *td, - - crc = fio_crc32c(p, offsetof(struct verify_header, crc32)); - if (crc != hdr->crc32) { -- log_err("verify: bad header crc %x, calculated %x", -+ log_err("verify: bad header crc %"PRIx32", calculated %"PRIx32"", - hdr->crc32, crc); - goto err; - } -diff --git fio/zbd.c fio/zbd.c -index 114fb665..3933ab2d 100644 ---- fio/zbd.c -+++ fio/zbd.c -@@ -814,7 +814,7 @@ static int parse_zone_info(struct thread_data *td, struct fio_file *f) - break; - - nrz = zbd_report_zones(td, f, offset, zones, -- min((uint32_t)(nr_zones - j), -+ min((unsigned)(nr_zones - j), - ZBD_REPORT_MAX_ZONES)); - if (nrz < 0) { - ret = nrz; --- -2.34.1 - diff --git a/benchmarks/fio/0006-external-fio-reinit-global-var-issue-when-run-multip.patch b/benchmarks/fio/0006-external-fio-reinit-global-var-issue-when-run-multip.patch deleted file mode 100644 index 534f77724..000000000 --- a/benchmarks/fio/0006-external-fio-reinit-global-var-issue-when-run-multip.patch +++ /dev/null @@ -1,438 +0,0 @@ -From 6afb9af3dd7734d0f6bd090fba947ffaec43482b Mon Sep 17 00:00:00 2001 -From: dongjiuzhu1 <dongjiuzhu1@xiaomi.com> -Date: Mon, 5 Jun 2023 14:44:53 +0800 -Subject: [PATCH 06/10] external/fio: reinit global var issue when run multiple - times - -Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com> ---- - init.c | 386 +++++++++++++++++++++++++----------------------------- - smalloc.c | 4 + - 2 files changed, 186 insertions(+), 204 deletions(-) - -diff --git fio/init.c fio/init.c -index de9d9d27..9dcad491 100644 ---- fio/init.c -+++ fio/init.c -@@ -96,214 +96,191 @@ static bool did_arg; - * Command line options. These will contain the above, plus a few - * extra that only pertain to fio itself and not jobs. - */ --static struct option l_opts[FIO_NR_OPTIONS] = { -- { -- .name = (char *) "output", -- .has_arg = required_argument, -- .val = 'o' | FIO_CLIENT_FLAG, -- }, -- { -- .name = (char *) "latency-log", -- .has_arg = required_argument, -- .val = 'l' | FIO_CLIENT_FLAG, -- }, -- { -- .name = (char *) "bandwidth-log", -- .has_arg = no_argument, -- .val = 'b' | FIO_CLIENT_FLAG, -- }, -- { -- .name = (char *) "minimal", -- .has_arg = no_argument, -- .val = 'm' | FIO_CLIENT_FLAG, -- }, -- { -- .name = (char *) "output-format", -- .has_arg = required_argument, -- .val = 'F' | FIO_CLIENT_FLAG, -- }, -- { -- .name = (char *) "append-terse", -- .has_arg = optional_argument, -- .val = 'f', -- }, -- { -- .name = (char *) "version", -- .has_arg = no_argument, -- .val = 'v' | FIO_CLIENT_FLAG, -- }, -- { -- .name = (char *) "help", -- .has_arg = no_argument, -- .val = 'h' | FIO_CLIENT_FLAG, -- }, -- { -- .name = (char *) "cmdhelp", -- .has_arg = optional_argument, -- .val = 'c' | FIO_CLIENT_FLAG, -- }, -- { -- .name = (char *) "enghelp", -- .has_arg = optional_argument, -- .val = 'i' | FIO_CLIENT_FLAG, -- }, -- { -- .name = (char *) "showcmd", -- .has_arg = no_argument, -- .val = 's' | FIO_CLIENT_FLAG, -- }, -- { -- .name = (char *) "readonly", -- .has_arg = no_argument, -- .val = 'r' | FIO_CLIENT_FLAG, -- }, -- { -- .name = (char *) "eta", -- .has_arg = required_argument, -- .val = 'e' | FIO_CLIENT_FLAG, -- }, -- { -- .name = (char *) "eta-interval", -- .has_arg = required_argument, -- .val = 'O' | FIO_CLIENT_FLAG, -- }, -- { -- .name = (char *) "eta-newline", -- .has_arg = required_argument, -- .val = 'E' | FIO_CLIENT_FLAG, -- }, -- { -- .name = (char *) "debug", -- .has_arg = required_argument, -- .val = 'd' | FIO_CLIENT_FLAG, -- }, -- { -- .name = (char *) "parse-only", -- .has_arg = no_argument, -- .val = 'P' | FIO_CLIENT_FLAG, -- }, -- { -- .name = (char *) "section", -- .has_arg = required_argument, -- .val = 'x' | FIO_CLIENT_FLAG, -- }, -+static struct option l_opts[FIO_NR_OPTIONS]; -+static void fio_init_global(void) -+{ -+ int i = 0; -+ -+ l_opts[i].name = (char *) "output", -+ l_opts[i].has_arg = required_argument, -+ l_opts[i++].val = 'o' | FIO_CLIENT_FLAG, -+ -+ l_opts[i].name = (char *) "latency-log", -+ l_opts[i].has_arg = required_argument, -+ l_opts[i++].val = 'l' | FIO_CLIENT_FLAG, -+ -+ l_opts[i].name = (char *) "bandwidth-log", -+ l_opts[i].has_arg = no_argument, -+ l_opts[i++].val = 'b' | FIO_CLIENT_FLAG, -+ -+ l_opts[i].name = (char *) "minimal", -+ l_opts[i].has_arg = no_argument, -+ l_opts[i++].val = 'm' | FIO_CLIENT_FLAG, -+ -+ l_opts[i].name = (char *) "output-format", -+ l_opts[i].has_arg = required_argument, -+ l_opts[i++].val = 'F' | FIO_CLIENT_FLAG, -+ -+ l_opts[i].name = (char *) "append-terse", -+ l_opts[i].has_arg = optional_argument, -+ l_opts[i++].val = 'f', -+ -+ l_opts[i].name = (char *) "version", -+ l_opts[i].has_arg = no_argument, -+ l_opts[i++].val = 'v' | FIO_CLIENT_FLAG, -+ -+ l_opts[i].name = (char *) "help", -+ l_opts[i].has_arg = no_argument, -+ l_opts[i++].val = 'h' | FIO_CLIENT_FLAG, -+ -+ l_opts[i].name = (char *) "cmdhelp", -+ l_opts[i].has_arg = optional_argument, -+ l_opts[i++].val = 'c' | FIO_CLIENT_FLAG, -+ -+ l_opts[i].name = (char *) "enghelp", -+ l_opts[i].has_arg = optional_argument, -+ l_opts[i++].val = 'i' | FIO_CLIENT_FLAG, -+ -+ l_opts[i].name = (char *) "showcmd", -+ l_opts[i].has_arg = no_argument, -+ l_opts[i++].val = 's' | FIO_CLIENT_FLAG, -+ -+ l_opts[i].name = (char *) "readonly", -+ l_opts[i].has_arg = no_argument, -+ l_opts[i++].val = 'r' | FIO_CLIENT_FLAG, -+ -+ l_opts[i].name = (char *) "eta", -+ l_opts[i].has_arg = required_argument, -+ l_opts[i++].val = 'e' | FIO_CLIENT_FLAG, -+ -+ l_opts[i].name = (char *) "eta-interval", -+ l_opts[i].has_arg = required_argument, -+ l_opts[i++].val = 'O' | FIO_CLIENT_FLAG, -+ -+ l_opts[i].name = (char *) "eta-newline", -+ l_opts[i].has_arg = required_argument, -+ l_opts[i++].val = 'E' | FIO_CLIENT_FLAG, -+ -+ l_opts[i].name = (char *) "debug", -+ l_opts[i].has_arg = required_argument, -+ l_opts[i++].val = 'd' | FIO_CLIENT_FLAG, -+ -+ l_opts[i].name = (char *) "parse-only", -+ l_opts[i].has_arg = no_argument, -+ l_opts[i++].val = 'P' | FIO_CLIENT_FLAG, -+ -+ l_opts[i].name = (char *) "section", -+ l_opts[i].has_arg = required_argument, -+ l_opts[i++].val = 'x' | FIO_CLIENT_FLAG, -+ - #ifdef CONFIG_ZLIB -- { -- .name = (char *) "inflate-log", -- .has_arg = required_argument, -- .val = 'X' | FIO_CLIENT_FLAG, -- }, -+ l_opts[i].name = (char *) "inflate-log", -+ l_opts[i].has_arg = required_argument, -+ l_opts[i++].val = 'X' | FIO_CLIENT_FLAG, - #endif -- { -- .name = (char *) "alloc-size", -- .has_arg = required_argument, -- .val = 'a' | FIO_CLIENT_FLAG, -- }, -- { -- .name = (char *) "profile", -- .has_arg = required_argument, -- .val = 'p' | FIO_CLIENT_FLAG, -- }, -- { -- .name = (char *) "warnings-fatal", -- .has_arg = no_argument, -- .val = 'w' | FIO_CLIENT_FLAG, -- }, -- { -- .name = (char *) "max-jobs", -- .has_arg = required_argument, -- .val = 'j' | FIO_CLIENT_FLAG, -- }, -- { -- .name = (char *) "terse-version", -- .has_arg = required_argument, -- .val = 'V' | FIO_CLIENT_FLAG, -- }, -- { -- .name = (char *) "server", -- .has_arg = optional_argument, -- .val = 'S', -- }, -+ -+ l_opts[i].name = (char *) "alloc-size", -+ l_opts[i].has_arg = required_argument, -+ l_opts[i++].val = 'a' | FIO_CLIENT_FLAG, -+ -+ l_opts[i].name = (char *) "profile", -+ l_opts[i].has_arg = required_argument, -+ l_opts[i++].val = 'p' | FIO_CLIENT_FLAG, -+ -+ l_opts[i].name = (char *) "warnings-fatal", -+ l_opts[i].has_arg = no_argument, -+ l_opts[i++].val = 'w' | FIO_CLIENT_FLAG, -+ -+ l_opts[i].name = (char *) "max-jobs", -+ l_opts[i].has_arg = required_argument, -+ l_opts[i++].val = 'j' | FIO_CLIENT_FLAG, -+ -+ l_opts[i].name = (char *) "terse-version", -+ l_opts[i].has_arg = required_argument, -+ l_opts[i++].val = 'V' | FIO_CLIENT_FLAG, -+ -+ l_opts[i].name = (char *) "server", -+ l_opts[i].has_arg = optional_argument, -+ l_opts[i++].val = 'S', -+ - #ifdef WIN32 -- { -- .name = (char *) "server-internal", -- .has_arg = required_argument, -- .val = 'N', -- }, -+ l_opts[i].name = (char *) "server-internal", -+ l_opts[i].has_arg = required_argument, -+ l_opts[i++].val = 'N', - #endif -- { .name = (char *) "daemonize", -- .has_arg = required_argument, -- .val = 'D', -- }, -- { -- .name = (char *) "client", -- .has_arg = required_argument, -- .val = 'C', -- }, -- { -- .name = (char *) "remote-config", -- .has_arg = required_argument, -- .val = 'R', -- }, -- { -- .name = (char *) "cpuclock-test", -- .has_arg = no_argument, -- .val = 'T', -- }, -- { -- .name = (char *) "crctest", -- .has_arg = optional_argument, -- .val = 'G', -- }, -- { -- .name = (char *) "memcpytest", -- .has_arg = optional_argument, -- .val = 'M', -- }, -- { -- .name = (char *) "idle-prof", -- .has_arg = required_argument, -- .val = 'I', -- }, -- { -- .name = (char *) "status-interval", -- .has_arg = required_argument, -- .val = 'L' | FIO_CLIENT_FLAG, -- }, -- { -- .name = (char *) "trigger-file", -- .has_arg = required_argument, -- .val = 'W', -- }, -- { -- .name = (char *) "trigger-timeout", -- .has_arg = required_argument, -- .val = 'B', -- }, -- { -- .name = (char *) "trigger", -- .has_arg = required_argument, -- .val = 'H', -- }, -- { -- .name = (char *) "trigger-remote", -- .has_arg = required_argument, -- .val = 'J', -- }, -- { -- .name = (char *) "aux-path", -- .has_arg = required_argument, -- .val = 'K', -- }, -- { -- .name = (char *) "merge-blktrace-only", -- .has_arg = no_argument, -- .val = 'A' | FIO_CLIENT_FLAG, -- }, -- { -- .name = NULL, -- }, --}; -+ -+ l_opts[i].name = (char *) "daemonize", -+ l_opts[i].has_arg = required_argument, -+ l_opts[i++].val = 'D', -+ -+ l_opts[i].name = (char *) "client", -+ l_opts[i].has_arg = required_argument, -+ l_opts[i++].val = 'C', -+ -+ l_opts[i].name = (char *) "remote-config", -+ l_opts[i].has_arg = required_argument, -+ l_opts[i++].val = 'R', -+ -+ l_opts[i].name = (char *) "cpuclock-test", -+ l_opts[i].has_arg = no_argument, -+ l_opts[i++].val = 'T', -+ -+ l_opts[i].name = (char *) "crctest", -+ l_opts[i].has_arg = optional_argument, -+ l_opts[i++].val = 'G', -+ -+ l_opts[i].name = (char *) "memcpytest", -+ l_opts[i].has_arg = optional_argument, -+ l_opts[i++].val = 'M', -+ -+ l_opts[i].name = (char *) "idle-prof", -+ l_opts[i].has_arg = required_argument, -+ l_opts[i++].val = 'I', -+ -+ l_opts[i].name = (char *) "status-interval", -+ l_opts[i].has_arg = required_argument, -+ l_opts[i++].val = 'L' | FIO_CLIENT_FLAG, -+ -+ l_opts[i].name = (char *) "trigger-file", -+ l_opts[i].has_arg = required_argument, -+ l_opts[i++].val = 'W', -+ -+ l_opts[i].name = (char *) "trigger-timeout", -+ l_opts[i].has_arg = required_argument, -+ l_opts[i++].val = 'B', -+ -+ l_opts[i].name = (char *) "trigger", -+ l_opts[i].has_arg = required_argument, -+ l_opts[i++].val = 'H', -+ -+ l_opts[i].name = (char *) "trigger-remote", -+ l_opts[i].has_arg = required_argument, -+ l_opts[i++].val = 'J', -+ -+ l_opts[i].name = (char *) "aux-path", -+ l_opts[i].has_arg = required_argument, -+ l_opts[i++].val = 'K', -+ -+ l_opts[i].name = (char *) "merge-blktrace-only", -+ l_opts[i].has_arg = no_argument, -+ l_opts[i++].val = 'A' | FIO_CLIENT_FLAG, -+ -+ l_opts[i].name = NULL, -+ -+ thread_number = 0; -+ nr_segments = 0; -+ cur_segment = 0; -+ stat_number = 0; -+ -+ did_arg = false; -+ ini_file = NULL; -+ nr_clients = 0; -+ thread_number = 0; -+ prev_group_jobs = 0; -+ memset(&def_thread, 0, sizeof(def_thread)); -+ memset(segments, 0, sizeof(segments)); -+ memset(cmd_optstr, 0, sizeof(cmd_optstr)); -+} - - void free_threads_shm(void) - { -@@ -3044,6 +3021,7 @@ int fio_init_options(void) - f_out = stdout; - f_err = stderr; - -+ fio_init_global(); - fio_options_fill_optstring(); - fio_options_dup_and_init(l_opts); - -diff --git fio/smalloc.c fio/smalloc.c -index 142e03d2..a93290eb 100644 ---- fio/smalloc.c -+++ fio/smalloc.c -@@ -215,6 +215,10 @@ void sinit(void) - bool ret; - int i; - -+ mp = NULL; -+ nr_pools = 0; -+ smalloc_pool_size = INITIAL_SIZE; -+ - /* - * sinit() can be called more than once if alloc-size is - * set. But we want to allocate space for the struct pool --- -2.34.1 - diff --git a/benchmarks/fio/0007-external-fio-add-engine-init.patch b/benchmarks/fio/0007-external-fio-add-engine-init.patch deleted file mode 100644 index 148bad36a..000000000 --- a/benchmarks/fio/0007-external-fio-add-engine-init.patch +++ /dev/null @@ -1,181 +0,0 @@ -From b167af3a9446506c6b3f48c0b03ae58bb3f1e9d4 Mon Sep 17 00:00:00 2001 -From: dongjiuzhu1 <dongjiuzhu1@xiaomi.com> -Date: Sat, 10 Jun 2023 15:01:29 +0800 -Subject: [PATCH 07/10] external/fio: add engine init - -Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com> ---- - engines/cpu.c | 2 +- - engines/exec.c | 2 +- - engines/falloc.c | 2 +- - engines/fileoperations.c | 2 +- - engines/ftruncate.c | 2 +- - engines/mmap.c | 2 +- - engines/net.c | 2 +- - engines/null.c | 2 +- - engines/sync.c | 2 +- - libfio.c | 24 ++++++++++++++++++++++++ - 10 files changed, 33 insertions(+), 9 deletions(-) - -diff --git fio/engines/cpu.c fio/engines/cpu.c -index ce74dbce..564a3d7a 100644 ---- fio/engines/cpu.c -+++ fio/engines/cpu.c -@@ -326,7 +326,7 @@ static struct ioengine_ops ioengine = { - .option_struct_size = sizeof(struct cpu_options), - }; - --static void fio_init fio_cpuio_register(void) -+void fio_cpuio_register(void) - { - register_ioengine(&ioengine); - } -diff --git fio/engines/exec.c fio/engines/exec.c -index 20e50e00..a9025264 100644 ---- fio/engines/exec.c -+++ fio/engines/exec.c -@@ -383,7 +383,7 @@ static struct ioengine_ops ioengine = { - .option_struct_size = sizeof(struct exec_options), - }; - --static void fio_init fio_exec_register(void) -+void fio_exec_register(void) - { - register_ioengine(&ioengine); - } -diff --git fio/engines/falloc.c fio/engines/falloc.c -index 4b05ed68..9fc3bd5b 100644 ---- fio/engines/falloc.c -+++ fio/engines/falloc.c -@@ -101,7 +101,7 @@ static struct ioengine_ops ioengine = { - .flags = FIO_SYNCIO - }; - --static void fio_init fio_syncio_register(void) -+void fio_syncio_falloc_register(void) - { - register_ioengine(&ioengine); - } -diff --git fio/engines/fileoperations.c fio/engines/fileoperations.c -index ed0456c0..b302cda5 100644 ---- fio/engines/fileoperations.c -+++ fio/engines/fileoperations.c -@@ -303,7 +303,7 @@ static struct ioengine_ops ioengine_filedelete = { - }; - - --static void fio_init fio_fileoperations_register(void) -+void fio_fileoperations_register(void) - { - register_ioengine(&ioengine_filecreate); - register_ioengine(&ioengine_filestat); -diff --git fio/engines/ftruncate.c fio/engines/ftruncate.c -index c7ad038c..7ed859a4 100644 ---- fio/engines/ftruncate.c -+++ fio/engines/ftruncate.c -@@ -41,7 +41,7 @@ static struct ioengine_ops ioengine = { - .flags = FIO_SYNCIO | FIO_FAKEIO - }; - --static void fio_init fio_syncio_register(void) -+void fio_syncio_ftruncate_register(void) - { - register_ioengine(&ioengine); - } -diff --git fio/engines/mmap.c fio/engines/mmap.c -index 55ba1ab3..a47b9686 100644 ---- fio/engines/mmap.c -+++ fio/engines/mmap.c -@@ -327,7 +327,7 @@ static struct ioengine_ops ioengine = { - #endif - }; - --static void fio_init fio_mmapio_register(void) -+void fio_mmapio_register(void) - { - register_ioengine(&ioengine); - } -diff --git fio/engines/net.c fio/engines/net.c -index c6cec584..0f9fd6be 100644 ---- fio/engines/net.c -+++ fio/engines/net.c -@@ -1450,7 +1450,7 @@ static int str_hostname_cb(void *data, const char *input) - return 0; - } - --static void fio_init fio_netio_register(void) -+void fio_netio_register(void) - { - register_ioengine(&ioengine_rw); - #ifdef CONFIG_LINUX_SPLICE -diff --git fio/engines/null.c fio/engines/null.c -index 68759c26..2b4695c4 100644 ---- fio/engines/null.c -+++ fio/engines/null.c -@@ -176,7 +176,7 @@ static struct ioengine_ops ioengine = { - .flags = FIO_DISKLESSIO | FIO_FAKEIO, - }; - --static void fio_init fio_null_register(void) -+void fio_null_register(void) - { - register_ioengine(&ioengine); - } -diff --git fio/engines/sync.c fio/engines/sync.c -index 339ba999..f1047114 100644 ---- fio/engines/sync.c -+++ fio/engines/sync.c -@@ -490,7 +490,7 @@ static struct ioengine_ops ioengine_pvrw2 = { - }; - #endif - --static void fio_init fio_syncio_register(void) -+void fio_syncio_register(void) - { - register_ioengine(&ioengine_rw); - register_ioengine(&ioengine_prw); -diff --git fio/libfio.c fio/libfio.c -index 1a891776..b634fbc7 100644 ---- fio/libfio.c -+++ fio/libfio.c -@@ -350,6 +350,28 @@ static int endian_check(void) - return 0; - } - -+extern void fio_cpuio_register(void); -+extern void fio_exec_register(void); -+extern void fio_syncio_register(void); -+extern void fio_syncio_ftruncate_register(void); -+extern void fio_syncio_falloc_register(void); -+extern void fio_fileoperations_register(void); -+extern void fio_mmapio_register(void); -+extern void fio_netio_register(void); -+extern void fio_null_register(void); -+void fio_engine_init(void) -+{ -+ fio_cpuio_register(); -+ fio_exec_register(); -+ fio_syncio_register(); -+ fio_syncio_ftruncate_register(); -+ fio_syncio_falloc_register(); -+ fio_fileoperations_register(); -+ fio_mmapio_register(); -+ fio_netio_register(); -+ fio_null_register(); -+} -+ - int initialize_fio(char *envp[]) - { - long ps; -@@ -431,6 +453,8 @@ int initialize_fio(char *envp[]) - page_mask = ps - 1; - - fio_keywords_init(); -+ -+ fio_engine_init(); - return 0; - } - --- -2.34.1 - diff --git a/benchmarks/fio/0008-fio-fix-memory-leak-run-cpuio.fio.patch b/benchmarks/fio/0008-fio-fix-memory-leak-run-cpuio.fio.patch deleted file mode 100644 index 200927a18..000000000 --- a/benchmarks/fio/0008-fio-fix-memory-leak-run-cpuio.fio.patch +++ /dev/null @@ -1,30 +0,0 @@ -From 4104f7946da6a608f40dc6028d2f6570daad8ef0 Mon Sep 17 00:00:00 2001 -From: guohao15 <guohao15@xiaomi.com> -Date: Wed, 18 Oct 2023 11:09:12 +0800 -Subject: [PATCH 08/10] fio:fix memory leak run cpuio.fio - -Signed-off-by: guohao15 <guohao15@xiaomi.com> ---- - init.c | 5 ++++- - 1 file changed, 4 insertions(+), 1 deletion(-) - -diff --git fio/init.c fio/init.c -index 9dcad491..57d8ae18 100644 ---- fio/init.c -+++ fio/init.c -@@ -493,8 +493,11 @@ static struct thread_data *get_new_job(bool global, struct thread_data *parent, - td->thread_number = thread_number; - td->subjob_number = 0; - -- if (jobname) -+ if (jobname) { -+ if (td->o.name) -+ free(td->o.name); - td->o.name = strdup(jobname); -+ } - - if (!parent->o.group_reporting || parent == &def_thread) - stat_number++; --- -2.34.1 - diff --git a/benchmarks/fio/0009-fio-fix-memory-leak-ioengine-filecreate.patch b/benchmarks/fio/0009-fio-fix-memory-leak-ioengine-filecreate.patch deleted file mode 100644 index b74e3a533..000000000 --- a/benchmarks/fio/0009-fio-fix-memory-leak-ioengine-filecreate.patch +++ /dev/null @@ -1,62 +0,0 @@ -From a7b806befaf11eccf7f769187717dda1ec352fdc Mon Sep 17 00:00:00 2001 -From: guohao15 <guohao15@xiaomi.com> -Date: Wed, 18 Oct 2023 21:14:05 +0800 -Subject: [PATCH 09/10] fio:fix memory leak ioengine=filecreate - -Signed-off-by: guohao15 <guohao15@xiaomi.com> ---- - gettime.c | 2 +- - init.c | 10 ++++++++++ - 2 files changed, 11 insertions(+), 1 deletion(-) - -diff --git fio/gettime.c fio/gettime.c -index 14462420..2f0207d5 100644 ---- fio/gettime.c -+++ fio/gettime.c -@@ -37,7 +37,7 @@ static pthread_key_t tv_tls_key; - - enum fio_cs fio_clock_source = FIO_PREFERRED_CLOCK_SOURCE; - int fio_clock_source_set = 0; --static enum fio_cs fio_clock_source_inited = CS_INVAL; -+enum fio_cs fio_clock_source_inited = CS_INVAL; - - #ifdef FIO_DEBUG_TIME - -diff --git fio/init.c fio/init.c -index 57d8ae18..c8f53e62 100644 ---- fio/init.c -+++ fio/init.c -@@ -90,6 +90,10 @@ unsigned int *fio_warned = NULL; - static char cmd_optstr[256]; - static bool did_arg; - -+extern enum fio_cs fio_clock_source; -+extern int fio_clock_source_set; -+extern enum fio_cs fio_clock_source_inited; -+ - #define FIO_CLIENT_FLAG (1 << 16) - - /* -@@ -277,6 +281,11 @@ static void fio_init_global(void) - nr_clients = 0; - thread_number = 0; - prev_group_jobs = 0; -+ -+ fio_clock_source = FIO_PREFERRED_CLOCK_SOURCE; -+ fio_clock_source_set = 0; -+ fio_clock_source_inited = CS_INVAL; -+ - memset(&def_thread, 0, sizeof(def_thread)); - memset(segments, 0, sizeof(segments)); - memset(cmd_optstr, 0, sizeof(cmd_optstr)); -@@ -3073,6 +3082,7 @@ int parse_options(int argc, char *argv[]) - - free(ini_file); - fio_options_free(&def_thread); -+ fio_dump_options_free(&def_thread); - filesetup_mem_free(); - - if (!thread_number) { --- -2.34.1 - diff --git a/benchmarks/fio/0010-fio-fix-memory-leak-ioengine-exec.patch b/benchmarks/fio/0010-fio-fix-memory-leak-ioengine-exec.patch deleted file mode 100644 index f07b7e8ed..000000000 --- a/benchmarks/fio/0010-fio-fix-memory-leak-ioengine-exec.patch +++ /dev/null @@ -1,31 +0,0 @@ -From 6b211dc0191f0ebef454fdc8f5602474bed65471 Mon Sep 17 00:00:00 2001 -From: guohao15 <guohao15@xiaomi.com> -Date: Wed, 18 Oct 2023 17:42:33 +0800 -Subject: [PATCH 10/10] fio:fix memory leak ioengine=exec - -Signed-off-by: guohao15 <guohao15@xiaomi.com> ---- - engines/exec.c | 6 ++++++ - 1 file changed, 6 insertions(+) - -diff --git fio/engines/exec.c fio/engines/exec.c -index a9025264..fbefb99e 100644 ---- fio/engines/exec.c -+++ fio/engines/exec.c -@@ -188,7 +188,13 @@ static int exec_background(struct thread_options *o, struct exec_options *eo) - free(outfilename); - free(errfilename); - } -+ for (int i = 0; i < arguments_nb_items; i++) -+ free(arguments_array[i]); -+ free(arguments_array); - free(expanded_arguments); -+ free(exec_cmd); -+ free(outfilename); -+ free(errfilename); - return 0; - } - --- -2.34.1 - diff --git a/benchmarks/fio/CMakeLists.txt b/benchmarks/fio/CMakeLists.txt deleted file mode 100644 index 5dae3f20d..000000000 --- a/benchmarks/fio/CMakeLists.txt +++ /dev/null @@ -1,171 +0,0 @@ -# ############################################################################## -# apps/benchmarks/fio/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_BENCHMARK_FIO) - - set(FIOAPP_DIR ${CMAKE_CURRENT_LIST_DIR}/fio) - - if(NOT EXISTS ${FIOAPP_DIR}) - FetchContent_Declare( - fio_fetch - URL https://github.com/ldorau/fio/archive/refs/heads/master.zip SOURCE_DIR - ${CMAKE_CURRENT_LIST_DIR}/fio BINARY_DIR - ${CMAKE_BINARY_DIR}/apps/benchmarks/fio/fio - DOWNLOAD_NO_PROGRESS true - TIMEOUT 30 - PATCH_COMMAND - patch -p1 -d ${CMAKE_CURRENT_LIST_DIR}/fio < - ${CMAKE_CURRENT_LIST_DIR}/0001-external-fio-fix-compile-warning.patch - COMMAND patch -p1 -d ${CMAKE_CURRENT_LIST_DIR}/fio < - ${CMAKE_CURRENT_LIST_DIR}/0002-external-fio-add-os-nuttx-support.patch - COMMAND patch -p1 -d ${CMAKE_CURRENT_LIST_DIR}/fio < - ${CMAKE_CURRENT_LIST_DIR}/0003-external-fio-modify-smaller-size-for-nuttx.patch - COMMAND patch -p1 -d ${CMAKE_CURRENT_LIST_DIR}/fio < - ${CMAKE_CURRENT_LIST_DIR}/0004-external-fio-fix-runtime-error-by-asan.patch - COMMAND patch -p1 -d ${CMAKE_CURRENT_LIST_DIR}/fio < - ${CMAKE_CURRENT_LIST_DIR}/0005-external-fio-fix-compile-warning.patch - COMMAND patch -p1 -d ${CMAKE_CURRENT_LIST_DIR}/fio < - ${CMAKE_CURRENT_LIST_DIR}/0006-external-fio-reinit-global-var-issue-when-run-multip.patch - COMMAND patch -p1 -d ${CMAKE_CURRENT_LIST_DIR}/fio < - ${CMAKE_CURRENT_LIST_DIR}/0007-external-fio-add-engine-init.patch - COMMAND patch -p1 -d ${CMAKE_CURRENT_LIST_DIR}/fio < - ${CMAKE_CURRENT_LIST_DIR}/0008-fio-fix-memory-leak-run-cpuio.fio.patch - COMMAND patch -p1 -d ${CMAKE_CURRENT_LIST_DIR}/fio < - ${CMAKE_CURRENT_LIST_DIR}/0009-fio-fix-memory-leak-ioengine-filecreate.patch - COMMAND patch -p1 -d ${CMAKE_CURRENT_LIST_DIR}/fio < - ${CMAKE_CURRENT_LIST_DIR}/0010-fio-fix-memory-leak-ioengine-exec.patch) - - FetchContent_GetProperties(fio_fetch) - if(NOT fio_fetch_POPULATED) - FetchContent_Populate(fio_fetch) - endif() - endif() - - file(GLOB LIB_SRCS ${FIOAPP_DIR}/lib/*.c) - file(GLOB CRC_SRCS ${FIOAPP_DIR}/crc/*.c) - - set(CSRCS - ${LIB_SRCS} - ${CRC_SRCS} - ${FIOAPP_DIR}/gettime.c - ${FIOAPP_DIR}/ioengines.c - ${FIOAPP_DIR}/init.c - ${FIOAPP_DIR}/stat.c - ${FIOAPP_DIR}/log.c - ${FIOAPP_DIR}/time.c - ${FIOAPP_DIR}/filesetup.c - ${FIOAPP_DIR}/eta.c - ${FIOAPP_DIR}/verify.c - ${FIOAPP_DIR}/memory.c - ${FIOAPP_DIR}/io_u.c - ${FIOAPP_DIR}/parse.c - ${FIOAPP_DIR}/fio_sem.c - ${FIOAPP_DIR}/rwlock.c - ${FIOAPP_DIR}/pshared.c - ${FIOAPP_DIR}/options.c - ${FIOAPP_DIR}/smalloc.c - ${FIOAPP_DIR}/filehash.c - ${FIOAPP_DIR}/profile.c - ${FIOAPP_DIR}/debug.c - ${FIOAPP_DIR}/server.c - ${FIOAPP_DIR}/client.c - ${FIOAPP_DIR}/iolog.c - ${FIOAPP_DIR}/backend.c - ${FIOAPP_DIR}/libfio.c - ${FIOAPP_DIR}/flow.c - ${FIOAPP_DIR}/cconv.c - ${FIOAPP_DIR}/gettime-thread.c - ${FIOAPP_DIR}/helpers.c - ${FIOAPP_DIR}/json.c - ${FIOAPP_DIR}/idletime.c - ${FIOAPP_DIR}/td_error.c - ${FIOAPP_DIR}/zbd.c - ${FIOAPP_DIR}/profiles/tiobench.c - ${FIOAPP_DIR}/profiles/act.c - ${FIOAPP_DIR}/io_u_queue.c - ${FIOAPP_DIR}/filelock.c - ${FIOAPP_DIR}/steadystate.c - ${FIOAPP_DIR}/workqueue.c - ${FIOAPP_DIR}/rate-submit.c - ${FIOAPP_DIR}/optgroup.c - ${FIOAPP_DIR}/helper_thread.c - ${FIOAPP_DIR}/zone-dist.c - ${FIOAPP_DIR}/dedupe.c - ${FIOAPP_DIR}/engines/exec.c - ${FIOAPP_DIR}/engines/cpu.c - ${FIOAPP_DIR}/engines/sync.c - ${FIOAPP_DIR}/engines/ftruncate.c - ${FIOAPP_DIR}/engines/falloc.c - ${FIOAPP_DIR}/engines/fileoperations.c - ${FIOAPP_DIR}/engines/mmap.c - ${FIOAPP_DIR}/engines/null.c - ${FIOAPP_DIR}/engines/net.c) - - set(CFLAGS - -DCONFIG_GETTIMEOFDAY - -DCONFIG_CLOCK_GETTIME - -DCONFIG_HAVE_GETTID - -DCONFIG_STATIC_ASSERT - -DCONFIG_LITTLE_ENDIAN - -DCONFIG_POSIX_FALLOCATE - -DCONFIG_HAVE_BOOL - -DFIO_INTERNAL - -DCONFIG_NO_SHM - -DFIO_VERSION=\"1.2.0\" - -DFIO_USE_GENERIC_SWAP - -DFIO_USE_GENERIC_INIT_RANDOM_STATE - -DFIO_USE_GENERIC_BDEV_SIZE - -DBLOOM_SIZE=1024*1024 - -DBUF_SIZE=512*1024 - -DMAX_POOLS=4 - -DINITIAL_POOLS=2 - -DINITIAL_SIZE=512*1024 - -DCONFIG_SEED_BUCKETS=8 - -DBITS_PER_LONG=32 - -DXXH32_digest=fio_XXH32_digest - -DXXH32_update=fio_XXH32_update - -DXXH32=fio_XXH32 - -Dparse_options=fio_parse_options - -Dparse_option=fio_parse_option) - - set(INCDIR ${FIOAPP_DIR} ${FIOAPP_DIR}/arch ${FIOAPP_DIR}/crc - ${FIOAPP_DIR}/os) - include_directories(${INCDIR}) - - if(CONFIG_ARCH_ARM) - list(APPEND CFLAGS -D__ARM_ARCH_6__) - endif() - - set(SRCS ${FIOAPP_DIR}/fio.c ${CSRCS}) - nuttx_add_application( - NAME - fio - PRIORITY - ${CONFIG_BENCHMARK_FIO_PRIORITY} - STACKSIZE - ${CONFIG_BENCHMARK_FIO_STACKSIZE} - COMPILE_FLAGS - ${CFLAGS} - SRCS - ${SRCS}) - -endif() diff --git a/benchmarks/fio/Kconfig b/benchmarks/fio/Kconfig deleted file mode 100644 index f77a8a8a8..000000000 --- a/benchmarks/fio/Kconfig +++ /dev/null @@ -1,24 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config BENCHMARK_FIO - tristate "Flexible I/O Tester" - default n - depends on LIBC_ELF && LIBC_DLFCN - ---help--- - https://github.com/axboe/fio Fio spawns a number of threads or processes - doing a particular type of I/O action as specified by the user. - -if BENCHMARK_FIO - -config BENCHMARK_FIO_PRIORITY - int "fio task priority" - default 100 - -config BENCHMARK_FIO_STACKSIZE - int "fio stack size" - default 65536 - -endif diff --git a/benchmarks/fio/Make.defs b/benchmarks/fio/Make.defs deleted file mode 100644 index 27c568349..000000000 --- a/benchmarks/fio/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/benchmarks/fio/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_BENCHMARK_FIO),) -CONFIGURED_APPS += $(APPDIR)/benchmarks/fio -endif diff --git a/benchmarks/fio/Makefile b/benchmarks/fio/Makefile deleted file mode 100644 index c7950873d..000000000 --- a/benchmarks/fio/Makefile +++ /dev/null @@ -1,89 +0,0 @@ -############################################################################ -# apps/benchmarks/fio/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -PROGNAME = fio -PRIORITY = $(CONFIG_BENCHMARK_FIO_PRIORITY) -STACKSIZE = $(CONFIG_BENCHMARK_FIO_STACKSIZE) -MODULE = $(CONFIG_BENCHMARK_FIO) -MAINSRC = $(CURDIR)/fio/fio.c - -CFLAGS += -DCONFIG_GETTIMEOFDAY -DCONFIG_CLOCK_GETTIME -DCONFIG_HAVE_GETTID -CFLAGS += -DCONFIG_STATIC_ASSERT -DCONFIG_LITTLE_ENDIAN -DCONFIG_POSIX_FALLOCATE -CFLAGS += -DCONFIG_HAVE_BOOL -DFIO_INTERNAL -DCONFIG_NO_SHM -CFLAGS += -DFIO_VERSION='"1.2.0"' -DFIO_USE_GENERIC_SWAP -CFLAGS += -DFIO_USE_GENERIC_INIT_RANDOM_STATE -DFIO_USE_GENERIC_BDEV_SIZE - -CFLAGS += -DBLOOM_SIZE=1024*1024 -DBUF_SIZE=512*1024 -CFLAGS += -DMAX_POOLS=4 -DINITIAL_POOLS=2 -DINITIAL_SIZE=512*1024 -CFLAGS += -DCONFIG_SEED_BUCKETS=8 -DBITS_PER_LONG=32 -CFLAGS += -Ifio -Ifio/arch -Ifio/crc -Ifio/os -CFLAGS += -DXXH32_digest=fio_XXH32_digest -DXXH32_update=fio_XXH32_update -DXXH32=fio_XXH32 \ - -Dparse_options=fio_parse_options -Dparse_option=fio_parse_option - -ifneq ($(CONFIG_ARCH_ARM),) -CFLAGS += -D__ARM_ARCH_6__ -endif - -CSRCS += $(wildcard fio/lib/*.c) -CSRCS += $(wildcard fio/crc/*.c) - -CSRCS += fio/gettime.c fio/ioengines.c fio/init.c fio/stat.c fio/log.c fio/time.c fio/filesetup.c \ - fio/eta.c fio/verify.c fio/memory.c fio/io_u.c fio/parse.c fio/fio_sem.c fio/rwlock.c \ - fio/pshared.c fio/options.c fio/smalloc.c fio/filehash.c fio/profile.c fio/debug.c \ - fio/server.c fio/client.c fio/iolog.c fio/backend.c fio/libfio.c fio/flow.c fio/cconv.c \ - fio/gettime-thread.c fio/helpers.c fio/json.c fio/idletime.c fio/td_error.c fio/zbd.c \ - fio/profiles/tiobench.c fio/profiles/act.c fio/io_u_queue.c fio/filelock.c fio/steadystate.c \ - fio/workqueue.c fio/rate-submit.c fio/optgroup.c fio/helper_thread.c fio/zone-dist.c \ - fio/dedupe.c - -CSRCS += fio/engines/exec.c fio/engines/cpu.c fio/engines/sync.c fio/engines/ftruncate.c \ - fio/engines/falloc.c fio/engines/fileoperations.c fio/engines/mmap.c \ - fio/engines/null.c fio/engines/net.c - -ifeq ($(wildcard fio/.git),) -VERSION ?= master -fio.zip: - $(Q) curl -L https://github.com/ldorau/fio/archive/refs/heads/master.zip -o fio.zip - $(Q) unzip -o fio.zip - $(Q) mv fio-$(VERSION) fio - $(Q) patch -p0 < 0001-external-fio-fix-compile-warning.patch - $(Q) patch -p0 < 0002-external-fio-add-os-nuttx-support.patch - $(Q) patch -p0 < 0003-external-fio-modify-smaller-size-for-nuttx.patch - $(Q) patch -p0 < 0004-external-fio-fix-runtime-error-by-asan.patch - $(Q) patch -p0 < 0005-external-fio-fix-compile-warning.patch - $(Q) patch -p0 < 0006-external-fio-reinit-global-var-issue-when-run-multip.patch - $(Q) patch -p0 < 0007-external-fio-add-engine-init.patch - $(Q) patch -p0 < 0008-fio-fix-memory-leak-run-cpuio.fio.patch - $(Q) patch -p0 < 0009-fio-fix-memory-leak-ioengine-filecreate.patch - $(Q) patch -p0 < 0010-fio-fix-memory-leak-ioengine-exec.patch - -context:: fio.zip - -distclean:: - $(call DELDIR, fio) - $(call DELFILE, fio.zip) - -endif - -include $(APPDIR)/Application.mk diff --git a/benchmarks/iozone/.gitignore b/benchmarks/iozone/.gitignore deleted file mode 100644 index 35b179466..000000000 --- a/benchmarks/iozone/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/iozone diff --git a/benchmarks/iozone/CMakeLists.txt b/benchmarks/iozone/CMakeLists.txt deleted file mode 100644 index 0559ad63e..000000000 --- a/benchmarks/iozone/CMakeLists.txt +++ /dev/null @@ -1,89 +0,0 @@ -# ############################################################################## -# apps/benchmarks/iozone/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_BENCHMARK_IOZONE) - - # Define the directory and file paths - set(IOZONE_VERSION "${CONFIG_BENCHMARK_IOZONE_VERSION}") # Adjust this as - # needed - set(IOZONE_DIR ${CMAKE_CURRENT_LIST_DIR}/iozone) - set(IOZONE_ZIP ${IOZONE_DIR}.tgz) - set(IOZONE_URL - "https://www.iozone.org/src/current/iozone${IOZONE_VERSION}.tgz") - - # Download and unpack iozone if not already present - if(NOT EXISTS ${IOZONE_DIR}) - FetchContent_Declare( - iozone_fetch - URL ${IOZONE_URL} SOURCE_DIR ${IOZONE_DIR} - DOWNLOAD_NO_PROGRESS true - TIMEOUT 30 - PATCH_COMMAND patch -p1 -d ${IOZONE_DIR} < - ${CMAKE_CURRENT_LIST_DIR}/iozone.patch) - - FetchContent_GetProperties(iozone_fetch) - if(NOT iozone_fetch_POPULATED) - FetchContent_Populate(iozone_fetch) - endif() - endif() - - # Define source files - set(CSRCS ${IOZONE_DIR}/src/current/libbif.c) - set(MAINSRC ${IOZONE_DIR}/src/current/iozone.c) - - # Define compile flags - set(CFLAGS - -Dunix - -DHAVE_ANSIC_C - -DHAVE_PREAD - -DNAME=\"nuttx\" - -DNO_MADVISE - -DNO_FORK - -D__FreeBSD__ - -DNO_THREADS - -Wno-unused-parameter - -Wno-unused-function - -Wno-shadow - -Wno-unused-but-set-variable - -Wno-strict-prototypes - -Wno-misleading-indentation - -Wno-maybe-uninitialized - -DMAXBUFFERSIZE=32*1024 - -DMAXSTREAMS=8 - -DMAXNAMESIZE=NAME_MAX - -DRECLEN_START=1024) - - # Add application to the build - set(SRCS ${IOZONE_DIR}/src/current/iozone.c ${CSRCS}) - nuttx_add_application( - NAME - iozone - PRIORITY - ${CONFIG_BENCHMARK_IOZONE_PRIORITY} - STACKSIZE - ${CONFIG_BENCHMARK_IOZONE_STACKSIZE} - COMPILE_FLAGS - ${CFLAGS} - SRCS - ${SRCS}) - -endif() diff --git a/benchmarks/iozone/Kconfig b/benchmarks/iozone/Kconfig deleted file mode 100644 index eedff6067..000000000 --- a/benchmarks/iozone/Kconfig +++ /dev/null @@ -1,30 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config BENCHMARK_IOZONE - tristate "IOzone, filesystem benchmark tool" - default n - ---help--- - https://www.iozone.org/ - -if BENCHMARK_IOZONE - -config BENCHMARK_IOZONE_PROGNAME - string "Program name" - default "iozone" - -config BENCHMARK_IOZONE_PRIORITY - int "IOzone task priority" - default 100 - -config BENCHMARK_IOZONE_STACKSIZE - int "IOzone stack size" - default 8192 - -config BENCHMARK_IOZONE_VERSION - string "iozone version" - default "3_493" - -endif diff --git a/benchmarks/iozone/Make.defs b/benchmarks/iozone/Make.defs deleted file mode 100644 index b3712058a..000000000 --- a/benchmarks/iozone/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/benchmarks/iozone/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_BENCHMARK_IOZONE),) -CONFIGURED_APPS += $(APPDIR)/benchmarks/iozone -endif diff --git a/benchmarks/iozone/Makefile b/benchmarks/iozone/Makefile deleted file mode 100644 index 22985764c..000000000 --- a/benchmarks/iozone/Makefile +++ /dev/null @@ -1,69 +0,0 @@ -############################################################################ -# apps/benchmarks/iozone/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -PROGNAME = $(CONFIG_BENCHMARK_IOZONE_PROGNAME) -PRIORITY = $(CONFIG_BENCHMARK_IOZONE_PRIORITY) -STACKSIZE = $(CONFIG_BENCHMARK_IOZONE_STACKSIZE) -MODULE = $(CONFIG_BENCHMARK_IOZONE) - -CFLAGS += -Dunix -DHAVE_ANSIC_C -DHAVE_PREAD -DNAME='"nuttx"' -CFLAGS += -DNO_MADVISE -DNO_FORK -D__FreeBSD__ -DNO_THREADS -CFLAGS += -Wno-unused-parameter -Wno-unused-function -Wno-shadow -CFLAGS += -Wno-unused-but-set-variable -Wno-strict-prototypes -CFLAGS += -Wno-misleading-indentation -Wno-maybe-uninitialized - -CFLAGS += -DMAXBUFFERSIZE=32*1024 -DMAXSTREAMS=8 -DMAXNAMESIZE=NAME_MAX -CFLAGS += -DRECLEN_START=1024 - -CSRCS = iozone/src/current/libbif.c -MAINSRC = iozone/src/current/iozone.c - -CONFIG_BENCHMARK_IOZONE_URL ?= "https://www.iozone.org/src/current/" - -IOZONE_UNPACKNAME = iozone -IOZONE_VERSION = $(patsubst "%",%,$(strip $(CONFIG_BENCHMARK_IOZONE_VERSION))) -IOZONE_ZIP = iozone$(IOZONE_VERSION).tgz - -$(IOZONE_ZIP): - @echo "Downloading: $(IOZONE_ZIP)" - $(Q) curl -O -L $(CONFIG_BENCHMARK_IOZONE_URL)/$(IOZONE_ZIP) - -$(IOZONE_UNPACKNAME): $(IOZONE_ZIP) - @echo "Unpacking: $(IOZONE_ZIP) -> $(IOZONE_UNPACKNAME)" - $(Q) tar zxvf $(IOZONE_ZIP) - $(Q) mv iozone$(IOZONE_VERSION) $(IOZONE_UNPACKNAME) - $(Q) echo "Patching $(IOZONE_UNPACKNAME)" - $(Q) cat iozone.patch | patch -s -N -d $(IOZONE_UNPACKNAME) -p1 - $(Q) touch $(IOZONE_UNPACKNAME) - -# Download and unpack tarball if no git repo found -ifeq ($(wildcard $(IOZONE_UNPACKNAME)/.git),) -context:: $(IOZONE_UNPACKNAME) - -distclean:: - $(call DELDIR, $(IOZONE_UNPACKNAME)) - $(call DELFILE, $(IOZONE_ZIP)) -endif - -include $(APPDIR)/Application.mk diff --git a/benchmarks/iozone/iozone.patch b/benchmarks/iozone/iozone.patch deleted file mode 100644 index e970c931f..000000000 --- a/benchmarks/iozone/iozone.patch +++ /dev/null @@ -1,125 +0,0 @@ -diff --git a/src/current/iozone.c b/src/current/iozone.c -index eda702d..59ee513 100644 ---- a/src/current/iozone.c -+++ b/src/current/iozone.c -@@ -82,11 +82,12 @@ extern int h_errno; /* imported for errors */ - #endif - #endif - -+#include <sys/types.h> - #ifdef NO_FORK -+pid_t no_fork(void); - #define fork no_fork - #endif - --#include <sys/types.h> - #include <sys/stat.h> - #if defined (__LP64__) || defined(OSF_64) || defined(__alpha__) || defined(__arch64__) || defined(_LP64) || defined(__s390x__) || defined(__AMD64__) - #define MODE "\tCompiled for 64 bit mode." -@@ -870,16 +871,22 @@ struct master_neutral_command { - /* At 8 Meg switch to large records */ - #define CROSSOVER (8*1024) - /*maximum buffer size*/ -+#ifndef MAXBUFFERSIZE - #define MAXBUFFERSIZE (8*1024*1024) -+#endif - #else - /* At 16 Meg switch to large records */ - #define CROSSOVER (16*1024) -+#ifndef MAXBUFFERSIZE - /* Maximum buffer size*/ - #define MAXBUFFERSIZE (16*1024*1024) - #endif -+#endif - - /* Maximum number of children. Threads/procs/clients */ -+#ifndef MAXSTREAMS - #define MAXSTREAMS 1024 -+#endif - - /* Minimum buffer size */ - #define MINBUFFERSIZE 128 -@@ -899,7 +906,9 @@ struct master_neutral_command { - - - /* Maximum number of characters in filename */ -+#ifndef MAXNAMESIZE - #define MAXNAMESIZE 1000 -+#endif - - /* - * Define the typical output that the user will see on their -@@ -953,7 +962,9 @@ struct master_neutral_command { - /* Default maximum file size. This is 512 MBytes */ - #define KILOBYTES_END (1024*512) - /* Default starting record size */ -+#ifndef RECLEN_START - #define RECLEN_START 4096 -+#endif - /* Default maximum record size */ - #define RECLEN_END (MAXBUFFERSIZE) - /* Multiplier for each itteration on file and record size */ -@@ -1640,7 +1651,7 @@ char dummyfile1 [MAXNAMESIZE]; /* name of dummy file */ - char *filearray[MAXSTREAMS]; /* array of file names */ - int blkidx[MAXSTREAMS]; /* array of file names */ - char tfile[MAXNAMESIZE]; --char *buffer,*buffer1, *mbuffer,*mainbuffer; -+static char *buffer,*buffer1, *mbuffer,*mainbuffer; - FILE *pi,*r_traj_fd,*w_traj_fd; - VOLATILE char *pbuffer; - char *default_filename="iozone.tmp"; /*default name of temporary file*/ -@@ -1805,7 +1816,7 @@ int direct_flag; - int current_client_number; - long long chid; - int file_lock; --unsigned int pattern; -+static unsigned int pattern; - long long stride = STRIDE; - long long delay,purge,fetchon; - off64_t numrecs64 = (off64_t)NUMRECS; -@@ -19219,7 +19230,7 @@ dump_throughput_cpu() - long long x,y,i,j; - char *port; - char *label; -- char print_str[300]; -+ char print_str[512]; - x=max_x; - y=max_y; - -@@ -19288,7 +19299,7 @@ dump_throughput() - long long x,y,i,j; - char *port; - char *label; -- char print_str[300]; -+ char print_str[512]; - x=max_x; - y=max_y; - -@@ -24340,7 +24351,7 @@ start_monitor(test) - char *test; - #endif - { -- char command_line[256]; -+ char command_line[512]; - if(strlen(imon_start)!=0) - { - if(imon_sync) -@@ -24358,7 +24369,7 @@ stop_monitor(test) - char *test; - #endif - { -- char command_line[256]; -+ char command_line[512]; - if(strlen(imon_stop)!=0) - { - if(imon_sync) -@@ -24867,6 +24878,9 @@ int main(void) - /* - ** Type definitions (for convenience). - */ -+ -+#undef false -+#undef true - #if defined(Windows) - int false = 0; - int true = 1; diff --git a/benchmarks/mtd/CMakeLists.txt b/benchmarks/mtd/CMakeLists.txt deleted file mode 100644 index 975ed1001..000000000 --- a/benchmarks/mtd/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# ############################################################################## -# apps/benchmarks/mtd/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_BENCHMARK_MTD) - nuttx_add_application( - NAME - mtd - STACKSIZE - ${CONFIG_DEFAULT_TASK_STACKSIZE} - MODULE - ${CONFIG_BENCHMARK_MTD} - SRCS - mtd.c) -endif() diff --git a/benchmarks/mtd/Kconfig b/benchmarks/mtd/Kconfig deleted file mode 100644 index 0628e7835..000000000 --- a/benchmarks/mtd/Kconfig +++ /dev/null @@ -1,18 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config BENCHMARK_MTD - tristate "MTD test and transfer rate benchmark" - default n - depends on BUILD_FLAT && MTD && LIBC_FLOATINGPOINT - ---help--- - This testing/benchmark application performs an erase/write - operation to evaluate write transfer rate and then reads the - written content back to evaluate the read transfer rate. Finally, - it compares the read data with the previously written data to - ensure the MTD device is working as expected. - - NOTE: This application uses internal OS interfaces and so it is not - available in the NuttX kernel build. diff --git a/benchmarks/mtd/Make.defs b/benchmarks/mtd/Make.defs deleted file mode 100644 index 9bf77e7b9..000000000 --- a/benchmarks/mtd/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/benchmarks/mtd/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_BENCHMARK_MTD),) -CONFIGURED_APPS += $(APPDIR)/benchmarks/mtd/ -endif diff --git a/benchmarks/mtd/mtd.c b/benchmarks/mtd/mtd.c deleted file mode 100644 index b9d3d8a98..000000000 --- a/benchmarks/mtd/mtd.c +++ /dev/null @@ -1,207 +0,0 @@ -/**************************************************************************** - * apps/benchmarks/mtd/mtd.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <sys/stat.h> -#include <unistd.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <time.h> - -#include <nuttx/mtd/mtd.h> -#include <nuttx/fs/smart.h> -#include <nuttx/fs/ioctl.h> - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private data - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -int main(int argc, FAR char *argv[]) -{ - struct inode *inode; - struct timespec start; - struct timespec end; - struct mtd_geometry_s geo; - struct partition_info_s info; - int ret; - int x; - double elapsed_time; - double transfer_rate; - size_t total_bytes_written = 0; - size_t total_bytes_read = 0; - char *buffer; - - /* Argument given? */ - - if (argc < 2) - { - fprintf(stderr, "usage: mtd flash_block_device\n"); - return -1; - } - - /* Find the inode of the block driver identified by 'source' */ - - ret = open_blockdriver(argv[1], 0, &inode); - if (ret < 0) - { - fprintf(stderr, "Failed to open %s\n", argv[1]); - return ret; - } - - /* Get the low-level format from the device. */ - - ret = inode->u.i_bops->ioctl(inode, BIOC_PARTINFO, (unsigned long) &info); - if (ret != OK) - { - fprintf(stderr, "Device is not a block device\n"); - goto errout_with_driver; - } - - /* Get the MTD geometry */ - - ret = inode->u.i_bops->ioctl(inode, MTDIOC_GEOMETRY, (unsigned long) &geo); - if (ret != OK) - { - fprintf(stderr, "Device is not a MTD device"); - goto errout_with_driver; - } - - /* Report the device structure */ - - printf("FLASH device parameters:\n"); - printf(" Sector size: %10d\n", info.sectorsize); - printf(" Sector count: %10d\n", info.numsectors); - printf(" Erase block size: %10" PRIu32 "\n", geo.erasesize); - printf(" Total size: %10d\n", info.sectorsize * info.numsectors); - - if (info.sectorsize != geo.erasesize) - { - fprintf(stderr, "Sector size does not match the erase block size.\n" - "Please adjust the sector size to enable erasing and writing " - "without using an intermediary read buffer.\n"); - goto errout_with_driver; - } - - /* Allocate buffers to use */ - - buffer = (char *)malloc(info.sectorsize); - if (buffer == NULL) - { - fprintf(stderr, "Error allocating buffer\n"); - goto errout_with_driver; - } - - /* Fill the buffer with known data */ - - for (int i = 0; i < info.sectorsize; i++) - { - buffer[i] = (char)(i & 0xff); - } - - /* Now write some data to the sector */ - - printf("\nStarting write operation...\n"); - - clock_gettime(CLOCK_MONOTONIC, &start); - for (x = 0; x < info.numsectors; x++) - { - inode->u.i_bops->write(inode, (const unsigned char *)buffer, x, 1); - - total_bytes_written += info.sectorsize; - } - - clock_gettime(CLOCK_MONOTONIC, &end); - - elapsed_time = (end.tv_sec - start.tv_sec) + \ - (end.tv_nsec - start.tv_nsec) / 1e9; - transfer_rate = (total_bytes_written / elapsed_time) / 1024; - - printf("\nWrite operation completed in %.2f seconds\n", elapsed_time); - printf("Total bytes written: %zu\n", total_bytes_written); - printf("Transfer rate [write]: %.2f KiB/s\n", transfer_rate); - - /* Now read the data back to validate everything was written and can - * be read. - */ - - printf("\nStarting read operation...\n"); - - clock_gettime(CLOCK_MONOTONIC, &start); - - for (x = 0; x < info.numsectors; x++) - { - inode->u.i_bops->read(inode, (unsigned char *)buffer, x, 1); - - total_bytes_read += info.sectorsize; - } - - clock_gettime(CLOCK_MONOTONIC, &end); - - elapsed_time = (end.tv_sec - start.tv_sec) + \ - (end.tv_nsec - start.tv_nsec) / 1e9; - transfer_rate = (total_bytes_written / elapsed_time) / 1024; - - printf("\nRead operation completed in %.2f seconds\n", elapsed_time); - printf("Total bytes read: %zu\n", total_bytes_read); - printf("Transfer rate [read]: %.2f KiB/s\n", transfer_rate); - - /* Compare the read data with the written data */ - - for (int i = 0; i < info.sectorsize; i++) - { - if (buffer[i] != (char)(i & 0xff)) - { - printf("\nData mismatch at byte %d: expected %02X, got %02X\n", - i, (unsigned char)(i & 0xff), (unsigned char)buffer[i]); - goto errout_with_buffers; - } - } - - printf("\nData verification successful: read data matches written data\n"); - -errout_with_buffers: - - /* Free the allocated buffers */ - - free(buffer); - -errout_with_driver: - - /* Now close the block device and exit */ - - close_blockdriver(inode); - return 0; -} diff --git a/benchmarks/osperf/CMakeLists.txt b/benchmarks/osperf/CMakeLists.txt deleted file mode 100644 index e47386d09..000000000 --- a/benchmarks/osperf/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# ############################################################################## -# apps/benchmarks/osperf/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_BENCHMARK_OSPERF) - nuttx_add_application( - NAME - osperf - SRCS - osperf.c - STACKSIZE - ${CONFIG_BENCHMARK_OSPERF_STACKSIZE} - PRIORITY - ${CONFIG_BENCHMARK_OSPERF_PRIORITY}) -endif() diff --git a/benchmarks/osperf/Kconfig b/benchmarks/osperf/Kconfig deleted file mode 100644 index da03babd0..000000000 --- a/benchmarks/osperf/Kconfig +++ /dev/null @@ -1,25 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config BENCHMARK_OSPERF - tristate "System performance profiling" - default n - depends on PIPES - depends on SCHED_HPWORK - ---help--- - Measure the performance of core system functions, such as thread - switching and the time required for semaphore execution - -if BENCHMARK_OSPERF - -config BENCHMARK_OSPERF_PRIORITY - int "OS profiling task priority" - default 100 - -config BENCHMARK_OSPERF_STACKSIZE - int "OS profiling stack size" - default DEFAULT_TASK_STACKSIZE - -endif diff --git a/benchmarks/osperf/Make.defs b/benchmarks/osperf/Make.defs deleted file mode 100644 index 1efa69044..000000000 --- a/benchmarks/osperf/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/benchmarks/osperf/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_BENCHMARK_OSPERF),) -CONFIGURED_APPS += $(APPDIR)/benchmarks/osperf -endif diff --git a/benchmarks/osperf/osperf.c b/benchmarks/osperf/osperf.c deleted file mode 100644 index 757fb4216..000000000 --- a/benchmarks/osperf/osperf.c +++ /dev/null @@ -1,504 +0,0 @@ -/**************************************************************************** - * apps/benchmarks/osperf/osperf.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <assert.h> -#include <limits.h> -#include <pthread.h> -#include <sched.h> -#include <semaphore.h> -#include <stdbool.h> -#include <stddef.h> -#include <stdint.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <sys/param.h> -#include <sys/poll.h> - -#include <nuttx/sched.h> -#include <nuttx/spinlock.h> - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -struct performance_time_s -{ - clock_t start; - clock_t end; -}; - -struct performance_thread_s -{ - sem_t sem; - struct performance_time_s time; -}; - -struct performance_entry_s -{ - const char name[NAME_MAX]; - CODE size_t (*entry)(void); -}; - -/**************************************************************************** - * Private Functions Prototypes - ****************************************************************************/ - -static size_t pthread_create_performance(void); -static size_t pthread_switch_performance(void); -static size_t context_switch_performance(void); -static size_t hpwork_performance(void); -static size_t poll_performance(void); -static size_t pipe_performance(void); -static size_t semwait_performance(void); -static size_t sempost_performance(void); - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static const struct performance_entry_s g_entry_list[] = -{ - {"pthread-create", pthread_create_performance}, - {"pthread-switch", pthread_switch_performance}, - {"context-switch", context_switch_performance}, - {"hpwork", hpwork_performance}, - {"poll-write", poll_performance}, - {"pipe-rw", pipe_performance}, - {"semwait", semwait_performance}, - {"sempost", sempost_performance}, -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static int performance_thread_create(FAR void *(*entry)(FAR void *), - FAR void *arg, int priority) -{ - struct sched_param param; - pthread_attr_t attr; - pthread_t tid; - - param.sched_priority = priority; - pthread_attr_init(&attr); - pthread_attr_setschedpolicy(&attr, SCHED_FIFO); - pthread_attr_setschedparam(&attr, ¶m); - pthread_create(&tid, &attr, entry, arg); - DEBUGASSERT(tid > 0); - return tid; -} - -static void performance_start(FAR struct performance_time_s *result) -{ - result->start = perf_gettime(); -} - -static void performance_end(FAR struct performance_time_s *result) -{ - result->end = perf_gettime(); -} - -static size_t performance_gettime(FAR struct performance_time_s *result) -{ - struct timespec ts; - perf_convert(result->end - result->start, &ts); - return ts.tv_sec * NSEC_PER_SEC + ts.tv_nsec; -} - -/**************************************************************************** - * Pthread switch performance - ****************************************************************************/ - -static FAR void *pthread_switch_task(FAR void *arg) -{ - FAR struct performance_thread_s *perf = arg; - irqstate_t flags = enter_critical_section(); - sem_wait(&perf->sem); - performance_end(&perf->time); - leave_critical_section(flags); - return NULL; -} - -static size_t pthread_switch_performance(void) -{ - struct performance_thread_s perf; - pthread_t tid; - - sem_init(&perf.sem, 0, 0); - tid = performance_thread_create(pthread_switch_task, &perf, - CONFIG_BENCHMARK_OSPERF_PRIORITY + 1); - - performance_start(&perf.time); - sem_post(&perf.sem); - pthread_join(tid, NULL); - - return performance_gettime(&perf.time); -} - -/**************************************************************************** - * Pthread create performance - ****************************************************************************/ - -static FAR void *pthread_create_task(FAR void *arg) -{ - FAR struct performance_time_s *time = arg; - performance_end(time); - return NULL; -} - -static size_t pthread_create_performance(void) -{ - struct performance_time_s result; - struct sched_param param; - pthread_attr_t attr; - pthread_t tid; - - sched_getparam(gettid(), ¶m); - param.sched_priority++; - pthread_attr_init(&attr); - pthread_attr_setschedpolicy(&attr, SCHED_FIFO); - pthread_attr_setschedparam(&attr, ¶m); - - performance_start(&result); - pthread_create(&tid, &attr, pthread_create_task, &result); - pthread_join(tid, NULL); - - return performance_gettime(&result); -} - -/**************************************************************************** - * Context create performance - ****************************************************************************/ - -static FAR void *context_switch_task(FAR void *arg) -{ - FAR struct performance_time_s *time = arg; - sched_yield(); - performance_end(time); - return 0; -} - -static size_t context_switch_performance(void) -{ - struct performance_time_s time; - int tid; - - tid = performance_thread_create(context_switch_task, &time, - CONFIG_INIT_PRIORITY); - sched_yield(); - performance_start(&time); - sched_yield(); - pthread_join(tid, NULL); - return performance_gettime(&time); -} - -/**************************************************************************** - * wdog performance - ****************************************************************************/ - -static void work_handle(void *arg) -{ - FAR struct performance_time_s *time = ((FAR void **)arg)[2]; - FAR sem_t *sem = ((void **)arg)[1]; - performance_end(time); - sem_post(sem); -} - -static size_t hpwork_performance(void) -{ - struct performance_time_s result; - struct work_s work; - sem_t sem = SEM_INITIALIZER(0); - int ret; - - FAR void *args = (void *[]) - { - (FAR void *)&work, - (FAR void *)&sem, - (FAR void *)&result - }; - - memset(&result, 0, sizeof(result)); - memset(&work, 0, sizeof(work)); - performance_start(&result); - ret = work_queue(HPWORK, &work, work_handle, args, 0); - DEBUGASSERT(ret == 0); - - sem_wait(&sem); - return performance_gettime(&result); -} - -/**************************************************************************** - * poll-write performance - ****************************************************************************/ - -static FAR void *poll_task(FAR void *arg) -{ - FAR void **argv = arg; - FAR struct performance_time_s *time = argv[0]; - int pipefd = (int)(uintptr_t)argv[1]; - - performance_start(time); - write(pipefd, "a", 1); - return 0; -} - -static size_t poll_performance(void) -{ - struct performance_time_s result; - struct pollfd fds; - FAR void *argv[2]; - int pipefd[2]; - int ret; - - ret = pipe(pipefd); - DEBUGASSERT(ret == 0); - fds.fd = pipefd[0]; - fds.events = POLLIN; - argv[0] = (FAR char *)&result; - argv[1] = (FAR char *)(uintptr_t)pipefd[1]; - - ret = performance_thread_create(poll_task, argv, CONFIG_INIT_PRIORITY); - - poll(&fds, 1, -1); - performance_end(&result); - - pthread_join(ret, NULL); - close(pipefd[0]); - close(pipefd[1]); - return performance_gettime(&result); -} - -/**************************************************************************** - * pipe performance - ****************************************************************************/ - -static size_t pipe_performance(void) -{ - struct performance_time_s result; - int pipefd[2]; - int ret; - char r; - - ret = pipe(pipefd); - DEBUGASSERT(ret == 0); - - performance_start(&result); - write(pipefd[0], "a", 1); - read(pipefd[1], &r, 1); - performance_end(&result); - - close(pipefd[0]); - close(pipefd[1]); - return performance_gettime(&result); -} - -/**************************************************************************** - * semwait_performance - ****************************************************************************/ - -static size_t semwait_performance(void) -{ - struct performance_time_s result; - sem_t sem; - - sem_init(&sem, 0, 2); - - performance_start(&result); - sem_wait(&sem); - performance_end(&result); - - sem_destroy(&sem); - return performance_gettime(&result); -} - -/**************************************************************************** - * sempost_performance - ****************************************************************************/ - -static size_t sempost_performance(void) -{ - struct performance_time_s result; - sem_t sem; - - sem_init(&sem, 0, 0); - - performance_start(&result); - sem_post(&sem); - performance_end(&result); - - sem_destroy(&sem); - return performance_gettime(&result); -} - -/**************************************************************************** - * performance_help - ****************************************************************************/ - -static void performance_help(void) -{ - printf("Usage: performance [OPTIONS] [name]\n\n"); - printf("OPTIONS:\n"); - printf("\t-c, \tNumber of times to run each test\n"); - printf("\t-d, \tShow detail of each test\n"); - printf("\t-h, \tShow this help message\n"); - printf("\t-l, \tList all tests\n"); -} - -/**************************************************************************** - * performance_run - ****************************************************************************/ - -static void performance_run(const FAR struct performance_entry_s *item, - size_t count, bool detail) -{ - size_t total = 0; - size_t max = 0; - size_t min = 0; - size_t i; - - for (i = 0; i < count; i++) - { - irqstate_t flags = enter_critical_section(); - size_t time = item->entry(); - leave_critical_section(flags); - - total += time; - if (time > max) - { - max = time; - } - - if (time < min || min == 0) - { - min = time; - } - - if (detail) - { - printf("\t%zu: %zu\n", i, time); - } - } - - printf("%-*s %10zu %10zu %10zu\n", NAME_MAX, item->name, max, min, - total / count); -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -static const FAR -struct performance_entry_s *find_entry(FAR const char *name) -{ - size_t i; - - for (i = 0; i < nitems(g_entry_list); i++) - { - if (strcmp(name, g_entry_list[i].name) == 0) - { - return &g_entry_list[i]; - } - } - - return NULL; -} - -void performance_list(void) -{ - size_t i; - - for (i = 0; i < nitems(g_entry_list); i++) - { - printf("%s\n", g_entry_list[i].name); - } -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -int main(int argc, FAR char *argv[]) -{ - const FAR struct performance_entry_s *item = NULL; - bool detail = false; - size_t count = 100; - size_t i; - int opt; - - while ((opt = getopt(argc, argv, "dc:hl")) != -1) - { - switch (opt) - { - case 'd': - detail = true; - break; - case 'c': - count = strtoul(optarg, NULL, 0); - break; - case 'h': - performance_help(); - return EXIT_SUCCESS; - case 'l': - performance_list(); - return EXIT_SUCCESS; - default: - performance_help(); - return EXIT_FAILURE; - } - } - - if (optind < argc) - { - item = find_entry(argv[optind]); - if (item == NULL) - { - printf("Can't find %s\n", argv[optind]); - return EXIT_FAILURE; - } - } - - printf("OS performance args: count:%zu, detail:%s\n", count, - detail ? "true" : "false"); - - printf("==============================================================\n"); - printf("%-*s %10s %10s %10s\n", NAME_MAX, "Describe", "Max", "Min", "Avg"); - - if (item != NULL) - { - performance_run(item, count, detail); - return EXIT_SUCCESS; - } - - for (i = 0; i < nitems(g_entry_list); i++) - { - item = &g_entry_list[i]; - performance_run(item, count, detail); - } - - return EXIT_SUCCESS; -} diff --git a/benchmarks/ramspeed/CMakeLists.txt b/benchmarks/ramspeed/CMakeLists.txt deleted file mode 100644 index a8b0df091..000000000 --- a/benchmarks/ramspeed/CMakeLists.txt +++ /dev/null @@ -1,31 +0,0 @@ -# ############################################################################## -# apps/benchmarks/ramspeed/CMakeLists.txt -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_BENCHMARK_RAMSPEED) - nuttx_add_application( - NAME - ${CONFIG_BENCHMARK_RAMSPEED_PROGNAME} - SRCS - ramspeed_main.c - STACKSIZE - ${CONFIG_BENCHMARK_RAMSPEED_STACKSIZE} - PRIORITY - ${CONFIG_BENCHMARK_RAMSPEED_PRIORITY}) -endif() diff --git a/benchmarks/ramspeed/Make.defs b/benchmarks/ramspeed/Make.defs deleted file mode 100644 index b78ae67fb..000000000 --- a/benchmarks/ramspeed/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/benchmarks/ramspeed/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_BENCHMARK_RAMSPEED),) -CONFIGURED_APPS += $(APPDIR)/benchmarks/ramspeed -endif diff --git a/benchmarks/ramspeed/Makefile b/benchmarks/ramspeed/Makefile deleted file mode 100644 index c11a67ff2..000000000 --- a/benchmarks/ramspeed/Makefile +++ /dev/null @@ -1,34 +0,0 @@ -############################################################################ -# apps/benchmarks/ramspeed/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -# RAM speed test - -PROGNAME = $(CONFIG_BENCHMARK_RAMSPEED_PROGNAME) -PRIORITY = $(CONFIG_BENCHMARK_RAMSPEED_PRIORITY) -STACKSIZE = $(CONFIG_BENCHMARK_RAMSPEED_STACKSIZE) -MODULE = $(CONFIG_BENCHMARK_RAMSPEED) - -MAINSRC = ramspeed_main.c - -include $(APPDIR)/Application.mk diff --git a/benchmarks/rt-tests/.gitignore b/benchmarks/rt-tests/.gitignore deleted file mode 100644 index baa0c8710..000000000 --- a/benchmarks/rt-tests/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/rt-tests -/*.zip diff --git a/benchmarks/rt-tests/0001-rt-tests-cyclictest-Port-for-NuttX.patch b/benchmarks/rt-tests/0001-rt-tests-cyclictest-Port-for-NuttX.patch deleted file mode 100644 index bb6d05fc7..000000000 --- a/benchmarks/rt-tests/0001-rt-tests-cyclictest-Port-for-NuttX.patch +++ /dev/null @@ -1,43 +0,0 @@ -From cbd7831e20f387a35e94a50b95e0b8db5c5e63dd Mon Sep 17 00:00:00 2001 -From: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com> -Date: Mon, 8 Jul 2024 10:43:14 +0800 -Subject: [PATCH] rt-tests/cyclictest: Port for NuttX - -VELAPLATFO-37815 - -This patch ports cyclictest for NuttX. - -Change-Id: I918da053887aaba78910e230db0169239dba3b73 -Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com> ---- - src/cyclictest/cyclictest.c | 6 +++++- - 1 file changed, 5 insertions(+), 1 deletion(-) - -diff --git a/src/cyclictest/cyclictest.c b/src/cyclictest/cyclictest.c -index c5c3389..0edb684 100644 ---- a/src/cyclictest/cyclictest.c -+++ b/src/cyclictest/cyclictest.c -@@ -847,7 +847,11 @@ static void display_help(int error) - static int use_nanosleep = MODE_CLOCK_NANOSLEEP; - static int timermode = TIMER_ABSTIME; - static int use_system; -+#ifdef RTTESTS_PRIORITY -+static int priority = RTTESTS_PRIORITY; -+#else - static int priority; -+#endif - static int policy = SCHED_OTHER; /* default policy if not specified */ - static int num_threads = 1; - static int max_cycles; -@@ -1224,7 +1228,7 @@ static void process_options(int argc, char *argv[], int max_cpus) - if (distance == -1) - distance = DEFAULT_DISTANCE; - -- if (priority < 0 || priority > 99) -+ if (priority < 0 || priority > 255) - error = 1; - - if (num_threads == -1) --- -2.34.1 - diff --git a/benchmarks/rt-tests/CMakeLists.txt b/benchmarks/rt-tests/CMakeLists.txt deleted file mode 100644 index 9d7e9213f..000000000 --- a/benchmarks/rt-tests/CMakeLists.txt +++ /dev/null @@ -1,86 +0,0 @@ -############################################################################ -# apps/benchmarks/rt-tests/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -if(CONFIG_BENCHMARK_RTTESTS) - - if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/rt-tests/.git) - set(RTTESTS_URL - "https://git.kernel.org/pub/scm/utils/rt-tests/rt-tests.git") - set(RTTESTS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/rt-tests) - - execute_process( - COMMAND git clone ${RTTESTS_URL} ${RTTESTS_DIR} - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - RESULT_VARIABLE GIT_CLONE_RESULT) - - if(NOT ${GIT_CLONE_RESULT} EQUAL 0) - message(FATAL_ERROR "Failed to clone rt-tests repository") - endif() - - execute_process( - COMMAND cd ${RTTESTS_DIR} && git checkout -q ${RTTESTS_VERSION} && patch - -p1 < ../0001-rt-tests-cyclictest-Port-for-NuttX.patch - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) - - add_custom_target(distclean COMMAND ${CMAKE_COMMAND} -E remove_directory - ${RTTESTS_DIR}) - endif() - - list( - APPEND - SRCS - rt-tests/src/cyclictest/cyclictest.c - rt-tests/src/lib/rt-error.c - rt-tests/src/lib/histogram.c - rt-tests/src/lib/rt-utils.c - rt-tests/src/lib/rt-numa.c) - - list( - APPEND - CFLAGS - -Irt-tests/src/include - -I. - -DVERSION=0.1 - -DSYS_gettid=0 - -Dgettid=rttest_gettid - -D'syscall - (x) - = - ((pid_t) (x)) - ' - -w - -DRTTESTS_PRIORITY=${CONFIG_BENCHMARK_RTTESTS_PRIORITY}+1) - - nuttx_add_application( - NAME - cyclictest - PRIORITY - ${CONFIG_BENCHMARK_RTTESTS_PRIORITY} - STACKSIZE - ${CONFIG_BENCHMARK_RTTESTS_STACKSIZE} - MODULE - ${CONFIG_BENCHMARK_RTTESTS} - COMPILE_FLAGS - ${CFLAGS} - SRCS - ${SRCS}) -endif() diff --git a/benchmarks/rt-tests/Kconfig b/benchmarks/rt-tests/Kconfig deleted file mode 100644 index 40650deb0..000000000 --- a/benchmarks/rt-tests/Kconfig +++ /dev/null @@ -1,23 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config BENCHMARK_RTTESTS - tristate "RT-Tests" - default n - depends on PIPES && ALLOW_GPL_COMPONENTS - ---help--- - Measure the timer jitter - -if BENCHMARK_RTTESTS - -config BENCHMARK_RTTESTS_PRIORITY - int "RT-Tests task priority" - default 200 - -config BENCHMARK_RTTESTS_STACKSIZE - int "RT-Tests stack size" - default DEFAULT_TASK_STACKSIZE - -endif diff --git a/benchmarks/rt-tests/Make.defs b/benchmarks/rt-tests/Make.defs deleted file mode 100644 index 7c9c5849c..000000000 --- a/benchmarks/rt-tests/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/benchmarks/rt-tests/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_BENCHMARK_RTTESTS),) -CONFIGURED_APPS += $(APPDIR)/benchmarks/rt-tests -endif diff --git a/benchmarks/rt-tests/Makefile b/benchmarks/rt-tests/Makefile deleted file mode 100644 index 5497d732e..000000000 --- a/benchmarks/rt-tests/Makefile +++ /dev/null @@ -1,65 +0,0 @@ -############################################################################ -# apps/benchmarks/rt-tests/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -############################################################################ -# Targets -############################################################################ - - -include $(APPDIR)/Make.defs - -PROGNAME = cyclictest -PRIORITY = $(CONFIG_BENCHMARK_RTTESTS_PRIORITY) -STACKSIZE = $(CONFIG_BENCHMARK_RTTESTS_STACKSIZE) -MODULE = $(CONFIG_BENCHMARK_RTTESTS) - -RTTESTS_PATH = $(APPDIR)/benchmarks/rt-tests/rt-tests -RTTESTS_URL = https://git.kernel.org/pub/scm/utils/rt-tests/rt-tests.git -RTTESTS_VERSION = cadd661f984c0e6717e681fdaca1ce589b0ed964 -RTTESTS_GIT = rt-tests - -ifeq ($(wildcard rt-tests/.git),) -rt-tests: - @echo "Git Cloning: $(RTTESTS_URL)" - $(Q) git clone $(RTTESTS_URL) - @echo "Checkout commit: $(RTTESTS_VERSION)" - $(Q) cd $(RTTESTS_PATH) && \ - git checkout -q $(RTTESTS_VERSION) - @echo "Patching: Applying patch" - $(Q) cd $(RTTESTS_PATH) && \ - patch -p1 < ../0001-rt-tests-cyclictest-Port-for-NuttX.patch - -context:: rt-tests -endif - -distclean:: - $(call DELDIR, $(RTTESTS_GIT)) - -MAINSRC = rt-tests/src/cyclictest/cyclictest.c -CSRCS = rt-tests/src/lib/rt-error.c rt-tests/src/lib/histogram.c -CSRCS += rt-tests/src/lib/rt-utils.c rt-tests/src/lib/rt-numa.c - -CFLAGS += -Irt-tests/src/include -I. -DVERSION=0.1 -CFLAGS += -DSYS_gettid=0 -Dgettid=rttest_gettid -D'syscall(x)=((pid_t)(x))' -CFLAGS += -w -DRTTESTS_PRIORITY=$(CONFIG_BENCHMARK_RTTESTS_PRIORITY)+1 - -include $(APPDIR)/Application.mk diff --git a/benchmarks/rt-tests/numa.h b/benchmarks/rt-tests/numa.h deleted file mode 100644 index 6938e9eb9..000000000 --- a/benchmarks/rt-tests/numa.h +++ /dev/null @@ -1,102 +0,0 @@ -/**************************************************************************** - * apps/benchmarks/rt-tests/numa.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __NUMA_H__ -#define __NUMA_H__ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <strings.h> - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define CACHE_LINESIZE (64) -#define numa_run_on_node(...) (-1) -#define numa_node_of_cpu(...) (-1) -#define numa_alloc_onnode(size, node) memalign(CACHE_LINESIZE, size) -#define numa_free(ptr, size) free(ptr) -#define numa_available() (-1) - -struct bitmask -{ - unsigned long size; /* number of bits in the map */ - unsigned long *maskp; -}; - -static inline -struct bitmask *numa_allocate_cpumask(void) -{ - return NULL; -} - -static inline void numa_bitmask_free(struct bitmask *mask) -{ - return; -} - -static inline int numa_sched_getaffinity(pid_t pid, struct bitmask *mask) -{ - return -1; -} - -static inline -unsigned int numa_bitmask_isbitset(const struct bitmask *mask, - unsigned int idx) -{ - return mask->maskp[idx / sizeof(unsigned long)] & - ((unsigned long)1 << (idx % sizeof(unsigned long))); -} - -static inline -struct bitmask *numa_bitmask_clearbit(struct bitmask *mask, - unsigned int idx) -{ - mask->maskp[idx / sizeof(unsigned long)] &= - ~((unsigned long)1 << (idx % sizeof(unsigned long))); - return mask; -} - -static inline -struct bitmask *numa_parse_cpustring_all(const char *s) -{ - return NULL; -} - -static inline -unsigned int numa_bitmask_weight(const struct bitmask *bitmap) -{ - unsigned int idx; - unsigned int ret = 0; - for (idx = 0; idx < bitmap->size / sizeof(unsigned long); idx++) - { - ret += popcountl(bitmap->maskp[idx]); - } - return ret; -} - -#define numa_sched_setaffinity(...) (-1) - -#endif diff --git a/benchmarks/sd_bench/Kconfig b/benchmarks/sd_bench/Kconfig deleted file mode 100644 index 440e17064..000000000 --- a/benchmarks/sd_bench/Kconfig +++ /dev/null @@ -1,40 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config BENCHMARK_SD_BENCH - tristate "SD benchmark program" - depends on ALLOW_BSD_COMPONENTS - default n - ---help--- - SD benchmark application based on https://github.com/PX4/PX4-Autopilot/blob/main/src/systemcmds/sd_bench/sd_bench.cpp - -if BENCHMARK_SD_BENCH - -config BENCHMARK_SD_BENCH_PROGNAME - string "Program name" - default "sdbench" - ---help--- - This is the name of the program that will be used when the NSH ELF - program is installed. - -config BENCHMARK_SD_BENCH_PRIORITY - int "SD bench task priority" - default 100 - -config BENCHMARK_SD_BENCH_STACKSIZE - int "SD bench stack size" - default DEFAULT_TASK_STACKSIZE - -config BENCHMARK_SD_BENCH_DEVICE - string "SD / MMC mount point" - default "/mnt" - -config TESTING_SD_MEM_ALIGN_BYTES - int "Allocated memory alignment" - ---help--- - Specifies the memory alignment (bytes) used for allocated buffers, when enabled with the -a argument. - default 512 - -endif diff --git a/benchmarks/sd_bench/Make.defs b/benchmarks/sd_bench/Make.defs deleted file mode 100644 index cb9a03819..000000000 --- a/benchmarks/sd_bench/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/benchmarks/sd_bench/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_BENCHMARK_SD_BENCH),) -CONFIGURED_APPS += $(APPDIR)/benchmarks/sd_bench -endif diff --git a/benchmarks/sd_bench/Makefile b/benchmarks/sd_bench/Makefile deleted file mode 100644 index 072a87c2e..000000000 --- a/benchmarks/sd_bench/Makefile +++ /dev/null @@ -1,32 +0,0 @@ -############################################################################ -# apps/benchmarks/sd_bench/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -PROGNAME = $(CONFIG_BENCHMARK_SD_BENCH_PROGNAME) -PRIORITY = $(CONFIG_BENCHMARK_SD_BENCH_PRIORITY) -STACKSIZE = $(CONFIG_BENCHMARK_SD_BENCH_STACKSIZE) -MODULE = $(CONFIG_BENCHMARK_SD_BENCH) - -MAINSRC = sd_bench_main.c - -include $(APPDIR)/Application.mk diff --git a/benchmarks/sd_bench/sd_bench_main.c b/benchmarks/sd_bench/sd_bench_main.c deleted file mode 100644 index 9822ac748..000000000 --- a/benchmarks/sd_bench/sd_bench_main.c +++ /dev/null @@ -1,505 +0,0 @@ -/**************************************************************************** - * apps/benchmarks/sd_bench/sd_bench_main.c - * - * SPDX-License-Identifier: BSD-3-Clause - * SPDX-FileCopyrightText: 2016-2021 PX4 Development Team. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name PX4 nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/* Originally ported from PX4 https://github.com/PX4/PX4-Autopilot, - * with the following additions: - * - * - Refactoring for NuttX code style. - * - Test result output has been modified to display total MB written. - */ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <errno.h> -#include <fcntl.h> -#include <stddef.h> -#include <stdint.h> -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> - -#include <nuttx/clock.h> - -/**************************************************************************** - * Private Definitions - ****************************************************************************/ - -#define BUFFER_ALIGN CONFIG_TESTING_SD_MEM_ALIGN_BYTES -/**************************************************************************** - * Private Types - ****************************************************************************/ - -typedef struct sdb_config -{ - int num_runs; - int run_duration; - bool synchronized; - bool aligned; - size_t total_blocks_written; -} sdb_config_t; - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static const char *BENCHMARK_FILE = - CONFIG_BENCHMARK_SD_BENCH_DEVICE "/sd_bench"; - -static const size_t max_block = 65536; -static const size_t min_block = 1; -static const size_t default_block = 512; - -static const size_t max_runs = 10000; -static const size_t min_runs = 1; -static const size_t default_runs = 5; - -static const size_t max_duration = 60000; -static const size_t min_duration = 1; -static const size_t default_duration = 2000; - -static const bool default_keep_test = false; -static const bool default_fsync = false; -static const bool default_verify = true; -static const bool default_aligned = false; - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -static void write_test(int fd, sdb_config_t *cfg, uint8_t *block, - int block_size); -static int read_test(int fd, sdb_config_t *cfg, uint8_t *block, - int block_size); - -static uint64_t time_fsync_us(int fd); -static struct timespec get_abs_time(void); -static uint64_t get_elapsed_time_us(const struct timespec *start); -static uint64_t time_fsync_us(int fd); -static float ts_to_kb(uint64_t bytes, uint64_t elapsed); -static float block_count_to_mb(size_t blocks, size_t block_size); -static const char *print_bool(const bool value); -static void usage(void); - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static struct timespec get_abs_time(void) -{ - struct timespec ts; - clock_gettime(CLOCK_MONOTONIC, &ts); - return ts; -} - -static uint64_t get_time_delta_us(const struct timespec *start, - const struct timespec *end) -{ - uint64_t elapsed; - elapsed = (end->tv_sec * NSEC_PER_SEC) + end->tv_nsec; - elapsed -= (start->tv_sec * NSEC_PER_SEC) + start->tv_nsec; - return elapsed / 1000.; -} - -static uint64_t get_elapsed_time_us(const struct timespec *start) -{ - struct timespec now = get_abs_time(); - return get_time_delta_us(start, &now); -} - -static uint64_t time_fsync_us(int fd) -{ - struct timespec start = get_abs_time(); - fsync(fd); - return get_elapsed_time_us(&start); -} - -static float ts_to_kb(uint64_t bytes, uint64_t elapsed) -{ - return (bytes / 1024.) / (elapsed / 1e6); -} - -static float block_count_to_mb(size_t blocks, size_t block_size) -{ - return blocks * block_size / (float)(1024 * 1024); -} - -static const char *print_bool(const bool value) -{ - return value ? "true" : "false"; -} - -static void write_test(int fd, sdb_config_t *cfg, uint8_t *block, - int block_size) -{ - struct timespec start; - struct timespec write_start; - size_t written; - size_t num_blocks; - uint64_t max_write_time; - uint64_t fsync_time; - uint64_t write_time; - uint64_t elapsed; - uint64_t total_elapsed = 0.; - size_t total_blocks = 0; - size_t *blocknumber = (size_t *)(void *)&block[0]; - - printf("\n"); - printf("Testing Sequential Write Speed...\n"); - - cfg->total_blocks_written = 0; - - for (int run = 0; run < cfg->num_runs; ++run) - { - start = get_abs_time(); - num_blocks = 0; - max_write_time = 0; - fsync_time = 0; - - while (get_elapsed_time_us(&start) < cfg->run_duration) - { - *blocknumber = total_blocks + num_blocks; - write_start = get_abs_time(); - written = write(fd, block, block_size); - write_time = get_elapsed_time_us(&write_start); - - if (write_time > max_write_time) - { - max_write_time = write_time; - } - - if ((int)written != block_size) - { - printf("Write error: %d\n", errno); - return; - } - - if (cfg->synchronized) - { - fsync_time += time_fsync_us(fd); - } - - ++num_blocks; - } - - /* Note: if testing a slow device (SD Card) and the OS buffers a lot, - * fsync can take really long, and it looks like the process hangs. - * But it does not and the reported result will still be correct. - */ - - if (!cfg->synchronized) - { - fsync_time += time_fsync_us(fd); - } - - elapsed = get_elapsed_time_us(&start); - printf(" Run %2i: %8.1f KB/s, max write time: %4.3f ms (%.1f KB/s), " - "fsync: %4.3f ms\n", run + 1, - ts_to_kb(block_size * num_blocks, elapsed), - max_write_time / 1.e3, - ts_to_kb(block_size, max_write_time), fsync_time / 1e3); - - total_elapsed += elapsed; - total_blocks += num_blocks; - } - - cfg->total_blocks_written = total_blocks; - printf(" Avg : %8.1f KB/s, %3.3f MB written.\n", - ts_to_kb(block_size * total_blocks, total_elapsed), - block_count_to_mb(total_blocks, block_size)); -} - -static int read_test(int fd, sdb_config_t *cfg, uint8_t *block, - int block_size) -{ - uint8_t *read_block; - uint64_t total_elapsed; - size_t total_blocks; - struct timespec start; - size_t num_blocks; - uint64_t max_read_time; - uint64_t read_time; - uint64_t elapsed; - struct timespec read_start; - size_t nread; - - printf("\n"); - printf("Testing Sequential Read Speed...\n"); - - if (cfg->aligned) - { - read_block = (uint8_t *)memalign(BUFFER_ALIGN, block_size); - } - else - { - read_block = (uint8_t *)malloc(block_size); - } - - if (!read_block) - { - printf("Failed to allocate memory block\n"); - return -1; - } - - total_elapsed = 0.; - total_blocks = 0; - size_t *blocknumber = (size_t *)(void *) &read_block[0]; - - for (int run = 0; run < cfg->num_runs; ++run) - { - start = get_abs_time(); - num_blocks = 0; - max_read_time = 0; - - while (get_elapsed_time_us(&start) < cfg->run_duration - && total_blocks + num_blocks < cfg->total_blocks_written) - { - read_start = get_abs_time(); - nread = read(fd, read_block, block_size); - read_time = get_elapsed_time_us(&read_start); - - if (read_time > max_read_time) - { - max_read_time = read_time; - } - - if ((int)nread != block_size) - { - printf("Read error\n"); - free(read_block); - return -1; - } - - if (*blocknumber != total_blocks + num_blocks) - { - printf("Read data error at block: %zu wrote:0x%04zx " - "read:0x%04zx", total_blocks + num_blocks, - total_blocks + num_blocks, *blocknumber); - } - - for (unsigned int i = sizeof(*blocknumber); - i < (block_size - sizeof(*blocknumber)); ++i) - { - if (block[i] != read_block[i]) - { - printf("Read data error at offset: %zu wrote:0x%02x " - "read:0x%02x", total_blocks + num_blocks + i, - block[i], read_block[i]); - } - } - - ++num_blocks; - } - - elapsed = get_elapsed_time_us(&start); - - if (num_blocks) - { - printf(" Run %2i: %8.1f KB/s, max read/verify time: %3.4f ms " - "(%.1f KB/s)\n", run + 1, - ts_to_kb(block_size * num_blocks, elapsed), - max_read_time / 1e3, - ts_to_kb(block_size, max_read_time)); - - total_elapsed += elapsed; - total_blocks += num_blocks; - } - } - - printf(" Avg : %8.1f KB/s, %3.3f MB and verified\n", - ts_to_kb(block_size * total_blocks, total_elapsed), - block_count_to_mb(total_blocks, block_size)); - - free(read_block); - return 0; -} - -static void usage(void) -{ - printf("Test the speed of an SD card or mount point\n"); - printf(CONFIG_BENCHMARK_SD_BENCH_PROGNAME - ": [-b] [-r] [-d] [-k] [-s] [-a] [-v]\n"); - printf(" -b Block size per write (%zu-%zu), default %zu\n", - min_block, max_block, default_block); - printf(" -r Number of runs (%zu-%zu), default %zu\n", - min_runs, max_runs, default_runs); - printf(" -d Max duration of a test (ms) (%zu-%zu), default %zu\n", - min_duration, max_duration, default_duration); - printf(" -k Keep test file when finished, default %s\n", - print_bool(default_keep_test)); - printf(" -s Call fsync after each block, false calls fsync\n" - " only at the end of each run, default %s\n", - print_bool(default_fsync)); - printf(" -a Test performance on aligned data, default %s\n", - print_bool(default_aligned)); - printf(" -v Verify data and block number, default %s\n", - print_bool(default_verify)); -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -int main(int argc, char *argv[]) -{ - size_t block_size = default_block; - bool verify = default_verify; - bool keep = default_keep_test; - int ch; - int bench_fd; - sdb_config_t cfg; - uint8_t *block = NULL; - - cfg.synchronized = default_fsync; - cfg.num_runs = default_runs; - cfg.run_duration = default_duration; - cfg.aligned = default_aligned; - - while ((ch = getopt(argc, argv, "b:r:d:ksav")) != EOF) - { - switch (ch) - { - case 'b': - block_size = strtol(optarg, NULL, 0); - break; - - case 'r': - cfg.num_runs = strtol(optarg, NULL, 0); - break; - - case 'd': - cfg.run_duration = strtol(optarg, NULL, 0); - break; - - case 'k': - keep = !default_keep_test; - break; - - case 's': - cfg.synchronized = !default_fsync; - break; - - case 'a': - cfg.aligned = !default_aligned; - break; - - case 'v': - verify = !default_verify; - break; - - default: - usage(); - return -1; - break; - } - } - - if (cfg.run_duration > max_duration || cfg.run_duration < min_duration) - { - printf("Duration outside of allowable range.\n"); - usage(); - exit(EXIT_FAILURE); - } - - if (block_size > max_block || block_size < min_block) - { - printf("Bytes outside allowable range.\n"); - usage(); - exit(EXIT_FAILURE); - } - - if (cfg.num_runs > max_runs || cfg.num_runs < min_runs) - { - printf("Runs outside allowable range.\n"); - usage(); - exit(EXIT_FAILURE); - } - - cfg.run_duration *= 1000; - bench_fd = open(BENCHMARK_FILE, - O_CREAT | (verify ? O_RDWR : O_WRONLY) | O_TRUNC, 0666); - - if (bench_fd < 0) - { - printf("Can't open benchmark file %s (%d)\n", - BENCHMARK_FILE, bench_fd); - exit(EXIT_FAILURE); - } - - if (cfg.aligned) - { - block = (uint8_t *)memalign(BUFFER_ALIGN, block_size); - } - else - { - block = (uint8_t *)malloc(block_size); - } - - if (!block) - { - printf("Failed to allocate memory block\n"); - close(bench_fd); - exit(EXIT_FAILURE); - } - - for (int j = 0; j < block_size; ++j) - { - block[j] = (uint8_t)j; - } - - printf("Using block size = %zu bytes, sync = %s\n", block_size, - print_bool(cfg.synchronized)); - - write_test(bench_fd, &cfg, block, block_size); - - if (verify) - { - fsync(bench_fd); - lseek(bench_fd, 0, SEEK_SET); - read_test(bench_fd, &cfg, block, block_size); - } - - free(block); - close(bench_fd); - - if (!keep) - { - unlink(BENCHMARK_FILE); - } - - return 0; -} diff --git a/benchmarks/spinlock_bench/CMakeLists.txt b/benchmarks/spinlock_bench/CMakeLists.txt deleted file mode 100644 index 80ed3afe0..000000000 --- a/benchmarks/spinlock_bench/CMakeLists.txt +++ /dev/null @@ -1,57 +0,0 @@ -# ############################################################################## -# apps/benchmarks/spinlock_bench/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_BENCHMARK_SPINLOCK) - - # ############################################################################ - # Config and Fetch Coremark application - # ############################################################################ - - set(SPINLOCKAPP_DIR ${CMAKE_CURRENT_LIST_DIR}) - - # ############################################################################ - # Sources - # ############################################################################ - - set(CSRCS ${SPINLOCKAPP_DIR}/spinlock_bench.c) - - # ############################################################################ - # Applications Configuration - # ############################################################################ - - nuttx_add_application( - NAME - spinlock_bench - PRIORITY - ${CONFIG_SPINLOCK_PRIORITY} - STACKSIZE - ${CONFIG_SPINLOCK_STACKSIZE} - MODULE - ${CONFIG_BENCHMARK_SPINLOCK} - COMPILE_FLAGS - ${CFLAGS} - SRCS - ${CSRCS} - INCLUDE_DIRECTORIES - ${INCDIR}) - -endif() diff --git a/benchmarks/spinlock_bench/Kconfig b/benchmarks/spinlock_bench/Kconfig deleted file mode 100644 index b872f5e84..000000000 --- a/benchmarks/spinlock_bench/Kconfig +++ /dev/null @@ -1,45 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -menuconfig BENCHMARK_SPINLOCK - bool "Spinlock Benchmark" - depends on BUILD_FLAT - default n - ---help--- - Enable the Spinlock benchmark application. - -if BENCHMARK_SPINLOCK - -config SPINLOCK_PROGNAME - string "spinlock benchmark" - default "spinlock_bench" - ---help--- - This is the name of the program that will be used when the NSH ELF - program is installed. - -config SPINLOCK_PRIORITY - int "Spinlock task priority" - default 100 - -config SPINLOCK_STACKSIZE - int "Spinlock task stack size" - default 4096 - - -config SPINLOCK_MULTITHREAD - int "Number of threads" - default 40 - ---help--- - Override the default number of threads to be executed. - The default value is 40. - -config SPINLOCK_ITERATIONS - int "Number of iterations" - default 100 - ---help--- - Default number of iterations for the benchmark on each thread. - The default value is 100. - -endif # BENCHMARK_SPINLOCK diff --git a/benchmarks/spinlock_bench/Make.defs b/benchmarks/spinlock_bench/Make.defs deleted file mode 100644 index 6031b9eff..000000000 --- a/benchmarks/spinlock_bench/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/benchmarks/spinlock_bench/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_BENCHMARK_SPINLOCK),) -CONFIGURED_APPS += $(APPDIR)/benchmarks/spinlock_bench -endif diff --git a/benchmarks/spinlock_bench/Makefile b/benchmarks/spinlock_bench/Makefile deleted file mode 100644 index e1a3f86c6..000000000 --- a/benchmarks/spinlock_bench/Makefile +++ /dev/null @@ -1,41 +0,0 @@ -############################################################################ -# apps/benchmarks/spinlock_bench/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -# spinlock_bench application - -############################################################################ -# Applications Configuration -############################################################################ - -MODULE = $(CONFIG_BENCHMARK_SPINLOCK) - -PROGNAME += $(CONFIG_SPINLOCK_PROGNAME) -PRIORITY += $(CONFIG_SPINLOCK_PRIORITY) -STACKSIZE += $(CONFIG_SPINLOCK_STACKSIZE) - -MAINSRC += spinlock_bench.c - -# Build with WebAssembly when CONFIG_INTERPRETERS_WAMR is enabled - -include $(APPDIR)/Application.mk diff --git a/benchmarks/spinlock_bench/spinlock_bench.c b/benchmarks/spinlock_bench/spinlock_bench.c deleted file mode 100644 index bc8c8b5ed..000000000 --- a/benchmarks/spinlock_bench/spinlock_bench.c +++ /dev/null @@ -1,112 +0,0 @@ -/**************************************************************************** - * apps/benchmarks/spinlock_bench/spinlock_bench.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <stdio.h> -#include <assert.h> -#include <errno.h> -#include <nuttx/spinlock.h> -#include <time.h> - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define TEST_NUM CONFIG_SPINLOCK_MULTITHREAD -#define THREAD_NUM CONFIG_SPINLOCK_MULTITHREAD - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -struct thread_parmeter_s -{ - FAR int *result; - FAR spinlock_t *lock; -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static FAR void *thread_spinlock(FAR void *parameter) -{ - FAR int *result = ((FAR struct thread_parmeter_s *)parameter)->result; - FAR spinlock_t *lock = ((FAR struct thread_parmeter_s *)parameter)->lock; - - int i; - - for (i = 0; i < TEST_NUM; i++) - { - spin_lock(lock); - (*result)++; - spin_unlock(lock); - } - - return NULL; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -void main(void) -{ - spinlock_t lock = SP_UNLOCKED; - int result = 0; - pthread_t thread[THREAD_NUM]; - struct thread_parmeter_s para; - clock_t start; - clock_t end; - - int status; - int i; - - para.result = &result; - para.lock = &lock; - - start = perf_gettime(); - for (i = 0; i < THREAD_NUM; ++i) - { - status = pthread_create(&thread[i], NULL, - thread_spinlock, ¶); - if (status != 0) - { - printf("spinlock_test: ERROR pthread_create failed, status=%d\n", - status); - ASSERT(false); - } - } - - for (i = 0; i < THREAD_NUM; ++i) - { - pthread_join(thread[i], NULL); - } - - end = perf_gettime(); - assert(result == THREAD_NUM * TEST_NUM); - - printf("total_time: %lu\n", end - start); -} diff --git a/benchmarks/superpi/.gitignore b/benchmarks/superpi/.gitignore deleted file mode 100644 index 06dd2c632..000000000 --- a/benchmarks/superpi/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/superpi -/main.zip diff --git a/benchmarks/superpi/CMakeLists.txt b/benchmarks/superpi/CMakeLists.txt deleted file mode 100644 index 7ab8ed611..000000000 --- a/benchmarks/superpi/CMakeLists.txt +++ /dev/null @@ -1,56 +0,0 @@ -# ############################################################################## -# apps/benchmarks/superpi/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_BENCHMARK_SUPERPI) - - set(SUPERPI_UNPACK ${CMAKE_CURRENT_LIST_DIR}/superpi) - set(SUPERPI_URL https://github.com/Fibonacci43/SuperPI/archive) - set(SUPERPI_ZIP main.zip) - - if(NOT EXISTS ${SUPERPI_UNPACK}) - - FetchContent_Declare( - superpi_fetch - URL ${SUPERPI_URL}/${SUPERPI_ZIP} SOURCE_DIR ${SUPERPI_UNPACK} BINARY_DIR - ${CMAKE_BINARY_DIR}/apps/benchmarks/superpi/superpi - DOWNLOAD_NO_PROGRESS true - TIMEOUT 30) - - FetchContent_GetProperties(superpi_fetch) - if(NOT superpi_fetch_POPULATED) - FetchContent_Populate(superpi_fetch) - endif() - - endif() - - nuttx_add_application( - NAME - ${CONFIG_BENCHMARK_SUPERPI_PROGNAME} - STACKSIZE - ${CONFIG_BENCHMARK_SUPERPI_STACKSIZE} - PRIORITY - ${CONFIG_BENCHMARK_SUPERPI_PRIORITY} - SRCS - ${SUPERPI_UNPACK}/pi_fftcs.c - ${SUPERPI_UNPACK}/fftsg_h.c) - -endif() diff --git a/benchmarks/superpi/Kconfig b/benchmarks/superpi/Kconfig deleted file mode 100644 index 124f334f7..000000000 --- a/benchmarks/superpi/Kconfig +++ /dev/null @@ -1,26 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config BENCHMARK_SUPERPI - tristate "SuperPI test" - default n - -if BENCHMARK_SUPERPI - -config BENCHMARK_SUPERPI_PROGNAME - string "Program Name" - default "pi_css5" - -config BENCHMARK_SUPERPI_STACKSIZE - int "SuperPI stack size" - default DEFAULT_TASK_STACKSIZE - -config BENCHMARK_SUPERPI_PRIORITY - int "Task PRIORITY" - default 100 - ---help--- - The higher the priority value, the lower the priority. - -endif # BENCHMARK_SUPERPI diff --git a/benchmarks/superpi/Make.defs b/benchmarks/superpi/Make.defs deleted file mode 100644 index a5c1095d4..000000000 --- a/benchmarks/superpi/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/benchmarks/superpi/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_BENCHMARK_SUPERPI),) -CONFIGURED_APPS += $(APPDIR)/benchmarks/superpi -endif diff --git a/benchmarks/superpi/Makefile b/benchmarks/superpi/Makefile deleted file mode 100644 index fbdb445d3..000000000 --- a/benchmarks/superpi/Makefile +++ /dev/null @@ -1,56 +0,0 @@ -############################################################################ -# apps/benchmarks/superpi/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -SUPERPI_UNPACK = superpi -SUPERPI_URL = https://github.com/Fibonacci43/SuperPI/archive -SUPERPI_VERSION = main -SUPERPI_ZIP = $(SUPERPI_VERSION).zip -UNPACK ?= unzip -q -o - -CSRCS += superpi/fftsg_h.c -PROGNAME = $(CONFIG_BENCHMARK_SUPERPI_PROGNAME) -PRIORITY = $(CONFIG_BENCHMARK_SUPERPI_PRIORITY) -STACKSIZE = $(CONFIG_BENCHMARK_SUPERPI_STACKSIZE) -MODULE = $(CONFIG_BENCHMARK_SUPERPI) -MAINSRC = superpi/pi_fftcs.c - -$(SUPERPI_ZIP): - @echo "Downloading: $(SUPERPI_URL)/$(SUPERPI_ZIP)" - $(Q) curl -O -L $(SUPERPI_URL)/$(SUPERPI_ZIP) - -$(SUPERPI_UNPACK): $(SUPERPI_ZIP) - @echo "Unpacking: $(SUPERPI_ZIP) -> $(SUPERPI_UNPACK)" - $(Q) $(UNPACK) $(SUPERPI_ZIP) - $(Q) mv SuperPI-$(SUPERPI_VERSION) $(SUPERPI_UNPACK) - $(Q) touch $(SUPERPI_UNPACK) - -ifeq ($(wildcard $(SUPERPI_UNPACK)/.git),) -context:: $(SUPERPI_UNPACK) - -distclean:: - $(call DELDIR, $(SUPERPI_UNPACK)) - $(call DELFILE, $(SUPERPI_ZIP)) -endif - -include $(APPDIR)/Application.mk diff --git a/benchmarks/tacle-bench/.gitignore b/benchmarks/tacle-bench/.gitignore deleted file mode 100644 index 649ff84b9..000000000 --- a/benchmarks/tacle-bench/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/tacle-bench -/*.zip diff --git a/benchmarks/tacle-bench/0001-tacle-bench-add-makefile-and-all-in-one-main-file.patch b/benchmarks/tacle-bench/0001-tacle-bench-add-makefile-and-all-in-one-main-file.patch deleted file mode 100644 index fb1e2e400..000000000 --- a/benchmarks/tacle-bench/0001-tacle-bench-add-makefile-and-all-in-one-main-file.patch +++ /dev/null @@ -1,1264 +0,0 @@ -From 6d0be04a4b4208447e75c369e9811d089f466739 Mon Sep 17 00:00:00 2001 -From: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com> -Date: Thu, 3 Apr 2025 11:59:02 +0800 -Subject: [PATCH] tacle-bench: add makefile and all-in-one main file - -The original taclebench is used for WCET analysis. This commit allows most taclebench test cases (except parallel test cases) to be compiled and executed. - -Change-Id: I707b8ac58d3ddc4b7974c5bedecac1a7b5c887f9 -Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com> ---- - Makefile | 12 + - bench/app/lift/lift.c | 3 + - bench/app/powerwindow/powerwindow.c | 3 + - bench/kernel/binarysearch/binarysearch.c | 3 + - bench/kernel/bitcount/bitcount.c | 3 + - bench/kernel/bitonic/bitonic.c | 3 + - bench/kernel/bsort/bsort.c | 3 + - .../kernel/complex_updates/complex_updates.c | 3 + - bench/kernel/cosf/cosf.c | 3 + - bench/kernel/countnegative/countnegative.c | 3 + - bench/kernel/cubic/cubic.c | 3 + - bench/kernel/deg2rad/deg2rad.c | 3 + - bench/kernel/fac/fac.c | 3 + - bench/kernel/fft/fft.c | 3 + - bench/kernel/filterbank/filterbank.c | 3 + - bench/kernel/fir2dim/fir2dim.c | 3 + - bench/kernel/iir/iir.c | 3 + - bench/kernel/insertsort/insertsort.c | 3 + - bench/kernel/isqrt/isqrt.c | 3 + - bench/kernel/jfdctint/jfdctint.c | 3 + - bench/kernel/lms/lms.c | 3 + - bench/kernel/ludcmp/ludcmp.c | 3 + - bench/kernel/matrix1/matrix1.c | 3 + - bench/kernel/md5/md5.c | 3 + - bench/kernel/minver/minver.c | 3 + - bench/kernel/pm/pm.c | 3 + - bench/kernel/prime/prime.c | 3 + - bench/kernel/quicksort/quicksort.c | 3 + - bench/kernel/rad2deg/rad2deg.c | 3 + - bench/kernel/recursion/recursion.c | 3 + - bench/kernel/sha/sha.c | 3 + - bench/kernel/st/st.c | 3 + - bench/sequential/adpcm_dec/adpcm_dec.c | 3 + - bench/sequential/adpcm_enc/adpcm_enc.c | 3 + - bench/sequential/ammunition/ammunition.c | 3 + - bench/sequential/anagram/anagram.c | 3 + - bench/sequential/audiobeam/audiobeam.c | 3 + - .../cjpeg_transupp/cjpeg_transupp.c | 3 + - bench/sequential/cjpeg_wrbmp/cjpeg_wrbmp.c | 3 + - bench/sequential/dijkstra/dijkstra.c | 3 + - bench/sequential/epic/epic.c | 3 + - bench/sequential/fmref/fmref.c | 3 + - bench/sequential/g723_enc/g723_enc.c | 3 + - bench/sequential/gsm_dec/gsm_dec.c | 3 + - bench/sequential/gsm_enc/gsm_enc.c | 3 + - bench/sequential/h264_dec/h264_dec.c | 3 + - bench/sequential/huff_dec/huff_dec.c | 3 + - bench/sequential/huff_enc/huff_enc.c | 3 + - bench/sequential/mpeg2/mpeg2.c | 3 + - bench/sequential/ndes/ndes.c | 3 + - bench/sequential/petrinet/petrinet.c | 3 + - bench/sequential/rijndael_dec/rijndael_dec.c | 3 + - bench/sequential/rijndael_enc/rijndael_enc.c | 3 + - bench/sequential/statemate/statemate.c | 3 + - bench/sequential/susan/susan.c | 3 + - bench/test/cover/cover.c | 3 + - bench/test/duff/duff.c | 3 + - bench/test/test3/test3.c | 3 + - taclebench.c | 366 ++++++++++++++++++ - 59 files changed, 549 insertions(+) - create mode 100644 Makefile - create mode 100644 taclebench.c - -diff --git a/Makefile b/Makefile -new file mode 100644 -index 0000000..75ca0a1 ---- /dev/null -+++ b/Makefile -@@ -0,0 +1,12 @@ -+APP_SRCS := $(shell find bench/app -name "*.c") -+# we just need only one wcclibm -+KERNEL_SRCS := $(shell find bench/kernel -name "*.c" | grep -v -E 'wcclibm.c') -+SEQUENTIAL_SRCS := $(shell find bench/sequential -name "*.c") -+TEST_SRCS := $(shell find bench/test -name "*.c") -+ -+all: -+ cc -DALL_IN_ONE ${APP_SRCS} ${KERNEL_SRCS} ${SEQUENTIAL_SRCS} ${TEST_SRCS} bench/kernel/cosf/wcclibm.c taclebench.c -static -o taclebench -O3 -+ -+clean: -+ rm -f taclebench -+ -diff --git a/bench/app/lift/lift.c b/bench/app/lift/lift.c -index 8c7795f..47ddf4f 100755 ---- a/bench/app/lift/lift.c -+++ b/bench/app/lift/lift.c -@@ -123,6 +123,9 @@ void _Pragma( "entrypoint" ) lift_main() - } - - -+#ifdef ALL_IN_ONE -+ #define main main_lift -+#endif - int main( void ) - { - lift_init(); -diff --git a/bench/app/powerwindow/powerwindow.c b/bench/app/powerwindow/powerwindow.c -index 1976506..9ea2e50 100644 ---- a/bench/app/powerwindow/powerwindow.c -+++ b/bench/app/powerwindow/powerwindow.c -@@ -47,6 +47,9 @@ void powerwindow_Uint8inputarray_initialize( powerwindow_uint8_T *, - void powerwindow_init(); - void powerwindow_main(); - int powerwindow_return(); -+#ifdef ALL_IN_ONE -+ #define main main_powerwindow -+#endif - int main( void ); - - -diff --git a/bench/kernel/binarysearch/binarysearch.c b/bench/kernel/binarysearch/binarysearch.c -index c4087f5..69d1191 100755 ---- a/bench/kernel/binarysearch/binarysearch.c -+++ b/bench/kernel/binarysearch/binarysearch.c -@@ -41,6 +41,9 @@ void binarysearch_init( void ); - int binarysearch_return( void ); - int binarysearch_binary_search( int ); - void binarysearch_main( void ); -+#ifdef ALL_IN_ONE -+ #define main main_binarysearch -+#endif - int main( void ); - - -diff --git a/bench/kernel/bitcount/bitcount.c b/bench/kernel/bitcount/bitcount.c -index dfae600..3ec9ff6 100755 ---- a/bench/kernel/bitcount/bitcount.c -+++ b/bench/kernel/bitcount/bitcount.c -@@ -40,6 +40,9 @@ unsigned long bitcount_random( void ); - void bitcount_main(); - int bitcount_return(); - void bitcount_init(); -+#ifdef ALL_IN_ONE -+ #define main main_bitcount -+#endif - int main( void ); - - -diff --git a/bench/kernel/bitonic/bitonic.c b/bench/kernel/bitonic/bitonic.c -index 09bb484..2f1cf6b 100755 ---- a/bench/kernel/bitonic/bitonic.c -+++ b/bench/kernel/bitonic/bitonic.c -@@ -27,6 +27,9 @@ int bitonic_return( void ); - void bitonic_compare( int i, int j, int dir ); - void bitonic_merge( int lo, int cnt, int dir ); - void bitonic_sort( int lo, int cnt, int dir ); -+#ifdef ALL_IN_ONE -+ #define main main_bitonic -+#endif - int main( void ); - - -diff --git a/bench/kernel/bsort/bsort.c b/bench/kernel/bsort/bsort.c -index 8a8b640..4ea2889 100755 ---- a/bench/kernel/bsort/bsort.c -+++ b/bench/kernel/bsort/bsort.c -@@ -123,6 +123,9 @@ void _Pragma( "entrypoint" ) bsort_main( void ) - Main function - */ - -+#ifdef ALL_IN_ONE -+ #define main main_bsort -+#endif - int main( void ) - { - bsort_init(); -diff --git a/bench/kernel/complex_updates/complex_updates.c b/bench/kernel/complex_updates/complex_updates.c -index 91e3ae6..9f07dfd 100755 ---- a/bench/kernel/complex_updates/complex_updates.c -+++ b/bench/kernel/complex_updates/complex_updates.c -@@ -40,6 +40,9 @@ - void complex_updates_pin_down( float *pa, float *pb, float *pc, float *pd ); - void complex_updates_init( void ); - void complex_updates_main( void ); -+#ifdef ALL_IN_ONE -+ #define main main_complex_updates -+#endif - int main( void ); - - -diff --git a/bench/kernel/cosf/cosf.c b/bench/kernel/cosf/cosf.c -index b838546..392f7f9 100755 ---- a/bench/kernel/cosf/cosf.c -+++ b/bench/kernel/cosf/cosf.c -@@ -29,6 +29,9 @@ - void cosf_init( void ); - void cosf_main( void ); - int cosf_return( void ); -+#ifdef ALL_IN_ONE -+ #define main main_cosf -+#endif - int main( void ); - - -diff --git a/bench/kernel/countnegative/countnegative.c b/bench/kernel/countnegative/countnegative.c -index 5835cab..7bc2765 100755 ---- a/bench/kernel/countnegative/countnegative.c -+++ b/bench/kernel/countnegative/countnegative.c -@@ -39,6 +39,9 @@ void countnegative_init( void ); - int countnegative_return( void ); - void countnegative_sum( matrix ); - void countnegative_main( void ); -+#ifdef ALL_IN_ONE -+ #define main main_countnegative -+#endif - int main( void ); - - /* -diff --git a/bench/kernel/cubic/cubic.c b/bench/kernel/cubic/cubic.c -index f266394..b26177a 100755 ---- a/bench/kernel/cubic/cubic.c -+++ b/bench/kernel/cubic/cubic.c -@@ -39,6 +39,9 @@ void cubic_solveCubic( float a, float b, float c, float d, - void cubic_main( void ); - void cubic_init( void ); - int cubic_return( void ); -+#ifdef ALL_IN_ONE -+ #define main main_cubic -+#endif - int main( void ); - - -diff --git a/bench/kernel/deg2rad/deg2rad.c b/bench/kernel/deg2rad/deg2rad.c -index 5fc1817..3cd5f06 100755 ---- a/bench/kernel/deg2rad/deg2rad.c -+++ b/bench/kernel/deg2rad/deg2rad.c -@@ -32,6 +32,9 @@ - void deg2rad_init( void ); - void deg2rad_main( void ); - int deg2rad_return( void ); -+#ifdef ALL_IN_ONE -+ #define main main_deg2rad -+#endif - int main( void ); - - -diff --git a/bench/kernel/fac/fac.c b/bench/kernel/fac/fac.c -index 606b8d1..ba6e2c4 100755 ---- a/bench/kernel/fac/fac.c -+++ b/bench/kernel/fac/fac.c -@@ -27,6 +27,9 @@ int fac_fac( int n ); - void fac_init(); - int fac_return(); - void fac_main(); -+#ifdef ALL_IN_ONE -+ #define main main_fac -+#endif - int main( void ); - /* - Declaration of global variables -diff --git a/bench/kernel/fft/fft.c b/bench/kernel/fft/fft.c -index 7aff936..f9a30f1 100755 ---- a/bench/kernel/fft/fft.c -+++ b/bench/kernel/fft/fft.c -@@ -84,6 +84,9 @@ void fft_pin_down( int input_data[ ] ); - void fft_init( void ); - void fft_main( void ); - int fft_return( void ); -+#ifdef ALL_IN_ONE -+ #define main main_fft -+#endif - int main( void ); - - /* -diff --git a/bench/kernel/filterbank/filterbank.c b/bench/kernel/filterbank/filterbank.c -index c9ab6de..734336d 100755 ---- a/bench/kernel/filterbank/filterbank.c -+++ b/bench/kernel/filterbank/filterbank.c -@@ -161,6 +161,9 @@ void filterbank_core( float r[ 256 ], - Main function - */ - -+#ifdef ALL_IN_ONE -+ #define main main_filterbank -+#endif - int main( void ) - { - filterbank_init(); -diff --git a/bench/kernel/fir2dim/fir2dim.c b/bench/kernel/fir2dim/fir2dim.c -index 054c144..bc94886 100755 ---- a/bench/kernel/fir2dim/fir2dim.c -+++ b/bench/kernel/fir2dim/fir2dim.c -@@ -32,6 +32,9 @@ void fir2dim_pin_down( float *pimage, float *parray, float *pcoeff, - void fir2dim_init(); - int fir2dim_return(); - void fir2dim_main(); -+#ifdef ALL_IN_ONE -+ #define main main_fir2dim -+#endif - int main( void ); - - -diff --git a/bench/kernel/iir/iir.c b/bench/kernel/iir/iir.c -index 2f085bd..2245602 100755 ---- a/bench/kernel/iir/iir.c -+++ b/bench/kernel/iir/iir.c -@@ -55,6 +55,9 @@ - void iir_init( void ); - int iir_return( void ); - void iir_main( void ); -+#ifdef ALL_IN_ONE -+ #define main main_iir -+#endif - int main( void ); - - -diff --git a/bench/kernel/insertsort/insertsort.c b/bench/kernel/insertsort/insertsort.c -index 59d90a5..8ba006d 100755 ---- a/bench/kernel/insertsort/insertsort.c -+++ b/bench/kernel/insertsort/insertsort.c -@@ -35,6 +35,9 @@ void insertsort_initialize( unsigned int *array ); - void insertsort_init( void ); - int insertsort_return( void ); - void insertsort_main( void ); -+#ifdef ALL_IN_ONE -+ #define main main_insertsort -+#endif - int main( void ); - - /* -diff --git a/bench/kernel/isqrt/isqrt.c b/bench/kernel/isqrt/isqrt.c -index 82b7a72..71d32ba 100755 ---- a/bench/kernel/isqrt/isqrt.c -+++ b/bench/kernel/isqrt/isqrt.c -@@ -69,6 +69,9 @@ void isqrt_usqrt( unsigned long x, struct int_sqrt *q ); - void isqrt_init( void ); - void isqrt_main( void ); - int isqrt_return( void ); -+#ifdef ALL_IN_ONE -+ #define main main_isqrt -+#endif - int main( void ); - - -diff --git a/bench/kernel/jfdctint/jfdctint.c b/bench/kernel/jfdctint/jfdctint.c -index 0e2f4fb..9e65563 100755 ---- a/bench/kernel/jfdctint/jfdctint.c -+++ b/bench/kernel/jfdctint/jfdctint.c -@@ -101,6 +101,9 @@ - void jfdctint_init(); - int jfdctint_return(); - void jfdctint_main(); -+#ifdef ALL_IN_ONE -+ #define main main_jfdctint -+#endif - int main( void ); - - -diff --git a/bench/kernel/lms/lms.c b/bench/kernel/lms/lms.c -index 42b1929..c8d33c5 100755 ---- a/bench/kernel/lms/lms.c -+++ b/bench/kernel/lms/lms.c -@@ -194,6 +194,9 @@ int lms_return( void ) - } - - -+#ifdef ALL_IN_ONE -+ #define main main_lms -+#endif - int main() - { - lms_init(); -diff --git a/bench/kernel/ludcmp/ludcmp.c b/bench/kernel/ludcmp/ludcmp.c -index 6c9127b..9af3fc0 100755 ---- a/bench/kernel/ludcmp/ludcmp.c -+++ b/bench/kernel/ludcmp/ludcmp.c -@@ -35,6 +35,9 @@ void ludcmp_init( void ); - int ludcmp_return( void ); - int ludcmp_test( int n, double eps ); - void ludcmp_main( void ); -+#ifdef ALL_IN_ONE -+ #define main main_ludcmp -+#endif - int main( void ); - - double ludcmp_a[ 50 ][ 50 ], ludcmp_b[ 50 ], ludcmp_x[ 50 ]; -diff --git a/bench/kernel/matrix1/matrix1.c b/bench/kernel/matrix1/matrix1.c -index 2b23504..8d7e431 100755 ---- a/bench/kernel/matrix1/matrix1.c -+++ b/bench/kernel/matrix1/matrix1.c -@@ -72,6 +72,9 @@ - void matrix1_pin_down( int A[ ], int B[ ], int C[ ] ); - void matrix1_init( void ); - void matrix1_main( void ); -+#ifdef ALL_IN_ONE -+ #define main main_matrix1 -+#endif - int main( void ); - - -diff --git a/bench/kernel/md5/md5.c b/bench/kernel/md5/md5.c -index 09ab091..be2d270 100755 ---- a/bench/kernel/md5/md5.c -+++ b/bench/kernel/md5/md5.c -@@ -201,6 +201,9 @@ void md5_init( void ); - int md5_return( void ); - int md5_bytesNeeded; - -+#ifdef ALL_IN_ONE -+ #define main main_md5 -+#endif - int main( void ); - - unsigned char md5_PADDING[ 64 ] = { -diff --git a/bench/kernel/minver/minver.c b/bench/kernel/minver/minver.c -index f417d1f..30e975f 100755 ---- a/bench/kernel/minver/minver.c -+++ b/bench/kernel/minver/minver.c -@@ -36,6 +36,9 @@ double minver_fabs( double n ); - void minver_init(); - int minver_return(); - void minver_main(); -+#ifdef ALL_IN_ONE -+ #define main main_minver -+#endif - int main( void ); - - /* -diff --git a/bench/kernel/pm/pm.c b/bench/kernel/pm/pm.c -index c046800..fb42960 100755 ---- a/bench/kernel/pm/pm.c -+++ b/bench/kernel/pm/pm.c -@@ -734,6 +734,9 @@ int pm_kernel( pm_data_t *pmdata ) - Main function - */ - -+#ifdef ALL_IN_ONE -+ #define main main_pm -+#endif - int main( void ) - { - pm_init(); -diff --git a/bench/kernel/prime/prime.c b/bench/kernel/prime/prime.c -index b694a6f..a3f7f55 100755 ---- a/bench/kernel/prime/prime.c -+++ b/bench/kernel/prime/prime.c -@@ -32,6 +32,9 @@ void prime_initSeed(); - void prime_init (); - int prime_return (); - void prime_main (); -+#ifdef ALL_IN_ONE -+ #define main main_prime -+#endif - int main( void ); - - -diff --git a/bench/kernel/quicksort/quicksort.c b/bench/kernel/quicksort/quicksort.c -index 55b4c73..b46aeda 100755 ---- a/bench/kernel/quicksort/quicksort.c -+++ b/bench/kernel/quicksort/quicksort.c -@@ -40,6 +40,9 @@ int quicksort_return( void ); - void quicksort_str( char *, unsigned long, unsigned long ); - void quicksort_vec( char *, unsigned long, unsigned long ); - void quicksort_main( void ); -+#ifdef ALL_IN_ONE -+ #define main main_quicksort -+#endif - int main( void ); - - -diff --git a/bench/kernel/rad2deg/rad2deg.c b/bench/kernel/rad2deg/rad2deg.c -index 380fe8b..72f1e14 100755 ---- a/bench/kernel/rad2deg/rad2deg.c -+++ b/bench/kernel/rad2deg/rad2deg.c -@@ -33,6 +33,9 @@ - void rad2deg_init( void ); - void rad2deg_main( void ); - int rad2deg_return( void ); -+#ifdef ALL_IN_ONE -+ #define main main_rad2deg -+#endif - int main( void ); - - -diff --git a/bench/kernel/recursion/recursion.c b/bench/kernel/recursion/recursion.c -index f0e7edd..462dd5e 100755 ---- a/bench/kernel/recursion/recursion.c -+++ b/bench/kernel/recursion/recursion.c -@@ -32,6 +32,9 @@ int recursion_fib( int i ); - void recursion_main( void ); - void recursion_init( void ); - int recursion_return( void ); -+#ifdef ALL_IN_ONE -+ #define main main_recursion -+#endif - int main ( void ); - - -diff --git a/bench/kernel/sha/sha.c b/bench/kernel/sha/sha.c -index fc1559a..def3990 100755 ---- a/bench/kernel/sha/sha.c -+++ b/bench/kernel/sha/sha.c -@@ -215,6 +215,9 @@ int sha_return( void ) - return ( sum - 261944 != 0 ); - } - -+#ifdef ALL_IN_ONE -+ #define main main_sha -+#endif - int main ( void ) - { - sha_init(); -diff --git a/bench/kernel/st/st.c b/bench/kernel/st/st.c -index 8a716fe..c303945 100755 ---- a/bench/kernel/st/st.c -+++ b/bench/kernel/st/st.c -@@ -38,6 +38,9 @@ void st_calc_Sum_Mean( float *, float *, float * ); - void st_calc_Var_Stddev( float *, float, float *, float * ); - void st_calc_LinCorrCoef( float *, float *, float, float, float * ); - void st_main( void ); -+#ifdef ALL_IN_ONE -+ #define main main_st -+#endif - int main( void ); - - -diff --git a/bench/sequential/adpcm_dec/adpcm_dec.c b/bench/sequential/adpcm_dec/adpcm_dec.c -index 5284bfa..2a11ded 100755 ---- a/bench/sequential/adpcm_dec/adpcm_dec.c -+++ b/bench/sequential/adpcm_dec/adpcm_dec.c -@@ -54,6 +54,9 @@ int adpcm_dec_sin( int n ); - void adpcm_dec_init(); - int adpcm_dec_return(); - void adpcm_dec_main(); -+#ifdef ALL_IN_ONE -+ #define main main_adpcm_dec -+#endif - int main( void ); - - -diff --git a/bench/sequential/adpcm_enc/adpcm_enc.c b/bench/sequential/adpcm_enc/adpcm_enc.c -index 2f58d9a..540a81d 100755 ---- a/bench/sequential/adpcm_enc/adpcm_enc.c -+++ b/bench/sequential/adpcm_enc/adpcm_enc.c -@@ -57,6 +57,9 @@ int adpcm_enc_abs( int n ); - void adpcm_enc_init( void ); - void adpcm_enc_main( void ); - int adpcm_enc_return( void ); -+#ifdef ALL_IN_ONE -+ #define main main_adpcm_enc -+#endif - int main( void ); - - /* -diff --git a/bench/sequential/ammunition/ammunition.c b/bench/sequential/ammunition/ammunition.c -index ba5e4c7..f5e9d79 100755 ---- a/bench/sequential/ammunition/ammunition.c -+++ b/bench/sequential/ammunition/ammunition.c -@@ -42,6 +42,9 @@ int ammunition_arithm_test(); - void ammunition_init( void ); - int ammunition_return( void ); - void ammunition_main( void ); -+#ifdef ALL_IN_ONE -+ #define main main_ammunition -+#endif - int main( void ); - - -diff --git a/bench/sequential/anagram/anagram.c b/bench/sequential/anagram/anagram.c -index 90ee4a2..adaa715 100755 ---- a/bench/sequential/anagram/anagram.c -+++ b/bench/sequential/anagram/anagram.c -@@ -652,6 +652,9 @@ void _Pragma( "entrypoint" ) anagram_main( void ) - Main function - */ - -+#ifdef ALL_IN_ONE -+ #define main main_anagram -+#endif - int main( void ) - { - anagram_init(); -diff --git a/bench/sequential/audiobeam/audiobeam.c b/bench/sequential/audiobeam/audiobeam.c -index 3d7ee15..01ebd85 100755 ---- a/bench/sequential/audiobeam/audiobeam.c -+++ b/bench/sequential/audiobeam/audiobeam.c -@@ -34,6 +34,9 @@ - void audiobeam_init(); - int audiobeam_return(); - void audiobeam_main( void ); -+#ifdef ALL_IN_ONE -+ #define main main_audiobeam -+#endif - int main( void ); - void audiobeam_preprocess_delays( struct audiobeam_PreprocessedDelays - prep_delays[ ], float *delays ); -diff --git a/bench/sequential/cjpeg_transupp/cjpeg_transupp.c b/bench/sequential/cjpeg_transupp/cjpeg_transupp.c -index c37ab95..a016b8e 100755 ---- a/bench/sequential/cjpeg_transupp/cjpeg_transupp.c -+++ b/bench/sequential/cjpeg_transupp/cjpeg_transupp.c -@@ -46,6 +46,9 @@ void cjpeg_transupp_do_rot_180( j_compress_ptr ); - void cjpeg_transupp_do_rot_270( j_compress_ptr ); - void cjpeg_transupp_do_transverse( j_compress_ptr ); - void cjpeg_transupp_main( void ); -+#ifdef ALL_IN_ONE -+ #define main main_cjpeg_transupp -+#endif - int main( void ); - - -diff --git a/bench/sequential/cjpeg_wrbmp/cjpeg_wrbmp.c b/bench/sequential/cjpeg_wrbmp/cjpeg_wrbmp.c -index cb81d01..71b6835 100755 ---- a/bench/sequential/cjpeg_wrbmp/cjpeg_wrbmp.c -+++ b/bench/sequential/cjpeg_wrbmp/cjpeg_wrbmp.c -@@ -71,6 +71,9 @@ int cjpeg_wrbmp_putc_modified( int character ); - void cjpeg_wrbmp_init(); - void cjpeg_wrbmp_main(); - int cjpeg_wrbmp_return(); -+#ifdef ALL_IN_ONE -+ #define main main_cjpeg_wrbmp -+#endif - int main(); - - /* -diff --git a/bench/sequential/dijkstra/dijkstra.c b/bench/sequential/dijkstra/dijkstra.c -index 7437c42..f71357b 100755 ---- a/bench/sequential/dijkstra/dijkstra.c -+++ b/bench/sequential/dijkstra/dijkstra.c -@@ -63,6 +63,9 @@ void dijkstra_dequeue( int *node, int *dist, int *prev ); - int dijkstra_qcount( void ); - int dijkstra_find( int chStart, int chEnd ); - void dijkstra_main( void ); -+#ifdef ALL_IN_ONE -+ #define main main_dijkstra -+#endif - int main( void ); - - void dijkstra_init( void ) -diff --git a/bench/sequential/epic/epic.c b/bench/sequential/epic/epic.c -index dc781d4..a29d6fb 100755 ---- a/bench/sequential/epic/epic.c -+++ b/bench/sequential/epic/epic.c -@@ -590,6 +590,9 @@ void epic_internal_filter( float *image, int x_dim, int y_dim, float *filt, - void epic_reflect1( float *filt, int x_dim, int y_dim, int x_pos, int y_pos, - float *result, int f_or_e ); - void epic_main( void ); -+#ifdef ALL_IN_ONE -+ #define main main_epic -+#endif - int main( void ); - - -diff --git a/bench/sequential/fmref/fmref.c b/bench/sequential/fmref/fmref.c -index c1b0611..80f65f9 100755 ---- a/bench/sequential/fmref/fmref.c -+++ b/bench/sequential/fmref/fmref.c -@@ -72,6 +72,9 @@ int fmref_return( void ) - return 0; - } - -+#ifdef ALL_IN_ONE -+ #define main main_fmref -+#endif - int main( void ) - { - fmref_init(); -diff --git a/bench/sequential/g723_enc/g723_enc.c b/bench/sequential/g723_enc/g723_enc.c -index fa46af3..27fd1cb 100755 ---- a/bench/sequential/g723_enc/g723_enc.c -+++ b/bench/sequential/g723_enc/g723_enc.c -@@ -106,6 +106,9 @@ int g723_enc_pack_output( - void g723_enc_init(); - int g723_enc_return(); - void g723_enc_main(); -+#ifdef ALL_IN_ONE -+ #define main main_g723_enc -+#endif - int main( void ); - - /* -diff --git a/bench/sequential/gsm_dec/gsm_dec.c b/bench/sequential/gsm_dec/gsm_dec.c -index 5c6cafd..ecaee90 100755 ---- a/bench/sequential/gsm_dec/gsm_dec.c -+++ b/bench/sequential/gsm_dec/gsm_dec.c -@@ -110,6 +110,9 @@ void gsm_dec_Coefficients_27_39( word *LARpp_j_1, word *LARpp_j, word *LARp ); - gsm gsm_dec_create( void ); - void gsm_dec_init( void ); - void gsm_dec_main( void ); -+#ifdef ALL_IN_ONE -+ #define main main_gsm_dec -+#endif - int main( void ); - - /* add.c */ -diff --git a/bench/sequential/gsm_enc/gsm_enc.c b/bench/sequential/gsm_enc/gsm_enc.c -index 63ca392..85dc5c8 100755 ---- a/bench/sequential/gsm_enc/gsm_enc.c -+++ b/bench/sequential/gsm_enc/gsm_enc.c -@@ -2216,6 +2216,9 @@ void _Pragma( "entrypoint" ) gsm_enc_main( void ) - gsm_enc_gsmdata + i * sizeof( gsm_frame ) ); - } - -+#ifdef ALL_IN_ONE -+ #define main main_gsm_enc -+#endif - int main( void ) - { - gsm_enc_init(); -diff --git a/bench/sequential/h264_dec/h264_dec.c b/bench/sequential/h264_dec/h264_dec.c -index db2b022..a4f26d3 100755 ---- a/bench/sequential/h264_dec/h264_dec.c -+++ b/bench/sequential/h264_dec/h264_dec.c -@@ -36,6 +36,9 @@ void h264_dec_init (); - int h264_dec_return (); - void h264_dec_decode_one_macroblock( struct h264_dec_img_par *img ); - void h264_dec_main( void ); -+#ifdef ALL_IN_ONE -+ #define main main_h264_dec -+#endif - int main( void ); - - -diff --git a/bench/sequential/huff_dec/huff_dec.c b/bench/sequential/huff_dec/huff_dec.c -index 09e180c..f099760 100755 ---- a/bench/sequential/huff_dec/huff_dec.c -+++ b/bench/sequential/huff_dec/huff_dec.c -@@ -77,6 +77,9 @@ void huff_dec_read_header( t_bin_val codes_table[ 257 ] ); - huff_dec_t_tree *huff_dec_tree_encoding( t_bin_val codes_table[ 257 ], - huff_dec_t_tree heap[ 514 ] ); - void huff_dec_main( void ); -+#ifdef ALL_IN_ONE -+ #define main main_huff_dec -+#endif - int main( void ); - - -diff --git a/bench/sequential/huff_enc/huff_enc.c b/bench/sequential/huff_enc/huff_enc.c -index a2768dc..7e61011 100755 ---- a/bench/sequential/huff_enc/huff_enc.c -+++ b/bench/sequential/huff_enc/huff_enc.c -@@ -85,6 +85,9 @@ void huff_enc_encode_codes_table( huff_enc_t_tree *tree, - void huff_enc_create_codes_table( huff_enc_t_tree *tree, - huff_enc_t_bin_val codes_table[ 257 ] ); - void huff_enc_main(); -+#ifdef ALL_IN_ONE -+ #define main main_huff_enc -+#endif - int main( void ); - - -diff --git a/bench/sequential/mpeg2/mpeg2.c b/bench/sequential/mpeg2/mpeg2.c -index 62b8779..7d5cfbd 100755 ---- a/bench/sequential/mpeg2/mpeg2.c -+++ b/bench/sequential/mpeg2/mpeg2.c -@@ -90,6 +90,9 @@ int mpeg2_bdist2( unsigned char *, unsigned char *, unsigned char *, int, int, - int, int, int, int ); - int mpeg2_variance( unsigned char *, int ); - void mpeg2_main( void ); -+#ifdef ALL_IN_ONE -+ #define main main_mpeg2 -+#endif - int main( void ); - - -diff --git a/bench/sequential/ndes/ndes.c b/bench/sequential/ndes/ndes.c -index 1e3e7d3..b7438f9 100755 ---- a/bench/sequential/ndes/ndes.c -+++ b/bench/sequential/ndes/ndes.c -@@ -55,6 +55,9 @@ void ndes_ks( /*immense key, */int n, ndes_great *kn ); - void ndes_init( void ); - int ndes_return( void ); - void ndes_main( void ); -+#ifdef ALL_IN_ONE -+ #define main main_ndes -+#endif - int main( void ); - - /* -diff --git a/bench/sequential/petrinet/petrinet.c b/bench/sequential/petrinet/petrinet.c -index 99b0cda..56a7e1e 100755 ---- a/bench/sequential/petrinet/petrinet.c -+++ b/bench/sequential/petrinet/petrinet.c -@@ -41,6 +41,9 @@ int petrinet_main_iters_dummy_i = 0, - void petrinet_init( void ); - int petrinet_return( void ); - void petrinet_main( void ); -+#ifdef ALL_IN_ONE -+ #define main main_petrinet -+#endif - int main( void ); - - -diff --git a/bench/sequential/rijndael_dec/rijndael_dec.c b/bench/sequential/rijndael_dec/rijndael_dec.c -index fc065d1..a0ce4d5 100755 ---- a/bench/sequential/rijndael_dec/rijndael_dec.c -+++ b/bench/sequential/rijndael_dec/rijndael_dec.c -@@ -179,6 +179,9 @@ void _Pragma( "entrypoint" ) rijndael_dec_main( void ) - rijndael_dec_decfile( &rijndael_dec_fin, ctx ); - } - -+#ifdef ALL_IN_ONE -+ #define main main_rijndael_dec -+#endif - int main() - { - -diff --git a/bench/sequential/rijndael_enc/rijndael_enc.c b/bench/sequential/rijndael_enc/rijndael_enc.c -index eaa7183..72e9393 100755 ---- a/bench/sequential/rijndael_enc/rijndael_enc.c -+++ b/bench/sequential/rijndael_enc/rijndael_enc.c -@@ -222,6 +222,9 @@ void _Pragma( "entrypoint" ) rijndael_enc_main( void ) - rijndael_enc_encfile( &rijndael_enc_fin, ctx ); - } - -+#ifdef ALL_IN_ONE -+ #define main main_rijndael_enc -+#endif - int main( void ) - { - rijndael_enc_init(); -diff --git a/bench/sequential/statemate/statemate.c b/bench/sequential/statemate/statemate.c -index 1799905..b72a68d 100755 ---- a/bench/sequential/statemate/statemate.c -+++ b/bench/sequential/statemate/statemate.c -@@ -1269,6 +1269,9 @@ void _Pragma ( "entrypoint" ) statemate_main( void ) - } - - -+#ifdef ALL_IN_ONE -+ #define main main_statemate -+#endif - int main ( void ) - { - statemate_init(); -diff --git a/bench/sequential/susan/susan.c b/bench/sequential/susan/susan.c -index 676bf61..807be77 100755 ---- a/bench/sequential/susan/susan.c -+++ b/bench/sequential/susan/susan.c -@@ -2499,6 +2499,9 @@ int susan_return( void ) - return 0; - } - -+#ifdef ALL_IN_ONE -+ #define main main_susan -+#endif - int main( void ) - { - susan_init(); -diff --git a/bench/test/cover/cover.c b/bench/test/cover/cover.c -index 051fa91..6c5153f 100755 ---- a/bench/test/cover/cover.c -+++ b/bench/test/cover/cover.c -@@ -693,6 +693,9 @@ void _Pragma( "entrypoint" ) cover_main( void ) - Main function - */ - -+#ifdef ALL_IN_ONE -+ #define main main_cover -+#endif - int main( void ) - { - cover_init(); -diff --git a/bench/test/duff/duff.c b/bench/test/duff/duff.c -index 9fb49f1..83313ce 100755 ---- a/bench/test/duff/duff.c -+++ b/bench/test/duff/duff.c -@@ -28,6 +28,9 @@ void duff_initialize( char *arr, int length ); - void duff_init(); - void duff_main( void ); - int duff_return( void ); -+#ifdef ALL_IN_ONE -+ #define main main_duff -+#endif - int main( void ); - - -diff --git a/bench/test/test3/test3.c b/bench/test/test3/test3.c -index 0235738..6eaf8c2 100755 ---- a/bench/test/test3/test3.c -+++ b/bench/test/test3/test3.c -@@ -154,6 +154,9 @@ void test3_func_2_0( void ); - void test3_func_1_0( void ); - void test3_func_0_0( void ); - void test3_main( void ); -+#ifdef ALL_IN_ONE -+ #define main main_test3 -+#endif - int main( void ); - - -diff --git a/taclebench.c b/taclebench.c -new file mode 100644 -index 0000000..aaff1bb ---- /dev/null -+++ b/taclebench.c -@@ -0,0 +1,366 @@ -+#include <stdio.h> -+#include <time.h> -+ -+int main_epic(void); -+int main_mpeg2(void); -+int main_cjpeg_transupp(void); -+int main_adpcm_enc(void); -+int main_rijndael_dec(void); -+int main_huff_enc(void); -+int main_dijkstra(void); -+int main_gsm_dec(void); -+int main_ammunition(void); -+int main_susan(void); -+int main_ndes(void); -+int main_petrinet(void); -+int main_gsm_enc(void); -+int main_h264_dec(void); -+int main_rijndael_enc(void); -+int main_huff_dec(void); -+int main_anagram(void); -+int main_g723_enc(void); -+int main_adpcm_dec(void); -+int main_cjpeg_wrbmp(void); -+int main_statemate(void); -+int main_fmref(void); -+int main_audiobeam(void); -+int main_test3(void); -+int main_duff(void); -+int main_cover(void); -+int main_powerwindow(void); -+int main_lift(void); -+int main_fac(void); -+int main_bsort(void); -+int main_complex_updates(void); -+int main_cosf(void); -+int main_isqrt(void); -+int main_minver(void); -+int main_pm(void); -+int main_lms(void); -+int main_binarysearch(void); -+int main_fft(void); -+int main_sha(void); -+int main_iir(void); -+int main_matrix1(void); -+int main_st(void); -+int main_prime(void); -+int main_deg2rad(void); -+int main_filterbank(void); -+int main_jfdctint(void); -+int main_fir2dim(void); -+int main_ludcmp(void); -+int main_bitcount(void); -+int main_md5(void); -+int main_recursion(void); -+int main_insertsort(void); -+int main_cubic(void); -+int main_rad2deg(void); -+int main_quicksort(void); -+int main_countnegative(void); -+int main_bitonic(void); -+ -+int main(void) -+{ -+ struct timespec start_ts; -+ struct timespec end_ts; -+ clock_gettime(CLOCK_MONOTONIC, &start_ts); -+ -+ if (main_epic() != 0) -+ { -+ printf("main_epic error\n"); -+ } -+ -+ if (main_mpeg2() != 0) -+ { -+ printf("main_mpeg2 error\n"); -+ } -+ -+ if (main_cjpeg_transupp() != 0) -+ { -+ printf("main_cjpeg_transupp error\n"); -+ } -+ -+ if (main_adpcm_enc() != 0) -+ { -+ printf("main_adpcm_enc error\n"); -+ } -+ -+ if (main_rijndael_dec() != 0) -+ { -+ printf("main_rijndael_dec error\n"); -+ } -+ -+ if (main_huff_enc() != 0) -+ { -+ printf("main_huff_enc error\n"); -+ } -+ -+ if (main_dijkstra() != 0) -+ { -+ printf("main_dijkstra error\n"); -+ } -+ -+ if (main_gsm_dec() != 0) -+ { -+ printf("main_gsm_dec error\n"); -+ } -+ -+ if (main_ammunition() != 0) -+ { -+ printf("main_ammunition error\n"); -+ } -+ -+ if (main_susan() != 0) -+ { -+ printf("main_susan error\n"); -+ } -+ -+ if (main_ndes() != 0) -+ { -+ printf("main_ndes error\n"); -+ } -+ -+ if (main_petrinet() != 0) -+ { -+ printf("main_petrinet error\n"); -+ } -+ -+ if (main_gsm_enc() != 0) -+ { -+ printf("main_gsm_enc error\n"); -+ } -+ -+ if (main_h264_dec() != 0) -+ { -+ printf("main_h264_dec error\n"); -+ } -+ -+ if (main_rijndael_enc() != 0) -+ { -+ printf("main_rijndael_enc error\n"); -+ } -+ -+ if (main_huff_dec() != 0) -+ { -+ printf("main_huff_dec error\n"); -+ } -+ -+ if (main_anagram() != 0) -+ { -+ printf("main_anagram error\n"); -+ } -+ -+ if (main_g723_enc() != 0) -+ { -+ printf("main_g723_enc error\n"); -+ } -+ -+ if (main_adpcm_dec() != 0) -+ { -+ printf("main_adpcm_dec error\n"); -+ } -+ -+ if (main_cjpeg_wrbmp() != 0) -+ { -+ printf("main_cjpeg_wrbmp error\n"); -+ } -+ -+ if (main_statemate() != 0) -+ { -+ printf("main_statemate error\n"); -+ } -+ -+ if (main_fmref() != 0) -+ { -+ printf("main_fmref error\n"); -+ } -+ -+ if (main_audiobeam() != 0) -+ { -+ printf("main_audiobeam error\n"); -+ } -+ -+ if (main_test3() != 0) -+ { -+ printf("main_test3 error\n"); -+ } -+ -+ if (main_duff() != 0) -+ { -+ printf("main_duff error\n"); -+ } -+ -+ if (main_cover() != 0) -+ { -+ printf("main_cover error\n"); -+ } -+ -+ if (main_powerwindow() != 0) -+ { -+ printf("main_powerwindow error\n"); -+ } -+ -+ if (main_lift() != 0) -+ { -+ printf("main_lift error\n"); -+ } -+ -+ if (main_fac() != 0) -+ { -+ printf("main_fac error\n"); -+ } -+ -+ if (main_bsort() != 0) -+ { -+ printf("main_bsort error\n"); -+ } -+ -+ if (main_complex_updates() != 0) -+ { -+ printf("main_complex_updates error\n"); -+ } -+ -+ if (main_cosf() != 0) -+ { -+ printf("main_cosf error\n"); -+ } -+ -+ if (main_isqrt() != 0) -+ { -+ printf("main_isqrt error\n"); -+ } -+ -+ if (main_minver() != 0) -+ { -+ printf("main_minver error\n"); -+ } -+ -+ if (main_pm() != 0) -+ { -+ printf("main_pm error\n"); -+ } -+ -+ if (main_lms() != 0) -+ { -+ printf("main_lms error\n"); -+ } -+ -+ if (main_binarysearch() != 0) -+ { -+ printf("main_binarysearch error\n"); -+ } -+ -+ if (main_fft() != 0) -+ { -+ printf("main_fft error\n"); -+ } -+ -+ if (main_sha() != 0) -+ { -+ printf("main_sha error\n"); -+ } -+ -+ if (main_iir() != 0) -+ { -+ printf("main_iir error\n"); -+ } -+ -+ if (main_matrix1() != 0) -+ { -+ printf("main_matrix1 error\n"); -+ } -+ -+ if (main_st() != 0) -+ { -+ printf("main_st error\n"); -+ } -+ -+ if (main_prime() != 0) -+ { -+ printf("main_prime error\n"); -+ } -+ -+ if (main_deg2rad() != 0) -+ { -+ printf("main_deg2rad error\n"); -+ } -+ -+ if (main_filterbank() != 0) -+ { -+ printf("main_filterbank error\n"); -+ } -+ -+ if (main_jfdctint() != 0) -+ { -+ printf("main_jfdctint error\n"); -+ } -+ -+ if (main_fir2dim() != 0) -+ { -+ printf("main_fir2dim error\n"); -+ } -+ -+ if (main_ludcmp() != 0) -+ { -+ printf("main_ludcmp error\n"); -+ } -+ -+ if (main_bitcount() != 0) -+ { -+ printf("main_bitcount error\n"); -+ } -+ -+ if (main_md5() != 0) -+ { -+ printf("main_md5 error\n"); -+ } -+ -+ if (main_recursion() != 0) -+ { -+ printf("main_recursion error\n"); -+ } -+ -+ if (main_insertsort() != 0) -+ { -+ printf("main_insertsort error\n"); -+ } -+ -+ if (main_cubic() != 0) -+ { -+ printf("main_cubic error\n"); -+ } -+ -+ if (main_rad2deg() != 0) -+ { -+ printf("main_rad2deg error\n"); -+ } -+ -+ if (main_quicksort() != 0) -+ { -+ printf("main_quicksort error\n"); -+ } -+ -+ if (main_countnegative() != 0) -+ { -+ printf("main_countnegative error\n"); -+ } -+ -+ if (main_bitonic() != 0) -+ { -+ printf("main_bitonic error\n"); -+ } -+ -+ clock_gettime(CLOCK_MONOTONIC, &end_ts); -+ long sec_diff = end_ts.tv_sec - start_ts.tv_sec; -+ long nsec_diff = end_ts.tv_nsec - start_ts.tv_nsec; -+ -+ if (nsec_diff < 0) -+ { -+ sec_diff -= 1; -+ nsec_diff += 1000000000; -+ } -+ -+ printf("%ld.%09ld seconds\n", sec_diff, nsec_diff); -+ -+ return 0; -+} --- -2.34.1 - diff --git a/benchmarks/tacle-bench/CMakeLists.txt b/benchmarks/tacle-bench/CMakeLists.txt deleted file mode 100644 index f443d45cd..000000000 --- a/benchmarks/tacle-bench/CMakeLists.txt +++ /dev/null @@ -1,199 +0,0 @@ -############################################################################ -# apps/benchmarks/tacle-bench/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -if(CONFIG_BENCHMARK_TACLEBENCH) - - set(SRCS tacle-bench/taclebench_main.c) - - set(TACLEBENCH_UNPACK ${CMAKE_CURRENT_LIST_DIR}/tacle-bench) - set(TACLEBENCH_URL https://github.com/tacle/tacle-bench/archive) - set(TACLEBENCH_ZIP master.zip) - - if(NOT EXISTS ${TACLEBENCH_UNPACK}) - - FetchContent_Declare( - taclebench_fetch - URL ${TACLEBENCH_URL}/${TACLEBENCH_ZIP} SOURCE_DIR ${TACLEBENCH_UNPACK} - BINARY_DIR ${CMAKE_BINARY_DIR}/apps/benchmarks/tacle-bench/tacle-bench - PATCH_COMMAND - patch -p0 -d ${CMAKE_CURRENT_LIST_DIR} < - ${CMAKE_CURRENT_LIST_DIR}/0001-tacle-bench-add-makefile-and-all-in-one-main-file.patch - DOWNLOAD_NO_PROGRESS true - TIMEOUT 30) - - FetchContent_GetProperties(taclebench_fetch) - if(NOT taclebench_fetch_POPULATED) - FetchContent_Populate(taclebench_fetch) - endif() - - endif() - - # app - list( - APPEND - SRCS - tacle-bench/bench/app/powerwindow/powerwindow_const_params.c - tacle-bench/bench/app/powerwindow/powerwindow_inputs.c - tacle-bench/bench/app/powerwindow/powerwindow_PW_Control_PSG_BackL.c - tacle-bench/bench/app/powerwindow/powerwindow_debounce.c - tacle-bench/bench/app/powerwindow/powerwindow_PW_Control_DRV.c - tacle-bench/bench/app/powerwindow/wcclib.c - tacle-bench/bench/app/powerwindow/powerwindow_PW_Control_PSG_BackR.c - tacle-bench/bench/app/powerwindow/powerwindow_PW_Control_PSG_Front.c - tacle-bench/bench/app/powerwindow/powerwindow_controlexclusion.c - tacle-bench/bench/app/powerwindow/powerwindow.c - tacle-bench/bench/app/powerwindow/powerwindow_powerwindow_control.c - tacle-bench/bench/app/lift/lift.c - tacle-bench/bench/app/lift/liftlibio.c - tacle-bench/bench/app/lift/liftlibcontrol.c) - - # kernel - list( - APPEND - SRCS - tacle-bench/bench/kernel/fac/fac.c - tacle-bench/bench/kernel/bsort/bsort.c - tacle-bench/bench/kernel/complex_updates/complex_updates.c - tacle-bench/bench/kernel/cosf/cosf.c - tacle-bench/bench/kernel/isqrt/isqrt.c - tacle-bench/bench/kernel/isqrt/basicmath_libc.c - tacle-bench/bench/kernel/minver/minver.c - tacle-bench/bench/kernel/pm/pm_stdlib.c - tacle-bench/bench/kernel/pm/pm_input.c - tacle-bench/bench/kernel/pm/pm_libm.c - tacle-bench/bench/kernel/pm/pm.c - tacle-bench/bench/kernel/lms/lms.c - tacle-bench/bench/kernel/binarysearch/binarysearch.c - tacle-bench/bench/kernel/fft/fft_input.c - tacle-bench/bench/kernel/fft/fft.c - tacle-bench/bench/kernel/sha/memset.c - tacle-bench/bench/kernel/sha/input_small.c - tacle-bench/bench/kernel/sha/memhelper.c - tacle-bench/bench/kernel/sha/memcpy.c - tacle-bench/bench/kernel/sha/sha.c - tacle-bench/bench/kernel/iir/iir.c - tacle-bench/bench/kernel/matrix1/matrix1.c - tacle-bench/bench/kernel/st/st.c - tacle-bench/bench/kernel/prime/prime.c - tacle-bench/bench/kernel/deg2rad/deg2rad.c - tacle-bench/bench/kernel/filterbank/filterbank.c - tacle-bench/bench/kernel/jfdctint/jfdctint.c - tacle-bench/bench/kernel/fir2dim/fir2dim.c - tacle-bench/bench/kernel/ludcmp/ludcmp.c - tacle-bench/bench/kernel/bitcount/bitcount.c - tacle-bench/bench/kernel/bitcount/bitcnt_2.c - tacle-bench/bench/kernel/bitcount/bitcnt_1.c - tacle-bench/bench/kernel/bitcount/bitcnt_3.c - tacle-bench/bench/kernel/bitcount/bitcnt_4.c - tacle-bench/bench/kernel/md5/md5.c - tacle-bench/bench/kernel/recursion/recursion.c - tacle-bench/bench/kernel/insertsort/insertsort.c - tacle-bench/bench/kernel/cubic/cubic.c - tacle-bench/bench/kernel/rad2deg/rad2deg.c - tacle-bench/bench/kernel/quicksort/quicksortstdlib.c - tacle-bench/bench/kernel/quicksort/input.c - tacle-bench/bench/kernel/quicksort/quicksortlibm.c - tacle-bench/bench/kernel/quicksort/quicksort.c - tacle-bench/bench/kernel/countnegative/countnegative.c - tacle-bench/bench/kernel/bitonic/bitonic.c) - - # sequential - list( - APPEND - SRCS - tacle-bench/bench/sequential/epic/epic.c - tacle-bench/bench/sequential/mpeg2/mpeg2.c - tacle-bench/bench/sequential/cjpeg_transupp/cjpeg_transupp.c - tacle-bench/bench/sequential/adpcm_enc/adpcm_enc.c - tacle-bench/bench/sequential/rijndael_dec/rijndael_dec.c - tacle-bench/bench/sequential/rijndael_dec/input_small_enc.c - tacle-bench/bench/sequential/rijndael_dec/aes.c - tacle-bench/bench/sequential/rijndael_dec/rijndael_dec_libc.c - tacle-bench/bench/sequential/huff_enc/huff_enc.c - tacle-bench/bench/sequential/dijkstra/dijkstra.c - tacle-bench/bench/sequential/dijkstra/input.c - tacle-bench/bench/sequential/gsm_dec/gsm_dec.c - tacle-bench/bench/sequential/ammunition/arithm.c - tacle-bench/bench/sequential/ammunition/ammunition.c - tacle-bench/bench/sequential/ammunition/bits.c - tacle-bench/bench/sequential/ammunition/ammunition_libc.c - tacle-bench/bench/sequential/susan/wccmalloc.c - tacle-bench/bench/sequential/susan/wccfile.c - tacle-bench/bench/sequential/susan/input.c - tacle-bench/bench/sequential/susan/susan.c - tacle-bench/bench/sequential/susan/wcclibm.c - tacle-bench/bench/sequential/ndes/ndes.c - tacle-bench/bench/sequential/petrinet/petrinet.c - tacle-bench/bench/sequential/gsm_enc/gsm_enc.c - tacle-bench/bench/sequential/h264_dec/h264_decinput.c - tacle-bench/bench/sequential/h264_dec/h264_dec.c - tacle-bench/bench/sequential/rijndael_enc/input_small.c - tacle-bench/bench/sequential/rijndael_enc/rijndael_enc.c - tacle-bench/bench/sequential/rijndael_enc/aes.c - tacle-bench/bench/sequential/rijndael_enc/rijndael_enc_libc.c - tacle-bench/bench/sequential/huff_dec/huff_dec.c - tacle-bench/bench/sequential/anagram/anagram_stdlib.c - tacle-bench/bench/sequential/anagram/anagram.c - tacle-bench/bench/sequential/anagram/anagram_input.c - tacle-bench/bench/sequential/g723_enc/g723_enc.c - tacle-bench/bench/sequential/adpcm_dec/adpcm_dec.c - tacle-bench/bench/sequential/cjpeg_wrbmp/cjpeg_wrbmp.c - tacle-bench/bench/sequential/cjpeg_wrbmp/input.c - tacle-bench/bench/sequential/statemate/statemate.c - tacle-bench/bench/sequential/fmref/fmref.c - tacle-bench/bench/sequential/fmref/wcclibm.c - tacle-bench/bench/sequential/audiobeam/audiobeamlibmalloc.c - tacle-bench/bench/sequential/audiobeam/audiobeam.c - tacle-bench/bench/sequential/audiobeam/audiobeamlibm.c - tacle-bench/bench/sequential/audiobeam/audiobeaminput.c - tacle-bench/bench/test/test3/test3.c - tacle-bench/bench/test/duff/duff.c - tacle-bench/bench/test/cover/cover.c) - - # only one wcclibm - list(APPEND SRCS tacle-bench/bench/kernel/cosf/wcclibm.c) - - list( - APPEND - CFLAGS - -DALL_IN_ONE - -Wno-unknown-pragmas - -Wno-strict-prototypes - -Wno-array-bounds - -Wno-shadow - -Wno-stringop-overflow - -Wno-maybe-uninitialized) - - nuttx_add_application( - NAME - taclebench - PRIORITY - ${CONFIG_BENCHMARK_TACLEBENCH_PRIORITY} - STACKSIZE - ${CONFIG_BENCHMARK_TACLEBENCH_STACKSIZE} - MODULE - ${CONFIG_BENCHMARK_TACLEBENCH} - COMPILE_FLAGS - ${CFLAGS} - SRCS - ${SRCS}) -endif() diff --git a/benchmarks/tacle-bench/Kconfig b/benchmarks/tacle-bench/Kconfig deleted file mode 100644 index 5ac56bb3f..000000000 --- a/benchmarks/tacle-bench/Kconfig +++ /dev/null @@ -1,22 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config BENCHMARK_TACLEBENCH - tristate "TacleBench" - default n - ---help--- - A real-time benchmark from WCET'16. - -if BENCHMARK_TACLEBENCH - -config BENCHMARK_TACLEBENCH_PRIORITY - int "TacleBench task priority" - default 100 - -config BENCHMARK_TACLEBENCH_STACKSIZE - int "TacleBench stack size" - default DEFAULT_TASK_STACKSIZE - -endif diff --git a/benchmarks/tacle-bench/Make.defs b/benchmarks/tacle-bench/Make.defs deleted file mode 100644 index db0d4f777..000000000 --- a/benchmarks/tacle-bench/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/benchmarks/tacle-bench/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_BENCHMARK_TACLEBENCH),) -CONFIGURED_APPS += $(APPDIR)/benchmarks/tacle-bench -endif diff --git a/benchmarks/tacle-bench/Makefile b/benchmarks/tacle-bench/Makefile deleted file mode 100644 index b574c0f59..000000000 --- a/benchmarks/tacle-bench/Makefile +++ /dev/null @@ -1,184 +0,0 @@ -############################################################################ -# apps/benchmarks/tacle-bench/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -############################################################################ -# Targets -############################################################################ - - -include $(APPDIR)/Make.defs - -PROGNAME = taclebench -PRIORITY = $(CONFIG_BENCHMARK_TACLEBENCH_PRIORITY) -STACKSIZE = $(CONFIG_BENCHMARK_TACLEBENCH_STACKSIZE) -MODULE = $(CONFIG_BENCHMARK_TACLEBENCH) - -TACLEBENCH_UNPACK = tacle-bench -TACLEBENCH_URL = https://github.com/tacle/tacle-bench/archive -TACLEBENCH_VERSION = master -TACLEBENCH_ZIP = $(TACLEBENCH_UNPACK)-$(TACLEBENCH_VERSION).zip -UNPACK ?= unzip -q -o - -$(TACLEBENCH_ZIP): - @echo "Downloading: $(TACLEBENCH_URL)" - $(Q) curl -L $(TACLEBENCH_URL)/$(TACLEBENCH_VERSION).zip -o $(TACLEBENCH_UNPACK)-$(TACLEBENCH_VERSION).zip - -$(TACLEBENCH_UNPACK): $(TACLEBENCH_ZIP) - @echo "Unpacking: $(TACLEBENCH_ZIP) -> $(TACLEBENCH_UNPACK)" - $(Q) $(UNPACK) $(TACLEBENCH_ZIP) - $(Q) mv tacle-bench-$(TACLEBENCH_VERSION) $(TACLEBENCH_UNPACK) - $(Q) touch $(TACLEBENCH_UNPACK) - @echo "Patching: Applying patch" - $(Q) cd tacle-bench && patch -p1 < ../0001-tacle-bench-add-makefile-and-all-in-one-main-file.patch - -ifeq ($(wildcard $(TACLEBENCH_UNPACK)/.git),) -context:: $(TACLEBENCH_UNPACK) - -distclean:: - $(call DELDIR, $(TACLEBENCH_UNPACK)) - $(call DELFILE, $(TACLEBENCH_ZIP)) -endif - -# app -CSRCS = tacle-bench/bench/app/powerwindow/powerwindow_const_params.c -CSRCS += tacle-bench/bench/app/powerwindow/powerwindow_inputs.c -CSRCS += tacle-bench/bench/app/powerwindow/powerwindow_PW_Control_PSG_BackL.c -CSRCS += tacle-bench/bench/app/powerwindow/powerwindow_debounce.c -CSRCS += tacle-bench/bench/app/powerwindow/powerwindow_PW_Control_DRV.c -CSRCS += tacle-bench/bench/app/powerwindow/wcclib.c -CSRCS += tacle-bench/bench/app/powerwindow/powerwindow_PW_Control_PSG_BackR.c -CSRCS += tacle-bench/bench/app/powerwindow/powerwindow_PW_Control_PSG_Front.c -CSRCS += tacle-bench/bench/app/powerwindow/powerwindow_controlexclusion.c -CSRCS += tacle-bench/bench/app/powerwindow/powerwindow.c -CSRCS += tacle-bench/bench/app/powerwindow/powerwindow_powerwindow_control.c -CSRCS += tacle-bench/bench/app/lift/lift.c -CSRCS += tacle-bench/bench/app/lift/liftlibio.c -CSRCS += tacle-bench/bench/app/lift/liftlibcontrol.c - -# kernel -CSRCS += tacle-bench/bench/kernel/fac/fac.c -CSRCS += tacle-bench/bench/kernel/bsort/bsort.c -CSRCS += tacle-bench/bench/kernel/complex_updates/complex_updates.c -CSRCS += tacle-bench/bench/kernel/cosf/cosf.c -CSRCS += tacle-bench/bench/kernel/isqrt/isqrt.c -CSRCS += tacle-bench/bench/kernel/isqrt/basicmath_libc.c -CSRCS += tacle-bench/bench/kernel/minver/minver.c -CSRCS += tacle-bench/bench/kernel/pm/pm_stdlib.c -CSRCS += tacle-bench/bench/kernel/pm/pm_input.c -CSRCS += tacle-bench/bench/kernel/pm/pm_libm.c -CSRCS += tacle-bench/bench/kernel/pm/pm.c -CSRCS += tacle-bench/bench/kernel/lms/lms.c -CSRCS += tacle-bench/bench/kernel/binarysearch/binarysearch.c -CSRCS += tacle-bench/bench/kernel/fft/fft_input.c -CSRCS += tacle-bench/bench/kernel/fft/fft.c -CSRCS += tacle-bench/bench/kernel/sha/memset.c -CSRCS += tacle-bench/bench/kernel/sha/input_small.c -CSRCS += tacle-bench/bench/kernel/sha/memhelper.c -CSRCS += tacle-bench/bench/kernel/sha/memcpy.c -CSRCS += tacle-bench/bench/kernel/sha/sha.c -CSRCS += tacle-bench/bench/kernel/iir/iir.c -CSRCS += tacle-bench/bench/kernel/matrix1/matrix1.c -CSRCS += tacle-bench/bench/kernel/st/st.c -CSRCS += tacle-bench/bench/kernel/prime/prime.c -CSRCS += tacle-bench/bench/kernel/deg2rad/deg2rad.c -CSRCS += tacle-bench/bench/kernel/filterbank/filterbank.c -CSRCS += tacle-bench/bench/kernel/jfdctint/jfdctint.c -CSRCS += tacle-bench/bench/kernel/fir2dim/fir2dim.c -CSRCS += tacle-bench/bench/kernel/ludcmp/ludcmp.c -CSRCS += tacle-bench/bench/kernel/bitcount/bitcount.c -CSRCS += tacle-bench/bench/kernel/bitcount/bitcnt_2.c -CSRCS += tacle-bench/bench/kernel/bitcount/bitcnt_1.c -CSRCS += tacle-bench/bench/kernel/bitcount/bitcnt_3.c -CSRCS += tacle-bench/bench/kernel/bitcount/bitcnt_4.c -CSRCS += tacle-bench/bench/kernel/md5/md5.c -CSRCS += tacle-bench/bench/kernel/recursion/recursion.c -CSRCS += tacle-bench/bench/kernel/insertsort/insertsort.c -CSRCS += tacle-bench/bench/kernel/cubic/cubic.c -CSRCS += tacle-bench/bench/kernel/rad2deg/rad2deg.c -CSRCS += tacle-bench/bench/kernel/quicksort/quicksortstdlib.c -CSRCS += tacle-bench/bench/kernel/quicksort/input.c -CSRCS += tacle-bench/bench/kernel/quicksort/quicksortlibm.c -CSRCS += tacle-bench/bench/kernel/quicksort/quicksort.c -CSRCS += tacle-bench/bench/kernel/countnegative/countnegative.c -CSRCS += tacle-bench/bench/kernel/bitonic/bitonic.c - -# sequential -CSRCS += tacle-bench/bench/sequential/epic/epic.c -CSRCS += tacle-bench/bench/sequential/mpeg2/mpeg2.c -CSRCS += tacle-bench/bench/sequential/cjpeg_transupp/cjpeg_transupp.c -CSRCS += tacle-bench/bench/sequential/adpcm_enc/adpcm_enc.c -CSRCS += tacle-bench/bench/sequential/rijndael_dec/rijndael_dec.c -CSRCS += tacle-bench/bench/sequential/rijndael_dec/input_small_enc.c -CSRCS += tacle-bench/bench/sequential/rijndael_dec/aes.c -CSRCS += tacle-bench/bench/sequential/rijndael_dec/rijndael_dec_libc.c -CSRCS += tacle-bench/bench/sequential/huff_enc/huff_enc.c -CSRCS += tacle-bench/bench/sequential/dijkstra/dijkstra.c -CSRCS += tacle-bench/bench/sequential/dijkstra/input.c -CSRCS += tacle-bench/bench/sequential/gsm_dec/gsm_dec.c -CSRCS += tacle-bench/bench/sequential/ammunition/arithm.c -CSRCS += tacle-bench/bench/sequential/ammunition/ammunition.c -CSRCS += tacle-bench/bench/sequential/ammunition/bits.c -CSRCS += tacle-bench/bench/sequential/ammunition/ammunition_libc.c -CSRCS += tacle-bench/bench/sequential/susan/wccmalloc.c -CSRCS += tacle-bench/bench/sequential/susan/wccfile.c -CSRCS += tacle-bench/bench/sequential/susan/input.c -CSRCS += tacle-bench/bench/sequential/susan/susan.c -CSRCS += tacle-bench/bench/sequential/susan/wcclibm.c -CSRCS += tacle-bench/bench/sequential/ndes/ndes.c -CSRCS += tacle-bench/bench/sequential/petrinet/petrinet.c -CSRCS += tacle-bench/bench/sequential/gsm_enc/gsm_enc.c -CSRCS += tacle-bench/bench/sequential/h264_dec/h264_decinput.c -CSRCS += tacle-bench/bench/sequential/h264_dec/h264_dec.c -CSRCS += tacle-bench/bench/sequential/rijndael_enc/input_small.c -CSRCS += tacle-bench/bench/sequential/rijndael_enc/rijndael_enc.c -CSRCS += tacle-bench/bench/sequential/rijndael_enc/aes.c -CSRCS += tacle-bench/bench/sequential/rijndael_enc/rijndael_enc_libc.c -CSRCS += tacle-bench/bench/sequential/huff_dec/huff_dec.c -CSRCS += tacle-bench/bench/sequential/anagram/anagram_stdlib.c -CSRCS += tacle-bench/bench/sequential/anagram/anagram.c -CSRCS += tacle-bench/bench/sequential/anagram/anagram_input.c -CSRCS += tacle-bench/bench/sequential/g723_enc/g723_enc.c -CSRCS += tacle-bench/bench/sequential/adpcm_dec/adpcm_dec.c -CSRCS += tacle-bench/bench/sequential/cjpeg_wrbmp/cjpeg_wrbmp.c -CSRCS += tacle-bench/bench/sequential/cjpeg_wrbmp/input.c -CSRCS += tacle-bench/bench/sequential/statemate/statemate.c -CSRCS += tacle-bench/bench/sequential/fmref/fmref.c -CSRCS += tacle-bench/bench/sequential/fmref/wcclibm.c -CSRCS += tacle-bench/bench/sequential/audiobeam/audiobeamlibmalloc.c -CSRCS += tacle-bench/bench/sequential/audiobeam/audiobeam.c -CSRCS += tacle-bench/bench/sequential/audiobeam/audiobeamlibm.c -CSRCS += tacle-bench/bench/sequential/audiobeam/audiobeaminput.c -CSRCS += tacle-bench/bench/test/test3/test3.c -CSRCS += tacle-bench/bench/test/duff/duff.c -CSRCS += tacle-bench/bench/test/cover/cover.c - -# only one wcclibm is allowed -CSRCS += tacle-bench/bench/kernel/cosf/wcclibm.c - -MAINSRC = tacle-bench/taclebench.c - -CFLAGS += -DALL_IN_ONE -CFLAGS += -Wno-unknown-pragmas -Wno-strict-prototypes -CFLAGS += -Wno-array-bounds -Wno-shadow -CFLAGS += -Wno-stringop-overflow -Wno-maybe-uninitialized - -include $(APPDIR)/Application.mk diff --git a/benchmarks/tacle-bench/generate_taclebench_c.sh b/benchmarks/tacle-bench/generate_taclebench_c.sh deleted file mode 100755 index c6b69e0bc..000000000 --- a/benchmarks/tacle-bench/generate_taclebench_c.sh +++ /dev/null @@ -1,95 +0,0 @@ -#!/bin/bash -############################################################################ -# apps/benchmarks/tacle-bench/generate_taclebench_c.sh -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -MAIN_C=tacle-bench/taclebench.c -BENCH_PATH=tacle-bench/bench -GENERATE_PATH=tacle-bench - -search_main() { - local file="$1" - local filename=$(basename "$file") - local new_main="main_${filename%.*}" - - flag=0 - - # try to modifiy main function declaration first - if grep -q "int main();" "$file"; then - flag=1 - sed -i 's/int main();/#ifdef ALL_IN_ONE\n #define main '"${new_main}"'\n#endif\nint main();/' "${file}" - elif grep -q "int main( void );" "$file"; then - flag=1 - sed -i 's/int main( void );/#ifdef ALL_IN_ONE\n #define main '"${new_main}"'\n#endif\nint main( void );/' "${file}" - elif grep -q "int main ( void );" "$file"; then - flag=1 - sed -i 's/int main ( void );/#ifdef ALL_IN_ONE\n #define main '"${new_main}"'\n#endif\nint main ( void );/' "${file}" - fi - - # if no main function delaration, try to modify main function - if [ "$flag" -eq 0 ]; then - if grep -q "int main()$" "$file"; then - flag=1 - sed -i 's/int main()$/#ifdef ALL_IN_ONE\n #define main '"${new_main}"'\n#endif\nint main()/' "${file}" - elif grep -q "int main( void )$" "$file"; then - flag=1 - sed -i 's/int main( void )$/#ifdef ALL_IN_ONE\n #define main '"${new_main}"'\n#endif\nint main( void )/' "${file}" - elif grep -q "int main ( void )$" "$file"; then - flag=1 - sed -i 's/int main ( void )$/#ifdef ALL_IN_ONE\n #define main '"${new_main}"'\n#endif\nint main ( void )/' "${file}" - fi - fi - - if [ "$flag" -eq 1 ]; then - echo "int $new_main (void);" >> $${MAIN_C}.tmp - echo " if ($new_main() != 0) { printf(\"$new_main error\n\"); }" >> $MAIN_C - echo "" >> $MAIN_C - else - echo "Failed to modify main function in $file" - fi -} - -# search for c file -find_c_files() { - local dir="$1" - find "$dir" -type f -name "*.c" | while read -r file; do - search_main "$file" - done -} - -> ${MAIN_C}.tmp -echo "#include <stdio.h>" >> ${MAIN_C}.tmp -echo "int main (void) {" >> $MAIN_C - - -# exclude bench/parallel -mv $BENCH_PATH/parallel ./parallel - -find_c_files "$BENCH_PATH" - -echo " return 0;" >> $MAIN_C -echo "}" >> $MAIN_C - -cat $MAIN_C >> ${MAIN_C}.tmp - -mv ${MAIN_C}.tmp $MAIN_C -# restore bench/parallel -mv ./parallel $BENCH_PATH/parallel diff --git a/benchmarks/test-tlb/.gitignore b/benchmarks/test-tlb/.gitignore deleted file mode 100644 index 3c99f56ef..000000000 --- a/benchmarks/test-tlb/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/test-tlb -/*.zip diff --git a/benchmarks/test-tlb/0001-test-tlb-port-for-NuttX.patch b/benchmarks/test-tlb/0001-test-tlb-port-for-NuttX.patch deleted file mode 100644 index 1a355cef6..000000000 --- a/benchmarks/test-tlb/0001-test-tlb-port-for-NuttX.patch +++ /dev/null @@ -1,139 +0,0 @@ -From fe4108f726a0e30d429f031a6006f030c5eda113 Mon Sep 17 00:00:00 2001 -From: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com> -Date: Thu, 6 Jun 2024 19:53:37 +0800 -Subject: [PATCH] test-tlb: port for NuttX - -VELAPLATFO-25227 - -This commit ports the test-tlb test program to the NuttX. Additionally, it implements dynamic CPU frequency calculation. - -Change-Id: If1c15f36742d7ee5a7d13147b41b3372047dad08 -Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com> ---- - test-tlb.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++---- - 1 file changed, 63 insertions(+), 5 deletions(-) - -diff --git a/test-tlb.c b/test-tlb.c -index 5c8aaa5..767794a 100644 ---- a/test-tlb.c -+++ b/test-tlb.c -@@ -14,13 +14,58 @@ - #include <math.h> - #include <time.h> - --#define PAGE_SIZE 4096 -- --#define FREQ 3.9 - - static int test_hugepage = 0; - static int random_list = 0; - -+/* Fix definition conflict */ -+#ifndef PAGE_SIZE -+#define PAGE_SIZE 4096 -+#endif -+ -+/* dynamic calculate freq */ -+#define MEASURE_GAP 500000 -+ -+#ifdef __x86_64__ -+static inline unsigned long rdcnt_relax(void) -+{ -+ unsigned int lo,hi; -+ asm volatile ("rdtsc" : "=a" (lo), "=d" (hi)); -+ return ((unsigned long)hi << 32) | (unsigned long)lo; -+} -+#elif defined(__aarch64__) -+static inline unsigned long rdcnt_relax(void) -+{ -+ unsigned long time; -+ asm volatile("mrs %0, cntvct_el0" : "=r"(time)); -+ return time; -+} -+#else -+#error "Unsupported architecture for dynamic frequencies measuring" -+#endif -+ -+static inline unsigned long rdcnt(void) -+{ -+ return rdcnt_relax(); -+} -+ -+static unsigned long measure_freq(void) -+{ -+ unsigned long cycles_per_useconds; -+ unsigned long start; -+ unsigned long end; -+ -+ start = rdcnt(); -+ usleep(MEASURE_GAP); -+ end = rdcnt(); -+ -+ cycles_per_useconds = (end - start) / MEASURE_GAP; -+ -+ printf("cycles_per_microseconds: %lu\n", cycles_per_useconds); -+ -+ return cycles_per_useconds; -+} -+ - static void die(const char *fmt, ...) - { - va_list argp; -@@ -69,7 +114,7 @@ static unsigned long warmup(void *map) - - static double do_test(void *map) - { -- unsigned long count = 0, offset = 0, usec; -+ unsigned long volatile count = 0, offset = 0, usec; - struct timeval start, end; - struct itimerval itval = { - .it_interval = { 0, 0 }, -@@ -190,7 +235,14 @@ static void *create_map(void *map, unsigned long size, unsigned long stride) - if (map) { - if (test_hugepage) - return map; -+ -+#ifdef __NuttX__ -+ if (munmap(map, size) != 0) -+ die("munmap failed\n"); -+ map = NULL; -+#else - flags |= MAP_FIXED; -+#endif - } - - mapsize = size; -@@ -237,9 +289,14 @@ int main(int argc, char **argv) - const char *arg; - void *map; - double cycles; -+ unsigned long freq; - - srandom(time(NULL)); - -+ /* Fix segmentation fault when execution without any arguments in NuttX */ -+ if (argc < 3) -+ die("bad arguments: test-tlb [-H] <size> <stride>"); -+ - while ((arg = argv[1]) != NULL) { - if (*arg != '-') - break; -@@ -261,6 +318,7 @@ int main(int argc, char **argv) - argv++; - } - -+ freq = measure_freq(); - size = get_num(argv[1]); - stride = get_num(argv[2]); - if (stride < 4 || size < stride) -@@ -281,6 +339,6 @@ int main(int argc, char **argv) - } - - printf("%6.2fns (~%.1f cycles)\n", -- cycles, cycles*FREQ); -+ cycles, cycles * freq); - return 0; - } --- -2.34.1 - diff --git a/benchmarks/test-tlb/CMakeLists.txt b/benchmarks/test-tlb/CMakeLists.txt deleted file mode 100644 index 866583e69..000000000 --- a/benchmarks/test-tlb/CMakeLists.txt +++ /dev/null @@ -1,61 +0,0 @@ -############################################################################ -# apps/benchmarks/test-tlb/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ -if(CONFIG_BENCHMARK_TESTTLB) - - set(SRCS test-tlb/test-tlb.c) - - set(TESTTLB_UNPACK ${CMAKE_CURRENT_LIST_DIR}/test-tlb) - set(TESTTLB_URL https://github.com/torvalds/test-tlb/archive) - set(TESTTLB_ZIP master.zip) - - if(NOT EXISTS ${TESTTLB_UNPACK}) - - FetchContent_Declare( - testtlb_fetch - URL ${TESTTLB_URL}/${TESTTLB_ZIP} SOURCE_DIR ${TESTTLB_UNPACK} BINARY_DIR - ${CMAKE_BINARY_DIR}/apps/benchmarks/test-tlb/test-tlb - PATCH_COMMAND patch -p0 -d ${CMAKE_CURRENT_LIST_DIR} < - ${CMAKE_CURRENT_LIST_DIR}/0001-test-tlb-port-for-NuttX.patch - DOWNLOAD_NO_PROGRESS true - TIMEOUT 30) - - FetchContent_GetProperties(testtlb_fetch) - if(NOT testtlb_fetch_POPULATED) - FetchContent_Populate(testtlb_fetch) - endif() - - endif() - - nuttx_add_application( - NAME - testtlb - PRIORITY - ${CONFIG_BENCHMARK_TESTTLB_PRIORITY} - STACKSIZE - ${CONFIG_BENCHMARK_TESTTLB_STACKSIZE} - MODULE - ${CONFIG_BENCHMARK_TESTTLB} - COMPILE_FLAGS - ${CFLAGS} - SRCS - ${SRCS}) -endif() diff --git a/benchmarks/test-tlb/Kconfig b/benchmarks/test-tlb/Kconfig deleted file mode 100644 index 111c5a9a5..000000000 --- a/benchmarks/test-tlb/Kconfig +++ /dev/null @@ -1,23 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config BENCHMARK_TESTTLB - tristate "Memory Latency profiling" - depends on ALLOW_GPL_COMPONENTS - default n - ---help--- - Measure the memory latency - -if BENCHMARK_TESTTLB - -config BENCHMARK_TESTTLB_PRIORITY - int "TestTLB task priority" - default 100 - -config BENCHMARK_TESTTLB_STACKSIZE - int "TestTLB stack size" - default DEFAULT_TASK_STACKSIZE - -endif diff --git a/benchmarks/test-tlb/Make.defs b/benchmarks/test-tlb/Make.defs deleted file mode 100644 index e7f275ef0..000000000 --- a/benchmarks/test-tlb/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/benchmarks/test-tlb/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_BENCHMARK_TESTTLB),) -CONFIGURED_APPS += $(APPDIR)/benchmarks/test-tlb -endif diff --git a/benchmarks/test-tlb/Makefile b/benchmarks/test-tlb/Makefile deleted file mode 100644 index ca0b5f1ad..000000000 --- a/benchmarks/test-tlb/Makefile +++ /dev/null @@ -1,59 +0,0 @@ -############################################################################ -# apps/benchmarks/test-tlb/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -PROGNAME = testtlb -PRIORITY = $(CONFIG_BENCHMARK_TESTTLB_PRIORITY) -STACKSIZE = $(CONFIG_BENCHMARK_TESTTLB_STACKSIZE) -MODULE = $(CONFIG_BENCHMARK_TESTTLB) - -TESTTLB_UNPACK = test-tlb -TESTTLB_GIT = github.com/torvalds/test-tlb -TESTTLB_URL = https://github.com/torvalds/test-tlb/archive -TESTTLB_VERSION = master -TESTTLB_ZIP = $(TESTTLB_UNPACK)-$(TESTTLB_VERSION).zip -UNPACK ?= unzip -q -o - -$(TESTTLB_ZIP): - @echo "Downloading: $(TESTTLB_URL)" - $(Q) curl -L $(TESTTLB_URL)/$(TESTTLB_VERSION).zip -o $(TESTTLB_UNPACK)-$(TESTTLB_VERSION).zip - -$(TESTTLB_UNPACK): $(TESTTLB_ZIP) - @echo "Unpacking: $(TESTTLB_ZIP) -> $(TESTTLB_UNPACK)" - $(Q) $(UNPACK) $(TESTTLB_ZIP) - $(Q) mv test-tlb-$(TESTTLB_VERSION) $(TESTTLB_UNPACK) - $(Q) touch $(TESTTLB_UNPACK) - @echo "Patching: Applying patch" - $(Q) cd test-tlb && patch -p1 < ../0001-test-tlb-port-for-NuttX.patch - -ifeq ($(wildcard $(TESTTLB_UNPACK)/.git),) -context:: $(TESTTLB_UNPACK) - -distclean:: - $(call DELDIR, $(TESTTLB_UNPACK)) - $(call DELFILE, $(TESTTLB_ZIP)) -endif - -MAINSRC = test-tlb/test-tlb.c - -include $(APPDIR)/Application.mk diff --git a/benchmarks/tinymembench/.gitignore b/benchmarks/tinymembench/.gitignore deleted file mode 100644 index 0a80bd78b..000000000 --- a/benchmarks/tinymembench/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/tinymembench -/*.zip diff --git a/benchmarks/tinymembench/0001-tinymembench-fix-compiling-error-for-NuttX.patch b/benchmarks/tinymembench/0001-tinymembench-fix-compiling-error-for-NuttX.patch deleted file mode 100644 index 1c9c7a052..000000000 --- a/benchmarks/tinymembench/0001-tinymembench-fix-compiling-error-for-NuttX.patch +++ /dev/null @@ -1,28 +0,0 @@ -From f478ab0f728bea1ed352844339f8bdc87f7792fa Mon Sep 17 00:00:00 2001 -From: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com> -Date: Fri, 31 May 2024 19:58:48 +0800 -Subject: [PATCH] tinymembench: fix compiling error for NuttX - -This patch fix compilation error: Resolve conflict between `util.c` function fmin and math library function fmin - -Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com> ---- - util.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/util.c b/util.c -index a0d562c..539049f 100644 ---- a/util.c -+++ b/util.c -@@ -303,7 +303,7 @@ double gettime(void) - return (double)((int64_t)tv.tv_sec * 1000000 + tv.tv_usec) / 1000000.; - } - --double fmin(double a, double b) -+__attribute__((weak)) double fmin(double a, double b) - { - return a < b ? a : b; - } --- -2.34.1 - diff --git a/benchmarks/tinymembench/CMakeLists.txt b/benchmarks/tinymembench/CMakeLists.txt deleted file mode 100644 index 1bbcf96ab..000000000 --- a/benchmarks/tinymembench/CMakeLists.txt +++ /dev/null @@ -1,76 +0,0 @@ -############################################################################ -# apps/benchmarks/tinymembench/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -if(CONFIG_BENCHMARK_TINY_MEMBENCH) - - set(TINYMB_UNPACK ${CMAKE_CURRENT_LIST_DIR}/tinymembench) - set(TINYMB_URL https://github.com/ssvb/tinymembench/archive) - set(TINYMB_ZIP master.zip) - - if(NOT EXISTS ${TINYMB_UNPACK}) - - FetchContent_Declare( - tinymb_fetch - URL ${TINYMB_URL}/${TINYMB_ZIP} SOURCE_DIR ${TINYMB_UNPACK} BINARY_DIR - ${CMAKE_BINARY_DIR}/apps/benchmarks/tinymembench/tinymembench - PATCH_COMMAND - patch -p0 -d ${CMAKE_CURRENT_LIST_DIR} < - ${CMAKE_CURRENT_LIST_DIR}/0001-tinymembench-fix-compiling-error-for-NuttX.patch - DOWNLOAD_NO_PROGRESS true - TIMEOUT 30) - - FetchContent_GetProperties(tinymb_fetch) - if(NOT tinymb_fetch_POPULATED) - FetchContent_Populate(tinymb_fetch) - endif() - - endif() - - list(APPEND CFLAGS -Wno-unused-but-set-variable -Wno-unused-variable - -Wno-strict-prototypes) - - set(SRCS tinymembench/main.c) - - list( - APPEND - SRCS - tinymembench/aarch64-asm.S - tinymembench/arm-neon.S - tinymembench/x86-sse2.S - tinymembench/mips-32.S - tinymembench/asm-opt.c - tinymembench/util.c) - - nuttx_add_application( - NAME - tinymembench - PRIORITY - ${CONFIG_BENCHMARK_TINY_MEMBENCH_PRIORITY} - STACKSIZE - ${CONFIG_BENCHMARK_TINY_MEMBENCH_STACKSIZE} - MODULE - ${CONFIG_BENCHMARK_TINY_MEMBENCH} - COMPILE_FLAGS - ${CFLAGS} - SRCS - ${SRCS}) -endif() diff --git a/benchmarks/tinymembench/Kconfig b/benchmarks/tinymembench/Kconfig deleted file mode 100644 index 7a6521dab..000000000 --- a/benchmarks/tinymembench/Kconfig +++ /dev/null @@ -1,22 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config BENCHMARK_TINY_MEMBENCH - tristate "TinyMemBench" - default n - ---help--- - Measure the memory bandwidth and latency - -if BENCHMARK_TINY_MEMBENCH - -config BENCHMARK_TINY_MEMBENCH_PRIORITY - int "TinyMemBench task priority" - default 100 - -config BENCHMARK_TINY_MEMBENCH_STACKSIZE - int "TinyMemBench stack size" - default DEFAULT_TASK_STACKSIZE - -endif diff --git a/benchmarks/tinymembench/Make.defs b/benchmarks/tinymembench/Make.defs deleted file mode 100644 index d32e7385f..000000000 --- a/benchmarks/tinymembench/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/benchmarks/tinymembench/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_BENCHMARK_TINY_MEMBENCH),) -CONFIGURED_APPS += $(APPDIR)/benchmarks/tinymembench -endif diff --git a/benchmarks/tinymembench/Makefile b/benchmarks/tinymembench/Makefile deleted file mode 100644 index 37b616753..000000000 --- a/benchmarks/tinymembench/Makefile +++ /dev/null @@ -1,70 +0,0 @@ -############################################################################ -# apps/benchmarks/tinymembench/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -PROGNAME = tinymembench -PRIORITY = $(CONFIG_BENCHMARK_TINY_MEMBENCH_PRIORITY) -STACKSIZE = $(CONFIG_BENCHMARK_TINY_MEMBENCH_STACKSIZE) -MODULE = $(CONFIG_BENCHMARK_TINY_MEMBENCH) - -TINYMB_UNPACK = tinymembench -TINYMB_GIT = github.com/ssvb/tinymembench -TINYMB_URL = https://github.com/ssvb/tinymembench/archive -TINYMB_VERSION = master -TINYMB_ZIP = $(TINYMB_UNPACK)-$(TINYMB_VERSION).zip -UNPACK ?= unzip -q -o - -$(TINYMB_ZIP): - @echo "Downloading: $(TINYMB_URL)" - $(Q) curl -L $(TINYMB_URL)/$(TINYMB_VERSION).zip -o $(TINYMB_UNPACK)-$(TINYMB_VERSION).zip - -$(TINYMB_UNPACK): $(TINYMB_ZIP) - @echo "Unpacking: $(TINYMB_ZIP) -> $(TINYMB_UNPACK)" - $(Q) $(UNPACK) $(TINYMB_ZIP) - $(Q) mv tinymembench-$(TINYMB_VERSION) $(TINYMB_UNPACK) - $(Q) touch $(TINYMB_UNPACK) - @echo "Patching: Applying patch" - $(Q) cd tinymembench && patch -p1 < ../0001-tinymembench-fix-compiling-error-for-NuttX.patch - -ifeq ($(wildcard $(TINYMB_UNPACK)/.git),) -context:: $(TINYMB_UNPACK) - -distclean:: - $(call DELDIR, $(TINYMB_UNPACK)) - $(call DELFILE, $(TINYMB_ZIP)) -endif - -ASRCS += $(TINYMB_UNPACK)/aarch64-asm.S -ASRCS += $(TINYMB_UNPACK)/arm-neon.S -ASRCS += $(TINYMB_UNPACK)/x86-sse2.S -ASRCS += $(TINYMB_UNPACK)/mips-32.S - -CSRCS += $(TINYMB_UNPACK)/asm-opt.c -CSRCS += $(TINYMB_UNPACK)/util.c - -MAINSRC = $(TINYMB_UNPACK)/main.c - -CFLAGS += -Wno-unused-but-set-variable -Wno-unused-variable -CFLAGS += -Wno-strict-prototypes - -include $(APPDIR)/Application.mk diff --git a/benchmarks/whetstone/CMakeLists.txt b/benchmarks/whetstone/CMakeLists.txt deleted file mode 100644 index 1bcc0f256..000000000 --- a/benchmarks/whetstone/CMakeLists.txt +++ /dev/null @@ -1,31 +0,0 @@ -# ############################################################################## -# apps/benchmarks/whetstone/CMakeLists.txt -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_BENCHMARK_WHETSTONE) - nuttx_add_application( - NAME - ${CONFIG_BENCHMARK_WHETSTONE_PROGNAME} - SRCS - whetstone.c - STACKSIZE - ${CONFIG_BENCHMARK_WHETSTONE_STACKSIZE} - PRIORITY - ${CONFIG_BENCHMARK_WHETSTONE_PRIORITY}) -endif() diff --git a/benchmarks/whetstone/Kconfig b/benchmarks/whetstone/Kconfig deleted file mode 100644 index 10df1429e..000000000 --- a/benchmarks/whetstone/Kconfig +++ /dev/null @@ -1,34 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config BENCHMARK_WHETSTONE - tristate "Double Precision Benchmark" - default n - depends on ALLOW_CUSTOM_PERMISSIVE_COMPONENTS - ---help--- - Enable a Whetstone test. - - This benchmark is based on the C converted version from - https://www.netlib.org/benchmark/whetstone.c which has a - custom permissive license requiring attribution. - -if BENCHMARK_WHETSTONE - -config BENCHMARK_WHETSTONE_PROGNAME - string "Program name" - default "whetstone" - ---help--- - This is the name of the program that will be used when the NSH ELF - program is installed. - -config BENCHMARK_WHETSTONE_PRIORITY - int "Whetstone test task priority" - default 100 - -config BENCHMARK_WHETSTONE_STACKSIZE - int "Whetstone test stack size" - default DEFAULT_TASK_STACKSIZE - -endif diff --git a/benchmarks/whetstone/Make.defs b/benchmarks/whetstone/Make.defs deleted file mode 100644 index d9fa9f1af..000000000 --- a/benchmarks/whetstone/Make.defs +++ /dev/null @@ -1,23 +0,0 @@ -############################################################################ -# apps/benchmarks/whetstone/Make.defs -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_BENCHMARK_WHETSTONE),) -CONFIGURED_APPS += $(APPDIR)/benchmarks/whetstone -endif diff --git a/benchmarks/whetstone/Makefile b/benchmarks/whetstone/Makefile deleted file mode 100644 index 1bdf6dfd6..000000000 --- a/benchmarks/whetstone/Makefile +++ /dev/null @@ -1,32 +0,0 @@ -############################################################################ -# apps/benchmarks/whetstone/Makefile -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -# WHETSTONE speed test - -PROGNAME = $(CONFIG_BENCHMARK_WHETSTONE_PROGNAME) -PRIORITY = $(CONFIG_BENCHMARK_WHETSTONE_PRIORITY) -STACKSIZE = $(CONFIG_BENCHMARK_WHETSTONE_STACKSIZE) -MODULE = $(CONFIG_BENCHMARK_WHETSTONE) - -MAINSRC = whetstone.c - -include $(APPDIR)/Application.mk diff --git a/benchmarks/whetstone/whetstone.c b/benchmarks/whetstone/whetstone.c deleted file mode 100644 index dbc8247fd..000000000 --- a/benchmarks/whetstone/whetstone.c +++ /dev/null @@ -1,520 +0,0 @@ -/**************************************************************************** - * apps/benchmarks/whetstone/whetstone.c - * - * SPDX-License-Identifier: LicenseRef-Painter-Engineering-Whetstone - * - * Converted Whetstone Double Precision Benchmark - * Version 1.2 22 March 1998 - * - * (c) Copyright 1998 Painter Engineering, Inc. - * All Rights Reserved. - * - * Permission is granted to use, duplicate, and - * publish this text and program as long as it - * includes this entire comment block and limited - * rights reference. - * - * Converted by Rich Painter, Painter Engineering, Inc. based on the - * www.netlib.org benchmark/whetstoned version obtained 16 March 1998. - * - * A novel approach was used here to keep the look and feel of the - * FORTRAN version. Altering the FORTRAN-based array indices, - * starting at element 1, to start at element 0 for C, would require - * numerous changes, including decrementing the variable indices by 1. - * Instead, the array e1[] was declared 1 element larger in C. This - * allows the FORTRAN index range to function without any literal or - * variable indices changes. The array element e1[0] is simply never - * used and does not alter the benchmark results. - * - * The major FORTRAN comment blocks were retained to minimize - * differences between versions. Modules N5 and N12, like in the - * FORTRAN version, have been eliminated here. - * - * An optional command-line argument has been provided [-c] to - * offer continuous repetition of the entire benchmark. - * An optional argument for setting an alternate loop count is also - * provided. Define PRINTOUT to cause the pout() function to print - * outputs at various stages. Final timing measurements should be - * made with the PRINTOUT undefined. - * - * Questions and comments may be directed to the author at - * r.painter@ieee.org - ****************************************************************************/ - -/**************************************************************************** - * Benchmark #2 -- Double Precision Whetstone (A001) - * - * o This is a REAL*8 version of - * the Whetstone benchmark program. - * - * o DO-loop semantics are ANSI-66 compatible. - * - * o Final measurements are to be made with all - * WRITE statements and FORMAT sttements removed. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -/* standard C library headers required */ - -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <math.h> - -/* the following is optional depending on the timing function used */ - -#include <time.h> - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* map the FORTRAN math functions, etc. to the C versions */ - -#define DSIN sin -#define DCOS cos -#define DATAN atan -#define DLOG log -#define DEXP exp -#define DSQRT sqrt -#define IF if -#define USAGE "usage: whetdc [-c] [loops]\n" - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/* function prototypes */ - -void pout(long n, long j, long k, double x1, - double x2, double x3, double x4); -void pa(double e[]); -void p0(void); -void p3(double x, double y, FAR double *z); - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/* COMMON t,t1,t2,e1(4),j,k,l */ - -double t; -double t1; -double t2; -double e1[5]; -int j; -int k; -int l; - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -int main(int argc, FAR char *argv[]) -{ - /* used in the FORTRAN version */ - - long loop; - long i; - long n1; - long n2; - long n3; - long n4; - long n6; - long n7; - long n8; - long n9; - long n10; - long n11; - double x1; - double x2; - double x3; - double x4; - double x; - double y; - double z; - int ii; - int jj; - - /* added for this version */ - - long loopstart; - long startmsec; - long finimsec; - float KIPS; - int continuous; - struct timespec ts; - - loopstart = 1000; /* see the note about loop below */ - continuous = 0; - - ii = 1; /* start at the first arg (temp use of ii here) */ - while (ii < argc) - { - if (strncmp(argv[ii], "-c", 2) == 0 || argv[ii][0] == 'c') - { - continuous = 1; - } - else if (atol(argv[ii]) > 0) - { - loopstart = atol(argv[ii]); - } - else - { - fprintf(stderr, USAGE); - return 1; - } - - ii++; - } - -LCONT: - - /* Start benchmark timing at this point. */ - - clock_gettime(CLOCK_REALTIME, &ts); - startmsec = ts.tv_sec * 1000 + ts.tv_nsec / 1000000; - - /* The actual benchmark starts here. */ - - t = .499975; - t1 = 0.50025; - t2 = 2.0; - - /* With loopcount loop=10, one million Whetstone instructions - * will be executed in EACH MAJOR loop..A MAJOR loop IS EXECUTED - * 'ii' TIMES TO INCREASE WALL-CLOCK TIMING ACCURACY. - * - * loop = 1000; - */ - - loop = loopstart; - ii = 1; - - jj = 1; - -IILOOP: - n1 = 0; - n2 = 12 * loop; - n3 = 14 * loop; - n4 = 345 * loop; - n6 = 210 * loop; - n7 = 32 * loop; - n8 = 899 * loop; - n9 = 616 * loop; - n10 = 0; - n11 = 93 * loop; - - /* Module 1: Simple identifiers */ - - x1 = 1.0; - x2 = -1.0; - x3 = -1.0; - x4 = -1.0; - - for (i = 1; i <= n1; i++) - { - x1 = (x1 + x2 + x3 - x4) * t; - x2 = (x1 + x2 - x3 + x4) * t; - x3 = (x1 - x2 + x3 + x4) * t; - x4 = (-x1 + x2 + x3 + x4) * t; - } - -#ifdef PRINTOUT - IF (jj == ii) - { - pout(n1, n1, n1, x1, x2, x3, x4); - } -#endif - - /* Module 2: Array elements */ - - e1[1] = 1.0; - e1[2] = -1.0; - e1[3] = -1.0; - e1[4] = -1.0; - - for (i = 1; i <= n2; i++) - { - e1[1] = (e1[1] + e1[2] + e1[3] - e1[4]) * t; - e1[2] = (e1[1] + e1[2] - e1[3] + e1[4]) * t; - e1[3] = (e1[1] - e1[2] + e1[3] + e1[4]) * t; - e1[4] = (-e1[1] + e1[2] + e1[3] + e1[4]) * t; - } - -#ifdef PRINTOUT - IF (jj == ii) - { - pout(n2, n3, n2, e1[1], e1[2], e1[3], e1[4]); - } -#endif - - /* Module 3: Array as parameter */ - - for (i = 1; i <= n3; i++) - { - pa(e1); - } - -#ifdef PRINTOUT - IF (jj == ii) - { - pout(n3, n2, n2, e1[1], e1[2], e1[3], e1[4]); - } -#endif - - /* Module 4: Conditional jumps */ - - j = 1; - for (i = 1; i <= n4; i++) - { - if (j == 1) - { - j = 2; - } - else - { - j = 3; - } - - if (j > 2) - { - j = 0; - } - else - { - j = 1; - } - - if (j < 1) - { - j = 1; - } - else - { - j = 0; - } - } - -#ifdef PRINTOUT - IF (jj == ii) - { - pout(n4, j, j, x1, x2, x3, x4); - } -#endif - -/* Module 5: Omitted - * Module 6: Integer arithmetic - */ - - j = 1; - k = 2; - l = 3; - - for (i = 1; i <= n6; i++) - { - j = j * (k - j) * (l - k); - k = l * k - (l - j) * k; - l = (l - k) * (k + j); - e1[l - 1] = j + k + l; - e1[k - 1] = j * k * l; - } - -#ifdef PRINTOUT - IF (jj == ii) - { - pout(n6, j, k, e1[1], e1[2], e1[3], e1[4]); - } -#endif - - /* Module 7: Trigonometric functions */ - - x = 0.5; - y = 0.5; - - for (i = 1; i <= n7; i++) - { - x = t * DATAN(t2 * DSIN(x) * DCOS(x) / - (DCOS(x + y) + DCOS(x - y) - 1.0)); - y = t * DATAN(t2 * DSIN(y) * DCOS(y) / - (DCOS(x + y) + DCOS(x - y) - 1.0)); - } - -#ifdef PRINTOUT - IF (jj == ii) - { - pout(n7, j, k, x, x, y, y); - } -#endif - - /* Module 8: Procedure calls */ - - x = 1.0; - y = 1.0; - z = 1.0; - - for (i = 1; i <= n8; i++) - { - p3(x, y, &z); - } - -#ifdef PRINTOUT - IF (jj == ii) - { - pout(n8, j, k, x, y, z, z); - } -#endif - - /* Module 9: Array references */ - - j = 1; - k = 2; - l = 3; - e1[1] = 1.0; - e1[2] = 2.0; - e1[3] = 3.0; - - for (i = 1; i <= n9; i++) - { - p0(); - } - -#ifdef PRINTOUT - IF (jj == ii) - { - pout(n9, j, k, e1[1], e1[2], e1[3], e1[4]); - } -#endif - - /* Module 10: Integer arithmetic */ - - j = 2; - k = 3; - - for (i = 1; i <= n10; i++) - { - j = j + k; - k = j + k; - j = k - j; - k = k - j - j; - } - -#ifdef PRINTOUT - IF (jj == ii) - { - pout(n10, j, k, x1, x2, x3, x4); - } -#endif - - /* Module 11: Standard functions */ - - x = 0.75; - - for (i = 1; i <= n11; i++) - x = DSQRT(DEXP(DLOG(x) / t1)); - -#ifdef PRINTOUT - IF (jj == ii) - { - pout(n11, j, k, x, x, x, x); - } -#endif - - /* THIS IS THE END OF THE MAJOR loop. */ - - if (++jj <= ii) - { - goto IILOOP; - } - - /* Stop benchmark timing at this point. */ - - clock_gettime(CLOCK_REALTIME, &ts); - finimsec = ts.tv_sec * 1000 + ts.tv_nsec / 1000000; - - /* Performance in Whetstone KIP's per second is given by - * - * (100*loop*ii)/TIME - * - * where TIME is in seconds. - */ - - printf("\n"); - if (finimsec - startmsec <= 0) - { - printf("Insufficient duration- Increase the loop count\n"); - return 1; - } - - printf("Loops: %ld, Iterations: %d, Duration: %ld millisecond.\n", - loop, ii, finimsec - startmsec); - - KIPS = (100.0 * loop * ii) / ((float)(finimsec - startmsec) * 1000); - if (KIPS >= 1000.0) - { - printf("C Converted Double Precision Whetstones: %.1f MIPS\n", - KIPS / 1000.0); - } - else - { - printf("C Converted Double Precision Whetstones: %.1f KIPS\n", KIPS); - } - - if (continuous) - { - goto LCONT; - } - - return 0; -} - -void -pa(double e[]) -{ - j = 0; - -L10: - e[1] = (e[1] + e[2] + e[3] - e[4]) * t; - e[2] = (e[1] + e[2] - e[3] + e[4]) * t; - e[3] = (e[1] - e[2] + e[3] + e[4]) * t; - e[4] = (-e[1] + e[2] + e[3] + e[4]) / t2; - j += 1; - - if (j < 6) - { - goto L10; - } -} - -void -p0(void) -{ - e1[j] = e1[k]; - e1[k] = e1[l]; - e1[l] = e1[j]; -} - -void p3(double x, double y, FAR double *z) -{ - double x1; - double y1; - - x1 = x; - y1 = y; - x1 = t * (x1 + y1); - y1 = t * (x1 + y1); - *z = (x1 + y1) / t2; -} - -#ifdef PRINTOUT -void -pout(long n, long j, long k, double x1, double x2, double x3, double x4) -{ - printf("%7ld %7ld %7ld %12.4e %12.4e %12.4e %12.4e\n", - n, j, k, x1, x2, x3, x4); -} -#endif diff --git a/boot/CMakeLists.txt b/boot/CMakeLists.txt deleted file mode 100644 index 4a418db7c..000000000 --- a/boot/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -# ############################################################################## -# apps/boot/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -nuttx_add_subdirectory() - -nuttx_generate_kconfig(MENUDESC "Bootloader Utilities") diff --git a/boot/Make.defs b/boot/Make.defs index 78765dbdb..b0e6794f6 100644 --- a/boot/Make.defs +++ b/boot/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/boot/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/boot/Makefile b/boot/Makefile index 3bbae8765..e20a7c4a3 100644 --- a/boot/Makefile +++ b/boot/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/boot/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/boot/mcuboot/CMakeLists.txt b/boot/mcuboot/CMakeLists.txt deleted file mode 100644 index 49c02a133..000000000 --- a/boot/mcuboot/CMakeLists.txt +++ /dev/null @@ -1,113 +0,0 @@ -# ############################################################################## -# apps/boot/mcuboot/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_BOOT_MCUBOOT) - nuttx_add_library(mcuboot) - - if(NOT EXISTS ${CMAKE_CURRENT_LIST_DIR}/mcuboot) - FetchContent_Declare( - mcuboot - DOWNLOAD_NAME "${CONFIG_MCUBOOT_VERSION}.tar.gz" - DOWNLOAD_DIR ${CMAKE_CURRENT_LIST_DIR} - URL "https://github.com/mcu-tools/mcuboot/archive/${CONFIG_MCUBOOT_VERSION}.tar.gz" - SOURCE_DIR - ${CMAKE_CURRENT_LIST_DIR}/mcuboot - BINARY_DIR - ${CMAKE_BINARY_DIR}/apps/boot/mcuboot/mcuboot - DOWNLOAD_NO_PROGRESS true - TIMEOUT 30) - - FetchContent_GetProperties(mcuboot) - - if(NOT mcuboot_POPULATED) - FetchContent_Populate(mcuboot) - endif() - endif() - - set(SRCS - mcuboot/boot/bootutil/src/boot_record.c - mcuboot/boot/bootutil/src/bootutil_area.c - mcuboot/boot/bootutil/src/bootutil_img_hash.c - mcuboot/boot/bootutil/src/bootutil_loader.c - mcuboot/boot/bootutil/src/bootutil_misc.c - mcuboot/boot/bootutil/src/bootutil_public.c - mcuboot/boot/bootutil/src/caps.c - mcuboot/boot/bootutil/src/encrypted.c - mcuboot/boot/bootutil/src/fault_injection_hardening.c - mcuboot/boot/bootutil/src/fault_injection_hardening_delay_rng_mbedtls.c - mcuboot/boot/bootutil/src/image_ed25519.c - mcuboot/boot/bootutil/src/image_rsa.c - mcuboot/boot/bootutil/src/image_validate.c - mcuboot/boot/bootutil/src/loader.c - mcuboot/boot/bootutil/src/swap_misc.c - mcuboot/boot/bootutil/src/swap_move.c - mcuboot/boot/bootutil/src/swap_scratch.c - mcuboot/boot/bootutil/src/tlv.c) - - list(APPEND SRCS mcuboot/boot/nuttx/src/flash_map_backend/flash_map_backend.c) - - if(CONFIG_MCUBOOT_BOOTLOADER) - nuttx_add_application( - NAME - mcuboot_loader - SRCS - ${CMAKE_CURRENT_LIST_DIR}/mcuboot/boot/nuttx/main.c - INCLUDE_DIRECTORIES - mcuboot/boot/bootutil/include - mcuboot/boot/nuttx/include - STACKSIZE - ${CONFIG_DEFAULT_TASK_STACKSIZE} - PRIORITY - SCHED_PRIORITY_DEFAULT) - endif() - - if(CONFIG_MCUBOOT_WATCHDOG) - list(APPEND SRCS mcuboot/boot/nuttx/src/watchdog/watchdog.c) - endif() - - if(CONFIG_MCUBOOT_USE_TINYCRYPT) - list( - APPEND - SRCS - mcuboot/ext/tinycrypt/lib/source/aes_encrypt.c - mcuboot/ext/tinycrypt/lib/source/aes_decrypt.c - mcuboot/ext/tinycrypt/lib/source/ctr_mode.c - mcuboot/ext/tinycrypt/lib/source/hmac.c - mcuboot/ext/tinycrypt/lib/source/ecc_dh.c - mcuboot/ext/tinycrypt/lib/source/sha256.c - mcuboot/ext/tinycrypt/lib/source/utils.c) - target_include_directories(mcuboot - PRIVATE mcuboot/ext/tinycrypt/lib/include) - endif() - - set(INCDIR ${CMAKE_CURRENT_LIST_DIR}/mcuboot/boot/nuttx/include - ${CMAKE_CURRENT_LIST_DIR}/mcuboot/boot/bootutil/include) - target_include_directories(mcuboot PRIVATE ${INCDIR}) - - target_compile_options(mcuboot PRIVATE -Wno-undef) - target_sources(mcuboot PRIVATE ${SRCS}) - - set_property( - TARGET nuttx - APPEND - PROPERTY NUTTX_INCLUDE_DIRECTORIES ${INCDIR}) -endif() diff --git a/boot/mcuboot/Kconfig b/boot/mcuboot/Kconfig index 656861d73..70a41eb7c 100644 --- a/boot/mcuboot/Kconfig +++ b/boot/mcuboot/Kconfig @@ -12,21 +12,9 @@ menuconfig BOOT_MCUBOOT if BOOT_MCUBOOT -config MCUBOOT_REPOSITORY - string "MCUboot GIT repository" - default "github.com/mcu-tools/mcuboot" - ---help--- - Specifies the location of MCUboot GIT repository . This - is by default MCUboot main GIT repository, but it can be changed - to user's fork if required. - config MCUBOOT_VERSION string "MCUboot version" - default "e36d3c8d6ca5e0ed1f510f2a7d110f405a7c396b" - ---help--- - Defines MCUboot version to be downloaded. Either release tag - or commit hash should be specified. Using newer MCUboot version - may cause compatibility issues. + default "bb927ac014787992f2d8b42c7bd5d05eb4c17e05" config MCUBOOT_ENABLE_LOGGING bool "Enable MCUboot logging" @@ -112,6 +100,46 @@ config MCUBOOT_DIRECT_XIP_REVERT depends on MCUBOOT_DIRECT_XIP default n +config MCUBOOT_UPDATE_AGENT_EXAMPLE + bool "MCUboot update agent example" + default n + depends on NET_TCP + ---help--- + Example application that implements an update agent that downloads + an application firmware image from a given URL and saves it to the + secondary slot as a pending update. + +if MCUBOOT_UPDATE_AGENT_EXAMPLE + +config MCUBOOT_UPDATE_AGENT_EXAMPLE_UPDATE_URL + string "URL for update image" + default "" + +config MCUBOOT_UPDATE_AGENT_EXAMPLE_DL_BUFFER_SIZE + int "Download buffer size in bytes" + default 512 + +config MCUBOOT_UPDATE_AGENT_EXAMPLE_DL_VERIFY_MD5 + bool "Calculate MD5 of update image" + default n + depends on CODECS_HASH_MD5 + +config MCUBOOT_UPDATE_AGENT_EXAMPLE_DL_MD5_HASH + string "Expected MD5 sum of update image" + default "" + depends on MCUBOOT_UPDATE_AGENT_EXAMPLE_DL_VERIFY_MD5 + +endif # MCUBOOT_UPDATE_AGENT_EXAMPLE + +config MCUBOOT_SLOT_CONFIRM_EXAMPLE + tristate "MCUboot slot confirm example" + default n + ---help--- + Example application for confirming a newly installed application + application firmware image using MCUboot public APIs. + This application should be used as the OTA update package of the + MCUBOOT_UPDATE_AGENT_EXAMPLE example. + config MCUBOOT_WATCHDOG bool "Watchdog feeding support" default n diff --git a/boot/mcuboot/Make.defs b/boot/mcuboot/Make.defs index 446a785e2..ea684ad19 100644 --- a/boot/mcuboot/Make.defs +++ b/boot/mcuboot/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/boot/mcuboot/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -20,17 +18,24 @@ # ############################################################################ -ifneq ($(CONFIG_BOOT_MCUBOOT),) +ifeq ($(CONFIG_BOOT_MCUBOOT),y) CONFIGURED_APPS += $(APPDIR)/boot/mcuboot # It allows import of NuttX implementation headers for MCUboot interfaces. -CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/boot/mcuboot/mcuboot/boot/nuttx/include -CXXFLAGS += ${INCDIR_PREFIX}$(APPDIR)/boot/mcuboot/mcuboot/boot/nuttx/include +CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(APPDIR)/boot/mcuboot/mcuboot/boot/nuttx/include} +CXXFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(APPDIR)/boot/mcuboot/mcuboot/boot/nuttx/include} # It allows import of MCUboot's bootutil library headers. -CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/boot/mcuboot/mcuboot/boot/bootutil/include -CXXFLAGS += ${INCDIR_PREFIX}$(APPDIR)/boot/mcuboot/mcuboot/boot/bootutil/include +CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(APPDIR)/boot/mcuboot/mcuboot/boot/bootutil/include} +CXXFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(APPDIR)/boot/mcuboot/mcuboot/boot/bootutil/include} + +# It allows import of MCUboot's crypto backend library headers. + +ifeq ($(CONFIG_MCUBOOT_USE_TINYCRYPT),y) +CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(APPDIR)/boot/mcuboot/mcuboot/ext/tinycrypt/lib/include/} +CXXFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(APPDIR)/boot/mcuboot/mcuboot/ext/tinycrypt/lib/include/} +endif endif diff --git a/boot/mcuboot/Makefile b/boot/mcuboot/Makefile index 6c036147f..9914fee0c 100644 --- a/boot/mcuboot/Makefile +++ b/boot/mcuboot/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/boot/mcuboot/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -22,67 +20,78 @@ include $(APPDIR)/Make.defs -MCUBOOT_VERSION := $(patsubst "%",%,$(CONFIG_MCUBOOT_VERSION)) -MCUBOOT_REPOSITORY := $(patsubst "%",%,$(CONFIG_MCUBOOT_REPOSITORY)) -MCUBOOT_TARBALL = $(MCUBOOT_VERSION).tar.gz -MCUBOOT_UNPACK = mcuboot -MCUBOOT_SRCDIR = $(MCUBOOT_UNPACK)$(DELIM)boot$(DELIM)bootutil$(DELIM)src +MCUBOOT_VERSION := $(patsubst "%",%,$(CONFIG_MCUBOOT_VERSION)) +MCUBOOT_TARBALL = $(MCUBOOT_VERSION).tar.gz +MCUBOOT_UNPACK = mcuboot +MCUBOOT_SRCDIR = $(MCUBOOT_UNPACK)$(DELIM)boot$(DELIM)bootutil$(DELIM)src DEPPATH += --dep-path $(MCUBOOT_UNPACK)$(DELIM)src DEPPATH += --dep-path $(MCUBOOT_SRCDIR) VPATH += :$(MCUBOOT_UNPACK)$(DELIM)src VPATH += :$(MCUBOOT_SRCDIR) +ifneq ($(CONFIG_MCUBOOT_UPDATE_AGENT_EXAMPLE),) +MAINSRC += mcuboot_agent_main.c + +PROGNAME += mcuboot_agent +PRIORITY += SCHED_PRIORITY_DEFAULT +STACKSIZE += $(CONFIG_DEFAULT_TASK_STACKSIZE) +endif + +ifneq ($(CONFIG_MCUBOOT_SLOT_CONFIRM_EXAMPLE),) +MAINSRC += mcuboot_confirm_main.c + +PROGNAME += mcuboot_confirm +PRIORITY += SCHED_PRIORITY_DEFAULT +STACKSIZE += $(CONFIG_DEFAULT_TASK_STACKSIZE) +endif + ifneq ($(CONFIG_MCUBOOT_BOOTLOADER),) -MAINSRC += $(MCUBOOT_UNPACK)/boot/nuttx/main.c +MAINSRC += mcuboot/boot/nuttx/main.c PROGNAME += mcuboot_loader PRIORITY += SCHED_PRIORITY_DEFAULT STACKSIZE += $(CONFIG_DEFAULT_TASK_STACKSIZE) endif -CFLAGS += -Wno-undef -Wno-unused-but-set-variable +CFLAGS += -Wno-undef -CSRCS := $(MCUBOOT_UNPACK)/boot/bootutil/src/boot_record.c \ - $(MCUBOOT_UNPACK)/boot/bootutil/src/bootutil_area.c \ - $(MCUBOOT_UNPACK)/boot/bootutil/src/bootutil_img_hash.c \ - $(MCUBOOT_UNPACK)/boot/bootutil/src/bootutil_loader.c \ - $(MCUBOOT_UNPACK)/boot/bootutil/src/bootutil_misc.c \ - $(MCUBOOT_UNPACK)/boot/bootutil/src/bootutil_public.c \ - $(MCUBOOT_UNPACK)/boot/bootutil/src/caps.c \ - $(MCUBOOT_UNPACK)/boot/bootutil/src/encrypted.c \ - $(MCUBOOT_UNPACK)/boot/bootutil/src/fault_injection_hardening.c \ - $(MCUBOOT_UNPACK)/boot/bootutil/src/fault_injection_hardening_delay_rng_mbedtls.c \ - $(MCUBOOT_UNPACK)/boot/bootutil/src/image_ed25519.c \ - $(MCUBOOT_UNPACK)/boot/bootutil/src/image_rsa.c \ - $(MCUBOOT_UNPACK)/boot/bootutil/src/image_validate.c \ - $(MCUBOOT_UNPACK)/boot/bootutil/src/loader.c \ - $(MCUBOOT_UNPACK)/boot/bootutil/src/swap_misc.c \ - $(MCUBOOT_UNPACK)/boot/bootutil/src/swap_move.c \ - $(MCUBOOT_UNPACK)/boot/bootutil/src/swap_scratch.c \ - $(MCUBOOT_UNPACK)/boot/bootutil/src/tlv.c \ - $(MCUBOOT_UNPACK)/boot/nuttx/src/flash_map_backend/flash_map_backend.c +CSRCS := mcuboot/boot/bootutil/src/boot_record.c \ + mcuboot/boot/bootutil/src/bootutil_misc.c \ + mcuboot/boot/bootutil/src/bootutil_public.c \ + mcuboot/boot/bootutil/src/caps.c \ + mcuboot/boot/bootutil/src/encrypted.c \ + mcuboot/boot/bootutil/src/fault_injection_hardening.c \ + mcuboot/boot/bootutil/src/fault_injection_hardening_delay_rng_mbedtls.c \ + mcuboot/boot/bootutil/src/image_ec.c \ + mcuboot/boot/bootutil/src/image_ec256.c \ + mcuboot/boot/bootutil/src/image_ed25519.c \ + mcuboot/boot/bootutil/src/image_rsa.c \ + mcuboot/boot/bootutil/src/image_validate.c \ + mcuboot/boot/bootutil/src/loader.c \ + mcuboot/boot/bootutil/src/swap_misc.c \ + mcuboot/boot/bootutil/src/swap_move.c \ + mcuboot/boot/bootutil/src/swap_scratch.c \ + mcuboot/boot/bootutil/src/tlv.c \ + mcuboot/boot/nuttx/src/flash_map_backend/flash_map_backend.c ifneq ($(CONFIG_MCUBOOT_WATCHDOG),) -CSRCS += $(MCUBOOT_UNPACK)/boot/nuttx/src/watchdog/watchdog.c +CSRCS += mcuboot/boot/nuttx/src/watchdog/watchdog.c endif ifneq ($(CONFIG_MCUBOOT_USE_TINYCRYPT),) -CSRCS += $(MCUBOOT_UNPACK)/ext/tinycrypt/lib/source/aes_encrypt.c \ - $(MCUBOOT_UNPACK)/ext/tinycrypt/lib/source/aes_decrypt.c \ - $(MCUBOOT_UNPACK)/ext/tinycrypt/lib/source/ctr_mode.c \ - $(MCUBOOT_UNPACK)/ext/tinycrypt/lib/source/hmac.c \ - $(MCUBOOT_UNPACK)/ext/tinycrypt/lib/source/ecc_dh.c \ - $(MCUBOOT_UNPACK)/ext/tinycrypt/lib/source/sha256.c \ - $(MCUBOOT_UNPACK)/ext/tinycrypt/lib/source/utils.c - -CFLAGS += ${INCDIR_PREFIX}mcuboot/ext/tinycrypt/lib/include -CXXFLAGS += ${INCDIR_PREFIX}mcuboot/ext/tinycrypt/lib/include +CSRCS += mcuboot/ext/tinycrypt/lib/source/aes_encrypt.c \ + mcuboot/ext/tinycrypt/lib/source/aes_decrypt.c \ + mcuboot/ext/tinycrypt/lib/source/ctr_mode.c \ + mcuboot/ext/tinycrypt/lib/source/hmac.c \ + mcuboot/ext/tinycrypt/lib/source/ecc_dh.c \ + mcuboot/ext/tinycrypt/lib/source/sha256.c \ + mcuboot/ext/tinycrypt/lib/source/utils.c endif $(MCUBOOT_TARBALL): - $(Q) echo "Downloading MCUboot-$(MCUBOOT_VERSION) from $(MCUBOOT_REPOSITORY)" - $(Q) curl -O -L --proto-default https $(MCUBOOT_REPOSITORY)/archive/$(MCUBOOT_TARBALL) + $(Q) echo "Downloading MCUboot-$(MCUBOOT_VERSION)" + $(Q) curl -O -L https://github.com/mcu-tools/mcuboot/archive/$(MCUBOOT_TARBALL) $(MCUBOOT_UNPACK): $(MCUBOOT_TARBALL) $(Q) echo "Unpacking: $(MCUBOOT_TARBALL) -> $(MCUBOOT_UNPACK)" @@ -90,13 +99,10 @@ $(MCUBOOT_UNPACK): $(MCUBOOT_TARBALL) $(Q) mv mcuboot-$(MCUBOOT_VERSION) $(MCUBOOT_UNPACK) $(Q) touch $(MCUBOOT_UNPACK) -# Download and unpack tarball if no git repo found -ifeq ($(wildcard $(MCUBOOT_UNPACK)/.git),) context:: $(MCUBOOT_UNPACK) distclean:: $(call DELFILE, $(MCUBOOT_TARBALL)) $(call DELDIR, $(MCUBOOT_UNPACK)) -endif include $(APPDIR)/Application.mk diff --git a/boot/mcuboot/README.md b/boot/mcuboot/README.md new file mode 100644 index 000000000..39a693545 --- /dev/null +++ b/boot/mcuboot/README.md @@ -0,0 +1,52 @@ +# Boot / `mcuboot` MCUboot + +## Description + +The NuttX port of MCUboot secure boot library expects that the platform provides a Flash storage with the following partitions: +- `CONFIG_MCUBOOT_PRIMARY_SLOT_PATH`: MTD partition for the application firmware image PRIMARY slot; +- `CONFIG_MCUBOOT_SECONDARY_SLOT_PATH`: MTD partition for the application firmware image SECONDARY slot; +- `CONFIG_MCUBOOT_SCRATCH_PATH`: MTD partition for the Scratch area; + +Also, these are optional features that may be enabled: + +- `CONFIG_MCUBOOT_WATCHDOG`: If `CONFIG_WATCHDOG` is enabled, MCUboot shall reset the watchdog timer indicated by `CONFIG_MCUBOOT_WATCHDOG_DEVPATH` to the current timeout value, preventing any imminent watchdog timeouts. + +The porting layer of MCUboot library consists of the following interfaces: +- `<flash_map_backend/flash_map_backend.h>`, for enabling MCUboot to manage the application firmware image slots in the device storage. +- `<mcuboot_config/mcuboot_config.h>`, for configuration of MCUboot's features. +- `<mcuboot_config/mcuboot_logging.h>`, for providing logging capabilities. +- `<os/os_malloc.h>`, for providing MCUboot access to the OS memory management interfaces. +- `<sysflash/sysflash.h>`, for configuration of the system's flash area organization. + +The NuttX port of MCUboot is implemented at application-level and requires minimal knowledge about characteristics of the underlying storage device. This is achieved by means of the `BCH` and `FTL` subsystems, which enable MCUboot to manage MTD partitions via character device drivers using standard POSIX filesystem operations (e.g. `open()` / `close()` / `read()` / `write()`). + +## Creating MCUboot-compatible application firmware images + +One common use case for MCUboot is to integrate it to a firmware update agent, which is an important component of a secure firmware update subsystem. Through MCUboot APIs an application is able to install a newly received application firmware image and, once this application firmware image is assured to be valid, the application may confirm it as a stable image. In case that application firmware image is deemed bogus, MCUboot provides an API for invalidating that update, which will induce a rollback procedure to the most recent stable application firmware image. + +The `CONFIG_MCUBOOT_UPDATE_AGENT_EXAMPLE` example demonstrates this workflow by downloading an application firmware image from a webserver, installing it and triggering the firmware update process for the next boot after a system reset. There is also the `CONFIG_MCUBOOT_SLOT_CONFIRM_EXAMPLE`, which is a fairly simple example that just calls an MCUboot API for confirming the executing application firmware image as stable. + +## Using MCUboot on NuttX as a secure boot solution + +NuttX port for MCUboot also enables the creation of a secure bootloader application requiring minimal platform-specific implementation. The logical implementation for the secure boot is performed at application-level by the MCUboot library. Once MCUboot validates the application firmware image, it delegates the loading and execution of the application firmware image to a platform-specific routine, which is accessed via `boardctl(BOARDIOC_BOOT_IMAGE)` call. Each platform must then provide an implementation for the `board_boot_image()` for executing the required actions in order to boot a new application firmware image (e.g. deinitialize peripherals, load the Program Counter register with the application firmware image entry point address). + +The MCUboot bootloader application may be enabled by selecting the `CONFIG_MCUBOOT_BOOTLOADER` option. + +## Assumptions + +### IOCTL MTD commands + +The implementation of `<flash_map_backend/flash_map_backend.h>` expects that the MTD driver for a given image partition handles the following `ioctl` commands: +- `MTDIOC_GEOMETRY`, for retrieving information about the geometry of the MTD, required for the configuration of the size of each flash area. +- `MTDIOC_ERASESTATE`, for retrieving the byte value of an erased cell of the MTD, required for the implementation of `flash_area_erased_val()` interface. + +### Write access alignment + +Through `flash_area_align()` interface MCUboot expects that the implementation provides the shortest data length that may be written via `flash_area_write()` interface. The NuttX implementation passes through the `BCH` and `FTL` layers, which appropriately handle the write alignment restrictions of the underlying MTD. So The NuttX implementation of `flash_area_align()` is able to return a fixed value of 1 byte, even if the MTD does not support byte operations. + +## Limitations + +### `<flash_map_backend/flash_map_backend.h>` functions are not multitasking-safe + +MCUboot's documentation imposes no restrictions regarding the usage of its public interfaces, which doesn't mean they are thread-safe. +But, regarding NuttX implementation of the `<flash_map_backend/flash_map_backend.h>`, it is safe to state that they are **not** multitasking-safe. NuttX implementation manages the MTD partitions via character device drivers. As file-descriptors cannot be shared between different tasks, if one task calls `flash_area_open` and another task calls `flash_area_<read/write/close>` passing the same `struct flash_area` instance, it will result in failure. diff --git a/examples/mcuboot/update_agent/mcuboot_agent_main.c b/boot/mcuboot/mcuboot_agent_main.c similarity index 90% rename from examples/mcuboot/update_agent/mcuboot_agent_main.c rename to boot/mcuboot/mcuboot_agent_main.c index 697825acb..0a33b08b9 100644 --- a/examples/mcuboot/update_agent/mcuboot_agent_main.c +++ b/boot/mcuboot/mcuboot_agent_main.c @@ -1,7 +1,5 @@ /**************************************************************************** - * apps/examples/mcuboot/update_agent/mcuboot_agent_main.c - * - * SPDX-License-Identifier: Apache-2.0 + * apps/boot/mcuboot/mcuboot_agent_main.c * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -40,7 +38,7 @@ #include <bootutil/bootutil_public.h> -#ifdef CONFIG_EXAMPLES_MCUBOOT_UPDATE_AGENT_DL_VERIFY_MD5 +#ifdef CONFIG_MCUBOOT_UPDATE_AGENT_EXAMPLE_DL_VERIFY_MD5 #include "netutils/md5.h" #endif #include "netutils/netlib.h" @@ -53,14 +51,14 @@ * Preprocessor Definitions ****************************************************************************/ -#define DL_BUFFER_SIZE CONFIG_EXAMPLES_MCUBOOT_UPDATE_AGENT_DL_BUFFER_SIZE +#define DL_BUFFER_SIZE CONFIG_MCUBOOT_UPDATE_AGENT_EXAMPLE_DL_BUFFER_SIZE -#define DL_UPDATE_URL CONFIG_EXAMPLES_MCUBOOT_UPDATE_AGENT_UPDATE_URL +#define DL_UPDATE_URL CONFIG_MCUBOOT_UPDATE_AGENT_EXAMPLE_UPDATE_URL -#ifdef CONFIG_EXAMPLES_MCUBOOT_UPDATE_AGENT_DL_VERIFY_MD5 +#ifdef CONFIG_MCUBOOT_UPDATE_AGENT_EXAMPLE_DL_VERIFY_MD5 # define MD5_HASH_LENGTH 32 # define MD5_DIGEST_LENGTH 16 -# define MD5_EXPECTED_HASH CONFIG_EXAMPLES_MCUBOOT_UPDATE_AGENT_DL_MD5_HASH +# define MD5_EXPECTED_HASH CONFIG_MCUBOOT_UPDATE_AGENT_EXAMPLE_DL_MD5_HASH #endif /**************************************************************************** @@ -72,7 +70,7 @@ struct download_context_s FAR const struct flash_area *fa; uint32_t fa_offset; ssize_t image_size; -#ifdef CONFIG_EXAMPLES_MCUBOOT_UPDATE_AGENT_DL_VERIFY_MD5 +#ifdef CONFIG_MCUBOOT_UPDATE_AGENT_EXAMPLE_DL_VERIFY_MD5 MD5_CTX md5_ctx; #endif }; @@ -140,7 +138,7 @@ static int sink_callback(FAR char **buffer, int offset, int datend, ctx->fa_offset += length; -#ifdef CONFIG_EXAMPLES_MCUBOOT_UPDATE_AGENT_DL_VERIFY_MD5 +#ifdef CONFIG_MCUBOOT_UPDATE_AGENT_EXAMPLE_DL_VERIFY_MD5 md5_update(&ctx->md5_ctx, (FAR const unsigned char *)&((*buffer)[offset]), length); @@ -164,7 +162,7 @@ static int download_firmware_image(FAR const char *url) int ret; struct webclient_context client_ctx; struct download_context_s dl_ctx; -#ifdef CONFIG_EXAMPLES_MCUBOOT_UPDATE_AGENT_DL_VERIFY_MD5 +#ifdef CONFIG_MCUBOOT_UPDATE_AGENT_EXAMPLE_DL_VERIFY_MD5 uint8_t digest[MD5_DIGEST_LENGTH]; char hash[MD5_HASH_LENGTH + 1]; int i; @@ -174,7 +172,7 @@ static int download_firmware_image(FAR const char *url) dl_ctx.fa_offset = 0; dl_ctx.image_size = -1; -#ifdef CONFIG_EXAMPLES_MCUBOOT_UPDATE_AGENT_DL_VERIFY_MD5 +#ifdef CONFIG_MCUBOOT_UPDATE_AGENT_EXAMPLE_DL_VERIFY_MD5 md5_init(&dl_ctx.md5_ctx); #endif @@ -204,13 +202,12 @@ static int download_firmware_image(FAR const char *url) goto exit_close; } -#ifdef CONFIG_EXAMPLES_MCUBOOT_UPDATE_AGENT_DL_VERIFY_MD5 +#ifdef CONFIG_MCUBOOT_UPDATE_AGENT_EXAMPLE_DL_VERIFY_MD5 md5_final(digest, &dl_ctx.md5_ctx); for (i = 0; i < MD5_DIGEST_LENGTH; i++) { - snprintf(&hash[i * 2], sizeof(hash) - i * 2, - "%02x", digest[i]); + sprintf(&hash[i * 2], "%02x", digest[i]); } hash[MD5_HASH_LENGTH] = '\0'; diff --git a/examples/mcuboot/slot_confirm/mcuboot_confirm_main.c b/boot/mcuboot/mcuboot_confirm_main.c similarity index 94% rename from examples/mcuboot/slot_confirm/mcuboot_confirm_main.c rename to boot/mcuboot/mcuboot_confirm_main.c index 2f296b081..c11e8d0fb 100644 --- a/examples/mcuboot/slot_confirm/mcuboot_confirm_main.c +++ b/boot/mcuboot/mcuboot_confirm_main.c @@ -1,7 +1,5 @@ /**************************************************************************** - * apps/examples/mcuboot/slot_confirm/mcuboot_confirm_main.c - * - * SPDX-License-Identifier: Apache-2.0 + * apps/boot/mcuboot/mcuboot_confirm_main.c * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with diff --git a/boot/miniboot/CMakeLists.txt b/boot/miniboot/CMakeLists.txt deleted file mode 100644 index 2c488cec7..000000000 --- a/boot/miniboot/CMakeLists.txt +++ /dev/null @@ -1,29 +0,0 @@ -# ############################################################################## -# apps/boot/miniboot/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_BOOT_MINIBOOT) - nuttx_add_application( - NAME - miniboot - SRCS - miniboot_main.c) -endif() diff --git a/boot/miniboot/Kconfig b/boot/miniboot/Kconfig deleted file mode 100644 index c65509ca9..000000000 --- a/boot/miniboot/Kconfig +++ /dev/null @@ -1,27 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -menuconfig BOOT_MINIBOOT - bool "Minimal bootloader" - default n - select BOARDCTL_BOOT_IMAGE - ---help--- - Enable support for the minimal NuttX based bootloader. - -if BOOT_MINIBOOT - -config MINIBOOT_SLOT_PATH - string "Application firmware image slot path" - default "/dev/ota0" - ---help--- - The path to the application firmware image slot character - device driver. - Default: /dev/ota0 - -config MINIBOOT_HEADER_SIZE - hex "Application firmware image header size" - default 0x200 - -endif # BOOT_MINIBOOT diff --git a/boot/miniboot/Make.defs b/boot/miniboot/Make.defs deleted file mode 100644 index 0f082485d..000000000 --- a/boot/miniboot/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/boot/miniboot/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_BOOT_MINIBOOT),) -CONFIGURED_APPS += $(APPDIR)/boot/miniboot -endif diff --git a/boot/miniboot/Makefile b/boot/miniboot/Makefile deleted file mode 100644 index c5c4de340..000000000 --- a/boot/miniboot/Makefile +++ /dev/null @@ -1,31 +0,0 @@ -############################################################################ -# apps/boot/miniboot/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -PROGNAME = miniboot -PRIORITY = SCHED_PRIORITY_DEFAULT -STACKSIZE = $(CONFIG_DEFAULT_TASK_STACKSIZE) - -MAINSRC = miniboot_main.c - -include $(APPDIR)/Application.mk diff --git a/boot/miniboot/miniboot_main.c b/boot/miniboot/miniboot_main.c deleted file mode 100644 index ce490c45b..000000000 --- a/boot/miniboot/miniboot_main.c +++ /dev/null @@ -1,64 +0,0 @@ -/**************************************************************************** - * apps/boot/miniboot/miniboot_main.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <stdio.h> -#include <syslog.h> - -#include <sys/boardctl.h> - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: miniboot_main - * - * Description: - * Minimal bootloader entry point. - * - ****************************************************************************/ - -int main(int argc, FAR char *argv[]) -{ - struct boardioc_boot_info_s info; - - syslog(LOG_INFO, "*** miniboot ***\n"); - -#ifdef CONFIG_BOARDCTL_FINALINIT - /* Perform architecture-specific final-initialization (if configured) */ - - boardctl(BOARDIOC_FINALINIT, 0); -#endif - - /* Call board specific image boot */ - - info.path = CONFIG_MINIBOOT_SLOT_PATH; - info.header_size = CONFIG_MINIBOOT_HEADER_SIZE; - - return boardctl(BOARDIOC_BOOT_IMAGE, (uintptr_t)&info); -} diff --git a/boot/nxboot/CMakeLists.txt b/boot/nxboot/CMakeLists.txt deleted file mode 100644 index 1ea82b7a8..000000000 --- a/boot/nxboot/CMakeLists.txt +++ /dev/null @@ -1,34 +0,0 @@ -# ############################################################################## -# apps/boot/nxboot/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_BOOT_NXBOOT) - nuttx_add_library(nxboot) - set(SRCS loader/boot.c loader/flash.c) - - if(BOOT_NXBOOT) - nuttx_add_application(NAME nxboot_loader SRCS nxboot_main.c - INCLUDE_DIRECTORIES include) - endif() - - target_include_directories(nxboot PUBLIC include) - target_sources(nxboot PRIVATE ${SRCS}) -endif() diff --git a/boot/nxboot/Kconfig b/boot/nxboot/Kconfig deleted file mode 100644 index f8222e0f0..000000000 --- a/boot/nxboot/Kconfig +++ /dev/null @@ -1,159 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -menuconfig BOOT_NXBOOT - bool "NuttX bootloader" - default n - select BCH - ---help--- - Enable support for the minimal NuttX based bootloader. - -if BOOT_NXBOOT - -config NXBOOT_PRIMARY_SLOT_PATH - string "Application firmware primary image slot path" - default "/dev/ota0" - ---help--- - The path to the application firmware image primary slot character - device driver. The image runs from this location. - Default: /dev/ota0 - -config NXBOOT_SECONDARY_SLOT_PATH - string "Application firmware secondary image slot path" - default "/dev/ota1" - ---help--- - The path to the application firmware image primary slot character - device driver. This is either update or recovery slot. - Default: /dev/ota1 - -config NXBOOT_TERTIARY_SLOT_PATH - string "Application firmware tertiary image slot path" - default "/dev/ota2" - ---help--- - The path to the application firmware image primary slot character - device driver. This is either update or recovery slot. - Default: /dev/ota2 - -config NXBOOT_HEADER_SIZE - hex "Application firmware image header size" - default 0x200 - ---help--- - The nxboot bootloader itself requires only a few bytes of header - data. Increase this value, if you need to store additional - application-specific meta data. - Note that this size should be aligned with the program memory write - page size! - -config NXBOOT_PLATFORM_IDENTIFIER - hex "A unique platform identifier" - default 0x0 - ---help--- - This is a unique platform identifier used by the bootloader to - verify whether the image should be run on a given platform. An update - (or even a firmware uploaded via a programmer) is rejected if the - value in image's header doesn't match this option. - -config NXBOOT_BOOTLOADER - bool "Build nxboot bootloader application" - default n - select BOARDCTL - select BOARDCTL_BOOT_IMAGE - ---help--- - This option builds and links a bootloader application. This application - ("nxboot_loader_main") should be the entry function for NuttX. - It checks for a possible update/revert operation, performs it and boots - the correct image. - -if NXBOOT_BOOTLOADER - -config NXBOOT_COPY_TO_RAM - bool "Copy bootable image to RAM before calling board boot-image function" - default n - ---help--- - The is a board and/or arch specific option that may be used when running - directly from flash, especially if external flash, even in XIP mode, is too - slow. - Running from RAM usually results in faster execution but the board must, of - course, have sufficient RAM available for the application image, stack - and heap. - -config NXBOOT_RAMSTART - hex "Start address in RAM that the application is to be loaded" - default 0x0 - depends on NXBOOT_COPY_TO_RAM - ---help--- - This will be board specific. A check of the board's linker script - may be informative. For example the SAMA5D2-XULT eval board's uboot - linker script - boards/arm/sama5/sama5d2-xult/scripts/uboot.ld - has: - - sdram (W!RX) : ORIGIN = 0x20008000, LENGTH = 256M - 32K - - This shows the load address to be 0x20008000 and would be the address - to use here if the same linker script is to be be used for NXboot. - - Typically the address is the base address of the RAM to be used, plus the - size of the NXboot image itself. The example above has reserved - 32KiB (0x8000) for this from the 256MiB available on the board at - address 0x20000000. - -config NXBOOT_SWRESET_ONLY - bool "Perform update/revert only on SW reset" - default n - select BOARDCTL_RESET_CAUSE - ---help--- - This option ensures the update/revert is performed only for following - reset causes: - BOARDIOC_RESETCAUSE_CPU_SOFT: software reset - BOARDIOC_RESETCAUSE_CPU_RWDT: watchdog error - BOARDIOC_RESETCAUSE_PIN: reset button - - This way the board can keep its image (even if not confirmed) during - for example power shutdown and perform update/revent only if expected - based on user/maintainer input. - -config NXBOOT_PREVENT_DOWNGRADE - bool "Perform update only for newer version" - default n - ---help--- - NXboot uses Semantic Version 2.0.0 (without build metadata). By default - the update is performed for every version that doesn't match the - currently running one. If NXBOOT_PREVENT_DOWNGRADE selected, update is - performed only for newer versions (according to Semantic Version - preference rules). - - WARNING: NXboot currently implements preferences only for - MAJOR.MINOR.PATCH and ignores prerelease. - -config NXBOOT_PROGRESS - bool - default n - -config NXBOOT_PRINTF_PROGRESS - bool "Enable progress messages to be sent to STDOUT" - default y - select NXBOOT_PROGRESS - ---help--- - This will display progress during typically lengthy operations: - - Calculating checksums - - copying images between slots - - Note: the NXboot binary will be approximately 2KiB larger with this enabled. - -choice - prompt "Choose preferred progress indication type" - depends on NXBOOT_PRINTF_PROGRESS - default NXBOOT_PRINTF_PROGRESS_PERCENT - -config NXBOOT_PRINTF_PROGRESS_DOTS - bool "Display progress using sequential dots" - -config NXBOOT_PRINTF_PROGRESS_PERCENT - bool "Display progress using percentage remaining" - -endchoice - -endif # NXBOOT_BOOTLOADER - -endif # BOOT_NXBOOT diff --git a/boot/nxboot/Make.defs b/boot/nxboot/Make.defs deleted file mode 100644 index 4a472724d..000000000 --- a/boot/nxboot/Make.defs +++ /dev/null @@ -1,28 +0,0 @@ -############################################################################ -# apps/boot/nxboot/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_BOOT_NXBOOT),) -CONFIGURED_APPS += $(APPDIR)/boot/nxboot - -CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/boot/nxboot/include - -endif diff --git a/boot/nxboot/include/nxboot.h b/boot/nxboot/include/nxboot.h deleted file mode 100644 index 3d92e9753..000000000 --- a/boot/nxboot/include/nxboot.h +++ /dev/null @@ -1,283 +0,0 @@ -/**************************************************************************** - * apps/boot/nxboot/include/nxboot.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __BOOT_NXBOOT_INCLUDE_NXBOOT_H -#define __BOOT_NXBOOT_INCLUDE_NXBOOT_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> -#include <assert.h> -#include <stdbool.h> - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define ERROR -1 - -#define NXBOOT_PRIMARY_SLOT_NUM (0) -#define NXBOOT_SECONDARY_SLOT_NUM (1) -#define NXBOOT_TERTIARY_SLOT_NUM (2) - -#define NXBOOT_HEADER_MAGIC 0x534f584e /* NXOS. The NX images, both - * uploaded directly to primary - * partition via debugger and to - * update via some application - * are used with this magic. If - * this image is uploaded to - * primary flash, it is considered - * valid. - */ -#define NXBOOT_HEADER_MAGIC_INT 0xaca0abb0 /* NXOS internal. This is used - * for internal bootloader - * handling and operations. It is - * switch internally to distinguish - * between images uploaded via - * debugger or the ones updated - * after the bootloader performed - * its operation. The first two - * bits are reserved to point - * what partition is a recovery - * for this image. - */ - -#define NXBOOT_HEADER_MAGIC_INT_MASK 0xfffffff0 -#define NXBOOT_RECOVERY_PTR_MASK 0x3 - -#define NXBOOT_HEADER_PRERELEASE_MAXLEN 94 - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -enum nxboot_update_type -{ - NXBOOT_UPDATE_TYPE_NONE = 0, /* No action to do */ - NXBOOT_UPDATE_TYPE_UPDATE = 1, /* Update will take place upon reboot */ - NXBOOT_UPDATE_TYPE_REVERT = 2, /* Revert will take place upon reboot */ -}; - -/* Versioning is according to Semantic Versioning 2.0.0 - * refer to (https://semver.org/spec/v2.0.0.html) - */ - -struct nxboot_img_version -{ - uint16_t major; /* MAJOR version */ - uint16_t minor; /* MINOR version */ - uint16_t patch; /* PATCH version */ - - char pre_release[NXBOOT_HEADER_PRERELEASE_MAXLEN]; /* Additional pre-release version */ -}; - -struct nxboot_hdr_version -{ - uint8_t major; - uint8_t minor; -}; - -struct nxboot_img_header -{ - uint32_t magic; /* Header magic */ - struct nxboot_hdr_version hdr_version; /* Version of the header */ - - uint16_t header_size; /* Length of the header in bytes */ - uint32_t crc; /* CRC32 of image (excluding the previous - * fields in header, but including the following - * ones). - */ - uint32_t size; /* Image size (excluding the header) */ - uint64_t identifier; /* Platform identifier. An image is rejected - * if it does not match the one set for - * the bootloader in NXBOOT_PLATFORM_IDENTIFIER. - */ - uint32_t extd_hdr_ptr; /* Address of the next extended header. - * This is a hook for future additional headers. - */ - - struct nxboot_img_version img_version; /* Image version */ -}; - -static_assert(CONFIG_NXBOOT_HEADER_SIZE > sizeof(struct nxboot_img_header), - "CONFIG_NXBOOT_HEADER_SIZE has to be larger than" - "sizeof(struct nxboot_img_header)"); - -struct nxboot_state -{ - int update; /* Number of update slot */ - int recovery; /* Number of recovery slot */ - bool recovery_valid; /* True if recovery image contains valid recovery */ - bool recovery_present; /* True if the image in primary has a recovery */ - bool primary_confirmed; /* True if primary slot is confirmed */ - enum nxboot_update_type next_boot; /* nxboot_update_type with next operation */ -}; - -enum progress_type_e -{ - nxboot_info = 0, /* Prefixes arg. string with "INFO:" */ - nxboot_error, /* Prefixes arg. string with "ERR:" */ - nxboot_progress_start, /* Prints arg. string with no newline to allow ..... sequence to follow */ - nxboot_progress_dot, /* Prints of a "." to the ..... progress sequence */ - nxboot_progress_percent, /* Displays progress as % remaining */ - nxboot_progress_end, /* Flags end of a "..." progrees sequence and prints newline */ -}; - -enum progress_msg_e -{ - startup_msg = 0, - power_reset, - soft_reset, - found_bootable_image, - no_bootable_image, - boardioc_image_boot_fail, - ramcopy_started, - recovery_revert, - recovery_create, - update_from_update, - validate_primary, - validate_recovery, - validate_update, - recovery_created, - recovery_invalid, - update_failed, -}; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -#ifdef CONFIG_NXBOOT_PROGRESS -void nxboot_progress(int type, ...); -#else -#define nxboot_progress(type, ...) do {} while (0) -#endif - -/**************************************************************************** - * Name: nxboot_get_state - * - * Description: - * Gets the current bootloader state and stores it in the nxboot_state - * structure passed as an argument. This function may be used to determine - * which slot is update slot and where should application save incoming - * firmware. - * - * Input parameters: - * state: The pointer to nxboot_state structure. The state is stored here. - * - * Returned Value: - * OK (0) on success, ERROR (-1) and sets errno on failure. - * - ****************************************************************************/ - -int nxboot_get_state(struct nxboot_state *state); - -/**************************************************************************** - * Name: nxboot_open_update_partition - * - * Description: - * Gets the current bootloader state and opens the partition to which an - * update image should be stored. It returns the valid file descriptor to - * this partition, the user is responsible for writing to it and closing - * if afterwards. - * - * Returned Value: - * Valid file descriptor on success, ERROR (-1) and sets errno on failure. - * - ****************************************************************************/ - -int nxboot_open_update_partition(void); - -/**************************************************************************** - * Name: nxboot_get_confirm - * - * Description: - * This function can be used to determine whether primary image is - * confirmed or not. This provides more direct access to confirm - * state compared to nxboot_get_state function that returns the full - * state of the bootloader. - * - * Returned Value: - * 1 if confirmed, OK (0) on success, ERROR (-1) and sets errno on failure. - * - ****************************************************************************/ - -int nxboot_get_confirm(void); - -/**************************************************************************** - * Name: nxboot_confirm - * - * Description: - * Confirms the image currently located in primary partition and marks - * its copy in update partition as a recovery. - * - * Returned Value: - * OK (0) on success, ERROR (-1) and sets errno on failure. - * - ****************************************************************************/ - -int nxboot_confirm(void); - -/**************************************************************************** - * Name: nxboot_perform_update - * - * Description: - * Checks for the possible firmware update and performs it by copying - * update image to primary slot or recovery image to primary slot in case - * of the revert. In any situation, this function ends with the valid - * image in primary slot. - * - * This is an entry point function that should be called from the - * bootloader application. - * - * Input parameters: - * check_only: Only repairs corrupted update, but do not start another one - * - * Returned Value: - * OK (0) on success, ERROR (-1) and sets errno on failure. - * - ****************************************************************************/ - -int nxboot_perform_update(bool check_only); - -/**************************************************************************** - * Name: nxboot_ramcopy - * - * Description: - * Copies the (already) validate bootable image to RAM memory - * - * NOTE - no checking that the RAM location is correct, nor that the - * image size is appropriate for that RAM address! - * - * Input parameters: - * none - * - * Returned Value: - * OK (0) on success, ERROR (-1) on fail - * - ****************************************************************************/ - -int nxboot_ramcopy(void); - -#endif /* __BOOT_NXBOOT_INCLUDE_NXBOOT_H */ diff --git a/boot/nxboot/loader/boot.c b/boot/nxboot/loader/boot.c deleted file mode 100644 index c4f936d23..000000000 --- a/boot/nxboot/loader/boot.c +++ /dev/null @@ -1,933 +0,0 @@ -/**************************************************************************** - * apps/boot/nxboot/loader/boot.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> -#include <stdbool.h> -#include <stdio.h> -#include <stddef.h> -#include <errno.h> -#include <syslog.h> -#include <sys/param.h> - -#include <nuttx/crc32.h> -#include <nxboot.h> - -#include "flash.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#ifdef CONFIG_NXBOOT_PREVENT_DOWNGRADE - # warning "Downgrade prevention currently ignores prerelease." -#endif - -#define IS_INTERNAL_MAGIC(magic) ((magic & NXBOOT_HEADER_MAGIC_INT_MASK) \ - == NXBOOT_HEADER_MAGIC_INT) - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static inline void get_image_header(int fd, struct nxboot_img_header *header) -{ - int ret; - ret = flash_partition_read(fd, header, sizeof *header, 0); - if (ret < 0) - { - /* Something went wrong, treat the partition as empty. */ - - memset(header, 0, sizeof *header); - } -} - -static inline bool validate_image_header(struct nxboot_img_header *header) -{ - return (header->magic == NXBOOT_HEADER_MAGIC || - IS_INTERNAL_MAGIC(header->magic)) && - header->identifier == CONFIG_NXBOOT_PLATFORM_IDENTIFIER; -} - -static uint32_t calculate_crc(int fd, struct nxboot_img_header *header) -{ - char *buf; - int remain; - int readsiz; - off_t off; - uint32_t crc; - struct flash_partition_info info; -#ifdef CONFIG_NXBOOT_PRINTF_PROGRESS_PERCENT - int total_size; -#endif - - if (flash_partition_info(fd, &info) < 0) - { - return false; - } - - buf = malloc(info.blocksize); - if (!buf) - { - return false; - } - - crc = 0xffffffff; - off = offsetof(struct nxboot_img_header, crc) + sizeof crc; - remain = header->size + header->header_size - off; -#ifdef CONFIG_NXBOOT_PRINTF_PROGRESS_PERCENT - total_size = remain; -#endif - while (remain > 0) - { - readsiz = remain > info.blocksize ? info.blocksize : remain; - if (flash_partition_read(fd, buf, readsiz, off) != 0) - { - free(buf); - return 0xffffffff; - } - - off += readsiz; - remain -= readsiz; - crc = crc32part((uint8_t *)buf, readsiz, crc); - if ((remain % 25) == 0) - { -#ifdef CONFIG_NXBOOT_PRINTF_PROGRESS_PERCENT - nxboot_progress(nxboot_progress_percent, - ((total_size - remain) * 100) / total_size); -#else - nxboot_progress(nxboot_progress_dot); -#endif - } - } - - free(buf); - return ~crc; -} - -static int copy_partition(int from, int where, struct nxboot_state *state, - bool update) -{ - struct nxboot_img_header header; - struct flash_partition_info info_from; - struct flash_partition_info info_where; - uint32_t magic; - int readsiz; - int remain; - int blocksize; - off_t off; - char *buf; -#ifdef CONFIG_NXBOOT_PRINTF_PROGRESS_PERCENT - int total_size; -#endif - - get_image_header(from, &header); - - if (flash_partition_info(from, &info_from) < 0) - { - return ERROR; - } - - if (flash_partition_info(where, &info_where) < 0) - { - return ERROR; - } - - remain = header.size + header.header_size; - if (remain > info_where.size) - { - return ERROR; - } - -#ifdef CONFIG_NXBOOT_PRINTF_PROGRESS_PERCENT - total_size = remain; -#endif - blocksize = info_where.blocksize; - - buf = malloc(blocksize); - if (!buf) - { - return ERROR; - } - - /* Flip header's magic. We go from standard to internal in case of - * image update and from internal to standard in case of recovery - * creation or revert operation. - */ - - magic = IS_INTERNAL_MAGIC(header.magic) ? - NXBOOT_HEADER_MAGIC : NXBOOT_HEADER_MAGIC_INT; - - if (update) - { - /* This is update operation, add pointer to recovery image to the - * image's magic. - */ - - magic |= state->update; - } - - if (flash_partition_read(from, buf, blocksize, 0) < 0) - { - free(buf); - return ERROR; - } - - memcpy(buf + offsetof(struct nxboot_img_header, magic), &magic, - sizeof magic); - if (flash_partition_write(where, buf, blocksize, 0) < 0) - { - free(buf); - return ERROR; - } - - off = blocksize; - remain -= blocksize; - - while (remain > 0) - { - readsiz = remain > blocksize ? blocksize : remain; - if (flash_partition_read(from, buf, readsiz, off) < 0) - { - free(buf); - return ERROR; - } - - if (flash_partition_write(where, buf, readsiz, off) < 0) - { - free(buf); - return ERROR; - } - - off += readsiz; - remain -= readsiz; - if ((remain % 25) == 0) - { -#ifdef CONFIG_NXBOOT_PRINTF_PROGRESS_PERCENT - nxboot_progress(nxboot_progress_percent, - 100 - ((100 * remain) / total_size)); -#else - nxboot_progress(nxboot_progress_dot); -#endif - } - } - - free(buf); - return OK; -} - -static bool validate_image(int fd) -{ - struct nxboot_img_header header; - - get_image_header(fd, &header); - if (!validate_image_header(&header)) - { - return false; - } - - syslog(LOG_INFO, "Validating image.\n"); - return calculate_crc(fd, &header) == header.crc; -} - -static bool compare_versions(struct nxboot_img_version *v1, - struct nxboot_img_version *v2) -{ -#ifndef CONFIG_NXBOOT_PREVENT_DOWNGRADE - int i; - if (v1->major != v2->major || - v1->minor != v2->minor || - v1->patch != v2->patch) - { - return false; - } - - for (i = 0; i < NXBOOT_HEADER_PRERELEASE_MAXLEN; i++) - { - if (v1->pre_release[i] != v2->pre_release[i]) - { - return false; - } - } - - return true; -#else - if (v1->major > v2->major || - v1->minor > v2->minor || - v1->patch > v2->patch) - { - return true; - } - - if (v1->major == v2->major && - v1->minor == v2->minor && - v1->patch == v2->patch) - { - /* TODO: compare prerelease */ - } - - return false; -#endif -} - -static enum nxboot_update_type - get_update_type(struct nxboot_state *state, - int primary, int update, int recovery, - struct nxboot_img_header *primary_header, - struct nxboot_img_header *update_header, - struct nxboot_img_header *recovery_header) -{ - nxboot_progress(nxboot_progress_start, validate_primary); - bool primary_valid = validate_image(primary); - nxboot_progress(nxboot_progress_end); - - nxboot_progress(nxboot_progress_start, validate_update); - if (update_header->magic == NXBOOT_HEADER_MAGIC && validate_image(update)) - { - if (primary_header->crc != update_header->crc || - !compare_versions(&primary_header->img_version, - &update_header->img_version) || !primary_valid) - { - nxboot_progress(nxboot_progress_end); - return NXBOOT_UPDATE_TYPE_UPDATE; - } - - flash_partition_erase_first_sector(update); - } - - nxboot_progress(nxboot_progress_end); - - if (IS_INTERNAL_MAGIC(recovery_header->magic) && state->recovery_valid && - ((IS_INTERNAL_MAGIC(primary_header->magic) && - !state->primary_confirmed) || !primary_valid)) - { - return NXBOOT_UPDATE_TYPE_REVERT; - } - - return NXBOOT_UPDATE_TYPE_NONE; -} - -static int perform_update(struct nxboot_state *state, bool check_only) -{ - int successful; - int update; - int recovery; - int primary; - int secondary; - int tertiary; - bool primary_valid; - - primary = flash_partition_open(CONFIG_NXBOOT_PRIMARY_SLOT_PATH); - if (primary < 0) - { - return ERROR; - } - - secondary = flash_partition_open(CONFIG_NXBOOT_SECONDARY_SLOT_PATH); - if (secondary < 0) - { - flash_partition_close(primary); - return ERROR; - } - - tertiary = flash_partition_open(CONFIG_NXBOOT_TERTIARY_SLOT_PATH); - if (tertiary < 0) - { - flash_partition_close(primary); - flash_partition_close(secondary); - return ERROR; - } - - if (state->update == NXBOOT_SECONDARY_SLOT_NUM) - { - update = secondary; - recovery = tertiary; - } - else - { - update = tertiary; - recovery = secondary; - } - - nxboot_progress(nxboot_progress_start, validate_primary); - if (state->next_boot == NXBOOT_UPDATE_TYPE_REVERT && - (!check_only || !validate_image(primary))) - { - nxboot_progress(nxboot_progress_end); - if (state->recovery_valid) - { - syslog(LOG_INFO, "Reverting image to recovery.\n"); - nxboot_progress(nxboot_progress_start, recovery_revert); - copy_partition(recovery, primary, state, false); - nxboot_progress(nxboot_progress_end); - } - } - else - { - nxboot_progress(nxboot_progress_end); - nxboot_progress(nxboot_progress_start, validate_primary); - primary_valid = validate_image(primary); - nxboot_progress(nxboot_progress_end); - if (primary_valid && check_only) - { - /* Skip if primary image is valid (does not mather whether - * confirmed or not) and check_only option is set. - */ - - goto perform_update_done; - } - - if ((!state->recovery_present || !state->recovery_valid) && - state->primary_confirmed && primary_valid) - { - /* Save current image as recovery only if it is valid and - * confirmed. We have to check this in case of restart - * during update process. - * If board is restarted during update, primary slot contains - * non-valid image and we do not want to copy this image to - * recovery slot. - * There also might be a case where primary image is valid - * but not confirmed (timing of board reset right after - * update is uploaded to secondary). Still we do not want - * to upload this to recovery. - */ - - syslog(LOG_INFO, "Creating recovery image.\n"); - nxboot_progress(nxboot_progress_start, recovery_create); - copy_partition(primary, recovery, state, false); - flash_partition_flush(recovery); - nxboot_progress(nxboot_progress_end); - nxboot_progress(nxboot_progress_start, validate_recovery); - successful = validate_image(recovery); - nxboot_progress(nxboot_progress_end); - if (!successful) - { - syslog(LOG_INFO, - "New recovery is not valid,stop update.\n"); - nxboot_progress(nxboot_info, recovery_invalid); - goto perform_update_done; - } - - syslog(LOG_INFO, "Recovery image created.\n"); - nxboot_progress(nxboot_info, recovery_created); - } - - nxboot_progress(nxboot_progress_start, validate_update); - successful = validate_image(update); - nxboot_progress(nxboot_progress_end); - if (successful) - { - /* Perform update only if update slot contains valid image. */ - - syslog(LOG_INFO, "Updating from update image.\n"); - nxboot_progress(nxboot_progress_start, update_from_update); - if (copy_partition(update, primary, state, true) >= 0) - { - flash_partition_flush(primary); - - /* Erase the first sector of update partition. This marks the - * partition as updated so we don't end up in an update loop. - * The sector is written back again during the image - * confirmation. - */ - - flash_partition_erase_first_sector(update); - } - - nxboot_progress(nxboot_progress_end); - } - } - -perform_update_done: - flash_partition_close(primary); - flash_partition_close(secondary); - flash_partition_close(tertiary); - return OK; -} - -#ifdef CONFIG_NXBOOT_COPY_TO_RAM -int nxboot_ramcopy(void) -{ - int ret = OK; - int primary; - struct nxboot_img_header header; - ssize_t bytes; - static uint8_t *buf; - - primary = flash_partition_open(CONFIG_NXBOOT_PRIMARY_SLOT_PATH); - if (primary < 0) - { - return ERROR; - } - - get_image_header(primary, &header); - buf = malloc(header.size); - if (!buf) - { - ret = ERROR; - goto exit_with_error; - } - - bytes = pread(primary, buf, header.size, header.header_size); - if (bytes != header.size) - { - ret = ERROR; - goto exit_with_error; - } - - memcpy((uint32_t *)CONFIG_NXBOOT_RAMSTART, buf, header.size); - -exit_with_error: - flash_partition_close(primary); - free(buf); - - return ret; -} -#endif - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: nxboot_get_state - * - * Description: - * Gets the current bootloader state and stores it in the nxboot_state - * structure passed as an argument. This function may be used to determine - * which slot is update slot and where should application save incoming - * firmware. - * - * Input parameters: - * state: The pointer to nxboot_state structure. The state is stored here. - * - * Returned Value: - * 0 on success, -1 and sets errno on failure. - * - ****************************************************************************/ - -int nxboot_get_state(struct nxboot_state *state) -{ - int primary; - int secondary; - int tertiary; - int update; - int recovery; - int recovery_pointer; - struct nxboot_img_header primary_header; - struct nxboot_img_header secondary_header; - struct nxboot_img_header tertiary_header; - struct nxboot_img_header *update_header; - struct nxboot_img_header *recovery_header; - - memset(state, 0, sizeof *state); - - primary = flash_partition_open(CONFIG_NXBOOT_PRIMARY_SLOT_PATH); - if (primary < 0) - { - return ERROR; - } - - secondary = flash_partition_open(CONFIG_NXBOOT_SECONDARY_SLOT_PATH); - if (secondary < 0) - { - flash_partition_close(primary); - return ERROR; - } - - tertiary = flash_partition_open(CONFIG_NXBOOT_TERTIARY_SLOT_PATH); - if (tertiary < 0) - { - flash_partition_close(primary); - flash_partition_close(secondary); - return ERROR; - } - - get_image_header(primary, &primary_header); - get_image_header(secondary, &secondary_header); - get_image_header(tertiary, &tertiary_header); - - /* Determine which partition is for update and which is a recovery. - * This depends on many factors, but in general a partition with - * NXBOOT_HEADER_MAGIC is an update partition and partition with - * NXBOOT_HEADER_MAGIC_INT is a recovery. - * - * A special case is when both partitions have NXBOOT_HEADER_MAGIC_INT, - * then we look into a recovery pointer in primary header magic and - * determine the recovery from it. - */ - - update = secondary; - recovery = tertiary; - update_header = &secondary_header; - recovery_header = &tertiary_header; - state->update = NXBOOT_SECONDARY_SLOT_NUM; - state->recovery = NXBOOT_TERTIARY_SLOT_NUM; - - if (tertiary_header.magic == NXBOOT_HEADER_MAGIC) - { - update = tertiary; - recovery = secondary; - update_header = &tertiary_header; - recovery_header = &secondary_header; - state->recovery = NXBOOT_SECONDARY_SLOT_NUM; - state->update = NXBOOT_TERTIARY_SLOT_NUM; - } - else if (IS_INTERNAL_MAGIC(secondary_header.magic) && - IS_INTERNAL_MAGIC(tertiary_header.magic)) - { - if (IS_INTERNAL_MAGIC(primary_header.magic)) - { - recovery_pointer = primary_header.magic & NXBOOT_RECOVERY_PTR_MASK; - if (recovery_pointer == NXBOOT_SECONDARY_SLOT_NUM && - primary_header.crc == secondary_header.crc) - { - update = tertiary; - recovery = secondary; - update_header = &tertiary_header; - recovery_header = &secondary_header; - state->recovery = NXBOOT_SECONDARY_SLOT_NUM; - state->update = NXBOOT_TERTIARY_SLOT_NUM; - } - } - else if (primary_header.crc == secondary_header.crc) - { - update = tertiary; - recovery = secondary; - update_header = &tertiary_header; - recovery_header = &secondary_header; - state->recovery = NXBOOT_SECONDARY_SLOT_NUM; - state->update = NXBOOT_TERTIARY_SLOT_NUM; - } - } - else if (IS_INTERNAL_MAGIC(secondary_header.magic)) - { - update = tertiary; - recovery = secondary; - update_header = &tertiary_header; - recovery_header = &secondary_header; - state->recovery = NXBOOT_SECONDARY_SLOT_NUM; - state->update = NXBOOT_TERTIARY_SLOT_NUM; - } - - nxboot_progress(nxboot_progress_start, validate_recovery); - state->recovery_valid = validate_image(recovery); - nxboot_progress(nxboot_progress_end); - state->recovery_present = primary_header.crc == recovery_header->crc; - - /* The image is confirmed if it has either NXBOOT_HEADER_MAGIC or a - * recovery exists. - */ - - if (primary_header.magic == NXBOOT_HEADER_MAGIC) - { - state->primary_confirmed = true; - } - else if (IS_INTERNAL_MAGIC(primary_header.magic)) - { - recovery_pointer = primary_header.magic & NXBOOT_RECOVERY_PTR_MASK; - if (recovery_pointer == NXBOOT_SECONDARY_SLOT_NUM && - IS_INTERNAL_MAGIC(secondary_header.magic)) - { - state->primary_confirmed = - primary_header.crc == secondary_header.crc; - } - else if (recovery_pointer == NXBOOT_TERTIARY_SLOT_NUM && - IS_INTERNAL_MAGIC(tertiary_header.magic)) - { - state->primary_confirmed = - primary_header.crc == tertiary_header.crc; - } - } - - state->next_boot = get_update_type(state, primary, update, recovery, - &primary_header, update_header, - recovery_header); - - flash_partition_close(primary); - flash_partition_close(secondary); - flash_partition_close(tertiary); - return OK; -} - -/**************************************************************************** - * Name: nxboot_open_update_partition - * - * Description: - * Gets the current bootloader state and opens the partition to which an - * update image should be stored. It returns the valid file descriptor to - * this partition, the user is responsible for writing to it and closing - * if afterwards. - * - * Returned Value: - * Valid file descriptor on success, -1 and sets errno on failure. - * - ****************************************************************************/ - -int nxboot_open_update_partition(void) -{ - char *path; - struct nxboot_state state; - - nxboot_get_state(&state); - - path = state.update == NXBOOT_SECONDARY_SLOT_NUM ? - CONFIG_NXBOOT_SECONDARY_SLOT_PATH : CONFIG_NXBOOT_TERTIARY_SLOT_PATH; - - return flash_partition_open(path); -} - -/**************************************************************************** - * Name: nxboot_get_confirm - * - * Description: - * This function can be used to determine whether primary image is - * confirmed or not. This provides more direct access to confirm - * state compared to nxboot_get_state function that returns the full - * state of the bootloader. - * - * Returned Value: - * 1 means confirmed, 0 not confirmed, -1 and sets errno on failure. - * - ****************************************************************************/ - -int nxboot_get_confirm(void) -{ - int primary; - int recovery; - int recovery_pointer; - char *path; - int ret = OK; - struct nxboot_img_header primary_header; - struct nxboot_img_header recovery_header; - - primary = flash_partition_open(CONFIG_NXBOOT_PRIMARY_SLOT_PATH); - if (primary < 0) - { - return ERROR; - } - - get_image_header(primary, &primary_header); - - if (primary_header.magic == NXBOOT_HEADER_MAGIC) - { - close(primary); - return 1; - } - else if (IS_INTERNAL_MAGIC(primary_header.magic)) - { - recovery_pointer = primary_header.magic & NXBOOT_RECOVERY_PTR_MASK; - if (recovery_pointer != 0) - { - path = recovery_pointer == NXBOOT_SECONDARY_SLOT_NUM ? - CONFIG_NXBOOT_SECONDARY_SLOT_PATH : - CONFIG_NXBOOT_TERTIARY_SLOT_PATH; - - recovery = flash_partition_open(path); - if (recovery < 0) - { - close(primary); - return ERROR; - } - - get_image_header(recovery, &recovery_header); - if (primary_header.crc == recovery_header.crc) - { - ret = 1; - } - - close(recovery); - } - } - - close(primary); - return ret; -} - -/**************************************************************************** - * Name: nxboot_confirm - * - * Description: - * Confirms the image currently located in primary partition and marks - * its copy in update partition as a recovery. - * - * Returned Value: - * 0 on success, -1 and sets errno on failure. - * - ****************************************************************************/ - -int nxboot_confirm(void) -{ - int ret; - int update; - int primary; - int remain; - int readsiz; - char *path; - char *buf; - off_t off; - struct nxboot_state state; - struct flash_partition_info info_update; - - ret = OK; - nxboot_get_state(&state); - if (state.primary_confirmed) - { - return OK; - } - - path = state.update == NXBOOT_SECONDARY_SLOT_NUM ? - CONFIG_NXBOOT_SECONDARY_SLOT_PATH : CONFIG_NXBOOT_TERTIARY_SLOT_PATH; - - primary = flash_partition_open(CONFIG_NXBOOT_PRIMARY_SLOT_PATH); - if (primary < 0) - { - return ERROR; - } - - update = flash_partition_open(path); - if (update < 0) - { - flash_partition_close(primary); - return ERROR; - } - - /* Confirm the image by creating a recovery. The recovery image is - * already present in the update slot, but without the first erase - * page. Therefore, just copy the first erase page to the update slot. - */ - - if (flash_partition_info(update, &info_update) < 0) - { - ret = ERROR; - goto confirm_done; - } - - /* Write by write pages to avoid large array buffering. */ - - buf = malloc(info_update.blocksize); - remain = info_update.erasesize; - off = 0; - - while (remain > 0) - { - readsiz = remain > info_update.blocksize ? - info_update.blocksize : remain; - if (flash_partition_read(primary, buf, readsiz, off) < 0) - { - free(buf); - ret = ERROR; - goto confirm_done; - } - - if (flash_partition_write(update, buf, readsiz, off) < 0) - { - free(buf); - ret = ERROR; - goto confirm_done; - } - - off += readsiz; - remain -= readsiz; - } - - free(buf); - -confirm_done: - flash_partition_close(primary); - flash_partition_close(update); - - return ret; -} - -/**************************************************************************** - * Name: nxboot_perform_update - * - * Description: - * Checks for the possible firmware update and performs it by copying - * update image to primary slot or recovery image to primary slot in case - * of the revert. In any situation, this function ends with the valid - * image in primary slot. - * - * This is an entry point function that should be called from the - * bootloader application. - * - * Input parameters: - * check_only: Only repairs corrupted update, but do not start another one - * - * Returned Value: - * 0 on success, -1 and sets errno on failure. - * - ****************************************************************************/ - -int nxboot_perform_update(bool check_only) -{ - int ret; - int primary; - struct nxboot_state state; - - ret = nxboot_get_state(&state); - if (ret < 0) - { - return ERROR; - } - - if (state.next_boot != NXBOOT_UPDATE_TYPE_NONE) - { - /* We either want to update or revert. */ - - ret = perform_update(&state, check_only); - if (ret < 0) - { - /* Update process failed, raise error and try to boot into - * primary. - */ - - syslog(LOG_ERR, "Update process failed: %s\n", strerror(errno)); - nxboot_progress(nxboot_error, update_failed); - } - } - - /* Check whether there is a valid image in the primary slot. Validates - * both the header and the full image CRC to ensure integrity before - * booting. - */ - - primary = flash_partition_open(CONFIG_NXBOOT_PRIMARY_SLOT_PATH); - if (primary < 0) - { - return ERROR; - } - - if (!validate_image(primary)) - { - ret = ERROR; - } - - flash_partition_close(primary); - - return ret; -} - diff --git a/boot/nxboot/loader/flash.c b/boot/nxboot/loader/flash.c deleted file mode 100644 index ab6a24320..000000000 --- a/boot/nxboot/loader/flash.c +++ /dev/null @@ -1,332 +0,0 @@ -/**************************************************************************** - * apps/boot/nxboot/loader/flash.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <stdio.h> -#include <errno.h> -#include <inttypes.h> -#include <string.h> -#include <stddef.h> -#include <fcntl.h> -#include <syslog.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <sys/ioctl.h> - -#include <nuttx/fs/fs.h> -#include <nuttx/mtd/mtd.h> - -#include "flash.h" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: flash_partition_open - * - * Description: - * Opens the partition based on a given name and returns the file - * descriptor to it. - * - * Input parameters: - * path: Path to the device. - * - * Returned Value: - * Valid file descriptor on success, -1 on failure. - * - ****************************************************************************/ - -int flash_partition_open(const char *path) -{ - int fd; - - fd = open(path, O_RDWR | O_DIRECT); - if (fd < 0) - { - syslog(LOG_ERR, "Could not open %s partition: %s\n", - path, strerror(errno)); - return ERROR; - } - - return fd; -} - -/**************************************************************************** - * Name: flash_partition_flush - * - * Description: - * Flushes any buffered writes to the underlying storage. This ensures - * data is physically committed to flash before the caller proceeds. - * - * Input parameters: - * fd: Valid file descriptor. - * - * Returned Value: - * 0 on success, -1 on failure. - * - ****************************************************************************/ - -int flash_partition_flush(int fd) -{ - return fsync(fd); -} - -/**************************************************************************** - * Name: flash_partition_close - * - * Description: - * Closes opened partition. - * - * Input parameters: - * fd: Valid file descriptor. - * - * Returned Value: - * 0 on success, -1 on failure. - * - ****************************************************************************/ - -int flash_partition_close(int fd) -{ - return close(fd); -} - -/**************************************************************************** - * Name: flash_partition_write - * - * Description: - * Writes count data pointed to by buf at offset off to a partition - * referenced by file descriptor fd. - * - * Input parameters: - * fd: Valid file descriptor. - * buf: The pointer to data to be written. - * count: Number of bytes to be written. - * off: Write offset in bytes. - * - * Returned Value: - * 0 on success, -1 on failure. - * - ****************************************************************************/ - -int flash_partition_write(int fd, const void *buf, size_t count, off_t off) -{ - int ret; - off_t pos; - size_t size; - ssize_t nbytes; - struct mtd_geometry_s geometry; - - ret = ioctl(fd, MTDIOC_GEOMETRY, (unsigned long)((uintptr_t)&geometry)); - if (ret < 0) - { - syslog(LOG_ERR, "ioctl MTDIOC_GEOMETRY failed: %s\n", strerror(errno)); - return ERROR; - } - - size = geometry.erasesize * geometry.neraseblocks; - if (count + off > size) - { - syslog(LOG_ERR, "Trying to write outside of flash area.\n"); - return ERROR; - } - - pos = lseek(fd, off, SEEK_SET); - if (pos != off) - { - syslog(LOG_ERR, "Could not seek to %" PRIdOFF ": %s\n", - off, strerror(errno)); - return ERROR; - } - - nbytes = write(fd, buf, count); - if (nbytes != count) - { - syslog(LOG_ERR, "Write to offset %" PRIdOFF " failed %s\n", - off, strerror(errno)); - return ERROR; - } - - return OK; -} - -/**************************************************************************** - * Name: flash_partition_read - * - * Description: - * Read count data to buffer buf at offset off from a partition - * referenced by file descriptor fd. - * - * Input parameters: - * fd: Valid file descriptor. - * buf: The pointer where read data are stored. - * count: Number of bytes to be read. - * off: Read offset in bytes. - * - * Returned Value: - * 0 on success, -1 on failure. - * - ****************************************************************************/ - -int flash_partition_read(int fd, void *buf, size_t count, off_t off) -{ - int ret; - off_t pos; - size_t size; - ssize_t nbytes; - struct mtd_geometry_s geometry; - - ret = ioctl(fd, MTDIOC_GEOMETRY, (unsigned long)((uintptr_t)&geometry)); - if (ret < 0) - { - syslog(LOG_ERR, "ioctl MTDIOC_GEOMETRY failed: %s\n", strerror(errno)); - return ERROR; - } - - size = geometry.erasesize * geometry.neraseblocks; - if (count + off > size) - { - syslog(LOG_ERR, "Trying to read outside of flash area.\n"); - return ERROR; - } - - pos = lseek(fd, off, SEEK_SET); - if (pos != off) - { - syslog(LOG_ERR, "Could not seek to %" PRIdOFF ": %s\n", - off, strerror(errno)); - return ERROR; - } - - nbytes = read(fd, buf, count); - if (nbytes != count) - { - syslog(LOG_ERR, "Read from offset %" PRIdOFF " failed %s\n", - off, strerror(errno)); - return ERROR; - } - - return OK; -} - -/**************************************************************************** - * Name: flash_partition_erase - * - * Description: - * Erases the entire partition. - * - * Input parameters: - * fd: Valid file descriptor. - * - * Returned Value: - * 0 on success, -1 on failure. - * - ****************************************************************************/ - -int flash_partition_erase(int fd) -{ - int ret; - - ret = ioctl(fd, MTDIOC_BULKERASE, 0); - if (ret < 0) - { - syslog(LOG_ERR, "Could not erase the partition: %s\n", - strerror(errno)); - return ERROR; - } - - return OK; -} - -/**************************************************************************** - * Name: flash_partition_erase_first_sector - * - * Description: - * Erases the first sector of the partition - * - * Input parameters: - * fd: Valid file descriptor. - * - * Returned Value: - * 0 on success, -1 on failure. - * - ****************************************************************************/ - -int flash_partition_erase_first_sector(int fd) -{ - int ret; - struct mtd_erase_s erase; - - erase.startblock = 0; - erase.nblocks = 1; - - ret = ioctl(fd, MTDIOC_ERASESECTORS, &erase); - if (ret < 0) - { - syslog(LOG_ERR, "Could not erase the partition: %s\n", - strerror(errno)); - return ERROR; - } - - return OK; -} - -/**************************************************************************** - * Name: flash_partition_info - * - * Description: - * Returns the size of one block. - * - * Input parameters: - * fd: Valid file descriptor. - * info: Pointer to flash_partition_info structure where info is filled. - * - * Returned Value: - * Size of the block on success, -1 on failure. - * - ****************************************************************************/ - -int flash_partition_info(int fd, struct flash_partition_info *info) -{ - int ret; - struct mtd_geometry_s geometry; - - ret = ioctl(fd, MTDIOC_GEOMETRY, (unsigned long)((uintptr_t)&geometry)); - if (ret < 0) - { - syslog(LOG_ERR, "ioctl MTDIOC_GEOMETRY failed: %s\n", - strerror(errno)); - return ERROR; - } - - info->blocksize = geometry.blocksize; - info->size = geometry.erasesize * geometry.neraseblocks; - info->neraseblocks = geometry.neraseblocks; - info->erasesize = geometry.erasesize; - - return OK; -} diff --git a/boot/nxboot/loader/flash.h b/boot/nxboot/loader/flash.h deleted file mode 100644 index 69906490d..000000000 --- a/boot/nxboot/loader/flash.h +++ /dev/null @@ -1,187 +0,0 @@ -/**************************************************************************** - * apps/boot/nxboot/loader/flash.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __BOOT_NXBOOT_LOADER_FLASH_H -#define __BOOT_NXBOOT_LOADER_FLASH_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <stdint.h> -#include <stddef.h> - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -struct flash_partition_info -{ - int size; - int blocksize; - int neraseblocks; - int erasesize; -}; - -/**************************************************************************** - * Public Functions Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Name: flash_partition_open - * - * Description: - * Opens the partition based on a given name and returns the file - * descriptor to it. - * - * Input parameters: - * path: Path to the device. - * - * Returned Value: - * Valid file descriptor on success, -1 on failure. - * - ****************************************************************************/ - -int flash_partition_open(const char *path); - -/**************************************************************************** - * Name: flash_partition_close - * - * Description: - * Closes opened partition. - * - * Input parameters: - * fd: Valid file descriptor. - * - * Returned Value: - * 0 on success, -1 on failure. - * - ****************************************************************************/ - -int flash_partition_close(int fd); - -/**************************************************************************** - * Name: flash_partition_flush - * - * Description: - * Flushes any buffered writes to the underlying storage. - * - * Input parameters: - * fd: Valid file descriptor. - * - * Returned Value: - * 0 on success, -1 on failure. - * - ****************************************************************************/ - -int flash_partition_flush(int fd); - -/**************************************************************************** - * Name: flash_partition_write - * - * Description: - * Writes count data pointed to by buf at offset off to a partition - * referenced by file descriptor fd. - * - * Input parameters: - * fd: Valid file descriptor. - * buf: The pointer to data to be written. - * count: Number of bytes to be written. - * off: Write offset in bytes. - * - * Returned Value: - * 0 on success, -1 on failure. - * - ****************************************************************************/ - -int flash_partition_write(int fd, const void *buf, size_t count, off_t off); - -/**************************************************************************** - * Name: flash_partition_read - * - * Description: - * Read count data to buffer buf at offset off from a partition - * referenced by file descriptor fd. - * - * Input parameters: - * fd: Valid file descriptor. - * buf: The pointer where read data are stored. - * count: Number of bytes to be read. - * off: Read offset in bytes. - * - * Returned Value: - * 0 on success, -1 on failure. - * - ****************************************************************************/ - -int flash_partition_read(int fd, void *buf, size_t count, off_t off); - -/**************************************************************************** - * Name: flash_partition_erase - * - * Description: - * Erases the entire partition. - * - * Input parameters: - * fd: Valid file descriptor. - * - * Returned Value: - * 0 on success, -1 on failure. - * - ****************************************************************************/ - -int flash_partition_erase(int fd); - -/**************************************************************************** - * Name: flash_partition_erase_first_sector - * - * Description: - * Erases the first sector of the partition - * - * Input parameters: - * fd: Valid file descriptor. - * - * Returned Value: - * 0 on success, -1 on failure. - * - ****************************************************************************/ - -int flash_partition_erase_first_sector(int fd); - -/**************************************************************************** - * Name: flash_partition_info - * - * Description: - * Returns the size of one block. - * - * Input parameters: - * fd: Valid file descriptor. - * info: Pointer to flash_partition_info structure where info is filled. - * - * Returned Value: - * Size of the block on success, -1 on failure. - * - ****************************************************************************/ - -int flash_partition_info(int fd, struct flash_partition_info *info); - -#endif /* __BOOT_NXBOOT_LOADER_FLASH_H */ diff --git a/boot/nxboot/nxboot_main.c b/boot/nxboot/nxboot_main.c deleted file mode 100644 index 0682b92c7..000000000 --- a/boot/nxboot/nxboot_main.c +++ /dev/null @@ -1,325 +0,0 @@ -/**************************************************************************** - * apps/boot/nxboot/nxboot_main.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <stdio.h> -#include <syslog.h> -#include <nuttx/ascii.h> -#include <sys/param.h> -#include <nxboot.h> -#include <sys/boardctl.h> - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -#ifdef CONFIG_NXBOOT_PROGRESS -static bool g_progress_started = false; -#ifdef CONFIG_NXBOOT_PRINTF_PROGRESS_PERCENT -static bool g_progress_percent_started = false; -#endif -#endif - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -#ifdef CONFIG_NXBOOT_PRINTF_PROGRESS - -# ifdef CONFIG_NXBOOT_PRINTF_PROGRESS_PERCENT -static const char backtab[] = -{ - ASCII_BS, ASCII_BS, ASCII_BS, ASCII_BS, '\0', -}; -# endif - -static const char *progress_msgs[] = -{ - [startup_msg] = "*** nxboot ***", - [power_reset] = "Power Reset detected, check images only", - [soft_reset] = "Soft reset detected, check for update", - [found_bootable_image] = "Found bootable image, boot from primary", - [no_bootable_image] = "No bootable image found", - [boardioc_image_boot_fail] = "Board failed to boot bootable image", - [ramcopy_started] = "Copying bootable image to RAM", - [recovery_revert] = "Reverting image to recovery", - [recovery_create] = "Creating recovery image", - [update_from_update] = "Updating from update image", - [validate_primary] = "Validating primary image", - [validate_recovery] = "Validating recovery image", - [validate_update] = "Validating update image", - [recovery_created] = "Recovery image created", - [recovery_invalid] = "Recovery image invalid, update stopped", - [update_failed] = "Update failed", -}; -#endif /* CONFIG_NXBOOT_PRINTF_PROGRESS */ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: nxboot_progress - * - * Description: - * If enabled, this function prints progress messages to stdout. - * Messages are handled via integer enums, allowing this function to be - * easily replaced if required with no changes needed to the underlying - * code - * - * Input Parameters: - * type - the progress message type to be printed, as per progress_type_e: - * - nxboot_info: Prefixes arg. string with "INFO:" - * - nxboot_error: Prefixes arg. string with "ERR:" - * - nxboot_progress_start: Prints arg. string with no newline - * to allow a ..... sequence - * or % remaining to follow - * - nxboot_progress_dot: Prints a "." to the ..... sequence - * - nxboot_progress_percent: Displays progress as % remaining - * - nxboot_progress_end, Flags end of a progrees sequence - * - * ... - variadic argument: - * - the enum (int) reference to the message string or - * - the % remaining in the case of type: nxboot_progress_percent - * - * Returned Value: - * None - * - ****************************************************************************/ - -#ifdef CONFIG_NXBOOT_PROGRESS -void nxboot_progress(int type, ...) -{ -#ifdef CONFIG_NXBOOT_PRINTF_PROGRESS - va_list arg; - - va_start(arg, type); - - switch (type) - { - case nxboot_info: - { - int idx = va_arg(arg, int); - assert(progress_msgs[idx]); - if (strlen(progress_msgs[idx]) == 0) - { - syslog(LOG_ERR, "No progress message for idx: %d\n", idx); - break; - } - - dprintf(STDOUT_FILENO, "%s\n", progress_msgs[idx]); - } - break; - case nxboot_error: - { - int idx = va_arg(arg, int); - assert(progress_msgs[idx]); - if (strlen(progress_msgs[idx]) == 0) - { - syslog(LOG_ERR, "No progress message for idx: %d\n", idx); - break; - } - - dprintf(STDOUT_FILENO, "ERROR: %s\n", progress_msgs[idx]); - } - break; - case nxboot_progress_start: - { - int idx = va_arg(arg, int); - assert(progress_msgs[idx]); - if (strlen(progress_msgs[idx]) == 0) - { - syslog(LOG_ERR, "No progress message for idx: %d\n", idx); - break; - } - - dprintf(STDOUT_FILENO, "%s", progress_msgs[idx]); - g_progress_started = true; - } - break; - case nxboot_progress_dot: - { - assert(g_progress_started); - if (!g_progress_started) - { - syslog(LOG_ERR, "Progress dot requested " - "but no previous progress start\n"); - } - else - { - dprintf(STDOUT_FILENO, "."); - } - } - break; -#ifdef CONFIG_NXBOOT_PRINTF_PROGRESS_PERCENT - case nxboot_progress_percent: - { - assert(g_progress_started); - if (!g_progress_started) - { - syslog(LOG_ERR, "Progress percent requested " - "but no previous progress start\n"); - } - else - { - int percent = va_arg(arg, int); - if (!g_progress_percent_started) - { - g_progress_percent_started = true; - dprintf(STDOUT_FILENO, ": "); - } - else - { - dprintf(STDOUT_FILENO, "%s", backtab); - } - - dprintf(STDOUT_FILENO, "%3d%%", MIN(percent, 100)); - } - } - break; -#endif - case nxboot_progress_end: - { - assert(g_progress_started); - if (!g_progress_started) - { - syslog(LOG_ERR, "Progress dot stop requested " - "but no previous progress start\n"); - } - else - { - dprintf(STDOUT_FILENO, "\n"); - } - - g_progress_started = false; -#ifdef CONFIG_NXBOOT_PRINTF_PROGRESS_PERCENT - g_progress_percent_started = false; -#endif - } - break; - default: - { - assert(false); - syslog(LOG_ERR, "Invalid progress message type: %d\n", type); - dprintf(STDOUT_FILENO, "progress: unknown type!\n"); - } - break; - } - - va_end(arg); -#endif /* CONFIG_NXBOOT_PRINTF_PROGRESS */ -} -#endif - -/**************************************************************************** - * Name: nxboot_main - * - * Description: - * NuttX bootloader entry point. - * - ****************************************************************************/ - -int main(int argc, FAR char *argv[]) -{ - int ret; - struct boardioc_boot_info_s info; - bool check_only; -#ifdef CONFIG_NXBOOT_SWRESET_ONLY - FAR struct boardioc_reset_cause_s cause; -#endif - -#ifdef CONFIG_BOARDCTL_FINALINIT - /* Perform architecture-specific final-initialization (if configured) */ - - boardctl(BOARDIOC_FINALINIT, 0); -#endif - - syslog(LOG_INFO, "*** nxboot ***\n"); - nxboot_progress(nxboot_info, startup_msg); - -#ifdef CONFIG_NXBOOT_SWRESET_ONLY - check_only = true; - ret = boardctl(BOARDIOC_RESET_CAUSE, (uintptr_t)&cause); - if (ret >= 0) - { - if (cause.cause == BOARDIOC_RESETCAUSE_CPU_SOFT || - cause.cause == BOARDIOC_RESETCAUSE_CPU_RWDT || - cause.cause == BOARDIOC_RESETCAUSE_PIN) - { - check_only = false; - nxboot_progress(nxboot_info, soft_reset); - } - else - { - syslog(LOG_INFO, "Power reset detected, performing check only.\n"); - nxboot_progress(nxboot_info, power_reset); - } - } -#else - check_only = false; -#endif - - if (nxboot_perform_update(check_only) < 0) - { - syslog(LOG_ERR, "Could not find bootable image.\n"); - nxboot_progress(nxboot_error, no_bootable_image); - return OK; - } - - syslog(LOG_INFO, "Found bootable image, boot from primary.\n"); - nxboot_progress(nxboot_info, found_bootable_image); - -#ifdef CONFIG_NXBOOT_COPY_TO_RAM - syslog(LOG_INFO, "Copying image to RAM.\n"); - nxboot_ramcopy(); -#endif - - /* Call board specific image boot */ - - info.path = CONFIG_NXBOOT_PRIMARY_SLOT_PATH; - info.header_size = CONFIG_NXBOOT_HEADER_SIZE; - - ret = boardctl(BOARDIOC_BOOT_IMAGE, (uintptr_t)&info); - - /* Only get here if the board boot fails */ - - nxboot_progress(nxboot_error, boardioc_image_boot_fail); - - return ret; -} diff --git a/boot/nxboot/tools/nximage.py b/boot/nxboot/tools/nximage.py deleted file mode 100644 index 6795b4b99..000000000 --- a/boot/nxboot/tools/nximage.py +++ /dev/null @@ -1,149 +0,0 @@ -#!/usr/bin/env python3 -############################################################################ -# apps/boot/nxboot/tools/nximage.py -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ -"""Python script that prepares the NuttX image to be used with NX bootloader""" - -import argparse -import io -import os -import struct -import zlib - -import semantic_version - - -class NxImage: - def __init__( - self, - path: str, - result: str, - version: str, - header_size: int, - identifier: int, - ) -> None: - self.path = path - self.result = result - self.size = os.stat(path).st_size - self.version = semantic_version.Version(version) - self.header_size = header_size - self.identifier = identifier - self.crc = 0 - self.extd_hdr_ptr = 0 - - def __repr__(self) -> str: - repr = ( - "<NxImage\n" - f" path: {self.path}\n" - f" result: {self.result}\n" - f" fsize: {self.size}\n" - f" version: {self.version}\n" - f" header_size: {self.header_size:x}\n" - f" identifier: {self.identifier:x}\n" - f" crc: {self.crc:x}\n" - f">" - ) - return repr - - def add_header(self) -> None: - with open(self.path, "r+b") as src, open(self.result, "w+b") as dest: - dest.write(b"\x4e\x58\x4f\x53") - dest.write(struct.pack("<H", 0)) - dest.write(struct.pack("<H", self.header_size)) - dest.write(struct.pack("<I", 0xFFFFFFFF)) - dest.write(struct.pack("<I", self.size)) - dest.write(struct.pack("<Q", self.identifier)) - dest.write(struct.pack("<I", self.extd_hdr_ptr)) - dest.write(struct.pack("<H", self.version.major)) - dest.write(struct.pack("<H", self.version.minor)) - dest.write(struct.pack("<H", self.version.patch)) - if not self.version.prerelease: - dest.write(struct.pack("@94s", b"\x00")) - else: - dest.write( - struct.pack("@94s", bytes(self.version.prerelease[0], "utf-8")) - ) - dest.write(bytearray(b"\xff") * (self.header_size - 128)) - while data := src.read(io.DEFAULT_BUFFER_SIZE): - dest.write(data) - - with open(self.result, "r+b") as f: - f.seek(12) - while data := f.read(io.DEFAULT_BUFFER_SIZE): - self.crc = zlib.crc32(data, self.crc) - f.seek(8) - f.write(struct.pack("<I", self.crc)) - - -def parse_args() -> argparse.Namespace: - """Parse passed arguments and return result.""" - parser = argparse.ArgumentParser(description="Tool for Nuttx Bootloader") - parser.add_argument( - "--version", - default="0.0.0", - help="Image version according to Semantic Versioning 2.0.0.", - ) - parser.add_argument( - "--header_size", - type=lambda x: int(x, 0), - default=0x200, - help="Size of the image header.", - ) - parser.add_argument( - "--identifier", - type=lambda x: int(x, 0), - default=0x0, - help="Platform identifier. An image is rejected if its identifier doesn't match the one set in bootloader.", - ) - parser.add_argument( - "-v", - action="store_true", - help="Verbose output. This prints information about the created image.", - ) - parser.add_argument( - "PATH", - default="nuttx.bin", - help="Path to the NuttX image.", - ) - parser.add_argument( - "RESULT", - default="nuttx.img", - help="Path where the resulting NuttX image is stored.", - ) - return parser.parse_args() - - -def main() -> None: - args = parse_args() - image = NxImage( - args.PATH, - args.RESULT, - args.version, - args.header_size, - args.identifier, - ) - image.add_header() - if args.v: - print(image) - - -if __name__ == "__main__": - main() diff --git a/boot/nxboot/tools/requirements.txt b/boot/nxboot/tools/requirements.txt deleted file mode 100644 index 62b4122af..000000000 --- a/boot/nxboot/tools/requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ -argparse>=1.4.0 -semantic_version>=2.10.0 diff --git a/builtin/CMakeLists.txt b/builtin/CMakeLists.txt deleted file mode 100644 index 3d8b244e4..000000000 --- a/builtin/CMakeLists.txt +++ /dev/null @@ -1,63 +0,0 @@ -# ############################################################################## -# apps/builtin/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_BUILTIN) - - include_directories(${CMAKE_CURRENT_BINARY_DIR}) - - # generate registry - get_property(nuttx_app_libs GLOBAL PROPERTY NUTTX_APPS_LIBRARIES) - get_property(only_registers GLOBAL PROPERTY NUTTX_APPS_ONLY_REGISTER) - list(APPEND nuttx_app_libs ${only_registers}) - set(builtin_list_string) - set(builtin_proto_string) - foreach(module ${nuttx_app_libs}) - - # builtin_list.h Example: { "hello", SCHED_PRIORITY_DEFAULT, 2048, - # hello_main }, - # - get_target_property(APP_MAIN ${module} APP_MAIN) - get_target_property(APP_NAME ${module} APP_NAME) - get_target_property(APP_PRIORITY ${module} APP_PRIORITY) - get_target_property(APP_STACK ${module} APP_STACK) - set(builtin_list_string - "${builtin_list_string}\{ \"${APP_NAME}\", ${APP_PRIORITY}, ${APP_STACK}, ${APP_MAIN} \}, \n" - ) - - # builtin_proto.h Example: int hello_main(int argc, char *argv[]); - set(builtin_proto_string - "${builtin_proto_string}int ${APP_MAIN}(int argc, char *argv[]);\n") - - endforeach() - - configure_file(builtin_proto.h.in builtin_proto.h) - configure_file(builtin_list.h.in builtin_list.h) - - set(CSRCS) - - list(APPEND CSRCS builtin_list.c exec_builtin.c builtin_list.h - builtin_proto.h) - - # target_sources(apps PRIVATE ${CSRCS}) - nuttx_add_library(apps_builtin ${CSRCS}) - -endif() diff --git a/builtin/Make.defs b/builtin/Make.defs index 47d1bf960..b41625c1c 100644 --- a/builtin/Make.defs +++ b/builtin/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/builtin/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -20,6 +18,6 @@ # ############################################################################ -ifneq ($(CONFIG_BUILTIN),) +ifeq ($(CONFIG_BUILTIN),y) CONFIGURED_APPS += $(APPDIR)/builtin endif diff --git a/builtin/Makefile b/builtin/Makefile index a5de31f6c..eaefd7748 100644 --- a/builtin/Makefile +++ b/builtin/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/builtin/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -30,30 +28,18 @@ CSRCS = builtin_list.c exec_builtin.c PDATLIST = $(strip $(call RWILDCARD, registry, *.pdat)) BDATLIST = $(strip $(call RWILDCARD, registry, *.bdat)) -ifeq ($(CONFIG_WINDOWS_NATIVE),y) - PDATLIST := $(subst /,\,$(PDATLIST)) - BDATLIST := $(subst /,\,$(BDATLIST)) -endif builtin_list.c: builtin_list.h builtin_proto.h registry$(DELIM).updated: $(Q) touch registry$(DELIM).updated -define CONFILE - if [ -n "$(strip $(2))" ]; then cat $(2) >> $1; fi -endef - builtin_list.h: registry$(DELIM).updated ifeq ($(BDATLIST),) $(call DELFILE, builtin_list.h) $(Q) touch builtin_list.h else - $(shell echo '' > builtin_list.h) - $(call SPLITVARIABLE,BDA,$(BDATLIST),50) \ - $(foreach BATCH, $(BDA_TOTAL), \ - $(shell $(call CONFILE, builtin_list.h, $(BDA_$(BATCH)))) \ - ) + $(call CATFILE, builtin_list.h, $(BDATLIST)) endif builtin_proto.h: registry$(DELIM).updated @@ -61,11 +47,7 @@ ifeq ($(PDATLIST),) $(call DELFILE, builtin_proto.h) $(Q) touch builtin_proto.h else - $(shell echo '' > builtin_proto.h) - $(call SPLITVARIABLE,PDA,$(PDATLIST),50) \ - $(foreach BATCH, $(PDA_TOTAL), \ - $(shell $(call CONFILE, builtin_proto.h, $(PDA_$(BATCH)))) \ - ) + $(call CATFILE, builtin_proto.h, $(PDATLIST)) endif depend:: builtin_list.h builtin_proto.h diff --git a/builtin/builtin_list.c b/builtin/builtin_list.c index 9605b097c..d7a7d02d2 100644 --- a/builtin/builtin_list.c +++ b/builtin/builtin_list.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/builtin/builtin_list.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -27,11 +25,6 @@ #include <nuttx/config.h> #include <nuttx/lib/builtin.h> -#include <sys/param.h> - -#include <sys/stat.h> - -#include "builtin_proto.h" /**************************************************************************** * Private Types @@ -45,17 +38,15 @@ * Public Data ****************************************************************************/ +#include "builtin_proto.h" + const struct builtin_s g_builtins[] = { -# include "builtin_list.h" -#ifdef CONFIG_SCHED_USER_IDENTITY - { NULL, 0, 0, 0, 0, 0, 0 } -#else +# include "builtin_list.h" { NULL, 0, 0, 0 } -#endif }; -const int g_builtin_count = nitems(g_builtins); +const int g_builtin_count = sizeof(g_builtins) / sizeof(g_builtins[0]); /**************************************************************************** * Private Data diff --git a/builtin/builtin_list.h.in b/builtin/builtin_list.h.in deleted file mode 100644 index b81626aa6..000000000 --- a/builtin/builtin_list.h.in +++ /dev/null @@ -1 +0,0 @@ -${builtin_list_string} diff --git a/builtin/builtin_proto.h.in b/builtin/builtin_proto.h.in deleted file mode 100644 index abb9dcee1..000000000 --- a/builtin/builtin_proto.h.in +++ /dev/null @@ -1 +0,0 @@ -${builtin_proto_string} diff --git a/builtin/exec_builtin.c b/builtin/exec_builtin.c index b87133243..1cacdd4ad 100644 --- a/builtin/exec_builtin.c +++ b/builtin/exec_builtin.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/builtin/exec_builtin.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -29,7 +27,7 @@ #include <spawn.h> #include <fcntl.h> #include <errno.h> -#include <nuttx/debug.h> +#include <debug.h> #include "builtin/builtin.h" @@ -45,9 +43,13 @@ * New application is run in a separate task context (and thread). * * Input Parameter: - * filename - Name of the linked-in binary to be started. - * argv - Argument list - * param - Parameters for execute. + * filename - Name of the linked-in binary to be started. + * argv - Argument list + * redirfile - If output is redirected, this parameter will be non-NULL + * and will provide the full path to the file. + * oflags - If output is redirected, this parameter will provide the + * open flags to use. This will support file replacement + * of appending to an existing file. * * Returned Value: * This is an end-user function, so it follows the normal convention: @@ -57,12 +59,12 @@ ****************************************************************************/ int exec_builtin(FAR const char *appname, FAR char * const *argv, - FAR const struct nsh_param_s *param) + FAR const char *redirfile, int oflags) { FAR const struct builtin_s *builtin; posix_spawnattr_t attr; posix_spawn_file_actions_t file_actions; - struct sched_param sched; + struct sched_param param; pid_t pid; int index; int ret; @@ -101,14 +103,14 @@ int exec_builtin(FAR const char *appname, FAR char * const *argv, /* Set the correct task size and priority */ - sched.sched_priority = builtin->priority; - ret = posix_spawnattr_setschedparam(&attr, &sched); + param.sched_priority = builtin->priority; + ret = posix_spawnattr_setschedparam(&attr, ¶m); if (ret != 0) { goto errout_with_actions; } - ret = posix_spawnattr_setstacksize(&attr, builtin->stacksize); + ret = task_spawnattr_setstacksize(&attr, builtin->stacksize); if (ret != 0) { goto errout_with_actions; @@ -142,67 +144,19 @@ int exec_builtin(FAR const char *appname, FAR char * const *argv, #endif - if (param) + /* Is output being redirected? */ + + if (redirfile) { - /* Is input being redirected? */ + /* Set up to close open redirfile and set to stdout (1) */ - if (param->file_in) + ret = posix_spawn_file_actions_addopen(&file_actions, 1, + redirfile, oflags, 0644); + if (ret != 0) { - /* Set up to close open redirfile and set to stdin (0) */ - - ret = posix_spawn_file_actions_addopen(&file_actions, 0, - param->file_in, - param->oflags_in, 0); - if (ret != 0) - { - serr("ERROR: posix_spawn_file_actions_addopen failed: %d\n", - ret); - goto errout_with_actions; - } + serr("ERROR: posix_spawn_file_actions_addopen failed: %d\n", ret); + goto errout_with_actions; } -#ifdef CONFIG_NSH_PIPELINE - else if (param->fd_in != -1) - { - ret = posix_spawn_file_actions_adddup2(&file_actions, - param->fd_in, 0); - if (ret != 0) - { - serr("ERROR: posix_spawn_file_actions_adddup2 failed: %d\n", - ret); - goto errout_with_actions; - } - } -#endif - - /* Is output being redirected? */ - - if (param->file_out) - { - /* Set up to close open redirfile and set to stdout (1) */ - - ret = posix_spawn_file_actions_addopen(&file_actions, 1, - param->file_out, - param->oflags_out, 0644); - if (ret != 0) - { - serr("ERROR: posix_spawn_file_actions_addopen failed: %d\n", - ret); - goto errout_with_actions; - } - } -#ifdef CONFIG_NSH_PIPELINE - else if (param->fd_out != -1) - { - ret = posix_spawn_file_actions_adddup2(&file_actions, - param->fd_out, 1); - if (ret != 0) - { - serr("ERROR: posix_spawn_file_actions_adddup2 failed: %d\n", - ret); - goto errout_with_actions; - } - } -#endif } #ifdef CONFIG_LIBC_EXECFUNCS @@ -215,7 +169,8 @@ int exec_builtin(FAR const char *appname, FAR char * const *argv, /* Start the built-in */ pid = task_spawn(builtin->name, builtin->main, &file_actions, - &attr, argv ? &argv[1] : NULL, NULL); + &attr, (argv) ? &argv[1] : (FAR char * const *)NULL, + (FAR char * const *)NULL); ret = pid < 0 ? -pid : 0; } diff --git a/canutils/CMakeLists.txt b/canutils/CMakeLists.txt deleted file mode 100644 index aa4a02ed9..000000000 --- a/canutils/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -# ############################################################################## -# apps/canutils/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -nuttx_add_subdirectory() - -nuttx_generate_kconfig(MENUDESC "CAN Utilities") diff --git a/canutils/Make.defs b/canutils/Make.defs index b68638da8..77a6c4d3a 100644 --- a/canutils/Make.defs +++ b/canutils/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/canutils/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/canutils/Makefile b/canutils/Makefile index 68a1d93b2..d8d9f1ddd 100644 --- a/canutils/Makefile +++ b/canutils/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/canutils/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/canutils/candump/CMakeLists.txt b/canutils/candump/CMakeLists.txt deleted file mode 100644 index be4f27f0b..000000000 --- a/canutils/candump/CMakeLists.txt +++ /dev/null @@ -1,39 +0,0 @@ -# ############################################################################## -# apps/canutils/candump/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_CANUTILS_CANDUMP) - - set(LIBCANUTILS_DIR ${NUTTX_APPS_DIR}/canutils/libcanutils) - - nuttx_add_application( - NAME - candump - STACKSIZE - ${CONFIG_CANUTILS_CANDUMP_STACKSIZE} - MODULE - ${CONFIG_CANUTILS_CANDUMP} - SRCS - candump.c - INCLUDE_DIRECTORIES - ${LIBCANUTILS_DIR}) - -endif() diff --git a/canutils/candump/Kconfig b/canutils/candump/Kconfig index 45a46118b..eaf41db5b 100644 --- a/canutils/candump/Kconfig +++ b/canutils/candump/Kconfig @@ -6,7 +6,8 @@ config CANUTILS_CANDUMP tristate "SocketCAN candump tool" default n - depends on NET_CAN && CANUTILS_LIBCANUTILS && ENABLE_ALL_SIGNALS + depends on NET_CAN + select CANUTILS_LIBCANUTILS ---help--- Enable the SocketCAN candump tool ported from https://github.com/linux-can/can-utils diff --git a/canutils/candump/Make.defs b/canutils/candump/Make.defs index d781a87b5..bf15862fe 100644 --- a/canutils/candump/Make.defs +++ b/canutils/candump/Make.defs @@ -1,7 +1,6 @@ ############################################################################ # apps/canutils/candump/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 +# Adds selected applications to apps/ build # # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with diff --git a/canutils/candump/Makefile b/canutils/candump/Makefile index d8861496f..869cbced4 100644 --- a/canutils/candump/Makefile +++ b/canutils/candump/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/canutils/candump/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -30,7 +28,7 @@ PRIORITY = SCHED_PRIORITY_DEFAULT STACKSIZE = $(CONFIG_CANUTILS_CANDUMP_STACKSIZE) MODULE = $(CONFIG_CANUTILS_CANDUMP) -CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/canutils/libcanutils +CFLAGS += ${shell $(INCDIR) "$(CC)" $(APPDIR)/canutils/libcanutils} MAINSRC = candump.c include $(APPDIR)/Application.mk diff --git a/canutils/candump/candump.c b/canutils/candump/candump.c index 58958a46f..7b3074cc3 100644 --- a/canutils/candump/candump.c +++ b/canutils/candump/candump.c @@ -1,8 +1,9 @@ -/**************************************************************************** - * apps/canutils/candump/candump.c +/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) */ +/* + * candump.c * - * SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) - * SPDX-FileCopyrightText: 2002-2007 Volkswagen Group Electronic Research + * Copyright (c) 2002-2009 Volkswagen Group Electronic Research + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -39,11 +40,7 @@ * * Send feedback to <linux-can@vger.kernel.org> * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ + */ #include <stdio.h> #include <stdlib.h> @@ -65,14 +62,11 @@ #include <net/if.h> #include <nuttx/can.h> +#include <netpacket/can.h> #include "terminal.h" #include "lib.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - /* for hardware timestamps - since Linux 2.6.30 */ #ifndef SO_TIMESTAMPING #define SO_TIMESTAMPING 37 @@ -105,10 +99,7 @@ const char col_on [MAXCOL][19] = {BLUE, RED, GREEN, BOLD, MAGENTA, CYAN}; const char col_off [] = ATTRESET; -/**************************************************************************** - * Public Functions - ****************************************************************************/ - +static char *cmdlinename[MAXSOCK]; static __u32 dropcnt[MAXSOCK]; static __u32 last_dropcnt[MAXSOCK]; static char devname[MAXIFNAMES][IFNAMSIZ+1]; @@ -212,7 +203,7 @@ int idx2dindex(int ifidx, int socket) { if (max_devname_len < (int)strlen(ifr.ifr_name)) max_devname_len = strlen(ifr.ifr_name); - strlcpy(devname[i], ifr.ifr_name, sizeof(devname[i])); + strcpy(devname[i], ifr.ifr_name); #ifdef DEBUG printf("new index %d (%s)\n", i, devname[i]); @@ -238,7 +229,7 @@ int main(int argc, char **argv) unsigned char logfrmt = 0; int count = 0; int rcvbuf_size = 0; - int opt; + int opt, ret; int currmax, numfilter; int join_filter; char *ptr, *nptr; @@ -403,6 +394,8 @@ int main(int argc, char **argv) return 1; } + cmdlinename[i] = ptr; /* save pointer to cmdline name of this socket */ + if (nptr) nbytes = nptr - ptr; /* interface name is up the first ',' */ else @@ -625,7 +618,7 @@ int main(int argc, char **argv) if (timeout_current) *timeout_current = timeout_config; - if ((select(s[currmax-1]+1, &rdfs, NULL, NULL, timeout_current)) <= 0) { + if ((ret = select(s[currmax-1]+1, &rdfs, NULL, NULL, timeout_current)) <= 0) { //perror("select"); running = 0; continue; diff --git a/canutils/canlib/CMakeLists.txt b/canutils/canlib/CMakeLists.txt deleted file mode 100644 index 9f8af63e1..000000000 --- a/canutils/canlib/CMakeLists.txt +++ /dev/null @@ -1,28 +0,0 @@ -# ############################################################################## -# apps/canutils/canlib/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## -if(CONFIG_CANUTILS_CANLIB) - - target_sources( - apps PRIVATE canlib_getbaud.c canlib_setbaud.c canlib_getloopback.c - canlib_setloopback.c canlib_getsilent.c canlib_setsilent.c) - -endif() diff --git a/canutils/canlib/Make.defs b/canutils/canlib/Make.defs index 61e591c18..48c1437b3 100644 --- a/canutils/canlib/Make.defs +++ b/canutils/canlib/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/canutils/canlib/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -20,6 +18,6 @@ # ############################################################################ -ifneq ($(CONFIG_CANUTILS_CANLIB),) +ifeq ($(CONFIG_CANUTILS_CANLIB),y) CONFIGURED_APPS += $(APPDIR)/canutils/canlib endif diff --git a/canutils/canlib/Makefile b/canutils/canlib/Makefile index 64ecdb0a3..54fc23f66 100644 --- a/canutils/canlib/Makefile +++ b/canutils/canlib/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/canutils/canlib/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/canutils/canlib/canlib_getbaud.c b/canutils/canlib/canlib_getbaud.c index 61ebb4de9..f8e2655c9 100644 --- a/canutils/canlib/canlib_getbaud.c +++ b/canutils/canlib/canlib_getbaud.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/canutils/canlib/canlib_getbaud.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -24,10 +22,15 @@ * Included Files ****************************************************************************/ -#include <sys/ioctl.h> -#include <nuttx/debug.h> -#include <errno.h> +#include <nuttx/config.h> +#include <sys/ioctl.h> + +#include <stdio.h> +#include <stdlib.h> +#include <fcntl.h> +#include <debug.h> +#include <errno.h> #include <nuttx/can/can.h> /**************************************************************************** @@ -60,9 +63,10 @@ int canlib_getbaud(int fd, FAR int *bauds) if (ret != OK) { canerr("CANIOC_GET_BITTIMING failed, errno=%d\n", errno); - return ret; + return 0; } *bauds = timings.bt_baud; + return ret; } diff --git a/canutils/canlib/canlib_getloopback.c b/canutils/canlib/canlib_getloopback.c index b931301d5..5c13614ca 100644 --- a/canutils/canlib/canlib_getloopback.c +++ b/canutils/canlib/canlib_getloopback.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/canutils/canlib/canlib_getloopback.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -24,10 +22,16 @@ * Included Files ****************************************************************************/ -#include <sys/ioctl.h> -#include <nuttx/debug.h> -#include <errno.h> +#include <nuttx/config.h> +#include <sys/ioctl.h> + +#include <stdio.h> +#include <stdlib.h> +#include <stdbool.h> +#include <fcntl.h> +#include <debug.h> +#include <errno.h> #include <nuttx/can/can.h> /**************************************************************************** @@ -60,9 +64,10 @@ int canlib_getloopback(int fd, FAR bool *loopback) if (ret != OK) { canerr("CANIOC_GET_CONNMODES failed, errno=%d\n", errno); - return ret; + return FALSE; } - *loopback = connmodes.bm_loopback; + *loopback = (bool)connmodes.bm_loopback; + return ret; } diff --git a/canutils/canlib/canlib_getsilent.c b/canutils/canlib/canlib_getsilent.c index 18e2b0637..10af602a4 100644 --- a/canutils/canlib/canlib_getsilent.c +++ b/canutils/canlib/canlib_getsilent.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/canutils/canlib/canlib_getsilent.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -24,10 +22,16 @@ * Included Files ****************************************************************************/ -#include <sys/ioctl.h> -#include <nuttx/debug.h> -#include <errno.h> +#include <nuttx/config.h> +#include <sys/ioctl.h> + +#include <stdio.h> +#include <stdlib.h> +#include <stdbool.h> +#include <fcntl.h> +#include <debug.h> +#include <errno.h> #include <nuttx/can/can.h> /**************************************************************************** @@ -41,8 +45,8 @@ * Wrapper for CANIOC_GET_CONNMODES. * * Input Parameter: - * fd - file descriptor of an opened can device - * silent - pointer to a buffer to store the current silent mode state. + * fd - file descriptor of an opened can device + * loopback - pointer to a buffer to store the current silent mode state. * * Returned Value: * Zero (OK) is returned on success. Otherwise -1 (ERROR) @@ -60,9 +64,10 @@ int canlib_getsilent(int fd, FAR bool *silent) if (ret != OK) { canerr("CANIOC_GET_CONNMODES failed, errno=%d\n", errno); - return ret; + return FALSE; } - *silent = connmodes.bm_silent; + *silent = (bool)connmodes.bm_silent; + return ret; } diff --git a/canutils/canlib/canlib_setbaud.c b/canutils/canlib/canlib_setbaud.c index f8bbb23ff..c2e9c3086 100644 --- a/canutils/canlib/canlib_setbaud.c +++ b/canutils/canlib/canlib_setbaud.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/canutils/canlib/canlib_setbaud.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -24,10 +22,15 @@ * Included Files ****************************************************************************/ -#include <sys/ioctl.h> -#include <nuttx/debug.h> -#include <errno.h> +#include <nuttx/config.h> +#include <sys/ioctl.h> + +#include <stdio.h> +#include <stdlib.h> +#include <fcntl.h> +#include <debug.h> +#include <errno.h> #include <nuttx/can/can.h> /**************************************************************************** diff --git a/canutils/canlib/canlib_setloopback.c b/canutils/canlib/canlib_setloopback.c index 18164210c..f97cc792c 100644 --- a/canutils/canlib/canlib_setloopback.c +++ b/canutils/canlib/canlib_setloopback.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/canutils/canlib/canlib_setloopback.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -24,10 +22,16 @@ * Included Files ****************************************************************************/ -#include <sys/ioctl.h> -#include <nuttx/debug.h> -#include <errno.h> +#include <nuttx/config.h> +#include <sys/ioctl.h> + +#include <stdio.h> +#include <stdlib.h> +#include <stdbool.h> +#include <fcntl.h> +#include <debug.h> +#include <errno.h> #include <nuttx/can/can.h> /**************************************************************************** diff --git a/canutils/canlib/canlib_setsilent.c b/canutils/canlib/canlib_setsilent.c index bf8ef1722..5a1978571 100644 --- a/canutils/canlib/canlib_setsilent.c +++ b/canutils/canlib/canlib_setsilent.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/canutils/canlib/canlib_setsilent.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -24,10 +22,16 @@ * Included Files ****************************************************************************/ -#include <sys/ioctl.h> -#include <nuttx/debug.h> -#include <errno.h> +#include <nuttx/config.h> +#include <sys/ioctl.h> + +#include <stdio.h> +#include <stdlib.h> +#include <stdbool.h> +#include <fcntl.h> +#include <debug.h> +#include <errno.h> #include <nuttx/can/can.h> /**************************************************************************** @@ -42,8 +46,8 @@ * peripheral never transmits on the bus, but receives all bus traffic. * * Input Parameter: - * fd - file descriptor of an opened can device - * silent - whether to use silent mode. + * fd - file descriptor of an opened can device + * loopback - whether to use loopback mode. * * Returned Value: * Zero (OK) is returned on success. Otherwise -1 (ERROR) diff --git a/canutils/cansend/CMakeLists.txt b/canutils/cansend/CMakeLists.txt deleted file mode 100644 index 311916666..000000000 --- a/canutils/cansend/CMakeLists.txt +++ /dev/null @@ -1,39 +0,0 @@ -# ############################################################################## -# apps/canutils/cansend/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_CANUTILS_CANSEND) - - set(LIBCANUTILS_DIR ${NUTTX_APPS_DIR}/canutils/libcanutils) - - nuttx_add_application( - NAME - cansend - STACKSIZE - ${CONFIG_CANUTILS_CANSEND_STACKSIZE} - MODULE - ${CONFIG_CANUTILS_CANSEND} - SRCS - cansend.c - INCLUDE_DIRECTORIES - ${LIBCANUTILS_DIR}) - -endif() diff --git a/canutils/cansend/Kconfig b/canutils/cansend/Kconfig index 2bd446af5..c471b7de9 100644 --- a/canutils/cansend/Kconfig +++ b/canutils/cansend/Kconfig @@ -6,7 +6,8 @@ config CANUTILS_CANSEND tristate "SocketCAN cansend tool" default n - depends on NET_CAN && CANUTILS_LIBCANUTILS + depends on NET_CAN + select CANUTILS_LIBCANUTILS ---help--- Enable the SocketCAN cansend tool ported from https://github.com/linux-can/can-utils diff --git a/canutils/cansend/Make.defs b/canutils/cansend/Make.defs index 13ddf36f4..2361a59bc 100644 --- a/canutils/cansend/Make.defs +++ b/canutils/cansend/Make.defs @@ -1,7 +1,6 @@ ############################################################################ # apps/canutils/cansend/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 +# Adds selected applications to apps/ build # # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with diff --git a/canutils/cansend/Makefile b/canutils/cansend/Makefile index ae0e2cc1c..0f106276d 100644 --- a/canutils/cansend/Makefile +++ b/canutils/cansend/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/canutils/cansend/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -30,7 +28,7 @@ PRIORITY = SCHED_PRIORITY_DEFAULT STACKSIZE = $(CONFIG_CANUTILS_CANSEND_STACKSIZE) MODULE = $(CONFIG_CANUTILS_CANSEND) -CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/canutils/libcanutils +CFLAGS += ${shell $(INCDIR) "$(CC)" $(APPDIR)/canutils/libcanutils} MAINSRC = cansend.c include $(APPDIR)/Application.mk diff --git a/canutils/cansend/cansend.c b/canutils/cansend/cansend.c index 42fcffc79..1001b52c8 100644 --- a/canutils/cansend/cansend.c +++ b/canutils/cansend/cansend.c @@ -1,8 +1,9 @@ -/**************************************************************************** - * apps/canutils/cansend/cansend.c +/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) */ +/* + * cansend.c - send CAN-frames via CAN_RAW sockets * - * SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) - * SPDX-FileCopyrightText: 2002-2007 Volkswagen Group Electronic Research + * Copyright (c) 2002-2007 Volkswagen Group Electronic Research + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -39,11 +40,7 @@ * * Send feedback to <linux-can@vger.kernel.org> * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ + */ #include <stdio.h> #include <stdlib.h> @@ -55,146 +52,118 @@ #include <sys/socket.h> #include <nuttx/can.h> +#include <netpacket/can.h> #include "lib.h" static void print_usage_send(char *prg) { - fprintf(stderr, "%s - send CAN-frames via CAN_RAW sockets.\n", prg); - fprintf(stderr, "\nUsage: %s <device> <can_frame>.\n", prg); - fprintf(stderr, "\n<can_frame>:\n"); - fprintf(stderr, - " <can_id>#{data} ""for 'classic' CAN 2.0 data frames\n"); - fprintf(stderr, - " <can_id>#R{len} for 'classic' CAN 2.0 data frames\n"); - fprintf(stderr, - " <can_id>##<flags>{data} for CAN FD frames\n\n"); - fprintf(stderr, "<can_id>:\n" - " 3 (SFF) or 8 (EFF) hex chars\n"); - fprintf(stderr, "{data}:\n" - " 0..8 (0..64 CAN FD) ASCII hex-values " - "(optionally separated by '.')\n"); - fprintf(stderr, "{len}:\n" - " an optional 0..8 value " - "as RTR frames can contain a valid dlc field\n"); - fprintf(stderr, "<flags>:\n" - " a single ASCII Hex value (0 .. F) " - "which defines canfd_frame.flags\n\n"); - fprintf(stderr, "Examples:\n"); - fprintf(stderr, " 5A1#11.2233.44556677.88 / 123#DEADBEEF / " - "5AA# / 123##1 / 213##311223344 /\n" - " 1F334455#1122334455667788 / 123#R / 00000123#R3\n\n"); + fprintf(stderr, "%s - send CAN-frames via CAN_RAW sockets.\n", prg); + fprintf(stderr, "\nUsage: %s <device> <can_frame>.\n", prg); + fprintf(stderr, "\n<can_frame>:\n"); + fprintf(stderr, " <can_id>#{data} for 'classic' CAN 2.0 data frames\n"); + fprintf(stderr, " <can_id>#R{len} for 'classic' CAN 2.0 data frames\n"); + fprintf(stderr, " <can_id>##<flags>{data} for CAN FD frames\n\n"); + fprintf(stderr, "<can_id>:\n" + " 3 (SFF) or 8 (EFF) hex chars\n"); + fprintf(stderr, "{data}:\n" + " 0..8 (0..64 CAN FD) ASCII hex-values (optionally separated by '.')\n"); + fprintf(stderr, "{len}:\n" + " an optional 0..8 value as RTR frames can contain a valid dlc field\n"); + fprintf(stderr, "<flags>:\n" + " a single ASCII Hex value (0 .. F) which defines canfd_frame.flags\n\n"); + fprintf(stderr, "Examples:\n"); + fprintf(stderr, " 5A1#11.2233.44556677.88 / 123#DEADBEEF / 5AA# / 123##1 / 213##311223344 /\n" + " 1F334455#1122334455667788 / 123#R / 00000123#R3\n\n"); } -/**************************************************************************** - * Public Functions - ****************************************************************************/ + int main(int argc, char **argv) { - /* can raw socket */ + int s; /* can raw socket */ + int required_mtu; + int mtu; + int enable_canfd = 1; + struct sockaddr_can addr; + struct canfd_frame frame; + struct ifreq ifr; - int s; - int required_mtu; - int mtu; - int enable_canfd = 1; - struct sockaddr_can addr; - struct canfd_frame frame; - struct ifreq ifr; + /* check command line options */ + if (argc != 3) { + print_usage_send(argv[0]); + return 1; + } - /* check command line options */ + /* parse CAN frame */ + required_mtu = parse_canframe(argv[2], &frame); + if (!required_mtu){ + fprintf(stderr, "\nWrong CAN-frame format!\n\n"); + print_usage_send(argv[0]); + return 1; + } - if (argc != 3) - { - print_usage_send(argv[0]); - return 1; - } + /* open socket */ + if ((s = socket(PF_CAN, SOCK_RAW, CAN_RAW)) < 0) { + perror("socket"); + return 1; + } - /* parse CAN frame */ + strncpy(ifr.ifr_name, argv[1], IFNAMSIZ - 1); + ifr.ifr_name[IFNAMSIZ - 1] = '\0'; + ifr.ifr_ifindex = if_nametoindex(ifr.ifr_name); + if (!ifr.ifr_ifindex) { + perror("if_nametoindex"); + return 1; + } - required_mtu = parse_canframe(argv[2], &frame); - if (!required_mtu) - { - fprintf(stderr, "\nWrong CAN-frame format!\n\n"); - print_usage_send(argv[0]); - return 1; - } + memset(&addr, 0, sizeof(addr)); + addr.can_family = AF_CAN; + addr.can_ifindex = ifr.ifr_ifindex; - /* open socket */ + if (required_mtu > (int)CAN_MTU) { - if ((s = socket(PF_CAN, SOCK_RAW, CAN_RAW)) < 0) - { - perror("socket"); - return 1; - } + /* check if the frame fits into the CAN netdevice */ + if (ioctl(s, SIOCGIFMTU, &ifr) < 0) { + perror("SIOCGIFMTU"); + return 1; + } + mtu = ifr.ifr_mtu; - strlcpy(ifr.ifr_name, argv[1], IFNAMSIZ); - ifr.ifr_ifindex = if_nametoindex(ifr.ifr_name); - if (!ifr.ifr_ifindex) - { - perror("if_nametoindex"); - return 1; - } + if (mtu != CANFD_MTU) { + printf("CAN interface is not CAN FD capable - sorry.\n"); + return 1; + } - memset(&addr, 0, sizeof(addr)); - addr.can_family = AF_CAN; - addr.can_ifindex = ifr.ifr_ifindex; + /* interface is ok - try to switch the socket into CAN FD mode */ + if (setsockopt(s, SOL_CAN_RAW, CAN_RAW_FD_FRAMES, + &enable_canfd, sizeof(enable_canfd))){ + printf("error when enabling CAN FD support\n"); + return 1; + } - if (required_mtu > (int)CAN_MTU) - { - /* check if the frame fits into the CAN netdevice */ + /* ensure discrete CAN FD length values 0..8, 12, 16, 20, 24, 32, 64 */ + frame.len = can_dlc2len(can_len2dlc(frame.len)); + } - if (ioctl(s, SIOCGIFMTU, &ifr) < 0) - { - perror("SIOCGIFMTU"); - return 1; - } + /* disable default receive filter on this RAW socket */ + /* This is obsolete as we do not read from the socket at all, but for */ + /* this reason we can remove the receive list in the Kernel to save a */ + /* little (really a very little!) CPU usage. */ + setsockopt(s, SOL_CAN_RAW, CAN_RAW_FILTER, NULL, 0); - mtu = ifr.ifr_mtu; + if (bind(s, (struct sockaddr *)&addr, sizeof(addr)) < 0) { + perror("bind"); + return 1; + } - if (mtu != CANFD_MTU) - { - printf("CAN interface is not CAN FD capable - sorry.\n"); - return 1; - } + /* send frame */ + if (write(s, &frame, required_mtu) != required_mtu) { + perror("write"); + return 1; + } - /* interface is ok - try to switch the socket into CAN FD mode */ + close(s); - if (setsockopt(s, SOL_CAN_RAW, CAN_RAW_FD_FRAMES, - &enable_canfd, sizeof(enable_canfd))) - { - printf("error when enabling CAN FD support\n"); - return 1; - } - - /* ensure discrete CAN FD length values 0..8, 12, 16, 20, 24, 32, 64 */ - - frame.len = can_dlc2len(can_len2dlc(frame.len)); - } - - /* disable default receive filter on this RAW socket - * This is obsolete as we do not read from the socket at all, but for - * this reason we can remove the receive list in the Kernel to save a - * little (really a very little!) CPU usage. - */ - - setsockopt(s, SOL_CAN_RAW, CAN_RAW_FILTER, NULL, 0); - - if (bind(s, (struct sockaddr *)&addr, sizeof(addr)) < 0) - { - perror("bind"); - return 1; - } - - /* send frame */ - - if (write(s, &frame, required_mtu) != required_mtu) - { - perror("write"); - return 1; - } - - close(s); - - return 0; + return 0; } diff --git a/canutils/lely-canopen/.gitignore b/canutils/lely-canopen/.gitignore deleted file mode 100644 index f3efe35af..000000000 --- a/canutils/lely-canopen/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/lely-* -/*.tar.gz diff --git a/canutils/lely-canopen/0001-tools-eliminate-multiple-definitions-of-poll-compile.patch b/canutils/lely-canopen/0001-tools-eliminate-multiple-definitions-of-poll-compile.patch deleted file mode 100644 index bba46790b..000000000 --- a/canutils/lely-canopen/0001-tools-eliminate-multiple-definitions-of-poll-compile.patch +++ /dev/null @@ -1,55 +0,0 @@ -From c907795a0856f1a0eb5a250fca7c2e02bbfdf28e Mon Sep 17 00:00:00 2001 -From: raiden00pl <raiden00@railab.me> -Date: Thu, 6 Oct 2022 15:12:49 +0200 -Subject: [PATCH 1/5] tools: eliminate 'multiple definitions of poll' compiler - errors for flat address space systems - -Signed-off-by: raiden00pl <raiden00@railab.me> ---- - tools/can2udp.c | 2 +- - tools/cocatd.c | 2 +- - tools/coctl.c | 2 +- - 3 files changed, 3 insertions(+), 3 deletions(-) - -diff --git a/tools/can2udp.c b/tools/can2udp.c -index 960c6117..caee9176 100644 ---- a/tools/can2udp.c -+++ b/tools/can2udp.c -@@ -79,7 +79,7 @@ int wtm_send(co_wtm_t *wtm, const void *buf, size_t nbytes, void *data); - - int flags; - int keep = 10000; --io_poll_t *poll; -+static io_poll_t *poll; - io_handle_t can_handle = IO_HANDLE_ERROR; - io_handle_t send_handle = IO_HANDLE_ERROR; - io_handle_t recv_handle = IO_HANDLE_ERROR; -diff --git a/tools/cocatd.c b/tools/cocatd.c -index 348168d5..ad191b74 100644 ---- a/tools/cocatd.c -+++ b/tools/cocatd.c -@@ -79,7 +79,7 @@ co_unsigned32_t co_1026_up_ind( - #define FLAG_NO_DAEMON 0x02 - - int flags; --io_poll_t *poll; -+static io_poll_t *poll; - io_handle_t hcan = IO_HANDLE_ERROR; - can_net_t *net; - co_dev_t *dev; -diff --git a/tools/coctl.c b/tools/coctl.c -index 351b81c0..12f4b3aa 100644 ---- a/tools/coctl.c -+++ b/tools/coctl.c -@@ -90,7 +90,7 @@ int io_thrd_start(void *arg); - void co_net_err(struct co_net *net); - - struct co_net net[CO_GW_NUM_NET]; --io_poll_t *poll; -+static io_poll_t *poll; - - int flags; - int inhibit = INHIBIT; --- -2.48.1 - diff --git a/canutils/lely-canopen/0002-tools-coctl.c-fix-printf-issues.patch b/canutils/lely-canopen/0002-tools-coctl.c-fix-printf-issues.patch deleted file mode 100644 index e32745043..000000000 --- a/canutils/lely-canopen/0002-tools-coctl.c-fix-printf-issues.patch +++ /dev/null @@ -1,71 +0,0 @@ -From fa0d7ef4f2ef9f1efff4f79bd69c1b59332ab3ba Mon Sep 17 00:00:00 2001 -From: raiden00pl <raiden00@railab.me> -Date: Fri, 21 Mar 2025 16:10:50 +0100 -Subject: [PATCH 2/5] tools/coctl.c: fix printf issues - -Signed-off-by: raiden00pl <raiden00@railab.me> ---- - tools/coctl.c | 12 +++++++----- - 1 file changed, 7 insertions(+), 5 deletions(-) - -diff --git a/tools/coctl.c b/tools/coctl.c -index 12f4b3aa..594fe699 100644 ---- a/tools/coctl.c -+++ b/tools/coctl.c -@@ -40,6 +40,8 @@ - #include <stdlib.h> - #include <string.h> - -+#include <inttypes.h> -+ - #if _WIN32 - #include <io.h> - #endif -@@ -358,7 +360,7 @@ main(int argc, char *argv[]) - if (cmd) - printf("... "); - else -- printf("[%u] ", seq); -+ printf("[%" PRIu32 "] ", seq); - fflush(stdout); - } - // Keep reading lines until end-of-file. -@@ -409,7 +411,7 @@ main(int argc, char *argv[]) - free(cmd); - cmd = tmp; - } else { -- if (asprintf(&cmd, "[%u] %s", seq, line) -+ if (asprintf(&cmd, "[%" PRIu32 "] %s", seq, line) - == -1) { - cmd = NULL; - break; -@@ -431,7 +433,7 @@ main(int argc, char *argv[]) - result = asprintf(&tmp, "%s%s%s", - recv_buf, cmd, line); - else -- result = asprintf(&tmp, "%s[%u] %s", -+ result = asprintf(&recv_buf, "%s[%" PRIu32 "] %s", - recv_buf, seq, line); - if (result < 0) { - mtx_unlock(&recv_mtx); -@@ -444,7 +446,7 @@ main(int argc, char *argv[]) - result = asprintf(&recv_buf, "%s%s", - cmd, line); - else -- result = asprintf(&recv_buf, "[%u] %s", -+ result = asprintf(&recv_buf, "[%" PRIu32 "] %s", - seq, line); - if (result < 0) { - recv_buf = NULL; -@@ -561,7 +563,7 @@ gw_rate(co_unsigned16_t id, co_unsigned16_t rate, void *data) - return; - bitrate = rate * 1000; - if (io_can_set_bitrate(net[id - 1].handle, bitrate) == -1) -- diag(DIAG_ERROR, 0, "unable to set bitrate of %s to %u bit/s", -+ diag(DIAG_ERROR, 0, "unable to set bitrate of %s to %" PRIu32 " bit/s", - net[id - 1].can_path, bitrate); - } - --- -2.48.1 - diff --git a/canutils/lely-canopen/0003-src-co-nmt.c-fix-compilation.patch b/canutils/lely-canopen/0003-src-co-nmt.c-fix-compilation.patch deleted file mode 100644 index fbe8566e3..000000000 --- a/canutils/lely-canopen/0003-src-co-nmt.c-fix-compilation.patch +++ /dev/null @@ -1,32 +0,0 @@ -From ba671d68bde31fc8e4cd893b3634fa6bbd299784 Mon Sep 17 00:00:00 2001 -From: raiden00pl <raiden00@railab.me> -Date: Wed, 19 Mar 2025 11:18:13 +0100 -Subject: [PATCH 3/5] src/co/nmt.c: fix compilation - -Signed-off-by: raiden00pl <raiden00@railab.me> ---- - src/co/nmt.c | 2 ++ - 1 file changed, 2 insertions(+) - -diff --git a/src/co/nmt.c b/src/co/nmt.c -index fa943fba..4074e238 100644 ---- a/src/co/nmt.c -+++ b/src/co/nmt.c -@@ -1432,12 +1432,14 @@ co_nmt_on_hb(co_nmt_t *nmt, co_unsigned8_t id, int state, int reason) - if (co_nmt_is_master(nmt)) - return; - #endif -+#if !LELY_NO_CO_EMCY - if (nmt->srv.emcy) { - // Remove the EMCY message from the stack. - ssize_t n = co_emcy_find(nmt->srv.emcy, 0x8130); - if (n >= 0) - co_emcy_remove(nmt->srv.emcy, n); - } -+#endif - } - } - --- -2.48.1 - diff --git a/canutils/lely-canopen/0004-tools-coctl.c-add-missing-mutex-init.patch b/canutils/lely-canopen/0004-tools-coctl.c-add-missing-mutex-init.patch deleted file mode 100644 index 3d06bcb93..000000000 --- a/canutils/lely-canopen/0004-tools-coctl.c-add-missing-mutex-init.patch +++ /dev/null @@ -1,25 +0,0 @@ -From 8d361b53e8a1f238a0b1545d237e4b0e29fba1fe Mon Sep 17 00:00:00 2001 -From: raiden00pl <raiden00@railab.me> -Date: Thu, 20 Mar 2025 13:58:17 +0100 -Subject: [PATCH 4/5] tools/coctl.c: add missing mutex init - -Signed-off-by: raiden00pl <raiden00@railab.me> ---- - tools/coctl.c | 1 + - 1 file changed, 1 insertion(+) - -diff --git a/tools/coctl.c b/tools/coctl.c -index 594fe699..c1d73b21 100644 ---- a/tools/coctl.c -+++ b/tools/coctl.c -@@ -287,6 +287,7 @@ main(int argc, char *argv[]) - co_gw_txt_set_recv_func(gw_txt, &gw_txt_recv, NULL); - co_gw_txt_set_send_func(gw_txt, &gw_txt_send, gw); - -+ mtx_init(&wait_mtx, mtx_plain); - mtx_init(&recv_mtx, mtx_plain); - cnd_init(&wait_cond); - wait = 0; --- -2.48.1 - diff --git a/canutils/lely-canopen/0005-add-NuttX-support.patch b/canutils/lely-canopen/0005-add-NuttX-support.patch deleted file mode 100644 index c33b5c104..000000000 --- a/canutils/lely-canopen/0005-add-NuttX-support.patch +++ /dev/null @@ -1,525 +0,0 @@ -From 3c58cd579a24a1b3ae829173c3fb124b08bb42d4 Mon Sep 17 00:00:00 2001 -From: raiden00pl <raiden00@railab.me> -Date: Wed, 19 Mar 2025 10:44:47 +0100 -Subject: [PATCH 5/5] add NuttX support - -Signed-off-by: raiden00pl <raiden00@railab.me> ---- - src/can/socket.c | 6 ++- - src/io/can.c | 95 ++++++++++++++++++++++++++++++++++++++++++++++- - src/io/poll.c | 2 +- - src/util/errnum.c | 11 +++--- - src/util/frbuf.c | 24 ++++++------ - src/util/fwbuf.c | 37 +++++++++--------- - 6 files changed, 136 insertions(+), 39 deletions(-) - -diff --git a/src/can/socket.c b/src/can/socket.c -index 4fc133dd..a35b281e 100644 ---- a/src/can/socket.c -+++ b/src/can/socket.c -@@ -39,6 +39,10 @@ - #include <linux/can/error.h> - #endif - -+#ifdef __NuttX__ -+#include <nuttx/can.h> -+#endif -+ - int - can_frame_is_error(const struct can_frame *frame, enum can_state *pstate, - enum can_error *perror) -@@ -51,7 +55,7 @@ can_frame_is_error(const struct can_frame *frame, enum can_state *pstate, - enum can_state state = pstate ? *pstate : CAN_STATE_ACTIVE; - enum can_error error = perror ? *perror : 0; - --#ifdef HAVE_LINUX_CAN_ERROR_H -+#if defined(HAVE_LINUX_CAN_ERROR_H) || defined(__NuttX__) - if (frame->can_dlc != CAN_ERR_DLC) { - set_errnum(ERRNUM_INVAL); - return -1; -diff --git a/src/io/can.c b/src/io/can.c -index ca7e7d95..fed1ae16 100644 ---- a/src/io/can.c -+++ b/src/io/can.c -@@ -26,7 +26,7 @@ - #if !LELY_NO_STDIO - - #include <lely/util/errnum.h> --#if !LELY_NO_CAN && defined(__linux__) && HAVE_LINUX_CAN_H -+#if !LELY_NO_CAN && ((defined(__linux__) && HAVE_LINUX_CAN_H) || defined(__NuttX__)) - #include <lely/can/socket.h> - #endif - #include "handle.h" -@@ -38,7 +38,7 @@ - #include <assert.h> - #include <string.h> - --#if defined(__linux__) && HAVE_LINUX_CAN_H -+#if (defined(__linux__) && HAVE_LINUX_CAN_H) || defined(__NuttX__) - - #ifdef HAVE_LINUX_CAN_ERROR_H - #include <linux/can/error.h> -@@ -56,6 +56,12 @@ - #include <linux/can/raw.h> - #endif - -+#ifdef __NuttX__ -+#include <sys/ioctl.h> -+#include <nuttx/can.h> -+#include <net/if.h> -+#endif -+ - /// A CAN device. - struct can { - /// The I/O device base handle. -@@ -384,6 +390,8 @@ io_can_stop(io_handle_t handle) - - #endif // HAVE_LINUX_CAN_NETLINK_H && HAVE_LINUX_RTNETLINK_H - -+ -+ - int - io_can_get_state(io_handle_t handle) - { -@@ -656,6 +664,89 @@ io_can_set_txqlen(io_handle_t handle, size_t txqlen) - - #endif // HAVE_LINUX_CAN_NETLINK_H && HAVE_LINUX_RTNETLINK_H - -+#if defined(__NuttX__) -+int -+io_can_get_ec(io_handle_t handle, uint16_t *ptxec, uint16_t *prxec) -+{ -+ /* tx error count */ -+ -+ *ptxec = 0; -+ -+ /* rx error count */ -+ -+ *prxec = 0; -+ -+ return 0; -+} -+ -+int -+io_can_get_bitrate(io_handle_t handle, uint32_t *pbitrate) -+{ -+ if (!handle) { -+ errno = EBADF; -+ return -1; -+ } -+ -+ if (handle->vtab != &can_vtab) { -+ errno = ENXIO; -+ return -1; -+ } -+ struct can *can = (struct can *)handle; -+ struct ifreq ifr; -+ if_indextoname(can->ifindex, ifr.ifr_name); -+ -+ if (ioctl(handle->fd, SIOCGCANBITRATE, &ifr) == -1) { -+ return -1; -+ } -+ -+ *pbitrate = ifr.ifr_ifru.ifru_can_data.arbi_bitrate; -+ -+ return 0; -+} -+ -+int -+io_can_set_bitrate(io_handle_t handle, uint32_t bitrate) -+{ -+ if (!handle) { -+ errno = EBADF; -+ return -1; -+ } -+ -+ if (handle->vtab != &can_vtab) { -+ errno = ENXIO; -+ return -1; -+ } -+ struct can *can = (struct can *)handle; -+ struct ifreq ifr; -+ if_indextoname(can->ifindex, ifr.ifr_name); -+ -+ ifr.ifr_ifru.ifru_can_data.arbi_bitrate = bitrate; -+ ifr.ifr_ifru.ifru_can_data.data_bitrate = bitrate; -+ ifr.ifr_ifru.ifru_can_data.arbi_samplep = 0; -+ ifr.ifr_ifru.ifru_can_data.data_samplep = 0; -+ -+ if (ioctl(handle->fd, SIOCSCANBITRATE, &ifr) == -1) { -+ return -1; -+ } -+ -+ return 0; -+} -+ -+int -+io_can_get_txqlen(io_handle_t handle, size_t *ptxqlen) -+{ -+ return -1; -+} -+ -+int -+io_can_set_txqlen(io_handle_t handle, size_t txqlen) -+{ -+ return -1; -+} -+ -+#endif // __NuttX__ -+ -+ - static void - can_fini(struct io_handle *handle) - { -diff --git a/src/io/poll.c b/src/io/poll.c -index d474e337..e07b36ce 100644 ---- a/src/io/poll.c -+++ b/src/io/poll.c -@@ -261,7 +261,7 @@ io_poll_watch(io_poll_t *poll, io_handle_t handle, struct io_event *event, - - assert(handle->vtab); - switch (handle->vtab->type) { --#if defined(__linux__) && defined(HAVE_LINUX_CAN_H) -+#if (defined(__linux__) && defined(HAVE_LINUX_CAN_H)) || defined(__NuttX__) - case IO_TYPE_CAN: - #endif - #if _POSIX_C_SOURCE >= 200112L -diff --git a/src/util/errnum.c b/src/util/errnum.c -index 39e4b28a..3b295b8e 100644 ---- a/src/util/errnum.c -+++ b/src/util/errnum.c -@@ -27,6 +27,7 @@ - #include <lely/util/util.h> - - #include <string.h> -+#include <netdb.h> - - #if _WIN32 - -@@ -38,7 +39,7 @@ - - #endif // _WIN32 - --#if _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__) -+#if _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__) && !defined(__NuttX__) - static const char *gai_strerror_r(int ecode, char *strerrbuf, size_t buflen); - #endif - -@@ -545,7 +546,7 @@ errc2num(int errc) - default: return 0; - } - #else --#if _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__) -+#if _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__) && !defined(__NuttX__) - switch (errc) { - case -ABS(EAI_AGAIN): return ERRNUM_AI_AGAIN; - case -ABS(EAI_BADFLAGS): return ERRNUM_AI_BADFLAGS; -@@ -910,7 +911,7 @@ errnum2c(errnum_t errnum) - default: return 0; - } - #else --#if _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__) -+#if _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__) && !defined(__NuttX__) - switch (errnum) { - case ERRNUM_AI_AGAIN: return -ABS(EAI_AGAIN); - case ERRNUM_AI_BADFLAGS: return -ABS(EAI_BADFLAGS); -@@ -1011,7 +1012,7 @@ errc2str_r(int errc, char *strerrbuf, size_t buflen) - strerrbuf[n - 2] = '\0'; - return strerrbuf; - #else --#if _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__) -+#if _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__) && !defined(__NuttX__) - switch (errc) { - case -ABS(EAI_AGAIN): - return gai_strerror_r(EAI_AGAIN, strerrbuf, buflen); -@@ -1036,7 +1037,7 @@ errc2str_r(int errc, char *strerrbuf, size_t buflen) - #endif - } - --#if _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__) -+#if _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__) && !defined(__NuttX__) - static const char * - gai_strerror_r(int ecode, char *strerrbuf, size_t buflen) - { -diff --git a/src/util/frbuf.c b/src/util/frbuf.c -index e01b7677..7157129b 100644 ---- a/src/util/frbuf.c -+++ b/src/util/frbuf.c -@@ -41,7 +41,7 @@ - #include <stdio.h> - #if _POSIX_C_SOURCE >= 200112L - #include <fcntl.h> --#if _POSIX_MAPPED_FILES >= 200112L -+#if _POSIX_MAPPED_FILES >= 200112L && !defined(__NuttX__) - #include <sys/mman.h> - #endif - #include <sys/stat.h> -@@ -57,7 +57,7 @@ struct __frbuf { - HANDLE hFileMappingObject; - /// The base address of the file mapping. - LPVOID lpBaseAddress; --#elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__) -+#elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__) && !defined(__NuttX__) - /// The file descriptor. - int fd; - /// The base address of the current file mapping. -@@ -75,7 +75,7 @@ struct __frbuf { - void * - __frbuf_alloc(void) - { -- void *ptr = malloc(sizeof(struct __frbuf)); -+ void *ptr = zalloc(sizeof(struct __frbuf)); - if (!ptr) - set_errc(errno2c(errno)); - return ptr; -@@ -102,7 +102,7 @@ __frbuf_init(struct __frbuf *buf, const char *filename) - - buf->hFileMappingObject = INVALID_HANDLE_VALUE; - buf->lpBaseAddress = NULL; --#elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__) -+#elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__) && !defined(__NuttX__) - buf->fd = open(filename, O_RDONLY | O_CLOEXEC); - if (buf->fd == -1) - return NULL; -@@ -127,7 +127,7 @@ __frbuf_fini(struct __frbuf *buf) - - #if _WIN32 - CloseHandle(buf->hFile); --#elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__) -+#elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__) && !defined(__NuttX__) - close(buf->fd); - #else - fclose(buf->stream); -@@ -178,7 +178,7 @@ frbuf_get_size(frbuf_t *buf) - if (!GetFileSizeEx(buf->hFile, &FileSize)) - return -1; - return FileSize.QuadPart; --#elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__) -+#elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__) && !defined(__NuttX__) - #ifdef __linux__ - struct stat64 stat; - if (fstat64(buf->fd, &stat) == -1) -@@ -223,7 +223,7 @@ frbuf_get_pos(frbuf_t *buf) - if (!SetFilePointerEx(buf->hFile, li, &li, FILE_CURRENT)) - return -1; - return li.QuadPart; --#elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__) -+#elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__) && !defined(__NuttX__) - #ifdef __linux__ - return lseek64(buf->fd, 0, SEEK_CUR); - #else -@@ -252,7 +252,7 @@ frbuf_set_pos(frbuf_t *buf, intmax_t pos) - if (!SetFilePointerEx(buf->hFile, li, &li, FILE_BEGIN)) - return -1; - return li.QuadPart; --#elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__) -+#elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__) && !defined(__NuttX__) - #ifdef __linux__ - return lseek64(buf->fd, pos, SEEK_SET); - #else -@@ -285,7 +285,7 @@ frbuf_read(frbuf_t *buf, void *ptr, size_t size) - if (!ReadFile(buf->hFile, ptr, size, &nNumberOfBytesRead, NULL)) - return -1; - return nNumberOfBytesRead; --#elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__) -+#elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__) && !defined(__NuttX__) - ssize_t result; - do - result = read(buf->fd, ptr, size); -@@ -349,7 +349,7 @@ error_ReadFile: - error_get_pos: - SetLastError(dwErrCode); - return result; --#elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__) -+#elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__) && !defined(__NuttX__) - ssize_t result; - #ifdef __linux__ - do -@@ -453,7 +453,7 @@ error_CreateFileMapping: - error_size: - SetLastError(dwErrCode); - return NULL; --#elif _POSIX_MAPPED_FILES >= 200112L -+#elif _POSIX_MAPPED_FILES >= 200112L && !defined(__NuttX__) - long page_size = sysconf(_SC_PAGE_SIZE); - if (page_size <= 0) - return NULL; -@@ -532,7 +532,7 @@ frbuf_unmap(frbuf_t *buf) - buf->hFileMappingObject = INVALID_HANDLE_VALUE; - buf->lpBaseAddress = NULL; - } --#elif _POSIX_MAPPED_FILES >= 200112L -+#elif _POSIX_MAPPED_FILES >= 200112L && !defined(__NuttX__) - if (buf->addr != MAP_FAILED) { - result = munmap(buf->addr, buf->len); - -diff --git a/src/util/fwbuf.c b/src/util/fwbuf.c -index 22c61fd7..33ba11c7 100644 ---- a/src/util/fwbuf.c -+++ b/src/util/fwbuf.c -@@ -48,7 +48,7 @@ - #if _POSIX_C_SOURCE >= 200112L - #include <fcntl.h> - #include <libgen.h> --#if _POSIX_MAPPED_FILES >= 200112L -+#if _POSIX_MAPPED_FILES >= 200112L && !defined(__NuttX__) - #include <sys/mman.h> - #endif - #include <sys/stat.h> -@@ -72,7 +72,7 @@ struct __fwbuf { - LPVOID lpBaseAddress; - /// The number of bytes mapped at <b>lpBaseAddress</b>. - SIZE_T dwNumberOfBytesToMap; --#elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__) -+#elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__) && !defined(__NuttX__) - /// A pointer to the name of the temporary file. - char *tmpname; - /// The file descriptor of the directory containing the temporary file. -@@ -175,7 +175,7 @@ error_GetTempFileNameA: - error_strdup: - SetLastError(dwErrCode); - return NULL; --#elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__) -+#elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__) && !defined(__NuttX__) - int errsv = 0; - - buf->filename = strdup(filename); -@@ -295,7 +295,7 @@ __fwbuf_fini(struct __fwbuf *buf) - fwbuf_commit(buf); - set_errc(errc); - --#if _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__) -+#if _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__) && !defined(__NuttX__) - free(buf->tmpname); - #endif - free(buf->filename); -@@ -348,7 +348,7 @@ fwbuf_get_size(fwbuf_t *buf) - return -1; - } - return FileSize.QuadPart; --#elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__) -+#elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__) && !defined(__NuttX__) - #ifdef __linux__ - struct stat64 stat; - if (fstat64(buf->fd, &stat) == -1) { -@@ -388,7 +388,7 @@ fwbuf_set_size(fwbuf_t *buf, intmax_t size) - return -1; - - return 0; --#elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__) -+#elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__) && !defined(__NuttX__) - #ifdef __linux__ - if (ftruncate64(buf->fd, size) == -1) { - #else -@@ -424,7 +424,7 @@ fwbuf_get_pos(fwbuf_t *buf) - return -1; - } - return li.QuadPart; --#elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__) -+#elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__) && !defined(__NuttX__) - #ifdef __linux__ - intmax_t pos = lseek64(buf->fd, 0, SEEK_CUR); - #else -@@ -456,7 +456,8 @@ fwbuf_set_pos(fwbuf_t *buf, intmax_t pos) - return -1; - } - return li.QuadPart; --#elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__) -+/* #elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__) */ -+#elif !defined(__NuttX__) - #ifdef __linux__ - pos = lseek64(buf->fd, pos, SEEK_SET); - #else -@@ -503,7 +504,7 @@ fwbuf_write(fwbuf_t *buf, const void *ptr, size_t size) - return -1; - } - return nNumberOfBytesWritten; --#elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__) -+#elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__) && !defined(__NuttX__) - ssize_t result; - do - result = write(buf->fd, ptr, size); -@@ -587,7 +588,7 @@ error_get_pos: - error_pos: - SetLastError(buf->dwErrCode); - return result; --#elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__) -+#elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__) && !defined(__NuttX__) - ssize_t result; - #ifdef __linux__ - do -@@ -666,7 +667,7 @@ fwbuf_map(fwbuf_t *buf, intmax_t pos, size_t *psize) - if (pos < 0) { - #if _WIN32 - SetLastError(buf->dwErrCode = ERROR_INVALID_PARAMETER); --#elif _POSIX_MAPPED_FILES >= 200112L -+#elif _POSIX_MAPPED_FILES >= 200112L && !defined(__NuttX__) - errno = buf->errsv = EINVAL; - #else - set_errnum(buf->errnum = ERRNUM_INVAL); -@@ -676,7 +677,7 @@ fwbuf_map(fwbuf_t *buf, intmax_t pos, size_t *psize) - if (pos > (intmax_t)size) { - #if _WIN32 - SetLastError(buf->dwErrCode = ERROR_INVALID_PARAMETER); --#elif _POSIX_MAPPED_FILES >= 200112L -+#elif _POSIX_MAPPED_FILES >= 200112L && !defined(__NuttX__) - errno = buf->errsv = EOVERFLOW; - #else - set_errnum(buf->errnum = ERRNUM_OVERFLOW); -@@ -728,7 +729,7 @@ error_CreateFileMapping: - error_size: - SetLastError(buf->dwErrCode); - return NULL; --#elif _POSIX_MAPPED_FILES >= 200112L -+#elif _POSIX_MAPPED_FILES >= 200112L && !defined(__NuttX__) - long page_size = sysconf(_SC_PAGE_SIZE); - if (page_size <= 0) { - buf->errsv = errno; -@@ -863,7 +864,7 @@ fwbuf_unmap(fwbuf_t *buf) - buf->dwErrCode = dwErrCode; - SetLastError(dwErrCode); - } --#elif _POSIX_MAPPED_FILES >= 200112L -+#elif _POSIX_MAPPED_FILES >= 200112L && !defined(__NuttX__) - int errsv = 0; - if (buf->errsv) { - result = -1; -@@ -931,7 +932,7 @@ fwbuf_clearerr(fwbuf_t *buf) - - #if _WIN32 - buf->dwErrCode = 0; --#elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__) -+#elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__) && !defined(__NuttX__) - buf->errsv = 0; - #else - buf->errnum = 0; -@@ -947,7 +948,7 @@ fwbuf_error(fwbuf_t *buf) - if (buf->dwErrCode) - SetLastError(buf->dwErrCode); - return !!buf->dwErrCode; --#elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__) -+#elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__) && !defined(__NuttX__) - if (buf->errsv) - errno = buf->errsv; - return !!buf->errsv; -@@ -966,7 +967,7 @@ fwbuf_cancel(fwbuf_t *buf) - #if _WIN32 - if (!buf->dwErrCode) - buf->dwErrCode = ERROR_OPERATION_ABORTED; --#elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__) -+#elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__) && !defined(__NuttX__) - if (!buf->errsv) - buf->errsv = ECANCELED; - #else -@@ -1013,7 +1014,7 @@ fwbuf_commit(fwbuf_t *buf) - done: - SetLastError(buf->dwErrCode = dwErrCode); - return result; --#elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__) -+#elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__) && !defined(__NuttX__) - int errsv = errno; - - if (buf->fd == -1) --- -2.48.1 - diff --git a/canutils/lely-canopen/CMakeLists.txt b/canutils/lely-canopen/CMakeLists.txt deleted file mode 100644 index 8331511b1..000000000 --- a/canutils/lely-canopen/CMakeLists.txt +++ /dev/null @@ -1,231 +0,0 @@ -# ############################################################################## -# apps/canutils/lely-canopen/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_CANUTILS_LELYCANOPEN) - - # ############################################################################ - # Config and Fetch lelycanopen lib - # ############################################################################ - - set(LELYCANOPEN_DIR ${CMAKE_CURRENT_LIST_DIR}/lely-core) - - if(NOT EXISTS ${LELYCANOPEN_DIR}) - FetchContent_Declare( - lelycanopen_fetch - URL ${CONFIG_CANUTILS_LELYCANOPEN_URL}/lely-core-${CONFIG_CANUTILS_LELYCANOPEN_VERSION}.tar.gz - SOURCE_DIR - ${CMAKE_CURRENT_LIST_DIR}/lely-core - BINARY_DIR - ${CMAKE_BINARY_DIR}/apps/canutils/lely-canopen/lely-core - PATCH_COMMAND - patch -p1 -d ${CMAKE_CURRENT_LIST_DIR}/lely-core < - ${CMAKE_CURRENT_LIST_DIR}/0001-tools-eliminate-multiple-definitions-of-poll-compile.patch - && patch -p1 -d ${CMAKE_CURRENT_LIST_DIR}/lely-core < - ${CMAKE_CURRENT_LIST_DIR}/0002-tools-coctl.c-fix-printf-issues.patch && - patch -p1 -d ${CMAKE_CURRENT_LIST_DIR}/lely-core < - ${CMAKE_CURRENT_LIST_DIR}/0003-src-co-nmt.c-fix-compilation.patch && - patch -p1 -d ${CMAKE_CURRENT_LIST_DIR}/lely-core < - ${CMAKE_CURRENT_LIST_DIR}/0004-tools-coctl.c-add-missing-mutex-init.patch - && patch -p1 -d ${CMAKE_CURRENT_LIST_DIR}/lely-core < - ${CMAKE_CURRENT_LIST_DIR}/0005-add-NuttX-support.patch - DOWNLOAD_NO_PROGRESS true - TIMEOUT 30) - - FetchContent_GetProperties(lelycanopen_fetch) - - if(NOT lelycanopen_fetch_POPULATED) - FetchContent_Populate(lelycanopen_fetch) - endif() - endif() - - nuttx_add_library(lelycanopen STATIC) - - # ############################################################################ - # Flags - # ############################################################################ - - set(CFLAGS -Wno-shadow -Wno-undef -DHAVE_CONFIG_H=1) - - # ############################################################################ - # Sources - # ############################################################################ - - set(CSRCS) - - # CAN network object - list(APPEND CSRCS ${LELYCANOPEN_DIR}/src/can/buf.c - ${LELYCANOPEN_DIR}/src/can/msg.c ${LELYCANOPEN_DIR}/src/can/vci.c - ${LELYCANOPEN_DIR}/src/can/net.c) - # CANopen library - list( - APPEND - CSRCS - ${LELYCANOPEN_DIR}/src/co/crc.c - ${LELYCANOPEN_DIR}/src/co/dev.c - ${LELYCANOPEN_DIR}/src/co/nmt.c - ${LELYCANOPEN_DIR}/src/co/nmt_hb.c - ${LELYCANOPEN_DIR}/src/co/nmt_srv.c - ${LELYCANOPEN_DIR}/src/co/obj.c - ${LELYCANOPEN_DIR}/src/co/pdo.c - ${LELYCANOPEN_DIR}/src/co/sdo.c - ${LELYCANOPEN_DIR}/src/co/ssdo.c - ${LELYCANOPEN_DIR}/src/co/type.c - ${LELYCANOPEN_DIR}/src/co/val.c) - - if(CONFIG_CANUTILS_LELYCANOPEN_TIME) - list(APPEND CSRCS ${LELYCANOPEN_DIR}/src/co/time.c) - endif() - - if(CONFIG_CANUTILS_LELYCANOPEN_CSDO) - list(APPEND CSRCS ${LELYCANOPEN_DIR}/src/co/csdo.c) - endif() - - if(CONFIG_CANUTILS_LELYCANOPEN_DCF) - list(APPEND CSRCS ${LELYCANOPEN_DIR}/src/co/dcf.c) - endif() - - if(CONFIG_CANUTILS_LELYCANOPEN_EMCY) - list(APPEND CSRCS ${LELYCANOPEN_DIR}/src/co/emcy.c) - endif() - - if(CONFIG_CANUTILS_LELYCANOPEN_GW) - list(APPEND CSRCS ${LELYCANOPEN_DIR}/src/co/gw.c) - endif() - - if(CONFIG_CANUTILS_LELYCANOPEN_GW_TXT) - list(APPEND CSRCS ${LELYCANOPEN_DIR}/src/co/gw_txt.c) - endif() - - if(CONFIG_CANUTILS_LELYCANOPEN_LSS) - list(APPEND CSRCS ${LELYCANOPEN_DIR}/src/co/lss.c) - endif() - - if(CONFIG_CANUTILS_LELYCANOPEN_NMTBOOT) - list(APPEND CSRCS ${LELYCANOPEN_DIR}/src/co/nmt_boot.c) - endif() - - if(CONFIG_CANUTILS_LELYCANOPEN_NMTCFG) - list(APPEND CSRCS ${LELYCANOPEN_DIR}/src/co/nmt_cfg.c) - endif() - - if(CONFIG_CANUTILS_LELYCANOPEN_RPDO) - list(APPEND CSRCS ${LELYCANOPEN_DIR}/src/co/rpdo.c) - endif() - - if(CONFIG_CANUTILS_LELYCANOPEN_SDEV) - list(APPEND CSRCS ${LELYCANOPEN_DIR}/src/co/sdev.c) - endif() - - if(CONFIG_CANUTILS_LELYCANOPEN_SYNC) - list(APPEND CSRCS ${LELYCANOPEN_DIR}/src/co/sync.c) - endif() - - if(CONFIG_CANUTILS_LELYCANOPEN_TPDO) - list(APPEND CSRCS ${LELYCANOPEN_DIR}/src/co/tpdo.c) - endif() - - if(CONFIG_CANUTILS_LELYCANOPEN_WTM) - list(APPEND CSRCS ${LELYCANOPEN_DIR}/src/co/wtm.c) - endif() - - # utils - - if(CONFIG_CANUTILS_LELYCANOPEN_DIAG) - list(APPEND CSRCS ${LELYCANOPEN_DIR}/src/util/diag.c) - endif() - - list( - APPEND - CSRCS - ${LELYCANOPEN_DIR}/src/util/bits.c - ${LELYCANOPEN_DIR}/src/util/bitset.c - ${LELYCANOPEN_DIR}/src/util/cmp.c - ${LELYCANOPEN_DIR}/src/util/config.c - ${LELYCANOPEN_DIR}/src/util/config_ini.c - ${LELYCANOPEN_DIR}/src/util/dllist.c - ${LELYCANOPEN_DIR}/src/util/endian.c - ${LELYCANOPEN_DIR}/src/util/errnum.c - ${LELYCANOPEN_DIR}/src/util/frbuf.c - ${LELYCANOPEN_DIR}/src/util/fwbuf.c - ${LELYCANOPEN_DIR}/src/util/lex.c - ${LELYCANOPEN_DIR}/src/util/membuf.c - ${LELYCANOPEN_DIR}/src/util/pheap.c - ${LELYCANOPEN_DIR}/src/util/print.c - ${LELYCANOPEN_DIR}/src/util/rbtree.c - ${LELYCANOPEN_DIR}/src/util/stop.c - ${LELYCANOPEN_DIR}/src/util/time.c - ${LELYCANOPEN_DIR}/src/util/ustring.c) - - # Lely IO lib - if(CONFIG_CANUTILS_LELYCANOPEN_IOLIB) - list( - APPEND - CSRCS - ${LELYCANOPEN_DIR}/src/io/handle.c - ${LELYCANOPEN_DIR}/src/io/io.c - ${LELYCANOPEN_DIR}/src/io/pipe.c - ${LELYCANOPEN_DIR}/src/io/poll.c - ${LELYCANOPEN_DIR}/src/io2/posix/poll.c - ${LELYCANOPEN_DIR}/src/io2/ctx.c - ${LELYCANOPEN_DIR}/src/io/can.c - ${LELYCANOPEN_DIR}/src/can/socket.c) - endif() - - # ############################################################################ - # Include Directory - # ############################################################################ - - set(INCDIR ${LELYCANOPEN_DIR}/include ${NUTTX_APPS_DIR}/include/canutils/lely) - - # ############################################################################ - # Applications Configuration - # ############################################################################ - - if(CONFIG_CANUTILS_LELYCANOPEN_TOOLS_COCTL) - nuttx_add_application( - NAME - coctl - PRIORITY - ${CONFIG_CANUTILS_LELYCANOPEN_TOOLS_COCTL_PRIORITY} - STACKSIZE - ${CONFIG_CANUTILS_LELYCANOPEN_TOOLS_COCTL_STACKSIZE} - COMPILE_FLAGS - ${CFLAGS} - SRCS - ${LELYCANOPEN_DIR}/tools/coctl.c - MODULE - ${CONFIG_CANUTILS_LELYCANOPEN} - INCLUDE_DIRECTORIES - ${INCDIR} - DEPENDS - lelycanopen) - endif() - - # ############################################################################ - # Library Configuration - # ############################################################################ - - target_compile_options(lelycanopen PRIVATE ${CFLAGS}) - target_sources(lelycanopen PRIVATE ${CSRCS}) - target_include_directories(lelycanopen PRIVATE ${INCDIR}) - -endif() diff --git a/canutils/lely-canopen/Kconfig b/canutils/lely-canopen/Kconfig deleted file mode 100644 index fe665a757..000000000 --- a/canutils/lely-canopen/Kconfig +++ /dev/null @@ -1,175 +0,0 @@ -menuconfig CANUTILS_LELYCANOPEN - bool "Lely CANopen support" - default n - ---help--- - Enable the Lely CANopen build - -if CANUTILS_LELYCANOPEN - -config CANUTILS_LELYCANOPEN_URL - string "URL where Lely CANopen can be downloaded" - default "https://gitlab.com/lely_industries/lely-core/-/archive/master/" - -config CANUTILS_LELYCANOPEN_VERSION - string "Version number" - default "637de61625c9e8af2b9598109d6fb0e3a2829ce6" - -menu "Lely CANopen configuration" - -config CANUTILS_LELYCANOPEN_CANFD - bool "Lely CANopen enable CAN FD support" - default n - -config CANUTILS_LELYCANOPEN_DIAG - bool "Lely CANopen enable diagnostic functions" - default n - -config CANUTILS_LELYCANOPEN_DCF - bool "Lely CANopen enable EDS/DCF support" - default n - -config CANUTILS_LELYCANOPEN_OBJDEFAULT - bool "Lely CANopen enable default values in the object dictionary" - default n - -config CANUTILS_LELYCANOPEN_OBJFILE - bool "Lely CANopen enable file support in the object dictionary" - default n - -config CANUTILS_LELYCANOPEN_OBJLIMITS - bool "Lely CANopen enable limit values in the object dictionary" - default n - -config CANUTILS_LELYCANOPEN_OBJNAME - bool "Lely CANopen enable names in the object dictionary" - default n - -config CANUTILS_LELYCANOPEN_OBJUPLOAD - bool "Lely CANopen enable upload indication functions in the object dictionary" - default n - -config CANUTILS_LELYCANOPEN_SDEV - bool "Lely CANopen enable static device description support" - default n - depends on CANUTILS_LELYCANOPEN_OBJNAME - -config CANUTILS_LELYCANOPEN_CSDO - bool "Lely CANopen enable Client-SDO support" - default n - -config CANUTILS_LELYCANOPEN_RPDO - bool "Lely CANopen enable Receive-PDO support" - default n - -config CANUTILS_LELYCANOPEN_TPDO - bool "Lely CANopen enable Transmit-PDO support" - default n - -config CANUTILS_LELYCANOPEN_MPDO - bool "Lely CANopen enable Multiplex PDO support" - default n - depends on CANUTILS_LELYCANOPEN_TPDO - -config CANUTILS_LELYCANOPEN_SYNC - bool "Lely CANopen enable SYNC support" - default n - -config CANUTILS_LELYCANOPEN_TIME - bool "Lely CANopen enable TIME support" - default n - -config CANUTILS_LELYCANOPEN_EMCY - bool "Lely CANopen enable EMCY support" - default n - -config CANUTILS_LELYCANOPEN_LSS - bool "Lely CANopen enable LSS support" - default n - -config CANUTILS_LELYCANOPEN_WTM - bool "Lely CANopen enable WTM support" - default n - -config CANUTILS_LELYCANOPEN_MASTER - bool "Lely CANopen enable MASTER support" - default n - -config CANUTILS_LELYCANOPEN_NG - bool "Lely CANopen enable node guardian support" - default n - depends on CANUTILS_LELYCANOPEN_EMCY - -config CANUTILS_LELYCANOPEN_NMTBOOT - bool "Lely CANopen enable NMT boot slave support" - default n - depends on CANUTILS_LELYCANOPEN_MASTER && CANUTILS_LELYCANOPEN_CSDO - -config CANUTILS_LELYCANOPEN_NMTCFG - bool "Lely CANopen enable NMT configuration request support" - default n - depends on CANUTILS_LELYCANOPEN_MASTER && CANUTILS_LELYCANOPEN_CSDO - -config CANUTILS_LELYCANOPEN_GW - bool "Lely CANopen enable gateway support" - default n - -config CANUTILS_LELYCANOPEN_GW_TXT - bool "Lely CANopen enable ASCII gateway support" - default n - -if HAVE_CXX - -config CANUTILS_LELYCANOPEN_COAPP_MASTER - bool "Lely CANopen C++ CANopen application master support" - default n - -config CANUTILS_LELYCANOPEN_COAPP_SLAVE - bool "Lely CANopen C++ CANopen application slave support" - default n - -endif # HAVE_CXX - -config CANUTILS_LELYCANOPEN_IOLIB - bool "Lely CANopen IO lib" - default n - depends on NET_CAN - select NETDEV_IFINDEX - select NET_CAN_SOCK_OPTS - select PIPES - -endmenu # "Lely CANopen configuration" - -menu "Lely CANopen tools" - -config CANUTILS_LELYCANOPEN_TOOLS_COCTL - bool "coctl" - depends on SERIAL_TERMIOS - depends on SYSTEM_READLINE - default n - select CANUTILS_LELYCANOPEN_IOLIB - select CANUTILS_LELYCANOPEN_DIAG - select CANUTILS_LELYCANOPEN_GW - select CANUTILS_LELYCANOPEN_DCF - select CANUTILS_LELYCANOPEN_OBJNAME - select CANUTILS_LELYCANOPEN_GW_TXT - select CANUTILS_LELYCANOPEN_EMCY - select CANUTILS_LELYCANOPEN_RPDO - select CANUTILS_LELYCANOPEN_TPDO - select CANUTILS_LELYCANOPEN_SYNC - select CANUTILS_LELYCANOPEN_CSDO - -if CANUTILS_LELYCANOPEN_TOOLS_COCTL - -config CANUTILS_LELYCANOPEN_TOOLS_COCTL_PRIORITY - int "coctl task priority" - default 100 - -config CANUTILS_LELYCANOPEN_TOOLS_COCTL_STACKSIZE - int "coctl stack size" - default DEFAULT_TASK_STACKSIZE - -endif #CANUTILS_LELYCANOPEN_TOOLS_COCTL - -endmenu # "Lely CANopen tools" - -endif # CANUTILS_LELYCANOPEN diff --git a/canutils/lely-canopen/Make.defs b/canutils/lely-canopen/Make.defs deleted file mode 100644 index 09f0c06cd..000000000 --- a/canutils/lely-canopen/Make.defs +++ /dev/null @@ -1,30 +0,0 @@ -############################################################################ -# apps/canutils/lely-canopen/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_CANUTILS_LELYCANOPEN),) -CONFIGURED_APPS += $(APPDIR)/canutils/lely-canopen - -# It allows `<lely/xxx.h>` import. - -CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/canutils/lely-canopen/lely-core/include -CXXFLAGS += ${INCDIR_PREFIX}$(APPDIR)/canutils/lely-canopen/lely-core/include -endif diff --git a/canutils/lely-canopen/Makefile b/canutils/lely-canopen/Makefile deleted file mode 100644 index 22c6a85d6..000000000 --- a/canutils/lely-canopen/Makefile +++ /dev/null @@ -1,207 +0,0 @@ -############################################################################ -# apps/canutils/lely-canopen/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -########################################################################### - -# Standard includes - -include $(APPDIR)/Make.defs - -# Set up build configuration and environment - -WD := ${shell echo $(CURDIR) | sed -e 's/ /\\ /g'} - -LELYCANOPEN_VERSION = $(patsubst "%",%,$(strip $(CONFIG_CANUTILS_LELYCANOPEN_VERSION))) - -LELYCANOPEN_TARBALL = lely-core-$(LELYCANOPEN_VERSION).tar.gz -LELYCANOPEN_SRCNAME = lely-core -UNPACK ?= tar -zxf -LELYCANOPEN_SRCDIR = $(WD)/$(LELYCANOPEN_SRCNAME) - -# The GitLab "archive/master" tarball unpacks to a directory named -# lely-core-master-<sha>, where <sha> is the current tip of master - -LELYCANOPEN_UNPACKGLOB = lely-core-master-* -LELYCANOPEN_PATCHES = $(sort $(wildcard *.patch)) - -# CAN network object - -CSRCS += $(LELYCANOPEN_SRCDIR)/src/can/buf.c -CSRCS += $(LELYCANOPEN_SRCDIR)/src/can/msg.c -CSRCS += $(LELYCANOPEN_SRCDIR)/src/can/vci.c -CSRCS += $(LELYCANOPEN_SRCDIR)/src/can/net.c - -# CANopen library - -CSRCS += $(LELYCANOPEN_SRCDIR)/src/co/crc.c -CSRCS += $(LELYCANOPEN_SRCDIR)/src/co/dev.c -CSRCS += $(LELYCANOPEN_SRCDIR)/src/co/nmt.c -CSRCS += $(LELYCANOPEN_SRCDIR)/src/co/nmt_hb.c -CSRCS += $(LELYCANOPEN_SRCDIR)/src/co/nmt_srv.c -CSRCS += $(LELYCANOPEN_SRCDIR)/src/co/obj.c -CSRCS += $(LELYCANOPEN_SRCDIR)/src/co/pdo.c -CSRCS += $(LELYCANOPEN_SRCDIR)/src/co/sdo.c -CSRCS += $(LELYCANOPEN_SRCDIR)/src/co/ssdo.c -CSRCS += $(LELYCANOPEN_SRCDIR)/src/co/type.c -CSRCS += $(LELYCANOPEN_SRCDIR)/src/co/val.c - -ifeq ($(CONFIG_CANUTILS_LELYCANOPEN_TIME),y) -CSRCS += $(LELYCANOPEN_SRCDIR)/src/co/time.c -endif - -ifeq ($(CONFIG_CANUTILS_LELYCANOPEN_CSDO),y) -CSRCS += $(LELYCANOPEN_SRCDIR)/src/co/csdo.c -endif - -ifeq ($(CONFIG_CANUTILS_LELYCANOPEN_DCF),y) -CSRCS += $(LELYCANOPEN_SRCDIR)/src/co/dcf.c -endif - -ifeq ($(CONFIG_CANUTILS_LELYCANOPEN_EMCY),y) -CSRCS += $(LELYCANOPEN_SRCDIR)/src/co/emcy.c -endif - -ifeq ($(CONFIG_CANUTILS_LELYCANOPEN_GW),y) -CSRCS += $(LELYCANOPEN_SRCDIR)/src/co/gw.c -endif - -ifeq ($(CONFIG_CANUTILS_LELYCANOPEN_GW_TXT),y) -CSRCS += $(LELYCANOPEN_SRCDIR)/src/co/gw_txt.c -endif - -ifeq ($(CONFIG_CANUTILS_LELYCANOPEN_LSS),y) -CSRCS += $(LELYCANOPEN_SRCDIR)/src/co/lss.c -endif - -ifeq ($(CONFIG_CANUTILS_LELYCANOPEN_NMTBOOT),y) -CSRCS += $(LELYCANOPEN_SRCDIR)/src/co/nmt_boot.c -endif - -ifeq ($(CONFIG_CANUTILS_LELYCANOPEN_NMTCFG),y) -CSRCS += $(LELYCANOPEN_SRCDIR)/src/co/nmt_cfg.c -endif - -ifeq ($(CONFIG_CANUTILS_LELYCANOPEN_RPDO),y) -CSRCS += $(LELYCANOPEN_SRCDIR)/src/co/rpdo.c -endif - -ifeq ($(CONFIG_CANUTILS_LELYCANOPEN_SDEV),y) -CSRCS += $(LELYCANOPEN_SRCDIR)/src/co/sdev.c -endif - -ifeq ($(CONFIG_CANUTILS_LELYCANOPEN_SYNC),y) -CSRCS += $(LELYCANOPEN_SRCDIR)/src/co/sync.c -endif - -ifeq ($(CONFIG_CANUTILS_LELYCANOPEN_TPDO),y) -CSRCS += $(LELYCANOPEN_SRCDIR)/src/co/tpdo.c -endif - -ifeq ($(CONFIG_CANUTILS_LELYCANOPEN_WTM),y) -CSRCS += $(LELYCANOPEN_SRCDIR)/src/co/wtm.c -endif - -# utils - -ifeq ($(CONFIG_CANUTILS_LELYCANOPEN_DIAG),y) -CSRCS += $(LELYCANOPEN_SRCDIR)/src/util/diag.c -endif - -CSRCS += $(LELYCANOPEN_SRCDIR)/src/util/bits.c -CSRCS += $(LELYCANOPEN_SRCDIR)/src/util/bitset.c -CSRCS += $(LELYCANOPEN_SRCDIR)/src/util/cmp.c -CSRCS += $(LELYCANOPEN_SRCDIR)/src/util/config.c -CSRCS += $(LELYCANOPEN_SRCDIR)/src/util/config_ini.c -CSRCS += $(LELYCANOPEN_SRCDIR)/src/util/dllist.c -CSRCS += $(LELYCANOPEN_SRCDIR)/src/util/endian.c -CSRCS += $(LELYCANOPEN_SRCDIR)/src/util/errnum.c -CSRCS += $(LELYCANOPEN_SRCDIR)/src/util/frbuf.c -CSRCS += $(LELYCANOPEN_SRCDIR)/src/util/fwbuf.c -CSRCS += $(LELYCANOPEN_SRCDIR)/src/util/lex.c -CSRCS += $(LELYCANOPEN_SRCDIR)/src/util/membuf.c -CSRCS += $(LELYCANOPEN_SRCDIR)/src/util/pheap.c -CSRCS += $(LELYCANOPEN_SRCDIR)/src/util/print.c -CSRCS += $(LELYCANOPEN_SRCDIR)/src/util/rbtree.c -CSRCS += $(LELYCANOPEN_SRCDIR)/src/util/stop.c -CSRCS += $(LELYCANOPEN_SRCDIR)/src/util/time.c -CSRCS += $(LELYCANOPEN_SRCDIR)/src/util/ustring.c - -# Lely IO lib - -ifeq ($(CONFIG_CANUTILS_LELYCANOPEN_IOLIB),y) -CSRCS += $(LELYCANOPEN_SRCDIR)/src/io/handle.c -CSRCS += $(LELYCANOPEN_SRCDIR)/src/io/io.c -CSRCS += $(LELYCANOPEN_SRCDIR)/src/io/pipe.c -CSRCS += $(LELYCANOPEN_SRCDIR)/src/io/poll.c -CSRCS += $(LELYCANOPEN_SRCDIR)/src/io2/posix/poll.c -CSRCS += $(LELYCANOPEN_SRCDIR)/src/io2/ctx.c -CSRCS += $(LELYCANOPEN_SRCDIR)/src/io/can.c -CSRCS += $(LELYCANOPEN_SRCDIR)/src/can/socket.c -endif - -# enable config.h - -CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/include/canutils/lely -CFLAGS += -DHAVE_CONFIG_H=1 - -CFLAGS += -Wno-shadow -Wno-undef - -MODULE = $(CONFIG_CANUTILS_LELYCANOPEN) - -# Lely CANopen tools - -ifeq ($(CONFIG_CANUTILS_LELYCANOPEN_TOOLS_COCTL),y) -PROGNAME = coctl -PRIORITY = $(CONFIG_CANUTILS_LELYCANOPEN_TOOLS_COCTL_PRIORITY) -STACKSIZE = $(CONFIG_CANUTILS_LELYCANOPEN_TOOLS_COCTL_STACKSIZE) -MAINSRC = $(LELYCANOPEN_SRCDIR)/tools/coctl.c -endif - -# Download, unpack and patch the Lely CANopen sources. - -ifeq ($(wildcard $(LELYCANOPEN_SRCNAME)/.git),) - -$(LELYCANOPEN_TARBALL): - @echo "Downloading: $(LELYCANOPEN_TARBALL)" - $(Q) curl -fL -o $@.tmp $(CONFIG_CANUTILS_LELYCANOPEN_URL)/$(LELYCANOPEN_TARBALL) - $(Q) mv $@.tmp $@ - -$(LELYCANOPEN_SRCNAME)/.patched: $(LELYCANOPEN_TARBALL) $(LELYCANOPEN_PATCHES) - @echo "Unpacking: $(LELYCANOPEN_TARBALL) -> $(LELYCANOPEN_SRCNAME)" - $(Q) rm -rf $(LELYCANOPEN_SRCNAME) $(LELYCANOPEN_UNPACKGLOB) - $(Q) $(UNPACK) $(LELYCANOPEN_TARBALL) - $(Q) mv $(LELYCANOPEN_UNPACKGLOB) $(LELYCANOPEN_SRCNAME) - $(Q) for patch in $(LELYCANOPEN_PATCHES); do \ - echo "Patching: $$patch"; \ - patch -s -N -p1 -d $(LELYCANOPEN_SRCNAME) < $$patch || exit 1; \ - done - $(Q) touch $@ - -context:: $(LELYCANOPEN_SRCNAME)/.patched - -distclean:: - $(Q) rm -rf $(LELYCANOPEN_SRCNAME) $(LELYCANOPEN_UNPACKGLOB) - $(call DELFILE, $(LELYCANOPEN_TARBALL)) - -else -context:: $(LELYCANOPEN_SRCNAME) -endif - -include $(APPDIR)/Application.mk diff --git a/canutils/libcanard/.gitignore b/canutils/libcanard/.gitignore new file mode 100644 index 000000000..ab82ca37f --- /dev/null +++ b/canutils/libcanard/.gitignore @@ -0,0 +1 @@ +/libcanard-* diff --git a/canutils/libcanard/Kconfig b/canutils/libcanard/Kconfig new file mode 100644 index 000000000..dfb760752 --- /dev/null +++ b/canutils/libcanard/Kconfig @@ -0,0 +1,27 @@ +# +# For a description of the syntax of this configuration file, +# see the file kconfig-language.txt in the NuttX tools repository. +# + +config CANUTILS_LIBCANARD + bool "libcanard UAVCAN Library" + default n + depends on CAN && CAN_EXTID + ---help--- + Enable the libcanard UAVCAN library. + +if CANUTILS_LIBCANARD + +config LIBCANARD_URL + string "libcanard URL" + default "https://github.com/UAVCAN/libcanard/archive" + ---help--- + libcanard URL. + +config LIBCANARD_VERSION + string "libcanard Version" + default "5ad65c6a4efda60cda7a8f0512da0f465822bbb8" + ---help--- + libcanard version. + +endif diff --git a/fsutils/flashtool/Make.defs b/canutils/libcanard/Make.defs similarity index 88% rename from fsutils/flashtool/Make.defs rename to canutils/libcanard/Make.defs index 55f2c72c9..433b07b58 100644 --- a/fsutils/flashtool/Make.defs +++ b/canutils/libcanard/Make.defs @@ -1,5 +1,5 @@ ############################################################################ -# apps/fsutils/flashtool/Make.defs +# apps/canutils/libcanard/Make.defs # # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with @@ -18,7 +18,6 @@ # ############################################################################ -ifneq ($(CONFIG_FSUTILS_FLASHTOOL),) -CONFIGURED_APPS += $(APPDIR)/fsutils/flashtool +ifeq ($(CONFIG_CANUTILS_LIBCANARD),y) +CONFIGURED_APPS += $(APPDIR)/canutils/libcanard endif - diff --git a/canutils/libcanard/Makefile b/canutils/libcanard/Makefile new file mode 100644 index 000000000..a89ed738a --- /dev/null +++ b/canutils/libcanard/Makefile @@ -0,0 +1,71 @@ +############################################################################ +# apps/canutils/libcanard/Makefile +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. The +# ASF licenses this file to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance with the +# License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +############################################################################ + +include $(APPDIR)/Make.defs + +UNPACK = unzip +PACKEXT = .zip + +LIBCANARD_URL = $(patsubst "%",%,$(strip $(CONFIG_LIBCANARD_URL))) +LIBCANARD_VERSION = $(patsubst "%",%,$(strip $(CONFIG_LIBCANARD_VERSION))) +LIBCANARD_UNPACKNAME = libcanard-$(LIBCANARD_VERSION) +LIBCANARD_PACKNAME = $(LIBCANARD_UNPACKNAME)$(PACKEXT) +LIBCANARD_SRCDIR = $(LIBCANARD_UNPACKNAME) +LIBCANARD_DRVDIR = $(LIBCANARD_SRCDIR)$(DELIM)drivers$(DELIM)nuttx + +APPS_INCDIR = $(APPDIR)$(DELIM)include$(DELIM)canutils + +CFLAGS += -std=c99 -DCANARD_ASSERT=DEBUGASSERT +CFLAGS += ${shell $(INCDIR) "$(CC)" $(APPS_INCDIR)} + +CSRCS = $(LIBCANARD_SRCDIR)$(DELIM)canard.c $(LIBCANARD_DRVDIR)$(DELIM)canard_nuttx.c + +$(LIBCANARD_PACKNAME): + @echo "Downloading: $@" + $(Q) curl -o $@ -L $(LIBCANARD_URL)$(DELIM)$(LIBCANARD_VERSION)$(PACKEXT) + +$(LIBCANARD_UNPACKNAME): $(LIBCANARD_PACKNAME) + @echo "Unpacking: $< -> $@" + $(call DELDIR, $@) + $(Q) $(UNPACK) $< + $(Q) touch $@ + +$(LIBCANARD_SRCDIR)$(DELIM)canard.h: $(LIBCANARD_UNPACKNAME) + +$(LIBCANARD_DRVDIR)$(DELIM)canard_nuttx.h: $(LIBCANARD_UNPACKNAME) + +$(APPS_INCDIR)$(DELIM)canard.h: $(LIBCANARD_SRCDIR)$(DELIM)canard.h + $(Q) cp $< $@ + +$(APPS_INCDIR)$(DELIM)canard_nuttx.h: $(LIBCANARD_DRVDIR)$(DELIM)canard_nuttx.h + $(Q) cp $< $@ + +context:: $(APPS_INCDIR)$(DELIM)canard.h $(APPS_INCDIR)$(DELIM)canard_nuttx.h + +clean:: + $(foreach OBJ, $(OBJS), $(call DELFILE, $(OBJ))) + +distclean:: + $(call DELFILE, $(APPS_INCDIR)$(DELIM)canard.h) + $(call DELFILE, $(APPS_INCDIR)$(DELIM)canard_nuttx.h) + $(call DELDIR, $(LIBCANARD_UNPACKNAME)) + $(call DELFILE, $(LIBCANARD_PACKNAME)) + +include $(APPDIR)/Application.mk diff --git a/canutils/libcanutils/CMakeLists.txt b/canutils/libcanutils/CMakeLists.txt deleted file mode 100644 index 1ceb042e5..000000000 --- a/canutils/libcanutils/CMakeLists.txt +++ /dev/null @@ -1,27 +0,0 @@ -# ############################################################################## -# apps/canutils/libcanutils/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_CANUTILS_LIBCANUTILS) - - target_sources(apps PRIVATE lib.c) - -endif() diff --git a/canutils/libcanutils/Kconfig b/canutils/libcanutils/Kconfig index 43dae4a00..fad8fcd1b 100644 --- a/canutils/libcanutils/Kconfig +++ b/canutils/libcanutils/Kconfig @@ -6,7 +6,7 @@ config CANUTILS_LIBCANUTILS bool "CAN-utils support library" default n - depends on NET_CAN && ALLOW_BSD_COMPONENTS + depends on NET_CAN && ALLOW_GPL_COMPONENTS ---help--- Enable the CAN-utils support library ported from https://github.com/linux-can/can-utils diff --git a/canutils/libcanutils/Make.defs b/canutils/libcanutils/Make.defs index 4c40e4cdf..7f6c7bca0 100644 --- a/canutils/libcanutils/Make.defs +++ b/canutils/libcanutils/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/canutils/libcanutils/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -20,6 +18,6 @@ # ############################################################################/ -ifneq ($(CONFIG_CANUTILS_LIBCANUTILS),) +ifeq ($(CONFIG_CANUTILS_LIBCANUTILS),y) CONFIGURED_APPS += $(APPDIR)/canutils/libcanutils endif diff --git a/canutils/libcanutils/Makefile b/canutils/libcanutils/Makefile index d7eb68785..cb790c853 100644 --- a/canutils/libcanutils/Makefile +++ b/canutils/libcanutils/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/canutils/libcanutils/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/canutils/libcanutils/lib.c b/canutils/libcanutils/lib.c index 749761d61..f12cfc3f7 100644 --- a/canutils/libcanutils/lib.c +++ b/canutils/libcanutils/lib.c @@ -1,7 +1,9 @@ -/**************************************************************************** +/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) */ +/* + * lib.c - library for command line tools * - * SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) - * SPDX-FileCopyrightText: 2002-2007 Volkswagen Group Electronic Research + * Copyright (c) 2002-2007 Volkswagen Group Electronic Research + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -38,15 +40,15 @@ * * Send feedback to <linux-can@vger.kernel.org> * - ****************************************************************************/ + */ #include <stdio.h> #include <string.h> #include <stdint.h> -#include <sys/param.h> #include <sys/socket.h> /* for sa_family_t */ #include <nuttx/can.h> +#include <netpacket/can.h> #include "lib.h" @@ -494,6 +496,10 @@ static const char *protocol_violation_locations[] = { "unspecified", }; +#ifndef ARRAY_SIZE +#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) +#endif + static int snprintf_error_data(char *buf, size_t len, uint8_t err, const char **arr, int arr_len) { @@ -531,7 +537,7 @@ static int snprintf_error_ctrl(char *buf, size_t len, const struct canfd_frame * n += snprintf(buf + n, len - n, "{"); n += snprintf_error_data(buf + n, len - n, cf->data[1], controller_problems, - nitems(controller_problems)); + ARRAY_SIZE(controller_problems)); n += snprintf(buf + n, len - n, "}"); return n; @@ -547,10 +553,10 @@ static int snprintf_error_prot(char *buf, size_t len, const struct canfd_frame * n += snprintf(buf + n, len - n, "{{"); n += snprintf_error_data(buf + n, len - n, cf->data[2], protocol_violation_types, - nitems(protocol_violation_types)); + ARRAY_SIZE(protocol_violation_types)); n += snprintf(buf + n, len - n, "}{"); if (cf->data[3] > 0 && - cf->data[3] < nitems(protocol_violation_locations)) + cf->data[3] < ARRAY_SIZE(protocol_violation_locations)) n += snprintf(buf + n, len - n, "%s", protocol_violation_locations[cf->data[3]]); n += snprintf(buf + n, len - n, "}}"); @@ -569,7 +575,7 @@ void snprintf_can_error_frame(char *buf, size_t len, const struct canfd_frame *c return; class = cf->can_id & CAN_EFF_MASK; - if (class > (1 << nitems(error_classes))) { + if (class > (1 << ARRAY_SIZE(error_classes))) { fprintf(stderr, "Error class %#jx is invalid\n", (uintmax_t)class); return; } @@ -577,7 +583,7 @@ void snprintf_can_error_frame(char *buf, size_t len, const struct canfd_frame *c if (!sep) sep = defsep; - for (i = 0; i < (int)nitems(error_classes); i++) { + for (i = 0; i < (int)ARRAY_SIZE(error_classes); i++) { mask = 1 << i; if (class & mask) { if (classes) diff --git a/canutils/libcanutils/lib.h b/canutils/libcanutils/lib.h index ebabb6a4d..97db405df 100644 --- a/canutils/libcanutils/lib.h +++ b/canutils/libcanutils/lib.h @@ -1,7 +1,9 @@ -/**************************************************************************** +/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) */ +/* + * lib.h - library include for command line tools * - * SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) - * SPDX-FileCopyrightText: 2002-2007 Volkswagen Group Electronic Research + * Copyright (c) 2002-2007 Volkswagen Group Electronic Research + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -38,7 +40,7 @@ * * Send feedback to <linux-can@vger.kernel.org> * - ****************************************************************************/ + */ #ifndef CAN_UTILS_LIB_H #define CAN_UTILS_LIB_H diff --git a/canutils/libcanutils/terminal.h b/canutils/libcanutils/terminal.h index 1b25e9ad3..198b48ec0 100644 --- a/canutils/libcanutils/terminal.h +++ b/canutils/libcanutils/terminal.h @@ -1,7 +1,7 @@ -/**************************************************************************** - * - * SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) - * SPDX-FileCopyrightText: 2002-2007 Volkswagen Group Electronic Research +/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) */ +/* + * Copyright (c) 2002-2007 Volkswagen Group Electronic Research + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -38,7 +38,7 @@ * * Send feedback to <linux-can@vger.kernel.org> * - ****************************************************************************/ + */ #ifndef TERMINAL_H #define TERMINAL_H diff --git a/canutils/libdronecan/.gitignore b/canutils/libdronecan/.gitignore deleted file mode 100644 index 03f1063a6..000000000 --- a/canutils/libdronecan/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/libcanard -/*.zip diff --git a/canutils/libdronecan/CMakeLists.txt b/canutils/libdronecan/CMakeLists.txt deleted file mode 100644 index c8f7af9b2..000000000 --- a/canutils/libdronecan/CMakeLists.txt +++ /dev/null @@ -1,95 +0,0 @@ -# ############################################################################## -# apps/canutils/libdronecan/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_CANUTILS_LIBDRONECAN) - - # ############################################################################ - # Config and Fetch libdronecan lib - # ############################################################################ - - set(LIBDRONECAN_DIR ${CMAKE_CURRENT_LIST_DIR}/libcanard) - - if(NOT EXISTS ${LIBDRONECAN_DIR}) - FetchContent_Declare( - libdronecan_fetch - URL ${CONFIG_LIBDRONECAN_URL}/${CONFIG_LIBDRONECAN_VERSION}.zip SOURCE_DIR - ${CMAKE_CURRENT_LIST_DIR}/libcanard BINARY_DIR - ${CMAKE_BINARY_DIR}/apps/canutils/libdronecan/libcanard - DOWNLOAD_NO_PROGRESS true - TIMEOUT 30) - - FetchContent_GetProperties(libdronecan_fetch) - - if(NOT libdronecan_fetch_POPULATED) - FetchContent_Populate(libdronecan_fetch) - endif() - endif() - - # ############################################################################ - # Flags - # ############################################################################ - - set(CFLAGS -std=c99 -DCANARD_ASSERT=DEBUGASSERT) - - # Conflict with Cyphal's libcanard - if(CONFIG_CANUTILS_LIBOPENCYPHAL) - list(APPEND CFLAGS -DcanardInit=dronecanardInit) - endif() - - if(CONFIG_LIBDRONECAN_CANFD) - list(APPEND CFLAGS -DCANARD_ENABLE_CANFD=1) - endif() - - # ############################################################################ - # Sources - # ############################################################################ - - set(CSRCS ${LIBDRONECAN_DIR}/canard.c) - - if(CONFIG_NET_CAN) - list(APPEND CSRCS ${LIBDRONECAN_DIR}/drivers/socketcan/socketcan.c) - else() - list(APPEND CSRCS ${LIBDRONECAN_DIR}/drivers/nuttx/canard_nuttx.c) - endif() - - # ############################################################################ - # Include Directory - # ############################################################################ - - set(INCDIR ${NUTTX_APPS_DIR}/canutils/libdronecan/libcanard) - - if(CONFIG_NET_CAN) - list(APPEND INCDIR - ${NUTTX_APPS_DIR}/canutils/libdronecan/libcanard/drivers/socketcan) - endif() - - # ############################################################################ - # Library Configuration - # ############################################################################ - - nuttx_add_user_library(libdronecan) - - target_sources(libdronecan PRIVATE ${CSRCS}) - target_compile_options(libdronecan PRIVATE ${CFLAGS}) - target_include_directories(libdronecan PRIVATE ${INCDIR}) - -endif() diff --git a/canutils/libdronecan/Kconfig b/canutils/libdronecan/Kconfig deleted file mode 100644 index 11578b939..000000000 --- a/canutils/libdronecan/Kconfig +++ /dev/null @@ -1,37 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config CANUTILS_LIBDRONECAN - bool "libcanard DroneCAN Library" - default n - depends on (CAN && CAN_EXTID) || NET_CAN - ---help--- - Enable the libcanard DroneCAN library. - -if CANUTILS_LIBDRONECAN - -config LIBDRONECAN_URL - string "libcanard URL" - default "https://github.com/dronecan/libcanard/archive" - ---help--- - libcanard URL. - -config LIBDRONECAN_VERSION - string "libcanard Version" - default "21f2a73df86886101e254d02cfc2277cd2a15717" - ---help--- - libcanard version. - -config LIBDRONECAN_CANFD - bool "(Experimental) libcanard CAN FD Support" - default n - depends on NET_CAN_CANFD && EXPERIMENTAL - ---help--- - libcanard CAN FD support. - Adds support for CAN FD, this is still experimental - since libcanard doesn't support runtime switching - between CAN2.0B and CAN FD that well - -endif # CANUTILS_LIBDRONECAN diff --git a/canutils/libdronecan/Make.defs b/canutils/libdronecan/Make.defs deleted file mode 100644 index 1a694e878..000000000 --- a/canutils/libdronecan/Make.defs +++ /dev/null @@ -1,31 +0,0 @@ -############################################################################ -# apps/canutils/libdronecan/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_CANUTILS_LIBDRONECAN),) -CONFIGURED_APPS += $(APPDIR)/canutils/libdronecan - -ifeq ($(CONFIG_NET_CAN),y) -CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/canutils/libdronecan/libcanard/drivers/socketcan -CXXFLAGS += ${INCDIR_PREFIX}$(APPDIR)/canutils/libdronecan/libcanard/drivers/socketcan -endif - -endif diff --git a/canutils/libdronecan/Makefile b/canutils/libdronecan/Makefile deleted file mode 100644 index 0ad1d2dd4..000000000 --- a/canutils/libdronecan/Makefile +++ /dev/null @@ -1,85 +0,0 @@ -############################################################################ -# apps/canutils/libdronecan/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -WD := ${shell echo $(CURDIR) | sed -e 's/ /\\ /g'} - -UNPACK = unzip -PACKEXT = .zip - -LIBDRONECAN_URL = $(patsubst "%",%,$(strip $(CONFIG_LIBDRONECAN_URL))) -LIBDRONECAN_VERSION = $(patsubst "%",%,$(strip $(CONFIG_LIBDRONECAN_VERSION))) - -LIBDRONECAN_PACKNAME = $(LIBDRONECAN_UNPACKNAME)$(PACKEXT) -LIBDRONECAN_UNPACKNAME = libcanard-$(LIBDRONECAN_VERSION) -LIBDRONECAN_SRCNAME = libcanard - -LIBDRONECAN_SRCDIR = $(WD)/$(LIBDRONECAN_SRCNAME) -LIBDRONECAN_DRVDIR = $(LIBDRONECAN_SRCDIR)$(DELIM)drivers$(DELIM)nuttx -LIBDRONECAN_SOCKETCANDIR = $(LIBDRONECAN_SRCDIR)$(DELIM)drivers$(DELIM)socketcan - -# Conflict with Cyphal's libcanard -ifeq ($(CONFIG_CANUTILS_LIBOPENCYPHAL),y) -CFLAGS += -DcanardInit=dronecanardInit -endif - -CFLAGS += -std=c99 -DCANARD_ASSERT=DEBUGASSERT -CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/canutils/libdronecan/libcanard - -ifeq ($(CONFIG_LIBDRONECAN_CANFD),y) -CFLAGS += -DCANARD_ENABLE_CANFD=1 -endif - -CSRCS = $(LIBDRONECAN_SRCDIR)$(DELIM)canard.c - -ifeq ($(CONFIG_NET_CAN),y) -CSRCS += $(LIBDRONECAN_SOCKETCANDIR)$(DELIM)socketcan.c -else -CSRCS += $(LIBDRONECAN_DRVDIR)$(DELIM)canard_nuttx.c -endif - -# Download and unpack tarball if no git repo found -ifeq ($(wildcard $(LIBDRONECAN_SRCNAME)/.git),) -$(LIBDRONECAN_PACKNAME): - @echo "Downloading: $@" - $(Q) curl -o $@ -L $(LIBDRONECAN_URL)$(DELIM)$(LIBDRONECAN_VERSION)$(PACKEXT) - -$(LIBDRONECAN_SRCNAME): $(LIBDRONECAN_PACKNAME) - @echo "Unpacking: $< -> $@" - $(call DELDIR, $@) - $(Q) $(UNPACK) $< - $(Q) mv $(LIBDRONECAN_UNPACKNAME) $(LIBDRONECAN_SRCNAME) - $(Q) touch $@ - -$(LIBDRONECAN_SRCDIR)$(DELIM)canard.c: $(LIBDRONECAN_SRCNAME) -endif - -context:: $(LIBDRONECAN_SRCNAME) - -distclean:: -ifeq ($(wildcard $(LIBDRONECAN_SRCNAME)/.git),) - $(call DELDIR, $(LIBDRONECAN_SRCNAME)) - $(call DELFILE, $(LIBDRONECAN_PACKNAME)) -endif - -include $(APPDIR)/Application.mk diff --git a/canutils/libobd2/CMakeLists.txt b/canutils/libobd2/CMakeLists.txt deleted file mode 100644 index f0dd56497..000000000 --- a/canutils/libobd2/CMakeLists.txt +++ /dev/null @@ -1,28 +0,0 @@ -# ############################################################################## -# apps/canutils/libobd2/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_CANUTILS_LIBOBD2) - - target_sources(apps PRIVATE obd2.c obd_sendrequest.c obd_waitresponse.c - obd_decodepid.c) - -endif() diff --git a/canutils/libobd2/Make.defs b/canutils/libobd2/Make.defs index 9e619d04d..1d0125da5 100644 --- a/canutils/libobd2/Make.defs +++ b/canutils/libobd2/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/canutils/libobd2/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -20,6 +18,6 @@ # ############################################################################ -ifneq ($(CONFIG_CANUTILS_LIBOBD2),) +ifeq ($(CONFIG_CANUTILS_LIBOBD2),y) CONFIGURED_APPS += $(APPDIR)/canutils/libobd2 endif diff --git a/canutils/libobd2/Makefile b/canutils/libobd2/Makefile index 2a1daebb0..495f1c069 100644 --- a/canutils/libobd2/Makefile +++ b/canutils/libobd2/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/canutils/libobd2/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/canutils/libobd2/obd2.c b/canutils/libobd2/obd2.c index 723b2f37c..fcf007b2a 100644 --- a/canutils/libobd2/obd2.c +++ b/canutils/libobd2/obd2.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/canutils/libobd2/obd2.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/canutils/libobd2/obd_decodepid.c b/canutils/libobd2/obd_decodepid.c index 0198d09bb..3a3439a74 100644 --- a/canutils/libobd2/obd_decodepid.c +++ b/canutils/libobd2/obd_decodepid.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/canutils/libobd2/obd_decodepid.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/canutils/libobd2/obd_sendrequest.c b/canutils/libobd2/obd_sendrequest.c index 3dc7243bd..370d93a9a 100644 --- a/canutils/libobd2/obd_sendrequest.c +++ b/canutils/libobd2/obd_sendrequest.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/canutils/libobd2/obd_sendrequest.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -32,8 +30,6 @@ #include <stdlib.h> #include <fcntl.h> #include <errno.h> -#include <unistd.h> - #include <nuttx/can/can.h> #include "canutils/obd.h" @@ -98,7 +94,7 @@ int obd_send_request(FAR struct obd_dev_s *dev, uint8_t opmode, uint8_t pid) #ifdef CONFIG_CAN_EXTID dev->can_txmsg.cm_hdr.ch_extid = extended; /* Standard/Extend mode */ #endif - dev->can_txmsg.cm_hdr.ch_tcf = 0; /* Unused */ + dev->can_txmsg.cm_hdr.ch_unused = 0; /* Unused */ /* Single Frame with two bytes data */ diff --git a/canutils/libobd2/obd_waitresponse.c b/canutils/libobd2/obd_waitresponse.c index 12c8a13e0..6319c5f72 100644 --- a/canutils/libobd2/obd_waitresponse.c +++ b/canutils/libobd2/obd_waitresponse.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/canutils/libobd2/obd_waitresponse.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -33,8 +31,6 @@ #include <string.h> #include <fcntl.h> #include <errno.h> -#include <unistd.h> - #include <nuttx/can/can.h> #include "canutils/obd.h" @@ -52,8 +48,8 @@ * Wait for a message from ECUs with requested PID that was sent using * obd_send_request(). * - * It will return an error case it doesn't receive the msg after the - * elapsed "timeout" time. + * It will return an error case it doesn't receive the msg after the elapsed + * "timeout" time. * ****************************************************************************/ @@ -94,10 +90,10 @@ int obd_wait_response(FAR struct obd_dev_s *dev, uint8_t opmode, uint8_t pid, return -EAGAIN; } -#ifdef CONFIG_DEBUG_INFO + #ifdef CONFIG_DEBUG_INFO printf(" ID: %4u DLC: %u\n", dev->can_rxmsg.cm_hdr.ch_id, dev->can_rxmsg.cm_hdr.ch_dlc); -#endif + #endif msgdlc = dev->can_rxmsg.cm_hdr.ch_dlc; @@ -113,10 +109,10 @@ int obd_wait_response(FAR struct obd_dev_s *dev, uint8_t opmode, uint8_t pid, /* Check if we received a Response Message */ - if ((extended && - dev->can_rxmsg.cm_hdr.ch_id == OBD_PID_EXT_RESPONSE) || + if ((extended && dev->can_rxmsg.cm_hdr.ch_id == OBD_PID_EXT_RESPONSE) || \ (!extended && dev->can_rxmsg.cm_hdr.ch_id == OBD_PID_STD_RESPONSE)) { + /* Check if the Response if for the PID we are interested! */ if (dev->can_rxmsg.cm_data[1] == (opmode + OBD_RESP_BASE) && \ diff --git a/canutils/libopencyphal/.gitignore b/canutils/libopencyphal/.gitignore deleted file mode 100644 index aeac8afe8..000000000 --- a/canutils/libopencyphal/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -/libcanard -/o1heap -/*.zip diff --git a/canutils/libopencyphal/CMakeLists.txt b/canutils/libopencyphal/CMakeLists.txt deleted file mode 100644 index 3f0efee73..000000000 --- a/canutils/libopencyphal/CMakeLists.txt +++ /dev/null @@ -1,75 +0,0 @@ -# ############################################################################## -# apps/canutils/libopencyphal/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_CANUTILS_LIBOPENCYPHAL) - - # ############################################################################ - # Config and Fetch libopencyphal o1heap lib - # ############################################################################ - - set(LIBOPENCYPHAL_DIR ${CMAKE_CURRENT_LIST_DIR}/libcanard) - if(NOT EXISTS ${LIBOPENCYPHAL_DIR}) - FetchContent_Declare( - libcanard_fetch - URL ${CONFIG_LIBOPENCYPHAL_URL}/${CONFIG_LIBOPENCYPHAL_VERSION}.zip - SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/libcanard BINARY_DIR - ${CMAKE_BINARY_DIR}/apps/canutils/libopencyphal/libcanard - DOWNLOAD_NO_PROGRESS true - TIMEOUT 30) - FetchContent_GetProperties(libcanard_fetch) - if(NOT libcanard_fetch_POPULATED) - FetchContent_Populate(libcanard_fetch) - endif() - endif() - - set(O1HEAP_DIR ${CMAKE_CURRENT_LIST_DIR}/o1heap) - if(NOT EXISTS ${O1HEAP_DIR}) - FetchContent_Declare( - o1heap_fetch - URL ${CONFIG_O1HEAP_URL}/${CONFIG_O1HEAP_VERSION}.zip SOURCE_DIR - ${CMAKE_CURRENT_LIST_DIR}/o1heap BINARY_DIR - ${CMAKE_BINARY_DIR}/apps/canutils/libopencyphal/o1heap - DOWNLOAD_NO_PROGRESS true - TIMEOUT 30) - FetchContent_GetProperties(o1heap_fetch) - if(NOT o1heap_fetch_POPULATED) - FetchContent_Populate(o1heap_fetch) - endif() - endif() - - # ############################################################################ - # Library Configuration - # ############################################################################ - - nuttx_add_user_library(libopencyphal) - - target_sources( - libopencyphal - PRIVATE ${LIBOPENCYPHAL_DIR}/libcanard/canard.c - ${LIBOPENCYPHAL_DIR}/libcanard/canard_dsdl.c - ${O1HEAP_DIR}/o1heap/o1heap.c) - target_compile_options( - libopencyphal PRIVATE -std=c11 -DCANARD_ASSERT=DEBUGASSERT - -DCANARD_DSDL_CONFIG_LITTLE_ENDIAN=1) - target_include_directories(libopencyphal PRIVATE ${O1HEAP_DIR}/o1heap) - -endif() diff --git a/canutils/libopencyphal/Kconfig b/canutils/libopencyphal/Kconfig deleted file mode 100644 index 77c9a875c..000000000 --- a/canutils/libopencyphal/Kconfig +++ /dev/null @@ -1,39 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config CANUTILS_LIBOPENCYPHAL - bool "libcanard OpenCyphal Cyphal/CAN Library" - default n - depends on NET_CAN && ALLOW_MIT_COMPONENTS - ---help--- - Enable the OpenCyphal Cyphal/CAN library. - -if CANUTILS_LIBOPENCYPHAL - -config LIBOPENCYPHAL_URL - string "libcanard URL" - default "https://github.com/OpenCyphal/libcanard/archive" - ---help--- - libcanard URL. - -config LIBOPENCYPHAL_VERSION - string "libcanard Version" - default "cde670347425023480a1417fcd603b27c8eb06c1" - ---help--- - libcanard version. - -config O1HEAP_URL - string "O(1) heap URL" - default "https://github.com/pavel-kirienko/o1heap/archive" - ---help--- - O(1) heap allocator URL. - -config O1HEAP_VERSION - string "O(1) heap Version" - default "b21b069e4b971d3016dd232784faca6f7d9fd724" - ---help--- - O(1) heap allocator version. - -endif diff --git a/canutils/libopencyphal/Make.defs b/canutils/libopencyphal/Make.defs deleted file mode 100644 index 483bfbcab..000000000 --- a/canutils/libopencyphal/Make.defs +++ /dev/null @@ -1,29 +0,0 @@ -############################################################################ -# apps/canutils/libopencyphal/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_CANUTILS_LIBOPENCYPHAL),) -CONFIGURED_APPS += $(APPDIR)/canutils/libopencyphal - -CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/canutils/libopencyphal/o1heap/o1heap -CXXFLAGS += ${INCDIR_PREFIX}$(APPDIR)/canutils/libopencyphal/o1heap/o1heap - -endif diff --git a/canutils/libopencyphal/Makefile b/canutils/libopencyphal/Makefile deleted file mode 100644 index 52f4e90c3..000000000 --- a/canutils/libopencyphal/Makefile +++ /dev/null @@ -1,93 +0,0 @@ -############################################################################ -# apps/canutils/libopencyphal/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -WD := ${shell echo $(CURDIR) | sed -e 's/ /\\ /g'} - -UNPACK = unzip -PACKEXT = .zip - -LIBOPENCYPHAL_URL = $(patsubst "%",%,$(strip $(CONFIG_LIBOPENCYPHAL_URL))) -LIBOPENCYPHAL_VERSION = $(patsubst "%",%,$(strip $(CONFIG_LIBOPENCYPHAL_VERSION))) - -LIBOPENCYPHAL_PACKNAME = $(LIBOPENCYPHAL_UNPACKNAME)$(PACKEXT) -LIBOPENCYPHAL_UNPACKNAME = libcanard-$(LIBOPENCYPHAL_VERSION) -LIBOPENCYPHAL_SRCNAME = libcanard - -LIBOPENCYPHAL_SRCDIR = $(WD)/$(LIBOPENCYPHAL_SRCNAME) -LIBOPENCYPHAL_DRVDIR = $(LIBOPENCYPHAL_SRCDIR)$(DELIM)libcanard - -O1HEAP_URL = $(patsubst "%",%,$(strip $(CONFIG_O1HEAP_URL))) -O1HEAP_VERSION = $(patsubst "%",%,$(strip $(CONFIG_O1HEAP_VERSION))) - -O1HEAP_PACKNAME = $(O1HEAP_UNPACKNAME)$(PACKEXT) -O1HEAP_UNPACKNAME = o1heap-$(O1HEAP_VERSION) -O1HEAP_SRCNAME = o1heap - -O1HEAP_SRCDIR = $(WD)/$(O1HEAP_SRCNAME) -O1HEAP_DRVDIR = $(O1HEAP_SRCDIR)$(DELIM)o1heap - -CFLAGS += -std=c11 -DCANARD_ASSERT=DEBUGASSERT -DCANARD_DSDL_CONFIG_LITTLE_ENDIAN=1 - -CSRCS = $(LIBOPENCYPHAL_DRVDIR)$(DELIM)canard.c $(LIBOPENCYPHAL_DRVDIR)$(DELIM)canard_dsdl.c -CSRCS += $(O1HEAP_DRVDIR)$(DELIM)o1heap.c - -ifeq ($(wildcard $(LIBOPENCYPHAL_SRCNAME)/.git),) -$(LIBOPENCYPHAL_PACKNAME): - @echo "Downloading: $@" - $(Q) curl -o $@ -L $(LIBOPENCYPHAL_URL)$(DELIM)$(LIBOPENCYPHAL_VERSION)$(PACKEXT) - -$(LIBOPENCYPHAL_SRCNAME): $(LIBOPENCYPHAL_PACKNAME) - @echo "Unpacking: $< -> $@" - $(call DELDIR, $@) - $(Q) $(UNPACK) $< - $(Q) mv $(LIBOPENCYPHAL_UNPACKNAME) $(LIBOPENCYPHAL_SRCNAME) - $(Q) touch $@ - -$(LIBOPENCYPHAL_DRVDIR)$(DELIM)canard.c: $(LIBOPENCYPHAL_SRCNAME) -endif - -ifeq ($(wildcard $(O1HEAP_SRCNAME)/.git),) -$(O1HEAP_PACKNAME): - @echo "Downloading: $@" - $(Q) curl -o $@ -L $(O1HEAP_URL)$(DELIM)$(O1HEAP_VERSION)$(PACKEXT) - -$(O1HEAP_SRCNAME): $(O1HEAP_PACKNAME) - @echo "Unpacking: $< -> $@" - $(call DELDIR, $@) - $(Q) $(UNPACK) $< - $(Q) mv $(O1HEAP_UNPACKNAME) $(O1HEAP_SRCNAME) - $(Q) touch $@ - -$(O1HEAP_DRVDIR)$(DELIM)o1heap.c: $(O1HEAP_SRCNAME) -endif - -context:: $(LIBOPENCYPHAL_SRCNAME) $(O1HEAP_SRCNAME) - -distclean:: - $(call DELDIR, $(LIBOPENCYPHAL_SRCNAME)) - $(call DELFILE, $(LIBOPENCYPHAL_PACKNAME)) - $(call DELDIR, $(O1HEAP_SRCNAME)) - $(call DELFILE, $(O1HEAP_PACKNAME)) - -include $(APPDIR)/Application.mk diff --git a/canutils/slcan/CMakeLists.txt b/canutils/slcan/CMakeLists.txt deleted file mode 100644 index 5feb5c28d..000000000 --- a/canutils/slcan/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# ############################################################################## -# apps/canutils/slcan/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_CANUTILS_SLCAN) - - nuttx_add_application( - NAME - slcan - STACKSIZE - ${CONFIG_CANUTILS_SLCAN_STACKSIZE} - MODULE - ${CONFIG_CANUTILS_SLCAN} - SRCS - slcan.c) - -endif() diff --git a/canutils/slcan/Make.defs b/canutils/slcan/Make.defs index 4f5ec3b6a..dd6f6db53 100644 --- a/canutils/slcan/Make.defs +++ b/canutils/slcan/Make.defs @@ -1,7 +1,6 @@ ############################################################################ # apps/canutils/slcan/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 +# Adds selected applications to apps/ build # # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with diff --git a/canutils/slcan/Makefile b/canutils/slcan/Makefile index 5b2f12a17..5ff4ce64f 100644 --- a/canutils/slcan/Makefile +++ b/canutils/slcan/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/canutils/slcan/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/canutils/slcan/slcan.c b/canutils/slcan/slcan.c index cd7234fa2..4ebff9335 100644 --- a/canutils/slcan/slcan.c +++ b/canutils/slcan/slcan.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/canutils/slcan/slcan.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -46,8 +44,10 @@ #include <sys/socket.h> #include <syslog.h> #include <sys/uio.h> +#include <net/if.h> #include <termios.h> #include <nuttx/can.h> +#include <netpacket/can.h> #include "slcan.h" @@ -137,7 +137,8 @@ static int caninit(char *candev, int *s, struct sockaddr_can *addr, syslog(LOG_ERR, "Error opening CAN socket\n"); return -1; } - strlcpy(ifr.ifr_name, candev, IFNAMSIZ); + strncpy(ifr.ifr_name, candev, 4); + ifr.ifr_name[4] = '\0'; ifr.ifr_ifindex = if_nametoindex(ifr.ifr_name); if (!ifr.ifr_ifindex) { @@ -188,11 +189,7 @@ int main(int argc, char *argv[]) /* CAN */ - int s; - int nbytes; - int i; - int ret; - int reccount = 0; + int s, nbytes, i, ret, reccount; struct sockaddr_can addr; struct canfd_frame frame; struct msghdr msg; @@ -200,8 +197,7 @@ int main(int argc, char *argv[]) fd_set rdfs; char ctrlmsg[CMSG_SPACE(sizeof(struct timeval) + 3 * sizeof(struct timespec) + sizeof(int))]; - char sbuf[40]; - char *sbp; + char sbuf[40], *sbp; if (argc != 3) { @@ -214,7 +210,7 @@ int main(int argc, char *argv[]) char *candev = argv[1]; debug_print("Starting slcan on NuttX\n"); - fd = open(chrdev, O_RDWR); + fd = open(chrdev, O_RDWR | O_BINARY); if (fd < 0) { syslog(LOG_ERR, "Failed to open serial channel %s\n", chrdev); @@ -262,30 +258,26 @@ int main(int argc, char *argv[]) if (nbytes == CAN_MTU) { reccount++; - debug_print("R%d, Id:0x%" PRIx32 "\n", - reccount, frame.can_id); + debug_print("R%d, Id:0x%lX\n", reccount, frame.can_id); if (frame.can_id & CAN_EFF_FLAG) { /* 29 bit address */ frame.can_id = frame.can_id & ~CAN_EFF_FLAG; - snprintf(sbuf, sizeof(sbuf), "T%08" PRIx32 "%d", - frame.can_id, frame.len); + sprintf(sbuf, "T%08lX%d", frame.can_id, frame.len); sbp = &sbuf[10]; } else { /* 11 bit address */ - snprintf(sbuf, sizeof(sbuf), "t%03" PRIx32 "%d", - frame.can_id, frame.len); + sprintf(sbuf, "t%03lX%d", frame.can_id, frame.len); sbp = &sbuf[5]; } for (i = 0; i < frame.len; i++) { - snprintf(sbp, sizeof(sbuf) - (sbp - sbuf), - "%02X", frame.data[i]); + sprintf(sbp, "%02X", frame.data[i]); sbp += 2; } @@ -316,22 +308,9 @@ int main(int argc, char *argv[]) { /* open CAN interface */ - struct ifreq ifr; - - strlcpy(ifr.ifr_name, argv[1], IFNAMSIZ); - - ifr.ifr_flags = IFF_UP; - if (ioctl(s, SIOCSIFFLAGS, &ifr) < 0) - { - syslog(LOG_ERR, "Open interface failed\n"); - fail_return(fd); - } - else - { - mode = 1; - debug_print("Open interface\n"); - ok_return(fd); - } + mode = 1; + debug_print("Open interface\n"); + ok_return(fd); } else if (buf[0] == 'S') { @@ -374,8 +353,11 @@ int main(int argc, char *argv[]) /* set the device name */ - strlcpy(ifr.ifr_name, argv[1], IFNAMSIZ); - ifr.ifr_ifru.ifru_can_data.arbi_bitrate = canspeed; + strncpy(ifr.ifr_name, argv[1], IFNAMSIZ - 1); + ifr.ifr_name[IFNAMSIZ - 1] = '\0'; + + ifr.ifr_ifru.ifru_can_data.arbi_bitrate = + canspeed / 1000; /* Convert bit/s to kbit/s */ ifr.ifr_ifru.ifru_can_data.arbi_samplep = 80; if (ioctl(s, SIOCSCANBITRATE, &ifr) < 0) @@ -405,30 +387,16 @@ int main(int argc, char *argv[]) { /* close interface */ - struct ifreq ifr; - - strlcpy(ifr.ifr_name, argv[1], IFNAMSIZ); - - ifr.ifr_flags = 0; - if (ioctl(s, SIOCSIFFLAGS, &ifr) < 0) - { - syslog(LOG_ERR, "Close interface failed\n"); - fail_return(fd); - } - else - { - mode = 0; - debug_print("Close interface\n"); - ok_return(fd); - } + mode = 0; + debug_print("Close interface\n"); + ok_return(fd); } else if (buf[0] == 'T') { /* Transmit an extended 29 bit CAN frame */ char tbuf[9]; - int idval; - int val; + int idval, val; /* get 29bit CAN ID */ @@ -473,8 +441,7 @@ int main(int argc, char *argv[]) /* Transmit an 11 bit CAN frame */ char tbuf[9]; - int idval; - int val; + int idval, val; /* get 11bit CAN ID */ diff --git a/canutils/slcan/slcan.h b/canutils/slcan/slcan.h index 229069ccf..cc6bedce0 100644 --- a/canutils/slcan/slcan.h +++ b/canutils/slcan/slcan.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/canutils/slcan/slcan.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/cmake/nuttx_add_luamod.cmake b/cmake/nuttx_add_luamod.cmake deleted file mode 100644 index 93fefd628..000000000 --- a/cmake/nuttx_add_luamod.cmake +++ /dev/null @@ -1,78 +0,0 @@ -# ############################################################################## -# cmake/nuttx_add_luamod.cmake -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -set(LUAMOD_DIR ${CMAKE_BINARY_DIR}/luamod) - -if(NOT EXISTS {LUAMOD_DIR}) - file(MAKE_DIRECTORY ${LUAMOD_DIR}) -endif() - -include(nuttx_parse_function_args) - -# ~~~ -# nuttx_add_luamod -# -# Description: -# Register custom Lua MOD to Lua interpreter -# -# Example: -# nuttx_add_luamod( -# MODS -# ${custom_mods} -# -# ~~~ - -function(nuttx_add_luamod) - - # parse arguments into variables - - nuttx_parse_function_args( - FUNC - nuttx_add_luamod - MULTI_VALUE - MODS - REQUIRED - MODS - ARGN - ${ARGN}) - - set(LUAMOD_LIST ${LUAMOD_DIR}/luamod_list.h) - set(LUAMOD_PROTO ${LUAMOD_DIR}/luamod_proto.h) - foreach(mod ${MODS}) - set(MOD_PDAT ${LUAMOD_DIR}/${mod}.pdat) - set(MOD_BDAT ${LUAMOD_DIR}/${mod}.bdat) - add_custom_command( - OUTPUT ${MOD_PDAT} ${MOD_BDAT} - COMMAND ${CMAKE_COMMAND} -E echo "{\"${mod}\", luaopen_${mod}}," >> - ${LUAMOD_LIST} - COMMAND ${CMAKE_COMMAND} -E echo "int luaopen_${mod}(lua_State *L);" >> - ${LUAMOD_PROTO} - COMMAND ${CMAKE_COMMAND} -E touch ${MOD_PDAT} - COMMAND ${CMAKE_COMMAND} -E touch ${MOD_BDAT} - WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} - VERBATIM - COMMENT "Lua Mod:Gen and Updating lua mod => ${mod}") - add_custom_target(lua_${mod} DEPENDS ${MOD_PDAT} ${MOD_BDAT}) - add_dependencies(apps_context lua_${mod}) - endforeach() - -endfunction() diff --git a/cmake/nuttx_add_rust.cmake b/cmake/nuttx_add_rust.cmake deleted file mode 100644 index cfc527b9b..000000000 --- a/cmake/nuttx_add_rust.cmake +++ /dev/null @@ -1,228 +0,0 @@ -# ############################################################################## -# cmake/nuttx_add_rust.cmake -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -include(nuttx_parse_function_args) - -# ~~~ -# Convert architecture type to Rust NuttX target -# -# Supported architectures: -# - armv7a: armv7a-nuttx-eabi, armv7a-nuttx-eabihf -# - thumbv6m: thumbv6m-nuttx-eabi -# - thumbv7a: thumbv7a-nuttx-eabi, thumbv7a-nuttx-eabihf -# - thumbv7m: thumbv7m-nuttx-eabi -# - thumbv7em: thumbv7em-nuttx-eabihf -# - thumbv8m.main: thumbv8m.main-nuttx-eabi, thumbv8m.main-nuttx-eabihf -# - thumbv8m.base: thumbv8m.base-nuttx-eabi, thumbv8m.base-nuttx-eabihf -# - riscv32: riscv32imc/imac/imafc-unknown-nuttx-elf -# - riscv64: riscv64imac/imafdc-unknown-nuttx-elf -# - x86: i686-unknown-nuttx -# - x86_64: x86_64-unknown-nuttx-macho for sim on macOS, -# x86_64-unknown-nuttx otherwise -# - aarch64: aarch64-unknown-nuttx-macho for sim on macOS, -# aarch64-unknown-nuttx otherwise -# -# Inputs: -# ARCHTYPE - Architecture type (e.g. thumbv7m, riscv32) -# ABITYPE - ABI type (e.g. eabi, eabihf) -# CPUTYPE - CPU type (e.g. cortex-m4, sifive-e20) -# -# Output: -# OUTPUT - Rust target triple (e.g. riscv32imac-unknown-nuttx-elf, -# thumbv7m-nuttx-eabi, thumbv7em-nuttx-eabihf) -# ~~~ - -function(nuttx_rust_target_triple ARCHTYPE ABITYPE CPUTYPE OUTPUT) - if(ARCHTYPE STREQUAL "x86_64") - if(CONFIG_ARCH_SIM AND CONFIG_HOST_MACOS) - set(TARGET_TRIPLE - "${PROJECT_SOURCE_DIR}/tools/x86_64-unknown-nuttx-macho.json") - else() - set(TARGET_TRIPLE "${PROJECT_SOURCE_DIR}/tools/x86_64-unknown-nuttx.json") - endif() - elseif(ARCHTYPE STREQUAL "x86") - set(TARGET_TRIPLE "${PROJECT_SOURCE_DIR}/tools/i486-unknown-nuttx.json") - elseif(ARCHTYPE STREQUAL "aarch64") - if(CONFIG_ARCH_SIM AND CONFIG_HOST_MACOS) - set(TARGET_TRIPLE - "${PROJECT_SOURCE_DIR}/tools/aarch64-unknown-nuttx-macho.json") - else() - set(TARGET_TRIPLE - "${PROJECT_SOURCE_DIR}/tools/aarch64-unknown-nuttx.json") - endif() - elseif(ARCHTYPE MATCHES "thumb") - if(ARCHTYPE MATCHES "thumbv8m") - # Extract just the base architecture type (thumbv8m.main or thumbv8m.base) - if(ARCHTYPE MATCHES "thumbv8m.main") - set(ARCH_BASE "thumbv8m.main") - elseif(ARCHTYPE MATCHES "thumbv8m.base") - set(ARCH_BASE "thumbv8m.base") - else() - # Otherwise determine if we should use thumbv8m.main or thumbv8m.base - # based on CPU type - if(CPUTYPE MATCHES "cortex-m23") - set(ARCH_BASE "thumbv8m.base") - else() - set(ARCH_BASE "thumbv8m.main") - endif() - endif() - set(TARGET_TRIPLE "${ARCH_BASE}-nuttx-${ABITYPE}") - else() - set(TARGET_TRIPLE "${ARCHTYPE}-nuttx-${ABITYPE}") - endif() - elseif(ARCHTYPE STREQUAL "riscv32") - if(CPUTYPE STREQUAL "sifive-e20") - set(TARGET_TRIPLE "riscv32imc-unknown-nuttx-elf") - elseif(CPUTYPE STREQUAL "sifive-e31") - set(TARGET_TRIPLE "riscv32imac-unknown-nuttx-elf") - elseif(CPUTYPE STREQUAL "sifive-e76") - set(TARGET_TRIPLE "riscv32imafc-unknown-nuttx-elf") - else() - set(TARGET_TRIPLE "riscv32imc-unknown-nuttx-elf") - endif() - elseif(ARCHTYPE STREQUAL "riscv64") - if(CPUTYPE STREQUAL "sifive-s51") - set(TARGET_TRIPLE "riscv64imac-unknown-nuttx-elf") - elseif(CPUTYPE STREQUAL "sifive-u54") - set(TARGET_TRIPLE "riscv64imafdc-unknown-nuttx-elf") - else() - set(TARGET_TRIPLE "riscv64imac-unknown-nuttx-elf") - endif() - endif() - - if(NOT TARGET_TRIPLE) - message( - FATAL_ERROR - "Unsupported Rust target: LLVM_ARCHTYPE=${ARCHTYPE}, LLVM_ABITYPE=${ABITYPE}, LLVM_CPUTYPE=${CPUTYPE}" - ) - endif() - set(${OUTPUT} - ${TARGET_TRIPLE} - PARENT_SCOPE) -endfunction() - -# ~~~ -# nuttx_add_rust -# -# Description: -# Build a Rust crate and add it as a static library to the NuttX build system -# -# Example: -# nuttx_add_rust( -# CRATE_NAME -# hello -# CRATE_PATH -# ${CMAKE_CURRENT_SOURCE_DIR}/hello -# FEATURES -# sim -# ) -# ~~~ - -function(nuttx_add_rust) - - # parse arguments into variables - nuttx_parse_function_args( - FUNC - nuttx_add_rust - ONE_VALUE - CRATE_NAME - CRATE_PATH - MULTI_VALUE - FEATURES - REQUIRED - CRATE_NAME - CRATE_PATH - ARGN - ${ARGN}) - - # Determine build profile based on CONFIG_DEBUG_FULLOPT - if(CONFIG_DEBUG_FULLOPT) - set(RUST_PROFILE_FLAG "--release") - set(RUST_PROFILE "release") - set(RUST_PANIC_FLAGS "-Zunstable-options -Cpanic=immediate-abort") - else() - set(RUST_PROFILE_FLAG "") - set(RUST_PROFILE "debug") - set(RUST_PANIC_FLAGS "") - endif() - - foreach(feature ${FEATURES}) - list(APPEND RUST_FEATURE_FLAGS --features ${feature}) - endforeach() - - # Get the Rust target triple - nuttx_rust_target_triple(${LLVM_ARCHTYPE} ${LLVM_ABITYPE} ${LLVM_CPUTYPE} - RUST_TARGET) - - # Get binary directory path using target triple base name if it's a JSON file - if(RUST_TARGET MATCHES ".json$") - get_filename_component(TARGET_BASE ${RUST_TARGET} NAME_WE) - else() - set(TARGET_BASE ${RUST_TARGET}) - endif() - - set(RUST_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR}/${CRATE_NAME}/target) - set(RUST_LIB_PATH - ${RUST_BUILD_DIR}/${TARGET_BASE}/${RUST_PROFILE}/lib${CRATE_NAME}.a) - - # Create build directory - file(MAKE_DIRECTORY ${RUST_BUILD_DIR}) - - # Collect Rust source files and manifests as dependencies so that changes in - # the crate trigger a rebuild via CMake/Ninja. - file( - GLOB_RECURSE - RUST_CRATE_SOURCES - CONFIGURE_DEPENDS - "${CRATE_PATH}/Cargo.toml" - "${CRATE_PATH}/Cargo.lock" - "${CRATE_PATH}/build.rs" - "${CRATE_PATH}/src/*.rs" - "${CRATE_PATH}/src/**/*.rs") - - # Add a custom command to build the Rust crate - add_custom_command( - OUTPUT ${RUST_LIB_PATH} - COMMAND - ${CMAKE_COMMAND} -E env - NUTTX_INCLUDE_DIR=${PROJECT_SOURCE_DIR}/include:${CMAKE_BINARY_DIR}/include:${CMAKE_BINARY_DIR}/include/arch - RUSTFLAGS=${RUST_PANIC_FLAGS} cargo build ${RUST_PROFILE_FLAG} - -Zbuild-std=std,panic_abort -Zjson-target-spec --manifest-path - ${CRATE_PATH}/Cargo.toml --target ${RUST_TARGET} --target-dir - ${RUST_BUILD_DIR} ${RUST_FEATURE_FLAGS} - DEPENDS ${RUST_CRATE_SOURCES} - COMMENT "Building Rust crate ${CRATE_NAME}" - VERBATIM) - - # Add a custom target that depends on the built library - add_custom_target(${CRATE_NAME}_build ALL DEPENDS ${RUST_LIB_PATH}) - - # Add imported library target - add_library(${CRATE_NAME} STATIC IMPORTED GLOBAL) - set_target_properties(${CRATE_NAME} PROPERTIES IMPORTED_LOCATION - ${RUST_LIB_PATH}) - - # Add the Rust library to NuttX build - nuttx_add_extra_library(${RUST_LIB_PATH}) - - # Ensure the Rust library is built before linking - add_dependencies(${CRATE_NAME} ${CRATE_NAME}_build) - -endfunction() diff --git a/cmake/nuttx_add_wamrmod.cmake b/cmake/nuttx_add_wamrmod.cmake deleted file mode 100644 index 65f27c91c..000000000 --- a/cmake/nuttx_add_wamrmod.cmake +++ /dev/null @@ -1,78 +0,0 @@ -# ############################################################################## -# cmake/nuttx_add_wamrmod.cmake -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -set(WAMR_MODULE_DIR ${CMAKE_BINARY_DIR}/wamrmod) - -if(NOT EXISTS {WAMR_MODULE_DIR}) - file(MAKE_DIRECTORY ${WAMR_MODULE_DIR}) -endif() - -include(nuttx_parse_function_args) - -# ~~~ -# nuttx_add_wamrmod -# -# Description: -# Register custom module into WAMR runtime -# -# Example: -# nuttx_add_wamrmod( -# MODS -# ${custom_mods} -# ) -# ~~~ - -function(nuttx_add_wamrmod) - - # parse arguments into variables - - nuttx_parse_function_args( - FUNC - nuttx_add_wamrmod - MULTI_VALUE - MODS - REQUIRED - MODS - ARGN - ${ARGN}) - - set(WAMR_MODULE_LIST ${WAMR_MODULE_DIR}/wamr_external_module_list.h) - set(WAMR_MODULE_PROTO ${WAMR_MODULE_DIR}/wamr_external_module_proto.h) - foreach(mod ${MODS}) - set(MOD_PDAT ${WAMR_MODULE_DIR}/${mod}.pdat) - set(MOD_BDAT ${WAMR_MODULE_DIR}/${mod}.bdat) - add_custom_command( - OUTPUT ${MOD_PDAT} ${MOD_BDAT} - COMMAND ${CMAKE_COMMAND} -E echo "wamr_module_${mod}_register," >> - ${WAMR_MODULE_LIST} - COMMAND ${CMAKE_COMMAND} -E echo "bool wamr_module_${mod}_register(void);" - >> ${WAMR_MODULE_PROTO} - COMMAND ${CMAKE_COMMAND} -E touch ${MOD_PDAT} - COMMAND ${CMAKE_COMMAND} -E touch ${MOD_BDAT} - WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} - VERBATIM - COMMENT "WAMR Module: Gen and Updating external module => ${mod}") - add_custom_target(wamr_module_${mod} DEPENDS ${MOD_PDAT} ${MOD_BDAT}) - add_dependencies(apps_context wamr_module_${mod}) - endforeach() - -endfunction() diff --git a/cmake/nuttx_wasm_interface.cmake b/cmake/nuttx_wasm_interface.cmake deleted file mode 100644 index 4e746f764..000000000 --- a/cmake/nuttx_wasm_interface.cmake +++ /dev/null @@ -1,58 +0,0 @@ -# ############################################################################## -# cmake/nuttx_wasm_interface.cmake -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -# This is NuttX native wrapper for the WAMR interface. - -if(NOT TARGET wasm_interface) - add_custom_target(wasm_interface) -endif() - -# declare WAMS build directory and add INSTALL path -function(wasm_add_application) - - cmake_parse_arguments( - APP "" "NAME;STACK_SIZE;INITIAL_MEMORY_SIZE;WAMR_MODE;INSTALL_NAME" - "SRCS;WLDFLAGS;WCFLAGS;WINCLUDES" ${ARGN}) - - set_property( - TARGET wasm_interface - APPEND - PROPERTY WASM_DIR ${CMAKE_CURRENT_LIST_DIR}) - - if(APP_INSTALL_NAME) - add_custom_command( - OUTPUT ${CMAKE_BINARY_DIR}/wasm/${APP_INSTALL_NAME} - COMMAND ${CMAKE_COMMAND} -E touch_nocreate - ${CMAKE_BINARY_DIR}/wasm/${APP_INSTALL_NAME} - DEPENDS apps) - add_custom_target(wasm_gen_${APP_NAME} - DEPENDS ${CMAKE_BINARY_DIR}/wasm/${APP_INSTALL_NAME}) - add_dynamic_rcraws(RAWS ${CMAKE_BINARY_DIR}/wasm/${APP_INSTALL_NAME} - DEPENDS wasm_gen_${APP_NAME}) - endif() - -endfunction() - -function(wasm_add_library) - set_property( - TARGET wasm_interface - APPEND - PROPERTY WASM_DIR ${CMAKE_CURRENT_LIST_DIR}) -endfunction() diff --git a/config.nims b/config.nims deleted file mode 100644 index 2d96ca390..000000000 --- a/config.nims +++ /dev/null @@ -1,135 +0,0 @@ -############################################################################ -# apps/config.nims -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -import std/os -import std/strutils - -switch "os", "nuttx" -switch "mm", "orc" - -switch "arm.nuttx.gcc.exe", "arm-none-eabi-gcc" -switch "arm64.nuttx.gcc.exe", "aarch64-none-elf-gcc" -switch "riscv32.nuttx.gcc.exe", "riscv64-unknown-elf-gcc" -switch "riscv64.nuttx.gcc.exe", "riscv64-unknown-elf-gcc" -switch "amd64.nuttx.gcc.exe", "x86_64-linux-gnu-gcc" - -switch "nimcache", ".nimcache" -switch "d", "useStdLib" -switch "d", "useMalloc" -switch "d", "nimAllocPagesViaMalloc" -switch "d", "noSignalHandler" -switch "threads", "off" -switch "noMain", "on" -switch "compileOnly", "on" -switch "noLinking", "on" -# TODO: need OpenSSL-mbedTLS wrapper library. -#switch "d", "ssl" -#swich "dynlibOverride", "ssl" - -type - OptFlag = enum - oNone - oSize - DotConfig = object - arch: string - opt: OptFlag - debugSymbols: bool - ramSize: int - isSim: bool - -proc killoBytes(bytes: int): int = - result = (bytes / 1024).int - -proc read_config(cfg: string): DotConfig = - for line in cfg.readFile.splitLines: - if not line.startsWith("CONFIG_"): - continue - let keyval = line.replace("CONFIG_", "").split("=") - if keyval.len != 2: - continue - case keyval[0] - of "ARCH": - let arch = keyval[1].strip(chars = {'"'}) - case arch - of "arm", "arm64": - result.arch = arch - of "sim": - if defined(amd64): - result.arch = "amd64" - elif defined(aarch64): - result.arch = "arm64" - result.isSim = true - of "ARCH_FAMILY": - let arch = keyval[1].strip(chars = {'"'}) - case arch - of "rv32": - result.arch = "riscv32" - of "rv64": - result.arch = "riscv64" - of "DEBUG_NOOPT": - result.opt = oNone - of "DEBUG_FULLOPT": - result.opt = oSize - of "DEBUG_SYMBOLS": - result.debugSymbols = true - of "RAM_SIZE": - result.ramSize = keyval[1].parseInt - echo "* arch: " & result.arch - echo "* opt: " & $result.opt - echo "* debug: " & $result.debugSymbols - echo "* ramSize: " & $result.ramSize - -func bool2onoff(b: bool): string = - result = if b: "on" else: "off" - -proc setup_cfg(cfg: DotConfig) = - switch("cpu", cfg.arch) - if cfg.opt == oSize: - switch("define", "release") - switch("define", "danger") - switch("opt", "size") - if cfg.debugSymbols: - # use native debugger (gdb) - switch("debugger", "native") - let debug_onoff = cfg.debugSymbols.bool2onoff - switch("lineDir", debug_onoff) - switch("stackTrace", debug_onoff) - switch("lineTrace", debug_onoff) - if not cfg.isSim: - # Adjust the page size for Nim's GC allocator. - let ramKilloBytes = cfg.ramSize.killoBytes - if ramKilloBytes < 32: - switch("define", "nimPage256") - elif ramKilloBytes < 512: - switch("define", "nimPage512") - elif ramKilloBytes < 2048: - switch("define", "nimPage1k") - if ramKilloBytes < 512: - # Sets MemAlign to 4 bytes which reduces the memory alignment - # to better match some embedded devices. - switch("define", "nimMemAlignTiny") - - -const key = "TOPDIR" -let topdir = if existsEnv(key): getEnv(key) else: thisDir() & "/../nuttx" -let cfg = read_config(topdir & "/.config") -cfg.setup_cfg() diff --git a/crypto/CMakeLists.txt b/crypto/CMakeLists.txt deleted file mode 100644 index 5f093c33c..000000000 --- a/crypto/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -# ############################################################################## -# apps/crypto/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -nuttx_add_subdirectory() - -nuttx_generate_kconfig(MENUDESC "Cryptography Library Support") diff --git a/crypto/controlse/CMakeLists.txt b/crypto/controlse/CMakeLists.txt deleted file mode 100644 index 5ffa43cfd..000000000 --- a/crypto/controlse/CMakeLists.txt +++ /dev/null @@ -1,47 +0,0 @@ -# ############################################################################## -# apps/crypto/controlse/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_CRYPTO_CONTROLSE) - - set(MBEDTLS_DIR ${CMAKE_BINARY_DIR}/apps/include/mbedtls) - - nuttx_add_application( - NAME - ${CONFIG_CRYPTO_CONTROLSE_PROGNAME} - STACKSIZE - ${CONFIG_CRYPTO_CONTROLSE_STACKSIZE} - MODULE - ${CONFIG_CRYPTO_CONTROLSE} - SRCS - controlse_main.cxx - chex_util.cxx - csecure_element.cxx - cstring.cxx - ccertificate.cxx - ccsr.cxx - cpublic_key.cxx - cserial_number.cxx - csan_builder.cxx - INCLUDE_DIRECTORIES - ${MBEDTLS_DIR}) - -endif() diff --git a/crypto/controlse/Kconfig b/crypto/controlse/Kconfig deleted file mode 100644 index 76b85ec57..000000000 --- a/crypto/controlse/Kconfig +++ /dev/null @@ -1,42 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config CRYPTO_CONTROLSE - bool "Control Secure Element device" - default n - depends on DEV_SE05X - depends on CRYPTO_MBEDTLS - depends on MBEDTLS_VERSION = "3.6.2" - select MBEDTLS_ECDSA_C - select MBEDTLS_ECP_C - select MBEDTLS_ECP_DP_SECP256R1_ENABLED - select MBEDTLS_PEM_WRITE_C - select MBEDTLS_PK_WRITE_C - select MBEDTLS_X509_CSR_PARSE_C - select MBEDTLS_X509_CSR_WRITE_C - select MBEDTLS_X509_CRT_WRITE_C - ---help--- - Enable the controlse library and utility. It provides an - access library to the secure element device. The utility can - control the secure element device from the nuttx shell - -if CRYPTO_CONTROLSE - -config CRYPTO_CONTROLSE_PROGNAME - string "Program name" - default "controlse" - ---help--- - This is the name of the program that will be used when the NSH ELF - program is installed. - -config CRYPTO_CONTROLSE_PRIORITY - int "Controlse utility task priority" - default 100 - -config CRYPTO_CONTROLSE_STACKSIZE - int "Controlse utility stack size" - default DEFAULT_TASK_STACKSIZE - -endif diff --git a/crypto/controlse/Make.defs b/crypto/controlse/Make.defs deleted file mode 100644 index 45536c468..000000000 --- a/crypto/controlse/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/crypto/controlse/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_CRYPTO_CONTROLSE),) -CONFIGURED_APPS += $(APPDIR)/crypto/controlse -endif diff --git a/crypto/controlse/Makefile b/crypto/controlse/Makefile deleted file mode 100644 index f4ba03a40..000000000 --- a/crypto/controlse/Makefile +++ /dev/null @@ -1,39 +0,0 @@ -############################################################################ -# apps/crypto/controlse/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -# Copyright 2023, 2024 NXP - -include $(APPDIR)/Make.defs - -# controlse built-in application info - -PROGNAME = $(CONFIG_CRYPTO_CONTROLSE_PROGNAME) -PRIORITY = $(CONFIG_CRYPTO_CONTROLSE_PRIORITY) -STACKSIZE = $(CONFIG_CRYPTO_CONTROLSE_STACKSIZE) - -# controlse main source - -MAINSRC = controlse_main.cxx -CXXSRCS = chex_util.cxx csecure_element.cxx cstring.cxx ccertificate.cxx\ - ccsr.cxx cpublic_key.cxx cserial_number.cxx csan_builder.cxx - -include $(APPDIR)/Application.mk diff --git a/crypto/controlse/ccertificate.cxx b/crypto/controlse/ccertificate.cxx deleted file mode 100644 index 4d663ea75..000000000 --- a/crypto/controlse/ccertificate.cxx +++ /dev/null @@ -1,534 +0,0 @@ -//*************************************************************************** -// apps/crypto/controlse/ccertificate.cxx -// -// SPDX-License-Identifier: Apache-2.0 -// -// Licensed to the Apache Software Foundation (ASF) under one or more -// contributor license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright ownership. The -// ASF licenses this file to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance with the -// License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -// License for the specific language governing permissions and limitations -// under the License. -// -//*************************************************************************** - -// Copyright 2024 NXP - -//*************************************************************************** -// Included Files -//*************************************************************************** - -#define MBEDTLS_ALLOW_PRIVATE_ACCESS -#include "crypto/controlse/ccertificate.hxx" - -#include "cmbedtls_se05x_extension.hxx" -#include "crypto/controlse/chex_util.hxx" -#include "crypto/controlse/cpublic_key.hxx" -#include "crypto/controlse/cserial_number.hxx" -#include "crypto/controlse/isecure_element.hxx" -#include <mbedtls/oid.h> -#include <mbedtls/pem.h> -#include <mbedtls/sha256.h> -#include <mbedtls/x509_crt.h> -#include <mbedtls/x509_csr.h> -#include <string.h> - -namespace Controlse -{ - -//*************************************************************************** -// Private Data -//*************************************************************************** - -static constexpr int SECONDS_IN_DAY = (60 * 60 * 24); -static constexpr size_t TBS_HASH_BUFFER_SIZE = 32; - -static constexpr char certificate_header[] = "-----BEGIN CERTIFICATE-----\n"; -static constexpr char certificate_footer[] = "-----END CERTIFICATE-----\n"; -static constexpr size_t datetime_size = 15; - -//*************************************************************************** -// Class Method Implementations -//*************************************************************************** - -CCertificate::CCertificate(const ISecureElement &se, uint32_t keystore_id) -{ - mbedtls_x509_crt_init(&crt); - is_loaded = LoadFromSecureElement(se, keystore_id); -} - -CCertificate::CCertificate(const uint8_t *crt_der_or_pem, size_t crt_size) -{ - mbedtls_x509_crt_init(&crt); - is_loaded = LoadFromDerOrPem(crt_der_or_pem, crt_size); -} - -static void GetCurrentDateTime(char datetime[datetime_size], int seconds) -{ - time_t rawtime; - struct tm tm_info; - time(&rawtime); - rawtime += seconds; - strftime(datetime, datetime_size, "%Y%m%d%H%M%S", - gmtime_r(&rawtime, &tm_info)); -} - -CCertificate::CCertificate(const ISecureElement &se, - const uint8_t *csr_der_or_pem, size_t csr_size, - uint32_t keystore_id) -{ - mbedtls_x509_crt_init(&crt); - char from_datetime[datetime_size]; - char to_datetime[datetime_size]; - GetCurrentDateTime(from_datetime, 0); - GetCurrentDateTime(to_datetime, SECONDS_IN_DAY); - is_loaded = LoadFromCsrDerOrPem(se, csr_der_or_pem, csr_size, keystore_id, - from_datetime, to_datetime); -} - -CCertificate::CCertificate(const ISecureElement &se, - const uint8_t *csr_der_or_pem, size_t csr_size, - uint32_t keystore_id, const char *from_datetime, - const char *to_datetime) -{ - mbedtls_x509_crt_init(&crt); - is_loaded = LoadFromCsrDerOrPem(se, csr_der_or_pem, csr_size, keystore_id, - from_datetime, to_datetime); -} - -CCertificate::~CCertificate() { mbedtls_x509_crt_free(&crt); } - -bool CCertificate::IsLoaded() const { return is_loaded; } - -bool CCertificate::StoreOnSecureElement(const ISecureElement &se, - uint32_t keystore_id) const -{ - struct se05x_key_transmission_s args; - args.entry.id = keystore_id; - args.content.buffer = crt.raw.p; - args.content.buffer_size = crt.raw.len; - args.content.buffer_content_size = crt.raw.len; - return se.SetData(args); -} - -bool CCertificate::LoadFromSecureElement(const ISecureElement &se, - uint32_t keystore_id) -{ - size_t certificate_der_size = 1000; - uint8_t *certificate_der = new uint8_t[certificate_der_size]; - struct se05x_key_transmission_s args - = { .entry = { .id = keystore_id }, - .content = { .buffer = certificate_der, - .buffer_size = certificate_der_size } }; - bool result = se.GetData(args); - - if (result) - { - result = 0 - == mbedtls_x509_crt_parse(&crt, certificate_der, - args.content.buffer_content_size); - } - - delete[] certificate_der; - return result; -} - -bool CCertificate::LoadFromDerOrPem(const uint8_t *crt_der_or_pem, - size_t crt_size) -{ - return 0 == mbedtls_x509_crt_parse(&crt, crt_der_or_pem, crt_size); -} - -bool CCertificate::LoadFromCsrDerOrPem(const ISecureElement &se, - const uint8_t *csr_der_or_pem, - size_t csr_size, uint32_t keystore_id, - const char *from_datetime, - const char *to_datetime) -{ - mbedtls_x509_csr csr; - mbedtls_x509_csr_init(&csr); - auto result = 0 == mbedtls_x509_csr_parse(&csr, csr_der_or_pem, csr_size); - - mbedtls_x509write_cert crt_builder; - mbedtls_x509write_crt_init(&crt_builder); - char subject_name[200]; - if (result) - { - mbedtls_x509write_crt_set_version(&crt_builder, - MBEDTLS_X509_CRT_VERSION_3); - result = 0 < mbedtls_x509_dn_gets(subject_name, sizeof(subject_name), - &csr.subject); - } - - mbedtls_pk_context key; - mbedtls_pk_init(&key); - if (result) - { - result = 0 - == MbedtlsSe05xExtension::mbedtls_pk_setup_key_se05x( - key, se, keystore_id); - } - - mbedtls_pk_context public_key; - public_key.pk_ctx = csr.pk.pk_ctx; - public_key.pk_info = csr.pk.pk_info; - - // Invalidate the public key in CSR - // The public key is transferred to CRT so the CSR may not free the memory - csr.pk.pk_ctx = nullptr; - csr.pk.pk_info = nullptr; - mbedtls_x509_csr_free(&csr); - - if (result) - { - mbedtls_x509write_crt_set_subject_key(&crt_builder, &public_key); - mbedtls_x509write_crt_set_issuer_key(&crt_builder, &key); - result = 0 - == mbedtls_x509write_crt_set_subject_name(&crt_builder, - subject_name); - } - - if (result) - { - result = 0 - == mbedtls_x509write_crt_set_issuer_name(&crt_builder, - "CN=CA,O=controlse,C=NL"); - } - - mbedtls_mpi serial; - mbedtls_mpi_init(&serial); - if (result) - { - mbedtls_x509write_crt_set_md_alg(&crt_builder, MBEDTLS_MD_SHA256); - result = 0 == mbedtls_mpi_read_string(&serial, 10, "1"); - } - - if (result) - { - result = 0 == mbedtls_x509write_crt_set_serial(&crt_builder, &serial); - } - - if (result) - { - result = 0 - == mbedtls_x509write_crt_set_validity( - &crt_builder, from_datetime, to_datetime); - } - - size_t buf_size = 1000; - uint8_t *buf = nullptr; - if (result) - { - buf = new uint8_t[buf_size]; - result = buf != nullptr; - } - - size_t buf_content_size; - if (result) - { - auto der_result - = mbedtls_x509write_crt_der(&crt_builder, buf, buf_size, nullptr, 0); - buf_content_size = der_result; - result = 0 < der_result; - } - - mbedtls_x509write_crt_free(&crt_builder); - MbedtlsSe05xExtension::mbedtls_pk_free_se05x(key); - mbedtls_pk_free(&key); - mbedtls_pk_free(&public_key); - mbedtls_mpi_free(&serial); - - if (result) - { - result = LoadFromDerOrPem(buf + buf_size - buf_content_size, - buf_content_size); - } - - if (buf) - { - delete[] buf; - } - return result; -} - -bool CCertificate::VerifyAgainst(const ISecureElement &se, - uint32_t verify_against_id) const -{ - if (!is_loaded) - { - return false; - } - - uint8_t tbs_buffer[TBS_HASH_BUFFER_SIZE]; - bool result = 0 == mbedtls_sha256(crt.tbs.p, crt.tbs.len, tbs_buffer, 0); - - if (result) - { - struct se05x_signature_s verify_args = { - .key_id = verify_against_id, - .algorithm = SE05X_ALGORITHM_SHA256, - .tbs = { .buffer = tbs_buffer, - .buffer_size = sizeof(tbs_buffer), - .buffer_content_size = sizeof(tbs_buffer) }, - .signature = { .buffer = crt.sig.p, - .buffer_size = crt.sig.len, - .buffer_content_size = crt.sig.len }, - }; - result = se.Verify(verify_args); - } - - return result; -} - -static bool check_time(const mbedtls_x509_time *before, - const mbedtls_x509_time *after) -{ - if (before->year > after->year) - return false; - - if (before->year == after->year && before->mon > after->mon) - return false; - - if (before->year == after->year && before->mon == after->mon - && before->day > after->day) - return false; - - if (before->year == after->year && before->mon == after->mon - && before->day == after->day && before->hour > after->hour) - return false; - - if (before->year == after->year && before->mon == after->mon - && before->day == after->day && before->hour == after->hour - && before->min > after->min) - return false; - - if (before->year == after->year && before->mon == after->mon - && before->day == after->day && before->hour == after->hour - && before->min == after->min && before->sec > after->sec) - return false; - - return true; -} - -int CCertificate::TestValidTimerange(time_t now) const -{ - - auto lt = gmtime(&now); - - mbedtls_x509_time mbedtls_now; - mbedtls_now.year = lt->tm_year + 1900; - mbedtls_now.mon = lt->tm_mon + 1; - mbedtls_now.day = lt->tm_mday; - mbedtls_now.hour = lt->tm_hour; - mbedtls_now.min = lt->tm_min; - mbedtls_now.sec = lt->tm_sec; - - if (!check_time(&mbedtls_now, &crt.valid_to)) - { - return -1; - } - if (!check_time(&crt.valid_from, &mbedtls_now)) - { - return 1; - } - - return 0; -} - -CPublicKey *CCertificate::GetPublicKey() const -{ - if (!is_loaded) - { - return nullptr; - } - - size_t root_key_buf_size = 100; - uint8_t *root_key_buf = new uint8_t[root_key_buf_size]; - - bool result = false; - if (root_key_buf) - { - mbedtls_ecp_keypair *keypair - = reinterpret_cast<mbedtls_ecp_keypair *>(crt.pk.pk_ctx); - result = 0 - == mbedtls_ecp_point_write_binary( - &keypair->grp, &keypair->Q, MBEDTLS_ECP_PF_UNCOMPRESSED, - &root_key_buf_size, root_key_buf, root_key_buf_size); - } - - CPublicKey *public_key - = result ? new CPublicKey(root_key_buf, root_key_buf_size) : nullptr; - - if (root_key_buf) - { - delete[] root_key_buf; - } - - return public_key; -} - -char *CCertificate::GetOid(const char *oid) const -{ - if (!is_loaded) - { - return nullptr; - } - auto item = mbedtls_asn1_find_named_data(&crt.subject, oid, 3); - - if (item) - { - auto data = new char[item->val.len + 1]; - memcpy(data, item->val.p, item->val.len); - data[item->val.len] = 0; - return data; - } - return nullptr; -} - -CSerialNumber *CCertificate::GetSerialNumber() const -{ - if (!is_loaded) - { - return nullptr; - } - - if (crt.serial.len == CSerialNumber::SERIAL_NUMBER_SIZE) - { - auto serial = new CSerialNumber(crt.serial.p); - return serial; - } - return nullptr; -} - -size_t CCertificate::GetNumberOfSubjectAlternativeNames() const -{ - if (!is_loaded) - { - return 0; - } - size_t size = 0; - auto current = &crt.subject_alt_names; - - do - { - if (current->buf.tag - == (MBEDTLS_ASN1_CONTEXT_SPECIFIC - | MBEDTLS_X509_SAN_UNIFORM_RESOURCE_IDENTIFIER)) - { - size++; - } - current = current->next; - } - while (current); - return size; -} - -char *CCertificate::GetSubjectAlternativeName(int item) const -{ - if (!is_loaded) - { - return nullptr; - } - - auto current = &crt.subject_alt_names; - - // go to first uri - while (current->buf.tag - != (MBEDTLS_ASN1_CONTEXT_SPECIFIC - | MBEDTLS_X509_SAN_UNIFORM_RESOURCE_IDENTIFIER)) - { - current = current->next; - if (current == nullptr) - { - return nullptr; - } - } - - // go the next uri until we get to the correct item - for (int i = 0; i < item; i++) - { - do - { - current = current->next; - if (current == nullptr) - { - return nullptr; - } - } - while (current->buf.tag - != (MBEDTLS_ASN1_CONTEXT_SPECIFIC - | MBEDTLS_X509_SAN_UNIFORM_RESOURCE_IDENTIFIER)); - } - - auto san = new char[current->buf.len + 1]; - if (san) - { - memcpy(san, current->buf.p, current->buf.len); - san[current->buf.len] = 0; - } - return san; -} - -size_t CCertificate::GetDer(uint8_t **der) const -{ - if (!is_loaded) - { - return 0; - } - *der = new uint8_t[crt.raw.len]; - memcpy(*der, crt.raw.p, crt.raw.len); - return crt.raw.len; -} - -char *CCertificate::GetPem() const -{ - if (!is_loaded) - { - return 0; - } - - char pem_buf[1000]; - size_t pem_content_size; - auto result = mbedtls_pem_write_buffer( - certificate_header, certificate_footer, crt.raw.p, crt.raw.len, - (uint8_t *)pem_buf, sizeof(pem_buf), &pem_content_size); - if (result != 0) - { - return nullptr; - } - - auto pem = new char[pem_content_size + 1]; - memcpy(pem, pem_buf, pem_content_size); - pem[pem_content_size] = 0; - return pem; -} - -bool CCertificate::ContainsSan(const char *name, size_t size) const -{ - auto san_amount = GetNumberOfSubjectAlternativeNames(); - for (size_t i = 0; i < san_amount; i++) - { - auto san = GetSubjectAlternativeName(i); - if (!san) - { - return false; - } - auto found = (memcmp(name, san, size) == 0); - delete[] san; - if (found) - { - return true; - } - } - return false; -} - -} // namespace Controlse diff --git a/crypto/controlse/ccsr.cxx b/crypto/controlse/ccsr.cxx deleted file mode 100644 index 9c3326468..000000000 --- a/crypto/controlse/ccsr.cxx +++ /dev/null @@ -1,214 +0,0 @@ -//*************************************************************************** -// apps/crypto/controlse/ccsr.cxx -// -// SPDX-License-Identifier: Apache-2.0 -// -// Licensed to the Apache Software Foundation (ASF) under one or more -// contributor license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright ownership. The -// ASF licenses this file to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance with the -// License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -// License for the specific language governing permissions and limitations -// under the License. -// -//************************************************************************** - -// Copyright 2024 NXP - -//*************************************************************************** -// Included Files -//*************************************************************************** - -#define MBEDTLS_ALLOW_PRIVATE_ACCESS -#include "crypto/controlse/ccsr.hxx" - -#include "cmbedtls_se05x_extension.hxx" -#include "crypto/controlse/cpublic_key.hxx" -#include "crypto/controlse/csecure_element.hxx" -#include <cstring> -#include <mbedtls/pem.h> - -using Controlse::MbedtlsSe05xExtension; - -namespace Controlse -{ - -//*************************************************************************** -// Private Data -//*************************************************************************** - -static const char certificate_request_header[] - = "-----BEGIN CERTIFICATE REQUEST-----\n"; -static const char certificate_request_footer[] - = "-----END CERTIFICATE REQUEST-----\n"; - -//*************************************************************************** -// Class Method Implementations -//*************************************************************************** - -CCsr::CCsr(const ISecureElement &se, uint32_t keystore_id) -{ - mbedtls_x509_csr_init(&csr); - is_loaded = LoadFromSecureElement(se, keystore_id); -} - -CCsr::CCsr(const uint8_t *der_or_pem, const size_t size) -{ - mbedtls_x509_csr_init(&csr); - is_loaded = 0 == mbedtls_x509_csr_parse(&csr, der_or_pem, size); -} - -CCsr::~CCsr() { mbedtls_x509_csr_free(&csr); } - -bool CCsr::IsLoaded() const { return is_loaded; } - -bool CCsr::StoreOnSecureElement(const ISecureElement &se, - uint32_t keystore_id) const -{ - struct se05x_key_transmission_s args; - args.entry.id = keystore_id; - args.content.buffer = csr.raw.p; - args.content.buffer_size = csr.raw.len; - args.content.buffer_content_size = csr.raw.len; - return se.SetData(args); -} - -bool CCsr::LoadFromSecureElement(const ISecureElement &se, - uint32_t keystore_id) -{ - size_t csr_der_size = 1000; - uint8_t *csr_der = new uint8_t[csr_der_size]; - struct se05x_key_transmission_s args - = { .entry = { .id = keystore_id }, - .content = { .buffer = csr_der, .buffer_size = csr_der_size } }; - bool result = se.GetData(args); - - if (result) - { - result = 0 - == mbedtls_x509_csr_parse(&csr, csr_der, - args.content.buffer_content_size); - } - - delete[] csr_der; - return result; -} - -size_t CCsr::GetDer(uint8_t **der) const -{ - if (!IsLoaded()) - { - return 0; - } - *der = new uint8_t[csr.raw.len]; - memcpy(*der, csr.raw.p, csr.raw.len); - return csr.raw.len; -} - -char *CCsr::GetPem() const -{ - if (!IsLoaded()) - { - return nullptr; - } - - char pem_buf[1000]; - size_t pem_content_size; - auto result = mbedtls_pem_write_buffer( - certificate_request_header, certificate_request_footer, csr.raw.p, - csr.raw.len, (uint8_t *)pem_buf, sizeof(pem_buf), &pem_content_size); - if (result != 0) - { - return nullptr; - } - - auto pem = new char[pem_content_size + 1]; - memcpy(pem, pem_buf, pem_content_size); - pem[pem_content_size] = 0; - return pem; -} - -CCsr::CsrBuilder::CsrBuilder(ISecureElement &se, const char *subject, - uint32_t key_slot_id) -{ - mbedtls_x509write_csr_init(&csr_w); - mbedtls_pk_init(&key); - - ready = 0 - == MbedtlsSe05xExtension::mbedtls_pk_setup_key_se05x(key, se, - key_slot_id); - - if (ready) - { - mbedtls_x509write_csr_set_key(&csr_w, &key); - ready = 0 == mbedtls_x509write_csr_set_subject_name(&csr_w, subject); - } - - if (ready) - { - mbedtls_x509write_csr_set_md_alg(&csr_w, MBEDTLS_MD_SHA256); - ready = 0 - == mbedtls_x509write_csr_set_key_usage( - &csr_w, MBEDTLS_X509_KU_KEY_CERT_SIGN); - } -} - -CCsr::CsrBuilder *CCsr::CsrBuilder::AddExtension(const char *oid, - size_t oid_size, - const uint8_t *value, - size_t value_size) -{ - if (ready) - { - ready = 0 - == mbedtls_x509write_csr_set_extension(&csr_w, oid, oid_size, 0, - value, value_size); - } - - return this; -} - -CCsr *CCsr::CsrBuilder::Build() -{ - size_t buf_size = 1000; - uint8_t *buf = nullptr; - if (ready) - { - buf = new uint8_t[buf_size]; - ready = nullptr != buf; - } - - int write_result_size = 0; - if (ready) - { - write_result_size - = mbedtls_x509write_csr_der(&csr_w, buf, buf_size, nullptr, 0); - ready = write_result_size > 0; - } - - MbedtlsSe05xExtension::mbedtls_pk_free_se05x(key); - mbedtls_x509write_csr_free(&csr_w); - - CCsr *result_csr = nullptr; - if (ready) - { - result_csr - = new CCsr(buf + buf_size - write_result_size, write_result_size); - } - - if (buf) - { - delete[] buf; - } - - return result_csr; -} - -} // namespace Controlse diff --git a/crypto/controlse/chex_util.cxx b/crypto/controlse/chex_util.cxx deleted file mode 100644 index 1e0f7e12a..000000000 --- a/crypto/controlse/chex_util.cxx +++ /dev/null @@ -1,102 +0,0 @@ -//*************************************************************************** -// apps/crypto/controlse/chex_util.cxx -// -// SPDX-License-Identifier: Apache-2.0 -// -// Licensed to the Apache Software Foundation (ASF) under one or more -// contributor license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright ownership. The -// ASF licenses this file to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance with the -// License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -// License for the specific language governing permissions and limitations -// under the License. -// -//************************************************************************** - -// Copyright 2024 NXP - -//*************************************************************************** -// Included Files -//*************************************************************************** - -#include "crypto/controlse/chex_util.hxx" -#include <cstdint> -#include <cstdio> -#include <cstring> - -namespace Controlse -{ - -//*************************************************************************** -// Class Method Implementations -//*************************************************************************** - -size_t CHexUtil::GetByteArraySizeFromHexString(const char *hex_buffer) -{ - auto hex_buffer_size = strcspn(hex_buffer, " \r\n"); - return GetByteArraySizeFromHexStringSize(hex_buffer_size); -} - -size_t CHexUtil::GetByteArraySizeFromHexStringSize(size_t hex_buffer_size) -{ - return hex_buffer_size / AMOUNT_OF_HEXDIGITS_PER_BYTE; -} - -size_t CHexUtil::GetHexStringSizeFromByteArraySize(size_t byte_array_size) -{ - return byte_array_size * AMOUNT_OF_HEXDIGITS_PER_BYTE; -} - -uint8_t *CHexUtil::ConvertHexStringToByteArray(const char *hex_buffer) -{ - auto hex_buffer_size = strcspn(hex_buffer, " \r\n"); - if (hex_buffer_size & 1) - { - return nullptr; - } - - return ConvertHexStringToByteArray(hex_buffer, hex_buffer_size); -} - -uint8_t *CHexUtil::ConvertHexStringToByteArray(const char *hex_buffer, - size_t hex_buffer_size) -{ - auto bin_buffer - = new uint8_t[GetByteArraySizeFromHexStringSize(hex_buffer_size)]; - if (bin_buffer) - { - size_t hex_buffer_pos; - size_t bin_buffer_pos = 0; - for (hex_buffer_pos = 0; (hex_buffer_pos < hex_buffer_size); - hex_buffer_pos += AMOUNT_OF_HEXDIGITS_PER_BYTE) - { - sscanf(&hex_buffer[hex_buffer_pos], "%2hhx", - &bin_buffer[bin_buffer_pos]); - bin_buffer_pos++; - } - } - return bin_buffer; -} - -char *CHexUtil::ByteArrayToHexString(const uint8_t bytearray[], size_t size) -{ - auto string = new char[GetHexStringSizeFromByteArraySize(size) + 1]; - if (string) - { - char *ptr = string; - for (size_t i = 0; i < size; i++) - { - ptr += sprintf(ptr, "%02x", bytearray[i]); - } - } - return string; -} - -} // namespace Controlse diff --git a/crypto/controlse/cmbedtls_se05x_extension.hxx b/crypto/controlse/cmbedtls_se05x_extension.hxx deleted file mode 100644 index 8289b124c..000000000 --- a/crypto/controlse/cmbedtls_se05x_extension.hxx +++ /dev/null @@ -1,191 +0,0 @@ -//*************************************************************************** -// apps/crypto/controlse/cmbedtls_se05x_extensions.hxx -// -// SPDX-License-Identifier: Apache-2.0 -// -// Licensed to the Apache Software Foundation (ASF) under one or more -// contributor license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright ownership. The -// ASF licenses this file to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance with the -// License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -// License for the specific language governing permissions and limitations -// under the License. -// -//************************************************************************** - -// Copyright 2024 NXP - -#pragma once - -//*************************************************************************** -// Included Files -//*************************************************************************** - -#define MBEDTLS_ALLOW_PRIVATE_ACCESS -#include "crypto/controlse/cpublic_key.hxx" -#include "crypto/controlse/isecure_element.hxx" -#include <../crypto/mbedtls/mbedtls/library/pk_wrap.h> -#include <cerrno> -#include <mbedtls/ctr_drbg.h> -#include <mbedtls/pk.h> -#include <mbedtls/x509_csr.h> -#include <nuttx/crypto/se05x.h> - -using Controlse::ISecureElement; - -struct mbedtls_se05x_ctx -{ - const ISecureElement *se; - uint32_t private_key_slot_id; -}; - -namespace Controlse -{ - -//*************************************************************************** -// Class definitions -//*************************************************************************** - -class MbedtlsSe05xExtension -{ -public: - static int mbedtls_pk_parse_se05x_public_key(mbedtls_pk_context &key, - CPublicKey &se05x_key) - { - mbedtls_ecp_keypair *keypair; - uint8_t *key_buffer = nullptr; - size_t key_buffer_size = 0; - if (se05x_key.IsLoaded()) - { - key_buffer_size = se05x_key.GetRawSize(); - key_buffer = new uint8_t[key_buffer_size]; - keypair = (mbedtls_ecp_keypair *)key.pk_ctx; - } - - int result = -ENOMEM; - if (key_buffer) - { - se05x_key.GetRaw(key_buffer); - result - = mbedtls_ecp_group_load(&keypair->grp, MBEDTLS_ECP_DP_SECP256R1); - } - - if (result == 0) - { - result = mbedtls_ecp_point_read_binary(&keypair->grp, &keypair->Q, - key_buffer, key_buffer_size); - } - - if (key_buffer) - { - delete[] key_buffer; - } - - return result; - } - - static int ecdsa_sign_wrap(mbedtls_pk_context *pk, mbedtls_md_type_t md_alg, - const unsigned char *hash, size_t hash_len, - unsigned char *sig, size_t sig_size, - size_t *sig_len, - int (*f_rng)(void *, unsigned char *, size_t), - void *p_rng) - { - - mbedtls_ecp_keypair *key = - reinterpret_cast<mbedtls_ecp_keypair *>(pk->pk_ctx); - auto se05x_ctx = reinterpret_cast<mbedtls_se05x_ctx *>(key->d.p); - - struct se05x_signature_s args - = { se05x_ctx->private_key_slot_id, - SE05X_ALGORITHM_SHA256, - { const_cast<uint8_t *>(hash), hash_len, hash_len }, - { sig, sig_size, sig_size } }; - auto result = se05x_ctx->se->CreateSignature(args); - - if (result) - { - *sig_len = args.signature.buffer_content_size; - } - - return result ? 0 : -EPERM; - } - - // return value is allocated ptr to mbedtls_pk_info_t (need to be deleted) - // otherwise nulltpr - static mbedtls_pk_info_t *CreatePkInfoSe05x() - { - auto info = mbedtls_pk_info_from_type(MBEDTLS_PK_ECKEY); - auto se05x_ec_info = new mbedtls_pk_info_t; - if (se05x_ec_info) - { - *se05x_ec_info = *info; - se05x_ec_info->sign_func = ecdsa_sign_wrap; - } - return se05x_ec_info; - } - - static int mbedtls_pk_setup_key_se05x(mbedtls_pk_context &key, - const ISecureElement &se, - uint32_t key_slot_id) - { - auto se05x_ec_info = CreatePkInfoSe05x(); - if (se05x_ec_info) - { - key.pk_info = se05x_ec_info; - key.pk_ctx = se05x_ec_info->ctx_alloc_func(); - } - - int result = -ENOMEM; - if (key.pk_ctx) - { - auto se05x_key = CPublicKey(se, key_slot_id); - result = mbedtls_pk_parse_se05x_public_key(key, se05x_key); - } - - mbedtls_se05x_ctx *se05x_ctx = nullptr; - if (result == 0) - { - se05x_ctx = new mbedtls_se05x_ctx; - result = se05x_ctx ? 0 : -ENOMEM; - } - - if (result == 0) - { - se05x_ctx->private_key_slot_id = key_slot_id; - se05x_ctx->se = &se; - } - - ((mbedtls_ecp_keypair *)key.pk_ctx)->d.p - = reinterpret_cast<mbedtls_mpi_uint *>(se05x_ctx); - return result; - } - - static void mbedtls_pk_free_se05x(mbedtls_pk_context &key) - { - auto key_ctx = reinterpret_cast<mbedtls_ecp_keypair *>(key.pk_ctx); - if (key_ctx) - { - auto se05x_ctx = reinterpret_cast<mbedtls_se05x_ctx *>(key_ctx->d.p); - if (se05x_ctx) - { - delete se05x_ctx; - key_ctx->d.p = nullptr; - } - } - auto pk_info = key.pk_info; - if (pk_info) - { - mbedtls_pk_free(&key); - delete pk_info; - } - } -}; -} // namespace Controlse diff --git a/crypto/controlse/controlse_main.cxx b/crypto/controlse/controlse_main.cxx deleted file mode 100644 index a2b5dddef..000000000 --- a/crypto/controlse/controlse_main.cxx +++ /dev/null @@ -1,717 +0,0 @@ -//*************************************************************************** -// apps/crypto/controlse/controlse_main.cxx -// -// SPDX-License-Identifier: Apache-2.0 -// -// Licensed to the Apache Software Foundation (ASF) under one or more -// contributor license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright ownership. The -// ASF licenses this file to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance with the -// License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -// License for the specific language governing permissions and limitations -// under the License. -// -//************************************************************************** - -// Copyright 2023, 2024 NXP - -//*************************************************************************** -// Included Files -//*************************************************************************** - -#include "crypto/controlse/ccertificate.hxx" -#include "crypto/controlse/ccsr.hxx" -#include "crypto/controlse/chex_util.hxx" -#include "crypto/controlse/cpublic_key.hxx" -#include "crypto/controlse/csecure_element.hxx" -#include "crypto/controlse/cstring.hxx" -#include <errno.h> -#include <fcntl.h> -#include <libgen.h> -#include <nuttx/config.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <sys/ioctl.h> -#include <unistd.h> - -#ifdef CONFIG_STACK_COLORATION -#include <nuttx/arch.h> -#include <nuttx/sched.h> -#endif - -//*************************************************************************** -// Pre-processor Definitions -//************************************************************************** - -#define EOT 0x04 - -#define DEFAULT_SETTINGS \ - { \ - .se05x_dev_filename = default_se05x_device, 0 \ - } - -#define TBS_HASH_BUFFER_SIZE 32 -#define SIGNATURE_BUFFER_SIZE 300 -#define SYMM_KEY_BUFFER_SIZE 300 -#define RAW_KEY_BUFFER_SIZE 600 -#define DEFAULT_BUFFER_SIZE 1000 - -//*************************************************************************** -// Private Types -//************************************************************************** - -typedef enum -{ - KEYSTORE_NO_ACTION = 0, - KEYSTORE_READ, - KEYSTORE_WRITE, - KEYSTORE_GENERATE, - KEYSTORE_DELETE, - KEYSTORE_DERIVE_SYMM_KEY, - KEYSTORE_CREATE_SIGNATURE, - KEYSTORE_VERIFY_SIGNATURE, - KEYSTORE_SIGN_CSR, - KEYSTORE_VERIFY_CERTIFICATE, - KEYSTORE_GET_INFO, - KEYSTORE_GET_UID, -} EKeystoreOperation; - -typedef enum -{ - KEYSTORE_DATA_TYPE_KEY = 0, - KEYSTORE_DATA_TYPE_CERT_OR_CSR, - KEYSTORE_DATA_TYPE_STRING, -} EKeystoreDataType; - -struct SSettings -{ - FAR const char *se05x_dev_filename; - FAR char *input_filename; - FAR char *signature_filename; - bool skip_process; - EKeystoreOperation operation; - EKeystoreDataType data_type; - uint32_t key_id; - uint32_t private_key_id; - bool show_stack_used; -}; - -//*************************************************************************** -// Private Function Prototypes -//************************************************************************** - -extern "C" int main(int argc, FAR char *argv[]); - -//*************************************************************************** -// Private Data -//************************************************************************** - -static const char default_se05x_device[] = "/dev/se05x"; -static const char enter_key_hex[] = "enter key(hex)"; -static const char enter_data_pem[] = "enter data(pem)"; -static const char enter_data_raw[] = "enter data(raw)"; - -//*************************************************************************** -// Public Data -//************************************************************************** - -//*************************************************************************** -// Private Functions -//************************************************************************** - -static void printUsage(FAR FILE *f, FAR char *prg) -{ - fprintf(f, "%s - Control SE05x Secure Element\n", prg); - fprintf(f, "\nUsage: %s [options] <secure element device>\n", prg); - fprintf(f, "Options:\n"); - fprintf(f, " -r <id> (read item from keystore at <id>)\n"); - fprintf(f, " -w <id> (set item in keystore at <id>)\n"); - fprintf(f, " -g <id> (generate keypair at <id>)\n"); - fprintf(f, " -d <id> (delete key at <id>)\n"); - fprintf(f, " -s <id> (create signature for data\n"); - fprintf(f, " with key at <id>)\n"); - fprintf(f, " -S <id> (Sign CSR with key at <id>)\n"); - fprintf(f, " -v <id> (verify signature for data\n"); - fprintf(f, " with key at <id>)\n"); - fprintf(f, " -V <id> (verify CRT with key at <id>\n"); - fprintf(f, " -a <id> (derive symm key\n"); - fprintf(f, " from public key <id>\n"); - fprintf(f, " and private key)\n"); - fprintf(f, " -t (interface using raw data\n"); - fprintf(f, " use with -r, -w)\n"); - fprintf(f, " -c (interface with PEM format\n"); - fprintf(f, " internally using DER\n"); - fprintf(f, " use with -r, -w)\n"); - fprintf(f, " -p <id> (select private key\n"); - fprintf(f, " use with -a)\n"); - fprintf(f, " -n <file> (Read input from file)\n"); - fprintf(f, " -N <file> (Read signature from file)\n"); - fprintf(f, " -i (show generic information)\n"); - fprintf(f, " -u (show UID)\n"); - fprintf(f, " -m (show used stack memory space)\n"); - fprintf(f, " -h (show this help)\n"); - fprintf(f, "\n"); -} - -static int setOperation(FAR struct SSettings *settings, - EKeystoreOperation operation, FAR char *key_id_text) -{ - int result = -EPERM; - if (settings->operation == KEYSTORE_NO_ACTION) - { - settings->operation = operation; - settings->key_id = 0; - if (key_id_text != NULL) - { - settings->key_id = (uint32_t)strtoul(key_id_text, NULL, 0); - } - - result = 0; - } - - return result; -} - -static int parseArguments(int argc, FAR char *argv[], - FAR struct SSettings *settings) -{ - int result = 0; - int opt; - FAR char *prg = basename(argv[0]); - while (((opt = getopt(argc, argv, "iug:w:r:d:s:v:S:V:tca:p:n:N:mh")) != -1) - && (result == 0)) - { - switch (opt) - { - case 'i': - result = setOperation(settings, KEYSTORE_GET_INFO, optarg); - break; - case 'u': - result = setOperation(settings, KEYSTORE_GET_UID, optarg); - break; - case 'g': - result = setOperation(settings, KEYSTORE_GENERATE, optarg); - break; - case 'r': - result = setOperation(settings, KEYSTORE_READ, optarg); - break; - case 'w': - result = setOperation(settings, KEYSTORE_WRITE, optarg); - break; - case 't': - settings->data_type = KEYSTORE_DATA_TYPE_STRING; - break; - case 'c': - settings->data_type = KEYSTORE_DATA_TYPE_CERT_OR_CSR; - break; - case 'd': - result = setOperation(settings, KEYSTORE_DELETE, optarg); - break; - case 's': - result = setOperation(settings, KEYSTORE_CREATE_SIGNATURE, optarg); - break; - case 'v': - result = setOperation(settings, KEYSTORE_VERIFY_SIGNATURE, optarg); - break; - case 'S': - result = setOperation(settings, KEYSTORE_SIGN_CSR, optarg); - break; - case 'V': - result = setOperation(settings, KEYSTORE_VERIFY_CERTIFICATE, optarg); - break; - case 'a': - result = setOperation(settings, KEYSTORE_DERIVE_SYMM_KEY, optarg); - break; - case 'p': - settings->private_key_id = (uint32_t)strtoul(optarg, NULL, 0); - break; - case 'n': - settings->input_filename = optarg; - break; - case 'N': - settings->signature_filename = optarg; - break; - case 'm': - settings->show_stack_used = TRUE; - break; - case 'h': - printUsage(stdout, prg); - settings->skip_process = TRUE; - break; - default: - printUsage(stderr, prg); - result = -EINVAL; - break; - } - } - - if ((result == 0) && (!settings->skip_process)) - { - if (settings->operation == KEYSTORE_NO_ACTION) - { - printUsage(stderr, prg); - result = -EINVAL; - } - - // if device is specified as positional argument - - if (optind != argc) - { - settings->se05x_dev_filename = argv[optind]; - } - } - - return result; -} - -// TODO: use chexutil -static int convert_array_hex_to_bin(FAR char *hex_buffer, - size_t hex_buffer_size, - FAR uint8_t *bin_buffer, - size_t bin_buffer_size, - FAR size_t *bin_buffer_content_size) -{ - hex_buffer_size = strcspn(hex_buffer, " \r\n"); - if (hex_buffer_size & 1) - { - return -1; - } - - *bin_buffer_content_size = 0; - size_t hex_buffer_pos; - for (hex_buffer_pos = 0; (hex_buffer_pos < hex_buffer_size) - && (*bin_buffer_content_size < bin_buffer_size); - hex_buffer_pos += 2) - { - sscanf(&hex_buffer[hex_buffer_pos], "%2hhx", - &bin_buffer[*bin_buffer_content_size]); - (*bin_buffer_content_size)++; - } - - return hex_buffer_pos == hex_buffer_size ? 0 : -1; -} - -static int readFromFile(FAR const char *prompt, FAR char *filename, - FAR char *buffer, size_t buffer_size) -{ - FAR FILE *f = stdin; - if (filename != NULL) - { - f = fopen(filename, "r"); - } - else - { - puts(prompt); - } - - size_t buffer_content_size = 0; - if (f != NULL) - { - FAR char *c = buffer; - int result = fgetc(f); - // keep looping until EOF or EOT are received or the buffer has only 1 - // space left (needed for the zero termination character) - while ((result != EOF) && (result != EOT) - && ((buffer_content_size + 1) < buffer_size)) - { - *c = result & 0xff; - c++; - buffer_content_size++; - result = fgetc(f); - } - // Add zero termination character - *c = 0; - buffer_content_size++; - } - - puts("\n"); - - if (filename != NULL) - { - fclose(f); - } - - return buffer_content_size; -} - -static int readFromFileAndConvert(FAR const char *prompt, FAR char *filename, - FAR uint8_t *buffer, size_t buffer_size, - FAR size_t *buffer_content_size) -{ - char file_buffer[DEFAULT_BUFFER_SIZE]; - size_t file_buffer_content_size; - int result; - - file_buffer_content_size = readFromFile( - prompt, filename, (FAR char *)file_buffer, sizeof(file_buffer)); - result = convert_array_hex_to_bin(file_buffer, file_buffer_content_size, - buffer, buffer_size, buffer_content_size); - - return result; -} - -static size_t addZeroTerminationCharacter(char *data, size_t content_size, - size_t buf_size) -{ - size_t zero_termination_char_position = content_size - 1; - if ((content_size + 1) <= buf_size) - { - zero_termination_char_position = content_size; - content_size++; - } - - data[zero_termination_char_position] = 0; - return content_size; -} - -static int process(int se05x_fd, FAR struct SSettings *settings) -{ - int result = 0; - Controlse::CSecureElement se(se05x_fd); - if (settings->operation == KEYSTORE_GET_INFO) - { - struct se05x_info_s info; - result = se.GetInfo(info) ? 0 : -EPERM; - - if (result == 0) - { - printf("OEF ID: %04x\n", info.oef_id); - } - } - else if (settings->operation == KEYSTORE_GET_UID) - { - struct se05x_uid_s uid; - result = se.GetUid(uid) ? 0 : -EPERM; - if (result == 0) - { - printf("UID: "); - for (size_t i = 0; i < SE05X_MODULE_UNIQUE_ID_LEN; i++) - { - printf("%02x", uid.uid[i]); - } - - printf("\n"); - } - } - else if (settings->operation == KEYSTORE_GENERATE) - { - struct se05x_generate_keypair_s args - = { .id = settings->key_id, - .cipher = SE05X_ASYM_CIPHER_EC_NIST_P_256 }; - - result = se.GenerateKey(args) ? 0 : -EPERM; - - if (result == 0) - { - printf("Keypair generated successfully\n"); - } - } - else if (settings->operation == KEYSTORE_WRITE) - { - char data[DEFAULT_BUFFER_SIZE]; - FAR const char *prompt = settings->data_type == KEYSTORE_DATA_TYPE_STRING - ? enter_data_raw - : enter_data_pem; - - size_t data_size - = readFromFile(prompt, settings->input_filename, data, sizeof(data)); - - result = -EINVAL; - if (data_size != 0) - { - Controlse::ISecureElementObject *object = nullptr; - if (settings->data_type == KEYSTORE_DATA_TYPE_STRING) - { - object = new Controlse::CString( - data, - data_size - 1); // -1 because no zero termination character - // required - } - else if (settings->data_type == KEYSTORE_DATA_TYPE_KEY) - { - object = new Controlse::CPublicKey(data); - } - else if (settings->data_type == KEYSTORE_DATA_TYPE_CERT_OR_CSR) - { - object = new Controlse::CCertificate( - reinterpret_cast<uint8_t *>(data), data_size); - if (object) - { - if (!object->IsLoaded()) - { - delete object; - object = new Controlse::CCsr( - reinterpret_cast<uint8_t *>(data), data_size); - } - } - } - - result = -EPERM; - if (object) - { - if (object->IsLoaded()) - { - result = object->StoreOnSecureElement(se, settings->key_id) - ? 0 - : -EPERM; - } - delete object; - } - } - - if (result == 0) - { - printf("Data stored successfully\n"); - } - } - else if (settings->operation == KEYSTORE_READ) - { - char *data = nullptr; - if (settings->data_type == KEYSTORE_DATA_TYPE_STRING) - { - Controlse::CString string(se, settings->key_id); - if (string.IsLoaded()) - { - data = string.c_str(); - } - } - else if (settings->data_type == KEYSTORE_DATA_TYPE_KEY) - { - Controlse::CPublicKey key(se, settings->key_id); - if (key.IsLoaded()) - { - data = key.GetPem(); - } - } - else if (settings->data_type == KEYSTORE_DATA_TYPE_CERT_OR_CSR) - { - Controlse::CCertificate cert(se, settings->key_id); - if (cert.IsLoaded()) - { - data = cert.GetPem(); - } - else - { - Controlse::CCsr csr(se, settings->key_id); - if (csr.IsLoaded()) - { - data = csr.GetPem(); - } - } - } - if (data) - { - puts(data); - delete[] data; - } - else - { - result = -EPERM; - } - } - else if (settings->operation == KEYSTORE_DELETE) - { - result = se.DeleteKey(settings->key_id) ? 0 : -EPERM; - if (result == 0) - { - printf("Deleted key successfully\n"); - } - } - else if (settings->operation == KEYSTORE_DERIVE_SYMM_KEY) - { - uint8_t buffer[SYMM_KEY_BUFFER_SIZE]; - struct se05x_derive_key_s args = { - .private_key_id = settings->private_key_id, - .public_key_id = settings->key_id, - .content = { .buffer = buffer, .buffer_size = sizeof(buffer) }, - }; - - result = se.DeriveSymmetricalKey(args) ? 0 : -EPERM; - - if (result == 0) - { - for (size_t i = 0; i < args.content.buffer_content_size; i++) - { - printf("%02x", args.content.buffer[i]); - } - printf("\n"); - } - } - else if (settings->operation == KEYSTORE_CREATE_SIGNATURE) - { - uint8_t tbs_buffer[TBS_HASH_BUFFER_SIZE]; - size_t tbs_content_size; - readFromFileAndConvert("Enter tbs(hex):", settings->input_filename, - tbs_buffer, sizeof(tbs_buffer), - &tbs_content_size); - uint8_t signature_buffer[SIGNATURE_BUFFER_SIZE]; - size_t signature_content_len = 0; - if (result == 0) - { - struct se05x_signature_s args = { - .key_id = settings->key_id, - .algorithm = SE05X_ALGORITHM_SHA256, - .tbs = { .buffer = tbs_buffer, - .buffer_size = tbs_content_size, - .buffer_content_size = tbs_content_size }, - .signature = { .buffer = signature_buffer, - .buffer_size = sizeof(signature_buffer) }, - }; - - result = se.CreateSignature(args) ? 0 : -EPERM; - signature_content_len = args.signature.buffer_content_size; - } - - if (result == 0) - { - for (size_t i = 0; i < signature_content_len; i++) - { - printf("%02x", signature_buffer[i]); - } - - printf("\n"); - } - } - else if (settings->operation == KEYSTORE_VERIFY_SIGNATURE) - { - uint8_t tbs_buffer[TBS_HASH_BUFFER_SIZE]; - size_t tbs_content_size; - result = readFromFileAndConvert( - "Enter tbs(hex):", settings->input_filename, tbs_buffer, - sizeof(tbs_buffer), &tbs_content_size); - - uint8_t signature_buffer[SIGNATURE_BUFFER_SIZE]; - size_t signature_content_size; - if (result == 0) - { - result = readFromFileAndConvert( - "Enter signature(hex):", settings->signature_filename, - signature_buffer, sizeof(signature_buffer), - &signature_content_size); - } - - if (result == 0) - { - struct se05x_signature_s args = { - .key_id = settings->key_id, - .algorithm = SE05X_ALGORITHM_SHA256, - .tbs = { .buffer = tbs_buffer, - .buffer_size = tbs_content_size, - .buffer_content_size = tbs_content_size }, - .signature = { .buffer = signature_buffer, - .buffer_size = signature_content_size, - .buffer_content_size = signature_content_size }, - }; - - result = se.Verify(args) ? 0 : -EPERM; - } - - if (result == 0) - { - printf("Signature verified successfully\n"); - } - } - else if (settings->operation == KEYSTORE_SIGN_CSR) - { - char csr_pem_buf[DEFAULT_BUFFER_SIZE]; - size_t csr_pem_buf_content_size - = readFromFile("enter csr(pem)", settings->input_filename, - csr_pem_buf, sizeof(csr_pem_buf)); - - csr_pem_buf_content_size = addZeroTerminationCharacter( - csr_pem_buf, csr_pem_buf_content_size, sizeof(csr_pem_buf)); - - auto certificate = Controlse::CCertificate( - se, reinterpret_cast<uint8_t *>(csr_pem_buf), - csr_pem_buf_content_size, settings->key_id); - - auto crt_pem = certificate.GetPem(); - if (crt_pem) - { - puts(crt_pem); - delete[] crt_pem; - } - else - { - result = -EPERM; - } - } - else if (settings->operation == KEYSTORE_VERIFY_CERTIFICATE) - { - char pem_buf[DEFAULT_BUFFER_SIZE]; - size_t pem_content_size - = readFromFile("enter crt(pem)", settings->input_filename, pem_buf, - sizeof(pem_buf)); - - pem_content_size = addZeroTerminationCharacter(pem_buf, pem_content_size, - sizeof(pem_buf)); - - auto certificate = Controlse::CCertificate( - reinterpret_cast<uint8_t *>(pem_buf), pem_content_size); - - result = certificate.VerifyAgainst(se, settings->key_id) ? 0 : -EPERM; - - if (result == 0) - { - printf("Signature verified successfully\n"); - } - } - - return result; -} - -//*************************************************************************** -// Public Functions -//************************************************************************** - -int main(int argc, FAR char *argv[]) -{ - struct SSettings settings = DEFAULT_SETTINGS; - int result = parseArguments(argc, argv, &settings); - - if ((result == 0) && (!settings.skip_process)) - { - int fd = open(settings.se05x_dev_filename, O_RDONLY); - if (fd == -1) - { - result = -ENODEV; - } - else - { - result = process(fd, &settings); - close(fd); - } - } - - if (result != 0) - { - fprintf(stderr, "err %i: %s\n", -result, strerror(-result)); - } - - if (settings.show_stack_used) - { -#ifdef CONFIG_STACK_COLORATION - FAR struct tcb_s *tcb; - tcb = nxsched_get_tcb(getpid()); - if (tcb != NULL) - { - fprintf(stderr, "\nStack used: %zu / %zu\n", up_check_tcbstack(tcb), - tcb->adj_stack_size); - nxsched_put_tcb(tcb); - } -#else - fprintf(stderr, "\nStack used: unknown" - " (STACK_COLORATION must be enabled)\n"); -#endif - } - - return result == 0 ? EXIT_SUCCESS : EXIT_FAILURE; -} diff --git a/crypto/controlse/cpublic_key.cxx b/crypto/controlse/cpublic_key.cxx deleted file mode 100644 index 097ef3270..000000000 --- a/crypto/controlse/cpublic_key.cxx +++ /dev/null @@ -1,245 +0,0 @@ -//*************************************************************************** -// apps/crypto/controlse/cpublic_key.cxx -// -// SPDX-License-Identifier: Apache-2.0 -// -// Licensed to the Apache Software Foundation (ASF) under one or more -// contributor license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright ownership. The -// ASF licenses this file to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance with the -// License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -// License for the specific language governing permissions and limitations -// under the License. -// -//************************************************************************** - -// Copyright 2024 NXP - -//*************************************************************************** -// Included Files -//*************************************************************************** - -#define MBEDTLS_ALLOW_PRIVATE_ACCESS -#include "crypto/controlse/cpublic_key.hxx" -#include "crypto/controlse/isecure_element.hxx" -#include "crypto/controlse/isecure_element_object.hxx" -#include <errno.h> -#include <mbedtls/pk.h> -#include <string.h> - -namespace Controlse -{ - -//*************************************************************************** -// Class Method Implementations -//*************************************************************************** - -CPublicKey::CPublicKey(const ISecureElement &se, uint32_t keystore_id) -{ - (void)LoadFromSecureElement(se, keystore_id); -} - -CPublicKey::CPublicKey(const char *pem) -{ - uint8_t key_buf[300]; - m_key = nullptr; - if (0 - == convert_public_key_pem_to_raw(key_buf, sizeof(key_buf), &m_size, pem)) - { - m_key = new uint8_t[m_size]; - memcpy(m_key, key_buf, m_size); - } -} - -CPublicKey::CPublicKey(const uint8_t *buffer, size_t buffer_size) - : m_key(new uint8_t[buffer_size]), m_size(buffer_size) -{ - memcpy(m_key, buffer, m_size); -} - -CPublicKey::CPublicKey(const CPublicKey &p1) : CPublicKey(p1.m_key, p1.m_size) -{ -} - -CPublicKey::~CPublicKey() { Unload(); } - -CPublicKey &CPublicKey::operator=(const CPublicKey &other) -{ - if (this != &other) - { - auto new_key = new uint8_t[other.m_size]; - memcpy(new_key, other.m_key, other.m_size); - - delete[] m_key; - - m_key = new_key; - m_size = other.m_size; - } - return *this; -} - -void CPublicKey::Unload() -{ - if (IsLoaded()) - { - delete[] m_key; - m_key = NULL; - m_size = 0; - } -} - -bool CPublicKey::IsLoaded() const { return m_key != NULL; } - -bool CPublicKey::StoreOnSecureElement(const ISecureElement &se, - uint32_t keystore_id) const -{ - if (!IsLoaded()) - { - return false; - } - - struct se05x_key_transmission_s args = { - .entry = { .id = keystore_id, .cipher = SE05X_ASYM_CIPHER_EC_NIST_P_256 }, - .content - = { .buffer = m_key, .buffer_size = m_size, .buffer_content_size = m_size } - }; - return se.SetKey(args); -} - -bool CPublicKey::LoadFromSecureElement(const ISecureElement &se, - uint32_t keystore_id) -{ - Unload(); - - m_size = 100; - m_key = new uint8_t[m_size]; - struct se05x_key_transmission_s args = { - .entry = { .id = keystore_id, .cipher = SE05X_ASYM_CIPHER_EC_NIST_P_256 }, - .content - = { .buffer = m_key, .buffer_size = m_size, .buffer_content_size = m_size } - }; - - bool result = se.GetKey(args); - - m_size = args.content.buffer_content_size; - if (!result) - { - Unload(); - } - - return result; -} - -bool CPublicKey::operator==(const CPublicKey &a) const -{ - if (this->m_size != a.m_size) - { - return false; - } - return 0 == memcmp(this->m_key, a.m_key, m_size); -} - -bool CPublicKey::operator!=(const CPublicKey &a) const -{ - return !operator==(a); -} - -size_t CPublicKey::GetRawSize() const { return m_size; } - -void CPublicKey::GetRaw(uint8_t *raw_buffer) const -{ - memcpy(raw_buffer, m_key, m_size); -} - -char *CPublicKey::GetPem() const -{ - char pem_buf[500]; - auto res - = convert_public_key_raw_to_pem(pem_buf, sizeof(pem_buf), m_key, m_size); - if (res < 0) - { - return nullptr; - } - auto pem_size = strlen(pem_buf); - auto pem = new char[pem_size + 1]; - memcpy(pem, pem_buf, pem_size); - pem[pem_size] = 0; - return pem; -} - -int CPublicKey::convert_public_key_raw_to_pem(char *pem_buf, - size_t pem_buf_size, - const uint8_t *key_buf, - size_t key_buf_size) -{ - mbedtls_pk_context key = { 0 }; - - mbedtls_pk_init(&key); - const mbedtls_pk_info_t *info = mbedtls_pk_info_from_type(MBEDTLS_PK_ECKEY); - - int result = -1; - if (info != NULL) - { - result = mbedtls_pk_setup(&key, info); - } - - mbedtls_ecp_keypair *keypair = (mbedtls_ecp_keypair *)key.pk_ctx; - if (result == 0) - { - result = mbedtls_ecp_group_load(&keypair->grp, MBEDTLS_ECP_DP_SECP256R1); - } - - if (result == 0) - { - result = mbedtls_ecp_point_read_binary(&keypair->grp, &keypair->Q, - key_buf, key_buf_size); - } - - if (result == 0) - { - result = mbedtls_pk_write_pubkey_pem(&key, (uint8_t *)pem_buf, - pem_buf_size); - } - - mbedtls_pk_free(&key); - return result < 0 ? -EINVAL : 0; -} - -int CPublicKey::convert_public_key_pem_to_raw(uint8_t *key_buf, - size_t key_buf_size, - size_t *key_size, - const char *pem_buf) -{ - int result = -1; - mbedtls_pk_context key = { 0 }; - - mbedtls_pk_init(&key); - - result = mbedtls_pk_parse_public_key(&key, (uint8_t *)pem_buf, - strlen(pem_buf) + 1); - - if (result == 0) - { - result = mbedtls_pk_can_do(&key, MBEDTLS_PK_ECKEY) == 1 ? 0 : -1; - } - - if (result == 0) - { - mbedtls_ecp_keypair *keypair = (mbedtls_ecp_keypair *)key.pk_ctx; - result = mbedtls_ecp_point_write_binary(&keypair->grp, &keypair->Q, - MBEDTLS_ECP_PF_UNCOMPRESSED, - key_size, key_buf, key_buf_size); - } - - mbedtls_pk_free(&key); - return result < 0 ? -EINVAL : 0; -} - -} // namespace Controlse diff --git a/crypto/controlse/csan_builder.cxx b/crypto/controlse/csan_builder.cxx deleted file mode 100644 index b25a4e5d2..000000000 --- a/crypto/controlse/csan_builder.cxx +++ /dev/null @@ -1,126 +0,0 @@ -//*************************************************************************** -// apps/crypto/controlse/csan_builder.cxx -// -// SPDX-License-Identifier: Apache-2.0 -// -// Licensed to the Apache Software Foundation (ASF) under one or more -// contributor license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright ownership. The -// ASF licenses this file to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance with the -// License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -// License for the specific language governing permissions and limitations -// under the License. -// -//************************************************************************** - -// Copyright 2024 NXP - -//*************************************************************************** -// Included Files -//*************************************************************************** - -#include "crypto/controlse/csan_builder.hxx" -#include "mbedtls/asn1write.h" -#include <cstring> - -namespace Controlse -{ - -//*************************************************************************** -// Class Method Implementations -//*************************************************************************** - -CSanBuilder::~CSanBuilder() -{ - while (entry != nullptr) - { - delete[] entry->p; - auto next_entry = entry->next; - delete entry; - entry = next_entry; - } -} - -CSanBuilder *CSanBuilder::AddSan(uint8_t type, const char *value, - size_t value_size) -{ - auto old_entry = entry; - entry = new List(); - if (entry) - { - entry->type = type; - entry->p = new char[value_size]; - if (entry->p) - { - memcpy(entry->p, value, value_size); - entry->size = value_size; - entry->next = old_entry; - total_size += value_size; - total_size += 2; - } - else - { - delete entry; - } - } - return this; -} - -//* -// result: pointer to dynamically allocated san (to be deleted with delete[]) -// or error when size == 0 -/// -size_t CSanBuilder::Build(uint8_t **san) -{ - if (!entry) - { - return 0; - } - - const size_t reservation_for_additional_length_bytes = 8; - const size_t buffer_size - = total_size + reservation_for_additional_length_bytes; - auto *buffer = new uint8_t[buffer_size]; - auto current = entry; - const unsigned char *start = buffer; - unsigned char *p = buffer + buffer_size; - int ret = 0; - size_t len = 0; - while (current) - { - ret = mbedtls_asn1_write_tagged_string(&p, start, current->type, - current->p, current->size); - current = current->next; - } - - MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_len(&p, start, total_size)); - MBEDTLS_ASN1_CHK_ADD( - len, mbedtls_asn1_write_tag( - &p, start, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)); - - *san = new uint8_t[total_size + len]; - memcpy(*san, p, total_size + len); - delete[] buffer; - return total_size + len; -} - -uint32_t CSanBuilder::GetNumberOfSan() -{ - auto e = entry; - uint32_t amount = 0; - while (e != nullptr) - { - e = e->next; - amount++; - } - return amount; -} - -} diff --git a/crypto/controlse/csecure_element.cxx b/crypto/controlse/csecure_element.cxx deleted file mode 100644 index cacdd0edd..000000000 --- a/crypto/controlse/csecure_element.cxx +++ /dev/null @@ -1,191 +0,0 @@ -//*************************************************************************** -// apps/crypto/controlse/csecure_element.cxx -// -// SPDX-License-Identifier: Apache-2.0 -// -// Licensed to the Apache Software Foundation (ASF) under one or more -// contributor license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright ownership. The -// ASF licenses this file to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance with the -// License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -// License for the specific language governing permissions and limitations -// under the License. -// -//************************************************************************** - -// Copyright 2024 NXP - -//*************************************************************************** -// Included Files -//*************************************************************************** - -#include "crypto/controlse/csecure_element.hxx" - -#include "crypto/controlse/ccertificate.hxx" -#include "crypto/controlse/cpublic_key.hxx" -#include <fcntl.h> -#include <libgen.h> -#include <stdio.h> -#include <sys/ioctl.h> -#include <unistd.h> -extern "C" -{ -#include <nuttx/crypto/se05x.h> -} - -namespace Controlse -{ - -//*************************************************************************** -// Class Method Implementations -//*************************************************************************** - -CSecureElement::CSecureElement(const char *se05x_device) - : se05x_fd(open(se05x_device, O_RDONLY)), close_device_at_destructor(true) -{ -} - -CSecureElement::CSecureElement(int fd) - : se05x_fd(fd), close_device_at_destructor(false) -{ -} - -CSecureElement::~CSecureElement() -{ - if ((se05x_fd >= 0) && close_device_at_destructor) - { - close(se05x_fd); - } -} - -bool CSecureElement::IsReady() const { return se05x_fd >= 0; } - -bool CSecureElement::GenerateKey(struct se05x_generate_keypair_s &args) const -{ - bool result = false; - if (se05x_fd >= 0) - { - result = 0 == ioctl(se05x_fd, SEIOC_GENERATE_KEYPAIR, &args); - } - return result; -} - -bool CSecureElement::SetKey(struct se05x_key_transmission_s &args) const -{ - bool result = false; - if (se05x_fd >= 0) - { - result = 0 == ioctl(se05x_fd, SEIOC_SET_KEY, &args); - } - return result; -} - -bool CSecureElement::GetKey(struct se05x_key_transmission_s &args) const -{ - bool result = false; - if (se05x_fd >= 0) - { - result = 0 == ioctl(se05x_fd, SEIOC_GET_KEY, &args); - } - return result; -} - -bool CSecureElement::DeleteKey(uint32_t id) const -{ - bool result = false; - if (se05x_fd >= 0) - { - result = 0 == ioctl(se05x_fd, SEIOC_DELETE_KEY, id); - } - return result; -} - -bool CSecureElement::SetData(struct se05x_key_transmission_s &args) const -{ - bool result = false; - if (se05x_fd >= 0) - { - result = 0 == ioctl(se05x_fd, SEIOC_SET_DATA, &args); - } - return result; -} - -bool CSecureElement::GetData(struct se05x_key_transmission_s &args) const -{ - bool result = false; - if (se05x_fd >= 0) - { - result = 0 == ioctl(se05x_fd, SEIOC_GET_DATA, &args); - } - return result; -} - -bool CSecureElement::CreateSignature(struct se05x_signature_s &args) const -{ - bool result = false; - if (se05x_fd >= 0) - { - result = 0 == ioctl(se05x_fd, SEIOC_CREATE_SIGNATURE, &args); - } - return result; -} - -bool CSecureElement::Verify(struct se05x_signature_s &args) const -{ - bool result = false; - if (se05x_fd >= 0) - { - result = 0 == ioctl(se05x_fd, SEIOC_VERIFY_SIGNATURE, &args); - } - return result; -} - -bool CSecureElement::DeriveSymmetricalKey( - struct se05x_derive_key_s &args) const -{ - bool result = false; - if (se05x_fd >= 0) - { - result = 0 == ioctl(se05x_fd, SEIOC_DERIVE_SYMM_KEY, &args); - } - return result; -} - -bool CSecureElement::GetUid(struct se05x_uid_s &args) const -{ - bool result = false; - if (se05x_fd >= 0) - { - result = 0 == ioctl(se05x_fd, SEIOC_GET_UID, &args); - } - return result; -} - -bool CSecureElement::GetInfo(struct se05x_info_s &args) const -{ - bool result = false; - if (se05x_fd >= 0) - { - result = 0 == ioctl(se05x_fd, SEIOC_GET_INFO, &args); - } - return result; -} - -CCertificate *CSecureElement::GetCertificate(uint32_t keystore_id) -{ - return new CCertificate(*this, keystore_id); -} - -CPublicKey *CSecureElement::GetPublicKey(uint32_t keystore_id) -{ - return new CPublicKey(*this, keystore_id); -} - -} // namespace Controlse diff --git a/crypto/controlse/cserial_number.cxx b/crypto/controlse/cserial_number.cxx deleted file mode 100644 index 219689dab..000000000 --- a/crypto/controlse/cserial_number.cxx +++ /dev/null @@ -1,96 +0,0 @@ -//*************************************************************************** -// apps/crypto/controlse/cserial_number.cxx -// -// SPDX-License-Identifier: Apache-2.0 -// -// Licensed to the Apache Software Foundation (ASF) under one or more -// contributor license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright ownership. The -// ASF licenses this file to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance with the -// License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -// License for the specific language governing permissions and limitations -// under the License. -// -//************************************************************************** - -// Copyright 2024 NXP - -//*************************************************************************** -// Included Files -//*************************************************************************** - -#include "crypto/controlse/cserial_number.hxx" -#include "crypto/controlse/isecure_element.hxx" -#include <string.h> - -namespace Controlse -{ -constexpr size_t CSerialNumber::SERIAL_NUMBER_SIZE; - -//*************************************************************************** -// Class Method Implementations -//*************************************************************************** - -CSerialNumber::CSerialNumber(const ISecureElement &se, uint32_t keystore_id) -{ - is_loaded = LoadFromSecureElement(se, keystore_id); -} - -CSerialNumber::CSerialNumber(uint8_t const *serial_number_byte_array) -{ - memcpy(serial_number, serial_number_byte_array, SERIAL_NUMBER_SIZE); - is_loaded = true; -} - -bool CSerialNumber::operator==(CSerialNumber &a) const -{ - return 0 == (memcmp(a.serial_number, serial_number, SERIAL_NUMBER_SIZE)); -} - -bool CSerialNumber::operator!=(CSerialNumber &a) const -{ - return !operator==(a); -} - -bool CSerialNumber::operator<(const CSerialNumber &a) const -{ - return 0 < (memcmp(a.serial_number, serial_number, SERIAL_NUMBER_SIZE)); -} - -bool CSerialNumber::IsLoaded() const { return is_loaded; } - -bool CSerialNumber::GetSerialNumber( - uint8_t serial_number_destination[SERIAL_NUMBER_SIZE]) const -{ - if (!is_loaded) - { - return false; - } - - memcpy(serial_number_destination, serial_number, SERIAL_NUMBER_SIZE); - return true; -} - -bool CSerialNumber::StoreOnSecureElement(const ISecureElement &se, - uint32_t keystore_id) const -{ - return false; -} - -bool CSerialNumber::LoadFromSecureElement(const ISecureElement &se, - uint32_t keystore_id) -{ - struct se05x_key_transmission_s args - = { .entry = { .id = keystore_id }, - .content - = { .buffer = serial_number, .buffer_size = SERIAL_NUMBER_SIZE } }; - return se.GetData(args); -} -} // namespace Controlse diff --git a/crypto/controlse/cstring.cxx b/crypto/controlse/cstring.cxx deleted file mode 100644 index dc2e9000c..000000000 --- a/crypto/controlse/cstring.cxx +++ /dev/null @@ -1,143 +0,0 @@ -//*************************************************************************** -// apps/crypto/controlse/cstring.cxx -// -// SPDX-License-Identifier: Apache-2.0 -// -// Licensed to the Apache Software Foundation (ASF) under one or more -// contributor license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright ownership. The -// ASF licenses this file to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance with the -// License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -// License for the specific language governing permissions and limitations -// under the License. -// -//************************************************************************** - -// Copyright 2024 NXP - -//*************************************************************************** -// Included Files -//*************************************************************************** - -#include "crypto/controlse/cstring.hxx" -#include "crypto/controlse/csecure_element.hxx" -#include <cstring> - -namespace Controlse -{ - -//*************************************************************************** -// Class Method Implementations -//*************************************************************************** - -CString::CString(const ISecureElement &se, uint32_t keystore_id) -{ - (void)LoadFromSecureElement(se, keystore_id); -} - -CString::CString(char *string, size_t size) : m_size(size) -{ - m_string = new char[m_size]; - memcpy(m_string, string, m_size); -} - -CString::CString(const CString &p1) : CString(p1.m_string, p1.m_size) {} - -CString::~CString() -{ - if (m_string != nullptr) - { - delete[] m_string; - m_size = 0; - } -} - -CString &CString::operator=(const CString &other) -{ - if (this != &other) - { - auto new_string = new char[other.m_size]; - memcpy(new_string, other.m_string, other.m_size); - - delete[] m_string; - - m_string = new_string; - m_size = other.m_size; - } - return *this; -} - -bool CString::operator==(CString &a) const -{ - if (a.m_size != m_size) - { - return false; - } - return 0 == (memcmp(a.m_string, m_string, m_size)); -} - -bool CString::operator!=(CString &a) const { return !operator==(a); } - -char *CString::c_str(void) const -{ - char *c_str = nullptr; - if (IsLoaded() && (m_size > 0)) - { - bool add_termination_character = false; - if (m_string[m_size - 1] != 0) - { - add_termination_character = true; - } - c_str = new char[m_size + (add_termination_character ? 1 : 0)]; - memcpy(c_str, m_string, m_size); - if (add_termination_character) - { - c_str[m_size] = 0; - } - } - return c_str; -} - -bool CString::IsLoaded() const { return m_string != nullptr; } - -bool CString::StoreOnSecureElement(const ISecureElement &se, - uint32_t keystore_id) const -{ - auto result = false; - if (IsLoaded()) - { - struct se05x_key_transmission_s args - = { .entry = { .id = keystore_id }, - .content = { .buffer = reinterpret_cast<uint8_t *>(m_string), - .buffer_size = m_size } }; - result = se.SetData(args); - } - return result; -} - -bool CString::LoadFromSecureElement(const ISecureElement &se, - uint32_t keystore_id) -{ - uint8_t buffer[1000]; - struct se05x_key_transmission_s args - = { .entry = { .id = keystore_id }, - .content = { .buffer = buffer, .buffer_size = sizeof(buffer) } }; - auto result = se.GetData(args); - - if (result) - { - m_size = args.content.buffer_content_size; - m_string = new char[m_size + 1]; - memcpy(m_string, buffer, m_size); - m_string[m_size] = 0; - } - return result; -} -} // namespace Controlse diff --git a/crypto/libsodium/.gitignore b/crypto/libsodium/.gitignore deleted file mode 100644 index e58ac29c3..000000000 --- a/crypto/libsodium/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/libsodium -/*.zip diff --git a/crypto/libsodium/0001-fix-multiple-definition-bug-in-libsodium-test.patch b/crypto/libsodium/0001-fix-multiple-definition-bug-in-libsodium-test.patch deleted file mode 100644 index 4589c822a..000000000 --- a/crypto/libsodium/0001-fix-multiple-definition-bug-in-libsodium-test.patch +++ /dev/null @@ -1,37 +0,0 @@ -From a0d59e038db8eb305d449ccbfe05fec839c487ba Mon Sep 17 00:00:00 2001 -From: makejian <makejian@xiaomi.com> -Date: Mon, 3 Jul 2023 13:44:46 +0800 -Subject: [PATCH] fix multiple definition bug in libsodium test - -ld: /home/mina/work_profile/vela/nuttx/staging/libapps.a(pwhash_scrypt_ll.c.home.mina.work_profile.vela.apps.crypto.libsodium.o): in function `xmain': -/home/mina/work_profile/vela/apps/crypto/libsodium/libsodium/test/default/pwhash_scrypt_ll.c:53: multiple definition of `xmain'; /home/mina/work_profile/vela/nuttx/staging/libapps.a(scalarmult6.c.home.mina.work_profile.vela.apps.crypto.libsodium.o):/home/mina/work_profile/vela/apps/crypto/libsodium/libsodium/test/default/scalarmult6.c:19: first defined here -Change-Id: If818aa076fc51554a2232e63c01ddd5dc017f466 -Signed-off-by: makejian <makejian@xiaomi.com> ---- - test/default/cmptest.h | 4 ++-- - 1 file changed, 2 insertions(+), 2 deletions(-) - -diff --git libsodium/test/default/cmptest.h libsodium/test/default/cmptest.h -index 54a02070..86745f16 100644 ---- libsodium/test/default/cmptest.h -+++ libsodium/test/default/cmptest.h -@@ -33,7 +33,7 @@ - # define rand(X) arc4random(X) - #endif - --int xmain(void); -+static int xmain(void); - - static unsigned char *guard_page; - -@@ -233,6 +233,6 @@ int main(void) - - #endif - --#define main xmain -+#define main static xmain - - #endif --- -2.40.0 - diff --git a/crypto/libsodium/0002-fix-cannot-find-file-sodium-version.h.patch b/crypto/libsodium/0002-fix-cannot-find-file-sodium-version.h.patch deleted file mode 100644 index 46ca45dd7..000000000 --- a/crypto/libsodium/0002-fix-cannot-find-file-sodium-version.h.patch +++ /dev/null @@ -1,55 +0,0 @@ -From a98a4eb8b65bc4e84ea75a568b00f4662a2dd7f7 Mon Sep 17 00:00:00 2001 -From: makejian <makejian@xiaomi.com> -Date: Mon, 3 Jul 2023 14:30:06 +0800 -Subject: [PATCH] fix 'cannot find file sodium/version.h' - -version.h is generated from version.h.in in the original library -Change-Id: Ia96d0da80c3ba44243d4965c35b8c2961fc90a2c -Signed-off-by: makejian <makejian@xiaomi.com> ---- - src/libsodium/include/sodium/version.h | 33 ++++++++++++++++++++++++++ - 1 file changed, 33 insertions(+) - create mode 100644 src/libsodium/include/sodium/version.h - -diff --git libsodium/src/libsodium/include/sodium/version.h libsodium/src/libsodium/include/sodium/version.h -new file mode 100644 -index 00000000..e1f24c52 ---- /dev/null -+++ libsodium/src/libsodium/include/sodium/version.h -@@ -0,0 +1,33 @@ -+ -+#ifndef sodium_version_H -+#define sodium_version_H -+ -+#include "export.h" -+ -+#define SODIUM_VERSION_STRING "1.0.20" -+ -+#define SODIUM_LIBRARY_VERSION_MAJOR 26 -+#define SODIUM_LIBRARY_VERSION_MINOR 2 -+ -+ -+#ifdef __cplusplus -+extern "C" { -+#endif -+ -+SODIUM_EXPORT -+const char *sodium_version_string(void); -+ -+SODIUM_EXPORT -+int sodium_library_version_major(void); -+ -+SODIUM_EXPORT -+int sodium_library_version_minor(void); -+ -+SODIUM_EXPORT -+int sodium_library_minimal(void); -+ -+#ifdef __cplusplus -+} -+#endif -+ -+#endif --- -2.40.0 - diff --git a/crypto/libsodium/CMakeLists.txt b/crypto/libsodium/CMakeLists.txt deleted file mode 100644 index daf7b326b..000000000 --- a/crypto/libsodium/CMakeLists.txt +++ /dev/null @@ -1,118 +0,0 @@ -# ############################################################################## -# apps/crypto/libsodium/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_LIBSODIUM) - - # ############################################################################ - # Config and Fetch libsodium lib - # ############################################################################ - set(LIBSODIUM_DIR ${CMAKE_CURRENT_LIST_DIR}/libsodium) - - if(NOT EXISTS ${LIBSODIUM_DIR}) - set(LIBSODIUM_URL https://github.com/jedisct1/libsodium/archive) - - FetchContent_Declare( - libsodium_fetch - URL ${LIBSODIUM_URL}/${CONFIG_LIBSODIUM_VERSION}.zip SOURCE_DIR - ${CMAKE_CURRENT_LIST_DIR}/libsodium BINARY_DIR - ${CMAKE_BINARY_DIR}/apps/crypto/libsodium/libsodium - PATCH_COMMAND - patch -p1 -d ${CMAKE_CURRENT_LIST_DIR}/libsodium < - ${CMAKE_CURRENT_LIST_DIR}/0001-fix-multiple-definition-bug-in-libsodium-test.patch - && patch -p1 -d ${CMAKE_CURRENT_LIST_DIR}/libsodium < - ${CMAKE_CURRENT_LIST_DIR}/0002-fix-cannot-find-file-sodium-version.h.patch - DOWNLOAD_NO_PROGRESS true - TIMEOUT 30) - - FetchContent_GetProperties(libsodium_fetch) - - if(NOT libsodium_fetch_POPULATED) - FetchContent_Populate(libsodium_fetch) - endif() - endif() - - # ############################################################################ - # Flags - # ############################################################################ - - set(CFLAGS - -DDEV_MODE - -DCONFIGURED=1 - -Wno-unused-function - -Wno-undef - -Wno-unused-variable - -Wno-deprecated-declarations - -Wno-shadow) - - # ############################################################################ - # Sources - # ############################################################################ - - file(GLOB_RECURSE CSRCS ${LIBSODIUM_DIR}/src/libsodium/*.c) - - # ############################################################################ - # Include Directory - # ############################################################################ - - set(INCDIR ${LIBSODIUM_DIR}/src/libsodium/include - ${LIBSODIUM_DIR}/src/libsodium/include/sodium) - - # ############################################################################ - # Library Configuration - # ############################################################################ - - nuttx_add_library(libsodium STATIC) - - target_sources(libsodium PRIVATE ${CSRCS}) - target_include_directories(libsodium PRIVATE ${INCDIR}) - target_compile_options(libsodium PRIVATE ${CFLAGS}) - - # ############################################################################ - # Applications Configuration - # ############################################################################ - - if(CONFIG_LIBSODIUM_TEST) - file(GLOB TEST_CSRCS ${LIBSODIUM_DIR}/test/default/*.c) - list(APPEND INCDIR ${LIBSODIUM_DIR}/test/quirks) - - foreach(TEST_CSRC ${TEST_CSRCS}) - get_filename_component(TEST_PROG ${TEST_CSRC} NAME_WLE) - nuttx_add_application( - MODULE - ${CONFIG_LIBSODIUM_TEST} - NAME - ${TEST_PROG} - STACKSIZE - ${CONFIG_LIBSODIUM_TEST_STACKSIZE} - PRIORITY - ${CONFIG_LIBSODIUM_TEST_PRIORITY} - SRCS - ${TEST_CSRC} - COMPILE_FLAGS - ${CFLAGS} - INCLUDE_DIRECTORIES - ${INCDIR} - DEPENDS - libsodium) - endforeach() - endif() -endif() diff --git a/crypto/libsodium/Kconfig b/crypto/libsodium/Kconfig deleted file mode 100644 index df47ffce3..000000000 --- a/crypto/libsodium/Kconfig +++ /dev/null @@ -1,37 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -menuconfig LIBSODIUM - bool "Libsodium Cryptography Library" - default n - depends on ALLOW_ICS_COMPONENTS - ---help--- - Enable support for Libsodium. - -if LIBSODIUM - -config LIBSODIUM_VERSION - string "Libsodium Version" - default "1.0.18" - -config LIBSODIUM_TEST - tristate "Enable Libsodium test" - default n - ---help--- - Enable the Libsodium test. - -if LIBSODIUM_TEST - -config LIBSODIUM_TEST_PRIORITY - int "Libsodium test priority" - default 100 - -config LIBSODIUM_TEST_STACKSIZE - int "Libsodium test stack size" - default DEFAULT_TASK_STACKSIZE - -endif # LIBSODIUM_TEST - -endif # LIBSODIUM diff --git a/crypto/libsodium/Make.defs b/crypto/libsodium/Make.defs deleted file mode 100644 index acae50f13..000000000 --- a/crypto/libsodium/Make.defs +++ /dev/null @@ -1,27 +0,0 @@ -############################################################################ -# apps/crypto/libsodium/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_LIBSODIUM),) -CONFIGURED_APPS += $(APPDIR)/crypto/libsodium -CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/crypto/libsodium/libsodium/src/libsodium/include -CXXFLAGS += ${INCDIR_PREFIX}$(APPDIR)/crypto/libsodium/libsodium/src/libsodium/include -endif \ No newline at end of file diff --git a/crypto/libsodium/Makefile b/crypto/libsodium/Makefile deleted file mode 100644 index 2ad47c9dc..000000000 --- a/crypto/libsodium/Makefile +++ /dev/null @@ -1,71 +0,0 @@ -############################################################################ -# apps/crypto/libsodium/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -LIBSODIUM_VERSION = $(patsubst "%",%,$(strip $(CONFIG_LIBSODIUM_VERSION))) -LIBSODIUM_URL ?= "https://github.com/jedisct1/libsodium/releases/download/$(LIBSODIUM_VERSION)-RELEASE" - -LIBSODIUM_TARGZ = "libsodium-$(LIBSODIUM_VERSION).tar.gz" - -LIBSODIUM_UNPACKNAME = libsodium -UNPACK ?= tar -xaf - -LIBSODIUM_UNPACKLIBDIR = $(LIBSODIUM_UNPACKNAME)$(DELIM)src$(DELIM)$(LIBSODIUM_UNPACKNAME) -LIBSODIUM_UNPACKTESTDIR = $(LIBSODIUM_UNPACKNAME)$(DELIM)test$(DELIM)default - -CSRCS += $(shell if [ -d "$(LIBSODIUM_UNPACKLIBDIR)" ]; then find "$(LIBSODIUM_UNPACKLIBDIR)" -name "*.c"; fi) -CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/crypto/libsodium/libsodium/src/libsodium/include/sodium -CFLAGS += -DDEV_MODE -DCONFIGURED=1 -CFLAGS += -Wno-unused-function -Wno-undef -Wno-unused-variable -Wno-deprecated-declarations \ - -Wno-shadow - -ifneq ($(CONFIG_LIBSODIUM_TEST),) -MODULE = $(CONFIG_LIBSODIUM_TEST) -MAINSRC = $(wildcard $(LIBSODIUM_UNPACKTESTDIR)$(DELIM)*.c) -PROGNAME = $(patsubst $(LIBSODIUM_UNPACKTESTDIR)$(DELIM)%.c,%,$(MAINSRC)) -CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/crypto/libsodium/libsodium/test/quirks -PRIORITY = $(CONFIG_LIBSODIUM_TEST_PRIORITY) -STACKSIZE = $(CONFIG_LIBSODIUM_TEST_STACKSIZE) -endif - -$(LIBSODIUM_TARGZ): - @echo "Downloading: $(LIBSODIUM_URL)/$(LIBSODIUM_TARGZ)" - $(Q) $(call DOWNLOAD,$(LIBSODIUM_URL),$(LIBSODIUM_TARGZ)) - -$(LIBSODIUM_UNPACKNAME): $(LIBSODIUM_TARGZ) - @echo "Unpacking: $(LIBSODIUM_TARGZ) -> $(LIBSODIUM_UNPACKNAME)" - $(Q) $(UNPACK) $(LIBSODIUM_TARGZ) - $(Q) mv $(LIBSODIUM_UNPACKNAME)-$(LIBSODIUM_VERSION) $(LIBSODIUM_UNPACKNAME) - $(Q) echo "Patching $(LIBSODIUM_UNPACKNAME)" - $(Q) patch -p1 -d $(LIBSODIUM_UNPACKNAME) < 0001-fix-multiple-definition-bug-in-libsodium-test.patch - $(Q) patch -p1 -d $(LIBSODIUM_UNPACKNAME) < 0002-fix-cannot-find-file-sodium-version.h.patch - $(Q) touch $(LIBSODIUM_UNPACKNAME) - -ifeq ($(wildcard $(LIBSODIUM_UNPACKNAME)/.git),) -context:: $(LIBSODIUM_UNPACKNAME) - -distclean:: - $(Q) rm -rf $(LIBSODIUM_UNPACKNAME) -endif - -include $(APPDIR)/Application.mk diff --git a/crypto/libtomcrypt/CMakeLists.txt b/crypto/libtomcrypt/CMakeLists.txt deleted file mode 100644 index d3fb2a5dc..000000000 --- a/crypto/libtomcrypt/CMakeLists.txt +++ /dev/null @@ -1,531 +0,0 @@ -# ############################################################################## -# apps/crypto/libtomcrypt/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_CRYPTO_LIBTOMCRYPT) - - # ############################################################################ - # Config and Fetch libtomcrypt - # ############################################################################ - set(LIBTOMCRYPT_DIR ${CMAKE_CURRENT_LIST_DIR}/libtomcrypt) - - if(NOT EXISTS ${LIBTOMCRYPT_DIR}) - set(CONFIG_LIBTOMCRYPT_URL https://github.com/libtom/libtomcrypt/archive) - - FetchContent_Declare( - libtomcrypt_fetch - URL ${CONFIG_LIBTOMCRYPT_URL}/v${CONFIG_LIBTOMCRYPT_VERSION}.zip - SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/libtomcrypt BINARY_DIR - ${CMAKE_BINARY_DIR}/apps/crypto/libtomcrypt/libtomcrypt - PATCH_COMMAND - patch -p0 -d ${CMAKE_CURRENT_LIST_DIR} < - ${CMAKE_CURRENT_LIST_DIR}/digit-bit.patch && patch -p0 -d - ${CMAKE_CURRENT_LIST_DIR} < - ${CMAKE_CURRENT_LIST_DIR}/ltcrypt-flush.patch - DOWNLOAD_NO_PROGRESS true - TIMEOUT 30) - - FetchContent_GetProperties(libtomcrypt_fetch) - - if(NOT libtomcrypt_fetch_POPULATED) - FetchContent_Populate(libtomcrypt_fetch) - endif() - endif() - - nuttx_add_library(libtomcrypt STATIC) - - # ############################################################################ - # Include Directory - # ############################################################################ - - set(INCDIR ${LIBTOMCRYPT_DIR}/src/headers) - - # ############################################################################ - # Sources - # ############################################################################ - - set(CSRCS - ${LIBTOMCRYPT_DIR}/src/ciphers/aes/aes.c - ${LIBTOMCRYPT_DIR}/src/ciphers/aes/aes_tab.c - ${LIBTOMCRYPT_DIR}/src/ciphers/anubis.c - ${LIBTOMCRYPT_DIR}/src/ciphers/blowfish.c - ${LIBTOMCRYPT_DIR}/src/ciphers/camellia.c - ${LIBTOMCRYPT_DIR}/src/ciphers/cast5.c - ${LIBTOMCRYPT_DIR}/src/ciphers/des.c - ${LIBTOMCRYPT_DIR}/src/ciphers/kasumi.c - ${LIBTOMCRYPT_DIR}/src/ciphers/khazad.c - ${LIBTOMCRYPT_DIR}/src/ciphers/kseed.c - ${LIBTOMCRYPT_DIR}/src/ciphers/multi2.c - ${LIBTOMCRYPT_DIR}/src/ciphers/noekeon.c - ${LIBTOMCRYPT_DIR}/src/ciphers/rc2.c - ${LIBTOMCRYPT_DIR}/src/ciphers/rc5.c - ${LIBTOMCRYPT_DIR}/src/ciphers/rc6.c - ${LIBTOMCRYPT_DIR}/src/ciphers/safer/safer.c - ${LIBTOMCRYPT_DIR}/src/ciphers/safer/saferp.c - ${LIBTOMCRYPT_DIR}/src/ciphers/skipjack.c - ${LIBTOMCRYPT_DIR}/src/ciphers/twofish/twofish.c - ${LIBTOMCRYPT_DIR}/src/ciphers/xtea.c - ${LIBTOMCRYPT_DIR}/src/encauth/ccm/ccm_add_aad.c - ${LIBTOMCRYPT_DIR}/src/encauth/ccm/ccm_add_nonce.c - ${LIBTOMCRYPT_DIR}/src/encauth/ccm/ccm_done.c - ${LIBTOMCRYPT_DIR}/src/encauth/ccm/ccm_init.c - ${LIBTOMCRYPT_DIR}/src/encauth/ccm/ccm_memory.c - ${LIBTOMCRYPT_DIR}/src/encauth/ccm/ccm_process.c - ${LIBTOMCRYPT_DIR}/src/encauth/ccm/ccm_reset.c - ${LIBTOMCRYPT_DIR}/src/encauth/ccm/ccm_test.c - ${LIBTOMCRYPT_DIR}/src/encauth/chachapoly/chacha20poly1305_add_aad.c - ${LIBTOMCRYPT_DIR}/src/encauth/chachapoly/chacha20poly1305_decrypt.c - ${LIBTOMCRYPT_DIR}/src/encauth/chachapoly/chacha20poly1305_done.c - ${LIBTOMCRYPT_DIR}/src/encauth/chachapoly/chacha20poly1305_encrypt.c - ${LIBTOMCRYPT_DIR}/src/encauth/chachapoly/chacha20poly1305_init.c - ${LIBTOMCRYPT_DIR}/src/encauth/chachapoly/chacha20poly1305_memory.c - ${LIBTOMCRYPT_DIR}/src/encauth/chachapoly/chacha20poly1305_setiv.c - ${LIBTOMCRYPT_DIR}/src/encauth/chachapoly/chacha20poly1305_setiv_rfc7905.c - ${LIBTOMCRYPT_DIR}/src/encauth/chachapoly/chacha20poly1305_test.c - ${LIBTOMCRYPT_DIR}/src/encauth/eax/eax_addheader.c - ${LIBTOMCRYPT_DIR}/src/encauth/eax/eax_decrypt.c - ${LIBTOMCRYPT_DIR}/src/encauth/eax/eax_decrypt_verify_memory.c - ${LIBTOMCRYPT_DIR}/src/encauth/eax/eax_done.c - ${LIBTOMCRYPT_DIR}/src/encauth/eax/eax_encrypt.c - ${LIBTOMCRYPT_DIR}/src/encauth/eax/eax_encrypt_authenticate_memory.c - ${LIBTOMCRYPT_DIR}/src/encauth/eax/eax_init.c - ${LIBTOMCRYPT_DIR}/src/encauth/eax/eax_test.c - ${LIBTOMCRYPT_DIR}/src/encauth/gcm/gcm_add_aad.c - ${LIBTOMCRYPT_DIR}/src/encauth/gcm/gcm_add_iv.c - ${LIBTOMCRYPT_DIR}/src/encauth/gcm/gcm_done.c - ${LIBTOMCRYPT_DIR}/src/encauth/gcm/gcm_gf_mult.c - ${LIBTOMCRYPT_DIR}/src/encauth/gcm/gcm_init.c - ${LIBTOMCRYPT_DIR}/src/encauth/gcm/gcm_memory.c - ${LIBTOMCRYPT_DIR}/src/encauth/gcm/gcm_mult_h.c - ${LIBTOMCRYPT_DIR}/src/encauth/gcm/gcm_process.c - ${LIBTOMCRYPT_DIR}/src/encauth/gcm/gcm_reset.c - ${LIBTOMCRYPT_DIR}/src/encauth/gcm/gcm_test.c - ${LIBTOMCRYPT_DIR}/src/encauth/ocb/ocb_decrypt.c - ${LIBTOMCRYPT_DIR}/src/encauth/ocb/ocb_decrypt_verify_memory.c - ${LIBTOMCRYPT_DIR}/src/encauth/ocb/ocb_done_decrypt.c - ${LIBTOMCRYPT_DIR}/src/encauth/ocb/ocb_done_encrypt.c - ${LIBTOMCRYPT_DIR}/src/encauth/ocb/ocb_encrypt.c - ${LIBTOMCRYPT_DIR}/src/encauth/ocb/ocb_encrypt_authenticate_memory.c - ${LIBTOMCRYPT_DIR}/src/encauth/ocb/ocb_init.c - ${LIBTOMCRYPT_DIR}/src/encauth/ocb/ocb_ntz.c - ${LIBTOMCRYPT_DIR}/src/encauth/ocb/ocb_shift_xor.c - ${LIBTOMCRYPT_DIR}/src/encauth/ocb/ocb_test.c - ${LIBTOMCRYPT_DIR}/src/encauth/ocb/s_ocb_done.c - ${LIBTOMCRYPT_DIR}/src/encauth/ocb3/ocb3_add_aad.c - ${LIBTOMCRYPT_DIR}/src/encauth/ocb3/ocb3_decrypt.c - ${LIBTOMCRYPT_DIR}/src/encauth/ocb3/ocb3_decrypt_last.c - ${LIBTOMCRYPT_DIR}/src/encauth/ocb3/ocb3_decrypt_verify_memory.c - ${LIBTOMCRYPT_DIR}/src/encauth/ocb3/ocb3_done.c - ${LIBTOMCRYPT_DIR}/src/encauth/ocb3/ocb3_encrypt.c - ${LIBTOMCRYPT_DIR}/src/encauth/ocb3/ocb3_encrypt_authenticate_memory.c - ${LIBTOMCRYPT_DIR}/src/encauth/ocb3/ocb3_encrypt_last.c - ${LIBTOMCRYPT_DIR}/src/encauth/ocb3/ocb3_init.c - ${LIBTOMCRYPT_DIR}/src/encauth/ocb3/ocb3_int_ntz.c - ${LIBTOMCRYPT_DIR}/src/encauth/ocb3/ocb3_int_xor_blocks.c - ${LIBTOMCRYPT_DIR}/src/encauth/ocb3/ocb3_test.c - ${LIBTOMCRYPT_DIR}/src/hashes/blake2b.c - ${LIBTOMCRYPT_DIR}/src/hashes/blake2s.c - ${LIBTOMCRYPT_DIR}/src/hashes/chc/chc.c - ${LIBTOMCRYPT_DIR}/src/hashes/helper/hash_file.c - ${LIBTOMCRYPT_DIR}/src/hashes/helper/hash_filehandle.c - ${LIBTOMCRYPT_DIR}/src/hashes/helper/hash_memory.c - ${LIBTOMCRYPT_DIR}/src/hashes/helper/hash_memory_multi.c - ${LIBTOMCRYPT_DIR}/src/hashes/md2.c - ${LIBTOMCRYPT_DIR}/src/hashes/md4.c - ${LIBTOMCRYPT_DIR}/src/hashes/md5.c - ${LIBTOMCRYPT_DIR}/src/hashes/rmd128.c - ${LIBTOMCRYPT_DIR}/src/hashes/rmd160.c - ${LIBTOMCRYPT_DIR}/src/hashes/rmd256.c - ${LIBTOMCRYPT_DIR}/src/hashes/rmd320.c - ${LIBTOMCRYPT_DIR}/src/hashes/sha1.c - ${LIBTOMCRYPT_DIR}/src/hashes/sha2/sha224.c - ${LIBTOMCRYPT_DIR}/src/hashes/sha2/sha256.c - ${LIBTOMCRYPT_DIR}/src/hashes/sha2/sha384.c - ${LIBTOMCRYPT_DIR}/src/hashes/sha2/sha512.c - ${LIBTOMCRYPT_DIR}/src/hashes/sha2/sha512_224.c - ${LIBTOMCRYPT_DIR}/src/hashes/sha2/sha512_256.c - ${LIBTOMCRYPT_DIR}/src/hashes/sha3.c - ${LIBTOMCRYPT_DIR}/src/hashes/sha3_test.c - ${LIBTOMCRYPT_DIR}/src/hashes/tiger.c - ${LIBTOMCRYPT_DIR}/src/hashes/whirl/whirl.c - ${LIBTOMCRYPT_DIR}/src/mac/blake2/blake2bmac.c - ${LIBTOMCRYPT_DIR}/src/mac/blake2/blake2bmac_file.c - ${LIBTOMCRYPT_DIR}/src/mac/blake2/blake2bmac_memory.c - ${LIBTOMCRYPT_DIR}/src/mac/blake2/blake2bmac_memory_multi.c - ${LIBTOMCRYPT_DIR}/src/mac/blake2/blake2bmac_test.c - ${LIBTOMCRYPT_DIR}/src/mac/blake2/blake2smac.c - ${LIBTOMCRYPT_DIR}/src/mac/blake2/blake2smac_file.c - ${LIBTOMCRYPT_DIR}/src/mac/blake2/blake2smac_memory.c - ${LIBTOMCRYPT_DIR}/src/mac/blake2/blake2smac_memory_multi.c - ${LIBTOMCRYPT_DIR}/src/mac/blake2/blake2smac_test.c - ${LIBTOMCRYPT_DIR}/src/mac/f9/f9_done.c - ${LIBTOMCRYPT_DIR}/src/mac/f9/f9_file.c - ${LIBTOMCRYPT_DIR}/src/mac/f9/f9_init.c - ${LIBTOMCRYPT_DIR}/src/mac/f9/f9_memory.c - ${LIBTOMCRYPT_DIR}/src/mac/f9/f9_memory_multi.c - ${LIBTOMCRYPT_DIR}/src/mac/f9/f9_process.c - ${LIBTOMCRYPT_DIR}/src/mac/f9/f9_test.c - ${LIBTOMCRYPT_DIR}/src/mac/hmac/hmac_done.c - ${LIBTOMCRYPT_DIR}/src/mac/hmac/hmac_file.c - ${LIBTOMCRYPT_DIR}/src/mac/hmac/hmac_init.c - ${LIBTOMCRYPT_DIR}/src/mac/hmac/hmac_memory.c - ${LIBTOMCRYPT_DIR}/src/mac/hmac/hmac_memory_multi.c - ${LIBTOMCRYPT_DIR}/src/mac/hmac/hmac_process.c - ${LIBTOMCRYPT_DIR}/src/mac/hmac/hmac_test.c - ${LIBTOMCRYPT_DIR}/src/mac/omac/omac_done.c - ${LIBTOMCRYPT_DIR}/src/mac/omac/omac_file.c - ${LIBTOMCRYPT_DIR}/src/mac/omac/omac_init.c - ${LIBTOMCRYPT_DIR}/src/mac/omac/omac_memory.c - ${LIBTOMCRYPT_DIR}/src/mac/omac/omac_memory_multi.c - ${LIBTOMCRYPT_DIR}/src/mac/omac/omac_process.c - ${LIBTOMCRYPT_DIR}/src/mac/omac/omac_test.c - ${LIBTOMCRYPT_DIR}/src/mac/pelican/pelican.c - ${LIBTOMCRYPT_DIR}/src/mac/pelican/pelican_memory.c - ${LIBTOMCRYPT_DIR}/src/mac/pelican/pelican_test.c - ${LIBTOMCRYPT_DIR}/src/mac/pmac/pmac_done.c - ${LIBTOMCRYPT_DIR}/src/mac/pmac/pmac_file.c - ${LIBTOMCRYPT_DIR}/src/mac/pmac/pmac_init.c - ${LIBTOMCRYPT_DIR}/src/mac/pmac/pmac_memory.c - ${LIBTOMCRYPT_DIR}/src/mac/pmac/pmac_memory_multi.c - ${LIBTOMCRYPT_DIR}/src/mac/pmac/pmac_ntz.c - ${LIBTOMCRYPT_DIR}/src/mac/pmac/pmac_process.c - ${LIBTOMCRYPT_DIR}/src/mac/pmac/pmac_shift_xor.c - ${LIBTOMCRYPT_DIR}/src/mac/pmac/pmac_test.c - ${LIBTOMCRYPT_DIR}/src/mac/poly1305/poly1305.c - ${LIBTOMCRYPT_DIR}/src/mac/poly1305/poly1305_file.c - ${LIBTOMCRYPT_DIR}/src/mac/poly1305/poly1305_memory.c - ${LIBTOMCRYPT_DIR}/src/mac/poly1305/poly1305_memory_multi.c - ${LIBTOMCRYPT_DIR}/src/mac/poly1305/poly1305_test.c - ${LIBTOMCRYPT_DIR}/src/mac/xcbc/xcbc_done.c - ${LIBTOMCRYPT_DIR}/src/mac/xcbc/xcbc_file.c - ${LIBTOMCRYPT_DIR}/src/mac/xcbc/xcbc_init.c - ${LIBTOMCRYPT_DIR}/src/mac/xcbc/xcbc_memory.c - ${LIBTOMCRYPT_DIR}/src/mac/xcbc/xcbc_memory_multi.c - ${LIBTOMCRYPT_DIR}/src/mac/xcbc/xcbc_process.c - ${LIBTOMCRYPT_DIR}/src/mac/xcbc/xcbc_test.c - ${LIBTOMCRYPT_DIR}/src/math/fp/ltc_ecc_fp_mulmod.c - ${LIBTOMCRYPT_DIR}/src/math/gmp_desc.c - ${LIBTOMCRYPT_DIR}/src/math/ltm_desc.c - ${LIBTOMCRYPT_DIR}/src/math/multi.c - ${LIBTOMCRYPT_DIR}/src/math/radix_to_bin.c - ${LIBTOMCRYPT_DIR}/src/math/rand_bn.c - ${LIBTOMCRYPT_DIR}/src/math/rand_prime.c - ${LIBTOMCRYPT_DIR}/src/math/tfm_desc.c - ${LIBTOMCRYPT_DIR}/src/misc/adler32.c - ${LIBTOMCRYPT_DIR}/src/misc/base64/base64_decode.c - ${LIBTOMCRYPT_DIR}/src/misc/base64/base64_encode.c - ${LIBTOMCRYPT_DIR}/src/misc/burn_stack.c - ${LIBTOMCRYPT_DIR}/src/misc/compare_testvector.c - ${LIBTOMCRYPT_DIR}/src/misc/crc32.c - ${LIBTOMCRYPT_DIR}/src/misc/crypt/crypt.c - ${LIBTOMCRYPT_DIR}/src/misc/crypt/crypt_argchk.c - ${LIBTOMCRYPT_DIR}/src/misc/crypt/crypt_cipher_descriptor.c - ${LIBTOMCRYPT_DIR}/src/misc/crypt/crypt_cipher_is_valid.c - ${LIBTOMCRYPT_DIR}/src/misc/crypt/crypt_constants.c - ${LIBTOMCRYPT_DIR}/src/misc/crypt/crypt_find_cipher.c - ${LIBTOMCRYPT_DIR}/src/misc/crypt/crypt_find_cipher_any.c - ${LIBTOMCRYPT_DIR}/src/misc/crypt/crypt_find_cipher_id.c - ${LIBTOMCRYPT_DIR}/src/misc/crypt/crypt_find_hash.c - ${LIBTOMCRYPT_DIR}/src/misc/crypt/crypt_find_hash_any.c - ${LIBTOMCRYPT_DIR}/src/misc/crypt/crypt_find_hash_id.c - ${LIBTOMCRYPT_DIR}/src/misc/crypt/crypt_find_hash_oid.c - ${LIBTOMCRYPT_DIR}/src/misc/crypt/crypt_find_prng.c - ${LIBTOMCRYPT_DIR}/src/misc/crypt/crypt_fsa.c - ${LIBTOMCRYPT_DIR}/src/misc/crypt/crypt_hash_descriptor.c - ${LIBTOMCRYPT_DIR}/src/misc/crypt/crypt_hash_is_valid.c - ${LIBTOMCRYPT_DIR}/src/misc/crypt/crypt_inits.c - ${LIBTOMCRYPT_DIR}/src/misc/crypt/crypt_ltc_mp_descriptor.c - ${LIBTOMCRYPT_DIR}/src/misc/crypt/crypt_prng_descriptor.c - ${LIBTOMCRYPT_DIR}/src/misc/crypt/crypt_prng_is_valid.c - ${LIBTOMCRYPT_DIR}/src/misc/crypt/crypt_prng_rng_descriptor.c - ${LIBTOMCRYPT_DIR}/src/misc/crypt/crypt_register_all_ciphers.c - ${LIBTOMCRYPT_DIR}/src/misc/crypt/crypt_register_all_hashes.c - ${LIBTOMCRYPT_DIR}/src/misc/crypt/crypt_register_all_prngs.c - ${LIBTOMCRYPT_DIR}/src/misc/crypt/crypt_register_cipher.c - ${LIBTOMCRYPT_DIR}/src/misc/crypt/crypt_register_hash.c - ${LIBTOMCRYPT_DIR}/src/misc/crypt/crypt_register_prng.c - ${LIBTOMCRYPT_DIR}/src/misc/crypt/crypt_sizes.c - ${LIBTOMCRYPT_DIR}/src/misc/crypt/crypt_unregister_cipher.c - ${LIBTOMCRYPT_DIR}/src/misc/crypt/crypt_unregister_hash.c - ${LIBTOMCRYPT_DIR}/src/misc/crypt/crypt_unregister_prng.c - ${LIBTOMCRYPT_DIR}/src/misc/error_to_string.c - ${LIBTOMCRYPT_DIR}/src/misc/hkdf/hkdf.c - ${LIBTOMCRYPT_DIR}/src/misc/hkdf/hkdf_test.c - ${LIBTOMCRYPT_DIR}/src/misc/mem_neq.c - ${LIBTOMCRYPT_DIR}/src/misc/pk_get_oid.c - ${LIBTOMCRYPT_DIR}/src/misc/pkcs5/pkcs_5_1.c - ${LIBTOMCRYPT_DIR}/src/misc/pkcs5/pkcs_5_2.c - ${LIBTOMCRYPT_DIR}/src/misc/pkcs5/pkcs_5_test.c - ${LIBTOMCRYPT_DIR}/src/misc/zeromem.c - ${LIBTOMCRYPT_DIR}/src/modes/cbc/cbc_decrypt.c - ${LIBTOMCRYPT_DIR}/src/modes/cbc/cbc_done.c - ${LIBTOMCRYPT_DIR}/src/modes/cbc/cbc_encrypt.c - ${LIBTOMCRYPT_DIR}/src/modes/cbc/cbc_getiv.c - ${LIBTOMCRYPT_DIR}/src/modes/cbc/cbc_setiv.c - ${LIBTOMCRYPT_DIR}/src/modes/cbc/cbc_start.c - ${LIBTOMCRYPT_DIR}/src/modes/cfb/cfb_decrypt.c - ${LIBTOMCRYPT_DIR}/src/modes/cfb/cfb_done.c - ${LIBTOMCRYPT_DIR}/src/modes/cfb/cfb_encrypt.c - ${LIBTOMCRYPT_DIR}/src/modes/cfb/cfb_getiv.c - ${LIBTOMCRYPT_DIR}/src/modes/cfb/cfb_setiv.c - ${LIBTOMCRYPT_DIR}/src/modes/cfb/cfb_start.c - ${LIBTOMCRYPT_DIR}/src/modes/ctr/ctr_decrypt.c - ${LIBTOMCRYPT_DIR}/src/modes/ctr/ctr_done.c - ${LIBTOMCRYPT_DIR}/src/modes/ctr/ctr_encrypt.c - ${LIBTOMCRYPT_DIR}/src/modes/ctr/ctr_getiv.c - ${LIBTOMCRYPT_DIR}/src/modes/ctr/ctr_setiv.c - ${LIBTOMCRYPT_DIR}/src/modes/ctr/ctr_start.c - ${LIBTOMCRYPT_DIR}/src/modes/ctr/ctr_test.c - ${LIBTOMCRYPT_DIR}/src/modes/ecb/ecb_decrypt.c - ${LIBTOMCRYPT_DIR}/src/modes/ecb/ecb_done.c - ${LIBTOMCRYPT_DIR}/src/modes/ecb/ecb_encrypt.c - ${LIBTOMCRYPT_DIR}/src/modes/ecb/ecb_start.c - ${LIBTOMCRYPT_DIR}/src/modes/f8/f8_decrypt.c - ${LIBTOMCRYPT_DIR}/src/modes/f8/f8_done.c - ${LIBTOMCRYPT_DIR}/src/modes/f8/f8_encrypt.c - ${LIBTOMCRYPT_DIR}/src/modes/f8/f8_getiv.c - ${LIBTOMCRYPT_DIR}/src/modes/f8/f8_setiv.c - ${LIBTOMCRYPT_DIR}/src/modes/f8/f8_start.c - ${LIBTOMCRYPT_DIR}/src/modes/f8/f8_test_mode.c - ${LIBTOMCRYPT_DIR}/src/modes/lrw/lrw_decrypt.c - ${LIBTOMCRYPT_DIR}/src/modes/lrw/lrw_done.c - ${LIBTOMCRYPT_DIR}/src/modes/lrw/lrw_encrypt.c - ${LIBTOMCRYPT_DIR}/src/modes/lrw/lrw_getiv.c - ${LIBTOMCRYPT_DIR}/src/modes/lrw/lrw_process.c - ${LIBTOMCRYPT_DIR}/src/modes/lrw/lrw_setiv.c - ${LIBTOMCRYPT_DIR}/src/modes/lrw/lrw_start.c - ${LIBTOMCRYPT_DIR}/src/modes/lrw/lrw_test.c - ${LIBTOMCRYPT_DIR}/src/modes/ofb/ofb_decrypt.c - ${LIBTOMCRYPT_DIR}/src/modes/ofb/ofb_done.c - ${LIBTOMCRYPT_DIR}/src/modes/ofb/ofb_encrypt.c - ${LIBTOMCRYPT_DIR}/src/modes/ofb/ofb_getiv.c - ${LIBTOMCRYPT_DIR}/src/modes/ofb/ofb_setiv.c - ${LIBTOMCRYPT_DIR}/src/modes/ofb/ofb_start.c - ${LIBTOMCRYPT_DIR}/src/modes/xts/xts_decrypt.c - ${LIBTOMCRYPT_DIR}/src/modes/xts/xts_done.c - ${LIBTOMCRYPT_DIR}/src/modes/xts/xts_encrypt.c - ${LIBTOMCRYPT_DIR}/src/modes/xts/xts_init.c - ${LIBTOMCRYPT_DIR}/src/modes/xts/xts_mult_x.c - ${LIBTOMCRYPT_DIR}/src/modes/xts/xts_test.c - ${LIBTOMCRYPT_DIR}/src/pk/asn1/der/bit/der_decode_bit_string.c - ${LIBTOMCRYPT_DIR}/src/pk/asn1/der/bit/der_decode_raw_bit_string.c - ${LIBTOMCRYPT_DIR}/src/pk/asn1/der/bit/der_encode_bit_string.c - ${LIBTOMCRYPT_DIR}/src/pk/asn1/der/bit/der_encode_raw_bit_string.c - ${LIBTOMCRYPT_DIR}/src/pk/asn1/der/bit/der_length_bit_string.c - ${LIBTOMCRYPT_DIR}/src/pk/asn1/der/boolean/der_decode_boolean.c - ${LIBTOMCRYPT_DIR}/src/pk/asn1/der/boolean/der_encode_boolean.c - ${LIBTOMCRYPT_DIR}/src/pk/asn1/der/boolean/der_length_boolean.c - ${LIBTOMCRYPT_DIR}/src/pk/asn1/der/choice/der_decode_choice.c - ${LIBTOMCRYPT_DIR}/src/pk/asn1/der/generalizedtime/der_decode_generalizedtime.c - ${LIBTOMCRYPT_DIR}/src/pk/asn1/der/generalizedtime/der_encode_generalizedtime.c - ${LIBTOMCRYPT_DIR}/src/pk/asn1/der/generalizedtime/der_length_generalizedtime.c - ${LIBTOMCRYPT_DIR}/src/pk/asn1/der/ia5/der_decode_ia5_string.c - ${LIBTOMCRYPT_DIR}/src/pk/asn1/der/ia5/der_encode_ia5_string.c - ${LIBTOMCRYPT_DIR}/src/pk/asn1/der/ia5/der_length_ia5_string.c - ${LIBTOMCRYPT_DIR}/src/pk/asn1/der/integer/der_decode_integer.c - ${LIBTOMCRYPT_DIR}/src/pk/asn1/der/integer/der_encode_integer.c - ${LIBTOMCRYPT_DIR}/src/pk/asn1/der/integer/der_length_integer.c - ${LIBTOMCRYPT_DIR}/src/pk/asn1/der/object_identifier/der_decode_object_identifier.c - ${LIBTOMCRYPT_DIR}/src/pk/asn1/der/object_identifier/der_encode_object_identifier.c - ${LIBTOMCRYPT_DIR}/src/pk/asn1/der/object_identifier/der_length_object_identifier.c - ${LIBTOMCRYPT_DIR}/src/pk/asn1/der/octet/der_decode_octet_string.c - ${LIBTOMCRYPT_DIR}/src/pk/asn1/der/octet/der_encode_octet_string.c - ${LIBTOMCRYPT_DIR}/src/pk/asn1/der/octet/der_length_octet_string.c - ${LIBTOMCRYPT_DIR}/src/pk/asn1/der/printable_string/der_decode_printable_string.c - ${LIBTOMCRYPT_DIR}/src/pk/asn1/der/printable_string/der_encode_printable_string.c - ${LIBTOMCRYPT_DIR}/src/pk/asn1/der/printable_string/der_length_printable_string.c - ${LIBTOMCRYPT_DIR}/src/pk/asn1/der/sequence/der_decode_sequence_ex.c - ${LIBTOMCRYPT_DIR}/src/pk/asn1/der/sequence/der_decode_sequence_flexi.c - ${LIBTOMCRYPT_DIR}/src/pk/asn1/der/sequence/der_decode_sequence_multi.c - ${LIBTOMCRYPT_DIR}/src/pk/asn1/der/sequence/der_decode_subject_public_key_info.c - ${LIBTOMCRYPT_DIR}/src/pk/asn1/der/sequence/der_encode_sequence_ex.c - ${LIBTOMCRYPT_DIR}/src/pk/asn1/der/sequence/der_encode_sequence_multi.c - ${LIBTOMCRYPT_DIR}/src/pk/asn1/der/sequence/der_encode_subject_public_key_info.c - ${LIBTOMCRYPT_DIR}/src/pk/asn1/der/sequence/der_length_sequence.c - ${LIBTOMCRYPT_DIR}/src/pk/asn1/der/sequence/der_sequence_free.c - ${LIBTOMCRYPT_DIR}/src/pk/asn1/der/sequence/der_sequence_shrink.c - ${LIBTOMCRYPT_DIR}/src/pk/asn1/der/set/der_encode_set.c - ${LIBTOMCRYPT_DIR}/src/pk/asn1/der/set/der_encode_setof.c - ${LIBTOMCRYPT_DIR}/src/pk/asn1/der/short_integer/der_decode_short_integer.c - ${LIBTOMCRYPT_DIR}/src/pk/asn1/der/short_integer/der_encode_short_integer.c - ${LIBTOMCRYPT_DIR}/src/pk/asn1/der/short_integer/der_length_short_integer.c - ${LIBTOMCRYPT_DIR}/src/pk/asn1/der/teletex_string/der_decode_teletex_string.c - ${LIBTOMCRYPT_DIR}/src/pk/asn1/der/teletex_string/der_length_teletex_string.c - ${LIBTOMCRYPT_DIR}/src/pk/asn1/der/utctime/der_decode_utctime.c - ${LIBTOMCRYPT_DIR}/src/pk/asn1/der/utctime/der_encode_utctime.c - ${LIBTOMCRYPT_DIR}/src/pk/asn1/der/utctime/der_length_utctime.c - ${LIBTOMCRYPT_DIR}/src/pk/asn1/der/utf8/der_decode_utf8_string.c - ${LIBTOMCRYPT_DIR}/src/pk/asn1/der/utf8/der_encode_utf8_string.c - ${LIBTOMCRYPT_DIR}/src/pk/asn1/der/utf8/der_length_utf8_string.c - ${LIBTOMCRYPT_DIR}/src/pk/dh/dh.c - ${LIBTOMCRYPT_DIR}/src/pk/dh/dh_check_pubkey.c - ${LIBTOMCRYPT_DIR}/src/pk/dh/dh_export.c - ${LIBTOMCRYPT_DIR}/src/pk/dh/dh_export_key.c - ${LIBTOMCRYPT_DIR}/src/pk/dh/dh_free.c - ${LIBTOMCRYPT_DIR}/src/pk/dh/dh_generate_key.c - ${LIBTOMCRYPT_DIR}/src/pk/dh/dh_import.c - ${LIBTOMCRYPT_DIR}/src/pk/dh/dh_set.c - ${LIBTOMCRYPT_DIR}/src/pk/dh/dh_set_pg_dhparam.c - ${LIBTOMCRYPT_DIR}/src/pk/dh/dh_shared_secret.c - ${LIBTOMCRYPT_DIR}/src/pk/dsa/dsa_decrypt_key.c - ${LIBTOMCRYPT_DIR}/src/pk/dsa/dsa_encrypt_key.c - ${LIBTOMCRYPT_DIR}/src/pk/dsa/dsa_export.c - ${LIBTOMCRYPT_DIR}/src/pk/dsa/dsa_free.c - ${LIBTOMCRYPT_DIR}/src/pk/dsa/dsa_generate_key.c - ${LIBTOMCRYPT_DIR}/src/pk/dsa/dsa_generate_pqg.c - ${LIBTOMCRYPT_DIR}/src/pk/dsa/dsa_import.c - ${LIBTOMCRYPT_DIR}/src/pk/dsa/dsa_make_key.c - ${LIBTOMCRYPT_DIR}/src/pk/dsa/dsa_set.c - ${LIBTOMCRYPT_DIR}/src/pk/dsa/dsa_set_pqg_dsaparam.c - ${LIBTOMCRYPT_DIR}/src/pk/dsa/dsa_shared_secret.c - ${LIBTOMCRYPT_DIR}/src/pk/dsa/dsa_sign_hash.c - ${LIBTOMCRYPT_DIR}/src/pk/dsa/dsa_verify_hash.c - ${LIBTOMCRYPT_DIR}/src/pk/dsa/dsa_verify_key.c - ${LIBTOMCRYPT_DIR}/src/pk/ecc/ecc.c - ${LIBTOMCRYPT_DIR}/src/pk/ecc/ecc_ansi_x963_export.c - ${LIBTOMCRYPT_DIR}/src/pk/ecc/ecc_ansi_x963_import.c - ${LIBTOMCRYPT_DIR}/src/pk/ecc/ecc_decrypt_key.c - ${LIBTOMCRYPT_DIR}/src/pk/ecc/ecc_encrypt_key.c - ${LIBTOMCRYPT_DIR}/src/pk/ecc/ecc_export.c - ${LIBTOMCRYPT_DIR}/src/pk/ecc/ecc_free.c - ${LIBTOMCRYPT_DIR}/src/pk/ecc/ecc_get_size.c - ${LIBTOMCRYPT_DIR}/src/pk/ecc/ecc_import.c - ${LIBTOMCRYPT_DIR}/src/pk/ecc/ecc_make_key.c - ${LIBTOMCRYPT_DIR}/src/pk/ecc/ecc_shared_secret.c - ${LIBTOMCRYPT_DIR}/src/pk/ecc/ecc_sign_hash.c - ${LIBTOMCRYPT_DIR}/src/pk/ecc/ecc_sizes.c - ${LIBTOMCRYPT_DIR}/src/pk/ecc/ecc_test.c - ${LIBTOMCRYPT_DIR}/src/pk/ecc/ecc_verify_hash.c - ${LIBTOMCRYPT_DIR}/src/pk/ecc/ltc_ecc_is_valid_idx.c - ${LIBTOMCRYPT_DIR}/src/pk/ecc/ltc_ecc_map.c - ${LIBTOMCRYPT_DIR}/src/pk/ecc/ltc_ecc_mul2add.c - ${LIBTOMCRYPT_DIR}/src/pk/ecc/ltc_ecc_mulmod.c - ${LIBTOMCRYPT_DIR}/src/pk/ecc/ltc_ecc_mulmod_timing.c - ${LIBTOMCRYPT_DIR}/src/pk/ecc/ltc_ecc_points.c - ${LIBTOMCRYPT_DIR}/src/pk/ecc/ltc_ecc_projective_add_point.c - ${LIBTOMCRYPT_DIR}/src/pk/ecc/ltc_ecc_projective_dbl_point.c - ${LIBTOMCRYPT_DIR}/src/pk/katja/katja_decrypt_key.c - ${LIBTOMCRYPT_DIR}/src/pk/katja/katja_encrypt_key.c - ${LIBTOMCRYPT_DIR}/src/pk/katja/katja_export.c - ${LIBTOMCRYPT_DIR}/src/pk/katja/katja_exptmod.c - ${LIBTOMCRYPT_DIR}/src/pk/katja/katja_free.c - ${LIBTOMCRYPT_DIR}/src/pk/katja/katja_import.c - ${LIBTOMCRYPT_DIR}/src/pk/katja/katja_make_key.c - ${LIBTOMCRYPT_DIR}/src/pk/pkcs1/pkcs_1_i2osp.c - ${LIBTOMCRYPT_DIR}/src/pk/pkcs1/pkcs_1_mgf1.c - ${LIBTOMCRYPT_DIR}/src/pk/pkcs1/pkcs_1_oaep_decode.c - ${LIBTOMCRYPT_DIR}/src/pk/pkcs1/pkcs_1_oaep_encode.c - ${LIBTOMCRYPT_DIR}/src/pk/pkcs1/pkcs_1_os2ip.c - ${LIBTOMCRYPT_DIR}/src/pk/pkcs1/pkcs_1_pss_decode.c - ${LIBTOMCRYPT_DIR}/src/pk/pkcs1/pkcs_1_pss_encode.c - ${LIBTOMCRYPT_DIR}/src/pk/pkcs1/pkcs_1_v1_5_decode.c - ${LIBTOMCRYPT_DIR}/src/pk/pkcs1/pkcs_1_v1_5_encode.c - ${LIBTOMCRYPT_DIR}/src/pk/rsa/rsa_decrypt_key.c - ${LIBTOMCRYPT_DIR}/src/pk/rsa/rsa_encrypt_key.c - ${LIBTOMCRYPT_DIR}/src/pk/rsa/rsa_export.c - ${LIBTOMCRYPT_DIR}/src/pk/rsa/rsa_exptmod.c - ${LIBTOMCRYPT_DIR}/src/pk/rsa/rsa_free.c - ${LIBTOMCRYPT_DIR}/src/pk/rsa/rsa_get_size.c - ${LIBTOMCRYPT_DIR}/src/pk/rsa/rsa_import.c - ${LIBTOMCRYPT_DIR}/src/pk/rsa/rsa_import_pkcs8.c - ${LIBTOMCRYPT_DIR}/src/pk/rsa/rsa_import_x509.c - ${LIBTOMCRYPT_DIR}/src/pk/rsa/rsa_make_key.c - ${LIBTOMCRYPT_DIR}/src/pk/rsa/rsa_set.c - ${LIBTOMCRYPT_DIR}/src/pk/rsa/rsa_sign_hash.c - ${LIBTOMCRYPT_DIR}/src/pk/rsa/rsa_sign_saltlen_get.c - ${LIBTOMCRYPT_DIR}/src/pk/rsa/rsa_verify_hash.c - ${LIBTOMCRYPT_DIR}/src/prngs/chacha20.c - ${LIBTOMCRYPT_DIR}/src/prngs/fortuna.c - ${LIBTOMCRYPT_DIR}/src/prngs/rc4.c - ${LIBTOMCRYPT_DIR}/src/prngs/rng_get_bytes.c - ${LIBTOMCRYPT_DIR}/src/prngs/rng_make_prng.c - ${LIBTOMCRYPT_DIR}/src/prngs/sober128.c - ${LIBTOMCRYPT_DIR}/src/prngs/sprng.c - ${LIBTOMCRYPT_DIR}/src/prngs/yarrow.c - ${LIBTOMCRYPT_DIR}/src/stream/chacha/chacha_crypt.c - ${LIBTOMCRYPT_DIR}/src/stream/chacha/chacha_done.c - ${LIBTOMCRYPT_DIR}/src/stream/chacha/chacha_ivctr32.c - ${LIBTOMCRYPT_DIR}/src/stream/chacha/chacha_ivctr64.c - ${LIBTOMCRYPT_DIR}/src/stream/chacha/chacha_keystream.c - ${LIBTOMCRYPT_DIR}/src/stream/chacha/chacha_setup.c - ${LIBTOMCRYPT_DIR}/src/stream/chacha/chacha_test.c - ${LIBTOMCRYPT_DIR}/src/stream/rc4/rc4_stream.c - ${LIBTOMCRYPT_DIR}/src/stream/rc4/rc4_test.c - ${LIBTOMCRYPT_DIR}/src/stream/sober128/sober128_stream.c - ${LIBTOMCRYPT_DIR}/src/stream/sober128/sober128_test.c) - - # ############################################################################ - # Applications Configuration - # ############################################################################ - - if(CONFIG_LIBTOMCRYPT_DEMOS) - - if(CONFIG_LIBTOMCRYPT_LTCRYPT) - - nuttx_add_application( - NAME - ${CONFIG_LIBTOMCRYPT_LTCRYPT_PROGNAME} - STACKSIZE - ${CONFIG_LIBTOMCRYPT_LTCRYPT_STACKSIZE} - PRIORITY - ${CONFIG_LIBTOMCRYPT_LTCRYPT_PRIORITY} - SRCS - ${LIBTOMCRYPT_DIR}/demos/ltcrypt.c - INCLUDE_DIRECTORIES - ${INCDIR} - DEPENDS - libtomcrypt) - - endif() - - if(CONFIG_LIBTOMCRYPT_HASHSUM) - - nuttx_add_application( - NAME - ${CONFIG_LIBTOMCRYPT_HASHSUM_PROGNAME} - STACKSIZE - ${CONFIG_LIBTOMCRYPT_HASHSUM_STACKSIZE} - PRIORITY - ${CONFIG_LIBTOMCRYPT_HASHSUM_PRIORITY} - SRCS - ${LIBTOMCRYPT_DIR}/demos/hashsum.c - INCLUDE_DIRECTORIES - ${INCDIR} - DEPENDS - libtomcrypt) - - endif() - - endif() - - # ############################################################################ - # Library Configuration - # ############################################################################ - - target_sources(libtomcrypt PRIVATE ${CSRCS}) - target_include_directories(libtomcrypt PRIVATE ${INCDIR}) - target_include_directories( - libtomcrypt - PRIVATE $<GENEX_EVAL:$<TARGET_PROPERTY:libtommath,INCLUDE_DIRECTORIES>>) - target_compile_definitions(libtomcrypt PRIVATE LTC_SOURCE LTM_DESC) - target_compile_options(libtomcrypt PRIVATE -Wno-deprecated-declarations) - -endif() diff --git a/crypto/libtomcrypt/Kconfig b/crypto/libtomcrypt/Kconfig index 2af14e6e1..ca8fc3f4e 100644 --- a/crypto/libtomcrypt/Kconfig +++ b/crypto/libtomcrypt/Kconfig @@ -54,6 +54,7 @@ endif # LIBTOMCRYPT_LTCRYPT config LIBTOMCRYPT_HASHSUM tristate "LibTomCrypt hashsum" + depends on SCHED_ATEXIT default n ---help--- Demo hashsum application @@ -78,28 +79,4 @@ endif # LIBTOMCRYPT_HASHSUM endif # LIBTOMCRYPT_DEMOS -menuconfig LIBTOMCRYPT_TEST - tristate "Enable LibTomCrypt tests" - default n - ---help--- - Enable LibTomCrypt tests. - -if LIBTOMCRYPT_TEST - -config LIBTOMCRYPT_TEST_PROGNAME - string "Program name" - default "libtomcrypt_test" - ---help--- - LibTomCrypt test priority program name - -config LIBTOMCRYPT_TEST_PRIORITY - int "LibTomCrypt test priority" - default 100 - -config LIBTOMCRYPT_TEST_STACKSIZE - int "LibTomCrypt test stack size" - default DEFAULT_TASK_STACKSIZE - -endif # LIBTOMCRYPT_TEST - endif # CRYPTO_LIBTOMCRYPT diff --git a/crypto/libtomcrypt/Make.defs b/crypto/libtomcrypt/Make.defs index 0fac308ff..2533123a2 100644 --- a/crypto/libtomcrypt/Make.defs +++ b/crypto/libtomcrypt/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/crypto/libtomcrypt/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -20,11 +18,11 @@ # ############################################################################ -ifneq ($(CONFIG_CRYPTO_LIBTOMCRYPT),) +ifeq ($(CONFIG_CRYPTO_LIBTOMCRYPT),y) CONFIGURED_APPS += $(APPDIR)/crypto/libtomcrypt # It allows `<tomcrypt.h>` import. -CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/crypto/libtomcrypt/libtomcrypt/src/headers -CXXFLAGS += ${INCDIR_PREFIX}$(APPDIR)/crypto/libtomcrypt/libtomcrypt/src/headers +CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(APPDIR)/crypto/libtomcrypt/libtomcrypt/src/headers/} +CXXFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(APPDIR)/crypto/libtomcrypt/libtomcrypt/src/headers/} endif diff --git a/crypto/libtomcrypt/Makefile b/crypto/libtomcrypt/Makefile index b4fe79fd6..c6b021105 100644 --- a/crypto/libtomcrypt/Makefile +++ b/crypto/libtomcrypt/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/crypto/libtomcrypt/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -22,445 +20,181 @@ include $(APPDIR)/Make.defs -CONFIG_LIBTOMCRYPT_URL ?= "https://github.com/libtom/libtomcrypt/archive" -LIBTOMCRYPT_VERSION = $(patsubst "%",%,$(strip $(CONFIG_LIBTOMCRYPT_VERSION))) -LIBTOMCRYPT_ZIP = v$(LIBTOMCRYPT_VERSION).zip - -LIBTOMCRYPT_UNPACKNAME = libtomcrypt -UNPACK ?= unzip -q -o - -CSRCS += \ - $(LIBTOMCRYPT_UNPACKNAME)/src/ciphers/aes/aes.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/ciphers/aes/aes_tab.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/ciphers/anubis.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/ciphers/blowfish.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/ciphers/camellia.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/ciphers/cast5.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/ciphers/des.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/ciphers/kasumi.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/ciphers/khazad.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/ciphers/kseed.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/ciphers/multi2.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/ciphers/noekeon.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/ciphers/rc2.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/ciphers/rc5.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/ciphers/rc6.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/ciphers/safer/safer.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/ciphers/safer/saferp.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/ciphers/skipjack.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/ciphers/twofish/twofish.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/ciphers/xtea.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/encauth/ccm/ccm_add_aad.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/encauth/ccm/ccm_add_nonce.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/encauth/ccm/ccm_done.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/encauth/ccm/ccm_init.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/encauth/ccm/ccm_memory.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/encauth/ccm/ccm_process.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/encauth/ccm/ccm_reset.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/encauth/ccm/ccm_test.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/encauth/chachapoly/chacha20poly1305_add_aad.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/encauth/chachapoly/chacha20poly1305_decrypt.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/encauth/chachapoly/chacha20poly1305_done.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/encauth/chachapoly/chacha20poly1305_encrypt.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/encauth/chachapoly/chacha20poly1305_init.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/encauth/chachapoly/chacha20poly1305_memory.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/encauth/chachapoly/chacha20poly1305_setiv.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/encauth/chachapoly/chacha20poly1305_setiv_rfc7905.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/encauth/chachapoly/chacha20poly1305_test.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/encauth/eax/eax_addheader.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/encauth/eax/eax_decrypt.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/encauth/eax/eax_decrypt_verify_memory.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/encauth/eax/eax_done.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/encauth/eax/eax_encrypt.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/encauth/eax/eax_encrypt_authenticate_memory.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/encauth/eax/eax_init.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/encauth/eax/eax_test.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/encauth/gcm/gcm_add_aad.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/encauth/gcm/gcm_add_iv.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/encauth/gcm/gcm_done.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/encauth/gcm/gcm_gf_mult.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/encauth/gcm/gcm_init.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/encauth/gcm/gcm_memory.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/encauth/gcm/gcm_mult_h.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/encauth/gcm/gcm_process.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/encauth/gcm/gcm_reset.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/encauth/gcm/gcm_test.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/encauth/ocb/ocb_decrypt.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/encauth/ocb/ocb_decrypt_verify_memory.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/encauth/ocb/ocb_done_decrypt.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/encauth/ocb/ocb_done_encrypt.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/encauth/ocb/ocb_encrypt.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/encauth/ocb/ocb_encrypt_authenticate_memory.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/encauth/ocb/ocb_init.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/encauth/ocb/ocb_ntz.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/encauth/ocb/ocb_shift_xor.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/encauth/ocb/ocb_test.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/encauth/ocb/s_ocb_done.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/encauth/ocb3/ocb3_add_aad.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/encauth/ocb3/ocb3_decrypt.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/encauth/ocb3/ocb3_decrypt_last.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/encauth/ocb3/ocb3_decrypt_verify_memory.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/encauth/ocb3/ocb3_done.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/encauth/ocb3/ocb3_encrypt.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/encauth/ocb3/ocb3_encrypt_authenticate_memory.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/encauth/ocb3/ocb3_encrypt_last.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/encauth/ocb3/ocb3_init.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/encauth/ocb3/ocb3_int_ntz.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/encauth/ocb3/ocb3_int_xor_blocks.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/encauth/ocb3/ocb3_test.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/hashes/blake2b.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/hashes/blake2s.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/hashes/chc/chc.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/hashes/helper/hash_file.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/hashes/helper/hash_filehandle.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/hashes/helper/hash_memory.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/hashes/helper/hash_memory_multi.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/hashes/md2.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/hashes/md4.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/hashes/md5.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/hashes/rmd128.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/hashes/rmd160.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/hashes/rmd256.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/hashes/rmd320.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/hashes/sha1.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/hashes/sha2/sha224.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/hashes/sha2/sha256.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/hashes/sha2/sha384.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/hashes/sha2/sha512.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/hashes/sha2/sha512_224.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/hashes/sha2/sha512_256.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/hashes/sha3.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/hashes/sha3_test.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/hashes/tiger.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/hashes/whirl/whirl.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/mac/blake2/blake2bmac.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/mac/blake2/blake2bmac_file.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/mac/blake2/blake2bmac_memory.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/mac/blake2/blake2bmac_memory_multi.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/mac/blake2/blake2bmac_test.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/mac/blake2/blake2smac.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/mac/blake2/blake2smac_file.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/mac/blake2/blake2smac_memory.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/mac/blake2/blake2smac_memory_multi.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/mac/blake2/blake2smac_test.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/mac/f9/f9_done.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/mac/f9/f9_file.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/mac/f9/f9_init.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/mac/f9/f9_memory.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/mac/f9/f9_memory_multi.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/mac/f9/f9_process.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/mac/f9/f9_test.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/mac/hmac/hmac_done.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/mac/hmac/hmac_file.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/mac/hmac/hmac_init.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/mac/hmac/hmac_memory.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/mac/hmac/hmac_memory_multi.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/mac/hmac/hmac_process.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/mac/hmac/hmac_test.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/mac/omac/omac_done.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/mac/omac/omac_file.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/mac/omac/omac_init.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/mac/omac/omac_memory.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/mac/omac/omac_memory_multi.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/mac/omac/omac_process.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/mac/omac/omac_test.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/mac/pelican/pelican.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/mac/pelican/pelican_memory.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/mac/pelican/pelican_test.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/mac/pmac/pmac_done.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/mac/pmac/pmac_file.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/mac/pmac/pmac_init.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/mac/pmac/pmac_memory.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/mac/pmac/pmac_memory_multi.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/mac/pmac/pmac_ntz.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/mac/pmac/pmac_process.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/mac/pmac/pmac_shift_xor.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/mac/pmac/pmac_test.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/mac/poly1305/poly1305.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/mac/poly1305/poly1305_file.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/mac/poly1305/poly1305_memory.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/mac/poly1305/poly1305_memory_multi.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/mac/poly1305/poly1305_test.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/mac/xcbc/xcbc_done.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/mac/xcbc/xcbc_file.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/mac/xcbc/xcbc_init.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/mac/xcbc/xcbc_memory.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/mac/xcbc/xcbc_memory_multi.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/mac/xcbc/xcbc_process.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/mac/xcbc/xcbc_test.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/math/fp/ltc_ecc_fp_mulmod.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/math/gmp_desc.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/math/ltm_desc.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/math/multi.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/math/radix_to_bin.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/math/rand_bn.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/math/rand_prime.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/math/tfm_desc.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/misc/adler32.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/misc/base64/base64_decode.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/misc/base64/base64_encode.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/misc/burn_stack.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/misc/compare_testvector.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/misc/crc32.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/misc/crypt/crypt.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/misc/crypt/crypt_argchk.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/misc/crypt/crypt_cipher_descriptor.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/misc/crypt/crypt_cipher_is_valid.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/misc/crypt/crypt_constants.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/misc/crypt/crypt_find_cipher.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/misc/crypt/crypt_find_cipher_any.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/misc/crypt/crypt_find_cipher_id.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/misc/crypt/crypt_find_hash.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/misc/crypt/crypt_find_hash_any.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/misc/crypt/crypt_find_hash_id.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/misc/crypt/crypt_find_hash_oid.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/misc/crypt/crypt_find_prng.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/misc/crypt/crypt_fsa.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/misc/crypt/crypt_hash_descriptor.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/misc/crypt/crypt_hash_is_valid.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/misc/crypt/crypt_inits.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/misc/crypt/crypt_ltc_mp_descriptor.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/misc/crypt/crypt_prng_descriptor.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/misc/crypt/crypt_prng_is_valid.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/misc/crypt/crypt_prng_rng_descriptor.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/misc/crypt/crypt_register_all_ciphers.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/misc/crypt/crypt_register_all_hashes.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/misc/crypt/crypt_register_all_prngs.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/misc/crypt/crypt_register_cipher.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/misc/crypt/crypt_register_hash.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/misc/crypt/crypt_register_prng.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/misc/crypt/crypt_sizes.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/misc/crypt/crypt_unregister_cipher.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/misc/crypt/crypt_unregister_hash.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/misc/crypt/crypt_unregister_prng.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/misc/error_to_string.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/misc/hkdf/hkdf.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/misc/hkdf/hkdf_test.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/misc/mem_neq.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/misc/pk_get_oid.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/misc/pkcs5/pkcs_5_1.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/misc/pkcs5/pkcs_5_2.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/misc/pkcs5/pkcs_5_test.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/misc/zeromem.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/modes/cbc/cbc_decrypt.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/modes/cbc/cbc_done.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/modes/cbc/cbc_encrypt.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/modes/cbc/cbc_getiv.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/modes/cbc/cbc_setiv.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/modes/cbc/cbc_start.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/modes/cfb/cfb_decrypt.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/modes/cfb/cfb_done.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/modes/cfb/cfb_encrypt.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/modes/cfb/cfb_getiv.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/modes/cfb/cfb_setiv.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/modes/cfb/cfb_start.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/modes/ctr/ctr_decrypt.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/modes/ctr/ctr_done.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/modes/ctr/ctr_encrypt.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/modes/ctr/ctr_getiv.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/modes/ctr/ctr_setiv.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/modes/ctr/ctr_start.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/modes/ctr/ctr_test.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/modes/ecb/ecb_decrypt.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/modes/ecb/ecb_done.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/modes/ecb/ecb_encrypt.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/modes/ecb/ecb_start.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/modes/f8/f8_decrypt.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/modes/f8/f8_done.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/modes/f8/f8_encrypt.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/modes/f8/f8_getiv.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/modes/f8/f8_setiv.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/modes/f8/f8_start.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/modes/f8/f8_test_mode.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/modes/lrw/lrw_decrypt.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/modes/lrw/lrw_done.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/modes/lrw/lrw_encrypt.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/modes/lrw/lrw_getiv.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/modes/lrw/lrw_process.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/modes/lrw/lrw_setiv.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/modes/lrw/lrw_start.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/modes/lrw/lrw_test.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/modes/ofb/ofb_decrypt.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/modes/ofb/ofb_done.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/modes/ofb/ofb_encrypt.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/modes/ofb/ofb_getiv.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/modes/ofb/ofb_setiv.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/modes/ofb/ofb_start.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/modes/xts/xts_decrypt.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/modes/xts/xts_done.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/modes/xts/xts_encrypt.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/modes/xts/xts_init.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/modes/xts/xts_mult_x.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/modes/xts/xts_test.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/asn1/der/bit/der_decode_bit_string.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/asn1/der/bit/der_decode_raw_bit_string.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/asn1/der/bit/der_encode_bit_string.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/asn1/der/bit/der_encode_raw_bit_string.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/asn1/der/bit/der_length_bit_string.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/asn1/der/boolean/der_decode_boolean.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/asn1/der/boolean/der_encode_boolean.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/asn1/der/boolean/der_length_boolean.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/asn1/der/choice/der_decode_choice.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/asn1/der/generalizedtime/der_decode_generalizedtime.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/asn1/der/generalizedtime/der_encode_generalizedtime.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/asn1/der/generalizedtime/der_length_generalizedtime.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/asn1/der/ia5/der_decode_ia5_string.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/asn1/der/ia5/der_encode_ia5_string.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/asn1/der/ia5/der_length_ia5_string.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/asn1/der/integer/der_decode_integer.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/asn1/der/integer/der_encode_integer.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/asn1/der/integer/der_length_integer.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/asn1/der/object_identifier/der_decode_object_identifier.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/asn1/der/object_identifier/der_encode_object_identifier.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/asn1/der/object_identifier/der_length_object_identifier.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/asn1/der/octet/der_decode_octet_string.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/asn1/der/octet/der_encode_octet_string.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/asn1/der/octet/der_length_octet_string.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/asn1/der/printable_string/der_decode_printable_string.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/asn1/der/printable_string/der_encode_printable_string.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/asn1/der/printable_string/der_length_printable_string.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/asn1/der/sequence/der_decode_sequence_ex.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/asn1/der/sequence/der_decode_sequence_flexi.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/asn1/der/sequence/der_decode_sequence_multi.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/asn1/der/sequence/der_decode_subject_public_key_info.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/asn1/der/sequence/der_encode_sequence_ex.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/asn1/der/sequence/der_encode_sequence_multi.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/asn1/der/sequence/der_encode_subject_public_key_info.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/asn1/der/sequence/der_length_sequence.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/asn1/der/sequence/der_sequence_free.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/asn1/der/sequence/der_sequence_shrink.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/asn1/der/set/der_encode_set.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/asn1/der/set/der_encode_setof.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/asn1/der/short_integer/der_decode_short_integer.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/asn1/der/short_integer/der_encode_short_integer.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/asn1/der/short_integer/der_length_short_integer.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/asn1/der/teletex_string/der_decode_teletex_string.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/asn1/der/teletex_string/der_length_teletex_string.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/asn1/der/utctime/der_decode_utctime.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/asn1/der/utctime/der_encode_utctime.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/asn1/der/utctime/der_length_utctime.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/asn1/der/utf8/der_decode_utf8_string.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/asn1/der/utf8/der_encode_utf8_string.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/asn1/der/utf8/der_length_utf8_string.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/dh/dh.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/dh/dh_check_pubkey.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/dh/dh_export.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/dh/dh_export_key.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/dh/dh_free.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/dh/dh_generate_key.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/dh/dh_import.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/dh/dh_set.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/dh/dh_set_pg_dhparam.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/dh/dh_shared_secret.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/dsa/dsa_decrypt_key.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/dsa/dsa_encrypt_key.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/dsa/dsa_export.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/dsa/dsa_free.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/dsa/dsa_generate_key.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/dsa/dsa_generate_pqg.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/dsa/dsa_import.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/dsa/dsa_make_key.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/dsa/dsa_set.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/dsa/dsa_set_pqg_dsaparam.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/dsa/dsa_shared_secret.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/dsa/dsa_sign_hash.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/dsa/dsa_verify_hash.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/dsa/dsa_verify_key.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/ecc/ecc.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/ecc/ecc_ansi_x963_export.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/ecc/ecc_ansi_x963_import.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/ecc/ecc_decrypt_key.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/ecc/ecc_encrypt_key.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/ecc/ecc_export.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/ecc/ecc_free.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/ecc/ecc_get_size.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/ecc/ecc_import.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/ecc/ecc_make_key.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/ecc/ecc_shared_secret.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/ecc/ecc_sign_hash.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/ecc/ecc_sizes.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/ecc/ecc_test.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/ecc/ecc_verify_hash.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/ecc/ltc_ecc_is_valid_idx.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/ecc/ltc_ecc_map.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/ecc/ltc_ecc_mul2add.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/ecc/ltc_ecc_mulmod.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/ecc/ltc_ecc_mulmod_timing.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/ecc/ltc_ecc_points.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/ecc/ltc_ecc_projective_add_point.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/ecc/ltc_ecc_projective_dbl_point.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/katja/katja_decrypt_key.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/katja/katja_encrypt_key.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/katja/katja_export.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/katja/katja_exptmod.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/katja/katja_free.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/katja/katja_import.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/katja/katja_make_key.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/pkcs1/pkcs_1_i2osp.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/pkcs1/pkcs_1_mgf1.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/pkcs1/pkcs_1_oaep_decode.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/pkcs1/pkcs_1_oaep_encode.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/pkcs1/pkcs_1_os2ip.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/pkcs1/pkcs_1_pss_decode.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/pkcs1/pkcs_1_pss_encode.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/pkcs1/pkcs_1_v1_5_decode.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/pkcs1/pkcs_1_v1_5_encode.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/rsa/rsa_decrypt_key.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/rsa/rsa_encrypt_key.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/rsa/rsa_export.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/rsa/rsa_exptmod.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/rsa/rsa_free.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/rsa/rsa_get_size.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/rsa/rsa_import.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/rsa/rsa_import_pkcs8.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/rsa/rsa_import_x509.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/rsa/rsa_make_key.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/rsa/rsa_set.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/rsa/rsa_sign_hash.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/rsa/rsa_sign_saltlen_get.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/pk/rsa/rsa_verify_hash.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/prngs/chacha20.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/prngs/fortuna.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/prngs/rc4.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/prngs/rng_get_bytes.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/prngs/rng_make_prng.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/prngs/sober128.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/prngs/sprng.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/prngs/yarrow.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/stream/chacha/chacha_crypt.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/stream/chacha/chacha_done.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/stream/chacha/chacha_ivctr32.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/stream/chacha/chacha_ivctr64.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/stream/chacha/chacha_keystream.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/stream/chacha/chacha_setup.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/stream/chacha/chacha_test.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/stream/rc4/rc4_stream.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/stream/rc4/rc4_test.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/stream/sober128/sober128_stream.c \ - $(LIBTOMCRYPT_UNPACKNAME)/src/stream/sober128/sober128_test.c +CSRCS += libtomcrypt/src/ciphers/aes/aes.c libtomcrypt/src/ciphers/aes/aes_tab.c libtomcrypt/src/ciphers/anubis.c libtomcrypt/src/ciphers/blowfish.c \ +libtomcrypt/src/ciphers/camellia.c libtomcrypt/src/ciphers/cast5.c libtomcrypt/src/ciphers/des.c libtomcrypt/src/ciphers/kasumi.c libtomcrypt/src/ciphers/khazad.c \ +libtomcrypt/src/ciphers/kseed.c libtomcrypt/src/ciphers/multi2.c libtomcrypt/src/ciphers/noekeon.c libtomcrypt/src/ciphers/rc2.c libtomcrypt/src/ciphers/rc5.c \ +libtomcrypt/src/ciphers/rc6.c libtomcrypt/src/ciphers/safer/safer.c libtomcrypt/src/ciphers/safer/saferp.c libtomcrypt/src/ciphers/skipjack.c \ +libtomcrypt/src/ciphers/twofish/twofish.c libtomcrypt/src/ciphers/xtea.c libtomcrypt/src/encauth/ccm/ccm_add_aad.c \ +libtomcrypt/src/encauth/ccm/ccm_add_nonce.c libtomcrypt/src/encauth/ccm/ccm_done.c libtomcrypt/src/encauth/ccm/ccm_init.c \ +libtomcrypt/src/encauth/ccm/ccm_memory.c libtomcrypt/src/encauth/ccm/ccm_process.c libtomcrypt/src/encauth/ccm/ccm_reset.c \ +libtomcrypt/src/encauth/ccm/ccm_test.c libtomcrypt/src/encauth/chachapoly/chacha20poly1305_add_aad.c \ +libtomcrypt/src/encauth/chachapoly/chacha20poly1305_decrypt.c libtomcrypt/src/encauth/chachapoly/chacha20poly1305_done.c \ +libtomcrypt/src/encauth/chachapoly/chacha20poly1305_encrypt.c libtomcrypt/src/encauth/chachapoly/chacha20poly1305_init.c \ +libtomcrypt/src/encauth/chachapoly/chacha20poly1305_memory.c libtomcrypt/src/encauth/chachapoly/chacha20poly1305_setiv.c \ +libtomcrypt/src/encauth/chachapoly/chacha20poly1305_setiv_rfc7905.c \ +libtomcrypt/src/encauth/chachapoly/chacha20poly1305_test.c libtomcrypt/src/encauth/eax/eax_addheader.c \ +libtomcrypt/src/encauth/eax/eax_decrypt.c libtomcrypt/src/encauth/eax/eax_decrypt_verify_memory.c libtomcrypt/src/encauth/eax/eax_done.c \ +libtomcrypt/src/encauth/eax/eax_encrypt.c libtomcrypt/src/encauth/eax/eax_encrypt_authenticate_memory.c \ +libtomcrypt/src/encauth/eax/eax_init.c libtomcrypt/src/encauth/eax/eax_test.c libtomcrypt/src/encauth/gcm/gcm_add_aad.c \ +libtomcrypt/src/encauth/gcm/gcm_add_iv.c libtomcrypt/src/encauth/gcm/gcm_done.c libtomcrypt/src/encauth/gcm/gcm_gf_mult.c \ +libtomcrypt/src/encauth/gcm/gcm_init.c libtomcrypt/src/encauth/gcm/gcm_memory.c libtomcrypt/src/encauth/gcm/gcm_mult_h.c \ +libtomcrypt/src/encauth/gcm/gcm_process.c libtomcrypt/src/encauth/gcm/gcm_reset.c libtomcrypt/src/encauth/gcm/gcm_test.c \ +libtomcrypt/src/encauth/ocb/ocb_decrypt.c libtomcrypt/src/encauth/ocb/ocb_decrypt_verify_memory.c \ +libtomcrypt/src/encauth/ocb/ocb_done_decrypt.c libtomcrypt/src/encauth/ocb/ocb_done_encrypt.c libtomcrypt/src/encauth/ocb/ocb_encrypt.c \ +libtomcrypt/src/encauth/ocb/ocb_encrypt_authenticate_memory.c libtomcrypt/src/encauth/ocb/ocb_init.c libtomcrypt/src/encauth/ocb/ocb_ntz.c \ +libtomcrypt/src/encauth/ocb/ocb_shift_xor.c libtomcrypt/src/encauth/ocb/ocb_test.c libtomcrypt/src/encauth/ocb/s_ocb_done.c \ +libtomcrypt/src/encauth/ocb3/ocb3_add_aad.c libtomcrypt/src/encauth/ocb3/ocb3_decrypt.c libtomcrypt/src/encauth/ocb3/ocb3_decrypt_last.c \ +libtomcrypt/src/encauth/ocb3/ocb3_decrypt_verify_memory.c libtomcrypt/src/encauth/ocb3/ocb3_done.c \ +libtomcrypt/src/encauth/ocb3/ocb3_encrypt.c libtomcrypt/src/encauth/ocb3/ocb3_encrypt_authenticate_memory.c \ +libtomcrypt/src/encauth/ocb3/ocb3_encrypt_last.c libtomcrypt/src/encauth/ocb3/ocb3_init.c libtomcrypt/src/encauth/ocb3/ocb3_int_ntz.c \ +libtomcrypt/src/encauth/ocb3/ocb3_int_xor_blocks.c libtomcrypt/src/encauth/ocb3/ocb3_test.c libtomcrypt/src/hashes/blake2b.c \ +libtomcrypt/src/hashes/blake2s.c libtomcrypt/src/hashes/chc/chc.c libtomcrypt/src/hashes/helper/hash_file.c \ +libtomcrypt/src/hashes/helper/hash_filehandle.c libtomcrypt/src/hashes/helper/hash_memory.c \ +libtomcrypt/src/hashes/helper/hash_memory_multi.c libtomcrypt/src/hashes/md2.c libtomcrypt/src/hashes/md4.c libtomcrypt/src/hashes/md5.c \ +libtomcrypt/src/hashes/rmd128.c libtomcrypt/src/hashes/rmd160.c libtomcrypt/src/hashes/rmd256.c libtomcrypt/src/hashes/rmd320.c libtomcrypt/src/hashes/sha1.c \ +libtomcrypt/src/hashes/sha2/sha224.c libtomcrypt/src/hashes/sha2/sha256.c libtomcrypt/src/hashes/sha2/sha384.c libtomcrypt/src/hashes/sha2/sha512.c \ +libtomcrypt/src/hashes/sha2/sha512_224.c libtomcrypt/src/hashes/sha2/sha512_256.c libtomcrypt/src/hashes/sha3.c libtomcrypt/src/hashes/sha3_test.c \ +libtomcrypt/src/hashes/tiger.c libtomcrypt/src/hashes/whirl/whirl.c libtomcrypt/src/mac/blake2/blake2bmac.c \ +libtomcrypt/src/mac/blake2/blake2bmac_file.c libtomcrypt/src/mac/blake2/blake2bmac_memory.c \ +libtomcrypt/src/mac/blake2/blake2bmac_memory_multi.c libtomcrypt/src/mac/blake2/blake2bmac_test.c libtomcrypt/src/mac/blake2/blake2smac.c \ +libtomcrypt/src/mac/blake2/blake2smac_file.c libtomcrypt/src/mac/blake2/blake2smac_memory.c \ +libtomcrypt/src/mac/blake2/blake2smac_memory_multi.c libtomcrypt/src/mac/blake2/blake2smac_test.c libtomcrypt/src/mac/f9/f9_done.c \ +libtomcrypt/src/mac/f9/f9_file.c libtomcrypt/src/mac/f9/f9_init.c libtomcrypt/src/mac/f9/f9_memory.c libtomcrypt/src/mac/f9/f9_memory_multi.c \ +libtomcrypt/src/mac/f9/f9_process.c libtomcrypt/src/mac/f9/f9_test.c libtomcrypt/src/mac/hmac/hmac_done.c libtomcrypt/src/mac/hmac/hmac_file.c \ +libtomcrypt/src/mac/hmac/hmac_init.c libtomcrypt/src/mac/hmac/hmac_memory.c libtomcrypt/src/mac/hmac/hmac_memory_multi.c \ +libtomcrypt/src/mac/hmac/hmac_process.c libtomcrypt/src/mac/hmac/hmac_test.c libtomcrypt/src/mac/omac/omac_done.c libtomcrypt/src/mac/omac/omac_file.c \ +libtomcrypt/src/mac/omac/omac_init.c libtomcrypt/src/mac/omac/omac_memory.c libtomcrypt/src/mac/omac/omac_memory_multi.c \ +libtomcrypt/src/mac/omac/omac_process.c libtomcrypt/src/mac/omac/omac_test.c libtomcrypt/src/mac/pelican/pelican.c \ +libtomcrypt/src/mac/pelican/pelican_memory.c libtomcrypt/src/mac/pelican/pelican_test.c libtomcrypt/src/mac/pmac/pmac_done.c \ +libtomcrypt/src/mac/pmac/pmac_file.c libtomcrypt/src/mac/pmac/pmac_init.c libtomcrypt/src/mac/pmac/pmac_memory.c \ +libtomcrypt/src/mac/pmac/pmac_memory_multi.c libtomcrypt/src/mac/pmac/pmac_ntz.c libtomcrypt/src/mac/pmac/pmac_process.c \ +libtomcrypt/src/mac/pmac/pmac_shift_xor.c libtomcrypt/src/mac/pmac/pmac_test.c libtomcrypt/src/mac/poly1305/poly1305.c \ +libtomcrypt/src/mac/poly1305/poly1305_file.c libtomcrypt/src/mac/poly1305/poly1305_memory.c \ +libtomcrypt/src/mac/poly1305/poly1305_memory_multi.c libtomcrypt/src/mac/poly1305/poly1305_test.c libtomcrypt/src/mac/xcbc/xcbc_done.c \ +libtomcrypt/src/mac/xcbc/xcbc_file.c libtomcrypt/src/mac/xcbc/xcbc_init.c libtomcrypt/src/mac/xcbc/xcbc_memory.c \ +libtomcrypt/src/mac/xcbc/xcbc_memory_multi.c libtomcrypt/src/mac/xcbc/xcbc_process.c libtomcrypt/src/mac/xcbc/xcbc_test.c \ +libtomcrypt/src/math/fp/ltc_ecc_fp_mulmod.c libtomcrypt/src/math/gmp_desc.c libtomcrypt/src/math/ltm_desc.c libtomcrypt/src/math/multi.c \ +libtomcrypt/src/math/radix_to_bin.c libtomcrypt/src/math/rand_bn.c libtomcrypt/src/math/rand_prime.c libtomcrypt/src/math/tfm_desc.c libtomcrypt/src/misc/adler32.c \ +libtomcrypt/src/misc/base64/base64_decode.c libtomcrypt/src/misc/base64/base64_encode.c libtomcrypt/src/misc/burn_stack.c \ +libtomcrypt/src/misc/compare_testvector.c libtomcrypt/src/misc/crc32.c libtomcrypt/src/misc/crypt/crypt.c libtomcrypt/src/misc/crypt/crypt_argchk.c \ +libtomcrypt/src/misc/crypt/crypt_cipher_descriptor.c libtomcrypt/src/misc/crypt/crypt_cipher_is_valid.c \ +libtomcrypt/src/misc/crypt/crypt_constants.c libtomcrypt/src/misc/crypt/crypt_find_cipher.c \ +libtomcrypt/src/misc/crypt/crypt_find_cipher_any.c libtomcrypt/src/misc/crypt/crypt_find_cipher_id.c \ +libtomcrypt/src/misc/crypt/crypt_find_hash.c libtomcrypt/src/misc/crypt/crypt_find_hash_any.c \ +libtomcrypt/src/misc/crypt/crypt_find_hash_id.c libtomcrypt/src/misc/crypt/crypt_find_hash_oid.c \ +libtomcrypt/src/misc/crypt/crypt_find_prng.c libtomcrypt/src/misc/crypt/crypt_fsa.c libtomcrypt/src/misc/crypt/crypt_hash_descriptor.c \ +libtomcrypt/src/misc/crypt/crypt_hash_is_valid.c libtomcrypt/src/misc/crypt/crypt_inits.c \ +libtomcrypt/src/misc/crypt/crypt_ltc_mp_descriptor.c libtomcrypt/src/misc/crypt/crypt_prng_descriptor.c \ +libtomcrypt/src/misc/crypt/crypt_prng_is_valid.c libtomcrypt/src/misc/crypt/crypt_prng_rng_descriptor.c \ +libtomcrypt/src/misc/crypt/crypt_register_all_ciphers.c libtomcrypt/src/misc/crypt/crypt_register_all_hashes.c \ +libtomcrypt/src/misc/crypt/crypt_register_all_prngs.c libtomcrypt/src/misc/crypt/crypt_register_cipher.c \ +libtomcrypt/src/misc/crypt/crypt_register_hash.c libtomcrypt/src/misc/crypt/crypt_register_prng.c libtomcrypt/src/misc/crypt/crypt_sizes.c \ +libtomcrypt/src/misc/crypt/crypt_unregister_cipher.c libtomcrypt/src/misc/crypt/crypt_unregister_hash.c \ +libtomcrypt/src/misc/crypt/crypt_unregister_prng.c libtomcrypt/src/misc/error_to_string.c libtomcrypt/src/misc/hkdf/hkdf.c \ +libtomcrypt/src/misc/hkdf/hkdf_test.c libtomcrypt/src/misc/mem_neq.c libtomcrypt/src/misc/pk_get_oid.c libtomcrypt/src/misc/pkcs5/pkcs_5_1.c \ +libtomcrypt/src/misc/pkcs5/pkcs_5_2.c libtomcrypt/src/misc/pkcs5/pkcs_5_test.c libtomcrypt/src/misc/zeromem.c libtomcrypt/src/modes/cbc/cbc_decrypt.c \ +libtomcrypt/src/modes/cbc/cbc_done.c libtomcrypt/src/modes/cbc/cbc_encrypt.c libtomcrypt/src/modes/cbc/cbc_getiv.c \ +libtomcrypt/src/modes/cbc/cbc_setiv.c libtomcrypt/src/modes/cbc/cbc_start.c libtomcrypt/src/modes/cfb/cfb_decrypt.c \ +libtomcrypt/src/modes/cfb/cfb_done.c libtomcrypt/src/modes/cfb/cfb_encrypt.c libtomcrypt/src/modes/cfb/cfb_getiv.c \ +libtomcrypt/src/modes/cfb/cfb_setiv.c libtomcrypt/src/modes/cfb/cfb_start.c libtomcrypt/src/modes/ctr/ctr_decrypt.c \ +libtomcrypt/src/modes/ctr/ctr_done.c libtomcrypt/src/modes/ctr/ctr_encrypt.c libtomcrypt/src/modes/ctr/ctr_getiv.c \ +libtomcrypt/src/modes/ctr/ctr_setiv.c libtomcrypt/src/modes/ctr/ctr_start.c libtomcrypt/src/modes/ctr/ctr_test.c \ +libtomcrypt/src/modes/ecb/ecb_decrypt.c libtomcrypt/src/modes/ecb/ecb_done.c libtomcrypt/src/modes/ecb/ecb_encrypt.c \ +libtomcrypt/src/modes/ecb/ecb_start.c libtomcrypt/src/modes/f8/f8_decrypt.c libtomcrypt/src/modes/f8/f8_done.c libtomcrypt/src/modes/f8/f8_encrypt.c \ +libtomcrypt/src/modes/f8/f8_getiv.c libtomcrypt/src/modes/f8/f8_setiv.c libtomcrypt/src/modes/f8/f8_start.c libtomcrypt/src/modes/f8/f8_test_mode.c \ +libtomcrypt/src/modes/lrw/lrw_decrypt.c libtomcrypt/src/modes/lrw/lrw_done.c libtomcrypt/src/modes/lrw/lrw_encrypt.c \ +libtomcrypt/src/modes/lrw/lrw_getiv.c libtomcrypt/src/modes/lrw/lrw_process.c libtomcrypt/src/modes/lrw/lrw_setiv.c \ +libtomcrypt/src/modes/lrw/lrw_start.c libtomcrypt/src/modes/lrw/lrw_test.c libtomcrypt/src/modes/ofb/ofb_decrypt.c libtomcrypt/src/modes/ofb/ofb_done.c \ +libtomcrypt/src/modes/ofb/ofb_encrypt.c libtomcrypt/src/modes/ofb/ofb_getiv.c libtomcrypt/src/modes/ofb/ofb_setiv.c \ +libtomcrypt/src/modes/ofb/ofb_start.c libtomcrypt/src/modes/xts/xts_decrypt.c libtomcrypt/src/modes/xts/xts_done.c \ +libtomcrypt/src/modes/xts/xts_encrypt.c libtomcrypt/src/modes/xts/xts_init.c libtomcrypt/src/modes/xts/xts_mult_x.c \ +libtomcrypt/src/modes/xts/xts_test.c libtomcrypt/src/pk/asn1/der/bit/der_decode_bit_string.c \ +libtomcrypt/src/pk/asn1/der/bit/der_decode_raw_bit_string.c libtomcrypt/src/pk/asn1/der/bit/der_encode_bit_string.c \ +libtomcrypt/src/pk/asn1/der/bit/der_encode_raw_bit_string.c libtomcrypt/src/pk/asn1/der/bit/der_length_bit_string.c \ +libtomcrypt/src/pk/asn1/der/boolean/der_decode_boolean.c libtomcrypt/src/pk/asn1/der/boolean/der_encode_boolean.c \ +libtomcrypt/src/pk/asn1/der/boolean/der_length_boolean.c libtomcrypt/src/pk/asn1/der/choice/der_decode_choice.c \ +libtomcrypt/src/pk/asn1/der/generalizedtime/der_decode_generalizedtime.c \ +libtomcrypt/src/pk/asn1/der/generalizedtime/der_encode_generalizedtime.c \ +libtomcrypt/src/pk/asn1/der/generalizedtime/der_length_generalizedtime.c \ +libtomcrypt/src/pk/asn1/der/ia5/der_decode_ia5_string.c libtomcrypt/src/pk/asn1/der/ia5/der_encode_ia5_string.c \ +libtomcrypt/src/pk/asn1/der/ia5/der_length_ia5_string.c libtomcrypt/src/pk/asn1/der/integer/der_decode_integer.c \ +libtomcrypt/src/pk/asn1/der/integer/der_encode_integer.c libtomcrypt/src/pk/asn1/der/integer/der_length_integer.c \ +libtomcrypt/src/pk/asn1/der/object_identifier/der_decode_object_identifier.c \ +libtomcrypt/src/pk/asn1/der/object_identifier/der_encode_object_identifier.c \ +libtomcrypt/src/pk/asn1/der/object_identifier/der_length_object_identifier.c \ +libtomcrypt/src/pk/asn1/der/octet/der_decode_octet_string.c libtomcrypt/src/pk/asn1/der/octet/der_encode_octet_string.c \ +libtomcrypt/src/pk/asn1/der/octet/der_length_octet_string.c \ +libtomcrypt/src/pk/asn1/der/printable_string/der_decode_printable_string.c \ +libtomcrypt/src/pk/asn1/der/printable_string/der_encode_printable_string.c \ +libtomcrypt/src/pk/asn1/der/printable_string/der_length_printable_string.c \ +libtomcrypt/src/pk/asn1/der/sequence/der_decode_sequence_ex.c \ +libtomcrypt/src/pk/asn1/der/sequence/der_decode_sequence_flexi.c \ +libtomcrypt/src/pk/asn1/der/sequence/der_decode_sequence_multi.c \ +libtomcrypt/src/pk/asn1/der/sequence/der_decode_subject_public_key_info.c \ +libtomcrypt/src/pk/asn1/der/sequence/der_encode_sequence_ex.c \ +libtomcrypt/src/pk/asn1/der/sequence/der_encode_sequence_multi.c \ +libtomcrypt/src/pk/asn1/der/sequence/der_encode_subject_public_key_info.c \ +libtomcrypt/src/pk/asn1/der/sequence/der_length_sequence.c libtomcrypt/src/pk/asn1/der/sequence/der_sequence_free.c \ +libtomcrypt/src/pk/asn1/der/sequence/der_sequence_shrink.c libtomcrypt/src/pk/asn1/der/set/der_encode_set.c \ +libtomcrypt/src/pk/asn1/der/set/der_encode_setof.c libtomcrypt/src/pk/asn1/der/short_integer/der_decode_short_integer.c \ +libtomcrypt/src/pk/asn1/der/short_integer/der_encode_short_integer.c \ +libtomcrypt/src/pk/asn1/der/short_integer/der_length_short_integer.c \ +libtomcrypt/src/pk/asn1/der/teletex_string/der_decode_teletex_string.c \ +libtomcrypt/src/pk/asn1/der/teletex_string/der_length_teletex_string.c \ +libtomcrypt/src/pk/asn1/der/utctime/der_decode_utctime.c libtomcrypt/src/pk/asn1/der/utctime/der_encode_utctime.c \ +libtomcrypt/src/pk/asn1/der/utctime/der_length_utctime.c libtomcrypt/src/pk/asn1/der/utf8/der_decode_utf8_string.c \ +libtomcrypt/src/pk/asn1/der/utf8/der_encode_utf8_string.c libtomcrypt/src/pk/asn1/der/utf8/der_length_utf8_string.c \ +libtomcrypt/src/pk/dh/dh.c libtomcrypt/src/pk/dh/dh_check_pubkey.c libtomcrypt/src/pk/dh/dh_export.c libtomcrypt/src/pk/dh/dh_export_key.c \ +libtomcrypt/src/pk/dh/dh_free.c libtomcrypt/src/pk/dh/dh_generate_key.c libtomcrypt/src/pk/dh/dh_import.c libtomcrypt/src/pk/dh/dh_set.c \ +libtomcrypt/src/pk/dh/dh_set_pg_dhparam.c libtomcrypt/src/pk/dh/dh_shared_secret.c libtomcrypt/src/pk/dsa/dsa_decrypt_key.c \ +libtomcrypt/src/pk/dsa/dsa_encrypt_key.c libtomcrypt/src/pk/dsa/dsa_export.c libtomcrypt/src/pk/dsa/dsa_free.c \ +libtomcrypt/src/pk/dsa/dsa_generate_key.c libtomcrypt/src/pk/dsa/dsa_generate_pqg.c libtomcrypt/src/pk/dsa/dsa_import.c \ +libtomcrypt/src/pk/dsa/dsa_make_key.c libtomcrypt/src/pk/dsa/dsa_set.c libtomcrypt/src/pk/dsa/dsa_set_pqg_dsaparam.c \ +libtomcrypt/src/pk/dsa/dsa_shared_secret.c libtomcrypt/src/pk/dsa/dsa_sign_hash.c libtomcrypt/src/pk/dsa/dsa_verify_hash.c \ +libtomcrypt/src/pk/dsa/dsa_verify_key.c libtomcrypt/src/pk/ecc/ecc.c libtomcrypt/src/pk/ecc/ecc_ansi_x963_export.c \ +libtomcrypt/src/pk/ecc/ecc_ansi_x963_import.c libtomcrypt/src/pk/ecc/ecc_decrypt_key.c libtomcrypt/src/pk/ecc/ecc_encrypt_key.c \ +libtomcrypt/src/pk/ecc/ecc_export.c libtomcrypt/src/pk/ecc/ecc_free.c libtomcrypt/src/pk/ecc/ecc_get_size.c libtomcrypt/src/pk/ecc/ecc_import.c \ +libtomcrypt/src/pk/ecc/ecc_make_key.c libtomcrypt/src/pk/ecc/ecc_shared_secret.c libtomcrypt/src/pk/ecc/ecc_sign_hash.c \ +libtomcrypt/src/pk/ecc/ecc_sizes.c libtomcrypt/src/pk/ecc/ecc_test.c libtomcrypt/src/pk/ecc/ecc_verify_hash.c \ +libtomcrypt/src/pk/ecc/ltc_ecc_is_valid_idx.c libtomcrypt/src/pk/ecc/ltc_ecc_map.c libtomcrypt/src/pk/ecc/ltc_ecc_mul2add.c \ +libtomcrypt/src/pk/ecc/ltc_ecc_mulmod.c libtomcrypt/src/pk/ecc/ltc_ecc_mulmod_timing.c libtomcrypt/src/pk/ecc/ltc_ecc_points.c \ +libtomcrypt/src/pk/ecc/ltc_ecc_projective_add_point.c libtomcrypt/src/pk/ecc/ltc_ecc_projective_dbl_point.c \ +libtomcrypt/src/pk/katja/katja_decrypt_key.c libtomcrypt/src/pk/katja/katja_encrypt_key.c libtomcrypt/src/pk/katja/katja_export.c \ +libtomcrypt/src/pk/katja/katja_exptmod.c libtomcrypt/src/pk/katja/katja_free.c libtomcrypt/src/pk/katja/katja_import.c \ +libtomcrypt/src/pk/katja/katja_make_key.c libtomcrypt/src/pk/pkcs1/pkcs_1_i2osp.c libtomcrypt/src/pk/pkcs1/pkcs_1_mgf1.c \ +libtomcrypt/src/pk/pkcs1/pkcs_1_oaep_decode.c libtomcrypt/src/pk/pkcs1/pkcs_1_oaep_encode.c libtomcrypt/src/pk/pkcs1/pkcs_1_os2ip.c \ +libtomcrypt/src/pk/pkcs1/pkcs_1_pss_decode.c libtomcrypt/src/pk/pkcs1/pkcs_1_pss_encode.c libtomcrypt/src/pk/pkcs1/pkcs_1_v1_5_decode.c \ +libtomcrypt/src/pk/pkcs1/pkcs_1_v1_5_encode.c libtomcrypt/src/pk/rsa/rsa_decrypt_key.c libtomcrypt/src/pk/rsa/rsa_encrypt_key.c \ +libtomcrypt/src/pk/rsa/rsa_export.c libtomcrypt/src/pk/rsa/rsa_exptmod.c libtomcrypt/src/pk/rsa/rsa_free.c libtomcrypt/src/pk/rsa/rsa_get_size.c \ +libtomcrypt/src/pk/rsa/rsa_import.c libtomcrypt/src/pk/rsa/rsa_import_pkcs8.c libtomcrypt/src/pk/rsa/rsa_import_x509.c \ +libtomcrypt/src/pk/rsa/rsa_make_key.c libtomcrypt/src/pk/rsa/rsa_set.c libtomcrypt/src/pk/rsa/rsa_sign_hash.c \ +libtomcrypt/src/pk/rsa/rsa_sign_saltlen_get.c libtomcrypt/src/pk/rsa/rsa_verify_hash.c libtomcrypt/src/prngs/chacha20.c libtomcrypt/src/prngs/fortuna.c \ +libtomcrypt/src/prngs/rc4.c libtomcrypt/src/prngs/rng_get_bytes.c libtomcrypt/src/prngs/rng_make_prng.c libtomcrypt/src/prngs/sober128.c \ +libtomcrypt/src/prngs/sprng.c libtomcrypt/src/prngs/yarrow.c libtomcrypt/src/stream/chacha/chacha_crypt.c libtomcrypt/src/stream/chacha/chacha_done.c \ +libtomcrypt/src/stream/chacha/chacha_ivctr32.c libtomcrypt/src/stream/chacha/chacha_ivctr64.c \ +libtomcrypt/src/stream/chacha/chacha_keystream.c libtomcrypt/src/stream/chacha/chacha_setup.c libtomcrypt/src/stream/chacha/chacha_test.c \ +libtomcrypt/src/stream/rc4/rc4_stream.c libtomcrypt/src/stream/rc4/rc4_test.c libtomcrypt/src/stream/sober128/sober128_stream.c \ +libtomcrypt/src/stream/sober128/sober128_test.c CFLAGS += -DLTC_SOURCE -DLTM_DESC CFLAGS += -Wno-deprecated-declarations -CFLAGS += -Dblake2s_init=libtomcrypt_blake2s_init -CFLAGS += -Dmd5_init=libtomcrypt_md5_init -#CFLAGS += -Wno-format + +#CFLAGS += -Wno-format -DLTC_SOURCE ifneq ($(CONFIG_LIBTOMCRYPT_DEMOS),) ifneq ($(CONFIG_LIBTOMCRYPT_LTCRYPT),) -MAINSRC += $(LIBTOMCRYPT_UNPACKNAME)/demos/ltcrypt.c +MAINSRC += libtomcrypt/demos/ltcrypt.c -MODULE += $(CONFIG_LIBTOMCRYPT_LTCRYPT) PROGNAME += $(CONFIG_LIBTOMCRYPT_LTCRYPT_PROGNAME) PRIORITY += $(CONFIG_LIBTOMCRYPT_LTCRYPT_PRIORITY) STACKSIZE += $(CONFIG_LIBTOMCRYPT_LTCRYPT_STACKSIZE) endif ifneq ($(CONFIG_LIBTOMCRYPT_HASHSUM),) -MAINSRC += $(LIBTOMCRYPT_UNPACKNAME)/demos/hashsum.c +MAINSRC += libtomcrypt/demos/hashsum.c -MODULE += $(CONFIG_LIBTOMCRYPT_HASHSUM) PROGNAME += $(CONFIG_LIBTOMCRYPT_HASHSUM_PROGNAME) PRIORITY += $(CONFIG_LIBTOMCRYPT_HASHSUM_PRIORITY) STACKSIZE += $(CONFIG_LIBTOMCRYPT_HASHSUM_STACKSIZE) @@ -468,23 +202,13 @@ endif endif -ifneq ($(CONFIG_LIBTOMCRYPT_TEST),) -${shell mkdir -p $(BOARD_DIR)/resource/libtomcrypt} -${shell cp libtomcrypt/tests/*.key $(BOARD_DIR)/resource/libtomcrypt} -${shell cp libtomcrypt/tests/*.der $(BOARD_DIR)/resource/libtomcrypt} -CFLAGS += -DKEY_DIR=\"/resource/libtomcrypt\" -CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/crypto/libtomcrypt/libtomcrypt/tests -CFLAGS += -Dbase64_decode=libtomcrypt_base64_decode -CFLAGS += -Dbase64_encode=libtomcrypt_encode -NEWSRC := $(wildcard libtomcrypt/tests/*.c) -CSRCS += $(filter-out $(LIBTOMCRYPT_UNPACKNAME)/tests/test.c, $(NEWSRC)) -MAINSRC += $(LIBTOMCRYPT_UNPACKNAME)/tests/test.c +CONFIG_LIBTOMCRYPT_URL ?= "https://github.com/libtom/libtomcrypt/archive" -MODULE += $(CONFIG_LIBTOMCRYPT_TEST) -PROGNAME += $(CONFIG_LIBTOMCRYPT_TEST_PROGNAME) -PRIORITY += $(CONFIG_LIBTOMCRYPT_TEST_PRIORITY) -STACKSIZE += $(CONFIG_LIBTOMCRYPT_TEST_STACKSIZE) -endif +LIBTOMCRYPT_UNPACKNAME = libtomcrypt +LIBTOMCRYPT_VERSION = $(patsubst "%",%,$(strip $(CONFIG_LIBTOMCRYPT_VERSION))) +LIBTOMCRYPT_ZIP = v$(LIBTOMCRYPT_VERSION).zip + +UNPACK ?= unzip -o $(LIBTOMCRYPT_ZIP): @echo "Downloading: $(LIBTOMCRYPT_ZIP)" @@ -499,13 +223,10 @@ $(LIBTOMCRYPT_UNPACKNAME): $(LIBTOMCRYPT_ZIP) $(Q) patch -p0 < ltcrypt-flush.patch # Missing stdout flush in demo app $(Q) touch $(LIBTOMCRYPT_UNPACKNAME) -# Download and unpack tarball if no git repo found -ifeq ($(wildcard $(LIBTOMCRYPT_UNPACKNAME)/.git),) context:: $(LIBTOMCRYPT_UNPACKNAME) distclean:: $(call DELDIR, $(LIBTOMCRYPT_UNPACKNAME)) $(call DELFILE, $(LIBTOMCRYPT_ZIP)) -endif include $(APPDIR)/Application.mk diff --git a/crypto/mbedtls/.gitignore b/crypto/mbedtls/.gitignore index 247a661f5..d96514d8d 100644 --- a/crypto/mbedtls/.gitignore +++ b/crypto/mbedtls/.gitignore @@ -1,3 +1,2 @@ /mbedtls -/mbedtls-framework /*.zip diff --git a/crypto/mbedtls/0001-mbedtls-entropy_poll-use-getrandom-to-get-the-system.patch b/crypto/mbedtls/0001-mbedtls-entropy_poll-use-getrandom-to-get-the-system.patch deleted file mode 100644 index 8a8aeab8a..000000000 --- a/crypto/mbedtls/0001-mbedtls-entropy_poll-use-getrandom-to-get-the-system.patch +++ /dev/null @@ -1,44 +0,0 @@ -From b82b0c314d78d44f717a69924e7a60d8d43eb200 Mon Sep 17 00:00:00 2001 -From: George Poulios <gpoulios@census-labs.com> -Date: Fri, 29 Nov 2024 10:32:54 +0200 -Subject: [PATCH 1/2] mbedtls/entropy_poll: use 'getrandom' to get the system - entropy - -Original patch: - From e40fdc9238384ee62013c41d74cb4d47ae8c1aad Mon Sep 17 00:00:00 2001 - From: makejian <makejian@xiaomi.com> - Date: Mon, 11 Sep 2023 19:40:04 +0800 - Subject: [PATCH] mbedtls/entropy_poll: use 'getrandom' to get the system - entropy - - VELAPLATFO-16390 - - Change-Id: I885969c441cd174f5eedf8c9ce17b89e501148c8 - Signed-off-by: makejian <makejian@xiaomi.com> - -Signed-off-by: George Poulios <gpoulios@census-labs.com> ---- - library/entropy_poll.c | 5 +++-- - 1 file changed, 3 insertions(+), 2 deletions(-) - -diff --git a/library/entropy_poll.c b/library/entropy_poll.c -index 611768cd85..a26e154db1 100644 ---- a/library/entropy_poll.c -+++ b/library/entropy_poll.c -@@ -95,10 +95,11 @@ static int getrandom_wrapper(void *buf, size_t buflen, unsigned int flags) - #endif /* SYS_getrandom */ - #endif /* __linux__ || __midipix__ */ - --#if defined(__FreeBSD__) || defined(__DragonFly__) -+#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__NuttX__) - #include <sys/param.h> - #if (defined(__FreeBSD__) && __FreeBSD_version >= 1200000) || \ -- (defined(__DragonFly__) && __DragonFly_version >= 500700) -+ (defined(__DragonFly__) && __DragonFly_version >= 500700) || \ -+ (defined(__NuttX__)) - #include <errno.h> - #include <sys/random.h> - #define HAVE_GETRANDOM --- -2.40.0 - diff --git a/crypto/mbedtls/0002-mbedtls-add-mbedtls-x509-crt-pool.patch b/crypto/mbedtls/0002-mbedtls-add-mbedtls-x509-crt-pool.patch deleted file mode 100644 index 728903abe..000000000 --- a/crypto/mbedtls/0002-mbedtls-add-mbedtls-x509-crt-pool.patch +++ /dev/null @@ -1,286 +0,0 @@ -From f846c8fb13238a4db1f7d5e1a9ebce459c21faf7 Mon Sep 17 00:00:00 2001 -From: George Poulios <gpoulios@census-labs.com> -Date: Fri, 29 Nov 2024 10:33:57 +0200 -Subject: [PATCH 2/2] mbedtls: add mbedtls x509 crt pool - -Original patch: - From e9eeb5721637faa451f66bbb2789046b9a7963d5 Mon Sep 17 00:00:00 2001 - From: makejian <makejian@xiaomi.com> - Date: Fri, 18 Aug 2023 15:52:45 +0800 - Subject: [PATCH 1/2] mbedtls: add mbedtls x509 crt pool - - Signed-off-by: makejian <makejian@xiaomi.com> - -Signed-off-by: George Poulios <gpoulios@census-labs.com> ---- - include/mbedtls/threading.h | 4 + - library/threading.c | 3 + - library/x509_crt.c | 15 ++++ - library/x509_crt_pool.c | 142 ++++++++++++++++++++++++++++++++++++ - library/x509_crt_pool.h | 30 ++++++++ - 5 files changed, 194 insertions(+) - create mode 100644 library/x509_crt_pool.c - create mode 100644 library/x509_crt_pool.h - -diff --git a/include/mbedtls/threading.h b/include/mbedtls/threading.h -index d50d04ead1..9fffe6705d 100644 ---- a/include/mbedtls/threading.h -+++ b/include/mbedtls/threading.h -@@ -128,6 +128,10 @@ extern mbedtls_threading_mutex_t mbedtls_threading_psa_globaldata_mutex; - extern mbedtls_threading_mutex_t mbedtls_threading_psa_rngdata_mutex; - #endif - -+#if defined(MBEDTLS_X509_CRT_POOL) -+extern mbedtls_threading_mutex_t mbedtls_threading_x509crtpool_mutex; -+#endif -+ - #endif /* MBEDTLS_THREADING_C */ - - #ifdef __cplusplus -diff --git a/library/threading.c b/library/threading.c -index 85db243f21..da500193f5 100644 ---- a/library/threading.c -+++ b/library/threading.c -@@ -191,5 +191,8 @@ mbedtls_threading_mutex_t mbedtls_threading_key_slot_mutex MUTEX_INIT; - mbedtls_threading_mutex_t mbedtls_threading_psa_globaldata_mutex MUTEX_INIT; - mbedtls_threading_mutex_t mbedtls_threading_psa_rngdata_mutex MUTEX_INIT; - #endif -+#if defined(MBEDTLS_X509_CRT_POOL) -+mbedtls_threading_mutex_t mbedtls_threading_x509crtpool_mutex MUTEX_INIT; -+#endif - - #endif /* MBEDTLS_THREADING_C */ -diff --git a/library/x509_crt.c b/library/x509_crt.c -index 53cdcf0266..dd3c83a91a 100644 ---- a/library/x509_crt.c -+++ b/library/x509_crt.c -@@ -71,6 +71,10 @@ - #endif /* !_WIN32 || EFIX64 || EFI32 */ - #endif - -+#if defined(MBEDTLS_X509_CRT_POOL) -+#include "x509_crt_pool.h" -+#endif -+ - /* - * Item in a verification chain: cert and flags for it - */ -@@ -1113,6 +1117,12 @@ static int x509_crt_parse_der_core(mbedtls_x509_crt *crt, - end = crt_end = p + len; - crt->raw.len = (size_t) (crt_end - buf); - if (make_copy != 0) { -+#if defined(MBEDTLS_X509_CRT_POOL) -+ crt->raw.p = p = x509_crt_pool_ref_buf(buf, crt->raw.len); -+ if(crt->raw.p == NULL) { -+ return MBEDTLS_ERR_X509_ALLOC_FAILED; -+ } -+#else - /* Create and populate a new buffer for the raw field. */ - crt->raw.p = p = mbedtls_calloc(1, crt->raw.len); - if (crt->raw.p == NULL) { -@@ -1120,6 +1130,7 @@ static int x509_crt_parse_der_core(mbedtls_x509_crt *crt, - } - - memcpy(crt->raw.p, buf, crt->raw.len); -+#endif - crt->own_buffer = 1; - - p += crt->raw.len - len; -@@ -3246,7 +3257,11 @@ void mbedtls_x509_crt_free(mbedtls_x509_crt *crt) - mbedtls_asn1_sequence_free(cert_cur->authority_key_id.authorityCertIssuer.next); - - if (cert_cur->raw.p != NULL && cert_cur->own_buffer) { -+#if defined(MBEDTLS_X509_CRT_POOL) -+ x509_crt_pool_unref_buf(cert_cur->raw.p); -+#else - mbedtls_zeroize_and_free(cert_cur->raw.p, cert_cur->raw.len); -+#endif - } - - cert_prv = cert_cur; -diff --git a/library/x509_crt_pool.c b/library/x509_crt_pool.c -new file mode 100644 -index 0000000000..da00c88a85 ---- /dev/null -+++ b/library/x509_crt_pool.c -@@ -0,0 +1,142 @@ -+/* -+ * X.509 certificate pool -+ * -+ * Copyright The Mbed TLS Contributors -+ * SPDX-License-Identifier: Apache-2.0 -+ * -+ * Licensed under the Apache License, Version 2.0 (the "License"); you may -+ * not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#include "common.h" -+ -+#if defined(MBEDTLS_X509_CRT_POOL) -+ -+#include <sys/queue.h> -+#include "mbedtls/platform.h" -+#include "mbedtls/platform_util.h" -+#include "mbedtls/x509.h" -+#include "x509_crt_pool.h" -+ -+#if defined(MBEDTLS_THREADING_C) -+#include "mbedtls/threading.h" -+#endif -+ -+struct x509_crt_pool_item { -+ mbedtls_x509_buf raw; -+ uint32_t ref_count; -+ SLIST_ENTRY(x509_crt_pool_item) next; -+}; -+ -+struct x509_crt_pool { -+ SLIST_HEAD(x509_crt_pool_list, x509_crt_pool_item) head; -+}; -+ -+static struct x509_crt_pool x509_crt_pool_s = { -+ .head = SLIST_HEAD_INITIALIZER(x509_crt_pool_s.head), -+}; -+ -+static struct x509_crt_pool_item *x509_crt_pool_item_create(const unsigned char *buf, -+ size_t buflen) -+{ -+ struct x509_crt_pool_item *item; -+ -+ item = mbedtls_calloc(1, sizeof(struct x509_crt_pool_item)); -+ if (item == NULL) -+ { -+ return NULL; -+ } -+ -+ item->raw.len = buflen; -+ item->raw.p = mbedtls_calloc(1, item->raw.len); -+ if (item->raw.p == NULL) -+ { -+ mbedtls_free(item); -+ return NULL; -+ } -+ -+ memcpy(item->raw.p, buf, item->raw.len); -+ item->ref_count = 1; -+ SLIST_INSERT_HEAD(&x509_crt_pool_s.head, item, next); -+ return item; -+} -+ -+static void x509_crt_pool_item_free(struct x509_crt_pool_item *item) -+{ -+ SLIST_REMOVE(&x509_crt_pool_s.head, item, x509_crt_pool_item, next); -+ mbedtls_platform_zeroize(item->raw.p, item->raw.len); -+ mbedtls_free(item->raw.p); -+ mbedtls_free(item); -+} -+ -+unsigned char *x509_crt_pool_ref_buf(const unsigned char *buf, size_t buflen) -+{ -+ struct x509_crt_pool_item *item; -+ -+#if defined(MBEDTLS_THREADING_C) -+ if (mbedtls_mutex_lock(&mbedtls_threading_x509crtpool_mutex) != 0) -+ { -+ return NULL; -+ } -+#endif -+ -+ SLIST_FOREACH(item, &x509_crt_pool_s.head, next) -+ if (item->raw.len == buflen) -+ { -+ if (memcmp(item->raw.p, buf, buflen) == 0) -+ { -+ item->ref_count++; -+ goto unlock; -+ } -+ } -+ -+ item = x509_crt_pool_item_create(buf, buflen); -+ -+unlock: -+#if defined(MBEDTLS_THREADING_C) -+ if (mbedtls_mutex_unlock(&mbedtls_threading_x509crtpool_mutex) != 0) -+ { -+ return NULL; -+ } -+#endif -+ -+ return item == NULL ? NULL : item->raw.p; -+} -+ -+void x509_crt_pool_unref_buf(const unsigned char *buf) -+{ -+ struct x509_crt_pool_item *item; -+ -+#if defined(MBEDTLS_THREADING_C) -+ if (mbedtls_mutex_lock(&mbedtls_threading_x509crtpool_mutex) != 0) -+ { -+ return; -+ } -+#endif -+ -+ SLIST_FOREACH(item, &x509_crt_pool_s.head, next) -+ if (item->raw.p == buf) -+ { -+ item->ref_count--; -+ if (item->ref_count == 0) -+ { -+ x509_crt_pool_item_free(item); -+ } -+ break; -+ } -+ -+#if defined(MBEDTLS_THREADING_C) -+ mbedtls_mutex_unlock(&mbedtls_threading_x509crtpool_mutex); -+#endif -+} -+ -+#endif /* MBEDTLS_X509_CRT_POOL */ -diff --git a/library/x509_crt_pool.h b/library/x509_crt_pool.h -new file mode 100644 -index 0000000000..8592761de4 ---- /dev/null -+++ b/library/x509_crt_pool.h -@@ -0,0 +1,30 @@ -+/** -+ * \file x509_crt_pool.h -+ * -+ * \brief This file contains x509_crt_pool definitions and functions. -+ */ -+/* -+ * Copyright The Mbed TLS Contributors -+ * SPDX-License-Identifier: Apache-2.0 -+ * -+ * Licensed under the Apache License, Version 2.0 (the "License"); you may -+ * not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+#ifndef MBEDTLS_X509_CRT_POOL_H -+#define MBEDTLS_X509_CRT_POOL_H -+ -+#include <stdint.h> -+ -+unsigned char *x509_crt_pool_ref_buf(const unsigned char *buf, size_t buflen); -+void x509_crt_pool_unref_buf(const unsigned char *buf); -+ -+#endif /* mbedtls_x509_crt_pool.h */ --- -2.40.0 diff --git a/crypto/mbedtls/0003-Fix-MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT-warning.patch b/crypto/mbedtls/0003-Fix-MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT-warning.patch deleted file mode 100644 index df8d45241..000000000 --- a/crypto/mbedtls/0003-Fix-MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT-warning.patch +++ /dev/null @@ -1,33 +0,0 @@ -From 84d6430f412d869a56bbcce070d5b730386e540a Mon Sep 17 00:00:00 2001 -From: George Poulios <gpoulios@census-labs.com> -Date: Thu, 5 Dec 2024 02:28:19 +0200 -Subject: [PATCH 3/3] Fix MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT warning - -When MBEDTLS_SSL_PROTO_DTLS is not defined, config_adjust_ssl.h -undefines (among others) MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT. -Then the preprocessor comparison with 0 generates Wundef. Wrap -the comparison under a defined() check to suppress this. This -breaks builds on systems with -Werror. - -Signed-off-by: George Poulios <gpoulios@census-labs.com> ---- - include/mbedtls/ssl.h | 3 ++- - 1 file changed, 2 insertions(+), 1 deletion(-) - -diff --git a/include/mbedtls/ssl.h b/include/mbedtls/ssl.h -index 42fffbf860..c68be5e30a 100644 ---- a/include/mbedtls/ssl.h -+++ b/include/mbedtls/ssl.h -@@ -620,7 +620,8 @@ - #define MBEDTLS_TLS_EXT_SIG_ALG_CERT 50 /* RFC 8446 TLS 1.3 */ - #define MBEDTLS_TLS_EXT_KEY_SHARE 51 /* RFC 8446 TLS 1.3 */ - --#if MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT == 0 -+#if !defined(MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT) || \ -+ MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT == 0 - #define MBEDTLS_TLS_EXT_CID 54 /* RFC 9146 DTLS 1.2 CID */ - #else - #define MBEDTLS_TLS_EXT_CID 254 /* Pre-RFC 9146 DTLS 1.2 CID */ --- -2.39.5 (Apple Git-154) - diff --git a/crypto/mbedtls/CMakeLists.txt b/crypto/mbedtls/CMakeLists.txt deleted file mode 100644 index 478a257bd..000000000 --- a/crypto/mbedtls/CMakeLists.txt +++ /dev/null @@ -1,192 +0,0 @@ -# ############################################################################## -# apps/crypto/mbedtls/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_CRYPTO_MBEDTLS) - - # ############################################################################ - # Config and Fetch MbedTLS lib - # ############################################################################ - - set(MBEDTLS_DIR ${CMAKE_CURRENT_LIST_DIR}/mbedtls) - - if(NOT EXISTS ${MBEDTLS_DIR}) - set(MBEDTLS_URL https://github.com/ARMmbed/mbedtls/archive) - FetchContent_Declare( - mbedtls_fetch - URL ${MBEDTLS_URL}/v${CONFIG_MBEDTLS_VERSION}.zip SOURCE_DIR - ${CMAKE_CURRENT_LIST_DIR}/mbedtls BINARY_DIR - ${CMAKE_BINARY_DIR}/apps/crypto/mbedtls/mbedtls - PATCH_COMMAND - patch -p1 -d ${MBEDTLS_DIR} < - ${CMAKE_CURRENT_LIST_DIR}/0001-mbedtls-entropy_poll-use-getrandom-to-get-the-system.patch - && patch -p1 -d ${MBEDTLS_DIR} < - ${CMAKE_CURRENT_LIST_DIR}/0002-mbedtls-add-mbedtls-x509-crt-pool.patch - && patch -p1 -d ${MBEDTLS_DIR} < - ${CMAKE_CURRENT_LIST_DIR}/0003-Fix-MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT-warning.patch - DOWNLOAD_NO_PROGRESS true - TIMEOUT 30) - - FetchContent_GetProperties(mbedtls_fetch) - - if(NOT mbedtls_fetch_POPULATED) - FetchContent_Populate(mbedtls_fetch) - endif() - endif() - - # ############################################################################ - # Flags - # ############################################################################ - - set_source_files_properties(${MBEDTLS_DIR}/library/bignum.c - PROPERTIES COMPILE_FLAGS -fno-lto) - - if(CONFIG_FRAME_POINTER) - if(CONFIG_DEBUG_OPTLEVEL STREQUAL -O3) - set_source_files_properties(${MBEDTLS_DIR}/library/sha246.c - PROPERTIES COMPILE_FLAGS -O2) - set_source_files_properties(${MBEDTLS_DIR}/library/cmac.c - PROPERTIES COMPILE_FLAGS -O2) - endif() - endif() - - # ############################################################################ - # Sources - # ############################################################################ - - file(GLOB CSRCS ${MBEDTLS_DIR}/library/*.c) - - if(CONFIG_MBEDTLS_ENTROPY_HARDWARE_ALT - OR CONFIG_MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG) - list(APPEND CSRCS ${CMAKE_CURRENT_LIST_DIR}/source/entropy_alt.c) - endif() - - if(CONFIG_MBEDTLS_ALT) - list(APPEND CSRCS ${CMAKE_CURRENT_LIST_DIR}/source/dev_alt.c) - - if(CONFIG_MBEDTLS_AES_ALT) - list(APPEND CSRCS ${CMAKE_CURRENT_LIST_DIR}/source/aes_alt.c) - endif() - - if(CONFIG_MBEDTLS_CMAC_ALT) - list(APPEND CSRCS ${CMAKE_CURRENT_LIST_DIR}/source/cmac_alt.c) - endif() - - if(CONFIG_MBEDTLS_MD5_ALT) - list(APPEND CSRCS ${CMAKE_CURRENT_LIST_DIR}/source/md5_alt.c) - endif() - - if(CONFIG_MBEDTLS_POLY1305_ALT) - list(APPEND CSRCS ${CMAKE_CURRENT_LIST_DIR}/source/poly1305_alt.c) - endif() - - if(CONFIG_MBEDTLS_RIPEMD160_ALT) - list(APPEND CSRCS ${CMAKE_CURRENT_LIST_DIR}/source/ripemd160_alt.c) - endif() - - if(CONFIG_MBEDTLS_SHA1_ALT) - list(APPEND CSRCS ${CMAKE_CURRENT_LIST_DIR}/source/sha1_alt.c) - endif() - - if(CONFIG_MBEDTLS_SHA256_ALT) - list(APPEND CSRCS ${CMAKE_CURRENT_LIST_DIR}/source/sha256_alt.c) - endif() - - if(CONFIG_MBEDTLS_SHA512_ALT) - list(APPEND CSRCS ${CMAKE_CURRENT_LIST_DIR}/source/sha512_alt.c) - endif() - - if(CONFIG_MBEDTLS_BIGNUM_ALT) - list(APPEND CSRCS ${CMAKE_CURRENT_LIST_DIR}/source/bignum_alt.c) - endif() - - endif() - - # ############################################################################ - # Include Directory - # ############################################################################ - - set(INCDIR ${CMAKE_CURRENT_LIST_DIR}/include ${MBEDTLS_DIR}/include) - # ############################################################################ - # Library Configuration - # ############################################################################ - - nuttx_add_library(mbedtls STATIC) - target_sources(mbedtls PRIVATE ${CSRCS}) - target_include_directories(mbedtls PUBLIC ${INCDIR}) - nuttx_export_header(TARGET mbedtls INCLUDE_DIRECTORIES ${MBEDTLS_DIR}/include) - # Overlay mbedtls_config.h cannot be in the same nuttx_export_header() as - # ${MBEDTLS_DIR}/include (duplicate path). Alt headers need no export; INCDIR - # supplies them for this library only. - nuttx_create_symlink( - ${CMAKE_CURRENT_LIST_DIR}/include/mbedtls/mbedtls_config.h - ${NUTTX_APPS_BINDIR}/include/mbedtls/mbedtls/mbedtls_config.h) - target_compile_definitions(mbedtls PRIVATE unix) - - if(CONFIG_ARCH_SIM) - target_compile_options(mbedtls PRIVATE -O0) - endif() - - # ############################################################################ - # Applications Configuration - # ############################################################################ - - if(CONFIG_MBEDTLS_APPS) - - if(CONFIG_MBEDTLS_APP_BENCHMARK) - nuttx_add_application( - MODULE - ${CONFIG_MBEDTLS_APPS} - NAME - ${CONFIG_MBEDTLS_APP_BENCHMARK_PROGNAME} - STACKSIZE - ${CONFIG_MBEDTLS_APP_BENCHMARK_STACKSIZE} - PRIORITY - ${CONFIG_MBEDTLS_APP_BENCHMARK_PRIORITY} - SRCS - ${MBEDTLS_DIR}/programs/test/benchmark.c - INCLUDE_DIRECTORIES - ${INCDIR} - DEPENDS - mbedtls) - endif() - - if(CONFIG_MBEDTLS_APP_SELFTEST) - nuttx_add_application( - MODULE - ${CONFIG_MBEDTLS_APPS} - NAME - ${CONFIG_MBEDTLS_APP_SELFTEST_PROGNAME} - STACKSIZE - ${CONFIG_MBEDTLS_APP_SELFTEST_STACKSIZE} - PRIORITY - ${CONFIG_MBEDTLS_APP_SELFTEST_PRIORITY} - SRCS - ${MBEDTLS_DIR}/programs/test/selftest.c - INCLUDE_DIRECTORIES - ${INCDIR} - DEPENDS - mbedtls) - endif() - - endif() - -endif() diff --git a/crypto/mbedtls/Kconfig b/crypto/mbedtls/Kconfig index 53b043017..d598ad136 100644 --- a/crypto/mbedtls/Kconfig +++ b/crypto/mbedtls/Kconfig @@ -13,718 +13,7 @@ if CRYPTO_MBEDTLS config MBEDTLS_VERSION string "Mbed TLS Version" - default "3.6.2" - -config MBEDTLS_DEBUG_C - bool "This module provides debugging functions." - default DEBUG_CRYPTO_INFO - ---help--- - This module provides debugging functions. - -config MBEDTLS_SSL_IN_CONTENT_LEN - int "Maximum length (in bytes) of incoming plaintext fragments." - default 16384 - ---help--- - Maximum length (in bytes) of incoming plaintext fragments. - -config MBEDTLS_SSL_OUT_CONTENT_LEN - int "Maximum length (in bytes) of outgoing plaintext fragments." - default 16384 - ---help--- - Maximum length (in bytes) of outgoing plaintext fragments. - -config MBEDTLS_SSL_SRV_C - bool "This module is required for SSL/TLS server support." - default y - ---help--- - This module is required for SSL/TLS server support. - -config MBEDTLS_PLATFORM_MEMORY - bool "Enable the memory allocation layer." - depends on MBEDTLS_PLATFORM_C - default n - -config MBEDTLS_ENTROPY_HARDWARE_ALT - bool "Uncomment this macro to let mbed TLS use your own implementation of a hardware entropy collector." - default n - depends on DEV_RANDOM - select MBEDTLS_NO_PLATFORM_ENTROPY - -config MBEDTLS_AES_ROM_TABLES - bool "Store the AES tables in ROM." - default n - -config MBEDTLS_NO_PLATFORM_ENTROPY - bool "Do not use built-in platform entropy functions." - default n - -config MBEDTLS_ECP_RESTARTABLE - bool "Enable the restartable ECC." - depends on MBEDTLS_ECP_C - default n - -config MBEDTLS_SELF_TEST - bool "Enable the checkup functions (*_self_test)." - default n - -config MBEDTLS_SSL_DTLS_CLIENT_PORT_REUSE - bool "Enable server-side support for clients that reconnect from the same port." - depends on MBEDTLS_SSL_DTLS_HELLO_VERIFY - default y - -config MBEDTLS_BLOWFISH_C - bool "Enable the Blowfish block cipher." - default n - -config MBEDTLS_CAMELLIA_C - bool "Enable the Camellia block cipher." - default y - -config MBEDTLS_PADLOCK_C - bool "Enable VIA Padlock support on x86." - default !MBEDTLS_AES_ALT - -config MBEDTLS_TIMING_C - bool "Enable the semi-portable timing interface." - default y - -config MBEDTLS_SSL_KEEP_PEER_CERTIFICATE - bool "Enable the availability of the API mbedtls_ssl_get_peer_cert() giving access to the peer's certificate after completion of the handshake." - default y - -config MBEDTLS_SSL_PROTO_DTLS - bool "Enable support for DTLS (all available versions)." - default y - -if MBEDTLS_SSL_PROTO_DTLS - -config MBEDTLS_SSL_DTLS_ANTI_REPLAY - bool "Enable support for the anti-replay mechanism in DTLS." - default y - -config MBEDTLS_SSL_DTLS_HELLO_VERIFY - bool "Enable support for HelloVerifyRequest on DTLS servers." - default y - -config MBEDTLS_SSL_DTLS_CONNECTION_ID - bool "Enable support for the DTLS Connection ID (CID) extension." - default y - -config MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT - int "Enable the standard version of DTLS Connection ID feature." - depends on MBEDTLS_SSL_DTLS_CONNECTION_ID - default 0 - -endif # MBEDTLS_SSL_PROTO_DTLS - -config MBEDTLS_SSL_ALPN - bool "Enable support for RFC 7301 Application Layer Protocol Negotiation." - default y - -config MBEDTLS_AESNI_C - bool "Enable AES-NI support on x86-64." - depends on ARCH_X86_64 - default !MBEDTLS_AES_ALT - -config MBEDTLS_ECP_WINDOW_SIZE - int "Maximum window size used" - default 6 - -config MBEDTLS_ECP_FIXED_POINT_OPTIM - bool "Enable fixed-point speed-up" - default n - -config MBEDTLS_CMAC_C - bool "Enable the CMAC (Cipher-based Message Authentication Code) mode for block" - default y - -config MBEDTLS_NET_C - bool "Enable the TCP and UDP over IPv6/IPv4 networking routines" - default LIBC_NETDB - -config MBEDTLS_OID_C - bool "Enable the OID database." - default y - -config MBEDTLS_ECDSA_C - bool "Enable the elliptic curve DSA library." - default y - -config MBEDTLS_ECP_C - bool "Enable the elliptic curve over GF(p) library." - default y - -config MBEDTLS_ECP_DP_SECP256R1_ENABLED - bool "Enables specific curves within the Elliptic Curve module." - default y - -config MBEDTLS_PEM_WRITE_C - bool "Enable PEM encoding / writing." - default y - -config MBEDTLS_PK_C - bool "Enable the generic public (asymmetric) key layer." - depends on MBEDTLS_MD_C && MBEDTLS_RSA_C && MBEDTLS_ECP_C - default y - -config MBEDTLS_PK_PARSE_C - bool "Enable the generic public (asymmetric) key parser" - depends on MBEDTLS_ASN1_PARSE_C && MBEDTLS_OID_C && MBEDTLS_PK_C - default y - -config MBEDTLS_PK_WRITE_C - bool "Enable the generic public (asymmetric) key writer." - depends on MBEDTLS_ASN1_WRITE_C && MBEDTLS_OID_C && MBEDTLS_PK_C - default y - -config MBEDTLS_X509_CREATE_C - bool "Enable X.509 core for creating certificates." - default y - -config MBEDTLS_X509_CRT_WRITE_C - bool "Enable creating X.509 certificates." - depends on MBEDTLS_X509_CREATE_C - default y - -config MBEDTLS_X509_CSR_WRITE_C - bool "Enable creating X.509 Certificate Signing Requests (CSR)." - depends on MBEDTLS_X509_CREATE_C - default y - -config MBEDTLS_X509_CSR_PARSE_C - bool "Enable X.509 Certificate Signing Request (CSR) parsing." - default y - -config MBEDTLS_X509_CRT_POOL - bool "Enable the X509 Certificate Pool" - depends on MBEDTLS_THREADING_C - default n - -config MBEDTLS_HAVE_ASM - bool "Enable compiler support for asm." - default y - -config MBEDTLS_HAVE_TIME_DATE - bool "Enable to verify the validity period of X.509 certificates when system have correct clock." - default y - -config MBEDTLS_CIPHER_MODE_CFB - bool "Enable Cipher Feedback mode (CFB) for symmetric ciphers." - default y - -config MBEDTLS_CIPHER_MODE_CTR - bool "Enable Counter Block Cipher mode (CTR) for symmetric ciphers." - default y - -config MBEDTLS_CIPHER_MODE_OFB - bool "Enable Output Feedback mode (OFB) for symmetric ciphers." - default y - -config MBEDTLS_CIPHER_MODE_XTS - bool "Enable Xor-encrypt-xor with ciphertext stealing mode (XTS) for AES." - default y - -config MBEDTLS_CIPHER_PADDING_PKCS7 - bool "Enable PKCS7 padding mode in the cipher layer." - default y - -config MBEDTLS_CIPHER_PADDING_ONE_AND_ZEROS - bool "Enable bit padding mode in the cipher layer." - default y - -config MBEDTLS_CIPHER_PADDING_ZEROS_AND_LEN - bool "Enable zero and length padding mode in the cipher layer." - default y - -config MBEDTLS_CIPHER_PADDING_ZEROS - bool "Enable zeros padding mode in the cipher layer." - default y - -config MBEDTLS_ECP_DP_SECP192R1_ENABLED - bool "Enables SECP192R1 curve within the Elliptic Curve module." - default y - -config MBEDTLS_ECP_DP_SECP224R1_ENABLED - bool "Enables SECP224R1 curve within the Elliptic Curve module." - default y - -config MBEDTLS_ECP_DP_SECP384R1_ENABLED - bool "Enables SECP384R1 curve within the Elliptic Curve module." - default y - -config MBEDTLS_ECP_DP_SECP521R1_ENABLED - bool "Enables SECP521R1 curve within the Elliptic Curve module." - default y - -config MBEDTLS_ECP_DP_SECP192K1_ENABLED - bool "Enables SECP192K1 curve within the Elliptic Curve module." - default y - -config MBEDTLS_ECP_DP_SECP224K1_ENABLED - bool "Enables SECP224K1 curve within the Elliptic Curve module." - default y - -config MBEDTLS_ECP_DP_SECP256K1_ENABLED - bool "Enables SECP256K1 curve within the Elliptic Curve module." - default y - -config MBEDTLS_ECP_DP_BP256R1_ENABLED - bool "Enables BP256R1 curve within the Elliptic Curve module." - default y - -config MBEDTLS_ECP_DP_BP384R1_ENABLED - bool "Enables BP384R1 curve within the Elliptic Curve module." - default y - -config MBEDTLS_ECP_DP_BP512R1_ENABLED - bool "Enables BP512R1 curve within the Elliptic Curve module." - default y - -config MBEDTLS_ECP_DP_CURVE25519_ENABLED - bool "Enables CURVE25519 curve within the Elliptic Curve module." - default y - -config MBEDTLS_ECP_DP_CURVE448_ENABLED - bool "Enables CURVE448 curve within the Elliptic Curve module." - default y - -config MBEDTLS_ECP_NIST_OPTIM - bool "Enable specific 'modulo p' routines for each NIST prime." - default y - -config MBEDTLS_ECDSA_DETERMINISTIC - bool "Enable deterministic ECDSA (RFC 6979)." - depends on MBEDTLS_HMAC_DRBG_C && MBEDTLS_ECDSA_C - default y - -config MBEDTLS_KEY_EXCHANGE_PSK_ENABLED - bool "Enable the PSK based ciphersuite modes in SSL / TLS." - default y - -config MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED - bool "Enable the DHE-PSK based ciphersuite modes in SSL / TLS." - depends on MBEDTLS_DHM_C - default y - -config MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED - bool "Enable the ECDHE-PSK based ciphersuite modes in SSL / TLS." - depends on MBEDTLS_ECDH_C - default y - -config MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED - bool "Enable the RSA-PSK based ciphersuite modes in SSL / TLS." - default y - -config MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED - bool "Enable the DHE-RSA based ciphersuite modes in SSL / TLS." - depends on MBEDTLS_DHM_C - default y - -config MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED - bool "Enable the ECDHE-RSA based ciphersuite modes in SSL / TLS." - depends on MBEDTLS_ECDH_C - default y - -config MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED - bool "Enable the ECDHE-ECDSA based ciphersuite modes in SSL / TLS." - depends on MBEDTLS_ECDH_C && MBEDTLS_ECDSA_C - default y - -config MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED - bool "Enable the ECDH-RSA based ciphersuite modes in SSL / TLS." - depends on MBEDTLS_ECDH_C - default y - -config MBEDTLS_PK_PARSE_EC_EXTENDED - bool "Enhance support for reading EC keys using variants of SEC1 not allowed by RFC 5915 and RFC 5480." - default y - -config MBEDTLS_PK_PARSE_EC_COMPRESSED - bool "Enable the support for parsing public keys of type Short Weierstrass (MBEDTLS_ECP_DP_SECP_XXX and MBEDTLS_ECP_DP_BP_XXX) which are using the compressed point format." - default y - -config MBEDTLS_ERROR_STRERROR_DUMMY - bool "Enable a dummy error function to make use of mbedtls_strerror()." - default y - -config MBEDTLS_GENPRIME - bool "Enable the prime-number generation code." - default y - -config MBEDTLS_PK_RSA_ALT_SUPPORT - bool "Support external private RSA keys (eg from a HSM) in the PK layer." - default y - -config MBEDTLS_PKCS1_V21 - bool "Enable support for PKCS#1 v2.1 encoding." - default y - -config MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG - bool "Make the PSA Crypto module use an external random generator provided by a driver, instead of Mbed TLS's entropy and DRBG modules." - depends on DEV_RANDOM - default n - -config MBEDTLS_PSA_KEY_STORE_DYNAMIC - bool "Dynamically resize the PSA key store to accommodate any number of volatile keys (until the heap memory is exhausted)." - depends on MBEDTLS_PSA_CRYPTO_C - default y - -config MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS - bool "Assume all buffers passed to PSA functions are owned exclusively by the PSA function and are not stored in shared memory." - default n - -config MBEDTLS_SSL_CONTEXT_SERIALIZATION - bool "Enable serialization of the TLS context structures." - depends on MBEDTLS_GCM_C || MBEDTLS_CCM_C || MBEDTLS_CHACHAPOLY_C - default y - -config MBEDTLS_SSL_ENCRYPT_THEN_MAC - bool "Enable support for Encrypt-then-MAC, RFC 7366." - default y - -config MBEDTLS_SSL_EXTENDED_MASTER_SECRET - bool "Enable Session Hash and Extended Master Secret Extension." - default y - -config MBEDTLS_SSL_RENEGOTIATION - bool "Enable support for TLS renegotiation." - default y - -config MBEDTLS_SSL_MAX_FRAGMENT_LENGTH - bool "Enable support for RFC 6066 max_fragment_length extension in SSL." - default y - -config MBEDTLS_SSL_PROTO_TLS1_2 - bool "Enable support for TLS 1.2 (and DTLS 1.2 if DTLS is enabled)." - depends on (MBEDTLS_USE_PSA_CRYPTO ||\ - (MBEDTLS_MD_C && (MBEDTLS_SHA256_C || MBEDTLS_SHA384_C))) - default y - ---help--- - If MBEDTLS_USE_PSA_CRYPTO is set, then PSA_WANT_ALG_SHA_256 or PSA_WANT_ALG_SHA_384 - must be defined. - -config MBEDTLS_SSL_PROTO_TLS1_3 - bool "Enable support for TLS 1.3." - depends on MBEDTLS_SSL_KEEP_PEER_CERTIFICATE && MBEDTLS_PSA_CRYPTO_C - default y - -config MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE - bool "Enable TLS 1.3 middlebox compatibility mode." - default y - -config MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED - bool "Enable TLS 1.3 PSK key exchange mode." - default y - -config MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED - bool "Enable TLS 1.3 ephemeral key exchange mode." - depends on MBEDTLS_X509_CRT_PARSE_C && \ - (MBEDTLS_ECDSA_C || MBEDTLS_USE_PSA_CRYPTO || MBEDTLS_PKCS1_V21) - default y - ---help--- - Requires PSA_WANT_ALG_ECDH or PSA_WANT_ALG_FFDH to be defined. Also, if - MBEDTLS_USE_PSA_CRYPTO is used to satisfy its dependencies, then PSA_WANT_ALG_ECDSA - must also be defined. - -config MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED - bool "Enable TLS 1.3 PSK ephemeral key exchange mode." - default y - ---help--- - Requires PSA_WANT_ALG_ECDH or PSA_WANT_ALG_FFDH. - -config MBEDTLS_SSL_SESSION_TICKETS - bool "Enable support for RFC 5077 session tickets in SSL." - default y - -config MBEDTLS_SSL_SERVER_NAME_INDICATION - bool "Enable support for RFC 6066 server name indication (SNI) in SSL." - default y - -config MBEDTLS_THREADING_PTHREAD - bool "Enable the pthread wrapper layer for the threading layer." - depends on MBEDTLS_THREADING_C - default n - -config MBEDTLS_USE_PSA_CRYPTO - bool "Make the X.509 and TLS library use PSA for cryptographic operations, and enable new APIs for using keys handled by PSA Crypto." - depends on MBEDTLS_PSA_CRYPTO_C - default n - -config MBEDTLS_VERSION_FEATURES - bool "Allow run-time checking of compile-time enabled features." - depends on MBEDTLS_VERSION_C - default y - -config MBEDTLS_X509_RSASSA_PSS_SUPPORT - bool "Enable parsing and verification of X.509 certificates, CRLs and CSRS signed with RSASSA-PSS." - depends on MBEDTLS_PKCS1_V21 - default y - -config MBEDTLS_AESCE_C - bool "Enable AES cryptographic extension support on 64-bit Arm." - depends on MBEDTLS_AES_C - default y - -config MBEDTLS_AES_C - bool "Enable the AES block cipher." - default y - -config MBEDTLS_ASN1_PARSE_C - bool "Enable the generic ASN1 parser." - default y - -config MBEDTLS_ASN1_WRITE_C - bool "Enable the generic ASN1 writer." - default y - -config MBEDTLS_ARC4_C - bool "Enable the ARCFOUR stream cipher." - default n - -config MBEDTLS_ARIA_C - bool "Enable the ARIA block cipher." - default y - -config MBEDTLS_CCM_C - bool "Enable the Counter with CBC-MAC (CCM) mode for 128-bit block cipher." - default y - -config MBEDTLS_CHACHA20_C - bool "Enable the ChaCha20 stream cipher." - default y - -config MBEDTLS_CHACHAPOLY_C - bool "Enable the ChaCha20-Poly1305 AEAD algorithm." - depends on MBEDTLS_CHACHA20_C && MBEDTLS_POLY1305_C - default y - -config MBEDTLS_DHM_C - bool "Enable the Diffie-Hellman-Merkle module." - default y - -config MBEDTLS_ECDH_C - bool "Enable the elliptic curve Diffie-Hellman library." - depends on MBEDTLS_ECP_C - default y - -config MBEDTLS_ECDSA_C - bool "Enable the elliptic curve DSA library." - depends on MBEDTLS_ECP_C - default y - -config MBEDTLS_ECJPAKE_C - bool "Enable the elliptic curve J-PAKE library." - depends on MBEDTLS_ECP_C - default y - -config MBEDTLS_ECP_C - bool "Enable the elliptic curve over GF(p) library." - depends on MBEDTLS_ECP_DP_SECP256R1_ENABLED || MBEDTLS_ECP_DP_SECP192R1_ENABLED \ - || MBEDTLS_ECP_DP_SECP224R1_ENABLED || MBEDTLS_ECP_DP_SECP384R1_ENABLED \ - || MBEDTLS_ECP_DP_SECP521R1_ENABLED || MBEDTLS_ECP_DP_SECP192K1_ENABLED \ - || MBEDTLS_ECP_DP_SECP224K1_ENABLED || MBEDTLS_ECP_DP_SECP256K1_ENABLED \ - || MBEDTLS_ECP_DP_BP256R1_ENABLED || MBEDTLS_ECP_DP_BP384R1_ENABLED \ - || MBEDTLS_ECP_DP_BP512R1_ENABLED || MBEDTLS_ECP_DP_CURVE25519_ENABLED \ - || MBEDTLS_ECP_DP_CURVE448_ENABLED - default y - -config MBEDTLS_ERROR_C - bool "Enable error code to error string conversion." - default y - -config MBEDTLS_GCM_C - bool "Enable the Galois/Counter Mode (GCM)." - default y - -config MBEDTLS_HKDF_C - bool "Enable the HKDF algorithm (RFC 5869)." - default y - -config MBEDTLS_HMAC_DRBG_C - bool "Enable the HMAC_DRBG random generator." - default y - -config MBEDTLS_LMS_C - bool "Enable the LMS stateful-hash asymmetric signature algorithm." - depends on MBEDTLS_PSA_CRYPTO_C - default y - -config MBEDTLS_NIST_KW_C - bool "Enable the Key Wrapping mode for 128-bit block ciphers." - default y - -config MBEDTLS_MD_C - bool "Enable the generic layer for message digest (hashing) and HMAC." - depends on MBEDTLS_MD5_C || MBEDTLS_RIPEMD160_C || MBEDTLS_SHA1_C ||\ - MBEDTLS_SHA224_C || MBEDTLS_SHA256_C || MBEDTLS_SHA384_C ||\ - MBEDTLS_SHA512_C || MBEDTLS_PSA_CRYPTO_C - default y - -config MBEDTLS_MD5_C - bool "Enable the MD5 hash algorithm." - default y - -config MBEDTLS_PKCS5_C - bool "Enable PKCS#5 functions." - select MBEDTLS_MD_C - default y - -config MBEDTLS_PKCS7_C - bool "Enable PKCS #7 core for using PKCS #7-formatted signatures." - depends on MBEDTLS_ASN1_PARSE_C && MBEDTLS_OID_C && MBEDTLS_PK_PARSE_C &&\ - MBEDTLS_X509_CRT_PARSE_C && MBEDTLS_X509_CRL_PARSE_C &&\ - MBEDTLS_MD_C - default y - -config MBEDTLS_PKCS12_C - bool "Enable PKCS#12 PBE functions." - depends on MBEDTLS_ASN1_PARSE_C && (MBEDTLS_MD_C || MBEDTLS_PSA_CRYPTO_C) - default y - -config MBEDTLS_PLATFORM_C - bool "Enable the platform abstraction layer." - default y - -config MBEDTLS_POLY1305_C - bool "Enable the Poly1305 MAC algorithm." - default y - -config MBEDTLS_PSA_CRYPTO_C - bool "Enable the Platform Security Architecture cryptography API." - default y - -config MBEDTLS_PSA_CRYPTO_STORAGE_C - bool "Enable the Platform Security Architecture persistent key storage." - depends on MBEDTLS_PSA_CRYPTO_C - default y - -config MBEDTLS_PSA_ITS_FILE_C - bool "Enable the emulation of the Platform Security Architecture Internal Trusted Storage (PSA ITS) over files." - default y - -config MBEDTLS_RIPEMD160_C - bool "Enable the RIPEMD-160 hash algorithm." - default y - -config MBEDTLS_RSA_C - bool "Enable the RSA public-key cryptosystem." - depends on MBEDTLS_OID_C - default y - -config MBEDTLS_SHA1_C - bool "Enable the SHA1 cryptographic hash algorithm." - default y - -config MBEDTLS_SHA224_C - bool "Enable the SHA-224 cryptographic hash algorithm." - default y - -config MBEDTLS_SHA256_C - bool "Enable the SHA-256 cryptographic hash algorithm." - default y - -config MBEDTLS_SHA384_C - bool "Enable the SHA-384 cryptographic hash algorithm." - default y - -config MBEDTLS_SHA512_C - bool "Enable SHA-512 cryptographic hash algorithms." - default y - -config MBEDTLS_SHA3_C - bool "Enable the SHA3 cryptographic hash algorithm." - default y - -config MBEDTLS_SSL_CACHE_C - bool "Enable simple SSL cache implementation." - default y - -config MBEDTLS_SSL_COOKIE_C - bool "Enable SSL cookie implementation." - default y - -config MBEDTLS_SSL_TICKET_C - bool "Enable an implementation of TLS server-side callbacks for session tickets." - depends on (MBEDTLS_CIPHER_C || MBEDTLS_USE_PSA_CRYPTO) && \ - (MBEDTLS_GCM_C || MBEDTLS_CCM_C || MBEDTLS_CHACHAPOLY_C) - default y - -config MBEDTLS_THREADING_C - bool "Enable the threading abstraction layer." - default n - -config MBEDTLS_VERSION_C - bool "Enable run-time version information." - default y - -config MBEDTLS_X509_USE_C - bool "Enable X.509 core for using certificates." - depends on MBEDTLS_ASN1_PARSE_C && MBEDTLS_OID_C && MBEDTLS_PK_PARSE_C &&\ - (MBEDTLS_MD_C || MBEDTLS_USE_PSA_CRYPTO) - default y - -config MBEDTLS_X509_CRT_PARSE_C - bool "Enable X.509 certificate parsing." - default y - -config MBEDTLS_X509_CRL_PARSE_C - bool "Enable X.509 CRL parsing." - default y - -if CRYPTO_CRYPTODEV - -config MBEDTLS_ALT - bool - default n - ---help--- - Enable Mbed TLS alted by nuttx crypto via /dev/crypto - -config MBEDTLS_AES_ALT - bool "Enable Mbedt TLS AES module alted by nuttx crypto" - select MBEDTLS_ALT - default n - -config MBEDTLS_CMAC_ALT - bool "Enable Mbedt TLS CMAC module alted by nuttx crypto" - select MBEDTLS_ALT - default n - -config MBEDTLS_MD5_ALT - bool "Enable Mbedt TLS MD5 module alted by nuttx crypto" - select MBEDTLS_ALT - default n - -config MBEDTLS_POLY1305_ALT - bool "Enable Mbedt TLS POLY1305 module alted by nuttx crypto" - select MBEDTLS_ALT - default n - -config MBEDTLS_RIPEMD160_ALT - bool "Enable Mbedt TLS RIPEMD160 module alted by nuttx crypto" - select MBEDTLS_ALT - default n - -config MBEDTLS_SHA1_ALT - bool "Enable Mbedt TLS SHA1 module alted by nuttx crypto" - select MBEDTLS_ALT - default n - -config MBEDTLS_SHA256_ALT - bool "Enable Mbedt TLS SHA224/SHA256 module alted by nuttx crypto" - select MBEDTLS_ALT - default n - -config MBEDTLS_SHA512_ALT - bool "Enable Mbedt TLS SHA384/SHA512 module alted by nuttx crypto" - select MBEDTLS_ALT - default n - -config MBEDTLS_BIGNUM_ALT - bool "Enable Mbedt TLS Bignum module alted by nuttx mpi" - select MBEDTLS_ALT - default n - -endif # CRYPTO_CRYPTODEV + default "3.0.0" menuconfig MBEDTLS_APPS tristate "Mbed TLS Applications" @@ -760,8 +49,7 @@ config MBEDTLS_APP_BENCHMARK_PRIORITY config MBEDTLS_APP_BENCHMARK_STACKSIZE int "Benchmark stack size" default MBEDTLS_DEFAULT_TASK_STACKSIZE - -endif # MBEDTLS_APP_BENCHMARK +endif config MBEDTLS_APP_SELFTEST bool "Mbed TLS Self Test" @@ -785,34 +73,8 @@ config MBEDTLS_APP_SELFTEST_PRIORITY config MBEDTLS_APP_SELFTEST_STACKSIZE int "Self test stack size" default MBEDTLS_DEFAULT_TASK_STACKSIZE +endif -endif # MBEDTLS_APP_SELFTEST - -config MBEDTLS_APP_SSL_CLIENT2 - bool "Mbed TLS ssl_client2 sample program" - default n - ---help--- - Enable the Mbed TLS ssl_client2 - -if MBEDTLS_APP_SSL_CLIENT2 - -config MBEDTLS_APP_SSL_CLIENT2_PROGNAME - string "Program name" - default "ssl_client2" - ---help--- - This is the name of the program that will be used when the NSH ELF - program is installed. - -config MBEDTLS_APP_SSL_CLIENT2_PRIORITY - int "ssl_client2 task priority" - default 100 - -config MBEDTLS_APP_SSL_CLIENT2_STACKSIZE - int "ssl_client2 stack size" - default MBEDTLS_DEFAULT_TASK_STACKSIZE - -endif # MBEDTLS_APP_SSL_CLIENT2 - -endif # MBEDTLS_APPS +endif endif # CRYPTO_MBEDTLS diff --git a/crypto/mbedtls/Make.defs b/crypto/mbedtls/Make.defs index a7c9a21ff..b09805bb4 100644 --- a/crypto/mbedtls/Make.defs +++ b/crypto/mbedtls/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/crypto/mbedtls/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -20,15 +18,15 @@ # ############################################################################ -ifneq ($(CONFIG_CRYPTO_MBEDTLS),) +ifeq ($(CONFIG_CRYPTO_MBEDTLS),y) CONFIGURED_APPS += $(APPDIR)/crypto/mbedtls # Allows `<mbedtls/<>.h>` import. -CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/crypto/mbedtls/include -CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/crypto/mbedtls/mbedtls/include +CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(APPDIR)/crypto/mbedtls/mbedtls/include} +CXXFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(APPDIR)/crypto/mbedtls/mbedtls/include} -CXXFLAGS += ${INCDIR_PREFIX}$(APPDIR)/crypto/mbedtls/include -CXXFLAGS += ${INCDIR_PREFIX}$(APPDIR)/crypto/mbedtls/mbedtls/include +CFLAGS += ${shell $(DEFINE) "$(CC)" MBEDTLS_CONFIG_FILE='"<crypto/mbedtls_config.h>"'} +CXXFLAGS += ${shell $(DEFINE) "$(CC)" MBEDTLS_CONFIG_FILE='"<crypto/mbedtls_config.h>"'} endif diff --git a/crypto/mbedtls/Makefile b/crypto/mbedtls/Makefile index 241e076ea..b2640fb76 100644 --- a/crypto/mbedtls/Makefile +++ b/crypto/mbedtls/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/crypto/mbedtls/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -37,34 +35,8 @@ UNPACK ?= unzip -q -o MBEDTLS_UNPACKLIBDIR = $(MBEDTLS_UNPACKNAME)$(DELIM)library MBEDTLS_UNPACKPROGDIR = $(MBEDTLS_UNPACKNAME)$(DELIM)programs -MBEDTLS_FRAMEWORK_URL ?= "https://github.com/Mbed-TLS/mbedtls-framework/archive" - -MBEDTLS_FRAMEWORK_VERSION = df3307f2b4fe512def60886024f7be8fd1523ccd -MBEDTLS_FRAMEWORK_ZIP = $(MBEDTLS_FRAMEWORK_VERSION).zip - -MBEDTLS_FRAMEWORK_UNPACKNAME = mbedtls-framework - # This lets Mbed TLS better use some of the POSIX features we have -CFLAGS += ${DEFINE_PREFIX}unix - -mbedtls/library/bignum.c_CFLAGS += -fno-lto -mbedtls/library/ctr_drbg.c_CFLAGS += -Wno-array-bounds - -# Build break on Assemble compiler if -fno-omit-frame-pointer and -O3 enabled at same time -# {standard input}: Assembler messages: -# {standard input}:2560: Error: branch out of range -# make[2]: *** [apps/Application.mk:170: mbedtls/library/sha256.o] Error 1 - -ifeq ($(CONFIG_FRAME_POINTER),y) - ifeq ($(CONFIG_DEBUG_OPTLEVEL),"-O3") - mbedtls/library/sha256.c_CFLAGS += -O2 - mbedtls/library/cmac.c_CFLAGS += -O2 - endif -endif - -ifeq ($(CONFIG_ARCH_SIM),y) - CFLAGS += -O0 -endif +CFLAGS += ${shell $(DEFINE) "$(CC)" __unix__} CSRCS = $(wildcard $(MBEDTLS_UNPACKLIBDIR)$(DELIM)*.c) @@ -72,32 +44,17 @@ $(MBEDTLS_ZIP): @echo "Downloading: $(MBEDTLS_URL)/$(MBEDTLS_ZIP)" $(Q) curl -O -L $(MBEDTLS_URL)/$(MBEDTLS_ZIP) -$(MBEDTLS_FRAMEWORK_ZIP): - @echo "Downloading: $(MBEDTLS_FRAMEWORK_URL)/$(MBEDTLS_FRAMEWORK_ZIP)" - $(Q) curl -O -L $(MBEDTLS_FRAMEWORK_URL)/$(MBEDTLS_FRAMEWORK_ZIP) - $(MBEDTLS_UNPACKNAME): $(MBEDTLS_ZIP) @echo "Unpacking: $(MBEDTLS_ZIP) -> $(MBEDTLS_UNPACKNAME)" $(Q) $(UNPACK) $(MBEDTLS_ZIP) $(Q) mv mbedtls-$(MBEDTLS_VERSION) $(MBEDTLS_UNPACKNAME) - $(Q) patch -p1 -d $(MBEDTLS_UNPACKNAME) < 0001-mbedtls-entropy_poll-use-getrandom-to-get-the-system.patch - $(Q) patch -p1 -d $(MBEDTLS_UNPACKNAME) < 0002-mbedtls-add-mbedtls-x509-crt-pool.patch - $(Q) patch -p1 -d $(MBEDTLS_UNPACKNAME) < 0003-Fix-MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT-warning.patch $(Q) touch $(MBEDTLS_UNPACKNAME) -$(MBEDTLS_FRAMEWORK_UNPACKNAME): $(MBEDTLS_FRAMEWORK_ZIP) - @echo "Unpacking: $(MBEDTLS_ZIP) -> $(MBEDTLS_FRAMEWORK_UNPACKNAME)" - $(Q) $(UNPACK) $(MBEDTLS_FRAMEWORK_ZIP) - $(Q) mv mbedtls-framework-$(MBEDTLS_FRAMEWORK_VERSION) $(MBEDTLS_FRAMEWORK_UNPACKNAME) - -# Download and unpack tarball if no git repo found -ifeq ($(wildcard $(MBEDTLS_UNPACKNAME)/.git),) context:: $(MBEDTLS_UNPACKNAME) distclean:: $(call DELDIR, $(MBEDTLS_UNPACKNAME)) $(call DELFILE, $(MBEDTLS_ZIP)) -endif # Configuration Applications @@ -123,81 +80,6 @@ STACKSIZE += $(CONFIG_MBEDTLS_APP_SELFTEST_STACKSIZE) MAINSRC += $(MBEDTLS_UNPACKPROGDIR)/test/selftest.c endif -ifeq ($(CONFIG_MBEDTLS_APP_SSL_CLIENT2),y) - -PROGNAME += $(CONFIG_MBEDTLS_APP_SSL_CLIENT2_PROGNAME) -PRIORITY += $(CONFIG_MBEDTLS_APP_SSL_CLIENT2_PRIORITY) -STACKSIZE += $(CONFIG_MBEDTLS_APP_SSL_CLIENT2_STACKSIZE) - -MAINSRC += $(MBEDTLS_UNPACKPROGDIR)/ssl/ssl_client2.c -CSRCS += $(MBEDTLS_UNPACKPROGDIR)/ssl/ssl_test_lib.c -CSRCS += $(MBEDTLS_UNPACKPROGDIR)/test/query_config.c -CSRCS += $(MBEDTLS_UNPACKNAME)/tests/src/certs.c -CSRCS += $(MBEDTLS_FRAMEWORK_UNPACKNAME)/tests/src/helpers.c -CSRCS += $(MBEDTLS_FRAMEWORK_UNPACKNAME)/tests/src/psa_crypto_helpers.c -CFLAGS += ${INCDIR_PREFIX}$(MBEDTLS_UNPACKLIBDIR) -CFLAGS += ${INCDIR_PREFIX}$(MBEDTLS_UNPACKNAME)/tests/include -CFLAGS += ${INCDIR_PREFIX}$(MBEDTLS_FRAMEWORK_UNPACKNAME)/tests/include -CFLAGS += ${INCDIR_PREFIX}$(MBEDTLS_FRAMEWORK_UNPACKNAME)/tests/programs -endif - -# Download and unpack tarball if no git repo found -ifeq ($(wildcard $(MBEDTLS_FRAMEWORK_UNPACKNAME)/.git),) -context:: $(MBEDTLS_FRAMEWORK_UNPACKNAME) - -distclean:: - $(call DELDIR, $(MBEDTLS_FRAMEWORK_UNPACKNAME)) - $(call DELFILE, $(MBEDTLS_FRAMEWORK_ZIP)) -endif - -endif - -# Configuration alternative implementation - -ifneq ($(CONFIG_MBEDTLS_ENTROPY_HARDWARE_ALT)$(CONFIG_MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG),) -CSRCS += $(APPDIR)/crypto/mbedtls/source/entropy_alt.c -endif - -ifeq ($(CONFIG_MBEDTLS_ALT),y) - -CSRCS += $(APPDIR)/crypto/mbedtls/source/dev_alt.c - -ifeq ($(CONFIG_MBEDTLS_AES_ALT),y) -CSRCS += $(APPDIR)/crypto/mbedtls/source/aes_alt.c -endif - -ifeq ($(CONFIG_MBEDTLS_CMAC_ALT),y) -CSRCS += $(APPDIR)/crypto/mbedtls/source/cmac_alt.c -endif - -ifeq ($(CONFIG_MBEDTLS_MD5_ALT),y) -CSRCS += $(APPDIR)/crypto/mbedtls/source/md5_alt.c -endif - -ifeq ($(CONFIG_MBEDTLS_POLY1305_ALT),y) -CSRCS += $(APPDIR)/crypto/mbedtls/source/poly1305_alt.c -endif - -ifeq ($(CONFIG_MBEDTLS_RIPEMD160_ALT),y) -CSRCS += $(APPDIR)/crypto/mbedtls/source/ripemd160_alt.c -endif - -ifeq ($(CONFIG_MBEDTLS_SHA1_ALT),y) -CSRCS += $(APPDIR)/crypto/mbedtls/source/sha1_alt.c -endif - -ifeq ($(CONFIG_MBEDTLS_SHA256_ALT),y) -CSRCS += $(APPDIR)/crypto/mbedtls/source/sha256_alt.c -endif - -ifeq ($(CONFIG_MBEDTLS_SHA512_ALT),y) -CSRCS += $(APPDIR)/crypto/mbedtls/source/sha512_alt.c -endif - -ifeq ($(CONFIG_MBEDTLS_BIGNUM_ALT),y) -CSRCS += $(APPDIR)/crypto/mbedtls/source/bignum_alt.c -endif - endif include $(APPDIR)/Application.mk diff --git a/crypto/mbedtls/include/aes_alt.h b/crypto/mbedtls/include/aes_alt.h deleted file mode 100644 index 0ba13cc41..000000000 --- a/crypto/mbedtls/include/aes_alt.h +++ /dev/null @@ -1,46 +0,0 @@ -/**************************************************************************** - * apps/crypto/mbedtls/include/aes_alt.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - ****************************************************************************/ - -#ifndef __APPS_CRYPTO_MBEDTLS_INCLUDE_AES_ALT_H -#define __APPS_CRYPTO_MBEDTLS_INCLUDE_AES_ALT_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "dev_alt.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define MAX_KEY_SIZE 64 - -typedef struct mbedtls_aes_context -{ - cryptodev_context_t dev; - unsigned char key[MAX_KEY_SIZE]; -} -mbedtls_aes_context; - -#define mbedtls_aes_xts_context mbedtls_aes_context - -#endif /* __APPS_CRYPTO_MBEDTLS_INCLUDE_AES_ALT_H */ diff --git a/crypto/mbedtls/include/cmac_alt.h b/crypto/mbedtls/include/cmac_alt.h deleted file mode 100644 index a6068aabc..000000000 --- a/crypto/mbedtls/include/cmac_alt.h +++ /dev/null @@ -1,42 +0,0 @@ -/**************************************************************************** - * apps/crypto/mbedtls/include/cmac_alt.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - ****************************************************************************/ - -#ifndef __APPS_CRYPTO_MBEDTLS_INCLUDE_CMAC_ALT_H -#define __APPS_CRYPTO_MBEDTLS_INCLUDE_CMAC_ALT_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "dev_alt.h" - -#define CMAC_KEY_MAX_SIZE 32 - -struct mbedtls_cmac_context_t -{ - cryptodev_context_t dev; - unsigned char key[CMAC_KEY_MAX_SIZE]; - uint32_t keybits; - uint32_t cipher_type; - uint32_t mac_type; -}; - -#endif /* __APPS_CRYPTO_MBEDTLS_INCLUDE_CMAC_ALT_H */ diff --git a/crypto/mbedtls/include/dev_alt.h b/crypto/mbedtls/include/dev_alt.h deleted file mode 100644 index caed8b9eb..000000000 --- a/crypto/mbedtls/include/dev_alt.h +++ /dev/null @@ -1,47 +0,0 @@ -/**************************************************************************** - * apps/crypto/mbedtls/include/dev_alt.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - ****************************************************************************/ - -#ifndef __APPS_CRYPTO_MBEDTLS_INCLUDE_DEV_ALT_H -#define __APPS_CRYPTO_MBEDTLS_INCLUDE_DEV_ALT_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <crypto/cryptodev.h> - -typedef struct cryptodev_context_s -{ - int fd; - struct session_op session; - struct crypt_op crypt; -} -cryptodev_context_t; - -int cryptodev_init(FAR cryptodev_context_t *ctx); -int cryptodev_clone(FAR cryptodev_context_t *dst, - FAR const cryptodev_context_t *src); -void cryptodev_free(FAR cryptodev_context_t *ctx); -int cryptodev_get_session(FAR cryptodev_context_t *ctx); -void cryptodev_free_session(FAR cryptodev_context_t *ctx); -int cryptodev_crypt(FAR cryptodev_context_t *ctx); - -#endif /* __APPS_CRYPTO_MBEDTLS_INCLUDE_DEV_ALT_H */ diff --git a/crypto/mbedtls/include/mbedtls/mbedtls_config.h b/crypto/mbedtls/include/mbedtls/mbedtls_config.h deleted file mode 100644 index f61cb60c0..000000000 --- a/crypto/mbedtls/include/mbedtls/mbedtls_config.h +++ /dev/null @@ -1,4991 +0,0 @@ -/**************************************************************************** - * apps/crypto/mbedtls/include/mbedtls/mbedtls_config.h - * - * SPDX-License-Identifier: Apache-2.0 - * SPDX-FileCopyrightText: Copyright The Mbed TLS Contributors - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - ****************************************************************************/ - -/** - * \file mbedtls_config.h - * - * \brief Configuration options (set of defines) - * - * This set of compile-time options may be used to enable - * or disable features selectively, and reduce the global - * memory footprint. - */ - -#ifndef __APPS_CRYPTO_MBEDTLS_INCLUDE_MBEDTLS_MBEDTLS_CONFIG_H -#define __APPS_CRYPTO_MBEDTLS_INCLUDE_MBEDTLS_MBEDTLS_CONFIG_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -/** - * This is an optional version symbol that enables compatibility handling of - * config files. - * - * It is equal to the #MBEDTLS_VERSION_NUMBER of the Mbed TLS version that - * introduced the config format we want to be compatible with. - */ - -/* #define MBEDTLS_CONFIG_VERSION 0x03000000 */ - -/** - * \name SECTION: System support - * - * This section sets system specific settings. - * \{ - */ - -/** - * \def MBEDTLS_HAVE_ASM - * - * The compiler has support for asm(). - * - * Requires support for asm() in compiler. - * - * Used in: - * library/aesni.h - * library/aria.c - * library/bn_mul.h - * library/constant_time.c - * library/padlock.h - * - * Required by: - * MBEDTLS_AESCE_C - * MBEDTLS_AESNI_C (on some platforms) - * MBEDTLS_PADLOCK_C - * - * Comment to disable the use of assembly code. - */ -#ifdef CONFIG_MBEDTLS_HAVE_ASM -#define MBEDTLS_HAVE_ASM -#endif - -/** - * \def MBEDTLS_NO_UDBL_DIVISION - * - * The platform lacks support for double-width integer division (64-bit - * division on a 32-bit platform, 128-bit division on a 64-bit platform). - * - * Used in: - * include/mbedtls/bignum.h - * library/bignum.c - * - * The bignum code uses double-width division to speed up some operations. - * Double-width division is often implemented in software that needs to - * be linked with the program. The presence of a double-width integer - * type is usually detected automatically through preprocessor macros, - * but the automatic detection cannot know whether the code needs to - * and can be linked with an implementation of division for that type. - * By default division is assumed to be usable if the type is present. - * Uncomment this option to prevent the use of double-width division. - * - * Note that division for the native integer type is always required. - * Furthermore, a 64-bit type is always required even on a 32-bit - * platform, but it need not support multiplication or division. In some - * cases it is also desirable to disable some double-width operations. For - * example, if double-width division is implemented in software, disabling - * it can reduce code size in some embedded targets. - */ - -/* #define MBEDTLS_NO_UDBL_DIVISION */ - -/** - * \def MBEDTLS_NO_64BIT_MULTIPLICATION - * - * The platform lacks support for 32x32 -> 64-bit multiplication. - * - * Used in: - * library/poly1305.c - * - * Some parts of the library may use multiplication of two unsigned 32-bit - * operands with a 64-bit result in order to speed up computations. On some - * platforms, this is not available in hardware and has to be implemented in - * software, usually in a library provided by the toolchain. - * - * Sometimes it is not desirable to have to link to that library. This option - * removes the dependency of that library on platforms that lack a hardware - * 64-bit multiplier by embedding a software implementation in Mbed TLS. - * - * Note that depending on the compiler, this may decrease performance - * compared to using the library function provided by the toolchain. - */ - -/* #define MBEDTLS_NO_64BIT_MULTIPLICATION */ - -/** - * \def MBEDTLS_HAVE_SSE2 - * - * CPU supports SSE2 instruction set. - * - * Uncomment if the CPU supports SSE2 (IA-32 specific). - */ - -/* #define MBEDTLS_HAVE_SSE2 */ - -/** - * \def MBEDTLS_HAVE_TIME - * - * System has time.h and time(). - * The time does not need to be correct, only time differences are used, - * by contrast with MBEDTLS_HAVE_TIME_DATE - * - * Defining MBEDTLS_HAVE_TIME allows you to specify - * MBEDTLS_PLATFORM_TIME_ALT, MBEDTLS_PLATFORM_TIME_MACRO, - * MBEDTLS_PLATFORM_TIME_TYPE_MACRO and MBEDTLS_PLATFORM_STD_TIME. - * - * Comment if your system does not support time functions. - * - * \note If MBEDTLS_TIMING_C is set - to enable the semi-portable timing - * interface - timing.c will include time.h on suitable platforms - * regardless of the setting of MBEDTLS_HAVE_TIME, unless - * MBEDTLS_TIMING_ALT is used. See timing.c for more information. - */ -#define MBEDTLS_HAVE_TIME - -/** - * \def MBEDTLS_HAVE_TIME_DATE - * - * System has time.h, time(), and an implementation for - * mbedtls_platform_gmtime_r() (see below). - * The time needs to be correct (not necessarily very accurate, but at least - * the date should be correct). This is used to verify the validity period of - * X.509 certificates. - * - * Comment if your system does not have a correct clock. - * - * \note mbedtls_platform_gmtime_r() is an abstraction in platform_util.h - * that behaves similarly to the gmtime_r() function from the C standard. - * Refer to the documentation for mbedtls_platform_gmtime_r() - * for more information. - * - * \note It is possible to configure an implementation for - * mbedtls_platform_gmtime_r() at compile-time by using the macro - * MBEDTLS_PLATFORM_GMTIME_R_ALT. - */ -#ifdef CONFIG_MBEDTLS_HAVE_TIME_DATE -#define MBEDTLS_HAVE_TIME_DATE -#endif - -/** - * \def MBEDTLS_PLATFORM_MEMORY - * - * Enable the memory allocation layer. - * - * By default Mbed TLS uses the system-provided calloc() and free(). - * This allows different allocators (self-implemented or provided) to be - * provided to the platform abstraction layer. - * - * Enabling #MBEDTLS_PLATFORM_MEMORY without the - * MBEDTLS_PLATFORM_{FREE,CALLOC}_MACROs will provide - * "mbedtls_platform_set_calloc_free()" allowing you to set an alternative - * calloc() and free() function pointer at runtime. - * - * Enabling #MBEDTLS_PLATFORM_MEMORY and specifying - * MBEDTLS_PLATFORM_{CALLOC,FREE}_MACROs will allow you to specify the - * alternate function at compile time. - * - * An overview of how the value of mbedtls_calloc is determined: - * - * - if !MBEDTLS_PLATFORM_MEMORY - * - mbedtls_calloc = calloc - * - if MBEDTLS_PLATFORM_MEMORY - * - if (MBEDTLS_PLATFORM_CALLOC_MACRO && MBEDTLS_PLATFORM_FREE_MACRO): - * - mbedtls_calloc = MBEDTLS_PLATFORM_CALLOC_MACRO - * - if !(MBEDTLS_PLATFORM_CALLOC_MACRO && MBEDTLS_PLATFORM_FREE_MACRO): - * - Dynamic setup via mbedtls_platform_set_calloc_free is no - * possible with a default value MBEDTLS_PLATFORM_STD_CALLOC. - * - How is MBEDTLS_PLATFORM_STD_CALLOC handled? - * - if MBEDTLS_PLATFORM_NO_STD_FUNCTIONS: - * - MBEDTLS_PLATFORM_STD_CALLOC is not set to anything; - * - MBEDTLS_PLATFORM_STD_MEM_HDR can be included if present; - * - if !MBEDTLS_PLATFORM_NO_STD_FUNCTIONS: - * - if MBEDTLS_PLATFORM_STD_CALLOC is present: - * - User-defined MBEDTLS_PLATFORM_STD_CALLOC is respected; - * - if !MBEDTLS_PLATFORM_STD_CALLOC: - * - MBEDTLS_PLATFORM_STD_CALLOC = calloc - * - * - At this point the presence of MBEDTLS_PLATFORM_STD_CALLOC is - * checked. - * - if !MBEDTLS_PLATFORM_STD_CALLOC - * - MBEDTLS_PLATFORM_STD_CALLOC = uninitialized_calloc - * - * - mbedtls_calloc = MBEDTLS_PLATFORM_STD_CALLOC. - * - * Defining MBEDTLS_PLATFORM_CALLOC_MACRO and #MBEDTLS_PLATFORM_STD_CALLOC at - * the same time is not possible. MBEDTLS_PLATFORM_CALLOC_MACRO and - * MBEDTLS_PLATFORM_FREE_MACRO must both be defined or undefined at the same - * time. #MBEDTLS_PLATFORM_STD_CALLOC and #MBEDTLS_PLATFORM_STD_FREE do not - * have to be defined at the same time, as, if they are used, dynamic setup - * of these functions is possible. See the tree above to see how are they - * handled in all cases. An uninitialized #MBEDTLS_PLATFORM_STD_CALLOC always - * fails, returning a null pointer. An uninitialized - * #MBEDTLS_PLATFORM_STD_FREE does not do anything. - * - * Requires: MBEDTLS_PLATFORM_C - * - * Enable this layer to allow use of alternative memory allocators. - */ -#ifdef CONFIG_MBEDTLS_PLATFORM_MEMORY -#define MBEDTLS_PLATFORM_MEMORY -#endif - -/** - * \def MBEDTLS_PLATFORM_NO_STD_FUNCTIONS - * - * Do not assign standard functions in the platform layer (e.g. calloc() to - * MBEDTLS_PLATFORM_STD_CALLOC and printf() to MBEDTLS_PLATFORM_STD_PRINTF) - * - * This makes sure there are no linking errors on platforms that do not - * support these functions. You will HAVE to provide alternatives, either - * at runtime via the platform_set_xxx() functions or at compile time by - * setting the MBEDTLS_PLATFORM_STD_XXX defines, or enabling a - * MBEDTLS_PLATFORM_XXX_MACRO. - * - * Requires: MBEDTLS_PLATFORM_C - * - * Uncomment to prevent default assignment of standard functions in the - * platform layer. - */ - -/* #define MBEDTLS_PLATFORM_NO_STD_FUNCTIONS */ - -/** - * \def MBEDTLS_PLATFORM_EXIT_ALT - * - * MBEDTLS_PLATFORM_XXX_ALT: Uncomment a macro to let Mbed TLS support the - * function in the platform abstraction layer. - * - * Example: In case you uncomment MBEDTLS_PLATFORM_PRINTF_ALT, Mbed TLS will - * provide a function "mbedtls_platform_set_printf()" that allows you to set - * an alternative printf function pointer. - * - * All these define require MBEDTLS_PLATFORM_C to be defined! - * - * \note MBEDTLS_PLATFORM_SNPRINTF_ALT is required on Windows; - * it will be enabled automatically by check_config.h - * - * \warning MBEDTLS_PLATFORM_XXX_ALT cannot be defined at the same time as - * MBEDTLS_PLATFORM_XXX_MACRO! - * - * Requires: MBEDTLS_PLATFORM_TIME_ALT requires MBEDTLS_HAVE_TIME - * - * Uncomment a macro to enable alternate implementation of specific base - * platform function - */ - -/* #define MBEDTLS_PLATFORM_SETBUF_ALT - * #define MBEDTLS_PLATFORM_EXIT_ALT - * #define MBEDTLS_PLATFORM_TIME_ALT - * #define MBEDTLS_PLATFORM_FPRINTF_ALT - * #define MBEDTLS_PLATFORM_PRINTF_ALT - * #define MBEDTLS_PLATFORM_SNPRINTF_ALT - * #define MBEDTLS_PLATFORM_VSNPRINTF_ALT - * #define MBEDTLS_PLATFORM_NV_SEED_ALT - * #define MBEDTLS_PLATFORM_SETUP_TEARDOWN_ALT - * #define MBEDTLS_PLATFORM_MS_TIME_ALT - */ - -/** - * Uncomment the macro to let Mbed TLS use your alternate implementation of - * mbedtls_platform_gmtime_r(). This replaces the default implementation in - * platform_util.c. - * - * gmtime() is not a thread-safe function as defined in the C standard. The - * library will try to use safer implementations of this function, such as - * gmtime_r() when available. However, if Mbed TLS cannot identify the target - * system, the implementation of mbedtls_platform_gmtime_r() will default to - * using the standard gmtime(). In this case, calls from the library to - * gmtime() will be guarded by the global mutex - * mbedtls_threading_gmtime_mutex if MBEDTLS_THREADING_C is enabled. We - * recommend that calls from outside the library are also guarded with this - * mutex to avoid race conditions. However, if the macro - * MBEDTLS_PLATFORM_GMTIME_R_ALT is defined, Mbed TLS will unconditionally - * use the implementation for mbedtls_platform_gmtime_r() supplied at - * compile time. - */ - -/* #define MBEDTLS_PLATFORM_GMTIME_R_ALT */ - -/** - * Uncomment the macro to let Mbed TLS use your alternate implementation of - * mbedtls_platform_zeroize(), to wipe sensitive data in memory. This - * replaces the default implementation in platform_util.c. - * - * By default, the library uses a system function such as memset_s() - * (optional feature of C11), explicit_bzero() (BSD and compatible), or - * SecureZeroMemory (Windows). If no such function is detected, the library - * falls back to a plain C implementation. Compilers are technically - * permitted to optimize this implementation out, meaning that the memory is - * not actually wiped. The library tries to prevent that, but the C language - * makes it impossible to guarantee that the memory will always be wiped. - * - * If your platform provides a guaranteed method to wipe memory which - * `platform_util.c` does not detect, define this macro to the name of - * a function that takes two arguments, a `void *` pointer and a length, - * and wipes that many bytes starting at the specified address. For example, - * if your platform has explicit_bzero() but `platform_util.c` does not - * detect its presence, define `MBEDTLS_PLATFORM_ZEROIZE_ALT` to be - * `explicit_bzero` to use that function as mbedtls_platform_zeroize(). - */ - -/* #define MBEDTLS_PLATFORM_ZEROIZE_ALT */ - -/** - * \def MBEDTLS_DEPRECATED_WARNING - * - * Mark deprecated functions and features so that they generate a warning if - * used. Functionality deprecated in one version will usually be removed in - * the next version. You can enable this to help you prepare the transition - * to a new major version by making sure your code is not using this - * functionality. - * - * This only works with GCC and Clang. With other compilers, you may want to - * use MBEDTLS_DEPRECATED_REMOVED - * - * Uncomment to get warnings on using deprecated functions and features. - */ - -/* #define MBEDTLS_DEPRECATED_WARNING */ - -/** - * \def MBEDTLS_DEPRECATED_REMOVED - * - * Remove deprecated functions and features so that they generate an error if - * used. Functionality deprecated in one version will usually be removed in - * the next version. You can enable this to help you prepare the transition - * to a new major version by making sure your code is not using this - * functionality. - * - * Uncomment to get errors on using deprecated functions and features. - */ - -/* #define MBEDTLS_DEPRECATED_REMOVED */ - -/** \} name SECTION: System support */ - -/** - * \name SECTION: Mbed TLS feature support - * - * This section sets support for features that are or are not needed - * within the modules that are enabled. - * \{ - */ - -/** - * \def MBEDTLS_TIMING_ALT - * - * Uncomment to provide your own alternate implementation for - * mbedtls_timing_get_timer(), mbedtls_set_alarm(), mbedtls_set/get_delay() - * - * Only works if you have MBEDTLS_TIMING_C enabled. - * - * You will need to provide a header "timing_alt.h" and an implementation at - * compile time. - */ - -/* #define MBEDTLS_TIMING_ALT */ - -/** - * \def MBEDTLS_AES_ALT - * - * MBEDTLS__MODULE_NAME__ALT: Uncomment a macro to let Mbed TLS use your - * alternate core implementation of a symmetric crypto, an arithmetic or hash - * module (e.g. platform specific assembly optimized implementations). Keep - * in mind that the function prototypes should remain the same. - * - * This replaces the whole module. If you only want to replace one of the - * functions, use one of the MBEDTLS__FUNCTION_NAME__ALT flags. - * - * Example: In case you uncomment MBEDTLS_AES_ALT, Mbed TLS will no longer - * provide the "struct mbedtls_aes_context" definition and omit the base - * function declarations and implementations. "aes_alt.h" will be included - * from "aes.h" to include the new function definitions. - * - * Uncomment a macro to enable alternate implementation of the corresponding - * module. - * - * \warning MD5, DES and SHA-1 are considered weak and their - * use constitutes a security risk. If possible, we recommend - * avoiding dependencies on them, and considering stronger message - * digests and ciphers instead. - * - */ - -#ifdef CONFIG_MBEDTLS_AES_ALT -#define MBEDTLS_AES_ALT -#endif -/* #define MBEDTLS_ARIA_ALT - * #define MBEDTLS_BLOWFISH_ALT - * #define MBEDTLS_CAMELLIA_ALT - * #define MBEDTLS_CCM_ALT - * #define MBEDTLS_CHACHA20_ALT - * #define MBEDTLS_CHACHAPOLY_ALT - */ -#ifdef CONFIG_MBEDTLS_CMAC_ALT -#define MBEDTLS_CMAC_ALT -#endif -/* #define MBEDTLS_DES_ALT - * #define MBEDTLS_DHM_ALT - * #define MBEDTLS_ECJPAKE_ALT - * #define MBEDTLS_GCM_ALT - * #define MBEDTLS_NIST_KW_ALT - */ -#ifdef CONFIG_MBEDTLS_MD5_ALT -#define MBEDTLS_MD5_ALT -#endif -#ifdef CONFIG_MBEDTLS_POLY1305_ALT -#define MBEDTLS_POLY1305_ALT -#endif -#ifdef CONFIG_MBEDTLS_RIPEMD160_ALT -#define MBEDTLS_RIPEMD160_ALT -#endif -/* #define MBEDTLS_RSA_ALT - */ -#ifdef CONFIG_MBEDTLS_SHA1_ALT -#define MBEDTLS_SHA1_ALT -#endif -#ifdef CONFIG_MBEDTLS_SHA256_ALT -#define MBEDTLS_SHA256_ALT -#endif -#ifdef CONFIG_MBEDTLS_SHA512_ALT -#define MBEDTLS_SHA512_ALT -#endif -#ifdef CONFIG_MBEDTLS_BIGNUM_ALT -#define MBEDTLS_BIGNUM_ALT -#endif -/* #define MBEDTLS_XTEA_ALT - */ - -/* When replacing the elliptic curve module, please consider, that it is - * implemented with two .c files: - * - ecp.c - * - ecp_curves.c - * You can replace them very much like all the other - * MBEDTLS__MODULE_NAME__ALT macros as described above. The only difference - * is that you have to make sure that you provide functionality for - * both .c files. - */ - -/* #define MBEDTLS_ECP_ALT */ - -/** - * \def MBEDTLS_SHA256_PROCESS_ALT - * - * MBEDTLS__FUNCTION_NAME__ALT: Uncomment a macro to let Mbed TLS use you - * alternate core implementation of symmetric crypto or hash function. Keep - * in mind that function prototypes should remain the same. - * - * This replaces only one function. The header file from Mbed TLS is still - * used, in contrast to the MBEDTLS__MODULE_NAME__ALT flags. - * - * Example: In case you uncomment MBEDTLS_SHA256_PROCESS_ALT, Mbed TLS will - * no longer provide the mbedtls_sha1_process() function, but it will still - * provide the other function (using your mbedtls_sha1_process() function) - * and the definition of mbedtls_sha1_context, so your implementation of - * mbedtls_sha1_process must be compatible with this definition. - * - * \note If you use the AES_xxx_ALT macros, then it is recommended to also - * set MBEDTLS_AES_ROM_TABLES in order to help the linker - * garbage-collect the AES tables. - * - * Uncomment a macro to enable alternate implementation of the corresponding - * function. - * - * \warning MD5, DES and SHA-1 are considered weak and their use - * constitutes a security risk. If possible, we recommend avoiding - * dependencies on them, and considering stronger message digests - * and ciphers instead. - * - * \warning If both MBEDTLS_ECDSA_SIGN_ALT and MBEDTLS_ECDSA_DETERMINISTIC - * are enabled, then the deterministic ECDH signature functions - * pass the static HMAC-DRBG as RNG to mbedtls_ecdsa_sign(). - * Therefore alternative implementations should use the RNG only - * for generating the ephemeral key and nothing else. If this is - * not possible, then MBEDTLS_ECDSA_DETERMINISTIC should be - * disabled and an alternative implementation should be provided - * for mbedtls_ecdsa_sign_det_ext(). - * - */ - -/* #define MBEDTLS_MD5_PROCESS_ALT - * #define MBEDTLS_RIPEMD160_PROCESS_ALT - * #define MBEDTLS_SHA1_PROCESS_ALT - * #define MBEDTLS_SHA256_PROCESS_ALT - * #define MBEDTLS_SHA512_PROCESS_ALT - * #define MBEDTLS_DES_SETKEY_ALT - * #define MBEDTLS_DES_CRYPT_ECB_ALT - * #define MBEDTLS_DES3_CRYPT_ECB_ALT - * #define MBEDTLS_AES_SETKEY_ENC_ALT - * #define MBEDTLS_AES_SETKEY_DEC_ALT - * #define MBEDTLS_AES_ENCRYPT_ALT - * #define MBEDTLS_AES_DECRYPT_ALT - * #define MBEDTLS_ECDH_GEN_PUBLIC_ALT - * #define MBEDTLS_ECDH_COMPUTE_SHARED_ALT - * #define MBEDTLS_ECDSA_VERIFY_ALT - * #define MBEDTLS_ECDSA_SIGN_ALT - * #define MBEDTLS_ECDSA_GENKEY_ALT - */ - -/** - * \def MBEDTLS_ECP_INTERNAL_ALT - * - * Expose a part of the internal interface of the Elliptic Curve Point - * module. - * - * MBEDTLS_ECP__FUNCTION_NAME__ALT: Uncomment a macro to let mbed TLS use - * your alternative core implementation of elliptic curve arithmetic. - * Keep in mind that function prototypes should remain the same. - * - * This partially replaces one function. The header file from mbed TLS is - *still - * used, in contrast to the MBEDTLS_ECP_ALT flag. The original implementation - * is still present and it is used for group structures not supported by the - * alternative. - * - * The original implementation can in addition be removed by setting the - * MBEDTLS_ECP_NO_FALLBACK option, in which case any function for which the - * corresponding MBEDTLS_ECP__FUNCTION_NAME__ALT macro is defined will not be - * able to fallback to curves not supported by the alternative - * implementation. - * - * Any of these options become available by defining MBEDTLS_ECP_INTERNAL_ALT - * and implementing the following functions: - * unsigned char mbedtls_internal_ecp_grp_capable( - * const mbedtls_ecp_group *grp ) - * int mbedtls_internal_ecp_init( const mbedtls_ecp_group *grp ) - * void mbedtls_internal_ecp_free( const mbedtls_ecp_group *grp ) - * The mbedtls_internal_ecp_grp_capable function should return 1 if the - * replacement functions implement arithmetic for the given group and 0 - * otherwise. - * The functions mbedtls_internal_ecp_init and mbedtls_internal_ecp_free are - * called before and after each point operation and provide an opportunity to - * implement optimized set up and tear down instructions. - * - * Example: In case you set MBEDTLS_ECP_INTERNAL_ALT and - * MBEDTLS_ECP_DOUBLE_JAC_ALT, mbed TLS will still provide the - * ecp_double_jac() function, but will use your - * mbedtls_internal_ecp_double_jac() if the group for the operation is - * supported by your implementation (i.e. - * yourmbedtls_internal_ecp_grp_capable() function returns 1 for this group) - * group is not supported by your implementation, then the original Mbed TLS - * If the implementation of ecp_double_jac() is used instead, unless this - * fallback behaviour is disabled by setting MBEDTLS_ECP_NO_FALLBACK - * (in which case ecp_double_jac() will return - * MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE). - * - * The function prototypes and the definition of mbedtls_ecp_group and - * mbedtls_ecp_point will not change based on MBEDTLS_ECP_INTERNAL_ALT, so - * your implementation of mbedtls_internal_ecp__function_name__ - * must be compatible with their definitions. - * - * Uncomment a macro to enable alternate implementation of the corresponding - * function. - */ - -/* Required for all the functions in this section */ - -/* #define MBEDTLS_ECP_INTERNAL_ALT */ - -/* Turn off software fallback for curves not supported in hardware */ - -/* #define MBEDTLS_ECP_NO_FALLBACK */ - -/* Support for Weierstrass curves with Jacobi representation */ - -/* #define MBEDTLS_ECP_RANDOMIZE_JAC_ALT - * #define MBEDTLS_ECP_ADD_MIXED_ALT - * #define MBEDTLS_ECP_DOUBLE_JAC_ALT - * #define MBEDTLS_ECP_NORMALIZE_JAC_MANY_ALT - * #define MBEDTLS_ECP_NORMALIZE_JAC_ALT - */ - -/* Support for curves with Montgomery arithmetic */ - -/* #define MBEDTLS_ECP_DOUBLE_ADD_MXZ_ALT - * #define MBEDTLS_ECP_RANDOMIZE_MXZ_ALT - * #define MBEDTLS_ECP_NORMALIZE_MXZ_ALT - */ - -/** - * \def MBEDTLS_ENTROPY_HARDWARE_ALT - * - * Uncomment this macro to let Mbed TLS use your own implementation of a - * hardware entropy collector. - * - * Your function must be called \c mbedtls_hardware_poll(), have the same - * prototype as declared in library/entropy_poll.h, and accept NULL as first - * argument. - * - * Uncomment to use your own hardware entropy collector. - */ -#ifdef CONFIG_MBEDTLS_ENTROPY_HARDWARE_ALT -#define MBEDTLS_ENTROPY_HARDWARE_ALT -#endif - -/** - * \def MBEDTLS_AES_ROM_TABLES - * - * Use precomputed AES tables stored in ROM. - * - * Uncomment this macro to use precomputed AES tables stored in ROM. - * Comment this macro to generate AES tables in RAM at runtime. - * - * Tradeoff: Using precomputed ROM tables reduces RAM usage by ~8kb - * (or ~2kb if \c MBEDTLS_AES_FEWER_TABLES is used) and reduces the - * initialization time before the first AES operation can be performed. - * It comes at the cost of additional ~8kb ROM use (resp. ~2kb if \c - * MBEDTLS_AES_FEWER_TABLES below is used), and potentially degraded - * performance if ROM access is slower than RAM access. - * - * This option is independent of \c MBEDTLS_AES_FEWER_TABLES. - * - */ -#ifdef CONFIG_MBEDTLS_AES_ROM_TABLES -#define MBEDTLS_AES_ROM_TABLES -#endif - -/** - * \def MBEDTLS_AES_FEWER_TABLES - * - * Use less ROM/RAM for AES tables. - * - * Uncommenting this macro omits 75% of the AES tables from - * ROM / RAM (depending on the value of \c MBEDTLS_AES_ROM_TABLES) - * by computing their values on the fly during operations - * (the tables are entry-wise rotations of one another). - * - * Tradeoff: Uncommenting this reduces the RAM / ROM footprint - * by ~6kb but at the cost of more arithmetic operations during - * runtime. Specifically, one has to compare 4 accesses within - * different tables to 4 accesses with additional arithmetic - * operations within the same table. The performance gain/loss - * depends on the system and memory details. - * - * This option is independent of \c MBEDTLS_AES_ROM_TABLES. - * - */ - -/* #define MBEDTLS_AES_FEWER_TABLES */ - -/** - * \def MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH - * - * Use only 128-bit keys in AES operations to save ROM. - * - * Uncomment this macro to remove support for AES operations that use 192- - * or 256-bit keys. - * - * Uncommenting this macro reduces the size of AES code by ~300 bytes - * on v8-M/Thumb2. - * - * Module: library/aes.c - * - * Requires: MBEDTLS_AES_C - */ - -/* #define MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH */ - -/** - * \def MBEDTLS_AES_USE_HARDWARE_ONLY - * - * Disable plain C implementation for AES. - * - * When the plain C implementation is enabled, and an implementation using a - * special CPU feature (such as MBEDTLS_AESCE_C) is also enabled, runtime - * detection will be used to select between them. - * - * If only one implementation is present, runtime detection will not be used. - * This configuration will crash at runtime if running on a CPU without the - * necessary features. It will not build unless at least one of - * MBEDTLS_AESCE_C and/or MBEDTLS_AESNI_C is enabled & present in the build. - */ - -/* #define MBEDTLS_AES_USE_HARDWARE_ONLY */ - -/** - * \def MBEDTLS_CAMELLIA_SMALL_MEMORY - * - * Use less ROM for the Camellia implementation (saves about 768 bytes). - * - * Uncomment this macro to use less memory for Camellia. - */ - -/* #define MBEDTLS_CAMELLIA_SMALL_MEMORY */ - -/** - * \def MBEDTLS_CHECK_RETURN_WARNING - * - * If this macro is defined, emit a compile-time warning if application code - * calls a function without checking its return value, but the return value - * should generally be checked in portable applications. - * - * This is only supported on platforms where #MBEDTLS_CHECK_RETURN is - * implemented. Otherwise this option has no effect. - * - * Uncomment to get warnings on using fallible functions without checking - * their return value. - * - * \note This feature is a work in progress. - * Warnings will be added to more functions in the future. - * - * \note A few functions are considered critical, and ignoring the return - * value of these functions will trigger a warning even if this - * macro is not defined. To completely disable return value check - * warnings, define #MBEDTLS_CHECK_RETURN with an empty expansion. - */ - -/* #define MBEDTLS_CHECK_RETURN_WARNING */ - -/** - * \def MBEDTLS_CIPHER_MODE_CBC - * - * Enable Cipher Block Chaining mode (CBC) for symmetric ciphers. - */ -#define MBEDTLS_CIPHER_MODE_CBC - -/** - * \def MBEDTLS_CIPHER_MODE_CFB - * - * Enable Cipher Feedback mode (CFB) for symmetric ciphers. - */ -#ifdef CONFIG_MBEDTLS_CIPHER_MODE_CFB -#define MBEDTLS_CIPHER_MODE_CFB -#endif - -/** - * \def MBEDTLS_CIPHER_MODE_CTR - * - * Enable Counter Block Cipher mode (CTR) for symmetric ciphers. - */ -#ifdef CONFIG_MBEDTLS_CIPHER_MODE_CTR -#define MBEDTLS_CIPHER_MODE_CTR -#endif - -/** - * \def MBEDTLS_CIPHER_MODE_OFB - * - * Enable Output Feedback mode (OFB) for symmetric ciphers. - */ -#ifdef CONFIG_MBEDTLS_CIPHER_MODE_OFB -#define MBEDTLS_CIPHER_MODE_OFB -#endif - -/** - * \def MBEDTLS_CIPHER_MODE_XTS - * - * Enable Xor-encrypt-xor with ciphertext stealing mode (XTS) for AES. - */ -#ifdef CONFIG_MBEDTLS_CIPHER_MODE_XTS -#define MBEDTLS_CIPHER_MODE_XTS -#endif - -/** - * \def MBEDTLS_CIPHER_NULL_CIPHER - * - * Enable NULL cipher. - * Warning: Only do so when you know what you are doing. This allows for - * encryption or channels without any security! - * - * To enable the following ciphersuites: - * MBEDTLS_TLS_ECDH_ECDSA_WITH_NULL_SHA - * MBEDTLS_TLS_ECDH_RSA_WITH_NULL_SHA - * MBEDTLS_TLS_ECDHE_ECDSA_WITH_NULL_SHA - * MBEDTLS_TLS_ECDHE_RSA_WITH_NULL_SHA - * MBEDTLS_TLS_ECDHE_PSK_WITH_NULL_SHA384 - * MBEDTLS_TLS_ECDHE_PSK_WITH_NULL_SHA256 - * MBEDTLS_TLS_ECDHE_PSK_WITH_NULL_SHA - * MBEDTLS_TLS_DHE_PSK_WITH_NULL_SHA384 - * MBEDTLS_TLS_DHE_PSK_WITH_NULL_SHA256 - * MBEDTLS_TLS_DHE_PSK_WITH_NULL_SHA - * MBEDTLS_TLS_RSA_WITH_NULL_SHA256 - * MBEDTLS_TLS_RSA_WITH_NULL_SHA - * MBEDTLS_TLS_RSA_WITH_NULL_MD5 - * MBEDTLS_TLS_RSA_PSK_WITH_NULL_SHA384 - * MBEDTLS_TLS_RSA_PSK_WITH_NULL_SHA256 - * MBEDTLS_TLS_RSA_PSK_WITH_NULL_SHA - * MBEDTLS_TLS_PSK_WITH_NULL_SHA384 - * MBEDTLS_TLS_PSK_WITH_NULL_SHA256 - * MBEDTLS_TLS_PSK_WITH_NULL_SHA - * - * Uncomment this macro to enable the NULL cipher and ciphersuites - */ - -/* #define MBEDTLS_CIPHER_NULL_CIPHER */ - -/** - * \def MBEDTLS_CIPHER_PADDING_PKCS7 - * - * MBEDTLS_CIPHER_PADDING_XXX: Uncomment or comment macros to add support for - * specific padding modes in the cipher layer with cipher modes that support - * padding (e.g. CBC) - * - * If you disable all padding modes, only full blocks can be used with CBC. - * - * Enable padding modes in the cipher layer. - */ -#ifdef CONFIG_MBEDTLS_CIPHER_PADDING_PKCS7 -#define MBEDTLS_CIPHER_PADDING_PKCS7 -#endif -#ifdef CONFIG_MBEDTLS_CIPHER_PADDING_ONE_AND_ZEROS -#define MBEDTLS_CIPHER_PADDING_ONE_AND_ZEROS -#endif -#ifdef CONFIG_MBEDTLS_CIPHER_PADDING_ZEROS_AND_LEN -#define MBEDTLS_CIPHER_PADDING_ZEROS_AND_LEN -#endif -#ifdef CONFIG_MBEDTLS_CIPHER_PADDING_ZEROS -#define MBEDTLS_CIPHER_PADDING_ZEROS -#endif - -/** \def MBEDTLS_CTR_DRBG_USE_128_BIT_KEY - * - * Uncomment this macro to use a 128-bit key in the CTR_DRBG module. - * Without this, CTR_DRBG uses a 256-bit key - * unless \c MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH is set. - */ - -/* #define MBEDTLS_CTR_DRBG_USE_128_BIT_KEY */ - -/** - * Enable the verified implementations of ECDH primitives from Project - * Everest (currently only Curve25519). This feature changes the layout of - * ECDH contexts and therefore is a compatibility break for applications that - * access fields of a mbedtls_ecdh_context structure directly. See also - * MBEDTLS_ECDH_LEGACY_CONTEXT in include/mbedtls/ecdh.h. - * - * The Everest code is provided under the Apache 2.0 license only; therefore - * enabling this option is not compatible with taking the library under the - * GPL v2.0-or-later license. - */ - -/* #define MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED */ - -/** - * \def MBEDTLS_ECP_DP_SECP192R1_ENABLED - * - * MBEDTLS_ECP_XXXX_ENABLED: Enables specific curves within the Elliptic - * Curve module. By default all supported curves are enabled. - * - * Comment macros to disable the curve and functions for it - */ - -/* Short Weierstrass curves (supporting ECP, ECDH, ECDSA) */ -#ifdef CONFIG_MBEDTLS_ECP_DP_SECP192R1_ENABLED -#define MBEDTLS_ECP_DP_SECP192R1_ENABLED -#endif -#ifdef CONFIG_MBEDTLS_ECP_DP_SECP224R1_ENABLED -#define MBEDTLS_ECP_DP_SECP224R1_ENABLED -#endif -#ifdef CONFIG_MBEDTLS_ECP_DP_SECP256R1_ENABLED -#define MBEDTLS_ECP_DP_SECP256R1_ENABLED -#endif -#ifdef CONFIG_MBEDTLS_ECP_DP_SECP384R1_ENABLED -#define MBEDTLS_ECP_DP_SECP384R1_ENABLED -#endif -#ifdef CONFIG_MBEDTLS_ECP_DP_SECP521R1_ENABLED -#define MBEDTLS_ECP_DP_SECP521R1_ENABLED -#endif -#ifdef CONFIG_MBEDTLS_ECP_DP_SECP192K1_ENABLED -#define MBEDTLS_ECP_DP_SECP192K1_ENABLED -#endif -#ifdef CONFIG_MBEDTLS_ECP_DP_SECP224K1_ENABLED -#define MBEDTLS_ECP_DP_SECP224K1_ENABLED -#endif -#ifdef CONFIG_MBEDTLS_ECP_DP_SECP256K1_ENABLED -#define MBEDTLS_ECP_DP_SECP256K1_ENABLED -#endif -#ifdef CONFIG_MBEDTLS_ECP_DP_BP256R1_ENABLED -#define MBEDTLS_ECP_DP_BP256R1_ENABLED -#endif -#ifdef CONFIG_MBEDTLS_ECP_DP_BP384R1_ENABLED -#define MBEDTLS_ECP_DP_BP384R1_ENABLED -#endif -#ifdef CONFIG_MBEDTLS_ECP_DP_BP512R1_ENABLED -#define MBEDTLS_ECP_DP_BP512R1_ENABLED -#endif - -/* Montgomery curves (supporting ECP) */ -#ifdef CONFIG_MBEDTLS_ECP_DP_CURVE25519_ENABLED -#define MBEDTLS_ECP_DP_CURVE25519_ENABLED -#endif -#ifdef CONFIG_MBEDTLS_ECP_DP_CURVE448_ENABLED -#define MBEDTLS_ECP_DP_CURVE448_ENABLED -#endif - -/** - * \def MBEDTLS_ECP_NIST_OPTIM - * - * Enable specific 'modulo p' routines for each NIST prime. - * Depending on the prime and architecture, makes operations 4 to 8 times - * faster on the corresponding curve. - * - * Comment this macro to disable NIST curves optimisation. - */ -#ifdef CONFIG_MBEDTLS_ECP_NIST_OPTIM -#define MBEDTLS_ECP_NIST_OPTIM -#endif - -/** - * \def MBEDTLS_ECP_RESTARTABLE - * - * Enable "non-blocking" ECC operations that can return early and be resumed. - * - * This allows various functions to pause by returning - * #MBEDTLS_ERR_ECP_IN_PROGRESS (or, for functions in the SSL module, - * #MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS) and then be called later again in - * order to further progress and eventually complete their operation. This is - * controlled through mbedtls_ecp_set_max_ops() which limits the maximum - * number of ECC operations a function may perform before pausing; see - * mbedtls_ecp_set_max_ops() for more information. - * - * This is useful in non-threaded environments if you want to avoid blocking - * for too long on ECC (and, hence, X.509 or SSL/TLS) operations. - * - * This option: - * - Adds xxx_restartable() variants of existing operations in the - * following modules, with corresponding restart context types: - * - ECP (for Short Weierstrass curves only): scalar multiplication (mul), - * linear combination (muladd); - * - ECDSA: signature generation & verification; - * - PK: signature generation & verification; - * - X509: certificate chain verification. - * - Adds mbedtls_ecdh_enable_restart() in the ECDH module. - * - Changes the behaviour of TLS 1.2 clients (not servers) when using the - * ECDHE-ECDSA key exchange (not other key exchanges) to make all ECC - * computations restartable: - * - ECDH operations from the key exchange, only for Short Weierstrass - * curves, only when MBEDTLS_USE_PSA_CRYPTO is not enabled. - * - verification of the server's key exchange signature; - * - verification of the server's certificate chain; - * - generation of the client's signature if client authentication is used, - * with an ECC key/certificate. - * - * \note In the cases above, the usual SSL/TLS functions, such as - * mbedtls_ssl_handshake(), can now return - * MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS. - * - * \note When this option and MBEDTLS_USE_PSA_CRYPTO are both enabled, - * restartable operations in PK, X.509 and TLS (see above) are not - * using PSA. On the other hand, ECDH computations in TLS are using - * PSA, and are not restartable. These are temporary limitations that - * should be lifted in the future. - * - * \note This option only works with the default software implementation of - * elliptic curve functionality. It is incompatible with - * MBEDTLS_ECP_ALT, MBEDTLS_ECDH_XXX_ALT, MBEDTLS_ECDSA_XXX_ALT. - * - * Requires: MBEDTLS_ECP_C - * - * Uncomment this macro to enable restartable ECC computations. - */ -#ifdef CONFIG_MBEDTLS_ECP_RESTARTABLE -#define MBEDTLS_ECP_RESTARTABLE -#endif - -/** - * Uncomment to enable using new bignum code in the ECC modules. - * - * \warning This is currently experimental, incomplete and therefore should - * not be used in production. - */ - -/* #define MBEDTLS_ECP_WITH_MPI_UINT */ - -/** - * \def MBEDTLS_ECDSA_DETERMINISTIC - * - * Enable deterministic ECDSA (RFC 6979). - * Standard ECDSA is "fragile" in the sense that lack of entropy when signing - * may result in a compromise of the long-term signing key. This is avoided - * by the deterministic variant. - * - * Requires: MBEDTLS_HMAC_DRBG_C, MBEDTLS_ECDSA_C - * - * Comment this macro to disable deterministic ECDSA. - */ -#ifdef CONFIG_MBEDTLS_ECDSA_DETERMINISTIC -#define MBEDTLS_ECDSA_DETERMINISTIC -#endif - -/** - * \def MBEDTLS_KEY_EXCHANGE_PSK_ENABLED - * - * Enable the PSK based ciphersuite modes in SSL / TLS. - * - * This enables the following ciphersuites (if other requisites are - * enabled as well): - * MBEDTLS_TLS_PSK_WITH_AES_256_GCM_SHA384 - * MBEDTLS_TLS_PSK_WITH_AES_256_CBC_SHA384 - * MBEDTLS_TLS_PSK_WITH_AES_256_CBC_SHA - * MBEDTLS_TLS_PSK_WITH_CAMELLIA_256_GCM_SHA384 - * MBEDTLS_TLS_PSK_WITH_CAMELLIA_256_CBC_SHA384 - * MBEDTLS_TLS_PSK_WITH_AES_128_GCM_SHA256 - * MBEDTLS_TLS_PSK_WITH_AES_128_CBC_SHA256 - * MBEDTLS_TLS_PSK_WITH_AES_128_CBC_SHA - * MBEDTLS_TLS_PSK_WITH_CAMELLIA_128_GCM_SHA256 - * MBEDTLS_TLS_PSK_WITH_CAMELLIA_128_CBC_SHA256 - */ -#ifdef CONFIG_MBEDTLS_KEY_EXCHANGE_PSK_ENABLED -#define MBEDTLS_KEY_EXCHANGE_PSK_ENABLED -#endif - -/** - * \def MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED - * - * Enable the DHE-PSK based ciphersuite modes in SSL / TLS. - * - * Requires: MBEDTLS_DHM_C - * - * This enables the following ciphersuites (if other requisites are - * enabled as well): - * MBEDTLS_TLS_DHE_PSK_WITH_AES_256_GCM_SHA384 - * MBEDTLS_TLS_DHE_PSK_WITH_AES_256_CBC_SHA384 - * MBEDTLS_TLS_DHE_PSK_WITH_AES_256_CBC_SHA - * MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_256_GCM_SHA384 - * MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_256_CBC_SHA384 - * MBEDTLS_TLS_DHE_PSK_WITH_AES_128_GCM_SHA256 - * MBEDTLS_TLS_DHE_PSK_WITH_AES_128_CBC_SHA256 - * MBEDTLS_TLS_DHE_PSK_WITH_AES_128_CBC_SHA - * MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_128_GCM_SHA256 - * MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_128_CBC_SHA256 - * - * \warning Using DHE constitutes a security risk as it - * is not possible to validate custom DH parameters. - * If possible, it is recommended users should consider - * preferring other methods of key exchange. - * See dhm.h for more details. - * - */ -#ifdef CONFIG_MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED -#define MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED -#endif - -/** - * \def MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED - * - * Enable the ECDHE-PSK based ciphersuite modes in SSL / TLS. - * - * Requires: MBEDTLS_ECDH_C or (MBEDTLS_USE_PSA_CRYPTO and PSA_WANT_ALG_ECDH) - * - * This enables the following ciphersuites (if other requisites are - * enabled as well): - * MBEDTLS_TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384 - * MBEDTLS_TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA - * MBEDTLS_TLS_ECDHE_PSK_WITH_CAMELLIA_256_CBC_SHA384 - * MBEDTLS_TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256 - * MBEDTLS_TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA - * MBEDTLS_TLS_ECDHE_PSK_WITH_CAMELLIA_128_CBC_SHA256 - */ -#ifdef CONFIG_MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED -#define MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED -#endif - -/** - * \def MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED - * - * Enable the RSA-PSK based ciphersuite modes in SSL / TLS. - * - * Requires: MBEDTLS_RSA_C, MBEDTLS_PKCS1_V15, - * MBEDTLS_X509_CRT_PARSE_C - * - * This enables the following ciphersuites (if other requisites are - * enabled as well): - * MBEDTLS_TLS_RSA_PSK_WITH_AES_256_GCM_SHA384 - * MBEDTLS_TLS_RSA_PSK_WITH_AES_256_CBC_SHA384 - * MBEDTLS_TLS_RSA_PSK_WITH_AES_256_CBC_SHA - * MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_256_GCM_SHA384 - * MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_256_CBC_SHA384 - * MBEDTLS_TLS_RSA_PSK_WITH_AES_128_GCM_SHA256 - * MBEDTLS_TLS_RSA_PSK_WITH_AES_128_CBC_SHA256 - * MBEDTLS_TLS_RSA_PSK_WITH_AES_128_CBC_SHA - * MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_128_GCM_SHA256 - * MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_128_CBC_SHA256 - */ -#ifdef CONFIG_MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED -#define MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED -#endif - -/** - * \def MBEDTLS_X509_CRT_POOL - * - * Enable X.509 certificate pool. - * - * Module: library/x509_crt_pool.c - * - * Requires: MBEDTLS_THREADING_C - * - * This module is required for X.509 certificate pool. - */ -#ifdef CONFIG_MBEDTLS_X509_CRT_POOL -#define MBEDTLS_X509_CRT_POOL -#endif - -/** - * \def MBEDTLS_KEY_EXCHANGE_RSA_ENABLED - * - * Enable the RSA-only based ciphersuite modes in SSL / TLS. - * - * Requires: MBEDTLS_RSA_C, MBEDTLS_PKCS1_V15, - * MBEDTLS_X509_CRT_PARSE_C - * - * This enables the following ciphersuites (if other requisites are - * enabled as well): - * MBEDTLS_TLS_RSA_WITH_AES_256_GCM_SHA384 - * MBEDTLS_TLS_RSA_WITH_AES_256_CBC_SHA256 - * MBEDTLS_TLS_RSA_WITH_AES_256_CBC_SHA - * MBEDTLS_TLS_RSA_WITH_CAMELLIA_256_GCM_SHA384 - * MBEDTLS_TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256 - * MBEDTLS_TLS_RSA_WITH_CAMELLIA_256_CBC_SHA - * MBEDTLS_TLS_RSA_WITH_AES_128_GCM_SHA256 - * MBEDTLS_TLS_RSA_WITH_AES_128_CBC_SHA256 - * MBEDTLS_TLS_RSA_WITH_AES_128_CBC_SHA - * MBEDTLS_TLS_RSA_WITH_CAMELLIA_128_GCM_SHA256 - * MBEDTLS_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256 - * MBEDTLS_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA - */ -#define MBEDTLS_KEY_EXCHANGE_RSA_ENABLED - -/** - * \def MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED - * - * Enable the DHE-RSA based ciphersuite modes in SSL / TLS. - * - * Requires: MBEDTLS_DHM_C, MBEDTLS_RSA_C, MBEDTLS_PKCS1_V15, - * MBEDTLS_X509_CRT_PARSE_C - * - * This enables the following ciphersuites (if other requisites are - * enabled as well): - * MBEDTLS_TLS_DHE_RSA_WITH_AES_256_GCM_SHA384 - * MBEDTLS_TLS_DHE_RSA_WITH_AES_256_CBC_SHA256 - * MBEDTLS_TLS_DHE_RSA_WITH_AES_256_CBC_SHA - * MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_256_GCM_SHA384 - * MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256 - * MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA - * MBEDTLS_TLS_DHE_RSA_WITH_AES_128_GCM_SHA256 - * MBEDTLS_TLS_DHE_RSA_WITH_AES_128_CBC_SHA256 - * MBEDTLS_TLS_DHE_RSA_WITH_AES_128_CBC_SHA - * MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_128_GCM_SHA256 - * MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 - * MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA - * - * \warning Using DHE constitutes a security risk as it - * is not possible to validate custom DH parameters. - * If possible, it is recommended users should consider - * preferring other methods of key exchange. - * See dhm.h for more details. - * - */ -#ifdef CONFIG_MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED -#define MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED -#endif - -/** - * \def MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED - * - * Enable the ECDHE-RSA based ciphersuite modes in SSL / TLS. - * - * Requires: MBEDTLS_ECDH_C or (MBEDTLS_USE_PSA_CRYPTO and PSA_WANT_ALG_ECDH) - * MBEDTLS_RSA_C - * MBEDTLS_PKCS1_V15 - * MBEDTLS_X509_CRT_PARSE_C - * - * This enables the following ciphersuites (if other requisites are - * enabled as well): - * MBEDTLS_TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 - * MBEDTLS_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 - * MBEDTLS_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA - * MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_256_GCM_SHA384 - * MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_256_CBC_SHA384 - * MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 - * MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 - * MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA - * MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_128_GCM_SHA256 - * MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 - */ -#ifdef CONFIG_MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED -#define MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED -#endif - -/** - * \def MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED - * - * Enable the ECDHE-ECDSA based ciphersuite modes in SSL / TLS. - * - * Requires: MBEDTLS_ECDH_C or (MBEDTLS_USE_PSA_CRYPTO and PSA_WANT_ALG_ECDH) - * MBEDTLS_ECDSA_C or (MBEDTLS_USE_PSA_CRYPTO and - * PSA_WANT_ALG_ECDSA) - * MBEDTLS_X509_CRT_PARSE_C - * - * This enables the following ciphersuites (if other requisites are - * enabled as well): - * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 - * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384 - * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA - * MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_GCM_SHA384 - * MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_CBC_SHA384 - * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 - * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 - * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA - * MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_GCM_SHA256 - * MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_CBC_SHA256 - */ -#ifdef CONFIG_MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED -#define MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED -#endif - -/** - * \def MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED - * - * Enable the ECDH-ECDSA based ciphersuite modes in SSL / TLS. - * - * Requires: MBEDTLS_ECDH_C or (MBEDTLS_USE_PSA_CRYPTO and PSA_WANT_ALG_ECDH) - * MBEDTLS_ECDSA_C or (MBEDTLS_USE_PSA_CRYPTO and - * PSA_WANT_ALG_ECDSA) - * MBEDTLS_X509_CRT_PARSE_C - * - * This enables the following ciphersuites (if other requisites are - * enabled as well): - * MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA - * MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA - * MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256 - * MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384 - * MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256 - * MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384 - * MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_128_CBC_SHA256 - * MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_256_CBC_SHA384 - * MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_128_GCM_SHA256 - * MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_256_GCM_SHA384 - */ -#ifdef CONFIG_MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED -#define MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED -#endif - -/** - * \def MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED - * - * Enable the ECDH-RSA based ciphersuite modes in SSL / TLS. - * - * Requires: MBEDTLS_ECDH_C or (MBEDTLS_USE_PSA_CRYPTO and PSA_WANT_ALG_ECDH) - * MBEDTLS_RSA_C - * MBEDTLS_X509_CRT_PARSE_C - * - * This enables the following ciphersuites (if other requisites are - * enabled as well): - * MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA - * MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA - * MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256 - * MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384 - * MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256 - * MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384 - * MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_128_CBC_SHA256 - * MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_256_CBC_SHA384 - * MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_128_GCM_SHA256 - * MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_256_GCM_SHA384 - */ -#ifdef CONFIG_MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED -#define MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED -#endif - -/** - * \def MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED - * - * Enable the ECJPAKE based ciphersuite modes in SSL / TLS. - * - * \warning This is currently experimental. EC J-PAKE support is based on the - * Thread v1.0.0 specification; incompatible changes to the specification - * might still happen. For this reason, this is disabled by default. - * - * Requires: MBEDTLS_ECJPAKE_C or (MBEDTLS_USE_PSA_CRYPTO and - * PSA_WANT_ALG_JPAKE) - * SHA-256 (via MBEDTLS_SHA256_C or a PSA driver) - * MBEDTLS_ECP_DP_SECP256R1_ENABLED - * - * \warning If SHA-256 is provided only by a PSA driver, you must call - * psa_crypto_init() before the first handshake (even if - * MBEDTLS_USE_PSA_CRYPTO is disabled). - * - * This enables the following ciphersuites (if other requisites are - * enabled as well): - * MBEDTLS_TLS_ECJPAKE_WITH_AES_128_CCM_8 - */ - -/* #define MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED */ - -/** - * \def MBEDTLS_PK_PARSE_EC_EXTENDED - * - * Enhance support for reading EC keys using variants of SEC1 not allowed by - * RFC 5915 and RFC 5480. - * - * Currently this means parsing the SpecifiedECDomain choice of EC - * parameters (only known groups are supported, not arbitrary domains, to - * avoid validation issues). - * - * Disable if you only need to support RFC 5915 + 5480 key formats. - */ -#ifdef CONFIG_MBEDTLS_PK_PARSE_EC_EXTENDED -#define MBEDTLS_PK_PARSE_EC_EXTENDED -#endif - -/** - * \def MBEDTLS_PK_PARSE_EC_COMPRESSED - * - * Enable the support for parsing public keys of type Short Weierstrass - * (MBEDTLS_ECP_DP_SECP_XXX and MBEDTLS_ECP_DP_BP_XXX) which are using the - * compressed point format. This parsing is done through ECP module's - * functions. - * - * \note As explained in the description of MBEDTLS_ECP_PF_COMPRESSED - * (in ecp.h) the only unsupported curves are MBEDTLS_ECP_DP_SECP224R1 - * and MBEDTLS_ECP_DP_SECP224K1. - */ -#ifdef CONFIG_MBEDTLS_PK_PARSE_EC_COMPRESSED -#define MBEDTLS_PK_PARSE_EC_COMPRESSED -#endif - -/** - * \def MBEDTLS_ERROR_STRERROR_DUMMY - * - * Enable a dummy error function to make use of mbedtls_strerror() in - * third party libraries easier when MBEDTLS_ERROR_C is disabled - * (no effect when MBEDTLS_ERROR_C is enabled). - * - * You can safely disable this if MBEDTLS_ERROR_C is enabled, or if you're - * not using mbedtls_strerror() or error_strerror() in your application. - * - * Disable if you run into name conflicts and want to really remove the - * mbedtls_strerror() - */ -#ifdef CONFIG_MBEDTLS_ERROR_STRERROR_DUMMY -#define MBEDTLS_ERROR_STRERROR_DUMMY -#endif - -/** - * \def MBEDTLS_GENPRIME - * - * Enable the prime-number generation code. - * - * Requires: MBEDTLS_BIGNUM_C - */ -#ifdef CONFIG_MBEDTLS_GENPRIME -#define MBEDTLS_GENPRIME -#endif - -/** - * \def MBEDTLS_FS_IO - * - * Enable functions that use the filesystem. - */ -#define MBEDTLS_FS_IO - -/** - * \def MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES - * - * Do not add default entropy sources in mbedtls_entropy_init(). - * - * This is useful to have more control over the added entropy sources in an - * application. - * - * Uncomment this macro to prevent loading of default entropy functions. - */ - -/* #define MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES */ - -/** - * \def MBEDTLS_NO_PLATFORM_ENTROPY - * - * Do not use built-in platform entropy functions. - * This is useful if your platform does not support - * standards like the /dev/urandom or Windows CryptoAPI. - * - * Uncomment this macro to disable the built-in platform entropy functions. - */ -#ifdef CONFIG_MBEDTLS_NO_PLATFORM_ENTROPY -#define MBEDTLS_NO_PLATFORM_ENTROPY -#endif - -/** - * \def MBEDTLS_ENTROPY_FORCE_SHA256 - * - * Force the entropy accumulator to use a SHA-256 accumulator instead of the - * default SHA-512 based one (if both are available). - * - * Requires: MBEDTLS_SHA256_C - * - * On 32-bit systems SHA-256 can be much faster than SHA-512. Use this option - * if you have performance concerns. - * - * This option is only useful if both MBEDTLS_SHA256_C and - * MBEDTLS_SHA512_C are defined. Otherwise the available hash module is used. - */ - -/* #define MBEDTLS_ENTROPY_FORCE_SHA256 */ - -/** - * \def MBEDTLS_ENTROPY_NV_SEED - * - * Enable the non-volatile (NV) seed file-based entropy source. - * (Also enables the NV seed read/write functions in the platform layer) - * - * This is crucial (if not required) on systems that do not have a - * cryptographic entropy source (in hardware or kernel) available. - * - * Requires: MBEDTLS_ENTROPY_C, MBEDTLS_PLATFORM_C - * - * \note The read/write functions that are used by the entropy source are - * determined in the platform layer, and can be modified at runtime - *and/or - * compile-time depending on the flags (MBEDTLS_PLATFORM_NV_SEED_*) - *used. - * - * \note If you use the default implementation functions that read a seedfile - * with regular fopen(), please make sure you make a seedfile with the - * proper name (defined in MBEDTLS_PLATFORM_STD_NV_SEED_FILE) and at - * least MBEDTLS_ENTROPY_BLOCK_SIZE bytes in size that can be read from - * and written to or you will get an entropy source error! The default - * implementation will only use the first MBEDTLS_ENTROPY_BLOCK_SIZE - * bytes from the file. - * - * \note The entropy collector will write to the seed file before entropy is - * given to an external source, to update it. - */ - -/* #define MBEDTLS_ENTROPY_NV_SEED */ - -/* MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER - * - * Enable key identifiers that encode a key owner identifier. - * - * The owner of a key is identified by a value of type - *::mbedtls_key_owner_id_t - * which is currently hard-coded to be int32_t. - * - * Note that this option is meant for internal use only and may be removed - * without notice. - */ - -/* #define MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER */ - -/** - * \def MBEDTLS_MEMORY_DEBUG - * - * Enable debugging of buffer allocator memory issues. Automatically prints - * (to stderr) all (fatal) messages on memory allocation issues. Enables - * function for 'debug output' of allocated memory. - * - * Requires: MBEDTLS_MEMORY_BUFFER_ALLOC_C - * - * Uncomment this macro to let the buffer allocator print out error messages. - */ - -/* #define MBEDTLS_MEMORY_DEBUG */ - -/** - * \def MBEDTLS_MEMORY_BACKTRACE - * - * Include backtrace information with each allocated block. - * - * Requires: MBEDTLS_MEMORY_BUFFER_ALLOC_C - * GLIBC-compatible backtrace() and backtrace_symbols() support - * - * Uncomment this macro to include backtrace information - */ - -/* #define MBEDTLS_MEMORY_BACKTRACE */ - -/** - * \def MBEDTLS_PK_RSA_ALT_SUPPORT - * - * Support external private RSA keys (eg from a HSM) in the PK layer. - * - * Comment this macro to disable support for external private RSA keys. - */ -#ifdef CONFIG_MBEDTLS_PK_RSA_ALT_SUPPORT -#define MBEDTLS_PK_RSA_ALT_SUPPORT -#endif - -/** - * \def MBEDTLS_PKCS1_V15 - * - * Enable support for PKCS#1 v1.5 encoding. - * - * Requires: MBEDTLS_RSA_C - * - * This enables support for PKCS#1 v1.5 operations. - */ -#define MBEDTLS_PKCS1_V15 - -/** - * \def MBEDTLS_PKCS1_V21 - * - * Enable support for PKCS#1 v2.1 encoding. - * - * Requires: MBEDTLS_RSA_C - * - * \warning If using a hash that is only provided by PSA drivers, you must - * call psa_crypto_init() before doing any PKCS#1 v2.1 operation. - * - * This enables support for RSAES-OAEP and RSASSA-PSS operations. - */ -#ifdef CONFIG_MBEDTLS_PKCS1_V21 -#define MBEDTLS_PKCS1_V21 -#endif - -/** \def MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS - * - * Enable support for platform built-in keys. If you enable this feature, - * you must implement the function mbedtls_psa_platform_get_builtin_key(). - * See the documentation of that function for more information. - * - * Built-in keys are typically derived from a hardware unique key or - * stored in a secure element. - * - * Requires: MBEDTLS_PSA_CRYPTO_C. - * - * \warning This interface is experimental and may change or be removed - * without notice. - */ - -/* #define MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS */ - -/** \def MBEDTLS_PSA_CRYPTO_CLIENT - * - * Enable support for PSA crypto client. - * - * \note This option allows to include the code necessary for a PSA - * crypto client when the PSA crypto implementation is not included in - * the library (MBEDTLS_PSA_CRYPTO_C disabled). The code included is - * the code to set and get PSA key attributes. - * The development of PSA drivers partially relying on the library to - * fulfill the hardware gaps is another possible usage of this option. - * - * \warning This interface is experimental and may change or be removed - * without notice. - */ - -/* #define MBEDTLS_PSA_CRYPTO_CLIENT */ - -/** \def MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG - * - * Make the PSA Crypto module use an external random generator provided - * by a driver, instead of Mbed TLS's entropy and DRBG modules. - * - * \note This random generator must deliver random numbers with cryptographic - * quality and high performance. It must supply unpredictable numbers - * with a uniform distribution. The implementation of this function - * is responsible for ensuring that the random generator is seeded - * with sufficient entropy. If you have a hardware TRNG which is slow - * or delivers non-uniform output, declare it as an entropy source - * with mbedtls_entropy_add_source() instead of enabling this option. - * - * If you enable this option, you must configure the type - * ::mbedtls_psa_external_random_context_t in psa/crypto_platform.h - * and define a function called mbedtls_psa_external_get_random() - * with the following prototype: - * ``` - * psa_status_t mbedtls_psa_external_get_random( - * mbedtls_psa_external_random_context_t *context, - * uint8_t *output, size_t output_size, size_t *output_length); - * ); - * ``` - * The \c context value is initialized to 0 before the first call. - * The function must fill the \c output buffer with \c output_size bytes - * of random data and set \c *output_length to \c output_size. - * - * Requires: MBEDTLS_PSA_CRYPTO_C - * - * \warning If you enable this option, code that uses the PSA cryptography - * interface will not use any of the entropy sources set up for - * the entropy module, nor the NV seed that MBEDTLS_ENTROPY_NV_SEED - * enables. - * - * \note This option is experimental and may be removed without notice. - */ - -#ifdef CONFIG_MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG -#define MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG -#endif - -/** - * \def MBEDTLS_PSA_CRYPTO_SPM - * - * When MBEDTLS_PSA_CRYPTO_SPM is defined, the code is built for SPM (Secure - * Partition Manager) integration which separates the code into two parts: a - * NSPE (Non-Secure Process Environment) and an SPE (Secure Process - * Environment). - * - * If you enable this option, your build environment must include a header - * file `"crypto_spe.h"` (either in the `psa` subdirectory of the Mbed TLS - * header files, or in another directory on the compiler's include search - * path). Alternatively, your platform may customize the header - * `psa/crypto_platform.h`, in which case it can skip or replace the - * inclusion of `"crypto_spe.h"`. - * - * Module: library/psa_crypto.c - * Requires: MBEDTLS_PSA_CRYPTO_C - * - */ - -/* #define MBEDTLS_PSA_CRYPTO_SPM */ - -/** - * \def MBEDTLS_PSA_KEY_STORE_DYNAMIC - * - * Dynamically resize the PSA key store to accommodate any number of - * volatile keys (until the heap memory is exhausted). - * - * If this option is disabled, the key store has a fixed size - * #MBEDTLS_PSA_KEY_SLOT_COUNT for volatile keys and loaded persistent keys - * together. - * - * This option has no effect when #MBEDTLS_PSA_CRYPTO_C is disabled. - * - * Module: library/psa_crypto.c - * Requires: MBEDTLS_PSA_CRYPTO_C - */ -#ifdef CONFIG_MBEDTLS_PSA_KEY_STORE_DYNAMIC -#define MBEDTLS_PSA_KEY_STORE_DYNAMIC -#endif - -/** - * Uncomment to enable p256-m. This is an alternative implementation of - * key generation, ECDH and (randomized) ECDSA on the curve SECP256R1. - * Compared to the default implementation: - * - * - p256-m has a much smaller code size and RAM footprint. - * - p256-m is only available via the PSA API. This includes the pk module - * when #MBEDTLS_USE_PSA_CRYPTO is enabled. - * - p256-m does not support deterministic ECDSA, EC-JPAKE, custom protocols - * over the core arithmetic, or deterministic derivation of keys. - * - * We recommend enabling this option if your application uses the PSA API - * and the only elliptic curve support it needs is ECDH and ECDSA over - * SECP256R1. - * - * If you enable this option, you do not need to enable any ECC-related - * MBEDTLS_xxx option. You do need to separately request support for the - * cryptographic mechanisms through the PSA API: - * - #MBEDTLS_PSA_CRYPTO_C and #MBEDTLS_PSA_CRYPTO_CONFIG for PSA-based - * configuration; - * - #MBEDTLS_USE_PSA_CRYPTO if you want to use p256-m from PK, X.509 or TLS; - * - #PSA_WANT_ECC_SECP_R1_256; - * - #PSA_WANT_ALG_ECDH and/or #PSA_WANT_ALG_ECDSA as needed; - * - #PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY, - * #PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_BASIC, - * #PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_IMPORT, - * #PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_EXPORT and/or - * #PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_GENERATE as needed. - * - * \note To benefit from the smaller code size of p256-m, make sure that you - * do not enable any ECC-related option not supported by p256-m: this - * would cause the built-in ECC implementation to be built as well, in - * order to provide the required option. - * Make sure #PSA_WANT_ALG_DETERMINISTIC_ECDSA, #PSA_WANT_ALG_JPAKE and - * #PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE, and curves other than - * SECP256R1 are disabled as they are not supported by this driver. - * Also, avoid defining #MBEDTLS_PK_PARSE_EC_COMPRESSED or - * #MBEDTLS_PK_PARSE_EC_EXTENDED as those currently require a subset of - * the built-in ECC implementation, see docs/driver-only-builds.md. - */ - -/* #define MBEDTLS_PSA_P256M_DRIVER_ENABLED */ - -/** - * \def MBEDTLS_PSA_INJECT_ENTROPY - * - * Enable support for entropy injection at first boot. This feature is - * required on systems that do not have a built-in entropy source (TRNG). - * This feature is currently not supported on systems that have a built-in - * entropy source. - * - * Requires: MBEDTLS_PSA_CRYPTO_STORAGE_C, MBEDTLS_ENTROPY_NV_SEED - * - */ - -/* #define MBEDTLS_PSA_INJECT_ENTROPY */ - -/** - * \def MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS - * - * Assume all buffers passed to PSA functions are owned exclusively by the - * PSA function and are not stored in shared memory. - * - * This option may be enabled if all buffers passed to any PSA function - * reside in memory that is accessible only to the PSA function during its - * execution. - * - * This option MUST be disabled whenever buffer arguments are in memory - * shared with an untrusted party, for example where arguments to PSA calls - * are passed across a trust boundary. - * - * \note Enabling this option reduces memory usage and code size. - * - * \note Enabling this option causes overlap of input and output buffers - * not to be supported by PSA functions. - */ -#ifdef CONFIG_MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS -#define MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS -#endif - -/** - * \def MBEDTLS_RSA_NO_CRT - * - * Do not use the Chinese Remainder Theorem - * for the RSA private operation. - * - * Uncomment this macro to disable the use of CRT in RSA. - * - */ - -/* #define MBEDTLS_RSA_NO_CRT */ - -/** - * \def MBEDTLS_SELF_TEST - * - * Enable the checkup functions (*_self_test). - */ -#ifdef CONFIG_MBEDTLS_SELF_TEST -#define MBEDTLS_SELF_TEST -#endif - -/** - * \def MBEDTLS_SHA256_SMALLER - * - * Enable an implementation of SHA-256 that has lower ROM footprint but also - * lower performance. - * - * The default implementation is meant to be a reasonable compromise between - * performance and size. This version optimizes more aggressively for size at - * the expense of performance. Eg on Cortex-M4 it reduces the size of - * mbedtls_sha256_process() from ~2KB to ~0.5KB for a performance hit of - * about 30%. - * - * Uncomment to enable the smaller implementation of SHA256. - */ - -/* #define MBEDTLS_SHA256_SMALLER */ - -/** - * \def MBEDTLS_SHA512_SMALLER - * - * Enable an implementation of SHA-512 that has lower ROM footprint but also - * lower performance. - * - * Uncomment to enable the smaller implementation of SHA512. - */ - -/* #define MBEDTLS_SHA512_SMALLER */ - -/** - * \def MBEDTLS_SSL_ALL_ALERT_MESSAGES - * - * Enable sending of alert messages in case of encountered errors as per RFC. - * If you choose not to send the alert messages, Mbed TLS can still - * communicate with other servers, only debugging of failures is harder. - * - * The advantage of not sending alert messages, is that no information is - * given about reasons for failures thus preventing adversaries of gaining - * intel. - * - * Enable sending of all alert messages - */ -#define MBEDTLS_SSL_ALL_ALERT_MESSAGES - -/** - * \def MBEDTLS_SSL_DTLS_CONNECTION_ID - * - * Enable support for the DTLS Connection ID (CID) extension, - * which allows to identify DTLS connections across changes - * in the underlying transport. The CID functionality is described - * in RFC 9146. - * - * Setting this option enables the SSL APIs `mbedtls_ssl_set_cid()`, - * mbedtls_ssl_get_own_cid()`, `mbedtls_ssl_get_peer_cid()` and - * `mbedtls_ssl_conf_cid()`. See the corresponding documentation for - * more information. - * - * The maximum lengths of outgoing and incoming CIDs can be configured - * through the options - * - MBEDTLS_SSL_CID_OUT_LEN_MAX - * - MBEDTLS_SSL_CID_IN_LEN_MAX. - * - * Requires: MBEDTLS_SSL_PROTO_DTLS - * - * Uncomment to enable the Connection ID extension. - */ -#ifdef CONFIG_MBEDTLS_SSL_DTLS_CONNECTION_ID -#define MBEDTLS_SSL_DTLS_CONNECTION_ID -#endif - -/** - * \def MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT - * - * Defines whether RFC 9146 (default) or the legacy version - * (version draft-ietf-tls-dtls-connection-id-05, - * https://tools.ietf.org/html/draft-ietf-tls-dtls-connection-id-05) - * is used. - * - * Set the value to 0 for the standard version, and - * 1 for the legacy draft version. - * - * \deprecated Support for the legacy version of the DTLS - * Connection ID feature is deprecated. Please - * switch to the standardized version defined - * in RFC 9146 enabled by utilizing - * MBEDTLS_SSL_DTLS_CONNECTION_ID without use - * of MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT. - * - * Requires: MBEDTLS_SSL_DTLS_CONNECTION_ID - */ -#ifdef CONFIG_MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT -#define MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT \ - CONFIG_MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT -#endif - -/** - * \def MBEDTLS_SSL_ASYNC_PRIVATE - * - * Enable asynchronous external private key operations in SSL. This allows - * you to configure an SSL connection to call an external cryptographic - * module to perform private key operations instead of performing the - * operation inside the library. - * - * Requires: MBEDTLS_X509_CRT_PARSE_C - */ - -/* #define MBEDTLS_SSL_ASYNC_PRIVATE */ - -/** - * \def MBEDTLS_SSL_CONTEXT_SERIALIZATION - * - * Enable serialization of the TLS context structures, through use of the - * functions mbedtls_ssl_context_save() and mbedtls_ssl_context_load(). - * - * This pair of functions allows one side of a connection to serialize the - * context associated with the connection, then free or re-use that context - * while the serialized state is persisted elsewhere, and finally deserialize - * that state to a live context for resuming read/write operations on the - * connection. From a protocol perspective, the state of the connection is - * unaffected, in particular this is entirely transparent to the peer. - * - * Note: this is distinct from TLS session resumption, which is part of the - * protocol and fully visible by the peer. TLS session resumption enables - * establishing new connections associated to a saved session with shorter, - * lighter handshakes, while context serialization is a local optimization in - * handling a single, potentially long-lived connection. - * - * Enabling these APIs makes some SSL structures larger, as 64 extra bytes - * are saved after the handshake to allow for more efficient serialization, - * so if you don't need this feature you'll save RAM by disabling it. - * - * Requires: MBEDTLS_GCM_C or MBEDTLS_CCM_C or MBEDTLS_CHACHAPOLY_C - * - * Comment to disable the context serialization APIs. - */ -#ifdef CONFIG_MBEDTLS_SSL_CONTEXT_SERIALIZATION -#define MBEDTLS_SSL_CONTEXT_SERIALIZATION -#endif - -/** - * \def MBEDTLS_SSL_DEBUG_ALL - * - * Enable the debug messages in SSL module for all issues. - * Debug messages have been disabled in some places to prevent timing - * attacks due to (unbalanced) debugging function calls. - * - * If you need all error reporting you should enable this during debugging, - * but remove this for production servers that should log as well. - * - * Uncomment this macro to report all debug messages on errors introducing - * a timing side-channel. - * - */ - -/* #define MBEDTLS_SSL_DEBUG_ALL */ - -/** \def MBEDTLS_SSL_ENCRYPT_THEN_MAC - * - * Enable support for Encrypt-then-MAC, RFC 7366. - * - * This allows peers that both support it to use a more robust protection for - * ciphersuites using CBC, providing deep resistance against timing attacks - * on the padding or underlying cipher. - * - * This only affects CBC ciphersuites, and is useless if none is defined. - * - * Requires: MBEDTLS_SSL_PROTO_TLS1_2 - * - * Comment this macro to disable support for Encrypt-then-MAC - */ -#ifdef CONFIG_MBEDTLS_SSL_ENCRYPT_THEN_MAC -#define MBEDTLS_SSL_ENCRYPT_THEN_MAC -#endif - -/** \def MBEDTLS_SSL_EXTENDED_MASTER_SECRET - * - * Enable support for RFC 7627: Session Hash and Extended Master Secret - * Extension. - * - * This was introduced as "the proper fix" to the Triple Handshake family of - * attacks, but it is recommended to always use it (even if you disable - * renegotiation), since it actually fixes a more fundamental issue in the - * original SSL/TLS design, and has implications beyond Triple Handshake. - * - * Requires: MBEDTLS_SSL_PROTO_TLS1_2 - * - * Comment this macro to disable support for Extended Master Secret. - */ -#ifdef CONFIG_MBEDTLS_SSL_EXTENDED_MASTER_SECRET -#define MBEDTLS_SSL_EXTENDED_MASTER_SECRET -#endif - -/** - * \def MBEDTLS_SSL_KEEP_PEER_CERTIFICATE - * - * This option controls the availability of the API - *mbedtls_ssl_get_peer_cert() - * giving access to the peer's certificate after completion of the handshake. - * - * Unless you need mbedtls_ssl_peer_cert() in your application, it is - * recommended to disable this option for reduced RAM usage. - * - * \note If this option is disabled, mbedtls_ssl_get_peer_cert() is still - * defined, but always returns \c NULL. - * - * \note This option has no influence on the protection against the - * triple handshake attack. Even if it is disabled, Mbed TLS will - * still ensure that certificates do not change during renegotiation, - * for example by keeping a hash of the peer's certificate. - * - * \note This option is required if MBEDTLS_SSL_PROTO_TLS1_3 is set. - * - * Comment this macro to disable storing the peer's certificate - * after the handshake. - */ -#ifdef CONFIG_MBEDTLS_SSL_KEEP_PEER_CERTIFICATE -#define MBEDTLS_SSL_KEEP_PEER_CERTIFICATE -#endif - -/** - * \def MBEDTLS_SSL_RENEGOTIATION - * - * Enable support for TLS renegotiation. - * - * The two main uses of renegotiation are (1) refresh keys on long-lived - * connections and (2) client authentication after the initial handshake. - * If you don't need renegotiation, it's probably better to disable it, since - * it has been associated with security issues in the past and is easy to - * misuse/misunderstand. - * - * Requires: MBEDTLS_SSL_PROTO_TLS1_2 - * - * Comment this to disable support for renegotiation. - * - * \note Even if this option is disabled, both client and server are aware - * of the Renegotiation Indication Extension (RFC 5746) used to - * prevent the SSL renegotiation attack (see RFC 5746 Sect. 1). - * (See \c mbedtls_ssl_conf_legacy_renegotiation for the - * configuration of this extension). - * - */ -#ifdef CONFIG_MBEDTLS_SSL_RENEGOTIATION -#define MBEDTLS_SSL_RENEGOTIATION -#endif - -/** - * \def MBEDTLS_SSL_MAX_FRAGMENT_LENGTH - * - * Enable support for RFC 6066 max_fragment_length extension in SSL. - * - * Comment this macro to disable support for the max_fragment_length - * extension - */ -#ifdef CONFIG_MBEDTLS_SSL_MAX_FRAGMENT_LENGTH -#define MBEDTLS_SSL_MAX_FRAGMENT_LENGTH -#endif - -/** - * \def MBEDTLS_SSL_RECORD_SIZE_LIMIT - * - * Enable support for RFC 8449 record_size_limit extension in SSL (TLS 1.3 - *only). - * - * Requires: MBEDTLS_SSL_PROTO_TLS1_3 - * - * Uncomment this macro to enable support for the record_size_limit extension - */ - -/* #define MBEDTLS_SSL_RECORD_SIZE_LIMIT */ - -/** - * \def MBEDTLS_SSL_PROTO_TLS1_2 - * - * Enable support for TLS 1.2 (and DTLS 1.2 if DTLS is enabled). - * - * Requires: Without MBEDTLS_USE_PSA_CRYPTO: MBEDTLS_MD_C and - * (MBEDTLS_SHA256_C or MBEDTLS_SHA384_C or - * SHA-256 or SHA-512 provided by a PSA driver) - * With MBEDTLS_USE_PSA_CRYPTO: - * PSA_WANT_ALG_SHA_256 or PSA_WANT_ALG_SHA_384 - * - * \warning If building with MBEDTLS_USE_PSA_CRYPTO, or if the hash(es) used - * are only provided by PSA drivers, you must call psa_crypto_init() before - * doing any TLS operations. - * - * Comment this macro to disable support for TLS 1.2 / DTLS 1.2 - */ -#ifdef CONFIG_MBEDTLS_SSL_PROTO_TLS1_2 -#define MBEDTLS_SSL_PROTO_TLS1_2 -#endif - -/** - * \def MBEDTLS_SSL_PROTO_TLS1_3 - * - * Enable support for TLS 1.3. - * - * \note See docs/architecture/tls13-support.md for a description of the TLS - * 1.3 support that this option enables. - * - * Requires: MBEDTLS_SSL_KEEP_PEER_CERTIFICATE - * Requires: MBEDTLS_PSA_CRYPTO_C - * - * \note TLS 1.3 uses PSA crypto for cryptographic operations that are - * directly performed by TLS 1.3 code. As a consequence, when TLS 1.3 - * is enabled, a TLS handshake may call psa_crypto_init(), even - * if it ends up negotiating a different TLS version. - * - * \note Cryptographic operations performed indirectly via another module - * (X.509, PK) or by code shared with TLS 1.2 (record protection, - * running handshake hash) only use PSA crypto if - * #MBEDTLS_USE_PSA_CRYPTO is enabled. - * - * Uncomment this macro to enable the support for TLS 1.3. - */ -#ifdef CONFIG_MBEDTLS_SSL_PROTO_TLS1_3 -#define MBEDTLS_SSL_PROTO_TLS1_3 -#endif - -/** - * \def MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE - * - * Enable TLS 1.3 middlebox compatibility mode. - * - * As specified in Section D.4 of RFC 8446, TLS 1.3 offers a compatibility - * mode to make a TLS 1.3 connection more likely to pass through middle boxes - * expecting TLS 1.2 traffic. - * - * Turning on the compatibility mode comes at the cost of a few added bytes - * on the wire, but it doesn't affect compatibility with TLS 1.3 - *implementations - * that don't use it. Therefore, unless transmission bandwidth is critical - * and you know that middlebox compatibility issues won't occur, - * it is therefore recommended to set this option. - * - * Comment to disable compatibility mode for TLS 1.3. If - * MBEDTLS_SSL_PROTO_TLS1_3 is not enabled, this option does not have any - * effect on the build. - * - */ -#ifdef CONFIG_MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE -#define MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE -#endif - -/** - * \def MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED - * - * Enable TLS 1.3 PSK key exchange mode. - * - * Comment to disable support for the PSK key exchange mode in TLS 1.3. If - * MBEDTLS_SSL_PROTO_TLS1_3 is not enabled, this option does not have any - * effect on the build. - * - */ -#ifdef CONFIG_MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED -#define MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED -#endif - -/** - * \def MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED - * - * Enable TLS 1.3 ephemeral key exchange mode. - * - * Requires: PSA_WANT_ALG_ECDH or PSA_WANT_ALG_FFDH - * MBEDTLS_X509_CRT_PARSE_C - * and at least one of: - * MBEDTLS_ECDSA_C or (MBEDTLS_USE_PSA_CRYPTO and - * PSA_WANT_ALG_ECDSA) - * MBEDTLS_PKCS1_V21 - * - * Comment to disable support for the ephemeral key exchange mode in TLS 1.3. - * If MBEDTLS_SSL_PROTO_TLS1_3 is not enabled, this option does not have any - * effect on the build. - * - */ -#ifdef CONFIG_MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED -#define MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED -#endif - -/** - * \def MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED - * - * Enable TLS 1.3 PSK ephemeral key exchange mode. - * - * Requires: PSA_WANT_ALG_ECDH or PSA_WANT_ALG_FFDH - * - * Comment to disable support for the PSK ephemeral key exchange mode in - * TLS 1.3. If MBEDTLS_SSL_PROTO_TLS1_3 is not enabled, this option does not - * have any effect on the build. - * - */ -#ifdef CONFIG_MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED -#define MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED -#endif - -/** - * \def MBEDTLS_SSL_EARLY_DATA - * - * Enable support for RFC 8446 TLS 1.3 early data. - * - * Requires: MBEDTLS_SSL_SESSION_TICKETS and either - * MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED or - * MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED - * - * Comment this to disable support for early data. If - * MBEDTLS_SSL_PROTO_TLS1_3 is not enabled, this option does not have any - * effect on the build. - * - * \note The maximum amount of early data can be set with - * MBEDTLS_SSL_MAX_EARLY_DATA_SIZE. - * - */ - -/* #define MBEDTLS_SSL_EARLY_DATA */ - -/** - * \def MBEDTLS_SSL_PROTO_DTLS - * - * Enable support for DTLS (all available versions). - * - * Enable this and MBEDTLS_SSL_PROTO_TLS1_2 to enable DTLS 1.2. - * - * Requires: MBEDTLS_SSL_PROTO_TLS1_2 - * - * Comment this macro to disable support for DTLS - */ -#ifdef CONFIG_MBEDTLS_SSL_PROTO_DTLS -#define MBEDTLS_SSL_PROTO_DTLS -#endif - -/** - * \def MBEDTLS_SSL_ALPN - * - * Enable support for RFC 7301 Application Layer Protocol Negotiation. - * - * Comment this macro to disable support for ALPN. - */ -#ifdef CONFIG_MBEDTLS_SSL_ALPN -#define MBEDTLS_SSL_ALPN -#endif - -/** - * \def MBEDTLS_SSL_DTLS_ANTI_REPLAY - * - * Enable support for the anti-replay mechanism in DTLS. - * - * Requires: MBEDTLS_SSL_TLS_C - * MBEDTLS_SSL_PROTO_DTLS - * - * \warning Disabling this is often a security risk! - * See mbedtls_ssl_conf_dtls_anti_replay() for details. - * - * Comment this to disable anti-replay in DTLS. - */ -#ifdef CONFIG_MBEDTLS_SSL_DTLS_ANTI_REPLAY -#define MBEDTLS_SSL_DTLS_ANTI_REPLAY -#endif - -/** - * \def MBEDTLS_SSL_DTLS_HELLO_VERIFY - * - * Enable support for HelloVerifyRequest on DTLS servers. - * - * This feature is highly recommended to prevent DTLS servers being used as - * amplifiers in DoS attacks against other hosts. It should always be enabled - * unless you know for sure amplification cannot be a problem in the - * environment in which your server operates. - * - * \warning Disabling this can be a security risk! (see above) - * - * Requires: MBEDTLS_SSL_PROTO_DTLS - * - * Comment this to disable support for HelloVerifyRequest. - */ -#ifdef CONFIG_MBEDTLS_SSL_DTLS_HELLO_VERIFY -#define MBEDTLS_SSL_DTLS_HELLO_VERIFY -#endif - -/** - * \def MBEDTLS_SSL_DTLS_SRTP - * - * Enable support for negotiation of DTLS-SRTP (RFC 5764) - * through the use_srtp extension. - * - * \note This feature provides the minimum functionality required - * to negotiate the use of DTLS-SRTP and to allow the derivation of - * the associated SRTP packet protection key material. - * In particular, the SRTP packet protection itself, as well as the - * demultiplexing of RTP and DTLS packets at the datagram layer - * (see Section 5 of RFC 5764), are not handled by this feature. - * Instead, after successful completion of a handshake negotiating - * the use of DTLS-SRTP, the extended key exporter API - * mbedtls_ssl_conf_export_keys_cb() should be used to implement - * the key exporter described in Section 4.2 of RFC 5764 and RFC 5705 - * (this is implemented in the SSL example programs). - * The resulting key should then be passed to an SRTP stack. - * - * Setting this option enables the runtime API - * mbedtls_ssl_conf_dtls_srtp_protection_profiles() - * through which the supported DTLS-SRTP protection - * profiles can be configured. You must call this API at - * runtime if you wish to negotiate the use of DTLS-SRTP. - * - * Requires: MBEDTLS_SSL_PROTO_DTLS - * - * Uncomment this to enable support for use_srtp extension. - */ - -/* #define MBEDTLS_SSL_DTLS_SRTP */ - -/** - * \def MBEDTLS_SSL_DTLS_CLIENT_PORT_REUSE - * - * Enable server-side support for clients that reconnect from the same port. - * - * Some clients unexpectedly close the connection and try to reconnect using - *the - * same source port. This needs special support from the server to handle the - * new connection securely, as described in section 4.2.8 of RFC 6347. This - * flag enables that support. - * - * Requires: MBEDTLS_SSL_DTLS_HELLO_VERIFY - * - * Comment this to disable support for clients reusing the source port. - */ -#ifdef CONFIG_MBEDTLS_SSL_DTLS_CLIENT_PORT_REUSE -#define MBEDTLS_SSL_DTLS_CLIENT_PORT_REUSE -#endif - -/** - * \def MBEDTLS_SSL_SESSION_TICKETS - * - * Enable support for RFC 5077 session tickets in SSL. - * Client-side, provides full support for session tickets (maintenance of a - * session store remains the responsibility of the application, though). - * Server-side, you also need to provide callbacks for writing and parsing - * tickets, including authenticated encryption and key management. Example - * callbacks are provided by MBEDTLS_SSL_TICKET_C. - * - * Comment this macro to disable support for SSL session tickets - */ -#ifdef CONFIG_MBEDTLS_SSL_SESSION_TICKETS -#define MBEDTLS_SSL_SESSION_TICKETS -#endif - -/** - * \def MBEDTLS_SSL_SERVER_NAME_INDICATION - * - * Enable support for RFC 6066 server name indication (SNI) in SSL. - * - * Requires: MBEDTLS_X509_CRT_PARSE_C - * - * Comment this macro to disable support for server name indication in SSL - */ -#ifdef CONFIG_MBEDTLS_SSL_SERVER_NAME_INDICATION -#define MBEDTLS_SSL_SERVER_NAME_INDICATION -#endif - -/** - * \def MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH - * - * When this option is enabled, the SSL buffer will be resized automatically - * based on the negotiated maximum fragment length in each direction. - * - * Requires: MBEDTLS_SSL_MAX_FRAGMENT_LENGTH - */ - -/* #define MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH */ - -/** - * \def MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN - * - * Enable testing of the constant-flow nature of some sensitive functions - * with clang's MemorySanitizer. This causes some existing tests to also test - * this non-functional property of the code under test. - * - * This setting requires compiling with clang -fsanitize=memory. The test - * suites can then be run normally. - * - * \warning This macro is only used for extended testing; it is not - * considered part of the library's API, so it may change or disappear - * at any time. - * - * Uncomment to enable testing of the constant-flow nature of selected code. - */ - -/* #define MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN */ - -/** - * \def MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND - * - * Enable testing of the constant-flow nature of some sensitive functions - * with valgrind's memcheck tool. This causes some existing tests to also - * test this non-functional property of the code under test. - * - * This setting requires valgrind headers for building, and is only useful - * for testing if the tests suites are run with valgrind's memcheck. This - * can be done for an individual test suite with 'valgrind ./test_suite_xxx', - * or when using CMake, this can be done for all test suites with - * 'make memcheck'. - * - * \warning This macro is only used for extended testing; it is not - * considered part of the library's API, - * so it may change or disappear at any time. - * - * Uncomment to enable testing of the constant-flow nature of selected code. - */ - -/* #define MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND */ - -/** - * \def MBEDTLS_TEST_HOOKS - * - * Enable features for invasive testing such as introspection functions and - * hooks for fault injection. This enables additional unit tests. - * - * Merely enabling this feature should not change the behavior of the - * product. It only adds new code, and new branching points where the - * default behavior is the same as when this feature is disabled. - * However, this feature increases the attack surface: there is an added - * risk of vulnerabilities, and more gadgets that can make exploits easier. - * Therefore this feature must never be enabled in production. - * - * See `docs/architecture/testing/mbed-crypto-invasive-testing.md` for more - * information. - * - * Uncomment to enable invasive tests. - */ - -/* #define MBEDTLS_TEST_HOOKS */ - -/** - * \def MBEDTLS_THREADING_ALT - * - * Provide your own alternate threading implementation. - * - * Requires: MBEDTLS_THREADING_C - * - * Uncomment this to allow your own alternate threading implementation. - */ - -/* #define MBEDTLS_THREADING_ALT */ - -/** - * \def MBEDTLS_THREADING_PTHREAD - * - * Enable the pthread wrapper layer for the threading layer. - * - * Requires: MBEDTLS_THREADING_C - * - * Uncomment this to enable pthread mutexes. - */ -#ifdef CONFIG_MBEDTLS_THREADING_PTHREAD -#define MBEDTLS_THREADING_PTHREAD -#endif - -/** - * \def MBEDTLS_USE_PSA_CRYPTO - * - * Make the X.509 and TLS libraries use PSA for cryptographic operations as - * much as possible, and enable new APIs for using keys handled by PSA - * Crypto. - * - * \note Development of this option is currently in progress, and parts of - * Mbed TLS's X.509 and TLS modules are not ported to PSA yet. However, these - * parts will still continue to work as usual, so enabling this option should - * not break backwards compatibility. - * - * \warning If you enable this option, you need to call `psa_crypto_init()` - * before calling any function from the SSL/TLS, X.509 or PK modules, except - * for the various mbedtls_xxx_init() functions which can be called at any - * time. - * - * \note An important and desirable effect of this option is that it allows - * PK, X.509 and TLS to take advantage of PSA drivers. For example, enabling - * this option is what allows use of drivers for ECDSA, ECDH and EC J-PAKE in - * those modules. However, note that even with this option disabled, some - * code in PK, X.509, TLS or the crypto library might still use PSA drivers, - * if it can determine it's safe to do so; currently that's the case for - * hashes. - * - * \note See docs/use-psa-crypto.md for a complete description this option. - * - * Requires: MBEDTLS_PSA_CRYPTO_C. - * - * Uncomment this to enable internal use of PSA Crypto and new associated - *APIs. - */ -#ifdef CONFIG_MBEDTLS_USE_PSA_CRYPTO -#define MBEDTLS_USE_PSA_CRYPTO -#endif - -/** - * \def MBEDTLS_PSA_CRYPTO_CONFIG - * - * This setting allows support for cryptographic mechanisms through the PSA - * API to be configured separately from support through the mbedtls API. - * - * When this option is disabled, the PSA API exposes the cryptographic - * mechanisms that can be implemented on top of the `mbedtls_xxx` API - * configured with `MBEDTLS_XXX` symbols. - * - * When this option is enabled, the PSA API exposes the cryptographic - * mechanisms requested by the `PSA_WANT_XXX` symbols defined in - * include/psa/crypto_config.h. The corresponding `MBEDTLS_XXX` settings are - * automatically enabled if required (i.e. if no PSA driver provides the - * mechanism). You may still freely enable additional `MBEDTLS_XXX` symbols - * in mbedtls_config.h. - * - * If the symbol #MBEDTLS_PSA_CRYPTO_CONFIG_FILE is defined, it specifies - * an alternative header to include instead of include/psa/crypto_config.h. - * - * \warning This option is experimental, in that the set of `PSA_WANT_XXX` - * symbols is not completely finalized yet, and the configuration - * tooling is not ideally adapted to having two separate - * configuration files. - * Future minor releases of Mbed TLS may make minor changes to those - * symbols, but we will endeavor to provide a transition path. - * Nonetheless, this option is considered mature enough to use in - * production, as long as you accept that you may need to make - * minor changes to psa/crypto_config.h when upgrading Mbed TLS. - */ - -/* #define MBEDTLS_PSA_CRYPTO_CONFIG */ - -/** - * \def MBEDTLS_VERSION_FEATURES - * - * Allow run-time checking of compile-time enabled features. Thus allowing - *users - * to check at run-time if the library is for instance compiled with - * threading support via mbedtls_version_check_feature(). - * - * Requires: MBEDTLS_VERSION_C - * - * Comment this to disable run-time checking and save ROM space - */ -#ifdef CONFIG_MBEDTLS_VERSION_FEATURES -#define MBEDTLS_VERSION_FEATURES -#endif - -/** - * \def MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK - * - * If set, this enables the X.509 API `mbedtls_x509_crt_verify_with_ca_cb()` - * and the SSL API `mbedtls_ssl_conf_ca_cb()` which allow users to configure - * the set of trusted certificates through a callback instead of a linked - * list. - * - * This is useful for example in environments where a large number of trusted - * certificates is present and storing them in a linked list isn't efficient - * enough, or when the set of trusted certificates changes frequently. - * - * See the documentation of `mbedtls_x509_crt_verify_with_ca_cb()` and - * `mbedtls_ssl_conf_ca_cb()` for more information. - * - * Requires: MBEDTLS_X509_CRT_PARSE_C - * - * Uncomment to enable trusted certificate callbacks. - */ - -/* #define MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK */ - -/** - * \def MBEDTLS_X509_REMOVE_INFO - * - * Disable mbedtls_x509_*_info() and related APIs. - * - * Uncomment to omit mbedtls_x509_*_info(), as well as - *mbedtls_debug_print_crt() - * and other functions/constants only used by these functions, thus reducing - * the code footprint by several KB. - */ - -/* #define MBEDTLS_X509_REMOVE_INFO */ - -/** - * \def MBEDTLS_X509_RSASSA_PSS_SUPPORT - * - * Enable parsing and verification of X.509 certificates, CRLs and CSRS - * signed with RSASSA-PSS (aka PKCS#1 v2.1). - * - * Requires: MBEDTLS_PKCS1_V21 - * - * Comment this macro to disallow using RSASSA-PSS in certificates. - */ -#ifdef CONFIG_MBEDTLS_X509_RSASSA_PSS_SUPPORT -#define MBEDTLS_X509_RSASSA_PSS_SUPPORT -#endif - -/** \} name SECTION: Mbed TLS feature support */ - -/** - * \name SECTION: Mbed TLS modules - * - * This section enables or disables entire modules in Mbed TLS - * \{ - */ - -/** - * \def MBEDTLS_AESNI_C - * - * Enable AES-NI support on x86-64 or x86-32. - * - * \note AESNI is only supported with certain compilers and target options: - * - Visual Studio: supported. - * - GCC, x86-64, target not explicitly supporting AESNI: - * requires MBEDTLS_HAVE_ASM. - * - GCC, x86-32, target not explicitly supporting AESNI: - * not supported. - * - GCC, x86-64 or x86-32, target supporting AESNI: supported. - * For this assembly-less implementation, you must currently compile - * `library/aesni.c` and `library/aes.c` with machine options to enable - * SSE2 and AESNI instructions: `gcc -msse2 -maes -mpclmul` or - * `clang -maes -mpclmul`. - * - Non-x86 targets: this option is silently ignored. - * - Other compilers: this option is silently ignored. - * - * \note - * Above, "GCC" includes compatible compilers such as Clang. - * The limitations on target support are likely to be relaxed in the future. - * - * Module: library/aesni.c - * Caller: library/aes.c - * - * Requires: MBEDTLS_HAVE_ASM (on some platforms, see note) - * - * This modules adds support for the AES-NI instructions on x86. - */ -#ifdef CONFIG_MBEDTLS_AESNI_C -#define MBEDTLS_AESNI_C -#endif - -/** - * \def MBEDTLS_AESCE_C - * - * Enable AES cryptographic extension support on Armv8. - * - * Module: library/aesce.c - * Caller: library/aes.c - * - * Requires: MBEDTLS_AES_C - * - * \warning Runtime detection only works on Linux. For non-Linux operating - * system, Armv8-A Cryptographic Extensions must be supported by - * the CPU when this option is enabled. - * - * \note Minimum compiler versions for this feature when targeting aarch64 - * are Clang 4.0; armclang 6.6; GCC 6.0; or MSVC 2019 version - * 16.11.2. Minimum compiler versions for this feature when - * targeting 32-bit Arm or Thumb are Clang 11.0; armclang 6.20; or - * GCC 6.0. - * - * \note \c CFLAGS must be set to a minimum of \c -march=armv8-a+crypto for - * armclang <= 6.9 - * - * This module adds support for the AES Armv8-A Cryptographic Extensions on - * Armv8 systems. - */ -#ifdef CONFIG_MBEDTLS_AESCE_C -#define MBEDTLS_AESCE_C -#endif - -/** - * \def MBEDTLS_AES_C - * - * Enable the AES block cipher. - * - * Module: library/aes.c - * Caller: library/cipher.c - * library/pem.c - * library/ctr_drbg.c - * - * This module enables the following ciphersuites (if other requisites are - * enabled as well): - * MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA - * MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA - * MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA - * MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA - * MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256 - * MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384 - * MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256 - * MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384 - * MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256 - * MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384 - * MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256 - * MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384 - * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 - * MBEDTLS_TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 - * MBEDTLS_TLS_DHE_RSA_WITH_AES_256_GCM_SHA384 - * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384 - * MBEDTLS_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 - * MBEDTLS_TLS_DHE_RSA_WITH_AES_256_CBC_SHA256 - * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA - * MBEDTLS_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA - * MBEDTLS_TLS_DHE_RSA_WITH_AES_256_CBC_SHA - * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 - * MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 - * MBEDTLS_TLS_DHE_RSA_WITH_AES_128_GCM_SHA256 - * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 - * MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 - * MBEDTLS_TLS_DHE_RSA_WITH_AES_128_CBC_SHA256 - * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA - * MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA - * MBEDTLS_TLS_DHE_RSA_WITH_AES_128_CBC_SHA - * MBEDTLS_TLS_DHE_PSK_WITH_AES_256_GCM_SHA384 - * MBEDTLS_TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384 - * MBEDTLS_TLS_DHE_PSK_WITH_AES_256_CBC_SHA384 - * MBEDTLS_TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA - * MBEDTLS_TLS_DHE_PSK_WITH_AES_256_CBC_SHA - * MBEDTLS_TLS_DHE_PSK_WITH_AES_128_GCM_SHA256 - * MBEDTLS_TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256 - * MBEDTLS_TLS_DHE_PSK_WITH_AES_128_CBC_SHA256 - * MBEDTLS_TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA - * MBEDTLS_TLS_DHE_PSK_WITH_AES_128_CBC_SHA - * MBEDTLS_TLS_RSA_WITH_AES_256_GCM_SHA384 - * MBEDTLS_TLS_RSA_WITH_AES_256_CBC_SHA256 - * MBEDTLS_TLS_RSA_WITH_AES_256_CBC_SHA - * MBEDTLS_TLS_RSA_WITH_AES_128_GCM_SHA256 - * MBEDTLS_TLS_RSA_WITH_AES_128_CBC_SHA256 - * MBEDTLS_TLS_RSA_WITH_AES_128_CBC_SHA - * MBEDTLS_TLS_RSA_PSK_WITH_AES_256_GCM_SHA384 - * MBEDTLS_TLS_RSA_PSK_WITH_AES_256_CBC_SHA384 - * MBEDTLS_TLS_RSA_PSK_WITH_AES_256_CBC_SHA - * MBEDTLS_TLS_RSA_PSK_WITH_AES_128_GCM_SHA256 - * MBEDTLS_TLS_RSA_PSK_WITH_AES_128_CBC_SHA256 - * MBEDTLS_TLS_RSA_PSK_WITH_AES_128_CBC_SHA - * MBEDTLS_TLS_PSK_WITH_AES_256_GCM_SHA384 - * MBEDTLS_TLS_PSK_WITH_AES_256_CBC_SHA384 - * MBEDTLS_TLS_PSK_WITH_AES_256_CBC_SHA - * MBEDTLS_TLS_PSK_WITH_AES_128_GCM_SHA256 - * MBEDTLS_TLS_PSK_WITH_AES_128_CBC_SHA256 - * MBEDTLS_TLS_PSK_WITH_AES_128_CBC_SHA - * - * PEM_PARSE uses AES for decrypting encrypted keys. - */ -#ifdef CONFIG_MBEDTLS_AES_C -#define MBEDTLS_AES_C -#endif - -/** - * \def MBEDTLS_ASN1_PARSE_C - * - * Enable the generic ASN1 parser. - * - * Module: library/asn1.c - * Caller: library/x509.c - * library/dhm.c - * library/pkcs12.c - * library/pkcs5.c - * library/pkparse.c - */ -#ifdef CONFIG_MBEDTLS_ASN1_PARSE_C -#define MBEDTLS_ASN1_PARSE_C -#endif - -/** - * \def MBEDTLS_ASN1_WRITE_C - * - * Enable the generic ASN1 writer. - * - * Module: library/asn1write.c - * Caller: library/ecdsa.c - * library/pkwrite.c - * library/x509_create.c - * library/x509write_crt.c - * library/x509write_csr.c - */ -#ifdef CONFIG_MBEDTLS_ASN1_WRITE_C -#define MBEDTLS_ASN1_WRITE_C -#endif - -/** - * \def MBEDTLS_BASE64_C - * - * Enable the Base64 module. - * - * Module: library/base64.c - * Caller: library/pem.c - * - * This module is required for PEM support (required by X.509). - */ -#define MBEDTLS_BASE64_C - -/** - * \def MBEDTLS_BLOCK_CIPHER_NO_DECRYPT - * - * Remove decryption operation for AES, ARIA and Camellia block cipher. - * - * \note This feature is incompatible with insecure block cipher, - * MBEDTLS_DES_C, and cipher modes which always require decryption - * operation, MBEDTLS_CIPHER_MODE_CBC, MBEDTLS_CIPHER_MODE_XTS and - * MBEDTLS_NIST_KW_C. When #MBEDTLS_PSA_CRYPTO_CONFIG is enabled, - * this feature is incompatible with following supported PSA - * equivalence, PSA_WANT_ALG_ECB_NO_PADDING, - * PSA_WANT_ALG_CBC_NO_PADDING, PSA_WANT_ALG_CBC_PKCS7 and - * PSA_WANT_KEY_TYPE_DES. - * - * Module: library/aes.c - * library/aesce.c - * library/aesni.c - * library/aria.c - * library/camellia.c - * library/cipher.c - */ - -/* #define MBEDTLS_BLOCK_CIPHER_NO_DECRYPT */ - -/** - * \def MBEDTLS_BIGNUM_C - * - * Enable the multi-precision integer library. - * - * Module: library/bignum.c - * library/bignum_core.c - * library/bignum_mod.c - * library/bignum_mod_raw.c - * Caller: library/dhm.c - * library/ecp.c - * library/ecdsa.c - * library/rsa.c - * library/rsa_alt_helpers.c - * library/ssl_tls.c - * - * This module is required for RSA, DHM and ECC (ECDH, ECDSA) support. - */ -#define MBEDTLS_BIGNUM_C - -/** - * \def MBEDTLS_BLOWFISH_C - * - * Enable the Blowfish block cipher. - * - * Module: library/blowfish.c - */ -#ifdef CONFIG_MBEDTLS_BLOWFISH_C -#define MBEDTLS_BLOWFISH_C -#endif - -/** - * \def MBEDTLS_CAMELLIA_C - * - * Enable the Camellia block cipher. - * - * Module: library/camellia.c - * Caller: library/cipher.c - * - * This module enables the following ciphersuites (if other requisites are - * enabled as well): - * MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_128_CBC_SHA256 - * MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_256_CBC_SHA384 - * MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_128_CBC_SHA256 - * MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_256_CBC_SHA384 - * MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_128_GCM_SHA256 - * MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_256_GCM_SHA384 - * MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_128_GCM_SHA256 - * MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_256_GCM_SHA384 - * MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_GCM_SHA384 - * MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_256_GCM_SHA384 - * MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_256_GCM_SHA384 - * MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_CBC_SHA384 - * MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_256_CBC_SHA384 - * MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256 - * MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA - * MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_GCM_SHA256 - * MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_128_GCM_SHA256 - * MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_128_GCM_SHA256 - * MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_CBC_SHA256 - * MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 - * MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 - * MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA - * MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_256_GCM_SHA384 - * MBEDTLS_TLS_ECDHE_PSK_WITH_CAMELLIA_256_CBC_SHA384 - * MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_256_CBC_SHA384 - * MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_128_GCM_SHA256 - * MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_128_CBC_SHA256 - * MBEDTLS_TLS_ECDHE_PSK_WITH_CAMELLIA_128_CBC_SHA256 - * MBEDTLS_TLS_RSA_WITH_CAMELLIA_256_GCM_SHA384 - * MBEDTLS_TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256 - * MBEDTLS_TLS_RSA_WITH_CAMELLIA_256_CBC_SHA - * MBEDTLS_TLS_RSA_WITH_CAMELLIA_128_GCM_SHA256 - * MBEDTLS_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256 - * MBEDTLS_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA - * MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_256_GCM_SHA384 - * MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_256_CBC_SHA384 - * MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_128_GCM_SHA256 - * MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_128_CBC_SHA256 - * MBEDTLS_TLS_PSK_WITH_CAMELLIA_256_GCM_SHA384 - * MBEDTLS_TLS_PSK_WITH_CAMELLIA_256_CBC_SHA384 - * MBEDTLS_TLS_PSK_WITH_CAMELLIA_128_GCM_SHA256 - * MBEDTLS_TLS_PSK_WITH_CAMELLIA_128_CBC_SHA256 - */ -#ifdef CONFIG_MBEDTLS_CAMELLIA_C -#define MBEDTLS_CAMELLIA_C -#endif - -/** - * \def MBEDTLS_ARIA_C - * - * Enable the ARIA block cipher. - * - * Module: library/aria.c - * Caller: library/cipher.c - * - * This module enables the following ciphersuites (if other requisites are - * enabled as well): - * - * MBEDTLS_TLS_RSA_WITH_ARIA_128_CBC_SHA256 - * MBEDTLS_TLS_RSA_WITH_ARIA_256_CBC_SHA384 - * MBEDTLS_TLS_DHE_RSA_WITH_ARIA_128_CBC_SHA256 - * MBEDTLS_TLS_DHE_RSA_WITH_ARIA_256_CBC_SHA384 - * MBEDTLS_TLS_ECDHE_ECDSA_WITH_ARIA_128_CBC_SHA256 - * MBEDTLS_TLS_ECDHE_ECDSA_WITH_ARIA_256_CBC_SHA384 - * MBEDTLS_TLS_ECDH_ECDSA_WITH_ARIA_128_CBC_SHA256 - * MBEDTLS_TLS_ECDH_ECDSA_WITH_ARIA_256_CBC_SHA384 - * MBEDTLS_TLS_ECDHE_RSA_WITH_ARIA_128_CBC_SHA256 - * MBEDTLS_TLS_ECDHE_RSA_WITH_ARIA_256_CBC_SHA384 - * MBEDTLS_TLS_ECDH_RSA_WITH_ARIA_128_CBC_SHA256 - * MBEDTLS_TLS_ECDH_RSA_WITH_ARIA_256_CBC_SHA384 - * MBEDTLS_TLS_RSA_WITH_ARIA_128_GCM_SHA256 - * MBEDTLS_TLS_RSA_WITH_ARIA_256_GCM_SHA384 - * MBEDTLS_TLS_DHE_RSA_WITH_ARIA_128_GCM_SHA256 - * MBEDTLS_TLS_DHE_RSA_WITH_ARIA_256_GCM_SHA384 - * MBEDTLS_TLS_ECDHE_ECDSA_WITH_ARIA_128_GCM_SHA256 - * MBEDTLS_TLS_ECDHE_ECDSA_WITH_ARIA_256_GCM_SHA384 - * MBEDTLS_TLS_ECDH_ECDSA_WITH_ARIA_128_GCM_SHA256 - * MBEDTLS_TLS_ECDH_ECDSA_WITH_ARIA_256_GCM_SHA384 - * MBEDTLS_TLS_ECDHE_RSA_WITH_ARIA_128_GCM_SHA256 - * MBEDTLS_TLS_ECDHE_RSA_WITH_ARIA_256_GCM_SHA384 - * MBEDTLS_TLS_ECDH_RSA_WITH_ARIA_128_GCM_SHA256 - * MBEDTLS_TLS_ECDH_RSA_WITH_ARIA_256_GCM_SHA384 - * MBEDTLS_TLS_PSK_WITH_ARIA_128_CBC_SHA256 - * MBEDTLS_TLS_PSK_WITH_ARIA_256_CBC_SHA384 - * MBEDTLS_TLS_DHE_PSK_WITH_ARIA_128_CBC_SHA256 - * MBEDTLS_TLS_DHE_PSK_WITH_ARIA_256_CBC_SHA384 - * MBEDTLS_TLS_RSA_PSK_WITH_ARIA_128_CBC_SHA256 - * MBEDTLS_TLS_RSA_PSK_WITH_ARIA_256_CBC_SHA384 - * MBEDTLS_TLS_PSK_WITH_ARIA_128_GCM_SHA256 - * MBEDTLS_TLS_PSK_WITH_ARIA_256_GCM_SHA384 - * MBEDTLS_TLS_DHE_PSK_WITH_ARIA_128_GCM_SHA256 - * MBEDTLS_TLS_DHE_PSK_WITH_ARIA_256_GCM_SHA384 - * MBEDTLS_TLS_RSA_PSK_WITH_ARIA_128_GCM_SHA256 - * MBEDTLS_TLS_RSA_PSK_WITH_ARIA_256_GCM_SHA384 - * MBEDTLS_TLS_ECDHE_PSK_WITH_ARIA_128_CBC_SHA256 - * MBEDTLS_TLS_ECDHE_PSK_WITH_ARIA_256_CBC_SHA384 - */ -#ifdef CONFIG_MBEDTLS_ARIA_C -#define MBEDTLS_ARIA_C -#endif - -/** - * \def MBEDTLS_CCM_C - * - * Enable the Counter with CBC-MAC (CCM) mode for 128-bit block cipher. - * - * Module: library/ccm.c - * - * Requires: MBEDTLS_CIPHER_C, MBEDTLS_AES_C or MBEDTLS_CAMELLIA_C or - * MBEDTLS_ARIA_C - * - * This module enables the AES-CCM ciphersuites, if other requisites are - * enabled as well. - */ -#ifdef CONFIG_MBEDTLS_CCM_C -#define MBEDTLS_CCM_C -#endif - -/** - * \def MBEDTLS_CHACHA20_C - * - * Enable the ChaCha20 stream cipher. - * - * Module: library/chacha20.c - */ -#ifdef CONFIG_MBEDTLS_CHACHA20_C -#define MBEDTLS_CHACHA20_C -#endif - -/** - * \def MBEDTLS_CHACHAPOLY_C - * - * Enable the ChaCha20-Poly1305 AEAD algorithm. - * - * Module: library/chachapoly.c - * - * This module requires: MBEDTLS_CHACHA20_C, MBEDTLS_POLY1305_C - */ -#ifdef CONFIG_MBEDTLS_CHACHAPOLY_C -#define MBEDTLS_CHACHAPOLY_C -#endif - -/** - * \def MBEDTLS_CIPHER_C - * - * Enable the generic cipher layer. - * - * Module: library/cipher.c - * Caller: library/ccm.c - * library/cmac.c - * library/gcm.c - * library/nist_kw.c - * library/pkcs12.c - * library/pkcs5.c - * library/psa_crypto_aead.c - * library/psa_crypto_mac.c - * library/ssl_ciphersuites.c - * library/ssl_msg.c - * library/ssl_ticket.c (unless MBEDTLS_USE_PSA_CRYPTO is enabled) - * Auto-enabled by: MBEDTLS_PSA_CRYPTO_C depending on which ciphers are - * enabled (see the documentation of that option for - * details). - * - * Uncomment to enable generic cipher wrappers. - */ -#define MBEDTLS_CIPHER_C - -/** - * \def MBEDTLS_CMAC_C - * - * Enable the CMAC (Cipher-based Message Authentication Code) mode for block - * ciphers. - * - * \note When #MBEDTLS_CMAC_ALT is active, meaning that the underlying - * implementation of the CMAC algorithm is provided by an alternate - * implementation, that alternate implementation may opt to not support - * AES-192 or 3DES as underlying block ciphers for the CMAC operation. - * - * Module: library/cmac.c - * - * Requires: MBEDTLS_CIPHER_C, MBEDTLS_AES_C or MBEDTLS_DES_C - * - */ - -#ifdef CONFIG_MBEDTLS_CMAC_C -#define MBEDTLS_CMAC_C -#endif - -/** - * \def MBEDTLS_CTR_DRBG_C - * - * Enable the CTR_DRBG AES-based random generator. - * The CTR_DRBG generator uses AES-256 by default. - * To use AES-128 instead, enable \c MBEDTLS_CTR_DRBG_USE_128_BIT_KEY above. - * - * AES support can either be achieved through builtin (MBEDTLS_AES_C) or PSA. - * Builtin is the default option when MBEDTLS_AES_C is defined otherwise PSA - * is used. - * - * \warning When using PSA, the user should call `psa_crypto_init()` before - * using any CTR_DRBG operation (except `mbedtls_ctr_drbg_init()`). - * - * \note AES-128 will be used if \c MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH is - * set. - * - * \note To achieve a 256-bit security strength with CTR_DRBG, - * you must use AES-256 *and* use sufficient entropy. - * See ctr_drbg.h for more details. - * - * Module: library/ctr_drbg.c - * Caller: - * - * Requires: MBEDTLS_AES_C or - * (PSA_WANT_KEY_TYPE_AES and PSA_WANT_ALG_ECB_NO_PADDING and - * MBEDTLS_PSA_CRYPTO_C) - * - * This module provides the CTR_DRBG AES random number generator. - */ -#define MBEDTLS_CTR_DRBG_C - -/** - * \def MBEDTLS_DEBUG_C - * - * Enable the debug functions. - * - * Module: library/debug.c - * Caller: library/ssl_msg.c - * library/ssl_tls.c - * library/ssl_tls12_*.c - * library/ssl_tls13_*.c - * - * This module provides debugging functions. - */ -#ifdef CONFIG_MBEDTLS_DEBUG_C -#define MBEDTLS_DEBUG_C -#endif - -/** - * \def MBEDTLS_DES_C - * - * Enable the DES block cipher. - * - * Module: library/des.c - * Caller: library/pem.c - * library/cipher.c - * - * PEM_PARSE uses DES/3DES for decrypting encrypted keys. - * - * \warning DES/3DES are considered weak ciphers and their use constitutes - * a security risk. We recommend considering stronger ciphers - *instead. - */ -#define MBEDTLS_DES_C - -/** - * \def MBEDTLS_DHM_C - * - * Enable the Diffie-Hellman-Merkle module. - * - * Module: library/dhm.c - * Caller: library/ssl_tls.c - * library/ssl*_client.c - * library/ssl*_server.c - * - * This module is used by the following key exchanges: - * DHE-RSA, DHE-PSK - * - * \warning Using DHE constitutes a security risk as it - * is not possible to validate custom DH parameters. - * If possible, it is recommended users should consider - * preferring other methods of key exchange. - * See dhm.h for more details. - * - */ -#ifdef CONFIG_MBEDTLS_DHM_C -#define MBEDTLS_DHM_C -#endif - -/** - * \def MBEDTLS_ECDH_C - * - * Enable the elliptic curve Diffie-Hellman library. - * - * Module: library/ecdh.c - * Caller: library/psa_crypto.c - * library/ssl_tls.c - * library/ssl*_client.c - * library/ssl*_server.c - * - * This module is used by the following key exchanges: - * ECDHE-ECDSA, ECDHE-RSA, DHE-PSK - * - * Requires: MBEDTLS_ECP_C - */ -#ifdef CONFIG_MBEDTLS_ECDH_C -#define MBEDTLS_ECDH_C -#endif - -/** - * \def MBEDTLS_ECDSA_C - * - * Enable the elliptic curve DSA library. - * - * Module: library/ecdsa.c - * Caller: - * - * This module is used by the following key exchanges: - * ECDHE-ECDSA - * - * Requires: MBEDTLS_ECP_C, MBEDTLS_ASN1_WRITE_C, MBEDTLS_ASN1_PARSE_C, - * and at least one MBEDTLS_ECP_DP_XXX_ENABLED for a - * short Weierstrass curve. - */ -#ifdef CONFIG_MBEDTLS_ECDSA_C -#define MBEDTLS_ECDSA_C -#endif - -/** - * \def MBEDTLS_ECJPAKE_C - * - * Enable the elliptic curve J-PAKE library. - * - * \note EC J-PAKE support is based on the Thread v1.0.0 specification. - * It has not been reviewed for compliance with newer standards such as - * Thread v1.1 or RFC 8236. - * - * Module: library/ecjpake.c - * Caller: - * - * This module is used by the following key exchanges: - * ECJPAKE - * - * Requires: MBEDTLS_ECP_C and either MBEDTLS_MD_C or MBEDTLS_PSA_CRYPTO_C - * - * \warning If using a hash that is only provided by PSA drivers, you must - * call psa_crypto_init() before doing any EC J-PAKE operations. - */ -#ifdef CONFIG_MBEDTLS_ECJPAKE_C -#define MBEDTLS_ECJPAKE_C -#endif - -/** - * \def MBEDTLS_ECP_C - * - * Enable the elliptic curve over GF(p) library. - * - * Module: library/ecp.c - * Caller: library/ecdh.c - * library/ecdsa.c - * library/ecjpake.c - * - * Requires: MBEDTLS_BIGNUM_C and at least one MBEDTLS_ECP_DP_XXX_ENABLED - */ -#ifdef CONFIG_MBEDTLS_ECP_C -#define MBEDTLS_ECP_C -#endif - -/** - * \def MBEDTLS_ENTROPY_C - * - * Enable the platform-specific entropy code. - * - * Module: library/entropy.c - * Caller: - * - * Requires: MBEDTLS_SHA512_C or MBEDTLS_SHA256_C - * - * This module provides a generic entropy pool - */ -#define MBEDTLS_ENTROPY_C - -/** - * \def MBEDTLS_ERROR_C - * - * Enable error code to error string conversion. - * - * Module: library/error.c - * Caller: - * - * This module enables mbedtls_strerror(). - */ -#ifdef CONFIG_MBEDTLS_ERROR_C -#define MBEDTLS_ERROR_C -#endif - -/** - * \def MBEDTLS_GCM_C - * - * Enable the Galois/Counter Mode (GCM). - * - * Module: library/gcm.c - * - * Requires: MBEDTLS_CIPHER_C, MBEDTLS_AES_C or MBEDTLS_CAMELLIA_C or - * MBEDTLS_ARIA_C - * - * This module enables the AES-GCM and CAMELLIA-GCM ciphersuites, if other - * requisites are enabled as well. - */ -#ifdef CONFIG_MBEDTLS_GCM_C -#define MBEDTLS_GCM_C -#endif - -/** - * \def MBEDTLS_GCM_LARGE_TABLE - * - * Enable large pre-computed tables for Galois/Counter Mode (GCM). - * Can significantly increase throughput on systems without GCM hardware - * acceleration (e.g., AESNI, AESCE). - * - * The mbedtls_gcm_context size will increase by 3840 bytes. - * The code size will increase by roughly 344 bytes. - * - * Module: library/gcm.c - * - * Requires: MBEDTLS_GCM_C - */ - -/* #define MBEDTLS_GCM_LARGE_TABLE */ - -/** - * \def MBEDTLS_HKDF_C - * - * Enable the HKDF algorithm (RFC 5869). - * - * Module: library/hkdf.c - * Caller: - * - * Requires: MBEDTLS_MD_C - * - * This module adds support for the Hashed Message Authentication Code - * (HMAC)-based key derivation function (HKDF). - */ -#ifdef CONFIG_MBEDTLS_HKDF_C -#define MBEDTLS_HKDF_C -#endif - -/** - * \def MBEDTLS_HMAC_DRBG_C - * - * Enable the HMAC_DRBG random generator. - * - * Module: library/hmac_drbg.c - * Caller: - * - * Requires: MBEDTLS_MD_C - * - * Uncomment to enable the HMAC_DRBG random number generator. - */ -#ifdef CONFIG_MBEDTLS_HMAC_DRBG_C -#define MBEDTLS_HMAC_DRBG_C -#endif - -/** - * \def MBEDTLS_LMS_C - * - * Enable the LMS stateful-hash asymmetric signature algorithm. - * - * Module: library/lms.c - * Caller: - * - * Requires: MBEDTLS_PSA_CRYPTO_C - * - * Uncomment to enable the LMS verification algorithm and public key - *operations. - */ -#ifdef CONFIG_MBEDTLS_LMS_C -#define MBEDTLS_LMS_C -#endif - -/** - * \def MBEDTLS_LMS_PRIVATE - * - * Enable LMS private-key operations and signing code. Functions enabled by - * this - * option are experimental, and should not be used in production. - * - * Requires: MBEDTLS_LMS_C - * - * Uncomment to enable the LMS signature algorithm and private key - * operations. - */ - -/* #define MBEDTLS_LMS_PRIVATE */ - -/** - * \def MBEDTLS_NIST_KW_C - * - * Enable the Key Wrapping mode for 128-bit block ciphers, - * as defined in NIST SP 800-38F. Only KW and KWP modes - * are supported. At the moment, only AES is approved by NIST. - * - * Module: library/nist_kw.c - * - * Requires: MBEDTLS_AES_C and MBEDTLS_CIPHER_C - */ -#ifdef CONFIG_MBEDTLS_NIST_KW_C -#define MBEDTLS_NIST_KW_C -#endif - -/** - * \def MBEDTLS_MD_C - * - * Enable the generic layer for message digest (hashing) and HMAC. - * - * Requires: one of: MBEDTLS_MD5_C, MBEDTLS_RIPEMD160_C, MBEDTLS_SHA1_C, - * MBEDTLS_SHA224_C, MBEDTLS_SHA256_C, MBEDTLS_SHA384_C, - * MBEDTLS_SHA512_C, or MBEDTLS_PSA_CRYPTO_C with at least - * one hash. - * Module: library/md.c - * Caller: library/constant_time.c - * library/ecdsa.c - * library/ecjpake.c - * library/hkdf.c - * library/hmac_drbg.c - * library/pk.c - * library/pkcs5.c - * library/pkcs12.c - * library/psa_crypto_ecp.c - * library/psa_crypto_rsa.c - * library/rsa.c - * library/ssl_cookie.c - * library/ssl_msg.c - * library/ssl_tls.c - * library/x509.c - * library/x509_crt.c - * library/x509write_crt.c - * library/x509write_csr.c - * - * Uncomment to enable generic message digest wrappers. - */ -#ifdef CONFIG_MBEDTLS_MD_C -#define MBEDTLS_MD_C -#endif - -/** - * \def MBEDTLS_MD5_C - * - * Enable the MD5 hash algorithm. - * - * Module: library/md5.c - * Caller: library/md.c - * library/pem.c - * library/ssl_tls.c - * - * This module is required for TLS 1.2 depending on the handshake parameters. - * Further, it is used for checking MD5-signed certificates, and for PBKDF1 - * when decrypting PEM-encoded encrypted keys. - * - * \warning MD5 is considered a weak message digest and its use constitutes - *a - * security risk. If possible, we recommend avoiding dependencies - *on - * it, and considering stronger message digests instead. - * - */ -#ifdef CONFIG_MBEDTLS_MD5_C -#define MBEDTLS_MD5_C -#endif - -/** - * \def MBEDTLS_MEMORY_BUFFER_ALLOC_C - * - * Enable the buffer allocator implementation that makes use of a (stack) - * based buffer to 'allocate' dynamic memory. (replaces calloc() and free() - * calls) - * - * Module: library/memory_buffer_alloc.c - * - * Requires: MBEDTLS_PLATFORM_C - * MBEDTLS_PLATFORM_MEMORY (to use it within Mbed TLS) - * - * Enable this module to enable the buffer memory allocator. - */ - -/* #define MBEDTLS_MEMORY_BUFFER_ALLOC_C */ - -/** - * \def MBEDTLS_NET_C - * - * Enable the TCP and UDP over IPv6/IPv4 networking routines. - * - * \note This module only works on POSIX/Unix (including Linux, BSD and OS X) - * and Windows. For other platforms, you'll want to disable it, and write - * your own networking callbacks to be passed to \c mbedtls_ssl_set_bio(). - * - * \note See also our Knowledge Base article about porting to a new - * environment: - * https://mbed-tls.readthedocs.io/en/latest/kb/how-to/ - * how-do-i-port-mbed-tls-to-a-new-environment-OS \ - * - * Module: library/net_sockets.c - * - * This module provides networking routines. - */ -#ifdef CONFIG_MBEDTLS_NET_C -#define MBEDTLS_NET_C -#endif - -/** - * \def MBEDTLS_OID_C - * - * Enable the OID database. - * - * Module: library/oid.c - * Caller: library/asn1write.c - * library/pkcs5.c - * library/pkparse.c - * library/pkwrite.c - * library/rsa.c - * library/x509.c - * library/x509_create.c - * library/x509_crl.c - * library/x509_crt.c - * library/x509_csr.c - * library/x509write_crt.c - * library/x509write_csr.c - * - * This modules translates between OIDs and internal values. - */ -#ifdef CONFIG_MBEDTLS_OID_C -#define MBEDTLS_OID_C -#endif - -/** - * \def MBEDTLS_PADLOCK_C - * - * Enable VIA Padlock support on x86. - * - * Module: library/padlock.c - * Caller: library/aes.c - * - * Requires: MBEDTLS_HAVE_ASM - * - * This modules adds support for the VIA PadLock on x86. - */ -#ifdef CONFIG_MBEDTLS_PADLOCK_C -#define MBEDTLS_PADLOCK_C -#endif - -/** - * \def MBEDTLS_PEM_PARSE_C - * - * Enable PEM decoding / parsing. - * - * Module: library/pem.c - * Caller: library/dhm.c - * library/pkparse.c - * library/x509_crl.c - * library/x509_crt.c - * library/x509_csr.c - * - * Requires: MBEDTLS_BASE64_C - * optionally MBEDTLS_MD5_C, or PSA Crypto with MD5 (see below) - * - * \warning When parsing password-protected files, if MD5 is provided only by - * a PSA driver, you must call psa_crypto_init() before the first file. - * - * This modules adds support for decoding / parsing PEM files. - */ -#define MBEDTLS_PEM_PARSE_C - -/** - * \def MBEDTLS_PEM_WRITE_C - * - * Enable PEM encoding / writing. - * - * Module: library/pem.c - * Caller: library/pkwrite.c - * library/x509write_crt.c - * library/x509write_csr.c - * - * Requires: MBEDTLS_BASE64_C - * - * This modules adds support for encoding / writing PEM files. - */ -#ifdef CONFIG_MBEDTLS_PEM_WRITE_C -#define MBEDTLS_PEM_WRITE_C -#endif - -/** - * \def MBEDTLS_PK_C - * - * Enable the generic public (asymmetric) key layer. - * - * Module: library/pk.c - * Caller: library/psa_crypto_rsa.c - * library/ssl_tls.c - * library/ssl*_client.c - * library/ssl*_server.c - * library/x509.c - * - * Requires: MBEDTLS_MD_C, MBEDTLS_RSA_C or MBEDTLS_ECP_C - * - * Uncomment to enable generic public key wrappers. - */ -#ifdef CONFIG_MBEDTLS_PK_C -#define MBEDTLS_PK_C -#endif - -/** - * \def MBEDTLS_PK_PARSE_C - * - * Enable the generic public (asymmetric) key parser. - * - * Module: library/pkparse.c - * Caller: library/x509_crt.c - * library/x509_csr.c - * - * Requires: MBEDTLS_ASN1_PARSE_C, MBEDTLS_OID_C, MBEDTLS_PK_C - * - * Uncomment to enable generic public key parse functions. - */ -#ifdef CONFIG_MBEDTLS_PK_PARSE_C -#define MBEDTLS_PK_PARSE_C -#endif - -/** - * \def MBEDTLS_PK_WRITE_C - * - * Enable the generic public (asymmetric) key writer. - * - * Module: library/pkwrite.c - * Caller: library/x509write.c - * - * Requires: MBEDTLS_ASN1_WRITE_C, MBEDTLS_OID_C, MBEDTLS_PK_C - * - * Uncomment to enable generic public key write functions. - */ -#ifdef CONFIG_MBEDTLS_PK_WRITE_C -#define MBEDTLS_PK_WRITE_C -#endif - -/** - * \def MBEDTLS_PKCS5_C - * - * Enable PKCS#5 functions. - * - * Module: library/pkcs5.c - * - * Auto-enables: MBEDTLS_MD_C - * - * \warning If using a hash that is only provided by PSA drivers, you must - * call psa_crypto_init() before doing any PKCS5 operations. - * - * This module adds support for the PKCS#5 functions. - */ -#ifdef CONFIG_MBEDTLS_PKCS5_C -#define MBEDTLS_PKCS5_C -#endif - -/** - * \def MBEDTLS_PKCS7_C - * - * Enable PKCS #7 core for using PKCS #7-formatted signatures. - * RFC Link - https://tools.ietf.org/html/rfc2315 - * - * Module: library/pkcs7.c - * - * Requires: MBEDTLS_ASN1_PARSE_C, MBEDTLS_OID_C, MBEDTLS_PK_PARSE_C, - * MBEDTLS_X509_CRT_PARSE_C MBEDTLS_X509_CRL_PARSE_C, - * MBEDTLS_BIGNUM_C, MBEDTLS_MD_C - * - * This module is required for the PKCS #7 parsing modules. - */ -#ifdef CONFIG_MBEDTLS_PKCS7_C -#define MBEDTLS_PKCS7_C -#endif - -/** - * \def MBEDTLS_PKCS12_C - * - * Enable PKCS#12 PBE functions. - * Adds algorithms for parsing PKCS#8 encrypted private keys - * - * Module: library/pkcs12.c - * Caller: library/pkparse.c - * - * Requires: MBEDTLS_ASN1_PARSE_C and either MBEDTLS_MD_C or - * MBEDTLS_PSA_CRYPTO_C. - * - * \warning If using a hash that is only provided by PSA drivers, you must - * call psa_crypto_init() before doing any PKCS12 operations. - * - * This module enables PKCS#12 functions. - */ -#ifdef CONFIG_MBEDTLS_PKCS12_C -#define MBEDTLS_PKCS12_C -#endif - -/** - * \def MBEDTLS_PLATFORM_C - * - * Enable the platform abstraction layer that allows you to re-assign - * functions like calloc(), free(), snprintf(), printf(), fprintf(), exit(). - * - * Enabling MBEDTLS_PLATFORM_C enables to use of MBEDTLS_PLATFORM_XXX_ALT - * or MBEDTLS_PLATFORM_XXX_MACRO directives, allowing the functions mentioned - * above to be specified at runtime or compile time respectively. - * - * \note This abstraction layer must be enabled on Windows (including MSYS2) - * as other modules rely on it for a fixed snprintf implementation. - * - * Module: library/platform.c - * Caller: Most other .c files - * - * This module enables abstraction of common (libc) functions. - */ -#ifdef CONFIG_MBEDTLS_PLATFORM_C -#define MBEDTLS_PLATFORM_C -#endif - -/** - * \def MBEDTLS_POLY1305_C - * - * Enable the Poly1305 MAC algorithm. - * - * Module: library/poly1305.c - * Caller: library/chachapoly.c - */ -#ifdef CONFIG_MBEDTLS_POLY1305_C -#define MBEDTLS_POLY1305_C -#endif - -/** - * \def MBEDTLS_PSA_CRYPTO_C - * - * Enable the Platform Security Architecture cryptography API. - * - * Module: library/psa_crypto.c - * - * Requires: either MBEDTLS_CTR_DRBG_C and MBEDTLS_ENTROPY_C, - * or MBEDTLS_HMAC_DRBG_C and MBEDTLS_ENTROPY_C, - * or MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG. - * Auto-enables: MBEDTLS_CIPHER_C if any unauthenticated (ie, non-AEAD) - * cipher is enabled in PSA (unless it's fully accelerated, see - * docs/driver-only-builds.md about that). - */ -#ifdef CONFIG_MBEDTLS_PSA_CRYPTO_C -#define MBEDTLS_PSA_CRYPTO_C -#endif - -/** - * \def MBEDTLS_PSA_CRYPTO_SE_C - * - * Enable dynamic secure element support in the Platform Security - * Architecture cryptography API. - * - * \deprecated This feature is deprecated. Please switch to the PSA driver - * interface. - * - * \warning This feature is not thread-safe, and should not be used in a - * multi-threaded environment. - * - * Module: library/psa_crypto_se.c - * - * Requires: MBEDTLS_PSA_CRYPTO_C, MBEDTLS_PSA_CRYPTO_STORAGE_C - * - */ - -/* #define MBEDTLS_PSA_CRYPTO_SE_C */ - -/** - * \def MBEDTLS_PSA_CRYPTO_STORAGE_C - * - * Enable the Platform Security Architecture persistent key storage. - * - * Module: library/psa_crypto_storage.c - * - * Requires: MBEDTLS_PSA_CRYPTO_C, - * either MBEDTLS_PSA_ITS_FILE_C or a native implementation of - * the PSA ITS interface - */ -#ifdef CONFIG_MBEDTLS_PSA_CRYPTO_STORAGE_C -#define MBEDTLS_PSA_CRYPTO_STORAGE_C -#endif - -/** - * \def MBEDTLS_PSA_ITS_FILE_C - * - * Enable the emulation of the Platform Security Architecture - * Internal Trusted Storage (PSA ITS) over files. - * - * Module: library/psa_its_file.c - * - * Requires: MBEDTLS_FS_IO - */ -#ifdef CONFIG_MBEDTLS_PSA_ITS_FILE_C -#define MBEDTLS_PSA_ITS_FILE_C -#endif - -/** - * \def MBEDTLS_RIPEMD160_C - * - * Enable the RIPEMD-160 hash algorithm. - * - * Module: library/ripemd160.c - * Caller: library/md.c - * - */ -#ifdef CONFIG_MBEDTLS_RIPEMD160_C -#define MBEDTLS_RIPEMD160_C -#endif - -/** - * \def MBEDTLS_RSA_C - * - * Enable the RSA public-key cryptosystem. - * - * Module: library/rsa.c - * library/rsa_alt_helpers.c - * Caller: library/pk.c - * library/psa_crypto.c - * library/ssl_tls.c - * library/ssl*_client.c - * library/ssl*_server.c - * - * This module is used by the following key exchanges: - * RSA, DHE-RSA, ECDHE-RSA, RSA-PSK - * - * Requires: MBEDTLS_BIGNUM_C, MBEDTLS_OID_C - */ -#ifdef CONFIG_MBEDTLS_RSA_C -#define MBEDTLS_RSA_C -#endif - -/** - * \def MBEDTLS_SHA1_C - * - * Enable the SHA1 cryptographic hash algorithm. - * - * Module: library/sha1.c - * Caller: library/md.c - * library/psa_crypto_hash.c - * - * This module is required for TLS 1.2 depending on the handshake parameters, - * and for SHA1-signed certificates. - * - * \warning SHA-1 is considered a weak message digest and its use - * constitutes a security risk. If possible, we recommend - * avoiding dependencies on it, and considering stronger - * message digests instead. - */ -#ifdef CONFIG_MBEDTLS_SHA1_C -#define MBEDTLS_SHA1_C -#endif - -/** - * \def MBEDTLS_SHA224_C - * - * Enable the SHA-224 cryptographic hash algorithm. - * - * Module: library/sha256.c - * Caller: library/md.c - * library/ssl_cookie.c - * - * This module adds support for SHA-224. - */ -#ifdef CONFIG_MBEDTLS_SHA224_C -#define MBEDTLS_SHA224_C -#endif - -/** - * \def MBEDTLS_SHA256_C - * - * Enable the SHA-256 cryptographic hash algorithm. - * - * Module: library/sha256.c - * Caller: library/entropy.c - * library/md.c - * library/ssl_tls.c - * library/ssl*_client.c - * library/ssl*_server.c - * - * This module adds support for SHA-256. - * This module is required for the SSL/TLS 1.2 PRF function. - */ -#ifdef CONFIG_MBEDTLS_SHA256_C -#define MBEDTLS_SHA256_C -#endif - -/** - * \def MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT - * - * Enable acceleration of the SHA-256 and SHA-224 cryptographic hash - * algorithms with the ARMv8 cryptographic extensions if they are available - * at runtime. If not, the library will fall back to the C implementation. - * - * \note If MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT is defined when - * building for a non-Armv8-A build it will be silently ignored. - * - * \note Minimum compiler versions for this feature are Clang 4.0, - * armclang 6.6 or GCC 6.0. - * - * \note \c CFLAGS must be set to a minimum of \c -march=armv8-a+crypto for - * armclang <= 6.9 - * - * \note This was previously known as - * MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT. That name is deprecated, but may - * still be used as an alternative form for this option. - * - * \warning MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT cannot be defined at - * the same time as MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY. - * - * Requires: MBEDTLS_SHA256_C. - * - * Module: library/sha256.c - * - * Uncomment to have the library check for the Armv8-A SHA-256 crypto - * extensions and use them if available. - */ - -/* #define MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT */ - -/** - * \def MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT - * - * \deprecated This is now known as - * MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT. This name is now deprecated, - * but may still be used as an alternative form for this option. - */ - -/* #define MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT */ - -/** - * \def MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY - * - * Enable acceleration of the SHA-256 and SHA-224 cryptographic hash - * algorithms with the ARMv8 cryptographic extensions, which must be - * available at runtime or else an illegal instruction fault will occur. - * - * \note This allows builds with a smaller code size than with - * MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT - * - * \note Minimum compiler versions for this feature are Clang 4.0, - * armclang 6.6 or GCC 6.0. - * - * \note \c CFLAGS must be set to a minimum of \c -march=armv8-a+crypto for - * armclang <= 6.9 - * - * \note This was previously known as MBEDTLS_SHA256_USE_A64_CRYPTO_ONLY. - * That name is deprecated, but may still be used as an alternative form for - * this option. - * - * \warning MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY cannot be defined at the - * same time as MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT. - * - * Requires: MBEDTLS_SHA256_C. - * - * Module: library/sha256.c - * - * Uncomment to have the library use the Armv8-A SHA-256 crypto extensions - * unconditionally. - */ - -/* #define MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY */ - -/** - * \def MBEDTLS_SHA256_USE_A64_CRYPTO_ONLY - * - * \deprecated This is now known as MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY. - * This name is now deprecated, but may still be used as an alternative form - * for this option. - */ - -/* #define MBEDTLS_SHA256_USE_A64_CRYPTO_ONLY */ - -/** - * \def MBEDTLS_SHA384_C - * - * Enable the SHA-384 cryptographic hash algorithm. - * - * Module: library/sha512.c - * Caller: library/md.c - * library/psa_crypto_hash.c - * library/ssl_tls.c - * library/ssl*_client.c - * library/ssl*_server.c - * - * Comment to disable SHA-384 - */ -#ifdef CONFIG_MBEDTLS_SHA384_C -#define MBEDTLS_SHA384_C -#endif - -/** - * \def MBEDTLS_SHA512_C - * - * Enable SHA-512 cryptographic hash algorithms. - * - * Module: library/sha512.c - * Caller: library/entropy.c - * library/md.c - * library/ssl_tls.c - * library/ssl_cookie.c - * - * This module adds support for SHA-512. - */ -#ifdef CONFIG_MBEDTLS_SHA512_C -#define MBEDTLS_SHA512_C -#endif - -/** - * \def MBEDTLS_SHA3_C - * - * Enable the SHA3 cryptographic hash algorithm. - * - * Module: library/sha3.c - * - * This module adds support for SHA3. - */ -#ifdef CONFIG_MBEDTLS_SHA3_C -#define MBEDTLS_SHA3_C -#endif - -/** - * \def MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT - * - * Enable acceleration of the SHA-512 and SHA-384 cryptographic hash - * algorithms with the ARMv8 cryptographic extensions if they are available - * at runtime. If not, the library will fall back to the C implementation. - * - * \note If MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT is defined when building - * for a non-Aarch64 build it will be silently ignored. - * - * \note Minimum compiler versions for this feature are Clang 7.0, - * armclang 6.9 or GCC 8.0. - * - * \note \c CFLAGS must be set to a minimum of \c -march=armv8.2-a+sha3 for - * armclang 6.9 - * - * \warning MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT cannot be defined at the - * same time as MBEDTLS_SHA512_USE_A64_CRYPTO_ONLY. - * - * Requires: MBEDTLS_SHA512_C. - * - * Module: library/sha512.c - * - * Uncomment to have the library check for the A64 SHA-512 crypto extensions - * and use them if available. - */ - -/* #define MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT */ - -/** - * \def MBEDTLS_SHA512_USE_A64_CRYPTO_ONLY - * - * Enable acceleration of the SHA-512 and SHA-384 cryptographic hash - * algorithms with the ARMv8 cryptographic extensions, which must be - * available at runtime or else an illegal instruction fault will occur. - * - * \note This allows builds with a smaller code size than with - * MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT - * - * \note Minimum compiler versions for this feature are Clang 7.0, - * armclang 6.9 or GCC 8.0. - * - * \note \c CFLAGS must be set to a minimum of \c -march=armv8.2-a+sha3 for - * armclang 6.9 - * - * \warning MBEDTLS_SHA512_USE_A64_CRYPTO_ONLY cannot be defined at the same - * time as MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT. - * - * Requires: MBEDTLS_SHA512_C. - * - * Module: library/sha512.c - * - * Uncomment to have the library use the A64 SHA-512 crypto extensions - * unconditionally. - */ - -/* #define MBEDTLS_SHA512_USE_A64_CRYPTO_ONLY */ - -/** - * \def MBEDTLS_SSL_CACHE_C - * - * Enable simple SSL cache implementation. - * - * Module: library/ssl_cache.c - * Caller: - * - * Requires: MBEDTLS_SSL_CACHE_C - */ -#ifdef CONFIG_MBEDTLS_SSL_CACHE_C -#define MBEDTLS_SSL_CACHE_C -#endif - -/** - * \def MBEDTLS_SSL_COOKIE_C - * - * Enable basic implementation of DTLS cookies for hello verification. - * - * Module: library/ssl_cookie.c - * Caller: - */ -#ifdef CONFIG_MBEDTLS_SSL_COOKIE_C -#define MBEDTLS_SSL_COOKIE_C -#endif - -/** - * \def MBEDTLS_SSL_TICKET_C - * - * Enable an implementation of TLS server-side callbacks for session tickets. - * - * Module: library/ssl_ticket.c - * Caller: - * - * Requires: (MBEDTLS_CIPHER_C || MBEDTLS_USE_PSA_CRYPTO) && - * (MBEDTLS_GCM_C || MBEDTLS_CCM_C || MBEDTLS_CHACHAPOLY_C) - */ -#ifdef CONFIG_MBEDTLS_SSL_TICKET_C -#define MBEDTLS_SSL_TICKET_C -#endif - -/** - * \def MBEDTLS_SSL_CLI_C - * - * Enable the SSL/TLS client code. - * - * Module: library/ssl*_client.c - * Caller: - * - * Requires: MBEDTLS_SSL_TLS_C - * - * This module is required for SSL/TLS client support. - */ -#define MBEDTLS_SSL_CLI_C - -/** - * \def MBEDTLS_SSL_SRV_C - * - * Enable the SSL/TLS server code. - * - * Module: library/ssl*_server.c - * Caller: - * - * Requires: MBEDTLS_SSL_TLS_C - * - * This module is required for SSL/TLS server support. - */ -#ifdef CONFIG_MBEDTLS_SSL_SRV_C -#define MBEDTLS_SSL_SRV_C -#endif - -/** - * \def MBEDTLS_SSL_TLS_C - * - * Enable the generic SSL/TLS code. - * - * Module: library/ssl_tls.c - * Caller: library/ssl*_client.c - * library/ssl*_server.c - * - * Requires: MBEDTLS_CIPHER_C, MBEDTLS_MD_C - * and at least one of the MBEDTLS_SSL_PROTO_XXX defines - * - * This module is required for SSL/TLS. - */ -#define MBEDTLS_SSL_TLS_C - -/** - * \def MBEDTLS_THREADING_C - * - * Enable the threading abstraction layer. - * By default Mbed TLS assumes it is used in a non-threaded environment or - * that contexts are not shared between threads. If you do intend to use - * contexts between threads, you will need to enable this layer to prevent - * race conditions. See also our Knowledge Base article about threading: - * https://mbed-tls.readthedocs.io/en/latest/kb/development/ \ - * thread-safety-and-multi-threading - * - * Module: library/threading.c - * - * This allows different threading implementations (self-implemented or - * provided). - * - * You will have to enable either MBEDTLS_THREADING_ALT or - * MBEDTLS_THREADING_PTHREAD. - * - * Enable this layer to allow use of mutexes within Mbed TLS - */ -#ifdef CONFIG_MBEDTLS_THREADING_C -#define MBEDTLS_THREADING_C -#endif - -/** - * \def MBEDTLS_TIMING_C - * - * Enable the semi-portable timing interface. - * - * \note The provided implementation only works on POSIX/Unix (including - * Linux, - * BSD and OS X) and Windows. On other platforms, you can either disable that - * module and provide your own implementations of the callbacks needed by - * \c mbedtls_ssl_set_timer_cb() for DTLS, or leave it enabled and provide - * your own implementation of the whole module by setting - * \c MBEDTLS_TIMING_ALT in the current file. - * - * \note The timing module will include time.h on suitable platforms - * regardless of the setting of MBEDTLS_HAVE_TIME, unless - * MBEDTLS_TIMING_ALT is used. See timing.c for more information. - * - * \note See also our Knowledge Base article about porting to a new - * environment: - * https://mbed-tls.readthedocs.io/en/latest/kb/how-to/ \ - * how-do-i-port-mbed-tls-to-a-new-environment-OS - * - * Module: library/timing.c - */ -#ifdef CONFIG_MBEDTLS_TIMING_C -#define MBEDTLS_TIMING_C -#endif - -/** - * \def MBEDTLS_VERSION_C - * - * Enable run-time version information. - * - * Module: library/version.c - * - * This module provides run-time version information. - */ -#ifdef CONFIG_MBEDTLS_VERSION_C -#define MBEDTLS_VERSION_C -#endif - -/** - * \def MBEDTLS_X509_USE_C - * - * Enable X.509 core for using certificates. - * - * Module: library/x509.c - * Caller: library/x509_crl.c - * library/x509_crt.c - * library/x509_csr.c - * - * Requires: MBEDTLS_ASN1_PARSE_C, MBEDTLS_BIGNUM_C, MBEDTLS_OID_C, - * MBEDTLS_PK_PARSE_C, (MBEDTLS_MD_C or MBEDTLS_USE_PSA_CRYPTO) - * - * \warning If building with MBEDTLS_USE_PSA_CRYPTO, you must call - * psa_crypto_init() before doing any X.509 operation. - * - * This module is required for the X.509 parsing modules. - */ -#ifdef CONFIG_MBEDTLS_X509_USE_C -#define MBEDTLS_X509_USE_C -#endif - -/** - * \def MBEDTLS_X509_CRT_PARSE_C - * - * Enable X.509 certificate parsing. - * - * Module: library/x509_crt.c - * Caller: library/ssl_tls.c - * library/ssl*_client.c - * library/ssl*_server.c - * - * Requires: MBEDTLS_X509_USE_C - * - * This module is required for X.509 certificate parsing. - */ -#ifdef CONFIG_MBEDTLS_X509_CRT_PARSE_C -#define MBEDTLS_X509_CRT_PARSE_C -#endif - -/** - * \def MBEDTLS_X509_CRL_PARSE_C - * - * Enable X.509 CRL parsing. - * - * Module: library/x509_crl.c - * Caller: library/x509_crt.c - * - * Requires: MBEDTLS_X509_USE_C - * - * This module is required for X.509 CRL parsing. - */ -#ifdef CONFIG_MBEDTLS_X509_CRL_PARSE_C -#define MBEDTLS_X509_CRL_PARSE_C -#endif - -/** - * \def MBEDTLS_X509_CSR_PARSE_C - * - * Enable X.509 Certificate Signing Request (CSR) parsing. - * - * Module: library/x509_csr.c - * Caller: library/x509_crt_write.c - * - * Requires: MBEDTLS_X509_USE_C - * - * This module is used for reading X.509 certificate request. - */ -#ifdef CONFIG_MBEDTLS_X509_CSR_PARSE_C -#define MBEDTLS_X509_CSR_PARSE_C -#endif - -/** - * \def MBEDTLS_X509_CREATE_C - * - * Enable X.509 core for creating certificates. - * - * Module: library/x509_create.c - * - * Requires: MBEDTLS_BIGNUM_C, MBEDTLS_OID_C, MBEDTLS_PK_PARSE_C, - * (MBEDTLS_MD_C or MBEDTLS_USE_PSA_CRYPTO) - * - * \warning If building with MBEDTLS_USE_PSA_CRYPTO, you must call - * psa_crypto_init() before doing any X.509 create operation. - * - * This module is the basis for creating X.509 certificates and CSRs. - */ -#ifdef CONFIG_MBEDTLS_X509_CREATE_C -#define MBEDTLS_X509_CREATE_C -#endif - -/** - * \def MBEDTLS_X509_CRT_WRITE_C - * - * Enable creating X.509 certificates. - * - * Module: library/x509_crt_write.c - * - * Requires: MBEDTLS_X509_CREATE_C - * - * This module is required for X.509 certificate creation. - */ -#ifdef CONFIG_MBEDTLS_X509_CRT_WRITE_C -#define MBEDTLS_X509_CRT_WRITE_C -#endif - -/** - * \def MBEDTLS_X509_CSR_WRITE_C - * - * Enable creating X.509 Certificate Signing Requests (CSR). - * - * Module: library/x509_csr_write.c - * - * Requires: MBEDTLS_X509_CREATE_C - * - * This module is required for X.509 certificate request writing. - */ -#ifdef CONFIG_MBEDTLS_X509_CSR_WRITE_C -#define MBEDTLS_X509_CSR_WRITE_C -#endif - -/** - * \def MBEDTLS_XTEA_C - * - * Enable the XTEA block cipher. - * - * Module: library/xtea.c - * Caller: - */ -#ifdef CONFIG_MBEDTLS_XTEA_C -#define MBEDTLS_XTEA_C -#endif - -/** \} name SECTION: Mbed TLS modules */ - -/** - * \name SECTION: General configuration options - * - * This section contains Mbed TLS build settings that are not associated - * with a particular module. - * - * \{ - */ - -/** - * \def MBEDTLS_CONFIG_FILE - * - * If defined, this is a header which will be included instead of - * `"mbedtls/mbedtls_config.h"`. - * This header file specifies the compile-time configuration of Mbed TLS. - * Unlike other configuration options, this one must be defined on the - * compiler command line: a definition in `mbedtls_config.h` would have - * no effect. - * - * This macro is expanded after an <tt>\#include</tt> directive. This is a - * popular but - * non-standard feature of the C language, so this feature is only available - * with compilers that perform macro expansion on an <tt>\#include</tt> line. - * - * The value of this symbol is typically a path in double quotes, either - * absolute or relative to a directory on the include search path. - */ - -/* #define MBEDTLS_CONFIG_FILE "mbedtls/mbedtls_config.h" */ - -/** - * \def MBEDTLS_USER_CONFIG_FILE - * - * If defined, this is a header which will be included after - * `"mbedtls/mbedtls_config.h"` or #MBEDTLS_CONFIG_FILE. - * This allows you to modify the default configuration, including the ability - * to undefine options that are enabled by default. - * - * This macro is expanded after an <tt>\#include</tt> directive. This is a - * popular but - * non-standard feature of the C language, so this feature is only available - * with compilers that perform macro expansion on an <tt>\#include</tt> line. - * - * The value of this symbol is typically a path in double quotes, either - * absolute or relative to a directory on the include search path. - */ - -/* #define MBEDTLS_USER_CONFIG_FILE "/dev/null" */ - -/** - * \def MBEDTLS_PSA_CRYPTO_CONFIG_FILE - * - * If defined, this is a header which will be included instead of - * `"psa/crypto_config.h"`. - * This header file specifies which cryptographic mechanisms are available - * through the PSA API when #MBEDTLS_PSA_CRYPTO_CONFIG is enabled, and - * is not used when #MBEDTLS_PSA_CRYPTO_CONFIG is disabled. - * - * This macro is expanded after an <tt>\#include</tt> directive. This is a - * popular but - * non-standard feature of the C language, so this feature is only available - * with compilers that perform macro expansion on an <tt>\#include</tt> line. - * - * The value of this symbol is typically a path in double quotes, either - * absolute or relative to a directory on the include search path. - */ - -/* #define MBEDTLS_PSA_CRYPTO_CONFIG_FILE "psa/crypto_config.h" */ - -/** - * \def MBEDTLS_PSA_CRYPTO_USER_CONFIG_FILE - * - * If defined, this is a header which will be included after - * `"psa/crypto_config.h"` or #MBEDTLS_PSA_CRYPTO_CONFIG_FILE. - * This allows you to modify the default configuration, including the ability - * to undefine options that are enabled by default. - * - * This macro is expanded after an <tt>\#include</tt> directive. This is a - * popular but - * non-standard feature of the C language, so this feature is only available - * with compilers that perform macro expansion on an <tt>\#include</tt> line. - * - * The value of this symbol is typically a path in double quotes, either - * absolute or relative to a directory on the include search path. - */ - -/* #define MBEDTLS_PSA_CRYPTO_USER_CONFIG_FILE "/dev/null" */ - -/** - * \def MBEDTLS_PSA_CRYPTO_PLATFORM_FILE - * - * If defined, this is a header which will be included instead of - * `"psa/crypto_platform.h"`. This file should declare the same identifiers - * as the one in Mbed TLS, but with definitions adapted to the platform on - * which the library code will run. - * - * \note The required content of this header can vary from one version of - * Mbed TLS to the next. Integrators who provide an alternative file - * should review the changes in the original file whenever they - * upgrade Mbed TLS. - * - * This macro is expanded after an <tt>\#include</tt> directive. This is a - * popular but - * non-standard feature of the C language, so this feature is only available - * with compilers that perform macro expansion on an <tt>\#include</tt> line. - * - * The value of this symbol is typically a path in double quotes, either - * absolute or relative to a directory on the include search path. - */ - -/* #define MBEDTLS_PSA_CRYPTO_PLATFORM_FILE "psa/crypto_platform_alt.h" */ - -/** - * \def MBEDTLS_PSA_CRYPTO_STRUCT_FILE - * - * If defined, this is a header which will be included instead of - * `"psa/crypto_struct.h"`. This file should declare the same identifiers - * as the one in Mbed TLS, but with definitions adapted to the environment - * in which the library code will run. The typical use for this feature - * is to provide alternative type definitions on the client side in - * client-server integrations of PSA crypto, where operation structures - * contain handles instead of cryptographic data. - * - * \note The required content of this header can vary from one version of - * Mbed TLS to the next. Integrators who provide an alternative file - * should review the changes in the original file whenever they - * upgrade Mbed TLS. - * - * This macro is expanded after an <tt>\#include</tt> directive. This is a - * popular but - * non-standard feature of the C language, so this feature is only available - * with compilers that perform macro expansion on an <tt>\#include</tt> line. - * - * The value of this symbol is typically a path in double quotes, either - * absolute or relative to a directory on the include search path. - */ - -/* #define MBEDTLS_PSA_CRYPTO_STRUCT_FILE "psa/crypto_struct_alt.h" */ - -/** \} name SECTION: General configuration options */ - -/** - * \name SECTION: Module configuration options - * - * This section allows for the setting of module specific sizes and - * configuration options. The default values are already present in the - * relevant header files and should suffice for the regular use cases. - * - * Our advice is to enable options and change their values here - * only if you have a good reason and know the consequences. - * \{ - */ - -/* The Doxygen documentation here is used when a user comments out a - * setting and runs doxygen themselves. On the other hand, when we typeset - * the full documentation including disabled settings, the documentation - * in specific modules' header files is used if present. When editing this - * file, make sure that each option is documented in exactly one place, - * plus optionally a same-line Doxygen comment here if there is a Doxygen - * comment in the specific module. - */ - -/* MPI / BIGNUM options */ - -/* #define MBEDTLS_MPI_WINDOW_SIZE 2 */ - -/* Maximum window size used. */ - -/* #define MBEDTLS_MPI_MAX_SIZE 1024 */ - -/* Maximum number of bytes for usable MPIs. */ - -/* CTR_DRBG options */ - -/* #define MBEDTLS_CTR_DRBG_ENTROPY_LEN 48 */ - -/* Amount of entropy used per seed by default - *(48 with SHA-512, 32 with SHA-256) - */ - -/* #define MBEDTLS_CTR_DRBG_RESEED_INTERVAL 10000 */ - -/* Interval before reseed is performed by default */ - -/* #define MBEDTLS_CTR_DRBG_MAX_INPUT 256 */ - -/* Maximum number of additional input bytes */ - -/* #define MBEDTLS_CTR_DRBG_MAX_REQUEST 1024 */ - -/* Maximum number of requested bytes per call */ - -/* #define MBEDTLS_CTR_DRBG_MAX_SEED_INPUT 384 */ - -/* Maximum size of (re)seed buffer */ - -/* HMAC_DRBG options */ - -/* #define MBEDTLS_HMAC_DRBG_RESEED_INTERVAL 10000 */ - -/* Interval before reseed is performed by default */ - -/* #define MBEDTLS_HMAC_DRBG_MAX_INPUT 256 */ - -/* Maximum number of additional input bytes */ - -/* #define MBEDTLS_HMAC_DRBG_MAX_REQUEST 1024 */ - -/* Maximum number of requested bytes per call */ - -/* #define MBEDTLS_HMAC_DRBG_MAX_SEED_INPUT 384 */ - -/* Maximum size of (re)seed buffer */ - -/* ECP options */ - -/* #define MBEDTLS_ECP_MAX_BITS 521 */ - -/* Maximum bit size of groups */ - -#ifdef CONFIG_MBEDTLS_ECP_WINDOW_SIZE -#define MBEDTLS_ECP_WINDOW_SIZE CONFIG_MBEDTLS_ECP_WINDOW_SIZE -/* <Maximum window size used */ -#endif -#ifndef CONFIG_MBEDTLS_ECP_FIXED_POINT_OPTIM -#define MBEDTLS_ECP_FIXED_POINT_OPTIM 0 -/* Disable fixed-point speed-up */ -#endif - -/* Entropy options */ - -/* #define MBEDTLS_ENTROPY_MAX_SOURCES 20 */ - -/* Maximum number of sources supported */ - -/* #define MBEDTLS_ENTROPY_MAX_GATHER 128 */ - -/* Maximum amount requested from entropy sources */ - -/* #define MBEDTLS_ENTROPY_MIN_HARDWARE 32 */ - -/* Default minimum number of bytes required for the hardware - * entropy source mbedtls_hardware_poll() before entropy is released - */ - -/* Memory buffer allocator options */ - -/* #define MBEDTLS_MEMORY_ALIGN_MULTIPLE 4 */ - -/* < Align on multiples of this value */ - -/* Platform options */ - -/* #define MBEDTLS_PLATFORM_STD_MEM_HDR <stdlib.h> */ - -/* Header to include if MBEDTLS_PLATFORM_NO_STD_FUNCTIONS is defined. - * Don't define if no header is needed. - */ - -/** \def MBEDTLS_PLATFORM_STD_CALLOC - * - * Default allocator to use, can be undefined. - * It must initialize the allocated buffer memory to zeroes. - * The size of the buffer is the product of the two parameters. - * The calloc function returns either a null pointer or a pointer to the - * allocated space. If the product is 0, the function may either return NULL - * or a valid pointer to an array of size 0 which is a valid input to the - * deallocation function. An uninitialized #MBEDTLS_PLATFORM_STD_CALLOC - * always fails, returning a null pointer. See the description of - * #MBEDTLS_PLATFORM_MEMORY for more details. The corresponding deallocation - * function is #MBEDTLS_PLATFORM_STD_FREE. - */ - -/* #define MBEDTLS_PLATFORM_STD_CALLOC calloc */ - -/** \def MBEDTLS_PLATFORM_STD_FREE - * - * Default free to use, can be undefined. - * NULL is a valid parameter, and the function must do nothing. - * A non-null parameter will always be a pointer previously returned by - * #MBEDTLS_PLATFORM_STD_CALLOC and not yet freed. An uninitialized - * #MBEDTLS_PLATFORM_STD_FREE does not do anything. See the description of - * #MBEDTLS_PLATFORM_MEMORY for more details (same principles as for - * MBEDTLS_PLATFORM_STD_CALLOC apply). - */ - -/* #define MBEDTLS_PLATFORM_STD_FREE free */ - -/* Default free to use, can be undefined */ - -/* #define MBEDTLS_PLATFORM_STD_SETBUF setbuf */ - -/* Default setbuf to use, can be undefined */ - -/* #define MBEDTLS_PLATFORM_STD_EXIT exit */ - -/* Default exit to use, can be undefined */ - -/* #define MBEDTLS_PLATFORM_STD_TIME time */ - -/* Default time to use, can be undefined. MBEDTLS_HAVE_TIME must be enabled */ - -/* #define MBEDTLS_PLATFORM_STD_FPRINTF fprintf */ - -/* Default fprintf to use, can be undefined */ - -/* #define MBEDTLS_PLATFORM_STD_PRINTF printf */ - -/* Default printf to use, can be undefined */ - -/* Note: your snprintf must correctly zero-terminate the buffer! */ - -/* #define MBEDTLS_PLATFORM_STD_SNPRINTF snprintf */ - -/* Default snprintf to use, can be undefined */ - -/* #define MBEDTLS_PLATFORM_STD_EXIT_SUCCESS 0 */ - -/* Default exit value to use, can be undefined */ - -/* #define MBEDTLS_PLATFORM_STD_EXIT_FAILURE 1 */ - -/* Default exit value to use, can be undefined */ - -/* #define MBEDTLS_PLATFORM_STD_NV_SEED_READ - * mbedtls_platform_std_nv_seed_read - */ - -/* Default nv_seed_read function to use, can be undefined */ - -/* #define MBEDTLS_PLATFORM_STD_NV_SEED_WRITE - * mbedtls_platform_std_nv_seed_write - */ - -/* Default nv_seed_write function to use, can be undefined */ - -/* #define MBEDTLS_PLATFORM_STD_NV_SEED_FILE "seedfile" */ - -/* Seed file to read/write with default implementation */ - -/* To use the following function macros, MBEDTLS_PLATFORM_C must be enabled */ - -/* MBEDTLS_PLATFORM_XXX_MACRO and MBEDTLS_PLATFORM_XXX_ALT cannot both be - * defined - */ - -/* #define MBEDTLS_PLATFORM_CALLOC_MACRO calloc */ - -/* Default allocator macro to use, can be undefined. - * See MBEDTLS_PLATFORM_STD_CALLOC for requirements. - */ - -/* #define MBEDTLS_PLATFORM_FREE_MACRO free */ - -/* Default free macro to use, can be undefined. - * See MBEDTLS_PLATFORM_STD_FREE for requirements. - */ - -/* #define MBEDTLS_PLATFORM_EXIT_MACRO exit */ - -/* Default exit macro to use, can be undefined */ - -/* #define MBEDTLS_PLATFORM_SETBUF_MACRO setbuf */ - -/* Default setbuf macro to use, can be undefined */ - -/* #define MBEDTLS_PLATFORM_TIME_MACRO time */ - -/* Default time macro to use, can be undefined. - * MBEDTLS_HAVE_TIME must be enabled - */ - -/* #define MBEDTLS_PLATFORM_TIME_TYPE_MACRO time_t */ - -/* Default time macro to use, can be undefined. - * MBEDTLS_HAVE_TIME must be enabled - */ - -/* #define MBEDTLS_PLATFORM_FPRINTF_MACRO fprintf */ - -/* Default fprintf macro to use, can be undefined */ - -/* #define MBEDTLS_PLATFORM_PRINTF_MACRO printf */ - -/* Default printf macro to use, can be undefined */ - -/* Note: your snprintf must correctly zero-terminate the buffer! */ - -/* #define MBEDTLS_PLATFORM_SNPRINTF_MACRO snprintf */ - -/* Default snprintf macro to use, can be undefined */ - -/* #define MBEDTLS_PLATFORM_VSNPRINTF_MACRO vsnprintf */ - -/* Default vsnprintf macro to use, can be undefined */ - -/* #define MBEDTLS_PLATFORM_NV_SEED_READ_MACRO - * mbedtls_platform_std_nv_seed_read - */ - -/* Default nv_seed_read function to use, can be undefined */ - -/* #define MBEDTLS_PLATFORM_NV_SEED_WRITE_MACRO - * mbedtls_platform_std_nv_seed_write - */ - -/* Default nv_seed_write function to use, can be undefined */ - -/* #define MBEDTLS_PLATFORM_MS_TIME_TYPE_MACRO int64_t */ - -/* Default milliseconds time macro to use, can be undefined. - * MBEDTLS_HAVE_TIME must be enabled. It must be signed, and at least 64 - * bits. If it is changed from the default, MBEDTLS_PRINTF_MS_TIME must be - * updated to match. - */ - -/* #define MBEDTLS_PRINTF_MS_TIME PRId64 */ - -/* Default fmt for printf. That's avoid compiler warning if mbedtls_ms_time_t - * is redefined. - */ - -/** \def MBEDTLS_CHECK_RETURN - * - * This macro is used at the beginning of the declaration of a function - * to indicate that its return value should be checked. It should - * instruct the compiler to emit a warning or an error if the function - * is called without checking its return value. - * - * There is a default implementation for popular compilers in - * platform_util.h. You can override the default implementation by - * defining your own here. - * - * If the implementation here is empty, this will effectively disable the - * checking of functions' return values. - */ - -/* #define MBEDTLS_CHECK_RETURN __attribute__((__warn_unused_result__)) */ - -/** \def MBEDTLS_IGNORE_RETURN - * - * This macro requires one argument, which should be a C function call. - * If that function call would cause a #MBEDTLS_CHECK_RETURN warning, this - * warning is suppressed. - */ - -/* #define MBEDTLS_IGNORE_RETURN( result ) ((void) !(result)) */ - -/* PSA options */ - -/** - * Use HMAC_DRBG with the specified hash algorithm for HMAC_DRBG for the - * PSA crypto subsystem. - * - * If this option is unset, the library chooses a hash (currently between - * #MBEDTLS_MD_SHA512 and #MBEDTLS_MD_SHA256) based on availability and - * unspecified heuristics. - * - * \note The PSA crypto subsystem uses the first available mechanism amongst - * the following: - * - #MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG if enabled; - * - Entropy from #MBEDTLS_ENTROPY_C plus CTR_DRBG with AES - * if #MBEDTLS_CTR_DRBG_C is enabled; - * - Entropy from #MBEDTLS_ENTROPY_C plus HMAC_DRBG. - * - * A future version may reevaluate the prioritization of DRBG - * mechanisms. - */ - -/* #define MBEDTLS_PSA_HMAC_DRBG_MD_TYPE MBEDTLS_MD_SHA256 */ - -/** \def MBEDTLS_PSA_KEY_SLOT_COUNT - * - * When #MBEDTLS_PSA_KEY_STORE_DYNAMIC is disabled, - * the maximum amount of PSA keys simultaneously in memory. This counts all - * volatile keys, plus loaded persistent keys. - * - * When #MBEDTLS_PSA_KEY_STORE_DYNAMIC is enabled, - * the maximum number of loaded persistent keys. - * - * Currently, persistent keys do not need to be loaded all the time while - * a multipart operation is in progress, only while the operation is being - * set up. This may change in future versions of the library. - * - * Currently, the library traverses of the whole table on each access to a - * persistent key. Therefore large values may cause poor performance. - * - * This option has no effect when #MBEDTLS_PSA_CRYPTO_C is disabled. - */ - -/* #define MBEDTLS_PSA_KEY_SLOT_COUNT 32 */ - -/* RSA OPTIONS */ - -/* #define MBEDTLS_RSA_GEN_KEY_MIN_BITS 1024 */ - -/* Minimum RSA key size that can be generated in bits (Minimum possible value - * is 128 bits) - */ - -/* SSL Cache options */ - -/* #define MBEDTLS_SSL_CACHE_DEFAULT_TIMEOUT 86400 */ - -/* 1 day */ - -/* #define MBEDTLS_SSL_CACHE_DEFAULT_MAX_ENTRIES 50 */ - -/* Maximum entries in cache */ - -/* SSL options */ - -/** \def MBEDTLS_SSL_IN_CONTENT_LEN - * - * Maximum length (in bytes) of incoming plaintext fragments. - * - * This determines the size of the incoming TLS I/O buffer in such a way - * that it is capable of holding the specified amount of plaintext data, - * regardless of the protection mechanism used. - * - * \note When using a value less than the default of 16KB on the client, - * it is recommended to use the Maximum Fragment Length (MFL) - * extension to inform the server about this limitation. On the server, - * there is no supported, standardized way of informing the client - * about restriction on the maximum size of incoming messages, and - * unless the limitation has been communicated by other means, it is - * recommended to only change the outgoing buffer size - * #MBEDTLS_SSL_OUT_CONTENT_LEN while keeping the default value of - * 16KB for the incoming buffer. - * - * Uncomment to set the maximum plaintext size of the incoming I/O buffer. - */ -#ifdef CONFIG_MBEDTLS_SSL_IN_CONTENT_LEN -#define MBEDTLS_SSL_IN_CONTENT_LEN CONFIG_MBEDTLS_SSL_IN_CONTENT_LEN -#endif - -/** \def MBEDTLS_SSL_CID_IN_LEN_MAX - * - * The maximum length of CIDs used for incoming DTLS messages. - * - */ - -/* #define MBEDTLS_SSL_CID_IN_LEN_MAX 32 */ - -/** \def MBEDTLS_SSL_CID_OUT_LEN_MAX - * - * The maximum length of CIDs used for outgoing DTLS messages. - * - */ - -/* #define MBEDTLS_SSL_CID_OUT_LEN_MAX 32 */ - -/** \def MBEDTLS_SSL_CID_TLS1_3_PADDING_GRANULARITY - * - * This option controls the use of record plaintext padding - * in TLS 1.3 and when using the Connection ID extension in DTLS 1.2. - * - * The padding will always be chosen so that the length of the - * padded plaintext is a multiple of the value of this option. - * - * Note: A value of \c 1 means that no padding will be used - * for outgoing records. - * - * Note: On systems lacking division instructions, - * a power of two should be preferred. - */ - -/* #define MBEDTLS_SSL_CID_TLS1_3_PADDING_GRANULARITY 16 */ - -/** \def MBEDTLS_SSL_OUT_CONTENT_LEN - * - * Maximum length (in bytes) of outgoing plaintext fragments. - * - * This determines the size of the outgoing TLS I/O buffer in such a way - * that it is capable of holding the specified amount of plaintext data, - * regardless of the protection mechanism used. - * - * It is possible to save RAM by setting a smaller outward buffer, while - *keeping - * the default inward 16384 byte buffer to conform to the TLS specification. - * - * The minimum required outward buffer size is determined by the handshake - * protocol's usage. Handshaking will fail if the outward buffer is too - * small. The specific size requirement depends on the configured ciphers - * and any certificate data which is sent during the handshake. - * - * Uncomment to set the maximum plaintext size of the outgoing I/O buffer. - */ -#ifdef CONFIG_MBEDTLS_SSL_OUT_CONTENT_LEN -#define MBEDTLS_SSL_OUT_CONTENT_LEN CONFIG_MBEDTLS_SSL_OUT_CONTENT_LEN -#endif - -/** \def MBEDTLS_SSL_DTLS_MAX_BUFFERING - * - * Maximum number of heap-allocated bytes for the purpose of - * DTLS handshake message reassembly and future message buffering. - * - * This should be at least 9/8 * MBEDTLS_SSL_IN_CONTENT_LEN - * to account for a reassembled handshake message of maximum size, - * together with its reassembly bitmap. - * - * A value of 2 * MBEDTLS_SSL_IN_CONTENT_LEN (32768 by default) - * should be sufficient for all practical situations as it allows - * to reassembly a large handshake message (such as a certificate) - * while buffering multiple smaller handshake messages. - * - */ - -/* #define MBEDTLS_SSL_DTLS_MAX_BUFFERING 32768 */ - -/* #define MBEDTLS_PSK_MAX_LEN 32 */ - -/* Max size of TLS pre-shared keys, in bytes (default 256 or 384 bits) */ - -/* #define MBEDTLS_SSL_COOKIE_TIMEOUT 60 */ - -/* Default expiration delay of DTLS cookies, in seconds if HAVE_TIME, - * or in number of cookies issued - */ - -/** - * Complete list of ciphersuites to use, in order of preference. - * - * \warning No dependency checking is done on that field! This option - * can only be used to restrict the set of available ciphersuites. - * It is your responsibility to make sure the needed modules are active. - * - * Use this to save a few hundred bytes of ROM (default ordering of all - * available ciphersuites) and a few to a few hundred bytes of RAM. - * - * The value below is only an example, not the default. - */ - -/* #define MBEDTLS_SSL_CIPHERSUITES - * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, - * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 - */ - -/** - * \def MBEDTLS_SSL_MAX_EARLY_DATA_SIZE - * - * The default maximum amount of 0-RTT data. See the documentation of - * \c mbedtls_ssl_conf_max_early_data_size() for more information. - * - * It must be positive and smaller than UINT32_MAX. - * - * If MBEDTLS_SSL_EARLY_DATA is not defined, this default value does not - * have any impact on the build. - */ - -/* #define MBEDTLS_SSL_MAX_EARLY_DATA_SIZE 1024 */ - -/** - * \def MBEDTLS_SSL_TLS1_3_TICKET_AGE_TOLERANCE - * - * Maximum allowed ticket age difference in milliseconds tolerated between - * server and client. Default value is 6000. This is not used in TLS 1.2. - * - * - The client ticket age is the time difference between the time when the - * client proposes to the server to use the ticket and the time the client - * received the ticket from the server. - * - The server ticket age is the time difference between the time when the - * server receives a proposition from the client to use the ticket and the - * time when the ticket was created by the server. - * - * The ages might be different due to the client and server clocks not - * running at the same pace. The typical accuracy of an RTC crystal is ยฑ100 - * to ยฑ20 parts per million (360 to 72 milliseconds per hour). Default - * tolerance window is 6s, thus in the worst case clients and servers must - * sync up their system time every 6000/360/2~=8 hours. - * - * See section 8.3 of the TLS 1.3 specification(RFC 8446) for more - * information. - */ - -/* #define MBEDTLS_SSL_TLS1_3_TICKET_AGE_TOLERANCE 6000 */ - -/** - * \def MBEDTLS_SSL_TLS1_3_TICKET_NONCE_LENGTH - * - * Size in bytes of a ticket nonce. This is not used in TLS 1.2. - * - * This must be less than 256. - */ - -/* #define MBEDTLS_SSL_TLS1_3_TICKET_NONCE_LENGTH 32 */ - -/** - * \def MBEDTLS_SSL_TLS1_3_DEFAULT_NEW_SESSION_TICKETS - * - * Default number of NewSessionTicket messages to be sent by a TLS 1.3 server - * after handshake completion. This is not used in TLS 1.2 and relevant only - *if - * the MBEDTLS_SSL_SESSION_TICKETS option is enabled. - * - */ - -/* #define MBEDTLS_SSL_TLS1_3_DEFAULT_NEW_SESSION_TICKETS 1 */ - -/* X509 options */ - -/* #define MBEDTLS_X509_MAX_INTERMEDIATE_CA 8 */ - -/* Maximum number of intermediate CAs in a verification chain. */ - -/* #define MBEDTLS_X509_MAX_FILE_PATH_LEN 512 */ - -/* Maximum length of a path/filename string in bytes - * including the null terminator character ('\0'). - */ - -/** \} name SECTION: Module configuration options */ - -#endif /* __APPS_CRYPTO_MBEDTLS_INCLUDE_MBEDTLS_MBEDTLS_CONFIG_H */ diff --git a/crypto/mbedtls/include/md5_alt.h b/crypto/mbedtls/include/md5_alt.h deleted file mode 100644 index 4c0fdb292..000000000 --- a/crypto/mbedtls/include/md5_alt.h +++ /dev/null @@ -1,33 +0,0 @@ -/**************************************************************************** - * apps/crypto/mbedtls/include/md5_alt.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - ****************************************************************************/ - -#ifndef __APPS_CRYPTO_MBEDTLS_INCLUDE_MD5_ALT_H -#define __APPS_CRYPTO_MBEDTLS_INCLUDE_MD5_ALT_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "dev_alt.h" - -#define mbedtls_md5_context cryptodev_context_t - -#endif /* __APPS_CRYPTO_MBEDTLS_INCLUDE_MD5_ALT_H */ diff --git a/crypto/mbedtls/include/poly1305_alt.h b/crypto/mbedtls/include/poly1305_alt.h deleted file mode 100644 index 7f55f7073..000000000 --- a/crypto/mbedtls/include/poly1305_alt.h +++ /dev/null @@ -1,33 +0,0 @@ -/**************************************************************************** - * apps/crypto/mbedtls/include/poly1305_alt.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - ****************************************************************************/ - -#ifndef __APPS_CRYPTO_MBEDTLS_INCLUDE_POLY1305_ALT_H -#define __APPS_CRYPTO_MBEDTLS_INCLUDE_POLY1305_ALT_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "dev_alt.h" - -#define mbedtls_poly1305_context cryptodev_context_t - -#endif /* __APPS_CRYPTO_MBEDTLS_INCLUDE_POLY1305_ALT_H */ diff --git a/crypto/mbedtls/include/ripemd160_alt.h b/crypto/mbedtls/include/ripemd160_alt.h deleted file mode 100644 index 8911d919f..000000000 --- a/crypto/mbedtls/include/ripemd160_alt.h +++ /dev/null @@ -1,33 +0,0 @@ -/**************************************************************************** - * apps/crypto/mbedtls/include/ripemd160_alt.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - ****************************************************************************/ - -#ifndef __APPS_CRYPTO_MBEDTLS_INCLUDE_RIPEMD160_ALT_H -#define __APPS_CRYPTO_MBEDTLS_INCLUDE_RIPEMD160_ALT_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "dev_alt.h" - -#define mbedtls_ripemd160_context cryptodev_context_t - -#endif /* __APPS_CRYPTO_MBEDTLS_INCLUDE_RIPEMD160_ALT_H */ diff --git a/crypto/mbedtls/include/sha1_alt.h b/crypto/mbedtls/include/sha1_alt.h deleted file mode 100644 index dede51762..000000000 --- a/crypto/mbedtls/include/sha1_alt.h +++ /dev/null @@ -1,33 +0,0 @@ -/**************************************************************************** - * apps/crypto/mbedtls/include/sha1_alt.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - ****************************************************************************/ - -#ifndef __APPS_CRYPTO_MBEDTLS_INCLUDE_SHA1_ALT_H -#define __APPS_CRYPTO_MBEDTLS_INCLUDE_SHA1_ALT_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "dev_alt.h" - -#define mbedtls_sha1_context cryptodev_context_t - -#endif /* __APPS_CRYPTO_MBEDTLS_INCLUDE_SHA1_ALT_H */ diff --git a/crypto/mbedtls/include/sha256_alt.h b/crypto/mbedtls/include/sha256_alt.h deleted file mode 100644 index bfbf135e8..000000000 --- a/crypto/mbedtls/include/sha256_alt.h +++ /dev/null @@ -1,33 +0,0 @@ -/**************************************************************************** - * apps/crypto/mbedtls/include/sha256_alt.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - ****************************************************************************/ - -#ifndef __APPS_CRYPTO_MBEDTLS_INCLUDE_SHA256_ALT_H -#define __APPS_CRYPTO_MBEDTLS_INCLUDE_SHA256_ALT_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "dev_alt.h" - -#define mbedtls_sha256_context cryptodev_context_t - -#endif /* __APPS_CRYPTO_MBEDTLS_INCLUDE_SHA256_ALT_H */ diff --git a/crypto/mbedtls/include/sha512_alt.h b/crypto/mbedtls/include/sha512_alt.h deleted file mode 100644 index b12adeee4..000000000 --- a/crypto/mbedtls/include/sha512_alt.h +++ /dev/null @@ -1,33 +0,0 @@ -/**************************************************************************** - * apps/crypto/mbedtls/include/sha512_alt.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - ****************************************************************************/ - -#ifndef __APPS_CRYPTO_MBEDTLS_INCLUDE_SHA512_ALT_H -#define __APPS_CRYPTO_MBEDTLS_INCLUDE_SHA512_ALT_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "dev_alt.h" - -#define mbedtls_sha512_context cryptodev_context_t - -#endif /* __APPS_CRYPTO_MBEDTLS_INCLUDE_SHA512_ALT_H */ diff --git a/crypto/mbedtls/source/aes_alt.c b/crypto/mbedtls/source/aes_alt.c deleted file mode 100644 index 23baa1959..000000000 --- a/crypto/mbedtls/source/aes_alt.c +++ /dev/null @@ -1,412 +0,0 @@ -/**************************************************************************** - * apps/crypto/mbedtls/source/aes_alt.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "mbedtls/aes.h" -#include <errno.h> -#include <stdlib.h> -#include <string.h> - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define ECB_BLOCK_SIZE 16 -#define NONCE_LENGTH 4 - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -void mbedtls_aes_init(FAR mbedtls_aes_context *ctx) -{ - cryptodev_init(&ctx->dev); -} - -void mbedtls_aes_free(FAR mbedtls_aes_context *ctx) -{ - cryptodev_free(&ctx->dev); -} - -int mbedtls_aes_setkey_enc(FAR mbedtls_aes_context *ctx, - FAR const unsigned char *key, - unsigned int keybits) -{ - switch (keybits) - { - case 128: - break; - case 192: - break; - case 256: - break; - default: - return MBEDTLS_ERR_AES_INVALID_KEY_LENGTH; - } - - memcpy(ctx->key, key, keybits / 8); - ctx->dev.session.key = (caddr_t)ctx->key; - ctx->dev.session.keylen = keybits / 8; - return 0; -} - -int mbedtls_aes_setkey_dec(FAR mbedtls_aes_context *ctx, - FAR const unsigned char *key, - unsigned int keybits) -{ - return mbedtls_aes_setkey_enc(ctx, key, keybits); -} - -/* AES-ECB block encryption/decryption */ - -int mbedtls_aes_crypt_ecb(FAR mbedtls_aes_context *ctx, - int mode, - const unsigned char input[16], - unsigned char output[16]) -{ - int ret; - unsigned char iv[16]; - - if (mode != MBEDTLS_AES_ENCRYPT && mode != MBEDTLS_AES_DECRYPT) - { - return MBEDTLS_ERR_AES_BAD_INPUT_DATA; - } - - ctx->dev.session.cipher = CRYPTO_AES_CBC; - ret = cryptodev_get_session(&ctx->dev); - if (ret != 0) - { - return ret; - } - - memset(iv, 0, 16); - ctx->dev.crypt.ses = ctx->dev.session.ses; - ctx->dev.crypt.op = mode == MBEDTLS_AES_ENCRYPT ? - COP_ENCRYPT : COP_DECRYPT; - ctx->dev.crypt.len = ECB_BLOCK_SIZE; - ctx->dev.crypt.src = (caddr_t)input; - ctx->dev.crypt.dst = (caddr_t)output; - ctx->dev.crypt.iv = (caddr_t)iv; - ret = cryptodev_crypt(&ctx->dev); - cryptodev_free_session(&ctx->dev); - return ret; -} - -#if defined(MBEDTLS_CIPHER_MODE_CBC) - -/* AES-CBC buffer encryption/decryption */ - -int mbedtls_aes_crypt_cbc(mbedtls_aes_context *ctx, - int mode, - size_t length, - unsigned char iv[16], - const unsigned char *input, - unsigned char *output) -{ - int ret; - - if (mode != MBEDTLS_AES_ENCRYPT && mode != MBEDTLS_AES_DECRYPT) - { - return MBEDTLS_ERR_AES_BAD_INPUT_DATA; - } - - if ((length % 16) != 0) - { - return MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH; - } - - ctx->dev.session.cipher = CRYPTO_AES_CBC; - ret = cryptodev_get_session(&ctx->dev); - if (ret != 0) - { - return ret; - } - - ctx->dev.crypt.ses = ctx->dev.session.ses; - ctx->dev.crypt.op = mode == MBEDTLS_AES_ENCRYPT ? - COP_ENCRYPT : COP_DECRYPT; - ctx->dev.crypt.len = length; - ctx->dev.crypt.src = (caddr_t)input; - ctx->dev.crypt.dst = (caddr_t)output; - ctx->dev.crypt.iv = (caddr_t)iv; - ret = cryptodev_crypt(&ctx->dev); - cryptodev_free_session(&ctx->dev); - return ret; -} -#endif /* MBEDTLS_CIPHER_MODE_CBC */ - -#if defined(MBEDTLS_CIPHER_MODE_CTR) - -/* AES-CTR buffer encryption/decryption */ - -int mbedtls_aes_crypt_ctr(FAR mbedtls_aes_context *ctx, - size_t length, - FAR size_t *nc_off, - unsigned char nonce_counter[16], - unsigned char stream_block[16], - FAR const unsigned char *input, - FAR unsigned char *output) -{ - int ret; - - if (*nc_off > 0x0f) - { - return MBEDTLS_ERR_AES_BAD_INPUT_DATA; - } - - ctx->dev.session.cipher = CRYPTO_AES_CTR; - memcpy(ctx->key + ctx->dev.session.keylen, - nonce_counter, NONCE_LENGTH); - ctx->dev.session.keylen += NONCE_LENGTH; - ret = cryptodev_get_session(&ctx->dev); - if (ret != 0) - { - return ret; - } - - ctx->dev.crypt.ses = ctx->dev.session.ses; - ctx->dev.crypt.op = COP_ENCRYPT; - ctx->dev.crypt.len = length; - ctx->dev.crypt.src = (caddr_t)input; - ctx->dev.crypt.dst = (caddr_t)output; - ctx->dev.crypt.iv = (caddr_t)nonce_counter + NONCE_LENGTH; - ret = cryptodev_crypt(&ctx->dev); - if (ret == 0) - { - *nc_off = length % ECB_BLOCK_SIZE; - } - - cryptodev_free_session(&ctx->dev); - return ret; -} -#endif /* MBEDTLS_CIPHER_MODE_CTR */ - -#if defined(MBEDTLS_CIPHER_MODE_XTS) -void mbedtls_aes_xts_init(FAR mbedtls_aes_xts_context *ctx) -{ - mbedtls_aes_init(ctx); -} - -void mbedtls_aes_xts_free(FAR mbedtls_aes_xts_context *ctx) -{ - mbedtls_aes_free(ctx); -} - -int mbedtls_aes_xts_setkey_enc(FAR mbedtls_aes_xts_context *ctx, - FAR const unsigned char *key, - unsigned int keybits) -{ - if (keybits != 256 && keybits != 512) - { - return MBEDTLS_ERR_AES_INVALID_KEY_LENGTH; - } - - memcpy(ctx->key, key, keybits / 8); - ctx->dev.session.key = (caddr_t)ctx->key; - ctx->dev.session.keylen = keybits / 8; - return 0; -} - -int mbedtls_aes_xts_setkey_dec(FAR mbedtls_aes_xts_context *ctx, - FAR const unsigned char *key, - unsigned int keybits) -{ - return mbedtls_aes_xts_setkey_enc(ctx, key, keybits); -} - -int mbedtls_aes_crypt_xts(FAR mbedtls_aes_xts_context *ctx, - int mode, - size_t length, - const unsigned char data_unit[16], - FAR const unsigned char *input, - FAR unsigned char *output) -{ - int ret; - unsigned char iv[16]; - - if (mode != MBEDTLS_AES_ENCRYPT && mode != MBEDTLS_AES_DECRYPT) - { - return MBEDTLS_ERR_AES_BAD_INPUT_DATA; - } - - /* Data units must be at least 16 bytes long. */ - - if (length < 16) - { - return MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH; - } - - /* NIST SP 800-38E disallows data units larger than 2**20 blocks. */ - - if (length > (1 << 20) * 16) - { - return MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH; - } - - ctx->dev.session.cipher = CRYPTO_AES_XTS; - ret = cryptodev_get_session(&ctx->dev); - if (ret != 0) - { - return ret; - } - - memcpy(iv, data_unit, 16); - ctx->dev.crypt.ses = ctx->dev.session.ses; - ctx->dev.crypt.op = mode == MBEDTLS_AES_ENCRYPT ? - COP_ENCRYPT : COP_DECRYPT; - ctx->dev.crypt.len = length; - ctx->dev.crypt.src = (caddr_t)input; - ctx->dev.crypt.dst = (caddr_t)output; - ctx->dev.crypt.iv = (caddr_t)iv; - ret = cryptodev_crypt(&ctx->dev); - cryptodev_free_session(&ctx->dev); - return ret; -} -#endif /* MBEDTLS_CIPHER_MODE_XTS */ - -#if defined(MBEDTLS_CIPHER_MODE_CFB) - -/* AES-CFB128 buffer encryption/decryption */ - -int mbedtls_aes_crypt_cfb128(FAR mbedtls_aes_context *ctx, - int mode, - size_t length, - size_t *iv_off, - unsigned char iv[16], - const unsigned char *input, - unsigned char *output) -{ - int ret; - - if (mode != MBEDTLS_AES_ENCRYPT && mode != MBEDTLS_AES_DECRYPT) - { - return MBEDTLS_ERR_AES_BAD_INPUT_DATA; - } - - if (*iv_off > 15) - { - return MBEDTLS_ERR_AES_BAD_INPUT_DATA; - } - - ctx->dev.session.cipher = CRYPTO_AES_CFB_128; - ret = cryptodev_get_session(&ctx->dev); - if (ret != 0) - { - return ret; - } - - ctx->dev.crypt.ses = ctx->dev.session.ses; - ctx->dev.crypt.op = mode == MBEDTLS_AES_ENCRYPT ? - COP_ENCRYPT : COP_DECRYPT; - ctx->dev.crypt.len = length; - ctx->dev.crypt.src = (caddr_t)input; - ctx->dev.crypt.dst = (caddr_t)output; - ctx->dev.crypt.iv = (caddr_t)iv; - ret = cryptodev_crypt(&ctx->dev); - if (ret == 0) - { - *iv_off = length % ECB_BLOCK_SIZE; - } - - cryptodev_free_session(&ctx->dev); - return ret; -} - -/* AES-CFB8 buffer encryption/decryption */ - -int mbedtls_aes_crypt_cfb8(FAR mbedtls_aes_context *ctx, - int mode, - size_t length, - unsigned char iv[16], - const unsigned char *input, - unsigned char *output) -{ - int ret; - - if (mode != MBEDTLS_AES_ENCRYPT && mode != MBEDTLS_AES_DECRYPT) - { - return MBEDTLS_ERR_AES_BAD_INPUT_DATA; - } - - ctx->dev.session.cipher = CRYPTO_AES_CFB_8; - ret = cryptodev_get_session(&ctx->dev); - if (ret != 0) - { - return ret; - } - - ctx->dev.crypt.ses = ctx->dev.session.ses; - ctx->dev.crypt.op = mode == MBEDTLS_AES_ENCRYPT ? - COP_ENCRYPT : COP_DECRYPT; - ctx->dev.crypt.len = length; - ctx->dev.crypt.src = (caddr_t)input; - ctx->dev.crypt.dst = (caddr_t)output; - ctx->dev.crypt.iv = (caddr_t)iv; - ret = cryptodev_crypt(&ctx->dev); - cryptodev_free_session(&ctx->dev); - return ret; -} -#endif /* MBEDTLS_CIPHER_MODE_CFB */ - -#if defined(MBEDTLS_CIPHER_MODE_OFB) - -/* AES-OFB (Output Feedback Mode) buffer encryption/decryption */ - -int mbedtls_aes_crypt_ofb(FAR mbedtls_aes_context *ctx, - size_t length, - size_t *iv_off, - unsigned char iv[16], - const unsigned char *input, - unsigned char *output) -{ - int ret; - - if (*iv_off > 15) - { - return MBEDTLS_ERR_AES_BAD_INPUT_DATA; - } - - ctx->dev.session.cipher = CRYPTO_AES_OFB; - ret = cryptodev_get_session(&ctx->dev); - if (ret != 0) - { - return ret; - } - - ctx->dev.crypt.ses = ctx->dev.session.ses; - ctx->dev.crypt.op = COP_ENCRYPT; - ctx->dev.crypt.len = length; - ctx->dev.crypt.src = (caddr_t)input; - ctx->dev.crypt.dst = (caddr_t)output; - ctx->dev.crypt.iv = (caddr_t)iv; - ret = cryptodev_crypt(&ctx->dev); - if (ret == 0) - { - *iv_off = length % ECB_BLOCK_SIZE; - } - - cryptodev_free_session(&ctx->dev); - return ret; -} -#endif /* MBEDTLS_CIPHER_MODE_OFB */ diff --git a/crypto/mbedtls/source/bignum_alt.c b/crypto/mbedtls/source/bignum_alt.c deleted file mode 100644 index 4cdddc25f..000000000 --- a/crypto/mbedtls/source/bignum_alt.c +++ /dev/null @@ -1,301 +0,0 @@ -/**************************************************************************** - * apps/crypto/mbedtls/source/bignum_alt.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <errno.h> -#include <fcntl.h> -#include <stdint.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> -#include <sys/ioctl.h> -#include <sys/param.h> -#include <sys/types.h> -#include <nuttx/math/math_ioctl.h> -#include <nuttx/math/mpi.h> -#include "mbedtls/bignum.h" -#include "mbedtls/platform.h" - -#define MBEDTLS_ROUNDUP(v, size) (((v) + (size - 1)) & ~(size - 1)) - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static inline -void mbedtls_mpi_to_mpiparam(FAR struct mpiparam *a, - FAR const mbedtls_mpi *A) -{ - a->n = A->n * sizeof(mbedtls_mpi_uint); - a->s = A->s; - a->p = (FAR uint8_t *)A->p; -} - -static inline -void mpiparam_to_mbedtls_mpi(FAR mbedtls_mpi *A, - FAR const struct mpiparam *a) -{ - A->n = a->n / sizeof(mbedtls_mpi_uint); - A->s = a->s; - A->p = (FAR mbedtls_mpi_uint *)a->p; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -int mbedtls_mpi_add_mpi(FAR mbedtls_mpi *X, FAR const mbedtls_mpi *A, - FAR const mbedtls_mpi *B) -{ - int ret; - int fd; - struct mpi_calc_s mpi; - - fd = open("/dev/mpi0", O_RDWR); - if (fd < 0) - { - return -errno; - } - - mpi.op = MPI_CALC_FUNC_ADD; - mbedtls_mpi_to_mpiparam(&mpi.param[0], A); - mbedtls_mpi_to_mpiparam(&mpi.param[1], B); - - mbedtls_mpi_grow(X, MBEDTLS_ROUNDUP(MAX(A->n, B->n) + 1, - sizeof(mbedtls_mpi_uint))); - mbedtls_mpi_to_mpiparam(&mpi.param[2], X); - ret = ioctl(fd, MATHIOC_MPI_CALC, (unsigned long)((uintptr_t)&mpi)); - if (ret >= 0) - { - mpiparam_to_mbedtls_mpi(X, &mpi.param[2]); - } - - close(fd); - return ret; -} - -int mbedtls_mpi_sub_mpi(FAR mbedtls_mpi *X, FAR const mbedtls_mpi *A, - FAR const mbedtls_mpi *B) -{ - int ret; - int fd; - struct mpi_calc_s mpi; - - fd = open("/dev/mpi0", O_RDWR); - if (fd < 0) - { - return -errno; - } - - mpi.op = MPI_CALC_FUNC_SUB; - mbedtls_mpi_to_mpiparam(&mpi.param[0], A); - mbedtls_mpi_to_mpiparam(&mpi.param[1], B); - - mbedtls_mpi_grow(X, MBEDTLS_ROUNDUP(MAX(A->n, B->n) + 1, - sizeof(mbedtls_mpi_uint))); - mbedtls_mpi_to_mpiparam(&mpi.param[2], X); - ret = ioctl(fd, MATHIOC_MPI_CALC, (unsigned long)((uintptr_t)&mpi)); - if (ret >= 0) - { - mpiparam_to_mbedtls_mpi(X, &mpi.param[2]); - } - - close(fd); - return ret; -} - -int mbedtls_mpi_mul_mpi(FAR mbedtls_mpi *X, FAR const mbedtls_mpi *A, - FAR const mbedtls_mpi *B) -{ - int ret; - int fd; - struct mpi_calc_s mpi; - - fd = open("/dev/mpi0", O_RDWR); - if (fd < 0) - { - return -errno; - } - - mpi.op = MPI_CALC_FUNC_MUL; - mbedtls_mpi_to_mpiparam(&mpi.param[0], A); - mbedtls_mpi_to_mpiparam(&mpi.param[1], B); - - mbedtls_mpi_grow(X, MBEDTLS_ROUNDUP(A->n + B->n, - sizeof(mbedtls_mpi_uint))); - mbedtls_mpi_to_mpiparam(&mpi.param[2], X); - ret = ioctl(fd, MATHIOC_MPI_CALC, (unsigned long)((uintptr_t)&mpi)); - if (ret >= 0) - { - mpiparam_to_mbedtls_mpi(X, &mpi.param[2]); - } - - close(fd); - return ret; -} - -int mbedtls_mpi_div_mpi(FAR mbedtls_mpi *Q, FAR mbedtls_mpi *R, - FAR const mbedtls_mpi *A, FAR const mbedtls_mpi *B) -{ - int ret; - int fd; - struct mpi_calc_s mpi; - - fd = open("/dev/mpi0", O_RDWR); - if (fd < 0) - { - return -errno; - } - - mpi.op = MPI_CALC_FUNC_DIV; - mbedtls_mpi_to_mpiparam(&mpi.param[0], A); - mbedtls_mpi_to_mpiparam(&mpi.param[1], B); - mbedtls_mpi_grow(Q, A->n); - mbedtls_mpi_grow(R, B->n); - mbedtls_mpi_to_mpiparam(&mpi.param[2], Q); - mbedtls_mpi_to_mpiparam(&mpi.param[3], R); - ret = ioctl(fd, MATHIOC_MPI_CALC, (unsigned long)((uintptr_t)&mpi)); - if (ret >= 0) - { - mpiparam_to_mbedtls_mpi(Q, &mpi.param[2]); - mpiparam_to_mbedtls_mpi(R, &mpi.param[3]); - } - - close(fd); - return ret; -} - -int mbedtls_mpi_mod_mpi(FAR mbedtls_mpi *R, FAR const mbedtls_mpi *A, - FAR const mbedtls_mpi *B) -{ - int ret; - int fd; - struct mpi_calc_s mpi; - - fd = open("/dev/mpi0", O_RDWR); - if (fd < 0) - { - return -errno; - } - - mpi.op = MPI_CALC_FUNC_MOD; - mbedtls_mpi_to_mpiparam(&mpi.param[0], A); - mbedtls_mpi_to_mpiparam(&mpi.param[1], B); - mbedtls_mpi_grow(R, B->n); - mbedtls_mpi_to_mpiparam(&mpi.param[2], R); - ret = ioctl(fd, MATHIOC_MPI_CALC, (unsigned long)((uintptr_t)&mpi)); - if (ret >= 0) - { - mpiparam_to_mbedtls_mpi(R, &mpi.param[2]); - } - - close(fd); - return ret; -} - -int mbedtls_mpi_exp_mod(FAR mbedtls_mpi *X, FAR const mbedtls_mpi *A, - FAR const mbedtls_mpi *E, FAR const mbedtls_mpi *N, - FAR mbedtls_mpi *) -{ - int ret; - int fd; - struct mpi_calc_s mpi; - - fd = open("/dev/mpi0", O_RDWR); - if (fd < 0) - { - return -errno; - } - - mpi.op = MPI_CALC_FUNC_EXP_MOD; - mbedtls_mpi_to_mpiparam(&mpi.param[0], A); - mbedtls_mpi_to_mpiparam(&mpi.param[1], E); - mbedtls_mpi_to_mpiparam(&mpi.param[2], N); - mbedtls_mpi_grow(X, N->n); - mbedtls_mpi_to_mpiparam(&mpi.param[3], X); - ret = ioctl(fd, MATHIOC_MPI_CALC, (unsigned long)((uintptr_t)&mpi)); - if (ret >= 0) - { - mpiparam_to_mbedtls_mpi(X, &mpi.param[3]); - } - - close(fd); - return ret; -} - -int mbedtls_mpi_gcd(FAR mbedtls_mpi *G, FAR const mbedtls_mpi *A, - FAR const mbedtls_mpi *B) -{ - int ret; - int fd; - struct mpi_calc_s mpi; - - fd = open("/dev/mpi0", O_RDWR); - if (fd < 0) - { - return -errno; - } - - mpi.op = MPI_CALC_FUNC_GCD; - mbedtls_mpi_to_mpiparam(&mpi.param[0], A); - mbedtls_mpi_to_mpiparam(&mpi.param[1], B); - mbedtls_mpi_grow(G, MIN(A->n, B->n)); - mbedtls_mpi_to_mpiparam(&mpi.param[2], G); - ret = ioctl(fd, MATHIOC_MPI_CALC, (unsigned long)((uintptr_t)&mpi)); - if (ret >= 0) - { - mpiparam_to_mbedtls_mpi(G, &mpi.param[2]); - } - - close(fd); - return ret; -} - -int mbedtls_mpi_inv_mod(FAR mbedtls_mpi *X, FAR const mbedtls_mpi *A, - FAR const mbedtls_mpi *N) -{ - int ret; - int fd; - struct mpi_calc_s mpi; - - fd = open("/dev/mpi0", O_RDWR); - if (fd < 0) - { - return -errno; - } - - mpi.op = MPI_CALC_FUNC_INV_MOD; - mbedtls_mpi_to_mpiparam(&mpi.param[0], A); - mbedtls_mpi_to_mpiparam(&mpi.param[1], N); - mbedtls_mpi_grow(X, N->n); - mbedtls_mpi_to_mpiparam(&mpi.param[2], X); - ret = ioctl(fd, MATHIOC_MPI_CALC, (unsigned long)((uintptr_t)&mpi)); - if (ret >= 0) - { - mpiparam_to_mbedtls_mpi(X, &mpi.param[2]); - } - - close(fd); - return ret; -} diff --git a/crypto/mbedtls/source/cmac_alt.c b/crypto/mbedtls/source/cmac_alt.c deleted file mode 100644 index c17d4ebdc..000000000 --- a/crypto/mbedtls/source/cmac_alt.c +++ /dev/null @@ -1,259 +0,0 @@ -/**************************************************************************** - * apps/crypto/mbedtls/source/cmac_alt.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "mbedtls/cmac.h" -#include "mbedtls/platform_util.h" -#include "mbedtls/error.h" -#include "mbedtls/platform.h" - -#include <string.h> - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -int mbedtls_cipher_cmac_starts(FAR mbedtls_cipher_context_t *ctx, - FAR const unsigned char *key, - size_t keybits) -{ - FAR mbedtls_cmac_context_t *cmac_ctx; - uint32_t cipher_type; - uint32_t mac_type; - int retval; - - if (ctx == NULL || ctx->cipher_info == NULL || key == NULL) - { - return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA; - } - - switch (ctx->cipher_info->type) - { - case MBEDTLS_CIPHER_AES_128_ECB: - cipher_type = CRYPTO_AES_CMAC; - mac_type = CRYPTO_AES_128_CMAC; - break; - default: - return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA; - } - - cmac_ctx = mbedtls_calloc(1, sizeof(mbedtls_cmac_context_t)); - if (cmac_ctx == NULL) - { - return MBEDTLS_ERR_CIPHER_ALLOC_FAILED; - } - - retval = cryptodev_init(&cmac_ctx->dev); - if (retval != 0) - { - mbedtls_free(cmac_ctx); - return MBEDTLS_ERR_CIPHER_ALLOC_FAILED; - } - - cmac_ctx->cipher_type = cipher_type; - cmac_ctx->mac_type = mac_type; - cmac_ctx->keybits = keybits; - memcpy(cmac_ctx->key, key, keybits / 8); - cmac_ctx->dev.session.cipher = cipher_type; - cmac_ctx->dev.session.key = (caddr_t)cmac_ctx->key; - cmac_ctx->dev.session.keylen = keybits / 8; - cmac_ctx->dev.session.mac = mac_type; - cmac_ctx->dev.session.mackey = (caddr_t)cmac_ctx->key; - cmac_ctx->dev.session.mackeylen = keybits / 8; - - retval = cryptodev_get_session(&cmac_ctx->dev); - if (retval != 0) - { - cryptodev_free(&cmac_ctx->dev); - mbedtls_free(cmac_ctx); - return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA; - } - - ctx->cmac_ctx = cmac_ctx; - return retval; -} - -int mbedtls_cipher_cmac_update(FAR mbedtls_cipher_context_t *ctx, - FAR const unsigned char *input, - size_t ilen) -{ - if (ctx == NULL || ctx->cmac_ctx == NULL || input == NULL || ilen < 0) - { - return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA; - } - - ctx->cmac_ctx->dev.crypt.op = COP_ENCRYPT; - ctx->cmac_ctx->dev.crypt.flags |= COP_FLAG_UPDATE; - ctx->cmac_ctx->dev.crypt.src = (caddr_t)input; - ctx->cmac_ctx->dev.crypt.len = ilen; - if (cryptodev_crypt(&ctx->cmac_ctx->dev) != 0) - { - return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA; - } - - return 0; -} - -int mbedtls_cipher_cmac_finish(FAR mbedtls_cipher_context_t *ctx, - FAR unsigned char *output) -{ - int ret; - - if (ctx == NULL || ctx->cmac_ctx == NULL || output == NULL) - { - return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA; - } - - ctx->cmac_ctx->dev.crypt.flags = 0; - ctx->cmac_ctx->dev.crypt.mac = (caddr_t)output; - ret = cryptodev_crypt(&ctx->cmac_ctx->dev); - if (ret != 0) - { - ret = MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA; - } - - cryptodev_free_session(&ctx->cmac_ctx->dev); - cryptodev_free(&ctx->cmac_ctx->dev); - return ret; -} - -int mbedtls_cipher_cmac_reset(FAR mbedtls_cipher_context_t *ctx) -{ - FAR mbedtls_cmac_context_t *cmac_ctx; - int ret; - - if (ctx == NULL || ctx->cmac_ctx == NULL) - { - return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA; - } - - cmac_ctx = ctx->cmac_ctx; - ret = cryptodev_init(&cmac_ctx->dev); - if (ret != 0) - { - return MBEDTLS_ERR_CIPHER_ALLOC_FAILED; - } - - cmac_ctx->dev.session.cipher = cmac_ctx->cipher_type; - cmac_ctx->dev.session.key = (caddr_t)cmac_ctx->key; - cmac_ctx->dev.session.keylen = cmac_ctx->keybits / 8; - cmac_ctx->dev.session.mac = cmac_ctx->mac_type; - cmac_ctx->dev.session.mackey = (caddr_t)cmac_ctx->key; - cmac_ctx->dev.session.mackeylen = cmac_ctx->keybits / 8; - - ret = cryptodev_get_session(&cmac_ctx->dev); - if (ret != 0) - { - cryptodev_free(&cmac_ctx->dev); - return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA; - } - - return ret; -} - -int mbedtls_cipher_cmac(FAR const mbedtls_cipher_info_t *cipher_info, - FAR const unsigned char *key, size_t keylen, - FAR const unsigned char *input, size_t ilen, - FAR unsigned char *output) -{ - FAR mbedtls_cipher_context_t ctx; - int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; - - if (cipher_info == NULL || key == NULL || input == NULL || output == NULL) - { - return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA; - } - - mbedtls_cipher_init(&ctx); - - if ((ret = mbedtls_cipher_setup(&ctx, cipher_info)) != 0) - { - goto exit; - } - - ret = mbedtls_cipher_cmac_starts(&ctx, key, keylen); - if (ret != 0) - { - goto exit; - } - - ret = mbedtls_cipher_cmac_update(&ctx, input, ilen); - if (ret != 0) - { - goto exit; - } - - ret = mbedtls_cipher_cmac_finish(&ctx, output); - -exit: - mbedtls_cipher_free(&ctx); - return ret; -} - -#if defined(MBEDTLS_AES_C) -int mbedtls_aes_cmac_prf_128(FAR const unsigned char *key, size_t key_length, - FAR const unsigned char *input, size_t in_len, - unsigned char output[16]) -{ - int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; - FAR const mbedtls_cipher_info_t *cipher_info; - unsigned char zero_key[MBEDTLS_AES_BLOCK_SIZE]; - unsigned char int_key[MBEDTLS_AES_BLOCK_SIZE]; - - if (key == NULL || input == NULL || output == NULL) - { - return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA; - } - - cipher_info = mbedtls_cipher_info_from_type(MBEDTLS_CIPHER_AES_128_ECB); - if (cipher_info == NULL) - { - ret = MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE; - goto exit; - } - - if (key_length == MBEDTLS_AES_BLOCK_SIZE) - { - memcpy(int_key, key, MBEDTLS_AES_BLOCK_SIZE); - } - else - { - memset(zero_key, 0, MBEDTLS_AES_BLOCK_SIZE); - - ret = mbedtls_cipher_cmac(cipher_info, zero_key, 128, key, - key_length, int_key); - if (ret != 0) - { - goto exit; - } - } - - ret = mbedtls_cipher_cmac(cipher_info, int_key, 128, input, in_len, - output); - -exit: - mbedtls_platform_zeroize(int_key, sizeof(int_key)); - return ret; -} -#endif /* MBEDTLS_AES_C */ diff --git a/crypto/mbedtls/source/dev_alt.c b/crypto/mbedtls/source/dev_alt.c deleted file mode 100644 index 1c5c290af..000000000 --- a/crypto/mbedtls/source/dev_alt.c +++ /dev/null @@ -1,100 +0,0 @@ -/**************************************************************************** - * apps/crypto/mbedtls/source/dev_alt.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <errno.h> -#include <fcntl.h> -#include <string.h> -#include <unistd.h> -#include <sys/ioctl.h> - -#include "dev_alt.h" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -int cryptodev_init(FAR cryptodev_context_t *ctx) -{ - int ret; - int fd; - - memset(ctx, 0, sizeof(cryptodev_context_t)); - fd = open("/dev/crypto", O_RDWR, 0); - if (fd < 0) - { - return -errno; - } - - ret = ioctl(fd, CRIOGET, &ctx->fd); - close(fd); - if (ret < 0) - { - ret = -errno; - } - - return ret; -} - -void cryptodev_free(FAR cryptodev_context_t *ctx) -{ - close(ctx->fd); - memset(ctx, 0, sizeof(cryptodev_context_t)); -} - -int cryptodev_get_session(FAR cryptodev_context_t *ctx) -{ - int ret; - - ret = ioctl(ctx->fd, CIOCGSESSION, &ctx->session); - if (ret < 0) - { - return -errno; - } - - ctx->crypt.ses = ctx->session.ses; - return ret; -} - -void cryptodev_free_session(FAR cryptodev_context_t *ctx) -{ - ioctl(ctx->fd, CIOCFSESSION, &ctx->session.ses); - ctx->crypt.ses = 0; -} - -int cryptodev_crypt(FAR cryptodev_context_t *ctx) -{ - int ret; - - ret = ioctl(ctx->fd, CIOCCRYPT, &ctx->crypt); - return ret < 0 ? -errno : ret; -} - -int cryptodev_clone(FAR cryptodev_context_t *dst, - FAR const cryptodev_context_t *src) -{ - dst->session = src->session; - dst->crypt = src->crypt; - return dup2(src->fd, dst->fd); -} diff --git a/crypto/mbedtls/source/entropy_alt.c b/crypto/mbedtls/source/entropy_alt.c deleted file mode 100644 index 08323e76c..000000000 --- a/crypto/mbedtls/source/entropy_alt.c +++ /dev/null @@ -1,96 +0,0 @@ -/**************************************************************************** - * apps/crypto/mbedtls/source/entropy_alt.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <fcntl.h> -#include <stdlib.h> -#include <stdio.h> -#include <unistd.h> -#include <psa/crypto.h> -#include <psa/crypto_platform.h> - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -#ifdef CONFIG_MBEDTLS_ENTROPY_HARDWARE_ALT -int mbedtls_hardware_poll(FAR void *data, - FAR unsigned char *output, - size_t len, - FAR size_t *olen) -{ - int fd; - size_t read_len; - *olen = 0; - - fd = open("/dev/random", O_RDONLY, 0); - if (fd < 0) - { - return -errno; - } - - read_len = read(fd, output, len); - if (read_len != len) - { - close(fd); - return -errno; - } - - close(fd); - *olen = len; - - return 0; -} -#endif /* CONFIG_MBEDTLS_ENTROPY_HARDWARE_ALT */ - -#ifdef CONFIG_MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG -psa_status_t mbedtls_psa_external_get_random( - FAR mbedtls_psa_external_random_context_t *context, - FAR uint8_t *output, size_t output_size, FAR size_t *output_length) -{ - int fd; - size_t read_len; - *output_length = 0; - - (void)context; - - fd = open("/dev/random", O_RDONLY, 0); - if (fd < 0) - { - return -errno; - } - - read_len = read(fd, output, output_size); - if (read_len != output_size) - { - close(fd); - return -errno; - } - - close(fd); - *output_length = read_len; - - return 0; -} -#endif /* CONFIG_MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG */ diff --git a/crypto/mbedtls/source/md5_alt.c b/crypto/mbedtls/source/md5_alt.c deleted file mode 100644 index 0a9886a7b..000000000 --- a/crypto/mbedtls/source/md5_alt.c +++ /dev/null @@ -1,76 +0,0 @@ -/**************************************************************************** - * apps/crypto/mbedtls/source/md5_alt.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "mbedtls/md5.h" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -void mbedtls_md5_clone(FAR mbedtls_md5_context *dst, - FAR const mbedtls_md5_context *src) -{ - cryptodev_clone(dst, src); -} - -void mbedtls_md5_init(FAR mbedtls_md5_context *ctx) -{ - cryptodev_init(ctx); -} - -void mbedtls_md5_free(FAR mbedtls_md5_context *ctx) -{ - cryptodev_free(ctx); -} - -int mbedtls_md5_starts(FAR mbedtls_md5_context *ctx) -{ - ctx->session.mac = CRYPTO_MD5; - return cryptodev_get_session(ctx); -} - -int mbedtls_md5_update(FAR mbedtls_md5_context *ctx, - FAR const unsigned char *input, - size_t ilen) -{ - ctx->crypt.op = COP_ENCRYPT; - ctx->crypt.flags |= COP_FLAG_UPDATE; - ctx->crypt.src = (caddr_t)input; - ctx->crypt.len = ilen; - return cryptodev_crypt(ctx); -} - -int mbedtls_md5_finish(FAR mbedtls_md5_context *ctx, - unsigned char output[16]) -{ - int ret; - - ctx->crypt.op = COP_ENCRYPT; - ctx->crypt.flags = 0; - ctx->crypt.mac = (caddr_t)output; - ret = cryptodev_crypt(ctx); - cryptodev_free_session(ctx); - return ret; -} diff --git a/crypto/mbedtls/source/poly1305_alt.c b/crypto/mbedtls/source/poly1305_alt.c deleted file mode 100644 index 0df9ddf3e..000000000 --- a/crypto/mbedtls/source/poly1305_alt.c +++ /dev/null @@ -1,118 +0,0 @@ -/**************************************************************************** - * apps/crypto/mbedtls/source/poly1305_alt.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "mbedtls/error.h" -#include "mbedtls/poly1305.h" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -void mbedtls_poly1305_init(FAR mbedtls_poly1305_context *ctx) -{ - cryptodev_init(ctx); -} - -void mbedtls_poly1305_free(FAR mbedtls_poly1305_context *ctx) -{ - cryptodev_free(ctx); -} - -int mbedtls_poly1305_starts(FAR mbedtls_poly1305_context *ctx, - const unsigned char key[32]) -{ - ctx->session.mac = CRYPTO_POLY1305; - ctx->session.mackey = (caddr_t)key; - ctx->session.mackeylen = 32; - if (cryptodev_get_session(ctx) != 0) - { - return MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA; - } - - return 0; -} - -int mbedtls_poly1305_update(FAR mbedtls_poly1305_context *ctx, - FAR const unsigned char *input, - size_t ilen) -{ - ctx->crypt.op = COP_ENCRYPT; - ctx->crypt.flags |= COP_FLAG_UPDATE; - ctx->crypt.src = (caddr_t)input; - ctx->crypt.len = ilen; - if (cryptodev_crypt(ctx) != 0) - { - return MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA; - } - - return 0; -} - -int mbedtls_poly1305_finish(FAR mbedtls_poly1305_context *ctx, - unsigned char mac[16]) -{ - int ret; - - ctx->crypt.op = COP_ENCRYPT; - ctx->crypt.flags = 0; - ctx->crypt.mac = (caddr_t)mac; - ret = cryptodev_crypt(ctx); - if (ret != 0) - { - ret = MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA; - } - - cryptodev_free_session(ctx); - return ret; -} - -int mbedtls_poly1305_mac(const unsigned char key[32], - FAR const unsigned char *input, - size_t ilen, - unsigned char mac[16]) -{ - mbedtls_poly1305_context ctx; - int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; - - mbedtls_poly1305_init(&ctx); - - ret = mbedtls_poly1305_starts(&ctx, key); - if (ret != 0) - { - goto cleanup; - } - - ret = mbedtls_poly1305_update(&ctx, input, ilen); - if (ret != 0) - { - goto cleanup; - } - - ret = mbedtls_poly1305_finish(&ctx, mac); - -cleanup: - mbedtls_poly1305_free(&ctx); - return ret; -} diff --git a/crypto/mbedtls/source/ripemd160_alt.c b/crypto/mbedtls/source/ripemd160_alt.c deleted file mode 100644 index 2107a63d1..000000000 --- a/crypto/mbedtls/source/ripemd160_alt.c +++ /dev/null @@ -1,76 +0,0 @@ -/**************************************************************************** - * apps/crypto/mbedtls/source/ripemd160_alt.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "mbedtls/ripemd160.h" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -void mbedtls_ripemd160_clone(FAR mbedtls_ripemd160_context *dst, - FAR const mbedtls_ripemd160_context *src) -{ - cryptodev_clone(dst, src); -} - -void mbedtls_ripemd160_init(FAR mbedtls_ripemd160_context *ctx) -{ - cryptodev_init(ctx); -} - -void mbedtls_ripemd160_free(FAR mbedtls_ripemd160_context *ctx) -{ - cryptodev_free(ctx); -} - -int mbedtls_ripemd160_starts(FAR mbedtls_ripemd160_context *ctx) -{ - ctx->session.mac = CRYPTO_RIPEMD160; - return cryptodev_get_session(ctx); -} - -int mbedtls_ripemd160_update(FAR mbedtls_ripemd160_context *ctx, - FAR const unsigned char *input, - size_t ilen) -{ - ctx->crypt.op = COP_ENCRYPT; - ctx->crypt.flags |= COP_FLAG_UPDATE; - ctx->crypt.src = (caddr_t)input; - ctx->crypt.len = ilen; - return cryptodev_crypt(ctx); -} - -int mbedtls_ripemd160_finish(FAR mbedtls_ripemd160_context *ctx, - unsigned char output[20]) -{ - int ret; - - ctx->crypt.op = COP_ENCRYPT; - ctx->crypt.flags = 0; - ctx->crypt.mac = (caddr_t)output; - ret = cryptodev_crypt(ctx); - cryptodev_free_session(ctx); - return ret; -} diff --git a/crypto/mbedtls/source/sha1_alt.c b/crypto/mbedtls/source/sha1_alt.c deleted file mode 100644 index 04e7c511a..000000000 --- a/crypto/mbedtls/source/sha1_alt.c +++ /dev/null @@ -1,91 +0,0 @@ -/**************************************************************************** - * apps/crypto/mbedtls/source/sha1_alt.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "mbedtls/sha1.h" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -void mbedtls_sha1_clone(FAR mbedtls_sha1_context *dst, - FAR const mbedtls_sha1_context *src) -{ - cryptodev_clone(dst, src); -} - -void mbedtls_sha1_init(FAR mbedtls_sha1_context *ctx) -{ - cryptodev_init(ctx); -} - -void mbedtls_sha1_free(FAR mbedtls_sha1_context *ctx) -{ - cryptodev_free(ctx); -} - -int mbedtls_sha1_starts(FAR mbedtls_sha1_context *ctx) -{ - ctx->session.mac = CRYPTO_SHA1; - if (cryptodev_get_session(ctx) != 0) - { - return MBEDTLS_ERR_SHA1_BAD_INPUT_DATA; - } - - return 0; -} - -int mbedtls_sha1_update(FAR mbedtls_sha1_context *ctx, - FAR const unsigned char *input, - size_t ilen) -{ - ctx->crypt.op = COP_ENCRYPT; - ctx->crypt.flags |= COP_FLAG_UPDATE; - ctx->crypt.src = (caddr_t)input; - ctx->crypt.len = ilen; - if (cryptodev_crypt(ctx) != 0) - { - return MBEDTLS_ERR_SHA1_BAD_INPUT_DATA; - } - - return 0; -} - -int mbedtls_sha1_finish(FAR mbedtls_sha1_context *ctx, - unsigned char output[20]) -{ - int ret; - - ctx->crypt.op = COP_ENCRYPT; - ctx->crypt.flags = 0; - ctx->crypt.mac = (caddr_t)output; - ret = cryptodev_crypt(ctx); - if (ret != 0) - { - ret = MBEDTLS_ERR_SHA1_BAD_INPUT_DATA; - } - - cryptodev_free_session(ctx); - return ret; -} diff --git a/crypto/mbedtls/source/sha256_alt.c b/crypto/mbedtls/source/sha256_alt.c deleted file mode 100644 index 4de03a342..000000000 --- a/crypto/mbedtls/source/sha256_alt.c +++ /dev/null @@ -1,104 +0,0 @@ -/**************************************************************************** - * apps/crypto/mbedtls/source/sha256_alt.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "mbedtls/sha256.h" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -void mbedtls_sha256_clone(FAR mbedtls_sha256_context *dst, - FAR const mbedtls_sha256_context *src) -{ - cryptodev_clone(dst, src); -} - -void mbedtls_sha256_init(FAR mbedtls_sha256_context *ctx) -{ - cryptodev_init(ctx); -} - -void mbedtls_sha256_free(FAR mbedtls_sha256_context *ctx) -{ - cryptodev_free(ctx); -} - -int mbedtls_sha256_starts(FAR mbedtls_sha256_context *ctx, int is224) -{ - if (is224 != 0 && is224 != 1) - { - return MBEDTLS_ERR_SHA256_BAD_INPUT_DATA; - } - - if (is224) - { - ctx->session.mac = CRYPTO_SHA2_224; - } - else - { - ctx->session.mac = CRYPTO_SHA2_256; - } - - if (cryptodev_get_session(ctx) != 0) - { - return MBEDTLS_ERR_SHA256_BAD_INPUT_DATA; - } - - return 0; -} - -int mbedtls_sha256_update(FAR mbedtls_sha256_context *ctx, - FAR const unsigned char *input, - size_t ilen) -{ - ctx->crypt.op = COP_ENCRYPT; - ctx->crypt.flags |= COP_FLAG_UPDATE; - ctx->crypt.src = (caddr_t)input; - ctx->crypt.len = ilen; - if (cryptodev_crypt(ctx) != 0) - { - return MBEDTLS_ERR_SHA256_BAD_INPUT_DATA; - } - - return 0; -} - -int mbedtls_sha256_finish(FAR mbedtls_sha256_context *ctx, - FAR unsigned char *output) -{ - int ret; - - ctx->crypt.op = COP_ENCRYPT; - ctx->crypt.flags = 0; - ctx->crypt.mac = (caddr_t)output; - ret = cryptodev_crypt(ctx); - if (ret != 0) - { - ret = MBEDTLS_ERR_SHA256_BAD_INPUT_DATA; - } - - cryptodev_free_session(ctx); - return ret; -} diff --git a/crypto/mbedtls/source/sha512_alt.c b/crypto/mbedtls/source/sha512_alt.c deleted file mode 100644 index 4fb3ed850..000000000 --- a/crypto/mbedtls/source/sha512_alt.c +++ /dev/null @@ -1,104 +0,0 @@ -/**************************************************************************** - * apps/crypto/mbedtls/source/sha512_alt.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "mbedtls/sha512.h" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -void mbedtls_sha512_clone(FAR mbedtls_sha512_context *dst, - FAR const mbedtls_sha512_context *src) -{ - cryptodev_clone(dst, src); -} - -void mbedtls_sha512_init(FAR mbedtls_sha512_context *ctx) -{ - cryptodev_init(ctx); -} - -void mbedtls_sha512_free(FAR mbedtls_sha512_context *ctx) -{ - cryptodev_free(ctx); -} - -int mbedtls_sha512_starts(FAR mbedtls_sha512_context *ctx, int is384) -{ - if (is384 != 0 && is384 != 1) - { - return MBEDTLS_ERR_SHA512_BAD_INPUT_DATA; - } - - if (is384) - { - ctx->session.mac = CRYPTO_SHA2_384; - } - else - { - ctx->session.mac = CRYPTO_SHA2_512; - } - - if (cryptodev_get_session(ctx) != 0) - { - return MBEDTLS_ERR_SHA512_BAD_INPUT_DATA; - } - - return 0; -} - -int mbedtls_sha512_update(FAR mbedtls_sha512_context *ctx, - FAR const unsigned char *input, - size_t ilen) -{ - ctx->crypt.op = COP_ENCRYPT; - ctx->crypt.flags |= COP_FLAG_UPDATE; - ctx->crypt.src = (caddr_t)input; - ctx->crypt.len = ilen; - if (cryptodev_crypt(ctx) != 0) - { - return MBEDTLS_ERR_SHA512_BAD_INPUT_DATA; - } - - return 0; -} - -int mbedtls_sha512_finish(FAR mbedtls_sha512_context *ctx, - FAR unsigned char *output) -{ - int ret; - - ctx->crypt.op = COP_ENCRYPT; - ctx->crypt.flags = 0; - ctx->crypt.mac = (caddr_t)output; - ret = cryptodev_crypt(ctx); - if (ret != 0) - { - ret = MBEDTLS_ERR_SHA512_BAD_INPUT_DATA; - } - - cryptodev_free_session(ctx); - return ret; -} diff --git a/crypto/openssl_mbedtls_wrapper/CMakeLists.txt b/crypto/openssl_mbedtls_wrapper/CMakeLists.txt deleted file mode 100644 index d16c5c6a1..000000000 --- a/crypto/openssl_mbedtls_wrapper/CMakeLists.txt +++ /dev/null @@ -1,32 +0,0 @@ -# ############################################################################## -# apps/crypto/openssl_mbedtls_wrapper/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_OPENSSL_MBEDTLS_WRAPPER) - - set_property( - TARGET nuttx - APPEND - PROPERTY NUTTX_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_LIST_DIR}/include) - - file(GLOB CSRCS ${CMAKE_CURRENT_LIST_DIR}/mbedtls/*.c) - target_sources(apps PRIVATE ${CSRCS}) -endif() diff --git a/crypto/openssl_mbedtls_wrapper/Kconfig b/crypto/openssl_mbedtls_wrapper/Kconfig deleted file mode 100644 index 3a4ee11a2..000000000 --- a/crypto/openssl_mbedtls_wrapper/Kconfig +++ /dev/null @@ -1,31 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config OPENSSL_MBEDTLS_WRAPPER - depends on CRYPTO_MBEDTLS - bool "openssl mbedtls wrapper" - default n - -if OPENSSL_MBEDTLS_WRAPPER - -choice - prompt "Openssl Mbedtls Wrapper Assert Debug" - default OPENSSL_ASSERT_EXIT - -config OPENSSL_ASSERT_DEBUG - bool "SSL_ASSERT* will show error file name and line" - -config OPENSSL_ASSERT_EXIT - bool "SSL_ASSERT* will just return error code" - -config OPENSSL_ASSERT_DEBUG_EXIT - bool "SSL_ASSERT* will show error file name and line, then return error code" - -config OPENSSL_ASSERT_DEBUG_BLOCK - bool "SSL_ASSERT* will show error file name and line, then block here with 'while (1)'" - -endchoice - -endif # OPENSSL_MBEDTLS_WRAPPER diff --git a/crypto/openssl_mbedtls_wrapper/Make.defs b/crypto/openssl_mbedtls_wrapper/Make.defs deleted file mode 100644 index 21f0e1cfb..000000000 --- a/crypto/openssl_mbedtls_wrapper/Make.defs +++ /dev/null @@ -1,27 +0,0 @@ -############################################################################ -# apps/crypto/openssl_mbedtls_wrapper/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_OPENSSL_MBEDTLS_WRAPPER),) -CONFIGURED_APPS += $(APPDIR)/crypto/openssl_mbedtls_wrapper -CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/crypto/openssl_mbedtls_wrapper/include -CXXFLAGS += ${INCDIR_PREFIX}$(APPDIR)/crypto/openssl_mbedtls_wrapper/include -endif diff --git a/crypto/openssl_mbedtls_wrapper/Makefile b/crypto/openssl_mbedtls_wrapper/Makefile deleted file mode 100644 index 25f79c63e..000000000 --- a/crypto/openssl_mbedtls_wrapper/Makefile +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/crypto/openssl_mbedtls_wrapper/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs -CSRCS += $(wildcard $(APPDIR)/crypto/openssl_mbedtls_wrapper/mbedtls/*.c) -include $(APPDIR)/Application.mk diff --git a/crypto/openssl_mbedtls_wrapper/include/openssl/aes.h b/crypto/openssl_mbedtls_wrapper/include/openssl/aes.h deleted file mode 100644 index 4dd165d38..000000000 --- a/crypto/openssl_mbedtls_wrapper/include/openssl/aes.h +++ /dev/null @@ -1,82 +0,0 @@ -/**************************************************************************** - * apps/crypto/openssl_mbedtls_wrapper/include/openssl/aes.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - ****************************************************************************/ - -#ifndef OPENSSL_MBEDTLS_WRAPPER_AES_H -#define OPENSSL_MBEDTLS_WRAPPER_AES_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <openssl/base.h> - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define AES_ENCRYPT 1 -#define AES_DECRYPT 0 - -#define AES_BLOCK_SIZE 16 -#define AES_MAXNR 14 - -#ifdef __cplusplus -extern "C" -{ -#endif - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -struct aes_key_st -{ - uint32_t rd_key[4 * (AES_MAXNR + 1)]; - unsigned rounds; -}; - -typedef struct aes_key_st AES_KEY; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -int AES_set_encrypt_key(const uint8_t *key, unsigned bits, - AES_KEY *aeskey); - -void AES_encrypt(const uint8_t *in, uint8_t *out, - const AES_KEY *key); - -int AES_set_decrypt_key(const uint8_t *key, unsigned bits, - AES_KEY *aeskey); - -void AES_decrypt(const uint8_t *in, uint8_t *out, - const AES_KEY *key); - -void AES_cbc_encrypt(const uint8_t *in, uint8_t *out, - size_t len, const AES_KEY *key, - uint8_t *ivec, const int enc); - -#ifdef __cplusplus -} -#endif - -#endif /* OPENSSL_MBEDTLS_WRAPPER_AES_H */ diff --git a/crypto/openssl_mbedtls_wrapper/include/openssl/asn1.h b/crypto/openssl_mbedtls_wrapper/include/openssl/asn1.h deleted file mode 100644 index 4bacafd40..000000000 --- a/crypto/openssl_mbedtls_wrapper/include/openssl/asn1.h +++ /dev/null @@ -1,84 +0,0 @@ -/**************************************************************************** - * apps/crypto/openssl_mbedtls_wrapper/include/openssl/asn1.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - ****************************************************************************/ - -#ifndef OPENSSL_MBEDTLS_WRAPPER_ASN1_H -#define OPENSSL_MBEDTLS_WRAPPER_ASN1_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <openssl/base.h> -#include <time.h> - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define MBSTRING_FLAG 0x1000 -#define MBSTRING_UTF8 (MBSTRING_FLAG) -#define MBSTRING_ASC (MBSTRING_FLAG | 1) - -#define V_ASN1_NULL 5 - -#ifdef __cplusplus -extern "C" -{ -#endif - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -void ASN1_BIT_STRING_free(ASN1_BIT_STRING *a); - -void ASN1_INTEGER_free(ASN1_INTEGER *a); - -void ASN1_OBJECT_free(ASN1_OBJECT *a); - -void ASN1_OCTET_STRING_free(ASN1_OCTET_STRING *a); - -void ASN1_TIME_free(ASN1_TIME *a); - -ASN1_BIT_STRING *ASN1_BIT_STRING_new(void); - -int ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *str, int n, int value); - -ASN1_OCTET_STRING *ASN1_OCTET_STRING_new(void); - -int i2d_ASN1_BIT_STRING(const ASN1_BIT_STRING *in, uint8_t **outp); - -int ASN1_OCTET_STRING_set(ASN1_OCTET_STRING *str, - const unsigned char *data, int len); - -ASN1_INTEGER *ASN1_INTEGER_new(void); - -ASN1_INTEGER *BN_to_ASN1_INTEGER(const BIGNUM *bn, ASN1_INTEGER *ai); - -ASN1_TIME *ASN1_TIME_new(void); - -ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s, time_t t); - -#ifdef __cplusplus -} -#endif - -#endif /* OPENSSL_MBEDTLS_WRAPPER_ASN1_H */ diff --git a/crypto/openssl_mbedtls_wrapper/include/openssl/base.h b/crypto/openssl_mbedtls_wrapper/include/openssl/base.h deleted file mode 100644 index 93ec89a55..000000000 --- a/crypto/openssl_mbedtls_wrapper/include/openssl/base.h +++ /dev/null @@ -1,83 +0,0 @@ -/**************************************************************************** - * apps/crypto/openssl_mbedtls_wrapper/include/openssl/base.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - ****************************************************************************/ - -#ifndef OPENSSL_MBEDTLS_WRAPPER_BASE_H -#define OPENSSL_MBEDTLS_WRAPPER_BASE_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <stddef.h> -#include <stdint.h> -#include <sys/types.h> - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define ASN1_BIT_STRING ASN1_STRING - -#ifdef __cplusplus -extern "C" -{ -#endif - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -typedef struct EVP_CIPHER EVP_CIPHER; -typedef struct EVP_CIPHER_CTX EVP_CIPHER_CTX; -typedef struct ENGINE ENGINE; -typedef struct EVP_MD EVP_MD; -typedef struct EVP_MD_CTX EVP_MD_CTX; -typedef struct ASN1_BIT_STRING ASN1_BIT_STRING; -typedef struct ASN1_INTEGER ASN1_INTEGER; -typedef struct ASN1_OBJECT ASN1_OBJECT; -typedef struct ASN1_OCTET_STRING ASN1_OCTET_STRING; -typedef struct ASN1_TIME ASN1_TIME; -typedef struct BN_CTX BN_CTX; -typedef struct EC_GROUP EC_GROUP; -typedef struct EC_KEY EC_KEY; -typedef struct EC_POINT EC_POINT; -typedef struct evp_pkey_st EVP_PKEY; -typedef struct EVP_PKEY_CTX EVP_PKEY_CTX; -typedef struct PKCS8_PRIV_KEY_INFO PKCS8_PRIV_KEY_INFO; -typedef struct X509_ALGOR X509_ALGOR; -typedef struct X509_EXTENSION X509_EXTENSION; -typedef struct X509_NAME X509_NAME; -typedef struct BIGNUM BIGNUM; -typedef struct HMAC_CTX HMAC_CTX; -typedef struct rsa_meth_st RSA_METHOD; -typedef struct ecdsa_method_st ECDSA_METHOD; -typedef struct BN_GENCB BN_GENCB; -typedef struct sha256_state_st SHA256_CTX; -typedef struct sha_state_st SHA_CTX; -typedef struct cbb_st CBB; -typedef struct ecdsa_sig_st ECDSA_SIG; -typedef void RSA; - -#ifdef __cplusplus -} -#endif - -#endif /* OPENSSL_MBEDTLS_WRAPPER_BASE_H */ diff --git a/crypto/openssl_mbedtls_wrapper/include/openssl/bio.h b/crypto/openssl_mbedtls_wrapper/include/openssl/bio.h deleted file mode 100644 index 7bfab1eb9..000000000 --- a/crypto/openssl_mbedtls_wrapper/include/openssl/bio.h +++ /dev/null @@ -1,114 +0,0 @@ -/**************************************************************************** - * apps/crypto/openssl_mbedtls_wrapper/include/openssl/bio.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - ****************************************************************************/ - -#ifndef OPENSSL_MBEDTLS_WRAPPER_BIO_H -#define OPENSSL_MBEDTLS_WRAPPER_BIO_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <openssl/base.h> -#include <openssl/types.h> - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* There are the classes of BIOs */ - -#define BIO_TYPE_DESCRIPTOR 0x0100 /* socket, fd, connect or accept */ -#define BIO_TYPE_FILTER 0x0200 -#define BIO_TYPE_SOURCE_SINK 0x0400 - -#define BIO_FLAGS_BASE64_NO_NL 0x100 - -/* This is used with memory BIOs: BIO_FLAGS_MEM_RDONLY - * means we shouldn't free up or change the data in any way; - * BIO_FLAGS_NONCLEAR_RST means we shouldn't clear data on reset. - */ - -#define BIO_FLAGS_MEM_RDONLY 0x200 -#define BIO_FLAGS_NONCLEAR_RST 0x400 -#define BIO_FLAGS_IN_EOF 0x800 - -#define BIO_TYPE_NONE 0 -#define BIO_TYPE_MEM (1 | BIO_TYPE_SOURCE_SINK) -#define BIO_TYPE_FILE (2 | BIO_TYPE_SOURCE_SINK) -#define BIO_TYPE_BASE64 (11 | BIO_TYPE_FILTER) - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -struct bio_method_st -{ - int type; - char *name; - int (*bwrite_old) (BIO *, const char *, int); - int (*bread_old) (BIO *, char *, int); - int (*create) (BIO *); - int (*destroy) (BIO *); -}; - -struct bio_st -{ - const BIO_METHOD *method; - int flags; /* extra storage */ - void *ptr; - struct bio_st *next_bio; /* used by filter BIOs */ - struct bio_st *prev_bio; /* used by filter BIOs */ -}; - -#ifdef __cplusplus -extern "C" -{ -#endif - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -const BIO_METHOD *BIO_f_base64(void); - -const BIO_METHOD *BIO_s_mem(void); - -BIO *BIO_new(const BIO_METHOD *method); - -BIO *BIO_push(BIO *b, BIO *bio); - -void BIO_set_flags(BIO *b, int flags); - -int BIO_write(BIO *b, const void *data, int dlen); - -int BIO_read(BIO *b, void *data, int dlen); - -void BIO_free_all(BIO *bio); - -BIO *BIO_next(BIO *b); - -int BIO_flush(BIO *b); - -#ifdef __cplusplus -} -#endif - -#endif /* OPENSSL_MBEDTLS_WRAPPER_BIO_H */ diff --git a/crypto/openssl_mbedtls_wrapper/include/openssl/bn.h b/crypto/openssl_mbedtls_wrapper/include/openssl/bn.h deleted file mode 100644 index 25b2bcda8..000000000 --- a/crypto/openssl_mbedtls_wrapper/include/openssl/bn.h +++ /dev/null @@ -1,78 +0,0 @@ -/**************************************************************************** - * apps/crypto/openssl_mbedtls_wrapper/include/openssl/bn.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - ****************************************************************************/ - -#ifndef OPENSSL_MBEDTLS_WRAPPER_BN_H -#define OPENSSL_MBEDTLS_WRAPPER_BN_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <openssl/asn1.h> -#include <openssl/base.h> - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define BN_ULONG uint32_t -#define BN_BITS2 32 - -#ifdef __cplusplus -extern "C" -{ -#endif - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -typedef uint32_t BN_ULONG; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -BN_CTX *BN_CTX_new(void); -void BN_CTX_free(BN_CTX *a); -void BN_free(BIGNUM *a); - -BN_ULONG BN_get_word(const BIGNUM *bn); - -unsigned BN_num_bits(const BIGNUM *bn); - -BIGNUM *BN_new(void); - -int BN_bn2binpad(const BIGNUM *in, uint8_t *out, int len); - -int BN_set_word(BIGNUM *bn, BN_ULONG value); - -BIGNUM *BN_dup(const BIGNUM *src); - -BIGNUM *BN_bin2bn(const uint8_t *in, size_t len, BIGNUM *ret); - -int BN_one(BIGNUM *bn); - -#ifdef __cplusplus -} -#endif - -#endif /* OPENSSL_MBEDTLS_WRAPPER_BN_H */ diff --git a/crypto/openssl_mbedtls_wrapper/include/openssl/bytestring.h b/crypto/openssl_mbedtls_wrapper/include/openssl/bytestring.h deleted file mode 100644 index b0fc67952..000000000 --- a/crypto/openssl_mbedtls_wrapper/include/openssl/bytestring.h +++ /dev/null @@ -1,116 +0,0 @@ -/**************************************************************************** - * apps/crypto/openssl_mbedtls_wrapper/include/openssl/bytestring.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - ****************************************************************************/ - -#ifndef OPENSSL_MBEDTLS_WRAPPER_BYTESTRING_H -#define OPENSSL_MBEDTLS_WRAPPER_BYTESTRING_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <openssl/base.h> - -#ifdef __cplusplus -extern "C" -{ -#endif - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -struct cbb_buffer_st -{ - uint8_t * buf; - - /* len is the number of valid bytes in |buf|. */ - - size_t len; - - /* cap is the size of |buf|. */ - - size_t cap; - - /* can_resize is one iff |buf| is owned by this object. If not then |buf| - * cannot be resized. - */ - - unsigned can_resize : 1; - - /* error is one if there was an error writing to this CBB. All future - * operations will fail. - */ - - unsigned error : 1; -}; - -struct cbb_child_st -{ - /* base is a pointer to the buffer this |CBB| writes to. */ - - struct cbb_buffer_st * base; - - /* offset is the number of bytes from the start of - * |base->buf| to this |CBB|'s - * pending length prefix. - */ - - size_t offset; - - /* pending_len_len contains the number of bytes in this |CBB|'s pending - * length-prefix, or zero if no length-prefix is pending. - */ - - uint8_t pending_len_len; - unsigned pending_is_asn1 : 1; -}; - -struct cbb_st -{ - /* child points to a child CBB if a length-prefix is pending. - * CBB* child; - * is_child is one if this is a child |CBB| and zero if it is a top-level - * |CBB|. This determines which arm of the union is valid. - */ - - char is_child; - union - { - struct cbb_buffer_st base; - struct cbb_child_st child; - } u; -}; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -int CBB_init(CBB *cbb, size_t initial_capacity); - -int CBB_finish(CBB *cbb, uint8_t **out_data, size_t *out_len); - -void CBB_cleanup(CBB *cbb); - -#ifdef __cplusplus -} -#endif - -#endif /* OPENSSL_MBEDTLS_WRAPPER_BYTESTRING_H */ diff --git a/crypto/openssl_mbedtls_wrapper/include/openssl/cipher.h b/crypto/openssl_mbedtls_wrapper/include/openssl/cipher.h deleted file mode 100644 index f7ad5c153..000000000 --- a/crypto/openssl_mbedtls_wrapper/include/openssl/cipher.h +++ /dev/null @@ -1,110 +0,0 @@ -/**************************************************************************** - * apps/crypto/openssl_mbedtls_wrapper/include/openssl/cipher.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - ****************************************************************************/ - -#ifndef OPENSSL_MBEDTLS_WRAPPER_CIPER_H -#define OPENSSL_MBEDTLS_WRAPPER_CIPER_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <openssl/base.h> - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define CIPHER_R_BAD_DECRYPT 101 -#define EVP_CTRL_GCM_GET_TAG 0x10 -#define EVP_CTRL_GCM_SET_TAG 0x11 - -#ifdef __cplusplus -extern "C" -{ -#endif - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -void EVP_CIPHER_CTX_init(EVP_CIPHER_CTX *ctx); -int EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *ctx); - -const EVP_CIPHER *EVP_aes_128_ecb(void); -const EVP_CIPHER *EVP_aes_192_ecb(void); -const EVP_CIPHER *EVP_aes_256_ecb(void); -const EVP_CIPHER *EVP_aes_128_cbc(void); -const EVP_CIPHER *EVP_aes_192_cbc(void); -const EVP_CIPHER *EVP_aes_256_cbc(void); -const EVP_CIPHER *EVP_aes_128_ctr(void); -const EVP_CIPHER *EVP_aes_192_ctr(void); -const EVP_CIPHER *EVP_aes_256_ctr(void); -const EVP_CIPHER *EVP_aes_128_gcm(void); -const EVP_CIPHER *EVP_aes_192_gcm(void); -const EVP_CIPHER *EVP_aes_256_gcm(void); - -const EVP_CIPHER *EVP_des_ede(void); -const EVP_CIPHER *EVP_des_ede3(void); -const EVP_CIPHER *EVP_des_ede_cbc(void); -const EVP_CIPHER *EVP_des_ede3_cbc(void); - -int EVP_CIPHER_CTX_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr); -int EVP_CIPHER_CTX_set_padding(EVP_CIPHER_CTX *c, int pad); -int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, - ENGINE *impl, const unsigned char *key, - const unsigned char *iv, int enc); -int EVP_CipherUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, - int *outl, const unsigned char *in, - int inl); -int EVP_CipherFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *outm, - int *outl); - -int EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx); - -EVP_CIPHER_CTX *EVP_CIPHER_CTX_new(void); - -void EVP_CIPHER_CTX_free(EVP_CIPHER_CTX *ctx); - -int EVP_EncryptInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, - ENGINE *impl, const uint8_t *key, - const uint8_t *iv); - -int EVP_DecryptInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, - ENGINE *impl, const uint8_t *key, - const uint8_t *iv); - -int EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, uint8_t *out, - int *out_len, const uint8_t *in, - int in_len); - -int EVP_EncryptFinal_ex(EVP_CIPHER_CTX *ctx, uint8_t *out, int *out_len); - -int EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, uint8_t *out, - int *out_len, const uint8_t *in, - int in_len); - -int EVP_DecryptFinal_ex(EVP_CIPHER_CTX *ctx, uint8_t *out, int *out_len); - -#ifdef __cplusplus -} -#endif - -#endif /* OPENSSL_MBEDTLS_WRAPPER_CIPER_H */ diff --git a/crypto/openssl_mbedtls_wrapper/include/openssl/crypto.h b/crypto/openssl_mbedtls_wrapper/include/openssl/crypto.h deleted file mode 100644 index b573b2949..000000000 --- a/crypto/openssl_mbedtls_wrapper/include/openssl/crypto.h +++ /dev/null @@ -1,48 +0,0 @@ -/**************************************************************************** - * apps/crypto/openssl_mbedtls_wrapper/include/openssl/crypto.h - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - ****************************************************************************/ - -#ifndef OPENSSL_MBEDTLS_WRAPPER_CRYPTO_H -#define OPENSSL_MBEDTLS_WRAPPER_CRYPTO_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <openssl/base.h> - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define CRYPTO_num_locks() 1 -#define CRYPTO_set_locking_callback(func) - -#define CRYPTO_set_id_callback(func) - -/* These defines where used in combination with the old locking callbacks, - * they are not called anymore, but old code that's not called might still - * use them. - */ - -#define CRYPTO_LOCK 1 -#define CRYPTO_UNLOCK 2 -#define CRYPTO_READ 4 -#define CRYPTO_WRITE 8 - -#endif /* OPENSSL_MBEDTLS_WRAPPER_CRYPTO_H */ diff --git a/crypto/openssl_mbedtls_wrapper/include/openssl/curve25519.h b/crypto/openssl_mbedtls_wrapper/include/openssl/curve25519.h deleted file mode 100644 index 3c9847c67..000000000 --- a/crypto/openssl_mbedtls_wrapper/include/openssl/curve25519.h +++ /dev/null @@ -1,79 +0,0 @@ -/**************************************************************************** - * apps/crypto/openssl_mbedtls_wrapper/include/openssl/curve25519.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - ****************************************************************************/ - -#ifndef OPENSSL_MBEDTLS_WRAPPER_CURVE25519_H -#define OPENSSL_MBEDTLS_WRAPPER_CURVE25519_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <openssl/base.h> - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define X25519_PRIVATE_KEY_LEN 32 -#define X25519_PUBLIC_VALUE_LEN 32 -#define X25519_SHARED_KEY_LEN 32 -#define ED25519_PRIVATE_KEY_LEN 64 -#define ED25519_PUBLIC_KEY_LEN 32 -#define ED25519_SIGNATURE_LEN 64 - -#ifdef __cplusplus -extern "C" -{ -#endif - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/* ED25519_keypair sets |out_public_key| and |out_private_key| to a freshly - * generated, publicโ€“private key pair. - */ - -void ED25519_keypair(uint8_t out_public_key[32], - uint8_t out_private_key[64]); - -void X25519_keypair(uint8_t out_public_value[32], - uint8_t out_private_key[32]); - -int X25519(uint8_t out_shared_key[32], const uint8_t private_key[32], - const uint8_t peer_public_value[32]); - -int ED25519_sign(uint8_t out_sig[64], const uint8_t *message, - size_t message_len, const uint8_t private_key[64]); - -int ED25519_verify(const uint8_t *message, size_t message_len, - const uint8_t signature[64], - const uint8_t public_key[32]); - -void ED25519_keypair_from_seed(uint8_t out_public_key[32], - uint8_t out_private_key[64], - const uint8_t seed[32]); - -#ifdef __cplusplus -} -#endif - -#endif /* OPENSSL_MBEDTLS_WRAPPER_CURVE25519_H */ diff --git a/crypto/openssl_mbedtls_wrapper/include/openssl/digest.h b/crypto/openssl_mbedtls_wrapper/include/openssl/digest.h deleted file mode 100644 index 8dab5d380..000000000 --- a/crypto/openssl_mbedtls_wrapper/include/openssl/digest.h +++ /dev/null @@ -1,105 +0,0 @@ -/**************************************************************************** - * apps/crypto/openssl_mbedtls_wrapper/include/openssl/digest.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - ****************************************************************************/ - -#ifndef KEYMASTER_DIGEST_H -#define KEYMASTER_DIGEST_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <openssl/base.h> - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define EVP_MAX_MD_SIZE 64 // SHA-512 is the longest so far. -#define EVP_MAX_MD_BLOCK_SIZE 128 // SHA-512 is the longest so far. - -#ifdef __cplusplus -extern "C" -{ -#endif - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -const EVP_MD *EVP_md4(void); -const EVP_MD *EVP_md5(void); -const EVP_MD *EVP_sha1(void); -const EVP_MD *EVP_sha224(void); -const EVP_MD *EVP_sha256(void); -const EVP_MD *EVP_sha384(void); -const EVP_MD *EVP_sha512(void); -const EVP_MD *EVP_sha512_256(void); -const EVP_MD *EVP_blake2b256(void); - -const EVP_MD *EVP_md5_sha1(void); - -const EVP_MD *EVP_get_digestbynid(int nid); - -const EVP_MD *EVP_get_digestbyobj(const ASN1_OBJECT *obj); - -void EVP_MD_CTX_init(EVP_MD_CTX *ctx); - -EVP_MD_CTX *EVP_MD_CTX_new(void); - -int EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx); - -void EVP_MD_CTX_cleanse(EVP_MD_CTX *ctx); - -void EVP_MD_CTX_free(EVP_MD_CTX *ctx); - -int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in); - -void EVP_MD_CTX_move(EVP_MD_CTX *out, EVP_MD_CTX *in); - -int EVP_MD_CTX_reset(EVP_MD_CTX *ctx); - -/* Digest operations. */ - -int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, - ENGINE *engine); - -int EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type); - -int EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *data, size_t len); - -int EVP_DigestFinal_ex(EVP_MD_CTX *ctx, uint8_t *md_out, - unsigned int *out_size); - -int EVP_DigestFinal(EVP_MD_CTX *ctx, uint8_t *md_out, - unsigned int *out_size); - -int EVP_Digest(const void *data, size_t len, - uint8_t *md_out, unsigned int *md_out_size, - const EVP_MD *type, ENGINE *impl); - -size_t EVP_MD_size(const EVP_MD *md); - -#ifdef __cplusplus -} -#endif - -#endif /* KEYMASTER_DIGEST_H */ - diff --git a/crypto/openssl_mbedtls_wrapper/include/openssl/ec.h b/crypto/openssl_mbedtls_wrapper/include/openssl/ec.h deleted file mode 100644 index fd906035e..000000000 --- a/crypto/openssl_mbedtls_wrapper/include/openssl/ec.h +++ /dev/null @@ -1,114 +0,0 @@ -/**************************************************************************** - * apps/crypto/openssl_mbedtls_wrapper/include/openssl/ec.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - ****************************************************************************/ - -#ifndef OPENSSL_MBEDTLS_WRAPPER_EC_H -#define OPENSSL_MBEDTLS_WRAPPER_EC_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <openssl/base.h> - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define OPENSSL_EC_NAMED_CURVE 1 - -#ifdef __cplusplus -extern "C" -{ -#endif - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -/* point_conversion_form_t enumerates forms, as defined in X9.62 (ECDSA), for - * the encoding of a elliptic curve point (x,y) - */ - -typedef enum -{ - /* POINT_CONVERSION_COMPRESSED indicates that the point is encoded as z||x, - * where the octet z specifies which solution of the quadratic equation y - * is. - */ - - POINT_CONVERSION_COMPRESSED = 2, - - /* POINT_CONVERSION_UNCOMPRESSED indicates that the point is encoded as - * z||x||y, where z is the octet 0x04. - */ - - POINT_CONVERSION_UNCOMPRESSED = 4, - - /* POINT_CONVERSION_HYBRID indicates that the point is encoded as z||x||y, - * where z specifies which solution of the quadratic equation y is. This is - * not supported by the code and has never been observed in use. - * - * TODO(agl): remove once node.js no longer references this. - */ - - POINT_CONVERSION_HYBRID = 6, -} point_conversion_form_t; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -void EC_GROUP_free(EC_GROUP *a); - -void EC_KEY_free(EC_KEY *a); - -void EC_POINT_free(EC_POINT *a); - -int EC_GROUP_get_curve_name(const EC_GROUP *group); - -EC_GROUP *EC_GROUP_new_by_curve_name(int nid); - -int EC_GROUP_get_order(const EC_GROUP *group, BIGNUM *order, BN_CTX *ctx); - -int EC_POINT_get_affine_coordinates_GFp(const EC_GROUP *group, - const EC_POINT *point, BIGNUM *x, - BIGNUM *y, BN_CTX *ctx); - -/* EC_GROUP_set_point_conversion_form aborts the process if |form| is not - * |POINT_CONVERSION_UNCOMPRESSED| and otherwise does nothing. - */ - -void EC_GROUP_set_point_conversion_form(EC_GROUP *group, - point_conversion_form_t form); - -void EC_GROUP_set_asn1_flag(EC_GROUP *group, int flag); - -EC_POINT *EC_POINT_new(const EC_GROUP *group); - -int EC_POINT_oct2point(const EC_GROUP *group, EC_POINT *point, - const uint8_t *buf, size_t len, - BN_CTX *ctx); - -#ifdef __cplusplus -} -#endif - -#endif /* OPENSSL_MBEDTLS_WRAPPER_EC_H */ diff --git a/crypto/openssl_mbedtls_wrapper/include/openssl/ec_key.h b/crypto/openssl_mbedtls_wrapper/include/openssl/ec_key.h deleted file mode 100644 index 2fbd13709..000000000 --- a/crypto/openssl_mbedtls_wrapper/include/openssl/ec_key.h +++ /dev/null @@ -1,110 +0,0 @@ -/**************************************************************************** - * apps/crypto/openssl_mbedtls_wrapper/include/openssl/ec_key.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - ****************************************************************************/ - -#ifndef OPENSSL_MBEDTLS_WRAPPER_EC_KEY_H -#define OPENSSL_MBEDTLS_WRAPPER_EC_KEY_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <openssl/base.h> -#include <openssl/engine.h> -#include <openssl/ex_data.h> - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define ECDSA_FLAG_OPAQUE 1 - -#ifdef __cplusplus -extern "C" -{ -#endif - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -struct ecdsa_method_st -{ - struct openssl_method_common_st common; - - void *app_data; - - int (*init)(EC_KEY *key); - int (*finish)(EC_KEY *key); - - /* group_order_size returns the number of bytes needed to - * represent the order of the group. This is used to - * calculate the maximum size of an ECDSA signature - * in |ECDSA_size|. - */ - - size_t (*group_order_size)(const EC_KEY *key); - - /* sign matches the arguments and behaviour of |ECDSA_sign|. */ - - int (*sign)(const uint8_t *digest, size_t digest_len, uint8_t *sig, - unsigned int *sig_len, EC_KEY *eckey); - - int flags; -}; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -EC_KEY *EC_KEY_new(void); - -const EC_GROUP *EC_KEY_get0_group(const EC_KEY *key); - -const EC_POINT *EC_KEY_get0_public_key(const EC_KEY *key); - -int EC_KEY_set_group(EC_KEY *key, const EC_GROUP *group); - -int EC_KEY_generate_key(EC_KEY *key); - -int EC_KEY_check_key(const EC_KEY *key); - -int EC_KEY_get_ex_new_index(long argl, void *argp, - CRYPTO_EX_unused *unused, - CRYPTO_EX_dup *dup_unused, - CRYPTO_EX_free *free_func); - -EC_KEY *EC_KEY_new_method(const ENGINE *engine); - -int EC_KEY_set_ex_data(EC_KEY *r, int idx, void *arg); - -void *EC_KEY_get_ex_data(const EC_KEY *r, int idx); - -int EC_KEY_set_public_key(EC_KEY *key, const EC_POINT *pub); - -EC_KEY *EC_KEY_new_by_curve_name(int nid); - -int EC_KEY_set_private_key(EC_KEY *key, const BIGNUM *priv); - -#ifdef __cplusplus -} -#endif - -#endif /* OPENSSL_MBEDTLS_WRAPPER_EC_KEY_H */ diff --git a/crypto/openssl_mbedtls_wrapper/include/openssl/ecdsa.h b/crypto/openssl_mbedtls_wrapper/include/openssl/ecdsa.h deleted file mode 100644 index 426680bb3..000000000 --- a/crypto/openssl_mbedtls_wrapper/include/openssl/ecdsa.h +++ /dev/null @@ -1,83 +0,0 @@ -/**************************************************************************** - * apps/crypto/openssl_mbedtls_wrapper/include/openssl/ecdsa.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - ****************************************************************************/ - -#ifndef OPENSSL_MBEDTLS_WRAPPER_ECDSA_H -#define OPENSSL_MBEDTLS_WRAPPER_ECDSA_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <openssl/base.h> -#include <openssl/ec_key.h> - -#ifdef __cplusplus -extern "C" -{ -#endif - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -struct ecdsa_sig_st -{ - BIGNUM *r; - BIGNUM *s; -}; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -size_t ECDSA_size(const EC_KEY *key); - -int ECDSA_sign(int type, const uint8_t *digest, size_t digest_len, - uint8_t *sig, unsigned int *sig_len, - const EC_KEY *key); - -int ECDSA_verify(int type, const uint8_t *digest, - size_t digest_len, const uint8_t *sig, - size_t sig_len, const EC_KEY *key); - -int i2d_ECDSA_SIG(const ECDSA_SIG *sig, uint8_t **outp); - -ECDSA_SIG *d2i_ECDSA_SIG(ECDSA_SIG **out, const uint8_t **inp, long len); - -const BIGNUM *ECDSA_SIG_get0_r(const ECDSA_SIG *sig); - -const BIGNUM *ECDSA_SIG_get0_s(const ECDSA_SIG *sig); - -ECDSA_SIG *ECDSA_SIG_new(void); - -void ECDSA_SIG_free(ECDSA_SIG *sig); - -ECDSA_SIG *ECDSA_do_sign(const uint8_t *digest, size_t digest_len, - const EC_KEY *key); - -int ECDSA_do_verify(const uint8_t *digest, size_t digest_len, - const ECDSA_SIG *sig, const EC_KEY *key); - -#ifdef __cplusplus -} -#endif - -#endif /* OPENSSL_MBEDTLS_WRAPPER_ECDSA_H */ diff --git a/crypto/openssl_mbedtls_wrapper/include/openssl/engine.h b/crypto/openssl_mbedtls_wrapper/include/openssl/engine.h deleted file mode 100644 index 7972fbee7..000000000 --- a/crypto/openssl_mbedtls_wrapper/include/openssl/engine.h +++ /dev/null @@ -1,64 +0,0 @@ -/**************************************************************************** - * apps/crypto/openssl_mbedtls_wrapper/include/openssl/engine.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - ****************************************************************************/ - -#ifndef OPENSSL_MBEDTLS_WRAPPER_ENGINE_H -#define OPENSSL_MBEDTLS_WRAPPER_ENGINE_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <openssl/base.h> - -#ifdef __cplusplus -extern "C" -{ -#endif - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -struct openssl_method_common_st -{ - int references; /* dummy โ€“ not used. */ - char is_static; -}; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -ENGINE *ENGINE_new(void); - -void ENGINE_free(ENGINE *a); - -int ENGINE_set_RSA_method(ENGINE *engine, const RSA_METHOD *method, - size_t method_size); - -int ENGINE_set_ECDSA_method(ENGINE *engine, const ECDSA_METHOD *method, - size_t method_size); - -#ifdef __cplusplus -} -#endif - -#endif /* OPENSSL_MBEDTLS_WRAPPER_ENGINE_H */ diff --git a/crypto/openssl_mbedtls_wrapper/include/openssl/err.h b/crypto/openssl_mbedtls_wrapper/include/openssl/err.h deleted file mode 100644 index 1453be16e..000000000 --- a/crypto/openssl_mbedtls_wrapper/include/openssl/err.h +++ /dev/null @@ -1,63 +0,0 @@ -/**************************************************************************** - * apps/crypto/openssl_mbedtls_wrapper/include/openssl/err.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - ****************************************************************************/ - -#ifndef OPENSSL_MBEDTLS_WRAPPER_ERR_H -#define OPENSSL_MBEDTLS_WRAPPER_ERR_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <stddef.h> - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define ERR_GET_LIB(l) (int)(((l) >> 24L) & 0x0FFL) -#define ERR_GET_REASON(l) (int)((l)&0xFFFL) -#define ERR_LIB_CIPHER 30 - -#ifdef __cplusplus -extern "C" -{ -#endif - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -unsigned long ERR_peek_last_error(void); -void ERR_error_string_n(unsigned long e, char *buf, size_t len); -void ERR_free_strings(void); -char *ERR_error_string(unsigned long e, char *buf); -void ERR_clear_error(void); -unsigned long ERR_get_error(void); -void ERR_remove_state(unsigned long pid); -int ERR_load_crypto_strings(void); -void ERR_print_errors_cb(int (*cb)(const char *str, size_t len, void *u), - void *u); - -#ifdef __cplusplus -} -#endif - -#endif /* OPENSSL_MBEDTLS_WRAPPER_ERR_H */ diff --git a/crypto/openssl_mbedtls_wrapper/include/openssl/evp.h b/crypto/openssl_mbedtls_wrapper/include/openssl/evp.h deleted file mode 100644 index e1696bfa6..000000000 --- a/crypto/openssl_mbedtls_wrapper/include/openssl/evp.h +++ /dev/null @@ -1,181 +0,0 @@ -/**************************************************************************** - * apps/crypto/openssl_mbedtls_wrapper/include/openssl/evp.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - ****************************************************************************/ - -#ifndef OPENSSL_MBEDTLS_WRAPPER_EVP_H -#define OPENSSL_MBEDTLS_WRAPPER_EVP_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <openssl/base.h> -#include <openssl/cipher.h> -#include <openssl/digest.h> -#include <openssl/ec_key.h> -#include <openssl/mem.h> -#include <openssl/nid.h> -#include <openssl/types.h> - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define EVP_PKEY_RSA NID_rsaEncryption -#define EVP_PKEY_EC NID_X9_62_id_ecPublicKey -#define EVP_PKEY_ED25519 NID_ED25519 - -#define EVP_PKEY_X25519 NID_X25519 - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -struct evp_pkey_st -{ - void *pkey_pm; - const PKEY_METHOD *method; -}; - -#ifdef __cplusplus -extern "C" -{ -#endif - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -int EVP_PKEY_id(const EVP_PKEY *pkey); - -RSA *EVP_PKEY_get1_RSA(const EVP_PKEY *pkey); - -int EVP_PKEY_set1_RSA(EVP_PKEY *pkey, RSA *key); - -EVP_PKEY *__EVP_PKEY_new(EVP_PKEY *ipk); - -EVP_PKEY *EVP_PKEY_new(void); - -void EVP_PKEY_free(EVP_PKEY *pkey); - -void EVP_PKEY_CTX_free(EVP_PKEY_CTX *ctx); - -EC_KEY *EVP_PKEY_get0_EC_KEY(const EVP_PKEY *pkey); - -EC_KEY *EVP_PKEY_get1_EC_KEY(const EVP_PKEY *pkey); - -int EVP_PKEY_type(int nid); - -EVP_PKEY *d2i_PrivateKey(int type, EVP_PKEY **out, - const uint8_t **inp, long len); - -int i2d_PUBKEY(const EVP_PKEY *pkey, uint8_t **outp); - -EVP_PKEY *EVP_PKEY_new_raw_private_key(int type, ENGINE *unused, - const uint8_t *in, size_t len); - -int EVP_PKEY_set1_EC_KEY(EVP_PKEY *pkey, EC_KEY *key); - -int EVP_PKEY_bits(const EVP_PKEY *pkey); - -int EVP_DigestSignInit(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx, - const EVP_MD *type, ENGINE *e, - EVP_PKEY *pkey); - -int EVP_DigestSignUpdate(EVP_MD_CTX *ctx, const void *data, size_t len); - -int EVP_DigestSignFinal(EVP_MD_CTX *ctx, uint8_t *out_sig, - size_t *out_sig_len); - -int EVP_DigestSign(EVP_MD_CTX *ctx, uint8_t *out_sig, - size_t *out_sig_len, const uint8_t *data, - size_t data_len); - -int EVP_DigestVerifyInit(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx, - const EVP_MD *type, ENGINE *e, - EVP_PKEY *pkey); - -int EVP_DigestVerifyUpdate(EVP_MD_CTX *ctx, const void *data, - size_t len); - -int EVP_DigestVerifyFinal(EVP_MD_CTX *ctx, const uint8_t *sig, - size_t sig_len); - -EVP_PKEY *d2i_PUBKEY(EVP_PKEY **out, const uint8_t **inp, - long len); - -int EVP_PKEY_size(const EVP_PKEY *pkey); - -int EVP_PKEY_CTX_set_rsa_padding(EVP_PKEY_CTX *ctx, int padding); - -int EVP_PKEY_CTX_set_rsa_pss_saltlen(EVP_PKEY_CTX *ctx, int salt_len); - -int EVP_PKEY_CTX_set_rsa_oaep_md(EVP_PKEY_CTX *ctx, const EVP_MD *md); - -int EVP_PKEY_CTX_set_rsa_mgf1_md(EVP_PKEY_CTX *ctx, const EVP_MD *md); - -EVP_PKEY_CTX *EVP_PKEY_CTX_new(EVP_PKEY *pkey, ENGINE *e); - -int EVP_PKEY_encrypt_init(EVP_PKEY_CTX *ctx); - -int EVP_PKEY_encrypt(EVP_PKEY_CTX *ctx, uint8_t *out, - size_t *out_len, const uint8_t *in, - size_t in_len); - -int EVP_PKEY_decrypt_init(EVP_PKEY_CTX *ctx); - -int EVP_PKEY_decrypt(EVP_PKEY_CTX *ctx, uint8_t *out, - size_t *out_len, const uint8_t *in, - size_t in_len); - -int i2d_PrivateKey(const EVP_PKEY *key, uint8_t **outp); - -EVP_PKEY *X509_get_pubkey(X509 *x509); - -int EVP_marshal_private_key(CBB *cbb, const EVP_PKEY *key); - -int EVP_PKEY_derive_init(EVP_PKEY_CTX *ctx); - -int EVP_PKEY_derive_set_peer(EVP_PKEY_CTX *ctx, EVP_PKEY *peer); - -int EVP_PKEY_get_raw_private_key(const EVP_PKEY *pkey, uint8_t *out, - size_t *out_len); - -int EVP_PKEY_get_raw_public_key(const EVP_PKEY *pkey, uint8_t *out, - size_t *out_len); - -int EVP_PKEY_derive(EVP_PKEY_CTX *ctx, uint8_t *key, size_t *out_key_len); - -int PKCS5_PBKDF2_HMAC(const char *password, size_t password_len, - const uint8_t *salt, size_t salt_len, - unsigned iterations, const EVP_MD *digest, - size_t key_len, uint8_t *out_key); - -const PKEY_METHOD *EVP_PKEY_method(void); - -int OpenSSL_add_all_algorithms(void); - -void EVP_cleanup(void); - -#ifdef __cplusplus -} -#endif - -#endif /* OPENSSL_MBEDTLS_WRAPPER_EVP_H */ diff --git a/crypto/openssl_mbedtls_wrapper/include/openssl/ex_data.h b/crypto/openssl_mbedtls_wrapper/include/openssl/ex_data.h deleted file mode 100644 index b77ba49b8..000000000 --- a/crypto/openssl_mbedtls_wrapper/include/openssl/ex_data.h +++ /dev/null @@ -1,59 +0,0 @@ -/**************************************************************************** - * apps/crypto/openssl_mbedtls_wrapper/include/openssl/ex_data.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - ****************************************************************************/ - -#ifndef OPENSSL_MBEDTLS_WRAPPER_EX_DATA_H -#define OPENSSL_MBEDTLS_WRAPPER_EX_DATA_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <openssl/base.h> - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -#ifdef __cplusplus -extern "C" -{ -#endif - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -typedef int CRYPTO_EX_unused; -typedef struct CRYPTO_EX_DATA CRYPTO_EX_DATA; - -typedef int CRYPTO_EX_dup(CRYPTO_EX_DATA *to, const CRYPTO_EX_DATA *from, - void **from_d, int index, - long argl, void *argp); - -typedef void CRYPTO_EX_free(void *parent, void *ptr, - CRYPTO_EX_DATA *ad, int index, - long argl, void *argp); - -#ifdef __cplusplus -} -#endif - -#endif /* OPENSSL_MBEDTLS_WRAPPER_EX_DATA_H */ diff --git a/crypto/openssl_mbedtls_wrapper/include/openssl/hkdf.h b/crypto/openssl_mbedtls_wrapper/include/openssl/hkdf.h deleted file mode 100644 index 1b5999358..000000000 --- a/crypto/openssl_mbedtls_wrapper/include/openssl/hkdf.h +++ /dev/null @@ -1,75 +0,0 @@ -/**************************************************************************** - * apps/crypto/openssl_mbedtls_wrapper/include/openssl/hkdf.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - ****************************************************************************/ - -#ifndef OPENSSL_MBEDTLS_WRAPPER_HKDF_H -#define OPENSSL_MBEDTLS_WRAPPER_HKDF_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <openssl/base.h> - -#ifdef __cplusplus -extern "C" -{ -#endif - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -int HKDF(uint8_t *out_key, size_t out_len, - const EVP_MD *digest, const uint8_t *secret, - size_t secret_len, const uint8_t *salt, - size_t salt_len, const uint8_t *info, - size_t info_len); - -/* HKDF_extract computes a HKDF PRK (as specified by RFC 5869) from initial - * keying material |secret| and salt |salt| using |digest|, and outputs - * |out_len| bytes to |out_key|. The maximum output size is - * |EVP_MAX_MD_SIZE|. It returns one on success and zero on error. - * - * WARNING: This function orders the inputs differently from RFC 5869 - * specification. Double-check which parameter is the secret/IKM and which is - * the salt when using. - */ - -int HKDF_extract(uint8_t *out_key, size_t *out_len, - const EVP_MD *digest, const uint8_t *secret, - size_t secret_len, const uint8_t *salt, - size_t salt_len); - -/* HKDF_expand computes a HKDF OKM (as specified by RFC 5869) of length - * |out_len| from the PRK |prk| and info |info| using |digest|, and outputs - * the result to |out_key|. It returns one on success and zero on error. - */ - -int HKDF_expand(uint8_t *out_key, size_t out_len, - const EVP_MD *digest, const uint8_t *prk, - size_t prk_len, const uint8_t *info, - size_t info_len); - -#ifdef __cplusplus -} -#endif - -#endif /* OPENSSL_MBEDTLS_WRAPPER_HKDF_H */ diff --git a/crypto/openssl_mbedtls_wrapper/include/openssl/hmac.h b/crypto/openssl_mbedtls_wrapper/include/openssl/hmac.h deleted file mode 100644 index b44e3626a..000000000 --- a/crypto/openssl_mbedtls_wrapper/include/openssl/hmac.h +++ /dev/null @@ -1,74 +0,0 @@ -/**************************************************************************** - * apps/crypto/openssl_mbedtls_wrapper/include/openssl/hmac.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - ****************************************************************************/ - -#ifndef OPENSSL_MBEDTLS_WRAPPER_HMAC_H -#define OPENSSL_MBEDTLS_WRAPPER_HMAC_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <openssl/base.h> -#include <openssl/digest.h> - -#ifdef __cplusplus -extern "C" -{ -#endif - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/* HMAC calculates the HMAC of |data_len| bytes of |data|, using the given - * key and hash function, and writes the result to |out|. On entry, |out| - * must contain at least |EVP_MD_size| bytes of space. The actual length - * of the result is written to |*out_len|. An output size of - * |EVP_MAX_MD_SIZE| will always be large enough. It returns |out| - * or NULL on error. - */ - -uint8_t *HMAC(const EVP_MD *evp_md, const void *key, - size_t key_len, const uint8_t *data, size_t data_len, - uint8_t *out, unsigned int *out_len); - -HMAC_CTX *HMAC_CTX_new(void); - -void HMAC_CTX_init(HMAC_CTX *ctx); - -int HMAC_Init_ex(HMAC_CTX *ctx, const void *key, - size_t key_len, const EVP_MD *md, - ENGINE *impl); - -int HMAC_Update(HMAC_CTX *ctx, const uint8_t *data, size_t data_len); - -int HMAC_Final(HMAC_CTX *ctx, uint8_t *out, unsigned int *out_len); - -void HMAC_CTX_cleanup(HMAC_CTX *ctx); - -void HMAC_CTX_free(HMAC_CTX *ctx); - -#ifdef __cplusplus -} -#endif - -#endif /* OPENSSL_MBEDTLS_WRAPPER_HMAC_H */ - diff --git a/crypto/openssl_mbedtls_wrapper/include/openssl/md5.h b/crypto/openssl_mbedtls_wrapper/include/openssl/md5.h deleted file mode 100644 index b77faf9bc..000000000 --- a/crypto/openssl_mbedtls_wrapper/include/openssl/md5.h +++ /dev/null @@ -1,55 +0,0 @@ -/**************************************************************************** - * apps/crypto/openssl_mbedtls_wrapper/include/openssl/md5.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - ****************************************************************************/ - -#ifndef OPENSSL_MBEDTLS_WRAPPER_MD5_H -#define OPENSSL_MBEDTLS_WRAPPER_MD5_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <openssl/base.h> - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* MD5_DIGEST_LENGTH is the length of an MD5 digest. */ - -#define MD5_DIGEST_LENGTH 16 - -#ifdef __cplusplus -extern "C" -{ -#endif - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -uint8_t *MD5(const uint8_t *data, size_t len, - uint8_t out[MD5_DIGEST_LENGTH]); - -#ifdef __cplusplus -} -#endif - -#endif /* OPENSSL_MBEDTLS_WRAPPER_MD5_H */ diff --git a/crypto/openssl_mbedtls_wrapper/include/openssl/mem.h b/crypto/openssl_mbedtls_wrapper/include/openssl/mem.h deleted file mode 100644 index f657068f5..000000000 --- a/crypto/openssl_mbedtls_wrapper/include/openssl/mem.h +++ /dev/null @@ -1,56 +0,0 @@ -/**************************************************************************** - * apps/crypto/openssl_mbedtls_wrapper/include/openssl/mem.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - ****************************************************************************/ - -#ifndef OPENSSL_MBEDTLS_WRAPPER_MEM_H -#define OPENSSL_MBEDTLS_WRAPPER_MEM_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <openssl/base.h> - -#ifdef __cplusplus -extern "C" -{ -#endif - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/* CRYPTO_memcmp returns zero iff the |len| bytes at - * |a| and |b| are equal. It takes an amount of time - * dependent on |len|, but independent of the contents - * of |a| and |b|. Unlike memcmp, it cannot be used to - * put elements into a defined order as the return value - * when a != b is undefined, other than to be non-zero. - */ - -int CRYPTO_memcmp(const void *a, const void *b, size_t len); - -void OPENSSL_free(void *ptr); - -#ifdef __cplusplus -} -#endif - -#endif /* OPENSSL_MBEDTLS_WRAPPER_MEM_H */ diff --git a/crypto/openssl_mbedtls_wrapper/include/openssl/nid.h b/crypto/openssl_mbedtls_wrapper/include/openssl/nid.h deleted file mode 100644 index 975af6f7a..000000000 --- a/crypto/openssl_mbedtls_wrapper/include/openssl/nid.h +++ /dev/null @@ -1,60 +0,0 @@ -/**************************************************************************** - * apps/crypto/openssl_mbedtls_wrapper/include/openssl/nid.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - ****************************************************************************/ - -#ifndef OPENSSL_MBEDTLS_WRAPPER_NID_H -#define OPENSSL_MBEDTLS_WRAPPER_NID_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <openssl/base.h> - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define NID_rsaEncryption 6 -#define NID_commonName 13 -#define NID_key_usage 83 -#define NID_X9_62_id_ecPublicKey 408 -#define NID_X9_62_prime256v1 415 -#define NID_sha256WithRSAEncryption 668 -#define NID_secp224r1 713 -#define NID_secp384r1 715 -#define NID_secp521r1 716 -#define NID_X25519 948 -#define NID_ED25519 949 - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -#ifdef __cplusplus -extern "C" -{ -#endif - -#ifdef __cplusplus -} -#endif - -#endif /* OPENSSL_MBEDTLS_WRAPPER_NID_H */ diff --git a/crypto/openssl_mbedtls_wrapper/include/openssl/rand.h b/crypto/openssl_mbedtls_wrapper/include/openssl/rand.h deleted file mode 100644 index 51dc428ae..000000000 --- a/crypto/openssl_mbedtls_wrapper/include/openssl/rand.h +++ /dev/null @@ -1,42 +0,0 @@ -/**************************************************************************** - * apps/crypto/openssl_mbedtls_wrapper/include/openssl/rand.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - ****************************************************************************/ - -#ifndef OPENSSL_MBEDTLS_WRAPPER_RAND_H -#define OPENSSL_MBEDTLS_WRAPPER_RAND_H - -#ifdef __cplusplus -extern "C" -{ -#endif - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -int RAND_bytes(unsigned char *buf, int num); - -void RAND_add(const void *buf, int num, double randomness); - -#ifdef __cplusplus -} -#endif - -#endif /* OPENSSL_MBEDTLS_WRAPPER_RAND_H */ diff --git a/crypto/openssl_mbedtls_wrapper/include/openssl/rsa.h b/crypto/openssl_mbedtls_wrapper/include/openssl/rsa.h deleted file mode 100644 index 4c5655deb..000000000 --- a/crypto/openssl_mbedtls_wrapper/include/openssl/rsa.h +++ /dev/null @@ -1,142 +0,0 @@ -/**************************************************************************** - * apps/crypto/openssl_mbedtls_wrapper/include/openssl/rsa.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - ****************************************************************************/ - -#ifndef OPENSSL_MBEDTLS_WRAPPER_RSA_H -#define OPENSSL_MBEDTLS_WRAPPER_RSA_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <openssl/base.h> -#include <openssl/engine.h> -#include <openssl/ex_data.h> - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define RSA_PKCS1_PADDING 1 -#define RSA_FLAG_OPAQUE 1 -#define RSA_NO_PADDING 3 -#define RSA_PKCS1_OAEP_PADDING 4 -#define RSA_PKCS1_PSS_PADDING 6 - -#ifdef __cplusplus -extern "C" -{ -#endif - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -struct rsa_meth_st -{ - struct openssl_method_common_st common; - - void *app_data; - - int (*init)(RSA *rsa); - int (*finish)(RSA *rsa); - - /* size returns the size of the RSA modulus in bytes. */ - - size_t (*size)(const RSA *rsa); - - int (*sign)(int type, const uint8_t *m, - unsigned int m_length, uint8_t *sigret, - unsigned int *siglen, const RSA *rsa); - - /* These functions mirror the |RSA_*| functions of the same name. */ - - int (*sign_raw)(RSA *rsa, size_t *out_len, - uint8_t *out, size_t max_out, - const uint8_t *in, size_t in_len, - int padding); - int (*decrypt)(RSA *rsa, size_t *out_len, - uint8_t *out, size_t max_out, - const uint8_t *in, size_t in_len, - int padding); - - /* private_transform takes a big-endian integer from |in|, calculates the - * d'th power of it, modulo the RSA modulus and writes the result as a - * big-endian integer to |out|. Both |in| and |out| are |len| bytes long - * and |len| is always equal to |RSA_size(rsa)|. If the result of - * the transform can be represented in fewer than |len| bytes, - * then |out| must be zero padded on the left. - * - * It returns one on success and zero otherwise. - * - * RSA decrypt and sign operations will call this, - * thus an ENGINE might wish - * to override it in order to avoid having to implement the padding - * functionality demanded by those, higher level, operations. - */ - - int (*private_transform)(RSA *rsa, uint8_t *out, - const uint8_t *in, size_t len); - - int flags; -}; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -RSA *RSA_new(void); - -void RSA_free(RSA *a); - -unsigned RSA_size(const RSA *rsa); - -const BIGNUM *RSA_get0_e(const RSA *rsa); - -const BIGNUM *RSA_get0_n(const RSA *rsa); - -int RSA_generate_key_ex(RSA *rsa, int bits, - const BIGNUM *e, BN_GENCB *cb); - -int RSA_get_ex_new_index(long argl, void *argp, - CRYPTO_EX_unused *unused, - CRYPTO_EX_dup *dup_unused, - CRYPTO_EX_free *free_func); - -RSA *RSA_new_method(const ENGINE *engine); - -int RSA_set_ex_data(RSA *rsa, int idx, void *arg); - -void *RSA_get_ex_data(const RSA *rsa, int idx); - -int RSA_set0_key(RSA *rsa, BIGNUM *n, BIGNUM *e, BIGNUM *d); - -int RSA_private_encrypt(size_t flen, const uint8_t *from, - uint8_t *to, RSA *rsa, int padding); - -int RSA_public_decrypt(size_t flen, const uint8_t *from, - uint8_t *to, RSA *rsa, int padding); - -#ifdef __cplusplus -} -#endif - -#endif /* OPENSSL_MBEDTLS_WRAPPER_RSA_H */ - diff --git a/crypto/openssl_mbedtls_wrapper/include/openssl/sha.h b/crypto/openssl_mbedtls_wrapper/include/openssl/sha.h deleted file mode 100644 index c2577319f..000000000 --- a/crypto/openssl_mbedtls_wrapper/include/openssl/sha.h +++ /dev/null @@ -1,131 +0,0 @@ -/**************************************************************************** - * apps/crypto/openssl_mbedtls_wrapper/include/openssl/sha.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - ****************************************************************************/ - -#ifndef OPENSSL_MBEDTLS_WRAPPER_SHA_H -#define OPENSSL_MBEDTLS_WRAPPER_SHA_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <openssl/base.h> - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* SHA256_DIGEST_LENGTH is the length of a SHA-256 digest */ - -#define SHA256_DIGEST_LENGTH 32 - -/* SHA_CBLOCK is the block size of SHA-1. */ - -#define SHA_CBLOCK 64 - -/* SHA_DIGEST_LENGTH is the length of a SHA-1 digest. */ - -#define SHA_DIGEST_LENGTH 20 - -#define SHA256_CBLOCK 64 - -#ifdef __cplusplus -extern "C" -{ -#endif - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -struct sha_state_st -{ - /* wpa_supplicant accesses |h0|..|h4| so we must support those names - * for compatibility with it until it can be updated. - */ - - union - { - uint32_t h[5]; - struct - { - uint32_t h0; - uint32_t h1; - uint32_t h2; - uint32_t h3; - uint32_t h4; - }; - }; - uint32_t Nl; - uint32_t Nh; - uint8_t data[SHA_CBLOCK]; - unsigned num; -}; - -struct sha256_state_st -{ - uint32_t h[8]; - uint32_t Nl; - uint32_t Nh; - uint8_t data[SHA256_CBLOCK]; - unsigned num; - unsigned md_len; -}; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/* SHA1_Init initialises |sha| and returns one. */ - -int SHA1_Init(SHA_CTX *sha); - -/* SHA1_Update adds |len| bytes from |data| to |sha| and returns one. */ - -int SHA1_Update(SHA_CTX *sha, const void *data, size_t len); - -/* SHA1_Final adds the final padding to |sha| and writes the - * resulting digest to |out|, which must have at least - * |SHA_DIGEST_LENGTH| bytes of space. It returns one. - */ - -int SHA1_Final(uint8_t out[SHA_DIGEST_LENGTH], SHA_CTX *sha); - -/* SHA1 writes the digest of |len| bytes from |data| to |out| and returns - * |out|. There must be at least |SHA_DIGEST_LENGTH| bytes of space in - * |out|. - */ - -uint8_t *SHA1(const uint8_t *data, size_t len, - uint8_t out[SHA_DIGEST_LENGTH]); - -void SHA1_Transform(SHA_CTX *sha, const uint8_t block[SHA_CBLOCK]); - -int SHA256_Init(SHA256_CTX *sha); - -int SHA256_Update(SHA256_CTX *sha, const void *data, size_t len); - -int SHA256_Final(uint8_t out[SHA256_DIGEST_LENGTH], SHA256_CTX *sha); - -#ifdef __cplusplus -} -#endif - -#endif /* OPENSSL_MBEDTLS_WRAPPER_SHA_H */ diff --git a/crypto/openssl_mbedtls_wrapper/include/openssl/ssl.h b/crypto/openssl_mbedtls_wrapper/include/openssl/ssl.h deleted file mode 100644 index d9b2298b9..000000000 --- a/crypto/openssl_mbedtls_wrapper/include/openssl/ssl.h +++ /dev/null @@ -1,468 +0,0 @@ -/**************************************************************************** - * apps/crypto/openssl_mbedtls_wrapper/include/openssl/ssl.h - * - * SPDX-License-Identifier: Apache-2.0 - * SPDX-FileCopyrightText: 2015-2016 Espressif Systems (Shanghai) PTE LTD - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - ****************************************************************************/ - -#ifndef OPENSSL_MBEDTLS_WRAPPER_SSL_H -#define OPENSSL_MBEDTLS_WRAPPER_SSL_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <stddef.h> -#include <openssl/ex_data.h> -#include <openssl/types.h> -#include <openssl/x509.h> -#include <openssl/x509_vfy.h> -#include <openssl/tls1.h> - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* Used in SSL_set_shutdown()/SSL_get_shutdown(); */ -#define SSL_SENT_SHUTDOWN 1 -#define SSL_RECEIVED_SHUTDOWN 2 - -#define SSL_VERIFY_NONE 0x00 -#define SSL_VERIFY_PEER 0x01 -#define SSL_VERIFY_FAIL_IF_NO_PEER_CERT 0x02 -#define SSL_VERIFY_CLIENT_ONCE 0x04 - -/* The following 3 states are kept in ssl->rlayer.rstate when reads fail, you - * should not need these - */ -#define SSL_ST_READ_HEADER 0xF0 -#define SSL_ST_READ_BODY 0xF1 -#define SSL_ST_READ_DONE 0xF2 - -#define SSL_NOTHING 1 -#define SSL_WRITING 2 -#define SSL_READING 3 -#define SSL_X509_LOOKUP 4 -#define SSL_ASYNC_PAUSED 5 -#define SSL_ASYNC_NO_JOBS 6 - -#define SSL_ERROR_NONE 0 -#define SSL_ERROR_SSL 1 -#define SSL_ERROR_WANT_READ 2 -#define SSL_ERROR_WANT_WRITE 3 -#define SSL_ERROR_WANT_X509_LOOKUP 4 -#define SSL_ERROR_SYSCALL 5 /* look at error stack/return value/errno */ -#define SSL_ERROR_ZERO_RETURN 6 -#define SSL_ERROR_WANT_CONNECT 7 -#define SSL_ERROR_WANT_ACCEPT 8 -#define SSL_ERROR_WANT_ASYNC 9 -#define SSL_ERROR_WANT_ASYNC_JOB 10 - -#define SSL_ST_CONNECT 0x1000 -#define SSL_ST_ACCEPT 0x2000 - -#define SSL_ST_MASK 0x0FFF - -#define SSL_CB_LOOP 0x01 -#define SSL_CB_EXIT 0x02 -#define SSL_CB_READ 0x04 -#define SSL_CB_WRITE 0x08 -#define SSL_CB_ALERT 0x4000 /* used in callback */ -#define SSL_CB_READ_ALERT (SSL_CB_ALERT | SSL_CB_READ) -#define SSL_CB_WRITE_ALERT (SSL_CB_ALERT | SSL_CB_WRITE) -#define SSL_CB_ACCEPT_LOOP (SSL_ST_ACCEPT | SSL_CB_LOOP) -#define SSL_CB_ACCEPT_EXIT (SSL_ST_ACCEPT | SSL_CB_EXIT) -#define SSL_CB_CONNECT_LOOP (SSL_ST_CONNECT | SSL_CB_LOOP) -#define SSL_CB_CONNECT_EXIT (SSL_ST_CONNECT | SSL_CB_EXIT) -#define SSL_CB_HANDSHAKE_START 0x10 -#define SSL_CB_HANDSHAKE_DONE 0x20 - -#define SSL_FILETYPE_ASN1 X509_FILETYPE_ASN1 -#define SSL_FILETYPE_PEM X509_FILETYPE_PEM - -/* Allow SSL_write(..., n) to return r with 0 < r < n (i.e. report success - * when just a single record has been written): - */ - -#define SSL_MODE_ENABLE_PARTIAL_WRITE 0x00000001U - -/* Make it possible to retry SSL_write() with changed buffer location (buffer - * contents must stay the same!); this is not the default to avoid the - * misconception that non-blocking SSL_write() behaves like non-blocking - * write(): - */ - -#define SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER 0x00000002U - -#define SSLEAY_VERSION 0 -#define SSLEAY_CFLAGS 1 -#define SSLEAY_BUILT_ON 2 -#define SSLEAY_PLATFORM 3 -#define SSLEAY_DIR 4 - -#define SSL2_VERSION 0x0002 - -#define SSL2_MT_CLIENT_HELLO 1 - -#define SSLv23_client_method TLS_client_method -#define SSL_library_init() 1 -#define SSL_load_error_strings() - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -typedef unsigned int (*SSL_psk_client_cb_func)(SSL *ssl, - const char *hint, - char *identity, - unsigned int max_identity_len, - unsigned char *psk, - unsigned int max_psk_len); - -typedef void (*ossl_msg_cb)( - int write_p, int version, int content_type, - const void *buf, size_t len, SSL *ssl, void *arg); - -typedef enum -{ - TLS_ST_BEFORE, - TLS_ST_OK, - DTLS_ST_CR_HELLO_VERIFY_REQUEST, - TLS_ST_CR_SRVR_HELLO, - TLS_ST_CR_CERT, - TLS_ST_CR_COMP_CERT, - TLS_ST_CR_CERT_STATUS, - TLS_ST_CR_KEY_EXCH, - TLS_ST_CR_CERT_REQ, - TLS_ST_CR_SRVR_DONE, - TLS_ST_CR_SESSION_TICKET, - TLS_ST_CR_CHANGE, - TLS_ST_CR_FINISHED, - TLS_ST_CW_CLNT_HELLO, - TLS_ST_CW_CERT, - TLS_ST_CW_COMP_CERT, - TLS_ST_CW_KEY_EXCH, - TLS_ST_CW_CERT_VRFY, - TLS_ST_CW_CHANGE, - TLS_ST_CW_NEXT_PROTO, - TLS_ST_CW_FINISHED, - TLS_ST_SW_HELLO_REQ, - TLS_ST_SR_CLNT_HELLO, - DTLS_ST_SW_HELLO_VERIFY_REQUEST, - TLS_ST_SW_SRVR_HELLO, - TLS_ST_SW_CERT, - TLS_ST_SW_COMP_CERT, - TLS_ST_SW_KEY_EXCH, - TLS_ST_SW_CERT_REQ, - TLS_ST_SW_SRVR_DONE, - TLS_ST_SR_CERT, - TLS_ST_SR_COMP_CERT, - TLS_ST_SR_KEY_EXCH, - TLS_ST_SR_CERT_VRFY, - TLS_ST_SR_NEXT_PROTO, - TLS_ST_SR_CHANGE, - TLS_ST_SR_FINISHED, - TLS_ST_SW_SESSION_TICKET, - TLS_ST_SW_CERT_STATUS, - TLS_ST_SW_CHANGE, - TLS_ST_SW_FINISHED, - TLS_ST_SW_ENCRYPTED_EXTENSIONS, - TLS_ST_CR_ENCRYPTED_EXTENSIONS, - TLS_ST_CR_CERT_VRFY, - TLS_ST_SW_CERT_VRFY, - TLS_ST_CR_HELLO_REQ, - TLS_ST_SW_KEY_UPDATE, - TLS_ST_CW_KEY_UPDATE, - TLS_ST_SR_KEY_UPDATE, - TLS_ST_CR_KEY_UPDATE, - TLS_ST_EARLY_DATA, - TLS_ST_PENDING_EARLY_DATA_END, - TLS_ST_CW_END_OF_EARLY_DATA, - TLS_ST_SR_END_OF_EARLY_DATA -} -OSSL_HANDSHAKE_STATE; - -#ifdef __cplusplus -extern "C" -{ -#endif - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -X509_VERIFY_PARAM *SSL_get0_param(SSL *ssl); - -int X509_VERIFY_PARAM_set_hostflags(X509_VERIFY_PARAM *param, - unsigned long flags); - -int X509_VERIFY_PARAM_clear_hostflags(X509_VERIFY_PARAM *param, - unsigned long flags); - -int SSL_CTX_add_client_CA(SSL_CTX *ctx, X509 *x); - -int SSL_CTX_add_client_CA_ASN1(SSL_CTX *ssl, int len, - const unsigned char *d); - -int SSL_CTX_use_certificate(SSL_CTX *ctx, X509 *x); - -int SSL_use_certificate(SSL *ssl, X509 *x); - -X509 *SSL_get_certificate(const SSL *ssl); - -int SSL_CTX_use_certificate_ASN1(SSL_CTX *ctx, int len, - const unsigned char *d); - -int SSL_use_certificate_ASN1(SSL *ssl, const unsigned char *d, int len); - -int SSL_CTX_use_certificate_file(SSL_CTX *ctx, const char *file, int type); - -int SSL_CTX_use_certificate_chain_file(SSL_CTX *ctx, const char *file); - -int SSL_use_certificate_file(SSL *ssl, const char *file, int type); - -X509 *SSL_get_peer_certificate(const SSL *ssl); - -int SSL_want(const SSL *ssl); - -int SSL_want_nothing(const SSL *ssl); - -int SSL_want_read(const SSL *ssl); - -int SSL_want_write(const SSL *ssl); - -int SSL_want_x509_lookup(const SSL *ssl); - -void _ssl_set_alpn_list(const SSL *ssl); - -int SSL_get_error(const SSL *ssl, int ret_code); - -OSSL_HANDSHAKE_STATE SSL_get_state(const SSL *ssl); - -SSL_CTX *SSL_CTX_new(const SSL_METHOD *method); - -void SSL_CTX_free(SSL_CTX *ctx); - -int SSL_CTX_set_ssl_version(SSL_CTX *ctx, const SSL_METHOD *meth); - -const SSL_METHOD *SSL_CTX_get_ssl_method(SSL_CTX *ctx); - -SSL *SSL_new(SSL_CTX *ctx); - -void SSL_free(SSL *ssl); - -int SSL_do_handshake(SSL *ssl); - -int SSL_connect(SSL *ssl); - -int SSL_accept(SSL *ssl); - -int SSL_shutdown(SSL *ssl); - -int SSL_clear(SSL *ssl); - -int SSL_read(SSL *ssl, void *buffer, int len); - -int SSL_write(SSL *ssl, const void *buffer, int len); - -SSL_CTX *SSL_get_SSL_CTX(const SSL *ssl); - -const SSL_METHOD *SSL_get_ssl_method(SSL *ssl); - -int SSL_set_ssl_method(SSL *ssl, const SSL_METHOD *method); - -int SSL_get_shutdown(const SSL *ssl); - -void SSL_set_shutdown(SSL *ssl, int mode); - -int SSL_pending(const SSL *ssl); - -int SSL_has_pending(const SSL *ssl); - -unsigned long SSL_CTX_clear_options(SSL_CTX *ctx, unsigned long op); - -unsigned long SSL_CTX_get_options(SSL_CTX *ctx); - -unsigned long SSL_clear_options(SSL *ssl, unsigned long op); - -unsigned long SSL_get_options(SSL *ssl); - -unsigned long SSL_set_options(SSL *ssl, unsigned long op); - -int SSL_get_fd(const SSL *ssl); - -int SSL_get_rfd(const SSL *ssl); - -int SSL_get_wfd(const SSL *ssl); - -int SSL_set_fd(SSL *ssl, int fd); - -int SSL_set_rfd(SSL *ssl, int fd); - -int SSL_set_wfd(SSL *ssl, int fd); - -int SSL_version(const SSL *ssl); - -const char *SSL_alert_type_string(int value); - -void SSL_CTX_set_default_read_buffer_len(SSL_CTX *ctx, size_t len); - -void SSL_set_default_read_buffer_len(SSL *ssl, size_t len); - -void SSL_set_info_callback(SSL *ssl, - void (*cb) (const SSL *ssl, int type, int val)); - -int SSL_CTX_up_ref(SSL_CTX *ctx); - -void SSL_set_security_level(SSL *ssl, int level); - -int SSL_get_security_level(const SSL *ssl); - -int SSL_CTX_get_verify_mode(const SSL_CTX *ctx); - -long SSL_CTX_set_timeout(SSL_CTX *ctx, long t); - -long SSL_CTX_get_timeout(const SSL_CTX *ctx); - -void SSL_set_read_ahead(SSL *ssl, int yes); - -void SSL_CTX_set_read_ahead(SSL_CTX *ctx, int yes); - -int SSL_get_read_ahead(const SSL *ssl); - -long SSL_CTX_get_read_ahead(SSL_CTX *ctx); - -long SSL_CTX_get_default_read_ahead(SSL_CTX *ctx); - -long SSL_set_time(SSL *ssl, long t); - -long SSL_set_timeout(SSL *ssl, long t); - -long SSL_get_verify_result(const SSL *ssl); - -int SSL_CTX_get_verify_depth(const SSL_CTX *ctx); - -void SSL_CTX_set_verify_depth(SSL_CTX *ctx, int depth); - -int SSL_get_verify_depth(const SSL *ssl); - -void SSL_set_verify_depth(SSL *ssl, int depth); - -void SSL_CTX_set_verify(SSL_CTX *ctx, int mode, - int (*verify_callback)(int, X509_STORE_CTX *)); - -void SSL_set_verify(SSL *ssl, int mode, - int (*verify_callback)(int, X509_STORE_CTX *)); - -void *SSL_CTX_get_ex_data(const SSL_CTX *ctx, int idx); - -void SSL_CTX_set_alpn_select_cb(SSL_CTX *ctx, next_proto_cb cb, void *arg); - -void SSL_set_alpn_select_cb(SSL *ssl, void *arg); - -int SSL_CTX_use_PrivateKey(SSL_CTX *ctx, EVP_PKEY *pkey); - -int SSL_use_PrivateKey(SSL *ssl, EVP_PKEY *pkey); - -int SSL_CTX_use_PrivateKey_ASN1(int type, SSL_CTX *ctx, - const unsigned char *d, long len); - -int SSL_use_PrivateKey_ASN1(int type, SSL *ssl, - const unsigned char *d, long len); - -int SSL_CTX_use_PrivateKey_file(SSL_CTX *ctx, const char *file, int type); - -int SSL_use_PrivateKey_file(SSL_CTX *ctx, const char *file, int type); - -int SSL_CTX_use_RSAPrivateKey_ASN1(SSL_CTX *ctx, const unsigned char *d, - long len); - -const SSL_METHOD *TLS_method(void); -const SSL_METHOD *TLS_server_method(void); -const SSL_METHOD *TLS_client_method(void); - -const SSL_METHOD *TLSv1_method(void); /* TLSv1.0 */ -const SSL_METHOD *TLSv1_server_method(void); -const SSL_METHOD *TLSv1_client_method(void); - -const SSL_METHOD *TLSv1_1_method(void); /* TLSv1.1 */ -const SSL_METHOD *TLSv1_1_server_method(void); -const SSL_METHOD *TLSv1_1_client_method(void); - -const SSL_METHOD *TLSv1_2_method(void); /* TLSv1.2 */ -const SSL_METHOD *TLSv1_2_server_method(void); -const SSL_METHOD *TLSv1_2_client_method(void); - -SSL_SESSION *SSL_get1_session(SSL *ssl); - -void SSL_SESSION_free(SSL_SESSION *session); - -int SSL_set_session(SSL *s, SSL_SESSION *session); - -const char *SSLeay_version(int t); - -const char *SSL_state_string_long(const SSL *s); - -const char *SSL_get_cipher_name(const SSL *s); - -const char *SSL_alert_type_string_long(int value); - -const char *SSL_alert_desc_string_long(int value); - -void SSL_CTX_set_default_passwd_cb(SSL_CTX *ctx, pem_password_cb *cb); - -void SSL_CTX_set_default_passwd_cb_userdata(SSL_CTX *ctx, void *u); - -int SSL_CTX_set_default_verify_paths(SSL_CTX *ctx); - -void SSL_CTX_set_psk_client_callback(SSL_CTX *ctx, - SSL_psk_client_cb_func cb); - -long SSL_CTX_set_mode(SSL_CTX *ctx, long larg); - -void SSL_CTX_set_info_callback(SSL_CTX *ctx, - void (*cb)(const SSL *ssl, int type, int val)); - -void SSL_CTX_set_msg_callback(SSL_CTX *ctx, - void (*cb)(int write_p, int version, - int content_type, const void *buf, - size_t len, SSL *ssl, void *arg)); - -const char *SSL_get_cipher_list(const SSL *s, int n); - -long SSL_set_tlsext_host_name(SSL *s, void *parg); - -int SSL_get_ex_new_index(long argl, void *argp, - CRYPTO_EX_new *new_func, CRYPTO_EX_dup *dup_func, - CRYPTO_EX_free *free_func); - -const char *SSL_get_cipher_list(const SSL *s, int n); - -int SSL_CTX_set_cipher_list(SSL_CTX *ctx, const char *str); - -int SSL_CTX_set_ex_data(SSL_CTX *s, int idx, void *arg); - -int SSL_CTX_load_verify_file(SSL_CTX *ctx, const char *CAfile); - -int SSL_CTX_load_verify_dir(SSL_CTX *ctx, const char *CApath); - -int SSL_CTX_load_verify_locations(SSL_CTX *ctx, const char *CAfile, - const char *CApath); - -#ifdef __cplusplus -} -#endif - -#endif /* OPENSSL_MBEDTLS_WRAPPER_SSL_H */ diff --git a/crypto/openssl_mbedtls_wrapper/include/openssl/ssl3.h b/crypto/openssl_mbedtls_wrapper/include/openssl/ssl3.h deleted file mode 100644 index 8e2806379..000000000 --- a/crypto/openssl_mbedtls_wrapper/include/openssl/ssl3.h +++ /dev/null @@ -1,50 +0,0 @@ -/**************************************************************************** - * apps/crypto/openssl_mbedtls_wrapper/include/openssl/ssl3.h - * - * SPDX-License-Identifier: Apache-2.0 - * SPDX-FileCopyrightText: 2015-2016 Espressif Systems (Shanghai) PTE LTD - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - ****************************************************************************/ - -#ifndef OPENSSL_MBEDTLS_WRAPPER_SSL_SSL3_H -#define OPENSSL_MBEDTLS_WRAPPER_SSL_SSL3_H - -#ifdef __cplusplus -extern "C" -{ -#endif - -#define SSL3_AD_CLOSE_NOTIFY 0 -#define SSL3_AD_UNEXPECTED_MESSAGE 10/* fatal */ -#define SSL3_AD_BAD_RECORD_MAC 20/* fatal */ -#define SSL3_AD_DECOMPRESSION_FAILURE 30/* fatal */ -#define SSL3_AD_HANDSHAKE_FAILURE 40/* fatal */ -#define SSL3_AD_NO_CERTIFICATE 41 -#define SSL3_AD_BAD_CERTIFICATE 42 -#define SSL3_AD_UNSUPPORTED_CERTIFICATE 43 -#define SSL3_AD_CERTIFICATE_REVOKED 44 -#define SSL3_AD_CERTIFICATE_EXPIRED 45 -#define SSL3_AD_CERTIFICATE_UNKNOWN 46 -#define SSL3_AD_ILLEGAL_PARAMETER 47/* fatal */ - -#define SSL3_AL_WARNING 1 -#define SSL3_AL_FATAL 2 - -#define SSL3_VERSION 0x0300 - -#ifdef __cplusplus -} -#endif - -#endif /* OPENSSL_MBEDTLS_WRAPPER_SSL_SSL3_H */ diff --git a/crypto/openssl_mbedtls_wrapper/include/openssl/ssl_dbg.h b/crypto/openssl_mbedtls_wrapper/include/openssl/ssl_dbg.h deleted file mode 100644 index 84fc7ac62..000000000 --- a/crypto/openssl_mbedtls_wrapper/include/openssl/ssl_dbg.h +++ /dev/null @@ -1,212 +0,0 @@ -/**************************************************************************** - * apps/crypto/openssl_mbedtls_wrapper/include/openssl/ssl_dbg.h - * - * SPDX-License-Identifier: Apache-2.0 - * SPDX-FileCopyrightText: 2015-2016 Espressif Systems (Shanghai) PTE LTD - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - ****************************************************************************/ - -#ifndef OPENSSL_MBEDTLS_WRAPPER_SSL_DBG_H -#define OPENSSL_MBEDTLS_WRAPPER_SSL_DBG_H - -#ifdef __cplusplus -extern "C" -{ -#endif - -#ifdef CONFIG_OPENSSL_DEBUG_LEVEL -# define SSL_DEBUG_LEVEL CONFIG_OPENSSL_DEBUG_LEVEL -#else -# define SSL_DEBUG_LEVEL 0 -#endif - -#define SSL_DEBUG_ON (SSL_DEBUG_LEVEL + 1) -#define SSL_DEBUG_OFF (SSL_DEBUG_LEVEL - 1) - -#ifdef CONFIG_OPENSSL_DEBUG -# ifndef SSL_DEBUG_LOG -# error "SSL_DEBUG_LOG is not defined" -# endif - -# ifndef SSL_DEBUG_FL -# define SSL_DEBUG_FL "\n" -# endif - -# define SSL_SHOW_LOCATION() \ - SSL_DEBUG_LOG("SSL assert : %s %d\n", \ - __FILE__, __LINE__) - -# define SSL_DEBUG(level, fmt, ...) \ -{ \ - if (level > SSL_DEBUG_LEVEL) \ - { \ - SSL_DEBUG_LOG(fmt SSL_DEBUG_FL, ##__VA_ARGS__); \ - } \ -} -#else /* CONFIG_OPENSSL_DEBUG */ -# define SSL_SHOW_LOCATION() - -# define SSL_DEBUG(level, fmt, ...) -#endif /* CONFIG_OPENSSL_DEBUG */ - -/* OpenSSL assert function - * - * if select "CONFIG_OPENSSL_ASSERT_DEBUG", SSL_ASSERT* will show error - * file name and line - * if select "CONFIG_OPENSSL_ASSERT_EXIT", SSL_ASSERT* will just return - * error code. - * if select "CONFIG_OPENSSL_ASSERT_DEBUG_EXIT" SSL_ASSERT* will show error - * file name and line, then return error code. - * if select "CONFIG_OPENSSL_ASSERT_DEBUG_BLOCK", SSL_ASSERT* will show error - * file name and line, then block here with "while (1)" - * - * SSL_ASSERT1 may will return "-1", so function's return argument is - * integer. - * SSL_ASSERT2 may will return "NULL", so function's return argument is a - * point. - * SSL_ASSERT2 may will return nothing, so function's return argument is - * "void". - */ - -#if defined(CONFIG_OPENSSL_ASSERT_DEBUG) -# define SSL_ASSERT1(s) \ -{ \ - if (!(s)) \ - { \ - SSL_SHOW_LOCATION(); \ - } \ -} - -# define SSL_ASSERT2(s) \ -{ \ - if (!(s)) \ - { \ - SSL_SHOW_LOCATION(); \ - } \ -} - -# define SSL_ASSERT3(s) \ -{ \ - if (!(s)) \ - { \ - SSL_SHOW_LOCATION(); \ - } \ -} -#elif defined(CONFIG_OPENSSL_ASSERT_EXIT) -# define SSL_ASSERT1(s) \ -{ \ - if (!(s)) \ - { \ - return -1; \ - } \ -} - -# define SSL_ASSERT2(s) \ -{ \ - if (!(s)) \ - { \ - return NULL; \ - } \ -} - -# define SSL_ASSERT3(s) \ -{ \ - if (!(s)) \ - { \ - return ; \ - } \ -} -#elif defined(CONFIG_OPENSSL_ASSERT_DEBUG_EXIT) -# define SSL_ASSERT1(s) \ -{ \ - if (!(s)) \ - { \ - SSL_SHOW_LOCATION(); \ - return -1; \ - } \ -} - -# define SSL_ASSERT2(s) \ -{ \ - if (!(s)) \ - { \ - SSL_SHOW_LOCATION(); \ - return NULL; \ - } \ -} - -# define SSL_ASSERT3(s) \ -{ \ - if (!(s)) \ - { \ - SSL_SHOW_LOCATION(); \ - return ; \ - } \ -} -#elif defined(CONFIG_OPENSSL_ASSERT_DEBUG_BLOCK) -# define SSL_ASSERT1(s) \ -{ \ - if (!(s)) \ - { \ - SSL_SHOW_LOCATION(); \ - while (1); \ - } \ -} - -# define SSL_ASSERT2(s) \ -{ \ - if (!(s)) \ - { \ - SSL_SHOW_LOCATION(); \ - while (1); \ - } \ -} - -# define SSL_ASSERT3(s) \ -{ \ - if (!(s)) \ - { \ - SSL_SHOW_LOCATION(); \ - while (1); \ - } \ -} -#else -# define SSL_ASSERT1(s) -# define SSL_ASSERT2(s) -# define SSL_ASSERT3(s) -#endif - -#define SSL_PLATFORM_DEBUG_LEVEL SSL_DEBUG_OFF -#define SSL_PLATFORM_ERROR_LEVEL SSL_DEBUG_ON - -#define SSL_CERT_DEBUG_LEVEL SSL_DEBUG_OFF -#define SSL_CERT_ERROR_LEVEL SSL_DEBUG_ON - -#define SSL_PKEY_DEBUG_LEVEL SSL_DEBUG_OFF -#define SSL_PKEY_ERROR_LEVEL SSL_DEBUG_ON - -#define SSL_X509_DEBUG_LEVEL SSL_DEBUG_OFF -#define SSL_X509_ERROR_LEVEL SSL_DEBUG_ON - -#define SSL_LIB_DEBUG_LEVEL SSL_DEBUG_OFF -#define SSL_LIB_ERROR_LEVEL SSL_DEBUG_ON - -#define SSL_STACK_DEBUG_LEVEL SSL_DEBUG_OFF -#define SSL_STACK_ERROR_LEVEL SSL_DEBUG_ON - -#ifdef __cplusplus -} -#endif - -#endif /* OPENSSL_MBEDTLS_WRAPPER_SSL_DBG_H */ diff --git a/crypto/openssl_mbedtls_wrapper/include/openssl/ssl_local.h b/crypto/openssl_mbedtls_wrapper/include/openssl/ssl_local.h deleted file mode 100644 index 053da27de..000000000 --- a/crypto/openssl_mbedtls_wrapper/include/openssl/ssl_local.h +++ /dev/null @@ -1,179 +0,0 @@ -/**************************************************************************** - * apps/crypto/openssl_mbedtls_wrapper/include/openssl/ssl_local.h - * - * SPDX-License-Identifier: Apache-2.0 - * SPDX-FileCopyrightText: 2015-2016 Espressif Systems (Shanghai) PTE LTD - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - ****************************************************************************/ - -#ifndef OPENSSL_MBEDTLS_WRAPPER_SSL_LOCAL_H -#define OPENSSL_MBEDTLS_WRAPPER_SSL_LOCAL_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <openssl/ssl.h> -#include <openssl/statem.h> -#include <openssl/x509.h> -#include <openssl/x509_local.h> -#include <openssl/x509_vfy.h> - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -struct record_layer_st -{ - int rstate; - int read_ahead; -}; - -struct ssl_ctx_st -{ - int version; - int references; - unsigned long options; - const SSL_METHOD *method; - CERT *cert; - X509 *client_CA; - const char **alpn_protos; - next_proto_cb alpn_cb; - int verify_mode; - int (*default_verify_callback) (int ok, X509_STORE_CTX *ctx); - long session_timeout; - int read_ahead; - int read_buffer_len; - X509_VERIFY_PARAM param; - - /* Default password callback. */ - - pem_password_cb *default_passwd_callback; - - /* Default password callback user data. */ - - void *default_passwd_callback_userdata; - uint32_t mode; - - /* optional informational callback */ - - void (*info_callback)(const SSL *ssl, int type, int val); - - /* callback that allows applications to peek at protocol messages */ - - ossl_msg_cb msg_callback; - SSL_psk_client_cb_func psk_client_callback; -}; - -struct ssl_method_func_st -{ - int (*ssl_new)(SSL *ssl); - void (*ssl_free)(SSL *ssl); - int (*ssl_handshake)(SSL *ssl); - int (*ssl_shutdown)(SSL *ssl); - int (*ssl_clear)(SSL *ssl); - int (*ssl_read)(SSL *ssl, void *buffer, int len); - int (*ssl_send)(SSL *ssl, const void *buffer, int len); - int (*ssl_pending)(const SSL *ssl); - void (*ssl_set_fd)(SSL *ssl, int fd, int mode); - int (*ssl_get_fd)(const SSL *ssl, int mode); - void (*ssl_set_bufflen)(SSL *ssl, int len); - long (*ssl_get_verify_result)(const SSL *ssl); - OSSL_HANDSHAKE_STATE (*ssl_get_state)(const SSL *ssl); -}; - -struct ssl_method_st -{ - /* protocol version(one of SSL3.0, TLS1.0, etc.) */ - - int version; - - /* SSL mode(client(0) , server(1), not known(-1)) */ - - int endpoint; - const SSL_METHOD_FUNC *func; -}; - -struct ssl_session_st -{ - long timeout; - long time; - X509 *peer; - const SSL_CIPHER *cipher; - int references; - struct - { - char hostname[TLSEXT_MAXLEN_host_name]; - } ext; -}; - -struct ssl_st -{ - /* protocol version(one of SSL3.0, TLS1.0, etc.) */ - - int version; - unsigned long options; - - /* shut things down(0x01 : sent, 0x02 : received) */ - - int shutdown; - CERT *cert; - X509 *client_CA; - SSL_CTX *ctx; - const SSL_METHOD *method; - const char **alpn_protos; - RECORD_LAYER rlayer; - - /* where we are */ - - OSSL_STATEM statem; - SSL_SESSION *session; - int verify_mode; - int (*verify_callback) (int ok, X509_STORE_CTX *ctx); - int rwstate; - int interrupted_remaining_write; - long verify_result; - X509_VERIFY_PARAM param; - int err; - void (*info_callback) (const SSL *ssl, int type, int val); - - /* SSL low-level system arch point */ - - void *ssl_pm; - SSL_CIPHER *cipher_list; -}; - -struct ssl_cipher_st -{ - const char *name; /* text name */ -}; - -#ifdef __cplusplus -extern "C" -{ -#endif - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -CERT *__ssl_cert_new(CERT *ic); -CERT *ssl_cert_new(void); -void ssl_cert_free(CERT *cert); - -#ifdef __cplusplus -} -#endif - -#endif /* OPENSSL_MBEDTLS_WRAPPER_SSL_LOCAL_H */ diff --git a/crypto/openssl_mbedtls_wrapper/include/openssl/stack.h b/crypto/openssl_mbedtls_wrapper/include/openssl/stack.h deleted file mode 100644 index b92138ee0..000000000 --- a/crypto/openssl_mbedtls_wrapper/include/openssl/stack.h +++ /dev/null @@ -1,59 +0,0 @@ -/**************************************************************************** - * apps/crypto/openssl_mbedtls_wrapper/include/openssl/stack.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - ****************************************************************************/ - -#ifndef OPENSSL_MBEDTLS_WRAPPER_STACK_H -#define OPENSSL_MBEDTLS_WRAPPER_STACK_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <openssl/types.h> - -#ifdef __cplusplus -extern "C" -{ -#endif - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -struct stack_st -{ - char **data; - int num_alloc; - OPENSSL_sk_compfunc c; -}; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -OPENSSL_STACK *OPENSSL_sk_new(OPENSSL_sk_compfunc c); -OPENSSL_STACK *OPENSSL_sk_new_null(void); -void OPENSSL_sk_free(OPENSSL_STACK *stack); - -#ifdef __cplusplus -} -#endif - -#endif /* OPENSSL_MBEDTLS_WRAPPER_STACK_H */ diff --git a/crypto/openssl_mbedtls_wrapper/include/openssl/statem.h b/crypto/openssl_mbedtls_wrapper/include/openssl/statem.h deleted file mode 100644 index c3f1e9406..000000000 --- a/crypto/openssl_mbedtls_wrapper/include/openssl/statem.h +++ /dev/null @@ -1,84 +0,0 @@ -/**************************************************************************** - * apps/crypto/openssl_mbedtls_wrapper/include/openssl/statem.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - ****************************************************************************/ - -#ifndef OPENSSL_MBEDTLS_WRAPPER_STATEM_H -#define OPENSSL_MBEDTLS_WRAPPER_STATEM_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <openssl/types.h> - -#ifdef __cplusplus -extern "C" -{ -#endif - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -typedef enum -{ -/* No handshake in progress */ - - MSG_FLOW_UNINITED, - -/* A permanent error with this connection */ - - MSG_FLOW_ERROR, - -/* We are about to renegotiate */ - - MSG_FLOW_RENEGOTIATE, - -/* We are reading messages */ - - MSG_FLOW_READING, - -/* We are writing messages */ - - MSG_FLOW_WRITING, - -/* Handshake has finished */ - - MSG_FLOW_FINISHED -} -MSG_FLOW_STATE; - -struct ossl_statem_st -{ - MSG_FLOW_STATE state; - int hand_state; -}; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -int ossl_statem_in_error(const SSL *ssl); - -#ifdef __cplusplus -} -#endif - -#endif /* OPENSSL_MBEDTLS_WRAPPER_STACK_H */ \ No newline at end of file diff --git a/crypto/openssl_mbedtls_wrapper/include/openssl/tls1.h b/crypto/openssl_mbedtls_wrapper/include/openssl/tls1.h deleted file mode 100644 index 6f0ff49cb..000000000 --- a/crypto/openssl_mbedtls_wrapper/include/openssl/tls1.h +++ /dev/null @@ -1,85 +0,0 @@ -/**************************************************************************** - * apps/crypto/openssl_mbedtls_wrapper/include/openssl/tls1.h - * - * SPDX-License-Identifier: Apache-2.0 - * SPDX-FileCopyrightText: 2015-2016 Espressif Systems (Shanghai) PTE LTD - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - ****************************************************************************/ - -#ifndef OPENSSL_MBEDTLS_WRAPPER_TLS1_H -#define OPENSSL_MBEDTLS_WRAPPER_TLS1_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <openssl/ssl.h> - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define TLS1_AD_DECRYPTION_FAILED 21 -#define TLS1_AD_RECORD_OVERFLOW 22 -#define TLS1_AD_UNKNOWN_CA 48 /* fatal */ -#define TLS1_AD_ACCESS_DENIED 49 /* fatal */ -#define TLS1_AD_DECODE_ERROR 50 /* fatal */ -#define TLS1_AD_DECRYPT_ERROR 51 -#define TLS1_AD_EXPORT_RESTRICTION 60 /* fatal */ -#define TLS1_AD_PROTOCOL_VERSION 70 /* fatal */ -#define TLS1_AD_INSUFFICIENT_SECURITY 71 /* fatal */ -#define TLS1_AD_INTERNAL_ERROR 80 /* fatal */ -#define TLS1_AD_INAPPROPRIATE_FALLBACK 86 /* fatal */ -#define TLS1_AD_USER_CANCELLED 90 -#define TLS1_AD_NO_RENEGOTIATION 100 - -/* codes 110-114 are from RFC3546 */ - -#define TLS1_AD_UNSUPPORTED_EXTENSION 110 -#define TLS1_AD_CERTIFICATE_UNOBTAINABLE 111 -#define TLS1_AD_UNRECOGNIZED_NAME 112 -#define TLS1_AD_BAD_CERTIFICATE_STATUS_RESPONSE 113 -#define TLS1_AD_BAD_CERTIFICATE_HASH_VALUE 114 -#define TLS1_AD_UNKNOWN_PSK_IDENTITY 115 /* fatal */ -#define TLS1_AD_NO_APPLICATION_PROTOCOL 120 /* fatal */ - -/* Special value for method supporting multiple versions */ - -#define TLS_ANY_VERSION 0x10000 - -#define TLS1_VERSION 0x0301 -#define TLS1_1_VERSION 0x0302 -#define TLS1_2_VERSION 0x0303 - -#define SSL_TLSEXT_ERR_OK 0 -#define SSL_TLSEXT_ERR_NOACK 3 - -#define TLSEXT_MAXLEN_host_name 255 - -#ifdef __cplusplus -extern "C" -{ -#endif - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -long SSL_set_tlsext_host_name(SSL *s, void *parg); - -#ifdef __cplusplus -} -#endif - -#endif /* OPENSSL_MBEDTLS_WRAPPER_TLS1_H */ diff --git a/crypto/openssl_mbedtls_wrapper/include/openssl/types.h b/crypto/openssl_mbedtls_wrapper/include/openssl/types.h deleted file mode 100644 index 294ef20f6..000000000 --- a/crypto/openssl_mbedtls_wrapper/include/openssl/types.h +++ /dev/null @@ -1,73 +0,0 @@ -/**************************************************************************** - * apps/crypto/openssl_mbedtls_wrapper/include/openssl/types.h - * - * SPDX-License-Identifier: Apache-2.0 - * SPDX-FileCopyrightText: 2015-2016 Espressif Systems (Shanghai) PTE LTD - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - ****************************************************************************/ - -#ifndef OPENSSL_MBEDTLS_WRAPPER_TYPES_H -#define OPENSSL_MBEDTLS_WRAPPER_TYPES_H - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -typedef void CRYPTO_EX_new; -typedef void CRYPTO_THREADID; -typedef void X509_STORE; -typedef void RSA; - -typedef int (*OPENSSL_sk_compfunc)(const void *, const void *); -typedef int pem_password_cb(char *buf, int size, - int rwflag, void *userdata); - -typedef struct bio_buf_mem_st BIO_BUF_MEM; -typedef struct bio_method_st BIO_METHOD; -typedef struct bio_st BIO; -typedef struct stack_st OPENSSL_STACK; -typedef struct ssl_method_st SSL_METHOD; -typedef struct ssl_method_func_st SSL_METHOD_FUNC; -typedef struct record_layer_st RECORD_LAYER; -typedef struct ossl_statem_st OSSL_STATEM; -typedef struct ssl_session_st SSL_SESSION; -typedef struct ssl_ctx_st SSL_CTX; -typedef struct ssl_st SSL; -typedef struct ssl_cipher_st SSL_CIPHER; -typedef struct cert_st CERT; -typedef struct x509_st X509; -typedef struct X509_VERIFY_PARAM_st X509_VERIFY_PARAM; -typedef struct evp_pkey_st EVP_PKEY; -typedef struct x509_method_st X509_METHOD; -typedef struct pkey_method_st PKEY_METHOD; - -#define ossl_inline inline -#define OPENSSL_NPN_NEGOTIATED 1 - -#define SSL_METHOD_CALL(f, s, ...) s->method->func->ssl_##f(s, ##__VA_ARGS__) -#define X509_METHOD_CALL(f, x, ...) x->method->x509_##f(x, ##__VA_ARGS__) -#define EVP_PKEY_METHOD_CALL(f, k, ...) k->method->pkey_##f(k, ##__VA_ARGS__) - -typedef int (*next_proto_cb)(SSL *ssl, unsigned char **out, - unsigned char *outlen, const unsigned char *in, - unsigned int inlen, void *arg); - -struct pkey_method_st -{ - int (*pkey_new)(EVP_PKEY *pkey, EVP_PKEY *m_pkey); - void (*pkey_free)(EVP_PKEY *pkey); - int (*pkey_load)(EVP_PKEY *pkey, const unsigned char *buf, int len); -}; - -#endif /* OPENSSL_MBEDTLS_WRAPPER_TYPES_H */ diff --git a/crypto/openssl_mbedtls_wrapper/include/openssl/x509.h b/crypto/openssl_mbedtls_wrapper/include/openssl/x509.h deleted file mode 100644 index cda221276..000000000 --- a/crypto/openssl_mbedtls_wrapper/include/openssl/x509.h +++ /dev/null @@ -1,156 +0,0 @@ -/**************************************************************************** - * apps/crypto/openssl_mbedtls_wrapper/include/openssl/x509.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - ****************************************************************************/ - -#ifndef OPENSSL_MBEDTLS_WRAPPER_X509_H -#define OPENSSL_MBEDTLS_WRAPPER_X509_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <stdint.h> - -#include <openssl/base.h> -#include <openssl/bytestring.h> -#include <openssl/ecdsa.h> -#include <openssl/obj.h> -#include <openssl/types.h> - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define X509_FILETYPE_PEM 1 -#define X509_FILETYPE_ASN1 2 -#define X509_FILETYPE_DEFAULT 3 - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -struct x509_st -{ - /* X509 certification platform private point */ - - void *x509_pm; - const X509_METHOD *method; -}; - -struct x509_method_st -{ - int (*x509_new)(X509 *x, X509 *m_x); - void (*x509_free)(X509 *x); - int (*x509_load)(X509 *x, const unsigned char *buf, int len); - int (*x509_load_file)(X509 *x, const char *file); - int (*x509_load_path)(X509 *x, const char *path); - int (*x509_show_info)(X509 *x); -}; - -struct cert_st -{ - int sec_level; - X509 *x509; - EVP_PKEY *pkey; -}; - -#ifdef __cplusplus -extern "C" -{ -#endif - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -void PKCS8_PRIV_KEY_INFO_free(PKCS8_PRIV_KEY_INFO *key); - -X509 *X509_new(void); - -void X509_free(X509 *a); - -void X509_ALGOR_free(X509_ALGOR *a); - -void X509_EXTENSION_free(X509_EXTENSION *a); - -void X509_NAME_free(X509_NAME *a); - -EVP_PKEY *EVP_PKCS82PKEY(const PKCS8_PRIV_KEY_INFO *p8); - -X509_ALGOR *X509_ALGOR_new(void); - -int X509_ALGOR_set0(X509_ALGOR *alg, ASN1_OBJECT *obj, - int param_type, void *param_value); - -int X509_set1_signature_algo(X509 *x509, const X509_ALGOR *algo); - -int X509_set1_signature_value(X509 *x509, const uint8_t *sig, - size_t sig_len); - -X509_NAME *X509_NAME_new(void); - -int X509_NAME_get_text_by_NID(const X509_NAME *name, int nid, - char *buf, int len); - -int X509_set_issuer_name(X509 *x509, X509_NAME *name); - -int X509_NAME_add_entry_by_txt(X509_NAME *name, const char *field, - int type, const uint8_t *bytes, - int len, int loc, int set); - -X509_NAME *d2i_X509_NAME(X509_NAME **out, const uint8_t **inp, long len); - -X509_EXTENSION *X509_EXTENSION_create_by_NID(X509_EXTENSION **ex, - int nid, int crit, - const ASN1_OCTET_STRING *data); - -int X509_set_version(X509 *x509, long version); - -int X509_set_serialNumber(X509 *x509, const ASN1_INTEGER *serial); - -int X509_set_subject_name(X509 *x509, X509_NAME *name); - -int X509_set_notBefore(X509 *x509, const ASN1_TIME *tm); - -int X509_set_notAfter(X509 *x509, const ASN1_TIME *tm); - -int X509_set_pubkey(X509 *x509, EVP_PKEY *pkey); - -int X509_add_ext(X509 *x, const X509_EXTENSION *ex, int loc); - -int X509_sign(X509 *x509, EVP_PKEY *pkey, const EVP_MD *md); - -int i2d_X509(X509 *x509, uint8_t **outp); - -PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO(PKCS8_PRIV_KEY_INFO *info, - const uint8_t **key_data, - size_t key_length); - -X509 *d2i_X509(X509 **out, const uint8_t **inp, long len); - -const char *X509_verify_cert_error_string(long n); - -X509 *__X509_new(X509 *ix); - -#ifdef __cplusplus -} -#endif - -#endif /* OPENSSL_MBEDTLS_WRAPPER_X509_H */ diff --git a/crypto/openssl_mbedtls_wrapper/include/openssl/x509_local.h b/crypto/openssl_mbedtls_wrapper/include/openssl/x509_local.h deleted file mode 100644 index 83799e9b7..000000000 --- a/crypto/openssl_mbedtls_wrapper/include/openssl/x509_local.h +++ /dev/null @@ -1,37 +0,0 @@ -/**************************************************************************** - * apps/crypto/openssl_mbedtls_wrapper/include/openssl/x509_local.h - * - * SPDX-License-Identifier: Apache-2.0 - * SPDX-FileCopyrightText: 2015-2016 Espressif Systems (Shanghai) PTE LTD - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - ****************************************************************************/ - -#ifndef OPENSSL_MBEDTLS_WRAPPER_X509_LOCAL_H -#define OPENSSL_MBEDTLS_WRAPPER_X509_LOCAL_H - -#ifdef __cplusplus -extern "C" -{ -#endif - -struct X509_VERIFY_PARAM_st -{ - int depth; -}; - -#ifdef __cplusplus -} -#endif - -#endif /* OPENSSL_MBEDTLS_WRAPPER_X509_LOCAL_H */ diff --git a/crypto/openssl_mbedtls_wrapper/include/openssl/x509_vfy.h b/crypto/openssl_mbedtls_wrapper/include/openssl/x509_vfy.h deleted file mode 100644 index 9ecf4fc27..000000000 --- a/crypto/openssl_mbedtls_wrapper/include/openssl/x509_vfy.h +++ /dev/null @@ -1,121 +0,0 @@ -/**************************************************************************** - * apps/crypto/openssl_mbedtls_wrapper/include/openssl/x509_vfy.h - * - * SPDX-License-Identifier: Apache-2.0 - * SPDX-FileCopyrightText: 2015-2016 Espressif Systems (Shanghai) PTE LTD - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - ****************************************************************************/ - -#ifndef OPENSSL_MBEDTLS_WRAPPER_X509_VFY_H -#define OPENSSL_MBEDTLS_WRAPPER_X509_VFY_H - -#ifdef __cplusplus -extern "C" -{ -#endif - -#define X509_V_OK 0 -#define X509_V_ERR_UNSPECIFIED 1 -#define X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT 2 -#define X509_V_ERR_UNABLE_TO_GET_CRL 3 -#define X509_V_ERR_UNABLE_TO_DECRYPT_CERT_SIGNATURE 4 -#define X509_V_ERR_UNABLE_TO_DECRYPT_CRL_SIGNATURE 5 -#define X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY 6 -#define X509_V_ERR_CERT_SIGNATURE_FAILURE 7 -#define X509_V_ERR_CRL_SIGNATURE_FAILURE 8 -#define X509_V_ERR_CERT_NOT_YET_VALID 9 -#define X509_V_ERR_CERT_HAS_EXPIRED 10 -#define X509_V_ERR_CRL_NOT_YET_VALID 11 -#define X509_V_ERR_CRL_HAS_EXPIRED 12 -#define X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD 13 -#define X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD 14 -#define X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD 15 -#define X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD 16 -#define X509_V_ERR_OUT_OF_MEM 17 -#define X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT 18 -#define X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN 19 -#define X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY 20 -#define X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE 21 -#define X509_V_ERR_CERT_CHAIN_TOO_LONG 22 -#define X509_V_ERR_CERT_REVOKED 23 -#define X509_V_ERR_INVALID_CA 24 -#define X509_V_ERR_PATH_LENGTH_EXCEEDED 25 -#define X509_V_ERR_INVALID_PURPOSE 26 -#define X509_V_ERR_CERT_UNTRUSTED 27 -#define X509_V_ERR_CERT_REJECTED 28 -/* These are 'informational' when looking for issuer cert */ -#define X509_V_ERR_SUBJECT_ISSUER_MISMATCH 29 -#define X509_V_ERR_AKID_SKID_MISMATCH 30 -#define X509_V_ERR_AKID_ISSUER_SERIAL_MISMATCH 31 -#define X509_V_ERR_KEYUSAGE_NO_CERTSIGN 32 -#define X509_V_ERR_UNABLE_TO_GET_CRL_ISSUER 33 -#define X509_V_ERR_UNHANDLED_CRITICAL_EXTENSION 34 -#define X509_V_ERR_KEYUSAGE_NO_CRL_SIGN 35 -#define X509_V_ERR_UNHANDLED_CRITICAL_CRL_EXTENSION 36 -#define X509_V_ERR_INVALID_NON_CA 37 -#define X509_V_ERR_PROXY_PATH_LENGTH_EXCEEDED 38 -#define X509_V_ERR_KEYUSAGE_NO_DIGITAL_SIGNATURE 39 -#define X509_V_ERR_PROXY_CERTIFICATES_NOT_ALLOWED 40 -#define X509_V_ERR_INVALID_EXTENSION 41 -#define X509_V_ERR_INVALID_POLICY_EXTENSION 42 -#define X509_V_ERR_NO_EXPLICIT_POLICY 43 -#define X509_V_ERR_DIFFERENT_CRL_SCOPE 44 -#define X509_V_ERR_UNSUPPORTED_EXTENSION_FEATURE 45 -#define X509_V_ERR_UNNESTED_RESOURCE 46 -#define X509_V_ERR_PERMITTED_VIOLATION 47 -#define X509_V_ERR_EXCLUDED_VIOLATION 48 -#define X509_V_ERR_SUBTREE_MINMAX 49 -/* The application is not happy */ -#define X509_V_ERR_APPLICATION_VERIFICATION 50 -#define X509_V_ERR_UNSUPPORTED_CONSTRAINT_TYPE 51 -#define X509_V_ERR_UNSUPPORTED_CONSTRAINT_SYNTAX 52 -#define X509_V_ERR_UNSUPPORTED_NAME_SYNTAX 53 -#define X509_V_ERR_CRL_PATH_VALIDATION_ERROR 54 -/* Another issuer check debug option */ -#define X509_V_ERR_PATH_LOOP 55 -/* Suite B mode algorithm violation */ -#define X509_V_ERR_SUITE_B_INVALID_VERSION 56 -#define X509_V_ERR_SUITE_B_INVALID_ALGORITHM 57 -#define X509_V_ERR_SUITE_B_INVALID_CURVE 58 -#define X509_V_ERR_SUITE_B_INVALID_SIGNATURE_ALGORITHM 59 -#define X509_V_ERR_SUITE_B_LOS_NOT_ALLOWED 60 -#define X509_V_ERR_SUITE_B_CANNOT_SIGN_P_384_WITH_P_256 61 -/* Host, email and IP check errors */ -#define X509_V_ERR_HOSTNAME_MISMATCH 62 -#define X509_V_ERR_EMAIL_MISMATCH 63 -#define X509_V_ERR_IP_ADDRESS_MISMATCH 64 -/* DANE TLSA errors */ -#define X509_V_ERR_DANE_NO_MATCH 65 -/* security level errors */ -#define X509_V_ERR_EE_KEY_TOO_SMALL 66 -#define X509_V_ERR_CA_KEY_TOO_SMALL 67 -#define X509_V_ERR_CA_MD_TOO_WEAK 68 -/* Caller error */ -#define X509_V_ERR_INVALID_CALL 69 -/* Issuer lookup error */ -#define X509_V_ERR_STORE_LOOKUP 70 -/* Certificate transparency */ -#define X509_V_ERR_NO_VALID_SCTS 71 - -#define X509_V_ERR_PROXY_SUBJECT_NAME_VIOLATION 72 - -typedef void X509_STORE_CTX; -int X509_STORE_CTX_get_error(X509_STORE_CTX *ctx); -int X509_STORE_CTX_get_error_depth(X509_STORE_CTX *ctx); - -#ifdef __cplusplus -} -#endif - -#endif /* OPENSSL_MBEDTLS_WRAPPER_X509_VFY_H */ diff --git a/crypto/openssl_mbedtls_wrapper/include/openssl/x509v3.h b/crypto/openssl_mbedtls_wrapper/include/openssl/x509v3.h deleted file mode 100644 index 9f39a729a..000000000 --- a/crypto/openssl_mbedtls_wrapper/include/openssl/x509v3.h +++ /dev/null @@ -1,44 +0,0 @@ -/**************************************************************************** - * apps/crypto/openssl_mbedtls_wrapper/include/openssl/x509v3.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - ****************************************************************************/ - -#ifndef OPENSSL_MBEDTLS_WRAPPER_X509V3_H -#define OPENSSL_MBEDTLS_WRAPPER_X509V3_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <openssl/x509.h> - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -#ifdef __cplusplus -extern "C" -{ -#endif - -#ifdef __cplusplus -} -#endif - -#endif /* OPENSSL_MBEDTLS_WRAPPER_X509V3_H */ diff --git a/crypto/openssl_mbedtls_wrapper/mbedtls/aes.c b/crypto/openssl_mbedtls_wrapper/mbedtls/aes.c deleted file mode 100644 index 988fec80a..000000000 --- a/crypto/openssl_mbedtls_wrapper/mbedtls/aes.c +++ /dev/null @@ -1,210 +0,0 @@ -/**************************************************************************** - * apps/crypto/openssl_mbedtls_wrapper/mbedtls/aes.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <errno.h> -#include <stdlib.h> -#include <openssl/evp.h> -#include <mbedtls/cipher.h> - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -void EVP_CIPHER_CTX_init(EVP_CIPHER_CTX *ctx) -{ - mbedtls_cipher_init((mbedtls_cipher_context_t *)ctx); -} - -int EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *ctx) -{ - mbedtls_cipher_free((mbedtls_cipher_context_t *)ctx); - return 1; -} - -const EVP_CIPHER *EVP_aes_128_ecb(void) -{ - return (const EVP_CIPHER *)mbedtls_cipher_info_from_type( - MBEDTLS_CIPHER_AES_128_ECB); -} - -const EVP_CIPHER *EVP_aes_192_ecb(void) -{ - return (const EVP_CIPHER *)mbedtls_cipher_info_from_type( - MBEDTLS_CIPHER_AES_192_ECB); -} - -const EVP_CIPHER *EVP_aes_256_ecb(void) -{ - return (const EVP_CIPHER *)mbedtls_cipher_info_from_type( - MBEDTLS_CIPHER_AES_256_ECB); -} - -const EVP_CIPHER *EVP_aes_128_cbc(void) -{ - return (const EVP_CIPHER *)mbedtls_cipher_info_from_type( - MBEDTLS_CIPHER_AES_128_CBC); -} - -const EVP_CIPHER *EVP_aes_192_cbc(void) -{ - return (const EVP_CIPHER *)mbedtls_cipher_info_from_type( - MBEDTLS_CIPHER_AES_192_CBC); -} - -const EVP_CIPHER *EVP_aes_256_cbc(void) -{ - return (const EVP_CIPHER *)mbedtls_cipher_info_from_type( - MBEDTLS_CIPHER_AES_256_CBC); -} - -const EVP_CIPHER *EVP_aes_128_ctr(void) -{ - return (const EVP_CIPHER *)mbedtls_cipher_info_from_type( - MBEDTLS_CIPHER_AES_128_CTR); -} - -const EVP_CIPHER *EVP_aes_192_ctr(void) -{ - return (const EVP_CIPHER *)mbedtls_cipher_info_from_type( - MBEDTLS_CIPHER_AES_192_CTR); -} - -const EVP_CIPHER *EVP_aes_256_ctr(void) -{ - return (const EVP_CIPHER *)mbedtls_cipher_info_from_type( - MBEDTLS_CIPHER_AES_256_CTR); -} - -const EVP_CIPHER *EVP_aes_128_gcm(void) -{ - return (const EVP_CIPHER *)mbedtls_cipher_info_from_type( - MBEDTLS_CIPHER_AES_128_GCM); -} - -const EVP_CIPHER *EVP_aes_192_gcm(void) -{ - return (const EVP_CIPHER *)mbedtls_cipher_info_from_type( - MBEDTLS_CIPHER_AES_192_GCM); -} - -const EVP_CIPHER *EVP_aes_256_gcm(void) -{ - return (const EVP_CIPHER *)mbedtls_cipher_info_from_type( - MBEDTLS_CIPHER_AES_256_GCM); -} - -int EVP_CIPHER_CTX_set_padding(EVP_CIPHER_CTX *c, int pad) -{ - mbedtls_cipher_padding_t padding = MBEDTLS_PADDING_PKCS7; - if (pad == 0) - { - padding = MBEDTLS_PADDING_NONE; - } - - mbedtls_cipher_set_padding_mode((mbedtls_cipher_context_t *)c, padding); - return 1; -} - -int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, - ENGINE *impl, const unsigned char *key, - const unsigned char *iv, int enc) -{ - mbedtls_cipher_context_t *ctx_ = (mbedtls_cipher_context_t *)ctx; - mbedtls_cipher_set_padding_mode(ctx_, MBEDTLS_PADDING_PKCS7); - const mbedtls_operation_t operation = enc - ? MBEDTLS_ENCRYPT : MBEDTLS_DECRYPT; - int ret = mbedtls_cipher_setup(ctx_, - (mbedtls_cipher_info_t *)cipher); - if (ret != 0) - { - goto error; - } - - ret = mbedtls_cipher_setkey(ctx_, key, - mbedtls_cipher_get_key_bitlen(ctx_), - operation); - if (ret != 0) - { - goto error; - } - - ret = mbedtls_cipher_set_iv(ctx_, iv, - mbedtls_cipher_get_iv_size(ctx_)); - if (ret != 0) - { - goto error; - } - - return 1; -error: - errno = ret; - return 0; -} - -int EVP_CipherUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl, - const unsigned char *in, int inl) -{ - size_t out_len = 0; - int ret = mbedtls_cipher_update((mbedtls_cipher_context_t *)ctx, - in, inl, out, &out_len); - if (ret != 0) - { - errno = ret; - return 0; - } - - *outl = out_len; - return 1; -} - -int EVP_CipherFinal_ex(EVP_CIPHER_CTX *ctx, - unsigned char *outm, int *outl) -{ - size_t out_len = 0; - int ret = mbedtls_cipher_finish((mbedtls_cipher_context_t *)ctx, - outm, &out_len); - if (ret != 0) - { - errno = ret; - return 0; - } - - *outl = out_len; - return 1; -} - -EVP_CIPHER_CTX *EVP_CIPHER_CTX_new(void) -{ - return (EVP_CIPHER_CTX *)(malloc(sizeof(mbedtls_cipher_context_t))); -} - -void EVP_CIPHER_CTX_free(EVP_CIPHER_CTX *ctx) -{ - if (ctx == NULL) - return; - - free(ctx); -} diff --git a/crypto/openssl_mbedtls_wrapper/mbedtls/asn1.c b/crypto/openssl_mbedtls_wrapper/mbedtls/asn1.c deleted file mode 100644 index 343ccc965..000000000 --- a/crypto/openssl_mbedtls_wrapper/mbedtls/asn1.c +++ /dev/null @@ -1,93 +0,0 @@ -/**************************************************************************** - * apps/crypto/openssl_mbedtls_wrapper/mbedtls/asn1.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <openssl/asn1.h> - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -void ASN1_TIME_free(ASN1_TIME *a) -{ -} - -void ASN1_INTEGER_free(ASN1_INTEGER *a) -{ -} - -void ASN1_OCTET_STRING_free(ASN1_OCTET_STRING *a) -{ -} - -void ASN1_BIT_STRING_free(ASN1_BIT_STRING *a) -{ -} - -ASN1_TIME *ASN1_TIME_new(void) -{ - return NULL; -} - -ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s, time_t t) -{ - return NULL; -} - -int ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *str, int n, int value) -{ - return 0; -} - -int i2d_ASN1_BIT_STRING(const ASN1_BIT_STRING *in, uint8_t **outp) -{ - return 0; -} - -ASN1_OCTET_STRING *ASN1_OCTET_STRING_new(void) -{ - return NULL; -} - -int ASN1_OCTET_STRING_set(ASN1_OCTET_STRING *str, - const unsigned char *data, int len) -{ - return 0; -} - -ASN1_INTEGER *ASN1_INTEGER_new(void) -{ - return NULL; -} - -ASN1_INTEGER *BN_to_ASN1_INTEGER(const BIGNUM *bn, ASN1_INTEGER *ai) -{ - return NULL; -} - -ASN1_BIT_STRING *ASN1_BIT_STRING_new(void) -{ - return NULL; -} diff --git a/crypto/openssl_mbedtls_wrapper/mbedtls/bio_b64.c b/crypto/openssl_mbedtls_wrapper/mbedtls/bio_b64.c deleted file mode 100644 index a13d4f26c..000000000 --- a/crypto/openssl_mbedtls_wrapper/mbedtls/bio_b64.c +++ /dev/null @@ -1,147 +0,0 @@ -/**************************************************************************** - * apps/crypto/openssl_mbedtls_wrapper/mbedtls/bio_b64.c - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <stdio.h> -#include <sys/param.h> - -#include <mbedtls/base64.h> -#include <openssl/bio.h> -#include <openssl/types.h> - -/**************************************************************************** - * Pre-processor definitions - ****************************************************************************/ - -#define BIO_B64_BUFSIZE ((BIO_B64_ENC_LEN / 3) * 4 + 1) -#define BIO_B64_ENC_LEN 192 - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -static int b64_write(BIO *h, const char *buf, int num); -static int b64_read(BIO *h, char *buf, int size); -static int b64_new(BIO *h); -static int b64_free(BIO *data); - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static const BIO_METHOD g_methods_b64 = -{ - BIO_TYPE_BASE64, - "base64 encoding", - b64_write, - b64_read, - b64_new, - b64_free, -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static int b64_write(BIO *b, const char *in, int inl) -{ - BIO *next; - int len; - int offset = 0; - int ret = 0; - size_t n; - unsigned char out[BIO_B64_BUFSIZE]; - - next = BIO_next(b); - if (next == NULL) - { - return 0; - } - - while (inl > 0) - { - len = MIN(inl, BIO_B64_ENC_LEN); - ret = mbedtls_base64_encode(out, BIO_B64_BUFSIZE, &n, - (const unsigned char *)in + offset, len); - if (ret < 0) - { - break; - } - - ret = BIO_write(next, out, n); - inl -= len; - offset += len; - } - - return ret; -} - -static int b64_read(BIO *b, char *out, int outl) -{ - BIO *next; - int ret; - size_t n; - - if (out == NULL) - { - return 0; - } - - next = BIO_next(b); - if (next == NULL) - { - return 0; - } - - ret = BIO_read(next, out, outl); - if (ret > 0) - { - ret = mbedtls_base64_decode((unsigned char *)out, outl, &n, - (const unsigned char *)out, ret); - if (ret == 0) - { - ret = n; - } - } - - return ret; -} - -static int b64_new(BIO *bi) -{ - return 1; -} - -static int b64_free(BIO *a) -{ - return 1; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -const BIO_METHOD *BIO_f_base64(void) -{ - return &g_methods_b64; -} diff --git a/crypto/openssl_mbedtls_wrapper/mbedtls/bio_lib.c b/crypto/openssl_mbedtls_wrapper/mbedtls/bio_lib.c deleted file mode 100644 index 36d08403a..000000000 --- a/crypto/openssl_mbedtls_wrapper/mbedtls/bio_lib.c +++ /dev/null @@ -1,151 +0,0 @@ -/**************************************************************************** - * apps/crypto/openssl_mbedtls_wrapper/mbedtls/bio_lib.c - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <stdio.h> - -#include <openssl/bio.h> - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -BIO *BIO_new(const BIO_METHOD *method) -{ - BIO *bio = zalloc(sizeof(*bio)); - - if (bio == NULL) - { - return NULL; - } - - bio->method = method; - - if (method->create != NULL && !method->create(bio)) - { - free(bio); - return NULL; - } - - return bio; -} - -BIO *BIO_push(BIO *b, BIO *bio) -{ - BIO *lb; - - if (b == NULL) - { - return bio; - } - else if (bio == NULL) - { - return b; - } - - lb = b; - while (lb->next_bio != NULL) - { - lb = lb->next_bio; - } - - lb->next_bio = bio; - bio->prev_bio = lb; - return b; -} - -void BIO_set_flags(BIO *b, int flags) -{ - b->flags |= flags; -} - -int BIO_write(BIO *b, const void *data, int dlen) -{ - if (b == NULL || dlen <= 0) - { - return 0; - } - - if (b->method == NULL || b->method->bwrite_old == NULL) - { - return -2; - } - - return b->method->bwrite_old(b, data, dlen); -} - -int BIO_read(BIO *b, void *data, int dlen) -{ - if (b == NULL || dlen <= 0) - { - return 0; - } - - if (b->method == NULL || b->method->bread_old == NULL) - { - return -2; - } - - return b->method->bread_old(b, data, dlen); -} - -int BIO_free(BIO *a) -{ - if (a == NULL) - { - return 0; - } - - if (a->method != NULL && a->method->destroy != NULL) - { - a->method->destroy(a); - } - - free(a); - return 1; -} - -void BIO_free_all(BIO *bio) -{ - while (bio != NULL) - { - BIO *b = bio; - bio = bio->next_bio; - BIO_free(b); - } -} - -BIO *BIO_next(BIO *b) -{ - if (b == NULL) - { - return NULL; - } - - return b->next_bio; -} - -int BIO_flush(BIO *b) -{ - return 1; -} diff --git a/crypto/openssl_mbedtls_wrapper/mbedtls/bn.c b/crypto/openssl_mbedtls_wrapper/mbedtls/bn.c deleted file mode 100644 index a066c0b19..000000000 --- a/crypto/openssl_mbedtls_wrapper/mbedtls/bn.c +++ /dev/null @@ -1,41 +0,0 @@ -/**************************************************************************** - * apps/crypto/openssl_mbedtls_wrapper/mbedtls/bn.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <openssl/bn.h> - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -BIGNUM *BN_bin2bn(const uint8_t *in, size_t len, BIGNUM *ret) -{ - return NULL; -} - -int BN_one(BIGNUM *bn) -{ - return 0; -} diff --git a/crypto/openssl_mbedtls_wrapper/mbedtls/bss_mem.c b/crypto/openssl_mbedtls_wrapper/mbedtls/bss_mem.c deleted file mode 100644 index 40f884135..000000000 --- a/crypto/openssl_mbedtls_wrapper/mbedtls/bss_mem.c +++ /dev/null @@ -1,236 +0,0 @@ -/**************************************************************************** - * apps/crypto/openssl_mbedtls_wrapper/mbedtls/bss_mem.c - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <sys/param.h> - -#include <openssl/bio.h> - -/**************************************************************************** - * Pre-processor definitions - ****************************************************************************/ - -/* LIMIT_BEFORE_EXPANSION is the maximum n such that (n+3)/3*4 < 2**31. That - * function is applied in several functions in this file and this limit - * ensures that the result fits in an int. - */ - -#define LIMIT_BEFORE_EXPANSION 0x5ffffffc - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -static int mem_write(BIO *h, const char *buf, int num); -static int mem_read(BIO *h, char *buf, int size); -static int mem_new(BIO *h); -static int mem_free(BIO *data); - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -struct bio_buf_mem_st -{ - unsigned long flags; - char *data; - size_t length; /* current number of bytes */ - size_t max; /* size of buffer */ - size_t offset; /* has been read */ -}; - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static const BIO_METHOD g_mem_method = -{ - BIO_TYPE_MEM, - "memory buffer", - mem_write, - mem_read, - mem_new, - mem_free, -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static int mem_buf_sync(BIO *b) -{ - if (b != NULL && b->ptr != NULL) - { - BIO_BUF_MEM *bbm = (BIO_BUF_MEM *)b->ptr; - - if (bbm->offset) - { - bbm->length = bbm->length - bbm->offset; - memmove(bbm->data, bbm->data + bbm->offset, bbm->length); - bbm->offset = 0; - } - } - - return 0; -} - -static size_t BUF_MEM_grow_clean(BIO_BUF_MEM *bbm, size_t len) -{ - char *ret; - size_t n; - - if (bbm->length >= len) - { - if (bbm->data != NULL) - { - memset(&bbm->data[len], 0, bbm->length - len); - } - - bbm->length = len; - return len; - } - - if (bbm->max >= len) - { - memset(&bbm->data[bbm->length], 0, len - bbm->length); - bbm->length = len; - return len; - } - - /* This limit is sufficient to ensure (len+3)/3*4 < 2**31 */ - - if (len > LIMIT_BEFORE_EXPANSION) - { - return 0; - } - - n = MAX((len + 3) / 3 * 4, bbm->max); - ret = realloc(bbm->data, n); - if (ret == NULL) - { - return 0; - } - - bbm->data = ret; - bbm->max = n; - bbm->length = len; - return len; -} - -static int mem_write(BIO *b, const char *in, int inl) -{ - BIO_BUF_MEM *bbm = (BIO_BUF_MEM *)b->ptr; - int blen; - - if (b->flags & BIO_FLAGS_MEM_RDONLY) - { - return -1; - } - - if (inl <= 0) - { - return 0; - } - else if (in == NULL) - { - return -1; - } - - blen = bbm->length - bbm->offset; - mem_buf_sync(b); - if (BUF_MEM_grow_clean(bbm, blen + inl) == 0) - { - return -1; - } - - memcpy(bbm->data + blen, in, inl); - return inl; -} - -static int mem_read(BIO *b, char *out, int outl) -{ - BIO_BUF_MEM *bbm = (BIO_BUF_MEM *)b->ptr; - - if (outl <= 0) - { - return 0; - } - - if (out == NULL) - { - return -1; - } - - if (outl > bbm->length - bbm->offset) - { - outl = bbm->length - bbm->offset; - } - - memcpy(out, bbm->data + bbm->offset, outl); - bbm->offset += outl; - return outl; -} - -static int mem_new(BIO *bi) -{ - BIO_BUF_MEM *bbm = zalloc(sizeof(*bbm)); - - if (bbm == NULL) - { - return 0; - } - - bi->ptr = bbm; - return 1; -} - -static int mem_free(BIO *a) -{ - BIO_BUF_MEM *bbm; - - if (a == NULL) - { - return 0; - } - - bbm = (BIO_BUF_MEM *)a->ptr; - if (bbm->data) - { - free(bbm->data); - } - - free(bbm); - return 1; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -const BIO_METHOD *BIO_s_mem(void) -{ - return &g_mem_method; -} diff --git a/crypto/openssl_mbedtls_wrapper/mbedtls/bytestring.c b/crypto/openssl_mbedtls_wrapper/mbedtls/bytestring.c deleted file mode 100644 index 68dfc5e06..000000000 --- a/crypto/openssl_mbedtls_wrapper/mbedtls/bytestring.c +++ /dev/null @@ -1,45 +0,0 @@ -/**************************************************************************** - * apps/crypto/openssl_mbedtls_wrapper/mbedtls/bytestring.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <openssl/bytestring.h> - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -int CBB_finish(CBB *cbb, uint8_t **out_data, size_t *out_len) -{ - return 0; -} - -void CBB_cleanup(CBB *cbb) -{ -} - -int CBB_init(CBB *cbb, size_t initial_capacity) -{ - return 0; -} diff --git a/crypto/openssl_mbedtls_wrapper/mbedtls/cipher.c b/crypto/openssl_mbedtls_wrapper/mbedtls/cipher.c deleted file mode 100644 index 3cbb25cc6..000000000 --- a/crypto/openssl_mbedtls_wrapper/mbedtls/cipher.c +++ /dev/null @@ -1,174 +0,0 @@ -/**************************************************************************** - * apps/crypto/openssl_mbedtls_wrapper/mbedtls/cipher.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <openssl/aes.h> -#include <openssl/cipher.h> - -#include <mbedtls/aes.h> -#include <mbedtls/cipher.h> -#include <mbedtls/cmac.h> - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -int EVP_DecryptInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER * cipher, - ENGINE *impl, const uint8_t *key, const uint8_t *iv) -{ - mbedtls_cipher_context_t *m_ctx = (mbedtls_cipher_context_t *)ctx; - mbedtls_cipher_init(m_ctx); - mbedtls_cipher_setup(m_ctx, (const mbedtls_cipher_info_t *)cipher); - mbedtls_cipher_setkey(m_ctx, key, m_ctx->cipher_info->key_bitlen, - MBEDTLS_DECRYPT); - mbedtls_cipher_set_iv(m_ctx, iv, m_ctx->cipher_info->iv_size); - return 1; -} - -int EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, uint8_t *out, int *out_len, - const uint8_t *in, int in_len) -{ - size_t len = 0; - int ret = mbedtls_cipher_update((mbedtls_cipher_context_t *)ctx, - in, in_len, out, &len); - *out_len = len; - return !ret; -} - -int EVP_DecryptFinal_ex(EVP_CIPHER_CTX *ctx, uint8_t *out, int *out_len) -{ - size_t len = 0; - int ret = mbedtls_cipher_finish((mbedtls_cipher_context_t *)ctx, - out, &len); - *out_len = len; - return !ret; -} - -const EVP_CIPHER *EVP_des_ede(void) -{ - return NULL; -} - -const EVP_CIPHER *EVP_des_ede3(void) -{ - return NULL; -} - -const EVP_CIPHER *EVP_des_ede_cbc(void) -{ - return NULL; -} - -const EVP_CIPHER *EVP_des_ede3_cbc(void) -{ - return NULL; -} - -int EVP_EncryptInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type, - ENGINE *impl, const unsigned char *key, - const unsigned char *iv) -{ - mbedtls_cipher_context_t *m_ctx = (mbedtls_cipher_context_t *)ctx; - mbedtls_cipher_init(m_ctx); - if (mbedtls_cipher_setup(m_ctx, (const mbedtls_cipher_info_t *)type) != 0) - { - mbedtls_cipher_free(m_ctx); - return 0; - } - - if (mbedtls_cipher_setkey(m_ctx, key, - m_ctx->cipher_info->key_bitlen, - MBEDTLS_ENCRYPT) != 0) - { - mbedtls_cipher_free(m_ctx); - return 0; - } - - if (mbedtls_cipher_set_iv(m_ctx, iv, m_ctx->cipher_info->iv_size) != 0) - { - mbedtls_cipher_free(m_ctx); - return 0; - } - - return 1; -} - -int EVP_EncryptUpdate(EVP_CIPHER_CTX * ctx, uint8_t *out, int *out_len, - const uint8_t *in, int in_len) -{ - return !mbedtls_cipher_update((mbedtls_cipher_context_t *)ctx, - in, in_len, out, (size_t *)out_len); -} - -int EVP_EncryptFinal_ex(EVP_CIPHER_CTX *ctx, - unsigned char *out, int *out_len) -{ - return !mbedtls_cipher_finish((mbedtls_cipher_context_t *)ctx, out, - (size_t *)out_len); -} - -void AES_cbc_encrypt(const uint8_t *in, uint8_t *out, size_t len, - const AES_KEY *key, uint8_t *ivec, const int enc) -{ - const mbedtls_aes_context *ctx = (const mbedtls_aes_context *)key; - mbedtls_aes_crypt_cbc((mbedtls_aes_context *)ctx, enc, len, ivec, in, out); -} - -int EVP_CIPHER_CTX_ctrl(EVP_CIPHER_CTX *ctx, int command, - int tag_len, void *tag) -{ - mbedtls_cipher_context_t *m_ctx = (mbedtls_cipher_context_t *)ctx; - int ret = 0; - if (command == EVP_CTRL_GCM_GET_TAG) - { - ret = mbedtls_cipher_write_tag(m_ctx, (unsigned char *)tag, tag_len); - } - else if (command == EVP_CTRL_GCM_SET_TAG) - { - ret = mbedtls_cipher_check_tag(m_ctx, - (const unsigned char *)tag, - tag_len); - } - - return !ret; -} - -int AES_set_encrypt_key(const uint8_t *key, unsigned bits, AES_KEY *aeskey) -{ - return -1; -} - -int AES_set_decrypt_key(const uint8_t *key, unsigned bits, AES_KEY *aeskey) -{ - return -1; -} - -void AES_encrypt(const uint8_t *in, uint8_t *out, const AES_KEY *key) -{ -} - -void AES_decrypt(const uint8_t *in, uint8_t *out, const AES_KEY *key) -{ -} diff --git a/crypto/openssl_mbedtls_wrapper/mbedtls/curve25519.c b/crypto/openssl_mbedtls_wrapper/mbedtls/curve25519.c deleted file mode 100644 index eaa105a52..000000000 --- a/crypto/openssl_mbedtls_wrapper/mbedtls/curve25519.c +++ /dev/null @@ -1,54 +0,0 @@ -/**************************************************************************** - * apps/crypto/openssl_mbedtls_wrapper/mbedtls/curve25519.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <openssl/curve25519.h> - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -void ED25519_keypair(uint8_t out_public_key[32], - uint8_t out_private_key[64]) -{ -} - -void X25519_keypair(uint8_t out_public_value[32], - uint8_t out_private_key[32]) -{ -} - -int X25519(uint8_t out_shared_key[32], - const uint8_t private_key[32], - const uint8_t peer_public_value[32]) -{ - return 0; -} - -void ED25519_keypair_from_seed(uint8_t out_public_key[32], - uint8_t out_private_key[64], - const uint8_t seed[32]) -{ -} diff --git a/crypto/openssl_mbedtls_wrapper/mbedtls/digest.c b/crypto/openssl_mbedtls_wrapper/mbedtls/digest.c deleted file mode 100644 index 41412d396..000000000 --- a/crypto/openssl_mbedtls_wrapper/mbedtls/digest.c +++ /dev/null @@ -1,106 +0,0 @@ -/**************************************************************************** - * apps/crypto/openssl_mbedtls_wrapper/mbedtls/digest.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <mbedtls/md.h> -#include <openssl/digest.h> -#include <stdlib.h> - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -EVP_MD_CTX *EVP_MD_CTX_new(void) -{ - mbedtls_md_context_t *ctx = - (mbedtls_md_context_t *)malloc(sizeof(mbedtls_md_context_t)); - EVP_MD_CTX_init((EVP_MD_CTX *)ctx); - return (EVP_MD_CTX *)ctx; -} - -void EVP_MD_CTX_free(EVP_MD_CTX *ctx) -{ - if (ctx != NULL) - { - EVP_MD_CTX_cleanup(ctx); - free(ctx); - } -} - -const EVP_MD *EVP_md5(void) -{ - return NULL; -} - -int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *engine) -{ - mbedtls_md_context_t *m_ctx = (mbedtls_md_context_t *)ctx; - if (mbedtls_md_setup(m_ctx, (const mbedtls_md_info_t *)type, 0) != 0) - { - return 0; - } - - if (mbedtls_md_starts(m_ctx) != 0) - { - return 0; - } - - return 1; -} - -int EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *data, size_t len) -{ - if (mbedtls_md_update((mbedtls_md_context_t *)ctx, - (const unsigned char *)data, len) != 0) - { - return 0; - } - - return 1; -} - -int EVP_DigestFinal_ex(EVP_MD_CTX *ctx, uint8_t *md_out, - unsigned int *size) -{ - const mbedtls_md_info_t *md_info = ((mbedtls_md_context_t *)ctx)->md_info; - if (md_info == NULL) - { - return 0; - } - - *size = mbedtls_md_get_size(md_info); - if (mbedtls_md_finish((mbedtls_md_context_t *)ctx, md_out) != 0) - { - return 0; - } - - return 1; -} - -int EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx) -{ - mbedtls_md_free((mbedtls_md_context_t *)ctx); - return 1; -} diff --git a/crypto/openssl_mbedtls_wrapper/mbedtls/ec.c b/crypto/openssl_mbedtls_wrapper/mbedtls/ec.c deleted file mode 100644 index 410cb2a31..000000000 --- a/crypto/openssl_mbedtls_wrapper/mbedtls/ec.c +++ /dev/null @@ -1,49 +0,0 @@ -/**************************************************************************** - * apps/crypto/openssl_mbedtls_wrapper/mbedtls/ec.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <openssl/ec.h> - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -void EC_KEY_free(EC_KEY *a) -{ -} - -EC_GROUP *EC_GROUP_new_by_curve_name(int nid) -{ - return NULL; -} - -void EC_GROUP_free(EC_GROUP *a) -{ -} - -int EC_GROUP_get_curve_name(const EC_GROUP *group) -{ - return 0; -} diff --git a/crypto/openssl_mbedtls_wrapper/mbedtls/ec_key.c b/crypto/openssl_mbedtls_wrapper/mbedtls/ec_key.c deleted file mode 100644 index 0fe4287c5..000000000 --- a/crypto/openssl_mbedtls_wrapper/mbedtls/ec_key.c +++ /dev/null @@ -1,36 +0,0 @@ -/**************************************************************************** - * apps/crypto/openssl_mbedtls_wrapper/mbedtls/ec_key.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <openssl/ec_key.h> - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -int EC_KEY_check_key(const EC_KEY *key) -{ - return 0; -} diff --git a/crypto/openssl_mbedtls_wrapper/mbedtls/ecdsa.c b/crypto/openssl_mbedtls_wrapper/mbedtls/ecdsa.c deleted file mode 100644 index b289a41e2..000000000 --- a/crypto/openssl_mbedtls_wrapper/mbedtls/ecdsa.c +++ /dev/null @@ -1,48 +0,0 @@ -/**************************************************************************** - * apps/crypto/openssl_mbedtls_wrapper/mbedtls/ecdsa.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <openssl/ecdsa.h> - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -size_t ECDSA_size(const EC_KEY *key) -{ - return 0; -} - -int ECDSA_sign(int type, const uint8_t *digest, size_t digest_len, - uint8_t *sig, unsigned int *sig_len, const EC_KEY *key) -{ - return 0; -} - -int ECDSA_verify(int type, const uint8_t *digest, size_t digest_len, - const uint8_t *sig, size_t sig_len, const EC_KEY *key) -{ - return 0; -} diff --git a/crypto/openssl_mbedtls_wrapper/mbedtls/engine.c b/crypto/openssl_mbedtls_wrapper/mbedtls/engine.c deleted file mode 100644 index 3d6a39868..000000000 --- a/crypto/openssl_mbedtls_wrapper/mbedtls/engine.c +++ /dev/null @@ -1,35 +0,0 @@ -/**************************************************************************** - * apps/crypto/openssl_mbedtls_wrapper/mbedtls/engine.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <openssl/engine.h> - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -void ENGINE_free(ENGINE *a) -{ -} diff --git a/crypto/openssl_mbedtls_wrapper/mbedtls/err.c b/crypto/openssl_mbedtls_wrapper/mbedtls/err.c deleted file mode 100644 index 4657259f7..000000000 --- a/crypto/openssl_mbedtls_wrapper/mbedtls/err.c +++ /dev/null @@ -1,71 +0,0 @@ -/**************************************************************************** - * apps/crypto/openssl_mbedtls_wrapper/mbedtls/err.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <openssl/err.h> -#include <mbedtls/error.h> -#include <mbedtls/cipher.h> -#include <errno.h> - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -unsigned long ERR_peek_last_error(void) -{ - return errno; -} - -void ERR_free_strings(void) -{ -} - -void ERR_error_string_n(unsigned long e, char *buf, size_t len) -{ - mbedtls_strerror(e, buf, len); -} - -void ERR_clear_error(void) -{ -} - -unsigned long ERR_get_error(void) -{ - return errno; -} - -void ERR_remove_state(unsigned long pid) -{ -} - -int ERR_load_crypto_strings(void) -{ - return 1; -} - -void ERR_print_errors_cb(int (*cb)(const char *str, size_t len, void *u), - void *u) -{ -} diff --git a/crypto/openssl_mbedtls_wrapper/mbedtls/evp.c b/crypto/openssl_mbedtls_wrapper/mbedtls/evp.c deleted file mode 100644 index b1feae343..000000000 --- a/crypto/openssl_mbedtls_wrapper/mbedtls/evp.c +++ /dev/null @@ -1,355 +0,0 @@ -/**************************************************************************** - * apps/crypto/openssl_mbedtls_wrapper/mbedtls/evp.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <openssl/bn.h> -#include <openssl/cipher.h> -#include <openssl/ssl_dbg.h> -#include <openssl/ec.h> -#include <openssl/evp.h> -#include <openssl/types.h> -#include "ssl_port.h" - -#include <mbedtls/md.h> -#include <mbedtls/pk.h> -#include <mbedtls/rsa.h> - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -EVP_PKEY *__EVP_PKEY_new(EVP_PKEY *ipk) -{ - int ret; - EVP_PKEY *pkey; - - pkey = ssl_mem_zalloc(sizeof(EVP_PKEY)); - if (!pkey) - { - SSL_DEBUG(SSL_PKEY_ERROR_LEVEL, "no enough memory > (pkey)"); - goto no_mem; - } - - if (ipk) - { - pkey->method = ipk->method; - } - else - { - pkey->method = EVP_PKEY_method(); - } - - ret = EVP_PKEY_METHOD_CALL(new, pkey, ipk); - if (ret) - { - SSL_DEBUG(SSL_PKEY_ERROR_LEVEL, - "EVP_PKEY_METHOD_CALL(new) return %d", ret); - goto failed; - } - - return pkey; - -failed: - ssl_mem_free(pkey); -no_mem: - return NULL; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -int EVP_PKEY_id(const EVP_PKEY *pkey) -{ - const mbedtls_pk_context *mbedtls_pkey = (const mbedtls_pk_context *)pkey; - return mbedtls_pk_get_type(mbedtls_pkey); -} - -RSA *EVP_PKEY_get1_RSA(const EVP_PKEY *pkey) -{ - mbedtls_pk_context *mbedtls_pkey = (mbedtls_pk_context *)pkey; - if (pkey == NULL || mbedtls_pk_get_type(mbedtls_pkey) != MBEDTLS_PK_RSA) - { - return NULL; - } - - mbedtls_rsa_context *rsa = mbedtls_pk_rsa(* mbedtls_pkey); - return (RSA *)rsa; -} - -void EVP_PKEY_free(EVP_PKEY *pkey) -{ - SSL_ASSERT3(pkey); - - EVP_PKEY_METHOD_CALL(free, pkey); - - ssl_mem_free(pkey); -} - -int EVP_PKEY_type(int nid) -{ - return 0; -} - -EC_KEY *EVP_PKEY_get1_EC_KEY(const EVP_PKEY *pkey) -{ - return NULL; -} - -EVP_PKEY *EVP_PKEY_new(void) -{ - return __EVP_PKEY_new(NULL); -} - -int EVP_PKEY_set1_RSA(EVP_PKEY *pkey, RSA *key) -{ - return 0; -} - -void EVP_MD_CTX_init(EVP_MD_CTX *ctx) -{ - mbedtls_md_init((mbedtls_md_context_t *)ctx); -} - -EVP_PKEY *EVP_PKEY_new_raw_private_key(int type, ENGINE *unused, - const uint8_t *in, size_t len) -{ - return NULL; -} - -const EC_GROUP *EC_KEY_get0_group(const EC_KEY *key) -{ - return NULL; -} - -EC_KEY *EC_KEY_new(void) -{ - return NULL; -} - -void EC_GROUP_set_point_conversion_form(EC_GROUP *group, - point_conversion_form_t form) -{ -} - -void EC_GROUP_set_asn1_flag(EC_GROUP *group, int flag) -{ -} - -int EC_KEY_set_group(EC_KEY *key, const EC_GROUP *group) -{ - return 0; -} - -int EC_KEY_generate_key(EC_KEY *key) -{ - return 0; -} - -BIGNUM *BN_new(void) -{ - return NULL; -} - -void BN_free(BIGNUM *bn) -{ -} - -int BN_set_word(BIGNUM *bn, BN_ULONG value) -{ - return 0; -} - -BN_ULONG BN_get_word(const BIGNUM *bn) -{ - return 0; -} - -int EVP_DigestVerifyFinal(EVP_MD_CTX *ctx, const uint8_t *sig, - size_t sig_len) -{ - return 0; -} - -int EVP_DigestVerifyUpdate(EVP_MD_CTX *ctx, const void *data, size_t len) -{ - return 0; -} - -int EVP_DigestVerifyInit(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx, - const EVP_MD *type, ENGINE *e, EVP_PKEY *pkey) -{ - return 0; -} - -int EVP_DigestSignFinal(EVP_MD_CTX *ctx, uint8_t *out_sig, - size_t *out_sig_len) -{ - return 0; -} - -int i2d_PUBKEY(const EVP_PKEY *pkey, uint8_t **outp) -{ - return 0; -} - -EVP_PKEY *d2i_PrivateKey(int type, EVP_PKEY **out, - const uint8_t **inp, long len) -{ - return NULL; -} - -int EVP_PKEY_set1_EC_KEY(EVP_PKEY *pkey, EC_KEY *key) -{ - return 0; -} - -int EVP_PKEY_bits(const EVP_PKEY *pkey) -{ - return 0; -} - -int EVP_DigestSignInit(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx, - const EVP_MD *type, ENGINE *e, EVP_PKEY *pkey) -{ - return 0; -} - -int EVP_DigestSignUpdate(EVP_MD_CTX *ctx, const void *data, size_t len) -{ - return 0; -} - -int EVP_marshal_private_key(CBB *cbb, const EVP_PKEY *key) -{ - return 0; -} - -int EVP_DigestSign(EVP_MD_CTX *ctx, uint8_t *out_sig, size_t *out_sig_len, - const uint8_t *data, size_t data_len) -{ - return 0; -} - -int EVP_PKEY_size(const EVP_PKEY *pkey) -{ - return 0; -} - -int EVP_PKEY_CTX_set_rsa_oaep_md(EVP_PKEY_CTX *ctx, const EVP_MD *md) -{ - return 0; -} - -int EVP_PKEY_CTX_set_rsa_padding(EVP_PKEY_CTX *ctx, int padding) -{ - return 0; -} - -int EVP_PKEY_CTX_set_rsa_pss_saltlen(EVP_PKEY_CTX *ctx, int salt_len) -{ - return 0; -} - -int EVP_PKEY_CTX_set_rsa_mgf1_md(EVP_PKEY_CTX *ctx, const EVP_MD *md) -{ - return 0; -} - -EVP_PKEY_CTX *EVP_PKEY_CTX_new(EVP_PKEY *pkey, ENGINE *e) -{ - return NULL; -} - -int EVP_PKEY_encrypt_init(EVP_PKEY_CTX *ctx) -{ - return 0; -} - -int EVP_PKEY_encrypt(EVP_PKEY_CTX *ctx, uint8_t *out, size_t *out_len, - const uint8_t *in, size_t in_len) -{ - return 0; -} - -int EVP_PKEY_decrypt_init(EVP_PKEY_CTX *ctx) -{ - return 0; -} - -int EVP_PKEY_decrypt(EVP_PKEY_CTX *ctx, uint8_t *out, size_t *out_len, - const uint8_t *in, size_t in_len) -{ - return 0; -} - -void EVP_PKEY_CTX_free(EVP_PKEY_CTX *ctx) -{ -} - -int i2d_PrivateKey(const EVP_PKEY *key, uint8_t **outp) -{ - return 0; -} - -int EVP_PKEY_derive_init(EVP_PKEY_CTX *ctx) -{ - return 0; -} - -int EVP_PKEY_derive_set_peer(EVP_PKEY_CTX *ctx, EVP_PKEY *peer) -{ - return 0; -} - -int EVP_PKEY_derive(EVP_PKEY_CTX *ctx, uint8_t *key, size_t *out_key_len) -{ - return 0; -} - -int EVP_PKEY_get_raw_public_key(const EVP_PKEY *pkey, - uint8_t *out, size_t *out_len) -{ - return 0; -} - -EVP_PKEY *d2i_PUBKEY(EVP_PKEY **out, const uint8_t **inp, long len) -{ - return NULL; -} - -int EVP_PKEY_get_raw_private_key(const EVP_PKEY *pkey, - uint8_t *out, size_t *out_len) -{ - return 0; -} - -int OpenSSL_add_all_algorithms(void) -{ - return 0; -} - -void EVP_cleanup(void) -{ -} diff --git a/crypto/openssl_mbedtls_wrapper/mbedtls/hkdf.c b/crypto/openssl_mbedtls_wrapper/mbedtls/hkdf.c deleted file mode 100644 index 066442858..000000000 --- a/crypto/openssl_mbedtls_wrapper/mbedtls/hkdf.c +++ /dev/null @@ -1,47 +0,0 @@ -/**************************************************************************** - * apps/crypto/openssl_mbedtls_wrapper/mbedtls/hkdf.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <openssl/hkdf.h> - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -int HKDF_extract(uint8_t *out_key, size_t *out_len, - const EVP_MD *digest, const uint8_t *secret, - size_t secret_len, const uint8_t *salt, - size_t salt_len) -{ - return 0; -} - -int HKDF_expand(uint8_t *out_key, size_t out_len, - const EVP_MD *digest, const uint8_t *prk, - size_t prk_len, const uint8_t *info, - size_t info_len) -{ - return 0; -} diff --git a/crypto/openssl_mbedtls_wrapper/mbedtls/hmac.c b/crypto/openssl_mbedtls_wrapper/mbedtls/hmac.c deleted file mode 100644 index 2e21de016..000000000 --- a/crypto/openssl_mbedtls_wrapper/mbedtls/hmac.c +++ /dev/null @@ -1,170 +0,0 @@ -/**************************************************************************** - * apps/crypto/openssl_mbedtls_wrapper/mbedtls/hmac.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <errno.h> -#include <openssl/hmac.h> -#include <mbedtls/hmac_drbg.h> -#include <mbedtls/md.h> -#include <stdlib.h> - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -uint8_t *HMAC(const EVP_MD *evp_md, const void *key, - size_t key_len, const uint8_t *data, - size_t data_len, uint8_t *out, - unsigned int *out_len) -{ - if (mbedtls_md_hmac((const mbedtls_md_info_t *)evp_md, - (const unsigned char *)key, key_len, data, data_len, - out) != 0) - { - return NULL; - } - - if (out_len != NULL) - { - *out_len = mbedtls_md_get_size((const mbedtls_md_info_t *)evp_md); - } - - return out; -} - -HMAC_CTX *HMAC_CTX_new(void) -{ - mbedtls_md_context_t *ctx = - (mbedtls_md_context_t *)malloc(sizeof(mbedtls_md_context_t)); - if (ctx != NULL) - { - mbedtls_md_init(ctx); - } - - return (HMAC_CTX *)ctx; -} - -void HMAC_CTX_init(HMAC_CTX *ctx) -{ - mbedtls_md_init((mbedtls_md_context_t *)ctx); -} - -int HMAC_Init_ex(HMAC_CTX *ctx, const void *key, size_t key_len, - const EVP_MD *md, ENGINE *impl) -{ - int ret = mbedtls_md_setup((mbedtls_md_context_t *)ctx, - (const mbedtls_md_info_t *)md, 1); - if (ret != 0) - { - goto error; - } - - ret = mbedtls_md_hmac_starts((mbedtls_md_context_t *)ctx, - (const unsigned char *)key, key_len); - if (ret != 0) - { - goto error; - } - - return 1; -error: - errno = ret; - return 0; -} - -int HMAC_Update(HMAC_CTX *ctx, const uint8_t *data, size_t data_len) -{ - errno = mbedtls_md_hmac_update((mbedtls_md_context_t *)ctx, - data, data_len); - return !errno; -} - -int HMAC_Final(HMAC_CTX *ctx, uint8_t *out, unsigned int *out_len) -{ - size_t md_size; - - const mbedtls_md_info_t *md_info = - ((mbedtls_md_context_t *)(ctx))->md_info; - if (md_info == NULL) - { - return 0; - } - - md_size = mbedtls_md_get_size(md_info); - *out_len = md_size; - errno = mbedtls_md_hmac_finish((mbedtls_md_context_t *)ctx, out); - return !errno; -} - -void HMAC_CTX_cleanup(HMAC_CTX *ctx) -{ - mbedtls_md_free((mbedtls_md_context_t *)ctx); -} - -void HMAC_CTX_free(HMAC_CTX *ctx) -{ - mbedtls_md_free((mbedtls_md_context_t *)ctx); - free(ctx); -} - -size_t EVP_MD_size(const EVP_MD *md) -{ - return mbedtls_md_get_size((const mbedtls_md_info_t *)md); -} - -const EVP_MD *EVP_sha1(void) -{ - const mbedtls_md_info_t *md_info = - mbedtls_md_info_from_type(MBEDTLS_MD_SHA1); - return (const EVP_MD *)md_info; -} - -const EVP_MD *EVP_sha224(void) -{ - const mbedtls_md_info_t *md_info = - mbedtls_md_info_from_type(MBEDTLS_MD_SHA224); - return (const EVP_MD *)md_info; -} - -const EVP_MD *EVP_sha256(void) -{ - const mbedtls_md_info_t *md_info = - mbedtls_md_info_from_type(MBEDTLS_MD_SHA256); - return (const EVP_MD *)md_info; -} - -const EVP_MD *EVP_sha384(void) -{ - const mbedtls_md_info_t *md_info = - mbedtls_md_info_from_type(MBEDTLS_MD_SHA384); - return (const EVP_MD *)md_info; -} - -const EVP_MD *EVP_sha512(void) -{ - const mbedtls_md_info_t *md_info = - mbedtls_md_info_from_type(MBEDTLS_MD_SHA512); - return (const EVP_MD *)md_info; -} diff --git a/crypto/openssl_mbedtls_wrapper/mbedtls/md5.c b/crypto/openssl_mbedtls_wrapper/mbedtls/md5.c deleted file mode 100644 index 0d993e06a..000000000 --- a/crypto/openssl_mbedtls_wrapper/mbedtls/md5.c +++ /dev/null @@ -1,43 +0,0 @@ -/**************************************************************************** - * apps/crypto/openssl_mbedtls_wrapper/mbedtls/md5.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <mbedtls/md5.h> -#include <openssl/md5.h> - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -uint8_t *MD5(const uint8_t *data, size_t len, - uint8_t out[MD5_DIGEST_LENGTH]) -{ - if (mbedtls_md5(data, len, out) != 0) - { - return NULL; - } - - return out; -} diff --git a/crypto/openssl_mbedtls_wrapper/mbedtls/mem.c b/crypto/openssl_mbedtls_wrapper/mbedtls/mem.c deleted file mode 100644 index 38fd65cfe..000000000 --- a/crypto/openssl_mbedtls_wrapper/mbedtls/mem.c +++ /dev/null @@ -1,41 +0,0 @@ -/**************************************************************************** - * apps/crypto/openssl_mbedtls_wrapper/mbedtls/mem.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <mbedtls/constant_time.h> -#include <openssl/mem.h> - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -int CRYPTO_memcmp(const void *in_a, const void *in_b, size_t len) -{ - return mbedtls_ct_memcmp(in_a, in_b, len); -} - -void OPENSSL_free(void *ptr) -{ -} diff --git a/crypto/openssl_mbedtls_wrapper/mbedtls/obj.c b/crypto/openssl_mbedtls_wrapper/mbedtls/obj.c deleted file mode 100644 index c529efa3d..000000000 --- a/crypto/openssl_mbedtls_wrapper/mbedtls/obj.c +++ /dev/null @@ -1,36 +0,0 @@ -/**************************************************************************** - * apps/crypto/openssl_mbedtls_wrapper/mbedtls/obj.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <openssl/obj.h> - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -ASN1_OBJECT *OBJ_nid2obj(int nid) -{ - return NULL; -} diff --git a/crypto/openssl_mbedtls_wrapper/mbedtls/pbkdf.c b/crypto/openssl_mbedtls_wrapper/mbedtls/pbkdf.c deleted file mode 100644 index 8cc890b79..000000000 --- a/crypto/openssl_mbedtls_wrapper/mbedtls/pbkdf.c +++ /dev/null @@ -1,57 +0,0 @@ -/**************************************************************************** - * apps/crypto/openssl_mbedtls_wrapper/mbedtls/pbkdf.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <errno.h> -#include <openssl/evp.h> -#include <openssl/hmac.h> -#include <mbedtls/pkcs5.h> - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -int PKCS5_PBKDF2_HMAC(const char *password, size_t password_len, - const uint8_t *salt, size_t salt_len, - unsigned iterations, const EVP_MD *digest, - size_t key_len, uint8_t *out_key) -{ - mbedtls_md_context_t md_ctx; - int generate_result = 0; - int ret = 0; - mbedtls_md_init(&md_ctx); - ret = mbedtls_md_setup(&md_ctx, (const mbedtls_md_info_t *)digest, 1); - if (ret == 0 - && mbedtls_pkcs5_pbkdf2_hmac(&md_ctx, - (const unsigned char *)password, - password_len, salt, salt_len, - iterations, key_len, out_key) == 0) - { - generate_result = 1; - } - - mbedtls_md_free(&md_ctx); - return generate_result; -} diff --git a/crypto/openssl_mbedtls_wrapper/mbedtls/rand.c b/crypto/openssl_mbedtls_wrapper/mbedtls/rand.c deleted file mode 100644 index 213ce5eee..000000000 --- a/crypto/openssl_mbedtls_wrapper/mbedtls/rand.c +++ /dev/null @@ -1,73 +0,0 @@ -/**************************************************************************** - * apps/crypto/openssl_mbedtls_wrapper/mbedtls/rand.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <mbedtls/ctr_drbg.h> -#include <mbedtls/entropy.h> -#include <openssl/rand.h> -#include <string.h> - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/* RAND_bytes() generates num random bytes using a - * cryptographically secure pseudo random generator - * (CSPRNG) and stores them in buf. - * - * @param buf the buffer to contains the generated random data - * @param num the length of the generated random data - * @return return 1 on success, other value on failure - */ - -int RAND_bytes(unsigned char *buf, int num) -{ - int ret; - mbedtls_entropy_context entropy; - mbedtls_ctr_drbg_context ctr_drbg; - const char *keymaster_personalization = - "softkeymaster_random_generator"; - mbedtls_entropy_init(&entropy); - mbedtls_ctr_drbg_init(&ctr_drbg); - - ret = mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func, - &entropy, (const unsigned char *)keymaster_personalization, - strlen(keymaster_personalization)) == 0 - && mbedtls_ctr_drbg_random(&ctr_drbg, buf, num) == 0 ? 1 : 0; - mbedtls_ctr_drbg_free(&ctr_drbg); - mbedtls_entropy_free(&entropy); - return ret; -} - -/* RAND_add method using to seed the random generator - * This function also do nothing on android - * https://github.com/google/boringssl/blob/ - * 94b477cea5057d9372984a311aba9276f737f748/ - * crypto/rand_extra/rand_extra.c#L39 - */ - -void RAND_add(const void *buf, int num, double randomness) -{ -} diff --git a/crypto/openssl_mbedtls_wrapper/mbedtls/rsa.c b/crypto/openssl_mbedtls_wrapper/mbedtls/rsa.c deleted file mode 100644 index 2e713d09c..000000000 --- a/crypto/openssl_mbedtls_wrapper/mbedtls/rsa.c +++ /dev/null @@ -1,70 +0,0 @@ -/**************************************************************************** - * apps/crypto/openssl_mbedtls_wrapper/mbedtls/rsa.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <mbedtls/rsa.h> -#include <openssl/err.h> -#include <openssl/rsa.h> - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -unsigned RSA_size(const RSA *rsa) -{ - return (mbedtls_rsa_get_len((const mbedtls_rsa_context *)rsa) + 7) / 8; -} - -const BIGNUM *RSA_get0_e(const RSA *rsa) -{ - return NULL; -} - -RSA *RSA_new(void) -{ - return NULL; -} - -void RSA_free(RSA *rsa) -{ -} - -int RSA_generate_key_ex(RSA *rsa, int bits, - const BIGNUM *e_value, BN_GENCB *cb) -{ - return 0; -} - -int RSA_private_encrypt(size_t flen, const uint8_t *from, - uint8_t *to, RSA *rsa, int padding) -{ - return 0; -} - -int RSA_public_decrypt(size_t flen, const uint8_t *from, - uint8_t *to, RSA *rsa, int padding) -{ - return 0; -} diff --git a/crypto/openssl_mbedtls_wrapper/mbedtls/sha.c b/crypto/openssl_mbedtls_wrapper/mbedtls/sha.c deleted file mode 100644 index dba8936cb..000000000 --- a/crypto/openssl_mbedtls_wrapper/mbedtls/sha.c +++ /dev/null @@ -1,76 +0,0 @@ -/**************************************************************************** - * apps/crypto/openssl_mbedtls_wrapper/mbedtls/sha.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <mbedtls/sha1.h> -#include <openssl/sha.h> - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -int SHA1_Init(SHA_CTX *sha) -{ - mbedtls_sha1_init((mbedtls_sha1_context *)sha); - mbedtls_sha1_starts((mbedtls_sha1_context *)sha); - return 0; -} - -int SHA1_Update(SHA_CTX *sha, const void *data, size_t len) -{ - return mbedtls_sha1_update((mbedtls_sha1_context *)sha, data, len); -} - -int SHA1_Final(uint8_t out[SHA_DIGEST_LENGTH], SHA_CTX *sha) -{ - return mbedtls_sha1_finish((mbedtls_sha1_context *)sha, - (unsigned char *)out); -} - -uint8_t *SHA1(const uint8_t *data, size_t len, - uint8_t out[SHA_DIGEST_LENGTH]) -{ - if (mbedtls_sha1(data, len, out) != 0) - { - return NULL; - } - - return out; -} - -int SHA256_Init(SHA256_CTX *sha) -{ - return 0; -} - -int SHA256_Update(SHA256_CTX *sha, const void *data, size_t len) -{ - return 0; -} - -int SHA256_Final(uint8_t out[SHA256_DIGEST_LENGTH], SHA256_CTX *sha) -{ - return 0; -} diff --git a/crypto/openssl_mbedtls_wrapper/mbedtls/ssl_cert.c b/crypto/openssl_mbedtls_wrapper/mbedtls/ssl_cert.c deleted file mode 100644 index 0ac5f281c..000000000 --- a/crypto/openssl_mbedtls_wrapper/mbedtls/ssl_cert.c +++ /dev/null @@ -1,140 +0,0 @@ -/**************************************************************************** - * apps/crypto/openssl_mbedtls_wrapper/mbedtls/ssl_cert.c - * - * SPDX-License-Identifier: Apache-2.0 - * SPDX-FileCopyrightText: 2015-2016 Espressif Systems (Shanghai) PTE LTD - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <assert.h> -#include <stdint.h> -#include <stdlib.h> - -#include <openssl/ssl_dbg.h> -#include <openssl/evp.h> -#include <openssl/ssl_local.h> -#include <openssl/x509.h> -#include <openssl/x509_vfy.h> -#include "ssl_port.h" - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -CERT *__ssl_cert_new(CERT *ic) -{ - CERT *cert; - - X509 *ix; - EVP_PKEY *ipk; - - cert = ssl_mem_zalloc(sizeof(CERT)); - if (!cert) - { - SSL_DEBUG(SSL_CERT_ERROR_LEVEL, "no enough memory > (cert)"); - goto no_mem; - } - - if (ic) - { - ipk = ic->pkey; - ix = ic->x509; - } - else - { - ipk = NULL; - ix = NULL; - } - - cert->pkey = __EVP_PKEY_new(ipk); - if (!cert->pkey) - { - SSL_DEBUG(SSL_CERT_ERROR_LEVEL, "__EVP_PKEY_new() return NULL"); - goto pkey_err; - } - - cert->x509 = __X509_new(ix); - if (!cert->x509) - { - SSL_DEBUG(SSL_CERT_ERROR_LEVEL, "__X509_new() return NULL"); - goto x509_err; - } - - return cert; - -x509_err: - EVP_PKEY_free(cert->pkey); -pkey_err: - ssl_mem_free(cert); -no_mem: - return NULL; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -int SSL_CTX_add_client_CA(SSL_CTX *ctx, X509 *x) -{ - SSL_ASSERT1(ctx); - SSL_ASSERT1(x); - assert(ctx); - if (ctx->client_CA == x) - { - return 1; - } - - X509_free(ctx->client_CA); - ctx->client_CA = x; - return 1; -} - -int SSL_CTX_add_client_CA_ASN1(SSL_CTX *ctx, int len, - const unsigned char *d) -{ - X509 *x; - - x = d2i_X509(NULL, &d, len); - if (!x) - { - SSL_DEBUG(SSL_PKEY_ERROR_LEVEL, "d2i_X509() return NULL"); - return 0; - } - - SSL_ASSERT1(ctx); - X509_free(ctx->client_CA); - ctx->client_CA = x; - - return 1; -} - -CERT *ssl_cert_new(void) -{ - return __ssl_cert_new(NULL); -} - -void ssl_cert_free(CERT *cert) -{ - SSL_ASSERT3(cert); - - X509_free(cert->x509); - - EVP_PKEY_free(cert->pkey); - - ssl_mem_free(cert); -} diff --git a/crypto/openssl_mbedtls_wrapper/mbedtls/ssl_lib.c b/crypto/openssl_mbedtls_wrapper/mbedtls/ssl_lib.c deleted file mode 100644 index b240d38d7..000000000 --- a/crypto/openssl_mbedtls_wrapper/mbedtls/ssl_lib.c +++ /dev/null @@ -1,1406 +0,0 @@ -/**************************************************************************** - * apps/crypto/openssl_mbedtls_wrapper/mbedtls/ssl_lib.c - * - * SPDX-License-Identifier: Apache-2.0 - * SPDX-FileCopyrightText: 2015-2016 Espressif Systems (Shanghai) PTE LTD - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/atomic.h> -#include <openssl/ssl_dbg.h> -#include <openssl/ssl3.h> -#include <openssl/ssl_local.h> -#include "ssl_port.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define SSL_SEND_DATA_MAX_LENGTH 1460 - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -struct alpn_ctx -{ - unsigned char data[23]; - unsigned char len; -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static SSL_SESSION *SSL_SESSION_new(void) -{ - SSL_SESSION *session; - - session = ssl_mem_zalloc(sizeof(SSL_SESSION)); - if (!session) - { - SSL_DEBUG(SSL_LIB_ERROR_LEVEL, "no enough memory > (session)"); - goto failed1; - } - - session->peer = X509_new(); - if (!session->peer) - { - SSL_DEBUG(SSL_LIB_ERROR_LEVEL, "X509_new() return NULL"); - goto failed2; - } - - session->references = 1; - return session; - -failed2: - ssl_mem_free(session); -failed1: - return NULL; -} - -static void -_openssl_alpn_to_mbedtls(struct alpn_ctx *ac, char ***palpn_protos) -{ - unsigned char *p = ac->data; - unsigned char *q; - unsigned char len; - char **alpn_protos; - int count = 0; - - /* find out how many entries he gave us */ - - len = *p++; - while (p - ac->data < ac->len) - { - if (len--) - { - p++; - continue; - } - - count++; - len = *p++; - if (!len) - { - break; - } - } - - if (!len) - { - count++; - } - - if (!count) - { - return; - } - - /* allocate space for count + 1 pointers and the data afterwards */ - - alpn_protos = ssl_mem_zalloc((count + 1) * sizeof(char *) + ac->len + 1); - if (!alpn_protos) - { - return; - } - - *palpn_protos = alpn_protos; - - /* convert to mbedtls format */ - - q = (unsigned char *)alpn_protos + (count + 1) * sizeof(char *); - p = ac->data; - count = 0; - - len = *p++; - alpn_protos[count] = (char *)q; - while (p - ac->data < ac->len) - { - if (len--) - { - *q++ = *p++; - continue; - } - - *q++ = '\0'; - count++; - len = *p++; - alpn_protos[count] = (char *)q; - if (!len) - { - break; - } - } - - if (!len) - { - *q++ = '\0'; - count++; - len = *p++; - alpn_protos[count] = (char *)q; - } - - alpn_protos[count] = NULL; /* last pointer ends list with NULL */ -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -X509_VERIFY_PARAM *SSL_get0_param(SSL *ssl) -{ - return &ssl->param; -} - -X509 *SSL_get_certificate(const SSL *ssl) -{ - SSL_ASSERT2(ssl); - - return ssl->cert->x509; -} - -X509 *SSL_get_peer_certificate(const SSL *ssl) -{ - SSL_ASSERT2(ssl); - - return ssl->session->peer; -} - -int SSL_want(const SSL *ssl) -{ - SSL_ASSERT1(ssl); - - return ssl->rwstate; -} - -int SSL_want_nothing(const SSL *ssl) -{ - SSL_ASSERT1(ssl); - - if (ssl->err) - { - return 1; - } - - return (SSL_want(ssl) == SSL_NOTHING); -} - -int SSL_want_read(const SSL *ssl) -{ - SSL_ASSERT1(ssl); - - if (ssl->err) - { - return 0; - } - - return (SSL_want(ssl) == SSL_READING); -} - -int SSL_want_x509_lookup(const SSL *ssl) -{ - SSL_ASSERT1(ssl); - - return (SSL_want(ssl) == SSL_WRITING); -} - -int SSL_get_error(const SSL *ssl, int ret_code) -{ - int ret = SSL_ERROR_SYSCALL; - - SSL_ASSERT1(ssl); - - if (ret_code > 0) - { - ret = SSL_ERROR_NONE; - } - else if (ret_code < 0) - { - if (ssl->err == SSL_ERROR_WANT_READ || SSL_want_read(ssl)) - { - ret = SSL_ERROR_WANT_READ; - } - else if (ssl->err == SSL_ERROR_WANT_WRITE || SSL_want_write(ssl)) - { - ret = SSL_ERROR_WANT_WRITE; - } - else - { - ret = SSL_ERROR_SYSCALL; - } - } - else - { - if (ssl->shutdown & SSL_RECEIVED_SHUTDOWN) - { - ret = SSL_ERROR_ZERO_RETURN; - } - else - { - ret = SSL_ERROR_SYSCALL; - } - } - - return ret; -} - -SSL_CTX *SSL_CTX_new(const SSL_METHOD *method) -{ - SSL_CTX *ctx; - CERT *cert; - X509 *client_ca; - - if (!method) - { - SSL_DEBUG(SSL_LIB_ERROR_LEVEL, "no no_method"); - return NULL; - } - - client_ca = X509_new(); - if (!client_ca) - { - SSL_DEBUG(SSL_LIB_ERROR_LEVEL, "X509_new() return NULL"); - goto failed1; - } - - cert = ssl_cert_new(); - if (!cert) - { - SSL_DEBUG(SSL_LIB_ERROR_LEVEL, "ssl_cert_new() return NULL"); - goto failed2; - } - - ctx = (SSL_CTX *)ssl_mem_zalloc(sizeof(SSL_CTX)); - if (!ctx) - { - SSL_DEBUG(SSL_LIB_ERROR_LEVEL, "no enough memory > (ctx)"); - goto failed3; - } - - ctx->method = method; - ctx->client_CA = client_ca; - ctx->cert = cert; - ctx->version = method->version; - return ctx; - -failed3: - ssl_cert_free(cert); -failed2: - X509_free(client_ca); -failed1: - return NULL; -} - -void SSL_CTX_free(SSL_CTX *ctx) -{ - SSL_ASSERT3(ctx); - - ssl_cert_free(ctx->cert); - - X509_free(ctx->client_CA); - - if (ctx->alpn_protos) - { - ssl_mem_free(ctx->alpn_protos); - } - - ssl_mem_free(ctx); -} - -int SSL_CTX_set_ssl_version(SSL_CTX *ctx, const SSL_METHOD *meth) -{ - SSL_ASSERT1(ctx); - SSL_ASSERT1(meth); - - ctx->method = meth; - - ctx->version = meth->version; - - return 1; -} - -const SSL_METHOD *SSL_CTX_get_ssl_method(SSL_CTX *ctx) -{ - SSL_ASSERT2(ctx); - - return ctx->method; -} - -SSL *SSL_new(SSL_CTX *ctx) -{ - int ret = 0; - SSL *ssl; - - if (!ctx) - { - SSL_DEBUG(SSL_LIB_ERROR_LEVEL, "no ctx"); - return NULL; - } - - ssl = (SSL *)ssl_mem_zalloc(sizeof(SSL)); - if (!ssl) - { - SSL_DEBUG(SSL_LIB_ERROR_LEVEL, "no enough memory > (ssl)"); - goto failed1; - } - - ssl->session = SSL_SESSION_new(); - if (!ssl->session) - { - SSL_DEBUG(SSL_LIB_ERROR_LEVEL, "SSL_SESSION_new() return NULL"); - goto failed2; - } - - ssl->cert = __ssl_cert_new(ctx->cert); - if (!ssl->cert) - { - SSL_DEBUG(SSL_LIB_ERROR_LEVEL, "__ssl_cert_new() return NULL"); - goto failed3; - } - - ssl->client_CA = __X509_new(ctx->client_CA); - if (!ssl->client_CA) - { - SSL_DEBUG(SSL_LIB_ERROR_LEVEL, "__X509_new() return NULL"); - goto failed4; - } - - ssl->ctx = ctx; - ssl->method = ctx->method; - - ssl->version = ctx->version; - ssl->options = ctx->options; - - ssl->verify_mode = ctx->verify_mode; - - ret = SSL_METHOD_CALL(new, ssl); - if (ret) - { - SSL_DEBUG(SSL_LIB_ERROR_LEVEL, "SSL_METHOD_CALL(new) return %d", ret); - goto failed5; - } - - _ssl_set_alpn_list(ssl); - - ssl->rwstate = SSL_NOTHING; - - return ssl; - -failed5: - X509_free(ssl->client_CA); -failed4: - ssl_cert_free(ssl->cert); -failed3: - SSL_SESSION_free(ssl->session); -failed2: - ssl_mem_free(ssl); -failed1: - return NULL; -} - -void SSL_free(SSL *ssl) -{ - SSL_ASSERT3(ssl); - - SSL_METHOD_CALL(free, ssl); - - X509_free(ssl->client_CA); - - ssl_cert_free(ssl->cert); - - SSL_SESSION_free(ssl->session); - - if (ssl->alpn_protos) - { - ssl_mem_free(ssl->alpn_protos); - } - - ssl_mem_free(ssl); -} - -int SSL_do_handshake(SSL *ssl) -{ - int ret; - - SSL_ASSERT1(ssl); - - ret = SSL_METHOD_CALL(handshake, ssl); - - return ret; -} - -int SSL_connect(SSL *ssl) -{ - SSL_ASSERT1(ssl); - - return SSL_do_handshake(ssl); -} - -int SSL_accept(SSL *ssl) -{ - SSL_ASSERT1(ssl); - - return SSL_do_handshake(ssl); -} - -int SSL_shutdown(SSL *ssl) -{ - int ret; - - SSL_ASSERT1(ssl); - - if (SSL_get_state(ssl) != TLS_ST_OK) - { - return 1; - } - - ret = SSL_METHOD_CALL(shutdown, ssl); - - return ret; -} - -int SSL_clear(SSL *ssl) -{ - int ret; - - SSL_ASSERT1(ssl); - - ret = SSL_shutdown(ssl); - if (1 != ret) - { - SSL_DEBUG(SSL_LIB_ERROR_LEVEL, "SSL_shutdown return %d", ret); - goto failed1; - } - - SSL_METHOD_CALL(free, ssl); - - ret = SSL_METHOD_CALL(new, ssl); - if (!ret) - { - SSL_DEBUG(SSL_LIB_ERROR_LEVEL, "SSL_METHOD_CALL(new) return %d", ret); - goto failed1; - } - - return 1; - -failed1: - return ret; -} - -int SSL_read(SSL *ssl, void *buffer, int len) -{ - int ret; - - SSL_ASSERT1(ssl); - SSL_ASSERT1(buffer); - SSL_ASSERT1(len); - - ssl->rwstate = SSL_READING; - - ret = SSL_METHOD_CALL(read, ssl, buffer, len); - - if (ret == len) - { - ssl->rwstate = SSL_NOTHING; - } - - return ret; -} - -int SSL_write(SSL *ssl, const void *buffer, int len) -{ - int ret; - int send_bytes; - int bytes; - const unsigned char *pbuf; - - SSL_ASSERT1(ssl); - SSL_ASSERT1(buffer); - SSL_ASSERT1(len); - - ssl->rwstate = SSL_WRITING; - - send_bytes = len; - pbuf = (const unsigned char *)buffer; - - do - { - if (send_bytes > SSL_SEND_DATA_MAX_LENGTH) - { - bytes = SSL_SEND_DATA_MAX_LENGTH; - } - else - { - bytes = send_bytes; - } - - if (ssl->interrupted_remaining_write) - { - bytes = ssl->interrupted_remaining_write; - ssl->interrupted_remaining_write = 0; - } - - ret = SSL_METHOD_CALL(send, ssl, pbuf, bytes); - - /* the return is a NEGATIVE OpenSSL error code, or the length sent */ - - if (ret > 0) - { - pbuf += ret; - send_bytes -= ret; - } - else - { - ssl->interrupted_remaining_write = bytes; - } - } - while (ret > 0 && send_bytes && ret == bytes); - - if (ret >= 0) - { - ret = len - send_bytes; - if (!ret) - { - ssl->rwstate = SSL_NOTHING; - } - } - else - { - if (send_bytes == len) - { - ret = -1; - } - else - { - ret = len - send_bytes; - } - } - - return ret; -} - -SSL_CTX *SSL_get_SSL_CTX(const SSL *ssl) -{ - SSL_ASSERT2(ssl); - - return ssl->ctx; -} - -const SSL_METHOD *SSL_get_ssl_method(SSL *ssl) -{ - SSL_ASSERT2(ssl); - - return ssl->method; -} - -int SSL_set_ssl_method(SSL *ssl, const SSL_METHOD *method) -{ - int ret; - - SSL_ASSERT1(ssl); - SSL_ASSERT1(method); - - if (ssl->version != method->version) - { - ret = SSL_shutdown(ssl); - if (1 != ret) - { - SSL_DEBUG(SSL_LIB_ERROR_LEVEL, "SSL_shutdown return %d", ret); - goto failed1; - } - - SSL_METHOD_CALL(free, ssl); - - ssl->method = method; - - ret = SSL_METHOD_CALL(new, ssl); - if (!ret) - { - SSL_DEBUG(SSL_LIB_ERROR_LEVEL, - "SSL_METHOD_CALL(new) return %d", ret); - goto failed1; - } - } - else - { - ssl->method = method; - } - - return 1; - -failed1: - return ret; -} - -int SSL_get_shutdown(const SSL *ssl) -{ - SSL_ASSERT1(ssl); - - return ssl->shutdown; -} - -void SSL_set_shutdown(SSL *ssl, int mode) -{ - SSL_ASSERT3(ssl); - - ssl->shutdown = mode; -} - -int SSL_pending(const SSL *ssl) -{ - int ret; - - SSL_ASSERT1(ssl); - - ret = SSL_METHOD_CALL(pending, ssl); - - return ret; -} - -int SSL_has_pending(const SSL *ssl) -{ - int ret; - - SSL_ASSERT1(ssl); - - if (SSL_pending(ssl)) - { - ret = 1; - } - else - { - ret = 0; - } - - return ret; -} - -unsigned long SSL_CTX_clear_options(SSL_CTX *ctx, unsigned long op) -{ - SSL_ASSERT1(ctx); - - return ctx->options &= ~op; -} - -unsigned long SSL_CTX_get_options(SSL_CTX *ctx) -{ - SSL_ASSERT1(ctx); - - return ctx->options; -} - -unsigned long SSL_clear_options(SSL *ssl, unsigned long op) -{ - SSL_ASSERT1(ssl); - - return ssl->options & ~op; -} - -unsigned long SSL_get_options(SSL *ssl) -{ - SSL_ASSERT1(ssl); - - return ssl->options; -} - -unsigned long SSL_set_options(SSL *ssl, unsigned long op) -{ - SSL_ASSERT1(ssl); - - return ssl->options |= op; -} - -int SSL_get_fd(const SSL *ssl) -{ - int ret; - - SSL_ASSERT1(ssl); - - ret = SSL_METHOD_CALL(get_fd, ssl, 0); - - return ret; -} - -int SSL_get_rfd(const SSL *ssl) -{ - int ret; - - SSL_ASSERT1(ssl); - - ret = SSL_METHOD_CALL(get_fd, ssl, 0); - - return ret; -} - -int SSL_get_wfd(const SSL *ssl) -{ - int ret; - - SSL_ASSERT1(ssl); - - ret = SSL_METHOD_CALL(get_fd, ssl, 0); - - return ret; -} - -int SSL_set_fd(SSL *ssl, int fd) -{ - SSL_ASSERT1(ssl); - SSL_ASSERT1(fd >= 0); - - SSL_METHOD_CALL(set_fd, ssl, fd, 0); - - return 1; -} - -int SSL_set_rfd(SSL *ssl, int fd) -{ - SSL_ASSERT1(ssl); - SSL_ASSERT1(fd >= 0); - - SSL_METHOD_CALL(set_fd, ssl, fd, 0); - - return 1; -} - -int SSL_set_wfd(SSL *ssl, int fd) -{ - SSL_ASSERT1(ssl); - SSL_ASSERT1(fd >= 0); - - SSL_METHOD_CALL(set_fd, ssl, fd, 0); - - return 1; -} - -int SSL_version(const SSL *ssl) -{ - SSL_ASSERT1(ssl); - - return ssl->version; -} - -const char *SSL_alert_type_string(int value) -{ - const char *str; - - switch (value >> 8) - { - case SSL3_AL_WARNING: - str = "W"; - break; - case SSL3_AL_FATAL: - str = "F"; - break; - default: - str = "U"; - break; - } - - return str; -} - -void SSL_CTX_set_default_read_buffer_len(SSL_CTX *ctx, size_t len) -{ - SSL_ASSERT3(ctx); - - ctx->read_buffer_len = (int)len; -} - -void SSL_set_default_read_buffer_len(SSL *ssl, size_t len) -{ - SSL_ASSERT3(ssl); - SSL_ASSERT3(len); - - SSL_METHOD_CALL(set_bufflen, ssl, (int)len); -} - -void SSL_set_info_callback(SSL *ssl, - void (*cb) (const SSL *ssl, int type, int val)) -{ - SSL_ASSERT3(ssl); - - ssl->info_callback = cb; -} - -int SSL_CTX_up_ref(SSL_CTX *ctx) -{ - SSL_ASSERT1(ctx); - - /* no support multi-thread SSL here */ - - ctx->references++; - - return 1; -} - -void SSL_set_security_level(SSL *ssl, int level) -{ - SSL_ASSERT3(ssl); - - ssl->cert->sec_level = level; -} - -int SSL_get_security_level(const SSL *ssl) -{ - SSL_ASSERT1(ssl); - - return ssl->cert->sec_level; -} - -int SSL_CTX_get_verify_mode(const SSL_CTX *ctx) -{ - SSL_ASSERT1(ctx); - - return ctx->verify_mode; -} - -long SSL_CTX_set_timeout(SSL_CTX *ctx, long t) -{ - long l; - - SSL_ASSERT1(ctx); - - l = ctx->session_timeout; - ctx->session_timeout = t; - - return l; -} - -long SSL_CTX_get_timeout(const SSL_CTX *ctx) -{ - SSL_ASSERT1(ctx); - - return ctx->session_timeout; -} - -void SSL_set_read_ahead(SSL *ssl, int yes) -{ - SSL_ASSERT3(ssl); - - ssl->rlayer.read_ahead = yes; -} - -void SSL_CTX_set_read_ahead(SSL_CTX *ctx, int yes) -{ - SSL_ASSERT3(ctx); - - ctx->read_ahead = yes; -} - -int SSL_get_read_ahead(const SSL *ssl) -{ - SSL_ASSERT1(ssl); - - return ssl->rlayer.read_ahead; -} - -long SSL_CTX_get_read_ahead(SSL_CTX *ctx) -{ - SSL_ASSERT1(ctx); - - return ctx->read_ahead; -} - -long SSL_CTX_get_default_read_ahead(SSL_CTX *ctx) -{ - SSL_ASSERT1(ctx); - - return ctx->read_ahead; -} - -long SSL_set_time(SSL *ssl, long t) -{ - SSL_ASSERT1(ssl); - - ssl->session->time = t; - - return t; -} - -long SSL_set_timeout(SSL *ssl, long t) -{ - SSL_ASSERT1(ssl); - - ssl->session->timeout = t; - - return t; -} - -long SSL_get_verify_result(const SSL *ssl) -{ - SSL_ASSERT1(ssl); - - return SSL_METHOD_CALL(get_verify_result, ssl); -} - -int SSL_CTX_get_verify_depth(const SSL_CTX *ctx) -{ - SSL_ASSERT1(ctx); - - return ctx->param.depth; -} - -void SSL_CTX_set_verify_depth(SSL_CTX *ctx, int depth) -{ - SSL_ASSERT3(ctx); - - ctx->param.depth = depth; -} - -int SSL_get_verify_depth(const SSL *ssl) -{ - SSL_ASSERT1(ssl); - - return ssl->param.depth; -} - -void SSL_set_verify_depth(SSL *ssl, int depth) -{ - SSL_ASSERT3(ssl); - - ssl->param.depth = depth; -} - -void SSL_CTX_set_verify(SSL_CTX *ctx, int mode, - int (*verify_callback)(int, X509_STORE_CTX *)) -{ - SSL_ASSERT3(ctx); - - ctx->verify_mode = mode; - ctx->default_verify_callback = verify_callback; -} - -void SSL_set_verify(SSL *ssl, int mode, - int (*verify_callback)(int, X509_STORE_CTX *)) -{ - SSL_ASSERT3(ssl); - - ssl->verify_mode = mode; - ssl->verify_callback = verify_callback; -} - -void *SSL_CTX_get_ex_data(const SSL_CTX *ctx, int idx) -{ - return NULL; -} - -void SSL_CTX_set_alpn_select_cb(SSL_CTX *ctx, next_proto_cb cb, void *arg) -{ - struct alpn_ctx *ac = arg; - - ctx->alpn_cb = cb; - - _openssl_alpn_to_mbedtls(ac, (char * **)&ctx->alpn_protos); -} - -void SSL_set_alpn_select_cb(SSL *ssl, void *arg) -{ - struct alpn_ctx *ac = arg; - - _openssl_alpn_to_mbedtls(ac, (char * **)&ssl->alpn_protos); - - _ssl_set_alpn_list(ssl); -} - -SSL_SESSION *SSL_get1_session(SSL *ssl) -{ - SSL_ASSERT2(ssl); - - atomic_fetch_add(&ssl->session->references, 1); - return ssl->session; -} - -void SSL_SESSION_free(SSL_SESSION *session) -{ - SSL_ASSERT3(session); - - if (atomic_fetch_sub(&session->references, 1) == 1) - { - X509_free(session->peer); - ssl_mem_free(session); - } -} - -int SSL_set_session(SSL *s, SSL_SESSION *session) -{ - SSL_ASSERT1(s); - SSL_ASSERT1(session); - - SSL_SESSION_free(s->session); - s->session = session; - return 1; -} - -const char *SSLeay_version(int t) -{ - return "not available"; -} - -const char *SSL_state_string_long(const SSL *s) -{ - SSL_ASSERT2(s); - - switch (SSL_get_state(s)) - { - case TLS_ST_CR_CERT_STATUS: - return "SSLv3/TLS read certificate status"; - case TLS_ST_CW_NEXT_PROTO: - return "SSLv3/TLS write next proto"; - case TLS_ST_SR_NEXT_PROTO: - return "SSLv3/TLS read next proto"; - case TLS_ST_SW_CERT_STATUS: - return "SSLv3/TLS write certificate status"; - case TLS_ST_BEFORE: - return "before SSL initialization"; - case TLS_ST_OK: - return "SSL negotiation finished successfully"; - case TLS_ST_CW_CLNT_HELLO: - return "SSLv3/TLS write client hello"; - case TLS_ST_CR_SRVR_HELLO: - return "SSLv3/TLS read server hello"; - case TLS_ST_CR_CERT: - return "SSLv3/TLS read server certificate"; - case TLS_ST_CR_COMP_CERT: - return "TLSv1.3 read server compressed certificate"; - case TLS_ST_CR_KEY_EXCH: - return "SSLv3/TLS read server key exchange"; - case TLS_ST_CR_CERT_REQ: - return "SSLv3/TLS read server certificate request"; - case TLS_ST_CR_SESSION_TICKET: - return "SSLv3/TLS read server session ticket"; - case TLS_ST_CR_SRVR_DONE: - return "SSLv3/TLS read server done"; - case TLS_ST_CW_CERT: - return "SSLv3/TLS write client certificate"; - case TLS_ST_CW_COMP_CERT: - return "TLSv1.3 write client compressed certificate"; - case TLS_ST_CW_KEY_EXCH: - return "SSLv3/TLS write client key exchange"; - case TLS_ST_CW_CERT_VRFY: - return "SSLv3/TLS write certificate verify"; - case TLS_ST_CW_CHANGE: - case TLS_ST_SW_CHANGE: - return "SSLv3/TLS write change cipher spec"; - case TLS_ST_CW_FINISHED: - case TLS_ST_SW_FINISHED: - return "SSLv3/TLS write finished"; - case TLS_ST_CR_CHANGE: - case TLS_ST_SR_CHANGE: - return "SSLv3/TLS read change cipher spec"; - case TLS_ST_CR_FINISHED: - case TLS_ST_SR_FINISHED: - return "SSLv3/TLS read finished"; - case TLS_ST_SR_CLNT_HELLO: - return "SSLv3/TLS read client hello"; - case TLS_ST_SW_HELLO_REQ: - return "SSLv3/TLS write hello request"; - case TLS_ST_SW_SRVR_HELLO: - return "SSLv3/TLS write server hello"; - case TLS_ST_SW_CERT: - return "SSLv3/TLS write certificate"; - case TLS_ST_SW_COMP_CERT: - return "TLSv1.3 write server compressed certificate"; - case TLS_ST_SW_KEY_EXCH: - return "SSLv3/TLS write key exchange"; - case TLS_ST_SW_CERT_REQ: - return "SSLv3/TLS write certificate request"; - case TLS_ST_SW_SESSION_TICKET: - return "SSLv3/TLS write session ticket"; - case TLS_ST_SW_SRVR_DONE: - return "SSLv3/TLS write server done"; - case TLS_ST_SR_CERT: - return "SSLv3/TLS read client certificate"; - case TLS_ST_SR_COMP_CERT: - return "TLSv1.3 read client compressed certificate"; - case TLS_ST_SR_KEY_EXCH: - return "SSLv3/TLS read client key exchange"; - case TLS_ST_SR_CERT_VRFY: - return "SSLv3/TLS read certificate verify"; - case DTLS_ST_CR_HELLO_VERIFY_REQUEST: - return "DTLS1 read hello verify request"; - case DTLS_ST_SW_HELLO_VERIFY_REQUEST: - return "DTLS1 write hello verify request"; - case TLS_ST_SW_ENCRYPTED_EXTENSIONS: - return "TLSv1.3 write encrypted extensions"; - case TLS_ST_CR_ENCRYPTED_EXTENSIONS: - return "TLSv1.3 read encrypted extensions"; - case TLS_ST_CR_CERT_VRFY: - return "TLSv1.3 read server certificate verify"; - case TLS_ST_SW_CERT_VRFY: - return "TLSv1.3 write server certificate verify"; - case TLS_ST_CR_HELLO_REQ: - return "SSLv3/TLS read hello request"; - case TLS_ST_SW_KEY_UPDATE: - return "TLSv1.3 write server key update"; - case TLS_ST_CW_KEY_UPDATE: - return "TLSv1.3 write client key update"; - case TLS_ST_SR_KEY_UPDATE: - return "TLSv1.3 read client key update"; - case TLS_ST_CR_KEY_UPDATE: - return "TLSv1.3 read server key update"; - case TLS_ST_EARLY_DATA: - return "TLSv1.3 early data"; - case TLS_ST_PENDING_EARLY_DATA_END: - return "TLSv1.3 pending early data end"; - case TLS_ST_CW_END_OF_EARLY_DATA: - return "TLSv1.3 write end of early data"; - case TLS_ST_SR_END_OF_EARLY_DATA: - return "TLSv1.3 read end of early data"; - default: - return "unknown state"; - } -} - -const char *SSL_get_cipher_name(const SSL *s) -{ - SSL_ASSERT2(s); - SSL_ASSERT2(s->session); - - return s->session->cipher->name ? s->session->cipher->name : "(NONE)"; -} - -const char *SSL_alert_type_string_long(int value) -{ - switch (value >> 8) - { - case SSL3_AL_WARNING: - return "warning"; - case SSL3_AL_FATAL: - return "fatal"; - } - - return "unknown"; -} - -const char *SSL_alert_desc_string_long(int value) -{ - switch (value & 0xff) - { - case SSL3_AD_CLOSE_NOTIFY: - return "close notify"; - case SSL3_AD_UNEXPECTED_MESSAGE: - return "unexpected message"; - case SSL3_AD_BAD_RECORD_MAC: - return "bad record mac"; - case SSL3_AD_DECOMPRESSION_FAILURE: - return "decompression failure"; - case SSL3_AD_HANDSHAKE_FAILURE: - return "handshake failure"; - case SSL3_AD_NO_CERTIFICATE: - return "no certificate"; - case SSL3_AD_BAD_CERTIFICATE: - return "bad certificate"; - case SSL3_AD_UNSUPPORTED_CERTIFICATE: - return "unsupported certificate"; - case SSL3_AD_CERTIFICATE_REVOKED: - return "certificate revoked"; - case SSL3_AD_CERTIFICATE_EXPIRED: - return "certificate expired"; - case SSL3_AD_CERTIFICATE_UNKNOWN: - return "certificate unknown"; - case SSL3_AD_ILLEGAL_PARAMETER: - return "illegal parameter"; - case TLS1_AD_DECRYPTION_FAILED: - return "decryption failed"; - case TLS1_AD_RECORD_OVERFLOW: - return "record overflow"; - case TLS1_AD_UNKNOWN_CA: - return "unknown CA"; - case TLS1_AD_ACCESS_DENIED: - return "access denied"; - case TLS1_AD_DECODE_ERROR: - return "decode error"; - case TLS1_AD_DECRYPT_ERROR: - return "decrypt error"; - case TLS1_AD_EXPORT_RESTRICTION: - return "export restriction"; - case TLS1_AD_PROTOCOL_VERSION: - return "protocol version"; - case TLS1_AD_INSUFFICIENT_SECURITY: - return "insufficient security"; - case TLS1_AD_INTERNAL_ERROR: - return "internal error"; - case TLS1_AD_USER_CANCELLED: - return "user canceled"; - case TLS1_AD_NO_RENEGOTIATION: - return "no renegotiation"; - case TLS1_AD_UNSUPPORTED_EXTENSION: - return "unsupported extension"; - case TLS1_AD_CERTIFICATE_UNOBTAINABLE: - return "certificate unobtainable"; - case TLS1_AD_UNRECOGNIZED_NAME: - return "unrecognized name"; - case TLS1_AD_BAD_CERTIFICATE_STATUS_RESPONSE: - return "bad certificate status response"; - case TLS1_AD_BAD_CERTIFICATE_HASH_VALUE: - return "bad certificate hash value"; - case TLS1_AD_UNKNOWN_PSK_IDENTITY: - return "unknown PSK identity"; - case TLS1_AD_NO_APPLICATION_PROTOCOL: - return "no application protocol"; - default: - return "unknown"; - } -} - -void SSL_CTX_set_default_passwd_cb(SSL_CTX *ctx, pem_password_cb *cb) -{ - ctx->default_passwd_callback = cb; -} - -void SSL_CTX_set_default_passwd_cb_userdata(SSL_CTX *ctx, void *u) -{ - ctx->default_passwd_callback_userdata = u; -} - -void SSL_CTX_set_psk_client_callback(SSL_CTX *ctx, SSL_psk_client_cb_func cb) -{ - ctx->psk_client_callback = cb; -} - -int SSL_CTX_set_default_verify_paths(SSL_CTX *ctx) -{ - return 0; -} - -long SSL_CTX_set_mode(SSL_CTX *ctx, long larg) -{ - return ctx->mode |= larg; -} - -void SSL_CTX_set_info_callback(SSL_CTX *ctx, - void (*cb)(const SSL *ssl, int type, int val)) -{ - ctx->info_callback = cb; -} - -void SSL_CTX_set_msg_callback(SSL_CTX *ctx, - void (*cb)(int write_p, int version, - int content_type, const void *buf, - size_t len, SSL *ssl, void *arg)) -{ - ctx->msg_callback = cb; -} - -long SSL_set_tlsext_host_name(SSL *s, void *parg) -{ - size_t len; - - SSL_ASSERT1(s); - SSL_ASSERT1(s->session); - - if (parg == NULL) - { - return 1; - } - - len = strlen(parg); - if (len == 0 || len > TLSEXT_MAXLEN_host_name) - { - return 0; - } - - memset(s->session->ext.hostname, 0, TLSEXT_MAXLEN_host_name); - memcpy(s->session->ext.hostname, parg, len); - return 1; -} - -int SSL_CTX_load_verify_file(SSL_CTX *ctx, const char *CAfile) -{ - X509 *x; - int ret; - - SSL_ASSERT1(ctx); - SSL_ASSERT1(CAfile); - - x = X509_new(); - ret = X509_METHOD_CALL(load_file, x, CAfile); - if (ret) - { - X509_free(x); - return 0; - } - - SSL_CTX_add_client_CA(ctx, x); - return 1; -} - -int SSL_CTX_load_verify_dir(SSL_CTX *ctx, const char *CApath) -{ - X509 *x; - int ret; - - SSL_ASSERT1(ctx); - SSL_ASSERT1(CApath); - - x = X509_new(); - ret = X509_METHOD_CALL(load_path, x, CApath); - if (ret) - { - X509_free(x); - return 0; - } - - SSL_CTX_add_client_CA(ctx, x); - return 1; -} - -int SSL_CTX_load_verify_locations(SSL_CTX *ctx, const char *CAfile, - const char *CApath) -{ - if (CAfile == NULL && CApath == NULL) - { - return 0; - } - - if (CAfile != NULL && !SSL_CTX_load_verify_file(ctx, CAfile)) - { - return 0; - } - - if (CApath != NULL && !SSL_CTX_load_verify_dir(ctx, CApath)) - { - return 0; - } - - return 1; -} - -int SSL_get_ex_new_index(long argl, void *argp, - CRYPTO_EX_new *new_func, CRYPTO_EX_dup *dup_func, - CRYPTO_EX_free *free_func) -{ - return 0; -} - -const char *SSL_get_cipher_list(const SSL *s, int n) -{ - return NULL; -} - -int SSL_CTX_set_ex_data(SSL_CTX *s, int idx, void *arg) -{ - return 0; -} - -int SSL_CTX_set_cipher_list(SSL_CTX *ctx, const char *str) -{ - return 0; -} diff --git a/crypto/openssl_mbedtls_wrapper/mbedtls/ssl_methods.c b/crypto/openssl_mbedtls_wrapper/mbedtls/ssl_methods.c deleted file mode 100644 index a5b8e5bb0..000000000 --- a/crypto/openssl_mbedtls_wrapper/mbedtls/ssl_methods.c +++ /dev/null @@ -1,107 +0,0 @@ -/**************************************************************************** - * apps/crypto/openssl_mbedtls_wrapper/mbedtls/ssl_methods.c - * - * SPDX-License-Identifier: Apache-2.0 - * SPDX-FileCopyrightText: 2015-2016 Espressif Systems (Shanghai) PTE LTD - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <openssl/tls1.h> -#include <openssl/ssl_local.h> -#include <openssl/ssl3.h> -#include "ssl_methods.h" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/** - * TLS method function collection - */ - -IMPLEMENT_TLS_METHOD_FUNC(TLS_method_func, - ssl_pm_new, ssl_pm_free, - ssl_pm_handshake, ssl_pm_shutdown, ssl_pm_clear, - ssl_pm_read, ssl_pm_send, ssl_pm_pending, - ssl_pm_set_fd, ssl_pm_get_fd, - ssl_pm_set_bufflen, - ssl_pm_get_verify_result, - ssl_pm_get_state); - -/** - * TLS or SSL client method collection - */ - -IMPLEMENT_TLS_METHOD(TLS_ANY_VERSION, 0, TLS_method_func, TLS_client_method); - -IMPLEMENT_TLS_METHOD(TLS1_2_VERSION, 0, - TLS_method_func, TLSv1_2_client_method); - -IMPLEMENT_TLS_METHOD(TLS1_1_VERSION, 0, - TLS_method_func, TLSv1_1_client_method); - -IMPLEMENT_TLS_METHOD(TLS1_VERSION, 0, TLS_method_func, TLSv1_client_method); - -IMPLEMENT_SSL_METHOD(SSL3_VERSION, 0, TLS_method_func, SSLv3_client_method); - -/** - * TLS or SSL server method collection - */ - -IMPLEMENT_TLS_METHOD(TLS_ANY_VERSION, 1, TLS_method_func, TLS_server_method); - -IMPLEMENT_TLS_METHOD(TLS1_1_VERSION, 1, - TLS_method_func, TLSv1_1_server_method); - -IMPLEMENT_TLS_METHOD(TLS1_2_VERSION, 1, - TLS_method_func, TLSv1_2_server_method); - -IMPLEMENT_TLS_METHOD(TLS1_VERSION, 0, TLS_method_func, TLSv1_server_method); - -IMPLEMENT_SSL_METHOD(SSL3_VERSION, 1, TLS_method_func, SSLv3_server_method); - -/** - * TLS or SSL method collection - */ - -IMPLEMENT_TLS_METHOD(TLS_ANY_VERSION, -1, TLS_method_func, TLS_method); - -IMPLEMENT_SSL_METHOD(TLS1_2_VERSION, -1, TLS_method_func, TLSv1_2_method); - -IMPLEMENT_SSL_METHOD(TLS1_1_VERSION, -1, TLS_method_func, TLSv1_1_method); - -IMPLEMENT_SSL_METHOD(TLS1_VERSION, -1, TLS_method_func, TLSv1_method); - -IMPLEMENT_SSL_METHOD(SSL3_VERSION, -1, TLS_method_func, SSLv3_method); - -/** - * @brief get X509 object method - */ - -IMPLEMENT_X509_METHOD(X509_method, - x509_pm_new, x509_pm_free, - x509_pm_load, x509_pm_load_file, - x509_pm_load_path, x509_pm_show_info); - -/** - * @brief get private key object method - */ - -IMPLEMENT_PKEY_METHOD(EVP_PKEY_method, - pkey_pm_new, pkey_pm_free, - pkey_pm_load); diff --git a/crypto/openssl_mbedtls_wrapper/mbedtls/ssl_methods.h b/crypto/openssl_mbedtls_wrapper/mbedtls/ssl_methods.h deleted file mode 100644 index c93546fc7..000000000 --- a/crypto/openssl_mbedtls_wrapper/mbedtls/ssl_methods.h +++ /dev/null @@ -1,154 +0,0 @@ -/**************************************************************************** - * apps/crypto/openssl_mbedtls_wrapper/mbedtls/ssl_methods.h - * - * SPDX-License-Identifier: Apache-2.0 - * SPDX-FileCopyrightText: 2015-2016 Espressif Systems (Shanghai) PTE LTD - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - ****************************************************************************/ - -#ifndef OPENSSL_MBEDTLS_WRAPPER_SSL_METHODS_H -#define OPENSSL_MBEDTLS_WRAPPER_SSL_METHODS_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <openssl/ssl.h> -#include "ssl_pm.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* TLS method function implement */ - -#define IMPLEMENT_TLS_METHOD_FUNC(func_name, \ - new, free, \ - handshake, shutdown, clear, \ - read, send, pending, \ - set_fd, get_fd, \ - set_bufflen, \ - get_verify_result, \ - get_state) \ - static const SSL_METHOD_FUNC func_name = \ - { \ - new, \ - free, \ - handshake, \ - shutdown, \ - clear, \ - read, \ - send, \ - pending, \ - set_fd, \ - get_fd, \ - set_bufflen, \ - get_verify_result, \ - get_state \ - }; - -#define IMPLEMENT_TLS_METHOD(ver, mode, fun, func_name) \ - const SSL_METHOD* func_name(void) \ - { \ - static const SSL_METHOD func_name##_data = \ - { \ - ver, \ - mode, \ - &(fun), \ - }; \ - return &func_name##_data; \ - } - -#define IMPLEMENT_SSL_METHOD(ver, mode, fun, func_name) \ - const SSL_METHOD* func_name(void) \ - { \ - static const SSL_METHOD func_name##_data = \ - { \ - ver, \ - mode, \ - &(fun), \ - }; \ - return &func_name##_data; \ - } - -#define IMPLEMENT_X509_METHOD(func_name, \ - new, \ - free, \ - load, \ - load_file, \ - load_path, \ - show_info) \ - const X509_METHOD* func_name(void) \ - { \ - static const X509_METHOD func_name##_data = \ - { \ - new, \ - free, \ - load, \ - load_file, \ - load_path, \ - show_info \ - }; \ - return &func_name##_data; \ - } - -#define IMPLEMENT_PKEY_METHOD(func_name, \ - new, \ - free, \ - load) \ - const PKEY_METHOD* func_name(void) \ - { \ - static const PKEY_METHOD func_name##_data = \ - { \ - new, \ - free, \ - load \ - }; \ - return &func_name##_data; \ - } - -#ifdef __cplusplus -extern "C" -{ -#endif - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/** - * @brief get X509 object method - * - * @param none - * - * @return X509 object method point - */ - -const X509_METHOD *X509_method(void); - -/** - * @brief get private key object method - * - * @param none - * - * @return private key object method point - */ - -const PKEY_METHOD *EVP_PKEY_method(void); - -#ifdef __cplusplus -} -#endif - -#endif /* OPENSSL_MBEDTLS_WRAPPER_SSL_METHODS_H */ diff --git a/crypto/openssl_mbedtls_wrapper/mbedtls/ssl_pm.c b/crypto/openssl_mbedtls_wrapper/mbedtls/ssl_pm.c deleted file mode 100644 index 4924969c9..000000000 --- a/crypto/openssl_mbedtls_wrapper/mbedtls/ssl_pm.c +++ /dev/null @@ -1,1105 +0,0 @@ -/**************************************************************************** - * apps/crypto/openssl_mbedtls_wrapper/mbedtls/ssl_pm.c - * - * SPDX-License-Identifier: Apache-2.0 - * SPDX-FileCopyrightText: 2015-2016 Espressif Systems (Shanghai) PTE LTD - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <errno.h> - -#include "ssl_pm.h" -#include "ssl_port.h" -#include <openssl/ssl_dbg.h> -#include <openssl/ssl_local.h> -#include <openssl/tls1.h> -#include <openssl/evp.h> - -/* mbedtls include */ -#include "mbedtls/platform.h" -#include "mbedtls/net_sockets.h" -#include "mbedtls/debug.h" -#include "mbedtls/entropy.h" -#include "mbedtls/ctr_drbg.h" -#include "mbedtls/error.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define X509_INFO_STRING_LENGTH 8192 -#define READ_TIMEOUT_MS 50000 /* 50 seconds */ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -struct ssl_pm -{ - /* local socket file description */ - - mbedtls_net_context fd; - - /* remote client socket file description */ - - mbedtls_net_context cl_fd; - mbedtls_ssl_config conf; - mbedtls_ctr_drbg_context ctr_drbg; - mbedtls_ssl_context ssl; - mbedtls_entropy_context entropy; - SSL *owner; -}; - -struct x509_pm -{ - mbedtls_x509_crt x509_crt; - mbedtls_x509_crt *ex_crt; -}; - -struct pkey_pm -{ - mbedtls_pk_context *pkey; - mbedtls_pk_context *ex_pkey; -}; - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -unsigned int max_content_len; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/** - * @brief mbedtls debug function - */ - -static void ssl_platform_debug(void *ctx, int level, - const char *file, int line, - const char *str) -{ - /* Shorten 'file' from the whole file path to just the filename - - * This is a bit wasteful because the macros are compiled in with - * the full _FILE_ path in each case. - */ - - printf("%s:%d %s", file, line, str); -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/** - * @brief create SSL low-level object - */ - -int ssl_pm_new(SSL *ssl) -{ - struct ssl_pm *ssl_pm; - int ret; - - const unsigned char pers[] = "OpenSSL PM"; - size_t pers_len = sizeof(pers); - - int endpoint; - int version; - - const SSL_METHOD *method = ssl->method; - - ssl_pm = ssl_mem_zalloc(sizeof(struct ssl_pm)); - if (!ssl_pm) - { - SSL_DEBUG(SSL_PLATFORM_ERROR_LEVEL, "no enough memory > (ssl_pm)"); - goto no_mem; - } - - ssl_pm->owner = ssl; - - if (!ssl->ctx->read_buffer_len) - { - ssl->ctx->read_buffer_len = 2048; - } - - max_content_len = ssl->ctx->read_buffer_len; - - mbedtls_net_init(&ssl_pm->fd); - mbedtls_net_init(&ssl_pm->cl_fd); - - mbedtls_ssl_config_init(&ssl_pm->conf); - mbedtls_ctr_drbg_init(&ssl_pm->ctr_drbg); - mbedtls_entropy_init(&ssl_pm->entropy); - mbedtls_ssl_init(&ssl_pm->ssl); - mbedtls_ssl_conf_read_timeout(&ssl_pm->conf, READ_TIMEOUT_MS); - - ret = mbedtls_ctr_drbg_seed(&ssl_pm->ctr_drbg, mbedtls_entropy_func, - &ssl_pm->entropy, pers, pers_len); - if (ret) - { - SSL_DEBUG(SSL_PLATFORM_ERROR_LEVEL, - "mbedtls_ctr_drbg_seed() return -0x%x", -ret); - goto mbedtls_err1; - } - - if (method->endpoint) - { - endpoint = MBEDTLS_SSL_IS_SERVER; - } - else - { - endpoint = MBEDTLS_SSL_IS_CLIENT; - } - - ret = mbedtls_ssl_config_defaults(&ssl_pm->conf, endpoint, - MBEDTLS_SSL_TRANSPORT_STREAM, - MBEDTLS_SSL_PRESET_DEFAULT); - if (ret) - { - SSL_DEBUG(SSL_PLATFORM_ERROR_LEVEL, - "mbedtls_ssl_config_defaults() return -0x%x", -ret); - goto mbedtls_err2; - } - - if (TLS_ANY_VERSION != ssl->version) - { - if (TLS1_2_VERSION == ssl->version) - { - version = MBEDTLS_SSL_MINOR_VERSION_3; - } - else if (TLS1_1_VERSION == ssl->version) - { - version = MBEDTLS_SSL_MINOR_VERSION_2; - } - else if (TLS1_VERSION == ssl->version) - { - version = MBEDTLS_SSL_MINOR_VERSION_1; - } - else - { - version = MBEDTLS_SSL_MINOR_VERSION_0; - } - - mbedtls_ssl_conf_max_version(&ssl_pm->conf, - MBEDTLS_SSL_MAJOR_VERSION_3, version); - mbedtls_ssl_conf_min_version(&ssl_pm->conf, - MBEDTLS_SSL_MAJOR_VERSION_3, version); - } - else - { - mbedtls_ssl_conf_max_version(&ssl_pm->conf, - MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_3); - mbedtls_ssl_conf_min_version(&ssl_pm->conf, - MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_0); - } - - mbedtls_ssl_conf_rng(&ssl_pm->conf, - mbedtls_ctr_drbg_random, &ssl_pm->ctr_drbg); - mbedtls_ssl_conf_dbg(&ssl_pm->conf, ssl_platform_debug, NULL); - - ret = mbedtls_ssl_setup(&ssl_pm->ssl, &ssl_pm->conf); - if (ret) - { - SSL_DEBUG(SSL_PLATFORM_ERROR_LEVEL, - "mbedtls_ssl_setup() return -0x%x", -ret); - goto mbedtls_err2; - } - - mbedtls_ssl_set_bio(&ssl_pm->ssl, &ssl_pm->fd, - mbedtls_net_send, mbedtls_net_recv, - mbedtls_net_recv_timeout); - - ssl->ssl_pm = ssl_pm; - - return 0; - -mbedtls_err2: - mbedtls_ssl_config_free(&ssl_pm->conf); - mbedtls_ctr_drbg_free(&ssl_pm->ctr_drbg); -mbedtls_err1: - mbedtls_entropy_free(&ssl_pm->entropy); - ssl_mem_free(ssl_pm); -no_mem: - return -1; -} - -/** - * @brief free SSL low-level object - */ - -void ssl_pm_free(SSL *ssl) -{ - struct ssl_pm *ssl_pm = (struct ssl_pm *)ssl->ssl_pm; - - mbedtls_ctr_drbg_free(&ssl_pm->ctr_drbg); - mbedtls_entropy_free(&ssl_pm->entropy); - mbedtls_ssl_config_free(&ssl_pm->conf); - mbedtls_ssl_free(&ssl_pm->ssl); - - ssl_mem_free(ssl_pm); - ssl->ssl_pm = NULL; -} - -/** - * @brief reload SSL low-level certification object - */ - -static int ssl_pm_reload_crt(SSL *ssl) -{ - int ret = 0; - int mode; - struct ssl_pm *ssl_pm = ssl->ssl_pm; - struct x509_pm *ca_pm = (struct x509_pm *)ssl->client_CA->x509_pm; - - struct pkey_pm *pkey_pm = (struct pkey_pm *)ssl->cert->pkey->pkey_pm; - struct x509_pm *crt_pm = (struct x509_pm *)ssl->cert->x509->x509_pm; - - if (ssl->verify_mode == SSL_VERIFY_PEER) - { - mode = MBEDTLS_SSL_VERIFY_OPTIONAL; - } - else if (ssl->verify_mode == SSL_VERIFY_FAIL_IF_NO_PEER_CERT) - { - mode = MBEDTLS_SSL_VERIFY_OPTIONAL; - } - else if (ssl->verify_mode == SSL_VERIFY_CLIENT_ONCE) - { - mode = MBEDTLS_SSL_VERIFY_UNSET; - } - else - { - mode = MBEDTLS_SSL_VERIFY_NONE; - } - - mbedtls_ssl_conf_authmode(&ssl_pm->conf, mode); - mbedtls_ssl_conf_ca_chain(&ssl_pm->conf, &ca_pm->x509_crt, NULL); - if (ca_pm->ex_crt) - { - mbedtls_ssl_conf_ca_chain(&ssl_pm->conf, ca_pm->ex_crt, NULL); - } - - if (pkey_pm->pkey) - { - ret = mbedtls_ssl_conf_own_cert(&ssl_pm->conf, - &crt_pm->x509_crt, pkey_pm->pkey); - } - - if (ret) - { - SSL_DEBUG(SSL_PLATFORM_ERROR_LEVEL, - "mbedtls_ssl_conf_own_cert() return -0x%x", -ret); - ret = -1; - } - - return ret; -} - -/* Perform the mbedtls SSL handshake instead of mbedtls_ssl_handshake. - * We can add debug here. - */ - -static int mbedtls_handshake(mbedtls_ssl_context *ssl) -{ - int ret = 0; - - while (ssl->state != MBEDTLS_SSL_HANDSHAKE_OVER) - { - ret = mbedtls_ssl_handshake_step(ssl); - - if (ret != 0) - { - break; - } - } - - return ret; -} - -int ssl_pm_handshake(SSL *ssl) -{ - int ret; - struct ssl_pm *ssl_pm = (struct ssl_pm *)ssl->ssl_pm; - - ssl->err = 0; - errno = 0; - - ret = ssl_pm_reload_crt(ssl); - if (ret) - { - SSL_DEBUG(SSL_PLATFORM_ERROR_LEVEL, - "%s: cert reload failed\n", __func__); - return 0; - } - - if (ssl_pm->ssl.state != MBEDTLS_SSL_HANDSHAKE_OVER) - { - ssl_speed_up_enter(); - - /* mbedtls return codes - * 0 = successful, or MBEDTLS_ERR_SSL_WANT_READ/WRITE - * anything else = death - */ - - ret = mbedtls_handshake(&ssl_pm->ssl); - ssl_speed_up_exit(); - } - else - { - ret = 0; - } - - /* OpenSSL return codes: - * 0 = The TLS/SSL handshake was not successful but was shut down - * controlled and by the specifications of the TLS/SSL protocol. - * 1 = successfully completed - * <0 = The TLS/SSL handshake was not successful because a fatal error - * occurred either at the protocol level or a connection failure - * occurred. - */ - - if (ret == MBEDTLS_ERR_SSL_WANT_READ || ret == MBEDTLS_ERR_SSL_WANT_WRITE) - { - ssl->err = (ret == MBEDTLS_ERR_SSL_WANT_READ) ? SSL_ERROR_WANT_READ : - SSL_ERROR_WANT_WRITE; - SSL_DEBUG(SSL_PLATFORM_ERROR_LEVEL, - "mbedtls_ssl_handshake() return -0x%x", -ret); - return -1; - } - - if (ret == 0) - { - /* successful */ - - struct x509_pm *x509_pm = - (struct x509_pm *)ssl->session->peer->x509_pm; - - x509_pm->ex_crt = (mbedtls_x509_crt *) - mbedtls_ssl_get_peer_cert(&ssl_pm->ssl); - return 1; /* openssl successful */ - } - - if (errno == 11) - { - ssl->err = ret == MBEDTLS_ERR_SSL_WANT_READ; - - return -1; - } - - SSL_DEBUG(SSL_PLATFORM_ERROR_LEVEL, - "%s: mbedtls_ssl_handshake() returned -0x%x\n", __func__, -ret); - - /* it's had it */ - - ssl->err = SSL_ERROR_SYSCALL; - - return -1; /* openssl death */ -} - -mbedtls_x509_crt * -ssl_ctx_get_mbedtls_x509_crt(SSL_CTX *ssl_ctx) -{ - struct x509_pm *x509_pm = (struct x509_pm *)ssl_ctx->cert->x509->x509_pm; - - if (!x509_pm) - { - return NULL; - } - - return &x509_pm->x509_crt; -} - -mbedtls_x509_crt * -ssl_get_peer_mbedtls_x509_crt(SSL *ssl) -{ - struct x509_pm *x509_pm = (struct x509_pm *)ssl->session->peer->x509_pm; - - if (!x509_pm) - { - return NULL; - } - - return x509_pm->ex_crt; -} - -int ssl_pm_shutdown(SSL *ssl) -{ - int ret; - struct ssl_pm *ssl_pm = (struct ssl_pm *)ssl->ssl_pm; - - ret = mbedtls_ssl_close_notify(&ssl_pm->ssl); - if (ret) - { - SSL_DEBUG(SSL_PLATFORM_ERROR_LEVEL, - "mbedtls_ssl_close_notify() return -0x%x", -ret); - if (ret == MBEDTLS_ERR_NET_CONN_RESET) - { - ssl->err = SSL_ERROR_SYSCALL; - } - - ret = -1; /* OpenSSL: "Call SSL_get_error with the return value to find the reason */ - } - else - { - struct x509_pm *x509_pm = - (struct x509_pm *)ssl->session->peer->x509_pm; - - x509_pm->ex_crt = NULL; - ret = 1; /* OpenSSL: "The shutdown was successfully completed" - * ...0 means retry */ - } - - return ret; -} - -int ssl_pm_clear(SSL *ssl) -{ - return ssl_pm_shutdown(ssl); -} - -int ssl_pm_read(SSL *ssl, void *buffer, int len) -{ - int ret; - struct ssl_pm *ssl_pm = (struct ssl_pm *)ssl->ssl_pm; - - ret = mbedtls_ssl_read(&ssl_pm->ssl, buffer, len); - if (ret < 0) - { - SSL_DEBUG(SSL_PLATFORM_ERROR_LEVEL, - "mbedtls_ssl_read() return -0x%x", -ret); - if (ret == MBEDTLS_ERR_NET_CONN_RESET || - ret <= MBEDTLS_ERR_SSL_NO_USABLE_CIPHERSUITE) /* fatal errors */ - { - ssl->err = SSL_ERROR_SYSCALL; - } - else if (ret == MBEDTLS_ERR_SSL_WANT_READ) - { - ssl->err = SSL_ERROR_WANT_READ; - } - else if (ret == MBEDTLS_ERR_SSL_WANT_WRITE) - { - ssl->err = SSL_ERROR_WANT_WRITE; - } - else if (ret == MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS) - { - ssl->err = SSL_ERROR_WANT_ASYNC; - } - else - { - ssl->err = SSL_ERROR_SSL; - } - - ret = -1; - } - - return ret; -} - -/* This returns -1, or the length sent. - * If -1, then you need to find out if the error was - * fatal or recoverable using SSL_get_error() - */ - -int ssl_pm_send(SSL *ssl, const void *buffer, int len) -{ - int ret; - struct ssl_pm *ssl_pm = (struct ssl_pm *)ssl->ssl_pm; - - ret = mbedtls_ssl_write(&ssl_pm->ssl, buffer, len); - /* We can get a positive number, which may be less than len... that - * much was sent successfully and you can call again to send more. - * - * We can get a negative mbedtls error code... if WANT_WRITE or WANT_READ, - * it's nonfatal and means it should be retried as-is. If something else, - * it's fatal actually. - * - * If this function returns something other than a positive value or - * MBEDTLS_ERR_SSL_WANT_READ/WRITE, the ssl context becomes unusable, and - * you should either free it or call mbedtls_ssl_session_reset() on it - * before re-using it for a new connection; the current connection must - * be closed. - * - * When this function returns MBEDTLS_ERR_SSL_WANT_WRITE/READ, it must be - * called later with the same arguments, until it returns a positive value. - */ - - if (ret < 0) - { - SSL_DEBUG(SSL_PLATFORM_ERROR_LEVEL, - "mbedtls_ssl_write() return -0x%x", -ret); - switch (ret) - { - case MBEDTLS_ERR_NET_SEND_FAILED: - case MBEDTLS_ERR_NET_CONN_RESET: - ssl->err = SSL_ERROR_SYSCALL; - break; - case MBEDTLS_ERR_SSL_WANT_WRITE: - ssl->err = SSL_ERROR_WANT_WRITE; - break; - case MBEDTLS_ERR_SSL_WANT_READ: - ssl->err = SSL_ERROR_WANT_READ; - break; - default: - break; - } - - ret = -1; - } - - return ret; -} - -int ssl_pm_pending(const SSL *ssl) -{ - struct ssl_pm *ssl_pm = (struct ssl_pm *)ssl->ssl_pm; - - return (int)mbedtls_ssl_get_bytes_avail(&ssl_pm->ssl); -} - -void ssl_pm_set_fd(SSL *ssl, int fd, int mode) -{ - struct ssl_pm *ssl_pm = (struct ssl_pm *)ssl->ssl_pm; - - ssl_pm->fd.fd = fd; -} - -int ssl_pm_get_fd(const SSL *ssl, int mode) -{ - struct ssl_pm *ssl_pm = (struct ssl_pm *)ssl->ssl_pm; - - return ssl_pm->fd.fd; -} - -OSSL_HANDSHAKE_STATE ssl_pm_get_state(const SSL *ssl) -{ - OSSL_HANDSHAKE_STATE state; - - struct ssl_pm *ssl_pm = (struct ssl_pm *)ssl->ssl_pm; - - switch (ssl_pm->ssl.state) - { - case MBEDTLS_SSL_CLIENT_HELLO: - state = TLS_ST_CW_CLNT_HELLO; - break; - case MBEDTLS_SSL_SERVER_HELLO: - state = TLS_ST_SW_SRVR_HELLO; - break; - case MBEDTLS_SSL_SERVER_CERTIFICATE: - state = TLS_ST_SW_CERT; - break; - case MBEDTLS_SSL_SERVER_HELLO_DONE: - state = TLS_ST_SW_SRVR_DONE; - break; - case MBEDTLS_SSL_CLIENT_KEY_EXCHANGE: - state = TLS_ST_CW_KEY_EXCH; - break; - case MBEDTLS_SSL_CLIENT_CHANGE_CIPHER_SPEC: - state = TLS_ST_CW_CHANGE; - break; - case MBEDTLS_SSL_CLIENT_FINISHED: - state = TLS_ST_CW_FINISHED; - break; - case MBEDTLS_SSL_SERVER_CHANGE_CIPHER_SPEC: - state = TLS_ST_SW_CHANGE; - break; - case MBEDTLS_SSL_SERVER_FINISHED: - state = TLS_ST_SW_FINISHED; - break; - case MBEDTLS_SSL_CLIENT_CERTIFICATE: - state = TLS_ST_CW_CERT; - break; - case MBEDTLS_SSL_SERVER_KEY_EXCHANGE: - state = TLS_ST_SR_KEY_EXCH; - break; - case MBEDTLS_SSL_SERVER_NEW_SESSION_TICKET: - state = TLS_ST_SW_SESSION_TICKET; - break; - case MBEDTLS_SSL_SERVER_HELLO_VERIFY_REQUEST_SENT: - state = TLS_ST_SW_CERT_REQ; - break; - case MBEDTLS_SSL_HANDSHAKE_OVER: - state = TLS_ST_OK; - break; - default: - state = TLS_ST_BEFORE; - break; - } - - return state; -} - -int x509_pm_show_info(X509 *x) -{ - int ret; - char *buf; - mbedtls_x509_crt *x509_crt; - struct x509_pm *x509_pm = x->x509_pm; - - x509_crt = &x509_pm->x509_crt; - if (x509_crt->version == 0) - { - return -1; - } - - buf = ssl_mem_malloc(X509_INFO_STRING_LENGTH); - if (!buf) - { - SSL_DEBUG(SSL_PLATFORM_ERROR_LEVEL, "no enough memory > (buf)"); - goto no_mem; - } - - ret = mbedtls_x509_crt_info(buf, X509_INFO_STRING_LENGTH - 1, - "", x509_crt); - if (ret <= 0) - { - SSL_DEBUG(SSL_PLATFORM_ERROR_LEVEL, - "mbedtls_x509_crt_info() return -0x%x", -ret); - goto mbedtls_err1; - } - - buf[ret] = 0; - - ssl_mem_free(buf); - - SSL_DEBUG(SSL_DEBUG_ON, "%s", buf); - - return 0; - -mbedtls_err1: - ssl_mem_free(buf); -no_mem: - return -1; -} - -int x509_pm_new(X509 *x, X509 *m_x) -{ - struct x509_pm *x509_pm; - - x509_pm = ssl_mem_zalloc(sizeof(struct x509_pm)); - if (!x509_pm) - { - SSL_DEBUG(SSL_PLATFORM_ERROR_LEVEL, "no enough memory > (x509_pm)"); - goto failed1; - } - - x->x509_pm = x509_pm; - - if (m_x) - { - struct x509_pm *m_x509_pm = (struct x509_pm *)m_x->x509_pm; - - x509_pm->ex_crt = &m_x509_pm->x509_crt; - } - - return 0; - -failed1: - return -1; -} - -void x509_pm_free(X509 *x) -{ - struct x509_pm *x509_pm = (struct x509_pm *)x->x509_pm; - - mbedtls_x509_crt_free(&x509_pm->x509_crt); - ssl_mem_free(x->x509_pm); - x->x509_pm = NULL; -} - -int x509_pm_load(X509 *x, const unsigned char *buffer, int len) -{ - int ret; - unsigned char *load_buf; - struct x509_pm *x509_pm = (struct x509_pm *)x->x509_pm; - - mbedtls_x509_crt_free(&x509_pm->x509_crt); - mbedtls_x509_crt_init(&x509_pm->x509_crt); - if (buffer[0] != 0x30) - { - load_buf = ssl_mem_malloc(len + 1); - if (!load_buf) - { - SSL_DEBUG(SSL_PLATFORM_ERROR_LEVEL, - "no enough memory > (load_buf)"); - goto failed; - } - - ssl_memcpy(load_buf, buffer, len); - load_buf[len] = '\0'; - - ret = mbedtls_x509_crt_parse(&x509_pm->x509_crt, load_buf, len + 1); - ssl_mem_free(load_buf); - } - else - { - SSL_DEBUG(SSL_PLATFORM_ERROR_LEVEL, "parsing as der\n"); - ret = mbedtls_x509_crt_parse_der(&x509_pm->x509_crt, buffer, len); - } - - if (ret) - { - SSL_DEBUG(SSL_PLATFORM_ERROR_LEVEL, - "mbedtls_x509_crt_parse return -0x%x", -ret); - goto failed; - } - - return 0; - -failed: - mbedtls_x509_crt_free(&x509_pm->x509_crt); - return -1; -} - -int x509_pm_load_file(X509 *x, const char *path) -{ - int ret; - struct x509_pm *x509_pm = (struct x509_pm *)x->x509_pm; - - mbedtls_x509_crt_free(&x509_pm->x509_crt); - mbedtls_x509_crt_init(&x509_pm->x509_crt); - ret = mbedtls_x509_crt_parse_file(&x509_pm->x509_crt, path); - if (ret) - { - SSL_DEBUG(SSL_PLATFORM_ERROR_LEVEL, - "mbedtls_x509_crt_parse_file return -0x%x", -ret); - mbedtls_x509_crt_free(&x509_pm->x509_crt); - return -1; - } - - return 0; -} - -int x509_pm_load_path(X509 *x, const char *path) -{ - int ret; - struct x509_pm *x509_pm = (struct x509_pm *)x->x509_pm; - - mbedtls_x509_crt_free(&x509_pm->x509_crt); - mbedtls_x509_crt_init(&x509_pm->x509_crt); - ret = mbedtls_x509_crt_parse_path(&x509_pm->x509_crt, path); - if (ret) - { - SSL_DEBUG(SSL_PLATFORM_ERROR_LEVEL, - "mbedtls_x509_crt_parse_file return -0x%x", -ret); - mbedtls_x509_crt_free(&x509_pm->x509_crt); - return -1; - } - - return 0; -} - -int pkey_pm_new(EVP_PKEY *pk, EVP_PKEY *m_pkey) -{ - struct pkey_pm *pkey_pm; - - pkey_pm = ssl_mem_zalloc(sizeof(struct pkey_pm)); - if (!pkey_pm) - { - return -1; - } - - pk->pkey_pm = pkey_pm; - - if (m_pkey) - { - struct pkey_pm *m_pkey_pm = (struct pkey_pm *)m_pkey->pkey_pm; - - pkey_pm->ex_pkey = m_pkey_pm->pkey; - } - - return 0; -} - -void pkey_pm_free(EVP_PKEY *pk) -{ - struct pkey_pm *pkey_pm = (struct pkey_pm *)pk->pkey_pm; - - if (pkey_pm->pkey) - { - mbedtls_pk_free(pkey_pm->pkey); - - ssl_mem_free(pkey_pm->pkey); - pkey_pm->pkey = NULL; - } - - ssl_mem_free(pk->pkey_pm); - pk->pkey_pm = NULL; -} - -int pkey_pm_load(EVP_PKEY *pk, const unsigned char *buffer, int len) -{ - int ret; - unsigned char *load_buf; - struct pkey_pm *pkey_pm = (struct pkey_pm *)pk->pkey_pm; - mbedtls_ctr_drbg_context ctr_drbg; - - if (pkey_pm->pkey) - { - mbedtls_pk_free(pkey_pm->pkey); - } - - if (!pkey_pm->pkey) - { - pkey_pm->pkey = ssl_mem_malloc(sizeof(mbedtls_pk_context)); - if (!pkey_pm->pkey) - { - SSL_DEBUG(SSL_PLATFORM_ERROR_LEVEL, - "no enough memory > (pkey_pm->pkey)"); - goto no_mem; - } - } - - load_buf = ssl_mem_malloc(len + 1); - if (!load_buf) - { - SSL_DEBUG(SSL_PLATFORM_ERROR_LEVEL, "no enough memory > (load_buf)"); - goto failed; - } - - ssl_memcpy(load_buf, buffer, len); - load_buf[len] = '\0'; - - mbedtls_pk_init(pkey_pm->pkey); - mbedtls_ctr_drbg_init(&ctr_drbg); - - ret = mbedtls_pk_parse_key(pkey_pm->pkey, load_buf, len + 1, - NULL, 0, mbedtls_ctr_drbg_random, &ctr_drbg); - ssl_mem_free(load_buf); - - if (ret) - { - SSL_DEBUG(SSL_PLATFORM_ERROR_LEVEL, - "mbedtls_pk_parse_key return -0x%x", -ret); - goto failed; - } - - mbedtls_ctr_drbg_free(&ctr_drbg); - - return 0; - -failed: - mbedtls_ctr_drbg_free(&ctr_drbg); - mbedtls_pk_free(pkey_pm->pkey); - ssl_mem_free(pkey_pm->pkey); - pkey_pm->pkey = NULL; -no_mem: - return -1; -} - -void ssl_pm_set_bufflen(SSL *ssl, int len) -{ - max_content_len = len; -} - -long ssl_pm_get_verify_result(const SSL *ssl) -{ - uint32_t ret; - long verify_result; - struct ssl_pm *ssl_pm = (struct ssl_pm *)ssl->ssl_pm; - - ret = mbedtls_ssl_get_verify_result(&ssl_pm->ssl); - if (!ret) - { - return X509_V_OK; - } - - if (ret & MBEDTLS_X509_BADCERT_NOT_TRUSTED || - (ret & MBEDTLS_X509_BADCRL_NOT_TRUSTED)) - { - verify_result = X509_V_ERR_INVALID_CA; - } - else if (ret & MBEDTLS_X509_BADCERT_CN_MISMATCH) - { - verify_result = X509_V_ERR_HOSTNAME_MISMATCH; - } - else if ((ret & MBEDTLS_X509_BADCERT_BAD_KEY) || - (ret & MBEDTLS_X509_BADCRL_BAD_KEY)) - { - verify_result = X509_V_ERR_CA_KEY_TOO_SMALL; - } - else if ((ret & MBEDTLS_X509_BADCERT_BAD_MD) || - (ret & MBEDTLS_X509_BADCRL_BAD_MD)) - { - verify_result = X509_V_ERR_CA_MD_TOO_WEAK; - } - else if ((ret & MBEDTLS_X509_BADCERT_FUTURE) || - (ret & MBEDTLS_X509_BADCRL_FUTURE)) - { - verify_result = X509_V_ERR_CERT_NOT_YET_VALID; - } - else if ((ret & MBEDTLS_X509_BADCERT_EXPIRED) || - (ret & MBEDTLS_X509_BADCRL_EXPIRED)) - { - verify_result = X509_V_ERR_CERT_HAS_EXPIRED; - } - else - { - verify_result = X509_V_ERR_UNSPECIFIED; - } - - SSL_DEBUG(SSL_PLATFORM_ERROR_LEVEL, - "mbedtls_ssl_get_verify_result() return 0x%x", ret); - - return verify_result; -} - -/** - * @brief set expected hostname on peer cert CN - */ - -int X509_VERIFY_PARAM_set1_host(X509_VERIFY_PARAM *param, - const char *name, size_t namelen) -{ - SSL *ssl = (SSL *)((char *)param - offsetof(SSL, param)); - struct ssl_pm *ssl_pm = (struct ssl_pm *)ssl->ssl_pm; - char *name_cstr = NULL; - - if (namelen) - { - name_cstr = malloc(namelen + 1); - if (!name_cstr) - { - return 0; - } - - memcpy(name_cstr, name, namelen); - name_cstr[namelen] = '\0'; - name = name_cstr; - } - - mbedtls_ssl_set_hostname(&ssl_pm->ssl, name); - - if (namelen) - { - free(name_cstr); - } - - return 1; -} - -void _ssl_set_alpn_list(const SSL *ssl) -{ - if (ssl->alpn_protos) - { - if (mbedtls_ssl_conf_alpn_protocols( - &((struct ssl_pm *)(ssl->ssl_pm))->conf, - ssl->alpn_protos)) - { - SSL_DEBUG(SSL_PLATFORM_ERROR_LEVEL, - "mbedtls_ssl_conf_alpn_protocols failed\n"); - } - - return; - } - - if (!ssl->ctx->alpn_protos) - { - return; - } - - if (mbedtls_ssl_conf_alpn_protocols( - &((struct ssl_pm *)(ssl->ssl_pm))->conf, - ssl->ctx->alpn_protos)) - { - SSL_DEBUG(SSL_PLATFORM_ERROR_LEVEL, - "mbedtls_ssl_conf_alpn_protocols failed\n"); - } -} - -void SSL_get0_alpn_selected(const SSL *ssl, const unsigned char **data, - unsigned int *len) -{ - const char *alp = mbedtls_ssl_get_alpn_protocol( - &((struct ssl_pm *)(ssl->ssl_pm))->ssl); - - *data = (const unsigned char *)alp; - if (alp) - { - *len = (int)strlen(alp); - } - else - { - *len = 0; - } -} - -int SSL_set_sni_callback(SSL *ssl, - int(*cb)(void *, mbedtls_ssl_context *, - const unsigned char *, size_t), void *param) -{ - struct ssl_pm *ssl_pm = (struct ssl_pm *)ssl->ssl_pm; - - mbedtls_ssl_conf_sni(&ssl_pm->conf, cb, param); - - return 0; -} - -SSL *SSL_SSL_from_mbedtls_ssl_context(mbedtls_ssl_context *msc) -{ - struct ssl_pm *ssl_pm = - (struct ssl_pm *)((char *)msc - offsetof(struct ssl_pm, ssl)); - - return ssl_pm->owner; -} - -void SSL_set_SSL_CTX(SSL *ssl, SSL_CTX *ctx) -{ - struct ssl_pm *ssl_pm = ssl->ssl_pm; - struct x509_pm *x509_pm = (struct x509_pm *)ctx->cert->x509->x509_pm; - struct x509_pm *x509_pm_ca = (struct x509_pm *)ctx->client_CA->x509_pm; - - struct pkey_pm *pkey_pm = (struct pkey_pm *)ctx->cert->pkey->pkey_pm; - int mode; - - if (ssl->cert) - { - ssl_cert_free(ssl->cert); - } - - ssl->ctx = ctx; - ssl->cert = __ssl_cert_new(ctx->cert); - - if (ctx->verify_mode == SSL_VERIFY_PEER) - { - mode = MBEDTLS_SSL_VERIFY_OPTIONAL; - } - else if (ctx->verify_mode == SSL_VERIFY_FAIL_IF_NO_PEER_CERT) - { - mode = MBEDTLS_SSL_VERIFY_OPTIONAL; - } - else if (ctx->verify_mode == SSL_VERIFY_CLIENT_ONCE) - { - mode = MBEDTLS_SSL_VERIFY_UNSET; - } - else - { - mode = MBEDTLS_SSL_VERIFY_NONE; - } - - /* apply new ctx cert to ssl */ - - ssl->verify_mode = ctx->verify_mode; - - mbedtls_ssl_set_hs_ca_chain(&ssl_pm->ssl, &x509_pm_ca->x509_crt, NULL); - mbedtls_ssl_set_hs_own_cert(&ssl_pm->ssl, &x509_pm->x509_crt, - pkey_pm->pkey); - mbedtls_ssl_set_hs_authmode(&ssl_pm->ssl, mode); -} diff --git a/crypto/openssl_mbedtls_wrapper/mbedtls/ssl_pm.h b/crypto/openssl_mbedtls_wrapper/mbedtls/ssl_pm.h deleted file mode 100644 index 0d2065024..000000000 --- a/crypto/openssl_mbedtls_wrapper/mbedtls/ssl_pm.h +++ /dev/null @@ -1,75 +0,0 @@ -/**************************************************************************** - * apps/crypto/openssl_mbedtls_wrapper/mbedtls/ssl_pm.h - * - * SPDX-License-Identifier: Apache-2.0 - * SPDX-FileCopyrightText: 2015-2016 Espressif Systems (Shanghai) PTE LTD - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - ****************************************************************************/ - -#ifndef OPENSSL_MBEDTLS_WRAPPER_SSL_PM_H -#define OPENSSL_MBEDTLS_WRAPPER_SSL_PM_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <string.h> -#include <openssl/ssl.h> -#include "ssl_port.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -int ssl_pm_new(SSL *ssl); -void ssl_pm_free(SSL *ssl); - -int ssl_pm_handshake(SSL *ssl); -int ssl_pm_shutdown(SSL *ssl); -int ssl_pm_clear(SSL *ssl); - -int ssl_pm_read(SSL *ssl, void *buffer, int len); -int ssl_pm_send(SSL *ssl, const void *buffer, int len); -int ssl_pm_pending(const SSL *ssl); - -void ssl_pm_set_fd(SSL *ssl, int fd, int mode); -int ssl_pm_get_fd(const SSL *ssl, int mode); - -OSSL_HANDSHAKE_STATE ssl_pm_get_state(const SSL *ssl); - -void ssl_pm_set_bufflen(SSL *ssl, int len); - -int x509_pm_show_info(X509 *x); -int x509_pm_new(X509 *x, X509 *m_x); -void x509_pm_free(X509 *x); -int x509_pm_load(X509 *x, const unsigned char *buffer, int len); -int x509_pm_load_file(X509 *x, const char *path); -int x509_pm_load_path(X509 *x, const char *path); - -int pkey_pm_new(EVP_PKEY *pk, EVP_PKEY *m_pk); -void pkey_pm_free(EVP_PKEY *pk); -int pkey_pm_load(EVP_PKEY *pk, const unsigned char *buffer, int len); - -long ssl_pm_get_verify_result(const SSL *ssl); - -#ifdef __cplusplus -} -#endif - -#endif /* OPENSSL_MBEDTLS_WRAPPER_SSL_PM_H */ diff --git a/crypto/openssl_mbedtls_wrapper/mbedtls/ssl_port.c b/crypto/openssl_mbedtls_wrapper/mbedtls/ssl_port.c deleted file mode 100644 index b21d4fb3a..000000000 --- a/crypto/openssl_mbedtls_wrapper/mbedtls/ssl_port.c +++ /dev/null @@ -1,40 +0,0 @@ -/**************************************************************************** - * apps/crypto/openssl_mbedtls_wrapper/mbedtls/ssl_port.c - * - * SPDX-License-Identifier: Apache-2.0 - * SPDX-FileCopyrightText: 2015-2016 Espressif Systems (Shanghai) PTE LTD - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "ssl_port.h" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -void *ssl_mem_zalloc(size_t size) -{ - void *p = malloc(size); - - if (p) - { - memset(p, 0, size); - } - - return p; -} diff --git a/crypto/openssl_mbedtls_wrapper/mbedtls/ssl_port.h b/crypto/openssl_mbedtls_wrapper/mbedtls/ssl_port.h deleted file mode 100644 index 90bec6a6a..000000000 --- a/crypto/openssl_mbedtls_wrapper/mbedtls/ssl_port.h +++ /dev/null @@ -1,56 +0,0 @@ -/**************************************************************************** - * apps/crypto/openssl_mbedtls_wrapper/mbedtls/ssl_port.h - * - * SPDX-License-Identifier: Apache-2.0 - * SPDX-FileCopyrightText: 2015-2016 Espressif Systems (Shanghai) PTE LTD - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - ****************************************************************************/ - -#ifndef OPENSSL_MBEDTLS_WRAPPER_SSL_PORT_H -#define OPENSSL_MBEDTLS_WRAPPER_SSL_PORT_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "string.h" -#include "stdlib.h" -#if defined(LWS_HAVE_MALLOC_H) -#include "malloc.h" -#endif - -#ifdef __cplusplus -extern "C" -{ -#endif - -void *ssl_mem_zalloc(size_t size); - -#define ssl_mem_malloc malloc -#define ssl_mem_free free - -#define ssl_memcpy memcpy -#define ssl_strlen strlen - -#define ssl_speed_up_enter() -#define ssl_speed_up_exit() - -#define SSL_DEBUG_FL -#define SSL_DEBUG_LOG(fmt, ...) ESP_LOGI("openssl", fmt, ##__VA_ARGS__) - -#ifdef __cplusplus -} -#endif - -#endif /* OPENSSL_MBEDTLS_WRAPPER_SSL_PORT_H */ diff --git a/crypto/openssl_mbedtls_wrapper/mbedtls/ssl_rsa.c b/crypto/openssl_mbedtls_wrapper/mbedtls/ssl_rsa.c deleted file mode 100644 index 7f21912ea..000000000 --- a/crypto/openssl_mbedtls_wrapper/mbedtls/ssl_rsa.c +++ /dev/null @@ -1,248 +0,0 @@ -/**************************************************************************** - * apps/crypto/openssl_mbedtls_wrapper/mbedtls/ssl_rsa.c - * - * SPDX-License-Identifier: Apache-2.0 - * SPDX-FileCopyrightText: 2015-2016 Espressif Systems (Shanghai) PTE LTD - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <stdint.h> - -#include <openssl/ssl_dbg.h> -#include <openssl/evp.h> -#include <openssl/ssl_local.h> -#include <openssl/x509.h> - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -int SSL_CTX_use_certificate(SSL_CTX *ctx, X509 *x) -{ - SSL_ASSERT1(ctx); - SSL_ASSERT1(x); - - if (ctx->cert->x509 == x) - { - return 1; - } - - X509_free(ctx->cert->x509); - ctx->cert->x509 = x; - return 1; -} - -int SSL_use_certificate(SSL *ssl, X509 *x) -{ - SSL_ASSERT1(ssl); - SSL_ASSERT1(x); - - if (ssl->cert->x509 == x) - { - return 1; - } - - X509_free(ssl->cert->x509); - ssl->cert->x509 = x; - return 1; -} - -int SSL_CTX_use_certificate_ASN1(SSL_CTX *ctx, int len, - const unsigned char *d) -{ - int ret; - X509 *x; - - x = d2i_X509(NULL, &d, len); - if (!x) - { - SSL_DEBUG(SSL_PKEY_ERROR_LEVEL, "d2i_X509() return NULL"); - goto failed1; - } - - ret = SSL_CTX_use_certificate(ctx, x); - if (!ret) - { - SSL_DEBUG(SSL_PKEY_ERROR_LEVEL, - "SSL_CTX_use_certificate() return %d", ret); - goto failed2; - } - - return 1; - -failed2: - X509_free(x); -failed1: - return 0; -} - -int SSL_use_certificate_ASN1(SSL *ssl, const unsigned char *d, int len) -{ - int ret; - X509 *x; - - x = d2i_X509(NULL, &d, len); - if (!x) - { - SSL_DEBUG(SSL_PKEY_ERROR_LEVEL, "d2i_X509() return NULL"); - goto failed1; - } - - ret = SSL_use_certificate(ssl, x); - if (!ret) - { - SSL_DEBUG(SSL_PKEY_ERROR_LEVEL, - "SSL_use_certificate() return %d", ret); - goto failed2; - } - - return 1; - -failed2: - X509_free(x); -failed1: - return 0; -} - -int SSL_CTX_use_certificate_file(SSL_CTX *ctx, const char *file, int type) -{ - return 0; -} - -int SSL_CTX_use_certificate_chain_file(SSL_CTX *ctx, const char *file) -{ - return 0; -} - -int SSL_use_certificate_file(SSL *ssl, const char *file, int type) -{ - return 0; -} - -int SSL_CTX_use_PrivateKey(SSL_CTX *ctx, EVP_PKEY *pkey) -{ - SSL_ASSERT1(ctx); - SSL_ASSERT1(pkey); - - if (ctx->cert->pkey == pkey) - { - return 1; - } - - if (ctx->cert->pkey) - { - EVP_PKEY_free(ctx->cert->pkey); - } - - ctx->cert->pkey = pkey; - - return 1; -} - -int SSL_use_PrivateKey(SSL *ssl, EVP_PKEY *pkey) -{ - SSL_ASSERT1(ssl); - SSL_ASSERT1(pkey); - - if (ssl->cert->pkey == pkey) - { - return 1; - } - - if (ssl->cert->pkey) - { - EVP_PKEY_free(ssl->cert->pkey); - } - - ssl->cert->pkey = pkey; - - return 1; -} - -int SSL_CTX_use_PrivateKey_ASN1(int type, SSL_CTX *ctx, - const unsigned char *d, long len) -{ - int ret; - EVP_PKEY *pk; - - pk = d2i_PrivateKey(0, NULL, &d, len); - if (!pk) - { - SSL_DEBUG(SSL_PKEY_ERROR_LEVEL, "d2i_PrivateKey() return NULL"); - goto failed1; - } - - ret = SSL_CTX_use_PrivateKey(ctx, pk); - if (!ret) - { - SSL_DEBUG(SSL_PKEY_ERROR_LEVEL, - "SSL_CTX_use_PrivateKey() return %d", ret); - goto failed2; - } - - return 1; - -failed2: - EVP_PKEY_free(pk); -failed1: - return 0; -} - -int SSL_use_PrivateKey_ASN1(int type, SSL *ssl, - const unsigned char *d, long len) -{ - int ret; - EVP_PKEY *pk; - - pk = d2i_PrivateKey(0, NULL, &d, len); - if (!pk) - { - SSL_DEBUG(SSL_PKEY_ERROR_LEVEL, "d2i_PrivateKey() return NULL"); - goto failed1; - } - - ret = SSL_use_PrivateKey(ssl, pk); - if (!ret) - { - SSL_DEBUG(SSL_PKEY_ERROR_LEVEL, "SSL_use_PrivateKey() return %d", ret); - goto failed2; - } - - return 1; - -failed2: - EVP_PKEY_free(pk); -failed1: - return 0; -} - -int SSL_CTX_use_PrivateKey_file(SSL_CTX *ctx, const char *file, int type) -{ - return 0; -} - -int SSL_use_PrivateKey_file(SSL_CTX *ctx, const char *file, int type) -{ - return 0; -} - -int SSL_CTX_use_RSAPrivateKey_ASN1(SSL_CTX *ctx, const unsigned char *d, - long len) -{ - return SSL_CTX_use_PrivateKey_ASN1(0, ctx, d, len); -} diff --git a/crypto/openssl_mbedtls_wrapper/mbedtls/stack.c b/crypto/openssl_mbedtls_wrapper/mbedtls/stack.c deleted file mode 100644 index aed407f8a..000000000 --- a/crypto/openssl_mbedtls_wrapper/mbedtls/stack.c +++ /dev/null @@ -1,80 +0,0 @@ -/**************************************************************************** - * apps/crypto/openssl_mbedtls_wrapper/mbedtls/stack.c - * - * SPDX-License-Identifier: Apache-2.0 - * SPDX-FileCopyrightText: 2015-2016 Espressif Systems (Shanghai) PTE LTD - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <openssl/stack.h> -#include <openssl/ssl_dbg.h> -#include "ssl_port.h" - -#ifndef CONFIG_MIN_NODES - #define MIN_NODES 4 -#else - #define MIN_NODES CONFIG_MIN_NODES -#endif - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -OPENSSL_STACK *OPENSSL_sk_new(OPENSSL_sk_compfunc c) -{ - OPENSSL_STACK *stack; - char **data; - - stack = ssl_mem_zalloc(sizeof(OPENSSL_STACK)); - if (!stack) - { - SSL_DEBUG(SSL_STACK_ERROR_LEVEL, "no enough memory > (stack)"); - goto no_mem1; - } - - data = ssl_mem_zalloc(sizeof(*data) * MIN_NODES); - if (!data) - { - SSL_DEBUG(SSL_STACK_ERROR_LEVEL, "no enough memory > (data)"); - goto no_mem2; - } - - stack->data = data; - stack->num_alloc = MIN_NODES; - stack->c = c; - - return stack; - -no_mem2: - ssl_mem_free(stack); -no_mem1: - return NULL; -} - -OPENSSL_STACK *OPENSSL_sk_new_null(void) -{ - return OPENSSL_sk_new((OPENSSL_sk_compfunc)NULL); -} - -void OPENSSL_sk_free(OPENSSL_STACK *stack) -{ - SSL_ASSERT3(stack); - - ssl_mem_free(stack->data); - ssl_mem_free(stack); -} diff --git a/crypto/openssl_mbedtls_wrapper/mbedtls/statem.c b/crypto/openssl_mbedtls_wrapper/mbedtls/statem.c deleted file mode 100644 index f7dd4ed99..000000000 --- a/crypto/openssl_mbedtls_wrapper/mbedtls/statem.c +++ /dev/null @@ -1,40 +0,0 @@ -/**************************************************************************** - * apps/crypto/openssl_mbedtls_wrapper/mbedtls/statem.c - * - * SPDX-License-Identifier: Apache-2.0 - * SPDX-FileCopyrightText: 2015-2016 Espressif Systems (Shanghai) PTE LTD - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <openssl/ssl_dbg.h> -#include <openssl/ssl_local.h> - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -OSSL_HANDSHAKE_STATE SSL_get_state(const SSL *ssl) -{ - OSSL_HANDSHAKE_STATE state; - - SSL_ASSERT1(ssl); - - state = SSL_METHOD_CALL(get_state, ssl); - - return state; -} diff --git a/crypto/openssl_mbedtls_wrapper/mbedtls/x509.c b/crypto/openssl_mbedtls_wrapper/mbedtls/x509.c deleted file mode 100644 index 27f5abb1d..000000000 --- a/crypto/openssl_mbedtls_wrapper/mbedtls/x509.c +++ /dev/null @@ -1,255 +0,0 @@ -/**************************************************************************** - * apps/crypto/openssl_mbedtls_wrapper/mbedtls/x509.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <openssl/ssl_dbg.h> -#include <openssl/x509.h> -#include "ssl_port.h" -#include "ssl_methods.h" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -void X509_free(X509 *a) -{ - SSL_ASSERT3(a); - - X509_METHOD_CALL(free, a); - - ssl_mem_free(a); -} - -void X509_EXTENSION_free(X509_EXTENSION *a) -{ -} - -int X509_set_notAfter(X509 *x509, const ASN1_TIME *tm) -{ - return 0; -} - -void X509_NAME_free(X509_NAME *a) -{ -} - -void X509_ALGOR_free(X509_ALGOR *a) -{ -} - -int X509_sign(X509 *x509, EVP_PKEY *pkey, const EVP_MD *md) -{ - return 0; -} - -int X509_add_ext(X509 *x, const X509_EXTENSION *ex, int loc) -{ - return 0; -} - -int X509_set_pubkey(X509 *x509, EVP_PKEY *pkey) -{ - return 0; -} - -X509_EXTENSION *X509_EXTENSION_create_by_NID(X509_EXTENSION **ex, - int nid, int crit, - const ASN1_OCTET_STRING *data) -{ - return NULL; -} - -X509 *X509_new(void) -{ - return __X509_new(NULL); -} - -int X509_set_version(X509 *x509, long version) -{ - return 0; -} - -int X509_set_serialNumber(X509 *x509, const ASN1_INTEGER *serial) -{ - return 0; -} - -int X509_set_subject_name(X509 *x509, X509_NAME *name) -{ - return 0; -} - -int X509_set_issuer_name(X509 *x509, X509_NAME *name) -{ - return 0; -} - -int X509_set_notBefore(X509 *x509, const ASN1_TIME *tm) -{ - return 0; -} - -int X509_ALGOR_set0(X509_ALGOR *alg, ASN1_OBJECT *obj, - int param_type, void *param_value) -{ - return 0; -} - -int X509_set1_signature_algo(X509 *x509, const X509_ALGOR *algo) -{ - return 0; -} - -int X509_set1_signature_value(X509 *x509, - const uint8_t *sig, - size_t sig_len) -{ - return 0; -} - -X509_NAME *X509_NAME_new(void) -{ - return NULL; -} - -int X509_NAME_add_entry_by_txt(X509_NAME *name, const char *field, - int type, const uint8_t *bytes, - int len, int loc, int set) -{ - return 0; -} - -X509_NAME *d2i_X509_NAME(X509_NAME **out, const uint8_t **inp, long len) -{ - return NULL; -} - -X509_ALGOR *X509_ALGOR_new(void) -{ - return NULL; -} - -int i2d_X509(X509 *x509, uint8_t **outp) -{ - return 0; -} - -PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO(PKCS8_PRIV_KEY_INFO *info, - const uint8_t **key_data, - size_t key_length) -{ - return NULL; -} - -void PKCS8_PRIV_KEY_INFO_free(PKCS8_PRIV_KEY_INFO *key) -{ -} - -EVP_PKEY *EVP_PKCS82PKEY(const PKCS8_PRIV_KEY_INFO *p8) -{ - return NULL; -} - -X509 *d2i_X509(X509 **out, const unsigned char **inp, long len) -{ - int m = 0; - int ret; - X509 *x; - - SSL_ASSERT2(inp); - SSL_ASSERT2(len); - - if (out && *out) - { - x = *out; - } - else - { - x = X509_new(); - if (!x) - { - SSL_DEBUG(SSL_PKEY_ERROR_LEVEL, "X509_new() return NULL"); - goto failed1; - } - - m = 1; - } - - ret = X509_METHOD_CALL(load, x, *inp, (int)len); - if (ret) - { - SSL_DEBUG(SSL_PKEY_ERROR_LEVEL, - "X509_METHOD_CALL(load) return %d", ret); - goto failed2; - } - - return x; - -failed2: - if (m) - { - X509_free(x); - } - -failed1: - return NULL; -} - -X509 *__X509_new(X509 *ix) -{ - int ret; - X509 *x; - - x = ssl_mem_zalloc(sizeof(X509)); - if (!x) - { - SSL_DEBUG(SSL_X509_ERROR_LEVEL, "no enough memory > (x)"); - goto no_mem; - } - - if (ix) - { - x->method = ix->method; - } - else - { - x->method = X509_method(); - } - - ret = X509_METHOD_CALL(new, x, ix); - if (ret) - { - SSL_DEBUG(SSL_PKEY_ERROR_LEVEL, - "X509_METHOD_CALL(new) return %d", ret); - goto failed; - } - - return x; - -failed: - ssl_mem_free(x); -no_mem: - return NULL; -} diff --git a/crypto/openssl_mbedtls_wrapper/mbedtls/x509_vpm.c b/crypto/openssl_mbedtls_wrapper/mbedtls/x509_vpm.c deleted file mode 100644 index 5bc660d09..000000000 --- a/crypto/openssl_mbedtls_wrapper/mbedtls/x509_vpm.c +++ /dev/null @@ -1,40 +0,0 @@ -/**************************************************************************** - * apps/crypto/openssl_mbedtls_wrapper/mbedtls/x509_vpm.c - * - * SPDX-License-Identifier: Apache-2.0 - * SPDX-FileCopyrightText: 2015-2016 Espressif Systems (Shanghai) PTE LTD - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <openssl/types.h> - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -int X509_VERIFY_PARAM_set_hostflags(X509_VERIFY_PARAM *param, - unsigned long flags) -{ - return 0; -} - -int X509_VERIFY_PARAM_clear_hostflags(X509_VERIFY_PARAM *param, - unsigned long flags) -{ - return 0; -} diff --git a/crypto/tinycrypt/.gitignore b/crypto/tinycrypt/.gitignore deleted file mode 100644 index 8b8137c74..000000000 --- a/crypto/tinycrypt/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/tinycrypt -/*.zip diff --git a/crypto/tinycrypt/0001-TinyCrypt-test-resolve-compile-error.patch b/crypto/tinycrypt/0001-TinyCrypt-test-resolve-compile-error.patch deleted file mode 100644 index 5c99d61d4..000000000 --- a/crypto/tinycrypt/0001-TinyCrypt-test-resolve-compile-error.patch +++ /dev/null @@ -1,204 +0,0 @@ ---- tests/test_ctr_mode.c 2017-08-30 05:21:56.000000000 +0800 -+++ tests/test_ctr_mode.c 2023-08-11 15:31:21.409557000 +0800 -@@ -50,7 +50,7 @@ - /* - * NIST SP 800-38a CTR Test for encryption and decryption. - */ --unsigned int test_1_and_2(void) -+static unsigned int test_1_and_2(void) - { - const uint8_t key[16] = { - 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, ---- tests/test_hmac.c 2017-08-30 05:21:56.000000000 +0800 -+++ tests/test_hmac.c 2023-08-11 15:32:58.239231000 +0800 -@@ -66,7 +66,7 @@ - /* - * NIST test vectors for encryption. - */ --unsigned int test_1(void) -+static unsigned int test_1(void) - { - unsigned int result = TC_PASS; - -@@ -94,7 +94,7 @@ - return result; - } - --unsigned int test_2(void) -+static unsigned int test_2(void) - { - unsigned int result = TC_PASS; - TC_PRINT("HMAC %s:\n", __func__); -@@ -122,7 +122,7 @@ - return result; - } - --unsigned int test_3(void) -+static unsigned int test_3(void) - { - unsigned int result = TC_PASS; - TC_PRINT("HMAC %s:\n", __func__); -@@ -153,7 +153,7 @@ - return result; - } - --unsigned int test_4(void) -+static unsigned int test_4(void) - { - unsigned int result = TC_PASS; - TC_PRINT("HMAC %s:\n", __func__); -@@ -186,7 +186,7 @@ - return result; - } - --unsigned int test_5(void) -+static unsigned int test_5(void) - { - unsigned int result = TC_PASS; - TC_PRINT("HMAC %s:\n", __func__); -@@ -214,7 +214,7 @@ - return result; - } - --unsigned int test_6(void) -+static unsigned int test_6(void) - { - unsigned int result = TC_PASS; - TC_PRINT("HMAC %s:\n", __func__); -@@ -254,7 +254,7 @@ - return result; - } - --unsigned int test_7(void) -+static unsigned int test_7(void) - { - unsigned int result = TC_PASS; - TC_PRINT("HMAC %s:\n", __func__); ---- tests/test_sha256.c 2017-08-30 05:21:56.000000000 +0800 -+++ tests/test_sha256.c 2023-08-11 15:54:28.022372000 +0800 -@@ -50,7 +50,7 @@ - /* - * NIST SHA256 test vector 1. - */ --unsigned int test_1(void) -+static unsigned int test_1(void) - { - unsigned int result = TC_PASS; - -@@ -76,7 +76,7 @@ - /* - * NIST SHA256 test vector 2. - */ --unsigned int test_2(void) -+static unsigned int test_2(void) - { - unsigned int result = TC_PASS; - TC_PRINT("SHA256 test #2:\n"); -@@ -99,7 +99,7 @@ - return result; - } - --unsigned int test_3(void) -+static unsigned int test_3(void) - { - unsigned int result = TC_PASS; - TC_PRINT("SHA256 test #3:\n"); -@@ -122,7 +122,7 @@ - return result; - } - --unsigned int test_4(void) -+static unsigned int test_4(void) - { - unsigned int result = TC_PASS; - TC_PRINT("SHA256 test #4:\n"); -@@ -145,7 +145,7 @@ - return result; - } - --unsigned int test_5(void) -+static unsigned int test_5(void) - { - unsigned int result = TC_PASS; - TC_PRINT("SHA256 test #5:\n"); -@@ -171,7 +171,7 @@ - return result; - } - --unsigned int test_6(void) -+static unsigned int test_6(void) - { - unsigned int result = TC_PASS; - TC_PRINT("SHA256 test #6:\n"); -@@ -196,7 +196,7 @@ - return result; - } - --unsigned int test_7(void) -+static unsigned int test_7(void) - { - unsigned int result = TC_PASS; - TC_PRINT("SHA256 test #7:\n"); -@@ -221,7 +221,7 @@ - return result; - } - --unsigned int test_8(void) -+static unsigned int test_8(void) - { - unsigned int result = TC_PASS; - -@@ -247,7 +247,7 @@ - return result; - } - --unsigned int test_9(void) -+static unsigned int test_9(void) - { - unsigned int result = TC_PASS; - TC_PRINT("SHA256 test #9:\n"); -@@ -272,7 +272,7 @@ - return result; - } - --unsigned int test_10(void) -+static unsigned int test_10(void) - { - unsigned int result = TC_PASS; - TC_PRINT("SHA256 test #10:\n"); -@@ -297,7 +297,7 @@ - return result; - } - --unsigned int test_11(void) -+static unsigned int test_11(void) - { - unsigned int result = TC_PASS; - TC_PRINT("SHA256 test #11:\n"); -@@ -322,7 +322,7 @@ - return result; - } - --unsigned int test_12(void) -+static unsigned int test_12(void) - { - unsigned int result = TC_PASS; - TC_PRINT("SHA256 test #12:\n"); -@@ -351,7 +351,7 @@ - return result; - } - --unsigned int test_13(void) -+static unsigned int test_13(void) - { - unsigned int result = TC_PASS; - TC_PRINT("SHA256 test #13:\n"); -@@ -379,7 +379,7 @@ - return result; - } - --unsigned int test_14(void) -+static unsigned int test_14(void) - { - unsigned int result = TC_PASS; - TC_PRINT("SHA256 test #14:\n"); diff --git a/crypto/tinycrypt/CMakeLists.txt b/crypto/tinycrypt/CMakeLists.txt deleted file mode 100644 index c75ae88c6..000000000 --- a/crypto/tinycrypt/CMakeLists.txt +++ /dev/null @@ -1,312 +0,0 @@ -# ############################################################################## -# apps/crypto/tinycrypt/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_TINYCRYPT) - - # ############################################################################ - # Config and Fetch tinycrypt - # ############################################################################ - set(TINYCRYPT_DIR ${CMAKE_CURRENT_LIST_DIR}/tinycrypt) - - if(NOT EXISTS ${TINYCRYPT_DIR}) - set(TINYCRYPT_VERSION ${CONFIG_TINYCRYPT_VERSION}) - - set(TINYCRYPT_URL - https://github.com/intel/tinycrypt/archive/refs/tags/v${TINYCRYPT_VERSION}.zip - ) - FetchContent_Declare( - tinycrypt_fetch - URL ${TINYCRYPT_URL} SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/tinycrypt - BINARY_DIR ${CMAKE_BINARY_DIR}/apps/crypto/tinycrypt/tinycrypt - PATCH_COMMAND - patch -p0 -d ${CMAKE_CURRENT_LIST_DIR}/tinycrypt < - ${CMAKE_CURRENT_LIST_DIR}/0001-TinyCrypt-test-resolve-compile-error.patch - DOWNLOAD_NO_PROGRESS true - TIMEOUT 30) - - FetchContent_GetProperties(tinycrypt_fetch) - - if(NOT tinycrypt_fetch_POPULATED) - FetchContent_Populate(tinycrypt_fetch) - endif() - endif() - - nuttx_add_library(tinycrypt STATIC) - - # ############################################################################ - # Include Directory - # ############################################################################ - - set(INCDIR ${TINYCRYPT_DIR}/lib/include) - - nuttx_export_header(TARGET tinycrypt INCLUDE_DIRECTORIES ${INCDIR}) - - # ############################################################################ - # Sources - # ############################################################################ - - list(APPEND CFLAGS -Dunix) - set(CSRCS - ${TINYCRYPT_DIR}/lib/source/utils.c ${TINYCRYPT_DIR}/lib/source/ecc.c - ${TINYCRYPT_DIR}/lib/source/ecc_platform_specific.c) - - if(CONFIG_TINYCRYPT_ECC_DH) - list(APPEND CSRCS ${TINYCRYPT_DIR}/lib/source/ecc_dh.c) - endif() - - if(CONFIG_TINYCRYPT_ECC_DSA) - list(APPEND CSRCS ${TINYCRYPT_DIR}/lib/source/ecc_dsa.c) - endif() - - if(CONFIG_TINYCRYPT_AES) - list(APPEND CSRCS ${TINYCRYPT_DIR}/lib/source/aes_encrypt.c - ${TINYCRYPT_DIR}/lib/source/aes_decrypt.c) - endif() - - if(CONFIG_TINYCRYPT_AES_CBC) - list(APPEND CSRCS ${TINYCRYPT_DIR}/lib/source/cbc_mode.c) - endif() - - if(CONFIG_TINYCRYPT_AES_CTR) - list(APPEND CSRCS ${TINYCRYPT_DIR}/lib/source/ctr_mode.c) - endif() - - if(CONFIG_TINYCRYPT_AES_CCM) - list(APPEND CSRCS ${TINYCRYPT_DIR}/lib/source/ccm_mode.c) - endif() - - if(CONFIG_TINYCRYPT_AES_CMAC) - list(APPEND CSRCS ${TINYCRYPT_DIR}/lib/source/cmac_mode.c) - endif() - - if(CONFIG_TINYCRYPT_SHA256) - list(APPEND CSRCS ${TINYCRYPT_DIR}/lib/source/sha256.c) - endif() - - if(CONFIG_TINYCRYPT_SHA256_HMAC) - list(APPEND CSRCS ${TINYCRYPT_DIR}/lib/source/hmac.c) - endif() - - if(CONFIG_TINYCRYPT_SHA256_HMAC_PRNG) - list(APPEND CSRCS ${TINYCRYPT_DIR}/lib/source/hmac_prng.c) - endif() - - if(CONFIG_TINYCRYPT_CTR_PRNG) - list(APPEND CSRCS ${TINYCRYPT_DIR}/lib/source/ctr_prng.c) - endif() - - # ############################################################################ - # Applications Configuration - # ############################################################################ - - if(CONFIG_TINYCRYPT_TEST) - list(APPEND CSRCS ${TINYCRYPT_DIR}/tests/test_ecc_utils.c) - list(APPEND INCDIR ${TINYCRYPT_DIR}/tests/include) - list(APPEND CFLAGS -DENABLE_TESTS) - - nuttx_add_application( - NAME - tinycrypt_test_aes - STACKSIZE - ${CONFIG_TINYCRYPT_TEST_STACKSIZE} - PRIORITY - ${CONFIG_TINYCRYPT_TEST_PRIORITY} - SRCS - ${TINYCRYPT_DIR}/tests/test_aes.c - INCLUDE_DIRECTORIES - ${INCDIR} - COMPILE_FLAGS - ${CFLAGS} - DEPENDS - tinycrypt) - - nuttx_add_application( - NAME - tinycrypt_test_cbc_mode - STACKSIZE - ${CONFIG_TINYCRYPT_TEST_STACKSIZE} - PRIORITY - ${CONFIG_TINYCRYPT_TEST_PRIORITY} - SRCS - ${TINYCRYPT_DIR}/tests/test_cbc_mode.c - INCLUDE_DIRECTORIES - ${INCDIR} - COMPILE_FLAGS - ${CFLAGS} - DEPENDS - tinycrypt) - - nuttx_add_application( - NAME - tinycrypt_test_ccm_mode - STACKSIZE - ${CONFIG_TINYCRYPT_TEST_STACKSIZE} - PRIORITY - ${CONFIG_TINYCRYPT_TEST_PRIORITY} - SRCS - ${TINYCRYPT_DIR}/tests/test_ccm_mode.c - INCLUDE_DIRECTORIES - ${INCDIR} - COMPILE_FLAGS - ${CFLAGS} - DEPENDS - tinycrypt) - - nuttx_add_application( - NAME - tinycrypt_test_cmac_mode - STACKSIZE - ${CONFIG_TINYCRYPT_TEST_STACKSIZE} - PRIORITY - ${CONFIG_TINYCRYPT_TEST_PRIORITY} - SRCS - ${TINYCRYPT_DIR}/tests/test_cmac_mode.c - INCLUDE_DIRECTORIES - ${INCDIR} - COMPILE_FLAGS - ${CFLAGS} - DEPENDS - tinycrypt) - - nuttx_add_application( - NAME - tinycrypt_test_ctr_mode - STACKSIZE - ${CONFIG_TINYCRYPT_TEST_STACKSIZE} - PRIORITY - ${CONFIG_TINYCRYPT_TEST_PRIORITY} - SRCS - ${TINYCRYPT_DIR}/tests/test_ctr_mode.c - INCLUDE_DIRECTORIES - ${INCDIR} - COMPILE_FLAGS - ${CFLAGS} - DEPENDS - tinycrypt) - - nuttx_add_application( - NAME - tinycrypt_test_ctr_prng - STACKSIZE - ${CONFIG_TINYCRYPT_TEST_STACKSIZE} - PRIORITY - ${CONFIG_TINYCRYPT_TEST_PRIORITY} - SRCS - ${TINYCRYPT_DIR}/tests/test_ctr_prng.c - INCLUDE_DIRECTORIES - ${INCDIR} - COMPILE_FLAGS - ${CFLAGS} - DEPENDS - tinycrypt) - - nuttx_add_application( - NAME - tinycrypt_test_ecc_dh - STACKSIZE - ${CONFIG_TINYCRYPT_TEST_STACKSIZE} - PRIORITY - ${CONFIG_TINYCRYPT_TEST_PRIORITY} - SRCS - ${TINYCRYPT_DIR}/tests/test_ecc_dh.c - INCLUDE_DIRECTORIES - ${INCDIR} - COMPILE_FLAGS - ${CFLAGS} - DEPENDS - tinycrypt) - - nuttx_add_application( - NAME - tinycrypt_test_ecc_dsa - STACKSIZE - ${CONFIG_TINYCRYPT_TEST_STACKSIZE} - PRIORITY - ${CONFIG_TINYCRYPT_TEST_PRIORITY} - SRCS - ${TINYCRYPT_DIR}/tests/test_ecc_dsa.c - INCLUDE_DIRECTORIES - ${INCDIR} - COMPILE_FLAGS - ${CFLAGS} - DEPENDS - tinycrypt) - - nuttx_add_application( - NAME - tinycrypt_test_hmac - STACKSIZE - ${CONFIG_TINYCRYPT_TEST_STACKSIZE} - PRIORITY - ${CONFIG_TINYCRYPT_TEST_PRIORITY} - SRCS - ${TINYCRYPT_DIR}/tests/test_hmac.c - INCLUDE_DIRECTORIES - ${INCDIR} - COMPILE_FLAGS - ${CFLAGS} - DEPENDS - tinycrypt) - - nuttx_add_application( - NAME - tinycrypt_test_hmac_prng - STACKSIZE - ${CONFIG_TINYCRYPT_TEST_STACKSIZE} - PRIORITY - ${CONFIG_TINYCRYPT_TEST_PRIORITY} - SRCS - ${TINYCRYPT_DIR}/tests/test_hmac_prng.c - INCLUDE_DIRECTORIES - ${INCDIR} - COMPILE_FLAGS - ${CFLAGS} - DEPENDS - tinycrypt) - - nuttx_add_application( - NAME - tinycrypt_test_sha256 - STACKSIZE - ${CONFIG_TINYCRYPT_TEST_STACKSIZE} - PRIORITY - ${CONFIG_TINYCRYPT_TEST_PRIORITY} - SRCS - ${TINYCRYPT_DIR}/tests/test_sha256.c - INCLUDE_DIRECTORIES - ${INCDIR} - COMPILE_FLAGS - ${CFLAGS} - DEPENDS - tinycrypt) - endif() - - # ############################################################################ - # Library Configuration - # ############################################################################ - - target_sources(tinycrypt PRIVATE ${CSRCS}) - target_include_directories(tinycrypt PRIVATE ${INCDIR}) - if(CFLAGS) - target_compile_options(tinycrypt PRIVATE ${CFLAGS}) - endif() -endif() diff --git a/crypto/tinycrypt/Kconfig b/crypto/tinycrypt/Kconfig deleted file mode 100644 index bfec69d64..000000000 --- a/crypto/tinycrypt/Kconfig +++ /dev/null @@ -1,122 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -menu "Crypto: TinyCrypt cryptography library" - -config TINYCRYPT - bool "TinyCrypt Support" - ---help--- - This option enables the TinyCrypt cryptography library. - -if TINYCRYPT -config TINYCRYPT_VERSION - string "Tinycrypt Version" - default "0.2.8" - -config TINYCRYPT_CTR_PRNG - bool "PRNG in counter mode" - default n - ---help--- - This option enables support for the pseudo-random number - generator in counter mode. - -config TINYCRYPT_SHA256 - bool "SHA-256 Hash function support" - default n - ---help--- - This option enables support for SHA-256 - hash function primitive. - -config TINYCRYPT_SHA256_HMAC - bool "HMAC (via SHA256) message auth support" - default n - ---help--- - This option enables support for HMAC using SHA-256 - message authentication code. - -config TINYCRYPT_SHA256_HMAC_PRNG - bool "PRNG (via HMAC-SHA256) support" - default n - ---help--- - This option enables support for pseudo-random number - generator. - -config TINYCRYPT_ECC - bool - default n - -config TINYCRYPT_ECC_DH - bool "ECC_DH anonymous key agreement protocol" - default n - select TINYCRYPT_ECC - ---help--- - This option enables support for the Elliptic curve - Diffie-Hellman anonymous key agreement protocol. - - Enabling ECC requires a cryptographically secure random number - generator. - -config TINYCRYPT_ECC_DSA - bool "ECC_DSA digital signature algorithm" - default n - select TINYCRYPT_ECC - ---help--- - This option enables support for the Elliptic Curve Digital - Signature Algorithm (ECDSA). - - Enabling ECC requires a cryptographically secure random number - generator. - -config TINYCRYPT_AES - bool "AES-128 decrypt/encrypt" - default n - ---help--- - This option enables support for AES-128 decrypt and encrypt. - -config TINYCRYPT_AES_CBC - bool "AES-128 block cipher" - default n - ---help--- - This option enables support for AES-128 block cipher mode. - -config TINYCRYPT_AES_CTR - bool "AES-128 counter mode" - default n - ---help--- - This option enables support for AES-128 counter mode. - -config TINYCRYPT_AES_CCM - bool "AES-128 CCM mode" - default n - ---help--- - This option enables support for AES-128 CCM mode. - -config TINYCRYPT_AES_CMAC - bool "AES-128 CMAC mode" - default n - ---help--- - This option enables support for AES-128 CMAC mode. - -config TINYCRYPT_TEST - tristate "Enable TinyCrypt test" - default n - ---help--- - Enable the TinyCrypt test. - -if TINYCRYPT_TEST - -config TINYCRYPT_TEST_PRIORITY - int "TinyCrypt test priority" - default 100 - -config TINYCRYPT_TEST_STACKSIZE - int "TinyCrypt test stack size" - default DEFAULT_TASK_STACKSIZE - -endif # TINYCRYPT_TEST - -endif # TINYCRYPT - -endmenu # "Crypto: TinyCrypt cryptography library" diff --git a/crypto/tinycrypt/Make.defs b/crypto/tinycrypt/Make.defs deleted file mode 100644 index a743cda43..000000000 --- a/crypto/tinycrypt/Make.defs +++ /dev/null @@ -1,27 +0,0 @@ -############################################################################ -# apps/crypto/tinycrypt/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_TINYCRYPT),) -CONFIGURED_APPS += $(APPDIR)/crypto/tinycrypt -CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/crypto/tinycrypt/tinycrypt/lib/include -CXXFLAGS += ${INCDIR_PREFIX}$(APPDIR)/crypto/tinycrypt/tinycrypt/lib/include -endif diff --git a/crypto/tinycrypt/Makefile b/crypto/tinycrypt/Makefile deleted file mode 100644 index d5c2c0e9f..000000000 --- a/crypto/tinycrypt/Makefile +++ /dev/null @@ -1,139 +0,0 @@ -############################################################################ -# apps/crypto/tinycrypt/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -TINYCRYPT_VERSION = $(patsubst "%",%,$(strip $(CONFIG_TINYCRYPT_VERSION))) -TINYCRYPT_URL ?= "https://github.com/intel/tinycrypt/archive/refs/tags/v$(TINYCRYPT_VERSION).zip" - -TINYCRYPT_ZIP = v$(TINYCRYPT_VERSION).zip - -TINYCRYPT_UNPACKNAME = tinycrypt -UNPACK ?= unzip -q -o - -$(TINYCRYPT_ZIP): - @echo "Downloading: $(TINYCRYPT_URL)/$(TINYCRYPT_ZIP)" - $(Q) curl -O -L $(TINYCRYPT_URL) - -$(TINYCRYPT_UNPACKNAME): $(TINYCRYPT_ZIP) - @echo "Unpacking: $(TINYCRYPT_ZIP) -> $(TINYCRYPT_UNPACKNAME)" - $(Q) $(UNPACK) $(TINYCRYPT_ZIP) - $(Q) mv tinycrypt-$(TINYCRYPT_VERSION) $(TINYCRYPT_UNPACKNAME) - $(Q) touch $(TINYCRYPT_UNPACKNAME) - $(Q) patch -p0 -d $(TINYCRYPT_UNPACKNAME) < 0001-TinyCrypt-test-resolve-compile-error.patch - -ifeq ($(wildcard $(TINYCRYPT_UNPACKNAME)/.git),) -context:: $(TINYCRYPT_UNPACKNAME) - -distclean:: - $(Q) rm -rf $(TINYCRYPT_UNPACKNAME) -endif - -CFLAGS += ${DEFINE_PREFIX}unix -CSRCS += tinycrypt/lib/source/utils.c - -ifeq ($(CONFIG_TINYCRYPT_ECC),y) -CSRCS += tinycrypt/lib/source/ecc.c -CSRCS += tinycrypt/lib/source/ecc_platform_specific.c -endif - -ifeq ($(CONFIG_TINYCRYPT_ECC_DH),y) - CSRCS += tinycrypt/lib/source/ecc_dh.c -endif - -ifeq ($(CONFIG_TINYCRYPT_ECC_DSA),y) - CSRCS += tinycrypt/lib/source/ecc_dsa.c -endif - -ifeq ($(CONFIG_TINYCRYPT_AES),y) - CSRCS += tinycrypt/lib/source/aes_decrypt.c -endif - -ifeq ($(CONFIG_TINYCRYPT_AES),y) - CSRCS += tinycrypt/lib/source/aes_encrypt.c -endif - -ifeq ($(CONFIG_TINYCRYPT_AES_CBC),y) - CSRCS += tinycrypt/lib/source/cbc_mode.c -endif - -ifeq ($(CONFIG_TINYCRYPT_AES_CTR),y) - CSRCS += tinycrypt/lib/source/ctr_mode.c -endif - -ifeq ($(CONFIG_TINYCRYPT_AES_CCM),y) - CSRCS += tinycrypt/lib/source/ccm_mode.c -endif - -ifeq ($(CONFIG_TINYCRYPT_AES_CMAC),y) - CSRCS += tinycrypt/lib/source/cmac_mode.c -endif - -ifeq ($(CONFIG_TINYCRYPT_SHA256),y) - CSRCS += tinycrypt/lib/source/sha256.c -endif - -ifeq ($(CONFIG_TINYCRYPT_SHA256_HMAC),y) - CSRCS += tinycrypt/lib/source/hmac.c -endif - -ifeq ($(CONFIG_TINYCRYPT_SHA256_HMAC_PRNG),y) - CSRCS += tinycrypt/lib/source/hmac_prng.c -endif - -ifeq ($(CONFIG_TINYCRYPT_CTR_PRNG),y) - CSRCS += tinycrypt/lib/source/ctr_prng.c -endif - -ifneq ($(CONFIG_TINYCRYPT_TEST),) - CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/crypto/tinycrypt/tinycrypt/tests/include - CFLAGS += -DENABLE_TESTS - CSRCS += tinycrypt/tests/test_ecc_utils.c - MODULE += $(CONFIG_TINYCRYPT_TEST) - PRIORITY = $(CONFIG_TINYCRYPT_TEST_PRIORITY) - STACKSIZE = $(CONFIG_TINYCRYPT_TEST_STACKSIZE) - - MAINSRC += tinycrypt/tests/test_aes.c - MAINSRC += tinycrypt/tests/test_cbc_mode.c - MAINSRC += tinycrypt/tests/test_ccm_mode.c - MAINSRC += tinycrypt/tests/test_cmac_mode.c - MAINSRC += tinycrypt/tests/test_ctr_mode.c - MAINSRC += tinycrypt/tests/test_ctr_prng.c - MAINSRC += tinycrypt/tests/test_ecc_dh.c - MAINSRC += tinycrypt/tests/test_ecc_dsa.c - MAINSRC += tinycrypt/tests/test_hmac.c - MAINSRC += tinycrypt/tests/test_hmac_prng.c - MAINSRC += tinycrypt/tests/test_sha256.c - PROGNAME += tinycrypt_test_aes - PROGNAME += tinycrypt_test_cbc_mode - PROGNAME += tinycrypt_test_ccm_mode - PROGNAME += tinycrypt_test_cmac_mode - PROGNAME += tinycrypt_test_ctr_mode - PROGNAME += tinycrypt_test_ctr_prng - PROGNAME += tinycrypt_test_ecc_dh - PROGNAME += tinycrypt_test_ecc_dsa - PROGNAME += tinycrypt_test_hmac - PROGNAME += tinycrypt_test_hmac_prng - PROGNAME += tinycrypt_test_sha256 -endif - -include $(APPDIR)/Application.mk diff --git a/crypto/tinydtls/.gitignore b/crypto/tinydtls/.gitignore deleted file mode 100644 index bc1a4e3d2..000000000 --- a/crypto/tinydtls/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/tinydtls -/*.tar.gz diff --git a/crypto/tinydtls/CMakeLists.txt b/crypto/tinydtls/CMakeLists.txt deleted file mode 100644 index 525422b4d..000000000 --- a/crypto/tinydtls/CMakeLists.txt +++ /dev/null @@ -1,86 +0,0 @@ -# ############################################################################## -# apps/crypto/tinydtls/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_CRYPTO_TINYDTLS) - - if(NOT EXISTS ${CMAKE_CURRENT_LIST_DIR}/tinydtls) - FetchContent_Declare( - tinydtls - DOWNLOAD_NAME "${CONFIG_TINYDTLS_VERSION}.tar.gz" - DOWNLOAD_DIR ${CMAKE_CURRENT_LIST_DIR} - URL "https://github.com/eclipse/tinydtls/archive/${CONFIG_TINYDTLS_VERSION}.tar.gz" - SOURCE_DIR - ${CMAKE_CURRENT_LIST_DIR}/tinydtls - BINARY_DIR - ${CMAKE_BINARY_DIR}/apps/crypto/tinydtls/tinydtls - DOWNLOAD_NO_PROGRESS true - TIMEOUT 30) - - FetchContent_GetProperties(tinydtls) - - if(NOT tinydtls_POPULATED) - FetchContent_Populate(tinydtls) - endif() - endif() - - add_subdirectory(tinydtls) - - target_compile_definitions( - tinydtls - PRIVATE HAVE_ARPA_INET_H - HAVE_ASSERT_H - HAVE_FCNTL_H - HAVE_GETRANDOM - HAVE_INTTYPES_H - HAVE_MEMSET - HAVE_NETDB_H - HAVE_NETINET_IN_H - HAVE_RANDOM - HAVE_SELECT - HAVE_SOCKET - HAVE_STDDEF_H - HAVE_STDINT_H - HAVE_STDLIB_H - HAVE_STRDUP - HAVE_STRERROR - HAVE_STRINGS_H - HAVE_STRING_H - HAVE_STRNLEN - HAVE_SYS_SOCKET_H - HAVE_SYS_STAT_H - HAVE_SYS_TIME_H - HAVE_SYS_TYPES_H - HAVE_TIME_H - HAVE_UNISTD_H - HAVE_VPRINTF - HAVE_SNPRINTF) - - target_compile_options(tinydtls PRIVATE -Wno-unused -Wno-inline) - - # TODO: this should be function in nuttx/cmake/nuttx_add_library.cmake - set_property(GLOBAL APPEND PROPERTY NUTTX_EXTRA_LIBRARIES tinydtls) - nuttx_add_library_internal(tinydtls) - - # allow #include "tinydtls/xxx.h" - target_include_directories(tinydtls PUBLIC .) - -endif() diff --git a/crypto/tinydtls/Kconfig b/crypto/tinydtls/Kconfig deleted file mode 100644 index 509d79631..000000000 --- a/crypto/tinydtls/Kconfig +++ /dev/null @@ -1,19 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config CRYPTO_TINYDTLS - bool "Eclipse Tinydtls" - default n - depends on ALLOW_ECLIPSE_COMPONENTS - ---help--- - Enable Eclipse tinydtls - a minimal library for DTLS. - -if CRYPTO_TINYDTLS - -config TINYDTLS_VERSION - string "Tinydtls version" - default "ba830a390642d057fcf21bbb6bd57546d12e584c" - -endif # CRYPTO_TINYDTLS diff --git a/crypto/wolfssl/.gitignore b/crypto/wolfssl/.gitignore deleted file mode 100644 index 1bf28703f..000000000 --- a/crypto/wolfssl/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/wolfssl -/wolfssl-examples diff --git a/crypto/wolfssl/Kconfig b/crypto/wolfssl/Kconfig deleted file mode 100644 index 51da239db..000000000 --- a/crypto/wolfssl/Kconfig +++ /dev/null @@ -1,112 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# -if ALLOW_GPL_COMPONENTS - -menuconfig CRYPTO_WOLFSSL - bool "wolfSSL SSL/TLS Cryptography Library" - default n - depends on ALLOW_GPL_COMPONENTS - ---help--- - Enable support for wolfSSL - -if CRYPTO_WOLFSSL - -config WOLFSSL_VERSION - string "wolfSSL Version" - default "5.5.4" - -menuconfig WOLFCRYPT_APPS - tristate "wolfCrypt applications" - default n - ---help--- - Enable wolfCrypt applications - -if WOLFCRYPT_APPS - -config WOLFSSL_DEFAULT_TASK_STACKSIZE - int "wolfSSL app default stack size" - default 16384 - -config WOLFCRYPT_APP_BENCHMARK - bool "wolfCrypt Benchmark application" - default n - ---help--- - Enable the wolfCrypt benchmark application - -if WOLFCRYPT_APP_BENCHMARK - -config WOLFCRYPT_APP_BENCHMARK_PROGNAME - string "Program name" - default "wolfcrypt_benchmark" - ---help--- - This is the name of the program that will be used when the NSH ELF - program is installed. - -config WOLFCRYPT_APP_BENCHMARK_PRIORITY - int "wolfcrypt benchmark task priority" - default 100 - -config WOLFCRYPT_APP_BENCHMARK_STACKSIZE - int "wolfcrypt benchmark stack size" - default WOLFSSL_DEFAULT_TASK_STACKSIZE - -endif - -config WOLFCRYPT_APP_SELFTEST - bool "wolfCrypt Self Test application" - default n - ---help--- - Enable the wolfCrypt self-test app - -if WOLFCRYPT_APP_SELFTEST - -config WOLFCRYPT_APP_SELFTEST_PROGNAME - string "Program name" - default "wolfcrypt_test" - ---help--- - This is the name of the program that will be used when the NSH ELF - program is installed. - -config WOLFCRYPT_APP_SELFTEST_PRIORITY - int "wolfcrypt self-test task priority" - default 100 - -config WOLFCRYPT_APP_SELFTEST_STACKSIZE - int "wolfcrypt self-test stack size" - default WOLFSSL_DEFAULT_TASK_STACKSIZE - -endif - -config WOLFSSL_APP_CLIENT_SERVER - bool "wolfSSL client and server example" - default n - ---help--- - runs both a tls client and server in the same task that connect to one - another, requires local loopback - -if WOLFSSL_APP_CLIENT_SERVER - -config WOLFSSL_APP_CLIENT_SERVER_PROGNAME - string "Program name" - default "wolfssl_client_server" - ---help--- - This is the name of the program that will be used when the NSH ELF - program is installed. - -config WOLFSSL_APP_CLIENT_SERVER_PRIORITY - int "wolfssl client server task priority" - default 100 - -config WOLFSSL_APP_CLIENT_SERVER_STACKSIZE - int "wolfssl client server stack size" - default WOLFSSL_DEFAULT_TASK_STACKSIZE - -endif - -endif - -endif # CRYPTO_WOLFSSL - -endif # ALLOW_GPL_COMPONENTS diff --git a/crypto/wolfssl/Make.defs b/crypto/wolfssl/Make.defs deleted file mode 100644 index 889778a18..000000000 --- a/crypto/wolfssl/Make.defs +++ /dev/null @@ -1,34 +0,0 @@ -# ############################################################################## -# apps/crypto/wolfssl/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -ifeq ($(CONFIG_CRYPTO_WOLFSSL),y) -CONFIGURED_APPS += $(APPDIR)/crypto/wolfssl - -CFLAGS += ${INCDIR_PREFIX}${APPDIR}/crypto/wolfssl -CFLAGS += ${INCDIR_PREFIX}${APPDIR}/crypto/wolfssl/wolfssl -CFLAGS += ${DEFINE_PREFIX}WOLFSSL_CONFIG_FILE="<crypto/wolfssl_config.h>" - -CXXFLAGS += ${INCDIR_PREFIX}${APPDIR}/crypto/wolfssl -CXXFLAGS += ${INCDIR_PREFIX}${APPDIR}/crypto/wolfssl/wolfssl -CXXFLAGS += ${DEFINE_PREFIX}WOLFSSL_CONFIG_FILE="<crypto/wolfssl_config.h>" - -endif diff --git a/crypto/wolfssl/Makefile b/crypto/wolfssl/Makefile deleted file mode 100644 index 90b0f6390..000000000 --- a/crypto/wolfssl/Makefile +++ /dev/null @@ -1,175 +0,0 @@ -# ############################################################################## -# apps/crypto/wolfssl/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -include $(APPDIR)/Make.defs - -# wolfSSL SSL/TLS crypto library - -WOLFSSL_VERSION = $(patsubst "%",%,$(strip $(CONFIG_WOLFSSL_VERSION))) - -WOLFSSL_UNPACKNAME = wolfssl -WOLFSSL_EXAMPLESNAME = wolfssl-examples - -# WOLFSSL TLS FILES -CSRCS += $(WOLFSSL_UNPACKNAME)/src/crl.c -CSRCS += $(WOLFSSL_UNPACKNAME)/src/internal.c -CSRCS += $(WOLFSSL_UNPACKNAME)/src/keys.c -CSRCS += $(WOLFSSL_UNPACKNAME)/src/ocsp.c -CSRCS += $(WOLFSSL_UNPACKNAME)/src/sniffer.c -CSRCS += $(WOLFSSL_UNPACKNAME)/src/ssl.c -CSRCS += $(WOLFSSL_UNPACKNAME)/src/tls.c -CSRCS += $(WOLFSSL_UNPACKNAME)/src/tls13.c -CSRCS += $(WOLFSSL_UNPACKNAME)/src/wolfio.c - -# wolfCrypt Core (FIPS validated crypto available contact fips@wolfssl.com) -CSRCS += $(WOLFSSL_UNPACKNAME)/wolfcrypt/src/aes.c -CSRCS += $(WOLFSSL_UNPACKNAME)/wolfcrypt/src/cmac.c -CSRCS += $(WOLFSSL_UNPACKNAME)/wolfcrypt/src/des3.c -CSRCS += $(WOLFSSL_UNPACKNAME)/wolfcrypt/src/dh.c -CSRCS += $(WOLFSSL_UNPACKNAME)/wolfcrypt/src/ecc.c -CSRCS += $(WOLFSSL_UNPACKNAME)/wolfcrypt/src/hmac.c -CSRCS += $(WOLFSSL_UNPACKNAME)/wolfcrypt/src/random.c -CSRCS += $(WOLFSSL_UNPACKNAME)/wolfcrypt/src/rsa.c -CSRCS += $(WOLFSSL_UNPACKNAME)/wolfcrypt/src/sha.c -CSRCS += $(WOLFSSL_UNPACKNAME)/wolfcrypt/src/sha256.c -CSRCS += $(WOLFSSL_UNPACKNAME)/wolfcrypt/src/sha512.c -CSRCS += $(WOLFSSL_UNPACKNAME)/wolfcrypt/src/sha3.c - -# wolfCrypt Additional -CSRCS += $(WOLFSSL_UNPACKNAME)/wolfcrypt/src/asm.c -CSRCS += $(WOLFSSL_UNPACKNAME)/wolfcrypt/src/asn.c -CSRCS += $(WOLFSSL_UNPACKNAME)/wolfcrypt/src/blake2s.c -CSRCS += $(WOLFSSL_UNPACKNAME)/wolfcrypt/src/chacha.c -CSRCS += $(WOLFSSL_UNPACKNAME)/wolfcrypt/src/chacha20_poly1305.c -CSRCS += $(WOLFSSL_UNPACKNAME)/wolfcrypt/src/coding.c -CSRCS += $(WOLFSSL_UNPACKNAME)/wolfcrypt/src/compress.c -CSRCS += $(WOLFSSL_UNPACKNAME)/wolfcrypt/src/cpuid.c -CSRCS += $(WOLFSSL_UNPACKNAME)/wolfcrypt/src/cryptocb.c -CSRCS += $(WOLFSSL_UNPACKNAME)/wolfcrypt/src/curve25519.c -CSRCS += $(WOLFSSL_UNPACKNAME)/wolfcrypt/src/curve448.c -CSRCS += $(WOLFSSL_UNPACKNAME)/wolfcrypt/src/ecc_fp.c -CSRCS += $(WOLFSSL_UNPACKNAME)/wolfcrypt/src/eccsi.c -CSRCS += $(WOLFSSL_UNPACKNAME)/wolfcrypt/src/ed25519.c -CSRCS += $(WOLFSSL_UNPACKNAME)/wolfcrypt/src/ed448.c -CSRCS += $(WOLFSSL_UNPACKNAME)/wolfcrypt/src/error.c -CSRCS += $(WOLFSSL_UNPACKNAME)/wolfcrypt/src/fe_448.c -CSRCS += $(WOLFSSL_UNPACKNAME)/wolfcrypt/src/fe_low_mem.c -CSRCS += $(WOLFSSL_UNPACKNAME)/wolfcrypt/src/fe_operations.c -CSRCS += $(WOLFSSL_UNPACKNAME)/wolfcrypt/src/ge_448.c -CSRCS += $(WOLFSSL_UNPACKNAME)/wolfcrypt/src/ge_low_mem.c -CSRCS += $(WOLFSSL_UNPACKNAME)/wolfcrypt/src/ge_operations.c -CSRCS += $(WOLFSSL_UNPACKNAME)/wolfcrypt/src/hash.c -CSRCS += $(WOLFSSL_UNPACKNAME)/wolfcrypt/src/kdf.c -CSRCS += $(WOLFSSL_UNPACKNAME)/wolfcrypt/src/integer.c -CSRCS += $(WOLFSSL_UNPACKNAME)/wolfcrypt/src/logging.c -CSRCS += $(WOLFSSL_UNPACKNAME)/wolfcrypt/src/md5.c -CSRCS += $(WOLFSSL_UNPACKNAME)/wolfcrypt/src/memory.c -CSRCS += $(WOLFSSL_UNPACKNAME)/wolfcrypt/src/pkcs12.c -CSRCS += $(WOLFSSL_UNPACKNAME)/wolfcrypt/src/pkcs7.c -CSRCS += $(WOLFSSL_UNPACKNAME)/wolfcrypt/src/poly1305.c -CSRCS += $(WOLFSSL_UNPACKNAME)/wolfcrypt/src/pwdbased.c -CSRCS += $(WOLFSSL_UNPACKNAME)/wolfcrypt/src/rc2.c -CSRCS += $(WOLFSSL_UNPACKNAME)/wolfcrypt/src/sakke.c -CSRCS += $(WOLFSSL_UNPACKNAME)/wolfcrypt/src/signature.c -CSRCS += $(WOLFSSL_UNPACKNAME)/wolfcrypt/src/srp.c -CSRCS += $(WOLFSSL_UNPACKNAME)/wolfcrypt/src/sp_arm32.c -CSRCS += $(WOLFSSL_UNPACKNAME)/wolfcrypt/src/sp_arm64.c -CSRCS += $(WOLFSSL_UNPACKNAME)/wolfcrypt/src/sp_armthumb.c -CSRCS += $(WOLFSSL_UNPACKNAME)/wolfcrypt/src/sp_c32.c -CSRCS += $(WOLFSSL_UNPACKNAME)/wolfcrypt/src/sp_c64.c -CSRCS += $(WOLFSSL_UNPACKNAME)/wolfcrypt/src/sp_cortexm.c -CSRCS += $(WOLFSSL_UNPACKNAME)/wolfcrypt/src/sp_dsp32.c -CSRCS += $(WOLFSSL_UNPACKNAME)/wolfcrypt/src/sp_int.c -CSRCS += $(WOLFSSL_UNPACKNAME)/wolfcrypt/src/sp_x86_64.c -CSRCS += $(WOLFSSL_UNPACKNAME)/wolfcrypt/src/tfm.c -CSRCS += $(WOLFSSL_UNPACKNAME)/wolfcrypt/src/wc_dsp.c -CSRCS += $(WOLFSSL_UNPACKNAME)/wolfcrypt/src/wc_encrypt.c -CSRCS += $(WOLFSSL_UNPACKNAME)/wolfcrypt/src/wc_pkcs11.c -CSRCS += $(WOLFSSL_UNPACKNAME)/wolfcrypt/src/wc_port.c -CSRCS += $(WOLFSSL_UNPACKNAME)/wolfcrypt/src/wolfevent.c -CSRCS += $(WOLFSSL_UNPACKNAME)/wolfcrypt/src/wolfmath.c - -CFLAGS += -DWOLFSSL_USER_SETTINGS - -ifneq ($(CONFIG_WOLFCRYPT_APPS),) - -MODULE = $(CONFIG_WOLFSSL_APPS) - -ifeq ($(CONFIG_WOLFCRYPT_APP_BENCHMARK),y) - -PROGNAME += $(CONFIG_WOLFCRYPT_APP_BENCHMARK_PROGNAME) -PRIORITY += $(CONFIG_WOLFCRYPT_APP_BENCHMARK_PRIORITY) -STACKSIZE += $(CONFIG_WOLFCRYPT_APP_BENCHMARK_STACKSIZE) - -CFLAGS += -I$(WOLFSSL_UNPACKNAME) -CFLAGS += -I$(WOLFSSL_UNPACKNAME)/../ # To reach user_settings.h -MAINSRC += $(WOLFSSL_UNPACKNAME)/wolfcrypt/benchmark/benchmark.c - -endif - -ifeq ($(CONFIG_WOLFCRYPT_APP_SELFTEST),y) - -PROGNAME += $(CONFIG_WOLFCRYPT_APP_SELFTEST_PROGNAME) -PRIORITY += $(CONFIG_WOLFCRYPT_APP_SELFTEST_PRIORITY) -STACKSIZE += $(CONFIG_WOLFCRYPT_APP_SELFTEST_STACKSIZE) - -CFLAGS += -I$(WOLFSSL_UNPACKNAME) -CFLAGS += -I$(WOLFSSL_UNPACKNAME)/../ # To reach user_settings.h -MAINSRC += $(WOLFSSL_UNPACKNAME)/wolfcrypt/test/test.c - -endif - -ifeq ($(CONFIG_WOLFSSL_APP_CLIENT_SERVER),y) - -PROGNAME += $(CONFIG_WOLFSSL_APP_CLIENT_SERVER_PROGNAME) -PRIORITY += $(CONFIG_WOLFSSL_APP_CLIENT_SERVER_PRIORITY) -STACKSIZE += $(CONFIG_WOLFSSL_APP_CLIENT_SERVER_STACKSIZE) - -CFLAGS += -I$(WOLFSSL_UNPACKNAME) -CFLAGS += -I$(WOLFSSL_UNPACKNAME)/../ # To reach user_settings.h -MAINSRC += $(WOLFSSL_EXAMPLESNAME)/embedded/tls-client-server.c - -endif - -endif - -ifeq ($(CONFIG_WOLFSSL_APP_CLIENT_SERVER),y) -wolfssl: - git clone git@github.com:wolfSSL/wolfssl.git $(WOLFSSL_UNPACKNAME) - git clone git@github.com:wolfSSL/wolfssl-examples.git $(WOLFSSL_EXAMPLESNAME) -else -wolfssl: - git clone git@github.com:wolfSSL/wolfssl.git $(WOLFSSL_UNPACKNAME) -endif - -context:: wolfssl - -ifeq ($(CONFIG_WOLFSSL_APP_CLIENT_SERVER),y) -distclean:: - $(call DELDIR, $(WOLFSSL_UNPACKNAME)) - $(call DELDIR, $(WOLFSSL_EXAMPLESNAME)) -else -distclean:: - $(call DELDIR, $(WOLFSSL_UNPACKNAME)) -endif - -include $(APPDIR)/Application.mk diff --git a/crypto/wolfssl/user_settings.h b/crypto/wolfssl/user_settings.h deleted file mode 100644 index 66427efdd..000000000 --- a/crypto/wolfssl/user_settings.h +++ /dev/null @@ -1,74 +0,0 @@ -/**************************************************************************** - * apps/crypto/wolfssl/user_settings.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - ****************************************************************************/ - -#include <nuttx/config.h> - -/* Library */ -#define SINGLE_THREADED -#define WOLFSSL_SMALL_STACK - -/* Environment */ -#define NO_FILESYSTEM -#define HAVE_STRINGS_H -#define WOLF_C99 - -/* Math */ -#define WOLFSSL_SP_MATH_ALL - -/* Crypto */ -#define HAVE_ECC -#define ECC_TIMING_RESISTANT -#define WC_RSA_BLINDING -#undef RSA_LOW_MEM -#define NO_MD4 -#define NO_DSA - -/* RNG */ -#define WOLFSSL_GENSEED_FORTEST - -/* Applications */ -#define NO_MAIN_FUNCTION -#define BENCH_EMBEDDED -#define WOLFSSL_BENCHMARK_FIXED_UNITS_MB - -/* Development */ -/*#define DEBUG_WOLFSSL*/ - -#define HAVE_TLS_EXTENSIONS -#define HAVE_SUPPORTED_CURVES -#define HAVE_ENCRYPT_THEN_MAC -#define HAVE_EXTENDED_MASTER -#define WOLFSSL_TLS13 -#define HAVE_AESGCM -#define HAVE_HKDF -#define HAVE_DH -#define HAVE_FFDHE_2048 -#define HAVE_DH_DEFAULT_PARAMS -#define WC_RSA_PSS -#define HAVE_AEAD -#define WOLFSSL_SHA224 -#define WOLFSSL_SHA384 -#define WOLFSSL_SHA512 -#define WOLFSSL_SHA3 -#define HAVE_POLY1305 -#define HAVE_CHACHA -#define HAVE_ENCRYPT_THEN_MAC -#define NO_OLD_TLS diff --git a/database/.gitignore b/database/.gitignore deleted file mode 100644 index 9e1d2593e..000000000 --- a/database/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/Kconfig diff --git a/database/Make.defs b/database/Make.defs deleted file mode 100644 index c6529b97e..000000000 --- a/database/Make.defs +++ /dev/null @@ -1,23 +0,0 @@ -############################################################################ -# apps/database/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(wildcard $(APPDIR)/database/*/Make.defs) diff --git a/database/Makefile b/database/Makefile deleted file mode 100644 index 4ee15a776..000000000 --- a/database/Makefile +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/database/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -MENUDESC = "Database" - -include $(APPDIR)/Directory.mk diff --git a/database/sqlite/.gitignore b/database/sqlite/.gitignore deleted file mode 100644 index 4292e4d3b..000000000 --- a/database/sqlite/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -/build -/sqlite -*.zip diff --git a/database/sqlite/Kconfig b/database/sqlite/Kconfig deleted file mode 100644 index fb15805ff..000000000 --- a/database/sqlite/Kconfig +++ /dev/null @@ -1,26 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config LIB_SQLITE - bool "SQLITE library" - depends on CONFIG_FS_LOCK_BUCKET_SIZE > 0 - default n - -if LIB_SQLITE - -config LIB_SQLITE_VERSION - string "SQLITE version" - default "3.45.1" - -config UTILS_SQLITE - tristate "SQLite cmd line tool" - default n - -config UTILS_SQLITE_STACKSIZE - int "SQLite3 cmd line tool stack size" - default 8192 - depends on UTILS_SQLITE - -endif diff --git a/database/sqlite/Make.defs b/database/sqlite/Make.defs deleted file mode 100644 index 3d14dbe01..000000000 --- a/database/sqlite/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/database/sqlite/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_LIB_SQLITE),) -CONFIGURED_APPS += $(APPDIR)/database/sqlite -endif diff --git a/database/sqlite/Makefile b/database/sqlite/Makefile deleted file mode 100644 index 3a109672f..000000000 --- a/database/sqlite/Makefile +++ /dev/null @@ -1,70 +0,0 @@ -############################################################################ -# apps/database/sqlite/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -SQLITEDIR=$(APPDIR)/database/sqlite -BUILDDIR=$(SQLITEDIR)/build - -CSRCS += ${BUILDDIR}/sqlite3.c - -CFLAGS += ${INCDIR_PREFIX}$(SQLITEDIR) -CFLAGS += ${DEFINE_PREFIX}_HAVE_SQLITE_CONFIG_H -CFLAGS += ${DEFINE_PREFIX}NDEBUG -CFLAGS += -Wno-unused-variable -Wno-undef -Wno-unused-function -Wno-shadow - -ifneq ($(CONFIG_UTILS_SQLITE),) -PROGNAME = sqlite3 -PRIORITY = 100 -STACKSIZE = ${CONFIG_UTILS_SQLITE_STACKSIZE} -MODULE = $(CONFIG_UTILS_SQLITE) -MAINSRC = ${BUILDDIR}/shell.c -endif - - -# Download and unpack tarball if no git repo found - -sqlite.zip: -ifeq ($(wildcard sqlite/.git),) - $(Q) curl -L https://codeload.github.com/sqlite/sqlite/zip/refs/tags/vesion-${CONFIG_LIB_SQLITE_VERSION} -o sqlite.zip - $(Q) unzip -q -o sqlite.zip - $(Q) mv sqlite-vesion-* sqlite - $(call DELFILE, sqlite.zip) -endif - -context:: sqlite.zip - $(Q) mkdir -p ${BUILDDIR} && \ - cd ${BUILDDIR} && \ - echo "Generate SQLite amalgamation version" && \ - ${SQLITEDIR}/sqlite/configure 1> /dev/null && \ - make sqlite3.c -j 1> /dev/null - -clean:: - $(call DELFILE, ${BUILDDIR}/*.o) - -distclean:: - $(call DELDIR, ${BUILDDIR}) -ifeq ($(wildcard sqlite/.git),) - $(call DELDIR, sqlite) -endif - -include $(APPDIR)/Application.mk diff --git a/database/sqlite/sqlite_cfg.h b/database/sqlite/sqlite_cfg.h deleted file mode 100644 index fcd1d7f07..000000000 --- a/database/sqlite/sqlite_cfg.h +++ /dev/null @@ -1,145 +0,0 @@ -/* sqlite_cfg.h. Generated from sqlite_cfg.h.in by configure. */ -/* sqlite_cfg.h.in. Generated from configure.ac by autoheader. */ - -/* Define to 1 if you have the <dlfcn.h> header file. */ -#define HAVE_DLFCN_H 1 - -/* Define to 1 if you have the `fdatasync' function. */ -#define HAVE_FDATASYNC 1 - -/* Define to 1 if you have the `gmtime_r' function. */ -#define HAVE_GMTIME_R 1 - -/* Define to 1 if the system has the type `int16_t'. */ -#define HAVE_INT16_T 1 - -/* Define to 1 if the system has the type `int32_t'. */ -#define HAVE_INT32_T 1 - -/* Define to 1 if the system has the type `int64_t'. */ -#define HAVE_INT64_T 1 - -/* Define to 1 if the system has the type `int8_t'. */ -#define HAVE_INT8_T 1 - -/* Define to 1 if the system has the type `intptr_t'. */ -#define HAVE_INTPTR_T 1 - -/* Define to 1 if you have the <inttypes.h> header file. */ -#define HAVE_INTTYPES_H 1 - -/* Define to 1 if you have the `isnan' function. */ -#define HAVE_ISNAN 1 - -/* Define to 1 if you have the `localtime_r' function. */ -#define HAVE_LOCALTIME_R 1 - -/* Define to 1 if you have the `localtime_s' function. */ -/* #undef HAVE_LOCALTIME_S */ - -/* Define to 1 if you have the <malloc.h> header file. */ -#define HAVE_MALLOC_H 1 - -/* Define to 1 if you have the `malloc_usable_size' function. */ -#define HAVE_MALLOC_USABLE_SIZE 1 - -/* Define to 1 if you have the <memory.h> header file. */ -#define HAVE_MEMORY_H 1 - -/* Define to 1 if you have the `pread' function. */ -#define HAVE_PREAD 1 - -/* Define to 1 if you have the `pread64' function. */ -#define HAVE_PREAD64 1 - -/* Define to 1 if you have the `pwrite' function. */ -#define HAVE_PWRITE 1 - -/* Define to 1 if you have the `pwrite64' function. */ -#define HAVE_PWRITE64 1 - -/* Define to 1 if you have the <stdint.h> header file. */ -#define HAVE_STDINT_H 1 - -/* Define to 1 if you have the <stdlib.h> header file. */ -#define HAVE_STDLIB_H 1 - -/* Define to 1 if you have the `strchrnul' function. */ -#define HAVE_STRCHRNUL 1 - -/* Define to 1 if you have the <strings.h> header file. */ -#define HAVE_STRINGS_H 1 - -/* Define to 1 if you have the <string.h> header file. */ -#define HAVE_STRING_H 1 - -/* Define to 1 if you have the <sys/stat.h> header file. */ -#define HAVE_SYS_STAT_H 1 - -/* Define to 1 if you have the <sys/types.h> header file. */ -#define HAVE_SYS_TYPES_H 1 - -/* Define to 1 if the system has the type `uint16_t'. */ -#define HAVE_UINT16_T 1 - -/* Define to 1 if the system has the type `uint32_t'. */ -#define HAVE_UINT32_T 1 - -/* Define to 1 if the system has the type `uint64_t'. */ -#define HAVE_UINT64_T 1 - -/* Define to 1 if the system has the type `uint8_t'. */ -#define HAVE_UINT8_T 1 - -/* Define to 1 if the system has the type `uintptr_t'. */ -#define HAVE_UINTPTR_T 1 - -/* Define to 1 if you have the <unistd.h> header file. */ -#define HAVE_UNISTD_H 1 - -/* Define to 1 if you have the `usleep' function. */ -#define HAVE_USLEEP 1 - -/* Define to 1 if you have the `utime' function. */ -#define HAVE_UTIME 1 - -/* Define to 1 if you have the <zlib.h> header file. */ -#ifdef CONFIG_LIB_ZLIB -# define HAVE_ZLIB_H 1 -#endif - -/* Define to the sub-directory in which libtool stores uninstalled libraries. - */ -#define LT_OBJDIR ".libs/" - -/* Define to the address where bug reports for this package should be sent. */ -#define PACKAGE_BUGREPORT "" - -/* Define to the full name of this package. */ -#define PACKAGE_NAME "sqlite" - -/* Define to the full name and version of this package. */ -#define PACKAGE_STRING "sqlite 3.45.1" - -/* Define to the one symbol short name of this package. */ -#define PACKAGE_TARNAME "sqlite" - -/* Define to the home page for this package. */ -#define PACKAGE_URL "" - -/* Define to the version of this package. */ -#define PACKAGE_VERSION "3.45.1" - -/* Define to 1 if you have the ANSI C header files. */ -#define STDC_HEADERS 1 - -/* Enable large inode numbers on Mac OS X 10.5. */ -#ifndef _DARWIN_USE_64_BIT_INODE -# define _DARWIN_USE_64_BIT_INODE 1 -#endif - -/* Number of bits in a file offset, on hosts where this is settable. */ -/* #undef _FILE_OFFSET_BITS */ - -/* Define for large files, on AIX-style hosts. */ -/* #undef _LARGE_FILES */ diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt deleted file mode 100644 index 3d04efdf4..000000000 --- a/examples/CMakeLists.txt +++ /dev/null @@ -1,24 +0,0 @@ -# ############################################################################## -# apps/examples/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -nuttx_add_subdirectory() -nuttx_generate_kconfig(MENUDESC "Examples") diff --git a/examples/Make.defs b/examples/Make.defs index 08127668f..aa354e503 100644 --- a/examples/Make.defs +++ b/examples/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/Makefile b/examples/Makefile index 9f8132ba5..26ecf518a 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/README.md b/examples/README.md new file mode 100644 index 000000000..1ad7b8d7e --- /dev/null +++ b/examples/README.md @@ -0,0 +1,2157 @@ +# Examples + +### Selecting Examples + +The examples directory contains several sample applications that can be linked +with NuttX. The specific example is selected in the +`boards/<arch-name>/<chip-name>/<board-name>/configs/<config>/defconfig` file +via the `CONFIG_EXAMPLES_xyz` setting where `xyz` is the name of the example. +For example: + +```conf +CONFIG_EXAMPLES_HELLO=y +``` + +Selects the `examples/hello` _Hello, World!_ example. + +### Built-In Functions + +Some of the examples may be built as _built-in_ functions that can be executed +at run time (rather than as NuttX _main_ programs). These _built-in_ examples +can be also be executed from the NuttShell (NSH) command line. In order to +configure these built-in NSH functions, you have to set up the following: + +- `CONFIG_NSH_BUILTIN_APPS` โ€“ Enable support for external registered, _named_ + applications that can be executed from the NSH command line (see + `apps/README.md` for more information). + +## `adc` Read from ADC + +A mindlessly simple test of an ADC devices. It simply reads from the ADC device +and dumps the data to the console forever. + +This test depends on these specific ADC/NSH configurations settings (your +specific ADC settings might require additional settings). + +- `CONFIG_ADC` โ€“ Enabled ADC support. +- `CONFIG_NSH_BUILTIN_APPS` โ€“ Build the ADC test as an NSH built-in function. + Default: Built as a standalone program. + +Specific configuration options for this example include: + +- `CONFIG_EXAMPLES_ADC_DEVPATH` โ€“ The default path to the ADC device. Default: + `/dev/adc0`. +- `CONFIG_EXAMPLES_ADC_NSAMPLES` โ€“ This number of samples is collected and the + program terminates. Default: Samples are collected indefinitely. +- `CONFIG_EXAMPLES_ADC_GROUPSIZE` โ€“ The number of samples to read at once. + Default: `4`. + +## `ajoystick` Analog Joystick + +This is a simple test of the analog joystick driver. See details about this +driver in `nuttx/include/nuttx/input/ajoystick.h`. + +Configuration Pre-requisites: + +- `CONFIG_AJOYSTICK` โ€“ The analog joystick driver. + +Example Configuration: +- `CONFIG_EXAMPLES_AJOYSTICK` โ€“ Enabled the analog joystick example. +- `CONFIG_EXAMPLES_AJOYSTICK_DEVNAME` โ€“ Joystick device name. Default + `/dev/adjoy0`. +- `CONFIG_EXAMPLES_AJOYSTICK_SIGNO` โ€“ Signal used to signal the test + application. Default `13`. + +## `alarm` RTC Alarm + +A simple example that tests the alarm IOCTLs of the RTC driver. + +Dependencies: + +- `CONFIG_RTC_DRIVER` โ€“ RTC driver must be initialized to allow user space + access to the RTC. +- `CONFIG_RTC_ALARM` โ€“ Support for RTC alarms must be enabled. + +Configuration: + +- `CONFIG_EXAMPLES_ALARM` โ€“ Enable the RTC driver alarm test. +- `CONFIG_EXAMPLES_ALARM_PROGNAME` โ€“ This is the name of the program that will + be used when the NSH ELF program is installed. +- `CONFIG_EXAMPLES_ALARM_PRIORITY` โ€“ Alarm daemon priority. +- `CONFIG_EXAMPLES_ALARM_STACKSIZE` โ€“ Alarm daemon stack size. +- `CONFIG_EXAMPLES_ALARM_DEVPATH` โ€“ RTC device path (`/dev/rtc0`). +- `CONFIG_EXAMPLES_ALARM_SIGNO` โ€“ Alarm signal. + +## `apa102` Rainbow on `APA102` LED Strip + +Rainbow example for `APA102` LED Strip. + +## `bastest` Bas BASIC Interpreter + +This directory contains a small program that will mount a ROMFS file system +containing the BASIC test files extracted from the Bas `2.4` release. See +`examples/bastest/README.md` for licensing and usage information. + +- `CONFIG_EXAMPLES_BASTEST_DEVMINOR` โ€“ The minor device number of the ROMFS + block driver. For example, the `N` in `/dev/ramN`. Used for registering the + RAM block driver that will hold the ROMFS file system containing the BASIC + files to be tested. Default: `0`. + +- `CONFIG_EXAMPLES_BASTEST_DEVPATH` โ€“ The path to the ROMFS block driver device. + This must match `EXAMPLES_BASTEST_DEVMINOR`. Used for registering the RAM + block driver that will hold the ROMFS file system containing the BASIC files + to be tested. Default: `/dev/ram0`. + +## `bridge` Network Bridge + +A simple test of a system with multiple networks. It simply echoes all UDP +packets received on network `1` and network `2` to network `2` and network `1`, +respectively. Interface `1` and interface may or may not lie on the same +network. + +- `CONFIG_EXAMPLES_BRIDGE` โ€“ Enables the simple UDP bridge test. + +There identical configurations for each of the two networks, `NETn` where `n` +refers to the network being configured `n={1,2}`. Let `m` refer to the other +network. + +- `CONFIG_EXAMPLES_BRIDGE_NETn_IFNAME` โ€“ The register name of the network `n` + device. Must match the previously registered driver name and must not be the + same as other network device name, `CONFIG_EXAMPLES_BRIDGE_NETm_IFNAME`. +- `CONFIG_EXAMPLES_BRIDGE_NETn_RECVPORT` โ€“ Network `n` listen port number. +- `CONFIG_EXAMPLES_BRIDGE_NETn_SNDPORT` โ€“ Network `2` send port number. +- `CONFIG_EXAMPLES_BRIDGE_NETn_IOBUFIZE` โ€“ Size of the network `n` UDP + send/receive I/O buffer. +- `CONFIG_EXAMPLES_BRIDGE_NETn_STACKSIZE` โ€“ Network `n` daemon stacksize. +- `CONFIG_EXAMPLES_BRIDGE_NETn_PRIORITY` โ€“ Network `n` daemon task priority. + +If used as a NSH add-on, then it is assumed that initialization of both networks +was performed externally prior to the time that this test was started. +Otherwise, the following options are available: + +- `CONFIG_EXAMPLES_BRIDGE_NETn_NOMAC` โ€“ Select of the network `n` hardware does + not have a built-in MAC address. If selected, the MAC address. provided by + `CONFIG_EXAMPLES_BRIDGE_NETn_MACADDR` will be used to assign the MAC address + to the network n device. +- `CONFIG_EXAMPLES_BRIDGE_NETn_DHCPC` โ€“ Use DHCP Client to get the network n IP + address. +- `CONFIG_EXAMPLES_BRIDGE_NETn_IPADDR` โ€“ If `CONFIG_EXAMPLES_BRIDGE_NETn_DHCPC` + is not selected, then this is the fixed IP address for network `n`. +- `CONFIG_EXAMPLES_BRIDGE_NETn_DRIPADDR` โ€“ Network `n` default router IP address + (Gateway). +- `CONFIG_EXAMPLES_BRIDGE_NETn_NETMASK` โ€“ Network `n` mask. + +## `buttons` Read GPIO Buttons + +To be provided. + +## `can` CAN Device Test + +If the CAN device is configured in loopback mode, then this example can be used +to test the CAN device in loop back mode. It simple sinces a sequence of CAN +messages and verifies that those messages are returned exactly as sent. + +This test depends on these specific CAN/NSH configurations settings (your +specific CAN settings might require additional settings). + +- `CONFIG_CAN` โ€“ Enables CAN support. +- `CONFIG_CAN_LOOPBACK` โ€“ A CAN driver may or may not support a loopback mode + for testing. The STM32 CAN driver does support loopback mode. +- `CONFIG_NSH_BUILTIN_APPS` โ€“ Build the CAN test as an NSH built-in function. + Default: Built as a standalone program. + +Specific configuration options for this example include: + +- `CONFIG_EXAMPLES_CAN_DEVPATH` โ€“ The path to the CAN device. Default: + `/dev/can0`. +- `CONFIG_EXAMPLES_CAN_NMSGS` โ€“ This number of CAN message is collected and the + program terminates. Default: messages are sent and received indefinitely. + +The default behavior assumes loopback mode. Messages are sent, then read and +verified. The behavior can be altered for other kinds of testing where the test +only sends or received (but does not verify) can messages. + +- `CONFIG_EXAMPLES_CAN_READONLY` โ€“ Only receive messages. +- `CONFIG_EXAMPLES_CAN_WRITEONLY` โ€“ Only send messages. + +## `canard` + +Example application for `canutils/libcarnard`. + +## `cctype` + +Verifies all possible inputs for all functions defined in the header file +`cctype`. + +## `chat` AT over TTY + +Demonstrates AT chat functionality over a TTY device. This is useful with AT +modems, for example, to establish a `pppd` connection (see the related `pppd` +example). Moreover, some AT modems โ€“ such as ones made by u-blox โ€“ have an +internal TCP/IP stack, often with an implementation of TLS/SSL. In such cases +the chat utility can be used to configure the internal TCP/IP stack, establish +socket connections, set up security (e.g., download base64-encoded certificates +to the modem), and perform data exchange through sockets over the TTY device. + +Useful configuration parameters: + +- `CONFIG_EXAMPLES_CHAT_PRESET[0..3]` โ€“ preset chat scripts. +- `CONFIG_EXAMPLES_CHAT_TTY_DEVNODE` โ€“ TTY device node name. +- `CONFIG_EXAMPLES_CHAT_TIMEOUT_SECONDS` โ€“ default receive timeout. + +## `configdata` + +This is a Unit Test for the MTD configuration data driver. + +## `cpuhog` Keep CPU Busy + +Attempts to keep the system busy by passing data through a pipe in loop back +mode. This may be useful if you are trying run down other problems that you +think might only occur when the system is very busy. + +## `cordic` + +A simple test of the CORDIC character driver. + +## `dac` Write to DAC + +This is a tool for writing values to DAC device. + +## `dhcpd` DHCP Server + +This examples builds a tiny DHCP server for the target system. + +**Note**: For test purposes, this example can be built as a host-based DHCPD +server. This can be built as follows: + +```bash +cd examples/dhcpd +make -f Makefile.host TOPDIR=<nuttx-directory> +``` + +NuttX configuration settings: + +- `CONFIG_NET=y` โ€“ of course. +- `CONFIG_NET_UDP=y` โ€“ UDP support is required for DHCP (as well as various + other UDP-related configuration settings). +- `CONFIG_NET_BROADCAST=y` โ€“ UDP broadcast support is needed. +- `CONFIG_NETUTILS_NETLIB=y` โ€“ The networking library is needed. +- `CONFIG_EXAMPLES_DHCPD_NOMAC` โ€“ (May be defined to use software assigned MAC) + +See also `CONFIG_NETUTILS_DHCPD_*` settings described elsewhere and used in +`netutils/dhcpd/dhcpd.c`. These settings are required to described the behavior +of the daemon. + +## `discover` UDP Discover Daemon + +This example exercises `netutils/discover` utility. This example initializes and +starts the UDP discover daemon. This daemon is useful for discovering devices in +local networks, especially with DHCP configured devices. It listens for UDP +broadcasts which also can include a device class so that groups of devices can +be discovered. It is also possible to address all classes with a kind of +broadcast discover. + +This example will automatically be built as an NSH built-in if +`CONFIG_NSH_BUILTIN_APPS` is selected. Otherwise, it will be a standalone +program with entry point `discover_main`. + +NuttX configuration settings: + +- `CONFIG_EXAMPLES_DISCOVER_DHCPC` โ€“ DHCP Client. +- `CONFIG_EXAMPLES_DISCOVER_NOMAC` โ€“ Use canned MAC address. +- `CONFIG_EXAMPLES_DISCOVER_IPADDR` โ€“ Target IP address. +- `CONFIG_EXAMPLES_DISCOVER_DRIPADDR` โ€“ Router IP address. +- `CONFIG_EXAMPLES_DISCOVER_NETMASK` โ€“ Network Mask. + +## `djoystick` Discrete Joystick + +This is a simple test of the discrete joystick driver. See details about this +driver in `nuttx/include/nuttx/input/djoystick.h`. + +Configuration Pre-requisites: + +- `CONFIG_INPUT_DJOYSTICK` โ€“ The discrete joystick driver. + +Example Configuration: + +- `CONFIG_EXAMPLES_DJOYSTICK` โ€“ Enabled the discrete joystick example. +- `CONFIG_EXAMPLES_DJOYSTICK_DEVNAME` โ€“ Joystick device name. Default + `/dev/djoy0`. +- `CONFIG_EXAMPLES_DJOYSTICK_SIGNO` โ€“ Signal used to signal the test + application. Default `13`. + +## `elf` ELF loader + +This example builds a small ELF loader test case. This includes several test +programs under `examples/elf` tests. These tests are build using the relocatable +ELF format and installed in a ROMFS file system. At run time, each program in +the ROMFS file system is executed. Requires `CONFIG_ELF`. Other configuration +options: + +- `CONFIG_EXAMPLES_ELF_DEVMINOR` โ€“ The minor device number of the ROMFS block + driver. For example, the `N` in `/dev/ramN`. Used for registering the RAM + block driver that will hold the ROMFS file system containing the ELF + executables to be tested. Default: `0`. + +- `CONFIG_EXAMPLES_ELF_DEVPATH` โ€“ The path to the ROMFS block driver device. + This must match `EXAMPLES_ELF_DEVMINOR`. Used for registering the RAM block + driver that will hold the ROMFS file system containing the ELF executables to + be tested. Default: `/dev/ram0`. + +**Notes**: + +1. `CFLAGS` should be provided in `CELFFLAGS`. RAM and FLASH memory regions may + require long allcs. For ARM, this might be: + + ```makefile + CELFFLAGS = $(CFLAGS) -mlong-calls + ``` + + Similarly for C++ flags which must be provided in `CXXELFFLAGS`. + +2. Your top-level `nuttx/Make.defs` file must also include an appropriate + definition, `LDELFFLAGS`, to generate a relocatable ELF object. With GNU LD, + this should include `-r` and `-e main` (or `_main` on some platforms). + + ```makefile + LDELFFLAGS = -r -e main + ``` + + If you use GCC to link, you make also need to include `-nostdlib` or + `-nostartfiles` and `-nodefaultlibs`. + +3. This example also requires `genromfs`. `genromfs` can be build as part of the + nuttx toolchain. Or can built from the `genromfs` sources that can be found + in the NuttX tools repository (`genromfs-0.5.2.tar.gz`). In any event, the + `PATH` variable must include the path to the genromfs executable. + +4. ELF size: The ELF files in this example are, be default, quite large because + they include a lot of _build garbage_. You can greatly reduce the size of the + ELF binaries are using the `objcopy --strip-unneeded` command to remove + un-necessary information from the ELF files. + +5. Simulator. You cannot use this example with the NuttX simulator on Cygwin. + That is because the Cygwin GCC does not generate ELF file but rather some + Windows-native binary format. + + If you really want to do this, you can create a NuttX x86 buildroot toolchain + and use that be build the ELF executables for the ROMFS file system. + +6. Linker scripts. You might also want to use a linker scripts to combine + sections better. An example linker script is at + `nuttx/binfmt/libelf/gnu-elf.ld`. That example might have to be tuned for + your particular linker output to position additional sections correctly. The + GNU LD `LDELFFLAGS` then might be: + + ```makefile + LDELFFLAGS = -r -e main -T$(TOPDIR)/binfmt/libelf/gnu-elf.ld + ``` + +## `fb` Framebuffer + +A simple test of the framebuffer character driver. + +## `flash_test` SMART Flash + +This example performs a SMART flash block device test. This test performs a +sector allocate, read, write, free and garbage collection test on a SMART MTD +block device. + +- `CONFIG_EXAMPLES_FLASH_TEST=y` โ€“ Enables the FLASH Test. + +Dependencies: + +- `CONFIG_MTD_SMART=y` โ€“ SMART block driver support. +- `CONFIG_BUILD_PROTECTED=n` and `CONFIG_BUILD_KERNEL=n` โ€“ This test uses + internal OS interfaces and so is not available in the NUTTX kernel builds. + +## `foc` FOC motor controller + +A FOC motor controller based on the NuttX FOC driver and the NuttX FOC library. +See `apps/foc/README.md` for more information. + +## `flowc` Serial Hardware Flow Control + +A simple test of serial hardware flow control. + +## `ft80x` FT80x GUI Chip + +This examples has ports of several FTDI demos for the FTDI/BridgeTek FT80x GUI +chip. As an example configuration, see +`nuttx/boards/arm/stm32/viewtool-stm32f107/configs/ft80x/defconfig`. + +## `ftpc` FTP Client + +This is a simple FTP client shell used to exercise the capabilities of the FTPC +library (`apps/netutils/ftpc`). + +From NSH, the startup command sequence is as follows. This is only an example, +your configuration could have different mass storage devices, mount paths, and +FTP directories: + +``` +nsh> mount -t vfat /dev/mmcsd0 /tmp # Mount the SD card at /tmp +nsh> cd /tmp # cd into the /tmp directory +nsh> ftpc <host> <port> # Start the FTP client +nfc> login <name> <password> # Log into the FTP server +nfc> help # See a list of FTP commands +``` + +where `<host>` is the IP address or hostname of the FTP server and `<port>` is +an optional port number. + +**Note**: By default, FTPC uses `readline` to get data from `stdin`. So your +defconfig file must have the following build path: + +```conf +CONFIG_SYSTEM_READLINE=y +``` + +**Note**: If you use the ftpc task over a telnet NSH connection, then you should +set the following configuration item: + +```conf +CONFIG_EXAMPLES_FTPC_FGETS=y +``` + +By default, the FTPC client will use `readline()` to get characters from the +console. Readline includes and command-line editor and echos characters received +in stdin back through `stdout`. Neither of these behaviors are desire-able if +Telnet is used. + +You may also want to define the following in your configuration file. Otherwise, +you will have not feedback about what is going on: + +```conf +CONFIG_DEBUG_FEATURES=y +CONFIG_DEBUG_INFO=y +CONFIG_DEBUG_FTPC=y +``` + +## `ftpd` FTP daemon + +This example exercises the FTPD daemon at `apps/netutils/ftpd`. Below are +configurations specific to the FTPD example (the FTPD daemon itself may require +other configuration options as well). + +- `CONFIG_EXAMPLES_FTPD` โ€“ Enable the FTPD example. +- `CONFIG_EXAMPLES_FTPD_PRIO` โ€“ Priority of the FTP daemon. Default: + `SCHED_PRIORITY_DEFAULT`. +- `CONFIG_EXAMPLES_FTPD_STACKSIZE` โ€“ Stack size allocated for the FTP daemon. + Default: `2048`. +- `CONFIG_EXAMPLES_FTPD_NONETINIT` โ€“ Define to suppress configuration of the + network by `apps/examples/ftpd`. You would need to suppress network + configuration if the network is configuration prior to running the example. + +NSH always initializes the network so if `CONFIG_NSH_NETINIT` is defined, so is +`CONFIG_EXAMPLES_FTPD_NONETINIT` (se it does not explicitly need to be defined +in that case): + +- `CONFIG_NSH_BUILTIN_APPS` โ€“ Build the FTPD daemon example test as an NSH + built-in function. By default the FTPD daemon will be built as a standalone + application. + +If `CONFIG_EXAMPLES_FTPD_NONETINIT` is not defined, then the following may be +specified to customized the network configuration: + +- `CONFIG_EXAMPLES_FTPD_NOMAC` โ€“ If the hardware has no MAC address of its own, + define this `=y` to provide a bogus address for testing. +- `CONFIG_EXAMPLES_FTPD_IPADDR` โ€“ The target IP address. Default `10.0.0.2`. +- `CONFIG_EXAMPLES_FTPD_DRIPADDR` โ€“ The default router address. Default: + `10.0.0.1`. +- `CONFIG_EXAMPLES_FTPD_NETMASK` โ€“ The network mask. Default: `255.255.255.0`. + +TCP networking support is required. So are pthreads so this must be set to 'n': + +- `CONFIG_DISABLE_PTHREAD` โ€“ `pthread` support is required. + +Other FTPD configuration options they may be of interest: + +- `CONFIG_FTPD_VENDORID` โ€“ The vendor name to use in FTP communications. + Default: `NuttX`. +- `CONFIG_FTPD_SERVERID` โ€“ The server name to use in FTP communications. + Default: `NuttX FTP Server`. +- `CONFIG_FTPD_CMDBUFFERSIZE` โ€“ The maximum size of one command. Default: `512` + bytes. +- `CONFIG_FTPD_DATABUFFERSIZE` โ€“ The size of the I/O buffer for data transfers. + Default: `2048` bytes. +- `CONFIG_FTPD_WORKERSTACKSIZE` โ€“ The stacksize to allocate for each FTP daemon + worker thread. Default: `2048` bytes. + +The following netutils libraries should be enabled in your `defconfig` file: + +```conf +CONFIG_NETUTILS_NETLIB=y +CONFIG_NETUTILS_FTPD=y +``` + +## `gpio` GPIO Read and Write + +A simple `test/example` of the NuttX GPIO driver. + +## `hello` Hello World + +This is the mandatory, _Hello, World!!_ example. It is little more than +`examples/null` with a single `printf` statement. Really useful only for +bringing up new NuttX architectures. + +- `CONFIG_NSH_BUILTIN_APPS` โ€“ Build the _Hello, World_ example as an NSH + built-in application. + +## `helloxx` Hello World in C++ + +This is C++ version of the _Hello, World!!_ example. It is intended only to +verify that the C++ compiler is functional, that basic C++ library support is +available, and that class are instantiated correctly. + +NuttX configuration prerequisites: + +- `CONFIG_HAVE_CXX` โ€“ Enable C++ Support. + +Optional NuttX configuration settings: + +- `CONFIG_HAVE_CXXINITIALIZE` โ€“ Enable support for static constructors (may not + be available on all platforms). + +NuttX configuration settings specific to this example: + +- `CONFIG_NSH_BUILTIN_APPS` โ€“ Build the helloxx example as a _built-in_ that can + be executed from the NSH command line. + +Also needed: + +- `CONFIG_HAVE_CXX=y` + +And you may have to tinker with the following to get libxx to compile properly: + +- `CCONFIG_ARCH_SIZET_LONG=y` or `=n`. + +The argument of the `new` operators should take a type of `size_t`. But `size_t` +has an unknown underlying. In the nuttx `sys/types.h` header file, `size_t` is +typed as `uint32_t` (which is determined by architecture-specific logic). But +the C++ compiler may believe that `size_t` is of a different type resulting in +compilation errors in the operator. Using the underlying integer type Instead of +`size_t` seems to resolve the compilation issues. + +## `hidkbd` USB Host HID keyboard + +This is a simple test to `debug/verify` the USB host HID keyboard class driver. + +- `CONFIG_EXAMPLES_HIDKBD_DEFPRIO` โ€“ Priority of _waiter_ thread. Default: `50`. +- `CONFIG_EXAMPLES_HIDKBD_STACKSIZE` โ€“ Stacksize of _waiter_ thread. Default + `1024`. +- `CONFIG_EXAMPLES_HIDKBD_DEVNAME` โ€“ Name of keyboard device to be used. + Default: `/dev/kbda`. +- `CONFIG_EXAMPLES_HIDKBD_ENCODED` โ€“ Decode special key press events in the + user buffer. In this case, the example coded will use the interfaces defined + in `include/nuttx/input/kbd_codec.h` to decode the returned keyboard data. + These special keys include such things as up/down arrows, home and end keys, + etc. If this not defined, only 7-bit printable and control ASCII characters + will be provided to the user. Requires `CONFIG_HIDKBD_ENCODED` and + `CONFIG_LIBC_KBDCODEC`. + +## `igmp` Trivial IGMP + +This is a trivial test of the NuttX IGMP capability. It present it does not do +much of value โ€“ Much more is needed in order to verify the IGMP features! + +- `CONFIG_EXAMPLES_IGMP_NOMAC` โ€“ Set if the hardware has no MAC address; one + will be assigned. +- `CONFIG_EXAMPLES_IGMP_IPADDR` โ€“ Target board IP address. +- `CONFIG_EXAMPLES_IGMP_DRIPADDR` โ€“ Default router address. +- `CONFIG_EXAMPLES_IGMP_NETMASK` โ€“ Network mask. +- `CONFIG_EXAMPLES_IGMP_GRPADDR` โ€“ Multicast group address. +- `CONFIG_EXAMPLES_NETLIB` โ€“ The networking library is needed. + +## `i2cchar` Transfer Through I2C + +A mindlessly simple test of an I2C driver. It reads an write garbage data to the +I2C transmitter and/or received as fast possible. + +This test depends on these specific I2S/AUDIO/NSH configurations settings (your +specific I2S settings might require additional settings). + +- `CONFIG_I2S` โ€“ Enabled I2S support. +- `CONFIG_AUDIO` โ€“ Enabled audio support. +- `CONFIG_DRIVERS_AUDIO` โ€“ Enable audio device support. +- `CONFIG_AUDIO_I2SCHAR` โ€“ Enabled support for the I2S character device. +- `CONFIG_NSH_BUILTIN_APPS` โ€“ Build the I2S test as an NSH built-in function. + Default: Built as a standalone program. + +Specific configuration options for this example include: + +- `CONFIG_EXAMPLES_I2SCHAR` โ€“ Enables the I2C test. + +- `CONFIG_EXAMPLES_I2SCHAR_DEVPATH` โ€“ The default path to the ADC device. + Default: `/dev/i2schar0`. + +- `CONFIG_EXAMPLES_I2SCHAR_TX` โ€“ This should be set if the I2S device supports a + transmitter. + +- `CONFIG_EXAMPLES_I2SCHAR_TXBUFFERS` โ€“ This is the default number of audio + buffers to send before the TX transfers terminate. When both TX and RX + transfers terminate, the task exits (and, if an NSH builtin, the `i2schar` + command returns). This number can be changed from the NSH command line. + +- `CONFIG_EXAMPLES_I2SCHAR_TXSTACKSIZE` โ€“ This is the stack size to use when + starting the transmitter thread. Default `1536`. + +- `CONFIG_EXAMPLES_I2SCHAR_RX` โ€“ This should be set if the I2S device supports a + transmitter. + +- `CONFIG_EXAMPLES_I2SCHAR_RXBUFFERS` โ€“ This is the default number of audio + buffers to receive before the RX transfers terminate. When both TX and RX + transfers terminate, the task exits (and, if an NSH builtin, the `i2schar` + command returns). This number can be changed from the NSH command line. + +- `CONFIG_EXAMPLES_I2SCHAR_RXSTACKSIZE` โ€“ This is the stack size to use when + starting the receiver thread. Default `1536`. + +- `CONFIG_EXAMPLES_I2SCHAR_BUFSIZE` โ€“ The size of the data payload in one audio + buffer. Applies to both TX and RX audio buffers. + +- `CONFIG_EXAMPLES_I2SCHAR_DEVINIT` โ€“ Define if architecture-specific I2S device + initialize is available. If defined, the platform specific code must provide a + function `i2schar_devinit()` that will be called each time that this test + executes. Not available in the kernel build mode. + +## `ina219` Current/Power Monitor `INA219` + +This is a simple infinite loop that polls the `INA219` sensor and displays the +measurements. + +## `ipforward` IP Forwarding Using TUN + +A simple test of IP forwarding using TUN devices. This can be used on any +platform, but was intended for use on the simulation platform because it +performs a test of IP forwarding without the use of hardware. + +## `json` cJSON + +This example exercises the cJSON implementation at `apps/netutils/json`. This +example contains logic taken from the cJSON project: + +http://sourceforge.net/projects/cjson/ + +The example corresponds to SVN revision `r42` (with lots of changes for NuttX +coding standards). As of `r42`, the SVN repository was last updated on +`2011-10-10` so I presume that the code is stable and there is no risk of +maintaining duplicate logic in the NuttX repository. + +## `leds` Toggle LEDs + +This is a simple test of the board LED driver at +`nuttx/drivers/leds/userled_*.c`. + +## `lis2csh_reader` `LIS3DSH` Accelerometer + +A simple reader example for the `LIS3DSH` acceleration sensor as found on +STM32F4Discovery rev. C. + +## `hts221_reader` `HTS221` Humidity Sensor + +A simple reader example for the `HTS221` humidity sensor. + +## `lsm303_reader` `LSM303` Accelerometer/Magnetometer + +A simple reader example for the `LSM303` acc-mag sensor. + +## `lsm6dsl_reader` `LSM6DSL` Accelerometer/Gyroscope + +A simple reader example for the `LSM6DSL` acc-gyro sensor. + +## `media` + +The media test simply writes values onto the media hidden behind a character +driver and verifies that the media can be successfully written and read. This +low level test is useful in the early phases of the bringup of a new block or +mtd driver because it avoids the complexity of a file system. + +This test uses a character driver and cannot directly access block or mtd +drivers. This test is suitable for use EEPROM character drivers (see +`nuttx/drivers/eeprom`), or with block drivers wrapped as character drivers (see +`nuttx/drivers/bch`) + +```c +int ret = bchdev_register(<path-to-block-driver>, + <path-to-character-driver>, false); +``` + +MTD drivers need an additional wrapper layer, the FTL wrapper must first be used +to convert the MTD driver to a block device: + +```c +int ret = ftl_initialize(<N>, mtd); +ret = bchdev_register(/dev/mtdblock<N>, <path-to-character-driver>, + false); +``` + +## `module` Loadable Module + +This example builds a small loadable module test case. This includes a character +driver under `examples/module/drivers`. This driver is built using the +relocatable ELF format and installed in a ROMFS file system. At run time, the +driver module is loaded and exercised. Requires `CONFIG_MODULE`. Other +configuration options: + +- `CONFIG_EXAMPLES_ELF_DEVMINOR` โ€“ The minor device number of the ROMFS block + driver. For example, the `N` in `/dev/ramN`. Used for registering the RAM + block driver that will hold the ROMFS file system containing the ELF + executables to be tested. Default: `0`. + +- `CONFIG_EXAMPLES_ELF_DEVPATH` โ€“ The path to the ROMFS block driver device. + This must match `EXAMPLES_ELF_DEVMINOR`. Used for registering the RAM block + driver that will hold the ROMFS file system containing the ELF executables to + be tested. Default: `/dev/ram0`. + +**Notes**: + +1. `CFLAGS` should be provided in `CMODULEFLAGS`. RAM and FLASH memory regions + may require long allcs. For ARM, this might be: + + ```makefile + CMODULEFLAGS = $(CFLAGS) -mlong-calls + ``` + + Similarly for C++ flags which must be provided in `CXXMODULEFLAGS`. + +2. Your top-level `nuttx/Make.defs` file must also include an appropriate + definition, LDMODULEFLAGS, to generate a relocatable ELF object. With GNU LD, + this should include `-r` and `-e <entry point>`. + + ```makefile + LDMODULEFLAGS = -r -e module_initialize + ``` + + If you use GCC to link, you make also need to include `-nostdlib` or + `-nostartfiles` and `-nodefaultlibs`. + +3. This example also requires `genromfs`. `genromfs` can be build as part of the + nuttx toolchain. Or can built from the `genromfs` sources that can be found + in the NuttX tools repository (`genromfs-0.5.2.tar.gz`). In any event, the + PATH variable must include the path to the `genromfs` executable. + +4. ELF size: The ELF files in this example are, be default, quite large because + they include a lot of _build garbage_. You can greatly reduce the size of the + ELF binaries are using the `objcopy --strip-unneeded` command to remove + un-necessary information from the ELF files. + +5. Simulator. You cannot use this example with the NuttX simulator on Cygwin. + That is because the Cygwin GCC does not generate ELF file but rather some + Windows-native binary format. + + If you really want to do this, you can create a NuttX x86 `buildroot` + toolchain and use that be build the ELF executables for the ROMFS file + system. + +6. Linker scripts. You might also want to use a linker scripts to combine + sections better. An example linker script is at + `nuttx/libc/modlib/gnu-elf.ld`. That example might have to be tuned for your + particular linker output to position additional sections correctly. The GNU + LD `LDMODULEFLAGS` then might be: + + ```makefile + LDMODULEFLAGS = -r -e module_initialize -T$(TOPDIR)/libc/modlib/gnu-elf.ld + ``` + +## `modbus` FreeModbus + +This is a port of the FreeModbus Linux demo. It derives from the demos/LINUX +directory of the FreeModBus version `1.5.0` (June 6, 2010) that can be +downloaded in its entirety from +http://developer.berlios.de/project/showfiles.php?group_id=6120. + +- `CONFIG_EXAMPLES_MODBUS_PORT`, Default `0` (for `/dev/ttyS0`). +- `CONFIG_EXAMPLES_MODBUS_BAUD`, Default B`38400`. +- `CONFIG_EXAMPLES_MODBUS_PARITY`, Default `MB_PAR_EVEN`. +- `CONFIG_EXAMPLES_MODBUS_REG_INPUT_START`, Default `1000`. +- `CONFIG_EXAMPLES_MODBUS_REG_INPUT_NREGS`, Default `4`. +- `CONFIG_EXAMPLES_MODBUS_REG_HOLDING_START`, Default `2000`. +- `CONFIG_EXAMPLES_MODBUS_REG_HOLDING_NREGS`, Default `130`. + +The FreeModBus library resides at `apps/modbus`. See `apps/modbus/README.txt` +for additional configuration information. + +## `mount` Mount Filesystem + +This contains a simple test of filesystem mountpoints. + +- `CONFIG_EXAMPLES_MOUNT_DEVNAME` โ€“ The name of the user-provided block device + to mount. If `CONFIG_EXAMPLES_MOUNT_DEVNAME` is not provided, then a RAM disk + will be configured. + +- `CONFIG_EXAMPLES_MOUNT_NSECTORS` โ€“ The number of _sectors_ in the RAM disk + used when `CONFIG_EXAMPLES_MOUNT_DEVNAME` is not defined. + +- `CONFIG_EXAMPLES_MOUNT_SECTORSIZE` โ€“ The size of each sectors in the RAM disk + used when `CONFIG_EXAMPLES_MOUNT_DEVNAME` is not defined. + +- `CONFIG_EXAMPLES_MOUNT_RAMDEVNO` โ€“ The RAM device minor number used to mount + the RAM disk used when `CONFIG_EXAMPLES_MOUNT_DEVNAME` is not defined. The + default is zero (meaning that `/dev/ram0` will be used). + +## `mtdpart` MTD Partition Test + +This examples provides a simple test of MTD partition logic. + +- `CONFIG_EXAMPLES_MTDPART` โ€“ Enables the MTD partition test example. + +- `CONFIG_EXAMPLES_MTDPART_ARCHINIT` โ€“ The default is to use the RAM MTD device + at `drivers/mtd/rammtd.c`. But an architecture-specific MTD driver can be used + instead by defining `CONFIG_EXAMPLES_MTDPART_ARCHINIT`. In this case, the + initialization logic will call `mtdpart_archinitialize()` to obtain the MTD + driver instance. + +- `CONFIG_EXAMPLES_MTDPART_NPARTITIONS` โ€“ This setting provides the number of + partitions to test. The test will divide the reported size of the MTD device + into equal-sized sub-regions for each test partition. Default: `3`. + +When `CONFIG_EXAMPLES_MTDPART_ARCHINIT` is not defined, this test will use the +RAM MTD device at `drivers/mtd/rammtd.c` to simulate FLASH. The size of the +allocated RAM drive will be: `CONFIG_EXMPLES_RAMMTD_ERASESIZE * +CONFIG_EXAMPLES_MTDPART_NEBLOCKS`. + +* `CONFIG_EXAMPLES_MTDPART_ERASESIZE` โ€“ This value gives the size of one erase + block in the MTD RAM device. This must exactly match the default configuration + in `drivers/mtd/rammtd.c`! + +* `CONFIG_EXAMPLES_MTDPART_NEBLOCKS` โ€“ This value gives the number of erase + blocks in MTD RAM device. + +## `mtdrwb` MTD Read-ahead and Write Buffering + +This examples provides a simple test of MTD Read-Ahead/Write buffering logic. + +- `CONFIG_EXAMPLES_MTDRWB` โ€“ Enables the MTD R/W buffering test example. + +- `CONFIG_EXAMPLES_MTDRWB_ARCHINIT` โ€“ The default is to use the RAM MTD device + at `drivers/mtd/rammtd.c`. But an architecture-specific MTD driver can be used + instead by defining `CONFIG_EXAMPLES_MTDRWB_ARCHINIT`. In this case, the + initialization logic will call `mtdrwb_archinitialize()` to obtain the MTD + driver instance. + +When `CONFIG_EXAMPLES_MTDRWB_ARCHINIT` is not defined, this test will use the +RAM MTD device at `drivers/mtd/rammtd.c` to simulate FLASH. The size of the +allocated RAM drive will be: `CONFIG_EXMPLES_RAMMTD_ERASESIZE * +CONFIG_EXAMPLES_MTDRWB_NEBLOCKS` + +- `CONFIG_EXAMPLES_MTDRWB_ERASESIZE` โ€“ This value gives the size of one erase + block in the MTD RAM device. This must exactly match the default configuration + in `drivers/mtd/rammtd.c`! + +- `CONFIG_EXAMPLES_MTDRWB_NEBLOCKS` โ€“ This value gives the number of erase + blocks in MTD RAM device. + +## `netpkt` `AF_PACKET` _Raw_ Sockets + +A test of `AF_PACKET`, _raw_ sockets. Contributed by Lazlo Sitzer. + +## `netloop` Network loopback device + +This is a simple test of the netwok loopback device. `examples/nettest` can also +be configured to provide (better) test of local loopback transfers. This version +derives from `examples/poll` and is focused on testing `poll()` with loopback +devices. + +- `CONFIG_EXAMPLES_NETLOOP=y` โ€“ Enables the nettest example. + +Dependencies: + +- `CONFIG_NET_LOOPBACK` โ€“ Requires local loopback support. +- `CONFIG_NET_TCP` โ€“ Requires TCP support with the following: + - `CONFIG_NET_TCPBACKLOG` + - `CONFIG_NET_TCP_WRITE_BUFFERS` +- `CONFIG_NET_IPv4` โ€“ Currently supports only IPv4. + +## `nettest` Client/Server Over TCP + +This is a simple network test for verifying client- and server- functionality in +a TCP/IP connection. + +- `CONFIG_EXAMPLES_NETTEST=y` โ€“ Enables the nettest example. +- `CONFIG_EXAMPLES_NETLIB=y` โ€“ The networking library in needed. + +Configurations: + +- Server on target hardware; client on host. +- Client on target hardware; server on host. +- Server and Client on different targets. +- Loopback configuration with both client and server on the same target. + +See also `examples/tcpecho`. + +## `nrf24l01_term` NRF24L01 Wireless Connection + +These is a simple test of NRF24L01-based wireless connectivity. Enabled with: + +- `CONFIG_EXAMPLES_NRF24L01TERM` + +Options: + +- `CONFIG_NSH_BUILTIN_APPS` โ€“ Built as an NSH built-in applications. + +## `nx` + +This directory contains a simple test of a subset of the NX APIs defined in +`include/nuttx/nx/nx.h`. The following configuration options can be selected: + +- `CONFIG_NSH_BUILTIN_APPS` โ€“ Build the NX example as a _built-in_ that can be + executed from the NSH command line +- `CONFIG_EXAMPLES_NX_BGCOLOR` โ€“ The color of the background. Default depends on + `CONFIG_EXAMPLES_NX_BPP`. +- `CONFIG_EXAMPLES_NX_COLOR1` โ€“ The color of window 1. Default depends on + `CONFIG_EXAMPLES_NX_BPP`. +- `CONFIG_EXAMPLES_NX_COLOR2` โ€“ The color of window 2. Default depends on + `CONFIG_EXAMPLES_NX_BPP`. +- `CONFIG_EXAMPLES_NX_TBCOLOR` โ€“ The color of the toolbar. Default depends on + `CONFIG_EXAMPLES_NX_BPP`. +- `CONFIG_EXAMPLES_NX_FONTID` โ€“ Selects the font (see font ID numbers in + `include/nuttx/nx/nxfonts.h`). +- `CONFIG_EXAMPLES_NX_FONTCOLOR` โ€“ The color of the fonts. Default depends on + `CONFIG_EXAMPLES_NX_BPP`. +- `CONFIG_EXAMPLES_NX_BPP` โ€“ Pixels per pixel to use. Valid options include `2`, + `4`, `8`, `16`, `24` and `32`. Default is `32`. +- `CONFIG_EXAMPLES_NX_RAWWINDOWS` โ€“ Use raw windows; Default is to use pretty, + framed NXTK windows with toolbars. +- `CONFIG_EXAMPLES_NX_STACKSIZE` โ€“ The stacksize to use when creating the NX + server. Default `2048`. +- `CONFIG_EXAMPLES_NX_CLIENTPRIO` โ€“ The client priority. Default: `100` +- `CONFIG_EXAMPLES_NX_SERVERPRIO` โ€“ The server priority. Default: `120` +- `CONFIG_EXAMPLES_NX_LISTENERPRIO` โ€“ The priority of the event listener thread. + Default `80`. +- `CONFIG_EXAMPLES_NX_NOTIFYSIGNO` โ€“ The signal number to use with + `nx_eventnotify()`. Default: `4`. + +The example also has the following settings and will generate an error if they +are not as expected: + +```conf +CONFIG_DISABLE_MQUEUE=n +CONFIG_DISABLE_PTHREAD=n +CONFIG_NX_BLOCKING=y +CONFIG_BOARDCTL=y +``` + +## `nxterm` Display NuttShell (NSH) as NX Console + +This directory contains yet another version of the NuttShell (NSH). This version +uses the NX console device defined in `include/nuttx/nx/nxterm.h` for output. +the result is that the NSH input still come from the standard console input +(probably a serial console). But the text output will go to an NX winbdow. +Prerequisite configuration settings for this test include: + +- `CONFIG_NX=y` โ€“ NX graphics must be enabled +- `CONFIG_NXTERM=y` โ€“ The NX console driver must be built +- `CONFIG_DISABLE_MQUEUE=n` โ€“ Message queue support must be available. +- `CONFIG_DISABLE_PTHREAD=n` โ€“ pthreads are needed +- `CONFIG_NX_BLOCKING=y` โ€“ pthread APIs must be blocking +- `CONFIG_NSH_CONSOLE=y` โ€“ NSH must be configured to use a console. + +The following configuration options can be selected to customize the test: + +- `CONFIG_EXAMPLES_NXTERM_BGCOLOR` โ€“ The color of the background. Default + Default is a darker royal blue. +- `CONFIG_EXAMPLES_NXTERM_WCOLOR` โ€“ The color of the window. Default is a light + slate blue. +- `CONFIG_EXAMPLES_NXTERM_FONTID` โ€“ Selects the font (see font ID numbers in + `include/nuttx/nx/nxfonts.h`). +- `CONFIG_EXAMPLES_NXTERM_FONTCOLOR` โ€“ The color of the fonts. Default is black. +- `CONFIG_EXAMPLES_NXTERM_BPP` โ€“ Pixels per pixel to use. Valid options include + `2`, `4`, `8`, `16`, `24` and `32`. Default is `32`. +- `CONFIG_EXAMPLES_NXTERM_TOOLBAR_HEIGHT` โ€“ The height of the toolbar. Default: + `16`. +- `CONFIG_EXAMPLES_NXTERM_TBCOLOR` โ€“ The color of the toolbar. Default is a + medium grey. +- `CONFIG_EXAMPLES_NXTERM_MINOR` โ€“ The NX console device minor number. Default + is `0` corresponding to `/dev/nxterm0`. +- `CONFIG_EXAMPLES_NXTERM_DEVNAME` โ€“ The quoted, full path to the NX console + device corresponding to `CONFIG_EXAMPLES_NXTERM_MINOR`. Default: + `/dev/nxterm0`. +- `CONFIG_EXAMPLES_NXTERM_PRIO` โ€“ Priority of the NxTerm task. Default: + `SCHED_PRIORITY_DEFAULT`. +- `CONFIG_EXAMPLES_NXTERM_STACKSIZE` โ€“ Stack size allocated for the NxTerm task. + Default: `2048`. +- `CONFIG_EXAMPLES_NXTERM_STACKSIZE` โ€“ The stacksize to use when creating the NX + server. Default: `2048`. +- `CONFIG_EXAMPLES_NXTERM_CLIENTPRIO` โ€“ The client priority. Default: `100`. +- `CONFIG_EXAMPLES_NXTERM_SERVERPRIO` โ€“ The server priority. Default: `120`. +- `CONFIG_EXAMPLES_NXTERM_LISTENERPRIO` โ€“ The priority of the event listener + thread. Default: `80`. +- `CONFIG_EXAMPLES_NXTERM_NOTIFYSIGNO` โ€“ The signal number to use with + `nx_eventnotify()`. Default: `4`. + +## `nxflat` NXFLAT Binary + +This example builds a small NXFLAT test case. This includes several test +programs under `examples/nxflat` tests. These tests are build using the NXFLAT +format and installed in a ROMFS file system. At run time, each program in the +ROMFS file system is executed. Requires `CONFIG_NXFLAT`. + +## `nxhello` + +A very simple graphics example that just says _Hello, World!_ in the center of +the display. + +The following configuration options can be selected: + +- `CONFIG_NSH_BUILTIN_APPS` โ€“ Build the `NXHELLO` example as a _built-in_ that + can be executed from the NSH command line +- `CONFIG_EXAMPLES_NXHELLO_VPLANE` โ€“ The plane to select from the frame- buffer + driver for use in the test. Default: `0`. +- `CONFIG_EXAMPLES_NXHELLO_DEVNO` โ€“ The LCD device to select from the LCD driver + for use in the test. Default: `0`. +- `CONFIG_EXAMPLES_NXHELLO_BGCOLOR` โ€“ The color of the background. Default + depends on `CONFIG_EXAMPLES_NXHELLO_BPP`. +- `CONFIG_EXAMPLES_NXHELLO_FONTID` โ€“ Selects the font (see font ID numbers in + include/nuttx/nx/nxfonts.h). +- `CONFIG_EXAMPLES_NXHELLO_FONTCOLOR` โ€“ The color of the fonts used in the + background window. Default depends on `CONFIG_EXAMPLES_NXHELLO_BPP`. +- `CONFIG_EXAMPLES_NXHELLO_BPP` โ€“ Pixels per pixel to use. Valid options include + `2`, `4`, `8`, `16`, `24` and `32`. Default: `32`. + +## `nximage` Display NuttX Logo + +This is a simple example that just puts the NuttX logo image in the center of +the display. This only works for `RGB23` (`888`), `RGB16` (`656`), `RGB8` +(`332`), and 8-bit greyscale for now. + +- `CONFIG_NSH_BUILTIN_APPS` โ€“ Build the `NXIMAGE` example as a _built-in_ that + can be executed from the NSH command line. +- `CONFIG_EXAMPLES_NXIMAGE_VPLANE` โ€“ The plane to select from the frame- buffer + driver for use in the test. Default: `0`. +- `CONFIG_EXAMPLES_NXIMAGE_DEVNO` โ€“ The LCD device to select from the LCD driver + for use in the test: Default: `0`. +- `CONFIG_EXAMPLES_NXIMAGE_BPP` โ€“ Pixels per pixel to use. Valid options include + `8`, `16` and `24`. Default is `16`. +- `CONFIG_EXAMPLES_NXIMAGE_XSCALEp5`, `CONFIG_EXAMPLES_NXIMAGE_XSCALE1p5` or + `CONFIG_EXAMPLES_NXIMAGE_XSCALE2p0` โ€“ The logo image width is 160 columns. One + of these may be defined to rescale the image horizontally by .5, 1.5 or 2.0. +- `CONFIG_EXAMPLES_NXIMAGE_YSCALEp5`, `CONFIG_EXAMPLES_NXIMAGE_YSCALE1p5` or + `CONFIG_EXAMPLES_NXIMAGE_YSCALE2p0` โ€“ The logo image height is 160 rows. One + of these may be defined to rescale the image vertically by .5, 1.5 or 2.0. +- `CONFIG_EXAMPLES_NXIMAGE_GREYSCALE` โ€“ Grey scale image. Default: `RGB`. + +How was that run-length encoded image produced? + +1. I used GIMP output the image as a `.c` file. +2. I added some C logic to palette-ize the RGB image in the GIMP `.c` file. +3. Then I add some simple run-length encoding to palette-ized image. + +But now there is a tool that can be found in the NxWidgets package at +`NxWidgets/tools/bitmap_converter.py` that can be used to convert any graphics +format to the NuttX RLE format. + +**Note**: As of this writing, most of the pixel depth, scaling options, and +combinations thereof have not been tested. + +## `nxlines` NX Line Drawing + +A very simple graphics example that just exercised the NX line drawing logic. + +The following configuration options can be selected: + +- `CONFIG_EXAMPLES_NXLINES_VPLANE` โ€“ The plane to select from the frame- buffer + driver for use in the test. Default: `0`. +- `CONFIG_EXAMPLES_NXLINES_DEVNO` โ€“ The LCD device to select from the LCD driver + for use in the test: Default: `0`. +- `CONFIG_EXAMPLES_NXLINES_BGCOLOR` โ€“ The color of the background. Default + depends on `CONFIG_EXAMPLES_NXLINES_BPP`. +- `CONFIG_EXAMPLES_NXLINES_LINEWIDTH` โ€“ Selects the width of the lines in pixels + (default: `16`). +- `CONFIG_EXAMPLES_NXLINES_LINECOLOR` โ€“ The color of the central lines drawn in + the background window. Default depends on `CONFIG_EXAMPLES_NXLINES_BPP` (there + really is no meaningful default). +- `CONFIG_EXAMPLES_NXLINES_BORDERWIDTH` โ€“ The width of the circular border drawn + in the background window. (default: `16`). +- `CONFIG_EXAMPLES_NXLINES_BORDERCOLOR` โ€“ The color of the circular border drawn + in the background window. Default depends on `CONFIG_EXAMPLES_NXLINES_BPP` + (there really is no meaningful default). +- `CONFIG_EXAMPLES_NXLINES_CIRCLECOLOR` โ€“ The color of the circular region + filled in the background window. Default depends on + `CONFIG_EXAMPLES_NXLINES_BPP` (there really is no meaningful default). +- `CONFIG_EXAMPLES_NXLINES_BORDERCOLOR` โ€“ The color of the lines drawn in the + background window. Default depends on `CONFIG_EXAMPLES_NXLINES_BPP` (there + really is no meaningful default). +- `CONFIG_EXAMPLES_NXLINES_BPP` โ€“ Pixels per pixel to use. Valid options include + `2`, `4`, `8`, `16`, `24`, and `32`. Default is `16`. +- `CONFIG_NSH_BUILTIN_APPS` โ€“ Build the NX lines examples as an NSH built-in + function. + +## `nxtext` Display NX Text + +This directory contains another simple test of a subset of the NX APIs defined +in `include/nuttx/nx/nx.h`. This text focuses on text displays on the display +background combined with pop-up displays over the text. The text display will +continue to update while the pop-up is visible. + +**Note**: This example will **only** work with FB drivers and with LCD drivers +that support reading the contents of the internal LCD memory **unless** you +define `CONFIG_EXAMPLES_NXTEXT_NOGETRUN`. If you notice garbage on the display +or a failure at the point where the display should scroll, it is probably +because you have an LCD driver that is write-only. + +The following configuration options can be selected: + +- `CONFIG_NSH_BUILTIN_APPS` โ€“ Build the `NXTEXT` example as a _built-in_ that + can be executed from the NSH command line. +- `CONFIG_EXAMPLES_NXTEXT_BGCOLOR` โ€“ The color of the background. Default + depends on `CONFIG_EXAMPLES_NXTEXT_BPP`. +- `CONFIG_EXAMPLES_NXTEXT_BGFONTID` โ€“ Selects the font to use in the background + text (see font ID numbers in `include/nuttx/nx/nxfonts.h`). +- `CONFIG_EXAMPLES_NXTEXT_BGFONTCOLOR` โ€“ The color of the fonts used in the + background window. Default depends on `CONFIG_EXAMPLES_NXTEXT_BPP`. +- `CONFIG_EXAMPLES_NXTEXT_PUCOLOR` โ€“ The color of the pop-up window. Default + depends on `CONFIG_EXAMPLES_NXTEXT_BPP`. +- `CONFIG_EXAMPLES_NXTEXT_PUFONTID` โ€“ Selects the font to use in the pop-up + windows (see font ID numbers in `include/nuttx/nx/nxfonts.h`). +- `CONFIG_EXAMPLES_NXTEXT_PUFONTCOLOR` โ€“ The color of the fonts used in the + background window. Default depends on `CONFIG_EXAMPLES_NXTEXT_BPP`. +- `CONFIG_EXAMPLES_NXTEXT_BPP` โ€“ Pixels per pixel to use. Valid options include + `2`, `4`, `8`, `16`, `24` and `32`. Default is `32`. +- `CONFIG_EXAMPLES_NXTEXT_NOGETRUN` โ€“ If your display is read-only OR if reading + is not reliable, then select this configuration to avoid reading from the + display. +- `CONFIG_EXAMPLES_NXTEXT_BMCACHE` โ€“ The maximum number of characters that can + be put in the background window. Default is `128`. +- `CONFIG_EXAMPLES_NXTEXT_GLCACHE` โ€“ The maximum number of pre-rendered fonts + that can be retained for the background window. +- `CONFIG_EXAMPLES_NXTEXT_STACKSIZE` โ€“ The stacksize to use when creating the NX + server. Default `2048`. +- `CONFIG_EXAMPLES_NXTEXT_CLIENTPRIO` โ€“ The client priority. Default: `100`. +- `CONFIG_EXAMPLES_NXTEXT_SERVERPRIO` โ€“ The server priority. Default: `120`. +- `CONFIG_EXAMPLES_NXTEXT_LISTENERPRIO` โ€“ The priority of the event listener + thread. Default: `80`. +- `CONFIG_EXAMPLES_NXTEXT_NOTIFYSIGNO` โ€“ The signal number to use with + `nx_eventnotify()`. Default: `4`. + +The example also expects the following settings and will generate an error if +they are not as expected: + +```conf +CONFIG_DISABLE_MQUEUE=n +CONFIG_DISABLE_PTHREAD=n +CONFIG_NX_BLOCKING=y +``` + +## `null` + +This is the do nothing application. It is only used for bringing up new NuttX +architectures in the most minimal of environments. + +## `obd2` + +A simple test of `apps/canutils/libobd2`. + +## `oneshot` Oneshot Timer + +Simple test of a oneshot driver. + +## `pca9635` `PCA9635PW` LED + +A simple test of the `PCA9635PW` LED driver. + +## `pdcurses` + +This directory contains the `demo/test` programs that accompany the public +domain cursors package (`pdcurses`) that can be found at +`apps/graphics/pdcurs34`. + +## `pipe` + +A test of the `mkfifo()` and `pipe()` APIs. Requires `CONFIG_PIPES` + +- `CONFIG_EXAMPLES_PIPE_STACKSIZE` โ€“ Sets the size of the stack to use when + creating the child tasks. The default size is `1024`. + +## `poll` + +A test of the `poll()` and `select()` APIs using FIFOs and, if available, +`stdin`, and a TCP/IP socket. In order to use the TCP/IP select test, you must +have the following things selected in your NuttX configuration file: + +- `CONFIG_NET` โ€“ Defined for general network support. +- `CONFIG_NET_TCP` โ€“ Defined for TCP/IP support. +- `CONFIG_NET_NTCP_READAHEAD_BUFFERS` โ€“ Defined to be greater than zero. +- `CONFIG_EXAMPLES_POLL_NOMAC` โ€“ (May be defined to use software assigned + MAC) +- `CONFIG_EXAMPLES_POLL_IPADDR` โ€“ Target IP address. +- `CONFIG_EXAMPLES_POLL_DRIPADDR` โ€“ Default router IP address. +- `CONFIG_EXAMPLES_POLL_NETMASK` โ€“ Network mask. + +In order to for select to work with incoming connections, you must also select: + +- `CONFIG_NET_TCPBACKLOG` โ€“ Incoming connections pend in a backlog until + `accept()` is called. + +In additional to the target device-side example, there is also a host-side +application in this directory. It can be compiled under Linux or Cygwin as +follows: + +```makefile +cd examples/usbserial +make -f Makefile.host TOPDIR=<nuttx-directory> TARGETIP=<target-ip> +``` + +Where `<target-ip>` is the IP address of your target board. + +This will generate a small program called 'host'. Usage: + +1. Build the `examples/poll` target program with TCP/IP poll support and start + the target. + +2. Then start the host application: + + ```bash + ./host + ``` + +The host and target will exchange are variety of small messages. Each message +sent from the host should cause the select to return in target. The target +example should read the small message and send it back to the host. The host +should then receive the echo'ed message. + +If networking is enabled, applications using this example will need to provide +the following definition in the `defconfig` file to enable the networking +library: + +- `CONFIG_NETUTILS_NETLIB=y` + +## `posix_spawn` + +This is a simple test of the `posix_spawn()` API. The example derives from +`examples/elf`. As a result, these tests are built using the relocatable ELF +format installed in a ROMFS file system. At run time, the test program in the +ROMFS file system is spawned using `posix_spawn()`. + +Requires: + +- `CONFIG_BINFMT_DISABLE=n` โ€“ Don't disable the binary loader. +- `CONFIG_ELF=y` โ€“ Enable ELF binary loader. +- `CONFIG_LIBC_EXECFUNCS=y` โ€“ Enable support for posix_spawn. +- `CONFIG_EXECFUNCS_SYMTAB_ARRAY="g_spawn_exports"` โ€“ The name of the symbol + table created by the test. +- `CONFIG_EXECFUNCS_NSYMBOLS_VAR="g_spawn_nexports"` โ€“ Name of variable holding + the number of symbols. +- `CONFIG_POSIX_SPAWN_STACKSIZE=768` โ€“ This default setting. + +Test-specific configuration options: + +- `CONFIG_EXAMPLES_POSIXSPAWN_DEVMINOR` โ€“ The minor device number of the ROMFS + block. driver. For example, the `N` in `/dev/ramN`. Used for registering the + RAM block driver that will hold the ROMFS file system containing the ELF + executables to be tested. Default: `0`. + +- `CONFIG_EXAMPLES_POSIXSPAWN_DEVPATH` โ€“ The path to the ROMFS block driver + device. This must match `EXAMPLES_POSIXSPAWN_DEVMINOR`. Used for registering + the RAM block driver that will hold the ROMFS file system containing the ELF + executables to be tested. Default: `/dev/ram0`. + +**Notes**: + +1. `CFLAGS` should be provided in `CELFFLAGS`. RAM and FLASH memory regions may + require long allcs. For ARM, this might be: + + ```makefile + CELFFLAGS = $(CFLAGS) -mlong-calls + ``` + + Similarly for C++ flags which must be provided in `CXXELFFLAGS`. + +2. Your top-level `nuttx/Make.defs` file must also include an appropriate + definition, `LDELFFLAGS`, to generate a relocatable ELF object. With GNU LD, + this should include `-r` and `-e main` (or `_main` on some platforms). + + ```makefile + LDELFFLAGS = -r -e main + ``` + + If you use GCC to link, you make also need to include `-nostdlib` or + `-nostartfiles` and `-nodefaultlibs`. + +3. This example also requires `genromfs`. `genromfs` can be build as part of the + nuttx toolchain. Or can built from the `genromfs` sources that can be found + in the NuttX tools repository (`genromfs-0.5.2.tar.gz`). In any event, the + `PATH` variable must include the path to the `genromfs` executable. + +4. ELF size: The ELF files in this example are, be default, quite large because + they include a lot of _build garbage_. You can greatly reduce the size of the + ELF binaries are using the `objcopy --strip-unneeded` command to remove + un-necessary information from the ELF files. + +5. Simulator. You cannot use this example with the NuttX simulator on Cygwin. + That is because the Cygwin GCC does not generate ELF file but rather some + Windows-native binary format. + + If you really want to do this, you can create a NuttX x86 buildroot toolchain + and use that be build the ELF executables for the ROMFS file system. + +6. Linker scripts. You might also want to use a linker scripts to combine + sections better. An example linker script is at + `nuttx/binfmt/libelf/gnu-elf.ld`. That example might have to be tuned for + your particular linker output to position additional sections correctly. The + GNU LD `LDELFFLAGS` then might be: + + ```makefile + LDELFFLAGS = -r -e main -T$(TOPDIR)/binfmt/libelf/gnu-elf.ld + ``` + +## `powerled` + +This is a powerled driver example application. This application support three +operation modes which can be selected from NSH command line: + +1. Demo mode. +2. Continuous mode. +3. Flash mode. + +## `pty_test` Pseudo-Terminals + +A test of NuttX pseudo-terminals. Provided by Alan Carvalho de Assis. + +## `pwfb` + +A graphics example using pre-window frame buffers. The example shows three +windows containing text moving around, crossing each other from _above_ and from +_below_. The example application is NOT updating the windows any anyway! The +application is only changing the window position. The windows are being updated +from the per-winidow framebuffers automatically. + +This example is reminiscent of Pong: Each window travels in straight line until +it hits an edge, then it bounces off. The window is also raised when it hits the +edge (gets _focus_). This tests all combinations of overap. + +**Note**: A significant amount of RAM, usually external SDRAM, is required to +run this demo. At 16bpp and a 480x272 display, each window requires about 70Kb +of RAM for its framebuffer. + +## `pwm` General PWM + +A test of a PWM device driver. It simply enables a pulsed output for a specified +frequency and duty for a specified period of time. This example can ONLY be +built as an NSH built-in function. + +This test depends on these specific PWM/NSH configurations settings (your +specific PWM settings might require additional settings). + +- `CONFIG_PWM` โ€“ Enables PWM support. +- `CONFIG_PWM_PULSECOUNT` โ€“ Enables PWM pulse count support (if the hardware + supports it). +- `CONFIG_NSH_BUILTIN_APPS` โ€“ Build the PWM test as an NSH built-in function. + +Specific configuration options for this example include: + +- `CONFIG_EXAMPLES_PWM_DEVPATH` โ€“ The path to the default PWM device. Default: + `/dev/pwm0`. +- `CONFIG_EXAMPLES_PWM_FREQUENCY` โ€“ The initial PWM frequency. Default: `100` Hz +- `CONFIG_EXAMPLES_PWM_DUTYPCT` โ€“ The initial PWM duty as a percentage. Default: + `50`%. +- `CONFIG_EXAMPLES_PWM_DURATION` โ€“ The initial PWM pulse train duration in + seconds. Used only if the current pulse count is zero (pulse count is only + supported if `CONFIG_PWM_PULSECOUNT` is defined). Default: `5` seconds. +- `CONFIG_EXAMPLES_PWM_PULSECOUNT` โ€“ The initial PWM pulse count. This option is + only available if `CONFIG_PWM_PULSECOUNT` is non-zero. Default: `0` (i.e., use + the duration, not the count). + +## `qencoder` Quadrature Encoder + +This example is a simple test of a Quadrature Encoder driver. It simply reads +positional data from the encoder and prints it., + +This test depends on these specific QE/NSH configurations settings (your +specific PWM settings might require additional settings). + +- `CONFIG_SENSORS_QENCODER` โ€“ Enables quadrature encoder support (upper-half + driver). +- `CONFIG_NSH_BUILTIN_APPS` โ€“ Build the QE test as an NSH built-in function. + Default: Built as a standalone program. + +Additional configuration options will mostly likely be required for the board- +specific lower-half driver. See the `README.txt` file in your board +configuration directory. + +Specific configuration options for this example include: + +- `CONFIG_EXAMPLES_QENCODER_DEVPATH` โ€“ The path to the QE device. Default: + `/dev/qe0`. +- `CONFIG_EXAMPLES_QENCODER_NSAMPLES` โ€“ This number of samples is collected and + the program terminates. Default: Samples are collected indefinitely. +- `CONFIG_EXAMPLES_QENCODER_DELAY` โ€“ This value provides the delay (in + milliseconds) between each sample. Default: `100` milliseconds. + +## `random` Random Numbers + +This is a very simply test of `/dev/random`. It simple collects random numbers +and displays them on the console. + +Prerequistes: + +- `CONFIG_DEV_RANDOM` โ€“ Support for `/dev/random` must be enabled in order to + select this example. + +Configuration: + +- `CONFIG_EXAMPLES_RANDOM` โ€“ Enables the `/dev/random` test. +- `CONFIG_EXAMPLES_MAXSAMPLES` โ€“ This is the size of the `/dev/random` I/O + buffer in units of 32-bit samples. Careful! This buffer is allocated on the + stack as needed! Default `64`. +- `CONFIG_EXAMPLES_NSAMPLES` โ€“ When you execute the `rand` command, a number of + samples ranging from `1` to `EXAMPLES_MAXSAMPLES` may be specified. If no + argument is specified, this is the default number of samples that will be + collected and displayed. Default `8`. + +## `relays` Relays + +Requires `CONFIG_ARCH_RELAYS`. Contributed by Darcy Gong. + +**Note**: This test exercises internal relay driver interfaces. As such, it +relies on internal OS interfaces that are not normally available to a user-space +program. As a result, this example cannot be used if a NuttX is built as a +protected, supervisor kernel (`CONFIG_BUILD_PROTECTED` or +`CONFIG_BUILD_KERNEL`). + +## `rfid_readuid` RFID + +RFID `READUID` example. + +## `rgbled` RGB LED Using PWM + +This example demonstrates the use of the RGB led driver to drive an RGB LED with +PWM outputs so that all color characteristcs of RGB LED can be controlled. + +## `romfs` File System + +This example exercises the romfs filesystem. Configuration options include: + +- `CONFIG_EXAMPLES_ROMFS_RAMDEVNO` โ€“ The minor device number to use for the ROM + disk. The default is `1` (meaning `/dev/ram1`). +- `CONFIG_EXAMPLES_ROMFS_SECTORSIZE` โ€“ The ROM disk sector size to use. Default + is `64`. +- `CONFIG_EXAMPLES_ROMFS_MOUNTPOINT` โ€“ The location to mount the ROM disk. + Default: `/usr/local/share`. + +## `sendmail` SMTP Client + +This examples exercises the uIP SMTP logic by sending a test message to a +selected recipient. This test can also be built to execute on the Cygwin/Linux +host environment: + +```bash +cd examples/sendmail +make -f Makefile.host TOPDIR=<nuttx-directory> +``` + +Settings unique to this example include: + +- `CONFIG_EXAMPLES_SENDMAIL_NOMAC` โ€“ May be defined to use software assigned + MAC (optional) +- `CONFIG_EXAMPLES_SENDMAIL_IPADDR` โ€“ Target IP address (required) +- `CONFIG_EXAMPLES_SENDMAIL_DRIPADDR` โ€“ Default router IP address (required) +- `CONFIG_EXAMPLES_SENDMAILT_NETMASK` โ€“ Network mask (required) +- `CONFIG_EXAMPLES_SENDMAIL_RECIPIENT` โ€“ The recipient of the email (required) +- `CONFIG_EXAMPLES_SENDMAIL_SENDER` โ€“ Optional. Default: + `nuttx-testing@example.com` +- `CONFIG_EXAMPLES_SENDMAIL_SUBJECT` โ€“ Optional. Default: `Testing SMTP from + NuttX` +- `CONFIG_EXAMPLES_SENDMAIL_BODY` โ€“ Optional. Default: `Test message sent + by NuttX` + +**Note 1**: This test has not been verified on the NuttX target environment. As +of this writing, unit-tested in the Cygwin/Linux host environment. + +**Note 2**: This sendmail example only works for the simplest of environments. +Virus protection software on your host may have to be disabled to allow you to +send messages. Only very open, unprotected recipients can be used. Most will +protect themselves from this test email because it looks like SPAM. + +Applications using this example will need to enable the following netutils +libraries in their defconfig file: + +```conf +CONFIG_NETUTILS_NETLIB=y +CONFIG_NETUTILS_SMTP=y +``` + +## `serialblaster` + +Sends a repeating pattern (the alphabet) out a serial port continuously. This +may be useful if you are trying run down other problems that you think might +only occur when the serial port usage is high. + +## `serialrx` + +Constant receives serial data. This is the complement to `serialblaster`. This +may be useful if you are trying run down other problems that you think might +only occur when the serial port usage is high. + +## `serloop` Serial Loopback + +This is a mindlessly simple loopback test on the console. Useful for testing new +serial drivers. Configuration options include: + +- `CONFIG_EXAMPLES_SERLOOP_BUFIO` โ€“ Use C buffered I/O (`getchar`/`putchar`) vs. + raw console I/O (read/read). + +## `slcd` Alphanumeric Segment LCD + +A simple test of alphanumeric, segment LCDs (SLCDs). + +- `CONFIG_EXAMPLES_SLCD` โ€“ Enable the SLCD test + +## `smps` Switched-Mode Power Supply + +This is a SMPS (Switched-mode power supply) driver example application. + +## `sotest` Shared Library Module Test + +This example builds a small shared library module test case. The test shared +library is built using the relocatable ELF format and installed in a ROMFS file +system. At run time, the shared library is installed and exercised. Requires +`CONFIG_LIBC_DLFCN`. Other configuration options: + +- `CONFIG_EXAMPLES_SOTEST_DEVMINOR` โ€“ The minor device number of the ROMFS block + driver. For example, the `N` in `/dev/ramN`. Used for registering the RAM + block driver that will hold the ROMFS file system containing the ELF + executables to be tested. Default: `0`. + +- `CONFIG_EXAMPLES_SOTEST_DEVPATH` โ€“ The path to the ROMFS block driver device. + This must match `EXAMPLES_ELF_DEVMINOR`. Used for registering the RAM block + driver that will hold the ROMFS file system containing the ELF executables to + be tested. Default: `/dev/ram0`. + +**Notes**: + +1. `CFLAGS` should be provided in `CMODULEFLAGS`. RAM and FLASH memory regions + may require long allcs. For ARM, this might be: + + ```makefile + CMODULEFLAGS = $(CFLAGS) -mlong-calls + ``` + + Similarly for C++ flags which must be provided in `CXXMODULEFLAGS`. + +2. Your top-level `nuttx/Make.defs` file must also include an appropriate + definition, `LDMODULEFLAGS`, to generate a relocatable ELF object. With GNU + LD, this should include `-r` and `-e <entry point>`. + + ```makefile + LDMODULEFLAGS = -r -e module_initialize + ``` + + If you use GCC to link, you make also need to include `-nostdlib` or + `-nostartfiles` and `-nodefaultlibs`. + +3. This example also requires `genromfs`. `genromfs` can be build as part of the + nuttx toolchain. Or can built from the `genromfs` sources that can be found + in the NuttX tools repository (`genromfs-0.5.2.tar.gz`). In any event, the + `PATH` variable must include the path to the `genromfs` executable. + +4. ELF size: The ELF files in this example are, be default, quite large because + they include a lot of _build garbage_. You can greatly reduce the size of the + ELF binaries are using the `objcopy --strip-unneeded` command to remove + un-necessary information from the ELF files. + +5. Simulator. You cannot use this example with the NuttX simulator on Cygwin. + That is because the Cygwin GCC does not generate ELF file but rather some + Windows-native binary format. + + If you really want to do this, you can create a NuttX x86 buildroot toolchain + and use that be build the ELF executables for the ROMFS file system. + +6. Linker scripts. You might also want to use a linker scripts to combine + sections better. An example linker script is at + `nuttx/libc/modlib/gnu-elf.ld`. That example might have to be tuned for your + particular linker output to position additional sections correctly. The GNU + LD `LDMODULEFLAGS` then might be: + +```makefile +LDMODULEFLAGS = -r -e module_initialize -T$(TOPDIR)/libc/modlib/gnu-elf.ld +``` + +## `stat` + +A simple test of `stat()`, `fstat()`, and `statfs()`. This is useful primarily +for bringing up a new file system and verifying the correctness of these +operations. + +## `sx127x_demo` `SX127X` Radio + +This example demonstrates the use of the `SX127X` radio. + +## `system` + +This is a simple test of the `system()` command. The test simply executes this +`system` command: + +```c +ret = system("ls -Rl /"); +``` + +## `tcpblaster` TCP Performance Test + +The `tcpblaster` example derives from the `nettest` example and basically +duplicates that example when the `nettest` PERFORMANCE option is selected. +`tcpblaster` has a little better reporting of performance stats, however. + +## `tcpecho` TCP Echo Server + +Simple single threaded, poll based TCP echo server. This example implements the +TCP Echo Server from W. Richard Stevens _UNIX Network Programming_ Book. +Contributed by Max Holtberg. + +See also `examples/nettest` + +- `CONFIG_EXAMPLES_TCPECHO=y` โ€“ Enables the TCP echo server. +- `CONFIG_XAMPLES_TCPECHO_PORT` โ€“ Server Port, default `80`. +- `CONFIG_EXAMPLES_TCPECHO_BACKLOG` โ€“ Listen Backlog, default `8`. +- `CONFIG_EXAMPLES_TCPECHO_NCONN` โ€“ Number of Connections, default `8`. +- `CONFIG_EXAMPLES_TCPECHO_DHCPC` โ€“ DHCP Client, default `n`. +- `CONFIG_EXAMPLES_TCPECHO_NOMAC` โ€“ Use Canned MAC Address, default `n`. +- `CONFIG_EXAMPLES_TCPECHO_IPADDR` โ€“ Target IP address, default `0x0a000002`. +- `CONFIG_EXAMPLES_TCPECHO_DRIPADDR` โ€“ Default Router IP address (Gateway), + default `0x0a000001`. +- `CONFIG_EXAMPLES_TCPECHO_NETMASK` โ€“ Network Mask, default `0xffffff00`. + +## `telnetd` Simple Telnet Shell + +This directory contains a functional port of the tiny uIP shell. In the NuttX +environment, the NuttShell (at `apps/nshlib`) supersedes this tiny shell and +also supports `telnetd`. + +- `CONFIG_EXAMPLES_TELNETD` โ€“ Enable the Telnetd example. +- `CONFIG_NETUTILS_NETLIB`, `CONFIG_NETUTILS_TELNETD` โ€“ Enable netutils libraries + needed by the Telnetd example. +- `CONFIG_EXAMPLES_TELNETD_DAEMONPRIO` โ€“ Priority of the Telnet daemon. Default: + `SCHED_PRIORITY_DEFAULT`. +- `CONFIG_EXAMPLES_TELNETD_DAEMONSTACKSIZE` โ€“ Stack size allocated for the + Telnet daemon. Default: `2048`. +- `CONFIG_EXAMPLES_TELNETD_CLIENTPRIO` โ€“ Priority of the Telnet client. Default: + `SCHED_PRIORITY_DEFAULT`. +- `CONFIG_EXAMPLES_TELNETD_CLIENTSTACKSIZE` โ€“ Stack size allocated for the + Telnet client. Default: `2048`. +- `CONFIG_EXAMPLES_TELNETD_NOMAC` โ€“ If the hardware has no MAC address of its + own, define this `=y` to provide a bogus address for testing. +- `CONFIG_EXAMPLES_TELNETD_IPADDR` โ€“ The target IP address. Default `10.0.0.2`. +- `CONFIG_EXAMPLES_TELNETD_DRIPADDR` โ€“ The default router address. Default + `10.0.0.1`. +- `CONFIG_EXAMPLES_TELNETD_NETMASK` โ€“ The network mask. Default: + `255.255.255.0`. + +Also, make sure that you have the following set in the NuttX configuration file +or else the performance will be very bad (because there will be only one +character per TCP transfer): + +- `CONFIG_STDIO_BUFFER_SIZE` โ€“ Some value `>= 64` +- `CONFIG_STDIO_LINEBUFFER=y` + +## `termios` Simple Termios interface test + +This directory contains a simple application that uses the termios interface +to change serial parameters. Just import a `nsh` config and enable the +following symbols: + +- `CONFIG_SERIAL_TERMIOS` โ€“ Enable the termios support. +- `CONFIG_EXAMPLES_TERMIOS` โ€“ Enable the example itself. + +## `thttpd` THTTPD server + +An example that builds `netutils/thttpd` with some simple NXFLAT CGI programs. +See `boards/README.txt` for most THTTPD settings. In addition to those, this +example accepts: + +- `CONFIG_EXAMPLES_THTTPD_NOMAC` โ€“ (May be defined to use software assigned + MAC) +- `CONFIG_EXAMPLES_THTTPD_DRIPADDR` โ€“ Default router IP address. +- `CONFIG_EXAMPLES_THTTPD_NETMASK` โ€“ Network mask. + +Applications using this example will need to enable the following `netutils` +libraries in the `defconfig` file: + +```conf +CONFIG_NETUTILS_NETLIB=y +CONFIG_NETUTILS_THTTPD=y +``` + +## `tiff` + +This is a simple unit test for the TIFF creation library at `apps/graphic/tiff`. +It is configured to work in the Linux user-mode simulation and has not been +tested in any other environment. + +At a minimum, to run in an embedded environment, you will probably have to +change the configured paths to the TIFF files defined in the example. + +- `CONFIG_EXAMPLES_TIFF_OUTFILE` โ€“ Name of the resulting TIFF file. Default is + `/tmp/result.tif`. +- `CONFIG_EXAMPLES_TIFF_TMPFILE1/2` โ€“ Names of two temporaries files that will + be used in the file creation. Defaults are `/tmp/tmpfile1.dat` and + `/tmp/tmpfile2.dat`. + +The following must also be defined in your `apps/` configuration file: + +```conf +CONFIG_EXAMPLES_TIFF=y +CONFIG_GRAPHICS_TIFF=y +``` + +## `timer` + +This is a simple test of the timer driver (see `include/nuttx/timers/timer.h`). + +Dependencies: + +- `CONFIG_TIMER` โ€“ The timer driver must be selected + +Example configuration: + +- `CONFIG_EXAMPLES_TIMER_DEVNAME` โ€“ This is the name of the timer device that + will be tested. Default: `/dev/timer0`. +- `CONFIG_EXAMPLES_TIMER_INTERVAL` โ€“ This is the timer interval in microseconds. + Default: `1000000`. +- `CONFIG_EXAMPLES_TIMER_DELAY` โ€“ This is the delay between timer samples in + microseconds. Default: `10000`. +- `CONFIG_EXAMPLES_TIMER_STACKSIZE` โ€“ This is the stack size allocated when the + timer task runs. Default: `2048`. +- `CONFIG_EXAMPLES_TIMER_PRIORITY` โ€“ This is the priority of the timer task: + Default: `100`. +- `CONFIG_EXAMPLES_TIMER_PROGNAME` โ€“ This is the name of the program that will + be used when the NSH ELF program is installed. Default: `timer`. + +## `timer_gpio` + +This example uses the timer interrupt to periodically change the state of a +digital output. The digital output may be a relay, a led or anything else. +This example can be very useful to validate timer drivers by using a logic +analyzer connected to the digital output. This example mainly differs from +the timer example because it waits on a sigwaitinfo() instead of using a +signal handler. This approach ensures a deterministic wake-up time when the +signal occurs. + +Dependencies: + +- `CONFIG_TIMER` โ€“ The timer driver must be selected. +- `CONFIG_DEV_GPIO` โ€“ The GPIO driver must be selected. + +Note: You should also select one timer instance and have the gpio driver +properly configured in your board logic. + +Example configuration: + +- `EXAMPLES_TIMER_GPIO_TIM_DEVNAME` โ€“ This is the name of the timer device + that will be used. + Default: `/dev/timer0`. +- `EXAMPLES_TIMER_GPIO_GPIO_DEVNAME` โ€“ This is the name of the gpio device + that will be used. + Default: `/dev/gpio0`. +- `EXAMPLES_TIMER_GPIO_INTERVAL` โ€“ This is the timer interval in + microseconds. + Default: `1000000`. +- `EXAMPLES_TIMER_GPIO_SIGNO` โ€“ This is the signal number that is used to + notify that a timer interrupt occurred. + Default: `17`. +- `EXAMPLES_TIMER_GPIO_STACKSIZE` โ€“ This is the stack size allocated when the + timer task runs. + Default: `2048`. +- `EXAMPLES_TIMER_GPIO_PRIORITY` โ€“ This is the priority of the timer task. + Default: `255`. +- `EXAMPLES_TIMER_GPIO_PROGNAME` โ€“ This is the name of the program that will + be used from the nsh. + Default: `timer_gpio`. + +## `touchscreen` Touchscreen Events + +This configuration implements a simple touchscreen test at +`apps/examples/touchscreen`. This test will create an empty X11 window and will +print the touchscreen output as it is received from the simulated touchscreen +driver. + +- `CONFIG_NSH_BUILTIN_APPS` โ€“ Build the touchscreen test as an NSH built-in + function. Default: Built as a standalone program. +- `CONFIG_EXAMPLES_TOUCHSCREEN_MINOR` โ€“ The minor device number. Minor `N` + corresponds to touchscreen device `/dev/inputN`. Note this value must with + `CONFIG_EXAMPLES_TOUCHSCREEN_DEVPATH`. Default `0`. +- `CONFIG_EXAMPLES_TOUCHSCREEN_DEVPATH` โ€“ The path to the touchscreen device. + This must be consistent with `CONFIG_EXAMPLES_TOUCHSCREEN_MINOR`. Default: + `/dev/input0`. +- `CONFIG_EXAMPLES_TOUCHSCREEN_NSAMPLES` โ€“ This number of samples is collected + and the program terminates. Default: Samples are collected indefinitely. +- `CONFIG_EXAMPLES_TOUCHSCREEN_MOUSE` โ€“ The touchscreen test can also be + configured to work with a mouse driver by setting this option. + +The following additional configurations must be set in the NuttX configuration +file: + +- `CONFIG_INPUT=y` (plus any touchscreen-specific settings) + +The following must also be defined in your apps configuration file: + +- `CONFIG_EXAMPLES_TOUCHSREEN=y` + +This example code will call `boardctl()` to setup the touchscreen driver for +texting. The implementation of `boardctl()` will require that board- specific +logic provide the following interfaces that will be called by the `boardctl()` +in order to initialize the touchscreen hardware: + +```c +int board_tsc_setup(int minor); +``` + +## `udp` Client/Server Over UDP + +This is a simple network test for verifying client- and server- functionality +over UDP. + +Applications using this example will need to enabled the following `netutils` +libraries in the `defconfig` file: + +- `CONFIG_NETUTILS_NETLIB=y` + +Possible configurations: + +- Server on target hardware; client on host. +- Client on target hardware; Server on host. +- Server and Client on different targets. + +## `udpblaster` + +This is a simple network test for stressing UDP transfers. It simply sends UDP +packets from both the host and the target and the highest possible rate. + +## `unionfs` Union File System + +This is at trivial test of the Union File System. See +`nuttx/fs/unionfs/README.txt`. Dependencies: + +- `CONFIG_DISABLE_MOUNTPOINT` โ€“ Mountpoint support must not be + disabled. +- `CONFIG_FS_ROMFS` โ€“ ROMFS support is required. +- `CONFIG_FS_UNIONFS` โ€“ Union File System support is required. + +Configuration options. Use the defaults if you are unsure of what you are doing: + +- `CONFIG_EXAMPLES_UNIONFS` โ€“ Enables the example. +- `CONFIG_EXAMPLES_UNIONFS_MOUNTPT` โ€“ Mountpoint path for the Union File + System. +- `CONFIG_EXAMPLES_UNIONFS_TMPA` โ€“ Temporary mount point for file system + `1`. +- `CONFIG_EXAMPLES_UNIONFS_TMPB` โ€“ Temporary mount point for file system + `2`. +- `CONFIG_EXAMPLES_UNIONFS_RAMDEVNO_A` โ€“ ROMFS file system `1` RAM disk device + number. +- `CONFIG_EXAMPLES_UNIONFS_RAMDEVNO_B` โ€“ ROMFS file system `2` RAM disk device + number. +- `CONFIG_EXAMPLES_UNIONFS_SECTORSIZE` โ€“ ROM disk sector size. + +See the `README.txt` file at `nuttx/boards/sim/sim/sim/README.txt` for a +walk-through of the output of this text. + +## `usbserial` USB Serial Hello World + +### Target configuration + +This is another implementation of _Hello, World_ but this one uses a USB serial +driver. Configuration options can be used to simply the test. These options +include: + +- `CONFIG_EXAMPLES_USBSERIAL_INONLY` โ€“ Only verify IN (device-to-host) data + transfers. Default: both. +- `CONFIG_EXAMPLES_USBSERIAL_OUTONLY` โ€“ Only verify OUT (host-to-device) data + transfers. Default: both. +- `CONFIG_EXAMPLES_USBSERIAL_ONLYSMALL` โ€“ Send only small, single packet + messages. Default: Send large and small. +- `CONFIG_EXAMPLES_USBSERIAL_ONLYBIG` โ€“ Send only large, multi-packet messages. + Default: Send large and small. + +If `CONFIG_USBDEV_TRACE` is enabled (or `CONFIG_DEBUG_FEATURES` and +`CONFIG_DEBUG_USB`), then the example code will also manage the USB trace +output. The amount of trace output can be controlled using: + +- `CONFIG_EXAMPLES_USBSERIAL_TRACEINIT` โ€“ Show initialization events. +- `CONFIG_EXAMPLES_USBSERIAL_TRACECLASS` โ€“ Show class driver events. +- `CONFIG_EXAMPLES_USBSERIAL_TRACETRANSFERS` โ€“ Show data transfer events. +- `CONFIG_EXAMPLES_USBSERIAL_TRACECONTROLLER` โ€“ Show controller events. +- `CONFIG_EXAMPLES_USBSERIAL_TRACEINTERRUPTS` โ€“ Show interrupt-related events. + +Error results are always shown in the trace output. + +### Host-side test program + +In additional to the target device-side example, there is also a host-side +application in this directory. This host side application must be executed on a +Linux host in order to perform the `USBSERIAL` test. The host application can be +compiled under Linux (or Cygwin?) as follows: + +```bash +cd examples/usbserial +make -f Makefile.host TOPDIR=<nuttx-directory> +``` + +### Running the test + +This will generate a small program called `host`. Usage: + +1. Build the `examples/usbserial` target program and start the target. + +2. Wait a bit, then do enter: + + ```shell + dmesg + ``` + + At the end of the dmesg output, you should see the serial device was + successfully idenfied and assigned to a tty device, probably `/dev/ttyUSB0` + or `/dev/ttyACM0` (depending on the configured USB serial driver). + +3. Then start the host application: + + ```bash + ./host [<tty-dev>] + ``` + + Where: + + - `<tty-dev>` is the USB TTY device to use. The default is `/dev/ttyUSB0` + (for the PL2303 emulation) or `/dev/ttyACM0` (for the CDC/ACM serial + device). + +The host and target will exchange are variety of very small and very large +serial messages. + +## `userfs` UserFS File System + +A simple test of the UserFS file system. + +## `ustream` Unix Datagram Sockets + +This is the same test as `examples/udp` and similar to `examples/ustream`, but +using Unix domain datagram sockets. + +Dependencies: + +- `CONFIG_NET_LOCAL` โ€“ Depends on support for Unix domain sockets. + +Configuration: + +- `CONFIG_EXAMPLES_UDGRAM` โ€“ Enables the Unix domain socket example. +- `CONFIG_EXAMPLES_UDGRAM_ADDR` โ€“ Specifics the Unix domain address. Default: + `/dev/fifo`. + +## `ustream` Unix Stream Sockets + +This is the same test as `examples/udp` and similar to `examples/udgram`, but +using Unix domain stream sockets. + +Dependencies: + +- `CONFIG_NET_LOCAL` โ€“ Depends on support for Unix domain sockets. + +Configuration: + +- `CONFIG_EXAMPLES_USTREAM` โ€“ Enables the Unix domain socket example. +- `CONFIG_EXAMPLES_USTREAM_ADDR` โ€“ Specifics the Unix domain address. Default: + `/dev/fifo`. + +## `watchdog` Watchdog Timer + +A simple test of a watchdog timer driver. Initializes starts the watchdog timer. +It pings the watchdog timer for a period of time then lets the watchdog timer +expire... resetting the CPU is successful. This example can ONLY be built as an +NSH built-in function. + +This test depends on these specific Watchdog/NSH configurations settings (your +specific watchdog hardware settings might require additional settings). + +- `CONFIG_WATCHDOG` โ€“ Enables watchdog timer support support. +- `CONFIG_NSH_BUILTIN_APPS` โ€“ Build the watchdog time test as an NSH built-in + function. + +Specific configuration options for this example include: + +- `CONFIG_EXAMPLES_WATCHDOG_DEVPATH` โ€“ The path to the Watchdog device. Default: + `/dev/watchdog0`. +- `CONFIG_EXAMPLES_WATCHDOG_PINGTIME` โ€“ Time in milliseconds that the example + will ping the watchdog before letting the watchdog expire. Default: `5000` + milliseconds. +- `CONFIG_EXAMPLES_WATCHDOG_PINGDELAY` โ€“ Time delay between pings in + milliseconds. Default: `500` milliseconds. +- `CONFIG_EXAMPLES_WATCHDOG_TIMEOUT` โ€“ The watchdog timeout value in + milliseconds before the watchdog timer expires. Default: `2000` milliseconds. + +## `watcher` Watcher & Watched + +The watcher and watched examples are designed to work together. The watched +example will only appear after watcher is selected. +The watcher is a task that will monitor other tasks that subscribe to be watched. +If a watched task doesn't signal the watcher during the watchdog time period, +the watchdog timer will expire and the watcher will print the tasks that did +not signal and the ones that signaled. The tasks that did not signal will be printed +as the tasks that starved the dog and the tasks that signaled will be printed as +the tasks that fed the dog. +The watcher task will only feed the watchdog timer when all subscribed tasks have +asked to feed dog. + +To start the watcher, just run: + +`watcher` + +The watched example is not required to use the watcher. The watched example is simply +a task that creates 4 tasks that will subscribe to be watched. The first and fourth +will not feed the dog to expose the functionality. This example will show the user +how to subscribe, to feed the dog and to unsubscribe. + +To start the watched, just run: + +`watched` + +P.S: This example will only be supported by the chips that support interrupt on +timeout, i.e., which have the \"capture\" command implemented. + +This test depends on these specific configurations settings (your +specific watchdog hardware settings might require additional settings). + +- `CONFIG_EXAMPLES_WATCHER` โ€“ Includes this example. +- `CONFIG_WATCHDOG` โ€“ Enables watchdog timer support. +- `CONFIG_NSH_BUILTIN_APPS` โ€“ Build this example an NSH built-in + function. +- `CONFIG_DRIVER_NOTE` and `CONFIG_SCHED_INSTRUMENTATION` โ€“ Allows the watcher + to get the tasks' names. +- `CONFIG_FS_FAT` โ€“ Allows the creation of a FAT filesystem on the ramdisk + to create a file with all the necessary info for the watched tasks. + +Specific configuration options for the `watcher` example include: + +- `CONFIG_EXAMPLES_WATCHER_PRIORITY` โ€“ Watcher Task Priority. +- `CONFIG_EXAMPLES_WATCHER_STACKSIZE` โ€“ Watcher Task Stack Size. +- `CONFIG_EXAMPLES_WATCHER_DEVPATH` โ€“ The path to the Watchdog device used by + the Watcher. Default: `/dev/watchdog0`. +- `CONFIG_EXAMPLES_WATCHER_TIMEOUT` โ€“ The watchdog timeout value in + milliseconds. +- `CONFIG_EXAMPLES_WATCHER_SIGNAL` โ€“ This is the Signal Number used for + communication between the watcher task and the watched tasks. + +Specific configuration options for the `watched` example include: + +- `CONFIG_EXAMPLES_WATCHED_PRIORITY` โ€“ Watched Task Priority. +- `CONFIG_EXAMPLES_WATCHED_STACKSIZE` โ€“ Watched Task Stack Size. + +## `webserver` Simple Webserver + +This is a port of uIP tiny webserver example application. Settings specific to +this example include: + +- `CONFIG_EXAMPLES_WEBSERVER_NOMAC` (may be defined to use software assigned + MAC) +- `CONFIG_EXAMPLES_WEBSERVER_IPADDR` โ€“ Target IP address. +- `CONFIG_EXAMPLES_WEBSERVER_DRIPADDR` โ€“ Default router IP address. +- `CONFIG_EXAMPLES_WEBSERVER_NETMASK` โ€“ Network mask. +- `CONFIG_EXAMPLES_WEBSERVER_DHCPC` โ€“ Select to get IP address via DHCP. + +If you use DHCPC, then some special configuration network options are required. +These include: + +- `CONFIG_NET=y` โ€“ of course. +- `CONFIG_NET_UDP=y` โ€“ UDP support is required for DHCP (as well as various + other UDP-related configuration settings). +- `CONFIG_NET_BROADCAST=y` โ€“ UDP broadcast support is needed. +- `CONFIG_NET_ETH_PKTSIZE=650` or larger. Per RFC2131 (p. 9), the DHCP client + must be prepared to receive DHCP messages of up to `576` bytes (excluding + Ethernet, IP, or UDP headers and FCS). **Note** that the actual MTU setting + will depend upon the specific link protocol. Here Ethernet is indicated. + +Other configuration items apply also to the selected `webserver` net utility. +Additional relevant settings for the uIP `webserver` net utility are: + +- `CONFIG_NETUTILS_HTTPDSTACKSIZE` +- `CONFIG_NETUTILS_HTTPDFILESTATS` +- `CONFIG_NETUTILS_HTTPDNETSTATS` + +Applications using this example will need to enable the following `netutils` +libraries in their `defconfig` file: + +```conf +CONFIG_NETUTILS_NETLIB=y +CONFIG_NETUTILS_DHCPC=y +CONFIG_NETDB_DNSCLIENT=y +CONFIG_NETUTILS_WEBSERVER=y +``` + +**Note**: This example does depend on the `perl` script at +`nuttx/tools/mkfsdata.pl`. You must have `perl` installed on your development +system at `/usr/bin/perl`. + +## `wget` Web Client + +A simple web client example. It will obtain a file from a server using the HTTP +protocol. Settings unique to this example include: + +- `CONFIG_EXAMPLES_WGET_URL` โ€“ The URL of the file to get +- `CONFIG_EXAMPLES_WGET_NOMAC` โ€“ (May be defined to use software assigned MAC) +- `CONFIG_EXAMPLES_WGET_IPADDR` โ€“ Target IP address +- `CONFIG_EXAMPLES_WGET_DRIPADDR` โ€“ Default router IP address +- `CONFIG_EXAMPLES_WGET_NETMASK` โ€“ Network mask + +This example uses `netutils/webclient`. Additional configuration settings apply +to that code as follows (but built-in defaults are probably OK): + +- `CONFIG_WEBCLIENT_GETMIMETYPE` +- `CONFIG_WEBCLIENT_MAXHTTPLINE` +- `CONFIG_WEBCLIENT_MAXMIMESIZE` +- `CONFIG_WEBCLIENT_MAXHOSTNAME` +- `CONFIG_WEBCLIENT_MAXFILENAME` + +Of course, the example also requires other settings including `CONFIG_NET` and +`CONFIG_NET_TCP`. The example also uses the uIP resolver which requires +`CONFIG_UDP`. + +**Warning**: As of this writing, `wget` is untested on the target platform. At +present it has been tested only in the host-based configuration described in the +following note. The primary difference is that the target version will rely on +the also untested uIP name resolver. + +**Note**: For test purposes, this example can be built as a host-based `wget` +function. This can be built as follows: + +```bash +cd examples/wget +make -f Makefile.host +``` + +Applications using this example will need to enable the following `netutils` +libraries in the `defconfig` file: + +```conf +CONFIG_NETUTILS_NETLIB=y +CONFIG_NETDB_DNSCLIENT=y +CONFIG_NETUTILS_WEBCLIENT=y +``` + +## `wgetjson` GET JSON Using `wget` + +Uses `wget` to get a JSON encoded file, then decodes the file. + +- `CONFIG_EXAMPLES_WDGETJSON_MAXSIZE` โ€“ Max. JSON Buffer Size. +- `CONFIG_EXAMPLES_EXAMPLES_WGETJSON_URL` โ€“ `wget` URL + +## `xmlrpc` XML-RPC Server + +This example exercises the _Embeddable Lightweight XML-RPC Server_ which is +discussed at: + +http://www.drdobbs.com/web-development/an-embeddable-lightweight-xml-rpc-server/184405364 + +Configuration options: + +- `CONFIG_EXAMPLES_XMLRPC_BUFFERSIZE` โ€“ HTTP buffer size. Default `1024` +- `CONFIG_EXAMPLES_XMLRPC_DHCPC` โ€“ Use DHCP Client. Default `n`. Ignored if + `CONFIG_NSH_NETINIT` is selected. +- `CONFIG_EXAMPLES_XMLRPC_NOMAC` โ€“ Use Canned MAC Address. Default `n`. Ignored + if `CONFIG_NSH_NETINIT` is selected. +- `CONFIG_EXAMPLES_XMLRPC_IPADDR` โ€“ Target IP address. Default `0x0a000002`. + Ignored if `CONFIG_NSH_NETINIT` is selected. +- `CONFIG_EXAMPLES_XMLRPC_DRIPADDR` โ€“ Default Router IP address (Gateway). + Default `0x0a000001`. Ignored if `CONFIG_NSH_NETINIT` is selected. +- `CONFIG_EXAMPLES_XMLRPC_NETMASK` โ€“ Network Mask. Default `0xffffff00`. Ignored + if `CONFIG_NSH_NETINIT` is selected. + +## `zerocross` Zero Crossing Device + +A simple test of the Zero Crossing device driver. diff --git a/examples/abntcodi/CMakeLists.txt b/examples/abntcodi/CMakeLists.txt deleted file mode 100644 index 19d10a4d8..000000000 --- a/examples/abntcodi/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# ############################################################################## -# apps/examples/abntcodi/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_ABNTCODI) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_ABNTCODI_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_ABNTCODI_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_ABNTCODI_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_ABNTCODI} - SRCS - abntcodi_main.c) -endif() diff --git a/examples/abntcodi/Make.defs b/examples/abntcodi/Make.defs index 1e5389c27..f6e97a685 100644 --- a/examples/abntcodi/Make.defs +++ b/examples/abntcodi/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/abntcodi/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/abntcodi/Makefile b/examples/abntcodi/Makefile index d0277e3d2..e85c7a94b 100644 --- a/examples/abntcodi/Makefile +++ b/examples/abntcodi/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/abntcodi/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/abntcodi/abntcodi_main.c b/examples/abntcodi/abntcodi_main.c index 547b7d88d..27faaa684 100644 --- a/examples/abntcodi/abntcodi_main.c +++ b/examples/abntcodi/abntcodi_main.c @@ -1,7 +1,5 @@ /**************************************************************************** - * apps/examples/abntcodi/abntcodi_main.c - * - * SPDX-License-Identifier: Apache-2.0 + * apps/examples/hello/abntcodi_main.c * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -30,7 +28,6 @@ #include <fcntl.h> #include <syslog.h> #include <stdlib.h> -#include <unistd.h> #include "industry/abnt_codi.h" @@ -48,22 +45,20 @@ void print_abnt_codi(FAR struct abnt_codi_proto_s *proto) proto->end_act_dem); printf("Current Bill Indicator: %d\n", proto->bill_indicator); printf("Reactive Interval Indicator: %d\n", proto->react_interval); - printf("Capacitive Reactive Pulses are used to calculate consumption: " - "%s\n", boolstr(proto->react_cap_pulse)); + printf("Capacitive Reactive Pulses are used to calculate consumption: %s\n", + boolstr(proto->react_cap_pulse)); printf("Inductive Reactive Pulses are used to calculate consumption: %s\n", boolstr(proto->react_ind_pulse)); printf("Segment type: %s\n", proto->segment_type == SEGMENT_PEEK ? "PEEK" : proto->segment_type == SEGMENT_OUT_PEEK ? "OUT OF PEEK" : - proto->segment_type == SEGMENT_RESERVED ? "RESERVED" : - "UNKNOWN"); + proto->segment_type == SEGMENT_RESERVED ? "RESERVED" : "UNKNOWN"); printf("Charges type: %s\n", proto->charge_type == CHARGES_BLUE ? "BLUE" : proto->charge_type == CHARGES_GREEN ? "GREEN" : - proto->charge_type == CHARGES_IRRIGATORS ? "IRRIGATORS" : - "OTHERS"); - printf("Number of Active pulses since the beginning of current demand: " - "%d\n", proto->pulses_act_dem); + proto->charge_type == CHARGES_IRRIGATORS ? "IRRIGATORS" : "OTHERS"); + printf("Number of Active pulses since the beginning of current demand: %d\n", + proto->pulses_act_dem); printf("Number of Reactive pulses since beginning of current demand: %d\n", proto->pulses_react_dem); } diff --git a/examples/adc/CMakeLists.txt b/examples/adc/CMakeLists.txt deleted file mode 100644 index 215137a40..000000000 --- a/examples/adc/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# ############################################################################## -# apps/examples/adc/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_ADC) - nuttx_add_application( - NAME - adc - STACKSIZE - ${CONFIG_DEFAULT_TASK_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_ADC} - SRCS - adc_main.c) -endif() diff --git a/examples/adc/Make.defs b/examples/adc/Make.defs index baecb9a70..6f7d70ac4 100644 --- a/examples/adc/Make.defs +++ b/examples/adc/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/adc/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/adc/Makefile b/examples/adc/Makefile index 631234ff6..25d0e5f48 100644 --- a/examples/adc/Makefile +++ b/examples/adc/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/adc/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/adc/adc.h b/examples/adc/adc.h index 45497b0c9..ca136a9de 100644 --- a/examples/adc/adc.h +++ b/examples/adc/adc.h @@ -1,7 +1,5 @@ /**************************************************************************** - * apps/examples/adc/adc.h - * - * SPDX-License-Identifier: Apache-2.0 + * apps/examples/examples/adc/adc.h * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -32,13 +30,10 @@ /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ - /* Configuration ************************************************************/ - /* CONFIG_NSH_BUILTIN_APPS - Build the ADC test as an NSH built-in function. * Default: Built as a standalone program - * CONFIG_EXAMPLES_ADC_DEVPATH - The default path to the ADC device. - * Default: /dev/adc0 + * CONFIG_EXAMPLES_ADC_DEVPATH - The default path to the ADC device. Default: /dev/adc0 * CONFIG_EXAMPLES_ADC_NSAMPLES - This number of samples is * collected and the program terminates. Default: Samples are collected * indefinitely. diff --git a/examples/adc/adc_main.c b/examples/adc/adc_main.c index e5678e123..1db9817e0 100644 --- a/examples/adc/adc_main.c +++ b/examples/adc/adc_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/adc/adc_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -35,7 +33,7 @@ #include <string.h> #include <fcntl.h> #include <errno.h> -#include <nuttx/debug.h> +#include <debug.h> #include <nuttx/analog/adc.h> #include <nuttx/analog/ioctl.h> @@ -95,7 +93,7 @@ static void adc_help(FAR struct adc_state_s *adc) printf("Usage: adc [OPTIONS]\n"); printf("\nArguments are \"sticky\". " "For example, once the ADC device is\n"); - printf("specified, that device will be reused until it is changed.\n"); + printf("specified, that device will be re-used until it is changed.\n"); printf("\n\"sticky\" OPTIONS include:\n"); printf(" [-p devpath] selects the ADC device. " "Default: %s Current: %s\n", @@ -310,7 +308,7 @@ int main(int argc, FAR char *argv[]) if (nsamples * sizeof(struct adc_msg_s) != nbytes) { printf("adc_main: read size=%ld is not a multiple of " - "sample size=%zu, Ignoring\n", + "sample size=%d, Ignoring\n", (long)nbytes, sizeof(struct adc_msg_s)); } else diff --git a/examples/adjtime/CMakeLists.txt b/examples/adjtime/CMakeLists.txt deleted file mode 100644 index 77c9338be..000000000 --- a/examples/adjtime/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# ############################################################################## -# apps/examples/adjtime/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_ADJTIME) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_ADJTIME_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_ADJTIME_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_ADJTIME_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_ADJTIME} - SRCS - adjtime_main.c) -endif() diff --git a/examples/adjtime/Kconfig b/examples/adjtime/Kconfig deleted file mode 100644 index 16e4db30c..000000000 --- a/examples/adjtime/Kconfig +++ /dev/null @@ -1,32 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config EXAMPLES_ADJTIME - tristate "Ajdtime function example" - default n - depends on CLOCK_ADJTIME - ---help--- - Enable the adjtime example. This application demonstrates the usage - of adjtime() interface used to synchronize system clock time if - its value varies from real time (usually get by external RTC). - -if EXAMPLES_ADJTIME - -config EXAMPLES_ADJTIME_PROGNAME - string "Program name" - default "adjtime" - ---help--- - This is the name of the program that will be used when the NSH ELF - program is installed. - -config EXAMPLES_ADJTIME_PRIORITY - int "Adjtime task priority" - default 100 - -config EXAMPLES_ADJTIME_STACKSIZE - int "Adjtime stack size" - default DEFAULT_TASK_STACKSIZE - -endif diff --git a/examples/adjtime/Make.defs b/examples/adjtime/Make.defs deleted file mode 100644 index 0abb68bb1..000000000 --- a/examples/adjtime/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/examples/adjtime/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_EXAMPLES_ADJTIME),) -CONFIGURED_APPS += $(APPDIR)/examples/adjtime -endif diff --git a/examples/adjtime/Makefile b/examples/adjtime/Makefile deleted file mode 100644 index c35b77f26..000000000 --- a/examples/adjtime/Makefile +++ /dev/null @@ -1,36 +0,0 @@ -############################################################################ -# apps/examples/adjtime/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -# Adjtime built-in application info - -PROGNAME = $(CONFIG_EXAMPLES_ADJTIME_PROGNAME) -PRIORITY = $(CONFIG_EXAMPLES_ADJTIME_PRIORITY) -STACKSIZE = $(CONFIG_EXAMPLES_ADJTIME_STACKSIZE) -MODULE = $(CONFIG_EXAMPLES_ADJTIME) - -# Adjtime Example - -MAINSRC = adjtime_main.c - -include $(APPDIR)/Application.mk diff --git a/examples/adjtime/adjtime_main.c b/examples/adjtime/adjtime_main.c deleted file mode 100644 index fefe80567..000000000 --- a/examples/adjtime/adjtime_main.c +++ /dev/null @@ -1,170 +0,0 @@ -/**************************************************************************** - * apps/examples/adjtime/adjtime_main.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> -#include <stdint.h> -#include <stdio.h> -#include <sys/time.h> - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: pwm_help - ****************************************************************************/ - -static void adjtime_help(void) -{ - printf("Usage: adjtime [OPTIONS]\n"); - printf(" [-s delta->tv_sec] sets delta in seconds.\n"); - printf(" [-u delta->tv_usec] sets delta in micro seconds.\n"); - printf(" [-h] shows this message and exits\n"); - printf("Both delta->tv_sec and delta->tv_usec are set to 0 by default\n"); -} - -/**************************************************************************** - * Name: arg_string - ****************************************************************************/ - -static int arg_string(FAR char **arg, FAR char **value) -{ - FAR char *ptr = *arg; - - if (ptr[2] == '\0') - { - *value = arg[1]; - return 2; - } - else - { - *value = &ptr[2]; - return 1; - } -} - -/**************************************************************************** - * Name: arg_decimal - ****************************************************************************/ - -static int arg_decimal(FAR char **arg, FAR unsigned long *value) -{ - FAR char *string; - int ret; - - ret = arg_string(arg, &string); - *value = strtoul(string, NULL, 10); - return ret; -} - -/**************************************************************************** - * Name: parse_args - ****************************************************************************/ - -static void parse_args(FAR struct timeval *delta, int argc, - FAR char **argv) -{ - FAR char *ptr; - unsigned long value; - int index; - int nargs; - - for (index = 1; index < argc; ) - { - ptr = argv[index]; - if (ptr[0] != '-') - { - printf("Invalid options format: %s\n", ptr); - exit(0); - } - - switch (ptr[1]) - { - case 's': - nargs = arg_decimal(&argv[index], &value); - - delta->tv_sec = value; - index += nargs; - break; - - case 'u': - nargs = arg_decimal(&argv[index], &value); - - delta->tv_usec = value; - index += nargs; - break; - - case 'h': - adjtime_help(); - exit(0); - - default: - printf("Unsupported option: %s\n", ptr); - adjtime_help(); - exit(1); - } - } -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * adjtime_main - ****************************************************************************/ - -int main(int argc, FAR char *argv[]) -{ - struct timeval delta; - struct timeval olddelta; - int ret; - - /* Set delta between real time and system tick. */ - - delta.tv_sec = 0; - delta.tv_usec = 0; - - parse_args(&delta, argc, argv); - - printf("Delta time is %jd seconds and %ld micro seconds.\n", - (intmax_t)delta.tv_sec, delta.tv_usec); - - /* Call adjtime function. */ - - ret = adjtime(&delta, &olddelta); - if (ret < 0) - { - printf("ERROR: adjtime() failed: %d\n", ret); - } - else - { - printf("Returned olddelta is %jd seconds and %ld micro seconds.\n", - (intmax_t)olddelta.tv_sec, olddelta.tv_usec); - } - - return ret; -} diff --git a/examples/ads7046/CMakeLists.txt b/examples/ads7046/CMakeLists.txt deleted file mode 100644 index 6e875a149..000000000 --- a/examples/ads7046/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# ############################################################################## -# apps/examples/ads7046/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_ADS7046) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_ADS7046_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_ADS7046_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_ADS7046_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_ADS7046} - SRCS - ads7046_main.c) -endif() diff --git a/examples/ads7046/Kconfig b/examples/ads7046/Kconfig deleted file mode 100644 index c2d825a60..000000000 --- a/examples/ads7046/Kconfig +++ /dev/null @@ -1,36 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config EXAMPLES_ADS7046 - tristate "ADS7046 ADC example" - default n - depends on ADC_ADS7046 - ---help--- - Enable the ADS7046 example - -if EXAMPLES_ADS7046 - -config EXAMPLES_ADS7046_PROGNAME - string "Program name" - default "ads7046" - ---help--- - This is the name of the program that will be used when the NSH ELF - program is installed. - -config EXAMPLES_ADS7046_PRIORITY - int "ADS7046 task priority" - default 100 - -config EXAMPLES_ADS7046_STACKSIZE - int "ADS7046 stack size" - default DEFAULT_TASK_STACKSIZE - -config EXAMPLES_ADS7046_DEVPATH - string "ADS7046 device path" - default "/dev/adc0" - ---help--- - The default path to the ADS7046 ADC device - -endif diff --git a/examples/ads7046/Make.defs b/examples/ads7046/Make.defs deleted file mode 100644 index 171c570f4..000000000 --- a/examples/ads7046/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/examples/ads7046/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_EXAMPLES_ADS7046),) -CONFIGURED_APPS += $(APPDIR)/examples/ads7046 -endif diff --git a/examples/ads7046/Makefile b/examples/ads7046/Makefile deleted file mode 100644 index 310ccea67..000000000 --- a/examples/ads7046/Makefile +++ /dev/null @@ -1,36 +0,0 @@ -############################################################################ -# apps/examples/ads7046/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -# ADS7046 ADC example built-in application info - -PROGNAME = $(CONFIG_EXAMPLES_ADS7046_PROGNAME) -PRIORITY = $(CONFIG_EXAMPLES_ADS7046_PRIORITY) -STACKSIZE = $(CONFIG_EXAMPLES_ADS7046_STACKSIZE) -MODULE = $(CONFIG_EXAMPLES_ADS7046) - -# ADS7046 ADC example - -MAINSRC = ads7046_main.c - -include $(APPDIR)/Application.mk diff --git a/examples/ads7046/ads7046_main.c b/examples/ads7046/ads7046_main.c deleted file mode 100644 index 1b0ca7253..000000000 --- a/examples/ads7046/ads7046_main.c +++ /dev/null @@ -1,90 +0,0 @@ -/**************************************************************************** - * apps/examples/ads7046/ads7046_main.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> -#include <stdio.h> -#include <fcntl.h> -#include <unistd.h> -#include <sys/ioctl.h> -#include <nuttx/analog/ioctl.h> -#include <nuttx/analog/ads7046.h> - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* As per the datasheet, the ADS7046 returns the following readings: - * INPUT VOLTAGE (AINP - AINM) DESCRIPTION HEX - * -------------------------------------- ------------------------ --- - * <= 1 LSB Negative full-scale code 000 - * 1 LSB to 2 LSB - 001 - * V_REF / 2 to V_REF / 2 + 1 LSB Mid code 7FF - * V_REF / 2 + 1 LSB to V_REF / 2 + 2 LSB - 800 - * >= V_REF - 1 LSB Positive full-scale code FFF - */ - -#define SAMPLE_TO_PCT(sample) (((sample) * 100) / 0xfff) - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: ads7046_main - ****************************************************************************/ - -int main(const int argc, FAR char *argv[]) -{ - UNUSED(argc); - UNUSED(argv); - - int ret; - int fd; - uint16_t sample; - - fd = open(CONFIG_EXAMPLES_ADS7046_DEVPATH, O_RDONLY); - if (fd < 0) - { - printf("Failed to open %s: %s (%d)\n", CONFIG_EXAMPLES_ADS7046_DEVPATH, - strerror(errno), errno); - return EXIT_FAILURE; - } - - ret = ioctl(fd, ANIOC_ADS7046_READ, &sample); - if (ret != OK) - { - perror("Could not ioctl fd"); - close(fd); - return EXIT_FAILURE; - } - - printf("ADS7046: hex=%x, dec=%"PRIu16", adc_percentage=%u%%\n", - sample, sample, SAMPLE_TO_PCT(sample)); - - close(fd); - - return EXIT_SUCCESS; -} diff --git a/examples/adxl372_test/CMakeLists.txt b/examples/adxl372_test/CMakeLists.txt deleted file mode 100644 index ead2dd360..000000000 --- a/examples/adxl372_test/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# ############################################################################## -# apps/examples/adxl372_test/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_ADXL372_TEST) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_ADXL372_TEST_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_ADXL372_TEST_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_ADXL372_TEST_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_ADXL372_TEST} - SRCS - adxl372_test_main.c) -endif() diff --git a/examples/adxl372_test/Kconfig b/examples/adxl372_test/Kconfig index 80189ea34..9f04a5797 100644 --- a/examples/adxl372_test/Kconfig +++ b/examples/adxl372_test/Kconfig @@ -6,7 +6,6 @@ config EXAMPLES_ADXL372_TEST tristate "ADXL372 test program" default n - depends on SENSORS_ADXL372 ---help--- Enable the ADXL372 sensor SPI test program. diff --git a/examples/adxl372_test/Make.defs b/examples/adxl372_test/Make.defs index 92384909f..d5311c7a3 100644 --- a/examples/adxl372_test/Make.defs +++ b/examples/adxl372_test/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/adxl372_test/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/adxl372_test/Makefile b/examples/adxl372_test/Makefile index 5c30ba191..583a03e6d 100644 --- a/examples/adxl372_test/Makefile +++ b/examples/adxl372_test/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/adxl372_test/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/adxl372_test/adxl372_test_main.c b/examples/adxl372_test/adxl372_test_main.c index 4d8b3ced9..4ebefb23b 100644 --- a/examples/adxl372_test/adxl372_test_main.c +++ b/examples/adxl372_test/adxl372_test_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/adxl372_test/adxl372_test_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -29,7 +27,7 @@ #include <stdio.h> #include <string.h> #include <fcntl.h> -#include <sys/param.h> +#include <nuttx/fs/fs.h> #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> @@ -43,6 +41,7 @@ * Pre-processor Definitions ****************************************************************************/ +#define ARRAYSIZE(x) (sizeof((x)) / sizeof((x)[0])) #define PASSED 0 #define SUB_PROMPT "stst >" @@ -148,7 +147,7 @@ static int adxl372_test(int is_interactive, FAR char *path) }; char bfr[32] __attribute__((aligned(2))); /* REVISIT: GCC dependent attribute */ - FAR struct XYZ *pxyz = (FAR struct XYZ *)bfr; + FAR struct XYZ *pxyz = (FAR struct XYZ *) bfr; int rc = PASSED; int rc_step = PASSED; @@ -336,11 +335,11 @@ static int adxl372_test(int is_interactive, FAR char *path) goto error_exit; } - printf("ADXL372 = (%6d, %6d, %6d))\n", + printf("ADXL372 = ( %6d, %6d, %6d))\n", pxyz->d[0], pxyz->d[1], pxyz->d[2]); - printf("ADXL372 = (0x%04X, 0x%04X, 0x%04X)\n", + printf("ADXL372 = ( 0x%04X, 0x%04X, 0x%04X)\n", pxyz->d[0], pxyz->d[1], pxyz->d[2]); - printf("ADXL372 raw = (0x%02X%02X, 0x%02X%02X, 0x%02X%02X)\n", + printf("ADXL372 raw = ( 0x%02X%02X, 0x%02X%02X, 0x%02X%02X)\n", bfr[1], bfr[0], bfr[3], bfr[2], bfr[5], bfr[4]); if (is_interactive) @@ -395,7 +394,7 @@ int main(int argc, FAR char *argv[]) adxl372_test, /* ADXL372 accelerometer tests */ }; - FAR char *test_path[nitems(test_ptr_array)]; + FAR char *test_path[ARRAYSIZE(test_ptr_array)]; if (argc < 1 || *argv[1] == 0 || *(argv[1] + 1) == 0) { @@ -491,7 +490,7 @@ int main(int argc, FAR char *argv[]) printf("Set to batch mode.\n"); } } - else if (ui >= nitems(test_ptr_array)) + else if (ui >= ARRAYSIZE(test_ptr_array)) { printf("Huh?\n"); } @@ -512,7 +511,7 @@ int main(int argc, FAR char *argv[]) { printf("ADXL372 sensor diagnostic started in batch mode...\n"); - for (ui = 0; ui < nitems(test_ptr_array); ui++) + for (ui = 0; ui < ARRAYSIZE(test_ptr_array); ui++) { step_rc = 0; if (test_ptr_array[ui] != 0) diff --git a/examples/ajoystick/CMakeLists.txt b/examples/ajoystick/CMakeLists.txt deleted file mode 100644 index b35aff10a..000000000 --- a/examples/ajoystick/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# ############################################################################## -# apps/examples/ajoystick/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_AJOYSTICK) - nuttx_add_application( - NAME - ajoy - STACKSIZE - ${CONFIG_DEFAULT_TASK_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_AJOYSTICK} - SRCS - ajoy_main.c) -endif() diff --git a/examples/ajoystick/Kconfig b/examples/ajoystick/Kconfig index ba58596d3..63ec2d2b5 100644 --- a/examples/ajoystick/Kconfig +++ b/examples/ajoystick/Kconfig @@ -18,6 +18,6 @@ config EXAMPLES_AJOYSTICK_DEVNAME config EXAMPLES_AJOYSTICK_SIGNO int "Joystick signal" - default 32 + default 13 endif diff --git a/examples/ajoystick/Make.defs b/examples/ajoystick/Make.defs index 623b4f169..e77577023 100644 --- a/examples/ajoystick/Make.defs +++ b/examples/ajoystick/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/ajoystick/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/ajoystick/Makefile b/examples/ajoystick/Makefile index 68d9de39f..0266cf8c2 100644 --- a/examples/ajoystick/Makefile +++ b/examples/ajoystick/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/ajoystick/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -22,11 +20,11 @@ include $(APPDIR)/Make.defs -# AJOYSTICK Example +# Hello, World! Example MAINSRC = ajoy_main.c -# AJOYSTICK built-in application info +# Buttons built-in application info PROGNAME = ajoy PRIORITY = SCHED_PRIORITY_DEFAULT diff --git a/examples/ajoystick/ajoy_main.c b/examples/ajoystick/ajoy_main.c index 8a58b66a9..398a787a9 100644 --- a/examples/ajoystick/ajoy_main.c +++ b/examples/ajoystick/ajoy_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/ajoystick/ajoy_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -27,14 +25,12 @@ #include <nuttx/config.h> #include <sys/ioctl.h> -#include <sys/param.h> #include <stdio.h> #include <stdlib.h> #include <fcntl.h> #include <errno.h> #include <fixedmath.h> -#include <nuttx/debug.h> -#include <unistd.h> +#include <debug.h> #include <nuttx/input/ajoystick.h> @@ -53,11 +49,20 @@ #endif #ifndef CONFIG_EXAMPLES_AJOYSTICK_SIGNO -# define CONFIG_EXAMPLES_AJOYSTICK_SIGNO 32 +# define CONFIG_EXAMPLES_AJOYSTICK_SIGNO 13 #endif #define FULL_RANGE 16 +/* Helpers ******************************************************************/ + +#ifndef MIN +# define MIN(a,b) ((a) < (b) ? (a) : (b)) +#endif +#ifndef MAX +# define MAX(a,b) ((a) > (b) ? (a) : (b)) +#endif + /**************************************************************************** * Private Function Prototypes ****************************************************************************/ diff --git a/examples/alarm/CMakeLists.txt b/examples/alarm/CMakeLists.txt deleted file mode 100644 index 314457750..000000000 --- a/examples/alarm/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# ############################################################################## -# apps/examples/alarm/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_ALARM) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_ALARM_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_ALARM_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_ALARM_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_ALARM} - SRCS - alarm_main.c) -endif() diff --git a/examples/alarm/Kconfig b/examples/alarm/Kconfig index 6abff44f4..e36961f35 100644 --- a/examples/alarm/Kconfig +++ b/examples/alarm/Kconfig @@ -33,6 +33,6 @@ config EXAMPLES_ALARM_DEVPATH config EXAMPLES_ALARM_SIGNO int "Alarm signal" - default 32 + default 1 endif # EXAMPLES_ALARM diff --git a/examples/alarm/Make.defs b/examples/alarm/Make.defs index 79c467cd4..d2699def1 100644 --- a/examples/alarm/Make.defs +++ b/examples/alarm/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/alarm/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/alarm/Makefile b/examples/alarm/Makefile index 59cdad47a..f0b8d7450 100644 --- a/examples/alarm/Makefile +++ b/examples/alarm/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/alarm/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/alarm/alarm_main.c b/examples/alarm/alarm_main.c index 4b5296f73..ce70123a8 100644 --- a/examples/alarm/alarm_main.c +++ b/examples/alarm/alarm_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/alarm/alarm_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -34,7 +32,6 @@ #include <fcntl.h> #include <sched.h> #include <errno.h> -#include <unistd.h> #include <nuttx/timers/rtc.h> @@ -337,14 +334,14 @@ int main(int argc, FAR char *argv[]) * alarm expiring in year 1900. */ - timeleft = timegm((struct tm *)&rd.time) - now; + timeleft = mktime((struct tm *)&rd.time) - now; } else { struct tm now_tm; /* Periodic extend "partial" alarms by "unfolding" months, - * until we get alarm that is in future. Note that timegm() + * until we get alarm that is in future. Note that mktime() * normalizes fields that are out of their valid values, * so we don't have to handle carry to tm_year by ourselves. */ @@ -355,7 +352,7 @@ int main(int argc, FAR char *argv[]) do { - timeleft = timegm((struct tm *)&rd.time) - now; + timeleft = mktime((struct tm *)&rd.time) - now; if (timeleft < 0) { rd.time.tm_mon++; @@ -393,7 +390,7 @@ int main(int argc, FAR char *argv[]) setrel.id = alarmid; setrel.pid = g_alarm_daemon_pid; - setrel.reltime = seconds; + setrel.reltime = (time_t)seconds; setrel.event.sigev_notify = SIGEV_SIGNAL; setrel.event.sigev_signo = CONFIG_EXAMPLES_ALARM_SIGNO; diff --git a/examples/amg88xx/CMakeLists.txt b/examples/amg88xx/CMakeLists.txt deleted file mode 100644 index cfd88724b..000000000 --- a/examples/amg88xx/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# ############################################################################## -# apps/examples/amg88xx/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_AMG88XX) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_AMG88XX_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_AMG88XX_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_AMG88XX_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_AMG88XX} - SRCS - amg88xx_main.c) -endif() diff --git a/examples/amg88xx/Kconfig b/examples/amg88xx/Kconfig deleted file mode 100644 index c79092881..000000000 --- a/examples/amg88xx/Kconfig +++ /dev/null @@ -1,25 +0,0 @@ -config EXAMPLES_AMG88XX - tristate "AMG88xx sensor example" - default n - depends on SENSORS_AMG88XX - ---help--- - Enable the AMG88xx sensor example - -if EXAMPLES_AMG88XX - -config EXAMPLES_AMG88XX_PROGNAME - string "Program name" - default "amg88xx" - ---help--- - This is the name of the program that will be used when the NSH ELF - program is installed. - -config EXAMPLES_AMG88XX_PRIORITY - int "AMG88xx task priority" - default 100 - -config EXAMPLES_AMG88XX_STACKSIZE - int "AMG88xx stack size" - default DEFAULT_TASK_STACKSIZE - -endif diff --git a/examples/amg88xx/Make.defs b/examples/amg88xx/Make.defs deleted file mode 100644 index ba390c84d..000000000 --- a/examples/amg88xx/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/examples/amg88xx/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_EXAMPLES_AMG88XX),) -CONFIGURED_APPS += $(APPDIR)/examples/amg88xx -endif diff --git a/examples/amg88xx/Makefile b/examples/amg88xx/Makefile deleted file mode 100644 index 85f777d49..000000000 --- a/examples/amg88xx/Makefile +++ /dev/null @@ -1,36 +0,0 @@ -############################################################################ -# apps/examples/amg88xx/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -# amg88xx, World! built-in application info - -PROGNAME = $(CONFIG_EXAMPLES_AMG88XX_PROGNAME) -PRIORITY = $(CONFIG_EXAMPLES_AMG88XX_PRIORITY) -STACKSIZE = $(CONFIG_EXAMPLES_AMG88XX_STACKSIZE) -MODULE = $(CONFIG_EXAMPLES_AMG88XX) - -# amg88xx Example - -MAINSRC = amg88xx_main.c - -include $(APPDIR)/Application.mk diff --git a/examples/amg88xx/amg88xx_main.c b/examples/amg88xx/amg88xx_main.c deleted file mode 100644 index 932348326..000000000 --- a/examples/amg88xx/amg88xx_main.c +++ /dev/null @@ -1,91 +0,0 @@ -/**************************************************************************** - * apps/examples/amg88xx/amg88xx_main.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> -#include <nuttx/sensors/ioctl.h> -#include <stdbool.h> -#include <stdio.h> -#include <fcntl.h> -#include <sys/ioctl.h> -#include <unistd.h> -#include <float.h> - -#include <nuttx/sensors/amg88xx.h> - -#define READ_DELAY 2 -#define ROWS 8 -#define COLS 8 - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * amg88xx_main - ****************************************************************************/ - -int main(int argc, FAR char *argv[]) -{ - amg88xx_pixels_temp_t data; - float temps[AMG88XX_PIXELS]; - int fd; - int ret; - int i; - int j; - - fd = open("/dev/irm0", O_RDWR); - - ioctl(fd, SNIOC_SET_MOVING_AVG, true); - - while (1) - { - sleep(READ_DELAY); - ret = read(fd, data, AMG88XX_PIXELS_ARRAY_LENGTH); - printf("\n"); - if (ret == 0) - { - for (i = 0; i < AMG88XX_PIXELS_ARRAY_LENGTH; i += 2) - { - uint16_t pixel = (data[i + 1] << 8) | data[i]; - pixel &= 0x0fff; - temps[i / 2] = pixel * AMG88XX_PIXEL_RESOLUTION; - } - - for (i = 0; i < ROWS; i++) - { - for (j = 0; j < COLS; j++) - { - printf(" %04.2f ", temps[i * COLS + j]); - } - - printf("\n"); - } - } - } - - close(fd); - return 0; -} diff --git a/examples/apa102/CMakeLists.txt b/examples/apa102/CMakeLists.txt deleted file mode 100644 index 35344d1b4..000000000 --- a/examples/apa102/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# ############################################################################## -# apps/examples/apa102/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_APA102) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_APA102_PROGNAME} - STACKSIZE - ${CONFIG_DEFAULT_TASK_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_APA102} - SRCS - apa102_main.c) -endif() diff --git a/examples/apa102/Kconfig b/examples/apa102/Kconfig index 6a896cf83..9494a7446 100644 --- a/examples/apa102/Kconfig +++ b/examples/apa102/Kconfig @@ -6,7 +6,6 @@ config EXAMPLES_APA102 tristate "APA102 LED Strip example" default n - depends on LCD_APA102 ---help--- Enable the APA102 example diff --git a/examples/apa102/Make.defs b/examples/apa102/Make.defs index 8286107ea..6bcac6cd3 100644 --- a/examples/apa102/Make.defs +++ b/examples/apa102/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/apa102/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/apa102/Makefile b/examples/apa102/Makefile index afe3f91ae..fe7d5e689 100644 --- a/examples/apa102/Makefile +++ b/examples/apa102/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/apa102/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/apa102/apa102_main.c b/examples/apa102/apa102_main.c index 8e933b392..0d2370688 100644 --- a/examples/apa102/apa102_main.c +++ b/examples/apa102/apa102_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/apa102/apa102_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -32,7 +30,6 @@ #include <fcntl.h> #include <errno.h> #include <stdio.h> -#include <unistd.h> #include <nuttx/leds/apa102.h> @@ -62,8 +59,7 @@ struct apa102_ledstrip_s ledstrip[NUM_LEDS]; * Converts a color from HSV to RGB. * * Note: This function is based on Pololu example: - * https://github.com/pololu/apa102-arduino/blob/master/examples/Rainbow/ - * Rainbow.ino + * https://github.com/pololu/apa102-arduino/blob/master/examples/Rainbow/Rainbow.ino * * Input Parameters: * h is hue, as a number between 0 and 360. @@ -83,7 +79,7 @@ static struct apa102_ledstrip_s hsvtorgb(uint16_t h, uint8_t s, uint8_t v) uint8_t g = 0; uint8_t b = 0; - switch ((h / 60) % 6) + switch((h / 60) % 6) { case 0: r = v; diff --git a/examples/apds9960/CMakeLists.txt b/examples/apds9960/CMakeLists.txt deleted file mode 100644 index 6f2c7f2e8..000000000 --- a/examples/apds9960/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# ############################################################################## -# apps/examples/apds9960/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_APDS9960) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_APDS9960_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_APDS9960_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_APDS9960_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_APDS9960} - SRCS - apds9960_main.c) -endif() diff --git a/examples/apds9960/Make.defs b/examples/apds9960/Make.defs index 3902c6ab2..44bf6c6aa 100644 --- a/examples/apds9960/Make.defs +++ b/examples/apds9960/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/apds9960/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/apds9960/Makefile b/examples/apds9960/Makefile index 7701173d7..a3ad27d98 100644 --- a/examples/apds9960/Makefile +++ b/examples/apds9960/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/apds9960/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -22,14 +20,14 @@ include $(APPDIR)/Make.defs -# APDS9960 built-in application info +# Hello, World! built-in application info PROGNAME = $(CONFIG_EXAMPLES_APDS9960_PROGNAME) PRIORITY = $(CONFIG_EXAMPLES_APDS9960_PRIORITY) STACKSIZE = $(CONFIG_EXAMPLES_APDS9960_STACKSIZE) MODULE = $(CONFIG_EXAMPLES_APDS9960) -# APDS9960 Example +# Hello, World! Example MAINSRC = apds9960_main.c diff --git a/examples/apds9960/apds9960_main.c b/examples/apds9960/apds9960_main.c index 97b5f907a..a4cc30999 100644 --- a/examples/apds9960/apds9960_main.c +++ b/examples/apds9960/apds9960_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/apds9960/apds9960_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -30,7 +28,6 @@ #include <stdlib.h> #include <errno.h> #include <fcntl.h> -#include <unistd.h> #include <nuttx/sensors/apds9960.h> @@ -56,7 +53,7 @@ int main(int argc, FAR char *argv[]) int nbytes; char gest; - fd = open(CONFIG_EXAMPLES_APDS9960_DEVNAME, O_RDONLY | O_NONBLOCK); + fd = open(CONFIG_EXAMPLES_APDS9960_DEVNAME, O_RDONLY|O_NONBLOCK); if (fd < 0) { int errcode = errno; @@ -67,7 +64,7 @@ int main(int argc, FAR char *argv[]) while (1) { - nbytes = read(fd, &gest, sizeof(gest)); + nbytes = read(fd, (void *)&gest, sizeof(gest)); if (nbytes == 1) { switch (gest) diff --git a/examples/audio_rttl/CMakeLists.txt b/examples/audio_rttl/CMakeLists.txt deleted file mode 100644 index 3553cfec6..000000000 --- a/examples/audio_rttl/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# ############################################################################## -# apps/examples/audio_rttl/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_AUDIO_SOUND) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_AUDIO_SOUND_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_AUDIO_SOUND_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_AUDIO_SOUND_STACKSIZE} - SRCS - audio_rttl_main.c) -endif() diff --git a/examples/audio_rttl/Kconfig b/examples/audio_rttl/Kconfig index 3a594e867..2dae260b0 100644 --- a/examples/audio_rttl/Kconfig +++ b/examples/audio_rttl/Kconfig @@ -5,11 +5,9 @@ config EXAMPLES_AUDIO_SOUND bool "Audio tone generator example (RTTL player)" - depends on AUDIO - depends on AUDIOUTILS_RTTTL_C default n ---help--- - Enable the audio RTTL player example. + Enable the audio RTTL player example if EXAMPLES_AUDIO_SOUND @@ -25,12 +23,4 @@ config EXAMPLES_AUDIO_SOUND_STACKSIZE int "Audio sound stack size" default DEFAULT_TASK_STACKSIZE -comment "Program options" - -config EXAMPLES_AUDIO_SOUND_MAXLEN - int "Maximum RTTL string length" - default 256 - ---help--- - The maximum length of an RTTL string that can be read from a file. - endif diff --git a/examples/audio_rttl/Make.defs b/examples/audio_rttl/Make.defs index 8975cb9ab..04c35191a 100644 --- a/examples/audio_rttl/Make.defs +++ b/examples/audio_rttl/Make.defs @@ -1,7 +1,5 @@ ############################################################################ -# apps/examples/audio_rttl/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 +# audio_player/Make.defs # # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with @@ -20,6 +18,6 @@ # ############################################################################ -ifneq ($(CONFIG_EXAMPLES_AUDIO_SOUND),) +ifeq ($(CONFIG_EXAMPLES_AUDIO_SOUND),y) CONFIGURED_APPS += examples/audio_rttl endif diff --git a/examples/audio_rttl/Makefile b/examples/audio_rttl/Makefile index b2a4630b3..62c26f607 100644 --- a/examples/audio_rttl/Makefile +++ b/examples/audio_rttl/Makefile @@ -1,7 +1,5 @@ ############################################################################ -# apps/examples/audio_rttl/Makefile -# -# SPDX-License-Identifier: Apache-2.0 +# audio_beep/Makefile # # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with @@ -21,6 +19,7 @@ ############################################################################ include $(APPDIR)/Make.defs +-include $(SDKDIR)/Make.defs # Audio application info @@ -30,6 +29,15 @@ STACKSIZE = $(CONFIG_EXAMPLES_AUDIO_SOUND_STACKSIZE) # Audio Example -MAINSRC = audio_rttl_main.c +MAINSRC = audio_rttl.cxx + +# Audio Example paths + +AUDIODIR = $(SDKDIR)$(DELIM)modules$(DELIM)audio + +# Audio Example flags + +CXXFLAGS += ${shell $(INCDIR) "$(CC)" "$(AUDIODIR)"} +CXXFLAGS += -D_POSIX include $(APPDIR)/Application.mk diff --git a/examples/audio_rttl/audio_rttl.cxx b/examples/audio_rttl/audio_rttl.cxx new file mode 100644 index 000000000..bad903e91 --- /dev/null +++ b/examples/audio_rttl/audio_rttl.cxx @@ -0,0 +1,359 @@ +/**************************************************************************** + * apps/examples/audio_rttl/audio_rttl.cxx + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <stdio.h> +#include <math.h> +#include <string.h> +#include <arch/board/board.h> +#include <arch/chip/audio.h> + +#include "audio_rttl.h" + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/* Note - note freq on octave 1 */ + +#define C 16.35 +#define CD 17.32 +#define D 18.35 +#define DE 19.45 +#define E 20.60 +#define F 21.83 +#define FG 23.12 +#define G 24.50 +#define A 27.50 +#define AB 29.14 +#define B 30.84 + +/* Octave - base freq multiplier for the base freq */ + +#define OCT2 4 +#define OCT3 8 +#define OCT4 16 +#define OCT5 32 +#define OCT6 64 +#define OCT7 128 +#define OCT8 256 + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +extern "C" int main(int argc, FAR char *argv[]) +{ + int freq; + float base_freq; + char temp_note; + int octave; + int duration; + int note_duration; + int base_duration; + int bpm; + int cnt; + + /* Set I/O parameters for power on. */ + + if (!board_audio_power_control(true)) + { + printf("Error: board_audio_power_control() failure.\n"); + return 1; + } + + printf("Start Audio RTTL player\n"); + + bpm = 0; + octave = 0; + base_duration = 0; + note_duration = 0; + + while (*g_song != ':') + { + g_song++; + } + + g_song++; + + if (*g_song == 'd') + { + g_song = g_song + 2; + base_duration = *g_song - '0'; + g_song++; + if ((*g_song >= '0') && (*g_song <= '9')) + { + base_duration = (base_duration * 10) + (*g_song - '0'); + g_song++; + } + + g_song++; + } + + if (*g_song == 'o') + { + g_song = g_song + 2; + octave = *g_song - '0'; + g_song = g_song + 2; + } + + if (octave == 2) + { + octave = OCT2; + } + else if (octave == 3) + { + octave = OCT3; + } + else if (octave == 4) + { + octave = OCT4; + } + else if (octave == 5) + { + octave = OCT5; + } + else if (octave == 6) + { + octave = OCT6; + } + else if (octave == 7) + { + octave = OCT7; + } + else if (octave == 8) + { + octave = OCT8; + } + + if (*g_song == 'b') + { + g_song = g_song + 2; + bpm = 0; + for (cnt = 1; cnt <= 3; cnt++) + { + if (*g_song != ':') + { + bpm = bpm * 10 + (*g_song - '0'); + g_song++; + } + + } + + g_song++; + } + + do + { + if ((*g_song >= '0') && (*g_song <= '9')) + { + note_duration = *g_song - '0'; + g_song++; + } + + if ((*g_song >= '0') && (*g_song <= '9')) + { + note_duration = (note_duration * 10) + (*g_song - '0'); + g_song++; + } + + if (note_duration > 0) + { + duration = ((60 * 1000L / bpm) * 4) / note_duration; + } + else + { + duration = ((60 * 1000L / bpm) * 4) / base_duration; + } + + base_freq = 0; + temp_note = ' '; + switch (*g_song) + { + case 'c': + { + temp_note = 'c'; + base_freq = C; + break; + } + + case 'd': + { + temp_note = 'd'; + base_freq = D; + break; + } + + case 'e': + { + temp_note = 'e'; + base_freq = E; + break; + } + + case 'f': + { + temp_note = 'f'; + base_freq = F; + break; + } + + case 'g': + { + temp_note = 'g'; + base_freq = G; + break; + } + + case 'a': + { + temp_note = 'a'; + base_freq = A; + break; + } + + case 'b': + { + temp_note = 'b'; + base_freq = B; + break; + } + + case 'p': + { + temp_note = 'p'; + break; + } + + default: + break; + } + + g_song++; + + if (*g_song == '.') + { + duration += duration / 2; + g_song++; + } + + if (*g_song == '#') + { + if (temp_note == 'c') + { + base_freq = CD; + } + + if (temp_note == 'd') + { + base_freq = DE; + } + + if (temp_note == 'f') + { + base_freq = FG; + } + + if (temp_note == 'a') + { + base_freq = AB; + } + + g_song++; + } + + if ((*g_song - '0') == '2') + { + octave = OCT2; + } + + if ((*g_song - '0') == '3') + { + octave = OCT3; + } + + if ((*g_song - '0') == '4') + { + octave = OCT4; + } + + if ((*g_song - '0') == '5') + { + octave = OCT5; + } + + if ((*g_song - '0') == '6') + { + octave = OCT6; + } + + if ((*g_song - '0') == '7') + { + octave = OCT7; + } + + if ((*g_song - '0') == '8') + { + octave = OCT8; + } + + g_song++; + + if (*g_song == ',') + { + g_song++; + } + + /* play the sound */ + + freq = ceil(base_freq * octave); + + if (!board_audio_tone_generator(1, -40, freq)) + { + break; + } + + usleep(duration * 1000L); + } + while (*g_song); + + /* Sound off. */ + + if (!board_audio_tone_generator(0, 0, 0)) + { + printf("Error: board_audio_tone_generator() failure.\n"); + return 1; + } + + /* Set I/O parameters for power off. */ + + if (!board_audio_power_control(false)) + { + printf("Error: board_audio_power_control() failure.\n"); + return 1; + } + + printf("Done.\n"); + + return 0; +} diff --git a/interpreters/toywasm/tmpl/license.in b/examples/audio_rttl/audio_rttl.h similarity index 86% rename from interpreters/toywasm/tmpl/license.in rename to examples/audio_rttl/audio_rttl.h index 2f7e88877..4759fb56c 100644 --- a/interpreters/toywasm/tmpl/license.in +++ b/examples/audio_rttl/audio_rttl.h @@ -1,7 +1,5 @@ /**************************************************************************** - * apps/interpreters/toywasm/FILENAME - * - * SPDX-License-Identifier: Apache-2.0 + * apps/examples/audio_rttl/audio_rttl.h * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -20,3 +18,5 @@ * ****************************************************************************/ +FAR char *g_song = (FAR char *) + "Test:d=4,o=6,b=90:c,c#,d,d#,e,f,f#,g,a,a#,b,p,b,a#,a,g,f#,f,e,d#,d,c#,c"; diff --git a/examples/audio_rttl/audio_rttl_main.c b/examples/audio_rttl/audio_rttl_main.c deleted file mode 100644 index 5e9e7e960..000000000 --- a/examples/audio_rttl/audio_rttl_main.c +++ /dev/null @@ -1,305 +0,0 @@ -/**************************************************************************** - * apps/examples/audio_rttl/audio_rttl_main.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <fcntl.h> -#include <getopt.h> -#include <math.h> -#include <stdio.h> -#include <string.h> - -#include <sys/ioctl.h> - -#ifdef CONFIG_PWM -#include <nuttx/timers/pwm.h> -#endif - -#include <audioutils/rtttl.h> - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -struct player_s -{ - void (*play)(struct rtttl_tone); /* Play RTTTL sound function */ - void (*teardown)(void); /* Clean-up function */ - void *arg; /* Private data for functions */ -}; - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/* Default song if none was passed. Otherwise, used as buffer for reading - * from a file. - */ - -static char g_default_song[CONFIG_EXAMPLES_AUDIO_SOUND_MAXLEN] = - "Test:d=4,o=6,b=90:c,c#,d,d#,e,f,f#,g,a,a#,b,p,b,a#,a,g," - "f#,f,e,d#,d,c#,c"; - -/* The selected player is a global variable so it can be accessed from within - * the player functions properly. - */ - -static struct player_s g_player; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: play_default - * - * Description: - * The default player choice; prints an error and exits. - * - * Input Parameters: - * sound - The sound to play - * - ****************************************************************************/ - -static void play_default(struct rtttl_tone sound) -{ - fprintf(stderr, "No player selected!\n"); - return; -} - -/**************************************************************************** - * Name: teardown_default - * - * Description: - * Default tear-down function. Does nothing. - * - ****************************************************************************/ - -static void teardown_default(void) -{ - /* No-op */ - - return; -} - -#ifdef CONFIG_PWM - -/**************************************************************************** - * Name: play_pwm - * - * Description: - * RTTTL player for audio sinks using PWM devices - * - * Input Parameters: - * sound - The sound to play - * - ****************************************************************************/ - -static void play_pwm(struct rtttl_tone sound) -{ - int err; - int i; - struct pwm_info_s info; - int fd = *((int *)g_player.arg); - - info.channels[0].channel = 1; - info.channels[0].duty = b16divi(uitoub16(50) - 1, 100); /* 50% duty cycle */ - info.channels[0].cpol = PWM_CPOL_NDEF; /* Default */ - info.channels[0].dcpol = PWM_DCPOL_NDEF; /* Default */ - info.frequency = sound.frequency_100hz / 100; - - /* Copy settings to all channels */ - - for (i = 1; i < CONFIG_PWM_NCHANNELS; i++) - { - info.channels[i] = info.channels[0]; - info.channels[i].channel = i + 1; - } - - err = ioctl(fd, PWMIOC_SETCHARACTERISTICS, &info); - if (err < 0) - { - fprintf(stderr, "Failed to set PWM characteristics: %d\n", errno); - return; - } - - err = ioctl(fd, PWMIOC_START, 0); - if (err < 0) - { - fprintf(stderr, "Failed to start PWM: %d\n", errno); - return; - } - - usleep(sound.duration_us); /* Wait */ - - err = ioctl(fd, PWMIOC_STOP, 0); - if (err < 0) - { - fprintf(stderr, "Failed to stop PWM: %d\n", errno); - } -} - -/**************************************************************************** - * Name: teardown_pwm - * - * Description: - * Teardown function for PWM players - * - ****************************************************************************/ - -static void teardown_pwm(void) -{ - int fd = *((int *)g_player.arg); - close(fd); -} -#endif /* CONFIG_PWM */ - -/**************************************************************************** - * Name: print_usage - * - * Description: - * Prints out the usage information for the program. - * - * Input Parameters: - * sink - The stream to output the usage information - * - ****************************************************************************/ - -static void print_usage(FILE *sink) -{ - fprintf(sink, "USAGE: audio_rttl <device path> [-s string] [-f file]\n"); - fprintf(sink, "Ex: audio_rttl /dev/tone0\n"); -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -int main(int argc, FAR char *argv[]) -{ - int err; - int fd; - int c; - FILE *fptr; - size_t bread; - const char *song = g_default_song; - const char *device = NULL; - const char *file = NULL; - - g_player.play = play_default; - g_player.teardown = teardown_default; - g_player.arg = NULL; - - while ((c = getopt(argc, argv, ":hs:f:")) != -1) - { - switch (c) - { - case 'h': - print_usage(stdout); - break; - case 's': - song = optarg; - break; - case 'f': - file = optarg; - break; - case '?': - fprintf(stderr, "Unknown option -%c\n", optopt); - print_usage(stderr); - return EXIT_FAILURE; - } - } - - if (argc <= optind) - { - fprintf(stderr, "Missing argument for device path.\n"); - return EXIT_FAILURE; - } - - device = argv[optind++]; - - /* Based on the device path, we choose which player should be used and - * perform the setup. - */ - -#ifdef CONFIG_PWM - if (strstr(device, "pwm")) - { - fd = open(device, O_RDWR); - if (fd < 0) - { - fprintf(stderr, "Failed to open %s: %d\n", device, errno); - return EXIT_FAILURE; - } - else - { - g_player.arg = &fd; - } - - g_player.play = play_pwm; - g_player.teardown = teardown_pwm; - } -#endif /* CONFIG_PWM */ - - /* If the user passed a file and a song string, use the string. Otherwise, - * read from the file - */ - - if (file != NULL && song == g_default_song) - { - fptr = fopen(file, "r"); - if (fptr == NULL) - { - fprintf(stderr, "Couldn't open file '%s': %d", file, errno); - g_player.teardown(); - return EXIT_FAILURE; - } - - bread = - fread(g_default_song, sizeof(char), sizeof(g_default_song), fptr); - - /* Ensure null termination of the string. */ - - if (bread <= sizeof(g_default_song)) - { - g_default_song[bread - 1] = '\0'; - } - - fclose(fptr); - } - - /* Play the song */ - - err = rtttl_play(song, g_player.play); - if (err != 0) - { - fprintf(stderr, "Failed to play song: %d\n", err); - return err; - } - - /* Tear down the player and exit */ - - g_player.teardown(); - return EXIT_SUCCESS; -} diff --git a/examples/baromonitor/CMakeLists.txt b/examples/baromonitor/CMakeLists.txt deleted file mode 100644 index e047922f8..000000000 --- a/examples/baromonitor/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# ############################################################################## -# apps/examples/baromonitor/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_BAROMONITOR) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_BAROMONITOR_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_BAROMONITOR_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_BAROMONITOR_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_BAROMONITOR} - SRCS - baromonitor_main.c) -endif() diff --git a/examples/baromonitor/Kconfig b/examples/baromonitor/Kconfig deleted file mode 100644 index 7ef4f17bc..000000000 --- a/examples/baromonitor/Kconfig +++ /dev/null @@ -1,38 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config EXAMPLES_BAROMONITOR - tristate "Barometer monitoring dashboard example" - default n - depends on UORB - depends on LIBC_FLOATINGPOINT - depends on GRAPHICS_LVGL - depends on LV_USE_NUTTX - depends on LV_FONT_MONTSERRAT_24 - depends on LV_FONT_MONTSERRAT_32 - ---help--- - Enable the barometer monitoring dashboard. - -if EXAMPLES_BAROMONITOR - -config EXAMPLES_BAROMONITOR_PROGNAME - string "Program name" - default "baromonitor" - -config EXAMPLES_BAROMONITOR_PRIORITY - int "Barometer monitor task priority" - default 100 - -config EXAMPLES_BAROMONITOR_STACKSIZE - int "Baromonitor stack size" - default DEFAULT_TASK_STACKSIZE - -config EXAMPLES_BAROMONITOR_SAMPLERATE - int "Sample rate (ms)" - default 50 - ---help--- - Sample rate in milliseconds of barometer data. - -endif # EXAMPLES_BARO_DASHBOARD diff --git a/examples/baromonitor/Make.defs b/examples/baromonitor/Make.defs deleted file mode 100644 index 206ea679f..000000000 --- a/examples/baromonitor/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/examples/baromonitor/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_EXAMPLES_BAROMONITOR),) -CONFIGURED_APPS += $(APPDIR)/examples/baromonitor -endif diff --git a/examples/baromonitor/Makefile b/examples/baromonitor/Makefile deleted file mode 100644 index 8fe37e36f..000000000 --- a/examples/baromonitor/Makefile +++ /dev/null @@ -1,36 +0,0 @@ -############################################################################ -# apps/examples/baromonitor/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -# BAROMONITOR Barometer sensor example built-in application info - -PROGNAME = $(CONFIG_EXAMPLES_BAROMONITOR_PROGNAME) -PRIORITY = $(CONFIG_EXAMPLES_BAROMONITOR_PRIORITY) -STACKSIZE = $(CONFIG_EXAMPLES_BAROMONITOR_STACKSIZE) -MODULE = $(CONFIG_EXAMPLES_BAROMONITOR) - -# BAROMONITOR Barometer sensor example - -MAINSRC = baromonitor_main.c - -include $(APPDIR)/Application.mk diff --git a/examples/baromonitor/baromonitor_main.c b/examples/baromonitor/baromonitor_main.c deleted file mode 100644 index c3a93d6b9..000000000 --- a/examples/baromonitor/baromonitor_main.c +++ /dev/null @@ -1,419 +0,0 @@ -/**************************************************************************** - * apps/examples/baromonitor/baromonitor_main.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <fcntl.h> -#include <stdio.h> -#include <unistd.h> - -#include <uORB/uORB.h> - -#include <lvgl/lvgl.h> - -#include <nuttx/sensors/sensor.h> - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define PRESSURE_COLOUR 0xef4444 -#define TEMPERATURE_COLOUR 0x6366f1 - -#define LINE_WIDTH (8) -#define GAUGE_SIZE (600) - -/* Axis limits */ - -#define PRESS_MIN (960) -#define PRESS_MAX (1010) - -#define TEMP_MIN (-30) -#define TEMP_MAX (60) -#define TEMP_THRESH (TEMP_MAX - 10) - -#define PRESS_MAJOR_TICKS_EVERY (5) -#define TEMP_MAJOR_TICKS_EVERY (5) - -#define NUM_TEMP_LABELS ((TEMP_MAX - TEMP_MIN) / TEMP_MAJOR_TICKS_EVERY) - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static const char *g_temp_labels[NUM_TEMP_LABELS + 1]; -static char g_label_buf[NUM_TEMP_LABELS][8]; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -#ifdef CONFIG_LV_USE_NUTTX_LIBUV -static void lv_nuttx_uv_loop(uv_loop_t *loop, lv_nuttx_result_t *result) -{ - lv_nuttx_uv_t uv_info; - void *data; - - uv_loop_init(loop); - - lv_memset(&uv_info, 0, sizeof(uv_info)); - uv_info.loop = loop; - uv_info.disp = result->disp; - uv_info.indev = result->indev; -#ifdef CONFIG_UINPUT_TOUCH - uv_info.uindev = result->utouch_indev; -#endif - - data = lv_nuttx_uv_init(&uv_info); - uv_run(loop, UV_RUN_DEFAULT); - lv_nuttx_uv_deinit(&data); -} -#endif - -static void set_column_flex(lv_obj_t *obj) -{ - lv_obj_set_flex_flow(obj, LV_FLEX_FLOW_COLUMN); - lv_obj_set_style_flex_main_place(obj, LV_FLEX_ALIGN_CENTER, 0); - lv_obj_set_style_flex_cross_place(obj, LV_FLEX_ALIGN_CENTER, 0); - lv_obj_set_style_flex_track_place(obj, LV_FLEX_ALIGN_CENTER, 0); -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * baromonitor_main - ****************************************************************************/ - -int main(int argc, FAR char *argv[]) -{ - lv_nuttx_dsc_t info; - lv_nuttx_result_t result; - lv_obj_t *screen; - lv_obj_t *gauge_cont; - lv_obj_t *press_gauge; - lv_obj_t *press_line; - lv_obj_t *press_cont; - lv_obj_t *press_label; - lv_obj_t *temp_gauge; - lv_obj_t *temp_line; - lv_obj_t *temp_cont; - lv_obj_t *temp_label; - lv_obj_t *title_cont; - lv_obj_t *title; - lv_scale_section_t *section; - lv_style_t indicator_style; - lv_style_t minor_ticks_style; - lv_style_t main_line_style; - lv_style_t section_label_style; - lv_style_t section_minor_ticks_style; - lv_style_t section_main_line_style; - -#ifdef CONFIG_LV_USE_NUTTX_LIBUV - uv_loop_t ui_loop; -#endif - - int err; - int fd; - bool got_data; - struct sensor_baro sensor_data; - unsigned instance = 0; - char topic[32]; - - if (argc == 2) - { - instance = atoi(argv[1]); - } - - snprintf(topic, sizeof(topic), "sensor_baro%u", instance); - - fd = orb_open("sensor_baro", instance, O_RDONLY | O_NONBLOCK); - if (fd < 0) - { - fprintf(stderr, "Could not open %s: %d\n", topic, errno); - return EXIT_FAILURE; - } - - printf("Subscribed to %s\n", topic); - - /* LVGL setup */ - -#ifdef CONFIG_LV_USE_NUTTX_LIBUV - lv_memzero(&ui_loop, sizeof(ui_loop)); -#endif - - if (!lv_is_initialized()) - { - printf("Initializing LVGL...\n"); - lv_init(); - printf("LVGL initialized...\n"); - } - - lv_nuttx_dsc_init(&info); - lv_nuttx_init(&info, &result); - - if (result.disp == NULL) - { - fprintf(stderr, "Failed to initialize LVGL.\n"); - close(fd); - return EXIT_FAILURE; - } - - /* Set up stuff to render */ - - screen = lv_screen_active(); - set_column_flex(screen); - - /* Create containers for layout. We want a spanning title, followed by two - * side-by-side containers for the gauges. - * - * Gauge container is therefore a ROW flex, while its inner containers are - * column flex (scale followed by a label below) - */ - - title_cont = lv_obj_create(screen); - lv_obj_set_size(title_cont, LV_PCT(100), LV_PCT(10)); - lv_obj_align(title_cont, LV_ALIGN_CENTER, 0, 0); - title = lv_label_create(title_cont); - lv_label_set_text(title, "Barometer monitor"); - lv_obj_set_style_text_font(title, &lv_font_montserrat_32, 0); - lv_obj_align(title, LV_ALIGN_CENTER, 0, 0); - - gauge_cont = lv_obj_create(screen); - lv_obj_set_size(gauge_cont, LV_PCT(100), LV_PCT(90)); - lv_obj_set_flex_flow(gauge_cont, LV_FLEX_FLOW_ROW); - lv_obj_set_style_flex_main_place(gauge_cont, LV_FLEX_ALIGN_CENTER, 0); - lv_obj_set_style_flex_cross_place(gauge_cont, LV_FLEX_ALIGN_CENTER, 0); - lv_obj_set_style_flex_track_place(gauge_cont, LV_FLEX_ALIGN_CENTER, 0); - - press_cont = lv_obj_create(gauge_cont); - temp_cont = lv_obj_create(gauge_cont); - set_column_flex(press_cont); - set_column_flex(temp_cont); - lv_obj_set_size(press_cont, LV_PCT(50), LV_PCT(100)); - lv_obj_set_size(temp_cont, LV_PCT(50), LV_PCT(100)); - - /* TODO: Get the text labels on the gauges to be padded better */ - - /* Pressure gauge */ - - press_gauge = lv_scale_create(press_cont); - - lv_obj_set_size(press_gauge, GAUGE_SIZE, GAUGE_SIZE); - lv_scale_set_mode(press_gauge, LV_SCALE_MODE_ROUND_INNER); - lv_obj_set_style_bg_opa(press_gauge, LV_OPA_COVER, 0); - lv_obj_set_style_bg_color(press_gauge, - lv_palette_lighten(LV_PALETTE_RED, 4), 0); - lv_obj_set_style_radius(press_gauge, LV_RADIUS_CIRCLE, 0); - lv_obj_set_style_clip_corner(press_gauge, true, 0); - lv_obj_set_style_text_font(press_gauge, &lv_font_montserrat_24, 0); - lv_obj_align(press_gauge, LV_ALIGN_LEFT_MID, LV_PCT(5), 0); - - lv_scale_set_label_show(press_gauge, true); - - lv_scale_set_total_tick_count(press_gauge, (PRESS_MAX - PRESS_MIN)); - lv_scale_set_major_tick_every(press_gauge, PRESS_MAJOR_TICKS_EVERY); - - lv_obj_set_style_length(press_gauge, 5, LV_PART_ITEMS); - lv_obj_set_style_length(press_gauge, 10, LV_PART_INDICATOR); - lv_scale_set_range(press_gauge, PRESS_MIN, PRESS_MAX); - - lv_scale_set_angle_range(press_gauge, 270); - lv_scale_set_rotation(press_gauge, 135); - - press_line = lv_line_create(press_gauge); - - lv_obj_set_style_line_width(press_line, LINE_WIDTH, LV_PART_MAIN); - lv_obj_set_style_line_rounded(press_line, true, LV_PART_MAIN); - lv_obj_set_style_line_color(press_line, lv_color_black(), LV_PART_MAIN); - lv_obj_center(press_line); - - /* Temperature gauge */ - - temp_gauge = lv_scale_create(temp_cont); - lv_obj_set_size(temp_gauge, GAUGE_SIZE, GAUGE_SIZE); - lv_scale_set_label_show(temp_gauge, true); - lv_scale_set_mode(temp_gauge, LV_SCALE_MODE_ROUND_OUTER); - lv_obj_align(temp_gauge, LV_ALIGN_RIGHT_MID, LV_PCT(-5), 0); - - lv_scale_set_total_tick_count(temp_gauge, (TEMP_MAX - TEMP_MIN)); - lv_scale_set_major_tick_every(temp_gauge, TEMP_MAJOR_TICKS_EVERY); - lv_obj_set_style_length(temp_gauge, 5, LV_PART_ITEMS); - lv_obj_set_style_length(temp_gauge, 10, LV_PART_INDICATOR); - lv_scale_set_range(temp_gauge, TEMP_MIN, TEMP_MAX); - - lv_scale_set_angle_range(temp_gauge, 270); - lv_scale_set_rotation(temp_gauge, 135); - - temp_line = lv_line_create(temp_gauge); - - lv_obj_set_style_line_width(temp_line, LINE_WIDTH, LV_PART_MAIN); - lv_obj_set_style_line_rounded(temp_line, true, LV_PART_MAIN); - lv_obj_center(temp_line); - - /* Generate labels */ - - for (unsigned i = 0; i < NUM_TEMP_LABELS; i++) - { - snprintf(g_label_buf[i], sizeof(g_label_buf[i]), "%d ยฐC", - TEMP_MIN + i * (TEMP_MAX - TEMP_MIN) / NUM_TEMP_LABELS); - g_temp_labels[i] = (const char *)g_label_buf[i]; - } - - g_temp_labels[NUM_TEMP_LABELS] = NULL; - - lv_scale_set_text_src(temp_gauge, g_temp_labels); - - /* Temp gauge styles */ - - lv_style_init(&indicator_style); - - lv_style_set_text_font(&indicator_style, &lv_font_montserrat_24); - lv_style_set_text_color(&indicator_style, - lv_palette_darken(LV_PALETTE_BLUE, 3)); - - lv_style_set_line_color(&indicator_style, - lv_palette_darken(LV_PALETTE_BLUE, 3)); - lv_style_set_width(&indicator_style, 10U); /* Tick length */ - lv_style_set_line_width(&indicator_style, 2U); /* Tick width */ - lv_obj_add_style(temp_gauge, &indicator_style, LV_PART_INDICATOR); - - lv_style_init(&minor_ticks_style); - lv_style_set_line_color(&minor_ticks_style, - lv_palette_lighten(LV_PALETTE_BLUE, 2)); - lv_style_set_width(&minor_ticks_style, 5U); /* Tick length */ - lv_style_set_line_width(&minor_ticks_style, 2U); /* Tick width */ - lv_obj_add_style(temp_gauge, &minor_ticks_style, LV_PART_ITEMS); - - lv_style_init(&main_line_style); - lv_style_set_arc_color(&main_line_style, - lv_palette_darken(LV_PALETTE_BLUE, 3)); - lv_style_set_arc_width(&main_line_style, 2U); /* Tick width */ - - /* Section on temperature gauge */ - - lv_style_init(§ion_label_style); - lv_style_init(§ion_minor_ticks_style); - lv_style_init(§ion_main_line_style); - - lv_style_set_text_font(§ion_label_style, &lv_font_montserrat_24); - lv_style_set_text_color(§ion_label_style, - lv_palette_darken(LV_PALETTE_RED, 3)); - - lv_style_set_line_color(§ion_label_style, - lv_palette_darken(LV_PALETTE_RED, 3)); - lv_style_set_line_width(§ion_label_style, 5U); /* Tick width */ - - lv_style_set_line_color(§ion_minor_ticks_style, - lv_palette_lighten(LV_PALETTE_RED, 2)); - lv_style_set_line_width(§ion_minor_ticks_style, 4U); /* Tick width */ - - lv_style_set_arc_color(§ion_main_line_style, - lv_palette_darken(LV_PALETTE_RED, 3)); - lv_style_set_arc_width(§ion_main_line_style, 4U); /* Tick width */ - - section = lv_scale_add_section(temp_gauge); - lv_scale_section_set_range(section, TEMP_THRESH, TEMP_MAX); - lv_scale_section_set_style(section, LV_PART_INDICATOR, - §ion_label_style); - lv_scale_section_set_style(section, LV_PART_ITEMS, - §ion_minor_ticks_style); - lv_scale_section_set_style(section, LV_PART_MAIN, - §ion_main_line_style); - - /* Data labels */ - - press_label = lv_label_create(press_cont); - lv_obj_align(press_label, LV_ALIGN_CENTER, 0, 0); - lv_obj_set_style_text_font(press_label, &lv_font_montserrat_24, 0); - temp_label = lv_label_create(temp_cont); - lv_obj_align(temp_label, LV_ALIGN_CENTER, 0, 0); - lv_obj_set_style_text_font(temp_label, &lv_font_montserrat_24, 0); - - /* Main loop */ - -#ifdef CONFIG_LV_USE_NUTTX_LIBUV - lv_nuttx_uv_loop(&ui_loop, &result); -#else - for (; ; ) - { - err = read(fd, &sensor_data, sizeof(sensor_data)); - if (err < 0) - { - fprintf(stderr, "Failed read data from %s: %d\n", topic, errno); - } - else if (err == 0) - { - fprintf(stderr, "No data from %s\n", topic); - } - else - { - got_data = true; - } - - if (got_data) - { - /* Update display if we obtained it successfully */ - - lv_label_set_text_fmt(temp_label, "Temperature: %2.f ยฐC", - sensor_data.temperature); - lv_label_set_text_fmt(press_label, "Pressure: %2.f mbar", - sensor_data.pressure); - - lv_scale_set_line_needle_value(press_gauge, press_line, -10, - (int32_t)sensor_data.pressure); - lv_scale_set_line_needle_value(temp_gauge, temp_line, -10, - (int32_t)sensor_data.temperature); - - if (sensor_data.temperature < TEMP_THRESH) - { - lv_obj_set_style_line_color( - temp_line, lv_palette_darken(LV_PALETTE_BLUE, 3), - LV_PART_MAIN); - } - else - { - lv_obj_set_style_line_color( - temp_line, lv_palette_darken(LV_PALETTE_RED, 3), - LV_PART_MAIN); - } - - got_data = false; /* Reset for next loop */ - } - - lv_timer_handler(); - usleep(CONFIG_EXAMPLES_BAROMONITOR_SAMPLERATE * 1000); - - /* TODO: make this equivalent in LIBUV loop */ - } -#endif - - orb_close(fd); - lv_nuttx_deinit(&result); - lv_deinit(); - return EXIT_SUCCESS; -} diff --git a/examples/bastest/CMakeLists.txt b/examples/bastest/CMakeLists.txt deleted file mode 100644 index 033ec2133..000000000 --- a/examples/bastest/CMakeLists.txt +++ /dev/null @@ -1,44 +0,0 @@ -# ############################################################################## -# apps/examples/bastest/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_BASTEST) - nuttx_add_romfs( - NAME - bastest - PATH - ${CMAKE_CURRENT_LIST_DIR}/test - HEADER - PREFIX - bastest - NONCONST) - - nuttx_add_application( - NAME - bastest - STACKSIZE - ${CONFIG_DEFAULT_TASK_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_BASTEST} - SRCS - bastest_main.c) - -endif() diff --git a/examples/bastest/Make.defs b/examples/bastest/Make.defs index 1ce65d362..269db6609 100644 --- a/examples/bastest/Make.defs +++ b/examples/bastest/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/bastest/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/bastest/Makefile b/examples/bastest/Makefile index ceed0ad3b..58531970d 100644 --- a/examples/bastest/Makefile +++ b/examples/bastest/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/bastest/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/bastest/testcases.md b/examples/bastest/README.md similarity index 90% rename from examples/bastest/testcases.md rename to examples/bastest/README.md index 3e3875714..b4c0bafb0 100644 --- a/examples/bastest/testcases.md +++ b/examples/bastest/README.md @@ -1,3 +1,49 @@ +# Examples / `bastest` Bas BASIC Tests + +This directory contains a small program that will mount a ROMFS file system +containing the BASIC test files extracted from the BAS `2.4` release. + +## Background + +Bas is an interpreter for the classic dialect of the programming language BASIC. +It is pretty compatible to typical BASIC interpreters of the 1980s, unlike some +other UNIX BASIC interpreters, that implement a different syntax, breaking +compatibility to existing programs. Bas offers many ANSI BASIC statements for +structured programming, such as procedures, local variables and various loop +types. Further there are matrix operations, automatic LIST indentation and many +statements and functions found in specific classic dialects. Line numbers are +not required. + +The interpreter tokenises the source and resolves references to variables and +jump targets before running the program. This compilation pass increases +efficiency and catches syntax errors, type errors and references to variables +that are never initialised. Bas is written in ANSI C for UNIX systems. + +## License + +BAS `2.4` is released as part of NuttX under the standard 3-clause BSD license +use by all components of NuttX. This is not incompatible with the original BAS +`2.4` licensing + +Copyright (c) 1999-2014 Michael Haardt + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + # Test Overview ## `test01.bas` diff --git a/examples/bastest/bastest_main.c b/examples/bastest/bastest_main.c index 2397b90c3..4c0deab9e 100644 --- a/examples/bastest/bastest_main.c +++ b/examples/bastest/bastest_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/bastest/bastest_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/battery/CMakeLists.txt b/examples/battery/CMakeLists.txt deleted file mode 100644 index 857a78f10..000000000 --- a/examples/battery/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# ############################################################################## -# apps/examples/battery/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_BATTERY) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_BATTERY_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_BATTERY_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_BATTERY_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_BATTERY} - SRCS - batt_main.c) -endif() diff --git a/examples/battery/Kconfig b/examples/battery/Kconfig index c96e2ec07..3e532d3e6 100644 --- a/examples/battery/Kconfig +++ b/examples/battery/Kconfig @@ -6,7 +6,6 @@ config EXAMPLES_BATTERY tristate "Battery monitor example" default n - depends on BATTERY_CHARGER || BATTERY_GAUGE || BATTERY_MONITOR ---help--- Enable the battery monitor example diff --git a/examples/battery/Make.defs b/examples/battery/Make.defs index eb4247aab..e30f32093 100644 --- a/examples/battery/Make.defs +++ b/examples/battery/Make.defs @@ -1,7 +1,5 @@ ############################################################################ -# apps/examples/battery/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 +# apps/examples/batt/Make.defs # # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with diff --git a/examples/battery/Makefile b/examples/battery/Makefile index 184fdfb5d..6acf63ddf 100644 --- a/examples/battery/Makefile +++ b/examples/battery/Makefile @@ -1,7 +1,5 @@ ############################################################################ -# apps/examples/battery/Makefile -# -# SPDX-License-Identifier: Apache-2.0 +# apps/examples/batt/Makefile # # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with @@ -29,7 +27,7 @@ PRIORITY = $(CONFIG_EXAMPLES_BATTERY_PRIORITY) STACKSIZE = $(CONFIG_EXAMPLES_BATTERY_STACKSIZE) MODULE = $(CONFIG_EXAMPLES_BATTERY) -# Battery Example +# Hello, World! Example MAINSRC = batt_main.c diff --git a/examples/battery/batt_main.c b/examples/battery/batt_main.c index 384d78147..019b381cf 100644 --- a/examples/battery/batt_main.c +++ b/examples/battery/batt_main.c @@ -1,7 +1,5 @@ /**************************************************************************** - * apps/examples/battery/batt_main.c - * - * SPDX-License-Identifier: Apache-2.0 + * apps/examples/batt/batt_main.c * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -31,7 +29,7 @@ #include <stdlib.h> #include <fcntl.h> #include <errno.h> -#include <nuttx/debug.h> +#include <debug.h> #include <nuttx/power/battery_ioctl.h> #include <nuttx/power/battery_charger.h> @@ -39,7 +37,6 @@ /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ - /* Configuration ************************************************************/ #ifndef CONFIG_EXAMPLES_BATTERY_DEVNAME @@ -72,8 +69,7 @@ void status_report(int status) case BATTERY_IDLE: { - printf("Battery is idle, not full, not charging, " - "not discharging!\n"); + printf("Battery is idle, not full, not charging, not discharging!\n"); } break; @@ -117,7 +113,7 @@ void health_report(int health) case BATTERY_HEALTH_GOOD: { - printf("Battery is in good condition!\n"); + printf("Battery is in good condiction!\n"); } break; @@ -198,8 +194,7 @@ int main(int argc, FAR char *argv[]) } printf("Going to read battery info, updated each two seconds.\n"); - printf("Try to remove the board power supply, etc, " - "to change its status.\n"); + printf("Try to remove the board power supply, etc, to change its status.\n"); /* Wait the user read the information message above */ @@ -207,8 +202,7 @@ int main(int argc, FAR char *argv[]) for (i = 0; i < 10; i++) { - printf("\n----------------------------" - "-------------------------------\n"); + printf("\n-----------------------------------------------------------\n"); /* Read battery status */ diff --git a/examples/ble/CMakeLists.txt b/examples/ble/CMakeLists.txt deleted file mode 100644 index 7a01af99d..000000000 --- a/examples/ble/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# ############################################################################## -# apps/examples/ble/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_BLE) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_BLE_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_BLE_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_BLE_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_BLE} - SRCS - ble_main.c) -endif() diff --git a/examples/ble/Kconfig b/examples/ble/Kconfig deleted file mode 100644 index 63618ea4c..000000000 --- a/examples/ble/Kconfig +++ /dev/null @@ -1,37 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config EXAMPLES_BLE - tristate "BLE sensor reading example" - default n - depends on WIRELESS_BLUETOOTH - ---help--- - Enable the BLE example - -if EXAMPLES_BLE - -config EXAMPLES_BLE_PROGNAME - string "Program name" - default "ble" - ---help--- - This is the name of the program that will be used when the NSH ELF - program is installed. - -config EXAMPLES_BLE_PRIORITY - int "BLE task priority" - default 100 - -config EXAMPLES_BLE_STACKSIZE - int "BLE stack size" - default DEFAULT_TASK_STACKSIZE - -config EXAMPLES_BLE_USE_BME680 - bool "Use BME680 sensor data" - default n - depends on SENSORS_BME680 - ---help--- - If enabled, use real BME680 sensor data. If disabled, use dummy data. - -endif diff --git a/examples/ble/Make.defs b/examples/ble/Make.defs deleted file mode 100644 index ddd9bd391..000000000 --- a/examples/ble/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/examples/ble/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_EXAMPLES_BLE),) -CONFIGURED_APPS += $(APPDIR)/examples/ble -endif diff --git a/examples/ble/Makefile b/examples/ble/Makefile deleted file mode 100644 index a2cfd2483..000000000 --- a/examples/ble/Makefile +++ /dev/null @@ -1,41 +0,0 @@ -############################################################################ -# apps/examples/ble/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -# BLE Barometer sensor example built-in application info - -PROGNAME = $(CONFIG_EXAMPLES_BLE_PROGNAME) -PRIORITY = $(CONFIG_EXAMPLES_BLE_PRIORITY) -STACKSIZE = $(CONFIG_EXAMPLES_BLE_STACKSIZE) -MODULE = $(CONFIG_EXAMPLES_BLE) - -CSRCS = ble.c -MAINSRC = ble_main.c - -ifeq ($(CONFIG_EXAMPLES_BLE_USE_BME680),y) - CSRCS += sensors.c -else - CSRCS += dummy.c -endif - -include $(APPDIR)/Application.mk diff --git a/examples/ble/ble.c b/examples/ble/ble.c deleted file mode 100644 index 82bbed5e5..000000000 --- a/examples/ble/ble.c +++ /dev/null @@ -1,250 +0,0 @@ -/**************************************************************************** - * apps/examples/ble/ble.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/wireless/bluetooth/bt_core.h> -#include <nuttx/wireless/bluetooth/bt_gatt.h> -#include <nuttx/wireless/bluetooth/bt_ioctl.h> -#include <netpacket/bluetooth.h> -#include "sensors.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define GASVC 0x0001 -#define NAME_CHR (GASVC + 0x0002) -#define NAME_DSC (GASVC + 0x0003) -#define APPEARANCE_CHR (GASVC + 0x0004) -#define APPEARANCE_DSC (GASVC + 0x0005) -#define SENSOR_SVC (APPEARANCE_DSC + 0x0001) -#define TEMP_CHR (SENSOR_SVC + 0x0001) -#define TEMP_DSC (SENSOR_SVC + 0x0002) -#define HUM_CHR (TEMP_DSC + 0x0001) -#define HUM_DSC (TEMP_DSC + 0x0002) -#define GAS_CHR (HUM_DSC + 0x0001) -#define GAS_DSC (HUM_DSC + 0x0002) -#define PRESS_CHR (GAS_DSC + 0x0001) -#define PRESS_DSC (GAS_DSC + 0x0002) - -/* Bluetooth UUIDs */ - -static struct bt_uuid_s g_gap_uuid = -{ - .type = BT_UUID_16, - .u.u16 = BT_UUID_GAP, -}; - -static struct bt_uuid_s g_device_name_uuid = -{ - .type = BT_UUID_16, - .u.u16 = BT_UUID_GAP_DEVICE_NAME, -}; - -static struct bt_uuid_s g_appearance_uuid = -{ - .type = BT_UUID_16, - .u.u16 = BT_UUID_GAP_APPEARANCE, -}; - -static struct bt_uuid_s g_sensor_uuid = -{ - .type = BT_UUID_128, - .u.u128 = - { - 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, - 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 - } -}; - -static struct bt_uuid_s g_temp_uuid = -{ - .type = BT_UUID_16, - .u.u16 = 0x2a6e, /* Temperature UUID */ -}; - -static struct bt_uuid_s g_hum_uuid = -{ - .type = BT_UUID_16, - .u.u16 = 0x2a6f, /* Humidity UUID */ -}; - -static struct bt_uuid_s g_press_uuid = -{ - .type = BT_UUID_16, - .u.u16 = 0x2a6d, /* Pressure UUID */ -}; - -/* GATT characteristics */ - -static struct bt_gatt_chrc_s g_name_chrc = -{ - .properties = BT_GATT_CHRC_READ, - .value_handle = NAME_DSC, - .uuid = &g_device_name_uuid, -}; - -static struct bt_gatt_chrc_s g_appearance_chrc = -{ - .properties = BT_GATT_CHRC_READ, - .value_handle = APPEARANCE_DSC, - .uuid = &g_appearance_uuid, -}; - -static struct bt_gatt_chrc_s g_temp_chrc = -{ - .properties = BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY, - .value_handle = TEMP_DSC, - .uuid = &g_temp_uuid, -}; - -static struct bt_gatt_chrc_s g_hum_chrc = -{ - .properties = BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY, - .value_handle = HUM_DSC, - .uuid = &g_hum_uuid, -}; - -static struct bt_gatt_chrc_s g_press_chrc = -{ - .properties = BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY, - .value_handle = PRESS_DSC, - .uuid = &g_press_uuid, -}; - -static int read_name(FAR struct bt_conn_s *conn, - FAR const struct bt_gatt_attr_s *attr, - FAR void *buf, uint8_t len, uint16_t offset) -{ - const char *name = CONFIG_DEVICE_NAME; - return bt_gatt_attr_read(conn, attr, buf, len, offset, name, strlen(name)); -} - -static int read_appearance(FAR struct bt_conn_s *conn, - FAR const struct bt_gatt_attr_s *attr, - FAR void *buf, uint8_t len, uint16_t offset) -{ - uint16_t appearance = 0; /* Set appropriate appearance value */ - return bt_gatt_attr_read(conn, attr, buf, len, offset, - &appearance, sizeof(appearance)); -} - -static int read_temperature(FAR struct bt_conn_s *conn, - FAR const struct bt_gatt_attr_s *attr, - FAR void *buf, uint8_t len, uint16_t offset) -{ - uint16_t temp = (uint16_t) (get_temperature() * 100); - return bt_gatt_attr_read(conn, attr, buf, len, offset, - &temp, sizeof(uint16_t)); -} - -static int read_humidity(FAR struct bt_conn_s *conn, - FAR const struct bt_gatt_attr_s *attr, - FAR void *buf, uint8_t len, uint16_t offset) -{ - uint16_t hum = (uint16_t) (get_humidity() * 100); - return bt_gatt_attr_read(conn, attr, buf, len, offset, - &hum, sizeof(uint16_t)); -} - -static int read_gas(FAR struct bt_conn_s *conn, - FAR const struct bt_gatt_attr_s *attr, - FAR void *buf, uint8_t len, uint16_t offset) -{ - uint16_t gas = (uint16_t) (get_gas_resistance() * 100); - return bt_gatt_attr_read(conn, attr, buf, len, offset, - &gas, sizeof(uint16_t)); -} - -static int read_pressure(FAR struct bt_conn_s *conn, - FAR const struct bt_gatt_attr_s *attr, - FAR void *buf, uint8_t len, uint16_t offset) -{ - uint32_t press = (uint32_t) (get_pressure() * 1000); - return bt_gatt_attr_read(conn, attr, buf, len, offset, - &press, sizeof(uint32_t)); -} - -/* GATT attributes */ - -static const struct bt_gatt_attr_s attrs[] = -{ - BT_GATT_PRIMARY_SERVICE(GASVC, &g_gap_uuid), - BT_GATT_CHARACTERISTIC(NAME_CHR, &g_name_chrc), - BT_GATT_DESCRIPTOR(NAME_DSC, &g_device_name_uuid, BT_GATT_PERM_READ, - read_name, NULL, NULL), - BT_GATT_CHARACTERISTIC(APPEARANCE_CHR, &g_appearance_chrc), - BT_GATT_DESCRIPTOR(APPEARANCE_DSC, &g_appearance_uuid, - BT_GATT_PERM_READ, read_appearance, NULL, NULL), - - BT_GATT_PRIMARY_SERVICE(SENSOR_SVC, &g_sensor_uuid), - BT_GATT_CHARACTERISTIC(TEMP_CHR, &g_temp_chrc), - BT_GATT_DESCRIPTOR(TEMP_DSC, &g_temp_uuid, BT_GATT_PERM_READ, - read_temperature, NULL, NULL), - BT_GATT_CHARACTERISTIC(HUM_CHR, &g_hum_chrc), - BT_GATT_DESCRIPTOR(HUM_DSC, &g_hum_uuid, BT_GATT_PERM_READ, - read_humidity, NULL, NULL), - BT_GATT_CHARACTERISTIC(PRESS_CHR, &g_press_chrc), - BT_GATT_DESCRIPTOR(PRESS_DSC, &g_press_uuid, BT_GATT_PERM_READ, - read_pressure, NULL, NULL), -}; - -static void start_scanning(void) -{ - struct btreq_s btreq; - memset(&btreq, 0, sizeof(struct btreq_s)); - strlcpy(btreq.btr_name, "bnep0", 16); - btreq.btr_dupenable = false; - - int sockfd = socket(PF_BLUETOOTH, SOCK_RAW, BTPROTO_L2CAP); - if (sockfd < 0) - { - fprintf(stderr, "ERROR: failed to create socket\n"); - return; - } - int ret = ioctl(sockfd, SIOCBTSCANSTART, - (unsigned long)((uintptr_t)&btreq)); - if (ret < 0) - { - fprintf(stderr, "ERROR: ioctl(SIOCBTSCANSTART) failed\n"); - } - close(sockfd); -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * setup_ble - ****************************************************************************/ - -void setup_ble(void) -{ - /* Scanning is enabled here to ensure advertising packets are sent. */ - - start_scanning(); - bt_gatt_register(attrs, nitems(attrs)); -} diff --git a/examples/ble/ble_main.c b/examples/ble/ble_main.c deleted file mode 100644 index 7afb2eedd..000000000 --- a/examples/ble/ble_main.c +++ /dev/null @@ -1,70 +0,0 @@ -/**************************************************************************** - * apps/examples/ble/ble_main.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> -#include <pthread.h> -#include "sensors.h" - -extern void setup_ble(void); - -#define STACKSIZE 2048 - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * ble_main - ****************************************************************************/ - -int main(int argc, FAR char *argv[]) -{ - int ret; - - init_sensors(); - setup_ble(); - - pthread_t thread; - pthread_attr_t attr; - struct sched_param param; - - pthread_attr_init(&attr); - pthread_attr_setstacksize(&attr, STACKSIZE); - param.sched_priority = SCHED_PRIORITY_DEFAULT; - pthread_attr_setschedparam(&attr, ¶m); - - ret = pthread_create(&thread, &attr, monitor_sensors, NULL); - if (ret != 0) - { - printf("Error: pthread_create failed: %d\n", ret); - return 1; - } - - pthread_join(thread, NULL); - - close_sensors_fd(); - return 0; -} diff --git a/examples/ble/dummy.c b/examples/ble/dummy.c deleted file mode 100644 index 528c3a5b6..000000000 --- a/examples/ble/dummy.c +++ /dev/null @@ -1,90 +0,0 @@ -/**************************************************************************** - * apps/examples/ble/dummy.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to you under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "sensors.h" - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/* Returns a dummy temperature value */ - -float get_temperature(void) -{ - return 40; -} - -/* Returns a dummy pressure value */ - -float get_pressure(void) -{ - return 1000; -} - -/* Returns a dummy gas resistance value */ - -float get_gas_resistance(void) -{ - return 100; -} - -/* Returns a dummy humidity value */ - -float get_humidity(void) -{ - return 30; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/* Monitors sensors indefinitely (dummy implementation) */ - -void *monitor_sensors(void *arg) -{ - (void)arg; - while (1) - { - /* Infinite loop as a placeholder */ - } - - return NULL; -} - -/* Initializes sensors (dummy implementation) */ - -int init_sensors(void) -{ - return 0; -} - -/* Closes sensor file descriptors (dummy implementation) */ - -void close_sensors_fd(void) -{ - return; -} diff --git a/examples/ble/sensors.c b/examples/ble/sensors.c deleted file mode 100644 index 85aed45aa..000000000 --- a/examples/ble/sensors.c +++ /dev/null @@ -1,206 +0,0 @@ -/**************************************************************************** - * apps/examples/ble/sensors.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to you under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/sensors/sensor.h> -#include <nuttx/sensors/bme680.h> -#include "sensors.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define NB_LOWERHALFS 3 - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static struct pollfd pfds[NB_LOWERHALFS]; -static int baro_fd; -static int hum_fd; -static int gas_fd; - -static struct sensor_baro baro_data; -static struct sensor_humi humi_data; -static struct sensor_gas gas_data; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/* Returns the current temperature value */ - -float get_temperature(void) -{ - return baro_data.temperature; -} - -/* Returns the current pressure value */ - -float get_pressure(void) -{ - return baro_data.pressure; -} - -/* Returns the current gas resistance value */ - -float get_gas_resistance(void) -{ - return gas_data.gas_resistance; -} - -/* Returns the current humidity value */ - -float get_humidity(void) -{ - return humi_data.humidity; -} - -/* Reads the barometer sensor data */ - -static void read_barometer(void) -{ - int ret = read(baro_fd, &baro_data, sizeof(struct sensor_baro)); - if (ret != sizeof(struct sensor_baro)) - { - perror("Could not read temperature"); - } -} - -/* Reads the humidity sensor data */ - -static void read_humidity(void) -{ - int ret = read(hum_fd, &humi_data, sizeof(struct sensor_humi)); - if (ret != sizeof(struct sensor_humi)) - { - perror("Could not read humidity"); - } -} - -/* Reads the gas sensor data */ - -static void read_gas(void) -{ - int ret = read(gas_fd, &gas_data, sizeof(struct sensor_gas)); - if (ret != sizeof(struct sensor_gas)) - { - perror("Could not read gas resistance"); - } -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/* Monitors sensor data and outputs periodically */ - -void *monitor_sensors(void *arg) -{ - while (1) - { - int ret = poll(pfds, NB_LOWERHALFS, -1); - if (ret < 0) - { - perror("Could not poll sensor."); - return NULL; - } - - read_barometer(); - read_humidity(); - read_gas(); - - printf("Temperature [C] = %f\n" - "Pressure [hPa] = %f\n" - "Humidity [rH] = %f\n" - "Gas resistance [kOhm] = %f\n", - baro_data.temperature, baro_data.pressure, - humi_data.humidity, gas_data.gas_resistance); - - sleep(1); - } - - return NULL; -} - -/* Initializes sensors and configures them */ - -int init_sensors(void) -{ - baro_fd = open("/dev/uorb/sensor_baro0", O_RDONLY | O_NONBLOCK); - if (baro_fd < 0) - { - printf("Failed to open barometer lowerhalf.\n"); - return -1; - } - - hum_fd = open("/dev/uorb/sensor_humi0", O_RDONLY | O_NONBLOCK); - if (hum_fd < 0) - { - printf("Failed to open humidity sensor lowerhalf.\n"); - return -1; - } - - gas_fd = open("/dev/uorb/sensor_gas0", O_RDONLY | O_NONBLOCK); - if (gas_fd < 0) - { - printf("Failed to open gas lowerhalf.\n"); - return -1; - } - - pfds[0].fd = baro_fd; - pfds[1].fd = hum_fd; - pfds[2].fd = gas_fd; - pfds[0].events = pfds[1].events = pfds[2].events = POLLIN; - - struct bme680_config_s config; - config.temp_os = BME680_OS_2X; - config.press_os = BME680_OS_16X; - config.filter_coef = BME680_FILTER_COEF3; - config.hum_os = BME680_OS_1X; - config.target_temp = 300; - config.amb_temp = 30; - config.heater_duration = 100; - config.nb_conv = 0; - - int ret = ioctl(baro_fd, SNIOC_CALIBRATE, &config); - if (ret < 0) - { - perror("Failed to configure sensor"); - return -1; - } - - return 0; -} - -/* Closes sensor file descriptors */ - -void close_sensors_fd(void) -{ - close(baro_fd); - close(hum_fd); - close(gas_fd); -} diff --git a/examples/ble/sensors.h b/examples/ble/sensors.h deleted file mode 100644 index 9d6defe70..000000000 --- a/examples/ble/sensors.h +++ /dev/null @@ -1,64 +0,0 @@ -/**************************************************************************** - * apps/examples/ble/sensors.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to you under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <fcntl.h> -#include <poll.h> -#include <unistd.h> -#include <sys/ioctl.h> -#include <time.h> -#include <stdio.h> - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/* Retrieves the current temperature */ - -float get_temperature(void); - -/* Retrieves the current atmospheric pressure */ - -float get_pressure(void); - -/* Retrieves the current gas resistance */ - -float get_gas_resistance(void); - -/* Retrieves the current humidity */ - -float get_humidity(void); - -/* Monitors sensors in a continuous loop */ - -void *monitor_sensors(void *arg); - -/* Initializes the sensors */ - -int init_sensors(void); - -/* Closes the sensors' file descriptors */ - -void close_sensors_fd(void); diff --git a/examples/bme680/CMakeLists.txt b/examples/bme680/CMakeLists.txt deleted file mode 100644 index 9b151abaa..000000000 --- a/examples/bme680/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# ############################################################################## -# apps/examples/bme680/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_BME680) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_BME680_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_BME680_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_BME680_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_BME680} - SRCS - bme680_main.c) -endif() diff --git a/examples/bme680/Kconfig b/examples/bme680/Kconfig deleted file mode 100644 index 3b32f1844..000000000 --- a/examples/bme680/Kconfig +++ /dev/null @@ -1,30 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config EXAMPLES_BME680 - tristate "BME680 sensor example" - default n - depends on SENSORS_BME680 - ---help--- - Enable the BME680 example - -if EXAMPLES_BME680 - -config EXAMPLES_BME680_PROGNAME - string "Program name" - default "bme680" - ---help--- - This is the name of the program that will be used when the NSH ELF - program is installed. - -config EXAMPLES_BME680_PRIORITY - int "BME680 task priority" - default 100 - -config EXAMPLES_BME680_STACKSIZE - int "BME680 stack size" - default DEFAULT_TASK_STACKSIZE - -endif diff --git a/examples/bme680/Make.defs b/examples/bme680/Make.defs deleted file mode 100644 index d4c3c6a9d..000000000 --- a/examples/bme680/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/examples/bme680/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_EXAMPLES_BME680),) -CONFIGURED_APPS += $(APPDIR)/examples/bme680 -endif diff --git a/examples/bme680/Makefile b/examples/bme680/Makefile deleted file mode 100644 index fd5240c31..000000000 --- a/examples/bme680/Makefile +++ /dev/null @@ -1,36 +0,0 @@ -############################################################################ -# apps/examples/bme680/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -# BME680 Barometer sensor example built-in application info - -PROGNAME = $(CONFIG_EXAMPLES_BME680_PROGNAME) -PRIORITY = $(CONFIG_EXAMPLES_BME680_PRIORITY) -STACKSIZE = $(CONFIG_EXAMPLES_BME680_STACKSIZE) -MODULE = $(CONFIG_EXAMPLES_BME680) - -# BME680 Barometer sensor example - -MAINSRC = bme680_main.c - -include $(APPDIR)/Application.mk diff --git a/examples/bme680/bme680_main.c b/examples/bme680/bme680_main.c deleted file mode 100644 index d0e626f01..000000000 --- a/examples/bme680/bme680_main.c +++ /dev/null @@ -1,178 +0,0 @@ -/**************************************************************************** - * apps/examples/bme680/bme680_main.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> -#include <nuttx/sensors/sensor.h> -#include <nuttx/sensors/bme680.h> -#include <stdio.h> -#include <fcntl.h> -#include <poll.h> -#include <unistd.h> -#include <sys/ioctl.h> -#include <time.h> - -#define NB_LOWERHALFS 3 - -/* Structure used when polling the sub-sensors */ - -struct data -{ - void *data_struct; - uint16_t data_size; -}; - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * bme680_main - ****************************************************************************/ - -int main(int argc, FAR char *argv[]) -{ - int baro_fd; - int hum_fd; - int gas_fd; - uint16_t seconds; - int ret; - - /* This example works when all of the sub-sensors of - * the BME680 are enabled. - */ - - struct sensor_baro baro_data; - struct sensor_humi humi_data; - struct sensor_gas gas_data; - - /* Open each lowerhalf file to be able to read the data. - * When the pressure measurement is deactivated, sensor_temp0 should - * be opened instead (to get the temperature measurement). - */ - - baro_fd = open("/dev/uorb/sensor_baro0", O_RDONLY | O_NONBLOCK); - if (baro_fd < 0) - { - printf("Failed to open barometer lowerhalf.\n"); - return -1; - } - - hum_fd = open("/dev/uorb/sensor_humi0", O_RDONLY | O_NONBLOCK); - if (hum_fd < 0) - { - printf("Failed to open humidity sensor lowerhalf.\n"); - return -1; - } - - gas_fd = open("/dev/uorb/sensor_gas0", O_RDONLY | O_NONBLOCK); - if (gas_fd < 0) - { - printf("Failed to open gas lowerhalf.\n"); - return -1; - } - - /* Configure the sensor */ - - struct bme680_config_s config; - - /* Set oversampling */ - - config.temp_os = BME680_OS_2X; - config.press_os = BME680_OS_16X; - config.filter_coef = BME680_FILTER_COEF3; - config.hum_os = BME680_OS_1X; - - /* Set heater parameters */ - - config.target_temp = 300; /* degrees Celsius */ - config.amb_temp = 30; /* degrees Celsius */ - config.heater_duration = 100; /* milliseconds */ - - config.nb_conv = 0; - - ret = ioctl(baro_fd, SNIOC_CALIBRATE, &config); - - struct pollfd pfds[] = { - {.fd = baro_fd, .events = POLLIN}, - {.fd = hum_fd, .events = POLLIN}, - {.fd = gas_fd, .events = POLLIN} - }; - - struct data sensor_data[] = { - {.data_struct = &baro_data, .data_size = sizeof(struct sensor_baro)}, - {.data_struct = &humi_data, .data_size = sizeof(struct sensor_humi)}, - {.data_struct = &gas_data, .data_size = sizeof(struct sensor_gas)} - }; - - seconds = 5 * 60; - - /* Wait ~5 minutes for the sensor to accomodate to the surroundings. - * The first measurements are not accurate. The longer the wait, the more - * accurate the results are. - */ - - while (seconds > 0) - { - ret = poll(pfds, NB_LOWERHALFS, -1); - if (ret < 0) - { - perror("Could not poll sensor."); - return ret; - } - - /* Go through lowerhalfs and read the data */ - - for (int i = 0; i < NB_LOWERHALFS; i++) - { - if (pfds[i].revents & POLLIN) - { - ret = read(pfds[i].fd, sensor_data[i].data_struct, - sensor_data[i].data_size); - - if (ret != sensor_data[i].data_size) - { - perror("Could not read from sub-sensor."); - return ret; - } - } - } - - seconds -= 3; - } - - printf("Temperature [C] = %f\n" - "Pressure [hPa] = %f\n" - "Humidity [rH] = %f\n" - "Gas resistance [kOhm] = %f\n", - baro_data.temperature, baro_data.pressure, - humi_data.humidity, gas_data.gas_resistance); - - close(baro_fd); - close(hum_fd); - close(gas_fd); - - return 0; -} diff --git a/examples/bmi160/CMakeLists.txt b/examples/bmi160/CMakeLists.txt deleted file mode 100644 index a21a690bb..000000000 --- a/examples/bmi160/CMakeLists.txt +++ /dev/null @@ -1,38 +0,0 @@ -# ############################################################################## -# apps/examples/bmi160/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_SIXAXIS) - if(CONFIG_EXAMPLES_SIXAXIS_UORB) - set(CSRC sixaxis_main.c) - else() - set(CSRC sixaxis_uorb_main.c) - endif() - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_SIXAXIS_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_SIXAXIS_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_SIXAXIS_STACKSIZE} - SRCS - ${CSRC}) -endif() diff --git a/examples/bmi160/Kconfig b/examples/bmi160/Kconfig index 1d93fdecc..c84b3afda 100644 --- a/examples/bmi160/Kconfig +++ b/examples/bmi160/Kconfig @@ -6,20 +6,11 @@ config EXAMPLES_SIXAXIS bool "BMI160 sensor example" default n - depends on SENSORS_BMI160 ---help--- Enable the 6 axis sensor example if EXAMPLES_SIXAXIS -config EXAMPLES_SIXAXIS_UORB - bool "BMI160 sensor uorb example" - default n - depends on SENSORS_BMI160_UORB - ---help--- - Enables Work with the UORB or Character Device interface. - If not set, the Character Device is used by default. - config EXAMPLES_SIXAXIS_PROGNAME string "Program name" default "sixaxis" diff --git a/examples/bmi160/Make.defs b/examples/bmi160/Make.defs index 48c25caa9..99413d2ab 100644 --- a/examples/bmi160/Make.defs +++ b/examples/bmi160/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/bmi160/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -20,6 +18,6 @@ # ############################################################################ -ifneq ($(CONFIG_EXAMPLES_SIXAXIS),) +ifeq ($(CONFIG_EXAMPLES_SIXAXIS),y) CONFIGURED_APPS += examples/bmi160 endif diff --git a/examples/bmi160/Makefile b/examples/bmi160/Makefile index 27789bd39..e71a4207c 100644 --- a/examples/bmi160/Makefile +++ b/examples/bmi160/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/bmi160/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -21,6 +19,7 @@ ############################################################################ include $(APPDIR)/Make.defs +-include $(SDKDIR)/Make.defs # sixaxis built-in application info @@ -30,10 +29,6 @@ STACKSIZE = $(CONFIG_EXAMPLES_SIXAXIS_STACKSIZE) # sixaxis Example -ifeq ($(CONFIG_EXAMPLES_SIXAXIS_UORB),) MAINSRC = sixaxis_main.c -else -MAINSRC = sixaxis_uorb_main.c -endif include $(APPDIR)/Application.mk diff --git a/examples/bmi160/sixaxis_main.c b/examples/bmi160/sixaxis_main.c index bded1ead1..93323455f 100644 --- a/examples/bmi160/sixaxis_main.c +++ b/examples/bmi160/sixaxis_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/bmi160/sixaxis_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -28,7 +26,6 @@ #include <inttypes.h> #include <fcntl.h> #include <stdio.h> -#include <unistd.h> #include <nuttx/sensors/bmi160.h> diff --git a/examples/bmi160/sixaxis_uorb_main.c b/examples/bmi160/sixaxis_uorb_main.c deleted file mode 100644 index 2d9143eb8..000000000 --- a/examples/bmi160/sixaxis_uorb_main.c +++ /dev/null @@ -1,93 +0,0 @@ -/**************************************************************************** - * apps/examples/bmi160/sixaxis_uorb_main.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <poll.h> -#include <errno.h> -#include <sensor/accel.h> - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define ACC_TIMEOUT 1000 -#define READ_TIMES 100 - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * sixaxis_main - ****************************************************************************/ - -int main(int argc, FAR char *argv[]) -{ - FAR const struct orb_metadata *meta; - struct sensor_accel accel_data; - struct pollfd fds; - int ret = OK; - int fd; - int i; - - meta = ORB_ID(sensor_accel_uncal); - fd = orb_subscribe_multi(meta, 0); - if (fd < 0) - { - printf("sensor accel subscribe error! return:%d\n", fd); - return fd; - } - - fds.fd = fd; - fds.events = POLLIN; - - for (i = 0; i < READ_TIMES; i++) - { - if (poll(&fds, 1, ACC_TIMEOUT) > 0) - { - if (fds.revents & POLLIN) - { - ret = orb_copy(meta, fd, &accel_data); -#ifdef CONFIG_DEBUG_UORB - if (ret == OK && meta->o_format != NULL) - { - orb_info(meta->o_format, meta->o_name, &accel_data); - } -#endif - } - } - else if (errno != EINTR) - { - printf("Waited for %d milliseconds without a message. " - "Giving up. err:%d", ACC_TIMEOUT, errno); - break; - } - } - - orb_unsubscribe(fd); - printf("sensor accel read examples exit.\n"); - - return ret; -} diff --git a/examples/bmp180/CMakeLists.txt b/examples/bmp180/CMakeLists.txt deleted file mode 100644 index 814a5c896..000000000 --- a/examples/bmp180/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# ############################################################################## -# apps/examples/bmp180/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_BMP180) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_BMP180_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_BMP180_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_BMP180_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_BMP180} - SRCS - bmp180_main.c) -endif() diff --git a/examples/bmp180/Kconfig b/examples/bmp180/Kconfig index f2b63ac87..19e778af9 100644 --- a/examples/bmp180/Kconfig +++ b/examples/bmp180/Kconfig @@ -4,11 +4,11 @@ # config EXAMPLES_BMP180 - tristate "BMP180 Barometer sensor example" + tristate "BMP180/280 Barometer sensor example" default n - depends on SENSORS_BMP180 + depends on SENSORS_BMP180 || SENSORS_BMP280 ---help--- - Enable the BMP180 example + Enable the BMP180/BMP280 example if EXAMPLES_BMP180 diff --git a/examples/bmp180/Make.defs b/examples/bmp180/Make.defs index 182d14940..536fbb2af 100644 --- a/examples/bmp180/Make.defs +++ b/examples/bmp180/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/bmp180/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/bmp180/Makefile b/examples/bmp180/Makefile index acdae3da2..d67c98f27 100644 --- a/examples/bmp180/Makefile +++ b/examples/bmp180/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/bmp180/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/bmp180/bmp180_main.c b/examples/bmp180/bmp180_main.c index 69c467cf0..0b5b98c23 100644 --- a/examples/bmp180/bmp180_main.c +++ b/examples/bmp180/bmp180_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/bmp180/bmp180_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/bmp280/CMakeLists.txt b/examples/bmp280/CMakeLists.txt deleted file mode 100644 index 6d45eb525..000000000 --- a/examples/bmp280/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# ############################################################################## -# apps/examples/bmp280/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_BMP280) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_BMP280_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_BMP280_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_BMP280_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_BMP280} - SRCS - bmp280_main.c) -endif() diff --git a/examples/bmp280/Kconfig b/examples/bmp280/Kconfig deleted file mode 100644 index 4229d9c23..000000000 --- a/examples/bmp280/Kconfig +++ /dev/null @@ -1,30 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config EXAMPLES_BMP280 - tristate "BMP280 Barometer sensor example" - default n - depends on SENSORS_BMP280 - ---help--- - Enable the BMP280 example - -if EXAMPLES_BMP280 - -config EXAMPLES_BMP280_PROGNAME - string "Program name" - default "bmp280" - ---help--- - This is the name of the program that will be used when the NSH ELF - program is installed. - -config EXAMPLES_BMP280_PRIORITY - int "BMP280 task priority" - default 100 - -config EXAMPLES_BMP280_STACKSIZE - int "BMP280 stack size" - default DEFAULT_TASK_STACKSIZE - -endif diff --git a/examples/bmp280/Make.defs b/examples/bmp280/Make.defs deleted file mode 100644 index 0f7ee54cf..000000000 --- a/examples/bmp280/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/examples/bmp280/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_EXAMPLES_BMP280),) -CONFIGURED_APPS += $(APPDIR)/examples/bmp280 -endif diff --git a/examples/bmp280/Makefile b/examples/bmp280/Makefile deleted file mode 100644 index bda4bb881..000000000 --- a/examples/bmp280/Makefile +++ /dev/null @@ -1,36 +0,0 @@ -############################################################################ -# apps/examples/bmp280/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -# BMP280 Barometer sensor example built-in application info - -PROGNAME = $(CONFIG_EXAMPLES_BMP280_PROGNAME) -PRIORITY = $(CONFIG_EXAMPLES_BMP280_PRIORITY) -STACKSIZE = $(CONFIG_EXAMPLES_BMP280_STACKSIZE) -MODULE = $(CONFIG_EXAMPLES_BMP280) - -# BMP280 Barometer sensor example - -MAINSRC = bmp280_main.c - -include $(APPDIR)/Application.mk diff --git a/examples/bmp280/bmp280_main.c b/examples/bmp280/bmp280_main.c deleted file mode 100644 index 1b8fdde88..000000000 --- a/examples/bmp280/bmp280_main.c +++ /dev/null @@ -1,65 +0,0 @@ -/**************************************************************************** - * apps/examples/bmp280/bmp280_main.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> -#include <stdio.h> -#include <fcntl.h> -#include <unistd.h> -#include <nuttx/sensors/sensor.h> - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * bmp280_main - ****************************************************************************/ - -int main(int argc, FAR char *argv[]) -{ - int fd; - int ret; - struct sensor_baro sensor_data; - - fd = open("/dev/uorb/sensor_baro0", O_RDONLY | O_NONBLOCK); - if (fd < 0) - { - printf("Failed to open BMP280 sensor"); - return EXIT_FAILURE; - } - - ret = read(fd, &sensor_data, sizeof(sensor_data)); - if (ret != sizeof(sensor_data)) - { - perror("Could not read"); - return EXIT_FAILURE; - } - - printf("Absolute pressure [hPa] = %f\n", sensor_data.pressure); - printf("Temperature [C] = %f\n", sensor_data.temperature); - - return EXIT_SUCCESS; -} diff --git a/examples/bridge/CMakeLists.txt b/examples/bridge/CMakeLists.txt deleted file mode 100644 index 02d0b58fa..000000000 --- a/examples/bridge/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -# ############################################################################## -# apps/examples/bridge/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_BRIDGE) - nuttx_add_application(NAME bridge) -endif() diff --git a/examples/bridge/Make.defs b/examples/bridge/Make.defs index deff70d1d..74bac5731 100644 --- a/examples/bridge/Make.defs +++ b/examples/bridge/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/bridge/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/bridge/Makefile b/examples/bridge/Makefile index c5d73e594..63b8ce165 100644 --- a/examples/bridge/Makefile +++ b/examples/bridge/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/bridge/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/bridge/bridge_main.c b/examples/bridge/bridge_main.c index 183ccedbe..d7a6885cf 100644 --- a/examples/bridge/bridge_main.c +++ b/examples/bridge/bridge_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/bridge/bridge_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -29,18 +27,18 @@ #include <stdlib.h> #include <sched.h> #include <errno.h> -#include <nuttx/debug.h> -#include <unistd.h> +#include <debug.h> #include <net/if.h> #include <arpa/inet.h> #include <netinet/in.h> -#include <nuttx/net/ip.h> +#include <nuttx/net/arp.h> #include "netutils/netlib.h" #if defined(CONFIG_EXAMPLES_BRIDGE_NET1_DHCPC) || \ defined(CONFIG_EXAMPLES_BRIDGE_NET2_DHCPC) +# include <arpa/inet.h> # include "netutils/dhcpc.h" #endif @@ -80,8 +78,6 @@ static int briget_net1_setup(void) #ifdef CONFIG_EXAMPLES_BRIDGE_NET1_DHCPC struct dhcpc_state ds; void *handle; - char inetaddr[INET_ADDRSTRLEN]; - int ret; #endif printf("NET1: Configuring %s\n", CONFIG_EXAMPLES_BRIDGE_NET1_IFNAME); @@ -163,22 +159,13 @@ static int briget_net1_setup(void) &ds.default_router); } - for (int i = 0; i < ds.num_dnsaddr; i++) + if (ds.dnsaddr.s_addr != 0) { - if (ds.dnsaddr[i].s_addr != 0) - { - ret = netlib_set_ipv4dnsaddr(&ds.dnsaddr[i]); - if (ret < 0) - { - nerr("NET1 ERROR: Set DNS server %d:%s address failed: %d\n", - i, inet_ntoa(ds.dnsaddr[i]), ret); - } - } + netlib_set_ipv4dnsaddr(&ds.dnsaddr); } dhcpc_close(handle); - printf("NET1: Assigned IP: %s\n", - net_ntoa_r(ds.ipaddr, inetaddr, sizeof(inetaddr))); + printf("NET1: Assigned IP: %s\n", inet_ntoa(ds.ipaddr)); /* Save the IP address in network order */ @@ -221,8 +208,6 @@ static int briget_net2_setup(void) #ifdef CONFIG_EXAMPLES_BRIDGE_NET2_DHCPC struct dhcpc_state ds; void *handle; - char inetaddr[INET_ADDRSTRLEN]; - int ret; #endif printf("NET2: Configuring %s\n", CONFIG_EXAMPLES_BRIDGE_NET2_IFNAME); @@ -298,22 +283,13 @@ static int briget_net2_setup(void) &ds.default_router); } - for (int i = 0; i < ds.num_dnsaddr; i++) + if (ds.dnsaddr.s_addr != 0) { - if (ds.dnsaddr[i].s_addr != 0) - { - ret = netlib_set_ipv4dnsaddr(&ds.dnsaddr[i]); - if (ret < 0) - { - nerr("NET2 ERROR: Set DNS server %d:%s address failed: %d\n", - i, inet_ntoa(ds.dnsaddr[i]), ret); - } - } + netlib_set_ipv4dnsaddr(&ds.dnsaddr); } dhcpc_close(handle); - printf("NET1: Assigned IP: %s\n", - inet_ntoa_r(ds.ipaddr, inetaddr, sizeof(inetaddr))); + printf("NET1: Assigned IP: %s\n", inet_ntoa(ds.ipaddr)); /* Save the IP address in network order */ @@ -348,6 +324,7 @@ static int bridge_net1_worker(int argc, char *argv[]) struct sockaddr_in fromaddr; struct sockaddr_in toaddr; socklen_t addrlen; + in_addr_t tmpaddr; ssize_t nrecvd; ssize_t nsent; int optval; @@ -358,16 +335,13 @@ static int bridge_net1_worker(int argc, char *argv[]) /* Create a UDP receive socket on network 1 */ - receiver.sin_family = AF_INET; - receiver.sin_port = htons(CONFIG_EXAMPLES_BRIDGE_NET1_RECVPORT); - receiver.sin_addr.s_addr = g_net1_ipaddr; - - printf("NET1: Create receive socket: %u.%u.%u.%u:%u\n", - ip4_addr1(receiver.sin_addr.s_addr), - ip4_addr2(receiver.sin_addr.s_addr), - ip4_addr3(receiver.sin_addr.s_addr), - ip4_addr4(receiver.sin_addr.s_addr), - htons(receiver.sin_port)); + tmpaddr = ntohl(g_net1_ipaddr); + printf("NET1: Create receive socket: %d.%d.%d.%d:%d\n", + (int)(tmpaddr >> 24), + (int)((tmpaddr >> 16) & 0xff), + (int)((tmpaddr >> 8) & 0xff), + (int)(tmpaddr & 0xff), + CONFIG_EXAMPLES_BRIDGE_NET1_RECVPORT); recvsd = socket(PF_INET, SOCK_DGRAM, 0); if (recvsd < 0) @@ -380,8 +354,8 @@ static int bridge_net1_worker(int argc, char *argv[]) /* Set socket to reuse address */ optval = 1; - if (setsockopt(recvsd, SOL_SOCKET, SO_REUSEADDR, - &optval, sizeof(int)) < 0) + if (setsockopt(recvsd, SOL_SOCKET, SO_REUSEADDR, (void *)&optval, + sizeof(int)) < 0) { fprintf(stderr, "NET1 ERROR: setsockopt SO_REUSEADDR failure: %d\n", errno); @@ -390,6 +364,10 @@ static int bridge_net1_worker(int argc, char *argv[]) /* Bind the socket to a local address */ + receiver.sin_family = AF_INET; + receiver.sin_port = HTONS(CONFIG_EXAMPLES_BRIDGE_NET1_RECVPORT); + receiver.sin_addr.s_addr = g_net1_ipaddr; + if (bind(recvsd, (struct sockaddr *)&receiver, sizeof(struct sockaddr_in)) < 0) { @@ -399,9 +377,12 @@ static int bridge_net1_worker(int argc, char *argv[]) /* Create a UDP send socket on network 2 */ - printf("NET1: Create send socket: %u.%u.%u.%u:INPORT_ANY\n", - ip4_addr1(g_net2_ipaddr), ip4_addr2(g_net2_ipaddr), - ip4_addr3(g_net2_ipaddr), ip4_addr4(g_net2_ipaddr)); + tmpaddr = ntohl(g_net2_ipaddr); + printf("NET1: Create send socket: %d.%d.%d.%d:INPORT_ANY\n", + (int)(tmpaddr >> 24), + (int)((tmpaddr >> 16) & 0xff), + (int)((tmpaddr >> 8) & 0xff), + (int)(tmpaddr & 0xff)); sndsd = socket(PF_INET, SOCK_DGRAM, 0); if (sndsd < 0) @@ -414,8 +395,8 @@ static int bridge_net1_worker(int argc, char *argv[]) /* Set socket to reuse address */ optval = 1; - if (setsockopt(sndsd, SOL_SOCKET, SO_REUSEADDR, - &optval, sizeof(int)) < 0) + if (setsockopt(sndsd, SOL_SOCKET, SO_REUSEADDR, (void *)&optval, + sizeof(int)) < 0) { fprintf(stderr, "NET1 ERROR: setsockopt SO_REUSEADDR failure: %d\n", errno); @@ -449,12 +430,13 @@ static int bridge_net1_worker(int argc, char *argv[]) CONFIG_EXAMPLES_BRIDGE_NET1_IOBUFIZE, 0, (FAR struct sockaddr *)&fromaddr, &addrlen); - printf("NET1: Received %ld bytes from %u.%u.%u.%u:%u\n", + tmpaddr = ntohl(fromaddr.sin_addr.s_addr); + printf("NET1: Received %ld bytes from %d.%d.%d.%d:%d\n", (long)nrecvd, - ip4_addr1(fromaddr.sin_addr.s_addr), - ip4_addr2(fromaddr.sin_addr.s_addr), - ip4_addr3(fromaddr.sin_addr.s_addr), - ip4_addr4(fromaddr.sin_addr.s_addr), + (int)(tmpaddr >> 24), + (int)((tmpaddr >> 16) & 0xff), + (int)((tmpaddr >> 8) & 0xff), + (int)(tmpaddr & 0xff), ntohs(fromaddr.sin_port)); /* Check for a receive error or zero bytes received. The negative @@ -480,18 +462,18 @@ static int bridge_net1_worker(int argc, char *argv[]) /* Send the newly received packet out network 2 */ + printf("NET1: Sending %ld bytes on network 2: %d.%d.%d.%d:%d\n", + (long)nrecvd, + CONFIG_EXAMPLES_BRIDGE_NET2_IPHOST >> 24, + (CONFIG_EXAMPLES_BRIDGE_NET2_IPHOST >> 16) & 0xff, + (CONFIG_EXAMPLES_BRIDGE_NET2_IPHOST >> 8) & 0xff, + CONFIG_EXAMPLES_BRIDGE_NET2_IPHOST & 0xff, + CONFIG_EXAMPLES_BRIDGE_NET2_HOSTPORT); + toaddr.sin_family = AF_INET; toaddr.sin_port = htons(CONFIG_EXAMPLES_BRIDGE_NET2_HOSTPORT); toaddr.sin_addr.s_addr = htonl(CONFIG_EXAMPLES_BRIDGE_NET2_IPHOST); - printf("NET1: Sending %ld bytes on network 2: %u.%u.%u.%u:%u\n", - (long)nrecvd, - ip4_addr1(toaddr.sin_addr.s_addr), - ip4_addr2(toaddr.sin_addr.s_addr), - ip4_addr3(toaddr.sin_addr.s_addr), - ip4_addr4(toaddr.sin_addr.s_addr), - htons(toaddr.sin_port)); - nsent = sendto(sndsd, g_net1_buffer, nrecvd, 0, (struct sockaddr *)&toaddr, sizeof(struct sockaddr_in)); @@ -533,6 +515,7 @@ static int bridge_net2_worker(int argc, char *argv[]) struct sockaddr_in fromaddr; struct sockaddr_in toaddr; socklen_t addrlen; + in_addr_t tmpaddr; ssize_t nrecvd; ssize_t nsent; int optval; @@ -543,16 +526,13 @@ static int bridge_net2_worker(int argc, char *argv[]) /* Create a UDP receive socket on network 2 */ - receiver.sin_family = AF_INET; - receiver.sin_port = htons(CONFIG_EXAMPLES_BRIDGE_NET2_RECVPORT); - receiver.sin_addr.s_addr = g_net2_ipaddr; - - printf("NET2: Create receive socket: %u.%u.%u,%u:%u\n", - ip4_addr1(receiver.sin_addr.s_addr), - ip4_addr2(receiver.sin_addr.s_addr), - ip4_addr3(receiver.sin_addr.s_addr), - ip4_addr4(receiver.sin_addr.s_addr), - htons(receiver.sin_port)); + tmpaddr = ntohl(g_net2_ipaddr); + printf("NET2: Create receive socket: %d.%d.%d.%d:%d\n", + (int)(tmpaddr >> 24), + (int)((tmpaddr >> 16) & 0xff), + (int)((tmpaddr >> 8) & 0xff), + (int)(tmpaddr & 0xff), + CONFIG_EXAMPLES_BRIDGE_NET2_RECVPORT); recvsd = socket(PF_INET, SOCK_DGRAM, 0); if (recvsd < 0) @@ -565,8 +545,8 @@ static int bridge_net2_worker(int argc, char *argv[]) /* Set socket to reuse address */ optval = 1; - if (setsockopt(recvsd, SOL_SOCKET, SO_REUSEADDR, - &optval, sizeof(int)) < 0) + if (setsockopt(recvsd, SOL_SOCKET, SO_REUSEADDR, (void *)&optval, + sizeof(int)) < 0) { fprintf(stderr, "NET2 ERROR: setsockopt SO_REUSEADDR failure: %d\n", errno); @@ -575,6 +555,10 @@ static int bridge_net2_worker(int argc, char *argv[]) /* Bind the socket to a local address */ + receiver.sin_family = AF_INET; + receiver.sin_port = HTONS(CONFIG_EXAMPLES_BRIDGE_NET2_RECVPORT); + receiver.sin_addr.s_addr = g_net2_ipaddr; + if (bind(recvsd, (struct sockaddr *)&receiver, sizeof(struct sockaddr_in)) < 0) { @@ -584,9 +568,12 @@ static int bridge_net2_worker(int argc, char *argv[]) /* Create a UDP send socket on network 1 */ - printf("NET2: Create send socket: %u.%u.%u.%u:INPORT_ANY\n", - ip4_addr1(g_net1_ipaddr), ip4_addr2(g_net1_ipaddr), - ip4_addr3(g_net1_ipaddr), ip4_addr4(g_net1_ipaddr)); + tmpaddr = ntohl(g_net1_ipaddr); + printf("NET2: Create send socket: %d.%d.%d.%d:INPORT_ANY\n", + (int)(tmpaddr >> 24), + (int)((tmpaddr >> 16) & 0xff), + (int)((tmpaddr >> 8) & 0xff), + (int)(tmpaddr & 0xff)); sndsd = socket(PF_INET, SOCK_DGRAM, 0); if (sndsd < 0) @@ -599,7 +586,7 @@ static int bridge_net2_worker(int argc, char *argv[]) /* Set socket to reuse address */ optval = 1; - if (setsockopt(sndsd, SOL_SOCKET, SO_REUSEADDR, &optval, + if (setsockopt(sndsd, SOL_SOCKET, SO_REUSEADDR, (void *)&optval, sizeof(int)) < 0) { fprintf(stderr, "NET2 ERROR: setsockopt SO_REUSEADDR failure: %d\n", @@ -634,12 +621,13 @@ static int bridge_net2_worker(int argc, char *argv[]) CONFIG_EXAMPLES_BRIDGE_NET2_IOBUFIZE, 0, (FAR struct sockaddr *)&fromaddr, &addrlen); - printf("NET2: Received %ld bytes from %u.%u.%u.%u:%u\n", + tmpaddr = ntohl(fromaddr.sin_addr.s_addr); + printf("NET2: Received %ld bytes from %d.%d.%d.%d:%d\n", (long)nrecvd, - ip4_addr1(fromaddr.sin_addr.s_addr), - ip4_addr2(fromaddr.sin_addr.s_addr), - ip4_addr3(fromaddr.sin_addr.s_addr), - ip4_addr4(fromaddr.sin_addr.s_addr), + (int)(tmpaddr >> 24), + (int)((tmpaddr >> 16) & 0xff), + (int)((tmpaddr >> 8) & 0xff), + (int)(tmpaddr & 0xff), ntohs(fromaddr.sin_port)); /* Check for a receive error or zero bytes received. The negative @@ -665,18 +653,18 @@ static int bridge_net2_worker(int argc, char *argv[]) /* Send the newly received packet out network 1 */ + printf("NET2: Sending %ld bytes on network 1: %d.%d.%d.%d:%d\n", + (long)nrecvd, + CONFIG_EXAMPLES_BRIDGE_NET1_IPHOST >> 24, + (CONFIG_EXAMPLES_BRIDGE_NET1_IPHOST >> 16) & 0xff, + (CONFIG_EXAMPLES_BRIDGE_NET1_IPHOST >> 8) & 0xff, + CONFIG_EXAMPLES_BRIDGE_NET1_IPHOST & 0xff, + CONFIG_EXAMPLES_BRIDGE_NET1_HOSTPORT); + toaddr.sin_family = AF_INET; toaddr.sin_port = htons(CONFIG_EXAMPLES_BRIDGE_NET1_HOSTPORT); toaddr.sin_addr.s_addr = htonl(CONFIG_EXAMPLES_BRIDGE_NET1_IPHOST); - printf("NET2: Sending %ld bytes on network 1: %u.%u.%u.%u:%u\n", - (long)nrecvd, - ip4_addr1(toaddr.sin_addr.s_addr), - ip4_addr2(toaddr.sin_addr.s_addr), - ip4_addr3(toaddr.sin_addr.s_addr), - ip4_addr4(toaddr.sin_addr.s_addr), - htons(toaddr.sin_port)); - nsent = sendto(sndsd, g_net2_buffer, nrecvd, 0, (struct sockaddr *)&toaddr, sizeof(struct sockaddr_in)); diff --git a/examples/bridge/host_main.c b/examples/bridge/host_main.c index 25a6c1631..29705397e 100644 --- a/examples/bridge/host_main.c +++ b/examples/bridge/host_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/bridge/host_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -65,6 +63,7 @@ int main(int argc, char *argv[]) struct sockaddr_in fromaddr; struct sockaddr_in toaddr; socklen_t addrlen; + in_addr_t tmpaddr; ssize_t nrecvd; ssize_t nsent; int optval; @@ -81,18 +80,16 @@ int main(int argc, char *argv[]) sndsd = socket(PF_INET, SOCK_DGRAM, 0); if (sndsd < 0) { - fprintf(stderr, LABEL "ERROR: Failed to create send socket: %d\n", - errno); + fprintf(stderr, LABEL "ERROR: Failed to create send socket: %d\n", errno); return EXIT_FAILURE; } /* Set socket to reuse address */ optval = 1; - if (setsockopt(sndsd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(int)) < 0) + if (setsockopt(sndsd, SOL_SOCKET, SO_REUSEADDR, (void*)&optval, sizeof(int)) < 0) { - fprintf(stderr, - LABEL "ERROR: setsockopt SO_REUSEADDR failure: %d\n", errno); + fprintf(stderr, LABEL "ERROR: setsockopt SO_REUSEADDR failure: %d\n", errno); goto errout_with_sendsd; } @@ -102,8 +99,7 @@ int main(int argc, char *argv[]) sender.sin_port = 0; sender.sin_addr.s_addr = htonl(EXAMPLES_BRIDGE_SEND_IPHOST); - if (bind(sndsd, (struct sockaddr *)&sender, - sizeof(struct sockaddr_in)) < 0) + if (bind(sndsd, (struct sockaddr*)&sender, sizeof(struct sockaddr_in)) < 0) { printf(LABEL "bind failure: %d\n", errno); goto errout_with_sendsd; @@ -117,18 +113,16 @@ int main(int argc, char *argv[]) recvsd = socket(PF_INET, SOCK_DGRAM, 0); if (recvsd < 0) { - fprintf(stderr, - LABEL "ERROR: Failed to create receive socket: %d\n", errno); + fprintf(stderr, LABEL "ERROR: Failed to create receive socket: %d\n", errno); goto errout_with_sendsd; } /* Set socket to reuse address */ optval = 1; - if (setsockopt(recvsd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(int)) < 0) + if (setsockopt(recvsd, SOL_SOCKET, SO_REUSEADDR, (void*)&optval, sizeof(int)) < 0) { - fprintf(stderr, - LABEL "ERROR: setsockopt SO_REUSEADDR failure: %d\n", errno); + fprintf(stderr, LABEL "ERROR: setsockopt SO_REUSEADDR failure: %d\n", errno); goto errout_with_recvsd; } @@ -138,8 +132,7 @@ int main(int argc, char *argv[]) receiver.sin_port = htons(EXAMPLES_BRIDGE_SEND_HOSTPORT); receiver.sin_addr.s_addr = htonl(EXAMPLES_BRIDGE_RECV_IPHOST); - if (bind(recvsd, (struct sockaddr *)&receiver, - sizeof(struct sockaddr_in)) < 0) + if (bind(recvsd, (struct sockaddr*)&receiver, sizeof(struct sockaddr_in)) < 0) { fprintf(stderr, LABEL "ERROR: bind failure: %d\n", errno); goto errout_with_recvsd; @@ -155,8 +148,8 @@ int main(int argc, char *argv[]) toaddr.sin_port = htons(EXAMPLES_BRIDGE_RECV_RECVPORT); toaddr.sin_addr.s_addr = htonl(EXAMPLES_BRIDGE_RECV_IPADDR); - nsent = sendto(sndsd, g_sndmessage, sizeof(g_sndmessage), 0, - (struct sockaddr *)&toaddr, sizeof(struct sockaddr_in)); + nsent = sendto(sndsd, g_sndmessage, sizeof(g_sndmessage), 0, + (struct sockaddr*)&toaddr, sizeof(struct sockaddr_in)); /* Check for send errors */ @@ -176,15 +169,17 @@ int main(int argc, char *argv[]) /* Read a packet */ - printf(LABEL "Receiving up to %d bytes\n", EXAMPLES_BRIDGE_SEND_IOBUFIZE); + printf(LABEL "Receiving up to %d bytes\n", EXAMPLES_BRIDGE_SEND_IOBUFIZE); addrlen = sizeof(struct sockaddr_in); nrecvd = recvfrom(recvsd, g_rdbuffer, EXAMPLES_BRIDGE_SEND_IOBUFIZE, 0, - (struct sockaddr *)&fromaddr, &addrlen); + (struct sockaddr*)&fromaddr, &addrlen); - printf(LABEL "Received %ld bytes from %s:%u\n", + tmpaddr = ntohl(fromaddr.sin_addr.s_addr); + printf(LABEL "Received %ld bytes from %d.%d.%d.%d:%d\n", (long)nrecvd, - inet_ntoa(fromaddr.sin_addr), + tmpaddr >> 24, (tmpaddr >> 16) & 0xff, + (tmpaddr >> 8) & 0xff, tmpaddr & 0xff, ntohs(fromaddr.sin_port)); /* Check for a receive error or zero bytes received. The negative @@ -212,7 +207,7 @@ int main(int argc, char *argv[]) for (i = 0, j = 0; i < nrecvd; i++) { - if (g_rdbuffer[i] == ' ' && j >= 64) + if ( g_rdbuffer[i] == ' ' && j >= 64) { putchar('\n'); j = 0; @@ -239,8 +234,8 @@ int main(int argc, char *argv[]) return EXIT_SUCCESS; errout_with_recvsd: - close(recvsd); + close(recvsd); errout_with_sendsd: - close(sndsd); - return EXIT_FAILURE; + close(sndsd); + return EXIT_FAILURE; } diff --git a/examples/bridge/host_net1.c b/examples/bridge/host_net1.c index a05c6711e..7584643fc 100644 --- a/examples/bridge/host_net1.c +++ b/examples/bridge/host_net1.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/bridge/host_net1.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/bridge/host_net2.c b/examples/bridge/host_net2.c index 87510ebda..b12cc13b4 100644 --- a/examples/bridge/host_net2.c +++ b/examples/bridge/host_net2.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/bridge/host_net2.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/buttons/CMakeLists.txt b/examples/buttons/CMakeLists.txt deleted file mode 100644 index bf266157f..000000000 --- a/examples/buttons/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# ############################################################################## -# apps/examples/buttons/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_BUTTONS) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_BUTTONS_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_BUTTONS_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_BUTTONS_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_BUTTONS} - SRCS - buttons_main.c) -endif() diff --git a/examples/buttons/Make.defs b/examples/buttons/Make.defs index 86b92252e..90ac06fab 100644 --- a/examples/buttons/Make.defs +++ b/examples/buttons/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/buttons/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/buttons/Makefile b/examples/buttons/Makefile index 4602b9bbb..d77ff3988 100644 --- a/examples/buttons/Makefile +++ b/examples/buttons/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/buttons/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/buttons/buttons_main.c b/examples/buttons/buttons_main.c index 13d4b080a..60fa6fd6a 100644 --- a/examples/buttons/buttons_main.c +++ b/examples/buttons/buttons_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/buttons/buttons_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -35,7 +33,6 @@ #include <fcntl.h> #include <sched.h> #include <errno.h> -#include <unistd.h> #include <nuttx/input/buttons.h> @@ -52,7 +49,7 @@ #endif #ifndef CONFIG_EXAMPLES_BUTTONS_SIGNO -# define CONFIG_EXAMPLES_BUTTONS_SIGNO 32 +# define CONFIG_EXAMPLES_BUTTONS_SIGNO 13 #endif #ifndef CONFIG_INPUT_BUTTONS_POLL_DELAY @@ -219,11 +216,9 @@ static int button_daemon(int argc, char *argv[]) goto errout_with_fd; } -#ifdef CONFIG_ENABLE_ALL_SIGNALS /* Ignore the default signal action */ signal(CONFIG_EXAMPLES_BUTTONS_SIGNO, SIG_IGN); -#endif /* CONFIG_ENABLE_ALL_SIGNALS */ #endif /* Now loop forever, waiting BUTTONs events */ diff --git a/examples/calib_udelay/CMakeLists.txt b/examples/calib_udelay/CMakeLists.txt deleted file mode 100644 index d48449bab..000000000 --- a/examples/calib_udelay/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# ############################################################################## -# apps/examples/calib_udelay/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_CALIB_UDELAY) - nuttx_add_application( - NAME - calib_udelay - PRIORITY - 100 - STACKSIZE - ${CONFIG_DEFAULT_TASK_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_CALIB_UDELAY} - SRCS - calib_udelay_main.c) -endif() diff --git a/examples/calib_udelay/Kconfig b/examples/calib_udelay/Kconfig index 97b059285..c1759bc16 100644 --- a/examples/calib_udelay/Kconfig +++ b/examples/calib_udelay/Kconfig @@ -17,15 +17,11 @@ if EXAMPLES_CALIB_UDELAY config EXAMPLES_CALIB_UDELAY_NUM_MEASUREMENTS int "Number of measurements to take for each loop iteration count" default 3 + ---help--- config EXAMPLES_CALIB_UDELAY_NUM_RESULTS int "Number of results to generate for calibration slope" default 20 - -config EXAMPLES_CALIB_UDELAY_DELAY_TEST_ITERATIONS - int "Delay loop interrations per test." - default 100000 ---help--- - Lower numbers decrease the time taken for the test to complete, - but may reduce the accuracy of the results. + endif diff --git a/examples/calib_udelay/Make.defs b/examples/calib_udelay/Make.defs index d890de933..1e9f8e237 100644 --- a/examples/calib_udelay/Make.defs +++ b/examples/calib_udelay/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/calib_udelay/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/calib_udelay/Makefile b/examples/calib_udelay/Makefile index 4570c51f7..ba1e17c18 100644 --- a/examples/calib_udelay/Makefile +++ b/examples/calib_udelay/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/calib_udelay/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/calib_udelay/calib_udelay_main.c b/examples/calib_udelay/calib_udelay_main.c index 1c9a822f9..9fbde1351 100644 --- a/examples/calib_udelay/calib_udelay_main.c +++ b/examples/calib_udelay/calib_udelay_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/calib_udelay/calib_udelay_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -31,21 +29,20 @@ #include <stdlib.h> #include <string.h> #include <math.h> -#include <unistd.h> /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ #ifndef CONFIG_EXAMPLES_CALIB_UDELAY_NUM_MEASUREMENTS -# define CONFIG_EXAMPLES_CALIB_UDELAY_NUM_MEASUREMENTS 3 +# define CONFIG_EXAMPLES_CALIB_UDELAY_NUM_MEASUREMENTS 3 #endif #ifndef CONFIG_EXAMPLES_CALIB_UDELAY_NUM_RESULTS -# define CONFIG_EXAMPLES_CALIB_UDELAY_NUM_RESULTS 20 +# define CONFIG_EXAMPLES_CALIB_UDELAY_NUM_RESULTS 20 #endif -#define DELAY_TEST_ITERS CONFIG_EXAMPLES_CALIB_UDELAY_DELAY_TEST_ITERATIONS +#define DELAY_TEST_ITERS 100000 /**************************************************************************** * Private Types diff --git a/examples/camera/CMakeLists.txt b/examples/camera/CMakeLists.txt deleted file mode 100644 index 488f485e5..000000000 --- a/examples/camera/CMakeLists.txt +++ /dev/null @@ -1,41 +0,0 @@ -# ############################################################################## -# apps/examples/camera/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_CAMERA) - - set(CSRCS camera_main.c camera_fileutil.c) - if(CONFIG_EXAMPLES_CAMERA_OUTPUT_LCD) - list(APPEND CSRCS camera_bkgd.c) - endif() - - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_CAMERA_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_CAMERA_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_CAMERA_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_CAMERA} - SRCS - ${CSRCS}) -endif() diff --git a/examples/camera/Kconfig b/examples/camera/Kconfig index 4c29ed082..ab9532f47 100644 --- a/examples/camera/Kconfig +++ b/examples/camera/Kconfig @@ -6,7 +6,6 @@ config EXAMPLES_CAMERA tristate "Camera example" default n - depends on DRIVERS_VIDEO ---help--- Enable the camera example diff --git a/examples/camera/Make.defs b/examples/camera/Make.defs index 7007a0682..d2507a9db 100644 --- a/examples/camera/Make.defs +++ b/examples/camera/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/camera/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/camera/Makefile b/examples/camera/Makefile index e734c96db..946f3049b 100644 --- a/examples/camera/Makefile +++ b/examples/camera/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/camera/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/camera/README.md b/examples/camera/README.md new file mode 100644 index 000000000..3c6750311 --- /dev/null +++ b/examples/camera/README.md @@ -0,0 +1,42 @@ +# Examples / `camera` Camera Snapshot + +This sample is implemented as `camera` command on NuttX Shell. The synopsis of +the command is as below. + +``` +nsh> camera ([-jpg]) ([capture num]) + + -jpg : this option is set for storing JPEG file into a strage. + : If this option isn't set capturing raw RGB565 data in a file. + : raw RGB565 is default. + + capture num : this option instructs number of taking pictures. + : 10 is default. +``` + +Storage will be selected automatically based on the available storage option. + +Execution example: + +``` +nsh> camera +nximage_listener: Connected +nximage_initialize: Screen resolution (320,240) +Take 10 pictures as RGB file in /mnt/sd0 after 5 seconds. +After finishing taking pictures, this app will be finished after 10 seconds. +Expier time is pasted. +Start capturing... +FILENAME:/mnt/sd0/VIDEO001.RGB +FILENAME:/mnt/sd0/VIDEO002.RGB +FILENAME:/mnt/sd0/VIDEO003.RGB +FILENAME:/mnt/sd0/VIDEO004.RGB +FILENAME:/mnt/sd0/VIDEO005.RGB +FILENAME:/mnt/sd0/VIDEO006.RGB +FILENAME:/mnt/sd0/VIDEO007.RGB +FILENAME:/mnt/sd0/VIDEO008.RGB +FILENAME:/mnt/sd0/VIDEO009.RGB +FILENAME:/mnt/sd0/VIDEO010.RGB +Finished capturing... +Expier time is pasted. +nximage_listener: Lost server connection: 117 +``` diff --git a/examples/camera/camera_bkgd.c b/examples/camera/camera_bkgd.c index a0c0bd2fa..3fa80f380 100644 --- a/examples/camera/camera_bkgd.c +++ b/examples/camera/camera_bkgd.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/camera/camera_bkgd.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -32,8 +30,7 @@ #include <stdlib.h> #include <semaphore.h> #include <errno.h> -#include <nuttx/debug.h> -#include <sys/boardctl.h> +#include <debug.h> #include <arch/board/board.h> #include <nuttx/nx/nx.h> @@ -50,7 +47,7 @@ struct nximage_data_s /* The NX handles */ NXHANDLE hnx; - NXWINDOW hbkgd; + NXHANDLE hbkgd; bool connected; /* The screen resolution */ @@ -98,13 +95,13 @@ static const struct nx_callback_s g_nximagecb = static struct nximage_data_s g_nximage = { - NULL, /* hnx */ - NULL, /* hbkgd */ - false, /* connected */ - 0, /* xres */ - 0, /* yres */ - false, /* havpos */ - SEM_INITIALIZER(0), /* sem */ + NULL, /* hnx */ + NULL, /* hbkgd */ + false, /* connected */ + 0, /* xres */ + 0, /* yres */ + false, /* havpos */ + { 0 }, /* sem */ }; /**************************************************************************** @@ -118,7 +115,7 @@ static struct nximage_data_s g_nximage = * NX event listener for an event from NX server. ****************************************************************************/ -static FAR void *nximage_listener(FAR void *arg) +FAR void *nximage_listener(FAR void *arg) { int ret; @@ -165,7 +162,7 @@ static FAR void *nximage_listener(FAR void *arg) ****************************************************************************/ static void nximage_redraw(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect, - bool more, FAR void *arg) + bool more, FAR void *arg) { ginfo("hwnd=%p rect={(%d,%d),(%d,%d)} more=%s\n", hwnd, rect->pt1.x, rect->pt1.y, rect->pt2.x, rect->pt2.y, @@ -249,7 +246,7 @@ int nximage_initialize(void) } /* Start a separate thread to listen for server events. - * For simplicity, use default thread attribute. + * For simplicity, use defaul thread attribute. */ ret = pthread_create(&thread, NULL, nximage_listener, NULL); @@ -267,7 +264,7 @@ int nximage_initialize(void) * are connected. */ - sem_wait(&g_nximage.sem); + (void)sem_wait(&g_nximage.sem); } /* Set background color to black */ @@ -284,7 +281,7 @@ int nximage_initialize(void) while (!g_nximage.havepos) { - sem_wait(&g_nximage.sem); + (void) sem_wait(&g_nximage.sem); } printf("nximage_initialize: Screen resolution (%d,%d)\n", @@ -294,7 +291,7 @@ int nximage_initialize(void) } /**************************************************************************** - * Name: nximage_draw + * Name: nximage_image * * Description: * Put the NuttX logo in the center of the display. @@ -307,31 +304,24 @@ void nximage_draw(FAR void *image, int w, int h) FAR struct nxgl_rect_s dest; FAR const void *src[CONFIG_NX_NPLANES]; int ret; - int dest_w; - int dest_h; origin.x = 0; origin.y = 0; - /* Clip destination to the smaller of image size and screen size */ - - dest_w = w < g_nximage.xres ? w : g_nximage.xres; - dest_h = h < g_nximage.yres ? h : g_nximage.yres; + /* Set up the destination to whole LCD screen */ dest.pt1.x = 0; dest.pt1.y = 0; - dest.pt2.x = dest_w - 1; - dest.pt2.y = dest_h - 1; + dest.pt2.x = g_nximage.xres - 1; + dest.pt2.y = g_nximage.yres - 1; src[0] = image; - /* stride must match the source image width, not the screen width */ - - ret = nx_bitmap(g_nximage.hbkgd, &dest, src, &origin, - w * sizeof(nxgl_mxpixel_t)); + ret = nx_bitmap((NXWINDOW)g_nximage.hbkgd, &dest, src, &origin, + g_nximage.xres * sizeof(nxgl_mxpixel_t)); if (ret < 0) { - printf("nximage_image: nx_bitmap failed: %d\n", errno); + printf("nximage_image: nx_bitmapwindow failed: %d\n", errno); } } @@ -346,3 +336,4 @@ void nximage_finalize(void) { nx_disconnect(g_nximage.hnx); } + diff --git a/examples/camera/camera_bkgd.h b/examples/camera/camera_bkgd.h index 1ebee240b..7d56aadde 100644 --- a/examples/camera/camera_bkgd.h +++ b/examples/camera/camera_bkgd.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/camera/camera_bkgd.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/camera/camera_fileutil.c b/examples/camera/camera_fileutil.c index f8c7500e3..743b0c7b3 100644 --- a/examples/camera/camera_fileutil.c +++ b/examples/camera/camera_fileutil.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/camera/camera_fileutil.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -42,8 +40,7 @@ * Private Data ****************************************************************************/ -static FAR const char *g_save_dir; -static int g_framecount; +static const char *save_dir; /**************************************************************************** * Public Functions @@ -56,7 +53,7 @@ static int g_framecount; * Choose strage to write a file. ****************************************************************************/ -FAR const char *futil_initialize(void) +const char *futil_initialize(void) { int ret; struct stat stat_buf; @@ -68,14 +65,14 @@ FAR const char *futil_initialize(void) ret = stat("/mnt/sd0", &stat_buf); if (ret < 0) { - g_save_dir = "/mnt/spif"; + save_dir = "/mnt/spif"; } else { - g_save_dir = "/mnt/sd0"; + save_dir = "/mnt/sd0"; } - return g_save_dir; + return save_dir; } /**************************************************************************** @@ -85,25 +82,29 @@ FAR const char *futil_initialize(void) * Write a image file to selected storage. ****************************************************************************/ -int futil_writeimage(FAR uint8_t *data, size_t len, FAR const char *fsuffix) +int futil_writeimage(uint8_t *data, size_t len, const char *fsuffix) { - char fname[IMAGE_FILENAME_LEN]; - FAR FILE *fp; + static char s_fname[IMAGE_FILENAME_LEN]; + static int s_framecount = 0; - g_framecount++; - if (g_framecount >= 1000) + FILE *fp; + + s_framecount++; + if (s_framecount >= 1000) { - g_framecount = 1; + s_framecount = 1; } - snprintf(fname, + memset(s_fname, 0, sizeof(s_fname)); + + snprintf(s_fname, IMAGE_FILENAME_LEN, "%s/VIDEO%03d.%s", - g_save_dir, g_framecount, fsuffix); + save_dir, s_framecount, fsuffix); - printf("FILENAME:%s\n", fname); + printf("FILENAME:%s\n", s_fname); - fp = fopen(fname, "wb"); + fp = fopen(s_fname, "wb"); if (NULL == fp) { printf("fopen error : %d\n", errno); @@ -118,3 +119,4 @@ int futil_writeimage(FAR uint8_t *data, size_t len, FAR const char *fsuffix) fclose(fp); return 0; } + diff --git a/examples/camera/camera_fileutil.h b/examples/camera/camera_fileutil.h index f9bce368c..5e366d9b5 100644 --- a/examples/camera/camera_fileutil.h +++ b/examples/camera/camera_fileutil.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/camera/camera_fileutil.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -36,11 +34,11 @@ /* Initialize file util of camera example */ -FAR const char *futil_initialize(void); +const char *futil_initialize(void); /* Write an image file */ -int futil_writeimage(FAR uint8_t *data, size_t len, FAR const char *fsuffix); +int futil_writeimage(uint8_t *data, size_t len, const char *fsuffix); #endif /* __APPS_EXAMPLES_CAMERA_CAMERA_FILEUTIL_H */ diff --git a/examples/camera/camera_main.c b/examples/camera/camera_main.c index c2c83e762..288f6170c 100644 --- a/examples/camera/camera_main.c +++ b/examples/camera/camera_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/camera/camera_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -34,14 +32,16 @@ #include <sys/time.h> #include <sys/ioctl.h> #include <time.h> -#include <unistd.h> #include <nuttx/video/video.h> -#include <nuttx/video/v4l2_cap.h> -#include <nuttx/cache.h> #include "camera_fileutil.h" + +#ifdef CONFIG_EXAMPLES_CAMERA_OUTPUT_LCD +#include <nuttx/nx/nx.h> +#include <nuttx/nx/nxglib.h> #include "camera_bkgd.h" +#endif /**************************************************************************** * Pre-processor Definitions @@ -63,15 +63,13 @@ #define APP_STATE_UNDER_CAPTURE (1) #define APP_STATE_AFTER_CAPTURE (2) -#define CAMERA_DEV_PATH "/dev/video" - /**************************************************************************** * Private Types ****************************************************************************/ struct v_buffer { - FAR uint32_t *start; + uint32_t *start; uint32_t length; }; @@ -84,18 +82,14 @@ typedef struct v_buffer v_buffer_t; static int camera_prepare(int fd, enum v4l2_buf_type type, uint32_t buf_mode, uint32_t pixformat, uint16_t hsize, uint16_t vsize, - FAR struct v_buffer **vbuf, - uint8_t buffernum, int buffersize, - FAR uint32_t *memory, - FAR uint32_t *actual_fmt); -static void free_buffer(FAR struct v_buffer *buffers, uint8_t bufnum); -static int parse_arguments(int argc, FAR char *argv[], - FAR int *capture_num, - FAR enum v4l2_buf_type *type, - FAR bool *mirror); -static int get_camimage(int fd, FAR struct v4l2_buffer *v4l2_buf, - enum v4l2_buf_type buf_type, uint32_t memory); -static int release_camimage(int fd, FAR struct v4l2_buffer *v4l2_buf); + struct v_buffer **vbuf, + uint8_t buffernum, int buffersize); +static void free_buffer(struct v_buffer *buffers, uint8_t bufnum); +static int parse_arguments(int argc, char *argv[], + int *capture_num, enum v4l2_buf_type *type); +static int get_camimage(int fd, struct v4l2_buffer *v4l2_buf, + enum v4l2_buf_type buf_type); +static int release_camimage(int fd, struct v4l2_buffer *v4l2_buf); static int start_stillcapture(int v_fd, enum v4l2_buf_type capture_type); static int stop_stillcapture(int v_fd, enum v4l2_buf_type capture_type); @@ -115,17 +109,15 @@ static int stop_stillcapture(int v_fd, enum v4l2_buf_type capture_type); * Name: camera_prepare() * * Description: - * Allocate frame buffer for camera and queue the allocated buffer + * Allocate frame buffer for camera and Queue the allocated buffer * into video driver. ****************************************************************************/ static int camera_prepare(int fd, enum v4l2_buf_type type, uint32_t buf_mode, uint32_t pixformat, uint16_t hsize, uint16_t vsize, - FAR struct v_buffer **vbuf, - uint8_t buffernum, int buffersize, - FAR uint32_t *memory, - FAR uint32_t *actual_fmt) + struct v_buffer **vbuf, + uint8_t buffernum, int buffersize) { int ret; int cnt; @@ -144,6 +136,20 @@ static int camera_prepare(int fd, enum v4l2_buf_type type, 0 }; + /* VIDIOC_REQBUFS initiate user pointer I/O */ + + req.type = type; + req.memory = V4L2_MEMORY_USERPTR; + req.count = buffernum; + req.mode = buf_mode; + + ret = ioctl(fd, VIDIOC_REQBUFS, (unsigned long)&req); + if (ret < 0) + { + printf("Failed to VIDIOC_REQBUFS: errno = %d\n", errno); + return ret; + } + /* VIDIOC_S_FMT set format */ fmt.type = type; @@ -152,54 +158,17 @@ static int camera_prepare(int fd, enum v4l2_buf_type type, fmt.fmt.pix.field = V4L2_FIELD_ANY; fmt.fmt.pix.pixelformat = pixformat; - ret = ioctl(fd, VIDIOC_S_FMT, (uintptr_t)&fmt); - if (ret < 0 && pixformat == V4L2_PIX_FMT_RGB565) - { - /* Some sensors on 8-bit DVP output big-endian RGB565 (RGB565X). - * Retry with RGB565X if RGB565 is not supported. - */ - - fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_RGB565X; - ret = ioctl(fd, VIDIOC_S_FMT, (uintptr_t)&fmt); - } - + ret = ioctl(fd, VIDIOC_S_FMT, (unsigned long)&fmt); if (ret < 0) { printf("Failed to VIDIOC_S_FMT: errno = %d\n", errno); return ret; } - if (actual_fmt) - { - *actual_fmt = fmt.fmt.pix.pixelformat; - } - - /* VIDIOC_REQBUFS: try MMAP first (driver-managed DMA buffers). - * Fall back to USERPTR if the driver does not support MMAP. - */ - - req.type = type; - req.memory = V4L2_MEMORY_MMAP; - req.count = buffernum; - req.mode = buf_mode; - - ret = ioctl(fd, VIDIOC_REQBUFS, (uintptr_t)&req); - if (ret < 0) - { - req.memory = V4L2_MEMORY_USERPTR; - ret = ioctl(fd, VIDIOC_REQBUFS, (uintptr_t)&req); - if (ret < 0) - { - printf("Failed to VIDIOC_REQBUFS: errno = %d\n", errno); - return ret; - } - } - - *memory = req.memory; - - /* Prepare v_buffer array to track buffer metadata */ + /* Prepare video memory to store images */ *vbuf = malloc(sizeof(v_buffer_t) * buffernum); + if (!(*vbuf)) { printf("Out of memory for array of v_buffer_t[%d]\n", buffernum); @@ -208,54 +177,30 @@ static int camera_prepare(int fd, enum v4l2_buf_type type, for (cnt = 0; cnt < buffernum; cnt++) { - if (req.memory == V4L2_MEMORY_MMAP) + (*vbuf)[cnt].length = buffersize; + + /* Note: + * VIDIOC_QBUF set buffer pointer. + * Buffer pointer must be 32bytes aligned. + */ + + (*vbuf)[cnt].start = memalign(32, buffersize); + if (!(*vbuf)[cnt].start) { - /* VIDIOC_QUERYBUF: get driver-allocated buffer metadata */ + printf("Out of memory for image buffer of %d/%d\n", + cnt, buffernum); - memset(&buf, 0, sizeof(v4l2_buffer_t)); - buf.type = type; - buf.memory = V4L2_MEMORY_MMAP; - buf.index = cnt; + /* Release allocated memory. */ - ret = ioctl(fd, VIDIOC_QUERYBUF, (uintptr_t)&buf); - if (ret < 0) + while (cnt) { - printf("Failed to VIDIOC_QUERYBUF %d: errno = %d\n", - cnt, errno); - free(*vbuf); - *vbuf = NULL; - return ret; + cnt--; + free((*vbuf)[cnt].start); } - (*vbuf)[cnt].start = NULL; - (*vbuf)[cnt].length = buf.length; - } - else - { - (*vbuf)[cnt].length = buffersize; - - /* Note: - * VIDIOC_QBUF set buffer pointer. - * Buffer pointer must be 32bytes aligned. - */ - - (*vbuf)[cnt].start = memalign(32, buffersize); - if (!(*vbuf)[cnt].start) - { - printf("Out of memory for image buffer of %d/%d\n", - cnt, buffernum); - - /* Release allocated memory. */ - - while (cnt--) - { - free((*vbuf)[cnt].start); - } - - free(*vbuf); - *vbuf = NULL; - return ERROR; - } + free(*vbuf); + *vbuf = NULL; + return ERROR; } } @@ -265,16 +210,12 @@ static int camera_prepare(int fd, enum v4l2_buf_type type, { memset(&buf, 0, sizeof(v4l2_buffer_t)); buf.type = type; - buf.memory = req.memory; + buf.memory = V4L2_MEMORY_USERPTR; buf.index = cnt; + buf.m.userptr = (unsigned long)(*vbuf)[cnt].start; buf.length = (*vbuf)[cnt].length; - if (req.memory == V4L2_MEMORY_USERPTR) - { - buf.m.userptr = (uintptr_t)(*vbuf)[cnt].start; - } - - ret = ioctl(fd, VIDIOC_QBUF, (uintptr_t)&buf); + ret = ioctl(fd, VIDIOC_QBUF, (unsigned long)&buf); if (ret) { printf("Fail QBUF %d\n", errno); @@ -286,7 +227,7 @@ static int camera_prepare(int fd, enum v4l2_buf_type type, /* VIDIOC_STREAMON start stream */ - ret = ioctl(fd, VIDIOC_STREAMON, (uintptr_t)&type); + ret = ioctl(fd, VIDIOC_STREAMON, (unsigned long)&type); if (ret < 0) { printf("Failed to VIDIOC_STREAMON: errno = %d\n", errno); @@ -305,7 +246,7 @@ static int camera_prepare(int fd, enum v4l2_buf_type type, * All free allocated memory of v_buffer. ****************************************************************************/ -static void free_buffer(FAR struct v_buffer *buffers, uint8_t bufnum) +static void free_buffer(struct v_buffer *buffers, uint8_t bufnum) { uint8_t cnt; if (buffers) @@ -329,38 +270,59 @@ static void free_buffer(FAR struct v_buffer *buffers, uint8_t bufnum) * Parse and decode commandline arguments. ****************************************************************************/ -static int parse_arguments(int argc, FAR char *argv[], - FAR int *capture_num, - FAR enum v4l2_buf_type *type, - FAR bool *mirror) +static int parse_arguments(int argc, char *argv[], + int *capture_num, enum v4l2_buf_type *type) { - int i; - - *capture_num = DEFAULT_CAPTURE_NUM; - *type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - *mirror = false; - - for (i = 1; i < argc; i++) + if (argc == 1) { - if (strncmp(argv[i], "-jpg", 5) == 0) + *capture_num = DEFAULT_CAPTURE_NUM; + *type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + } + else if (argc == 2) + { + if (strncmp(argv[1], "-jpg", 5) == 0) { + *capture_num = DEFAULT_CAPTURE_NUM; *type = V4L2_BUF_TYPE_STILL_CAPTURE; } - else if (strncmp(argv[i], "-m", 3) == 0) - { - *mirror = true; - } else { - *capture_num = atoi(argv[i]); - if (*capture_num < 0 || *capture_num > MAX_CAPTURE_NUM) + *capture_num = atoi(argv[1]); + if ((*capture_num < 0) || (*capture_num > MAX_CAPTURE_NUM)) { printf("Invalid capture num(%d). must be >=0 and <=%d\n", *capture_num, MAX_CAPTURE_NUM); return ERROR; } + + *type = V4L2_BUF_TYPE_VIDEO_CAPTURE; } } + else if (argc == 3) + { + if (strncmp(argv[1], "-jpg", 5) == 0) + { + *capture_num = atoi(argv[2]); + if ((*capture_num < 0) || (*capture_num > MAX_CAPTURE_NUM)) + { + printf("Invalid capture num(%d). must be >=0 and <=%d\n", + *capture_num, MAX_CAPTURE_NUM); + return ERROR; + } + + *type = V4L2_BUF_TYPE_STILL_CAPTURE; + } + else + { + printf("Invalid argument 1 : %s\n", argv[1]); + return ERROR; + } + } + else + { + printf("Too many arguments\n"); + return ERROR; + } return OK; } @@ -372,8 +334,8 @@ static int parse_arguments(int argc, FAR char *argv[], * DQBUF camera frame buffer from video driver with taken picture data. ****************************************************************************/ -static int get_camimage(int fd, FAR struct v4l2_buffer *v4l2_buf, - enum v4l2_buf_type buf_type, uint32_t memory) +static int get_camimage(int fd, struct v4l2_buffer *v4l2_buf, + enum v4l2_buf_type buf_type) { int ret; @@ -381,9 +343,9 @@ static int get_camimage(int fd, FAR struct v4l2_buffer *v4l2_buf, memset(v4l2_buf, 0, sizeof(v4l2_buffer_t)); v4l2_buf->type = buf_type; - v4l2_buf->memory = memory; + v4l2_buf->memory = V4L2_MEMORY_USERPTR; - ret = ioctl(fd, VIDIOC_DQBUF, (uintptr_t)v4l2_buf); + ret = ioctl(fd, VIDIOC_DQBUF, (unsigned long)v4l2_buf); if (ret) { printf("Fail DQBUF %d\n", errno); @@ -400,13 +362,13 @@ static int get_camimage(int fd, FAR struct v4l2_buffer *v4l2_buf, * Re-QBUF to set used frame buffer into video driver. ****************************************************************************/ -static int release_camimage(int fd, FAR struct v4l2_buffer *v4l2_buf) +static int release_camimage(int fd, struct v4l2_buffer *v4l2_buf) { int ret; /* VIDIOC_QBUF sets buffer pointer into video driver again. */ - ret = ioctl(fd, VIDIOC_QBUF, (uintptr_t)v4l2_buf); + ret = ioctl(fd, VIDIOC_QBUF, (unsigned long)v4l2_buf); if (ret) { printf("Fail QBUF %d\n", errno); @@ -465,22 +427,6 @@ static int stop_stillcapture(int v_fd, enum v4l2_buf_type capture_type) return OK; } -/**************************************************************************** - * Name: get_imgsensor_name() - * - * Description: - * Get image sensor driver name by querying device capabilities. - ****************************************************************************/ - -static FAR const char *get_imgsensor_name(int fd) -{ - static struct v4l2_capability cap; - - ioctl(fd, VIDIOC_QUERYCAP, (uintptr_t)&cap); - - return (FAR const char *)cap.driver; -} - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -499,10 +445,7 @@ int main(int argc, FAR char *argv[]) int capture_num = DEFAULT_CAPTURE_NUM; enum v4l2_buf_type capture_type = V4L2_BUF_TYPE_STILL_CAPTURE; struct v4l2_buffer v4l2_buf; - FAR const char *save_dir; - FAR const char *sensor; - uint16_t w; - uint16_t h; + const char *save_dir; int is_eternal; int app_state; @@ -511,19 +454,15 @@ int main(int argc, FAR char *argv[]) struct timeval delta; struct timeval wait; - FAR struct v_buffer *buffers_video = NULL; - FAR struct v_buffer *buffers_still = NULL; - uint32_t video_memory = V4L2_MEMORY_USERPTR; - uint32_t still_memory = V4L2_MEMORY_USERPTR; - uint32_t video_pixfmt = V4L2_PIX_FMT_RGB565; - bool mirror = false; + struct v_buffer *buffers_video = NULL; + struct v_buffer *buffers_still = NULL; /* ===== Parse and Check arguments ===== */ - ret = parse_arguments(argc, argv, &capture_num, &capture_type, &mirror); + ret = parse_arguments(argc, argv, &capture_num, &capture_type); if (ret != OK) { - printf("usage: %s [-jpg] [-m] [capture num]\n", argv[0]); + printf("usage: %s ([-jpg]) ([capture num])\n", argv[0]); return ERROR; } @@ -546,7 +485,7 @@ int main(int argc, FAR char *argv[]) /* Initialize video driver to create a device file */ - ret = capture_initialize(CAMERA_DEV_PATH); + ret = video_initialize("/dev/video"); if (ret != 0) { printf("ERROR: Failed to initialize video: errno = %d\n", errno); @@ -555,7 +494,7 @@ int main(int argc, FAR char *argv[]) /* Open the device file. */ - v_fd = open(CAMERA_DEV_PATH, 0); + v_fd = open("/dev/video", 0); if (v_fd < 0) { printf("ERROR: Failed to open video.errno = %d\n", errno); @@ -563,21 +502,6 @@ int main(int argc, FAR char *argv[]) goto exit_without_cleaning_buffer; } - /* Set horizontal mirror if requested */ - - if (mirror) - { - struct v4l2_control ctrl; - - ctrl.id = V4L2_CID_HFLIP; - ctrl.value = 1; - ret = ioctl(v_fd, VIDIOC_S_CTRL, (uintptr_t)&ctrl); - if (ret < 0) - { - printf("WARNING: VIDIOC_S_CTRL HFLIP failed: %d\n", errno); - } - } - /* Prepare for STILL_CAPTURE stream. * * The video buffer mode is V4L2_BUF_MODE_FIFO mode. @@ -586,42 +510,17 @@ int main(int argc, FAR char *argv[]) * waits for new VIDIOC_QBUFed frame buffer. * And when new VIDIOC_QBUF is executed, the capturing is resumed. * - * Allocate frame buffers for JPEG size (512KB). - * Set FULLHD size in ISX012 case, QUADVGA size in ISX019 case or other - * image sensors, + * Allocate freame buffers for FullHD JPEG size (512KB). * Number of frame buffers is defined as STILL_BUFNUM(1). - * And all allocated memories are VIDIOC_QBUFed. + * And all allocated memorys are VIDIOC_QBUFed. */ - if (capture_num != 0 && capture_type == V4L2_BUF_TYPE_STILL_CAPTURE) + if (capture_num != 0) { - /* Determine image size from connected image sensor name, - * because video driver does not support VIDIOC_ENUM_FRAMESIZES - * for now. - */ - - sensor = get_imgsensor_name(v_fd); - if (strncmp(sensor, "ISX012", strlen("ISX012")) == 0) - { - w = VIDEO_HSIZE_FULLHD; - h = VIDEO_VSIZE_FULLHD; - } - else if (strncmp(sensor, "ISX019", strlen("ISX019")) == 0) - { - w = VIDEO_HSIZE_QUADVGA; - h = VIDEO_VSIZE_QUADVGA; - } - else - { - w = VIDEO_HSIZE_QUADVGA; - h = VIDEO_VSIZE_QUADVGA; - } - ret = camera_prepare(v_fd, V4L2_BUF_TYPE_STILL_CAPTURE, V4L2_BUF_MODE_FIFO, V4L2_PIX_FMT_JPEG, - w, h, - &buffers_still, STILL_BUFNUM, IMAGE_JPG_SIZE, - &still_memory, NULL); + VIDEO_HSIZE_FULLHD, VIDEO_VSIZE_FULLHD, + &buffers_still, STILL_BUFNUM, IMAGE_JPG_SIZE); if (ret != OK) { goto exit_this_app; @@ -637,16 +536,15 @@ int main(int argc, FAR char *argv[]) * order from the captured frame buffer and a new camera image is * recaptured. * - * Allocate frame buffers for QVGA RGB565 size (320x240x2=150KB). + * Allocate freame buffers for QVGA RGB565 size (320x240x2=150KB). * Number of frame buffers is defined as VIDEO_BUFNUM(3). - * And all allocated memories are VIDIOC_QBUFed. + * And all allocated memorys are VIDIOC_QBUFed. */ ret = camera_prepare(v_fd, V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_BUF_MODE_RING, V4L2_PIX_FMT_RGB565, VIDEO_HSIZE_QVGA, VIDEO_VSIZE_QVGA, - &buffers_video, VIDEO_BUFNUM, IMAGE_RGB_SIZE, - &video_memory, &video_pixfmt); + &buffers_video, VIDEO_BUFNUM, IMAGE_RGB_SIZE); if (ret != OK) { goto exit_this_app; @@ -655,19 +553,19 @@ int main(int argc, FAR char *argv[]) /* This application has 3 states. * * APP_STATE_BEFORE_CAPTURE: - * This state waits 5 seconds (defined as START_CAPTURE_TIME) + * This state waits 5 seconds (definded START_CAPTURE_TIME) * with displaying preview (VIDEO_CAPTURE stream image) on LCD. * After 5 seconds, state will be changed to APP_STATE_UNDER_CAPTURE. * * APP_STATE_UNDER_CAPTURE: * This state will start taking picture and store the image into files. - * Number of taking pictures is set capture_num variable. + * Number of taking pictures is set capture_num valiable. * It can be changed by command line argument. * After finishing taking pictures, the state will be changed to * APP_STATE_AFTER_CAPTURE. * * APP_STATE_AFTER_CAPTURE: - * This state waits 10 seconds (defined as KEEP_VIDEO_TIME) + * This state waits 10 seconds (definded KEEP_VIDEO_TIME) * with displaying preview (VIDEO_CAPTURE stream image) on LCD. * After 10 seconds, this application will be finished. * @@ -695,7 +593,7 @@ int main(int argc, FAR char *argv[]) wait.tv_usec = 0; printf("Take %d pictures as %s file in %s after %d seconds.\n", capture_num, - capture_type == V4L2_BUF_TYPE_STILL_CAPTURE ? "JPEG" : "RGB", + (capture_type == V4L2_BUF_TYPE_STILL_CAPTURE) ? "JPEG" : "RGB", save_dir, START_CAPTURE_TIME); printf(" After finishing taking pictures," " this app will be finished after %d seconds.\n", @@ -712,42 +610,19 @@ int main(int argc, FAR char *argv[]) { /* BEFORE_CAPTURE and AFTER_CAPTURE is waiting for expiring the * time. - * In the meantime, Capturing VIDEO image to show pre-view on LCD. + * In the meantime, Captureing VIDEO image to show pre-view on LCD. */ case APP_STATE_BEFORE_CAPTURE: case APP_STATE_AFTER_CAPTURE: - ret = get_camimage(v_fd, &v4l2_buf, - V4L2_BUF_TYPE_VIDEO_CAPTURE, video_memory); + ret = get_camimage(v_fd, &v4l2_buf, V4L2_BUF_TYPE_VIDEO_CAPTURE); if (ret != OK) { goto exit_this_app; } #ifdef CONFIG_EXAMPLES_CAMERA_OUTPUT_LCD - /* If the sensor outputs RGB565X (big-endian), invalidate - * D-Cache so we read fresh DMA data from PSRAM, then - * byte-swap in place for display and swap back before - * returning the buffer to the driver. - */ - - if (video_pixfmt == V4L2_PIX_FMT_RGB565X) - { - FAR uint16_t *p = (FAR uint16_t *)v4l2_buf.m.userptr; - uint32_t npixels = v4l2_buf.bytesused / 2; - uint32_t i; - - up_invalidate_dcache((uintptr_t)p, - (uintptr_t)p + v4l2_buf.bytesused); - - for (i = 0; i < npixels; i++) - { - uint16_t v = p[i]; - p[i] = (v >> 8) | (v << 8); - } - } - - nximage_draw((FAR void *)v4l2_buf.m.userptr, + nximage_draw((void *)v4l2_buf.m.userptr, VIDEO_HSIZE_QVGA, VIDEO_VSIZE_QVGA); #endif @@ -761,7 +636,7 @@ int main(int argc, FAR char *argv[]) { gettimeofday(&now, NULL); timersub(&now, &start, &delta); - if (timercmp(&delta, &wait, > /* For checkpatch */)) + if (timercmp(&delta, &wait, >)) { printf("Expire time is pasted. GoTo next state.\n"); if (app_state == APP_STATE_BEFORE_CAPTURE) @@ -784,7 +659,7 @@ int main(int argc, FAR char *argv[]) */ case APP_STATE_UNDER_CAPTURE: - printf("Start capturing...\n"); + printf("Start captureing...\n"); ret = start_stillcapture(v_fd, capture_type); if (ret != OK) { @@ -793,19 +668,16 @@ int main(int argc, FAR char *argv[]) while (capture_num) { - ret = get_camimage(v_fd, &v4l2_buf, capture_type, - capture_type == - V4L2_BUF_TYPE_STILL_CAPTURE ? - still_memory : video_memory); + ret = get_camimage(v_fd, &v4l2_buf, capture_type); if (ret != OK) { goto exit_this_app; } futil_writeimage( - (FAR uint8_t *)v4l2_buf.m.userptr, + (uint8_t *)v4l2_buf.m.userptr, (size_t)v4l2_buf.bytesused, - capture_type == V4L2_BUF_TYPE_VIDEO_CAPTURE ? + (capture_type == V4L2_BUF_TYPE_VIDEO_CAPTURE) ? "RGB" : "JPG"); ret = release_camimage(v_fd, &v4l2_buf); @@ -827,11 +699,11 @@ int main(int argc, FAR char *argv[]) wait.tv_sec = KEEP_VIDEO_TIME; wait.tv_usec = 0; gettimeofday(&start, NULL); - printf("Finished capturing...\n"); + printf("Finished captureing...\n"); break; /* Finish APP_STATE_UNDER_CAPTURE */ default: - printf("Unknown error is occurred.. state=%d\n", app_state); + printf("Unknown error is occured.. state=%d\n", app_state); goto exit_this_app; break; } @@ -847,11 +719,15 @@ exit_this_app: free_buffer(buffers_still, STILL_BUFNUM); exit_without_cleaning_buffer: - capture_uninitialize(CAMERA_DEV_PATH); + + video_uninitialize(); exit_without_cleaning_videodriver: + #ifdef CONFIG_EXAMPLES_CAMERA_OUTPUT_LCD nximage_finalize(); #endif + return ret; } + diff --git a/examples/can/CMakeLists.txt b/examples/can/CMakeLists.txt deleted file mode 100644 index 783d82dc6..000000000 --- a/examples/can/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# ############################################################################## -# apps/examples/can/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_CAN) - nuttx_add_application( - NAME - can - STACKSIZE - ${CONFIG_DEFAULT_TASK_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_CAN} - SRCS - can_main.c) -endif() diff --git a/examples/can/Make.defs b/examples/can/Make.defs index a8a53ac2b..420dbbf03 100644 --- a/examples/can/Make.defs +++ b/examples/can/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/can/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/can/Makefile b/examples/can/Makefile index 297591fe8..9237bfd0b 100644 --- a/examples/can/Makefile +++ b/examples/can/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/can/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -22,11 +20,11 @@ include $(APPDIR)/Make.defs -# Can example. +# NuttX NX Graphics Example. MAINSRC = can_main.c -# Can built-in application info +# Touchscreen built-in application info PROGNAME = can PRIORITY = SCHED_PRIORITY_DEFAULT diff --git a/examples/can/can.h b/examples/can/can.h index 21a2fbda5..b9446c5ab 100644 --- a/examples/can/can.h +++ b/examples/can/can.h @@ -1,7 +1,5 @@ /**************************************************************************** - * apps/examples/can/can.h - * - * SPDX-License-Identifier: Apache-2.0 + * apps/examples/examples/can/can.h * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -32,9 +30,7 @@ /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ - /* Configuration ************************************************************/ - /* This test depends on these specific CAN configurations settings (your * specific CAN settings might require additional settings). * @@ -45,8 +41,7 @@ * Specific configuration options for this example include: * * CONFIG_CAN_LOOPBACK - * CONFIG_EXAMPLES_CAN_DEVPATH - The path to the CAN device. - * Default: /dev/can0 + * CONFIG_EXAMPLES_CAN_DEVPATH - The path to the CAN device. Default: /dev/can0 * CONFIG_EXAMPLES_CAN_NMSGS - This number of CAN message is collected and * the program terminates. Default: 32. * CONFIG_EXAMPLES_CAN_READ - Only receive messages diff --git a/examples/can/can_main.c b/examples/can/can_main.c index 422458a33..95e414a73 100644 --- a/examples/can/can_main.c +++ b/examples/can/can_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/can/can_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -35,7 +33,7 @@ #include <string.h> #include <fcntl.h> #include <errno.h> -#include <nuttx/debug.h> +#include <debug.h> #include <nuttx/can/can.h> @@ -70,12 +68,8 @@ #endif #ifdef CONFIG_EXAMPLES_CAN_WRITE -# if defined(CONFIG_CAN_EXTID) && defined(CONFIG_CAN_FD) -# define OPT_STR ":n:a:b:ehs" -# elif defined(CONFIG_CAN_EXTID) +# ifdef CONFIG_CAN_EXTID # define OPT_STR ":n:a:b:hs" -# elif defined(CONFIG_CAN_FD) -# define OPT_STR ":n:a:b:eh" # else # define OPT_STR ":n:a:b:h" # endif @@ -105,37 +99,30 @@ static void show_usage(FAR const char *progname) { - dprintf(STDERR_FILENO, "USAGE: %s" + fprintf(stderr, "USAGE: %s" " [-n <nmsgs]" #ifdef CONFIG_EXAMPLES_CAN_WRITE #ifdef CONFIG_CAN_EXTID " [-s]" -#endif -#ifdef CONFIG_CAN_FD - " [-e]" #endif " [-a <min-id>] [b <max-id>]" #endif "\n", progname); - dprintf(STDERR_FILENO, "USAGE: %s -h\n", + fprintf(stderr, "USAGE: %s -h\n", progname); - dprintf(STDERR_FILENO, "\nWhere:\n"); - dprintf(STDERR_FILENO, + fprintf(stderr, "\nWhere:\n"); + fprintf(stderr, "-n <nmsgs>: The number of messages to send. Default: 32\n"); #ifdef CONFIG_EXAMPLES_CAN_WRITE #ifdef CONFIG_CAN_EXTID - dprintf(STDERR_FILENO, "-s: Use standard IDs. Default: Extended ID\n"); + fprintf(stderr, "-s: Use standard IDs. Default: Extended ID\n"); #endif -#ifdef CONFIG_CAN_FD - dprintf(STDERR_FILENO, "-e: Use extended data length without bit rate " - "switch. Default: bit rate switch enabled\n"); -#endif - dprintf(STDERR_FILENO, "-a <min-id>: The start message id. Default 1\n"); - dprintf(STDERR_FILENO, "-b <max-id>: The start message id. Default %d\n", + fprintf(stderr, "-a <min-id>: The start message id. Default 1\n"); + fprintf(stderr, "-b <max-id>: The start message id. Default %d\n", MAX_ID); #endif - dprintf(STDERR_FILENO, "-h: Show this message and exit\n"); + fprintf(stderr, "-h: Show this message and exit\n"); } /**************************************************************************** @@ -151,34 +138,22 @@ int main(int argc, FAR char *argv[]) struct canioc_bittiming_s bt; #ifdef CONFIG_EXAMPLES_CAN_WRITE - int msgdlc; - struct can_msg_s txmsg = - { - 0 - }; - + struct can_msg_s txmsg; #ifdef CONFIG_CAN_EXTID bool extended = true; uint32_t msgid; #else uint16_t msgid; -#endif -#ifdef CONFIG_CAN_FD - bool brs = true; #endif long minid = 1; long maxid = MAX_ID; uint8_t msgdata; #endif - int msgbytes; + int msgdlc; int i; #ifdef CONFIG_EXAMPLES_CAN_READ - struct can_msg_s rxmsg = - { - 0 - }; - + struct can_msg_s rxmsg; #endif size_t msgsize; @@ -204,16 +179,12 @@ int main(int argc, FAR char *argv[]) extended = false; break; #endif -#ifdef CONFIG_CAN_FD - case 'e': - brs = false; - break; -#endif + case 'a': minid = strtol(optarg, NULL, 10); if (minid < 1 || minid > maxid) { - dprintf(STDERR_FILENO, "<min-id> out of range\n"); + fprintf(stderr, "<min-id> out of range\n"); badarg = true; } break; @@ -222,7 +193,7 @@ int main(int argc, FAR char *argv[]) maxid = strtol(optarg, NULL, 10); if (maxid < minid || maxid > MAX_ID) { - dprintf(STDERR_FILENO, "ERROR: <max-id> out of range\n"); + fprintf(stderr, "ERROR: <max-id> out of range\n"); badarg = true; } break; @@ -236,19 +207,19 @@ int main(int argc, FAR char *argv[]) nmsgs = strtol(optarg, NULL, 10); if (nmsgs < 1) { - dprintf(STDERR_FILENO, "ERROR: <nmsgs> out of range\n"); + fprintf(stderr, "ERROR: <nmsgs> out of range\n"); badarg = true; } break; case ':': - dprintf(STDERR_FILENO, "ERROR: Bad option argument\n"); + fprintf(stderr, "ERROR: Bad option argument\n"); badarg = true; break; case '?': default: - dprintf(STDERR_FILENO, "ERROR: Unrecognized option\n"); + fprintf(stderr, "ERROR: Unrecognized option\n"); badarg = true; break; } @@ -279,7 +250,7 @@ int main(int argc, FAR char *argv[]) if (optind != argc) { - dprintf(STDERR_FILENO, "ERROR: Garbage on command line\n"); + fprintf(stderr, "ERROR: Garbage on command line\n"); show_usage(argv[0]); return EXIT_FAILURE; } @@ -327,18 +298,23 @@ int main(int argc, FAR char *argv[]) */ #ifdef CONFIG_EXAMPLES_CAN_WRITE - msgbytes = 1; - msgid = minid; - msgdata = 0; + msgdlc = 1; + msgid = minid; + msgdata = 0; #endif for (msgno = 0; !nmsgs || msgno < nmsgs; msgno++) { + /* Flush any output before the loop entered or from the previous pass + * through the loop. + */ + + fflush(stdout); + #ifdef CONFIG_EXAMPLES_CAN_WRITE /* Construct the next TX message */ - msgdlc = can_bytes2dlc(msgbytes); txmsg.cm_hdr.ch_id = msgid; txmsg.cm_hdr.ch_rtr = false; txmsg.cm_hdr.ch_dlc = msgdlc; @@ -348,21 +324,16 @@ int main(int argc, FAR char *argv[]) #ifdef CONFIG_CAN_EXTID txmsg.cm_hdr.ch_extid = extended; #endif -#ifdef CONFIG_CAN_FD - txmsg.cm_hdr.ch_edl = true; - txmsg.cm_hdr.ch_brs = brs; - txmsg.cm_hdr.ch_esi = false; -#endif - txmsg.cm_hdr.ch_tcf = 0; + txmsg.cm_hdr.ch_unused = 0; - for (i = 0; i < msgbytes; i++) + for (i = 0; i < msgdlc; i++) { txmsg.cm_data[i] = msgdata + i; } /* Send the TX message */ - msgsize = CAN_MSGLEN(can_dlc2bytes(msgdlc)); + msgsize = CAN_MSGLEN(msgdlc); nbytes = write(fd, &txmsg, msgsize); if (nbytes != msgsize) { @@ -392,7 +363,7 @@ int main(int argc, FAR char *argv[]) printf(" ID: %4" PRI_CAN_ID " DLC: %u\n", rxmsg.cm_hdr.ch_id, rxmsg.cm_hdr.ch_dlc); - msgbytes = can_dlc2bytes(rxmsg.cm_hdr.ch_dlc); + msgdlc = rxmsg.cm_hdr.ch_dlc; #ifdef CONFIG_CAN_ERRORS /* Check for error reports */ @@ -468,10 +439,10 @@ int main(int argc, FAR char *argv[]) goto errout_with_dev; } - if (memcmp(txmsg.cm_data, rxmsg.cm_data, msgbytes) != 0) + if (memcmp(txmsg.cm_data, rxmsg.cm_data, msgdlc) != 0) { printf("ERROR: Data does not match. DLC=%d\n", msgdlc); - for (i = 0; i < msgbytes; i++) + for (i = 0; i < msgdlc; i++) { printf(" %d: TX 0x%02x RX 0x%02x\n", i, txmsg.cm_data[i], rxmsg.cm_data[i]); @@ -489,7 +460,7 @@ int main(int argc, FAR char *argv[]) /* Print the data received */ printf("Data received:\n"); - for (i = 0; i < msgbytes; i++) + for (i = 0; i < msgdlc; i++) { printf(" %d: 0x%02x\n", i, rxmsg.cm_data[i]); } @@ -501,16 +472,16 @@ int main(int argc, FAR char *argv[]) /* Set up for the next pass */ - msgdata += msgbytes; + msgdata += msgdlc; if (++msgid > maxid) { msgid = minid; } - if (++msgbytes > CAN_MAXDATALEN) + if (++msgdlc > CAN_MAXDATALEN) { - msgbytes = 1; + msgdlc = 1; } #endif } @@ -519,5 +490,6 @@ errout_with_dev: close(fd); printf("Terminating!\n"); + fflush(stdout); return errval; } diff --git a/examples/dronecan/Kconfig b/examples/canard/Kconfig similarity index 56% rename from examples/dronecan/Kconfig rename to examples/canard/Kconfig index 4ad761eb1..888a756de 100644 --- a/examples/dronecan/Kconfig +++ b/examples/canard/Kconfig @@ -3,46 +3,45 @@ # see the file kconfig-language.txt in the NuttX tools repository. # -config EXAMPLES_DRONECAN - tristate "DroneCAN example" +config EXAMPLES_LIBCANARD + tristate "libcandard example" default n - depends on CANUTILS_LIBDRONECAN + depends on CANUTILS_LIBCANARD && SYSTEM_TIME64 ---help--- - Enable the LIBDRONECAN example + Enable the LIBCANARD example -if EXAMPLES_DRONECAN +if EXAMPLES_LIBCANARD -config EXAMPLES_DRONECAN_DEVPATH +config EXAMPLES_LIBCANARD_DEVPATH string "Device Path" default "/dev/can0" - depends on CAN ---help--- The device path -config EXAMPLES_DRONECAN_NODE_ID +config EXAMPLES_LIBCANARD_NODE_ID int "Node ID" default 1 range 1 127 ---help--- Specifies the node's ID -config EXAMPLES_DRONECAN_APP_NODE_NAME +config EXAMPLES_LIBCANARD_APP_NODE_NAME string "Node name" - default "org.dronecan.nuttx.demo" + default "org.uavcan.libcanard.nuttx.demo" ---help--- app node name -config EXAMPLES_DRONECAN_NODE_MEM_POOL_SIZE +config EXAMPLES_LIBCANARD_NODE_MEM_POOL_SIZE int "Node Memory Pool Size" default 1024 ---help--- Specifies the node's memory pool size -config EXAMPLES_DRONECAN_DAEMON_PRIORITY +config EXAMPLES_LIBCANARD_DAEMON_PRIORITY int "daemon task priority" default 100 -config EXAMPLES_DRONECAN_STACKSIZE +config EXAMPLES_LIBCANARD_STACKSIZE int "canard stack size" default DEFAULT_TASK_STACKSIZE diff --git a/netutils/cmux/Makefile b/examples/canard/Make.defs similarity index 86% rename from netutils/cmux/Makefile rename to examples/canard/Make.defs index 4dfd0447b..b8b7b51ae 100644 --- a/netutils/cmux/Makefile +++ b/examples/canard/Make.defs @@ -1,7 +1,5 @@ ############################################################################ -# apps/netutils/cmux/Makefile -# -# SPDX-License-Identifier: Apache-2.0 +# apps/examples/canard/Make.defs # # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with @@ -20,8 +18,6 @@ # ############################################################################ -include $(APPDIR)/Make.defs - -CSRCS = cmux.c - -include $(APPDIR)/Application.mk +ifneq ($(CONFIG_EXAMPLES_LIBCANARD),) +CONFIGURED_APPS += $(APPDIR)/examples/canard +endif diff --git a/benchmarks/mtd/Makefile b/examples/canard/Makefile similarity index 78% rename from benchmarks/mtd/Makefile rename to examples/canard/Makefile index 30029efe3..cfc9c8044 100644 --- a/benchmarks/mtd/Makefile +++ b/examples/canard/Makefile @@ -1,7 +1,5 @@ ############################################################################ -# apps/benchmarks/mtd/Makefile -# -# SPDX-License-Identifier: Apache-2.0 +# apps/examples/canard/Makefile # # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with @@ -10,7 +8,7 @@ # "License"); you may not use this file except in compliance with the # License. You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http:#www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT @@ -22,13 +20,12 @@ include $(APPDIR)/Make.defs -# MTD test and transfer rate benchmark - -PROGNAME = mtd +PROGNAME = canard PRIORITY = SCHED_PRIORITY_DEFAULT -STACKSIZE = $(CONFIG_DEFAULT_TASK_STACKSIZE) -MODULE = $(CONFIG_BENCHMARK_MTD) +STACKSIZE = $(CONFIG_EXAMPLES_LIBCANARD_STACKSIZE) +MODULE = $(CONFIG_EXAMPLES_LIBCANARD) -MAINSRC = mtd.c +CFLAGS += ${shell $(INCDIR) "$(CC)" $(APPDIR)/include/canutils} +MAINSRC = canard_main.c include $(APPDIR)/Application.mk diff --git a/examples/dronecan/canard_main.c b/examples/canard/canard_main.c similarity index 70% rename from examples/dronecan/canard_main.c rename to examples/canard/canard_main.c index a5a55ebe9..87ba6020a 100644 --- a/examples/dronecan/canard_main.c +++ b/examples/canard/canard_main.c @@ -1,9 +1,8 @@ /**************************************************************************** - * apps/examples/dronecan/canard_main.c + * apps/examples/canard/canard_main.c * - * SPDX-License-Identifier: BSD-3-Clause - * SPDX-FileCopyrightText: 2016 ETH Zuerich. All rights reserved. - * SPDX-FileContributor: Matthias Renner <rennerm@ethz.ch> + * Copyright (C) 2016 ETH Zuerich. All rights reserved. + * Author: Matthias Renner <rennerm@ethz.ch> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -39,19 +38,9 @@ ****************************************************************************/ #include <nuttx/can/can.h> - -#ifdef CONFIG_NET_CAN_CANFD -# define CANARD_ENABLE_CANFD 1 -#endif - #include <canard.h> -#ifdef CONFIG_NET_CAN -#include <socketcan.h> /* CAN backend driver for nuttx socketcan, distributed - * with Libcanard */ -#else #include <canard_nuttx.h> /* CAN backend driver for nuttx, distributed * with Libcanard */ -#endif #include <sys/ioctl.h> #include <sched.h> @@ -67,17 +56,17 @@ * Pre-processor Definitions ****************************************************************************/ -/* Application constants */ + /* Application constants */ #define APP_VERSION_MAJOR 1 #define APP_VERSION_MINOR 0 -#define APP_NODE_NAME CONFIG_EXAMPLES_DRONECAN_APP_NODE_NAME +#define APP_NODE_NAME CONFIG_EXAMPLES_LIBCANARD_APP_NODE_NAME #define GIT_HASH 0xb28bf6ac -/* Some useful constants defined by the UAVCAN specification. - * Data type signature values can be easily obtained with the script - * show_data_type_info.py - */ + /* Some useful constants defined by the UAVCAN specification. + * Data type signature values can be easily obtained with the script + * show_data_type_info.py + */ #define UAVCAN_NODE_STATUS_MESSAGE_SIZE 7 #define UAVCAN_NODE_STATUS_DATA_TYPE_ID 341 @@ -110,8 +99,7 @@ static CanardInstance canard; /* Arena for memory allocation, used by the library */ -static uint8_t canard_memory_pool - [CONFIG_EXAMPLES_DRONECAN_NODE_MEM_POOL_SIZE]; +static uint8_t canard_memory_pool[CONFIG_EXAMPLES_LIBCANARD_NODE_MEM_POOL_SIZE]; static uint8_t unique_id[UNIQUE_ID_LENGTH_BYTES] = { 0x00, 0x00, 0x00, 0x00, @@ -126,10 +114,6 @@ static uint8_t node_health = UAVCAN_NODE_HEALTH_OK; static uint8_t node_mode = UAVCAN_NODE_MODE_INITIALIZATION; static bool g_canard_daemon_started; -#if CANARD_ENABLE_CANFD -static bool canfd; -#endif - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -219,17 +203,13 @@ static void onTransferReceived(CanardInstance *ins, */ /* Image CRC skipped */ - /* HardwareVersion */ - /* Major skipped */ - /* Minor skipped */ memcpy(&buffer[24], unique_id, UNIQUE_ID_LENGTH_BYTES); /* Certificate of authenticity skipped */ - /* Name */ const size_t name_len = strlen(APP_NODE_NAME); @@ -242,17 +222,6 @@ static void onTransferReceived(CanardInstance *ins, */ const int resp_res = -#if CANARD_ENABLE_CANFD - canardRequestOrRespond(ins, - transfer->source_node_id, - UAVCAN_GET_NODE_INFO_DATA_TYPE_SIGNATURE, - UAVCAN_GET_NODE_INFO_DATA_TYPE_ID, - &transfer->transfer_id, - transfer->priority, - CanardResponse, - &buffer[0], - (uint16_t)total_size, canfd); -#else canardRequestOrRespond(ins, transfer->source_node_id, UAVCAN_GET_NODE_INFO_DATA_TYPE_SIGNATURE, @@ -262,7 +231,6 @@ static void onTransferReceived(CanardInstance *ins, CanardResponse, &buffer[0], (uint16_t) total_size); -#endif if (resp_res <= 0) { fprintf(stderr, "Could not respond to GetNodeInfo; error %d\n", @@ -300,8 +268,7 @@ static bool shouldAcceptTransfer(const CanardInstance * ins, if ((transfer_type == CanardTransferTypeRequest) && (data_type_id == UAVCAN_GET_NODE_INFO_DATA_TYPE_ID)) { - *out_data_type_signature = - UAVCAN_GET_NODE_INFO_DATA_TYPE_SIGNATURE; + *out_data_type_signature = UAVCAN_GET_NODE_INFO_DATA_TYPE_SIGNATURE; return true; } } @@ -327,83 +294,66 @@ void process1HzTasks(uint64_t timestamp_usec) /* Printing the memory usage statistics. */ - { - const CanardPoolAllocatorStatistics stats = - canardGetPoolAllocatorStatistics(&canard); - const unsigned peak_percent = - 100U * stats.peak_usage_blocks / stats.capacity_blocks; + { + const CanardPoolAllocatorStatistics stats = + canardGetPoolAllocatorStatistics(&canard); + const unsigned peak_percent = + 100U * stats.peak_usage_blocks / stats.capacity_blocks; #ifdef CONFIG_DEBUG_CAN - printf("Memory pool stats: capacity %u blocks, usage %u blocks," - " peak usage %u blocks (%u%%)\n", - stats.capacity_blocks, stats.current_usage_blocks, - stats.peak_usage_blocks, peak_percent); + printf + ("Memory pool stats: capacity %u blocks, usage %u blocks, peak usage %u blocks (%u%%)\n", + stats.capacity_blocks, stats.current_usage_blocks, + stats.peak_usage_blocks, peak_percent); #endif - /* The recommended way to establish the minimal size of the memory pool - * is to stress-test the application and record the worst case memory - * usage. - */ + /* The recommended way to establish the minimal size of the memory pool + * is to stress-test the application and record the worst case memory + * usage. + */ - if (peak_percent > 70) - { - puts("WARNING: ENLARGE MEMORY POOL"); - } - } + if (peak_percent > 70) + { + puts("WARNING: ENLARGE MEMORY POOL"); + } + } /* Transmitting the node status message periodically. */ - { - uint8_t buffer[UAVCAN_NODE_STATUS_MESSAGE_SIZE]; - makeNodeStatusMessage(buffer); + { + uint8_t buffer[UAVCAN_NODE_STATUS_MESSAGE_SIZE]; + makeNodeStatusMessage(buffer); - static uint8_t transfer_id; + static uint8_t transfer_id; - const int bc_res = -#if CANARD_ENABLE_CANFD - canardBroadcast(&canard, UAVCAN_NODE_STATUS_DATA_TYPE_SIGNATURE, - UAVCAN_NODE_STATUS_DATA_TYPE_ID, &transfer_id, - CANARD_TRANSFER_PRIORITY_LOW, - buffer, UAVCAN_NODE_STATUS_MESSAGE_SIZE, canfd); -#else - canardBroadcast(&canard, UAVCAN_NODE_STATUS_DATA_TYPE_SIGNATURE, - UAVCAN_NODE_STATUS_DATA_TYPE_ID, &transfer_id, - CANARD_TRANSFER_PRIORITY_LOW, - buffer, UAVCAN_NODE_STATUS_MESSAGE_SIZE); -#endif - if (bc_res <= 0) - { - fprintf(stderr, "Could not broadcast node status; error %d\n", - bc_res); - } - } + const int bc_res = + canardBroadcast(&canard, UAVCAN_NODE_STATUS_DATA_TYPE_SIGNATURE, + UAVCAN_NODE_STATUS_DATA_TYPE_ID, &transfer_id, + CANARD_TRANSFER_PRIORITY_LOW, + buffer, UAVCAN_NODE_STATUS_MESSAGE_SIZE); + if (bc_res <= 0) + { + fprintf(stderr, "Could not broadcast node status; error %d\n", + bc_res); + } + } - { - static uint8_t transfer_id; - uint8_t payload[1]; - uint8_t dest_id = 2; - const int resp_res = -#if CANARD_ENABLE_CANFD - canardRequestOrRespond(&canard, dest_id, - UAVCAN_GET_NODE_INFO_DATA_TYPE_SIGNATURE, - UAVCAN_GET_NODE_INFO_DATA_TYPE_ID, - &transfer_id, - CANARD_TRANSFER_PRIORITY_LOW, CanardRequest, - payload, 0, canfd); -#else - canardRequestOrRespond(&canard, dest_id, - UAVCAN_GET_NODE_INFO_DATA_TYPE_SIGNATURE, - UAVCAN_GET_NODE_INFO_DATA_TYPE_ID, - &transfer_id, - CANARD_TRANSFER_PRIORITY_LOW, CanardRequest, - payload, 0); -#endif - if (resp_res <= 0) - { - fprintf(stderr, "Could not request GetNodeInfo; error %d\n", - resp_res); - } - } + { + static uint8_t transfer_id; + uint8_t payload[1]; + uint8_t dest_id = 2; + const int resp_res = + canardRequestOrRespond(&canard, dest_id, + UAVCAN_GET_NODE_INFO_DATA_TYPE_SIGNATURE, + UAVCAN_GET_NODE_INFO_DATA_TYPE_ID, &transfer_id, + CANARD_TRANSFER_PRIORITY_LOW, CanardRequest, + payload, 0); + if (resp_res <= 0) + { + fprintf(stderr, "Could not request GetNodeInfo; error %d\n", + resp_res); + } + } node_mode = UAVCAN_NODE_MODE_OPERATIONAL; } @@ -415,24 +365,17 @@ void process1HzTasks(uint64_t timestamp_usec) * Transmits all frames from the TX queue, receives up to one frame. * ****************************************************************************/ -#ifdef CONFIG_NET_CAN -void processTxRxOnce(SocketCANInstance *socketcan, int timeout_msec) -#else -void processTxRxOnce(CanardNuttXInstance *nuttxcan, int timeout_msec) -#endif + +void processTxRxOnce(CanardNuttXInstance * nuttxcan, int timeout_msec) { const CanardCANFrame *txf; /* Transmitting */ - for (txf = NULL; (txf = canardPeekTxQueue(&canard)) != NULL; ) + for (txf = NULL; (txf = canardPeekTxQueue(&canard)) != NULL;) { -#ifdef CONFIG_NET_CAN - const int tx_res = socketcanTransmit(socketcan, txf, 0); -#else const int tx_res = canardNuttXTransmit(nuttxcan, txf, 0); -#endif - if (tx_res < 0 && tx_res != -EAGAIN) /* Failure - drop the frame and report */ + if (tx_res < 0) /* Failure - drop the frame and report */ { canardPopTxQueue(&canard); fprintf(stderr, @@ -453,11 +396,7 @@ void processTxRxOnce(CanardNuttXInstance *nuttxcan, int timeout_msec) CanardCANFrame rx_frame; const uint64_t timestamp = getMonotonicTimestampUSec(); -#ifdef CONFIG_NET_CAN - const int rx_res = socketcanReceive(socketcan, &rx_frame, timeout_msec); -#else const int rx_res = canardNuttXReceive(nuttxcan, &rx_frame, timeout_msec); -#endif if (rx_res < 0) /* Failure - report */ { @@ -483,16 +422,12 @@ void processTxRxOnce(CanardNuttXInstance *nuttxcan, int timeout_msec) static int canard_daemon(int argc, char *argv[]) { -#ifdef CONFIG_NET_CAN - static SocketCANInstance socketcan; -#else static CanardNuttXInstance canardnuttx_instance; - int ret; -#endif #ifdef CONFIG_DEBUG_CAN struct canioc_bittiming_s bt; #endif int errval = 0; + int ret; /* Initialization of the CAN hardware is performed by external, board- * specific logic to running this test. @@ -500,33 +435,17 @@ static int canard_daemon(int argc, char *argv[]) /* Open the CAN device for reading */ - -#ifdef CONFIG_NET_CAN - const char * const can_iface_name = "can0"; - -# if CANARD_ENABLE_CANFD - int16_t res = socketcanInit(&socketcan, can_iface_name, canfd); -# else - int16_t res = socketcanInit(&socketcan, can_iface_name); -# endif - if (res < 0) - { - fprintf(stderr, "Failed to open CAN iface '%s'\n", can_iface_name); - return 1; - } -#else ret = canardNuttXInit(&canardnuttx_instance, - CONFIG_EXAMPLES_DRONECAN_DEVPATH); + CONFIG_EXAMPLES_LIBCANARD_DEVPATH); if (ret < 0) { printf("canard_daemon: ERROR: open %s failed: %d\n", - CONFIG_EXAMPLES_DRONECAN_DEVPATH, errno); + CONFIG_EXAMPLES_LIBCANARD_DEVPATH, errno); errval = 2; goto errout_with_dev; } -#endif -#if defined(CONFIG_CAN) && defined(CONFIG_DEBUG_CAN) +#ifdef CONFIG_DEBUG_CAN /* Show bit timing information if provided by the driver. Not all CAN * drivers will support this IOCTL. */ @@ -550,22 +469,17 @@ static int canard_daemon(int argc, char *argv[]) canardInit(&canard, canard_memory_pool, sizeof(canard_memory_pool), onTransferReceived, shouldAcceptTransfer, (void *)(12345)); - canardSetLocalNodeID(&canard, CONFIG_EXAMPLES_DRONECAN_NODE_ID); + canardSetLocalNodeID(&canard, CONFIG_EXAMPLES_LIBCANARD_NODE_ID); printf("canard_daemon: canard initialized\n"); - printf("start node (ID: %d Name: %s)\n", - CONFIG_EXAMPLES_DRONECAN_NODE_ID, + printf("start node (ID: %d Name: %s)\n", CONFIG_EXAMPLES_LIBCANARD_NODE_ID, APP_NODE_NAME); g_canard_daemon_started = true; uint64_t next_1hz_service_at = getMonotonicTimestampUSec(); - for (; ; ) + for (;;) { -#ifdef CONFIG_NET_CAN - processTxRxOnce(&socketcan, 10); -#else processTxRxOnce(&canardnuttx_instance, 10); -#endif const uint64_t ts = getMonotonicTimestampUSec(); @@ -576,10 +490,8 @@ static int canard_daemon(int argc, char *argv[]) } } -#ifdef CONFIG_CAN errout_with_dev: canardNuttXClose(&canardnuttx_instance); -#endif g_canard_daemon_started = false; printf("canard_daemon: Terminating!\n"); @@ -605,17 +517,8 @@ int main(int argc, FAR char *argv[]) return EXIT_SUCCESS; } -#if CANARD_ENABLE_CANFD - if (argc == 2 && strcmp(argv[1], "canfd") == 0) - { - printf("CAN FD mode enabled\n"); - canfd = true; - } -#endif - - ret = task_create("canard_daemon", - CONFIG_EXAMPLES_DRONECAN_DAEMON_PRIORITY, - CONFIG_EXAMPLES_DRONECAN_STACKSIZE, canard_daemon, + ret = task_create("canard_daemon", CONFIG_EXAMPLES_LIBCANARD_DAEMON_PRIORITY, + CONFIG_EXAMPLES_LIBCANARD_STACKSIZE, canard_daemon, NULL); if (ret < 0) { diff --git a/examples/capture/CMakeLists.txt b/examples/capture/CMakeLists.txt deleted file mode 100644 index e23ee56aa..000000000 --- a/examples/capture/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# ############################################################################## -# apps/examples/capture/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_CAPTURE) - nuttx_add_application( - NAME - cap - STACKSIZE - ${CONFIG_DEFAULT_TASK_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_CAPTURE} - SRCS - cap_main.c) -endif() diff --git a/examples/capture/Kconfig b/examples/capture/Kconfig deleted file mode 100644 index b5b5ba068..000000000 --- a/examples/capture/Kconfig +++ /dev/null @@ -1,36 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config EXAMPLES_CAPTURE - tristate "PWM Capture example" - default n - depends on CAPTURE - ---help--- - Enable the pwm capture example - -if EXAMPLES_CAPTURE - -config EXAMPLES_CAPTURE_DEVPATH - string "Capture device path" - default "/dev/capture0" - ---help--- - The default path to the capture device - -config EXAMPLES_CAPTURE_NSAMPLES - int "Number of samples" - default 0 - ---help--- - This number of samples is collected and the program - terminates. If the value is 0, samples are collected indefinitely. - -config EXAMPLES_CAPTURE_DELAY - int "Delay between samples" - default 100 - ---help--- - This value provides the delay (in milliseconds) between each sample. - If CONFIG_NSH_BUILTIN_APPS is defined, then this value is the default - delay if no other delay is provided on the command line. - -endif diff --git a/examples/capture/Make.defs b/examples/capture/Make.defs deleted file mode 100644 index 2e64699f4..000000000 --- a/examples/capture/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/examples/capture/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_EXAMPLES_CAPTURE),) -CONFIGURED_APPS += $(APPDIR)/examples/capture -endif diff --git a/examples/capture/Makefile b/examples/capture/Makefile deleted file mode 100644 index add205481..000000000 --- a/examples/capture/Makefile +++ /dev/null @@ -1,36 +0,0 @@ -############################################################################ -# apps/examples/capture/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -# PWM Input Capture Example. - -MAINSRC = cap_main.c - -# PWM input capture built-in application info - -PROGNAME = cap -PRIORITY = SCHED_PRIORITY_DEFAULT -STACKSIZE = $(CONFIG_DEFAULT_TASK_STACKSIZE) -MODULE = $(CONFIG_EXAMPLES_CAPTURE) - -include $(APPDIR)/Application.mk diff --git a/examples/capture/cap.h b/examples/capture/cap.h deleted file mode 100644 index 98c3a5e27..000000000 --- a/examples/capture/cap.h +++ /dev/null @@ -1,54 +0,0 @@ -/**************************************************************************** - * apps/examples/capture/cap.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __APPS_EXAMPLES_CAPTURE_QE_H -#define __APPS_EXAMPLES_CAPTURE_QE_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -struct cap_example_s -{ - FAR char *devpath; /* Path to the capture device */ - unsigned int nloops; /* Collect this number of samples */ - unsigned int delay; /* Delay this number of seconds between samples */ - int signo; /* Signal number to deliver on isr occur */ -}; - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -extern struct cap_example_s g_capexample; - -#endif /* __APPS_EXAMPLES_CAPTURE_QE_H */ diff --git a/examples/capture/cap_main.c b/examples/capture/cap_main.c deleted file mode 100644 index 1c44e0383..000000000 --- a/examples/capture/cap_main.c +++ /dev/null @@ -1,400 +0,0 @@ -/**************************************************************************** - * apps/examples/capture/cap_main.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <sys/types.h> -#include <sys/ioctl.h> - -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <string.h> -#include <fcntl.h> -#include <limits.h> -#include <inttypes.h> -#include <errno.h> -#include <nuttx/debug.h> - -#include <nuttx/timers/capture.h> - -#include "cap.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -struct cap_example_s g_capexample; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: cap_devpath - ****************************************************************************/ - -static void cap_devpath(FAR const char *devpath) -{ - /* Get rid of any old device path */ - - if (g_capexample.devpath) - { - free(g_capexample.devpath); - } - - /* The set-up the new device path by copying the string */ - - g_capexample.devpath = strdup(devpath); -} - -/**************************************************************************** - * Name: cap_help - ****************************************************************************/ - -static void cap_help(void) -{ - printf("\nUsage: cap [OPTIONS]\n\n"); - printf("OPTIONS include:\n"); - printf(" [-p devpath] Capture device path\n"); - printf(" [-n samples] Number of samples\n"); - printf(" [-t msec] Delay between samples (msec)\n"); -#ifdef CONFIG_CAPTURE_NOTIFY - printf(" [-w signo]: Wait for a signal if given " - "otherwise POLL mode if this is an interrupt pin.\n"); -#endif - printf(" [-h] Shows this message and exits\n\n"); -} - -/**************************************************************************** - * Name: arg_string - ****************************************************************************/ - -static int arg_string(FAR char **arg, FAR char **value) -{ - FAR char *ptr = *arg; - - if (ptr[2] == '\0') - { - *value = arg[1]; - return 2; - } - else - { - *value = &ptr[2]; - return 1; - } -} - -/**************************************************************************** - * Name: arg_decimal - ****************************************************************************/ - -static int arg_decimal(FAR char **arg, FAR long *value) -{ - FAR char *string; - int ret; - - ret = arg_string(arg, &string); - *value = strtol(string, NULL, 10); - return ret; -} - -/**************************************************************************** - * Name: parse_args - ****************************************************************************/ - -static void parse_args(int argc, FAR char **argv) -{ - FAR char *ptr; - FAR char *str; - long value; - int index; - int nargs; - - g_capexample.nloops = CONFIG_EXAMPLES_CAPTURE_NSAMPLES; - g_capexample.delay = CONFIG_EXAMPLES_CAPTURE_DELAY; - g_capexample.signo = 1; - - for (index = 1; index < argc; ) - { - ptr = argv[index]; - if (ptr[0] != '-') - { - printf("Invalid options format: %s\n", ptr); - exit(0); - } - - switch (ptr[1]) - { - case 'n': - nargs = arg_decimal(&argv[index], &value); - if (value < 0 || value > INT_MAX) - { - printf("Sample count out of range: %ld\n", value); - exit(1); - } - - g_capexample.nloops = (unsigned int)value; - index += nargs; - break; - - case 'p': - nargs = arg_string(&argv[index], &str); - cap_devpath(str); - index += nargs; - break; - - case 't': - nargs = arg_decimal(&argv[index], &value); - if (value < 0 || value > INT_MAX) - { - printf("Sample delay out of range: %ld\n", value); - exit(1); - } - - g_capexample.delay = (unsigned int)value; - index += nargs; - break; - -#ifdef CONFIG_CAPTURE_NOTIFY - case 'w': - nargs = arg_decimal(&argv[index], &value); - if (value < MIN_SIGNO || value > MAX_SIGNO) - { - printf("Wait signo out of range: %ld\n", value); - exit(1); - } - - g_capexample.signo = (int)value; - index += nargs; - break; -#endif - - case 'h': - cap_help(); - exit(EXIT_SUCCESS); - - default: - printf("Unsupported option: %s\n", ptr); - cap_help(); - exit(EXIT_FAILURE); - } - } -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: cap_main - ****************************************************************************/ - -int main(int argc, FAR char *argv[]) -{ - int8_t dutycycle; - int32_t frequency; - int32_t edges; - int fd; - int exitval = EXIT_SUCCESS; - int ret; - int nloops; -#ifdef CONFIG_CAPTURE_NOTIFY - struct cap_notify_s notify; - struct timespec ts; - sigset_t set; -#endif - - /* Set the default values */ - - cap_devpath(CONFIG_EXAMPLES_CAPTURE_DEVPATH); - - /* Parse command line arguments */ - - parse_args(argc, argv); - - /* Open the capture device for reading */ - - printf("cap_main: Hardware initialized. Opening the capture device: %s\n", - g_capexample.devpath); - - fd = open(g_capexample.devpath, O_RDONLY); - if (fd < 0) - { - printf("cap_main: open %s failed: %d\n", g_capexample.devpath, errno); - exitval = EXIT_FAILURE; - goto errout; - } - -#ifdef CONFIG_CAPTURE_NOTIFY - notify.chan = 0; - notify.type = CAP_TYPE_BOTH; - - notify.event.sigev_notify = SIGEV_SIGNAL; - notify.event.sigev_signo = g_capexample.signo; - - ret = ioctl(fd, CAPIOC_REGISTER, (unsigned long)¬ify); - if (ret < 0) - { - printf("cap_main: ioctl(GPIOC_REGISTER) failed: %d\n", errno); - exitval = EXIT_FAILURE; - goto errout_with_dev; - } - - /* Wait up to 5 seconds for the signal */ - - sigemptyset(&set); - sigaddset(&set, g_capexample.signo); - - ts.tv_sec = 5; - ts.tv_nsec = 0; - - ret = sigtimedwait(&set, NULL, &ts); - ioctl(fd, CAPIOC_UNREGISTER, notify.chan); - if (ret < 0) - { - int errcode = errno; - if (errcode == EAGAIN) - { - printf("cpu_main: Five second timeout with no signal\n"); - exitval = EXIT_FAILURE; - goto errout_with_dev; - } - else - { - printf("cpu_main: ERROR: Failed to wait signal %d " - "from %s: %d\n", g_capexample.signo, g_capexample.devpath, - errcode); - exitval = EXIT_FAILURE; - goto errout_with_dev; - } - } - else - { - printf("cap_main: Received signal %d from %s\n", - g_capexample.signo, g_capexample.devpath); - } -#endif - - /* Now loop the appropriate number of times, displaying the collected - * encoder samples. - */ - - printf("cap_main: Number of samples: %u\n", g_capexample.nloops); - for (nloops = 0; - !g_capexample.nloops || nloops < g_capexample.nloops; - nloops++) - { - /* Flush any output before the loop entered or from the previous pass - * through the loop. - */ - - fflush(stdout); - - /* Get the dutycycle data using the ioctl */ - - ret = ioctl(fd, CAPIOC_DUTYCYCLE, - (unsigned long)((uintptr_t)&dutycycle)); - if (ret < 0) - { - printf("cap_main: ioctl(CAPIOC_DUTYCYCLE) failed: %d\n", errno); - exitval = EXIT_FAILURE; - goto errout_with_dev; - } - - /* Print the sample data on successful return */ - - else - { - printf("pwm duty cycle: %d %% \n", dutycycle); - } - - /* Get the frequency data using the ioctl */ - - ret = ioctl(fd, CAPIOC_FREQUENCY, - (unsigned long)((uintptr_t)&frequency)); - if (ret < 0) - { - printf("cap_main: ioctl(CAPIOC_FREQUENCY) failed: %d\n", errno); - exitval = EXIT_FAILURE; - goto errout_with_dev; - } - - /* Print the sample data on successful return */ - - else - { - printf("pwm frequency: %"PRId32" Hz \n", frequency); - } - - /* Get the edges data using the ioctl */ - - ret = ioctl(fd, CAPIOC_EDGES, - (unsigned long)((uintptr_t)&edges)); - if (ret < 0) - { - printf("cap_main: ioctl(CAPIOC_EDGES) failed: %d\n", errno); - exitval = EXIT_FAILURE; - goto errout_with_dev; - } - - /* Print the sample data on successful return */ - - else - { - printf("pwm edges counting: %"PRId32" \n", edges); - } - - /* Delay a little bit */ - - usleep(g_capexample.delay * 1000); - } - -errout_with_dev: - close(fd); - -errout: - printf("Terminating!\n"); - fflush(stdout); - return exitval; -} diff --git a/examples/cbortest/CMakeLists.txt b/examples/cbortest/CMakeLists.txt deleted file mode 100644 index 01557a340..000000000 --- a/examples/cbortest/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# ############################################################################## -# apps/examples/cbortest/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_TINYCBOR_TEST) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_TINYCBOR_TEST_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_TINYCBOR_TEST_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_TINYCBOR_TEST_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_TINYCBOR_TEST} - SRCS - cbortest_main.c) -endif() diff --git a/examples/cbortest/Kconfig b/examples/cbortest/Kconfig deleted file mode 100644 index 5c6cb6870..000000000 --- a/examples/cbortest/Kconfig +++ /dev/null @@ -1,30 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config EXAMPLES_TINYCBOR_TEST - tristate "TinyCBOR Test Example" - default n - depends on FSUTILS_TINYCBOR_LIB - ---help--- - Enable the TinyCBOR test example - -if EXAMPLES_TINYCBOR_TEST - -config EXAMPLES_TINYCBOR_TEST_PROGNAME - string "Program name" - default "cbor" - ---help--- - This is the name of the program that will be used when the NSH ELF - program is installed. - -config EXAMPLES_TINYCBOR_TEST_PRIORITY - int "TINYCBOR_TEST task priority" - default 100 - -config EXAMPLES_TINYCBOR_TEST_STACKSIZE - int "TINYCBOR_TEST stack size" - default DEFAULT_TASK_STACKSIZE - -endif diff --git a/examples/cbortest/Make.defs b/examples/cbortest/Make.defs deleted file mode 100644 index a4844be9d..000000000 --- a/examples/cbortest/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/examples/cbortest/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_EXAMPLES_TINYCBOR_TEST),) -CONFIGURED_APPS += $(APPDIR)/examples/cbortest -endif diff --git a/examples/cbortest/Makefile b/examples/cbortest/Makefile deleted file mode 100644 index 01061a201..000000000 --- a/examples/cbortest/Makefile +++ /dev/null @@ -1,36 +0,0 @@ -############################################################################ -# apps/examples/cbortest/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -# TINYCBOR_TEST built-in application info - -PROGNAME = $(CONFIG_EXAMPLES_TINYCBOR_TEST_PROGNAME) -PRIORITY = $(CONFIG_EXAMPLES_TINYCBOR_TEST_PRIORITY) -STACKSIZE = $(CONFIG_EXAMPLES_TINYCBOR_TEST_STACKSIZE) -MODULE = $(CONFIG_EXAMPLES_TINYCBOR_TEST) - -# TINYCBOR_TEST Example - -MAINSRC = cbortest_main.c - -include $(APPDIR)/Application.mk diff --git a/examples/cbortest/cbortest_main.c b/examples/cbortest/cbortest_main.c deleted file mode 100644 index 1ce7ccee5..000000000 --- a/examples/cbortest/cbortest_main.c +++ /dev/null @@ -1,113 +0,0 @@ -/**************************************************************************** - * apps/examples/cbortest/cbortest_main.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <stdio.h> -#include <fcntl.h> -#include <wchar.h> -#include <syslog.h> -#include <unistd.h> - -#include "tinycbor/cbor.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define MINMEA_MAX_LENGTH 256 - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * cbortest_main - ****************************************************************************/ - -int main(int argc, FAR char *argv[]) -{ - CborError res; - CborEncoder encoder; - CborEncoder map_encoder; - uint8_t output[50]; - size_t output_len; - int i; - - printf("TinyCBOR test: Encoding { \"t\": 1234 }\n"); - - /* Init our CBOR Encoder */ - - cbor_encoder_init(&encoder, output, sizeof(output), 0); - - /* Create a Map Encoder that maps keys to values, 1 = Key-Value Pairs */ - - res = cbor_encoder_create_map(&encoder, &map_encoder, 1); - - /* Check for any error */ - - assert(res == CborNoError); - - /* First Key-Value Pair: Map the Key */ - - res = cbor_encode_text_stringz(&map_encoder, "t"); - - /* Check for any error */ - - assert(res == CborNoError); - - /* First Key-Value Pair: Map the Value */ - - res = cbor_encode_int(&map_encoder, 1234); - - /* Check for any error */ - - assert(res == CborNoError); - - /* Close the Map Encoder */ - - res = cbor_encoder_close_container(&encoder, &map_encoder); - - /* Check for any error */ - - assert(res == CborNoError); - - /* How many bytes were encoded */ - - output_len = cbor_encoder_get_buffer_size(&encoder, output); - printf("CBOR Output: %d bytes\n", output_len); - - /* Dump the encoded CBOR output (6 bytes): */ - - printf("Expected sequence: 0xa1 0x61 0x74 0x19 0x04 0xd2\n"); - - for (i = 0; i < output_len; i++) - { - printf(" 0x%02x\n", output[i]); - } - - return 0; -} diff --git a/examples/cctype/CMakeLists.txt b/examples/cctype/CMakeLists.txt deleted file mode 100644 index 921d91a6c..000000000 --- a/examples/cctype/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# ############################################################################## -# apps/examples/cctype/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_CCTYPE) - nuttx_add_application( - NAME - cctype - STACKSIZE - ${CONFIG_DEFAULT_TASK_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_CCTYPE} - SRCS - cctype_main.cxx) -endif() diff --git a/examples/cctype/Make.defs b/examples/cctype/Make.defs index f1cdcd34e..30174b5fd 100644 --- a/examples/cctype/Make.defs +++ b/examples/cctype/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/cctype/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/cctype/Makefile b/examples/cctype/Makefile index c58e8326f..bd7bbee1d 100644 --- a/examples/cctype/Makefile +++ b/examples/cctype/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/cctype/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/cctype/cctype_main.cxx b/examples/cctype/cctype_main.cxx index 680143563..27b885fdc 100644 --- a/examples/cctype/cctype_main.cxx +++ b/examples/cctype/cctype_main.cxx @@ -1,8 +1,6 @@ //*************************************************************************** // apps/examples/cctype/cctype_main.cxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The diff --git a/examples/charger/CMakeLists.txt b/examples/charger/CMakeLists.txt deleted file mode 100644 index 54a332076..000000000 --- a/examples/charger/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# ############################################################################## -# apps/examples/charger/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_CHARGER) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_CHARGER_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_CHARGER_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_CHARGER_STACKSIZE} - SRCS - charger_main.c) -endif() diff --git a/examples/charger/Kconfig b/examples/charger/Kconfig index ae95d4a65..94629bed3 100644 --- a/examples/charger/Kconfig +++ b/examples/charger/Kconfig @@ -1,7 +1,3 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# config EXAMPLES_CHARGER bool "Battery charger example" diff --git a/examples/charger/Make.defs b/examples/charger/Make.defs index 2e9d48467..43855e252 100644 --- a/examples/charger/Make.defs +++ b/examples/charger/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/charger/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -20,6 +18,6 @@ # ############################################################################ -ifneq ($(CONFIG_EXAMPLES_CHARGER),) +ifeq ($(CONFIG_EXAMPLES_CHARGER),y) CONFIGURED_APPS += examples/charger endif diff --git a/examples/charger/Makefile b/examples/charger/Makefile index a9f536611..28f4e2364 100644 --- a/examples/charger/Makefile +++ b/examples/charger/Makefile @@ -1,26 +1,6 @@ -############################################################################ -# apps/examples/charger/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ include $(APPDIR)/Make.defs +-include $(SDKDIR)/Make.defs PROGNAME = $(CONFIG_EXAMPLES_CHARGER_PROGNAME) PRIORITY = $(CONFIG_EXAMPLES_CHARGER_PRIORITY) diff --git a/examples/charger/charger_main.c b/examples/charger/charger_main.c index 2184ea9d5..84b4bb8a7 100644 --- a/examples/charger/charger_main.c +++ b/examples/charger/charger_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/charger/charger_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -231,8 +229,8 @@ int main(int argc, FAR char *argv[]) } gettimeofday(&tv, NULL); - printf("%jd.%06ld: %d mV, %d mA\n", - (intmax_t)tv.tv_sec, tv.tv_usec, voltage, current); + printf("%ju.%06ld: %d mV, %d mA\n", + (uintmax_t)tv.tv_sec, tv.tv_usec, voltage, current); close(fd); diff --git a/examples/chat/CMakeLists.txt b/examples/chat/CMakeLists.txt deleted file mode 100644 index b63991ab2..000000000 --- a/examples/chat/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# ############################################################################## -# apps/examples/chat/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_CHAT) - nuttx_add_application( - NAME - chat - STACKSIZE - ${CONFIG_DEFAULT_TASK_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_CHAT} - SRCS - chat_main.c) -endif() diff --git a/examples/chat/Make.defs b/examples/chat/Make.defs index 6f5f9498d..8725d60f1 100644 --- a/examples/chat/Make.defs +++ b/examples/chat/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/chat/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/chat/Makefile b/examples/chat/Makefile index c4d1d90cc..5c30573de 100644 --- a/examples/chat/Makefile +++ b/examples/chat/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/chat/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/chat/chat_main.c b/examples/chat/chat_main.c index 291e88824..18d176614 100644 --- a/examples/chat/chat_main.c +++ b/examples/chat/chat_main.c @@ -1,9 +1,8 @@ /**************************************************************************** * apps/examples/chat/chat_main.c * - * SPDX-License-Identifier: BSD-3-Clause - * SPDX-FileCopyrightText: 2016 Vladimir Komendantskiy. All rights reserved. - * SPDX-FileContributor: Vladimir Komendantskiy <vladimir@moixaenergy.com> + * Copyright (C) 2016 Vladimir Komendantskiy. All rights reserved. + * Author: Vladimir Komendantskiy <vladimir@moixaenergy.com> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -45,7 +44,7 @@ #include <sys/ioctl.h> #include <assert.h> -#include <nuttx/debug.h> +#include <debug.h> #include <errno.h> #include <fcntl.h> #include <poll.h> @@ -257,7 +256,9 @@ static int chat_parse_args(FAR struct chat_app *priv) /* set the TTY device node */ - strlcpy(priv->tty, priv->argv[i] + 2, CHAT_TTYNAME_SIZE); + strncpy(priv->tty, + (FAR char *)priv->argv[i] + 2, + CHAT_TTYNAME_SIZE - 1); break; case 'e': @@ -265,11 +266,13 @@ static int chat_parse_args(FAR struct chat_app *priv) break; case 'f': - ret = chat_script_read(priv, priv->argv[i] + 2); + ret = chat_script_read(priv, + (FAR char *)priv->argv[i] + 2); break; case 'p': - numarg = strtol(priv->argv[i] + 2, NULL, 10); + numarg = strtol((FAR char *)priv->argv[i] + 2, + NULL, 10); if (errno < 0) { ret = -EINVAL; @@ -280,7 +283,8 @@ static int chat_parse_args(FAR struct chat_app *priv) break; case 't': - numarg = strtol(priv->argv[i] + 2, NULL, 10); + numarg = strtol((FAR char *)priv->argv[i] + 2, + NULL, 10); if (errno < 0 || numarg < 0) { @@ -332,7 +336,7 @@ int main(int argc, FAR char **argv) priv.ctl.timeout = CONFIG_EXAMPLES_CHAT_TIMEOUT_SECONDS; priv.script = NULL; priv.script_dynalloc = false; - strlcpy(priv.tty, CONFIG_EXAMPLES_CHAT_TTY_DEVNODE, CHAT_TTYNAME_SIZE); + strncpy(priv.tty, CONFIG_EXAMPLES_CHAT_TTY_DEVNODE, CHAT_TTYNAME_SIZE - 1); _info("parsing the arguments\n"); ret = chat_parse_args((FAR struct chat_app *)&priv); diff --git a/examples/chrono/CMakeLists.txt b/examples/chrono/CMakeLists.txt deleted file mode 100644 index e4523875e..000000000 --- a/examples/chrono/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# ############################################################################## -# apps/examples/chrono/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_CHRONO) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_CHRONO_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_CHRONO_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_CHRONO_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_CHRONO} - SRCS - chrono_main.c) -endif() diff --git a/examples/chrono/Kconfig b/examples/chrono/Kconfig index 324f0c452..26c02ee44 100644 --- a/examples/chrono/Kconfig +++ b/examples/chrono/Kconfig @@ -6,7 +6,6 @@ config EXAMPLES_CHRONO tristate "Chronometer example to use with STM32LDiscover" default n - depends on SLCD && ENABLE_ALL_SIGNALS ---help--- Enable the Chronometer example diff --git a/examples/chrono/Make.defs b/examples/chrono/Make.defs index ff5723527..8577d8536 100644 --- a/examples/chrono/Make.defs +++ b/examples/chrono/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/chrono/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/chrono/Makefile b/examples/chrono/Makefile index 5cec2e30d..f28079cef 100644 --- a/examples/chrono/Makefile +++ b/examples/chrono/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/chrono/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/chrono/chrono_main.c b/examples/chrono/chrono_main.c index 9ce5dbb58..11a77051b 100644 --- a/examples/chrono/chrono_main.c +++ b/examples/chrono/chrono_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/chrono/chrono_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -34,7 +32,6 @@ #include <fcntl.h> #include <errno.h> #include <time.h> -#include <unistd.h> #include <sys/time.h> #include <nuttx/input/buttons.h> @@ -46,7 +43,7 @@ * Pre-processor Definitions ****************************************************************************/ -#define BUTTON_SIGNO 32 +#define BUTTON_SIGNO 13 #define BUTTON_STACKSIZE 2048 #define BUTTON_PRIORITY 100 #define BUTTON_DEVPATH "/dev/buttons" @@ -165,11 +162,9 @@ static int chrono_daemon(int argc, char *argv[]) goto errout_with_fd; } -#ifdef CONFIG_ENABLE_ALL_SIGNALS /* Ignore the default signal action */ signal(BUTTON_SIGNO, SIG_IGN); -#endif /* Now loop forever, waiting BUTTONs events */ @@ -212,6 +207,7 @@ errout_with_fd: close(fd); errout: + printf("chrono_daemon: Terminating\n"); return EXIT_FAILURE; } @@ -347,7 +343,7 @@ int main(int argc, FAR char *argv[]) /* Initialize the output stream */ memset(priv, 0, sizeof(struct slcd_chrono_s)); - priv->stream.putc = slcd_putc; + priv->stream.put = slcd_putc; #ifdef CONFIG_STDIO_LINEBUFFER priv->stream.flush = slcd_flush; #endif diff --git a/examples/configdata/CMakeLists.txt b/examples/configdata/CMakeLists.txt deleted file mode 100644 index 3047383c0..000000000 --- a/examples/configdata/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# ############################################################################## -# apps/examples/configdata/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_CONFIGDATA) - nuttx_add_application( - NAME - configdata - STACKSIZE - ${CONFIG_DEFAULT_TASK_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_CONFIGDATA} - SRCS - configdata_main.c) -endif() diff --git a/examples/configdata/Make.defs b/examples/configdata/Make.defs index 61e3f1554..0db814b6b 100644 --- a/examples/configdata/Make.defs +++ b/examples/configdata/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/configdata/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/configdata/Makefile b/examples/configdata/Makefile index 8e6fba943..c27eb6b75 100644 --- a/examples/configdata/Makefile +++ b/examples/configdata/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/configdata/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/configdata/configdata_main.c b/examples/configdata/configdata_main.c index 007a9d162..6d230b201 100644 --- a/examples/configdata/configdata_main.c +++ b/examples/configdata/configdata_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/configdata/configdata_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -35,9 +33,9 @@ #include <fcntl.h> #include <string.h> #include <errno.h> -#include <nuttx/debug.h> +#include <crc32.h> +#include <debug.h> -#include <nuttx/crc32.h> #include <nuttx/mtd/mtd.h> #include <nuttx/mtd/configdata.h> #include <nuttx/fs/ioctl.h> @@ -304,7 +302,7 @@ static inline int config.instance = entry->instance; config.len = entry->len; config.configdata = g_entryimage; - ret = ioctl(g_fd, CFGDIOC_SETCONFIG, (unsigned long)&config); + ret = ioctl(g_fd, CFGDIOC_SETCONFIG, (unsigned long) &config); if (ret < 0) { entry->id = 0; @@ -370,7 +368,7 @@ static inline int config.instance = entry->instance; config.len = entry->len; config.configdata = g_entryimage; - ret = ioctl(g_fd, CFGDIOC_GETCONFIG, (unsigned long)&config); + ret = ioctl(g_fd, CFGDIOC_GETCONFIG, (unsigned long) &config); if (ret < 0) { return ERROR; @@ -401,9 +399,11 @@ static int configdata_verifyconfig(void) int ret; int errcode = OK; int i; + static int iteration = 0; /* Create a file for each unused file structure */ + iteration++; for (i = 0; i < CONFIG_EXAMPLES_CONFIGDATA_MAXENTRIES; i++) { entry = &g_entries[i]; @@ -450,7 +450,7 @@ static int configdata_verifyconfig(void) { g_nverified++; #if CONFIG_EXAMPLES_CONFIGDATA_VERBOSE != 0 - printf(" Verified entry %04X, %d\n", + printf(" Verifed entry %04X, %d\n", entry->id, entry->instance); #endif } @@ -664,7 +664,7 @@ int main(int argc, FAR char *argv[]) /* Open the /dev/config device */ - g_fd = open("/dev/config", O_RDONLY); + g_fd = open("/dev/config", O_RDOK); if (g_fd == -1) { printf("ERROR: Failed to open /dev/config %d\n", -errno); diff --git a/examples/cordic/CMakeLists.txt b/examples/cordic/CMakeLists.txt deleted file mode 100644 index e303d8b96..000000000 --- a/examples/cordic/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# ############################################################################## -# apps/examples/cordic/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_CORDIC) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_CORDIC_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_CORDIC_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_CORDIC_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_CORDIC} - SRCS - cordic_main.c) -endif() diff --git a/examples/cordic/Make.defs b/examples/cordic/Make.defs index b1342b638..7494f87ec 100644 --- a/examples/cordic/Make.defs +++ b/examples/cordic/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/cordic/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/cordic/Makefile b/examples/cordic/Makefile index 18344c92c..c58d75a75 100644 --- a/examples/cordic/Makefile +++ b/examples/cordic/Makefile @@ -1,7 +1,5 @@ ############################################################################ -# apps/examples/cordic/Makefile -# -# SPDX-License-Identifier: Apache-2.0 +# apps/examples/cordic/Make.defs # # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with diff --git a/examples/cordic/cordic_main.c b/examples/cordic/cordic_main.c index 3d4aede0c..fe128a7d5 100644 --- a/examples/cordic/cordic_main.c +++ b/examples/cordic/cordic_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/cordic/cordic_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -35,7 +33,7 @@ #include <string.h> #include <fcntl.h> #include <errno.h> -#include <nuttx/debug.h> +#include <debug.h> #include <math.h> #include <fixedmath.h> diff --git a/examples/cpuhog/CMakeLists.txt b/examples/cpuhog/CMakeLists.txt deleted file mode 100644 index c9995e7c9..000000000 --- a/examples/cpuhog/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# ############################################################################## -# apps/examples/cpuhog/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_CPUHOG) - nuttx_add_application( - NAME - cpuhog - PRIORITY - ${CONFIG_EXAMPLES_CPUHOG_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_CPUHOG_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_CPUHOG} - SRCS - cpuhog_main.c) -endif() diff --git a/examples/cpuhog/Make.defs b/examples/cpuhog/Make.defs index c15cb779e..a80cad304 100644 --- a/examples/cpuhog/Make.defs +++ b/examples/cpuhog/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/cpuhog/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/cpuhog/Makefile b/examples/cpuhog/Makefile index 8fa589e58..2f1214930 100644 --- a/examples/cpuhog/Makefile +++ b/examples/cpuhog/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/cpuhog/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/cpuhog/cpuhog_main.c b/examples/cpuhog/cpuhog_main.c index 6a45ddad0..2c8d77344 100644 --- a/examples/cpuhog/cpuhog_main.c +++ b/examples/cpuhog/cpuhog_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/cpuhog/cpuhog_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/cromfs/CMakeLists.txt b/examples/cromfs/CMakeLists.txt deleted file mode 100644 index 9c06bf855..000000000 --- a/examples/cromfs/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -# ############################################################################## -# apps/examples/cromfs/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_CROMFS) - nuttx_add_cromfs(NAME example_cromfs PATH ${CMAKE_CURRENT_LIST_DIR}/cromfs) -endif() diff --git a/examples/cromfs/Make.defs b/examples/cromfs/Make.defs index dbf0dbeb0..f95a7f623 100644 --- a/examples/cromfs/Make.defs +++ b/examples/cromfs/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/cromfs/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/cromfs/Makefile b/examples/cromfs/Makefile index 96078719e..161736d29 100644 --- a/examples/cromfs/Makefile +++ b/examples/cromfs/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/cromfs/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/dac/CMakeLists.txt b/examples/dac/CMakeLists.txt deleted file mode 100644 index 854199b9a..000000000 --- a/examples/dac/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# ############################################################################## -# apps/examples/dac/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_DAC) - nuttx_add_application( - NAME - dac - STACKSIZE - ${CONFIG_DEFAULT_TASK_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_DAC} - SRCS - dac_main.c) -endif() diff --git a/examples/dac/Make.defs b/examples/dac/Make.defs index 9e5350817..a86d75824 100644 --- a/examples/dac/Make.defs +++ b/examples/dac/Make.defs @@ -1,25 +1,3 @@ -############################################################################ -# apps/examples/dac/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - ifneq ($(CONFIG_EXAMPLES_DAC),) CONFIGURED_APPS += $(APPDIR)/examples/dac endif diff --git a/examples/dac/Makefile b/examples/dac/Makefile index 3f983939f..ea26dea9d 100644 --- a/examples/dac/Makefile +++ b/examples/dac/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/dac/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/dac/dac_main.c b/examples/dac/dac_main.c index 050cc0f80..14b9942ba 100644 --- a/examples/dac/dac_main.c +++ b/examples/dac/dac_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/dac/dac_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -34,7 +32,6 @@ #include <unistd.h> #include <sys/ioctl.h> -#include <sys/param.h> #include <nuttx/analog/dac.h> #include <nuttx/arch.h> @@ -50,12 +47,9 @@ # define CONFIG_EXAMPLES_DAC_DEVPATH "/dev/dac0" #endif -#define DEFAULT_COUNT 1 -#define DEFAULT_DELAY 0 -#define DEFAULT_CHANNEL 0 -#define DEFAULT_TEST_BIT_RES 8 -#define DEFAULT_TEST_STEP 8 -#define DEFAULT_INITIALIZED true +#ifndef ARRAY_SIZE +# define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) +#endif /**************************************************************************** * Private Types @@ -64,8 +58,8 @@ struct command { FAR const char *name; - CODE int (* const cmd)(int argc, FAR const char *argv[]); - FAR const char *args; + CODE int (* const cmd)(int argc, const char *argv[]); + const char *args; }; struct dac_state_s @@ -74,8 +68,6 @@ struct dac_state_s int count; int delay; uint8_t channel; - int test_bit_res; - int test_step; bool initialized; }; @@ -85,7 +77,6 @@ struct dac_state_s static int cmd_dac_put(int argc, FAR const char *argv[]); static int cmd_dac_putv(int argc, FAR const char *argv[]); -static int cmd_dac_test(int argc, FAR const char *argv[]); /**************************************************************************** * Private Data @@ -95,7 +86,6 @@ static const struct command commands[] = { { "put", cmd_dac_put, "DATA [DELAY]" }, { "putv", cmd_dac_putv, "DATA [DATA...]" }, - { "test", cmd_dac_test, "" }, }; static struct dac_state_s g_dacstate; @@ -104,25 +94,6 @@ static struct dac_state_s g_dacstate; * Private Functions ****************************************************************************/ -/**************************************************************************** - * Name: dac_devpath - * - * Description: - * Update the DAC device path in the DAC state structure. This function - * manages memory allocation for the device path and frees the previous - * path if it exists. - * - * Input Parameters: - * dac - Pointer to the DAC state structure. - * devpath - New DAC device path to be set. - * - * Operation: - * - Frees the existing DAC device path if it exists. - * - Allocates memory for the new DAC device path. - * - Updates the device path in the DAC state structure. - * - ****************************************************************************/ - static void dac_devpath(FAR struct dac_state_s *dac, FAR const char *devpath) { @@ -134,34 +105,12 @@ static void dac_devpath(FAR struct dac_state_s *dac, dac->devpath = strdup(devpath); } -/**************************************************************************** - * Name: print_cmds - * - * Description: - * Print a list of commands with their names, arguments, and a given header - * and trailer. This function is used to display available - * commands and their usage information. - * - * Input Parameters: - * header - Header string to be printed before the command list. - * cmds - Pointer to an array of command structures. - * ncmds - Number of commands in the array. - * trailer - Trailer string to be printed after the command list. - * - * Operation: - * - Prints the header. - * - Iterates through the array of command structures and prints - * their names, arguments, and a newline character after each command. - * - Prints the trailer. - * - ****************************************************************************/ - static void print_cmds(FAR const char *header, FAR const struct command *cmds, size_t ncmds, FAR const char *trailer) { - printf("%s", header); + printf(header); while (ncmds--) { printf(" %s %s %c", cmds->name, cmds->args, @@ -169,32 +118,9 @@ static void print_cmds(FAR const char *header, cmds++; } - printf("%s", trailer); + printf(trailer); } -/**************************************************************************** - * Name: find_cmd - * - * Description: - * Find a command structure in an array of commands by comparing command - * names. - * - * Input Parameters: - * name - Name of the command to be found. - * cmds - Pointer to an array of command structures. - * ncmds - Number of commands in the array. - * - * Returned Value: - * Returns a pointer to the found command structure if successful; NULL - * if the command is not found. - * - * Operation: - * - Iterates through the array of command structures. - * - Compares the name of each command with the specified name. - * - Returns a pointer to the found command structure or NULL if not found. - * - ****************************************************************************/ - static const struct command *find_cmd(FAR const char *name, FAR const struct command *cmds, size_t ncmds) @@ -212,30 +138,6 @@ static const struct command *find_cmd(FAR const char *name, return NULL; } -/**************************************************************************** - * Name: execute_cmd - * - * Description: - * Execute a command function based on the command name. - * This function finds the corresponding command structure in the - * array and invokes the associated function. - * - * Input Parameters: - * argc - Number of command-line arguments. - * argv - Array of command-line argument strings. - * cmds - Pointer to an array of command structures. - * ncmds - Number of commands in the array. - * - * Returned Value: - * Returns the result of the executed command function. - * - * Operation: - * - Finds the command structure for the specified command name. - * - Invokes the associated command function with the provided arguments. - * - Prints an error message if the command is not found. - * - ****************************************************************************/ - static int execute_cmd(int argc, FAR const char *argv[], FAR const struct command *cmds, @@ -254,35 +156,6 @@ static int execute_cmd(int argc, return cmd->cmd(argc - 1, argv + 1); } -/**************************************************************************** - * Name: dac_put - * - * Description: - * Write DAC messages to the specified DAC device. This function writes - * multiple DAC messages, allowing the configuration of DAC channel and - * data values. It handles potential write retries in case of non-blocking - * write operations and provides debug information about the write process. - * - * Input Parameters: - * devpath - Path to the DAC device. - * msg - Pointer to an array of DAC messages to be written. - * nmsgs - Number of DAC messages in the array. - * delay - Delay between writes in milliseconds. - * - * Returned Value: - * Returns the number of successfully written messages on success; a - * negated errno value on failure. - * - * Operation: - * - Opens the specified DAC device for writing. - * - Iterates through the array of DAC messages and writes - * them to the device. - * - Handles non-blocking writes, retries on EAGAIN, and provides - * debug output. - * - Closes the DAC device after completing the write operations. - * - ****************************************************************************/ - static int dac_put(FAR const char *devpath, FAR struct dac_msg_s *msg, size_t nmsgs, @@ -333,32 +206,6 @@ static int dac_put(FAR const char *devpath, return (i > 0) ? i : ret; } -/**************************************************************************** - * Name: cmd_dac_put - * - * Description: - * Execute the 'put' command, writing a specified DAC value to the DAC - * device. - * - * Input Parameters: - * argc - Number of command-line arguments. - * argv - Array of command-line argument strings. - * - * Returned Value: - * Returns OK on success; a negated errno value on failure. - * - * Operation: - * - Parses the command-line arguments to extract the DAC value and delay. - * - Overrides the "sticky" delay option if provided in the arguments. - * - Repeats the DAC write operation for the specified number of times. - * - * Usage: - * `put [value] [delay]`: Write the specified DAC value to the device. - * - [value]: DAC value to be written (Default: 100). - * - [delay]: Delay between writes in milliseconds. - * - ****************************************************************************/ - static int cmd_dac_put(int argc, FAR const char *argv[]) { struct dac_msg_s msgs[1]; @@ -379,35 +226,13 @@ static int cmd_dac_put(int argc, FAR const char *argv[]) { msgs[0].am_channel = g_dacstate.channel; msgs[0].am_data = data; - ret = dac_put(g_dacstate.devpath, msgs, nitems(msgs), delay); + ret = dac_put(g_dacstate.devpath, msgs, ARRAY_SIZE(msgs), delay); printf("ret=%d\n", ret); } return ret; } -/**************************************************************************** - * Name: cmd_dac_putv - * - * Description: - * Execute the 'putv' command, writing DAC values specified in the command - * arguments to the DAC device. The command supports writing - * multiple values in a single execution. - * - * Input Parameters: - * argc - Number of command-line arguments. - * argv - Array of command-line argument strings. - * - * Returned Value: - * Returns OK on success; a negated errno value on failure. - * - * Operation: - * - Parses the command-line arguments to extract DAC values. - * - Constructs DAC messages with the specified channel and data values. - * - Repeats the DAC write operation for the specified number of times. - * - ****************************************************************************/ - static int cmd_dac_putv(int argc, FAR const char *argv[]) { struct dac_msg_s msgs[CONFIG_NSH_MAXARGUMENTS]; @@ -435,105 +260,6 @@ static int cmd_dac_putv(int argc, FAR const char *argv[]) return ret; } -/**************************************************************************** - * Name: cmd_dac_test - * - * Description: - * Perform DAC testing by generating a sequence of values and writing them - * to the DAC device specified in the global DAC state structure. - * - * Input Parameters: - * argc - Number of arguments in argv. - * argv - Array of command-line argument strings. - * - * Returned Value: - * Total return value, the sum of return values from write calls. Returns - * a negative errno on failure. - * - * Note: Utilizing the parameters can make testing much easier. If you are - * testing with one config test, you can change the constant definition for - * default value at the top and simply run `nsh> dat test` - * If you want setup for multimeter testing, set appropriate delay between - * writes (in ms). Example for 8 bit DAC using step in value of 16 - * nsh> dac -d 5000 -b 8 -s 16 test - * Example for oscilloscope test for 12 bit DAC: - * nsh> dac -d 10 -b 12 -s 4 test - * - ****************************************************************************/ - -static int cmd_dac_test(int argc, FAR const char *argv[]) -{ - struct dac_msg_s msg; - int fd; - int i; - bool count_up; - uint32_t value = 0; - uint32_t max_value = (1 << g_dacstate.test_bit_res); - int ret = OK; - int total_ret = 0; - - fd = open(g_dacstate.devpath, O_WRONLY | O_NONBLOCK); - if (fd < 0) - { - fprintf(stderr, "ERROR: open() failed: %d\n", errno); - return -ENODEV; - } - - for (i = 0; i < g_dacstate.count; i++) - { - count_up = true; - value = 0; - while (count_up || value) - { - msg.am_channel = g_dacstate.channel; - msg.am_data = value; - - if (count_up) - { - value += g_dacstate.test_step; - if (value >= max_value - 1) - { - value = max_value - 1; - count_up = false; - } - } - else - { - value -= g_dacstate.test_step; - - /* Check if value is underflow */ - - if (value > UINT32_MAX - g_dacstate.test_step) - { - value = 0; - } - } - - ret = write(fd, &msg, sizeof(struct dac_msg_s)); - total_ret += ret; - usleep(1000 * g_dacstate.delay); - } - } - - close(fd); - - return total_ret; -} - -/**************************************************************************** - * Name: dac_help - * - * Description: - * Display the help message for the DAC testing application. - * - * Input Parameters: - * None - * - * Returned Value: - * None - * - ****************************************************************************/ - static void dac_help(void) { printf("Usage: dac [OPTIONS] command [CMD OPTIONS]\n"); @@ -542,41 +268,18 @@ static void dac_help(void) printf("specified, that device will be re-used until it is changed.\n"); printf("\n\"sticky\" OPTIONS include:\n"); printf(" [-c channel] selects the DAC channel. " - "Default: %d Current: %d\n", DEFAULT_CHANNEL, g_dacstate.channel); + "Default: 0 Current: %d\n", g_dacstate.channel); printf(" [-d delay] pause for DELAY ms between writes. " - "Default: %d Current: %d\n", DEFAULT_DELAY, g_dacstate.delay); + "Default: 0 Current: %d\n", g_dacstate.delay); printf(" [-n count] repeats device write COUNT times. " - "Default: %d Current: %d\n", DEFAULT_COUNT, g_dacstate.count); - printf(" [-b bit_resolution] Test-specific config - set DAC bit" - " resolution Default: %d Current: %d\n", - DEFAULT_TEST_BIT_RES, g_dacstate.test_bit_res); - printf(" [-s step] Test-specific config - test loop step " - "Default: %d Current: %d\n", - DEFAULT_TEST_STEP, g_dacstate.test_step); + "Default: 1 Current: %d\n", g_dacstate.count); printf(" [-p devpath] selects the DAC device. " "Default: %s Current: %s\n", CONFIG_EXAMPLES_DAC_DEVPATH, g_dacstate.devpath ? g_dacstate.devpath : "NONE"); - printf(" [-h] Print this help and exit.\n"); - print_cmds("\nCommands:\n", commands, nitems(commands), "\n"); + print_cmds("\nCommands:\n", commands, ARRAY_SIZE(commands), "\n"); } -/**************************************************************************** - * Name: arg_string - * - * Description: - * Extracts a string argument from a command-line option. - * - * Input Parameters: - * arg - Pointer to the current command-line argument being processed. - * value - Pointer to store the extracted string argument. - * - * Returned Value: - * Integer representing the number of arguments consumed - * (2 if the option takes an additional argument, 1 otherwise). - * - ****************************************************************************/ - static int arg_string(FAR const char **arg, FAR const char **value) { FAR const char *ptr = *arg; @@ -593,26 +296,6 @@ static int arg_string(FAR const char **arg, FAR const char **value) } } -/**************************************************************************** - * Name: arg_decimal - * - * Description: - * Extracts a decimal value from a command-line option. - * - * Input Parameters: - * arg - Pointer to the current command-line argument being processed. - * value - Pointer to store the extracted decimal value. - * - * Returned Value: - * Integer representing the number of arguments consumed - * (2 if the option takes an additional argument, 1 otherwise). - * - * Note: - * Utilizes arg_string internally to extract the string argument - * and then converts it to a long integer using strtol. - * - ****************************************************************************/ - static int arg_decimal(FAR const char **arg, FAR long *value) { FAR const char *string; @@ -627,12 +310,12 @@ static int parse_args(FAR struct dac_state_s *dac, int argc, const char *argv[]) { - FAR const char *ptr; /* Pointer to the current argument in argv */ - FAR const char *str; /* Pointer to a string argument extracted from argv */ - long value; /* Numerical argument value */ - int nargs; /* Number of args consumed by the current option */ - int n; /* Total number of arguments processed */ - int i; /* Loop counter */ + FAR const char *ptr; + FAR const char *str; + long value; + int nargs; + int n; + int i; for (i = n = 1; i < argc; ) { @@ -684,32 +367,6 @@ static int parse_args(FAR struct dac_state_s *dac, n += nargs; break; - case 'b': - nargs = arg_decimal(&argv[i], &value); - if (value < 0) - { - printf("Bit resolution must be non-negative: %ld\n", value); - exit(1); - } - - dac->test_bit_res = (uint32_t)value; - i += nargs; - n += nargs; - break; - - case 's': - nargs = arg_decimal(&argv[i], &value); - if (value < 0) - { - printf("Step must be non-negative: %ld\n", value); - exit(1); - } - - dac->test_step = (uint32_t)value; - i += nargs; - n += nargs; - break; - case 'p': nargs = arg_string(&argv[i], &str); dac_devpath(dac, str); @@ -717,11 +374,6 @@ static int parse_args(FAR struct dac_state_s *dac, n += nargs; break; - case 'h': - dac_help(); - exit(0); - break; - case '?': default: printf("Unsupported option: %s\n", ptr); @@ -737,23 +389,6 @@ static int parse_args(FAR struct dac_state_s *dac, * Public Functions ****************************************************************************/ -/**************************************************************************** - * Name: main - * - * Description: - * Entry point for the DAC testing application. - * Initializes the DAC hardware and processes command-line - * arguments to execute DAC testing commands. - * - * Input Parameters: - * argc - Number of command-line arguments. - * argv - Array of command-line argument strings. - * - * Returned Value: - * EXIT_SUCCESS on success, EXIT_FAILURE on failure. - * - ****************************************************************************/ - int main(int argc, FAR const char *argv[]) { int ret; @@ -768,12 +403,9 @@ int main(int argc, FAR const char *argv[]) /* Set the default values */ dac_devpath(&g_dacstate, CONFIG_EXAMPLES_DAC_DEVPATH); - g_dacstate.delay = DEFAULT_DELAY; - g_dacstate.count = DEFAULT_COUNT; - g_dacstate.channel = DEFAULT_CHANNEL; - g_dacstate.test_bit_res = DEFAULT_TEST_BIT_RES; - g_dacstate.test_step = DEFAULT_TEST_STEP; - g_dacstate.initialized = DEFAULT_INITIALIZED; + g_dacstate.count = 1; + g_dacstate.channel = 0; /* This seems to be ignored by driver. */ + g_dacstate.initialized = true; } /* Parse the command line */ @@ -790,7 +422,7 @@ int main(int argc, FAR const char *argv[]) } else { - ret = execute_cmd(argc, argv, commands, nitems(commands)); + ret = execute_cmd(argc, argv, commands, ARRAY_SIZE(commands)); } return (ret >= 0) ? EXIT_SUCCESS : EXIT_FAILURE; diff --git a/examples/dhcpd/CMakeLists.txt b/examples/dhcpd/CMakeLists.txt deleted file mode 100644 index 5b2ba7cd2..000000000 --- a/examples/dhcpd/CMakeLists.txt +++ /dev/null @@ -1,58 +0,0 @@ -# ############################################################################## -# apps/examples/dhcpd/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_DHCPD) - nuttx_add_application( - NAME - dhcpd - SRCS - target.c - dhcpd_daemon.c - STACKSIZE - ${CONFIG_DEFAULT_TASK_STACKSIZE}) - - if(NOT CONFIG_BUILD_KERNEL) - nuttx_add_application( - NAME - dhcpd_start - SRCS - dhcpd_start.c - dhcpd_daemon.c - STACKSIZE - ${CONFIG_DEFAULT_TASK_STACKSIZE}) - endif() - - if(CONFIG_SCHED_WAITPID) - nuttx_add_application( - NAME - dhcpd_stop - SRCS - dhcpd_stop.c - dhcpd_daemon.c - STACKSIZE - ${CONFIG_DEFAULT_TASK_STACKSIZE}) - endif() - - add_definitions(-DCONFIG_NETUTILS_DHCPD_HOST=1 -DHAVE_SO_REUSEADDR=1 - -DHAVE_SO_BROADCAST=1) - -endif() diff --git a/examples/dhcpd/Make.defs b/examples/dhcpd/Make.defs index 8c6fddcf6..6d0024286 100644 --- a/examples/dhcpd/Make.defs +++ b/examples/dhcpd/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/dhcpd/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/dhcpd/Makefile b/examples/dhcpd/Makefile index 6c6ab3ba8..5f127cdc6 100644 --- a/examples/dhcpd/Makefile +++ b/examples/dhcpd/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/dhcpd/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -26,23 +24,13 @@ include $(APPDIR)/Make.defs CSRCS = dhcpd_daemon.c -MAINSRC = target.c +MAINSRC = dhcpd_start.c dhcpd_stop.c target.c # DHCPD built-in application info -PROGNAME = dhcpd +PROGNAME = dhcpd_start dhcpd_stop dhcpd PRIORITY = SCHED_PRIORITY_DEFAULT STACKSIZE = $(CONFIG_DEFAULT_TASK_STACKSIZE) MODULE = $(CONFIG_EXAMPLES_DHCPD) -ifneq ($(CONFIG_BUILD_KERNEL),y) -MAINSRC += dhcpd_start.c -PROGNAME += dhcpd_start -endif - -ifeq ($(CONFIG_SCHED_WAITPID),y) -MAINSRC += dhcpd_stop.c -PROGNAME += dhcpd_stop -endif - include $(APPDIR)/Application.mk diff --git a/examples/dhcpd/Makefile.host b/examples/dhcpd/Makefile.host index 18795707a..78caadfe8 100644 --- a/examples/dhcpd/Makefile.host +++ b/examples/dhcpd/Makefile.host @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/dhcpd/Makefile.host # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/dhcpd/dhcpd_daemon.c b/examples/dhcpd/dhcpd_daemon.c index b4f16e787..7ed38bb6a 100644 --- a/examples/dhcpd/dhcpd_daemon.c +++ b/examples/dhcpd/dhcpd_daemon.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/dhcpd/dhcpd_daemon.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -115,6 +113,11 @@ int dhcpd_daemon(int argc, FAR char *argv[], bool daemon) addr.s_addr = HTONL(CONFIG_NETUTILS_DHCPD_ROUTERIP); netlib_set_ipv4addr(devname, &addr); + /* Set up the default router address */ + + addr.s_addr = HTONL(CONFIG_NETUTILS_DHCPD_ROUTERIP); + netlib_set_dripv4addr(devname, &addr); + /* Setup the subnet mask */ addr.s_addr = HTONL(CONFIG_NETUTILS_DHCPD_NETMASK); @@ -128,12 +131,10 @@ int dhcpd_daemon(int argc, FAR char *argv[], bool daemon) /* Then start the dhcpd */ -#ifndef CONFIG_BUILD_KERNEL - if (!daemon) + if (daemon) { - return dhcpd_start(devname); + return dhcpd_run(devname); } -#endif - return dhcpd_run(devname); + return dhcpd_start(devname); } diff --git a/examples/dhcpd/dhcpd_daemon.h b/examples/dhcpd/dhcpd_daemon.h index bdf929146..5c2e521c7 100644 --- a/examples/dhcpd/dhcpd_daemon.h +++ b/examples/dhcpd/dhcpd_daemon.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/dhcpd/dhcpd_daemon.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/dhcpd/dhcpd_start.c b/examples/dhcpd/dhcpd_start.c index e5e7d5c24..1ab56aa61 100644 --- a/examples/dhcpd/dhcpd_start.c +++ b/examples/dhcpd/dhcpd_start.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/dhcpd/dhcpd_start.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/dhcpd/dhcpd_stop.c b/examples/dhcpd/dhcpd_stop.c index 099d47fcd..7d6795d16 100644 --- a/examples/dhcpd/dhcpd_stop.c +++ b/examples/dhcpd/dhcpd_stop.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/dhcpd/dhcpd_stop.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/dhcpd/host.c b/examples/dhcpd/host.c index bd806f06a..89c4885ee 100644 --- a/examples/dhcpd/host.c +++ b/examples/dhcpd/host.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/dhcpd/host.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/dhcpd/target.c b/examples/dhcpd/target.c index 3a5117f61..574a6b6cb 100644 --- a/examples/dhcpd/target.c +++ b/examples/dhcpd/target.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/dhcpd/target.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/dhtxx/CMakeLists.txt b/examples/dhtxx/CMakeLists.txt deleted file mode 100644 index b46b9b404..000000000 --- a/examples/dhtxx/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# ############################################################################## -# apps/examples/dhtxx/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_DHTXX) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_DHTXX_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_DHTXX_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_DHTXX_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_DHTXX} - SRCS - dhtxx_main.c) -endif() diff --git a/examples/dhtxx/Kconfig b/examples/dhtxx/Kconfig index f664637f4..7489520a2 100644 --- a/examples/dhtxx/Kconfig +++ b/examples/dhtxx/Kconfig @@ -6,7 +6,6 @@ config EXAMPLES_DHTXX tristate "Dhtxx sensor example" default n - depends on SENSORS_DHTXX ---help--- Enable the dhtxx sensor example diff --git a/examples/dhtxx/Make.defs b/examples/dhtxx/Make.defs index 7caff5907..924d5dac7 100644 --- a/examples/dhtxx/Make.defs +++ b/examples/dhtxx/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/dhtxx/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/dhtxx/Makefile b/examples/dhtxx/Makefile index cca81fc2f..cfebad515 100644 --- a/examples/dhtxx/Makefile +++ b/examples/dhtxx/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/dhtxx/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/dhtxx/dhtxx_main.c b/examples/dhtxx/dhtxx_main.c index d38b502ae..4720c4d7b 100644 --- a/examples/dhtxx/dhtxx_main.c +++ b/examples/dhtxx/dhtxx_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/dhtxx/dhtxx_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/discover/CMakeLists.txt b/examples/discover/CMakeLists.txt deleted file mode 100644 index 1baaa7a8e..000000000 --- a/examples/discover/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# ############################################################################## -# apps/examples/discover/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_DISCOVER) - nuttx_add_application( - NAME - discover - STACKSIZE - ${CONFIG_DEFAULT_TASK_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_DISCOVER} - SRCS - discover_main.c) -endif() diff --git a/examples/discover/Make.defs b/examples/discover/Make.defs index b5491e957..79226fec9 100644 --- a/examples/discover/Make.defs +++ b/examples/discover/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/discover/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/discover/Makefile b/examples/discover/Makefile index 698d9cbd1..7c4e96b7c 100644 --- a/examples/discover/Makefile +++ b/examples/discover/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/discover/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/discover/discover_main.c b/examples/discover/discover_main.c index 9f5941587..bfc3c3dac 100644 --- a/examples/discover/discover_main.c +++ b/examples/discover/discover_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/discover/discover_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -29,10 +27,11 @@ #include <string.h> #include <unistd.h> #include <time.h> -#include <nuttx/debug.h> +#include <debug.h> #include <net/if.h> #include <netinet/in.h> +#include <nuttx/net/arp.h> #include "netutils/netlib.h" #include "netutils/discover.h" @@ -137,9 +136,6 @@ int main(int argc, FAR char *argv[]) if (handle) { struct dhcpc_state ds; - char inetaddr[INET_ADDRSTRLEN]; - int ret; - dhcpc_request(handle, &ds); netlib_set_ipv4addr("eth0", &ds.ipaddr); @@ -153,21 +149,13 @@ int main(int argc, FAR char *argv[]) netlib_set_dripv4addr("eth0", &ds.default_router); } - for (int i = 0; i < ds.num_dnsaddr; i++) + if (ds.dnsaddr.s_addr != 0) { - if (ds.dnsaddr[i].s_addr != 0) - { - ret = netlib_set_ipv4dnsaddr(&ds.dnsaddr[i]); - if (ret < 0) - { - nerr("ERROR: Set DNS server %d:%s address failed: %d\n", - i, inet_ntoa(ds.dnsaddr[i]), ret); - } - } + netlib_set_ipv4dnsaddr(&ds.dnsaddr); } dhcpc_close(handle); - printf("IP: %s\n", inet_ntoa_r(ds.ipaddr, inetaddr, sizeof(inetaddr))); + printf("IP: %s\n", inet_ntoa(ds.ipaddr)); } #endif /* CONFIG_EXAMPLES_DISCOVER_DHCPC */ diff --git a/examples/djoystick/CMakeLists.txt b/examples/djoystick/CMakeLists.txt deleted file mode 100644 index 37152b56b..000000000 --- a/examples/djoystick/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# ############################################################################## -# apps/examples/djoystick/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_DJOYSTICK) - nuttx_add_application( - NAME - djoy - STACKSIZE - ${CONFIG_DEFAULT_TASK_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_DJOYSTICK} - SRCS - djoy_main.c) -endif() diff --git a/examples/djoystick/Kconfig b/examples/djoystick/Kconfig index 68e38ab6e..82648d704 100644 --- a/examples/djoystick/Kconfig +++ b/examples/djoystick/Kconfig @@ -6,7 +6,7 @@ config EXAMPLES_DJOYSTICK tristate "Discrete joystick example" default n - depends on INPUT_DJOYSTICK && ENABLE_ALL_SIGNALS + depends on INPUT_DJOYSTICK ---help--- Enable the discrete joystick example @@ -18,6 +18,6 @@ config EXAMPLES_DJOYSTICK_DEVNAME config EXAMPLES_DJOYSTICK_SIGNO int "Joystick signal" - default 32 + default 13 endif diff --git a/examples/djoystick/Make.defs b/examples/djoystick/Make.defs index 280c627af..f4a064992 100644 --- a/examples/djoystick/Make.defs +++ b/examples/djoystick/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/djoystick/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/djoystick/Makefile b/examples/djoystick/Makefile index 74e31b644..839aa64d7 100644 --- a/examples/djoystick/Makefile +++ b/examples/djoystick/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/djoystick/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -22,11 +20,11 @@ include $(APPDIR)/Make.defs -# DJOYSTICK Example +# Hello, World! Example MAINSRC = djoy_main.c -# DJOYSTICK built-in application info +# Buttons built-in application info PROGNAME = djoy PRIORITY = SCHED_PRIORITY_DEFAULT diff --git a/examples/djoystick/djoy_main.c b/examples/djoystick/djoy_main.c index b3d1134c9..40249b98d 100644 --- a/examples/djoystick/djoy_main.c +++ b/examples/djoystick/djoy_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/djoystick/djoy_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -27,13 +25,11 @@ #include <nuttx/config.h> #include <sys/ioctl.h> -#include <sys/param.h> #include <stdio.h> #include <stdlib.h> #include <fcntl.h> #include <errno.h> -#include <nuttx/debug.h> -#include <unistd.h> +#include <debug.h> #include <nuttx/input/djoystick.h> @@ -52,7 +48,16 @@ #endif #ifndef CONFIG_EXAMPLES_DJOYSTICK_SIGNO -# define CONFIG_EXAMPLES_DJOYSTICK_SIGNO 32 +# define CONFIG_EXAMPLES_DJOYSTICK_SIGNO 13 +#endif + +/* Helpers ******************************************************************/ + +#ifndef MIN +# define MIN(a,b) (a < b ? a : b) +#endif +#ifndef MAX +# define MAX(a,b) (a > b ? a : b) #endif /**************************************************************************** diff --git a/examples/dronecan/CMakeLists.txt b/examples/dronecan/CMakeLists.txt deleted file mode 100644 index 353bd4dc7..000000000 --- a/examples/dronecan/CMakeLists.txt +++ /dev/null @@ -1,43 +0,0 @@ -# ############################################################################## -# apps/examples/dronecan/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_DRONECAN) - set(INCDIR ${NUTTX_APPS_DIR}/canutils/libdronecan/libcanard - ${NUTTX_APPS_DIR}/canutils/libdronecan/libcanard/drivers/nuttx) - if(CONFIG_CANUTILS_LIBOPENCYPHAL) - set(CFLAGS -DcanardInit=dronecanardInit) - endif() - - nuttx_add_application( - NAME - dronecan - STACKSIZE - ${CONFIG_EXAMPLES_DRONECAN_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_DRONECAN} - SRCS - canard_main.c - INCLUDE_DIRECTORIES - ${INCDIR} - COMPILE_FLAGS - ${CFLAGS}) -endif() diff --git a/examples/dronecan/Make.defs b/examples/dronecan/Make.defs deleted file mode 100644 index f17aebd60..000000000 --- a/examples/dronecan/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/examples/dronecan/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http:#www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_EXAMPLES_DRONECAN),) -CONFIGURED_APPS += $(APPDIR)/examples/dronecan -endif diff --git a/examples/dronecan/Makefile b/examples/dronecan/Makefile deleted file mode 100644 index a8f309b68..000000000 --- a/examples/dronecan/Makefile +++ /dev/null @@ -1,40 +0,0 @@ -############################################################################ -# apps/examples/dronecan/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http:#www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -PROGNAME = dronecan -PRIORITY = SCHED_PRIORITY_DEFAULT -STACKSIZE = $(CONFIG_EXAMPLES_DRONECAN_STACKSIZE) -MODULE = $(CONFIG_EXAMPLES_DRONECAN) - -# Conflict with Cyphal's libcanard -ifeq ($(CONFIG_CANUTILS_LIBOPENCYPHAL),y) -CFLAGS += -DcanardInit=dronecanardInit -endif - -CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/canutils/libdronecan/libcanard -CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/canutils/libdronecan/libcanard/drivers/nuttx - -MAINSRC = canard_main.c - -include $(APPDIR)/Application.mk diff --git a/examples/elf/.gitignore b/examples/elf/.gitignore deleted file mode 100644 index 9e1d2593e..000000000 --- a/examples/elf/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/Kconfig diff --git a/examples/elf/CMakeLists.txt b/examples/elf/CMakeLists.txt deleted file mode 100644 index f5b2b0ee6..000000000 --- a/examples/elf/CMakeLists.txt +++ /dev/null @@ -1,24 +0,0 @@ -# ############################################################################## -# apps/examples/elf/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -nuttx_add_subdirectory() -nuttx_generate_kconfig(MENUDESC "Elf") diff --git a/examples/elf/main/Kconfig b/examples/elf/Kconfig similarity index 94% rename from examples/elf/main/Kconfig rename to examples/elf/Kconfig index ee285b091..3c1a69a39 100644 --- a/examples/elf/main/Kconfig +++ b/examples/elf/Kconfig @@ -39,7 +39,7 @@ config EXAMPLES_ELF_EXTERN The file system is assumed to reside on some external media such as an SD card or a USB FLASH drive. In this case, that external file system must be created manually by copying the - files in apps/examples/elf/tests/extfs to the volume. + files in apps/examples/elf/tests/romfs to the volume. The external volume can optionally be mounted by the test if the CONFIG_EXAMPLES_FSMOUNT option is also selected. @@ -81,10 +81,7 @@ config EXAMPLES_ELF_FSTYPE depends on EXAMPLES_ELF_FSMOUNT ---help--- The type of the external file system as will be used in the mount() - command. Default: "vfat". - If the type of the external file system is set to "romfs" a romfs.img - is created in apps/examples/elf/tests/ this can be copied to an - internal block device. + command. Default: "vfat" config EXAMPLES_ELF_DEVPATH string "Block driver device path" diff --git a/examples/elf/Make.defs b/examples/elf/Make.defs index fe9092e3b..a86d97359 100644 --- a/examples/elf/Make.defs +++ b/examples/elf/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/elf/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -20,4 +18,6 @@ # ############################################################################ -include $(wildcard $(APPDIR)/examples/elf/*/Make.defs) +ifneq ($(CONFIG_EXAMPLES_ELF),) +CONFIGURED_APPS += $(APPDIR)/examples/elf +endif diff --git a/examples/elf/Makefile b/examples/elf/Makefile index cde6ca47d..1ddfb60d6 100644 --- a/examples/elf/Makefile +++ b/examples/elf/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/elf/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -20,6 +18,45 @@ # ############################################################################ -MENUDESC = "Elf example" +include $(APPDIR)/Make.defs -include $(APPDIR)/Directory.mk +# ELF Example + +ifeq ($(CONFIG_EXAMPLES_ELF_ROMFS),y) +CSRCS = romfs.c +endif +ifeq ($(CONFIG_EXAMPLES_ELF_CROMFS),y) +CSRCS = cromfs.c +endif +CSRCS += dirlist.c +CSRCS += symtab.c +MAINSRC = elf_main.c + +PROGNAME = elf +PRIORITY = SCHED_PRIORITY_DEFAULT +STACKSIZE = $(CONFIG_DEFAULT_TASK_STACKSIZE) +MODULE = $(CONFIG_EXAMPLES_ELF) + +DEPPATH := --dep-path tests + +# Build targets + +VPATH += :tests + +ifeq ($(CONFIG_EXAMPLES_ELF_ROMFS),y) +tests/romfs.c: build +endif +ifeq ($(CONFIG_EXAMPLES_ELF_CROMFS),y) +tests/cromfs.c: build +endif +tests/dirlist.c: build +tests/symtab.c: build + +.PHONY: build +build: + +$(Q) $(MAKE) -C tests TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)" CROSSDEV=$(CROSSDEV) + +clean:: + +$(Q) $(MAKE) -C tests TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)" CROSSDEV=$(CROSSDEV) clean + +include $(APPDIR)/Application.mk diff --git a/examples/elf/main/elf_main.c b/examples/elf/elf_main.c similarity index 82% rename from examples/elf/main/elf_main.c rename to examples/elf/elf_main.c index 000339e00..ebcc5e97a 100644 --- a/examples/elf/main/elf_main.c +++ b/examples/elf/elf_main.c @@ -1,7 +1,5 @@ /**************************************************************************** - * apps/examples/elf/main/elf_main.c - * - * SPDX-License-Identifier: Apache-2.0 + * apps/examples/elf/elf_main.c * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -37,7 +35,7 @@ #include <unistd.h> #include <string.h> #include <pthread.h> -#include <nuttx/debug.h> +#include <debug.h> #include <errno.h> #include <nuttx/symtab.h> @@ -64,26 +62,30 @@ # error "You must not disable mountpoints via CONFIG_DISABLE_MOUNTPOINT in your configuration file" #endif -#ifndef CONFIG_EXAMPLES_ELF_DEVMINOR -# define CONFIG_EXAMPLES_ELF_DEVMINOR 0 -#endif - #if defined(CONFIG_EXAMPLES_ELF_ROMFS) /* Describe the ROMFS file system */ # define SECTORSIZE 512 # define NSECTORS(b) (((b) + SECTORSIZE - 1) / SECTORSIZE) -# define MOUNTPT "/mnt/elf/romfs" +# define MOUNTPT "/mnt/romfs" + +# ifndef CONFIG_EXAMPLES_ELF_DEVMINOR +# define CONFIG_EXAMPLES_ELF_DEVMINOR 0 +# endif + +# ifndef CONFIG_EXAMPLES_ELF_DEVPATH +# define CONFIG_EXAMPLES_ELF_DEVPATH "/dev/ram0" +# endif #elif defined(CONFIG_EXAMPLES_ELF_CROMFS) /* Describe the CROMFS file system */ -# define MOUNTPT "/mnt/elf/cromfs" +# define MOUNTPT "/mnt/cromfs" #elif defined(CONFIG_EXAMPLES_ELF_EXTERN) && defined(CONFIG_EXAMPLES_ELF_FSMOUNT) /* Describe the external file system */ -# define MOUNTPT "/mnt/elf/" CONFIG_EXAMPLES_ELF_FSTYPE +# define MOUNTPT "/mnt/" CONFIG_EXAMPLES_ELF_FSTYPE #else # undef MOUNTPT @@ -104,8 +106,6 @@ # define errmsg printf #endif -#define ELF_DEVPATH_FMT "/dev/ram%d" - /**************************************************************************** * Private Data ****************************************************************************/ @@ -126,43 +126,14 @@ static char fullpath[128]; ****************************************************************************/ #if defined(CONFIG_EXAMPLES_ELF_ROMFS) || defined(CONFIG_EXAMPLES_ELF_CROMFS) -extern const unsigned char elf_romfs_img[]; -extern const unsigned int elf_romfs_img_len; +extern const unsigned char romfs_img[]; +extern const unsigned int romfs_img_len; #elif !defined(CONFIG_EXAMPLES_ELF_EXTERN) # error "No file system selected" #endif -const char *dirlist[] = -{ - "errno", - "hello", -#ifndef CONFIG_DISABLE_SIGNALS - "signal", -#endif - "struct", -#ifdef CONFIG_HAVE_CXX - "hello++1", - "hello++2", -# ifdef CONFIG_HAVE_CXXINITIALIZE - "hello++3", -# endif -# ifdef CONFIG_EXAMPLES_ELF_CXX - "hello++4", - "hello++5", -# endif -#endif -#ifdef CONFIG_EXAMPLES_ELF_LONGJMP - "longjmp" -#endif -#ifndef CONFIG_DISABLE_PTHREAD - "mutex", - "pthread", -#endif -#ifndef CONFIG_ARCH_ADDRENV - "task", -#endif - NULL -}; +extern const char *dirlist[]; + extern const struct symtab_s g_elf_exports[]; extern const int g_elf_nexports; @@ -229,7 +200,6 @@ static inline void testheader(FAR const char *progname) int main(int argc, FAR char *argv[]) { - char devname[32]; #ifdef CONFIG_EXAMPLES_ELF_FSREMOVEABLE struct stat buf; #endif @@ -244,12 +214,6 @@ int main(int argc, FAR char *argv[]) mm_initmonitor(); -#if defined(CONFIG_EXAMPLES_ELF_FSMOUNT) - sprintf(devname, CONFIG_EXAMPLES_ELF_DEVPATH); -#else - sprintf(devname, ELF_DEVPATH_FMT, CONFIG_EXAMPLES_ELF_DEVMINOR); -#endif - #if defined(CONFIG_EXAMPLES_ELF_ROMFS) /* Create a ROM disk for the ROMFS filesystem */ @@ -258,9 +222,9 @@ int main(int argc, FAR char *argv[]) CONFIG_EXAMPLES_ELF_DEVMINOR); desc.minor = CONFIG_EXAMPLES_ELF_DEVMINOR; /* Minor device number of the ROM disk. */ - desc.nsectors = NSECTORS(elf_romfs_img_len); /* The number of sectors in the ROM disk */ + desc.nsectors = NSECTORS(romfs_img_len); /* The number of sectors in the ROM disk */ desc.sectsize = SECTORSIZE; /* The size of one sector in bytes */ - desc.image = (FAR uint8_t *)elf_romfs_img; /* File system image */ + desc.image = (FAR uint8_t *)romfs_img; /* File system image */ ret = boardctl(BOARDIOC_ROMDISK, (uintptr_t)&desc); if (ret < 0) @@ -274,13 +238,14 @@ int main(int argc, FAR char *argv[]) /* Mount the ROMFS file system */ message("Mounting ROMFS filesystem at target=%s with source=%s\n", - MOUNTPT, devname); + MOUNTPT, CONFIG_EXAMPLES_ELF_DEVPATH); - ret = mount(devname, MOUNTPT, "romfs", MS_RDONLY, NULL); + ret = mount(CONFIG_EXAMPLES_ELF_DEVPATH, MOUNTPT, "romfs", + MS_RDONLY, NULL); if (ret < 0) { errmsg("ERROR: mount(%s,%s,romfs) failed: %s\n", - devname, MOUNTPT, strerror(errno)); + CONFIG_EXAMPLES_ELF_DEVPATH, MOUNTPT, strerror(errno)); } #elif defined(CONFIG_EXAMPLES_ELF_CROMFS) @@ -303,26 +268,27 @@ int main(int argc, FAR char *argv[]) do { - ret = stat(devname, &buf); + ret = stat(CONFIG_EXAMPLES_ELF_DEVPATH, &buf); if (ret < 0) { int errcode = errno; if (errcode == ENOENT) { - printf("%s does not exist. Waiting...\n", devname); + printf("%s does not exist. Waiting...\n", + CONFIG_EXAMPLES_ELF_DEVPATH); sleep(1); } else { printf("ERROR: stat(%s) failed: %s Aborting...\n", - devname, strerror(errcode)); + CONFIG_EXAMPLES_ELF_DEVPATH, strerror(errcode)); exit(EXIT_FAILURE); } } else if (!S_ISBLK(buf.st_mode)) { printf("ERROR: stat(%s) exists but is not a block driver: %04x\n", - devname, buf.st_mode); + CONFIG_EXAMPLES_ELF_DEVPATH, buf.st_mode); exit(EXIT_FAILURE); } } @@ -331,18 +297,20 @@ int main(int argc, FAR char *argv[]) /* Mount the external file system */ - message("Mounting %s filesystem at target=%s on %s\n", - CONFIG_EXAMPLES_ELF_FSTYPE, MOUNTPT, devname); + message("Mounting %s filesystem at target=%s\n", + CONFIG_EXAMPLES_ELF_FSTYPE, MOUNTPT); - ret = mount(devname, MOUNTPT, CONFIG_EXAMPLES_ELF_FSTYPE, MS_RDONLY, NULL); + ret = mount(CONFIG_EXAMPLES_ELF_DEVPATH, MOUNTPT, + CONFIG_EXAMPLES_ELF_FSTYPE, MS_RDONLY, NULL); if (ret < 0) { - errmsg("ERROR: mount(%s, %s, %s) failed: %s\n", devname, - CONFIG_EXAMPLES_ELF_FSTYPE, MOUNTPT, strerror(errno)); + errmsg("ERROR: mount(%s, %s, %s) failed: %s\n", + CONFIG_EXAMPLES_ELF_DEVPATH, CONFIG_EXAMPLES_ELF_FSTYPE, + MOUNTPT, strerror(errno)); } #endif #else -# warning "No file system selected" +# Warning "No file system selected" #endif mm_update(&g_mmstep, "after mount"); @@ -376,7 +344,7 @@ int main(int argc, FAR char *argv[]) #ifdef CONFIG_LIBC_ENVPATH filename = dirlist[i]; #else - snprintf(fullpath, sizeof(fullpath), "%s/%s", MOUNTPT, dirlist[i]); + snprintf(fullpath, 128, "%s/%s", MOUNTPT, dirlist[i]); filename = fullpath; #endif @@ -391,7 +359,7 @@ int main(int argc, FAR char *argv[]) args[0] = (FAR char *)dirlist[i]; args[1] = NULL; - ret = exec(filename, args, NULL, g_elf_exports, g_elf_nexports); + ret = exec(filename, args, g_elf_exports, g_elf_nexports); mm_update(&g_mmstep, "after exec"); diff --git a/examples/elf/main/.gitignore b/examples/elf/main/.gitignore deleted file mode 100644 index 17739289c..000000000 --- a/examples/elf/main/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -/elf_romfs.c -/elf_romfs.img -/cromfs.c -/test_symtab.c diff --git a/examples/elf/main/CMakeLists.txt b/examples/elf/main/CMakeLists.txt deleted file mode 100644 index 3b354fe21..000000000 --- a/examples/elf/main/CMakeLists.txt +++ /dev/null @@ -1,134 +0,0 @@ -# ############################################################################## -# apps/examples/elf/main/CMakeLists.txt -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_ELF) - set(ELF_SYMTAB ${CMAKE_CURRENT_BINARY_DIR}/test_symtab.c) - set(ELF_ROMFS_IMG ${CMAKE_CURRENT_BINARY_DIR}/elf_romfs.img) - set(ELF_ROMFS_SRC ${CMAKE_CURRENT_BINARY_DIR}/elf_romfs.c) - - set(ELFNAME_BASE hello) - - set(ELF_BINARY_FILES) - set(ELF_BINARY_TARGETS) - foreach(ELFNAME IN LISTS ELFNAME_BASE) - list(APPEND ELF_BINARY_FILES ${CMAKE_BINARY_DIR}/bin/${ELFNAME}) - - if(CMAKE_C_ELF_COMPILER) - list(APPEND ELF_BINARY_TARGETS ${ELFNAME}) - else() - list(APPEND ELF_BINARY_TARGETS ELF_${ELFNAME}) - endif() - endforeach() - - add_custom_command( - OUTPUT ${ELF_SYMTAB} - COMMAND ${NUTTX_APPS_DIR}/tools/mksymtab.sh ${ELF_BINARY_FILES} g_elf > - ${ELF_SYMTAB} - DEPENDS ${ELF_BINARY_TARGETS}) - - set_source_files_properties(${ELF_SYMTAB} PROPERTIES GENERATED TRUE) - - set(ELF_GENERATED_OUTPUTS ${ELF_SYMTAB}) - set(ELF_SRCS elf_main.c ${ELF_SYMTAB}) - - if(CONFIG_EXAMPLES_ELF_ROMFS) - set(ELF_ROMFS_DEPS ${ELF_BINARY_TARGETS}) - - if(CONFIG_SYSTEM_NXPKG) - set(ELF_INDEX_JSON ${CMAKE_BINARY_DIR}/bin/index.json) - set(ELF_BAD_INDEX_JSON ${CMAKE_BINARY_DIR}/bin/bad-index.json) - set(ELF_PKGTEST ${CMAKE_BINARY_DIR}/bin/pkgtest.nsh) - set(ELF_PKGFAIL ${CMAKE_BINARY_DIR}/bin/pkgfail.nsh) - set(ELF_HELLO_BIN ${CMAKE_BINARY_DIR}/bin/hello) - set(ELF_FIXTURE_HOST_DIR ${CMAKE_CURRENT_BINARY_DIR}/host) - set(ELF_FIXTURE_HOST_SRC ${CMAKE_CURRENT_SOURCE_DIR}/host/CMakeLists.txt) - set(ELF_FIXTURE_TOOL - ${ELF_FIXTURE_HOST_DIR}/mk_pkg_fixture${CMAKE_EXECUTABLE_SUFFIX}) - set(ELF_HELLO_TARGET hello) - - if(CONFIG_ARCH_BOARD) - set(ELF_FIXTURE_COMPAT ${CONFIG_ARCH_BOARD}) - else() - set(ELF_FIXTURE_COMPAT ${CONFIG_ARCH_BOARD_CUSTOM_NAME}) - endif() - - if(NOT CMAKE_C_ELF_COMPILER) - set(ELF_HELLO_TARGET ELF_hello) - endif() - - add_custom_command( - OUTPUT ${ELF_FIXTURE_TOOL} - COMMAND ${CMAKE_COMMAND} -S ${CMAKE_CURRENT_SOURCE_DIR}/host -B - ${ELF_FIXTURE_HOST_DIR} - COMMAND ${CMAKE_COMMAND} --build ${ELF_FIXTURE_HOST_DIR} --target - mk_pkg_fixture - DEPENDS ${ELF_FIXTURE_HOST_SRC} - ${CMAKE_CURRENT_SOURCE_DIR}/mk_pkg_fixture.c - VERBATIM) - - add_custom_command( - OUTPUT ${ELF_INDEX_JSON} ${ELF_BAD_INDEX_JSON} ${ELF_PKGTEST} - ${ELF_PKGFAIL} - COMMAND - ${ELF_FIXTURE_TOOL} ${ELF_HELLO_BIN} ${ELF_INDEX_JSON} - ${ELF_BAD_INDEX_JSON} ${ELF_PKGTEST} ${ELF_PKGFAIL} ${CONFIG_ARCH} - ${ELF_FIXTURE_COMPAT} - DEPENDS ${ELF_HELLO_TARGET} ${ELF_FIXTURE_TOOL} - VERBATIM) - - list(APPEND ELF_ROMFS_DEPS ${ELF_INDEX_JSON} ${ELF_BAD_INDEX_JSON} - ${ELF_PKGTEST} ${ELF_PKGFAIL}) - endif() - - add_custom_command( - OUTPUT ${ELF_ROMFS_IMG} - COMMAND genromfs -f ${ELF_ROMFS_IMG} -d ${CMAKE_BINARY_DIR}/bin - DEPENDS ${ELF_ROMFS_DEPS} - VERBATIM) - - get_filename_component(ELF_ROMFS_IMG_NAME ${ELF_ROMFS_IMG} NAME) - - # xxd -i derives the generated array/length symbol names from the exact path - # it is given - elf_main.c declares them as plain - # "elf_romfs_img"/"elf_romfs_img_len", so xxd must be run against just the - # bare filename (via WORKING_DIRECTORY) rather than the absolute - # ${ELF_ROMFS_IMG} path, or every non-alphanumeric character in that path - # (e.g. every "/" in the build directory) gets folded into the symbol name - # instead, leaving the names elf_main.c expects undefined at link time. - - add_custom_command( - OUTPUT ${ELF_ROMFS_SRC} - COMMAND xxd -i ${ELF_ROMFS_IMG_NAME} > ${ELF_ROMFS_SRC} - DEPENDS ${ELF_ROMFS_IMG} - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) - - set_source_files_properties(${ELF_ROMFS_SRC} PROPERTIES GENERATED TRUE) - - list(APPEND ELF_GENERATED_OUTPUTS ${ELF_ROMFS_SRC}) - list(APPEND ELF_SRCS ${ELF_ROMFS_SRC}) - endif() - - add_custom_target(elf_artifacts DEPENDS ${ELF_GENERATED_OUTPUTS}) - - nuttx_add_application(NAME elf SRCS ${ELF_SRCS} DEPENDS elf_artifacts) - - # TODO: tests - -endif() diff --git a/examples/elf/main/Makefile b/examples/elf/main/Makefile deleted file mode 100644 index 5cc8db511..000000000 --- a/examples/elf/main/Makefile +++ /dev/null @@ -1,143 +0,0 @@ -############################################################################ -# apps/examples/elf/main/Makefile -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -# Module example built-in application info - -PROGNAME = elf -PRIORITY = SCHED_PRIORITY_DEFAULT -STACKSIZE = $(CONFIG_DEFAULT_TASK_STACKSIZE) -MODULE = $(CONFIG_EXAMPLES_ELF) - -MAINSRC = elf_main.c - -SYMTABSRC = test_symtab.c -SYMTABOBJ = $(SYMTABSRC:.c=$(OBJEXT)) - -ELFNAME_BASE = errno hello -ifneq ($(CONFIG_DISABLE_SIGNALS),y) - ELFNAME_BASE += signal -endif - -ifeq ($(CONFIG_HAVE_CXX),y) - ELFNAME_BASE += hello++1 hello++2 - ifeq ($(CONFIG_HAVE_CXXINITIALIZE),y) - ELFNAME_BASE += hello++3 - endif - ifeq ($(CONFIG_EXAMPLES_ELF_CXX),y) - ELFNAME_BASE += hello++4 hello++5 - endif -endif -ifeq ($(CONFIG_EXAMPLES_ELF_LONGJMP),y) - ELFNAME_BASE += longjmp -endif -ifneq ($(CONFIG_DISABLE_PTHREAD),y) - ELFNAME_BASE += pthread mutex -endif -ifneq ($(CONFIG_ARCH_ADDRENV),y) - ELFNAME_BASE += task -endif - -ELFNAME = $(addprefix $(BINDIR)$(DELIM),$(ELFNAME_BASE)) - -$(SYMTABSRC): - $(Q) $(APPDIR)$(DELIM)tools$(DELIM)mksymtab.sh $(ELFNAME) g_elf >$@.tmp - $(Q) $(call TESTANDREPLACEFILE, $@.tmp, $@) - - -$(SYMTABOBJ): %$(OBJEXT): %.c - $(call COMPILE, $<, $@, -fno-lto -fno-builtin) - -ifeq ($(CONFIG_EXAMPLES_ELF_ROMFS),y) - -ROMFSIMG = elf_romfs.img -ROMFSSRC = elf_romfs.c -ROMFSOBJ = $(ROMFSSRC:.c=$(OBJEXT)) -ifdef CONFIG_SYSTEM_NXPKG -HOSTOBJSEXT ?= hobj -PKGINDEX = $(BINDIR)/index.json -PKGBADINDEX = $(BINDIR)/bad-index.json -PKGTEST = $(BINDIR)/pkgtest.nsh -PKGFAIL = $(BINDIR)/pkgfail.nsh -PKG_FIXTURE_GEN = mk_pkg_fixture$(HOSTEXEEXT) -PKG_FIXTURE_SRCS = mk_pkg_fixture.c -PKG_FIXTURE_OBJS = $(PKG_FIXTURE_SRCS:.c=.$(HOSTOBJSEXT)) -PKG_FIXTURE_OUTPUTS = $(PKGINDEX) $(PKGBADINDEX) $(PKGTEST) $(PKGFAIL) -PKG_FIXTURE_INPUTS = $(BINDIR)/hello -PKG_FIXTURE_STAMP = $(BINDIR)/.pkgtest.stamp -PKG_FIXTURE_COMPAT = $(if $(CONFIG_ARCH_BOARD),$(CONFIG_ARCH_BOARD),$(CONFIG_ARCH_BOARD_CUSTOM_NAME)) -PKG_FIXTURE_ARGS = \ - $(BINDIR)/hello $(PKGINDEX) $(PKGBADINDEX) $(PKGTEST) $(PKGFAIL) \ - $(CONFIG_ARCH) $(PKG_FIXTURE_COMPAT) - -$(PKG_FIXTURE_OBJS): %.$(HOSTOBJSEXT): %.c - @echo "CC: $<" - $(Q) $(HOSTCC) -c $(HOSTCFLAGS) $< -o $@ - -$(PKG_FIXTURE_GEN): $(PKG_FIXTURE_OBJS) - $(Q) $(HOSTCC) $(HOSTLDFLAGS) $(PKG_FIXTURE_OBJS) -o $@ - -$(PKG_FIXTURE_OUTPUTS): $(PKG_FIXTURE_STAMP) - -$(PKG_FIXTURE_STAMP): $(PKG_FIXTURE_INPUTS) $(PKG_FIXTURE_GEN) - $(Q) ./$(PKG_FIXTURE_GEN) \ - $(PKG_FIXTURE_ARGS) - $(Q) touch $@ -endif - -$(ROMFSIMG): $(PKG_FIXTURE_OUTPUTS) - $(Q) genromfs -d $(BINDIR) -f $@ - -$(ROMFSSRC): $(ROMFSIMG) - $(Q) (echo "#include <nuttx/compiler.h>" >$@ && \ - xxd -i $(ROMFSIMG) | sed -e "s/^unsigned char/const unsigned char aligned_data(4)/g" >>$@) - -$(ROMFSOBJ): %$(OBJEXT): %.c - $(call COMPILE, $<, $@, -fno-lto -fno-builtin) - -else ifeq ($(CONFIG_EXAMPLES_ELF_CROMFS),y) - NXTOOLDIR = $(TOPDIR)/tools - GENCROMFSSRC = gencromfs.c - GENCROMFSEXE = gencromfs$(HOSTEXEEXT) - - FSIMG_SRC = cromfs.c - FSIMG_OBJ = $(FSIMG_SRC:.c=$(OBJEXT)) - -$(NXTOOLDIR)/$(GENCROMFSEXE): $(NXTOOLDIR)/$(GENCROMFSSRC) - $(Q) $(MAKE) -C $(NXTOOLDIR) -f Makefile.host $(GENCROMFSEXE) - -# Create the cromfs.c file from the populated cromfs directory - -$(FSIMG_SRC):$(NXTOOLDIR)/$(GENCROMFSEXE) - $(Q) $(NXTOOLDIR)/$(GENCROMFSEXE) $(BINDIR) $@.tmp - $(Q) $(call TESTANDREPLACEFILE, $@.tmp, $@) - -$(FSIMG_OBJ): %$(OBJEXT): %.c - $(call COMPILE, $<, $@, -fno-lto -fno-builtin) - -endif - -postinstall:: $(ROMFSOBJ) $(SYMTABOBJ) $(FSIMG_OBJ) - $(call ARLOCK, $(call CONVERT_PATH,$(BIN)), $^) - -distclean:: - $(Q) $(call DELFILE, $(SYMTABSRC) $(SYMTABOBJ) $(ROMFSSRC) $(ROMFSIMG) $(ROMFSOBJ) $(MODLUE_NAME) $(PKG_FIXTURE_GEN) $(PKG_FIXTURE_OBJS) $(PKG_FIXTURE_STAMP)) - - -include $(APPDIR)/Application.mk diff --git a/examples/elf/main/host/CMakeLists.txt b/examples/elf/main/host/CMakeLists.txt deleted file mode 100644 index a2474cb7a..000000000 --- a/examples/elf/main/host/CMakeLists.txt +++ /dev/null @@ -1,26 +0,0 @@ -# ############################################################################## -# apps/examples/elf/main/host/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -cmake_minimum_required(VERSION 3.16) -project(elf_fixture_host LANGUAGES C) - -add_executable(mk_pkg_fixture ../mk_pkg_fixture.c) diff --git a/examples/elf/main/mk_pkg_fixture.c b/examples/elf/main/mk_pkg_fixture.c deleted file mode 100644 index c3799b519..000000000 --- a/examples/elf/main/mk_pkg_fixture.c +++ /dev/null @@ -1,463 +0,0 @@ -/**************************************************************************** - * apps/examples/elf/main/mk_pkg_fixture.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <errno.h> -#include <stdint.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define SHA256_BLOCK_SIZE 64 -#define SHA256_DIGEST_SIZE 32 - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -struct sha256_state_s -{ - uint32_t state[8]; - uint64_t bitcount; - uint8_t buffer[SHA256_BLOCK_SIZE]; - size_t buffer_len; -}; - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static const uint32_t g_sha256_init[8] = -{ - 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, - 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19 -}; - -static const uint32_t g_sha256_k[64] = -{ - 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, - 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, - 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, - 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, - 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, - 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, - 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, - 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, - 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, - 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, - 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, - 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, - 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, - 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, - 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, - 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2 -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static uint32_t sha256_rotr(uint32_t value, unsigned int bits) -{ - return (value >> bits) | (value << (32 - bits)); -} - -static uint32_t sha256_ch(uint32_t x, uint32_t y, uint32_t z) -{ - return (x & y) ^ (~x & z); -} - -static uint32_t sha256_maj(uint32_t x, uint32_t y, uint32_t z) -{ - return (x & y) ^ (x & z) ^ (y & z); -} - -static uint32_t sha256_bs0(uint32_t x) -{ - return sha256_rotr(x, 2) ^ sha256_rotr(x, 13) ^ sha256_rotr(x, 22); -} - -static uint32_t sha256_bs1(uint32_t x) -{ - return sha256_rotr(x, 6) ^ sha256_rotr(x, 11) ^ sha256_rotr(x, 25); -} - -static uint32_t sha256_ss0(uint32_t x) -{ - return sha256_rotr(x, 7) ^ sha256_rotr(x, 18) ^ (x >> 3); -} - -static uint32_t sha256_ss1(uint32_t x) -{ - return sha256_rotr(x, 17) ^ sha256_rotr(x, 19) ^ (x >> 10); -} - -static uint32_t sha256_load32(const uint8_t *src) -{ - return ((uint32_t)src[0] << 24) | ((uint32_t)src[1] << 16) | - ((uint32_t)src[2] << 8) | (uint32_t)src[3]; -} - -static void sha256_store32(uint8_t *dst, uint32_t value) -{ - dst[0] = (uint8_t)(value >> 24); - dst[1] = (uint8_t)(value >> 16); - dst[2] = (uint8_t)(value >> 8); - dst[3] = (uint8_t)value; -} - -static void sha256_transform(struct sha256_state_s *ctx, - const uint8_t block[SHA256_BLOCK_SIZE]) -{ - uint32_t schedule[64]; - uint32_t a; - uint32_t b; - uint32_t c; - uint32_t d; - uint32_t e; - uint32_t f; - uint32_t g; - uint32_t h; - int i; - - for (i = 0; i < 16; i++) - { - schedule[i] = sha256_load32(block + i * 4); - } - - for (; i < 64; i++) - { - schedule[i] = sha256_ss1(schedule[i - 2]) + schedule[i - 7] + - sha256_ss0(schedule[i - 15]) + schedule[i - 16]; - } - - a = ctx->state[0]; - b = ctx->state[1]; - c = ctx->state[2]; - d = ctx->state[3]; - e = ctx->state[4]; - f = ctx->state[5]; - g = ctx->state[6]; - h = ctx->state[7]; - - for (i = 0; i < 64; i++) - { - uint32_t t1 = h + sha256_bs1(e) + sha256_ch(e, f, g) + g_sha256_k[i] + - schedule[i]; - uint32_t t2 = sha256_bs0(a) + sha256_maj(a, b, c); - - h = g; - g = f; - f = e; - e = d + t1; - d = c; - c = b; - b = a; - a = t1 + t2; - } - - ctx->state[0] += a; - ctx->state[1] += b; - ctx->state[2] += c; - ctx->state[3] += d; - ctx->state[4] += e; - ctx->state[5] += f; - ctx->state[6] += g; - ctx->state[7] += h; -} - -static void sha256_init(struct sha256_state_s *ctx) -{ - memcpy(ctx->state, g_sha256_init, sizeof(g_sha256_init)); - ctx->bitcount = 0; - ctx->buffer_len = 0; -} - -static void sha256_update(struct sha256_state_s *ctx, const uint8_t *data, - size_t len) -{ - ctx->bitcount += (uint64_t)len * 8; - - while (len > 0) - { - size_t space = SHA256_BLOCK_SIZE - ctx->buffer_len; - size_t chunk = len < space ? len : space; - - memcpy(ctx->buffer + ctx->buffer_len, data, chunk); - ctx->buffer_len += chunk; - data += chunk; - len -= chunk; - - if (ctx->buffer_len == SHA256_BLOCK_SIZE) - { - sha256_transform(ctx, ctx->buffer); - ctx->buffer_len = 0; - } - } -} - -static void sha256_final(struct sha256_state_s *ctx, - uint8_t digest[SHA256_DIGEST_SIZE]) -{ - uint8_t length_bytes[8]; - uint8_t padding[SHA256_BLOCK_SIZE] = - { - 0x80 - }; - - int i; - - for (i = 0; i < 8; i++) - { - length_bytes[7 - i] = (uint8_t)(ctx->bitcount >> (i * 8)); - } - - if (ctx->buffer_len < 56) - { - sha256_update(ctx, padding, 56 - ctx->buffer_len); - } - else - { - sha256_update(ctx, padding, SHA256_BLOCK_SIZE - ctx->buffer_len); - sha256_update(ctx, padding + 1, 56); - } - - sha256_update(ctx, length_bytes, sizeof(length_bytes)); - - for (i = 0; i < 8; i++) - { - sha256_store32(digest + i * 4, ctx->state[i]); - } -} - -static int sha256_file(const char *path, char *digest_hex, size_t digest_len) -{ - struct sha256_state_s ctx; - uint8_t digest[SHA256_DIGEST_SIZE]; - uint8_t buffer[4096]; - static const char g_hex[] = "0123456789abcdef"; - FILE *stream; - size_t nread; - int i; - - if (digest_len < SHA256_DIGEST_SIZE * 2 + 1) - { - fprintf(stderr, "digest buffer is too small\n"); - return -1; - } - - stream = fopen(path, "rb"); - if (stream == NULL) - { - fprintf(stderr, "failed to open %s: %s\n", path, strerror(errno)); - return -1; - } - - sha256_init(&ctx); - - while ((nread = fread(buffer, 1, sizeof(buffer), stream)) > 0) - { - sha256_update(&ctx, buffer, nread); - } - - if (ferror(stream) != 0) - { - fprintf(stderr, "failed to read %s: %s\n", path, strerror(errno)); - fclose(stream); - return -1; - } - - fclose(stream); - sha256_final(&ctx, digest); - - for (i = 0; i < SHA256_DIGEST_SIZE; i++) - { - digest_hex[i * 2] = g_hex[digest[i] >> 4]; - digest_hex[i * 2 + 1] = g_hex[digest[i] & 0x0f]; - } - - digest_hex[SHA256_DIGEST_SIZE * 2] = '\0'; - return 0; -} - -static int write_text_file(const char *path, const char *content) -{ - FILE *stream = fopen(path, "w"); - - if (stream == NULL) - { - fprintf(stderr, "failed to open %s: %s\n", path, strerror(errno)); - return -1; - } - - if (fputs(content, stream) == EOF) - { - fprintf(stderr, "failed to write %s: %s\n", path, strerror(errno)); - fclose(stream); - return -1; - } - - if (fclose(stream) != 0) - { - fprintf(stderr, "failed to close %s: %s\n", path, strerror(errno)); - return -1; - } - - return 0; -} - -static int write_index_file(const char *path, const char *arch, - const char *compat, const char *digest) -{ - const char *artifact = "hello"; - FILE *stream = fopen(path, "w"); - - if (stream == NULL) - { - fprintf(stderr, "failed to open %s: %s\n", path, strerror(errno)); - return -1; - } - - if (fprintf(stream, - "{\"_nxpkg_source\":\"/etc/nxpkg/index.json\"," - "\"packages\":[" - "{\"name\":\"hello\",\"version\":\"1.0.0\",\"arch\":\"%s\"," - "\"compat\":\"%s\",\"artifact\":\"%s\",\"sha256\":\"%s\"," - "\"type\":\"elf\"}," - "{\"name\":\"hello\",\"version\":\"9.9.9\",\"arch\":\"arm\"," - "\"compat\":\"stm32f4discovery\",\"artifact\":\"%s\"," - "\"sha256\":\"%s\",\"type\":\"elf\"}" - "]}\n", - arch, compat, artifact, digest, artifact, digest) < 0) - { - fprintf(stderr, "failed to write %s: %s\n", path, strerror(errno)); - fclose(stream); - return -1; - } - - if (fclose(stream) != 0) - { - fprintf(stderr, "failed to close %s: %s\n", path, strerror(errno)); - return -1; - } - - return 0; -} - -static int write_bad_index_file(const char *path, const char *arch, - const char *compat) -{ - FILE *stream = fopen(path, "w"); - - if (stream == NULL) - { - fprintf(stderr, "failed to open %s: %s\n", path, strerror(errno)); - return -1; - } - - if (fprintf(stream, - "{\"_nxpkg_source\":\"/etc/nxpkg/index.json\"," - "\"packages\":[" - "{\"name\":\"hello-missing\",\"version\":\"1.0.0\"," - "\"arch\":\"%s\",\"compat\":\"%s\"," - "\"artifact\":\"hello-missing\"," - "\"sha256\":\"" - "00000000000000000000000000000000" - "00000000000000000000000000000000" - "\",\"type\":\"elf\"}" - "]}\n", - arch, compat) < 0) - { - fprintf(stderr, "failed to write %s: %s\n", path, strerror(errno)); - fclose(stream); - return -1; - } - - if (fclose(stream) != 0) - { - fprintf(stderr, "failed to close %s: %s\n", path, strerror(errno)); - return -1; - } - - return 0; -} - -static void usage(const char *progname) -{ - fprintf(stderr, - "usage: %s <hello-bin> <index-json> <bad-index-json> " - "<pkgtest-nsh> <pkgfail-nsh> <arch> <compat>\n", - progname); -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -int main(int argc, char *argv[]) -{ - char digest[SHA256_DIGEST_SIZE * 2 + 1]; - static const char g_pkgtest[] = - "mount -t tmpfs /etc\n" - "mount -t tmpfs /var\n" - "mkdir /etc/nxpkg\n" - "cp /mnt/elf/romfs/index.json /etc/nxpkg/index.json\n" - "cp /mnt/elf/romfs/hello /etc/nxpkg/hello\n" - "mkdir /var/lib\n" - "mkdir /var/lib/nxpkg\n" - "cp /mnt/elf/romfs/index.json /var/lib/nxpkg/index.jsn\n" - "nxpkg install hello\n" - "nxpkg list\n"; - static const char g_pkgfail[] = - "mount -t tmpfs /etc\n" - "mount -t tmpfs /var\n" - "mkdir /etc/nxpkg\n" - "cp /mnt/elf/romfs/bad-index.json /etc/nxpkg/index.json\n" - "mkdir /var/lib\n" - "mkdir /var/lib/nxpkg\n" - "cp /mnt/elf/romfs/bad-index.json /var/lib/nxpkg/index.jsn\n" - "nxpkg install hello-missing\n"; - - if (argc != 8) - { - usage(argv[0]); - return EXIT_FAILURE; - } - - if (sha256_file(argv[1], digest, sizeof(digest)) < 0 || - write_index_file(argv[2], argv[6], argv[7], digest) < 0 || - write_bad_index_file(argv[3], argv[6], argv[7]) < 0 || - write_text_file(argv[4], g_pkgtest) < 0 || - write_text_file(argv[5], g_pkgfail) < 0) - { - return EXIT_FAILURE; - } - - return EXIT_SUCCESS; -} diff --git a/examples/elf/tests/.gitignore b/examples/elf/tests/.gitignore index 78af96a0d..abf82cfea 100644 --- a/examples/elf/tests/.gitignore +++ b/examples/elf/tests/.gitignore @@ -4,6 +4,4 @@ /cromfs /cromfs.c /dirlist.c -/extfs /symtab.c -/Kconfig diff --git a/examples/elf/tests/CMakeLists.txt b/examples/elf/tests/CMakeLists.txt deleted file mode 100644 index 952929788..000000000 --- a/examples/elf/tests/CMakeLists.txt +++ /dev/null @@ -1,23 +0,0 @@ -# ############################################################################## -# apps/examples/elf/tests/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -nuttx_add_subdirectory() diff --git a/examples/elf/tests/Make.defs b/examples/elf/tests/Make.defs deleted file mode 100644 index e29058c49..000000000 --- a/examples/elf/tests/Make.defs +++ /dev/null @@ -1,41 +0,0 @@ -############################################################################ -# apps/examples/elf/tests/Make.defs -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifeq ($(CONFIG_EXAMPLES_ELF),y) - CONFIGURED_APPS += $(APPDIR)/examples/elf/tests/errno - CONFIGURED_APPS += $(APPDIR)/examples/elf/tests/hello - ifneq ($(CONFIG_DISABLE_SIGNALS),y) - CONFIGURED_APPS += $(APPDIR)/examples/elf/tests/signal - endif - CONFIGURED_APPS += $(APPDIR)/examples/elf/tests/struct - ifeq ($(CONFIG_HAVE_CXX),y) - CONFIGURED_APPS += $(APPDIR)/examples/elf/tests/helloxx - endif - ifeq ($(CONFIG_EXAMPLES_ELF_LONGJMP),y) - CONFIGURED_APPS += $(APPDIR)/examples/elf/tests/longjmp - endif - ifneq ($(CONFIG_DISABLE_PTHREAD),y) - CONFIGURED_APPS += $(APPDIR)/examples/elf/tests/mutex - CONFIGURED_APPS += $(APPDIR)/examples/elf/tests/pthread - endif - ifneq ($(CONFIG_ARCH_ADDRENV),y) - CONFIGURED_APPS += $(APPDIR)/examples/elf/tests/task - endif -endif diff --git a/examples/elf/tests/Makefile b/examples/elf/tests/Makefile index 741d9d7a9..1ade3b106 100644 --- a/examples/elf/tests/Makefile +++ b/examples/elf/tests/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/elf/tests/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -20,6 +18,103 @@ # ############################################################################ -MENUDESC = "Elf tests example" +include $(APPDIR)/Make.defs -include $(APPDIR)/Directory.mk +ALL_SUBDIRS = errno hello helloxx longjmp mutex pthread signal task struct +BUILD_SUBDIRS = errno hello struct signal + +ifeq ($(CONFIG_HAVE_CXX),y) +BUILD_SUBDIRS += helloxx +endif + +ifeq ($(CONFIG_EXAMPLES_ELF_LONGJMP),y) +BUILD_SUBDIRS += longjmp +endif + +ifneq ($(CONFIG_DISABLE_PTHREAD),y) +BUILD_SUBDIRS += mutex pthread +endif + +ifneq ($(CONFIG_ARCH_ADDRENV),y) +BUILD_SUBDIRS += task +endif + +ELF_DIR = $(APPDIR)/examples/elf +TESTS_DIR = $(ELF_DIR)/tests +DIRLIST_SRC = $(TESTS_DIR)/dirlist.c +SYMTAB_SRC = $(TESTS_DIR)/symtab.c + +ifeq ($(CONFIG_EXAMPLES_ELF_ROMFS),y) + FSIMG_SUBDIR = romfs + FSIMG_DIR = $(TESTS_DIR)/$(FSIMG_SUBDIR) + ROMFS_IMG = $(TESTS_DIR)/romfs.img + FSIMG_SRC = $(TESTS_DIR)/romfs.c +else + NXTOOLDIR = $(TOPDIR)/tools + GENCROMFSSRC = gencromfs.c + GENCROMFSEXE = gencromfs$(HOSTEXEEXT) + + FSIMG_SUBDIR = cromfs + FSIMG_DIR = $(TESTS_DIR)/$(FSIMG_SUBDIR) + FSIMG_SRC = $(TESTS_DIR)/cromfs.c +endif + +define DIR_template +$(1)_$(2): + +$(Q) $(MAKE) -C $(1) $(2) TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)" FSIMG_DIR="$(FSIMG_DIR)" CROSSDEV=$(CROSSDEV) +endef + +all: $(FSIMG_SRC) $(DIRLIST_SRC) $(SYMTAB_SRC) +.PHONY: all clean install + +$(foreach DIR, $(ALL_SUBDIRS), $(eval $(call DIR_template,$(DIR),clean))) +$(foreach DIR, $(BUILD_SUBDIRS), $(eval $(call DIR_template,$(DIR),install))) + +# Install each program in the file system image directory + +install: $(foreach DIR, $(BUILD_SUBDIRS), $(DIR)_install) + +ifeq ($(CONFIG_EXAMPLES_ELF_ROMFS),y) +# Create the romfs.img file from the populated romfs directory + +$(ROMFS_IMG): install + $(Q) genromfs -f $@.tmp -d $(FSIMG_DIR) -V "ELFTEST" + $(Q) $(call TESTANDREPLACEFILE, $@.tmp, $@) + +# Create the romfs.c file from the romfs.img file + +$(FSIMG_SRC): $(ROMFS_IMG) + $(Q) (cd $(TESTS_DIR) && echo "#include <nuttx/compiler.h>" >$@ && \ + xxd -i romfs.img | sed -e "s/^unsigned char/const unsigned char aligned_data(4)/g" >>$@) + +else +# Make sure that the NuttX gencromfs tool has been built + +$(NXTOOLDIR)/$(GENCROMFSEXE): $(NXTOOLDIR)/$(GENCROMFSSRC) + $(Q) $(MAKE) -C $(NXTOOLDIR) -f Makefile.host $(GENCROMFSEXE) + +# Create the cromfs.h header file from the populated cromfs directory + +$(FSIMG_SRC): install $(NXTOOLDIR)/$(GENCROMFSEXE) + $(Q) $(NXTOOLDIR)/$(GENCROMFSEXE) $(FSIMG_DIR) $@.tmp + $(Q) $(call TESTANDREPLACEFILE, $@.tmp, $@) + +endif + +# Create the dirlist.h header file from the file system image directory + +$(DIRLIST_SRC): install + $(Q) $(TESTS_DIR)/mkdirlist.sh $(FSIMG_DIR) >$@.tmp + $(Q) $(call TESTANDREPLACEFILE, $@.tmp, $@) + +# Create the exported symbol table + +$(SYMTAB_SRC): install + $(Q) $(APPDIR)$(DELIM)tools$(DELIM)mksymtab.sh $(FSIMG_DIR) g_elf >$@.tmp + $(Q) $(call TESTANDREPLACEFILE, $@.tmp, $@) + +# Clean each subdirectory + +clean: $(foreach DIR, $(ALL_SUBDIRS), $(DIR)_clean) + $(Q) rm -f $(FSIMG_SRC) $(DIRLIST_SRC) $(ROMFS_IMG) $(SYMTAB_SRC) + $(Q) rm -rf $(FSIMG_DIR) diff --git a/examples/elf/tests/errno/Kconfig b/examples/elf/tests/errno/Kconfig deleted file mode 100644 index f72f3c094..000000000 --- a/examples/elf/tests/errno/Kconfig +++ /dev/null @@ -1,4 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# diff --git a/examples/elf/tests/errno/Makefile b/examples/elf/tests/errno/Makefile index ee383144d..4432cbd4a 100644 --- a/examples/elf/tests/errno/Makefile +++ b/examples/elf/tests/errno/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/elf/tests/errno/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -22,10 +20,49 @@ include $(APPDIR)/Make.defs -PROGNAME = errno -PRIORITY = 100 -STACKSIZE = $(CONFIG_ELF_STACKSIZE) -MODULE = m -MAINSRC = errno.c +ifeq ($(CONFIG_EXAMPLES_ELF_SYSCALL),y) +LDELFFLAGS += -Bstatic +LDLIBPATH += -L $(NUTTXLIB) +else +ifeq ($(CONFIG_EXAMPLES_ELF_LIBC),y) +LDELFFLAGS += -Bstatic +LDLIBPATH += -L $(NUTTXLIB) +endif +endif -include $(APPDIR)/Application.mk +ifeq ($(CONFIG_EXAMPLES_ELF_LIBC),y) +LDLIBS += -lc +endif + +ifeq ($(CONFIG_EXAMPLES_ELF_SYSCALL),y) +LDLIBS += -lproxies +endif + +BIN = errno + +SRCS = $(BIN).c +OBJS = $(SRCS:.c=$(OBJEXT)) + +all: $(BIN) +.PHONY: all clean install + +$(OBJS): %$(OBJEXT): %.c + @echo "CC: $<" + $(Q) $(CC) -c $(CELFFLAGS) $< -o $@ + +$(BIN): $(OBJS) + @echo "LD: $<" + $(Q) $(LD) $(LDELFFLAGS) $(LDLIBPATH) -o $@ $(ARCHCRT0OBJ) $^ $(LDLIBS) + +$(FSIMG_DIR)/$(BIN): $(BIN) + $(Q) mkdir -p $(FSIMG_DIR) + $(Q) install $(BIN) $(FSIMG_DIR)/$(BIN) +ifneq ($(CONFIG_DEBUG_SYMBOLS),y) + $(Q) $(STRIP) $(FSIMG_DIR)/$(BIN) +endif + +install: $(FSIMG_DIR)/$(BIN) + +clean: + $(call DELFILE, $(BIN)) + $(call CLEAN) diff --git a/examples/elf/tests/errno/errno.c b/examples/elf/tests/errno/errno.c index 8a26e47c4..e75659f3b 100644 --- a/examples/elf/tests/errno/errno.c +++ b/examples/elf/tests/errno/errno.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/elf/tests/errno/errno.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/elf/tests/hello/CMakeLists.txt b/examples/elf/tests/hello/CMakeLists.txt deleted file mode 100644 index d3906bfcf..000000000 --- a/examples/elf/tests/hello/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# ############################################################################## -# apps/examples/elf/tests/hello/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_ELF) - nuttx_add_application( - NAME - hello - SRCS - hello.c - STACKSIZE - ${CONFIG_ELF_STACKSIZE} - MODULE - m) -endif() diff --git a/examples/elf/tests/hello/Kconfig b/examples/elf/tests/hello/Kconfig deleted file mode 100644 index f72f3c094..000000000 --- a/examples/elf/tests/hello/Kconfig +++ /dev/null @@ -1,4 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# diff --git a/examples/elf/tests/hello/Makefile b/examples/elf/tests/hello/Makefile index 6920b1522..cde309695 100644 --- a/examples/elf/tests/hello/Makefile +++ b/examples/elf/tests/hello/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/elf/tests/hello/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -22,10 +20,49 @@ include $(APPDIR)/Make.defs -PROGNAME = hello -PRIORITY = 100 -STACKSIZE = $(CONFIG_ELF_STACKSIZE) -MODULE = m -MAINSRC = hello.c +ifeq ($(CONFIG_EXAMPLES_ELF_SYSCALL),y) +LDELFFLAGS += -Bstatic +LDLIBPATH += -L $(NUTTXLIB) +else +ifeq ($(CONFIG_EXAMPLES_ELF_LIBC),y) +LDELFFLAGS += -Bstatic +LDLIBPATH += -L $(NUTTXLIB) +endif +endif -include $(APPDIR)/Application.mk +ifeq ($(CONFIG_EXAMPLES_ELF_LIBC),y) +LDLIBS += -lc +endif + +ifeq ($(CONFIG_EXAMPLES_ELF_SYSCALL),y) +LDLIBS += -lproxies +endif + +BIN = hello + +SRCS = $(BIN).c +OBJS = $(SRCS:.c=$(OBJEXT)) + +all: $(BIN) +.PHONY: all clean install + +$(OBJS): %$(OBJEXT): %.c + @echo "CC: $<" + $(Q) $(CC) -c $(CELFFLAGS) $< -o $@ + +$(BIN): $(OBJS) + @echo "LD: $<" + $(Q) $(LD) $(LDELFFLAGS) $(LDLIBPATH) -o $@ $(ARCHCRT0OBJ) $^ $(LDLIBS) + +$(FSIMG_DIR)/$(BIN): $(BIN) + $(Q) mkdir -p $(FSIMG_DIR) + $(Q) install $(BIN) $(FSIMG_DIR)/$(BIN) +ifneq ($(CONFIG_DEBUG_SYMBOLS),y) + $(Q) $(STRIP) $(FSIMG_DIR)/$(BIN) +endif + +install: $(FSIMG_DIR)/$(BIN) + +clean: + $(call DELFILE, $(BIN)) + $(call CLEAN) diff --git a/examples/elf/tests/hello/hello.c b/examples/elf/tests/hello/hello.c index d2856f73b..41b3cfcb8 100644 --- a/examples/elf/tests/hello/hello.c +++ b/examples/elf/tests/hello/hello.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/elf/tests/hello/hello.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/elf/tests/helloxx/Kconfig b/examples/elf/tests/helloxx/Kconfig deleted file mode 100644 index f72f3c094..000000000 --- a/examples/elf/tests/helloxx/Kconfig +++ /dev/null @@ -1,4 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# diff --git a/examples/elf/tests/helloxx/Makefile b/examples/elf/tests/helloxx/Makefile index 667bf453d..90124073c 100644 --- a/examples/elf/tests/helloxx/Makefile +++ b/examples/elf/tests/helloxx/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/elf/tests/helloxx/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -22,19 +20,154 @@ include $(APPDIR)/Make.defs -PROGNAME = hello++1 hello++2 -PRIORITY = 100 -STACKSIZE = $(CONFIG_ELF_STACKSIZE) -MODULE = m -MAINSRC = hello++1.cxx hello++2.cxx +ifeq ($(CONFIG_EXAMPLES_ELF_SYSCALL),y) +LDELFFLAGS += -Bstatic +LDLIBPATH += -L $(NUTTXLIB) +else +ifeq ($(CONFIG_EXAMPLES_ELF_LIBC),y) +LDELFFLAGS += -Bstatic +LDLIBPATH += -L $(NUTTXLIB) +endif +endif + +ifeq ($(CONFIG_EXAMPLES_ELF_LIBC),y) +LDLIBS += -lc +endif + +ifeq ($(CONFIG_EXAMPLES_ELF_SYSCALL),y) +LDLIBS += -lproxies +endif + +BIN1 = hello++1 +ALL_BIN = $(FSIMG_DIR)/$(BIN1) +BIN2 = hello++2 +ALL_BIN += $(FSIMG_DIR)/$(BIN2) ifeq ($(CONFIG_HAVE_CXXINITIALIZE),y) - PROGNAME += hello++3 - MAINSRC += hello++3.cxx +BIN3 = hello++3 +ALL_BIN += $(FSIMG_DIR)/$(BIN3) +ifeq ($(CONFIG_EXAMPLES_ELF_CXX),y) +BIN4 = hello++4 +ALL_BIN += $(FSIMG_DIR)/$(BIN4) +BIN5 = hello++5 +ALL_BIN += $(FSIMG_DIR)/$(BIN5) +endif +endif + +SRCS1 = $(BIN1).c +OBJS1 = $(SRCS1:.c=$(OBJEXT)) + +SRCS2 = $(BIN2).c +OBJS2 = $(SRCS2:.c=$(OBJEXT)) + +ifeq ($(CONFIG_HAVE_CXXINITIALIZE),y) +SRCS3 = $(BIN3).c +OBJS3 = $(SRCS3:.c=$(OBJEXT)) +ifeq ($(CONFIG_EXAMPLES_ELF_CXX),y) +SRCS4 = $(BIN4).c +OBJS4 = $(SRCS4:.c=$(OBJEXT)) +SRCS5 = $(BIN5).c +OBJS5 = $(SRCS5:.c=$(OBJEXT)) +endif +endif + +SRCS = $(SRCS1) $(SRCS2) $(SRCS3) $(SRCS4) $(SRCS5) +OBJS = $(OBJS1) $(OBJS2) $(OBJS3) $(OBJS4) $(OBJS5) + +LDLIBSTDC_STUBS_DIR = $(TOPDIR)/libxx +LDLIBSTDC_STUBS_LIB = $(LDLIBSTDC_STUBS_DIR)/liblibxx.a + +all: $(BIN1) $(BIN2) $(BIN3) $(BIN4) $(BIN5) +.PHONY: all clean install + +$(OBJS): %$(OBJEXT): %.cxx + @echo "CC: $<" + $(Q) $(CXX) -c $(CXXELFFLAGS) $< -o $@ + +# This contains libstdc++ stubs to that you can build C++ code +# without actually having libstdc++ + +$(LDLIBSTDC_STUBS_LIB): + $(Q) $(MAKE) -C $(LDLIBSTDC_STUBS_DIR) TOPDIR=$(TOPDIR) + +# BIN1 and BIN2 link just like C code because they contain no +# static constructors. BIN1 is equivalent to a C hello world; +# BIN2 contains a class that implements hello world, but it is +# not statically initialized. + +$(BIN1): $(OBJS1) + @echo "LD: $<" + $(Q) $(LD) $(LDELFFLAGS) $(LDLIBPATH) -o $@ $(ARCHCRT0OBJ) $^ $(LDLIBS) + +$(BIN2): $(OBJS2) + @echo "LD: $<" + $(Q) $(LD) $(LDELFFLAGS) $(LDLIBPATH) -o $@ $(ARCHCRT0OBJ) $^ $(LDLIBS) + +# BIN3 is equivalent to BIN2 except that is uses static initializers + +ifeq ($(CONFIG_HAVE_CXXINITIALIZE),y) +$(BIN3): $(OBJS3) + @echo "LD: $<" + $(Q) $(LD) $(LDELFFLAGS) $(LDLIBPATH) -o $@ $(ARCHCRT0OBJ) $^ $(LDLIBS) + +# BIN4 is similar to BIN3 except that it uses the streams code from libstdc++ +# +# NOTE: libstdc++ is not available for NuttX as of this writing +# +ifeq ($(CONFIG_EXAMPLES_ELF_CXX),y) +$(BIN4): $(OBJS4) + @echo "LD: $<" + $(Q) $(LD) $(LDELFFLAGS) $(LDLIBPATH) -o $@ $(ARCHCRT0OBJ) $^ $(LDLIBS) +$(BIN5): $(OBJS5) + @echo "LD: $<" + $(Q) $(LD) $(LDELFFLAGS) $(LDLIBPATH) -o $@ $(ARCHCRT0OBJ) $^ $(LDLIBS) +endif +endif + +$(FSIMG_DIR)/$(BIN1): $(BIN1) + $(Q) mkdir -p $(FSIMG_DIR) + $(Q) install $(BIN1) $(FSIMG_DIR)/$(BIN1) +ifneq ($(CONFIG_DEBUG_SYMBOLS),y) + $(Q) $(STRIP) $(FSIMG_DIR)/$(BIN1) +endif + +$(FSIMG_DIR)/$(BIN2): $(BIN2) + $(Q) mkdir -p $(FSIMG_DIR) + $(Q) install $(BIN2) $(FSIMG_DIR)/$(BIN2) +ifneq ($(CONFIG_DEBUG_SYMBOLS),y) + $(Q) $(STRIP) $(FSIMG_DIR)/$(BIN2) +endif + +ifeq ($(CONFIG_HAVE_CXXINITIALIZE),y) +$(FSIMG_DIR)/$(BIN3): $(BIN3) + $(Q) mkdir -p $(FSIMG_DIR) + $(Q) install $(BIN3) $(FSIMG_DIR)/$(BIN3) +ifneq ($(CONFIG_DEBUG_SYMBOLS),y) + $(Q) $(STRIP) $(FSIMG_DIR)/$(BIN3) endif ifeq ($(CONFIG_EXAMPLES_ELF_CXX),y) - PROGNAME += hello++4 hello++5 - MAINSRC += hello++4.cxx hello++5.cxx +$(FSIMG_DIR)/$(BIN4): $(BIN4) + $(Q) mkdir -p $(FSIMG_DIR) + $(Q) install $(BIN4) $(FSIMG_DIR)/$(BIN4) +ifneq ($(CONFIG_DEBUG_SYMBOLS),y) + $(Q) $(STRIP) $(FSIMG_DIR)/$(BIN4) endif -include $(APPDIR)/Application.mk +$(FSIMG_DIR)/$(BIN5): $(BIN5) + $(Q) mkdir -p $(FSIMG_DIR) + $(Q) install $(BIN5) $(FSIMG_DIR)/$(BIN5) +ifneq ($(CONFIG_DEBUG_SYMBOLS),y) + $(Q) $(STRIP) $(FSIMG_DIR)/$(BIN5) +endif +endif +endif + +install: $(ALL_BIN) + +clean: + $(call DELFILE, $(BIN1)) + $(call DELFILE, $(BIN2)) + $(call DELFILE, $(BIN3)) + $(call DELFILE, $(BIN4)) + $(call DELFILE, $(BIN5)) + $(call CLEAN) diff --git a/examples/elf/tests/helloxx/hello++1.cxx b/examples/elf/tests/helloxx/hello++1.cxx index 5b79d7f2f..acc86c04c 100644 --- a/examples/elf/tests/helloxx/hello++1.cxx +++ b/examples/elf/tests/helloxx/hello++1.cxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/examples/elf/tests/helloxx/hello++1.cxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The diff --git a/examples/elf/tests/helloxx/hello++2.cxx b/examples/elf/tests/helloxx/hello++2.cxx index a7dc71918..527a29a92 100644 --- a/examples/elf/tests/helloxx/hello++2.cxx +++ b/examples/elf/tests/helloxx/hello++2.cxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/examples/elf/tests/helloxx/hello++2.cxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -46,7 +44,7 @@ public: CThingSayer(void) { printf("CThingSayer::CThingSayer: I am!\n"); - szWhatToSay = NULL; + szWhatToSay = (const char*)NULL; } ~CThingSayer(void) @@ -57,7 +55,7 @@ public: printf("CThingSayer::~CThingSayer: I will never say '%s' again\n", szWhatToSay); } - szWhatToSay = NULL; + szWhatToSay = (const char*)NULL; } void Initialize(const char *czSayThis) diff --git a/examples/elf/tests/helloxx/hello++3.cxx b/examples/elf/tests/helloxx/hello++3.cxx index d76406eac..e23de7bf2 100644 --- a/examples/elf/tests/helloxx/hello++3.cxx +++ b/examples/elf/tests/helloxx/hello++3.cxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/examples/elf/tests/helloxx/hello++3.cxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -61,7 +59,7 @@ static CThingSayer MyThingSayer; CThingSayer::CThingSayer(void) { printf("CThingSayer::CThingSayer: I am!\n"); - szWhatToSay = NULL; + szWhatToSay = (const char*)NULL; } CThingSayer::~CThingSayer(void) @@ -72,7 +70,7 @@ CThingSayer::~CThingSayer(void) printf("CThingSayer::~CThingSayer: I will never say '%s' again\n", szWhatToSay); } - szWhatToSay = NULL; + szWhatToSay = (const char*)NULL; } void CThingSayer::Initialize(const char *czSayThis) diff --git a/examples/elf/tests/helloxx/hello++4.cxx b/examples/elf/tests/helloxx/hello++4.cxx index 3f065cafe..c10abfde9 100644 --- a/examples/elf/tests/helloxx/hello++4.cxx +++ b/examples/elf/tests/helloxx/hello++4.cxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/examples/elf/tests/helloxx/hello++4.cxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -37,7 +35,7 @@ #include <iostream> #ifndef NULL -# define NULL ((void*)0L) +# define NULL ((void*)0L) #endif ///////////////////////////////////////////////////////////////////////////// @@ -78,7 +76,7 @@ static CThingSayer MyThingSayer; CThingSayer::CThingSayer(void) { cout << "CThingSayer::CThingSayer: I am!" << endl; - szWhatToSay = NULL; + szWhatToSay = (const char*)NULL; } CThingSayer::~CThingSayer(void) @@ -89,7 +87,7 @@ CThingSayer::~CThingSayer(void) cout << "CThingSayer::~CThingSayer: I will never say '" << szWhatToSay << "' again" << endl; } - szWhatToSay = NULL; + szWhatToSay = (const char*)NULL; } void CThingSayer::Initialize(const char *czSayThis) diff --git a/examples/elf/tests/helloxx/hello++5.cxx b/examples/elf/tests/helloxx/hello++5.cxx index c72a8cc9a..153d05c3f 100644 --- a/examples/elf/tests/helloxx/hello++5.cxx +++ b/examples/elf/tests/helloxx/hello++5.cxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/examples/elf/tests/helloxx/hello++5.cxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -39,7 +37,7 @@ #include <string> #ifndef NULL -# define NULL ((void*)0L) +# define NULL ((void*)0L) #endif ///////////////////////////////////////////////////////////////////////////// @@ -91,7 +89,7 @@ static CThingSayer MyThingSayer; MyException::MyException(std::string r = NULL) : reason(r) { - if(r.length() > 0) + if( r.length() > 0 ) { cout << "MyException(" << r << "): constructing with reason." << endl; } @@ -120,7 +118,7 @@ const char *MyException::what() const throw() CThingSayer::CThingSayer(void) { cout << "CThingSayer::CThingSayer: I am!" << endl; - szWhatToSay = NULL; + szWhatToSay = (const char*)NULL; } CThingSayer::~CThingSayer(void) @@ -131,7 +129,7 @@ CThingSayer::~CThingSayer(void) cout << "CThingSayer::~CThingSayer: I will never say '" << szWhatToSay << "' again" << endl; } - szWhatToSay = NULL; + szWhatToSay = (const char*)NULL; } void CThingSayer::Initialize(const char *czSayThis) @@ -156,7 +154,7 @@ void CThingSayer::ThrowThing(void) void CThingSayer::ThrowMyThing(const char *czSayThis = NULL) { cout << "CThingSayer::ThrowMyThing: I am now throwing an MyException (with reason)." << endl; - throw MyException(string(czSayThis)); + throw MyException( string(czSayThis) ); } ///////////////////////////////////////////////////////////////////////////// diff --git a/examples/elf/tests/longjmp/Kconfig b/examples/elf/tests/longjmp/Kconfig deleted file mode 100644 index f72f3c094..000000000 --- a/examples/elf/tests/longjmp/Kconfig +++ /dev/null @@ -1,4 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# diff --git a/examples/elf/tests/longjmp/Makefile b/examples/elf/tests/longjmp/Makefile index a5e482f28..17e325c78 100644 --- a/examples/elf/tests/longjmp/Makefile +++ b/examples/elf/tests/longjmp/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/elf/tests/longjmp/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -22,10 +20,49 @@ include $(APPDIR)/Make.defs -PROGNAME = longjmp -PRIORITY = 100 -STACKSIZE = $(CONFIG_ELF_STACKSIZE) -MODULE = m -MAINSRC = longjmp.c +ifeq ($(CONFIG_EXAMPLES_ELF_SYSCALL),y) +LDELFFLAGS += -Bstatic +LDLIBPATH += -L $(NUTTXLIB) +else +ifeq ($(CONFIG_EXAMPLES_ELF_LIBC),y) +LDELFFLAGS += -Bstatic +LDLIBPATH += -L $(NUTTXLIB) +endif +endif -include $(APPDIR)/Application.mk +ifeq ($(CONFIG_EXAMPLES_ELF_LIBC),y) +LDLIBS += -lc +endif + +ifeq ($(CONFIG_EXAMPLES_ELF_SYSCALL),y) +LDLIBS += -lproxies +endif + +BIN = longjmp + +SRCS = $(BIN).c +OBJS = $(SRCS:.c=$(OBJEXT)) + +all: $(BIN) +.PHONY: all clean install + +$(OBJS): %$(OBJEXT): %.c + @echo "CC: $<" + $(Q) $(CC) -c $(CELFFLAGS) $< -o $@ + +$(BIN): $(OBJS) + @echo "LD: $<" + $(Q) $(LD) $(LDELFFLAGS) $(LDLIBPATH) -o $@ $(ARCHCRT0OBJ) $^ $(LDLIBS) + +$(FSIMG_DIR)/$(BIN): $(BIN) + $(Q) mkdir -p $(FSIMG_DIR) + $(Q) install $(BIN) $(FSIMG_DIR)/$(BIN) +ifneq ($(CONFIG_DEBUG_SYMBOLS),y) + $(Q) $(STRIP) $(FSIMG_DIR)/$(BIN) +endif + +install: $(FSIMG_DIR)/$(BIN) + +clean: + $(call DELFILE, $(BIN)) + $(call CLEAN) diff --git a/examples/elf/tests/longjmp/longjmp.c b/examples/elf/tests/longjmp/longjmp.c index ea48d4569..ca36b95dd 100644 --- a/examples/elf/tests/longjmp/longjmp.c +++ b/examples/elf/tests/longjmp/longjmp.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/elf/tests/longjmp/longjmp.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/elf/tests/mutex/Kconfig b/examples/elf/tests/mutex/Kconfig deleted file mode 100644 index f72f3c094..000000000 --- a/examples/elf/tests/mutex/Kconfig +++ /dev/null @@ -1,4 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# diff --git a/examples/elf/tests/mutex/Makefile b/examples/elf/tests/mutex/Makefile index fe3619513..e95fba84e 100644 --- a/examples/elf/tests/mutex/Makefile +++ b/examples/elf/tests/mutex/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/elf/tests/mutex/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -22,10 +20,49 @@ include $(APPDIR)/Make.defs -PROGNAME = mutex -PRIORITY = 100 -STACKSIZE = $(CONFIG_ELF_STACKSIZE) -MODULE = m -MAINSRC = mutex.c +ifeq ($(CONFIG_EXAMPLES_ELF_SYSCALL),y) +LDELFFLAGS += -Bstatic +LDLIBPATH += -L $(NUTTXLIB) +else +ifeq ($(CONFIG_EXAMPLES_ELF_LIBC),y) +LDELFFLAGS += -Bstatic +LDLIBPATH += -L $(NUTTXLIB) +endif +endif -include $(APPDIR)/Application.mk +ifeq ($(CONFIG_EXAMPLES_ELF_LIBC),y) +LDLIBS += -lc +endif + +ifeq ($(CONFIG_EXAMPLES_ELF_SYSCALL),y) +LDLIBS += -lproxies +endif + +BIN = mutex + +SRCS = $(BIN).c +OBJS = $(SRCS:.c=$(OBJEXT)) + +all: $(BIN) +.PHONY: all clean install + +$(OBJS): %$(OBJEXT): %.c + @echo "CC: $<" + $(Q) $(CC) -c $(CELFFLAGS) $< -o $@ + +$(BIN): $(OBJS) + @echo "LD: $<" + $(Q) $(LD) $(LDELFFLAGS) $(LDLIBPATH) -o $@ $(ARCHCRT0OBJ) $^ $(LDLIBS) + +$(FSIMG_DIR)/$(BIN): $(BIN) + $(Q) mkdir -p $(FSIMG_DIR) + $(Q) install $(BIN) $(FSIMG_DIR)/$(BIN) +ifneq ($(CONFIG_DEBUG_SYMBOLS),y) + $(Q) $(STRIP) $(FSIMG_DIR)/$(BIN) +endif + +install: $(FSIMG_DIR)/$(BIN) + +clean: + $(call DELFILE, $(BIN)) + $(call CLEAN) diff --git a/examples/elf/tests/mutex/mutex.c b/examples/elf/tests/mutex/mutex.c index 2c7310ccf..752941cac 100644 --- a/examples/elf/tests/mutex/mutex.c +++ b/examples/elf/tests/mutex/mutex.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/elf/tests/mutex/mutex.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -44,7 +42,7 @@ static volatile bool bendoftest; * Private Functions ****************************************************************************/ -/* NOTE: it is necessary for functions that are referred to by function +/* NOTE: it is necessary for functions that are referred to by function pointers * pointer to be declared with global scope (at least for ARM). Otherwise, * a relocation type that is not supported by ELF is generated by GCC. */ @@ -105,7 +103,7 @@ int main(int argc, char **argv) printf("Starting thread 1\n"); bendoftest = false; - if ((pthread_create(&thread1, NULL, (void *)thread_func, (void *)1)) != 0) + if ((pthread_create(&thread1, NULL, (void*)thread_func, (void*)1)) != 0) { fprintf(stderr, "Error in thread#1 creation\n"); } diff --git a/examples/elf/tests/pthread/Kconfig b/examples/elf/tests/pthread/Kconfig deleted file mode 100644 index f72f3c094..000000000 --- a/examples/elf/tests/pthread/Kconfig +++ /dev/null @@ -1,4 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# diff --git a/examples/elf/tests/pthread/Makefile b/examples/elf/tests/pthread/Makefile index b1ca8c70d..39e821e80 100644 --- a/examples/elf/tests/pthread/Makefile +++ b/examples/elf/tests/pthread/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/elf/tests/pthread/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -22,10 +20,49 @@ include $(APPDIR)/Make.defs -PROGNAME = pthread -PRIORITY = 100 -STACKSIZE = $(CONFIG_ELF_STACKSIZE) -MODULE = m -MAINSRC = pthread.c +ifeq ($(CONFIG_EXAMPLES_ELF_SYSCALL),y) +LDELFFLAGS += -Bstatic +LDLIBPATH += -L $(NUTTXLIB) +else +ifeq ($(CONFIG_EXAMPLES_ELF_LIBC),y) +LDELFFLAGS += -Bstatic +LDLIBPATH += -L $(NUTTXLIB) +endif +endif -include $(APPDIR)/Application.mk +ifeq ($(CONFIG_EXAMPLES_ELF_LIBC),y) +LDLIBS += -lc +endif + +ifeq ($(CONFIG_EXAMPLES_ELF_SYSCALL),y) +LDLIBS += -lproxies +endif + +BIN = pthread + +SRCS = $(BIN).c +OBJS = $(SRCS:.c=$(OBJEXT)) + +all: $(BIN) +.PHONY: all clean install + +$(OBJS): %$(OBJEXT): %.c + @echo "CC: $<" + $(Q) $(CC) -c $(CELFFLAGS) $< -o $@ + +$(BIN): $(OBJS) + @echo "LD: $<" + $(Q) $(LD) $(LDELFFLAGS) $(LDLIBPATH) -o $@ $(ARCHCRT0OBJ) $^ $(LDLIBS) + +$(FSIMG_DIR)/$(BIN): $(BIN) + $(Q) mkdir -p $(FSIMG_DIR) + $(Q) install $(BIN) $(FSIMG_DIR)/$(BIN) +ifneq ($(CONFIG_DEBUG_SYMBOLS),y) + $(Q) $(STRIP) $(FSIMG_DIR)/$(BIN) +endif + +install: $(FSIMG_DIR)/$(BIN) + +clean: + $(call DELFILE, $(BIN)) + $(call CLEAN) diff --git a/examples/elf/tests/pthread/pthread.c b/examples/elf/tests/pthread/pthread.c index cea9f0330..4e5e8f810 100644 --- a/examples/elf/tests/pthread/pthread.c +++ b/examples/elf/tests/pthread/pthread.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/elf/tests/pthread/pthread.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/elf/tests/signal/Kconfig b/examples/elf/tests/signal/Kconfig deleted file mode 100644 index f72f3c094..000000000 --- a/examples/elf/tests/signal/Kconfig +++ /dev/null @@ -1,4 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# diff --git a/examples/elf/tests/signal/Makefile b/examples/elf/tests/signal/Makefile index 64d674033..d89e18384 100644 --- a/examples/elf/tests/signal/Makefile +++ b/examples/elf/tests/signal/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/elf/tests/signal/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -22,10 +20,49 @@ include $(APPDIR)/Make.defs -PROGNAME = signal -PRIORITY = 100 -STACKSIZE = $(CONFIG_ELF_STACKSIZE) -MODULE = m -MAINSRC = signal.c +ifeq ($(CONFIG_EXAMPLES_ELF_SYSCALL),y) +LDELFFLAGS += -Bstatic +LDLIBPATH += -L $(NUTTXLIB) +else +ifeq ($(CONFIG_EXAMPLES_ELF_LIBC),y) +LDELFFLAGS += -Bstatic +LDLIBPATH += -L $(NUTTXLIB) +endif +endif -include $(APPDIR)/Application.mk +ifeq ($(CONFIG_EXAMPLES_ELF_LIBC),y) +LDLIBS += -lc +endif + +ifeq ($(CONFIG_EXAMPLES_ELF_SYSCALL),y) +LDLIBS += -lproxies +endif + +BIN = signal + +SRCS = $(BIN).c +OBJS = $(SRCS:.c=$(OBJEXT)) + +all: $(BIN) +.PHONY: all clean install + +$(OBJS): %$(OBJEXT): %.c + @echo "CC: $<" + $(Q) $(CC) -c $(CELFFLAGS) $< -o $@ + +$(BIN): $(OBJS) + @echo "LD: $<" + $(Q) $(LD) $(LDELFFLAGS) $(LDLIBPATH) -o $@ $(ARCHCRT0OBJ) $^ $(LDLIBS) + +$(FSIMG_DIR)/$(BIN): $(BIN) + $(Q) mkdir -p $(FSIMG_DIR) + $(Q) install $(BIN) $(FSIMG_DIR)/$(BIN) +ifneq ($(CONFIG_DEBUG_SYMBOLS),y) + $(Q) $(STRIP) $(FSIMG_DIR)/$(BIN) +endif + +install: $(FSIMG_DIR)/$(BIN) + +clean: + $(call DELFILE, $(BIN)) + $(call CLEAN) diff --git a/examples/elf/tests/signal/signal.c b/examples/elf/tests/signal/signal.c index afcdff281..a55070fbe 100644 --- a/examples/elf/tests/signal/signal.c +++ b/examples/elf/tests/signal/signal.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/elf/tests/signal/signal.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -66,8 +64,8 @@ static int sigusr2_rcvd = 0; * Name: siguser_action ****************************************************************************/ -/* NOTE: it is necessary for functions that are referred to by function - * pointers to be declared with global scope (at least for ARM). Otherwise, +/* NOTE: it is necessary for functions that are referred to by function pointers + * pointer to be declared with global scope (at least for ARM). Otherwise, * a relocation type that is not supported by ELF is generated by GCC. */ @@ -225,7 +223,7 @@ int main(int argc, char **argv) /* Verify that the handler that was removed was siguser_action */ - if ((void *)act.sa_handler != (void *)siguser_action) + if ((void*)act.sa_handler != (void*)siguser_action) { fprintf(stderr, "Old SIGUSR2 signal handler (%p) is not siguser_action (%p)\n", diff --git a/examples/elf/tests/struct/Kconfig b/examples/elf/tests/struct/Kconfig deleted file mode 100644 index f72f3c094..000000000 --- a/examples/elf/tests/struct/Kconfig +++ /dev/null @@ -1,4 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# diff --git a/examples/elf/tests/struct/Makefile b/examples/elf/tests/struct/Makefile index 88ab66f3f..e76e5a6c4 100644 --- a/examples/elf/tests/struct/Makefile +++ b/examples/elf/tests/struct/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/elf/tests/struct/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -22,11 +20,48 @@ include $(APPDIR)/Make.defs -PROGNAME = struct -PRIORITY = 100 -STACKSIZE = $(CONFIG_ELF_STACKSIZE) -MODULE = m -CSRCS = struct_dummy.c -MAINSRC = struct_main.c +ifeq ($(CONFIG_EXAMPLES_ELF_SYSCALL),y) +LDELFFLAGS += -Bstatic +LDLIBPATH += -L $(NUTTXLIB) +else +ifeq ($(CONFIG_EXAMPLES_ELF_LIBC),y) +LDELFFLAGS += -Bstatic +LDLIBPATH += -L $(NUTTXLIB) +endif +endif -include $(APPDIR)/Application.mk +ifeq ($(CONFIG_EXAMPLES_ELF_LIBC),y) +LDLIBS += -lc +endif + +ifeq ($(CONFIG_EXAMPLES_ELF_SYSCALL),y) +LDLIBS += -lproxies +endif + +BIN = struct +SRCS = struct_main.c struct_dummy.c +OBJS = $(SRCS:.c=$(OBJEXT)) + +all: $(BIN) +.PHONY: all clean install + +$(OBJS): %$(OBJEXT): %.c + @echo "CC: $<" + $(Q) $(CC) -c $(CELFFLAGS) $< -o $@ + +$(BIN): $(OBJS) + @echo "LD: $<" + $(Q) $(LD) $(LDELFFLAGS) $(LDLIBPATH) -o $@ $(ARCHCRT0OBJ) $^ $(LDLIBS) + +$(FSIMG_DIR)/$(BIN): $(BIN) + $(Q) mkdir -p $(FSIMG_DIR) + $(Q) install $(BIN) $(FSIMG_DIR)/$(BIN) +ifneq ($(CONFIG_DEBUG_SYMBOLS),y) + $(Q) $(STRIP) $(FSIMG_DIR)/$(BIN) +endif + +install: $(FSIMG_DIR)/$(BIN) + +clean: + $(call DELFILE, $(BIN)) + $(call CLEAN) diff --git a/examples/elf/tests/struct/struct.h b/examples/elf/tests/struct/struct.h index bfbe1c8ac..7508f053d 100644 --- a/examples/elf/tests/struct/struct.h +++ b/examples/elf/tests/struct/struct.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/elf/tests/struct/struct.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/elf/tests/struct/struct_dummy.c b/examples/elf/tests/struct/struct_dummy.c index c1361d4eb..d3376417c 100644 --- a/examples/elf/tests/struct/struct_dummy.c +++ b/examples/elf/tests/struct/struct_dummy.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/elf/tests/struct/struct_dummy.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/elf/tests/struct/struct_main.c b/examples/elf/tests/struct/struct_main.c index 5158c03b7..2cb707ec1 100644 --- a/examples/elf/tests/struct/struct_main.c +++ b/examples/elf/tests/struct/struct_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/elf/tests/struct/struct_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -35,7 +33,7 @@ const struct struct_dummy_s dummy_struct = { - DUMMY_SCALAR_VALUE3 + DUMMY_SCALAR_VALUE3 }; int dummy_scalar = DUMMY_SCALAR_VALUE2; diff --git a/examples/elf/tests/task/Kconfig b/examples/elf/tests/task/Kconfig deleted file mode 100644 index f72f3c094..000000000 --- a/examples/elf/tests/task/Kconfig +++ /dev/null @@ -1,4 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# diff --git a/examples/elf/tests/task/Makefile b/examples/elf/tests/task/Makefile index 09424ac96..3db9ab24f 100644 --- a/examples/elf/tests/task/Makefile +++ b/examples/elf/tests/task/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/elf/tests/task/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -22,10 +20,49 @@ include $(APPDIR)/Make.defs -PROGNAME = task -PRIORITY = 100 -STACKSIZE = $(CONFIG_ELF_STACKSIZE) -MODULE = m -MAINSRC = task.c +ifeq ($(CONFIG_EXAMPLES_ELF_SYSCALL),y) +LDELFFLAGS += -Bstatic +LDLIBPATH += -L $(NUTTXLIB) +else +ifeq ($(CONFIG_EXAMPLES_ELF_LIBC),y) +LDELFFLAGS += -Bstatic +LDLIBPATH += -L $(NUTTXLIB) +endif +endif -include $(APPDIR)/Application.mk +ifeq ($(CONFIG_EXAMPLES_ELF_LIBC),y) +LDLIBS += -lc +endif + +ifeq ($(CONFIG_EXAMPLES_ELF_SYSCALL),y) +LDLIBS += -lproxies +endif + +BIN = task + +SRCS = $(BIN).c +OBJS = $(SRCS:.c=$(OBJEXT)) + +all: $(BIN) +.PHONY: all clean install + +$(OBJS): %$(OBJEXT): %.c + @echo "CC: $<" + $(Q) $(CC) -c $(CELFFLAGS) $< -o $@ + +$(BIN): $(OBJS) + @echo "LD: $<" + $(Q) $(LD) $(LDELFFLAGS) $(LDLIBPATH) -o $@ $(ARCHCRT0OBJ) $^ $(LDLIBS) + +$(FSIMG_DIR)/$(BIN): $(BIN) + $(Q) mkdir -p $(FSIMG_DIR) + $(Q) install $(BIN) $(FSIMG_DIR)/$(BIN) +ifneq ($(CONFIG_DEBUG_SYMBOLS),y) + $(Q) $(STRIP) $(FSIMG_DIR)/$(BIN) +endif + +install: $(FSIMG_DIR)/$(BIN) + +clean: + $(call DELFILE, $(BIN)) + $(call CLEAN) diff --git a/examples/elf/tests/task/task.c b/examples/elf/tests/task/task.c index 64a90f07f..8bbc819d9 100644 --- a/examples/elf/tests/task/task.c +++ b/examples/elf/tests/task/task.c @@ -1,7 +1,5 @@ /**************************************************************************** - * apps/examples/elf/tests/task/task.c - * - * SPDX-License-Identifier: Apache-2.0 + * apps/examples/elf/tests/task/parent.c * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -49,11 +47,9 @@ static char no_name[] = "<noname>"; * Privite Functions ****************************************************************************/ -/* NOTE: it is necessary for functions that are referred to by - * function pointers pointer to be declared with global scope - * (at least for ARM). - * Otherwise, a relocation type that is not supported by ELF - * is generated by GCC. +/* NOTE: it is necessary for functions that are referred to by function pointers + * pointer to be declared with global scope (at least for ARM). Otherwise, + * a relocation type that is not supported by ELF is generated by GCC. */ int child_task(int argc, char **argv) @@ -117,8 +113,7 @@ int main(int argc, char **argv) child_argv[0] = child_arg; child_argv[1] = 0; - child_pid = task_create(child_name, 50, 2048, child_task, - (FAR char * const *)child_argv); + child_pid = task_create(child_name, 50, 2048, child_task, (FAR char * const *)child_argv); if (child_pid < 0) { printf("Parent: task_create failed: %d\n", errno); diff --git a/examples/embedlog/CMakeLists.txt b/examples/embedlog/CMakeLists.txt deleted file mode 100644 index 0a403bfc5..000000000 --- a/examples/embedlog/CMakeLists.txt +++ /dev/null @@ -1,40 +0,0 @@ -# ############################################################################## -# apps/examples/embedlog/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_EMBEDLOG) - - if(CONFIG_EXAMPLES_EMBEDLOG_STRIP_ALL_STRINGS) - list(APPEND CFLAGS -DDISABLE_ALL_EMBEDLOG) - endif() - - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_EMBEDLOG_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_EMBEDLOG_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_EMBEDLOG_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_EMBEDLOG} - SRCS - embedlog_main.c) -endif() diff --git a/examples/embedlog/Kconfig b/examples/embedlog/Kconfig index 564823d50..8d92d7327 100644 --- a/examples/embedlog/Kconfig +++ b/examples/embedlog/Kconfig @@ -3,7 +3,7 @@ # see the file kconfig-language.txt in the NuttX tools repository. # -if LOGGING_EMBEDLOG +if SYSTEM_EMBEDLOG config EXAMPLES_EMBEDLOG tristate "embedlog example" @@ -23,39 +23,6 @@ config EXAMPLES_EMBEDLOG if EXAMPLES_EMBEDLOG -config EXAMPLES_EMBEDLOG_STRIP_ALL_STRINGS - bool "Disable embedlog (strip)" - default n - ---help--- - Enabled embedlog so you can disable it... sounds about right. - - Enable this to replace all embedlog function calls with stub - functions that always return OK. This will effectively strip - final binary from all log strings making code considerably - smaller. - - This may be useful in two cases (at least): - - 1) You develop your app on bigger version of target MCU, on - which you have a lot of memory. So on that version of the - build you can afford to enable good diagnostic logs. But - final image may be run on smaller version, on which logs - would not fit. In that case you can strip binary in final - production image. Thanks to that you will get logs in dev - env, but still maintain small footprint on production build. - - 2) You want to hide implementation details that could be - leaked with debug logs from final image. - - It only makes sense to enable this on production type builds. - Linker will optimize out embedlog and remove all unused - functions, just as if embedlog was never built. - - Enabling this will render embedlog example useless - it - will not print anything, but example will stil compile - and final image will be about 15kB smaller. But YMMV - depending how much strings you have in project. - config EXAMPLES_EMBEDLOG_PROGNAME string "Program name" default "embedlog" @@ -72,4 +39,4 @@ config EXAMPLES_EMBEDLOG_STACKSIZE default DEFAULT_TASK_STACKSIZE endif #EXAMPLES_EMBEDLOG -endif #LOGGING_EMBEDLOG +endif #SYSTEM_EMBEDLOG diff --git a/examples/embedlog/Make.defs b/examples/embedlog/Make.defs index 6096211d4..9c2ef3aad 100644 --- a/examples/embedlog/Make.defs +++ b/examples/embedlog/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/embedlog/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/embedlog/Makefile b/examples/embedlog/Makefile index a48e7e76d..f3476b3d7 100644 --- a/examples/embedlog/Makefile +++ b/examples/embedlog/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/embedlog/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -29,10 +27,6 @@ PRIORITY = $(CONFIG_EXAMPLES_EMBEDLOG_PRIORITY) STACKSIZE = $(CONFIG_EXAMPLES_EMBEDLOG_STACKSIZE) MODULE = $(CONFIG_EXAMPLES_EMBEDLOG) -ifeq ($(CONFIG_EXAMPLES_EMBEDLOG_STRIP_ALL_STRINGS),y) - CFLAGS += -DDISABLE_ALL_EMBEDLOG -endif - # embedlog Example MAINSRC = embedlog_main.c diff --git a/examples/embedlog/embedlog_main.c b/examples/embedlog/embedlog_main.c index 85c119364..8857c42a0 100644 --- a/examples/embedlog/embedlog_main.c +++ b/examples/embedlog/embedlog_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/embedlog/embedlog_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -24,7 +22,7 @@ * Included Files ****************************************************************************/ -#include <logging/embedlog.h> +#include <system/embedlog.h> #include <errno.h> #include <nuttx/config.h> #include <stdio.h> @@ -115,6 +113,7 @@ static void el_print_options(void) el_ooption(&g_el, EL_TS, EL_TS_LONG); el_ooption(&g_el, EL_TS, EL_TS_OFF); el_oprint(OELF, "no time information, if your heart desire it"); + el_ooption(&g_el, EL_TS_FRACT, EL_TS_FRACT_NS); el_ooption(&g_el, EL_FINFO, 1); el_oprint(OELF, "log location is very useful for debugging"); @@ -122,10 +121,6 @@ static void el_print_options(void) el_ooption(&g_el, EL_TS, EL_TS_LONG); el_ooption(&g_el, EL_TS_TM, EL_TS_TM_REALTIME); el_ooption(&g_el, EL_PRINT_LEVEL, 1); - - /* nuttx runs on rather slow cpus, so millisecond precision is enough */ - - el_ooption(&g_el, EL_TS_FRACT, EL_TS_FRACT_MS); el_oprint(OELF, "Different scenarios need different options"); el_oprint(OELA, "So we can mix options however we want"); @@ -193,10 +188,6 @@ static void el_print_memory(void) el_oprint(OELI, "print the same region but this time with nice ascii " "table"); el_opmemory_table(OELI, s, sizeof(s)); - - el_ooption(&g_el, EL_PMEMORY_SPACE, 1); - el_oprint(OELI, "print whole ASCII table with additional spacing"); - el_opmemory(OELI, ascii, sizeof(ascii)); } /**************************************************************************** @@ -228,20 +219,53 @@ static void el_print_file(const char *workdir) /* Create full path to log file embedlog will use */ - snprintf(log_path, sizeof(log_path), "%s/log-rotate", workdir); + sprintf(log_path, "%s/log-rotate", workdir); + + /* Enable file rotation, maximum 5 files will be created, none of the log + * files size shall exceed 512 bytes. Rotate size is low to present how + * rotation works, in real life this should be much higher, unless you + * really know what you are doing and understand the consequences of low + * rotate size. + */ + + el_ooption(&g_el, EL_FROTATE_NUMBER, 5); + el_ooption(&g_el, EL_FROTATE_SIZE, 512); + + /* Tell embedlog to sync all buffers and metadata regarding log file. + * There are cases, when data (a lot of data) goes into block device, + * but metadata of the file are not updated when power loss occurs. This + * leads to data loss - even though they landed physically on block device + * like sdcard. To prevent losing too much data, you can define how often + * you want embedlog to call sync() functions. It basically translates to + * "how much data am I ready to loose?". In this example, we sync() once + * every 4096 bytes are stored into file. + */ + + el_ooption(&g_el, EL_FILE_SYNC_EVERY, 4096); + + /* Setting above value to too small value, will cause sync() to be called + * very often (depending on how much data you log) and that may criple + * performance greatly. And there are situations when you are willing to + * loose some info or debug data (up to configured sync every value), but + * when critical error shows up, you want data to be synced immediately to + * minimize chance of losing information about critical error. For that + * you can define which log level will be synced *every* time regardless + * of sync every value. Here we will instruct embedlog to log prints that + * have severity higher or equal to critical (so critial, alert and fatal) + */ el_ooption(&g_el, EL_FILE_SYNC_LEVEL, EL_CRIT); - /* Enable logging to file with file rotation based on file size. - * Maximum 5 files will be created, none of the log files size shall - * exceed 512 bytes. Rotate size is low to present how rotation works, in - * real life this should be much higher, unless you really know what you - * are doing and understand the consequences of low rotate size. - * This function will also automatically enable file output without - * disabling any - already enabled - outputs. + /* Print logs to both file and standard error */ + + el_ooption(&g_el, EL_OUT, EL_OUT_FILE | EL_OUT_STDERR); + + /* Register path to log file in embedlog. This will cause logger to look + * for next valid log file (when log rotate in enabled) and will try to + * open file for reading. */ - if (el_oenable_file_log(&g_el, log_path, 5, 512)) + if (el_ooption(&g_el, EL_FPATH, log_path) != 0) { if (errno == ENAMETOOLONG || errno == EINVAL) { @@ -262,29 +286,6 @@ static void el_print_file(const char *workdir) return; } - /* Tell embedlog to sync all buffers and metadata regarding log file. - * - * There are cases, when data (a lot of data) goes into block device, - * but metadata of the file are not updated when power loss occurs. This - * leads to data loss - even though they landed physically on block device - * like sdcard. To prevent losing too much data, you can define how often - * you want embedlog to call sync() functions. It basically translates to - * "how much data am I ready to loose?". In this example, we sync() once - * every 4096 bytes are stored into file. - * - * Setting that value to too small value, will cause sync() to be called - * very often (depending on how much data you log) and that may criple - * performance greatly. And there are situations when you are willing to - * loose some info or debug data (up to configured sync every value), but - * when critical error shows up, you want data to be synced immediately to - * minimize chance of losing information about critical error. For that - * you can define which log level will be synced *every* time regardless - * of 'sync every' value. Here we will instruct embedlog to log prints that - * have severity higher or equal to critical (so critial, alert and fatal) - */ - - el_oset_file_sync(&g_el, 4096, EL_CRIT); - /* Now we can print messages */ el_oprint(OELI, "Now we enabled log rotation"); @@ -316,21 +317,7 @@ int main(int argc, FAR char *argv[]) el_oinit(&g_el); el_oprint(OELI, "Right after init, embedlog will print to stderr with " - "just log level information - these are default settings."); - - el_oprint(OELI, "You can enable most common and usefull options with just " - "a few special functions"); - - el_oset_timestamp(&g_el, EL_TS_LONG, EL_TS_TM_REALTIME, EL_TS_FRACT_US); - el_oprint_extra_info(&g_el, 1); - - el_oprint(OELI, "timestamp and information about log place in code is " - "most usefull for developer"); - el_oprint(OELI, "If these are not enough, you can always really fine"); - el_oprint(OELI, "tune embedlog behaviour with options"); - - el_oset_timestamp(&g_el, EL_TS_OFF, EL_TS_TM_REALTIME, EL_TS_FRACT_OFF); - el_oprint_extra_info(&g_el, 0); + "just log level information - these are default settings."); el_print_options(); el_print_memory(); diff --git a/examples/esp32_himem/CMakeLists.txt b/examples/esp32_himem/CMakeLists.txt deleted file mode 100644 index 313e90674..000000000 --- a/examples/esp32_himem/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# ############################################################################## -# apps/examples/esp32_himem/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_ESP32_HIMEM) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_ESP32_HIMEM_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_ESP32_HIMEM_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_ESP32_HIMEM_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_ESP32_HIMEM} - SRCS - esp32_himem_main.c) -endif() diff --git a/examples/esp32_himem/Make.defs b/examples/esp32_himem/Make.defs index 2f6324c6b..8ad873552 100644 --- a/examples/esp32_himem/Make.defs +++ b/examples/esp32_himem/Make.defs @@ -1,7 +1,5 @@ ############################################################################ -# apps/examples/esp32_himem/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 +# apps/examples/esp32himem/Make.defs # # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with diff --git a/examples/esp32_himem/Makefile b/examples/esp32_himem/Makefile index aba61321d..4184a97fe 100644 --- a/examples/esp32_himem/Makefile +++ b/examples/esp32_himem/Makefile @@ -1,7 +1,5 @@ ############################################################################ -# apps/examples/esp32_himem/Makefile -# -# SPDX-License-Identifier: Apache-2.0 +# apps/examples/esp32himem/Makefile # # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with diff --git a/examples/esp32_himem/esp32_himem_main.c b/examples/esp32_himem/esp32_himem_main.c index bf7eda01c..2d5e49240 100644 --- a/examples/esp32_himem/esp32_himem_main.c +++ b/examples/esp32_himem/esp32_himem_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/esp32_himem/esp32_himem_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -25,13 +23,11 @@ ****************************************************************************/ #include <nuttx/config.h> - #include <stdio.h> #include <fcntl.h> #include <stdbool.h> #include <stdint.h> #include <assert.h> -#include <unistd.h> #include <nuttx/himem/himem.h> @@ -62,7 +58,7 @@ static bool check_mem(void *mem, int len, int phys_addr) if (val != *p) { printf("check_mem: %x has 0x%08x expected 0x%08x\n", - phys_addr + ((char *)p - (char *)mem), *p, val); + phys_addr + ((char *) p - (char *) mem), *p, val); return false; } p++; diff --git a/examples/etl/CMakeLists.txt b/examples/etl/CMakeLists.txt deleted file mode 100644 index 9c0a20106..000000000 --- a/examples/etl/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# ############################################################################## -# apps/examples/etl/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_ETL) - nuttx_add_application( - NAME - etl - STACKSIZE - ${CONFIG_DEFAULT_TASK_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_HELLOXX} - SRCS - etl_main.cxx) -endif() diff --git a/examples/etl/Kconfig b/examples/etl/Kconfig deleted file mode 100644 index b555273b6..000000000 --- a/examples/etl/Kconfig +++ /dev/null @@ -1,12 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config EXAMPLES_ETL - tristate "Embedded Template Library (ETL) C++ example" - default n - depends on HAVE_CXX && ETL - ---help--- - Enable the ETL C++ example which showcases the etl::vector container - and C++11 iterator diff --git a/examples/etl/Make.defs b/examples/etl/Make.defs deleted file mode 100644 index 54405b0ed..000000000 --- a/examples/etl/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/examples/etl/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_EXAMPLES_ETL),) -CONFIGURED_APPS += $(APPDIR)/examples/etl -endif diff --git a/examples/etl/Makefile b/examples/etl/Makefile deleted file mode 100644 index 89b4c57a8..000000000 --- a/examples/etl/Makefile +++ /dev/null @@ -1,36 +0,0 @@ -############################################################################ -# apps/examples/etl/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -# ETL C++ Example - -MAINSRC = etl_main.cxx - -# etl built-in application info - -PROGNAME = etl -PRIORITY = SCHED_PRIORITY_DEFAULT -STACKSIZE = $(CONFIG_DEFAULT_TASK_STACKSIZE) -MODULE = $(CONFIG_EXAMPLES_HELLOXX) - -include $(APPDIR)/Application.mk diff --git a/examples/etl/etl_main.cxx b/examples/etl/etl_main.cxx deleted file mode 100644 index f8628cdfc..000000000 --- a/examples/etl/etl_main.cxx +++ /dev/null @@ -1,146 +0,0 @@ -//*************************************************************************** -// apps/examples/etl/etl_main.cxx -// -// SPDX-License-Identifier: Apache-2.0 -// -// Licensed to the Apache Software Foundation (ASF) under one or more -// contributor license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright ownership. The -// ASF licenses this file to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance with the -// License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -// License for the specific language governing permissions and limitations -// under the License. -// -//*************************************************************************** - -//*************************************************************************** -// Included Files -//*************************************************************************** - -#include <nuttx/config.h> - -#include <cstdio> -#include <nuttx/debug.h> - -#include <etl/vector.h> -#include <etl/numeric.h> - -//*************************************************************************** -// Definitions -//*************************************************************************** -// Configuration ************************************************************ - -// Debug ******************************************************************** -// Non-standard debug that may be enabled just for testing the constructors - -#ifdef CONFIG_DEBUG_FEATURES -# define CONFIG_DEBUG_CXX -#endif - -#ifdef CONFIG_DEBUG_CXX -# define cxxinfo _info -#else -# define cxxinfo(x...) -#endif - -typedef etl::vector<int, 10> Data; - -//*************************************************************************** -// Private Classes -//*************************************************************************** - -class CETL -{ - public: - CETL(void) : mSecret(42) - { - cxxinfo("Constructor: mSecret=%d\n", mSecret); - } - - ~CETL(void) - { - cxxinfo("Destructor\n"); - } - - bool HelloWorld(void) - { - cxxinfo("HelloWorld: mSecret=%d\n", mSecret); - - // Declare the vector instances. - etl::vector<int, 10> v1(10); - etl::vector<int, 20> v2(20); - - etl::iota(v1.begin(), v1.end(), 0); // Fill with 0 through 9 - etl::iota(v2.begin(), v2.end(), 10); // Fill with 10 through 29 - - printf("v1 with 0 through 9\n"); - for (auto& it : v1) { - printf("%i ", it); - } - printf("\n"); - - printf("v2 with 10 through 29\n"); - for (auto& it : v2) { - printf("%i ", it); - } - printf("\n"); - - return true; - } - - private: - int mSecret; -}; - -//*************************************************************************** -// Private Data -//*************************************************************************** - -// Define a statically constructed CHellowWorld instance if C++ static -// initializers are supported by the platform - -#ifdef CONFIG_HAVE_CXXINITIALIZE -static CETL g_HelloWorld; -#endif - -//*************************************************************************** -// Public Functions -//*************************************************************************** - -/**************************************************************************** - * Name: etl_main - ****************************************************************************/ - - -extern "C" int main(int argc, FAR char *argv[]) -{ - // Exercise an explicitly instantiated C++ object - - CETL *pHelloWorld = new CETL; - printf("etl_main: Testing ETL from the dynamically constructed instance\n"); - pHelloWorld->HelloWorld(); - - // Exercise an C++ object instantiated on the stack - - CETL HelloWorld; - - printf("etl_main: Testing ETL from the instance constructed on the stack\n"); - HelloWorld.HelloWorld(); - - // Exercise an statically constructed C++ object - -#ifdef CONFIG_HAVE_CXXINITIALIZE - printf("etl_main: Testing ETL from the statically constructed instance\n"); - g_HelloWorld.HelloWorld(); -#endif - - delete pHelloWorld; - return 0; -} diff --git a/examples/fb/CMakeLists.txt b/examples/fb/CMakeLists.txt deleted file mode 100644 index 87736c960..000000000 --- a/examples/fb/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# ############################################################################## -# apps/examples/fb/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_FB) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_FB_PROGNAME} - SRCS - fb_main.c - STACKSIZE - ${CONFIG_EXAMPLES_FB_STACKSIZE} - PRIORITY - ${CONFIG_EXAMPLES_FB_PRIORITY}) -endif() diff --git a/examples/fb/Make.defs b/examples/fb/Make.defs index a8ddc29d3..319ba7ea1 100644 --- a/examples/fb/Make.defs +++ b/examples/fb/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/fb/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/fb/Makefile b/examples/fb/Makefile index fcf0f41ab..1ccc6944a 100644 --- a/examples/fb/Makefile +++ b/examples/fb/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/fb/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/fb/fb_main.c b/examples/fb/fb_main.c index 3d237df05..5852dea9b 100644 --- a/examples/fb/fb_main.c +++ b/examples/fb/fb_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/fb/fb_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -30,11 +28,9 @@ #include <sys/mman.h> #include <unistd.h> #include <stdlib.h> -#include <string.h> #include <stdio.h> #include <fcntl.h> #include <errno.h> -#include <poll.h> #include <nuttx/video/fb.h> #include <nuttx/video/rgbcolors.h> @@ -43,11 +39,7 @@ * Preprocessor Definitions ****************************************************************************/ -#define NRECTCOLORS 6 -#define NSMPTECOLORS 7 - -#define PATTERN_RECTANGLES 0 -#define PATTERN_SMPTE 1 +#define NCOLORS 6 /**************************************************************************** * Private Types @@ -62,9 +54,6 @@ struct fb_state_s struct fb_overlayinfo_s oinfo; #endif FAR void *fbmem; - FAR void *fbmem2; - FAR void *act_fbmem; - uint32_t mem2_yoffset; }; /**************************************************************************** @@ -75,269 +64,47 @@ static const char g_default_fbdev[] = CONFIG_EXAMPLES_FB_DEFAULTFB; /* Violet-Blue-Green-Yellow-Orange-Red */ -static const uint32_t g_rgb24[NRECTCOLORS] = +static const uint32_t g_rgb24[NCOLORS] = { RGB24_VIOLET, RGB24_BLUE, RGB24_GREEN, RGB24_YELLOW, RGB24_ORANGE, RGB24_RED }; -static const uint16_t g_rgb16[NRECTCOLORS] = +static const uint16_t g_rgb16[NCOLORS] = { RGB16_VIOLET, RGB16_BLUE, RGB16_GREEN, RGB16_YELLOW, RGB16_ORANGE, RGB16_RED }; -static const uint8_t g_rgb8[NRECTCOLORS] = +static const uint8_t g_rgb8[NCOLORS] = { RGB8_VIOLET, RGB8_BLUE, RGB8_GREEN, RGB8_YELLOW, RGB8_ORANGE, RGB8_RED }; -/* White-Yellow-Cyan-Green-Magenta-Red-Blue */ - -static const uint32_t g_smpte_rgb24[NSMPTECOLORS] = -{ - RGB24_WHITE, RGB24_YELLOW, RGB24_CYAN, RGB24_GREEN, - RGB24_MAGENTA, RGB24_RED, RGB24_BLUE -}; - -static const uint16_t g_smpte_rgb16[NSMPTECOLORS] = -{ - RGB16_WHITE, RGB16_YELLOW, RGB16_CYAN, RGB16_GREEN, - RGB16_MAGENTA, RGB16_RED, RGB16_BLUE -}; - -static const uint8_t g_smpte_rgb8[NSMPTECOLORS] = -{ - RGB8_WHITE, RGB8_YELLOW, RGB8_CYAN, RGB8_GREEN, - RGB8_MAGENTA, RGB8_RED, RGB8_BLUE -}; - -/* Monochrome equivalents selected using BT.601 luma. */ - -static const uint8_t g_smpte_mono[NSMPTECOLORS] = -{ - 1, 1, 1, 1, 0, 0, 0 -}; - /**************************************************************************** * Private Functions ****************************************************************************/ -/**************************************************************************** - * sync_area - ****************************************************************************/ - -static void sync_area(FAR struct fb_state_s *state) -{ - if (state->fbmem2 == NULL) - { - return; - } - - if (state->act_fbmem == state->fbmem) - { - memcpy(state->fbmem, state->fbmem2, - state->vinfo.yres * state->pinfo.stride); - } - else - { - memcpy(state->fbmem2, state->fbmem, - state->vinfo.yres * state->pinfo.stride); - } -} - -/**************************************************************************** - * pan_display - ****************************************************************************/ - -static void pan_display(FAR struct fb_state_s *state) -{ - struct pollfd pfd; - int ret; - pfd.fd = state->fd; - pfd.events = POLLOUT; - - ret = poll(&pfd, 1, 0); - - if (ret > 0) - { - if (state->fbmem2 == NULL) - { - return; - } - - if (state->act_fbmem == state->fbmem) - { - state->pinfo.yoffset = 0; - } - else - { - state->pinfo.yoffset = state->mem2_yoffset; - } - - ioctl(state->fd, FBIOPAN_DISPLAY, - (unsigned long)(uintptr_t)&state->pinfo); - - state->act_fbmem = state->act_fbmem == state->fbmem ? - state->fbmem2 : state->fbmem; - } -} - -/**************************************************************************** - * fbdev_get_pinfo - ****************************************************************************/ - -static int fbdev_get_pinfo(int fd, FAR struct fb_planeinfo_s *pinfo) -{ - if (ioctl(fd, FBIOGET_PLANEINFO, (unsigned long)((uintptr_t)pinfo)) < 0) - { - int errcode = errno; - fprintf(stderr, "ERROR: ioctl(FBIOGET_PLANEINFO) failed: %d\n", - errcode); - return EXIT_FAILURE; - } - - printf("PlaneInfo (plane %d):\n", pinfo->display); - printf(" fbmem: %p\n", pinfo->fbmem); - printf(" fblen: %zu\n", pinfo->fblen); - printf(" stride: %u\n", pinfo->stride); - printf(" display: %u\n", pinfo->display); - printf(" bpp: %u\n", pinfo->bpp); - - /* Only these pixel depths are supported. viinfo.fmt is ignored, only - * certain color formats are supported. - */ - - if (pinfo->bpp != 32 && pinfo->bpp != 24 && - pinfo->bpp != 16 && pinfo->bpp != 8 && - pinfo->bpp != 1) - { - fprintf(stderr, "ERROR: bpp=%u not supported\n", pinfo->bpp); - return EXIT_FAILURE; - } - - return 0; -} - -/**************************************************************************** - * fb_init_mem2 - ****************************************************************************/ - -static int fb_init_mem2(FAR struct fb_state_s *state) -{ - int ret; - uintptr_t buf_offset; - struct fb_planeinfo_s pinfo; - FAR void *fbmem; - - memset(&pinfo, 0, sizeof(pinfo)); - pinfo.display = state->pinfo.display + 1; - - if ((ret = fbdev_get_pinfo(state->fd, &pinfo)) < 0) - { - return EXIT_FAILURE; - } - - fbmem = mmap(NULL, pinfo.fblen, PROT_READ | PROT_WRITE, - MAP_SHARED | MAP_FILE, state->fd, 0); - - if (fbmem == MAP_FAILED) - { - int errcode = errno; - fprintf(stderr, "ERROR: ioctl(FBIOGET_PLANEINFO) failed: %d\n", - errcode); - return EXIT_FAILURE; - } - - /* Check bpp */ - - if (pinfo.bpp != state->pinfo.bpp) - { - fprintf(stderr, "ERROR: fbmem2 is incorrect\n"); - return -EINVAL; - } - - /* Check the buffer address offset, - * It needs to be divisible by pinfo.stride - */ - - buf_offset = fbmem - state->fbmem; - - if ((buf_offset % state->pinfo.stride) != 0) - { - fprintf(stderr, "ERROR: It is detected that buf_offset(%" PRIuPTR ") " - "and stride(%d) are not divisible, please ensure " - "that the driver handles the address offset by itself.\n", - buf_offset, state->pinfo.stride); - } - - /* Calculate the address and yoffset of fbmem2 */ - - if (buf_offset == 0) - { - /* Use consecutive fbmem2. */ - - state->mem2_yoffset = state->vinfo.yres; - state->fbmem2 = fbmem + state->mem2_yoffset * pinfo.stride; - printf("Use consecutive fbmem2 = %p, yoffset = %" PRIu32"\n", - state->fbmem2, state->mem2_yoffset); - } - else - { - /* Use non-consecutive fbmem2. */ - - state->mem2_yoffset = buf_offset / state->pinfo.stride; - state->fbmem2 = fbmem; - printf("Use non-consecutive fbmem2 = %p, yoffset = %" PRIu32"\n", - state->fbmem2, state->mem2_yoffset); - } - - return 0; -} - /**************************************************************************** * draw_rect ****************************************************************************/ static void draw_rect32(FAR struct fb_state_s *state, - FAR struct fb_area_s *area, uint32_t color) + FAR struct fb_area_s *area, int color) { FAR uint32_t *dest; FAR uint8_t *row; int x; int y; - row = (FAR uint8_t *)state->act_fbmem + state->pinfo.stride * area->y; + row = (FAR uint8_t *)state->fbmem + state->pinfo.stride * area->y; for (y = 0; y < area->h; y++) { dest = ((FAR uint32_t *)row) + area->x; for (x = 0; x < area->w; x++) { - *dest++ = color | 0xff000000; - } - - row += state->pinfo.stride; - } -} - -static void draw_rect24(FAR struct fb_state_s *state, - FAR struct fb_area_s *area, uint32_t color) -{ - FAR uint8_t *dest; - FAR uint8_t *row; - int x; - int y; - - row = (FAR uint8_t *)state->act_fbmem + state->pinfo.stride * area->y; - for (y = 0; y < area->h; y++) - { - dest = ((FAR uint8_t *)row) + area->x * 3; - for (x = 0; x < area->w; x++) - { - *dest++ = color & 0xff; - *dest++ = (color >> 8) & 0xff; - *dest++ = (color >> 16) & 0xff; + *dest++ = g_rgb24[color]; } row += state->pinfo.stride; @@ -345,20 +112,20 @@ static void draw_rect24(FAR struct fb_state_s *state, } static void draw_rect16(FAR struct fb_state_s *state, - FAR struct fb_area_s *area, uint16_t color) + FAR struct fb_area_s *area, int color) { FAR uint16_t *dest; FAR uint8_t *row; int x; int y; - row = (FAR uint8_t *)state->act_fbmem + state->pinfo.stride * area->y; + row = (FAR uint8_t *)state->fbmem + state->pinfo.stride * area->y; for (y = 0; y < area->h; y++) { dest = ((FAR uint16_t *)row) + area->x; for (x = 0; x < area->w; x++) { - *dest++ = color; + *dest++ = g_rgb16[color]; } row += state->pinfo.stride; @@ -366,20 +133,20 @@ static void draw_rect16(FAR struct fb_state_s *state, } static void draw_rect8(FAR struct fb_state_s *state, - FAR struct fb_area_s *area, uint8_t color) + FAR struct fb_area_s *area, int color) { FAR uint8_t *dest; FAR uint8_t *row; int x; int y; - row = (FAR uint8_t *)state->act_fbmem + state->pinfo.stride * area->y; + row = (FAR uint8_t *)state->fbmem + state->pinfo.stride * area->y; for (y = 0; y < area->h; y++) { dest = row + area->x; for (x = 0; x < area->w; x++) { - *dest++ = color; + *dest++ = g_rgb8[color]; } row += state->pinfo.stride; @@ -387,80 +154,71 @@ static void draw_rect8(FAR struct fb_state_s *state, } static void draw_rect1(FAR struct fb_state_s *state, - FAR struct fb_area_s *area, uint8_t color) + FAR struct fb_area_s *area, int color) { FAR uint8_t *pixel; FAR uint8_t *row; - uint8_t color8 = color == 0 ? 0 : 0xff; - - int start_full_x; - int end_full_x; - int start_bit_shift; - int last_bits; + uint8_t color8 = (color & 1) == 0 ? 0 : 0xff; uint8_t lmask; uint8_t rmask; + int startx; + int endx; + int x; int y; /* Calculate the framebuffer address of the first row to draw on */ - row = (FAR uint8_t *)state->act_fbmem + state->pinfo.stride * area->y; + row = (FAR uint8_t *)state->fbmem + state->pinfo.stride * area->y; - /* Calculate the position of the first complete (with all bits) byte. - * Then calculate the last byte with all the bits. + /* Calculate the start byte position rounding down so that we get the + * first byte containing any part of the pixel sequence. Then calculate + * the last byte position with a ceil() operation so it includes any final + * final pixels of the sequence. */ - start_full_x = ((area->x + 7) >> 3); - end_full_x = ((area->x + area->w) >> 3); - - /* Calculate the number of bits in byte before start that need to remain - * unchanged. Later calculate the mask. - */ - - start_bit_shift = 8 + area->x - (start_full_x << 3); - lmask = 0xff >> start_bit_shift; - - /* Calculate the number of bits that needs to be changed after last byte - * with all the bits. Later calculate the mask. - */ - - last_bits = area->x + area->w - (end_full_x << 3); - rmask = 0xff << (8 - last_bits); + startx = (area->x >> 3); + endx = ((area->x + area->w + 6) >> 3); /* Calculate a mask on the first and last bytes of the sequence that may * not be completely filled with pixel. */ + lmask = 0xff << (8 - (area->x & 7)); + rmask = 0xff >> ((area->x + area->w - 1) & 7); + /* Now draw each row, one-at-a-time */ for (y = 0; y < area->h; y++) { /* 'pixel' points to the 1st pixel the next row */ - /* Special case: The row starts and ends within the same byte */ + pixel = row + startx; - if (start_full_x > end_full_x) + /* Special case: The row is less no more than one byte wide */ + + if (startx == endx) { - pixel = row + start_full_x - 1; - *pixel = (*pixel & (~lmask | ~rmask)) | (lmask & rmask & color8); - continue; + uint8_t mask = lmask | rmask; + + *pixel = (*pixel & mask) | (color8 & ~mask); } - - if (start_bit_shift != 0) + else { - pixel = row + start_full_x - 1; - *pixel = (*pixel & ~lmask) | (lmask & color8); - } + /* Special case the first byte of the row */ - if (end_full_x > start_full_x) - { - pixel = row + start_full_x; - memset(pixel, color8, end_full_x - start_full_x); - } + *pixel = (*pixel & lmask) | (color8 & ~lmask); + pixel++; - if (last_bits != 0) - { - pixel = row + end_full_x; - *pixel = (*pixel & ~rmask) | (rmask & color8); + /* Handle all middle bytes in the row */ + + for (x = startx + 1; x < endx; x++) + { + *pixel++ = color8; + } + + /* Handle the final byte of the row */ + + *pixel = (*pixel & rmask) | (color8 & ~rmask); } row += state->pinfo.stride; @@ -468,47 +226,35 @@ static void draw_rect1(FAR struct fb_state_s *state, } static void draw_rect(FAR struct fb_state_s *state, - FAR struct fb_area_s *area, uint32_t color24, - uint16_t color16, uint8_t color8, uint8_t mono) + FAR struct fb_area_s *area, int color) { +#ifdef CONFIG_FB_UPDATE + int ret; +#endif + switch (state->pinfo.bpp) { case 32: - draw_rect32(state, area, color24); - break; - - case 24: - draw_rect24(state, area, color24); + draw_rect32(state, area, color); break; case 16: - draw_rect16(state, area, color16); + draw_rect16(state, area, color); break; case 8: default: - draw_rect8(state, area, color8); + draw_rect8(state, area, color); break; case 1: - draw_rect1(state, area, mono); + draw_rect1(state, area, color); break; } -} -static void present_area(FAR struct fb_state_s *state, - FAR const struct fb_area_s *area) -{ #ifdef CONFIG_FB_UPDATE - struct fb_area_s update = *area; - int ret; - - int yoffset = state->act_fbmem == state->fbmem ? - 0 : state->mem2_yoffset; - update.y += yoffset; - ret = ioctl(state->fd, FBIO_UPDATE, - (unsigned long)((uintptr_t)&update)); + (unsigned long)((uintptr_t)area)); if (ret < 0) { int errcode = errno; @@ -516,11 +262,6 @@ static void present_area(FAR struct fb_state_s *state, errcode); } #endif - - if (state->pinfo.yres_virtual == (state->vinfo.yres * 2)) - { - pan_display(state); - } } /**************************************************************************** @@ -534,7 +275,6 @@ static void present_area(FAR struct fb_state_s *state, int main(int argc, FAR char *argv[]) { FAR const char *fbdev = g_default_fbdev; - int pattern = PATTERN_RECTANGLES; struct fb_state_s state; struct fb_area_s area; int nsteps; @@ -546,43 +286,20 @@ int main(int argc, FAR char *argv[]) int x; int y; int ret; - int opt; - while ((opt = getopt(argc, argv, "p:")) != ERROR) + /* There is a single required argument: The path to the framebuffer + * driver. + */ + + if (argc == 2) { - switch (opt) - { - case 'p': - if (strcmp(optarg, "rectangles") == 0) - { - pattern = PATTERN_RECTANGLES; - } - else if (strcmp(optarg, "smpte") == 0) - { - pattern = PATTERN_SMPTE; - } - else - { - fprintf(stderr, "ERROR: Unknown pattern: %s\n", optarg); - goto usage; - } - - break; - - default: - goto usage; - } + fbdev = argv[1]; } - - if (optind < argc) + else if (argc != 1) { - fbdev = argv[optind++]; - } - - if (optind < argc) - { - fprintf(stderr, "ERROR: Too many framebuffer paths\n"); - goto usage; + fprintf(stderr, "ERROR: Single argument required\n"); + fprintf(stderr, "USAGE: %s [<fb-driver-path>]\n", argv[0]); + return EXIT_FAILURE; } /* Open the framebuffer driver */ @@ -645,7 +362,7 @@ int main(int argc, FAR char *argv[]) printf("OverlayInfo (overlay 0):\n"); printf(" fbmem: %p\n", state.oinfo.fbmem); - printf(" fblen: %zu\n", state.oinfo.fblen); + printf(" fblen: %lu\n", (unsigned long)state.oinfo.fblen); printf(" stride: %u\n", state.oinfo.stride); printf(" overlay: %u\n", state.oinfo.overlay); printf(" bpp: %u\n", state.oinfo.bpp); @@ -659,22 +376,34 @@ int main(int argc, FAR char *argv[]) state.oinfo.sarea.w, state.oinfo.sarea.h); printf(" accl: %" PRIu32 "\n", state.oinfo.accl); - /* select default framebuffer layer */ +#endif - ret = ioctl(state.fd, FBIO_SELECT_OVERLAY, FB_NO_OVERLAY); + ret = ioctl(state.fd, FBIOGET_PLANEINFO, + (unsigned long)((uintptr_t)&state.pinfo)); if (ret < 0) { int errcode = errno; - fprintf(stderr, "ERROR: ioctl(FBIO_SELECT_OVERLAY) failed: %d\n", + fprintf(stderr, "ERROR: ioctl(FBIOGET_PLANEINFO) failed: %d\n", errcode); close(state.fd); return EXIT_FAILURE; } -#endif + printf("PlaneInfo (plane 0):\n"); + printf(" fbmem: %p\n", state.pinfo.fbmem); + printf(" fblen: %lu\n", (unsigned long)state.pinfo.fblen); + printf(" stride: %u\n", state.pinfo.stride); + printf(" display: %u\n", state.pinfo.display); + printf(" bpp: %u\n", state.pinfo.bpp); - if ((ret = fbdev_get_pinfo(state.fd, &state.pinfo)) < 0) + /* Only these pixel depths are supported. viinfo.fmt is ignored, only + * certain color formats are supported. + */ + + if (state.pinfo.bpp != 32 && state.pinfo.bpp != 16 && + state.pinfo.bpp != 8 && state.pinfo.bpp != 1) { + fprintf(stderr, "ERROR: bpp=%u not supported\n", state.pinfo.bpp); close(state.fd); return EXIT_FAILURE; } @@ -693,7 +422,7 @@ int main(int argc, FAR char *argv[]) if (state.fbmem == MAP_FAILED) { int errcode = errno; - fprintf(stderr, "ERROR: mmap() failed: %d\n", + fprintf(stderr, "ERROR: ioctl(FBIOGET_PLANEINFO) failed: %d\n", errcode); close(state.fd); return EXIT_FAILURE; @@ -701,87 +430,35 @@ int main(int argc, FAR char *argv[]) printf("Mapped FB: %p\n", state.fbmem); - /* double buffer mode */ + /* Draw some rectangles */ - if (state.pinfo.yres_virtual == (state.vinfo.yres * 2)) + nsteps = 2 * (NCOLORS - 1) + 1; + xstep = state.vinfo.xres / nsteps; + ystep = state.vinfo.yres / nsteps; + width = state.vinfo.xres; + height = state.vinfo.yres; + + for (x = 0, y = 0, color = 0; + color < NCOLORS; + x += xstep, y += ystep, color++) { - if ((ret = fb_init_mem2(&state)) < 0) - { - goto out; - } - } + area.x = x; + area.y = y; + area.w = width; + area.h = height; - /* Draw the selected pattern */ + printf("%2d: (%3d,%3d) (%3d,%3d)\n", + color, area.x, area.y, area.w, area.h); - state.act_fbmem = state.fbmem; - if (pattern == PATTERN_SMPTE) - { - for (color = 0; color < NSMPTECOLORS; color++) - { - area.x = color * state.vinfo.xres / NSMPTECOLORS; - area.y = 0; - area.w = (color + 1) * state.vinfo.xres / NSMPTECOLORS - - area.x; - area.h = state.vinfo.yres; + draw_rect(&state, &area, color); + usleep(500 * 1000); - draw_rect(&state, &area, g_smpte_rgb24[color], - g_smpte_rgb16[color], g_smpte_rgb8[color], - g_smpte_mono[color]); - } - - area.x = 0; - area.y = 0; - area.w = state.vinfo.xres; - area.h = state.vinfo.yres; - present_area(&state, &area); - } - else - { - nsteps = 2 * (NRECTCOLORS - 1) + 1; - xstep = state.vinfo.xres / nsteps; - ystep = state.vinfo.yres / nsteps; - width = state.vinfo.xres; - height = state.vinfo.yres; - - for (x = 0, y = 0, color = 0; - color < NRECTCOLORS; - x += xstep, y += ystep, color++) - { - area.x = x; - area.y = y; - area.w = width; - area.h = height; - - printf("%2d: (%3d,%3d) (%3d,%3d)\n", - color, area.x, area.y, area.w, area.h); - - draw_rect(&state, &area, g_rgb24[color], - g_rgb16[color], g_rgb8[color], color & 1); - present_area(&state, &area); - usleep(500 * 1000); - - width -= (2 * xstep); - height -= (2 * ystep); - - /* double buffer mode */ - - if (state.pinfo.yres_virtual == (state.vinfo.yres * 2)) - { - sync_area(&state); - } - } + width -= (2 * xstep); + height -= (2 * ystep); } printf("Test finished\n"); - ret = EXIT_SUCCESS; -out: munmap(state.fbmem, state.pinfo.fblen); close(state.fd); - return ret; - -usage: - fprintf(stderr, - "USAGE: %s [-p rectangles|smpte] [<fb-driver-path>]\n", - argv[0]); - return EXIT_FAILURE; + return EXIT_SUCCESS; } diff --git a/examples/fbcon/CMakeLists.txt b/examples/fbcon/CMakeLists.txt deleted file mode 100644 index 0af45b1b9..000000000 --- a/examples/fbcon/CMakeLists.txt +++ /dev/null @@ -1,34 +0,0 @@ -# ############################################################################## -# apps/examples/fbcon/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_FBCON) - nuttx_add_application( - NAME - fbcon - STACKSIZE - ${CONFIG_EXAMPLES_FBCON_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_FBCON} - SRCS - fbcon_main.c) - target_sources(apps PRIVATE fbcon_main.c) -endif() diff --git a/examples/fbcon/Kconfig b/examples/fbcon/Kconfig deleted file mode 100644 index 0c0aac033..000000000 --- a/examples/fbcon/Kconfig +++ /dev/null @@ -1,206 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config EXAMPLES_FBCON - tristate "Framebuffer console example" - default n - ---help--- - Enable the Framebuffer console example. - This example allows STDOUT and/or STDERR to be redirected and displayed - on a framebuffer character device. - - A chosen builtin app can be spawned - such as "nsh" - to create a - console and, if required, STDIN can be intercepted to allow input - characters to be interpreted and pre-processed before passing them - on to the spawned app. - - Relies on and uses NX and NXFONTS - -if EXAMPLES_FBCON - -comment "Console STDIN and/or STDOUT setup" - -config EXAMPLES_FBCON_PIPE_STDOUT - bool "Pipe stdout to this console" - default y - -config EXAMPLES_FBCON_PIPE_STDERR - bool "Pipe stderr to this console" - default y - -config EXAMPLES_FBCON_PIPE_STDIN - bool "Pipe stdin via this console" - default y - ---help--- - This is usually needed if the spawned App is "nsh" as we need to - intercept input characters in some cases - -comment "Console Framebuffer setup" - -config EXAMPLES_FBCON_DEF_FB - string "Default framebuffer driver" - default "/dev/fb0" - ---help--- - Default framebuffer drivers. This selection can be overridden from - the command line. - -comment "BPP setup" - -choice EXAMPLES_FBCON_BPP_SELECTION - prompt "BPP Configuration" - default EXAMPLES_FBCON_BPP_NX_DEFAULT - -config EXAMPLES_FBCON_BPP_NX_DEFAULT - bool "Use smallest BPP as enabled via NXFONTS setup" - -config EXAMPLES_FBCON_CUSTOM_BPP - bool "Choose custom BPP (must not be disabled in NX)" - -endchoice # EXAMPLES_FBCON_BPP_SELECTION - -choice EXAMPLES_FBCON_CUSTOM_BPP - prompt "Custom Font pixel depth (BPP - Bits Per Pixel)" - depends on EXAMPLES_FBCON_CUSTOM_BPP - ---help--- - Note: The required BPP must not be disabled via the NXFONT setup - -config EXAMPLES_FBCON_1BPP - bool "1 BPP" - depends on !NX_DISABLE_1BPP - -config EXAMPLES_FBCON_2BPP - bool "2 BPP" - depends on !NX_DISABLE_2BPP - -config EXAMPLES_FBCON_4BPP - bool "4 BPP" - depends on !NX_DISABLE_4BPP - -config EXAMPLES_FBCON_8BPP - bool "8 BPP" - depends on !NX_DISABLE_8BPP - -config EXAMPLES_FBCON_16BPP - bool "16 BPP" - depends on !NX_DISABLE_16BPP - -config EXAMPLES_FBCON_24BPP - bool "24 BPP" - depends on !NX_DISABLE_24BPP - -config EXAMPLES_FBCON_32BPP - bool "32 BPP" - depends on !NX_DISABLE_32BPP - -endchoice # EXAMPLES_FBCON_CUSTOM_BPP - -comment "Console appearance" - -config EXAMPLES_FBCON_SHOW_WELCOME - bool "Display welcome messages on stdout and/or stdin" - default y - -config EXAMPLES_FBCON_DEFAULT_COLORS - bool "Use Default Colors (white characters on black background)" - default y - -if !EXAMPLES_FBCON_DEFAULT_COLORS - -config EXAMPLES_FBCON_BGCOLOR - hex "Background color" - default 0x0 - ---help--- - The color of the background. Default depends on config - EXAMPLES_FBCON_BPP. - -config EXAMPLES_FBCON_FCOLOR - hex "Console font color" - default 0x0 - ---help--- - The color of the fonts used by the console. -endif # !EXAMPLES_FBCON_DEFAULT_COLORS - -config EXAMPLES_FBCON_LINESPACING - int "Line spacing" - default 0 - range 0 4 - ---help--- - The vertical distance between lines is the sum of (1) the vertical - bounding box dimension of the font, and (2) this additional line - space. This value may be zero, but not negative. - -config EXAMPLES_FBCON_NOWRAP - bool "No wrap" - default n - ---help--- - By default, lines will wrap when the test reaches the right hand side - of the window. This setting can be defining to change this behavior so - that the text is simply truncated until a new line is encountered. - -choice EXAMPLES_FBCON_FONT - prompt "Font Configuration" - default EXAMPLES_FBCON_DEFAULT_FONT - -config EXAMPLES_FBCON_DEFAULT_FONT - bool "Use Default Font" - -config EXAMPLES_FBCON_CUSTOM_FONTID - bool "Use Custom Font ID" - -config EXAMPLES_FBCON_FONTID - int "Custom font ID" - depends on EXAMPLES_FBCON_CUSTOM_FONTID - default 0 - ---help--- - Selects the font used by the console (see font ID numbers - in include/nuttx/nx/nxfonts.h) - -endchoice # EXAMPLES_FBCON_FONT - -config EXAMPLES_FBCON_CURSORCHAR - int "Character code to use as the cursor" - default 95 - ---help--- - The bitmap code to use as the cursor. Default '_' (95) - -comment "FB Console App Escape code decoding" - -config EXAMPLES_FBCON_VT100_DECODE - bool "Decode VT100 Escape Codes" - default y - ---help--- - Decode VT100 ESC codes - only minimal supporting functions - -comment "FB Console spawn task configuration" - -config EXAMPLES_FBCON_SPAWN_TASK - string "Built-in application, or task, to spawn after console setup" - default "nsh" - ---help--- - The required App must be enabled via Kconfig, of course. Its - priority and stack size will be determined by this example and passed - on during the spawn of the chosen app. - -comment "FB Console App stack and priority options and glyph cache size" - -config EXAMPLES_FBCON_STACKSIZE - int "Stack Size" - default DEFAULT_TASK_STACKSIZE - ---help--- - The stacksize to use when starting the example. - -config EXAMPLES_FBCON_PRIORITY - int "Task Priority" - default 100 - ---help--- - The priority of the example. - -config EXAMPLES_FBCON_GLCACHE - int "Glyph cache size" - default 94 - ---help--- - Size of the glyph cache. Default allows all usual ASCII characters to be cached - -endif # EXAMPLES_FBCON diff --git a/examples/fbcon/Make.defs b/examples/fbcon/Make.defs deleted file mode 100644 index 21336dda1..000000000 --- a/examples/fbcon/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/examples/fbcon/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_EXAMPLES_FBCON),) -CONFIGURED_APPS += $(APPDIR)/examples/fbcon -endif diff --git a/examples/fbcon/Makefile b/examples/fbcon/Makefile deleted file mode 100644 index f5795ce17..000000000 --- a/examples/fbcon/Makefile +++ /dev/null @@ -1,36 +0,0 @@ -############################################################################ -# apps/examples/fbcon/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -# NuttX NX Framebuffer Console Example. - -MAINSRC = fbcon_main.c - -# NXTEXT built-in application info - -PROGNAME = fbcon -PRIORITY = $(CONFIG_EXAMPLES_FBCON_PRIORITY) -STACKSIZE = $(CONFIG_EXAMPLES_FBCON_STACKSIZE) -MODULE = $(CONFIG_EXAMPLES_FBCON) - -include $(APPDIR)/Application.mk diff --git a/examples/fbcon/fbcon_main.c b/examples/fbcon/fbcon_main.c deleted file mode 100644 index da0833800..000000000 --- a/examples/fbcon/fbcon_main.c +++ /dev/null @@ -1,2654 +0,0 @@ -/**************************************************************************** - * apps/examples/fbcon/fbcon_main.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> -#include <stdlib.h> -#include <string.h> -#include <sys/types.h> -#include <sys/boardctl.h> -#include <sys/ioctl.h> -#include <sys/mman.h> -#include <stdint.h> -#include <stdbool.h> -#include <stdio.h> -#include <errno.h> -#include <assert.h> -#include <fcntl.h> -#include <nuttx/video/fb.h> -#include <nuttx/nx/nxfonts.h> -#include <nuttx/video/fb.h> -#include <ctype.h> -#include <spawn.h> -#include <nuttx/debug.h> -#include <poll.h> -#include <nuttx/ascii.h> -#include <nuttx/lib/builtin.h> - -#ifndef CONFIG_NX -# error This application requires NX Graphics -#endif - -/* NSH Redirection requires Pipes */ - -#ifndef CONFIG_DEV_PIPE_SIZE -# error FIFO and Named Pipe Drivers should be enabled in the configuration -#endif - -#ifdef CONFIG_NSH_CLE -# warning FBCON console does not support much VT100/EMACS/CLE type functionality yet -#endif - -#if !defined(CONFIG_EXAMPLES_FBCON_PIPE_STDOUT) && \ - !defined(CONFIG_EXAMPLES_FBCON_PIPE_STDOUT) -# warning FBCON is not configured for either stdout or stderr! -#endif - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* stdout and stderr configuration */ - -#define READ_PIPE 0 -#define WRITE_PIPE 1 -#define POLL_BUFSIZE 64 -#define VT100_MAX_SEQUENCE 6 /* Max length of VT100 sequence to check */ - -/* VT100 codes that can be decoded */ - -#define VT100_CLEAREOL {ASCII_ESC, '[', 'K'} /* Clear line from cursor right */ -#define VT100_CLEARLINE {ASCII_ESC, '[', '2', 'K'} /* Clear entire line */ -#define VT100_CURSOROFF {ASCII_ESC, '[', '?', '2', '5', 'l'} /* Cursor OFF */ -#define VT100_CURSORON {ASCII_ESC, '[', '?', '2', '5', 'h'} /* Cursor ON */ -#define VT100_CURSORL {ASCII_ESC, '[', '*', 'D'} /* Move cursor left (* = [1...99]) columns */ - -/* Configuration ************************************************************/ - -/* Pixel depth. If none provided, pick the smallest enabled pixel depth */ - -#ifdef CONFIG_EXAMPLES_FBCON_BPP_NX_DEFAULT -# if !defined(CONFIG_NX_DISABLE_1BPP) -# define FBCON_BPP 1 -# elif !defined(CONFIG_NX_DISABLE_2BPP) -# define FBCON_BPP 2 -# elif !defined(CONFIG_NX_DISABLE_4BPP) -# define FBCON_BPP 4 -# elif !defined(CONFIG_NX_DISABLE_8BPP) -# define FBCON_BPP 8 -# elif !defined(CONFIG_NX_DISABLE_16BPP) -# define FBCON_BPP 16 -# elif !defined(CONFIG_NX_DISABLE_24BPP) -# define FBCON_BPP 24 -# elif !defined(CONFIG_NX_DISABLE_32BPP) -# define FBCON_BPP 32 -# else -# error "No pixel depth enabled" -# endif -#elif defined(CONFIG_EXAMPLES_FBCON_1BPP) -# define FBCON_BPP 1 -#elif defined(CONFIG_EXAMPLES_FBCON_2BPP) -# define FBCON_BPP 2 -#elif defined(CONFIG_EXAMPLES_FBCON_4BPP) -# define FBCON_BPP 4 -#elif defined(CONFIG_EXAMPLES_FBCON_8BPP) -# define FBCON_BPP 8 -#elif defined(CONFIG_EXAMPLES_FBCON_16BPP) -# define FBCON_BPP 16 -#elif defined(CONFIG_EXAMPLES_FBCON_24BPP) -# define FBCON_BPP 24 -#elif defined(CONFIG_EXAMPLES_FBCON_32BPP) -# define FBCON_BPP 32 -#endif - -/* Select renderer */ - -#if (FBCON_BPP == 1) -# define RENDERER nxf_convert_1bpp -#elif (FBCON_BPP == 2) -# define RENDERER nxf_convert_2bpp -#elif (FBCON_BPP == 4) -# define RENDERER nxf_convert_4bpp -#elif (FBCON_BPP == 8) -# define RENDERER nxf_convert_8bpp -#elif (FBCON_BPP == 16) -# define RENDERER nxf_convert_16bpp -#elif (FBCON_BPP == 24) -# define RENDERER nxf_convert_24bpp -#elif (FBCON_BPP == 32) -# define RENDERER nxf_convert_32bpp -#else -# error "Unsupported CONFIG_EXAMPLES_FBCON_BPP" -#endif - -/* Background and font color, if defaults chosen */ - -#ifndef CONFIG_EXAMPLES_FBCON_BGCOLOR -# if (FBCON_BPP == 24) || (FBCON_BPP == 32) -# define FBCON_BGCOLOR 0x00000000 -# elif FBCON_BPP == 16 -# define FBCON_BGCOLOR 0x0000 -# else -# define FBCON_BGCOLOR 0x0 -# endif -#else -# define FBCON_BGCOLOR CONFIG_EXAMPLES_FBCON_BGCOLOR -#endif - -#ifndef CONFIG_EXAMPLES_FBCON_FCOLOR -# if (FBCON_BPP == 32) || (FBCON_BPP == 24) -# define FBCON_FCOLOR 0xffffff -# elif FBCON_BPP == 16 -# define FBCON_FCOLOR 0xffff -# else -# define FBCON_FCOLOR 0xff -# endif -#else -# define FBCON_FCOLOR CONFIG_EXAMPLES_FBCON_FCOLOR -#endif - -/* Console font ID */ - -#ifndef CONFIG_EXAMPLES_FBCON_FONTID -# ifndef NXFONT_DEFAULT -# error NXFONT_DEFAULT not defined -# endif -# define FBCON_FONTID NXFONT_DEFAULT -#else -# define FBCON_FONTID CONFIG_EXAMPLES_FBCON_FONTID -#endif - -/* Font glyph caching */ - -#ifndef CONFIG_EXAMPLES_FBCON_GLCACHE -# define FBCON_GLCACHE 16 -#else -# define FBCON_GLCACHE CONFIG_EXAMPLES_FBCON_GLCACHE -#endif - -/* Bitmap flags */ - -#define BMFLAGS_NOGLYPH (1 << 0) /* No glyph available, use space */ -#define BM_ISSPACE(bm) (((bm)->flags & BMFLAGS_NOGLYPH) != 0) - -/* Sizes and maximums */ - -#define MAX_USECNT 255 /* Limit to range of a uint8_t */ - -/* Line spacing. Space (in rows) between lines. */ - -#define FBCON_LINESPACING CONFIG_EXAMPLES_FBCON_LINESPACING - -/* Cursor character */ - -#define FBCON_CURSORCHAR CONFIG_EXAMPLES_FBCON_CURSORCHAR - -/* Spawn task */ - -#define SPAWN_TASK CONFIG_EXAMPLES_FBCON_SPAWN_TASK - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -enum exitcode_e -{ - FBCON_EXIT_SUCCESS = 0, - FBCON_EXIT_FAIL, - FBCON_EXIT_FD, - FBCON_EXIT_GETVINFO, - FBCON_EXIT_GETPINFO, - FBCON_EXIT_FBMEM, - FBCON_EXIT_FBMEM2, - FBCON_EXIT_FBIO_OVERLAY_INFO, - FBCON_EXIT_FBIO_SELECT_OVERLAY, - FBCON_EXIT_FONTOPEN, - FBCON_EXIT_SETBGCOLOR, - FBCON_EXIT_STDOUT_PIPE_FAILED, - FBCON_EXIT_STDERR_PIPE_FAILED, - FBCON_EXIT_STDIN_PIPE_FAILED, - FBCON_EXIT_LOCAL_STDERR_PIPE_FAILED, - FBCON_EXIT_LOCAL_STDOUT_PIPE_FAILED, - FBCON_EXIT_POSIX_SPAWN_ACTIONS_INIT_FAILED, - FBCON_EXIT_POSIX_SPAWN_FAILED, - FBCON_EXIT_APP_INDEX_UNAVAILABLE, - FBCON_EXIT_APP_POSIX_ATTRIB_INIT_FAILED, -}; - -/* Describes one cached glyph bitmap */ - -struct fbcon_glyph_s -{ - uint8_t code; /* Character code */ - uint8_t height; /* Height of this glyph (in rows) */ - uint8_t width; /* Width of this glyph (in pixels) */ - uint8_t stride; /* Width of the glyph row (bytes) */ - uint8_t usecnt; /* Use count */ - FAR uint8_t *bitmap; /* Allocated bitmap memory */ -}; - -/* Describes on character on the display */ - -struct fbcon_bitmap_s -{ - uint8_t code; /* Character code */ - uint8_t flags; /* See BMFLAGS_* */ - struct nxgl_point_s pos; /* Character position */ -}; - -/* Describes the state of one text display */ - -struct fbcon_state_s -{ - int fd_fb; - FAR void *fbcon_font; - struct fb_videoinfo_s *vinfo; - struct fb_planeinfo_s *pinfo; -#ifdef CONFIG_FB_OVERLAY - struct fb_overlayinfo_s oinfo; -#endif - FAR void *fbmem; -#if 0 - /* Revisit needed - no support got dual framebuffers as yet */ - - FAR void *fbmem2; - FAR void *act_fbmem; -#endif - uint32_t mem2_yoffset; - - /* The following describe the console */ - - nxgl_mxpixel_t bcolor; /* Console background color */ - nxgl_mxpixel_t fcolor; /* Console font color */ - struct nxgl_size_s wsize; /* Console size */ - uint8_t fheight; /* Max height of a font in pixels */ - uint8_t fwidth; /* Max width of a font in pixels */ - uint8_t spwidth; /* The width of a space */ - - /* These describe all text already added to the display */ - - uint8_t maxglyphs; /* Size of the glyph[] array */ - uint16_t maxchars; /* Size of the bm[] array */ - uint32_t nchars; /* Numb of chars in the bm[] array */ - - FAR struct fbcon_bitmap_s *bm; /* List of bitmaps on the display */ - FAR struct fbcon_glyph_s *glyph; /* Cache of rendered fonts in use */ - FAR struct fbcon_bitmap_s cursor; /* Character to use for cursor */ - - /* VT100 escape sequence processing */ - - char seq[VT100_MAX_SEQUENCE]; /* Buffered chars */ - uint8_t nseq; /* Num buffered chars */ - int nwild; /* Num wild collected */ - int wildval; /* Wildcard value */ -}; - -typedef void (*seqhandler_t)(FAR struct fbcon_state_s *st); - -/* Identifies the state of the VT100 escape sequence processing */ - -enum fbcon_vt100state_e -{ - VT100_NOT_CONSUMED = 0, /* Character is not part of a VT100 escape sequence */ - VT100_CONSUMED, /* Character was consumed as part of the VT100 escape processing */ - VT100_PROCESSED, /* The full VT100 escape sequence was processed */ - VT100_ABORT /* Invalid/unsupported character in buffered escape sequence */ -}; - -struct vt100_sequence_s -{ - FAR const char *seq; - seqhandler_t handler; - uint8_t size; -}; - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ -#if 0 -/* Revisit needed = no support for dual framebuffers yet */ - -static int fb_init_mem2(FAR struct fbcon_state_s *st); -#endif -static int fbdev_get_pinfo(int fd, FAR struct fb_planeinfo_s *pinfo); -static int fbcon_initialize(FAR struct fbcon_state_s *st); -static void fbcon_newline(FAR struct fbcon_state_s *st); -static int fbcon_hidechar(FAR FAR struct fbcon_state_s *st, - FAR const struct fbcon_bitmap_s *bm); -static enum fbcon_vt100state_e fbcon_vt100(FAR struct fbcon_state_s *st, - char ch); -static void fbcon_fillchar(FAR struct fbcon_state_s *st, - FAR const struct nxgl_rect_s *rect, - FAR const struct fbcon_bitmap_s *bm); -static int fbcon_fill(FAR struct fbcon_state_s *st, - FAR struct nxgl_rect_s *rect, - FAR nxgl_mxpixel_t *color); -static void fbcon_fillspace(FAR struct fbcon_state_s *st, - FAR const struct nxgl_rect_s *rect, - FAR const struct fbcon_bitmap_s *bm); -static int fbcon_bitmap(FAR struct fbcon_state_s *st, - FAR const struct nxgl_rect_s *dest, - FAR const uint32_t *src, - unsigned int stride); -static int fbcon_backspace(FAR struct fbcon_state_s *st); -static void fbcon_home(FAR struct fbcon_state_s *st); -static inline void fbcon_movedisplay(FAR struct fbcon_state_s *st, - int bottom, int scrollheight); -static inline void fbcon_scroll(FAR struct fbcon_state_s *st, - int scrollheight); -static void fbcon_freeglyph(FAR struct fbcon_glyph_s *glyph); -static inline FAR struct fbcon_glyph_s * - fbcon_allocglyph(FAR struct fbcon_state_s *st); -static FAR struct fbcon_glyph_s * - fbcon_findglyph(FAR struct fbcon_state_s *st, uint8_t ch); -static inline FAR struct fbcon_glyph_s * - fbcon_renderglyph(FAR struct fbcon_state_s *st, - FAR const struct nx_fontbitmap_s *fbm, uint8_t ch); -static int fbcon_fontsize(FAR void *hfont, uint8_t ch, - FAR struct nxgl_size_s *size); -static FAR struct fbcon_glyph_s * - fbcon_getglyph(FAR struct fbcon_state_s *st, uint8_t ch); -static FAR const struct fbcon_bitmap_s * - fbcon_addchar(FAR struct fbcon_state_s *st, uint8_t ch); -static void fbcon_write(FAR struct fbcon_state_s *st, - FAR char *buffer, size_t buflen); -static bool has_input(int fd); -static void poll_std_streams(FAR struct fbcon_state_s *st); -static void fbcon_putc(FAR struct fbcon_state_s *st, uint8_t ch); -static enum fbcon_vt100state_e fbcon_vt100seq( - FAR struct fbcon_state_s *st, int seqsize); -static FAR const struct vt100_sequence_s * - fbcon_vt100part(FAR struct fbcon_state_s *st, int seqsize); -static enum fbcon_vt100state_e fbcon_vt100(FAR struct fbcon_state_s *st, - char ch); -static void fbcon_erasetoeol(FAR struct fbcon_state_s *st); -static void fbcon_clearline(FAR struct fbcon_state_s *st); -static void fbcon_showcursor(FAR struct fbcon_state_s *st); -static void fbcon_hidecursor(FAR struct fbcon_state_s *st); -static void fbcon_cursorl(FAR struct fbcon_state_s *st); - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/* Pipes for NSH Shell: stdin, stdout, stderr */ - -#ifdef CONFIG_EXAMPLES_FBCON_PIPE_STDIN -static int g_nsh_stdin[2]; -#endif -static int g_nsh_stdout[2]; -static int g_nsh_stderr[2]; - -/* The VT100 sequences supported by FBCON */ - -static const char g_erasetoeol[] = VT100_CLEAREOL; -static const char g_clearline[] = VT100_CLEARLINE; -static const char g_cursoroff[] = VT100_CURSOROFF; -static const char g_cursoron[] = VT100_CURSORON; -static const char g_cursorl[] = VT100_CURSORL; - -static const struct vt100_sequence_s g_vt100sequences[] = -{ - {g_erasetoeol, fbcon_erasetoeol, sizeof(g_erasetoeol)}, - {g_clearline, fbcon_clearline, sizeof(g_clearline)}, - {g_cursoroff, fbcon_hidecursor, sizeof(g_cursoroff)}, - {g_cursoron, fbcon_showcursor, sizeof(g_cursoroff)}, - {g_cursorl, fbcon_cursorl, sizeof(g_cursorl)}, - {NULL, NULL, 0} -}; - -#ifdef CONFIG_EXAMPLES_FBCON_SHOW_WELCOME -# ifdef CONFIG_EXAMPLES_FBCON_PIPE_STDOUT -static const char g_stdout_hello[] = "Hello FBCON stdout fprintf output!"; -# endif -# ifdef CONFIG_EXAMPLES_FBCON_PIPE_STDERR -static const char g_stderr_hello[] = "Hello FBCON stderr fprintf output!"; -# endif -#endif - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: fbcon_showcursor - * - * Description: - * Render the cursor character at the current display position. - * - * Input Parameters: - * st - pointer to FBCON status structure - * - * Returned Value: - * None - * - ****************************************************************************/ - -static void fbcon_showcursor(FAR struct fbcon_state_s *st) -{ - int lineheight; - - if ((st->cursor.pos.x + st->fwidth) > st->wsize.w) - { -#ifndef CONFIG_EXAMPLES_FBCON_NOWRAP - /* No.. move to the next line */ - - fbcon_newline(st); -#else - return OK; -#endif - } - - /* Check if we need to scroll up */ - - lineheight = st->fheight + FBCON_LINESPACING; - while (st->cursor.pos.y >= st->wsize.h + lineheight) - { - fbcon_scroll(st, lineheight); - } - - /* Render the cursor glyph onto the display. */ - - fbcon_fillchar(st, NULL, &st->cursor); -} - -/**************************************************************************** - * Name: fbcon_hidecursor - * - * Description: - * Remove the cursor character at the current display position. - * - * Input Parameters: - * st - pointer to FBCON status structure - * - * Returned Value: - * None - * - ****************************************************************************/ - -static void fbcon_hidecursor(FAR struct fbcon_state_s *st) -{ - fbcon_hidechar(st, &st->cursor); -} - -/**************************************************************************** - * Name: fbcon_cursorl - * - * Description: - * Move the cursor position to the left n characters. - * - * Input Parameters: - * st - pointer to FBCON status structure - * - * Returned Value: - * None - * - ****************************************************************************/ - -static void fbcon_cursorl(FAR struct fbcon_state_s *st) -{ - int i; - - /* Revisit needed. It seems backspace 1 less than calculated. - * This is illogical and yet to be explained and is perhaps related to - * nsh itself when nsh is the spawned app/task. - */ - - for (i = 1; i < st->wildval; i++) - { - fbcon_backspace(st); - } -} - -/**************************************************************************** - * Name: fbcon_erasetoeol - * - * Description: - * Handle the erase-to-eol VT100 escape sequence. - * Erase from and including cursor position - * - * Input Parameters: - * st - pointer to FBCON status structure - * - * Returned Value: - * None - * - ****************************************************************************/ - -static void fbcon_erasetoeol(FAR struct fbcon_state_s *st) -{ - struct nxgl_rect_s rect; - - /* Create a bounding box the size of the remaining iine */ - - rect.pt1.x = st->cursor.pos.x; - rect.pt2.x = st->wsize.w - 1; - rect.pt1.y = st->cursor.pos.y; - rect.pt2.y = rect.pt1.y + st->fheight + FBCON_LINESPACING - 1; - - /* Clear the region */ - - if (fbcon_fill(st, &rect, &st->bcolor) < 0) - { - gerr("ERROR: fbcon_fill failed: %d\n", errno); - } - - /* Because we were clearing from the cursor position, there's no need - * to modify st->nchar as there are no characters after the cursor. - */ -} - -/**************************************************************************** - * Name: fbcon_clearline - * - * Description: - * Handle the clearline VT100 escape sequence - * - * Input Parameters: - * st - pointer to FBCON status structure - * - * Returned Value: - * The index of the match in g_vt100sequences[] - * - ****************************************************************************/ - -static void fbcon_clearline(FAR struct fbcon_state_s *st) -{ - int i; - FAR struct fbcon_bitmap_s *bm; - struct nxgl_rect_s rect; - - /* Create a bounding box the size of the iine */ - - rect.pt1.x = 0; - rect.pt2.x = st->wsize.w - 1; - rect.pt1.y = st->cursor.pos.y + FBCON_LINESPACING; - rect.pt2.y = st->cursor.pos.y + st->fheight + FBCON_LINESPACING - 1; - - /* Clear the region */ - - if (fbcon_fill(st, &rect, &st->bcolor) < 0) - { - gerr("ERROR: fbcon_fill failed: %d\n", errno); - } - - st->cursor.pos.x = st->spwidth; - - /* Decrement nchar for each character within in the bounding box */ - - i = st->nchars; - while (--i > 0) - { - bm = &st->bm[i]; - if (bm->pos.y <= rect.pt1.y && - bm->pos.y + st->fheight >= rect.pt2.y) - { - st->nchars--; - } - } -} - -/**************************************************************************** - * Name: fbcon_bitmap - * - * Description: - * Copy a rectangular region of a larger image into the rectangle in the - * specified window. - * - * Input Parameters: - * st - pointer to FBCON status structure - * dest - Describes the rectangular region on the display that will - * receive the bit map. - * src - The start of the source image. - * stride - The width of the full source image in pixels. - * - * Returned Value: - * OK on success; ERROR on failure with errno set appropriately - * - ****************************************************************************/ - -static int fbcon_bitmap(FAR struct fbcon_state_s *st, - FAR const struct nxgl_rect_s *dest, - FAR const uint32_t *src, - unsigned int stride) -{ - FAR uint32_t *dst; - FAR uint8_t *row; - struct fb_area_s area; - int x; - int y; - - area.h = dest->pt2.y - dest->pt1.y + 1; - area.w = dest->pt2.x - dest->pt1.x + 1; - area.x = dest->pt1.x; - area.y = dest->pt1.y; - - row = (FAR uint8_t *)st->fbmem + st->pinfo->stride * area.y; - for (y = 0; y < area.h; y++) - { - dst = ((FAR uint32_t *)row) + area.x; - for (x = 0; x < area.w; x++) - { - *dst++ = *(uint32_t *)src++; - } - - row += st->pinfo->stride; - } - - return OK; -} - -/**************************************************************************** - * Name: fbcon_movedisplay - * - * Description: - * This function implements the data movement for the scroll operation. - * - * Input Parameters: - * st - pointer to FBCON status structure - * bottom - Start of the vacated area at the bottom to be cleared - * scrollheight - The distance the display must be scrolled - * - * Returned Value: - * OK on success; ERROR on failure with errno set appropriately - * - ****************************************************************************/ - -static inline void fbcon_movedisplay(struct fbcon_state_s *st, int bottom, - int scrollheight) -{ - FAR struct fbcon_bitmap_s *bm; - struct nxgl_rect_s rect; - nxgl_coord_t row; - int ret; - int i; - - /* Move each row, one at a time. They could all be moved at once but since - * the region is cleared, then re-written, the effect would not be good. - * Below the region is also cleared and re-written, - * however, in much smaller chunks. - */ - - rect.pt1.x = 0; - rect.pt2.x = st->wsize.w - 1; - - for (row = FBCON_LINESPACING; row < bottom; row += scrollheight) - { - /* Create a bounding box the size of one row of characters */ - - rect.pt1.y = row; - rect.pt2.y = row + scrollheight - 1; - - /* Clear the region */ - - ret = fbcon_fill(st, &rect, &st->bcolor); - if (ret < 0) - { - gerr("ERROR: fbcon_fill failed: %d\n", errno); - } - - /* Fill each character that might lie within in the bounding box */ - - for (i = 0; i < st->nchars; i++) - { - bm = &st->bm[i]; - if (bm->pos.y <= rect.pt1.y && - bm->pos.y + st->fheight >= rect.pt2.y) - { - fbcon_fillchar(st, &rect, bm); - } - } - } - - /* Finally, clear the vacated part of the display */ - - rect.pt1.y = bottom; - rect.pt2.y = st->wsize.h - 1; - - ret = fbcon_fill(st, &rect, &st->bcolor); - if (ret < 0) - { - fprintf(stderr, "fbcon_movedisplay: fbcon_fill failed: %d\n", errno); - } -} - -/**************************************************************************** - * Name: fbcon_scroll - * - * Description: - * Scroll the display up by a certain amount - * - * Input Parameters: - * st - pointer to FBCON status structure - * scrollheight - The distance the display must be scrolled - * - * Returned Value: - * OK on success; ERROR on failure with errno set appropriately - * - ****************************************************************************/ - -static inline void fbcon_scroll(struct fbcon_state_s *st, int scrollheight) -{ - int i; - int j; - - /* Adjust the vertical position of each character */ - - for (i = 0; i < st->nchars; ) - { - FAR struct fbcon_bitmap_s *bm = &st->bm[i]; - - /* Has any part of this character scrolled off the screen? */ - - if (bm->pos.y < scrollheight + FBCON_LINESPACING) - { - /* Yes... Delete the character by moving all of the data */ - - for (j = i; j < st->nchars - 1; j++) - { - memcpy(&st->bm[j], &st->bm[j + 1], - sizeof(struct fbcon_bitmap_s)); - } - - /* Decrement the number of cached characters ('i' is not - * incremented in this case because it already points to the next - * character) - */ - - st->nchars--; - } - - /* No.. just decrement its vertical position (moving it "up" the - * display by one line). - */ - - else - { - bm->pos.y -= scrollheight; - - /* We are keeping this one so increment to the next character */ - - i++; - } - } - - /* And move the next display position up by one line as well */ - - st->cursor.pos.y -= scrollheight; - - /* Move the display in the range of 0-height up one scrollheight. */ - - fbcon_movedisplay(st, st->cursor.pos.y, scrollheight); -} - -/**************************************************************************** - * Name: fbcon_freeglyph - * - * Description: - * Clear the specified glyph structure - * - * Input Parameters: - * glyph - pointer to glyph structure to be freed - * - * Returned Value: - * None - * - ****************************************************************************/ - -static void fbcon_freeglyph(FAR struct fbcon_glyph_s *glyph) -{ - if (glyph->bitmap) - { - free(glyph->bitmap); - } - - memset(glyph, 0, sizeof(struct fbcon_glyph_s)); -} - -/**************************************************************************** - * Name: fbcon_allocglyph - * - * Description: - * Allocate a glyph structure - * - * Input Parameters: - * glyph - pointer to glyph structure to be allocated - * - * Returned Value: - * None - * - ****************************************************************************/ - -static inline FAR struct fbcon_glyph_s * - fbcon_allocglyph(FAR struct fbcon_state_s *st) -{ - FAR struct fbcon_glyph_s *glyph = NULL; - FAR struct fbcon_glyph_s *luglyph = NULL; - uint8_t luusecnt; - int i; - - /* Search through the glyph cache looking for an unused glyph. Also, keep - * track of the least used glyph as well. We need that if we have to - * replace a glyph in the cache. - */ - - for (i = 0; i < st->maxglyphs; i++) - { - /* Is this glyph in use? */ - - glyph = &st->glyph[i]; - if (!glyph->usecnt) - { - /* No.. return this glyph with a use count of one */ - - glyph->usecnt = 1; - return glyph; - } - - /* Yes.. check for the least recently used */ - - if (!luglyph || glyph->usecnt < luglyph->usecnt) - { - luglyph = glyph; - } - } - - /* If we get here, the glyph cache is full. We replace the least used - * glyph with the one we need now. (luglyph can't be NULL). - */ - - luusecnt = luglyph->usecnt; - fbcon_freeglyph(luglyph); - - /* But lets decrement all of the usecnts so that the new one one be so - * far behind in the counts as the older ones. - */ - - if (luusecnt > 1) - { - uint8_t decr = luusecnt - 1; - - for (i = 0; i < st->maxglyphs; i++) - { - /* Is this glyph in use? */ - - glyph = &st->glyph[i]; - if (glyph->usecnt > decr) - { - glyph->usecnt -= decr; - } - } - } - - /* Then return the least used glyph */ - - luglyph->usecnt = 1; - return luglyph; -} - -/**************************************************************************** - * Name: fbcon_findglyph - * - * Description: - * Try and find a glyph in the cache for a given character - * - * Input Parameters: - * st - pointer to FBCON status structure - * ch - the character - * - * Returned Value: - * a pointer to the glyph structure if found or NULL if not - * - ****************************************************************************/ - -static FAR struct fbcon_glyph_s * - fbcon_findglyph(FAR struct fbcon_state_s *st, uint8_t ch) -{ - int i; - - /* Try to find the glyph in the cache of pre-rendered glyphs */ - - for (i = 0; i < st->maxglyphs; i++) - { - FAR struct fbcon_glyph_s *glyph = &st->glyph[i]; - if (glyph->usecnt > 0 && glyph->code == ch) - { - /* Increment the use count (unless it is already at the max) */ - - if (glyph->usecnt < MAX_USECNT) - { - glyph->usecnt++; - } - - /* And return the glyph that we found */ - - return glyph; - } - } - - return NULL; -} - -/**************************************************************************** - * Name: fbcon_renderglyph - * - * Description: - * Render a character as a glyph based on the font bitmap and metrics - * - * Input Parameters: - * st - pointer to FBCON status structure - * fbm - pointer to the character bitmap/metrics - * ch - the character to be rendered - * - * Returned Value: - * a pointer to the rendered glyph structure - * - ****************************************************************************/ - -static inline FAR struct fbcon_glyph_s * - fbcon_renderglyph(FAR struct fbcon_state_s *st, - FAR const struct nx_fontbitmap_s *fbm, uint8_t ch) -{ - FAR struct fbcon_glyph_s *glyph = NULL; - FAR nxgl_mxpixel_t *ptr; -#if FBCON_BPP < 8 - nxgl_mxpixel_t pixel; -#endif - int bmsize; - int row; - int col; - int ret; - - /* Make sure that there is room for another glyph */ - - ginfo("ch=%c [%02x]\n", isprint(ch) ? ch : '.', ch); - - /* Allocate the glyph (always succeeds) */ - - glyph = fbcon_allocglyph(st); - glyph->code = ch; - - /* Get the dimensions of the glyph */ - - glyph->width = fbm->metric.width + fbm->metric.xoffset; - glyph->height = fbm->metric.height + fbm->metric.yoffset; - - /* Allocate memory to hold the glyph with its offsets */ - - glyph->stride = (glyph->width * FBCON_BPP + 7) / 8; - bmsize = glyph->stride * glyph->height; - glyph->bitmap = (FAR uint8_t *)malloc(bmsize); - - if (glyph->bitmap) - { - /* Initialize the glyph memory to the background color */ - -#if FBCON_BPP < 8 - pixel = st->bcolor; -# if FBCON_BPP == 1 - /* Pack 1-bit pixels into a 2-bits */ - - pixel &= 0x01; - pixel = (pixel) << 1 | pixel; -# endif -# if FBCON_BPP < 4 - /* Pack 2-bit pixels into a nibble */ - - pixel &= 0x03; - pixel = (pixel) << 2 | pixel; -# endif - - /* Pack 4-bit nibbles into a byte */ - - pixel &= 0x0f; - pixel = (pixel) << 4 | pixel; - - ptr = (FAR nxgl_mxpixel_t *)glyph->bitmap; - for (row = 0; row < glyph->height; row++) - { - for (col = 0; col < glyph->stride; col++) - { - /* Transfer the packed bytes into the buffer */ - - *ptr++ = pixel; - } - } - -#elif FBCON_BPP == 24 -# error "Additional logic is needed here for 24bpp support" - -#else /* FBCON_BPP = {8,16,32} */ - - ptr = (FAR nxgl_mxpixel_t *)glyph->bitmap; - for (row = 0; row < glyph->height; row++) - { - /* Just copy the color value into the glyph memory */ - - for (col = 0; col < glyph->width; col++) - { - *ptr++ = st->bcolor; - } - } -#endif - - /* Then render the glyph into the allocated memory */ - - ret = RENDERER((FAR nxgl_mxpixel_t *)glyph->bitmap, - glyph->height, glyph->width, glyph->stride, - fbm, st->fcolor); - if (ret < 0) - { - /* Actually, the RENDERER never returns a failure */ - - gerr("ERROR: fbcon_renderglyph: RENDERER failed\n"); - fbcon_freeglyph(glyph); - glyph = NULL; - } - } - - return glyph; -} - -/**************************************************************************** - * Name: fbcon_fontsize - * - * Description: - * Get the size of a given character bitmap - * - * Input Parameters: - * font - the font of interest - * ch - the character of interest - * size _ pointer to the structure to return the character size - * - * Returned Value: - * Success or ERROR - * - ****************************************************************************/ - -static int fbcon_fontsize(FAR void *hfont, uint8_t ch, - FAR struct nxgl_size_s *size) -{ - FAR const struct nx_fontbitmap_s *fbm; - - /* No, it is not cached... Does the code map to a font? */ - - fbm = nxf_getbitmap(hfont, ch); - if (fbm) - { - /* Yes.. return the font size */ - - size->w = fbm->metric.width + fbm->metric.xoffset; - size->h = fbm->metric.height + fbm->metric.yoffset; - return OK; - } - - return ERROR; -} - -/**************************************************************************** - * Name: fbcon_getglyph - * - * Description: - * Get rendered glyph data for a given character - * - * Input Parameters: - * st - pointer to FBCON status structure - * ch - the character to be rendered - * - * Returned Value: - * a pointer to the glyph data - * - ****************************************************************************/ - -static FAR struct fbcon_glyph_s * - fbcon_getglyph(FAR struct fbcon_state_s *st, uint8_t ch) -{ - FAR struct fbcon_glyph_s *glyph; - FAR const struct nx_fontbitmap_s *fbm; - - /* First, try to find the glyph in the cache of pre-rendered glyphs */ - - glyph = fbcon_findglyph(st, ch); - if (!glyph) - { - /* No, it is not cached... Does the code map to a font? */ - - fbm = nxf_getbitmap(st->fbcon_font, ch); - if (fbm) - { - /* Yes.. render the glyph */ - - glyph = fbcon_renderglyph(st, fbm, ch); - } - } - - return glyph; -} - -/**************************************************************************** - * Name: fbcon_hidechar - * - * Description: - * Erase a character from the display. - * - * Input Parameters: - * st - pointer to FBCON status structure - * bm - pointer to the character bitmap to be erased - * - * Returned Value: - * Success or error value - * - ****************************************************************************/ - -static int fbcon_hidechar(FAR struct fbcon_state_s *st, - FAR const struct fbcon_bitmap_s *bm) -{ - struct nxgl_rect_s bounds; - struct nxgl_size_s fsize; - int ret; - - /* Get the size of the font glyph. If fbcon_fontsize, then the - * character will have been rendered as a space, and no display - * modification is required (not an error). - */ - - ret = fbcon_fontsize(st->fbcon_font, bm->code, &fsize); - if (ret < 0) - { - /* It was rendered as a space. */ - - return OK; - } - - /* Construct a bounding box for the glyph */ - - bounds.pt1.x = bm->pos.x; - bounds.pt1.y = bm->pos.y; - bounds.pt2.x = bm->pos.x + fsize.w - 1; - bounds.pt2.y = bm->pos.y + fsize.h - 1; - - /* Fill the bitmap region with the background color, erasing the - * character from the display. - */ - - return fbcon_fill(st, &bounds, &st->bcolor); -} - -/**************************************************************************** - * Name: fbcon_addchar - * - * Description: - * Find or create a bitmap structurefor a character - * - * Input Parameters: - * st - pointer to FBCON status structure - * ch - the character to be rendered - * - * Returned Value: - * Pointer to the character bitmap - * - ****************************************************************************/ - -static FAR const struct fbcon_bitmap_s * - fbcon_addchar(FAR struct fbcon_state_s *st, - uint8_t ch) -{ - FAR struct fbcon_bitmap_s *bm = NULL; - FAR struct fbcon_glyph_s *glyph; - - /* Setup the bitmap information */ - - bm = &st->bm[st->nchars]; - bm->code = ch; - bm->flags = 0; - bm->pos.x = st->cursor.pos.x; - bm->pos.y = st->cursor.pos.y; - - /* Find (or create) the matching glyph */ - - glyph = fbcon_getglyph(st, ch); - if (!glyph) - { - /* No, there is no font for this code. Just mark this as a space. */ - - bm->flags |= BMFLAGS_NOGLYPH; - - /* Set up the next character position */ - - st->cursor.pos.x += st->spwidth; - } - else - { - /* Set up the next character position */ - - st->cursor.pos.x += glyph->width; - } - - /* Increment nchars to retain this character */ - - if (st->nchars < st->maxchars) - { - st->nchars++; - } - - return bm; -} - -/**************************************************************************** - * Name: fbcon_fill - * - * Description: - * Fill a region with a colour. - * - * Input Parameters: - * st - pointer to FBCON status structure - * rect - Describes the rectangular region on the display to be filled - * color - The color to fill the rectangle with - * - * Returned Value: - * OK on success; ERROR on failure with errno set appropriately - * - ****************************************************************************/ - -static int fbcon_fill(FAR struct fbcon_state_s *st, - FAR struct nxgl_rect_s *rect, - FAR nxgl_mxpixel_t *color) -{ - FAR uint32_t *dest; - FAR uint8_t *row; - struct fb_area_s area; - int x; - int y; - - area.h = rect->pt2.y - rect->pt1.y + 1; - area.w = rect->pt2.x - rect->pt1.x + 1; - area.x = rect->pt1.x; - area.y = rect->pt1.y; - - row = (FAR uint8_t *)st->fbmem + st->pinfo->stride * area.y; - for (y = 0; y < area.h; y++) - { - dest = (FAR uint32_t *)row + area.x; - for (x = 0; x < area.w; x++) - { - *dest++ = *color; - } - - row += st->pinfo->stride; - } - - return OK; -} - -/**************************************************************************** - * Name: fbcon_backspace - * - * Description: - * Remove the last character from the window. - * - * Input Parameters: - * st - pointer to FBCON status structure - * - * Returned Value: - * OK on success; ERROR on failure with errno set appropriately - * - ****************************************************************************/ - -static int fbcon_backspace(FAR struct fbcon_state_s *st) -{ - FAR struct fbcon_bitmap_s *bm; - int ndx; - int ret = -ENOENT; - - /* Is there a character on the display? */ - - if (st->nchars > 0) - { - /* Yes.. Get the index to the last bitmap on the display */ - - ndx = st->nchars - 1; - bm = &st->bm[ndx]; - - /* Erase the character from the display */ - - ret = fbcon_hidechar(st, bm); - - /* The current position to the location where the last character was */ - - st->cursor.pos.x = bm->pos.x; - st->cursor.pos.y = bm->pos.y; - - /* Decrement nchars to discard this character */ - - st->nchars = ndx; - } - - return ret; -} - -/**************************************************************************** - * Name: fbcon_home - * - * Description: - * Set the next character position to the top-left corner of the display. - * - * Input Parameters: - * st - pointer to FBCON status structure - * - * Returned Value: - * None - * - ****************************************************************************/ - -static void fbcon_home(FAR struct fbcon_state_s *st) -{ - /* The first character is one space from the left */ - - st->cursor.pos.x = st->spwidth; - - /* And FBCON_LINESPACING lines from the top */ - - st->cursor.pos.y = FBCON_LINESPACING; - - /* And reset number of characters in the bm buffer */ - - st->nchars = 0; -} - -/**************************************************************************** - * Name: fbcon_newline - * - * Description: - * Set the next character position to the beginning of the next line. - * - * Input Parameters: - * st - pointer to FBCON status structure - * - * Returned Value: - * None - * - ****************************************************************************/ - -void fbcon_newline(FAR struct fbcon_state_s *st) -{ - /* Carriage return: The first character is one space from the left */ - - st->cursor.pos.x = st->spwidth; - - /* Linefeed: Down the max font height + FBCON_LINESPACING */ - - st->cursor.pos.y += (st->fheight + FBCON_LINESPACING); -} - -/**************************************************************************** - * Name: fbcon_putc - * - * Description: - * Render the specified character at the current display position. - * - * Input Parameters: - * st - pointer to FBCON status structure - * ch - the character to be rendered - * - * Returned Value: - * None - * - ****************************************************************************/ - -void fbcon_putc(FAR struct fbcon_state_s *st, uint8_t ch) -{ - FAR const struct fbcon_bitmap_s *bm; - int lineheight; - - /* Ignore carriage returns */ - - if (ch == '\r') - { - return; - } - - /* Handle backspace (treating both BS and DEL as backspace) */ - - if (ch == ASCII_BS || ch == ASCII_DEL) - { - fbcon_backspace(st); - return; - } - - /* Will another character fit on this line? */ - - if (st->cursor.pos.x + st->fwidth > st->wsize.w) - { -#ifndef CONFIG_EXAMPLES_FBCON_NOWRAP - /* No.. move to the next line */ - - fbcon_newline(st); - - /* If we were about to output a newline character, then don't */ - - if (ch == ASCII_LF) - { - return; - } -#else - /* No.. Ignore all further characters until a newline is encountered */ - - if (ch != ASCII_LF) - { - return; - } -#endif - } - - /* If it is a newline character, then just perform the logical newline - * operation. - */ - - if (ch == ASCII_LF) - { - fbcon_newline(st); - return; - } - - /* Check if we need to scroll up */ - - lineheight = st->fheight + FBCON_LINESPACING; - while (st->cursor.pos.y > st->wsize.h - lineheight) - { - fbcon_scroll(st, lineheight); - } - - /* Find the glyph associated with the character and render it - * onto the display. - */ - - bm = fbcon_addchar(st, ch); - if (bm) - { - fbcon_fillchar(st, NULL, bm); - } -} - -/**************************************************************************** - * Name: fbcon_fillspace - * - * Description: - * Handle the special case of a space being displayed - * - * Input Parameters: - * st - pointer to FBCON status structure - * rect- Describes the rectangular region on the display that will - * receive the space. - * bm - pointer to the character bitmap structure with the location - * - * Returned Value: - * None - * - ****************************************************************************/ - -static void fbcon_fillspace(FAR struct fbcon_state_s *st, - FAR const struct nxgl_rect_s *rect, - FAR const struct fbcon_bitmap_s *bm) -{ - struct nxgl_rect_s bounds; - struct nxgl_rect_s intersection; - int ret; - - /* Construct a bounding box for the glyph */ - - bounds.pt1.x = bm->pos.x; - bounds.pt1.y = bm->pos.y; - bounds.pt2.x = bm->pos.x + st->spwidth - 1; - bounds.pt2.y = bm->pos.y + st->fheight - 1; - - /* Should this also be clipped to a region in the window? */ - - if (rect != NULL) - { - /* Get the intersection of the redraw region and the character bitmap */ - - nxgl_rectintersect(&intersection, rect, &bounds); - } - else - { - /* The intersection is the whole glyph */ - - nxgl_rectcopy(&intersection, &bounds); - } - - /* Check for empty intersections */ - - if (!nxgl_nullrect(&intersection)) - { - /* Fill the bitmap region with the background color, erasing the - * character from the display. - */ - - ret = fbcon_fill(st, &intersection, &st->bcolor); - if (ret < 0) - { - gerr("ERROR: fill() method failed: %d\n", ret); - } - } -} - -/**************************************************************************** - * Name: fbcon_fillchar - * - * Description: - * Implement the character display - * - * Input Parameters: - * st - pointer to FBCON status structure - * rect- Describes the rectangular region on the display that will - * receive the space. - * bm - pointer to the character bitmap structure with the location - * - * Returned Value: - * None - * - ****************************************************************************/ - -void fbcon_fillchar(FAR struct fbcon_state_s *st, - FAR const struct nxgl_rect_s *rect, - FAR const struct fbcon_bitmap_s *bm) -{ - FAR struct fbcon_glyph_s *glyph; - struct nxgl_rect_s bounds; - struct nxgl_rect_s intersection; - struct nxgl_size_s fsize; - int ret; - - /* Handle the special case of spaces which have no glyph bitmap */ - - if (BM_ISSPACE(bm)) - { - fbcon_fillspace(st, rect, bm); - return; - } - - /* Get the size of the font glyph (which may not have been created yet) */ - - ret = fbcon_fontsize(st->fbcon_font, bm->code, &fsize); - if (ret < 0) - { - /* This would mean that there is no bitmap for the character code and - * that the font would be rendered as a space. But this case should - * never happen here because the BM_ISSPACE() should have already - * found all such cases. - */ - - return; - } - - /* Construct a bounding box for the glyph */ - - bounds.pt1.x = bm->pos.x; - bounds.pt1.y = bm->pos.y; - bounds.pt2.x = bm->pos.x + fsize.w - 1; - bounds.pt2.y = bm->pos.y + fsize.h - 1; - - /* Should this also be clipped to a region in the window? */ - - if (rect != NULL) - { - /* Get the intersection of the redraw region and the character bitmap */ - - nxgl_rectintersect(&intersection, rect, &bounds); - } - else - { - /* The intersection is the whole glyph */ - - nxgl_rectcopy(&intersection, &bounds); - } - - /* Check for empty intersections */ - - if (!nxgl_nullrect(&intersection)) - { - FAR const void *src; - - /* Find (or create) the glyph that goes with this font */ - - glyph = fbcon_getglyph(st, bm->code); - if (!glyph) - { - /* Shouldn't happen */ - - return; - } - - /* Blit the font bitmap into the window */ - - src = (FAR const void *)glyph->bitmap; - - ret = fbcon_bitmap(st, &intersection, src, - (unsigned int)glyph->stride); - if (ret < 0) - { - gerr("ERROR: fbcon_fillchar: fbcon_bitmapwindow failed: %d\n", - ret); - } - } -} - -/**************************************************************************** - * Name: fbcon_vt100part - * - * Description: - * Return the next entry that is a partial match to the sequence. - * - * Input Parameters: - * st - Driver data structure - * seqsize - The number of bytes in the sequence - * - * Returned Value: - * A pointer to the matching sequence in g_vt100sequences[] - * - ****************************************************************************/ - -FAR const struct vt100_sequence_s * - fbcon_vt100part(FAR struct fbcon_state_s *st, int seqsize) -{ - FAR static const struct vt100_sequence_s *seq; - static int ndx; - static int i; - static bool aborted; - static int numw; - static bool collecting; - - /* Search from the beginning of the sequence table */ - - for (ndx = 0; g_vt100sequences[ndx].seq; ndx++) - { - seq = &g_vt100sequences[ndx]; - - /* Is this sequence big enough? */ - - aborted = false; - numw = 0; - st->nwild = 0; - - /* compare characters received to those in the decodable sequences */ - - collecting = false; - for (i = 0; i < seqsize; i++) - { - if (seq->seq[i] == '*') - { - /* This sequence has a wildcard */ - - if ((st->seq[i] < ASCII_0) || (st->seq[i] > ASCII_9)) - { - aborted = true; - break; - } - - if (++numw > 1) - { - /* This logic only allows collection of one wildcard - * per VT100 sequence - */ - - aborted = true; - break; - } - - collecting = true; - st->wildval = st->seq[i] - ASCII_0; /* convert from ASCII */ - } - else if (collecting) - { - if ((st->seq[i] >= ASCII_0) && (st->seq[i] <= ASCII_9)) - { - st->wildval *= 10; - st->wildval += st->seq[i] - ASCII_0; - st->nwild++; - } - else - { - collecting = false; - } - } - else if (st->seq[i] != seq->seq[i]) - { - aborted = true; - break; - } - } - - if (!aborted) - { - return seq; - } - } - - return NULL; -} - -/**************************************************************************** - * Name: fbcon_vt100seq - * - * Description: - * Determine if the new sequence is a part of a supported VT100 escape - * sequence. - * - * Input Parameters: - * st - Driver data structure - * seqsize - The number of bytes in the sequence - * - * Returned Value: - * state - See enum fbcon_vt100state_e; - * - ****************************************************************************/ - -static enum fbcon_vt100state_e fbcon_vt100seq( - FAR struct fbcon_state_s *st, int seqsize) -{ - FAR const struct vt100_sequence_s *seq; - enum fbcon_vt100state_e ret; - - /* Is there any VT100 escape sequence that matches what we have - * buffered so far? - */ - - seq = fbcon_vt100part(st, seqsize); - if (seq) - { - /* Yes.. if the size of that escape sequence is the same as that - * buffered, then we have an exact match. - */ - - if (seqsize >= seq->size + st->nwild) - { - /* Process the VT100 sequence */ - - seq->handler(st); - st->nseq = 0; - return VT100_PROCESSED; - } - - /* The 'seqsize' is still smaller than the potential match(es). We - * will need to collect more characters before we can make a decision. - * Return an indication that we have consumed the character. - */ - - return VT100_CONSUMED; - } - - /* We get here on a failure. The buffer sequence is not part of any - * supported VT100 escape sequence. If seqsize > 1 then we need to - * return a special value because we have to re-process the buffered - * data. - */ - - ret = seqsize > 1 ? VT100_ABORT : VT100_NOT_CONSUMED; - return ret; -} - -/**************************************************************************** - * Name: fbcon_vt100 - * - * Description: - * Test if the newly received byte is part of a VT100 escape sequence - * - * Input Parameters: - * st - Driver data structure - * ch - The newly received character - * - * Returned Value: - * state - See enum fbcon_vt100state_e; - * - ****************************************************************************/ - -static enum fbcon_vt100state_e fbcon_vt100(FAR struct fbcon_state_s *st, - char ch) -{ - enum fbcon_vt100state_e ret; - int seqsize; - - /* If we have no buffered characters, then 'ch' must be the first character - * of an escape sequence. - */ - - if (st->nseq < 1) - { - /* The first character of an escape sequence must be an an escape - * character (!). - */ - - if (ch != ASCII_ESC) - { - return VT100_NOT_CONSUMED; - } - - /* Add the escape character to the buffer but don't bother with any - * further checking. - */ - - st->seq[0] = ASCII_ESC; - st->nseq = 1; - - return VT100_CONSUMED; - } - - /* Temporarily add the next character to the buffer */ - - seqsize = st->nseq; - st->seq[seqsize] = ch; - - /* Then check if this sequence is part of an a valid escape sequence */ - - seqsize++; - ret = fbcon_vt100seq(st, seqsize); - if (ret == VT100_CONSUMED) - { - /* The newly added character is indeed part of a VT100 escape sequence - * (which is still incomplete). Keep it in the buffer. - */ - - st->nseq = seqsize; - } - - return ret; -} - -/**************************************************************************** - * Name: fbcon_write - * - * Description: - * Put a sequence of characters on the display. - * - * Input Parameters: - * st - pointer to FBCON status structure - * buffer - pointer to the character array to be displayed - * buflen - number of characters to be displayed - * - * Returned Value: - * None - * - ****************************************************************************/ - -static void fbcon_write(FAR struct fbcon_state_s *st, - FAR char *buffer, size_t buflen) -{ - char ch; - enum fbcon_vt100state_e state; - ssize_t remaining; - - fbcon_hidecursor(st); - for (remaining = buflen; remaining > 0; remaining--) - { - ch = *buffer++; - -#if CONFIG_EXAMPLES_FBCON_VT100_DECODE - /* Check if this character is part of a VT100 escape sequence */ - - do - { - /* Is the character part of a VT100 escape sequence? */ - - state = fbcon_vt100(st, ch); - switch (state) - { - /* Character is not part of a VT100 escape sequence (and no - * characters are buffer. - */ - - default: - case VT100_NOT_CONSUMED: - { - /* We can output the character to the window */ - - fbcon_putc(st, (uint8_t)ch); - } - break; - - /* The full VT100 escape sequence was processed (and the new - * character was consumed) - */ - - case VT100_PROCESSED: - - /* Character was consumed as part of the VT100 escape processing - * (but the escape sequence is still incomplete. - */ - - case VT100_CONSUMED: - { - /* Do nothing... the VT100 logic owns the character */ - } - break; - - /* Invalid/unsupported character in escape sequence */ - - case VT100_ABORT: - { - int i; - - /* Add the first unhandled character to the window */ - - fbcon_putc(st, (uint8_t)st->seq[0]); - - /* Move all buffer characters down one */ - - for (i = 1; i < st->nseq; i++) - { - st->seq[i - 1] = st->seq[i]; - } - - st->nseq--; - - /* Then loop again and check if what remains is part of a - * VT100 escape sequence. We could speed this up by - * checking if st->seq[0] == ASCII_ESC. - */ - } - break; - } - } - while (state == VT100_ABORT); -#else - /* Just output the character */ - - fbcon_putc(st, ch); -#endif /* CONFIG_EXAMPLES_FBCON_VT100_DECODE */ - } - - fbcon_showcursor(st); -} - -/**************************************************************************** - * Name: fbdev_get_pinfo - * - * Description: - * Get plane information for a framebuffer - * Note - does not support dual framebuffer memory - * - * Input Parameters: - * fd - file descriptor of the framebuffer - * pinfo - pointer to the3 structure for the plane info - * - * Returned Value: - * OK - * - ****************************************************************************/ - -static int fbdev_get_pinfo(int fd, FAR struct fb_planeinfo_s *pinfo) -{ - if (ioctl(fd, FBIOGET_PLANEINFO, (unsigned long)((uintptr_t)pinfo)) < 0) - { - int errcode = errno; - gerr("ERROR: ioctl(FBIOGET_PLANEINFO) failed: %d\n", errcode); - return EXIT_FAILURE; - } - - /* Only these pixel depths are supported. viinfo.fmt is ignored, only - * certain color formats are supported. - */ - - if (pinfo->bpp != 32 && pinfo->bpp != 24 && - pinfo->bpp != 16 && pinfo->bpp != 8 && - pinfo->bpp != 1) - { - gerr("ERROR: bpp=%u not supported\n", pinfo->bpp); - return EXIT_FAILURE; - } - - return OK; -} - -#if 0 -/* Revisit needed = no support for dual framebuffers yet */ - -/**************************************************************************** - * Name: fb_init_mem2 - * - * Description: - * Initialise the memory for the second framebuffer - * - * Input Parameters: - * st - pointer to FBCON status structure - * - * Returned Value: - * OK - * - ****************************************************************************/ - -static int fb_init_mem2(FAR struct fbcon_state_s *st) -{ - int ret; - uintptr_t buf_offset; - struct fb_planeinfo_s pinfo; - - memset(&pinfo, 0, sizeof(pinfo)); - pinfo.display = st->pinfo->display + 1; - - if ((ret = fbdev_get_pinfo(st->fd_fb, &pinfo)) < 0) - { - return EXIT_FAILURE; - } - - /* Check bpp */ - - if (pinfo.bpp != st->pinfo->bpp) - { - gerr("ERROR: fbmem2 is incorrect"); - return -EINVAL; - } - - /* Check the buffer address offset, - * It needs to be divisible by pinfo->stride - */ - - buf_offset = pinfo.fbmem - st->fbmem; - - if ((buf_offset % st->pinfo->stride) != 0) - { - gerr("ERROR: It is detected that buf_offset(%" PRIuPTR ") " - "and stride(%d) are not divisible, please ensure " - "that the driver handles the address offset by itself.\n", - buf_offset, st->pinfo->stride); - } - - /* Calculate the address and yoffset of fbmem2 */ - - if (buf_offset == 0) - { - /* Use consecutive fbmem2. */ - - st->mem2_yoffset = st->vinfo->yres; - st->fbmem2 = pinfo.fbmem + st->mem2_yoffset * pinfo.stride; - gerr("ERROR: Use consecutive fbmem2 = %p, yoffset = %" PRIu32"\n", - st->fbmem2, st->mem2_yoffset); - } - else - { - /* Use non-consecutive fbmem2. */ - - st->mem2_yoffset = buf_offset / st->pinfo->stride; - st->fbmem2 = pinfo.fbmem; - gerr("ERROR: Use non-consecutive fbmem2 = %p, yoffset = %" PRIu32"\n", - st->fbmem2, st->mem2_yoffset); - } - - return OK; -} -#endif - -/**************************************************************************** - * Name: fbcon_initialize - * - * Description: - * Initialise the Framebuffer Console - * - * Input Parameters: - * st - pointer to FBCON status structure - * - * Returned Value: - * Success or failure code - * - ****************************************************************************/ - -static int fbcon_initialize(FAR struct fbcon_state_s *st) -{ - struct nxgl_rect_s rect; - FAR const struct nx_font_s *fontset; - int ret; - - /* Get the configured font handles */ - - st->fbcon_font = nxf_getfonthandle(FBCON_FONTID); - if (!st->fbcon_font) - { - gerr("ERROR: fbcon_main: Failed to get console font handle: %d\n", - errno); - return FBCON_EXIT_FONTOPEN; - } - - st->bcolor = FBCON_BGCOLOR; - st->fcolor = FBCON_FCOLOR; - - rect.pt1.x = 0; - rect.pt1.y = 0; - rect.pt2.x = st->vinfo->xres - 1; - rect.pt2.y = st->vinfo->yres - 1; - ret = fbcon_fill(st, &rect, &st->bcolor); - if (ret < 0) - { - gerr("ERROR: fbcon_main: fbcon_setbgcolor failed: %d\n", errno); - return FBCON_EXIT_SETBGCOLOR; - } - - fontset = nxf_getfontset(st->fbcon_font); - st->fheight = fontset->mxheight; - st->fwidth = fontset->mxwidth; - st->spwidth = fontset->spwidth; - - /* we use the entire LCD area for the console */ - - st->wsize.h = st->vinfo->yres; - st->wsize.w = st->vinfo->xres; - - st->cursor.code = FBCON_CURSORCHAR; - if (FBCON_CURSORCHAR != ASCII_SPACE) - { - st->cursor.flags = 0; - } - else - { - st->cursor.flags = BMFLAGS_NOGLYPH; - } - - st->nchars = 0; - st->maxglyphs = FBCON_GLCACHE; - - /* The first character is one space from the left - * and FBCON_LINESEPARATION lines from the top - */ - - st->cursor.pos.x = st->spwidth; - st->cursor.pos.y = FBCON_LINESPACING; - st->maxchars = (st->wsize.w / st->fwidth) * - (st->wsize.h / (st->fheight + FBCON_LINESPACING) - 1); - - st->bm = malloc(st->maxchars * sizeof(struct fbcon_bitmap_s)); - if (st->bm == NULL) - { - gerr("ERROR: Unable to allocate display buffer memory"); - return -ENOMEM; - } - - memset(st->bm, 0, st->maxchars * sizeof(struct fbcon_bitmap_s)); - - st->glyph = malloc(FBCON_GLCACHE * (sizeof(struct fbcon_glyph_s))); - if (st->glyph == NULL) - { - gerr("ERROR: Unable to allocate glyph cache memory"); - return -ENOMEM; - } - - memset(st->glyph, 0, FBCON_GLCACHE * (sizeof(struct fbcon_glyph_s))); - - st->nseq = 0; - - return OK; -} - -/**************************************************************************** - * Name: has_input - * - * Description: - * Return true if a File Descriptor has data to be read. - * - * Input Parameters: - * fd - File Descriptor to be checked - * - * Returned Value: - * True if File Descriptor has data to be read; False otherwise - * - ****************************************************************************/ - -static bool has_input(int fd) -{ - int ret; - - /* Poll the File Descriptor for input */ - - struct pollfd fdp; - fdp.fd = fd; - fdp.events = POLLIN; - ret = poll(&fdp, /* File Descriptors */ - 1, /* Number of File Descriptors */ - 0); /* Poll Timeout (Milliseconds) */ - - if (ret > 0) - { - /* If poll is OK and there is input */ - - if ((fdp.revents & POLLIN) != 0) - { - /* Report that there is input */ - - return true; - } - - /* Else report no input */ - - return false; - } - else if (ret == 0) - { - /* If timeout, report no input */ - - return false; - } - else if (ret < 0) - { - /* Handle error */ - - fprintf(stderr, "poll failed: %d, fd=%d\n", ret, fd); - return false; - } - - /* Never comes here */ - - assert(false); - return false; -} - -/**************************************************************************** - * Name: poll_std_streams - * - * Description: - * Poll NSH stdout and stderr for output and display the output. - * - * Input Parameters: - * st - pointer to FBCON status structure - * - * Returned Value: - * None - * - ****************************************************************************/ - -static void poll_std_streams(FAR struct fbcon_state_s *st) -{ - ssize_t num_ch; - static char buf[POLL_BUFSIZE]; - - assert(g_nsh_stdout[READ_PIPE] != 0); - assert(g_nsh_stderr[READ_PIPE] != 0); -#ifdef CONFIG_EXAMPLES_FBCON_PIPE_STDIN - assert(g_nsh_stdin[READ_PIPE] != 0); -#endif - -#ifdef CONFIG_EXAMPLES_FBCON_PIPE_STDERR - /* Poll NSH stderr to check if there's output to be processed */ - - if (has_input(g_nsh_stderr[READ_PIPE])) - { - /* Write it to display */ - - num_ch = read(g_nsh_stderr[READ_PIPE], buf, POLL_BUFSIZE); - if (num_ch > 0) - { - /* display */ - - fbcon_write(st, buf, num_ch); - } - } -#endif /* CONFIG_EXAMPLES_FBCON_PIPE_STDERR */ - -#ifdef CONFIG_EXAMPLES_FBCON_PIPE_STDOUT - /* Poll NSH stdout to check if there's output to be processed */ - - if (has_input(g_nsh_stdout[READ_PIPE])) - { - /* Read the output from NSH stdout */ - - num_ch = read(g_nsh_stdout[READ_PIPE], buf, POLL_BUFSIZE); - if (num_ch > 0) - { - /* Write it to display */ - - fbcon_write(st, buf, num_ch); - } - } -#endif /* CONFIG_EXAMPLES_FBCON_PIPE_STDOUT */ - -#ifdef CONFIG_EXAMPLES_FBCON_PIPE_STDIN - if (has_input(STDIN_FILENO)) - { - /* Get and process a character */ - - ssize_t num = 0; - char ch; - num_ch = read(STDIN_FILENO, &ch, 1); - - if (num_ch != 1) - { - fprintf(stderr, "STDIN read failed\n"); - return; - } - - /* copy it to spawned app/process */ - - num = write(g_nsh_stdin[WRITE_PIPE], &ch, 1); - if (num != num_ch) - { - fprintf(stderr, "STDIN write failed\n"); - return; - } - -# if defined(CONFIG_NSH_READLINE) - fbcon_write(st, buf, num_ch); -# elif defined(CONFIG_NSH_CLE) - if (ch == ASCII_LF) - { - fbcon_write(st, &ch, 1); - } -# endif - } -#endif /* CONFIG_EXAMPLES_FBCON_PIPE_STDIN */ -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: fbcon_main - * - * Description: - * fbcon entry point - * - ****************************************************************************/ - -int main(int argc, FAR char *argv[]) -{ - FAR struct fbcon_state_s *st; - int index; - int ret; - pid_t pid; - posix_spawn_file_actions_t actions; - posix_spawnattr_t attr; - FAR const struct builtin_s *builtin; - int exitcode = FBCON_EXIT_SUCCESS; - FAR const char *fbdev = CONFIG_EXAMPLES_FBCON_DEF_FB; - - /* There is a single optional argument: The path to the framebuffer - * driver. - */ - - if (argc == 2) - { - fbdev = argv[1]; - } - else if (argc != 1) - { - fprintf(stderr, "ERROR: Single argument required\n"); - fprintf(stderr, "USAGE: %s [<fb-driver-path>]\n", argv[0]); - return FBCON_EXIT_FAIL; - } - - st = malloc(sizeof(struct fbcon_state_s)); - if (st == NULL) - { - gerr("ERROR: Unable to allocate fbcon_state_s memory"); - return -ENOMEM; - } - - st->pinfo = malloc(sizeof(struct fb_planeinfo_s)); - if (st->pinfo == NULL) - { - gerr("ERROR: Unable to allocate pinfo memory"); - return -ENOMEM; - } - - st->vinfo = malloc(sizeof(struct fb_videoinfo_s)); - if (st->vinfo == NULL) - { - gerr("ERROR: Unable to allocate vinfo memory"); - return -ENOMEM; - } - - /* Open the framebuffer driver */ - - st->fd_fb = open(fbdev, O_RDWR); - if (st->fd_fb < 0) - { - int errcode = errno; - gerr("ERROR: Failed to open %s: %d\n", fbdev, errcode); - return FBCON_EXIT_FD; - } - - /* Get the characteristics of the framebuffer */ - - ret = ioctl(st->fd_fb, FBIOGET_VIDEOINFO, - (unsigned long)((uintptr_t)st->vinfo)); - if (ret < 0) - { - int errcode = errno; - fprintf(stderr, "ERROR: ioctl(FBIOGET_VIDEOINFO) failed: %d\n", - errcode); - exitcode = FBCON_EXIT_GETVINFO; - goto errout; - } - -#ifdef CONFIG_FB_OVERLAY - gerr("ERROR: noverlays: %u\n", st->vinfo->noverlays); - - /* Select the first overlay, which should be the composed framebuffer */ - - ret = ioctl(st->fd_fb, FBIO_SELECT_OVERLAY, 0); - if (ret < 0) - { - int errcode = errno; - gerr("ERROR: ioctl(FBIO_SELECT_OVERLAY) failed: %d\n", errcode); - ret = FBCON_EXIT_FBIO_SELECT_OVERLAY - goto errout; - } - - /* Get the first overlay information */ - - st->oinfo.overlay = 0; - ret = ioctl(st->fd_fb, FBIOGET_OVERLAYINFO, - (unsigned long)((uintptr_t)&st->oinfo)); - if (ret < 0) - { - int errcode = errno; - gerr("ERROR: ioctl(FBIOGET_OVERLAYINFO) failed: %d\n", errcode); - ret = FBCON_EXIT_FBIO_OVERLAY_INFO - goto errout; - } - - /* select default framebuffer layer */ - - ret = ioctl(st->fd_fb, FBIO_SELECT_OVERLAY, FB_NO_OVERLAY); - if (ret < 0) - { - int errcode = errno; - gerr("ERROR: ioctl(FBIO_SELECT_OVERLAY) failed: %d\n", errcode); - ret = FBCON_EXIT_FBIO_SELECT_OVERLAY - goto errout; - } - -#endif - - if ((ret = fbdev_get_pinfo(st->fd_fb, st->pinfo)) < 0) - { - ret = FBCON_EXIT_GETPINFO; - goto errout; - } - - /* mmap() the framebuffer. - * - * NOTE: In the FLAT build the frame buffer address returned by the - * FBIOGET_PLANEINFO IOCTL command will be the same as the framebuffer - * address. mmap(), however, is the preferred way to get the framebuffer - * address because in the KERNEL build, it will perform the necessary - * address mapping to make the memory accessible to the application. - */ - - st->fbmem = mmap(NULL, st->pinfo->fblen, PROT_READ | PROT_WRITE, - MAP_SHARED | MAP_FILE, st->fd_fb, 0); - if (st->fbmem == MAP_FAILED) - { - gerr("ERROR: ioctl(FBIOGET_PLANEINFO) failed: %d\n", errno); - ret = FBCON_EXIT_FBMEM; - goto errout; - } - -#if 0 - /* Revisit needed = no support for dual framebuffers yet */ - - if (st->pinfo->yres_virtual == (st->vinfo->yres * 2)) - { - if ((ret = fb_init_mem2(st)) < 0) - { - ret = FBCON_EXIT_FBMEM2; - goto errout; - } - } - -#endif - ret = fbcon_initialize(st); - if (ret != OK) - { - exitcode = ret; - goto errout; - } - - fbcon_home(st); - fbcon_showcursor(st); - - /* Pipe and duplicate STDOUT and/or STDERR */ - -#ifdef CONFIG_EXAMPLES_FBCON_PIPE_STDOUT - ret = pipe(g_nsh_stdout); - if (ret < 0) - { - _err("stdout pipe failed: %d\n", errno); - return ERROR; - } - - close(STDOUT_FILENO); - dup2(g_nsh_stdout[WRITE_PIPE], 1); -#endif -#ifdef CONFIG_EXAMPLES_FBCON_PIPE_STDERR - ret = pipe(g_nsh_stderr); - if (ret < 0) - { - _err("stderr pipe failed: %d\n", errno); - return ERROR; - } - - close(STDERR_FILENO); - dup2(g_nsh_stderr[WRITE_PIPE], 2); -#endif - - ret = posix_spawn_file_actions_init(&actions); - if (ret != 0) - { - gerr("ERROR: unable to init spawn sctiond for" - "requested task " "\"""%s""\"" ".\n", SPAWN_TASK); - exitcode = FBCON_EXIT_POSIX_SPAWN_ACTIONS_INIT_FAILED; - goto errout; - } - -#ifdef CONFIG_EXAMPLES_FBCON_PIPE_STDIN - /* Spawned app/task may need to intercept and forward STDIN - * otherwise any waiting input characters can be missed if read by the - * spawned app/task first. - */ - - ret = pipe(g_nsh_stdin); - if (ret < 0) - { - gerr("ERROR: stdin pipe failed: %d\n", errno); - exitcode = FBCON_EXIT_STDIN_PIPE_FAILED; - goto errout; - } - - posix_spawn_file_actions_addclose(&actions, STDIN_FILENO); - posix_spawn_file_actions_adddup2(&actions, g_nsh_stdin[READ_PIPE], - STDIN_FILENO); - -#endif /* CONFIG_EXAMPLES_FBCON_PIPE_STDIN */ - - index = builtin_isavail(SPAWN_TASK); - if (index < 0) - { - gerr("ERROR: requested task " "\"""%s""\"" " not available.\n", - SPAWN_TASK); - exitcode = FBCON_EXIT_APP_INDEX_UNAVAILABLE; - goto errout; - } - - builtin = builtin_for_index(index); - if (builtin == NULL) - { - gerr("ERROR: requested task " "\"""%s""\"" - " has no scheduling parameters.\n", SPAWN_TASK); - exitcode = FBCON_EXIT_APP_INDEX_UNAVAILABLE; - goto errout; - } - - /* Set up for app/task spawn */ - - ret = posix_spawnattr_init(&attr); - if (ret != 0) - { - gerr("ERROR: unable to init spawn attributes for" - "requested task " "\"""%s""\"" ".\n", SPAWN_TASK); - exitcode = FBCON_EXIT_APP_POSIX_ATTRIB_INIT_FAILED; - goto errout; - } - - attr.stacksize = builtin->stacksize; - attr.priority = builtin->priority; - - /* Spawn required application */ - - ret = posix_spawn(&pid, /* Returned Task ID */ - SPAWN_TASK, /* Task Path */ - &actions, /* Replace STDIN and/or STDOUT and/or STDIN */ - &attr, /* Attributes of app/task */ - NULL, /* Arguments */ - NULL); /* No environment */ - if (ret < 0) - { - int errcode = errno; - gerr("ERROR: posix_spawn failed: %d\n", errcode); - exitcode = FBCON_EXIT_POSIX_SPAWN_FAILED; - } - -#ifdef CONFIG_EXAMPLES_FBCON_SHOW_WELCOME -# ifdef CONFIG_EXAMPLES_FBCON_PIPE_STDOUT - fprintf(stdout, "%s\n", g_stdout_hello); - fflush(stdout); -# endif -# ifdef CONFIG_EXAMPLES_FBCON_PIPE_STDERR - fprintf(stderr, "%s\n", g_stderr_hello); - fflush(stderr); -# endif -#endif - - for (; ; ) - { - poll_std_streams(st); - usleep(10000); - } - -errout: - close(st->fd_fb); - fprintf(stderr, "FBCON exiting with error %d\n", exitcode); - return exitcode; -} diff --git a/examples/fboverlay/CMakeLists.txt b/examples/fboverlay/CMakeLists.txt deleted file mode 100644 index 0a90f9ab4..000000000 --- a/examples/fboverlay/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# ############################################################################## -# apps/examples/fboverlay/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_FBOVERLAY) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_FBOVERLAY_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_FBOVERLAY_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_FBOVERLAY_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_FBOVERLAY} - SRCS - fboverlay_main.c) -endif() diff --git a/examples/fboverlay/Make.defs b/examples/fboverlay/Make.defs index 62ea27755..0fc92aaa6 100644 --- a/examples/fboverlay/Make.defs +++ b/examples/fboverlay/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/fboverlay/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/fboverlay/Makefile b/examples/fboverlay/Makefile index d68057f25..9c80d122c 100644 --- a/examples/fboverlay/Makefile +++ b/examples/fboverlay/Makefile @@ -1,7 +1,5 @@ ############################################################################ -# apps/examples/fboverlay/Makefile -# -# SPDX-License-Identifier: Apache-2.0 +# apps/graphics/fboverlay/Makefile # # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with diff --git a/examples/fboverlay/fboverlay_main.c b/examples/fboverlay/fboverlay_main.c index f71e17e9b..362e72b2a 100644 --- a/examples/fboverlay/fboverlay_main.c +++ b/examples/fboverlay/fboverlay_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/fboverlay/fboverlay_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -32,8 +30,6 @@ #include <sys/ioctl.h> #include <sys/mman.h> #include <errno.h> -#include <unistd.h> - #include <nuttx/video/fb.h> #include <nuttx/config.h> @@ -117,8 +113,8 @@ static uint16_t rgb565(uint32_t argb) ****************************************************************************/ #ifdef CONFIG_FB_CMAP -static void draw_rect8(FAR void *fbmem, FAR struct fb_overlayinfo_s *oinfo, - FAR const struct fb_area_s *area, uint8_t color) +static void draw_rect8(FAR void *fbmem, FAR struct fb_overlayinfo_s * oinfo, + FAR const struct fb_area_s * area, uint8_t color) { FAR uint8_t *dest; FAR uint8_t *row; @@ -156,8 +152,8 @@ static void draw_rect8(FAR void *fbmem, FAR struct fb_overlayinfo_s *oinfo, * ****************************************************************************/ -static void draw_rect16(FAR void *fbmem, FAR struct fb_overlayinfo_s *oinfo, - FAR const struct fb_area_s *area, uint16_t rgb) +static void draw_rect16(FAR void *fbmem, FAR struct fb_overlayinfo_s * oinfo, + FAR const struct fb_area_s * area, uint16_t rgb) { FAR uint16_t *dest; FAR uint8_t *row; @@ -194,8 +190,8 @@ static void draw_rect16(FAR void *fbmem, FAR struct fb_overlayinfo_s *oinfo, * ****************************************************************************/ -static void draw_rect24(FAR void *fbmem, FAR struct fb_overlayinfo_s *oinfo, - FAR const struct fb_area_s *area, uint32_t rgb) +static void draw_rect24(FAR void *fbmem, FAR struct fb_overlayinfo_s * oinfo, + FAR const struct fb_area_s * area, uint32_t rgb) { int x; int y; @@ -242,8 +238,8 @@ static void draw_rect24(FAR void *fbmem, FAR struct fb_overlayinfo_s *oinfo, * ****************************************************************************/ -static void draw_rect32(FAR void *fbmem, FAR struct fb_overlayinfo_s *oinfo, - FAR const struct fb_area_s *area, uint32_t argb) +static void draw_rect32(FAR void *fbmem, FAR struct fb_overlayinfo_s * oinfo, + FAR const struct fb_area_s * area, uint32_t argb) { int x; int y; @@ -505,7 +501,7 @@ static void print_overlay_info(int fb, uint8_t overlayno) ****************************************************************************/ static int overlay_fill(int fb, uint8_t overlayno, uint32_t color, - FAR const struct fb_area_s *area) + FAR const struct fb_area_s * area) { int ret; FAR void *fbmem; diff --git a/examples/fdpicxip/CMakeLists.txt b/examples/fdpicxip/CMakeLists.txt deleted file mode 100644 index 2af0fc4a8..000000000 --- a/examples/fdpicxip/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -# ############################################################################## -# apps/examples/fdpicxip/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_FDPICXIP) - nuttx_add_application(NAME fdpicxip SRCS fdpicxip_main.c) -endif() diff --git a/examples/fdpicxip/Kconfig b/examples/fdpicxip/Kconfig deleted file mode 100644 index 6de10e005..000000000 --- a/examples/fdpicxip/Kconfig +++ /dev/null @@ -1,39 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config EXAMPLES_FDPICXIP - tristate "FDPIC modules executed in place from xipfs demo" - depends on FS_XIPFS && FDPIC && LIBC_EXECFUNCS - default n - ---help--- - Write FDPIC modules into xipfs at run time, the way a download - would, then run them. Their text is executed directly out of - flash and shared between concurrent instances, while each - instance gets its own data. - - Subcommands: - - qsort one self-contained module, two instances - solib a shared library across two instances - cxx the same in C++, checking global constructors ran - jmprel a module whose imports are all in DT_JMPREL - - With no subcommand, qsort runs. - - The modules are embedded in the image as C headers. Their - sources are in modules/, which rebuilds the headers on an - explicit 'make regen': linking one needs arm-uclinuxfdpiceabi - binutils, which this build does not. - - This demonstrates; it does not assert. For the assertions see - the fdpic and reject sections of CONFIG_TESTING_FS_XIPFS. - -if EXAMPLES_FDPICXIP - -config EXAMPLES_FDPICXIP_MOUNTPT - string "xipfs mountpoint" - default "/mnt/xipfs" - -endif # EXAMPLES_FDPICXIP diff --git a/examples/fdpicxip/Make.defs b/examples/fdpicxip/Make.defs deleted file mode 100644 index 88acd75f8..000000000 --- a/examples/fdpicxip/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/examples/fdpicxip/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_EXAMPLES_FDPICXIP),) -CONFIGURED_APPS += $(APPDIR)/examples/fdpicxip -endif diff --git a/examples/fdpicxip/Makefile b/examples/fdpicxip/Makefile deleted file mode 100644 index 05f90116c..000000000 --- a/examples/fdpicxip/Makefile +++ /dev/null @@ -1,37 +0,0 @@ -############################################################################ -# apps/examples/fdpicxip/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -# FDPIC modules executed in place from xipfs. The modules are embedded as -# headers, built from the sources in modules/ by an explicit 'make regen' -# there: linking one needs arm-uclinuxfdpiceabi binutils, which this build -# does not. - -MAINSRC = fdpicxip_main.c - -PROGNAME = fdpicxip -PRIORITY = SCHED_PRIORITY_DEFAULT -STACKSIZE = $(CONFIG_DEFAULT_TASK_STACKSIZE) -MODULE = $(CONFIG_EXAMPLES_FDPICXIP) - -include $(APPDIR)/Application.mk diff --git a/examples/fdpicxip/cxxuser_bin.h b/examples/fdpicxip/cxxuser_bin.h deleted file mode 100644 index 8baafab00..000000000 --- a/examples/fdpicxip/cxxuser_bin.h +++ /dev/null @@ -1,400 +0,0 @@ -/**************************************************************************** - * apps/examples/fdpicxip/cxxuser_bin.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/* Generated from cxxuser.fdpic -- do not edit. - * - * An FDPIC module, embedded so the demo has something to load without - * needing a filesystem populated from the host first. - */ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -static const unsigned char g_cxxuser[] = -{ - 0x7f, 0x45, 0x4c, 0x46, 0x01, 0x01, 0x01, 0x41, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x28, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x81, 0x04, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x30, 0x0e, 0x00, 0x00, - 0x00, 0x02, 0x00, 0x05, 0x34, 0x00, 0x20, 0x00, 0x04, 0x00, 0x28, 0x00, - 0x12, 0x00, 0x11, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x06, 0x00, 0x00, - 0xf0, 0x06, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0xf0, 0x06, 0x00, 0x00, 0xf0, 0x16, 0x00, 0x00, - 0xf0, 0x16, 0x00, 0x00, 0x14, 0x01, 0x00, 0x00, 0x1c, 0x01, 0x00, 0x00, - 0x06, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, - 0xf4, 0x06, 0x00, 0x00, 0xf4, 0x16, 0x00, 0x00, 0xf4, 0x16, 0x00, 0x00, - 0xa0, 0x00, 0x00, 0x00, 0xa0, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, 0x51, 0xe5, 0x74, 0x64, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x80, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, 0x16, 0x00, 0x00, 0x00, 0x15, 0x00, 0x00, 0x00, - 0x11, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x09, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, - 0x0c, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, - 0x0e, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x90, 0x03, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x80, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x06, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x44, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0xec, 0x06, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x94, 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x0b, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x04, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x0c, 0x00, 0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0x4e, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, - 0x3b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, - 0x5c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, 0x66, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x8f, 0x00, 0x00, 0x00, - 0xf0, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x08, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x81, 0x04, 0x00, 0x00, 0xa8, 0x01, 0x00, 0x00, - 0x12, 0x00, 0x06, 0x00, 0x7e, 0x00, 0x00, 0x00, 0xec, 0x06, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x08, 0x00, 0x2a, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, - 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, 0x57, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, - 0x6c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x61, 0x74, - 0x6f, 0x69, 0x00, 0x73, 0x68, 0x61, 0x70, 0x65, 0x5f, 0x6d, 0x61, 0x72, - 0x6b, 0x65, 0x72, 0x00, 0x73, 0x68, 0x61, 0x70, 0x65, 0x5f, 0x63, 0x6f, - 0x6e, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x65, 0x64, 0x00, 0x73, 0x79, - 0x73, 0x6c, 0x6f, 0x67, 0x00, 0x73, 0x68, 0x61, 0x70, 0x65, 0x5f, 0x61, - 0x64, 0x64, 0x00, 0x75, 0x73, 0x6c, 0x65, 0x65, 0x70, 0x00, 0x73, 0x68, - 0x61, 0x70, 0x65, 0x5f, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x00, 0x73, 0x6e, - 0x70, 0x72, 0x69, 0x6e, 0x74, 0x66, 0x00, 0x6f, 0x70, 0x65, 0x6e, 0x00, - 0x66, 0x74, 0x72, 0x75, 0x6e, 0x63, 0x61, 0x74, 0x65, 0x00, 0x77, 0x72, - 0x69, 0x74, 0x65, 0x00, 0x63, 0x6c, 0x6f, 0x73, 0x65, 0x00, 0x6c, 0x69, - 0x62, 0x73, 0x68, 0x61, 0x70, 0x65, 0x2e, 0x73, 0x6f, 0x00, 0x5f, 0x5f, - 0x52, 0x4f, 0x46, 0x49, 0x58, 0x55, 0x50, 0x5f, 0x4c, 0x49, 0x53, 0x54, - 0x5f, 0x5f, 0x00, 0x5f, 0x5f, 0x52, 0x4f, 0x46, 0x49, 0x58, 0x55, 0x50, - 0x5f, 0x45, 0x4e, 0x44, 0x5f, 0x5f, 0x00, 0x00, 0xf0, 0x16, 0x00, 0x00, - 0x17, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00, - 0xa0, 0x17, 0x00, 0x00, 0xa4, 0x07, 0x00, 0x00, 0xa8, 0x17, 0x00, 0x00, - 0xa4, 0x08, 0x00, 0x00, 0xb0, 0x17, 0x00, 0x00, 0xa4, 0x09, 0x00, 0x00, - 0xb8, 0x17, 0x00, 0x00, 0xa4, 0x0a, 0x00, 0x00, 0xc0, 0x17, 0x00, 0x00, - 0xa4, 0x0b, 0x00, 0x00, 0xc8, 0x17, 0x00, 0x00, 0xa4, 0x0c, 0x00, 0x00, - 0xd0, 0x17, 0x00, 0x00, 0xa4, 0x0d, 0x00, 0x00, 0xd8, 0x17, 0x00, 0x00, - 0xa4, 0x11, 0x00, 0x00, 0xe0, 0x17, 0x00, 0x00, 0xa4, 0x12, 0x00, 0x00, - 0xe8, 0x17, 0x00, 0x00, 0xa4, 0x13, 0x00, 0x00, 0xf0, 0x17, 0x00, 0x00, - 0xa4, 0x14, 0x00, 0x00, 0xf8, 0x17, 0x00, 0x00, 0xa4, 0x15, 0x00, 0x00, - 0xdf, 0xf8, 0x0c, 0xc0, 0x0c, 0xeb, 0x09, 0x0c, 0xdc, 0xf8, 0x04, 0x90, - 0xdc, 0xf8, 0x00, 0xf0, 0x0c, 0x00, 0x00, 0x00, 0xdf, 0xf8, 0x0c, 0xc0, - 0x0c, 0xeb, 0x09, 0x0c, 0xdc, 0xf8, 0x04, 0x90, 0xdc, 0xf8, 0x00, 0xf0, - 0x14, 0x00, 0x00, 0x00, 0xdf, 0xf8, 0x0c, 0xc0, 0x0c, 0xeb, 0x09, 0x0c, - 0xdc, 0xf8, 0x04, 0x90, 0xdc, 0xf8, 0x00, 0xf0, 0x1c, 0x00, 0x00, 0x00, - 0xdf, 0xf8, 0x0c, 0xc0, 0x0c, 0xeb, 0x09, 0x0c, 0xdc, 0xf8, 0x04, 0x90, - 0xdc, 0xf8, 0x00, 0xf0, 0x24, 0x00, 0x00, 0x00, 0xdf, 0xf8, 0x0c, 0xc0, - 0x0c, 0xeb, 0x09, 0x0c, 0xdc, 0xf8, 0x04, 0x90, 0xdc, 0xf8, 0x00, 0xf0, - 0x2c, 0x00, 0x00, 0x00, 0xdf, 0xf8, 0x0c, 0xc0, 0x0c, 0xeb, 0x09, 0x0c, - 0xdc, 0xf8, 0x04, 0x90, 0xdc, 0xf8, 0x00, 0xf0, 0x34, 0x00, 0x00, 0x00, - 0xdf, 0xf8, 0x0c, 0xc0, 0x0c, 0xeb, 0x09, 0x0c, 0xdc, 0xf8, 0x04, 0x90, - 0xdc, 0xf8, 0x00, 0xf0, 0x3c, 0x00, 0x00, 0x00, 0xdf, 0xf8, 0x0c, 0xc0, - 0x0c, 0xeb, 0x09, 0x0c, 0xdc, 0xf8, 0x04, 0x90, 0xdc, 0xf8, 0x00, 0xf0, - 0x44, 0x00, 0x00, 0x00, 0xdf, 0xf8, 0x0c, 0xc0, 0x0c, 0xeb, 0x09, 0x0c, - 0xdc, 0xf8, 0x04, 0x90, 0xdc, 0xf8, 0x00, 0xf0, 0x4c, 0x00, 0x00, 0x00, - 0xdf, 0xf8, 0x0c, 0xc0, 0x0c, 0xeb, 0x09, 0x0c, 0xdc, 0xf8, 0x04, 0x90, - 0xdc, 0xf8, 0x00, 0xf0, 0x54, 0x00, 0x00, 0x00, 0xdf, 0xf8, 0x0c, 0xc0, - 0x0c, 0xeb, 0x09, 0x0c, 0xdc, 0xf8, 0x04, 0x90, 0xdc, 0xf8, 0x00, 0xf0, - 0x5c, 0x00, 0x00, 0x00, 0xdf, 0xf8, 0x0c, 0xc0, 0x0c, 0xeb, 0x09, 0x0c, - 0xdc, 0xf8, 0x04, 0x90, 0xdc, 0xf8, 0x00, 0xf0, 0x64, 0x00, 0x00, 0x00, - 0x2d, 0xe9, 0xf0, 0x45, 0x01, 0x28, 0x4c, 0x46, 0x80, 0x46, 0x0f, 0x46, - 0x89, 0xb0, 0x40, 0xf3, 0x8e, 0x80, 0x48, 0x68, 0xff, 0xf7, 0xcc, 0xff, - 0xb8, 0xf1, 0x02, 0x0f, 0xa1, 0x46, 0x06, 0x46, 0x03, 0xd0, 0xb8, 0x68, - 0xff, 0xf7, 0xd8, 0xff, 0xa1, 0x46, 0x52, 0x4b, 0x4f, 0x4d, 0x59, 0xf8, - 0x03, 0x30, 0x1b, 0x68, 0xab, 0x42, 0x7c, 0xd1, 0xdf, 0xf8, 0x3c, 0xa1, - 0xfa, 0x44, 0xff, 0xf7, 0x8f, 0xff, 0xa1, 0x46, 0x00, 0x28, 0x78, 0xd0, - 0x4c, 0x4b, 0x7b, 0x44, 0x49, 0x4a, 0x59, 0xf8, 0x02, 0x20, 0x12, 0x79, - 0x00, 0x2a, 0x73, 0xd0, 0x49, 0x4a, 0x7a, 0x44, 0x49, 0x49, 0xcd, 0xe9, - 0x00, 0x32, 0x06, 0x20, 0x53, 0x46, 0x32, 0x46, 0x79, 0x44, 0xff, 0xf7, - 0x97, 0xff, 0xa1, 0x46, 0x40, 0x4b, 0x59, 0xf8, 0x03, 0x30, 0x1b, 0x68, - 0x5d, 0x1b, 0x18, 0xbf, 0x01, 0x25, 0xff, 0xf7, 0x6f, 0xff, 0xa1, 0x46, - 0x08, 0xb9, 0x45, 0xf0, 0x02, 0x05, 0x3a, 0x4b, 0x59, 0xf8, 0x03, 0x30, - 0x1b, 0x79, 0x0b, 0xb9, 0x45, 0xf0, 0x04, 0x05, 0x4f, 0xf0, 0x03, 0x0a, - 0x34, 0x4b, 0x03, 0x93, 0x30, 0x46, 0xff, 0xf7, 0x35, 0xff, 0x03, 0x98, - 0xa1, 0x46, 0xff, 0xf7, 0x45, 0xff, 0xba, 0xf1, 0x01, 0x0a, 0xa1, 0x46, - 0xf4, 0xd1, 0xff, 0xf7, 0x49, 0xff, 0x06, 0xeb, 0x46, 0x0a, 0xa1, 0x46, - 0x50, 0x45, 0x18, 0xbf, 0x45, 0xf0, 0x08, 0x05, 0xff, 0xf7, 0x40, 0xff, - 0xa1, 0x46, 0x03, 0x46, 0x00, 0x2d, 0x38, 0xd1, 0x2c, 0x4a, 0x7a, 0x44, - 0x2c, 0x49, 0xcd, 0xe9, 0x00, 0xa2, 0x06, 0x20, 0x32, 0x46, 0x79, 0x44, - 0xff, 0xf7, 0x5a, 0xff, 0xb8, 0xf1, 0x03, 0x0f, 0xa1, 0x46, 0x1a, 0xdd, - 0xff, 0x68, 0xc7, 0xb1, 0x26, 0x4a, 0x2b, 0x46, 0x10, 0x21, 0x7a, 0x44, - 0x04, 0xa8, 0xff, 0xf7, 0x11, 0xff, 0x4f, 0xf4, 0xd2, 0x72, 0xa1, 0x46, - 0x82, 0x46, 0x40, 0xf2, 0x41, 0x21, 0x38, 0x46, 0xff, 0xf7, 0x58, 0xff, - 0x06, 0x1e, 0xa1, 0x46, 0x18, 0xda, 0x1e, 0x49, 0x3a, 0x46, 0x06, 0x20, - 0x79, 0x44, 0xff, 0xf7, 0x3b, 0xff, 0x28, 0x46, 0x09, 0xb0, 0xbd, 0xe8, - 0xf0, 0x85, 0x01, 0x26, 0x7b, 0xe7, 0xdf, 0xf8, 0x64, 0xa0, 0xfa, 0x44, - 0x81, 0xe7, 0x18, 0x4b, 0x7b, 0x44, 0x85, 0xe7, 0x17, 0x4a, 0x7a, 0x44, - 0x8a, 0xe7, 0x17, 0x4a, 0x7a, 0x44, 0xc5, 0xe7, 0x51, 0x46, 0xff, 0xf7, - 0x11, 0xff, 0x00, 0x28, 0xa1, 0x46, 0x05, 0xdb, 0x52, 0x46, 0x30, 0x46, - 0x04, 0xa9, 0xff, 0xf7, 0x13, 0xff, 0xa1, 0x46, 0x30, 0x46, 0xff, 0xf7, - 0x41, 0xff, 0xdc, 0xe7, 0x55, 0x1a, 0x0c, 0x00, 0xa0, 0x86, 0x01, 0x00, - 0x6c, 0x00, 0x00, 0x00, 0x84, 0x01, 0x00, 0x00, 0x76, 0x01, 0x00, 0x00, - 0x66, 0x01, 0x00, 0x00, 0x69, 0x01, 0x00, 0x00, 0xf1, 0x00, 0x00, 0x00, - 0x34, 0x01, 0x00, 0x00, 0x4e, 0x01, 0x00, 0x00, 0x2b, 0x01, 0x00, 0x00, - 0x8e, 0x00, 0x00, 0x00, 0x88, 0x00, 0x00, 0x00, 0x82, 0x00, 0x00, 0x00, - 0x84, 0x00, 0x00, 0x00, 0x38, 0xb5, 0x05, 0x4b, 0x59, 0xf8, 0x03, 0x40, - 0x02, 0x4b, 0x23, 0x60, 0xff, 0xf7, 0xd4, 0xfe, 0x20, 0x71, 0x38, 0xbd, - 0x55, 0x1a, 0x0c, 0x00, 0x6c, 0x00, 0x00, 0x00, 0x79, 0x65, 0x73, 0x00, - 0x4e, 0x4f, 0x00, 0x50, 0x41, 0x53, 0x53, 0x00, 0x46, 0x41, 0x49, 0x4c, - 0x00, 0x5b, 0x75, 0x73, 0x65, 0x72, 0x20, 0x25, 0x64, 0x5d, 0x20, 0x6f, - 0x77, 0x6e, 0x20, 0x63, 0x74, 0x6f, 0x72, 0x20, 0x72, 0x61, 0x6e, 0x3a, - 0x20, 0x25, 0x73, 0x2c, 0x20, 0x6c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x79, - 0x20, 0x63, 0x74, 0x6f, 0x72, 0x20, 0x72, 0x61, 0x6e, 0x3a, 0x20, 0x25, - 0x73, 0x2c, 0x20, 0x6c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x79, 0x20, 0x66, - 0x69, 0x72, 0x73, 0x74, 0x3a, 0x20, 0x25, 0x73, 0x0a, 0x00, 0x5b, 0x75, - 0x73, 0x65, 0x72, 0x20, 0x25, 0x64, 0x5d, 0x20, 0x6c, 0x69, 0x62, 0x72, - 0x61, 0x72, 0x79, 0x20, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x20, 0x3d, 0x20, - 0x25, 0x64, 0x20, 0x28, 0x65, 0x78, 0x70, 0x65, 0x63, 0x74, 0x65, 0x64, - 0x20, 0x25, 0x64, 0x29, 0x20, 0x2d, 0x2d, 0x20, 0x25, 0x73, 0x0a, 0x00, - 0x25, 0x64, 0x00, 0x5b, 0x75, 0x73, 0x65, 0x72, 0x5d, 0x20, 0x63, 0x61, - 0x6e, 0x6e, 0x6f, 0x74, 0x20, 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x20, - 0x74, 0x6f, 0x20, 0x25, 0x73, 0x0a, 0x00, 0x00, 0x94, 0x17, 0x00, 0x00, - 0x29, 0x06, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x72, 0x00, 0x00, 0x00, - 0x19, 0x00, 0x00, 0x00, 0xf0, 0x16, 0x00, 0x00, 0x1b, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xb4, 0x00, 0x00, 0x00, - 0x05, 0x00, 0x00, 0x00, 0x80, 0x02, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, - 0x20, 0x01, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x9f, 0x00, 0x00, 0x00, - 0x0b, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, - 0x94, 0x17, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x20, 0x03, 0x00, 0x00, - 0x12, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xfb, 0xff, 0xff, 0x6f, 0x01, 0x00, 0x00, 0x00, 0xfa, 0xff, 0xff, 0x6f, - 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf4, 0x16, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x18, 0x00, 0x00, - 0x47, 0x43, 0x43, 0x3a, 0x20, 0x28, 0x41, 0x72, 0x6d, 0x20, 0x47, 0x4e, - 0x55, 0x20, 0x54, 0x6f, 0x6f, 0x6c, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x20, - 0x31, 0x35, 0x2e, 0x32, 0x2e, 0x52, 0x65, 0x6c, 0x31, 0x20, 0x28, 0x42, - 0x75, 0x69, 0x6c, 0x64, 0x20, 0x61, 0x72, 0x6d, 0x2d, 0x31, 0x35, 0x2e, - 0x38, 0x36, 0x29, 0x29, 0x20, 0x31, 0x35, 0x2e, 0x32, 0x2e, 0x31, 0x20, - 0x32, 0x30, 0x32, 0x35, 0x31, 0x32, 0x30, 0x33, 0x00, 0x41, 0x2c, 0x00, - 0x00, 0x00, 0x61, 0x65, 0x61, 0x62, 0x69, 0x00, 0x01, 0x22, 0x00, 0x00, - 0x00, 0x05, 0x37, 0x2d, 0x4d, 0x00, 0x06, 0x0a, 0x07, 0x4d, 0x09, 0x02, - 0x12, 0x04, 0x14, 0x01, 0x15, 0x01, 0x17, 0x03, 0x18, 0x01, 0x19, 0x01, - 0x1a, 0x01, 0x1e, 0x04, 0x22, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xb4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x80, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x03, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x20, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x90, 0x03, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x80, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x06, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x44, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0xec, 0x06, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xf0, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x09, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xf4, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x94, 0x17, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x04, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x0c, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x0e, 0x00, 0x16, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0xf1, 0xff, - 0x01, 0x00, 0x00, 0x00, 0x80, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x06, 0x00, 0x04, 0x00, 0x00, 0x00, 0xec, 0x05, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x28, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, - 0x07, 0x00, 0x00, 0x00, 0x29, 0x06, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x06, 0x00, 0x04, 0x00, 0x00, 0x00, 0x3c, 0x06, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x04, 0x00, 0x00, 0x00, - 0xf0, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x00, - 0x04, 0x00, 0x00, 0x00, 0x04, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x0c, 0x00, 0x22, 0x00, 0x00, 0x00, 0x04, 0x18, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x2c, 0x00, 0x00, 0x00, - 0x04, 0x18, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x01, 0x00, 0x0c, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x04, 0x00, 0xf1, 0xff, 0x37, 0x00, 0x00, 0x00, 0xf4, 0x16, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0xf1, 0xff, 0x40, 0x00, 0x00, 0x00, - 0x94, 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x0b, 0x00, - 0x04, 0x00, 0x00, 0x00, 0x44, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x07, 0x00, 0x01, 0x00, 0x00, 0x00, 0x90, 0x03, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x04, 0x00, 0x00, 0x00, - 0xa0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, - 0x01, 0x00, 0x00, 0x00, 0xa4, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x05, 0x00, 0x04, 0x00, 0x00, 0x00, 0xb4, 0x03, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x01, 0x00, 0x00, 0x00, - 0xb8, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, - 0x04, 0x00, 0x00, 0x00, 0xc8, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x05, 0x00, 0x01, 0x00, 0x00, 0x00, 0xcc, 0x03, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x04, 0x00, 0x00, 0x00, - 0xdc, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, - 0x01, 0x00, 0x00, 0x00, 0xe0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x05, 0x00, 0x04, 0x00, 0x00, 0x00, 0xf0, 0x03, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x01, 0x00, 0x00, 0x00, - 0xf4, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, - 0x04, 0x00, 0x00, 0x00, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x05, 0x00, 0x01, 0x00, 0x00, 0x00, 0x08, 0x04, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x18, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x1c, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x05, 0x00, 0x04, 0x00, 0x00, 0x00, 0x2c, 0x04, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x30, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, - 0x04, 0x00, 0x00, 0x00, 0x40, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x05, 0x00, 0x01, 0x00, 0x00, 0x00, 0x44, 0x04, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x54, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x58, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x05, 0x00, 0x04, 0x00, 0x00, 0x00, 0x68, 0x04, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x6c, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, - 0x04, 0x00, 0x00, 0x00, 0x7c, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x05, 0x00, 0x56, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, - 0x69, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0x7c, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, - 0x8e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, 0x98, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x9e, 0x00, 0x00, 0x00, - 0xf0, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x08, 0x00, - 0xae, 0x00, 0x00, 0x00, 0x81, 0x04, 0x00, 0x00, 0xa8, 0x01, 0x00, 0x00, - 0x12, 0x00, 0x06, 0x00, 0xb3, 0x00, 0x00, 0x00, 0xec, 0x06, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x08, 0x00, 0xc4, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, - 0xcb, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, 0xd0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0xd5, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, - 0xe2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, 0x00, 0x24, 0x74, 0x00, 0x24, 0x64, 0x00, 0x5f, - 0x47, 0x4c, 0x4f, 0x42, 0x41, 0x4c, 0x5f, 0x5f, 0x73, 0x75, 0x62, 0x5f, - 0x49, 0x5f, 0x63, 0x78, 0x78, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x63, 0x70, - 0x70, 0x00, 0x2e, 0x4c, 0x41, 0x4e, 0x43, 0x48, 0x4f, 0x52, 0x30, 0x00, - 0x5f, 0x5a, 0x4c, 0x36, 0x67, 0x5f, 0x73, 0x65, 0x6c, 0x66, 0x00, 0x5f, - 0x44, 0x59, 0x4e, 0x41, 0x4d, 0x49, 0x43, 0x00, 0x5f, 0x47, 0x4c, 0x4f, - 0x42, 0x41, 0x4c, 0x5f, 0x4f, 0x46, 0x46, 0x53, 0x45, 0x54, 0x5f, 0x54, - 0x41, 0x42, 0x4c, 0x45, 0x5f, 0x00, 0x73, 0x68, 0x61, 0x70, 0x65, 0x5f, - 0x61, 0x64, 0x64, 0x00, 0x73, 0x6e, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x66, - 0x00, 0x75, 0x73, 0x6c, 0x65, 0x65, 0x70, 0x00, 0x73, 0x68, 0x61, 0x70, - 0x65, 0x5f, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x00, 0x73, 0x68, 0x61, 0x70, - 0x65, 0x5f, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x65, - 0x64, 0x00, 0x66, 0x74, 0x72, 0x75, 0x6e, 0x63, 0x61, 0x74, 0x65, 0x00, - 0x77, 0x72, 0x69, 0x74, 0x65, 0x00, 0x5f, 0x5f, 0x52, 0x4f, 0x46, 0x49, - 0x58, 0x55, 0x50, 0x5f, 0x45, 0x4e, 0x44, 0x5f, 0x5f, 0x00, 0x6d, 0x61, - 0x69, 0x6e, 0x00, 0x5f, 0x5f, 0x52, 0x4f, 0x46, 0x49, 0x58, 0x55, 0x50, - 0x5f, 0x4c, 0x49, 0x53, 0x54, 0x5f, 0x5f, 0x00, 0x73, 0x79, 0x73, 0x6c, - 0x6f, 0x67, 0x00, 0x61, 0x74, 0x6f, 0x69, 0x00, 0x6f, 0x70, 0x65, 0x6e, - 0x00, 0x73, 0x68, 0x61, 0x70, 0x65, 0x5f, 0x6d, 0x61, 0x72, 0x6b, 0x65, - 0x72, 0x00, 0x63, 0x6c, 0x6f, 0x73, 0x65, 0x00, 0x00, 0x2e, 0x73, 0x79, - 0x6d, 0x74, 0x61, 0x62, 0x00, 0x2e, 0x73, 0x74, 0x72, 0x74, 0x61, 0x62, - 0x00, 0x2e, 0x73, 0x68, 0x73, 0x74, 0x72, 0x74, 0x61, 0x62, 0x00, 0x2e, - 0x68, 0x61, 0x73, 0x68, 0x00, 0x2e, 0x64, 0x79, 0x6e, 0x73, 0x79, 0x6d, - 0x00, 0x2e, 0x64, 0x79, 0x6e, 0x73, 0x74, 0x72, 0x00, 0x2e, 0x72, 0x65, - 0x6c, 0x2e, 0x64, 0x79, 0x6e, 0x00, 0x2e, 0x70, 0x6c, 0x74, 0x00, 0x2e, - 0x74, 0x65, 0x78, 0x74, 0x00, 0x2e, 0x72, 0x6f, 0x64, 0x61, 0x74, 0x61, - 0x00, 0x2e, 0x72, 0x6f, 0x66, 0x69, 0x78, 0x75, 0x70, 0x00, 0x2e, 0x69, - 0x6e, 0x69, 0x74, 0x5f, 0x61, 0x72, 0x72, 0x61, 0x79, 0x00, 0x2e, 0x64, - 0x79, 0x6e, 0x61, 0x6d, 0x69, 0x63, 0x00, 0x2e, 0x67, 0x6f, 0x74, 0x00, - 0x2e, 0x62, 0x73, 0x73, 0x00, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, - 0x74, 0x00, 0x2e, 0x41, 0x52, 0x4d, 0x2e, 0x61, 0x74, 0x74, 0x72, 0x69, - 0x62, 0x75, 0x74, 0x65, 0x73, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x1b, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, - 0xb4, 0x00, 0x00, 0x00, 0xb4, 0x00, 0x00, 0x00, 0x6c, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, 0x21, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, 0x20, 0x01, 0x00, 0x00, 0x20, 0x01, 0x00, 0x00, - 0x60, 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x29, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x80, 0x02, 0x00, 0x00, - 0x80, 0x02, 0x00, 0x00, 0x9f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x31, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, - 0x20, 0x03, 0x00, 0x00, 0x20, 0x03, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, 0x3a, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x06, 0x00, 0x00, 0x00, 0x90, 0x03, 0x00, 0x00, 0x90, 0x03, 0x00, 0x00, - 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x80, 0x04, 0x00, 0x00, - 0x80, 0x04, 0x00, 0x00, 0xc4, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x45, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x32, 0x00, 0x00, 0x00, - 0x44, 0x06, 0x00, 0x00, 0x44, 0x06, 0x00, 0x00, 0xa7, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x4d, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, 0xec, 0x06, 0x00, 0x00, 0xec, 0x06, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x56, 0x00, 0x00, 0x00, - 0x0e, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0xf0, 0x16, 0x00, 0x00, - 0xf0, 0x06, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x62, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, - 0xf4, 0x16, 0x00, 0x00, 0xf4, 0x06, 0x00, 0x00, 0xa0, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, 0x6b, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, 0x94, 0x17, 0x00, 0x00, 0x94, 0x07, 0x00, 0x00, - 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, 0x18, 0x00, 0x00, - 0x04, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x75, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x04, 0x08, 0x00, 0x00, 0x45, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x70, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x49, 0x08, 0x00, 0x00, - 0x2d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x78, 0x08, 0x00, 0x00, 0x40, 0x04, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, - 0x35, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, - 0x09, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xb8, 0x0c, 0x00, 0x00, 0xe8, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa0, 0x0d, 0x00, 0x00, - 0x8e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 -}; - -static const unsigned int g_cxxuser_len = 4352; diff --git a/examples/fdpicxip/fdpicxip_main.c b/examples/fdpicxip/fdpicxip_main.c deleted file mode 100644 index 5c89f2ae0..000000000 --- a/examples/fdpicxip/fdpicxip_main.c +++ /dev/null @@ -1,538 +0,0 @@ -/**************************************************************************** - * apps/examples/fdpicxip/fdpicxip_main.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * End to end demonstration of the FDPIC module loader over a writable - * execute-in-place file system: - * - * 1. write a module into xipfs at run time, the way a download would, - * 2. confirm the file system can hand out a direct flash pointer for it, - * 3. run it, in some cases as two concurrent instances, - * 4. confirm the shared text was pinned in place while they ran and - * released afterwards. - * - * The point of FDPIC here is that text stays in flash and only the writable - * segment is copied, once per running instance -- so a second instance, or - * a second module sharing a library, costs data and no code. - * - * This demonstrates; it does not assert. The assertions live in the fdpic - * and reject sections of apps/testing/fs/xipfs. - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <sys/ioctl.h> -#include <sys/stat.h> -#include <sys/wait.h> - -#include <elf.h> -#include <errno.h> -#include <fcntl.h> -#include <inttypes.h> -#include <spawn.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <syslog.h> -#include <unistd.h> - -#include <nuttx/fs/ioctl.h> -#include <nuttx/fs/xipfs.h> - -#include "qsorter_bin.h" -#include "libcounter_bin.h" -#include "user_bin.h" -#include "libshape_bin.h" -#include "cxxuser_bin.h" -#include "lazymod_bin.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define MOUNTPT CONFIG_EXAMPLES_FDPICXIP_MOUNTPT - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: extent_info_path - * - * Description: - * Where a file physically lies: its extent, its flash address, and how - * many live mappings are pinning it in place. - * - ****************************************************************************/ - -static int extent_info_path(FAR const char *path, - FAR struct xipfs_extent_info_s *info) -{ - int fd; - int ret; - - fd = open(path, O_RDONLY | O_CLOEXEC); - if (fd < 0) - { - return -errno; - } - - ret = ioctl(fd, XIPFSIOC_EXTENTINFO, (unsigned long)(uintptr_t)info); - close(fd); - - return ret < 0 ? -errno : 0; -} - -/**************************************************************************** - * Shared library demonstration - * - * Stages a library and a module that needs it, then runs two instances. - * Both share one mapped copy of each object's code, executed in place from - * flash, while each instance gets private copies of both the module's data - * and the library's. If the library's state were shared, the two totals - * would interleave instead of each reaching seed*3. - ****************************************************************************/ - -static int stage_blob(FAR const char *path, FAR const unsigned char *data, - unsigned int len) -{ - ssize_t n; - int fd; - - unlink(path); - - fd = open(path, O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0755); - if (fd < 0) - { - return -errno; - } - - if (ftruncate(fd, len) < 0) - { - close(fd); - return -errno; - } - - n = write(fd, data, len); - close(fd); - - return (n == (ssize_t)len) ? 0 : -EIO; -} - -/**************************************************************************** - * Name: qsorter_main - * - * Description: - * The simplest case the loader has: one self-contained FDPIC module, no - * library behind it, run as two concurrent instances. It is the FDPIC - * counterpart of what this demo does by default with NXFLAT, and the - * only subcommand that exercises a module with no second object -- solib - * and cxx both bring a library, jmprel is about how imports are bound. - * - * The two instances overlap deliberately: each fills its array, sleeps, - * then sorts. One shared copy of the text, a private copy of the data - * per instance -- shared data would show up as corrupted output, and the - * pin count while both are alive is what stops the defragmenter - * relocating code that is executing. - * - ****************************************************************************/ - -static int qsorter_main(void) -{ - struct xipfs_extent_info_s info; - FAR char *args[3]; - pid_t pid[2]; - char seed[8]; - int status; - int ret; - int i; - - syslog(LOG_INFO, - "\n=== FDPIC module executed in place from xipfs ===\n\n"); - - ret = stage_blob(MOUNTPT "/qsorter", g_qsorter_nxf, g_qsorter_nxf_len); - if (ret < 0) - { - syslog(LOG_INFO, "staging the module failed: %d\n", ret); - return EXIT_FAILURE; - } - - syslog(LOG_INFO, "staged qsorter (%u bytes)\n", g_qsorter_nxf_len); - - if (extent_info_path(MOUNTPT "/qsorter", &info) == 0) - { - syslog(LOG_INFO, "extent: block %" PRIu32 " x%" PRIu32 ", size %" - PRIu32 ", flash addr 0x%08lx\n", - info.start_block, info.nblocks, info.size, - (unsigned long)info.xipaddr); - - if (info.xipaddr == 0) - { - syslog(LOG_INFO, - "ERROR: filesystem cannot expose a flash pointer; the " - "module would have to be copied to RAM\n"); - return EXIT_FAILURE; - } - } - - syslog(LOG_INFO, "\nspawning two concurrent instances...\n\n"); - - for (i = 0; i < 2; i++) - { - snprintf(seed, sizeof(seed), "%d", i + 1); - args[0] = (FAR char *)"qsorter"; - args[1] = seed; - args[2] = NULL; - - ret = posix_spawn(&pid[i], MOUNTPT "/qsorter", NULL, NULL, args, NULL); - if (ret != 0) - { - syslog(LOG_INFO, "spawn %d failed: %d\n", i + 1, ret); - return EXIT_FAILURE; - } - } - - usleep(150000); - - if (extent_info_path(MOUNTPT "/qsorter", &info) == 0) - { - syslog(LOG_INFO, "[while running] pins on the shared text = %lu\n\n", - (unsigned long)info.pincount); - } - - for (i = 0; i < 2; i++) - { - waitpid(pid[i], &status, 0); - } - - usleep(100000); - - if (extent_info_path(MOUNTPT "/qsorter", &info) == 0) - { - syslog(LOG_INFO, "\n[after exit] pins on the shared text = %lu\n", - (unsigned long)info.pincount); - } - - syslog(LOG_INFO, "\n=== done ===\n"); - return EXIT_SUCCESS; -} - -static int solib_main(void) -{ - struct xipfs_extent_info_s li; - struct xipfs_extent_info_s ui; - FAR char *args[3]; - pid_t pid[2]; - char seed[8]; - int status; - int ret; - int i; - - syslog(LOG_INFO, "\n=== FDPIC shared library, executed in place ===\n\n"); - - ret = stage_blob(MOUNTPT "/libcounter.so", g_libcounter, g_libcounter_len); - if (ret < 0) - { - syslog(LOG_INFO, "staging the library failed: %d\n", ret); - return EXIT_FAILURE; - } - - ret = stage_blob(MOUNTPT "/user", g_user, g_user_len); - if (ret < 0) - { - syslog(LOG_INFO, "staging the module failed: %d\n", ret); - return EXIT_FAILURE; - } - - syslog(LOG_INFO, "staged libcounter.so (%u bytes) and user (%u bytes)\n", - g_libcounter_len, g_user_len); - - if (extent_info_path(MOUNTPT "/libcounter.so", &li) == 0 && - extent_info_path(MOUNTPT "/user", &ui) == 0) - { - syslog(LOG_INFO, " libcounter.so text at 0x%08lx\n", - (unsigned long)li.xipaddr); - syslog(LOG_INFO, " user text at 0x%08lx\n", - (unsigned long)ui.xipaddr); - } - - syslog(LOG_INFO, "\nspawning two instances, each bumping by its own" - " seed...\n\n"); - - for (i = 0; i < 2; i++) - { - snprintf(seed, sizeof(seed), "%d", i + 1); - args[0] = (FAR char *)"user"; - args[1] = seed; - args[2] = NULL; - - ret = posix_spawn(&pid[i], MOUNTPT "/user", NULL, NULL, args, NULL); - if (ret != 0) - { - syslog(LOG_INFO, "spawn %d failed: %d\n", i + 1, ret); - return EXIT_FAILURE; - } - } - - usleep(150000); - - if (extent_info_path(MOUNTPT "/libcounter.so", &li) == 0) - { - syslog(LOG_INFO, "[while running] pins on the library's shared text" - " = %lu\n\n", (unsigned long)li.pincount); - } - - for (i = 0; i < 2; i++) - { - waitpid(pid[i], &status, 0); - } - - usleep(100000); - - if (extent_info_path(MOUNTPT "/libcounter.so", &li) == 0) - { - syslog(LOG_INFO, "\n[after exit] pins on the library's shared text" - " = %lu\n", (unsigned long)li.pincount); - } - - syslog(LOG_INFO, "\n=== done ===\n"); - return EXIT_SUCCESS; -} - -/**************************************************************************** - * Name: cxx_main - * - * Description: - * The same shape as solib_main(), in C++, and with one thing extra to - * prove: that global constructors ran. - * - * That is worth a demo of its own because of how it fails. A loader that - * ignores DT_INIT_ARRAY still loads a C++ module, still resolves every - * symbol, and still runs it -- the globals are simply left as .bss and - * every field reads zero. Nothing faults and nothing is logged; the - * module just answers wrong. So both objects here carry a magic number - * that only a constructor writes, and the module reports whether it found - * them. - * - * The ordering is checked too. The module's constructor samples whether - * the library was already constructed when it ran, which is the only - * moment the answer is still interesting -- by the time main() is entered - * both have run either way. - * - ****************************************************************************/ - -static int cxx_main(void) -{ - struct xipfs_extent_info_s li; - struct xipfs_extent_info_s ui; - FAR char *args[3]; - pid_t pid[2]; - char seed[8]; - int status; - int ret; - int i; - - syslog(LOG_INFO, "\n=== C++ module and shared library, executed in" - " place ===\n\n"); - - ret = stage_blob(MOUNTPT "/libshape.so", g_libshape, g_libshape_len); - if (ret < 0) - { - syslog(LOG_INFO, "staging the library failed: %d\n", ret); - return EXIT_FAILURE; - } - - ret = stage_blob(MOUNTPT "/cxxuser", g_cxxuser, g_cxxuser_len); - if (ret < 0) - { - syslog(LOG_INFO, "staging the module failed: %d\n", ret); - return EXIT_FAILURE; - } - - syslog(LOG_INFO, "staged libshape.so (%u bytes) and cxxuser (%u bytes)\n", - g_libshape_len, g_cxxuser_len); - - if (extent_info_path(MOUNTPT "/libshape.so", &li) == 0 && - extent_info_path(MOUNTPT "/cxxuser", &ui) == 0) - { - syslog(LOG_INFO, " libshape.so text at 0x%08lx\n", - (unsigned long)li.xipaddr); - syslog(LOG_INFO, " cxxuser text at 0x%08lx\n", - (unsigned long)ui.xipaddr); - } - - syslog(LOG_INFO, "\nspawning two instances, each adding its own seed...\n" - "(each instance's constructors run at load time, before main)\n\n"); - - for (i = 0; i < 2; i++) - { - snprintf(seed, sizeof(seed), "%d", i + 1); - args[0] = (FAR char *)"cxxuser"; - args[1] = seed; - args[2] = NULL; - - ret = posix_spawn(&pid[i], MOUNTPT "/cxxuser", NULL, NULL, args, NULL); - if (ret != 0) - { - syslog(LOG_INFO, "spawn %d failed: %d\n", i + 1, ret); - return EXIT_FAILURE; - } - } - - usleep(150000); - - if (extent_info_path(MOUNTPT "/libshape.so", &li) == 0) - { - syslog(LOG_INFO, "[while running] pins on the library's shared text" - " = %lu\n\n", (unsigned long)li.pincount); - } - - /* Only a barrier. The exit status is deliberately not read: waitpid() - * retains it for an already-exited child only under - * CONFIG_SCHED_CHILD_STATUS, and both instances run for the same time, so - * the second is always gone by the time the first wait returns. Checking - * `status` after a failed wait reads whatever the previous iteration left - * there, which looks like a pass. The suite in apps/testing/fs/xipfs - * asserts the real result via files; this demo reports through the log. - */ - - ret = EXIT_SUCCESS; - - for (i = 0; i < 2; i++) - { - waitpid(pid[i], &status, 0); - } - - /* The destructors run on unload, which happens as each task is reaped -- - * after waitpid() has returned, so give them a moment to be logged. - */ - - usleep(100000); - - if (extent_info_path(MOUNTPT "/libshape.so", &li) == 0) - { - syslog(LOG_INFO, "\n[after exit] pins on the library's shared text" - " = %lu\n", (unsigned long)li.pincount); - } - - syslog(LOG_INFO, "\n=== %s ===\n", - ret == EXIT_SUCCESS ? "done" : "FAILED"); - return ret; -} - -/**************************************************************************** - * Name: jmprel_main - * - * Description: - * Load a module whose imports the linker put in DT_JMPREL. - * - * Every other module here is linked with -z now, which leaves the imported - * descriptors in DT_REL. This one empties BINDNOW in modules/Makefile, so - * it has no DT_REL at all -- both of its imports are in the PLT relocation - * table. - * - * There is no lazy resolver in the loader, so a DT_JMPREL table that went - * unwalked was not deferred work: the descriptors stayed unrelocated and - * the module's first call into the firmware branched to whatever the - * unrelocated word held. It loaded cleanly and printed nothing, then - * took an INVSTATE UsageFault that escalated to a HardFault -- no - * console, no crash dump. If this demo prints its line, both tables are - * being bound. - * - ****************************************************************************/ - -static int jmprel_main(void) -{ - FAR char *args[3]; - pid_t pid; - int status; - int ret; - - syslog(LOG_INFO, "\n=== FDPIC module bound through DT_JMPREL ===\n\n"); - - ret = stage_blob(MOUNTPT "/lazymod", g_lazymod, g_lazymod_len); - if (ret < 0) - { - syslog(LOG_INFO, "staging the module failed: %d\n", ret); - return EXIT_FAILURE; - } - - syslog(LOG_INFO, "staged lazymod (%u bytes), all imports in DT_JMPREL\n\n", - g_lazymod_len); - - args[0] = (FAR char *)"lazymod"; - args[1] = (FAR char *)"42"; - args[2] = NULL; - - ret = posix_spawn(&pid, MOUNTPT "/lazymod", NULL, NULL, args, NULL); - if (ret != 0) - { - syslog(LOG_INFO, "spawn failed: %d\n", ret); - return EXIT_FAILURE; - } - - waitpid(pid, &status, 0); - - if (!WIFEXITED(status) || WEXITSTATUS(status) != EXIT_SUCCESS) - { - syslog(LOG_INFO, "\n=== FAILED: module did not exit cleanly ===\n"); - return EXIT_FAILURE; - } - - syslog(LOG_INFO, "\n=== done: the module reached the firmware and came" - " back ===\n"); - return EXIT_SUCCESS; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -int main(int argc, FAR char *argv[]) -{ - if (argc > 1 && strcmp(argv[1], "solib") == 0) - { - return solib_main(); - } - - if (argc > 1 && strcmp(argv[1], "cxx") == 0) - { - return cxx_main(); - } - - if (argc > 1 && strcmp(argv[1], "jmprel") == 0) - { - return jmprel_main(); - } - - if (argc > 1 && strcmp(argv[1], "qsort") != 0) - { - fprintf(stderr, "usage: fdpicxip [qsort|solib|cxx|jmprel]\n"); - return EXIT_FAILURE; - } - - return qsorter_main(); -} diff --git a/examples/fdpicxip/lazymod_bin.h b/examples/fdpicxip/lazymod_bin.h deleted file mode 100644 index b2d514312..000000000 --- a/examples/fdpicxip/lazymod_bin.h +++ /dev/null @@ -1,220 +0,0 @@ -/**************************************************************************** - * apps/examples/fdpicxip/lazymod_bin.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/* Generated from lazymod.fdpic -- do not edit. - * - * An FDPIC module, embedded so the demo has something to load without - * needing a filesystem populated from the host first. - */ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -static const unsigned char g_lazymod[] = -{ - 0x7f, 0x45, 0x4c, 0x46, 0x01, 0x01, 0x01, 0x41, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x28, 0x00, 0x01, 0x00, 0x00, 0x00, - 0xd5, 0x01, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x10, 0x06, 0x00, 0x00, - 0x00, 0x02, 0x00, 0x05, 0x34, 0x00, 0x20, 0x00, 0x04, 0x00, 0x28, 0x00, - 0x10, 0x00, 0x0f, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x02, 0x00, 0x00, - 0x3c, 0x02, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x3c, 0x02, 0x00, 0x00, 0x3c, 0x12, 0x00, 0x00, - 0x3c, 0x12, 0x00, 0x00, 0x94, 0x00, 0x00, 0x00, 0x94, 0x00, 0x00, 0x00, - 0x06, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, - 0x3c, 0x02, 0x00, 0x00, 0x3c, 0x12, 0x00, 0x00, 0x3c, 0x12, 0x00, 0x00, - 0x78, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, 0x51, 0xe5, 0x74, 0x64, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x80, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x23, 0x00, 0x00, 0x00, 0x3c, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x08, 0x00, 0x01, 0x00, 0x00, 0x00, 0xd5, 0x01, 0x00, 0x00, - 0x28, 0x00, 0x00, 0x00, 0x12, 0x00, 0x06, 0x00, 0x12, 0x00, 0x00, 0x00, - 0x38, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x08, 0x00, - 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, - 0x6e, 0x00, 0x61, 0x74, 0x6f, 0x69, 0x00, 0x73, 0x79, 0x73, 0x6c, 0x6f, - 0x67, 0x00, 0x5f, 0x5f, 0x52, 0x4f, 0x46, 0x49, 0x58, 0x55, 0x50, 0x5f, - 0x4c, 0x49, 0x53, 0x54, 0x5f, 0x5f, 0x00, 0x5f, 0x5f, 0x52, 0x4f, 0x46, - 0x49, 0x58, 0x55, 0x50, 0x5f, 0x45, 0x4e, 0x44, 0x5f, 0x5f, 0x00, 0x00, - 0xc0, 0x12, 0x00, 0x00, 0xa4, 0x04, 0x00, 0x00, 0xc8, 0x12, 0x00, 0x00, - 0xa4, 0x05, 0x00, 0x00, 0xdf, 0xf8, 0x0c, 0xc0, 0x0c, 0xeb, 0x09, 0x0c, - 0xdc, 0xf8, 0x04, 0x90, 0xdc, 0xf8, 0x00, 0xf0, 0x0c, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x5f, 0xf8, 0x08, 0xc0, 0x4d, 0xf8, 0x04, 0xcd, - 0xd9, 0xf8, 0x04, 0xc0, 0xd9, 0xf8, 0x00, 0xf0, 0xdf, 0xf8, 0x0c, 0xc0, - 0x0c, 0xeb, 0x09, 0x0c, 0xdc, 0xf8, 0x04, 0x90, 0xdc, 0xf8, 0x00, 0xf0, - 0x14, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x5f, 0xf8, 0x08, 0xc0, - 0x4d, 0xf8, 0x04, 0xcd, 0xd9, 0xf8, 0x04, 0xc0, 0xd9, 0xf8, 0x00, 0xf0, - 0x01, 0x28, 0x10, 0xb5, 0x4c, 0x46, 0x0b, 0xdd, 0x48, 0x68, 0xff, 0xf7, - 0xe5, 0xff, 0xa1, 0x46, 0x02, 0x46, 0x04, 0x49, 0x06, 0x20, 0x79, 0x44, - 0xff, 0xf7, 0xca, 0xff, 0x00, 0x20, 0x10, 0xbd, 0x01, 0x22, 0xf6, 0xe7, - 0x0e, 0x00, 0x00, 0x00, 0x5b, 0x6c, 0x61, 0x7a, 0x79, 0x6d, 0x6f, 0x64, - 0x5d, 0x20, 0x63, 0x61, 0x6c, 0x6c, 0x65, 0x64, 0x20, 0x74, 0x68, 0x72, - 0x6f, 0x75, 0x67, 0x68, 0x20, 0x61, 0x20, 0x44, 0x54, 0x5f, 0x4a, 0x4d, - 0x50, 0x52, 0x45, 0x4c, 0x20, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, - 0x74, 0x6f, 0x72, 0x2c, 0x20, 0x73, 0x65, 0x65, 0x64, 0x20, 0x25, 0x64, - 0x0a, 0x00, 0x00, 0x00, 0xb4, 0x12, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0xb4, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x40, 0x01, 0x00, 0x00, - 0x06, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, - 0x33, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, 0xb4, 0x12, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, - 0x17, 0x00, 0x00, 0x00, 0x74, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x12, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9c, 0x01, 0x00, 0x00, - 0xff, 0xff, 0xff, 0xff, 0xc4, 0x01, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, - 0x47, 0x43, 0x43, 0x3a, 0x20, 0x28, 0x41, 0x72, 0x6d, 0x20, 0x47, 0x4e, - 0x55, 0x20, 0x54, 0x6f, 0x6f, 0x6c, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x20, - 0x31, 0x35, 0x2e, 0x32, 0x2e, 0x52, 0x65, 0x6c, 0x31, 0x20, 0x28, 0x42, - 0x75, 0x69, 0x6c, 0x64, 0x20, 0x61, 0x72, 0x6d, 0x2d, 0x31, 0x35, 0x2e, - 0x38, 0x36, 0x29, 0x29, 0x20, 0x31, 0x35, 0x2e, 0x32, 0x2e, 0x31, 0x20, - 0x32, 0x30, 0x32, 0x35, 0x31, 0x32, 0x30, 0x33, 0x00, 0x41, 0x2c, 0x00, - 0x00, 0x00, 0x61, 0x65, 0x61, 0x62, 0x69, 0x00, 0x01, 0x22, 0x00, 0x00, - 0x00, 0x05, 0x37, 0x2d, 0x4d, 0x00, 0x06, 0x0a, 0x07, 0x4d, 0x09, 0x02, - 0x12, 0x04, 0x14, 0x01, 0x15, 0x01, 0x17, 0x03, 0x18, 0x01, 0x19, 0x01, - 0x1a, 0x01, 0x1e, 0x04, 0x22, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xb4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x40, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x03, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x74, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x84, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xd4, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x06, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xfc, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x02, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x3c, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x09, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xb4, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x0c, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x04, 0x00, 0xf1, 0xff, 0x0b, 0x00, 0x00, 0x00, 0xd4, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x0e, 0x00, 0x00, 0x00, - 0xf8, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x04, 0x00, 0xf1, 0xff, 0x11, 0x00, 0x00, 0x00, 0x3c, 0x12, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0xf1, 0xff, 0x1a, 0x00, 0x00, 0x00, - 0xb4, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x0a, 0x00, - 0x0e, 0x00, 0x00, 0x00, 0xfc, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x84, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x0e, 0x00, 0x00, 0x00, - 0x94, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, - 0x0b, 0x00, 0x00, 0x00, 0x9c, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x05, 0x00, 0x0b, 0x00, 0x00, 0x00, 0xac, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x0e, 0x00, 0x00, 0x00, - 0xbc, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, - 0x0b, 0x00, 0x00, 0x00, 0xc4, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x05, 0x00, 0x30, 0x00, 0x00, 0x00, 0x3c, 0x02, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x08, 0x00, 0x40, 0x00, 0x00, 0x00, - 0xd5, 0x01, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x12, 0x00, 0x06, 0x00, - 0x45, 0x00, 0x00, 0x00, 0x38, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x08, 0x00, 0x56, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x5d, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, - 0x00, 0x6c, 0x61, 0x7a, 0x79, 0x6d, 0x6f, 0x64, 0x2e, 0x63, 0x00, 0x24, - 0x74, 0x00, 0x24, 0x64, 0x00, 0x5f, 0x44, 0x59, 0x4e, 0x41, 0x4d, 0x49, - 0x43, 0x00, 0x5f, 0x47, 0x4c, 0x4f, 0x42, 0x41, 0x4c, 0x5f, 0x4f, 0x46, - 0x46, 0x53, 0x45, 0x54, 0x5f, 0x54, 0x41, 0x42, 0x4c, 0x45, 0x5f, 0x00, - 0x5f, 0x5f, 0x52, 0x4f, 0x46, 0x49, 0x58, 0x55, 0x50, 0x5f, 0x45, 0x4e, - 0x44, 0x5f, 0x5f, 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x5f, 0x5f, 0x52, - 0x4f, 0x46, 0x49, 0x58, 0x55, 0x50, 0x5f, 0x4c, 0x49, 0x53, 0x54, 0x5f, - 0x5f, 0x00, 0x73, 0x79, 0x73, 0x6c, 0x6f, 0x67, 0x00, 0x61, 0x74, 0x6f, - 0x69, 0x00, 0x00, 0x2e, 0x73, 0x79, 0x6d, 0x74, 0x61, 0x62, 0x00, 0x2e, - 0x73, 0x74, 0x72, 0x74, 0x61, 0x62, 0x00, 0x2e, 0x73, 0x68, 0x73, 0x74, - 0x72, 0x74, 0x61, 0x62, 0x00, 0x2e, 0x68, 0x61, 0x73, 0x68, 0x00, 0x2e, - 0x64, 0x79, 0x6e, 0x73, 0x79, 0x6d, 0x00, 0x2e, 0x64, 0x79, 0x6e, 0x73, - 0x74, 0x72, 0x00, 0x2e, 0x72, 0x65, 0x6c, 0x2e, 0x70, 0x6c, 0x74, 0x00, - 0x2e, 0x74, 0x65, 0x78, 0x74, 0x00, 0x2e, 0x72, 0x6f, 0x64, 0x61, 0x74, - 0x61, 0x00, 0x2e, 0x72, 0x6f, 0x66, 0x69, 0x78, 0x75, 0x70, 0x00, 0x2e, - 0x64, 0x79, 0x6e, 0x61, 0x6d, 0x69, 0x63, 0x00, 0x2e, 0x67, 0x6f, 0x74, - 0x00, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x00, 0x2e, 0x41, - 0x52, 0x4d, 0x2e, 0x61, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, - 0x73, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1b, 0x00, 0x00, 0x00, - 0x05, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0xb4, 0x00, 0x00, 0x00, - 0xb4, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x21, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, - 0xe0, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, 0x29, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, 0x40, 0x01, 0x00, 0x00, 0x40, 0x01, 0x00, 0x00, - 0x33, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x31, 0x00, 0x00, 0x00, - 0x09, 0x00, 0x00, 0x00, 0x42, 0x00, 0x00, 0x00, 0x74, 0x01, 0x00, 0x00, - 0x74, 0x01, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, - 0x35, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, - 0x84, 0x01, 0x00, 0x00, 0x84, 0x01, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, 0x3a, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x06, 0x00, 0x00, 0x00, 0xd4, 0x01, 0x00, 0x00, 0xd4, 0x01, 0x00, 0x00, - 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x32, 0x00, 0x00, 0x00, 0xfc, 0x01, 0x00, 0x00, - 0xfc, 0x01, 0x00, 0x00, 0x3a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x48, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, - 0x38, 0x02, 0x00, 0x00, 0x38, 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x51, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, 0x3c, 0x12, 0x00, 0x00, 0x3c, 0x02, 0x00, 0x00, - 0x78, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x5a, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0xb4, 0x12, 0x00, 0x00, - 0xb4, 0x02, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x5f, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xd0, 0x02, 0x00, 0x00, 0x45, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x68, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x70, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x15, 0x03, 0x00, 0x00, - 0x2d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x44, 0x03, 0x00, 0x00, 0xf0, 0x01, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, - 0x09, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x34, 0x05, 0x00, 0x00, 0x62, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x96, 0x05, 0x00, 0x00, - 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 -}; - -static const unsigned int g_lazymod_len = 2192; diff --git a/examples/fdpicxip/libcounter_bin.h b/examples/fdpicxip/libcounter_bin.h deleted file mode 100644 index 9ef92cae7..000000000 --- a/examples/fdpicxip/libcounter_bin.h +++ /dev/null @@ -1,208 +0,0 @@ -/**************************************************************************** - * apps/examples/fdpicxip/libcounter_bin.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/* Generated from libcounter.so -- do not edit. - * - * An FDPIC module, embedded so the demo has something to load without - * needing a filesystem populated from the host first. - */ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -static const unsigned char g_libcounter[] = -{ - 0x7f, 0x45, 0x4c, 0x46, 0x01, 0x01, 0x01, 0x41, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x28, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0xac, 0x05, 0x00, 0x00, - 0x00, 0x02, 0x00, 0x05, 0x34, 0x00, 0x20, 0x00, 0x04, 0x00, 0x28, 0x00, - 0x0f, 0x00, 0x0e, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x01, 0x00, 0x00, - 0xf8, 0x01, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0xf8, 0x01, 0x00, 0x00, 0xf8, 0x11, 0x00, 0x00, - 0xf8, 0x11, 0x00, 0x00, 0x98, 0x00, 0x00, 0x00, 0x9c, 0x00, 0x00, 0x00, - 0x06, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, - 0xf8, 0x01, 0x00, 0x00, 0xf8, 0x11, 0x00, 0x00, 0xf8, 0x11, 0x00, 0x00, - 0x88, 0x00, 0x00, 0x00, 0x88, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, 0x51, 0xe5, 0x74, 0x64, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x80, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x06, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xd0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf4, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x80, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x08, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x90, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x09, 0x00, 0x01, 0x00, 0x00, 0x00, 0xd1, 0x01, 0x00, 0x00, - 0x14, 0x00, 0x00, 0x00, 0x12, 0x00, 0x05, 0x00, 0x0e, 0x00, 0x00, 0x00, - 0xe5, 0x01, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x12, 0x00, 0x05, 0x00, - 0x2d, 0x00, 0x00, 0x00, 0xf8, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x06, 0x00, 0x1c, 0x00, 0x00, 0x00, 0xf4, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x06, 0x00, 0x00, 0x63, 0x6f, 0x75, - 0x6e, 0x74, 0x65, 0x72, 0x5f, 0x62, 0x75, 0x6d, 0x70, 0x00, 0x63, 0x6f, - 0x75, 0x6e, 0x74, 0x65, 0x72, 0x5f, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x00, - 0x5f, 0x5f, 0x52, 0x4f, 0x46, 0x49, 0x58, 0x55, 0x50, 0x5f, 0x4c, 0x49, - 0x53, 0x54, 0x5f, 0x5f, 0x00, 0x5f, 0x5f, 0x52, 0x4f, 0x46, 0x49, 0x58, - 0x55, 0x50, 0x5f, 0x45, 0x4e, 0x44, 0x5f, 0x5f, 0x00, 0x6c, 0x69, 0x62, - 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x65, 0x72, 0x2e, 0x73, 0x6f, 0x00, 0x00, - 0x8c, 0x12, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00, 0x03, 0x4b, 0x59, 0xf8, - 0x03, 0x30, 0x1a, 0x68, 0x10, 0x44, 0x18, 0x60, 0x70, 0x47, 0x00, 0xbf, - 0x0c, 0x00, 0x00, 0x00, 0x02, 0x4b, 0x59, 0xf8, 0x03, 0x30, 0x18, 0x68, - 0x70, 0x47, 0x00, 0xbf, 0x0c, 0x00, 0x00, 0x00, 0x80, 0x12, 0x00, 0x00, - 0x0e, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0xb4, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x7c, 0x01, 0x00, 0x00, - 0x06, 0x00, 0x00, 0x00, 0xec, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, - 0x4b, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, - 0x11, 0x00, 0x00, 0x00, 0xc8, 0x01, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, - 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfb, 0xff, 0xff, 0x6f, - 0x01, 0x00, 0x00, 0x00, 0xfa, 0xff, 0xff, 0x6f, 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xf8, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x90, 0x12, 0x00, 0x00, 0x47, 0x43, 0x43, 0x3a, - 0x20, 0x28, 0x41, 0x72, 0x6d, 0x20, 0x47, 0x4e, 0x55, 0x20, 0x54, 0x6f, - 0x6f, 0x6c, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x20, 0x31, 0x35, 0x2e, 0x32, - 0x2e, 0x52, 0x65, 0x6c, 0x31, 0x20, 0x28, 0x42, 0x75, 0x69, 0x6c, 0x64, - 0x20, 0x61, 0x72, 0x6d, 0x2d, 0x31, 0x35, 0x2e, 0x38, 0x36, 0x29, 0x29, - 0x20, 0x31, 0x35, 0x2e, 0x32, 0x2e, 0x31, 0x20, 0x32, 0x30, 0x32, 0x35, - 0x31, 0x32, 0x30, 0x33, 0x00, 0x41, 0x2c, 0x00, 0x00, 0x00, 0x61, 0x65, - 0x61, 0x62, 0x69, 0x00, 0x01, 0x22, 0x00, 0x00, 0x00, 0x05, 0x37, 0x2d, - 0x4d, 0x00, 0x06, 0x0a, 0x07, 0x4d, 0x09, 0x02, 0x12, 0x04, 0x14, 0x01, - 0x15, 0x01, 0x17, 0x03, 0x18, 0x01, 0x19, 0x01, 0x1a, 0x01, 0x1e, 0x04, - 0x22, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xb4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x01, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xec, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xc8, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x04, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xd0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf4, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xf8, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x80, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x90, 0x12, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x0a, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x0b, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0xf1, 0xff, 0x0e, 0x00, 0x00, 0x00, - 0xd0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, - 0x11, 0x00, 0x00, 0x00, 0xe0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x05, 0x00, 0x0e, 0x00, 0x00, 0x00, 0xe4, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x11, 0x00, 0x00, 0x00, - 0xf0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, - 0x11, 0x00, 0x00, 0x00, 0x90, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x09, 0x00, 0x14, 0x00, 0x00, 0x00, 0x90, 0x12, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x00, 0x1e, 0x00, 0x00, 0x00, - 0x90, 0x12, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x09, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x04, 0x00, 0xf1, 0xff, 0x26, 0x00, 0x00, 0x00, 0xf8, 0x11, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0xf1, 0xff, 0x2f, 0x00, 0x00, 0x00, - 0x80, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x08, 0x00, - 0x45, 0x00, 0x00, 0x00, 0xd1, 0x01, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, - 0x12, 0x00, 0x05, 0x00, 0x52, 0x00, 0x00, 0x00, 0xe5, 0x01, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, 0x12, 0x00, 0x05, 0x00, 0x60, 0x00, 0x00, 0x00, - 0xf8, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x06, 0x00, - 0x70, 0x00, 0x00, 0x00, 0xf4, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x06, 0x00, 0x00, 0x6c, 0x69, 0x62, 0x63, 0x6f, 0x75, 0x6e, - 0x74, 0x65, 0x72, 0x2e, 0x63, 0x00, 0x24, 0x74, 0x00, 0x24, 0x64, 0x00, - 0x2e, 0x4c, 0x41, 0x4e, 0x43, 0x48, 0x4f, 0x52, 0x30, 0x00, 0x67, 0x5f, - 0x63, 0x61, 0x6c, 0x6c, 0x73, 0x00, 0x5f, 0x44, 0x59, 0x4e, 0x41, 0x4d, - 0x49, 0x43, 0x00, 0x5f, 0x47, 0x4c, 0x4f, 0x42, 0x41, 0x4c, 0x5f, 0x4f, - 0x46, 0x46, 0x53, 0x45, 0x54, 0x5f, 0x54, 0x41, 0x42, 0x4c, 0x45, 0x5f, - 0x00, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x65, 0x72, 0x5f, 0x62, 0x75, 0x6d, - 0x70, 0x00, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x65, 0x72, 0x5f, 0x74, 0x6f, - 0x74, 0x61, 0x6c, 0x00, 0x5f, 0x5f, 0x52, 0x4f, 0x46, 0x49, 0x58, 0x55, - 0x50, 0x5f, 0x45, 0x4e, 0x44, 0x5f, 0x5f, 0x00, 0x5f, 0x5f, 0x52, 0x4f, - 0x46, 0x49, 0x58, 0x55, 0x50, 0x5f, 0x4c, 0x49, 0x53, 0x54, 0x5f, 0x5f, - 0x00, 0x00, 0x2e, 0x73, 0x79, 0x6d, 0x74, 0x61, 0x62, 0x00, 0x2e, 0x73, - 0x74, 0x72, 0x74, 0x61, 0x62, 0x00, 0x2e, 0x73, 0x68, 0x73, 0x74, 0x72, - 0x74, 0x61, 0x62, 0x00, 0x2e, 0x68, 0x61, 0x73, 0x68, 0x00, 0x2e, 0x64, - 0x79, 0x6e, 0x73, 0x79, 0x6d, 0x00, 0x2e, 0x64, 0x79, 0x6e, 0x73, 0x74, - 0x72, 0x00, 0x2e, 0x72, 0x65, 0x6c, 0x2e, 0x64, 0x79, 0x6e, 0x00, 0x2e, - 0x74, 0x65, 0x78, 0x74, 0x00, 0x2e, 0x72, 0x6f, 0x66, 0x69, 0x78, 0x75, - 0x70, 0x00, 0x2e, 0x64, 0x79, 0x6e, 0x61, 0x6d, 0x69, 0x63, 0x00, 0x2e, - 0x67, 0x6f, 0x74, 0x00, 0x2e, 0x62, 0x73, 0x73, 0x00, 0x2e, 0x63, 0x6f, - 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x00, 0x2e, 0x41, 0x52, 0x4d, 0x2e, 0x61, - 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x73, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x1b, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, 0xb4, 0x00, 0x00, 0x00, 0xb4, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x21, 0x00, 0x00, 0x00, - 0x0b, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0xec, 0x00, 0x00, 0x00, - 0xec, 0x00, 0x00, 0x00, 0x90, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, - 0x05, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, - 0x29, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, - 0x7c, 0x01, 0x00, 0x00, 0x7c, 0x01, 0x00, 0x00, 0x4b, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x31, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, 0xc8, 0x01, 0x00, 0x00, 0xc8, 0x01, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x3a, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0xd0, 0x01, 0x00, 0x00, - 0xd0, 0x01, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x40, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, - 0xf4, 0x01, 0x00, 0x00, 0xf4, 0x01, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x49, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, 0xf8, 0x11, 0x00, 0x00, 0xf8, 0x01, 0x00, 0x00, - 0x88, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x52, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x80, 0x12, 0x00, 0x00, - 0x80, 0x02, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x57, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, - 0x90, 0x12, 0x00, 0x00, 0x90, 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x5c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x90, 0x02, 0x00, 0x00, - 0x45, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xd5, 0x02, 0x00, 0x00, 0x2d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x04, 0x03, 0x00, 0x00, 0xb0, 0x01, 0x00, 0x00, - 0x0d, 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb4, 0x04, 0x00, 0x00, - 0x81, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x35, 0x05, 0x00, 0x00, 0x75, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 -}; - -static const unsigned int g_libcounter_len = 2052; diff --git a/examples/fdpicxip/libshape_bin.h b/examples/fdpicxip/libshape_bin.h deleted file mode 100644 index 178153308..000000000 --- a/examples/fdpicxip/libshape_bin.h +++ /dev/null @@ -1,389 +0,0 @@ -/**************************************************************************** - * apps/examples/fdpicxip/libshape_bin.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/* Generated from libshape.so -- do not edit. - * - * An FDPIC module, embedded so the demo has something to load without - * needing a filesystem populated from the host first. - */ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -static const unsigned char g_libshape[] = -{ - 0x7f, 0x45, 0x4c, 0x46, 0x01, 0x01, 0x01, 0x41, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x28, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x88, 0x0d, 0x00, 0x00, - 0x00, 0x02, 0x00, 0x05, 0x34, 0x00, 0x20, 0x00, 0x04, 0x00, 0x28, 0x00, - 0x13, 0x00, 0x12, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xbc, 0x05, 0x00, 0x00, - 0xbc, 0x05, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0xbc, 0x05, 0x00, 0x00, 0xbc, 0x15, 0x00, 0x00, - 0xbc, 0x15, 0x00, 0x00, 0x08, 0x01, 0x00, 0x00, 0x54, 0x01, 0x00, 0x00, - 0x06, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, - 0xc4, 0x05, 0x00, 0x00, 0xc4, 0x15, 0x00, 0x00, 0xc4, 0x15, 0x00, 0x00, - 0xb0, 0x00, 0x00, 0x00, 0xb0, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, 0x51, 0xe5, 0x74, 0x64, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x80, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, 0x16, 0x00, 0x00, 0x00, 0x15, 0x00, 0x00, 0x00, - 0x12, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, - 0x0c, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, - 0x09, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, - 0x11, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x90, 0x03, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x30, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x06, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x4c, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb8, 0x05, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x74, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x0c, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xc4, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x0d, 0x00, 0x3d, 0x00, 0x00, 0x00, 0xc5, 0x04, 0x00, 0x00, - 0x88, 0x00, 0x00, 0x00, 0x22, 0x00, 0x06, 0x00, 0x4e, 0x00, 0x00, 0x00, - 0x6d, 0x04, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x12, 0x00, 0x06, 0x00, - 0x19, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xc5, 0x04, 0x00, 0x00, - 0x88, 0x00, 0x00, 0x00, 0x22, 0x00, 0x06, 0x00, 0x6d, 0x00, 0x00, 0x00, - 0x99, 0x04, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x12, 0x00, 0x06, 0x00, - 0x79, 0x00, 0x00, 0x00, 0xa9, 0x04, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, - 0x12, 0x00, 0x06, 0x00, 0x27, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x31, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, - 0x65, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, 0x9c, 0x00, 0x00, 0x00, 0xbc, 0x05, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x08, 0x00, 0x8b, 0x00, 0x00, 0x00, - 0xb8, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x08, 0x00, - 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x58, 0x00, 0x00, 0x00, - 0x85, 0x04, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x12, 0x00, 0x06, 0x00, - 0x37, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, 0x00, 0x5f, 0x5a, 0x4e, 0x38, 0x52, 0x65, 0x67, - 0x69, 0x73, 0x74, 0x72, 0x79, 0x44, 0x32, 0x45, 0x76, 0x00, 0x73, 0x79, - 0x73, 0x6c, 0x6f, 0x67, 0x00, 0x73, 0x6e, 0x70, 0x72, 0x69, 0x6e, 0x74, - 0x66, 0x00, 0x6f, 0x70, 0x65, 0x6e, 0x00, 0x66, 0x74, 0x72, 0x75, 0x6e, - 0x63, 0x61, 0x74, 0x65, 0x00, 0x77, 0x72, 0x69, 0x74, 0x65, 0x00, 0x63, - 0x6c, 0x6f, 0x73, 0x65, 0x00, 0x5f, 0x5a, 0x4e, 0x38, 0x52, 0x65, 0x67, - 0x69, 0x73, 0x74, 0x72, 0x79, 0x44, 0x31, 0x45, 0x76, 0x00, 0x73, 0x68, - 0x61, 0x70, 0x65, 0x5f, 0x61, 0x64, 0x64, 0x00, 0x73, 0x68, 0x61, 0x70, - 0x65, 0x5f, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x72, 0x00, 0x73, 0x74, 0x72, - 0x6c, 0x63, 0x70, 0x79, 0x00, 0x73, 0x68, 0x61, 0x70, 0x65, 0x5f, 0x74, - 0x6f, 0x74, 0x61, 0x6c, 0x00, 0x73, 0x68, 0x61, 0x70, 0x65, 0x5f, 0x63, - 0x6f, 0x6e, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x65, 0x64, 0x00, 0x5f, - 0x5f, 0x52, 0x4f, 0x46, 0x49, 0x58, 0x55, 0x50, 0x5f, 0x4c, 0x49, 0x53, - 0x54, 0x5f, 0x5f, 0x00, 0x5f, 0x5f, 0x52, 0x4f, 0x46, 0x49, 0x58, 0x55, - 0x50, 0x5f, 0x45, 0x4e, 0x44, 0x5f, 0x5f, 0x00, 0x6c, 0x69, 0x62, 0x73, - 0x68, 0x61, 0x70, 0x65, 0x2e, 0x73, 0x6f, 0x00, 0xbc, 0x15, 0x00, 0x00, - 0x17, 0x00, 0x00, 0x00, 0xc0, 0x15, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00, - 0xc0, 0x16, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00, 0x80, 0x16, 0x00, 0x00, - 0xa4, 0x07, 0x00, 0x00, 0x88, 0x16, 0x00, 0x00, 0xa4, 0x09, 0x00, 0x00, - 0x90, 0x16, 0x00, 0x00, 0xa4, 0x0d, 0x00, 0x00, 0x98, 0x16, 0x00, 0x00, - 0xa4, 0x0e, 0x00, 0x00, 0xa0, 0x16, 0x00, 0x00, 0xa4, 0x0f, 0x00, 0x00, - 0xa8, 0x16, 0x00, 0x00, 0xa4, 0x12, 0x00, 0x00, 0xb0, 0x16, 0x00, 0x00, - 0xa4, 0x13, 0x00, 0x00, 0xb8, 0x16, 0x00, 0x00, 0xa4, 0x15, 0x00, 0x00, - 0xdf, 0xf8, 0x0c, 0xc0, 0x0c, 0xeb, 0x09, 0x0c, 0xdc, 0xf8, 0x04, 0x90, - 0xdc, 0xf8, 0x00, 0xf0, 0x0c, 0x00, 0x00, 0x00, 0xdf, 0xf8, 0x0c, 0xc0, - 0x0c, 0xeb, 0x09, 0x0c, 0xdc, 0xf8, 0x04, 0x90, 0xdc, 0xf8, 0x00, 0xf0, - 0x14, 0x00, 0x00, 0x00, 0xdf, 0xf8, 0x0c, 0xc0, 0x0c, 0xeb, 0x09, 0x0c, - 0xdc, 0xf8, 0x04, 0x90, 0xdc, 0xf8, 0x00, 0xf0, 0x1c, 0x00, 0x00, 0x00, - 0xdf, 0xf8, 0x0c, 0xc0, 0x0c, 0xeb, 0x09, 0x0c, 0xdc, 0xf8, 0x04, 0x90, - 0xdc, 0xf8, 0x00, 0xf0, 0x24, 0x00, 0x00, 0x00, 0xdf, 0xf8, 0x0c, 0xc0, - 0x0c, 0xeb, 0x09, 0x0c, 0xdc, 0xf8, 0x04, 0x90, 0xdc, 0xf8, 0x00, 0xf0, - 0x2c, 0x00, 0x00, 0x00, 0xdf, 0xf8, 0x0c, 0xc0, 0x0c, 0xeb, 0x09, 0x0c, - 0xdc, 0xf8, 0x04, 0x90, 0xdc, 0xf8, 0x00, 0xf0, 0x34, 0x00, 0x00, 0x00, - 0xdf, 0xf8, 0x0c, 0xc0, 0x0c, 0xeb, 0x09, 0x0c, 0xdc, 0xf8, 0x04, 0x90, - 0xdc, 0xf8, 0x00, 0xf0, 0x3c, 0x00, 0x00, 0x00, 0xdf, 0xf8, 0x0c, 0xc0, - 0x0c, 0xeb, 0x09, 0x0c, 0xdc, 0xf8, 0x04, 0x90, 0xdc, 0xf8, 0x00, 0xf0, - 0x44, 0x00, 0x00, 0x00, 0x10, 0xb5, 0x03, 0x4b, 0x59, 0xf8, 0x03, 0x00, - 0xff, 0xf7, 0xaa, 0xff, 0x10, 0xbd, 0x00, 0xbf, 0x4c, 0x00, 0x00, 0x00, - 0x00, 0x22, 0x07, 0x4b, 0x05, 0x49, 0x59, 0xf8, 0x03, 0x30, 0x06, 0x20, - 0xc3, 0xe9, 0x00, 0x12, 0x04, 0x49, 0x9a, 0x60, 0x79, 0x44, 0x1a, 0x73, - 0xff, 0xf7, 0xca, 0xbf, 0xe0, 0xa9, 0x5b, 0x00, 0x4c, 0x00, 0x00, 0x00, - 0x3e, 0x01, 0x00, 0x00, 0x04, 0x4b, 0x59, 0xf8, 0x03, 0x30, 0x9a, 0x68, - 0x01, 0x32, 0x9a, 0x60, 0x5a, 0x68, 0x10, 0x44, 0x58, 0x60, 0x70, 0x47, - 0x4c, 0x00, 0x00, 0x00, 0x03, 0x4b, 0x01, 0x46, 0x59, 0xf8, 0x03, 0x00, - 0x40, 0x22, 0x0c, 0x30, 0xff, 0xf7, 0xa6, 0xbf, 0x4c, 0x00, 0x00, 0x00, - 0x02, 0x4b, 0x59, 0xf8, 0x03, 0x30, 0x58, 0x68, 0x70, 0x47, 0x00, 0xbf, - 0x4c, 0x00, 0x00, 0x00, 0x05, 0x4b, 0x59, 0xf8, 0x03, 0x30, 0x18, 0x68, - 0x02, 0x4b, 0xc3, 0x1a, 0x58, 0x42, 0x58, 0x41, 0x70, 0x47, 0x00, 0xbf, - 0xe0, 0xa9, 0x5b, 0x00, 0x4c, 0x00, 0x00, 0x00, 0x2d, 0xe9, 0xf0, 0x45, - 0x1d, 0x49, 0x05, 0x46, 0x82, 0x68, 0x85, 0xb0, 0x06, 0x20, 0x79, 0x44, - 0x4c, 0x46, 0xff, 0xf7, 0x8d, 0xff, 0x2b, 0x7b, 0xa1, 0x46, 0x1b, 0xb3, - 0x18, 0x4a, 0x10, 0x21, 0x6b, 0x68, 0x7a, 0x44, 0x68, 0x46, 0xff, 0xf7, - 0x5b, 0xff, 0x05, 0xf1, 0x0c, 0x07, 0xa1, 0x46, 0x82, 0x46, 0x4f, 0xf4, - 0xd2, 0x72, 0x40, 0xf2, 0x41, 0x21, 0x38, 0x46, 0xff, 0xf7, 0x82, 0xff, - 0x06, 0x1e, 0xa1, 0x46, 0x12, 0xdb, 0x51, 0x46, 0xff, 0xf7, 0x54, 0xff, - 0x00, 0x28, 0xa1, 0x46, 0x05, 0xdb, 0x52, 0x46, 0x69, 0x46, 0x30, 0x46, - 0xff, 0xf7, 0x56, 0xff, 0xa1, 0x46, 0x30, 0x46, 0xff, 0xf7, 0x7a, 0xff, - 0x28, 0x46, 0x05, 0xb0, 0xbd, 0xe8, 0xf0, 0x85, 0x05, 0x49, 0x3a, 0x46, - 0x06, 0x20, 0x79, 0x44, 0xff, 0xf7, 0x5c, 0xff, 0xf4, 0xe7, 0x00, 0xbf, - 0x76, 0x00, 0x00, 0x00, 0x8e, 0x00, 0x00, 0x00, 0x41, 0x00, 0x00, 0x00, - 0x20, 0x20, 0x5b, 0x6c, 0x69, 0x62, 0x73, 0x68, 0x61, 0x70, 0x65, 0x5d, - 0x20, 0x7e, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x72, 0x79, 0x28, 0x29, - 0x20, 0x72, 0x61, 0x6e, 0x20, 0x61, 0x66, 0x74, 0x65, 0x72, 0x20, 0x25, - 0x64, 0x20, 0x61, 0x64, 0x64, 0x73, 0x0a, 0x00, 0x25, 0x64, 0x00, 0x20, - 0x20, 0x5b, 0x6c, 0x69, 0x62, 0x73, 0x68, 0x61, 0x70, 0x65, 0x5d, 0x20, - 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x72, 0x20, 0x25, 0x73, 0x20, 0x66, 0x61, - 0x69, 0x6c, 0x65, 0x64, 0x0a, 0x00, 0x20, 0x20, 0x5b, 0x6c, 0x69, 0x62, - 0x73, 0x68, 0x61, 0x70, 0x65, 0x5d, 0x20, 0x52, 0x65, 0x67, 0x69, 0x73, - 0x74, 0x72, 0x79, 0x28, 0x29, 0x20, 0x72, 0x61, 0x6e, 0x0a, 0x00, 0x00, - 0x74, 0x16, 0x00, 0x00, 0x45, 0x04, 0x00, 0x00, 0x31, 0x04, 0x00, 0x00, - 0x0e, 0x00, 0x00, 0x00, 0xac, 0x00, 0x00, 0x00, 0x19, 0x00, 0x00, 0x00, - 0xbc, 0x15, 0x00, 0x00, 0x1b, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x00, 0x00, 0xc0, 0x15, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xb4, 0x00, 0x00, 0x00, - 0x05, 0x00, 0x00, 0x00, 0x80, 0x02, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, - 0x20, 0x01, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0xb8, 0x00, 0x00, 0x00, - 0x0b, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, - 0x74, 0x16, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x38, 0x03, 0x00, 0x00, - 0x12, 0x00, 0x00, 0x00, 0x58, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xfb, 0xff, 0xff, 0x6f, 0x01, 0x00, 0x00, 0x00, 0xfa, 0xff, 0xff, 0x6f, - 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc4, 0x15, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xc4, 0x16, 0x00, 0x00, 0x47, 0x43, 0x43, 0x3a, 0x20, 0x28, 0x41, 0x72, - 0x6d, 0x20, 0x47, 0x4e, 0x55, 0x20, 0x54, 0x6f, 0x6f, 0x6c, 0x63, 0x68, - 0x61, 0x69, 0x6e, 0x20, 0x31, 0x35, 0x2e, 0x32, 0x2e, 0x52, 0x65, 0x6c, - 0x31, 0x20, 0x28, 0x42, 0x75, 0x69, 0x6c, 0x64, 0x20, 0x61, 0x72, 0x6d, - 0x2d, 0x31, 0x35, 0x2e, 0x38, 0x36, 0x29, 0x29, 0x20, 0x31, 0x35, 0x2e, - 0x32, 0x2e, 0x31, 0x20, 0x32, 0x30, 0x32, 0x35, 0x31, 0x32, 0x30, 0x33, - 0x00, 0x41, 0x2c, 0x00, 0x00, 0x00, 0x61, 0x65, 0x61, 0x62, 0x69, 0x00, - 0x01, 0x22, 0x00, 0x00, 0x00, 0x05, 0x37, 0x2d, 0x4d, 0x00, 0x06, 0x0a, - 0x07, 0x4d, 0x09, 0x02, 0x12, 0x04, 0x14, 0x01, 0x15, 0x01, 0x17, 0x03, - 0x18, 0x01, 0x19, 0x01, 0x1a, 0x01, 0x1e, 0x04, 0x22, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb4, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x20, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x02, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x80, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x03, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x90, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x05, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x30, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4c, 0x05, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xb8, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x08, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xbc, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x15, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xc4, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x0b, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x74, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc4, 0x16, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x0e, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x0f, 0x00, 0x32, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0xf1, 0xff, 0x01, 0x00, 0x00, 0x00, - 0xc4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, - 0x04, 0x00, 0x00, 0x00, 0x40, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x06, 0x00, 0x01, 0x00, 0x00, 0x00, 0x6c, 0x04, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x80, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x84, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x06, 0x00, 0x04, 0x00, 0x00, 0x00, 0x94, 0x04, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x98, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, - 0x04, 0x00, 0x00, 0x00, 0xa4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x06, 0x00, 0x01, 0x00, 0x00, 0x00, 0xa8, 0x04, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x04, 0x00, 0x00, 0x00, - 0xbc, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x44, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x06, 0x00, 0x07, 0x00, 0x00, 0x00, 0x45, 0x04, 0x00, 0x00, - 0x28, 0x00, 0x00, 0x00, 0x02, 0x00, 0x06, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x60, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, - 0x04, 0x00, 0x00, 0x00, 0xbc, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x09, 0x00, 0x01, 0x00, 0x00, 0x00, 0x30, 0x04, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x23, 0x00, 0x00, 0x00, - 0x31, 0x04, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x02, 0x00, 0x06, 0x00, - 0x04, 0x00, 0x00, 0x00, 0x40, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x06, 0x00, 0x04, 0x00, 0x00, 0x00, 0xc0, 0x15, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x04, 0x00, 0x00, 0x00, - 0xc4, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0d, 0x00, - 0x3f, 0x00, 0x00, 0x00, 0xc4, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x0d, 0x00, 0x49, 0x00, 0x00, 0x00, 0xc4, 0x16, 0x00, 0x00, - 0x4c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0xf1, 0xff, - 0x59, 0x00, 0x00, 0x00, 0xc4, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0xf1, 0xff, 0x62, 0x00, 0x00, 0x00, 0x74, 0x16, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x0c, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x4c, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x90, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x05, 0x00, 0x04, 0x00, 0x00, 0x00, 0xa0, 0x03, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x01, 0x00, 0x00, 0x00, - 0xa4, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, - 0x04, 0x00, 0x00, 0x00, 0xb4, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x05, 0x00, 0x01, 0x00, 0x00, 0x00, 0xb8, 0x03, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x04, 0x00, 0x00, 0x00, - 0xc8, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, - 0x01, 0x00, 0x00, 0x00, 0xcc, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x05, 0x00, 0x04, 0x00, 0x00, 0x00, 0xdc, 0x03, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x01, 0x00, 0x00, 0x00, - 0xe0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, - 0x04, 0x00, 0x00, 0x00, 0xf0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x05, 0x00, 0x01, 0x00, 0x00, 0x00, 0xf4, 0x03, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x08, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x05, 0x00, 0x04, 0x00, 0x00, 0x00, 0x18, 0x04, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x1c, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, - 0x04, 0x00, 0x00, 0x00, 0x2c, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x05, 0x00, 0x78, 0x00, 0x00, 0x00, 0xc5, 0x04, 0x00, 0x00, - 0x88, 0x00, 0x00, 0x00, 0x22, 0x00, 0x06, 0x00, 0x89, 0x00, 0x00, 0x00, - 0x6d, 0x04, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x12, 0x00, 0x06, 0x00, - 0x93, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, 0x9c, 0x00, 0x00, 0x00, 0xc5, 0x04, 0x00, 0x00, - 0x88, 0x00, 0x00, 0x00, 0x22, 0x00, 0x06, 0x00, 0xad, 0x00, 0x00, 0x00, - 0x99, 0x04, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x12, 0x00, 0x06, 0x00, - 0xb9, 0x00, 0x00, 0x00, 0xa9, 0x04, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, - 0x12, 0x00, 0x06, 0x00, 0xcb, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0xd5, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, - 0xdb, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, 0xe3, 0x00, 0x00, 0x00, 0xbc, 0x05, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x08, 0x00, 0xf3, 0x00, 0x00, 0x00, - 0xb8, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x08, 0x00, - 0x04, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, 0x0b, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x10, 0x01, 0x00, 0x00, - 0x85, 0x04, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x12, 0x00, 0x06, 0x00, - 0x1d, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, 0x00, 0x24, 0x74, 0x00, 0x24, 0x64, 0x00, 0x5f, - 0x47, 0x4c, 0x4f, 0x42, 0x41, 0x4c, 0x5f, 0x5f, 0x73, 0x75, 0x62, 0x5f, - 0x49, 0x5f, 0x6c, 0x69, 0x62, 0x73, 0x68, 0x61, 0x70, 0x65, 0x2e, 0x63, - 0x70, 0x70, 0x00, 0x5f, 0x47, 0x4c, 0x4f, 0x42, 0x41, 0x4c, 0x5f, 0x5f, - 0x73, 0x75, 0x62, 0x5f, 0x44, 0x5f, 0x6c, 0x69, 0x62, 0x73, 0x68, 0x61, - 0x70, 0x65, 0x2e, 0x63, 0x70, 0x70, 0x00, 0x2e, 0x4c, 0x41, 0x4e, 0x43, - 0x48, 0x4f, 0x52, 0x30, 0x00, 0x5f, 0x5a, 0x4c, 0x31, 0x30, 0x67, 0x5f, - 0x72, 0x65, 0x67, 0x69, 0x73, 0x74, 0x72, 0x79, 0x00, 0x5f, 0x44, 0x59, - 0x4e, 0x41, 0x4d, 0x49, 0x43, 0x00, 0x5f, 0x47, 0x4c, 0x4f, 0x42, 0x41, - 0x4c, 0x5f, 0x4f, 0x46, 0x46, 0x53, 0x45, 0x54, 0x5f, 0x54, 0x41, 0x42, - 0x4c, 0x45, 0x5f, 0x00, 0x5f, 0x5a, 0x4e, 0x38, 0x52, 0x65, 0x67, 0x69, - 0x73, 0x74, 0x72, 0x79, 0x44, 0x31, 0x45, 0x76, 0x00, 0x73, 0x68, 0x61, - 0x70, 0x65, 0x5f, 0x61, 0x64, 0x64, 0x00, 0x73, 0x6e, 0x70, 0x72, 0x69, - 0x6e, 0x74, 0x66, 0x00, 0x5f, 0x5a, 0x4e, 0x38, 0x52, 0x65, 0x67, 0x69, - 0x73, 0x74, 0x72, 0x79, 0x44, 0x32, 0x45, 0x76, 0x00, 0x73, 0x68, 0x61, - 0x70, 0x65, 0x5f, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x00, 0x73, 0x68, 0x61, - 0x70, 0x65, 0x5f, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, - 0x65, 0x64, 0x00, 0x66, 0x74, 0x72, 0x75, 0x6e, 0x63, 0x61, 0x74, 0x65, - 0x00, 0x77, 0x72, 0x69, 0x74, 0x65, 0x00, 0x73, 0x74, 0x72, 0x6c, 0x63, - 0x70, 0x79, 0x00, 0x5f, 0x5f, 0x52, 0x4f, 0x46, 0x49, 0x58, 0x55, 0x50, - 0x5f, 0x45, 0x4e, 0x44, 0x5f, 0x5f, 0x00, 0x5f, 0x5f, 0x52, 0x4f, 0x46, - 0x49, 0x58, 0x55, 0x50, 0x5f, 0x4c, 0x49, 0x53, 0x54, 0x5f, 0x5f, 0x00, - 0x73, 0x79, 0x73, 0x6c, 0x6f, 0x67, 0x00, 0x6f, 0x70, 0x65, 0x6e, 0x00, - 0x73, 0x68, 0x61, 0x70, 0x65, 0x5f, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x72, - 0x00, 0x63, 0x6c, 0x6f, 0x73, 0x65, 0x00, 0x00, 0x2e, 0x73, 0x79, 0x6d, - 0x74, 0x61, 0x62, 0x00, 0x2e, 0x73, 0x74, 0x72, 0x74, 0x61, 0x62, 0x00, - 0x2e, 0x73, 0x68, 0x73, 0x74, 0x72, 0x74, 0x61, 0x62, 0x00, 0x2e, 0x68, - 0x61, 0x73, 0x68, 0x00, 0x2e, 0x64, 0x79, 0x6e, 0x73, 0x79, 0x6d, 0x00, - 0x2e, 0x64, 0x79, 0x6e, 0x73, 0x74, 0x72, 0x00, 0x2e, 0x72, 0x65, 0x6c, - 0x2e, 0x64, 0x79, 0x6e, 0x00, 0x2e, 0x70, 0x6c, 0x74, 0x00, 0x2e, 0x74, - 0x65, 0x78, 0x74, 0x00, 0x2e, 0x72, 0x6f, 0x64, 0x61, 0x74, 0x61, 0x00, - 0x2e, 0x72, 0x6f, 0x66, 0x69, 0x78, 0x75, 0x70, 0x00, 0x2e, 0x69, 0x6e, - 0x69, 0x74, 0x5f, 0x61, 0x72, 0x72, 0x61, 0x79, 0x00, 0x2e, 0x66, 0x69, - 0x6e, 0x69, 0x5f, 0x61, 0x72, 0x72, 0x61, 0x79, 0x00, 0x2e, 0x64, 0x79, - 0x6e, 0x61, 0x6d, 0x69, 0x63, 0x00, 0x2e, 0x67, 0x6f, 0x74, 0x00, 0x2e, - 0x62, 0x73, 0x73, 0x00, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, - 0x00, 0x2e, 0x41, 0x52, 0x4d, 0x2e, 0x61, 0x74, 0x74, 0x72, 0x69, 0x62, - 0x75, 0x74, 0x65, 0x73, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x1b, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, - 0xb4, 0x00, 0x00, 0x00, 0xb4, 0x00, 0x00, 0x00, 0x6c, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, 0x21, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, 0x20, 0x01, 0x00, 0x00, 0x20, 0x01, 0x00, 0x00, - 0x60, 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x29, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x80, 0x02, 0x00, 0x00, - 0x80, 0x02, 0x00, 0x00, 0xb8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x31, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, - 0x38, 0x03, 0x00, 0x00, 0x38, 0x03, 0x00, 0x00, 0x58, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, 0x3a, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x06, 0x00, 0x00, 0x00, 0x90, 0x03, 0x00, 0x00, 0x90, 0x03, 0x00, 0x00, - 0xa0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x30, 0x04, 0x00, 0x00, - 0x30, 0x04, 0x00, 0x00, 0x1c, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x45, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x32, 0x00, 0x00, 0x00, - 0x4c, 0x05, 0x00, 0x00, 0x4c, 0x05, 0x00, 0x00, 0x6b, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x4d, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, 0xb8, 0x05, 0x00, 0x00, 0xb8, 0x05, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x56, 0x00, 0x00, 0x00, - 0x0e, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0xbc, 0x15, 0x00, 0x00, - 0xbc, 0x05, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x62, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, - 0xc0, 0x15, 0x00, 0x00, 0xc0, 0x05, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, 0x6e, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, 0xc4, 0x15, 0x00, 0x00, 0xc4, 0x05, 0x00, 0x00, - 0xb0, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x77, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x74, 0x16, 0x00, 0x00, - 0x74, 0x06, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x7c, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, - 0xc4, 0x16, 0x00, 0x00, 0xc4, 0x06, 0x00, 0x00, 0x4c, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x81, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc4, 0x06, 0x00, 0x00, - 0x45, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x8a, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x09, 0x07, 0x00, 0x00, 0x2d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x38, 0x07, 0x00, 0x00, 0x90, 0x04, 0x00, 0x00, - 0x11, 0x00, 0x00, 0x00, 0x3a, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc8, 0x0b, 0x00, 0x00, - 0x23, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xeb, 0x0c, 0x00, 0x00, 0x9a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 -}; - -static const unsigned int g_libshape_len = 4224; diff --git a/examples/fdpicxip/modules/.gitignore b/examples/fdpicxip/modules/.gitignore deleted file mode 100644 index 8c3555579..000000000 --- a/examples/fdpicxip/modules/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -/*.fdpic -/*.so -/.nuttx-exports -/manyneeded.c -/need*.c diff --git a/examples/fdpicxip/modules/Makefile b/examples/fdpicxip/modules/Makefile deleted file mode 100644 index 56dfd7ebb..000000000 --- a/examples/fdpicxip/modules/Makefile +++ /dev/null @@ -1,205 +0,0 @@ -############################################################################ -# apps/examples/fdpicxip/modules/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -# The FDPIC modules that examples/fdpicxip and testing/fs/xipfs carry inside -# their images, and the sources they are built from. -# -# This is NOT part of the application build. Nothing here runs unless it is -# asked for: the *_bin.h headers are committed, so both apps build with a -# plain toolchain and CI covers them, while the link needs -# arm-uclinuxfdpiceabi binutils, which the tree does not require. See -# nuttx/tools/fdpic/README.md and Documentation/components/fdpic.rst. -# -# To rebuild the headers from these sources: -# -# make -C apps/examples/fdpicxip/modules regen NUTTX_DIR=/path/to/nuttx -# -# NUTTX_DIR must be a configured, built tree with CONFIG_FDPIC and a system -# symbol table: the compile needs its headers and the verify step needs -# libs/libc/exec_symtab.c. -# -# CPU is cortex-m3 rather than the toolchain default, deliberately. A v7-M -# module runs on both the v7-M and v8-M targets, so one set of blobs serves -# the RP2350 (Cortex-M33) and mps2-an500 (Cortex-M7) alike. Building for -# cortex-m33 produces blobs the M7 cannot execute at all. - -CPU ?= cortex-m3 - -FDPICDIR = $(NUTTX_DIR)/tools/fdpic -MODULE_MK = $(FDPICDIR)/nuttx-fdpic.mk -EMBED = $(FDPICDIR)/fdpic-embed - -# Where each generated header goes, and its path from the repository root -- -# fdpic-embed puts that on line 2, which is what nxstyle wants. - -DEMODIR = .. -DEMOREL = apps/examples/fdpicxip -TESTDIR = ../../../testing/fs/xipfs -TESTREL = apps/testing/fs/xipfs - -BUILD = $(MAKE) -f $(MODULE_MK) NUTTX_DIR=$(NUTTX_DIR) CPU=$(CPU) - -# manyneeded needs one library per DT_NEEDED entry, one more than the loader -# will follow. They exist only to make the linker record nine entries; the -# module is refused while its dynamic section is parsed, before any of them -# would be loaded, so none of them is embedded. - -NEEDLIBS := $(foreach n,0 1 2 3 4 5 6 7 8,need$(n).so) - -DEMO_HDRS = $(DEMODIR)/qsorter_bin.h $(DEMODIR)/libcounter_bin.h \ - $(DEMODIR)/user_bin.h $(DEMODIR)/libshape_bin.h \ - $(DEMODIR)/cxxuser_bin.h $(DEMODIR)/lazymod_bin.h - -TEST_HDRS = $(TESTDIR)/callback_bin.h $(TESTDIR)/counteruser_bin.h \ - $(TESTDIR)/cxxuser_bin.h $(TESTDIR)/funcdesc_bin.h \ - $(TESTDIR)/lazymod_bin.h $(TESTDIR)/libcounter_bin.h \ - $(TESTDIR)/libshape_bin.h $(TESTDIR)/manyneeded_bin.h \ - $(TESTDIR)/missingsym_bin.h - -.PHONY: all regen check-nuttx-dir clean - -all: - @echo "Nothing to do: the *_bin.h headers are committed." - @echo "To rebuild them: make regen NUTTX_DIR=/path/to/nuttx" - -regen: check-nuttx-dir $(DEMO_HDRS) $(TEST_HDRS) - @echo "Regenerated the embedded modules for $(DEMOREL) and $(TESTREL)." - -check-nuttx-dir: -ifeq ($(NUTTX_DIR),) - $(error Set NUTTX_DIR to a configured, built NuttX tree) -endif - -# The modules. Libraries have no entry point and are named by their SONAME, -# which is what a consumer records in DT_NEEDED and what the loader searches -# for at run time. - -qsorter.fdpic: qsorter.c - $(BUILD) MODULE=qsorter SRCS=qsorter.c - -callback.fdpic: callback.c - $(BUILD) MODULE=callback SRCS=callback.c - -funcdesc.fdpic: funcdesc.c - $(BUILD) MODULE=funcdesc SRCS=funcdesc.c - -libcounter.so: libcounter.c - $(BUILD) MODULE=libcounter SRCS=libcounter.c ENTRY=0 \ - EXTRA_LDFLAGS="-soname libcounter.so" - mv libcounter.fdpic libcounter.so - -user.fdpic: user.c libcounter.so - $(BUILD) MODULE=user SRCS=user.c LIBS=libcounter.so - -# C++ compiles with the stock arm-none-eabi-g++; only the link is FDPIC. - -libshape.so: libshape.cpp - $(BUILD) MODULE=libshape CXXSRCS=libshape.cpp ENTRY=0 \ - EXTRA_LDFLAGS="-soname libshape.so" - mv libshape.fdpic libshape.so - -cxxuser.fdpic: cxxuser.cpp libshape.so - $(BUILD) MODULE=cxxuser CXXSRCS=cxxuser.cpp LIBS=libshape.so - -# BINDNOW is emptied so the imported descriptors stay in the lazy binding -# table, which is the case this module exists to cover. - -lazymod.fdpic: lazymod.c - $(BUILD) MODULE=lazymod SRCS=lazymod.c BINDNOW= - -# missingsym is linked with the bare .fdpic target rather than the default -# 'verify' one, because it is exactly what fdpic-verify is meant to catch. - -missingsym.fdpic: missingsym.c - $(BUILD) MODULE=missingsym SRCS=missingsym.c missingsym.fdpic - -need%.so: - echo "int need_leaf_$*(void){return $*;}" > need$*.c - $(BUILD) MODULE=need$* SRCS=need$*.c ENTRY=0 \ - EXTRA_LDFLAGS="-soname need$*.so" - mv need$*.fdpic need$*.so - -manyneeded.c: $(NEEDLIBS) - { for n in 0 1 2 3 4 5 6 7 8; do \ - echo "extern int need_leaf_$$n(void);"; done; \ - echo "int main(int argc, char *argv[]) {"; \ - echo " return need_leaf_0() + need_leaf_1() + need_leaf_2() +"; \ - echo " need_leaf_3() + need_leaf_4() + need_leaf_5() +"; \ - echo " need_leaf_6() + need_leaf_7() + need_leaf_8();"; \ - echo "}"; } > manyneeded.c - -manyneeded.fdpic: manyneeded.c $(NEEDLIBS) - $(BUILD) MODULE=manyneeded SRCS=manyneeded.c LIBS="$(NEEDLIBS)" \ - manyneeded.fdpic - -# The headers. One artifact can be embedded under more than one name: the -# demo's user_bin.h and the suite's counteruser_bin.h are the same module. - -$(DEMODIR)/qsorter_bin.h: qsorter.fdpic - $(EMBED) $< g_qsorter_nxf $(DEMOREL)/$(@F) > $@ - -$(DEMODIR)/libcounter_bin.h: libcounter.so - $(EMBED) $< g_libcounter $(DEMOREL)/$(@F) > $@ - -$(DEMODIR)/user_bin.h: user.fdpic - $(EMBED) $< g_user $(DEMOREL)/$(@F) > $@ - -$(DEMODIR)/libshape_bin.h: libshape.so - $(EMBED) $< g_libshape $(DEMOREL)/$(@F) > $@ - -$(DEMODIR)/cxxuser_bin.h: cxxuser.fdpic - $(EMBED) $< g_cxxuser $(DEMOREL)/$(@F) > $@ - -$(DEMODIR)/lazymod_bin.h: lazymod.fdpic - $(EMBED) $< g_lazymod $(DEMOREL)/$(@F) > $@ - -$(TESTDIR)/callback_bin.h: callback.fdpic - $(EMBED) $< g_callback $(TESTREL)/$(@F) > $@ - -$(TESTDIR)/counteruser_bin.h: user.fdpic - $(EMBED) $< g_counteruser $(TESTREL)/$(@F) > $@ - -$(TESTDIR)/cxxuser_bin.h: cxxuser.fdpic - $(EMBED) $< g_cxxuser $(TESTREL)/$(@F) > $@ - -$(TESTDIR)/funcdesc_bin.h: funcdesc.fdpic - $(EMBED) $< g_funcdesc $(TESTREL)/$(@F) > $@ - -$(TESTDIR)/lazymod_bin.h: lazymod.fdpic - $(EMBED) $< g_lazymod $(TESTREL)/$(@F) > $@ - -$(TESTDIR)/libcounter_bin.h: libcounter.so - $(EMBED) $< g_libcounter $(TESTREL)/$(@F) > $@ - -$(TESTDIR)/libshape_bin.h: libshape.so - $(EMBED) $< g_libshape $(TESTREL)/$(@F) > $@ - -$(TESTDIR)/manyneeded_bin.h: manyneeded.fdpic - $(EMBED) $< g_manyneeded $(TESTREL)/$(@F) > $@ - -$(TESTDIR)/missingsym_bin.h: missingsym.fdpic - $(EMBED) $< g_missingsym $(TESTREL)/$(@F) > $@ - -# No NUTTX_DIR needed to clean. - -clean: - $(Q) rm -f *.o *.fdpic *.so .nuttx-exports need*.c manyneeded.c diff --git a/examples/fdpicxip/modules/callback.c b/examples/fdpicxip/modules/callback.c deleted file mode 100644 index 1a1b33325..000000000 --- a/examples/fdpicxip/modules/callback.c +++ /dev/null @@ -1,517 +0,0 @@ -/**************************************************************************** - * apps/examples/fdpicxip/modules/callback.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/* Hands a module function to the firmware every way the firmware will - * accept one. - * - * In FDPIC a function pointer is the address of a two-word descriptor, not - * a code address, and that descriptor lives in the module's writable - * segment in RAM. Firmware that stores such a pointer and later branches to - * it therefore jumps into the module's *data* and faults -- unless the entry - * point it came through resolved the descriptor first. - * - * qsort and bsearch have always done that. pthread_create, signal and - * task_create did not, which made them look usable and then take the board - * down; pthread_once, task_spawn, scandir's filter and sigaction followed - * later. This module is what keeps all of them honest. - * - * scandir is one worth noting: its filter is called by scandir itself and - * must be resolved there, while its comparison function is handed to qsort, - * which resolves it. Resolving both would be a bug, so both are passed here - * at once. - * - * mq_notify and timer_create with SIGEV_THREAD are the interesting ones: - * their callback runs on a work-queue worker that carries no module data - * base. The base is captured at registration and installed around the call, - * so the callback still reaches the module's own globals. Each is checked - * by having the callback write a distinctive value into a module global. - * - * Everything is checked by observing a side effect the callback itself - * produces, because a callback that never runs is the failure being tested - * for -- and on this target the alternative failure is a HardFault, which - * reports nothing at all. - */ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <dirent.h> -#include <fcntl.h> -#include <mqueue.h> -#include <pthread.h> -#include <sched.h> -#include <signal.h> -#include <spawn.h> -#include <stdlib.h> -#include <string.h> -#include <syslog.h> -#include <time.h> -#include <unistd.h> - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define FAIL_QSORT 0x01 -#define FAIL_PTHREAD 0x02 -#define FAIL_SIGNAL 0x04 -#define FAIL_TASK 0x08 -#define FAIL_ONCE 0x10 -#define FAIL_SPAWN 0x20 -#define FAIL_SCANDIR 0x40 -#define FAIL_SIGACTION 0x80 - -/* The mq checks run under "callback mq" and report in their own byte, so the - * exit status -- only eight bits survive waitpid -- never has to hold more - * than eight flags at once. - */ - -#define FAIL_MQ_THREAD 0x01 -#define FAIL_MQ_SIGNAL 0x02 -#define FAIL_TIMER_THREAD 0x04 - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/* Written by the callbacks, read by main. These live in the module's - * writable segment, which is what the callback can only reach if it was - * entered with this module's data base in the FDPIC register. - */ - -static volatile int g_qsort_calls; -static volatile int g_thread_ran; -static volatile int g_signal_ran; -static volatile int g_task_ran; -static volatile int g_once_ran; -static volatile int g_spawn_ran; -static volatile int g_filter_calls; -static volatile int g_compar_calls; -static volatile int g_sigaction_ran; -static volatile int g_mq_signal_ran; -static volatile int g_mq_thread_ran; -static volatile int g_timer_thread_ran; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static int cmp_int(const void *a, const void *b) -{ - g_qsort_calls++; - return *(const int *)a - *(const int *)b; -} - -static void *thread_main(void *arg) -{ - g_thread_ran = (int)(intptr_t)arg; - return NULL; -} - -static void sig_handler(int signo) -{ - g_signal_ran = signo; -} - -static void sigaction_handler(int signo, siginfo_t *info, void *context) -{ - g_sigaction_ran = signo; -} - -static void mq_signal_handler(int signo, siginfo_t *info, void *context) -{ - g_mq_signal_ran = signo; -} - -static void mq_thread_notify(union sigval value) -{ - /* Runs on a work-queue worker, which carries no module data base of its - * own. Writing this module global proves the base was installed around - * the call -- without it this store would fault or land nowhere. - */ - - g_mq_thread_ran = value.sival_int; -} - -static void timer_thread_notify(union sigval value) -{ - g_timer_thread_ran = value.sival_int; -} - -static int task_main(int argc, char *argv[]) -{ - g_task_ran = 1; - return 0; -} - -static void once_routine(void) -{ - g_once_ran++; -} - -static int spawn_main(int argc, char *argv[]) -{ - g_spawn_ran = 1; - return 0; -} - -static int dir_filter(const struct dirent *entry) -{ - g_filter_calls++; - return 1; -} - -static int dir_compar(const struct dirent **a, const struct dirent **b) -{ - g_compar_calls++; - return strcmp((*a)->d_name, (*b)->d_name); -} - -/* The message-queue checks run as a second invocation, "callback mq", so - * their two flags report in a byte of their own rather than overflowing the - * eight-bit exit status the other checks already fill. - */ - -static int run_mq(void) -{ - struct mq_attr attr; - struct sigaction sa; - struct sigevent ev; - struct itimerspec its; - timer_t timer; - mqd_t mqd; - int fails = 0; - int i; - - attr.mq_maxmsg = 1; - attr.mq_msgsize = 1; - attr.mq_flags = 0; - - mqd = mq_open("/cbmq", O_CREAT | O_RDWR, 0644, &attr); - if (mqd == (mqd_t)-1) - { - return FAIL_MQ_THREAD | FAIL_MQ_SIGNAL | FAIL_TIMER_THREAD; - } - - /* mq_notify with SIGEV_THREAD. The callback runs on a work-queue worker - * that carries no module data base of its own; the base captured at - * registration is installed around the call, so the callback reaches this - * module's globals. A distinctive sival marks that the right callback - * ran with the right argument. - */ - - memset(&ev, 0, sizeof(ev)); - ev.sigev_notify = SIGEV_THREAD; - ev.sigev_notify_function = mq_thread_notify; - ev.sigev_value.sival_int = 0x5a; - - if (mq_notify(mqd, &ev) < 0) - { - fails |= FAIL_MQ_THREAD; - } - else - { - char buf[1]; - - /* The notification fires on a send to an empty queue; drain the - * message afterwards so the queue is empty for the next test and the - * next send does not block on a full queue. - */ - - mq_send(mqd, "x", 1, 0); - - for (i = 0; i < 50 && g_mq_thread_ran == 0; i++) - { - usleep(10000); - } - - mq_receive(mqd, buf, sizeof(buf), NULL); - - if (g_mq_thread_ran != 0x5a) - { - fails |= FAIL_MQ_THREAD; - } - } - - /* mq_notify with SIGEV_SIGNAL, delivered to this task and caught by a - * handler installed through sigaction. - */ - - memset(&sa, 0, sizeof(sa)); - sa.sa_sigaction = mq_signal_handler; - sa.sa_flags = SA_SIGINFO; - sigaction(SIGUSR1, &sa, NULL); - - memset(&ev, 0, sizeof(ev)); - ev.sigev_notify = SIGEV_SIGNAL; - ev.sigev_signo = SIGUSR1; - - if (mq_notify(mqd, &ev) < 0) - { - fails |= FAIL_MQ_SIGNAL; - } - else - { - char buf[1]; - - mq_send(mqd, "x", 1, 0); - - for (i = 0; i < 50 && g_mq_signal_ran == 0; i++) - { - usleep(10000); - } - - mq_receive(mqd, buf, sizeof(buf), NULL); - - if (g_mq_signal_ran != SIGUSR1) - { - fails |= FAIL_MQ_SIGNAL; - } - } - - mq_close(mqd); - mq_unlink("/cbmq"); - - /* timer_create with SIGEV_THREAD reaches the module the same way: the - * expiry callback runs on the worker with the module's base installed. - */ - - memset(&ev, 0, sizeof(ev)); - ev.sigev_notify = SIGEV_THREAD; - ev.sigev_notify_function = timer_thread_notify; - ev.sigev_value.sival_int = 0xa5; - - if (timer_create(CLOCK_MONOTONIC, &ev, &timer) < 0) - { - fails |= FAIL_TIMER_THREAD; - } - else - { - its.it_value.tv_sec = 0; - its.it_value.tv_nsec = 20 * 1000 * 1000; - its.it_interval.tv_sec = 0; - its.it_interval.tv_nsec = 0; - timer_settime(timer, 0, &its, NULL); - - for (i = 0; i < 50 && g_timer_thread_ran == 0; i++) - { - usleep(10000); - } - - if (g_timer_thread_ran != 0xa5) - { - fails |= FAIL_TIMER_THREAD; - } - - timer_delete(timer); - } - - syslog(LOG_INFO, - "[callback] mq_thread=%#x mq_signal=%d timer_thread=%#x -- %s\n", - g_mq_thread_ran, g_mq_signal_ran, g_timer_thread_ran, - fails == 0 ? "PASS" : "FAIL"); - - return fails; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -int main(int argc, char *argv[]) -{ - int v[5] = - { - 5, 3, 1, 4, 2 - }; - - struct dirent **namelist; - pthread_once_t once = PTHREAD_ONCE_INIT; - struct sigaction sa; - pthread_t tid; - int fails = 0; - int n; - int i; - - if (argc > 1 && strcmp(argv[1], "mq") == 0) - { - return run_mq(); - } - - /* qsort -- the path that always worked */ - - qsort(v, 5, sizeof(int), cmp_int); - if (g_qsort_calls == 0 || v[0] != 1 || v[4] != 5) - { - fails |= FAIL_QSORT; - } - - /* pthread_create. The thread inherits this module's D-Space, so it can - * reach g_thread_ran only if it was entered at the right address. - */ - - if (pthread_create(&tid, NULL, thread_main, (void *)(intptr_t)7) != 0) - { - fails |= FAIL_PTHREAD; - } - else - { - pthread_join(tid, NULL); - if (g_thread_ran != 7) - { - fails |= FAIL_PTHREAD; - } - } - - /* signal, delivered to this task */ - - if (signal(SIGUSR1, sig_handler) == SIG_ERR) - { - fails |= FAIL_SIGNAL; - } - else - { - /* raise() rather than kill(getpid(), ...): getpid is not in the - * firmware's export list, and raise targets the calling thread, which - * is exactly what this is checking. - */ - - raise(SIGUSR1); - - for (i = 0; i < 50 && g_signal_ran == 0; i++) - { - usleep(10000); - } - - if (g_signal_ran != SIGUSR1) - { - fails |= FAIL_SIGNAL; - } - } - - /* task_create. A separate task, but the same D-Space. */ - - if (task_create("cbtask", SCHED_PRIORITY_DEFAULT, 2048, task_main, - NULL) < 0) - { - fails |= FAIL_TASK; - } - else - { - for (i = 0; i < 50 && g_task_ran == 0; i++) - { - usleep(10000); - } - - if (g_task_ran == 0) - { - fails |= FAIL_TASK; - } - } - - /* sigaction, delivered to this task. signal() above resolves the handler - * before calling sigaction; this reaches sigaction directly, which is the - * path signal() does not cover. - */ - - memset(&sa, 0, sizeof(sa)); - sa.sa_sigaction = sigaction_handler; - sa.sa_flags = SA_SIGINFO; - - if (sigaction(SIGUSR2, &sa, NULL) < 0) - { - fails |= FAIL_SIGACTION; - } - else - { - raise(SIGUSR2); - - for (i = 0; i < 50 && g_sigaction_ran == 0; i++) - { - usleep(10000); - } - - if (g_sigaction_ran != SIGUSR2) - { - fails |= FAIL_SIGACTION; - } - } - - /* pthread_once. Runs on this thread, so only the code address matters. */ - - if (pthread_once(&once, once_routine) != 0 || g_once_ran != 1) - { - fails |= FAIL_ONCE; - } - - /* task_spawn. Like task_create, a separate task with the same D-Space. */ - - if (task_spawn("cbspawn", spawn_main, NULL, NULL, NULL, NULL) < 0) - { - fails |= FAIL_SPAWN; - } - else - { - for (i = 0; i < 50 && g_spawn_ran == 0; i++) - { - usleep(10000); - } - - if (g_spawn_ran == 0) - { - fails |= FAIL_SPAWN; - } - } - - /* scandir takes two callbacks that reach the module by different routes: - * the filter is called by scandir itself, while the comparison function is - * handed to qsort. Passing both at once is the point -- it is what would - * catch the comparison function being resolved twice. - */ - - namelist = NULL; - n = scandir("/mnt/xipfs", &namelist, dir_filter, dir_compar); - if (n < 0 || g_filter_calls == 0) - { - fails |= FAIL_SCANDIR; - } - - if (namelist != NULL) - { - while (n-- > 0) - { - free(namelist[n]); - } - - free(namelist); - } - - syslog(LOG_INFO, - "[callback] qsort=%d pthread=%d signal=%d task=%d sigaction=%d " - "once=%d spawn=%d filter=%d compar=%d -- %s\n", - g_qsort_calls, g_thread_ran, g_signal_ran, g_task_ran, - g_sigaction_ran, g_once_ran, g_spawn_ran, g_filter_calls, - g_compar_calls, fails == 0 ? "PASS" : "FAIL"); - - return fails; -} diff --git a/examples/fdpicxip/modules/cxxuser.cpp b/examples/fdpicxip/modules/cxxuser.cpp deleted file mode 100644 index 5c27cf575..000000000 --- a/examples/fdpicxip/modules/cxxuser.cpp +++ /dev/null @@ -1,210 +0,0 @@ -/**************************************************************************** - * apps/examples/fdpicxip/modules/cxxuser.cpp - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/* A C++ module using a C++ shared library. - * - * Two instances of this run at once in the demo. Between them they show - * the three things that have to hold: - * - * - constructors ran, in both objects. Neither magic can be right by - * accident: an unconstructed global is zero. - * - the library's constructors ran before this module's, which is the - * ordering DT_NEEDED implies and the loader has to honour. - * - the library's data is private per instance. One copy of its code - * sits in flash; the totals do not interleave. - */ - -#include <fcntl.h> -#include <stdio.h> -#include <stdlib.h> -#include <syslog.h> -#include <unistd.h> - -extern "C" -{ - int shape_add(int by); - int shape_total(void); - bool shape_constructed(void); - void shape_marker(const char *path); -} - -#define USER_MAGIC 0x0c1a55 - -class Instance -{ -public: - Instance() : m_magic(USER_MAGIC), m_libwasready(shape_constructed()) - { - } - - bool constructed() const - { - return m_magic == USER_MAGIC; - } - - /* Whether the library was already constructed when this object's own - * constructor ran. Sampling it here is the only way to observe the - * ordering: by the time main() runs, both have been constructed either - * way. - */ - - bool libwasready() const - { - return m_libwasready; - } - -private: - int m_magic; - bool m_libwasready; -}; - -static Instance g_self; - -/* Exit status is a bitmask of what failed, so one run reports on all four - * properties independently. Kept in step with the reader in - * apps/testing/fs/xipfs/. - */ - -#define USER_FAIL_OWN_CTOR 0x01 -#define USER_FAIL_LIB_CTOR 0x02 -#define USER_FAIL_ORDER 0x04 -#define USER_FAIL_PRIVATE 0x08 - -/**************************************************************************** - * Name: record - * - * Description: - * Write a number to a file, for a caller that cannot rely on this task's - * exit status. - * - * It cannot, in general. waitpid() only retains the status of a child - * that has already exited when CONFIG_SCHED_CHILD_STATUS is set, and that - * depends on CONFIG_SCHED_HAVE_PARENT. With two instances running for - * the same length of time, the second has always exited by the time the - * first waitpid() returns, so its status is simply gone. A file survives - * the task, and survives the module being unloaded. - * - ****************************************************************************/ - -static void record(const char *path, int value) -{ - char text[16]; - int len; - int fd; - - if (path == NULL) - { - return; - } - - len = snprintf(text, sizeof(text), "%d", value); - - fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0644); - if (fd < 0) - { - syslog(LOG_INFO, "[user] cannot record to %s\n", path); - return; - } - - /* xipfs wants the size declared up front so it can reserve one - * contiguous extent. - */ - - if (ftruncate(fd, len) >= 0) - { - write(fd, text, len); - } - - close(fd); -} - -extern "C" int main(int argc, char *argv[]) -{ - int seed = (argc > 1) ? atoi(argv[1]) : 1; - int fails = 0; - int i; - - /* Optional second argument: a path for the library's destructor to record - * its final total in. A destructor runs at unload, after this task is - * gone, so leaving a file behind is the only way a test can observe that - * it ran at all. The demo omits it and reads the log instead. - */ - - if (argc > 2) - { - shape_marker(argv[2]); - } - - syslog(LOG_INFO, "[user %d] own ctor ran: %s, library ctor ran: %s, " - "library first: %s\n", - seed, - g_self.constructed() ? "yes" : "NO", - shape_constructed() ? "yes" : "NO", - g_self.libwasready() ? "yes" : "NO"); - - /* Every check runs and contributes a bit, rather than the first failure - * returning early. A caller that reports these individually can then say - * which property broke instead of just that something did -- and none of - * its assertions pass merely because an earlier one stopped the run. - */ - - if (!g_self.constructed()) - { - fails |= USER_FAIL_OWN_CTOR; - } - - if (!shape_constructed()) - { - fails |= USER_FAIL_LIB_CTOR; - } - - if (!g_self.libwasready()) - { - fails |= USER_FAIL_ORDER; - } - - for (i = 0; i < 3; i++) - { - shape_add(seed); - usleep(100000); - } - - if (shape_total() != seed * 3) - { - fails |= USER_FAIL_PRIVATE; - } - - syslog(LOG_INFO, "[user %d] library total = %d (expected %d) -- %s\n", - seed, shape_total(), seed * 3, - fails == 0 ? "PASS" : "FAIL"); - - /* Optional third argument: where to record the bitmask, for a caller that - * cannot rely on the exit status surviving. See record() above. - */ - - if (argc > 3) - { - record(argv[3], fails); - } - - return fails; -} diff --git a/examples/fdpicxip/modules/funcdesc.c b/examples/fdpicxip/modules/funcdesc.c deleted file mode 100644 index 850715474..000000000 --- a/examples/fdpicxip/modules/funcdesc.c +++ /dev/null @@ -1,156 +0,0 @@ -/**************************************************************************** - * apps/examples/fdpicxip/modules/funcdesc.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/* Exercises R_ARM_FUNCDESC -- the relocation that asks the loader to - * manufacture a function descriptor and hand back its address. - * - * It is emitted for an *address-taken imported* function, which is a - * different thing from a called one. A call gets a PLT entry and an - * R_ARM_FUNCDESC_VALUE relocation on a descriptor the linker already laid - * out; taking the address instead needs a pointer to a descriptor that does - * not exist yet, so the loader carves one out of the pool it reserves - * behind the writable segment. No other module here emits one, which is - * why this exists. - * - * Every pointer here is called *through*, not merely printed: a descriptor - * with the wrong entry or the wrong GOT half only shows up when it is - * branched through. - */ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <stdlib.h> -#include <string.h> -#include <syslog.h> - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -typedef int (*atoifn)(const char *); -typedef void *(*memcpyfn)(void *, const void *, size_t); -typedef int (*strcmpfn)(const char *, const char *); -typedef void (*qsortfn)(void *, size_t, size_t, - int (*)(const void *, const void *)); - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/* volatile is load bearing, and the reason is worth knowing before anyone - * tidies it away. - * - * Without it these are static pointers that are never written, so GCC - * constant-propagates them, turns every indirect call back into a direct - * one, and deletes the variables. The descriptor address then never has to - * materialise, the linker emits R_ARM_FUNCDESC_VALUE for the direct calls - * instead, and not one R_ARM_FUNCDESC survives -- the module still builds, - * still runs, still passes, and tests nothing it claims to. - * - * volatile forces each pointer to be loaded from memory at the point of - * call, which is what makes the slot genuinely hold the address of a - * descriptor the loader has to supply. - */ - -static atoifn volatile g_atoi = atoi; -static memcpyfn volatile g_memcpy = memcpy; -static strcmpfn volatile g_strcmp = strcmp; -static qsortfn volatile g_qsort = qsort; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/* A local function's address is R_ARM_FUNCDESC_VALUE, not FUNCDESC -- the - * linker can lay that descriptor out itself. Kept here so the module - * exercises both kinds side by side. - */ - -static int cmp_int(const void *a, const void *b) -{ - return *(const int *)a - *(const int *)b; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -int main(int argc, char *argv[]) -{ - int v[5] = - { - 5, 3, 1, 4, 2 - }; - - int copy[5]; - char buf[8]; - int seed; - int fails = 0; - int i; - - seed = g_atoi((argc > 1) ? argv[1] : "7"); - if (seed != 7 && seed != 1 && seed != 2) - { - syslog(LOG_INFO, "[funcdesc] FAIL atoi through a descriptor: %d\n", - seed); - fails++; - } - - g_memcpy(copy, v, sizeof(v)); - for (i = 0; i < 5; i++) - { - if (copy[i] != v[i]) - { - syslog(LOG_INFO, "[funcdesc] FAIL memcpy through a descriptor\n"); - fails++; - break; - } - } - - g_memcpy(buf, "abcdef", 7); - if (g_strcmp(buf, "abcdef") != 0) - { - syslog(LOG_INFO, "[funcdesc] FAIL strcmp through a descriptor\n"); - fails++; - } - - /* A manufactured descriptor for qsort, called with a descriptor for a - * function of our own -- so the firmware calls back into module code - * that has to arrive with this module's data base in the FDPIC register. - */ - - g_qsort(copy, 5, sizeof(int), cmp_int); - for (i = 0; i < 5; i++) - { - if (copy[i] != i + 1) - { - syslog(LOG_INFO, "[funcdesc] FAIL qsort through a descriptor\n"); - fails++; - break; - } - } - - syslog(LOG_INFO, "[funcdesc] seed %d, %d failures\n", seed, fails); - return fails == 0 ? EXIT_SUCCESS : EXIT_FAILURE; -} diff --git a/examples/fdpicxip/modules/lazymod.c b/examples/fdpicxip/modules/lazymod.c deleted file mode 100644 index 40a21d6fc..000000000 --- a/examples/fdpicxip/modules/lazymod.c +++ /dev/null @@ -1,45 +0,0 @@ -/**************************************************************************** - * apps/examples/fdpicxip/modules/lazymod.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/* Linked without -z now (BINDNOW= in the makefile), so its imported function - * descriptors land in DT_JMPREL instead of DT_REL. - */ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <syslog.h> -#include <stdlib.h> - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -int main(int argc, char *argv[]) -{ - int seed = (argc > 1) ? atoi(argv[1]) : 1; - - syslog(LOG_INFO, "[lazymod] called through a DT_JMPREL descriptor, " - "seed %d\n", seed); - return 0; -} diff --git a/examples/fdpicxip/modules/libcounter.c b/examples/fdpicxip/modules/libcounter.c deleted file mode 100644 index 7d4c16677..000000000 --- a/examples/fdpicxip/modules/libcounter.c +++ /dev/null @@ -1,58 +0,0 @@ -/**************************************************************************** - * apps/examples/fdpicxip/modules/libcounter.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/* A shared library with its own state. - * - * g_calls is the interesting part: it lives in the library's writable - * segment, and each task that loads the library gets a private copy. The - * library's code, meanwhile, is mapped once and executed in place. - */ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <syslog.h> - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static int g_calls; - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -int counter_bump(int by); -int counter_total(void); - -int counter_bump(int by) -{ - g_calls += by; - return g_calls; -} - -int counter_total(void) -{ - return g_calls; -} diff --git a/examples/fdpicxip/modules/libshape.cpp b/examples/fdpicxip/modules/libshape.cpp deleted file mode 100644 index 1cab840ef..000000000 --- a/examples/fdpicxip/modules/libshape.cpp +++ /dev/null @@ -1,160 +0,0 @@ -/**************************************************************************** - * apps/examples/fdpicxip/modules/libshape.cpp - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/* A C++ shared library, executed in place out of flash. - * - * The point of this file is g_registry. It is a global object with a real - * constructor, and the constructor is the only thing that ever writes - * m_magic. If the loader does not walk DT_INIT_ARRAY, the object simply - * stays in .bss and every field reads back zero -- the library still loads, - * still links, and still runs, and quietly answers wrong. That is why the - * demo checks for a magic rather than just printing a total: the failure - * this is here to catch does not announce itself. - * - * m_total is the second half: it lives in the library's writable segment, - * which is copied once per running instance, so two tasks sharing this - * library's flash-resident code still count independently. - */ - -#include <fcntl.h> -#include <stdio.h> -#include <string.h> -#include <syslog.h> -#include <unistd.h> - -#define SHAPE_MAGIC 0x5ba9e0 - -class Registry -{ -public: - Registry() : m_magic(SHAPE_MAGIC), m_total(0), m_adds(0) - { - m_marker[0] = '\0'; - syslog(LOG_INFO, " [libshape] Registry() ran\n"); - } - - /* Runs last of the two objects, because destruction mirrors construction - * and this library was constructed first. So a marker written here is - * evidence that the whole DT_FINI_ARRAY chain ran, not just the module's - * half -- which is why the marker is written from the library rather than - * from the module that knows the path. - */ - - ~Registry() - { - syslog(LOG_INFO, " [libshape] ~Registry() ran after %d adds\n", m_adds); - - if (m_marker[0] != '\0') - { - char text[16]; - int len; - int fd; - - len = snprintf(text, sizeof(text), "%d", m_total); - - fd = open(m_marker, O_WRONLY | O_CREAT | O_TRUNC, 0644); - if (fd >= 0) - { - /* xipfs wants the size declared up front so it can reserve one - * contiguous extent. - */ - - if (ftruncate(fd, len) >= 0) - { - write(fd, text, len); - } - - close(fd); - } - else - { - syslog(LOG_INFO, " [libshape] marker %s failed\n", m_marker); - } - } - } - - /* Where ~Registry() should record its final total. Optional: the demo - * does not set one and simply logs instead. - */ - - void marker(const char *path) - { - strlcpy(m_marker, path, sizeof(m_marker)); - } - - bool constructed() const - { - return m_magic == SHAPE_MAGIC; - } - - int add(int by) - { - m_adds++; - m_total += by; - return m_total; - } - - int total() const - { - return m_total; - } - -private: - int m_magic; - int m_total; - int m_adds; - char m_marker[64]; -}; - -static Registry g_registry; - -/* C linkage, because the module imports these by name and the loader - * matches dynamic symbols as plain strings. - */ - -extern "C" -{ - int shape_add(int by); - int shape_total(void); - bool shape_constructed(void); - void shape_marker(const char *path); -} - -int shape_add(int by) -{ - return g_registry.add(by); -} - -void shape_marker(const char *path) -{ - g_registry.marker(path); -} - -int shape_total(void) -{ - return g_registry.total(); -} - -bool shape_constructed(void) -{ - return g_registry.constructed(); -} diff --git a/examples/fdpicxip/modules/missingsym.c b/examples/fdpicxip/modules/missingsym.c deleted file mode 100644 index 184675dde..000000000 --- a/examples/fdpicxip/modules/missingsym.c +++ /dev/null @@ -1,40 +0,0 @@ -/**************************************************************************** - * apps/examples/fdpicxip/modules/missingsym.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/* A module that imports a firmware symbol which does not exist. It links - * cleanly -- the symbol simply becomes an undefined import resolved at load - * -- so the loader is the only thing that can catch it, when resolution - * fails rather than at link time. This is why the build runs fdpic-verify - * by default; this module is the one that deliberately does not pass it, so - * it is linked without that check. - */ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -extern int __xipfs_test_nonexistent(int value); - -int main(int argc, char *argv[]) -{ - return __xipfs_test_nonexistent(argc); -} diff --git a/examples/fdpicxip/modules/qsorter.c b/examples/fdpicxip/modules/qsorter.c deleted file mode 100644 index 3dead3f03..000000000 --- a/examples/fdpicxip/modules/qsorter.c +++ /dev/null @@ -1,89 +0,0 @@ -/**************************************************************************** - * apps/examples/fdpicxip/modules/qsorter.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/* Demonstrates the two things worth knowing about NuttX FDPIC modules. - * - * 1. qsort() runs in the firmware and calls back into compare(), which - * lives here. That works because the firmware reserves the FDPIC - * register, so this module's data base survives the call in, and - * because libc resolves the callback descriptor on the way back out. - * - * 2. g_data is module data. Every running instance gets a private copy, - * while the code itself is shared and executed in place from flash. - */ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <stdlib.h> -#include <syslog.h> -#include <unistd.h> - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define N 8 - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static int g_data[N]; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static int compare(const void *a, const void *b) -{ - return *(const int *)a - *(const int *)b; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -int main(int argc, char *argv[]) -{ - int seed = (argc > 1) ? atoi(argv[1]) : 0; - int i; - - for (i = 0; i < N; i++) - { - g_data[i] = (N - i) * 10 + seed; - } - - /* Overlap with any other instance, so shared data would show up as - * corruption rather than passing by luck. - */ - - usleep(300000); - - qsort(g_data, N, sizeof(int), compare); - - syslog(LOG_INFO, "[inst %d] %d %d %d %d %d %d %d %d\n", seed, - g_data[0], g_data[1], g_data[2], g_data[3], - g_data[4], g_data[5], g_data[6], g_data[7]); - return 0; -} diff --git a/examples/fdpicxip/modules/user.c b/examples/fdpicxip/modules/user.c deleted file mode 100644 index bd82dbf31..000000000 --- a/examples/fdpicxip/modules/user.c +++ /dev/null @@ -1,68 +0,0 @@ -/**************************************************************************** - * apps/examples/fdpicxip/modules/user.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/* Uses libcounter.so. Two instances run concurrently: if the library's - * data were shared between them the totals would interleave. - * - * libcounter is also a *leaf* library -- it calls nothing outside itself, - * so it has no PLT and therefore no DT_PLTGOT. The loader has to fall back - * to PT_DYNAMIC vaddr + memsz to find its GOT. If that fallback is wrong - * the library cannot reach its own globals, which is exactly what the total - * below would expose. - */ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <stdlib.h> -#include <syslog.h> -#include <unistd.h> - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -extern int counter_bump(int by); -extern int counter_total(void); - -int main(int argc, char *argv[]) -{ - int seed = (argc > 1) ? atoi(argv[1]) : 0; - int i; - - for (i = 0; i < 3; i++) - { - counter_bump(seed); - usleep(100000); - } - - syslog(LOG_INFO, "[user %d] library total = %d (expected %d) -- %s\n", - seed, counter_total(), seed * 3, - counter_total() == seed * 3 ? "PASS" : "FAIL"); - - /* Reported through the exit status as well as the log, so a test can - * assert on it rather than a human reading the console. - */ - - return counter_total() == seed * 3 ? EXIT_SUCCESS : EXIT_FAILURE; -} diff --git a/examples/fdpicxip/qsorter_bin.h b/examples/fdpicxip/qsorter_bin.h deleted file mode 100644 index 6e1f39c00..000000000 --- a/examples/fdpicxip/qsorter_bin.h +++ /dev/null @@ -1,268 +0,0 @@ -/**************************************************************************** - * apps/examples/fdpicxip/qsorter_bin.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/* Generated from qsorter.fdpic -- do not edit. - * - * An FDPIC module, embedded so the demo has something to load without - * needing a filesystem populated from the host first. - */ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -static const unsigned char g_qsorter_nxf[] = -{ - 0x7f, 0x45, 0x4c, 0x46, 0x01, 0x01, 0x01, 0x41, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x28, 0x00, 0x01, 0x00, 0x00, 0x00, - 0xa1, 0x02, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x28, 0x08, 0x00, 0x00, - 0x00, 0x02, 0x00, 0x05, 0x34, 0x00, 0x20, 0x00, 0x04, 0x00, 0x28, 0x00, - 0x11, 0x00, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x58, 0x03, 0x00, 0x00, - 0x58, 0x03, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x58, 0x03, 0x00, 0x00, 0x58, 0x13, 0x00, 0x00, - 0x58, 0x13, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x00, - 0x06, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, - 0x58, 0x03, 0x00, 0x00, 0x58, 0x13, 0x00, 0x00, 0x58, 0x13, 0x00, 0x00, - 0x88, 0x00, 0x00, 0x00, 0x88, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, 0x51, 0xe5, 0x74, 0x64, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x80, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00, - 0x0c, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, - 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x50, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x05, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xa0, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x03, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x54, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x08, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xe0, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x14, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x0b, 0x00, 0x0b, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, - 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x58, 0x03, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x08, 0x00, 0x01, 0x00, 0x00, 0x00, - 0xa1, 0x02, 0x00, 0x00, 0x88, 0x00, 0x00, 0x00, 0x12, 0x00, 0x06, 0x00, - 0x1f, 0x00, 0x00, 0x00, 0x54, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x08, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, - 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x61, 0x74, 0x6f, 0x69, 0x00, 0x75, - 0x73, 0x6c, 0x65, 0x65, 0x70, 0x00, 0x71, 0x73, 0x6f, 0x72, 0x74, 0x00, - 0x73, 0x79, 0x73, 0x6c, 0x6f, 0x67, 0x00, 0x5f, 0x5f, 0x52, 0x4f, 0x46, - 0x49, 0x58, 0x55, 0x50, 0x5f, 0x4c, 0x49, 0x53, 0x54, 0x5f, 0x5f, 0x00, - 0x5f, 0x5f, 0x52, 0x4f, 0x46, 0x49, 0x58, 0x55, 0x50, 0x5f, 0x45, 0x4e, - 0x44, 0x5f, 0x5f, 0x00, 0x14, 0x14, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00, - 0xec, 0x13, 0x00, 0x00, 0xa4, 0x07, 0x00, 0x00, 0xf4, 0x13, 0x00, 0x00, - 0xa4, 0x08, 0x00, 0x00, 0xfc, 0x13, 0x00, 0x00, 0xa4, 0x0c, 0x00, 0x00, - 0x04, 0x14, 0x00, 0x00, 0xa4, 0x0d, 0x00, 0x00, 0x0c, 0x14, 0x00, 0x00, - 0xa4, 0x02, 0x00, 0x00, 0xdf, 0xf8, 0x0c, 0xc0, 0x0c, 0xeb, 0x09, 0x0c, - 0xdc, 0xf8, 0x04, 0x90, 0xdc, 0xf8, 0x00, 0xf0, 0x0c, 0x00, 0x00, 0x00, - 0xdf, 0xf8, 0x0c, 0xc0, 0x0c, 0xeb, 0x09, 0x0c, 0xdc, 0xf8, 0x04, 0x90, - 0xdc, 0xf8, 0x00, 0xf0, 0x14, 0x00, 0x00, 0x00, 0xdf, 0xf8, 0x0c, 0xc0, - 0x0c, 0xeb, 0x09, 0x0c, 0xdc, 0xf8, 0x04, 0x90, 0xdc, 0xf8, 0x00, 0xf0, - 0x1c, 0x00, 0x00, 0x00, 0xdf, 0xf8, 0x0c, 0xc0, 0x0c, 0xeb, 0x09, 0x0c, - 0xdc, 0xf8, 0x04, 0x90, 0xdc, 0xf8, 0x00, 0xf0, 0x24, 0x00, 0x00, 0x00, - 0x70, 0xb5, 0x01, 0x28, 0x4e, 0x46, 0x88, 0xb0, 0x34, 0xdd, 0x48, 0x68, - 0xff, 0xf7, 0xee, 0xff, 0xb1, 0x46, 0x1a, 0x4b, 0x00, 0xf1, 0x50, 0x05, - 0x59, 0xf8, 0x03, 0x30, 0x43, 0xf8, 0x04, 0x5b, 0x0a, 0x3d, 0x85, 0x42, - 0xfa, 0xd1, 0x14, 0x48, 0xff, 0xf7, 0xc2, 0xff, 0xb1, 0x46, 0x13, 0x4b, - 0x04, 0x22, 0x59, 0xf8, 0x03, 0x40, 0x12, 0x4b, 0x20, 0x46, 0x4b, 0x44, - 0x08, 0x21, 0xff, 0xf7, 0xc1, 0xff, 0xe3, 0x69, 0x0f, 0x49, 0x06, 0x93, - 0xa3, 0x69, 0xb1, 0x46, 0x05, 0x93, 0x63, 0x69, 0x2a, 0x46, 0x04, 0x93, - 0x23, 0x69, 0x06, 0x20, 0x03, 0x93, 0xe3, 0x68, 0x79, 0x44, 0x02, 0x93, - 0xa3, 0x68, 0x01, 0x93, 0x63, 0x68, 0x00, 0x93, 0x23, 0x68, 0xff, 0xf7, - 0xb5, 0xff, 0x00, 0x20, 0x08, 0xb0, 0x70, 0xbd, 0x00, 0x20, 0xcc, 0xe7, - 0xe0, 0x93, 0x04, 0x00, 0x34, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, - 0x30, 0x00, 0x00, 0x00, 0x00, 0x68, 0x0b, 0x68, 0xc0, 0x1a, 0x70, 0x47, - 0x5b, 0x69, 0x6e, 0x73, 0x74, 0x20, 0x25, 0x64, 0x5d, 0x20, 0x25, 0x64, - 0x20, 0x25, 0x64, 0x20, 0x25, 0x64, 0x20, 0x25, 0x64, 0x20, 0x25, 0x64, - 0x20, 0x25, 0x64, 0x20, 0x25, 0x64, 0x20, 0x25, 0x64, 0x0a, 0x00, 0x00, - 0xe0, 0x13, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xb4, 0x00, 0x00, 0x00, - 0x05, 0x00, 0x00, 0x00, 0xe0, 0x01, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, - 0x00, 0x01, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, - 0x0b, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, - 0xe0, 0x13, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x20, 0x02, 0x00, 0x00, - 0x12, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xfb, 0xff, 0xff, 0x6f, 0x01, 0x00, 0x00, 0x00, 0xfa, 0xff, 0xff, 0x6f, - 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x58, 0x13, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x89, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, - 0x18, 0x14, 0x00, 0x00, 0x47, 0x43, 0x43, 0x3a, 0x20, 0x28, 0x41, 0x72, - 0x6d, 0x20, 0x47, 0x4e, 0x55, 0x20, 0x54, 0x6f, 0x6f, 0x6c, 0x63, 0x68, - 0x61, 0x69, 0x6e, 0x20, 0x31, 0x35, 0x2e, 0x32, 0x2e, 0x52, 0x65, 0x6c, - 0x31, 0x20, 0x28, 0x42, 0x75, 0x69, 0x6c, 0x64, 0x20, 0x61, 0x72, 0x6d, - 0x2d, 0x31, 0x35, 0x2e, 0x38, 0x36, 0x29, 0x29, 0x20, 0x31, 0x35, 0x2e, - 0x32, 0x2e, 0x31, 0x20, 0x32, 0x30, 0x32, 0x35, 0x31, 0x32, 0x30, 0x33, - 0x00, 0x41, 0x2c, 0x00, 0x00, 0x00, 0x61, 0x65, 0x61, 0x62, 0x69, 0x00, - 0x01, 0x22, 0x00, 0x00, 0x00, 0x05, 0x37, 0x2d, 0x4d, 0x00, 0x06, 0x0a, - 0x07, 0x4d, 0x09, 0x02, 0x12, 0x04, 0x14, 0x01, 0x15, 0x01, 0x17, 0x03, - 0x18, 0x01, 0x19, 0x01, 0x1a, 0x01, 0x1e, 0x04, 0x22, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb4, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x02, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xe0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x02, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x50, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x05, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xa0, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x03, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x54, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x08, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x58, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x13, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x18, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x0b, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x0d, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0xf1, 0xff, - 0x0b, 0x00, 0x00, 0x00, 0x28, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x06, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x29, 0x03, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, 0x02, 0x00, 0x06, 0x00, 0x0b, 0x00, 0x00, 0x00, - 0xa0, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, - 0x16, 0x00, 0x00, 0x00, 0x18, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x06, 0x00, 0x16, 0x00, 0x00, 0x00, 0x18, 0x14, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x19, 0x00, 0x00, 0x00, - 0x18, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0b, 0x00, - 0x23, 0x00, 0x00, 0x00, 0x18, 0x14, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0xf1, 0xff, 0x2a, 0x00, 0x00, 0x00, - 0x58, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0xf1, 0xff, - 0x33, 0x00, 0x00, 0x00, 0xe0, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x0a, 0x00, 0x16, 0x00, 0x00, 0x00, 0x30, 0x03, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x00, 0x00, - 0x50, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, - 0x16, 0x00, 0x00, 0x00, 0x60, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x05, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x64, 0x02, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x16, 0x00, 0x00, 0x00, - 0x74, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, - 0x0b, 0x00, 0x00, 0x00, 0x78, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x05, 0x00, 0x16, 0x00, 0x00, 0x00, 0x88, 0x02, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x0b, 0x00, 0x00, 0x00, - 0x8c, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, - 0x16, 0x00, 0x00, 0x00, 0x9c, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x05, 0x00, 0x49, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, - 0x56, 0x00, 0x00, 0x00, 0x58, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x08, 0x00, 0x66, 0x00, 0x00, 0x00, 0xa1, 0x02, 0x00, 0x00, - 0x88, 0x00, 0x00, 0x00, 0x12, 0x00, 0x06, 0x00, 0x6b, 0x00, 0x00, 0x00, - 0x54, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x08, 0x00, - 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, 0x83, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x71, 0x73, 0x6f, - 0x72, 0x74, 0x65, 0x72, 0x2e, 0x63, 0x00, 0x24, 0x74, 0x00, 0x63, 0x6f, - 0x6d, 0x70, 0x61, 0x72, 0x65, 0x00, 0x24, 0x64, 0x00, 0x2e, 0x4c, 0x41, - 0x4e, 0x43, 0x48, 0x4f, 0x52, 0x30, 0x00, 0x67, 0x5f, 0x64, 0x61, 0x74, - 0x61, 0x00, 0x5f, 0x44, 0x59, 0x4e, 0x41, 0x4d, 0x49, 0x43, 0x00, 0x5f, - 0x47, 0x4c, 0x4f, 0x42, 0x41, 0x4c, 0x5f, 0x4f, 0x46, 0x46, 0x53, 0x45, - 0x54, 0x5f, 0x54, 0x41, 0x42, 0x4c, 0x45, 0x5f, 0x00, 0x75, 0x73, 0x6c, - 0x65, 0x65, 0x70, 0x00, 0x71, 0x73, 0x6f, 0x72, 0x74, 0x00, 0x5f, 0x5f, - 0x52, 0x4f, 0x46, 0x49, 0x58, 0x55, 0x50, 0x5f, 0x45, 0x4e, 0x44, 0x5f, - 0x5f, 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x5f, 0x5f, 0x52, 0x4f, 0x46, - 0x49, 0x58, 0x55, 0x50, 0x5f, 0x4c, 0x49, 0x53, 0x54, 0x5f, 0x5f, 0x00, - 0x73, 0x79, 0x73, 0x6c, 0x6f, 0x67, 0x00, 0x61, 0x74, 0x6f, 0x69, 0x00, - 0x00, 0x2e, 0x73, 0x79, 0x6d, 0x74, 0x61, 0x62, 0x00, 0x2e, 0x73, 0x74, - 0x72, 0x74, 0x61, 0x62, 0x00, 0x2e, 0x73, 0x68, 0x73, 0x74, 0x72, 0x74, - 0x61, 0x62, 0x00, 0x2e, 0x68, 0x61, 0x73, 0x68, 0x00, 0x2e, 0x64, 0x79, - 0x6e, 0x73, 0x79, 0x6d, 0x00, 0x2e, 0x64, 0x79, 0x6e, 0x73, 0x74, 0x72, - 0x00, 0x2e, 0x72, 0x65, 0x6c, 0x2e, 0x64, 0x79, 0x6e, 0x00, 0x2e, 0x70, - 0x6c, 0x74, 0x00, 0x2e, 0x74, 0x65, 0x78, 0x74, 0x00, 0x2e, 0x72, 0x6f, - 0x64, 0x61, 0x74, 0x61, 0x00, 0x2e, 0x72, 0x6f, 0x66, 0x69, 0x78, 0x75, - 0x70, 0x00, 0x2e, 0x64, 0x79, 0x6e, 0x61, 0x6d, 0x69, 0x63, 0x00, 0x2e, - 0x67, 0x6f, 0x74, 0x00, 0x2e, 0x62, 0x73, 0x73, 0x00, 0x2e, 0x63, 0x6f, - 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x00, 0x2e, 0x41, 0x52, 0x4d, 0x2e, 0x61, - 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x73, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x1b, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, 0xb4, 0x00, 0x00, 0x00, 0xb4, 0x00, 0x00, 0x00, - 0x4c, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x21, 0x00, 0x00, 0x00, - 0x0b, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, - 0x00, 0x01, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, - 0x07, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, - 0x29, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, - 0xe0, 0x01, 0x00, 0x00, 0xe0, 0x01, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x31, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, 0x20, 0x02, 0x00, 0x00, 0x20, 0x02, 0x00, 0x00, - 0x30, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x3a, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x50, 0x02, 0x00, 0x00, - 0x50, 0x02, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x3f, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, - 0xa0, 0x02, 0x00, 0x00, 0xa0, 0x02, 0x00, 0x00, 0x90, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x45, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x32, 0x00, 0x00, 0x00, 0x30, 0x03, 0x00, 0x00, 0x30, 0x03, 0x00, 0x00, - 0x23, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x4d, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x54, 0x03, 0x00, 0x00, - 0x54, 0x03, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x56, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, - 0x58, 0x13, 0x00, 0x00, 0x58, 0x03, 0x00, 0x00, 0x88, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, 0x5f, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, 0xe0, 0x13, 0x00, 0x00, 0xe0, 0x03, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x18, 0x14, 0x00, 0x00, - 0x18, 0x04, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x69, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x18, 0x04, 0x00, 0x00, 0x45, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x72, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x70, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5d, 0x04, 0x00, 0x00, - 0x2d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x8c, 0x04, 0x00, 0x00, 0x90, 0x02, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, - 0x22, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, - 0x09, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x1c, 0x07, 0x00, 0x00, 0x88, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa4, 0x07, 0x00, 0x00, - 0x82, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 -}; - -static const unsigned int g_qsorter_nxf_len = 2768; diff --git a/examples/fdpicxip/user_bin.h b/examples/fdpicxip/user_bin.h deleted file mode 100644 index fd417418c..000000000 --- a/examples/fdpicxip/user_bin.h +++ /dev/null @@ -1,265 +0,0 @@ -/**************************************************************************** - * apps/examples/fdpicxip/user_bin.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/* Generated from user.fdpic -- do not edit. - * - * An FDPIC module, embedded so the demo has something to load without - * needing a filesystem populated from the host first. - */ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -static const unsigned char g_user[] = -{ - 0x7f, 0x45, 0x4c, 0x46, 0x01, 0x01, 0x01, 0x41, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x28, 0x00, 0x01, 0x00, 0x00, 0x00, - 0xd1, 0x02, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x2c, 0x08, 0x00, 0x00, - 0x00, 0x02, 0x00, 0x05, 0x34, 0x00, 0x20, 0x00, 0x04, 0x00, 0x28, 0x00, - 0x10, 0x00, 0x0f, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x94, 0x03, 0x00, 0x00, - 0x94, 0x03, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x94, 0x03, 0x00, 0x00, 0x94, 0x13, 0x00, 0x00, - 0x94, 0x13, 0x00, 0x00, 0xc4, 0x00, 0x00, 0x00, 0xc4, 0x00, 0x00, 0x00, - 0x06, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, - 0x94, 0x03, 0x00, 0x00, 0x94, 0x13, 0x00, 0x00, 0x94, 0x13, 0x00, 0x00, - 0x90, 0x00, 0x00, 0x00, 0x90, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, 0x51, 0xe5, 0x74, 0x64, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x80, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00, - 0x0c, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, - 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x6c, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x05, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xd0, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x54, 0x03, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x90, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x08, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x24, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x0a, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, - 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x12, 0x00, 0x00, 0x00, 0x53, 0x00, 0x00, 0x00, 0x94, 0x03, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x08, 0x00, 0x01, 0x00, 0x00, 0x00, - 0xd1, 0x02, 0x00, 0x00, 0x84, 0x00, 0x00, 0x00, 0x12, 0x00, 0x06, 0x00, - 0x42, 0x00, 0x00, 0x00, 0x90, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x08, 0x00, 0x2d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, - 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x61, 0x74, 0x6f, 0x69, 0x00, 0x63, - 0x6f, 0x75, 0x6e, 0x74, 0x65, 0x72, 0x5f, 0x62, 0x75, 0x6d, 0x70, 0x00, - 0x75, 0x73, 0x6c, 0x65, 0x65, 0x70, 0x00, 0x63, 0x6f, 0x75, 0x6e, 0x74, - 0x65, 0x72, 0x5f, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x00, 0x73, 0x79, 0x73, - 0x6c, 0x6f, 0x67, 0x00, 0x6c, 0x69, 0x62, 0x63, 0x6f, 0x75, 0x6e, 0x74, - 0x65, 0x72, 0x2e, 0x73, 0x6f, 0x00, 0x5f, 0x5f, 0x52, 0x4f, 0x46, 0x49, - 0x58, 0x55, 0x50, 0x5f, 0x4c, 0x49, 0x53, 0x54, 0x5f, 0x5f, 0x00, 0x5f, - 0x5f, 0x52, 0x4f, 0x46, 0x49, 0x58, 0x55, 0x50, 0x5f, 0x45, 0x4e, 0x44, - 0x5f, 0x5f, 0x00, 0x00, 0x30, 0x14, 0x00, 0x00, 0xa4, 0x06, 0x00, 0x00, - 0x38, 0x14, 0x00, 0x00, 0xa4, 0x07, 0x00, 0x00, 0x40, 0x14, 0x00, 0x00, - 0xa4, 0x08, 0x00, 0x00, 0x48, 0x14, 0x00, 0x00, 0xa4, 0x0c, 0x00, 0x00, - 0x50, 0x14, 0x00, 0x00, 0xa4, 0x0d, 0x00, 0x00, 0xdf, 0xf8, 0x0c, 0xc0, - 0x0c, 0xeb, 0x09, 0x0c, 0xdc, 0xf8, 0x04, 0x90, 0xdc, 0xf8, 0x00, 0xf0, - 0x0c, 0x00, 0x00, 0x00, 0xdf, 0xf8, 0x0c, 0xc0, 0x0c, 0xeb, 0x09, 0x0c, - 0xdc, 0xf8, 0x04, 0x90, 0xdc, 0xf8, 0x00, 0xf0, 0x14, 0x00, 0x00, 0x00, - 0xdf, 0xf8, 0x0c, 0xc0, 0x0c, 0xeb, 0x09, 0x0c, 0xdc, 0xf8, 0x04, 0x90, - 0xdc, 0xf8, 0x00, 0xf0, 0x1c, 0x00, 0x00, 0x00, 0xdf, 0xf8, 0x0c, 0xc0, - 0x0c, 0xeb, 0x09, 0x0c, 0xdc, 0xf8, 0x04, 0x90, 0xdc, 0xf8, 0x00, 0xf0, - 0x24, 0x00, 0x00, 0x00, 0xdf, 0xf8, 0x0c, 0xc0, 0x0c, 0xeb, 0x09, 0x0c, - 0xdc, 0xf8, 0x04, 0x90, 0xdc, 0xf8, 0x00, 0xf0, 0x2c, 0x00, 0x00, 0x00, - 0xf0, 0xb5, 0x01, 0x28, 0x4c, 0x46, 0x85, 0xb0, 0x2f, 0xdd, 0x48, 0x68, - 0xff, 0xf7, 0xee, 0xff, 0xa1, 0x46, 0x05, 0x46, 0x03, 0x26, 0x17, 0x4b, - 0x03, 0x93, 0x28, 0x46, 0xff, 0xf7, 0xc8, 0xff, 0x03, 0x98, 0xa1, 0x46, - 0xff, 0xf7, 0xba, 0xff, 0x01, 0x3e, 0xa1, 0x46, 0xf5, 0xd1, 0xff, 0xf7, - 0xc9, 0xff, 0xa1, 0x46, 0x07, 0x46, 0xff, 0xf7, 0xc5, 0xff, 0x05, 0xeb, - 0x45, 0x06, 0x86, 0x42, 0xa1, 0x46, 0x14, 0xd1, 0x0c, 0x4a, 0x7a, 0x44, - 0x0c, 0x49, 0x3b, 0x46, 0xcd, 0xe9, 0x00, 0x62, 0x79, 0x44, 0x2a, 0x46, - 0x06, 0x20, 0xff, 0xf7, 0xbf, 0xff, 0xa1, 0x46, 0xff, 0xf7, 0xb2, 0xff, - 0x30, 0x1a, 0x18, 0xbf, 0x01, 0x20, 0x05, 0xb0, 0xf0, 0xbd, 0x00, 0x25, - 0xd2, 0xe7, 0x04, 0x4a, 0x7a, 0x44, 0xe9, 0xe7, 0xa0, 0x86, 0x01, 0x00, - 0x3a, 0x00, 0x00, 0x00, 0x3a, 0x00, 0x00, 0x00, 0x15, 0x00, 0x00, 0x00, - 0x50, 0x41, 0x53, 0x53, 0x00, 0x46, 0x41, 0x49, 0x4c, 0x00, 0x5b, 0x75, - 0x73, 0x65, 0x72, 0x20, 0x25, 0x64, 0x5d, 0x20, 0x6c, 0x69, 0x62, 0x72, - 0x61, 0x72, 0x79, 0x20, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x20, 0x3d, 0x20, - 0x25, 0x64, 0x20, 0x28, 0x65, 0x78, 0x70, 0x65, 0x63, 0x74, 0x65, 0x64, - 0x20, 0x25, 0x64, 0x29, 0x20, 0x2d, 0x2d, 0x20, 0x25, 0x73, 0x0a, 0x00, - 0x24, 0x14, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, 0xb4, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, - 0xe0, 0x01, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, - 0x0a, 0x00, 0x00, 0x00, 0x63, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x24, 0x14, 0x00, 0x00, - 0x11, 0x00, 0x00, 0x00, 0x44, 0x02, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, - 0x28, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, - 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfb, 0xff, 0xff, 0x6f, - 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x94, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x43, 0x43, 0x3a, - 0x20, 0x28, 0x41, 0x72, 0x6d, 0x20, 0x47, 0x4e, 0x55, 0x20, 0x54, 0x6f, - 0x6f, 0x6c, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x20, 0x31, 0x35, 0x2e, 0x32, - 0x2e, 0x52, 0x65, 0x6c, 0x31, 0x20, 0x28, 0x42, 0x75, 0x69, 0x6c, 0x64, - 0x20, 0x61, 0x72, 0x6d, 0x2d, 0x31, 0x35, 0x2e, 0x38, 0x36, 0x29, 0x29, - 0x20, 0x31, 0x35, 0x2e, 0x32, 0x2e, 0x31, 0x20, 0x32, 0x30, 0x32, 0x35, - 0x31, 0x32, 0x30, 0x33, 0x00, 0x41, 0x2c, 0x00, 0x00, 0x00, 0x61, 0x65, - 0x61, 0x62, 0x69, 0x00, 0x01, 0x22, 0x00, 0x00, 0x00, 0x05, 0x37, 0x2d, - 0x4d, 0x00, 0x06, 0x0a, 0x07, 0x4d, 0x09, 0x02, 0x12, 0x04, 0x14, 0x01, - 0x15, 0x01, 0x17, 0x03, 0x18, 0x01, 0x19, 0x01, 0x1a, 0x01, 0x1e, 0x04, - 0x22, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xb4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x01, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x44, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x04, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x6c, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd0, 0x02, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x54, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x90, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x94, 0x13, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x24, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x0a, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x0c, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0xf1, 0xff, - 0x08, 0x00, 0x00, 0x00, 0xd0, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x06, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x44, 0x03, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0xf1, 0xff, - 0x0e, 0x00, 0x00, 0x00, 0x94, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0xf1, 0xff, 0x17, 0x00, 0x00, 0x00, 0x24, 0x14, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x0a, 0x00, 0x0b, 0x00, 0x00, 0x00, - 0x54, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, - 0x08, 0x00, 0x00, 0x00, 0x6c, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x05, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x7c, 0x02, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x08, 0x00, 0x00, 0x00, - 0x80, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, - 0x0b, 0x00, 0x00, 0x00, 0x90, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x05, 0x00, 0x08, 0x00, 0x00, 0x00, 0x94, 0x02, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x0b, 0x00, 0x00, 0x00, - 0xa4, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, - 0x08, 0x00, 0x00, 0x00, 0xa8, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x05, 0x00, 0x0b, 0x00, 0x00, 0x00, 0xb8, 0x02, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x08, 0x00, 0x00, 0x00, - 0xbc, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, - 0x0b, 0x00, 0x00, 0x00, 0xcc, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x05, 0x00, 0x2d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, - 0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x12, 0x00, 0x00, 0x00, 0x4f, 0x00, 0x00, 0x00, 0x94, 0x03, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x08, 0x00, 0x5f, 0x00, 0x00, 0x00, - 0xd1, 0x02, 0x00, 0x00, 0x84, 0x00, 0x00, 0x00, 0x12, 0x00, 0x06, 0x00, - 0x64, 0x00, 0x00, 0x00, 0x90, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x08, 0x00, 0x75, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x7c, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, - 0x00, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x63, 0x00, 0x24, 0x74, 0x00, 0x24, - 0x64, 0x00, 0x5f, 0x44, 0x59, 0x4e, 0x41, 0x4d, 0x49, 0x43, 0x00, 0x5f, - 0x47, 0x4c, 0x4f, 0x42, 0x41, 0x4c, 0x5f, 0x4f, 0x46, 0x46, 0x53, 0x45, - 0x54, 0x5f, 0x54, 0x41, 0x42, 0x4c, 0x45, 0x5f, 0x00, 0x75, 0x73, 0x6c, - 0x65, 0x65, 0x70, 0x00, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x65, 0x72, 0x5f, - 0x62, 0x75, 0x6d, 0x70, 0x00, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x65, 0x72, - 0x5f, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x00, 0x5f, 0x5f, 0x52, 0x4f, 0x46, - 0x49, 0x58, 0x55, 0x50, 0x5f, 0x45, 0x4e, 0x44, 0x5f, 0x5f, 0x00, 0x6d, - 0x61, 0x69, 0x6e, 0x00, 0x5f, 0x5f, 0x52, 0x4f, 0x46, 0x49, 0x58, 0x55, - 0x50, 0x5f, 0x4c, 0x49, 0x53, 0x54, 0x5f, 0x5f, 0x00, 0x73, 0x79, 0x73, - 0x6c, 0x6f, 0x67, 0x00, 0x61, 0x74, 0x6f, 0x69, 0x00, 0x00, 0x2e, 0x73, - 0x79, 0x6d, 0x74, 0x61, 0x62, 0x00, 0x2e, 0x73, 0x74, 0x72, 0x74, 0x61, - 0x62, 0x00, 0x2e, 0x73, 0x68, 0x73, 0x74, 0x72, 0x74, 0x61, 0x62, 0x00, - 0x2e, 0x68, 0x61, 0x73, 0x68, 0x00, 0x2e, 0x64, 0x79, 0x6e, 0x73, 0x79, - 0x6d, 0x00, 0x2e, 0x64, 0x79, 0x6e, 0x73, 0x74, 0x72, 0x00, 0x2e, 0x72, - 0x65, 0x6c, 0x2e, 0x64, 0x79, 0x6e, 0x00, 0x2e, 0x70, 0x6c, 0x74, 0x00, - 0x2e, 0x74, 0x65, 0x78, 0x74, 0x00, 0x2e, 0x72, 0x6f, 0x64, 0x61, 0x74, - 0x61, 0x00, 0x2e, 0x72, 0x6f, 0x66, 0x69, 0x78, 0x75, 0x70, 0x00, 0x2e, - 0x64, 0x79, 0x6e, 0x61, 0x6d, 0x69, 0x63, 0x00, 0x2e, 0x67, 0x6f, 0x74, - 0x00, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x00, 0x2e, 0x41, - 0x52, 0x4d, 0x2e, 0x61, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, - 0x73, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1b, 0x00, 0x00, 0x00, - 0x05, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0xb4, 0x00, 0x00, 0x00, - 0xb4, 0x00, 0x00, 0x00, 0x4c, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x21, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, - 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, 0x29, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, 0xe0, 0x01, 0x00, 0x00, 0xe0, 0x01, 0x00, 0x00, - 0x63, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x31, 0x00, 0x00, 0x00, - 0x09, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x44, 0x02, 0x00, 0x00, - 0x44, 0x02, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, - 0x6c, 0x02, 0x00, 0x00, 0x6c, 0x02, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x06, 0x00, 0x00, 0x00, 0xd0, 0x02, 0x00, 0x00, 0xd0, 0x02, 0x00, 0x00, - 0x84, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x45, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x32, 0x00, 0x00, 0x00, 0x54, 0x03, 0x00, 0x00, - 0x54, 0x03, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x4d, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, - 0x90, 0x03, 0x00, 0x00, 0x90, 0x03, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x56, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, 0x94, 0x13, 0x00, 0x00, 0x94, 0x03, 0x00, 0x00, - 0x90, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x5f, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x24, 0x14, 0x00, 0x00, - 0x24, 0x04, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x64, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x58, 0x04, 0x00, 0x00, 0x45, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x6d, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x70, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9d, 0x04, 0x00, 0x00, - 0x2d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xcc, 0x04, 0x00, 0x00, 0x60, 0x02, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, - 0x1e, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, - 0x09, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x2c, 0x07, 0x00, 0x00, 0x81, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xad, 0x07, 0x00, 0x00, - 0x7d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 -}; - -static const unsigned int g_user_len = 2732; diff --git a/examples/flash_test/CMakeLists.txt b/examples/flash_test/CMakeLists.txt deleted file mode 100644 index 136905dfc..000000000 --- a/examples/flash_test/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# ############################################################################## -# apps/examples/flash_test/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_FLASH_TEST) - nuttx_add_application( - NAME - flash_test - STACKSIZE - ${CONFIG_DEFAULT_TASK_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_FLASH_TEST} - SRCS - flash_test.c) -endif() diff --git a/examples/flash_test/Make.defs b/examples/flash_test/Make.defs index 04e423a2d..a5ef02bb4 100644 --- a/examples/flash_test/Make.defs +++ b/examples/flash_test/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/flash_test/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/flash_test/Makefile b/examples/flash_test/Makefile index 6b1cf355f..580ec0ab8 100644 --- a/examples/flash_test/Makefile +++ b/examples/flash_test/Makefile @@ -1,7 +1,5 @@ ############################################################################ -# apps/examples/flash_test/Makefile -# -# SPDX-License-Identifier: Apache-2.0 +# apps/system/flash_test/Makefile # # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with diff --git a/examples/flash_test/README.md b/examples/flash_test/README.md new file mode 100644 index 000000000..9fb2fdf3f --- /dev/null +++ b/examples/flash_test/README.md @@ -0,0 +1,23 @@ +# Examples / `flash_test` SMART Flash Device Test + +``` +Author: Ken Pettit + Date: April 24, 2013 +``` + +This application performs a SMART flash block device test. This test performs a +sector allocate, read, write, free and garbage collection test on a SMART MTD +block device. This test can be built only as an NSH command + +**Note**: This test uses internal OS interfaces and so is not available in the +NUTTX kernel build + +``` +Usage: + + flash_test mtdblock_device + +Additional options: + + --force to replace existing installation +``` diff --git a/examples/flash_test/flash_test.c b/examples/flash_test/flash_test.c index 2dea201c2..b62b04e7d 100644 --- a/examples/flash_test/flash_test.c +++ b/examples/flash_test/flash_test.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/flash_test/flash_test.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -50,7 +48,7 @@ int main(int argc, FAR char *argv[]) { - struct inode *inode; + struct inode * inode; int ret; int x; int logsector; @@ -75,7 +73,7 @@ int main(int argc, FAR char *argv[]) if (ret < 0) { fprintf(stderr, "Failed to open %s\n", argv[1]); - return ret; + goto errout; } /* Get the low-level format from the device. */ @@ -115,14 +113,14 @@ int main(int argc, FAR char *argv[]) /* Allocate buffers to use */ - buffer = (char *)malloc(fmt.availbytes); + buffer = (char *) malloc(fmt.availbytes); if (buffer == NULL) { fprintf(stderr, "Error allocating buffer\n"); goto errout_with_driver; } - seqs = (uint16_t *)malloc(fmt.nsectors << 1); + seqs = (uint16_t *) malloc(fmt.nsectors << 1); if (seqs == NULL) { free(buffer); @@ -130,7 +128,7 @@ int main(int argc, FAR char *argv[]) goto errout_with_driver; } - sectors = (uint16_t *)malloc(fmt.nsectors << 1); + sectors = (uint16_t *) malloc(fmt.nsectors << 1); if (sectors == NULL) { free(seqs); @@ -158,19 +156,18 @@ int main(int argc, FAR char *argv[]) /* Save the sector in our array */ - sectors[x] = (uint16_t)logsector; + sectors[x] = (uint16_t) logsector; seqs[x] = seq++; /* Now write some data to the sector */ - snprintf(buffer, fmt.availbytes, - "Logical sector %d sequence %d\n", - sectors[x], seqs[x]); + sprintf(buffer, "Logical sector %d sequence %d\n", + sectors[x], seqs[x]); readwrite.logsector = sectors[x]; readwrite.offset = 0; readwrite.count = strlen(buffer) + 1; - readwrite.buffer = (uint8_t *)buffer; + readwrite.buffer = (uint8_t *) buffer; inode->u.i_bops->ioctl(inode, BIOC_WRITESECT, (unsigned long) &readwrite); @@ -191,7 +188,7 @@ int main(int argc, FAR char *argv[]) readwrite.logsector = sectors[x]; readwrite.offset = 0; readwrite.count = fmt.availbytes; - readwrite.buffer = (uint8_t *)buffer; + readwrite.buffer = (uint8_t *) buffer; ret = inode->u.i_bops->ioctl(inode, BIOC_READSECT, (unsigned long) &readwrite); @@ -205,9 +202,8 @@ int main(int argc, FAR char *argv[]) printf("\r%d ", sectors[x]); - snprintf(&buffer[100], fmt.availbytes - 100, - "Logical sector %d sequence %d\n", - sectors[x], seqs[x]); + sprintf(&buffer[100], "Logical sector %d sequence %d\n", + sectors[x], seqs[x]); if (strcmp(buffer, &buffer[100]) != 0) { @@ -228,13 +224,12 @@ int main(int argc, FAR char *argv[]) /* Now write over the sector data with new data, causing a relocation. */ - snprintf(buffer, fmt.availbytes, - "Logical sector %d sequence %d\n", - sectors[x], seqs[x]); + sprintf(buffer, "Logical sector %d sequence %d\n", + sectors[x], seqs[x]); readwrite.logsector = sectors[x]; readwrite.offset = 0; readwrite.count = strlen(buffer) + 1; - readwrite.buffer = (uint8_t *)buffer; + readwrite.buffer = (uint8_t *) buffer; inode->u.i_bops->ioctl(inode, BIOC_WRITESECT, (unsigned long) &readwrite); @@ -257,12 +252,11 @@ int main(int argc, FAR char *argv[]) * causing a relocation. */ - snprintf(buffer, fmt.availbytes, - "Appended data in sector %d\n", sectors[x]); + sprintf(buffer, "Appended data in sector %d\n", sectors[x]); readwrite.logsector = sectors[x]; readwrite.offset = 64; readwrite.count = strlen(buffer) + 1; - readwrite.buffer = (uint8_t *)buffer; + readwrite.buffer = (uint8_t *) buffer; inode->u.i_bops->ioctl(inode, BIOC_WRITESECT, (unsigned long) &readwrite); @@ -299,5 +293,8 @@ errout_with_driver: /* Now close the block device and exit */ close_blockdriver(inode); + +errout: + return 0; } diff --git a/examples/flowc/CMakeLists.txt b/examples/flowc/CMakeLists.txt deleted file mode 100644 index fd7d70960..000000000 --- a/examples/flowc/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -# ############################################################################## -# apps/examples/flowc/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_FLOWC) - nuttx_add_application(NAME flowc) -endif() diff --git a/examples/flowc/Make.defs b/examples/flowc/Make.defs index 5153fbc9b..060c7d3ad 100644 --- a/examples/flowc/Make.defs +++ b/examples/flowc/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/flowc/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/flowc/Makefile b/examples/flowc/Makefile index 9d9d90f54..597f6eedc 100644 --- a/examples/flowc/Makefile +++ b/examples/flowc/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/flowc/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/flowc/README.md b/examples/flowc/README.md new file mode 100644 index 000000000..6f3d23280 --- /dev/null +++ b/examples/flowc/README.md @@ -0,0 +1,17 @@ +# Examples / `flowc` + +General Usage Instructions: + +1. The receiver side enter, start the receiver program. The receiver is now + waiting to receive data on the configured serial port. +2. On the sender side start the sender program. This will send data to the + receiver which will verify that no data is lost. + +On Linux, you can alternatively do: + +```bash +$ stty -F /dev/ttyACM0 crtscts +$ cat testdata.dat >/dev/ttyACM0 +``` + +where you need to replace `/dev/ttyACM0` with your selected serial device. diff --git a/examples/flowc/flowc.h b/examples/flowc/flowc.h index 12caefa93..2e7bd07b6 100644 --- a/examples/flowc/flowc.h +++ b/examples/flowc/flowc.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/flowc/flowc.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -29,7 +27,7 @@ #ifdef EXAMPLES_FLOWC_HOST #else -# include <nuttx/debug.h> +# include <debug.h> #endif /**************************************************************************** diff --git a/examples/flowc/flowc_host.c b/examples/flowc/flowc_host.c index 3355dcb3e..a2d97bb8b 100644 --- a/examples/flowc/flowc_host.c +++ b/examples/flowc/flowc_host.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/flowc/flowc_host.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/flowc/flowc_mktestdata.c b/examples/flowc/flowc_mktestdata.c index 0ad5546a2..ae31cf851 100644 --- a/examples/flowc/flowc_mktestdata.c +++ b/examples/flowc/flowc_mktestdata.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/flowc/flowc_mktestdata.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -37,7 +35,7 @@ int main(int argc, char **envp) for (i = 0; i < 100; i++) { - for (ch = 0x20; ch < 0x7f; ch++) + for (ch = 0x20; ch < 0x7F; ch++) { putchar(ch); } diff --git a/examples/flowc/flowc_receiver.c b/examples/flowc/flowc_receiver.c index 07d9ede0f..165dd750b 100644 --- a/examples/flowc/flowc_receiver.c +++ b/examples/flowc/flowc_receiver.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/flowc/flowc_receiver.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -109,7 +107,7 @@ static int flowc_cmdline(int argc, char **argv) if (argc == 2) { - strlcpy(g_tty_devname, argv[1], MAX_DEVNAME); + strncpy(g_tty_devname, argv[1], MAX_DEVNAME); } else if (argc != 1) { diff --git a/examples/flowc/flowc_sender.c b/examples/flowc/flowc_sender.c index fc536c452..986d5b2a9 100644 --- a/examples/flowc/flowc_sender.c +++ b/examples/flowc/flowc_sender.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/flowc/flowc_sender.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -71,7 +69,7 @@ static int flowc_cmdline(int argc, char **argv) if (argc == 2) { - strlcpy(g_tty_devname, argv[1], MAX_DEVNAME); + strncpy(g_tty_devname, argv[1], MAX_DEVNAME); } else if (argc != 1) { diff --git a/examples/flowc/flowc_target1.c b/examples/flowc/flowc_target1.c index a79562115..80790b323 100644 --- a/examples/flowc/flowc_target1.c +++ b/examples/flowc/flowc_target1.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/flowc/flowc_target1.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/flowc/flowc_target2.c b/examples/flowc/flowc_target2.c index 31fa00718..4488308bf 100644 --- a/examples/flowc/flowc_target2.c +++ b/examples/flowc/flowc_target2.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/flowc/flowc_target2.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/fmsynth/CMakeLists.txt b/examples/fmsynth/CMakeLists.txt deleted file mode 100644 index b6ff8c4f1..000000000 --- a/examples/fmsynth/CMakeLists.txt +++ /dev/null @@ -1,45 +0,0 @@ -# ############################################################################## -# apps/examples/fmsynth/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_FMSYNTH) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_FMSYNTH_KEYBOARD_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_FMSYNTH_KEYBOARD_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_FMSYNTH_KEYBOARD_STACKSIZE} - SRCS - keyboard_main.c) - - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_FMSYNTH_MMLPLAYER_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_FMSYNTH_MMLPLAYER_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_FMSYNTH_MMLPLAYER_STACKSIZE} - SRCS - mmlplayer_main.c) - - target_sources(apps PRIVATE music_scale.c operator_algorithm.c) -endif() diff --git a/examples/fmsynth/Kconfig b/examples/fmsynth/Kconfig deleted file mode 100644 index 6038fb033..000000000 --- a/examples/fmsynth/Kconfig +++ /dev/null @@ -1,42 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config EXAMPLES_FMSYNTH - tristate "FM Synthesizer examples" - default n - ---help--- - Examples for fmsynth library. - -if EXAMPLES_FMSYNTH - -config EXAMPLES_FMSYNTH_KEYBOARD_PROGNAME - string "Simple music keyboard Program name" - default "keyboard" - ---help--- - Command name of this "Simple music keyboard". - -config EXAMPLES_FMSYNTH_KEYBOARD_PRIORITY - int "Simple music keyboard task priority" - default 100 - -config EXAMPLES_FMSYNTH_KEYBOARD_STACKSIZE - int "Simple music keyboard stack size" - default 2048 - -config EXAMPLES_FMSYNTH_MMLPLAYER_PROGNAME - string "MML Player Program name" - default "mmlplayer" - ---help--- - Command name of this "MML Player". - -config EXAMPLES_FMSYNTH_MMLPLAYER_PRIORITY - int "MML Player task priority" - default 100 - -config EXAMPLES_FMSYNTH_MMLPLAYER_STACKSIZE - int "MML Player stack size" - default 2048 - -endif diff --git a/examples/fmsynth/Make.defs b/examples/fmsynth/Make.defs deleted file mode 100644 index ecca6198f..000000000 --- a/examples/fmsynth/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/examples/fmsynth/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_EXAMPLES_FMSYNTH),) -CONFIGURED_APPS += $(APPDIR)/examples/fmsynth -endif diff --git a/examples/fmsynth/Makefile b/examples/fmsynth/Makefile deleted file mode 100644 index 11aa02ff9..000000000 --- a/examples/fmsynth/Makefile +++ /dev/null @@ -1,46 +0,0 @@ -############################################################################ -# apps/examples/fmsynth/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -# For fmsynth utilities - -ASRCS = -CSRCS = music_scale.c operator_algorithm.c - -# For fmsynth_keyboard - -PROGNAME = $(CONFIG_EXAMPLES_FMSYNTH_KEYBOARD_PROGNAME) -PRIORITY = $(CONFIG_EXAMPLES_FMSYNTH_KEYBOARD_PRIORITY) -STACKSIZE = $(CONFIG_EXAMPLES_FMSYNTH_KEYBOARD_STACKSIZE) -MAINSRC = keyboard_main.c - -# For fmsynth_mmlplayer - -PROGNAME += $(CONFIG_EXAMPLES_FMSYNTH_MMLPLAYER_PROGNAME) -PRIORITY += $(CONFIG_EXAMPLES_FMSYNTH_MMLPLAYER_PRIORITY) -STACKSIZE += $(CONFIG_EXAMPLES_FMSYNTH_MMLPLAYER_STACKSIZE) -MAINSRC += mmlplayer_main.c - -MODULE = $(CONFIG_EXAMPLES_FMSYNTH) - -include $(APPDIR)/Application.mk diff --git a/examples/fmsynth/keyboard_main.c b/examples/fmsynth/keyboard_main.c deleted file mode 100644 index e30eab3de..000000000 --- a/examples/fmsynth/keyboard_main.c +++ /dev/null @@ -1,452 +0,0 @@ -/**************************************************************************** - * apps/examples/fmsynth/keyboard_main.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <errno.h> -#include <pthread.h> -#include <sched.h> -#include <limits.h> - -#include <nuttx/audio/audio.h> -#include <audioutils/fmsynth.h> -#include <audioutils/nxaudio.h> - -#include "operator_algorithm.h" -#include "music_scale.h" - -/**************************************************************************** - * Pre-processor - ****************************************************************************/ - -#define APP_FS (48000) -#define APP_BPS (16) -#define APP_CHNUM (2) - -#define APP_DEFAULT_VOL (400) - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -struct app_options -{ - int volume; - int mode; -}; - -struct kbd_s -{ - struct nxaudio_s nxaudio; - - FAR fmsynth_sound_t *sound; - FAR fmsynth_op_t *carrier; - - volatile int request_scale; -}; - -struct key_convert_s -{ - int key; - char key_str; - FAR const char *dispstr; -}; - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -static void app_dequeue_cb(unsigned long arg, - FAR struct ap_buffer_s *apb); -static void app_complete_cb(unsigned long arg); -static void app_user_cb(unsigned long arg, - FAR struct audio_msg_s *msg, FAR bool *running); - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static struct kbd_s g_kbd; -static bool g_running = true; - -static struct nxaudio_callbacks_s cbs = -{ - app_dequeue_cb, - app_complete_cb, - app_user_cb -}; - -static struct key_convert_s key_convert[] = -{ - { OCTAVE(4, MUSIC_SCALE_C), 'a', "O4C" }, - { OCTAVE(4, MUSIC_SCALE_CS), 'w', "O4C+" }, - { OCTAVE(4, MUSIC_SCALE_D), 's', "O4D" }, - { OCTAVE(4, MUSIC_SCALE_DS), 'e', "O4D+" }, - { OCTAVE(4, MUSIC_SCALE_E), 'd', "O4E" }, - { OCTAVE(4, MUSIC_SCALE_F), 'f', "O4F" }, - { OCTAVE(4, MUSIC_SCALE_FS), 't', "O4F+" }, - { OCTAVE(4, MUSIC_SCALE_G), 'g', "O4G" }, - { OCTAVE(4, MUSIC_SCALE_GS), 'y', "O4G+" }, - { OCTAVE(4, MUSIC_SCALE_A), 'h', "O4A" }, - { OCTAVE(4, MUSIC_SCALE_AS), 'u', "O4A+" }, - { OCTAVE(4, MUSIC_SCALE_B), 'j', "O4B" }, - { OCTAVE(5, MUSIC_SCALE_C), 'k', "O5C" }, - { OCTAVE(5, MUSIC_SCALE_CS), 'o', "O5C+" }, - { OCTAVE(5, MUSIC_SCALE_D), 'l', "O5D" }, - { OCTAVE(5, MUSIC_SCALE_DS), 'p', "O5D+" }, - { OCTAVE(5, MUSIC_SCALE_E), ';', "O5E" }, -}; - -#define MAX_KEYCONVERT (sizeof(key_convert)/sizeof(key_convert[0])) - -/**************************************************************************** - * Private functions - ****************************************************************************/ - -/**************************************************************************** - * name: convert_key2idx - ****************************************************************************/ - -static int convert_key2idx(char key) -{ - int i; - - for (i = 0; i < MAX_KEYCONVERT; i++) - { - if (key == key_convert[i].key_str) - { - return i; - } - } - - return -1; -} - -/**************************************************************************** - * name: tick_callback - ****************************************************************************/ - -static void tick_callback(unsigned long arg) -{ - FAR struct kbd_s *kbd = (FAR struct kbd_s *)(uintptr_t)arg; - int scale = kbd->request_scale; - - if (scale != -1) - { - fmsynthsnd_set_soundfreq(kbd->sound, - musical_scale[scale]); - kbd->request_scale = -1; - } -} - -/**************************************************************************** - * name: app_dequeue_cb - ****************************************************************************/ - -static void app_dequeue_cb(unsigned long arg, - FAR struct ap_buffer_s *apb) -{ - FAR struct kbd_s *kbd = (FAR struct kbd_s *)(uintptr_t)arg; - - apb->curbyte = 0; - apb->flags = 0; - - if (kbd->request_scale != -1) - { - apb->nbytes = fmsynth_rendering(kbd->sound, - (FAR int16_t *)apb->samp, - apb->nmaxbytes / sizeof(int16_t), - kbd->nxaudio.chnum, - tick_callback, (unsigned long)kbd); - } - else - { - apb->nbytes = fmsynth_rendering(kbd->sound, - (FAR int16_t *)apb->samp, - apb->nmaxbytes / sizeof(int16_t), - kbd->nxaudio.chnum, - NULL, 0); - } - - if (g_running) - { - nxaudio_enqbuffer(&kbd->nxaudio, apb); - } -} - -/**************************************************************************** - * name: app_complete_cb - ****************************************************************************/ - -static void app_complete_cb(unsigned long arg) -{ - /* Do nothing.. */ - - printf("Audio loop is Done\n"); -} - -/**************************************************************************** - * name: app_user_cb - ****************************************************************************/ - -static void app_user_cb(unsigned long arg, - FAR struct audio_msg_s *msg, FAR bool *running) -{ - /* Do nothing.. */ -} - -/**************************************************************************** - * name: audio_loop_thread - ****************************************************************************/ - -static FAR void *audio_loop_thread(pthread_addr_t arg) -{ - FAR struct kbd_s *kbd = (FAR struct kbd_s *)arg; - - nxaudio_start(&kbd->nxaudio); - nxaudio_msgloop(&kbd->nxaudio, &cbs, (unsigned long)kbd); - - return NULL; -} - -/**************************************************************************** - * name: create_audio_thread - ****************************************************************************/ - -static pthread_t create_audio_thread(FAR struct kbd_s *kbd) -{ - pthread_t pid; - pthread_attr_t tattr; - struct sched_param sparam; - - pthread_attr_init(&tattr); - sparam.sched_priority = sched_get_priority_max(SCHED_FIFO) - 9; - pthread_attr_setschedparam(&tattr, &sparam); - pthread_attr_setstacksize(&tattr, 4096); - - pthread_create(&pid, &tattr, audio_loop_thread, - (pthread_addr_t)kbd); - pthread_setname_np(pid, "musickeyboard_thread"); - - return pid; -} - -/**************************************************************************** - * name: init_fmmusi_soundsc - ****************************************************************************/ - -static int init_keyboard_sound(FAR struct kbd_s *kbd, int fs, int mode) -{ - int ret = ERROR; - - fmsynth_initialize(fs); - - kbd->sound = fmsynthsnd_create(); - if (kbd->sound) - { - kbd->carrier = mode == 0 ? fmsynthutil_algorithm0() : - mode == 1 ? fmsynthutil_algorithm1() : - mode == 2 ? fmsynthutil_algorithm2() : - NULL; - if (!kbd->carrier) - { - fmsynthsnd_delete(kbd->sound); - return ret; - } - - fmsynthsnd_set_operator(kbd->sound, kbd->carrier); - kbd->request_scale = -1; - ret = OK; - } - - return ret; -} - -/**************************************************************************** - * name: fin_keyboard - ****************************************************************************/ - -static void fin_keyboard(FAR struct kbd_s *kbd) -{ - fin_nxaudio(&kbd->nxaudio); - fmsynthutil_delete_ops(kbd->carrier); - fmsynthsnd_delete(kbd->sound); -} - -/**************************************************************************** - * name: print_help - ****************************************************************************/ - -static void print_help(FAR char *name) -{ - printf("nsh> %s ([-v (volume from 0 to 100)]) ([-m (mode 0, 1 or 2)])\n", - name); -} - -/**************************************************************************** - * name: configure_option - ****************************************************************************/ - -static int configure_option(FAR struct app_options *option, - int argc, FAR char **argv) -{ - int opt; - - option->volume = APP_DEFAULT_VOL; - option->mode = 0; - while ((opt = getopt(argc, argv, "hv:m:")) != ERROR) - { - switch (opt) - { - case 'v': - option->volume = atoi(optarg) * 10; - if (option->volume < 0 || option->volume > 1000) - { - option->volume = 400; - } - break; - - case 'm': - option->mode = atoi(optarg); - if (option->mode < 0 || option->mode > 3) - { - option->mode = 0; - } - break; - - default: - return ERROR; - } - } - - return OK; -} - -/**************************************************************************** - * name: print_keyusage() - ****************************************************************************/ - -static void print_keyusage(void) -{ - int i; - - printf("press any key below to make a sound.\n"); - for (i = 0; i < MAX_KEYCONVERT; i++) - { - printf(" [KEY]: %c, [CODE]: %s\n", - key_convert[i].key_str, - key_convert[i].dispstr); - } - printf("\n"); -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * name: main - ****************************************************************************/ - -int main(int argc, FAR char *argv[]) -{ - int i; - int ret; - int key; - pthread_t pid; - struct app_options appopt; - int key_idx; - - g_running = true; - if (configure_option(&appopt, argc, argv) != OK) - { - print_help(argv[0]); - return -1; - } - - ret = init_nxaudio(&g_kbd.nxaudio, APP_FS, APP_BPS, APP_CHNUM); - if (ret < 0) - { - printf("init_nxaoud() returned with error!!\n"); - return -1; - } - - nxaudio_setvolume(&g_kbd.nxaudio, appopt.volume); - - ret = init_keyboard_sound(&g_kbd, APP_FS, appopt.mode); - if (ret != OK) - { - fin_nxaudio(&g_kbd.nxaudio); - printf("init_keyboard_sound() error!!\n"); - return -1; - } - - /* Render audio samples in audio buffers */ - - for (i = 0; i < g_kbd.nxaudio.abufnum; i++) - { - app_dequeue_cb((unsigned long)&g_kbd, - g_kbd.nxaudio.abufs[i]); - } - - pid = create_audio_thread(&g_kbd); - - printf("Start %s\n", argv[0]); - print_keyusage(); - - while (g_running) - { - key = getchar(); - if (key != EOF) - { - switch (key) - { - case 'q': - g_running = false; - break; - - default: - key_idx = convert_key2idx(key); - if (key_idx >= 0) - { - g_kbd.request_scale = key_convert[key_idx].key; - printf("%s \n", key_convert[key_idx].dispstr); - fflush(stdout); - } - break; - } - } - } - - nxaudio_stop(&g_kbd.nxaudio); - pthread_join(pid, NULL); - - fin_keyboard(&g_kbd); - - return ret; -} diff --git a/examples/fmsynth/mmlplayer_main.c b/examples/fmsynth/mmlplayer_main.c deleted file mode 100644 index dd2a2b478..000000000 --- a/examples/fmsynth/mmlplayer_main.c +++ /dev/null @@ -1,570 +0,0 @@ -/**************************************************************************** - * apps/examples/fmsynth/mmlplayer_main.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <errno.h> -#include <pthread.h> -#include <sched.h> -#include <limits.h> - -#include <nuttx/audio/audio.h> -#include <audioutils/fmsynth.h> -#include <audioutils/nxaudio.h> -#include <audioutils/mml_parser.h> - -#include "operator_algorithm.h" -#include "music_scale.h" -#include "mmlplayer_score.h" - -/**************************************************************************** - * Pre-processor - ****************************************************************************/ - -#define APP_FS (48000) -#define APP_BPS (16) -#define APP_CHNUM (2) -#define CARRIER_LEVEL (25.f / 100.f) - -#define APP_DEFAULT_VOL (1000) - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -struct app_options -{ - int volume; - int mode; -}; - -struct mmlplayer_s -{ - struct nxaudio_s nxaudio; - - /* Right hand sound */ - - FAR fmsynth_sound_t *rsound[2]; /* Need 2 sounds for CHORD */ - FAR fmsynth_op_t *rop[2]; /* Need 2 sounds for CHORD */ - - int rtick; - FAR char *rscore; - struct music_macro_lang_s rmml; - - /* Left hand sound */ - - FAR fmsynth_sound_t *lsound; - FAR fmsynth_op_t *lop; - int ltick; - FAR char *lscore; - struct music_macro_lang_s lmml; -}; - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -static void app_dequeue_cb(unsigned long arg, - FAR struct ap_buffer_s *apb); -static void app_complete_cb(unsigned long arg); -static void app_user_cb(unsigned long arg, - FAR struct audio_msg_s *msg, FAR bool *running); - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static struct mmlplayer_s g_mmlplayer; -static bool g_running = true; - -static struct nxaudio_callbacks_s cbs = -{ - app_dequeue_cb, - app_complete_cb, - app_user_cb -}; - -/**************************************************************************** - * Private functions - ****************************************************************************/ - -/**************************************************************************** - * name: print_note - ****************************************************************************/ - -static void print_note(bool LR, int index, int length) -{ - printf("%c: O%d%c : %d\n", LR ? 'R' : 'L', - index / 12, "CcDdEFfGgAaB"[index % 12], length); -} - -/**************************************************************************** - * name: print_chord - ****************************************************************************/ - -static void print_chord(bool LR, int index1, int index2, int length) -{ - printf("%c: [O%d%c, O%d%c] : %d\n", LR ? 'R' : 'L', - index1 / 12, "CcDdEFfGgAaB"[index1 % 12], - index2 / 12, "CcDdEFfGgAaB"[index2 % 12], - length); -} - -/**************************************************************************** - * name: update_righthand_note - ****************************************************************************/ - -static void update_righthand_note(FAR struct mmlplayer_s *fmmsc) -{ - int mml_ret; - struct mml_result_s mml_result; - - fmmsc->rtick = 0; - do - { - mml_ret = parse_mml(&fmmsc->rmml, &fmmsc->rscore, &mml_result); - switch (mml_ret) - { - case MML_TYPE_NOTE: - fmmsc->rtick = mml_result.length; - fmsynthsnd_set_soundfreq(fmmsc->rsound[0], - musical_scale[mml_result.note_idx[0]]); - fmsynthsnd_set_volume(fmmsc->rsound[0], CARRIER_LEVEL); - fmsynthsnd_set_volume(fmmsc->rsound[1], 0.f); - print_note(1, mml_result.note_idx[0], mml_result.length); - break; - - case MML_TYPE_CHORD: - fmmsc->rtick = mml_result.length; - fmsynthsnd_set_soundfreq(fmmsc->rsound[0], - musical_scale[mml_result.note_idx[0]]); - fmsynthsnd_set_soundfreq(fmmsc->rsound[1], - musical_scale[mml_result.note_idx[1]]); - fmsynthsnd_set_volume(fmmsc->rsound[0], CARRIER_LEVEL); - fmsynthsnd_set_volume(fmmsc->rsound[1], CARRIER_LEVEL); - print_chord(1, mml_result.note_idx[0], mml_result.note_idx[1], - mml_result.length); - break; - - case MML_TYPE_REST: - fmmsc->rtick = mml_result.length; - fmsynthsnd_set_volume(fmmsc->rsound[0], 0.f); - fmsynthsnd_set_volume(fmmsc->rsound[1], 0.f); - printf("R: Rest : %d\n", mml_result.length); - break; - - default: - - /* Do nothing */ - - break; - } - } - while (!fmmsc->rtick && mml_ret != MML_TYPE_EOF); -} - -/**************************************************************************** - * name: update_lefthand_note - ****************************************************************************/ - -static void update_lefthand_note(FAR struct mmlplayer_s *fmmsc) -{ - int mml_ret; - struct mml_result_s mml_result; - - fmmsc->ltick = 0; - do - { - mml_ret = parse_mml(&fmmsc->lmml, &fmmsc->lscore, &mml_result); - switch (mml_ret) - { - case MML_TYPE_NOTE: - fmmsc->ltick = mml_result.length; - fmsynthsnd_set_soundfreq(fmmsc->lsound, - musical_scale[mml_result.note_idx[0]]); - fmsynthsnd_set_volume(fmmsc->lsound, CARRIER_LEVEL); - print_note(0, mml_result.note_idx[0], mml_result.length); - break; - - case MML_TYPE_REST: - fmmsc->ltick = mml_result.length; - fmsynthsnd_set_volume(fmmsc->lsound, 0.f); - printf("L: Rest : %d\n", mml_result.length); - break; - - default: - - /* Do nothing */ - - break; - } - } - while (!fmmsc->ltick && mml_ret != MML_TYPE_EOF); -} - -/**************************************************************************** - * name: tick_callback - ****************************************************************************/ - -static void tick_callback(unsigned long arg) -{ - FAR struct mmlplayer_s *fmmsc = (FAR struct mmlplayer_s *)(uintptr_t)arg; - - fmmsc->rtick--; - fmmsc->ltick--; - - if (fmmsc->rtick <= 0) - { - update_righthand_note(fmmsc); - } - - if (fmmsc->ltick <= 0) - { - update_lefthand_note(fmmsc); - } -} - -/**************************************************************************** - * name: app_dequeue_cb - ****************************************************************************/ - -static void app_dequeue_cb(unsigned long arg, - FAR struct ap_buffer_s *apb) -{ - FAR struct mmlplayer_s *mmlplayer = (struct mmlplayer_s *)(uintptr_t)arg; - - apb->curbyte = 0; - apb->flags = 0; - apb->nbytes = fmsynth_rendering(mmlplayer->lsound, - (FAR int16_t *)apb->samp, - apb->nmaxbytes / sizeof(int16_t), - mmlplayer->nxaudio.chnum, - tick_callback, - (unsigned long)(uintptr_t)mmlplayer); - - if (g_running) - { - nxaudio_enqbuffer(&mmlplayer->nxaudio, apb); - } -} - -/**************************************************************************** - * name: app_complete_cb - ****************************************************************************/ - -static void app_complete_cb(unsigned long arg) -{ - /* Do nothing.. */ - - printf("Audio loop is Done\n"); -} - -/**************************************************************************** - * name: app_user_cb - ****************************************************************************/ - -static void app_user_cb(unsigned long arg, - FAR struct audio_msg_s *msg, FAR bool *running) -{ - /* Do nothing.. */ -} - -/**************************************************************************** - * name: autio_loop_thread - ****************************************************************************/ - -static FAR void *audio_loop_thread(pthread_addr_t arg) -{ - struct mmlplayer_s *mmlplayer = (FAR struct mmlplayer_s *)arg; - - nxaudio_start(&mmlplayer->nxaudio); - nxaudio_msgloop(&mmlplayer->nxaudio, &cbs, - (unsigned long)(uintptr_t)mmlplayer); - - return NULL; -} - -/**************************************************************************** - * name: create_audio_thread - ****************************************************************************/ - -static pthread_t create_audio_thread(FAR struct mmlplayer_s *mmlplayer) -{ - pthread_t pid; - pthread_attr_t tattr; - struct sched_param sparam; - - pthread_attr_init(&tattr); - sparam.sched_priority = sched_get_priority_max(SCHED_FIFO) - 9; - pthread_attr_setschedparam(&tattr, &sparam); - pthread_attr_setstacksize(&tattr, 4096); - - pthread_create(&pid, &tattr, audio_loop_thread, - (pthread_addr_t)mmlplayer); - pthread_setname_np(pid, "mmlplayer_thread"); - - return pid; -} - -/**************************************************************************** - * name: delete_sounds - ****************************************************************************/ - -static void delete_sounds(FAR struct mmlplayer_s *mmlplayer) -{ - if (mmlplayer->rop[0]) - { - fmsynthutil_delete_ops(mmlplayer->rop[0]); - } - - if (mmlplayer->rop[1]) - { - fmsynthutil_delete_ops(mmlplayer->rop[1]); - } - - if (mmlplayer->lop) - { - fmsynthutil_delete_ops(mmlplayer->lop); - } - - if (mmlplayer->rsound[0]) - { - fmsynthsnd_delete(mmlplayer->rsound[0]); - } - - if (mmlplayer->rsound[1]) - { - fmsynthsnd_delete(mmlplayer->rsound[1]); - } - - if (mmlplayer->lsound) - { - fmsynthsnd_delete(mmlplayer->lsound); - } -} - -/**************************************************************************** - * name: init_fmmusi_soundsc - ****************************************************************************/ - -static int init_mmlplayer_sound(FAR struct mmlplayer_s *mmlplayer, int fs, - int mode) -{ - CODE fmsynth_op_t *(*opfunc)(void); - - opfunc = mode == 0 ? fmsynthutil_algorithm0 : - mode == 1 ? fmsynthutil_algorithm1 : - mode == 2 ? fmsynthutil_algorithm2 : - NULL; - - fmsynth_initialize(fs); - - mmlplayer->rop[0] = NULL; - mmlplayer->rop[1] = NULL; - mmlplayer->lop = NULL; - - mmlplayer->rsound[0] = fmsynthsnd_create(); - mmlplayer->rsound[1] = fmsynthsnd_create(); - mmlplayer->lsound = fmsynthsnd_create(); - - if (mmlplayer->rsound[0] && mmlplayer->rsound[1] && mmlplayer->lsound) - { - mmlplayer->rop[0] = opfunc(); - mmlplayer->rop[1] = opfunc(); - mmlplayer->lop = opfunc(); - - if (mmlplayer->rop[0] && mmlplayer->rop[1] && mmlplayer->lop) - { - fmsynthsnd_set_operator(mmlplayer->rsound[0], mmlplayer->rop[0]); - fmsynthsnd_set_operator(mmlplayer->rsound[1], mmlplayer->rop[1]); - fmsynthsnd_set_operator(mmlplayer->lsound, mmlplayer->lop); - fmsynthsnd_set_operator(mmlplayer->lsound, mmlplayer->lop); - - fmsynthsnd_add_subsound(mmlplayer->lsound, mmlplayer->rsound[0]); - fmsynthsnd_add_subsound(mmlplayer->lsound, mmlplayer->rsound[1]); - } - else - { - delete_sounds(mmlplayer); - return ERROR; - } - } - else - { - delete_sounds(mmlplayer); - return ERROR; - } - - mmlplayer->rtick = 0; - mmlplayer->ltick = 0; - - init_mml(&mmlplayer->rmml, fs, 120, 4, 4); - init_mml(&mmlplayer->lmml, fs, 120, 4, 3); - - mmlplayer->rscore = (FAR char *)floh_walzer_right; - mmlplayer->lscore = (FAR char *)floh_walzer_left; - - return OK; -} - -/**************************************************************************** - * name: fin_mmlplayer - ****************************************************************************/ - -static void fin_mmlplayer(FAR struct mmlplayer_s *mmlplayer) -{ - fin_nxaudio(&mmlplayer->nxaudio); - delete_sounds(mmlplayer); -} - -/**************************************************************************** - * name: print_help - ****************************************************************************/ - -static void print_help(FAR char *name) -{ - printf("nsh> %s ([-v (volume)]) ([-m (mode)])\n", name); -} - -/**************************************************************************** - * name: configure_option - ****************************************************************************/ - -static int configure_option(FAR struct app_options *option, - int argc, char **argv) -{ - int opt; - - option->volume = APP_DEFAULT_VOL; - option->mode = 0; - while ((opt = getopt(argc, argv, "hv:m:")) != ERROR) - { - switch (opt) - { - case 'v': - option->volume = atoi(optarg) * 10; - if (option->volume < 0 || option->volume > 1000) - { - option->volume = 400; - } - - break; - - case 'm': - option->mode = atoi(optarg); - if (option->mode < 0 || option->mode >= 3) - { - option->mode = 0; - } - - break; - - case 'h': - return ERROR; - break; - - default: - return ERROR; - break; - } - } - - return OK; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * name: main - ****************************************************************************/ - -int main(int argc, FAR char *argv[]) -{ - int i; - int ret; - int key; - pthread_t pid; - struct app_options appopt; - - printf("Start %s\n", argv[0]); - - g_running = true; - if (configure_option(&appopt, argc, argv) != OK) - { - print_help(argv[0]); - return -1; - } - - ret = init_nxaudio(&g_mmlplayer.nxaudio, APP_FS, APP_BPS, APP_CHNUM); - if (ret < 0) - { - printf("init_nxaoud() returned with error!!\n"); - return -1; - } - - nxaudio_setvolume(&g_mmlplayer.nxaudio, appopt.volume); - - ret = init_mmlplayer_sound(&g_mmlplayer, APP_FS, appopt.mode); - if (ret != OK) - { - printf("init_mmlplayer_sound() returned error.\n"); - fin_nxaudio(&g_mmlplayer.nxaudio); - return -1; - } - - for (i = 0; i < g_mmlplayer.nxaudio.abufnum; i++) - { - app_dequeue_cb((unsigned long)&g_mmlplayer, - g_mmlplayer.nxaudio.abufs[i]); - } - - pid = create_audio_thread(&g_mmlplayer); - - while (g_running) - { - key = getchar(); - if (key != EOF) - { - switch (key) - { - case 'q': - g_running = false; - break; - } - } - } - - nxaudio_stop(&g_mmlplayer.nxaudio); - pthread_join(pid, NULL); - - fin_mmlplayer(&g_mmlplayer); - - return ret; -} diff --git a/examples/fmsynth/mmlplayer_score.h b/examples/fmsynth/mmlplayer_score.h deleted file mode 100644 index eae095aa1..000000000 --- a/examples/fmsynth/mmlplayer_score.h +++ /dev/null @@ -1,60 +0,0 @@ -/**************************************************************************** - * apps/examples/fmsynth/mmlplayer_score.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __APPS_EXAMPLES_FMSYNTH_MMLPLAYER_SCORE_H -#define __APPS_EXAMPLES_FMSYNTH_MMLPLAYER_SCORE_H - -static const char *floh_walzer_right = - "T120 L4 O4" - "R8 {D#C#}8" - "R8{[<A#>F#][<A#>F#]}{D#C#}8 R8{[<A#>F#][<A#>F#]}{D#C#}8" - "R8[<A#>F#]8R8[<A#>F#]8 R8{[<B>F][<B>F]} {D#C#}8" - "R8{[<B>F][<B>F]}{D#C#}8 R8{[<B>F][<B>F]}{D#C#}8 " - "R8[<B>F]8R8[<B>F]8 R8{[<A#>F#][<A#>F#]} {D#C#}8" - "R8{[<A#>F#][<A#>F#]}{D#C#}8 R8{[<A#>F#][<A#>F#]}{D#C#}8" - "R8[<A#>F#]8R8[<A#>F#]8 R8{[<B>F][<B>F]} {D#C#}8" - "R8{[<B>F][<B>F]}{D#C#}8 R8{[<B>F][<B>F]}{D#C#}8 " - "R8[<B>F]8R8[<B>F]8 R8{[<A#>F#][<A#>F#]} {D#C#}8" - "R8[<A#>F#]8R8[<A#>F#]8 R8[<A#>F#]8R8[<A#>F#]8 " - "R2 R8{[<B>F][<B>F]} {D#C#}8" - "R8[<B>F]8R8[<B>F]8 R8[<B>F]8R8[<B>F]8 " - "R2 R8{[<A#>F#][<A#>F#]} {D#C#}8" - "R8{[<A#>F#][<A#>F#]}{D#C#}8 R8{[<A#>F#][<A#>F#]}{D#C#}8" - "R8[<A#>F#]8R8[<A#>F#]8 R8{[<B>F][<B>F]} {D#C#}8" - "R8{[<B>F][<B>F]}{D#C#}8 R8{[<B>F][<B>F]}{D#C#}8 " - "R8[<B>F]8R8[<B>F]8 R8{[<A#>F#][<A#>F#]} {D#C#}8" - "[<A#>F#]8{CC}8{C#C} R8[<B>F]8[<A#>F#]8R8"; - -static const char *floh_walzer_left = - "T120 L4 O3" - "R4" - "F#.R8 F#.R8 F#D# C#.R8" - "C#.R8 C#.R8 C#D# F#.R8" - ">A#.R8 A#.R8 A#>C# D#.R8" - "D#.R8 D#.R8 D#C# <A#.R8" - "<F#C# F#C# {F#F}{F#G} G#R" - "G#C# G#C# {G#G}{G#A} A#R" - "F#.R8 F#.R8 F#D# C#.R8" - "C#.R8 C#.R8 C#D# F#.R8" - "C#8R8R R8C#8<F#8R8"; - -#endif /* __APPS_EXAMPLES_FMSYNTH_MMLPLAYER_SCORE_H */ diff --git a/examples/fmsynth/music_scale.c b/examples/fmsynth/music_scale.c deleted file mode 100644 index 185528be0..000000000 --- a/examples/fmsynth/music_scale.c +++ /dev/null @@ -1,99 +0,0 @@ -/**************************************************************************** - * apps/examples/fmsynth/music_scale.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/* Musical Scale frequency - * Negative value means not supported. - */ - -const float musical_scale[] = -{ - /* Octave 0 */ - - -1.f, -1.f, -1.f, - -1.f, -1.f, -1.f, - -1.f, -1.f, -1.f, - 27.5f, 29.13523509f, 30.86770631f, - - /* Octave 1 */ - - 32.70319563f, 34.64782883f, 36.70809593f, - 38.89087289f, 41.20344452f, 43.65352881f, - 46.2493027f, 48.99942933f, 51.913087f, - 55.f, 58.27047017f, 61.73541262f, - - /* Octave 2 */ - - 65.40639126f, 69.29565765f, 73.41619185f, - 77.78174577f, 82.40688903f, 87.30705762f, - 92.4986054f, 97.99885866f, 103.826174f, - 110.f, 116.5409403f, 123.4708252f, - - /* Octave 3 */ - - 130.8127825f, 138.5913153f, 146.8323837f, - 155.5634915f, 164.8137781f, 174.6141152f, - 184.9972108f, 195.9977173f, 207.652348f, - 220.f, 233.0818807f, 246.9416505f, - - /* Octave 4 */ - - 261.625565f, 277.1826306f, 293.6647674f, - 311.1269831f, 329.6275561f, 349.2282305f, - 369.9944216f, 391.9954347f, 415.304696f, - 440.f, 466.1637614f, 493.8833009f, - - /* Octave 5 */ - - 523.2511301f, 554.3652612f, 587.3295348f, - 622.2539662f, 659.2551123f, 698.456461f, - 739.9888432f, 783.9908693f, 830.6093921f, - 880.f, 932.3275227f, 987.7666018f, - - /* Octave 6 */ - - 1046.50226f, 1108.730522f, 1174.65907f, - 1244.507932f, 1318.510225f, 1396.912922f, - 1479.977686f, 1567.981739f, 1661.218784f, - 1760.f, 1864.655045f, 1975.533204f, - - /* Octave 7 */ - - 2093.00452f, 2217.461045f, 2349.318139f, - 2489.015865f, 2637.020449f, 2793.825844f, - 2959.955373f, 3135.963477f, 3322.437568f, - 3520.f, 3729.310091f, 3951.066407f, - - /* Octave 8 */ - - 4186.009041f, -1.f, -1.f, - -1.f, -1.f, -1.f, - -1.f, -1.f, -1.f, - -1.f, -1.f, -1.f, -}; - -/**************************************************************************** - * Public Functions - ****************************************************************************/ diff --git a/examples/fmsynth/music_scale.h b/examples/fmsynth/music_scale.h deleted file mode 100644 index afb5a384a..000000000 --- a/examples/fmsynth/music_scale.h +++ /dev/null @@ -1,64 +0,0 @@ -/**************************************************************************** - * apps/examples/fmsynth/music_scale.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __APPS_EXAMPLES_FMSYNTH_UTILS_MUSIC_SCALE_H -#define __APPS_EXAMPLES_FMSYNTH_UTILS_MUSIC_SCALE_H - -/**************************************************************************** - * Pre-processor definisions - ****************************************************************************/ - -#define MUSIC_SCALE_C (0) -#define MUSIC_SCALE_CS (1) -#define MUSIC_SCALE_D (2) -#define MUSIC_SCALE_DS (3) -#define MUSIC_SCALE_E (4) -#define MUSIC_SCALE_F (5) -#define MUSIC_SCALE_FS (6) -#define MUSIC_SCALE_G (7) -#define MUSIC_SCALE_GS (8) -#define MUSIC_SCALE_A (9) -#define MUSIC_SCALE_AS (10) -#define MUSIC_SCALE_B (11) -#define OCTAVE(n, s) ((s) + ((n) * 12)) - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -#undef EXTERN -#if defined(__cplusplus) -#define EXTERN extern "C" -extern "C" -{ -#else -#define EXTERN extern -#endif - -EXTERN const float musical_scale[]; - -#undef EXTERN -#if defined(__cplusplus) -} -#endif - -#endif /* __APPS_EXAMPLES_FMSYNTH_UTILS_MUSIC_SCALE_H */ diff --git a/examples/fmsynth/operator_algorithm.c b/examples/fmsynth/operator_algorithm.c deleted file mode 100644 index 6eafe9025..000000000 --- a/examples/fmsynth/operator_algorithm.c +++ /dev/null @@ -1,190 +0,0 @@ -/**************************************************************************** - * apps/examples/fmsynth/operator_algorithm.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <stddef.h> - -#include <audioutils/fmsynth.h> - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * name: fmsynthutil_algorithm0 - ****************************************************************************/ - -FAR fmsynth_op_t *fmsynthutil_algorithm0(void) -{ - /* [Simple sin operator] - * - * +--------------+ - * | OP (carrier) | ----> Audio out - * +--------------+ - */ - - FAR fmsynth_op_t *carrier; - fmsynth_eglevels_t level; - - /* Attack level and period time : 1.0, 40ms - * Decay Break level and period time : 0.3, 200ms - * Decay level and period time : 0.1, 100ms - * Sustain level and period time : 0.1, 100ms - * Release level : 0.0, 0ms - * - */ - - level.attack.level = 1.0f; - level.attack.period_ms = 40; - level.decaybrk.level = 0.3f; - level.decaybrk.period_ms = 200; - level.decay.level = 0.1f; - level.decay.period_ms = 100; - level.sustain.level = 0.1f; - level.sustain.period_ms = 100; - level.release.level = 0.f; - level.release.period_ms = 0; - - carrier = fmsynthop_create(); - if (carrier) - { - fmsynthop_set_envelope(carrier, &level); - fmsynthop_select_opfunc(carrier, FMSYNTH_OPFUNC_SIN); - } - - return carrier; -} - -/**************************************************************************** - * name: fmsynthutil_algorithm1 - ****************************************************************************/ - -FAR fmsynth_op_t *fmsynthutil_algorithm1(void) -{ - /* feed back - * +--------------------+ - * | | - * | +--------------+ | - * +->| OP (carrier) | -+--> Audio out - * +--------------+ - */ - - FAR fmsynth_op_t *carrier; - fmsynth_eglevels_t level; - - level.attack.level = 1.0f; - level.attack.period_ms = 40; - level.decaybrk.level = 0.3f; - level.decaybrk.period_ms = 200; - level.decay.level = 0.1f; - level.decay.period_ms = 100; - level.sustain.level = 0.1f; - level.sustain.period_ms = 100; - level.release.level = 0.f; - level.release.period_ms = 0; - - carrier = fmsynthop_create(); - if (carrier) - { - fmsynthop_set_envelope(carrier, &level); - fmsynthop_select_opfunc(carrier, FMSYNTH_OPFUNC_SIN); - fmsynthop_bind_feedback(carrier, carrier, 0.6f); - } - - return carrier; -} - -/**************************************************************************** - * name: fmsynthutil_algorithm2 - ****************************************************************************/ - -FAR fmsynth_op_t *fmsynthutil_algorithm2(void) -{ - /* feed back - * +--------------------+ - * | | - * | +--------------+ | +--------------+ - * +->| OP (subop) | -+-> | OP (carrier) | ----> Audio out - * +--------------+ +--------------+ - */ - - FAR fmsynth_op_t *carrier; - FAR fmsynth_op_t *subop; - fmsynth_eglevels_t level; - - level.attack.level = 1.0f; - level.attack.period_ms = 40; - level.decaybrk.level = 0.3f; - level.decaybrk.period_ms = 200; - level.decay.level = 0.1f; - level.decay.period_ms = 100; - level.sustain.level = 0.f; - level.sustain.period_ms = 0; - level.release.level = 0.f; - level.release.period_ms = 0; - - carrier = fmsynthop_create(); - if (carrier) - { - subop = fmsynthop_create(); - if (!subop) - { - fmsynthop_delete(carrier); - return NULL; - } - - fmsynthop_set_envelope(carrier, &level); - fmsynthop_select_opfunc(carrier, FMSYNTH_OPFUNC_SIN); - - fmsynthop_set_soundfreqrate(subop, 3.7f); - fmsynthop_select_opfunc(subop, FMSYNTH_OPFUNC_SIN); - - fmsynthop_cascade_subop(carrier, subop); - } - - return carrier; -} - -/**************************************************************************** - * name: fmsynthutil_delete_ops - ****************************************************************************/ - -void FAR fmsynthutil_delete_ops(FAR fmsynth_op_t *op) -{ - FAR fmsynth_op_t *tmp; - - while (op != NULL) - { - tmp = op->parallelop; - - if (op->cascadeop) - { - fmsynthutil_delete_ops(op->cascadeop); - } - - fmsynthop_delete(op); - op = tmp; - } -} diff --git a/examples/fmsynth/operator_algorithm.h b/examples/fmsynth/operator_algorithm.h deleted file mode 100644 index 45adb4a19..000000000 --- a/examples/fmsynth/operator_algorithm.h +++ /dev/null @@ -1,41 +0,0 @@ -/**************************************************************************** - * apps/examples/fmsynth/operator_algorithm.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __APPS_EXAMPLES_FMSYNTH_OPERATOR_ALGORITHM_H -#define __APPS_EXAMPLES_FMSYNTH_OPERATOR_ALGORITHM_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <audioutils/fmsynth.h> - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -FAR fmsynth_op_t *fmsynthutil_algorithm0(void); -FAR fmsynth_op_t *fmsynthutil_algorithm1(void); -FAR fmsynth_op_t *fmsynthutil_algorithm2(void); -void FAR fmsynthutil_delete_ops(FAR fmsynth_op_t *op); - -#endif /* __APPS_EXAMPLES_FMSYNTH_OPERATOR_ALGORITHM_H */ diff --git a/examples/foc/CMakeLists.txt b/examples/foc/CMakeLists.txt deleted file mode 100644 index 17fcc5fa6..000000000 --- a/examples/foc/CMakeLists.txt +++ /dev/null @@ -1,66 +0,0 @@ -# ############################################################################## -# apps/examples/foc/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_FOC) - nuttx_add_application( - NAME - foc - SRCS - foc_main.c - STACKSIZE - ${CONFIG_EXAMPLES_FOC_STACKSIZE} - PRIORITY - ${CONFIG_EXAMPLES_FOC_PRIORITY}) - - set(CSRCS foc_device.c foc_mq.c foc_thr.c foc_intf.c) - - if(CONFIG_BUILTIN) - list(APPEND CSRCS foc_parseargs.c) - endif() - - # fixed16 support - - if(CONFIG_INDUSTRY_FOC_FIXED16) - list(APPEND CSRCS foc_fixed16_thr.c foc_motor_b16.c) - endif() - - # float32 support - - if(CONFIG_INDUSTRY_FOC_FLOAT) - list(APPEND CSRCS foc_float_thr.c foc_motor_f32.c) - endif() - - # NxScope support - - if(CONFIG_EXAMPLES_FOC_NXSCOPE) - list(APPEND CSRCS foc_nxscope.c) - endif() - - # perf support - - if(CONFIG_EXAMPLES_FOC_PERF) - list(APPEND CSRCS foc_perf.c) - endif() - - target_sources(apps PRIVATE ${CSRCS}) - -endif() diff --git a/examples/foc/Kconfig b/examples/foc/Kconfig index 0c066575f..21a13332d 100644 --- a/examples/foc/Kconfig +++ b/examples/foc/Kconfig @@ -43,56 +43,6 @@ config EXAMPLES_FOC_VERBOSE default 1 range 0 2 -config EXAMPLES_FOC_PERF - bool "Enable performance meassurements" - default n - -config EXAMPLES_FOC_CONTROL_CRITSEC - bool "Protect controller thread with critical section" - default y - depends on BUILD_FLAT - ---help--- - Protect controller thread with critical section. - - If the controller frequency is high, system timer interrupts will - eventually interrupt the controller function, thereby increasing the - execution time. This may lead to skipping the control cycle, which - negatively affects the control algorithm. - - With this option enabled, interrupts are disabled for the duration - of the controller function execution. - - This option uses the kernel internal API directly, which means - it won't work outside of FLAT build. - -if EXAMPLES_FOC_PERF - -config EXAMPLES_FOC_PERF_LIVE - bool "Print FOC perf results on each max value change" - default n - ---help--- - With this option perf results are printed every time the maximum value - changes. The disadvantage of this method is that printing can directly - affect the pref result but it gives results in real time. - -config EXAMPLES_FOC_PERF_EXIT - bool "Print FOC perf results on thread exit" - default y - ---help--- - With this option perf results are printed on control thread exit. - -endif # EXAMPLES_FOC_PERF - -choice - prompt "FOC modulation selection" - default EXAMPLES_FOC_MODULATION_SVM3 - -config EXAMPLES_FOC_MODULATION_SVM3 - bool "FOC use SVM3" - select INDUSTRY_FOC_MODULATION_SVM3 - -endchoice # FOC modulation selection - choice prompt "FOC current controller selection" default EXAMPLES_FOC_CONTROL_PI @@ -115,6 +65,12 @@ config EXAMPLES_FOC_NOTIFIER_FREQ ---help--- Select the FOC notifier frequency +config EXAMPLES_FOC_IPHASE_ADC + int "FOC phase current scale [x100000]" + default 0 + ---help--- + This parameter is used to get real currents from ADC RAW values + config EXAMPLES_FOC_STATE_PRINT_FREQ int "FOC example data printer frequency" default 0 @@ -130,60 +86,18 @@ config EXAMPLES_FOC_STATE_USE_MODEL_PMSM Use PMSM model instead of real hardware choice - prompt "FOC motor controller type" + prompt "FOC sensored or sensorless configuration" default EXAMPLES_FOC_SENSORLESS config EXAMPLES_FOC_SENSORLESS - bool "FOC example sensorless motor controller" - select EXAMPLES_FOC_ANGOBS - ---help--- - Use sensorless controller, no angle sensor required. + bool "FOC example sensorless configuration" config EXAMPLES_FOC_SENSORED - bool "FOC example sensored motor controller" + bool "FOC example sensored configuration" select EXAMPLES_FOC_HAVE_ALIGN - ---help--- - Use sensored controller, angle sensor for motor required. endchoice # -config EXAMPLES_FOC_RUN_DISABLE - bool "FOC Disable motor controller" - ---help--- - Disable motor controller logic. Requested dq is always [0, 0]. - Useful for testing and benchmarking. - -menu "Motor phy" - -config EXAMPLES_FOC_MOTOR_POLES - int "FOC example motor poles pairs" - default 0 - -config EXAMPLES_FOC_MOTOR_RES - int "FOC example motor phase resistance (x1000000)" - default 0 - ---help--- - The unit is micro-ohm (1/1000000 ohm). - -config EXAMPLES_FOC_MOTOR_IND - int "FOC example motor phase inductance (x1000000)" - default 0 - ---help--- - The unit is micro micro-henry (1/1000000 henry). - -config EXAMPLES_FOC_MOTOR_FLUXLINK - int "FOC example motor flux linkage (x1000000)" - default 0 - ---help--- - The unit is micro-Vs (1/1000000 Vs). - Flux linkage can be obtained from the formula: - lambda_pm = (1 / sqrt(3)) * (60 / 2*PI) * (Ke / P) [Vs] - where: - Ke - motor voltage constant Ke [V/rpm] - P - motor pole pairs - -endmenu # Motor phy - if EXAMPLES_FOC_SENSORED choice @@ -201,6 +115,10 @@ endchoice # FOC sensored sensor selection if EXAMPLES_FOC_HAVE_QENCO +config EXAMPLES_FOC_MOTOR_POLES + int "FOC example motor poles pairs" + default 0 + config EXAMPLES_FOC_QENCO_POSMAX int "FOC example qencoder maximum position" default 0 @@ -210,7 +128,7 @@ config EXAMPLES_FOC_QENCO_DEVPATH default "/dev/qe" ---help--- The default path to the qenco device without the device minor number. - Default: /dev/qe + Default: /dev/qenco endif # EXAMPLES_FOC_HAVE_QENCO @@ -230,208 +148,21 @@ endif # EXAMPLES_FOC_SENSORED config EXAMPLES_FOC_HAVE_OPENLOOP bool "FOC example have open-loop controller" select INDUSTRY_FOC_ANGLE_OPENLOOP - select EXAMPLES_FOC_HAVE_ALIGN - default EXAMPLES_FOC_SENSORLESS + default y if EXAMPLES_FOC_SENSORLESS + default n config EXAMPLES_FOC_HAVE_TORQ bool "FOC example torque controller support" default n -if EXAMPLES_FOC_HAVE_TORQ - -config EXAMPLES_FOC_TORQ_MAX - int "FOC example torque maximum (x1000)" - default 1000 - ---help--- - The unit is mini-ampere (1/1000 ampere) for current mode. - The unit is mini-volt (1/1000 voltage) for voltage mode. - -endif # EXAMPLES_FOC_HAVE_TORQ - config EXAMPLES_FOC_HAVE_VEL bool "FOC example velocity controller support" - default EXAMPLES_FOC_SENSORLESS - select EXAMPLES_FOC_HAVE_TORQ + default y if EXAMPLES_FOC_SENSORLESS + default n config EXAMPLES_FOC_HAVE_POS bool "FOC example position controller support" default n - select EXAMPLES_FOC_HAVE_VEL - -config EXAMPLES_FOC_VELOBS - bool "FOC example velocity observer support" - default n - -if EXAMPLES_FOC_HAVE_VEL - -config EXAMPLES_FOC_VELCTRL_FREQ - int "FOC example velocity controller frequency" - default 1000 - -config EXAMPLES_FOC_VELNOW_FILTER - int "FOC example velocity controller (x1000)" - default 990 - -config EXAMPLES_FOC_VEL_MAX - int "FOC example velocity maximum (x1)" - default 1000 - ---help--- - The unit is rad/s - -choice - prompt "FOC velocity controller selection" - default EXAMPLES_FOC_VELCTRL_PI - -config EXAMPLES_FOC_VELCTRL_PI - bool "FOC velocity PI controller" - -endchoice # FOC velocity controller - -if EXAMPLES_FOC_VELCTRL_PI - -config EXAMPLES_FOC_VELCTRL_PI_KP - int "FOC velocity PI Kp (1000000x)" - default 0 - ---help--- - The Kp coefficient used in controller is: - Kp = EXAMPLES_FOC_VELCTRL_PI_KP/1000000 - -config EXAMPLES_FOC_VELCTRL_PI_KI - int "FOC velocity PI Ki (1000000x)" - default 0 - ---help--- - The Ki coefficient used in controller is: - Ki = EXAMPLES_FOC_VELCTRL_PI_KI/1000000 - -endif # EXAMPLES_FOC_VELCTRL_PI - -endif # EXAMPLES_FOC_HAVE_VEL - -config EXAMPLES_FOC_ANGOBS - bool "FOC example phase angle observer support" - default n - -choice - prompt "FOC angle observer selection" - default EXAMPLES_FOC_ANGOBS_NFO - depends on EXAMPLES_FOC_ANGOBS - -config EXAMPLES_FOC_ANGOBS_SMO - bool "FOC angle SMO observer" - select INDUSTRY_FOC_ANGLE_OSMO - -config EXAMPLES_FOC_ANGOBS_NFO - bool "FOC angle NFO observer" - select INDUSTRY_FOC_ANGLE_ONFO - -endchoice # FOC angle observer - -if EXAMPLES_FOC_ANGOBS - -config EXAMPLES_FOC_ANGOBS_HYS - int "FOC angle observer hysteresis [x1]" - default 0 - ---help--- - Hysteresis added to the observer to open-loop transition. - -config EXAMPLES_FOC_ANGOBS_THR - int "FOC angle observer velocity threshold [x1]" - default 0 - ---help--- - Once the motor reaches this speed, we switch from the open-loop angle - to the observer angle. - -config EXAMPLES_FOC_ANGOBS_MERGE_RATIO - int "FOC angle observer merge ratio" - default 50 - range 0 50 - ---help--- - This parameter determines how quickly we make the transition from the - open-loop angle to the observer angle after reaching the observer threshold - velocity. The smaler the value, the smoother the transition. - If set to 0 - smooth transition is disabled. - -endif # EXAMPLES_FOC_ANGOBS - -if EXAMPLES_FOC_ANGOBS_SMO - -config EXAMPLES_FOC_ANGOBS_SMO_KSLIDE - int "FOC angle SMO observer Kslide (x1000)" - default 0 - ---help--- - The Kslide coefficient used in observer is: - Kslide = EXAMPLES_FOC_ANGOBS_SMO_KSLIDE/1000 - -config EXAMPLES_FOC_ANGOBS_SMO_ERRMAX - int "FOC angle SMO observer err_max (x1000)" - default 0 - ---help--- - The err_max coefficient used in observer is: - err_max = EXAMPLES_FOC_ANGOBS_SMO_ERRMAX/1000 - -endif # EXAMPLES_FOC_ANGOBS_SMO - -if EXAMPLES_FOC_ANGOBS_NFO - -config EXAMPLES_FOC_ANGOBS_NFO_GAIN - int "FOC angle NFO observer gain (x1)" - default 0 - ---help--- - The gain coefficient used in observer at maximum duty cycle. - -config EXAMPLES_FOC_ANGOBS_NFO_GAINSLOW - int "FOC angle NFO observer gain slow (x1)" - default 0 - ---help--- - The gain coefficient used in observer at minimum duty cycle. - -endif # EXAMPLES_FOC_ANGOBS_NFO - -config EXAMPLES_FOC_VELOBS - bool "FOC example velocity observer support" - default n - -if EXAMPLES_FOC_VELOBS - -choice - prompt "FOC example velocity observer selection" - default EXAMPLES_FOC_VELOBS_DIV - -config EXAMPLES_FOC_VELOBS_DIV - bool "FOC velocity DIV observer" - select INDUSTRY_FOC_VELOCITY_ODIV - -config EXAMPLES_FOC_VELOBS_PLL - bool "FOC velocity PLL observer" - select INDUSTRY_FOC_VELOCITY_OPLL - -endchoice # FOC example velocity observer selection - -if EXAMPLES_FOC_VELOBS_DIV - -config EXAMPLES_FOC_VELOBS_DIV_SAMPLES - int "FOC velocity DIV observer samples" - default 10 - -config EXAMPLES_FOC_VELOBS_DIV_FILTER - int "FOC velocity DIV observer filter (x1000)" - default 990 - -endif # INDUSTRY_FOC_VELOCITY_ODIV - -if EXAMPLES_FOC_VELOBS_PLL - -config EXAMPLES_FOC_VELOBS_PLL_KP - int "FOC velocity PLL observer Kp (x1)" - default 0 - -config EXAMPLES_FOC_VELOBS_PLL_KI - int "FOC velocity PLL observer Ki (x1)" - default 0 - -endif # EXAMPLES_FOC_VELOBS_PLL - -endif # EXAMPLES_FOC_VELOBS menu "FOC user input" @@ -494,7 +225,6 @@ config EXAMPLES_FOC_SETPOINT_CONST config EXAMPLES_FOC_SETPOINT_ADC bool "Use ADC to control setpoint" - depends on ADC select EXAMPLES_FOC_HAVE_ADC select EXAMPLES_FOC_HAVE_SETPOINT_VAR @@ -584,36 +314,17 @@ config EXAMPLES_FOC_FMODE config EXAMPLES_FOC_MMODE int "Motor control mode" default 2 - range 1 5 + range 1 3 ---help--- 1 - torque control 2 - velocity control 3 - position control - 4 - align only - 5 - ident only - -config EXAMPLES_FOC_STOP_CURRENT - int "FOC stop state Q voltage/current [x1000]" - default 0 - ---help--- - This current or voltage will be forced on the motor Q axis when - the application is in active break state. config EXAMPLES_FOC_OPENLOOP_Q int "FOC open-loop Vq/Iq setting [x1000]" default 200 depends on EXAMPLES_FOC_HAVE_OPENLOOP -config EXAMPLES_FOC_FEEDFORWARD - bool "FOC use feedforward compensation for current controller" - select INDUSTRY_FOC_FEEDFORWARD - default n - ---help--- - This option enables feed-forward compensation for PI current controller - which can help achieve better performace of FOC. This option is not - recomended for sensorless operations and for current controllers that - already has high update frequency. - if EXAMPLES_FOC_CONTROL_PI config EXAMPLES_FOC_IDQ_KP @@ -635,15 +346,15 @@ config EXAMPLES_FOC_IDQ_KI endif #EXAMPLES_FOC_CONTROL_PI config EXAMPLES_FOC_RAMP_THR - int "FOC velocity ramp threshold [x1]" + int "FOC velocity ramp threshold [x1000]" default 0 config EXAMPLES_FOC_RAMP_ACC - int "FOC velocity ramp acc [x1]" + int "FOC velocity ramp acc [x1000]" default 0 config EXAMPLES_FOC_RAMP_DEC - int "FOC velocity ramp dec [x1]" + int "FOC velocity ramp dec [x1000]" default 0 config EXAMPLES_FOC_HAVE_ALIGN @@ -654,167 +365,25 @@ config EXAMPLES_FOC_HAVE_ALIGN if EXAMPLES_FOC_HAVE_ALIGN config EXAMPLES_FOC_ALIGN_VOLT - int "FOC example motor alignment voltage (x1000)" + int "EXAMPLES_FOC_ALIGN_VOLT (x1000)" default 0 config EXAMPLES_FOC_ALIGN_SEC - int "FOC example motor alignment time (x1000)" + int "EXAMPLES_FOC_ALIGN_SEC (x1000)" default 0 endif # EXAMPLES_FOC_HAVE_ALIGN -config EXAMPLES_FOC_HAVE_IDENT - bool "FOC example motor identification support" - select INDUSTRY_FOC_IDENT - default n - -if EXAMPLES_FOC_HAVE_IDENT - -config EXAMPLES_FOC_IDENT_RES_CURRENT - int "FOC motor ident resistance current (x1000)" - default 0 - -config EXAMPLES_FOC_IDENT_RES_KI - int "FOC motor ident resistance Ki (x1000)" - default 50 - -config EXAMPLES_FOC_IDENT_IND_VOLTAGE - int "FOC motor ident inductance voltage (x1000)" - default 0 - -config EXAMPLES_FOC_IDENT_RES_SEC - int "FOC motor ident resistance time in sec (x1000)" - default 0 - -config EXAMPLES_FOC_IDENT_IND_SEC - int "FOC motor ident inductance time in sec (x1000)" - default 0 - -config EXAMPLES_FOC_IDENT_IDLE - int "FOC motor ident idle steps" - default 100 - -endif # EXAMPLES_FOC_HAVE_IDENT - endmenu # FOC controller parameters config EXAMPLES_FOC_HAVE_RUN bool - default !EXAMPLES_FOC_RUN_DISABLE - -config EXAMPLES_FOC_NXSCOPE - bool "FOC nxscope support" - depends on LOGGING_NXSCOPE - select LOGGING_NXSCOPE_DISABLE_PUTLOCK + default y if !EXAMPLES_FOC_RUN_DISABLE default n - ---help--- - This option enables a controller real-time data capture with - the NxScope library. -if EXAMPLES_FOC_NXSCOPE - -config EXAMPLES_FOC_NXSCOPE_SERIAL - bool "FOC nxscope on serial port" - select LOGGING_NXSCOPE_INTF_SERIAL - default y - -if EXAMPLES_FOC_NXSCOPE_SERIAL - -config EXAMPLES_FOC_NXSCOPE_SERIAL_PATH - string "FOC nxscope serial path" - default "/dev/ttyS0" - -config EXAMPLES_FOC_NXSCOPE_SERIAL_BAUD - int "FOC nxscope serial baud" - default 115200 - -endif # EXAMPLES_FOC_NXSCOPE_SERIAL - -config EXAMPLES_FOC_NXSCOPE_STREAMBUF_LEN - int "FOC nxscope stream buffer length" - default 512 - -config EXAMPLES_FOC_NXSCOPE_RXBUF_LEN - int "FOC nxscope RX buffer length" - default 64 - -config EXAMPLES_FOC_NXSCOPE_RXPADDING - int "FOC nxscope RX padding" - default 0 - -config EXAMPLES_FOC_NXSCOPE_CHANNELS - int "FOC nxscope channels" - default 0 - -config EXAMPLES_FOC_NXSCOPE_PRESCALER - int "FOC nxscope prescaler" - default 1 - ---help--- - This option allows you to reduce the frequency of adding samples to - the NxScope buffer. - -config EXAMPLES_FOC_NXSCOPE_CFG - hex "FOC nxscope configuration" - default 0x00000000 - ---help--- - Each bit defines the controller state variable that can be captured. - Look at foc_nxscope.h for bits definitions. - -config EXAMPLES_FOC_NXSCOPE_START - bool "FOC nxscope start frame sync" +config EXAMPLES_FOC_RUN_DISABLE + bool "FOC Disable FOC motor controller" default n - ---help--- - If this option is set, the controller will be waiting for the start - frame from a NxScope master device. This allows us to capture - controller data from the very beginning of its operation. - -choice - prompt "FOC nxscope work caller" - default EXAMPLES_FOC_NXSCOPE_MAIN - -config EXAMPLES_FOC_NXSCOPE_MAIN - bool "FOC nxscope uses foc_main()" - ---help--- - Use foc_main() for NxScope communication. - -config EXAMPLES_FOC_NXSCOPE_CONTROL - bool "FOC nxscope uses control thread" - ---help--- - Use control thread for NxScope communication. - With this option enabled you should limit the number of nxscope channels. - Otherwise, handling incoming nxscope data may significantly delay the control - loop, and consequently, the control cycle may be missed. - -config EXAMPLES_FOC_NXSCOPE_THREAD - bool "FOC nxscope uses separate thread" - ---help--- - Use a separate thread for NxScope communication. - -endchoice # FOC nxscope work caller - -if EXAMPLES_FOC_NXSCOPE_CONTROL - -config EXAMPLES_FOC_NXSCOPE_WORK_PRESCALER - int "FOC nxscope work prescaler" - default 10 - ---help--- - This option allows you to reduce the frequency of calling nxscope worker. - -endif #EXAMPLES_FOC_NXSCOPE_CONTROL - -if EXAMPLES_FOC_NXSCOPE_THREAD - -config EXAMPLES_FOC_NXSCOPE_PRIO - int "FOC nxscope thread priority" - default 100 - -config EXAMPLES_FOC_NXSCOPE_STACKSIZE - int "FOC nxscope thread stack size" - default 2048 - -endif # EXAMPLES_FOC_NXSCOPE_THREAD - -endif # EXAMPLES_FOC_NXSCOPE endif # EXAMPLES_FOC diff --git a/examples/foc/Make.defs b/examples/foc/Make.defs index 646d0c54b..6543f814a 100644 --- a/examples/foc/Make.defs +++ b/examples/foc/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/foc/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -20,6 +18,6 @@ # ############################################################################ -ifneq ($(CONFIG_EXAMPLES_FOC),) +ifeq ($(CONFIG_EXAMPLES_FOC),y) CONFIGURED_APPS += examples/foc endif diff --git a/examples/foc/Makefile b/examples/foc/Makefile index e0785cf21..68b0d61b2 100644 --- a/examples/foc/Makefile +++ b/examples/foc/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/foc/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -52,16 +50,4 @@ ifeq ($(CONFIG_INDUSTRY_FOC_FLOAT),y) CSRCS += foc_float_thr.c foc_motor_f32.c endif -# NxScope support - -ifeq ($(CONFIG_EXAMPLES_FOC_NXSCOPE),y) - CSRCS += foc_nxscope.c -endif - -# perf support - -ifeq ($(CONFIG_EXAMPLES_FOC_PERF),y) -CSRCS += foc_perf.c -endif - include $(APPDIR)/Application.mk diff --git a/examples/foc/README.md b/examples/foc/README.md new file mode 100644 index 000000000..e124a7a39 --- /dev/null +++ b/examples/foc/README.md @@ -0,0 +1,83 @@ +# FOC example + +The main purpose of this example is to provide a universal template to +implement the motor controller based on the kernel-side FOC device and +the application-side FOC library. + +At the moment, this example implements a simple open-loop velocity controller. + +# Hardware setup + +This example has not yet implemented any mechanism to protect the +powered device. This means that there is no overtemeprature +protection, no overcurrent protection and no overvoltage protection. + +Make sure that you power the device properly and provide current +limits on your own so as not to break your hardware. + +# Configuration + +The FOC PI current controller parameters can be obtained from the given +equations: + +``` +Kp = ccb * Ls; +pp = Rs / Ls; +Ki = pp * Kp * T; +``` + +where: + Kp - PI proportional coefficient + Ki - PI integral coefficient + Rs - average phase serial resistance + Ls - average phase serial inductance + pp - pole plant + ccb - current control bandwidth + T - sampling period + +## Sample parameters for some commercially available motors + +* Odrive D6374 150KV + p = 7 + Rs = 0.0254 Ohm + Ls = 8.73 uH + i\_max = ? + v\_max = ? + + Example configuration for f\_PWM = 20kHz, f\_notifier = 10kHz, ccb=1000: + Kp = 0.0087 + Ki = 0.0025 + +* Linix 45ZWN24-40 (PMSM motor dedicated for NXP FRDM-MC-LVMTR kit) + p = 2 + Rs = 0.5 Ohm + Ls = 0.400 mH + i\_max = 2.34 A + v\_max = 24 V + + Example configuration for f\_PWM = 10kHz, f\_notifier = 5kHz, ccb=1000: + Kp = 0.4 + Ki = 0.1 + +* Bull-Running BR2804-1700 kV (motor provided with the ST P-NUCLEO-IHM07 kit) + p = 7 + Rs = 0.11 Ohm + Ls = 0.018 mH + i\_max = 1.2A + v\_max = 12V + + Example configuration for f\_PWM = 20kHz, f\_notifier = 10kHz, ccb=200: + Kp = 0.036 + Ki = 0.022 + +* iPower GBM2804H-100T (gimbal motor provided with the ST P-NUCLEO-IHM03 kit) + p = 7 + Rs = 5.29 Ohm + Ls = 1.05 mH + i\_max = 0.15A + v\_max = 12V + + Example configuration for f\_PWM = 10kHz, f\_notifier = 5kHz, ccb=TODO: + Kp = TODO + Ki = TODO + diff --git a/examples/foc/foc_adc.h b/examples/foc/foc_adc.h index fbc1a69ab..d578d1fb0 100644 --- a/examples/foc/foc_adc.h +++ b/examples/foc/foc_adc.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/foc/foc_adc.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/foc/foc_cfg.h b/examples/foc/foc_cfg.h index 6ce034347..d3710ee04 100644 --- a/examples/foc/foc_cfg.h +++ b/examples/foc/foc_cfg.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/foc/foc_cfg.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -29,15 +27,16 @@ #include <nuttx/config.h> -#include <stdbool.h> - /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ -#if defined(CONFIG_EXAMPLES_FOC_SENSORLESS) && \ - defined(CONFIG_EXAMPLES_FOC_SENSORED) -# error Simultaneous support for sensorless and sensored mode not supported +/* For now only torque mode supported for sensored */ + +#ifdef CONFIG_EXAMPLES_FOC_SENSORED +# ifndef CONFIG_EXAMPLES_FOC_HAVE_TORQ +# error +# endif #endif /* For now only sensorless velocity control supported */ @@ -48,28 +47,14 @@ # endif #endif -/* Position controller needs velocity controller */ - -#if defined(CONFIG_EXAMPLES_FOC_HAVE_POS) && \ - !defined(CONFIG_EXAMPLES_FOC_HAVE_VEL) -# error Position controller needs velocity controller -#endif - -/* Velocity controller needs torque controller */ - -#if defined(CONFIG_EXAMPLES_FOC_HAVE_VEL) && \ - !defined(CONFIG_EXAMPLES_FOC_HAVE_TORQ) -# error Velocity controller needs torque controller -#endif - /* Open-loop configuration */ #ifdef CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP # ifndef CONFIG_EXAMPLES_FOC_HAVE_VEL -# error open-loop needs CONFIG_EXAMPLES_FOC_HAVE_VEL set +# error # endif -# ifndef CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP -# error open-loop needs CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP +# ifndef CONFIG_INDUSTRY_FOC_ANGLE_OPENLOOP +# error # endif #endif @@ -82,33 +67,19 @@ /* Velocity ramp must be configured */ #if (CONFIG_EXAMPLES_FOC_RAMP_THR == 0) -# error CONFIG_EXAMPLES_FOC_RAMP_THR not configured +# error #endif #if (CONFIG_EXAMPLES_FOC_RAMP_ACC == 0) -# error CONFIG_EXAMPLES_FOC_RAMP_ACC not configured +# error #endif #if (CONFIG_EXAMPLES_FOC_RAMP_DEC == 0) -# error CONFIG_EXAMPLES_FOC_RAMP_DEC not configured +# error #endif -/* Motor identification support */ +/* ADC Iphase ratio must be provided */ -#ifdef CONFIG_EXAMPLES_FOC_HAVE_IDENT -# if (CONFIG_EXAMPLES_FOC_IDENT_RES_CURRENT == 0) -# error CONFIG_EXAMPLES_FOC_IDENT_RES_CURRENT not configured -# endif -# if (CONFIG_EXAMPLES_FOC_IDENT_RES_KI == 0) -# error CONFIG_EXAMPLES_FOC_IDENT_RES_KI not configured -# endif -# if (CONFIG_EXAMPLES_FOC_IDENT_IND_VOLTAGE == 0) -# error CONFIG_EXAMPLES_FOC_IDENT_IND_VOLTAGE not configured -# endif -# if (CONFIG_EXAMPLES_FOC_IDENT_RES_SEC == 0) -# error CONFIG_EXAMPLES_FOC_IDENT_RES_SEC not configured -# endif -# if (CONFIG_EXAMPLES_FOC_IDENT_IND_SEC == 0) -# error CONFIG_EXAMPLES_FOC_IDENT_IND_SEC not configured -# endif +#if (CONFIG_EXAMPLES_FOC_IPHASE_ADC == 0) +# error #endif /* Printer prescaler */ @@ -123,7 +94,9 @@ /* Velocity ramp configuration */ -#define RAMP_CFG_THR (CONFIG_EXAMPLES_FOC_RAMP_THR / 1.0f) +#define RAMP_CFG_THR (CONFIG_EXAMPLES_FOC_RAMP_THR / 1000.0f) +#define RAMP_CFG_ACC (CONFIG_EXAMPLES_FOC_RAMP_ACC / 1000.0f) +#define RAMP_CFG_DEC (CONFIG_EXAMPLES_FOC_RAMP_DEC / 1000.0f) #ifdef CONFIG_EXAMPLES_FOC_STATE_USE_MODEL_PMSM @@ -139,14 +112,25 @@ # define FOC_MODEL_INDQ (0.0002f) #endif +/* Motor alignment configuration */ + +#ifdef CONFIG_EXAMPLES_FOC_HAVE_ALIGN +# if CONFIG_EXAMPLES_FOC_ALIGN_VOLT == 0 +# error +# endif +# if CONFIG_EXAMPLES_FOC_ALIGN_SEC == 0 +# error +# endif +#endif + /* Qenco configuration */ #ifdef CONFIG_EXAMPLES_FOC_HAVE_QENCO # if CONFIG_EXAMPLES_FOC_MOTOR_POLES == 0 -# error CONFIG_EXAMPLES_FOC_MOTOR_POLES must be defined +# error # endif # if CONFIG_EXAMPLES_FOC_QENCO_POSMAX == 0 -# error CONFIG_EXAMPLES_FOC_QENCO_POSMAX must be defined +# error # endif #endif @@ -155,35 +139,35 @@ #if !defined(CONFIG_EXAMPLES_FOC_SETPOINT_CONST) && \ !defined(CONFIG_EXAMPLES_FOC_SETPOINT_ADC) && \ !defined(CONFIG_EXAMPLES_FOC_SETPOINT_CHAR) -# error setpoint source not selected +# error #endif /* Setpoint ADC scale factor */ #ifdef CONFIG_EXAMPLES_FOC_SETPOINT_ADC -# define SETPOINT_INTF_SCALE (1.0f / CONFIG_EXAMPLES_FOC_ADC_MAX) +# define SETPOINT_ADC_SCALE (1.0f / CONFIG_EXAMPLES_FOC_ADC_MAX) #endif /* If constant setpoint is selected, setpoint value must be provided */ #ifdef CONFIG_EXAMPLES_FOC_SETPOINT_CONST -# define SETPOINT_INTF_SCALE (1) +# define SETPOINT_ADC_SCALE (1) # if CONFIG_EXAMPLES_FOC_SETPOINT_CONST_VALUE == 0 -# error CONFIG_EXAMPLES_FOC_SETPOINT_CONST_VALUE not configured +# error # endif #endif /* CHARCTRL setpoint control */ #ifdef CONFIG_EXAMPLES_FOC_SETPOINT_CHAR -# define SETPOINT_INTF_SCALE (1.0f / (CONFIG_EXAMPLES_FOC_SETPOINT_MAX / 1000.0f)) +# define SETPOINT_ADC_SCALE (1 / 1000.0f) #endif /* VBUS source must be specified */ #if !defined(CONFIG_EXAMPLES_FOC_VBUS_CONST) && \ !defined(CONFIG_EXAMPLES_FOC_VBUS_ADC) -# error no VBUS source selected ! +# error #endif /* VBUS ADC scale factor */ @@ -202,86 +186,8 @@ # define VBUS_ADC_SCALE (1) # define VBUS_CONST_VALUE (CONFIG_EXAMPLES_FOC_VBUS_CONST_VALUE / 1000.0f) # if CONFIG_EXAMPLES_FOC_VBUS_CONST_VALUE == 0 -# error CONFIG_EXAMPLES_FOC_VBUS_CONST_VALUE not configured +# error # endif #endif -/* Velocity controller prescaler */ - -#define VEL_CONTROL_PRESCALER (CONFIG_EXAMPLES_FOC_NOTIFIER_FREQ / \ - CONFIG_EXAMPLES_FOC_VELCTRL_FREQ) - -/* Open-loop to observer angle merge factor */ - -#ifdef CONFIG_EXAMPLES_FOC_SENSORLESS -# if CONFIG_EXAMPLES_FOC_ANGOBS_MERGE_RATIO > 0 -# define ANGLE_MERGE_FACTOR (CONFIG_EXAMPLES_FOC_ANGOBS_MERGE_RATIO / 100.0f) -# endif -#endif - -/**************************************************************************** - * Public Type Definition - ****************************************************************************/ - -struct foc_thr_cfg_s -{ - int fmode; /* FOC control mode */ - int mmode; /* Motor control mode */ -#ifdef CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP - uint32_t qparam; /* Open-loop Q setting (x1000) */ - bool ol_force; /* Force open-loop */ -# ifdef CONFIG_EXAMPLES_FOC_ANGOBS - uint32_t ol_thr; /* Observer vel threshold [x1] */ - uint32_t ol_hys; /* Observer vel hysteresys [x1] */ -# endif -#endif - -#ifdef CONFIG_EXAMPLES_FOC_CONTROL_PI - uint32_t foc_pi_kp; /* FOC PI Kp (x1000) */ - uint32_t foc_pi_ki; /* FOC PI Ki (x1000) */ -#endif - -#ifdef CONFIG_EXAMPLES_FOC_HAVE_TORQ - uint32_t torqmax; /* Torque max (x1000) */ -#endif -#ifdef CONFIG_EXAMPLES_FOC_HAVE_VEL - uint32_t velmax; /* Velocity max (x1000) */ - uint32_t acc; /* Acceleration (x1) */ - uint32_t dec; /* Deceleration (x1) */ -#endif -#ifdef CONFIG_EXAMPLES_FOC_HAVE_POS - uint32_t posmax; /* Position max (x1000) */ -#endif - -#ifdef CONFIG_EXAMPLES_FOC_HAVE_IDENT - uint32_t ident_res_ki; /* Ident res Ki (x1000) */ - uint32_t ident_res_curr; /* Ident res current (x1000) */ - uint32_t ident_res_sec; /* Ident res sec */ - uint32_t ident_ind_volt; /* Ident res voltage (x1000) */ - uint32_t ident_ind_sec; /* Ident ind sec */ -#endif - -#ifdef CONFIG_EXAMPLES_FOC_HAVE_VEL - uint32_t vel_filter; /* Velocity filter (x1000) */ -#endif - -#ifdef CONFIG_EXAMPLES_FOC_VELOBS_PLL - uint32_t vel_pll_kp; /* Vel PLL observer Kp (x1000) */ - uint32_t vel_pll_ki; /* Vel PLL observer Ki (x1000) */ -#endif -#ifdef CONFIG_EXAMPLES_FOC_VELOBS_DIV - uint32_t vel_div_samples; /* Vel DIV observer samples */ - uint32_t vel_div_filter; /* Vel DIV observer filter (x1000) */ -#endif -#ifdef CONFIG_EXAMPLES_FOC_VELCTRL_PI - uint32_t vel_pi_kp; /* Vel controller PI Kp (x1000000) */ - uint32_t vel_pi_ki; /* Vel controller PI Ki (x1000000) */ -#endif - -#ifdef CONFIG_EXAMPLES_FOC_ANGOBS_NFO - uint32_t ang_nfo_slow; /* Ang NFO slow gain (x1) */ - uint32_t ang_nfo_gain; /* Ang NFO gain (x1) */ -#endif -}; - #endif /* __APPS_EXAMPLES_FOC_FOC_CFG_H */ diff --git a/examples/foc/foc_debug.h b/examples/foc/foc_debug.h index ed8ebcb20..fd92d247e 100644 --- a/examples/foc/foc_debug.h +++ b/examples/foc/foc_debug.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/foc/foc_debug.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/foc/foc_device.c b/examples/foc/foc_device.c index 3ebea241f..69429da35 100644 --- a/examples/foc/foc_device.c +++ b/examples/foc/foc_device.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/foc/foc_device.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -29,7 +27,6 @@ #include <stdio.h> #include <fcntl.h> #include <assert.h> -#include <unistd.h> #include "foc_debug.h" #include "foc_device.h" @@ -52,8 +49,7 @@ int foc_device_init(FAR struct foc_device_s *dev, int id) /* Get FOC devpath */ - snprintf(devpath, sizeof(devpath), "%s%d", - CONFIG_EXAMPLES_FOC_DEVPATH, id); + sprintf(devpath, "%s%d", CONFIG_EXAMPLES_FOC_DEVPATH, id); /* Open FOC device */ @@ -92,12 +88,6 @@ int foc_device_init(FAR struct foc_device_s *dev, int id) goto errout; } -#ifdef CONFIG_EXAMPLES_FOC_PERF - /* Initialize perf */ - - foc_perf_init(&dev->perf); -#endif - errout: return ret; } @@ -180,10 +170,6 @@ int foc_dev_state_get(FAR struct foc_device_s *dev) goto errout; } -#ifdef CONFIG_EXAMPLES_FOC_PERF - foc_perf_start(&dev->perf); -#endif - errout: return ret; } @@ -207,16 +193,6 @@ int foc_dev_params_set(FAR struct foc_device_s *dev) goto errout; } -#ifdef CONFIG_EXAMPLES_FOC_PERF - foc_perf_end(&dev->perf); -#endif - -#ifdef CONFIG_EXAMPLES_FOC_PERF_LIVE - /* Print perf live stats */ - - foc_perf_live(&dev->perf); -#endif - errout: return ret; } diff --git a/examples/foc/foc_device.h b/examples/foc/foc_device.h index aa056b63d..1b46b9cab 100644 --- a/examples/foc/foc_device.h +++ b/examples/foc/foc_device.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/foc/foc_device.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -29,8 +27,6 @@ #include <nuttx/config.h> -#include "foc_perf.h" - #include "industry/foc/foc_utils.h" /**************************************************************************** @@ -45,9 +41,6 @@ struct foc_device_s struct foc_info_s info; /* FOC dev info */ struct foc_state_s state; /* FOC dev state */ struct foc_params_s params; /* FOC dev params */ -#ifdef CONFIG_EXAMPLES_FOC_PERF - struct foc_perf_s perf; /* FOC dev perf */ -#endif }; /**************************************************************************** diff --git a/examples/foc/foc_fixed16_thr.c b/examples/foc/foc_fixed16_thr.c index 3c9a8c77b..67f31ecdc 100644 --- a/examples/foc/foc_fixed16_thr.c +++ b/examples/foc/foc_fixed16_thr.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/foc/foc_fixed16_thr.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -26,14 +24,11 @@ #include <nuttx/config.h> -#include <nuttx/spinlock.h> - -#include <assert.h> -#include <dspb16.h> -#include <fcntl.h> #include <stdio.h> -#include <string.h> -#include <unistd.h> +#include <fcntl.h> +#include <assert.h> + +#include <dspb16.h> #include "foc_cfg.h" #include "foc_debug.h" @@ -42,10 +37,6 @@ #include "industry/foc/foc_utils.h" #include "industry/foc/foc_common.h" -#ifdef CONFIG_EXAMPLES_FOC_NXSCOPE -# include "logging/nxscope/nxscope.h" -#endif - /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ @@ -54,18 +45,8 @@ # error #endif -/* Critical section */ - -#ifdef CONFIG_EXAMPLES_FOC_CONTROL_CRITSEC -# define foc_enter_critical() irqstate_t intflags = enter_critical_section() -# define foc_leave_critical() leave_critical_section(intflags) -#else -# define foc_enter_critical() -# define foc_leave_critical() -#endif - /**************************************************************************** - * Private Types + * Private Type Definition ****************************************************************************/ /**************************************************************************** @@ -141,9 +122,7 @@ static int foc_handler_run(FAR struct foc_motor_b16_s *motor, /* Get FOC handler state */ - foc_handler_state_b16(&motor->handler, - &motor->foc_state, - &motor->mod_state); + foc_handler_state_b16(&motor->handler, &motor->foc_state); return ret; } @@ -193,109 +172,6 @@ static int foc_state_print(FAR struct foc_motor_b16_s *motor) } #endif -#ifdef CONFIG_EXAMPLES_FOC_NXSCOPE -/**************************************************************************** - * Name: foc_fixed16_nxscope - ****************************************************************************/ - -static void foc_fixed16_nxscope(FAR struct foc_nxscope_s *nxs, - FAR struct foc_motor_b16_s *motor, - FAR struct foc_device_s *dev) -{ -#if (CONFIG_EXAMPLES_FOC_NXSCOPE_CFG != 0) - FAR b16_t *ptr = NULL; - int i = nxs->ch_per_inst * motor->envp->id; -#endif - - nxscope_lock(&nxs->nxs); - -#if (CONFIG_EXAMPLES_FOC_NXSCOPE_CFG & FOC_NXSCOPE_IABC) - ptr = (FAR b16_t *)&motor->foc_state.curr; - nxscope_put_vb16(&nxs->nxs, i++, ptr, CONFIG_MOTOR_FOC_PHASES); -#endif -#if (CONFIG_EXAMPLES_FOC_NXSCOPE_CFG & FOC_NXSCOPE_IDQ) - ptr = (FAR b16_t *)&motor->foc_state.idq; - nxscope_put_vb16(&nxs->nxs, i++, ptr, 2); -#endif -#if (CONFIG_EXAMPLES_FOC_NXSCOPE_CFG & FOC_NXSCOPE_IAB) - ptr = (FAR b16_t *)&motor->foc_state.iab; - nxscope_put_vb16(&nxs->nxs, i++, ptr, 2); -#endif -#if (CONFIG_EXAMPLES_FOC_NXSCOPE_CFG & FOC_NXSCOPE_VABC) - ptr = (FAR b16_t *)&motor->foc_state.volt; - nxscope_put_vb16(&nxs->nxs, i++, ptr, CONFIG_MOTOR_FOC_PHASES); -#endif -#if (CONFIG_EXAMPLES_FOC_NXSCOPE_CFG & FOC_NXSCOPE_VDQ) - ptr = (FAR b16_t *)&motor->foc_state.vdq; - nxscope_put_vb16(&nxs->nxs, i++, ptr, 2); -#endif -#if (CONFIG_EXAMPLES_FOC_NXSCOPE_CFG & FOC_NXSCOPE_VAB) - ptr = (FAR b16_t *)&motor->foc_state.vab; - nxscope_put_vb16(&nxs->nxs, i++, ptr, 2); -#endif -#if (CONFIG_EXAMPLES_FOC_NXSCOPE_CFG & FOC_NXSCOPE_AEL) - ptr = (FAR b16_t *)&motor->angle_el; - nxscope_put_vb16(&nxs->nxs, i++, ptr, 1); -#endif -#if (CONFIG_EXAMPLES_FOC_NXSCOPE_CFG & FOC_NXSCOPE_AM) - ptr = (FAR b16_t *)&motor->angle_m; - nxscope_put_vb16(&nxs->nxs, i++, ptr, 1); -#endif -#if (CONFIG_EXAMPLES_FOC_NXSCOPE_CFG & FOC_NXSCOPE_VEL) - ptr = (FAR b16_t *)&motor->vel_el; - nxscope_put_vb16(&nxs->nxs, i++, ptr, 1); -#endif -#if (CONFIG_EXAMPLES_FOC_NXSCOPE_CFG & FOC_NXSCOPE_VM) - ptr = (FAR b16_t *)&motor->vel_mech; - nxscope_put_vb16(&nxs->nxs, i++, ptr, 1); -#endif -#if (CONFIG_EXAMPLES_FOC_NXSCOPE_CFG & FOC_NXSCOPE_VBUS) - ptr = (FAR b16_t *)&motor->vbus; - nxscope_put_vb16(&nxs->nxs, i++, ptr, 1); -#endif -#if (CONFIG_EXAMPLES_FOC_NXSCOPE_CFG & FOC_NXSCOPE_SPTORQ) - ptr = (FAR b16_t *)&motor->torq; - nxscope_put_vb16(&nxs->nxs, i++, ptr, 3); -#endif -#if (CONFIG_EXAMPLES_FOC_NXSCOPE_CFG & FOC_NXSCOPE_SPVEL) - ptr = (FAR b16_t *)&motor->vel; - nxscope_put_vb16(&nxs->nxs, i++, ptr, 3); -#endif -#if (CONFIG_EXAMPLES_FOC_NXSCOPE_CFG & FOC_NXSCOPE_SPPOS) - ptr = (FAR b16_t *)&motor->pos; - nxscope_put_vb16(&nxs->nxs, i++, ptr, 3); -#endif -#if (CONFIG_EXAMPLES_FOC_NXSCOPE_CFG & FOC_NXSCOPE_DQREF) - ptr = (FAR b16_t *)&motor->dq_ref; - nxscope_put_vb16(&nxs->nxs, i++, ptr, 2); -#endif -#if (CONFIG_EXAMPLES_FOC_NXSCOPE_CFG & FOC_NXSCOPE_VDQCOMP) - ptr = (FAR b16_t *)&motor->vdq_comp; - nxscope_put_vb16(&nxs->nxs, i++, ptr, 2); -#endif -#if (CONFIG_EXAMPLES_FOC_NXSCOPE_CFG & FOC_NXSCOPE_SVM3) - b16_t svm3_tmp[4]; - - /* Convert sector to b16_t. - * Normally, a sector value is an integer in the range 1-6 but we convert - * it to b16_t and range to 0.1-0.6. This is to send the entire SVM3 state - * as b16_t array and scale the sector value closer to PWM duty values - * (range 0.0 to 0.5) which makes it easier to visualize the data later. - */ - - svm3_tmp[0] = b16mulb16(itob16(motor->mod_state.sector), ftob16(0.1f)); - svm3_tmp[1] = motor->mod_state.d_u; - svm3_tmp[2] = motor->mod_state.d_v; - svm3_tmp[3] = motor->mod_state.d_w; - - ptr = svm3_tmp; - nxscope_put_vb16(&nxs->nxs, i++, ptr, 4); -#endif - - nxscope_unlock(&nxs->nxs); -} -#endif - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -309,7 +185,8 @@ int foc_fixed16_thr(FAR struct foc_ctrl_env_s *envp) struct foc_mq_s handle; struct foc_motor_b16_s motor; struct foc_device_s dev; - int ret = OK; + int time = 0; + int ret = OK; DEBUGASSERT(envp); @@ -337,10 +214,9 @@ int foc_fixed16_thr(FAR struct foc_ctrl_env_s *envp) goto errout; } - /* Store data from device */ + /* Get PWM max duty */ motor.pwm_duty_max = FOCDUTY_TO_FIXED16(dev.info.hw_cfg.pwm_max); - motor.iphase_adc = b16idiv(dev.info.hw_cfg.iphase_scale, 100000); /* Start with motor free */ @@ -354,21 +230,7 @@ int foc_fixed16_thr(FAR struct foc_ctrl_env_s *envp) while (motor.mq.quit == false) { - foc_enter_critical(); - - if (motor.mq.start == true) - { - /* Get FOC device state */ - - ret = foc_dev_state_get(&dev); - if (ret < 0) - { - PRINTF("ERROR: foc_dev_state_get failed %d!\n", ret); - goto errout; - } - } - - PRINTFV("foc_fixed16_thr %d %d\n", envp->id, motor.time); + PRINTFV("foc_fixed16_thr %d %d\n", envp->id, time); /* Handle mqueue */ @@ -403,126 +265,102 @@ int foc_fixed16_thr(FAR struct foc_ctrl_env_s *envp) } motor.startstop = false; - - /* Start from the beginning of the control loop */ - - foc_leave_critical(); - continue; } - /* Ignore control logic if controller not started yet */ + /* Run control logic if controller started */ - if (motor.mq.start == false) + if (motor.mq.start == true) { - foc_leave_critical(); - usleep(1000); - continue; - } + /* Get FOC device state */ + + ret = foc_dev_state_get(&dev); + if (ret < 0) + { + PRINTF("ERROR: foc_dev_state_get failed %d!\n", ret); + goto errout; + } #ifdef CONFIG_EXAMPLES_FOC_STATE_USE_MODEL_PMSM - /* Get model state */ + /* Get model state */ - ret = foc_model_state_get(&motor, &dev); - if (ret < 0) - { - PRINTF("ERROR: foc_model_state_get failed %d!\n", ret); - goto errout; - } + ret = foc_model_state_get(&motor, &dev); + if (ret < 0) + { + PRINTF("ERROR: foc_model_state_get failed %d!\n", ret); + goto errout; + } #endif - /* Handle controller state */ + /* Handle controller state */ - ret = foc_dev_state_handle(&dev, &motor.fault); - if (ret < 0) - { - PRINTF("ERROR: foc_dev_state_handle failed %d!\n", ret); - goto errout; - } + ret = foc_dev_state_handle(&dev, &motor.fault); + if (ret < 0) + { + PRINTF("ERROR: foc_dev_state_handle failed %d!\n", ret); + goto errout; + } - /* Get motor state */ + /* Get motor state */ - ret = foc_motor_get(&motor); - if (ret < 0) - { - PRINTF("ERROR: foc_motor_get failed %d!\n", ret); - goto errout; - } + ret = foc_motor_get(&motor); + if (ret < 0) + { + PRINTF("ERROR: foc_motor_get failed %d!\n", ret); + goto errout; + } - /* Motor control */ + /* Motor control */ - ret = foc_motor_control(&motor); - if (ret < 0) - { - PRINTF("ERROR: foc_motor_control failed %d!\n", ret); - goto errout; - } + ret = foc_motor_control(&motor); + if (ret < 0) + { + PRINTF("ERROR: foc_motor_control failed %d!\n", ret); + goto errout; + } - /* Run FOC */ + /* Run FOC */ - ret = foc_handler_run(&motor, &dev); - if (ret < 0) - { - PRINTF("ERROR: foc_handler_run failed %d!\n", ret); - goto errout; - } + ret = foc_handler_run(&motor, &dev); + if (ret < 0) + { + PRINTF("ERROR: foc_handler_run failed %d!\n", ret); + goto errout; + } #ifdef FOC_STATE_PRINT_PRE - /* Print state if configured */ + /* Print state if configured */ - if (motor.time % FOC_STATE_PRINT_PRE == 0) - { - foc_state_print(&motor); - } + if (time % FOC_STATE_PRINT_PRE == 0) + { + foc_state_print(&motor); + } #endif #ifdef CONFIG_EXAMPLES_FOC_STATE_USE_MODEL_PMSM - /* Feed FOC model with data */ + /* Feed FOC model with data */ - foc_model_run_b16(&motor.model, - ftob16(FOC_MODEL_LOAD), - &motor.foc_state.vab); + foc_model_run_b16(&motor.model, + ftob16(FOC_MODEL_LOAD), + &motor.foc_state.vab); #endif - /* Set FOC device parameters */ + /* Set FOC device parameters */ - ret = foc_dev_params_set(&dev); - if (ret < 0) - { - PRINTF("ERROR: foc_dev_params_set failed %d!\n", ret); - goto errout; + ret = foc_dev_params_set(&dev); + if (ret < 0) + { + PRINTF("ERROR: foc_dev_params_set failed %d!\n", ret); + goto errout; + } } - -#ifdef CONFIG_EXAMPLES_FOC_NXSCOPE - /* Capture nxscope samples */ - - if (motor.time % CONFIG_EXAMPLES_FOC_NXSCOPE_PRESCALER == 0) + else { - foc_fixed16_nxscope(envp->nxs, &motor, &dev); - } -#endif - -#ifdef CONFIG_EXAMPLES_FOC_NXSCOPE_CONTROL - /* Handle nxscope work */ - - if (motor.time % CONFIG_EXAMPLES_FOC_NXSCOPE_WORK_PRESCALER == 0) - { - foc_nxscope_work(envp->nxs); - } -#endif - - /* Terminate control thread */ - - if (motor.ctrl_state == FOC_CTRL_STATE_TERMINATE) - { - PRINTF("TERMINATE CTRL THREAD\n"); - goto errout; + usleep(1000); } /* Increase counter */ - motor.time += 1; - - foc_leave_critical(); + time += 1; } errout: @@ -545,12 +383,6 @@ errout: PRINTF("ERROR: foc_device_deinit %d failed %d\n", envp->id, ret); } -#ifdef CONFIG_EXAMPLES_FOC_PERF_EXIT - /* Print final perf stats */ - - foc_perf_exit(&dev.perf); -#endif - PRINTF("foc_fixed16_thr %d exit\n", envp->id); return ret; diff --git a/examples/foc/foc_float_thr.c b/examples/foc/foc_float_thr.c index 4c52b86bf..615899276 100644 --- a/examples/foc/foc_float_thr.c +++ b/examples/foc/foc_float_thr.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/foc/foc_float_thr.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -26,14 +24,11 @@ #include <nuttx/config.h> -#include <nuttx/spinlock.h> - -#include <assert.h> -#include <dsp.h> -#include <fcntl.h> #include <stdio.h> -#include <string.h> -#include <unistd.h> +#include <fcntl.h> +#include <assert.h> + +#include <dsp.h> #include "foc_cfg.h" #include "foc_debug.h" @@ -42,10 +37,6 @@ #include "industry/foc/foc_utils.h" #include "industry/foc/foc_common.h" -#ifdef CONFIG_EXAMPLES_FOC_NXSCOPE -# include "logging/nxscope/nxscope.h" -#endif - /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ @@ -54,18 +45,8 @@ # error #endif -/* Critical section */ - -#ifdef CONFIG_EXAMPLES_FOC_CONTROL_CRITSEC -# define foc_enter_critical() irqstate_t intflags = enter_critical_section() -# define foc_leave_critical() leave_critical_section(intflags) -#else -# define foc_enter_critical() -# define foc_leave_critical() -#endif - /**************************************************************************** - * Private Types + * Private Type Definition ****************************************************************************/ /**************************************************************************** @@ -141,9 +122,7 @@ static int foc_handler_run(FAR struct foc_motor_f32_s *motor, /* Get FOC handler state */ - foc_handler_state_f32(&motor->handler, - &motor->foc_state, - &motor->mod_state); + foc_handler_state_f32(&motor->handler, &motor->foc_state); return ret; } @@ -194,121 +173,6 @@ static int foc_state_print(FAR struct foc_motor_f32_s *motor) } #endif -#ifdef CONFIG_EXAMPLES_FOC_NXSCOPE -/**************************************************************************** - * Name: foc_float_nxscope - ****************************************************************************/ - -static void foc_float_nxscope(FAR struct foc_nxscope_s *nxs, - FAR struct foc_motor_f32_s *motor, - FAR struct foc_device_s *dev) -{ -#if (CONFIG_EXAMPLES_FOC_NXSCOPE_CFG != 0) - FAR float *ptr = NULL; - int i = nxs->ch_per_inst * motor->envp->id; -#endif - -#ifndef CONFIG_EXAMPLES_FOC_NXSCOPE_CONTROL - nxscope_lock(&nxs->nxs); -#endif - -#if (CONFIG_EXAMPLES_FOC_NXSCOPE_CFG & FOC_NXSCOPE_IABC) - ptr = (FAR float *)&motor->foc_state.curr; - nxscope_put_vfloat(&nxs->nxs, i++, ptr, CONFIG_MOTOR_FOC_PHASES); -#endif -#if (CONFIG_EXAMPLES_FOC_NXSCOPE_CFG & FOC_NXSCOPE_IDQ) - ptr = (FAR float *)&motor->foc_state.idq; - nxscope_put_vfloat(&nxs->nxs, i++, ptr, 2); -#endif -#if (CONFIG_EXAMPLES_FOC_NXSCOPE_CFG & FOC_NXSCOPE_IAB) - ptr = (FAR float *)&motor->foc_state.iab; - nxscope_put_vfloat(&nxs->nxs, i++, ptr, 2); -#endif -#if (CONFIG_EXAMPLES_FOC_NXSCOPE_CFG & FOC_NXSCOPE_VABC) - ptr = (FAR float *)&motor->foc_state.volt; - nxscope_put_vfloat(&nxs->nxs, i++, ptr, CONFIG_MOTOR_FOC_PHASES); -#endif -#if (CONFIG_EXAMPLES_FOC_NXSCOPE_CFG & FOC_NXSCOPE_VDQ) - ptr = (FAR float *)&motor->foc_state.vdq; - nxscope_put_vfloat(&nxs->nxs, i++, ptr, 2); -#endif -#if (CONFIG_EXAMPLES_FOC_NXSCOPE_CFG & FOC_NXSCOPE_VAB) - ptr = (FAR float *)&motor->foc_state.vab; - nxscope_put_vfloat(&nxs->nxs, i++, ptr, 2); -#endif -#if (CONFIG_EXAMPLES_FOC_NXSCOPE_CFG & FOC_NXSCOPE_AEL) - ptr = (FAR float *)&motor->angle_el; - nxscope_put_vfloat(&nxs->nxs, i++, ptr, 1); -#endif -#if (CONFIG_EXAMPLES_FOC_NXSCOPE_CFG & FOC_NXSCOPE_AM) - ptr = (FAR float *)&motor->angle_m; - nxscope_put_vfloat(&nxs->nxs, i++, ptr, 1); -#endif -#if (CONFIG_EXAMPLES_FOC_NXSCOPE_CFG & FOC_NXSCOPE_VEL) - ptr = (FAR float *)&motor->vel_el; - nxscope_put_vfloat(&nxs->nxs, i++, ptr, 1); -#endif -#if (CONFIG_EXAMPLES_FOC_NXSCOPE_CFG & FOC_NXSCOPE_VM) - ptr = (FAR float *)&motor->vel_mech; - nxscope_put_vfloat(&nxs->nxs, i++, ptr, 1); -#endif -#if (CONFIG_EXAMPLES_FOC_NXSCOPE_CFG & FOC_NXSCOPE_VBUS) - ptr = (FAR float *)&motor->vbus; - nxscope_put_vfloat(&nxs->nxs, i++, ptr, 1); -#endif -#if (CONFIG_EXAMPLES_FOC_NXSCOPE_CFG & FOC_NXSCOPE_SPTORQ) - ptr = (FAR float *)&motor->torq; - nxscope_put_vfloat(&nxs->nxs, i++, ptr, 3); -#endif -#if (CONFIG_EXAMPLES_FOC_NXSCOPE_CFG & FOC_NXSCOPE_SPVEL) - ptr = (FAR float *)&motor->vel; - nxscope_put_vfloat(&nxs->nxs, i++, ptr, 3); -#endif -#if (CONFIG_EXAMPLES_FOC_NXSCOPE_CFG & FOC_NXSCOPE_SPPOS) - ptr = (FAR float *)&motor->pos; - nxscope_put_vfloat(&nxs->nxs, i++, ptr, 3); -#endif -#if (CONFIG_EXAMPLES_FOC_NXSCOPE_CFG & FOC_NXSCOPE_DQREF) - ptr = (FAR float *)&motor->dq_ref; - nxscope_put_vfloat(&nxs->nxs, i++, ptr, 2); -#endif -#if (CONFIG_EXAMPLES_FOC_NXSCOPE_CFG & FOC_NXSCOPE_VDQCOMP) - ptr = (FAR float *)&motor->vdq_comp; - nxscope_put_vfloat(&nxs->nxs, i++, ptr, 2); -#endif -#if (CONFIG_EXAMPLES_FOC_NXSCOPE_CFG & FOC_NXSCOPE_SVM3) - float svm3_tmp[4]; - - /* Convert sector to float. - * Normally, a sector value is an integer in the range 1-6 but we convert - * it to float and range to 0.1-0.6. This is to send the entire SVM3 state - * as float array and scale the sector value closer to PWM duty values - * (range 0.0 to 0.5) which makes it easier to visualize the data later. - */ - - svm3_tmp[0] = (float)motor->mod_state.sector * 0.1f; - svm3_tmp[1] = motor->mod_state.d_u; - svm3_tmp[2] = motor->mod_state.d_v; - svm3_tmp[3] = motor->mod_state.d_w; - - ptr = svm3_tmp; - nxscope_put_vfloat(&nxs->nxs, i++, ptr, 4); -#endif -#if (CONFIG_EXAMPLES_FOC_NXSCOPE_CFG & FOC_NXSCOPE_VOBS) - ptr = (FAR float *)&motor->vel_obs; - nxscope_put_vfloat(&nxs->nxs, i++, ptr, 1); -#endif -#if (CONFIG_EXAMPLES_FOC_NXSCOPE_CFG & FOC_NXSCOPE_AOBS) - ptr = (FAR float *)&motor->angle_obs; - nxscope_put_vfloat(&nxs->nxs, i++, ptr, 1); -#endif - -#ifndef CONFIG_EXAMPLES_FOC_NXSCOPE_CONTROL - nxscope_unlock(&nxs->nxs); -#endif -} -#endif - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -322,7 +186,8 @@ int foc_float_thr(FAR struct foc_ctrl_env_s *envp) struct foc_mq_s handle; struct foc_motor_f32_s motor; struct foc_device_s dev; - int ret = OK; + int time = 0; + int ret = OK; DEBUGASSERT(envp); @@ -350,10 +215,9 @@ int foc_float_thr(FAR struct foc_ctrl_env_s *envp) goto errout; } - /* Store data from device */ + /* Get PWM max duty */ motor.pwm_duty_max = FOCDUTY_TO_FLOAT(dev.info.hw_cfg.pwm_max); - motor.iphase_adc = dev.info.hw_cfg.iphase_scale / 100000.0f; /* Start with motor free */ @@ -367,21 +231,7 @@ int foc_float_thr(FAR struct foc_ctrl_env_s *envp) while (motor.mq.quit == false) { - foc_enter_critical(); - - if (motor.mq.start == true) - { - /* Get FOC device state */ - - ret = foc_dev_state_get(&dev); - if (ret < 0) - { - PRINTF("ERROR: foc_dev_state_get failed %d!\n", ret); - goto errout; - } - } - - PRINTFV("foc_float_thr %d %d\n", envp->id, motor.time); + PRINTFV("foc_float_thr %d %d\n", envp->id, time); /* Handle mqueue */ @@ -416,126 +266,102 @@ int foc_float_thr(FAR struct foc_ctrl_env_s *envp) } motor.startstop = false; - - /* Start from the beginning of the control loop */ - - foc_leave_critical(); - continue; } - /* Ignore control logic if controller not started yet */ + /* Run control logic if controller started */ - if (motor.mq.start == false) + if (motor.mq.start == true) { - foc_leave_critical(); - usleep(1000); - continue; - } + /* Get FOC device state */ + + ret = foc_dev_state_get(&dev); + if (ret < 0) + { + PRINTF("ERROR: foc_dev_state_get failed %d!\n", ret); + goto errout; + } #ifdef CONFIG_EXAMPLES_FOC_STATE_USE_MODEL_PMSM - /* Get model state */ + /* Get model state */ - ret = foc_model_state_get(&motor, &dev); - if (ret < 0) - { - PRINTF("ERROR: foc_model_state_get failed %d!\n", ret); - goto errout; - } + ret = foc_model_state_get(&motor, &dev); + if (ret < 0) + { + PRINTF("ERROR: foc_model_state_get failed %d!\n", ret); + goto errout; + } #endif - /* Handle controller state */ + /* Handle controller state */ - ret = foc_dev_state_handle(&dev, &motor.fault); - if (ret < 0) - { - PRINTF("ERROR: foc_dev_state_handle failed %d!\n", ret); - goto errout; - } + ret = foc_dev_state_handle(&dev, &motor.fault); + if (ret < 0) + { + PRINTF("ERROR: foc_dev_state_handle failed %d!\n", ret); + goto errout; + } - /* Get motor state */ + /* Get motor state */ - ret = foc_motor_get(&motor); - if (ret < 0) - { - PRINTF("ERROR: foc_motor_get failed %d!\n", ret); - goto errout; - } + ret = foc_motor_get(&motor); + if (ret < 0) + { + PRINTF("ERROR: foc_motor_get failed %d!\n", ret); + goto errout; + } - /* Motor control */ + /* Motor control */ - ret = foc_motor_control(&motor); - if (ret < 0) - { - PRINTF("ERROR: foc_motor_control failed %d!\n", ret); - goto errout; - } + ret = foc_motor_control(&motor); + if (ret < 0) + { + PRINTF("ERROR: foc_motor_control failed %d!\n", ret); + goto errout; + } - /* Run FOC */ + /* Run FOC */ - ret = foc_handler_run(&motor, &dev); - if (ret < 0) - { - PRINTF("ERROR: foc_handler_run failed %d!\n", ret); - goto errout; - } + ret = foc_handler_run(&motor, &dev); + if (ret < 0) + { + PRINTF("ERROR: foc_handler_run failed %d!\n", ret); + goto errout; + } #ifdef FOC_STATE_PRINT_PRE - /* Print state if configured */ + /* Print state if configured */ - if (motor.time % FOC_STATE_PRINT_PRE == 0) - { - foc_state_print(&motor); - } + if (time % FOC_STATE_PRINT_PRE == 0) + { + foc_state_print(&motor); + } #endif #ifdef CONFIG_EXAMPLES_FOC_STATE_USE_MODEL_PMSM - /* Feed FOC model with data */ + /* Feed FOC model with data */ - foc_model_run_f32(&motor.model, - FOC_MODEL_LOAD, - &motor.foc_state.vab); + foc_model_run_f32(&motor.model, + FOC_MODEL_LOAD, + &motor.foc_state.vab); #endif - /* Set FOC device parameters */ + /* Set FOC device parameters */ - ret = foc_dev_params_set(&dev); - if (ret < 0) - { - PRINTF("ERROR: foc_dev_prams_set failed %d!\n", ret); - goto errout; + ret = foc_dev_params_set(&dev); + if (ret < 0) + { + PRINTF("ERROR: foc_dev_prams_set failed %d!\n", ret); + goto errout; + } } - -#ifdef CONFIG_EXAMPLES_FOC_NXSCOPE - /* Capture nxscope samples */ - - if (motor.time % CONFIG_EXAMPLES_FOC_NXSCOPE_PRESCALER == 0) + else { - foc_float_nxscope(envp->nxs, &motor, &dev); - } -#endif - -#ifdef CONFIG_EXAMPLES_FOC_NXSCOPE_CONTROL - /* Handle nxscope work */ - - if (motor.time % CONFIG_EXAMPLES_FOC_NXSCOPE_WORK_PRESCALER == 0) - { - foc_nxscope_work(envp->nxs); - } -#endif - - /* Terminate control thread */ - - if (motor.ctrl_state == FOC_CTRL_STATE_TERMINATE) - { - PRINTF("TERMINATE CTRL THREAD\n"); - goto errout; + usleep(1000); } /* Increase counter */ - motor.time += 1; - - foc_leave_critical(); + time += 1; } errout: @@ -558,12 +384,6 @@ errout: PRINTF("ERROR: foc_device_deinit %d failed %d\n", envp->id, ret); } -#ifdef CONFIG_EXAMPLES_FOC_PERF_EXIT - /* Print final perf stats */ - - foc_perf_exit(&dev.perf); -#endif - PRINTF("foc_float_thr %d exit\n", envp->id); return ret; diff --git a/examples/foc/foc_intf.c b/examples/foc/foc_intf.c index be8e1ba5d..45edfa212 100644 --- a/examples/foc/foc_intf.c +++ b/examples/foc/foc_intf.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/foc/foc_intf.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -30,7 +28,6 @@ #include <fcntl.h> #include <assert.h> #include <errno.h> -#include <unistd.h> #include <sys/ioctl.h> @@ -73,7 +70,7 @@ #endif /**************************************************************************** - * Private Types + * Private Type Definition ****************************************************************************/ #ifdef CONFIG_EXAMPLES_FOC_HAVE_BUTTON @@ -591,7 +588,7 @@ int foc_intf_init(void) #endif #ifdef FOC_HAVE_INTF -errout: + errout: #endif return ret; @@ -639,7 +636,7 @@ int foc_intf_deinit(void) #endif #ifdef FOC_HAVE_INTF -errout: + errout: #endif return ret; @@ -689,7 +686,7 @@ int foc_intf_update(FAR struct foc_intf_data_s *data) #endif #ifdef FOC_HAVE_INTF -errout: + errout: #endif return ret; diff --git a/examples/foc/foc_intf.h b/examples/foc/foc_intf.h index ca6edf7bd..286898319 100644 --- a/examples/foc/foc_intf.h +++ b/examples/foc/foc_intf.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/foc/foc_intf.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/foc/foc_main.c b/examples/foc/foc_main.c index 2f1b6b0c4..80b285bdd 100644 --- a/examples/foc/foc_main.c +++ b/examples/foc/foc_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/foc/foc_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -45,10 +43,6 @@ #include "industry/foc/foc_common.h" -#ifdef CONFIG_EXAMPLES_FOC_NXSCOPE -# include "foc_nxscope.h" -#endif - /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ @@ -61,96 +55,148 @@ #define INST_EN_DEFAULT (0xff) -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/* Default configuration */ - -struct args_s g_args = -{ - .time = CONFIG_EXAMPLES_FOC_TIME_DEFAULT, - .state = CONFIG_EXAMPLES_FOC_STATE_INIT, - .en = INST_EN_DEFAULT, - .cfg = - { - .fmode = CONFIG_EXAMPLES_FOC_FMODE, - .mmode = CONFIG_EXAMPLES_FOC_MMODE, -#ifdef CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP - .qparam = CONFIG_EXAMPLES_FOC_OPENLOOP_Q, - .ol_force = false, -# ifdef CONFIG_EXAMPLES_FOC_ANGOBS - .ol_hys = CONFIG_EXAMPLES_FOC_ANGOBS_HYS, - .ol_thr = CONFIG_EXAMPLES_FOC_ANGOBS_THR, -# endif -#endif -#ifdef CONFIG_EXAMPLES_FOC_CONTROL_PI - .foc_pi_kp = CONFIG_EXAMPLES_FOC_IDQ_KP, - .foc_pi_ki = CONFIG_EXAMPLES_FOC_IDQ_KI, -#endif -#ifdef CONFIG_EXAMPLES_FOC_SETPOINT_CONST -# ifdef CONFIG_EXAMPLES_FOC_HAVE_TORQ - .torqmax = CONFIG_EXAMPLES_FOC_SETPOINT_CONST_VALUE, -# endif -# ifdef CONFIG_EXAMPLES_FOC_HAVE_VEL - .velmax = CONFIG_EXAMPLES_FOC_SETPOINT_CONST_VALUE, -# endif -# ifdef CONFIG_EXAMPLES_FOC_HAVE_POS - .posmax = CONFIG_EXAMPLES_FOC_SETPOINT_CONST_VALUE, -# endif -#else -# ifdef CONFIG_EXAMPLES_FOC_HAVE_TORQ - .torqmax = CONFIG_EXAMPLES_FOC_SETPOINT_MAX, -# endif -# ifdef CONFIG_EXAMPLES_FOC_HAVE_VEL - .velmax = CONFIG_EXAMPLES_FOC_SETPOINT_MAX, -# endif -# ifdef CONFIG_EXAMPLES_FOC_HAVE_POS - .posmax = CONFIG_EXAMPLES_FOC_SETPOINT_MAX, -# endif -#endif -#ifdef CONFIG_EXAMPLES_FOC_HAVE_VEL - .acc = CONFIG_EXAMPLES_FOC_RAMP_ACC, - .dec = CONFIG_EXAMPLES_FOC_RAMP_DEC, -#endif -#ifdef CONFIG_EXAMPLES_FOC_HAVE_IDENT - .ident_res_ki = CONFIG_EXAMPLES_FOC_IDENT_RES_KI, - .ident_res_curr = CONFIG_EXAMPLES_FOC_IDENT_RES_CURRENT, - .ident_res_sec = CONFIG_EXAMPLES_FOC_IDENT_RES_SEC, - .ident_ind_volt = CONFIG_EXAMPLES_FOC_IDENT_IND_VOLTAGE, - .ident_ind_sec = CONFIG_EXAMPLES_FOC_IDENT_IND_SEC, -#endif -#ifdef CONFIG_EXAMPLES_FOC_HAVE_VEL - .vel_filter = CONFIG_EXAMPLES_FOC_VELNOW_FILTER, -#endif -#ifdef CONFIG_EXAMPLES_FOC_VELOBS_PLL - .vel_pll_kp = CONFIG_EXAMPLES_FOC_VELOBS_PLL_KP, - .vel_pll_ki = CONFIG_EXAMPLES_FOC_VELOBS_PLL_KI, -#endif -#ifdef CONFIG_EXAMPLES_FOC_VELOBS_DIV - .vel_div_samples = CONFIG_EXAMPLES_FOC_VELOBS_DIV_SAMPLES, - .vel_div_filter = CONFIG_EXAMPLES_FOC_VELOBS_DIV_FILTER, -#endif -#ifdef CONFIG_EXAMPLES_FOC_VELCTRL_PI - .vel_pi_kp = CONFIG_EXAMPLES_FOC_VELCTRL_PI_KP, - .vel_pi_ki = CONFIG_EXAMPLES_FOC_VELCTRL_PI_KI, -#endif -#ifdef CONFIG_EXAMPLES_FOC_ANGOBS_NFO - .ang_nfo_slow = CONFIG_EXAMPLES_FOC_ANGOBS_NFO_GAINSLOW, - .ang_nfo_gain = CONFIG_EXAMPLES_FOC_ANGOBS_NFO_GAIN, -#endif - } -}; - -/* Start allowed at default */ - -static bool g_start_allowed = true; -static pthread_mutex_t g_start_allowed_lock = PTHREAD_MUTEX_INITIALIZER; - /**************************************************************************** * Private Functions ****************************************************************************/ +/**************************************************************************** + * Name: init_args + ****************************************************************************/ + +static void init_args(FAR struct args_s *args) +{ + args->time = + (args->time == 0 ? CONFIG_EXAMPLES_FOC_TIME_DEFAULT : args->time); + args->fmode = + (args->fmode == 0 ? CONFIG_EXAMPLES_FOC_FMODE : args->fmode); + args->mmode = + (args->mmode == 0 ? CONFIG_EXAMPLES_FOC_MMODE : args->mmode); +#ifdef CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP + args->qparam = + (args->qparam == 0 ? CONFIG_EXAMPLES_FOC_OPENLOOP_Q : args->qparam); +#endif + +#ifdef CONFIG_EXAMPLES_FOC_CONTROL_PI + args->foc_pi_kp = + (args->foc_pi_kp == 0 ? CONFIG_EXAMPLES_FOC_IDQ_KP : args->foc_pi_kp); + args->foc_pi_ki = + (args->foc_pi_ki == 0 ? CONFIG_EXAMPLES_FOC_IDQ_KI : args->foc_pi_ki); +#endif + + /* Setpoint configuration */ + +#ifdef CONFIG_EXAMPLES_FOC_HAVE_TORQ +#ifdef CONFIG_EXAMPLES_FOC_SETPOINT_CONST + args->torqmax = + (args->torqmax == 0 ? + CONFIG_EXAMPLES_FOC_SETPOINT_CONST_VALUE : args->torqmax); +#else + args->torqmax = + (args->torqmax == 0 ? + CONFIG_EXAMPLES_FOC_SETPOINT_MAX : args->torqmax); +#endif +#endif +#ifdef CONFIG_EXAMPLES_FOC_HAVE_VEL +#ifdef CONFIG_EXAMPLES_FOC_SETPOINT_CONST + args->velmax = + (args->velmax == 0 ? + CONFIG_EXAMPLES_FOC_SETPOINT_CONST_VALUE : args->velmax); +#else + args->velmax = + (args->velmax == 0 ? + CONFIG_EXAMPLES_FOC_SETPOINT_MAX : args->velmax); +#endif +#endif +#ifdef CONFIG_EXAMPLES_FOC_HAVE_POS +#ifdef CONFIG_EXAMPLES_FOC_SETPOINT_CONST + args->posmax = + (args->posmax == 0 ? + CONFIG_EXAMPLES_FOC_SETPOINT_CONST_VALUE : args->posmax); +#else + args->posmax = + (args->posmax == 0 ? + CONFIG_EXAMPLES_FOC_SETPOINT_MAX : args->posmax); +#endif +#endif + + args->state = + (args->state == 0 ? CONFIG_EXAMPLES_FOC_STATE_INIT : args->state); + args->en = (args->en == -1 ? INST_EN_DEFAULT : args->en); +} + +/**************************************************************************** + * Name: validate_args + ****************************************************************************/ + +static int validate_args(FAR struct args_s *args) +{ + int ret = -EINVAL; + +#ifdef CONFIG_EXAMPLES_FOC_CONTROL_PI + /* Current PI controller */ + + if (args->foc_pi_kp == 0 && args->foc_pi_ki == 0) + { + PRINTF("ERROR: missing FOC Kp/Ki configuration\n"); + goto errout; + } +#endif + + /* FOC operation mode */ + + if (args->fmode != FOC_FMODE_IDLE && + args->fmode != FOC_FMODE_VOLTAGE && + args->fmode != FOC_FMODE_CURRENT) + { + PRINTF("Invalid op mode value %d s\n", args->fmode); + goto errout; + } + + /* Example control mode */ + + if ( +#ifdef CONFIG_EXAMPLES_FOC_HAVE_TORQ + args->mmode != FOC_MMODE_TORQ && +#endif +#ifdef CONFIG_EXAMPLES_FOC_HAVE_VEL + args->mmode != FOC_MMODE_VEL && +#endif +#ifdef CONFIG_EXAMPLES_FOC_HAVE_POS + args->mmode != FOC_MMODE_POS && +#endif + 1) + { + PRINTF("Invalid ctrl mode value %d s\n", args->mmode); + goto errout; + } + + /* Example state */ + + if (args->state != FOC_EXAMPLE_STATE_FREE && + args->state != FOC_EXAMPLE_STATE_STOP && + args->state != FOC_EXAMPLE_STATE_CW && + args->state != FOC_EXAMPLE_STATE_CCW) + { + PRINTF("Invalid state value %d s\n", args->state); + goto errout; + } + + /* Time parameter */ + + if (args->time <= 0 && args->time != -1) + { + PRINTF("Invalid time value %d s\n", args->time); + goto errout; + } + + /* Otherwise OK */ + + ret = OK; + +errout: + return ret; +} + /**************************************************************************** * Name: foc_mq_send ****************************************************************************/ @@ -165,7 +211,7 @@ static int foc_mq_send(mqd_t mqd, uint8_t msg, FAR void *data) /* Data max 4B */ - tmp = *((FAR uint32_t *)data); + tmp = *((FAR uint32_t *) data); buffer[0] = msg; buffer[1] = ((tmp & 0x000000ff) >> 0); @@ -232,20 +278,6 @@ static int foc_kill_send(mqd_t mqd) return foc_mq_send(mqd, CONTROL_MQ_MSG_KILL, (FAR void *)&tmp); } -#ifdef CONFIG_EXAMPLES_FOC_NXSCOPE_START -/**************************************************************************** - * Name: foc_nxscope_cb_start - ****************************************************************************/ - -static int foc_nxscope_cb_start(FAR void *priv, bool start) -{ - pthread_mutex_lock(&g_start_allowed_lock); - g_start_allowed = start; - pthread_mutex_unlock(&g_start_allowed_lock); - return OK; -} -#endif - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -259,78 +291,64 @@ int main(int argc, char *argv[]) struct foc_ctrl_env_s foc[CONFIG_MOTOR_FOC_INST]; pthread_t threads[CONFIG_MOTOR_FOC_INST]; mqd_t mqd[CONFIG_MOTOR_FOC_INST]; + struct args_s args; struct foc_intf_data_s data; - uint32_t thrs_active = 0; int ret = OK; int i = 0; int time = 0; - bool startallowed = false; -#ifdef CONFIG_EXAMPLES_FOC_NXSCOPE - struct foc_nxscope_s nxs; -#endif /* Reset some data */ + memset(&args, 0, sizeof(struct args_s)); memset(mqd, 0, sizeof(mqd_t) * CONFIG_MOTOR_FOC_INST); memset(foc, 0, sizeof(struct foc_ctrl_env_s) * CONFIG_MOTOR_FOC_INST); memset(threads, 0, sizeof(pthread_t) * CONFIG_MOTOR_FOC_INST); memset(&data, 0, sizeof(struct foc_intf_data_s)); -#ifdef CONFIG_EXAMPLES_FOC_NXSCOPE - memset(&nxs, 0, sizeof(struct foc_nxscope_s)); -#endif + + /* Initialize args before parse */ + + args.en = -1; #ifdef CONFIG_BUILTIN /* Parse the command line */ - parse_args(&g_args, argc, argv); + parse_args(&args, argc, argv); #endif + /* Initialize args */ + + init_args(&args); + /* Validate arguments */ - ret = validate_args(&g_args); + ret = validate_args(&args); if (ret < 0) { PRINTF("ERROR: validate args failed\n"); - goto errout_no_nxscope; + goto errout_no_mutex; } -#ifdef CONFIG_BOARDCTL_FINALINIT +#ifndef CONFIG_NSH_ARCHINIT + /* Perform architecture-specific initialization (if configured) */ + + boardctl(BOARDIOC_INIT, 0); + +# ifdef CONFIG_BOARDCTL_FINALINIT /* Perform architecture-specific final-initialization (if configured) */ boardctl(BOARDIOC_FINALINIT, 0); +# endif #endif PRINTF("\nStart foc_main application!\n\n"); -#ifdef CONFIG_EXAMPLES_FOC_NXSCOPE - -# ifdef CONFIG_EXAMPLES_FOC_NXSCOPE_START - /* Wait for nxscope */ - - g_start_allowed = false; - - /* Connect start callback */ - - nxs.cb.start = foc_nxscope_cb_start; -# endif - - /* Initialize nxscope */ - - ret = foc_nxscope_init(&nxs); - if (ret < 0) - { - PRINTF("ERROR: failed to initialize nxscope %d\n", ret); - goto errout_no_threads; - } -#endif - /* Initialize threads */ ret = foc_threads_init(); if (ret < 0) { PRINTF("ERROR: failed to initialize threads %d\n", ret); - goto errout_no_intf; + goto errout_no_mutex; } /* Initialize control interface */ @@ -348,12 +366,26 @@ int main(int argc, char *argv[]) { /* Get configuration */ - foc[i].cfg = &g_args.cfg; -#ifdef CONFIG_EXAMPLES_FOC_NXSCOPE - foc[i].nxs = &nxs; +#ifdef CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP + foc[i].qparam = args.qparam; +#endif + foc[i].fmode = args.fmode; + foc[i].mmode = args.mmode; +#ifdef CONFIG_EXAMPLES_FOC_CONTROL_PI + foc[i].foc_pi_kp = args.foc_pi_kp; + foc[i].foc_pi_ki = args.foc_pi_ki; +#endif +#ifdef CONFIG_EXAMPLES_FOC_HAVE_TORQ + foc[i].torqmax = args.torqmax; +#endif +#ifdef CONFIG_EXAMPLES_FOC_HAVE_VEL + foc[i].velmax = args.velmax; +#endif +#ifdef CONFIG_EXAMPLES_FOC_HAVE_POS + foc[i].posmax = args.posmax; #endif - if (g_args.en & (1 << i)) + if (args.en & (1 << i)) { /* Initialize controller thread if enabled */ @@ -384,7 +416,7 @@ int main(int argc, char *argv[]) /* Controller state */ - data.state = g_args.state; + data.state = args.state; /* Auxliary control loop */ @@ -392,14 +424,6 @@ int main(int argc, char *argv[]) { PRINTFV("foc_main loop %d\n", time); -#ifdef CONFIG_EXAMPLES_FOC_NXSCOPE_MAIN - foc_nxscope_work(&nxs); -#endif - - /* Get active control threads */ - - thrs_active = foc_threads_get(); - /* Update control interface */ ret = foc_intf_update(&data); @@ -415,7 +439,7 @@ int main(int argc, char *argv[]) { for (i = 0; i < CONFIG_MOTOR_FOC_INST; i += 1) { - if ((g_args.en & (1 << i)) && (thrs_active & (1 << i))) + if (args.en & (1 << i)) { PRINTFV("Send vbus to %d\n", i); @@ -441,7 +465,7 @@ int main(int argc, char *argv[]) { for (i = 0; i < CONFIG_MOTOR_FOC_INST; i += 1) { - if ((g_args.en & (1 << i)) && (thrs_active & (1 << i))) + if (args.en & (1 << i)) { PRINTFV("Send state %" PRIu32 " to %d\n", data.state, i); @@ -467,7 +491,7 @@ int main(int argc, char *argv[]) { for (i = 0; i < CONFIG_MOTOR_FOC_INST; i += 1) { - if ((g_args.en & (1 << i)) && (thrs_active & (1 << i))) + if (args.en & (1 << i)) { PRINTFV("Send setpoint = %" PRIu32 "to %d\n", data.sp_raw, i); @@ -492,44 +516,35 @@ int main(int argc, char *argv[]) if (data.started == false) { - /* Is start allowed now ? */ - - pthread_mutex_lock(&g_start_allowed_lock); - startallowed = g_start_allowed; - pthread_mutex_unlock(&g_start_allowed_lock); - - if (startallowed) + for (i = 0; i < CONFIG_MOTOR_FOC_INST; i += 1) { - for (i = 0; i < CONFIG_MOTOR_FOC_INST; i += 1) + if (args.en & (1 << i)) { - if ((g_args.en & (1 << i)) && (thrs_active & (1 << i))) + PRINTFV("Send start to %d\n", i); + + /* Send START to threads */ + + ret = foc_start_send(mqd[i]); + if (ret < 0) { - PRINTFV("Send start to %d\n", i); - - /* Send START to threads */ - - ret = foc_start_send(mqd[i]); - if (ret < 0) - { - PRINTF("ERROR: foc_start_send failed %d\n", ret); - goto errout; - } + PRINTF("ERROR: foc_start_send failed %d\n", ret); + goto errout; } } - - /* Set flag */ - - data.started = true; } + + /* Set flag */ + + data.started = true; } /* Handle run time */ time += 1; - if (g_args.time != -1) + if (args.time != -1) { - if (time >= (g_args.time * (1000000 / MAIN_LOOP_USLEEP))) + if (time >= (args.time * (1000000 / MAIN_LOOP_USLEEP))) { /* Exit loop */ @@ -549,25 +564,11 @@ int main(int argc, char *argv[]) errout: - /* De-initialize control interface */ - - ret = foc_intf_deinit(); - if (ret < 0) - { - PRINTF("ERROR: foc_inf_deinit failed %d\n", ret); - } - -errout_no_intf: - /* Stop FOC control threads */ for (i = 0; i < CONFIG_MOTOR_FOC_INST; i += 1) { - /* Only for active threads */ - - thrs_active = foc_threads_get(); - - if ((g_args.en & (1 << i)) && (thrs_active & (1 << i))) + if (args.en & (1 << i)) { if (mqd[i] != (mqd_t)-1) { @@ -593,7 +594,7 @@ errout_no_intf: for (i = 0; i < CONFIG_MOTOR_FOC_INST; i += 1) { - if (g_args.en & (1 << i)) + if (args.en & (1 << i)) { /* Close FOC control thread queue */ @@ -604,19 +605,20 @@ errout_no_intf: } } - /* De-initialize control threads */ + /* De-initialize control interface */ + + ret = foc_intf_deinit(); + if (ret < 0) + { + PRINTF("ERROR: foc_inf_deinit failed %d\n", ret); + goto errout; + } + +errout_no_mutex: foc_threads_deinit(); -#ifdef CONFIG_EXAMPLES_FOC_NXSCOPE -errout_no_threads: - - /* De-initialize NxScope */ - - foc_nxscope_deinit(&nxs); -#endif - -errout_no_nxscope: PRINTF("foc_main exit\n"); + return 0; } diff --git a/examples/foc/foc_motor_b16.c b/examples/foc/foc_motor_b16.c index a9530e18c..a734001e6 100644 --- a/examples/foc/foc_motor_b16.c +++ b/examples/foc/foc_motor_b16.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/foc/foc_motor_b16.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -27,28 +25,18 @@ #include <nuttx/config.h> #include <assert.h> -#include <string.h> -#include <dspb16.h> + +#include "foc_motor_b16.h" #include "foc_cfg.h" #include "foc_debug.h" -#include "foc_motor_b16.h" -#ifdef CONFIG_EXAMPLES_FOC_FEEDFORWARD -# include "industry/foc/float/foc_feedforward.h" -#endif /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ -#define FOC_FLOAT_IDENT_RES_MIN ftob16(1e-6) -#define FOC_FLOAT_IDENT_RES_MAX ftob16(2.0f) - -#define FOC_FLOAT_IDENT_IND_MIN ftob16(1e-9) -#define FOC_FLOAT_IDENT_IND_MAX ftob16(2.0f) - /**************************************************************************** - * Private Types + * Private Type Definition ****************************************************************************/ /**************************************************************************** @@ -123,96 +111,9 @@ static int foc_motor_align(FAR struct foc_motor_b16_s *motor, FAR bool *done) goto errout; } - PRINTFV("Aling results:\n"); -#ifdef CONFIG_INDUSTRY_FOC_ALIGN_DIR - PRINTFV(" dir = %.2f\n", b16tof(final.dir)); -#endif - PRINTFV(" offset = %.2f\n", b16tof(final.offset)); - - *done = true; - } - - /* Copy output */ - - motor->dq_ref.d = out.dq_ref.d; - motor->dq_ref.q = out.dq_ref.q; - motor->vdq_comp.d = out.vdq_comp.d; - motor->vdq_comp.q = out.vdq_comp.q; - motor->angle_now = out.angle; - motor->foc_mode = out.foc_mode; - -errout: - return ret; -} -#endif - -#ifdef CONFIG_EXAMPLES_FOC_HAVE_IDENT -/**************************************************************************** - * Name: foc_motor_ident - ****************************************************************************/ - -static int foc_motor_ident(FAR struct foc_motor_b16_s *motor, FAR bool *done) -{ - struct foc_routine_in_b16_s in; - struct foc_routine_out_b16_s out; - struct foc_routine_ident_final_b16_s final; - int ret = OK; - - /* Get input */ - - in.foc_state = &motor->foc_state; - in.angle = motor->angle_now; -#ifdef CONFIG_EXAMPLES_FOC_HAVE_VEL - in.vel = motor->vel.now; -#endif - in.vbus = motor->vbus; - - /* Run ident procedure */ - - ret = foc_routine_run_b16(&motor->ident, &in, &out); - if (ret < 0) - { - PRINTFV("ERROR: foc_routine_run_b16 failed %d!\n", ret); - goto errout; - } - - if (ret == FOC_ROUTINE_RUN_DONE) - { - ret = foc_routine_final_b16(&motor->ident, &final); - if (ret < 0) - { - PRINTFV("ERROR: foc_routine_final_b16 failed %d!\n", ret); - goto errout; - } - - PRINTF("Ident results:\n"); - PRINTF(" res = %.4f\n", b16tof(final.res)); - PRINTF(" ind = %.8f\n", b16tof(final.ind)); - - if (final.res < FOC_FLOAT_IDENT_RES_MIN || - final.res > FOC_FLOAT_IDENT_RES_MAX) - { - PRINTF("ERROR: Motor resistance out of valid range res=%.4f!\n", - b16tof(final.res)); - - ret = -EINVAL; - goto errout; - } - - if (final.ind < FOC_FLOAT_IDENT_IND_MIN || - final.ind > FOC_FLOAT_IDENT_IND_MAX) - { - PRINTF("ERROR: Motor inductance out of valid range ind=%.8f!\n", - b16tof(final.ind)); - - ret = -EINVAL; - goto errout; - } - - /* Store results */ - - motor->phy_ident.res = final.res; - motor->phy_ident.ind = final.ind; + PRINTF("Aling results:\n"); + PRINTF(" dir = %.2f\n", b16tof(final.dir)); + PRINTF(" offset = %.2f\n", b16tof(final.offset)); *done = true; } @@ -240,7 +141,7 @@ static int foc_runmode_init(FAR struct foc_motor_b16_s *motor) { int ret = OK; - switch (motor->envp->cfg->fmode) + switch (motor->envp->fmode) { case FOC_FMODE_IDLE: { @@ -262,7 +163,7 @@ static int foc_runmode_init(FAR struct foc_motor_b16_s *motor) default: { - PRINTF("ERROR: unsupported op mode %d\n", motor->envp->cfg->fmode); + PRINTF("ERROR: unsupported op mode %d\n", motor->envp->fmode); ret = -EINVAL; goto errout; } @@ -272,7 +173,7 @@ static int foc_runmode_init(FAR struct foc_motor_b16_s *motor) #ifdef CONFIG_EXAMPLES_FOC_SENSORLESS # ifdef CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP - motor->openloop_now = FOC_OPENLOOP_ENABLED; + motor->openloop_now = true; # else # error # endif @@ -294,7 +195,7 @@ static int foc_motor_configure(FAR struct foc_motor_b16_s *motor) #ifdef CONFIG_EXAMPLES_FOC_CONTROL_PI struct foc_initdata_b16_s ctrl_cfg; #endif -#ifdef CONFIG_EXAMPLES_FOC_MODULATION_SVM3 +#ifdef CONFIG_INDUSTRY_FOC_MODULATION_SVM3 struct foc_mod_cfg_b16_s mod_cfg; #endif #ifdef CONFIG_EXAMPLES_FOC_STATE_USE_MODEL_PMSM @@ -310,8 +211,8 @@ static int foc_motor_configure(FAR struct foc_motor_b16_s *motor) ret = foc_ramp_init_b16(&motor->ramp, motor->per, ftob16(RAMP_CFG_THR), - ftob16((motor->envp->cfg->acc / 1.0f)), - ftob16((motor->envp->cfg->dec / 1.0f))); + ftob16(RAMP_CFG_ACC), + ftob16(RAMP_CFG_ACC)); if (ret < 0) { PRINTF("ERROR: foc_ramp_init failed %d\n", ret); @@ -329,7 +230,7 @@ static int foc_motor_configure(FAR struct foc_motor_b16_s *motor) /* Get FOC modulation */ -#ifdef CONFIG_EXAMPLES_FOC_MODULATION_SVM3 +#ifdef CONFIG_INDUSTRY_FOC_MODULATION_SVM3 foc_mod = &g_foc_mod_svm3_b16; #else # error FOC modulation not selected @@ -354,13 +255,13 @@ static int foc_motor_configure(FAR struct foc_motor_b16_s *motor) #ifdef CONFIG_EXAMPLES_FOC_CONTROL_PI /* Get PI controller configuration */ - ctrl_cfg.id_kp = ftob16(motor->envp->cfg->foc_pi_kp / 1000.0f); - ctrl_cfg.id_ki = ftob16(motor->envp->cfg->foc_pi_ki / 1000.0f); - ctrl_cfg.iq_kp = ftob16(motor->envp->cfg->foc_pi_kp / 1000.0f); - ctrl_cfg.iq_ki = ftob16(motor->envp->cfg->foc_pi_ki / 1000.0f); + ctrl_cfg.id_kp = ftob16(motor->envp->foc_pi_kp / 1000.0f); + ctrl_cfg.id_ki = ftob16(motor->envp->foc_pi_ki / 1000.0f); + ctrl_cfg.iq_kp = ftob16(motor->envp->foc_pi_kp / 1000.0f); + ctrl_cfg.iq_ki = ftob16(motor->envp->foc_pi_ki / 1000.0f); #endif -#ifdef CONFIG_EXAMPLES_FOC_MODULATION_SVM3 +#ifdef CONFIG_INDUSTRY_FOC_MODULATION_SVM3 /* Get SVM3 modulation configuration */ mod_cfg.pwm_duty_max = motor->pwm_duty_max; @@ -370,13 +271,11 @@ static int foc_motor_configure(FAR struct foc_motor_b16_s *motor) foc_handler_cfg_b16(&motor->handler, &ctrl_cfg, &mod_cfg); - /* Configure motor phy */ +#ifdef CONFIG_EXAMPLES_FOC_MOTOR_POLES + /* Configure motor poles */ - motor_phy_params_init_b16(&motor->phy, - CONFIG_EXAMPLES_FOC_MOTOR_POLES, - ftob16(CONFIG_EXAMPLES_FOC_MOTOR_RES / 1000000.0f), - ftob16(CONFIG_EXAMPLES_FOC_MOTOR_IND / 1000000.0f), - ftob16(CONFIG_EXAMPLES_FOC_MOTOR_FLUXLINK / 1000000.0f)); + motor->poles = CONFIG_EXAMPLES_FOC_MOTOR_POLES; +#endif #ifdef CONFIG_EXAMPLES_FOC_STATE_USE_MODEL_PMSM /* Initialize PMSM model */ @@ -441,10 +340,10 @@ static int foc_motor_torq(FAR struct foc_motor_b16_s *motor, uint32_t torq) * NOTE: torqmax may not fit in b16_t so we can't use b16idiv() */ - tmp1 = itob16(motor->envp->cfg->torqmax / 1000); - tmp2 = b16mulb16(ftob16(SETPOINT_INTF_SCALE), tmp1); + tmp1 = itob16(motor->envp->torqmax / 1000); + tmp2 = b16mulb16(ftob16(SETPOINT_ADC_SCALE), tmp1); - motor->torq.des = b16mulb16(motor->dir, b16muli(tmp2, torq)); + motor->torq.des = b16muli(tmp2, torq); return OK; } @@ -466,10 +365,10 @@ static int foc_motor_vel(FAR struct foc_motor_b16_s *motor, uint32_t vel) * NOTE: velmax may not fit in b16_t so we can't use b16idiv() */ - tmp1 = itob16(motor->envp->cfg->velmax / 1000); - tmp2 = b16mulb16(ftob16(SETPOINT_INTF_SCALE), tmp1); + tmp1 = itob16(motor->envp->velmax / 1000); + tmp2 = b16mulb16(ftob16(SETPOINT_ADC_SCALE), tmp1); - motor->vel.des = b16mulb16(motor->dir, b16muli(tmp2, vel)); + motor->vel.des = b16muli(tmp2, vel); return OK; } @@ -491,10 +390,10 @@ static int foc_motor_pos(FAR struct foc_motor_b16_s *motor, uint32_t pos) * NOTE: posmax may not fit in b16_t so we can't use b16idiv() */ - tmp1 = itob16(motor->envp->cfg->posmax / 1000); - tmp2 = b16mulb16(ftob16(SETPOINT_INTF_SCALE), tmp1); + tmp1 = itob16(motor->envp->posmax / 1000); + tmp2 = b16mulb16(ftob16(SETPOINT_ADC_SCALE), tmp1); - motor->pos.des = b16mulb16(motor->dir, b16muli(tmp2, pos)); + motor->pos.des = b16muli(tmp2, pos); return OK; } @@ -508,7 +407,7 @@ static int foc_motor_setpoint(FAR struct foc_motor_b16_s *motor, uint32_t sp) { int ret = OK; - switch (motor->envp->cfg->mmode) + switch (motor->envp->mmode) { #ifdef CONFIG_EXAMPLES_FOC_HAVE_TORQ case FOC_MMODE_TORQ: @@ -558,22 +457,9 @@ static int foc_motor_setpoint(FAR struct foc_motor_b16_s *motor, uint32_t sp) } #endif -#ifdef CONFIG_EXAMPLES_FOC_HAVE_ALIGN - case FOC_MMODE_ALIGN_ONLY: -#endif -#ifdef CONFIG_EXAMPLES_FOC_HAVE_IDENT - case FOC_MMODE_IDENT_ONLY: -#endif - { - /* Do nothing */ - - break; - } - default: { - PRINTF("ERROR: unsupported ctrl mode %d\n", - motor->envp->cfg->mmode); + PRINTF("ERROR: unsupported ctrl mode %d\n", motor->envp->mmode); ret = -EINVAL; goto errout; } @@ -583,43 +469,6 @@ errout: return ret; } -#if defined(CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP) || \ - defined(CONFIG_EXAMPLES_FOC_VELOBS) -/**************************************************************************** - * Name: foc_motor_vel_reset - ****************************************************************************/ - -static int foc_motor_vel_reset(FAR struct foc_motor_b16_s *motor) -{ - int ret = OK; - - /* Reset velocity observer */ - -#ifdef CONFIG_EXAMPLES_FOC_VELOBS_DIV - ret = foc_velocity_zero_b16(&motor->vel_div); - if (ret < 0) - { - PRINTF("ERROR: foc_velocity_zero failed %d\n", ret); - goto errout; - } -#endif - -#ifdef CONFIG_EXAMPLES_FOC_VELOBS_PLL - ret = foc_velocity_zero_b16(&motor->vel_pll); - if (ret < 0) - { - PRINTF("ERROR: foc_velocity_zero failed %d\n", ret); - goto errout; - } -#endif - -#ifdef CONFIG_EXAMPLES_FOC_VELOBS - errout: -#endif - return ret; -} -#endif - /**************************************************************************** * Name: foc_motor_state ****************************************************************************/ @@ -630,7 +479,7 @@ static int foc_motor_state(FAR struct foc_motor_b16_s *motor, int state) DEBUGASSERT(motor); - /* Update motor state - this function is called every controller cycle */ + /* Update motor state */ switch (state) { @@ -648,26 +497,10 @@ static int foc_motor_state(FAR struct foc_motor_b16_s *motor, int state) case FOC_EXAMPLE_STATE_STOP: { -#ifdef CONFIG_EXAMPLES_FOC_SENSORLESS - /* For sensorless we can just set Q reference to lock the motor */ - motor->dir = DIR_NONE_B16; /* DQ vector not zero - active brake */ - motor->dq_ref.q = ftob16(CONFIG_EXAMPLES_FOC_STOP_CURRENT / - 1000.0f); - motor->dq_ref.d = 0; -#else - /* For sensored mode we set requested velocity to 0 */ - -# ifdef CONFIG_EXAMPLES_FOC_HAVE_VEL - motor->vel.des = 0; -# else -# error STOP state for sensored mode requires velocity support -# endif -#endif - break; } @@ -692,27 +525,6 @@ static int foc_motor_state(FAR struct foc_motor_b16_s *motor, int state) } } -#ifdef CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP - /* Re-align motor if we change mode from FREE/STOP to CW/CCW otherwise, - * the open-loop may fail because the rotor position at the start is - * random. - */ - - if ((motor->mq.app_state == FOC_EXAMPLE_STATE_FREE || - motor->mq.app_state == FOC_EXAMPLE_STATE_STOP) && - (state == FOC_EXAMPLE_STATE_CW || - state == FOC_EXAMPLE_STATE_CCW)) - { - motor->ctrl_state = FOC_CTRL_STATE_ALIGN; - motor->align_done = false; - motor->angle_now = 0; - - /* Reset velocity observer */ - - foc_motor_vel_reset(motor); - } -#endif - /* Reset current setpoint */ #ifdef CONFIG_EXAMPLES_FOC_HAVE_TORQ @@ -780,129 +592,30 @@ errout: static int foc_motor_run_init(FAR struct foc_motor_b16_s *motor) { - int ret = OK; + /* Empty for now */ -#ifdef CONFIG_EXAMPLES_FOC_VELOBS - ret = foc_motor_vel_reset(motor); -#endif - - return ret; + return OK; } -#ifdef CONFIG_EXAMPLES_FOC_ANGOBS -/**************************************************************************** - * Name: foc_motor_openloop_trans - ****************************************************************************/ - -static void foc_motor_openloop_trans(FAR struct foc_motor_b16_s *motor) -{ -#ifdef CONFIG_EXAMPLES_FOC_VELCTRL_PI - /* Set the intergral part of the velocity PI controller equal to the - * open-loop Q current value. - * - * REVISIT: this may casue a velocity overshoot when going from open-loop - * to closed-loop. We can either use part of the open-loop Q - * current here or gradually reduce the Q current during - * transition. - */ - - motor->vel_pi.part[1] = b16mulb16(motor->dir, motor->openloop_q); - motor->vel_pi.part[0] = 0; -#endif -} - -/**************************************************************************** - * Name: foc_motor_openloop_angobs - ****************************************************************************/ - -static void foc_motor_openloop_angobs(FAR struct foc_motor_b16_s *motor) -{ - b16_t vel_abs = 0; - - vel_abs = b16abs(motor->vel_el); - - /* Disable open-loop if velocity above threshold */ - - if (motor->openloop_now == FOC_OPENLOOP_ENABLED) - { - if (vel_abs >= motor->ol_thr) - { - /* Store angle error between the forced open-loop angle and - * observer output. The error will be gradually eliminated over - * the next controller cycles. - */ - -#ifdef ANGLE_MERGE_FACTOR - motor->angle_step = b16mulb16(motor->angle_err, - ftob16(ANGLE_MERGE_FACTOR)); - motor->angle_err = motor->angle_ol - motor->angle_obs; -#endif - - motor->openloop_now = FOC_OPENLOOP_TRANSITION; - } - } - - /* Handle transition end */ - - else if (motor->openloop_now == FOC_OPENLOOP_TRANSITION) - { - if (motor->angle_err == 0) - { - /* Call open-open loop transition handler */ - - foc_motor_openloop_trans(motor); - - motor->openloop_now = FOC_OPENLOOP_DISABLED; - } - } - - /* Enable open-loop if velocity below threshold with hysteresis */ - - else if (motor->openloop_now == FOC_OPENLOOP_DISABLED) - { - /* For better stability we add hysteresis from transition - * from closed-loop to open-loop. - */ - - if (vel_abs < (motor->ol_thr - motor->ol_hys)) - { - motor->openloop_now = FOC_OPENLOOP_ENABLED; - } - } -} -#endif - /**************************************************************************** * Name: foc_motor_run ****************************************************************************/ static int foc_motor_run(FAR struct foc_motor_b16_s *motor) { -#ifdef CONFIG_EXAMPLES_FOC_HAVE_VEL - b16_t vel_err = 0.0f; -#endif b16_t q_ref = 0; b16_t d_ref = 0; int ret = OK; DEBUGASSERT(motor); -#ifdef CONFIG_EXAMPLES_FOC_ANGOBS - if (motor->envp->cfg->ol_force == false) - { - /* Handle open-loop to observer transition */ - - foc_motor_openloop_angobs(motor); - } -#endif - #ifdef CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP /* Open-loop works only in velocity control mode */ if (motor->openloop_now == true) { # ifdef CONFIG_EXAMPLES_FOC_HAVE_VEL - if (motor->envp->cfg->mmode != FOC_MMODE_VEL) + if (motor->envp->mmode != FOC_MMODE_VEL) #endif { PRINTF("ERROR: open-loop only with FOC_MMODE_VEL\n"); @@ -917,94 +630,34 @@ static int foc_motor_run(FAR struct foc_motor_b16_s *motor) q_ref = motor->dq_ref.q; d_ref = motor->dq_ref.d; - /* Ignore controller if motor is free (sensorless and sensored mode) - * or stopped (only sensorless mode) - */ + /* Controller */ - if (motor->mq.app_state == FOC_EXAMPLE_STATE_FREE -#ifdef CONFIG_EXAMPLES_FOC_SENSORLESS - || motor->mq.app_state == FOC_EXAMPLE_STATE_STOP -#endif - ) + switch (motor->envp->mmode) { - goto no_controller; - } - - /* Controller. - * - * The FOC motor controller is a cascade controller: - * - * 1. Position controller sets requested velocity, - * 2. Velocity controller sets requested torque, - * 3. Torque controller sets requested motor phase voltages. - * - * NOTE: the motor torque is directly proportional to the motor - * current which is proportional to the motor set voltage - */ - - switch (motor->envp->cfg->mmode) - { -#ifdef CONFIG_EXAMPLES_FOC_HAVE_VEL - case FOC_MMODE_VEL: - { - /* Saturate velocity */ - - f_saturate_b16(&motor->vel.des, -motor->vel_sat, - motor->vel_sat); - - /* Velocity controller */ - - if (motor->time % VEL_CONTROL_PRESCALER == 0) - { - /* Run velocity ramp controller */ - - ret = foc_ramp_run_b16(&motor->ramp, - motor->vel.des, - motor->vel.now, - &motor->vel.set); - if (ret < 0) - { - PRINTF("ERROR: foc_ramp_run failed %d\n", ret); - goto errout; - } - - /* Run velocity controller if no in open-loop */ - -#ifdef CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP - if (motor->openloop_now == false) -#endif - { - /* Get velocity error */ - - vel_err = motor->vel.set - motor->vel.now; - -#ifdef CONFIG_EXAMPLES_FOC_VELCTRL_PI - /* PI velocit controller */ - - motor->torq.des = pi_controller_b16(&motor->vel_pi, - vel_err); -#else -# error Missing velocity controller -#endif - } - } - - /* Don't break here! pass to torque controller */ - } -#endif - #ifdef CONFIG_EXAMPLES_FOC_HAVE_TORQ case FOC_MMODE_TORQ: { - /* Saturate torque */ + motor->torq.set = b16mulb16(motor->dir, motor->torq.des); - f_saturate_b16(&motor->torq.des, -motor->torq_sat, - motor->torq_sat); + q_ref = motor->torq.set; + d_ref = 0; - /* Torque setpoint */ + break; + } +#endif - motor->torq.set = motor->torq.des; - motor->torq.now = motor->foc_state.idq.q; +#ifdef CONFIG_EXAMPLES_FOC_HAVE_VEL + case FOC_MMODE_VEL: + { + /* Run velocity ramp controller */ + + ret = foc_ramp_run_b16(&motor->ramp, motor->vel.des, + motor->vel.now, &motor->vel.set); + if (ret < 0) + { + PRINTF("ERROR: foc_ramp_run failed %d\n", ret); + goto errout; + } break; } @@ -1017,28 +670,20 @@ static int foc_motor_run(FAR struct foc_motor_b16_s *motor) } } - /* Get dq ref */ - - q_ref = motor->torq.set; - d_ref = 0; - #ifdef CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP /* Force open-loop current */ - if (motor->openloop_now == FOC_OPENLOOP_ENABLED || - motor->openloop_now == FOC_OPENLOOP_TRANSITION) + if (motor->openloop_now == true) { - /* Get open-loop currents. Positive for CW direction, negative for - * CCW direction. Id always set to 0. + /* Get open-loop currents + * NOTE: Id always set to 0 */ - q_ref = b16mulb16(motor->dir, motor->openloop_q); - d_ref = 0; + motor->dq_ref.q = b16idiv(motor->envp->qparam, 1000); + motor->dq_ref.d = 0; } #endif -no_controller: - /* Set DQ reference frame */ motor->dq_ref.q = q_ref; @@ -1046,267 +691,14 @@ no_controller: /* DQ compensation */ -#ifdef CONFIG_EXAMPLES_FOC_FEEDFORWARD - foc_feedforward_pmsm_b16(&motor->phy, &motor->foc_state.idq, - motor->vel.now, &motor->vdq_comp); -#else motor->vdq_comp.q = 0; motor->vdq_comp.d = 0; -#endif errout: return ret; } #endif -/**************************************************************************** - * Name: foc_motor_ang_get - ****************************************************************************/ - -static int foc_motor_ang_get(FAR struct foc_motor_b16_s *motor) -{ - struct foc_angle_in_b16_s ain; - struct foc_angle_out_b16_s aout; - int ret = OK; - - DEBUGASSERT(motor); - - /* Update open-loop angle handler */ - -#ifdef CONFIG_EXAMPLES_FOC_HAVE_VEL - ain.vel = motor->vel.set; -#endif - ain.state = &motor->foc_state; - ain.angle = motor->angle_now; - ain.dir = motor->dir; - -#ifdef CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP - if (motor->openloop_now != FOC_OPENLOOP_DISABLED) - { - foc_angle_run_b16(&motor->openloop, &ain, &aout); - - /* Store open-loop angle */ - - motor->angle_ol = aout.angle; - } -#endif - -#ifdef CONFIG_EXAMPLES_FOC_HAVE_QENCO - ret = foc_angle_run_b16(&motor->qenco, &ain, &aout); - if (ret < 0) - { - PRINTF("ERROR: foc_angle_run failed %d\n", ret); - goto errout; - } -#endif - -#ifdef CONFIG_EXAMPLES_FOC_HAVE_HALL - ret = foc_angle_run_b16(&motor->hall, &ain, &aout); - if (ret < 0) - { - PRINTF("ERROR: foc_angle_run failed %d\n", ret); - goto errout; - } -#endif - -#ifdef CONFIG_EXAMPLES_FOC_ANGOBS_SMO - ret = foc_angle_run_b16(&motor->ang_smo, &ain, &aout); - if (ret < 0) - { - PRINTF("ERROR: foc_angle_run failed %d\n", ret); - goto errout; - } - - motor->angle_obs = aout.angle; -#endif - -#ifdef CONFIG_EXAMPLES_FOC_ANGOBS_NFO - ret = foc_angle_run_b16(&motor->ang_nfo, &ain, &aout); - if (ret < 0) - { - PRINTF("ERROR: foc_angle_run failed %d\n", ret); - goto errout; - } - - motor->angle_obs = aout.angle; -#endif - -#ifndef CONFIG_EXAMPLES_FOC_HAVE_RUN - /* Dummy value when motor controller disabled */ - - UNUSED(ain); - aout.type = FOC_ANGLE_TYPE_ELE; - aout.angle = 0; -#endif - - /* Store electrical angle from sensor or observer */ - - if (aout.type == FOC_ANGLE_TYPE_ELE) - { - /* Store electrical angle */ - - motor->angle_el = aout.angle; - } - - else if (aout.type == FOC_ANGLE_TYPE_MECH) - { - /* Store mechanical angle */ - - motor->angle_m = aout.angle; - - /* Convert mechanical angle to electrical angle */ - - motor->angle_el = (b16muli(motor->angle_m, - motor->phy.p) % - MOTOR_ANGLE_E_MAX_B16); - } - - else - { - ASSERT(0); - } - -#ifdef CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP - /* Get open-loop phase angle */ - - if (motor->openloop_now == FOC_OPENLOOP_ENABLED) - { - motor->angle_now = motor->angle_ol; - motor->angle_el = motor->angle_ol; - } - else -#endif -#ifdef CONFIG_EXAMPLES_FOC_SENSORLESS - /* Handle smooth open-loop to closed-loop transition */ - - if (motor->openloop_now == FOC_OPENLOOP_TRANSITION) - { -#ifdef ANGLE_MERGE_FACTOR - if (b16abs(motor->angle_err) > b16abs(motor->angle_step)) - { - motor->angle_now = motor->angle_obs + motor->angle_err; - - /* Update error */ - - motor->angle_err -= motor->angle_step; - } - else -#endif - { - motor->angle_now = motor->angle_obs; - motor->angle_err = 0; - } - } - - /* Get angle from observer if closed-loop now */ - - else - { - motor->angle_now = motor->angle_obs; - } -#endif - -#ifdef CONFIG_EXAMPLES_FOC_SENSORED - /* Get phase angle from sensor */ - - motor->angle_now = motor->angle_el; -#endif - -#if defined(CONFIG_EXAMPLES_FOC_SENSORED) || defined(CONFIG_EXAMPLES_FOC_ANGOBS) - errout: -#endif - return ret; -} - -#ifdef CONFIG_EXAMPLES_FOC_HAVE_VEL -/**************************************************************************** - * Name: foc_motor_vel_get - ****************************************************************************/ - -static int foc_motor_vel_get(FAR struct foc_motor_b16_s *motor) -{ - struct foc_velocity_in_b16_s vin; - struct foc_velocity_out_b16_s vout; - int ret = OK; - - DEBUGASSERT(motor); - - /* Update velocity handler input data */ - - vin.state = &motor->foc_state; - vin.angle = motor->angle_now; - vin.vel = motor->vel.now; - vin.dir = motor->dir; - - /* Get velocity from observer */ - -#ifdef CONFIG_EXAMPLES_FOC_VELOBS_DIV - ret = foc_velocity_run_b16(&motor->vel_div, &vin, &vout); - if (ret < 0) - { - PRINTF("ERROR: foc_velocity_run failed %d\n", ret); - goto errout; - } -#endif - -#ifdef CONFIG_EXAMPLES_FOC_VELOBS_PLL - ret = foc_velocity_run_b16(&motor->vel_pll, &vin, &vout); - if (ret < 0) - { - PRINTF("ERROR: foc_velocity_run failed %d\n", ret); - goto errout; - } -#endif - - /* Get motor electrical velocity now */ - -#if defined(CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP) && \ - !defined(CONFIG_EXAMPLES_FOC_VELOBS) || \ - !defined(CONFIG_EXAMPLES_FOC_HAVE_RUN) - /* No velocity feedback - assume that electical velocity is velocity set - * in a open-loop contorller. - */ - - UNUSED(vin); - UNUSED(vout); - - motor->vel_el = motor->vel.set; -#elif defined(CONFIG_EXAMPLES_FOC_VELOBS) && defined(CONFIG_EXAMPLES_FOC_SENSORLESS) - if (motor->openloop_now == FOC_OPENLOOP_DISABLED) - { - /* Get electrical velocity from observer if we are in closed-loop */ - - motor->vel_el = motor->vel_obs; - } - else - { - /* Otherwise use open-loop velocity */ - - motor->vel_el = motor->vel.set; - } -#elif defined(CONFIG_EXAMPLES_FOC_VELOBS) && defined(CONFIG_EXAMPLES_FOC_SENSORED) - /* Get electrical velocity from observer in sensored mode */ - - motor->vel_el = motor->vel_obs; -#else - /* Need electrical velocity source here - raise assertion */ - - ASSERT(0); -#endif - - LP_FILTER_B16(motor->vel.now, motor->vel_el, motor->vel_filter); - - /* Get mechanical velocity (rad/s) */ - - motor->vel_mech = b16mulb16(motor->vel_el, motor->phy.one_by_p); - -#ifdef CONFIG_EXAMPLES_FOC_VELOBS -errout: -#endif - return ret; -} -#endif /* CONFIG_EXAMPLES_FOC_HAVE_VEL */ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -1327,23 +719,8 @@ int foc_motor_init(FAR struct foc_motor_b16_s *motor, #ifdef CONFIG_EXAMPLES_FOC_HAVE_HALL struct foc_hall_cfg_b16_s hl_cfg; #endif -#ifdef CONFIG_EXAMPLES_FOC_ANGOBS_SMO - struct foc_angle_osmo_cfg_b16_s smo_cfg; -#endif -#ifdef CONFIG_EXAMPLES_FOC_ANGOBS_NFO - struct foc_angle_onfo_cfg_b16_s nfo_cfg; -#endif -#ifdef CONFIG_EXAMPLES_FOC_VELOBS_DIV - struct foc_vel_div_b16_cfg_s odiv_cfg; -#endif -#ifdef CONFIG_EXAMPLES_FOC_VELOBS_PLL - struct foc_vel_pll_b16_cfg_s opll_cfg; -#endif #ifdef CONFIG_EXAMPLES_FOC_HAVE_ALIGN struct foc_routine_align_cfg_b16_s align_cfg; -#endif -#ifdef CONFIG_EXAMPLES_FOC_HAVE_IDENT - struct foc_routine_ident_cfg_b16_s ident_cfg; #endif int ret = OK; @@ -1361,16 +738,7 @@ int foc_motor_init(FAR struct foc_motor_b16_s *motor, /* Initialize motor data */ motor->per = b16divi(b16ONE, CONFIG_EXAMPLES_FOC_NOTIFIER_FREQ); -#ifdef CONFIG_EXAMPLES_FOC_ANGOBS - motor->ol_thr = ftob16(motor->envp->cfg->ol_thr / 1.0f); - motor->ol_hys = ftob16(motor->envp->cfg->ol_hys / 1.0f); -#endif -#ifdef CONFIG_EXAMPLES_FOC_HAVE_TORQ - motor->torq_sat = ftob16(CONFIG_EXAMPLES_FOC_TORQ_MAX / 1000.0f); -#endif -#ifdef CONFIG_EXAMPLES_FOC_HAVE_VEL - motor->vel_sat = ftob16(CONFIG_EXAMPLES_FOC_VEL_MAX / 1.0f); -#endif + motor->iphase_adc = ftob16((CONFIG_EXAMPLES_FOC_IPHASE_ADC) / 100000.0f); #ifdef CONFIG_EXAMPLES_FOC_HAVE_RUN /* Initialize controller run mode */ @@ -1397,10 +765,6 @@ int foc_motor_init(FAR struct foc_motor_b16_s *motor, ol_cfg.per = motor->per; foc_angle_cfg_b16(&motor->openloop, &ol_cfg); - - /* Store open-loop Q-param */ - - motor->openloop_q = ftob16(motor->envp->cfg->qparam / 1000.0f); #endif #ifdef CONFIG_EXAMPLES_FOC_HAVE_QENCO @@ -1416,10 +780,10 @@ int foc_motor_init(FAR struct foc_motor_b16_s *motor, /* Get qenco devpath */ - snprintf(motor->qedpath, sizeof(motor->qedpath), - "%s%d", - CONFIG_EXAMPLES_FOC_QENCO_DEVPATH, - motor->envp->id); + sprintf(motor->qedpath, + "%s%d", + CONFIG_EXAMPLES_FOC_QENCO_DEVPATH, + motor->envp->id); /* Configure qenco angle handler */ @@ -1447,10 +811,10 @@ int foc_motor_init(FAR struct foc_motor_b16_s *motor, /* Get hall devpath */ - snprintf(motor->hldpath, sizeof(motor->hldpath), - "%s%d", - CONFIG_EXAMPLES_FOC_HALL_DEVPATH, - motor->envp->id); + sprintf(motor->hldpath, + "%s%d", + CONFIG_EXAMPLES_FOC_HALL_DEVPATH, + motor->envp->id); /* Configure hall angle handler */ @@ -1465,120 +829,6 @@ int foc_motor_init(FAR struct foc_motor_b16_s *motor, } #endif -#ifdef CONFIG_EXAMPLES_FOC_ANGOBS_SMO - /* Initialzie SMO angle observer handler */ - - ret = foc_angle_init_b16(&motor->ang_smo, - &g_foc_angle_osmo_b16); - if (ret < 0) - { - PRINTFV("ERROR: foc_angle_init_b16 failed %d!\n", ret); - goto errout; - } - - /* Configure SMO angle handler */ - - smo_cfg.per = motor->per; - smo_cfg.k_slide = ftob16(CONFIG_EXAMPLES_FOC_ANGOBS_SMO_KSLIDE / 1000.0f); - smo_cfg.err_max = ftob16(CONFIG_EXAMPLES_FOC_ANGOBS_SMO_ERRMAX / 1000.0f); - memcpy(&smo_cfg.phy, &motor->phy, sizeof(struct motor_phy_params_b16_s)); - - ret = foc_angle_cfg_b16(&motor->ang_smo, &smo_cfg); - if (ret < 0) - { - PRINTFV("ERROR: foc_angle_cfg_b16 failed %d!\n", ret); - goto errout; - } -#endif - -#ifdef CONFIG_EXAMPLES_FOC_ANGOBS_NFO - /* Initialzie NFO angle observer handler */ - - ret = foc_angle_init_b16(&motor->ang_nfo, - &g_foc_angle_onfo_b16); - if (ret < 0) - { - PRINTFV("ERROR: foc_angle_init_b16 failed %d!\n", ret); - goto errout; - } - - /* Configure NFO angle handler */ - - nfo_cfg.per = motor->per; - nfo_cfg.gain = ftob16(motor->envp->cfg->ang_nfo_gain / 1.0f); - nfo_cfg.gain_slow = ftob16(motor->envp->cfg->ang_nfo_slow / 1.0f); - memcpy(&nfo_cfg.phy, &motor->phy, sizeof(struct motor_phy_params_b16_s)); - - ret = foc_angle_cfg_b16(&motor->ang_nfo, &nfo_cfg); - if (ret < 0) - { - PRINTFV("ERROR: foc_angle_cfg_b16 failed %d!\n", ret); - goto errout; - } -#endif - -#ifdef CONFIG_EXAMPLES_FOC_VELOBS_DIV - /* Initialize velocity observer */ - - ret = foc_velocity_init_b16(&motor->vel_div, - &g_foc_velocity_odiv_b16); - if (ret < 0) - { - PRINTFV("ERROR: foc_angle_init_b16 failed %d!\n", ret); - goto errout; - } - - /* Configure velocity observer */ - - odiv_cfg.samples = (motor->envp->cfg->vel_div_samples); - odiv_cfg.filter = ftob16(motor->envp->cfg->vel_div_samples / 1000.0f); - odiv_cfg.per = motor->per; - - ret = foc_velocity_cfg_b16(&motor->vel_div, &odiv_cfg); - if (ret < 0) - { - PRINTFV("ERROR: foc_velocity_cfg_b16 failed %d!\n", ret); - goto errout; - } -#endif - -#ifdef CONFIG_EXAMPLES_FOC_VELOBS_PLL - /* Initialize velocity observer */ - - ret = foc_velocity_init_b16(&motor->vel_pll, - &g_foc_velocity_opll_b16); - if (ret < 0) - { - PRINTFV("ERROR: foc_angle_init_b16 failed %d!\n", ret); - goto errout; - } - - /* Configure velocity observer */ - - opll_cfg.kp = ftob16(motor->envp->cfg->vel_pll_kp / 1.0f); - opll_cfg.ki = ftob16(motor->envp->cfg->vel_pll_ki / 1.0f); - opll_cfg.per = motor->per; - - ret = foc_velocity_cfg_b16(&motor->vel_pll, &opll_cfg); - if (ret < 0) - { - PRINTFV("ERROR: foc_velocity_cfg_b16 failed %d!\n", ret); - goto errout; - } -#endif - -#ifdef CONFIG_EXAMPLES_FOC_VELCTRL_PI - /* Initialize velocity controller */ - - pi_controller_init_b16(&motor->vel_pi, - ftob16(motor->envp->cfg->vel_pi_kp / 1000000.0f), - ftob16(motor->envp->cfg->vel_pi_ki / 1000000.0f)); - - pi_saturation_set_b16(&motor->vel_pi, -motor->torq_sat, motor->torq_sat); - - pi_antiwindup_enable_b16(&motor->vel_pi, ftob16(0.99f), true); -#endif - #ifdef CONFIG_EXAMPLES_FOC_HAVE_ALIGN /* Initialize motor alignment routine */ @@ -1592,7 +842,7 @@ int foc_motor_init(FAR struct foc_motor_b16_s *motor, /* Initialize motor alignment data */ align_cfg.volt = ftob16(CONFIG_EXAMPLES_FOC_ALIGN_VOLT / 1000.0f); - align_cfg.offset_steps = (CONFIG_EXAMPLES_FOC_NOTIFIER_FREQ * \ + align_cfg.offset_steps = (CONFIG_EXAMPLES_FOC_NOTIFIER_FREQ * \ CONFIG_EXAMPLES_FOC_ALIGN_SEC / 1000); /* Connect align callbacks */ @@ -1602,9 +852,6 @@ int foc_motor_init(FAR struct foc_motor_b16_s *motor, /* Connect align callbacks private data */ -# ifdef CONFIG_EXAMPLES_FOC_SENSORLESS - align_cfg.cb.priv = &motor->openloop; -# endif # ifdef CONFIG_EXAMPLES_FOC_HAVE_QENCO align_cfg.cb.priv = &motor->qenco; # endif @@ -1615,93 +862,16 @@ int foc_motor_init(FAR struct foc_motor_b16_s *motor, ret = foc_routine_cfg_b16(&motor->align, &align_cfg); if (ret < 0) { -# ifndef CONFIG_EXAMPLES_FOC_RUN_DISABLE PRINTFV("ERROR: foc_routine_cfg_b16 failed %d!\n", ret); goto errout; -# else - /* When motor controller is disabled, most likely we don't care about - * align routine failure - */ - - PRINTFV("ignore align routine failure\n", ret); - ret = OK; -# endif } #endif -#ifdef CONFIG_EXAMPLES_FOC_HAVE_IDENT - - /* Initialize motor identifiaction routine */ - - ret = foc_routine_init_b16(&motor->ident, &g_foc_routine_ident_b16); - if (ret < 0) - { - PRINTFV("ERROR: foc_routine_init_b16 failed %d!\n", ret); - goto errout; - } - - /* Initialize motor identification data */ - - ident_cfg.per = motor->per; - ident_cfg.res_current = ftob16(motor->envp->cfg->ident_res_curr / - 1000.0f); - ident_cfg.res_ki = ftob16(motor->envp->cfg->ident_res_ki / - 1000.0f); - ident_cfg.ind_volt = ftob16(motor->envp->cfg->ident_ind_volt / - 1000.0f); - ident_cfg.res_steps = (CONFIG_EXAMPLES_FOC_NOTIFIER_FREQ * - motor->envp->cfg->ident_res_sec / 1000); - ident_cfg.ind_steps = (CONFIG_EXAMPLES_FOC_NOTIFIER_FREQ * - motor->envp->cfg->ident_ind_sec / 1000); - ident_cfg.idle_steps = CONFIG_EXAMPLES_FOC_IDENT_IDLE; - - ret = foc_routine_cfg_b16(&motor->ident, &ident_cfg); - if (ret < 0) - { -# ifndef CONFIG_EXAMPLES_FOC_RUN_DISABLE - PRINTFV("ERROR: foc_ident_cfg_b16 failed %d!\n", ret); - goto errout; -# else - /* When motor controller is disabled, most likely we don't care about - * ident routine failure - */ - - PRINTFV("ident align routine failure\n", ret); - ret = OK; -# endif - } -#endif - -#ifdef CONFIG_EXAMPLES_FOC_HAVE_VEL - /* Store velocity filter value */ - - motor->vel_filter = ftob16(motor->envp->cfg->vel_filter / 1000.0f); -#endif - /* Initialize controller state */ -#ifdef CONFIG_EXAMPLES_FOC_HAVE_ALIGN - if (motor->envp->cfg->mmode == FOC_MMODE_ALIGN_ONLY) - { - motor->ctrl_state = FOC_CTRL_STATE_ALIGN; - } - else -#endif -#ifdef CONFIG_EXAMPLES_FOC_HAVE_IDENT - if (motor->envp->cfg->mmode == FOC_MMODE_IDENT_ONLY) - { - motor->ctrl_state = FOC_CTRL_STATE_IDENT; - } - else -#endif - { - motor->ctrl_state = FOC_CTRL_STATE_INIT; - } + motor->ctrl_state = FOC_CTRL_STATE_INIT; -#if defined(CONFIG_EXAMPLES_FOC_SENSORED) || \ - defined(CONFIG_EXAMPLES_FOC_HAVE_RUN) || \ - defined(CONFIG_EXAMPLES_FOC_HAVE_ALIGN) || \ - defined(CONFIG_EXAMPLES_FOC_HAVE_IDENT) +#if defined(CONFIG_EXAMPLES_FOC_SENSORED) || defined(CONFIG_EXAMPLES_FOC_HAVE_RUN) errout: #endif return ret; @@ -1717,105 +887,6 @@ int foc_motor_deinit(FAR struct foc_motor_b16_s *motor) DEBUGASSERT(motor); - #ifdef CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP - /* Deinitialzie open-loop handler */ - - ret = foc_angle_deinit_b16(&motor->openloop); - if (ret < 0) - { - PRINTFV("ERROR: foc_angle_deinit_b16 failed %d!\n", ret); - goto errout; - } -#endif - -#ifdef CONFIG_EXAMPLES_FOC_HAVE_QENCO - /* Deinitialzie qenco handler */ - - ret = foc_angle_deinit_b16(&motor->qenco); - if (ret < 0) - { - PRINTFV("ERROR: foc_angle_deinit_b16 failed %d!\n", ret); - goto errout; - } -#endif - -#ifdef CONFIG_EXAMPLES_FOC_HAVE_HALL - /* Deinitialzie hall handler */ - - ret = foc_angle_deinit_b16(&motor->hall); - if (ret < 0) - { - PRINTFV("ERROR: foc_angle_deinit_b16 failed %d!\n", ret); - goto errout; - } -#endif - -#ifdef CONFIG_EXAMPLES_FOC_ANGOBS_SMO - /* Deinitialize SMO observer handler */ - - ret = foc_angle_deinit_b16(&motor->ang_smo); - if (ret < 0) - { - PRINTFV("ERROR: foc_angle_deinit_b16 failed %d!\n", ret); - goto errout; - } -#endif - -#ifdef CONFIG_EXAMPLES_FOC_ANGOBS_NFO - /* Deinitialize NFO observer handler */ - - ret = foc_angle_deinit_b16(&motor->ang_nfo); - if (ret < 0) - { - PRINTFV("ERROR: foc_angle_deinit_b16 failed %d!\n", ret); - goto errout; - } -#endif - -#ifdef CONFIG_EXAMPLES_FOC_VELOBS_DIV - /* Deinitialize DIV observer handler */ - - ret = foc_velocity_deinit_b16(&motor->vel_div); - if (ret < 0) - { - PRINTFV("ERROR: foc_velocity_deinit_b16 failed %d!\n", ret); - goto errout; - } -#endif - -#ifdef CONFIG_EXAMPLES_FOC_VELOBS_PLL - /* Deinitialize PLL observer handler */ - - ret = foc_velocity_deinit_b16(&motor->vel_pll); - if (ret < 0) - { - PRINTFV("ERROR: foc_velocity_deinit_b16 failed %d!\n", ret); - goto errout; - } -#endif - -#ifdef CONFIG_EXAMPLES_FOC_HAVE_ALIGN - /* Deinitialize motor alignment routine */ - - ret = foc_routine_deinit_b16(&motor->align); - if (ret < 0) - { - PRINTFV("ERROR: foc_routine_deinit_b16 failed %d!\n", ret); - goto errout; - } -#endif - -#ifdef CONFIG_EXAMPLES_FOC_HAVE_IDENT - /* Deinitialize motor identification routine */ - - ret = foc_routine_deinit_b16(&motor->ident); - if (ret < 0) - { - PRINTFV("ERROR: foc_routine_deinit_b16 failed %d!\n", ret); - goto errout; - } -#endif - #ifdef CONFIG_EXAMPLES_FOC_STATE_USE_MODEL_PMSM /* Deinitialize PMSM model */ @@ -1850,29 +921,105 @@ errout: int foc_motor_get(FAR struct foc_motor_b16_s *motor) { - int ret = OK; + struct foc_angle_in_b16_s ain; + struct foc_angle_out_b16_s aout; + int ret = OK; DEBUGASSERT(motor); - /* Get motor angle */ - - ret = foc_motor_ang_get(motor); - if (ret < 0) - { - goto errout; - } + /* Update open-loop angle handler */ #ifdef CONFIG_EXAMPLES_FOC_HAVE_VEL - /* Get motor velocity */ + ain.vel = motor->vel.set; +#endif + ain.angle = motor->angle_now; + ain.dir = motor->dir; - ret = foc_motor_vel_get(motor); +#ifdef CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP + foc_angle_run_b16(&motor->openloop, &ain, &aout); + + /* Store open-loop angle */ + + motor->angle_ol = aout.angle; +#endif + +#ifdef CONFIG_EXAMPLES_FOC_HAVE_QENCO + ret = foc_angle_run_b16(&motor->qenco, &ain, &aout); if (ret < 0) { + PRINTF("ERROR: foc_angle_run failed %d\n", ret); goto errout; } #endif +#ifdef CONFIG_EXAMPLES_FOC_HAVE_HALL + ret = foc_angle_run_b16(&motor->hall, &ain, &aout); + if (ret < 0) + { + PRINTF("ERROR: foc_angle_run failed %d\n", ret); + goto errout; + } +#endif + +#ifdef CONFIG_EXAMPLES_FOC_SENSORED + /* Handle angle from sensor */ + + if (aout.type == FOC_ANGLE_TYPE_ELE) + { + /* Store electrical angle */ + + motor->angle_el = aout.angle; + } + + else if (aout.type == FOC_ANGLE_TYPE_MECH) + { + /* Store mechanical angle */ + + motor->angle_m = aout.angle; + + /* Convert mechanical angle to electrical angle */ + + motor->angle_el = (b16muli(motor->angle_m, + motor->poles) % MOTOR_ANGLE_E_MAX_B16); + } + + else + { + ASSERT(0); + } +#endif /* CONFIG_EXAMPLES_FOC_SENSORED */ + +#ifdef CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP + /* Get phase angle now */ + + if (motor->openloop_now == true) + { + motor->angle_now = motor->angle_ol; + } + else +#endif + { + /* Get phase angle from observer or sensor */ + + motor->angle_now = motor->angle_el; + } + +#ifdef CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP + if (motor->openloop_now == true) + { + /* No velocity feedback - assume that velocity now is velocity set */ + + motor->vel.now = motor->vel.set; + } + else +#endif + { + /* TODO: velocity observer or sensor */ + } + +#ifdef CONFIG_EXAMPLES_FOC_SENSORED errout: +#endif return ret; } @@ -1883,6 +1030,9 @@ errout: int foc_motor_control(FAR struct foc_motor_b16_s *motor) { int ret = OK; +#ifdef CONFIG_EXAMPLES_FOC_HAVE_ALIGN + bool align_done = false; +#endif DEBUGASSERT(motor); @@ -1905,53 +1055,19 @@ int foc_motor_control(FAR struct foc_motor_b16_s *motor) { /* Run motor align procedure */ - ret = foc_motor_align(motor, &motor->align_done); + ret = foc_motor_align(motor, &align_done); if (ret < 0) { PRINTF("ERROR: foc_motor_align failed %d!\n", ret); goto errout; } - if (motor->align_done == true) + if (align_done == true) { /* Next state */ motor->ctrl_state += 1; motor->foc_mode = FOC_HANDLER_MODE_IDLE; - - if (motor->envp->cfg->mmode == FOC_MMODE_ALIGN_ONLY) - { - motor->ctrl_state = FOC_CTRL_STATE_TERMINATE; - } - } - - break; - } -#endif - -#ifdef CONFIG_EXAMPLES_FOC_HAVE_IDENT - case FOC_CTRL_STATE_IDENT: - { - /* Run motor identification procedure */ - - ret = foc_motor_ident(motor, &motor->ident_done); - if (ret < 0) - { - PRINTF("ERROR: foc_motor_ident failed %d!\n", ret); - goto errout; - } - - if (motor->ident_done == true) - { - /* Next state */ - - motor->ctrl_state += 1; - motor->foc_mode = FOC_HANDLER_MODE_IDLE; - - if (motor->envp->cfg->mmode == FOC_MMODE_IDENT_ONLY) - { - motor->ctrl_state = FOC_CTRL_STATE_TERMINATE; - } } break; @@ -2004,13 +1120,6 @@ int foc_motor_control(FAR struct foc_motor_b16_s *motor) break; } - case FOC_CTRL_STATE_TERMINATE: - { - /* Do nothing */ - - break; - } - default: { PRINTF("ERROR: invalid ctrl_state=%d\n", motor->ctrl_state); diff --git a/examples/foc/foc_motor_b16.h b/examples/foc/foc_motor_b16.h index 834d92111..f368e2382 100644 --- a/examples/foc/foc_motor_b16.h +++ b/examples/foc/foc_motor_b16.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/foc/foc_motor_b16.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -40,9 +38,6 @@ #ifdef CONFIG_EXAMPLES_FOC_HAVE_ALIGN # include "industry/foc/fixed16/foc_align.h" #endif -#ifdef CONFIG_EXAMPLES_FOC_HAVE_IDENT -# include "industry/foc/fixed16/foc_ident.h" -#endif #ifdef CONFIG_EXAMPLES_FOC_STATE_USE_MODEL_PMSM # include "industry/foc/fixed16/foc_model.h" #endif @@ -68,133 +63,57 @@ struct foc_setpoint_b16_s struct foc_motor_b16_s { - /* App data ***************************************************************/ - FAR struct foc_ctrl_env_s *envp; /* Thread env */ - struct foc_mq_s mq; /* MQ data */ bool fault; /* Fault flag */ bool startstop; /* Start/stop request */ - int ctrl_state; /* Controller state */ +#ifdef CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP + bool openloop_now; /* Open-loop now */ + b16_t angle_ol; /* Phase angle open-loop */ + foc_angle_b16_t openloop; /* Open-loop angle handler */ +#endif +#ifdef CONFIG_EXAMPLES_FOC_HAVE_HALL + char hldpath[32]; /* Hall devpath */ + foc_angle_b16_t hall; /* Hall angle handler */ +#endif +#ifdef CONFIG_EXAMPLES_FOC_HAVE_QENCO + char qedpath[32]; /* Qenco devpath */ + foc_angle_b16_t qenco; /* Qenco angle handler */ +#endif + int foc_mode; /* FOC mode */ #ifdef CONFIG_EXAMPLES_FOC_HAVE_RUN int foc_mode_run; /* FOC mode for run state */ #endif - - /* FOC data ***************************************************************/ - - struct foc_state_b16_s foc_state; /* FOC controller sate */ -#ifdef CONFIG_EXAMPLES_FOC_MODULATION_SVM3 - struct svm3_state_b16_s mod_state; /* Modulation state */ -#endif - foc_handler_b16_t handler; /* FOC controller */ - dq_frame_b16_t dq_ref; /* DQ reference */ - dq_frame_b16_t vdq_comp; /* DQ voltage compensation */ - int foc_mode; /* FOC mode */ - int time; /* Helper counter */ + int ctrl_state; /* Controller state */ b16_t vbus; /* Power bus voltage */ - b16_t per; /* Controller period in seconds */ -#ifdef CONFIG_EXAMPLES_FOC_ANGOBS - b16_t ol_thr; /* Angle observer threshold velocity */ - b16_t ol_hys; /* Angle observer hysteresis */ - b16_t angle_step; /* Open-loop transition step */ -#endif - - /* Data from FOC device ***************************************************/ - - b16_t iphase_adc; /* Iphase ADC scaling factor */ - b16_t pwm_duty_max; /* PWM duty max */ - - /* Velocity controller data ***********************************************/ - - struct foc_ramp_b16_s ramp; /* Velocity ramp data */ -#ifdef CONFIG_EXAMPLES_FOC_VELCTRL_PI - pid_controller_b16_t vel_pi; /* Velocity controller */ -#endif - - /* Angle state ************************************************************/ - b16_t angle_now; /* Phase angle now */ b16_t angle_m; /* Motor mechanical angle */ b16_t angle_el; /* Motor electrical angle */ -#ifdef CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP - b16_t angle_ol; /* Phase angle open-loop */ -#endif -#ifdef CONFIG_EXAMPLES_FOC_ANGOBS - b16_t angle_obs; /* Angle observer output */ - b16_t angle_err; /* Open-loop to observer error */ -#endif - - /* Velocity state *********************************************************/ - -#ifdef CONFIG_EXAMPLES_FOC_HAVE_VEL - b16_t vel_el; /* Velocity - electrical */ - b16_t vel_mech; /* Velocity - mechanical */ - b16_t vel_filter; /* Velocity low-pass filter */ -#endif -#ifdef CONFIG_EXAMPLES_FOC_VELOBS - b16_t vel_obs; /* Velocity observer output */ -#endif - - /* Motor setpoints ********************************************************/ - #ifdef CONFIG_EXAMPLES_FOC_HAVE_TORQ struct foc_setpoint_b16_s torq; /* Torque setpoint */ - b16_t torq_sat; /* Torque saturation */ #endif #ifdef CONFIG_EXAMPLES_FOC_HAVE_VEL struct foc_setpoint_b16_s vel; /* Velocity setpoint */ - b16_t vel_sat; /* Velocity saturation */ #endif #ifdef CONFIG_EXAMPLES_FOC_HAVE_POS struct foc_setpoint_b16_s pos; /* Position setpoint */ #endif b16_t dir; /* Motor's direction */ - - /* Motor routines *********************************************************/ - + b16_t per; /* Controller period in seconds */ + b16_t iphase_adc; /* Iphase ADC scaling factor */ + b16_t pwm_duty_max; /* PWM duty max */ + uint8_t poles; /* Motor poles */ + dq_frame_b16_t dq_ref; /* DQ reference */ + dq_frame_b16_t vdq_comp; /* DQ voltage compensation */ + foc_handler_b16_t handler; /* FOC controller */ + struct foc_mq_s mq; /* MQ data */ + struct foc_state_b16_s foc_state; /* FOC controller sate */ + struct foc_ramp_b16_s ramp; /* Velocity ramp data */ #ifdef CONFIG_EXAMPLES_FOC_HAVE_ALIGN struct foc_routine_b16_s align; /* Alignment routine */ - bool align_done; /* Alignment done */ #endif -#ifdef CONFIG_EXAMPLES_FOC_HAVE_IDENT - struct foc_routine_b16_s ident; /* Motor ident routine */ - struct motor_phy_params_b16_s phy_ident; /* Motor phy from ident */ - bool ident_done; /* Motor ident done */ -#endif - - /* Motor data *************************************************************/ - #ifdef CONFIG_EXAMPLES_FOC_STATE_USE_MODEL_PMSM - struct foc_model_b16_s model; /* Model handler */ - struct foc_model_state_b16_s model_state; /* PMSM model state */ -#endif - struct motor_phy_params_b16_s phy; /* Motor phy */ - - /* Motor velocity and angle handlers **************************************/ - -#ifdef CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP - foc_angle_b16_t openloop; /* Open-loop angle handler */ - uint8_t openloop_now; /* Open-loop now */ - b16_t openloop_q; /* Open-loop Q parameter */ -#endif -#ifdef CONFIG_EXAMPLES_FOC_HAVE_HALL - foc_angle_b16_t hall; /* Hall angle handler */ - char hldpath[32]; /* Hall devpath */ -#endif -#ifdef CONFIG_EXAMPLES_FOC_HAVE_QENCO - foc_angle_b16_t qenco; /* Qenco angle handler */ - char qedpath[32]; /* Qenco devpath */ -#endif -#ifdef CONFIG_EXAMPLES_FOC_VELOBS_DIV - foc_velocity_b16_t vel_div; /* DIV velocity observer */ -#endif -#ifdef CONFIG_EXAMPLES_FOC_VELOBS_PLL - foc_velocity_b16_t vel_pll; /* PLL velocity observer */ -#endif -#ifdef CONFIG_EXAMPLES_FOC_ANGOBS_SMO - foc_angle_b16_t ang_smo; /* SMO angle observer */ -#endif -#ifdef CONFIG_EXAMPLES_FOC_ANGOBS_NFO - foc_angle_b16_t ang_nfo; /* NFO angle observer */ + struct foc_model_b16_s model; /* Model handler */ + struct foc_model_state_b16_s model_state; /* PMSM model state */ #endif }; diff --git a/examples/foc/foc_motor_f32.c b/examples/foc/foc_motor_f32.c index 1aee970f9..a7adf5363 100644 --- a/examples/foc/foc_motor_f32.c +++ b/examples/foc/foc_motor_f32.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/foc/foc_motor_f32.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -27,28 +25,18 @@ #include <nuttx/config.h> #include <assert.h> -#include <string.h> -#include <dsp.h> + +#include "foc_motor_f32.h" #include "foc_cfg.h" #include "foc_debug.h" -#include "foc_motor_f32.h" -#ifdef CONFIG_EXAMPLES_FOC_FEEDFORWARD -# include "industry/foc/float/foc_feedforward.h" -#endif /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ -#define FOC_FLOAT_IDENT_RES_MIN (1e-6) -#define FOC_FLOAT_IDENT_RES_MAX (2.0f) - -#define FOC_FLOAT_IDENT_IND_MIN (1e-9) -#define FOC_FLOAT_IDENT_IND_MAX (2.0f) - /**************************************************************************** - * Private Types + * Private Type Definition ****************************************************************************/ /**************************************************************************** @@ -123,96 +111,9 @@ static int foc_motor_align(FAR struct foc_motor_f32_s *motor, FAR bool *done) goto errout; } - PRINTFV("Aling results:\n"); -#ifdef CONFIG_INDUSTRY_FOC_ALIGN_DIR - PRINTFV(" dir = %.2f\n", final.dir); -#endif - PRINTFV(" offset = %.2f\n", final.offset); - - *done = true; - } - - /* Copy output */ - - motor->dq_ref.d = out.dq_ref.d; - motor->dq_ref.q = out.dq_ref.q; - motor->vdq_comp.d = out.vdq_comp.d; - motor->vdq_comp.q = out.vdq_comp.q; - motor->angle_now = out.angle; - motor->foc_mode = out.foc_mode; - -errout: - return ret; -} -#endif - -#ifdef CONFIG_EXAMPLES_FOC_HAVE_IDENT -/**************************************************************************** - * Name: foc_motor_ident - ****************************************************************************/ - -static int foc_motor_ident(FAR struct foc_motor_f32_s *motor, FAR bool *done) -{ - struct foc_routine_in_f32_s in; - struct foc_routine_out_f32_s out; - struct foc_routine_ident_final_f32_s final; - int ret = OK; - - /* Get input */ - - in.foc_state = &motor->foc_state; - in.angle = motor->angle_now; -#ifdef CONFIG_EXAMPLES_FOC_HAVE_VEL - in.vel = motor->vel.now; -#endif - in.vbus = motor->vbus; - - /* Run ident procedure */ - - ret = foc_routine_run_f32(&motor->ident, &in, &out); - if (ret < 0) - { - PRINTFV("ERROR: foc_routine_run_f32 failed %d!\n", ret); - goto errout; - } - - if (ret == FOC_ROUTINE_RUN_DONE) - { - ret = foc_routine_final_f32(&motor->ident, &final); - if (ret < 0) - { - PRINTFV("ERROR: foc_routine_final_f32 failed %d!\n", ret); - goto errout; - } - - PRINTF("Ident results:\n"); - PRINTF(" res = %.4f\n", final.res); - PRINTF(" ind = %.8f\n", final.ind); - - if (final.res < FOC_FLOAT_IDENT_RES_MIN || - final.res > FOC_FLOAT_IDENT_RES_MAX) - { - PRINTF("ERROR: Motor resistance out of valid range res=%.4f!\n", - final.res); - - ret = -EINVAL; - goto errout; - } - - if (final.ind < FOC_FLOAT_IDENT_IND_MIN || - final.ind > FOC_FLOAT_IDENT_IND_MAX) - { - PRINTF("ERROR: Motor inductance out of valid range ind=%.8f!\n", - final.ind); - - ret = -EINVAL; - goto errout; - } - - /* Store results */ - - motor->phy_ident.res = final.res; - motor->phy_ident.ind = final.ind; + PRINTF("Aling results:\n"); + PRINTF(" dir = %.2f\n", final.dir); + PRINTF(" offset = %.2f\n", final.offset); *done = true; } @@ -240,7 +141,7 @@ static int foc_runmode_init(FAR struct foc_motor_f32_s *motor) { int ret = OK; - switch (motor->envp->cfg->fmode) + switch (motor->envp->fmode) { case FOC_FMODE_IDLE: { @@ -262,7 +163,7 @@ static int foc_runmode_init(FAR struct foc_motor_f32_s *motor) default: { - PRINTF("ERROR: unsupported op mode %d\n", motor->envp->cfg->fmode); + PRINTF("ERROR: unsupported op mode %d\n", motor->envp->fmode); ret = -EINVAL; goto errout; } @@ -272,7 +173,7 @@ static int foc_runmode_init(FAR struct foc_motor_f32_s *motor) #ifdef CONFIG_EXAMPLES_FOC_SENSORLESS # ifdef CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP - motor->openloop_now = FOC_OPENLOOP_ENABLED; + motor->openloop_now = true; # else # error # endif @@ -294,7 +195,7 @@ static int foc_motor_configure(FAR struct foc_motor_f32_s *motor) #ifdef CONFIG_EXAMPLES_FOC_CONTROL_PI struct foc_initdata_f32_s ctrl_cfg; #endif -#ifdef CONFIG_EXAMPLES_FOC_MODULATION_SVM3 +#ifdef CONFIG_INDUSTRY_FOC_MODULATION_SVM3 struct foc_mod_cfg_f32_s mod_cfg; #endif #ifdef CONFIG_EXAMPLES_FOC_STATE_USE_MODEL_PMSM @@ -310,8 +211,8 @@ static int foc_motor_configure(FAR struct foc_motor_f32_s *motor) ret = foc_ramp_init_f32(&motor->ramp, motor->per, RAMP_CFG_THR, - (motor->envp->cfg->acc / 1.0f), - (motor->envp->cfg->dec / 1.0f)); + RAMP_CFG_ACC, + RAMP_CFG_ACC); if (ret < 0) { PRINTF("ERROR: foc_ramp_init failed %d\n", ret); @@ -329,7 +230,7 @@ static int foc_motor_configure(FAR struct foc_motor_f32_s *motor) /* Get FOC modulation */ -#ifdef CONFIG_EXAMPLES_FOC_MODULATION_SVM3 +#ifdef CONFIG_INDUSTRY_FOC_MODULATION_SVM3 foc_mod = &g_foc_mod_svm3_f32; #else # error FOC modulation not selected @@ -352,13 +253,13 @@ static int foc_motor_configure(FAR struct foc_motor_f32_s *motor) #ifdef CONFIG_EXAMPLES_FOC_CONTROL_PI /* Get PI controller configuration */ - ctrl_cfg.id_kp = (motor->envp->cfg->foc_pi_kp / 1000.0f); - ctrl_cfg.id_ki = (motor->envp->cfg->foc_pi_ki / 1000.0f); - ctrl_cfg.iq_kp = (motor->envp->cfg->foc_pi_kp / 1000.0f); - ctrl_cfg.iq_ki = (motor->envp->cfg->foc_pi_ki / 1000.0f); + ctrl_cfg.id_kp = (motor->envp->foc_pi_kp / 1000.0f); + ctrl_cfg.id_ki = (motor->envp->foc_pi_ki / 1000.0f); + ctrl_cfg.iq_kp = (motor->envp->foc_pi_kp / 1000.0f); + ctrl_cfg.iq_ki = (motor->envp->foc_pi_ki / 1000.0f); #endif -#ifdef CONFIG_EXAMPLES_FOC_MODULATION_SVM3 +#ifdef CONFIG_INDUSTRY_FOC_MODULATION_SVM3 /* Get SVM3 modulation configuration */ mod_cfg.pwm_duty_max = motor->pwm_duty_max; @@ -368,13 +269,11 @@ static int foc_motor_configure(FAR struct foc_motor_f32_s *motor) foc_handler_cfg_f32(&motor->handler, &ctrl_cfg, &mod_cfg); - /* Configure motor phy */ +#ifdef CONFIG_EXAMPLES_FOC_MOTOR_POLES + /* Configure motor poles */ - motor_phy_params_init(&motor->phy, - CONFIG_EXAMPLES_FOC_MOTOR_POLES, - CONFIG_EXAMPLES_FOC_MOTOR_RES / 1000000.0f, - CONFIG_EXAMPLES_FOC_MOTOR_IND / 1000000.0f, - CONFIG_EXAMPLES_FOC_MOTOR_FLUXLINK / 1000000.0f); + motor->poles = CONFIG_EXAMPLES_FOC_MOTOR_POLES; +#endif #ifdef CONFIG_EXAMPLES_FOC_STATE_USE_MODEL_PMSM /* Initialize PMSM model */ @@ -434,8 +333,8 @@ static int foc_motor_torq(FAR struct foc_motor_f32_s *motor, uint32_t torq) /* Update motor torque destination */ - motor->torq.des = (motor->dir * torq * SETPOINT_INTF_SCALE * - motor->envp->cfg->torqmax / 1000.0f); + motor->torq.des = (torq * SETPOINT_ADC_SCALE * + motor->envp->torqmax / 1000.0f); return OK; } @@ -452,8 +351,8 @@ static int foc_motor_vel(FAR struct foc_motor_f32_s *motor, uint32_t vel) /* Update motor velocity destination */ - motor->vel.des = (motor->dir * vel * SETPOINT_INTF_SCALE * - motor->envp->cfg->velmax / 1000.0f); + motor->vel.des = (vel * SETPOINT_ADC_SCALE * + motor->envp->velmax / 1000.0f); return OK; } @@ -470,8 +369,8 @@ static int foc_motor_pos(FAR struct foc_motor_f32_s *motor, uint32_t pos) /* Update motor position destination */ - motor->pos.des = (motor->dir * pos * SETPOINT_INTF_SCALE * - motor->envp->cfg->posmax / 1000.0f); + motor->pos.des = (pos * SETPOINT_ADC_SCALE * + motor->envp->posmax / 1000.0f); return OK; } @@ -485,7 +384,7 @@ static int foc_motor_setpoint(FAR struct foc_motor_f32_s *motor, uint32_t sp) { int ret = OK; - switch (motor->envp->cfg->mmode) + switch (motor->envp->mmode) { #ifdef CONFIG_EXAMPLES_FOC_HAVE_TORQ case FOC_MMODE_TORQ: @@ -535,23 +434,9 @@ static int foc_motor_setpoint(FAR struct foc_motor_f32_s *motor, uint32_t sp) } #endif -#ifdef CONFIG_EXAMPLES_FOC_HAVE_ALIGN - case FOC_MMODE_ALIGN_ONLY: -#endif -#ifdef CONFIG_EXAMPLES_FOC_HAVE_IDENT - case FOC_MMODE_IDENT_ONLY: -#endif - case FOC_MMODE_IDLE: - { - /* Do nothing */ - - break; - } - default: { - PRINTF("ERROR: unsupported ctrl mode %d\n", - motor->envp->cfg->mmode); + PRINTF("ERROR: unsupported ctrl mode %d\n", motor->envp->mmode); ret = -EINVAL; goto errout; } @@ -561,43 +446,6 @@ errout: return ret; } -#if defined(CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP) || \ - defined(CONFIG_EXAMPLES_FOC_VELOBS) -/**************************************************************************** - * Name: foc_motor_vel_reset - ****************************************************************************/ - -static int foc_motor_vel_reset(FAR struct foc_motor_f32_s *motor) -{ - int ret = OK; - - /* Reset velocity observer */ - -#ifdef CONFIG_EXAMPLES_FOC_VELOBS_DIV - ret = foc_velocity_zero_f32(&motor->vel_div); - if (ret < 0) - { - PRINTF("ERROR: foc_velocity_zero failed %d\n", ret); - goto errout; - } -#endif - -#ifdef CONFIG_EXAMPLES_FOC_VELOBS_PLL - ret = foc_velocity_zero_f32(&motor->vel_pll); - if (ret < 0) - { - PRINTF("ERROR: foc_velocity_zero failed %d\n", ret); - goto errout; - } -#endif - -#ifdef CONFIG_EXAMPLES_FOC_VELOBS - errout: -#endif - return ret; -} -#endif - /**************************************************************************** * Name: foc_motor_state ****************************************************************************/ @@ -608,7 +456,7 @@ static int foc_motor_state(FAR struct foc_motor_f32_s *motor, int state) DEBUGASSERT(motor); - /* Update motor state - this function is called every controller cycle */ + /* Update motor state */ switch (state) { @@ -626,25 +474,10 @@ static int foc_motor_state(FAR struct foc_motor_f32_s *motor, int state) case FOC_EXAMPLE_STATE_STOP: { -#ifdef CONFIG_EXAMPLES_FOC_SENSORLESS - /* For sensorless we can just set Q reference to lock the motor */ - motor->dir = DIR_NONE; /* DQ vector not zero - active brake */ - motor->dq_ref.q = CONFIG_EXAMPLES_FOC_STOP_CURRENT / 1000.0f; - motor->dq_ref.d = 0.0f; -#else - /* For sensored mode we set requested velocity to 0 */ - -# ifdef CONFIG_EXAMPLES_FOC_HAVE_VEL - motor->vel.des = 0.0f; -# else -# error STOP state for sensored mode requires velocity support -# endif -#endif - break; } @@ -669,27 +502,6 @@ static int foc_motor_state(FAR struct foc_motor_f32_s *motor, int state) } } -#ifdef CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP - /* Re-align motor if we change mode from FREE/STOP to CW/CCW otherwise, - * the open-loop may fail because the rotor position at the start is - * random. - */ - - if ((motor->mq.app_state == FOC_EXAMPLE_STATE_FREE || - motor->mq.app_state == FOC_EXAMPLE_STATE_STOP) && - (state == FOC_EXAMPLE_STATE_CW || - state == FOC_EXAMPLE_STATE_CCW)) - { - motor->ctrl_state = FOC_CTRL_STATE_ALIGN; - motor->align_done = false; - motor->angle_now = 0.0f; - - /* Reset velocity observer */ - - foc_motor_vel_reset(motor); - } -#endif - /* Reset current setpoint */ #ifdef CONFIG_EXAMPLES_FOC_HAVE_TORQ @@ -764,128 +576,30 @@ errout: static int foc_motor_run_init(FAR struct foc_motor_f32_s *motor) { - int ret = OK; + /* Empty for now */ -#ifdef CONFIG_EXAMPLES_FOC_VELOBS - ret = foc_motor_vel_reset(motor); -#endif - - return ret; + return OK; } -#ifdef CONFIG_EXAMPLES_FOC_ANGOBS -/**************************************************************************** - * Name: foc_motor_openloop_trans - ****************************************************************************/ - -static void foc_motor_openloop_trans(FAR struct foc_motor_f32_s *motor) -{ -#ifdef CONFIG_EXAMPLES_FOC_VELCTRL_PI - /* Set the intergral part of the velocity PI controller equal to the - * open-loop Q current value. - * - * REVISIT: this may casue a velocity overshoot when going from open-loop - * to closed-loop. We can either use part of the open-loop Q - * current here or gradually reduce the Q current during - * transition. - */ - - motor->vel_pi.part[1] = motor->dir * motor->openloop_q; - motor->vel_pi.part[0] = 0.0f; -#endif -} - -/**************************************************************************** - * Name: foc_motor_openloop_angobs - ****************************************************************************/ - -static void foc_motor_openloop_angobs(FAR struct foc_motor_f32_s *motor) -{ - float vel_abs = 0.0f; - - vel_abs = fabsf(motor->vel_el); - - /* Disable open-loop if velocity above threshold */ - - if (motor->openloop_now == FOC_OPENLOOP_ENABLED) - { - if (vel_abs >= motor->ol_thr) - { - /* Store angle error between the forced open-loop angle and - * observer output. The error will be gradually eliminated over - * the next controller cycles. - */ - -#ifdef ANGLE_MERGE_FACTOR - motor->angle_err = motor->angle_ol - motor->angle_obs; - motor->angle_step = (motor->angle_err * ANGLE_MERGE_FACTOR); -#endif - - motor->openloop_now = FOC_OPENLOOP_TRANSITION; - } - } - - /* Handle transition end */ - - else if (motor->openloop_now == FOC_OPENLOOP_TRANSITION) - { - if (motor->angle_err == 0.0f) - { - /* Call open-open loop transition handler */ - - foc_motor_openloop_trans(motor); - - motor->openloop_now = FOC_OPENLOOP_DISABLED; - } - } - - /* Enable open-loop if velocity below threshold with hysteresis */ - - else if (motor->openloop_now == FOC_OPENLOOP_DISABLED) - { - /* For better stability we add hysteresis from transition - * from closed-loop to open-loop. - */ - - if (vel_abs < (motor->ol_thr - motor->ol_hys)) - { - motor->openloop_now = FOC_OPENLOOP_ENABLED; - } - } -} -#endif - /**************************************************************************** * Name: foc_motor_run ****************************************************************************/ static int foc_motor_run(FAR struct foc_motor_f32_s *motor) { -#ifdef CONFIG_EXAMPLES_FOC_HAVE_VEL - float vel_err = 0.0f; -#endif float q_ref = 0.0f; float d_ref = 0.0f; int ret = OK; DEBUGASSERT(motor); -#ifdef CONFIG_EXAMPLES_FOC_ANGOBS - if (motor->envp->cfg->ol_force == false) - { - /* Handle open-loop to observer transition */ - - foc_motor_openloop_angobs(motor); - } -#endif - #ifdef CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP /* Open-loop works only in velocity control mode */ - if (motor->openloop_now == FOC_OPENLOOP_ENABLED) + if (motor->openloop_now == true) { # ifdef CONFIG_EXAMPLES_FOC_HAVE_VEL - if (motor->envp->cfg->mmode != FOC_MMODE_VEL) + if (motor->envp->mmode != FOC_MMODE_VEL) # endif { PRINTF("ERROR: open-loop only with FOC_MMODE_VEL\n"); @@ -900,93 +614,34 @@ static int foc_motor_run(FAR struct foc_motor_f32_s *motor) q_ref = motor->dq_ref.q; d_ref = motor->dq_ref.d; - /* Ignore controller if motor is free (sensorless and sensored mode) - * or stopped (only sensorless mode) - */ + /* Controller */ - if (motor->mq.app_state == FOC_EXAMPLE_STATE_FREE -#ifdef CONFIG_EXAMPLES_FOC_SENSORLESS - || motor->mq.app_state == FOC_EXAMPLE_STATE_STOP -#endif - ) + switch (motor->envp->mmode) { - goto no_controller; - } - - /* Controller. - * - * The FOC motor controller is a cascade controller: - * - * 1. Position controller sets requested velocity, - * 2. Velocity controller sets requested torque, - * 3. Torque controller sets requested motor phase voltages. - * - * NOTE: the motor torque is directly proportional to the motor - * current which is proportional to the motor set voltage - */ - - switch (motor->envp->cfg->mmode) - { -#ifdef CONFIG_EXAMPLES_FOC_HAVE_VEL - case FOC_MMODE_VEL: - { - /* Saturate velocity */ - - f_saturate(&motor->vel.des, -motor->vel_sat, - motor->vel_sat); - - /* Velocity controller */ - - if (motor->time % VEL_CONTROL_PRESCALER == 0) - { - /* Run velocity ramp controller */ - - ret = foc_ramp_run_f32(&motor->ramp, - motor->vel.des, - motor->vel.now, - &motor->vel.set); - if (ret < 0) - { - PRINTF("ERROR: foc_ramp_run failed %d\n", ret); - goto errout; - } - - /* Run velocity controller if no in open-loop */ - -#ifdef CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP - if (motor->openloop_now == FOC_OPENLOOP_DISABLED) -#endif - { - /* Get velocity error */ - - vel_err = motor->vel.set - motor->vel.now; - -#ifdef CONFIG_EXAMPLES_FOC_VELCTRL_PI - /* PI velocit controller */ - - motor->torq.des = pi_controller(&motor->vel_pi, - vel_err); -#else -# error Missing velocity controller -#endif - } - } - - /* Don't break here! pass to torque controller */ - } -#endif - #ifdef CONFIG_EXAMPLES_FOC_HAVE_TORQ case FOC_MMODE_TORQ: { - /* Saturate torque */ + motor->torq.set = motor->dir * motor->torq.des; - f_saturate(&motor->torq.des, -motor->torq_sat, - motor->torq_sat); + q_ref = motor->torq.set; + d_ref = 0.0f; - /* Torque setpoint */ + break; + } +#endif - motor->torq.set = motor->torq.des; +#ifdef CONFIG_EXAMPLES_FOC_HAVE_VEL + case FOC_MMODE_VEL: + { + /* Run velocity ramp controller */ + + ret = foc_ramp_run_f32(&motor->ramp, motor->vel.des, + motor->vel.now, &motor->vel.set); + if (ret < 0) + { + PRINTF("ERROR: foc_ramp_run failed %d\n", ret); + goto errout; + } break; } @@ -999,28 +654,20 @@ static int foc_motor_run(FAR struct foc_motor_f32_s *motor) } } - /* Get dq ref */ - - q_ref = motor->torq.set; - d_ref = 0.0f; - #ifdef CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP /* Force open-loop current */ - if (motor->openloop_now == FOC_OPENLOOP_ENABLED || - motor->openloop_now == FOC_OPENLOOP_TRANSITION) + if (motor->openloop_now == true) { - /* Get open-loop currents. Positive for CW direction, negative for - * CCW direction. Id always set to 0. + /* Get open-loop currents + * NOTE: Id always set to 0 */ - q_ref = motor->dir * motor->openloop_q; + q_ref = (motor->envp->qparam / 1000.0f); d_ref = 0.0f; } #endif -no_controller: - /* Set DQ reference frame */ motor->dq_ref.q = q_ref; @@ -1028,272 +675,14 @@ no_controller: /* DQ compensation */ -#ifdef CONFIG_EXAMPLES_FOC_FEEDFORWARD - foc_feedforward_pmsm_f32(&motor->phy, &motor->foc_state.idq, - motor->vel.now, &motor->vdq_comp); -#else motor->vdq_comp.q = 0.0f; motor->vdq_comp.d = 0.0f; -#endif errout: return ret; } #endif -/**************************************************************************** - * Name: foc_motor_ang_get - ****************************************************************************/ - -static int foc_motor_ang_get(FAR struct foc_motor_f32_s *motor) -{ - struct foc_angle_in_f32_s ain; - struct foc_angle_out_f32_s aout; - int ret = OK; - - DEBUGASSERT(motor); - - /* Update open-loop angle handler */ - -#ifdef CONFIG_EXAMPLES_FOC_HAVE_VEL - ain.vel = motor->vel.set; -#endif - ain.state = &motor->foc_state; - ain.angle = motor->angle_now; - ain.dir = motor->dir; - -#ifdef CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP - if (motor->openloop_now != FOC_OPENLOOP_DISABLED) - { - foc_angle_run_f32(&motor->openloop, &ain, &aout); - - /* Store open-loop angle */ - - motor->angle_ol = aout.angle; - } -#endif - -#ifdef CONFIG_EXAMPLES_FOC_HAVE_QENCO - ret = foc_angle_run_f32(&motor->qenco, &ain, &aout); - if (ret < 0) - { - PRINTF("ERROR: foc_angle_run failed %d\n", ret); - goto errout; - } -#endif - -#ifdef CONFIG_EXAMPLES_FOC_HAVE_HALL - ret = foc_angle_run_f32(&motor->hall, &ain, &aout); - if (ret < 0) - { - PRINTF("ERROR: foc_angle_run failed %d\n", ret); - goto errout; - } -#endif - -#ifdef CONFIG_EXAMPLES_FOC_ANGOBS_SMO - ret = foc_angle_run_f32(&motor->ang_smo, &ain, &aout); - if (ret < 0) - { - PRINTF("ERROR: foc_angle_run failed %d\n", ret); - goto errout; - } - - motor->angle_obs = aout.angle; -#endif - -#ifdef CONFIG_EXAMPLES_FOC_ANGOBS_NFO - ret = foc_angle_run_f32(&motor->ang_nfo, &ain, &aout); - if (ret < 0) - { - PRINTF("ERROR: foc_angle_run failed %d\n", ret); - goto errout; - } - - motor->angle_obs = aout.angle; -#endif - -#ifndef CONFIG_EXAMPLES_FOC_HAVE_RUN - /* Dummy value when motor controller disabled */ - - UNUSED(ain); - aout.type = FOC_ANGLE_TYPE_ELE; - aout.angle = 0.0f; -#endif - - /* Store electrical angle from sensor or observer */ - - if (aout.type == FOC_ANGLE_TYPE_ELE) - { - /* Store as electrical angle */ - - motor->angle_el = aout.angle; - } - - else if (aout.type == FOC_ANGLE_TYPE_MECH) - { - /* Store as mechanical angle */ - - motor->angle_m = aout.angle; - - /* Convert mechanical angle to electrical angle */ - - motor->angle_el = fmodf(motor->angle_m * motor->phy.p, - MOTOR_ANGLE_E_MAX); - } - - else - { - ASSERT(0); - } - -#ifdef CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP - /* Get open-loop phase angle */ - - if (motor->openloop_now == FOC_OPENLOOP_ENABLED) - { - motor->angle_now = motor->angle_ol; - motor->angle_el = motor->angle_ol; - } - else -#endif -#ifdef CONFIG_EXAMPLES_FOC_SENSORLESS - /* Handle smooth open-loop to closed-loop transition */ - - if (motor->openloop_now == FOC_OPENLOOP_TRANSITION) - { -#ifdef ANGLE_MERGE_FACTOR - if (fabsf(motor->angle_err) > fabsf(motor->angle_step)) - { - motor->angle_now = motor->angle_obs + motor->angle_err; - - /* Update error */ - - motor->angle_err -= motor->angle_step; - } - else -#endif - { - motor->angle_now = motor->angle_obs; - motor->angle_err = 0.0f; - } - } - - /* Get angle from observer if closed-loop now */ - - else - { - motor->angle_now = motor->angle_obs; - } -#endif - -#ifdef CONFIG_EXAMPLES_FOC_SENSORED - /* Get phase angle from sensor */ - - motor->angle_now = motor->angle_el; -#endif - -#if defined(CONFIG_EXAMPLES_FOC_SENSORED) || defined(CONFIG_EXAMPLES_FOC_ANGOBS) - errout: -#endif - return ret; -} - -#ifdef CONFIG_EXAMPLES_FOC_HAVE_VEL -/**************************************************************************** - * Name: foc_motor_vel_get - ****************************************************************************/ - -static int foc_motor_vel_get(FAR struct foc_motor_f32_s *motor) -{ - struct foc_velocity_in_f32_s vin; - struct foc_velocity_out_f32_s vout; - int ret = OK; - - DEBUGASSERT(motor); - - /* Update velocity handler input data */ - - vin.state = &motor->foc_state; - vin.angle = motor->angle_now; - vin.vel = motor->vel.now; - vin.dir = motor->dir; - - /* Get velocity */ - -#ifdef CONFIG_EXAMPLES_FOC_VELOBS_DIV - ret = foc_velocity_run_f32(&motor->vel_div, &vin, &vout); - if (ret < 0) - { - PRINTF("ERROR: foc_velocity_run failed %d\n", ret); - goto errout; - } - - motor->vel_obs = vout.velocity; -#endif - -#ifdef CONFIG_EXAMPLES_FOC_VELOBS_PLL - ret = foc_velocity_run_f32(&motor->vel_pll, &vin, &vout); - if (ret < 0) - { - PRINTF("ERROR: foc_velocity_run failed %d\n", ret); - goto errout; - } - - motor->vel_obs = vout.velocity; -#endif - - /* Get motor electrical velocity now */ - -#if defined(CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP) && \ - !defined(CONFIG_EXAMPLES_FOC_VELOBS) || \ - !defined(CONFIG_EXAMPLES_FOC_HAVE_RUN) - /* No velocity feedback - assume that electical velocity is - * velocity set - */ - - UNUSED(vin); - UNUSED(vout); - - motor->vel_el = motor->vel.set; -#elif defined(CONFIG_EXAMPLES_FOC_VELOBS) && defined(CONFIG_EXAMPLES_FOC_SENSORLESS) - if (motor->openloop_now == FOC_OPENLOOP_DISABLED) - { - /* Get electrical velocity from observer if we are in closed-loop */ - - motor->vel_el = motor->vel_obs; - } - else - { - /* Otherwise use open-loop velocity */ - - motor->vel_el = motor->vel.set; - } -#elif defined(CONFIG_EXAMPLES_FOC_VELOBS) && defined(CONFIG_EXAMPLES_FOC_SENSORED) - /* Get electrical velocity from observer in sensored mode */ - - motor->vel_el = motor->vel_obs; -#else - /* Need electrical velocity source here - raise assertion */ - - ASSERT(0); -#endif - - /* Store filtered velocity */ - - LP_FILTER(motor->vel.now, motor->vel_el, motor->vel_filter); - - /* Get mechanical velocity (rad/s) */ - - motor->vel_mech = motor->vel_el * motor->phy.one_by_p; - -#ifdef CONFIG_EXAMPLES_FOC_VELOBS -errout: -#endif - return ret; -} -#endif /* CONFIG_EXAMPLES_FOC_HAVE_VEL */ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -1314,23 +703,8 @@ int foc_motor_init(FAR struct foc_motor_f32_s *motor, #ifdef CONFIG_EXAMPLES_FOC_HAVE_HALL struct foc_hall_cfg_f32_s hl_cfg; #endif -#ifdef CONFIG_EXAMPLES_FOC_ANGOBS_SMO - struct foc_angle_osmo_cfg_f32_s smo_cfg; -#endif -#ifdef CONFIG_EXAMPLES_FOC_ANGOBS_NFO - struct foc_angle_onfo_cfg_f32_s nfo_cfg; -#endif -#ifdef CONFIG_EXAMPLES_FOC_VELOBS_DIV - struct foc_vel_div_f32_cfg_s odiv_cfg; -#endif -#ifdef CONFIG_EXAMPLES_FOC_VELOBS_PLL - struct foc_vel_pll_f32_cfg_s opll_cfg; -#endif #ifdef CONFIG_EXAMPLES_FOC_HAVE_ALIGN struct foc_routine_align_cfg_f32_s align_cfg; -#endif -#ifdef CONFIG_EXAMPLES_FOC_HAVE_IDENT - struct foc_routine_ident_cfg_f32_s ident_cfg; #endif int ret = OK; @@ -1348,16 +722,7 @@ int foc_motor_init(FAR struct foc_motor_f32_s *motor, /* Initialize motor data */ motor->per = (float)(1.0f / CONFIG_EXAMPLES_FOC_NOTIFIER_FREQ); -#ifdef CONFIG_EXAMPLES_FOC_ANGOBS - motor->ol_thr = (motor->envp->cfg->ol_thr / 1.0f); - motor->ol_hys = (motor->envp->cfg->ol_hys / 1.0f); -#endif -#ifdef CONFIG_EXAMPLES_FOC_HAVE_TORQ - motor->torq_sat = (CONFIG_EXAMPLES_FOC_TORQ_MAX / 1000.0f); -#endif -#ifdef CONFIG_EXAMPLES_FOC_HAVE_VEL - motor->vel_sat = (CONFIG_EXAMPLES_FOC_VEL_MAX / 1.0f); -#endif + motor->iphase_adc = ((CONFIG_EXAMPLES_FOC_IPHASE_ADC) / 100000.0f); #ifdef CONFIG_EXAMPLES_FOC_HAVE_RUN /* Initialize controller run mode */ @@ -1384,10 +749,6 @@ int foc_motor_init(FAR struct foc_motor_f32_s *motor, ol_cfg.per = motor->per; foc_angle_cfg_f32(&motor->openloop, &ol_cfg); - - /* Store open-loop Q-param */ - - motor->openloop_q = motor->envp->cfg->qparam / 1000.0f; #endif #ifdef CONFIG_EXAMPLES_FOC_HAVE_QENCO @@ -1403,10 +764,10 @@ int foc_motor_init(FAR struct foc_motor_f32_s *motor, /* Get qenco devpath */ - snprintf(motor->qedpath, sizeof(motor->qedpath), - "%s%d", - CONFIG_EXAMPLES_FOC_QENCO_DEVPATH, - motor->envp->id); + sprintf(motor->qedpath, + "%s%d", + CONFIG_EXAMPLES_FOC_QENCO_DEVPATH, + motor->envp->id); /* Configure qenco angle handler */ @@ -1434,10 +795,10 @@ int foc_motor_init(FAR struct foc_motor_f32_s *motor, /* Get hall devpath */ - snprintf(motor->hldpath, sizeof(motor->hldpath), - "%s%d", - CONFIG_EXAMPLES_FOC_HALL_DEVPATH, - motor->envp->id); + sprintf(motor->hldpath, + "%s%d", + CONFIG_EXAMPLES_FOC_HALL_DEVPATH, + motor->envp->id); /* Configure hall angle handler */ @@ -1452,120 +813,6 @@ int foc_motor_init(FAR struct foc_motor_f32_s *motor, } #endif -#ifdef CONFIG_EXAMPLES_FOC_ANGOBS_SMO - /* Initialzie SMO angle observer handler */ - - ret = foc_angle_init_f32(&motor->ang_smo, - &g_foc_angle_osmo_f32); - if (ret < 0) - { - PRINTFV("ERROR: foc_angle_init_f32 failed %d!\n", ret); - goto errout; - } - - /* Configure SMO angle handler */ - - smo_cfg.per = motor->per; - smo_cfg.k_slide = (CONFIG_EXAMPLES_FOC_ANGOBS_SMO_KSLIDE / 1000.0f); - smo_cfg.err_max = (CONFIG_EXAMPLES_FOC_ANGOBS_SMO_ERRMAX / 1000.0f); - memcpy(&smo_cfg.phy, &motor->phy, sizeof(struct motor_phy_params_f32_s)); - - ret = foc_angle_cfg_f32(&motor->ang_smo, &smo_cfg); - if (ret < 0) - { - PRINTFV("ERROR: foc_angle_cfg_f32 failed %d!\n", ret); - goto errout; - } -#endif - -#ifdef CONFIG_EXAMPLES_FOC_ANGOBS_NFO - /* Initialzie NFO angle observer handler */ - - ret = foc_angle_init_f32(&motor->ang_nfo, - &g_foc_angle_onfo_f32); - if (ret < 0) - { - PRINTFV("ERROR: foc_angle_init_f32 failed %d!\n", ret); - goto errout; - } - - /* Configure NFO angle handler */ - - nfo_cfg.per = motor->per; - nfo_cfg.gain = (motor->envp->cfg->ang_nfo_gain / 1.0f); - nfo_cfg.gain_slow = (motor->envp->cfg->ang_nfo_slow / 1.0f); - memcpy(&nfo_cfg.phy, &motor->phy, sizeof(struct motor_phy_params_f32_s)); - - ret = foc_angle_cfg_f32(&motor->ang_nfo, &nfo_cfg); - if (ret < 0) - { - PRINTFV("ERROR: foc_angle_cfg_f32 failed %d!\n", ret); - goto errout; - } -#endif - -#ifdef CONFIG_EXAMPLES_FOC_VELOBS_DIV - /* Initialize velocity observer */ - - ret = foc_velocity_init_f32(&motor->vel_div, - &g_foc_velocity_odiv_f32); - if (ret < 0) - { - PRINTFV("ERROR: foc_angle_init_f32 failed %d!\n", ret); - goto errout; - } - - /* Configure velocity observer */ - - odiv_cfg.samples = (motor->envp->cfg->vel_div_samples); - odiv_cfg.filter = (motor->envp->cfg->vel_div_samples / 1000.0f); - odiv_cfg.per = motor->per; - - ret = foc_velocity_cfg_f32(&motor->vel_div, &odiv_cfg); - if (ret < 0) - { - PRINTFV("ERROR: foc_velocity_cfg_f32 failed %d!\n", ret); - goto errout; - } -#endif - -#ifdef CONFIG_EXAMPLES_FOC_VELOBS_PLL - /* Initialize velocity observer */ - - ret = foc_velocity_init_f32(&motor->vel_pll, - &g_foc_velocity_opll_f32); - if (ret < 0) - { - PRINTFV("ERROR: foc_angle_init_f32 failed %d!\n", ret); - goto errout; - } - - /* Configure velocity observer */ - - opll_cfg.kp = (motor->envp->cfg->vel_pll_kp / 1.0f); - opll_cfg.ki = (motor->envp->cfg->vel_pll_ki / 1.0f); - opll_cfg.per = motor->per; - - ret = foc_velocity_cfg_f32(&motor->vel_pll, &opll_cfg); - if (ret < 0) - { - PRINTFV("ERROR: foc_velocity_cfg_f32 failed %d!\n", ret); - goto errout; - } -#endif - -#ifdef CONFIG_EXAMPLES_FOC_VELCTRL_PI - /* Initialize velocity controller */ - - pi_controller_init(&motor->vel_pi, - (motor->envp->cfg->vel_pi_kp / 1000000.0f), - (motor->envp->cfg->vel_pi_ki / 1000000.0f)); - - pi_saturation_set(&motor->vel_pi, -motor->torq_sat, motor->torq_sat); - - pi_antiwindup_enable(&motor->vel_pi, 0.99f, true); -#endif - #ifdef CONFIG_EXAMPLES_FOC_HAVE_ALIGN /* Initialize motor alignment routine */ @@ -1579,7 +826,7 @@ int foc_motor_init(FAR struct foc_motor_f32_s *motor, /* Initialize motor alignment data */ align_cfg.volt = (CONFIG_EXAMPLES_FOC_ALIGN_VOLT / 1000.0f); - align_cfg.offset_steps = (CONFIG_EXAMPLES_FOC_NOTIFIER_FREQ * \ + align_cfg.offset_steps = (CONFIG_EXAMPLES_FOC_NOTIFIER_FREQ * \ CONFIG_EXAMPLES_FOC_ALIGN_SEC / 1000); /* Connect align callbacks */ @@ -1589,9 +836,6 @@ int foc_motor_init(FAR struct foc_motor_f32_s *motor, /* Connect align callbacks private data */ -# ifdef CONFIG_EXAMPLES_FOC_SENSORLESS - align_cfg.cb.priv = &motor->openloop; -# endif # ifdef CONFIG_EXAMPLES_FOC_HAVE_QENCO align_cfg.cb.priv = &motor->qenco; # endif @@ -1602,95 +846,16 @@ int foc_motor_init(FAR struct foc_motor_f32_s *motor, ret = foc_routine_cfg_f32(&motor->align, &align_cfg); if (ret < 0) { -# ifndef CONFIG_EXAMPLES_FOC_RUN_DISABLE PRINTFV("ERROR: foc_routine_cfg_f32 failed %d!\n", ret); goto errout; -# else - /* When motor controller is disabled, most likely we don't care about - * align routine failure - */ - - PRINTFV("ignore align routine failure\n", ret); - ret = OK; -# endif } #endif -#ifdef CONFIG_EXAMPLES_FOC_HAVE_IDENT - - /* Initialize motor identifiaction routine */ - - ret = foc_routine_init_f32(&motor->ident, &g_foc_routine_ident_f32); - if (ret < 0) - { - PRINTFV("ERROR: foc_routine_init_f32 failed %d!\n", ret); - goto errout; - } - - /* Initialize motor identification data */ - - ident_cfg.per = motor->per; - ident_cfg.res_current = (motor->envp->cfg->ident_res_curr / 1000.0f); - ident_cfg.res_ki = (motor->envp->cfg->ident_res_ki / 1000.0f); - ident_cfg.ind_volt = (motor->envp->cfg->ident_ind_volt / 1000.0f); - ident_cfg.res_steps = (CONFIG_EXAMPLES_FOC_NOTIFIER_FREQ * \ - motor->envp->cfg->ident_res_sec / 1000); - ident_cfg.ind_steps = (CONFIG_EXAMPLES_FOC_NOTIFIER_FREQ * \ - motor->envp->cfg->ident_ind_sec / 1000); - ident_cfg.idle_steps = CONFIG_EXAMPLES_FOC_IDENT_IDLE; - - ret = foc_routine_cfg_f32(&motor->ident, &ident_cfg); - if (ret < 0) - { -# ifndef CONFIG_EXAMPLES_FOC_RUN_DISABLE - PRINTFV("ERROR: foc_ident_cfg_f32 failed %d!\n", ret); - goto errout; -# else - /* When motor controller is disabled, most likely we don't care about - * ident routine failure - */ - - PRINTFV("ident align routine failure\n", ret); - ret = OK; -# endif - } -#endif - -#ifdef CONFIG_EXAMPLES_FOC_HAVE_VEL - /* Store velocity filter value */ - - motor->vel_filter = motor->envp->cfg->vel_filter / 1000.0f; -#endif - /* Initialize controller state */ -#ifdef CONFIG_EXAMPLES_FOC_HAVE_ALIGN - if (motor->envp->cfg->mmode == FOC_MMODE_ALIGN_ONLY) - { - motor->ctrl_state = FOC_CTRL_STATE_ALIGN; - } - else -#endif -#ifdef CONFIG_EXAMPLES_FOC_HAVE_IDENT - if (motor->envp->cfg->mmode == FOC_MMODE_IDENT_ONLY) - { - motor->ctrl_state = FOC_CTRL_STATE_IDENT; - } - else -#endif - if (motor->envp->cfg->mmode == FOC_MMODE_IDLE) - { - motor->ctrl_state = FOC_CTRL_STATE_IDLE; - } - else - { - motor->ctrl_state = FOC_CTRL_STATE_INIT; - } + motor->ctrl_state = FOC_CTRL_STATE_INIT; -#if defined(CONFIG_EXAMPLES_FOC_SENSORED) || \ - defined(CONFIG_EXAMPLES_FOC_HAVE_RUN) || \ - defined(CONFIG_EXAMPLES_FOC_HAVE_ALIGN) || \ - defined(CONFIG_EXAMPLES_FOC_HAVE_IDENT) +#if defined(CONFIG_EXAMPLES_FOC_SENSORED) || defined(CONFIG_EXAMPLES_FOC_HAVE_RUN) errout: #endif return ret; @@ -1706,83 +871,6 @@ int foc_motor_deinit(FAR struct foc_motor_f32_s *motor) DEBUGASSERT(motor); -#ifdef CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP - /* Deinitialzie open-loop handler */ - - ret = foc_angle_deinit_f32(&motor->openloop); - if (ret < 0) - { - PRINTFV("ERROR: foc_angle_deinit_f32 failed %d!\n", ret); - goto errout; - } -#endif - -#ifdef CONFIG_EXAMPLES_FOC_HAVE_QENCO - /* Deinitialzie qenco handler */ - - ret = foc_angle_deinit_f32(&motor->qenco); - if (ret < 0) - { - PRINTFV("ERROR: foc_angle_deinit_f32 failed %d!\n", ret); - goto errout; - } -#endif - -#ifdef CONFIG_EXAMPLES_FOC_HAVE_HALL - /* Deinitialzie hall handler */ - - ret = foc_angle_deinit_f32(&motor->hall); - if (ret < 0) - { - PRINTFV("ERROR: foc_angle_deinit_f32 failed %d!\n", ret); - goto errout; - } -#endif - -#ifdef CONFIG_EXAMPLES_FOC_ANGOBS_SMO - /* Deinitialize SMO observer handler */ - - ret = foc_angle_deinit_f32(&motor->ang_smo); - if (ret < 0) - { - PRINTFV("ERROR: foc_angle_deinit_f32 failed %d!\n", ret); - goto errout; - } -#endif - -#ifdef CONFIG_EXAMPLES_FOC_ANGOBS_NFO - /* Deinitialize NFO observer handler */ - - ret = foc_angle_deinit_f32(&motor->ang_nfo); - if (ret < 0) - { - PRINTFV("ERROR: foc_angle_deinit_f32 failed %d!\n", ret); - goto errout; - } -#endif - -#ifdef CONFIG_EXAMPLES_FOC_VELOBS_DIV - /* Deinitialize DIV observer handler */ - - ret = foc_velocity_deinit_f32(&motor->vel_div); - if (ret < 0) - { - PRINTFV("ERROR: foc_velocity_deinit_f32 failed %d!\n", ret); - goto errout; - } -#endif - -#ifdef CONFIG_EXAMPLES_FOC_VELOBS_PLL - /* Deinitialize PLL observer handler */ - - ret = foc_velocity_deinit_f32(&motor->vel_pll); - if (ret < 0) - { - PRINTFV("ERROR: foc_velocity_deinit_f32 failed %d!\n", ret); - goto errout; - } -#endif - #ifdef CONFIG_EXAMPLES_FOC_HAVE_ALIGN /* Deinitialize motor alignment routine */ @@ -1794,17 +882,6 @@ int foc_motor_deinit(FAR struct foc_motor_f32_s *motor) } #endif -#ifdef CONFIG_EXAMPLES_FOC_HAVE_IDENT - /* Deinitialize motor identification routine */ - - ret = foc_routine_deinit_f32(&motor->ident); - if (ret < 0) - { - PRINTFV("ERROR: foc_routine_deinit_f32 failed %d!\n", ret); - goto errout; - } -#endif - #ifdef CONFIG_EXAMPLES_FOC_STATE_USE_MODEL_PMSM /* Deinitialize PMSM model */ @@ -1839,29 +916,105 @@ errout: int foc_motor_get(FAR struct foc_motor_f32_s *motor) { - int ret = OK; + struct foc_angle_in_f32_s ain; + struct foc_angle_out_f32_s aout; + int ret = OK; DEBUGASSERT(motor); - /* Get motor angle */ - - ret = foc_motor_ang_get(motor); - if (ret < 0) - { - goto errout; - } + /* Update open-loop angle handler */ #ifdef CONFIG_EXAMPLES_FOC_HAVE_VEL - /* Get motor velocity */ + ain.vel = motor->vel.set; +#endif + ain.angle = motor->angle_now; + ain.dir = motor->dir; - ret = foc_motor_vel_get(motor); +#ifdef CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP + foc_angle_run_f32(&motor->openloop, &ain, &aout); + + /* Store open-loop angle */ + + motor->angle_ol = aout.angle; +#endif + +#ifdef CONFIG_EXAMPLES_FOC_HAVE_QENCO + ret = foc_angle_run_f32(&motor->qenco, &ain, &aout); if (ret < 0) { + PRINTF("ERROR: foc_angle_run failed %d\n", ret); goto errout; } #endif +#ifdef CONFIG_EXAMPLES_FOC_HAVE_HALL + ret = foc_angle_run_f32(&motor->hall, &ain, &aout); + if (ret < 0) + { + PRINTF("ERROR: foc_angle_run failed %d\n", ret); + goto errout; + } +#endif + +#ifdef CONFIG_EXAMPLES_FOC_SENSORED + /* Handle angle from sensor */ + + if (aout.type == FOC_ANGLE_TYPE_ELE) + { + /* Store electrical angle */ + + motor->angle_el = aout.angle; + } + + else if (aout.type == FOC_ANGLE_TYPE_MECH) + { + /* Store mechanical angle */ + + motor->angle_m = aout.angle; + + /* Convert mechanical angle to electrical angle */ + + motor->angle_el = fmodf(motor->angle_m * motor->poles, + MOTOR_ANGLE_E_MAX); + } + + else + { + ASSERT(0); + } +#endif /* CONFIG_EXAMPLES_FOC_SENSORED */ + +#ifdef CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP + /* Get phase angle now */ + + if (motor->openloop_now == true) + { + motor->angle_now = motor->angle_ol; + } + else +#endif + { + /* Get phase angle from observer or sensor */ + + motor->angle_now = motor->angle_el; + } + +#ifdef CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP + if (motor->openloop_now == true) + { + /* No velocity feedback - assume that velocity now is velocity set */ + + motor->vel.now = motor->vel.set; + } + else +#endif + { + /* TODO: velocity observer or sensor */ + } + +#ifdef CONFIG_EXAMPLES_FOC_SENSORED errout: +#endif return ret; } @@ -1872,6 +1025,9 @@ errout: int foc_motor_control(FAR struct foc_motor_f32_s *motor) { int ret = OK; +#ifdef CONFIG_EXAMPLES_FOC_HAVE_ALIGN + bool align_done = false; +#endif DEBUGASSERT(motor); @@ -1894,53 +1050,19 @@ int foc_motor_control(FAR struct foc_motor_f32_s *motor) { /* Run motor align procedure */ - ret = foc_motor_align(motor, &motor->align_done); + ret = foc_motor_align(motor, &align_done); if (ret < 0) { PRINTF("ERROR: foc_motor_align failed %d!\n", ret); goto errout; } - if (motor->align_done == true) + if (align_done == true) { /* Next state */ motor->ctrl_state += 1; motor->foc_mode = FOC_HANDLER_MODE_IDLE; - - if (motor->envp->cfg->mmode == FOC_MMODE_ALIGN_ONLY) - { - motor->ctrl_state = FOC_CTRL_STATE_TERMINATE; - } - } - - break; - } -#endif - -#ifdef CONFIG_EXAMPLES_FOC_HAVE_IDENT - case FOC_CTRL_STATE_IDENT: - { - /* Run motor identification procedure */ - - ret = foc_motor_ident(motor, &motor->ident_done); - if (ret < 0) - { - PRINTF("ERROR: foc_motor_ident failed %d!\n", ret); - goto errout; - } - - if (motor->ident_done == true) - { - /* Next state */ - - motor->ctrl_state += 1; - motor->foc_mode = FOC_HANDLER_MODE_IDLE; - - if (motor->envp->cfg->mmode == FOC_MMODE_IDENT_ONLY) - { - motor->ctrl_state = FOC_CTRL_STATE_TERMINATE; - } } break; @@ -1993,13 +1115,6 @@ int foc_motor_control(FAR struct foc_motor_f32_s *motor) break; } - case FOC_CTRL_STATE_TERMINATE: - { - /* Do nothing */ - - break; - } - default: { PRINTF("ERROR: invalid ctrl_state=%d\n", motor->ctrl_state); diff --git a/examples/foc/foc_motor_f32.h b/examples/foc/foc_motor_f32.h index 773241f28..6bab5119a 100644 --- a/examples/foc/foc_motor_f32.h +++ b/examples/foc/foc_motor_f32.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/foc/foc_motor_f32.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -40,9 +38,6 @@ #ifdef CONFIG_EXAMPLES_FOC_HAVE_ALIGN # include "industry/foc/float/foc_align.h" #endif -#ifdef CONFIG_EXAMPLES_FOC_HAVE_IDENT -# include "industry/foc/float/foc_ident.h" -#endif #ifdef CONFIG_EXAMPLES_FOC_STATE_USE_MODEL_PMSM # include "industry/foc/float/foc_model.h" #endif @@ -68,133 +63,57 @@ struct foc_setpoint_f32_s struct foc_motor_f32_s { - /* App data ***************************************************************/ - FAR struct foc_ctrl_env_s *envp; /* Thread env */ - struct foc_mq_s mq; /* MQ data */ bool fault; /* Fault flag */ bool startstop; /* Start/stop request */ - int ctrl_state; /* Controller state */ +#ifdef CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP + bool openloop_now; /* Open-loop now */ + float angle_ol; /* Phase angle open-loop */ + foc_angle_f32_t openloop; /* Open-loop angle handler */ +#endif +#ifdef CONFIG_EXAMPLES_FOC_HAVE_HALL + char hldpath[32]; /* Hall devpath */ + foc_angle_f32_t hall; /* Hall angle handler */ +#endif +#ifdef CONFIG_EXAMPLES_FOC_HAVE_QENCO + char qedpath[32]; /* Qenco devpath */ + foc_angle_f32_t qenco; /* Qenco angle handler */ +#endif + int foc_mode; /* FOC mode */ #ifdef CONFIG_EXAMPLES_FOC_HAVE_RUN int foc_mode_run; /* FOC mode for run state */ #endif - - /* FOC data ***************************************************************/ - - struct foc_state_f32_s foc_state; /* FOC controller sate */ -#ifdef CONFIG_EXAMPLES_FOC_MODULATION_SVM3 - struct svm3_state_f32_s mod_state; /* Modulation state */ -#endif - foc_handler_f32_t handler; /* FOC controller */ - dq_frame_f32_t dq_ref; /* DQ reference */ - dq_frame_f32_t vdq_comp; /* DQ voltage compensation */ - int foc_mode; /* FOC mode */ - int time; /* Helper counter */ + int ctrl_state; /* Controller state */ float vbus; /* Power bus voltage */ - float per; /* Controller period in seconds */ -#ifdef CONFIG_EXAMPLES_FOC_ANGOBS - float ol_thr; /* Angle observer threshold velocity */ - float ol_hys; /* Angle observer hysteresis */ -#endif - - /* Data from FOC device ***************************************************/ - - float iphase_adc; /* Iphase ADC scaling factor */ - float pwm_duty_max; /* PWM duty max */ - - /* Velocity controller data ***********************************************/ - - struct foc_ramp_f32_s ramp; /* Velocity ramp data */ -#ifdef CONFIG_EXAMPLES_FOC_VELCTRL_PI - pid_controller_f32_t vel_pi; /* Velocity controller */ -#endif - - /* Angle state ************************************************************/ - float angle_now; /* Phase angle now */ float angle_m; /* Motor mechanical angle */ float angle_el; /* Motor electrical angle */ -#ifdef CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP - float angle_ol; /* Phase angle open-loop */ -#endif -#ifdef CONFIG_EXAMPLES_FOC_ANGOBS - float angle_obs; /* Angle observer output */ - float angle_err; /* Open-loop to observer error */ - float angle_step; /* Open-loop transition step */ -#endif - - /* Velocity state *********************************************************/ - -#ifdef CONFIG_EXAMPLES_FOC_HAVE_VEL - float vel_el; /* Velocity - electrical */ - float vel_mech; /* Velocity - mechanical */ - float vel_filter; /* Velocity low-pass filter */ -#endif -#ifdef CONFIG_EXAMPLES_FOC_VELOBS - float vel_obs; /* Velocity observer output */ -#endif - - /* Motor setpoints ********************************************************/ - #ifdef CONFIG_EXAMPLES_FOC_HAVE_TORQ struct foc_setpoint_f32_s torq; /* Torque setpoint */ - float torq_sat; /* Torque saturation */ #endif #ifdef CONFIG_EXAMPLES_FOC_HAVE_VEL struct foc_setpoint_f32_s vel; /* Velocity setpoint */ - float vel_sat; /* Velocity saturation */ #endif #ifdef CONFIG_EXAMPLES_FOC_HAVE_POS struct foc_setpoint_f32_s pos; /* Position setpoint */ #endif float dir; /* Motor's direction */ - - /* Motor routines *********************************************************/ - + float per; /* Controller period in seconds */ + float iphase_adc; /* Iphase ADC scaling factor */ + float pwm_duty_max; /* PWM duty max */ + uint8_t poles; /* Motor poles */ + dq_frame_f32_t dq_ref; /* DQ reference */ + dq_frame_f32_t vdq_comp; /* DQ voltage compensation */ + foc_handler_f32_t handler; /* FOC controller */ + struct foc_mq_s mq; /* MQ data */ + struct foc_state_f32_s foc_state; /* FOC controller sate */ + struct foc_ramp_f32_s ramp; /* Velocity ramp data */ #ifdef CONFIG_EXAMPLES_FOC_HAVE_ALIGN struct foc_routine_f32_s align; /* Alignment routine */ - bool align_done; /* Motor alignment done */ #endif -#ifdef CONFIG_EXAMPLES_FOC_HAVE_IDENT - struct foc_routine_f32_s ident; /* Motor ident routine */ - struct motor_phy_params_f32_s phy_ident; /* Motor phy from ident */ - bool ident_done; /* Motor ident done */ -#endif - - /* Motor data *************************************************************/ - #ifdef CONFIG_EXAMPLES_FOC_STATE_USE_MODEL_PMSM - struct foc_model_f32_s model; /* Model handler */ - struct foc_model_state_f32_s model_state; /* PMSM model state */ -#endif - struct motor_phy_params_f32_s phy; /* Motor phy */ - - /* Motor velocity and angle handlers **************************************/ - -#ifdef CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP - foc_angle_f32_t openloop; /* Open-loop angle handler */ - uint8_t openloop_now; /* Open-loop now */ - float openloop_q; /* Open-loop Q parameter */ -#endif -#ifdef CONFIG_EXAMPLES_FOC_HAVE_HALL - foc_angle_f32_t hall; /* Hall angle handler */ - char hldpath[32]; /* Hall devpath */ -#endif -#ifdef CONFIG_EXAMPLES_FOC_HAVE_QENCO - foc_angle_f32_t qenco; /* Qenco angle handler */ - char qedpath[32]; /* Qenco devpath */ -#endif -#ifdef CONFIG_EXAMPLES_FOC_VELOBS_DIV - foc_velocity_f32_t vel_div; /* DIV velocity observer */ -#endif -#ifdef CONFIG_EXAMPLES_FOC_VELOBS_PLL - foc_velocity_f32_t vel_pll; /* PLL velocity observer */ -#endif -#ifdef CONFIG_EXAMPLES_FOC_ANGOBS_SMO - foc_angle_f32_t ang_smo; /* SMO angle observer */ -#endif -#ifdef CONFIG_EXAMPLES_FOC_ANGOBS_NFO - foc_angle_f32_t ang_nfo; /* NFO angle observer */ + struct foc_model_f32_s model; /* Model handler */ + struct foc_model_state_f32_s model_state; /* PMSM model state */ #endif }; diff --git a/examples/foc/foc_mq.c b/examples/foc/foc_mq.c index bbcd5a4fa..e33617034 100644 --- a/examples/foc/foc_mq.c +++ b/examples/foc/foc_mq.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/foc/foc_mq.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -43,11 +41,11 @@ int foc_mq_handle(mqd_t mq, FAR struct foc_mq_s *h) { int ret = OK; - uint8_t buffer[CONTROL_MQ_MSGSIZE]; + uint8_t buffer[5]; /* Get data from AUX */ - ret = mq_receive(mq, (char *)buffer, CONTROL_MQ_MSGSIZE, 0); + ret = mq_receive(mq, (char *)buffer, 5, 0); if (ret < 0) { if (errno != EAGAIN) @@ -67,7 +65,7 @@ int foc_mq_handle(mqd_t mq, FAR struct foc_mq_s *h) /* Verify message length */ - if (ret != CONTROL_MQ_MSGSIZE) + if (ret != 5) { PRINTF("ERROR: invalid message length = %d\n", ret); goto errout; diff --git a/examples/foc/foc_mq.h b/examples/foc/foc_mq.h index a2fd32c4d..e096d0c4b 100644 --- a/examples/foc/foc_mq.h +++ b/examples/foc/foc_mq.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/foc/foc_mq.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/foc/foc_nxscope.c b/examples/foc/foc_nxscope.c deleted file mode 100644 index 93fd992af..000000000 --- a/examples/foc/foc_nxscope.c +++ /dev/null @@ -1,324 +0,0 @@ -/**************************************************************************** - * apps/examples/foc/foc_nxscope.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <errno.h> -#include <unistd.h> -#include <string.h> - -#include "foc_debug.h" -#include "foc_nxscope.h" -#include "foc_thr.h" - -#include "industry/foc/foc_common.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#ifndef CONFIG_LOGGING_NXSCOPE_DISABLE_PUTLOCK -# error CONFIG_LOGGING_NXSCOPE_DISABLE_PUTLOCK must be set to proper operation. -#endif - -#if defined(CONFIG_LOGGING_NXSCOPE_INTF_SERIAL) && !defined(CONFIG_SERIAL_RTT) -# ifndef CONFIG_SERIAL_TERMIOS -# error CONFIG_SERIAL_TERMIOS must be set to proper operation. -# endif -#endif - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -#ifdef CONFIG_EXAMPLES_FOC_NXSCOPE_THREAD -/**************************************************************************** - * Name: foc_nxscope_thr - ****************************************************************************/ - -static FAR void *foc_nxscope_thr(FAR void *arg) -{ - FAR struct foc_nxscope_s *nxs = (FAR struct foc_nxscope_s *)arg; - - DEBUGASSERT(nxs); - - while (1) - { - /* NxScope work */ - - foc_nxscope_work(nxs); - - usleep(10000); - } - - return NULL; -} -#endif - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: foc_nxscope_init - ****************************************************************************/ - -int foc_nxscope_init(FAR struct foc_nxscope_s *nxs) -{ - union nxscope_chinfo_type_u u; - struct nxscope_cfg_s nxs_cfg; -#ifdef CONFIG_EXAMPLES_FOC_NXSCOPE_THREAD - struct sched_param param; - pthread_attr_t attr; - pthread_t nxsthr = 0; -#endif - int ret = OK; - int i = 0; - int j = 0; - - DEBUGASSERT(nxs); - - /* Initialize serial interface */ - - nxs->ser_cfg.path = CONFIG_EXAMPLES_FOC_NXSCOPE_SERIAL_PATH; - nxs->ser_cfg.nonblock = true; - nxs->ser_cfg.baud = CONFIG_EXAMPLES_FOC_NXSCOPE_SERIAL_BAUD; - - ret = nxscope_ser_init(&nxs->intf, &nxs->ser_cfg); - if (ret < 0) - { - PRINTF("ERROR: nxscope_ser_init failed %d\n", ret); - goto errout; - } - - /* Default serial protocol */ - - ret = nxscope_proto_ser_init(&nxs->proto, NULL); - if (ret < 0) - { - PRINTF("ERROR: nxscope_proto_ser_init failed %d\n", ret); - goto errout; - } - - /* Initialize nxscope */ - - nxs_cfg.intf_cmd = &nxs->intf; - nxs_cfg.proto_cmd = &nxs->proto; - nxs_cfg.intf_stream = &nxs->intf; - nxs_cfg.proto_stream = &nxs->proto; - nxs_cfg.channels = CONFIG_EXAMPLES_FOC_NXSCOPE_CHANNELS; - nxs_cfg.streambuf_len = CONFIG_EXAMPLES_FOC_NXSCOPE_STREAMBUF_LEN; - nxs_cfg.rxbuf_len = CONFIG_EXAMPLES_FOC_NXSCOPE_RXBUF_LEN; - nxs_cfg.rx_padding = CONFIG_EXAMPLES_FOC_NXSCOPE_RXPADDING; - nxs_cfg.callbacks = &nxs->cb; - - ret = nxscope_init(&nxs->nxs, &nxs_cfg); - if (ret < 0) - { - PRINTF("ERROR: nxscope_init failed %d\n", ret); - goto errout; - } - - /* Get channels per instance */ - - for (j = 0; j < CONFIG_MOTOR_FOC_INST; j += 1) - { - if (CONFIG_EXAMPLES_FOC_NXSCOPE_CFG & (1 << j)) - { - nxs->ch_per_inst += 1; - } - } - - /* For all FOC controllers */ - - for (j = 0; j < CONFIG_MOTOR_FOC_INST; j += 1) - { - /* Get controller data type */ - - switch (foc_thread_type(j)) - { -#if CONFIG_EXAMPLES_FOC_FLOAT_INST > 0 - case FOC_NUMBER_TYPE_FLOAT: - { - u.s.dtype = NXSCOPE_TYPE_FLOAT; - break; - } -#endif - -#if CONFIG_EXAMPLES_FOC_FIXED16_INST > 0 - case FOC_NUMBER_TYPE_FIXED16: - { - u.s.dtype = NXSCOPE_TYPE_B16; - break; - } -#endif - - default: - { - ASSERT(0); - } - } - - /* Create channels */ - -#if (CONFIG_EXAMPLES_FOC_NXSCOPE_CFG == 0) - UNUSED(u); -#endif - -#if (CONFIG_EXAMPLES_FOC_NXSCOPE_CFG & FOC_NXSCOPE_IABC) - nxscope_chan_init(&nxs->nxs, i++, "iabc", u.u8, - CONFIG_MOTOR_FOC_PHASES, 0); -#endif -#if (CONFIG_EXAMPLES_FOC_NXSCOPE_CFG & FOC_NXSCOPE_IDQ) - nxscope_chan_init(&nxs->nxs, i++, "idq", u.u8, 2, 0); -#endif -#if (CONFIG_EXAMPLES_FOC_NXSCOPE_CFG & FOC_NXSCOPE_IAB) - nxscope_chan_init(&nxs->nxs, i++, "iab", u.u8, 2, 0); -#endif -#if (CONFIG_EXAMPLES_FOC_NXSCOPE_CFG & FOC_NXSCOPE_VABC) - nxscope_chan_init(&nxs->nxs, i++, "vabc", u.u8, - CONFIG_MOTOR_FOC_PHASES, 0); -#endif -#if (CONFIG_EXAMPLES_FOC_NXSCOPE_CFG & FOC_NXSCOPE_VDQ) - nxscope_chan_init(&nxs->nxs, i++, "vdq", u.u8, 2, 0); -#endif -#if (CONFIG_EXAMPLES_FOC_NXSCOPE_CFG & FOC_NXSCOPE_VAB) - nxscope_chan_init(&nxs->nxs, i++, "vab", u.u8, 2, 0); -#endif -#if (CONFIG_EXAMPLES_FOC_NXSCOPE_CFG & FOC_NXSCOPE_AEL) - nxscope_chan_init(&nxs->nxs, i++, "a_el", u.u8, 1, 0); -#endif -#if (CONFIG_EXAMPLES_FOC_NXSCOPE_CFG & FOC_NXSCOPE_AM) - nxscope_chan_init(&nxs->nxs, i++, "a_m", u.u8, 1, 0); -#endif -#if (CONFIG_EXAMPLES_FOC_NXSCOPE_CFG & FOC_NXSCOPE_VEL) - nxscope_chan_init(&nxs->nxs, i++, "v_el", u.u8, 1, 0); -#endif -#if (CONFIG_EXAMPLES_FOC_NXSCOPE_CFG & FOC_NXSCOPE_VM) - nxscope_chan_init(&nxs->nxs, i++, "v_m", u.u8, 1, 0); -#endif -#if (CONFIG_EXAMPLES_FOC_NXSCOPE_CFG & FOC_NXSCOPE_VBUS) - nxscope_chan_init(&nxs->nxs, i++, "vbus", u.u8, 1, 0); -#endif -#if (CONFIG_EXAMPLES_FOC_NXSCOPE_CFG & FOC_NXSCOPE_SPTORQ) - nxscope_chan_init(&nxs->nxs, i++, "sp_torq", u.u8, 3, 0); -#endif -#if (CONFIG_EXAMPLES_FOC_NXSCOPE_CFG & FOC_NXSCOPE_SPVEL) - nxscope_chan_init(&nxs->nxs, i++, "sp_vel", u.u8, 3, 0); -#endif -#if (CONFIG_EXAMPLES_FOC_NXSCOPE_CFG & FOC_NXSCOPE_SPPOS) - nxscope_chan_init(&nxs->nxs, i++, "sp_pos", u.u8, 3, 0); -#endif -#if (CONFIG_EXAMPLES_FOC_NXSCOPE_CFG & FOC_NXSCOPE_DQREF) - nxscope_chan_init(&nxs->nxs, i++, "dqref", u.u8, 2, 0); -#endif -#if (CONFIG_EXAMPLES_FOC_NXSCOPE_CFG & FOC_NXSCOPE_VDQCOMP) - nxscope_chan_init(&nxs->nxs, i++, "vdqcomp", u.u8, 2, 0); -#endif -#if (CONFIG_EXAMPLES_FOC_NXSCOPE_CFG & FOC_NXSCOPE_SVM3) - nxscope_chan_init(&nxs->nxs, i++, "svm3", u.u8, 4, 0); -#endif -#if (CONFIG_EXAMPLES_FOC_NXSCOPE_CFG & FOC_NXSCOPE_VOBS) - nxscope_chan_init(&nxs->nxs, i++, "vobs", u.u8, 1, 0); -#endif -#if (CONFIG_EXAMPLES_FOC_NXSCOPE_CFG & FOC_NXSCOPE_AOBS) - nxscope_chan_init(&nxs->nxs, i++, "aobs", u.u8, 1, 0); -#endif - - if (i > CONFIG_EXAMPLES_FOC_NXSCOPE_CHANNELS) - { - PRINTF("ERROR: invalid nxscope channels value %d\n", i); - ret = -ENOBUFS; - goto errout; - } - } - -#ifdef CONFIG_EXAMPLES_FOC_NXSCOPE_THREAD - /* Configure thread */ - - pthread_attr_init(&attr); - param.sched_priority = CONFIG_EXAMPLES_FOC_NXSCOPE_PRIO; - pthread_attr_setschedparam(&attr, ¶m); - pthread_attr_setstacksize(&attr, CONFIG_EXAMPLES_FOC_NXSCOPE_STACKSIZE); - - /* Create nxscope thread */ - - ret = pthread_create(&nxsthr, &attr, foc_nxscope_thr, nxs); - if (ret != OK) - { - PRINTF("ERROR: pthread_create failed %d\n", ret); - goto errout; - } - - /* Set thread name */ - - ret = pthread_setname_np(nxsthr, "nxsthr"); - if (ret != OK) - { - PRINTF("ERROR: pthread_setname_np failed %d\n", ret); - goto errout; - } -#endif - -errout: - return ret; -} - -/**************************************************************************** - * Name: foc_nxscope_deinit - ****************************************************************************/ - -void foc_nxscope_deinit(FAR struct foc_nxscope_s *nxs) -{ - DEBUGASSERT(nxs); - - nxscope_ser_deinit(nxs->nxs.intf_cmd); - nxscope_proto_ser_deinit(nxs->nxs.proto_cmd); - nxscope_deinit(&nxs->nxs); -} - -/**************************************************************************** - * Name: foc_nxscope_work - ****************************************************************************/ - -void foc_nxscope_work(FAR struct foc_nxscope_s *nxs) -{ - int ret = OK; - - /* Flush stream data */ - - ret = nxscope_stream(&nxs->nxs); - if (ret < 0) - { - PRINTF("ERROR: nxscope_stream failed %d\n", ret); - } - - ret = nxscope_recv(&nxs->nxs); - if (ret < 0) - { - PRINTF("ERROR: nxscope_recv failed %d\n", ret); - } -} diff --git a/examples/foc/foc_nxscope.h b/examples/foc/foc_nxscope.h deleted file mode 100644 index 28ab6c06e..000000000 --- a/examples/foc/foc_nxscope.h +++ /dev/null @@ -1,97 +0,0 @@ -/**************************************************************************** - * apps/examples/foc/foc_nxscope.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __APPS_EXAMPLES_FOC_FOC_NXSCOPE_H -#define __APPS_EXAMPLES_FOC_FOC_NXSCOPE_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include "logging/nxscope/nxscope.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* Definitions for CONFIG_EXAMPLES_FOC_NXSCOPE_CFG bit-mask */ - -#define FOC_NXSCOPE_IABC (1 << 0) /* Phases current */ -#define FOC_NXSCOPE_IDQ (1 << 1) /* Current dq */ -#define FOC_NXSCOPE_IAB (1 << 2) /* Current alpha-beta */ -#define FOC_NXSCOPE_VABC (1 << 3) /* Phases voltage */ -#define FOC_NXSCOPE_VDQ (1 << 4) /* Voltage dq */ -#define FOC_NXSCOPE_VAB (1 << 5) /* Voltage alpha-beta */ -#define FOC_NXSCOPE_AEL (1 << 6) /* Electrical angle */ -#define FOC_NXSCOPE_AM (1 << 7) /* Mechanical angle */ -#define FOC_NXSCOPE_VEL (1 << 8) /* Electrical velocity */ -#define FOC_NXSCOPE_VM (1 << 9) /* Mechanical velocity */ -#define FOC_NXSCOPE_VBUS (1 << 10) /* VBUS */ -#define FOC_NXSCOPE_SPTORQ (1 << 11) /* Torque setpoint */ -#define FOC_NXSCOPE_SPVEL (1 << 12) /* Velolcity setpoint */ -#define FOC_NXSCOPE_SPPOS (1 << 13) /* Position setpoint */ -#define FOC_NXSCOPE_DQREF (1 << 14) /* DQ reference */ -#define FOC_NXSCOPE_VDQCOMP (1 << 15) /* VDQ compensation */ -#define FOC_NXSCOPE_SVM3 (1 << 16) /* Space-vector modulation sector */ -#define FOC_NXSCOPE_VOBS (1 << 17) /* Output from velocity observer */ -#define FOC_NXSCOPE_AOBS (1 << 18) /* Output from angle observer */ - /* Max 32-bit */ - -/**************************************************************************** - * Public Type Definition - ****************************************************************************/ - -struct foc_nxscope_s -{ - struct nxscope_s nxs; - struct nxscope_intf_s intf; - struct nxscope_proto_s proto; - struct nxscope_ser_cfg_s ser_cfg; - struct nxscope_callbacks_s cb; - uint8_t ch_per_inst; -}; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Name: foc_nxscope_init - ****************************************************************************/ - -int foc_nxscope_init(FAR struct foc_nxscope_s *nxs); - -/**************************************************************************** - * Name: foc_nxscope_deinit - ****************************************************************************/ - -void foc_nxscope_deinit(FAR struct foc_nxscope_s *nxs); - -/**************************************************************************** - * Name: foc_nxscope_work - ****************************************************************************/ - -void foc_nxscope_work(FAR struct foc_nxscope_s *nxs); - -#endif /* __APPS_EXAMPLES_FOC_FOC_NXSCOPE_H */ diff --git a/examples/foc/foc_parseargs.c b/examples/foc/foc_parseargs.c index 972a0703f..d94b35027 100644 --- a/examples/foc/foc_parseargs.c +++ b/examples/foc/foc_parseargs.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/foc/foc_parseargs.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -29,10 +27,8 @@ #include <unistd.h> #include <stdlib.h> #include <getopt.h> -#include <inttypes.h> #include "foc_debug.h" -#include "foc_thr.h" #include "foc_parseargs.h" /**************************************************************************** @@ -42,27 +38,6 @@ #define OPT_FKI (SCHAR_MAX + 1) #define OPT_FKP (SCHAR_MAX + 2) -#define OPT_IRKI (SCHAR_MAX + 3) -#define OPT_IRC (SCHAR_MAX + 4) -#define OPT_IRS (SCHAR_MAX + 5) -#define OPT_IIV (SCHAR_MAX + 6) -#define OPT_IIS (SCHAR_MAX + 7) - -#define OPT_VOPLLKP (SCHAR_MAX + 8) -#define OPT_VOPLLKI (SCHAR_MAX + 9) -#define OPT_VODIVS (SCHAR_MAX + 10) -#define OPT_VODIVF (SCHAR_MAX + 11) - -#define OPT_VCPIKP (SCHAR_MAX + 12) -#define OPT_VCPIKI (SCHAR_MAX + 13) - -#define OPT_ANFOS (SCHAR_MAX + 14) -#define OPT_ANFOG (SCHAR_MAX + 15) - -#define OPT_OLFORCE (SCHAR_MAX + 16) -#define OPT_OLTHR (SCHAR_MAX + 17) -#define OPT_OLHYS (SCHAR_MAX + 18) - /**************************************************************************** * Private Data ****************************************************************************/ @@ -78,8 +53,6 @@ static struct option g_long_options[] = #endif #ifdef CONFIG_EXAMPLES_FOC_HAVE_VEL { "vel", required_argument, 0, 'v' }, - { "acc", required_argument, 0, 'a' }, - { "dec", required_argument, 0, 'd' }, #endif #ifdef CONFIG_EXAMPLES_FOC_HAVE_POS { "pos", required_argument, 0, 'x' }, @@ -88,38 +61,10 @@ static struct option g_long_options[] = { "en", required_argument, 0, 'j' }, #ifdef CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP { "oqset", required_argument, 0, 'o' }, - { "olforce", no_argument, 0, OPT_OLFORCE }, -# ifdef CONFIG_EXAMPLES_FOC_ANGOBS - { "olthr", required_argument, 0, OPT_OLTHR }, - { "olhys", required_argument, 0, OPT_OLHYS }, -# endif #endif #ifdef CONFIG_EXAMPLES_FOC_CONTROL_PI { "fkp", required_argument, 0, OPT_FKP }, { "fki", required_argument, 0, OPT_FKI }, -#endif -#ifdef CONFIG_EXAMPLES_FOC_HAVE_IDENT - { "irki", required_argument, 0, OPT_IRKI }, - { "irc", required_argument, 0, OPT_IRC }, - { "irs", required_argument, 0, OPT_IRS }, - { "iiv", required_argument, 0, OPT_IIV }, - { "iis", required_argument, 0, OPT_IIS }, -#endif -#ifdef CONFIG_EXAMPLES_FOC_VELOBS_PLL - { "vopllkp", required_argument, 0, OPT_VOPLLKP }, - { "vopllki", required_argument, 0, OPT_VOPLLKI }, -#endif -#ifdef CONFIG_EXAMPLES_FOC_VELOBS_DIV - { "vodivs", required_argument, 0, OPT_VODIVS }, - { "vodivf", required_argument, 0, OPT_VODIVF }, -#endif -#ifdef CONFIG_EXAMPLES_FOC_VELCTRL_PI - { "vcpikp", required_argument, 0, OPT_VCPIKP }, - { "vcpiki", required_argument, 0, OPT_VCPIKI }, -#endif -#ifdef CONFIG_EXAMPLES_FOC_ANGOBS_NFO - { "anfos", required_argument, 0, OPT_ANFOS }, - { "anfog", required_argument, 0, OPT_ANFOG }, #endif { 0, 0, 0, 0 } }; @@ -132,102 +77,40 @@ static struct option g_long_options[] = * Name: foc_help ****************************************************************************/ -static void foc_help(FAR struct args_s *args) +static void foc_help(void) { PRINTF("Usage: foc [OPTIONS]\n"); - PRINTF(" [-t] run time (default: %d)\n", - CONFIG_EXAMPLES_FOC_TIME_DEFAULT); + PRINTF(" [-t] run time\n"); PRINTF(" [-h] shows this message and exits\n"); - PRINTF(" [-f] FOC run mode (default: %d)\n", - CONFIG_EXAMPLES_FOC_FMODE); + PRINTF(" [-f] FOC run mode\n"); PRINTF(" 1 - IDLE mode\n"); PRINTF(" 2 - voltage mode\n"); PRINTF(" 3 - current mode\n"); - PRINTF(" [-m] controller mode (default: %d)\n", - CONFIG_EXAMPLES_FOC_MMODE); + PRINTF(" [-m] controller mode\n"); PRINTF(" 1 - torqe control\n"); PRINTF(" 2 - velocity control\n"); PRINTF(" 3 - position control\n"); -#ifdef CONFIG_EXAMPLES_FOC_HAVE_ALIGN - PRINTF(" 4 - align only\n"); -#endif -#ifdef CONFIG_EXAMPLES_FOC_HAVE_IDENT - PRINTF(" 5 - ident only\n"); -#endif - PRINTF(" 6 - IDLE state\n"); - #ifdef CONFIG_EXAMPLES_FOC_HAVE_TORQ PRINTF(" [-r] torque [x1000]\n"); #endif #ifdef CONFIG_EXAMPLES_FOC_HAVE_VEL PRINTF(" [-v] velocity [x1000]\n"); - PRINTF(" [-a] acceleration [x1000] (default: %" PRId32 ")\n", - args->cfg.acc); - PRINTF(" [-d] deceleration [x1000] (default: %" PRId32 ")\n", - args->cfg.dec); #endif #ifdef CONFIG_EXAMPLES_FOC_HAVE_POS PRINTF(" [-x] position [x1000]\n"); #endif - PRINTF(" [-s] motor state init (default: %d)\n", - args->state); + PRINTF(" [-s] motor state\n"); PRINTF(" 1 - motor free\n"); PRINTF(" 2 - motor stop\n"); PRINTF(" 3 - motor CW\n"); PRINTF(" 4 - motor CCW\n"); PRINTF(" [-j] enable specific instances\n"); #ifdef CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP - PRINTF(" [-o] openloop Vq/Iq setting [x1000] (default: %" PRId32 ")\n", - args->cfg.qparam); - PRINTF(" [--olforce] force openloop\n"); -# ifdef CONFIG_EXAMPLES_FOC_ANGOBS - PRINTF(" [--olthr] observer vel threshold [x1] (default: %d)\n", - CONFIG_EXAMPLES_FOC_ANGOBS_THR); - PRINTF(" [--olhys] observer vel hysteresys [x1] (default: %d)\n", - CONFIG_EXAMPLES_FOC_ANGOBS_THR); -# endif + PRINTF(" [-o] openloop Vq/Iq setting [x1000]\n"); #endif #ifdef CONFIG_EXAMPLES_FOC_CONTROL_PI - PRINTF(" [--fkp] PI Kp coefficient [x1000] (default: %" PRId32 ")\n", - args->cfg.foc_pi_kp); - PRINTF(" [--fki] PI Ki coefficient [x1000] (default: %" PRId32 ")\n", - args->cfg.foc_pi_ki); -#endif -#ifdef CONFIG_EXAMPLES_FOC_HAVE_IDENT - PRINTF(" [--irki] res Ki coefficient [x1000] (default: %" PRId32 ")\n", - args->cfg.ident_res_ki); - PRINTF(" [--irc] res current [x1000] (default: %" PRId32 ")\n", - args->cfg.ident_res_curr); - PRINTF(" [--irs] res sec (default: %" PRId32 ")\n", - args->cfg.ident_res_sec); - PRINTF(" [--iiv] ind voltage [x1000] (default: %" PRId32 ")\n", - args->cfg.ident_ind_volt); - PRINTF(" [--iis] ind sec (default: %" PRId32 ")\n", - args->cfg.ident_ind_sec); -#endif -#ifdef CONFIG_EXAMPLES_FOC_VELOBS_PLL - PRINTF(" [--vopllkp] velobs PLL Kp [x1] (default: %" PRId32 ")\n", - args->cfg.vel_pll_kp); - PRINTF(" [--vopllki] velobs PLL Ki [x1] (default: %" PRId32 ")\n", - args->cfg.vel_pll_ki); -#endif -#ifdef CONFIG_EXAMPLES_FOC_VELOBS_DIV - PRINTF(" [--vodivs] velobs DIV samples (default: %" PRId32 ")\n", - args->cfg.vel_div_samples); - PRINTF(" [--vodivf] velobs DIV filter (default: %" PRId32 ")\n", - args->cfg.vel_div_filter); -#endif -#ifdef CONFIG_EXAMPLES_FOC_VELCTRL_PI - PRINTF(" [--vcpikp] velctrl PI Kp [x1000000] (default: %" PRId32 ")\n", - args->cfg.vel_pi_kp); - PRINTF(" [--vcpiki] velctrl PI Ki [x1000000] (default: %" PRId32 ")\n", - args->cfg.vel_pi_ki); -#endif -#ifdef CONFIG_EXAMPLES_FOC_ANGOBS_NFO - PRINTF(" [--anfos] angobs NFO Slow [x1] (default: %" PRId32 ")\n", - args->cfg.ang_nfo_slow); - PRINTF(" [--anfog] angobs NFO Gain [x1] (default: %" PRId32 ")\n", - args->cfg.ang_nfo_gain); + PRINTF(" [--fki] PI Kp coefficient [x1000]\n"); + PRINTF(" [--fkp] PI Ki coefficient [x1000]\n"); #endif } @@ -246,7 +129,7 @@ void parse_args(FAR struct args_s *args, int argc, FAR char **argv) while (1) { - c = getopt_long(argc, argv, "ht:f:m:o:r:v:a:d:x:s:j:", g_long_options, + c = getopt_long(argc, argv, "ht:f:m:o:r:v:x:s:j:", g_long_options, &option_index); if (c == -1) @@ -259,101 +142,13 @@ void parse_args(FAR struct args_s *args, int argc, FAR char **argv) #ifdef CONFIG_EXAMPLES_FOC_CONTROL_PI case OPT_FKP: { - args->cfg.foc_pi_kp = atoi(optarg); + args->foc_pi_kp = atoi(optarg); break; } case OPT_FKI: { - args->cfg.foc_pi_ki = atoi(optarg); - break; - } -#endif - -#ifdef CONFIG_EXAMPLES_FOC_HAVE_IDENT - case OPT_IRKI: - { - args->cfg.ident_res_ki = atoi(optarg); - break; - } - - case OPT_IRC: - { - args->cfg.ident_res_curr = atoi(optarg); - break; - } - - case OPT_IRS: - { - args->cfg.ident_res_sec = atoi(optarg); - break; - } - - case OPT_IIV: - { - args->cfg.ident_ind_volt = atoi(optarg); - break; - } - - case OPT_IIS: - { - args->cfg.ident_ind_sec = atoi(optarg); - break; - } -#endif - -#ifdef CONFIG_EXAMPLES_FOC_VELOBS_PLL - case OPT_VOPLLKP: - { - args->cfg.vel_pll_kp = atoi(optarg); - break; - } - - case OPT_VOPLLKI: - { - args->cfg.vel_pll_ki = atoi(optarg); - break; - } -#endif - -#ifdef CONFIG_EXAMPLES_FOC_VELOBS_DIV - case OPT_VODIVS: - { - args->cfg.vel_div_samples = atoi(optarg); - break; - } - - case OPT_VODIVF: - { - args->cfg.vel_div_filter = atoi(optarg); - break; - } -#endif - -#ifdef CONFIG_EXAMPLES_FOC_VELCTRL_PI - case OPT_VCPIKP: - { - args->cfg.vel_pi_kp = atoi(optarg); - break; - } - - case OPT_VCPIKI: - { - args->cfg.vel_pi_ki = atoi(optarg); - break; - } -#endif - -#ifdef CONFIG_EXAMPLES_FOC_ANGOBS_NFO - case OPT_ANFOS: - { - args->cfg.ang_nfo_slow = atoi(optarg); - break; - } - - case OPT_ANFOG: - { - args->cfg.ang_nfo_gain = atoi(optarg); + args->foc_pi_ki = atoi(optarg); break; } #endif @@ -366,26 +161,26 @@ void parse_args(FAR struct args_s *args, int argc, FAR char **argv) case 'h': { - foc_help(args); + foc_help(); exit(0); } case 'f': { - args->cfg.fmode = atoi(optarg); + args->fmode = atoi(optarg); break; } case 'm': { - args->cfg.mmode = atoi(optarg); + args->mmode = atoi(optarg); break; } #ifdef CONFIG_EXAMPLES_FOC_HAVE_TORQ case 'r': { - args->cfg.torqmax = atoi(optarg); + args->torqmax = atoi(optarg); break; } #endif @@ -393,19 +188,7 @@ void parse_args(FAR struct args_s *args, int argc, FAR char **argv) #ifdef CONFIG_EXAMPLES_FOC_HAVE_VEL case 'v': { - args->cfg.velmax = atoi(optarg); - break; - } - - case 'a': - { - args->cfg.acc = atoi(optarg); - break; - } - - case 'd': - { - args->cfg.dec = atoi(optarg); + args->velmax = atoi(optarg); break; } #endif @@ -413,7 +196,7 @@ void parse_args(FAR struct args_s *args, int argc, FAR char **argv) #ifdef CONFIG_EXAMPLES_FOC_HAVE_POS case 'x': { - args->cfg.posmax = atoi(optarg); + args->posmax = atoi(optarg); break; } #endif @@ -433,29 +216,9 @@ void parse_args(FAR struct args_s *args, int argc, FAR char **argv) #ifdef CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP case 'o': { - args->cfg.qparam = atoi(optarg); + args->qparam = atoi(optarg); break; } - - case OPT_OLFORCE: - { - args->cfg.ol_force = true; - break; - } - -# ifdef CONFIG_EXAMPLES_FOC_ANGOBS - case OPT_OLTHR: - { - args->cfg.ol_thr = atoi(optarg); - break; - } - - case OPT_OLHYS: - { - args->cfg.ol_hys = atoi(optarg); - break; - } -# endif #endif case '?': @@ -471,105 +234,9 @@ void parse_args(FAR struct args_s *args, int argc, FAR char **argv) PRINTF("ERROR: invalid option %s\n", argv[optind - 1]); } - foc_help(args); + foc_help(); exit(1); } } } } - -/**************************************************************************** - * Name: validate_args - ****************************************************************************/ - -int validate_args(FAR struct args_s *args) -{ - int ret = -EINVAL; - -#ifdef CONFIG_EXAMPLES_FOC_CONTROL_PI - /* Current PI controller */ - - if (args->cfg.foc_pi_kp == 0 && args->cfg.foc_pi_ki == 0) - { - PRINTF("ERROR: missing FOC Kp/Ki configuration\n"); - goto errout; - } -#endif - - /* FOC operation mode */ - - if (args->cfg.fmode != FOC_FMODE_IDLE && - args->cfg.fmode != FOC_FMODE_VOLTAGE && - args->cfg.fmode != FOC_FMODE_CURRENT) - { - PRINTF("Invalid op mode value %d s\n", args->cfg.fmode); - goto errout; - } - - /* Example control mode */ - - if (args->cfg.mmode != FOC_MMODE_IDLE && -#ifdef CONFIG_EXAMPLES_FOC_HAVE_TORQ - args->cfg.mmode != FOC_MMODE_TORQ && -#endif -#ifdef CONFIG_EXAMPLES_FOC_HAVE_VEL - args->cfg.mmode != FOC_MMODE_VEL && -#endif -#ifdef CONFIG_EXAMPLES_FOC_HAVE_POS - args->cfg.mmode != FOC_MMODE_POS && -#endif -#ifdef CONFIG_EXAMPLES_FOC_HAVE_ALIGN - args->cfg.mmode != FOC_MMODE_ALIGN_ONLY && -#endif -#ifdef CONFIG_EXAMPLES_FOC_HAVE_IDENT - args->cfg.mmode != FOC_MMODE_IDENT_ONLY && -#endif - 1) - { - PRINTF("Invalid ctrl mode value %d s\n", args->cfg.mmode); - goto errout; - } - - /* Example state */ - - if (args->state != FOC_EXAMPLE_STATE_FREE && - args->state != FOC_EXAMPLE_STATE_STOP && - args->state != FOC_EXAMPLE_STATE_CW && - args->state != FOC_EXAMPLE_STATE_CCW) - { - PRINTF("Invalid state value %d s\n", args->state); - goto errout; - } - - /* Time parameter */ - - if (args->time <= 0 && args->time != -1) - { - PRINTF("Invalid time value %d s\n", args->time); - goto errout; - } - -#ifdef CONFIG_EXAMPLES_FOC_HAVE_IDENT - /* Motor identification parameters */ - - if (args->cfg.ident_res_ki == 0 || args->cfg.ident_res_curr == 0 || - args->cfg.ident_res_sec == 0) - { - PRINTF("ERROR: missing motor res ident configuration\n"); - goto errout; - } - - if (args->cfg.ident_ind_volt == 0 || args->cfg.ident_ind_sec == 0) - { - PRINTF("ERROR: missing motor ind ident configuration\n"); - goto errout; - } -#endif - - /* Otherwise OK */ - - ret = OK; - -errout: - return ret; -} diff --git a/examples/foc/foc_parseargs.h b/examples/foc/foc_parseargs.h index 485ab7a43..ad3759f9c 100644 --- a/examples/foc/foc_parseargs.h +++ b/examples/foc/foc_parseargs.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/foc/foc_parseargs.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -30,7 +28,6 @@ #include <nuttx/config.h> #include "foc_device.h" -#include "foc_cfg.h" /**************************************************************************** * Pre-processor Definitions @@ -44,10 +41,29 @@ struct args_s { - int time; /* Run time limit in sec, -1 if forever */ - int state; /* Example state (FREE, CW, CCW, STOP) */ - int8_t en; /* Enabled instances (bit-encoded) */ - struct foc_thr_cfg_s cfg; /* Control thread configuration */ + int time; /* Run time limit in sec, -1 if forever */ + int fmode; /* FOC control mode */ + int mmode; /* Motor control mode */ +#ifdef CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP + int qparam; /* Open-loop Q setting (x1000) */ +#endif + +#ifdef CONFIG_EXAMPLES_FOC_CONTROL_PI + uint32_t foc_pi_kp; /* FOC PI Kp (x1000) */ + uint32_t foc_pi_ki; /* FOC PI Ki (x1000) */ +#endif + + int state; /* Example state (FREE, CW, CCW, STOP) */ + int8_t en; /* Enabled instances (bit-encoded) */ +#ifdef CONFIG_EXAMPLES_FOC_HAVE_TORQ + uint32_t torqmax; /* Torque max (x1000) */ +#endif +#ifdef CONFIG_EXAMPLES_FOC_HAVE_VEL + uint32_t velmax; /* Velocity max (x1000) */ +#endif +#ifdef CONFIG_EXAMPLES_FOC_HAVE_POS + uint32_t posmax; /* Position max (x1000) */ +#endif }; /**************************************************************************** @@ -64,10 +80,4 @@ struct args_s void parse_args(FAR struct args_s *args, int argc, FAR char **argv); -/**************************************************************************** - * Name: validate_args - ****************************************************************************/ - -int validate_args(FAR struct args_s *args); - #endif /* __APPS_EXAMPLES_FOC_FOC_THR_H */ diff --git a/examples/foc/foc_perf.c b/examples/foc/foc_perf.c deleted file mode 100644 index 22a0456da..000000000 --- a/examples/foc/foc_perf.c +++ /dev/null @@ -1,174 +0,0 @@ -/**************************************************************************** - * apps/examples/foc/foc_perf.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <assert.h> -#include <stdbool.h> -#include <string.h> -#include <stdio.h> - -#include <nuttx/clock.h> - -#include "foc_perf.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define PRINTF_PERF(format, ...) printf(format, ##__VA_ARGS__) - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: foc_perf_exec - ****************************************************************************/ - -static bool foc_perf_exec(struct foc_perf_s *p, FAR uint32_t *exec) -{ - bool tmp = p->exec_max_changed; - - *exec = p->exec_max; - p->exec_max_changed = false; - - return tmp; -} - -/**************************************************************************** - * Name: foc_perf_per - ****************************************************************************/ - -static bool foc_perf_per(struct foc_perf_s *p, FAR uint32_t *per) -{ - bool tmp = p->per_max_changed; - - *per = p->per_max; - p->per_max_changed = false; - - return tmp; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: foc_perf_init - ****************************************************************************/ - -int foc_perf_init(struct foc_perf_s *p) -{ - memset(p, 0, sizeof(struct foc_perf_s)); - - return OK; -} - -/**************************************************************************** - * Name: foc_perf_start - ****************************************************************************/ - -void foc_perf_start(struct foc_perf_s *p) -{ - p->exec = perf_gettime(); -} - -/**************************************************************************** - * Name: foc_perf_end - ****************************************************************************/ - -void foc_perf_end(struct foc_perf_s *p) -{ - uint32_t now = perf_gettime(); - uint32_t tmp = 0; - - if (p->per > 0) - { - tmp = now - p->per; - } - - p->per = now; - p->exec = now - p->exec; - - p->exec_max_changed = false; - p->per_max_changed = false; - - if (p->exec > p->exec_max) - { - p->exec_max = p->exec; - p->exec_max_changed = true; - } - - if (tmp > p->per_max) - { - p->per_max = tmp; - p->per_max_changed = true; - } -} - -/**************************************************************************** - * Name: foc_perf_live - ****************************************************************************/ - -void foc_perf_live(struct foc_perf_s *p) -{ - uint32_t perf = 0; - - if (foc_perf_exec(p, &perf)) - { - PRINTF_PERF("exec ticks=%" PRId32 "\n", perf); - } - - if (foc_perf_per(p, &perf)) - { - PRINTF_PERF("per ticks=%" PRId32 "\n", perf); - } -} - -/**************************************************************************** - * Name: foc_perf_exit - ****************************************************************************/ - -void foc_perf_exit(struct foc_perf_s *p) -{ - struct timespec ts; - uint32_t max = 0; - - PRINTF_PERF("===============================\n"); - - foc_perf_exec(p, &max); - perf_convert(max, &ts); - PRINTF_PERF("exec ticks=%" PRId32 "\n", max); - PRINTF_PERF(" nsec=%" PRId32 "\n", ts.tv_nsec); - - foc_perf_per(p, &max); - perf_convert(max, &ts); - PRINTF_PERF("per ticks=%" PRId32 "\n", max); - PRINTF_PERF(" nsec=%" PRId32 "\n", ts.tv_nsec); - - PRINTF_PERF("===============================\n"); -} diff --git a/examples/foc/foc_perf.h b/examples/foc/foc_perf.h deleted file mode 100644 index d8b90d795..000000000 --- a/examples/foc/foc_perf.h +++ /dev/null @@ -1,80 +0,0 @@ -/**************************************************************************** - * apps/examples/foc/foc_perf.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __APPS_EXAMPLES_FOC_FOC_PERF_H -#define __APPS_EXAMPLES_FOC_FOC_PERF_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -/**************************************************************************** - * Public Type Definition - ****************************************************************************/ - -/* The diagram below illustrates the operation of a simple FOC ocntroller - * performance measurement tool: - * - * | notify | notify | notify - * v v v - * ctrl ctrl - * |------| |------| |--- - * | BUSY | wait | BUSY | wait | - * ____| |------| |------| - * - * ^ ^ ^ - * | exec | | - * |<---->| | - * | | - * | per | - * |<----------->| - * - * - * exec - FOC control loop execution time - * per - FOC control loop period - * notify - notification event from FOC device, - * called with CONFIG_EXAMPLES_FOC_NOTIFIER_FREQ frequency - */ - -struct foc_perf_s -{ - bool exec_max_changed; /* Max execution time changed */ - bool per_max_changed; /* Max period changed */ - uint32_t exec_max; /* Control loop execution max */ - uint32_t per_max; /* Control loop period max */ - uint32_t exec; /* Temporary storage */ - uint32_t per; /* Temporary storage */ -}; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -int foc_perf_init(struct foc_perf_s *p); -void foc_perf_start(struct foc_perf_s *p); -void foc_perf_end(struct foc_perf_s *p); -void foc_perf_live(struct foc_perf_s *p); -void foc_perf_exit(struct foc_perf_s *p); - -#endif /* __APPS_EXAMPLES_FOC_FOC_PERF_H */ diff --git a/examples/foc/foc_thr.c b/examples/foc/foc_thr.c index 6de9900fa..aee4b8bf8 100644 --- a/examples/foc/foc_thr.c +++ b/examples/foc/foc_thr.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/foc/foc_thr.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -26,10 +24,9 @@ #include <nuttx/config.h> +#include <fcntl.h> #include <assert.h> #include <errno.h> -#include <fcntl.h> -#include <sched.h> #include "foc_mq.h" #include "foc_thr.h" @@ -37,30 +34,15 @@ #include "industry/foc/foc_common.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#ifndef CONFIG_EXAMPLES_FOC_FLOAT_INST -# define CONFIG_EXAMPLES_FOC_FLOAT_INST (0) -#endif -#ifndef CONFIG_EXAMPLES_FOC_FIXED16_INST -# define CONFIG_EXAMPLES_FOC_FIXED16_INST (0) -#endif - -#if CONFIG_EXAMPLES_FOC_FLOAT_INST + CONFIG_EXAMPLES_FOC_FIXED16_INST == 0 -# warning no control thread enabled ! -#endif - /**************************************************************************** * Extern Functions Prototypes ****************************************************************************/ -#if CONFIG_EXAMPLES_FOC_FLOAT_INST > 0 +#ifdef CONFIG_INDUSTRY_FOC_FLOAT extern int foc_float_thr(FAR struct foc_ctrl_env_s *envp); #endif -#if CONFIG_EXAMPLES_FOC_FIXED16_INST > 0 +#ifdef CONFIG_INDUSTRY_FOC_FIXED16 extern int foc_fixed16_thr(FAR struct foc_ctrl_env_s *envp); #endif @@ -70,11 +52,10 @@ extern int foc_fixed16_thr(FAR struct foc_ctrl_env_s *envp); pthread_mutex_t g_cntr_lock; -static uint32_t g_foc_thr = 0; -#if CONFIG_EXAMPLES_FOC_FLOAT_INST > 0 +#ifdef CONFIG_INDUSTRY_FOC_FLOAT static int g_float_thr_cntr = 0; #endif -#if CONFIG_EXAMPLES_FOC_FIXED16_INST > 0 +#ifdef CONFIG_INDUSTRY_FOC_FIXED16 static int g_fixed16_thr_cntr = 0; #endif @@ -88,8 +69,7 @@ static int g_fixed16_thr_cntr = 0; static FAR void *foc_control_thr(FAR void *arg) { - FAR struct foc_ctrl_env_s *envp = (FAR struct foc_ctrl_env_s *)arg; - char buffer[CONTROL_MQ_MSGSIZE]; + FAR struct foc_ctrl_env_s *envp = (FAR struct foc_ctrl_env_s *) arg; char mqname[10]; int ret = OK; @@ -97,19 +77,35 @@ static FAR void *foc_control_thr(FAR void *arg) /* Get controller type */ - envp->type = foc_thread_type(envp->id); - if (envp->type == -1) + pthread_mutex_lock(&g_cntr_lock); + +#ifdef CONFIG_INDUSTRY_FOC_FLOAT + if (g_float_thr_cntr < CONFIG_EXAMPLES_FOC_FLOAT_INST) + { + envp->type = FOC_NUMBER_TYPE_FLOAT; + } + else +#endif +#ifdef CONFIG_INDUSTRY_FOC_FIXED16 + if (g_fixed16_thr_cntr < CONFIG_EXAMPLES_FOC_FIXED16_INST) + { + envp->type = FOC_NUMBER_TYPE_FIXED16; + } + else +#endif { /* Invalid configuration */ ASSERT(0); } + pthread_mutex_unlock(&g_cntr_lock); + PRINTF("FOC device %d type = %d!\n", envp->id, envp->type); /* Get queue name */ - snprintf(mqname, sizeof(mqname), "%s%d", CONTROL_MQ_MQNAME, envp->id); + sprintf(mqname, "%s%d", CONTROL_MQ_MQNAME, envp->id); /* Open queue */ @@ -120,37 +116,16 @@ static FAR void *foc_control_thr(FAR void *arg) goto errout; } - /* Make sure that the queue is empty */ - - while (1) - { - ret = mq_receive(envp->mqd, buffer, CONTROL_MQ_MSGSIZE, 0); - if (ret < 0) - { - if (errno == EAGAIN) - { - break; - } - else - { - PRINTF("ERROR: mq_receive failed errno=%d\n", errno); - ret = -errno; - goto errout; - } - } - } - /* Select control logic according to FOC device type */ switch (envp->type) { -#if CONFIG_EXAMPLES_FOC_FLOAT_INST > 0 +#ifdef CONFIG_INDUSTRY_FOC_FLOAT case FOC_NUMBER_TYPE_FLOAT: { pthread_mutex_lock(&g_cntr_lock); envp->inst = g_float_thr_cntr; g_float_thr_cntr += 1; - g_foc_thr |= (1 << envp->id); pthread_mutex_unlock(&g_cntr_lock); /* Start thread */ @@ -159,20 +134,18 @@ static FAR void *foc_control_thr(FAR void *arg) pthread_mutex_lock(&g_cntr_lock); g_float_thr_cntr -= 1; - g_foc_thr &= ~(1 << envp->id); pthread_mutex_unlock(&g_cntr_lock); break; } #endif -#if CONFIG_EXAMPLES_FOC_FIXED16_INST > 0 +#ifdef CONFIG_INDUSTRY_FOC_FIXED16 case FOC_NUMBER_TYPE_FIXED16: { pthread_mutex_lock(&g_cntr_lock); envp->inst = g_fixed16_thr_cntr; g_fixed16_thr_cntr += 1; - g_foc_thr |= (1 << envp->id); pthread_mutex_unlock(&g_cntr_lock); /* Start thread */ @@ -181,7 +154,6 @@ static FAR void *foc_control_thr(FAR void *arg) pthread_mutex_lock(&g_cntr_lock); g_fixed16_thr_cntr -= 1; - g_foc_thr &= ~(1 << envp->id); pthread_mutex_unlock(&g_cntr_lock); break; @@ -210,6 +182,7 @@ errout: } PRINTFV("foc_control_thr %d exit\n", envp->id); + return NULL; } @@ -257,54 +230,21 @@ bool foc_threads_terminated(void) { bool ret = false; - pthread_mutex_lock(&g_cntr_lock); + pthread_mutex_unlock(&g_cntr_lock); - if (g_foc_thr == 0) + if (1 +#ifdef CONFIG_INDUSTRY_FOC_FLOAT + && g_float_thr_cntr <= 0 +#endif +#ifdef CONFIG_INDUSTRY_FOC_FIXED16 + && g_fixed16_thr_cntr <= 0 +#endif + ) { ret = true; } - pthread_mutex_unlock(&g_cntr_lock); - - return ret; -} - -/**************************************************************************** - * Name: foc_threads_get - ****************************************************************************/ - -uint32_t foc_threads_get(void) -{ - uint32_t ret = 0; - pthread_mutex_lock(&g_cntr_lock); - ret = g_foc_thr; - pthread_mutex_unlock(&g_cntr_lock); - - return ret; -} - -/**************************************************************************** - * Name: foc_thread_type - ****************************************************************************/ - -int foc_thread_type(int id) -{ - int ret = -1; - -#if CONFIG_EXAMPLES_FOC_FLOAT_INST > 0 - if (id < CONFIG_EXAMPLES_FOC_FLOAT_INST) - { - ret = FOC_NUMBER_TYPE_FLOAT; - } -#endif - -#if CONFIG_EXAMPLES_FOC_FIXED16_INST > 0 - if (id < CONFIG_EXAMPLES_FOC_FLOAT_INST + CONFIG_EXAMPLES_FOC_FIXED16_INST) - { - ret = FOC_NUMBER_TYPE_FIXED16; - } -#endif return ret; } @@ -316,11 +256,11 @@ int foc_thread_type(int id) int foc_ctrlthr_init(FAR struct foc_ctrl_env_s *foc, int i, FAR mqd_t *mqd, FAR pthread_t *thread) { - char mqname[10]; - int ret = OK; - pthread_attr_t attr; - struct mq_attr mqattr; - struct sched_param param; + char mqname[10]; + int ret = OK; + pthread_attr_t attr; + struct mq_attr mqattr; + struct sched_param param; DEBUGASSERT(foc); DEBUGASSERT(mqd); @@ -338,7 +278,7 @@ int foc_ctrlthr_init(FAR struct foc_ctrl_env_s *foc, int i, FAR mqd_t *mqd, /* Get queue name */ - snprintf(mqname, sizeof(mqname), "%s%d", CONTROL_MQ_MQNAME, foc->id); + sprintf(mqname, "%s%d", CONTROL_MQ_MQNAME, foc->id); /* Initialize thread recv queue */ diff --git a/examples/foc/foc_thr.h b/examples/foc/foc_thr.h index f7a931c60..2a8237e6c 100644 --- a/examples/foc/foc_thr.h +++ b/examples/foc/foc_thr.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/foc/foc_thr.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -29,7 +27,6 @@ #include <nuttx/config.h> -#include <stdint.h> #include <pthread.h> #include <mqueue.h> @@ -37,10 +34,6 @@ #include "foc_device.h" -#ifdef CONFIG_EXAMPLES_FOC_NXSCOPE -# include "foc_nxscope.h" -#endif - /**************************************************************************** * Public Type Definition ****************************************************************************/ @@ -70,23 +63,16 @@ enum foc_foc_mode_e enum foc_motor_mode_e { - FOC_MMODE_INVALID = 0, /* Reserved */ + FOC_MMODE_INVALID = 0, /* Reserved */ #ifdef CONFIG_EXAMPLES_FOC_HAVE_TORQ - FOC_MMODE_TORQ = 1, /* Torque control */ + FOC_MMODE_TORQ = 1, /* Torque control */ #endif #ifdef CONFIG_EXAMPLES_FOC_HAVE_VEL - FOC_MMODE_VEL = 2, /* Velocity control */ + FOC_MMODE_VEL = 2, /* Velocity control */ #endif #ifdef CONFIG_EXAMPLES_FOC_HAVE_POS - FOC_MMODE_POS = 3, /* Position control */ + FOC_MMODE_POS = 3 /* Position control */ #endif -#ifdef CONFIG_EXAMPLES_FOC_HAVE_ALIGN - FOC_MMODE_ALIGN_ONLY = 4, /* Sensor alignment only */ -#endif -#ifdef CONFIG_EXAMPLES_FOC_HAVE_IDENT - FOC_MMODE_IDENT_ONLY = 5, /* Motor identification only */ -#endif - FOC_MMODE_IDLE = 6, /* IDLE state */ }; /* Controller state */ @@ -98,28 +84,40 @@ enum foc_controller_state_e #ifdef CONFIG_EXAMPLES_FOC_HAVE_ALIGN FOC_CTRL_STATE_ALIGN, #endif -#ifdef CONFIG_EXAMPLES_FOC_HAVE_IDENT - FOC_CTRL_STATE_IDENT, -#endif #ifdef CONFIG_EXAMPLES_FOC_HAVE_RUN FOC_CTRL_STATE_RUN_INIT, FOC_CTRL_STATE_RUN, #endif - FOC_CTRL_STATE_IDLE, - FOC_CTRL_STATE_TERMINATE + FOC_CTRL_STATE_IDLE }; /* FOC thread data */ struct foc_ctrl_env_s { - mqd_t mqd; /* Control msg queue */ - uint8_t id; /* FOC device id */ - int inst; /* Type specific instance counter */ - int type; /* Controller type */ - FAR struct foc_thr_cfg_s *cfg; /* Control thread configuration */ -#ifdef CONFIG_EXAMPLES_FOC_NXSCOPE - FAR struct foc_nxscope_s *nxs; /* nxscope handler */ + mqd_t mqd; /* Control msg queue */ + int id; /* FOC device id */ + int inst; /* Type specific instance counter */ + int type; /* Controller type */ + int fmode; /* FOC control mode */ + int mmode; /* Motor control mode */ +#ifdef CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP + int qparam; /* Open-loop Q setting (x1000) */ +#endif + +#ifdef CONFIG_EXAMPLES_FOC_CONTROL_PI + uint32_t foc_pi_kp; /* FOC PI Kp (x1000) */ + uint32_t foc_pi_ki; /* FOC PI Ki (x1000) */ +#endif + +#ifdef CONFIG_EXAMPLES_FOC_HAVE_TORQ + uint32_t torqmax; /* Torque max (x1000) */ +#endif +#ifdef CONFIG_EXAMPLES_FOC_HAVE_VEL + uint32_t velmax; /* Velocity max (x1000) */ +#endif +#ifdef CONFIG_EXAMPLES_FOC_HAVE_POS + uint32_t posmax; /* Position max (x1000) */ #endif }; @@ -134,8 +132,6 @@ struct foc_ctrl_env_s int foc_threads_init(void); void foc_threads_deinit(void); bool foc_threads_terminated(void); -uint32_t foc_threads_get(void); -int foc_thread_type(int id); int foc_ctrlthr_init(FAR struct foc_ctrl_env_s *foc, int i, FAR mqd_t *mqd, FAR pthread_t *thread); diff --git a/examples/ft80x/CMakeLists.txt b/examples/ft80x/CMakeLists.txt deleted file mode 100644 index beacaaa5e..000000000 --- a/examples/ft80x/CMakeLists.txt +++ /dev/null @@ -1,44 +0,0 @@ -# ############################################################################## -# apps/examples/ft80x/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_FT80X) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_FT80X_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_FT80X_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_FT80X_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_FT80X} - SRCS - ft80x_main.c) - - set(CSRCS ft80x_coprocessor.c) - if(CONFIG_EXAMPLES_FT80X_PRIMITIVES) - list(APPEND CSRCS ft80x_primitives.c) - endif() - if(CONFIG_EXAMPLES_FT80X_EXCLUDE_BITMAPS) - list(APPEND CSRCS ft80x_bitmaps.c) - endif() - target_sources(apps PRIVATE ${CSRCS}) -endif() diff --git a/examples/ft80x/Make.defs b/examples/ft80x/Make.defs index c4a5c5f63..6cc416928 100644 --- a/examples/ft80x/Make.defs +++ b/examples/ft80x/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/ft80x/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/ft80x/Makefile b/examples/ft80x/Makefile index 9bbf390dc..04ef4ab22 100644 --- a/examples/ft80x/Makefile +++ b/examples/ft80x/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/ft80x/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/ft80x/ft80x.h b/examples/ft80x/ft80x.h index 70492f24e..b87164e61 100644 --- a/examples/ft80x/ft80x.h +++ b/examples/ft80x/ft80x.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/ft80x/ft80x.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -31,7 +29,7 @@ #include <nuttx/compiler.h> #include <stdio.h> -#include <nuttx/debug.h> +#include <debug.h> #ifdef CONFIG_EXAMPLES_FT80X diff --git a/examples/ft80x/ft80x_bitmaps.c b/examples/ft80x/ft80x_bitmaps.c index aecfbfb4f..4794f3c52 100644 --- a/examples/ft80x/ft80x_bitmaps.c +++ b/examples/ft80x/ft80x_bitmaps.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/ft80x/ft80x_bitmaps.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/ft80x/ft80x_coprocessor.c b/examples/ft80x/ft80x_coprocessor.c index 474097a45..d9caba6ba 100644 --- a/examples/ft80x/ft80x_coprocessor.c +++ b/examples/ft80x/ft80x_coprocessor.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/ft80x/ft80x_coprocessor.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -32,7 +30,6 @@ #include <nuttx/config.h> #include <errno.h> -#include <unistd.h> #include <nuttx/lcd/ft80x.h> @@ -2069,7 +2066,7 @@ int ft80x_coproc_interactive(int fd, FAR struct ft80x_dlbuffer_s *buffer) cmds.e.button.cmd = FT80X_CMD_BUTTON; cmds.e.button.x = ydist; cmds.e.button.y = yoffset; - cmds.e.button.w = 10 * width; + cmds.e.button.w = 10 *width; cmds.e.button.h = height; cmds.e.button.font = fontid; @@ -3910,8 +3907,7 @@ int ft80x_coproc_calibrate(int fd, FAR struct ft80x_dlbuffer_s *buffer) return ret; } - ft80x_info("Transform A-F: {%08" PRIx32 ", %08" PRIx32 ", %08" - PRIx32 ", %08" PRIx32 ", %08" PRIx32 ", %08" PRIx32 "}\n", + ft80x_info("Transform A-F: {%08lx, %08lx, %08lx, %08lx, %08lx, %08lx}\n", matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5]); return OK; diff --git a/examples/ft80x/ft80x_main.c b/examples/ft80x/ft80x_main.c index e35294547..da79bf92a 100644 --- a/examples/ft80x/ft80x_main.c +++ b/examples/ft80x/ft80x_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/ft80x/ft80x_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -32,7 +30,6 @@ #include <fcntl.h> #include <errno.h> -#include <sys/param.h> #include <nuttx/lcd/ft80x.h> #include "graphics/ft80x.h" @@ -63,13 +60,13 @@ struct ft80x_exampleinfo_s * ft80x_prim_lines LINES Line drawing primitive * ft80x_prim_linestrip LINE_STRIP Line strip drawing primitive * ft80x_prim_edgestrip_r EDGE_STRIP_R Edge strip right side drawing - * primitive + primitive * (To be provided) EDGE_STRIP_L Edge strip left side drawing - * primitive + primitive * (To be provided) EDGE_STRIP_A Edge strip above side drawing - * primitive + primitive * (To be provided) EDGE_STRIP_B Edge strip below side drawing - * primitive + primitive * ft80x_prim_rectangles RECTS Rectangle drawing primitive * ft80x_prim_scissor SCISSOR Scissor primitive * ft80x_prim_stencil STENCIL Stencil primitives @@ -91,6 +88,7 @@ static const struct ft80x_exampleinfo_s g_primitives[] = { "Alpha Blend", ft80x_prim_alphablend } }; +#define NPRIMITIVES (sizeof(g_primitives) / sizeof(struct ft80x_exampleinfo_s)) #endif /* CONFIG_EXAMPLES_FT80X_PRIMITIVES */ /* Co-processor display examples. Only a small, but interesting, subset @@ -98,7 +96,7 @@ static const struct ft80x_exampleinfo_s g_primitives[] = * possible options. * * FUNCTION CoProc CMD USED DESCRIPTION - * ------------------------ --------------- -------------------------------- + * ------------------------ --------------- ---------------------------------- * ft80x_coproc_button CMD_BUTTON Draw a button * ft80x_coproc_clock CMD_CLOCK Draw an analog clock * ft80x_coproc_gauge CMD_GAUGE Draw a gauge @@ -111,12 +109,12 @@ static const struct ft80x_exampleinfo_s g_primitives[] = * ft80x_coproc_toggle CMD_TOGGLE Draw a toggle switch * ft80x_coproc_number CMD_NUMBER Draw a decimal number * ft80x_coproc_calibrate CMD_CALIBRATE Execute the touch screen - * calibration routine + calibration routine * ft80x_coproc_spinner CMD_SPINNER Start an animated spinner * ft80x_coproc_screensaver CMD_SCREENSAVER Start an animated screensaver * (To be provided) CMD_SKETCH Start a continuous sketch update * (To be provided) CMD_SNAPSHOT Take a snapshot of the current - * screen + screen * ft80x_coproc_logo CMD_LOGO Play device log animation */ @@ -141,6 +139,8 @@ static const struct ft80x_exampleinfo_s g_coproc[] = { "Logo", ft80x_coproc_logo } }; +#define NCOPROC (sizeof(g_coproc) / sizeof(struct ft80x_exampleinfo_s)) + /**************************************************************************** * Private Functions ****************************************************************************/ @@ -182,7 +182,7 @@ static int ft80x_showname(int fd, FAR struct ft80x_dlbuffer_s *buffer, /* Clear the display */ cmds.clearrgb.cmd = FT80X_CLEAR_COLOR_RGB(0, 0, 0x80); - cmds.clear.cmd = FT80X_CLEAR(1, 1, 1); + cmds.clear.cmd = FT80X_CLEAR(1 ,1, 1); cmds.colorrgb.cmd = FT80X_COLOR_RGB(0xff, 0xff, 0xff); /* Use the CMD_TEXT co-processor command to show the name of the next @@ -308,7 +308,7 @@ int main(int argc, FAR char *argv[]) ft80x_info("FT80x Primitive Functions\n"); - for (i = 0; i < nitems(g_primitives); i++) + for (i = 0; i < NPRIMITIVES; i++) { ft80x_example(fd, buffer, &g_primitives[i]); } @@ -318,7 +318,7 @@ int main(int argc, FAR char *argv[]) ft80x_info("FT80x Co-processor Functions\n"); - for (i = 0; i < nitems(g_coproc); i++) + for (i = 0; i < NCOPROC; i++) { ft80x_example(fd, buffer, &g_coproc[i]); } diff --git a/examples/ft80x/ft80x_primitives.c b/examples/ft80x/ft80x_primitives.c index 6f70b53f2..3bd075cfe 100644 --- a/examples/ft80x/ft80x_primitives.c +++ b/examples/ft80x/ft80x_primitives.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/ft80x/ft80x_primitives.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/ftpc/CMakeLists.txt b/examples/ftpc/CMakeLists.txt deleted file mode 100644 index 1e7f1512b..000000000 --- a/examples/ftpc/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# ############################################################################## -# apps/examples/ftpc/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_FTPC) - nuttx_add_application( - NAME - ftpc - STACKSIZE - ${CONFIG_EXAMPLES_FTPC_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_FTPC} - SRCS - ftpc_main.c) - - target_sources(apps PRIVATE ftpc_cmds.c) -endif() diff --git a/examples/ftpc/Make.defs b/examples/ftpc/Make.defs index 22d85b45c..b6b5e7a44 100644 --- a/examples/ftpc/Make.defs +++ b/examples/ftpc/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/ftpc/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/ftpc/Makefile b/examples/ftpc/Makefile index 733ef4e69..f49e509a9 100644 --- a/examples/ftpc/Makefile +++ b/examples/ftpc/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/ftpc/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/ftpc/ftpc.h b/examples/ftpc/ftpc.h index 5b20aa634..55bf00406 100644 --- a/examples/ftpc/ftpc.h +++ b/examples/ftpc/ftpc.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/ftpc/ftpc.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/ftpc/ftpc_cmds.c b/examples/ftpc/ftpc_cmds.c index 4d7a890d4..a3abd17d6 100644 --- a/examples/ftpc/ftpc_cmds.c +++ b/examples/ftpc/ftpc_cmds.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/ftpc/ftpc_cmds.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/ftpc/ftpc_main.c b/examples/ftpc/ftpc_main.c index cce4cf6c2..07a3d9efa 100644 --- a/examples/ftpc/ftpc_main.c +++ b/examples/ftpc/ftpc_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/ftpc/ftpc_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -562,8 +560,7 @@ do_connect: return 1; } #else - ret = readline_stream(g_line, CONFIG_FTPC_LINELEN, - stdin, stdout); + ret = readline(g_line, CONFIG_FTPC_LINELEN, stdin, stdout); /* Readline normally returns the number of characters read, * but will return EOF on end of file or if an error occurs. diff --git a/examples/ftpd/CMakeLists.txt b/examples/ftpd/CMakeLists.txt deleted file mode 100644 index 7b3b33b43..000000000 --- a/examples/ftpd/CMakeLists.txt +++ /dev/null @@ -1,28 +0,0 @@ -# ############################################################################## -# apps/examples/ftpd/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_FTPD) - nuttx_add_application(NAME ftpd_start SRCS ftpd_main.c STACKSIZE - ${CONFIG_EXAMPLES_FTPD_STACKSIZE}) - nuttx_add_application(NAME ftpd_stop STACKSIZE - ${CONFIG_EXAMPLES_FTPD_STACKSIZE}) -endif() diff --git a/examples/ftpd/Kconfig b/examples/ftpd/Kconfig index ab9b1e94c..b2edd881e 100644 --- a/examples/ftpd/Kconfig +++ b/examples/ftpd/Kconfig @@ -11,10 +11,6 @@ config EXAMPLES_FTPD if EXAMPLES_FTPD -config EXAMPLES_FTPD_PORT - int "FTP Daemon Port" - default 21 - config EXAMPLES_FTPD_STACKSIZE int "FTP Daemon Stack Size" default DEFAULT_TASK_STACKSIZE diff --git a/examples/ftpd/Make.defs b/examples/ftpd/Make.defs index b845f46df..4761439f8 100644 --- a/examples/ftpd/Make.defs +++ b/examples/ftpd/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/ftpd/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/ftpd/Makefile b/examples/ftpd/Makefile index 564dd149b..fe42036f9 100644 --- a/examples/ftpd/Makefile +++ b/examples/ftpd/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/ftpd/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/ftpd/ftpd.h b/examples/ftpd/ftpd.h index 59bf11b80..213ab1b19 100644 --- a/examples/ftpd/ftpd.h +++ b/examples/ftpd/ftpd.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/ftpd/ftpd.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/ftpd/ftpd_main.c b/examples/ftpd/ftpd_main.c index e2673572a..f154681e9 100644 --- a/examples/ftpd/ftpd_main.c +++ b/examples/ftpd/ftpd_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/ftpd/ftpd_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -24,8 +22,6 @@ * Included Files ****************************************************************************/ -#include <nuttx/config.h> - #include <sys/types.h> #include <stdio.h> @@ -33,9 +29,8 @@ #include <unistd.h> #include <sched.h> #include <errno.h> -#include <nuttx/debug.h> +#include <debug.h> -#include <sys/param.h> #include <netinet/in.h> #include <arpa/inet.h> @@ -68,12 +63,13 @@ static const struct fptd_account_s g_ftpdaccounts[] = { FTPD_ACCOUNTFLAG_GUEST, "ftp", NULL, NULL }, { FTPD_ACCOUNTFLAG_GUEST, "anonymous", NULL, NULL }, }; +#define NACCOUNTS (sizeof(g_ftpdaccounts) / sizeof(struct fptd_account_s)) /**************************************************************************** * Public Data ****************************************************************************/ -/* To minimize the probability of name collisions, all FTPD example +/* To minimize the probability of name collisitions, all FTPD example * global data is maintained in a single instance of a structure. */ @@ -141,7 +137,7 @@ static void ftpd_accounts(FTPD_SESSION handle) int i; printf("Adding accounts:\n"); - for (i = 0; i < nitems(g_ftpdaccounts); i++) + for (i = 0; i < NACCOUNTS; i++) { account = &g_ftpdaccounts[i]; @@ -156,15 +152,6 @@ static void ftpd_accounts(FTPD_SESSION handle) } } -static void hint(void) -{ - fprintf(stderr, - "Usage: ftpd [-46] \n\ - \t-4 Use IPv4\n\ - \t-6 Use IPv6\n\ - "); -} - /**************************************************************************** * Name: ftpd_daemon ****************************************************************************/ @@ -172,51 +159,28 @@ static void hint(void) int ftpd_daemon(int s_argc, char **s_argv) { FTPD_SESSION handle; - int ret = EXIT_FAILURE; - int option; - int family = AF_UNSPEC; + int ret; /* The FTPD daemon has been started */ g_ftpdglob.running = true; printf("FTP daemon [%d] started\n", g_ftpdglob.pid); - while ((option = getopt(s_argc, &s_argv[1], "46")) != ERROR) - { - switch (option) - { - case '4': - family = AF_INET; - break; - case '6': - family = AF_INET6; - break; - default: - break; - } - } - - if (family == AF_UNSPEC) - { - hint(); - goto out; - } - - if ((optind + 1) < s_argc) - { - fprintf(stderr, "%s: Too many arguments\n", s_argv[1]); - hint(); - goto out; - } - /* Open FTPD */ - handle = ftpd_open(CONFIG_EXAMPLES_FTPD_PORT, family); +#if ADDR_FAMILY == AF_INET6 + handle = ftpd_open(AF_INET6); +#else + handle = ftpd_open(AF_INET); +#endif if (!handle) { printf("FTP daemon [%d] failed to open FTPD\n", g_ftpdglob.pid); - goto out; + g_ftpdglob.running = false; + g_ftpdglob.stop = false; + g_ftpdglob.pid = -1; + return EXIT_FAILURE; } /* Configure accounts */ @@ -247,15 +211,12 @@ int ftpd_daemon(int s_argc, char **s_argv) /* Close the FTPD server and exit. */ printf("FTP daemon [%d] stopping\n", g_ftpdglob.pid); - ftpd_close(handle); - ret = EXIT_SUCCESS; - -out: g_ftpdglob.running = false; g_ftpdglob.stop = false; g_ftpdglob.pid = -1; + ftpd_close(handle); - return ret; + return EXIT_SUCCESS; } /**************************************************************************** @@ -298,7 +259,7 @@ int main(int argc, FAR char *argv[]) printf("Starting the FTP daemon\n"); g_ftpdglob.pid = task_create("FTP daemon", CONFIG_EXAMPLES_FTPD_PRIO, CONFIG_EXAMPLES_FTPD_STACKSIZE, - ftpd_daemon, argv); + ftpd_daemon, NULL); if (g_ftpdglob.pid < 0) { printf("Failed to start the FTP daemon: %d\n", errno); diff --git a/examples/fxos8700cq_test/CMakeLists.txt b/examples/fxos8700cq_test/CMakeLists.txt deleted file mode 100644 index d1fa727ed..000000000 --- a/examples/fxos8700cq_test/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# ############################################################################## -# apps/examples/fxos8700cq_test/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_FXOS8700CQ) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_FXOS8700CQ_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_FXOS8700CQ_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_FXOS8700CQ_STACKSIZE} - SRCS - fxos8700cq_main.c) -endif() diff --git a/examples/fxos8700cq_test/Make.defs b/examples/fxos8700cq_test/Make.defs index 6f58ed4c0..53a3b9b85 100644 --- a/examples/fxos8700cq_test/Make.defs +++ b/examples/fxos8700cq_test/Make.defs @@ -1,8 +1,6 @@ ############################################################################# # apps/examples/fxos8700cq_test/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -20,6 +18,6 @@ # ############################################################################# -ifneq ($(CONFIG_EXAMPLES_FXOS8700CQ),) +ifeq ($(CONFIG_EXAMPLES_FXOS8700CQ),y) CONFIGURED_APPS += examples/fxos8700cq_test endif diff --git a/examples/fxos8700cq_test/Makefile b/examples/fxos8700cq_test/Makefile index 18f857db0..de7448110 100644 --- a/examples/fxos8700cq_test/Makefile +++ b/examples/fxos8700cq_test/Makefile @@ -1,8 +1,6 @@ ############################################################################# # apps/examples/fxos8700cq_test/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -21,6 +19,7 @@ ############################################################################# include $(APPDIR)/Make.defs +-include $(SDKDIR)/Make.defs # fxos8700cq built-in application info diff --git a/examples/fxos8700cq_test/fxos8700cq_main.c b/examples/fxos8700cq_test/fxos8700cq_main.c index b55ad7aef..b73819773 100644 --- a/examples/fxos8700cq_test/fxos8700cq_main.c +++ b/examples/fxos8700cq_test/fxos8700cq_main.c @@ -1,7 +1,6 @@ /**************************************************************************** - * apps/examples/fxos8700cq_test/fxos8700cq_main.c - * - * SPDX-License-Identifier: Apache-2.0 + * apps/examples/fxos8700cq/fxos8700cq_main.c + * fxos8700cq motion sensor sample application * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -25,10 +24,8 @@ ****************************************************************************/ #include <nuttx/config.h> - #include <fcntl.h> #include <stdio.h> -#include <unistd.h> #include <nuttx/sensors/fxos8700cq.h> diff --git a/examples/gpio/CMakeLists.txt b/examples/gpio/CMakeLists.txt deleted file mode 100644 index e0d664020..000000000 --- a/examples/gpio/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# ############################################################################## -# apps/examples/gpio/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_GPIO) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_GPIO_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_GPIO_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_GPIO_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_GPIO} - SRCS - gpio_main.c) -endif() diff --git a/examples/gpio/Make.defs b/examples/gpio/Make.defs index 05f914f31..6575a1ef4 100644 --- a/examples/gpio/Make.defs +++ b/examples/gpio/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/gpio/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/gpio/Makefile b/examples/gpio/Makefile index be8b54ab7..889ca59af 100644 --- a/examples/gpio/Makefile +++ b/examples/gpio/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/gpio/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/gpio/gpio_main.c b/examples/gpio/gpio_main.c index 1b2e86ad5..b24aa1f42 100644 --- a/examples/gpio/gpio_main.c +++ b/examples/gpio/gpio_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/gpio/gpio_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -34,7 +32,6 @@ #include <fcntl.h> #include <signal.h> #include <errno.h> -#include <unistd.h> #include <nuttx/ioexpander/gpio.h> @@ -69,12 +66,6 @@ static void show_usage(FAR const char *progname) fprintf(stderr, "\t 8: GPIO_INTERRUPT_RISING_PIN\n"); fprintf(stderr, "\t 9: GPIO_INTERRUPT_FALLING_PIN\n"); fprintf(stderr, "\t10: GPIO_INTERRUPT_BOTH_PIN\n"); - fprintf(stderr, "\t11: GPIO_INTERRUPT_PIN_WAKEUP\n"); - fprintf(stderr, "\t12: GPIO_INTERRUPT_HIGH_PIN_WAKEUP\n"); - fprintf(stderr, "\t13: GPIO_INTERRUPT_LOW_PIN_WAKEUP\n"); - fprintf(stderr, "\t14: GPIO_INTERRUPT_RISING_PIN_WAKEUP\n"); - fprintf(stderr, "\t15: GPIO_INTERRUPT_FALLING_PIN_WAKEUP\n"); - fprintf(stderr, "\t16: GPIO_INTERRUPT_BOTH_PIN_WAKEUP\n"); } /**************************************************************************** @@ -316,12 +307,6 @@ int main(int argc, FAR char *argv[]) case GPIO_INTERRUPT_RISING_PIN: case GPIO_INTERRUPT_FALLING_PIN: case GPIO_INTERRUPT_BOTH_PIN: - case GPIO_INTERRUPT_PIN_WAKEUP: - case GPIO_INTERRUPT_HIGH_PIN_WAKEUP: - case GPIO_INTERRUPT_LOW_PIN_WAKEUP: - case GPIO_INTERRUPT_RISING_PIN_WAKEUP: - case GPIO_INTERRUPT_FALLING_PIN_WAKEUP: - case GPIO_INTERRUPT_BOTH_PIN_WAKEUP: { printf(" Interrupt pin: Value=%u\n", invalue); diff --git a/examples/gps/CMakeLists.txt b/examples/gps/CMakeLists.txt deleted file mode 100644 index 43d7dd081..000000000 --- a/examples/gps/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# ############################################################################## -# apps/examples/gps/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_GPS) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_GPS_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_GPS_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_GPS_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_GPS} - SRCS - gps_main.c) -endif() diff --git a/examples/gps/Kconfig b/examples/gps/Kconfig index 0d3ac3943..c69d0549c 100644 --- a/examples/gps/Kconfig +++ b/examples/gps/Kconfig @@ -6,7 +6,7 @@ config EXAMPLES_GPS tristate "GPS example" default n - depends on GNSSUTILS_MINMEA_LIB + select GPSUTILS_MINMEA_LIB ---help--- Enable the gps test example diff --git a/examples/gps/Make.defs b/examples/gps/Make.defs index a7b093ba1..e90682038 100644 --- a/examples/gps/Make.defs +++ b/examples/gps/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/gps/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/gps/Makefile b/examples/gps/Makefile index b6af0ca7d..efac4f0ba 100644 --- a/examples/gps/Makefile +++ b/examples/gps/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/gps/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/gps/gps_main.c b/examples/gps/gps_main.c index a308f5213..5db2f1189 100644 --- a/examples/gps/gps_main.c +++ b/examples/gps/gps_main.c @@ -1,7 +1,5 @@ /**************************************************************************** - * apps/examples/gps/gps_main.c - * - * SPDX-License-Identifier: Apache-2.0 + * apps/examples/hello/gps_main.c * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -26,20 +24,12 @@ #include <nuttx/config.h> -#include <stdbool.h> #include <stdio.h> #include <fcntl.h> #include <wchar.h> #include <syslog.h> -#include <unistd.h> -#include <minmea/minmea.h> - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define MINMEA_MAX_LENGTH 256 +#include "gpsutils/minmea.h" /**************************************************************************** * Public Functions @@ -53,26 +43,15 @@ int main(int argc, FAR char *argv[]) { int fd; int cnt; - ssize_t nread; char ch; char line[MINMEA_MAX_LENGTH]; - char *port = "/dev/ttyS1"; - bool truncated; - - /* Get the GPS serial port argument. If none specified, default to ttyS1 */ - - if (argc > 1) - { - port = argv[1]; - } /* Open the GPS serial port */ - fd = open(port, O_RDONLY); + fd = open("/dev/ttyS1", O_RDONLY); if (fd < 0) { - fprintf(stderr, "Unable to open file %s\n", port); - return 1; + printf("Unable to open file /dev/ttyS1\n"); } /* Run forever */ @@ -82,38 +61,18 @@ int main(int argc, FAR char *argv[]) /* Read until we complete a line */ cnt = 0; - truncated = false; - - for (; ; ) + do { - nread = read(fd, &ch, 1); - if (nread <= 0) - { - continue; - } - - if (ch == '\r' || ch == '\n') - { - break; - } - - if (cnt < MINMEA_MAX_LENGTH - 1) + read(fd, &ch, 1); + if (ch != '\r' && ch != '\n') { line[cnt++] = ch; } - else - { - truncated = true; - } } + while (ch != '\r' && ch != '\n'); line[cnt] = '\0'; - if (truncated) - { - continue; - } - switch (minmea_sentence_id(line, false)) { case MINMEA_SENTENCE_RMC: @@ -122,24 +81,18 @@ int main(int argc, FAR char *argv[]) if (minmea_parse_rmc(&frame, line)) { - printf("Fixed-point Latitude................: %" - PRIdLEAST32 " (NMEA * 1000)\n", + printf("Fixed-point Latitude...........: %d\n", minmea_rescale(&frame.latitude, 1000)); - printf("Fixed-point Longitude...............: %" - PRIdLEAST32 " (NMEA * 1000)\n", + printf("Fixed-point Longitude..........: %d\n", minmea_rescale(&frame.longitude, 1000)); - printf("Fixed-point Speed...................: %" - PRIdLEAST32 " (knots * 1000)\n", + printf("Fixed-point Speed..............: %d\n", minmea_rescale(&frame.speed, 1000)); - printf("Floating point Latitude.............: %2.6f " - "degrees\n", + printf("Floating point degree latitude.: %2.6f\n", minmea_tocoord(&frame.latitude)); - printf("Floating point Longitude............: %2.6f " - "degrees\n", + printf("Floating point degree longitude: %2.6f\n", minmea_tocoord(&frame.longitude)); - printf("Floating point Speed................: %2.6f " - "knots\n", - minmea_tofloat(&frame.speed)); + printf("Floating point speed...........: %2.6f\n", + minmea_tocoord(&frame.speed)); } else { @@ -156,9 +109,8 @@ int main(int argc, FAR char *argv[]) { printf("Fix quality....................: %d\n", frame.fix_quality); - printf("Altitude.......................: %2.6f %c\n", - minmea_tofloat(&frame.altitude), - frame.altitude_units ? frame.altitude_units : '?'); + printf("Altitude.......................: %d\n", + frame.altitude.value); printf("Tracked satellites.............: %d\n", frame.satellites_tracked); } @@ -169,7 +121,12 @@ int main(int argc, FAR char *argv[]) } break; - default: + case MINMEA_INVALID: + case MINMEA_UNKNOWN: + case MINMEA_SENTENCE_GSA: + case MINMEA_SENTENCE_GLL: + case MINMEA_SENTENCE_GST: + case MINMEA_SENTENCE_GSV: { } break; diff --git a/examples/hall/CMakeLists.txt b/examples/hall/CMakeLists.txt deleted file mode 100644 index 9626d70fa..000000000 --- a/examples/hall/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# ############################################################################## -# apps/examples/hall/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_HALL) - nuttx_add_application( - NAME - hall - STACKSIZE - ${CONFIG_DEFAULT_TASK_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_HALL} - SRCS - hall_main.c) -endif() diff --git a/examples/hall/Make.defs b/examples/hall/Make.defs index 40bb4483f..7db20e769 100644 --- a/examples/hall/Make.defs +++ b/examples/hall/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/hall/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/hall/Makefile b/examples/hall/Makefile index 12e6dfe23..3c415e238 100644 --- a/examples/hall/Makefile +++ b/examples/hall/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/hall/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/hall/hall.h b/examples/hall/hall.h index 242e9d064..3bb2a2a76 100644 --- a/examples/hall/hall.h +++ b/examples/hall/hall.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/hall/hall.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/hall/hall_main.c b/examples/hall/hall_main.c index e0fdc2e78..3cf2a4d4a 100644 --- a/examples/hall/hall_main.c +++ b/examples/hall/hall_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/hall/hall_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -37,7 +35,7 @@ #include <limits.h> #include <inttypes.h> #include <errno.h> -#include <nuttx/debug.h> +#include <debug.h> #include <nuttx/sensors/hall3ph.h> diff --git a/examples/hdc1008_demo/CMakeLists.txt b/examples/hdc1008_demo/CMakeLists.txt deleted file mode 100644 index d2807a4ea..000000000 --- a/examples/hdc1008_demo/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# ############################################################################## -# apps/examples/hdc1008_demo/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_HDC1008) - nuttx_add_application( - NAME - hdc1008 - STACKSIZE - ${CONFIG_DEFAULT_TASK_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_HDC1008} - SRCS - hdc1008_main.c) -endif() diff --git a/examples/hdc1008_demo/Kconfig b/examples/hdc1008_demo/Kconfig index f23482606..a52b254f4 100644 --- a/examples/hdc1008_demo/Kconfig +++ b/examples/hdc1008_demo/Kconfig @@ -6,7 +6,6 @@ config EXAMPLES_HDC1008 tristate "HDC1008 driver example" default n - depends on SENSORS_HDC1008 ---help--- Enable the example application diff --git a/examples/hdc1008_demo/Make.defs b/examples/hdc1008_demo/Make.defs index ac45aa939..fa1dd8e8a 100644 --- a/examples/hdc1008_demo/Make.defs +++ b/examples/hdc1008_demo/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/hdc1008_demo/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/hdc1008_demo/Makefile b/examples/hdc1008_demo/Makefile index 0016c3e71..6f691ea5e 100644 --- a/examples/hdc1008_demo/Makefile +++ b/examples/hdc1008_demo/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/hdc1008_demo/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/hdc1008_demo/hdc1008_main.c b/examples/hdc1008_demo/hdc1008_main.c index 57b6f2215..cf5c558c4 100644 --- a/examples/hdc1008_demo/hdc1008_main.c +++ b/examples/hdc1008_demo/hdc1008_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/hdc1008_demo/hdc1008_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -33,7 +31,6 @@ #include <fcntl.h> #include <stdio.h> -#include <unistd.h> /**************************************************************************** * Pre-processor Definitions diff --git a/examples/hello/CMakeLists.txt b/examples/hello/CMakeLists.txt deleted file mode 100644 index 94fefd612..000000000 --- a/examples/hello/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# ############################################################################## -# apps/examples/hello/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_HELLO) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_HELLO_PROGNAME} - SRCS - hello_main.c - STACKSIZE - ${CONFIG_EXAMPLES_HELLO_STACKSIZE} - PRIORITY - ${CONFIG_EXAMPLES_HELLO_PRIORITY}) -endif() diff --git a/examples/hello/Make.defs b/examples/hello/Make.defs index e31ef0f1d..b21f7d203 100644 --- a/examples/hello/Make.defs +++ b/examples/hello/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/hello/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/hello/Makefile b/examples/hello/Makefile index e8bcc4985..1a95f1ae9 100644 --- a/examples/hello/Makefile +++ b/examples/hello/Makefile @@ -1,7 +1,5 @@ ############################################################################ -# apps/examples/hello/Makefile -# -# SPDX-License-Identifier: Apache-2.0 +# apps/examples/hello/Make.defs # # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with diff --git a/examples/hello/hello_main.c b/examples/hello/hello_main.c index fd194a623..2cd6cb400 100644 --- a/examples/hello/hello_main.c +++ b/examples/hello/hello_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/hello/hello_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/hello_d/Kconfig b/examples/hello_d/Kconfig deleted file mode 100644 index 04fb65a61..000000000 --- a/examples/hello_d/Kconfig +++ /dev/null @@ -1,29 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config EXAMPLES_HELLO_D - tristate "\"Hello, D!\" D example" - default n - ---help--- - Enable the \"Hello, D!\" D example - -if EXAMPLES_HELLO_D - -config EXAMPLES_HELLO_D_PROGNAME - string "Program name" - default "hello_d" - ---help--- - This is the name of the program that will be used when the - program is installed. - -config EXAMPLES_HELLO_D_PRIORITY - int "Hello D task priority" - default 100 - -config EXAMPLES_HELLO_D_STACKSIZE - int "Hello D stack size" - default DEFAULT_TASK_STACKSIZE - -endif diff --git a/examples/hello_d/Make.defs b/examples/hello_d/Make.defs deleted file mode 100644 index 1dbcd3b9f..000000000 --- a/examples/hello_d/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/examples/hello_d/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_EXAMPLES_HELLO_D),) -CONFIGURED_APPS += $(APPDIR)/examples/hello_d -endif diff --git a/examples/hello_d/Makefile b/examples/hello_d/Makefile deleted file mode 100644 index 983d3f3d7..000000000 --- a/examples/hello_d/Makefile +++ /dev/null @@ -1,43 +0,0 @@ -############################################################################ -# apps/examples/hello_d/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -# Hello, World! D Example - -MAINSRC = hello_d_main.d - -# hello_d built-in application info - -# no garbage collection -DFLAGS += -betterC -# better informations -DFLAGS += -vtls -verrors=context -# like #ifdef/#define NuttX_ImportC -# importC: need $(CC) to compile C file and -P-I to import C includes -DFLAGS += -P-I$(TOPDIR)/include --d-version=NuttX_ImportC --gcc=$(CC) -PROGNAME = $(CONFIG_EXAMPLES_HELLO_D_PROGNAME) -PRIORITY = $(CONFIG_EXAMPLES_HELLO_D_PRIORITY) -STACKSIZE = $(CONFIG_EXAMPLES_HELLO_D_STACKSIZE) -MODULE = $(CONFIG_EXAMPLES_HELLO_D) - -include $(APPDIR)/Application.mk diff --git a/examples/hello_d/hello_d_main.d b/examples/hello_d/hello_d_main.d deleted file mode 100644 index 4d165b1f3..000000000 --- a/examples/hello_d/hello_d_main.d +++ /dev/null @@ -1,162 +0,0 @@ -//*************************************************************************** -// apps/examples/hello_d/hello_d_main.d -// -// SPDX-License-Identifier: Apache-2.0 -// -// Licensed to the Apache Software Foundation (ASF) under one or more -// contributor license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright ownership. The -// ASF licenses this file to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance with the -// License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -// License for the specific language governing permissions and limitations -// under the License. -// -//*************************************************************************** -module examples.hello_d_main; - -//*************************************************************************** -// Imports module -//*************************************************************************** -/// Type issues, need make own D runtime (object.d file) -// import core.stdc.stdio : printf; -// import core.stdc.stdlib : malloc, free; - -version (D_BetterC) // no DRT -{ - /// if betterC and LDC, disable moduleinfo and typeinfo - version (LDC) - { - pragma(LDC_no_moduleinfo); - pragma(LDC_no_typeinfo); - } -} - -/// use --d-version=NuttX_ImportC to define -version (NuttX_ImportC) -{ - /// D compiler will not import C++ symbols - /// so we need to import them manually - /// @nogc, @trusted, @safe, nothrow - not allowed - /// https://issues.dlang.org/show_bug.cgi?id=23812 - import nuttx_std : malloc, free, printf; // by default: @system (unsafe) -} -else -{ - /// Correctly FFI-import C/C++ symbols (@safe compatibility) - /// - pragma(printf) - extern (C) int printf(scope const(char)* fmt, scope...) @nogc nothrow @trusted; - /// - extern (C) void* malloc(size_t size) @nogc nothrow @trusted; - /// - extern (C) void free(scope void* ptr) @nogc nothrow @trusted; -} - -//*************************************************************************** -// Private module content (default is public) -//*************************************************************************** -private: - -// based heloxx class layout -extern (C++,class) -struct DHelloWorld -{ - @disable this(); - @disable this(this); - - /// use --d-version=NuttX_ImportC to define - version (NuttX_ImportC) - { - this(int secret) - { - mSecret = secret; - printf("Constructor\n"); - } - - ~this() - { - printf("Destructor\n"); - } - - bool HelloWorld() - { - printf("HelloWorld: mSecret=%d\n", mSecret); - - if (mSecret != 42) - { - printf("DHelloWorld.HelloWorld: CONSTRUCTION FAILED!\n"); - return false; - } - else - { - printf("DHelloWorld.HelloWorld: Hello, World!!\n"); - return true; - } - } - } - else - { - this(int secret) @safe nothrow @nogc - { - mSecret = secret; - printf("Constructor\n"); - } - - ~this() @safe nothrow @nogc - { - printf("Destructor\n"); - } - - bool HelloWorld() @safe nothrow @nogc - { - printf("HelloWorld: mSecret=%d\n", mSecret); - - if (mSecret != 42) - { - printf("DHelloWorld.HelloWorld: CONSTRUCTION FAILED!\n"); - return false; - } - else - { - printf("DHelloWorld.HelloWorld: Hello, World!!\n"); - return true; - } - } - } - private int mSecret = 0; -} - -/**************************************************************************** - * Name: hello_d_main - ****************************************************************************/ -// betterC need main function no-mangle. -extern (C) int hello_d_main(int argc, char*[] argv) -{ - version (LDC) - { - /// need LLVM targetinfo - printf("Hello World, [%s]!\n", __traits(targetCPU).ptr); - } - // Exercise an explicitly instantiated C++ object - auto pHelloWorld = cast(DHelloWorld*) malloc(DHelloWorld.sizeof); - scope (exit) - free(pHelloWorld); - - printf("hello_d_main: Saying hello from the dynamically constructed instance\n"); - pHelloWorld.HelloWorld(); - - // Exercise an D object instantiated on the stack - auto HelloWorld = DHelloWorld(42); - - printf("hello_d_main: Saying hello from the instance constructed on the stack\n"); - HelloWorld.HelloWorld(); - - return 0; -} diff --git a/examples/hello_d/nuttx_std.c b/examples/hello_d/nuttx_std.c deleted file mode 100644 index 0583f396b..000000000 --- a/examples/hello_d/nuttx_std.c +++ /dev/null @@ -1,41 +0,0 @@ -/**************************************************************************** - * apps/examples/hello_d/nuttx_std.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -/**************************************************************************** - * This is imported to d source using importC - * https://dlang.org/spec/importc.html - ****************************************************************************/ -#include <nuttx/config.h> -#include <stdio.h> -#include <stdlib.h> - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * hello_d_main - ****************************************************************************/ \ No newline at end of file diff --git a/examples/hello_nim/.gitignore b/examples/hello_nim/.gitignore deleted file mode 100644 index e8a85e0b5..000000000 --- a/examples/hello_nim/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -.nimcache/ -.nimc diff --git a/examples/hello_nim/Kconfig b/examples/hello_nim/Kconfig deleted file mode 100644 index e955ef88f..000000000 --- a/examples/hello_nim/Kconfig +++ /dev/null @@ -1,29 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config EXAMPLES_HELLO_NIM - tristate "\"Hello, Nim!\" example" - default n - ---help--- - Enable the \"Hello, Nim!\" example in Nim language - -if EXAMPLES_HELLO_NIM - -config EXAMPLES_HELLO_NIM_PROGNAME - string "Program name" - default "hello_nim" - ---help--- - This is the name of the program that will be used when the NSH ELF - program is installed. - -config EXAMPLES_HELLO_NIM_PRIORITY - int "Hello task priority" - default 100 - -config EXAMPLES_HELLO_NIM_STACKSIZE - int "Hello stack size" - default DEFAULT_TASK_STACKSIZE - -endif diff --git a/examples/hello_nim/Make.defs b/examples/hello_nim/Make.defs deleted file mode 100644 index 595d85133..000000000 --- a/examples/hello_nim/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/examples/hello_nim/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_EXAMPLES_HELLO_NIM),) -CONFIGURED_APPS += $(APPDIR)/examples/hello_nim -endif diff --git a/examples/hello_nim/Makefile b/examples/hello_nim/Makefile deleted file mode 100644 index fa7973106..000000000 --- a/examples/hello_nim/Makefile +++ /dev/null @@ -1,52 +0,0 @@ -############################################################################ -# apps/examples/hello_nim/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -# Hello, World! (Nim) built-in application info - -PROGNAME = $(CONFIG_EXAMPLES_HELLO_NIM_PROGNAME) -PRIORITY = $(CONFIG_EXAMPLES_HELLO_NIM_PRIORITY) -STACKSIZE = $(CONFIG_EXAMPLES_HELLO_NIM_STACKSIZE) -MODULE = $(CONFIG_EXAMPLES_HELLO_NIM) - -# Hello, World! Example - -NIMPATH = $(shell choosenim show path) -CFLAGS += -I $(NIMPATH)/lib -I ../../.nimcache -CSRCS += $(wildcard ../../.nimcache/*.c) - -MAINSRC = hello_nim_main.c - -.nimc: hello_nim_async.nim - nim c --header $< - touch .nimc - -$(MAINSRC): .nimc - -clean:: - $(call DELDIR, .nimcache) - $(call DELFILE, .nimc) - -all:: .nimc $(MAINSRC) - -include $(APPDIR)/Application.mk diff --git a/examples/hello_nim/hello_nim_async.nim b/examples/hello_nim/hello_nim_async.nim deleted file mode 100644 index 08e5a3b86..000000000 --- a/examples/hello_nim/hello_nim_async.nim +++ /dev/null @@ -1,42 +0,0 @@ -#[ - **************************************************************************** - * apps/examples/hello_nim/hello_nim_async.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ -]# - -import std/asyncdispatch -import std/strformat - -proc task(id: int): Future[void] {.async.} = - for loop in 0..2: - echo &"Hello from task {id}! loops: {loop}" - if loop < 2: - await sleepAsync(1000) - -proc launch() {.async.} = - for id in 1..2: - asyncCheck task(id) - await sleepAsync(200) - await task(3) - -proc hello_nim() {.exportc, cdecl.} = - waitFor launch() - GC_runOrc() diff --git a/examples/hello_nim/hello_nim_main.c b/examples/hello_nim/hello_nim_main.c deleted file mode 100644 index 2f1386533..000000000 --- a/examples/hello_nim/hello_nim_main.c +++ /dev/null @@ -1,43 +0,0 @@ -/**************************************************************************** - * apps/examples/hello_nim/hello_nim_main.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> -#include "hello_nim_async.h" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * hello_main - ****************************************************************************/ - -int main(int argc, FAR char *argv[]) -{ - NimMain(); - hello_nim(); - return 0; -} diff --git a/examples/rust/baremetal/Kconfig b/examples/hello_rust/Kconfig similarity index 84% rename from examples/rust/baremetal/Kconfig rename to examples/hello_rust/Kconfig index a1b391bee..92e3b1f34 100644 --- a/examples/rust/baremetal/Kconfig +++ b/examples/hello_rust/Kconfig @@ -7,8 +7,7 @@ config EXAMPLES_HELLO_RUST tristate "\"Hello, Rust!\" example" default n ---help--- - Enable the \"Hello, Rust!\" example to show how to build - and run a baremetal Rust application with rustc. + Enable the \"Hello, Rust!\" example if EXAMPLES_HELLO_RUST diff --git a/examples/hello_rust/Make.defs b/examples/hello_rust/Make.defs new file mode 100644 index 000000000..245662e68 --- /dev/null +++ b/examples/hello_rust/Make.defs @@ -0,0 +1,23 @@ +############################################################################ +# apps/examples/hello_rust/Make.defs +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. The +# ASF licenses this file to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance with the +# License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +############################################################################ + +ifneq ($(CONFIG_EXAMPLES_HELLO_RUST),) +CONFIGURED_APPS += $(APPDIR)/examples/hello_rust +endif diff --git a/examples/rust/baremetal/Makefile b/examples/hello_rust/Makefile similarity index 92% rename from examples/rust/baremetal/Makefile rename to examples/hello_rust/Makefile index 55e98ce7b..f96db90e5 100644 --- a/examples/rust/baremetal/Makefile +++ b/examples/hello_rust/Makefile @@ -1,7 +1,5 @@ ############################################################################ -# apps/examples/rust/baremetal/Makefile -# -# SPDX-License-Identifier: Apache-2.0 +# apps/examples/hello_rust/Make.defs # # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with @@ -33,6 +31,6 @@ MODULE = $(CONFIG_EXAMPLES_HELLO_RUST) MAINSRC = hello_rust_main.rs -RUSTFLAGS += -C panic=abort -O +RUSTFLAGS += -C panic=abort include $(APPDIR)/Application.mk diff --git a/examples/rust/baremetal/hello_rust_main.rs b/examples/hello_rust/hello_rust_main.rs similarity index 96% rename from examples/rust/baremetal/hello_rust_main.rs rename to examples/hello_rust/hello_rust_main.rs index 3d7a3eceb..3a276e94d 100644 --- a/examples/rust/baremetal/hello_rust_main.rs +++ b/examples/hello_rust/hello_rust_main.rs @@ -1,7 +1,5 @@ /**************************************************************************** - * apps/examples/rust/baremetal/hello_rust_main.rs - * - * SPDX-License-Identifier: Apache-2.0 + * apps/examples/hello_rust/hello_rust_main.rs * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with diff --git a/examples/hello_swift/BridgingHeader.h b/examples/hello_swift/BridgingHeader.h deleted file mode 100644 index ca7ed2ce6..000000000 --- a/examples/hello_swift/BridgingHeader.h +++ /dev/null @@ -1,30 +0,0 @@ -/**************************************************************************** - * apps/examples/hello_swift/BridgingHeader.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ -#ifndef BridgingHeader_h -#define BridgingHeader_h -#include <nuttx/config.h> -#include <stdio.h> -#endif // BridgingHeader_h \ No newline at end of file diff --git a/examples/hello_swift/Kconfig b/examples/hello_swift/Kconfig deleted file mode 100644 index 4bdeac8ab..000000000 --- a/examples/hello_swift/Kconfig +++ /dev/null @@ -1,29 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config EXAMPLES_HELLO_SWIFT - tristate "\"Hello, Swift!\" Swift embedded example" - default n - ---help--- - Enable the \"Hello, Swift!\" Swift embedded example - -if EXAMPLES_HELLO_SWIFT - -config EXAMPLES_HELLO_SWIFT_PROGNAME - string "Program name" - default "hello_swift" - ---help--- - This is the name of the program that will be used when the - program is installed. - -config EXAMPLES_HELLO_SWIFT_PRIORITY - int "Hello Swift task priority" - default 100 - -config EXAMPLES_HELLO_SWIFT_STACKSIZE - int "Hello Swift stack size" - default DEFAULT_TASK_STACKSIZE - -endif diff --git a/examples/hello_swift/Make.defs b/examples/hello_swift/Make.defs deleted file mode 100644 index d3e68fc72..000000000 --- a/examples/hello_swift/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/examples/hello_swift/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_EXAMPLES_HELLO_SWIFT),) -CONFIGURED_APPS += $(APPDIR)/examples/hello_swift -endif diff --git a/examples/hello_swift/Makefile b/examples/hello_swift/Makefile deleted file mode 100644 index 49fabf55d..000000000 --- a/examples/hello_swift/Makefile +++ /dev/null @@ -1,39 +0,0 @@ -############################################################################ -# apps/examples/hello_swift/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -# Hello, World! Swift Embedded Example - -MAINSRC = hello_swift_main.swift - -# hello_swift built-in application info - -SWIFTFLAGS += -import-bridging-header BridgingHeader.h -I$(TOPDIR)/include -SWIFTFLAGS += -Xfrontend -function-sections -Xfrontend -disable-stack-protector -SWIFTFLAGS += -Xfrontend -enable-single-module-llvm-emission -PROGNAME = $(CONFIG_EXAMPLES_HELLO_SWIFT_PROGNAME) -PRIORITY = $(CONFIG_EXAMPLES_HELLO_SWIFT_PRIORITY) -STACKSIZE = $(CONFIG_EXAMPLES_HELLO_SWIFT_STACKSIZE) -MODULE = $(CONFIG_EXAMPLES_HELLO_SWIFT) - -include $(APPDIR)/Application.mk diff --git a/examples/hello_swift/hello_swift_main.swift b/examples/hello_swift/hello_swift_main.swift deleted file mode 100644 index 665704908..000000000 --- a/examples/hello_swift/hello_swift_main.swift +++ /dev/null @@ -1,35 +0,0 @@ -/**************************************************************************** - * apps/examples/hello_swift/hello_swift_main.swift - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Name: hello_swift_main - ****************************************************************************/ -func swiftMain() { - print("Hello from Swift embedded!") -} - -// Create a C-compatible entry point -@_cdecl("hello_swift_main") -public func cMain(_ argc: Int32, _ argv: UnsafeMutablePointer<UnsafeMutablePointer<Int8>?>) -> Int32 { - swiftMain() - return 0 -} \ No newline at end of file diff --git a/examples/hello_wasm/CMakeLists.txt b/examples/hello_wasm/CMakeLists.txt deleted file mode 100644 index ecdc6e8e7..000000000 --- a/examples/hello_wasm/CMakeLists.txt +++ /dev/null @@ -1,38 +0,0 @@ -# ############################################################################## -# apps/examples/hello_wasm/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_HELLO_WASM_BUILD_NATIVE) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_HELLO_WASM_PROGNAME} - SRCS - hello_main.c - STACKSIZE - ${CONFIG_EXAMPLES_HELLO_WASM_STACKSIZE} - PRIORITY - ${CONFIG_EXAMPLES_HELLO_WASM_PRIORITY}) -endif() - -if(CONFIG_EXAMPLES_HELLO_WASM_BUILD_WASM) - wasm_add_application(NAME ${CONFIG_EXAMPLES_HELLO_WASM_PROGNAME} SRCS - hello_main.c) -endif() diff --git a/examples/hello_wasm/Kconfig b/examples/hello_wasm/Kconfig deleted file mode 100644 index d4ed93523..000000000 --- a/examples/hello_wasm/Kconfig +++ /dev/null @@ -1,41 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config EXAMPLES_HELLO_WASM - tristate "\"Hello, WebAssembly!\" example" - default n - ---help--- - Enable the \"Hello, WebAssembly!\" example - -if EXAMPLES_HELLO_WASM - -config EXAMPLES_HELLO_WASM_PROGNAME - string "Program name" - default "hello_wasm" - ---help--- - This is the name of the program that will be used when the NSH ELF - program is installed. - -config EXAMPLES_HELLO_WASM__PRIORITY - int "Hello wasm task priority" - default 100 - -config EXAMPLES_HELLO_WASM_STACKSIZE - int "Hello wasm stack size" - default DEFAULT_TASK_STACKSIZE - -config EXAMPLES_HELLO_WASM_BUILD_WASM - bool "Build as WebAssembly module" - default y - ---help--- - Build the WebAssembly binary from the C source code. - -config EXAMPLES_HELLO_WASM_BUILD_NATIVE - bool "Build as native program" - default n - ---help--- - Build the native binary from the C source code. - -endif diff --git a/examples/hello_wasm/Make.defs b/examples/hello_wasm/Make.defs deleted file mode 100644 index 4f780cbbc..000000000 --- a/examples/hello_wasm/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/examples/hello_wasm/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_EXAMPLES_HELLO_WASM),) -CONFIGURED_APPS += $(APPDIR)/examples/hello_wasm -endif diff --git a/examples/hello_wasm/Makefile b/examples/hello_wasm/Makefile deleted file mode 100644 index 1ca45f7c5..000000000 --- a/examples/hello_wasm/Makefile +++ /dev/null @@ -1,44 +0,0 @@ -############################################################################ -# apps/examples/hello_wasm/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -# Hello, World! built-in application info - -PROGNAME = $(CONFIG_EXAMPLES_HELLO_WASM_PROGNAME) -PRIORITY = $(CONFIG_EXAMPLES_HELLO_WASM_PRIORITY) -STACKSIZE = $(CONFIG_EXAMPLES_HELLO_WASM_STACKSIZE) -MODULE = $(CONFIG_EXAMPLES_HELLO_WASM) - -# Hello, World! Example - -MAINSRC = hello_main.c - -# Build with WebAssembly when CONFIG_INTERPRETERS_WAMR is enabled - -WASM_BUILD = y - -# Mode of WebAssembly Micro Runtime - -WAMR_MODE = AOT - -include $(APPDIR)/Application.mk diff --git a/examples/hello_wasm/hello_main.c b/examples/hello_wasm/hello_main.c deleted file mode 100644 index 856f6b4cc..000000000 --- a/examples/hello_wasm/hello_main.c +++ /dev/null @@ -1,41 +0,0 @@ -/**************************************************************************** - * apps/examples/hello_wasm/hello_main.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <stdio.h> - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * hello_main - ****************************************************************************/ - -int main(int argc, FAR char *argv[]) -{ - printf("Hello, WebAssembly!!\n"); - return 0; -} diff --git a/examples/hello_zig/Kconfig b/examples/hello_zig/Kconfig deleted file mode 100644 index b3d1d68a4..000000000 --- a/examples/hello_zig/Kconfig +++ /dev/null @@ -1,29 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config EXAMPLES_HELLO_ZIG - tristate "\"Hello, Zig!\" example" - default n - ---help--- - Enable the \"Hello, Zig!\" example - -if EXAMPLES_HELLO_ZIG - -config EXAMPLES_HELLO_ZIG_PROGNAME - string "Program name" - default "hello_zig" - ---help--- - This is the name of the program that will be used when the - program is installed. - -config EXAMPLES_HELLO_ZIG_PRIORITY - int "Hello Zig task priority" - default 100 - -config EXAMPLES_HELLO_ZIG_STACKSIZE - int "Hello Zig stack size" - default DEFAULT_TASK_STACKSIZE - -endif diff --git a/examples/hello_zig/Make.defs b/examples/hello_zig/Make.defs deleted file mode 100644 index e60bcc7ce..000000000 --- a/examples/hello_zig/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/examples/hello_zig/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_EXAMPLES_HELLO_ZIG),) -CONFIGURED_APPS += $(APPDIR)/examples/hello_zig -endif diff --git a/examples/hello_zig/Makefile b/examples/hello_zig/Makefile deleted file mode 100644 index a1a66d2f8..000000000 --- a/examples/hello_zig/Makefile +++ /dev/null @@ -1,36 +0,0 @@ -############################################################################ -# apps/examples/hello_zig/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -# Hello, Zig! Example - -MAINSRC = hello_zig.zig - -# Hello, Zig! built-in application info -ZIGFLAGS += -lc -I$(TOPDIR)/include -PROGNAME = $(CONFIG_EXAMPLES_HELLO_ZIG_PROGNAME) -PRIORITY = $(CONFIG_EXAMPLES_HELLO_ZIG_PRIORITY) -STACKSIZE = $(CONFIG_EXAMPLES_HELLO_ZIG_STACKSIZE) -MODULE = $(CONFIG_EXAMPLES_HELLO_ZIG) - -include $(APPDIR)/Application.mk diff --git a/examples/hello_zig/hello_zig.zig b/examples/hello_zig/hello_zig.zig deleted file mode 100644 index d3b5dd35d..000000000 --- a/examples/hello_zig/hello_zig.zig +++ /dev/null @@ -1,60 +0,0 @@ -//*************************************************************************** -// examples/hello_zig/hello_zig.zig -// -// SPDX-License-Identifier: Apache-2.0 -// -// Licensed to the Apache Software Foundation (ASF) under one or more -// contributor license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright ownership. The -// ASF licenses this file to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance with the -// License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -// License for the specific language governing permissions and limitations -// under the License. -// -//*************************************************************************** - -//*************************************************************************** -// Included Files -//*************************************************************************** -const std = @import("std"); - -//**************************************************************************** -//* C API - need libc linking (freestanding libc is stubs only) -//**************************************************************************** -// NuttX namespace -const NuttX = struct { - pub const c = @cImport({ - @cInclude("nuttx/config.h"); - @cInclude("stdio.h"); - }); - pub fn print(comptime fmt: [*:0]const u8, args: anytype) void { - _ = printf(std.fmt.comptimePrint(std.mem.span(fmt), args)); - } -}; - -// or (optional) const c = std.c; // from std library (non-full libc) - -// typedef alias -const printf = NuttX.c.printf; -//**************************************************************************** -//* hello_zig_main -//**************************************************************************** -comptime { - // rename to hello_zig_main entry point for nuttx - @export(hello_zig, .{ - .name = "hello_zig_main", - .linkage = .weak, - }); -} - -fn hello_zig(_: c_int, _: ?[*]const [*]const u8) callconv(.C) c_int { - NuttX.print("[{s}]: Hello, Zig!\n", .{NuttX.c.CONFIG_ARCH_BOARD}); - return 0; -} diff --git a/examples/helloxx/CMakeLists.txt b/examples/helloxx/CMakeLists.txt deleted file mode 100644 index 12c27efe2..000000000 --- a/examples/helloxx/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# ############################################################################## -# apps/examples/helloxx/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_HELLOXX) - nuttx_add_application( - NAME - helloxx - STACKSIZE - ${CONFIG_DEFAULT_TASK_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_HELLOXX} - SRCS - helloxx_main.cxx) -endif() diff --git a/examples/helloxx/Make.defs b/examples/helloxx/Make.defs index 318436af9..13fbd567b 100644 --- a/examples/helloxx/Make.defs +++ b/examples/helloxx/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/helloxx/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/helloxx/Makefile b/examples/helloxx/Makefile index a9741277f..30b02cfd1 100644 --- a/examples/helloxx/Makefile +++ b/examples/helloxx/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/helloxx/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/helloxx/helloxx_main.cxx b/examples/helloxx/helloxx_main.cxx index 8df920916..c64891de1 100644 --- a/examples/helloxx/helloxx_main.cxx +++ b/examples/helloxx/helloxx_main.cxx @@ -1,8 +1,6 @@ //*************************************************************************** // apps/examples/helloxx/helloxx_main.cxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -27,7 +25,7 @@ #include <nuttx/config.h> #include <cstdio> -#include <nuttx/debug.h> +#include <debug.h> //*************************************************************************** // Definitions @@ -37,8 +35,8 @@ // Debug ******************************************************************** // Non-standard debug that may be enabled just for testing the constructors -#ifdef CONFIG_DEBUG_FEATURES -# define CONFIG_DEBUG_CXX +#ifndef CONFIG_DEBUG_FEATURES +# undef CONFIG_DEBUG_CXX #endif #ifdef CONFIG_DEBUG_CXX diff --git a/examples/hidkbd/CMakeLists.txt b/examples/hidkbd/CMakeLists.txt deleted file mode 100644 index 90654c581..000000000 --- a/examples/hidkbd/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# ############################################################################## -# apps/examples/hidkbd/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_HIDKBD) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_HIDKBD_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_HIDKBD_DEFPRIO} - STACKSIZE - ${CONFIG_EXAMPLES_HIDKBD_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_HIDKBD} - SRCS - hidkbd_main.c) -endif() diff --git a/examples/hidkbd/Kconfig b/examples/hidkbd/Kconfig index c80d40943..0046c36bd 100644 --- a/examples/hidkbd/Kconfig +++ b/examples/hidkbd/Kconfig @@ -6,7 +6,6 @@ config EXAMPLES_HIDKBD tristate "USB HID keyboard example" default n - depends on USBHOST_HIDKBD ---help--- Enable the USB HID keyboard example diff --git a/examples/hidkbd/Make.defs b/examples/hidkbd/Make.defs index 659cf76da..7868506f9 100644 --- a/examples/hidkbd/Make.defs +++ b/examples/hidkbd/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/hidkbd/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/hidkbd/Makefile b/examples/hidkbd/Makefile index 8532747f3..e216cd11a 100644 --- a/examples/hidkbd/Makefile +++ b/examples/hidkbd/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/hidkbd/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -22,14 +20,14 @@ include $(APPDIR)/Make.defs -# USB Host HID keyboard built-in application info +# USB Host HID keyboard Example PROGNAME = $(CONFIG_EXAMPLES_HIDKBD_PROGNAME) PRIORITY = $(CONFIG_EXAMPLES_HIDKBD_DEFPRIO) STACKSIZE = $(CONFIG_EXAMPLES_HIDKBD_STACKSIZE) MODULE = $(CONFIG_EXAMPLES_HIDKBD) -# USB Host HID keyboard example +# Hello, World! Example MAINSRC = hidkbd_main.c diff --git a/examples/hidkbd/hidkbd_main.c b/examples/hidkbd/hidkbd_main.c index 1515d6526..ac38cde2c 100644 --- a/examples/hidkbd/hidkbd_main.c +++ b/examples/hidkbd/hidkbd_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/hidkbd/hidkbd_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -59,10 +57,49 @@ # undef CONFIG_EXAMPLES_HIDKBD_ENCODED #endif +/**************************************************************************** + * Private Types + ****************************************************************************/ + +#ifdef CONFIG_EXAMPLES_HIDKBD_ENCODED +struct hidbkd_instream_s +{ + struct lib_instream_s stream; + FAR char *buffer; + ssize_t nbytes; +}; +#endif + /**************************************************************************** * Private Functions ****************************************************************************/ +/**************************************************************************** + * Name: hidkbd_getstream + * + * Description: + * Get one character from the keyboard. + * + ****************************************************************************/ + +#ifdef CONFIG_EXAMPLES_HIDKBD_ENCODED +static int hidkbd_getstream(FAR struct lib_instream_s *this) +{ + FAR struct hidbkd_instream_s *kbdstream = \ + (FAR struct hidbkd_instream_s *)this; + + DEBUGASSERT(kbdstream && kbdstream->buffer); + if (kbdstream->nbytes > 0) + { + kbdstream->nbytes--; + kbdstream->stream.nget++; + return (int)*kbdstream->buffer++; + } + + return EOF; +} +#endif + /**************************************************************************** * Name: hidkbd_decode * @@ -74,7 +111,7 @@ #ifdef CONFIG_EXAMPLES_HIDKBD_ENCODED static void hidkbd_decode(FAR char *buffer, ssize_t nbytes) { - struct lib_meminstream_s kbdstream; + struct hidbkd_instream_s kbdstream; struct kbd_getstate_s state; uint8_t ch; int ret; @@ -82,7 +119,10 @@ static void hidkbd_decode(FAR char *buffer, ssize_t nbytes) /* Initialize */ memset(&state, 0, sizeof(struct kbd_getstate_s)); - lib_meminstream(&kbdstream, buffer, nbytes); + kbdstream.stream.get = hidkbd_getstream; + kbdstream.stream.nget = 0; + kbdstream.buffer = buffer; + kbdstream.nbytes = nbytes; /* Loop until all of the bytes have been consumed. We implicitly assume * that the escaped sequences do not cross buffer boundaries. That diff --git a/examples/hts221_reader/CMakeLists.txt b/examples/hts221_reader/CMakeLists.txt deleted file mode 100644 index 70b883a4b..000000000 --- a/examples/hts221_reader/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# ############################################################################## -# apps/examples/hts221_reader/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_HTS221_READER) - nuttx_add_application( - NAME - hts221_reader - STACKSIZE - ${CONFIG_DEFAULT_TASK_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_HTS221_READER} - SRCS - hts221_reader_main.c) -endif() diff --git a/examples/hts221_reader/Make.defs b/examples/hts221_reader/Make.defs index d6577e5b2..5d9c2b52f 100644 --- a/examples/hts221_reader/Make.defs +++ b/examples/hts221_reader/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/hts221_reader/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -20,6 +18,6 @@ # ############################################################################ -ifneq ($(CONFIG_EXAMPLES_HTS221_READER),) +ifeq ($(CONFIG_EXAMPLES_HTS221_READER),y) CONFIGURED_APPS += examples/hts221_reader endif diff --git a/examples/hts221_reader/Makefile b/examples/hts221_reader/Makefile index 90b9cc579..46db8727c 100644 --- a/examples/hts221_reader/Makefile +++ b/examples/hts221_reader/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/hts221_reader/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/hts221_reader/hts221_reader_main.c b/examples/hts221_reader/hts221_reader_main.c index 5c1c39664..f77bbfd88 100644 --- a/examples/hts221_reader/hts221_reader_main.c +++ b/examples/hts221_reader/hts221_reader_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/hts221_reader/hts221_reader_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -32,7 +30,7 @@ #include <errno.h> #include <unistd.h> -#include <nuttx/debug.h> +#include <debug.h> #include <nuttx/sensors/hts221.h> diff --git a/examples/hx711/CMakeLists.txt b/examples/hx711/CMakeLists.txt deleted file mode 100644 index df388c6ae..000000000 --- a/examples/hx711/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# ############################################################################## -# apps/examples/hx711/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_HX711) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_HX711_PROGNAME} - SRCS - hx711_main.c - STACKSIZE - ${CONFIG_EXAMPLES_HX711_STACKSIZE} - PRIORITY - ${CONFIG_EXAMPLES_HX711_PRIORITY}) -endif() diff --git a/examples/hx711/Kconfig b/examples/hx711/Kconfig deleted file mode 100644 index f68a26d12..000000000 --- a/examples/hx711/Kconfig +++ /dev/null @@ -1,32 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config EXAMPLES_HX711 - tristate "HX711 driver example" - default n - select ADC_HX711 - ---help--- - Enable the HX711 example. This program is also useful during - development as it's possible to manipulate and dump hx711 - settings, as well as print conversions to terminal. - -if EXAMPLES_HX711 - -config EXAMPLES_HX711_PROGNAME - string "Program name" - default "hx711" - ---help--- - This is the name of the program that will be used when the NSH ELF - program is installed. - -config EXAMPLES_HX711_PRIORITY - int "hx711 task priority" - default 100 - -config EXAMPLES_HX711_STACKSIZE - int "hx711 stack size" - default DEFAULT_TASK_STACKSIZE - -endif diff --git a/examples/hx711/Make.defs b/examples/hx711/Make.defs deleted file mode 100644 index 2503e5b99..000000000 --- a/examples/hx711/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/examples/hx711/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_EXAMPLES_HX711),) -CONFIGURED_APPS += $(APPDIR)/examples/hx711 -endif diff --git a/examples/hx711/Makefile b/examples/hx711/Makefile deleted file mode 100644 index d68a8767e..000000000 --- a/examples/hx711/Makefile +++ /dev/null @@ -1,36 +0,0 @@ -############################################################################ -# apps/examples/hx711/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -# hx711 built-in application info - -PROGNAME = $(CONFIG_EXAMPLES_HX711_PROGNAME) -PRIORITY = $(CONFIG_EXAMPLES_HX711_PRIORITY) -STACKSIZE = $(CONFIG_EXAMPLES_HX711_STACKSIZE) -MODULE = $(CONFIG_EXAMPLES_HX711) - -# hx711 example - -MAINSRC = hx711_main.c - -include $(APPDIR)/Application.mk diff --git a/examples/hx711/hx711_main.c b/examples/hx711/hx711_main.c deleted file mode 100644 index 3e9f1755c..000000000 --- a/examples/hx711/hx711_main.c +++ /dev/null @@ -1,363 +0,0 @@ -/**************************************************************************** - * apps/examples/hx711/hx711_main.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> -#include <nuttx/analog/hx711.h> - -#include <fcntl.h> -#include <unistd.h> -#include <errno.h> -#include <string.h> -#include <stdio.h> -#include <sys/ioctl.h> - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -struct hx711_config -{ - char dev[32]; - char dump; - char channel; - unsigned char gain; - unsigned average; - unsigned loops; - float precision; - int val_per_unit; - int sign; -} g_hx711_config; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: hx711_print_help - * - * Description: - * Prints help onto stdout. - * - ****************************************************************************/ - -static void hx711_print_help(const char *progname) -{ - printf("usage: %s [-d <device>] [options]\n" - "\n" - "\t-h print this help message\n" - "\t-d<path> path to hx711 device, default: /dev/hx711_0\n" - "\t-t<prec> tares the scale with specified precision, might" - "take few seconds to complete.\n" - "\t If you set value per unit, precision is in units, " - "otherwise it's raw values.\n" - "\t If units are used, float can be passed like 0.1\n" - "\t-v<val> value read that coresponds to one unit. This value " - "has to be\n" - "\t calibrated first before it's known\n" - "\t-s reverse sign, if values decreses when mass increases, " - "pass this\n" - "\t-D dumps current device settings (like, average, channel, " - "gain etc.)\n" - "\t-a<avg> set how many samples should be averaged before " - "returning value,\n" - "\t values [1..%d] are valid\n" - "\t-c<chan> set channel to read (either 'a' or 'b' is valid)\n" - "\t-g<gain> set adc gain, for channel 'a' 64 and 128 are valid,\n" - "\t for channel 'b', only 64 is valid\n" - "\t-r<num> read this number of samples before exiting, samples " - "will be printed\n" - "\t on stdout as string, one sample per line\n" - "\n" - "Check documentation for full description\n", - progname, HX711_MAX_AVG_SAMPLES); -} - -/**************************************************************************** - * Name: hx711_parse_args - * - * Description: - * Parses command line arguments - * - ****************************************************************************/ - -static int hx711_parse_args(int argc, FAR char *argv[]) -{ - int opt; - - memset(&g_hx711_config, 0x00, sizeof(g_hx711_config)); - - while ((opt = getopt(argc, argv, "hd:Dt:a:c:g:r:v:s")) != -1) - { - switch (opt) - { - case 'h': - hx711_print_help(argv[0]); - return 1; - - case 'd': - strcpy(g_hx711_config.dev, optarg); - break; - - case 't': - g_hx711_config.precision = atof(optarg); - break; - - case 'D': - g_hx711_config.dump = 1; - break; - - case 'a': - g_hx711_config.average = atoi(optarg); - break; - - case 'c': - g_hx711_config.channel = optarg[0]; - break; - - case 'g': - g_hx711_config.gain = atoi(optarg); - break; - - case 'r': - g_hx711_config.loops = atoi(optarg); - break; - - case 's': - g_hx711_config.sign = -1; - break; - - case 'v': - g_hx711_config.val_per_unit = atoi(optarg); - break; - - default: - fprintf(stderr, "Invalid option, run with -h for help\n"); - return 1; - } - } - - if (g_hx711_config.dev[0] == '\0') - { - strcpy(g_hx711_config.dev, "/dev/hx711_0"); - } - - return 0; -} - -/**************************************************************************** - * Name: hx711_set_options - * - * Description: - * Set hx711 options if they were specified on command line - * - * Input Parameters: - * fd - opened hx711 instance - * - ****************************************************************************/ - -int hx711_set_options(int fd) -{ - int ret; - - /* Set channel to read */ - - if (g_hx711_config.channel > 0) - { - if ((ret = ioctl(fd, HX711_SET_CHANNEL, g_hx711_config.channel))) - { - fprintf(stderr, "Failed to set channel to %c, error: %s\n", - g_hx711_config.channel, strerror(errno)); - return -1; - } - } - - /* Set channel ADC gain */ - - if (g_hx711_config.gain > 0) - { - if ((ret = ioctl(fd, HX711_SET_GAIN, g_hx711_config.gain))) - { - fprintf(stderr, "Failed to set gain to %d, error: %s\n", - g_hx711_config.gain, strerror(errno)); - return -1; - } - } - - /* Set how many samples to average before printing value */ - - if (g_hx711_config.average > 0) - { - if ((ret = ioctl(fd, HX711_SET_AVERAGE, g_hx711_config.average))) - { - fprintf(stderr, "Failed to set average to %d, error: %s\n", - g_hx711_config.average, strerror(errno)); - return -1; - } - } - - /* Set if sign should be reversed or not */ - - if (g_hx711_config.sign) - { - if ((ret = ioctl(fd, HX711_SET_SIGN, &g_hx711_config.sign))) - { - fprintf(stderr, "Failed to set sign to %d, error: %s\n", - g_hx711_config.sign, strerror(errno)); - return -1; - } - } - - /* Set what value coresponds to 1 unit */ - - if (g_hx711_config.val_per_unit > 0) - { - if ((ret = ioctl(fd, HX711_SET_VAL_PER_UNIT, - g_hx711_config.val_per_unit))) - { - fprintf(stderr, "Failed to set val per unit to %d, error: %s\n", - g_hx711_config.val_per_unit, strerror(errno)); - return -1; - } - } - - return 0; -} - -/**************************************************************************** - * Name: hx711_dump_options - * - * Description: - * Reads current hx711 settings from kernel driver and dumps them on stdout - * - ****************************************************************************/ - -static void hx711_dump_options(int fd) -{ - unsigned average; - unsigned char gain; - char channel; - unsigned val_per_unit; - - ioctl(fd, HX711_GET_GAIN, &gain); - ioctl(fd, HX711_GET_CHANNEL, &channel); - ioctl(fd, HX711_GET_AVERAGE, &average); - ioctl(fd, HX711_GET_VAL_PER_UNIT, &val_per_unit); - - printf("Current settings for: %s\n", g_hx711_config.dev); - printf("average.............: %u\n", average); - printf("channel.............: %c\n", channel); - printf("gain................: %d\n", gain); - printf("value per unit......: %u\n", val_per_unit); -} - -/**************************************************************************** - * Name: hx711_read_and_dump - * - * Description: - * Reads configured number of samples, and dumps them to terminal. - * - ****************************************************************************/ - -static int hx711_read_and_dump(int fd) -{ - int32_t sample; - - while (g_hx711_config.loops--) - { - if (read(fd, &sample, sizeof(sample)) != sizeof(sample)) - { - fprintf(stderr, "Error reading from %s, error %s\n", - g_hx711_config.dev, strerror(errno)); - return -1; - } - - printf("%"PRId32"\n", sample); - } - - return 0; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * hx711 - ****************************************************************************/ - -int main(int argc, FAR char *argv[]) -{ - int fd; - - if (hx711_parse_args(argc, argv)) - { - return 1; - } - - fd = open(g_hx711_config.dev, O_RDONLY); - if (fd < 0) - { - fprintf(stderr, "Failed to open %s, error: %s\n", g_hx711_config.dev, - strerror(errno)); - return 1; - } - - if (hx711_set_options(fd)) - { - close(fd); - return 1; - } - - if (g_hx711_config.precision) - { - ioctl(fd, HX711_GET_VAL_PER_UNIT, &g_hx711_config.val_per_unit); - - if (g_hx711_config.val_per_unit) - { - printf("Taring with %fg precision\n", g_hx711_config.precision); - } - - if (ioctl(fd, HX711_TARE, &g_hx711_config.precision)) - { - perror("Failed to tare the scale"); - close(fd); - return 1; - } - } - - if (g_hx711_config.dump) - { - hx711_dump_options(fd); - } - - if (g_hx711_config.loops) - { - hx711_read_and_dump(fd); - } - - close(fd); - return 0; -} diff --git a/examples/i2schar/CMakeLists.txt b/examples/i2schar/CMakeLists.txt deleted file mode 100644 index 003a13e98..000000000 --- a/examples/i2schar/CMakeLists.txt +++ /dev/null @@ -1,39 +0,0 @@ -# ############################################################################## -# apps/examples/i2schar/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_I2SCHAR) - nuttx_add_application( - NAME - i2schar - STACKSIZE - ${CONFIG_DEFAULT_TASK_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_I2SCHAR} - SRCS - i2schar_main.c) - if(CONFIG_EXAMPLES_I2SCHAR_TX) - target_sources(apps PRIVATE i2schar_transmitter.c) - endif() - if(CONFIG_EXAMPLES_I2SCHAR_RX) - target_sources(apps PRIVATE i2schar_receiver.c) - endif() -endif() diff --git a/examples/i2schar/Make.defs b/examples/i2schar/Make.defs index a4add3ee8..eb17a38b4 100644 --- a/examples/i2schar/Make.defs +++ b/examples/i2schar/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/i2schar/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/i2schar/Makefile b/examples/i2schar/Makefile index 6f4ad7de2..8a312abcd 100644 --- a/examples/i2schar/Makefile +++ b/examples/i2schar/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/i2schar/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/i2schar/i2schar.h b/examples/i2schar/i2schar.h index 73e9f6ea3..ed140e6e7 100644 --- a/examples/i2schar/i2schar.h +++ b/examples/i2schar/i2schar.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/i2schar/i2schar.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -73,7 +71,7 @@ #endif #ifndef CONFIG_EXAMPLES_I2SCHAR_BUFSIZE -# define CONFIG_EXAMPLES_I2SCHAR_BUFSIZE 256 +# efine CONFIG_EXAMPLES_I2SCHAR_BUFSIZE 256 #endif /**************************************************************************** @@ -83,7 +81,6 @@ struct i2schar_state_s { bool initialized; - bool loopback; FAR char *devpath; #ifdef CONFIG_EXAMPLES_I2SCHAR_TX int txcount; diff --git a/examples/i2schar/i2schar_main.c b/examples/i2schar/i2schar_main.c index 176def927..71d590ced 100644 --- a/examples/i2schar/i2schar_main.c +++ b/examples/i2schar/i2schar_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/i2schar/i2schar_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -33,11 +31,7 @@ #include <string.h> #include <pthread.h> #include <errno.h> -#include <nuttx/debug.h> -#include <fcntl.h> -#include <sys/ioctl.h> -#include <nuttx/audio/audio.h> -#include <nuttx/audio/i2s.h> +#include <debug.h> #include "i2schar.h" @@ -95,18 +89,12 @@ static void i2schar_help(FAR struct i2schar_state_s *i2schar) printf("Usage: i2schar [OPTIONS]\n"); printf("\nArguments are \"sticky\".\n"); printf("For example, once the I2C character device is\n"); - printf("specified, that device will be reused until it is changed.\n"); + printf("specified, that device will be re-used until it is changed.\n"); printf("\n\"sticky\" OPTIONS include:\n"); printf(" [-p devpath] selects the I2C character device path. " "Default: %s Current: %s\n", CONFIG_EXAMPLES_I2SCHAR_DEVPATH, g_i2schar.devpath ? g_i2schar.devpath : "NONE"); -#if defined(CONFIG_EXAMPLES_I2SCHAR_TX) && defined(CONFIG_EXAMPLES_I2SCHAR_RX) - printf(" [-l [0|1]] enables/disables loopback mode " - "(0=disable, 1=enable, no value=enable). " - "Default: disabled Current: %s\n", - g_i2schar.loopback ? "enabled" : "disabled"); -#endif #ifdef CONFIG_EXAMPLES_I2SCHAR_TX printf(" [-t count] selects the number of audio buffers to send. " "Default: %d Current: %d\n", @@ -185,81 +173,8 @@ static void parse_args(FAR struct i2schar_state_s *i2schar, index += nargs; break; -#if defined(CONFIG_EXAMPLES_I2SCHAR_TX) && defined(CONFIG_EXAMPLES_I2SCHAR_RX) - case 'l': - - /* Check if a value is provided */ - - if (ptr[2] == '\0' && index + 1 < argc && - argv[index + 1][0] != '-') - { - /* Value provided as next argument */ - - long loopback = strtol(argv[index + 1], NULL, 10); - - if (loopback == 0) - { - i2schar->loopback = false; - } - else if (loopback == 1) - { - i2schar->loopback = true; - } - else - { - printf("Invalid loopback value: %ld (must be 0 or 1)\n", - loopback); - exit(1); - } - - index += 2; - } - else if (ptr[2] == '\0') - { - /* No value provided, default to enable */ - - i2schar->loopback = true; - index += 1; - } - - else - { - /* Value provided as part of the same argument */ - - long loopback = strtol(&ptr[2], NULL, 10); - - if (loopback == 0) - { - i2schar->loopback = false; - } - else if (loopback == 1) - { - i2schar->loopback = true; - } - else - { - printf("Invalid loopback value: %ld (must be 0 or 1)\n", - loopback); - exit(1); - } - - index += 1; - } - break; -#endif - #ifdef CONFIG_EXAMPLES_I2SCHAR_RX case 'r': -#if defined(CONFIG_EXAMPLES_I2SCHAR_TX) && defined(CONFIG_EXAMPLES_I2SCHAR_RX) - if (i2schar->loopback) - { - printf("i2schar_main: Warning: -r argument " - "ignored in loopback mode\n"); - index += 1; - break; - } -#endif - nargs = arg_decimal(&argv[index], &value); if (value < 0) { @@ -274,16 +189,6 @@ static void parse_args(FAR struct i2schar_state_s *i2schar, #ifdef CONFIG_EXAMPLES_I2SCHAR_TX case 't': -#if defined(CONFIG_EXAMPLES_I2SCHAR_TX) && defined(CONFIG_EXAMPLES_I2SCHAR_RX) - if (i2schar->loopback) - { - printf("i2schar_main: Warning: -t argument " - "ignored in loopback mode\n"); - index += 1; - break; - } -#endif - nargs = arg_decimal(&argv[index], &value); if (value < 0) { @@ -307,106 +212,6 @@ static void parse_args(FAR struct i2schar_state_s *i2schar, } } } - -#ifdef CONFIG_EXAMPLES_I2SCHAR_TX - -/**************************************************************************** - * Name: i2schar_prepare_tx_buffer - ****************************************************************************/ - -static struct ap_buffer_s *i2schar_prepare_tx_buffer(uint32_t data_width) -{ - FAR struct ap_buffer_s *apb; - struct audio_buf_desc_s desc; - int ret; - int j; - uint32_t crap = 0; - - /* Allocate an audio buffer of the configured size */ - - desc.numbytes = CONFIG_EXAMPLES_I2SCHAR_BUFSIZE; - desc.u.pbuffer = &apb; - - ret = apb_alloc(&desc); - if (ret < 0) - { - printf("i2schar_prepare_tx_buffer: ERROR: failed to " - "allocate buffer: %d\n", ret); - return NULL; - } - - /* Fill the audio buffer with sequential data based on data width */ - - if (data_width == 8) - { - uint8_t *ptr8 = (uint8_t *)apb->samp; - - /* 8-bit data: fill with sequential bytes */ - - for (j = 0; j < CONFIG_EXAMPLES_I2SCHAR_BUFSIZE; j++) - { - *ptr8++ = crap++; - } - } - else if (data_width == 16) - { - /* 16-bit data: fill with sequential 16-bit values */ - - uint16_t *ptr16 = (uint16_t *)apb->samp; - int samples_16bit = CONFIG_EXAMPLES_I2SCHAR_BUFSIZE / 2; - for (j = 0; j < samples_16bit; j++) - { - *ptr16++ = crap++; - } - } - else if (data_width == 24) - { - /* 24-bit data: fill with sequential 24-bit values (3 bytes each) */ - - uint8_t *ptr8 = apb->samp; - int samples_24bit = CONFIG_EXAMPLES_I2SCHAR_BUFSIZE / 3; - for (j = 0; j < samples_24bit; j++) - { - /* Store 24-bit value in little-endian format */ - - *ptr8++ = crap & 0xff; - *ptr8++ = (crap >> 8) & 0xff; - *ptr8++ = (crap >> 16) & 0xff; - crap++; - } - } - else if (data_width == 32) - { - /* 32-bit data: fill with sequential 32-bit values */ - - uint32_t *ptr32 = (uint32_t *)apb->samp; - int samples_32bit = CONFIG_EXAMPLES_I2SCHAR_BUFSIZE / 4; - for (j = 0; j < samples_32bit; j++) - { - *ptr32++ = crap++; - } - } - else - { - uint8_t *ptr = (uint8_t *)apb->samp; - - /* Unknown data width, fall back to byte-by-byte */ - - printf("i2schar_prepare_tx_buffer: Unknown data width %"PRIu32", " - "using byte mode\n", data_width); - for (j = 0, ptr = apb->samp; j < CONFIG_EXAMPLES_I2SCHAR_BUFSIZE; j++) - { - *ptr++ = crap++; - } - } - - apb->nbytes = CONFIG_EXAMPLES_I2SCHAR_BUFSIZE; - - printf("i2schar_prepare_tx_buffer: Prepared transmitter buffer " - "with %"PRIu32"-bit data\n", data_width); - - return apb; -} #endif /**************************************************************************** @@ -423,7 +228,6 @@ int main(int argc, FAR char *argv[]) pthread_addr_t result; #ifdef CONFIG_EXAMPLES_I2SCHAR_TX pthread_t transmitter; - int fd; #endif #ifdef CONFIG_EXAMPLES_I2SCHAR_RX pthread_t receiver; @@ -431,8 +235,6 @@ int main(int argc, FAR char *argv[]) #if defined(CONFIG_EXAMPLES_I2SCHAR_RX) & defined(CONFIG_EXAMPLES_I2SCHAR_TX) struct sched_param param; #endif - FAR struct ap_buffer_s *transmitter_apb = NULL; - uint32_t data_width = 16; /* Default data width */ int ret; UNUSED(ret); @@ -466,10 +268,6 @@ int main(int argc, FAR char *argv[]) g_i2schar.rxcount = CONFIG_EXAMPLES_I2SCHAR_RXBUFFERS; #endif -#if defined(CONFIG_EXAMPLES_I2SCHAR_TX) && defined(CONFIG_EXAMPLES_I2SCHAR_RX) - g_i2schar.loopback = false; /* Default to disabled */ -#endif - g_i2schar.initialized = true; } @@ -477,66 +275,6 @@ int main(int argc, FAR char *argv[]) parse_args(&g_i2schar, argc, argv); -#ifdef CONFIG_EXAMPLES_I2SCHAR_TX - - /* Get I2S configuration parameters to set data width */ - - fd = open(g_i2schar.devpath, O_RDONLY); - if (fd >= 0) - { - ret = ioctl(fd, I2SIOC_GTXDATAWIDTH, (unsigned long)&data_width); - if (ret >= 0) - { - printf("i2schar_main: TX data width: %" PRIu32 " bits\n", - data_width); - } - else - { - printf("i2schar_main: Failed to get TX data width: %d\n", ret); - printf("i2schar_main: Using default data width: %" PRIu32 " " - "bits\n", data_width); - } - - close(fd); - } - else - { - printf("i2schar_main: Failed to open device for data width query: " - "%d\n", errno); - printf("i2schar_main: Using default data width: %" PRIu32 " bits\n", - data_width); - } - - /* Always prepare the transmitter buffer when transmitter is enabled */ - - transmitter_apb = i2schar_prepare_tx_buffer(data_width); - - if (transmitter_apb == NULL) - { - printf("i2schar_main: ERROR: failed to prepare transmitter buffer\n"); - return EXIT_FAILURE; - } -#endif - -#if defined(CONFIG_EXAMPLES_I2SCHAR_TX) && defined(CONFIG_EXAMPLES_I2SCHAR_RX) - - /* Handle loopback mode */ - - if (g_i2schar.loopback) - { - printf("i2schar_main: Loopback mode enabled\n"); - - /* In loopback mode, we only send/receive one buffer each */ - - g_i2schar.txcount = 1; - g_i2schar.rxcount = 1; - } - else - { - printf("i2schar_main: Loopback mode disabled\n"); - } -#endif - sched_lock(); #ifdef CONFIG_EXAMPLES_I2SCHAR_RX /* Start the receiver thread */ @@ -562,9 +300,7 @@ int main(int argc, FAR char *argv[]) /* Start the receiver */ - ret = pthread_create(&receiver, &attr, i2schar_receiver, - g_i2schar.loopback ? \ - (pthread_addr_t)transmitter_apb : NULL); + ret = pthread_create(&receiver, &attr, i2schar_receiver, NULL); if (ret != OK) { sched_unlock(); @@ -588,8 +324,7 @@ int main(int argc, FAR char *argv[]) /* Start the transmitter */ - ret = pthread_create(&transmitter, &attr, i2schar_transmitter, - (pthread_addr_t)transmitter_apb); + ret = pthread_create(&transmitter, &attr, i2schar_transmitter, NULL); if (ret != OK) { sched_unlock(); @@ -613,13 +348,6 @@ int main(int argc, FAR char *argv[]) { printf("i2schar_main: ERROR: pthread_join failed: %d\n", ret); } -#if defined(CONFIG_EXAMPLES_I2SCHAR_TX) && defined(CONFIG_EXAMPLES_I2SCHAR_RX) - else if (g_i2schar.loopback && result != NULL) - { - printf("i2schar_main: ERROR: Loopback verification failed\n"); - ret = EXIT_FAILURE; - } -#endif #endif #ifdef CONFIG_EXAMPLES_I2SCHAR_RX @@ -629,23 +357,7 @@ int main(int argc, FAR char *argv[]) { printf("i2schar_main: ERROR: pthread_join failed: %d\n", ret); } -#if defined(CONFIG_EXAMPLES_I2SCHAR_TX) && defined(CONFIG_EXAMPLES_I2SCHAR_RX) - else if (g_i2schar.loopback && result != NULL) - { - printf("i2schar_main: ERROR: Loopback verification failed\n"); - ret = EXIT_FAILURE; - } -#endif #endif -#ifdef CONFIG_EXAMPLES_I2SCHAR_TX - /* Clean up transmitter buffer if it was allocated */ - - if (transmitter_apb != NULL) - { - apb_free(transmitter_apb); - } -#endif - - return ret; + return EXIT_SUCCESS; } diff --git a/examples/i2schar/i2schar_receiver.c b/examples/i2schar/i2schar_receiver.c index e088bee9f..8bff12c93 100644 --- a/examples/i2schar/i2schar_receiver.c +++ b/examples/i2schar/i2schar_receiver.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/i2schar/i2schar_receiver.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -31,9 +29,7 @@ #include <fcntl.h> #include <pthread.h> #include <errno.h> -#include <nuttx/debug.h> -#include <unistd.h> -#include <string.h> +#include <debug.h> #include <nuttx/audio/audio.h> @@ -80,15 +76,12 @@ pthread_addr_t i2schar_receiver(pthread_addr_t arg) { FAR struct ap_buffer_s *apb; - FAR struct ap_buffer_s *transmitter_apb = (FAR struct ap_buffer_s *)arg; struct audio_buf_desc_s desc; int bufsize; int nread; int ret; int fd; int i; - int j; - bool loopback = (transmitter_apb != NULL); /* Open the I2C character device */ @@ -103,9 +96,9 @@ pthread_addr_t i2schar_receiver(pthread_addr_t arg) /* Loop for the requested number of times */ - for (i = 0; i < g_i2schar.rxcount; i++) + for (i = 0; i < CONFIG_EXAMPLES_I2SCHAR_TXBUFFERS; i++) { - /* Allocate an audio buffer of the configured size for receiving data */ + /* Allocate an audio buffer of the configured size */ desc.numbytes = CONFIG_EXAMPLES_I2SCHAR_BUFSIZE; desc.u.pbuffer = &apb; @@ -122,13 +115,7 @@ pthread_addr_t i2schar_receiver(pthread_addr_t arg) bufsize = sizeof(struct ap_buffer_s) + CONFIG_EXAMPLES_I2SCHAR_BUFSIZE; - if (loopback) - { - printf("i2schar_receiver: Using allocated buffer for " - "loopback verification\n"); - } - - /* Then receive into the buffer */ + /* Then receifve into the buffer */ do { @@ -147,7 +134,6 @@ pthread_addr_t i2schar_receiver(pthread_addr_t arg) printf("i2schar_receiver: ERROR: read failed: %d\n", errcode); close(fd); - apb_free(apb); pthread_exit(NULL); } } @@ -156,7 +142,6 @@ pthread_addr_t i2schar_receiver(pthread_addr_t arg) printf("i2schar_receiver: ERROR: partial read: %d\n", nread); close(fd); - apb_free(apb); pthread_exit(NULL); } else @@ -166,51 +151,6 @@ pthread_addr_t i2schar_receiver(pthread_addr_t arg) } while (nread != bufsize); - /* Print received buffer data (first 16 bytes) regardless of mode */ - - printf("i2schar_receiver: Received data (first 16 bytes): "); - for (j = 0; j < 16 && j < CONFIG_EXAMPLES_I2SCHAR_BUFSIZE; j++) - { - printf("0x%02x ", ((uint8_t *)apb->samp)[j]); - } - - printf("\n"); - - /* Verify the received data in loopback mode */ - - if (loopback) - { - /* Compare the received data with the expected transmitter buffer */ - - if (memcmp(apb->samp, transmitter_apb->samp, - CONFIG_EXAMPLES_I2SCHAR_BUFSIZE) == 0) - { - printf("i2schar_receiver: Loopback verification PASSED - " - "data matches expected\n"); - } - else - { - printf("i2schar_receiver: Loopback verification FAILED - " - "data mismatch!\n"); - printf("i2schar_receiver: Expected data (first 16 bytes): "); - for (j = 0; - j < 16 && j < CONFIG_EXAMPLES_I2SCHAR_BUFSIZE; j++) - { - printf("0x%02x ", - ((uint8_t *)transmitter_apb->samp)[j]); - } - - printf("\n"); - close(fd); - apb_free(apb); - pthread_exit((pthread_addr_t)1); /* Return error */ - } - } - - /* Free the buffer after use */ - - apb_free(apb); - /* Make sure that the transmitter thread has a chance to run */ pthread_yield(); diff --git a/examples/i2schar/i2schar_transmitter.c b/examples/i2schar/i2schar_transmitter.c index 14e4ec347..f7173c80f 100644 --- a/examples/i2schar/i2schar_transmitter.c +++ b/examples/i2schar/i2schar_transmitter.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/i2schar/i2schar_transmitter.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -31,9 +29,7 @@ #include <fcntl.h> #include <pthread.h> #include <errno.h> -#include <nuttx/debug.h> -#include <unistd.h> -#include <sys/ioctl.h> +#include <debug.h> #include <nuttx/audio/audio.h> @@ -80,13 +76,17 @@ pthread_addr_t i2schar_transmitter(pthread_addr_t arg) { FAR struct ap_buffer_s *apb; - FAR struct ap_buffer_s *transmitter_apb = (FAR struct ap_buffer_s *)arg; + struct audio_buf_desc_s desc; + uint8_t crap; + uint8_t *ptr; int bufsize; int nwritten; + int ret; int fd; int i; + int j; - /* Open the I2S character device */ + /* Open the I2C character device */ fd = open(g_i2schar.devpath, O_WRONLY); if (fd < 0) @@ -99,13 +99,34 @@ pthread_addr_t i2schar_transmitter(pthread_addr_t arg) /* Loop for the requested number of times */ - for (i = 0; i < g_i2schar.txcount; i++) + for (i = 0, crap = 0; i < CONFIG_EXAMPLES_I2SCHAR_TXBUFFERS; i++) { - /* Use the provided transmitter buffer */ + /* Allocate an audio buffer of the configured size */ + + desc.numbytes = CONFIG_EXAMPLES_I2SCHAR_BUFSIZE; + desc.u.pbuffer = &apb; + + ret = apb_alloc(&desc); + if (ret < 0) + { + printf(" + i2schar_transmitter: ERROR: failed to allocate buffer %d: %d\n", + i + 1, ret); + close(fd); + pthread_exit(NULL); + } - apb = transmitter_apb; bufsize = sizeof(struct ap_buffer_s) + CONFIG_EXAMPLES_I2SCHAR_BUFSIZE; + /* Fill the audio buffer with crap */ + + for (j = 0, ptr = apb->samp; j < CONFIG_EXAMPLES_I2SCHAR_BUFSIZE; j++) + { + *ptr++ = crap++; + } + + apb->nbytes = CONFIG_EXAMPLES_I2SCHAR_BUFSIZE; + /* Then send the buffer */ do diff --git a/examples/i2sloop/CMakeLists.txt b/examples/i2sloop/CMakeLists.txt deleted file mode 100644 index c1d64f136..000000000 --- a/examples/i2sloop/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# ############################################################################## -# apps/examples/i2sloop/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_I2SLOOP) - nuttx_add_application( - NAME - i2sloop - STACKSIZE - ${CONFIG_DEFAULT_TASK_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_I2SLOOP} - SRCS - i2sloop_main.c) -endif() diff --git a/examples/i2sloop/Kconfig b/examples/i2sloop/Kconfig index 982c0b020..cea8333cd 100644 --- a/examples/i2sloop/Kconfig +++ b/examples/i2sloop/Kconfig @@ -6,6 +6,6 @@ config EXAMPLES_I2SLOOP tristate "I2S loopback test" default n - depends on I2S && AUDIO && DRIVERS_AUDIO && AUDIO_I2SCHAR && ENABLE_ALL_SIGNALS + depends on I2S && AUDIO && DRIVERS_AUDIO && AUDIO_I2SCHAR ---help--- Enable the I2S loopback test diff --git a/examples/i2sloop/Make.defs b/examples/i2sloop/Make.defs index 97c751df4..6f72f5fcb 100644 --- a/examples/i2sloop/Make.defs +++ b/examples/i2sloop/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/i2sloop/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/i2sloop/Makefile b/examples/i2sloop/Makefile index fb5b56255..d3341ac2f 100644 --- a/examples/i2sloop/Makefile +++ b/examples/i2sloop/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/i2sloop/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/i2sloop/i2sloop_main.c b/examples/i2sloop/i2sloop_main.c index a84c8254c..a6279c3dd 100644 --- a/examples/i2sloop/i2sloop_main.c +++ b/examples/i2sloop/i2sloop_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/i2sloop/i2sloop_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -36,7 +34,6 @@ #include <string.h> #include <assert.h> #include <signal.h> -#include <unistd.h> /**************************************************************************** * Private Data diff --git a/examples/igmp/CMakeLists.txt b/examples/igmp/CMakeLists.txt deleted file mode 100644 index f02381f81..000000000 --- a/examples/igmp/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# ############################################################################## -# apps/examples/igmp/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_IGMP) - nuttx_add_application( - NAME - igmp - STACKSIZE - ${CONFIG_DEFAULT_TASK_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_IGMP} - SRCS - igmp.c) -endif() diff --git a/examples/igmp/Make.defs b/examples/igmp/Make.defs index 1f839cc9e..5ce9853f3 100644 --- a/examples/igmp/Make.defs +++ b/examples/igmp/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/igmp/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/igmp/Makefile b/examples/igmp/Makefile index 9dbec79ca..4fc9fef01 100644 --- a/examples/igmp/Makefile +++ b/examples/igmp/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/igmp/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/igmp/igmp.c b/examples/igmp/igmp.c index 7da32c680..4822227cc 100644 --- a/examples/igmp/igmp.c +++ b/examples/igmp/igmp.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/igmp/igmp.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -29,7 +27,7 @@ #include <stdint.h> #include <stdio.h> #include <unistd.h> -#include <nuttx/debug.h> +#include <debug.h> #include <arpa/inet.h> #include <net/if.h> diff --git a/examples/igmp/igmp.h b/examples/igmp/igmp.h index 3cf99b1b0..3d9ac6466 100644 --- a/examples/igmp/igmp.h +++ b/examples/igmp/igmp.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/igmp/igmp.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -27,7 +25,7 @@ * Included Files ****************************************************************************/ -#include <nuttx/debug.h> +#include <debug.h> /**************************************************************************** * Pre-processor Definitions diff --git a/examples/ina219/CMakeLists.txt b/examples/ina219/CMakeLists.txt deleted file mode 100644 index 451ddffaf..000000000 --- a/examples/ina219/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# ############################################################################## -# apps/examples/ina219/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_INA219) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_INA219_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_INA219_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_INA219_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_INA219} - SRCS - ina219_main.c) -endif() diff --git a/examples/ina219/Kconfig b/examples/ina219/Kconfig index bdb3a2561..c5fd86059 100644 --- a/examples/ina219/Kconfig +++ b/examples/ina219/Kconfig @@ -6,7 +6,6 @@ config EXAMPLES_INA219 tristate "INA219 example" default n - depends on SENSORS_INA219 ---help--- Enable the INA219 example diff --git a/examples/ina219/Make.defs b/examples/ina219/Make.defs index 29ae967e0..4aad654d6 100644 --- a/examples/ina219/Make.defs +++ b/examples/ina219/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/ina219/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/ina219/Makefile b/examples/ina219/Makefile index 5580850fe..0b84d9f90 100644 --- a/examples/ina219/Makefile +++ b/examples/ina219/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/ina219/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -22,14 +20,14 @@ include $(APPDIR)/Make.defs -# INA219 built-in application info +# Hello, World! built-in application info PROGNAME = $(CONFIG_EXAMPLES_INA219_PROGNAME) PRIORITY = $(CONFIG_EXAMPLES_INA219_PRIORITY) STACKSIZE = $(CONFIG_EXAMPLES_INA219_STACKSIZE) MODULE = $(CONFIG_EXAMPLES_INA219) -# INA219 Example +# Hello, World! Example MAINSRC = ina219_main.c diff --git a/examples/ina219/ina219_main.c b/examples/ina219/ina219_main.c index ddb4ce5ab..a82064ceb 100644 --- a/examples/ina219/ina219_main.c +++ b/examples/ina219/ina219_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/ina219/ina219_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/ina226/CMakeLists.txt b/examples/ina226/CMakeLists.txt deleted file mode 100644 index 1e34b2659..000000000 --- a/examples/ina226/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# ############################################################################## -# apps/examples/ina226/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_INA226) - nuttx_add_application( - NAME - ina226 - SRCS - ina226_main.c - STACKSIZE - ${CONFIG_EXAMPLES_INA226_STACKSIZE} - PRIORITY - ${CONFIG_EXAMPLES_INA226_PRIORITY}) -endif() diff --git a/examples/ina226/Kconfig b/examples/ina226/Kconfig index 55e24b0e8..289b30b5b 100644 --- a/examples/ina226/Kconfig +++ b/examples/ina226/Kconfig @@ -6,7 +6,6 @@ config EXAMPLES_INA226 tristate "INA226 example" default n - depends on SENSORS_INA226 ---help--- Enable the INA226 example diff --git a/examples/ina226/Make.defs b/examples/ina226/Make.defs index a335ce5c0..980fd358a 100644 --- a/examples/ina226/Make.defs +++ b/examples/ina226/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/ina226/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/ina226/Makefile b/examples/ina226/Makefile index 46efa9d1c..cb2e2601c 100644 --- a/examples/ina226/Makefile +++ b/examples/ina226/Makefile @@ -1,7 +1,5 @@ ############################################################################ -# apps/examples/ina226/Makefile -# -# SPDX-License-Identifier: Apache-2.0 +# apps/examples/ina219/Makefile # # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with diff --git a/examples/ina226/ina226_main.c b/examples/ina226/ina226_main.c index 6a73f6cbb..e760397b5 100644 --- a/examples/ina226/ina226_main.c +++ b/examples/ina226/ina226_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/ina226/ina226_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -26,7 +24,6 @@ #include <errno.h> #include <fcntl.h> -#include <inttypes.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> @@ -73,8 +70,7 @@ int main(int argc, FAR char *argv[]) break; } - printf("U=%12"PRIu32 "uV I=%12"PRIi32 "uA\n", sample.voltage, - sample.current); + printf("U=%12u uV I=%12d uA\n", sample.voltage, sample.current); usleep(500000); } diff --git a/examples/ini_dumper/CMakeLists.txt b/examples/ini_dumper/CMakeLists.txt deleted file mode 100644 index e6cf93929..000000000 --- a/examples/ini_dumper/CMakeLists.txt +++ /dev/null @@ -1,37 +0,0 @@ -# ############################################################################## -# apps/examples/ini_dumper/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_INI_DUMPER) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_INI_DUMPER_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_INI_DUMPER_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_INI_DUMPER_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_INI_DUMPER} - SRCS - ini_dumper_main.c - COMPILE_FLAGS - -DINI_HANDLER_LINENO=1) -endif() diff --git a/examples/ini_dumper/Make.defs b/examples/ini_dumper/Make.defs index 2c92065a8..f83e58fdb 100644 --- a/examples/ini_dumper/Make.defs +++ b/examples/ini_dumper/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/ini_dumper/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/ini_dumper/Makefile b/examples/ini_dumper/Makefile index cecc252ab..fdd362a3d 100644 --- a/examples/ini_dumper/Makefile +++ b/examples/ini_dumper/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/ini_dumper/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/ini_dumper/ini_dumper_main.c b/examples/ini_dumper/ini_dumper_main.c index 8f3e2ca76..7f950e1f5 100644 --- a/examples/ini_dumper/ini_dumper_main.c +++ b/examples/ini_dumper/ini_dumper_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/ini_dumper/ini_dumper_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/ipcfg/CMakeLists.txt b/examples/ipcfg/CMakeLists.txt deleted file mode 100644 index ab57dcd6d..000000000 --- a/examples/ipcfg/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# ############################################################################## -# apps/examples/ipcfg/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_IPCFG) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_IPCFG_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_IPCFG_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_IPCFG_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_IPCFG} - SRCS - ipcfg_main.c) -endif() diff --git a/examples/ipcfg/Make.defs b/examples/ipcfg/Make.defs index 6dc082db0..1a54ae6f8 100644 --- a/examples/ipcfg/Make.defs +++ b/examples/ipcfg/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/ipcfg/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/ipcfg/Makefile b/examples/ipcfg/Makefile index fe8231880..82c6b018c 100644 --- a/examples/ipcfg/Makefile +++ b/examples/ipcfg/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/ipcfg/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/ipcfg/ipcfg_main.c b/examples/ipcfg/ipcfg_main.c index 51c411081..3428daa92 100644 --- a/examples/ipcfg/ipcfg_main.c +++ b/examples/ipcfg/ipcfg_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/ipcfg/ipcfg_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -30,8 +28,7 @@ #include <stdio.h> #include <stdlib.h> #include <fcntl.h> -#include <nuttx/debug.h> -#include <unistd.h> +#include <debug.h> #include <arpa/inet.h> @@ -285,10 +282,7 @@ static void ipcfg_dump_ipv4addr(FAR const char *variable, in_addr_t address) address }; - char inetaddr[INET_ADDRSTRLEN]; - - printf("%s%s\n", variable, - inet_ntoa_r(saddr, inetaddr, sizeof(inetaddr))); + printf("%s%s\n", variable, inet_ntoa(saddr)); } } #endif diff --git a/examples/ipforward/CMakeLists.txt b/examples/ipforward/CMakeLists.txt deleted file mode 100644 index 350da02db..000000000 --- a/examples/ipforward/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# ############################################################################## -# apps/examples/ipforward/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_IPFORWARD) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_IPFORWARD_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_IPFORWARD_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_IPFORWARD_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_IPFORWARD} - SRCS - ipforward.c) -endif() diff --git a/examples/ipforward/Make.defs b/examples/ipforward/Make.defs index 42f55108f..51f4e5da9 100644 --- a/examples/ipforward/Make.defs +++ b/examples/ipforward/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/ipforward/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/ipforward/Makefile b/examples/ipforward/Makefile index 1a5c2a909..890e7cf07 100644 --- a/examples/ipforward/Makefile +++ b/examples/ipforward/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/ipforward/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -22,14 +20,14 @@ include $(APPDIR)/Make.defs -# IPFORWARD built-in application info +# Hello, World! built-in application info PROGNAME = $(CONFIG_EXAMPLES_IPFORWARD_PROGNAME) PRIORITY = $(CONFIG_EXAMPLES_IPFORWARD_PRIORITY) STACKSIZE = $(CONFIG_EXAMPLES_IPFORWARD_STACKSIZE) MODULE = $(CONFIG_EXAMPLES_IPFORWARD) -# IPFORWARD Example +# Hello, World! Example MAINSRC = ipforward.c diff --git a/examples/ipforward/ipforward.c b/examples/ipforward/ipforward.c index ae9ee5831..b6e082b11 100644 --- a/examples/ipforward/ipforward.c +++ b/examples/ipforward/ipforward.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/ipforward/ipforward.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -75,7 +73,7 @@ #endif /**************************************************************************** - * Private Types + * Name: Private Types ****************************************************************************/ struct ipfwd_tun_s @@ -230,7 +228,7 @@ static int ipfwd_tun_configure(FAR struct ipfwd_tun_s *tun) return -errcode; } - strlcpy(tun->it_devname, ifr.ifr_name, MAX_DEVNAME); + strncpy(tun->it_devname, ifr.ifr_name, MAX_DEVNAME); printf("Created TUN device: %s\n", tun->it_devname); return 0; } @@ -291,11 +289,10 @@ static int ipfwd_netconfig(FAR struct ipfwd_tun_s *tun, IPADDR_TYPE ipaddr, } /**************************************************************************** - * Name: check_sum + * Name: Checksums ****************************************************************************/ -static uint16_t check_sum(uint16_t sum, FAR const uint8_t *data, - uint16_t len) +static uint16_t chksum(uint16_t sum, FAR const uint8_t *data, uint16_t len) { FAR const uint8_t *dataptr; FAR const uint8_t *last_byte; @@ -338,7 +335,7 @@ static uint16_t ipv4_chksum(FAR const uint8_t *buffer) { uint16_t sum; - sum = check_sum(0, buffer, IPv4_HDRLEN); + sum = chksum(0, buffer, IPv4_HDRLEN); return (sum == 0) ? 0xffff : htons(sum); } #endif @@ -365,12 +362,12 @@ static uint16_t common_chksum(FAR uint8_t *buffer, uint8_t proto) /* Sum IP source and destination addresses. */ - sum = check_sum(sum, (FAR uint8_t *)&ipv6->srcipaddr, - 2 * sizeof(net_ipv6addr_t)); + sum = chksum(sum, (FAR uint8_t *)&ipv6->srcipaddr, + 2 * sizeof(net_ipv6addr_t)); /* Sum IP payload data. */ - sum = check_sum(sum, &buffer[IPv6_HDRLEN], upperlen); + sum = chksum(sum, &buffer[IPv6_HDRLEN], upperlen); return (sum == 0) ? 0xffff : htons(sum); #else FAR struct ipv4_hdr_s *ipv4 = (FAR struct ipv4_hdr_s *)buffer; @@ -392,12 +389,11 @@ static uint16_t common_chksum(FAR uint8_t *buffer, uint8_t proto) /* Sum IP source and destination addresses. */ - sum = check_sum(sum, (FAR uint8_t *)&ipv4->srcipaddr, - 2 * sizeof(in_addr_t)); + sum = chksum(sum, (FAR uint8_t *)&ipv4->srcipaddr, 2 * sizeof(in_addr_t)); /* Sum IP payload data. */ - sum = check_sum(sum, &buffer[IPv4_HDRLEN], upperlen); + sum = chksum(sum, &buffer[IPv4_HDRLEN], upperlen); return (sum == 0) ? 0xffff : htons(sum); #endif } @@ -542,16 +538,8 @@ static FAR void *ipfwd_receiver(FAR void *arg) int errcode; int i; -#ifdef CONFIG_DISABLE_ALL_SIGNALS - pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); - pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL); -#endif - for (i = 0; i < IPFWD_NPACKETS; i++) { -#ifdef CONFIG_DISABLE_ALL_SIGNALS - pthread_testcancel(); -#endif nread = read(fwd->ia_fd, fwd->ia_buffer, IPFWD_BUFSIZE); if (nread < 0) { @@ -778,7 +766,7 @@ int main(int argc, FAR char *argv[]) if (ret < 0) { fprintf(stderr, "ERROR: Failed to create tun0: %d\n", ret); - return ret; + goto errout; } ret = ipfwd_netconfig(&fwd.if_tun0, g_tun0_laddr, g_netmask); @@ -848,12 +836,7 @@ errout_with_receiver: /* Wait for receiver thread to terminate */ -#ifdef CONFIG_DISABLE_ALL_SIGNALS - pthread_cancel(fwd.if_receiver); -#else pthread_kill(fwd.if_receiver, 9); -#endif - ret = pthread_join(fwd.if_receiver, &value); if (ret != OK) { @@ -865,5 +848,6 @@ errout_with_tun1: close(fwd.if_tun1.it_fd); errout_with_tun0: close(fwd.if_tun0.it_fd); +errout: return errcode; } diff --git a/examples/isl29023/CMakeLists.txt b/examples/isl29023/CMakeLists.txt deleted file mode 100644 index d833c1a62..000000000 --- a/examples/isl29023/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# ############################################################################## -# apps/examples/isl29023/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_ISL29023) - nuttx_add_application( - NAME - isl29023 - STACKSIZE - ${CONFIG_DEFAULT_TASK_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_ISL29023} - SRCS - isl29023_main.c) -endif() diff --git a/examples/isl29023/Kconfig b/examples/isl29023/Kconfig index 001570c08..3999d8f33 100644 --- a/examples/isl29023/Kconfig +++ b/examples/isl29023/Kconfig @@ -6,7 +6,6 @@ config EXAMPLES_ISL29023 tristate "ISL29023 driver example" default n - depends on SENSORS_ISL29023 ---help--- Enable the example application diff --git a/examples/isl29023/Make.defs b/examples/isl29023/Make.defs index e8e9583c5..f6497bbe0 100644 --- a/examples/isl29023/Make.defs +++ b/examples/isl29023/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/isl29023/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/isl29023/Makefile b/examples/isl29023/Makefile index 2c20c2665..7e3a0801f 100644 --- a/examples/isl29023/Makefile +++ b/examples/isl29023/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/isl29023/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/isl29023/isl29023_main.c b/examples/isl29023/isl29023_main.c index 2c36d8178..a35422542 100644 --- a/examples/isl29023/isl29023_main.c +++ b/examples/isl29023/isl29023_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/isl29023/isl29023_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -33,7 +31,6 @@ #include <fcntl.h> #include <stdio.h> -#include <unistd.h> /**************************************************************************** * Pre-processor Definitions diff --git a/examples/json/CMakeLists.txt b/examples/json/CMakeLists.txt deleted file mode 100644 index f2c1d432d..000000000 --- a/examples/json/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# ############################################################################## -# apps/examples/json/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_JSON) - nuttx_add_application( - NAME - json - STACKSIZE - ${CONFIG_DEFAULT_TASK_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_JSON} - SRCS - json_main.c) -endif() diff --git a/examples/json/Make.defs b/examples/json/Make.defs index 023d630f5..1156c7928 100644 --- a/examples/json/Make.defs +++ b/examples/json/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/json/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/json/Makefile b/examples/json/Makefile index c416b2233..2ce526730 100644 --- a/examples/json/Makefile +++ b/examples/json/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/json/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/json/README.md b/examples/json/README.md new file mode 100644 index 000000000..0d9fcf5d4 --- /dev/null +++ b/examples/json/README.md @@ -0,0 +1,297 @@ +# Examples / `json` cJSON JSON Parser + +This directory contains logic taken from the cJSON project: + +http://sourceforge.net/projects/cjson/ + +This corresponds to SVN revision `r42` (with lots of changes for NuttX coding +standards). As of `r42`, the SVN repository was last updated on `2011-10-10` so +I presume that the code is stable and there is no risk of maintaining duplicate +logic in the NuttX repository. + +# Contents + +- License +- Welcome to cJSON + +# License + +Copyright (c) 2009 Dave Gamble + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +# Welcome to cJSON + +cJSON aims to be the dumbest possible parser that you can get your job done +with. It's a single file of C, and a single header file. + +JSON is described best here: http://www.json.org/ It's like XML, but fat-free. +You use it to move data around, store things, or just generally represent your +program's state. + +First up, how do I build? Add `cJSON.c` to your project, and put `cJSON.h` +somewhere in the header search path. For example, to build the test app: + +```bash +gcc cJSON.c test.c -o test -lm +./test +``` + +As a library, cJSON exists to take away as much legwork as it can, but not get +in your way. As a point of pragmatism (i.e. ignoring the truth), I'm going to +say that you can use it in one of two modes: Auto and Manual. Let's have a quick +run-through. + +I lifted some JSON from this page: http://www.json.org/fatfree.html That page +inspired me to write cJSON, which is a parser that tries to share the same +philosophy as JSON itself. Simple, dumb, out of the way. + +Some JSON: + +```json +{ + "name": "Jack (\"Bee\") Nimble", + "format": { + "type": "rect", + "width": 1920, + "height": 1080, + "interlace": false, + "frame rate": 24 + } +} +``` + +Assume that you got this from a file, a webserver, or magic JSON elves, +whatever, you have a `char *` to it. Everything is a cJSON struct. + +Get it parsed: + +```c +cJSON *root = cJSON_Parse(my_json_string); +``` + +This is an object. We're in C. We don't have objects. But we do have structs. + +What's the framerate? + +```c +cJSON *format = cJSON_GetObjectItem(root,"format"); +int framerate = cJSON_GetObjectItem(format,"frame rate")->valueint; +``` + +Want to change the framerate? + +```c +cJSON_GetObjectItem(format,"frame rate")->valueint = 25; +``` + +Back to disk? + +```c +char *rendered = cJSON_Print(root); +``` + +Finished? Delete the root (this takes care of everything else). + +```c +cJSON_Delete(root); +``` + +That's AUTO mode. If you're going to use Auto mode, you really ought to check +pointers before you dereference them. If you want to see how you'd build this +struct in code? + +```c +cJSON *root,*fmt; +root = cJSON_CreateObject(); + +cJSON_AddItemToObject(root, "name", cJSON_CreateString("Jack (\"Bee\") Nimble")); +cJSON_AddItemToObject(root, "format", fmt = cJSON_CreateObject()); +cJSON_AddStringToObject(fmt,"type", "rect"); +cJSON_AddNumberToObject(fmt,"width", 1920); +cJSON_AddNumberToObject(fmt,"height", 1080); +cJSON_AddFalseToObject (fmt,"interlace"); +cJSON_AddNumberToObject(fmt,"frame rate", 24); +``` + +Hopefully we can agree that's not a lot of code? There's no overhead, no +unnecessary setup. Look at test.c for a bunch of nice examples, mostly all +ripped off the json.org site, and a few from elsewhere. + +What about manual mode? First up you need some detail. +Let's cover how the cJSON objects represent the JSON data. +cJSON doesn't distinguish arrays from objects in handling; just type. +Each cJSON has, potentially, a child, siblings, value, a name. + +The root object has: Object Type and a Child +The Child has name "name", with value "Jack ("Bee") Nimble", and a sibling: +Sibling has type Object, name "format", and a child. +That child has type String, name "type", value "rect", and a sibling: +Sibling has type Number, name "width", value 1920, and a sibling: +Sibling has type Number, name "height", value 1080, and a sibling: +Sibling hs type False, name "interlace", and a sibling: +Sibling has type Number, name "frame rate", value 24 + +Here's the structure: + +```c +typedef struct cJSON { + struct cJSON *next,*prev; + struct cJSON *child; + + int type; + + char *valuestring; + int valueint; + double valuedouble; + + char *string; +} cJSON; +``` + +By default all values are 0 unless set by virtue of being meaningful. + +next/prev is a doubly linked list of siblings. next takes you to your sibling, +prev takes you back from your sibling to you. Only objects and arrays have a +"child", and it's the head of the doubly linked list. A "child" entry will have +`prev==0`, but next potentially points on. The last sibling has `next=0`. The +type expresses Null/True/False/Number/String/Array/Object, all of which are +`#define`d in `cJSON.h`. + +A Number has `valueint` and `valuedouble`. If you're expecting an `int`, read +`valueint`, if not read `valuedouble`. + +Any entry which is in the linked list which is the child of an object will have +a "string" which is the "name" of the entry. When I said "name" in the above +example, that's "string". "string" is the JSON name for the 'variable name' if +you will. + +Now you can trivially walk the lists, recursively, and parse as you please. You +can invoke `cJSON_Parse` to get cJSON to parse for you, and then you can take +the root object, and traverse the structure (which is, formally, an N-tree), and +tokenise as you please. If you wanted to build a callback style parser, this is +how you'd do it (just an example, since these things are very specific): + +```c +void parse_and_callback(cJSON *item, const char *prefix) +{ + while (item) + { + char *newprefix = malloc(strlen(prefix) + strlen(item->name) + 2); + sprintf(newprefix, "%s/%s", prefix, item->name); + int dorecurse = callback(newprefix, item->type, item); + if (item->child && dorecurse) parse_and_callback(item->child, newprefix); + item = item->next; + free(newprefix); + } +} +``` + +The prefix process will build you a separated list, to simplify your callback +handling. The `dorecurse` flag would let the callback decide to handle +sub-arrays on it's own, or let you invoke it per-item. For the item above, your +callback might look like this: + +```c +int callback(const char *name,int type, cJSON *item) +{ + if (!strcmp(name,"name")) { /* populate name */ } + else if (!strcmp(name,"format/type") { /* handle "rect" */ } + else if (!strcmp(name,"format/width") { /* 800 */ } + else if (!strcmp(name,"format/height") { /* 600 */ } + else if (!strcmp(name,"format/interlace") { /* false */ } + else if (!strcmp(name,"format/frame rate") { /* 24 */ } + return 1; +} +``` + +Alternatively, you might like to parse iteratively. + +You'd use: + +```c +void parse_object(cJSON *item) +{ + int i; for (i=0; i < cJSON_GetArraySize(item); i++) + { + cJSON *subitem = cJSON_GetArrayItem(item, i); + // handle subitem. + } +} +``` + +Or, for PROPER manual mode: + +```c +void parse_object(cJSON *item) +{ + cJSON *subitem = item->child; + + while (subitem) + { + // handle subitem + if (subitem->child) parse_object(subitem->child); + + subitem = subitem->next; + } +} +``` + +Of course, this should look familiar, since this is just a stripped-down version +of the callback-parser. + +This should cover most uses you'll find for parsing. The rest should be possible +to infer.. and if in doubt, read the source! There's not a lot of it! ;) + +In terms of constructing JSON data, the example code above is the right way to +do it. You can, of course, hand your sub-objects to other functions to populate. +Also, if you find a use for it, you can manually build the objects. For +instance, suppose you wanted to build an array of objects? + +```c +cJSON *objects[24]; + +cJSON *Create_array_of_anything(cJSON **items,int num) +{ + int i;cJSON *prev, *root=cJSON_CreateArray(); + for (i=0;i<24;i++) + { + if (!i) root->child=objects[i]; + else prev->next=objects[i], objects[i]->prev=prev; + prev=objects[i]; + } + return root; +} +``` + +and simply: `Create_array_of_anything(objects,24)`; + +cJSON doesn't make any assumptions about what order you create things in. You +can attach the objects, as above, and later add children to each of those +objects. + +As soon as you call `cJSON_Print`, it renders the structure to text. + +The test.c code shows how to handle a bunch of typical cases. If you uncomment +the code, it'll load, parse and print a bunch of test files, also from json.org, +which are more complex than I'd care to try and stash into a `const char +array[]`. + +Enjoy cJSON! + +_Dave Gamble, Aug 2009_ diff --git a/examples/json/json_main.c b/examples/json/json_main.c index d49d40316..e3b1c9118 100644 --- a/examples/json/json_main.c +++ b/examples/json/json_main.c @@ -1,10 +1,14 @@ /**************************************************************************** * apps/examples/json/json_main.c * - * SPDX-License-Identifier: MIT - * SPDX-FileCopyrightText: 2012 Gregory Nutt. All rights reserved. - * SPDX-FileCopyrightText: 2009 Dave Gamble - * SPDX-FileContributor: Darcy Gong + * This file is a part of NuttX: + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Ported by: Darcy Gong + * + * And derives from the cJSON Project which has an MIT license: + * + * Copyright (c) 2009 Dave Gamble * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/examples/keyboard/Kconfig b/examples/keyboard/Kconfig deleted file mode 100644 index 208907e42..000000000 --- a/examples/keyboard/Kconfig +++ /dev/null @@ -1,20 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config EXAMPLES_KEYBOARD - tristate "Keyboard example" - default n - ---help--- - Enable the keyboard example - -if EXAMPLES_KEYBOARD - -config EXAMPLES_KEYBOARD_DEVPATH - string "Keyboard device path" - default "/dev/kbd0" - ---help--- - The path to the keyboard device. Default: "/dev/kbd0" - -endif diff --git a/examples/keyboard/Make.defs b/examples/keyboard/Make.defs deleted file mode 100644 index ddd11f9bc..000000000 --- a/examples/keyboard/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/examples/keyboard/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_EXAMPLES_KEYBOARD),) -CONFIGURED_APPS += $(APPDIR)/examples/keyboard -endif diff --git a/examples/keyboard/Makefile b/examples/keyboard/Makefile deleted file mode 100644 index 1284fb73a..000000000 --- a/examples/keyboard/Makefile +++ /dev/null @@ -1,36 +0,0 @@ -############################################################################ -# apps/examples/keyboard/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -# Keyboard built-in application info - -PROGNAME = kbd -PRIORITY = SCHED_PRIORITY_DEFAULT -STACKSIZE = $(CONFIG_DEFAULT_TASK_STACKSIZE) -MODULE = $(CONFIG_EXAMPLES_KEYBOARD) - -# Keyboard Example - -MAINSRC = kbd_main.c - -include $(APPDIR)/Application.mk diff --git a/examples/keyboard/kbd_main.c b/examples/keyboard/kbd_main.c deleted file mode 100644 index d793e6344..000000000 --- a/examples/keyboard/kbd_main.c +++ /dev/null @@ -1,161 +0,0 @@ -/**************************************************************************** - * apps/examples/keyboard/kbd_main.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <sys/types.h> - -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <fcntl.h> -#include <errno.h> -#include <nuttx/debug.h> - -#include <nuttx/input/keyboard.h> - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: kbd_main - ****************************************************************************/ - -int main(int argc, FAR char *argv[]) -{ - struct keyboard_event_s sample; - ssize_t nbytes; - long nsamples = 0; - int fd; - int errval = 0; - - if (argc > 1) - { - nsamples = strtol(argv[1], NULL, 10); - } - - printf("kbd_main: nsamples: %ld\n", nsamples); - - /* Open the keyboard device for reading */ - - printf("kbd_main: Opening %s\n", CONFIG_EXAMPLES_KEYBOARD_DEVPATH); - fd = open(CONFIG_EXAMPLES_KEYBOARD_DEVPATH, O_RDONLY); - if (fd < 0) - { - printf("kbd_main: open %s failed: %d\n", - CONFIG_EXAMPLES_KEYBOARD_DEVPATH, errno); - errval = 2; - goto errout; - } - - /* Now loop the appropriate number of times, displaying the collected - * keyboard samples. - */ - - for (; ; ) - { - /* Flush any output before the loop entered or from the previous pass - * through the loop. - */ - - fflush(stdout); - - /* Read one sample */ - - iinfo("Reading...\n"); - nbytes = read(fd, &sample, sizeof(struct keyboard_event_s)); - iinfo("Bytes read: %zd\n", nbytes); - - /* Handle unexpected return values */ - - if (nbytes < 0) - { - errval = errno; - if (errval != EINTR) - { - printf("kbd_main: read %s failed: %d\n", - CONFIG_EXAMPLES_KEYBOARD_DEVPATH, errval); - errval = 3; - goto errout_with_dev; - } - - printf("kbd_main: Interrupted read...\n"); - } - else if (nbytes != sizeof(struct keyboard_event_s)) - { - printf("kbd_main: Unexpected read size=%zd, expected=%zd, " - "Ignoring\n", - nbytes, sizeof(struct keyboard_event_s)); - } - - /* Print the sample data on successful return */ - - else - { - printf("Sample :\n"); - printf(" code : %" PRIu32 "\n", sample.code); - printf(" type : %" PRIu32 "\n", sample.type); - } - - if (nsamples && --nsamples <= 0) - { - break; - } - } - -errout_with_dev: - close(fd); - -errout: - printf("Terminating!\n"); - fflush(stdout); - return errval; -} diff --git a/examples/leds/CMakeLists.txt b/examples/leds/CMakeLists.txt deleted file mode 100644 index 9e45423d2..000000000 --- a/examples/leds/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# ############################################################################## -# apps/examples/leds/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_LEDS) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_LEDS_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_LEDS_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_LEDS_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_LEDS} - SRCS - leds_main.c) -endif() diff --git a/examples/leds/Make.defs b/examples/leds/Make.defs index 50b1b9997..eff16b389 100644 --- a/examples/leds/Make.defs +++ b/examples/leds/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/leds/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/leds/Makefile b/examples/leds/Makefile index 2bd032ba3..f98a32f48 100644 --- a/examples/leds/Makefile +++ b/examples/leds/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/leds/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/leds/leds_main.c b/examples/leds/leds_main.c index 4d785f65c..47ed05bde 100644 --- a/examples/leds/leds_main.c +++ b/examples/leds/leds_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/leds/leds_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -34,7 +32,6 @@ #include <sched.h> #include <errno.h> #include <signal.h> -#include <unistd.h> #include <nuttx/leds/userled.h> diff --git a/examples/leds_rust/Kconfig b/examples/leds_rust/Kconfig deleted file mode 100644 index 914693c88..000000000 --- a/examples/leds_rust/Kconfig +++ /dev/null @@ -1,30 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config EXAMPLES_LEDS_RUST - tristate "\"LEDs Rust\" example" - default n - depends on USERLED - ---help--- - Enable the \"LEDs Rust\" example - -if EXAMPLES_LEDS_RUST - -config EXAMPLES_LEDS_RUST_PROGNAME - string "Program name" - default "leds_rust" - ---help--- - This is the name of the program that will be used when the - program is installed. - -config EXAMPLES_LEDS_RUST_PRIORITY - int "LEDs Rust task priority" - default 100 - -config EXAMPLES_LEDS_RUST_STACKSIZE - int "LEDs Rust stack size" - default DEFAULT_TASK_STACKSIZE - -endif diff --git a/examples/leds_rust/Make.defs b/examples/leds_rust/Make.defs deleted file mode 100644 index 059e8a20e..000000000 --- a/examples/leds_rust/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/examples/leds_rust/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_EXAMPLES_LEDS_RUST),) -CONFIGURED_APPS += $(APPDIR)/examples/leds_rust -endif diff --git a/examples/leds_rust/Makefile b/examples/leds_rust/Makefile deleted file mode 100644 index bf3c8345d..000000000 --- a/examples/leds_rust/Makefile +++ /dev/null @@ -1,38 +0,0 @@ -############################################################################ -# apps/examples/leds_rust/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -# Hello, Rust! built-in application info - -PROGNAME = $(CONFIG_EXAMPLES_LEDS_RUST_PROGNAME) -PRIORITY = $(CONFIG_EXAMPLES_LEDS_RUST_PRIORITY) -STACKSIZE = $(CONFIG_EXAMPLES_LEDS_RUST_STACKSIZE) -MODULE = $(CONFIG_EXAMPLES_LEDS_RUST) - -# Hello, Rust! Example - -MAINSRC = leds_rust_main.rs - -RUSTFLAGS += -C panic=abort -O - -include $(APPDIR)/Application.mk diff --git a/examples/leds_rust/leds_rust_main.rs b/examples/leds_rust/leds_rust_main.rs deleted file mode 100644 index 206d36028..000000000 --- a/examples/leds_rust/leds_rust_main.rs +++ /dev/null @@ -1,130 +0,0 @@ -/**************************************************************************** - * apps/examples/leds_rust/leds_rust_main.rs - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Attributes - ****************************************************************************/ - -/* Comment out these lines for testing with Rust Standard Library */ - -#![no_main] -#![no_std] - -/**************************************************************************** - * Uses - ****************************************************************************/ - -#[cfg(target_os = "none")] -use core::{ - panic::PanicInfo, - result::Result::{self, Err, Ok}, -}; - -/**************************************************************************** - * Modules - ****************************************************************************/ - -mod nuttx; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Panic Handler (needed for [no_std] compilation) - ****************************************************************************/ - -#[cfg(target_os = "none")] /* For NuttX */ -#[panic_handler] -fn panic(_panic: &PanicInfo<'_>) -> ! { - loop {} -} - -/**************************************************************************** - * rust_main - ****************************************************************************/ - -fn rust_main(_argc: i32, _argv: *const *const u8) -> Result<i32, i32> { - /* "Hello, Rust!!" using puts() from libc */ - - nuttx::safe_puts("Hello, Rust!!"); - - /* Blink LED 1 using ioctl() from NuttX */ - - nuttx::safe_puts("Opening /dev/userleds"); - let fd = nuttx::safe_open("/dev/userleds", nuttx::O_WRONLY)?; - nuttx::safe_puts("Set LED 1 to 1"); - - nuttx::safe_ioctl(fd, nuttx::ULEDIOC_SETALL, 1)?; - nuttx::safe_puts("Sleeping..."); - unsafe { - nuttx::usleep(500_000); - } - - nuttx::safe_puts("Set LED 1 to 0"); - nuttx::safe_ioctl(fd, nuttx::ULEDIOC_SETALL, 0)?; - unsafe { - nuttx::close(fd); - } - - /* Exit with status 0 */ - - Ok(0) -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * leds_rust_main - ****************************************************************************/ - -#[no_mangle] -pub extern "C" fn leds_rust_main(_argc: i32, _argv: *const *const u8) -> i32 { - /* Call the program logic in Rust Main */ - - let res = rust_main(0, core::ptr::null()); - - /* If Rust Main returns an error, print it */ - - if let Err(e) = res { - unsafe { - nuttx::printf( - b"ERROR: rust_main() failed with error %d\n\0" as *const u8, - e, - ); - } - e - } else { - 0 - } -} - -/**************************************************************************** - * main - ****************************************************************************/ - -#[cfg(not(target_os = "none"))] /* For Testing Locally */ -fn main() { - leds_rust_main(0, core::ptr::null()); -} diff --git a/examples/leds_rust/nuttx.rs b/examples/leds_rust/nuttx.rs deleted file mode 100644 index 41366096d..000000000 --- a/examples/leds_rust/nuttx.rs +++ /dev/null @@ -1,121 +0,0 @@ -/**************************************************************************** - * apps/examples/leds_rust/nuttx.rs - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/* NuttX Definitions for Rust Apps */ - -/**************************************************************************** - * Uses - ****************************************************************************/ - -use core::result::Result::{self, Err, Ok}; - -/**************************************************************************** - * Externs - ****************************************************************************/ - -extern "C" { - pub fn printf(format: *const u8, ...) -> i32; - pub fn open(path: *const u8, oflag: i32, ...) -> i32; - pub fn close(fd: i32) -> i32; - pub fn ioctl(fd: i32, request: i32, ...) -> i32; - pub fn usleep(usec: u32) -> u32; - pub fn puts(s: *const u8) -> i32; -} - -/**************************************************************************** - * Public Constants - ****************************************************************************/ - -pub const ENAMETOOLONG: i32 = 36; -pub const O_WRONLY: i32 = 1 << 1; -pub const PATH_MAX: usize = 256; -pub const PUTS_MAX: usize = 256; -pub const ULEDIOC_SETALL: i32 = 0x1d03; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/* Copy the Rust Str to the Byte Buffer and terminate with null */ - -fn copy_to_buffer(s: &str, buffer: &mut [u8]) -> Result<(), ()> { - let byte_str = s.as_bytes(); - let len = byte_str.len(); - if len >= buffer.len() { - Err(()) - } else { - buffer[..len].copy_from_slice(&byte_str[..len]); - buffer[len] = 0; - Ok(()) - } -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/* Safe Version of open() */ - -pub fn safe_open(path: &str, oflag: i32) -> Result<i32, i32> { - let mut buffer = [0u8; PATH_MAX]; - let res = copy_to_buffer(path, &mut buffer); - if res.is_err() { - unsafe { - puts(b"ERROR: safe_open() path size exceeds PATH_MAX\0" as *const u8); - } - return Err(-ENAMETOOLONG); - } - - let fd = unsafe { open(buffer.as_ptr(), oflag) }; - if fd < 0 { - Err(fd) - } else { - Ok(fd) - } -} - -/* Safe Version of ioctl() */ - -pub fn safe_ioctl(fd: i32, request: i32, arg: i32) -> Result<i32, i32> { - let ret = unsafe { ioctl(fd, request, arg) }; - if ret < 0 { - Err(ret) - } else { - Ok(ret) - } -} - -/* Safe Version of puts() */ - -pub fn safe_puts(s: &str) { - let mut buffer = [0u8; PUTS_MAX]; - let res = copy_to_buffer(s, &mut buffer); - if res.is_err() { - unsafe { - puts(b"ERROR: safe_puts() string size exceeds PUTS_MAX\0" as *const u8); - } - } else { - unsafe { - puts(buffer.as_ptr()); - } - } -} diff --git a/examples/leds_zig/Kconfig b/examples/leds_zig/Kconfig deleted file mode 100644 index 59ea600ca..000000000 --- a/examples/leds_zig/Kconfig +++ /dev/null @@ -1,30 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config EXAMPLES_LEDS_ZIG - tristate "\"LEDs Zig\" example" - default n - depends on USERLED - ---help--- - Enable the \"LEDs Zig\" example - -if EXAMPLES_LEDS_ZIG - -config EXAMPLES_LEDS_ZIG_PROGNAME - string "Program name" - default "leds_zig" - ---help--- - This is the name of the program that will be used when the - program is installed. - -config EXAMPLES_LEDS_ZIG_PRIORITY - int "LEDs Zig task priority" - default 100 - -config EXAMPLES_LEDS_ZIG_STACKSIZE - int "LEDs Zig stack size" - default DEFAULT_TASK_STACKSIZE - -endif diff --git a/examples/leds_zig/Make.defs b/examples/leds_zig/Make.defs deleted file mode 100644 index 1ea4e5d04..000000000 --- a/examples/leds_zig/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/examples/leds_zig/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_EXAMPLES_LEDS_ZIG),) -CONFIGURED_APPS += $(APPDIR)/examples/leds_zig -endif diff --git a/examples/leds_zig/Makefile b/examples/leds_zig/Makefile deleted file mode 100644 index a97c199d1..000000000 --- a/examples/leds_zig/Makefile +++ /dev/null @@ -1,36 +0,0 @@ -############################################################################ -# apps/examples/leds_zig/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -# LEDS in Zig Example - -MAINSRC = leds_zig.zig - -# LEDS_zig built-in application info -ZIGFLAGS += -O ReleaseSmall -lc -I$(TOPDIR)/include -PROGNAME = $(CONFIG_EXAMPLES_LEDS_ZIG_PROGNAME) -PRIORITY = $(CONFIG_EXAMPLES_LEDS_ZIG_PRIORITY) -STACKSIZE = $(CONFIG_EXAMPLES_LEDS_ZIG_STACKSIZE) -MODULE = $(CONFIG_EXAMPLES_LEDS_ZIG) - -include $(APPDIR)/Application.mk diff --git a/examples/leds_zig/leds_zig.zig b/examples/leds_zig/leds_zig.zig deleted file mode 100644 index bbfbffd54..000000000 --- a/examples/leds_zig/leds_zig.zig +++ /dev/null @@ -1,213 +0,0 @@ -///************************************************************************** -// examples/leds_zig/leds_zig.zig -// -// SPDX-License-Identifier: Apache-2.0 -// -// Licensed to the Apache Software Foundation (ASF) under one or more -// contributor license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright ownership. The -// ASF licenses this file to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance with the -// License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -// License for the specific language governing permissions and limitations -// under the License. -// -///************************************************************************** -///************************************************************************** -// Included Files -///************************************************************************** -const std = @import("std"); - -// C types not working with Zig comptime, need allocation -const Allocator = std.mem.Allocator; - -/// NuttX namespace -const NuttX = struct { - // public constant - pub const c = @cImport({ - @cInclude("nuttx/config.h"); - @cInclude("sys/ioctl.h"); - @cInclude("stdbool.h"); - @cInclude("stdlib.h"); - @cInclude("stdio.h"); - @cInclude("fcntl.h"); - @cInclude("sched.h"); - @cInclude("errno.h"); - @cInclude("signal.h"); - @cInclude("unistd.h"); - - @cInclude("nuttx/leds/userled.h"); - }); - - var g_led_daemon_started: bool = false; - - pub fn print(allocator: Allocator, comptime fmt: [*:0]const u8, args: anytype) void { - // comptime buffer[count(fmt, args)] or runtime allocation - const output = if (isComptime(args)) - std.fmt.comptimePrint(std.mem.span(fmt), args) - else - std.fmt.allocPrintZ(allocator, std.mem.span(fmt), args) catch @panic("Out of Memory!!"); - - _ = c.printf(output); - } - - pub const exit_t = enum(c_int) { - success = c.EXIT_SUCCESS, - failure = c.EXIT_FAILURE, - }; - - // private function - - // check if value is comptime - inline fn isComptime(val: anytype) bool { - return @typeInfo(@TypeOf(.{val})).Struct.fields[0].is_comptime; - } - - export fn led_daemon(_: c_int, _: [*c][*c]u8) callconv(.C) c_int { - var supported: NuttX.c.userled_set_t = 0; - var ledset: NuttX.c.userled_set_t = 0; - var incrementing: bool = true; - - // SIGTERM handler - const sigaction_t = NuttX.c.struct_sigaction; - var act: sigaction_t = .{ - .sa_flags = NuttX.c.SA_SIGINFO, - .sa_u = .{ - ._sa_sigaction = sigterm_action, - }, - }; - - _ = NuttX.c.sigemptyset(&act.sa_mask); - _ = NuttX.c.sigaddset(&act.sa_mask, NuttX.c.SIGTERM); - - const sig = NuttX.c.sigaction(NuttX.c.SIGTERM, &act, null); - if (sig != 0) { - NuttX.print(global_allocator, "Failed to install SIGTERM handler, errno={}\n", .{sig}); - return @intFromEnum(NuttX.exit_t.failure); - } - - // Indicate that we are running - const mypid = NuttX.c.getpid(); - g_led_daemon_started = true; - NuttX.print(global_allocator, "\nled_daemon (pid# {}): Running\n", .{mypid}); - - // Open the LED driver - NuttX.print(global_allocator, "led_daemon: Opening {s}\n", .{NuttX.c.CONFIG_EXAMPLES_LEDS_DEVPATH}); - const fd = NuttX.c.open(NuttX.c.CONFIG_EXAMPLES_LEDS_DEVPATH, NuttX.c.O_WRONLY); - if (fd < 0) { - NuttX.print(global_allocator, "led_daemon: ERROR: Failed to open {s}: {}\n", .{ - NuttX.c.CONFIG_EXAMPLES_LEDS_DEVPATH, - fd, - }); - g_led_daemon_started = false; - return @intFromEnum(NuttX.exit_t.failure); - } - - // Get the set of LEDs supported - var ret = NuttX.c.ioctl(fd, NuttX.c.ULEDIOC_SUPPORTED, &supported); - if (ret < 0) { - NuttX.print(global_allocator, "led_daemon: ERROR: ioctl(ULEDIOC_SUPPORTED) failed: {}\n", .{ret}); - _ = NuttX.c.close(fd); - g_led_daemon_started = false; - return @intFromEnum(NuttX.exit_t.failure); - } - - NuttX.print(global_allocator, "led_daemon: Supported LEDs {x}\n", .{supported}); - supported &= NuttX.c.CONFIG_EXAMPLES_LEDS_LEDSET; - - // Main loop - while (g_led_daemon_started) { - var newset: NuttX.c.userled_set_t = 0; - var tmp: NuttX.c.userled_set_t = 0; - - if (incrementing) { - tmp = ledset; - while (newset == ledset) { - tmp += 1; - newset = tmp & supported; - } - - if (newset == 0) { - incrementing = false; - continue; - } - } else { - if (ledset == 0) { - incrementing = true; - continue; - } - - tmp = ledset; - while (newset == ledset) { - tmp -= 1; - newset = tmp & supported; - } - } - - ledset = newset; - NuttX.print(global_allocator, "led_daemon: LED set {x}\n", .{ledset}); - - ret = NuttX.c.ioctl(fd, NuttX.c.ULEDIOC_SETALL, ledset); - if (ret < 0) { - NuttX.print(global_allocator, "led_daemon: ERROR: ioctl(ULEDIOC_SETALL) failed: {}\n", .{ret}); - _ = NuttX.c.close(fd); - g_led_daemon_started = false; - return @intFromEnum(NuttX.exit_t.failure); - } - - _ = NuttX.c.usleep(500 * 1000); - } - - _ = NuttX.c.close(fd); - return @intFromEnum(NuttX.exit_t.success); - } - - export fn sigterm_action(signo: c_int, siginfo: [*c]NuttX.c.siginfo_t, arg: ?*anyopaque) void { - if (signo == NuttX.c.SIGTERM) { - NuttX.print(global_allocator, "SIGTERM received\n", .{}); - g_led_daemon_started = false; - NuttX.print(global_allocator, "led_daemon: Terminated.\n", .{}); - } else { - NuttX.print(global_allocator, "\nsigterm_action: Received signo={} siginfo={*} arg={*}\n", .{ - signo, - siginfo, - arg, - }); - } - } -}; - -// Global allocator -var arena = std.heap.ArenaAllocator.init(std.heap.raw_c_allocator); -const global_allocator = arena.allocator(); - -export fn leds_zig_main(_: c_int, _: [*][*:0]u8) NuttX.exit_t { - defer arena.deinit(); - - NuttX.print(global_allocator, "leds_main: Starting the led_daemon\n", .{}); - if (NuttX.g_led_daemon_started) { - NuttX.print(global_allocator, "leds_main: led_daemon already running\n", .{}); - return .success; - } - - const ret = NuttX.c.task_create( - "led_daemon", - NuttX.c.CONFIG_EXAMPLES_LEDS_PRIORITY, - NuttX.c.CONFIG_EXAMPLES_LEDS_STACKSIZE, - NuttX.led_daemon, - null, - ); - if (ret < 0) { - NuttX.print(global_allocator, "leds_main: ERROR: Failed to start led_daemon: {}\n", .{ret}); - return .failure; - } - - NuttX.print(global_allocator, "leds_main: led_daemon started\n", .{}); - return .success; -} diff --git a/examples/lely_master/CMakeLists.txt b/examples/lely_master/CMakeLists.txt deleted file mode 100644 index 003c3e9fb..000000000 --- a/examples/lely_master/CMakeLists.txt +++ /dev/null @@ -1,53 +0,0 @@ -# ############################################################################## -# apps/examples/lely_master/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_LELYMASTER) - - set(LELY_INCDIR ${NUTTX_APPS_DIR}/canutils/lely-canopen/lely-core/include) - - set(SRCS master_main.c sdev_master.c) - - if(CONFIG_EXAMPLES_LELYMASTER_CHARDEV) - list(APPEND SRCS candev_char.c) - endif() - - if(CONFIG_EXAMPLES_LELYMASTER_SOCKET) - list(APPEND SRCS candev_sock.c) - endif() - - nuttx_add_application( - NAME - comaster - PRIORITY - ${CONFIG_EXAMPLES_LELYMASTER_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_LELYMASTER_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_LELYMASTER} - COMPILE_FLAGS - -Wno-undef - INCLUDE_DIRECTORIES - ${LELY_INCDIR} - SRCS - ${SRCS}) - -endif() diff --git a/examples/lely_master/Kconfig b/examples/lely_master/Kconfig deleted file mode 100644 index b370ea1f9..000000000 --- a/examples/lely_master/Kconfig +++ /dev/null @@ -1,50 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config EXAMPLES_LELYMASTER - tristate "Lely CANopen master example" - default n - depends on CANUTILS_LELYCANOPEN && CANUTILS_LELYCANOPEN_SDEV - depends on CANUTILS_LELYCANOPEN_TIME && CANUTILS_LELYCANOPEN_OBJUPLOAD - depends on CANUTILS_LELYCANOPEN_MASTER - ---help--- - Enable the Lely CANopen master (comaster) example application. - -if EXAMPLES_LELYMASTER - -choice - prompt "CAN backend" - default EXAMPLES_LELYMASTER_CHARDEV - -config EXAMPLES_LELYMASTER_CHARDEV - bool "CAN character driver" - depends on CAN - -config EXAMPLES_LELYMASTER_SOCKET - bool "SocketCAN" - depends on NET_CAN - select NETUTILS_NETLIB - -endchoice - -config EXAMPLES_LELYMASTER_DEVPATH - string "CAN character device path" - default "/dev/can0" - depends on EXAMPLES_LELYMASTER_CHARDEV - -config EXAMPLES_LELYMASTER_INTF - string "SocketCAN interface" - default "can0" - depends on EXAMPLES_LELYMASTER_SOCKET - -config EXAMPLES_LELYMASTER_PRIORITY - int "Task priority" - default 100 - -config EXAMPLES_LELYMASTER_STACKSIZE - int "Stack size" - default DEFAULT_TASK_STACKSIZE - -endif diff --git a/examples/lely_master/Make.defs b/examples/lely_master/Make.defs deleted file mode 100644 index d47806ad6..000000000 --- a/examples/lely_master/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/examples/lely_master/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_EXAMPLES_LELYMASTER),) -CONFIGURED_APPS += $(APPDIR)/examples/lely_master -endif diff --git a/examples/lely_master/Makefile b/examples/lely_master/Makefile deleted file mode 100644 index 68db84998..000000000 --- a/examples/lely_master/Makefile +++ /dev/null @@ -1,47 +0,0 @@ -############################################################################ -# apps/examples/lely_master/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -PROGNAME = comaster -PRIORITY = $(CONFIG_EXAMPLES_LELYMASTER_PRIORITY) -STACKSIZE = $(CONFIG_EXAMPLES_LELYMASTER_STACKSIZE) -MODULE = $(CONFIG_EXAMPLES_LELYMASTER) - -CFLAGS += -DHAVE_CONFIG_H=1 - -# Lely headers use bare "#if __cplusplus"; silence -Wundef like the library - -CFLAGS += -Wno-undef - -CSRCS = sdev_master.c - -ifeq ($(CONFIG_EXAMPLES_LELYMASTER_CHARDEV),y) -CSRCS += candev_char.c -endif -ifeq ($(CONFIG_EXAMPLES_LELYMASTER_SOCKET),y) -CSRCS += candev_sock.c -endif - -MAINSRC = master_main.c - -include $(APPDIR)/Application.mk diff --git a/examples/lely_master/candev.h b/examples/lely_master/candev.h deleted file mode 100644 index 47a6fb8a9..000000000 --- a/examples/lely_master/candev.h +++ /dev/null @@ -1,44 +0,0 @@ -/**************************************************************************** - * apps/examples/lely_master/candev.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __APPS_EXAMPLES_LELY_MASTER_CANDEV_H -#define __APPS_EXAMPLES_LELY_MASTER_CANDEV_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <canutils/lely/config.h> - -#include <lely/can/msg.h> - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -int comaster_candev_init(void); -int comaster_candev_send(FAR const struct can_msg *msg); -int comaster_candev_recv(FAR struct can_msg *msg); - -#endif /* __APPS_EXAMPLES_LELY_MASTER_CANDEV_H */ diff --git a/examples/lely_master/candev_char.c b/examples/lely_master/candev_char.c deleted file mode 100644 index 3506b75d9..000000000 --- a/examples/lely_master/candev_char.c +++ /dev/null @@ -1,173 +0,0 @@ -/**************************************************************************** - * apps/examples/lely_master/candev_char.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <stdio.h> -#include <fcntl.h> -#include <errno.h> -#include <unistd.h> - -#include <sys/types.h> -#include <sys/ioctl.h> - -#include <nuttx/can/can.h> - -#include "candev.h" - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static int g_candev_fd; - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: comaster_candev_init - ****************************************************************************/ - -int comaster_candev_init(void) -{ - struct canioc_bittiming_s bt; - int ret; - - /* Non-blocking so the main loop keeps servicing the CANopen timers */ - - g_candev_fd = open(CONFIG_EXAMPLES_LELYMASTER_DEVPATH, - O_RDWR | O_NONBLOCK); - if (g_candev_fd < 0) - { - ret = -errno; - printf("ERROR: open %s failed %d\n", - CONFIG_EXAMPLES_LELYMASTER_DEVPATH, errno); - return ret; - } - - ret = ioctl(g_candev_fd, CANIOC_GET_BITTIMING, &bt); - if (ret < 0) - { - printf("Bit timing not available: %d\n", errno); - } - else - { - printf("Bit timing:\n"); - printf(" Baud: %lu\n", (unsigned long)bt.bt_baud); - printf(" TSEG1: %u\n", bt.bt_tseg1); - printf(" TSEG2: %u\n", bt.bt_tseg2); - printf(" SJW: %u\n", bt.bt_sjw); - } - - return OK; -} - -/**************************************************************************** - * Name: comaster_candev_send - ****************************************************************************/ - -int comaster_candev_send(FAR const struct can_msg *msg) -{ - struct can_msg_s txmsg; - ssize_t nwritten; - int i; - - txmsg.cm_hdr.ch_id = msg->id; - txmsg.cm_hdr.ch_rtr = (msg->flags & CAN_FLAG_RTR) != 0; - txmsg.cm_hdr.ch_dlc = msg->len; -#ifdef CONFIG_CAN_EXTID - txmsg.cm_hdr.ch_extid = (msg->flags & CAN_FLAG_IDE) != 0; -#endif -#ifdef CONFIG_CAN_ERRORS - txmsg.cm_hdr.ch_error = 0; -#endif - txmsg.cm_hdr.ch_tcf = 0; - - for (i = 0; i < msg->len; i++) - { - txmsg.cm_data[i] = msg->data[i]; - } - - nwritten = write(g_candev_fd, &txmsg, CAN_MSGLEN(txmsg.cm_hdr.ch_dlc)); - if (nwritten != CAN_MSGLEN(txmsg.cm_hdr.ch_dlc)) - { - return -1; - } - - return 0; -} - -/**************************************************************************** - * Name: comaster_candev_recv - ****************************************************************************/ - -int comaster_candev_recv(FAR struct can_msg *msg) -{ - struct can_msg_s rxmsg; - ssize_t nread; - int i; - - nread = read(g_candev_fd, &rxmsg, sizeof(struct can_msg_s)); - if (nread < 0) - { - if (errno == EAGAIN || errno == EWOULDBLOCK) - { - return 0; - } - - return -1; - } - - if (nread < CAN_MSGLEN(0)) - { - return 0; - } - - msg->id = rxmsg.cm_hdr.ch_id; - msg->flags = 0; - -#ifdef CONFIG_CAN_EXTID - if (rxmsg.cm_hdr.ch_extid) - { - msg->flags |= CAN_FLAG_IDE; - } -#endif - - if (rxmsg.cm_hdr.ch_rtr) - { - msg->flags |= CAN_FLAG_RTR; - } - - msg->len = rxmsg.cm_hdr.ch_dlc; - - for (i = 0; i < rxmsg.cm_hdr.ch_dlc; i++) - { - msg->data[i] = rxmsg.cm_data[i]; - } - - return 1; -} diff --git a/examples/lely_master/candev_sock.c b/examples/lely_master/candev_sock.c deleted file mode 100644 index 46c30ddc6..000000000 --- a/examples/lely_master/candev_sock.c +++ /dev/null @@ -1,197 +0,0 @@ -/**************************************************************************** - * apps/examples/lely_master/candev_sock.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <stdio.h> -#include <string.h> -#include <fcntl.h> -#include <errno.h> -#include <unistd.h> - -#include <net/if.h> -#include <sys/socket.h> - -#include <nuttx/can.h> - -#include "netutils/netlib.h" -#include "candev.h" - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static int g_candev_sock; - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: comaster_candev_init - ****************************************************************************/ - -int comaster_candev_init(void) -{ - struct sockaddr_can addr; - struct ifreq ifr; - int on = 1; - int ret; - - g_candev_sock = socket(PF_CAN, SOCK_RAW, CAN_RAW); - if (g_candev_sock < 0) - { - ret = -errno; - printf("ERROR: socket failed %d\n", errno); - return ret; - } - - strlcpy(ifr.ifr_name, CONFIG_EXAMPLES_LELYMASTER_INTF, IFNAMSIZ); - - /* SocketCAN silently drops traffic while the interface is down, so bring - * it up here. This lets the example run without a separate "ifup" step. - */ - - if (netlib_ifup(ifr.ifr_name) < 0) - { - ret = -errno; - printf("ERROR: netlib_ifup %s failed %d\n", ifr.ifr_name, errno); - goto errout; - } - - ifr.ifr_ifindex = if_nametoindex(ifr.ifr_name); - if (ifr.ifr_ifindex == 0) - { - ret = -errno; - printf("ERROR: if_nametoindex %s failed %d\n", ifr.ifr_name, errno); - goto errout; - } - - setsockopt(g_candev_sock, SOL_CAN_RAW, CAN_RAW_RECV_OWN_MSGS, - &on, sizeof(on)); - - memset(&addr, 0, sizeof(addr)); - addr.can_family = AF_CAN; - addr.can_ifindex = ifr.ifr_ifindex; - - if (bind(g_candev_sock, (FAR struct sockaddr *)&addr, sizeof(addr)) < 0) - { - ret = -errno; - printf("ERROR: bind failed %d\n", errno); - goto errout; - } - - ret = fcntl(g_candev_sock, F_SETFL, O_NONBLOCK); - if (ret < 0) - { - ret = -errno; - goto errout; - } - - return OK; - -errout: - close(g_candev_sock); - g_candev_sock = -1; - return ret; -} - -/**************************************************************************** - * Name: comaster_candev_send - ****************************************************************************/ - -int comaster_candev_send(FAR const struct can_msg *msg) -{ - struct can_frame frame; - ssize_t nwritten; - - memset(&frame, 0, sizeof(frame)); - - frame.can_id = msg->id; - if (msg->flags & CAN_FLAG_IDE) - { - frame.can_id |= CAN_EFF_FLAG; - } - - if (msg->flags & CAN_FLAG_RTR) - { - frame.can_id |= CAN_RTR_FLAG; - } - - frame.can_dlc = msg->len; - memcpy(frame.data, msg->data, msg->len); - - nwritten = write(g_candev_sock, &frame, sizeof(frame)); - if (nwritten != sizeof(frame)) - { - return -1; - } - - return 0; -} - -/**************************************************************************** - * Name: comaster_candev_recv - ****************************************************************************/ - -int comaster_candev_recv(FAR struct can_msg *msg) -{ - struct can_frame frame; - ssize_t nread; - - nread = read(g_candev_sock, &frame, sizeof(frame)); - if (nread < 0) - { - if (errno == EAGAIN || errno == EWOULDBLOCK) - { - return 0; - } - - return -1; - } - - if (nread < sizeof(frame)) - { - return 0; - } - - msg->id = frame.can_id & CAN_EFF_MASK; - msg->flags = 0; - if (frame.can_id & CAN_EFF_FLAG) - { - msg->flags |= CAN_FLAG_IDE; - } - - if (frame.can_id & CAN_RTR_FLAG) - { - msg->flags |= CAN_FLAG_RTR; - } - - msg->len = frame.can_dlc; - memcpy(msg->data, frame.data, frame.can_dlc); - - return 1; -} diff --git a/examples/lely_master/master_main.c b/examples/lely_master/master_main.c deleted file mode 100644 index 4148d0d1c..000000000 --- a/examples/lely_master/master_main.c +++ /dev/null @@ -1,358 +0,0 @@ -/**************************************************************************** - * apps/examples/lely_master/master_main.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <stdbool.h> -#include <time.h> -#include <unistd.h> - -#include <canutils/lely/config.h> - -#include <lely/co/csdo.h> -#include <lely/co/dev.h> -#include <lely/co/nmt.h> -#include <lely/co/sdev.h> -#include <lely/co/sdo.h> -#include <lely/co/time.h> - -#include "sdev.h" -#include "candev.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define SLAVE_ID 0x02 -#define OBJ_COUNTER 0x2100 - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -enum master_phase_e -{ - PHASE_WAIT, /* wait for the slave, then read its info via SDO */ - PHASE_SDO, /* SDO request in flight */ - PHASE_RUN /* network operational, streaming PDO data */ -}; - -struct co_net_s -{ - can_net_t *net; - co_dev_t *dev; - co_nmt_t *nmt; -}; - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static struct co_net_s g_net; -static bool g_sdo_done; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: elapsed_ms - ****************************************************************************/ - -static long elapsed_ms(const struct timespec *a, const struct timespec *b) -{ - return (a->tv_sec - b->tv_sec) * 1000 + - (a->tv_nsec - b->tv_nsec) / 1000000; -} - -/**************************************************************************** - * Name: on_can_send - ****************************************************************************/ - -static int on_can_send(const struct can_msg *msg, void *data) -{ - UNUSED(data); - - return comaster_candev_send(msg); -} - -/**************************************************************************** - * Name: nmt_start_remote - ****************************************************************************/ - -static void nmt_start_remote(co_unsigned8_t id) -{ - struct can_msg msg; - - /* NMT command frame: COB-ID 0x000, {command specifier, node-ID} */ - - memset(&msg, 0, sizeof(msg)); - msg.len = 2; - msg.data[0] = CO_NMT_CS_START; - msg.data[1] = id; - - comaster_candev_send(&msg); -} - -/**************************************************************************** - * Name: on_sdo_up - ****************************************************************************/ - -static void on_sdo_up(co_csdo_t *sdo, co_unsigned16_t idx, - co_unsigned8_t subidx, co_unsigned32_t ac, - const void *ptr, size_t n, void *data) -{ - co_unsigned32_t val; - - UNUSED(sdo); - UNUSED(idx); - UNUSED(subidx); - UNUSED(data); - - if (ac == 0 && n >= sizeof(co_unsigned32_t)) - { - memcpy(&val, ptr, sizeof(val)); - printf("SDO: slave device type (0x1000) = 0x%08x\n", (unsigned)val); - } - else - { - printf("SDO: read failed, abort code 0x%08x\n", (unsigned)ac); - } - - g_sdo_done = true; -} - -/**************************************************************************** - * Name: on_time - ****************************************************************************/ - -static void on_time(co_time_t *time, const struct timespec *tp, void *data) -{ - UNUSED(time); - UNUSED(data); - - /* Update the wall clock */ - - clock_settime(CLOCK_REALTIME, tp); -} - -/**************************************************************************** - * Name: on_nmt_cs - ****************************************************************************/ - -static void on_nmt_cs(co_nmt_t *nmt, co_unsigned8_t cs, void *data) -{ - UNUSED(data); - - switch (cs) - { - case CO_NMT_CS_START: - case CO_NMT_CS_ENTER_PREOP: - { - co_time_set_ind(co_nmt_get_time(nmt), &on_time, NULL); - break; - } - - case CO_NMT_CS_RESET_NODE: - { - exit(0); - break; - } - - case CO_NMT_CS_STOP: - case CO_NMT_CS_RESET_COMM: - default: - { - break; - } - } -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: main - ****************************************************************************/ - -int main(int argc, FAR char *argv[]) -{ - struct timespec now; - struct can_msg msg; - struct timespec t0; - co_unsigned32_t last = 0xffffffff; - int phase = PHASE_WAIT; - int ret; - co_csdo_t *csdo; - co_unsigned32_t v; - - memset(&g_net, 0, sizeof(g_net)); - g_sdo_done = false; - setvbuf(stdout, NULL, _IONBF, 0); - - ret = comaster_candev_init(); - if (ret < 0) - { - printf("ERROR: comaster_candev_init failed %d\n", ret); - goto errout; - } - - g_net.net = can_net_create(); - if (!g_net.net) - { - printf("ERROR: can_net_create failed\n"); - goto errout; - } - - can_net_set_send_func(g_net.net, &on_can_send, NULL); - - clock_gettime(CLOCK_MONOTONIC, &now); - can_net_set_time(g_net.net, &now); - - /* Create dev from struct */ - - g_net.dev = co_dev_create_from_sdev(&g_sdev_master); - if (!g_net.dev) - { - printf("ERROR: co_dev_create_from_sdev failed\n"); - goto errout; - } - - g_net.nmt = co_nmt_create(g_net.net, g_net.dev); - if (!g_net.nmt) - { - printf("ERROR: co_nmt_create failed\n"); - goto errout; - } - - /* Start the NMT service by resetting the node */ - - co_nmt_cs_ind(g_net.nmt, CO_NMT_CS_RESET_NODE); - - /* Set the NMT indication function after the initial reset */ - - co_nmt_set_cs_ind(g_net.nmt, &on_nmt_cs, NULL); - - printf("lely CANopen master running (node 0x%02x)\n", g_sdev_master.id); - - clock_gettime(CLOCK_MONOTONIC, &t0); - - while (1) - { - clock_gettime(CLOCK_MONOTONIC, &now); - can_net_set_time(g_net.net, &now); - - while (comaster_candev_recv(&msg) > 0) - { - can_net_recv(g_net.net, &msg); - } - - switch (phase) - { - /* Give the slave time to boot, then read its device type with - * a Client-SDO transfer (works while both nodes are pre-op). - */ - - case PHASE_WAIT: - { - if (elapsed_ms(&now, &t0) >= 500) - { - csdo = co_nmt_get_csdo(g_net.nmt, 1); - if (csdo != NULL && co_csdo_up_req( - csdo, 0x1000, 0x00, &on_sdo_up, NULL) == 0) - { - phase = PHASE_SDO; - } - else - { - t0 = now; - } - } - - break; - } - - /* Once the SDO completes, bring the network to OPERATIONAL: - * the master itself and the slave (NMT start). PDO/SYNC then - * flow. - */ - - case PHASE_SDO: - { - if (g_sdo_done) - { - co_nmt_cs_ind(g_net.nmt, CO_NMT_CS_START); - nmt_start_remote(SLAVE_ID); - printf("NMT: master + slave 0x%02x OPERATIONAL\n", - SLAVE_ID); - phase = PHASE_RUN; - } - - break; - } - - /* The slave's synchronous TPDO lands in object 0x2100 via the - * RPDO mapping; print it whenever it changes. - */ - - case PHASE_RUN: - { - v = co_dev_get_val_u32(g_net.dev, OBJ_COUNTER, 0x00); - if (v != last) - { - printf("PDO rx: counter = %u\n", (unsigned)v); - last = v; - } - - break; - } - } - - usleep(1000); - } - -errout: - if (g_net.nmt) - { - co_nmt_destroy(g_net.nmt); - } - - if (g_net.dev) - { - co_dev_destroy(g_net.dev); - } - - if (g_net.net) - { - can_net_destroy(g_net.net); - } - - return 0; -} diff --git a/examples/lely_master/sdev.h b/examples/lely_master/sdev.h deleted file mode 100644 index 559b8468d..000000000 --- a/examples/lely_master/sdev.h +++ /dev/null @@ -1,41 +0,0 @@ -/**************************************************************************** - * apps/examples/lely_master/sdev.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __APPS_EXAMPLES_LELY_SDEV_H -#define __APPS_EXAMPLES_LELY_SDEV_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <canutils/lely/config.h> -#include <lely/co/sdev.h> - -/**************************************************************************** - * Public data - ****************************************************************************/ - -extern const struct co_sdev g_sdev_master; - -#endif /* __APPS_EXAMPLES_LELY_SDEV_H */ diff --git a/examples/lely_master/sdev_master.c b/examples/lely_master/sdev_master.c deleted file mode 100644 index 34d5c6620..000000000 --- a/examples/lely_master/sdev_master.c +++ /dev/null @@ -1,714 +0,0 @@ -/**************************************************************************** - * apps/examples/lely_master/sdev_master.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include "sdev.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define CO_SDEV_STRING(s) s - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/* Object 0x1000 sub-objects */ - -static const struct co_ssub g_1000_sub[] = -{ - { -#if !LELY_NO_CO_OBJ_NAME - .name = CO_SDEV_STRING("Device type"), -#endif - .subidx = 0x00, - .type = CO_DEFTYPE_UNSIGNED32, -#if !LELY_NO_CO_OBJ_LIMITS - .min.u32 = CO_UNSIGNED32_MIN, - .max.u32 = CO_UNSIGNED32_MAX, -#endif -#if !LELY_NO_CO_OBJ_DEFAULT - .def.u32 = CO_UNSIGNED32_MIN, -#endif - .val.u32 = CO_UNSIGNED32_MIN, - .access = CO_ACCESS_RO, - .pdo_mapping = 0, - .flags = 0 - } -}; - -/* Object 0x1001 sub-objects */ - -static const struct co_ssub g_1001_sub[] = -{ - { -#if !LELY_NO_CO_OBJ_NAME - .name = CO_SDEV_STRING("Error register"), -#endif - .subidx = 0x00, - .type = CO_DEFTYPE_UNSIGNED8, -#if !LELY_NO_CO_OBJ_LIMITS - .min.u8 = CO_UNSIGNED8_MIN, - .max.u8 = CO_UNSIGNED8_MAX, -#endif -#if !LELY_NO_CO_OBJ_DEFAULT - .def.u8 = CO_UNSIGNED8_MIN, -#endif - .val.u8 = CO_UNSIGNED8_MIN, - .access = CO_ACCESS_RO, - .pdo_mapping = 0, - .flags = 0 - } -}; - -/* Object 0x1005 sub-objects */ - -static const struct co_ssub g_1005_sub[] = -{ - { -#if !LELY_NO_CO_OBJ_NAME - .name = CO_SDEV_STRING("COB-ID SYNC message"), -#endif - .subidx = 0x00, - .type = CO_DEFTYPE_UNSIGNED32, -#if !LELY_NO_CO_OBJ_LIMITS - .min.u32 = CO_UNSIGNED32_MIN, - .max.u32 = CO_UNSIGNED32_MAX, -#endif -#if !LELY_NO_CO_OBJ_DEFAULT - .def.u32 = 0x40000080lu, -#endif - .val.u32 = 0x40000080lu, - .access = CO_ACCESS_RW, - .pdo_mapping = 0, - .flags = 0 - } -}; - -/* Object 0x1006 sub-objects */ - -static const struct co_ssub g_1006_sub[] = -{ - { -#if !LELY_NO_CO_OBJ_NAME - .name = CO_SDEV_STRING("Communication cycle period"), -#endif - .subidx = 0x00, - .type = CO_DEFTYPE_UNSIGNED32, -#if !LELY_NO_CO_OBJ_LIMITS - .min.u32 = CO_UNSIGNED32_MIN, - .max.u32 = CO_UNSIGNED32_MAX, -#endif -#if !LELY_NO_CO_OBJ_DEFAULT - .def.u32 = 0x000186a0lu, -#endif - .val.u32 = 0x000186a0lu, - .access = CO_ACCESS_RW, - .pdo_mapping = 0, - .flags = 0 - } -}; - -/* Object 0x1012 sub-objects */ - -static const struct co_ssub g_1012_sub[] = -{ - { -#if !LELY_NO_CO_OBJ_NAME - .name = CO_SDEV_STRING("COB-ID time stamp object"), -#endif - .subidx = 0x00, - .type = CO_DEFTYPE_UNSIGNED32, -#if !LELY_NO_CO_OBJ_LIMITS - .min.u32 = CO_UNSIGNED32_MIN, - .max.u32 = CO_UNSIGNED32_MAX, -#endif -#if !LELY_NO_CO_OBJ_DEFAULT - .def.u32 = 0x80000100lu, -#endif - .val.u32 = 0x80000100lu, - .access = CO_ACCESS_RW, - .pdo_mapping = 0, - .flags = 0 - } -}; - -/* Object 0x1017 sub-objects */ - -static const struct co_ssub g_1017_sub[] = -{ - { -#if !LELY_NO_CO_OBJ_NAME - .name = CO_SDEV_STRING("Producer heartbeat time"), -#endif - .subidx = 0x00, - .type = CO_DEFTYPE_UNSIGNED16, -#if !LELY_NO_CO_OBJ_LIMITS - .min.u16 = CO_UNSIGNED16_MIN, - .max.u16 = CO_UNSIGNED16_MAX, -#endif -#if !LELY_NO_CO_OBJ_DEFAULT - .def.u16 = 0x0032, -#endif - .val.u16 = 0x0032, - .access = CO_ACCESS_RW, - .pdo_mapping = 0, - .flags = 0 - } -}; - -/* Object 0x1018 sub-objects */ - -static const struct co_ssub g_1018_sub[] = -{ - { -#if !LELY_NO_CO_OBJ_NAME - .name = CO_SDEV_STRING("Highest sub-index supported"), -#endif - .subidx = 0x00, - .type = CO_DEFTYPE_UNSIGNED8, -#if !LELY_NO_CO_OBJ_LIMITS - .min.u8 = CO_UNSIGNED8_MIN, - .max.u8 = CO_UNSIGNED8_MAX, -#endif -#if !LELY_NO_CO_OBJ_DEFAULT - .def.u8 = 0x04, -#endif - .val.u8 = 0x04, - .access = CO_ACCESS_CONST, - .pdo_mapping = 0, - .flags = 0 - }, - { -#if !LELY_NO_CO_OBJ_NAME - .name = CO_SDEV_STRING("Vendor-ID"), -#endif - .subidx = 0x01, - .type = CO_DEFTYPE_UNSIGNED32, -#if !LELY_NO_CO_OBJ_LIMITS - .min.u32 = CO_UNSIGNED32_MIN, - .max.u32 = CO_UNSIGNED32_MAX, -#endif -#if !LELY_NO_CO_OBJ_DEFAULT - .def.u32 = 0x00000360lu, -#endif - .val.u32 = 0x00000360lu, - .access = CO_ACCESS_RO, - .pdo_mapping = 0, - .flags = 0 - }, - { -#if !LELY_NO_CO_OBJ_NAME - .name = CO_SDEV_STRING("Product code"), -#endif - .subidx = 0x02, - .type = CO_DEFTYPE_UNSIGNED32, -#if !LELY_NO_CO_OBJ_LIMITS - .min.u32 = CO_UNSIGNED32_MIN, - .max.u32 = CO_UNSIGNED32_MAX, -#endif -#if !LELY_NO_CO_OBJ_DEFAULT - .def.u32 = CO_UNSIGNED32_MIN, -#endif - .val.u32 = CO_UNSIGNED32_MIN, - .access = CO_ACCESS_RO, - .pdo_mapping = 0, - .flags = 0 - }, - { -#if !LELY_NO_CO_OBJ_NAME - .name = CO_SDEV_STRING("Revision number"), -#endif - .subidx = 0x03, - .type = CO_DEFTYPE_UNSIGNED32, -#if !LELY_NO_CO_OBJ_LIMITS - .min.u32 = CO_UNSIGNED32_MIN, - .max.u32 = CO_UNSIGNED32_MAX, -#endif -#if !LELY_NO_CO_OBJ_DEFAULT - .def.u32 = CO_UNSIGNED32_MIN, -#endif - .val.u32 = CO_UNSIGNED32_MIN, - .access = CO_ACCESS_RO, - .pdo_mapping = 0, - .flags = 0 - }, - { -#if !LELY_NO_CO_OBJ_NAME - .name = CO_SDEV_STRING("Serial number"), -#endif - .subidx = 0x04, - .type = CO_DEFTYPE_UNSIGNED32, -#if !LELY_NO_CO_OBJ_LIMITS - .min.u32 = CO_UNSIGNED32_MIN, - .max.u32 = CO_UNSIGNED32_MAX, -#endif -#if !LELY_NO_CO_OBJ_DEFAULT - .def.u32 = CO_UNSIGNED32_MIN, -#endif - .val.u32 = CO_UNSIGNED32_MIN, - .access = CO_ACCESS_RO, - .pdo_mapping = 0, - .flags = 0 - } -}; - -/* Object 0x1280 sub-objects */ - -static const struct co_ssub g_1280_sub[] = -{ - { -#if !LELY_NO_CO_OBJ_NAME - .name = CO_SDEV_STRING("Highest sub-index supported"), -#endif - .subidx = 0x00, - .type = CO_DEFTYPE_UNSIGNED8, -#if !LELY_NO_CO_OBJ_LIMITS - .min.u8 = CO_UNSIGNED8_MIN, - .max.u8 = CO_UNSIGNED8_MAX, -#endif -#if !LELY_NO_CO_OBJ_DEFAULT - .def.u8 = 0x03, -#endif - .val.u8 = 0x03, - .access = CO_ACCESS_CONST, - .pdo_mapping = 0, - .flags = 0 - }, - { -#if !LELY_NO_CO_OBJ_NAME - .name = CO_SDEV_STRING("COB-ID client to server"), -#endif - .subidx = 0x01, - .type = CO_DEFTYPE_UNSIGNED32, -#if !LELY_NO_CO_OBJ_LIMITS - .min.u32 = CO_UNSIGNED32_MIN, - .max.u32 = CO_UNSIGNED32_MAX, -#endif -#if !LELY_NO_CO_OBJ_DEFAULT - .def.u32 = 0x00000602lu, -#endif - .val.u32 = 0x00000602lu, - .access = CO_ACCESS_RW, - .pdo_mapping = 0, - .flags = 0 - }, - { -#if !LELY_NO_CO_OBJ_NAME - .name = CO_SDEV_STRING("COB-ID server to client"), -#endif - .subidx = 0x02, - .type = CO_DEFTYPE_UNSIGNED32, -#if !LELY_NO_CO_OBJ_LIMITS - .min.u32 = CO_UNSIGNED32_MIN, - .max.u32 = CO_UNSIGNED32_MAX, -#endif -#if !LELY_NO_CO_OBJ_DEFAULT - .def.u32 = 0x00000582lu, -#endif - .val.u32 = 0x00000582lu, - .access = CO_ACCESS_RW, - .pdo_mapping = 0, - .flags = 0 - }, - { -#if !LELY_NO_CO_OBJ_NAME - .name = CO_SDEV_STRING("Node-ID of the SDO server"), -#endif - .subidx = 0x03, - .type = CO_DEFTYPE_UNSIGNED8, -#if !LELY_NO_CO_OBJ_LIMITS - .min.u8 = CO_UNSIGNED8_MIN, - .max.u8 = CO_UNSIGNED8_MAX, -#endif -#if !LELY_NO_CO_OBJ_DEFAULT - .def.u8 = 0x02, -#endif - .val.u8 = 0x02, - .access = CO_ACCESS_RW, - .pdo_mapping = 0, - .flags = 0 - } -}; - -/* Object 0x1400 sub-objects */ - -static const struct co_ssub g_1400_sub[] = -{ - { -#if !LELY_NO_CO_OBJ_NAME - .name = CO_SDEV_STRING("Highest sub-index supported"), -#endif - .subidx = 0x00, - .type = CO_DEFTYPE_UNSIGNED8, -#if !LELY_NO_CO_OBJ_LIMITS - .min.u8 = CO_UNSIGNED8_MIN, - .max.u8 = CO_UNSIGNED8_MAX, -#endif -#if !LELY_NO_CO_OBJ_DEFAULT - .def.u8 = 0x02, -#endif - .val.u8 = 0x02, - .access = CO_ACCESS_CONST, - .pdo_mapping = 0, - .flags = 0 - }, - { -#if !LELY_NO_CO_OBJ_NAME - .name = CO_SDEV_STRING("COB-ID"), -#endif - .subidx = 0x01, - .type = CO_DEFTYPE_UNSIGNED32, -#if !LELY_NO_CO_OBJ_LIMITS - .min.u32 = CO_UNSIGNED32_MIN, - .max.u32 = CO_UNSIGNED32_MAX, -#endif -#if !LELY_NO_CO_OBJ_DEFAULT - .def.u32 = 0x00000182lu, -#endif - .val.u32 = 0x00000182lu, - .access = CO_ACCESS_RW, - .pdo_mapping = 0, - .flags = 0 - }, - { -#if !LELY_NO_CO_OBJ_NAME - .name = CO_SDEV_STRING("Transmission type"), -#endif - .subidx = 0x02, - .type = CO_DEFTYPE_UNSIGNED8, -#if !LELY_NO_CO_OBJ_LIMITS - .min.u8 = CO_UNSIGNED8_MIN, - .max.u8 = CO_UNSIGNED8_MAX, -#endif -#if !LELY_NO_CO_OBJ_DEFAULT - .def.u8 = 0x01, -#endif - .val.u8 = 0x01, - .access = CO_ACCESS_RW, - .pdo_mapping = 0, - .flags = 0 - } -}; - -/* Object 0x1600 sub-objects */ - -static const struct co_ssub g_1600_sub[] = -{ - { -#if !LELY_NO_CO_OBJ_NAME - .name = CO_SDEV_STRING("Number of mapped objects"), -#endif - .subidx = 0x00, - .type = CO_DEFTYPE_UNSIGNED8, -#if !LELY_NO_CO_OBJ_LIMITS - .min.u8 = CO_UNSIGNED8_MIN, - .max.u8 = CO_UNSIGNED8_MAX, -#endif -#if !LELY_NO_CO_OBJ_DEFAULT - .def.u8 = 0x01, -#endif - .val.u8 = 0x01, - .access = CO_ACCESS_RW, - .pdo_mapping = 0, - .flags = 0 - }, - { -#if !LELY_NO_CO_OBJ_NAME - .name = CO_SDEV_STRING("Mapping 1"), -#endif - .subidx = 0x01, - .type = CO_DEFTYPE_UNSIGNED32, -#if !LELY_NO_CO_OBJ_LIMITS - .min.u32 = CO_UNSIGNED32_MIN, - .max.u32 = CO_UNSIGNED32_MAX, -#endif -#if !LELY_NO_CO_OBJ_DEFAULT - .def.u32 = 0x21000020lu, -#endif - .val.u32 = 0x21000020lu, - .access = CO_ACCESS_RW, - .pdo_mapping = 0, - .flags = 0 - } -}; - -/* Object 0x1f80 sub-objects */ - -static const struct co_ssub g_1f80_sub[] = -{ - { -#if !LELY_NO_CO_OBJ_NAME - .name = CO_SDEV_STRING("NMT startup"), -#endif - .subidx = 0x00, - .type = CO_DEFTYPE_UNSIGNED32, -#if !LELY_NO_CO_OBJ_LIMITS - .min.u32 = CO_UNSIGNED32_MIN, - .max.u32 = CO_UNSIGNED32_MAX, -#endif -#if !LELY_NO_CO_OBJ_DEFAULT - .def.u32 = CO_UNSIGNED32_MIN, -#endif - .val.u32 = 0x00000000lu, - .access = CO_ACCESS_RW, - .pdo_mapping = 0, - .flags = 0 - | CO_OBJ_FLAGS_PARAMETER_VALUE - } -}; - -/* Object 0x2000 sub-objects */ - -static const struct co_ssub g_2000_sub[] = -{ - { -#if !LELY_NO_CO_OBJ_NAME - .name = CO_SDEV_STRING("Object with custom SDO download callback"), -#endif - .subidx = 0x00, - .type = CO_DEFTYPE_UNSIGNED32, -#if !LELY_NO_CO_OBJ_LIMITS - .min.u32 = CO_UNSIGNED32_MIN, - .max.u32 = CO_UNSIGNED32_MAX, -#endif -#if !LELY_NO_CO_OBJ_DEFAULT - .def.u32 = CO_UNSIGNED32_MIN, -#endif - .val.u32 = CO_UNSIGNED32_MIN, - .access = CO_ACCESS_RW, - .pdo_mapping = 0, - .flags = 0 - } -}; - -/* Object 0x2001 sub-objects */ - -static const struct co_ssub g_2001_sub[] = -{ - { -#if !LELY_NO_CO_OBJ_NAME - .name = CO_SDEV_STRING("Object with custom SDO upload callback"), -#endif - .subidx = 0x00, - .type = CO_DEFTYPE_UNSIGNED32, -#if !LELY_NO_CO_OBJ_LIMITS - .min.u32 = CO_UNSIGNED32_MIN, - .max.u32 = CO_UNSIGNED32_MAX, -#endif -#if !LELY_NO_CO_OBJ_DEFAULT - .def.u32 = CO_UNSIGNED32_MIN, -#endif - .val.u32 = CO_UNSIGNED32_MIN, - .access = CO_ACCESS_RO, - .pdo_mapping = 0, - .flags = 0 - } -}; - -/* Object 0x2100 sub-objects */ - -static const struct co_ssub g_2100_sub[] = -{ - { -#if !LELY_NO_CO_OBJ_NAME - .name = CO_SDEV_STRING("Counter"), -#endif - .subidx = 0x00, - .type = CO_DEFTYPE_UNSIGNED32, -#if !LELY_NO_CO_OBJ_LIMITS - .min.u32 = CO_UNSIGNED32_MIN, - .max.u32 = CO_UNSIGNED32_MAX, -#endif -#if !LELY_NO_CO_OBJ_DEFAULT - .def.u32 = CO_UNSIGNED32_MIN, -#endif - .val.u32 = CO_UNSIGNED32_MIN, - .access = CO_ACCESS_RW, - .pdo_mapping = 1, - .flags = 0 - } -}; - -/* Object dictionary */ - -static const struct co_sobj g_g_sdev_master_objs[] = -{ - { -#if !LELY_NO_CO_OBJ_NAME - .name = CO_SDEV_STRING("Device type"), -#endif - .idx = 0x1000, - .code = CO_OBJECT_VAR, - .nsub = 1, - .subs = g_1000_sub - }, - { -#if !LELY_NO_CO_OBJ_NAME - .name = CO_SDEV_STRING("Error register"), -#endif - .idx = 0x1001, - .code = CO_OBJECT_VAR, - .nsub = 1, - .subs = g_1001_sub - }, - { -#if !LELY_NO_CO_OBJ_NAME - .name = CO_SDEV_STRING("COB-ID SYNC message"), -#endif - .idx = 0x1005, - .code = CO_OBJECT_VAR, - .nsub = 1, - .subs = g_1005_sub - }, - { -#if !LELY_NO_CO_OBJ_NAME - .name = CO_SDEV_STRING("Communication cycle period"), -#endif - .idx = 0x1006, - .code = CO_OBJECT_VAR, - .nsub = 1, - .subs = g_1006_sub - }, - { -#if !LELY_NO_CO_OBJ_NAME - .name = CO_SDEV_STRING("COB-ID time stamp object"), -#endif - .idx = 0x1012, - .code = CO_OBJECT_VAR, - .nsub = 1, - .subs = g_1012_sub - }, - { -#if !LELY_NO_CO_OBJ_NAME - .name = CO_SDEV_STRING("Producer heartbeat time"), -#endif - .idx = 0x1017, - .code = CO_OBJECT_VAR, - .nsub = 1, - .subs = g_1017_sub - }, - { -#if !LELY_NO_CO_OBJ_NAME - .name = CO_SDEV_STRING("Identity object"), -#endif - .idx = 0x1018, - .code = CO_OBJECT_RECORD, - .nsub = 5, - .subs = g_1018_sub - }, - { -#if !LELY_NO_CO_OBJ_NAME - .name = CO_SDEV_STRING("SDO client parameter"), -#endif - .idx = 0x1280, - .code = CO_OBJECT_RECORD, - .nsub = 4, - .subs = g_1280_sub - }, - { -#if !LELY_NO_CO_OBJ_NAME - .name = CO_SDEV_STRING("RPDO communication parameter"), -#endif - .idx = 0x1400, - .code = CO_OBJECT_RECORD, - .nsub = 3, - .subs = g_1400_sub - }, - { -#if !LELY_NO_CO_OBJ_NAME - .name = CO_SDEV_STRING("RPDO mapping parameter"), -#endif - .idx = 0x1600, - .code = CO_OBJECT_RECORD, - .nsub = 2, - .subs = g_1600_sub - }, - { -#if !LELY_NO_CO_OBJ_NAME - .name = CO_SDEV_STRING("NMT startup"), -#endif - .idx = 0x1f80, - .code = CO_OBJECT_VAR, - .nsub = 1, - .subs = g_1f80_sub - }, - { -#if !LELY_NO_CO_OBJ_NAME - .name = CO_SDEV_STRING("Object with custom SDO download callback"), -#endif - .idx = 0x2000, - .code = CO_OBJECT_VAR, - .nsub = 1, - .subs = g_2000_sub - }, - { -#if !LELY_NO_CO_OBJ_NAME - .name = CO_SDEV_STRING("Object with custom SDO upload callback"), -#endif - .idx = 0x2001, - .code = CO_OBJECT_VAR, - .nsub = 1, - .subs = g_2001_sub - }, - { -#if !LELY_NO_CO_OBJ_NAME - .name = CO_SDEV_STRING("Counter"), -#endif - .idx = 0x2100, - .code = CO_OBJECT_VAR, - .nsub = 1, - .subs = g_2100_sub - } -}; - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -const struct co_sdev g_sdev_master = -{ - .id = 0x01, - .name = NULL, - .vendor_name = CO_SDEV_STRING("Apache NuttX RTOS"), - .vendor_id = 0x00000000, - .product_name = NULL, - .product_code = 0x00000000, - .revision = 0x00000000, - .order_code = NULL, - .baud = CO_BAUD_125, - .rate = 0, - .lss = 0, - .dummy = 0x000000fe, - .nobj = 14, - .objs = g_g_sdev_master_objs -}; - -/**************************************************************************** - * Public Functions - ****************************************************************************/ diff --git a/examples/lely_slave/CMakeLists.txt b/examples/lely_slave/CMakeLists.txt deleted file mode 100644 index 4ffdb62ea..000000000 --- a/examples/lely_slave/CMakeLists.txt +++ /dev/null @@ -1,55 +0,0 @@ -# ############################################################################## -# apps/examples/lely_slave/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_LELYSLAVE) - - set(LELY_INCDIR ${NUTTX_APPS_DIR}/canutils/lely-canopen/lely-core/include) - - # The main source must be first so it receives the main=coslave_main alias - - set(SRCS slave_main.c sdev_slave.c) - - if(CONFIG_EXAMPLES_LELYSLAVE_CHARDEV) - list(APPEND SRCS candev_char.c) - endif() - - if(CONFIG_EXAMPLES_LELYSLAVE_SOCKET) - list(APPEND SRCS candev_sock.c) - endif() - - nuttx_add_application( - NAME - coslave - PRIORITY - ${CONFIG_EXAMPLES_LELYSLAVE_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_LELYSLAVE_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_LELYSLAVE} - COMPILE_FLAGS - -Wno-undef - INCLUDE_DIRECTORIES - ${LELY_INCDIR} - SRCS - ${SRCS}) - -endif() diff --git a/examples/lely_slave/Kconfig b/examples/lely_slave/Kconfig deleted file mode 100644 index de8f9d30a..000000000 --- a/examples/lely_slave/Kconfig +++ /dev/null @@ -1,49 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config EXAMPLES_LELYSLAVE - tristate "Lely CANopen slave example" - default n - depends on CANUTILS_LELYCANOPEN && CANUTILS_LELYCANOPEN_SDEV - depends on CANUTILS_LELYCANOPEN_TIME && CANUTILS_LELYCANOPEN_OBJUPLOAD - ---help--- - Enable the Lely CANopen slave (coslave) example application. - -if EXAMPLES_LELYSLAVE - -choice - prompt "CAN backend" - default EXAMPLES_LELYSLAVE_CHARDEV - -config EXAMPLES_LELYSLAVE_CHARDEV - bool "CAN character driver" - depends on CAN - -config EXAMPLES_LELYSLAVE_SOCKET - bool "SocketCAN" - depends on NET_CAN - select NETUTILS_NETLIB - -endchoice - -config EXAMPLES_LELYSLAVE_DEVPATH - string "CAN character device path" - default "/dev/can0" - depends on EXAMPLES_LELYSLAVE_CHARDEV - -config EXAMPLES_LELYSLAVE_INTF - string "SocketCAN interface" - default "can0" - depends on EXAMPLES_LELYSLAVE_SOCKET - -config EXAMPLES_LELYSLAVE_PRIORITY - int "Task priority" - default 100 - -config EXAMPLES_LELYSLAVE_STACKSIZE - int "Stack size" - default DEFAULT_TASK_STACKSIZE - -endif diff --git a/examples/lely_slave/Make.defs b/examples/lely_slave/Make.defs deleted file mode 100644 index 20382554f..000000000 --- a/examples/lely_slave/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/examples/lely_slave/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_EXAMPLES_LELYSLAVE),) -CONFIGURED_APPS += $(APPDIR)/examples/lely_slave -endif diff --git a/examples/lely_slave/Makefile b/examples/lely_slave/Makefile deleted file mode 100644 index dcc135012..000000000 --- a/examples/lely_slave/Makefile +++ /dev/null @@ -1,47 +0,0 @@ -############################################################################ -# apps/examples/lely_slave/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -PROGNAME = coslave -PRIORITY = $(CONFIG_EXAMPLES_LELYSLAVE_PRIORITY) -STACKSIZE = $(CONFIG_EXAMPLES_LELYSLAVE_STACKSIZE) -MODULE = $(CONFIG_EXAMPLES_LELYSLAVE) - -CFLAGS += -DHAVE_CONFIG_H=1 - -# Lely headers use bare "#if __cplusplus"; silence -Wundef like the library - -CFLAGS += -Wno-undef - -CSRCS = sdev_slave.c - -ifeq ($(CONFIG_EXAMPLES_LELYSLAVE_CHARDEV),y) -CSRCS += candev_char.c -endif -ifeq ($(CONFIG_EXAMPLES_LELYSLAVE_SOCKET),y) -CSRCS += candev_sock.c -endif - -MAINSRC = slave_main.c - -include $(APPDIR)/Application.mk diff --git a/examples/lely_slave/candev.h b/examples/lely_slave/candev.h deleted file mode 100644 index e044f8e89..000000000 --- a/examples/lely_slave/candev.h +++ /dev/null @@ -1,44 +0,0 @@ -/**************************************************************************** - * apps/examples/lely_slave/candev.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __APPS_EXAMPLES_LELY_SLAVE_CANDEV_H -#define __APPS_EXAMPLES_LELY_SLAVE_CANDEV_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <canutils/lely/config.h> - -#include <lely/can/msg.h> - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -int coslave_candev_init(void); -int coslave_candev_send(FAR const struct can_msg *msg); -int coslave_candev_recv(FAR struct can_msg *msg); - -#endif /* __APPS_EXAMPLES_LELY_SLAVE_CANDEV_H */ diff --git a/examples/lely_slave/candev_char.c b/examples/lely_slave/candev_char.c deleted file mode 100644 index 71c2aed11..000000000 --- a/examples/lely_slave/candev_char.c +++ /dev/null @@ -1,173 +0,0 @@ -/**************************************************************************** - * apps/examples/lely_slave/candev_char.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <stdio.h> -#include <fcntl.h> -#include <errno.h> -#include <unistd.h> - -#include <sys/types.h> -#include <sys/ioctl.h> - -#include <nuttx/can/can.h> - -#include "candev.h" - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static int g_candev_fd; - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: coslave_candev_init - ****************************************************************************/ - -int coslave_candev_init(void) -{ - struct canioc_bittiming_s bt; - int ret; - - /* Non-blocking so the main loop keeps servicing the CANopen timers */ - - g_candev_fd = open(CONFIG_EXAMPLES_LELYSLAVE_DEVPATH, - O_RDWR | O_NONBLOCK); - if (g_candev_fd < 0) - { - ret = -errno; - printf("ERROR: open %s failed %d\n", - CONFIG_EXAMPLES_LELYSLAVE_DEVPATH, errno); - return ret; - } - - ret = ioctl(g_candev_fd, CANIOC_GET_BITTIMING, &bt); - if (ret < 0) - { - printf("Bit timing not available: %d\n", errno); - } - else - { - printf("Bit timing:\n"); - printf(" Baud: %lu\n", (unsigned long)bt.bt_baud); - printf(" TSEG1: %u\n", bt.bt_tseg1); - printf(" TSEG2: %u\n", bt.bt_tseg2); - printf(" SJW: %u\n", bt.bt_sjw); - } - - return OK; -} - -/**************************************************************************** - * Name: coslave_candev_send - ****************************************************************************/ - -int coslave_candev_send(FAR const struct can_msg *msg) -{ - struct can_msg_s txmsg; - ssize_t nwritten; - int i; - - txmsg.cm_hdr.ch_id = msg->id; - txmsg.cm_hdr.ch_rtr = (msg->flags & CAN_FLAG_RTR) != 0; - txmsg.cm_hdr.ch_dlc = msg->len; -#ifdef CONFIG_CAN_EXTID - txmsg.cm_hdr.ch_extid = (msg->flags & CAN_FLAG_IDE) != 0; -#endif -#ifdef CONFIG_CAN_ERRORS - txmsg.cm_hdr.ch_error = 0; -#endif - txmsg.cm_hdr.ch_tcf = 0; - - for (i = 0; i < msg->len; i++) - { - txmsg.cm_data[i] = msg->data[i]; - } - - nwritten = write(g_candev_fd, &txmsg, CAN_MSGLEN(txmsg.cm_hdr.ch_dlc)); - if (nwritten != CAN_MSGLEN(txmsg.cm_hdr.ch_dlc)) - { - return -1; - } - - return 0; -} - -/**************************************************************************** - * Name: coslave_candev_recv - ****************************************************************************/ - -int coslave_candev_recv(FAR struct can_msg *msg) -{ - struct can_msg_s rxmsg; - ssize_t nread; - int i; - - nread = read(g_candev_fd, &rxmsg, sizeof(struct can_msg_s)); - if (nread < 0) - { - if (errno == EAGAIN || errno == EWOULDBLOCK) - { - return 0; - } - - return -1; - } - - if (nread < CAN_MSGLEN(0)) - { - return 0; - } - - msg->id = rxmsg.cm_hdr.ch_id; - msg->flags = 0; - -#ifdef CONFIG_CAN_EXTID - if (rxmsg.cm_hdr.ch_extid) - { - msg->flags |= CAN_FLAG_IDE; - } -#endif - - if (rxmsg.cm_hdr.ch_rtr) - { - msg->flags |= CAN_FLAG_RTR; - } - - msg->len = rxmsg.cm_hdr.ch_dlc; - - for (i = 0; i < rxmsg.cm_hdr.ch_dlc; i++) - { - msg->data[i] = rxmsg.cm_data[i]; - } - - return 1; -} diff --git a/examples/lely_slave/candev_sock.c b/examples/lely_slave/candev_sock.c deleted file mode 100644 index d52db0b97..000000000 --- a/examples/lely_slave/candev_sock.c +++ /dev/null @@ -1,197 +0,0 @@ -/**************************************************************************** - * apps/examples/lely_slave/candev_sock.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <stdio.h> -#include <string.h> -#include <fcntl.h> -#include <errno.h> -#include <unistd.h> - -#include <net/if.h> -#include <sys/socket.h> - -#include <nuttx/can.h> - -#include "netutils/netlib.h" -#include "candev.h" - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static int g_candev_sock; - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: coslave_candev_init - ****************************************************************************/ - -int coslave_candev_init(void) -{ - struct sockaddr_can addr; - struct ifreq ifr; - int on = 1; - int ret; - - g_candev_sock = socket(PF_CAN, SOCK_RAW, CAN_RAW); - if (g_candev_sock < 0) - { - ret = -errno; - printf("ERROR: socket failed %d\n", errno); - return ret; - } - - strlcpy(ifr.ifr_name, CONFIG_EXAMPLES_LELYSLAVE_INTF, IFNAMSIZ); - - /* SocketCAN silently drops traffic while the interface is down, so bring - * it up here. This lets the example run without a separate "ifup" step. - */ - - if (netlib_ifup(ifr.ifr_name) < 0) - { - ret = -errno; - printf("ERROR: netlib_ifup %s failed %d\n", ifr.ifr_name, errno); - goto errout; - } - - ifr.ifr_ifindex = if_nametoindex(ifr.ifr_name); - if (ifr.ifr_ifindex == 0) - { - ret = -errno; - printf("ERROR: if_nametoindex %s failed %d\n", ifr.ifr_name, errno); - goto errout; - } - - setsockopt(g_candev_sock, SOL_CAN_RAW, CAN_RAW_RECV_OWN_MSGS, - &on, sizeof(on)); - - memset(&addr, 0, sizeof(addr)); - addr.can_family = AF_CAN; - addr.can_ifindex = ifr.ifr_ifindex; - - if (bind(g_candev_sock, (FAR struct sockaddr *)&addr, sizeof(addr)) < 0) - { - ret = -errno; - printf("ERROR: bind failed %d\n", errno); - goto errout; - } - - ret = fcntl(g_candev_sock, F_SETFL, O_NONBLOCK); - if (ret < 0) - { - ret = -errno; - goto errout; - } - - return OK; - -errout: - close(g_candev_sock); - g_candev_sock = -1; - return ret; -} - -/**************************************************************************** - * Name: coslave_candev_send - ****************************************************************************/ - -int coslave_candev_send(FAR const struct can_msg *msg) -{ - struct can_frame frame; - ssize_t nwritten; - - memset(&frame, 0, sizeof(frame)); - - frame.can_id = msg->id; - if (msg->flags & CAN_FLAG_IDE) - { - frame.can_id |= CAN_EFF_FLAG; - } - - if (msg->flags & CAN_FLAG_RTR) - { - frame.can_id |= CAN_RTR_FLAG; - } - - frame.can_dlc = msg->len; - memcpy(frame.data, msg->data, msg->len); - - nwritten = write(g_candev_sock, &frame, sizeof(frame)); - if (nwritten != sizeof(frame)) - { - return -1; - } - - return 0; -} - -/**************************************************************************** - * Name: coslave_candev_recv - ****************************************************************************/ - -int coslave_candev_recv(FAR struct can_msg *msg) -{ - struct can_frame frame; - ssize_t nread; - - nread = read(g_candev_sock, &frame, sizeof(frame)); - if (nread < 0) - { - if (errno == EAGAIN || errno == EWOULDBLOCK) - { - return 0; - } - - return -1; - } - - if (nread < sizeof(frame)) - { - return 0; - } - - msg->id = frame.can_id & CAN_EFF_MASK; - msg->flags = 0; - if (frame.can_id & CAN_EFF_FLAG) - { - msg->flags |= CAN_FLAG_IDE; - } - - if (frame.can_id & CAN_RTR_FLAG) - { - msg->flags |= CAN_FLAG_RTR; - } - - msg->len = frame.can_dlc; - memcpy(msg->data, frame.data, frame.can_dlc); - - return 1; -} diff --git a/examples/lely_slave/sdev.h b/examples/lely_slave/sdev.h deleted file mode 100644 index ca13a532d..000000000 --- a/examples/lely_slave/sdev.h +++ /dev/null @@ -1,41 +0,0 @@ -/**************************************************************************** - * apps/examples/lely_slave/sdev.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __APPS_EXAMPLES_LELY_SDEV_H -#define __APPS_EXAMPLES_LELY_SDEV_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <canutils/lely/config.h> -#include <lely/co/sdev.h> - -/**************************************************************************** - * Public data - ****************************************************************************/ - -extern const struct co_sdev g_sdev_slave; - -#endif /* __APPS_EXAMPLES_LELY_SDEV_H */ diff --git a/examples/lely_slave/sdev_slave.c b/examples/lely_slave/sdev_slave.c deleted file mode 100644 index 8f71558f5..000000000 --- a/examples/lely_slave/sdev_slave.c +++ /dev/null @@ -1,594 +0,0 @@ -/**************************************************************************** - * apps/examples/lely_slave/sdev_slave.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include "sdev.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define CO_SDEV_STRING(s) s - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/* Object 0x1000 sub-objects */ - -static const struct co_ssub g_1000_sub[] = -{ - { -#if !LELY_NO_CO_OBJ_NAME - .name = CO_SDEV_STRING("Device type"), -#endif - .subidx = 0x00, - .type = CO_DEFTYPE_UNSIGNED32, -#if !LELY_NO_CO_OBJ_LIMITS - .min.u32 = CO_UNSIGNED32_MIN, - .max.u32 = CO_UNSIGNED32_MAX, -#endif -#if !LELY_NO_CO_OBJ_DEFAULT - .def.u32 = CO_UNSIGNED32_MIN, -#endif - .val.u32 = CO_UNSIGNED32_MIN, - .access = CO_ACCESS_RO, - .pdo_mapping = 0, - .flags = 0 - } -}; - -/* Object 0x1001 sub-objects */ - -static const struct co_ssub g_1001_sub[] = -{ - { -#if !LELY_NO_CO_OBJ_NAME - .name = CO_SDEV_STRING("Error register"), -#endif - .subidx = 0x00, - .type = CO_DEFTYPE_UNSIGNED8, -#if !LELY_NO_CO_OBJ_LIMITS - .min.u8 = CO_UNSIGNED8_MIN, - .max.u8 = CO_UNSIGNED8_MAX, -#endif -#if !LELY_NO_CO_OBJ_DEFAULT - .def.u8 = CO_UNSIGNED8_MIN, -#endif - .val.u8 = CO_UNSIGNED8_MIN, - .access = CO_ACCESS_RO, - .pdo_mapping = 0, - .flags = 0 - } -}; - -/* Object 0x1005 sub-objects */ - -static const struct co_ssub g_1005_sub[] = -{ - { -#if !LELY_NO_CO_OBJ_NAME - .name = CO_SDEV_STRING("COB-ID SYNC message"), -#endif - .subidx = 0x00, - .type = CO_DEFTYPE_UNSIGNED32, -#if !LELY_NO_CO_OBJ_LIMITS - .min.u32 = CO_UNSIGNED32_MIN, - .max.u32 = CO_UNSIGNED32_MAX, -#endif -#if !LELY_NO_CO_OBJ_DEFAULT - .def.u32 = 0x00000080lu, -#endif - .val.u32 = 0x00000080lu, - .access = CO_ACCESS_RW, - .pdo_mapping = 0, - .flags = 0 - } -}; - -/* Object 0x1012 sub-objects */ - -static const struct co_ssub g_1012_sub[] = -{ - { -#if !LELY_NO_CO_OBJ_NAME - .name = CO_SDEV_STRING("COB-ID time stamp object"), -#endif - .subidx = 0x00, - .type = CO_DEFTYPE_UNSIGNED32, -#if !LELY_NO_CO_OBJ_LIMITS - .min.u32 = CO_UNSIGNED32_MIN, - .max.u32 = CO_UNSIGNED32_MAX, -#endif -#if !LELY_NO_CO_OBJ_DEFAULT - .def.u32 = 0x80000100lu, -#endif - .val.u32 = 0x80000100lu, - .access = CO_ACCESS_RW, - .pdo_mapping = 0, - .flags = 0 - } -}; - -/* Object 0x1017 sub-objects */ - -static const struct co_ssub g_1017_sub[] = -{ - { -#if !LELY_NO_CO_OBJ_NAME - .name = CO_SDEV_STRING("Producer heartbeat time"), -#endif - .subidx = 0x00, - .type = CO_DEFTYPE_UNSIGNED16, -#if !LELY_NO_CO_OBJ_LIMITS - .min.u16 = CO_UNSIGNED16_MIN, - .max.u16 = CO_UNSIGNED16_MAX, -#endif -#if !LELY_NO_CO_OBJ_DEFAULT - .def.u16 = 0x0032, -#endif - .val.u16 = 0x0032, - .access = CO_ACCESS_RW, - .pdo_mapping = 0, - .flags = 0 - } -}; - -/* Object 0x1018 sub-objects */ - -static const struct co_ssub g_1018_sub[] = -{ - { -#if !LELY_NO_CO_OBJ_NAME - .name = CO_SDEV_STRING("Highest sub-index supported"), -#endif - .subidx = 0x00, - .type = CO_DEFTYPE_UNSIGNED8, -#if !LELY_NO_CO_OBJ_LIMITS - .min.u8 = CO_UNSIGNED8_MIN, - .max.u8 = CO_UNSIGNED8_MAX, -#endif -#if !LELY_NO_CO_OBJ_DEFAULT - .def.u8 = 0x04, -#endif - .val.u8 = 0x04, - .access = CO_ACCESS_CONST, - .pdo_mapping = 0, - .flags = 0 - }, - { -#if !LELY_NO_CO_OBJ_NAME - .name = CO_SDEV_STRING("Vendor-ID"), -#endif - .subidx = 0x01, - .type = CO_DEFTYPE_UNSIGNED32, -#if !LELY_NO_CO_OBJ_LIMITS - .min.u32 = CO_UNSIGNED32_MIN, - .max.u32 = CO_UNSIGNED32_MAX, -#endif -#if !LELY_NO_CO_OBJ_DEFAULT - .def.u32 = 0x00000360lu, -#endif - .val.u32 = 0x00000360lu, - .access = CO_ACCESS_RO, - .pdo_mapping = 0, - .flags = 0 - }, - { -#if !LELY_NO_CO_OBJ_NAME - .name = CO_SDEV_STRING("Product code"), -#endif - .subidx = 0x02, - .type = CO_DEFTYPE_UNSIGNED32, -#if !LELY_NO_CO_OBJ_LIMITS - .min.u32 = CO_UNSIGNED32_MIN, - .max.u32 = CO_UNSIGNED32_MAX, -#endif -#if !LELY_NO_CO_OBJ_DEFAULT - .def.u32 = CO_UNSIGNED32_MIN, -#endif - .val.u32 = CO_UNSIGNED32_MIN, - .access = CO_ACCESS_RO, - .pdo_mapping = 0, - .flags = 0 - }, - { -#if !LELY_NO_CO_OBJ_NAME - .name = CO_SDEV_STRING("Revision number"), -#endif - .subidx = 0x03, - .type = CO_DEFTYPE_UNSIGNED32, -#if !LELY_NO_CO_OBJ_LIMITS - .min.u32 = CO_UNSIGNED32_MIN, - .max.u32 = CO_UNSIGNED32_MAX, -#endif -#if !LELY_NO_CO_OBJ_DEFAULT - .def.u32 = CO_UNSIGNED32_MIN, -#endif - .val.u32 = CO_UNSIGNED32_MIN, - .access = CO_ACCESS_RO, - .pdo_mapping = 0, - .flags = 0 - }, - { -#if !LELY_NO_CO_OBJ_NAME - .name = CO_SDEV_STRING("Serial number"), -#endif - .subidx = 0x04, - .type = CO_DEFTYPE_UNSIGNED32, -#if !LELY_NO_CO_OBJ_LIMITS - .min.u32 = CO_UNSIGNED32_MIN, - .max.u32 = CO_UNSIGNED32_MAX, -#endif -#if !LELY_NO_CO_OBJ_DEFAULT - .def.u32 = CO_UNSIGNED32_MIN, -#endif - .val.u32 = CO_UNSIGNED32_MIN, - .access = CO_ACCESS_RO, - .pdo_mapping = 0, - .flags = 0 - } -}; - -/* Object 0x1800 sub-objects */ - -static const struct co_ssub g_1800_sub[] = -{ - { -#if !LELY_NO_CO_OBJ_NAME - .name = CO_SDEV_STRING("Highest sub-index supported"), -#endif - .subidx = 0x00, - .type = CO_DEFTYPE_UNSIGNED8, -#if !LELY_NO_CO_OBJ_LIMITS - .min.u8 = CO_UNSIGNED8_MIN, - .max.u8 = CO_UNSIGNED8_MAX, -#endif -#if !LELY_NO_CO_OBJ_DEFAULT - .def.u8 = 0x02, -#endif - .val.u8 = 0x02, - .access = CO_ACCESS_CONST, - .pdo_mapping = 0, - .flags = 0 - }, - { -#if !LELY_NO_CO_OBJ_NAME - .name = CO_SDEV_STRING("COB-ID"), -#endif - .subidx = 0x01, - .type = CO_DEFTYPE_UNSIGNED32, -#if !LELY_NO_CO_OBJ_LIMITS - .min.u32 = CO_UNSIGNED32_MIN, - .max.u32 = CO_UNSIGNED32_MAX, -#endif -#if !LELY_NO_CO_OBJ_DEFAULT - .def.u32 = 0x00000182lu, -#endif - .val.u32 = 0x00000182lu, - .access = CO_ACCESS_RW, - .pdo_mapping = 0, - .flags = 0 - }, - { -#if !LELY_NO_CO_OBJ_NAME - .name = CO_SDEV_STRING("Transmission type"), -#endif - .subidx = 0x02, - .type = CO_DEFTYPE_UNSIGNED8, -#if !LELY_NO_CO_OBJ_LIMITS - .min.u8 = CO_UNSIGNED8_MIN, - .max.u8 = CO_UNSIGNED8_MAX, -#endif -#if !LELY_NO_CO_OBJ_DEFAULT - .def.u8 = 0x01, -#endif - .val.u8 = 0x01, - .access = CO_ACCESS_RW, - .pdo_mapping = 0, - .flags = 0 - } -}; - -/* Object 0x1a00 sub-objects */ - -static const struct co_ssub g_1a00_sub[] = -{ - { -#if !LELY_NO_CO_OBJ_NAME - .name = CO_SDEV_STRING("Number of mapped objects"), -#endif - .subidx = 0x00, - .type = CO_DEFTYPE_UNSIGNED8, -#if !LELY_NO_CO_OBJ_LIMITS - .min.u8 = CO_UNSIGNED8_MIN, - .max.u8 = CO_UNSIGNED8_MAX, -#endif -#if !LELY_NO_CO_OBJ_DEFAULT - .def.u8 = 0x01, -#endif - .val.u8 = 0x01, - .access = CO_ACCESS_RW, - .pdo_mapping = 0, - .flags = 0 - }, - { -#if !LELY_NO_CO_OBJ_NAME - .name = CO_SDEV_STRING("Mapping 1"), -#endif - .subidx = 0x01, - .type = CO_DEFTYPE_UNSIGNED32, -#if !LELY_NO_CO_OBJ_LIMITS - .min.u32 = CO_UNSIGNED32_MIN, - .max.u32 = CO_UNSIGNED32_MAX, -#endif -#if !LELY_NO_CO_OBJ_DEFAULT - .def.u32 = 0x21000020lu, -#endif - .val.u32 = 0x21000020lu, - .access = CO_ACCESS_RW, - .pdo_mapping = 0, - .flags = 0 - } -}; - -/* Object 0x1f80 sub-objects */ - -static const struct co_ssub g_1f80_sub[] = -{ - { -#if !LELY_NO_CO_OBJ_NAME - .name = CO_SDEV_STRING("NMT startup"), -#endif - .subidx = 0x00, - .type = CO_DEFTYPE_UNSIGNED32, -#if !LELY_NO_CO_OBJ_LIMITS - .min.u32 = CO_UNSIGNED32_MIN, - .max.u32 = CO_UNSIGNED32_MAX, -#endif -#if !LELY_NO_CO_OBJ_DEFAULT - .def.u32 = CO_UNSIGNED32_MIN, -#endif - .val.u32 = 0x00000004lu, - .access = CO_ACCESS_RW, - .pdo_mapping = 0, - .flags = 0 - | CO_OBJ_FLAGS_PARAMETER_VALUE - } -}; - -/* Object 0x2000 sub-objects */ - -static const struct co_ssub g_2000_sub[] = -{ - { -#if !LELY_NO_CO_OBJ_NAME - .name = CO_SDEV_STRING("Object with custom SDO download callback"), -#endif - .subidx = 0x00, - .type = CO_DEFTYPE_UNSIGNED32, -#if !LELY_NO_CO_OBJ_LIMITS - .min.u32 = CO_UNSIGNED32_MIN, - .max.u32 = CO_UNSIGNED32_MAX, -#endif -#if !LELY_NO_CO_OBJ_DEFAULT - .def.u32 = CO_UNSIGNED32_MIN, -#endif - .val.u32 = CO_UNSIGNED32_MIN, - .access = CO_ACCESS_RW, - .pdo_mapping = 0, - .flags = 0 - } -}; - -/* Object 0x2001 sub-objects */ - -static const struct co_ssub g_2001_sub[] = -{ - { -#if !LELY_NO_CO_OBJ_NAME - .name = CO_SDEV_STRING("Object with custom SDO upload callback"), -#endif - .subidx = 0x00, - .type = CO_DEFTYPE_UNSIGNED32, -#if !LELY_NO_CO_OBJ_LIMITS - .min.u32 = CO_UNSIGNED32_MIN, - .max.u32 = CO_UNSIGNED32_MAX, -#endif -#if !LELY_NO_CO_OBJ_DEFAULT - .def.u32 = CO_UNSIGNED32_MIN, -#endif - .val.u32 = CO_UNSIGNED32_MIN, - .access = CO_ACCESS_RO, - .pdo_mapping = 0, - .flags = 0 - } -}; - -/* Object 0x2100 sub-objects */ - -static const struct co_ssub g_2100_sub[] = -{ - { -#if !LELY_NO_CO_OBJ_NAME - .name = CO_SDEV_STRING("Counter"), -#endif - .subidx = 0x00, - .type = CO_DEFTYPE_UNSIGNED32, -#if !LELY_NO_CO_OBJ_LIMITS - .min.u32 = CO_UNSIGNED32_MIN, - .max.u32 = CO_UNSIGNED32_MAX, -#endif -#if !LELY_NO_CO_OBJ_DEFAULT - .def.u32 = CO_UNSIGNED32_MIN, -#endif - .val.u32 = CO_UNSIGNED32_MIN, - .access = CO_ACCESS_RW, - .pdo_mapping = 1, - .flags = 0 - } -}; - -/* Object dictionary */ - -static const struct co_sobj g_g_sdev_slave_objs[] = -{ - { -#if !LELY_NO_CO_OBJ_NAME - .name = CO_SDEV_STRING("Device type"), -#endif - .idx = 0x1000, - .code = CO_OBJECT_VAR, - .nsub = 1, - .subs = g_1000_sub - }, - { -#if !LELY_NO_CO_OBJ_NAME - .name = CO_SDEV_STRING("Error register"), -#endif - .idx = 0x1001, - .code = CO_OBJECT_VAR, - .nsub = 1, - .subs = g_1001_sub - }, - { -#if !LELY_NO_CO_OBJ_NAME - .name = CO_SDEV_STRING("COB-ID SYNC message"), -#endif - .idx = 0x1005, - .code = CO_OBJECT_VAR, - .nsub = 1, - .subs = g_1005_sub - }, - { -#if !LELY_NO_CO_OBJ_NAME - .name = CO_SDEV_STRING("COB-ID time stamp object"), -#endif - .idx = 0x1012, - .code = CO_OBJECT_VAR, - .nsub = 1, - .subs = g_1012_sub - }, - { -#if !LELY_NO_CO_OBJ_NAME - .name = CO_SDEV_STRING("Producer heartbeat time"), -#endif - .idx = 0x1017, - .code = CO_OBJECT_VAR, - .nsub = 1, - .subs = g_1017_sub - }, - { -#if !LELY_NO_CO_OBJ_NAME - .name = CO_SDEV_STRING("Identity object"), -#endif - .idx = 0x1018, - .code = CO_OBJECT_RECORD, - .nsub = 5, - .subs = g_1018_sub - }, - { -#if !LELY_NO_CO_OBJ_NAME - .name = CO_SDEV_STRING("TPDO communication parameter"), -#endif - .idx = 0x1800, - .code = CO_OBJECT_RECORD, - .nsub = 3, - .subs = g_1800_sub - }, - { -#if !LELY_NO_CO_OBJ_NAME - .name = CO_SDEV_STRING("TPDO mapping parameter"), -#endif - .idx = 0x1a00, - .code = CO_OBJECT_RECORD, - .nsub = 2, - .subs = g_1a00_sub - }, - { -#if !LELY_NO_CO_OBJ_NAME - .name = CO_SDEV_STRING("NMT startup"), -#endif - .idx = 0x1f80, - .code = CO_OBJECT_VAR, - .nsub = 1, - .subs = g_1f80_sub - }, - { -#if !LELY_NO_CO_OBJ_NAME - .name = CO_SDEV_STRING("Object with custom SDO download callback"), -#endif - .idx = 0x2000, - .code = CO_OBJECT_VAR, - .nsub = 1, - .subs = g_2000_sub - }, - { -#if !LELY_NO_CO_OBJ_NAME - .name = CO_SDEV_STRING("Object with custom SDO upload callback"), -#endif - .idx = 0x2001, - .code = CO_OBJECT_VAR, - .nsub = 1, - .subs = g_2001_sub - }, - { -#if !LELY_NO_CO_OBJ_NAME - .name = CO_SDEV_STRING("Counter"), -#endif - .idx = 0x2100, - .code = CO_OBJECT_VAR, - .nsub = 1, - .subs = g_2100_sub - } -}; - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -const struct co_sdev g_sdev_slave = -{ - .id = 0x02, - .name = NULL, - .vendor_name = CO_SDEV_STRING("Apache NuttX RTOS"), - .vendor_id = 0x00000000, - .product_name = NULL, - .product_code = 0x00000000, - .revision = 0x00000000, - .order_code = NULL, - .baud = CO_BAUD_125, - .rate = 0, - .lss = 0, - .dummy = 0x000000fe, - .nobj = 12, - .objs = g_g_sdev_slave_objs -}; - -/**************************************************************************** - * Public Functions - ****************************************************************************/ diff --git a/examples/lely_slave/slave_main.c b/examples/lely_slave/slave_main.c deleted file mode 100644 index 39cfa8af7..000000000 --- a/examples/lely_slave/slave_main.c +++ /dev/null @@ -1,242 +0,0 @@ -/**************************************************************************** - * apps/examples/lely_slave/slave_main.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <time.h> -#include <unistd.h> - -#include <canutils/lely/config.h> - -#include <lely/co/dev.h> -#include <lely/co/nmt.h> -#include <lely/co/sdev.h> -#include <lely/co/sdo.h> -#include <lely/co/time.h> - -#include "sdev.h" -#include "candev.h" - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -struct co_net_s -{ - can_net_t *net; - co_dev_t *dev; - co_nmt_t *nmt; -}; - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static struct co_net_s g_net; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: elapsed_ms - ****************************************************************************/ - -static long elapsed_ms(const struct timespec *a, const struct timespec *b) -{ - return (a->tv_sec - b->tv_sec) * 1000 + - (a->tv_nsec - b->tv_nsec) / 1000000; -} - -/**************************************************************************** - * Name: on_can_send - ****************************************************************************/ - -static int on_can_send(const struct can_msg *msg, void *data) -{ - UNUSED(data); - - return coslave_candev_send(msg); -} - -/**************************************************************************** - * Name: on_time - ****************************************************************************/ - -static void on_time(co_time_t *time, const struct timespec *tp, void *data) -{ - UNUSED(time); - UNUSED(data); - - /* Update the wall clock */ - - clock_settime(CLOCK_REALTIME, tp); -} - -/**************************************************************************** - * Name: on_nmt_cs - ****************************************************************************/ - -static void on_nmt_cs(co_nmt_t *nmt, co_unsigned8_t cs, void *data) -{ - UNUSED(data); - - switch (cs) - { - case CO_NMT_CS_START: - case CO_NMT_CS_ENTER_PREOP: - { - co_time_set_ind(co_nmt_get_time(nmt), &on_time, NULL); - break; - } - - case CO_NMT_CS_RESET_NODE: - { - exit(0); - break; - } - - case CO_NMT_CS_STOP: - case CO_NMT_CS_RESET_COMM: - default: - { - break; - } - } -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: main - ****************************************************************************/ - -int main(int argc, FAR char *argv[]) -{ - struct timespec now; - struct timespec t_last; - struct can_msg msg; - co_unsigned32_t counter = 0; - int ret; - - memset(&g_net, 0, sizeof(g_net)); - setvbuf(stdout, NULL, _IONBF, 0); - - ret = coslave_candev_init(); - if (ret < 0) - { - printf("ERROR: coslave_candev_init failed %d\n", ret); - goto errout; - } - - g_net.net = can_net_create(); - if (!g_net.net) - { - printf("ERROR: can_net_create failed\n"); - goto errout; - } - - can_net_set_send_func(g_net.net, &on_can_send, NULL); - - clock_gettime(CLOCK_MONOTONIC, &now); - can_net_set_time(g_net.net, &now); - - /* Create dev from struct */ - - g_net.dev = co_dev_create_from_sdev(&g_sdev_slave); - if (!g_net.dev) - { - printf("ERROR: co_dev_create_from_sdev failed\n"); - goto errout; - } - - g_net.nmt = co_nmt_create(g_net.net, g_net.dev); - if (!g_net.nmt) - { - printf("ERROR: co_nmt_create failed\n"); - goto errout; - } - - /* Start the NMT service by resetting the node */ - - co_nmt_cs_ind(g_net.nmt, CO_NMT_CS_RESET_NODE); - - /* Set the NMT indication function after the initial reset */ - - co_nmt_set_cs_ind(g_net.nmt, &on_nmt_cs, NULL); - - printf("lely CANopen slave running (node 0x%02x)\n", g_sdev_slave.id); - - clock_gettime(CLOCK_MONOTONIC, &t_last); - - while (1) - { - clock_gettime(CLOCK_MONOTONIC, &now); - can_net_set_time(g_net.net, &now); - - while (coslave_candev_recv(&msg) > 0) - { - can_net_recv(g_net.net, &msg); - } - - /* Update the counter mapped into TPDO1 (0x2100) every 100 ms. - * When the master has brought us to OPERATIONAL, the synchronous TPDO - * sends the current value on each SYNC. - */ - - if (elapsed_ms(&now, &t_last) >= 100) - { - t_last = now; - counter++; - co_dev_set_val_u32(g_net.dev, 0x2100, 0x00, counter); - } - - usleep(1000); - } - -errout: - if (g_net.nmt) - { - co_nmt_destroy(g_net.nmt); - } - - if (g_net.dev) - { - co_dev_destroy(g_net.dev); - } - - if (g_net.net) - { - can_net_destroy(g_net.net); - } - - return 0; -} diff --git a/examples/libtest/CMakeLists.txt b/examples/libtest/CMakeLists.txt deleted file mode 100644 index a1975f184..000000000 --- a/examples/libtest/CMakeLists.txt +++ /dev/null @@ -1,42 +0,0 @@ -# ############################################################################## -# apps/examples/libtest/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_LIBTEST) - - if(CONFIG_EXAMPLES_LIBTEST_CMDTOOL) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_LIBTEST_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_LIBTEST_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_LIBTEST_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_LIBTEST_CMDTOOL} - SRCS - libtest_main.c) - endif() - - nuttx_add_library(libtest STATIC) - target_sources(libtest PRIVATE libtest.c) - -endif() diff --git a/examples/libtest/Kconfig b/examples/libtest/Kconfig deleted file mode 100644 index 3a16ffc2b..000000000 --- a/examples/libtest/Kconfig +++ /dev/null @@ -1,37 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config EXAMPLES_LIBTEST - bool "Static library Example" - default n - ---help--- - Enable the static library example - -if EXAMPLES_LIBTEST - -config EXAMPLES_LIBTEST_CMDTOOL - tristate "Static library Command Line Tool" - default n - ---help--- - By default, static library example is build as only a library. - If this option is selected than a simple command line tool that - can be ran from NSH will also be generated. - -config EXAMPLES_LIBTEST_PROGNAME - string "Static library program name" - default "libtest" - ---help--- - This is the name of the program that will be used when the NSH ELF - program is installed. - -config EXAMPLES_LIBTEST_PRIORITY - int "Static library task priority" - default 100 - -config EXAMPLES_LIBTEST_STACKSIZE - int "Static library stack size" - default DEFAULT_TASK_STACKSIZE - -endif diff --git a/examples/libtest/Make.defs b/examples/libtest/Make.defs deleted file mode 100644 index c9e0a6c88..000000000 --- a/examples/libtest/Make.defs +++ /dev/null @@ -1,27 +0,0 @@ -############################################################################ -# apps/examples/libtest/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################/ - -ifneq ($(CONFIG_EXAMPLES_LIBTEST),) -EXTRA_LIBS += -ltest -EXTRA_LIBPATHS += -L$(APPDIR)/examples/libtest -CONFIGURED_APPS += $(APPDIR)/examples/libtest -endif diff --git a/examples/libtest/Makefile b/examples/libtest/Makefile deleted file mode 100644 index b29501389..000000000 --- a/examples/libtest/Makefile +++ /dev/null @@ -1,37 +0,0 @@ -############################################################################ -# apps/examples/libtest/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################/ - - -include $(APPDIR)/Make.defs - -BIN = libtest$(LIBEXT) -CSRCS = libtest.c - -ifneq ($(CONFIG_EXAMPLES_LIBTEST_CMDTOOL),) - PROGNAME = $(CONFIG_EXAMPLES_LIBTEST_PROGNAME) - PRIORITY = $(CONFIG_EXAMPLES_LIBTEST_PRIORITY) - STACKSIZE = $(CONFIG_EXAMPLES_LIBTEST_STACKSIZE) - MODULE = $(CONFIG_EXAMPLES_LIBTEST_CMDTOOL) - MAINSRC = libtest_main.c -endif - -include $(APPDIR)/Application.mk diff --git a/examples/libtest/libtest.c b/examples/libtest/libtest.c deleted file mode 100644 index a1d9852c8..000000000 --- a/examples/libtest/libtest.c +++ /dev/null @@ -1,53 +0,0 @@ -/**************************************************************************** - * apps/examples/libtest/libtest.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/compiler.h> -#include <stdio.h> -#include <stdlib.h> - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * library_test - ****************************************************************************/ - -void library_test(void) -{ - FAR int *p = malloc(sizeof(int)); - if (p == NULL) - { - printf("libtest failed to allocate memory\n"); - return; - } - - *p = 12345; - printf("libtest: p=%p *p=%d\n", p, *p); - free(p); - - printf("Hello, Library!!\n"); -} diff --git a/examples/libtest/libtest.h b/examples/libtest/libtest.h deleted file mode 100644 index df0ed548a..000000000 --- a/examples/libtest/libtest.h +++ /dev/null @@ -1,32 +0,0 @@ -/**************************************************************************** - * apps/examples/libtest/libtest.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __APPS_EXAMPLES_LIBTEST_LIBTEST_H -#define __APPS_EXAMPLES_LIBTEST_LIBTEST_H - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -void library_test(void); - -#endif /* __APPS_EXAMPLES_LIBTEST_LIBTEST_H */ diff --git a/examples/libtest/libtest_main.c b/examples/libtest/libtest_main.c deleted file mode 100644 index 9ce195256..000000000 --- a/examples/libtest/libtest_main.c +++ /dev/null @@ -1,42 +0,0 @@ -/**************************************************************************** - * apps/examples/libtest/libtest_main.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/compiler.h> -#include "libtest.h" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * main - ****************************************************************************/ - -int main(int argc, FAR char *argv[]) -{ - library_test(); - return 0; -} diff --git a/examples/lis3dsh_reader/CMakeLists.txt b/examples/lis3dsh_reader/CMakeLists.txt deleted file mode 100644 index 37e2d5961..000000000 --- a/examples/lis3dsh_reader/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# ############################################################################## -# apps/examples/lis3dsh_reader/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_LIS3DSH_READER) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_LIS3DSH_READER_PROGNAME} - STACKSIZE - ${CONFIG_DEFAULT_TASK_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_LIS3DSH_READER} - SRCS - lis3dsh_reader_main.c) -endif() diff --git a/examples/lis3dsh_reader/Make.defs b/examples/lis3dsh_reader/Make.defs index 1caf28f15..2245b4d37 100644 --- a/examples/lis3dsh_reader/Make.defs +++ b/examples/lis3dsh_reader/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/lis3dsh_reader/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/lis3dsh_reader/Makefile b/examples/lis3dsh_reader/Makefile index d97e90a41..b83339d9e 100644 --- a/examples/lis3dsh_reader/Makefile +++ b/examples/lis3dsh_reader/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/lis3dsh_reader/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/lis3dsh_reader/lis3dsh_reader_main.c b/examples/lis3dsh_reader/lis3dsh_reader_main.c index 98194ea66..da2af927d 100644 --- a/examples/lis3dsh_reader/lis3dsh_reader_main.c +++ b/examples/lis3dsh_reader/lis3dsh_reader_main.c @@ -1,9 +1,8 @@ /**************************************************************************** * apps/examples/lis3dsh_reader/lis3dsh_reader_main.c * - * SPDX-License-Identifier: BSD-3-Clause - * SPDX-FileCopyrightText: 2017 Florian Olbrich. All rights reserved. - * SPDX-FileContributor: Florian Olbrich <florian.olbrich@oth-regensburg.de> + * Copyright (C) 2017 Florian Olbrich. All rights reserved. + * Author: Florian Olbrich <florian.olbrich@oth-regensburg.de> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -47,9 +46,9 @@ #include <fcntl.h> #include <sched.h> #include <errno.h> -#include <nuttx/debug.h> + +#include <debug.h> #include <time.h> -#include <unistd.h> #include <nuttx/sensors/lis3dsh.h> diff --git a/examples/lp503x/CMakeLists.txt b/examples/lp503x/CMakeLists.txt deleted file mode 100644 index 1256caabb..000000000 --- a/examples/lp503x/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# ############################################################################## -# apps/examples/lp503x/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_LP503X) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_LP503X_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_LP503X_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_LP503X_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_LP503X} - SRCS - lp503x_main.c) -endif() diff --git a/examples/lp503x/Kconfig b/examples/lp503x/Kconfig deleted file mode 100644 index 394105d47..000000000 --- a/examples/lp503x/Kconfig +++ /dev/null @@ -1,34 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config EXAMPLES_LP503X - tristate "LP503X PWM LED example" - default n - depends on LP503X - ---help--- - Enable the LP503X example - -if EXAMPLES_LP503X - -config EXAMPLES_LP503X_PROGNAME - string "Program name" - default "lp503x" - ---help--- - This is the name of the program that will be used when the NSH ELF - program is installed. - -config EXAMPLES_LP503X_DEVPATH - string "LP503X device path" - default "/dev/leddrv0" - -config EXAMPLES_LP503X_PRIORITY - int "lp503x task priority" - default 100 - -config EXAMPLES_LP503X_STACKSIZE - int "lp503x stack size" - default DEFAULT_TASK_STACKSIZE - -endif diff --git a/examples/lp503x/Make.defs b/examples/lp503x/Make.defs deleted file mode 100644 index bf3f20b86..000000000 --- a/examples/lp503x/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/examples/lp503x/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_EXAMPLES_LP503X),) -CONFIGURED_APPS += $(APPDIR)/examples/lp503x -endif diff --git a/examples/lp503x/Makefile b/examples/lp503x/Makefile deleted file mode 100644 index 5cab0d4e4..000000000 --- a/examples/lp503x/Makefile +++ /dev/null @@ -1,36 +0,0 @@ -############################################################################ -# apps/examples/lp503x/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -# LP503x built-in application info - -PROGNAME = $(CONFIG_EXAMPLES_LP503X_PROGNAME) -PRIORITY = $(CONFIG_EXAMPLES_LP503X_PRIORITY) -STACKSIZE = $(CONFIG_EXAMPLES_LP503X_STACKSIZE) -MODULE = $(CONFIG_EXAMPLES_LP503X) - -# LP503x Test - -MAINSRC = lp503x_main.c - -include $(APPDIR)/Application.mk diff --git a/examples/lp503x/lp503x_main.c b/examples/lp503x/lp503x_main.c deleted file mode 100644 index fafb617e4..000000000 --- a/examples/lp503x/lp503x_main.c +++ /dev/null @@ -1,722 +0,0 @@ -/**************************************************************************** - * apps/examples/lp503x/lp503x_main.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <sys/ioctl.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#include <errno.h> -#include <stdio.h> -#include <stdlib.h> -#include <stdbool.h> -#include <unistd.h> - -#include "system/readline.h" - -#include <nuttx/leds/lp503x.h> - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ -#define LP503X_HELP_TEXT(x) x - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -typedef CODE int (*lp503x_func)(FAR char *pargs); - -struct lp503x_cmd_s -{ - FAR const char *cmd; /* The command text */ - FAR const char *arghelp; /* Text describing the args */ - lp503x_func pfunc; /* Pointer to command handler */ - FAR const char *help; /* The help text */ -}; - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -static int lp503x_cmd_quit(FAR char *parg); -static int lp503x_cmd_help(FAR char *parg); -static int lp503x_cmd_set_rgbled(FAR char *parg); -static int lp503x_cmd_setled(FAR char *parg); -static int lp503x_cmd_setcolour(FAR char *parg); -static int lp503x_cmd_pattern(FAR char *parg); -static int lp503x_cmd_brightness(FAR char *parg); -static int lp503x_cmd_mode(FAR char *parg); -static int lp503x_cmd_disable(FAR char *parg); -static int lp503x_cmd_set_bank_mode(FAR char *parg); -static int lp503x_cmd_set_banka_colour(FAR char *parg); -static int lp503x_cmd_set_bankb_colour(FAR char *parg); -static int lp503x_cmd_set_bankc_colour(FAR char *parg); -static int lp503x_cmd_set_bank_brightness(FAR char *parg); -static int lp503x_cmd_set_individual_mode(FAR char *parg); - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -int fd; - -static struct lp503x_cmd_s g_lp503x_cmds[] = -{ - { - "q", - "", - lp503x_cmd_quit, - LP503X_HELP_TEXT("Exit lp503x") - }, - { - "h", - "", - lp503x_cmd_help, - LP503X_HELP_TEXT("Display help for commands") - }, - { - "?", - "", - lp503x_cmd_help, - LP503X_HELP_TEXT("Display help for commands") - }, - { - "help", - "", - lp503x_cmd_help, - LP503X_HELP_TEXT("Display help for commands") - }, - { - "m", - "", - lp503x_cmd_mode, - LP503X_HELP_TEXT("send default mode to the device") - }, - { - "c", - "[hex]", - lp503x_cmd_setcolour, - LP503X_HELP_TEXT("show or set current RGB colour") - }, - { - "l", - "led, 0..11", - lp503x_cmd_set_rgbled, - LP503X_HELP_TEXT("set RGB LED selected to current colour") - }, - { - "n", - "led, 0..35", - lp503x_cmd_setled, - LP503X_HELP_TEXT("set individual LED to current brightness X") - }, - { - "p", - "num of leds in pattern (1..12)", - lp503x_cmd_pattern, - LP503X_HELP_TEXT("play LED pattern") - }, - { - "b", - "brightness, 0-255", - lp503x_cmd_brightness, - LP503X_HELP_TEXT("set brightness of all leds") - }, - { - "d", - "disable=1", - lp503x_cmd_disable, - LP503X_HELP_TEXT("globally disable ALL leds") - }, - { - "k", - "led num", - lp503x_cmd_set_bank_mode, - LP503X_HELP_TEXT("enable bank mode for LED ") - }, - { - "i", - "led num 0..11", - lp503x_cmd_set_individual_mode, - LP503X_HELP_TEXT("enable individual mode for LED ") - }, - { - "A", - "", - lp503x_cmd_set_banka_colour, - LP503X_HELP_TEXT("set bankA colour") - }, - { - "B", - "", - lp503x_cmd_set_bankb_colour, - LP503X_HELP_TEXT("set bankB colour") - }, - { - "C", - "", - lp503x_cmd_set_bankc_colour, - LP503X_HELP_TEXT("set bankC colour") - }, - { - "X", - "0..255", - lp503x_cmd_set_bank_brightness, - LP503X_HELP_TEXT("Bank or individual LED brightness required") - }, -}; - -static const int g_lp503x_cmd_count = sizeof(g_lp503x_cmds) / - sizeof(struct lp503x_cmd_s); -FAR static struct lp503x_config_s *lp503x_config; -FAR static struct ioctl_arg_s *lp503x_ioctl_args; -int current_colour; -int current_led_brightness; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name:lp503x_cmd_mode - * - * send default (Kconfig) mode/config to the device - ****************************************************************************/ - -static int lp503x_cmd_mode(FAR char *parg) -{ - return ioctl(fd, PWMIOC_CONFIG, lp503x_config); -} - -/**************************************************************************** - * Name:lp503x_cmd_quit - * - * lp503x_cmd_quit() terminates the application - ****************************************************************************/ - -static int lp503x_cmd_quit(FAR char *parg) -{ - return OK; -} - -/**************************************************************************** - * Name:lp503x_cmd_disable - * - * Globally disable all LEDS - ****************************************************************************/ - -static int lp503x_cmd_disable(FAR char *parg) -{ - return ioctl(fd, PWMIOC_ENABLE, atoi(parg)) ; -} - -/**************************************************************************** - * Name:lp503x_setled - * - * sets the chosen led (0..35) to the current brightness (0..255) (T) - ****************************************************************************/ - -static int lp503x_cmd_setled(FAR char *parg) -{ - int ret; - int lednum; - lednum = atoi(parg); - if (lednum > MAX_LEDS) - { - printf("ERROR: led number must be in range 0..35\n"); - ret = -EINVAL; - } - else - { - lp503x_ioctl_args->lednum = lednum; - lp503x_ioctl_args->param = current_led_brightness; - ret = ioctl(fd, PWMIOC_SET_LED_COLOUR, lp503x_ioctl_args); - } - - return ret; -} - -/**************************************************************************** - * Name:lp503x_setRGBled - * - * sets the chosen RGB led (0..11) to the current RGB colour - ****************************************************************************/ - -static int lp503x_cmd_set_rgbled(FAR char *parg) -{ - int ret; - int lednum; - - lednum = atoi(parg); - if (lednum > MAX_RGB_LEDS) - { - printf("ERROR: RGB led must be in range 0..11\n"); - ret = -EINVAL; - } - else - { - lp503x_ioctl_args->lednum = lednum; - lp503x_ioctl_args->param = current_colour; - ret = ioctl(fd, PWMIOC_SET_RGB_COLOUR, lp503x_ioctl_args); - } - - return ret; -} - -/**************************************************************************** - * Name:lp503x_cmd_set_bank_mode - * - * sets requested led to use "bank" mode - ****************************************************************************/ - -static int lp503x_cmd_set_bank_mode(FAR char *parg) -{ - int ret; - int lednum; - - lednum = atoi(parg); - if (lednum > MAX_RGB_LEDS) - { - printf("ERROR: RGB led must be in range 0..11\n"); - ret = -EINVAL; - } - else - { - lp503x_ioctl_args->param = LP503X_LED_BANK_MODE_ENABLED; - lp503x_ioctl_args->lednum = lednum; - ret = ioctl(fd, PWMIOC_ENABLE_LED_BANK_MODE, lp503x_ioctl_args); - } - - return ret; -} - -/**************************************************************************** - * Name:lp503x_cmd_set_individual_mode - * - * sets requested led to use "individual" mode (default) - ****************************************************************************/ - -static int lp503x_cmd_set_individual_mode(FAR char *parg) -{ - int ret; - int lednum; - - lednum = atoi(parg); - if (lednum > MAX_RGB_LEDS) - { - printf("ERROR: RGB led must be in range 0..11\n"); - ret = -EINVAL; - } - else - { - lp503x_ioctl_args->param = LP503X_LED_BANK_MODE_DISABLED; - lp503x_ioctl_args->lednum = lednum; - ret = ioctl(fd, PWMIOC_ENABLE_LED_BANK_MODE, lp503x_ioctl_args); - } - - return ret; -} - -/**************************************************************************** - * Name:lp503x_cmd_set_bank?_colour - * - * sets bank A/B/C to the current brightness (T) - ****************************************************************************/ - -static int lp503x_cmd_set_banka_colour(FAR char *parg) -{ - int requested_colour; - - requested_colour = atoi(parg); - - if ((requested_colour > MAX_BRIGHTNESS) || (requested_colour < 0)) - { - printf("ERR: Bank Colour (mix percent) must be in range 0..255\n"); - return -EINVAL; - } - else - { - lp503x_ioctl_args->param = requested_colour; - lp503x_ioctl_args->lednum = 'A'; - return ioctl(fd, PWMIOC_SET_BANK_MIX_COLOUR, lp503x_ioctl_args); - } -} - -static int lp503x_cmd_set_bankb_colour(FAR char *parg) -{ - int requested_colour; - - requested_colour = atoi(parg); - - if ((requested_colour > MAX_BRIGHTNESS) || (requested_colour < 0)) - { - printf("ERR: Bank Colour (mix percent) must be in range 0..255\n"); - return -EINVAL; - } - else - { - lp503x_ioctl_args->param = requested_colour; - lp503x_ioctl_args->lednum = 'B'; - return ioctl(fd, PWMIOC_SET_BANK_MIX_COLOUR, lp503x_ioctl_args); - } -} - -static int lp503x_cmd_set_bankc_colour(FAR char *parg) -{ - int requested_colour; - - requested_colour = atoi(parg); - - if ((requested_colour > MAX_BRIGHTNESS) || (requested_colour < 0)) - { - printf("ERR: Bank Colour (mix percent) must be in range 0..255\n"); - return -EINVAL; - } - else - { - lp503x_ioctl_args->param = requested_colour; - lp503x_ioctl_args->lednum = 'C'; - return ioctl(fd, PWMIOC_SET_BANK_MIX_COLOUR, lp503x_ioctl_args); - } -} - -/**************************************************************************** - * Name:lp503x_cmd_brightness - * - * sets all RGB led to the requested brightness - ****************************************************************************/ - -static int lp503x_cmd_brightness(FAR char *parg) -{ - int ret; - int lednum; - int requested_brightness; - - requested_brightness = (int)strtol(parg, NULL, 0); - if ((requested_brightness > MAX_BRIGHTNESS) || - (requested_brightness < 0)) - { - printf("ERROR: brightness must be in range 0..255\n"); - ret = -EINVAL; - } - else - { - lp503x_ioctl_args->param = requested_brightness; - - for (lednum = 0; lednum < 12; lednum++) - { - lp503x_ioctl_args->lednum = lednum; - ret = ioctl(fd, PWMIOC_SET_RGB_BRIGHTNESS, lp503x_ioctl_args); - } - } - - return ret; -} - -/**************************************************************************** - * Name:lp503x_cmd_pattern - * - * run a pattern for "arg[0]" leds. - * Repeats 5 times at different brightness levels - ****************************************************************************/ - -static int lp503x_cmd_pattern(FAR char *parg) -{ - int ret; - int numleds; - int i; - int j; - uint8_t k; - - int colour_lookup[12] = - { - 0x0000ff, 0x00ff00, 0xff0000, - 0x00ffff, 0xff00ff, 0xffff33, - 0xffffff, 0xffa500, 0xff00a5, - 0x8080ff, 0x80ff80, 0xff8080 - }; - - int pattern_brightness[5] = - { - 50, 100, 150, 200, 255 - }; - - int curcolour; - - numleds = atoi(parg); - if ((numleds > 12) || (numleds < 1)) - { - printf("Error: number of leds should be between 1 and 12\n"); - return -EINVAL; - } - - curcolour = 0; - - for (i = 0; i < 5; i++) - { - for (j = 0; j < numleds; j++) - { - lp503x_ioctl_args->lednum = j; - lp503x_ioctl_args->param = pattern_brightness[i]; - ret = ioctl(fd, PWMIOC_SET_RGB_BRIGHTNESS, lp503x_ioctl_args); - curcolour++; - if (curcolour >= numleds) - { - curcolour = 0; - } - - lp503x_ioctl_args->param = colour_lookup[curcolour]; - ret = ioctl(fd, PWMIOC_SET_RGB_COLOUR, lp503x_ioctl_args); - } - - usleep(500000); - curcolour++; - } - - lp503x_ioctl_args->param = 0; - for (k = 0; k < numleds; k++) - { - lp503x_ioctl_args->lednum = k; - ret = ioctl(fd, PWMIOC_SET_RGB_COLOUR, lp503x_ioctl_args); - } - - return ret; -} - -/**************************************************************************** - * Name:lp503x_cmd_set_bank_brightness - * - * sets the bank brightness to be used - ****************************************************************************/ - -static int lp503x_cmd_set_bank_brightness(FAR char *parg) -{ - int bank_brightness; - if (parg != NULL && *parg != '\0') - { - bank_brightness = atoi(parg); - - if ((bank_brightness > MAX_BRIGHTNESS) || (bank_brightness < 0)) - { - printf("bank brightness range is 0..255\n"); - bank_brightness = 0; - return -EINVAL; - } - else - { - lp503x_ioctl_args->param = bank_brightness; - current_led_brightness = bank_brightness; - return ioctl(fd, PWMIOC_SET_BANK_BRIGHTNESS, lp503x_ioctl_args); - } - } - - return OK; -} - -/**************************************************************************** - * Name:lp503x_setcolour - * - * shows the current RGB colour when no argument is provided, otherwise - * sets the current RGB colour to be used - ****************************************************************************/ - -static int lp503x_cmd_setcolour(FAR char *parg) -{ - int colour; - if (parg == NULL || *parg == '\0') - { - printf("current colour is: 0x%06x\n", current_colour); - } - else - { - colour = (int)strtol(parg, NULL, 16); - - if (colour > MAX_RGB_COLOUR) - { - printf("colour range is 0...0xFFFFFF\n"); - current_colour = 0; - return -EINVAL; - } - else - { - current_colour = colour; - printf("colour set to: 0x%06x\n", current_colour); - } - } - - return OK; -} - -/**************************************************************************** - * Name: lp503x_cmd_help - * - * lp503x_cmd_help() displays the application's help information on - * supported commands and command syntax. - ****************************************************************************/ - -static int lp503x_cmd_help(FAR char *parg) -{ - int len; - int maxlen = 0; - int x; - int c; - - /* Calculate length of longest cmd + arghelp */ - - for (x = 0; x < g_lp503x_cmd_count; x++) - { - len = strlen(g_lp503x_cmds[x].cmd) + - strlen(g_lp503x_cmds[x].arghelp); - if (len > maxlen) - { - maxlen = len; - } - } - - printf("lp503x commands\n================\n"); - for (x = 0; x < g_lp503x_cmd_count; x++) - { - /* Print the command and it's arguments */ - - printf(" %s %s", g_lp503x_cmds[x].cmd, - g_lp503x_cmds[x].arghelp); - - /* Calculate number of spaces to print before the help text */ - - len = maxlen - (strlen(g_lp503x_cmds[x].cmd) + - strlen(g_lp503x_cmds[x].arghelp)); - for (c = 0; c < len; c++) - { - printf(" "); - } - - printf(" : %s\n", g_lp503x_cmds[x].help); - } - - return OK; -} - -/**************************************************************************** - * lp503x_main - ****************************************************************************/ - -int main(int argc, FAR char *argv[]) -{ - char buffer[LINE_MAX]; - FAR char *cmd; - FAR char *arg; - bool running; - int len; - int x; - - fd = open(CONFIG_EXAMPLES_LP503X_DEVPATH, O_WRONLY); - if (fd < 0) - { - fprintf(stderr, "ERROR: Failed to open %s: %d\n", - CONFIG_EXAMPLES_LP503X_DEVPATH, errno); - return -ENODEV; - } - - running = true; - while (running) - { - printf("lp503x> "); - fflush(stdout); - - /* read a line from the terminal */ - - len = readline_stream(buffer, sizeof(buffer), - stdin, stdout); - if (len > 0) - { - buffer[len] = '\0'; - if (strncmp(buffer, "!", 1) != 0) - { - /* a command */ - - if (buffer[len - 1] == '\n') - { - buffer[len - 1] = '\0'; - } - - /* Parse the command from the argument */ - - cmd = strtok_r(buffer, " \n", &arg); - if (cmd == NULL) - { - continue; - } - - /* Remove leading spaces from arg */ - - while (*arg == ' ') - { - arg++; - } - - /* Find the command in our cmd array */ - - for (x = 0; x < g_lp503x_cmd_count; x++) - { - if (strcmp(cmd, g_lp503x_cmds[x].cmd) == 0) - { - /* Command found. Call it's handler if not NULL */ - - if (g_lp503x_cmds[x].pfunc != NULL) - { - g_lp503x_cmds[x].pfunc(arg); - } - - /* Test if it is a quit command */ - - if (g_lp503x_cmds[x].pfunc == lp503x_cmd_quit) - { - running = FALSE; - } - - break; - } - } - } - else - { -#ifdef CONFIG_SYSTEM_SYSTEM - /* Transfer nuttx shell */ - - system(buffer + 1); -#else - printf("%s: unknown lp503x command\n", buffer); -#endif - } - } - } - - close(fd); - - return 0; -} diff --git a/examples/lsm303_reader/CMakeLists.txt b/examples/lsm303_reader/CMakeLists.txt deleted file mode 100644 index b45c576a7..000000000 --- a/examples/lsm303_reader/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# ############################################################################## -# apps/examples/lsm303_reader/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_LSM303_READER) - nuttx_add_application( - NAME - lsm303_reader - STACKSIZE - ${CONFIG_DEFAULT_TASK_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_LSM303_READER} - SRCS - lsm303_reader_main.c) -endif() diff --git a/examples/lsm303_reader/Make.defs b/examples/lsm303_reader/Make.defs index 3035bb276..b33cc5f55 100644 --- a/examples/lsm303_reader/Make.defs +++ b/examples/lsm303_reader/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/lsm303_reader/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -20,6 +18,6 @@ # ############################################################################ -ifneq ($(CONFIG_EXAMPLES_LSM303_READER),) +ifeq ($(CONFIG_EXAMPLES_LSM303_READER),y) CONFIGURED_APPS += examples/lsm303_reader endif diff --git a/examples/lsm303_reader/Makefile b/examples/lsm303_reader/Makefile index 0183a5320..325b91048 100644 --- a/examples/lsm303_reader/Makefile +++ b/examples/lsm303_reader/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/lsm303_reader/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/lsm303_reader/lsm303_reader_main.c b/examples/lsm303_reader/lsm303_reader_main.c index 51611720d..7c5c2e7f6 100644 --- a/examples/lsm303_reader/lsm303_reader_main.c +++ b/examples/lsm303_reader/lsm303_reader_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/lsm303_reader/lsm303_reader_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -32,7 +30,7 @@ #include <errno.h> #include <unistd.h> -#include <nuttx/debug.h> +#include <debug.h> #include <nuttx/sensors/lsm303agr.h> diff --git a/examples/lsm330spi_test/CMakeLists.txt b/examples/lsm330spi_test/CMakeLists.txt deleted file mode 100644 index 96438b772..000000000 --- a/examples/lsm330spi_test/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# ############################################################################## -# apps/examples/lsm330spi_test/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_LSM330SPI_TEST) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_LSM330SPI_TEST_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_LSM330SPI_TEST_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_LSM330SPI_TEST_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_LSM330SPI_TEST} - SRCS - lsm330spi_test_main.c) -endif() diff --git a/examples/lsm330spi_test/Kconfig b/examples/lsm330spi_test/Kconfig index a245ba02a..5f5efee8d 100644 --- a/examples/lsm330spi_test/Kconfig +++ b/examples/lsm330spi_test/Kconfig @@ -6,7 +6,6 @@ config EXAMPLES_LSM330SPI_TEST tristate "LSM330 SPI test program" default n - depends on SENSORS_LSM330SPI ---help--- Enable the LSM330 sensor SPI test program. diff --git a/examples/lsm330spi_test/Make.defs b/examples/lsm330spi_test/Make.defs index 19908c392..ea85abe51 100644 --- a/examples/lsm330spi_test/Make.defs +++ b/examples/lsm330spi_test/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/lsm330spi_test/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/lsm330spi_test/Makefile b/examples/lsm330spi_test/Makefile index 341cf7567..4e2ebc68d 100644 --- a/examples/lsm330spi_test/Makefile +++ b/examples/lsm330spi_test/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/lsm330spi_test/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/lsm330spi_test/lsm330spi_test_main.c b/examples/lsm330spi_test/lsm330spi_test_main.c index 2ac49feac..ca1a5361d 100644 --- a/examples/lsm330spi_test/lsm330spi_test_main.c +++ b/examples/lsm330spi_test/lsm330spi_test_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/lsm330spi_test/lsm330spi_test_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -29,7 +27,7 @@ #include <stdio.h> #include <string.h> #include <fcntl.h> -#include <sys/param.h> +#include <nuttx/fs/fs.h> #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> @@ -43,6 +41,7 @@ * Pre-processor Definitions ****************************************************************************/ +#define ARRAYSIZE(x) (sizeof((x)) / sizeof((x)[0])) #define PASSED 0 #define SUB_PROMPT "stst >" @@ -632,7 +631,7 @@ int main(int argc, FAR char *argv[]) lsm330gyro_test, /* LSM330 gyroscope tests */ }; - FAR char *test_path[nitems(test_ptr_array)]; + FAR char *test_path[ARRAYSIZE(test_ptr_array)]; if (argc < 2 || *argv[1] == 0 || *(argv[1] + 1) == 0) { @@ -738,7 +737,7 @@ int main(int argc, FAR char *argv[]) printf("Set to batch mode.\n"); } } - else if (ui >= nitems(test_ptr_array)) + else if (ui >= ARRAYSIZE(test_ptr_array)) { printf("Huh?\n"); } @@ -758,7 +757,7 @@ int main(int argc, FAR char *argv[]) else /* not interactive mode */ { printf("LSM330 sensor diagnostic started in batch mode...\n"); - for (ui = 0; ui < nitems(test_ptr_array); ui++) + for (ui = 0; ui < ARRAYSIZE(test_ptr_array); ui++) { step_rc = 0; if (test_ptr_array[ui] != 0) diff --git a/examples/lsm6dsl_reader/CMakeLists.txt b/examples/lsm6dsl_reader/CMakeLists.txt deleted file mode 100644 index 766504114..000000000 --- a/examples/lsm6dsl_reader/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# ############################################################################## -# apps/examples/lsm6dsl_reader/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_LSM6DSL_READER) - nuttx_add_application( - NAME - lsm6dsl_reader - STACKSIZE - ${CONFIG_DEFAULT_TASK_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_LSM6DSL_READER} - SRCS - lsm6dsl_reader_main.c) -endif() diff --git a/examples/lsm6dsl_reader/Make.defs b/examples/lsm6dsl_reader/Make.defs index 19918cf56..e73809d38 100644 --- a/examples/lsm6dsl_reader/Make.defs +++ b/examples/lsm6dsl_reader/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/lsm6dsl_reader/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -20,6 +18,6 @@ # ############################################################################ -ifneq ($(CONFIG_EXAMPLES_LSM6DSL_READER),) +ifeq ($(CONFIG_EXAMPLES_LSM6DSL_READER),y) CONFIGURED_APPS += examples/lsm6dsl_reader endif diff --git a/examples/lsm6dsl_reader/Makefile b/examples/lsm6dsl_reader/Makefile index a9fbfb475..f1a8cb3e2 100644 --- a/examples/lsm6dsl_reader/Makefile +++ b/examples/lsm6dsl_reader/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/lsm6dsl_reader/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/lsm6dsl_reader/lsm6dsl_reader_main.c b/examples/lsm6dsl_reader/lsm6dsl_reader_main.c index 6f7cf0355..6fea70de5 100644 --- a/examples/lsm6dsl_reader/lsm6dsl_reader_main.c +++ b/examples/lsm6dsl_reader/lsm6dsl_reader_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/lsm6dsl_reader/lsm6dsl_reader_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -32,7 +30,7 @@ #include <errno.h> #include <unistd.h> -#include <nuttx/debug.h> +#include <debug.h> #include <nuttx/sensors/lsm6dsl.h> diff --git a/examples/ltr308/CMakeLists.txt b/examples/ltr308/CMakeLists.txt deleted file mode 100644 index 5d3615c04..000000000 --- a/examples/ltr308/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# ############################################################################## -# apps/examples/ltr308/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_LTR308) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_LTR308_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_LTR308_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_LTR308_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_LTR308} - SRCS - ltr308_main.c) -endif() diff --git a/examples/ltr308/Kconfig b/examples/ltr308/Kconfig deleted file mode 100644 index 05148af33..000000000 --- a/examples/ltr308/Kconfig +++ /dev/null @@ -1,30 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config EXAMPLES_LTR308 - tristate "LTR308 ambient light sensor example" - default n - depends on SENSORS_LTR308 - ---help--- - Enable the LTR308 example - -if EXAMPLES_LTR308 - -config EXAMPLES_LTR308_PROGNAME - string "Program name" - default "ltr308" - ---help--- - This is the name of the program that will be used when the NSH ELF - program is installed. - -config EXAMPLES_LTR308_PRIORITY - int "LTR308 task priority" - default 100 - -config EXAMPLES_LTR308_STACKSIZE - int "LTR308 stack size" - default DEFAULT_TASK_STACKSIZE - -endif diff --git a/examples/ltr308/Make.defs b/examples/ltr308/Make.defs deleted file mode 100644 index 16bdcc134..000000000 --- a/examples/ltr308/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/examples/ltr308/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_EXAMPLES_LTR308),) -CONFIGURED_APPS += $(APPDIR)/examples/ltr308 -endif diff --git a/examples/ltr308/Makefile b/examples/ltr308/Makefile deleted file mode 100644 index 0db3eb1f4..000000000 --- a/examples/ltr308/Makefile +++ /dev/null @@ -1,36 +0,0 @@ -############################################################################ -# apps/examples/ltr308/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -# LTR308 ambient light sensor example built-in application info - -PROGNAME = $(CONFIG_EXAMPLES_LTR308_PROGNAME) -PRIORITY = $(CONFIG_EXAMPLES_LTR308_PRIORITY) -STACKSIZE = $(CONFIG_EXAMPLES_LTR308_STACKSIZE) -MODULE = $(CONFIG_EXAMPLES_LTR308) - -# LTR308 ambient light sensor example - -MAINSRC = ltr308_main.c - -include $(APPDIR)/Application.mk diff --git a/examples/ltr308/ltr308_main.c b/examples/ltr308/ltr308_main.c deleted file mode 100644 index 1109b1799..000000000 --- a/examples/ltr308/ltr308_main.c +++ /dev/null @@ -1,95 +0,0 @@ -/**************************************************************************** - * apps/examples/ltr308/ltr308_main.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> -#include <nuttx/sensors/ioctl.h> -#include <nuttx/sensors/sensor.h> -#include <nuttx/sensors/ltr308.h> - -#include <stdio.h> -#include <string.h> -#include <fcntl.h> -#include <sys/ioctl.h> -#include <poll.h> -#include <unistd.h> - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * ltr308_main - ****************************************************************************/ - -int main(int argc, FAR char *argv[]) -{ - struct ltr308_calibval calibval; - struct sensor_light light; - struct pollfd pfd; - int ret; - int fd; - - fd = open("/dev/uorb/sensor_light0", O_RDONLY); - if (fd < 0) - { - perror("Could not open file"); - return fd; - } - - calibval.integration_time = 1; - calibval.measurement_rate = 2; - calibval.gain = 1; - ret = ioctl(fd, SNIOC_CALIBRATE, &calibval); - if (ret < 0) - { - perror("Could not calibrate sensor"); - goto err_out; - } - - memset(&pfd, 0, sizeof(struct pollfd)); - pfd.fd = fd; - pfd.events = POLLIN; - ret = poll(&pfd, 1, -1); - if (ret < 0) - { - perror("Could not poll sensor"); - goto err_out; - } - - ret = read(fd, &light, sizeof(struct sensor_light)); - if (ret < 0) - { - perror("Could not read from sensor"); - goto err_out; - } - - printf("timestamp: %llu, lux: %f\n", light.timestamp, light.light); - return OK; - -err_out: - close(fd); - return ret; -} diff --git a/examples/lua_module/CMakeLists.txt b/examples/lua_module/CMakeLists.txt deleted file mode 100644 index 713f5abbd..000000000 --- a/examples/lua_module/CMakeLists.txt +++ /dev/null @@ -1,29 +0,0 @@ -# ############################################################################## -# apps/examples/lua_module/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_LUA_MODULE) - - target_sources(apps PRIVATE luamod_hello.c) - - # register lua mod - nuttx_add_luamod(MODS hello) -endif() diff --git a/examples/lua_module/Kconfig b/examples/lua_module/Kconfig deleted file mode 100644 index 18a30eb95..000000000 --- a/examples/lua_module/Kconfig +++ /dev/null @@ -1,10 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config EXAMPLES_LUA_MODULE - tristate "Lua module example" - default n - ---help--- - Enable the Lua module example diff --git a/examples/lua_module/Make.defs b/examples/lua_module/Make.defs deleted file mode 100644 index 11cf233b1..000000000 --- a/examples/lua_module/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/examples/lua_module/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_EXAMPLES_LUA_MODULE),) -CONFIGURED_APPS += $(APPDIR)/examples/lua_module -endif diff --git a/examples/lua_module/Makefile b/examples/lua_module/Makefile deleted file mode 100644 index 77f193261..000000000 --- a/examples/lua_module/Makefile +++ /dev/null @@ -1,37 +0,0 @@ -############################################################################ -# apps/examples/lua_module/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -# A Hello World Lua C module - -CSRCS = luamod_hello.c - -# Set LUAMODNAME and include Module.mk to add this module to the list of -# builtin modules for the Lua interpreter. LUAMODNAME should match the -# module's luaopen function. - -LUAMODNAME = hello - -include $(APPDIR)/interpreters/lua/Module.mk - -include $(APPDIR)/Application.mk diff --git a/examples/lvgldemo/CMakeLists.txt b/examples/lvgldemo/CMakeLists.txt deleted file mode 100644 index a3b241fa8..000000000 --- a/examples/lvgldemo/CMakeLists.txt +++ /dev/null @@ -1,37 +0,0 @@ -# ############################################################################## -# apps/examples/lvgldemo/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_LVGLDEMO) - nuttx_add_application( - NAME - lvgldemo - PRIORITY - ${CONFIG_EXAMPLES_LVGLDEMO_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_LVGLDEMO_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_LVGLDEMO} - DEPENDS - lvgl - SRCS - lvgldemo.c) -endif() diff --git a/examples/lvgldemo/Kconfig b/examples/lvgldemo/Kconfig index dfe26f1e0..cbd642684 100644 --- a/examples/lvgldemo/Kconfig +++ b/examples/lvgldemo/Kconfig @@ -12,19 +12,104 @@ menuconfig EXAMPLES_LVGLDEMO if EXAMPLES_LVGLDEMO +config EXAMPLES_LVGLDEMO_BUFF_SIZE + int "Display buffer size (in line)" + default 20 + +config EXAMPLES_LVGLDEMO_DOUBLE_BUFFERING + bool "Enable double buffering" + default n + ---help--- + When double buffering is enabled, LVGL expects the size of both + buffers as: + CONFIG_LV_HOR_RES * CONFIG_EXAMPLES_LVGLDEMO_BUFF_SIZE. + True double buffering support is enabled if both buffers have the + same dimensions as the display device resolution. Otherwise, + LVGL will perform a number of partial refreshes according to the + defined buffer size. + +config EXAMPLES_LVGLDEMO_ASYNC_FLUSH + bool "Flush the display buffer asynchronously" + default n + ---help--- + Enable this option to perform an asynchronous write of the buffer + contents to the display device. + +choice + prompt "Select a demo application" + default EXAMPLES_LVGLDEMO_WIDGETS + +config EXAMPLES_LVGLDEMO_BENCHMARK + bool "Benchmark" + +config EXAMPLES_LVGLDEMO_PRINTER + bool "Printer" + ---help--- + This demo is optimized for 800 * 480 resolution + +config EXAMPLES_LVGLDEMO_STRESS + bool "Stress" + +config EXAMPLES_LVGLDEMO_WIDGETS + bool "Widgets" + +endchoice + +if EXAMPLES_LVGLDEMO_WIDGETS + +config EXAMPLES_LVGLDEMO_WIDGETS_SLIDESHOW + bool "Enable Slideshow mode for Widgets example" + default n + ---help--- + Slideshow mode consists of a non-interactive demonstration of the + Widgets example. + +endif # EXAMPLES_LVGLDEMO_WIDGETS + config EXAMPLES_LVGLDEMO_PRIORITY - int "lvgldemo task priority" + int "lvgl task priority" default 100 config EXAMPLES_LVGLDEMO_STACKSIZE int "lvgldemo stack size" default 16384 -config EXAMPLES_LVGLDEMO_INPUT_DEVPATH +comment "Input configuration options" + depends on INPUT_TOUCHSCREEN || INPUT_MOUSE + +config EXAMPLES_LVGLDEMO_CALIBRATE + bool "Calibrate touchscreen" + default y + depends on INPUT_TOUCHSCREEN || INPUT_MOUSE + ---help--- + Calibrate touchscreen before demo start, but some touchscreen + don't need it, like capacitive touchscreen. + +if INPUT_TOUCHSCREEN + +config EXAMPLES_LVGLDEMO_MINOR + int "Touchscreen minor device number" + default 0 + ---help--- + The minor device number. Minor=N corresponds to touchscreen device + /dev/inputN. Note this value must with EXAMPLES_LVGLDEMO_DEVPATH. + Default 0. + +config EXAMPLES_LVGLDEMO_DEVPATH string "Touchscreen device path" default "/dev/input0" - depends on INPUT_TOUCHSCREEN ---help--- - The path to the touchscreen device. Default: "/dev/input0" + The path to the touchscreen device. This must be consistent with + EXAMPLES_LVGLDEMO_MINOR. Default: "/dev/input0" + +endif # INPUT_TOUCHSCREEN + +config EXAMPLES_LVGLDEMO_MOUSE + bool "Mouse interface" + default n + depends on INPUT_MOUSE + ---help--- + The LittleVGL demo can also be configured to work with a mouse + driver by setting this option. endif # EXAMPLES_LVGLDEMO diff --git a/examples/lvgldemo/Make.defs b/examples/lvgldemo/Make.defs index 7729d01d6..cd8adf98d 100644 --- a/examples/lvgldemo/Make.defs +++ b/examples/lvgldemo/Make.defs @@ -1,7 +1,5 @@ ############################################################################ -# apps/examples/lvgldemo/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 +# apps/examples/lvgdemo/Make.defs # # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with diff --git a/examples/lvgldemo/Makefile b/examples/lvgldemo/Makefile index f2645b243..486241e38 100644 --- a/examples/lvgldemo/Makefile +++ b/examples/lvgldemo/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/lvgldemo/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -22,13 +20,77 @@ include $(APPDIR)/Make.defs +# LittleVGL demo built-in application info + +CONFIG_LV_EXAMPLES_URL ?= https://github.com/lvgl/lv_demos/archive + +LVGL_EXAMPLES_VERSION = $(patsubst "%",%,$(strip $(CONFIG_LVGL_VERSION))) +LVGL_EXAMPLES_TARBALL = v$(LVGL_EXAMPLES_VERSION).zip + +LVGL_EXAMPLES_UNPACKNAME = lv_demos +UNPACK ?= unzip -o + PROGNAME = lvgldemo PRIORITY = $(CONFIG_EXAMPLES_LVGLDEMO_PRIORITY) STACKSIZE = $(CONFIG_EXAMPLES_LVGLDEMO_STACKSIZE) MODULE = $(CONFIG_EXAMPLES_LVGLDEMO) -# LVGL demo Example +# LittleVGL demo Example + +CSRCS += fbdev.c lcddev.c + +ifneq ($(CONFIG_INPUT_TOUCHSCREEN)$(CONFIG_INPUT_MOUSE),) +CSRCS += tp.c tp_cal.c +endif + +# static common assets used in multiple examples + +LV_EXAMPLE_ASSETS = $(wildcard ./lv_demos/assets/*.c) +CSRCS += $(notdir $(LV_EXAMPLE_ASSETS)) +VPATH += lv_demos/assets + +ifneq ($(CONFIG_EXAMPLES_LVGLDEMO_BENCHMARK),) +CSRCS += lv_demo_benchmark.c +VPATH += lv_demos/src/lv_demo_benchmark +endif + +ifneq ($(CONFIG_EXAMPLES_LVGLDEMO_PRINTER),) +LV_PRINTER_IMAGES = $(wildcard ./lv_demos/src/lv_demo_printer/images/*.c) +CSRCS += lv_demo_printer.c lv_demo_printer_theme.c +CSRCS += $(notdir $(LV_PRINTER_IMAGES)) +VPATH += lv_demos/src/lv_demo_printer +VPATH += lv_demos/src/lv_demo_printer/images +endif + +ifneq ($(CONFIG_EXAMPLES_LVGLDEMO_STRESS),) +CSRCS += lv_demo_stress.c +VPATH += lv_demos/src/lv_demo_stress +endif + +ifneq ($(CONFIG_EXAMPLES_LVGLDEMO_WIDGETS),) +CSRCS += lv_demo_widgets.c +VPATH += lv_demos/src/lv_demo_widgets +endif MAINSRC = lvgldemo.c +CFLAGS += ${shell $(DEFINE) "$(CC)" LV_LVGL_H_INCLUDE_SIMPLE} -Wno-format +CXXFLAGS += ${shell $(DEFINE) "$(CC)" LV_LVGL_H_INCLUDE_SIMPLE} -Wno-format + +$(LVGL_EXAMPLES_TARBALL): + $(Q) echo "Downloading: $(LVGL_EXAMPLES_TARBALL)" + $(Q) curl -O -L $(CONFIG_LV_EXAMPLES_URL)/$(LVGL_EXAMPLES_TARBALL) + +$(LVGL_EXAMPLES_UNPACKNAME): $(LVGL_EXAMPLES_TARBALL) + $(Q) echo "Unpacking: $(LVGL_EXAMPLES_TARBALL) -> $(LVGL_EXAMPLES_UNPACKNAME)" + $(Q) $(UNPACK) $(LVGL_EXAMPLES_TARBALL) + $(Q) mv lv_demos-$(LVGL_EXAMPLES_VERSION) $(LVGL_EXAMPLES_UNPACKNAME) + $(Q) touch $(LVGL_EXAMPLES_UNPACKNAME) + +context:: $(LVGL_EXAMPLES_UNPACKNAME) + +distclean:: + $(call DELDIR, $(LVGL_EXAMPLES_UNPACKNAME)) + $(call DELFILE, $(LVGL_EXAMPLES_TARBALL)) + include $(APPDIR)/Application.mk diff --git a/examples/lvgldemo/fbdev.c b/examples/lvgldemo/fbdev.c new file mode 100644 index 000000000..811b821f7 --- /dev/null +++ b/examples/lvgldemo/fbdev.c @@ -0,0 +1,469 @@ +/**************************************************************************** + * apps/examples/lvgldemo/fbdev.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include "fbdev.h" + +#include <nuttx/compiler.h> +#include <nuttx/config.h> + +#ifdef CONFIG_EXAMPLES_LVGLDEMO_ASYNC_FLUSH +#include <pthread.h> +#include <semaphore.h> +#endif + +#include <sys/ioctl.h> +#include <sys/mman.h> +#include <unistd.h> +#include <stdlib.h> +#include <stdio.h> +#include <fcntl.h> +#include <errno.h> +#include <debug.h> + +#include <nuttx/video/fb.h> +#include <nuttx/video/rgbcolors.h> + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#ifndef FBDEV_PATH +# define FBDEV_PATH "/dev/fb0" +#endif + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +struct fb_state_s +{ + int fd; + struct fb_videoinfo_s vinfo; + struct fb_planeinfo_s pinfo; + FAR void *fbmem; +}; + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +struct fb_state_s state; + +#ifdef CONFIG_EXAMPLES_LVGLDEMO_ASYNC_FLUSH +static pthread_t fb_write_thread; +static sem_t flush_sem; +static sem_t wait_sem; + +static lv_area_t lv_area; +static lv_color_t *lv_color_p; +#endif + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: fbdev_wait + * + * Description: + * Wait for the flushing operation conclusion to notify LVGL. + * + * Input Parameters: + * disp_drv - LVGL driver interface + * + * Returned Value: + * None + * + ****************************************************************************/ + +#ifdef CONFIG_EXAMPLES_LVGLDEMO_ASYNC_FLUSH + +static void fbdev_wait(lv_disp_drv_t *disp_drv) +{ + sem_wait(&wait_sem); + + /* Tell the flushing is ready */ + + lv_disp_flush_ready(disp_drv); +} + +#endif + +/**************************************************************************** + * Name: fbdev_flush_internal + * + * Description: + * Write the buffer to Framebuffer interface. + * + * Input Parameters: + * area - Area of the screen to be flushed + * color_p - A n array of colors + * + * Returned Value: + * None + * + ****************************************************************************/ + +static int fbdev_flush_internal(const lv_area_t *area, lv_color_t *color_p) +{ +#ifdef CONFIG_FB_UPDATE + struct fb_area_s fb_area; +#endif + int32_t x1 = area->x1; + int32_t y1 = area->y1; + int32_t x2 = area->x2; + int32_t y2 = area->y2; + int32_t act_x1; + int32_t act_y1; + int32_t act_x2; + int32_t act_y2; + long int location = 0; + + if (state.fbmem == NULL) + { + return ERROR; + } + + /* Return if the area is out the screen */ + + if (x2 < 0) + { + return ERROR; + } + + if (y2 < 0) + { + return ERROR; + } + + if (x1 > state.vinfo.xres - 1) + { + return ERROR; + } + + if (y1 > state.vinfo.yres - 1) + { + return ERROR; + } + + /* Truncate the area to the screen */ + + act_x1 = x1 < 0 ? 0 : x1; + act_y1 = y1 < 0 ? 0 : y1; + act_x2 = x2 > state.vinfo.xres - 1 ? state.vinfo.xres - 1 : x2; + act_y2 = y2 > state.vinfo.yres - 1 ? state.vinfo.yres - 1 : y2; + + if (state.pinfo.bpp == 8) + { + uint8_t *fbp8 = (uint8_t *)state.fbmem; + uint32_t x; + uint32_t y; + + for (y = act_y1; y <= act_y2; y++) + { + for (x = act_x1; x <= act_x2; x++) + { + location = x + (y * state.vinfo.xres); + fbp8[location] = color_p->full; + color_p++; + } + + color_p += x2 - act_x2; + } + } + + if (state.pinfo.bpp == 16) + { + uint16_t *fbp16 = (uint16_t *)state.fbmem; + uint32_t x; + uint32_t y; + + for (y = act_y1; y <= act_y2; y++) + { + for (x = act_x1; x <= act_x2; x++) + { + location = x + (y * state.vinfo.xres); + fbp16[location] = color_p->full; + color_p++; + } + + color_p += x2 - act_x2; + } + } + + if (state.pinfo.bpp == 24 || state.pinfo.bpp == 32) + { + uint32_t *fbp32 = (uint32_t *)state.fbmem; + uint32_t x; + uint32_t y; + + for (y = act_y1; y <= act_y2; y++) + { + for (x = act_x1; x <= act_x2; x++) + { + location = x + (y * state.vinfo.xres); + fbp32[location] = color_p->full; + color_p++; + } + + color_p += x2 - act_x2; + } + } + +#ifdef CONFIG_FB_UPDATE + fb_area.x = act_x1; + fb_area.y = act_y1; + fb_area.w = act_x2 - act_x1 + 1; + fb_area.h = act_y2 - act_y1 + 1; + ioctl(state.fd, FBIO_UPDATE, (unsigned long)((uintptr_t)&fb_area)); +#endif + + return OK; +} + +/**************************************************************************** + * Name: fbdev_async_flush + * + * Description: + * Flush a buffer to the marked area asynchronously. + * + * Input Parameters: + * disp_drv - LVGL driver interface + * area - Area of the screen to be flushed + * color_p - A n array of colors + * + * Returned Value: + * None + * + ****************************************************************************/ + +#ifdef CONFIG_EXAMPLES_LVGLDEMO_ASYNC_FLUSH + +static void fbdev_async_flush(lv_disp_drv_t *disp_drv, const lv_area_t *area, + lv_color_t *color_p) +{ + UNUSED(disp_drv); + + lv_area.y1 = area->y1; + lv_area.y2 = area->y2; + lv_area.x1 = area->x1; + lv_area.x2 = area->x2; + + lv_color_p = color_p; + + sem_post(&flush_sem); +} + +#endif + +/**************************************************************************** + * Name: fbdev_sync_flush + * + * Description: + * Flush a buffer to the marked area synchronously. + * + * Input Parameters: + * disp_drv - LVGL driver interface + * area - Area of the screen to be flushed + * color_p - A n array of colors + * + * Returned Value: + * None + * + ****************************************************************************/ + +#ifndef CONFIG_EXAMPLES_LVGLDEMO_ASYNC_FLUSH + +static void fbdev_sync_flush(lv_disp_drv_t *disp_drv, const lv_area_t *area, + lv_color_t *color_p) +{ + fbdev_flush_internal(area, color_p); + + /* Tell the flushing is ready */ + + lv_disp_flush_ready(disp_drv); +} + +#endif + +/**************************************************************************** + * Name: fbdev_write + * + * Description: + * Thread for writing the buffer to Framebuffer interface. + * + * Input Parameters: + * arg - Context data from the parent thread + * + * Returned Value: + * Context data to the parent thread + * + ****************************************************************************/ + +#ifdef CONFIG_EXAMPLES_LVGLDEMO_ASYNC_FLUSH + +static pthread_addr_t fbdev_write(pthread_addr_t arg) +{ + int ret = OK; + + UNUSED(arg); + + while (ret == OK) + { + sem_wait(&flush_sem); + + ret = fbdev_flush_internal(&lv_area, lv_color_p); + + sem_post(&wait_sem); + } + + gerr("Failed to write buffer contents to display device\n"); + + return NULL; +} + +#endif + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: fbdev_init + * + * Description: + * + * Input Parameters: + * lv_drvr -- LVGL driver interface + * + * Returned Value: + * None + * + ****************************************************************************/ + +int fbdev_init(lv_disp_drv_t *lv_drvr) +{ + FAR const char *fbdev = "/dev/fb0"; + int ret; + + /* Open the framebuffer driver */ + + state.fd = open(fbdev, O_RDWR); + if (state.fd < 0) + { + int errcode = errno; + gerr("Failed to open %s: %d\n", fbdev, errcode); + return EXIT_FAILURE; + } + + /* Get the characteristics of the framebuffer */ + + ret = ioctl(state.fd, FBIOGET_VIDEOINFO, + (unsigned long)((uintptr_t)&state.vinfo)); + if (ret < 0) + { + int errcode = errno; + + gerr("ioctl(FBIOGET_VIDEOINFO) failed: %d\n", errcode); + close(state.fd); + state.fd = -1; + return EXIT_FAILURE; + } + + ginfo("VideoInfo:\n\tfmt: %u\n\txres: %u\n\tyres: %u\n\tnplanes: %u\n", + state.vinfo.fmt, state.vinfo.xres, state.vinfo.yres, + state.vinfo.nplanes); + + ret = ioctl(state.fd, FBIOGET_PLANEINFO, + (unsigned long)((uintptr_t)&state.pinfo)); + if (ret < 0) + { + int errcode = errno; + gerr("ioctl(FBIOGET_PLANEINFO) failed: %d\n", errcode); + close(state.fd); + state.fd = -1; + return EXIT_FAILURE; + } + + ginfo("PlaneInfo (plane 0):\n" + "\tfbmem: %p\n\tfblen: %l\n\tstride: %u\n" + "\tdisplay: %u\n\tbpp: %u\n\t", + state.pinfo.fbmem, (unsigned long)state.pinfo.fblen, + state.pinfo.stride, state.pinfo.display, state.pinfo.bpp); + + lv_drvr->hor_res = state.vinfo.xres; + lv_drvr->ver_res = state.vinfo.yres; +#ifndef CONFIG_EXAMPLES_LVGLDEMO_ASYNC_FLUSH + lv_drvr->flush_cb = fbdev_sync_flush; +#else + lv_drvr->flush_cb = fbdev_async_flush; + lv_drvr->wait_cb = fbdev_wait; + + /* Initialize the mutexes for buffer flushing synchronization */ + + sem_init(&flush_sem, 0, 0); + sem_init(&wait_sem, 0, 0); + + /* Initialize the buffer flushing thread */ + + pthread_create(&fb_write_thread, NULL, fbdev_write, NULL); +#endif + + /* Only these pixel depths are supported. viinfo.fmt is ignored, only + * certain color formats are supported. + */ + + if (state.pinfo.bpp != 32 && state.pinfo.bpp != 16 && + state.pinfo.bpp != 8 && state.pinfo.bpp != 1) + { + gerr("bpp=%u not supported\n", state.pinfo.bpp); + close(state.fd); + state.fd = -1; + return EXIT_FAILURE; + } + + /* mmap() the framebuffer. + * + * NOTE: In the FLAT build the frame buffer address returned by the + * FBIOGET_PLANEINFO IOCTL command will be the same as the framebuffer + * address. mmap(), however, is the preferred way to get the framebuffer + * address because in the KERNEL build, it will perform the necessary + * address mapping to make the memory accessible to the application. + */ + + state.fbmem = mmap(NULL, state.pinfo.fblen, PROT_READ | PROT_WRITE, + MAP_SHARED | MAP_FILE, state.fd, 0); + if (state.fbmem == MAP_FAILED) + { + int errcode = errno; + gerr("ioctl(FBIOGET_PLANEINFO) failed: %d\n", errcode); + close(state.fd); + state.fd = -1; + return EXIT_FAILURE; + } + + ginfo("Mapped FB: %p\n", state.fbmem); + + return EXIT_SUCCESS; +} diff --git a/crypto/openssl_mbedtls_wrapper/include/openssl/des.h b/examples/lvgldemo/fbdev.h similarity index 85% rename from crypto/openssl_mbedtls_wrapper/include/openssl/des.h rename to examples/lvgldemo/fbdev.h index 2c26a25bc..d5d8ef7fe 100644 --- a/crypto/openssl_mbedtls_wrapper/include/openssl/des.h +++ b/examples/lvgldemo/fbdev.h @@ -1,7 +1,5 @@ /**************************************************************************** - * apps/crypto/openssl_mbedtls_wrapper/include/openssl/des.h - * - * SPDX-License-Identifier: Apache-2.0 + * apps/examples/lvgldemo/fbdev.h * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -17,28 +15,32 @@ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. + * ****************************************************************************/ -#ifndef OPENSSL_MBEDTLS_WRAPPER_DES_H -#define OPENSSL_MBEDTLS_WRAPPER_DES_H +#ifndef __APPS_EXAMPLES_LVGLDEMO_FBDEV_H +#define __APPS_EXAMPLES_LVGLDEMO_FBDEV_H /**************************************************************************** * Included Files ****************************************************************************/ -#include <openssl/base.h> - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ +#include <stdint.h> +#include <lvgl/lvgl.h> #ifdef __cplusplus extern "C" { #endif +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +int fbdev_init(lv_disp_drv_t *lv_drvr); + #ifdef __cplusplus } #endif -#endif /* OPENSSL_MBEDTLS_WRAPPER_DES_H */ +#endif /* __APPS_EXAMPLES_LVGLDEMO_FBDEV_H */ diff --git a/examples/lvgldemo/lcddev.c b/examples/lvgldemo/lcddev.c new file mode 100644 index 000000000..092410c09 --- /dev/null +++ b/examples/lvgldemo/lcddev.c @@ -0,0 +1,315 @@ +/**************************************************************************** + * apps/examples/lvgldemo/lcddev.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include "lcddev.h" + +#include <nuttx/compiler.h> +#include <nuttx/config.h> +#include <nuttx/lcd/lcd_dev.h> + +#ifdef CONFIG_EXAMPLES_LVGLDEMO_ASYNC_FLUSH +#include <pthread.h> +#include <semaphore.h> +#endif + +#include <sys/ioctl.h> +#include <sys/mman.h> +#include <unistd.h> +#include <stdlib.h> +#include <stdio.h> +#include <fcntl.h> +#include <errno.h> +#include <debug.h> + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#ifndef LCDDEV_PATH +# define LCDDEV_PATH "/dev/lcd0" +#endif + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +struct lcd_state_s +{ + int fd; + struct fb_videoinfo_s vinfo; + struct lcd_planeinfo_s pinfo; + bool rotated; +}; + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static struct lcd_state_s state; + +#ifdef CONFIG_EXAMPLES_LVGLDEMO_ASYNC_FLUSH +static pthread_t lcd_write_thread; +static sem_t flush_sem; +static sem_t wait_sem; +static struct lcddev_area_s lcd_area; +#endif + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: lcddev_wait + * + * Description: + * Wait for the flushing operation conclusion to notify LVGL. + * + * Input Parameters: + * disp_drv - LVGL driver interface + * + * Returned Value: + * None + * + ****************************************************************************/ + +#ifdef CONFIG_EXAMPLES_LVGLDEMO_ASYNC_FLUSH + +static void lcddev_wait(lv_disp_drv_t *disp_drv) +{ + sem_wait(&wait_sem); + + /* Tell the flushing is ready */ + + lv_disp_flush_ready(disp_drv); +} + +#endif + +/**************************************************************************** + * Name: lcddev_flush + * + * Description: + * Flush a buffer to the marked area. + * + * Input Parameters: + * disp_drv - LVGL driver interface + * lv_area_t - Area of the screen to be flushed + * color_p - A n array of colors + * + * Returned Value: + * None + * + ****************************************************************************/ + +#ifdef CONFIG_EXAMPLES_LVGLDEMO_ASYNC_FLUSH + +static void lcddev_async_flush(lv_disp_drv_t *disp_drv, + const lv_area_t *area, + lv_color_t *color_p) +{ + UNUSED(disp_drv); + + lcd_area.row_start = area->y1; + lcd_area.row_end = area->y2; + lcd_area.col_start = area->x1; + lcd_area.col_end = area->x2; + + lcd_area.data = (uint8_t *)color_p; + + sem_post(&flush_sem); +} + +#else + +static void lcddev_sync_flush(lv_disp_drv_t *disp_drv, const lv_area_t *area, + lv_color_t *color_p) +{ + int ret; + struct lcddev_area_s lcd_area; + + lcd_area.row_start = area->y1; + lcd_area.row_end = area->y2; + lcd_area.col_start = area->x1; + lcd_area.col_end = area->x2; + + lcd_area.data = (uint8_t *)color_p; + + ret = ioctl(state.fd, LCDDEVIO_PUTAREA, + (unsigned long)((uintptr_t)&lcd_area)); + + if (ret < 0) + { + int errcode = errno; + + gerr("ioctl(LCDDEVIO_PUTAREA) failed: %d\n", errcode); + close(state.fd); + return; + } + + /* Tell the flushing is ready */ + + lv_disp_flush_ready(disp_drv); +} + +#endif + +/**************************************************************************** + * Name: lcddev_write + * + * Description: + * Write the buffer to LCD interface. + * + * Input Parameters: + * None + * + * Returned Value: + * None + * + ****************************************************************************/ + +#ifdef CONFIG_EXAMPLES_LVGLDEMO_ASYNC_FLUSH + +static pthread_addr_t lcddev_write(pthread_addr_t addr) +{ + int ret = OK; + int errcode; + + while (ret == OK) + { + sem_wait(&flush_sem); + ret = ioctl(state.fd, LCDDEVIO_PUTAREA, (unsigned long)&lcd_area); + if (ret < 0) + { + errcode = errno; + } + + sem_post(&wait_sem); + } + + if (ret != OK) + { + gerr("ioctl(LCDDEVIO_PUTAREA) failed: %d\n", errcode); + close(state.fd); + state.fd = -1; + } + + return NULL; +} + +#endif + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: lcddev_init + * + * Description: + * Initialize LCD device. + * + * Input Parameters: + * lv_drvr -- LVGL driver interface + * + * Returned Value: + * EXIT_SUCCESS on success; EXIT_FAILURE on failure. + * + ****************************************************************************/ + +int lcddev_init(lv_disp_drv_t *lv_drvr) +{ + FAR const char *lcddev = LCDDEV_PATH; + int ret; + + /* Open the framebuffer driver */ + + state.fd = open(lcddev, 0); + if (state.fd < 0) + { + int errcode = errno; + gerr("Failed to open %s: %d\n", state.fd, errcode); + return EXIT_FAILURE; + } + + /* Get the characteristics of the framebuffer */ + + ret = ioctl(state.fd, LCDDEVIO_GETVIDEOINFO, + (unsigned long)((uintptr_t)&state.vinfo)); + if (ret < 0) + { + int errcode = errno; + + gerr("ioctl(LCDDEVIO_GETVIDEOINFO) failed: %d\n", errcode); + close(state.fd); + state.fd = -1; + return EXIT_FAILURE; + } + + ginfo("VideoInfo:\n\tfmt: %u\n\txres: %u\n\tyres: %u\n\tnplanes: %u\n", + state.vinfo.fmt, state.vinfo.xres, state.vinfo.yres, + state.vinfo.nplanes); + + ret = ioctl(state.fd, LCDDEVIO_GETPLANEINFO, + (unsigned long)((uintptr_t)&state.pinfo)); + if (ret < 0) + { + int errcode = errno; + gerr("ioctl(LCDDEVIO_GETPLANEINFO) failed: %d\n", errcode); + close(state.fd); + state.fd = -1; + return EXIT_FAILURE; + } + + ginfo("PlaneInfo (plane 0):\n\tbpp: %u\n", state.pinfo.bpp); + + if (state.pinfo.bpp != CONFIG_LV_COLOR_DEPTH) + { + /* For the LCD driver we do not have a great way to translate this + * so fail to initialize. + */ + + gerr("Display bpp (%u) did not match CONFIG_LV_COLOR_DEPTH (%u)\n", + state.pinfo.bpp, CONFIG_LV_COLOR_DEPTH); + } + + lv_drvr->hor_res = state.vinfo.xres; + lv_drvr->ver_res = state.vinfo.yres; +#ifndef CONFIG_EXAMPLES_LVGLDEMO_ASYNC_FLUSH + lv_drvr->flush_cb = lcddev_sync_flush; +#else + lv_drvr->flush_cb = lcddev_async_flush; + lv_drvr->wait_cb = lcddev_wait; + + /* Initialize the mutexes for buffer flushing synchronization */ + + sem_init(&flush_sem, 0, 0); + sem_init(&wait_sem, 0, 0); + + /* Initialize the buffer flushing thread */ + + pthread_create(&lcd_write_thread, NULL, lcddev_write, NULL); +#endif + + return EXIT_SUCCESS; +} diff --git a/crypto/openssl_mbedtls_wrapper/include/openssl/pem.h b/examples/lvgldemo/lcddev.h similarity index 84% rename from crypto/openssl_mbedtls_wrapper/include/openssl/pem.h rename to examples/lvgldemo/lcddev.h index 0af64792f..18d5b786e 100644 --- a/crypto/openssl_mbedtls_wrapper/include/openssl/pem.h +++ b/examples/lvgldemo/lcddev.h @@ -1,7 +1,5 @@ /**************************************************************************** - * apps/crypto/openssl_mbedtls_wrapper/include/openssl/pem.h - * - * SPDX-License-Identifier: Apache-2.0 + * apps/examples/lvgldemo/lcddev.h * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -17,28 +15,32 @@ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. + * ****************************************************************************/ -#ifndef OPENSSL_MBEDTLS_WRAPPER_PEM_H -#define OPENSSL_MBEDTLS_WRAPPER_PEM_H +#ifndef __APPS_EXAMPLES_LVGLDEMO_LCDDEV_H +#define __APPS_EXAMPLES_LVGLDEMO_LCDDEV_H /**************************************************************************** * Included Files ****************************************************************************/ -#include <openssl/base.h> - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ +#include <stdint.h> +#include <lvgl/lvgl.h> #ifdef __cplusplus extern "C" { #endif +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +int lcddev_init(lv_disp_drv_t *lv_drvr); + #ifdef __cplusplus } #endif -#endif /* OPENSSL_MBEDTLS_WRAPPER_PEM_H */ +#endif /* __APPS_EXAMPLES_LVGLDEMO_LCDDEV_H */ diff --git a/examples/mdnsd/mdnsd_daemon.h b/examples/lvgldemo/lv_ex_conf.h similarity index 52% rename from examples/mdnsd/mdnsd_daemon.h rename to examples/lvgldemo/lv_ex_conf.h index 4fda59587..78cedf96a 100644 --- a/examples/mdnsd/mdnsd_daemon.h +++ b/examples/lvgldemo/lv_ex_conf.h @@ -1,7 +1,5 @@ /**************************************************************************** - * apps/examples/mdnsd/mdnsd_daemon.h - * - * SPDX-License-Identifier: Apache-2.0 + * apps/examples/lvgldemo/lv_ex_conf.h * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -20,38 +18,55 @@ * ****************************************************************************/ -#ifndef __APPS_EXAMPLES_MDNSD_H -#define __APPS_EXAMPLES_MDNSD_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ +#ifndef __APPS_EXAMPLES_LVGLDEMO_LV_EX_CONF_H +#define __APPS_EXAMPLES_LVGLDEMO_LV_EX_CONF_H /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ -/**************************************************************************** - * Public Types - ****************************************************************************/ +/* Enable printf-ing data in demoes and examples */ -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ +#define LV_EX_PRINTF 1 -#ifdef __cplusplus -#define EXTERN extern "C" -extern "C" -{ +/* Add PC keyboard support to some examples + * (`lv_drivers` repository is required) + */ + +#define LV_EX_KEYBOARD 0 + +/* Add 'encoder' (mouse wheel) support to some examples + * (`lv_drivers` repository is required) + */ + +#define LV_EX_MOUSEWHEEL 0 + +/* Show some widget */ + +#define LV_USE_DEMO_WIDGETS 1 +#if LV_USE_DEMO_WIDGETS +#ifdef CONFIG_EXAMPLES_LVGLDEMO_WIDGETS_SLIDESHOW +#define LV_DEMO_WIDGETS_SLIDESHOW CONFIG_EXAMPLES_LVGLDEMO_WIDGETS_SLIDESHOW #else -#define EXTERN extern +#define LV_DEMO_WIDGETS_SLIDESHOW 0 +#endif #endif -int mdnsd_daemon(int argc, FAR char *argv[], bool start); +/* Printer demo, optimized for 800x480 */ -#undef EXTERN -#ifdef __cplusplus -} -#endif +#define LV_USE_DEMO_PRINTER 1 + +/* Demonstrate the usage of encoder and keyboard */ + +#define LV_USE_DEMO_KEYPAD_AND_ENCODER 1 + +/* Benchmark your system */ + +#define LV_USE_DEMO_BENCHMARK 1 + +/* Stress test for LVGL */ + +#define LV_USE_DEMO_STRESS 1 + +#endif /* __APPS_EXAMPLES_LVGLDEMO_LV_EX_CONF_H */ -#endif /* __APPS_EXAMPLES_MDNSD_H */ diff --git a/examples/lvgldemo/lvgldemo.c b/examples/lvgldemo/lvgldemo.c index b6ab1e5ab..c9dd63a8f 100644 --- a/examples/lvgldemo/lvgldemo.c +++ b/examples/lvgldemo/lvgldemo.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/lvgldemo/lvgldemo.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -25,51 +23,84 @@ ****************************************************************************/ #include <nuttx/config.h> -#include <unistd.h> + #include <sys/boardctl.h> +#include <unistd.h> +#include <stddef.h> +#include <stdlib.h> +#include <time.h> +#include <debug.h> #include <lvgl/lvgl.h> -#include <lvgl/demos/lv_demos.h> -#ifdef CONFIG_LV_USE_NUTTX_LIBUV -#include <uv.h> + +#include "fbdev.h" +#include "lcddev.h" + +#if defined(CONFIG_INPUT_TOUCHSCREEN) || defined(CONFIG_INPUT_MOUSE) +#include "tp.h" +#include "tp_cal.h" #endif /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ -/**************************************************************************** - * Private Types - ****************************************************************************/ +/* Should we perform board-specific driver initialization? There are two + * ways that board initialization can occur: 1) automatically via + * board_late_initialize() during bootupif CONFIG_BOARD_LATE_INITIALIZE + * or 2). + * via a call to boardctl() if the interface is enabled + * (CONFIG_BOARDCTL=y). + * If this task is running as an NSH built-in application, then that + * initialization has probably already been performed otherwise we do it + * here. + */ + +#undef NEED_BOARDINIT + +#if defined(CONFIG_BOARDCTL) && !defined(CONFIG_NSH_ARCHINIT) +# define NEED_BOARDINIT 1 +#endif + +#define DISPLAY_BUFFER_SIZE (CONFIG_LV_HOR_RES * \ + CONFIG_EXAMPLES_LVGLDEMO_BUFF_SIZE) /**************************************************************************** - * Private Data + * Public Functions Prototypes ****************************************************************************/ +void lv_demo_benchmark(void); +void lv_demo_printer(void); +void lv_demo_stress(void); +void lv_demo_widgets(void); + /**************************************************************************** * Private Functions ****************************************************************************/ -#ifdef CONFIG_LV_USE_NUTTX_LIBUV -static void lv_nuttx_uv_loop(uv_loop_t *loop, lv_nuttx_result_t *result) +/**************************************************************************** + * Name: monitor_cb + * + * Description: + * Monitoring callback from lvgl every time the screen is flushed. + * + ****************************************************************************/ + +static void monitor_cb(lv_disp_drv_t * disp_drv, uint32_t time, uint32_t px) { - lv_nuttx_uv_t uv_info; - void *data; - - uv_loop_init(loop); - - lv_memset(&uv_info, 0, sizeof(uv_info)); - uv_info.loop = loop; - uv_info.disp = result->disp; - uv_info.indev = result->indev; -#ifdef CONFIG_UINPUT_TOUCH - uv_info.uindev = result->utouch_indev; -#endif - - data = lv_nuttx_uv_init(&uv_info); - uv_run(loop, UV_RUN_DEFAULT); - lv_nuttx_uv_deinit(&data); + ginfo("%" PRIu32 " px refreshed in %" PRIu32 " ms\n", px, time); } + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static lv_color_t buffer1[DISPLAY_BUFFER_SIZE]; + +#ifdef CONFIG_EXAMPLES_LVGLDEMO_DOUBLE_BUFFERING +static lv_color_t buffer2[DISPLAY_BUFFER_SIZE]; +#else +# define buffer2 NULL #endif /**************************************************************************** @@ -77,7 +108,7 @@ static void lv_nuttx_uv_loop(uv_loop_t *loop, lv_nuttx_result_t *result) ****************************************************************************/ /**************************************************************************** - * Name: main or lv_demos_main + * Name: main or lvgldemo_main * * Description: * @@ -91,67 +122,117 @@ static void lv_nuttx_uv_loop(uv_loop_t *loop, lv_nuttx_result_t *result) int main(int argc, FAR char *argv[]) { - lv_nuttx_dsc_t info; - lv_nuttx_result_t result; + lv_disp_drv_t disp_drv; + lv_disp_buf_t disp_buf; -#ifdef CONFIG_LV_USE_NUTTX_LIBUV - uv_loop_t ui_loop; - lv_memzero(&ui_loop, sizeof(ui_loop)); +#if defined(CONFIG_INPUT_TOUCHSCREEN) || defined(CONFIG_INPUT_MOUSE) +#ifndef CONFIG_EXAMPLES_LVGLDEMO_CALIBRATE + lv_point_t p[4]; + + /* top left */ + + p[0].x = 0; + p[0].y = 0; + + /* top right */ + + p[1].x = LV_HOR_RES; + p[1].y = 0; + + /* bottom left */ + + p[2].x = 0; + p[2].y = LV_VER_RES; + + /* bottom right */ + + p[3].x = LV_HOR_RES; + p[3].y = LV_VER_RES; +#endif #endif - if (lv_is_initialized()) - { - LV_LOG_ERROR("LVGL already initialized! aborting."); - return -1; - } +#ifdef NEED_BOARDINIT + /* Perform board-specific driver initialization */ + + boardctl(BOARDIOC_INIT, 0); + +#ifdef CONFIG_BOARDCTL_FINALINIT + /* Perform architecture-specific final-initialization (if configured) */ + + boardctl(BOARDIOC_FINALINIT, 0); +#endif +#endif + + /* LVGL initialization */ lv_init(); - lv_nuttx_dsc_init(&info); + /* Basic LVGL display driver initialization */ -#ifdef CONFIG_LV_USE_NUTTX_LCD - info.fb_path = "/dev/lcd0"; -#endif + lv_disp_buf_init(&disp_buf, buffer1, buffer2, DISPLAY_BUFFER_SIZE); + lv_disp_drv_init(&disp_drv); + disp_drv.buffer = &disp_buf; + disp_drv.monitor_cb = monitor_cb; -#ifdef CONFIG_INPUT_TOUCHSCREEN - info.input_path = CONFIG_EXAMPLES_LVGLDEMO_INPUT_DEVPATH; -#endif + /* Display interface initialization */ - lv_nuttx_init(&info, &result); - - if (result.disp == NULL) + if (fbdev_init(&disp_drv) != EXIT_SUCCESS) { - LV_LOG_ERROR("lv_demos initialization failure!"); - return 1; + /* Failed to use framebuffer falling back to lcd driver */ + + if (lcddev_init(&disp_drv) != EXIT_SUCCESS) + { + /* No possible drivers left, fail */ + + return EXIT_FAILURE; + } } - if (!lv_demos_create(&argv[1], argc - 1)) - { - lv_demos_show_help(); + lv_disp_drv_register(&disp_drv); - /* we can add custom demos here */ +#if defined(CONFIG_INPUT_TOUCHSCREEN) || defined(CONFIG_INPUT_MOUSE) + /* Touchpad Initialization */ - goto demo_end; - } + tp_init(); + lv_indev_drv_t indev_drv; + lv_indev_drv_init(&indev_drv); + indev_drv.type = LV_INDEV_TYPE_POINTER; -#ifdef CONFIG_LV_USE_NUTTX_LIBUV - lv_nuttx_uv_loop(&ui_loop, &result); + /* This function will be called periodically (by the library) to get the + * mouse position and state. + */ + + indev_drv.read_cb = tp_read; + lv_indev_drv_register(&indev_drv); +#endif + +#if defined(CONFIG_EXAMPLES_LVGLDEMO_BENCHMARK) + lv_demo_benchmark(); +#elif defined(CONFIG_EXAMPLES_LVGLDEMO_PRINTER) + lv_demo_printer(); +#elif defined(CONFIG_EXAMPLES_LVGLDEMO_STRESS) + lv_demo_stress(); +#elif defined(CONFIG_EXAMPLES_LVGLDEMO_WIDGETS) + lv_demo_widgets(); +#endif + +#if defined(CONFIG_INPUT_TOUCHSCREEN) || defined(CONFIG_INPUT_MOUSE) + /* Start TP calibration */ + +#ifdef CONFIG_EXAMPLES_LVGLDEMO_CALIBRATE + tp_cal_create(); #else + tp_set_cal_values(p, p + 1, p + 2, p + 3); +#endif +#endif + + /* Handle LVGL tasks */ + while (1) { - uint32_t idle; - idle = lv_timer_handler(); - - /* Minimum sleep of 1ms */ - - idle = idle ? idle : 1; - usleep(idle * 1000); + lv_task_handler(); + usleep(10000); } -#endif -demo_end: - lv_nuttx_deinit(&result); - lv_deinit(); - - return 0; + return EXIT_SUCCESS; } diff --git a/examples/lvgldemo/tp.c b/examples/lvgldemo/tp.c new file mode 100644 index 000000000..4cc298eac --- /dev/null +++ b/examples/lvgldemo/tp.c @@ -0,0 +1,279 @@ +/**************************************************************************** + * apps/examples/lvgldemo/tp.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#include <sys/types.h> + +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <fcntl.h> +#include <errno.h> +#include <debug.h> + +#ifdef CONFIG_EXAMPLES_LVGLDEMO_MOUSE +# include <nuttx/input/mouse.h> +#endif + +#include <nuttx/input/touchscreen.h> + +#include "tp.h" + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static int fd; +static bool calibrated = false; +static int x_range; +static int y_range; +static int x_offset; +static int y_offset; +static bool xy_inv; +static bool x_inv; +static bool y_inv; + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: tp_init + * + * Description: + * Initialize The Touch pad + * + * Input Parameters: + * None + * + * Returned Value: + * Zero (OK) on success; a positive error code on failure. + * + ****************************************************************************/ + +int tp_init(void) +{ + int errval = 0; + + /* Open the touchscreen device for reading */ + + printf("tp_init: Opening %s\n", CONFIG_EXAMPLES_LVGLDEMO_DEVPATH); + fd = open(CONFIG_EXAMPLES_LVGLDEMO_DEVPATH, O_RDONLY | O_NONBLOCK); + if (fd < 0) + { + printf("tp_init: open %s failed: %d\n", + CONFIG_EXAMPLES_LVGLDEMO_DEVPATH, errno); + errval = 2; + goto errout; + } + + return OK; + +errout: + printf("Terminating!\n"); + fflush(stdout); + return errval; +} + +/**************************************************************************** + * Name: tp_read + * + * Description: + * Read a TP data and store in 'data' argument + * + * Input Parameters: + * indev_drv - Input device handler + * data - Store the x, y and state information here + * + * Returned Value: + * false: no more data to read; true: there are more data to read. + * + ****************************************************************************/ + +bool tp_read(struct _lv_indev_drv_t *indev_drv, lv_indev_data_t *data) +{ + struct touch_sample_s sample; + int nbytes; + static int last_x = 0; + static int last_y = 0; + static lv_indev_state_t last_state = LV_INDEV_STATE_REL; + + /* Be sure at least the previous state is set */ + + data->point.x = last_x; + data->point.y = last_y; + data->state = last_state; + + /* Read one sample */ + + nbytes = read(fd, &sample, sizeof(struct touch_sample_s)); + + /* Handle unexpected return values */ + + if (nbytes < 0 || nbytes != sizeof(struct touch_sample_s)) + { + return false; + } + + if (sample.point[0].flags & TOUCH_DOWN + || sample.point[0].flags & TOUCH_MOVE) + { + if (calibrated) + { + if (xy_inv) + { + last_x = sample.point[0].y; + last_y = sample.point[0].x; + } + else + { + last_x = sample.point[0].x; + last_y = sample.point[0].y; + } + + /* Remove offset */ + + last_x -= x_offset; + last_y -= y_offset; + + last_x = (int)((int)last_x * LV_HOR_RES) / x_range; + last_y = (int)((int)last_y * LV_VER_RES) / y_range; + + if (x_inv) + { + last_x = LV_HOR_RES - last_x; + } + + if (y_inv) + { + last_y = LV_VER_RES - last_y; + } + } + else + { + last_x = sample.point[0].x; + last_y = sample.point[0].y; + } + + last_state = LV_INDEV_STATE_PR; + } + else if (sample.point[0].flags & TOUCH_UP) + { + last_state = LV_INDEV_STATE_REL; + } + else if (sample.point[0].flags & TOUCH_UP) + { + last_state = LV_INDEV_STATE_REL; + } + + /* Update touchpad data */ + + data->point.x = last_x; + data->point.y = last_y; + data->state = last_state; + + fflush(stdout); + return false; +} + +/**************************************************************************** + * Name: tp_read + * + * Description: + * Set calibration data + * + * Input Parameters: + * ul - Upper left hand corner TP value + * ur - Upper right hand corner TP value + * lr - Lower right hand corner TP value + * ll - Lower left hand corner TP value + * + * Returned Value: + * None + * + ****************************************************************************/ + +void tp_set_cal_values(FAR lv_point_t *ul, FAR lv_point_t *ur, + FAR lv_point_t *lr, FAR lv_point_t *ll) +{ + /* Is x/y inverted? */ + + if (abs(ul->x - ur->x) < LV_HOR_RES / 2) + { + /* No real change in x horizontally */ + + xy_inv = true; + } + + if (xy_inv) + { + /* Is x inverted */ + + if (ur->y < ul->y) + { + x_inv = true; + } + + /* Is y inverted */ + + if (ll->x < ul->x) + { + y_inv = true; + } + + x_range = abs(ul->y - ur->y); + y_range = abs(ul->x - ll->x); + x_offset = x_inv ? ur->y : ul->y; + y_offset = y_inv ? ll->x : ul->x; + } + else + { + /* Is x inverted */ + + if (ur->x < ul->x) + { + x_inv = true; + } + + /* Is y inverted */ + + if (ll->y < ul->y) + { + y_inv = true; + } + + x_range = abs(ul->x - ur->x); + y_range = abs(ul->y - ll->y); + x_offset = x_inv ? ur->x : ul->x; + y_offset = y_inv ? ll->y : ul->y; + } + + calibrated = true; + + printf("tp_cal result\n"); + printf("offset x:%d, y:%d\n", x_offset, y_offset); + printf("range x:%d, y:%d\n", x_range, y_range); + printf("invert x/y:%d, x:%d, y:%d\n\n", xy_inv, x_inv, y_inv); +} diff --git a/examples/lvgldemo/tp.h b/examples/lvgldemo/tp.h new file mode 100644 index 000000000..1507cb663 --- /dev/null +++ b/examples/lvgldemo/tp.h @@ -0,0 +1,129 @@ +/**************************************************************************** + * apps/examples/lvgldemo/tp.h + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __APPS_EXAMPLES_LVGLDEMO_TP_H +#define __APPS_EXAMPLES_LVGLDEMO_TP_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> +#include <lvgl/lvgl.h> + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Configuration ************************************************************/ + +/* CONFIG_EXAMPLES_LVGLDEMO_MINOR - The minor device number. Minor=N + * corresponds to touchscreen device /dev/input0. Note this value must + * with CONFIG_EXAMPLES_LVGLDEMO_DEVPATH. Default 0. + * CONFIG_EXAMPLES_LVGLDEMO_DEVPATH - The path to the touchscreen + * device. This must be consistent with CONFIG_EXAMPLES_LVGLDEMO_MINOR. + * Default: "/dev/input0" + * CONFIG_EXAMPLES_LVGLDEMO_MOUSE - The touchscreen test can also be + * configured to work with a mouse driver by setting this option. + */ + +#if !defined(CONFIG_INPUT_TOUCHSCREEN) && !defined(CONFIG_INPUT_MOUSE) +# error "Input device support is not enabled (CONFIG_INPUT_TOUCHSCREEN || CONFIG_INPUT_MOUSE)" +#endif + +#ifndef CONFIG_EXAMPLES_LVGLDEMO_MINOR +# undef CONFIG_EXAMPLES_LVGLDEMO_DEVPATH +# define CONFIG_EXAMPLES_LVGLDEMO_MINOR 0 +# ifdef CONFIG_EXAMPLES_LVGLDEMO_MOUSE +# define CONFIG_EXAMPLES_LVGLDEMO_DEVPATH "/dev/mouse0" +# else +# define CONFIG_EXAMPLES_LVGLDEMO_DEVPATH "/dev/input0" +# endif +#endif + +#ifndef CONFIG_EXAMPLES_LVGLDEMO_DEVPATH +# undef CONFIG_EXAMPLES_LVGLDEMO_MINOR +# define CONFIG_EXAMPLES_LVGLDEMO_MINOR 0 +# ifdef CONFIG_EXAMPLES_LVGLDEMO_MOUSE +# define CONFIG_EXAMPLES_LVGLDEMO_DEVPATH "/dev/mouse0" +# else +# define CONFIG_EXAMPLES_LVGLDEMO_DEVPATH "/dev/input0" +# endif +#endif + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Name: tp_init + * + * Description: + * Initialize The Touch pad + * + * Input Parameters: + * None + * + * Returned Value: + * Zero (OK) on success; a positive error code on failure. + * + ****************************************************************************/ + +int tp_init(void); + +/**************************************************************************** + * Name: tp_read + * + * Description: + * Read a TP data and store in 'data' argument + * + * Input Parameters: + * indev_drv - Input device handler + * data - Store the x, y and state information here + * + * Returned Value: + * false: no more data to read; true: there are more data to read. + * + ****************************************************************************/ + +bool tp_read(FAR struct _lv_indev_drv_t *indev_drv, + FAR lv_indev_data_t *data); + +/**************************************************************************** + * Name: tp_read + * + * Description: + * Set calibration data + * + * Input Parameters: + * ul - Upper left hand corner TP value + * ur - Upper right hand corner TP value + * lr - Lower right hand corner TP value + * ll - Lower left hand corner TP value + * + * Returned Value: + * None + * + ****************************************************************************/ + +void tp_set_cal_values(FAR lv_point_t *ul, FAR lv_point_t *ur, + FAR lv_point_t *lr, FAR lv_point_t *ll); + +#endif /* __APPS_EXAMPLES_LVGLDEMO_TP_H */ diff --git a/examples/lvgldemo/tp_cal.c b/examples/lvgldemo/tp_cal.c new file mode 100644 index 000000000..ccb067a14 --- /dev/null +++ b/examples/lvgldemo/tp_cal.c @@ -0,0 +1,332 @@ +/**************************************************************************** + * apps/examples/lvgldemo/tp_cal.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <stdio.h> + +#include <lvgl/lvgl.h> +#include "tp.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define CIRCLE_SIZE 20 +#define TP_MAX_VALUE 5000 + +/**************************************************************************** + * Private Type Definitions + ****************************************************************************/ + +enum tp_cal_state_e +{ + TP_CAL_STATE_INIT, + TP_CAL_STATE_WAIT_TOP_LEFT, + TP_CAL_STATE_WAIT_TOP_RIGHT, + TP_CAL_STATE_WAIT_BOTTOM_RIGHT, + TP_CAL_STATE_WAIT_BOTTOM_LEFT, + TP_CAL_STATE_WAIT_LEAVE, + TP_CAL_STATE_READY, +}; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +static void btn_click_action(FAR lv_obj_t *scr, lv_event_t event); + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static enum tp_cal_state_e state; +static lv_point_t p[4]; +static lv_obj_t *prev_scr; +static lv_obj_t *big_btn; +static lv_obj_t *label_main; +static lv_obj_t *circ_area; +static lv_theme_t *prev_theme; + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: btn_click_action + * + * Description: + * + * Input Parameters: + * scr + * event + * + * Returned Value: + * ? + * + ****************************************************************************/ + +static void btn_click_action(FAR lv_obj_t *scr, lv_event_t event) +{ + if (event == LV_EVENT_CLICKED) + { + if (state == TP_CAL_STATE_WAIT_TOP_LEFT) + { + lv_indev_t *indev = lv_indev_get_act(); + char buf[64]; +#if LV_USE_ANIMATION + lv_anim_t a; +#endif + + lv_indev_get_point(indev, &p[0]); + + sprintf(buf, "x: %d\ny: %d", p[0].x, p[0].y); + lv_obj_t *label_coord = lv_label_create(lv_scr_act(), NULL); + lv_label_set_text(label_coord, buf); + + lv_label_set_text(label_main, "Click the circle in\n" + "upper right-hand corner"); + + lv_obj_set_pos(label_main, + (LV_HOR_RES - lv_obj_get_width(label_main)) / 2, + (LV_VER_RES - lv_obj_get_height(label_main)) / 2); + +#if LV_USE_ANIMATION + lv_anim_init(&a); + lv_anim_set_var(&a, circ_area); + lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t)lv_obj_set_x); + lv_anim_set_time(&a, 500); + lv_anim_set_values(&a, 0, LV_HOR_RES - CIRCLE_SIZE); + lv_anim_set_delay(&a, 200); + lv_anim_start(&a); +#else + lv_obj_set_pos(circ_area, LV_HOR_RES - CIRCLE_SIZE, 0); +#endif + + state = TP_CAL_STATE_WAIT_TOP_RIGHT; + } + else if (state == TP_CAL_STATE_WAIT_TOP_RIGHT) + { + lv_indev_t *indev = lv_indev_get_act(); + char buf[64]; + +#if LV_USE_ANIMATION + lv_anim_t a; +#endif + + lv_indev_get_point(indev, &p[1]); + + sprintf(buf, "x: %d\ny: %d", p[1].x, p[1].y); + lv_obj_t *label_coord = lv_label_create(lv_scr_act(), NULL); + lv_label_set_text(label_coord, buf); + lv_obj_set_pos(label_coord, + LV_HOR_RES - lv_obj_get_width(label_coord), + 0); + + lv_label_set_text(label_main, "Click the circle in\n" + "lower right-hand corner"); + + lv_obj_set_pos(label_main, + (LV_HOR_RES - lv_obj_get_width(label_main)) / 2, + (LV_VER_RES - lv_obj_get_height(label_main)) / 2); + +#if LV_USE_ANIMATION + lv_anim_init(&a); + lv_anim_set_var(&a, circ_area); + lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t)lv_obj_set_y); + lv_anim_set_time(&a, 500); + lv_anim_set_values(&a, 0, LV_VER_RES - CIRCLE_SIZE); + lv_anim_set_delay(&a, 200); + lv_anim_start(&a); +#else + lv_obj_set_pos(circ_area, + LV_HOR_RES - CIRCLE_SIZE, LV_VER_RES - CIRCLE_SIZE); +#endif + + state = TP_CAL_STATE_WAIT_BOTTOM_RIGHT; + } + else if (state == TP_CAL_STATE_WAIT_BOTTOM_RIGHT) + { + lv_indev_t *indev = lv_indev_get_act(); + char buf[64]; +#if LV_USE_ANIMATION + lv_anim_t a; +#endif + lv_indev_get_point(indev, &p[2]); + + sprintf(buf, "x: %d\ny: %d", p[2].x, p[2].y); + lv_obj_t *label_coord = lv_label_create(lv_scr_act(), NULL); + lv_label_set_text(label_coord, buf); + lv_obj_set_pos(label_coord, + LV_HOR_RES - lv_obj_get_width(label_coord), + LV_VER_RES - lv_obj_get_height(label_coord)); + + lv_label_set_text(label_main, "Click the circle in\n" + "lower left-hand corner"); + + lv_obj_set_pos(label_main, + (LV_HOR_RES - lv_obj_get_width(label_main)) / 2, + (LV_VER_RES - lv_obj_get_height(label_main)) / 2); + +#if LV_USE_ANIMATION + lv_anim_init(&a); + lv_anim_set_var(&a, circ_area); + lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t)lv_obj_set_x); + lv_anim_set_time(&a, 500); + lv_anim_set_values(&a, LV_HOR_RES - CIRCLE_SIZE, 0); + lv_anim_set_delay(&a, 200); + lv_anim_start(&a); +#else + lv_obj_set_pos(circ_area, 0, LV_VER_RES - CIRCLE_SIZE); +#endif + + state = TP_CAL_STATE_WAIT_BOTTOM_LEFT; + } + else if (state == TP_CAL_STATE_WAIT_BOTTOM_LEFT) + { + lv_indev_t *indev = lv_indev_get_act(); + char buf[64]; + + lv_indev_get_point(indev, &p[3]); + + lv_label_set_text(label_main, "Click the screen\n" + "to leave calibration"); + + lv_obj_set_pos(label_main, + (LV_HOR_RES - lv_obj_get_width(label_main)) / 2, + (LV_VER_RES - lv_obj_get_height(label_main)) / 2); + + sprintf(buf, "x: %d\ny: %d", p[3].x, p[3].y); + lv_obj_t *label_coord = lv_label_create(lv_scr_act(), NULL); + lv_label_set_text(label_coord, buf); + lv_obj_set_pos(label_coord, 0, + LV_VER_RES - lv_obj_get_height(label_coord)); + + lv_obj_del(circ_area); + + state = TP_CAL_STATE_WAIT_LEAVE; + } + else if (state == TP_CAL_STATE_WAIT_LEAVE) + { + lv_theme_set_act(prev_theme); + lv_scr_load(prev_scr); + tp_set_cal_values(&p[0], &p[1], &p[2], &p[3]); + state = TP_CAL_STATE_READY; + } + else if (state == TP_CAL_STATE_READY) + { + } + } +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: tp_cal_create + * + * Description: + * Create a touchpad calibration screen + * + * Input Parameters: + * None + * + * Returned Value: + * None + * + ****************************************************************************/ + +void tp_cal_create(void) +{ + static lv_style_t style_circ; + static lv_style_t style_big_btn; +#if LV_USE_ANIMATION + lv_anim_t a; +#endif + + state = TP_CAL_STATE_INIT; + + prev_scr = lv_scr_act(); + + lv_theme_t *theme = LV_THEME_DEFAULT_INIT(LV_THEME_DEFAULT_COLOR_PRIMARY, + LV_THEME_DEFAULT_COLOR_SECONDARY, + LV_THEME_DEFAULT_FLAG, + LV_THEME_DEFAULT_FONT_SMALL, + LV_THEME_DEFAULT_FONT_NORMAL, + LV_THEME_DEFAULT_FONT_SUBTITLE, + LV_THEME_DEFAULT_FONT_TITLE); + + prev_theme = lv_theme_get_act(); + lv_theme_set_act(theme); + + lv_obj_t *scr = lv_obj_create(NULL, NULL); + lv_obj_set_size(scr, TP_MAX_VALUE, TP_MAX_VALUE); + lv_scr_load(scr); + + /* Create a big transparent button screen to receive clicks */ + + big_btn = lv_btn_create(lv_scr_act(), NULL); + lv_obj_set_size(big_btn, TP_MAX_VALUE, TP_MAX_VALUE); + + lv_style_init(&style_big_btn); + + lv_style_set_bg_opa(&style_big_btn, LV_STATE_DEFAULT | LV_STATE_PRESSED, + LV_OPA_TRANSP); + lv_obj_add_style(big_btn, LV_BTN_PART_MAIN, &style_big_btn); + + lv_obj_set_event_cb(big_btn, btn_click_action); + lv_btn_set_layout(big_btn, LV_LAYOUT_OFF); + + label_main = lv_label_create(lv_scr_act(), NULL); + lv_label_set_text(label_main, "Click the circle in\n" + "upper left-hand corner"); + lv_label_set_align(label_main, LV_LABEL_ALIGN_CENTER); + + lv_obj_set_pos(label_main, (LV_HOR_RES - lv_obj_get_width(label_main)) / 2, + (LV_VER_RES - lv_obj_get_height(label_main)) / 2); + + lv_style_init(&style_circ); + lv_style_set_radius(&style_circ, LV_STATE_DEFAULT, + LV_RADIUS_CIRCLE); + lv_style_set_bg_color(&style_circ, LV_STATE_DEFAULT, + LV_COLOR_BLUE); + circ_area = lv_obj_create(lv_scr_act(), NULL); + lv_obj_set_size(circ_area, CIRCLE_SIZE, CIRCLE_SIZE); + lv_obj_add_style(circ_area, LV_OBJ_PART_MAIN, &style_circ); + lv_obj_set_click(circ_area, false); + +#if LV_USE_ANIMATION + lv_anim_init(&a); + lv_anim_set_var(&a, circ_area); + lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t)lv_obj_set_x); + lv_anim_set_time(&a, 200); + lv_anim_set_values(&a, LV_HOR_RES / 2, 0); + lv_anim_set_delay(&a, 200); + lv_anim_start(&a); + + lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t)lv_obj_set_y); + lv_anim_set_values(&a, LV_VER_RES / 2, 0); + lv_anim_start(&a); +#endif + state = TP_CAL_STATE_WAIT_TOP_LEFT; +} diff --git a/crypto/openssl_mbedtls_wrapper/include/openssl/obj.h b/examples/lvgldemo/tp_cal.h similarity index 79% rename from crypto/openssl_mbedtls_wrapper/include/openssl/obj.h rename to examples/lvgldemo/tp_cal.h index 4351c5113..409f63223 100644 --- a/crypto/openssl_mbedtls_wrapper/include/openssl/obj.h +++ b/examples/lvgldemo/tp_cal.h @@ -1,7 +1,5 @@ /**************************************************************************** - * apps/crypto/openssl_mbedtls_wrapper/include/openssl/obj.h - * - * SPDX-License-Identifier: Apache-2.0 + * apps/examples/lvgldemo/tp_cal.h * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -17,31 +15,39 @@ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. + * ****************************************************************************/ -#ifndef OPENSSL_MBEDTLS_WRAPPER_OBJ_H -#define OPENSSL_MBEDTLS_WRAPPER_OBJ_H +#ifndef __APPS_EXAMPLES_LVGLDEMO_TP_CAL_H +#define __APPS_EXAMPLES_LVGLDEMO_TP_CAL_H /**************************************************************************** - * Included Files + * Public Function Prototypes ****************************************************************************/ -#include <openssl/base.h> -#include <openssl/nid.h> - #ifdef __cplusplus extern "C" { #endif /**************************************************************************** - * Public Function Prototypes + * Name: tp_cal_create + * + * Description: + * Create a touchpad calibration screen + * + * Input Parameters: + * None + * + * Returned Value: + * None + * ****************************************************************************/ -ASN1_OBJECT *OBJ_nid2obj(int nid); +void tp_cal_create(void); #ifdef __cplusplus } #endif -#endif /* OPENSSL_MBEDTLS_WRAPPER_OBJ_H */ +#endif /* __APPS_EXAMPLES_LVGLDEMO_TP_CAL_H */ diff --git a/examples/lvglterm/CMakeLists.txt b/examples/lvglterm/CMakeLists.txt deleted file mode 100644 index c3f84b26e..000000000 --- a/examples/lvglterm/CMakeLists.txt +++ /dev/null @@ -1,42 +0,0 @@ -# ############################################################################## -# apps/examples/lvglterm/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_LVGLTERM) - if(CONFIG_EXAMPLES_LVGLTERM_INPUT_TOUCH) - set(lvglterm_input lvglterm_touch.c) - else() - set(lvglterm_input lvglterm_kbd.c) - endif() - - nuttx_add_application( - NAME - lvglterm - PRIORITY - ${CONFIG_EXAMPLES_LVGLTERM_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_LVGLTERM_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_LVGLTERM} - SRCS - lvglterm.c - ${lvglterm_input}) -endif() diff --git a/examples/lvglterm/Kconfig b/examples/lvglterm/Kconfig deleted file mode 100644 index ca393e845..000000000 --- a/examples/lvglterm/Kconfig +++ /dev/null @@ -1,87 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -menuconfig EXAMPLES_LVGLTERM - tristate "LVGL Terminal" - default n - depends on GRAPHICS_LVGL - ---help--- - Enable LVGL Terminal - -if EXAMPLES_LVGLTERM - -choice - prompt "LVGL Terminal input source" - default EXAMPLES_LVGLTERM_INPUT_TOUCH - ---help--- - Select how the terminal receives keystrokes. Only one input source - is built at a time. The physical-keyboard options differ in the data - the keyboard device delivers on read(), so pick the one that matches - the hardware. - -config EXAMPLES_LVGLTERM_INPUT_TOUCH - bool "On-screen keyboard (touch)" - ---help--- - Input comes from an on-screen LVGL keyboard operated by touch; a - command line is typed and submitted with Enter. This is the default - and matches the original behaviour. - -config EXAMPLES_LVGLTERM_INPUT_KBD_MATRIX - bool "Matrix / upper-half keyboard (keyboard events)" - depends on INPUT_KEYBOARD - ---help--- - Physical keyboard registered through the INPUT_KEYBOARD upper half, - whose read() returns struct keyboard_event_s events (for example the - M5Stack Cardputer matrix keyboard on /dev/kbd0). Fn Up/Down scroll - the terminal. - -config EXAMPLES_LVGLTERM_INPUT_KBD_USB - bool "USB HID keyboard (byte stream)" - depends on USBHOST_HIDKBD - select LIBC_KBDCODEC - ---help--- - USB HID keyboard (for example on /dev/kbda with CONFIG_USBHOST_HIDKBD). - read() returns a byte stream that is decoded with the keyboard codec: - normal keys go to the shell and, when the driver is built with - CONFIG_HIDKBD_ENCODED, the Up/Down cursor keys scroll the terminal. - -endchoice - -config EXAMPLES_LVGLTERM_KBD_DEV - string "Keyboard device path" - default "/dev/kbda" if EXAMPLES_LVGLTERM_INPUT_KBD_USB - default "/dev/kbd0" - depends on EXAMPLES_LVGLTERM_INPUT_KBD_MATRIX || EXAMPLES_LVGLTERM_INPUT_KBD_USB - ---help--- - Keyboard device the terminal reads from. Can also be overridden at - run time by passing the path as the first command-line argument - (useful when more than one keyboard is present). - -choice - prompt "LVGL Terminal font" - default EXAMPLES_LVGLTERM_FONT_UNSCII_16 - ---help--- - Monospaced font used to render the terminal. Use the smaller UNSCII 8 - on low-resolution displays where UNSCII 16 shows too few columns. - -config EXAMPLES_LVGLTERM_FONT_UNSCII_8 - bool "UNSCII 8 (small)" - select LV_FONT_UNSCII_8 - -config EXAMPLES_LVGLTERM_FONT_UNSCII_16 - bool "UNSCII 16" - select LV_FONT_UNSCII_16 - -endchoice - -config EXAMPLES_LVGLTERM_PRIORITY - int "lvglterm task priority" - default 100 - -config EXAMPLES_LVGLTERM_STACKSIZE - int "lvglterm stack size" - default 16384 - -endif # EXAMPLES_LVGLTERM diff --git a/examples/lvglterm/Make.defs b/examples/lvglterm/Make.defs deleted file mode 100644 index 89c84302a..000000000 --- a/examples/lvglterm/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/examples/lvglterm/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_EXAMPLES_LVGLTERM),) -CONFIGURED_APPS += $(APPDIR)/examples/lvglterm -endif diff --git a/examples/lvglterm/Makefile b/examples/lvglterm/Makefile deleted file mode 100644 index 0d4c5d0c2..000000000 --- a/examples/lvglterm/Makefile +++ /dev/null @@ -1,41 +0,0 @@ -############################################################################ -# apps/examples/lvglterm/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -PROGNAME = lvglterm -PRIORITY = $(CONFIG_EXAMPLES_LVGLTERM_PRIORITY) -STACKSIZE = $(CONFIG_EXAMPLES_LVGLTERM_STACKSIZE) -MODULE = $(CONFIG_EXAMPLES_LVGLTERM) - -# LVGL Terminal. lvglterm.c holds the shared core; the input source is -# selected at build time (on-screen keyboard for touch, /dev/kbdN otherwise). - -MAINSRC = lvglterm.c - -ifneq ($(CONFIG_EXAMPLES_LVGLTERM_INPUT_TOUCH),y) -CSRCS = lvglterm_kbd.c -else -CSRCS = lvglterm_touch.c -endif - -include $(APPDIR)/Application.mk diff --git a/examples/lvglterm/lvglterm.c b/examples/lvglterm/lvglterm.c deleted file mode 100644 index f2dcb1f10..000000000 --- a/examples/lvglterm/lvglterm.c +++ /dev/null @@ -1,449 +0,0 @@ -/**************************************************************************** - * apps/examples/lvglterm/lvglterm.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/* Reference: - * "NuttX RTOS for PinePhone: LVGL Terminal for NSH Shell" - * https://lupyuen.github.io/articles/terminal - * - * Code shared by both input variants: it starts the NSH shell with its - * standard streams redirected through pipes, renders the shell output in an - * LVGL text area, and delegates the input source to the selected variant - * (on-screen keyboard in lvglterm_touch.c, physical keyboard in - * lvglterm_kbd.c). - */ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> -#include <sys/boardctl.h> -#include <unistd.h> -#include <stddef.h> -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <time.h> -#include <nuttx/debug.h> -#include <poll.h> -#include <spawn.h> -#include <lvgl/lvgl.h> - -#include "lvglterm.h" - -/* NSH Task requires posix_spawn() */ - -#ifndef CONFIG_LIBC_EXECFUNCS -# error posix_spawn() should be enabled in the configuration -#endif - -/* NSH Redirection requires Pipes */ - -#ifndef CONFIG_DEV_PIPE_SIZE -# error FIFO and Named Pipe Drivers should be enabled in the configuration -#endif - -/* NSH Output requires a Monospaced Font. The size is selectable so that - * low-resolution displays can use the smaller UNSCII 8. - */ - -#if defined(CONFIG_EXAMPLES_LVGLTERM_FONT_UNSCII_8) -# ifndef CONFIG_LV_FONT_UNSCII_8 -# error LVGL Font UNSCII 8 should be enabled in the configuration -# endif -# define LVGLTERM_FONT lv_font_unscii_8 -#else -# ifndef CONFIG_LV_FONT_UNSCII_16 -# error LVGL Font UNSCII 16 should be enabled in the configuration -# endif -# define LVGLTERM_FONT lv_font_unscii_16 -#endif - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* How often to poll for output from NSH Shell (milliseconds) */ - -#define TIMER_PERIOD_MS 20 - -/* Trim the output text area once it grows past this many characters */ - -#define TERM_MAXCHARS 4096 -#define TERM_KEEPCHARS 3072 - -/* NSH Task to be started */ - -#define NSH_TASK "nsh" - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -static int create_widgets(void); -static void timer_callback(lv_timer_t *timer); - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/* Pipe to NSH stdin, written by the selected input variant */ - -int g_nsh_stdin[2]; - -/* LVGL Column Container and NSH Output Text Area (shared with the variant) */ - -lv_obj_t *g_col; -lv_obj_t *g_output; - -/* LVGL Font Style for NSH Input and Output */ - -lv_style_t g_terminal_style; - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/* Pipes for NSH stdout and stderr */ - -static int g_nsh_stdout[2]; -static int g_nsh_stderr[2]; - -/* LVGL Timer for polling NSH Output */ - -static lv_timer_t *g_timer; - -/* Arguments for NSH Task */ - -static char * const g_nsh_argv[] = -{ - NSH_TASK, NULL -}; - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: lvglterm_has_input - * - * Description: - * Return true if the file descriptor has data to be read. - * - ****************************************************************************/ - -bool lvglterm_has_input(int fd) -{ - struct pollfd fdp; - - fdp.fd = fd; - fdp.events = POLLIN; - return poll(&fdp, 1, 0) > 0 && (fdp.revents & POLLIN) != 0; -} - -/**************************************************************************** - * Name: lvglterm_add_output - * - * Description: - * Append text to the NSH output text area, dropping VT100 escape sequences - * and carriage returns, honouring backspace, and trimming the buffer once - * it grows too large. Must run in the LVGL thread. - * - ****************************************************************************/ - -void lvglterm_add_output(FAR const char *buf, int len) -{ - char clean[64]; - int ci = 0; - int i; - - for (i = 0; i < len; i++) - { - char c = buf[i]; - - if (c == 0x1b) /* ESC: skip the escape sequence */ - { - i++; - if (i < len && buf[i] == '[') - { - for (i++; i < len; i++) - { - if ((buf[i] >= 'A' && buf[i] <= 'Z') || - (buf[i] >= 'a' && buf[i] <= 'z')) - { - break; - } - } - } - - continue; - } - - if (c == '\r') /* Drop carriage return */ - { - continue; - } - - if (c == 0x08 || c == 0x7f) /* Backspace/DEL: erase last character */ - { - if (ci > 0) - { - clean[ci] = '\0'; - lv_textarea_add_text(g_output, clean); - ci = 0; - } - - lv_textarea_delete_char(g_output); - continue; - } - - if (c == '\n' || c == '\t' || (c >= 0x20 && c < 0x7f)) - { - clean[ci++] = c; - if (ci >= (int)sizeof(clean) - 1) - { - clean[ci] = '\0'; - lv_textarea_add_text(g_output, clean); - ci = 0; - } - } - } - - if (ci > 0) - { - clean[ci] = '\0'; - lv_textarea_add_text(g_output, clean); - } - - /* Trim the text area if it has grown too large */ - - if ((int)strlen(lv_textarea_get_text(g_output)) > TERM_MAXCHARS) - { - FAR const char *txt = lv_textarea_get_text(g_output); - int total = strlen(txt); - lv_textarea_set_text(g_output, txt + (total - TERM_KEEPCHARS)); - lv_textarea_set_cursor_pos(g_output, LV_TEXTAREA_CURSOR_LAST); - } -} - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: create_widgets - * - * Description: - * Create the shared LVGL widgets: a column container and the NSH output - * text area. The input source is added by the selected variant. - * - ****************************************************************************/ - -static int create_widgets(void) -{ - /* Set the Font Style for NSH Input and Output to a Monospaced Font */ - - lv_style_init(&g_terminal_style); - lv_style_set_text_font(&g_terminal_style, &LVGLTERM_FONT); - - /* Create an LVGL Container with Column Flex Direction */ - - g_col = lv_obj_create(lv_scr_act()); - DEBUGASSERT(g_col != NULL); - lv_obj_set_size(g_col, LV_PCT(100), LV_PCT(100)); - lv_obj_set_flex_flow(g_col, LV_FLEX_FLOW_COLUMN); - lv_obj_set_style_pad_all(g_col, 0, 0); - - /* Create an LVGL Text Area Widget for NSH Output */ - - g_output = lv_textarea_create(g_col); - DEBUGASSERT(g_output != NULL); - lv_obj_add_style(g_output, &g_terminal_style, 0); - lv_obj_set_width(g_output, LV_PCT(100)); - lv_obj_set_flex_grow(g_output, 1); - - return OK; -} - -/**************************************************************************** - * Name: create_terminal - * - * Description: - * Start the NSH shell with its streams redirected to pipes, create the - * shared widgets and the output-polling timer, and set up the input - * variant. - * - ****************************************************************************/ - -static int create_terminal(int argc, FAR char *argv[]) -{ - int ret; - pid_t pid; - - /* Create the pipes for NSH Shell: stdin, stdout and stderr */ - - if (pipe(g_nsh_stdin) < 0 || pipe(g_nsh_stdout) < 0 || - pipe(g_nsh_stderr) < 0) - { - fprintf(stderr, "pipe failed: %d\n", errno); - return ERROR; - } - - /* Close default stdin, stdout and stderr and assign the new pipes */ - - close(0); - close(1); - close(2); - - dup2(g_nsh_stdin[READ_PIPE], 0); - dup2(g_nsh_stdout[WRITE_PIPE], 1); - dup2(g_nsh_stderr[WRITE_PIPE], 2); - - /* Start the NSH Shell and inherit stdin, stdout and stderr */ - - ret = posix_spawn(&pid, NSH_TASK, NULL, NULL, g_nsh_argv, NULL); - if (ret < 0) - { - int errcode = errno; - fprintf(stderr, "posix_spawn failed: %d\n", errcode); - return -errcode; - } - - /* Create an LVGL Timer to poll for output from NSH Shell */ - - g_timer = lv_timer_create(timer_callback, TIMER_PERIOD_MS, NULL); - DEBUGASSERT(g_timer != NULL); - - /* Create the shared widgets and the input source for the variant */ - - ret = create_widgets(); - if (ret < 0) - { - return ret; - } - - lvglterm_input_create(argc, argv); - return OK; -} - -/**************************************************************************** - * Name: timer_callback - * - * Description: - * Poll NSH stdout and stderr for output and render it, then let the input - * variant perform its periodic work. Runs in the LVGL thread. - * - ****************************************************************************/ - -static void timer_callback(lv_timer_t *timer) -{ - static char buf[64]; - int ret; - - /* Drain the input variant first (local echo, scroll) so that what the user - * typed is rendered before the resulting shell output. - */ - - lvglterm_input_poll(); - - if (lvglterm_has_input(g_nsh_stdout[READ_PIPE])) - { - ret = read(g_nsh_stdout[READ_PIPE], buf, sizeof(buf)); - if (ret > 0) - { - lvglterm_add_output(buf, ret); - } - } - - if (lvglterm_has_input(g_nsh_stderr[READ_PIPE])) - { - ret = read(g_nsh_stderr[READ_PIPE], buf, sizeof(buf)); - if (ret > 0) - { - lvglterm_add_output(buf, ret); - } - } -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: main or lvglterm_main - * - * Description: - * Start an LVGL Terminal that runs interactive commands with NSH. - * NSH output is rendered in an LVGL text area; the input comes from an - * on-screen keyboard (touch) or a physical keyboard, selected at build - * time. - * - ****************************************************************************/ - -int main(int argc, FAR char *argv[]) -{ - lv_nuttx_dsc_t info; - lv_nuttx_result_t result; - int ret; - -#ifdef CONFIG_LV_USE_NUTTX_LIBUV - uv_loop_t ui_loop; -#endif - -#ifdef CONFIG_BOARDCTL_FINALINIT - boardctl(BOARDIOC_FINALINIT, 0); -#endif - - lv_init(); - lv_nuttx_dsc_init(&info); - -#ifdef CONFIG_LV_USE_NUTTX_LCD - info.fb_path = "/dev/lcd0"; -#endif - - lv_nuttx_init(&info, &result); - if (result.disp == NULL) - { - LV_LOG_ERROR("lv_nuttx_init failure!"); - return 1; - } - - ret = create_terminal(argc, argv); - if (ret < 0) - { - return EXIT_FAILURE; - } - -#ifdef CONFIG_LV_USE_NUTTX_LIBUV - lv_nuttx_uv_loop(&ui_loop, &result); -#else - while (1) - { - uint32_t idle; - idle = lv_timer_handler(); - idle = idle ? idle : 1; - usleep(idle * 1000); - } -#endif - - return EXIT_SUCCESS; -} diff --git a/examples/lvglterm/lvglterm.h b/examples/lvglterm/lvglterm.h deleted file mode 100644 index 627919cdd..000000000 --- a/examples/lvglterm/lvglterm.h +++ /dev/null @@ -1,75 +0,0 @@ -/**************************************************************************** - * apps/examples/lvglterm/lvglterm.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __APPS_EXAMPLES_LVGLTERM_LVGLTERM_H -#define __APPS_EXAMPLES_LVGLTERM_LVGLTERM_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> -#include <stdbool.h> -#include <lvgl/lvgl.h> - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* Read and Write ends of the NSH pipes */ - -#define READ_PIPE 0 -#define WRITE_PIPE 1 - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/* Shared state owned by the core (lvglterm.c). The input variant writes the - * shell input to g_nsh_stdin, adds its widgets under g_col (styled with - * g_terminal_style) and may render into g_output. - */ - -extern int g_nsh_stdin[2]; /* Input variant -> NSH stdin */ -extern lv_obj_t *g_col; /* Column container (widget parent) */ -extern lv_obj_t *g_output; /* NSH output text area */ -extern lv_style_t g_terminal_style; /* Monospaced font style */ - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/* Shared helpers provided by the core */ - -bool lvglterm_has_input(int fd); -void lvglterm_add_output(FAR const char *buf, int len); - -/* Provided by the selected input variant (lvglterm_touch.c or - * lvglterm_kbd.c). lvglterm_input_create() sets up the input source under - * g_col and wires it to g_nsh_stdin. lvglterm_input_poll() runs on every - * LVGL timer tick (LVGL thread) for periodic work; it may be a no-op. - */ - -void lvglterm_input_create(int argc, FAR char *argv[]); -void lvglterm_input_poll(void); - -#endif /* __APPS_EXAMPLES_LVGLTERM_LVGLTERM_H */ diff --git a/examples/lvglterm/lvglterm_kbd.c b/examples/lvglterm/lvglterm_kbd.c deleted file mode 100644 index 08ae83612..000000000 --- a/examples/lvglterm/lvglterm_kbd.c +++ /dev/null @@ -1,260 +0,0 @@ -/**************************************************************************** - * apps/examples/lvglterm/lvglterm_kbd.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/* Physical-keyboard input variant of the LVGL terminal: the keyboard device - * is polled (non-blocking) from the LVGL thread and key presses are streamed - * to NSH; the shell output fills the whole screen. Works on any board with - * a keyboard driver; the device defaults to CONFIG_EXAMPLES_LVGLTERM_KBD_DEV - * and can be overridden by the first command-line argument. - * - * Two device flavours are supported, selected at build time: - * - * - Upper-half keyboards (INPUT_KEYBOARD, e.g. the M5Stack Cardputer - * matrix on /dev/kbd0) deliver struct keyboard_event_s events; the Fn - * Up/Down keys are handled locally as scroll requests. - * - USB HID keyboards (EXAMPLES_LVGLTERM_INPUT_KBD_USB, e.g. /dev/kbda) - * deliver a byte stream decoded with the NuttX keyboard codec: normal - * keys are forwarded to the shell and, when the driver is built with - * CONFIG_HIDKBD_ENCODED, the Up/Down cursor keys scroll the terminal. - */ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> -#include <sys/types.h> -#include <stdint.h> -#include <string.h> -#include <unistd.h> -#include <fcntl.h> -#include <errno.h> -#include <debug.h> - -#ifdef CONFIG_EXAMPLES_LVGLTERM_INPUT_KBD_MATRIX -# include <nuttx/input/keyboard.h> -#endif - -#ifdef CONFIG_EXAMPLES_LVGLTERM_INPUT_KBD_USB -# include <nuttx/streams.h> -# include <nuttx/input/kbd_codec.h> -#endif - -#include <lvgl/lvgl.h> - -#include "lvglterm.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* Out-of-band key codes for the Fn + navigation cluster (cursor keys), - * reported by keyboard drivers that follow this convention (for example the - * M5Stack Cardputer). Up/Down scroll the terminal instead of going to the - * shell; drivers that do not emit these codes keep normal behaviour. - */ - -#define KEY_UP 0x80 -#define KEY_DOWN 0x81 -#define KEY_LEFT 0x82 -#define KEY_RIGHT 0x83 - -#define SCROLL_STEP 24 /* Pixels scrolled per Up/Down keypress */ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static int g_kfd = -1; /* Keyboard device fd (opened O_NONBLOCK) */ -static FAR const char *g_kbddev; /* Keyboard device path (/dev/kbdN) */ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: feed_char - * - * Description: - * Forward one character to NSH stdin and, for printable characters and - * newline, echo it on screen. Control keys such as backspace are echoed - * by the shell's own line editor (via its stdout) to avoid handling them - * twice. Carriage return is normalised to newline. Runs in the LVGL - * thread, so it may touch the LVGL widgets directly. - * - ****************************************************************************/ - -static void feed_char(char ch) -{ - if (ch == '\r') - { - ch = '\n'; - } - - write(g_nsh_stdin[WRITE_PIPE], &ch, 1); - - if (ch == '\n' || ((uint8_t)ch >= 0x20 && (uint8_t)ch < 0x7f)) - { - lvglterm_add_output(&ch, 1); - } -} - -/**************************************************************************** - * Name: scroll_terminal - * - * Description: - * Scroll the output text area up (older output) or down by one step. Runs - * in the LVGL thread. - * - ****************************************************************************/ - -static void scroll_terminal(bool up) -{ - int32_t dy = up ? SCROLL_STEP : -SCROLL_STEP; - - lv_obj_scroll_by(g_output, 0, dy, LV_ANIM_OFF); -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: lvglterm_input_create - * - * Description: - * Resolve the keyboard device (first command-line argument, else the - * configured default) and open it non-blocking so that it can be polled - * from the LVGL thread. - * - ****************************************************************************/ - -void lvglterm_input_create(int argc, FAR char *argv[]) -{ - g_kbddev = (argc > 1) ? argv[1] : CONFIG_EXAMPLES_LVGLTERM_KBD_DEV; - - g_kfd = open(g_kbddev, O_RDONLY | O_NONBLOCK); - if (g_kfd < 0) - { - gerr("ERROR: open %s failed: %d\n", g_kbddev, errno); - } -} - -/**************************************************************************** - * Name: lvglterm_input_poll - * - * Description: - * Drain any pending key presses from the keyboard device and forward them - * to NSH (echoing what is typed on screen). Runs in the LVGL thread from - * the terminal's periodic timer, so the read must not block. - * - ****************************************************************************/ - -void lvglterm_input_poll(void) -{ - if (g_kfd < 0) - { - return; - } - -#ifdef CONFIG_EXAMPLES_LVGLTERM_INPUT_KBD_USB - /* USB HID keyboard: read() returns a byte stream that is decoded with the - * keyboard codec. Normal keys are fed to the shell; the Up/Down cursor - * keys (only emitted when the driver is built with CONFIG_HIDKBD_ENCODED) - * scroll the terminal. On a plain-ASCII stream every byte simply decodes - * to a normal key press, so this also works without encoding. - */ - - struct lib_meminstream_s stream; - struct kbd_getstate_s state; - char buf[64]; - ssize_t nread; - uint8_t ch; - int ret; - - nread = read(g_kfd, buf, sizeof(buf)); - if (nread <= 0) - { - return; - } - - memset(&state, 0, sizeof(state)); - lib_meminstream(&stream, buf, nread); - - for (; ; ) - { - ret = kbd_decode((FAR struct lib_instream_s *)&stream, &state, &ch); - if (ret == KBD_ERROR) - { - break; - } - - if (ret == KBD_PRESS) - { - feed_char((char)ch); - } - else if (ret == KBD_SPECPRESS) - { - if (ch == KEYCODE_UP) - { - scroll_terminal(true); - } - else if (ch == KEYCODE_DOWN) - { - scroll_terminal(false); - } - } - } -#else - /* Upper-half keyboard: read() returns keyboard_event_s events */ - - struct keyboard_event_s evt; - - while (read(g_kfd, &evt, sizeof(evt)) == (ssize_t)sizeof(evt)) - { - if (evt.type != KEYBOARD_PRESS) - { - continue; - } - - /* Fn navigation keys are handled locally: Up/Down scroll the terminal; - * Left/Right are reserved and simply swallowed for now. - */ - - if (evt.code >= KEY_UP && evt.code <= KEY_RIGHT) - { - if (evt.code == KEY_UP) - { - scroll_terminal(true); - } - else if (evt.code == KEY_DOWN) - { - scroll_terminal(false); - } - - continue; - } - - feed_char((char)evt.code); - } -#endif -} diff --git a/examples/lvglterm/lvglterm_touch.c b/examples/lvglterm/lvglterm_touch.c deleted file mode 100644 index 4285c97e6..000000000 --- a/examples/lvglterm/lvglterm_touch.c +++ /dev/null @@ -1,164 +0,0 @@ -/**************************************************************************** - * apps/examples/lvglterm/lvglterm_touch.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/* Touch input variant of the LVGL terminal: an on-screen LVGL keyboard feeds - * an input text area; pressing Enter sends the line to NSH stdin. This is - * the original PinePhone behaviour and suits touchscreen boards. - */ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> -#include <unistd.h> -#include <string.h> -#include <nuttx/debug.h> -#include <lvgl/lvgl.h> - -#include "lvglterm.h" - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -static void input_callback(lv_event_t *e); - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/* LVGL Text Area for NSH Input and the on-screen Keyboard Widget */ - -static lv_obj_t *g_input; -static lv_obj_t *g_kb; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: input_callback - * - * Description: - * Callback for the NSH input text area. When the on-screen keyboard Enter - * key is pressed, send the input command to NSH stdin. - * - ****************************************************************************/ - -static void input_callback(lv_event_t *e) -{ - int ret; - const lv_event_code_t code = lv_event_get_code(e); - - if (code == LV_EVENT_VALUE_CHANGED) - { - const uint16_t id = lv_keyboard_get_selected_button(g_kb); - const char *key = lv_keyboard_get_button_text(g_kb, id); - - if (key == NULL) - { - return; - } - - /* If the key pressed is Enter, send the command to NSH stdin */ - - if (key[0] == 0xef && key[1] == 0xa2 && key[2] == 0xa2) - { - const char *cmd; - int len; - - DEBUGASSERT(g_input != NULL); - cmd = lv_textarea_get_text(g_input); - if (cmd == NULL || cmd[0] == 0) - { - return; - } - - /* Echo the command on the output so the prompt line reads - * "nsh> <command>", then send it to the shell. - */ - - len = strlen(cmd); - lvglterm_add_output(cmd, len); - if (cmd[len - 1] != '\n') - { - lvglterm_add_output("\n", 1); - } - - DEBUGASSERT(g_nsh_stdin[WRITE_PIPE] != 0); - ret = write(g_nsh_stdin[WRITE_PIPE], cmd, len); - DEBUGASSERT(ret == len); - - lv_textarea_set_text(g_input, ""); - } - } -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: lvglterm_input_create - * - * Description: - * Create the on-screen keyboard and input text area under the shared - * column container. - * - ****************************************************************************/ - -void lvglterm_input_create(int argc, FAR char *argv[]) -{ - UNUSED(argc); - UNUSED(argv); - - /* Create an LVGL Text Area Widget for NSH Input */ - - g_input = lv_textarea_create(g_col); - DEBUGASSERT(g_input != NULL); - lv_obj_add_style(g_input, &g_terminal_style, 0); - lv_obj_set_size(g_input, LV_PCT(100), LV_SIZE_CONTENT); - - /* Create an LVGL Keyboard Widget */ - - g_kb = lv_keyboard_create(g_col); - DEBUGASSERT(g_kb != NULL); - lv_obj_set_style_pad_all(g_kb, 0, 0); - - /* Wire the keyboard to the input text area */ - - lv_obj_add_event_cb(g_input, input_callback, LV_EVENT_ALL, NULL); - lv_keyboard_set_textarea(g_kb, g_input); -} - -/**************************************************************************** - * Name: lvglterm_input_poll - * - * Description: - * No periodic work is needed for the touch variant. - * - ****************************************************************************/ - -void lvglterm_input_poll(void) -{ -} diff --git a/examples/lws_echo/CMakeLists.txt b/examples/lws_echo/CMakeLists.txt deleted file mode 100644 index d959489f6..000000000 --- a/examples/lws_echo/CMakeLists.txt +++ /dev/null @@ -1,37 +0,0 @@ -# ############################################################################## -# apps/examples/lws_echo/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_LWS_ECHO) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_LWS_ECHO_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_LWS_ECHO_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_LWS_ECHO_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_LWS_ECHO} - DEPENDS - libwebsockets - SRCS - lws_echo_main.c) -endif() diff --git a/examples/lws_echo/Kconfig b/examples/lws_echo/Kconfig deleted file mode 100644 index b58daa24e..000000000 --- a/examples/lws_echo/Kconfig +++ /dev/null @@ -1,31 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config EXAMPLES_LWS_ECHO - tristate "libwebsockets WebSocket echo server" - default n - depends on NETUTILS_LIBWEBSOCKETS && NETUTILS_LIBWEBSOCKETS_SERVER - ---help--- - Simple WebSocket echo server using libwebsockets without TLS. - -if EXAMPLES_LWS_ECHO - -config EXAMPLES_LWS_ECHO_PROGNAME - string "Program name" - default "lws_echo" - -config EXAMPLES_LWS_ECHO_PRIORITY - int "Task priority" - default 100 - -config EXAMPLES_LWS_ECHO_STACKSIZE - int "Stack size" - default 16384 - -config EXAMPLES_LWS_ECHO_PORT - int "WebSocket server TCP port" - default 9000 - -endif diff --git a/examples/lws_echo/Make.defs b/examples/lws_echo/Make.defs deleted file mode 100644 index b0a46ccd5..000000000 --- a/examples/lws_echo/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/examples/lws_echo/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_EXAMPLES_LWS_ECHO),) -CONFIGURED_APPS += $(APPDIR)/examples/lws_echo -endif diff --git a/examples/lws_echo/Makefile b/examples/lws_echo/Makefile deleted file mode 100644 index 48da93216..000000000 --- a/examples/lws_echo/Makefile +++ /dev/null @@ -1,32 +0,0 @@ -############################################################################ -# apps/examples/lws_echo/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -PROGNAME = $(CONFIG_EXAMPLES_LWS_ECHO_PROGNAME) -PRIORITY = $(CONFIG_EXAMPLES_LWS_ECHO_PRIORITY) -STACKSIZE = $(CONFIG_EXAMPLES_LWS_ECHO_STACKSIZE) -MODULE = $(CONFIG_EXAMPLES_LWS_ECHO) - -MAINSRC = lws_echo_main.c - -include $(APPDIR)/Application.mk diff --git a/examples/lws_echo/lws_echo_main.c b/examples/lws_echo/lws_echo_main.c deleted file mode 100644 index 48bf644f0..000000000 --- a/examples/lws_echo/lws_echo_main.c +++ /dev/null @@ -1,203 +0,0 @@ -/**************************************************************************** - * apps/examples/lws_echo/lws_echo_main.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <libwebsockets.h> -#include <stdio.h> -#include <string.h> - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#ifndef CONFIG_EXAMPLES_LWS_ECHO_PORT -# define CONFIG_EXAMPLES_LWS_ECHO_PORT 9000 -#endif - -#define LWS_ECHO_IOBUF_SIZE 256 - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -struct lws_echo_session_s -{ - unsigned char buf[LWS_PRE + LWS_ECHO_IOBUF_SIZE]; - size_t len; - int pending; -}; - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -static int callback_echo(struct lws *wsi, - enum lws_callback_reasons reason, - void *user, void *in, size_t len); - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static const struct lws_protocols g_protocols[] = -{ - { - "echo-protocol", - callback_echo, - sizeof(struct lws_echo_session_s), - LWS_ECHO_IOBUF_SIZE, - 0, NULL, 0 - }, - LWS_PROTOCOL_LIST_TERM -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: callback_echo - * - * Description: - * libwebsockets protocol callback for the echo server. - * - * Input Parameters: - * wsi - Websocket instance. - * reason - Callback reason. - * user - Per-session data. - * in - Received data. - * len - Length of received data. - * - * Returned Value: - * Zero on success; non-zero on failure. - * - ****************************************************************************/ - -static int callback_echo(struct lws *wsi, - enum lws_callback_reasons reason, - void *user, void *in, size_t len) -{ - struct lws_echo_session_s *pss = (struct lws_echo_session_s *)user; - - switch (reason) - { - case LWS_CALLBACK_ESTABLISHED: - printf("lws_echo: client connected\n"); - pss->pending = 0; - break; - - case LWS_CALLBACK_RECEIVE: - if (len > sizeof(pss->buf) - LWS_PRE) - { - len = sizeof(pss->buf) - LWS_PRE; - } - - memcpy(&pss->buf[LWS_PRE], in, len); - pss->len = len; - pss->pending = 1; - lws_callback_on_writable(wsi); - break; - - case LWS_CALLBACK_SERVER_WRITEABLE: - if (!pss->pending) - { - break; - } - - lws_write(wsi, &pss->buf[LWS_PRE], pss->len, LWS_WRITE_TEXT); - pss->pending = 0; - break; - - case LWS_CALLBACK_CLOSED: - printf("lws_echo: client disconnected\n"); - break; - - default: - break; - } - - return 0; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: main - * - * Description: - * Start a libwebsockets WebSocket echo server. - * - * Input Parameters: - * Standard argc and argv. - * - * Returned Value: - * Zero on success; non-zero on failure. - * - ****************************************************************************/ - -int main(int argc, FAR char *argv[]) -{ - struct lws_context_creation_info info; - struct lws_context *context; - int n; - - lws_set_log_level(LLL_USER | LLL_ERR | LLL_WARN | LLL_NOTICE, NULL); - - printf("lws_echo: starting WebSocket echo server on port %d\n", - CONFIG_EXAMPLES_LWS_ECHO_PORT); - printf("lws_echo: connect with ws://<device-ip>:%d " - "(subprotocol echo-protocol)\n", - CONFIG_EXAMPLES_LWS_ECHO_PORT); - - memset(&info, 0, sizeof(info)); - info.port = CONFIG_EXAMPLES_LWS_ECHO_PORT; - info.protocols = g_protocols; - info.vhost_name = "localhost"; - info.options = 0; - - context = lws_create_context(&info); - if (context == NULL) - { - printf("lws_echo: ERROR creating context\n"); - return 1; - } - - printf("lws_echo: server running\n"); - - n = 0; - while (n >= 0) - { - n = lws_service(context, 100); - } - - lws_context_destroy(context); - printf("lws_echo: server stopped\n"); - - return 0; -} diff --git a/examples/max31855/CMakeLists.txt b/examples/max31855/CMakeLists.txt deleted file mode 100644 index 68a8014e1..000000000 --- a/examples/max31855/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# ############################################################################## -# apps/examples/max31855/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_MAX31855) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_MAX31855_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_MAX31855_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_MAX31855_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_MAX31855} - SRCS - max31855_main.c) -endif() diff --git a/examples/max31855/Make.defs b/examples/max31855/Make.defs index d114228b1..b707cabf4 100644 --- a/examples/max31855/Make.defs +++ b/examples/max31855/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/max31855/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/max31855/Makefile b/examples/max31855/Makefile index 04951afa1..592c03d0b 100644 --- a/examples/max31855/Makefile +++ b/examples/max31855/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/max31855/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/max31855/max31855_main.c b/examples/max31855/max31855_main.c index fb26fee2c..97e5af843 100644 --- a/examples/max31855/max31855_main.c +++ b/examples/max31855/max31855_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/max31855/max31855_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -31,7 +29,6 @@ #include <stdlib.h> #include <fcntl.h> #include <errno.h> -#include <unistd.h> /**************************************************************************** * Public Functions diff --git a/examples/mcuboot/CMakeLists.txt b/examples/mcuboot/CMakeLists.txt deleted file mode 100644 index 7c6b7189d..000000000 --- a/examples/mcuboot/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -# ############################################################################## -# apps/examples/mcuboot/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -nuttx_add_subdirectory() - -nuttx_generate_kconfig(MENUDESC "MCUboot Examples") diff --git a/examples/mcuboot/Make.defs b/examples/mcuboot/Make.defs index f8cc9ed89..fea6548f9 100644 --- a/examples/mcuboot/Make.defs +++ b/examples/mcuboot/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/mcuboot/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/mcuboot/Makefile b/examples/mcuboot/Makefile index 5687f531c..3bd6703c2 100644 --- a/examples/mcuboot/Makefile +++ b/examples/mcuboot/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/mcuboot/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/mcuboot/slot_confirm/CMakeLists.txt b/examples/mcuboot/slot_confirm/CMakeLists.txt deleted file mode 100644 index ec4c24abd..000000000 --- a/examples/mcuboot/slot_confirm/CMakeLists.txt +++ /dev/null @@ -1,28 +0,0 @@ -# ############################################################################## -# apps/examples/mcuboot/slot_confirm/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_MCUBOOT_SLOT_CONFIRM) - nuttx_add_application( - NAME mcuboot_confirm2 - SRCS ${CMAKE_CURRENT_LIST_DIR}/mcuboot_confirm_main.c - DEPENDS mcuboot) -endif() diff --git a/examples/mcuboot/slot_confirm/Kconfig b/examples/mcuboot/slot_confirm/Kconfig deleted file mode 100644 index 03d16831a..000000000 --- a/examples/mcuboot/slot_confirm/Kconfig +++ /dev/null @@ -1,14 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config EXAMPLES_MCUBOOT_SLOT_CONFIRM - tristate "MCUboot slot confirm example" - default n - select BOOT_MCUBOOT - ---help--- - Example application for confirming a newly installed application - application firmware image using MCUboot public APIs. - This application should be used as the OTA update package of the - EXAMPLES_MCUBOOT_UPDATE_AGENT example. diff --git a/examples/mcuboot/slot_confirm/Make.defs b/examples/mcuboot/slot_confirm/Make.defs deleted file mode 100644 index 5050148d1..000000000 --- a/examples/mcuboot/slot_confirm/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/examples/mcuboot/slot_confirm/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_EXAMPLES_MCUBOOT_SLOT_CONFIRM),) -CONFIGURED_APPS += $(APPDIR)/examples/mcuboot/slot_confirm -endif diff --git a/examples/mcuboot/slot_confirm/Makefile b/examples/mcuboot/slot_confirm/Makefile deleted file mode 100644 index dc4a93279..000000000 --- a/examples/mcuboot/slot_confirm/Makefile +++ /dev/null @@ -1,31 +0,0 @@ -############################################################################ -# apps/examples/mcuboot/slot_confirm/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -MAINSRC += mcuboot_confirm_main.c - -PROGNAME += mcuboot_confirm -PRIORITY += SCHED_PRIORITY_DEFAULT -STACKSIZE += $(CONFIG_DEFAULT_TASK_STACKSIZE) - -include $(APPDIR)/Application.mk diff --git a/examples/mcuboot/swap_test/CMakeLists.txt b/examples/mcuboot/swap_test/CMakeLists.txt deleted file mode 100644 index 0de3e51b7..000000000 --- a/examples/mcuboot/swap_test/CMakeLists.txt +++ /dev/null @@ -1,38 +0,0 @@ -# ############################################################################## -# apps/examples/mcuboot/swap_test/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_MCUBOOT_SWAP_TEST) - nuttx_add_application( - NAME mcuboot_confirm - SRCS ${CMAKE_CURRENT_LIST_DIR}/confirm_main.c - DEPENDS mcuboot) - - nuttx_add_application( - NAME mcuboot_set_img - SRCS ${CMAKE_CURRENT_LIST_DIR}/set_img_main.c - DEPENDS mcuboot) - - nuttx_add_application( - NAME mcuboot_version - SRCS ${CMAKE_CURRENT_LIST_DIR}/version_main.c - DEPENDS mcuboot) -endif() diff --git a/examples/mcuboot/swap_test/Make.defs b/examples/mcuboot/swap_test/Make.defs index e503eab8a..e4d015532 100644 --- a/examples/mcuboot/swap_test/Make.defs +++ b/examples/mcuboot/swap_test/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/mcuboot/swap_test/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/mcuboot/swap_test/Makefile b/examples/mcuboot/swap_test/Makefile index c409490a8..ad91a8804 100644 --- a/examples/mcuboot/swap_test/Makefile +++ b/examples/mcuboot/swap_test/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/mcuboot/swap_test/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/mcuboot/swap_test/README.md b/examples/mcuboot/swap_test/README.md new file mode 100644 index 000000000..6a43a069a --- /dev/null +++ b/examples/mcuboot/swap_test/README.md @@ -0,0 +1,138 @@ +# Examples / MCUboot / `swap_test` + +## Description + +MCUboot Swap Image is an application to demostrate firmware upgrade using +internal flash memory. It simulate MCUboot API steps to switch between two +valid images. + +This application add 3 Builtin Apps to NuttX NSH: version, set_img and confirm. +After application is build and `nuttx.bin` be generated, the binary must be +signed. Consult your board README file to get instructions how to do it. + +## How to build and flash + +First step is build your board configuraton using `mcuboot-loader` as target. +That create the bootloader itself. The `nuttx.bin` must be flash as usual. + +After that, clean up environment and set `mcuboot-swap-test` as target. The +build output will generate the `nuttx.bin` file. You should execute the MCUboot +script called `imgtool.py` and sign the binary file two times. + +The first time you will use `--version 1.0.0` and `signedv1.bin` as output file. +Then, the second sign you need change to `--version 2.0.0` and `signedv2.bin` +as output file. + +The `signedv1.bin` file must be at MCUboot Slot-0 partition and `signedv2.bin` +at Slot-1. + +More instructions about how to sign and flash can be found at board README file. + +## Running swap image test + +Open you terminal and reboot your board. You can see a similar output as below. +You can check builtin apps using command `?`. + +```bash +*** Booting MCUboot build 7c890f4b075aed73e4c825ccf875b2fb9ebf2ded *** +NuttShell (NSH) NuttX-10.2.0 +nsh> ? +help usage: help [-v] [<cmd>] + + . cd echo hexdump mv rmdir true xd + [ cp exec kill printf set truncate + ? cmp exit ls ps sleep uname + basename dirname false mkdir pwd source umount + break dd free mkrd reboot test unset + cat df help mount rm time usleep + +Builtin Apps: + mcuboot_set_img mcuboot_confirm sh + mcuboot_version ramtest nsh +nsh> +``` + +First step (check version): + +```bash +nsh> mcuboot_version +Image version 1.0.0.0 +nsh> +``` + +Second step (mark image as good because it is running). This is an optional +step that must be executed if you ran `imgtool.py` without optional parameter +`--confirm`. + +```bash +nsh> mcuboot_confirm +Application Image successfully confirmed! +nsh> +``` + +Third step (let's reboot and see whats happen): + +```bash +nsh> reboot +*** Booting MCUboot build 7c890f4b075aed73e4c825ccf875b2fb9ebf2ded *** +NuttShell (NSH) NuttX-10.2.0 +nsh> mcuboot_version +Image version 1.0.0.0 +nsh> +``` + +Fourth step (let's switch image): + +```bash +nsh> mcuboot_set_img +Requested update for next boot. Restarting... +*** Booting MCUboot build 7c890f4b075aed73e4c825ccf875b2fb9ebf2ded *** +NuttShell (NSH) NuttX-10.2.0 +nsh> mcuboot_version +Image version 2.0.0.0 +nsh> +``` + +Now, we switched from image version 1.0.0 to image 2.0.0. However, we intentionaly +will not run `mcuboot_confirm` app. + +```bash +nsh> reboot +*** Booting MCUboot build 7c890f4b075aed73e4c825ccf875b2fb9ebf2ded *** +NuttShell (NSH) NuttX-10.2.0 +nsh> mcuboot_version +Image version 1.0.0.0 +nsh> +``` + +This means that if for any reason App reboot, have a malfunctioning or not boot, +MCUboot will switch back to old `good` image! Remember that we executed +`mcuboot_confirm` at step two. + +Fifth step (switch to image version 2 and mark as permanent): + +```bash +nsh> mcuboot_set_img +Requested update for next boot. Restarting... +*** Booting MCUboot build 7c890f4b075aed73e4c825ccf875b2fb9ebf2ded *** +NuttShell (NSH) NuttX-10.2.0 +nsh> mcuboot_confirm +Application Image successfully confirmed! +nsh> mcuboot_version +Image version 2.0.0.0 +nsh> +``` + +Sixth step (Reboot and confirm V2 image): + +```bash +nsh> reboot +*** Booting MCUboot build 7c890f4b075aed73e4c825ccf875b2fb9ebf2ded *** +NuttShell (NSH) NuttX-10.2.0 +nsh> mcuboot_version +Image version 2.0.0.0 +nsh> +``` + +Conclusion, once we boot a newer image and confirm it MCUboot always run that +image, unless you instruct it to swap again! diff --git a/examples/mcuboot/swap_test/confirm_main.c b/examples/mcuboot/swap_test/confirm_main.c index 8f1980455..c8a29c179 100644 --- a/examples/mcuboot/swap_test/confirm_main.c +++ b/examples/mcuboot/swap_test/confirm_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/mcuboot/swap_test/confirm_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/mcuboot/swap_test/set_img_main.c b/examples/mcuboot/swap_test/set_img_main.c index b8196094a..7c6d7c20f 100644 --- a/examples/mcuboot/swap_test/set_img_main.c +++ b/examples/mcuboot/swap_test/set_img_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/mcuboot/swap_test/set_img_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -28,8 +26,6 @@ #include <stdio.h> #include <stdlib.h> -#include <unistd.h> - #include <sys/boardctl.h> #include <bootutil/bootutil_public.h> diff --git a/examples/mcuboot/swap_test/version_main.c b/examples/mcuboot/swap_test/version_main.c index b606c628c..932112493 100644 --- a/examples/mcuboot/swap_test/version_main.c +++ b/examples/mcuboot/swap_test/version_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/mcuboot/swap_test/version_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -120,9 +118,10 @@ int main(int argc, FAR char *argv[]) return rc; } - printf("Image version %d.%d.%d.%" PRId32 "\n", - raw_header.version.major, raw_header.version.minor, - raw_header.version.revision, raw_header.version.build_num); + printf("Image version %d.%d.%d.%ld\n", raw_header.version.major, + raw_header.version.minor, + raw_header.version.revision, + raw_header.version.build_num); return 0; } diff --git a/examples/mcuboot/update_agent/CMakeLists.txt b/examples/mcuboot/update_agent/CMakeLists.txt deleted file mode 100644 index f356d8c22..000000000 --- a/examples/mcuboot/update_agent/CMakeLists.txt +++ /dev/null @@ -1,28 +0,0 @@ -# ############################################################################## -# apps/examples/mcuboot/update_agent/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_MCUBOOT_UPDATE_AGENT) - nuttx_add_application( - NAME mcuboot_agent - SRCS ${CMAKE_CURRENT_LIST_DIR}/mcuboot_agent_main.c - DEPENDS mcuboot) -endif() diff --git a/examples/mcuboot/update_agent/Kconfig b/examples/mcuboot/update_agent/Kconfig deleted file mode 100644 index 510f961e7..000000000 --- a/examples/mcuboot/update_agent/Kconfig +++ /dev/null @@ -1,36 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config EXAMPLES_MCUBOOT_UPDATE_AGENT - bool "MCUboot update agent example" - default n - select BOOT_MCUBOOT - depends on NET_TCP - ---help--- - Example application that implements an update agent that downloads - an application firmware image from a given URL and saves it to the - secondary slot as a pending update. - -if EXAMPLES_MCUBOOT_UPDATE_AGENT - -config EXAMPLES_MCUBOOT_UPDATE_AGENT_UPDATE_URL - string "URL for update image" - default "" - -config EXAMPLES_MCUBOOT_UPDATE_AGENT_DL_BUFFER_SIZE - int "Download buffer size in bytes" - default 512 - -config EXAMPLES_MCUBOOT_UPDATE_AGENT_DL_VERIFY_MD5 - bool "Calculate MD5 of update image" - default n - depends on CODECS_HASH_MD5 - -config EXAMPLES_MCUBOOT_UPDATE_AGENT_DL_MD5_HASH - string "Expected MD5 sum of update image" - default "" - depends on EXAMPLES_MCUBOOT_UPDATE_AGENT_DL_VERIFY_MD5 - -endif # EXAMPLES_MCUBOOT_UPDATE_AGENT diff --git a/examples/mcuboot/update_agent/Make.defs b/examples/mcuboot/update_agent/Make.defs deleted file mode 100644 index 0130402bd..000000000 --- a/examples/mcuboot/update_agent/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/examples/mcuboot/update_agent/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_EXAMPLES_MCUBOOT_UPDATE_AGENT),) -CONFIGURED_APPS += $(APPDIR)/examples/mcuboot/update_agent -endif diff --git a/examples/mcuboot/update_agent/Makefile b/examples/mcuboot/update_agent/Makefile deleted file mode 100644 index bb227cabf..000000000 --- a/examples/mcuboot/update_agent/Makefile +++ /dev/null @@ -1,31 +0,0 @@ -############################################################################ -# apps/examples/mcuboot/update_agent/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -MAINSRC += mcuboot_agent_main.c - -PROGNAME += mcuboot_agent -PRIORITY += SCHED_PRIORITY_DEFAULT -STACKSIZE += $(CONFIG_DEFAULT_TASK_STACKSIZE) - -include $(APPDIR)/Application.mk diff --git a/examples/mcuboot/update_agent_local/CMakeLists.txt b/examples/mcuboot/update_agent_local/CMakeLists.txt deleted file mode 100644 index 4b73b64fc..000000000 --- a/examples/mcuboot/update_agent_local/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# ############################################################################## -# apps/examples/mcuboot/update_agent_local/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_MCUBOOT_LOCAL_AGENT) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_MCUBOOT_LOCAL_AGENT_PROGNAME} - SRCS - mcuboot_local_agent_main.c - STACKSIZE - ${CONFIG_EXAMPLES_MCUBOOT_LOCAL_AGENT_STACKSIZE} - PRIORITY - ${CONFIG_EXAMPLES_MCUBOOT_LOCAL_AGENT_PRIORITY}) -endif() diff --git a/examples/mcuboot/update_agent_local/Kconfig b/examples/mcuboot/update_agent_local/Kconfig deleted file mode 100644 index 4079c83fb..000000000 --- a/examples/mcuboot/update_agent_local/Kconfig +++ /dev/null @@ -1,41 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config EXAMPLES_MCUBOOT_LOCAL_AGENT - tristate "MCUBoot Local Update Agent" - default n - depends on BOOT_MCUBOOT - select BOARDCTL - select BOARDCTL_RESET - ---help--- - Enable the MCUBoot Local Update Agent example. - This application reads a firmware binary from local storage - and copies it to the MCUBoot secondary flash slot for update. - -if EXAMPLES_MCUBOOT_LOCAL_AGENT - -config EXAMPLES_MCUBOOT_LOCAL_AGENT_PROGNAME - string "Program name" - default "mcuboot_local_agent" - ---help--- - This is the name of the program that will be used when the NSH ELF - program is installed. - -config EXAMPLES_MCUBOOT_LOCAL_AGENT_PRIORITY - int "MCUBoot Local Agent task priority" - default 100 - -config EXAMPLES_MCUBOOT_LOCAL_AGENT_STACKSIZE - int "MCUBoot Local Agent stack size" - default DEFAULT_TASK_STACKSIZE - -config EXAMPLES_MCUBOOT_LOCAL_AGENT_DEFAULT_PATH - string "Default firmware file path" - default "/mnt/sdcard/firmware.bin" - ---help--- - Default path to the firmware binary file on local storage. - This can be overridden by passing a path as a command line argument. - -endif # EXAMPLES_MCUBOOT_LOCAL_AGENT diff --git a/examples/mcuboot/update_agent_local/Make.defs b/examples/mcuboot/update_agent_local/Make.defs deleted file mode 100644 index e7f7ff602..000000000 --- a/examples/mcuboot/update_agent_local/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/examples/mcuboot/update_agent_local/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_EXAMPLES_MCUBOOT_LOCAL_AGENT),) -CONFIGURED_APPS += $(APPDIR)/examples/mcuboot/update_agent_local -endif diff --git a/examples/mcuboot/update_agent_local/Makefile b/examples/mcuboot/update_agent_local/Makefile deleted file mode 100644 index a730a662b..000000000 --- a/examples/mcuboot/update_agent_local/Makefile +++ /dev/null @@ -1,32 +0,0 @@ -############################################################################ -# apps/examples/mcuboot/update_agent_local/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -MAINSRC = mcuboot_local_agent_main.c - -PROGNAME = $(CONFIG_EXAMPLES_MCUBOOT_LOCAL_AGENT_PROGNAME) -PRIORITY = $(CONFIG_EXAMPLES_MCUBOOT_LOCAL_AGENT_PRIORITY) -STACKSIZE = $(CONFIG_EXAMPLES_MCUBOOT_LOCAL_AGENT_STACKSIZE) -MODULE = $(CONFIG_EXAMPLES_MCUBOOT_LOCAL_AGENT) - -include $(APPDIR)/Application.mk diff --git a/examples/mcuboot/update_agent_local/mcuboot_local_agent_main.c b/examples/mcuboot/update_agent_local/mcuboot_local_agent_main.c deleted file mode 100644 index dd0c183fa..000000000 --- a/examples/mcuboot/update_agent_local/mcuboot_local_agent_main.c +++ /dev/null @@ -1,298 +0,0 @@ -/**************************************************************************** - * apps/examples/mcuboot/update_agent_local/mcuboot_local_agent_main.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <errno.h> -#include <fcntl.h> -#include <stdint.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> -#include <sys/stat.h> -#include <sys/boardctl.h> - -#include <bootutil/bootutil_public.h> - -#include "flash_map_backend/flash_map_backend.h" -#include "sysflash/sysflash.h" - -/**************************************************************************** - * Preprocessor Definitions - ****************************************************************************/ - -#define BUFFER_SIZE 4096 -#define DEFAULT_FW_PATH "/mnt/sdcard/firmware.bin" - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -struct update_context_s -{ - FAR const struct flash_area *fa; - uint32_t fa_offset; - ssize_t image_size; - int fd; -}; - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static uint8_t g_buffer[BUFFER_SIZE]; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: get_file_size - * - * Description: - * Retrieves the size of an open file descriptor. - * - * Input Parameters: - * fd - File descriptor of the open file. - * - * Returned Value: - * On success, returns the file size in bytes. - * On failure, returns -1. - * - ****************************************************************************/ - -static ssize_t get_file_size(int fd) -{ - struct stat st; - - if (fstat(fd, &st) < 0) - { - return -1; - } - - return st.st_size; -} - -/**************************************************************************** - * Name: copy_firmware_from_local - * - * Description: - * Copies a firmware binary from local storage to the secondary flash slot. - * - * Input Parameters: - * filepath - Path to the firmware binary file. - * - * Returned Value: - * On success, returns OK. - * On failure, returns an error code. - * - ****************************************************************************/ - -static int copy_firmware_from_local(FAR const char *filepath) -{ - int ret = OK; - struct update_context_s ctx; - ssize_t bytes_read; - uint32_t total_copied = 0; - uint32_t progress; - - /* Initialize context */ - - memset(&ctx, 0, sizeof(ctx)); - ctx.fa = NULL; - ctx.fa_offset = 0; - ctx.image_size = -1; - ctx.fd = -1; - - /* Open firmware file from local storage */ - - ctx.fd = open(filepath, O_RDONLY); - if (ctx.fd < 0) - { - fprintf(stderr, "Failed to open firmware file: %s\n", filepath); - ret = -errno; - goto exit; - } - - /* Get file size */ - - ctx.image_size = get_file_size(ctx.fd); - if (ctx.image_size < 0) - { - fprintf(stderr, "Failed to get file size\n"); - ret = -errno; - goto exit_close_file; - } - - printf("Firmware file size: %zd bytes\n", ctx.image_size); - - /* Open secondary flash area for MCUBoot */ - - ret = flash_area_open(FLASH_AREA_IMAGE_SECONDARY(0), &ctx.fa); - if (ret != OK) - { - fprintf(stderr, "Failed to open secondary flash area: %d\n", ret); - goto exit_close_file; - } - - /* Check if file fits in secondary slot */ - - if (ctx.image_size > ctx.fa->fa_size) - { - fprintf(stderr, "Firmware file too large for secondary slot\n"); - fprintf(stderr, "File size: %zd, Slot size: %lu\n", - ctx.image_size, ctx.fa->fa_size); - ret = -EFBIG; - goto exit_close_flash; - } - - /* Erase secondary slot */ - - printf("Erasing secondary flash slot...\n"); - ret = flash_area_erase(ctx.fa, 0, ctx.fa->fa_size); - if (ret != OK) - { - fprintf(stderr, "Failed to erase secondary flash area: %d\n", ret); - goto exit_close_flash; - } - - /* Copy firmware from local storage to flash */ - - printf("Copying firmware to secondary slot...\n"); - - while (total_copied < ctx.image_size) - { - /* Read from local file */ - - bytes_read = read(ctx.fd, g_buffer, BUFFER_SIZE); - if (bytes_read < 0) - { - fprintf(stderr, "Failed to read from firmware file: %d\n", errno); - ret = -errno; - goto exit_close_flash; - } - - if (bytes_read == 0) - { - break; /* EOF reached */ - } - - /* Adjust bytes to write if near end of file */ - - if (total_copied + bytes_read > ctx.image_size) - { - bytes_read = ctx.image_size - total_copied; - } - - /* Write to flash */ - - ret = flash_area_write(ctx.fa, ctx.fa_offset, g_buffer, bytes_read); - if (ret != OK) - { - fprintf(stderr, "Failed to write to flash: %d\n", ret); - goto exit_close_flash; - } - - ctx.fa_offset += bytes_read; - total_copied += bytes_read; - - /* Show progress */ - - progress = (total_copied * 100) / ctx.image_size; - printf("Progress: %lu/%zd bytes [%lu%%]\n", - total_copied, ctx.image_size, progress); - } - - printf("Firmware copy completed successfully!\n"); - -exit_close_flash: - flash_area_close(ctx.fa); - -exit_close_file: - if (ctx.fd >= 0) - { - close(ctx.fd); - } - -exit: - return ret; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * mcuboot_local_agent_main - ****************************************************************************/ - -int main(int argc, FAR char *argv[]) -{ - int ret; - FAR const char *filepath; - - printf("MCUBoot Local Update Agent\n"); - - if (argc > 1) - { - filepath = argv[1]; - } - else - { - filepath = DEFAULT_FW_PATH; - } - - printf("Firmware file: %s\n", filepath); - - /* Copy firmware from local storage to secondary flash slot */ - - ret = copy_firmware_from_local(filepath); - if (ret != OK) - { - fprintf(stderr, "Firmware update failed: %d\n", ret); - return ERROR; - } - - printf("Firmware successfully copied to secondary slot!\n"); - - /* Mark image as pending for next boot */ - - boot_set_pending_multi(0, 0); - - printf("Update scheduled for next boot. Restarting...\n"); - - fflush(stdout); - fflush(stderr); - - usleep(1000000); /* Wait 1 second */ - - /* Restart system to apply update */ - - boardctl(BOARDIOC_RESET, 0); - - return OK; -} diff --git a/examples/mdnsd/Kconfig b/examples/mdnsd/Kconfig deleted file mode 100644 index 5b142d5d1..000000000 --- a/examples/mdnsd/Kconfig +++ /dev/null @@ -1,32 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config EXAMPLES_MDNSD - tristate "MDNS daemon example" - default n - depends on NETUTILS_MDNS_DAEMON - ---help--- - Enable the MDNS daemon example - -if EXAMPLES_MDNSD - -config EXAMPLES_MDNS_SERVICE - string "Name of the mdns service" - default "_nuttx._tcp.local" - ---help--- - This is the name of the service to be advertised by this example. - The format is _service.protocol.domain where - - "service" identifies the type of service being advertised such as - _http, or _printer - - "protocol" as used by the service (e.g. _udp or _tcp) - - "domain" which for mDNS is most likely _local - -config EXAMPLES_MDNS_SERVICE_PORT - string "The port that the advertised service uses" - default "32000" - ---help--- - The port the advertised service uses. The default is randomly chosen. - -endif diff --git a/examples/mdnsd/Make.defs b/examples/mdnsd/Make.defs deleted file mode 100644 index 96008aa5c..000000000 --- a/examples/mdnsd/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/examples/mdnsd/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_EXAMPLES_MDNSD),) -CONFIGURED_APPS += $(APPDIR)/examples/mdnsd -endif diff --git a/examples/mdnsd/Makefile b/examples/mdnsd/Makefile deleted file mode 100644 index 5dc84bd13..000000000 --- a/examples/mdnsd/Makefile +++ /dev/null @@ -1,38 +0,0 @@ -############################################################################ -# apps/examples/mdnsd/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -# MDNS Daemon Example - -CSRCS = mdnsd_daemon.c - -MAINSRC = mdnsd_start.c mdnsd_stop.c mdnsd_event.c - -# MDNSD built-in application info - -PROGNAME = mdnsd_start mdnsd_stop mdnsd_event -PRIORITY = SCHED_PRIORITY_DEFAULT -STACKSIZE = $(CONFIG_DEFAULT_TASK_STACKSIZE) -MODULE = $(CONFIG_EXAMPLES_MDNSD) - -include $(APPDIR)/Application.mk diff --git a/examples/mdnsd/mdnsd_daemon.c b/examples/mdnsd/mdnsd_daemon.c deleted file mode 100644 index bc2ea4563..000000000 --- a/examples/mdnsd/mdnsd_daemon.c +++ /dev/null @@ -1,103 +0,0 @@ -/**************************************************************************** - * apps/examples/mdnsd/mdnsd_daemon.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> -#include <stdint.h> -#include <stdlib.h> - -#include "netutils/netlib.h" -#include "netutils/mdnsd.h" -#include "mdnsd_daemon.h" - -/**************************************************************************** - * Preprocessor Definitions - ****************************************************************************/ - -/* Configuration Checks *****************************************************/ - -/* BEWARE: - * There are other configuration settings needed in netutils/mdnsd/mdnsdc.c, - * but there are default values for those so we cannot check them here. - */ - -#ifndef CONFIG_NET -# error "You must define CONFIG_NET" -#endif - -#ifndef CONFIG_NET_UDP -# error "You must define CONFIG_NET_UDP" -#endif - -#ifndef CONFIG_NET_BROADCAST -# error "You must define CONFIG_NET_BROADCAST" -#endif - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * mdnsd_showusage - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: mdnsd_daemon - ****************************************************************************/ - -int mdnsd_daemon(int argc, FAR char *argv[], bool start) -{ - /* No arguments are needed for the example app */ - - if (start) - { - return mdnsd_start(CONFIG_EXAMPLES_MDNS_SERVICE, - CONFIG_EXAMPLES_MDNS_SERVICE_PORT); - } - else - { - return mdnsd_stop(); - } -} diff --git a/examples/mdnsd/mdnsd_event.c b/examples/mdnsd/mdnsd_event.c deleted file mode 100644 index 432042372..000000000 --- a/examples/mdnsd/mdnsd_event.c +++ /dev/null @@ -1,244 +0,0 @@ -/**************************************************************************** - * apps/examples/mdnsd/mdnsd_event.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <arpa/inet.h> -#include <errno.h> -#include <net/if.h> -#include <netinet/in.h> -#include <netpacket/if_addr.h> -#include <netpacket/netlink.h> -#include <stdbool.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <sys/ioctl.h> -#include <sys/socket.h> -#include <unistd.h> - -#include "netutils/mdnsd.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define MDNSD_EVENT_BUFSIZE 512 -#define MDNSD_EVENT_SETTLE_MS 500 - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: mdnsd_event_has_ipv4addr - * - * Description: - * Check whether any network interface already has a non-zero IPv4 - * address. Uses SIOCGIFCONF to enumerate interfaces. - * - * Returned Value: - * true if at least one interface has a non-zero IPv4 address, - * false otherwise. - * - ****************************************************************************/ - -static bool mdnsd_event_has_ipv4addr(void) -{ - struct ifconf ifc; - char buf[sizeof(struct ifreq) * 4]; - int sd; - int i; - - sd = socket(AF_INET, SOCK_DGRAM, 0); - if (sd < 0) - { - return false; - } - - ifc.ifc_len = sizeof(buf); - ifc.ifc_buf = buf; - if (ioctl(sd, SIOCGIFCONF, &ifc) < 0) - { - close(sd); - return false; - } - - close(sd); - - for (i = 0; i < ifc.ifc_len; i += sizeof(struct ifreq)) - { - FAR struct ifreq *ifr = (FAR struct ifreq *)&buf[i]; - FAR struct sockaddr_in *sin; - - if (ifr->ifr_addr.sa_family != AF_INET) - { - continue; - } - - sin = (FAR struct sockaddr_in *)&ifr->ifr_addr; - if (sin->sin_addr.s_addr != INADDR_ANY && - sin->sin_addr.s_addr != htonl(INADDR_LOOPBACK)) - { - return true; - } - } - - return false; -} - -/**************************************************************************** - * Name: mdnsd_event_is_newaddr - * - * Description: - * Checks whether the given Netlink message header represents a new - * IPv4 or IPv6 address event (RTM_NEWADDR). - * - * Input Parameters: - * hdr - Pointer to the Netlink message header to inspect. - * - * Returned Value: - * true if the message is a new IPv4 or IPv6 address notification, - * false otherwise. - * - ****************************************************************************/ - -static bool mdnsd_event_is_newaddr(FAR struct nlmsghdr *hdr) -{ - FAR struct ifaddrmsg *addr; - - if (hdr->nlmsg_type != RTM_NEWADDR) - { - return false; - } - - if (hdr->nlmsg_len < NLMSG_LENGTH(sizeof(struct ifaddrmsg))) - { - return false; - } - - addr = (FAR struct ifaddrmsg *)NLMSG_DATA(hdr); - return addr->ifa_family == AF_INET || addr->ifa_family == AF_INET6; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: main - * - * Description: - * Entry point for the mdnsd_event application. Listens for Netlink - * address events and starts the mDNS daemon when an IP address is - * assigned to a network interface. - * - * Input Parameters: - * argc - Number of command-line arguments. - * argv - Array of command-line argument strings. - * - * Returned Value: - * EXIT_SUCCESS on success, EXIT_FAILURE on error. - * - ****************************************************************************/ - -int main(int argc, FAR char *argv[]) -{ -#ifdef CONFIG_NETLINK_ROUTE - struct sockaddr_nl addr; - uint8_t buffer[MDNSD_EVENT_BUFSIZE]; - int sd; - int ret; - - /* If an interface already has an IP (DHCP finished before we started), - * skip the netlink wait and start mDNS right away. - */ - - if (mdnsd_event_has_ipv4addr()) - { - printf("mdnsd_event: address already set, starting mDNS\n"); - usleep(MDNSD_EVENT_SETTLE_MS * 1000); - ret = mdnsd_start(CONFIG_EXAMPLES_MDNS_SERVICE, - CONFIG_EXAMPLES_MDNS_SERVICE_PORT); - return ret < 0 ? EXIT_FAILURE : EXIT_SUCCESS; - } - - sd = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE); - if (sd < 0) - { - fprintf(stderr, "mdnsd_event: socket failed: %d\n", errno); - return EXIT_FAILURE; - } - - memset(&addr, 0, sizeof(addr)); - addr.nl_family = AF_NETLINK; - addr.nl_groups = RTMGRP_IPV4_IFADDR | RTMGRP_IPV6_IFADDR; - - ret = bind(sd, (FAR struct sockaddr *)&addr, sizeof(addr)); - if (ret < 0) - { - fprintf(stderr, "mdnsd_event: bind failed: %d\n", errno); - close(sd); - return EXIT_FAILURE; - } - - printf("mdnsd_event: waiting for network address event\n"); - - for (; ; ) - { - FAR struct nlmsghdr *hdr; - ssize_t nread; - int remaining; - - nread = recv(sd, buffer, sizeof(buffer), 0); - if (nread < 0) - { - fprintf(stderr, "mdnsd_event: recv failed: %d\n", errno); - close(sd); - return EXIT_FAILURE; - } - - remaining = nread; - for (hdr = (FAR struct nlmsghdr *)buffer; - NLMSG_OK(hdr, remaining); - hdr = NLMSG_NEXT(hdr, remaining)) - { - if (mdnsd_event_is_newaddr(hdr)) - { - printf("mdnsd_event: address set, starting mDNS\n"); - usleep(MDNSD_EVENT_SETTLE_MS * 1000); - ret = mdnsd_start(CONFIG_EXAMPLES_MDNS_SERVICE, - CONFIG_EXAMPLES_MDNS_SERVICE_PORT); - close(sd); - return ret < 0 ? EXIT_FAILURE : EXIT_SUCCESS; - } - } - } -#else - fprintf(stderr, "mdnsd_event: CONFIG_NETLINK_ROUTE is required\n"); - return EXIT_FAILURE; -#endif -} diff --git a/examples/mdnsd/mdnsd_start.c b/examples/mdnsd/mdnsd_start.c deleted file mode 100644 index 865bde967..000000000 --- a/examples/mdnsd/mdnsd_start.c +++ /dev/null @@ -1,43 +0,0 @@ -/**************************************************************************** - * apps/examples/mdnsd/mdnsd_start.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> -#include <stdio.h> - -#include "mdnsd_daemon.h" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: mdnsd_start_main - ****************************************************************************/ - -int main(int argc, FAR char *argv[]) -{ - return mdnsd_daemon(argc, argv, true); -} diff --git a/examples/mdnsd/mdnsd_stop.c b/examples/mdnsd/mdnsd_stop.c deleted file mode 100644 index 45da47dd2..000000000 --- a/examples/mdnsd/mdnsd_stop.c +++ /dev/null @@ -1,43 +0,0 @@ -/**************************************************************************** - * apps/examples/mdnsd/mdnsd_stop.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> -#include <stdio.h> - -#include "mdnsd_daemon.h" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: mdnsd_stop_main - ****************************************************************************/ - -int main(int argc, char **argv) -{ - return mdnsd_daemon(argc, argv, false); -} diff --git a/examples/media/CMakeLists.txt b/examples/media/CMakeLists.txt deleted file mode 100644 index e579c4fd9..000000000 --- a/examples/media/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# ############################################################################## -# apps/examples/media/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_MEDIA) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_MEDIA_PROGNAME} - STACKSIZE - ${CONFIG_DEFAULT_TASK_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_MEDIA} - SRCS - media_main.c) -endif() diff --git a/examples/media/Make.defs b/examples/media/Make.defs index d6ae0164a..99d09ae79 100644 --- a/examples/media/Make.defs +++ b/examples/media/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/media/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/media/Makefile b/examples/media/Makefile index c1d39a1b2..d0203d196 100644 --- a/examples/media/Makefile +++ b/examples/media/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/media/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/media/media_main.c b/examples/media/media_main.c index f27b507c4..31c4b586e 100644 --- a/examples/media/media_main.c +++ b/examples/media/media_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/media/media_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -33,7 +31,6 @@ #include <stdlib.h> #include <fcntl.h> #include <errno.h> -#include <unistd.h> #include <nuttx/fs/fs.h> #include <nuttx/mtd/mtd.h> diff --git a/examples/microros_pub/CMakeLists.txt b/examples/microros_pub/CMakeLists.txt deleted file mode 100644 index 8bf83218e..000000000 --- a/examples/microros_pub/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# ############################################################################## -# apps/examples/microros_pub/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_MICROROS_PUB) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_MICROROS_PUB_PROGNAME} - SRCS - microros_pub_main.c - STACKSIZE - ${CONFIG_EXAMPLES_MICROROS_PUB_STACKSIZE} - PRIORITY - ${CONFIG_EXAMPLES_MICROROS_PUB_PRIORITY} - DEPENDS - microros_transport) -endif() diff --git a/examples/microros_pub/Kconfig b/examples/microros_pub/Kconfig deleted file mode 100644 index a1d75478d..000000000 --- a/examples/microros_pub/Kconfig +++ /dev/null @@ -1,30 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config EXAMPLES_MICROROS_PUB - tristate "micro-ROS int32 publisher example" - default n - depends on SYSTEM_MICROROS - ---help--- - Minimal micro-ROS publisher that creates a node and publishes - an std_msgs/Int32 every second on the topic /nuttx_pub. Used - to validate the NuttX-native transport layer end-to-end with - a micro-ROS agent. - -if EXAMPLES_MICROROS_PUB - -config EXAMPLES_MICROROS_PUB_PROGNAME - string "Program name" - default "microros_pub" - -config EXAMPLES_MICROROS_PUB_PRIORITY - int "micro-ROS pub task priority" - default 100 - -config EXAMPLES_MICROROS_PUB_STACKSIZE - int "micro-ROS pub stack size" - default 8192 - -endif diff --git a/examples/microros_pub/Make.defs b/examples/microros_pub/Make.defs deleted file mode 100644 index 16128b96e..000000000 --- a/examples/microros_pub/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/examples/microros_pub/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_EXAMPLES_MICROROS_PUB),) -CONFIGURED_APPS += $(APPDIR)/examples/microros_pub -endif diff --git a/examples/microros_pub/Makefile b/examples/microros_pub/Makefile deleted file mode 100644 index 1377e68b5..000000000 --- a/examples/microros_pub/Makefile +++ /dev/null @@ -1,32 +0,0 @@ -############################################################################ -# apps/examples/microros_pub/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -PROGNAME = $(CONFIG_EXAMPLES_MICROROS_PUB_PROGNAME) -PRIORITY = $(CONFIG_EXAMPLES_MICROROS_PUB_PRIORITY) -STACKSIZE = $(CONFIG_EXAMPLES_MICROROS_PUB_STACKSIZE) -MODULE = $(CONFIG_EXAMPLES_MICROROS_PUB) - -MAINSRC = microros_pub_main.c - -include $(APPDIR)/Application.mk diff --git a/examples/microros_pub/microros_pub_main.c b/examples/microros_pub/microros_pub_main.c deleted file mode 100644 index d9211c36b..000000000 --- a/examples/microros_pub/microros_pub_main.c +++ /dev/null @@ -1,109 +0,0 @@ -/**************************************************************************** - * apps/examples/microros_pub/microros_pub_main.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <stdio.h> -#include <unistd.h> - -#include <rcl/rcl.h> -#include <rcl/error_handling.h> -#include <rclc/rclc.h> -#include <rclc/executor.h> -#include <std_msgs/msg/int32.h> - -#include <system/microros_transport.h> - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -int main(int argc, FAR char *argv[]) -{ - rcl_publisher_t publisher; - std_msgs__msg__Int32 msg; - rcl_allocator_t allocator; - rclc_support_t support; - rcl_node_t node; - int i; - - printf("microros_pub: starting\n"); - - if (microros_transport_init() != 0) - { - printf("microros_pub: transport init failed\n"); - return 1; - } - - allocator = rcl_get_default_allocator(); - - if (rclc_support_init(&support, 0, NULL, &allocator) != RCL_RET_OK) - { - printf("microros_pub: rclc_support_init failed\n"); - return 1; - } - - if (rclc_node_init_default(&node, "nuttx_node", "", &support) - != RCL_RET_OK) - { - printf("microros_pub: node init failed\n"); - return 1; - } - - if (rclc_publisher_init_default( - &publisher, - &node, - ROSIDL_GET_MSG_TYPE_SUPPORT(std_msgs, msg, Int32), - "nuttx_pub") != RCL_RET_OK) - { - printf("microros_pub: publisher init failed\n"); - return 1; - } - - msg.data = 0; - - for (i = 0; i < 30; i++) - { - if (rcl_publish(&publisher, &msg, NULL) == RCL_RET_OK) - { - printf("microros_pub: sent %d\n", (int)msg.data); - } - else - { - printf("microros_pub: publish failed\n"); - } - - msg.data++; - sleep(1); - } - - rcl_publisher_fini(&publisher, &node); - rcl_node_fini(&node); - rclc_support_fini(&support); - - printf("microros_pub: done\n"); - return 0; -} diff --git a/examples/microros_sub/CMakeLists.txt b/examples/microros_sub/CMakeLists.txt deleted file mode 100644 index 1c094949a..000000000 --- a/examples/microros_sub/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# ############################################################################## -# apps/examples/microros_sub/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_MICROROS_SUB) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_MICROROS_SUB_PROGNAME} - SRCS - microros_sub_main.c - STACKSIZE - ${CONFIG_EXAMPLES_MICROROS_SUB_STACKSIZE} - PRIORITY - ${CONFIG_EXAMPLES_MICROROS_SUB_PRIORITY} - DEPENDS - microros_transport) -endif() diff --git a/examples/microros_sub/Kconfig b/examples/microros_sub/Kconfig deleted file mode 100644 index 3bbbf5efb..000000000 --- a/examples/microros_sub/Kconfig +++ /dev/null @@ -1,31 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config EXAMPLES_MICROROS_SUB - tristate "micro-ROS int32 subscriber example" - default n - depends on SYSTEM_MICROROS - ---help--- - Minimal micro-ROS subscriber that creates a node, subscribes to - the topic /nuttx_sub with std_msgs/Int32, and prints each - received value. Drives an rclc_executor spin loop and is used - together with microros_pub (or any external publisher) to - validate the NuttX-native transport in the receive direction. - -if EXAMPLES_MICROROS_SUB - -config EXAMPLES_MICROROS_SUB_PROGNAME - string "Program name" - default "microros_sub" - -config EXAMPLES_MICROROS_SUB_PRIORITY - int "micro-ROS sub task priority" - default 100 - -config EXAMPLES_MICROROS_SUB_STACKSIZE - int "micro-ROS sub stack size" - default 8192 - -endif diff --git a/examples/microros_sub/Make.defs b/examples/microros_sub/Make.defs deleted file mode 100644 index e9fe5aa1d..000000000 --- a/examples/microros_sub/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/examples/microros_sub/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_EXAMPLES_MICROROS_SUB),) -CONFIGURED_APPS += $(APPDIR)/examples/microros_sub -endif diff --git a/examples/microros_sub/Makefile b/examples/microros_sub/Makefile deleted file mode 100644 index a1144a70c..000000000 --- a/examples/microros_sub/Makefile +++ /dev/null @@ -1,32 +0,0 @@ -############################################################################ -# apps/examples/microros_sub/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -PROGNAME = $(CONFIG_EXAMPLES_MICROROS_SUB_PROGNAME) -PRIORITY = $(CONFIG_EXAMPLES_MICROROS_SUB_PRIORITY) -STACKSIZE = $(CONFIG_EXAMPLES_MICROROS_SUB_STACKSIZE) -MODULE = $(CONFIG_EXAMPLES_MICROROS_SUB) - -MAINSRC = microros_sub_main.c - -include $(APPDIR)/Application.mk diff --git a/examples/microros_sub/microros_sub_main.c b/examples/microros_sub/microros_sub_main.c deleted file mode 100644 index 1e1a6c550..000000000 --- a/examples/microros_sub/microros_sub_main.c +++ /dev/null @@ -1,131 +0,0 @@ -/**************************************************************************** - * apps/examples/microros_sub/microros_sub_main.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <stdio.h> -#include <unistd.h> - -#include <rcl/rcl.h> -#include <rcl/error_handling.h> -#include <rclc/rclc.h> -#include <rclc/executor.h> -#include <std_msgs/msg/int32.h> - -#include <system/microros_transport.h> - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static std_msgs__msg__Int32 g_rx_msg; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static void sub_callback(const void *msgin) -{ - const std_msgs__msg__Int32 *msg = (const std_msgs__msg__Int32 *)msgin; - - printf("microros_sub: got %d\n", (int)msg->data); -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -int main(int argc, FAR char *argv[]) -{ - rcl_subscription_t subscriber; - rcl_allocator_t allocator; - rclc_support_t support; - rcl_node_t node; - rclc_executor_t executor; - - printf("microros_sub: starting\n"); - - if (microros_transport_init() != 0) - { - printf("microros_sub: transport init failed\n"); - return 1; - } - - allocator = rcl_get_default_allocator(); - - if (rclc_support_init(&support, 0, NULL, &allocator) != RCL_RET_OK) - { - printf("microros_sub: rclc_support_init failed\n"); - return 1; - } - - if (rclc_node_init_default(&node, "nuttx_sub_node", "", &support) - != RCL_RET_OK) - { - printf("microros_sub: node init failed\n"); - return 1; - } - - if (rclc_subscription_init_default( - &subscriber, - &node, - ROSIDL_GET_MSG_TYPE_SUPPORT(std_msgs, msg, Int32), - "nuttx_sub") != RCL_RET_OK) - { - printf("microros_sub: subscription init failed\n"); - return 1; - } - - executor = rclc_executor_get_zero_initialized_executor(); - if (rclc_executor_init(&executor, &support.context, 1, &allocator) - != RCL_RET_OK) - { - printf("microros_sub: executor init failed\n"); - return 1; - } - - if (rclc_executor_add_subscription(&executor, - &subscriber, - &g_rx_msg, - &sub_callback, - ON_NEW_DATA) != RCL_RET_OK) - { - printf("microros_sub: add_subscription failed\n"); - return 1; - } - - printf("microros_sub: spinning on /nuttx_sub\n"); - - rclc_executor_spin(&executor); - - rclc_executor_fini(&executor); - rcl_subscription_fini(&subscriber, &node); - rcl_node_fini(&node); - rclc_support_fini(&support); - - printf("microros_sub: done\n"); - return 0; -} diff --git a/examples/microwindows/Kconfig b/examples/microwindows/Kconfig deleted file mode 100644 index 6319ac587..000000000 --- a/examples/microwindows/Kconfig +++ /dev/null @@ -1,26 +0,0 @@ -config EXAMPLES_MICROWINDOWS - tristate "Microwindows example" - default n - depends on GRAPHICS_MICROWINDOWS - depends on MICROWINDOWS_MWIN - ---help--- - Enable the Microwindows example application - -if EXAMPLES_MICROWINDOWS - -config EXAMPLES_MICROWINDOWS_PROGNAME - string "Program name" - default "mwexample" - ---help--- - This is the name of the program that will be used when the NSH ELF - program is installed. - -config EXAMPLES_MICROWINDOWS_PRIORITY - int "Microwindows task priority" - default 100 - -config EXAMPLES_MICROWINDOWS_STACKSIZE - int "Microwindows stack size" - default 32768 - -endif diff --git a/examples/microwindows/Make.defs b/examples/microwindows/Make.defs deleted file mode 100644 index 6c3595cc3..000000000 --- a/examples/microwindows/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/examples/microwindows/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_EXAMPLES_MICROWINDOWS),) -CONFIGURED_APPS += $(APPDIR)/examples/microwindows -endif diff --git a/examples/microwindows/Makefile b/examples/microwindows/Makefile deleted file mode 100644 index c8c588abc..000000000 --- a/examples/microwindows/Makefile +++ /dev/null @@ -1,55 +0,0 @@ -############################################################################ -# apps/examples/microwindows/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -PROGNAME = $(CONFIG_EXAMPLES_MICROWINDOWS_PROGNAME) -PRIORITY = $(CONFIG_EXAMPLES_MICROWINDOWS_PRIORITY) -STACKSIZE = $(CONFIG_EXAMPLES_MICROWINDOWS_STACKSIZE) -MODULE = $(CONFIG_EXAMPLES_MICROWINDOWS) - -MAINSRC = mwdemo_main.c -CSRCS += mwdemo.c -MW_IMAGES = penguin microwin -CSRCS += $(MW_IMAGES:%=$(MW_IMGDIR)/%.c) - -# Generate image .c files from .bmp -MW_SRC = $(APPDIR)/graphics/microwindows/microwindows/src -MW_IMGDIR = images -MW_CONVBMP = convbmp$(HOSTEXEEXT) - -$(MW_CONVBMP): $(MW_SRC)/images/tools/convbmp.c - $(HOSTCC) $(HOSTCFLAGS) -I$(MW_SRC)/include $< -o $@ - -$(MW_IMGDIR)/%.c: $(MW_SRC)/images/demos/mwin/%.bmp $(MW_CONVBMP) - mkdir -p $(MW_IMGDIR) - $(CURDIR)/$(MW_CONVBMP) -o $@ $< - -clean:: - $(call DELFILE, $(MW_IMAGES:%=$(MW_IMGDIR)/%.c)) - $(Q) rmdir $(MW_IMGDIR) 2>/dev/null || true - $(call DELFILE, $(MW_CONVBMP)) - -CFLAGS += -Wno-undef -CFLAGS += -DNOGDI - -include $(APPDIR)/Application.mk diff --git a/examples/microwindows/mwdemo.c b/examples/microwindows/mwdemo.c deleted file mode 100644 index c672fd459..000000000 --- a/examples/microwindows/mwdemo.c +++ /dev/null @@ -1,333 +0,0 @@ -/**************************************************************************** - * apps/examples/microwindows/mwdemo.c - * - * Copyright (c) 1999, 2000, 2001, 2010 Greg Haerr <greg@censoft.com> - * Portions Copyright (c) 2002 by Koninklijke Philips Electronics N.V. - * - * Demo program for Microwindows - * - * GB: 10-14-2004: Modified to store degrees data on each window, - * for new Timers features. - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <stdlib.h> -#include <uni_std.h> -#define MWINCLUDECOLORS -#include <windows.h> -#include <device.h> -#include <graph3d.h> - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -typedef struct -{ - int startdegrees; - int enddegrees; -} demoWndData; - -typedef demoWndData *pdemoWndData; - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -extern MWIMAGEHDR image_penguin; -PMWIMAGEHDR g_image = &image_penguin; - -#define APPCLASS "test" -#define APPCHILD "test2" - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wp, LPARAM lp); - -LRESULT CALLBACK ChildWndProc(HWND hwnd, UINT uMsg, WPARAM wp, LPARAM lp); - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -int MwUserInit(int ac, char **av) -{ - /* test user init procedure - do nothing */ - - return 0; -} - -int RegisterAppClass(HINSTANCE hInstance) -{ - WNDCLASS wc; - - /* register builtin controls and dialog classes */ - - MwInitializeDialogs(hInstance); - - wc.style = CS_DBLCLKS | CS_VREDRAW | CS_HREDRAW; - wc.lpfnWndProc = (WNDPROC) WndProc; - wc.cbClsExtra = 0; - wc.cbWndExtra = sizeof(LONG_PTR); - wc.hInstance = 0; - wc.hIcon = 0; /* LoadIcon(GetHInstance(), MAKEINTRESOURCE( - * 1)); */ - wc.hCursor = LoadCursor(NULL, IDC_ARROW); - wc.hbrBackground = (HBRUSH) GetStockObject(LTGRAY_BRUSH); - wc.lpszMenuName = NULL; - wc.lpszClassName = APPCLASS; - RegisterClass(&wc); - - wc.lpfnWndProc = (WNDPROC) ChildWndProc; - wc.lpszClassName = APPCHILD; - return RegisterClass(&wc); -} - -HWND CreateAppWindow(void) -{ - HWND hwnd; - static int nextid = 1; - int width; - int height; - RECT r; - GetWindowRect(GetDesktopWindow(), &r); - width = height = r.right / 2; - - hwnd = CreateWindowEx(0L, APPCLASS, - "Microwindows Application", - WS_OVERLAPPEDWINDOW | WS_VISIBLE, - CW_USEDEFAULT, CW_USEDEFAULT, - width, height, - NULL, (HMENU)(LONG_PTR)nextid++, NULL, NULL); - - if (hwnd && (nextid & 03) != 2) - { - CreateWindowEx(0L, APPCHILD, - "", - WS_BORDER | WS_CHILD | WS_VISIBLE, - 4, 4, width / 3 - 6, height / 3, - hwnd, (HMENU)2, NULL, NULL); - CreateWindowEx(0L, APPCHILD, - "", - WS_BORDER | WS_CHILD | WS_VISIBLE, - width / 3, height / 3, - width / 3 - 6, height / 3, - hwnd, (HMENU)3, NULL, NULL); - CreateWindowEx(0L, APPCHILD, - "", - WS_BORDER | WS_CHILD | WS_VISIBLE, - width * 3 / 5, height * 3 / 5, - width * 2 / 3, height * 2 / 3, - hwnd, (HMENU)4, NULL, NULL); - CreateWindowEx(0L, "EDIT", - "OK", - WS_BORDER | WS_CHILD | WS_VISIBLE, - width * 5 / 8, 10, - 100, 18, - hwnd, (HMENU)5, NULL, NULL); - CreateWindowEx(0L, "PROGBAR", - "OK", - WS_BORDER | WS_CHILD | WS_VISIBLE, - width * 5 / 8, 32, - 100, 18, - hwnd, (HMENU)6, NULL, NULL); - - HWND hlist = CreateWindowEx(0L, "LISTBOX", - "OK", - WS_HSCROLL | WS_VSCROLL | - WS_BORDER | WS_CHILD | - WS_VISIBLE, - width * 5 / 8, 54, - 100, 48, - hwnd, (HMENU)7, NULL, NULL); - SendMessage(hlist, LB_ADDSTRING, 0, - (LPARAM)(LPSTR)"Cherry"); - SendMessage(hlist, LB_ADDSTRING, 0, - (LPARAM)(LPSTR)"Apple"); - SendMessage(hlist, LB_ADDSTRING, 0, - (LPARAM)(LPSTR)"Orange"); - - CreateWindowEx(0L, "BUTTON", - "Cancel", - BS_AUTOCHECKBOX | WS_CHILD | WS_VISIBLE, - width * 5 / 8 + 50, 106, - 50, 14, - hwnd, (HMENU)8, NULL, NULL); - } - - return hwnd; -} - -LRESULT CALLBACK ChildWndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) -{ - RECT rc; - PAINTSTRUCT ps; - - switch (msg) - { - case WM_PAINT: - BeginPaint(hwnd, &ps); - GetClientRect(hwnd, &rc); - - HDC hdcMem; - HBITMAP hbmp, hbmpOrg; - - /* redirect painting to offscreen dc, then use blit function */ - - hdcMem = CreateCompatibleDC(ps.hdc); - - /* Note: rc.right, rc.bottom happens to be smaller than image - * width/height. We use the image size, so we can stretchblit - * from the whole image. - */ - - hbmp = CreateCompatibleBitmap(hdcMem, g_image->width, - g_image->height); - hbmpOrg = SelectObject(hdcMem, hbmp); - - /* draw onto offscreen dc */ - - DrawDIB(hdcMem, 0, 0, g_image); - - /* blit offscreen with physical screen */ - - StretchBlt(ps.hdc, 0, 0, rc.right * 4 / 5, - rc.bottom * 4 / 5, hdcMem, - 0, 0, g_image->width, g_image->height, MWROP_COPY); - DeleteObject(SelectObject(hdcMem, hbmpOrg)); - DeleteDC(hdcMem); - EndPaint(hwnd, &ps); - break; - default: - return DefWindowProc(hwnd, msg, wp, lp); - } - - return 0; -} - -LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) -{ - PAINTSTRUCT ps; - HDC hdc; - RECT rc; - static int countup = 1; - int id; - static vec1 gx; - static vec1 gy; - static POINT mousept; - pdemoWndData pData; - - switch (msg) - { - case WM_CREATE: - pData = (pdemoWndData) malloc(sizeof(demoWndData)); - SetWindowLongPtr(hwnd, 0, (LONG_PTR) pData); - mousept.x = 60; - mousept.y = 20; - pData->startdegrees = 0; - pData->enddegrees = 30; - SetTimer(hwnd, 1, (50 + random() % 250), NULL); - break; - - case WM_TIMER: - pData = (pdemoWndData)(LONG_PTR)GetWindowLongPtr(hwnd, 0); - GetClientRect(hwnd, &rc); - if (countup) - { - mousept.y += 20; - if (mousept.y >= rc.bottom) - { - mousept.y -= 20; - countup = 0; - } - } - else - { - mousept.y -= 20; - if (mousept.y < 20) - { - mousept.y += 20; - countup = 1; - } - } - - SendMessage(hwnd, WM_MOUSEMOVE, 0, - MAKELONG(mousept.x, mousept.y)); - break; - case WM_DESTROY: - KillTimer(hwnd, 1); - pData = (pdemoWndData)(LONG_PTR)GetWindowLongPtr(hwnd, 0); - free(pData); - SetWindowLongPtr(hwnd, 0, (LONG_PTR)0); - break; - case WM_SIZE: - break; - case WM_MOVE: - break; - - case WM_ERASEBKGND: - if ((GetWindowLong(hwnd, GWL_ID) & 03) == 1) - { - return 1; - } - - return DefWindowProc(hwnd, msg, wp, lp); - case WM_PAINT: - hdc = BeginPaint(hwnd, &ps); - id = (int)GetWindowLong(hwnd, GWL_ID) & 03; - init3(hdc, id == 1 ? hwnd : NULL); - switch (id) - { - case 0: - rose(1.0, 7, 13); - break; - case 1: - look3(-2 * gx, -2 * gy, 1.2); - drawgrid(-8.0, 8.0, 10, -8.0, 8.0, 10); - break; - case 2: - setcolor3(BLACK); - circle3(1.0); - break; - case 3: - setcolor3(BLUE); - daisy(1.0, 20); - break; - } - - paint3(hdc); - EndPaint(hwnd, &ps); - break; - - case WM_MOUSEMOVE: - pData = (pdemoWndData)(LONG_PTR)GetWindowLongPtr(hwnd, 0); - if ((GetWindowLong(hwnd, GWL_ID) & 03) == 1) - { - POINT pt; - - POINTSTOPOINT(pt, lp); - GetClientRect(hwnd, &rc); - gx = (vec1) pt.x / rc.right; - gy = (vec1) pt.y / rc.bottom; - InvalidateRect(hwnd, NULL, FALSE); - mousept.x = pt.x; - mousept.y = pt.y; - } - break; - case WM_LBUTTONDOWN: - break; - case WM_LBUTTONUP: - break; - case WM_RBUTTONDOWN: - break; - default: - return DefWindowProc(hwnd, msg, wp, lp); - } - - return 0; -} diff --git a/examples/microwindows/mwdemo_main.c b/examples/microwindows/mwdemo_main.c deleted file mode 100644 index f8860074b..000000000 --- a/examples/microwindows/mwdemo_main.c +++ /dev/null @@ -1,101 +0,0 @@ -/**************************************************************************** - * apps/examples/microwindows/mwdemo_main.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> -#include <time.h> -#include <stdlib.h> -#include <uni_std.h> -#include <windows.h> - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -extern MWIMAGEHDR image_microwin; - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -extern int RegisterAppClass(HINSTANCE hInstance); -extern HWND CreateAppWindow(void); - -#define APPCLASS "test" -#define APPCHILD "test2" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -int main(int argc, FAR char *argv[]) -{ - MSG msg; - HWND hwnd; - RECT rc; - - invoke_WinMain_Start(argc, argv); - - srandom(time(NULL)); - RegisterAppClass(0); - GetWindowRect(GetDesktopWindow(), &rc); - - /* create penguin window */ - - CreateWindowEx(0L, APPCHILD, "", - WS_BORDER | WS_VISIBLE, - rc.right - 130 - 1, rc.bottom - 153 - 1, - 130, 153, - GetDesktopWindow(), (HMENU)1000, NULL, NULL); - - CreateAppWindow(); - CreateAppWindow(); - CreateAppWindow(); - CreateAppWindow(); - CreateAppWindow(); - CreateAppWindow(); - CreateAppWindow(); - CreateAppWindow(); - - /* set background wallpaper */ - - MwSetDesktopWallpaper(&image_microwin); - hwnd = CreateAppWindow(); - GetWindowRect(hwnd, &rc); - OffsetRect(&rc, 50, 50); - MoveWindow(hwnd, rc.left, rc.top, - rc.bottom - rc.top, - rc.right - rc.left, TRUE); - - while (GetMessage(&msg, NULL, 0, 0)) - { - TranslateMessage(&msg); - DispatchMessage(&msg); - } - - invoke_WinMain_End(); - - return 0; -} diff --git a/examples/mld/CMakeLists.txt b/examples/mld/CMakeLists.txt deleted file mode 100644 index 66120beb4..000000000 --- a/examples/mld/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# ############################################################################## -# apps/examples/mld/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_MLD) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_MLD_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_MLD_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_MLD_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_MLD} - SRCS - mld_main.c) -endif() diff --git a/examples/mld/Kconfig b/examples/mld/Kconfig index 47e650c91..4816998bb 100644 --- a/examples/mld/Kconfig +++ b/examples/mld/Kconfig @@ -29,7 +29,8 @@ config EXAMPLES_MLD_STACKSIZE config EXAMPLES_MLD_INIT bool "Initialize network" - default !NSH_NETINIT + default n if NSH_NETINIT + default y if !NSH_NETINIT ---help--- Include logic to initialize the network. This should not be done if the network is already initialized when nettest runs. This is diff --git a/examples/mld/Make.defs b/examples/mld/Make.defs index 350dbd005..c94b181f2 100644 --- a/examples/mld/Make.defs +++ b/examples/mld/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/mld/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/mld/Makefile b/examples/mld/Makefile index af45c8866..f309c17e8 100644 --- a/examples/mld/Makefile +++ b/examples/mld/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/mld/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/mld/mld.h b/examples/mld/mld.h index 936a37062..c2d5afbfc 100644 --- a/examples/mld/mld.h +++ b/examples/mld/mld.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/mld/mld.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -27,7 +25,7 @@ * Included Files ****************************************************************************/ -#include <nuttx/debug.h> +#include <debug.h> /**************************************************************************** * Pre-processor Definitions diff --git a/examples/mld/mld_main.c b/examples/mld/mld_main.c index 594115a22..dd7a894f9 100644 --- a/examples/mld/mld_main.c +++ b/examples/mld/mld_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/mld/mld_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -33,7 +31,7 @@ #include <fcntl.h> #include <string.h> #include <errno.h> -#include <nuttx/debug.h> +#include <debug.h> #include <arpa/inet.h> #include <net/if.h> @@ -361,28 +359,31 @@ int main(int argc, FAR char *argv[]) /* Set up a routing table entry for the address of the multicast group */ - memset(&target, 0, sizeof(target)); + memset(&target, 0, sizeof(struct sockaddr_in6)); target.sin6_family = AF_INET6; target.sin6_port = HTONS(0x4321); - memcpy(v6_addr->sin6_addr.s6_addr16, g_grp_addr, sizeof(struct in6_addr)); + memcpy(target.sin6_addr.s6_addr16, g_grp_addr, sizeof(struct in6_addr)); - memset(&netmask, 0, sizeof(netmask)); + memset(&netmask, 0, sizeof(struct sockaddr_in6)); netmask.sin6_family = AF_INET6; netmask.sin6_port = HTONS(0x4321); - memset(v6_addr->sin6_addr.s6_addr16, 0xff, sizeof(struct in6_addr)); + memset(netmask.sin6_addr.s6_addr16, 0xff, sizeof(struct in6_addr)); - memset(&router, 0, sizeof(router)); + memset(&router, 0, sizeof(struct sockaddr_in6)); router.sin6_family = AF_INET6; router.sin6_port = HTONS(0x4321); - ret = netlib_get_ipv6addr("eth0", &v6_addr->sin6_addr); + ret = netlib_get_ipv6addr("eth0", &router.sin6_addr); if (ret < 0) { fprintf(stderr, "ERROR: netlib_get_ipv6addr() failed: %d\n", ret); } else { - ret = addroute(sockfd, &target, &netmask, &router, sizeof(router)); + ret = addroute(sockfd, + (FAR struct sockaddr_storage *)&target, + (FAR struct sockaddr_storage *)&netmask, + (FAR struct sockaddr_storage *)&router); if (ret < 0) { fprintf(stderr, "ERROR: addroute() failed: %d\n", errno); @@ -404,7 +405,9 @@ int main(int argc, FAR char *argv[]) } } - ret = delroute(sockfd, &target, &netmask, sizeof(target)); + ret = delroute(sockfd, + (FAR struct sockaddr_storage *)&target, + (FAR struct sockaddr_storage *)&netmask); if (ret < 0) { fprintf(stderr, "ERROR: delroute() failed: %d\n", errno); diff --git a/examples/mlx90614/CMakeLists.txt b/examples/mlx90614/CMakeLists.txt deleted file mode 100644 index aaa6ea244..000000000 --- a/examples/mlx90614/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# ############################################################################## -# apps/examples/mlx90614/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_MLX90614) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_MLX90614_PROGNAME} - STACKSIZE - ${CONFIG_DEFAULT_TASK_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_MLX90614} - SRCS - mlx90614_main.c) -endif() diff --git a/examples/mlx90614/Kconfig b/examples/mlx90614/Kconfig index f7b510f3e..5ab94a07c 100644 --- a/examples/mlx90614/Kconfig +++ b/examples/mlx90614/Kconfig @@ -6,7 +6,7 @@ config EXAMPLES_MLX90614 tristate "MLX90614 Test Example" default n - select LIBC_FLOATINGPOINT + select LIBC_FLOATINGPOINT ---help--- Enable the MLX90614 example diff --git a/examples/mlx90614/Make.defs b/examples/mlx90614/Make.defs index f0a682e74..6c59d12ff 100644 --- a/examples/mlx90614/Make.defs +++ b/examples/mlx90614/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/mlx90614/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/mlx90614/Makefile b/examples/mlx90614/Makefile index 60ddd79a1..0c7316ca7 100644 --- a/examples/mlx90614/Makefile +++ b/examples/mlx90614/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/mlx90614/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/mlx90614/mlx90614_main.c b/examples/mlx90614/mlx90614_main.c index 0311ceddd..601545211 100644 --- a/examples/mlx90614/mlx90614_main.c +++ b/examples/mlx90614/mlx90614_main.c @@ -1,10 +1,9 @@ /**************************************************************************** * apps/examples/mlx90614/mlx90614_main.c * - * SPDX-License-Identifier: BSD-3-Clause - * SPDX-FileCopyrightText: 2017 Gregory Nutt. All rights reserved. - * SPDX-FileCopyrightText: 2015-2017 Pololu Corporation. - * SPDX-FileContributor: Alan Carvalho de Assis <acassis@gmail.com> + * Copyright (C) 2017 Gregory Nutt. All rights reserved. + * Copyright (c) 2015-2017 Pololu Corporation. + * Author: Alan Carvalho de Assis <acassis@gmail.com> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -48,7 +47,6 @@ #include <fcntl.h> #include <errno.h> #include <stdio.h> -#include <unistd.h> #include <nuttx/sensors/ioctl.h> #include <nuttx/sensors/mlx90614.h> @@ -111,8 +109,7 @@ int main(int argc, FAR char *argv[]) if (buffer[0] != '0' && buffer[1] != 'x') { - fprintf(stderr, - "You need to pass the I2C address in hexa: 0xNN\n"); + fprintf(stderr, "You need to pass the I2C address in hexa: 0xNN\n"); goto out; } @@ -124,13 +121,10 @@ int main(int argc, FAR char *argv[]) goto out; } - ret = ioctl(fd, SNIOC_CHANGE_SMBUSADDR, - (unsigned long)((uintptr_t)&newaddr)); + ret = ioctl(fd, SNIOC_CHANGE_SMBUSADDR, (unsigned long)((uintptr_t)&newaddr)); if (ret < 0) { - fprintf(stderr, - "ERROR: ioctl(SNIOC_CHANGE_SMBUSADDR) failed: %d\n", - errno); + fprintf(stderr, "ERROR: ioctl(SNIOC_CHANGE_SMBUSADDR) failed: %d\n", errno); goto out; } @@ -167,6 +161,7 @@ int main(int argc, FAR char *argv[]) } out: + close(fd); return 0; } diff --git a/examples/mml_parser/CMakeLists.txt b/examples/mml_parser/CMakeLists.txt deleted file mode 100644 index b6792dd7b..000000000 --- a/examples/mml_parser/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# ############################################################################## -# apps/examples/mml_parser/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_MMLPARSER) - nuttx_add_application( - NAME - mmlparser - STACKSIZE - ${CONFIG_DEFAULT_TASK_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_MMLPARSER} - SRCS - mml_parser_main.c) -endif() diff --git a/examples/mml_parser/Kconfig b/examples/mml_parser/Kconfig deleted file mode 100644 index 8ff8c4135..000000000 --- a/examples/mml_parser/Kconfig +++ /dev/null @@ -1,11 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config EXAMPLES_MMLPARSER - tristate "mml_parser example" - default n - ---help--- - Enable the mml_parser example - diff --git a/examples/mml_parser/Make.defs b/examples/mml_parser/Make.defs deleted file mode 100644 index 5f290c70b..000000000 --- a/examples/mml_parser/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/examples/mml_parser/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_EXAMPLES_MMLPARSER),) -CONFIGURED_APPS += $(APPDIR)/examples/mml_parser -endif diff --git a/examples/mml_parser/Makefile b/examples/mml_parser/Makefile deleted file mode 100644 index 796153ed6..000000000 --- a/examples/mml_parser/Makefile +++ /dev/null @@ -1,34 +0,0 @@ -############################################################################ -# apps/examples/mml_parser/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -MAINSRC = mml_parser_main.c - -# application info - -PROGNAME = mmlparser -PRIORITY = SCHED_PRIORITY_DEFAULT -STACKSIZE = $(CONFIG_DEFAULT_TASK_STACKSIZE) -MODULE = $(CONFIG_EXAMPLES_MMLPARSER) - -include $(APPDIR)/Application.mk diff --git a/examples/mml_parser/mml_parser_main.c b/examples/mml_parser/mml_parser_main.c deleted file mode 100644 index 4f4fe9bf2..000000000 --- a/examples/mml_parser/mml_parser_main.c +++ /dev/null @@ -1,197 +0,0 @@ -/**************************************************************************** - * apps/examples/mml_parser/mml_parser_main.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> -#include <stdio.h> - -#ifndef CONFIG_AUDIOUTILS_MMLPARSER_LIB -#error "This example needs to enable config of AUDIOUTILS_MMLPARSER_LIB," \ - " please enable it" -#endif - -#include <audioutils/mml_parser.h> - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -#define SIMPLE_SCORE \ - "O0 CC+DD+EE+FF+GG+AA+BB+" \ - "O1 CC-DD-EE-FF-GG-AA-BB-" \ - "O2 CC#DD#EE#FF#GG#AA#BB#" - -#define TEST_SCORE \ - "T240L0O3D>F+>E8 V8{R [CE O7 < G] C+#- C >B}8 [G B > C]16" \ - "T120 D> C A8 B. A8+4 C+8.D#+4+4 E- C.+4." - -#define FLOH_WALZER_RIGHT \ - "T120 L4 O4" \ - "R8 {D#C#}8" \ - "R8{[<A#>F#][<A#>F#]}{D#C#}8 R8{[<A#>F#][<A#>F#]}{D#C#}8" \ - "R8[<A#>F#]8R8[<A#>F#]8 R8{[<B>F][<B>F]} {D#C#}8" \ - "R8{[<B>F][<B>F]}{D#C#}8 R8{[<B>F][<B>F]}{D#C#}8" \ - "R8[<B>F]8R8[<B>F]8 R8{[<A#>F#][<A#>F#]} {D#C#}8" \ - "R8{[<A#>F#][<A#>F#]}{D#C#}8 R8{[<A#>F#][<A#>F#]}{D#C#}8" \ - "R8[<A#>F#]8R8[<A#>F#]8 R8{[<B>F][<B>F]} {D#C#}8" \ - "R8{[<B>F][<B>F]}{D#C#}8 R8{[<B>F][<B>F]}{D#C#}8" \ - "R8[<B>F]8R8[<B>F]8 R8{[<A#>F#][<A#>F#]} {D#C#}8" \ - "R8[<A#>F#]8R8[<A#>F#]8 R8[<A#>F#]8R8[<A#>F#]8" \ - "R2 R8{[<B>F][<B>F]} {D#C#}8" \ - "R8[<B>F]8R8[<B>F]8 R8[<B>F]8R8[<B>F]8" \ - "R2 R8{[<A#>F#][<A#>F#]} {D#C#}8" \ - "R8{[<A#>F#][<A#>F#]}{D#C#}8 R8{[<A#>F#][<A#>F#]}{D#C#}8" \ - "R8[<A#>F#]8R8[<A#>F#]8 R8{[<B>F][<B>F]} {D#C#}8" \ - "R8{[<B>F][<B>F]}{D#C#}8 R8{[<B>F][<B>F]}{D#C#}8" \ - "R8[<B>F]8R8[<B>F]8 R8{[<A#>F#][<A#>F#]} {D#C#}8" \ - "[<A#>F#]8{CC}8{C#C} R8[<B>F]8[<A#>F#]8R8" - -#define FLOH_WALZER_LEFT \ - "T120 L4 O3" \ - "R4" \ - "F#.R8 F#.R8 F#D# C#.R8" \ - "C#.R8 C#.R8 C#D# F#.R8" \ - ">A#.R8 A#.R8 A#>C# D#.R8" \ - "D#.R8 D#.R8 D#C# <A#.R8" \ - "<F#C# F#C# {F#F}{F#G} G#R" \ - "G#C# G#C# {G#G}{G#A} A#R" \ - "F#.R8 F#.R8 F#D# C#.R8" \ - "C#.R8 C#.R8 C#D# F#.R8" \ - "C#8R8R R8C#8<F#8R8" - -static const char *test_scores[] = -{ - SIMPLE_SCORE, TEST_SCORE, FLOH_WALZER_RIGHT, FLOH_WALZER_LEFT, -}; - -#define TEST_SCORES_NUM (sizeof(test_scores)/sizeof(test_scores[0])) - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: print_parse_result - ****************************************************************************/ - -int print_parse_result(int ret_code, FAR struct mml_result_s *result) -{ - int passed_tick = 0; - - switch (ret_code) - { - case MML_TYPE_NOTE: - printf("Note(%2d) : length = %d\n", - result->note_idx[0], result->length); - passed_tick += result->length; - break; - case MML_TYPE_REST: - printf("Rest : length = %d\n", result->length); - passed_tick += result->length; - break; - case MML_TYPE_TEMPO: - printf("Tempo : length = %d\n", result->length); - break; - case MML_TYPE_LENGTH: - printf("Length : length = %d\n", result->length); - break; - case MML_TYPE_OCTAVE: - printf("Octave : length = %d\n", result->length); - break; - case MML_TYPE_TUPLETSTART: - printf("Tuplet B : length = %d\n", result->length); - break; - case MML_TYPE_TUPLETDONE: - printf("Tuplet D :\n"); - break; - case MML_TYPE_VOLUME: - printf("Volume : length = %d\n", result->length); - break; - case MML_TYPE_CHORD: - printf("Chord : length = %d, chord_num = %d\n", - result->length, result->chord_notes); - printf(" : Notes "); - { - int i; - for (i = 0; i < result->chord_notes; i++) - { - printf("%d ", result->note_idx[i]); - } - - printf("\n"); - } - - passed_tick += result->length; - break; - } - - return passed_tick; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: main - ****************************************************************************/ - -int main(void) -{ - int i; - int ret; - int total_tick; - - FAR char *score; - struct music_macro_lang_s mml; - struct mml_result_s result; - - for (i = 0; i < TEST_SCORES_NUM; i++) - { - init_mml(&mml, 48000, 1, 0, 4); - - score = (char *)test_scores[i]; - printf("===================================\n"); - printf("Test Score :\n%s\n\n", score); - - total_tick = 0; - while ((ret = parse_mml(&mml, &score, &result)) > 0) - { - total_tick += print_parse_result(ret, &result); - } - - if (ret < 0) - { - printf("\nret = %d\n", ret); - printf("Error was occured below:\n"); - printf("%s\n", score); - break; - } - - printf("\n=== Total Tick : %d\n\n", total_tick); - } - - return 0; -} diff --git a/examples/modbus/CMakeLists.txt b/examples/modbus/CMakeLists.txt deleted file mode 100644 index 37104316f..000000000 --- a/examples/modbus/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# ############################################################################## -# apps/examples/modbus/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_MODBUS) - nuttx_add_application( - NAME - modbus - STACKSIZE - ${CONFIG_DEFAULT_TASK_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_MODBUS} - SRCS - modbus_main.c) -endif() diff --git a/examples/modbus/Make.defs b/examples/modbus/Make.defs index 2032f5c26..b44c8b8b8 100644 --- a/examples/modbus/Make.defs +++ b/examples/modbus/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/modbus/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/modbus/Makefile b/examples/modbus/Makefile index 7d7810f07..c792c809b 100644 --- a/examples/modbus/Makefile +++ b/examples/modbus/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/modbus/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/modbus/modbus_main.c b/examples/modbus/modbus_main.c index 7178a458e..59c9cc0a4 100644 --- a/examples/modbus/modbus_main.c +++ b/examples/modbus/modbus_main.c @@ -1,7 +1,5 @@ /**************************************************************************** - * apps/examples/modbus/modbus_main.c - * - * SPDX-License-Identifier: Apache-2.0 + * apps/examples/modbus/main.c * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -51,6 +49,7 @@ #include <string.h> #include <unistd.h> #include <pthread.h> +#include <termios.h> #include <signal.h> #include <errno.h> @@ -68,9 +67,12 @@ /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ - /* Configuration ************************************************************/ +#ifndef CONFIG_SERIAL_TERMIOS +# error "CONFIG_SERIAL_TERMIOS is needed by modbus example" +#endif + #ifndef CONFIG_EXAMPLES_MODBUS_PORT # define CONFIG_EXAMPLES_MODBUS_PORT 0 #endif @@ -125,6 +127,7 @@ struct modbus_state_s #endif pthread_t threadid; pthread_mutex_t lock; + volatile bool quit; }; /**************************************************************************** @@ -141,10 +144,7 @@ static void modbus_showusage(FAR const char *progname, int exitcode); ****************************************************************************/ static struct modbus_state_s g_modbus; -static const uint8_t g_slaveid[] = -{ - 0xaa, 0xbb, 0xcc -}; +static const uint8_t g_slaveid[] = { 0xaa, 0xbb, 0xcc }; /**************************************************************************** * Private Functions @@ -166,7 +166,7 @@ static inline int modbus_initialize(void) /* Verify that we are in the stopped state */ - if (g_modbus.threadstate == RUNNING) + if (g_modbus.threadstate != STOPPED) { fprintf(stderr, "modbus_main: " "ERROR: Bad state: %d\n", g_modbus.threadstate); @@ -195,8 +195,7 @@ static inline int modbus_initialize(void) */ mberr = eMBInit(MB_RTU, 0x0a, CONFIG_EXAMPLES_MODBUS_PORT, - CONFIG_EXAMPLES_MODBUS_BAUD, - CONFIG_EXAMPLES_MODBUS_PARITY); + CONFIG_EXAMPLES_MODBUS_BAUD, CONFIG_EXAMPLES_MODBUS_PARITY); if (mberr != MB_ENOERR) { fprintf(stderr, "modbus_main: " @@ -236,7 +235,6 @@ static inline int modbus_initialize(void) return OK; errout_with_modbus: - /* Release hardware resources. */ eMBClose(); @@ -380,10 +378,9 @@ static inline int modbus_create_pollthread(void) { int ret; - if (g_modbus.threadstate != RUNNING) + if (g_modbus.threadstate == STOPPED) { - ret = pthread_create(&g_modbus.threadid, NULL, - modbus_pollthread, NULL); + ret = pthread_create(&g_modbus.threadid, NULL, modbus_pollthread, NULL); } else { @@ -428,32 +425,30 @@ static void modbus_showusage(FAR const char *progname, int exitcode) int main(int argc, FAR char *argv[]) { - bool quit = true; int option; int ret; /* Handle command line arguments */ + g_modbus.quit = false; + while ((option = getopt(argc, argv, "desqh")) != ERROR) { switch (option) { case 'd': /* Disable protocol stack */ + pthread_mutex_lock(&g_modbus.lock); g_modbus.threadstate = SHUTDOWN; + pthread_mutex_unlock(&g_modbus.lock); break; case 'e': /* Enable the protocol stack */ { - /* Keep running, otherwise the thread will die */ - - quit = false; - ret = modbus_create_pollthread(); if (ret != OK) { fprintf(stderr, "modbus_main: " - "ERROR: modbus_create_pollthread failed: %d\n", - ret); + "ERROR: modbus_create_pollthread failed: %d\n", ret); exit(EXIT_FAILURE); } } @@ -483,6 +478,7 @@ int main(int argc, FAR char *argv[]) break; case 'q': /* Quit application */ + g_modbus.quit = true; pthread_kill(g_modbus.threadid, 9); break; @@ -498,13 +494,6 @@ int main(int argc, FAR char *argv[]) } } - /* Don't exit until the thread finishes */ - - if (!quit) - { - pthread_join(g_modbus.threadid, NULL); - } - return EXIT_SUCCESS; } @@ -551,8 +540,8 @@ eMBErrorCode eMBRegInputCB(uint8_t *buffer, uint16_t address, uint16_t nregs) * ****************************************************************************/ -eMBErrorCode eMBRegHoldingCB(uint8_t *buffer, uint16_t address, - uint16_t nregs, eMBRegisterMode mode) +eMBErrorCode eMBRegHoldingCB(uint8_t *buffer, uint16_t address, uint16_t nregs, + eMBRegisterMode mode) { eMBErrorCode mberr = MB_ENOERR; int index; @@ -566,7 +555,6 @@ eMBErrorCode eMBRegHoldingCB(uint8_t *buffer, uint16_t address, switch (mode) { /* Pass current register values to the protocol stack. */ - case MB_REG_READ: while (nregs > 0) { @@ -608,8 +596,8 @@ eMBErrorCode eMBRegHoldingCB(uint8_t *buffer, uint16_t address, * ****************************************************************************/ -eMBErrorCode eMBRegCoilsCB(uint8_t *buffer, uint16_t address, - uint16_t ncoils, eMBRegisterMode mode) +eMBErrorCode eMBRegCoilsCB(uint8_t *buffer, uint16_t address, uint16_t ncoils, + eMBRegisterMode mode) { eMBErrorCode mberr = MB_ENOERR; int index; @@ -665,8 +653,7 @@ eMBErrorCode eMBRegCoilsCB(uint8_t *buffer, uint16_t address, * ****************************************************************************/ -eMBErrorCode eMBRegDiscreteCB(uint8_t *buffer, uint16_t address, - uint16_t ndiscrete) +eMBErrorCode eMBRegDiscreteCB(uint8_t *buffer, uint16_t address, uint16_t ndiscrete) { return MB_ENOREG; } diff --git a/examples/modbusmaster/CMakeLists.txt b/examples/modbusmaster/CMakeLists.txt deleted file mode 100644 index 3a6043a38..000000000 --- a/examples/modbusmaster/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# ############################################################################## -# apps/examples/modbusmaster/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_MODBUSMASTER) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_MODBUSMASTER_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_MODBUSMASTER_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_MODBUSMASTER_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_MODBUSMASTER} - SRCS - mbmaster_main.c) -endif() diff --git a/examples/modbusmaster/Make.defs b/examples/modbusmaster/Make.defs index bcdef99c5..e90c3d1ec 100644 --- a/examples/modbusmaster/Make.defs +++ b/examples/modbusmaster/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/modbusmaster/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/modbusmaster/Makefile b/examples/modbusmaster/Makefile index fc93c00ce..188a70e55 100644 --- a/examples/modbusmaster/Makefile +++ b/examples/modbusmaster/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/modbusmaster/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/modbusmaster/mbmaster_main.c b/examples/modbusmaster/mbmaster_main.c index 2c369dd35..867daf71e 100644 --- a/examples/modbusmaster/mbmaster_main.c +++ b/examples/modbusmaster/mbmaster_main.c @@ -1,9 +1,9 @@ /**************************************************************************** * apps/examples/modbusmaster/mbmaster_main.c * - * SPDX-License-Identifier: BSD-3-Clause - * SPDX-FileCopyrightText: 2016 Vytautas Lukenskas <lukevyta@gmail.com> - * SPDX-FileCopyrightText: 2019 Alan Carvalho de Assis <acassis@gmail.com> + * Copyright (c) 2016 Vytautas Lukenskas <lukevyta@gmail.com> + * Copyright (c) 2019 Alan Carvalho de Assis <acassis@gmail.com> + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -50,6 +50,10 @@ /* modbus master port */ +#ifndef CONFIG_SERIAL_TERMIOS +# error "CONFIG_SERIAL_TERMIOS is needed by modbus example" +#endif + #ifdef CONFIG_EXAMPLES_MODBUSMASTER_PORT # define MBMASTER_PORT CONFIG_EXAMPLES_MODBUSMASTER_PORT #else @@ -280,7 +284,7 @@ int main(int argc, FAR char *argv[]) if (ret != OK) { - fprintf(stderr, "mbmaster_main: " + fprintf(stderr, "mbmaster_main: ", "ERROR: mbmaster_initialize failed: %d\n", ret); goto errout; } @@ -292,15 +296,11 @@ int main(int argc, FAR char *argv[]) if (ret != OK) { - fprintf(stderr, "mbmaster_main: " + fprintf(stderr, "mbmaster_main: ", "ERROR: mbmaster_pollthread create failed: %d\n", ret); goto errout_with_initialize; } - /* Work around to give time to pthread_create run the modbus poller */ - - usleep(100000); - printf("Sending %d requests to slave %d\n", MBMASTER_REQUESTS_COUNT, SLAVE_ID); diff --git a/examples/module/.gitignore b/examples/module/.gitignore deleted file mode 100644 index 8e29db973..000000000 --- a/examples/module/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/Kconfig -lib/ diff --git a/examples/module/CMakeLists.txt b/examples/module/CMakeLists.txt deleted file mode 100644 index 77e6b30aa..000000000 --- a/examples/module/CMakeLists.txt +++ /dev/null @@ -1,24 +0,0 @@ -# ############################################################################## -# apps/examples/module/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -nuttx_add_subdirectory() -nuttx_generate_kconfig(MENUDESC "Module") diff --git a/examples/module/main/Kconfig b/examples/module/Kconfig similarity index 95% rename from examples/module/main/Kconfig rename to examples/module/Kconfig index b3a8889e6..d51461d8d 100644 --- a/examples/module/main/Kconfig +++ b/examples/module/Kconfig @@ -8,7 +8,6 @@ config EXAMPLES_MODULE default n depends on MODULE && BOARDCTL select BOARDCTL_OS_SYMTAB - select MODULES ---help--- Enable the module example @@ -115,14 +114,6 @@ config EXAMPLES_MODULE_BINDIR The full, absolute path to the location for the binaries can be located in a pre-mounted external file system. -config EXAMPLES_MODULE_FSDATA - string "Additional data passed to mount" - default "" - depends on EXAMPLES_MODULE_FSMOUNT - ---help--- - Additional data needed by mount. For example, when hostfs - is used, this can be "fs=../apps/bin" - config EXAMPLES_MODULE_LIBC bool "Link with LIBC" default n diff --git a/examples/module/Make.defs b/examples/module/Make.defs index 2e99fa3b5..6729d9c24 100644 --- a/examples/module/Make.defs +++ b/examples/module/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/module/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -20,4 +18,6 @@ # ############################################################################ -include $(wildcard $(APPDIR)/examples/module/*/Make.defs) +ifneq ($(CONFIG_EXAMPLES_MODULE),) +CONFIGURED_APPS += $(APPDIR)/examples/module +endif diff --git a/examples/module/Makefile b/examples/module/Makefile index ca547c70d..3b6c8a9f8 100644 --- a/examples/module/Makefile +++ b/examples/module/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/module/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -20,6 +18,44 @@ # ############################################################################ -MENUDESC = "Module example" +include $(APPDIR)/Make.defs -include $(APPDIR)/Directory.mk +# Module example built-in application info + +PROGNAME = module +PRIORITY = SCHED_PRIORITY_DEFAULT +STACKSIZE = $(CONFIG_DEFAULT_TASK_STACKSIZE) +MODULE = $(CONFIG_EXAMPLES_MODULE) + +# Module Example + +ifeq ($(CONFIG_EXAMPLES_MODULE_ROMFS),y) +CSRCS = romfs.c +endif +ifeq ($(CONFIG_EXAMPLES_MODULE_CROMFS),y) +CSRCS = cromfs.c +endif +CSRCS += mod_symtab.c +MAINSRC = module_main.c + +VPATH += drivers +DEPPATH += --dep-path drivers + +# Build targets + +ifeq ($(CONFIG_EXAMPLES_MODULE_ROMFS),y) +drivers/romfs.c: build +endif +ifeq ($(CONFIG_EXAMPLES_MODULE_CROMFS),y) +drivers/cromfs.c: build +endif +drivers/mod_symtab.c: build + +.PHONY: build +build: + +$(Q) $(MAKE) -C drivers TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)" CROSSDEV=$(CROSSDEV) + +clean:: + +$(Q) $(MAKE) -C drivers TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)" CROSSDEV=$(CROSSDEV) clean + +include $(APPDIR)/Application.mk diff --git a/examples/module/chardev/.gitignore b/examples/module/chardev/.gitignore deleted file mode 100644 index c7de605bd..000000000 --- a/examples/module/chardev/.gitignore +++ /dev/null @@ -1 +0,0 @@ -*.map diff --git a/examples/module/chardev/Kconfig b/examples/module/chardev/Kconfig deleted file mode 100644 index f72f3c094..000000000 --- a/examples/module/chardev/Kconfig +++ /dev/null @@ -1,4 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# diff --git a/examples/module/chardev/Make.defs b/examples/module/chardev/Make.defs deleted file mode 100644 index 71ed9fb3a..000000000 --- a/examples/module/chardev/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/examples/module/chardev/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_EXAMPLES_MODULE),) -CONFIGURED_APPS += $(APPDIR)/examples/module/chardev -endif diff --git a/examples/module/chardev/Makefile b/examples/module/chardev/Makefile deleted file mode 100644 index 94d56ed87..000000000 --- a/examples/module/chardev/Makefile +++ /dev/null @@ -1,30 +0,0 @@ -############################################################################ -# apps/examples/module/chardev/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -PROGNAME = chardev -DYNLIB = y - -MAINSRC = chardev.c - -include $(APPDIR)/Application.mk diff --git a/examples/module/drivers/.gitignore b/examples/module/drivers/.gitignore new file mode 100644 index 000000000..922cf8961 --- /dev/null +++ b/examples/module/drivers/.gitignore @@ -0,0 +1,5 @@ +/fsroot +/romfs.c +/cromfs.c +/romfs.img +/mod_symtab.c diff --git a/examples/module/drivers/Makefile b/examples/module/drivers/Makefile new file mode 100644 index 000000000..248067f18 --- /dev/null +++ b/examples/module/drivers/Makefile @@ -0,0 +1,110 @@ +############################################################################ +# apps/examples/module/drivers/Makefile +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. The +# ASF licenses this file to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance with the +# License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +############################################################################ + +include $(APPDIR)/Make.defs + +ALL_SUBDIRS = chardev +BUILD_SUBDIRS = chardev +FSIMG_SUBDIR = fsroot + +MODULE_DIR = $(APPDIR)/examples/module +DRIVER_DIR = $(MODULE_DIR)/drivers +FSROOT_DIR = $(DRIVER_DIR)/fsroot +SYMTAB_SRC = $(DRIVER_DIR)/mod_symtab.c + +ifneq ($(CONFIG_BUILD_FLAT),y) + PASS1_SYMTAB = $(TOPDIR)/pass1/mod_symtab.c +endif + +ifeq ($(CONFIG_EXAMPLES_MODULE_BUILTINFS),y) +ifeq ($(CONFIG_EXAMPLES_MODULE_ROMFS),y) + ROMFS_IMG = $(DRIVER_DIR)/romfs.img + FSIMG_SRC = $(DRIVER_DIR)/romfs.c +else ifeq ($(CONFIG_EXAMPLES_MODULE_CROMFS),y) + NXTOOLDIR = $(TOPDIR)/tools + GENCROMFSSRC = gencromfs.c + GENCROMFSEXE = gencromfs$(HOSTEXEEXT) + + FSIMG_SRC = $(DRIVER_DIR)/cromfs.c +endif +endif + +define DIR_template +$(1)_$(2): + +$(Q) $(MAKE) -C $(1) $(2) TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)" FSROOT_DIR="$(FSROOT_DIR)" CROSSDEV=$(CROSSDEV) +endef + +all: $(FSIMG_SRC) $(SYMTAB_SRC) $(PASS1_SYMTAB) +.PHONY: all clean install + +$(foreach DIR, $(ALL_SUBDIRS), $(eval $(call DIR_template,$(DIR),clean))) +$(foreach DIR, $(BUILD_SUBDIRS), $(eval $(call DIR_template,$(DIR),install))) + +# Install each program in the fsroot directory + +install: $(foreach DIR, $(BUILD_SUBDIRS), $(DIR)_install) + +ifeq ($(CONFIG_EXAMPLES_MODULE_BUILTINFS),y) +ifeq ($(CONFIG_EXAMPLES_MODULE_ROMFS),y) +# Create the romfs.img file from the populated fsroot directory + +$(ROMFS_IMG): install + $(Q) genromfs -f $@.tmp -d $(FSROOT_DIR) -V "MODULETEST" + $(Q) $(call TESTANDREPLACEFILE, $@.tmp, $@) + +# Create the romfs.c file from the romfs.img file + +$(FSIMG_SRC): $(ROMFS_IMG) + $(Q) (cd $(DRIVER_DIR) && echo "#include <nuttx/compiler.h>" >$@ && \ + xxd -i romfs.img | sed -e "s/^unsigned char/const unsigned char aligned_data(4)/g" >>$@) + +else ifeq ($(CONFIG_EXAMPLES_MODULE_CROMFS),y) +# Make sure that the NuttX gencromfs tool has been built + +$(NXTOOLDIR)/$(GENCROMFSEXE): $(NXTOOLDIR)/$(GENCROMFSSRC) + $(Q) $(MAKE) -C $(NXTOOLDIR) -f Makefile.host $(GENCROMFSEXE) + +# Create the cromfs.c file from the populated cromfs directory + +$(FSIMG_SRC): install $(NXTOOLDIR)/$(GENCROMFSEXE) + $(Q) $(NXTOOLDIR)/$(GENCROMFSEXE) $(FSIMG_DIR) $@.tmp + $(Q) $(call TESTANDREPLACEFILE, $@.tmp, $@) + +endif +endif + +# Create the exported symbol table + +$(SYMTAB_SRC): install + $(Q) $(APPDIR)$(DELIM)tools$(DELIM)mksymtab.sh $(FSROOT_DIR) g_mod >$@.tmp + $(Q) $(call TESTANDREPLACEFILE, $@.tmp, $@) + +# Copy the symbol table into the kernel pass1/ build directory + +ifneq ($(CONFIG_BUILD_FLAT),y) +$(PASS1_SYMTAB): $(SYMTAB_SRC) + $(Q) install -m 0644 $(SYMTAB_SRC) $(PASS1_SYMTAB) +endif + +# Clean each subdirectory + +clean: $(foreach DIR, $(ALL_SUBDIRS), $(DIR)_clean) + $(Q) rm -f $(FSIMG_SRC) $(ROMFS_IMG) $(SYMTAB_SRC) + $(Q) rm -rf $(FSROOT_DIR) diff --git a/examples/module/drivers/chardev/.gitignore b/examples/module/drivers/chardev/.gitignore new file mode 100644 index 000000000..c28dc954f --- /dev/null +++ b/examples/module/drivers/chardev/.gitignore @@ -0,0 +1 @@ +/chardev diff --git a/examples/module/drivers/chardev/Makefile b/examples/module/drivers/chardev/Makefile new file mode 100644 index 000000000..abf530f58 --- /dev/null +++ b/examples/module/drivers/chardev/Makefile @@ -0,0 +1,73 @@ +############################################################################ +# apps/examples/module/drivers/chardev/Makefile +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. The +# ASF licenses this file to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance with the +# License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +############################################################################ + +include $(APPDIR)/Make.defs + +CMODULEFLAGS += $(KDEFINE) + +ifeq ($(CONFIG_EXAMPLES_MODULE_LIBGCC),y) +LIBGCC = "${shell $(CC) $(ARCHCPUFLAGS) -print-libgcc-file-name 2>/dev/null}" +ifneq ($(LIBGCC),) + LDLIBPATH += -L "${shell dirname $(LIBGCC)}" + LDLIBS += -lgcc +endif +endif + +ifeq ($(CONFIG_EXAMPLES_MODULE_LIBC),y) +LDMODULEFLAGS += -Bstatic +LDLIBPATH += -L $(NUTTXLIB) +endif + +ifeq ($(CONFIG_EXAMPLES_MODULE_LIBC),y) +ifneq ($(CONFIG_BUILD_FLAT),y) +LDLIBS += -lkc +else +LDLIBS += -lc +endif +endif + +BIN = chardev + +SRCS = $(BIN).c +OBJS = $(SRCS:.c=$(OBJEXT)) + +all: $(BIN) +.PHONY: all clean install + +$(OBJS): %$(OBJEXT): %.c + @echo "MODULECC: $<" + $(Q) $(MODULECC) -c $(CMODULEFLAGS) $< -o $@ + +$(BIN): $(OBJS) + @echo "MODULELD: $<" + $(Q) $(MODULELD) $(LDMODULEFLAGS) $(LDLIBPATH) -o $@ $(ARCHCRT0OBJ) $^ $(LDLIBS) + +$(FSROOT_DIR)/$(BIN): $(BIN) + $(Q) mkdir -p $(FSROOT_DIR) + $(Q) install $(BIN) $(FSROOT_DIR)/$(BIN) +ifneq ($(CONFIG_DEBUG_SYMBOLS),y) + $(Q) $(MODULESTRIP) $(FSROOT_DIR)/$(BIN) +endif + +install: $(FSROOT_DIR)/$(BIN) + +clean: + $(call DELFILE, $(BIN)) + $(call CLEAN) diff --git a/examples/module/chardev/chardev.c b/examples/module/drivers/chardev/chardev.c similarity index 78% rename from examples/module/chardev/chardev.c rename to examples/module/drivers/chardev/chardev.c index b2fd7b61d..2bea20fb1 100644 --- a/examples/module/chardev/chardev.c +++ b/examples/module/drivers/chardev/chardev.c @@ -1,7 +1,5 @@ /**************************************************************************** - * apps/examples/module/chardev/chardev.c - * - * SPDX-License-Identifier: Apache-2.0 + * apps/examples/module/drivers/chardev/chardev.c * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -26,18 +24,25 @@ #include <nuttx/config.h> -#include <sys/param.h> #include <sys/types.h> #include <stdbool.h> #include <string.h> #include <errno.h> #include <syslog.h> -#include <nuttx/debug.h> +#include <debug.h> #include <nuttx/module.h> -#include <nuttx/lib/elf.h> +#include <nuttx/lib/modlib.h> #include <nuttx/fs/fs.h> +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#ifndef MIN +# define MIN(a,b) ((a) < (b) ? (a) : (b)) +#endif + /**************************************************************************** * Private data ****************************************************************************/ @@ -57,12 +62,18 @@ static ssize_t chardev_write(FAR struct file *filep, FAR const char *buffer, * Private Data ****************************************************************************/ -static const struct file_operations g_chardev_fops = +static const struct file_operations chardev_fops = { NULL, /* open */ NULL, /* close */ chardev_read, /* read */ chardev_write, /* write */ + NULL, /* seek */ + NULL, /* ioctl */ + NULL /* poll */ +#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS + , NULL /* unlink */ +#endif }; /**************************************************************************** @@ -82,8 +93,7 @@ static ssize_t chardev_read(FAR struct file *filep, FAR char *buffer, memcpy(buffer, g_read_string, ret); syslog(LOG_INFO, "chardev_read: Returning %d bytes\n", (int)ret); - lib_dumpbuffer("chardev_read: Returning", - (FAR const uint8_t *)buffer, ret); + lib_dumpbuffer("chardev_read: Returning", (FAR const uint8_t *)buffer, ret); return ret; } @@ -103,12 +113,12 @@ static ssize_t chardev_write(FAR struct file *filep, FAR const char *buffer, * Name: module_uninitialize ****************************************************************************/ -destructor_function void module_uninitialize(void) +static int module_uninitialize(FAR void *arg) { /* TODO: Check if there are any open references to the driver */ - syslog(LOG_INFO, "module_uninitialize\n"); - unregister_driver("/dev/chardev"); + syslog(LOG_INFO, "module_uninitialize: arg=%p\n", arg); + return unregister_driver("/dev/chardev"); } /**************************************************************************** @@ -123,8 +133,14 @@ destructor_function void module_uninitialize(void) * ****************************************************************************/ -constructor_fuction void module_initialize(void) +int module_initialize(FAR struct mod_info_s *modinfo) { - syslog(LOG_INFO, "module_initialize\n"); - register_driver("/dev/chardev", &g_chardev_fops, 0666, NULL); + syslog(LOG_INFO, "module_initialize:\n"); + + modinfo->uninitializer = module_uninitialize; + modinfo->arg = NULL; + modinfo->exports = NULL; + modinfo->nexports = 0; + + return register_driver("/dev/chardev", &chardev_fops, 0666, NULL); } diff --git a/examples/module/main/.gitignore b/examples/module/main/.gitignore deleted file mode 100644 index a23661bdf..000000000 --- a/examples/module/main/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/chardev_romfs.c -/chardev_romfs.img -/cromfs.c -/chardev_mod_symtab.c -/mod_symtab.c -/chardev diff --git a/examples/module/main/CMakeLists.txt b/examples/module/main/CMakeLists.txt deleted file mode 100644 index 8036a7c87..000000000 --- a/examples/module/main/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -# ############################################################################## -# apps/examples/module/main/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_MODULE) - nuttx_add_application(NAME module) -endif() diff --git a/examples/module/main/Make.defs b/examples/module/main/Make.defs deleted file mode 100644 index 7e049406d..000000000 --- a/examples/module/main/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/examples/module/main/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_EXAMPLES_MODULE),) -CONFIGURED_APPS += $(APPDIR)/examples/module/main -endif diff --git a/examples/module/main/Makefile b/examples/module/main/Makefile deleted file mode 100644 index 466af6dbf..000000000 --- a/examples/module/main/Makefile +++ /dev/null @@ -1,106 +0,0 @@ -############################################################################ -# apps/examples/module/main/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -# Module example built-in application info - -PROGNAME = module -PRIORITY = SCHED_PRIORITY_DEFAULT -STACKSIZE = $(CONFIG_DEFAULT_TASK_STACKSIZE) -MODULE = $(CONFIG_EXAMPLES_MODULE) - -MAINSRC = module_main.c - -SYMTABSRC = mod_symtab.c -SYMTABOBJ = $(SYMTABSRC:.c=$(OBJEXT)) - -MODLUE_NAME = chardev -ifneq ($(CONFIG_BUILD_FLAT),y) - PASS1_SYMTAB = $(TOPDIR)/pass1/mod_symtab.c -endif - -$(SYMTABSRC): - $(Q) $(APPDIR)$(DELIM)tools$(DELIM)mksymtab.sh $(BINDIR)$(DELIM)$(MODLUE_NAME) g_mod >$@.tmp - $(Q) $(call TESTANDREPLACEFILE, $@.tmp, $@) - - -$(SYMTABOBJ): %$(OBJEXT): %.c - $(call COMPILE, $<, $@, -fno-lto -fno-builtin) - -ifeq ($(CONFIG_EXAMPLES_MODULE_BUILTINFS),y) -ifeq ($(CONFIG_EXAMPLES_MODULE_ROMFS),y) - -ROMFSIMG = chardev_romfs.img -ROMFSSRC = chardev_romfs.c -ROMFSOBJ = $(ROMFSSRC:.c=$(OBJEXT)) - -$(ROMFSIMG): - $(Q) genromfs -d $(BINDIR) -f $@ - -$(ROMFSSRC): $(ROMFSIMG) - $(Q) (echo "#include <nuttx/compiler.h>" >$@ && \ - xxd -i $(ROMFSIMG) | sed -e "s/^unsigned char/const unsigned char aligned_data(4)/g" >>$@) - -$(ROMFSOBJ): %$(OBJEXT): %.c - $(call COMPILE, $<, $@, -fno-lto -fno-builtin) - -else ifeq ($(CONFIG_EXAMPLES_MODULE_CROMFS),y) - NXTOOLDIR = $(TOPDIR)/tools - GENCROMFSSRC = gencromfs.c - GENCROMFSEXE = gencromfs$(HOSTEXEEXT) - - FSIMG_SRC = cromfs.c - FSIMG_OBJ = $(FSIMG_SRC:.c=$(OBJEXT)) - -$(NXTOOLDIR)/$(GENCROMFSEXE): $(NXTOOLDIR)/$(GENCROMFSSRC) - $(Q) $(MAKE) -C $(NXTOOLDIR) -f Makefile.host $(GENCROMFSEXE) - -# Create the cromfs.c file from the populated cromfs directory - -$(FSIMG_SRC):$(NXTOOLDIR)/$(GENCROMFSEXE) - $(Q) $(NXTOOLDIR)/$(GENCROMFSEXE) $(BINDIR) $@.tmp - $(Q) $(call TESTANDREPLACEFILE, $@.tmp, $@) - -$(FSIMG_OBJ): %$(OBJEXT): %.c - $(call COMPILE, $<, $@, -fno-lto -fno-builtin) - -endif - -endif - -# Copy the symbol table into the kernel pass1/ build directory - -ifneq ($(CONFIG_BUILD_FLAT),y) -$(PASS1_SYMTAB): $(SYMTABSRC) - $(Q) install -m 0644 $(SYMTABSRC) $(PASS1_SYMTAB) - $(Q) mv $(BINDIR)$(DELIM)$(MODLUE_NAME) . -endif - -postinstall:: $(ROMFSOBJ) $(SYMTABOBJ) $(FSIMG_OBJ) $(PASS1_SYMTAB) - $(call ARLOCK, $(call CONVERT_PATH,$(BIN)), $^) - -distclean:: - $(Q) $(call DELFILE, $(SYMTABSRC) $(SYMTABOBJ) $(ROMFSSRC) $(ROMFSIMG) $(ROMFSOBJ) $(MODLUE_NAME)) - - -include $(APPDIR)/Application.mk diff --git a/examples/module/main/module_main.c b/examples/module/module_main.c similarity index 95% rename from examples/module/main/module_main.c rename to examples/module/module_main.c index 9eb9b205e..0b940bc6c 100644 --- a/examples/module/main/module_main.c +++ b/examples/module/module_main.c @@ -1,7 +1,5 @@ /**************************************************************************** - * apps/examples/module/main/module_main.c - * - * SPDX-License-Identifier: Apache-2.0 + * apps/examples/module/module_main.c * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -36,9 +34,10 @@ #include <string.h> #include <unistd.h> #include <fcntl.h> +#include <string.h> #include <syslog.h> #include <errno.h> -#include <nuttx/debug.h> +#include <debug.h> #include <nuttx/module.h> #include <nuttx/symtab.h> @@ -115,8 +114,8 @@ static const char g_write_string[] = "Hi there installed driver\n"; ****************************************************************************/ #if defined(CONFIG_EXAMPLES_MODULE_ROMFS) || defined(CONFIG_EXAMPLES_MODULE_CROMFS) -extern const unsigned char chardev_romfs_img[]; -extern const unsigned int chardev_romfs_img_len; +extern const unsigned char romfs_img[]; +extern const unsigned int romfs_img_len; #endif #ifdef CONFIG_BUILD_FLAT @@ -154,7 +153,7 @@ int main(int argc, FAR char *argv[]) #ifdef CONFIG_BUILD_FLAT /* Set the OS symbol table indirectly through the boardctl() */ - symdesc.symtab = g_mod_exports; + symdesc.symtab = (FAR struct symtab_s *)g_mod_exports; symdesc.nsymbols = g_mod_nexports; ret = boardctl(BOARDIOC_OS_SYMTAB, (uintptr_t)&symdesc); if (ret < 0) @@ -173,9 +172,9 @@ int main(int argc, FAR char *argv[]) CONFIG_EXAMPLES_MODULE_DEVMINOR); desc.minor = CONFIG_EXAMPLES_MODULE_DEVMINOR; /* Minor device number of the ROM disk. */ - desc.nsectors = NSECTORS(chardev_romfs_img_len); /* The number of sectors in the ROM disk */ + desc.nsectors = NSECTORS(romfs_img_len); /* The number of sectors in the ROM disk */ desc.sectsize = SECTORSIZE; /* The size of one sector in bytes */ - desc.image = (FAR uint8_t *)chardev_romfs_img; /* File system image */ + desc.image = (FAR uint8_t *)romfs_img; /* File system image */ ret = boardctl(BOARDIOC_ROMDISK, (uintptr_t)&desc); if (ret < 0) @@ -253,8 +252,7 @@ int main(int argc, FAR char *argv[]) CONFIG_EXAMPLES_MODULE_FSTYPE, MOUNTPT); ret = mount(CONFIG_EXAMPLES_MODULE_DEVPATH, MOUNTPT, - CONFIG_EXAMPLES_MODULE_FSTYPE, MS_RDONLY, - CONFIG_EXAMPLES_MODULE_FSDATA); + CONFIG_EXAMPLES_MODULE_FSTYPE, MS_RDONLY, NULL); if (ret < 0) { printf("ERROR: mount(%s, %s, %s) failed: %d\n", diff --git a/examples/mount/CMakeLists.txt b/examples/mount/CMakeLists.txt deleted file mode 100644 index 9c7e5b03c..000000000 --- a/examples/mount/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# ############################################################################## -# apps/examples/mount/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_MOUNT) - nuttx_add_application( - NAME - mount - SRCS - mount_main.c - STACKSIZE - ${CONFIG_DEFAULT_TASK_STACKSIZE}) - - target_sources(apps PRIVATE ramdisk.c) -endif() diff --git a/examples/mount/Make.defs b/examples/mount/Make.defs index eed839585..998094833 100644 --- a/examples/mount/Make.defs +++ b/examples/mount/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/mount/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/mount/Makefile b/examples/mount/Makefile index 197c6b004..652f2d302 100644 --- a/examples/mount/Makefile +++ b/examples/mount/Makefile @@ -1,7 +1,5 @@ ############################################################################ -# apps/examples/mount/Makefile -# -# SPDX-License-Identifier: Apache-2.0 +# apps/Makefile # # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with diff --git a/examples/mount/mount.h b/examples/mount/mount.h index 4697ec2a3..a1ac41212 100644 --- a/examples/mount/mount.h +++ b/examples/mount/mount.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/mount/mount.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/mount/mount_main.c b/examples/mount/mount_main.c index e42f0d88b..510e5bb9d 100644 --- a/examples/mount/mount_main.c +++ b/examples/mount/mount_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/mount/mount_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -180,7 +178,7 @@ static void show_statfs(const char *path) } } #else -# define show_statfs(p) +# define show_statfs(p) #endif /**************************************************************************** @@ -214,16 +212,8 @@ static void show_directories(const char *path, int indent) { char *subdir; printf("%s/\n", direntry->d_name); - snprintf(g_namebuffer, sizeof(g_namebuffer), - "%s/%s", path, direntry->d_name); + sprintf(g_namebuffer, "%s/%s", path, direntry->d_name); subdir = strdup(g_namebuffer); - if (subdir == NULL) - { - printf("show_directories: ERROR out of memory\n"); - g_nerrors++; - continue; - } - show_directories(subdir, indent + 1); free(subdir); } @@ -236,7 +226,7 @@ static void show_directories(const char *path, int indent) closedir(dirp); } #else -# define show_directories(p,i) +# define show_directories(p,i) #endif /**************************************************************************** @@ -567,7 +557,7 @@ static void fail_stat(const char *path, int expectederror) } } #else -# define fail_stat(p,e); +# define fail_stat(p,e); #endif /**************************************************************************** @@ -609,7 +599,7 @@ static void succeed_stat(const char *path) int main(int argc, FAR char *argv[]) { - int ret; + int ret; #ifndef CONFIG_EXAMPLES_MOUNT_DEVNAME /* Create a RAM disk for the test */ diff --git a/examples/mount/ramdisk.c b/examples/mount/ramdisk.c index 11b29130a..f732c2834 100644 --- a/examples/mount/ramdisk.c +++ b/examples/mount/ramdisk.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/mount/ramdisk.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -97,8 +95,8 @@ int create_ramdisk(void) ret = mkfatfs(g_source, &g_fmt); if (ret < 0) { - printf("create_ramdisk: Failed to create FAT filesystem on " - "ramdisk at %s\n", g_source); + printf("create_ramdisk: Failed to create FAT filesystem on ramdisk at %s\n", + g_source); return ret; } diff --git a/examples/mqttc/CMakeLists.txt b/examples/mqttc/CMakeLists.txt deleted file mode 100644 index 6e4ee010a..000000000 --- a/examples/mqttc/CMakeLists.txt +++ /dev/null @@ -1,45 +0,0 @@ -# ############################################################################## -# apps/examples/mqttc/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_MQTTC) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_MQTTC_PUB_PROGNAME} - STACKSIZE - ${CONFIG_EXAMPLES_MQTTC_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_MQTTC} - SRCS - mqttc_pub.c) - - if(CONFIG_EXAMPLES_MQTTC_SUB) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_MQTTC_SUB_PROGNAME} - STACKSIZE - ${CONFIG_EXAMPLES_MQTTC_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_MQTTC} - SRCS - mqttc_sub.c) - endif() -endif() diff --git a/examples/mqttc/Kconfig b/examples/mqttc/Kconfig index 61a2e6ba1..279378da7 100644 --- a/examples/mqttc/Kconfig +++ b/examples/mqttc/Kconfig @@ -6,7 +6,7 @@ config EXAMPLES_MQTTC tristate "Enable MQTT-C Example" default n - depends on NETUTILS_MQTTC + depends on NETUTILS_MQTTC ---help--- Enable a simple MQTT-C publisher example @@ -16,17 +16,6 @@ config EXAMPLES_MQTTC_PROGNAME string "Program name" default "mqttc_pub" -config EXAMPLES_MQTTC_SUB - bool "Enable MQTT-C Subscriber Client" - default n - ---help--- - Enable a simple MQTT-C subscriber example alongside publisher - -config EXAMPLES_MQTTC_SUB_PROGNAME - string "Subscriber program name" - default "mqttc_sub" - depends on EXAMPLES_MQTTC_SUB - config EXAMPLES_MQTTC_STACKSIZE int "Task's stack size" default 8192 @@ -39,25 +28,4 @@ config EXAMPLES_MQTTC_RXSIZE int "RX Buffer size" default 256 -config MQTT_USE_MBEDTLS - bool - default n - -config EXAMPLES_MQTTC_MBEDTLS - bool "Enable MQTT over TLS (mbedTLS)" - default n - depends on NETUTILS_MQTTC_WITH_MBEDTLS - select MQTT_USE_MBEDTLS - ---help--- - Enable TLS/SSL support for MQTT connections using mbedTLS. - Requires NETUTILS_MQTTC_WITH_MBEDTLS to be enabled. - -config EXAMPLES_MQTTC_ALLOW_UNVERIFIED_TLS - bool "Allow unverified TLS" - default n - ---help--- - Do not fail TLS connection if certificate verification fails. Usually - this is useful during development when connection to server with - self-signed certificates - endif diff --git a/examples/mqttc/Make.defs b/examples/mqttc/Make.defs index 87bb64530..80ed6a46a 100644 --- a/examples/mqttc/Make.defs +++ b/examples/mqttc/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/mqttc/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/mqttc/Makefile b/examples/mqttc/Makefile index 45a2d9f04..5c844c09c 100644 --- a/examples/mqttc/Makefile +++ b/examples/mqttc/Makefile @@ -1,44 +1,12 @@ -############################################################################ -# apps/examples/mqttc/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - include $(APPDIR)/Make.defs PROGNAME = $(CONFIG_EXAMPLES_MQTTC_PROGNAME) PRIORITY = SCHED_PRIORITY_DEFAULT STACKSIZE = $(CONFIG_EXAMPLES_MQTTC_STACKSIZE) - -ifeq ($(CONFIG_EXAMPLES_MQTTC_SUB),y) - PROGNAME += $(CONFIG_EXAMPLES_MQTTC_SUB_PROGNAME) - PRIORITY += SCHED_PRIORITY_DEFAULT - STACKSIZE += $(CONFIG_EXAMPLES_MQTTC_STACKSIZE) -endif - MODULE = $(CONFIG_EXAMPLES_MQTTC) # MQTT-C example source code MAINSRC = mqttc_pub.c -ifeq ($(CONFIG_EXAMPLES_MQTTC_SUB), y) - MAINSRC += mqttc_sub.c -endif include $(APPDIR)/Application.mk diff --git a/examples/mqttc/README.md b/examples/mqttc/README.md new file mode 100644 index 000000000..28f562a0f --- /dev/null +++ b/examples/mqttc/README.md @@ -0,0 +1,25 @@ +This is a simple MQTT publisher example using MQTT-C + +By default it publishes to the "test" topic and exits. Default behaviour +including, host, port, topic, message and loop count can be changed through +different arguments. + +To test: +From the host start an MQTT broker and subscribe to the "test" topic. Here +mosquitto is used: + +``` +mosquitto& +mosquitto_sub -t test +``` +Make sure that mosquitto is not configured in local mode only. + +From the nsh: + +Launch the built-in app `mqttc_pub` specifying the host: + +``` +mqttc_pub -h HOST +``` + +The target will publish the message "test". diff --git a/examples/mqttc/cert.inc b/examples/mqttc/cert.inc deleted file mode 100644 index 542602db5..000000000 --- a/examples/mqttc/cert.inc +++ /dev/null @@ -1,30 +0,0 @@ -/* Broker CA certificate (PEM), embedded in the firmware so the subscriber - * can authenticate the broker without copying a certificate file onto the - * board. - * Replace the body below if the broker's CA changes; init_conn() parses - * it whenever no CA file is supplied on the command line via -c. - */ - -# define TEST_CA_CRT_RSA_SHA256_PEM \ - "-----BEGIN CERTIFICATE-----\r\n" \ - "MIIDYTCCAkmgAwIBAgIUAk1VwJ7il2775wUnEgBZSvW77dUwDQYJKoZIhvcNAQEL\r\n" \ - "BQAwQDELMAkGA1UEBhMCUk8xEjAQBgNVBAgMCUJ1Y2hhcmVzdDEOMAwGA1UECgwF\r\n" \ - "TXlPcmcxDTALBgNVBAMMBE15Q0EwHhcNMjYwNjA5MDA0MjExWhcNMzYwNjA2MDA0\r\n" \ - "MjExWjBAMQswCQYDVQQGEwJSTzESMBAGA1UECAwJQnVjaGFyZXN0MQ4wDAYDVQQK\r\n" \ - "DAVNeU9yZzENMAsGA1UEAwwETXlDQTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCC\r\n" \ - "AQoCggEBAMGfLamBuio0mYqL8TDLqcxqCDhELmrmYxccz8/BAJ3xG0bbqAg0o2CM\r\n" \ - "2nUcDWeDTTOFTEAOVKhqqbu7jzQA+/XRQaptYAzt13N0pMUFlKZQ0QVefAH11mph\r\n" \ - "M2u0exWZObRQxUyfzzJG1UZQ4xGqXUekg+2LMSS09g/QAsCreu8O+xzAK9XUA6np\r\n" \ - "8lebaIqxFHabrjlbHgan5qKP0+EncMRN/5Lb11MDzfjyIusoFWPZF8rF2x9D+UFv\r\n" \ - "hZuL9Z40jz3cRlVUxuVtUq1tna2CCwWhwl5gwAQ/b0rkhe+5/b3cgSs3VbIdWHic\r\n" \ - "nwM4Yq4K/nAetYiOxtjKY5zLIvRopd0CAwEAAaNTMFEwHQYDVR0OBBYEFFR43w+x\r\n" \ - "ri1ssaAyJzQGDH/dP2e0MB8GA1UdIwQYMBaAFFR43w+xri1ssaAyJzQGDH/dP2e0\r\n" \ - "MA8GA1UdEwEB/wQFMAMBAf8wDQYJKoZIhvcNAQELBQADggEBADU/lBjTGb7RlgGq\r\n" \ - "HYCktoWZBNkJFPVTPrC1mwzJX/vSaz9QUpRA5dpprSl84QKvWNxO5fPEMmwK2Wrw\r\n" \ - "x6tdE2aWb5x+3W0302JnaUPNhDF26Z5+LK4CoRHjbT2J3FrDg2u6/3Si+RpNSHYh\r\n" \ - "0OCdApzCyzqWdmvb7VD+u+isSh9CEUcaBOCq/72GNqdIjnSsgMGNHp9Ld6+ctwJO\r\n" \ - "sQkj0M3MaciNSPZ3y0w/GqeWNQaK3Rk5pSaqrc9RQS42KtJuGOqMiBMG1Ib6b7D4\r\n" \ - "bJSEDBzhO1M0o9vwr9xYaCUfbQzuuYJ3al4weRl0E4B63o2OFUjMOILIO3LeuuRD\r\n" \ - "+HXdOE0=\r\n" \ - "-----END CERTIFICATE-----\r\n" -/* END FILE */ diff --git a/examples/mqttc/mqttc_pub.c b/examples/mqttc/mqttc_pub.c index d979fb24a..6394dbf3e 100644 --- a/examples/mqttc/mqttc_pub.c +++ b/examples/mqttc/mqttc_pub.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/mqttc/mqttc_pub.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -24,7 +22,6 @@ * Included Files ****************************************************************************/ -#include <nuttx/compiler.h> #include <unistd.h> #include <stdlib.h> #include <stdio.h> @@ -34,73 +31,37 @@ #include <errno.h> #include <mqtt.h> -#ifdef MQTT_USE_MBEDTLS -# include <inttypes.h> - -# include <mbedtls/error.h> -# include <mbedtls/entropy.h> -# include <mbedtls/ctr_drbg.h> -# include <mbedtls/net_sockets.h> -# include <mbedtls/ssl.h> - -#include "cert.inc" - /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ -# define EXTRA_OPT "c:" -#else -# define EXTRA_OPT "" -#endif - /**************************************************************************** * Private Types ****************************************************************************/ struct mqttc_cfg_s { - FAR const char *host; - FAR const char *port; - FAR const char *topic; - FAR const char *msg; - FAR const char *id; - FAR const char *user; - FAR const char *pass; -#ifdef MQTT_USE_MBEDTLS - FAR const char *ca_file; -#endif + struct mqtt_client client; + const FAR char *host; + const FAR char *port; + const FAR char *topic; + const FAR char *msg; + const FAR char *id; + uint8_t sendbuf[CONFIG_EXAMPLES_MQTTC_TXSIZE]; + uint8_t recvbuf[CONFIG_EXAMPLES_MQTTC_RXSIZE]; uint32_t tmo; uint8_t flags; uint8_t qos; }; -struct mqtt_conn_context_s -{ - struct mqtt_client client; -#ifdef MQTT_USE_MBEDTLS - mbedtls_net_context net_ctx; - mbedtls_ssl_context ssl_ctx; - mbedtls_ssl_config ssl_conf; - mbedtls_x509_crt ca_crt; - mbedtls_entropy_context entropy; - mbedtls_ctr_drbg_context ctr_drbg; -#endif - uint8_t sendbuf[CONFIG_EXAMPLES_MQTTC_TXSIZE]; - uint8_t recvbuf[CONFIG_EXAMPLES_MQTTC_RXSIZE]; -}; - /**************************************************************************** * Private Function Prototypes ****************************************************************************/ static FAR void *client_refresher(FAR void *data); -static void parsearg(int argc, FAR char *argv[], FAR struct mqttc_cfg_s *cfg, - FAR int *n); -static int init_conn(FAR const struct mqttc_cfg_s *cfg, - FAR struct mqtt_conn_context_s *ctx, - FAR mqtt_pal_socket_handle *handle); -static void close_conn(FAR struct mqtt_conn_context_s *ctx); +static void parsearg(int argc, char *argv[], struct mqttc_cfg_s *cfg, + int *n); +static int initserver(const FAR struct mqttc_cfg_s *cfg); /**************************************************************************** * Private Functions @@ -134,12 +95,11 @@ static FAR void *client_refresher(FAR void *data) * ****************************************************************************/ -static void parsearg(int argc, FAR char *argv[], - FAR struct mqttc_cfg_s *cfg, FAR int *n) +static void parsearg(int argc, char *argv[], struct mqttc_cfg_s *cfg, int *n) { int opt; - while ((opt = getopt(argc, argv, "h:p:m:t:n:q:" EXTRA_OPT)) != ERROR) + while ((opt = getopt(argc, argv, "h:p:m:t:n:")) != ERROR) { switch (opt) { @@ -163,27 +123,6 @@ static void parsearg(int argc, FAR char *argv[], *n = strtol(optarg, NULL, 10); break; - case 'q': - switch (strtol(optarg, NULL, 10)) - { - case 0L: - cfg->qos = MQTT_PUBLISH_QOS_0; - break; - case 1L: - cfg->qos = MQTT_PUBLISH_QOS_1; - break; - case 2L: - cfg->qos = MQTT_PUBLISH_QOS_2; - break; - } - break; - -#ifdef MQTT_USE_MBEDTLS - case 'c': - cfg->ca_file = optarg; - break; -#endif - default: fprintf(stderr, "ERROR: Unrecognized option\n"); break; @@ -192,195 +131,29 @@ static void parsearg(int argc, FAR char *argv[], } /**************************************************************************** - * Name: init_conn + * Name: initserver * * Description: * Resolve server's name and try to establish a connection. * ****************************************************************************/ -static int init_conn(FAR const struct mqttc_cfg_s *cfg, - FAR struct mqtt_conn_context_s *conn, - FAR mqtt_pal_socket_handle *socketfd) +static int initserver(const FAR struct mqttc_cfg_s *cfg) { -#ifdef MQTT_USE_MBEDTLS - FAR mbedtls_net_context *net_ctx = &conn->net_ctx; - FAR mbedtls_ssl_context *ssl_ctx = &conn->ssl_ctx; - FAR mbedtls_ssl_config *ssl_conf = &conn->ssl_conf; - FAR mbedtls_x509_crt *ca_crt = &conn->ca_crt; - FAR mbedtls_entropy_context *entropy = &conn->entropy; - FAR mbedtls_ctr_drbg_context *ctr_drbg = &conn->ctr_drbg; - uint32_t result; - - FAR const unsigned char *additional = (FAR const unsigned char *)"MQTT-C"; - size_t additional_len = 6; -#else struct addrinfo hints; - FAR struct addrinfo *servinfo; - FAR struct addrinfo *itr; + struct addrinfo *servinfo; + struct addrinfo *itr; int fd; -#endif int ret; - printf("Connecting to %s:%s...\n", cfg->host, cfg->port); - -#ifdef MQTT_USE_MBEDTLS - mbedtls_entropy_init(entropy); - mbedtls_ctr_drbg_init(ctr_drbg); - ret = mbedtls_ctr_drbg_seed(ctr_drbg, mbedtls_entropy_func, entropy, - additional, additional_len); - if (ret != 0) - { - printf("ERROR! mbedtls_ctr_drbg_seed() failed: %d\n", ret); - goto err_with_ctr_drbg; - } - - mbedtls_x509_crt_init(ca_crt); - if (cfg->ca_file != NULL) - { - ret = mbedtls_x509_crt_parse_file(ca_crt, cfg->ca_file); - } - else - { - ret = mbedtls_x509_crt_parse(ca_crt, - (FAR const unsigned char *)TEST_CA_CRT_RSA_SHA256_PEM, - sizeof(TEST_CA_CRT_RSA_SHA256_PEM)); - } - - if (ret != 0) - { - printf("ERROR! mbedtls_x509_crt_parse_file() failed: %d\n", ret); - goto err_with_x509_crt; - } - - mbedtls_ssl_config_init(ssl_conf); - ret = mbedtls_ssl_config_defaults(ssl_conf, MBEDTLS_SSL_IS_CLIENT, - MBEDTLS_SSL_TRANSPORT_STREAM, - MBEDTLS_SSL_PRESET_DEFAULT); - if (ret != 0) - { - printf("ERROR! mbedtls_ssl_config_defaults() failed: %d\n", ret); - goto err_with_ssl_conf; - } - - mbedtls_ssl_conf_ca_chain(ssl_conf, ca_crt, NULL); - mbedtls_ssl_conf_authmode(ssl_conf, MBEDTLS_SSL_VERIFY_OPTIONAL); - mbedtls_ssl_conf_rng(ssl_conf, mbedtls_ctr_drbg_random, ctr_drbg); - - mbedtls_net_init(net_ctx); - ret = mbedtls_net_connect(net_ctx, cfg->host, cfg->port, - MBEDTLS_NET_PROTO_TCP); - if (ret != 0) - { - printf("ERROR! mbedtls_net_connect() failed: %d\n", ret); - goto err_with_net; - } - - ret = mbedtls_net_set_nonblock(net_ctx); - if (ret != 0) - { - printf("ERROR! mbedtls_net_set_nonblock() failed: %d\n", ret); - goto err_with_net; - } - - mbedtls_ssl_init(ssl_ctx); - ret = mbedtls_ssl_setup(ssl_ctx, ssl_conf); - if (ret != 0) - { - printf("ERROR! mbedtls_ssl_setup() failed: %d\n", ret); - goto err_with_ssl; - } - - ret = mbedtls_ssl_set_hostname(ssl_ctx, cfg->host); - if (ret != 0) - { - printf("ERROR! mbedtls_ssl_set_hostname() failed: %d\n", ret); - goto err_with_ssl; - } - - mbedtls_ssl_set_bio(ssl_ctx, net_ctx, - mbedtls_net_send, mbedtls_net_recv, NULL); - - for (; ; ) - { - uint32_t want = 0; - ret = mbedtls_ssl_handshake(ssl_ctx); - if (ret == MBEDTLS_ERR_SSL_WANT_READ) - { - want |= MBEDTLS_NET_POLL_READ; - } - else if (ret == MBEDTLS_ERR_SSL_WANT_WRITE) - { - want |= MBEDTLS_NET_POLL_WRITE; - } - else - { - break; - } - - ret = mbedtls_net_poll(net_ctx, want, -1); - if (ret < 0) - { - printf("ERROR! mbedtls_net_poll() failed: %d\n", ret); - goto err_with_ssl; - } - } - - if (ret != 0) - { - printf("ERROR! mbedtls_ssl_handshake() failed: %d\n", ret); - goto err_with_ssl; - } - - result = mbedtls_ssl_get_verify_result(ssl_ctx); - if (result != 0) - { - if (result == 0xffffffff) - { - printf("ERROR! mbedtls_ssl_get_verify_result() failed\n"); - goto err_with_ssl; - } - else - { -#if defined(MBEDTLS_X509_REMOVE_INFO) - const char *buf = ""; -#else - char buf[512]; - mbedtls_x509_crt_verify_info(buf, sizeof(buf), "\t", result); -#endif - printf("Certificate verification failed (%0" PRIx32 ")\n%s\n", - result, buf); - -#ifndef CONFIG_EXAMPLES_MQTTC_ALLOW_UNVERIFIED_TLS - goto err_with_ssl; -#endif - } - } - - *socketfd = ssl_ctx; - - return 0; - -err_with_ssl: - mbedtls_ssl_free(ssl_ctx); -err_with_net: - mbedtls_net_free(net_ctx); -err_with_ssl_conf: - mbedtls_ssl_config_free(ssl_conf); -err_with_x509_crt: - mbedtls_x509_crt_free(ca_crt); -err_with_ctr_drbg: - mbedtls_ctr_drbg_free(ctr_drbg); - mbedtls_entropy_free(entropy); - - return -1; -#else memset(&hints, 0, sizeof(hints)); hints.ai_family = AF_INET; hints.ai_socktype = SOCK_STREAM; + printf("Connecting to %s:%s...\n", cfg->host, cfg->port); + ret = getaddrinfo(cfg->host, cfg->port, &hints, &servinfo); - if (ret != 0) + if (ret != OK) { printf("ERROR! getaddrinfo() failed: %s\n", gai_strerror(ret)); return -1; @@ -417,7 +190,6 @@ err_with_ctr_drbg: ret = fcntl(fd, F_GETFL, 0); if (ret < 0) { - close(fd); printf("ERROR! fcntl() F_GETFL failed, errno: %d\n", errno); return -1; } @@ -425,145 +197,90 @@ err_with_ctr_drbg: ret = fcntl(fd, F_SETFL, ret | O_NONBLOCK); if (ret < 0) { - close(fd); printf("ERROR! fcntl() F_SETFL failed, errno: %d\n", errno); return -1; } - *socketfd = fd; - - return 0; -#endif -} - -/**************************************************************************** - * Name: close_conn - * - * Description: - * Shut down connection to server established by init_conn. - * - ****************************************************************************/ - -static void close_conn(FAR struct mqtt_conn_context_s *conn) -{ -#ifndef MQTT_USE_MBEDTLS - close(conn->client.socketfd); -#else - mbedtls_net_free(&conn->net_ctx); - mbedtls_ssl_free(&conn->ssl_ctx); - mbedtls_ssl_config_free(&conn->ssl_conf); - mbedtls_x509_crt_free(&conn->ca_crt); - mbedtls_ctr_drbg_free(&conn->ctr_drbg); - mbedtls_entropy_free(&conn->entropy); -#endif + return fd; } /**************************************************************************** * Public Functions ****************************************************************************/ -int main(int argc, FAR char *argv[]) +int main(int argc, char *argv[]) { - struct mqtt_conn_context_s mqtt_conn; - mqtt_pal_socket_handle socketfd; - int timeout = 100; + int sockfd; enum MQTTErrors mqtterr; - pthread_attr_t attr; pthread_t thrdid; int n = 1; struct mqttc_cfg_s mqtt_cfg = { .host = "broker.hivemq.com", -#ifndef MQTT_USE_MBEDTLS .port = "1883", -#else - .port = "8883", -#endif .topic = "test", .msg = "test", .flags = MQTT_CONNECT_CLEAN_SESSION, .tmo = 400, .id = NULL, - .user = NULL, - .pass = NULL, - .qos = MQTT_PUBLISH_QOS_0 + .qos = MQTT_PUBLISH_QOS_0, }; parsearg(argc, argv, &mqtt_cfg, &n); - - if (init_conn(&mqtt_cfg, &mqtt_conn, &socketfd) < 0) + sockfd = initserver(&mqtt_cfg); + if (sockfd < 0) { return -1; } - mqtterr = mqtt_init(&mqtt_conn.client, socketfd, - mqtt_conn.sendbuf, sizeof(mqtt_conn.sendbuf), - mqtt_conn.recvbuf, sizeof(mqtt_conn.recvbuf), + mqtterr = mqtt_init(&mqtt_cfg.client, sockfd, + mqtt_cfg.sendbuf, sizeof(mqtt_cfg.sendbuf), + mqtt_cfg.recvbuf, sizeof(mqtt_cfg.recvbuf), NULL); if (mqtterr != MQTT_OK) { - printf("ERROR! mqtt_init() failed.\n"); - goto err_with_conn; + printf("ERRPR! mqtt_init() failed.\n"); + goto err_with_socket; } - mqtterr = mqtt_connect(&mqtt_conn.client, mqtt_cfg.id, - NULL, /* Will topic */ - NULL, /* Will message */ - 0, /* Will message size */ - mqtt_cfg.user, /* User name */ - mqtt_cfg.pass, /* Password */ + mqtterr = mqtt_connect(&mqtt_cfg.client, mqtt_cfg.id, + NULL, /* Will topic */ + NULL, /* Will message */ + 0, /* Will message size */ + NULL, /* User name */ + NULL, /* Password */ mqtt_cfg.flags, mqtt_cfg.tmo); if (mqtterr != MQTT_OK) { printf("ERROR! mqtt_connect() failed\n"); - goto err_with_conn; + goto err_with_socket; } - if (mqtt_conn.client.error != MQTT_OK) + if (mqtt_cfg.client.error != MQTT_OK) { - printf("error: %s\n", mqtt_error_str(mqtt_conn.client.error)); - goto err_with_conn; + printf("error: %s\n", mqtt_error_str(mqtt_cfg.client.error)); + goto err_with_socket; } else { printf("Success: Connected to broker!\n"); } - /* Start a thread to refresh the client (handle egress and ingress client + /* Start a thread to refresh the client (handle egress and ingree client * traffic) */ - if (pthread_attr_init(&attr) != 0) - { - printf("ERROR! pthread_attr_init() failed.\n"); - goto err_with_conn; - } - - pthread_attr_setstacksize(&attr, CONFIG_EXAMPLES_MQTTC_STACKSIZE); - - if (pthread_create(&thrdid, &attr, client_refresher, &mqtt_conn.client)) + if (pthread_create(&thrdid, NULL, client_refresher, &mqtt_cfg.client)) { printf("ERROR! pthread_create() failed.\n"); - goto err_with_conn; - } - - /* Wait for MQTT ACK or time-out */ - - while (!mqtt_conn.client.event_connect && --timeout > 0) - { - usleep(10000); - } - - if (timeout == 0) - { - goto err_with_thrd; + goto err_with_socket; } while (n--) { - mqtterr = mqtt_publish(&mqtt_conn.client, mqtt_cfg.topic, - mqtt_cfg.msg, strlen(mqtt_cfg.msg), + mqtterr = mqtt_publish(&mqtt_cfg.client, mqtt_cfg.topic, + mqtt_cfg.msg, strlen(mqtt_cfg.msg) + 1, mqtt_cfg.qos); if (mqtterr != MQTT_OK) { @@ -571,9 +288,9 @@ int main(int argc, FAR char *argv[]) goto err_with_thrd; } - if (mqtt_conn.client.error != MQTT_OK) + if (mqtt_cfg.client.error != MQTT_OK) { - printf("error: %s\n", mqtt_error_str(mqtt_conn.client.error)); + printf("error: %s\n", mqtt_error_str(mqtt_cfg.client.error)); goto err_with_thrd; } else @@ -585,7 +302,7 @@ int main(int argc, FAR char *argv[]) } printf("\nDisconnecting from %s\n\n", mqtt_cfg.host); - mqtterr = mqtt_disconnect(&mqtt_conn.client); + mqtterr = mqtt_disconnect(&mqtt_cfg.client); if (mqtterr != MQTT_OK) { printf("ERROR! mqtt_disconnect() failed\n"); @@ -597,13 +314,12 @@ int main(int argc, FAR char *argv[]) * through TCP (i.e. no MQTT DISCONNECT packet). */ - mqtt_sync(&mqtt_conn.client); + mqtt_sync(&mqtt_cfg.client); err_with_thrd: pthread_cancel(thrdid); - -err_with_conn: - close_conn(&mqtt_conn); +err_with_socket: + close(sockfd); return 0; } diff --git a/examples/mqttc/mqttc_sub.c b/examples/mqttc/mqttc_sub.c deleted file mode 100644 index d7ad1858a..000000000 --- a/examples/mqttc/mqttc_sub.c +++ /dev/null @@ -1,820 +0,0 @@ -/**************************************************************************** - * apps/examples/mqttc/mqttc_sub.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <sys/types.h> -#include <unistd.h> -#include <stdlib.h> -#include <stdio.h> -#include <sys/socket.h> -#include <fcntl.h> -#include <netdb.h> -#include <arpa/inet.h> -#include <errno.h> -#include <mqtt.h> -#include <netutils/netlib.h> - -#ifdef MQTT_USE_MBEDTLS -# include <inttypes.h> - -# include <mbedtls/error.h> -# include <mbedtls/entropy.h> -# include <mbedtls/ctr_drbg.h> -# include <mbedtls/net_sockets.h> -# include <mbedtls/ssl.h> - -# include "cert.inc" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -# define EXTRA_OPT "c:" -#else -# define EXTRA_OPT "" -#endif - -/* Seconds to wait between failed connection attempts in the reconnect - * callback. - */ - -#define MQTTC_RECONNECT_DELAY_S 2 - -/* Network interface to wait on before the first connection attempt, and the - * polling parameters for that wait. Change MQTTC_NETIF to match the board's - * network device (e.g. "eth0" for wired Ethernet). - */ - -#define MQTTC_NETIF "wlan0" -#define MQTTC_NET_POLL_MS 200 -#define MQTTC_NET_WAIT_MS 30000 - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -struct mqttc_cfg_s -{ - FAR const char *host; - FAR const char *port; - FAR const char *topic; - FAR const char *msg; - FAR const char *id; - FAR const char *user; - FAR const char *pass; - #ifdef MQTT_USE_MBEDTLS - FAR const char *ca_file; - #endif - uint32_t tmo; - uint8_t flags; - uint8_t qos; -}; - -struct mqtt_conn_context_s -{ - struct mqtt_client client; - #ifdef MQTT_USE_MBEDTLS - mbedtls_net_context net_ctx; - mbedtls_ssl_context ssl_ctx; - mbedtls_ssl_config ssl_conf; - mbedtls_x509_crt ca_crt; - mbedtls_entropy_context entropy; - mbedtls_ctr_drbg_context ctr_drbg; - #endif - uint8_t sendbuf[CONFIG_EXAMPLES_MQTTC_TXSIZE]; - uint8_t recvbuf[CONFIG_EXAMPLES_MQTTC_RXSIZE]; -}; - -/* State handed to the reconnect callback so it can rebuild the transport - * connection and reconfigure the MQTT session from scratch. - */ - -struct mqttc_reconnect_s -{ - FAR const struct mqttc_cfg_s *cfg; - FAR struct mqtt_conn_context_s *conn; -}; - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -static FAR void *client_refresher(FAR void *data); -static void parsearg(int argc, FAR char *argv[], - FAR struct mqttc_cfg_s *cfg); -static int init_conn(FAR const struct mqttc_cfg_s *cfg, - FAR struct mqtt_conn_context_s *ctx, - FAR mqtt_pal_socket_handle *handle); -static void close_conn(FAR struct mqtt_conn_context_s *ctx); -static void reconnect_client(FAR struct mqtt_client *client, - FAR void **state); -static void wait_for_network(void); - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -#ifdef MQTT_USE_MBEDTLS - -/**************************************************************************** - * Name: mqttc_net_recv - * - * Description: - * mbedTLS BIO receive callback for non-blocking sockets. The stock - * mbedtls_net_recv() relies on fcntl(F_GETFL) reporting O_NONBLOCK to - * classify EAGAIN as "would block". On NuttX, F_SETFL applies the - * non-blocking mode via FIONBIO but does not retain O_NONBLOCK in the - * file status flags, so F_GETFL never reports it. The stock callback - * therefore turns a benign EAGAIN into MBEDTLS_ERR_NET_RECV_FAILED. This - * wrapper inspects errno directly and returns MBEDTLS_ERR_SSL_WANT_READ - * so callers (e.g. MQTT-C's mqtt_sync) keep retrying instead of aborting. - * - ****************************************************************************/ - -static int mqttc_net_recv(FAR void *ctx, FAR unsigned char *buf, size_t len) -{ - int fd = ((FAR mbedtls_net_context *)ctx)->fd; - int ret; - - ret = recv(fd, buf, len, 0); - if (ret < 0) - { - if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR) - { - return MBEDTLS_ERR_SSL_WANT_READ; - } - - if (errno == EPIPE || errno == ECONNRESET) - { - return MBEDTLS_ERR_NET_CONN_RESET; - } - - return MBEDTLS_ERR_NET_RECV_FAILED; - } - - return ret; -} - -/**************************************************************************** - * Name: mqttc_net_send - * - * Description: - * mbedTLS BIO send callback, mirroring mqttc_net_recv() for the same - * non-blocking/EAGAIN reason on the transmit side. - * - ****************************************************************************/ - -static int mqttc_net_send(FAR void *ctx, FAR const unsigned char *buf, - size_t len) -{ - int fd = ((FAR mbedtls_net_context *)ctx)->fd; - int ret; - - ret = send(fd, buf, len, 0); - if (ret < 0) - { - if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR) - { - return MBEDTLS_ERR_SSL_WANT_WRITE; - } - - if (errno == EPIPE || errno == ECONNRESET) - { - return MBEDTLS_ERR_NET_CONN_RESET; - } - - return MBEDTLS_ERR_NET_SEND_FAILED; - } - - return ret; -} - -#endif /* MQTT_USE_MBEDTLS */ - -/**************************************************************************** - * Name: client_refresher - * - * Description: - * The client's refresher. This function triggers back-end routines to - * handle ingress/egress traffic to the broker. - * - ****************************************************************************/ - -static FAR void *client_refresher(FAR void *data) -{ - while (1) - { - mqtt_sync((FAR struct mqtt_client *)data); - usleep(100000U); - } - - return NULL; -} - -/**************************************************************************** - * Name: publish_callback - * - * Description: - * Print received publish message. - * - ****************************************************************************/ - -void publish_callback(void** unused, struct mqtt_response_publish *published) -{ - /* this is a byte stream, we have to convert it to C string */ - - char message[CONFIG_EXAMPLES_MQTTC_RXSIZE]; - - /* convert to C string (null terminated) */ - - size_t message_size = published->application_message_size; - if (message_size >= CONFIG_EXAMPLES_MQTTC_RXSIZE) - { - message_size = CONFIG_EXAMPLES_MQTTC_RXSIZE - 1; - } - - memcpy(message, published->application_message, message_size); - message[message_size] = '\0'; - - printf("Received: %s\n", message); -} - -/**************************************************************************** - * Name: parsearg - * - * Description: - * Parse command line arguments. - * - ****************************************************************************/ - -static void parsearg(int argc, FAR char *argv[], - FAR struct mqttc_cfg_s *cfg) -{ - int opt; - - while ((opt = getopt(argc, argv, "h:p:t:q:" EXTRA_OPT)) != ERROR) - { - switch (opt) - { - case 'h': - cfg->host = optarg; - break; - - case 'p': - cfg->port = optarg; - break; - - case 't': - cfg->topic = optarg; - break; - - case 'q': - switch (strtol(optarg, NULL, 10)) - { - case 0L: - cfg->qos = 0; - break; - case 1L: - cfg->qos = 1; - break; - case 2L: - cfg->qos = 2; - break; - } - break; -#ifdef MQTT_USE_MBEDTLS - case 'c': - cfg->ca_file = optarg; - break; -#endif - - default: - fprintf(stderr, "ERROR: Unrecognized option\n"); - break; - } - } -} - -/**************************************************************************** - * Name: init_conn - * - * Description: - * Resolve server's name and try to establish a connection. - * - ****************************************************************************/ - -static int init_conn(FAR const struct mqttc_cfg_s *cfg, - FAR struct mqtt_conn_context_s *conn, - FAR mqtt_pal_socket_handle *socketfd) -{ -#ifdef MQTT_USE_MBEDTLS - FAR mbedtls_net_context *net_ctx = &conn->net_ctx; - FAR mbedtls_ssl_context *ssl_ctx = &conn->ssl_ctx; - FAR mbedtls_ssl_config *ssl_conf = &conn->ssl_conf; - FAR mbedtls_x509_crt *ca_crt = &conn->ca_crt; - FAR mbedtls_entropy_context *entropy = &conn->entropy; - FAR mbedtls_ctr_drbg_context *ctr_drbg = &conn->ctr_drbg; - uint32_t result; - - FAR const unsigned char *additional = (FAR const unsigned char *)"MQTT-C"; - size_t additional_len = 6; -#else - struct addrinfo hints; - FAR struct addrinfo *servinfo; - FAR struct addrinfo *itr; - int fd; -#endif - int ret; - - printf("Connecting to %s:%s...\n", cfg->host, cfg->port); - -#ifdef MQTT_USE_MBEDTLS - mbedtls_entropy_init(entropy); - mbedtls_ctr_drbg_init(ctr_drbg); - ret = mbedtls_ctr_drbg_seed(ctr_drbg, mbedtls_entropy_func, entropy, - additional, additional_len); - if (ret != 0) - { - printf("ERROR! mbedtls_ctr_drbg_seed() failed: %d\n", ret); - goto err_with_ctr_drbg; - } - - mbedtls_x509_crt_init(ca_crt); - if (cfg->ca_file != NULL) - { - ret = mbedtls_x509_crt_parse_file(ca_crt, cfg->ca_file); - } - else - { - ret = mbedtls_x509_crt_parse(ca_crt, - (FAR const unsigned char *)TEST_CA_CRT_RSA_SHA256_PEM, - sizeof(TEST_CA_CRT_RSA_SHA256_PEM)); - } - - if (ret != 0) - { - printf("ERROR! mbedtls_x509_crt_parse_file() failed: %d\n", ret); - goto err_with_x509_crt; - } - - mbedtls_ssl_config_init(ssl_conf); - ret = mbedtls_ssl_config_defaults(ssl_conf, MBEDTLS_SSL_IS_CLIENT, - MBEDTLS_SSL_TRANSPORT_STREAM, - MBEDTLS_SSL_PRESET_DEFAULT); - if (ret != 0) - { - printf("ERROR! mbedtls_ssl_config_defaults() failed: %d\n", ret); - goto err_with_ssl_conf; - } - - mbedtls_ssl_conf_ca_chain(ssl_conf, ca_crt, NULL); - mbedtls_ssl_conf_authmode(ssl_conf, MBEDTLS_SSL_VERIFY_OPTIONAL); - mbedtls_ssl_conf_rng(ssl_conf, mbedtls_ctr_drbg_random, ctr_drbg); - - mbedtls_net_init(net_ctx); - ret = mbedtls_net_connect(net_ctx, cfg->host, cfg->port, - MBEDTLS_NET_PROTO_TCP); - if (ret != 0) - { - printf("ERROR! mbedtls_net_connect() failed: %d\n", ret); - goto err_with_net; - } - - ret = mbedtls_net_set_nonblock(net_ctx); - if (ret != 0) - { - printf("ERROR! mbedtls_net_set_nonblock() failed: %d\n", ret); - goto err_with_net; - } - - mbedtls_ssl_init(ssl_ctx); - ret = mbedtls_ssl_setup(ssl_ctx, ssl_conf); - if (ret != 0) - { - printf("ERROR! mbedtls_ssl_setup() failed: %d\n", ret); - goto err_with_ssl; - } - - ret = mbedtls_ssl_set_hostname(ssl_ctx, cfg->host); - if (ret != 0) - { - printf("ERROR! mbedtls_ssl_set_hostname() failed: %d\n", ret); - goto err_with_ssl; - } - - mbedtls_ssl_set_bio(ssl_ctx, net_ctx, - mqttc_net_send, mqttc_net_recv, NULL); - - for (; ; ) - { - uint32_t want = 0; - ret = mbedtls_ssl_handshake(ssl_ctx); - if (ret == MBEDTLS_ERR_SSL_WANT_READ) - { - want |= MBEDTLS_NET_POLL_READ; - } - else if (ret == MBEDTLS_ERR_SSL_WANT_WRITE) - { - want |= MBEDTLS_NET_POLL_WRITE; - } - else - { - break; - } - - ret = mbedtls_net_poll(net_ctx, want, -1); - if (ret < 0) - { - printf("ERROR! mbedtls_net_poll() failed: %d\n", ret); - goto err_with_ssl; - } - } - - if (ret != 0) - { - printf("ERROR! mbedtls_ssl_handshake() failed: %d\n", ret); - goto err_with_ssl; - } - - result = mbedtls_ssl_get_verify_result(ssl_ctx); - if (result != 0) - { - if (result == 0xffffffff) - { - printf("ERROR! mbedtls_ssl_get_verify_result() failed\n"); - goto err_with_ssl; - } - else - { -#if defined(MBEDTLS_X509_REMOVE_INFO) - const char *buf = ""; -#else - char buf[512]; - mbedtls_x509_crt_verify_info(buf, sizeof(buf), "\t", result); -#endif - printf("Certificate verification failed (%0" PRIx32 ")\n%s\n", - result, buf); - -#ifndef CONFIG_EXAMPLES_MQTTC_ALLOW_UNVERIFIED_TLS - goto err_with_ssl; -#endif - } - } - - *socketfd = ssl_ctx; - - return 0; - -err_with_ssl: - mbedtls_ssl_free(ssl_ctx); -err_with_net: - mbedtls_net_free(net_ctx); -err_with_ssl_conf: - mbedtls_ssl_config_free(ssl_conf); -err_with_x509_crt: - mbedtls_x509_crt_free(ca_crt); -err_with_ctr_drbg: - mbedtls_ctr_drbg_free(ctr_drbg); - mbedtls_entropy_free(entropy); - - return -1; -#else - memset(&hints, 0, sizeof(hints)); - hints.ai_family = AF_INET; - hints.ai_socktype = SOCK_STREAM; - - ret = getaddrinfo(cfg->host, cfg->port, &hints, &servinfo); - if (ret != 0) - { - printf("ERROR! getaddrinfo() failed: %s\n", gai_strerror(ret)); - return -1; - } - - itr = servinfo; - do - { - fd = socket(itr->ai_family, itr->ai_socktype, itr->ai_protocol); - if (fd < 0) - { - continue; - } - - ret = connect(fd, itr->ai_addr, itr->ai_addrlen); - if (ret == 0) - { - break; - } - - close(fd); - fd = -1; - } - while ((itr = itr->ai_next) != NULL); - - freeaddrinfo(servinfo); - - if (fd < 0) - { - printf("ERROR! Couldn't create socket\n"); - return -1; - } - - ret = fcntl(fd, F_GETFL, 0); - if (ret < 0) - { - close(fd); - printf("ERROR! fcntl() F_GETFL failed, errno: %d\n", errno); - return -1; - } - - ret = fcntl(fd, F_SETFL, ret | O_NONBLOCK); - if (ret < 0) - { - close(fd); - printf("ERROR! fcntl() F_SETFL failed, errno: %d\n", errno); - return -1; - } - - *socketfd = fd; - - return 0; -#endif -} - -/**************************************************************************** - * Name: close_conn - * - * Description: - * Shut down connection to server established by init_conn. - * - ****************************************************************************/ - -static void close_conn(FAR struct mqtt_conn_context_s *conn) -{ -#ifndef MQTT_USE_MBEDTLS - close(conn->client.socketfd); -#else - mbedtls_net_free(&conn->net_ctx); - mbedtls_ssl_free(&conn->ssl_ctx); - mbedtls_ssl_config_free(&conn->ssl_conf); - mbedtls_x509_crt_free(&conn->ca_crt); - mbedtls_ctr_drbg_free(&conn->ctr_drbg); - mbedtls_entropy_free(&conn->entropy); -#endif -} - -/**************************************************************************** - * Name: wait_for_network - * - * Description: - * Block until the network interface has a usable IPv4 address (i.e. the - * link is up and DHCP has completed) or a timeout elapses. This avoids - * the spurious first-attempt connect() failure that happens when the - * example starts before Wi-Fi association/DHCP have finished. - * - ****************************************************************************/ - -static void wait_for_network(void) -{ - struct in_addr addr; - int waited = 0; - - for (; ; ) - { - if (netlib_get_ipv4addr(MQTTC_NETIF, &addr) == 0 && - addr.s_addr != INADDR_ANY && - addr.s_addr != htonl(INADDR_LOOPBACK)) - { - return; - } - - if (waited >= MQTTC_NET_WAIT_MS) - { - return; - } - - usleep(MQTTC_NET_POLL_MS * 1000); - waited += MQTTC_NET_POLL_MS; - } -} - -/**************************************************************************** - * Name: reconnect_client - * - * Description: - * Reconnect callback registered with mqtt_init_reconnect(). MQTT-C calls - * this whenever the client enters an error state, and once at start-up - * (with client->error == MQTT_ERROR_INITIAL_RECONNECT) to set up the - * initial session. It tears down the previous connection, re-establishes - * the transport (TCP + optional TLS), reinitializes the client and then - * reconfigures the session (CONNECT + SUBSCRIBE). - * - ****************************************************************************/ - -static void reconnect_client(FAR struct mqtt_client *client, - FAR void **state) -{ - FAR struct mqttc_reconnect_s *rc = - *((FAR struct mqttc_reconnect_s **)state); - FAR const struct mqttc_cfg_s *cfg = rc->cfg; - FAR struct mqtt_conn_context_s *conn = rc->conn; - mqtt_pal_socket_handle socketfd; - enum MQTTErrors mqtterr; - - /* Tear down the previous connection, unless this is the initial set-up - * call (in which case there is nothing to clean up yet). - */ - - if (client->error != MQTT_ERROR_INITIAL_RECONNECT) - { - printf("reconnect_client: reconnecting after error \"%s\"\n", - mqtt_error_str(client->error)); - close_conn(conn); - } - - /* (Re)establish the transport connection. - * - * mqtt_sync() unconditionally proceeds to recv/send on client->socketfd - * after this callback returns. Until mqtt_reinit() runs, socketfd is the - * sentinel value -1 set by mqtt_init_reconnect(); in the mbedTLS build - * that is a pointer (0xffffffff) that mbedtls_ssl_read() would dereference - * and crash on. We must therefore not return until a connection has - * actually been established, so retry with a short back-off on failure. - */ - - while (init_conn(cfg, conn, &socketfd) < 0) - { - printf("ERROR! init_conn() failed; retrying in %d s\n", - MQTTC_RECONNECT_DELAY_S); - sleep(MQTTC_RECONNECT_DELAY_S); - } - - printf("Success: Connected to broker!\n"); - - /* Reinitialize the client with the fresh socket/SSL handle. */ - - mqtt_reinit(client, socketfd, - conn->sendbuf, sizeof(conn->sendbuf), - conn->recvbuf, sizeof(conn->recvbuf)); - - /* Send the connection request to the broker. */ - - mqtterr = mqtt_connect(client, cfg->id, NULL, NULL, 0, NULL, NULL, - cfg->flags, cfg->tmo); - if (mqtterr != MQTT_OK) - { - printf("ERROR! mqtt_connect() failed: %s\n", mqtt_error_str(mqtterr)); - return; - } - - /* (Re)subscribe to the configured topic. */ - - mqtterr = mqtt_subscribe(client, cfg->topic, cfg->qos); - if (mqtterr != MQTT_OK) - { - printf("ERROR! mqtt_subscribe() failed: %s\n", - mqtt_error_str(mqtterr)); - } -} - -int main(int argc, FAR char * argv[]) -{ - struct mqtt_conn_context_s mqtt_conn = - { - 0 - }; - - struct mqttc_reconnect_s reconnect_state; - int timeout = 100; - enum MQTTErrors mqtterr; - pthread_attr_t attr; - pthread_t thrdid; - struct mqttc_cfg_s mqtt_cfg = - { - .host = "broker.hivemq.com", - #ifndef MQTT_USE_MBEDTLS - .port = "1883", - #else - .port = "8883", - #endif - .topic = "test", - .msg = "NULL", - .flags = MQTT_CONNECT_CLEAN_SESSION, - .tmo = 400, - .id = NULL, - .user = NULL, - .pass = NULL, - .qos = MQTT_PUBLISH_QOS_0 - }; - - parsearg(argc, argv, &mqtt_cfg); - - /* Wait for the network to come up so the first connection attempt does not - * fail with ENETUNREACH - */ - - wait_for_network(); - - /* Bundle the configuration and connection context for the reconnect - * callback. mqtt_init_reconnect() leaves the client in the - * MQTT_ERROR_INITIAL_RECONNECT state; the first mqtt_sync() (driven by the - * refresher thread) invokes reconnect_client(), which establishes the - * transport, calls mqtt_reinit() and then mqtt_connect()/mqtt_subscribe(). - */ - - reconnect_state.cfg = &mqtt_cfg; - reconnect_state.conn = &mqtt_conn; - - mqtt_init_reconnect(&mqtt_conn.client, - reconnect_client, &reconnect_state, - publish_callback); - - /* Start a thread to refresh the client (handle egress and ingress client - * traffic) - */ - - if (pthread_attr_init(&attr) != 0) - { - printf("ERROR! pthread_attr_init() failed.\n"); - goto err_with_conn; - } - - pthread_attr_setstacksize(&attr, CONFIG_EXAMPLES_MQTTC_STACKSIZE); - - if (pthread_create(&thrdid, &attr, client_refresher, &mqtt_conn.client)) - { - printf("ERROR! pthread_create() failed.\n"); - goto err_with_conn; - } - - /* Wait for the initial MQTT connection to be acknowledged or time-out. - * On time-out we keep going anyway: the reconnect callback will continue - * retrying in the background. - */ - - while (!mqtt_conn.client.event_connect && --timeout > 0) - { - usleep(10000); - } - - if (timeout == 0) - { - printf("WARNING! Initial connection timed out; " - "reconnect will keep retrying.\n"); - } - else - { - printf("Success: Connected to broker!\n"); - } - - printf("Listening for %s.\nType q to exit.\n\n", mqtt_cfg.topic); - - /* Wait for messages */ - - while (fgetc(stdin) != 'q'); - - /* Disconnect */ - - printf("\nDisconnecting from %s\n\n", mqtt_cfg.host); - mqtterr = mqtt_disconnect(&mqtt_conn.client); - if (mqtterr != MQTT_OK) - { - printf("ERROR! mqtt_disconnect() failed\n"); - } - - /* Force sending the DISCONNECT, the thread will be canceled before getting - * the chance to sync this last packet. - * Note however that close() would cleanly close the connection but only - * through TCP (i.e. no MQTT DISCONNECT packet). - */ - - mqtt_sync(&mqtt_conn.client); - - pthread_cancel(thrdid); - -err_with_conn: - close_conn(&mqtt_conn); - - return 0; -} diff --git a/examples/mtdpart/CMakeLists.txt b/examples/mtdpart/CMakeLists.txt deleted file mode 100644 index 2b629ba03..000000000 --- a/examples/mtdpart/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# ############################################################################## -# apps/examples/mtdpart/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_MTDPART) - nuttx_add_application( - NAME - mtdpart - STACKSIZE - ${CONFIG_DEFAULT_TASK_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_MTDPART} - SRCS - mtdpart_main.c) -endif() diff --git a/examples/mtdpart/Make.defs b/examples/mtdpart/Make.defs index a5bb9f62d..b15dcadd0 100644 --- a/examples/mtdpart/Make.defs +++ b/examples/mtdpart/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/mtdpart/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/mtdpart/Makefile b/examples/mtdpart/Makefile index ac0785e75..c758eb3cc 100644 --- a/examples/mtdpart/Makefile +++ b/examples/mtdpart/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/mtdpart/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/mtdpart/mtdpart_main.c b/examples/mtdpart/mtdpart_main.c index 428eddc57..4749793f1 100644 --- a/examples/mtdpart/mtdpart_main.c +++ b/examples/mtdpart/mtdpart_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/mtdpart/mtdpart_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -31,7 +29,7 @@ #include <unistd.h> #include <fcntl.h> #include <errno.h> -#include <nuttx/debug.h> +#include <debug.h> #include <nuttx/mtd/mtd.h> #include <nuttx/drivers/drivers.h> @@ -89,14 +87,18 @@ # define CONFIG_EXAMPLES_MTDPART_NPARTITIONS 3 #endif -#if CONFIG_EXAMPLES_MTDPART_NPARTITIONS <= 0 -# error "CONFIG_EXAMPLES_MTDPART_NPARTITIONS must be greater than 0" -#endif - /**************************************************************************** * Private Types ****************************************************************************/ +struct mtdpart_filedesc_s +{ + FAR char *name; + bool deleted; + size_t len; + uint32_t crc; +}; + /**************************************************************************** * Private Data ****************************************************************************/ @@ -113,7 +115,6 @@ static uint8_t g_simflash[MTDPART_BUFSIZE]; #ifdef CONFIG_EXAMPLES_MTDPART_ARCHINIT extern FAR struct mtd_dev_s *mtdpart_archinitialize(void); -extern void mtdpart_archuninitialize(FAR struct mtd_dev_s *dev); #endif /**************************************************************************** @@ -130,7 +131,8 @@ int main(int argc, FAR char *argv[]) FAR struct mtd_dev_s *part[CONFIG_EXAMPLES_MTDPART_NPARTITIONS + 1]; FAR struct mtd_geometry_s geo; FAR uint32_t *buffer; - char mtdname[32]; + char blockname[32]; + char charname[32]; size_t partsize; ssize_t nbytes; off_t nblocks; @@ -144,7 +146,6 @@ int main(int argc, FAR char *argv[]) int j; int k; int ret; - int status; /* Create and initialize a RAM MTD FLASH driver instance */ @@ -156,8 +157,8 @@ int main(int argc, FAR char *argv[]) if (!master) { printf("ERROR: Failed to create RAM MTD instance\n"); - status = 1; - exit(status); + fflush(stdout); + exit(1); } /* Perform the IOCTL to erase the entire FLASH part */ @@ -176,12 +177,22 @@ int main(int argc, FAR char *argv[]) * interesting. */ - ret = register_mtddriver("/dev/mtd0", master, 0775, NULL); + ret = ftl_initialize(0, master); if (ret < 0) { - printf("ERROR: register_mtddriver /dev/mtd0 failed: %d\n", ret); - status = 2; - goto err_master_mtd; + printf("ERROR: ftl_initialize /dev/mtdblock0 failed: %d\n", ret); + fflush(stdout); + exit(2); + } + + /* Now create a character device on the block device */ + + ret = bchdev_register("/dev/mtdblock0", "/dev/mtd0", false); + if (ret < 0) + { + printf("ERROR: bchdev_register /dev/mtd0 failed: %d\n", ret); + fflush(stdout); + exit(3); } /* Get the geometry of the FLASH device */ @@ -190,9 +201,8 @@ int main(int argc, FAR char *argv[]) (unsigned long)((uintptr_t)&geo)); if (ret < 0) { - printf("ERROR: mtd->ioctl failed: %d\n", ret); - status = 3; - goto err_master_mtd; + ferr("ERROR: mtd->ioctl failed: %d\n", ret); + exit(3); } printf("Flash Geometry:\n"); @@ -211,7 +221,7 @@ int main(int argc, FAR char *argv[]) partsize = nblocks * geo.blocksize; printf(" No. partitions: %u\n", CONFIG_EXAMPLES_MTDPART_NPARTITIONS); - printf(" Partition size: %ju Blocks (%zu bytes)\n", (uintmax_t)nblocks, + printf(" Partition size: %ju Blocks (%lu bytes)\n", (uintmax_t)nblocks, partsize); /* Now create MTD FLASH partitions */ @@ -232,18 +242,33 @@ int main(int argc, FAR char *argv[]) { printf("ERROR: mtd_partition failed. offset=%lu nblocks=%lu\n", (unsigned long)offset, (unsigned long)nblocks); - status = 4; - goto err_part_mtd; + fflush(stdout); + exit(4); } - snprintf(mtdname, sizeof(mtdname), "/dev/mtd%d", i); + /* Initialize to provide an FTL block driver on the MTD FLASH + * interface + */ - ret = register_mtddriver(mtdname, part[i], 0775, NULL); + snprintf(blockname, 32, "/dev/mtdblock%d", i); + snprintf(charname, 32, "/dev/mtd%d", i); + + ret = ftl_initialize(i, part[i]); if (ret < 0) { - printf("ERROR: register_mtddriver %s failed: %d\n", mtdname, ret); - status = 5; - goto err_part_mtd; + printf("ERROR: ftl_initialize %s failed: %d\n", blockname, ret); + fflush(stdout); + exit(5); + } + + /* Now create a character device on the block device */ + + ret = bchdev_register(blockname, charname, false); + if (ret < 0) + { + printf("ERROR: bchdev_register %s failed: %d\n", charname, ret); + fflush(stdout); + exit(6); } } @@ -253,8 +278,8 @@ int main(int argc, FAR char *argv[]) if (!buffer) { printf("ERROR: failed to allocate a sector buffer\n"); - status = 6; - goto err_part_mtd; + fflush(stdout); + exit(7); } /* Open the master MTD FLASH character driver for writing */ @@ -263,8 +288,8 @@ int main(int argc, FAR char *argv[]) if (fd < 0) { printf("ERROR: open /dev/mtd0 failed: %d\n", errno); - status = 7; - goto err_buf; + fflush(stdout); + exit(8); } /* Now write the offset into every block */ @@ -290,8 +315,8 @@ int main(int argc, FAR char *argv[]) if (nbytes < 0) { printf("ERROR: write to /dev/mtd0 failed: %d\n", errno); - status = 8; - goto err_fd; + fflush(stdout); + exit(9); } } } @@ -311,13 +336,13 @@ int main(int argc, FAR char *argv[]) /* Open the master MTD partition character driver for writing */ - snprintf(mtdname, sizeof(mtdname), "/dev/mtd%d", i); - fd = open(mtdname, O_RDWR); + snprintf(charname, 32, "/dev/mtd%d", i); + fd = open(charname, O_RDWR); if (fd < 0) { - printf("ERROR: open %s failed: %d\n", mtdname, errno); - status = 9; - goto err_buf; + printf("ERROR: open %s failed: %d\n", charname, errno); + fflush(stdout); + exit(10); } /* Now verify the offset in every block */ @@ -337,8 +362,8 @@ int main(int argc, FAR char *argv[]) { printf("ERROR: lseek to offset %ld failed: %d\n", (unsigned long)sectoff, errno); - status = 10; - goto err_fd; + fflush(stdout); + exit(11); } /* Read the next block into memory */ @@ -346,9 +371,22 @@ int main(int argc, FAR char *argv[]) nbytes = read(fd, buffer, geo.blocksize); if (nbytes < 0) { - printf("ERROR: read from %s failed: %d\n", mtdname, errno); - status = 11; - goto err_fd; + printf("ERROR: read from %s failed: %d\n", charname, errno); + fflush(stdout); + exit(12); + } + else if (nbytes == 0) + { + printf("ERROR: Unexpected end-of file in %s\n", charname); + fflush(stdout); + exit(13); + } + else if (nbytes != geo.blocksize) + { + printf("ERROR: Unexpected read size from %s: %ld\n", + charname, (unsigned long)nbytes); + fflush(stdout); + exit(14); } /* Since we forced the size of the partition to be an even number @@ -358,19 +396,19 @@ int main(int argc, FAR char *argv[]) else if (nbytes == 0) { - printf("ERROR: Unexpected end of file on %s\n", mtdname); - status = 12; - goto err_fd; + printf("ERROR: Unexpected end of file on %s\n", charname); + fflush(stdout); + exit(15); } /* This is not expected at all */ else if (nbytes != geo.blocksize) { - printf("ERROR: Short read from %s failed: %lu\n", - mtdname, (unsigned long)nbytes); - status = 13; - goto err_fd; + printf("ERROR: Short read from %s failed: %lu\n", + charname, (unsigned long)nbytes); + fflush(stdout); + exit(16); } /* Verify the offsets in the block */ @@ -381,8 +419,8 @@ int main(int argc, FAR char *argv[]) { printf("ERROR: Bad offset %lu, expected %lu\n", (long)buffer[k], (long)check); - status = 14; - goto err_fd; + fflush(stdout); + exit(17); } /* Invert the value to indicate that we have verified @@ -400,8 +438,8 @@ int main(int argc, FAR char *argv[]) { printf("ERROR: lseek to offset %ld failed: %d\n", (unsigned long)sectoff, errno); - status = 15; - goto err_fd; + fflush(stdout); + exit(18); } /* Now write the block back to FLASH with the modified value */ @@ -409,16 +447,16 @@ int main(int argc, FAR char *argv[]) nbytes = write(fd, buffer, geo.blocksize); if (nbytes < 0) { - printf("ERROR: write to %s failed: %d\n", mtdname, errno); - status = 16; - goto err_fd; + printf("ERROR: write to %s failed: %d\n", charname, errno); + fflush(stdout); + exit(19); } else if (nbytes != geo.blocksize) { printf("ERROR: Unexpected write size to %s: %ld\n", - mtdname, (unsigned long)nbytes); - status = 17; - goto err_fd; + charname, (unsigned long)nbytes); + fflush(stdout); + exit(20); } /* Get the offset to the next block */ @@ -432,15 +470,15 @@ int main(int argc, FAR char *argv[]) if (nbytes != 0) { printf("ERROR: Expected end-of-file from %s failed: %zd %d\n", - mtdname, nbytes, errno); - status = 18; - goto err_fd; + charname, nbytes, errno); + fflush(stdout); + exit(22); } close(fd); } - /* Now verify that all of the verified blocks appear where we thing they + /* Now verify that all of the verifed blocks appear where we thing they * should on the device. */ @@ -450,8 +488,8 @@ int main(int argc, FAR char *argv[]) if (fd < 0) { printf("ERROR: open /dev/mtd0 failed: %d\n", errno); - status = 19; - goto err_buf; + fflush(stdout); + exit(23); } offset = 0; @@ -464,22 +502,22 @@ int main(int argc, FAR char *argv[]) nbytes = read(fd, buffer, geo.blocksize); if (nbytes < 0) { - printf("ERROR: read from /dev/mtd0 failed: %d\n", errno); - status = 20; - goto err_fd; + printf("ERROR: read from %s failed: %d\n", charname, errno); + fflush(stdout); + exit(24); } else if (nbytes == 0) { - printf("ERROR: Unexpected end-of file in /dev/mtd0\n"); - status = 21; - goto err_fd; + printf("ERROR: Unexpected end-of file in %s\n", charname); + fflush(stdout); + exit(25); } else if (nbytes != geo.blocksize) { - printf("ERROR: Unexpected read size from /dev/mtd0: %ld\n", - (unsigned long)nbytes); - status = 22; - goto err_fd; + printf("ERROR: Unexpected read size from %s: %ld\n", + charname, (unsigned long)nbytes); + fflush(stdout); + exit(26); } /* Verify the values in the block */ @@ -490,40 +528,19 @@ int main(int argc, FAR char *argv[]) { printf("ERROR: Bad value %lu, expected %lu\n", (long)buffer[k], (long)(~check)); - status = 23; - goto err_fd; + fflush(stdout); + exit(27); } check += sizeof(uint32_t); } } - status = 0; + close(fd); /* And exit without bothering to clean up */ printf("PASS: Everything looks good\n"); - -err_fd: - close(fd); - -err_buf: - free(buffer); - -err_part_mtd: - for (i = 1; i <= CONFIG_EXAMPLES_MTDPART_NPARTITIONS; i++) - { - snprintf(mtdname, sizeof(mtdname), "/dev/mtd%d", i); - unregister_mtddriver(mtdname); - } - -err_master_mtd: - unregister_mtddriver("/dev/mtd0"); -#ifdef CONFIG_EXAMPLES_MTDPART_ARCHINIT - mtdpart_archuninitialize(master); -#else - rammtd_uninitialize(master); -#endif fflush(stdout); - exit(status); + return 0; } diff --git a/examples/mtdrwb/CMakeLists.txt b/examples/mtdrwb/CMakeLists.txt deleted file mode 100644 index f0e53117d..000000000 --- a/examples/mtdrwb/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# ############################################################################## -# apps/examples/mtdrwb/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_MTDRWB) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_MTDRWB_PROGNAME} - STACKSIZE - ${CONFIG_DEFAULT_TASK_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_MTDRWB} - SRCS - mtdrwb_main.c) -endif() diff --git a/examples/mtdrwb/Make.defs b/examples/mtdrwb/Make.defs index b5f983c5e..c63649109 100644 --- a/examples/mtdrwb/Make.defs +++ b/examples/mtdrwb/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/mtdrwb/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/mtdrwb/Makefile b/examples/mtdrwb/Makefile index 79831664d..53798ec6e 100644 --- a/examples/mtdrwb/Makefile +++ b/examples/mtdrwb/Makefile @@ -1,7 +1,5 @@ ############################################################################ -# apps/examples/mtdrwb/Makefile -# -# SPDX-License-Identifier: Apache-2.0 +# apps/apps/examples/mtdrwb/Makefile # # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with diff --git a/examples/mtdrwb/mtdrwb_main.c b/examples/mtdrwb/mtdrwb_main.c index 93b9d3290..7110f112a 100644 --- a/examples/mtdrwb/mtdrwb_main.c +++ b/examples/mtdrwb/mtdrwb_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/mtdrwb/mtdrwb_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -31,7 +29,7 @@ #include <unistd.h> #include <fcntl.h> #include <errno.h> -#include <nuttx/debug.h> +#include <debug.h> #include <nuttx/mtd/mtd.h> #include <nuttx/drivers/drivers.h> diff --git a/examples/netlink_route/CMakeLists.txt b/examples/netlink_route/CMakeLists.txt deleted file mode 100644 index 57d14f977..000000000 --- a/examples/netlink_route/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# ############################################################################## -# apps/examples/netlink_route/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_NETLINK_ROUTE) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_NETLINK_ROUTE_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_NETLINK_ROUTE_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_NETLINK_ROUTE_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_NETLINK_ROUTE} - SRCS - netlink_route_main.c) -endif() diff --git a/examples/netlink_route/Make.defs b/examples/netlink_route/Make.defs index 7b46636ba..0fdbd42d0 100644 --- a/examples/netlink_route/Make.defs +++ b/examples/netlink_route/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/netlink_route/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/netlink_route/Makefile b/examples/netlink_route/Makefile index 9fd5052c8..dd6c790db 100644 --- a/examples/netlink_route/Makefile +++ b/examples/netlink_route/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/netlink_route/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/netlink_route/netlink_route_main.c b/examples/netlink_route/netlink_route_main.c index 896a9796e..0c6aef187 100644 --- a/examples/netlink_route/netlink_route_main.c +++ b/examples/netlink_route/netlink_route_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/netlink_route/netlink_route_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -36,9 +34,9 @@ #include <net/if.h> #include <net/route.h> #include <net/ethernet.h> -#include <netinet/arp.h> #include <netinet/in.h> +#include <nuttx/net/arp.h> #include <nuttx/net/neighbor.h> #include "netutils/netlib.h" @@ -50,7 +48,7 @@ ****************************************************************************/ #define MAX_DEVICES 16 -#define MAX_ROUTES 4 +#define MAX_ROUTES 64 #ifdef CONFIG_NET_IPv6 # define ROUTE_BUFSIZE INET6_ADDRSTRLEN @@ -150,11 +148,11 @@ static void dump_neighbor(void) { if ((j + 1) >= nb->ne_addr.na_llsize) { - printf("%02x", nb->ne_addr.u.na_addr[j]); + printf("%02x", nb->ne_addr.u.na_addr); } else { - printf("%02x.", nb->ne_addr.u.na_addr[j]); + printf("%02x.", nb->ne_addr.u.na_addr); } } @@ -168,7 +166,11 @@ static void dump_neighbor(void) printf(" "); } +#ifdef CONFIG_SYSTEM_TIME64 printf("Time 0x%" PRIx64 "\n", nb->ne_time); +#else + printf("Time 0x%" PRIx32 "\n", nb->ne_time); +#endif } free(nbtab); @@ -180,8 +182,8 @@ static void dump_neighbor(void) #if defined(CONFIG_NET_ARP) && !defined(CONFIG_NETLINK_DISABLE_GETNEIGH) static void dump_arp(void) { - FAR struct arpreq *arptab; - char buffer[INET_ADDRSTRLEN]; + FAR struct arp_entry_s *arptab; + FAR char buffer[INET_ADDRSTRLEN]; size_t allocsize; ssize_t nentries; int i; @@ -191,8 +193,8 @@ static void dump_arp(void) /* Allocate a buffer to hold the ARP table */ - allocsize = CONFIG_NET_ARPTAB_SIZE * sizeof(struct arpreq); - arptab = (FAR struct arpreq *)malloc(allocsize); + allocsize = CONFIG_NET_ARPTAB_SIZE * sizeof(struct arp_entry_s); + arptab = (FAR struct arp_entry_s *)malloc(allocsize); if (arptab == NULL) { fprintf(stderr, "\nERROR: Failed to allocate ARP table\n"); @@ -215,23 +217,28 @@ static void dump_arp(void) for (i = 0; i < nentries; i++) { - FAR struct arpreq *arp = &arptab[i]; - FAR struct sockaddr_in *addr = (FAR struct sockaddr_in *)&arp->arp_pa; + FAR struct arp_entry_s *arp = &arptab[i]; - inet_ntop(AF_INET, &addr->sin_addr.s_addr, buffer, INET_ADDRSTRLEN); + inet_ntop(AF_INET, &arp->at_ipaddr, buffer, INET_ADDRSTRLEN); printf(" Dest: %s MAC Addr: ", buffer); for (j = 0; j < ETHER_ADDR_LEN; j++) { if (j == (ETHER_ADDR_LEN - 1)) { - printf("%02x", (uint8_t)arp->arp_ha.sa_data[j]); + printf("%02x", arp->at_ethaddr.ether_addr_octet[j]); } else { - printf("%02x.", (uint8_t)arp->arp_ha.sa_data[j]); + printf("%02x.", arp->at_ethaddr.ether_addr_octet[j]); } } + +#ifdef CONFIG_SYSTEM_TIME64 + printf(" Time 0x%" PRIx64 "\n", arp->at_time); +#else + printf(" Time 0x%" PRIx32 "\n", arp->at_time); +#endif } free(arptab); diff --git a/examples/netloop/CMakeLists.txt b/examples/netloop/CMakeLists.txt deleted file mode 100644 index 22a4bedbe..000000000 --- a/examples/netloop/CMakeLists.txt +++ /dev/null @@ -1,36 +0,0 @@ -# ############################################################################## -# apps/examples/netloop/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_NETLOOP) - nuttx_add_application( - NAME - netloop - PRIORITY - ${CONFIG_EXAMPLES_NETLOOP_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_NETLOOP_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_NETLOOP} - SRCS - lo_main.c) - target_sources(apps PRIVATE lo_listener.c) -endif() diff --git a/examples/netloop/Make.defs b/examples/netloop/Make.defs index aac6a4db9..2478605a2 100644 --- a/examples/netloop/Make.defs +++ b/examples/netloop/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/netloop/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/netloop/Makefile b/examples/netloop/Makefile index bb6c3d73f..486cb02d4 100644 --- a/examples/netloop/Makefile +++ b/examples/netloop/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/netloop/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/netloop/lo_listener.c b/examples/netloop/lo_listener.c index 57362cec8..e1d2831d7 100644 --- a/examples/netloop/lo_listener.c +++ b/examples/netloop/lo_listener.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/netloop/lo_listener.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -39,7 +37,7 @@ #include <string.h> #include <pthread.h> #include <errno.h> -#include <nuttx/debug.h> +#include <debug.h> #include <net/if.h> #include <arpa/inet.h> @@ -64,7 +62,7 @@ struct net_listener_s struct sockaddr_in addr; fd_set master; fd_set working; - char buffer[IOBUFFER_SIZE + 1]; + char buffer[IOBUFFER_SIZE]; int listensd; int mxsd; }; @@ -87,9 +85,7 @@ static bool net_closeclient(struct net_listener_s *nls, int sd) close(sd); FD_CLR(sd, &nls->master); - /* If we just closed the max SD, then search downward for the next - * biggest SD. - */ + /* If we just closed the max SD, then search downward for the next biggest SD. */ while (FD_ISSET(nls->mxsd, &nls->master) == false) { @@ -112,7 +108,7 @@ static inline bool net_incomingdata(struct net_listener_s *nls, int sd) /* Read data from the socket */ #ifdef FIONBIO - for (; ; ) + for (;;) #endif { printf("lo_listener: Read data from sd=%d\n", sd); @@ -137,7 +133,7 @@ static inline bool net_incomingdata(struct net_listener_s *nls, int sd) } else { - nls->buffer[ret] = '\0'; + nls->buffer[ret]='\0'; printf("lo_listener: Read '%s' (%d bytes)\n", nls->buffer, ret); /* Echo the data back to the client */ @@ -149,10 +145,9 @@ static inline bool net_incomingdata(struct net_listener_s *nls, int sd) { if (errno != EINTR) { - printf("lo_listener: Send failed sd=%d: %d\n", - sd, errno); - net_closeclient(nls, sd); - return false; + printf("lo_listener: Send failed sd=%d: %d\n", sd, errno); + net_closeclient(nls, sd); + return false; } } else @@ -178,13 +173,12 @@ static inline bool net_connection(struct net_listener_s *nls) /* Loop until all connections have been processed */ #ifdef FIONBIO - for (; ; ) + for (;;) #endif { - printf("lo_listener: Accepting new connection on sd=%d\n", - nls->listensd); + printf("lo_listener: Accepting new connection on sd=%d\n", nls->listensd); - sd = accept4(nls->listensd, NULL, NULL, SOCK_CLOEXEC); + sd = accept(nls->listensd, NULL, NULL); if (sd < 0) { printf("lo_listener: accept failed: %d\n", errno); @@ -235,8 +229,7 @@ static inline bool net_mksocket(struct net_listener_s *nls) /* Configure the socket */ value = 1; - ret = setsockopt(nls->listensd, SOL_SOCKET, - SO_REUSEADDR, &value, sizeof(int)); + ret = setsockopt(nls->listensd, SOL_SOCKET, SO_REUSEADDR, (char*)&value, sizeof(int)); if (ret < 0) { printf("lo_listener: setsockopt failed: %d\n", errno); @@ -262,8 +255,7 @@ static inline bool net_mksocket(struct net_listener_s *nls) nls->addr.sin_family = AF_INET; nls->addr.sin_port = htons(LISTENER_PORT); nls->addr.sin_addr.s_addr = htonl(LO_ADDRESS); - ret = bind(nls->listensd, (struct sockaddr *)&nls->addr, - sizeof(struct sockaddr_in)); + ret = bind(nls->listensd, (struct sockaddr *)&nls->addr, sizeof(struct sockaddr_in)); if (ret < 0) { printf("lo_listener: bind failed: %d\n", errno); @@ -305,7 +297,7 @@ void *lo_listener(pthread_addr_t pvarg) memset(&nls, 0, sizeof(struct net_listener_s)); if (!net_mksocket(&nls)) { - return (void *)(uintptr_t)1; + return (void*)1; } /* Initialize the 'master' file descriptor set */ @@ -323,14 +315,13 @@ void *lo_listener(pthread_addr_t pvarg) * on any of the connect sockets. */ - for (; ; ) + for (;;) { /* Wait on select */ - printf("lo_listener: Calling select(), listener sd=%d\n", - nls.listensd); + printf("lo_listener: Calling select(), listener sd=%d\n", nls.listensd); memcpy(&nls.working, &nls.master, sizeof(fd_set)); - ret = select(nls.mxsd + 1, &nls.working, NULL, NULL, &timeout); + ret = select(nls.mxsd + 1, (FAR fd_set*)&nls.working, (FAR fd_set*)NULL, (FAR fd_set*)NULL, &timeout); if (ret < 0) { printf("lo_listener: select failed: %d\n", errno); @@ -374,7 +365,7 @@ void *lo_listener(pthread_addr_t pvarg) /* Cleanup */ #if 0 /* Don't get here */ - for (i = 0; i <= nls.mxsd; +i++) + for (i = 0; i <= nls.mxsd; +i++) { if (FD_ISSET(i, &nls.master)) { @@ -382,6 +373,5 @@ void *lo_listener(pthread_addr_t pvarg) } } #endif - return NULL; /* Keeps some compilers from complaining */ } diff --git a/examples/netloop/lo_main.c b/examples/netloop/lo_main.c index 3c6a0c72f..12dede13b 100644 --- a/examples/netloop/lo_main.c +++ b/examples/netloop/lo_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/netloop/lo_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -37,7 +35,7 @@ #include <fcntl.h> #include <poll.h> #include <errno.h> -#include <nuttx/debug.h> +#include <debug.h> #include <arpa/inet.h> #include <netinet/in.h> @@ -63,7 +61,7 @@ static int lo_client(void) { struct sockaddr_in myaddr; char outbuf[IOBUFFER_SIZE]; - char inbuf[IOBUFFER_SIZE + 1]; + char inbuf[IOBUFFER_SIZE]; int sockfd; int len; int nbytessent; @@ -154,7 +152,7 @@ static int lo_client(void) for (i = 0; ; i++) { - snprintf(outbuf, sizeof(outbuf), "Loopback message %d", i); + sprintf(outbuf, "Loopback message %d", i); len = strlen(outbuf); printf("lo_client: Sending '%s' (%d bytes)\n", outbuf, len); diff --git a/examples/netloop/netloop.h b/examples/netloop/netloop.h index 2696e89ae..e6788f08f 100644 --- a/examples/netloop/netloop.h +++ b/examples/netloop/netloop.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/netloop/netloop.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -45,6 +43,7 @@ * buffering s not yet support for UDP) */ + #ifndef CONFIG_NET # error Network socket support not enabled #endif diff --git a/examples/netpkt/CMakeLists.txt b/examples/netpkt/CMakeLists.txt deleted file mode 100644 index 54da626d4..000000000 --- a/examples/netpkt/CMakeLists.txt +++ /dev/null @@ -1,43 +0,0 @@ -# ############################################################################## -# apps/examples/netpkt/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_NETPKT) - nuttx_add_application( - NAME - netpkt - STACKSIZE - ${CONFIG_DEFAULT_TASK_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_NETPKT} - SRCS - netpkt_main.c) - - nuttx_add_application( - NAME - netpkt_ethercat - STACKSIZE - ${CONFIG_DEFAULT_TASK_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_NETPKT} - SRCS - netpkt_ethercat.c) -endif() diff --git a/examples/netpkt/Make.defs b/examples/netpkt/Make.defs index 2c6ceecc9..ff4735448 100644 --- a/examples/netpkt/Make.defs +++ b/examples/netpkt/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/netpkt/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/netpkt/Makefile b/examples/netpkt/Makefile index b3c056a6d..da915f388 100644 --- a/examples/netpkt/Makefile +++ b/examples/netpkt/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/netpkt/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -24,13 +22,13 @@ include $(APPDIR)/Make.defs # Network packet socket example -PROGNAME = netpkt netpkt_ethercat +PROGNAME = netpkt PRIORITY = SCHED_PRIORITY_DEFAULT STACKSIZE = $(CONFIG_DEFAULT_TASK_STACKSIZE) MODULE = $(CONFIG_EXAMPLES_NETPKT) # MDIO tool -MAINSRC = netpkt_main.c netpkt_ethercat.c +MAINSRC = netpkt_main.c include $(APPDIR)/Application.mk diff --git a/examples/netpkt/netpkt_ethercat.c b/examples/netpkt/netpkt_ethercat.c deleted file mode 100644 index ea24791a7..000000000 --- a/examples/netpkt/netpkt_ethercat.c +++ /dev/null @@ -1,131 +0,0 @@ -/**************************************************************************** - * apps/examples/netpkt/netpkt_ethercat.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <stdint.h> -#include <stdio.h> -#include <time.h> - -#include <net/if.h> -#include <netinet/if_ether.h> -#include <netinet/in.h> -#include <netinet/ip.h> -#include <netpacket/packet.h> -#include <sys/socket.h> - -#include <nuttx/clock.h> - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static void usage(void) -{ - printf("usage: netpkt_ethercat [<ifname> [times]]\n"); -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -int main(int argc, FAR const char *argv[]) -{ - struct timespec send_time; - struct timespec recv_time; - struct sockaddr_ll addr; - uint8_t sendbuff[60] = - { - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x9c, 0x7f, 0x81, 0x3c, 0x1e, 0x8e, - 0x88, 0xa4, 0x0e, 0x10, 0x07, 0x4a, 0x00, 0x00, 0x30, 0x01, 0x02, 0x00, - }; - - uint8_t recvbuff[100]; - FAR const char *ifname = "eth0"; - int repeat = 10; - int num_packets = 0; - int len; - int ifindex; - int sockfd = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL)); - - if (sockfd == -1) - { - perror("ERROR: creating socket failed"); - return -errno; - } - - if (argc >= 2) - { - ifname = argv[1]; - } - - ifindex = if_nametoindex(ifname); - - if (argc >= 3) - { - repeat = atoi(argv[2]); - } - - if (ifindex == 0) - { - printf("Failed to get index of device %s\n", ifname); - close(sockfd); - usage(); - return -errno; - } - - addr.sll_family = AF_PACKET; - addr.sll_ifindex = ifindex; - addr.sll_protocol = htons(ETH_P_ALL); - if (bind(sockfd, (FAR const struct sockaddr *)&addr, sizeof(addr)) < 0) - { - perror("ERROR: binding socket failed"); - close(sockfd); - usage(); - return -errno; - } - - for (num_packets = 0; num_packets < repeat; num_packets++) - { - clock_gettime(CLOCK_REALTIME, &send_time); - if (sendto(sockfd, sendbuff, 60, 0, NULL, 0) < 0) - { - perror("ERROR: sendto socket failed"); - continue; - } - - len = recvfrom(sockfd, recvbuff, 100, 0, NULL, NULL); - clock_gettime(CLOCK_REALTIME, &recv_time); - printf("Data recv: %d bytes, spent time %jd ns\n", len, - (intmax_t)(recv_time.tv_sec - send_time.tv_sec) * - NSEC_PER_SEC + recv_time.tv_nsec - send_time.tv_nsec); - usleep(1000); - } - - close(sockfd); - - return 0; -} diff --git a/examples/netpkt/netpkt_main.c b/examples/netpkt/netpkt_main.c index ab0595be4..94a37f050 100644 --- a/examples/netpkt/netpkt_main.c +++ b/examples/netpkt/netpkt_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/netpkt/netpkt_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -29,10 +27,7 @@ #include <string.h> #include <sys/socket.h> #include <unistd.h> -#include <netinet/if_ether.h> -#include <netinet/in.h> #include <netpacket/packet.h> -#include <net/if.h> /**************************************************************************** * Private Functions @@ -42,17 +37,11 @@ * Name: psock_create ****************************************************************************/ -static int psock_create(const char *ifname) +static int psock_create(void) { int sd; struct sockaddr_ll addr; int addrlen = sizeof(addr); - unsigned int ifindex = 0; - - if (ifname && ifname[0]) - { - ifindex = if_nametoindex(ifname); - } sd = socket(AF_PACKET, SOCK_RAW, 0); if (sd < 0) @@ -64,8 +53,7 @@ static int psock_create(const char *ifname) /* Prepare sockaddr struct */ addr.sll_family = AF_PACKET; - addr.sll_ifindex = ifindex; - addr.sll_protocol = htons(ETH_P_ALL); + addr.sll_ifindex = 0; if (bind(sd, (const struct sockaddr *)&addr, addrlen) < 0) { perror("ERROR: binding socket failed"); @@ -115,7 +103,6 @@ static void netpkt_usage(void) printf(" -r receive\n"); printf(" -t transmit\n"); printf(" -v verbose\n"); - printf(" -i <IF> specify interface name (e.g. eth0)\n"); printf("\n"); } @@ -127,7 +114,7 @@ static void netpkt_usage(void) * Name: netpkt_main ****************************************************************************/ -int main(int argc, char *argv[]) +int main(int argc, FAR char *argv[]) { int sd; int i; @@ -151,9 +138,6 @@ int main(int argc, char *argv[]) int do_rxtimes = 3; int do_tx = 0; int do_txtimes = 3; - char ifname[IFNAMSIZ]; - - memset(ifname, 0, sizeof(ifname)); if (argc == 1) { @@ -163,7 +147,7 @@ int main(int argc, char *argv[]) /* Parse arguments */ - while ((opt = getopt(argc, argv, "artvi:")) != -1) + while ((opt = getopt(argc, argv, "artv")) != -1) { switch (opt) { @@ -184,17 +168,13 @@ int main(int argc, char *argv[]) verbose = 1; break; - case 'i': - strlcpy(ifname, optarg, sizeof(ifname)); - break; - default: netpkt_usage(); return -1; } } - sd = psock_create(ifname); + sd = psock_create(); if (do_tx) { diff --git a/examples/nettest/CMakeLists.txt b/examples/nettest/CMakeLists.txt deleted file mode 100644 index fafdec236..000000000 --- a/examples/nettest/CMakeLists.txt +++ /dev/null @@ -1,103 +0,0 @@ -# ############################################################################## -# apps/examples/nettest/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_NETTEST) - - set(CSRCS) - - # Basic TCP networking test - - set(SRCS nettest_cmdline.c) - if(CONFIG_EXAMPLES_NETTEST_INIT) - list(APPEND SRCS nettest_netinit.c) - endif() - - # Target 1 Files - - if(CONFIG_EXAMPLES_NETTEST_LOOPBACK) - list(APPEND SRCS nettest_server.c nettest_client.c) - elseif(CONFIG_EXAMPLES_NETTEST_SERVER) - list(APPEND SRCS nettest_server.c) - else() - list(APPEND SRCS nettest_client.c) - endif() - - # Target 1 Application Info - - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_NETTEST_PROGNAME1} - SRCS - nettest_target1.c - INCLUDE_DIRECTORIES - ${CMAKE_BINARY_DIR}/include/nuttx - STACKSIZE - ${CONFIG_EXAMPLES_NETTEST_STACKSIZE1} - PRIORITY - ${CONFIG_EXAMPLES_NETTEST_PRIORITY1}) - - # Target 2 - - if(CONFIG_EXAMPLES_NETTEST_TARGET2) - - if(CONFIG_EXAMPLES_NETTEST_SERVER) - list(APPEND SRCS nettest_client.c) - else() - list(APPEND SRCS nettest_server.c) - endif() - - # Target 2 Application Info - - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_NETTEST_PROGNAME2} - SRCS - nettest_target2.c - INCLUDE_DIRECTORIES - ${CMAKE_BINARY_DIR}/include/nuttx - STACKSIZE - ${CONFIG_EXAMPLES_NETTEST_STACKSIZE2} - PRIORITY - ${CONFIG_EXAMPLES_NETTEST_PRIORITY2}) - - endif() - - target_include_directories(apps PRIVATE ${CMAKE_BINARY_DIR}/include/nuttx) - target_sources(apps PRIVATE ${SRCS}) - - # Host - - if(NOT CONFIG_EXAMPLES_NETTEST_TARGET2 AND NOT - CONFIG_EXAMPLES_NETTEST_LOOPBACK) - ExternalProject_Add( - nettest - SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/host - INSTALL_DIR ${CMAKE_BINARY_DIR}/apps/examples/nettest/host - CMAKE_ARGS - -DNUTTX_DIR=${NUTTX_DIR} -DNUTTX_BINARY_DIR=${CMAKE_BINARY_DIR} - -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/apps/examples/nettest/host - USES_TERMINAL_CONFIGURE true - USES_TERMINAL_BUILD true - USES_TERMINAL_INSTALL true) - endif() - -endif() diff --git a/examples/nettest/Kconfig b/examples/nettest/Kconfig index fe045c4de..5c3d31fea 100644 --- a/examples/nettest/Kconfig +++ b/examples/nettest/Kconfig @@ -129,7 +129,8 @@ endchoice # IP Domain config EXAMPLES_NETTEST_INIT bool "Initialize network" - default !NSH_NETINIT + default n if NSH_NETINIT + default y if !NSH_NETINIT depends on !EXAMPLES_NETTEST_LOOPBACK ---help--- Include logic to initialize the network. This should not be done if diff --git a/examples/nettest/Make.defs b/examples/nettest/Make.defs index 36647cfc1..a18a3eca3 100644 --- a/examples/nettest/Make.defs +++ b/examples/nettest/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/nettest/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/nettest/Makefile b/examples/nettest/Makefile index 763cd4476..9cd52eacf 100644 --- a/examples/nettest/Makefile +++ b/examples/nettest/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/nettest/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/nettest/host/CMakeLists.txt b/examples/nettest/host/CMakeLists.txt deleted file mode 100644 index 6a06817e8..000000000 --- a/examples/nettest/host/CMakeLists.txt +++ /dev/null @@ -1,54 +0,0 @@ -# ############################################################################## -# apps/examples/nettest/host/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## -# Configure project -cmake_minimum_required(VERSION 3.16) -project(nuttx_tools LANGUAGES C) - -include(${NUTTX_DIR}/cmake/nuttx_kconfig.cmake) -nuttx_export_kconfig(${NUTTX_BINARY_DIR}/.config) - -set(HOST_SRCS ../nettest_host.c) -if(CONFIG_EXAMPLES_NETTEST_SERVER) - set(HOST_TARGET tcpclient) - add_executable(tcpclient ../nettest_client.c ${HOST_SRCS}) - install(TARGETS tcpclient DESTINATION bin) -else() - set(HOST_TARGET tcpserver) - add_executable(tcpserver ../nettest_server.c ${HOST_SRCS}) - install(TARGETS tcpserver DESTINATION bin) -endif() - -target_compile_definitions(${HOST_TARGET} PRIVATE NETTEST_HOST=1) -if(CONFIG_EXAMPLES_NETTEST_SERVER) - target_compile_definitions( - ${HOST_TARGET} - PRIVATE - CONFIG_EXAMPLES_NETTEST_SERVER=1 - CONFIG_EXAMPLES_NETTEST_SERVERIP="${CONFIG_EXAMPLES_NETTEST_SERVERIP}") -endif() -if(CONFIG_EXAMPLES_NETTEST_PERFORMANCE) - target_compile_definitions(${HOST_TARGET} - PRIVATE CONFIG_EXAMPLES_NETTEST_PERFORMANCE=1) -endif() - -target_include_directories(${HOST_TARGET} - PRIVATE ${NUTTX_BINARY_DIR}/include/nuttx) diff --git a/examples/nettest/nettest.h b/examples/nettest/nettest.h index fd314befb..9a9e8bd58 100644 --- a/examples/nettest/nettest.h +++ b/examples/nettest/nettest.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/nettest/nettest.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -31,7 +29,7 @@ #ifdef NETTEST_HOST #else -# include <nuttx/debug.h> +# include <debug.h> #endif /**************************************************************************** diff --git a/examples/nettest/nettest_client.c b/examples/nettest/nettest_client.c index c6070b7c6..9a3a10408 100644 --- a/examples/nettest/nettest_client.c +++ b/examples/nettest/nettest_client.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/nettest/nettest_client.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/nettest/nettest_cmdline.c b/examples/nettest/nettest_cmdline.c index 397e0aa7c..76736d79d 100644 --- a/examples/nettest/nettest_cmdline.c +++ b/examples/nettest/nettest_cmdline.c @@ -1,7 +1,5 @@ /**************************************************************************** - * apps/examples/nettest/nettest_cmdline.c - * - * SPDX-License-Identifier: Apache-2.0 + * apps/examples/nettest/netest_cmdline.c * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with diff --git a/examples/nettest/nettest_host.c b/examples/nettest/nettest_host.c index e6dfb4eaf..6e6ce25bd 100644 --- a/examples/nettest/nettest_host.c +++ b/examples/nettest/nettest_host.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/nettest/nettest_host.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/nettest/nettest_netinit.c b/examples/nettest/nettest_netinit.c index e2e786164..481a7737f 100644 --- a/examples/nettest/nettest_netinit.c +++ b/examples/nettest/nettest_netinit.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/nettest/nettest_netinit.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -28,7 +26,7 @@ #include <stdbool.h> #include <stdio.h> -#include <nuttx/debug.h> +#include <debug.h> #include <arpa/inet.h> #include <netinet/in.h> diff --git a/examples/nettest/nettest_server.c b/examples/nettest/nettest_server.c index 26fca6088..aa2dd1ba1 100644 --- a/examples/nettest/nettest_server.c +++ b/examples/nettest/nettest_server.c @@ -1,7 +1,5 @@ /**************************************************************************** - * apps/examples/nettest/nettest_server.c - * - * SPDX-License-Identifier: Apache-2.0 + * apps/examples/nettest/nettest-server.c * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -89,7 +87,7 @@ void nettest_server(void) optval = 1; if (setsockopt(listensd, SOL_SOCKET, SO_REUSEADDR, - &optval, sizeof(int)) < 0) + (void *)&optval, sizeof(int)) < 0) { printf("server: setsockopt SO_REUSEADDR failure: %d\n", errno); goto errout_with_listensd; @@ -147,12 +145,7 @@ void nettest_server(void) printf("server: Accepting connections on port %d\n", CONFIG_EXAMPLES_NETTEST_SERVER_PORTNO); -#ifdef __NuttX__ - acceptsd = accept4(listensd, (struct sockaddr *)&myaddr, &addrlen, - SOCK_CLOEXEC); -#else acceptsd = accept(listensd, (struct sockaddr *)&myaddr, &addrlen); -#endif if (acceptsd < 0) { printf("server: accept failure: %d\n", errno); diff --git a/examples/nettest/nettest_target1.c b/examples/nettest/nettest_target1.c index 47db8916b..9a14f3fe8 100644 --- a/examples/nettest/nettest_target1.c +++ b/examples/nettest/nettest_target1.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/nettest/nettest_target1.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -32,7 +30,7 @@ #include <stdio.h> #include <unistd.h> #include <sched.h> -#include <nuttx/debug.h> +#include <debug.h> #include "nettest.h" diff --git a/examples/nettest/nettest_target2.c b/examples/nettest/nettest_target2.c index 4a56f18a2..43e4e0806 100644 --- a/examples/nettest/nettest_target2.c +++ b/examples/nettest/nettest_target2.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/nettest/nettest_target2.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/nimble/CMakeLists.txt b/examples/nimble/CMakeLists.txt deleted file mode 100644 index 6298d5d4a..000000000 --- a/examples/nimble/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# ############################################################################## -# apps/examples/nimble/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_NIMBLE) - nuttx_add_application( - NAME - nimble - SRCS - ${CMAKE_CURRENT_LIST_DIR}/nimble_main.c - INCLUDE_DIRECTORIES - $<GENEX_EVAL:$<TARGET_PROPERTY:nimble,INCLUDE_DIRECTORIES>> - DEPENDS - nimble) -endif() diff --git a/examples/nimble/Kconfig b/examples/nimble/Kconfig deleted file mode 100644 index 1fc566378..000000000 --- a/examples/nimble/Kconfig +++ /dev/null @@ -1,30 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config EXAMPLES_NIMBLE - tristate "NimBLE example" - default n - ---help--- - Enable the nimble example - -if EXAMPLES_NIMBLE - -config EXAMPLES_NIMBLE_PROGNAME - string "Program name" - default "nimble" - ---help--- - This is the name of the program that will be used when the NSH ELF - program is installed. - -config EXAMPLES_NIMBLE_PRIORITY - int "NimBLE task priority" - default 100 - -config EXAMPLES_NIMBLE_STACKSIZE - int "NimBLE stack size" - default DEFAULT_TASK_STACKSIZE - -endif # EXAMPLES_NIMBLE - diff --git a/examples/nimble/Make.defs b/examples/nimble/Make.defs deleted file mode 100644 index 09cc79a8b..000000000 --- a/examples/nimble/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/examples/nimble/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_EXAMPLES_NIMBLE),) -CONFIGURED_APPS += $(APPDIR)/examples/nimble -endif diff --git a/examples/nimble/Makefile b/examples/nimble/Makefile deleted file mode 100644 index 6b75c2aa1..000000000 --- a/examples/nimble/Makefile +++ /dev/null @@ -1,38 +0,0 @@ -############################################################################ -# apps/examples/nimble/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -# NimBLE built-in application info - -PROGNAME = $(CONFIG_EXAMPLES_NIMBLE_PROGNAME) -PRIORITY = $(CONFIG_EXAMPLES_NIMBLE_PRIORITY) -STACKSIZE = $(CONFIG_EXAMPLES_NIMBLE_STACKSIZE) -MODULE = $(CONFIG_EXAMPLES_NIMBLE) - -# NimBLE Example - -MAINSRC = nimble_main.c - -include $(APPDIR)/wireless/bluetooth/nimble/Makefile.nimble - -include $(APPDIR)/Application.mk diff --git a/examples/nimble/nimble_main.c b/examples/nimble/nimble_main.c deleted file mode 100644 index 68eb2f051..000000000 --- a/examples/nimble/nimble_main.c +++ /dev/null @@ -1,313 +0,0 @@ -/**************************************************************************** - * apps/examples/nimble/nimble_main.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <stdbool.h> -#include <stdint.h> -#include <stdlib.h> -#include <stdio.h> -#include <pthread.h> -#include <unistd.h> -#include <sys/boardctl.h> -#include <assert.h> - -#include "netutils/netinit.h" - -#include "nimble/nimble_npl.h" -#include "nimble/nimble_port.h" - -#include "host/ble_hs.h" -#include "host/util/util.h" - -#include "services/gap/ble_svc_gap.h" -#include "services/gatt/ble_svc_gatt.h" -#include "services/ans/ble_svc_ans.h" -#include "services/ias/ble_svc_ias.h" -#include "services/lls/ble_svc_lls.h" -#include "services/tps/ble_svc_tps.h" -#include "services/bas/ble_svc_bas.h" -#include "services/dis/ble_svc_dis.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* Not used now */ - -#define TASK_DEFAULT_PRIORITY CONFIG_EXAMPLES_NIMBLE_PRIORITY -#define TASK_DEFAULT_STACK NULL -#define TASK_DEFAULT_STACK_SIZE 0 - -/**************************************************************************** - * External Functions Prototypes - ****************************************************************************/ - -void ble_hci_sock_ack_handler(FAR void *param); -void ble_hci_sock_set_device(int dev); - -/**************************************************************************** - * Private Functions Prototypes - ****************************************************************************/ - -static void put_ad(uint8_t ad_type, uint8_t ad_len, FAR const void *ad, - FAR uint8_t *buf, FAR uint8_t *len); -static void update_ad(void); -static void start_advertise(void); -static int gap_event_cb(FAR struct ble_gap_event *event, FAR void *arg); -static void app_ble_sync_cb(void); -static void nimble_host_task(FAR void *param); -static FAR void *ble_hci_sock_task(FAR void *param); -static FAR void *ble_host_task(FAR void *param); - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static const char *g_gap_name = "NuttX NimBLE"; -static uint8_t g_own_addr_type; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: put_ad - ****************************************************************************/ - -static void put_ad(uint8_t ad_type, uint8_t ad_len, FAR const void *ad, - FAR uint8_t *buf, FAR uint8_t *len) -{ - buf[(*len)++] = ad_len + 1; - buf[(*len)++] = ad_type; - - memcpy(&buf[*len], ad, ad_len); - - *len += ad_len; -} - -/**************************************************************************** - * Name: update_ad - ****************************************************************************/ - -static void update_ad(void) -{ - uint8_t ad_flags = BLE_HS_ADV_F_DISC_GEN | BLE_HS_ADV_F_BREDR_UNSUP; - uint8_t ad_len = 0; - uint8_t ad[BLE_HS_ADV_MAX_SZ]; - - put_ad(BLE_HS_ADV_TYPE_FLAGS, 1, &ad_flags, ad, &ad_len); - put_ad(BLE_HS_ADV_TYPE_COMP_NAME, sizeof(g_gap_name), g_gap_name, - ad, &ad_len); - - ble_gap_adv_set_data(ad, ad_len); -} - -/**************************************************************************** - * Name: start_advertise - ****************************************************************************/ - -static void start_advertise(void) -{ - struct ble_gap_adv_params advp; - int rc; - - printf("advertise\n"); - - update_ad(); - - memset(&advp, 0, sizeof advp); - advp.conn_mode = BLE_GAP_CONN_MODE_UND; - advp.disc_mode = BLE_GAP_DISC_MODE_GEN; - rc = ble_gap_adv_start(g_own_addr_type, NULL, BLE_HS_FOREVER, - &advp, gap_event_cb, NULL); - assert(rc == 0); -} - -/**************************************************************************** - * Name: gap_event_cb - ****************************************************************************/ - -static int gap_event_cb(FAR struct ble_gap_event *event, FAR void *arg) -{ - switch (event->type) - { - case BLE_GAP_EVENT_CONNECT: - { - if (event->connect.status) - { - start_advertise(); - } - break; - } - - case BLE_GAP_EVENT_DISCONNECT: - { - start_advertise(); - break; - } - } - - return 0; -} - -/**************************************************************************** - * Name: app_ble_sync_cb - ****************************************************************************/ - -static void app_ble_sync_cb(void) -{ - ble_addr_t addr; - int rc; - - /* Generate new non-resolvable private address */ - - rc = ble_hs_id_gen_rnd(1, &addr); - assert(rc == 0); - - /* Set generated address */ - - rc = ble_hs_id_set_rnd(addr.val); - assert(rc == 0); - - rc = ble_hs_util_ensure_addr(0); - assert(rc == 0); - - rc = ble_hs_id_infer_auto(0, &g_own_addr_type); - assert(rc == 0); - - start_advertise(); -} - -/**************************************************************************** - * Name: nimble_host_task - ****************************************************************************/ - -static void nimble_host_task(FAR void *param) -{ - ble_hs_cfg.sync_cb = app_ble_sync_cb; - ble_svc_gap_device_name_set(g_gap_name); - nimble_port_run(); -} - -/**************************************************************************** - * Name: ble_hci_sock_task - ****************************************************************************/ - -static FAR void *ble_hci_sock_task(FAR void *param) -{ - ble_hci_sock_ack_handler(param); - return NULL; -} - -/**************************************************************************** - * Name: ble_host_task - ****************************************************************************/ - -static FAR void *ble_host_task(FAR void *param) -{ - nimble_host_task(param); - return NULL; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: nimble_main - ****************************************************************************/ - -int main(int argc, FAR char *argv[]) -{ - struct ble_npl_task s_task_host; - struct ble_npl_task s_task_hci; - uint8_t batt_level = 0; - int ret = 0; - - /* allow to specify custom hci */ - - if (argc > 1) - { - ble_hci_sock_set_device(atoi(argv[1])); - } - -#ifndef CONFIG_NSH_NETINIT - /* Bring up the network */ - - netinit_bringup(); -#endif - - nimble_port_init(); - - /* Initialize services */ - - ble_svc_gap_init(); - ble_svc_gatt_init(); - ble_svc_ans_init(); - ble_svc_ias_init(); - ble_svc_lls_init(); - ble_svc_tps_init(); - ble_svc_bas_init(); - ble_svc_dis_init(); - - /* Create task which handles HCI socket */ - - ret = ble_npl_task_init(&s_task_hci, "hci_sock", ble_hci_sock_task, - NULL, TASK_DEFAULT_PRIORITY, BLE_NPL_TIME_FOREVER, - TASK_DEFAULT_STACK, TASK_DEFAULT_STACK_SIZE); - if (ret != 0) - { - printf("ERROR: starting hci task: %i\n", ret); - } - - /* Create task which handles default event queue for host stack. */ - - ret = ble_npl_task_init(&s_task_host, "ble_host", ble_host_task, - NULL, TASK_DEFAULT_PRIORITY, BLE_NPL_TIME_FOREVER, - TASK_DEFAULT_STACK, TASK_DEFAULT_STACK_SIZE); - if (ret != 0) - { - printf("ERROR: starting ble task: %i\n", ret); - } - - while (true) - { - /* Simulate battery */ - - batt_level += 1; - if (batt_level > 100) - { - batt_level = 0; - } - - ble_svc_bas_battery_level_set(batt_level); - - sleep(1); - } - - return 0; -} diff --git a/examples/nimble_blecent/CMakeLists.txt b/examples/nimble_blecent/CMakeLists.txt deleted file mode 100644 index 973b6e9ed..000000000 --- a/examples/nimble_blecent/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# ############################################################################## -# apps/examples/nimble_blecent/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_NIMBLE_BLECENT) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_NIMBLE_BLECENT_PROGNAME} - SRCS - ${CMAKE_CURRENT_LIST_DIR}/nimble_blecent_main.c - ${CMAKE_CURRENT_LIST_DIR}/misc.c - ${CMAKE_CURRENT_LIST_DIR}/peer.c - DEPENDS - nimble) -endif() diff --git a/examples/nimble_blecent/Kconfig b/examples/nimble_blecent/Kconfig deleted file mode 100644 index 20fe3b82e..000000000 --- a/examples/nimble_blecent/Kconfig +++ /dev/null @@ -1,30 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config EXAMPLES_NIMBLE_BLECENT - tristate "NimBLE central" - default n - ---help--- - Enable the nimble central example - -if EXAMPLES_NIMBLE_BLECENT - -config EXAMPLES_NIMBLE_BLECENT_PROGNAME - string "Program name" - default "blecent" - ---help--- - This is the name of the program that will be used when the NSH ELF - program is installed. - -config EXAMPLES_NIMBLE_BLECENT_PRIORITY - int "NimBLE task priority" - default 100 - -config EXAMPLES_NIMBLE_BLECENT_STACKSIZE - int "NimBLE stack size" - default DEFAULT_TASK_STACKSIZE - -endif # EXAMPLES_NIMBLE_BLECENT - diff --git a/examples/nimble_blecent/Make.defs b/examples/nimble_blecent/Make.defs deleted file mode 100644 index c6f0b98e6..000000000 --- a/examples/nimble_blecent/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/examples/nimble_blecent/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_EXAMPLES_NIMBLE_BLECENT),) -CONFIGURED_APPS += $(APPDIR)/examples/nimble_blecent -endif diff --git a/examples/nimble_blecent/Makefile b/examples/nimble_blecent/Makefile deleted file mode 100644 index 5870a0285..000000000 --- a/examples/nimble_blecent/Makefile +++ /dev/null @@ -1,40 +0,0 @@ -############################################################################ -# apps/examples/nimble_blecent/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -# NimBLE built-in application info - -PROGNAME = $(CONFIG_EXAMPLES_NIMBLE_BLECENT_PROGNAME) -PRIORITY = $(CONFIG_EXAMPLES_NIMBLE_BLECENT_PRIORITY) -STACKSIZE = $(CONFIG_EXAMPLES_NIMBLE_BLECENT_STACKSIZE) -MODULE = $(CONFIG_EXAMPLES_NIMBLE_BLECENT) - -# NimBLE Central Example - -CSRCS += misc.c peer.c -MAINSRC = nimble_blecent_main.c - -include $(APPDIR)/wireless/bluetooth/nimble/Makefile.nimble - -include $(APPDIR)/Application.mk - diff --git a/examples/nimble_blecent/blecent.h b/examples/nimble_blecent/blecent.h deleted file mode 100644 index 20e9239a7..000000000 --- a/examples/nimble_blecent/blecent.h +++ /dev/null @@ -1,149 +0,0 @@ -/**************************************************************************** - * apps/examples/nimble_blecent/blecent.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __APPS_EXAMPLES_NIMBLE_BLECENT_BLECENT_H -#define __APPS_EXAMPLES_NIMBLE_BLECENT_BLECENT_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <stdio.h> - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define BLECENT_SVC_ALERT_UUID 0x1811 -#define BLECENT_CHR_SUP_NEW_ALERT_CAT_UUID 0x2A47 -#define BLECENT_CHR_NEW_ALERT 0x2A46 -#define BLECENT_CHR_SUP_UNR_ALERT_CAT_UUID 0x2A48 -#define BLECENT_CHR_UNR_ALERT_STAT_UUID 0x2A45 -#define BLECENT_CHR_ALERT_NOT_CTRL_PT 0x2A44 - -/**************************************************************************** - * Public Type Definition - ****************************************************************************/ - -/* Peer. */ - -struct peer_dsc -{ - SLIST_ENTRY(peer_dsc) next; - struct ble_gatt_dsc dsc; -}; -SLIST_HEAD(peer_dsc_list, peer_dsc); - -struct peer_chr -{ - SLIST_ENTRY(peer_chr) next; - struct ble_gatt_chr chr; - - struct peer_dsc_list dscs; -}; -SLIST_HEAD(peer_chr_list, peer_chr); - -struct peer_svc -{ - SLIST_ENTRY(peer_svc) next; - struct ble_gatt_svc svc; - - struct peer_chr_list chrs; -}; -SLIST_HEAD(peer_svc_list, peer_svc); - -struct peer; -typedef void peer_disc_fn(const struct peer *peer, int status, void *arg); - -struct peer -{ - SLIST_ENTRY(peer) next; - - uint16_t conn_handle; - - /* List of discovered GATT services. */ - - struct peer_svc_list svcs; - - /* Keeps track of where we are in the service discovery process. */ - - uint16_t disc_prev_chr_val; - struct peer_svc *cur_svc; - - /* Callback that gets executed when service discovery completes. */ - - peer_disc_fn *disc_cb; - void *disc_cb_arg; -}; - -/**************************************************************************** - * Public Type Definition - ****************************************************************************/ - -/* Forward references */ - -struct ble_hs_adv_fields; -struct ble_gap_conn_desc; -struct ble_hs_cfg; -union ble_store_value; -union ble_store_key; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -#ifdef __cplusplus -extern "C" -{ -#endif - -/* Misc. */ - -void print_mbuf(FAR const struct os_mbuf *om); -FAR char *addr_str(FAR const void *addr); -void print_uuid(FAR const ble_uuid_t *uuid); -void print_conn_desc(FAR const struct ble_gap_conn_desc *desc); -void print_adv_fields(FAR const struct ble_hs_adv_fields *fields); - -int peer_disc_all(uint16_t conn_handle, FAR peer_disc_fn *disc_cb, - FAR void *disc_cb_arg); -FAR const struct peer_dsc * -peer_dsc_find_uuid(FAR const struct peer *peer, - FAR const ble_uuid_t *svc_uuid, - FAR const ble_uuid_t *chr_uuid, - FAR const ble_uuid_t *dsc_uuid); -FAR const struct peer_chr * -peer_chr_find_uuid(FAR const struct peer *peer, - FAR const ble_uuid_t *svc_uuid, - FAR const ble_uuid_t *chr_uuid); -FAR const struct peer_svc * -peer_svc_find_uuid(FAR const struct peer *peer, - FAR const ble_uuid_t *uuid); -int peer_delete(uint16_t conn_handle); -int peer_add(uint16_t conn_handle); -int peer_init(int max_peers, int max_svcs, int max_chrs, int max_dscs); - -#ifdef __cplusplus -} -#endif - -#endif /* __APPS_EXAMPLES_NIMBLE_BLECENT_BLECENT_H */ diff --git a/examples/nimble_blecent/misc.c b/examples/nimble_blecent/misc.c deleted file mode 100644 index 87c7f5d37..000000000 --- a/examples/nimble_blecent/misc.c +++ /dev/null @@ -1,241 +0,0 @@ -/**************************************************************************** - * apps/examples/nimble_blecent/misc.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <assert.h> -#include <stdio.h> -#include <string.h> - -#include "host/ble_hs.h" -#include "host/ble_uuid.h" -#include "blecent.h" - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static void print_bytes(FAR const uint8_t *bytes, int len) -{ - int i; - - for (i = 0; i < len; i++) - { - printf("%s0x%02x", i != 0 ? ":" : "", bytes[i]); - } -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -void print_mbuf(FAR const struct os_mbuf *om) -{ - int colon; - - colon = 0; - while (om != NULL) - { - if (colon) - { - printf(":"); - } - else - { - colon = 1; - } - - print_bytes(om->om_data, om->om_len); - om = SLIST_NEXT(om, om_next); - } -} - -FAR char *addr_str(FAR const void *addr) -{ - static char buf[6 * 2 + 5 + 1]; - const uint8_t *u8p; - - u8p = addr; - sprintf(buf, "%02x:%02x:%02x:%02x:%02x:%02x", - u8p[5], u8p[4], u8p[3], u8p[2], u8p[1], u8p[0]); - - return buf; -} - -void print_uuid(FAR const ble_uuid_t *uuid) -{ - char buf[BLE_UUID_STR_LEN]; - - printf("%s", ble_uuid_to_str(uuid, buf)); -} - -void print_conn_desc(FAR const struct ble_gap_conn_desc *desc) -{ - printf("handle=%d our_ota_addr_type=%d our_ota_addr=%s ", - desc->conn_handle, desc->our_ota_addr.type, - addr_str(desc->our_ota_addr.val)); - printf("our_id_addr_type=%d our_id_addr=%s ", - desc->our_id_addr.type, addr_str(desc->our_id_addr.val)); - printf("peer_ota_addr_type=%d peer_ota_addr=%s ", - desc->peer_ota_addr.type, addr_str(desc->peer_ota_addr.val)); - printf("peer_id_addr_type=%d peer_id_addr=%s ", - desc->peer_id_addr.type, addr_str(desc->peer_id_addr.val)); - printf("conn_itvl=%d conn_latency=%d supervision_timeout=%d " - "encrypted=%d authenticated=%d bonded=%d", - desc->conn_itvl, desc->conn_latency, - desc->supervision_timeout, - desc->sec_state.encrypted, - desc->sec_state.authenticated, - desc->sec_state.bonded); -} - -void print_adv_fields(FAR const struct ble_hs_adv_fields *fields) -{ - char s[BLE_HS_ADV_MAX_SZ]; - const uint8_t *u8p; - int i; - - if (fields->flags != 0) - { - printf(" flags=0x%02x\n", fields->flags); - } - - if (fields->uuids16 != NULL) - { - printf(" uuids16(%scomplete)=", - fields->uuids16_is_complete ? "" : "in"); - for (i = 0; i < fields->num_uuids16; i++) - { - print_uuid(&fields->uuids16[i].u); - printf(" "); - } - - printf("\n"); - } - - if (fields->uuids32 != NULL) - { - printf(" uuids32(%scomplete)=", - fields->uuids32_is_complete ? "" : "in"); - for (i = 0; i < fields->num_uuids32; i++) - { - print_uuid(&fields->uuids32[i].u); - printf(" "); - } - - printf("\n"); - } - - if (fields->uuids128 != NULL) - { - printf(" uuids128(%scomplete)=", - fields->uuids128_is_complete ? "" : "in"); - for (i = 0; i < fields->num_uuids128; i++) - { - print_uuid(&fields->uuids128[i].u); - printf(" "); - } - - printf("\n"); - } - - if (fields->name != NULL) - { - assert(fields->name_len < sizeof s - 1); - memcpy(s, fields->name, fields->name_len); - s[fields->name_len] = '\0'; - printf(" name(%scomplete)=%s\n", - fields->name_is_complete ? "" : "in", s); - } - - if (fields->tx_pwr_lvl_is_present) - { - printf(" tx_pwr_lvl=%d\n", fields->tx_pwr_lvl); - } - - if (fields->slave_itvl_range != NULL) - { - printf(" slave_itvl_range="); - print_bytes(fields->slave_itvl_range, BLE_HS_ADV_SLAVE_ITVL_RANGE_LEN); - printf("\n"); - } - - if (fields->svc_data_uuid16 != NULL) - { - printf(" svc_data_uuid16="); - print_bytes(fields->svc_data_uuid16, fields->svc_data_uuid16_len); - printf("\n"); - } - - if (fields->public_tgt_addr != NULL) - { - printf(" public_tgt_addr="); - u8p = fields->public_tgt_addr; - for (i = 0; i < fields->num_public_tgt_addrs; i++) - { - printf("public_tgt_addr=%s ", addr_str(u8p)); - u8p += BLE_HS_ADV_PUBLIC_TGT_ADDR_ENTRY_LEN; - } - - printf("\n"); - } - - if (fields->appearance_is_present) - { - printf(" appearance=0x%04x\n", fields->appearance); - } - - if (fields->adv_itvl_is_present) - { - printf(" adv_itvl=0x%04x\n", fields->adv_itvl); - } - - if (fields->svc_data_uuid32 != NULL) - { - printf(" svc_data_uuid32="); - print_bytes(fields->svc_data_uuid32, fields->svc_data_uuid32_len); - printf("\n"); - } - - if (fields->svc_data_uuid128 != NULL) - { - printf(" svc_data_uuid128="); - print_bytes(fields->svc_data_uuid128, fields->svc_data_uuid128_len); - printf("\n"); - } - - if (fields->uri != NULL) - { - printf(" uri="); - print_bytes(fields->uri, fields->uri_len); - printf("\n"); - } - - if (fields->mfg_data != NULL) - { - printf(" mfg_data="); - print_bytes(fields->mfg_data, fields->mfg_data_len); - printf("\n"); - } -} diff --git a/examples/nimble_blecent/nimble_blecent_main.c b/examples/nimble_blecent/nimble_blecent_main.c deleted file mode 100644 index 5af9d2b03..000000000 --- a/examples/nimble_blecent/nimble_blecent_main.c +++ /dev/null @@ -1,680 +0,0 @@ -/**************************************************************************** - * apps/examples/nimble_blecent/nimble_blecent_main.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <assert.h> -#include <string.h> - -/* BLE */ - -#include "nimble/ble.h" -#include "nimble/nimble_port.h" -#include "host/ble_hs.h" -#include "host/util/util.h" - -/* Mandatory services. */ - -#include "services/gap/ble_svc_gap.h" -#include "services/gatt/ble_svc_gatt.h" -#include "services/bas/ble_svc_bas.h" - -/* Application-specified header. */ - -#include "blecent.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define BLECENT_BAS_UUID 0x180f -#define BLECENT_CHR_BAS_BL_UUID 0x2a19 - -/* Not used now */ - -#define TASK_DEFAULT_PRIORITY CONFIG_EXAMPLES_NIMBLE_BLECENT_PRIORITY -#define TASK_DEFAULT_STACK NULL -#define TASK_DEFAULT_STACK_SIZE 0 - -/**************************************************************************** - * External Functions Prototypes - ****************************************************************************/ - -void ble_hci_sock_ack_handler(FAR void *param); -void ble_hci_sock_set_device(int dev); - -/**************************************************************************** - * Private Functions Prototypes - ****************************************************************************/ - -static int blecent_gap_event(FAR struct ble_gap_event *event, FAR void *arg); - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: blecent_on_read - ****************************************************************************/ - -static int -blecent_on_read(uint16_t conn_handle, - FAR const struct ble_gatt_error *error, - FAR struct ble_gatt_attr *attr, - FAR void *arg) -{ - printf("Read complete; status=%d conn_handle=%d", error->status, - conn_handle); - if (error->status == 0) - { - printf(" attr_handle=%d value=", attr->handle); - print_mbuf(attr->om); - } - - printf("\n"); - - return 0; -} - -/**************************************************************************** - * Name: blecent_on_write - ****************************************************************************/ - -static int -blecent_on_write(uint16_t conn_handle, - FAR const struct ble_gatt_error *error, - FAR struct ble_gatt_attr *attr, - FAR void *arg) -{ - printf("Write complete; status=%d conn_handle=%d attr_handle=%d\n", - error->status, conn_handle, attr->handle); - - return 0; -} - -/* Application callback. Called when the attempt to subscribe to - * notifications for the ANS Unread Alert Status characteristic - * has completed. - */ - -static int -blecent_on_subscribe(uint16_t conn_handle, - FAR const struct ble_gatt_error *error, - FAR struct ble_gatt_attr *attr, - FAR void *arg) -{ - printf("Subscribe complete; status=%d conn_handle=%d " - "attr_handle=%d\n", - error->status, conn_handle, attr->handle); - - return 0; -} - -/**************************************************************************** - * Name: blecent_read_write_subscribe - ****************************************************************************/ - -static void blecent_read_write_subscribe(FAR const struct peer *peer) -{ - const struct peer_chr *chr; - const struct peer_dsc *dsc; - uint8_t value[2]; - int rc; - - /* Read the supported-new-alert-category characteristic. */ - - chr = peer_chr_find_uuid( - peer, BLE_UUID16_DECLARE(BLECENT_SVC_ALERT_UUID), - BLE_UUID16_DECLARE(BLECENT_CHR_SUP_NEW_ALERT_CAT_UUID)); - if (chr == NULL) - { - printf("Error: Peer doesn't support the Supported New " - "Alert Category characteristic\n"); - goto err; - } - - rc = ble_gattc_read(peer->conn_handle, chr->chr.val_handle, - blecent_on_read, NULL); - if (rc != 0) - { - printf("Error: Failed to read characteristic; rc=%d\n", rc); - goto err; - } - - /* Write two bytes (99, 100) to the alert-notification-control-point - * characteristic. - */ - - chr = peer_chr_find_uuid( - peer, BLE_UUID16_DECLARE(BLECENT_SVC_ALERT_UUID), - BLE_UUID16_DECLARE(BLECENT_CHR_ALERT_NOT_CTRL_PT)); - if (chr == NULL) - { - printf("Error: Peer doesn't support the Alert " - "Notification Control Point characteristic\n"); - goto err; - } - - value[0] = 99; - value[1] = 100; - rc = ble_gattc_write_flat(peer->conn_handle, chr->chr.val_handle, value, - sizeof value, blecent_on_write, NULL); - if (rc != 0) - { - printf("Error: Failed to write characteristic; rc=%d\n", rc); - } - - /* Subscribe to notifications for the Battery Level characteristic. - * A central enables notifications by writing two bytes (1, 0) to the - * characteristic's client-characteristic-configuration-descriptor (CCCD). - */ - - dsc = peer_dsc_find_uuid( - peer, BLE_UUID16_DECLARE(BLE_SVC_BAS_UUID16), - BLE_UUID16_DECLARE(BLE_SVC_BAS_CHR_UUID16_BATTERY_LEVEL), - BLE_UUID16_DECLARE(BLE_GATT_DSC_CLT_CFG_UUID16)); - if (dsc == NULL) - { - printf("Error: Peer lacks a CCCD for the \ - Battery Level characteristic\n"); - goto err; - } - - value[0] = 1; - value[1] = 0; - rc = ble_gattc_write_flat(peer->conn_handle, dsc->dsc.handle, value, - sizeof value, blecent_on_subscribe, NULL); - if (rc != 0) - { - printf("Error: Failed to subscribe to characteristic; " - "rc=%d\n", - rc); - goto err; - } - - return; - -err: - - /* Terminate the connection. */ - - ble_gap_terminate(peer->conn_handle, BLE_ERR_REM_USER_CONN_TERM); -} - -/**************************************************************************** - * Name: blecent_on_disc_complete - ****************************************************************************/ - -static void -blecent_on_disc_complete(FAR const struct peer *peer, int status, - FAR void *arg) -{ - if (status != 0) - { - /* Service discovery failed. Terminate the connection. */ - - printf("Error: Service discovery failed; status=%d " - "conn_handle=%d\n", - status, peer->conn_handle); - ble_gap_terminate(peer->conn_handle, BLE_ERR_REM_USER_CONN_TERM); - return; - } - - /* Service discovery has completed successfully. Now we have a complete - * list of services, characteristics, and descriptors that the peer - * supports. - */ - - printf("Service discovery complete; status=%d " - "conn_handle=%d\n", - status, peer->conn_handle); - - /* Now perform three concurrent GATT procedures against the peer: read, - * write, and subscribe to notifications. - */ - - blecent_read_write_subscribe(peer); -} - -/**************************************************************************** - * Name: blecent_scan - ****************************************************************************/ - -static void blecent_scan(void) -{ - struct ble_gap_disc_params disc_params; - uint8_t own_addr_type; - int rc; - - /* Figure out address to use while advertising (no privacy for now) */ - - rc = ble_hs_id_infer_auto(0, &own_addr_type); - if (rc != 0) - { - printf("error determining address type; rc=%d\n", rc); - return; - } - - /* Tell the controller to filter duplicates; we don't want to process - * repeated advertisements from the same device. - */ - - disc_params.filter_duplicates = 1; - - /* Perform a passive scan. I.e., don't send follow-up scan requests to - * each advertiser. - */ - - disc_params.passive = 1; - - /* Use defaults for the rest of the parameters. */ - - disc_params.itvl = 0; - disc_params.window = 0; - disc_params.filter_policy = 0; - disc_params.limited = 0; - - rc = ble_gap_disc(own_addr_type, BLE_HS_FOREVER, &disc_params, - blecent_gap_event, NULL); - if (rc != 0) - { - printf("Error initiating GAP discovery procedure; rc=%d\n", rc); - } -} - -/**************************************************************************** - * Name: blecent_should_connect - ****************************************************************************/ - -static int blecent_should_connect(const struct ble_gap_disc_desc *disc) -{ - struct ble_hs_adv_fields fields; - int rc; - int i; - - /* The device has to be advertising connectability. */ - - if (disc->event_type != BLE_HCI_ADV_RPT_EVTYPE_ADV_IND - && disc->event_type != BLE_HCI_ADV_RPT_EVTYPE_DIR_IND) - { - return 0; - } - - rc = ble_hs_adv_parse_fields(&fields, disc->data, disc->length_data); - if (rc != 0) - { - return 0; - } - - /* The device has to advertise support for the Alert Notification - * service (0x1811). - */ - - for (i = 0; i < fields.num_uuids16; i++) - { - if (ble_uuid_u16(&fields.uuids16[i].u) == BLECENT_SVC_ALERT_UUID) - { - return 1; - } - } - - return 0; -} - -/**************************************************************************** - * Name: blecent_connect_if_interesting - ****************************************************************************/ - -static void -blecent_connect_if_interesting(FAR const struct ble_gap_disc_desc *disc) -{ - uint8_t own_addr_type; - int rc; - - /* Don't do anything if we don't care about this advertiser. */ - - if (!blecent_should_connect(disc)) - { - return; - } - - /* Scanning must be stopped before a connection can be initiated. */ - - rc = ble_gap_disc_cancel(); - if (rc != 0) - { - printf("Failed to cancel scan; rc=%d\n", rc); - return; - } - - /* Figure out address to use for connect (no privacy for now) */ - - rc = ble_hs_id_infer_auto(0, &own_addr_type); - if (rc != 0) - { - printf("error determining address type; rc=%d\n", rc); - return; - } - - /* Try to connect the the advertiser. Allow 30 seconds (30000 ms) for - * timeout. - */ - - rc = ble_gap_connect(own_addr_type, &disc->addr, 30000, NULL, - blecent_gap_event, NULL); - if (rc != 0) - { - printf("Error: Failed to connect to device; addr_type=%d " - "addr=%s\n; rc=%d", - disc->addr.type, addr_str(disc->addr.val), rc); - return; - } -} - -/**************************************************************************** - * Name: blecent_gap_event - ****************************************************************************/ - -static int blecent_gap_event(FAR struct ble_gap_event *event, FAR void *arg) -{ - struct ble_gap_conn_desc desc; - struct ble_hs_adv_fields fields; - int rc; - - switch (event->type) - { - case BLE_GAP_EVENT_DISC: - rc = ble_hs_adv_parse_fields(&fields, event->disc.data, - event->disc.length_data); - if (rc != 0) - { - return 0; - } - - /* An advertisement report was received during GAP discovery. */ - - print_adv_fields(&fields); - - /* Try to connect to the advertiser if it looks interesting. */ - - blecent_connect_if_interesting(&event->disc); - return 0; - - case BLE_GAP_EVENT_CONNECT: - - /* A new connection was established or a connection attempt failed. - */ - - if (event->connect.status == 0) - { - /* Connection successfully established. */ - - printf("Connection established "); - - rc = ble_gap_conn_find(event->connect.conn_handle, &desc); - assert(rc == 0); - print_conn_desc(&desc); - printf("\n"); - - /* Remember peer. */ - - rc = peer_add(event->connect.conn_handle); - if (rc != 0) - { - printf("Failed to add peer; rc=%d\n", rc); - return 0; - } - - /* Perform service discovery. */ - - rc = peer_disc_all(event->connect.conn_handle, - blecent_on_disc_complete, NULL); - if (rc != 0) - { - printf("Failed to discover services; rc=%d\n", rc); - return 0; - } - } - else - { - /* Connection attempt failed; resume scanning. */ - - printf("Error: Connection failed; status=%d\n", - event->connect.status); - blecent_scan(); - } - - return 0; - - case BLE_GAP_EVENT_DISCONNECT: - - /* Connection terminated. */ - - printf("disconnect; reason=%d ", event->disconnect.reason); - print_conn_desc(&event->disconnect.conn); - printf("\n"); - - /* Forget about peer. */ - - peer_delete(event->disconnect.conn.conn_handle); - - /* Resume scanning. */ - - blecent_scan(); - return 0; - - case BLE_GAP_EVENT_DISC_COMPLETE: - printf("discovery complete; reason=%d\n", - event->disc_complete.reason); - return 0; - - case BLE_GAP_EVENT_ENC_CHANGE: - - /* Encryption has been enabled or disabled for this connection. */ - - printf("encryption change event; status=%d ", - event->enc_change.status); - rc = ble_gap_conn_find(event->enc_change.conn_handle, &desc); - assert(rc == 0); - print_conn_desc(&desc); - return 0; - - case BLE_GAP_EVENT_NOTIFY_RX: - - /* Peer sent us a notification or indication. */ - - printf("received %s; conn_handle=%d attr_handle=%d " - "attr_len=%d\n", - event->notify_rx.indication ? "indication" : "notification", - event->notify_rx.conn_handle, event->notify_rx.attr_handle, - OS_MBUF_PKTLEN(event->notify_rx.om)); - - uint8_t notif_data[100]; /* Size depending on the actual size of the - notification data you have */ - uint16_t notif_len; - int offset = 0; - notif_len = OS_MBUF_PKTLEN(event->notify_rx.om); - os_mbuf_copydata(event->notify_rx.om, offset, notif_len, notif_data); - - printf("notification data: "); - for (int i = 0; i < notif_len; i++) - { - printf("%02d ", notif_data[i]); - } - - printf("\n"); - - /* Attribute data is contained in event->notify_rx.attr_data. */ - - return 0; - - case BLE_GAP_EVENT_MTU: - printf("mtu update event; conn_handle=%d cid=%d mtu=%d\n", - event->mtu.conn_handle, event->mtu.channel_id, - event->mtu.value); - return 0; - - case BLE_GAP_EVENT_REPEAT_PAIRING: - /* We already have a bond with the peer, but it is attempting to - * establish a new secure link. This app sacrifices security for - * convenience: just throw away the old bond and accept the new link. - */ - - /* Delete the old bond. */ - - rc = ble_gap_conn_find(event->repeat_pairing.conn_handle, &desc); - assert(rc == 0); - ble_store_util_delete_peer(&desc.peer_id_addr); - - /* Return BLE_GAP_REPEAT_PAIRING_RETRY to indicate that the host - * should continue with the pairing operation. - */ - - return BLE_GAP_REPEAT_PAIRING_RETRY; - - default: - return 0; - } -} - -static void blecent_on_reset(int reason) -{ - printf("Resetting state; reason=%d\n", reason); -} - -/**************************************************************************** - * Name: blecent_on_sync - ****************************************************************************/ - -static void blecent_on_sync(void) -{ - int rc; - - /* Make sure we have proper identity address set (public preferred) */ - - rc = ble_hs_util_ensure_addr(0); - assert(rc == 0); - - /* Begin scanning for a peripheral to connect to. */ - - blecent_scan(); -} - -/**************************************************************************** - * Name: nimble_host_task - ****************************************************************************/ - -static void nimble_host_task(FAR void *param) -{ - ble_svc_gap_device_name_set("NuttX NimBLE CENT"); - nimble_port_run(); -} - -/**************************************************************************** - * Name: ble_hci_sock_task - ****************************************************************************/ - -static FAR void *ble_hci_sock_task(FAR void *param) -{ - ble_hci_sock_ack_handler(param); - return NULL; -} - -/**************************************************************************** - * Name: ble_host_task - ****************************************************************************/ - -static FAR void *ble_host_task(FAR void *param) -{ - nimble_host_task(param); - return NULL; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: nimble_main - ****************************************************************************/ - -int main(int argc, FAR char **argv) -{ - struct ble_npl_task s_task_host; - struct ble_npl_task s_task_hci; - int ret = 0; - - /* allow to specify custom hci */ - - if (argc > 1) - { - ble_hci_sock_set_device(atoi(argv[1])); - } - -#ifndef CONFIG_NSH_NETINIT - /* Bring up the network */ - - netinit_bringup(); -#endif - - nimble_port_init(); - - /* Configure the host. */ - - ble_hs_cfg.reset_cb = blecent_on_reset; - ble_hs_cfg.sync_cb = blecent_on_sync; - ble_hs_cfg.store_status_cb = ble_store_util_status_rr; - - /* Initialize data structures to track connected peers. */ - - ret = peer_init(MYNEWT_VAL(BLE_MAX_CONNECTIONS), 64, 64, 64); - assert(ret == 0); - - /* Create task which handles HCI socket */ - - ret = ble_npl_task_init(&s_task_hci, "hci_sock", ble_hci_sock_task, NULL, - TASK_DEFAULT_PRIORITY, BLE_NPL_TIME_FOREVER, - TASK_DEFAULT_STACK, TASK_DEFAULT_STACK_SIZE); - if (ret != 0) - { - printf("ERROR: starting hci task: %i\n", ret); - } - - /* Create task which handles default event queue for host stack. */ - - ret = ble_npl_task_init(&s_task_host, "ble_host", ble_host_task, NULL, - TASK_DEFAULT_PRIORITY, BLE_NPL_TIME_FOREVER, - TASK_DEFAULT_STACK, TASK_DEFAULT_STACK_SIZE); - if (ret != 0) - { - printf("ERROR: starting ble task: %i\n", ret); - } - - while (true) - { - sleep(1); - } - - return 0; -} diff --git a/examples/nimble_blecent/peer.c b/examples/nimble_blecent/peer.c deleted file mode 100644 index 16ebd7872..000000000 --- a/examples/nimble_blecent/peer.c +++ /dev/null @@ -1,935 +0,0 @@ -/**************************************************************************** - * apps/examples/nimble_blecent/peer.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <assert.h> -#include <string.h> -#include "host/ble_hs.h" -#include "blecent.h" - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -FAR static struct peer_svc * -peer_svc_find_range(FAR struct peer *peer, uint16_t attr_handle); -FAR static struct peer_svc * -peer_svc_find(FAR struct peer *peer, uint16_t svc_start_handle, - struct peer_svc **out_prev); -static int peer_svc_is_empty(const struct peer_svc *svc); - -static uint16_t chr_end_handle(FAR const struct peer_svc *svc, - FAR const struct peer_chr *chr); -static int chr_is_empty(FAR const struct peer_svc *svc, - FAR const struct peer_chr *chr); -FAR static struct peer_chr * -peer_chr_find(FAR const struct peer_svc *svc, uint16_t chr_def_handle, - FAR struct peer_chr **out_prev); -static void peer_disc_chrs(FAR struct peer *peer); - -static int -peer_dsc_disced(uint16_t conn_handle, FAR const struct ble_gatt_error *error, - uint16_t chr_val_handle, FAR const struct ble_gatt_dsc *dsc, - FAR void *arg); - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -FAR static void *peer_svc_mem; -static struct os_mempool peer_svc_pool; - -FAR static void *peer_chr_mem; -static struct os_mempool peer_chr_pool; - -FAR static void *peer_dsc_mem; -static struct os_mempool peer_dsc_pool; - -FAR static void *peer_mem; -static struct os_mempool peer_pool; -static SLIST_HEAD(, peer) peers; - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -FAR static struct peer *peer_find(uint16_t conn_handle) -{ - struct peer *peer; - - SLIST_FOREACH(peer, &peers, next) - { - if (peer->conn_handle == conn_handle) - { - return peer; - } - } - - return NULL; -} - -static void peer_disc_complete(FAR struct peer *peer, int rc) -{ - peer->disc_prev_chr_val = 0; - - /* Notify caller that discovery has completed. */ - - if (peer->disc_cb != NULL) - { - peer->disc_cb(peer, rc, peer->disc_cb_arg); - } -} - -FAR static struct peer_dsc * -peer_dsc_find_prev(FAR const struct peer_chr *chr, uint16_t dsc_handle) -{ - FAR struct peer_dsc *prev; - FAR struct peer_dsc *dsc; - - prev = NULL; - SLIST_FOREACH(dsc, &chr->dscs, next) - { - if (dsc->dsc.handle >= dsc_handle) - { - break; - } - - prev = dsc; - } - - return prev; -} - -FAR static struct peer_dsc * -peer_dsc_find(FAR const struct peer_chr *chr, uint16_t dsc_handle, - FAR struct peer_dsc **out_prev) -{ - FAR struct peer_dsc *prev; - FAR struct peer_dsc *dsc; - - prev = peer_dsc_find_prev(chr, dsc_handle); - if (prev == NULL) - { - dsc = SLIST_FIRST(&chr->dscs); - } - else - { - dsc = SLIST_NEXT(prev, next); - } - - if (dsc != NULL && dsc->dsc.handle != dsc_handle) - { - dsc = NULL; - } - - if (out_prev != NULL) - { - *out_prev = prev; - } - - return dsc; -} - -static int -peer_dsc_add(FAR struct peer *peer, uint16_t chr_val_handle, - FAR const struct ble_gatt_dsc *gatt_dsc) -{ - FAR struct peer_dsc *prev; - FAR struct peer_dsc *dsc; - FAR struct peer_svc *svc; - FAR struct peer_chr *chr; - - svc = peer_svc_find_range(peer, chr_val_handle); - if (svc == NULL) - { - /* Can't find service for discovered descriptor; - * this shouldn't happen. - */ - - assert(0); - return BLE_HS_EUNKNOWN; - } - - chr = peer_chr_find(svc, chr_val_handle, NULL); - if (chr == NULL) - { - /* Can't find characteristic for discovered descriptor; - * this shouldn't happen. - */ - - assert(0); - return BLE_HS_EUNKNOWN; - } - - dsc = peer_dsc_find(chr, gatt_dsc->handle, &prev); - if (dsc != NULL) - { - /* Descriptor already discovered. */ - - return 0; - } - - dsc = os_memblock_get(&peer_dsc_pool); - if (dsc == NULL) - { - /* Out of memory. */ - - return BLE_HS_ENOMEM; - } - - memset(dsc, 0, sizeof *dsc); - - dsc->dsc = *gatt_dsc; - - if (prev == NULL) - { - SLIST_INSERT_HEAD(&chr->dscs, dsc, next); - } - else - { - SLIST_NEXT(prev, next) = dsc; - } - - return 0; -} - -static void peer_disc_dscs(FAR struct peer *peer) -{ - FAR struct peer_chr *chr; - FAR struct peer_svc *svc; - int rc; - - /* Search through the list of discovered characteristics for the first - * characteristic that contains undiscovered descriptors. - * Then, discover all descriptors belonging to that characteristic. - */ - - SLIST_FOREACH(svc, &peer->svcs, next) - { - SLIST_FOREACH(chr, &svc->chrs, next) - { - if (!chr_is_empty(svc, chr) && - SLIST_EMPTY(&chr->dscs) && - peer->disc_prev_chr_val <= chr->chr.def_handle) - { - rc = ble_gattc_disc_all_dscs(peer->conn_handle, - chr->chr.val_handle, - chr_end_handle(svc, chr), - peer_dsc_disced, peer); - if (rc != 0) - { - peer_disc_complete(peer, rc); - } - - peer->disc_prev_chr_val = chr->chr.val_handle; - return; - } - } - } - - /* All descriptors discovered. */ - - peer_disc_complete(peer, 0); -} - -static int -peer_dsc_disced(uint16_t conn_handle, FAR const struct ble_gatt_error *error, - uint16_t chr_val_handle, FAR const struct ble_gatt_dsc *dsc, - FAR void *arg) -{ - FAR struct peer *peer; - int rc; - - peer = arg; - assert(peer->conn_handle == conn_handle); - - switch (error->status) - { - case 0: - rc = peer_dsc_add(peer, chr_val_handle, dsc); - break; - - case BLE_HS_EDONE: - /* All descriptors in this characteristic discovered; - * start discovering descriptors in the next characteristic. - */ - - if (peer->disc_prev_chr_val > 0) - { - peer_disc_dscs(peer); - } - - rc = 0; - break; - - default: - - /* Error; abort discovery. */ - - rc = error->status; - break; - } - - if (rc != 0) - { - /* Error; abort discovery. */ - - peer_disc_complete(peer, rc); - } - - return rc; -} - -static uint16_t chr_end_handle(FAR const struct peer_svc *svc, - FAR const struct peer_chr *chr) -{ - FAR const struct peer_chr *next_chr; - - next_chr = SLIST_NEXT(chr, next); - if (next_chr != NULL) - { - return next_chr->chr.def_handle - 1; - } - else - { - return svc->svc.end_handle; - } -} - -static int chr_is_empty(FAR const struct peer_svc *svc, - FAR const struct peer_chr *chr) -{ - return chr_end_handle(svc, chr) <= chr->chr.val_handle; -} - -FAR static struct peer_chr * -peer_chr_find_prev(const struct peer_svc *svc, uint16_t chr_val_handle) -{ - FAR struct peer_chr *prev; - FAR struct peer_chr *chr; - - prev = NULL; - SLIST_FOREACH(chr, &svc->chrs, next) - { - if (chr->chr.val_handle >= chr_val_handle) - { - break; - } - - prev = chr; - } - - return prev; -} - -FAR static struct peer_chr * -peer_chr_find(FAR const struct peer_svc *svc, uint16_t chr_val_handle, - FAR struct peer_chr **out_prev) -{ - FAR struct peer_chr *prev; - FAR struct peer_chr *chr; - - prev = peer_chr_find_prev(svc, chr_val_handle); - if (prev == NULL) - { - chr = SLIST_FIRST(&svc->chrs); - } - else - { - chr = SLIST_NEXT(prev, next); - } - - if (chr != NULL && chr->chr.val_handle != chr_val_handle) - { - chr = NULL; - } - - if (out_prev != NULL) - { - *out_prev = prev; - } - - return chr; -} - -static void peer_chr_delete(FAR struct peer_chr *chr) -{ - FAR struct peer_dsc *dsc; - - while ((dsc = SLIST_FIRST(&chr->dscs)) != NULL) - { - SLIST_REMOVE_HEAD(&chr->dscs, next); - os_memblock_put(&peer_dsc_pool, dsc); - } - - os_memblock_put(&peer_chr_pool, chr); -} - -static int -peer_chr_add(FAR struct peer *peer, uint16_t svc_start_handle, - FAR const struct ble_gatt_chr *gatt_chr) -{ - FAR struct peer_chr *prev; - FAR struct peer_chr *chr; - FAR struct peer_svc *svc; - - svc = peer_svc_find(peer, svc_start_handle, NULL); - if (svc == NULL) - { - /* Can't find service for discovered characteristic; this shouldn't - * happen. - */ - - assert(0); - return BLE_HS_EUNKNOWN; - } - - chr = peer_chr_find(svc, gatt_chr->def_handle, &prev); - if (chr != NULL) - { - /* Characteristic already discovered. */ - - return 0; - } - - chr = os_memblock_get(&peer_chr_pool); - if (chr == NULL) - { - /* Out of memory. */ - - return BLE_HS_ENOMEM; - } - - memset(chr, 0, sizeof *chr); - - chr->chr = *gatt_chr; - - if (prev == NULL) - { - SLIST_INSERT_HEAD(&svc->chrs, chr, next); - } - else - { - SLIST_NEXT(prev, next) = chr; - } - - return 0; -} - -static int -peer_chr_disced(uint16_t conn_handle, FAR const struct ble_gatt_error *error, - FAR const struct ble_gatt_chr *chr, FAR void *arg) -{ - FAR struct peer *peer; - int rc; - - peer = arg; - assert(peer->conn_handle == conn_handle); - - switch (error->status) - { - case 0: - rc = peer_chr_add(peer, peer->cur_svc->svc.start_handle, chr); - break; - - case BLE_HS_EDONE: - /* All characteristics in this service discovered; start discovering - * characteristics in the next service. - */ - - if (peer->disc_prev_chr_val > 0) - { - peer_disc_chrs(peer); - } - - rc = 0; - break; - - default: - rc = error->status; - break; - } - - if (rc != 0) - { - /* Error; abort discovery. */ - - peer_disc_complete(peer, rc); - } - - return rc; -} - -static void peer_disc_chrs(FAR struct peer *peer) -{ - FAR struct peer_svc *svc; - int rc; - - /* Search through the list of discovered service for the first - * service that contains undiscovered characteristics. - * Then, discover all characteristics belonging to that service. - */ - - SLIST_FOREACH(svc, &peer->svcs, next) - { - if (!peer_svc_is_empty(svc) && SLIST_EMPTY(&svc->chrs)) - { - peer->cur_svc = svc; - rc = ble_gattc_disc_all_chrs(peer->conn_handle, - svc->svc.start_handle, - svc->svc.end_handle, - peer_chr_disced, peer); - if (rc != 0) - { - peer_disc_complete(peer, rc); - } - - return; - } - } - - /* All characteristics discovered. */ - - peer_disc_dscs(peer); -} - -static int peer_svc_is_empty(FAR const struct peer_svc *svc) -{ - return svc->svc.end_handle <= svc->svc.start_handle; -} - -FAR static struct peer_svc * -peer_svc_find_prev(FAR struct peer *peer, uint16_t svc_start_handle) -{ - FAR struct peer_svc *prev; - FAR struct peer_svc *svc; - - prev = NULL; - SLIST_FOREACH(svc, &peer->svcs, next) - { - if (svc->svc.start_handle >= svc_start_handle) - { - break; - } - - prev = svc; - } - - return prev; -} - -FAR static struct peer_svc * -peer_svc_find(FAR struct peer *peer, uint16_t svc_start_handle, - FAR struct peer_svc **out_prev) -{ - FAR struct peer_svc *prev; - FAR struct peer_svc *svc; - - prev = peer_svc_find_prev(peer, svc_start_handle); - if (prev == NULL) - { - svc = SLIST_FIRST(&peer->svcs); - } - else - { - svc = SLIST_NEXT(prev, next); - } - - if (svc != NULL && svc->svc.start_handle != svc_start_handle) - { - svc = NULL; - } - - if (out_prev != NULL) - { - *out_prev = prev; - } - - return svc; -} - -FAR static struct peer_svc * -peer_svc_find_range(FAR struct peer *peer, uint16_t attr_handle) -{ - FAR struct peer_svc *svc; - - SLIST_FOREACH(svc, &peer->svcs, next) - { - if (svc->svc.start_handle <= attr_handle && - svc->svc.end_handle >= attr_handle) - { - return svc; - } - } - - return NULL; -} - -FAR const struct peer_svc * -peer_svc_find_uuid(FAR const struct peer *peer, FAR const ble_uuid_t *uuid) -{ - FAR const struct peer_svc *svc; - - SLIST_FOREACH(svc, &peer->svcs, next) - { - if (ble_uuid_cmp(&svc->svc.uuid.u, uuid) == 0) - { - return svc; - } - } - - return NULL; -} - -FAR const struct peer_chr * -peer_chr_find_uuid(FAR const struct peer *peer, - FAR const ble_uuid_t *svc_uuid, - FAR const ble_uuid_t *chr_uuid) -{ - FAR const struct peer_svc *svc; - FAR const struct peer_chr *chr; - - svc = peer_svc_find_uuid(peer, svc_uuid); - if (svc == NULL) - { - return NULL; - } - - SLIST_FOREACH(chr, &svc->chrs, next) - { - if (ble_uuid_cmp(&chr->chr.uuid.u, chr_uuid) == 0) - { - return chr; - } - } - - return NULL; -} - -FAR const struct peer_dsc * -peer_dsc_find_uuid(FAR const struct peer *peer, - FAR const ble_uuid_t *svc_uuid, - FAR const ble_uuid_t *chr_uuid, - FAR const ble_uuid_t *dsc_uuid) -{ - FAR const struct peer_chr *chr; - FAR const struct peer_dsc *dsc; - - chr = peer_chr_find_uuid(peer, svc_uuid, chr_uuid); - if (chr == NULL) - { - return NULL; - } - - SLIST_FOREACH(dsc, &chr->dscs, next) - { - if (ble_uuid_cmp(&dsc->dsc.uuid.u, dsc_uuid) == 0) - { - return dsc; - } - } - - return NULL; -} - -static int -peer_svc_add(FAR struct peer *peer, FAR const struct ble_gatt_svc *gatt_svc) -{ - FAR struct peer_svc *prev; - FAR struct peer_svc *svc; - - svc = peer_svc_find(peer, gatt_svc->start_handle, &prev); - if (svc != NULL) - { - /* Service already discovered. */ - - return 0; - } - - svc = os_memblock_get(&peer_svc_pool); - if (svc == NULL) - { - /* Out of memory. */ - - return BLE_HS_ENOMEM; - } - - memset(svc, 0, sizeof *svc); - - svc->svc = *gatt_svc; - SLIST_INIT(&svc->chrs); - - if (prev == NULL) - { - SLIST_INSERT_HEAD(&peer->svcs, svc, next); - } - else - { - SLIST_INSERT_AFTER(prev, svc, next); - } - - return 0; -} - -static void peer_svc_delete(FAR struct peer_svc *svc) -{ - FAR struct peer_chr *chr; - - while ((chr = SLIST_FIRST(&svc->chrs)) != NULL) - { - SLIST_REMOVE_HEAD(&svc->chrs, next); - peer_chr_delete(chr); - } - - os_memblock_put(&peer_svc_pool, svc); -} - -static int -peer_svc_disced(uint16_t conn_handle, FAR const struct ble_gatt_error *error, - FAR const struct ble_gatt_svc *service, FAR void *arg) -{ - FAR struct peer *peer; - int rc; - - peer = arg; - assert(peer->conn_handle == conn_handle); - - switch (error->status) - { - case 0: - rc = peer_svc_add(peer, service); - break; - - case BLE_HS_EDONE: - - /* All services discovered; start discovering characteristics. */ - - if (peer->disc_prev_chr_val > 0) - { - peer_disc_chrs(peer); - } - - rc = 0; - break; - - default: - rc = error->status; - break; - } - - if (rc != 0) - { - /* Error; abort discovery. */ - - peer_disc_complete(peer, rc); - } - - return rc; -} - -int peer_disc_all(uint16_t conn_handle, FAR peer_disc_fn *disc_cb, - FAR void *disc_cb_arg) -{ - FAR struct peer_svc *svc; - FAR struct peer *peer; - int rc; - - peer = peer_find(conn_handle); - if (peer == NULL) - { - return BLE_HS_ENOTCONN; - } - - /* Undiscover everything first. */ - - while ((svc = SLIST_FIRST(&peer->svcs)) != NULL) - { - SLIST_REMOVE_HEAD(&peer->svcs, next); - peer_svc_delete(svc); - } - - peer->disc_prev_chr_val = 1; - peer->disc_cb = disc_cb; - peer->disc_cb_arg = disc_cb_arg; - - rc = ble_gattc_disc_all_svcs(conn_handle, peer_svc_disced, peer); - if (rc != 0) - { - return rc; - } - - return 0; -} - -int peer_delete(uint16_t conn_handle) -{ - FAR struct peer_svc *svc; - FAR struct peer *peer; - int rc; - - peer = peer_find(conn_handle); - if (peer == NULL) - { - return BLE_HS_ENOTCONN; - } - - SLIST_REMOVE(&peers, peer, peer, next); - - while ((svc = SLIST_FIRST(&peer->svcs)) != NULL) - { - SLIST_REMOVE_HEAD(&peer->svcs, next); - peer_svc_delete(svc); - } - - rc = os_memblock_put(&peer_pool, peer); - if (rc != 0) - { - return BLE_HS_EOS; - } - - return 0; -} - -int peer_add(uint16_t conn_handle) -{ - FAR struct peer *peer; - - /* Make sure the connection handle is unique. */ - - peer = peer_find(conn_handle); - if (peer != NULL) - { - return BLE_HS_EALREADY; - } - - peer = os_memblock_get(&peer_pool); - if (peer == NULL) - { - /* Out of memory. */ - - return BLE_HS_ENOMEM; - } - - memset(peer, 0, sizeof *peer); - peer->conn_handle = conn_handle; - - SLIST_INSERT_HEAD(&peers, peer, next); - - return 0; -} - -static void peer_free_mem(void) -{ - free(peer_mem); - peer_mem = NULL; - - free(peer_svc_mem); - peer_svc_mem = NULL; - - free(peer_chr_mem); - peer_chr_mem = NULL; - - free(peer_dsc_mem); - peer_dsc_mem = NULL; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -int peer_init(int max_peers, int max_svcs, int max_chrs, int max_dscs) -{ - int rc; - - /* Free memory first in case this function gets called more than once. */ - - peer_free_mem(); - - peer_mem = malloc(OS_MEMPOOL_BYTES(max_peers, sizeof(struct peer))); - if (peer_mem == NULL) - { - rc = BLE_HS_ENOMEM; - goto err; - } - - rc = os_mempool_init(&peer_pool, max_peers, sizeof(struct peer), peer_mem, - "peer_pool"); - if (rc != 0) - { - rc = BLE_HS_EOS; - goto err; - } - - peer_svc_mem = malloc(OS_MEMPOOL_BYTES(max_svcs, sizeof(struct peer_svc))); - if (peer_svc_mem == NULL) - { - rc = BLE_HS_ENOMEM; - goto err; - } - - rc = os_mempool_init(&peer_svc_pool, max_svcs, sizeof(struct peer_svc), - peer_svc_mem, "peer_svc_pool"); - if (rc != 0) - { - rc = BLE_HS_EOS; - goto err; - } - - peer_chr_mem = malloc(OS_MEMPOOL_BYTES(max_chrs, sizeof(struct peer_chr))); - if (peer_chr_mem == NULL) - { - rc = BLE_HS_ENOMEM; - goto err; - } - - rc = os_mempool_init(&peer_chr_pool, max_chrs, sizeof(struct peer_chr), - peer_chr_mem, "peer_chr_pool"); - if (rc != 0) - { - rc = BLE_HS_EOS; - goto err; - } - - peer_dsc_mem = malloc(OS_MEMPOOL_BYTES(max_dscs, sizeof(struct peer_dsc))); - if (peer_dsc_mem == NULL) - { - rc = BLE_HS_ENOMEM; - goto err; - } - - rc = os_mempool_init(&peer_dsc_pool, max_dscs, sizeof(struct peer_dsc), - peer_dsc_mem, "peer_dsc_pool"); - if (rc != 0) - { - rc = BLE_HS_EOS; - goto err; - } - - return 0; - -err: - peer_free_mem(); - return rc; -} diff --git a/examples/nimble_bleprph/CMakeLists.txt b/examples/nimble_bleprph/CMakeLists.txt deleted file mode 100644 index a745fd4f7..000000000 --- a/examples/nimble_bleprph/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# ############################################################################## -# apps/examples/nimble_bleprph/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_NIMBLE_BLEPRPH) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_NIMBLE_BLECENT_PROGNAME} - SRCS - ${CMAKE_CURRENT_LIST_DIR}/nimble_bleprph_main.c - ${CMAKE_CURRENT_LIST_DIR}/misc.c - ${CMAKE_CURRENT_LIST_DIR}/gatt_svr.c - DEPENDS - nimble) -endif() diff --git a/examples/nimble_bleprph/Kconfig b/examples/nimble_bleprph/Kconfig deleted file mode 100644 index ce7870feb..000000000 --- a/examples/nimble_bleprph/Kconfig +++ /dev/null @@ -1,30 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config EXAMPLES_NIMBLE_BLEPRPH - tristate "NimBLE peripheral" - default n - ---help--- - Enable the nimble peripheral example - -if EXAMPLES_NIMBLE_BLEPRPH - -config EXAMPLES_NIMBLE_BLEPRPH_PROGNAME - string "Program name" - default "bleprph" - ---help--- - This is the name of the program that will be used when the NSH ELF - program is installed. - -config EXAMPLES_NIMBLE_BLEPRPH_PRIORITY - int "NimBLE task priority" - default 100 - -config EXAMPLES_NIMBLE_BLEPRPH_STACKSIZE - int "NimBLE stack size" - default DEFAULT_TASK_STACKSIZE - -endif # EXAMPLES_NIMBLE_BLEPRPH - diff --git a/examples/nimble_bleprph/Make.defs b/examples/nimble_bleprph/Make.defs deleted file mode 100644 index a2b5e29f8..000000000 --- a/examples/nimble_bleprph/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/examples/nimble_bleprph/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_EXAMPLES_NIMBLE_BLEPRPH),) -CONFIGURED_APPS += $(APPDIR)/examples/nimble_bleprph -endif diff --git a/examples/nimble_bleprph/Makefile b/examples/nimble_bleprph/Makefile deleted file mode 100644 index f5c04b014..000000000 --- a/examples/nimble_bleprph/Makefile +++ /dev/null @@ -1,40 +0,0 @@ -############################################################################ -# apps/examples/nimble_bleprph/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -# NimBLE built-in application info - -PROGNAME = $(CONFIG_EXAMPLES_NIMBLE_BLEPRPH_PROGNAME) -PRIORITY = $(CONFIG_EXAMPLES_NIMBLE_BLEPRPH_PRIORITY) -STACKSIZE = $(CONFIG_EXAMPLES_NIMBLE_BLEPRPH_STACKSIZE) -MODULE = $(CONFIG_EXAMPLES_NIMBLE_BLEPRPH) - -# NimBLE Peripheral Example - -CSRCS += misc.c gatt_svr.c -MAINSRC = nimble_bleprph_main.c - -include $(APPDIR)/wireless/bluetooth/nimble/Makefile.nimble - -include $(APPDIR)/Application.mk - diff --git a/examples/nimble_bleprph/bleprph.h b/examples/nimble_bleprph/bleprph.h deleted file mode 100644 index cb752f3ad..000000000 --- a/examples/nimble_bleprph/bleprph.h +++ /dev/null @@ -1,77 +0,0 @@ -/**************************************************************************** - * apps/examples/nimble_bleprph/bleprph.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef H_BLEPRPH_ -#define H_BLEPRPH_ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <stdbool.h> -#include <stdio.h> - -#include "nimble/ble.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* GATT server. */ - -#define GATT_SVR_SVC_ALERT_UUID 0x1811 -#define GATT_SVR_CHR_SUP_NEW_ALERT_CAT_UUID 0x2A47 -#define GATT_SVR_CHR_NEW_ALERT 0x2A46 -#define GATT_SVR_CHR_SUP_UNR_ALERT_CAT_UUID 0x2A48 -#define GATT_SVR_CHR_UNR_ALERT_STAT_UUID 0x2A45 -#define GATT_SVR_CHR_ALERT_NOT_CTRL_PT 0x2A44 - -/**************************************************************************** - * Public Type Definition - ****************************************************************************/ - -/* Forward references */ - -struct ble_gatt_register_ctxt; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -#ifdef __cplusplus -extern "C" -{ -#endif - -void gatt_svr_register_cb(FAR struct ble_gatt_register_ctxt *ctxt, - FAR void *arg); -int gatt_svr_init(void); - -/* Misc. */ - -void print_addr(FAR const void *addr); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/examples/nimble_bleprph/gatt_svr.c b/examples/nimble_bleprph/gatt_svr.c deleted file mode 100644 index 38efeefd1..000000000 --- a/examples/nimble_bleprph/gatt_svr.c +++ /dev/null @@ -1,250 +0,0 @@ -/**************************************************************************** - * apps/examples/nimble_bleprph/gatt_svr.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <assert.h> -#include <stdio.h> -#include <string.h> -#include "host/ble_hs.h" -#include "host/ble_uuid.h" -#include "services/ans/ble_svc_ans.h" -#include "services/bas/ble_svc_bas.h" -#include "bleprph.h" - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -static int -gatt_svr_chr_access_sec_test(uint16_t conn_handle, uint16_t attr_handle, - FAR struct ble_gatt_access_ctxt *ctxt, - FAR void *arg); - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/* The vendor specific security test service consists of two characteristics: - * - random-number-generator: generates a random 32-bit number each time - * it is read. This characteristic can only be read over an encrypted - * connection. - * - static-value: a single-byte characteristic that can always be read, - * but can only be written over an encrypted connection. - */ - -/* 59462f12-9543-9999-12c8-58b459a2712d */ - -static const ble_uuid128_t gatt_svr_svc_sec_test_uuid = - BLE_UUID128_INIT(0x2d, 0x71, 0xa2, 0x59, 0xb4, 0x58, 0xc8, 0x12, - 0x99, 0x99, 0x43, 0x95, 0x12, 0x2f, 0x46, 0x59); - -/* 5c3a659e-897e-45e1-b016-007107c96df6 */ - -static const ble_uuid128_t gatt_svr_chr_sec_test_rand_uuid = - BLE_UUID128_INIT(0xf6, 0x6d, 0xc9, 0x07, 0x71, 0x00, 0x16, 0xb0, - 0xe1, 0x45, 0x7e, 0x89, 0x9e, 0x65, 0x3a, 0x5c); - -/* 5c3a659e-897e-45e1-b016-007107c96df7 */ - -static const ble_uuid128_t gatt_svr_chr_sec_test_static_uuid = - BLE_UUID128_INIT(0xf7, 0x6d, 0xc9, 0x07, 0x71, 0x00, 0x16, 0xb0, - 0xe1, 0x45, 0x7e, 0x89, 0x9e, 0x65, 0x3a, 0x5c); - -static uint8_t gatt_svr_sec_test_static_val; - -static const struct ble_gatt_svc_def gatt_svr_svcs[] = -{ - { - /* Service: Security test. */ - - .type = BLE_GATT_SVC_TYPE_PRIMARY, - .uuid = &gatt_svr_svc_sec_test_uuid.u, - .characteristics = (struct ble_gatt_chr_def[]) - { - { - /* Characteristic: Random number generator. */ - - .uuid = &gatt_svr_chr_sec_test_rand_uuid.u, - .access_cb = gatt_svr_chr_access_sec_test, - .flags = BLE_GATT_CHR_F_READ, - }, - { - /* Characteristic: Static value. */ - - .uuid = &gatt_svr_chr_sec_test_static_uuid.u, - .access_cb = gatt_svr_chr_access_sec_test, - .flags = BLE_GATT_CHR_F_READ | - BLE_GATT_CHR_F_WRITE, - }, - { - 0, /* No more characteristics in this service. */ - } - }, - }, - - { - 0, /* No more services. */ - }, -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static int -gatt_svr_chr_write(FAR struct os_mbuf *om, uint16_t min_len, - uint16_t max_len, FAR void *dst, FAR uint16_t *len) -{ - uint16_t om_len; - int rc; - - om_len = OS_MBUF_PKTLEN(om); - if (om_len < min_len || om_len > max_len) - { - return BLE_ATT_ERR_INVALID_ATTR_VALUE_LEN; - } - - rc = ble_hs_mbuf_to_flat(om, dst, max_len, len); - if (rc != 0) - { - return BLE_ATT_ERR_UNLIKELY; - } - - return 0; -} - -static int -gatt_svr_chr_access_sec_test(uint16_t conn_handle, uint16_t attr_handle, - FAR struct ble_gatt_access_ctxt *ctxt, - FAR void *arg) -{ - FAR const ble_uuid_t *uuid; - int rand_num; - int rc; - - uuid = ctxt->chr->uuid; - - /* Determine which characteristic is being accessed by examining its - * 128-bit UUID. - */ - - if (ble_uuid_cmp(uuid, &gatt_svr_chr_sec_test_rand_uuid.u) == 0) - { - assert(ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR); - - /* Respond with a 32-bit random number. */ - - rand_num = rand(); - rc = os_mbuf_append(ctxt->om, &rand_num, sizeof rand_num); - return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES; - } - - if (ble_uuid_cmp(uuid, &gatt_svr_chr_sec_test_static_uuid.u) == 0) - { - switch (ctxt->op) - { - case BLE_GATT_ACCESS_OP_READ_CHR: - rc = os_mbuf_append(ctxt->om, &gatt_svr_sec_test_static_val, - sizeof gatt_svr_sec_test_static_val); - return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES; - - case BLE_GATT_ACCESS_OP_WRITE_CHR: - rc = gatt_svr_chr_write(ctxt->om, - sizeof gatt_svr_sec_test_static_val, - sizeof gatt_svr_sec_test_static_val, - &gatt_svr_sec_test_static_val, NULL); - return rc; - - default: - assert(0); - return BLE_ATT_ERR_UNLIKELY; - } - } - - /* Unknown characteristic; the nimble stack should not have called this - * function. - */ - - assert(0); - return BLE_ATT_ERR_UNLIKELY; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -void gatt_svr_register_cb(FAR struct ble_gatt_register_ctxt *ctxt, - FAR void *arg) -{ - char buf[BLE_UUID_STR_LEN]; - - switch (ctxt->op) - { - case BLE_GATT_REGISTER_OP_SVC: - printf("registered service %s with handle=%d\n", - ble_uuid_to_str(ctxt->svc.svc_def->uuid, buf), - ctxt->svc.handle); - break; - - case BLE_GATT_REGISTER_OP_CHR: - printf("registering characteristic %s with " - "def_handle=%d val_handle=%d\n", - ble_uuid_to_str(ctxt->chr.chr_def->uuid, buf), - ctxt->chr.def_handle, ctxt->chr.val_handle); - break; - - case BLE_GATT_REGISTER_OP_DSC: - printf("registering descriptor %s with handle=%d\n", - ble_uuid_to_str(ctxt->dsc.dsc_def->uuid, buf), - ctxt->dsc.handle); - break; - - default: - assert(0); - break; - } -} - -int gatt_svr_init(void) -{ - int rc; - - ble_svc_ans_init(); - ble_svc_bas_init(); - - rc = ble_gatts_count_cfg(gatt_svr_svcs); - if (rc != 0) - { - return rc; - } - - rc = ble_gatts_add_svcs(gatt_svr_svcs); - if (rc != 0) - { - return rc; - } - - return 0; -} diff --git a/examples/nimble_bleprph/misc.c b/examples/nimble_bleprph/misc.c deleted file mode 100644 index 5007f24fa..000000000 --- a/examples/nimble_bleprph/misc.c +++ /dev/null @@ -1,40 +0,0 @@ -/**************************************************************************** - * apps/examples/nimble_bleprph/misc.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "bleprph.h" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -void print_addr(FAR const void *addr) -{ - FAR const uint8_t *u8p; - - u8p = addr; - printf("%02x:%02x:%02x:%02x:%02x:%02x", - u8p[5], u8p[4], u8p[3], u8p[2], u8p[1], u8p[0]); -} diff --git a/examples/nimble_bleprph/nimble_bleprph_main.c b/examples/nimble_bleprph/nimble_bleprph_main.c deleted file mode 100644 index 9c41f72b2..000000000 --- a/examples/nimble_bleprph/nimble_bleprph_main.c +++ /dev/null @@ -1,430 +0,0 @@ -/**************************************************************************** - * apps/examples/nimble_bleprph/nimble_bleprph_main.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <assert.h> -#include <string.h> -#include <stdio.h> -#include <errno.h> - -/* BLE */ - -#include "nimble/ble.h" -#include "nimble/nimble_port.h" -#include "host/ble_hs.h" -#include "host/util/util.h" -#include "services/gap/ble_svc_gap.h" -#include "services/bas/ble_svc_bas.h" - -/* Application-specified header. */ - -#include "bleprph.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* Not used now */ - -#define TASK_DEFAULT_PRIORITY CONFIG_EXAMPLES_NIMBLE_BLEPRPH_PRIORITY -#define TASK_DEFAULT_STACK NULL -#define TASK_DEFAULT_STACK_SIZE 0 - -/**************************************************************************** - * External Functions Prototypes - ****************************************************************************/ - -void ble_hci_sock_ack_handler(FAR void *param); -void ble_hci_sock_set_device(int dev); - -/**************************************************************************** - * Private Functions Prototypes - ****************************************************************************/ - -static void bleprph_advertise(void); -static void nimble_host_task(FAR void *param); -static FAR void *ble_hci_sock_task(FAR void *param); -static FAR void *ble_host_task(FAR void *param); -static int bleprph_gap_event(FAR struct ble_gap_event *event, FAR void *arg); - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: bleprph_print_conn_desc - ****************************************************************************/ - -static void bleprph_print_conn_desc(FAR struct ble_gap_conn_desc *desc) -{ - printf("handle=%d our_ota_addr_type=%d our_ota_addr=", - desc->conn_handle, desc->our_ota_addr.type); - print_addr(desc->our_ota_addr.val); - printf(" our_id_addr_type=%d our_id_addr=", - desc->our_id_addr.type); - print_addr(desc->our_id_addr.val); - printf(" peer_ota_addr_type=%d peer_ota_addr=", - desc->peer_ota_addr.type); - print_addr(desc->peer_ota_addr.val); - printf(" peer_id_addr_type=%d peer_id_addr=", - desc->peer_id_addr.type); - print_addr(desc->peer_id_addr.val); - printf(" conn_itvl=%d conn_latency=%d supervision_timeout=%d " - "encrypted=%d authenticated=%d bonded=%d\n", - desc->conn_itvl, desc->conn_latency, - desc->supervision_timeout, - desc->sec_state.encrypted, - desc->sec_state.authenticated, - desc->sec_state.bonded); -} - -/**************************************************************************** - * Name: bleprph_advertise - ****************************************************************************/ - -static void bleprph_advertise(void) -{ - struct ble_gap_adv_params adv_params; - struct ble_hs_adv_fields fields; - uint8_t own_addr_type; - FAR const char *name; - int rc; - - /* Figure out address to use while advertising (no privacy for now) */ - - rc = ble_hs_id_infer_auto(0, &own_addr_type); - if (rc != 0) - { - printf("error determining address type; rc=%d\n", rc); - return; - } - - /** - * Set the advertisement data included in our advertisements: - * o Flags (indicates advertisement type and other general info). - * o Advertising tx power. - * o Device name. - * o 16-bit service UUIDs (alert notifications). - */ - - memset(&fields, 0, sizeof fields); - - /* Advertise two flags: - * o Discoverability in forthcoming advertisement (general) - * o BLE-only (BR/EDR unsupported). - */ - - fields.flags = BLE_HS_ADV_F_DISC_GEN | - BLE_HS_ADV_F_BREDR_UNSUP; - - /* Indicate that the TX power level field should be included; have the - * stack fill this value automatically. This is done by assigning the - * special value BLE_HS_ADV_TX_PWR_LVL_AUTO. - */ - - fields.tx_pwr_lvl_is_present = 1; - fields.tx_pwr_lvl = BLE_HS_ADV_TX_PWR_LVL_AUTO; - - name = ble_svc_gap_device_name(); - fields.name = (FAR uint8_t *)name; - fields.name_len = strlen(name); - fields.name_is_complete = 1; - - fields.uuids16 = (ble_uuid16_t[]) - { - BLE_UUID16_INIT(GATT_SVR_SVC_ALERT_UUID) - }; - - fields.num_uuids16 = 1; - fields.uuids16_is_complete = 1; - - rc = ble_gap_adv_set_fields(&fields); - if (rc != 0) - { - printf("error setting advertisement data; rc=%d\n", rc); - return; - } - - /* Begin advertising. */ - - memset(&adv_params, 0, sizeof adv_params); - adv_params.conn_mode = BLE_GAP_CONN_MODE_UND; - adv_params.disc_mode = BLE_GAP_DISC_MODE_GEN; - rc = ble_gap_adv_start(own_addr_type, NULL, BLE_HS_FOREVER, - &adv_params, bleprph_gap_event, NULL); - if (rc != 0) - { - printf("error enabling advertisement; rc=%d\n", rc); - return; - } -} - -/**************************************************************************** - * Name: bleprph_gap_event - ****************************************************************************/ - -static int bleprph_gap_event(FAR struct ble_gap_event *event, FAR void *arg) -{ - struct ble_gap_conn_desc desc; - int rc; - - switch (event->type) - { - case BLE_GAP_EVENT_CONNECT: - - /* A new connection was established or a connection attempt failed. - */ - - printf("connection %s; status=%d ", - event->connect.status == 0 ? "established" : "failed", - event->connect.status); - if (event->connect.status == 0) - { - rc = ble_gap_conn_find(event->connect.conn_handle, &desc); - assert(rc == 0); - bleprph_print_conn_desc(&desc); - } - - printf("\n"); - - if (event->connect.status != 0) - { - /* Connection failed; resume advertising. */ - - bleprph_advertise(); - } - - return 0; - - case BLE_GAP_EVENT_DISCONNECT: - printf("disconnect; reason=%d ", event->disconnect.reason); - bleprph_print_conn_desc(&event->disconnect.conn); - printf("\n"); - - /* Connection terminated; resume advertising. */ - - bleprph_advertise(); - return 0; - - case BLE_GAP_EVENT_CONN_UPDATE: - - /* The central has updated the connection parameters. */ - - printf("connection updated; status=%d ", event->conn_update.status); - rc = ble_gap_conn_find(event->conn_update.conn_handle, &desc); - assert(rc == 0); - bleprph_print_conn_desc(&desc); - printf("\n"); - return 0; - - case BLE_GAP_EVENT_ADV_COMPLETE: - printf("advertise complete; reason=%d", event->adv_complete.reason); - bleprph_advertise(); - return 0; - - case BLE_GAP_EVENT_ENC_CHANGE: - - /* Encryption has been enabled or disabled for this connection. */ - - printf("encryption change event; status=%d ", - event->enc_change.status); - rc = ble_gap_conn_find(event->connect.conn_handle, &desc); - assert(rc == 0); - bleprph_print_conn_desc(&desc); - printf("\n"); - return 0; - - case BLE_GAP_EVENT_SUBSCRIBE: - printf("subscribe event; conn_handle=%d attr_handle=%d " - "reason=%d prevn=%d curn=%d previ=%d curi=%d\n", - event->subscribe.conn_handle, event->subscribe.attr_handle, - event->subscribe.reason, event->subscribe.prev_notify, - event->subscribe.cur_notify, event->subscribe.prev_indicate, - event->subscribe.cur_indicate); - return 0; - - case BLE_GAP_EVENT_MTU: - printf("mtu update event; conn_handle=%d cid=%d mtu=%d\n", - event->mtu.conn_handle, event->mtu.channel_id, - event->mtu.value); - return 0; - - case BLE_GAP_EVENT_REPEAT_PAIRING: - /* We already have a bond with the peer, but it is attempting to - * establish a new secure link. This app sacrifices security for - * convenience: just throw away the old bond and accept the new link. - */ - - /* Delete the old bond. */ - - rc = ble_gap_conn_find(event->repeat_pairing.conn_handle, &desc); - assert(rc == 0); - ble_store_util_delete_peer(&desc.peer_id_addr); - - /* Return BLE_GAP_REPEAT_PAIRING_RETRY to indicate that the host - * should continue with the pairing operation. - */ - - return BLE_GAP_REPEAT_PAIRING_RETRY; - } - - return 0; -} - -/**************************************************************************** - * Name: bleprph_on_reset - ****************************************************************************/ - -static void bleprph_on_reset(int reason) -{ - printf("Resetting state; reason=%d\n", reason); -} - -/**************************************************************************** - * Name: bleprph_on_sync - ****************************************************************************/ - -static void bleprph_on_sync(void) -{ - int rc; - - /* Make sure we have proper identity address set (public preferred) */ - - rc = ble_hs_util_ensure_addr(0); - assert(rc == 0); - - /* Begin advertising. */ - - bleprph_advertise(); -} - -/**************************************************************************** - * Name: nimble_host_task - ****************************************************************************/ - -static void nimble_host_task(FAR void *param) -{ - ble_svc_gap_device_name_set("NuttX NimBLE PRPH"); - nimble_port_run(); -} - -/**************************************************************************** - * Name: ble_hci_sock_task - ****************************************************************************/ - -static FAR void *ble_hci_sock_task(FAR void *param) -{ - ble_hci_sock_ack_handler(param); - return NULL; -} - -/**************************************************************************** - * Name: ble_host_task - ****************************************************************************/ - -static FAR void *ble_host_task(FAR void *param) -{ - nimble_host_task(param); - return NULL; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: nimble_main - ****************************************************************************/ - -int main(int argc, FAR char *argv[]) -{ - struct ble_npl_task s_task_host; - struct ble_npl_task s_task_hci; - uint8_t batt_level = 0; - int ret = 0; - - /* allow to specify custom hci */ - - if (argc > 1) - { - ble_hci_sock_set_device(atoi(argv[1])); - } - -#ifndef CONFIG_NSH_NETINIT - /* Bring up the network */ - - netinit_bringup(); -#endif - - nimble_port_init(); - - /* Initialize the NimBLE host configuration. */ - - ble_hs_cfg.reset_cb = bleprph_on_reset; - ble_hs_cfg.sync_cb = bleprph_on_sync; - ble_hs_cfg.gatts_register_cb = gatt_svr_register_cb; - ble_hs_cfg.store_status_cb = ble_store_util_status_rr; - - /* Initialize services */ - - ret = gatt_svr_init(); - assert(ret == 0); - - /* Create task which handles HCI socket */ - - ret = ble_npl_task_init(&s_task_hci, "hci_sock", ble_hci_sock_task, - NULL, TASK_DEFAULT_PRIORITY, BLE_NPL_TIME_FOREVER, - TASK_DEFAULT_STACK, TASK_DEFAULT_STACK_SIZE); - if (ret != 0) - { - printf("ERROR: starting hci task: %i\n", ret); - } - - /* Create task which handles default event queue for host stack. */ - - ret = ble_npl_task_init(&s_task_host, "ble_host", ble_host_task, - NULL, TASK_DEFAULT_PRIORITY, BLE_NPL_TIME_FOREVER, - TASK_DEFAULT_STACK, TASK_DEFAULT_STACK_SIZE); - if (ret != 0) - { - printf("ERROR: starting ble task: %i\n", ret); - } - - while (true) - { - /* Simulate battery */ - - batt_level += 1; - if (batt_level > 100) - { - batt_level = 0; - } - - ble_svc_bas_battery_level_set(batt_level); - usleep(100000); - } - - return 0; -} diff --git a/examples/nng_test/CMakeLists.txt b/examples/nng_test/CMakeLists.txt deleted file mode 100644 index 3d35655ee..000000000 --- a/examples/nng_test/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# ############################################################################## -# apps/examples/nng_test/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_NNG_TEST) - nuttx_add_application( - NAME - pubsub - PRIORITY - ${CONFIG_EXAMPLES_NNG_TEST_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_NNG_TEST_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_NNG_TEST} - SRCS - pubsub.c) -endif() diff --git a/examples/nng_test/Kconfig b/examples/nng_test/Kconfig deleted file mode 100644 index 6bb0c8dc5..000000000 --- a/examples/nng_test/Kconfig +++ /dev/null @@ -1,22 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config EXAMPLES_NNG_TEST - bool "NNG pubsub program" - default n - ---help--- - Enable the NNG pubsub program - -if EXAMPLES_NNG_TEST - -config EXAMPLES_NNG_TEST_STACKSIZE - int "NNG pubsub stack size" - default DEFAULT_TASK_STACKSIZE - -config EXAMPLES_NNG_TEST_PRIORITY - int "NNG pubsub task priority" - default 50 - -endif diff --git a/examples/nng_test/Make.defs b/examples/nng_test/Make.defs deleted file mode 100644 index c8a42149b..000000000 --- a/examples/nng_test/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/examples/nng_test/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_EXAMPLES_NNG_TEST),) -CONFIGURED_APPS += $(APPDIR)/examples/nng_test -endif diff --git a/examples/nng_test/Makefile b/examples/nng_test/Makefile deleted file mode 100644 index 7ab7ecb6c..000000000 --- a/examples/nng_test/Makefile +++ /dev/null @@ -1,34 +0,0 @@ -############################################################################ -# apps/examples/nng_test/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -MAINSRC = pubsub.c - -# Built-in application info - -PROGNAME = pubsub -PRIORITY = $(CONFIG_EXAMPLES_NNG_TEST_PRIORITY) -STACKSIZE = $(CONFIG_EXAMPLES_NNG_TEST_STACKSIZE) -MODULE = $(CONFIG_EXAMPLES_NNG_TEST) - -include $(APPDIR)/Application.mk diff --git a/examples/nng_test/pubsub.c b/examples/nng_test/pubsub.c deleted file mode 100644 index 78e427eb2..000000000 --- a/examples/nng_test/pubsub.c +++ /dev/null @@ -1,143 +0,0 @@ -/**************************************************************************** - * apps/examples/nng_test/pubsub.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <time.h> -#include <unistd.h> -#include <pthread.h> -#include <fcntl.h> -#include <errno.h> -#include <nuttx/debug.h> - -#include <nng/nng.h> -#include <nng/protocol/pubsub0/pub.h> -#include <nng/protocol/pubsub0/sub.h> - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -void fatal(FAR const char *func, int rv) -{ - fprintf(stderr, "%s: %s\n", func, nng_strerror(rv)); -} - -FAR char *date(void) -{ - time_t now = time(&now); - FAR struct tm *info = localtime(&now); - FAR char *text = asctime(info); - text[strlen(text) - 1] = '\0'; - return text; -} - -FAR void *client_thread(pthread_addr_t pvarg) -{ - nng_socket sock; - int rv; - - sleep(2); - - if ((rv = nng_sub0_open(&sock)) != 0) - { - fatal("nng_sub0_open", rv); - return NULL; - } - - /* subscribe to everything (empty means all topics) */ - - if ((rv = nng_setopt(sock, NNG_OPT_SUB_SUBSCRIBE, "", 0)) != 0) - { - fatal("nng_setopt", rv); - return NULL; - } - - if ((rv = nng_dial(sock, "ipc:///pubsub.ipc", NULL, 0)) != 0) - { - fatal("nng_dial", rv); - return NULL; - } - - for (; ; ) - { - FAR char *buf = NULL; - size_t sz; - - if ((rv = nng_recv(sock, &buf, &sz, NNG_FLAG_ALLOC)) != 0) - { - fatal("nng_recv", rv); - break; - } - - printf("CLIENT: RECEIVED %s\n", buf); - nng_free(buf, sz); - } - - return NULL; /* Keeps some compilers from complaining */ -} - -int main(const int argc, const FAR char *argv[]) -{ - pthread_t tid; - nng_socket sock; - int rv; - - if ((rv = nng_pub0_open(&sock)) != 0) - { - fatal("nng_pub0_open", rv); - return 1; - } - - rv = pthread_create(&tid, NULL, client_thread, NULL); - if (rv != 0) - { - fatal("main: Failed to create client thread: %d\n", rv); - return 1; - } - - if ((rv = nng_listen(sock, "ipc:///pubsub.ipc", NULL, 0)) < 0) - { - fatal("nng_listen", rv); - return 1; - } - - for (; ; ) - { - FAR char *d = date(); - printf("SERVER: PUBLISHING DATE %s\n", d); - if ((rv = nng_send(sock, d, strlen(d) + 1, 0)) != 0) - { - fatal("nng_send", rv); - break; - } - - sleep(1); - } - - return 1; -} diff --git a/examples/noteprintf/CMakeLists.txt b/examples/noteprintf/CMakeLists.txt deleted file mode 100644 index 3bcfc483a..000000000 --- a/examples/noteprintf/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# ############################################################################## -# apps/examples/noteprintf/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_NOTEPRINTF) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_NOTEPRINTF_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_NOTEPRINTF_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_NOTEPRINTF_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_NOTEPRINTF} - SRCS - noteprintf_main.c) -endif() diff --git a/examples/noteprintf/Make.defs b/examples/noteprintf/Make.defs index eb21a4d5c..3c481289d 100644 --- a/examples/noteprintf/Make.defs +++ b/examples/noteprintf/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/noteprintf/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/noteprintf/Makefile b/examples/noteprintf/Makefile index b14eddf98..79f08d09d 100644 --- a/examples/noteprintf/Makefile +++ b/examples/noteprintf/Makefile @@ -1,7 +1,5 @@ ############################################################################ -# apps/examples/noteprintf/Makefile -# -# SPDX-License-Identifier: Apache-2.0 +# apps/examples/noteprintf/Make.defs # # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with diff --git a/examples/noteprintf/noteprintf_main.c b/examples/noteprintf/noteprintf_main.c index 2717d7a1b..a12df95d0 100644 --- a/examples/noteprintf/noteprintf_main.c +++ b/examples/noteprintf/noteprintf_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/noteprintf/noteprintf_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -25,9 +23,7 @@ ****************************************************************************/ #include <nuttx/config.h> - #include <stdio.h> -#include <unistd.h> #include "nuttx/sched_note.h" @@ -47,13 +43,25 @@ int main(int argc, FAR char *argv[]) { - char *str = "sched note test"; + struct binary + { + uint8_t val1; + uint8_t val2; + } binary = + { + .val1 = 0x01, + .val2 = 0x02 + }; + + char *str = "shced note test"; int count = 0; char c = 1; short s = 2; int i = 3; long l = 4; +#ifdef CONFIG_LIBC_LONG_LONG long long ll = 5; +#endif intmax_t im = 6; size_t sz = 7; ptrdiff_t ptr = 8; @@ -69,29 +77,29 @@ int main(int argc, FAR char *argv[]) while (1) { - sched_note_printf(NOTE_TAG_ALWAYS, - "sched note test count = %d.", count++); - sched_note_mark(NOTE_TAG_ALWAYS, str); - sched_note_printf(NOTE_TAG_ALWAYS, "%hhd", c); - sched_note_printf(NOTE_TAG_ALWAYS, "%hd", s); - sched_note_printf(NOTE_TAG_ALWAYS, "%d", i); - sched_note_printf(NOTE_TAG_ALWAYS, "%ld", l); - sched_note_printf(NOTE_TAG_ALWAYS, "%lld", ll); - sched_note_printf(NOTE_TAG_ALWAYS, "%jd", im); - sched_note_printf(NOTE_TAG_ALWAYS, "%zd", sz); - sched_note_printf(NOTE_TAG_ALWAYS, "%td", ptr); + sched_note_printf("shced note test count = %d.", count++); + sched_note_string(str); + sched_note_dump(MAIN_MODULE, 1, &binary, sizeof(struct binary)); + sched_note_bprintf(MAIN_MODULE, 2, "%hhd", c); + sched_note_bprintf(MAIN_MODULE, 3, "%hd", s); + sched_note_bprintf(MAIN_MODULE, 4, "%d", i); + sched_note_bprintf(MAIN_MODULE, 5, "%ld", l); + sched_note_bprintf(MAIN_MODULE, 6, "%lld", ll); + sched_note_bprintf(MAIN_MODULE, 7, "%jd", im); + sched_note_bprintf(MAIN_MODULE, 8, "%zd", sz); + sched_note_bprintf(MAIN_MODULE, 9, "%td", ptr); #ifdef CONFIG_HAVE_FLOAT - sched_note_printf(NOTE_TAG_ALWAYS, "%e", f); + sched_note_bprintf(MAIN_MODULE, 10, "%e", f); #endif #ifdef CONFIG_HAVE_DOUBLE - sched_note_printf(NOTE_TAG_ALWAYS, "%le", d); + sched_note_bprintf(MAIN_MODULE, 11, "%le", d); #endif #ifdef CONFIG_HAVE_LONG_DOUBLE - sched_note_printf(NOTE_TAG_ALWAYS, "%Le", ld); + sched_note_bprintf(MAIN_MODULE, 12, "%Le", ld); #endif - sched_note_printf(NOTE_TAG_ALWAYS, - "%hhd %hd %d %ld %lld %jd %zd %td", - c, s, i, l, ll, im, sz, ptr); + sched_note_bprintf(MAIN_MODULE, 13, + "%hhd %hd %d %ld %lld %jd %zd %td", + c, s, i, l, ll, im, sz, ptr); usleep(10); } diff --git a/examples/nrf24l01_btle/CMakeLists.txt b/examples/nrf24l01_btle/CMakeLists.txt deleted file mode 100644 index ec150791f..000000000 --- a/examples/nrf24l01_btle/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# ############################################################################## -# apps/examples/nrf24l01_btle/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_NRF24L01_BTLE) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_NRF24L01_BTLE_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_NRF24L01_BTLE_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_NRF24L01_BTLE_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_NRF24L01_BTLE} - SRCS - nrf24l01_btle.c) -endif() diff --git a/examples/nrf24l01_btle/Kconfig b/examples/nrf24l01_btle/Kconfig index fc3554678..99b928da3 100644 --- a/examples/nrf24l01_btle/Kconfig +++ b/examples/nrf24l01_btle/Kconfig @@ -39,6 +39,6 @@ config NRF24L01_BTLE_DHT11 default n depends on SENSORS_DHTXX ---help--- - Enable driver support for the DHTxx humidity/temperature sensor. + Enable driver support for the DHTxx humidity/temperature sensor. endif diff --git a/examples/nrf24l01_btle/Make.defs b/examples/nrf24l01_btle/Make.defs index adb767470..459ce982b 100644 --- a/examples/nrf24l01_btle/Make.defs +++ b/examples/nrf24l01_btle/Make.defs @@ -1,8 +1,7 @@ ############################################################################ # apps/examples/nrf24l01_btle/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# + +# Adds selected applications to apps/ build # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/nrf24l01_btle/Makefile b/examples/nrf24l01_btle/Makefile index 621635598..4e1eda4e1 100644 --- a/examples/nrf24l01_btle/Makefile +++ b/examples/nrf24l01_btle/Makefile @@ -1,22 +1,20 @@ ############################################################################ # apps/examples/nrf24l01_btle/Makefile # -# SPDX-License-Identifier: Apache-2.0 +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. The +# ASF licenses this file to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance with the +# License. You may obtain a copy of the License at # -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at +# http://www.apache.org/licenses/LICENSE-2.0 # -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. # ############################################################################ diff --git a/examples/nrf24l01_btle/nrf24l01_btle.c b/examples/nrf24l01_btle/nrf24l01_btle.c index d7f24ab3c..bc976e421 100644 --- a/examples/nrf24l01_btle/nrf24l01_btle.c +++ b/examples/nrf24l01_btle/nrf24l01_btle.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/nrf24l01_btle/nrf24l01_btle.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -27,8 +25,7 @@ #include <sys/types.h> #include <sys/stat.h> #include <sys/ioctl.h> -#include <nuttx/debug.h> -#include <unistd.h> +#include <debug.h> #include <nuttx/signal.h> #include <nuttx/sensors/dhtxx.h> @@ -154,9 +151,10 @@ static inline void crc(uint8_t len, uint8_t * dst) uint8_t i; uint8_t * buf = (uint8_t *)&buffer; - /* initialize 24-bit shift register in "wire bit order" + /** + * initialize 24-bit shift register in "wire bit order" * dst[0] = bits 23-16, dst[1] = bits 15-8, dst[2] = bits 7-0. - */ + **/ dst[0] = 0xaa; dst[1] = 0xaa; @@ -167,24 +165,27 @@ static inline void crc(uint8_t len, uint8_t * dst) uint8_t d = *(buf++); for (i = 1; i; i <<= 1, d >>= 1) { - /* save bit 23 (highest-value), + /** + * save bit 23 (highest-value), * left-shift the entire register by one - */ + **/ uint8_t t = dst[0] & 0x01; dst[0] >>= 1; if (dst[1] & 0x01) dst[0] |= 0x80; dst[1] >>= 1; if (dst[2] & 0x01) dst[1] |= 0x80; dst[2] >>= 1; - /* if the bit just shifted out (former bit 23) and the incoming + /** + * if the bit just shifted out (former bit 23) and the incoming * data bit are not equal (i.e. bit_out ^ bit_in == 1) => toggle * tap bits */ if (t != (d & 1)) { - /* toggle register tap bits (=XOR with 1) + /** + * toggle register tap bits (=XOR with 1) * according to CRC polynom - */ + **/ /* 0b11011010 inv. = 0b01011011 ^= x^6+x^4+x^3+x+1 */ @@ -217,11 +218,17 @@ int nrf24_cfg(int fd) uint32_t rf = NRF24L01_MIN_FREQ + frequency[current]; int32_t txpow = DEFAULT_TXPOWER; - nrf24l01_datarate_t datarate = RATE_1Mbps; + /************************************************************************** + * if using RATE_1Mbps from include/nuttx/wireless/nrf24l01.h, + * tools/checkpatch.sh report error: Mixed case identifier found. + * + **************************************************************************/ + + nrf24l01_datarate_t datarate = 0; /* RATE_1Mbps */ nrf24l01_retrcfg_t retrcfg = { .count = 0, - .delay = DELAY_1000us + .delay = 3 /* DELAY_1000us */ }; uint32_t addrwidth = 4; @@ -467,7 +474,7 @@ static void adv_packet(int wl_fd) FAR void *advertise(FAR void *arg) { - uint32_t wl_fd = *(FAR uint32_t *)arg; + uint32_t wl_fd = *(uint32_t *)arg; while (!quit) { if (current == 2) @@ -484,9 +491,9 @@ int nrf24_read(int wl_fd) { int ret; uint32_t pipeno; - uint8_t rbuf[NRF24L01_MAX_PAYLOAD_LEN + 1]; + uint8_t rbuf[32]; - ret = read(wl_fd, rbuf, NRF24L01_MAX_PAYLOAD_LEN); + ret = read(wl_fd, rbuf, sizeof(rbuf)); if (ret < 0) { perror("Error reading packet\n"); @@ -512,7 +519,7 @@ int nrf24_read(int wl_fd) #ifdef CONFIG_DEBUG_WIRELESS syslog(LOG_INFO, "Message received : (on pipe %d)\n", pipeno); - nrf24_dumpbuffer("Hex Dump", &rbuf[0], ret); + nrf24_dumpbuffer("Hex Dump", &rbuf[0], 32); #endif return 0; } diff --git a/examples/nrf24l01_btle/nrf24l01_btle.h b/examples/nrf24l01_btle/nrf24l01_btle.h index 9394ee568..04c823057 100644 --- a/examples/nrf24l01_btle/nrf24l01_btle.h +++ b/examples/nrf24l01_btle/nrf24l01_btle.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/nrf24l01_btle/nrf24l01_btle.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -31,7 +29,7 @@ #include <stdint.h> #include <stdbool.h> -#include <nuttx/debug.h> +#include <debug.h> /**************************************************************************** * Pre-processor Definitions @@ -39,7 +37,7 @@ /* Service UUIDs used on the nRF8001 and nRF51822 platforms */ -#define NRF_TEMPERATURE_SERVICE_UUID 0x1809 +#define NRF_TEMPERATURE_SERVICE_UUID 0x1809 #define NRF_ENVIRONMENTAL_SERVICE_UUID 0x181A /**************************************************************************** @@ -58,7 +56,7 @@ struct nrf_service_data struct btle_adv_pdu { - /* PDU type, most of it 0x42 */ + /* PDU type, most of it 0x42 */ uint8_t pdu_type; @@ -98,4 +96,4 @@ int nrf24_open(void); int nrf24_send(int wl_fd, uint8_t * buf, uint8_t len); -#endif /* __APPS_EXAMPLES_NRF24L01_BTLE_NRF24L01_BTLE_H */ +#endif /* __APPS_EXAMPLES_NRF24L01_BTLE_NRF24L01_BTLE_H */ diff --git a/examples/nrf24l01_term/CMakeLists.txt b/examples/nrf24l01_term/CMakeLists.txt deleted file mode 100644 index e1e46c0ae..000000000 --- a/examples/nrf24l01_term/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# ############################################################################## -# apps/examples/nrf24l01_term/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_NRF24L01TERM) - nuttx_add_application( - NAME - nrf24l01_term - STACKSIZE - ${CONFIG_DEFAULT_TASK_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_NRF24L01TERM} - SRCS - nrf24l01_term.c) -endif() diff --git a/examples/nrf24l01_term/Make.defs b/examples/nrf24l01_term/Make.defs index 35985af7f..4129a49f5 100644 --- a/examples/nrf24l01_term/Make.defs +++ b/examples/nrf24l01_term/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/nrf24l01_term/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/nrf24l01_term/Makefile b/examples/nrf24l01_term/Makefile index f496bd852..f0911da2e 100644 --- a/examples/nrf24l01_term/Makefile +++ b/examples/nrf24l01_term/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/nrf24l01_term/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/nrf24l01_term/nrf24l01_term.c b/examples/nrf24l01_term/nrf24l01_term.c index e8c41e8c3..80cec95cf 100644 --- a/examples/nrf24l01_term/nrf24l01_term.c +++ b/examples/nrf24l01_term/nrf24l01_term.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/nrf24l01_term/nrf24l01_term.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -30,6 +28,7 @@ #include <sys/stat.h> #include <sys/ioctl.h> +#include <unistd.h> #include <inttypes.h> #include <stdint.h> #include <stdbool.h> @@ -38,7 +37,7 @@ #include <string.h> #include <stdlib.h> #include <errno.h> -#include <nuttx/debug.h> +#include <debug.h> #include <poll.h> #include <fcntl.h> @@ -193,7 +192,7 @@ int send_pkt(int wl_fd) len = strlen(buff); if (len > 0 && buff[len - 1] == '\n') { - len--; + len --; buff[len] = '\0'; } @@ -221,7 +220,7 @@ int read_pkt(int wl_fd) int ret; uint32_t pipeno; - ret = read(wl_fd, buff, sizeof(buff) - 1); + ret = read(wl_fd, buff, sizeof(buff)); if (ret < 0) { perror("Error reading packet\n"); @@ -322,8 +321,7 @@ int main(int argc, FAR char *argv[]) goto out; } #else - ret = readline_stream(&buff[1], sizeof(buff) - 1, - stdin, stdout); + ret = readline(&buff[1], sizeof(buff) - 1, stdin, stdout); /* Readline normally returns the number of characters read, * but will return EOF on end of file or if an error occurs. diff --git a/examples/null/CMakeLists.txt b/examples/null/CMakeLists.txt deleted file mode 100644 index 299433f0b..000000000 --- a/examples/null/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# ############################################################################## -# apps/examples/null/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_NULL) - nuttx_add_application( - NAME - null - STACKSIZE - ${CONFIG_DEFAULT_TASK_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_NULL} - SRCS - null_main.c) -endif() diff --git a/examples/null/Make.defs b/examples/null/Make.defs index 6d55c9de2..0fdb580f4 100644 --- a/examples/null/Make.defs +++ b/examples/null/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/null/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/null/Makefile b/examples/null/Makefile index 602f61171..b5a051051 100644 --- a/examples/null/Makefile +++ b/examples/null/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/null/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/null/null_main.c b/examples/null/null_main.c index 0e9ea160e..43702b20d 100644 --- a/examples/null/null_main.c +++ b/examples/null/null_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/null/null_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/nunchuck/CMakeLists.txt b/examples/nunchuck/CMakeLists.txt deleted file mode 100644 index 50680da74..000000000 --- a/examples/nunchuck/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# ############################################################################## -# apps/examples/nunchuck/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_NUNCHUCK) - nuttx_add_application( - NAME - nunchuck - STACKSIZE - ${CONFIG_DEFAULT_TASK_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_NUNCHUCK} - SRCS - nunchuck_main.c) -endif() diff --git a/examples/nunchuck/Make.defs b/examples/nunchuck/Make.defs index 931735e59..1ec2ae312 100644 --- a/examples/nunchuck/Make.defs +++ b/examples/nunchuck/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/nunchuck/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/nunchuck/Makefile b/examples/nunchuck/Makefile index 87e66e50c..1bcb336bf 100644 --- a/examples/nunchuck/Makefile +++ b/examples/nunchuck/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/nunchuck/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/nunchuck/nunchuck_main.c b/examples/nunchuck/nunchuck_main.c index 63200288c..2e28ebbc7 100644 --- a/examples/nunchuck/nunchuck_main.c +++ b/examples/nunchuck/nunchuck_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/nunchuck/nunchuck_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -27,14 +25,12 @@ #include <nuttx/config.h> #include <sys/ioctl.h> -#include <sys/param.h> #include <stdio.h> #include <stdlib.h> #include <fcntl.h> #include <errno.h> #include <fixedmath.h> -#include <nuttx/debug.h> -#include <unistd.h> +#include <debug.h> #include <nuttx/input/nunchuck.h> @@ -54,6 +50,15 @@ #define FULL_RANGE 16 +/* Helpers ******************************************************************/ + +#ifndef MIN +# define MIN(a,b) ((a) < (b) ? (a) : (b)) +#endif +#ifndef MAX +# define MAX(a,b) ((a) > (b) ? (a) : (b)) +#endif + /**************************************************************************** * Private Function Prototypes ****************************************************************************/ diff --git a/examples/nx/CMakeLists.txt b/examples/nx/CMakeLists.txt deleted file mode 100644 index a4ff9f8d1..000000000 --- a/examples/nx/CMakeLists.txt +++ /dev/null @@ -1,34 +0,0 @@ -# ############################################################################## -# apps/examples/nx/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_NX) - nuttx_add_application( - NAME - nx - STACKSIZE - ${CONFIG_DEFAULT_TASK_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_NX} - SRCS - nx_main.c) - target_sources(apps PRIVATE nx_events.c nx_kbdin.c) -endif() diff --git a/examples/nx/Kconfig b/examples/nx/Kconfig index 29baace4f..c5ac50ac9 100644 --- a/examples/nx/Kconfig +++ b/examples/nx/Kconfig @@ -103,4 +103,10 @@ config EXAMPLES_NX_LISTENERPRIO ---help--- The priority of the event listener thread. Default 80. +config EXAMPLES_NX_NOTIFYSIGNO + int "Notify Signal Number" + default 4 + ---help--- + The signal number to use with nx_eventnotify(). Default: 4 + endif diff --git a/examples/nx/Make.defs b/examples/nx/Make.defs index db23b214e..c8adfaba4 100644 --- a/examples/nx/Make.defs +++ b/examples/nx/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/nx/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/nx/Makefile b/examples/nx/Makefile index cacdb2e31..b743cf0ef 100644 --- a/examples/nx/Makefile +++ b/examples/nx/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/nx/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/nx/nx_events.c b/examples/nx/nx_events.c index 065c4e3cf..7aaf1272d 100644 --- a/examples/nx/nx_events.c +++ b/examples/nx/nx_events.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/nx/nx_events.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -31,7 +29,7 @@ #include <stdio.h> #include <stdlib.h> #include <semaphore.h> -#include <nuttx/debug.h> +#include <debug.h> #include <errno.h> #include <nuttx/nx/nx.h> @@ -52,30 +50,25 @@ static void nxeg_redraw(NXEGWINDOW hwnd, FAR const struct nxgl_rect_s *rect, bool morem, FAR void *arg); -static void nxeg_position(NXEGWINDOW hwnd, - FAR const struct nxgl_size_s *size, +static void nxeg_position(NXEGWINDOW hwnd, FAR const struct nxgl_size_s *size, FAR const struct nxgl_point_s *pos, FAR const struct nxgl_rect_s *bounds, FAR void *arg); #ifdef CONFIG_NX_XYINPUT -static void nxeg_mousein(NXEGWINDOW hwnd, - FAR const struct nxgl_point_s *pos, +static void nxeg_mousein(NXEGWINDOW hwnd, FAR const struct nxgl_point_s *pos, uint8_t buttons, FAR void *arg); #endif #ifndef CONFIG_EXAMPLES_NX_RAWWINDOWS -static void nxeg_tbredraw(NXEGWINDOW hwnd, - FAR const struct nxgl_rect_s *rect, +static void nxeg_tbredraw(NXEGWINDOW hwnd, FAR const struct nxgl_rect_s *rect, bool morem, FAR void *arg); -static void nxeg_tbposition(NXEGWINDOW hwnd, - FAR const struct nxgl_size_s *size, +static void nxeg_tbposition(NXEGWINDOW hwnd, FAR const struct nxgl_size_s *size, FAR const struct nxgl_point_s *pos, FAR const struct nxgl_rect_s *bounds, FAR void *arg); #ifdef CONFIG_NX_XYINPUT -static void nxeg_tbmousein(NXEGWINDOW hwnd, - FAR const struct nxgl_point_s *pos, - uint8_t buttons, FAR void *arg); +static void nxeg_tbmousein(NXEGWINDOW hwnd, FAR const struct nxgl_point_s *pos, + uint8_t buttons, FAR void *arg); #endif #endif @@ -142,7 +135,6 @@ static inline void nxeg_fillwindow(NXEGWINDOW hwnd, printf("nxeg_fillwindow: nxtk_fillwindow failed: %d\n", errno); } #endif - #ifdef CONFIG_NX_KBD nxeg_filltext(hwnd, rect, st); #endif @@ -154,8 +146,8 @@ static inline void nxeg_fillwindow(NXEGWINDOW hwnd, #ifndef CONFIG_EXAMPLES_NX_RAWWINDOWS static inline void nxeg_filltoolbar(NXTKWINDOW htb, - FAR const struct nxgl_rect_s *rect, - nxgl_mxpixel_t color[CONFIG_NX_NPLANES]) + FAR const struct nxgl_rect_s *rect, + nxgl_mxpixel_t color[CONFIG_NX_NPLANES]) { int ret; @@ -187,8 +179,7 @@ static void nxeg_redraw(NXEGWINDOW hwnd, FAR const struct nxgl_rect_s *rect, * Name: nxeg_position ****************************************************************************/ -static void nxeg_position(NXEGWINDOW hwnd, - FAR const struct nxgl_size_s *size, +static void nxeg_position(NXEGWINDOW hwnd, FAR const struct nxgl_size_s *size, FAR const struct nxgl_point_s *pos, FAR const struct nxgl_rect_s *bounds, FAR void *arg) @@ -197,8 +188,7 @@ static void nxeg_position(NXEGWINDOW hwnd, /* Report the position */ - printf("nxeg_position%d: hwnd=%p size=(%d,%d) pos=(%d,%d) " - "bounds={(%d,%d),(%d,%d)}\n", + printf("nxeg_position%d: hwnd=%p size=(%d,%d) pos=(%d,%d) bounds={(%d,%d),(%d,%d)}\n", st->wnum, hwnd, size->w, size->h, pos->x, pos->y, bounds->pt1.x, bounds->pt1.y, bounds->pt2.x, bounds->pt2.y); @@ -206,9 +196,7 @@ static void nxeg_position(NXEGWINDOW hwnd, if (!b_haveresolution) { - /* Save the window limits (these should be the same for all places - * and all windows. - */ + /* Save the window limits (these should be the same for all places and all windows */ g_xres = bounds->pt2.x; g_yres = bounds->pt2.y; @@ -238,8 +226,7 @@ static void nxeg_mousein(NXEGWINDOW hwnd, FAR const struct nxgl_point_s *pos, ****************************************************************************/ #ifndef CONFIG_EXAMPLES_NX_RAWWINDOWS -static void nxeg_tbredraw(NXEGWINDOW hwnd, - FAR const struct nxgl_rect_s *rect, +static void nxeg_tbredraw(NXEGWINDOW hwnd, FAR const struct nxgl_rect_s *rect, bool more, FAR void *arg) { FAR struct nxeg_state_s *st = (FAR struct nxeg_state_s *)arg; @@ -256,18 +243,16 @@ static void nxeg_tbredraw(NXEGWINDOW hwnd, ****************************************************************************/ #ifndef CONFIG_EXAMPLES_NX_RAWWINDOWS -static void nxeg_tbposition(NXEGWINDOW hwnd, - FAR const struct nxgl_size_s *size, - FAR const struct nxgl_point_s *pos, - FAR const struct nxgl_rect_s *bounds, - FAR void *arg) +static void nxeg_tbposition(NXEGWINDOW hwnd, FAR const struct nxgl_size_s *size, + FAR const struct nxgl_point_s *pos, + FAR const struct nxgl_rect_s *bounds, + FAR void *arg) { FAR struct nxeg_state_s *st = (FAR struct nxeg_state_s *)arg; /* Report the position */ - printf("nxeg_ptbosition%d: hwnd=%p size=(%d,%d) pos=(%d,%d) " - "bounds={(%d,%d),(%d,%d)}\n", + printf("nxeg_ptbosition%d: hwnd=%p size=(%d,%d) pos=(%d,%d) bounds={(%d,%d),(%d,%d)}\n", st->wnum, hwnd, size->w, size->h, pos->x, pos->y, bounds->pt1.x, bounds->pt1.y, bounds->pt2.x, bounds->pt2.y); } @@ -279,9 +264,8 @@ static void nxeg_tbposition(NXEGWINDOW hwnd, #ifndef CONFIG_EXAMPLES_NX_RAWWINDOWS #ifdef CONFIG_NX_XYINPUT -static void nxeg_tbmousein(NXEGWINDOW hwnd, - FAR const struct nxgl_point_s *pos, - uint8_t buttons, FAR void *arg) +static void nxeg_tbmousein(NXEGWINDOW hwnd, FAR const struct nxgl_point_s *pos, + uint8_t buttons, FAR void *arg) { FAR struct nxeg_state_s *st = (FAR struct nxeg_state_s *)arg; @@ -305,7 +289,7 @@ FAR void *nx_listenerthread(FAR void *arg) /* Process events forever */ - for (; ; ) + for (;;) { /* Handle the next event. If we were configured blocking, then * we will stay right here until the next event is received. Since diff --git a/examples/nx/nx_internal.h b/examples/nx/nx_internal.h index c92b1ccfa..906466162 100644 --- a/examples/nx/nx_internal.h +++ b/examples/nx/nx_internal.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/nx/nx_internal.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -62,7 +60,7 @@ # define CONFIG_EXAMPLES_NX_BGCOLOR 0x7b5d # else # define CONFIG_EXAMPLES_NX_BGCOLOR ' ' -# endif +# endif #endif #ifndef CONFIG_EXAMPLES_NX_COLOR1 @@ -72,7 +70,7 @@ # define CONFIG_EXAMPLES_NX_COLOR1 0xe73f # else # define CONFIG_EXAMPLES_NX_COLOR1 '1' -# endif +# endif #endif #ifndef CONFIG_EXAMPLES_NX_COLOR2 @@ -82,7 +80,7 @@ # define CONFIG_EXAMPLES_NX_COLOR2 0xdefb # else # define CONFIG_EXAMPLES_NX_COLOR2 '2' -# endif +# endif #endif #ifndef CONFIG_EXAMPLES_NX_TBCOLOR @@ -136,6 +134,9 @@ #ifndef CONFIG_EXAMPLES_NX_SERVERPRIO # define CONFIG_EXAMPLES_NX_SERVERPRIO 120 #endif +#ifndef CONFIG_EXAMPLES_NX_NOTIFYSIGNO +# define CONFIG_EXAMPLES_NX_NOTIFYSIGNO 4 +#endif #ifdef CONFIG_EXAMPLES_NX_RAWWINDOWS # define NXEGWINDOW NXWINDOW diff --git a/examples/nx/nx_kbdin.c b/examples/nx/nx_kbdin.c index 51f0e7efd..137207f81 100644 --- a/examples/nx/nx_kbdin.c +++ b/examples/nx/nx_kbdin.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/nx/nx_kbdin.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -31,7 +29,7 @@ #include <stdio.h> #include <string.h> #include <ctype.h> -#include <nuttx/debug.h> +#include <debug.h> #include <errno.h> #include <nuttx/nx/nx.h> @@ -109,8 +107,7 @@ static void nxeg_fillchar(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect, if (!nxgl_nullrect(&intersection)) { #ifndef CONFIG_EXAMPLES_NX_RAWWINDOWS - ret = nxtk_bitmapwindow((NXTKWINDOW)hwnd, &intersection, - (FAR const void **)&src, + ret = nxtk_bitmapwindow((NXTKWINDOW)hwnd, &intersection, (FAR const void **)&src, &bm->bounds.pt1, (unsigned int)bm->glyph->stride); if (ret < 0) @@ -166,7 +163,7 @@ nxeg_renderglyph(FAR struct nxeg_state_s *st, /* Allocate memory to hold the glyph with its offsets */ glyph->stride = (glyph->width * CONFIG_EXAMPLES_NX_BPP + 7) / 8; - bmsize = glyph->stride * glyph->height; + bmsize = glyph->stride * glyph->height; glyph->bitmap = (FAR uint8_t *)malloc(bmsize); if (glyph->bitmap) @@ -179,13 +176,13 @@ nxeg_renderglyph(FAR struct nxeg_state_s *st, /* Pack 1-bit pixels into a 2-bits */ pixel &= 0x01; - pixel = (pixel) << 1 | pixel; + pixel = (pixel) << 1 |pixel; # endif # if CONFIG_EXAMPLES_NX_BPP < 4 /* Pack 2-bit pixels into a nibble */ pixel &= 0x03; - pixel = (pixel) << 2 | pixel; + pixel = (pixel) << 2 |pixel; # endif /* Pack 4-bit nibbles into a byte */ @@ -223,7 +220,7 @@ nxeg_renderglyph(FAR struct nxeg_state_s *st, /* Then render the glyph into the allocated memory */ - ret = RENDERER((FAR nxgl_mxpixel_t *)glyph->bitmap, + ret = RENDERER((FAR nxgl_mxpixel_t*)glyph->bitmap, glyph->height, glyph->width, glyph->stride, bm, CONFIG_EXAMPLES_NX_FONTCOLOR); if (ret < 0) @@ -237,9 +234,9 @@ nxeg_renderglyph(FAR struct nxeg_state_s *st, } else { - /* Make it permanent */ + /* Make it permanent */ - st->nglyphs++; + st->nglyphs++; } } } @@ -270,7 +267,6 @@ nxeg_addspace(FAR struct nxeg_state_s *st, uint8_t ch) st->nglyphs++; } - return glyph; } @@ -285,14 +281,13 @@ nxeg_findglyph(FAR struct nxeg_state_s *st, uint8_t ch) /* First, try to find the glyph in the cache of pre-rendered glyphs */ - for (i = 0; i < st->nglyphs; i++) + for (i = 0; i < st->nglyphs; i++) { if (st->glyph[i].code == ch) { return &st->glyph[i]; } } - return NULL; } @@ -316,22 +311,21 @@ nxeg_getglyph(FAR struct nxeg_state_s *st, uint8_t ch) bm = nxf_getbitmap(g_fonthandle, ch); if (!bm) { - /* No, there is no glyph for this code. Use space. */ + /* No, there is no glyph for this code. Use space */ glyph = nxeg_findglyph(st, ' '); if (!glyph) { - /* There isn't a fake glyph for ' ' yet... create one */ + /* There isn't fake glyph for ' ' yet... create one */ glyph = nxeg_addspace(st, ' '); } } else { - glyph = nxeg_renderglyph(st, bm, ch); + glyph = nxeg_renderglyph(st, bm, ch); } } - return glyph; } @@ -350,42 +344,41 @@ nxeg_addchar(FAR struct nxeg_state_s *st, uint8_t ch) if (st->nchars < NXTK_MAXKBDCHARS) { - /* Yes, setup the bitmap */ + /* Yes, setup the bitmap */ - bm = &st->bm[st->nchars]; + bm = &st->bm[st->nchars]; - /* Find the matching glyph */ + /* Find the matching glyph */ - bm->glyph = nxeg_getglyph(st, ch); - if (!bm->glyph) - { - return NULL; - } + bm->glyph = nxeg_getglyph(st, ch); + if (!bm->glyph) + { + return NULL; + } - /* Set up the bounds for the bitmap */ + /* Set up the bounds for the bitmap */ - if (st->nchars <= 0) - { - /* The first character is one space from the left */ + if (st->nchars <= 0) + { + /* The first character is one space from the left */ - leftx = st->spwidth; - } - else - { - /* Otherwise, it is to the left of the preceding char */ + leftx = st->spwidth; + } + else + { + /* Otherwise, it is to the left of the preceding char */ - bmleft = &st->bm[st->nchars - 1]; - leftx = bmleft->bounds.pt2.x + 1; - } + bmleft = &st->bm[st->nchars-1]; + leftx = bmleft->bounds.pt2.x + 1; + } - bm->bounds.pt1.x = leftx; - bm->bounds.pt1.y = 2; - bm->bounds.pt2.x = leftx + bm->glyph->width - 1; - bm->bounds.pt2.y = 2 + bm->glyph->height - 1; + bm->bounds.pt1.x = leftx; + bm->bounds.pt1.y = 2; + bm->bounds.pt2.x = leftx + bm->glyph->width - 1; + bm->bounds.pt2.y = 2 + bm->glyph->height - 1; - st->nchars++; + st->nchars++; } - return bm; } @@ -429,12 +422,10 @@ void nxeg_kbdin(NXWINDOW hwnd, uint8_t nch, FAR const uint8_t *ch, ****************************************************************************/ #ifndef CONFIG_EXAMPLES_NX_RAWWINDOWS -void nxeg_tbkbdin(NXWINDOW hwnd, uint8_t nch, const uint8_t *ch, - FAR void *arg) +void nxeg_tbkbdin(NXWINDOW hwnd, uint8_t nch, const uint8_t *ch, FAR void *arg) { FAR struct nxeg_state_s *st = (FAR struct nxeg_state_s *)arg; - printf("nxeg_tbkbdin: ERROR -- toolbar should not received keyboard " - "input\n"); + printf("nxeg_tbkbdin: ERROR -- toolbar should not received keyboard input\n"); printf("nxeg_tbkbdin%d: hwnd=%p nch=%d\n", st->wnum, hwnd, nch); } #endif diff --git a/examples/nx/nx_main.c b/examples/nx/nx_main.c index 9bdeded9c..674d91496 100644 --- a/examples/nx/nx_main.c +++ b/examples/nx/nx_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/nx/nx_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -38,7 +36,7 @@ #include <sched.h> #include <pthread.h> #include <errno.h> -#include <nuttx/debug.h> +#include <debug.h> #include <nuttx/arch.h> #include <nuttx/board.h> @@ -54,7 +52,6 @@ ****************************************************************************/ /* Configuration ************************************************************/ - /* If not specified, assume that the hardware supports one video plane */ #ifndef CONFIG_EXAMPLES_NX_VPLANE @@ -99,10 +96,7 @@ nxgl_coord_t g_yres; bool b_haveresolution = false; bool g_connected = false; -sem_t g_semevent = -{ - 0 -}; +sem_t g_semevent = {0}; /* Colors used to fill window 1 & 2 */ @@ -185,16 +179,14 @@ static void nxeg_freestate(FAR struct nxeg_state_s *st) { for (i = 0; i < st->nglyphs; i++) { - if (st->glyph[i].bitmap) - { - free(st->glyph[i].bitmap); - } - - st->glyph[i].bitmap = NULL; + if (st->glyph[i].bitmap) + { + free(st->glyph[i].bitmap); + } + st->glyph[i].bitmap = NULL; } - st->nchars = 0; - } + } #endif } #endif @@ -205,7 +197,7 @@ static void nxeg_freestate(FAR struct nxeg_state_s *st) #ifdef CONFIG_EXAMPLES_NX_RAWWINDOWS static inline NXEGWINDOW nxeg_openwindow(FAR const struct nx_callback_s *cb, - FAR struct nxeg_state_s *state) + FAR struct nxeg_state_s *state) { NXEGWINDOW hwnd; @@ -215,10 +207,8 @@ static inline NXEGWINDOW nxeg_openwindow(FAR const struct nx_callback_s *cb, printf("nxeg_openwindow: nx_openwindow failed: %d\n", errno); g_exitcode = NXEXIT_NXOPENWINDOW; } - return hwnd; } - #else static inline NXEGWINDOW nxeg_openwindow(FAR const struct nx_callback_s *cb, FAR struct nxeg_state_s *state) @@ -231,10 +221,8 @@ static inline NXEGWINDOW nxeg_openwindow(FAR const struct nx_callback_s *cb, printf("nxeg_openwindow: nxtk_openwindow failed: %d\n", errno); g_exitcode = NXEXIT_NXOPENWINDOW; } - return hwnd; } - #endif /**************************************************************************** @@ -242,8 +230,7 @@ static inline NXEGWINDOW nxeg_openwindow(FAR const struct nx_callback_s *cb, ****************************************************************************/ #ifdef CONFIG_EXAMPLES_NX_RAWWINDOWS -static inline int nxeg_closewindow(NXEGWINDOW hwnd, - FAR struct nxeg_state_s *state) +static inline int nxeg_closewindow(NXEGWINDOW hwnd, FAR struct nxeg_state_s *state) { int ret = nx_closewindow(hwnd); if (ret < 0) @@ -251,13 +238,10 @@ static inline int nxeg_closewindow(NXEGWINDOW hwnd, printf("nxeg_closewindow: nx_closewindow failed: %d\n", errno); g_exitcode = NXEXIT_NXCLOSEWINDOW; } - return ret; } - #else -static inline int nxeg_closewindow(NXEGWINDOW hwnd, - FAR struct nxeg_state_s *state) +static inline int nxeg_closewindow(NXEGWINDOW hwnd, FAR struct nxeg_state_s *state) { int ret = nxtk_closewindow(hwnd); if (ret < 0) @@ -265,11 +249,9 @@ static inline int nxeg_closewindow(NXEGWINDOW hwnd, printf("nxeg_closewindow: nxtk_closewindow failed: %d\n", errno); g_exitcode = NXEXIT_NXCLOSEWINDOW; } - nxeg_freestate(state); return ret; } - #endif /**************************************************************************** @@ -277,8 +259,7 @@ static inline int nxeg_closewindow(NXEGWINDOW hwnd, ****************************************************************************/ #ifdef CONFIG_EXAMPLES_NX_RAWWINDOWS -static inline int nxeg_setsize(NXEGWINDOW hwnd, - FAR struct nxgl_size_s *size) +static inline int nxeg_setsize(NXEGWINDOW hwnd, FAR struct nxgl_size_s *size) { int ret = nx_setsize(hwnd, size); if (ret < 0) @@ -286,13 +267,10 @@ static inline int nxeg_setsize(NXEGWINDOW hwnd, printf("nxeg_setsize: nx_setsize failed: %d\n", errno); g_exitcode = NXEXIT_NXSETSIZE; } - return ret; } - #else -static inline int nxeg_setsize(NXEGWINDOW hwnd, - FAR struct nxgl_size_s *size) +static inline int nxeg_setsize(NXEGWINDOW hwnd, FAR struct nxgl_size_s *size) { int ret = nxtk_setsize(hwnd, size); if (ret < 0) @@ -300,10 +278,8 @@ static inline int nxeg_setsize(NXEGWINDOW hwnd, printf("nxeg_setsize: nxtk_setsize failed: %d\n", errno); g_exitcode = NXEXIT_NXSETSIZE; } - return ret; } - #endif /**************************************************************************** @@ -311,8 +287,7 @@ static inline int nxeg_setsize(NXEGWINDOW hwnd, ****************************************************************************/ #ifdef CONFIG_EXAMPLES_NX_RAWWINDOWS -static inline int nxeg_setposition(NXEGWINDOW hwnd, - FAR struct nxgl_point_s *pos) +static inline int nxeg_setposition(NXEGWINDOW hwnd, FAR struct nxgl_point_s *pos) { int ret = nx_setposition(hwnd, pos); if (ret < 0) @@ -320,13 +295,10 @@ static inline int nxeg_setposition(NXEGWINDOW hwnd, printf("nxeg_setposition: nx_setposition failed: %d\n", errno); g_exitcode = NXEXIT_NXSETPOSITION; } - return ret; } - #else -static inline int nxeg_setposition(NXEGWINDOW hwnd, - FAR struct nxgl_point_s *pos) +static inline int nxeg_setposition(NXEGWINDOW hwnd, FAR struct nxgl_point_s *pos) { int ret = nxtk_setposition(hwnd, pos); if (ret < 0) @@ -334,10 +306,8 @@ static inline int nxeg_setposition(NXEGWINDOW hwnd, printf("nxeg_setposition: nxtk_setposition failed: %d\n", errno); g_exitcode = NXEXIT_NXSETPOSITION; } - return ret; } - #endif /**************************************************************************** @@ -356,10 +326,8 @@ static inline int nxeq_opentoolbar(NXEGWINDOW hwnd, nxgl_coord_t height, printf("nxeq_opentoolbar: nxtk_opentoolbar failed: %d\n", errno); g_exitcode = NXEXIT_NXOPENTOOLBAR; } - return ret; } - #endif /**************************************************************************** @@ -375,10 +343,8 @@ static inline int nxeg_lower(NXEGWINDOW hwnd) printf("nxeg_lower: nx_lower failed: %d\n", errno); g_exitcode = NXEXIT_NXLOWER; } - return ret; } - #else static inline int nxeg_lower(NXEGWINDOW hwnd) { @@ -388,10 +354,8 @@ static inline int nxeg_lower(NXEGWINDOW hwnd) printf("nxeg_lower: nxtk_lower failed: %d\n", errno); g_exitcode = NXEXIT_NXLOWER; } - return ret; } - #endif /**************************************************************************** @@ -407,10 +371,8 @@ static inline int nxeg_raise(NXEGWINDOW hwnd) printf("nxeg_raise: nx_raise failed: %d\n", errno); g_exitcode = NXEXIT_NXRAISE; } - return ret; } - #else static inline int nxeg_raise(NXEGWINDOW hwnd) { @@ -420,10 +382,8 @@ static inline int nxeg_raise(NXEGWINDOW hwnd) printf("nxeg_raise: nxtk_raise failed: %d\n", errno); g_exitcode = NXEXIT_NXRAISE; } - return ret; } - #endif /**************************************************************************** @@ -454,7 +414,7 @@ static int nxeg_initialize(void) ret = sched_setparam(0, ¶m); if (ret < 0) { - printf("nxeg_initialize: sched_setparam failed: %d\n", ret); + printf("nxeg_initialize: sched_setparam failed: %d\n" , ret); g_exitcode = NXEXIT_SCHEDSETPARAM; return ERROR; } @@ -464,8 +424,7 @@ static int nxeg_initialize(void) ret = boardctl(BOARDIOC_NX_START, 0); if (ret < 0) { - printf("nxeg_initialize: Failed to start the NX server: %d\n", - errno); + printf("nxeg_initialize: Failed to start the NX server: %d\n", errno); g_exitcode = NXEXIT_TASKCREATE; return ERROR; } @@ -475,54 +434,54 @@ static int nxeg_initialize(void) g_hnx = nx_connect(); if (g_hnx) { - pthread_attr_t attr; + pthread_attr_t attr; #ifdef CONFIG_VNCSERVER /* Setup the VNC server to support keyboard/mouse inputs */ - struct boardioc_vncstart_s vnc = - { - 0, g_hnx - }; + struct boardioc_vncstart_s vnc = + { + 0, g_hnx + }; - ret = boardctl(BOARDIOC_VNC_START, (uintptr_t)&vnc); - if (ret < 0) - { - printf("boardctl(BOARDIOC_VNC_START) failed: %d\n", ret); - nx_disconnect(g_hnx); - g_exitcode = NXEXIT_FBINITIALIZE; - return ERROR; - } + ret = boardctl(BOARDIOC_VNC_START, (uintptr_t)&vnc); + if (ret < 0) + { + printf("boardctl(BOARDIOC_VNC_START) failed: %d\n", ret); + nx_disconnect(g_hnx); + g_exitcode = NXEXIT_FBINITIALIZE; + return ERROR; + } #endif - /* Start a separate thread to listen for server events. This is - * probably the least efficient way to do this, but it makes this - * example flow more smoothly. - */ + /* Start a separate thread to listen for server events. This is probably + * the least efficient way to do this, but it makes this example flow more + * smoothly. + */ - pthread_attr_init(&attr); - param.sched_priority = CONFIG_EXAMPLES_NX_LISTENERPRIO; - pthread_attr_setschedparam(&attr, ¶m); - pthread_attr_setstacksize(&attr, CONFIG_EXAMPLES_NX_STACKSIZE); + pthread_attr_init(&attr); + param.sched_priority = CONFIG_EXAMPLES_NX_LISTENERPRIO; + pthread_attr_setschedparam(&attr, ¶m); + pthread_attr_setstacksize(&attr, CONFIG_EXAMPLES_NX_STACKSIZE); - ret = pthread_create(&thread, &attr, nx_listenerthread, NULL); - if (ret != 0) - { - printf("nxeg_initialize: pthread_create failed: %d\n", ret); - g_exitcode = NXEXIT_PTHREADCREATE; - return ERROR; - } + ret = pthread_create(&thread, &attr, nx_listenerthread, NULL); + if (ret != 0) + { + printf("nxeg_initialize: pthread_create failed: %d\n", ret); + g_exitcode = NXEXIT_PTHREADCREATE; + return ERROR; + } - /* Don't return until we are connected to the server */ + /* Don't return until we are connected to the server */ - while (!g_connected) - { - /* Wait for the listener thread to wake us up when we really - * are connected. - */ + while (!g_connected) + { + /* Wait for the listener thread to wake us up when we really + * are connected. + */ - sem_wait(&g_semevent); - } + sem_wait(&g_semevent); + } } else { @@ -601,7 +560,6 @@ int main(int argc, FAR char *argv[]) { sem_wait(&g_semevent); } - printf("nx_main: Screen resolution (%d,%d)\n", g_xres, g_yres); /* Set the size of the window 1 */ @@ -616,8 +574,9 @@ int main(int argc, FAR char *argv[]) goto errout_with_hwnd1; } - /* Sleep a bit. This lets us see the result of the above operations and, - * in the multi-user case, gives the server a chance to actually do them. + /* Sleep a bit -- both so that we can see the result of the above operations + * but also, in the multi-user case, so that the server can get a chance to + * actually do them! */ printf("nx_main: Sleeping\n\n"); @@ -644,8 +603,7 @@ int main(int argc, FAR char *argv[]) #ifndef CONFIG_EXAMPLES_NX_RAWWINDOWS printf("nx_main: Add toolbar to window #1\n"); - ret = nxeq_opentoolbar(hwnd1, CONFIG_EXAMPLES_NX_TOOLBAR_HEIGHT, - &g_tbcb, &g_wstate[0]); + ret = nxeq_opentoolbar(hwnd1, CONFIG_EXAMPLES_NX_TOOLBAR_HEIGHT, &g_tbcb, &g_wstate[0]); if (ret < 0) { goto errout_with_hwnd1; @@ -673,7 +631,7 @@ int main(int argc, FAR char *argv[]) printf("nx_main: Sleeping\n\n"); sleep(1); - /* Set the size of window 2 equal to the size of window 1 */ + /* Set the size of the window 2 == size of window 1*/ printf("nx_main: Set hwnd2 size to (%d,%d)\n", size.w, size.h); ret = nxeg_setsize(hwnd2, &size); @@ -706,8 +664,7 @@ int main(int argc, FAR char *argv[]) #ifndef CONFIG_EXAMPLES_NX_RAWWINDOWS printf("nx_main: Add toolbar to window #2\n"); - ret = nxeq_opentoolbar(hwnd2, CONFIG_EXAMPLES_NX_TOOLBAR_HEIGHT, - &g_tbcb, &g_wstate[1]); + ret = nxeq_opentoolbar(hwnd2, CONFIG_EXAMPLES_NX_TOOLBAR_HEIGHT, &g_tbcb, &g_wstate[1]); if (ret < 0) { goto errout_with_hwnd2; @@ -811,7 +768,6 @@ errout_with_hwnd1: nxeg_closewindow(hwnd1, &g_wstate[0]); errout_with_nx: - /* Disconnect from the server */ printf("nx_main: Disconnect from the server\n"); diff --git a/examples/nxdemo/CMakeLists.txt b/examples/nxdemo/CMakeLists.txt deleted file mode 100644 index b43078f14..000000000 --- a/examples/nxdemo/CMakeLists.txt +++ /dev/null @@ -1,34 +0,0 @@ -# ############################################################################## -# apps/examples/nxdemo/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_NXDEMO) - nuttx_add_application( - NAME - nxdemo - STACKSIZE - ${CONFIG_DEFAULT_TASK_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_NXDEMO} - SRCS - nxdemo_main.c) - target_sources(apps PRIVATE nxdemo_bkgd.c nxdemo_listener.c) -endif() diff --git a/examples/nxdemo/Make.defs b/examples/nxdemo/Make.defs index 7a75f29af..6243398f9 100644 --- a/examples/nxdemo/Make.defs +++ b/examples/nxdemo/Make.defs @@ -1,7 +1,5 @@ ############################################################################ -# apps/examples/nxdemo/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 +# apps/examples/nxhello/Make.defs # # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with diff --git a/examples/nxdemo/Makefile b/examples/nxdemo/Makefile index 67faa61aa..475e58c99 100644 --- a/examples/nxdemo/Makefile +++ b/examples/nxdemo/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/nxdemo/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/nxdemo/images.h b/examples/nxdemo/images.h index b0c411a62..a3bed7888 100644 --- a/examples/nxdemo/images.h +++ b/examples/nxdemo/images.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/nxdemo/images.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/nxdemo/nxdemo.h b/examples/nxdemo/nxdemo.h index ebace04ae..60781a85e 100644 --- a/examples/nxdemo/nxdemo.h +++ b/examples/nxdemo/nxdemo.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/nxdemo/nxdemo.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -63,7 +61,7 @@ # define CONFIG_EXAMPLES_NXDEMO_BGCOLOR 0x00 # else # define CONFIG_EXAMPLES_NXDEMO_BGCOLOR ' ' -# endif +# endif #endif #ifndef CONFIG_EXAMPLES_NXDEMO_DRAWCOLOR @@ -101,6 +99,9 @@ #ifndef CONFIG_EXAMPLES_NXDEMO_SERVERPRIO # define CONFIG_EXAMPLES_NXDEMO_SERVERPRIO 120 #endif +#ifndef CONFIG_EXAMPLES_NXDEMO_NOTIFYSIGNO +# define CONFIG_EXAMPLES_NXDEMO_NOTIFYSIGNO 4 +#endif /* Image Information ********************************************************/ diff --git a/examples/nxdemo/nxdemo_bkgd.c b/examples/nxdemo/nxdemo_bkgd.c index ecd82b238..6eef6eeb8 100644 --- a/examples/nxdemo/nxdemo_bkgd.c +++ b/examples/nxdemo/nxdemo_bkgd.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/nxdemo/nxdemo_bkgd.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -32,10 +30,8 @@ #include <stdlib.h> #include <string.h> #include <semaphore.h> -#include <sys/param.h> #include <errno.h> -#include <nuttx/debug.h> -#include <unistd.h> +#include <debug.h> #include <nuttx/nx/nx.h> #include <nuttx/nx/nxglib.h> @@ -70,6 +66,14 @@ # error "Unsupported CONFIG_EXAMPLES_NXDEMO_BPP" #endif +#ifndef MIN +# define MIN(a, b) (a < b ? a : b) +#endif + +#ifndef MAX +# define MAX(a, b) (a > b ? a : b) +#endif + /**************************************************************************** * Private Function Prototypes ****************************************************************************/ @@ -473,7 +477,7 @@ static void nxdemo_demo_4(NXWINDOW hwnd) origin.x = 0; origin.y = 0; - src[0] = g_battery; + src[0] = (FAR const void *)g_battery; ret = nx_bitmap((NXWINDOW)hwnd, &rect, diff --git a/examples/nxdemo/nxdemo_listener.c b/examples/nxdemo/nxdemo_listener.c index 834584913..a5042a077 100644 --- a/examples/nxdemo/nxdemo_listener.c +++ b/examples/nxdemo/nxdemo_listener.c @@ -1,7 +1,5 @@ /**************************************************************************** - * apps/examples/nxdemo/nxdemo_listener.c - * - * SPDX-License-Identifier: Apache-2.0 + * apps/examples/nxterm/nxdemo_listener.c * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -48,7 +46,7 @@ FAR void *nxdemo_listener(FAR void *arg) /* Process events forever */ - for (; ; ) + for (;;) { /* Handle the next event. If we were configured blocking, then * we will stay right here until the next event is received. Since diff --git a/examples/nxdemo/nxdemo_main.c b/examples/nxdemo/nxdemo_main.c index e6875b9cd..e09e0182f 100644 --- a/examples/nxdemo/nxdemo_main.c +++ b/examples/nxdemo/nxdemo_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/nxdemo/nxdemo_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -38,7 +36,7 @@ #include <sched.h> #include <pthread.h> #include <errno.h> -#include <nuttx/debug.h> +#include <debug.h> #include <nuttx/arch.h> #include <nuttx/board.h> diff --git a/examples/nxflat/CMakeLists.txt b/examples/nxflat/CMakeLists.txt deleted file mode 100644 index 35107f1b9..000000000 --- a/examples/nxflat/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -# ############################################################################## -# apps/examples/nxflat/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_NXFLAT) - nuttx_add_application(NAME nxflat) -endif() diff --git a/examples/nxflat/Make.defs b/examples/nxflat/Make.defs index 45e673908..765c79574 100644 --- a/examples/nxflat/Make.defs +++ b/examples/nxflat/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/nxflat/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/nxflat/Makefile b/examples/nxflat/Makefile index a8aa81842..934c3f5c6 100644 --- a/examples/nxflat/Makefile +++ b/examples/nxflat/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/nxflat/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -27,8 +25,6 @@ include $(APPDIR)/Make.defs CSRCS = romfs.c CSRCS += dirlist.c CSRCS += symtab.c -tests$(DELIM)symtab.c_CFLAGS = -fno-builtin -tests$(DELIM)symtab.c_CELFFLAGS = -fno-builtin MAINSRC = nxflat_main.c PROGNAME = nxflat diff --git a/examples/nxflat/nxflat_main.c b/examples/nxflat/nxflat_main.c index c7ea6cf19..96fe4c6f6 100644 --- a/examples/nxflat/nxflat_main.c +++ b/examples/nxflat/nxflat_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/nxflat/nxflat_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -34,7 +32,7 @@ #include <unistd.h> #include <string.h> #include <pthread.h> -#include <nuttx/debug.h> +#include <debug.h> #include <errno.h> #include <nuttx/symtab.h> @@ -200,7 +198,7 @@ int main(int argc, FAR char *argv[]) #ifdef CONFIG_LIBC_ENVPATH filename = dirlist[i]; #else - snprintf(fullpath, sizeof(fullpath), "%s/%s", MOUNTPT, dirlist[i]); + snprintf(fullpath, 128, "%s/%s", MOUNTPT, dirlist[i]); filename = fullpath; #endif @@ -215,7 +213,7 @@ int main(int argc, FAR char *argv[]) args[0] = (FAR char *)dirlist[i]; args[1] = NULL; - ret = exec(filename, args, NULL, g_nxflat_exports, g_nxflat_nexports); + ret = exec(filename, args, g_nxflat_exports, g_nxflat_nexports); if (ret < 0) { errmsg("ERROR: exec(%s) failed: %d\n", dirlist[i], errno); diff --git a/examples/nxflat/tests/Makefile b/examples/nxflat/tests/Makefile index 0f83f5137..b14d2f74b 100644 --- a/examples/nxflat/tests/Makefile +++ b/examples/nxflat/tests/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/nxflat/tests/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/nxflat/tests/errno/Makefile b/examples/nxflat/tests/errno/Makefile index 43ee63d4e..97d707a98 100644 --- a/examples/nxflat/tests/errno/Makefile +++ b/examples/nxflat/tests/errno/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/nxflat/tests/errno/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/nxflat/tests/errno/errno.c b/examples/nxflat/tests/errno/errno.c index 1c3e43057..bb5acd3c4 100644 --- a/examples/nxflat/tests/errno/errno.c +++ b/examples/nxflat/tests/errno/errno.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/nxflat/tests/errno/errno.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/nxflat/tests/hello++/Makefile b/examples/nxflat/tests/hello++/Makefile index 3202dd1b9..f34dc3387 100644 --- a/examples/nxflat/tests/hello++/Makefile +++ b/examples/nxflat/tests/hello++/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/nxflat/tests/hello++/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/nxflat/tests/hello++/hello++1.cxx b/examples/nxflat/tests/hello++/hello++1.cxx index d0a229f98..013861a71 100644 --- a/examples/nxflat/tests/hello++/hello++1.cxx +++ b/examples/nxflat/tests/hello++/hello++1.cxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/examples/nxflat/tests/hello++/hello++1.cxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The diff --git a/examples/nxflat/tests/hello++/hello++2.cxx b/examples/nxflat/tests/hello++/hello++2.cxx index d5ee74eda..87fc7a2d7 100644 --- a/examples/nxflat/tests/hello++/hello++2.cxx +++ b/examples/nxflat/tests/hello++/hello++2.cxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/examples/nxflat/tests/hello++/hello++2.cxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -46,7 +44,7 @@ public: CThingSayer(void) { printf("CThingSayer::CThingSayer: I am!\n"); - szWhatToSay = NULL; + szWhatToSay = (const char*)NULL; } ~CThingSayer(void) @@ -57,7 +55,7 @@ public: printf("CThingSayer::~CThingSayer: I will never say '%s' again\n", szWhatToSay); } - szWhatToSay = NULL; + szWhatToSay = (const char*)NULL; } void Initialize(const char *czSayThis) diff --git a/examples/nxflat/tests/hello++/hello++3.cxx b/examples/nxflat/tests/hello++/hello++3.cxx index c16686e68..f4d57054d 100644 --- a/examples/nxflat/tests/hello++/hello++3.cxx +++ b/examples/nxflat/tests/hello++/hello++3.cxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/examples/nxflat/tests/hello++/hello++3.cxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -61,7 +59,7 @@ static CThingSayer MyThingSayer; CThingSayer::CThingSayer(void) { printf("CThingSayer::CThingSayer: I am!\n"); - szWhatToSay = NULL; + szWhatToSay = (const char*)NULL; } CThingSayer::~CThingSayer(void) @@ -72,7 +70,7 @@ CThingSayer::~CThingSayer(void) printf("CThingSayer::~CThingSayer: I will never say '%s' again\n", szWhatToSay); } - szWhatToSay = NULL; + szWhatToSay = (const char*)NULL; } void CThingSayer::Initialize(const char *czSayThis) diff --git a/examples/nxflat/tests/hello++/hello++4.cxx b/examples/nxflat/tests/hello++/hello++4.cxx index 98a1eb746..79b5ebf90 100644 --- a/examples/nxflat/tests/hello++/hello++4.cxx +++ b/examples/nxflat/tests/hello++/hello++4.cxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/examples/nxflat/tests/hello++/hello++4.cxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -37,7 +35,7 @@ #include <iostream> #ifndef NULL -# define NULL ((void*)0L) +# define NULL ((void*)0L) #endif ///////////////////////////////////////////////////////////////////////////// @@ -78,7 +76,7 @@ static CThingSayer MyThingSayer; CThingSayer::CThingSayer(void) { cout << "CThingSayer::CThingSayer: I am!" << endl; - szWhatToSay = NULL; + szWhatToSay = (const char*)NULL; } CThingSayer::~CThingSayer(void) @@ -89,7 +87,7 @@ CThingSayer::~CThingSayer(void) cout << "CThingSayer::~CThingSayer: I will never say '" << szWhatToSay << "' again" << endl; } - szWhatToSay = NULL; + szWhatToSay = (const char*)NULL; } void CThingSayer::Initialize(const char *czSayThis) diff --git a/examples/nxflat/tests/hello/Makefile b/examples/nxflat/tests/hello/Makefile index c17605095..fb7036409 100644 --- a/examples/nxflat/tests/hello/Makefile +++ b/examples/nxflat/tests/hello/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/nxflat/tests/hello/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/nxflat/tests/hello/hello.c b/examples/nxflat/tests/hello/hello.c index 90017f1b2..f55565b33 100644 --- a/examples/nxflat/tests/hello/hello.c +++ b/examples/nxflat/tests/hello/hello.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/nxflat/tests/hello/hello.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/nxflat/tests/longjmp/Makefile b/examples/nxflat/tests/longjmp/Makefile index d1dfdd6a4..1cb724b18 100644 --- a/examples/nxflat/tests/longjmp/Makefile +++ b/examples/nxflat/tests/longjmp/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/nxflat/tests/longjmp/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/nxflat/tests/longjmp/longjmp.c b/examples/nxflat/tests/longjmp/longjmp.c index ea7ae7bad..c27518f17 100644 --- a/examples/nxflat/tests/longjmp/longjmp.c +++ b/examples/nxflat/tests/longjmp/longjmp.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/nxflat/tests/longjmp/longjmp.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/nxflat/tests/mkdirlist.sh b/examples/nxflat/tests/mkdirlist.sh index 786a7b4cd..96f928c7a 100755 --- a/examples/nxflat/tests/mkdirlist.sh +++ b/examples/nxflat/tests/mkdirlist.sh @@ -1,25 +1,4 @@ #!/usr/bin/env bash -############################################################################ -# apps/examples/nxflat/tests/mkdirlist.sh -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ usage="Usage: %0 <romfs-dir-path>" diff --git a/examples/nxflat/tests/mutex/Makefile b/examples/nxflat/tests/mutex/Makefile index afdfc4966..6ed1f3823 100644 --- a/examples/nxflat/tests/mutex/Makefile +++ b/examples/nxflat/tests/mutex/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/nxflat/tests/mutex/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/nxflat/tests/mutex/mutex.c b/examples/nxflat/tests/mutex/mutex.c index c8bede26d..9ca14fc3b 100644 --- a/examples/nxflat/tests/mutex/mutex.c +++ b/examples/nxflat/tests/mutex/mutex.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/nxflat/tests/mutex/mutex.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -105,7 +103,7 @@ int main(int argc, char **argv) printf("Starting thread 1\n"); bendoftest = false; - if ((pthread_create(&thread1, NULL, (void*)thread_func, (void *)1)) != 0) + if ((pthread_create(&thread1, NULL, (void*)thread_func, (void*)1)) != 0) { fprintf(stderr, "Error in thread#1 creation\n"); } diff --git a/examples/nxflat/tests/pthread/Makefile b/examples/nxflat/tests/pthread/Makefile index 34eda9330..219213d4d 100644 --- a/examples/nxflat/tests/pthread/Makefile +++ b/examples/nxflat/tests/pthread/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/nxflat/tests/pthread/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/nxflat/tests/pthread/pthread.c b/examples/nxflat/tests/pthread/pthread.c index ca2f6268d..200de0a5a 100644 --- a/examples/nxflat/tests/pthread/pthread.c +++ b/examples/nxflat/tests/pthread/pthread.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/nxflat/tests/pthread/pthread.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/nxflat/tests/signal/Makefile b/examples/nxflat/tests/signal/Makefile index 0fba33864..cb20c0118 100644 --- a/examples/nxflat/tests/signal/Makefile +++ b/examples/nxflat/tests/signal/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/nxflat/tests/signal/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/nxflat/tests/signal/signal.c b/examples/nxflat/tests/signal/signal.c index 63ee50767..7cf4732d3 100644 --- a/examples/nxflat/tests/signal/signal.c +++ b/examples/nxflat/tests/signal/signal.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/nxflat/tests/signal/signal.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -66,8 +64,8 @@ static int sigusr2_rcvd = 0; * Name: siguser_action ****************************************************************************/ -/* NOTE: it is necessary for functions that are referred to by function - * pointers to be declared with global scope (at least for ARM). Otherwise, +/* NOTE: it is necessary for functions that are referred to by function pointers + * pointer to be declared with global scope (at least for ARM). Otherwise, * a relocation type that is not supported by ELF is generated by GCC. */ @@ -225,7 +223,7 @@ int main(int argc, char **argv) /* Verify that the handler that was removed was siguser_action */ - if ((void *)act.sa_handler != (void *)siguser_action) + if ((void*)act.sa_handler != (void*)siguser_action) { fprintf(stderr, "Old SIGUSR2 signal handler (%p) is not siguser_action (%p)\n", diff --git a/examples/nxflat/tests/struct/Makefile b/examples/nxflat/tests/struct/Makefile index 463b2c260..e765aadff 100644 --- a/examples/nxflat/tests/struct/Makefile +++ b/examples/nxflat/tests/struct/Makefile @@ -1,7 +1,5 @@ ############################################################################ -# apps/examples/nxflat/tests/struct/Makefile -# -# SPDX-License-Identifier: Apache-2.0 +# apps/examples/nxflat/tests/hello/Makefile # # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with diff --git a/examples/nxflat/tests/struct/struct.h b/examples/nxflat/tests/struct/struct.h index 199efd8ca..1afd0c5a2 100644 --- a/examples/nxflat/tests/struct/struct.h +++ b/examples/nxflat/tests/struct/struct.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/nxflat/tests/struct/struct.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/nxflat/tests/struct/struct_dummy.c b/examples/nxflat/tests/struct/struct_dummy.c index 5630b22ad..c1444a4ae 100644 --- a/examples/nxflat/tests/struct/struct_dummy.c +++ b/examples/nxflat/tests/struct/struct_dummy.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/nxflat/tests/struct/struct_dummy.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/nxflat/tests/struct/struct_main.c b/examples/nxflat/tests/struct/struct_main.c index b3721f87a..f8abc2a73 100644 --- a/examples/nxflat/tests/struct/struct_main.c +++ b/examples/nxflat/tests/struct/struct_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/nxflat/tests/struct/struct_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -35,7 +33,7 @@ const struct struct_dummy_s dummy_struct = { - DUMMY_SCALAR_VALUE3 + DUMMY_SCALAR_VALUE3 }; int dummy_scalar = DUMMY_SCALAR_VALUE2; diff --git a/examples/nxflat/tests/task/Makefile b/examples/nxflat/tests/task/Makefile index cb3473d6b..712f5b1fd 100644 --- a/examples/nxflat/tests/task/Makefile +++ b/examples/nxflat/tests/task/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/nxflat/tests/task/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/nxflat/tests/task/task.c b/examples/nxflat/tests/task/task.c index 8a208d5aa..f543dc19b 100644 --- a/examples/nxflat/tests/task/task.c +++ b/examples/nxflat/tests/task/task.c @@ -1,7 +1,5 @@ /**************************************************************************** - * apps/examples/nxflat/tests/task/task.c - * - * SPDX-License-Identifier: Apache-2.0 + * apps/examples/nxflat/tests/task/parent.c * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -49,10 +47,9 @@ static char no_name[] = "<noname>"; * Privite Functions ****************************************************************************/ -/* NOTE: it is necessary for functions that are referred to by function - * pointers pointer to be declared with global scope (at least for ARM). - * Otherwise, a relocation type that is not supported by - * NXFLAT is generated by GCC. +/* NOTE: it is necessary for functions that are referred to by function pointers + * pointer to be declared with global scope (at least for ARM). Otherwise, + * a relocation type that is not supported by NXFLAT is generated by GCC. */ int child_task(int argc, char **argv) @@ -116,8 +113,7 @@ int main(int argc, char **argv) child_argv[0] = child_arg; child_argv[1] = 0; - child_pid = task_create(child_name, 50, 512, - child_task, (FAR char * const *)child_argv); + child_pid = task_create(child_name, 50, 512, child_task, (FAR char * const *)child_argv); if (child_pid < 0) { printf("Parent: task_create failed: %d\n", errno); diff --git a/examples/nxflatxip/.gitignore b/examples/nxflatxip/.gitignore deleted file mode 100644 index c04a5d03c..000000000 --- a/examples/nxflatxip/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/symtab.c -/xipmod_bin.h diff --git a/examples/nxflatxip/CMakeLists.txt b/examples/nxflatxip/CMakeLists.txt deleted file mode 100644 index dc5dd064e..000000000 --- a/examples/nxflatxip/CMakeLists.txt +++ /dev/null @@ -1,29 +0,0 @@ -# ############################################################################## -# apps/examples/nxflatxip/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -# The module and the symbol table it needs are built by module/Makefile, which -# the CMake build does not drive. As with apps/examples/nxflat, use the make -# build for this example. - -if(CONFIG_EXAMPLES_NXFLATXIP) - nuttx_add_application(NAME nxflatxip SRCS nxflatxip_main.c symtab.c) -endif() diff --git a/examples/nxflatxip/Kconfig b/examples/nxflatxip/Kconfig deleted file mode 100644 index 8a798d503..000000000 --- a/examples/nxflatxip/Kconfig +++ /dev/null @@ -1,38 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config EXAMPLES_NXFLATXIP - tristate "NXFLAT execute-in-place from xipfs demo" - depends on FS_XIPFS && NXFLAT && LIBC_EXECFUNCS - default n - ---help--- - Write an NXFLAT module into xipfs at run time, the way a download - would, then run two instances of it concurrently. The module's - text is executed directly out of flash and shared between the - instances, while each instance gets its own data. - - Subcommands: - - bench XIP read throughput before and after a flash write - defrag fragment the volume, compact it, with a block map - - Building the module needs the mknxflat and ldnxflat host tools - from the NuttX toolchain, and the board's Make.defs must name - them, exactly as apps/examples/nxflat requires. - -if EXAMPLES_NXFLATXIP - -config EXAMPLES_NXFLATXIP_MOUNTPT - string "xipfs mountpoint" - default "/mnt/xipfs" - -config EXAMPLES_NXFLATXIP_MTD - string "MTD device backing the volume" - default "/dev/rpflash" - ---help--- - Used only by the defrag subcommand, which remounts the volume to - show that what it did survives. - -endif # EXAMPLES_NXFLATXIP diff --git a/examples/nxflatxip/Make.defs b/examples/nxflatxip/Make.defs deleted file mode 100644 index 2290cf00c..000000000 --- a/examples/nxflatxip/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/examples/nxflatxip/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_EXAMPLES_NXFLATXIP),) -CONFIGURED_APPS += $(APPDIR)/examples/nxflatxip -endif diff --git a/examples/nxflatxip/Makefile b/examples/nxflatxip/Makefile deleted file mode 100644 index e74981c17..000000000 --- a/examples/nxflatxip/Makefile +++ /dev/null @@ -1,54 +0,0 @@ -############################################################################ -# apps/examples/nxflatxip/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -# NXFLAT execute-in-place from xipfs - -CSRCS = symtab.c -MAINSRC = nxflatxip_main.c - -# The generated symbol table declares every imported symbol as void *, which -# the compiler objects to for the ones it knows as builtins. - -symtab.c_CFLAGS = -fno-builtin - -PROGNAME = nxflatxip -PRIORITY = SCHED_PRIORITY_DEFAULT -STACKSIZE = $(CONFIG_DEFAULT_TASK_STACKSIZE) -MODULE = $(CONFIG_EXAMPLES_NXFLATXIP) - -# Both are generated by the module build below - -symtab.c: build -xipmod_bin.h: build - -$(MAINSRC): xipmod_bin.h - -.PHONY: build -build: - +$(Q) $(MAKE) -C module TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)" CROSSDEV=$(CROSSDEV) - -clean:: - +$(Q) $(MAKE) -C module TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)" CROSSDEV=$(CROSSDEV) clean - -include $(APPDIR)/Application.mk diff --git a/examples/nxflatxip/module/.gitignore b/examples/nxflatxip/module/.gitignore deleted file mode 100644 index 111804b12..000000000 --- a/examples/nxflatxip/module/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -/xipmod -/xipmod-thunk.S -/*.r1 -/*.r2 diff --git a/examples/nxflatxip/module/Makefile b/examples/nxflatxip/module/Makefile deleted file mode 100644 index 89ad64866..000000000 --- a/examples/nxflatxip/module/Makefile +++ /dev/null @@ -1,94 +0,0 @@ -############################################################################ -# apps/examples/nxflatxip/module/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -# The NXFLAT module the demo downloads into xipfs. Built exactly the way -# apps/examples/nxflat builds its test programs, so it needs the same two -# host tools from the NuttX toolchain: mknxflat and ldnxflat. - -BIN = xipmod - -R1SRCS = $(BIN).c -R1OBJS = $(R1SRCS:.c=.o) - -R2SRC = $(BIN)-thunk.S -R2OBJ = $(R2SRC:.S=.o) - -EXAMPLDIR = $(APPDIR)$(DELIM)examples$(DELIM)nxflatxip -BINHDR = $(EXAMPLDIR)$(DELIM)$(BIN)_bin.h -SYMTAB = $(EXAMPLDIR)$(DELIM)symtab.c - -all: $(BINHDR) $(SYMTAB) -.PHONY: all clean - -$(R1OBJS): %.o: %.c - @echo "CC: $<" - $(Q) $(CC) -c $(CPICFLAGS) $< -o $@ - -$(R2OBJ): %.o: %.S - @echo "AS: $<" - $(Q) $(CC) -c $(CPICFLAGS) $< -o $@ - -$(BIN).r1: $(R1OBJS) - @echo "LD: $<" - $(Q) $(LD) $(NXFLATLDFLAGS1) -o $@ $^ - -$(R2SRC): $(BIN).r1 - @echo "MK: $<" - $(Q) $(MKNXFLAT) -o $@ $^ - -$(BIN).r2: $(R2OBJ) - @echo "LD: $<" - $(Q) $(LD) $(NXFLATLDFLAGS2) -o $@ $(R1OBJS) $(R2OBJ) - -$(BIN): $(BIN).r2 - @echo "LD: $<" - $(Q) $(LDNXFLAT) $(LDNXFLATFLAGS) -o $@ $^ - -# Embed the module in the demo. It is not the demo's own text, it is a -# payload the demo writes into the filesystem, so a plain byte array is what -# is wanted. - -$(BINHDR): $(BIN) - @echo "GEN: $@" - $(Q) xxd -i -n g_xipmod $(BIN) | \ - sed -e "s/^unsigned char/static const unsigned char/" \ - -e "s/^unsigned int/static const unsigned int/" >$@.tmp - $(Q) $(call TESTANDREPLACEFILE, $@.tmp, $@) - -# The symbols the module imports from the firmware. mknxflat left the list -# in the thunk file it generated, so that is what is scanned. - -$(SYMTAB): $(R2SRC) - @echo "GEN: $@" - $(Q) $(APPDIR)$(DELIM)tools$(DELIM)mksymtab.sh . g_nxflat >$@.tmp - $(Q) $(call TESTANDREPLACEFILE, $@.tmp, $@) - -clean: - $(call DELFILE, $(BIN)) - $(call DELFILE, $(R2SRC)) - $(call DELFILE, *.r1) - $(call DELFILE, *.r2) - $(call DELFILE, $(BINHDR)) - $(call DELFILE, $(SYMTAB)) - $(call CLEAN) diff --git a/examples/nxflatxip/module/xipmod.c b/examples/nxflatxip/module/xipmod.c deleted file mode 100644 index 1c721acbd..000000000 --- a/examples/nxflatxip/module/xipmod.c +++ /dev/null @@ -1,116 +0,0 @@ -/**************************************************************************** - * apps/examples/nxflatxip/module/xipmod.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * The module the demo downloads into xipfs and runs. - * - * Given a seed on the command line it fills an array derived from it, - * sleeps long enough for a second instance to do the same with a different - * seed, checks its own values are untouched, and hands the result to the - * firmware. It reports the address of its own text, which is the point of - * the exercise: that address is inside the memory mapped flash window, it - * is the same in both instances, and the module is executing from it rather - * than from a copy in RAM. - * - * Two things this module deliberately does not have, both because of what - * the ldnxflat in circulation does with them: - * - * - No global or static variables. Those are reached through the GOT, - * and the GOT entries come out pointing into the import table rather - * than into .bss, so the module overwrites the addresses of the - * functions it imports and jumps into nothing on its next call out. - * - No string constants. With this linker script .rodata lives in the - * text segment and is reached PC-relatively, and the addend already - * in the instruction is dropped when that relocation is resolved, so - * the pointer lands somewhere in the middle of the code. - * - * Hence the reporting callback: the module passes numbers to the firmware - * and the firmware, which has a working printf and a format string, does - * the printing. It also exercises the other direction of the interface -- - * firmware code entered with the module's data base still in r10. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <stdlib.h> -#include <unistd.h> - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define NVALUES 64 - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/* Exported by the demo in the firmware and imported by this module */ - -void xipmod_report(int seed, const void *text, const void *stack, - long sum, int errors); - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -int main(int argc, char *argv[]) -{ - int values[NVALUES]; - int errors = 0; - int seed = 1; - long sum = 0; - int i; - - if (argc > 1) - { - seed = atoi(argv[1]); - } - - for (i = 0; i < NVALUES; i++) - { - values[i] = seed * (i + 1); - } - - /* Long enough that the other instance has certainly filled its own copy - * by the time this one checks. - */ - - usleep(200000); - - for (i = 0; i < NVALUES; i++) - { - if (values[i] != seed * (i + 1)) - { - errors++; - } - - sum += values[i]; - } - - xipmod_report(seed, (const void *)main, (const void *)values, sum, errors); - - return errors == 0 ? EXIT_SUCCESS : EXIT_FAILURE; -} diff --git a/examples/nxflatxip/nxflatxip_main.c b/examples/nxflatxip/nxflatxip_main.c deleted file mode 100644 index 946e2b649..000000000 --- a/examples/nxflatxip/nxflatxip_main.c +++ /dev/null @@ -1,895 +0,0 @@ -/**************************************************************************** - * apps/examples/nxflatxip/nxflatxip_main.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * End to end demonstration of what a writable execute-in-place file system - * is for: - * - * 1. write an NXFLAT module into xipfs at run time, the way a download - * would, - * 2. confirm the file system can hand out a direct flash pointer for it, - * 3. run two instances of it concurrently, - * 4. confirm both ran correctly, that their data did not interfere, and - * that the shared text was pinned in place while they ran. - * - * The same module in a ROMFS image would give the same execute-in-place - * behaviour; what it could not do is arrive after the firmware was built. - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <sys/ioctl.h> -#include <sys/mount.h> -#include <sys/stat.h> -#include <sys/wait.h> - -#include <dirent.h> -#include <errno.h> -#include <fcntl.h> -#include <inttypes.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <syslog.h> -#include <time.h> -#include <unistd.h> - -#include <nuttx/binfmt/binfmt.h> -#include <nuttx/fs/ioctl.h> -#include <nuttx/fs/xipfs.h> -#include <nuttx/symtab.h> - -#include "xipmod_bin.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define MOUNTPT CONFIG_EXAMPLES_NXFLATXIP_MOUNTPT -#define MTDDEV CONFIG_EXAMPLES_NXFLATXIP_MTD -#define MODPATH MOUNTPT "/xipmod" -#define BENCH_PATH MOUNTPT "/big" -#define BENCH_SIZE (256 * 1024) -#define DF_FILES 55 -#define DF_MAPCOLS 50 - -/**************************************************************************** - * External Symbols - ****************************************************************************/ - -/* Generated by module/Makefile from the import list mknxflat left in the - * module's thunk file. The NXFLAT loader has no other way to resolve the - * functions the module calls. - */ - -extern const struct symtab_s g_nxflat_exports[]; -extern const int g_nxflat_nexports; - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static char g_map[512]; - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: xipmod_report - * - * Description: - * Called by the module, running in place from flash, to report what it - * found. It passes numbers rather than formatting its own output; see - * module/xipmod.c for why. - * - * This is also the direction of the interface that needs r10 to survive: - * the module reaches its own data through that register, and this - * function runs with the module's data base still in it. That is what - * the --fixed-r10 the ARM toolchain adds under CONFIG_PIC is for. - * - ****************************************************************************/ - -void xipmod_report(int seed, FAR const void *text, FAR const void *stack, - long sum, int errors) -{ - syslog(LOG_INFO, " instance seed %d: text %p, stack %p, sum %ld -- %s\n", - seed, text, stack, sum, - errors == 0 ? "data private and intact" : "DATA CORRUPTED"); -} - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: stage_module - * - * Description: - * Write the module into the file system exactly as a download would: - * declare the size up front so xipfs reserves an exactly sized - * contiguous extent, then write it once. - * - ****************************************************************************/ - -static int stage_module(void) -{ - ssize_t nwritten; - int fd; - - unlink(MODPATH); - - fd = open(MODPATH, O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0755); - if (fd < 0) - { - syslog(LOG_INFO, "ERROR: open %s failed: %d\n", MODPATH, errno); - return -errno; - } - - if (ftruncate(fd, g_xipmod_len) < 0) - { - syslog(LOG_INFO, "ERROR: ftruncate failed: %d\n", errno); - close(fd); - return -errno; - } - - nwritten = write(fd, g_xipmod, g_xipmod_len); - close(fd); - - if (nwritten != (ssize_t)g_xipmod_len) - { - syslog(LOG_INFO, "ERROR: short write: %zd of %u\n", nwritten, - g_xipmod_len); - return -EIO; - } - - syslog(LOG_INFO, "staged %u bytes to %s\n", g_xipmod_len, MODPATH); - return 0; -} - -/**************************************************************************** - * Name: extent_info_path - * - * Description: - * Where a file physically lies: its extent, its flash address, and how - * many live mappings are pinning it in place. - * - ****************************************************************************/ - -static int extent_info_path(FAR const char *path, - FAR struct xipfs_extent_info_s *info) -{ - int fd; - int ret; - - fd = open(path, O_RDONLY | O_CLOEXEC); - if (fd < 0) - { - return -errno; - } - - ret = ioctl(fd, XIPFSIOC_EXTENTINFO, (unsigned long)(uintptr_t)info); - close(fd); - - return ret < 0 ? -errno : 0; -} - -/**************************************************************************** - * Name: bench_read - * - * Description: - * Time a bulk read straight out of the memory mapped flash, big enough to - * miss the XIP cache. Run once on a freshly booted system, where the - * bootrom's fast read mode is still in effect, and again after a flash - * write has forced the driver to restore XIP itself. The difference is - * the cost of whichever restore path the driver used. - * - ****************************************************************************/ - -static long bench_read(void) -{ - struct timespec t0; - struct timespec t1; - FAR uint8_t *buf; - ssize_t n; - long total = 0; - int fd; - - buf = malloc(4096); - if (buf == NULL) - { - return -1; - } - - fd = open(BENCH_PATH, O_RDONLY | O_CLOEXEC); - if (fd < 0) - { - free(buf); - return -1; - } - - clock_gettime(CLOCK_MONOTONIC, &t0); - - while ((n = read(fd, buf, 4096)) > 0) - { - total += n; - } - - clock_gettime(CLOCK_MONOTONIC, &t1); - - close(fd); - free(buf); - - if (total <= 0) - { - return -1; - } - - return (t1.tv_sec - t0.tv_sec) * 1000 + - (t1.tv_nsec - t0.tv_nsec) / 1000000; -} - -static int bench_main(void) -{ - long before; - long after; - int fd; - - syslog(LOG_INFO, "\nXIP read benchmark (%d KB)\n", BENCH_SIZE / 1024); - - before = bench_read(); - if (before < 0) - { - syslog(LOG_INFO, " create %s first: " - "dd if=/dev/zero of=%s bs=512 count=512\n", - BENCH_PATH, BENCH_PATH); - return EXIT_FAILURE; - } - - syslog(LOG_INFO, " before any flash write : %ld ms\n", before); - - /* Any write forces the driver to tear XIP down and put it back */ - - fd = open(MOUNTPT "/benchw", - O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0644); - if (fd >= 0) - { - write(fd, "x", 1); - close(fd); - } - - after = bench_read(); - syslog(LOG_INFO, " after a flash write : %ld ms\n", after); - - if (before > 0) - { - syslog(LOG_INFO, " ratio : %ld.%02ldx\n", - after / before, ((after * 100) / before) % 100); - } - - unlink(MOUNTPT "/benchw"); - return EXIT_SUCCESS; -} - -static int remount(void) -{ - int ret; - - ret = umount(MOUNTPT); - if (ret < 0 && errno != ENOENT && errno != EINVAL) - { - return -errno; - } - - ret = mount(MTDDEV, MOUNTPT, "xipfs", 0, NULL); - return ret < 0 ? -errno : 0; -} - -static void fill_pattern(FAR uint8_t *buf, size_t len, uint8_t seed) -{ - size_t i; - - for (i = 0; i < len; i++) - { - buf[i] = (uint8_t)(seed + (i * 7)); - } -} - -static int create_file(FAR const char *path, size_t len, uint8_t seed) -{ - FAR uint8_t *buf; - ssize_t nw; - int fd; - int ret = 0; - - buf = malloc(len); - if (buf == NULL) - { - return -ENOMEM; - } - - fill_pattern(buf, len, seed); - - fd = open(path, O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0644); - if (fd < 0) - { - free(buf); - return -errno; - } - - if (ftruncate(fd, len) < 0) - { - ret = -errno; - } - else - { - nw = write(fd, buf, len); - if (nw != (ssize_t)len) - { - ret = nw < 0 ? -errno : -EIO; - } - } - - close(fd); - free(buf); - return ret; -} - -static bool verify_file(FAR const char *path, size_t len, uint8_t seed) -{ - FAR uint8_t *got; - FAR uint8_t *want; - bool ok = false; - ssize_t n; - int fd; - - got = malloc(len); - want = malloc(len); - if (got == NULL || want == NULL) - { - free(got); - free(want); - return false; - } - - fill_pattern(want, len, seed); - - fd = open(path, O_RDONLY | O_CLOEXEC); - if (fd >= 0) - { - n = read(fd, got, len); - ok = (n == (ssize_t)len) && (memcmp(got, want, len) == 0); - close(fd); - } - - free(got); - free(want); - return ok; -} - -/**************************************************************************** - * Name: run_defrag - * - * Description: - * Compact the volume. The command acts on the volume, so it goes through - * a descriptor for the mountpoint directory: a descriptor for a file - * inside it would hold that file open, and an open extent cannot be - * relocated. - * - ****************************************************************************/ - -static int run_defrag(uint32_t max_ms, - FAR struct xipfs_defrag_result_s *result) -{ - struct xipfs_defrag_arg_s arg; - int fd; - int ret; - - memset(&arg, 0, sizeof(arg)); - arg.max_ms = max_ms; - - fd = open(MOUNTPT, O_RDONLY | O_DIRECTORY | O_CLOEXEC); - if (fd < 0) - { - return -errno; - } - - ret = ioctl(fd, XIPFSIOC_DEFRAG, (unsigned long)(uintptr_t)&arg); - close(fd); - - if (ret < 0) - { - return -errno; - } - - *result = arg.result; - return 0; -} - -/**************************************************************************** - * Defragmentation showcase - * - * Fragments the volume until an allocation genuinely cannot be satisfied -- - * plenty of free space, but none of it contiguous -- then compacts and - * retries the same allocation. On a real board everything below runs - * against real NOR: each move is a page-at-a-time copy, a metadata commit, - * and an erase of the vacated blocks. - ****************************************************************************/ - -static int df_mapfill(FAR uint32_t *dstart, FAR uint32_t *dblocks) -{ - struct xipfs_extent_info_s info; - FAR struct dirent *de; - FAR DIR *dirp; - char path[80]; - int files = 0; - uint32_t i; - - memset(g_map, '.', sizeof(g_map)); - *dstart = 0; - *dblocks = 0; - - dirp = opendir(MOUNTPT); - if (dirp == NULL) - { - return -1; - } - - while ((de = readdir(dirp)) != NULL) - { - snprintf(path, sizeof(path), "%s/%s", MOUNTPT, de->d_name); - if (extent_info_path(path, &info) < 0) - { - continue; - } - - *dstart = info.data_start; - *dblocks = info.data_nblocks; - files++; - - for (i = 0; i < info.nblocks; i++) - { - uint32_t idx = info.start_block - info.data_start + i; - if (idx < sizeof(g_map)) - { - g_map[idx] = '#'; - } - } - } - - closedir(dirp); - return files; -} - -static void df_showmap(FAR const char *title, uint32_t dblocks, - FAR uint32_t *freeout, FAR uint32_t *largestout) -{ - uint32_t largest = 0; - uint32_t run = 0; - uint32_t free = 0; - uint32_t i; - char row[DF_MAPCOLS + 1]; - - syslog(LOG_INFO, "\n %s\n", title); - - for (i = 0; i < dblocks; i++) - { - if (g_map[i] == '.') - { - free++; - if (++run > largest) - { - largest = run; - } - } - else - { - run = 0; - } - } - - for (i = 0; i < dblocks; i += DF_MAPCOLS) - { - uint32_t n = dblocks - i; - if (n > DF_MAPCOLS) - { - n = DF_MAPCOLS; - } - - memcpy(row, &g_map[i], n); - row[n] = '\0'; - syslog(LOG_INFO, " %3" PRIu32 " |%s|\n", i, row); - } - - syslog(LOG_INFO, " free %" PRIu32 - " blocks, largest contiguous run %" PRIu32 "\n", free, largest); - - if (freeout != NULL) - { - *freeout = free; - } - - if (largestout != NULL) - { - *largestout = largest; - } -} - -static int df_try_alloc(uint32_t nblocks, uint32_t erasesize) -{ - int fd; - int ret; - - unlink(MOUNTPT "/bigalloc"); - - fd = open(MOUNTPT "/bigalloc", - O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0644); - if (fd < 0) - { - return -errno; - } - - ret = ftruncate(fd, (off_t)nblocks * erasesize); - close(fd); - - if (ret < 0) - { - ret = -errno; - unlink(MOUNTPT "/bigalloc"); - } - - return ret; -} - -/**************************************************************************** - * Name: empty_dir - * - * Description: - * Delete everything below 'dir', descending into subdirectories. - * - * One entry is taken per pass rather than a listing being collected up - * front, because this recurses and the task stack is the default 2 KB: an - * array of names big enough to be useful costs more than a kilobyte a - * frame, and two levels of that overflows and returns through a smashed - * frame. A pass costs an opendir instead, which no one is timing. - * - * The directory is closed before anything is removed, since unlinking - * while iterating skips entries. - * - ****************************************************************************/ - -static void empty_dir(FAR const char *dir) -{ - char path[80]; - bool more = true; - - while (more) - { - FAR struct dirent *de; - FAR DIR *dirp; - bool isdir; - - dirp = opendir(dir); - if (dirp == NULL) - { - return; - } - - de = readdir(dirp); - if (de == NULL) - { - closedir(dirp); - return; - } - - isdir = (de->d_type == DTYPE_DIRECTORY); - snprintf(path, sizeof(path), "%s/%s", dir, de->d_name); - closedir(dirp); - - if (isdir) - { - empty_dir(path); - more = rmdir(path) == 0; - } - else - { - more = unlink(path) == 0; - } - } -} - -static int defrag_main(void) -{ - struct xipfs_defrag_result_s res; - struct xipfs_extent_info_s info; - struct timespec t0; - struct timespec t1; - uint32_t dstart; - uint32_t dblocks; - uint32_t erasesize = 4096; - uint32_t want; - uint32_t freeblk = 0; - uint32_t largest = 0; - char path[80]; - long ms; - int i; - int ret; - - memset(&res, 0, sizeof(res)); - - syslog(LOG_INFO, "\n=== xipfs defragmentation ===\n"); - - /* Clean slate, so the map below accounts for every used block */ - - empty_dir(MOUNTPT); - - syslog(LOG_INFO, "\n[1] writing %d files...\n", DF_FILES); - - for (i = 0; i < DF_FILES; i++) - { - snprintf(path, sizeof(path), MOUNTPT "/m%02d", i); - if (create_file(path, 2000, (uint8_t)(i + 1)) < 0) - { - syslog(LOG_INFO, " stopped at %d (volume full)\n", i); - break; - } - } - - if (extent_info_path(MOUNTPT "/m00", &info) == 0) - { - erasesize = info.erasesize; - } - - df_mapfill(&dstart, &dblocks); - df_showmap("map, all files present:", dblocks, NULL, NULL); - - syslog(LOG_INFO, "\n[2] deleting every other file to fragment it...\n"); - - for (i = 0; i < DF_FILES; i += 2) - { - snprintf(path, sizeof(path), MOUNTPT "/m%02d", i); - unlink(path); - } - - df_mapfill(&dstart, &dblocks); - df_showmap("map, fragmented (# used, . free):", dblocks, - &freeblk, &largest); - - /* Bigger than any single hole, but comfortably inside the total free - * space -- so it can only be satisfied once the holes are coalesced. - */ - - want = largest + (freeblk - largest) / 2; - - syslog(LOG_INFO, "\n[3] requesting a %" PRIu32 - "-block (%" PRIu32 " KB) contiguous file\n", want, - want * erasesize / 1024); - - ret = df_try_alloc(want, erasesize); - syslog(LOG_INFO, " result: %s\n", - ret < 0 ? "FAILED -ENOSPC (free space is not contiguous)" : "ok"); - - syslog(LOG_INFO, "\n[4] compacting...\n"); - - clock_gettime(CLOCK_MONOTONIC, &t0); - ret = run_defrag(0, &res); - clock_gettime(CLOCK_MONOTONIC, &t1); - - ms = (t1.tv_sec - t0.tv_sec) * 1000 + (t1.tv_nsec - t0.tv_nsec) / 1000000; - - if (ret < 0) - { - syslog(LOG_INFO, " defrag failed: %d\n", ret); - return EXIT_FAILURE; - } - - syslog(LOG_INFO, " elapsed : %ld ms\n", ms); - syslog(LOG_INFO, " extents relocated: %" PRIu32 "\n", - res.extents_moved); - syslog(LOG_INFO, " blocks reclaimed : %" PRIu32 "\n", - res.blocks_reclaimed); - syslog(LOG_INFO, " largest free run : %zu bytes (%zu blocks)\n", - res.largest_free_run, res.largest_free_run / erasesize); - syslog(LOG_INFO, " stop reason : %d (%s)\n", res.reason, - res.reason == XIPFS_DEFRAG_DONE ? "done" : - res.reason == XIPFS_DEFRAG_BLOCKED_OPEN ? "blocked by an open " - "file" : - res.reason == XIPFS_DEFRAG_BLOCKED_PINS ? "blocked by a live " - "XIP mapping" : - "other"); - - df_mapfill(&dstart, &dblocks); - df_showmap("map after defrag:", dblocks, NULL, NULL); - - want = res.largest_free_run / erasesize; - - syslog(LOG_INFO, "\n[5] retrying, sized to the reported largest run" - " (%" PRIu32 " blocks)\n", want); - ret = df_try_alloc(want, erasesize); - syslog(LOG_INFO, " result: %s\n", - ret < 0 ? "still failed" : "OK -- allocation now fits"); - unlink(MOUNTPT "/bigalloc"); - - syslog(LOG_INFO, "\n[6] verifying every relocated file byte-for-byte\n"); - - ret = 0; - for (i = 1; i < DF_FILES; i += 2) - { - snprintf(path, sizeof(path), MOUNTPT "/m%02d", i); - if (!verify_file(path, 2000, (uint8_t)(i + 1))) - { - syslog(LOG_INFO, " MISMATCH in %s\n", path); - ret = -1; - } - } - - syslog(LOG_INFO, " %s\n", ret == 0 ? "all survivors intact" : "FAILED"); - - syslog(LOG_INFO, "\n[7] remounting to prove it is durable\n"); - if (remount() < 0) - { - syslog(LOG_INFO, " remount FAILED\n"); - return EXIT_FAILURE; - } - - ret = 0; - for (i = 1; i < DF_FILES; i += 2) - { - snprintf(path, sizeof(path), MOUNTPT "/m%02d", i); - if (!verify_file(path, 2000, (uint8_t)(i + 1))) - { - ret = -1; - } - } - - syslog(LOG_INFO, " %s\n", - ret == 0 ? "all files intact after remount" : "FAILED"); - - syslog(LOG_INFO, "\n=== defrag complete ===\n"); - return EXIT_SUCCESS; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -int main(int argc, FAR char *argv[]) -{ - struct xipfs_extent_info_s info; - FAR char *args[3]; - char seed[2][8]; - pid_t pid[2]; - int status; - int ret; - int i; - - if (argc > 1 && strcmp(argv[1], "bench") == 0) - { - return bench_main(); - } - - if (argc > 1 && strcmp(argv[1], "defrag") == 0) - { - return defrag_main(); - } - - syslog(LOG_INFO, - "\n=== NXFLAT module executed in place from xipfs ===\n\n"); - - ret = stage_module(); - if (ret < 0) - { - return EXIT_FAILURE; - } - - ret = extent_info_path(MODPATH, &info); - if (ret < 0) - { - syslog(LOG_INFO, "ERROR: cannot query extent: %d\n", ret); - return EXIT_FAILURE; - } - - syslog(LOG_INFO, "extent: block %" PRIu32 " x%" PRIu32 ", size %" PRIu32 - ", flash addr 0x%08" PRIxPTR "\n", - info.start_block, info.nblocks, info.size, info.xipaddr); - - if (info.xipaddr == 0) - { - syslog(LOG_INFO, - "ERROR: the file system cannot expose a flash pointer, so the " - "module would have to be copied to RAM. Does the MTD driver " - "answer BIOC_XIPBASE?\n"); - return EXIT_FAILURE; - } - - /* Launch two instances. They overlap deliberately: each fills its array, - * sleeps, then checks it. Shared data would show up as a mismatch. - */ - - syslog(LOG_INFO, "\nrunning two concurrent instances...\n\n"); - - for (i = 0; i < 2; i++) - { - snprintf(seed[i], sizeof(seed[i]), "%d", i + 1); - - args[0] = (FAR char *)"xipmod"; - args[1] = seed[i]; - args[2] = NULL; - - /* exec() rather than posix_spawn() because the symbol table the - * module links against is the demo's, not one the OS holds. - */ - - pid[i] = exec(MODPATH, args, NULL, g_nxflat_exports, - g_nxflat_nexports); - if (pid[i] < 0) - { - syslog(LOG_INFO, "ERROR: exec of instance %d failed: %d\n", i + 1, - pid[i]); - return EXIT_FAILURE; - } - } - - /* While both are alive the shared text must be pinned once per instance, - * which is what stops the defragmenter relocating code that is executing. - */ - - usleep(100000); - - if (extent_info_path(MODPATH, &info) == 0) - { - syslog(LOG_INFO, - "\n[while running] pin count on the shared text = %" PRIu32 - "\n\n", info.pincount); - } - - for (i = 0; i < 2; i++) - { - if (waitpid(pid[i], &status, 0) >= 0 && - (!WIFEXITED(status) || WEXITSTATUS(status) != EXIT_SUCCESS)) - { - syslog(LOG_INFO, "instance %d did not exit cleanly\n", i + 1); - ret = -1; - } - } - - /* The pins outlive the instances. binfmt maps the text in the context of - * whoever called exec(), so the mappings belong to this task's address - * space, not to the tasks that ran, and they are released when this task - * exits. Run "xipfs -n" after this demo returns to see the count back at - * zero and the extent movable again. - */ - - if (extent_info_path(MODPATH, &info) == 0) - { - syslog(LOG_INFO, - "[after exit] pin count on the shared text = %" PRIu32 - " (released when this task exits)\n", info.pincount); - } - - syslog(LOG_INFO, "\n=== %s ===\n", ret == 0 ? "done" : "FAILED"); - return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; -} diff --git a/examples/nxhello/CMakeLists.txt b/examples/nxhello/CMakeLists.txt deleted file mode 100644 index 96330188f..000000000 --- a/examples/nxhello/CMakeLists.txt +++ /dev/null @@ -1,36 +0,0 @@ -# ############################################################################## -# apps/examples/nxhello/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_NXHELLO) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_NXHELLO_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_NXHELLO_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_NXHELLO_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_NXHELLO} - SRCS - nxhello_main.c) - target_sources(apps PRIVATE nxhello_bkgd.c nxhello_listener.c) -endif() diff --git a/examples/nxhello/Kconfig b/examples/nxhello/Kconfig index 63f3850db..ee29ec205 100644 --- a/examples/nxhello/Kconfig +++ b/examples/nxhello/Kconfig @@ -102,4 +102,10 @@ config EXAMPLES_NXHELLO_LISTENERPRIO ---help--- The priority of the event listener thread. Default 80. +config EXAMPLES_NXHELLO_NOTIFYSIGNO + int "Notify Signal Number" + default 4 + ---help--- + The signal number to use with nx_eventnotify(). Default: 4 + endif diff --git a/examples/nxhello/Make.defs b/examples/nxhello/Make.defs index c64c988f5..c0081cd11 100644 --- a/examples/nxhello/Make.defs +++ b/examples/nxhello/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/nxhello/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/nxhello/Makefile b/examples/nxhello/Makefile index 4fd312e89..5e0c54de8 100644 --- a/examples/nxhello/Makefile +++ b/examples/nxhello/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/nxhello/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/nxhello/nxhello.h b/examples/nxhello/nxhello.h index 9fae5855a..44c461c8a 100644 --- a/examples/nxhello/nxhello.h +++ b/examples/nxhello/nxhello.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/nxhello/nxhello.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -62,7 +60,7 @@ # define CONFIG_EXAMPLES_NXHELLO_BGCOLOR 0x00 # else # define CONFIG_EXAMPLES_NXHELLO_BGCOLOR ' ' -# endif +# endif #endif #ifndef CONFIG_EXAMPLES_NXHELLO_FONTID @@ -104,6 +102,9 @@ #ifndef CONFIG_EXAMPLES_NXHELLO_SERVERPRIO # define CONFIG_EXAMPLES_NXHELLO_SERVERPRIO 120 #endif +#ifndef CONFIG_EXAMPLES_NXHELLO_NOTIFYSIGNO +# define CONFIG_EXAMPLES_NXHELLO_NOTIFYSIGNO 4 +#endif /**************************************************************************** * Public Types diff --git a/examples/nxhello/nxhello_bkgd.c b/examples/nxhello/nxhello_bkgd.c index 5e0a5b80e..1a18925ca 100644 --- a/examples/nxhello/nxhello_bkgd.c +++ b/examples/nxhello/nxhello_bkgd.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/nxhello/nxhello_bkgd.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -33,7 +31,7 @@ #include <string.h> #include <semaphore.h> #include <errno.h> -#include <nuttx/debug.h> +#include <debug.h> #include <nuttx/nx/nx.h> #include <nuttx/nx/nxglib.h> @@ -76,21 +74,19 @@ ****************************************************************************/ static void nxhello_redraw(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect, - bool morem, FAR void *arg); -static void nxhello_position(NXWINDOW hwnd, - FAR const struct nxgl_size_s *size, - FAR const struct nxgl_point_s *pos, - FAR const struct nxgl_rect_s *bounds, - FAR void *arg); + bool morem, FAR void *arg); +static void nxhello_position(NXWINDOW hwnd, FAR const struct nxgl_size_s *size, + FAR const struct nxgl_point_s *pos, + FAR const struct nxgl_rect_s *bounds, + FAR void *arg); #ifdef CONFIG_NX_XYINPUT -static void nxhello_mousein(NXWINDOW hwnd, - FAR const struct nxgl_point_s *pos, - uint8_t buttons, FAR void *arg); +static void nxhello_mousein(NXWINDOW hwnd, FAR const struct nxgl_point_s *pos, + uint8_t buttons, FAR void *arg); #endif #ifdef CONFIG_NX_KBD -static void nxhello_kbdin(NXWINDOW hwnd, uint8_t nch, - FAR const uint8_t *ch, FAR void *arg); +static void nxhello_kbdin(NXWINDOW hwnd, uint8_t nch, FAR const uint8_t *ch, + FAR void *arg); #endif /**************************************************************************** @@ -127,7 +123,7 @@ const struct nx_callback_s g_nxhellocb = ****************************************************************************/ static void nxhello_redraw(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect, - bool more, FAR void *arg) + bool more, FAR void *arg) { ginfo("hwnd=%p rect={(%d,%d),(%d,%d)} more=%s\n", hwnd, rect->pt1.x, rect->pt1.y, rect->pt2.x, rect->pt2.y, @@ -138,11 +134,10 @@ static void nxhello_redraw(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect, * Name: nxhello_position ****************************************************************************/ -static void nxhello_position(NXWINDOW hwnd, - FAR const struct nxgl_size_s *size, - FAR const struct nxgl_point_s *pos, - FAR const struct nxgl_rect_s *bounds, - FAR void *arg) +static void nxhello_position(NXWINDOW hwnd, FAR const struct nxgl_size_s *size, + FAR const struct nxgl_point_s *pos, + FAR const struct nxgl_rect_s *bounds, + FAR void *arg) { /* Report the position */ @@ -174,9 +169,8 @@ static void nxhello_position(NXWINDOW hwnd, ****************************************************************************/ #ifdef CONFIG_NX_XYINPUT -static void nxhello_mousein(NXWINDOW hwnd, - FAR const struct nxgl_point_s *pos, - uint8_t buttons, FAR void *arg) +static void nxhello_mousein(NXWINDOW hwnd, FAR const struct nxgl_point_s *pos, + uint8_t buttons, FAR void *arg) { printf("nxhello_mousein: hwnd=%p pos=(%d,%d) button=%02x\n", hwnd, pos->x, pos->y, buttons); @@ -188,16 +182,16 @@ static void nxhello_mousein(NXWINDOW hwnd, ****************************************************************************/ #ifdef CONFIG_NX_KBD -static void nxhello_kbdin(NXWINDOW hwnd, uint8_t nch, - FAR const uint8_t *ch, FAR void *arg) +static void nxhello_kbdin(NXWINDOW hwnd, uint8_t nch, FAR const uint8_t *ch, + FAR void *arg) { ginfo("hwnd=%p nch=%d\n", hwnd, nch); - /* In this example, there is no keyboard so a keyboard event is not - * expected. - */ + /* In this example, there is no keyboard so a keyboard event is not + * expected. + */ - printf("nxhello_kbdin: Unexpected keyboard callback\n"); + printf("nxhello_kbdin: Unexpected keyboard callback\n"); } #endif @@ -216,7 +210,7 @@ static void nxhello_center(FAR struct nxgl_point_s *pos, * hello world message. */ - for (ptr = (uint8_t *)g_hello, width = 0; *ptr; ptr++) + for (ptr = (uint8_t*)g_hello, width = 0; *ptr; ptr++) { /* Get the font bitmap for this character */ @@ -229,7 +223,7 @@ static void nxhello_center(FAR struct nxgl_point_s *pos, } else { - /* Use the width of a space */ + /* Use the width of a space */ width += fontset->spwidth; } @@ -270,7 +264,7 @@ static void nxhello_initglyph(FAR uint8_t *glyph, uint8_t height, /* Pack 1-bit pixels into a 2-bits */ pixel &= 0x01; - pixel = (pixel) << 1 | pixel; + pixel = (pixel) << 1 |pixel; # endif # if CONFIG_EXAMPLES_NXHELLO_BPP < 4 @@ -278,7 +272,7 @@ static void nxhello_initglyph(FAR uint8_t *glyph, uint8_t height, /* Pack 2-bit pixels into a nibble */ pixel &= 0x03; - pixel = (pixel) << 2 | pixel; + pixel = (pixel) << 2 |pixel; # endif @@ -352,10 +346,10 @@ void nxhello_hello(NXWINDOW hwnd) mxstride = (fontset->mxwidth * CONFIG_EXAMPLES_NXHELLO_BPP + 7) >> 3; glyphsize = (unsigned int)fontset->mxheight * mxstride; - glyph = (FAR uint8_t *)malloc(glyphsize); + glyph = (FAR uint8_t*)malloc(glyphsize); - /* NOTE: no check for failure to allocate the memory. In a real - * application you would need to handle that event. + /* NOTE: no check for failure to allocate the memory. In a real application + * you would need to handle that event. */ /* Get a position so the "Hello, World!" string will be centered on the @@ -393,7 +387,7 @@ void nxhello_hello(NXWINDOW hwnd) #if CONFIG_NX_NPLANES > 1 # warning "More logic is needed for the case where CONFIG_NX_PLANES > 1" #endif - RENDERER((FAR nxgl_mxpixel_t *)glyph, fheight, fwidth, + RENDERER((FAR nxgl_mxpixel_t*)glyph, fheight, fwidth, fstride, fbm, CONFIG_EXAMPLES_NXHELLO_FONTCOLOR); /* Describe the destination of the font with a rectangle */ @@ -405,7 +399,7 @@ void nxhello_hello(NXWINDOW hwnd) /* Then put the font on the display */ - src[0] = glyph; + src[0] = (FAR const void *)glyph; #if CONFIG_NX_NPLANES > 1 # warning "More logic is needed for the case where CONFIG_NX_PLANES > 1" #endif @@ -415,15 +409,15 @@ void nxhello_hello(NXWINDOW hwnd) printf("nxhello_write: nx_bitmapwindow failed: %d\n", errno); } - /* Skip to the right the width of the font */ + /* Skip to the right the width of the font */ pos.x += fwidth; } else { - /* No bitmap (probably because the font is a space). Skip to the - * right the width of a space. - */ + /* No bitmap (probably because the font is a space). Skip to the + * right the width of a space. + */ pos.x += fontset->spwidth; } diff --git a/examples/nxhello/nxhello_listener.c b/examples/nxhello/nxhello_listener.c index 65995f476..06273af84 100644 --- a/examples/nxhello/nxhello_listener.c +++ b/examples/nxhello/nxhello_listener.c @@ -1,7 +1,5 @@ /**************************************************************************** - * apps/examples/nxhello/nxhello_listener.c - * - * SPDX-License-Identifier: Apache-2.0 + * apps/examples/nxterm/nxhello_listener.c * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -48,7 +46,7 @@ FAR void *nxhello_listener(FAR void *arg) /* Process events forever */ - for (; ; ) + for (;;) { /* Handle the next event. If we were configured blocking, then * we will stay right here until the next event is received. Since diff --git a/examples/nxhello/nxhello_main.c b/examples/nxhello/nxhello_main.c index d524f6f2c..097134ebe 100644 --- a/examples/nxhello/nxhello_main.c +++ b/examples/nxhello/nxhello_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/nxhello/nxhello_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -38,7 +36,7 @@ #include <sched.h> #include <pthread.h> #include <errno.h> -#include <nuttx/debug.h> +#include <debug.h> #include <nuttx/arch.h> #include <nuttx/board.h> @@ -95,8 +93,7 @@ static inline int nxhello_initialize(void) ret = boardctl(BOARDIOC_NX_START, 0); if (ret < 0) { - printf("nxhello_initialize: Failed to start the NX server: %d\n", - errno); + printf("nxhello_initialize: Failed to start the NX server: %d\n", errno); return ERROR; } @@ -105,53 +102,52 @@ static inline int nxhello_initialize(void) g_nxhello.hnx = nx_connect(); if (g_nxhello.hnx) { - pthread_attr_t attr; + pthread_attr_t attr; #ifdef CONFIG_VNCSERVER /* Setup the VNC server to support keyboard/mouse inputs */ - struct boardioc_vncstart_s vnc = - { - 0, g_nxhello.hnx - }; + struct boardioc_vncstart_s vnc = + { + 0, g_nxhello.hnx + }; - ret = boardctl(BOARDIOC_VNC_START, (uintptr_t)&vnc); - if (ret < 0) - { - printf("boardctl(BOARDIOC_VNC_START) failed: %d\n", ret); - nx_disconnect(g_nxhello.hnx); - return ERROR; - } + ret = boardctl(BOARDIOC_VNC_START, (uintptr_t)&vnc); + if (ret < 0) + { + printf("boardctl(BOARDIOC_VNC_START) failed: %d\n", ret); + nx_disconnect(g_nxhello.hnx); + return ERROR; + } #endif - /* Start a separate thread to listen for server events. This is - * probably the least efficient way to do this, but it makes this - * example flow more smoothly. - */ + /* Start a separate thread to listen for server events. This is probably + * the least efficient way to do this, but it makes this example flow more + * smoothly. + */ - pthread_attr_init(&attr); - param.sched_priority = CONFIG_EXAMPLES_NXHELLO_LISTENERPRIO; - pthread_attr_setschedparam(&attr, ¶m); - pthread_attr_setstacksize(&attr, - CONFIG_EXAMPLES_NXHELLO_LISTENER_STACKSIZE); + pthread_attr_init(&attr); + param.sched_priority = CONFIG_EXAMPLES_NXHELLO_LISTENERPRIO; + pthread_attr_setschedparam(&attr, ¶m); + pthread_attr_setstacksize(&attr, CONFIG_EXAMPLES_NXHELLO_LISTENER_STACKSIZE); - ret = pthread_create(&thread, &attr, nxhello_listener, NULL); - if (ret != 0) - { - printf("nxhello_initialize: pthread_create failed: %d\n", ret); - return ERROR; - } + ret = pthread_create(&thread, &attr, nxhello_listener, NULL); + if (ret != 0) + { + printf("nxhello_initialize: pthread_create failed: %d\n", ret); + return ERROR; + } - /* Don't return until we are connected to the server */ + /* Don't return until we are connected to the server */ - while (!g_nxhello.connected) - { - /* Wait for the listener thread to wake us up when we really - * are connected. - */ + while (!g_nxhello.connected) + { + /* Wait for the listener thread to wake us up when we really + * are connected. + */ - sem_wait(&g_nxhello.eventsem); - } + sem_wait(&g_nxhello.eventsem); + } } else { @@ -227,8 +223,7 @@ int main(int argc, FAR char *argv[]) sem_wait(&g_nxhello.eventsem); } - printf("nxhello_main: Screen resolution (%d,%d)\n", - g_nxhello.xres, g_nxhello.yres); + printf("nxhello_main: Screen resolution (%d,%d)\n", g_nxhello.xres, g_nxhello.yres); /* Now, say hello and exit, sleeping a little before each. */ diff --git a/examples/nximage/CMakeLists.txt b/examples/nximage/CMakeLists.txt deleted file mode 100644 index 0fa9b0adc..000000000 --- a/examples/nximage/CMakeLists.txt +++ /dev/null @@ -1,37 +0,0 @@ -# ############################################################################## -# apps/examples/nximage/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_NXIMAGE) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_NXIMAGE_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_NXIMAGE_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_NXIMAGE_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_NXIMAGE} - SRCS - nximage_main.c) - target_sources(apps PRIVATE nximage_bkgd.c nximage_bitmap.c - nximage_listener.c) -endif() diff --git a/examples/nximage/Kconfig b/examples/nximage/Kconfig index 1014da156..abc84fc60 100644 --- a/examples/nximage/Kconfig +++ b/examples/nximage/Kconfig @@ -15,7 +15,7 @@ if EXAMPLES_NXIMAGE config EXAMPLES_NXIMAGE_PROGNAME string "NX Image Program name" - default "nximage" + default "nxhello" ---help--- This is the name of the program that will be used when the NSH ELF program is installed. @@ -116,4 +116,10 @@ config EXAMPLES_NXIMAGE_LISTENERPRIO ---help--- The priority of the event listener thread. Default 80. +config EXAMPLES_NXIMAGE_NOTIFYSIGNO + int "Notify Signal Number" + default 4 + ---help--- + The signal number to use with nx_eventnotify(). Default: 4 + endif diff --git a/examples/nximage/Make.defs b/examples/nximage/Make.defs index 5fdc15793..dbdbd4b18 100644 --- a/examples/nximage/Make.defs +++ b/examples/nximage/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/nximage/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/nximage/Makefile b/examples/nximage/Makefile index b4ed626a3..1e11d344b 100644 --- a/examples/nximage/Makefile +++ b/examples/nximage/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/nximage/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/nximage/nximage.h b/examples/nximage/nximage.h index 12e79e0e5..14c1ca0b0 100644 --- a/examples/nximage/nximage.h +++ b/examples/nximage/nximage.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/nximage/nximage.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -113,6 +111,9 @@ #ifndef CONFIG_EXAMPLES_NXIMAGE_SERVERPRIO # define CONFIG_EXAMPLES_NXIMAGE_SERVERPRIO 120 #endif +#ifndef CONFIG_EXAMPLES_NXIMAGE_NOTIFYSIGNO +# define CONFIG_EXAMPLES_NXIMAGE_NOTIFYSIGNO 4 +#endif /* Image Information ********************************************************/ @@ -196,8 +197,7 @@ void nximage_image(NXWINDOW hwnd); /* Image interfaces */ nxgl_mxpixel_t nximage_bgcolor(void); -nxgl_mxpixel_t nximage_avgcolor(nxgl_mxpixel_t color1, - nxgl_mxpixel_t color2); +nxgl_mxpixel_t nximage_avgcolor(nxgl_mxpixel_t color1, nxgl_mxpixel_t color2); void nximage_blitrow(FAR nxgl_mxpixel_t *run, FAR const void **state); #endif /* __APPS_EXAMPLES_NXIMAGE_NXIMAGE_H */ diff --git a/examples/nximage/nximage_bitmap.c b/examples/nximage/nximage_bitmap.c index ee7444a14..34d0bce18 100644 --- a/examples/nximage/nximage_bitmap.c +++ b/examples/nximage/nximage_bitmap.c @@ -1,8 +1,6 @@ /******************************************************************************************** * apps/examples/nximage/nximage_bitmap.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -3694,5 +3692,5 @@ void nximage_blitrow(FAR nxgl_mxpixel_t *run, FAR const void **state) /* Save the start of the next row and return success */ - *state = pos; + *state = (FAR const void *)pos; } diff --git a/examples/nximage/nximage_bkgd.c b/examples/nximage/nximage_bkgd.c index 8e3a2f651..f63ef144f 100644 --- a/examples/nximage/nximage_bkgd.c +++ b/examples/nximage/nximage_bkgd.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/nximage/nximage_bkgd.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -33,7 +31,7 @@ #include <string.h> #include <semaphore.h> #include <errno.h> -#include <nuttx/debug.h> +#include <debug.h> #include <nuttx/nx/nx.h> #include <nuttx/nx/nxglib.h> @@ -109,21 +107,19 @@ struct nximage_run_s ****************************************************************************/ static void nximage_redraw(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect, - bool more, FAR void *arg); -static void nximage_position(NXWINDOW hwnd, - FAR const struct nxgl_size_s *size, - FAR const struct nxgl_point_s *pos, - FAR const struct nxgl_rect_s *bounds, - FAR void *arg); + bool more, FAR void *arg); +static void nximage_position(NXWINDOW hwnd, FAR const struct nxgl_size_s *size, + FAR const struct nxgl_point_s *pos, + FAR const struct nxgl_rect_s *bounds, + FAR void *arg); #ifdef CONFIG_NX_XYINPUT -static void nximage_mousein(NXWINDOW hwnd, - FAR const struct nxgl_point_s *pos, - uint8_t buttons, FAR void *arg); +static void nximage_mousein(NXWINDOW hwnd, FAR const struct nxgl_point_s *pos, + uint8_t buttons, FAR void *arg); #endif #ifdef CONFIG_NX_KBD -static void nximage_kbdin(NXWINDOW hwnd, uint8_t nch, - FAR const uint8_t *ch, FAR void *arg); +static void nximage_kbdin(NXWINDOW hwnd, uint8_t nch, FAR const uint8_t *ch, + FAR void *arg); #endif /**************************************************************************** @@ -166,7 +162,7 @@ const struct nx_callback_s g_nximagecb = ****************************************************************************/ static void nximage_redraw(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect, - bool more, FAR void *arg) + bool more, FAR void *arg) { ginfo("hwnd=%p rect={(%d,%d),(%d,%d)} more=%s\n", hwnd, rect->pt1.x, rect->pt1.y, rect->pt2.x, rect->pt2.y, @@ -181,11 +177,10 @@ static void nximage_redraw(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect, * ****************************************************************************/ -static void nximage_position(NXWINDOW hwnd, - FAR const struct nxgl_size_s *size, - FAR const struct nxgl_point_s *pos, - FAR const struct nxgl_rect_s *bounds, - FAR void *arg) +static void nximage_position(NXWINDOW hwnd, FAR const struct nxgl_size_s *size, + FAR const struct nxgl_point_s *pos, + FAR const struct nxgl_rect_s *bounds, + FAR void *arg) { /* Report the position */ @@ -221,9 +216,8 @@ static void nximage_position(NXWINDOW hwnd, ****************************************************************************/ #ifdef CONFIG_NX_XYINPUT -static void nximage_mousein(NXWINDOW hwnd, - FAR const struct nxgl_point_s *pos, - uint8_t buttons, FAR void *arg) +static void nximage_mousein(NXWINDOW hwnd, FAR const struct nxgl_point_s *pos, + uint8_t buttons, FAR void *arg) { printf("nximage_mousein: hwnd=%p pos=(%d,%d) button=%02x\n", hwnd, pos->x, pos->y, buttons); @@ -239,16 +233,16 @@ static void nximage_mousein(NXWINDOW hwnd, ****************************************************************************/ #ifdef CONFIG_NX_KBD -static void nximage_kbdin(NXWINDOW hwnd, uint8_t nch, - FAR const uint8_t *ch, FAR void *arg) +static void nximage_kbdin(NXWINDOW hwnd, uint8_t nch, FAR const uint8_t *ch, + FAR void *arg) { ginfo("hwnd=%p nch=%d\n", hwnd, nch); - /* In this example, there is no keyboard so a keyboard event is not - * expected. - */ + /* In this example, there is no keyboard so a keyboard event is not + * expected. + */ - printf("nximage_kbdin: Unexpected keyboard callback\n"); + printf("nximage_kbdin: Unexpected keyboard callback\n"); } #endif @@ -292,9 +286,9 @@ void nximage_image(NXWINDOW hwnd) { /* Read input row(s) */ - nximage_blitrow(g_runs[0].run, &state); + nximage_blitrow(g_runs[0].run, &state); #if NINPUT_ROWS > 1 - nximage_blitrow(g_runs[1].run, &state); + nximage_blitrow(g_runs[1].run, &state); #endif /* Output rows before averaging */ @@ -306,12 +300,11 @@ void nximage_image(NXWINDOW hwnd) dest.pt1.y = pos.y; dest.pt2.y = pos.y; - src[0] = g_runs[0].run; + src[0] = (FAR const void *)g_runs[0].run; #if CONFIG_NX_NPLANES > 1 # warning "More logic is needed for the case where CONFIG_NX_PLANES > 1" #endif - ret = nx_bitmap((NXWINDOW)hwnd, &dest, src, &pos, - SCALED_WIDTH * sizeof(nxgl_mxpixel_t)); + ret = nx_bitmap((NXWINDOW)hwnd, &dest, src, &pos, SCALED_WIDTH*sizeof(nxgl_mxpixel_t)); if (ret < 0) { printf("nximage_image: nx_bitmapwindow failed: %d\n", errno); @@ -349,12 +342,11 @@ void nximage_image(NXWINDOW hwnd) dest.pt1.y = pos.y; dest.pt2.y = pos.y; - src[0] = g_runs[0].run; + src[0] = (FAR const void *)g_runs[0].run; #if CONFIG_NX_NPLANES > 1 # warning "More logic is needed for the case where CONFIG_NX_PLANES > 1" #endif - ret = nx_bitmap((NXWINDOW)hwnd, &dest, src, &pos, - SCALED_WIDTH * sizeof(nxgl_mxpixel_t)); + ret = nx_bitmap((NXWINDOW)hwnd, &dest, src, &pos, SCALED_WIDTH*sizeof(nxgl_mxpixel_t)); if (ret < 0) { printf("nximage_image: nx_bitmapwindow failed: %d\n", errno); @@ -371,12 +363,11 @@ void nximage_image(NXWINDOW hwnd) dest.pt1.y = pos.y; dest.pt2.y = pos.y; - src[0] = g_runs[1].run; + src[0] = (FAR const void *)g_runs[1].run; #if CONFIG_NX_NPLANES > 1 # warning "More logic is needed for the case where CONFIG_NX_PLANES > 1" #endif - ret = nx_bitmap((NXWINDOW)hwnd, &dest, src, &pos, - SCALED_WIDTH * sizeof(nxgl_mxpixel_t)); + ret = nx_bitmap((NXWINDOW)hwnd, &dest, src, &pos, SCALED_WIDTH*sizeof(nxgl_mxpixel_t)); if (ret < 0) { printf("nximage_image: nx_bitmapwindow failed: %d\n", errno); diff --git a/examples/nximage/nximage_listener.c b/examples/nximage/nximage_listener.c index cc0353ee0..84d4e47ca 100644 --- a/examples/nximage/nximage_listener.c +++ b/examples/nximage/nximage_listener.c @@ -1,7 +1,5 @@ /**************************************************************************** - * apps/examples/nximage/nximage_listener.c - * - * SPDX-License-Identifier: Apache-2.0 + * apps/examples/nxterm/nximage_listener.c * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -48,7 +46,7 @@ FAR void *nximage_listener(FAR void *arg) /* Process events forever */ - for (; ; ) + for (;;) { /* Handle the next event. If we were configured blocking, then * we will stay right here until the next event is received. Since diff --git a/examples/nximage/nximage_main.c b/examples/nximage/nximage_main.c index 4d9648f0f..96a85b63f 100644 --- a/examples/nximage/nximage_main.c +++ b/examples/nximage/nximage_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/nximage/nximage_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -38,7 +36,7 @@ #include <sched.h> #include <pthread.h> #include <errno.h> -#include <nuttx/debug.h> +#include <debug.h> #include <nuttx/arch.h> #include <nuttx/board.h> @@ -90,7 +88,7 @@ static inline int nximage_initialize(void) ret = sched_setparam(0, ¶m); if (ret < 0) { - printf("nximage_initialize: sched_setparam failed: %d\n", ret); + printf("nximage_initialize: sched_setparam failed: %d\n" , ret); return ERROR; } @@ -99,8 +97,7 @@ static inline int nximage_initialize(void) ret = boardctl(BOARDIOC_NX_START, 0); if (ret < 0) { - printf("nximage_initialize: Failed to start the NX server: %d\n", - errno); + printf("nximage_initialize: Failed to start the NX server: %d\n", errno); return ERROR; } @@ -109,53 +106,52 @@ static inline int nximage_initialize(void) g_nximage.hnx = nx_connect(); if (g_nximage.hnx) { - pthread_attr_t attr; + pthread_attr_t attr; #ifdef CONFIG_VNCSERVER /* Setup the VNC server to support keyboard/mouse inputs */ - struct boardioc_vncstart_s vnc = - { - 0, g_nximage.hnx - }; + struct boardioc_vncstart_s vnc = + { + 0, g_nximage.hnx + }; - ret = boardctl(BOARDIOC_VNC_START, (uintptr_t)&vnc); - if (ret < 0) - { - printf("boardctl(BOARDIOC_VNC_START) failed: %d\n", ret); - nx_disconnect(g_nximage.hnx); - return ERROR; - } + ret = boardctl(BOARDIOC_VNC_START, (uintptr_t)&vnc); + if (ret < 0) + { + printf("boardctl(BOARDIOC_VNC_START) failed: %d\n", ret); + nx_disconnect(g_nximage.hnx); + return ERROR; + } #endif - /* Start a separate thread to listen for server events. This is - * probably the least efficient way to do this, but it makes this - * example flow more smoothly. - */ + /* Start a separate thread to listen for server events. This is probably + * the least efficient way to do this, but it makes this example flow more + * smoothly. + */ - pthread_attr_init(&attr); - param.sched_priority = CONFIG_EXAMPLES_NXIMAGE_LISTENERPRIO; - pthread_attr_setschedparam(&attr, ¶m); - pthread_attr_setstacksize(&attr, - CONFIG_EXAMPLES_NXIMAGE_LISTENER_STACKSIZE); + pthread_attr_init(&attr); + param.sched_priority = CONFIG_EXAMPLES_NXIMAGE_LISTENERPRIO; + pthread_attr_setschedparam(&attr, ¶m); + pthread_attr_setstacksize(&attr, CONFIG_EXAMPLES_NXIMAGE_LISTENER_STACKSIZE); - ret = pthread_create(&thread, &attr, nximage_listener, NULL); - if (ret != 0) - { - printf("nximage_initialize: pthread_create failed: %d\n", ret); - return ERROR; - } + ret = pthread_create(&thread, &attr, nximage_listener, NULL); + if (ret != 0) + { + printf("nximage_initialize: pthread_create failed: %d\n", ret); + return ERROR; + } - /* Don't return until we are connected to the server */ + /* Don't return until we are connected to the server */ - while (!g_nximage.connected) - { - /* Wait for the listener thread to wake us up when we really - * are connected. - */ + while (!g_nximage.connected) + { + /* Wait for the listener thread to wake us up when we really + * are connected. + */ - sem_wait(&g_nximage.eventsem); - } + sem_wait(&g_nximage.eventsem); + } } else { @@ -196,7 +192,7 @@ int main(int argc, FAR char *argv[]) /* Set the background to the configured background color */ - color = nximage_bgcolor(); + color = nximage_bgcolor(); printf("nximage_main: Set background color=%u\n", color); ret = nx_setbgcolor(g_nximage.hnx, &color); @@ -224,8 +220,7 @@ int main(int argc, FAR char *argv[]) sem_wait(&g_nximage.eventsem); } - printf("nximage_main: Screen resolution (%d,%d)\n", - g_nximage.xres, g_nximage.yres); + printf("nximage_main: Screen resolution (%d,%d)\n", g_nximage.xres, g_nximage.yres); /* Now, put up the NuttX logo and wait a bit so that it visible. */ diff --git a/examples/nxlines/CMakeLists.txt b/examples/nxlines/CMakeLists.txt deleted file mode 100644 index 4ae6fc213..000000000 --- a/examples/nxlines/CMakeLists.txt +++ /dev/null @@ -1,36 +0,0 @@ -# ############################################################################## -# apps/examples/nxlines/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_NXLINES) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_NXLINES_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_NXLINES_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_NXLINES_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_NXLINES} - SRCS - nxlines_main.c) - target_sources(apps PRIVATE nxlines_bkgd.c nxlines_listener.c) -endif() diff --git a/examples/nxlines/Kconfig b/examples/nxlines/Kconfig index 8646fc1dc..7e44a868a 100644 --- a/examples/nxlines/Kconfig +++ b/examples/nxlines/Kconfig @@ -111,4 +111,10 @@ config EXAMPLES_NXLINES_LISTENERPRIO ---help--- The priority of the event listener thread. Default 80. +config EXAMPLES_NXLINES_NOTIFYSIGNO + int "Notify Signal Number" + default 4 + ---help--- + The signal number to use with nx_eventnotify(). Default: 4 + endif diff --git a/examples/nxlines/Make.defs b/examples/nxlines/Make.defs index bfdf33232..9f3337688 100644 --- a/examples/nxlines/Make.defs +++ b/examples/nxlines/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/nxlines/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/nxlines/Makefile b/examples/nxlines/Makefile index 836ffde06..14ae58a69 100644 --- a/examples/nxlines/Makefile +++ b/examples/nxlines/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/nxlines/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/nxlines/nxlines.h b/examples/nxlines/nxlines.h index 98993c25a..de925494b 100644 --- a/examples/nxlines/nxlines.h +++ b/examples/nxlines/nxlines.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/nxlines/nxlines.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -122,6 +120,9 @@ #ifndef CONFIG_EXAMPLES_NXLINES_SERVERPRIO # define CONFIG_EXAMPLES_NXLINES_SERVERPRIO 120 #endif +#ifndef CONFIG_EXAMPLES_NXLINES_NOTIFYSIGNO +# define CONFIG_EXAMPLES_NXLINES_NOTIFYSIGNO 4 +#endif /**************************************************************************** * Public Types diff --git a/examples/nxlines/nxlines_bkgd.c b/examples/nxlines/nxlines_bkgd.c index f3e3940fd..21a02458b 100644 --- a/examples/nxlines/nxlines_bkgd.c +++ b/examples/nxlines/nxlines_bkgd.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/nxlines/nxlines_bkgd.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -31,8 +29,7 @@ #include <stdlib.h> #include <unistd.h> #include <string.h> -#include <sys/param.h> -#include <nuttx/debug.h> +#include <debug.h> #include <fixedmath.h> #include <inttypes.h> @@ -55,6 +52,10 @@ # define CLEAR_WIDTH CONFIG_EXAMPLES_NXLINES_LINEWIDTH #endif +#ifndef MIN +# define MIN(a,b) (a < b ? a : b) +#endif + /**************************************************************************** * Private Types ****************************************************************************/ diff --git a/examples/nxlines/nxlines_listener.c b/examples/nxlines/nxlines_listener.c index ab1c25306..8bb4d9d94 100644 --- a/examples/nxlines/nxlines_listener.c +++ b/examples/nxlines/nxlines_listener.c @@ -1,7 +1,5 @@ /**************************************************************************** - * apps/examples/nxlines/nxlines_listener.c - * - * SPDX-License-Identifier: Apache-2.0 + * apps/examples/nxterm/nxlines_listener.c * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -48,7 +46,7 @@ FAR void *nxlines_listener(FAR void *arg) /* Process events forever */ - for (; ; ) + for (;;) { /* Handle the next event. If we were configured blocking, then * we will stay right here until the next event is received. Since diff --git a/examples/nxlines/nxlines_main.c b/examples/nxlines/nxlines_main.c index f13294fd0..8b6753b40 100644 --- a/examples/nxlines/nxlines_main.c +++ b/examples/nxlines/nxlines_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/nxlines/nxlines_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -36,7 +34,7 @@ #include <string.h> #include <sched.h> #include <errno.h> -#include <nuttx/debug.h> +#include <debug.h> #include <nuttx/arch.h> #include <nuttx/board.h> @@ -51,7 +49,6 @@ ****************************************************************************/ /* Configuration ************************************************************/ - /* If not specified, assume that the hardware supports one video plane */ #ifndef CONFIG_EXAMPLES_NXLINES_VPLANE @@ -112,7 +109,7 @@ static inline int nxlines_initialize(void) ret = sched_setparam(0, ¶m); if (ret < 0) { - printf("nxlines_initialize: sched_setparam failed: %d\n", ret); + printf("nxlines_initialize: sched_setparam failed: %d\n" , ret); return ERROR; } @@ -121,8 +118,7 @@ static inline int nxlines_initialize(void) ret = boardctl(BOARDIOC_NX_START, 0); if (ret < 0) { - printf("nxlines_initialize: Failed to start the NX server: %d\n", - errno); + printf("nxlines_initialize: Failed to start the NX server: %d\n", errno); return ERROR; } @@ -131,53 +127,52 @@ static inline int nxlines_initialize(void) g_nxlines.hnx = nx_connect(); if (g_nxlines.hnx) { - pthread_attr_t attr; + pthread_attr_t attr; #ifdef CONFIG_VNCSERVER /* Setup the VNC server to support keyboard/mouse inputs */ - struct boardioc_vncstart_s vnc = - { - 0, g_nxlines.hnx - }; + struct boardioc_vncstart_s vnc = + { + 0, g_nxlines.hnx + }; - ret = boardctl(BOARDIOC_VNC_START, (uintptr_t)&vnc); - if (ret < 0) - { - printf("boardctl(BOARDIOC_VNC_START) failed: %d\n", ret); - nx_disconnect(g_nxlines.hnx); - return ERROR; - } + ret = boardctl(BOARDIOC_VNC_START, (uintptr_t)&vnc); + if (ret < 0) + { + printf("boardctl(BOARDIOC_VNC_START) failed: %d\n", ret); + nx_disconnect(g_nxlines.hnx); + return ERROR; + } #endif - /* Start a separate thread to listen for server events. This is - * probably the least efficient way to do this, but it makes this - * example flow more smoothly. - */ + /* Start a separate thread to listen for server events. This is probably + * the least efficient way to do this, but it makes this example flow more + * smoothly. + */ - pthread_attr_init(&attr); - param.sched_priority = CONFIG_EXAMPLES_NXLINES_LISTENERPRIO; - pthread_attr_setschedparam(&attr, ¶m); - pthread_attr_setstacksize(&attr, - CONFIG_EXAMPLES_NXLINES_LISTENER_STACKSIZE); + pthread_attr_init(&attr); + param.sched_priority = CONFIG_EXAMPLES_NXLINES_LISTENERPRIO; + pthread_attr_setschedparam(&attr, ¶m); + pthread_attr_setstacksize(&attr, CONFIG_EXAMPLES_NXLINES_LISTENER_STACKSIZE); - ret = pthread_create(&thread, &attr, nxlines_listener, NULL); - if (ret != 0) - { - printf("nxlines_initialize: pthread_create failed: %d\n", ret); - return ERROR; - } + ret = pthread_create(&thread, &attr, nxlines_listener, NULL); + if (ret != 0) + { + printf("nxlines_initialize: pthread_create failed: %d\n", ret); + return ERROR; + } - /* Don't return until we are connected to the server */ + /* Don't return until we are connected to the server */ - while (!g_nxlines.connected) - { - /* Wait for the listener thread to wake us up when we really - * are connected. - */ + while (!g_nxlines.connected) + { + /* Wait for the listener thread to wake us up when we really + * are connected. + */ - sem_wait(&g_nxlines.eventsem); - } + sem_wait(&g_nxlines.eventsem); + } } else { @@ -243,8 +238,7 @@ int main(int argc, FAR char *argv[]) sem_wait(&g_nxlines.eventsem); } - printf("nxlines_main: Screen resolution (%d,%d)\n", - g_nxlines.xres, g_nxlines.yres); + printf("nxlines_main: Screen resolution (%d,%d)\n", g_nxlines.xres, g_nxlines.yres); /* Now, say perform the lines (these test does not return so the remaining * logic is cosmetic). diff --git a/examples/nxmbserver/CMakeLists.txt b/examples/nxmbserver/CMakeLists.txt deleted file mode 100644 index d6880be38..000000000 --- a/examples/nxmbserver/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# ############################################################################## -# apps/examples/nxmbserver/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_NXMBSERVER) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_NXMBSERVER_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_NXMBSERVER_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_NXMBSERVER_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_NXMBSERVER} - SRCS - nxmbserver_main.c) -endif() diff --git a/examples/nxmbserver/Kconfig b/examples/nxmbserver/Kconfig deleted file mode 100644 index 428f49c5e..000000000 --- a/examples/nxmbserver/Kconfig +++ /dev/null @@ -1,33 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config EXAMPLES_NXMBSERVER - tristate "NxModbus Server Example" - default n - depends on NXMODBUS_SERVER - ---help--- - Enable the NxModbus server example. This example demonstrates - how to create a Modbus server (slave) that responds to client - requests. Supports RTU, ASCII, and TCP transports with simulated - register data. - -if EXAMPLES_NXMBSERVER - -config EXAMPLES_NXMBSERVER_PROGNAME - string "Program name" - default "nxmbserver" - ---help--- - This is the name of the program that will be used when the NSH ELF - program is installed. - -config EXAMPLES_NXMBSERVER_PRIORITY - int "NxModbus server task priority" - default 100 - -config EXAMPLES_NXMBSERVER_STACKSIZE - int "NxModbus server stack size" - default DEFAULT_TASK_STACKSIZE - -endif # EXAMPLES_NXMBSERVER diff --git a/examples/nxmbserver/Make.defs b/examples/nxmbserver/Make.defs deleted file mode 100644 index 57fd777e7..000000000 --- a/examples/nxmbserver/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/examples/nxmbserver/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_EXAMPLES_NXMBSERVER),) -CONFIGURED_APPS += $(APPDIR)/examples/nxmbserver -endif diff --git a/examples/nxmbserver/Makefile b/examples/nxmbserver/Makefile deleted file mode 100644 index d3699d90b..000000000 --- a/examples/nxmbserver/Makefile +++ /dev/null @@ -1,32 +0,0 @@ -############################################################################ -# apps/examples/nxmbserver/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -MAINSRC = nxmbserver_main.c - -PROGNAME = $(CONFIG_EXAMPLES_NXMBSERVER_PROGNAME) -PRIORITY = $(CONFIG_EXAMPLES_NXMBSERVER_PRIORITY) -STACKSIZE = $(CONFIG_EXAMPLES_NXMBSERVER_STACKSIZE) -MODULE = $(CONFIG_EXAMPLES_NXMBSERVER) - -include $(APPDIR)/Application.mk diff --git a/examples/nxmbserver/nxmbserver_main.c b/examples/nxmbserver/nxmbserver_main.c deleted file mode 100644 index 8e8572dda..000000000 --- a/examples/nxmbserver/nxmbserver_main.c +++ /dev/null @@ -1,543 +0,0 @@ -/**************************************************************************** - * apps/examples/nxmbserver/nxmbserver_main.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <errno.h> -#include <signal.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> - -#include <nxmodbus/nxmodbus.h> - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define DEFAULT_UNIT_ID 1 -#define DEFAULT_TCP_PORT 502 -#define DEFAULT_BAUDRATE 19200 - -#define NUM_COILS 100 -#define NUM_DISCRETE 100 -#define NUM_INPUT_REGS 100 -#define NUM_HOLDING_REGS 100 - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/* Modbus type supported by example */ - -enum transport_type_e -{ - TRANSPORT_RTU = 0, - TRANSPORT_ASCII, - TRANSPORT_TCP -}; - -/* Modbus registers */ - -struct server_data_s -{ - uint8_t coils[NUM_COILS / 8 + 1]; - uint8_t discrete[NUM_DISCRETE / 8 + 1]; - uint16_t input_regs[NUM_INPUT_REGS]; - uint16_t holding_regs[NUM_HOLDING_REGS]; -}; - -/* Modbus server configuration */ - -struct server_config_s -{ - enum transport_type_e transport; - enum nxmb_parity_e parity; - FAR const char *device; - FAR const char *bindaddr; - uint32_t baudrate; - uint16_t port; - uint8_t unit_id; -}; - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static struct server_data_s g_data; -static volatile bool g_running = true; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: signal_handler - ****************************************************************************/ - -static void signal_handler(int signo) -{ - g_running = false; -} - -/**************************************************************************** - * Name: show_usage - ****************************************************************************/ - -static void show_usage(FAR const char *progname) -{ - printf("Usage: %s [OPTIONS]\n\n", progname); - printf("Transport Options:\n"); - printf(" -t TYPE Transport type: rtu, ascii, tcp (required)\n"); - printf(" -d DEVICE Serial device path (for RTU/ASCII)\n"); - printf(" -b BAUD Baud rate (default: %u)\n", DEFAULT_BAUDRATE); - printf(" -p PARITY Parity: none, even, odd (default: even)\n"); - printf(" -a ADDR Bind address (for TCP, default: 0.0.0.0)\n"); - printf(" -P PORT TCP port (default: %u)\n", DEFAULT_TCP_PORT); - printf("\nModbus Options:\n"); - printf(" -u UNIT Unit ID (default: %u)\n", DEFAULT_UNIT_ID); - printf("\nExample:\n"); - printf(" %s -t rtu -d /dev/ttyS1 -b 19200\n", progname); - printf(" %s -t tcp -P 502\n", progname); -} - -/**************************************************************************** - * Name: parse_parity - ****************************************************************************/ - -static int parse_parity(FAR const char *str, FAR enum nxmb_parity_e *parity) -{ - if (strcmp(str, "none") == 0) - { - *parity = NXMB_PAR_NONE; - } - else if (strcmp(str, "even") == 0) - { - *parity = NXMB_PAR_EVEN; - } - else if (strcmp(str, "odd") == 0) - { - *parity = NXMB_PAR_ODD; - } - else - { - return -EINVAL; - } - - return OK; -} - -/**************************************************************************** - * Name: parse_transport - ****************************************************************************/ - -static int parse_transport(FAR const char *str, - FAR enum transport_type_e *transport) -{ - if (strcmp(str, "rtu") == 0) - { - *transport = TRANSPORT_RTU; - } - else if (strcmp(str, "ascii") == 0) - { - *transport = TRANSPORT_ASCII; - } - else if (strcmp(str, "tcp") == 0) - { - *transport = TRANSPORT_TCP; - } - else - { - return -EINVAL; - } - - return OK; -} - -/**************************************************************************** - * Name: coils_callback - ****************************************************************************/ - -static int coils_callback(FAR uint8_t *buf, uint16_t addr, uint16_t count, - enum nxmb_regmode_e mode, FAR void *priv) -{ - uint16_t byte_idx; - uint16_t bit_idx; - uint16_t i; - - if (addr + count > NUM_COILS) - { - return -ENOENT; - } - - if (mode == NXMB_REG_READ) - { - for (i = 0; i < count; i++) - { - byte_idx = (addr + i) / 8; - bit_idx = (addr + i) % 8; - - if (g_data.coils[byte_idx] & (1 << bit_idx)) - { - buf[i / 8] |= (1 << (i % 8)); - } - else - { - buf[i / 8] &= ~(1 << (i % 8)); - } - } - } - else - { - for (i = 0; i < count; i++) - { - byte_idx = (addr + i) / 8; - bit_idx = (addr + i) % 8; - - if (buf[i / 8] & (1 << (i % 8))) - { - g_data.coils[byte_idx] |= (1 << bit_idx); - } - else - { - g_data.coils[byte_idx] &= ~(1 << bit_idx); - } - } - } - - return OK; -} - -/**************************************************************************** - * Name: discrete_callback - ****************************************************************************/ - -static int discrete_callback(FAR uint8_t *buf, uint16_t addr, - uint16_t count, FAR void *priv) -{ - uint16_t byte_idx; - uint16_t bit_idx; - uint16_t i; - - if (addr + count > NUM_DISCRETE) - { - return -ENOENT; - } - - for (i = 0; i < count; i++) - { - byte_idx = (addr + i) / 8; - bit_idx = (addr + i) % 8; - - if (g_data.discrete[byte_idx] & (1 << bit_idx)) - { - buf[i / 8] |= (1 << (i % 8)); - } - else - { - buf[i / 8] &= ~(1 << (i % 8)); - } - } - - return OK; -} - -/**************************************************************************** - * Name: input_callback - ****************************************************************************/ - -static int input_callback(FAR uint8_t *buf, uint16_t addr, uint16_t count, - FAR void *priv) -{ - uint16_t i; - - if (addr + count > NUM_INPUT_REGS) - { - return -ENOENT; - } - - for (i = 0; i < count; i++) - { - buf[i * 2] = (uint8_t)(g_data.input_regs[addr + i] >> 8); - buf[i * 2 + 1] = (uint8_t)(g_data.input_regs[addr + i] & 0xff); - } - - return OK; -} - -/**************************************************************************** - * Name: holding_callback - ****************************************************************************/ - -static int holding_callback(FAR uint8_t *buf, uint16_t addr, uint16_t count, - enum nxmb_regmode_e mode, FAR void *priv) -{ - uint16_t i; - - if (addr + count > NUM_HOLDING_REGS) - { - return -ENOENT; - } - - if (mode == NXMB_REG_READ) - { - for (i = 0; i < count; i++) - { - buf[i * 2] = (uint8_t)(g_data.holding_regs[addr + i] >> 8); - buf[i * 2 + 1] = (uint8_t)(g_data.holding_regs[addr + i] & 0xff); - } - } - else - { - for (i = 0; i < count; i++) - { - g_data.holding_regs[addr + i] = - (uint16_t)(buf[i * 2] << 8) | (uint16_t)buf[i * 2 + 1]; - } - } - - return OK; -} - -/**************************************************************************** - * Name: init_data - ****************************************************************************/ - -static void init_data(void) -{ - uint16_t i; - - memset(&g_data, 0, sizeof(g_data)); - - for (i = 0; i < NUM_INPUT_REGS; i++) - { - g_data.input_regs[i] = i * 10; - } - - for (i = 0; i < NUM_HOLDING_REGS; i++) - { - g_data.holding_regs[i] = i * 100; - } -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: nxmbserver_main - ****************************************************************************/ - -int main(int argc, FAR char *argv[]) -{ - struct server_config_s config; - struct nxmb_config_s mb_config; - struct nxmb_callbacks_s callbacks; - nxmb_handle_t handle; - bool transport_set = false; - int option; - int ret; - - /* Default config */ - - memset(&config, 0, sizeof(config)); - config.baudrate = DEFAULT_BAUDRATE; - config.parity = NXMB_PAR_EVEN; - config.port = DEFAULT_TCP_PORT; - config.unit_id = DEFAULT_UNIT_ID; - - /* Handle CLI */ - - while ((option = getopt(argc, argv, "t:d:b:p:a:P:u:h")) != -1) - { - switch (option) - { - case 't': - if (parse_transport(optarg, &config.transport) < 0) - { - fprintf(stderr, "Error: invalid transport '%s'\n", optarg); - return EXIT_FAILURE; - } - - transport_set = true; - break; - - case 'd': - config.device = optarg; - break; - - case 'b': - config.baudrate = (uint32_t)strtoul(optarg, NULL, 0); - break; - - case 'p': - if (parse_parity(optarg, &config.parity) < 0) - { - fprintf(stderr, "Error: invalid parity '%s'\n", optarg); - return EXIT_FAILURE; - } - - break; - - case 'a': - config.bindaddr = optarg; - break; - - case 'P': - config.port = (uint16_t)strtoul(optarg, NULL, 0); - break; - - case 'u': - config.unit_id = (uint8_t)strtoul(optarg, NULL, 0); - break; - - case 'h': - default: - show_usage(argv[0]); - return (option == 'h') ? EXIT_SUCCESS : EXIT_FAILURE; - } - } - - /* Validate input */ - - if (!transport_set) - { - fprintf(stderr, "Error: transport type (-t) is required\n\n"); - show_usage(argv[0]); - return EXIT_FAILURE; - } - - if ((config.transport == TRANSPORT_RTU || - config.transport == TRANSPORT_ASCII) && - config.device == NULL) - { - fprintf(stderr, "Error: device path (-d) required for RTU/ASCII\n"); - return EXIT_FAILURE; - } - - /* Connect signals */ - - signal(SIGINT, signal_handler); - signal(SIGTERM, signal_handler); - - /* Init modbus data */ - - init_data(); - - /* Init modbus stack */ - - memset(&callbacks, 0, sizeof(callbacks)); - callbacks.coil_cb = coils_callback; - callbacks.discrete_cb = discrete_callback; - callbacks.input_cb = input_callback; - callbacks.holding_cb = holding_callback; - - memset(&mb_config, 0, sizeof(mb_config)); - mb_config.unit_id = config.unit_id; - mb_config.is_client = false; - - switch (config.transport) - { - case TRANSPORT_RTU: - mb_config.mode = NXMB_MODE_RTU; - mb_config.transport.serial.devpath = config.device; - mb_config.transport.serial.baudrate = config.baudrate; - mb_config.transport.serial.parity = config.parity; - printf("Starting Modbus RTU server on %s (baud=%" PRId32 - ", unit=%u)\n", config.device, config.baudrate, - config.unit_id); - break; - - case TRANSPORT_ASCII: - mb_config.mode = NXMB_MODE_ASCII; - mb_config.transport.serial.devpath = config.device; - mb_config.transport.serial.baudrate = config.baudrate; - mb_config.transport.serial.parity = config.parity; - printf("Starting Modbus ASCII server on %s (baud=%" PRId32 - ", unit=%u)\n", config.device, config.baudrate, - config.unit_id); - break; - - case TRANSPORT_TCP: - mb_config.mode = NXMB_MODE_TCP; - mb_config.transport.tcp.port = config.port; - mb_config.transport.tcp.bindaddr = config.bindaddr; - printf("Starting Modbus TCP server on port %u (unit=%u)\n", - config.port, config.unit_id); - break; - } - - ret = nxmb_create(&handle, &mb_config); - if (ret < 0) - { - fprintf(stderr, "Error: failed to create Modbus context: %d\n", ret); - return EXIT_FAILURE; - } - - ret = nxmb_set_callbacks(handle, &callbacks); - if (ret < 0) - { - fprintf(stderr, "Error: failed to set callbacks: %d\n", ret); - nxmb_destroy(handle); - return EXIT_FAILURE; - } - - ret = nxmb_enable(handle); - if (ret < 0) - { - fprintf(stderr, "Error: failed to enable context: %d\n", ret); - nxmb_destroy(handle); - return EXIT_FAILURE; - } - - printf("Server running. Press Ctrl+C to stop.\n"); - printf("Register map:\n"); - printf(" Coils: 1-%d (read/write)\n", NUM_COILS); - printf(" Discrete: 1-%d (read-only)\n", NUM_DISCRETE); - printf(" Input regs: 1-%d (read-only, value=addr*10)\n", - NUM_INPUT_REGS); - printf(" Holding regs: 1-%d (read/write, initial=addr*100)\n", - NUM_HOLDING_REGS); - - /* Poll loop */ - - while (g_running) - { - ret = nxmb_poll(handle); - if (ret < 0 && ret != -EAGAIN) - { - fprintf(stderr, "Error: poll failed: %d\n", ret); - break; - } - } - - printf("\nShutting down...\n"); - nxmb_disable(handle); - nxmb_destroy(handle); - - return EXIT_SUCCESS; -} diff --git a/examples/nxscope/CMakeLists.txt b/examples/nxscope/CMakeLists.txt deleted file mode 100644 index 09f9b8e16..000000000 --- a/examples/nxscope/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -############################################################################ -# apps/examples/nxscope/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -if(CONFIG_EXAMPLES_NXSCOPE) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_NXSCOPE_PROGNAME} - SRCS - nxscope_main.c - STACKSIZE - ${CONFIG_EXAMPLES_NXSCOPE_STACKSIZE} - PRIORITY - ${CONFIG_EXAMPLES_NXSCOPE_PRIORITY}) -endif() diff --git a/examples/nxscope/Kconfig b/examples/nxscope/Kconfig deleted file mode 100644 index 49d36f270..000000000 --- a/examples/nxscope/Kconfig +++ /dev/null @@ -1,107 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config EXAMPLES_NXSCOPE - tristate "nxscope example" - default n - depends on LOGGING_NXSCOPE - ---help--- - Enable the nxscope example - -if EXAMPLES_NXSCOPE - -config EXAMPLES_NXSCOPE_PROGNAME - string "Program name" - default "nxscope" - -config EXAMPLES_NXSCOPE_PRIORITY - int "nxscope task priority" - default 100 - -config EXAMPLES_NXSCOPE_STACKSIZE - int "nxscope stack size" - default DEFAULT_TASK_STACKSIZE - -if LOGGING_NXSCOPE_INTF_SERIAL - -config EXAMPLES_NXSCOPE_SERIAL_PATH - string "nxscope serial path" - default "/dev/ttyUSB0" - -config EXAMPLES_NXSCOPE_SERIAL_BAUD - int "nxscope serial baud" - default 115200 - ---help--- - Ignored if set to 0 (for example for RTT interface) - -config EXAMPLES_NXSCOPE_CDCACM - bool "nxscope CDCACM device support" - depends on CDCACM - default n - -endif # LOGGING_NXSCOPE_INTF_SERIAL - -if LOGGING_NXSCOPE_INTF_UDP - -config EXAMPLES_NXSCOPE_UDP_PORT - int "nxscope UDP local port" - default 50000 - range 1 65535 - -endif # LOGGING_NXSCOPE_INTF_UDP - -config EXAMPLES_NXSCOPE_FORCE_ENABLE - bool "nxscope force enable" - default n - -config EXAMPLES_NXSCOPE_STREAMBUF_LEN - int "nxscope stream buffer length" - default 512 - -config EXAMPLES_NXSCOPE_RXBUF_LEN - int "nxscope RX buffer length" - default 32 - -config EXAMPLES_NXSCOPE_CHARLOG - bool "nxscope send text message over channel 19" - default n - -config EXAMPLES_NXSCOPE_CRIBUF_LEN - int "nxscope critical channels buffer length" - default 32 - depends on LOGGING_NXSCOPE_CRICHANNELS - -config EXAMPLES_NXSCOPE_RX_PADDING - int "nxscope RX padding" - default 0 - -config EXAMPLES_NXSCOPE_TIMER - bool "nxscope use timer to wake up samples thread" - default n - -config EXAMPLES_NXSCOPE_MAIN_INTERVAL - int "nxscope main interval (microseconds)" - default 100000 - ---help--- - This value is responsible for the frequency at which stream - frames will be sent and incoming frames will be received. - -if EXAMPLES_NXSCOPE_TIMER - -config EXAMPLES_NXSCOPE_TIMER_PATH - string "nxscope timer path" - default "/dev/timer0" - -config EXAMPLES_NXSCOPE_TIMER_SIGNO - int "nxscope notification signal number" - default 32 - -config EXAMPLES_NXSCOPE_TIMER_INTERVAL - int "nxscope timer interval (microseconds)" - default 100 - -endif # EXAMPLES_NXSCOPE_TIMER - -endif diff --git a/examples/nxscope/Make.defs b/examples/nxscope/Make.defs deleted file mode 100644 index 0e1689875..000000000 --- a/examples/nxscope/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/examples/nxscope/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_EXAMPLES_NXSCOPE),) -CONFIGURED_APPS += $(APPDIR)/examples/nxscope -endif diff --git a/examples/nxscope/Makefile b/examples/nxscope/Makefile deleted file mode 100644 index d9f4029a1..000000000 --- a/examples/nxscope/Makefile +++ /dev/null @@ -1,38 +0,0 @@ -############################################################################ -# apps/examples/nxscope/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -# nxscope built-in application info - -PROGNAME = $(CONFIG_EXAMPLES_NXSCOPE_PROGNAME) -PRIORITY = $(CONFIG_EXAMPLES_NXSCOPE_PRIORITY) -STACKSIZE = $(CONFIG_EXAMPLES_NXSCOPE_STACKSIZE) -MODULE = $(CONFIG_EXAMPLES_NXSCOPE) - -# NxScope example - -MAINSRC = nxscope_main.c - -CSRCS = - -include $(APPDIR)/Application.mk diff --git a/examples/nxscope/nxscope_main.c b/examples/nxscope/nxscope_main.c deleted file mode 100644 index ba0a3c226..000000000 --- a/examples/nxscope/nxscope_main.c +++ /dev/null @@ -1,852 +0,0 @@ -/**************************************************************************** - * apps/examples/nxscope/nxscope_main.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <sys/boardctl.h> - -#include <assert.h> -#include <errno.h> -#include <getopt.h> -#include <pthread.h> -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <math.h> - -#ifdef CONFIG_EXAMPLES_NXSCOPE_TIMER -# include <sys/ioctl.h> -# include <fcntl.h> -# include <signal.h> -# include <nuttx/timers/timer.h> -#endif - -#include "logging/nxscope/nxscope.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#ifdef CONFIG_LIBM_NONE -# error "math library must be selected for this example" -#endif - -#define SIN_DT (0.01f) -#define STREAM_THREAD_USLEP 100 - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -struct nxscope_thr_env_s -{ - FAR struct nxscope_s *nxs; - int interval; -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: nxscope_cb_userid - ****************************************************************************/ - -static int nxscope_cb_userid(FAR void *priv, uint8_t id, FAR uint8_t *buff) -{ - UNUSED(priv); - - printf("--> nxscope_cb_userid: id=%d\n", id); - - return OK; -} - -/**************************************************************************** - * Name: nxscope_cb_start - ****************************************************************************/ - -static int nxscope_cb_start(FAR void *priv, bool start) -{ - UNUSED(priv); - - printf("--> nxscope_cb_start: start=%d\n", start); - - return OK; -} - -/**************************************************************************** - * Name: nxscope_show_usage - ****************************************************************************/ - -static void nxscope_show_usage(FAR const char *progname) -{ - printf("Usage: %s [-i <stream_interval_us>]\n", progname); - printf(" [-m <main_interval_us>]\n"); -} - -/**************************************************************************** - * Name: nxscope_parse_args - ****************************************************************************/ - -static int nxscope_parse_args(int argc, FAR char *argv[], - FAR int *stream_interval, - FAR int *main_interval) -{ - unsigned long value = 0; - int opt = 0; - - DEBUGASSERT(argv); - DEBUGASSERT(stream_interval); - DEBUGASSERT(main_interval); - - while ((opt = getopt(argc, argv, "i:m:")) != -1) - { - switch (opt) - { - case 'i': - { - value = strtoul(optarg, NULL, 10); - if (value == 0) - { - printf("ERROR: invalid interval: %s\n", optarg); - return -EINVAL; - } - - *stream_interval = (int)value; - break; - } - - case 'm': - { - value = strtoul(optarg, NULL, 10); - if (value == 0) - { - printf("ERROR: invalid interval: %s\n", optarg); - return -EINVAL; - } - - *main_interval = (int)value; - break; - } - - default: - printf("ERROR: unsupported argument\n"); - return -EINVAL; - } - } - - return OK; -} - -#ifdef CONFIG_EXAMPLES_NXSCOPE_TIMER -/**************************************************************************** - * Name: nxscope_timer_init - ****************************************************************************/ - -static int nxscope_timer_init(int interval_us) -{ - int fd = 0; - int ret = 0; - struct timer_notify_s notify; - - /* Open the timer driver */ - - fd = open(CONFIG_EXAMPLES_NXSCOPE_TIMER_PATH, O_RDONLY); - if (fd < 0) - { - printf("ERROR: Failed to open %s: %d\n", - CONFIG_EXAMPLES_NXSCOPE_TIMER_PATH, errno); - goto errout; - } - - /* Set the timer interval */ - - ret = ioctl(fd, TCIOC_SETTIMEOUT, interval_us); - if (ret < 0) - { - printf("ERROR: Failed to set the timer interval: %d\n", errno); - goto errout; - } - - /* Configure the timer notifier */ - - notify.pid = getpid(); - notify.periodic = true; - - notify.event.sigev_notify = SIGEV_SIGNAL; - notify.event.sigev_signo = CONFIG_EXAMPLES_NXSCOPE_TIMER_SIGNO; - notify.event.sigev_value.sival_ptr = NULL; - - ret = ioctl(fd, TCIOC_NOTIFICATION, - (unsigned long)((uintptr_t)¬ify)); - if (ret < 0) - { - printf("ERROR: Failed to set the timer handler: %d\n", errno); - goto errout; - } - - /* Start the timer */ - - ret = ioctl(fd, TCIOC_START, 0); - if (ret < 0) - { - printf("ERROR: Failed to start the timer: %d\n", errno); - goto errout; - } - -errout: - return fd; -} - -/**************************************************************************** - * Name: nxscope_timer_deinit - ****************************************************************************/ - -static void nxscope_timer_deinit(int fd) -{ - int ret = 0; - - /* Stop the timer */ - - ret = ioctl(fd, TCIOC_STOP, 0); - if (ret < 0) - { - printf("ERROR: Failed to stop the timer: %d\n", errno); - } - - close(fd); -} -#endif - -/**************************************************************************** - * Name: nxscope_samples_thr - ****************************************************************************/ - -static FAR void *nxscope_samples_thr(FAR void *arg) -{ - FAR struct nxscope_thr_env_s *envp = arg; - FAR uint8_t *ptr = NULL; - uint32_t i = 0; - float v[3]; -#ifdef CONFIG_EXAMPLES_NXSCOPE_TIMER - int fd_timer = 0; - int ret = OK; - sigset_t set; -#endif - - DEBUGASSERT(envp); - - printf("nxscope_samples_thr\n"); - -#ifdef CONFIG_EXAMPLES_NXSCOPE_TIMER - /* Initialize timer for periodic signal. */ - - ret = nxscope_timer_init(envp->interval); - if (ret < 0) - { - printf("ERROR: nxscope_timer_init() failed: %d\n", errno); - goto errout; - } - - /* Configure the signal set for this thread */ - - sigemptyset(&set); - sigaddset(&set, CONFIG_EXAMPLES_NXSCOPE_TIMER_SIGNO); -#endif - - while (1) - { - /* Float vector - tree-phase sine waveform */ - - v[0] = sinf(i * SIN_DT); - v[1] = sinf(i * SIN_DT + (2.0f / 3.0f) * M_PI); - v[2] = sinf(i * SIN_DT + (4.0f / 3.0f) * M_PI); - - /* Channel 0 */ - - nxscope_put_uint8(envp->nxs, 0, i); - - /* Channel 1 */ - - nxscope_put_int8(envp->nxs, 1, -1); - - /* Channel 2 */ - - nxscope_put_uint16(envp->nxs, 2, 300); - - /* Channel 3 */ - - nxscope_put_int16(envp->nxs, 3, -300); - - /* Channel 4 */ - - nxscope_put_uint32(envp->nxs, 4, 35000); - - /* Channel 5 */ - - nxscope_put_int32(envp->nxs, 5, -35000); - - /* Channel 6 */ - - nxscope_put_uint64(envp->nxs, 6, 4294967296); - - /* Channel 7 */ - - nxscope_put_int64(envp->nxs, 7, -4294967296); - - /* Channel 8 */ - - nxscope_put_float(envp->nxs, 8, 1.0f); - - /* Channel 9 */ - - nxscope_put_double(envp->nxs, 9, 1.11111111); - - /* Channel 10 */ - - nxscope_put_ub8(envp->nxs, 10, ftob8(1.0f)); - - /* Channel 11 */ - - nxscope_put_b8(envp->nxs, 11, ftob8(-1.0f)); - - /* Channel 12 */ - - nxscope_put_ub16(envp->nxs, 12, ftob16(1.0f)); - - /* Channel 13 */ - - nxscope_put_b16(envp->nxs, 13, ftob16(-1.0f)); - - /* Channel 14 */ - - nxscope_put_ub32(envp->nxs, 14, dtob32(1.0)); - - /* Channel 15 */ - - nxscope_put_b32(envp->nxs, 15, dtob32(-1.0)); - - /* Channel 16 */ - - nxscope_put_vfloat(envp->nxs, 16, v, 3); - - /* Channel 17 */ - - ptr = (FAR uint8_t *) &i; - nxscope_put_vfloat_m(envp->nxs, 17, v, 3, ptr, sizeof(uint32_t)); - - /* Channel 18 */ - - nxscope_put_none_m(envp->nxs, 18, ptr, sizeof(uint32_t)); - - i += 1; - -#ifdef CONFIG_EXAMPLES_NXSCOPE_TIMER - ret = sigwaitinfo(&set, NULL); - if (ret < 0) - { - printf("ERROR: sigwaitinfo() failed: %d\n", errno); - goto errout; - } -#else - usleep(envp->interval); -#endif - } - -#ifdef CONFIG_EXAMPLES_NXSCOPE_TIMER -errout: - - /* Deinit timer */ - - nxscope_timer_deinit(fd_timer); -#endif - - return NULL; -} - -#ifdef CONFIG_EXAMPLES_NXSCOPE_CHARLOG -/**************************************************************************** - * Name: nxscope_charlog_thr - ****************************************************************************/ - -static FAR void *nxscope_charlog_thr(FAR void *arg) -{ - FAR struct nxscope_thr_env_s *envp = arg; - int i = 0; - - DEBUGASSERT(envp); - - printf("nxscope_charlog_thr\n"); - - while (1) - { - /* Channel 19 - send hello with metadata */ - - nxscope_put_vchar_m(envp->nxs, 19, "hello", 64, - (FAR uint8_t *)&i, sizeof(int)); - - i += 1; - - usleep(100000); - } - - return NULL; -} -#endif - -#ifdef CONFIG_LOGGING_NXSCOPE_CRICHANNELS -/**************************************************************************** - * Name: nxscope_crichan_thr - ****************************************************************************/ - -static FAR void *nxscope_crichan_thr(FAR void *arg) -{ - FAR struct nxscope_thr_env_s *envp = arg; - uint8_t i = 0; - - DEBUGASSERT(envp); - - printf("nxscope_crichan_thr\n"); - - while (1) - { - /* Channel 20 */ - - nxscope_put_uint8(envp->nxs, 20, i); - - i += 1; - - usleep(100000); - } - - return NULL; -} -#endif - -#ifdef CONFIG_EXAMPLES_NXSCOPE_CDCACM -/**************************************************************************** - * Name: nxscope_cdcacm_init - ****************************************************************************/ - -static int nxscope_cdcacm_init(void) -{ - struct boardioc_usbdev_ctrl_s ctrl; - FAR void *handle; - int ret = OK; - - ctrl.usbdev = BOARDIOC_USBDEV_CDCACM; - ctrl.action = BOARDIOC_USBDEV_CONNECT; - ctrl.instance = 0; - ctrl.handle = &handle; - - ret = boardctl(BOARDIOC_USBDEV_CONTROL, (uintptr_t)&ctrl); - if (ret < 0) - { - printf("ERROR: BOARDIOC_USBDEV_CONTROL failed %d\n", ret); - goto errout; - } - -errout: - return ret; -} -#endif - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: nxscope_main - ****************************************************************************/ - -int main(int argc, FAR char *argv[]) -{ - struct nxscope_s nxs; - int ret = OK; - int interval; - pthread_t thread; - struct nxscope_thr_env_s env; - struct nxscope_cfg_s nxs_cfg; - union nxscope_chinfo_type_u u; - struct nxscope_intf_s intf; - struct nxscope_proto_s proto; - struct nxscope_callbacks_s cbs; -#ifdef CONFIG_LOGGING_NXSCOPE_INTF_SERIAL - struct nxscope_ser_cfg_s nxs_ser_cfg; -#endif -#ifdef CONFIG_LOGGING_NXSCOPE_INTF_UDP - struct nxscope_udp_cfg_s nxs_udp_cfg; -#endif -#ifdef CONFIG_LOGGING_NXSCOPE_INTF_DUMMY - struct nxscope_dummy_cfg_s nxs_dummy_cfg; -#endif - - /* Default settings */ - - interval = CONFIG_EXAMPLES_NXSCOPE_MAIN_INTERVAL; -#ifdef CONFIG_EXAMPLES_NXSCOPE_TIMER - env.interval = CONFIG_EXAMPLES_NXSCOPE_TIMER_INTERVAL; -#else - env.interval = STREAM_THREAD_USLEP; -#endif - - /* Parse args */ - - ret = nxscope_parse_args(argc, argv, &env.interval, &interval); - if (ret < 0) - { - nxscope_show_usage(argv[0]); - return EXIT_FAILURE; - } - - printf("stream interval = %d\n", env.interval); - printf("main interval = %d\n", interval); - -#ifdef CONFIG_BOARDCTL_FINALINIT - /* Perform architecture-specific final-initialization (if configured) */ - - boardctl(BOARDIOC_FINALINIT, 0); -#endif - -#ifdef CONFIG_EXAMPLES_NXSCOPE_CDCACM - /* Initialize the USB CDCACM device */ - - ret = nxscope_cdcacm_init(); - if (ret < 0) - { - printf("ERROR: nxscope_cdcacm_init failed %d\n", ret); - goto errout_noproto; - } -#endif - - /* Default serial protocol */ - - ret = nxscope_proto_ser_init(&proto, NULL); - if (ret < 0) - { - printf("ERROR: nxscope_proto_ser_init failed %d\n", ret); - goto errout_noproto; - } - -#ifdef CONFIG_LOGGING_NXSCOPE_INTF_SERIAL - /* Configuration */ - - nxs_ser_cfg.path = CONFIG_EXAMPLES_NXSCOPE_SERIAL_PATH; - nxs_ser_cfg.nonblock = true; - nxs_ser_cfg.baud = CONFIG_EXAMPLES_NXSCOPE_SERIAL_BAUD; - - /* Initialize serial interface */ - - ret = nxscope_ser_init(&intf, &nxs_ser_cfg); - if (ret < 0) - { - printf("ERROR: nxscope_ser_init failed %d\n", ret); - goto errout_nointf; - } -#endif - -#ifdef CONFIG_LOGGING_NXSCOPE_INTF_UDP - /* Configuration */ - - nxs_udp_cfg.port = CONFIG_EXAMPLES_NXSCOPE_UDP_PORT; - nxs_udp_cfg.nonblock = true; - - /* Initialize UDP interface */ - - ret = nxscope_udp_init(&intf, &nxs_udp_cfg); - if (ret < 0) - { - printf("ERROR: nxscope_udp_init failed %d\n", ret); - goto errout_nointf; - } -#endif - -#ifdef CONFIG_LOGGING_NXSCOPE_INTF_DUMMY - /* Configuration */ - - nxs_dummy_cfg.res = 0; - - /* Initialize dummy interface */ - - ret = nxscope_dummy_init(&intf, &nxs_dummy_cfg); - if (ret < 0) - { - printf("ERROR: nxscope_dummy_init failed %d\n", ret); - goto errout_nointf; - } -#endif - - /* Connect callbacks */ - - cbs.userid_priv = NULL; - cbs.userid = nxscope_cb_userid; - - cbs.start_priv = NULL; - cbs.start = nxscope_cb_start; - - /* Initialize nxscope */ - - nxs_cfg.intf_cmd = &intf; - nxs_cfg.intf_stream = &intf; - nxs_cfg.proto_cmd = &proto; - nxs_cfg.proto_stream = &proto; - nxs_cfg.callbacks = &cbs; - nxs_cfg.channels = 32; - nxs_cfg.streambuf_len = CONFIG_EXAMPLES_NXSCOPE_STREAMBUF_LEN; - nxs_cfg.rxbuf_len = CONFIG_EXAMPLES_NXSCOPE_RXBUF_LEN; -#ifdef CONFIG_LOGGING_NXSCOPE_CRICHANNELS - nxs_cfg.cribuf_len = CONFIG_EXAMPLES_NXSCOPE_CRIBUF_LEN; -#endif - nxs_cfg.rx_padding = CONFIG_EXAMPLES_NXSCOPE_RX_PADDING; - - ret = nxscope_init(&nxs, &nxs_cfg); - if (ret < 0) - { - printf("ERROR: nxscope_init failed %d\n", ret); - goto errout_nonxscope; - } - - /* Create channels */ - - /* Point data channels */ - - u.s.dtype = NXSCOPE_TYPE_UINT8; - u.s._res = 0; - u.s.cri = 0; - nxscope_chan_init(&nxs, 0, "chan0", u.u8, 1, 0); - - u.s.dtype = NXSCOPE_TYPE_INT8; - u.s._res = 0; - u.s.cri = 0; - nxscope_chan_init(&nxs, 1, "chan1", u.u8, 1, 0); - - u.s.dtype = NXSCOPE_TYPE_UINT16; - u.s._res = 0; - u.s.cri = 0; - nxscope_chan_init(&nxs, 2, "chan2", u.u8, 1, 0); - - u.s.dtype = NXSCOPE_TYPE_INT16; - u.s._res = 0; - u.s.cri = 0; - nxscope_chan_init(&nxs, 3, "chan3", u.u8, 1, 0); - - u.s.dtype = NXSCOPE_TYPE_UINT32; - u.s._res = 0; - u.s.cri = 0; - nxscope_chan_init(&nxs, 4, "chan4", u.u8, 1, 0); - - u.s.dtype = NXSCOPE_TYPE_INT32; - u.s._res = 0; - u.s.cri = 0; - nxscope_chan_init(&nxs, 5, "chan5", u.u8, 1, 0); - - u.s.dtype = NXSCOPE_TYPE_UINT64; - u.s._res = 0; - u.s.cri = 0; - nxscope_chan_init(&nxs, 6, "chan6", u.u8, 1, 0); - - u.s.dtype = NXSCOPE_TYPE_INT64; - u.s._res = 0; - u.s.cri = 0; - nxscope_chan_init(&nxs, 7, "chan7", u.u8, 1, 0); - - u.s.dtype = NXSCOPE_TYPE_FLOAT; - u.s._res = 0; - u.s.cri = 0; - nxscope_chan_init(&nxs, 8, "chan8", u.u8, 1, 0); - - u.s.dtype = NXSCOPE_TYPE_DOUBLE; - u.s._res = 0; - u.s.cri = 0; - nxscope_chan_init(&nxs, 9, "chan9", u.u8, 1, 0); - - u.s.dtype = NXSCOPE_TYPE_UB8; - u.s._res = 0; - u.s.cri = 0; - nxscope_chan_init(&nxs, 10, "chan10", u.u8, 1, 0); - - u.s.dtype = NXSCOPE_TYPE_B8; - u.s._res = 0; - u.s.cri = 0; - nxscope_chan_init(&nxs, 11, "chan11", u.u8, 1, 0); - - u.s.dtype = NXSCOPE_TYPE_UB16; - u.s._res = 0; - u.s.cri = 0; - nxscope_chan_init(&nxs, 12, "chan12", u.u8, 1, 0); - - u.s.dtype = NXSCOPE_TYPE_B16; - u.s._res = 0; - u.s.cri = 0; - nxscope_chan_init(&nxs, 13, "chan13", u.u8, 1, 0); - - u.s.dtype = NXSCOPE_TYPE_UB32; - u.s._res = 0; - u.s.cri = 0; - nxscope_chan_init(&nxs, 14, "chan14", u.u8, 1, 0); - - u.s.dtype = NXSCOPE_TYPE_B32; - u.s._res = 0; - u.s.cri = 0; - nxscope_chan_init(&nxs, 15, "chan15", u.u8, 1, 0); - - /* Vector data channel */ - - u.s.dtype = NXSCOPE_TYPE_FLOAT; - u.s._res = 0; - u.s.cri = 0; - nxscope_chan_init(&nxs, 16, "chan16", u.u8, 3, 0); - - /* Vector data channel with metadata */ - - u.s.dtype = NXSCOPE_TYPE_FLOAT; - u.s._res = 0; - u.s.cri = 0; - nxscope_chan_init(&nxs, 17, "chan17", u.u8, 3, 4); - - /* No-data channel with metadata */ - - u.s.dtype = NXSCOPE_TYPE_NONE; - u.s._res = 0; - u.s.cri = 0; - nxscope_chan_init(&nxs, 18, "chan18", u.u8, 0, 4); - -#ifdef CONFIG_EXAMPLES_NXSCOPE_CHARLOG - /* Char channel with metadata */ - - u.s.dtype = NXSCOPE_TYPE_CHAR; - u.s._res = 0; - u.s.cri = 0; - nxscope_chan_init(&nxs, 19, "chan19", u.u8, 64, 4); -#endif - -#ifdef CONFIG_LOGGING_NXSCOPE_CRICHANNELS - /* Critical channel */ - - u.s.dtype = NXSCOPE_TYPE_UINT8; - u.s._res = 0; - u.s.cri = 1; - nxscope_chan_init(&nxs, 20, "chan20c", u.u8, 1, 0); -#endif - - /* Channels 20-31: reserved for future use */ - - /* Create samples thread */ - - env.nxs = &nxs; - ret = pthread_create(&thread, NULL, nxscope_samples_thr, &env); - if (ret != OK) - { - printf("ERROR: pthread_create failed %d\n", ret); - goto errout; - } - -#ifdef CONFIG_EXAMPLES_NXSCOPE_CHARLOG - /* Create char log thread */ - - env.nxs = &nxs; - ret = pthread_create(&thread, NULL, nxscope_charlog_thr, &env); - if (ret != OK) - { - printf("ERROR: pthread_create failed %d\n", ret); - goto errout; - } -#endif - -#ifdef CONFIG_LOGGING_NXSCOPE_CRICHANNELS - /* Create critical channel thread */ - - env.nxs = &nxs; - ret = pthread_create(&thread, NULL, nxscope_crichan_thr, &env); - if (ret != OK) - { - printf("ERROR: pthread_create failed %d\n", ret); - goto errout; - } -#endif - -#ifdef CONFIG_EXAMPLES_NXSCOPE_FORCE_ENABLE - /* Enable channels and enable stream */ - - nxscope_chan_all_en(&nxs, true); - nxscope_stream_start(&nxs, true); -#endif - - /* Main loop */ - - while (1) - { - /* Flush stream data */ - - ret = nxscope_stream(&nxs); - if (ret < 0) - { - printf("ERROR: nxscope_stream failed %d\n", ret); - } - - /* Handle recv data */ - - ret = nxscope_recv(&nxs); - if (ret < 0) - { - printf("ERROR: nxscope_recv failed %d\n", ret); - } - - usleep(interval); - } - -errout: - - /* Deinit nxscope */ - - nxscope_deinit(&nxs); - -errout_nonxscope: - - /* Deinit interface */ - -#if defined(CONFIG_LOGGING_NXSCOPE_INTF_SERIAL) - nxscope_ser_deinit(&intf); -#endif -#if defined(CONFIG_LOGGING_NXSCOPE_INTF_UDP) - nxscope_udp_deinit(&intf); -#endif -#if defined(CONFIG_LOGGING_NXSCOPE_INTF_DUMMY) - nxscope_dummy_deinit(&intf); -#endif - -errout_nointf: - - /* Deinit protocol */ - -#if defined(CONFIG_LOGGING_NXSCOPE_PROTO_SER) - nxscope_proto_ser_deinit(&proto); -#endif - -errout_noproto: - - return 0; -} diff --git a/examples/nxterm/CMakeLists.txt b/examples/nxterm/CMakeLists.txt deleted file mode 100644 index 816d90c36..000000000 --- a/examples/nxterm/CMakeLists.txt +++ /dev/null @@ -1,36 +0,0 @@ -# ############################################################################## -# apps/examples/nxterm/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_NXTERM) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_NXTERM_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_NXTERM_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_NXTERM_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_NXTERM} - SRCS - nxterm_main.c) - target_sources(apps PRIVATE nxterm_toolbar.c nxterm_wndo.c nxterm_listener.c) -endif() diff --git a/examples/nxterm/Kconfig b/examples/nxterm/Kconfig index b1cc3a7df..6ac118eea 100644 --- a/examples/nxterm/Kconfig +++ b/examples/nxterm/Kconfig @@ -40,6 +40,11 @@ config EXAMPLES_NXTERM_SERVERPRIO int "Server priority" default 120 +config EXAMPLES_NXTERM_NOTIFYSIGNO + int "Notification signal" + default 4 + range 1 31 + config EXAMPLES_NXTERM_BPP int "Pixel width" default 16 diff --git a/examples/nxterm/Make.defs b/examples/nxterm/Make.defs index 096848dec..9392c310e 100644 --- a/examples/nxterm/Make.defs +++ b/examples/nxterm/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/nxterm/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/nxterm/Makefile b/examples/nxterm/Makefile index 58b7037ad..b2911fe8d 100644 --- a/examples/nxterm/Makefile +++ b/examples/nxterm/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/nxterm/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/nxterm/nxterm_internal.h b/examples/nxterm/nxterm_internal.h index d72aa0159..1baf76ee3 100644 --- a/examples/nxterm/nxterm_internal.h +++ b/examples/nxterm/nxterm_internal.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/nxterm/nxterm_internal.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -112,7 +110,7 @@ # define CONFIG_EXAMPLES_NXTERM_BGCOLOR RGBTO16(39, 64, 139) # else # define CONFIG_EXAMPLES_NXTERM_BGCOLOR RGBTO8(39, 64, 139) -# endif +# endif #endif /* Window color (lighter steel blue) */ @@ -124,7 +122,7 @@ # define CONFIG_EXAMPLES_NXTERM_WCOLOR RGBTO16(202, 225, 255) # else # define CONFIG_EXAMPLES_NXTERM_WCOLOR RGBTO8(202, 225, 255) -# endif +# endif #endif /* Toolbar color (medium grey) */ @@ -186,6 +184,9 @@ #ifndef CONFIG_EXAMPLES_NXTERM_SERVERPRIO # define CONFIG_EXAMPLES_NXTERM_SERVERPRIO 120 #endif +#ifndef CONFIG_EXAMPLES_NXTERM_NOTIFYSIGNO +# define CONFIG_EXAMPLES_NXTERM_NOTIFYSIGNO 4 +#endif /* NX Console Device */ diff --git a/examples/nxterm/nxterm_listener.c b/examples/nxterm/nxterm_listener.c index b01328ab2..de20445ca 100644 --- a/examples/nxterm/nxterm_listener.c +++ b/examples/nxterm/nxterm_listener.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/nxterm/nxterm_listener.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/nxterm/nxterm_main.c b/examples/nxterm/nxterm_main.c index 6fbf0be6d..57c19576b 100644 --- a/examples/nxterm/nxterm_main.c +++ b/examples/nxterm/nxterm_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/nxterm/nxterm_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -38,7 +36,7 @@ #include <string.h> #include <assert.h> #include <errno.h> -#include <nuttx/debug.h> +#include <debug.h> #ifdef CONFIG_NX_LCDDRIVER # include <nuttx/lcd/lcd.h> @@ -55,6 +53,16 @@ #include "nxterm_internal.h" +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* The NSH telnet console requires networking support (and TCP/IP) */ + +#ifndef CONFIG_NET +# undef CONFIG_NSH_TELNET +#endif + /**************************************************************************** * Public Data ****************************************************************************/ @@ -215,6 +223,22 @@ int main(int argc, FAR char *argv[]) printf("nxterm_main: Initialize NSH\n"); nsh_initialize(); + /* If the Telnet console is selected as a front-end, then start the + * Telnet daemon. + */ + +#ifdef CONFIG_NSH_TELNET + ret = nsh_telnetstart(AF_UNSPEC); + if (ret < 0) + { + /* The daemon is NOT running. Report the error then fail... + * either with the serial console up or just exiting. + */ + + fprintf(stderr, "ERROR: Failed to start TELNET daemon: %d\n", ret); + } +#endif + /* NX Initialization ******************************************************/ /* Initialize NX */ diff --git a/examples/nxterm/nxterm_toolbar.c b/examples/nxterm/nxterm_toolbar.c index 327a54057..63076ac5b 100644 --- a/examples/nxterm/nxterm_toolbar.c +++ b/examples/nxterm/nxterm_toolbar.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/nxterm/nxterm_toolbar.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -33,7 +31,7 @@ #include <string.h> #include <semaphore.h> #include <errno.h> -#include <nuttx/debug.h> +#include <debug.h> #include <nuttx/nx/nx.h> #include <nuttx/nx/nxfonts.h> @@ -54,14 +52,12 @@ static void nxtool_redraw(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect, bool morem, FAR void *arg); -static void nxtool_position(NXWINDOW hwnd, - FAR const struct nxgl_size_s *size, +static void nxtool_position(NXWINDOW hwnd, FAR const struct nxgl_size_s *size, FAR const struct nxgl_point_s *pos, FAR const struct nxgl_rect_s *bounds, FAR void *arg); #ifdef CONFIG_NX_XYINPUT -static void nxtool_mousein(NXWINDOW hwnd, - FAR const struct nxgl_point_s *pos, +static void nxtool_mousein(NXWINDOW hwnd, FAR const struct nxgl_point_s *pos, uint8_t buttons, FAR void *arg); #endif @@ -123,8 +119,7 @@ static void nxtool_redraw(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect, * Name: nxtool_position ****************************************************************************/ -static void nxtool_position(NXWINDOW hwnd, - FAR const struct nxgl_size_s *size, +static void nxtool_position(NXWINDOW hwnd, FAR const struct nxgl_size_s *size, FAR const struct nxgl_point_s *pos, FAR const struct nxgl_rect_s *bounds, FAR void *arg) diff --git a/examples/nxterm/nxterm_wndo.c b/examples/nxterm/nxterm_wndo.c index ca88204ae..227f4db97 100644 --- a/examples/nxterm/nxterm_wndo.c +++ b/examples/nxterm/nxterm_wndo.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/nxterm/nxterm_wndo.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -35,7 +33,7 @@ #include <string.h> #include <semaphore.h> #include <errno.h> -#include <nuttx/debug.h> +#include <debug.h> #include <nuttx/nx/nx.h> #include <nuttx/nx/nxglib.h> @@ -49,14 +47,12 @@ static void nxwndo_redraw(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect, bool morem, FAR void *arg); -static void nxwndo_position(NXWINDOW hwnd, - FAR const struct nxgl_size_s *size, +static void nxwndo_position(NXWINDOW hwnd, FAR const struct nxgl_size_s *size, FAR const struct nxgl_point_s *pos, FAR const struct nxgl_rect_s *bounds, FAR void *arg); #ifdef CONFIG_NX_XYINPUT -static void nxwndo_mousein(NXWINDOW hwnd, - FAR const struct nxgl_point_s *pos, +static void nxwndo_mousein(NXWINDOW hwnd, FAR const struct nxgl_point_s *pos, uint8_t buttons, FAR void *arg); #endif @@ -121,9 +117,7 @@ static void nxwndo_redraw(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect, } else { - /* If the driver has not been opened, then just redraw the window - * color. - */ + /* If the driver has not been opened, then just redraw the window color */ wcolor[0] = CONFIG_EXAMPLES_NXTERM_WCOLOR; nxtk_fillwindow(hwnd, rect, wcolor); @@ -134,8 +128,7 @@ static void nxwndo_redraw(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect, * Name: nxwndo_position ****************************************************************************/ -static void nxwndo_position(NXWINDOW hwnd, - FAR const struct nxgl_size_s *size, +static void nxwndo_position(NXWINDOW hwnd, FAR const struct nxgl_size_s *size, FAR const struct nxgl_point_s *pos, FAR const struct nxgl_rect_s *bounds, FAR void *arg) @@ -168,8 +161,7 @@ static void nxwndo_position(NXWINDOW hwnd, g_nxterm_vars.haveres = true; sem_post(&g_nxterm_vars.eventsem); - ginfo("Have xres=%d yres=%d\n", - g_nxterm_vars.xres, g_nxterm_vars.yres); + ginfo("Have xres=%d yres=%d\n", g_nxterm_vars.xres, g_nxterm_vars.yres); } } diff --git a/examples/nxtext/CMakeLists.txt b/examples/nxtext/CMakeLists.txt deleted file mode 100644 index 7bfa5f756..000000000 --- a/examples/nxtext/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# ############################################################################## -# apps/examples/nxtext/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_NXTEXT) - nuttx_add_application( - NAME - nxtext - STACKSIZE - ${CONFIG_DEFAULT_TASK_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_NXTEXT} - SRCS - nxtext_main.c) - target_sources(apps PRIVATE nxtext_bkgd.c nxtext_popup.c nxtext_putc.c - nxtext_listener.c) -endif() diff --git a/examples/nxtext/Make.defs b/examples/nxtext/Make.defs index 003fb52db..028b1f756 100644 --- a/examples/nxtext/Make.defs +++ b/examples/nxtext/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/nxtext/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/nxtext/Makefile b/examples/nxtext/Makefile index dafa6386e..420746da0 100644 --- a/examples/nxtext/Makefile +++ b/examples/nxtext/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/nxtext/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/nxtext/nxtext_bkgd.c b/examples/nxtext/nxtext_bkgd.c index b0957bb7a..98c761bbb 100644 --- a/examples/nxtext/nxtext_bkgd.c +++ b/examples/nxtext/nxtext_bkgd.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/nxtext/nxtext_bkgd.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -33,7 +31,7 @@ #include <string.h> #include <semaphore.h> #include <errno.h> -#include <nuttx/debug.h> +#include <debug.h> #include <nuttx/nx/nx.h> #include <nuttx/nx/nxfonts.h> @@ -107,8 +105,7 @@ NXHANDLE g_bgwnd; * Name: nxbg_redrawrect ****************************************************************************/ -static void nxbg_redrawrect(NXWINDOW hwnd, - FAR const struct nxgl_rect_s *rect) +static void nxbg_redrawrect(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect) { int ret; int i; @@ -173,9 +170,7 @@ static void nxbg_position(NXWINDOW hwnd, FAR const struct nxgl_size_s *size, st->wsize.w = size->w; st->wsize.h = size->h; - /* Save the window limits (these should be the same for all places - * and all windows. - */ + /* Save the window limits (these should be the same for all places and all windows */ g_xres = bounds->pt2.x + 1; g_yres = bounds->pt2.y + 1; @@ -222,8 +217,7 @@ static void nxbg_kbdin(NXWINDOW hwnd, uint8_t nch, FAR const uint8_t *ch, * only. ****************************************************************************/ -static inline void nxbg_movedisplay(NXWINDOW hwnd, int bottom, - int lineheight) +static inline void nxbg_movedisplay(NXWINDOW hwnd, int bottom, int lineheight) { FAR struct nxtext_bitmap_s *bm; struct nxgl_rect_s rect; @@ -231,10 +225,10 @@ static inline void nxbg_movedisplay(NXWINDOW hwnd, int bottom, int ret; int i; - /* Move each row, one at a time. They could all be moved at once (by - * calling nxbg_redrawrect), but since the region is cleared, then - * rewritten, the effect would not be good. Below the region is also - * cleared and rewritten, however, in much smaller chunks. + /* Move each row, one at a time. They could all be moved at once (by calling + * nxbg_redrawrect), but the since the region is cleared, then re-written, the + * effect would not be good. Below the region is also cleared and re-written, + * however, in much smaller chunks. */ rect.pt1.x = 0; @@ -260,8 +254,7 @@ static inline void nxbg_movedisplay(NXWINDOW hwnd, int bottom, for (i = 0; i < g_bgstate.nchars; i++) { bm = &g_bgstate.bm[i]; - if (bm->pos.y <= rect.pt2.y && - bm->pos.y + g_bgstate.fheight >= rect.pt1.y) + if (bm->pos.y <= rect.pt2.y && bm->pos.y + g_bgstate.fheight >= rect.pt1.y) { nxtext_fillchar(hwnd, &rect, &g_bgstate, g_bghfont, bm); } @@ -271,7 +264,7 @@ static inline void nxbg_movedisplay(NXWINDOW hwnd, int bottom, /* Finally, clear the bottom part of the display */ rect.pt1.y = bottom; - rect.pt2.y = g_bgstate.wsize.h - 1; + rect.pt2.y = g_bgstate.wsize.h- 1; ret = nx_fill(hwnd, &rect, g_bgstate.wcolor); if (ret < 0) @@ -301,15 +294,13 @@ static inline void nxbg_scroll(NXWINDOW hwnd, int lineheight) { /* Yes... Delete the character by moving all of the data */ - for (j = i; j < g_bgstate.nchars - 1; j++) + for (j = i; j < g_bgstate.nchars-1; j++) { - memcpy(&g_bgstate.bm[j], &g_bgstate.bm[j + 1], - sizeof(struct nxtext_bitmap_s)); + memcpy(&g_bgstate.bm[j], &g_bgstate.bm[j+1], sizeof(struct nxtext_bitmap_s)); } - /* Decrement the number of cached characters. 'i' is not - * incremented in this case because it already points to the next - * character. + /* Decrement the number of cached characters ('i' is not incremented + * in this case because it already points to the next character) */ g_bgstate.nchars--; diff --git a/examples/nxtext/nxtext_internal.h b/examples/nxtext/nxtext_internal.h index 376fe5d07..af271acef 100644 --- a/examples/nxtext/nxtext_internal.h +++ b/examples/nxtext/nxtext_internal.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/nxtext/nxtext_internal.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -89,7 +87,7 @@ # define CONFIG_EXAMPLES_NXTEXT_BGCOLOR 0x7b5d # else # define CONFIG_EXAMPLES_NXTEXT_BGCOLOR ' ' -# endif +# endif #endif /* Pop-up font ID */ @@ -107,7 +105,7 @@ # define CONFIG_EXAMPLES_NXTEXT_PUCOLOR 0xdefb # else # define CONFIG_EXAMPLES_NXTEXT_PUCOLOR '2' -# endif +# endif #endif /* Background font ID */ diff --git a/examples/nxtext/nxtext_listener.c b/examples/nxtext/nxtext_listener.c index ddb9069ef..7189d684a 100644 --- a/examples/nxtext/nxtext_listener.c +++ b/examples/nxtext/nxtext_listener.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/nxtext/nxtext_listener.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/nxtext/nxtext_main.c b/examples/nxtext/nxtext_main.c index c749cd53a..3814c8dd9 100644 --- a/examples/nxtext/nxtext_main.c +++ b/examples/nxtext/nxtext_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/nxtext/nxtext_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -38,7 +36,7 @@ #include <sched.h> #include <pthread.h> #include <errno.h> -#include <nuttx/debug.h> +#include <debug.h> #include <nuttx/arch.h> #include <nuttx/board.h> @@ -60,7 +58,6 @@ ****************************************************************************/ /* Configuration ************************************************************/ - /* If not specified, assume that the hardware supports one video plane */ #ifndef CONFIG_EXAMPLES_NXTEXT_VPLANE @@ -139,10 +136,7 @@ nxgl_coord_t g_yres; bool b_haveresolution = false; bool g_connected = false; -sem_t g_semevent = -{ - 0 -}; +sem_t g_semevent = {0}; int g_exitcode = NXEXIT_SUCCESS; @@ -166,7 +160,7 @@ static int nxtext_initialize(void) ret = sched_setparam(0, ¶m); if (ret < 0) { - printf("nxtext_initialize: sched_setparam failed: %d\n", ret); + printf("nxtext_initialize: sched_setparam failed: %d\n" , ret); g_exitcode = NXEXIT_SCHEDSETPARAM; return ERROR; } @@ -177,8 +171,7 @@ static int nxtext_initialize(void) ret = boardctl(BOARDIOC_NX_START, 0); if (ret < 0) { - printf("nxtext_initialize: Failed to start the NX server: %d\n", - errno); + printf("nxtext_initialize: Failed to start the NX server: %d\n", errno); g_exitcode = NXEXIT_SERVERSTART; return ERROR; } @@ -193,24 +186,24 @@ static int nxtext_initialize(void) #ifdef CONFIG_VNCSERVER /* Setup the VNC server to support keyboard/mouse inputs */ - struct boardioc_vncstart_s vnc = - { - 0, g_hnx - }; + struct boardioc_vncstart_s vnc = + { + 0, g_hnx + }; - ret = boardctl(BOARDIOC_VNC_START, (uintptr_t)&vnc); - if (ret < 0) - { - printf("boardctl(BOARDIOC_VNC_START) failed: %d\n", ret); - nx_disconnect(g_hnx); - g_exitcode = NXEXIT_FBINITIALIZE; - return ERROR; - } + ret = boardctl(BOARDIOC_VNC_START, (uintptr_t)&vnc); + if (ret < 0) + { + printf("boardctl(BOARDIOC_VNC_START) failed: %d\n", ret); + nx_disconnect(g_hnx); + g_exitcode = NXEXIT_FBINITIALIZE; + return ERROR; + } #endif - /* Start a separate thread to listen for server events. This is - * probably the least efficient way to do this, but it makes this - * example flow more smoothly. + /* Start a separate thread to listen for server events. This is probably + * the least efficient way to do this, but it makes this example flow more + * smoothly. */ pthread_attr_init(&attr); @@ -221,10 +214,10 @@ static int nxtext_initialize(void) ret = pthread_create(&thread, &attr, nxtext_listener, NULL); if (ret != 0) { - printf("nxtext_initialize: pthread_create failed: %d\n", ret); + printf("nxtext_initialize: pthread_create failed: %d\n", ret); - g_exitcode = NXEXIT_PTHREADCREATE; - return ERROR; + g_exitcode = NXEXIT_PTHREADCREATE; + return ERROR; } /* Don't return until we are connected to the server */ @@ -282,8 +275,7 @@ int main(int argc, FAR char *argv[]) g_bghfont = nxf_getfonthandle(CONFIG_EXAMPLES_NXTEXT_BGFONTID); if (!g_bghfont) { - printf("nxtext_main: Failed to get background font handle: %d\n", - errno); + printf("nxtext_main: Failed to get background font handle: %d\n", errno); g_exitcode = NXEXIT_FONTOPEN; goto errout; } @@ -291,16 +283,14 @@ int main(int argc, FAR char *argv[]) g_puhfont = nxf_getfonthandle(CONFIG_EXAMPLES_NXTEXT_PUFONTID); if (!g_puhfont) { - printf("nxtext_main: Failed to get pop-up font handle: %d\n", - errno); + printf("nxtext_main: Failed to get pop-up font handle: %d\n", errno); g_exitcode = NXEXIT_FONTOPEN; goto errout; } /* Set the background to the configured background color */ - printf("nxtext_main: Set background color=%d\n", - CONFIG_EXAMPLES_NXTEXT_BGCOLOR); + printf("nxtext_main: Set background color=%d\n", CONFIG_EXAMPLES_NXTEXT_BGCOLOR); color = CONFIG_EXAMPLES_NXTEXT_BGCOLOR; ret = nx_setbgcolor(g_hnx, &color); if (ret < 0) @@ -336,7 +326,7 @@ int main(int argc, FAR char *argv[]) popcnt = 0; bkgndx = 0; - for (; ; ) + for (;;) { /* Sleep for one second */ @@ -354,18 +344,15 @@ int main(int argc, FAR char *argv[]) hwnd = nxpu_open(); #ifdef CONFIG_NX_KBD - /* Give keyboard input to the top window (which should be the - * pop-up). - */ + /* Give keyboard input to the top window (which should be the pop-up) */ printf("nxtext_main: Send keyboard input: %s\n", g_pumsg); - ret = nx_kbdin(g_hnx, strlen((FAR const char *)g_pumsg), - g_pumsg); + ret = nx_kbdin(g_hnx, strlen((FAR const char *)g_pumsg), g_pumsg); if (ret < 0) - { - printf("nxtext_main: nx_kbdin failed: %d\n", errno); - goto errout_with_hwnd; - } + { + printf("nxtext_main: nx_kbdin failed: %d\n", errno); + goto errout_with_hwnd; + } #endif } else if (popcnt == 5) @@ -378,12 +365,11 @@ int main(int argc, FAR char *argv[]) } /* Give another line of text to the background window. Force this - * text to the background by calling the background window - * interfaces directly. + * text to go the background by calling the background window interfaces + * directly. */ - nxbg_write(g_bgwnd, (FAR const uint8_t *)g_bgmsg[bkgndx], - strlen(g_bgmsg[bkgndx])); + nxbg_write(g_bgwnd, (FAR const uint8_t *)g_bgmsg[bkgndx], strlen(g_bgmsg[bkgndx])); if (++bkgndx >= BGMSG_LINES) { bkgndx = 0; @@ -398,15 +384,13 @@ errout_with_hwnd: if (popcnt >= 3) { printf("nxtext_main: Close pop-up\n"); - nxpu_close(hwnd); + nxpu_close(hwnd); } - /* errout_with_bkgd: */ - +//errout_with_bkgd: nx_releasebkgd(g_bgwnd); errout_with_nx: - /* Disconnect from the server */ printf("nxtext_main: Disconnect from the server\n"); diff --git a/examples/nxtext/nxtext_popup.c b/examples/nxtext/nxtext_popup.c index 19dbd3cc5..8e56aeb06 100644 --- a/examples/nxtext/nxtext_popup.c +++ b/examples/nxtext/nxtext_popup.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/nxtext/nxtext_popup.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -32,7 +30,7 @@ #include <string.h> #include <semaphore.h> #include <errno.h> -#include <nuttx/debug.h> +#include <debug.h> #include <nuttx/nx/nx.h> #include <nuttx/nx/nxfonts.h> @@ -141,7 +139,6 @@ static inline int nxpu_setsize(NXWINDOW hwnd, FAR struct nxgl_size_s *size) printf("nxpu_setsize: nx_setsize failed: %d\n", errno); g_exitcode = NXEXIT_NXSETSIZE; } - return ret; } @@ -149,8 +146,7 @@ static inline int nxpu_setsize(NXWINDOW hwnd, FAR struct nxgl_size_s *size) * Name: nxpu_setposition ****************************************************************************/ -static inline int nxpu_setposition(NXWINDOW hwnd, - FAR struct nxgl_point_s *pos) +static inline int nxpu_setposition(NXWINDOW hwnd, FAR struct nxgl_point_s *pos) { int ret = nx_setposition(hwnd, pos); if (ret < 0) @@ -158,7 +154,6 @@ static inline int nxpu_setposition(NXWINDOW hwnd, printf("nxpu_setposition: nx_setposition failed: %d\n", errno); g_exitcode = NXEXIT_NXSETPOSITION; } - return ret; } @@ -252,7 +247,6 @@ static void nxpu_mousein(NXWINDOW hwnd, FAR const struct nxgl_point_s *pos, * Name: nxpu_puts ****************************************************************************/ -#ifdef CONFIG_NX_KBD static inline void nxpu_puts(NXWINDOW hwnd, FAR struct nxtext_state_s *st, uint8_t nch, FAR const uint8_t *ch) { @@ -262,7 +256,6 @@ static inline void nxpu_puts(NXWINDOW hwnd, FAR struct nxtext_state_s *st, nxtext_putc(hwnd, st, g_puhfont, *ch++); } } -#endif /**************************************************************************** * Name: nxpu_kbdin @@ -399,6 +392,5 @@ int nxpu_close(NXWINDOW hwnd) g_exitcode = NXEXIT_NXCLOSEWINDOW; return ret; } - return OK; } diff --git a/examples/nxtext/nxtext_putc.c b/examples/nxtext/nxtext_putc.c index 325132caf..b2727270f 100644 --- a/examples/nxtext/nxtext_putc.c +++ b/examples/nxtext/nxtext_putc.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/nxtext/nxtext_putc.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -32,7 +30,7 @@ #include <string.h> #include <ctype.h> #include <errno.h> -#include <nuttx/debug.h> +#include <debug.h> #include <nuttx/nx/nx.h> #include <nuttx/nx/nxfonts.h> @@ -95,7 +93,6 @@ static void nxtext_freeglyph(FAR struct nxtext_glyph_s *glyph) { free(glyph->bitmap); } - memset(glyph, 0, sizeof(struct nxtext_glyph_s)); } @@ -112,11 +109,11 @@ nxtext_allocglyph(FAR struct nxtext_state_s *st) int i; /* Search through the glyph cache looking for an unused glyph. Also, keep - * track of the least used glyph as well. We need that if we have to - * replace a glyph in the cache. + * track of the least used glyph as well. We need that if we have to replace + * a glyph in the cache. */ - for (i = 0; i < st->maxglyphs; i++) + for (i = 0; i < st->maxglyphs; i++) { /* Is this glyph in use? */ @@ -150,9 +147,9 @@ nxtext_allocglyph(FAR struct nxtext_state_s *st) if (luusecnt > 1) { - uint8_t decr = luusecnt - 1; + uint8_t decr = luusecnt - 1; - for (i = 0; i < st->maxglyphs; i++) + for (i = 0; i < st->maxglyphs; i++) { /* Is this glyph in use? */ @@ -181,7 +178,7 @@ nxtext_findglyph(FAR struct nxtext_state_s *st, uint8_t ch) /* First, try to find the glyph in the cache of pre-rendered glyphs */ - for (i = 0; i < st->maxglyphs; i++) + for (i = 0; i < st->maxglyphs; i++) { FAR struct nxtext_glyph_s *glyph = &st->glyph[i]; if (glyph->usecnt > 0 && glyph->code == ch) @@ -190,7 +187,7 @@ nxtext_findglyph(FAR struct nxtext_state_s *st, uint8_t ch) if (glyph->usecnt < MAX_USECNT) { - glyph->usecnt++; + glyph->usecnt++; } /* And return the glyph that we found */ @@ -198,7 +195,6 @@ nxtext_findglyph(FAR struct nxtext_state_s *st, uint8_t ch) return glyph; } } - return NULL; } @@ -250,13 +246,13 @@ nxtext_renderglyph(FAR struct nxtext_state_s *st, /* Pack 1-bit pixels into a 2-bits */ pixel &= 0x01; - pixel = (pixel) << 1 | pixel; + pixel = (pixel) << 1 |pixel; # endif # if CONFIG_EXAMPLES_NXTEXT_BPP < 4 /* Pack 2-bit pixels into a nibble */ pixel &= 0x03; - pixel = (pixel) << 2 | pixel; + pixel = (pixel) << 2 |pixel; # endif /* Pack 4-bit nibbles into a byte */ @@ -294,7 +290,7 @@ nxtext_renderglyph(FAR struct nxtext_state_s *st, /* Then render the glyph into the allocated memory */ - ret = RENDERER((FAR nxgl_mxpixel_t *)glyph->bitmap, + ret = RENDERER((FAR nxgl_mxpixel_t*)glyph->bitmap, glyph->height, glyph->width, glyph->stride, fbm, st->fcolor[0]); if (ret < 0) @@ -314,8 +310,7 @@ nxtext_renderglyph(FAR struct nxtext_state_s *st, * Name: nxtext_fontsize ****************************************************************************/ -static int nxtext_fontsize(NXHANDLE hfont, uint8_t ch, - FAR struct nxgl_size_s *size) +static int nxtext_fontsize(NXHANDLE hfont, uint8_t ch, FAR struct nxgl_size_s *size) { FAR const struct nx_fontbitmap_s *fbm; @@ -368,7 +363,7 @@ nxtext_getglyph(NXHANDLE hfont, FAR struct nxtext_state_s *st, uint8_t ch) * * Description: * This is part of the nxtext_putc logic. It creates and positions a - * the character and renders (or reuses) a glyph for font. + * the character and renders (or re-uses) a glyph for font. * ****************************************************************************/ @@ -382,39 +377,37 @@ nxtext_addchar(NXHANDLE hfont, FAR struct nxtext_state_s *st, uint8_t ch) if (st->nchars < st->maxchars) { - /* Yes, setup the bitmap information */ + /* Yes, setup the bitmap information */ - bm = &st->bm[st->nchars]; - bm->code = ch; - bm->flags = 0; - bm->pos.x = st->fpos.x; - bm->pos.y = st->fpos.y; + bm = &st->bm[st->nchars]; + bm->code = ch; + bm->flags = 0; + bm->pos.x = st->fpos.x; + bm->pos.y = st->fpos.y; - /* Find (or create) the matching glyph */ + /* Find (or create) the matching glyph */ - glyph = nxtext_getglyph(hfont, st, ch); - if (!glyph) - { - /* No, there is no font for this code. Just mark this as a - * space. - */ + glyph = nxtext_getglyph(hfont, st, ch); + if (!glyph) + { + /* No, there is no font for this code. Just mark this as a space. */ - bm->flags |= BMFLAGS_NOGLYPH; + bm->flags |= BMFLAGS_NOGLYPH; - /* Set up the next character position */ + /* Set up the next character position */ - st->fpos.x += st->spwidth; - } - else - { - /* Set up the next character position */ + st->fpos.x += st->spwidth; + } + else + { + /* Set up the next character position */ - st->fpos.x += glyph->width; - } + st->fpos.x += glyph->width; + } - /* Success.. increment nchars to retain this character */ + /* Success.. increment nchars to retain this character */ - st->nchars++; + st->nchars++; } return bm; @@ -470,8 +463,7 @@ void nxtext_newline(FAR struct nxtext_state_s *st) * ****************************************************************************/ -void nxtext_putc(NXWINDOW hwnd, FAR struct nxtext_state_s *st, - NXHANDLE hfont, uint8_t ch) +void nxtext_putc(NXWINDOW hwnd, FAR struct nxtext_state_s *st, NXHANDLE hfont, uint8_t ch) { FAR const struct nxtext_bitmap_s *bm; @@ -568,17 +560,17 @@ void nxtext_fillchar(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect, /* Find (or create) the glyph that goes with this font */ - glyph = nxtext_getglyph(hfont, st, bm->code); - if (!glyph) - { - /* Shouldn't happen */ + glyph = nxtext_getglyph(hfont, st, bm->code); + if (!glyph) + { + /* Shouldn't happen */ - return; - } + return; + } /* Blit the font bitmap into the window */ - src = glyph->bitmap; + src = (FAR const void *)glyph->bitmap; ret = nx_bitmap((NXWINDOW)hwnd, &intersection, &src, &bm->pos, (unsigned int)glyph->stride); if (ret < 0) diff --git a/examples/obd2/CMakeLists.txt b/examples/obd2/CMakeLists.txt deleted file mode 100644 index a2d8d9fd7..000000000 --- a/examples/obd2/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# ############################################################################## -# apps/examples/obd2/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_OBD2) - nuttx_add_application( - NAME - obd2 - STACKSIZE - ${CONFIG_DEFAULT_TASK_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_OBD2} - SRCS - obd2_main.c) -endif() diff --git a/examples/obd2/Make.defs b/examples/obd2/Make.defs index 61ccfd4a3..49e7cdb7b 100644 --- a/examples/obd2/Make.defs +++ b/examples/obd2/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/obd2/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/obd2/Makefile b/examples/obd2/Makefile index d3d64bfec..73be45854 100644 --- a/examples/obd2/Makefile +++ b/examples/obd2/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/obd2/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/obd2/obd2_main.c b/examples/obd2/obd2_main.c index 20efcdb7d..eeadebe0d 100644 --- a/examples/obd2/obd2_main.c +++ b/examples/obd2/obd2_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/obd2/obd2_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/oneshot/CMakeLists.txt b/examples/oneshot/CMakeLists.txt deleted file mode 100644 index d38a0e419..000000000 --- a/examples/oneshot/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# ############################################################################## -# apps/examples/oneshot/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_ONESHOT) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_ONESHOT_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_ONESHOT_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_ONESHOT_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_ONESHOT} - SRCS - oneshot_main.c) -endif() diff --git a/examples/oneshot/Kconfig b/examples/oneshot/Kconfig index 3b9505985..88f2713d4 100644 --- a/examples/oneshot/Kconfig +++ b/examples/oneshot/Kconfig @@ -6,7 +6,7 @@ config EXAMPLES_ONESHOT tristate "Oneshot timer example" default n - depends on ONESHOT && ENABLE_ALL_SIGNALS + depends on ONESHOT ---help--- Enable the oneshot timer driver example @@ -28,7 +28,7 @@ config EXAMPLES_ONESHOT_DELAY config EXAMPLES_ONESHOT_SIGNO int "Signal number" - default 32 + default 13 ---help--- This is the number of the signal that will be used in the oneshot notification. diff --git a/examples/oneshot/Make.defs b/examples/oneshot/Make.defs index d3a12049c..d194c2e91 100644 --- a/examples/oneshot/Make.defs +++ b/examples/oneshot/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/oneshot/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/oneshot/Makefile b/examples/oneshot/Makefile index 5e4989657..1ddce3049 100644 --- a/examples/oneshot/Makefile +++ b/examples/oneshot/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/oneshot/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/oneshot/oneshot_main.c b/examples/oneshot/oneshot_main.c index 00fac3f2d..3a29a2b29 100644 --- a/examples/oneshot/oneshot_main.c +++ b/examples/oneshot/oneshot_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/oneshot/oneshot_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -34,9 +32,7 @@ #include <fcntl.h> #include <time.h> #include <errno.h> -#include <unistd.h> -#include <nuttx/clock.h> #include <nuttx/timers/oneshot.h> /**************************************************************************** @@ -52,7 +48,7 @@ #endif #ifndef CONFIG_EXAMPLES_ONESHOT_SIGNO -# define CONFIG_EXAMPLES_ONESHOT_SIGNO 32 +# define CONFIG_EXAMPLES_ONESHOT_SIGNO 13 #endif /* For long delays that have to be broken into segments, some loss of @@ -167,8 +163,8 @@ int main(int argc, FAR char *argv[]) return EXIT_FAILURE; } - maxus = ts.tv_sec * USEC_PER_SEC + - ts.tv_nsec / NSEC_PER_USEC; + maxus = (uint64_t)ts.tv_sec * USEC_PER_SEC + + (uint64_t)ts.tv_nsec / NSEC_PER_USEC; printf("Maximum delay is %" PRIu64 "\n", maxus); @@ -211,8 +207,8 @@ int main(int argc, FAR char *argv[]) { /* Wait for the maximum */ - printf("Starting oneshot timer with delay %" PRId64 - " microseconds\n", maxus); + printf("Starting oneshot timer with delay %llu microseconds\n", + maxus); start.ts.tv_sec = ts.tv_sec; start.ts.tv_nsec = ts.tv_nsec; diff --git a/examples/opencyphal/CMakeLists.txt b/examples/opencyphal/CMakeLists.txt deleted file mode 100644 index 386a094b8..000000000 --- a/examples/opencyphal/CMakeLists.txt +++ /dev/null @@ -1,40 +0,0 @@ -# ############################################################################## -# apps/examples/opencyphal/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_LIBOPENCYPHAL) - set(INCDIR ${NUTTX_APPS_DIR}/canutils/libopencyphal/libcanard/libcanard) - set(CFLAGS -std=c11) - nuttx_add_application( - NAME - opencyphal - STACKSIZE - ${CONFIG_EXAMPLES_LIBOPENCYPHAL_DAEMON_STACK_SIZE} - MODULE - ${CONFIG_EXAMPLES_LIBOPENCYPHAL} - SRCS - canard_main.c - INCLUDE_DIRECTORIES - ${INCDIR} - COMPILE_FLAGS - ${CFLAGS}) - target_sources(apps PRIVATE socketcan.c) -endif() diff --git a/examples/opencyphal/Kconfig b/examples/opencyphal/Kconfig deleted file mode 100644 index 49ab8d5f7..000000000 --- a/examples/opencyphal/Kconfig +++ /dev/null @@ -1,48 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config EXAMPLES_LIBOPENCYPHAL - tristate "OpenCyphal Cyphal/CAN example" - default n - depends on CANUTILS_LIBOPENCYPHAL - ---help--- - Enable the LIBOPENCYPHAL example - -if EXAMPLES_LIBOPENCYPHAL - -config EXAMPLES_LIBOPENCYPHAL_DEV - string "Device" - default "can0" - ---help--- - The device - -config EXAMPLES_LIBOPENCYPHAL_NODE_ID - int "Node ID" - default 1 - range 1 127 - ---help--- - Specifies the node's ID - -config EXAMPLES_LIBOPENCYPHAL_APP_NODE_NAME - string "Node name" - default "org.apache.nuttx.demo" - ---help--- - app node name - -config EXAMPLES_LIBOPENCYPHAL_NODE_MEM_POOL_SIZE - int "Node Memory Pool Size" - default 1024 - ---help--- - Specifies the node's memory pool size - -config EXAMPLES_LIBOPENCYPHAL_DAEMON_PRIORITY - int "daemon task priority" - default 100 - -config EXAMPLES_LIBOPENCYPHAL_DAEMON_STACK_SIZE - int "canard stack size" - default DEFAULT_TASK_STACKSIZE - -endif diff --git a/examples/opencyphal/Make.defs b/examples/opencyphal/Make.defs deleted file mode 100644 index 432f44b22..000000000 --- a/examples/opencyphal/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/examples/opencyphal/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http:#www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_EXAMPLES_LIBOPENCYPHAL),) -CONFIGURED_APPS += $(APPDIR)/examples/opencyphal -endif diff --git a/examples/opencyphal/Makefile b/examples/opencyphal/Makefile deleted file mode 100644 index 6168f583c..000000000 --- a/examples/opencyphal/Makefile +++ /dev/null @@ -1,37 +0,0 @@ -############################################################################ -# apps/examples/opencyphal/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http:#www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -PROGNAME = opencyphal -PRIORITY = SCHED_PRIORITY_DEFAULT -STACKSIZE = $(CONFIG_EXAMPLES_LIBOPENCYPHAL_DAEMON_STACK_SIZE) -MODULE = $(CONFIG_EXAMPLES_LIBOPENCYPHAL) - -CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/canutils/libopencyphal/libcanard/libcanard -CXXFLAGS += ${INCDIR_PREFIX}$(APPDIR)/canutils/libopencyphal/libcanard/libcanard - -CFLAGS += -std=c11 -CSRCS = socketcan.c -MAINSRC = canard_main.c - -include $(APPDIR)/Application.mk diff --git a/examples/opencyphal/canard_main.c b/examples/opencyphal/canard_main.c deleted file mode 100644 index 4c6f6dd30..000000000 --- a/examples/opencyphal/canard_main.c +++ /dev/null @@ -1,413 +0,0 @@ -/**************************************************************************** - * apps/examples/opencyphal/canard_main.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <canard.h> -#include <canard_dsdl.h> -#include <o1heap.h> - -#include <sched.h> - -#include <stdio.h> -#include <stdlib.h> -#include <time.h> -#include <string.h> -#include <assert.h> -#include <errno.h> - -#include <net/if.h> -#include <sys/time.h> -#include <sys/ioctl.h> -#include <sys/socket.h> - -#include <poll.h> - -#include <nuttx/can.h> - -#include "socketcan.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* Application constants */ - -#define APP_VERSION_MAJOR 1 -#define APP_VERSION_MINOR 0 -#define APP_NODE_NAME CONFIG_EXAMPLES_LIBOPENCYPHAL_APP_NODE_NAME - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/* Arena for memory allocation, used by the library */ - -#define O1_HEAP_SIZE CONFIG_EXAMPLES_LIBOPENCYPHAL_NODE_MEM_POOL_SIZE - -/* Temporary development UAVCAN topic service ID to publish/subscribe from */ -#define PORT_ID 4421 -#define TOPIC_SIZE 512 - -O1HeapInstance *my_allocator; -static uint8_t uavcan_heap[O1_HEAP_SIZE] -__attribute__((aligned(O1HEAP_ALIGNMENT))); - -/* Node status variables */ - -static bool g_canard_daemon_started; - -static uint8_t my_message_transfer_id; - -struct pollfd fd; - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: memallocate - * - * Description: - * - ****************************************************************************/ - -static void *memallocate(CanardInstance *const ins, const size_t amount) -{ - (void) ins; - return o1heapAllocate(my_allocator, amount); -} - -/**************************************************************************** - * Name: memfree - * - * Description: - * - ****************************************************************************/ - -static void memfree(CanardInstance *const ins, void *const pointer) -{ - (void) ins; - o1heapFree(my_allocator, pointer); -} - -/**************************************************************************** - * Name: getmonotonictimestampusec - * - * Description: - * - ****************************************************************************/ - -uint64_t getmonotonictimestampusec(void) -{ - struct timespec ts; - - memset(&ts, 0, sizeof(ts)); - - if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) - { - abort(); - } - - return ts.tv_sec * 1000000ULL + ts.tv_nsec / 1000ULL; -} - -/**************************************************************************** - * Name: process1hztasks - * - * Description: - * This function is called at 1 Hz rate from the main loop. - * - ****************************************************************************/ - -void process1hztasks(CanardInstance *ins, uint64_t timestamp_usec) -{ - CanardMicrosecond transmission_deadline = - getmonotonictimestampusec() + 1000 * 10; - - const CanardTransfer transfer = - { - .timestamp_usec = transmission_deadline, /* Zero if transmission deadline is not limited. */ - .priority = CanardPriorityNominal, - .transfer_kind = CanardTransferKindMessage, - .port_id = 1234, /* This is the subject-ID. */ - .remote_node_id = CANARD_NODE_ID_UNSET, /* Messages cannot be unicast, so use UNSET. */ - .transfer_id = my_message_transfer_id, - .payload_size = 47, - .payload = "\x2D\x00" - "Sancho, it strikes me thou art in great fear.", - }; - - ++my_message_transfer_id; /* The transfer-ID shall be incremented after every transmission on this subject. */ - int32_t result = canardTxPush(ins, &transfer); - - if (result < 0) - { - /* An error has occurred: either an argument is invalid or we've - * ran out of memory. It is possible to statically prove that an - * out-of-memory will never occur for a given application if the - * heap is sized correctly; for background, refer to the Robson's - * Proof and the documentation for O1Heap. - */ - - fprintf(stderr, "Transmit error %ld\n", result); - } -} - -/**************************************************************************** - * Name: processTxRxOnce - * - * Description: - * Transmits all frames from the TX queue, receives up to one frame. - * - ****************************************************************************/ - -void processtxrxonce(CanardInstance *ins, canardsocketinstance *sock_ins, - int timeout_msec) -{ - int32_t result; - - /* Transmitting, Look at the top of the TX queue. */ - - for (const CanardFrame *txf = NULL; (txf = canardTxPeek(ins)) != NULL; ) - { - if (txf->timestamp_usec > getmonotonictimestampusec()) /* Check if the frame has timed out. */ - { - if (socketcantransmit(sock_ins, txf) == 0) /* Send the frame. Redundant interfaces may be used here. */ - { - /* If the driver is busy, break and retry later. */ - - break; - } - } - - canardTxPop(ins); /* Remove the frame from the queue after it's transmitted. */ - ins->memory_free(ins, (CanardFrame *)txf); - } - - /* Poll receive */ - - if (poll(&fd, 1, timeout_msec) <= 0) - { - return; - } - - /* Receiving */ - - CanardFrame received_frame; - - socketcanreceive(sock_ins, &received_frame); - - CanardTransfer receive; - result = canardRxAccept(ins, - &received_frame, /* The CAN frame received from the bus. */ - 0, /* If the transport is not redundant, use 0. */ - &receive); - - if (result < 0) - { - /* An error has occurred: either an argument is invalid or we've ran - * out of memory. It is possible to statically prove that an - * out-of-memory will never occur for a given application - * if the heap is sized correctly; for background, refer to the - * Robson's Proof and the documentation for O1Heap. - * Reception of an invalid frame is NOT an error. - */ - - fprintf(stderr, "Receive error %ld\n", result); - } - else if (result == 1) - { - /* A transfer has been received, process it */ - - printf("Receive UAVCAN port id%d TODO process me\n", - receive.port_id); - - ins->memory_free(ins, (void *)receive.payload); - } - else - { - /* Nothing to do. - * The received frame is either invalid or it's a non-last frame - * of a multi-frame transfer. - * Reception of an invalid frame is NOT reported as an error - * because it is not an error. - */ - } -} - -/**************************************************************************** - * Name: canard_daemon - * - * Description: - * - ****************************************************************************/ - -static int canard_daemon(int argc, char *argv[]) -{ - int errval = 0; - int can_fd = 0; - int pub = 1; - - if (argc > 2) - { - for (int args = 2; args < argc; args++) - { - if (!strcmp(argv[args], "canfd")) - { - can_fd = 1; - } - - if (!strcmp(argv[args], "pub")) - { - pub = 1; - } - - if (!strcmp(argv[args], "sub")) - { - pub = 0; - } - } - } - - my_allocator = o1heapInit(&uavcan_heap, O1_HEAP_SIZE); - - if (my_allocator == NULL) - { - printf("o1heapInit failed with size %d\n", O1_HEAP_SIZE); - errval = 2; - goto errout_with_dev; - } - - CanardInstance ins = canardInit(&memallocate, &memfree); - - if (can_fd) - { - ins.mtu_bytes = CANARD_MTU_CAN_FD; - } - else - { - ins.mtu_bytes = CANARD_MTU_CAN_CLASSIC; - } - - ins.node_id = (pub ? CONFIG_EXAMPLES_LIBOPENCYPHAL_NODE_ID : - CONFIG_EXAMPLES_LIBOPENCYPHAL_NODE_ID + 1); - - /* Open the CAN device for reading */ - - canardsocketinstance sock_ins; - socketcanopen(&sock_ins, CONFIG_EXAMPLES_LIBOPENCYPHAL_DEV, can_fd); - - /* setup poll fd */ - - fd.fd = sock_ins.s; - fd.events = POLLIN; - - if (sock_ins.s < 0) - { - printf("canard_daemon: ERROR: open %s failed: %d\n", - CONFIG_EXAMPLES_LIBOPENCYPHAL_DEV, errno); - errval = 2; - goto errout_with_dev; - } - - printf("canard_daemon: canard initialized\n"); - printf("start node (ID: %d Name: %s MTU: %d PUB: %d TOPIC_SIZE: %d)\n", - ins.node_id, APP_NODE_NAME, ins.mtu_bytes, pub, TOPIC_SIZE); - - CanardRxSubscription heartbeat_subscription; - (void) canardRxSubscribe(&ins, /* Subscribe to messages uavcan.node.Heartbeat. */ - CanardTransferKindMessage, - 32085, /* The fixed Subject-ID of the Heartbeat message type (see DSDL definition). */ - 7, /* The maximum payload size (max DSDL object size) from the DSDL definition. */ - CANARD_DEFAULT_TRANSFER_ID_TIMEOUT_USEC, - &heartbeat_subscription); - - CanardRxSubscription my_subscription; - (void) canardRxSubscribe(&ins, - CanardTransferKindMessage, - PORT_ID, /* The Service-ID to subscribe to. */ - TOPIC_SIZE, /* The maximum payload size (max DSDL object size). */ - CANARD_DEFAULT_TRANSFER_ID_TIMEOUT_USEC, - &my_subscription); - - g_canard_daemon_started = true; - uint64_t next_1hz_service_at = getmonotonictimestampusec(); - - for (; ; ) - { - processtxrxonce(&ins, &sock_ins, 10); - - const uint64_t ts = getmonotonictimestampusec(); - - if (ts >= next_1hz_service_at) - { - next_1hz_service_at += 1000000; - process1hztasks(&ins, ts); - } - } - -errout_with_dev: - - g_canard_daemon_started = false; - printf("canard_daemon: Terminating!\n"); - fflush(stdout); - return errval; -} - -/**************************************************************************** - * Name: canard_main - * - * Description: - * - ****************************************************************************/ - -int opencyphal_main(int argc, FAR char *argv[]) -{ - int ret; - - printf("canard_main: Starting canard_daemon\n"); - - if (g_canard_daemon_started) - { - printf("canard_main: receive and send task already running\n"); - return EXIT_SUCCESS; - } - - ret = task_create("canard_daemon", - CONFIG_EXAMPLES_LIBOPENCYPHAL_DAEMON_PRIORITY, - CONFIG_EXAMPLES_LIBOPENCYPHAL_DAEMON_STACK_SIZE, - canard_daemon, argv); - - if (ret < 0) - { - int errcode = errno; - printf("canard_main: ERROR: Failed to start canard_daemon: %d\n", - errcode); - return EXIT_FAILURE; - } - - printf("canard_main: canard_daemon started\n"); - return EXIT_SUCCESS; -} diff --git a/examples/opencyphal/socketcan.c b/examples/opencyphal/socketcan.c deleted file mode 100644 index 378098337..000000000 --- a/examples/opencyphal/socketcan.c +++ /dev/null @@ -1,228 +0,0 @@ -/**************************************************************************** - * apps/examples/opencyphal/socketcan.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "socketcan.h" - -#include <net/if.h> -#include <sys/ioctl.h> -#include <string.h> -#include <stdio.h> - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -int16_t socketcanopen(canardsocketinstance *ins, - const char *const can_iface_name, const bool can_fd) -{ - struct sockaddr_can addr; - struct ifreq ifr; - - ins->can_fd = can_fd; - - /* open socket */ - - if ((ins->s = socket(PF_CAN, SOCK_RAW, CAN_RAW)) < 0) - { - perror("socket"); - return -1; - } - - strlcpy(ifr.ifr_name, can_iface_name, IFNAMSIZ); - ifr.ifr_ifindex = if_nametoindex(ifr.ifr_name); - - if (!ifr.ifr_ifindex) - { - perror("if_nametoindex"); - return -1; - } - - memset(&addr, 0, sizeof(addr)); - addr.can_family = AF_CAN; - addr.can_ifindex = ifr.ifr_ifindex; - - const int on = 1; - - /* RX Timestamping */ - - if (setsockopt(ins->s, SOL_SOCKET, SO_TIMESTAMP, &on, sizeof(on)) < 0) - { - perror("SO_TIMESTAMP is disabled"); - return -1; - } - - /* NuttX Feature: Enable TX deadline when sending CAN frames - * When a deadline occurs the driver will remove the CAN frame - */ - - if (setsockopt(ins->s, SOL_CAN_RAW, CAN_RAW_TX_DEADLINE, - &on, sizeof(on)) < 0) - { - perror("CAN_RAW_TX_DEADLINE is disabled"); - return -1; - } - - if (can_fd) - { - if (setsockopt(ins->s, SOL_CAN_RAW, CAN_RAW_FD_FRAMES, - &on, sizeof(on)) < 0) - { - perror("no CAN FD support"); - return -1; - } - } - - if (bind(ins->s, (struct sockaddr *)&addr, sizeof(addr)) < 0) - { - perror("bind"); - return -1; - } - - /* Setup TX msg */ - - ins->send_iov.iov_base = &ins->send_frame; - - if (ins->can_fd) - { - ins->send_iov.iov_len = sizeof(struct canfd_frame); - } - else - { - ins->send_iov.iov_len = sizeof(struct can_frame); - } - - memset(&ins->send_control, 0x00, sizeof(ins->send_control)); - - ins->send_msg.msg_iov = &ins->send_iov; - ins->send_msg.msg_iovlen = 1; - ins->send_msg.msg_control = &ins->send_control; - ins->send_msg.msg_controllen = sizeof(ins->send_control); - - ins->send_cmsg = CMSG_FIRSTHDR(&ins->send_msg); - ins->send_cmsg->cmsg_level = SOL_CAN_RAW; - ins->send_cmsg->cmsg_type = CAN_RAW_TX_DEADLINE; - ins->send_cmsg->cmsg_len = sizeof(struct timeval); - ins->send_tv = (struct timeval *)CMSG_DATA(&ins->send_cmsg); - - /* Setup RX msg */ - - ins->recv_iov.iov_base = &ins->recv_frame; - - if (can_fd) - { - ins->recv_iov.iov_len = sizeof(struct canfd_frame); - } - else - { - ins->recv_iov.iov_len = sizeof(struct can_frame); - } - - memset(&ins->recv_control, 0x00, sizeof(ins->recv_control)); - - ins->recv_msg.msg_iov = &ins->recv_iov; - ins->recv_msg.msg_iovlen = 1; - ins->recv_msg.msg_control = &ins->recv_control; - ins->recv_msg.msg_controllen = sizeof(ins->recv_control); - ins->recv_cmsg = CMSG_FIRSTHDR(&ins->recv_msg); - - return 0; -} - -int16_t socketcantransmit(canardsocketinstance *ins, const CanardFrame *txf) -{ - /* Copy CanardFrame to can_frame/canfd_frame */ - - if (ins->can_fd) - { - ins->send_frame.can_id = txf->extended_can_id; - ins->send_frame.can_id |= CAN_EFF_FLAG; - ins->send_frame.len = txf->payload_size; - memcpy(&ins->send_frame.data, txf->payload, txf->payload_size); - } - else - { - struct can_frame *frame = (struct can_frame *)&ins->send_frame; - frame->can_id = txf->extended_can_id; - frame->can_id |= CAN_EFF_FLAG; - frame->can_dlc = txf->payload_size; - memcpy(&frame->data, txf->payload, txf->payload_size); - } - - /* Set CAN_RAW_TX_DEADLINE timestamp */ - - ins->send_tv->tv_usec = txf->timestamp_usec % 1000000ULL; - ins->send_tv->tv_sec = (txf->timestamp_usec - ins->send_tv->tv_usec) - / 1000000ULL; - - return sendmsg(ins->s, &ins->send_msg, 0); -} - -int16_t socketcanreceive(canardsocketinstance *ins, CanardFrame *rxf) -{ - int32_t result = recvmsg(ins->s, &ins->recv_msg, 0); - - if (result < 0) - { - return result; - } - - /* Copy CAN frame to CanardFrame */ - - if (ins->can_fd) - { - struct canfd_frame *recv_frame = - (struct canfd_frame *)&ins->recv_frame; - rxf->extended_can_id = recv_frame->can_id & CAN_EFF_MASK; - rxf->payload_size = recv_frame->len; - rxf->payload = &recv_frame->data; - } - else - { - struct can_frame *recv_frame = (struct can_frame *)&ins->recv_frame; - rxf->extended_can_id = recv_frame->can_id & CAN_EFF_MASK; - rxf->payload_size = recv_frame->can_dlc; - rxf->payload = &recv_frame->data; - } - - /* Read SO_TIMESTAMP value */ - - if (ins->recv_cmsg->cmsg_level == SOL_SOCKET - && ins->recv_cmsg->cmsg_type == SO_TIMESTAMP) - { - struct timeval *tv = (struct timeval *)CMSG_DATA(ins->recv_cmsg); - rxf->timestamp_usec = tv->tv_sec * 1000000ULL + tv->tv_usec; - } - - return result; -} - -/* TODO implement corresponding IOCTL */ - -int16_t socketcanconfigurefilter(const fd_t fd, const size_t num_filters, - const struct can_filter *filters) -{ - return -1; -} diff --git a/examples/opencyphal/socketcan.h b/examples/opencyphal/socketcan.h deleted file mode 100644 index 8876813c7..000000000 --- a/examples/opencyphal/socketcan.h +++ /dev/null @@ -1,115 +0,0 @@ -/**************************************************************************** - * apps/examples/opencyphal/socketcan.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef SOCKETCAN_H_INCLUDED -#define SOCKETCAN_H_INCLUDED - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <stdbool.h> -#include <stddef.h> -#include <stdint.h> - -#include <sys/time.h> -#include <sys/socket.h> - -#include <nuttx/can.h> - -#include <canard.h> - -#ifdef __cplusplus -extern "C" -{ -#endif - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -typedef struct canardsocketinstance canardsocketinstance; -typedef int fd_t; - -struct canardsocketinstance -{ - fd_t s; - bool can_fd; - - /* Send msg structure */ - - struct iovec send_iov; - struct canfd_frame send_frame; - struct msghdr send_msg; - struct cmsghdr *send_cmsg; - struct timeval *send_tv; /* TX deadline timestamp */ - uint8_t send_control[sizeof(struct cmsghdr) - + sizeof(struct timeval)]; - - /* Receive msg structure */ - - struct iovec recv_iov; - struct canfd_frame recv_frame; - struct msghdr recv_msg; - struct cmsghdr *recv_cmsg; - uint8_t recv_control[sizeof(struct cmsghdr) - + sizeof(struct timeval)]; -}; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/* Creates a SocketCAN socket for corresponding iface can_iface_name - * Also sets up the message structures required for transmit and receive - * can_fd determines to use CAN FD frame when is 1, and classical CAN - * frame when is 0. The return value is 0 on succes and -1 on error - */ - -int16_t socketcanopen(canardsocketinstance *ins, - const char *const can_iface_name, - const bool can_fd); - -/* Send a CanardFrame to the canardsocketinstance socket - * This function is blocking - * The return value is number of bytes transferred, negative value on error. - */ - -int16_t socketcantransmit(canardsocketinstance *ins, const CanardFrame *txf); - -/* Receive a CanardFrame from the canardsocketinstance socket - * This function is blocking - * The return value is number of bytes received, negative value on error. - */ - -int16_t socketcanreceive(canardsocketinstance *ins, CanardFrame *rxf); - -/* TODO implement ioctl for CAN filter */ - -int16_t socketcanconfigurefilter(const fd_t fd, const size_t num_filters, - const struct can_filter *filters); - -#ifdef __cplusplus -} -#endif - -#endif //SOCKETCAN_H_INCLUDED diff --git a/examples/optee/CMakeLists.txt b/examples/optee/CMakeLists.txt deleted file mode 100644 index e843d6717..000000000 --- a/examples/optee/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# ############################################################################## -# apps/examples/optee/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_OPTEE) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_OPTEE_PROGNAME} - SRCS - optee_main.c - STACKSIZE - ${CONFIG_EXAMPLES_OPTEE_STACKSIZE} - PRIORITY - ${CONFIG_EXAMPLES_OPTEE_PRIORITY}) -endif() diff --git a/examples/optee/Kconfig b/examples/optee/Kconfig deleted file mode 100644 index 9e91beff6..000000000 --- a/examples/optee/Kconfig +++ /dev/null @@ -1,29 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config EXAMPLES_OPTEE - tristate "OP-TEE client example" - default n - ---help--- - Enable the OP-TEE client example - -if EXAMPLES_OPTEE - -config EXAMPLES_OPTEE_PROGNAME - string "Program name" - default "optee" - ---help--- - This is the name of the program that will be used when the NSH ELF - program is installed. - -config EXAMPLES_OPTEE_PRIORITY - int "OP-TEE task priority" - default 100 - -config EXAMPLES_OPTEE_STACKSIZE - int "OP-TEE stack size" - default DEFAULT_TASK_STACKSIZE - -endif diff --git a/examples/optee/Make.defs b/examples/optee/Make.defs deleted file mode 100644 index 8da4df36e..000000000 --- a/examples/optee/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/examples/optee/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_EXAMPLES_OPTEE),) -CONFIGURED_APPS += $(APPDIR)/examples/optee -endif diff --git a/examples/optee/optee_main.c b/examples/optee/optee_main.c deleted file mode 100644 index c089145d4..000000000 --- a/examples/optee/optee_main.c +++ /dev/null @@ -1,414 +0,0 @@ -/**************************************************************************** - * apps/examples/optee/optee_main.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> -#include <stdio.h> -#include <fcntl.h> -#include <stdlib.h> -#include <unistd.h> -#include <errno.h> -#include <sys/ioctl.h> -#include <sys/mman.h> -#include <nuttx/tee.h> -#include <uuid.h> - -/**************************************************************************** - * Pre-processor definitions - ****************************************************************************/ - -#undef USE_ALLOC_IOC - -#ifdef USE_ALLOC_IOC -# define tee_shm_alloc tee_shm_mmap -# define tee_shm_free_buf(p, s) munmap(p, s) -#else -# define tee_shm_alloc tee_shm_malloc -# define tee_shm_free_buf(p, s) ((void)s, free(p)) -#endif - -#define OPTEE_DEV "/dev/tee0" - -#define PTA_DEVICE_ENUM { 0x7011a688, 0xddde, 0x4053, \ - 0xa5, 0xa9, \ - { 0x7b, 0x3c, 0x4d, 0xdf, 0x13, 0xb8 } } - -#define PTA_CMD_GET_DEVICES 0x0 - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -typedef struct tee_shm -{ - int fd; - size_t size; - void *ptr; - int32_t id; -} tee_shm_t; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static int tee_check_version_and_caps(int fd, uint32_t *caps) -{ - struct tee_ioctl_version_data ioc_ver; - int ret; - - ret = ioctl(fd, TEE_IOC_VERSION, (unsigned long)&ioc_ver); - if (ret < 0) - { - printf("Failed to query TEE driver version and caps: %d, %s\n", - ret, strerror(errno)); - return ret; - } - - if (ioc_ver.impl_id != TEE_IMPL_ID_OPTEE) - { - printf("Not an OP-TEE implementation\n"); - return -ENOTSUP; - } - - if (!(ioc_ver.impl_caps & TEE_OPTEE_CAP_TZ)) - { - printf("OP-TEE TrustZone not supported\n"); - return -ENOTSUP; - } - - if (((TEE_GEN_CAP_GP | TEE_GEN_CAP_MEMREF_NULL) & ioc_ver.gen_caps) != - (TEE_GEN_CAP_GP | TEE_GEN_CAP_MEMREF_NULL)) - { - printf("CAP_GP or MEMREF_NULL not supported\n"); - return -ENOTSUP; - } - - printf("impl id: %u, impl caps: %u, gen caps: %u\n", - ioc_ver.impl_id, ioc_ver.impl_caps, ioc_ver.gen_caps); - - if (caps) - { - *caps = ioc_ver.gen_caps; - } - - return ret; -} - -static int tee_open_session(int fd, const uuid_t *uuid, uint32_t *session) -{ - struct tee_ioctl_open_session_arg ioc_opn; - struct tee_ioctl_buf_data ioc_buf; - int ret; - - memset(&ioc_opn, 0, sizeof(struct tee_ioctl_open_session_arg)); - - uuid_enc_be(&ioc_opn.uuid, uuid); - - ioc_buf.buf_ptr = (uintptr_t)&ioc_opn; - ioc_buf.buf_len = sizeof(struct tee_ioctl_open_session_arg); - - ret = ioctl(fd, TEE_IOC_OPEN_SESSION, (unsigned long)&ioc_buf); - if (ret < 0) - { - return ret; - } - - if (session) - { - *session = ioc_opn.session; - } - - return ret; -} - -static int tee_invoke(int fd, uint32_t session, uint32_t func, - struct tee_ioctl_param *params, size_t num_params) -{ - struct tee_ioctl_invoke_arg *ioc_args; - struct tee_ioctl_buf_data ioc_buf; - size_t ioc_args_len; - int ret; - - ioc_args_len = sizeof(struct tee_ioctl_invoke_arg) + - TEE_IOCTL_PARAM_SIZE(num_params); - - ioc_args = (struct tee_ioctl_invoke_arg *)calloc(1, ioc_args_len); - if (!ioc_args) - { - return -ENOMEM; - } - - ioc_args->func = func; - ioc_args->session = session; - ioc_args->num_params = num_params; - memcpy(&ioc_args->params, params, TEE_IOCTL_PARAM_SIZE(num_params)); - - ioc_buf.buf_ptr = (uintptr_t)ioc_args; - ioc_buf.buf_len = ioc_args_len; - - ret = ioctl(fd, TEE_IOC_INVOKE, (unsigned long)&ioc_buf); - if (ret < 0) - { - goto err_with_args; - } - - memcpy(params, &ioc_args->params, TEE_IOCTL_PARAM_SIZE(num_params)); - -err_with_args: - free(ioc_args); - - return ret; -} - -static int tee_shm_register(int fd, tee_shm_t *shm) -{ - struct tee_ioctl_shm_register_data ioc_reg; - - memset(&ioc_reg, 0, sizeof(struct tee_ioctl_shm_register_data)); - - if (!shm) - { - return -EINVAL; - } - - ioc_reg.addr = (uintptr_t)shm->ptr; - ioc_reg.length = shm->size; - - shm->fd = ioctl(fd, TEE_IOC_SHM_REGISTER, (unsigned long)&ioc_reg); - shm->id = ioc_reg.id; - - return shm->fd < 0 ? shm->fd : 0; -} - -#ifdef USE_ALLOC_IOC -static int tee_shm_mmap(int fd, tee_shm_t *shm, bool reg) -{ - struct tee_ioctl_shm_alloc_data ioc_alloc; - int ret = 0; - - memset(&ioc_alloc, 0, sizeof(struct tee_ioctl_shm_alloc_data)); - - if (!shm) - { - return -EINVAL; - } - - ioc_alloc.size = shm->size; - - shm->fd = ioctl(fd, TEE_IOC_SHM_ALLOC, (unsigned long)&ioc_alloc); - if (shm->fd < 0) - { - return shm->fd; - } - - shm->ptr = mmap(NULL, shm->size, PROT_READ | PROT_WRITE, MAP_SHARED, - shm->fd, 0); - if (shm->ptr == MAP_FAILED) - { - close(shm->fd); - return -ENOMEM; - } - - if (reg) - { - ret = tee_shm_register(fd, shm); - if (ret < 0) - { - munmap(shm->ptr, shm->size); - close(shm->fd); - return ret; - } - } - - return ret; -} - -#else /* !USE_ALLOC_IOC */ -static int tee_shm_malloc(int fd, tee_shm_t *shm, bool reg) -{ - int ret = 0; - - if (!shm) - { - return -EINVAL; - } - - shm->ptr = malloc(shm->size); - if (!shm->ptr) - { - return -ENOMEM; - } - - shm->fd = -1; - - if (reg) - { - ret = tee_shm_register(fd, shm); - if (ret < 0) - { - free(shm->ptr); - } - } - - return ret; -} -#endif /* !USE_ALLOC_IOC */ - -static void tee_shm_free(tee_shm_t *shm) -{ - if (!shm) - { - return; - } - - tee_shm_free_buf(shm->ptr, shm->size); - - if (shm->fd >= 0) - { - close(shm->fd); - } - - shm->ptr = NULL; - shm->fd = -1; -} - -static int tee_close_session(int fd, uint32_t session) -{ - struct tee_ioctl_close_session_arg ioc_close; - int ret; - - ioc_close.session = session; - - ret = ioctl(fd, TEE_IOC_CLOSE_SESSION, (unsigned long)&ioc_close); - - return ret; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * optee_main - ****************************************************************************/ - -int main(int argc, FAR char *argv[]) -{ - int fd; - uint32_t caps; - const uuid_t pta_dvc_uuid = PTA_DEVICE_ENUM; - uint32_t session; - struct tee_ioctl_param par0; - tee_shm_t shm; - unsigned int count; - const uuid_t *raw_ta_uuid; - uuid_t ta_uuid; - char *ta_uuid_s; - int ret; - - memset(&par0, 0, sizeof(struct tee_ioctl_param)); - memset(&shm, 0, sizeof(tee_shm_t)); - - fd = open(OPTEE_DEV, O_RDONLY | O_NONBLOCK); - if (fd < 0) - { - printf("Failed to open " OPTEE_DEV ": %s\n", strerror(errno)); - return -errno; - } - - ret = tee_check_version_and_caps(fd, &caps); - if (ret < 0) - { - goto err; - } - - ret = tee_open_session(fd, &pta_dvc_uuid, &session); - if (ret < 0) - { - printf("Failed to open session with devices.pta: %d, %s\n", - ret, strerror(errno)); - goto err; - } - - par0.attr = TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_OUTPUT; - par0.c = TEE_MEMREF_NULL; - - ret = tee_invoke(fd, session, PTA_CMD_GET_DEVICES, &par0, 1); - if (ret < 0) - { - printf("Failed to get size needed for device enumeration: %d, %s\n", - ret, strerror(errno)); - goto err_with_session; - } - - shm.size = par0.b; - - ret = tee_shm_alloc(fd, &shm, caps & TEE_GEN_CAP_REG_MEM); - if (ret < 0) - { - printf("Failed to allocate shared memory: %d, %s\n", - ret, strerror(errno)); - goto err_with_session; - } - - par0.attr = TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_OUTPUT; - par0.a = 0; - par0.b = shm.size; - par0.c = shm.id; - - ret = tee_invoke(fd, session, PTA_CMD_GET_DEVICES, &par0, 1); - if (ret < 0) - { - printf("Failed to enumerate devices: %d, %s\n", ret, strerror(errno)); - goto err_with_shm; - } - - printf("Available devices:\n"); - - count = par0.b / sizeof(uuid_t); - raw_ta_uuid = (uuid_t *)shm.ptr; - - while (count--) - { - uuid_dec_be(raw_ta_uuid, &ta_uuid); - uuid_to_string(&ta_uuid, &ta_uuid_s, NULL); - - printf(" %s\n", ta_uuid_s); - - free(ta_uuid_s); - raw_ta_uuid++; - } - -err_with_shm: - tee_shm_free(&shm); - -err_with_session: - tee_close_session(fd, session); - -err: - close(fd); - - return ret; -} diff --git a/examples/optee_gp/CMakeLists.txt b/examples/optee_gp/CMakeLists.txt deleted file mode 100644 index 4840c7d7e..000000000 --- a/examples/optee_gp/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# ############################################################################## -# apps/examples/optee_gp/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_OPTEE_GP) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_OPTEE_GP_PROGNAME} - SRCS - optee_gp_main.c - STACKSIZE - ${CONFIG_EXAMPLES_OPTEE_GP_STACKSIZE} - PRIORITY - ${CONFIG_EXAMPLES_OPTEE_GP_PRIORITY} - DEPENDS - libteec) -endif() diff --git a/examples/optee_gp/Kconfig b/examples/optee_gp/Kconfig deleted file mode 100644 index 46b1ae947..000000000 --- a/examples/optee_gp/Kconfig +++ /dev/null @@ -1,30 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config EXAMPLES_OPTEE_GP - tristate "OP-TEE GP API client example" - depends on LIBTEEC - default n - ---help--- - Enable the OP-TEE GP API client example which uses libteec - -if EXAMPLES_OPTEE_GP - -config EXAMPLES_OPTEE_GP_PROGNAME - string "Program name" - default "optee_gp" - ---help--- - This is the name of the program that will be used when the NSH ELF - program is installed. - -config EXAMPLES_OPTEE_GP_PRIORITY - int "OP-TEE GP task priority" - default 100 - -config EXAMPLES_OPTEE_GP_STACKSIZE - int "OP-TEE GP stack size" - default DEFAULT_TASK_STACKSIZE - -endif diff --git a/examples/optee_gp/Make.defs b/examples/optee_gp/Make.defs deleted file mode 100644 index e732a4c5b..000000000 --- a/examples/optee_gp/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/examples/optee_gp/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_EXAMPLES_OPTEE_GP),) -CONFIGURED_APPS += $(APPDIR)/examples/optee_gp -endif diff --git a/examples/optee_gp/Makefile b/examples/optee_gp/Makefile deleted file mode 100644 index 02fb022cc..000000000 --- a/examples/optee_gp/Makefile +++ /dev/null @@ -1,34 +0,0 @@ -############################################################################ -# apps/examples/optee_gp/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -# OP-TEE GP API client built-in application info - -PROGNAME = $(CONFIG_EXAMPLES_OPTEE_GP_PROGNAME) -PRIORITY = $(CONFIG_EXAMPLES_OPTEE_GP_PRIORITY) -STACKSIZE = $(CONFIG_EXAMPLES_OPTEE_GP_STACKSIZE) -MODULE = $(CONFIG_EXAMPLES_OPTEE_GP) - -MAINSRC = optee_gp_main.c - -include $(APPDIR)/Application.mk diff --git a/examples/optee_gp/optee_gp_main.c b/examples/optee_gp/optee_gp_main.c deleted file mode 100644 index b88aba694..000000000 --- a/examples/optee_gp/optee_gp_main.c +++ /dev/null @@ -1,190 +0,0 @@ -/**************************************************************************** - * apps/examples/optee_gp/optee_gp_main.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> -#include <nuttx/tee.h> -#include <tee_client_api.h> -#include <teec_trace.h> -#include <uuid.h> - -/**************************************************************************** - * Pre-processor definitions - ****************************************************************************/ - -/* This UUID is taken from the OP-TEE OS built-in pseudo TA: - * https://github.com/OP-TEE/optee_os/blob/4.6.0/ - * lib/libutee/include/pta_device.h - */ -#define PTA_DEVICE_ENUM_UUID \ - { \ - 0x7011a688, 0xddde, 0x4053, \ - { \ - 0xa5, 0xa9, 0x7b, 0x3c, 0x4d, 0xdf, 0x13, 0xb8 \ - } \ - } - -#define PTA_CMD_GET_DEVICES 0x0 - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * optee_gp_main - ****************************************************************************/ - -int main(int argc, FAR char *argv[]) -{ - TEEC_Result res; - TEEC_Context ctx; - TEEC_Session sess; - TEEC_Operation op; - TEEC_UUID uuid = PTA_DEVICE_ENUM_UUID; - void *buf; - TEEC_SharedMemory io_shm; - uint32_t err_origin; - unsigned int count; - const uuid_t *raw_ta_uuid; - uuid_t ta_uuid; - char *ta_uuid_s; - - res = TEEC_InitializeContext(NULL, &ctx); - if (res != TEEC_SUCCESS) - { - EMSG("TEEC_InitializeContext failed with code 0x%08x\n", res); - goto exit; - } - - memset(&op, 0, sizeof(op)); - - /* Open a session with the devices pseudo TA */ - - res = TEEC_OpenSession(&ctx, &sess, &uuid, TEEC_LOGIN_PUBLIC, NULL, - &op, &err_origin); - if (res != TEEC_SUCCESS) - { - EMSG("TEEC_Opensession failed with code 0x%08x origin 0x%08x", res, - err_origin); - goto exit_with_ctx; - } - - /* Invoke command with NULL buffer to get required size */ - - op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_OUTPUT, TEEC_NONE, - TEEC_NONE, TEEC_NONE); - op.params[0].tmpref.buffer = NULL; - op.params[0].tmpref.size = 0; - - res = TEEC_InvokeCommand(&sess, PTA_CMD_GET_DEVICES, &op, &err_origin); - if (err_origin != TEEC_ORIGIN_TRUSTED_APP || - res != TEEC_ERROR_SHORT_BUFFER) - { - EMSG("TEEC_InvokeCommand failed: code 0x%08x origin 0x%08x", - res, err_origin); - goto exit_with_session; - } - - /* Invoke command using temporary memory */ - - op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_OUTPUT, TEEC_NONE, - TEEC_NONE, TEEC_NONE); - - op.params[0].tmpref.buffer = buf = malloc(op.params[0].tmpref.size); - if (!op.params[0].tmpref.buffer) - { - EMSG("Failed to allocate %zu bytes of memory to share with TEE", - op.params[0].tmpref.size); - goto exit_with_session; - } - - res = TEEC_InvokeCommand(&sess, PTA_CMD_GET_DEVICES, &op, &err_origin); - if (res != TEEC_SUCCESS) - { - EMSG("TEEC_InvokeCommand failed: code 0x%08x origin 0x%08x", - res, err_origin); - goto exit_with_buf; - } - - /* Invoke command using pre-allocated, pre-registered memory */ - - io_shm.size = op.params[0].tmpref.size; - io_shm.flags = TEEC_MEM_OUTPUT; - res = TEEC_AllocateSharedMemory(&ctx, &io_shm); - if (res != TEEC_SUCCESS) - { - EMSG("TEEC_AllocateSharedMemory failed: code 0x%08x", res); - goto exit_with_buf; - } - - op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_WHOLE, TEEC_NONE, TEEC_NONE, - TEEC_NONE); - op.params[0].memref.parent = &io_shm; - - res = TEEC_InvokeCommand(&sess, PTA_CMD_GET_DEVICES, &op, &err_origin); - if (res != TEEC_SUCCESS) - { - EMSG("TEEC_InvokeCommand failed: code 0x%08x origin 0x%08x", - res, err_origin); - goto exit_with_shm; - } - - /* Sanity check that both outputs are the same */ - - if (memcmp(buf, io_shm.buffer, io_shm.size)) - { - EMSG("Different results with temp vs registered memory"); - goto exit_with_shm; - } - - /* Print results to stdout */ - - IMSG("Available devices:"); - - count = io_shm.size / sizeof(uuid_t); - raw_ta_uuid = (uuid_t *)io_shm.buffer; - - while (count--) - { - uuid_dec_be(raw_ta_uuid, &ta_uuid); - uuid_to_string(&ta_uuid, &ta_uuid_s, NULL); - - IMSG(" %s", ta_uuid_s); - - free(ta_uuid_s); - raw_ta_uuid++; - } - -exit_with_shm: - TEEC_ReleaseSharedMemory(&io_shm); -exit_with_buf: - free(buf); -exit_with_session: - TEEC_CloseSession(&sess); -exit_with_ctx: - TEEC_FinalizeContext(&ctx); -exit: - return res; -} diff --git a/examples/pca9635/CMakeLists.txt b/examples/pca9635/CMakeLists.txt deleted file mode 100644 index 459fe370a..000000000 --- a/examples/pca9635/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# ############################################################################## -# apps/examples/pca9635/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_PCA9635) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_PCA9635_PROGNAME} - STACKSIZE - ${CONFIG_DEFAULT_TASK_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_PCA9635} - SRCS - pca9635_main.c) -endif() diff --git a/examples/pca9635/Kconfig b/examples/pca9635/Kconfig index 631420d78..b406017a5 100644 --- a/examples/pca9635/Kconfig +++ b/examples/pca9635/Kconfig @@ -6,7 +6,6 @@ config EXAMPLES_PCA9635 tristate "PCA9635 PWM LED example" default n - depends on PCA9635PW ---help--- Enable the PCA9635 example diff --git a/examples/pca9635/Make.defs b/examples/pca9635/Make.defs index c9909027e..5093e997c 100644 --- a/examples/pca9635/Make.defs +++ b/examples/pca9635/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/pca9635/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/pca9635/Makefile b/examples/pca9635/Makefile index 1b399bde3..18f0de298 100644 --- a/examples/pca9635/Makefile +++ b/examples/pca9635/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/pca9635/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/pca9635/pca9635_main.c b/examples/pca9635/pca9635_main.c index 28ad428f1..7fd00ddcb 100644 --- a/examples/pca9635/pca9635_main.c +++ b/examples/pca9635/pca9635_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/pca9635/pca9635_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -32,7 +30,6 @@ #include <fcntl.h> #include <errno.h> #include <stdio.h> -#include <unistd.h> #include <nuttx/leds/pca9635pw.h> @@ -62,7 +59,7 @@ int main(int argc, FAR char *argv[]) int fd; int ret; - fd = open(CONFIG_EXAMPLES_PCA9635_DEVNAME, 0); + fd = open(CONFIG_EXAMPLES_PCA9635_DEVNAME, O_WRONLY); if (fd < 0) { fprintf(stderr, "ERROR: Failed to open %s: %d\n", diff --git a/examples/pdcurses/CMakeLists.txt b/examples/pdcurses/CMakeLists.txt deleted file mode 100644 index 462dad6b1..000000000 --- a/examples/pdcurses/CMakeLists.txt +++ /dev/null @@ -1,132 +0,0 @@ -# ############################################################################## -# apps/examples/pdcurses/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_PDCURSES) - target_sources(apps PRIVATE tui.c) - nuttx_add_application( - NAME - charset - PRIORITY - ${CONFIG_EXAMPLES_PDCURSES_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_PDCURSES_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_PDCURSES} - SRCS - charset_main.c) - - nuttx_add_application( - NAME - firework - PRIORITY - ${CONFIG_EXAMPLES_PDCURSES_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_PDCURSES_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_PDCURSES} - SRCS - firework_main.c) - - nuttx_add_application( - NAME - newdemo - PRIORITY - ${CONFIG_EXAMPLES_PDCURSES_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_PDCURSES_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_PDCURSES} - SRCS - newdemo_main.c) - - nuttx_add_application( - NAME - panel - PRIORITY - ${CONFIG_EXAMPLES_PDCURSES_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_PDCURSES_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_PDCURSES} - SRCS - panel_main.c) - - nuttx_add_application( - NAME - rain - PRIORITY - ${CONFIG_EXAMPLES_PDCURSES_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_PDCURSES_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_PDCURSES} - SRCS - rain_main.c) - - nuttx_add_application( - NAME - testcurs - PRIORITY - ${CONFIG_EXAMPLES_PDCURSES_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_PDCURSES_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_PDCURSES} - SRCS - testcurs_main.c) - - nuttx_add_application( - NAME - tui - PRIORITY - ${CONFIG_EXAMPLES_PDCURSES_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_PDCURSES_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_PDCURSES} - SRCS - tui_main.c) - - nuttx_add_application( - NAME - worm - PRIORITY - ${CONFIG_EXAMPLES_PDCURSES_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_PDCURSES_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_PDCURSES} - SRCS - worm_main.c) - - nuttx_add_application( - NAME - xmas - PRIORITY - ${CONFIG_EXAMPLES_PDCURSES_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_PDCURSES_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_PDCURSES} - SRCS - xmas_main.c) -endif() diff --git a/examples/pdcurses/Make.defs b/examples/pdcurses/Make.defs index 119f39683..bbd979834 100644 --- a/examples/pdcurses/Make.defs +++ b/examples/pdcurses/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/pdcurses/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/pdcurses/Makefile b/examples/pdcurses/Makefile index 0ebf82c3e..743485152 100644 --- a/examples/pdcurses/Makefile +++ b/examples/pdcurses/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/pdcurses/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/pdcurses/README.md b/examples/pdcurses/README.md new file mode 100644 index 000000000..2bce03f9c --- /dev/null +++ b/examples/pdcurses/README.md @@ -0,0 +1,17 @@ +# Examples / `pdcurses` PDCurses Demos + +This directory contains demonstration programs to show and test the capabilities +of `pdcurses` libraries. Some of them predate PDCurses, PCcurses or even +`pcurses`/`ncurses`. Although some PDCurses-specific code has been added, all +programs remain portable to other implementations (at a minimum, to `ncurses`). + +## Building + +The demos are built by the platform-specific makefiles, in the platform +directories. There are no dependencies besides curses and the standard C +library, and no configuration is needed. + +## Distribution Status + +Public Domain, except for `rain_main.c` and `worm_main.c`, which are under the +ncurses license (MIT-like). diff --git a/examples/pdcurses/charset_main.c b/examples/pdcurses/charset_main.c index a7baceeaf..46a4e8eb1 100644 --- a/examples/pdcurses/charset_main.c +++ b/examples/pdcurses/charset_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/pdcurses/charset_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/pdcurses/firework_main.c b/examples/pdcurses/firework_main.c index ec8034264..7fe718ae3 100644 --- a/examples/pdcurses/firework_main.c +++ b/examples/pdcurses/firework_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/pdcurses/firework_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -163,7 +161,7 @@ int main(int argc, FAR char *argv[]) init_pair(i, color_table[i], COLOR_BLACK); } - seed = time(NULL); + seed = time((time_t *) 0); srand(seed); flag = 0; diff --git a/examples/pdcurses/newdemo_main.c b/examples/pdcurses/newdemo_main.c index aea60acf5..1e34c9f01 100644 --- a/examples/pdcurses/newdemo_main.c +++ b/examples/pdcurses/newdemo_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/pdcurses/newdemo_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -305,7 +303,7 @@ int main(int argc, FAR char *argv[]) traceon(); initscr(); - seed = time(NULL); + seed = time((time_t *) 0); srand(seed); start_color(); @@ -318,8 +316,8 @@ int main(int argc, FAR char *argv[]) curs_set(0); noecho(); - /* Refresh stdscr so that reading from it will not cause it to overwrite - * the other windows that are being created. + /* Refresh stdscr so that reading from it will not cause it to overwrite the + * other windows that are being created. */ refresh(); @@ -337,7 +335,7 @@ int main(int argc, FAR char *argv[]) return 1; } - for (; ; ) + for (;;) { init_pair(1, COLOR_WHITE, COLOR_BLUE); wbkgd(win, COLOR_PAIR(1)); @@ -435,7 +433,7 @@ int main(int argc, FAR char *argv[]) for (i = w + msg_len; i > 0; i--) { memset(visbuf, ' ', w); - strlcpy(scrollbuf + i, message, msg_len); + strncpy(scrollbuf + i, message, msg_len); mvwaddnstr(win, height / 2, 1, visbuf, w); wrefresh(win); diff --git a/examples/pdcurses/panel_main.c b/examples/pdcurses/panel_main.c index e9b252c17..8c8095902 100644 --- a/examples/pdcurses/panel_main.c +++ b/examples/pdcurses/panel_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/pdcurses/panel_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/pdcurses/rain_main.c b/examples/pdcurses/rain_main.c index dfd3ec776..703afc294 100644 --- a/examples/pdcurses/rain_main.c +++ b/examples/pdcurses/rain_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/pdcurses/rain_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/pdcurses/testcurs_main.c b/examples/pdcurses/testcurs_main.c index 759cee9e6..14ac2ed88 100644 --- a/examples/pdcurses/testcurs_main.c +++ b/examples/pdcurses/testcurs_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/pdcurses/testcurs_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -31,10 +29,13 @@ #include <stdio.h> #include <ctype.h> #include <string.h> -#include <sys/param.h> #include "graphics/curses.h" +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + #ifdef WACS_S1 # define HAVE_WIDE 1 #else @@ -47,10 +48,6 @@ # include <wchar.h> #endif -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - #ifdef A_COLOR # define HAVE_COLOR 1 #else @@ -114,19 +111,19 @@ static const COMMAND command[] = {"Scroll Test", scroll_test}, {"Input Test", input_test}, {"Output Test", output_test}, - {"ACS Test", acs_test}, + {"ACS Test", acs_test} #if HAVE_COLOR - {"Color Test", color_test}, + , {"Color Test", color_test} #endif #if HAVE_CLIPBOARD - {"Clipboard Test", clipboard_test}, + , {"Clipboard Test", clipboard_test} #endif #if HAVE_WIDE - {"Wide Input", wide_test}, + , {"Wide Input", wide_test} #endif }; -#define MAX_OPTIONS nitems(command) +#define MAX_OPTIONS (sizeof(command) / sizeof(COMMAND)) static int height; static int width; @@ -141,9 +138,9 @@ static const char *acs_names[] = "ACS_PLMINUS", "ACS_BULLET", "ACS_LARROW", "ACS_RARROW", "ACS_UARROW", "ACS_DARROW", - "ACS_BOARD", "ACS_LANTERN", "ACS_BLOCK", + "ACS_BOARD", "ACS_LANTERN", "ACS_BLOCK" #ifdef ACS_S3 - "ACS_S3", "ACS_S7", "ACS_LEQUAL", "ACS_GEQUAL", + , "ACS_S3", "ACS_S7", "ACS_LEQUAL", "ACS_GEQUAL", "ACS_PI", "ACS_NEQUAL", "ACS_STERLING" #endif }; @@ -242,7 +239,6 @@ static int init_test(WINDOW ** win, int argc, char *argv[]) start_color(); } #endif - /* Create a drawing window */ width = 60; @@ -360,7 +356,7 @@ static void input_test(WINDOW *win) sw = w / 3; sh = h / 3; - if (!(subWin = subwin(win, sh, sw, by + h - sh - 2, bx + w - sw - 2))) + if ((subWin = subwin(win, sh, sw, by + h - sh - 2, bx + w - sw - 2)) == NULL) { return; } @@ -682,7 +678,7 @@ static void output_test(WINDOW *win) wattron(win1, A_BLINK); mvwaddstr(win1, 4, 1, - "This blinking text should appear in only the second window"); + "This blinking text should appear in only the second window"); wattroff(win1, A_BLINK); mvwin(win1, by, bx); @@ -729,7 +725,7 @@ static void output_test(WINDOW *win) wclear(win); wmove(win, 2, 2); - wprintw(win, "This is a formatted string in a window: %d is it\n", 42); + wprintw(win, "This is a formatted string in a window: %d %s\n", 42, "is it"); mvwaddstr(win, 10, 1, "Enter a string: "); wrefresh(win); echo(); @@ -893,8 +889,7 @@ static void clipboard_test(WINDOW *win) FAR struct pdc_context_s *ctx = PDC_ctx(); #endif - mvaddstr(1, 1, - "This test will display the contents of the system clipboard"); + mvaddstr(1, 1, "This test will display the contents of the system clipboard"); continue2(); @@ -927,7 +922,7 @@ static void clipboard_test(WINDOW *win) clear(); mvaddstr(1, 1, - "This test will place the following string in the system clipboard:"); + "This test will place the following string in the system clipboard:"); mvaddstr(2, 1, text); i = PDC_setclipboard(text, strlen(text)); @@ -1081,8 +1076,7 @@ static void color_test(WINDOW *win) for (j = 0; j < 16; j++) { mvaddch(tmarg + i + 5, col2 + j, fill | COLOR_PAIR(i + 4)); - mvaddch(tmarg + i + 5, col3 + j, - fill | COLOR_PAIR(i + 4) | A_BOLD); + mvaddch(tmarg + i + 5, col3 + j, fill | COLOR_PAIR(i + 4) | A_BOLD); } } @@ -1099,7 +1093,7 @@ static void color_test(WINDOW *win) short red; short green; short blue; - }orgcolors[16]; + } orgcolors[16]; int MAXCOL = (COLORS >= 16) ? 16 : 8; @@ -1135,8 +1129,7 @@ static void color_test(WINDOW *win) for (i = 0; i < MAXCOL; i++) { - init_color(i, orgcolors[i].red, - orgcolors[i].green, orgcolors[i].blue); + init_color(i, orgcolors[i].red, orgcolors[i].green, orgcolors[i].blue); } } } @@ -1181,8 +1174,7 @@ void display_menu(int old_option, int new_option) #ifdef CONFIG_PDCURSES_MULTITHREAD FAR struct pdc_context_s *ctx = PDC_ctx(); #endif - int lmarg = (COLS - 14) / 2; - int tmarg = (LINES - (MAX_OPTIONS + 2)) / 2; + int lmarg = (COLS - 14) / 2, tmarg = (LINES - (MAX_OPTIONS + 2)) / 2; if (old_option == -1) { diff --git a/examples/pdcurses/tui.c b/examples/pdcurses/tui.c index 70084a6ea..a124ac2c3 100644 --- a/examples/pdcurses/tui.c +++ b/examples/pdcurses/tui.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/pdcurses/tui.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -43,7 +41,7 @@ ****************************************************************************/ #ifdef A_COLOR -# define TITLECOLOR 1 /* color pair indices */ +# define TITLECOLOR 1 /* color pair indices */ # define MAINMENUCOLOR (2 | A_BOLD) # define MAINMENUREVCOLOR (3 | A_BOLD | A_REVERSE) # define SUBMENUCOLOR (4 | A_BOLD) @@ -53,7 +51,7 @@ # define INPUTBOXCOLOR 8 # define EDITBOXCOLOR (9 | A_BOLD | A_REVERSE) #else -# define TITLECOLOR 0 /* color pair indices */ +# define TITLECOLOR 0 /* color pair indices */ # define MAINMENUCOLOR (A_BOLD) # define MAINMENUREVCOLOR (A_BOLD | A_REVERSE) # define SUBMENUCOLOR (A_BOLD) @@ -64,11 +62,11 @@ # define EDITBOXCOLOR (A_BOLD | A_REVERSE) #endif -#define th 1 /* title window height */ -#define mh 1 /* main menu height */ -#define sh 2 /* status window height */ +#define th 1 /* title window height */ +#define mh 1 /* main menu height */ +#define sh 2 /* status window height */ #define bh (LINES - th - mh - sh) /* body window height */ -#define bw COLS /* body window width */ +#define bw COLS /* body window width */ /**************************************************************************** * Private Data @@ -94,9 +92,8 @@ static char *padstr(char *s, int length) static char buf[MAXSTRLEN]; char fmt[10]; - snprintf(fmt, sizeof(fmt), - (int)strlen(s) > length ? "%%.%ds" : "%%-%ds", length); - snprintf(buf, sizeof(buf), fmt, s); + sprintf(fmt, (int)strlen(s) > length ? "%%.%ds" : "%%-%ds", length); + sprintf(buf, fmt, s); return buf; } @@ -209,7 +206,7 @@ static void idle(void) } tp = localtime(&t); - snprintf(buf, sizeof(buf), " %.2d-%.2d-%.4d %.2d:%.2d:%.2d", + sprintf(buf, " %.2d-%.2d-%.4d %.2d:%.2d:%.2d", tp->tm_mday, tp->tm_mon + 1, tp->tm_year + 1900, tp->tm_hour, tp->tm_min, tp->tm_sec); @@ -301,12 +298,7 @@ static void mainhelp(void) static void mainmenu(menu *mp) { - int nitems; - int barlen; - int c; - int cur0; - int old = -1; - int cur = 0; + int nitems, barlen, old = -1, cur = 0, c, cur0; menudim(mp, &nitems, &barlen); repaintmainmenu(barlen, mp); @@ -607,12 +599,13 @@ void domenu(const menu *mp) do { cur = (cur + 1) % nitems; + } - while ((cur != cur0) && (hotkey(mp[cur].name) - != toupper((int)key))); + while ((cur != cur0) && (hotkey(mp[cur].name) != toupper((int)key))); key = (hotkey(mp[cur].name) == toupper((int)key)) ? '\n' : ERR; } + } rmerror(); @@ -699,27 +692,18 @@ static void repainteditbox(WINDOW *win, int x, char *buf) int weditstr(WINDOW *win, char *buf, int field) { - char org[MAXSTRLEN]; - char *tp; - char *bp = buf; - bool defdisp = true; - bool stop = false; - bool insert = false; - int cury; - int curx; - int begy; - int begx; - int oldattr; - int c = 0; + char org[MAXSTRLEN], *tp, *bp = buf; + bool defdisp = true, stop = false, insert = false; + int cury, curx, begy, begx, oldattr; WINDOW *wedit; + int c = 0; - if ((field >= MAXSTRLEN) || (buf == NULL) || - ((int)strlen(buf) > field - 1)) + if ((field >= MAXSTRLEN) || (buf == NULL) || ((int)strlen(buf) > field - 1)) { return ERR; } - strlcpy(org, buf, sizeof(org)); /* save original */ + strcpy(org, buf); /* save original */ wrefresh(win); getyx(win, cury, curx); @@ -776,7 +760,7 @@ int weditstr(WINDOW *win, char *buf, int field) case KEY_DC: if (*bp != 0) { - memmove((void *)(bp), (const void *)(bp + 1), strlen(bp)); + memmove((void *)(bp), (const void *)(bp+1), strlen(bp)); } break; @@ -785,8 +769,7 @@ int weditstr(WINDOW *win, char *buf, int field) { if (bp > buf) { - memmove((void *)(bp - 1), (const void *)bp, - strlen(bp) + 1); + memmove((void *)(bp - 1), (const void *)bp, strlen(bp) + 1); bp--; } } @@ -851,10 +834,7 @@ int weditstr(WINDOW *win, char *buf, int field) WINDOW *winputbox(WINDOW *win, int nlines, int ncols) { WINDOW *winp; - int cury; - int curx; - int begy; - int begx; + int cury, curx, begy, begx; getyx(win, cury, curx); getbegyx(win, begy, begx); @@ -868,16 +848,7 @@ WINDOW *winputbox(WINDOW *win, int nlines, int ncols) int getstrings(const char *desc[], char *buf[], int field) { WINDOW *winput; - int oldy; - int oldx; - int maxy; - int maxx; - int nlines; - int ncols; - int i; - int n; - int l; - int mmax = 0; + int oldy, oldx, maxy, maxx, nlines, ncols, i, n, l, mmax = 0; int c = 0; bool stop = false; diff --git a/examples/pdcurses/tui.h b/examples/pdcurses/tui.h index e989562d9..f7abba784 100644 --- a/examples/pdcurses/tui.h +++ b/examples/pdcurses/tui.h @@ -1,7 +1,5 @@ /**************************************************************************** - * apps/examples/pdcurses/tui.h - * - * SPDX-License-Identifier: Apache-2.0 + * apps/examples/pdcurses/tui.c * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with diff --git a/examples/pdcurses/tui_main.c b/examples/pdcurses/tui_main.c index 0a9ef0e3d..9d7a5531d 100644 --- a/examples/pdcurses/tui_main.c +++ b/examples/pdcurses/tui_main.c @@ -1,7 +1,5 @@ /**************************************************************************** - * apps/examples/pdcurses/tui_main.c - * - * SPDX-License-Identifier: Apache-2.0 + * apps/examples/pdcurses/tui.c * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -72,21 +70,11 @@ static const char *g_fieldname[6] = menu g_mainmenu[] = { -{ - "Asub", sub0, "Go inside first submenu" -}, -{ - "Bsub", sub1, "Go inside second submenu" -}, -{ - "Csub", sub2, "Go inside third submenu" -}, -{ - "Dsub", sub3, "Go inside fourth submenu" -}, -{ - "", (FUNC)0, "" /* always add this as the last item! */ -} + {"Asub", sub0, "Go inside first submenu"}, + {"Bsub", sub1, "Go inside second submenu"}, + {"Csub", sub2, "Go inside third submenu"}, + {"Dsub", sub3, "Go inside fourth submenu"}, + {"", (FUNC)0, ""} /* always add this as the last item! */ }; static const menu g_submenu0[] = @@ -157,8 +145,7 @@ static char *getfname(char *desc, char *fname, int field) fieldname[1] = 0; fieldbuf[0] = fname; - return (getstrings((const char **)fieldname, - fieldbuf, field) == KEY_ESC) ? NULL : fname; + return (getstrings((const char **)fieldname, fieldbuf, field) == KEY_ESC) ? NULL : fname; } static void showfile(char *fname) @@ -206,7 +193,7 @@ static void showfile(char *fname) } else { - snprintf(buf, sizeof(buf), "ERROR: file '%s' not found", fname); + sprintf(buf, "ERROR: file '%s' not found", fname); errormsg(buf); } } @@ -253,7 +240,7 @@ static void subfunc2(void) { char fname[MAXSTRLEN]; - strlcpy(fname, FNAME, sizeof(fname)); + strcpy(fname, FNAME); if (getfname("File to browse:", fname, 50)) { showfile(fname); @@ -275,7 +262,6 @@ int main(int argc, FAR char *argv[]) setlocale(LC_ALL, ""); #endif - startmenu(g_mainmenu, - "TUI - 'textual user interface' demonstration program"); + startmenu(g_mainmenu, "TUI - 'textual user interface' demonstration program"); return 0; } diff --git a/examples/pdcurses/worm_main.c b/examples/pdcurses/worm_main.c index 7e3d0c488..84bba04d5 100644 --- a/examples/pdcurses/worm_main.c +++ b/examples/pdcurses/worm_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/pdcurses/rain_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/pdcurses/xmas_main.c b/examples/pdcurses/xmas_main.c index 83542d592..3168b509e 100644 --- a/examples/pdcurses/xmas_main.c +++ b/examples/pdcurses/xmas_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/pdcurses/tui.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/pf_ieee802154/CMakeLists.txt b/examples/pf_ieee802154/CMakeLists.txt deleted file mode 100644 index e02fe47ce..000000000 --- a/examples/pf_ieee802154/CMakeLists.txt +++ /dev/null @@ -1,48 +0,0 @@ -# ############################################################################## -# apps/examples/pf_ieee802154/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_PFIEEE802154) - target_sources(apps PRIVATE pf_cmdline.c) - nuttx_add_application( - NAME - pfserver - PRIORITY - ${CONFIG_EXAMPLES_PFIEEE802154_PRIORITY1} - STACKSIZE - ${CONFIG_EXAMPLES_PFIEEE802154_STACKSIZE1} - MODULE - ${CONFIG_EXAMPLES_PFIEEE802154} - SRCS - pf_server.c) - - nuttx_add_application( - NAME - pfclient - PRIORITY - ${CONFIG_EXAMPLES_PFIEEE802154_PRIORITY1} - STACKSIZE - ${CONFIG_EXAMPLES_PFIEEE802154_STACKSIZE1} - MODULE - ${CONFIG_EXAMPLES_PFIEEE802154} - SRCS - pf_client.c) -endif() diff --git a/examples/pf_ieee802154/Make.defs b/examples/pf_ieee802154/Make.defs index db390a0a5..09c9f0bef 100644 --- a/examples/pf_ieee802154/Make.defs +++ b/examples/pf_ieee802154/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/pf_ieee802154/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/pf_ieee802154/Makefile b/examples/pf_ieee802154/Makefile index fab3910a9..1c8929aa5 100644 --- a/examples/pf_ieee802154/Makefile +++ b/examples/pf_ieee802154/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/pf_ieee802154/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/pf_ieee802154/pf_client.c b/examples/pf_ieee802154/pf_client.c index 3c4092290..b8cbbae92 100644 --- a/examples/pf_ieee802154/pf_client.c +++ b/examples/pf_ieee802154/pf_client.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/pf_ieee802154/pf_client.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/pf_ieee802154/pf_cmdline.c b/examples/pf_ieee802154/pf_cmdline.c index 6dfb6890d..1fa694948 100644 --- a/examples/pf_ieee802154/pf_cmdline.c +++ b/examples/pf_ieee802154/pf_cmdline.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/pf_ieee802154/pf_cmdline.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/pf_ieee802154/pf_server.c b/examples/pf_ieee802154/pf_server.c index 8b0ba87f5..5996012a7 100644 --- a/examples/pf_ieee802154/pf_server.c +++ b/examples/pf_ieee802154/pf_server.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/pf_ieee802154/pf_server.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/pf_ieee802154/pfieee802154.h b/examples/pf_ieee802154/pfieee802154.h index adf9e3bd6..86baf2c73 100644 --- a/examples/pf_ieee802154/pfieee802154.h +++ b/examples/pf_ieee802154/pfieee802154.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/pf_ieee802154/pfieee802154.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -27,7 +25,7 @@ * Included Files ****************************************************************************/ -#include <nuttx/debug.h> +#include <debug.h> #include <netpacket/ieee802154.h> /**************************************************************************** diff --git a/examples/pipe/CMakeLists.txt b/examples/pipe/CMakeLists.txt deleted file mode 100644 index 505689e3e..000000000 --- a/examples/pipe/CMakeLists.txt +++ /dev/null @@ -1,34 +0,0 @@ -# ############################################################################## -# apps/examples/pipe/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_PIPE) - nuttx_add_application( - NAME - pipe - STACKSIZE - ${CONFIG_DEFAULT_TASK_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_PIPE} - SRCS - pipe_main.c) - target_sources(apps PRIVATE transfer_test.c interlock_test.c redirect_test.c) -endif() diff --git a/examples/pipe/Make.defs b/examples/pipe/Make.defs index cc32907bd..08e63cfef 100644 --- a/examples/pipe/Make.defs +++ b/examples/pipe/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/pipe/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/pipe/Makefile b/examples/pipe/Makefile index cac461a69..5358908fd 100644 --- a/examples/pipe/Makefile +++ b/examples/pipe/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/pipe/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/pipe/interlock_test.c b/examples/pipe/interlock_test.c index cb2985800..887674870 100644 --- a/examples/pipe/interlock_test.c +++ b/examples/pipe/interlock_test.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/pipe/interlock_test.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -25,14 +23,14 @@ ****************************************************************************/ #include <nuttx/config.h> - -#include <errno.h> -#include <fcntl.h> -#include <pthread.h> -#include <stdio.h> #include <sys/stat.h> + #include <sys/types.h> + +#include <stdio.h> +#include <fcntl.h> #include <unistd.h> +#include <errno.h> #include "pipe.h" @@ -52,50 +50,6 @@ * Private Functions ****************************************************************************/ -/**************************************************************************** - * Name: null_reader - ****************************************************************************/ - -static void *null_reader(pthread_addr_t pvarg) -{ - int fd; - - /* Wait a bit */ - - printf("null_reader: started -- sleeping\n"); - sleep(5); - - /* Then open the FIFO for read access */ - - printf("null_reader: Opening FIFO for read access\n"); - fd = open(FIFO_PATH2, O_RDONLY); - if (fd < 0) - { - fprintf(stderr, \ - "null_reader: Failed to open FIFO %s for reading, errno=%d\n", - FIFO_PATH2, errno); - return (void *)(uintptr_t)1; - } - - /* Wait a bit more */ - - printf("null_reader: Opened %s for reading -- sleeping\n", FIFO_PATH2); - sleep(5); - - /* Then close the FIFO */ - - printf("null_reader: Closing %s\n", FIFO_PATH2); - if (close(fd) != 0) - { - fprintf(stderr, "null_reader: close failed: %d\n", errno); - } - - sleep(5); - - printf("null_reader: Returning success\n"); - return NULL; -} - /**************************************************************************** * Name: null_writer ****************************************************************************/ @@ -115,10 +69,9 @@ static void *null_writer(pthread_addr_t pvarg) fd = open(FIFO_PATH2, O_WRONLY); if (fd < 0) { - fprintf(stderr, \ - "null_writer: Failed to open FIFO %s for writing, errno=%d\n", + fprintf(stderr, "null_writer: Failed to open FIFO %s for writing, errno=%d\n", FIFO_PATH2, errno); - return (void *)(uintptr_t)1; + return (void*)1; } /* Wait a bit more */ @@ -133,11 +86,10 @@ static void *null_writer(pthread_addr_t pvarg) { fprintf(stderr, "null_writer: close failed: %d\n", errno); } - sleep(5); printf("null_writer: Returning success\n"); - return NULL; + return (void*)0; } /**************************************************************************** @@ -150,11 +102,11 @@ static void *null_writer(pthread_addr_t pvarg) int interlock_test(void) { - pthread_t tid; + pthread_t writerid; void *value; char data[16]; ssize_t nbytes; - int fd = -1; + int fd; int ret; /* Create a FIFO */ @@ -162,64 +114,55 @@ int interlock_test(void) ret = mkfifo(FIFO_PATH2, 0666); if (ret < 0) { - fprintf(stderr, \ - "interlock_test: mkfifo failed with errno=%d\n", errno); + fprintf(stderr, "interlock_test: mkfifo failed with errno=%d\n", errno); return 1; } - /* Start the null_writer thread */ + /* Start the null_writer_thread */ printf("interlock_test: Starting null_writer thread\n"); - ret = pthread_create(&tid, NULL, null_writer, NULL); + ret = pthread_create(&writerid, NULL, null_writer, (pthread_addr_t)NULL); if (ret != 0) { - fprintf(stderr, \ - "interlock_test: Failed to create null_writer thread," - "error=%d\n", ret); + fprintf(stderr, "interlock_test: Failed to create null_writer thread, error=%d\n", ret); ret = 2; goto errout_with_fifo; } - /* Open one end of the FIFO for reading. This open call should block until - * the null_writer thread opens the other end of the FIFO for writing. + /* Open one end of the FIFO for reading. This open call should block until the + * null_writer thread opens the other end of the FIFO for writing. */ printf("interlock_test: Opening FIFO for read access\n"); fd = open(FIFO_PATH2, O_RDONLY); if (fd < 0) { - fprintf(stderr, \ - "interlock_test: Failed to open FIFO %s for reading" - "errno=%d\n", + fprintf(stderr, "interlock_test: Failed to open FIFO %s for reading, errno=%d\n", FIFO_PATH2, errno); ret = 3; - goto errout_with_null_thread; + goto errout_with_thread; } - /* Attempt to read one byte from the FIFO. This should return end-of-file - * because the null_writer closes the FIFO without writing anything. + /* Attempt to read one byte from the FIFO. This should return end-of-file because + * the null_writer closes the FIFO without writing anything. */ printf("interlock_test: Reading from %s\n", FIFO_PATH2); nbytes = read(fd, data, 16); - if (nbytes < 0) + if (nbytes < 0 ) { - fprintf(stderr, \ - "interlock_test: read failed, errno=%d\n", errno); + fprintf(stderr, "interlock_test: read failed, errno=%d\n", errno); ret = 4; goto errout_with_file; } - else if (nbytes != 0) + else if (ret != 0) { - fprintf(stderr, \ - "interlock_test: Read %ld bytes of data -- aborting: %d\n", + fprintf(stderr, "interlock_test: Read %ld bytes of data -- aborting: %d\n", (long)nbytes, errno); ret = 5; goto errout_with_file; } - printf("interlock_test: read returned\n"); - /* Close the file */ printf("interlock_test: Closing %s\n", FIFO_PATH2); @@ -228,134 +171,40 @@ int interlock_test(void) fprintf(stderr, "interlock_test: close failed: %d\n", errno); } - fd = -1; - /* Wait for null_writer thread to complete */ printf("interlock_test: Waiting for null_writer thread\n"); - ret = pthread_join(tid, &value); + ret = pthread_join(writerid, &value); if (ret != 0) { - fprintf(stderr, \ - "interlock_test: pthread_join failed, error=%d\n", ret); + fprintf(stderr, "interlock_test: pthread_join failed, error=%d\n", ret); ret = 6; goto errout_with_fifo; } else { - printf("interlock_test: writer returned %p\n", value); - if (value != NULL) + printf("interlock_test: writer returned %d\n", (int)value); + if (value != (void*)0) { ret = 7; goto errout_with_fifo; } } - /* Start the null_reader thread */ - - printf("interlock_test: Starting null_reader thread\n"); - ret = pthread_create(&tid, NULL, null_reader, NULL); - if (ret != 0) - { - fprintf(stderr, \ - "interlock_test: Failed to create null_reader thread," - "error=%d\n", ret); - ret = 8; - goto errout_with_fifo; - } - - /* Open one end of the FIFO for writing. This open call should block until - * the null_reader thread opens the other end of the FIFO for reading. - */ - - printf("interlock_test: Opening FIFO for write access\n"); - fd = open(FIFO_PATH2, O_WRONLY); - if (fd < 0) - { - fprintf(stderr, \ - "interlock_test: Failed to open FIFO %s for writing," - "errno=%d\n", - FIFO_PATH2, errno); - ret = 9; - goto errout_with_null_thread; - } - - /* Attempt to write one byte from the FIFO. This should return n bytes - * written since the null_reader has opened the FIFO. - */ - - printf("interlock_test: Writing to %s\n", FIFO_PATH2); - nbytes = write(fd, data, 16); - if (nbytes <= 0) - { - fprintf(stderr, \ - "interlock_test: write failed, errno=%d\n", errno); - ret = 10; - goto errout_with_file; - } - else - { - fprintf(stderr, \ - "interlock_test: Wrote %ld bytes of data\n", (long)nbytes); - } - - printf("interlock_test: write returned\n"); - - /* Close the file */ - - printf("interlock_test: Closing %s\n", FIFO_PATH2); - if (close(fd) != 0) - { - fprintf(stderr, "interlock_test: close failed: %d\n", errno); - } - - fd = -1; - - /* Wait for null_reader thread to complete */ - - printf("interlock_test: Waiting for null_reader thread\n"); - ret = pthread_join(tid, &value); - if (ret != 0) - { - fprintf(stderr, \ - "interlock_test: pthread_join failed, error=%d\n", ret); - ret = 12; - goto errout_with_fifo; - } - else - { - printf("interlock_test: reader returned %p\n", value); - if (value != NULL) - { - ret = 13; - goto errout_with_fifo; - } - } - - ret = 0; - goto errout_with_fifo; + /* unlink(FIFO_PATH2); */ + printf("interlock_test: Returning success\n"); + return 0; errout_with_file: if (close(fd) != 0) { fprintf(stderr, "interlock_test: close failed: %d\n", errno); } - -errout_with_null_thread: - pthread_detach(tid); - pthread_cancel(tid); - +errout_with_thread: + pthread_detach(writerid); + pthread_cancel(writerid); errout_with_fifo: - - /* Close the file */ - - ret = remove(FIFO_PATH2); - if (ret != 0) - { - fprintf(stderr, \ - "interlock_test: remove failed with errno=%d\n", errno); - } - + /* unlink(FIFO_PATH2); */ printf("interlock_test: Returning %d\n", ret); return ret; } diff --git a/examples/pipe/pipe.h b/examples/pipe/pipe.h index 9dc14b4c1..6ce7c06bb 100644 --- a/examples/pipe/pipe.h +++ b/examples/pipe/pipe.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/pipe/pipe.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -35,8 +33,8 @@ * Pre-processor Definitions ****************************************************************************/ -#define FIFO_PATH1 "/var/testfifo-1" -#define FIFO_PATH2 "/var/testfifo-2" +#define FIFO_PATH1 "/tmp/testfifo-1" +#define FIFO_PATH2 "/tmp/testfifo-2" /**************************************************************************** * Public Types @@ -50,8 +48,7 @@ * Public Function Prototypes ****************************************************************************/ -extern int transfer_test(int fdin, int fdout, - int boost_reader, int boost_writer); +extern int transfer_test(int fdin, int fdout); extern int interlock_test(void); extern int redirection_test(void); diff --git a/examples/pipe/pipe_main.c b/examples/pipe/pipe_main.c index c34f281f5..224fe0328 100644 --- a/examples/pipe/pipe_main.c +++ b/examples/pipe/pipe_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/pipe/pipe_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -32,35 +30,9 @@ #include <sched.h> #include <fcntl.h> #include <errno.h> -#include <pthread.h> #include "pipe.h" -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: open_write_only - ****************************************************************************/ - -static void *open_write_only(pthread_addr_t pvarg) -{ - void *fd_addr = (void *)pvarg; - - fprintf(stderr, "open_write_only: Opening FIFO for write access\n"); - ((int *)fd_addr)[1] = open(FIFO_PATH1, O_WRONLY); - if (((int *)fd_addr)[1] < 0) - { - fprintf(stderr, \ - "open_write_only: Failed to open FIFO %s for writing," - "errno=%d\n", FIFO_PATH1, errno); - return (void *)(uintptr_t)1; - } - - return NULL; -} - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -79,16 +51,7 @@ int main(int argc, FAR char *argv[]) #if CONFIG_DEV_FIFO_SIZE > 0 /* Test FIFO logic */ - fprintf(stderr, "\npipe_main: Performing FIFO test\n"); - - pthread_t writeonly; - void *status; - - /* Open one end of the FIFO for reading and the other end for writing. - * NOTE: This test's result is expected to be the same on any other - * POSIX-compliant system. NuttX FIFOs block for write-only and - * read-only (see interlock_test()). - */ + printf("\npipe_main: Performing FIFO test\n"); ret = mkfifo(FIFO_PATH1, 0666); if (ret < 0) @@ -97,12 +60,18 @@ int main(int argc, FAR char *argv[]) return 1; } - ret = pthread_create(&writeonly, NULL, open_write_only, &fd); + /* Open one end of the FIFO for reading and the other end for writing. + * NOTE: The following might not work on most FIFO implementations because + * the attempt to open just one end of the FIFO for writing might block. + * The NuttX FIFOs block only on open for read-only (see interlock_test()). + */ - if (ret < 0) + fd[1] = open(FIFO_PATH1, O_WRONLY); + if (fd[1] < 0) { - fprintf(stderr, "redirection_test: " - "Failed to create open_write_only task: %d\n", ret); + fprintf(stderr, + "pipe_main: Failed to open FIFO %s for writing, errno=%d\n", + FIFO_PATH1, errno); return 2; } @@ -120,58 +89,9 @@ int main(int argc, FAR char *argv[]) return 3; } - /* Wait for open_write_only thread to complete */ - - fprintf(stderr, "open_write_only: Waiting for open_write_only thread\n"); - ret = pthread_join(writeonly, &status); - if (ret != 0) - { - fprintf(stderr, "pipe_main: pthread_join failed, error=%d\n", ret); - return 4; - } - else - { - fprintf(stderr, "pipe_main: open_write_only returned %p\n", status); - if (status != NULL) - { - return 5; - } - } - /* Then perform the test using those file descriptors */ - ret = transfer_test(fd[0], fd[1], 0, 0); - - if (ret != 0) - { - fprintf(stderr, "pipe_main: FIFO test FAILED (00) (%d)\n", ret); - return 6; - } - - ret = transfer_test(fd[0], fd[1], 1, 0); - - if (ret != 0) - { - fprintf(stderr, "pipe_main: FIFO test FAILED (10) (%d)\n", ret); - return 6; - } - - ret = transfer_test(fd[0], fd[1], 0, 1); - - if (ret != 0) - { - fprintf(stderr, "pipe_main: FIFO test FAILED (01)(%d)\n", ret); - return 6; - } - - ret = transfer_test(fd[0], fd[1], 1, 1); - - if (ret != 0) - { - fprintf(stderr, "pipe_main: FIFO test FAILED (11) (%d)\n", ret); - return 6; - } - + ret = transfer_test(fd[0], fd[1]); if (close(fd[0]) != 0) { fprintf(stderr, "pipe_main: close failed: %d\n", errno); @@ -187,18 +107,51 @@ int main(int argc, FAR char *argv[]) if (ret != 0) { fprintf(stderr, "pipe_main: FIFO test FAILED (%d)\n", ret); + return 4; + } + + printf("pipe_main: FIFO test PASSED\n"); + +#else + printf("\npipe_main: Skipping FIFO test\n"); + +#endif /* CONFIG_DEV_FIFO_SIZE > 0 */ + +#if CONFIG_DEV_PIPE_SIZE > 0 + /* Test PIPE logic */ + + printf("\npipe_main: Performing pipe test\n"); + + ret = pipe(fd); + if (ret < 0) + { + fprintf(stderr, "pipe_main: pipe failed with errno=%d\n", errno); + return 5; + } + + /* Then perform the test using those file descriptors */ + + ret = transfer_test(fd[0], fd[1]); + if (close(fd[0]) != 0) + { + fprintf(stderr, "pipe_main: close failed: %d\n", errno); + } + if (close(fd[1]) != 0) + { + fprintf(stderr, "pipe_main: close failed: %d\n", errno); + } + + if (ret != 0) + { + fprintf(stderr, "pipe_main: PIPE test FAILED (%d)\n", ret); return 6; } - ret = remove(FIFO_PATH1); - if (ret != 0) - { - fprintf(stderr, "pipe_main: remove failed with errno=%d\n", errno); - } + printf("pipe_main: PIPE test PASSED\n"); /* Perform the FIFO interlock test */ - fprintf(stderr, "\npipe_main: Performing pipe interlock test\n"); + printf("\npipe_main: Performing pipe interlock test\n"); ret = interlock_test(); if (ret != 0) { @@ -206,90 +159,25 @@ int main(int argc, FAR char *argv[]) return 7; } - fprintf(stderr, "pipe_main: FIFO interlock test PASSED\n"); - - fprintf(stderr, "pipe_main: FIFO test PASSED\n"); - -#else - fprintf(stderr, "\npipe_main: Skipping FIFO test\n"); - -#endif /* CONFIG_DEV_FIFO_SIZE > 0 */ - -#if CONFIG_DEV_PIPE_SIZE > 0 - /* Test PIPE logic */ - - fprintf(stderr, "\npipe_main: Performing pipe test\n"); - - ret = pipe(fd); - if (ret < 0) - { - fprintf(stderr, "pipe_main: pipe failed with errno=%d\n", errno); - return 8; - } - - /* Then perform the test using those file descriptors */ - - ret = transfer_test(fd[0], fd[1], 0, 0); - - if (ret != 0) - { - fprintf(stderr, "pipe_main: PIPE test FAILED (00) (%d)\n", ret); - return 9; - } - - ret = transfer_test(fd[0], fd[1], 1, 0); - - if (ret != 0) - { - fprintf(stderr, "pipe_main: PIPE test FAILED (10) (%d)\n", ret); - return 9; - } - - ret = transfer_test(fd[0], fd[1], 0, 1); - - if (ret != 0) - { - fprintf(stderr, "pipe_main: PIPE test FAILED (01) (%d)\n", ret); - return 9; - } - - ret = transfer_test(fd[0], fd[1], 1, 1); - - if (ret != 0) - { - fprintf(stderr, "pipe_main: PIPE test FAILED (11) (%d)\n", ret); - return 9; - } - - if (close(fd[0]) != 0) - { - fprintf(stderr, "pipe_main: close failed: %d\n", errno); - } - - if (close(fd[1]) != 0) - { - fprintf(stderr, "pipe_main: close failed: %d\n", errno); - } + printf("pipe_main: PIPE interlock test PASSED\n"); /* Perform the pipe redirection test */ - fprintf(stderr, "\npipe_main: Performing redirection test\n"); + printf("\npipe_main: Performing redirection test\n"); ret = redirection_test(); if (ret != 0) { - fprintf(stderr, "pipe_main: PIPE redirection test FAILED (%d)\n", ret); - return 10; + fprintf(stderr, "pipe_main: FIFO redirection test FAILED (%d)\n", ret); + return 7; } - fprintf(stderr, "pipe_main: PIPE redirection test PASSED\n"); - - fprintf(stderr, "pipe_main: PIPE test PASSED\n"); + printf("pipe_main: PIPE redirection test PASSED\n"); #else - fprintf(stderr, "\npipe_main: Skipping pipe test\n"); + printf("\npipe_main: Skipping pipe test\n"); #endif /* CONFIG_DEV_PIPE_SIZE > 0 */ - fflush(stderr); + fflush(stdout); return 0; } diff --git a/examples/pipe/redirect_test.c b/examples/pipe/redirect_test.c index 838929588..5e1dbb256 100644 --- a/examples/pipe/redirect_test.c +++ b/examples/pipe/redirect_test.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/pipe/redirect_test.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -26,13 +24,12 @@ #include <nuttx/config.h> -#include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sched.h> +#include <semaphore.h> #include <errno.h> -#include <pthread.h> #include "pipe.h" @@ -42,6 +39,12 @@ #define READ_SIZE 37 +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static sem_t g_rddone; + /**************************************************************************** * Private Functions ****************************************************************************/ @@ -50,39 +53,63 @@ * Name: redirect_reader ****************************************************************************/ -static void *redirect_reader(pthread_addr_t pvarg) +static int redirect_reader(int argc, char *argv[]) { char buffer[READ_SIZE]; - int *fd = (int *)pvarg; int fdin; + int fdout; int ret; int nbytes = 0; - fprintf(stderr, "redirect_reader: started with fdin=%d\n", fd[0]); + printf("redirect_reader: started with fdin=%s\n", argv[1]); - fdin = fd[0]; + /* Convert the fdin to binary */ + + fdin = atoi(argv[1]); + fdout = atoi(argv[2]); + + /* Close fdout -- we don't need it */ + + ret = close(fdout); + if (ret != 0) + { + fprintf(stderr, "redirect_reader: failed to close fdout=%d\n", + fdout); + return 1; + } /* Re-direct the fdin to stdin */ ret = dup2(fdin, 0); - if (ret < 0) + if (ret != 0) { - fprintf(stderr, "redirect_reader: dup2 failed: %d\n", errno); - close(fdin); - return (void *)(uintptr_t)1; + fprintf(stderr, "redirect_reader: dup2 failed: %d\n", errno); + close(fdin); + return 2; + } + + /* Close the original file descriptor */ + + ret = close(fdin); + if (ret != 0) + { + fprintf(stderr, "redirect_reader: failed to close fdin=%d\n", fdin); + return 3; } /* Then read from stdin until we hit the end of file */ - for (; ; ) + fflush(stdout); + for (;;) { /* Read from stdin */ ret = read(0, buffer, READ_SIZE); - if (ret < 0) + if (ret < 0 ) { - fprintf(stderr, "redirect_reader: read failed, errno=%d\n", errno); - return (void *)(uintptr_t)2; + fprintf(stderr, "redirect_reader: read failed, errno=%d\n", + errno); + return 4; } else if (ret == 0) { @@ -93,85 +120,93 @@ static void *redirect_reader(pthread_addr_t pvarg) /* Echo to stdout */ - ret = write(2, buffer, ret); + ret = write(1, buffer, ret); if (ret < 0) { - fprintf(stderr, "redirect_reader: write failed, errno=%d\n", - errno); - return (void *)(uintptr_t)3; + fprintf(stderr, "redirect_reader: read failed, errno=%d\n", + errno); + return 5; } } - fprintf(stderr, "redirect_reader: %d bytes read\n", nbytes); + printf("redirect_reader: %d bytes read\n", nbytes); ret = close(0); if (ret != 0) { - fprintf(stderr, "redirect_reader: failed to close fd=0\n"); - return (void *)(uintptr_t)4; + fprintf(stderr, "redirect_reader: failed to close fd=0\n"); + return 6; } - fprintf(stderr, "redirect_reader: Returning success\n"); - return NULL; + sem_post(&g_rddone); + printf("redirect_reader: Returning success\n"); + return 0; } /**************************************************************************** * Name: redirect_writer ****************************************************************************/ -static void *redirect_writer(pthread_addr_t pvarg) +static int redirect_writer(int argc, char *argv[]) { - int *fd = (int *)pvarg; + int fdin; int fdout; int nbytes = 0; int ret; - fprintf(stderr, "redirect_writer: started with fdout=%d\n", fd[1]); + fprintf(stderr, "redirect_writer: started with fdout=%s\n", argv[2]); - fdout = fd[1]; + /* Convert the fdout to binary */ + + fdin = atoi(argv[1]); + fdout = atoi(argv[2]); + + /* Close fdin -- we don't need it */ + + ret = close(fdin); + if (ret != 0) + { + fprintf(stderr, "redirect_reader: failed to close fdin=%d\n", fdin); + return 1; + } /* Re-direct the fdout to stdout */ ret = dup2(fdout, 1); - if (ret < 0) + if (ret != 0) { - fprintf(stderr, "redirect_writer: dup2 failed: %d\n", ret); - return (void *)(uintptr_t)1; + fprintf(stderr, "redirect_writer: dup2 failed: %d\n", errno); + return 2; + } + + /* Close the original file descriptor */ + + ret = close(fdout); + if (ret != 0) + { + fprintf(stderr, "redirect_reader: failed to close fdout=%d\n", + fdout); + return 3; } /* Then write a bunch of stuff to stdout */ - fflush(stdout); - nbytes += printf("\nFour score and seven years ago our fathers brought" - "forth on this continent a new nation,\n"); - nbytes += printf("conceived in Liberty, and dedicated to the proposition" - "that all men are created equal.\n"); - nbytes += printf("\nNow we are engaged in a great civil war, testing" - "whether that nation, or any nation, so\n"); - nbytes += printf("conceived and so dedicated, can long endure. We are met" - "on a great battle-field of that war.\n"); - nbytes += printf("We have come to dedicate a portion of that field, as a" - "final resting place for those who here\n"); - nbytes += printf("gave their lives that that nation might live. It is" - "altogether fitting and proper that we\n"); + fflush(stderr); + nbytes += printf("\nFour score and seven years ago our fathers brought forth on this continent a new nation,\n"); + nbytes += printf("conceived in Liberty, and dedicated to the proposition that all men are created equal.\n"); + nbytes += printf("\nNow we are engaged in a great civil war, testing whether that nation, or any nation, so\n"); + nbytes += printf("conceived and so dedicated, can long endure. We are met on a great battle-field of that war.\n"); + nbytes += printf("We have come to dedicate a portion of that field, as a final resting place for those who here\n"); + nbytes += printf("gave their lives that that nation might live. It is altogether fitting and proper that we\n"); nbytes += printf("should do this.\n"); - nbytes += printf("\nBut, in a larger sense, we can not dedicate - we can" - "not consecrate - we can not hallow - this ground.\n"); - nbytes += printf("The brave men, living and dead, who struggled here, have" - "consecrated it, far above our poor power\n"); - nbytes += printf("to add or detract. The world will little note, nor long" - "remember what we say here, but it can\n"); - nbytes += printf("never forget what they did here. It is for us the" - "living, rather, to be dedicated here to the\n"); - nbytes += printf("unfinished work which they who fought here have thus far" - "so nobly advanced. It is rather for us to\n"); - nbytes += printf("be here dedicated to the great task remaining before us" - "- that from these honored dead we take\n"); - nbytes += printf("increased devotion to that cause for which they gave the" - "last full measure of devotion - that we\n"); - nbytes += printf("here highly resolve that these dead shall not have died" - "in vain - that this nation, under God,\n"); - nbytes += printf("shall have a new birth of freedom - and that government" - "of the people, by the people, for the\n"); + nbytes += printf("\nBut, in a larger sense, we can not dedicate - we can not consecrate - we can not hallow - this ground.\n"); + nbytes += printf("The brave men, living and dead, who struggled here, have consecrated it, far above our poor power\n"); + nbytes += printf("to add or detract. The world will little note, nor long remember what we say here, but it can\n"); + nbytes += printf("never forget what they did here. It is for us the living, rather, to be dedicated here to the\n"); + nbytes += printf("unfinished work which they who fought here have thus far so nobly advanced. It is rather for us to\n"); + nbytes += printf("be here dedicated to the great task remaining before us - that from these honored dead we take\n"); + nbytes += printf("increased devotion to that cause for which they gave the last full measure of devotion - that we\n"); + nbytes += printf("here highly resolve that these dead shall not have died in vain - that this nation, under God,\n"); + nbytes += printf("shall have a new birth of freedom - and that government of the people, by the people, for the\n"); nbytes += printf("people, shall not perish from the earth.\n\n"); fflush(stdout); @@ -180,19 +215,12 @@ static void *redirect_writer(pthread_addr_t pvarg) ret = close(1); if (ret != 0) { - fprintf(stderr, "redirect_writer: failed to close fd=1\n"); - return (void *)(uintptr_t)2; - } - - ret = close(fdout); - if (ret != 0) - { - fprintf(stderr, "redirect_writer: failed to close fdout\n"); - return (void *)(uintptr_t)4; + fprintf(stderr, "redirect_writer: failed to close fd=1\n"); + return 4; } fprintf(stderr, "redirect_writer: Returning success\n"); - return NULL; + return 0; } /**************************************************************************** @@ -205,75 +233,66 @@ static void *redirect_writer(pthread_addr_t pvarg) int redirection_test(void) { - pthread_t readerid; - pthread_t writerid; - void *value; + const char *argv[3]; + char buffer1[8]; + char buffer2[8]; + int readerid; + int writerid; int fd[2]; int ret; - /* Create the pipe */ + sem_init(&g_rddone, 0, 0); + + /* Create the pipe */ ret = pipe(fd); if (ret < 0) { - fprintf(stderr, "redirection_test: pipe failed with errno=%d\n", + fprintf(stderr, "redirection_test: pipe failed with errno=%d\n", errno); + return 5; + } + + sprintf(buffer1, "%d", fd[0]); + argv[0] = buffer1; + sprintf(buffer2, "%d", fd[1]); + argv[1] = buffer2; + argv[2] = NULL; + + /* Start redirect_reader thread */ + + printf("redirection_test: Starting redirect_reader task with fd=%d\n", fd[0]); + readerid = task_create("redirect_reader", 50, CONFIG_EXAMPLES_PIPE_STACKSIZE, + redirect_reader, (FAR char * const *)argv); + if (readerid < 0) + { + fprintf(stderr, + "redirection_test: Failed to create redirect_writer task: %d\n", errno); return 1; } /* Start redirect_writer task */ - fprintf(stderr, - "redirection_test: Starting redirect_writer task with fd=%d\n", - fd[1]); - ret = pthread_create(&writerid, NULL, redirect_writer, fd); - if (ret < 0) + printf("redirection_test: Starting redirect_writer task with fd=%d\n", fd[1]); + writerid = task_create("redirect_writer", 50, CONFIG_EXAMPLES_PIPE_STACKSIZE, + redirect_writer, (FAR char * const *)argv); + if (writerid < 0) { - fprintf(stderr, "redirection_test: " - "Failed to create redirect_writer task: %d\n", errno); - ret = pthread_cancel(writerid); + fprintf(stderr, + "redirection_test: Failed to create redirect_writer task: %d\n", + errno); + + ret = task_delete(readerid); if (ret != 0) { - fprintf(stderr, "redirection_test: " - "Failed to delete redirect_reader task %d\n", errno); + fprintf(stderr, + "redirection_test: Failed to delete redirect_reader task %d\n", + errno); } return 2; } - /* Start redirect_reader thread */ - - fprintf(stderr, - "redirection_test: Starting redirect_reader task with fd=%d\n", - fd[0]); - ret = pthread_create(&readerid, NULL, redirect_reader, fd); - - if (ret < 0) - { - fprintf(stderr, "redirection_test: " - "Failed to create redirect_writer task: %d\n", ret); - return 3; - } - - /* Wait for redirect_reader thread to complete */ - - fprintf(stderr, "redirection_test: Waiting for null_reader thread\n"); - ret = pthread_join(readerid, &value); - if (ret != 0) - { - fprintf(stderr, \ - "interlock_test: pthread_join failed, error=%d\n", ret); - ret = 4; - } - else - { - printf("interlock_test: reader returned %p\n", value); - if (value != NULL) - { - ret = 5; - } - } - /* We should be able to close the pipe file descriptors now. */ if (close(fd[0]) != 0) @@ -281,11 +300,23 @@ int redirection_test(void) fprintf(stderr, "pipe_main: close failed: %d\n", errno); } + if (close(fd[1]) != 0) + { + fprintf(stderr, "pipe_main: close failed: %d\n", errno); + } + + if (ret != 0) + { + fprintf(stderr, "pipe_main: PIPE test FAILED (%d)\n", ret); + return 6; + } + /* Wait for redirect_writer thread to complete */ - fprintf(stderr, "redirection_test: Waiting...\n"); + printf("redirection_test: Waiting...\n"); fflush(stdout); + sem_wait(&g_rddone); - fprintf(stderr, "redirection_test: returning %d\n", ret); + printf("redirection_test: returning %d\n", ret); return ret; } diff --git a/examples/pipe/transfer_test.c b/examples/pipe/transfer_test.c index 5c929ca51..c7162ad04 100644 --- a/examples/pipe/transfer_test.c +++ b/examples/pipe/transfer_test.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/pipe/transfer_test.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -26,10 +24,9 @@ #include <nuttx/config.h> -#include <errno.h> -#include <pthread.h> #include <stdio.h> #include <unistd.h> +#include <errno.h> #include "pipe.h" @@ -66,70 +63,53 @@ static void *transfer_reader(pthread_addr_t pvarg) { char buffer[READ_SIZE]; - int fd = (intptr_t)pvarg; + int fd = (int)pvarg; int ret; int nbytes; int value; int ndx; printf("transfer_reader: started\n"); - for (nbytes = 0, value = 0; nbytes < NREAD_BYTES; ) + for (nbytes = 0, value = 0; nbytes < NREAD_BYTES;) { ret = read(fd, buffer, READ_SIZE); - if (ret < 0) + if (ret < 0 ) { - fprintf(stderr, \ - "transfer_reader: read failed, errno=%d\n", - errno); - - return (void *)(uintptr_t)1; + fprintf(stderr, "transfer_reader: read failed, errno=%d\n", errno); + return (void*)1; } else if (ret == 0) { if (nbytes < NREAD_BYTES) { - fprintf(stderr, \ - "transfer_reader: Too few bytes read. Aborting: %d\n", - nbytes); - - return (void *)(uintptr_t)2; + fprintf(stderr, "transfer_reader: Too few bytes read -- aborting: %d\n", nbytes); + return (void*)2; } - break; + break; } - for (ndx = 0; ndx < ret; ndx++) { if (value >= WRITE_SIZE) { value = 0; } - if (buffer[ndx] != value) { - fprintf(stderr, \ - "transfer_reader: Byte %d, expected %d, found %d\n", + fprintf(stderr, "transfer_reader: Byte %d, expected %d, found %d\n", nbytes + ndx, value, buffer[ndx]); - - return (void *)(uintptr_t)3; + return (void*)3; } - value++; } - nbytes += ret; if (nbytes > NREAD_BYTES) { - fprintf(stderr, \ - "transfer_reader: Too many bytes read. Aborting: %d\n", - nbytes); - - return (void *)(uintptr_t)4; + fprintf(stderr, "transfer_reader: Too many bytes read -- aborting: %d\n", nbytes); + return (void*)4; } } - printf("transfer_reader: %d bytes read\n", nbytes); - - return NULL; + return (void*)0; } /**************************************************************************** @@ -139,9 +119,8 @@ static void *transfer_reader(pthread_addr_t pvarg) static void *transfer_writer(pthread_addr_t pvarg) { char buffer[WRITE_SIZE]; - int fd = (intptr_t)pvarg; + int fd = (int)pvarg; int ret; - int nbytes; int i; printf("transfer_writer: started\n"); @@ -152,28 +131,20 @@ static void *transfer_writer(pthread_addr_t pvarg) for (i = 0; i < NWRITES; i++) { - for (nbytes = 0; nbytes < WRITE_SIZE; ) + ret = write(fd, buffer, WRITE_SIZE); + if (ret < 0 ) { - ret = write(fd, buffer + nbytes, WRITE_SIZE - nbytes); - if (ret < 0) - { - fprintf(stderr, \ - "transfer_writer: write failed, errno=%d\n", errno); - return (void *)(uintptr_t)1; - } - else if (ret == 0) - { - fprintf(stderr, \ - "transfer_writer: Unexpected zero write size\n"); - return (void *)(uintptr_t)2; - } - - nbytes += ret; + fprintf(stderr, "transfer_writer: write failed, errno=%d\n", errno); + return (void*)1; + } + else if (ret != WRITE_SIZE) + { + fprintf(stderr, "transfer_writer: Unexpected write size=%d\n", ret); + return (void*)2; } } - printf("transfer_writer: %d bytes written\n", NWRITE_BYTES); - return NULL; + return (void*)0; } /**************************************************************************** @@ -184,72 +155,37 @@ static void *transfer_writer(pthread_addr_t pvarg) * Name: transfer_test ****************************************************************************/ -int transfer_test(int fdin, int fdout, int boost_reader, int boost_writer) +int transfer_test(int fdin, int fdout) { pthread_t readerid; pthread_t writerid; - pthread_attr_t rattr; - pthread_attr_t wattr; void *value; int tmp; int ret; - printf("transfer_test: fdin=%d fdout=%d\n", fdin, fdout); - - /* Boost the priority of reader or writer on need */ - - pthread_attr_init(&rattr); - if (boost_reader) - { - rattr.priority += 1; - printf("transfer_test: Boost priority of transfer_reader" - "thread to %d\n", rattr.priority); - } - /* Start transfer_reader thread */ printf("transfer_test: Starting transfer_reader thread\n"); - ret = pthread_create(&readerid, &rattr, - transfer_reader, (void *)(intptr_t)fdin); - pthread_attr_destroy(&rattr); + ret = pthread_create(&readerid, NULL, transfer_reader, (pthread_addr_t)fdin); if (ret != 0) { - fprintf(stderr, \ - "transfer_test: Failed to create transfer_reader thread," - "error=%d\n", ret); + fprintf(stderr, "transfer_test: Failed to create transfer_reader thread, error=%d\n", ret); return 1; } - /* Boost the priority of reader or writer on need */ - - pthread_attr_init(&wattr); - if (boost_writer) - { - wattr.priority += 1; - printf("transfer_test: Boost priority of transfer_writer" - "thread to %d\n", wattr.priority); - } - /* Start transfer_writer thread */ printf("transfer_test: Starting transfer_writer thread\n"); - ret = pthread_create(&writerid, &wattr, - transfer_writer, (void *)(intptr_t)fdout); - pthread_attr_destroy(&wattr); + ret = pthread_create(&writerid, NULL, transfer_writer, (pthread_addr_t)fdout); if (ret != 0) { - fprintf(stderr, \ - "transfer_test: Failed to create transfer_writer thread," - "error=%d\n", ret); + fprintf(stderr, "transfer_test: Failed to create transfer_writer thread, error=%d\n", ret); pthread_detach(readerid); ret = pthread_cancel(readerid); if (ret != 0) { - fprintf(stderr, \ - "transfer_test: Failed to cancel transfer_reader thread," - "error=%d\n", ret); + fprintf(stderr, "transfer_test: Failed to cancel transfer_reader thread, error=%d\n", ret); } - return 2; } @@ -263,7 +199,7 @@ int transfer_test(int fdin, int fdout, int boost_reader, int boost_writer) } else { - ret = (intptr_t)value; + ret = (int)value; printf("transfer_test: transfer_writer returned %d\n", ret); } @@ -277,7 +213,7 @@ int transfer_test(int fdin, int fdout, int boost_reader, int boost_writer) } else { - tmp = (intptr_t)value; + tmp = (int)value; printf("transfer_test: transfer_reader returned %d\n", tmp); } @@ -285,7 +221,6 @@ int transfer_test(int fdin, int fdout, int boost_reader, int boost_writer) { ret = tmp; } - printf("transfer_test: returning %d\n", ret); return ret; } diff --git a/examples/poll/CMakeLists.txt b/examples/poll/CMakeLists.txt deleted file mode 100644 index 6c66a9fe0..000000000 --- a/examples/poll/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# ############################################################################## -# apps/examples/poll/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_POLL) - nuttx_add_application( - NAME - poll - STACKSIZE - ${CONFIG_DEFAULT_TASK_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_POLL} - SRCS - poll_main.c) - target_sources(apps PRIVATE poll_listener.c select_listener.c net_listener.c - net_reader.c) -endif() diff --git a/examples/poll/Make.defs b/examples/poll/Make.defs index c14ebf06f..abf4f7585 100644 --- a/examples/poll/Make.defs +++ b/examples/poll/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/poll/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/poll/Makefile b/examples/poll/Makefile index 48c9693c0..0d13c436d 100644 --- a/examples/poll/Makefile +++ b/examples/poll/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/poll/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/poll/Makefile.host b/examples/poll/Makefile.host index 36a34347b..51ddc4745 100644 --- a/examples/poll/Makefile.host +++ b/examples/poll/Makefile.host @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/poll/Makefile.host # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/poll/host.c b/examples/poll/host.c index 8d42dd997..cd6edad5d 100644 --- a/examples/poll/host.c +++ b/examples/poll/host.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/poll/host.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -64,7 +62,7 @@ int main(int argc, char **argv, char **envp) { struct sockaddr_in myaddr; char outbuf[IOBUFFER_SIZE]; - char inbuf[IOBUFFER_SIZE + 1]; + char inbuf[IOBUFFER_SIZE]; int sockfd; int len; int nbytessent; @@ -87,20 +85,18 @@ int main(int argc, char **argv, char **envp) myaddr.sin_addr.s_addr = inet_addr(TARGETIP); printf("client: Connecting to %s...\n", TARGETIP); - if (connect(sockfd, (struct sockaddr *)&myaddr, - sizeof(struct sockaddr_in)) < 0) + if (connect( sockfd, (struct sockaddr*)&myaddr, sizeof(struct sockaddr_in)) < 0) { printf("client: connect failure: %d\n", errno); goto errout_with_socket; } - printf("client: Connected\n"); /* Then send and receive messages */ for (i = 0; ; i++) { - snprintf(outbuf, sizeof(outbuf), "Remote message %d", i); + sprintf(outbuf, "Remote message %d", i); len = strlen(outbuf); printf("client: Sending '%s' (%d bytes)\n", outbuf, len); @@ -114,8 +110,7 @@ int main(int argc, char **argv, char **envp) } else if (nbytessent != len) { - printf("client: Bad send length: %d Expected: %d\n", - nbytessent, len); + printf("client: Bad send length: %d Expected: %d\n", nbytessent, len); goto errout_with_socket; } @@ -138,8 +133,7 @@ int main(int argc, char **argv, char **envp) if (nbytesrecvd != len) { - printf("client: Bad recv length: %d Expected: %d\n", - nbytesrecvd, len); + printf("client: Bad recv length: %d Expected: %d\n", nbytesrecvd, len); goto errout_with_socket; } else if (memcmp(inbuf, outbuf, len) != 0) diff --git a/examples/poll/net_listener.c b/examples/poll/net_listener.c index 3c72e16e3..3333f699d 100644 --- a/examples/poll/net_listener.c +++ b/examples/poll/net_listener.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/poll/net_listener.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -39,7 +37,7 @@ #include <string.h> #include <pthread.h> #include <errno.h> -#include <nuttx/debug.h> +#include <debug.h> #include <net/if.h> #include <arpa/inet.h> @@ -64,7 +62,7 @@ struct net_listener_s struct sockaddr_in addr; fd_set master; fd_set working; - char buffer[IOBUFFER_SIZE + 1]; + char buffer[IOBUFFER_SIZE]; int listensd; int mxsd; }; @@ -87,15 +85,12 @@ static bool net_closeclient(struct net_listener_s *nls, int sd) close(sd); FD_CLR(sd, &nls->master); - /* If we just closed the max SD, then search downward for the next - * biggest SD. - */ + /* If we just closed the max SD, then search downward for the next biggest SD. */ while (FD_ISSET(nls->mxsd, &nls->master) == false) { nls->mxsd -= 1; } - return true; } @@ -112,7 +107,7 @@ static inline bool net_incomingdata(struct net_listener_s *nls, int sd) /* Read data from the socket */ #ifdef FIONBIO - for (; ; ) + for (;;) #endif { printf("net_listener: Read data from sd=%d\n", sd); @@ -137,7 +132,7 @@ static inline bool net_incomingdata(struct net_listener_s *nls, int sd) } else { - nls->buffer[ret] = '\0'; + nls->buffer[ret]='\0'; printf("poll_listener: Read '%s' (%d bytes)\n", nls->buffer, ret); /* Echo the data back to the client */ @@ -149,10 +144,9 @@ static inline bool net_incomingdata(struct net_listener_s *nls, int sd) { if (errno != EINTR) { - printf("net_listener: Send failed sd=%d: %d\n", - sd, errno); - net_closeclient(nls, sd); - return false; + printf("net_listener: Send failed sd=%d: %d\n", sd, errno); + net_closeclient(nls, sd); + return false; } } else @@ -163,7 +157,6 @@ static inline bool net_incomingdata(struct net_listener_s *nls, int sd) } } } - return 0; } @@ -178,13 +171,12 @@ static inline bool net_connection(struct net_listener_s *nls) /* Loop until all connections have been processed */ #ifdef FIONBIO - for (; ; ) + for (;;) #endif { - printf("net_listener: Accepting new connection on sd=%d\n", - nls->listensd); + printf("net_listener: Accepting new connection on sd=%d\n", nls->listensd); - sd = accept4(nls->listensd, NULL, NULL, SOCK_CLOEXEC); + sd = accept(nls->listensd, NULL, NULL); if (sd < 0) { printf("net_listener: accept failed: %d\n", errno); @@ -205,11 +197,9 @@ static inline bool net_connection(struct net_listener_s *nls) { nls->mxsd = sd; } - return true; } } - return false; } @@ -235,8 +225,7 @@ static inline bool net_mksocket(struct net_listener_s *nls) /* Configure the socket */ value = 1; - ret = setsockopt(nls->listensd, SOL_SOCKET, SO_REUSEADDR, - (char *)&value, sizeof(int)); + ret = setsockopt(nls->listensd, SOL_SOCKET, SO_REUSEADDR, (char*)&value, sizeof(int)); if (ret < 0) { printf("net_listener: setsockopt failed: %d\n", errno); @@ -262,8 +251,7 @@ static inline bool net_mksocket(struct net_listener_s *nls) nls->addr.sin_family = AF_INET; nls->addr.sin_addr.s_addr = htonl(INADDR_ANY); nls->addr.sin_port = htons(LISTENER_PORT); - ret = bind(nls->listensd, (struct sockaddr *)&nls->addr, - sizeof(struct sockaddr_in)); + ret = bind(nls->listensd, (struct sockaddr *)&nls->addr, sizeof(struct sockaddr_in)); if (ret < 0) { printf("net_listener: bind failed: %d\n", errno); @@ -295,9 +283,8 @@ static void net_configure(void) uint8_t mac[IFHWADDRLEN]; #endif - /* Configure the network - * Many embedded network interfaces must have a software assigned MAC - */ + /* Configure the network */ + /* Many embedded network interfaces must have a software assigned MAC */ #ifdef CONFIG_EXAMPLES_POLL_NOMAC mac[0] = 0x00; @@ -356,7 +343,7 @@ void *net_listener(pthread_addr_t pvarg) memset(&nls, 0, sizeof(struct net_listener_s)); if (!net_mksocket(&nls)) { - return (void *)(uintptr_t)1; + return (void*)1; } /* Initialize the 'master' file descriptor set */ @@ -374,14 +361,13 @@ void *net_listener(pthread_addr_t pvarg) * on any of the connect sockets. */ - for (; ; ) + for (;;) { /* Wait on select */ - printf("net_listener: Calling select(), listener sd=%d\n", - nls.listensd); + printf("net_listener: Calling select(), listener sd=%d\n", nls.listensd); memcpy(&nls.working, &nls.master, sizeof(fd_set)); - ret = select(nls.mxsd + 1, &nls.working, NULL, NULL, &timeout); + ret = select(nls.mxsd + 1, (FAR fd_set*)&nls.working, (FAR fd_set*)NULL, (FAR fd_set*)NULL, &timeout); if (ret < 0) { printf("net_listener: select failed: %d\n", errno); @@ -425,7 +411,7 @@ void *net_listener(pthread_addr_t pvarg) /* Cleanup */ #if 0 /* Don't get here */ - for (i = 0; i <= nls.mxsd; +i++) + for (i = 0; i <= nls.mxsd; +i++) { if (FD_ISSET(i, &nls.master)) { @@ -433,6 +419,5 @@ void *net_listener(pthread_addr_t pvarg) } } #endif - return NULL; /* Keeps some compilers from complaining */ } diff --git a/examples/poll/net_reader.c b/examples/poll/net_reader.c index 191f39875..34c69dafe 100644 --- a/examples/poll/net_reader.c +++ b/examples/poll/net_reader.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/poll/net_reader.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -39,7 +37,7 @@ #include <pthread.h> #include <fcntl.h> #include <errno.h> -#include <nuttx/debug.h> +#include <debug.h> #include <net/if.h> #include <arpa/inet.h> @@ -78,9 +76,8 @@ static void net_configure(void) uint8_t mac[IFHWADDRLEN]; #endif - /* Configure the network - * Many embedded network interfaces must have a software assigned MAC - */ + /* Configure the network */ + /* Many embedded network interfaces must have a software assigned MAC */ #ifdef CONFIG_EXAMPLES_POLL_NOMAC mac[0] = 0x00; @@ -121,7 +118,7 @@ static void net_configure(void) static void net_receive(int sd) { struct timeval timeout; - char buffer[IOBUFFER_SIZE + 1]; + char buffer[IOBUFFER_SIZE]; char *ptr; fd_set readset; int nbytes; @@ -134,7 +131,7 @@ static void net_receive(int sd) /* Loop while we have the connection */ - for (; ; ) + for (;;) { /* Wait for incoming message */ @@ -142,7 +139,7 @@ static void net_receive(int sd) { FD_ZERO(&readset); FD_SET(sd, &readset); - ret = select(sd + 1, &readset, NULL, NULL, &timeout); + ret = select(sd + 1, (FAR fd_set*)&readset, (FAR fd_set*)NULL, (FAR fd_set*)NULL, &timeout); } while (ret < 0 && errno == EINTR); @@ -180,7 +177,7 @@ static void net_receive(int sd) } else { - buffer[ret] = '\0'; + buffer[ret]='\0'; printf("net_reader: Read '%s' (%d bytes)\n", buffer, ret); /* Echo the data back to the client */ @@ -192,8 +189,7 @@ static void net_receive(int sd) { if (errno != EINTR) { - printf("net_reader: Send failed sd=%d: %d\n", - sd, errno); + printf("net_reader: Send failed sd=%d: %d\n", sd, errno); return; } } @@ -243,8 +239,7 @@ void *net_reader(pthread_addr_t pvarg) /* Set socket to reuse address */ optval = 1; - if (setsockopt(listensd, SOL_SOCKET, SO_REUSEADDR, - &optval, sizeof(int)) < 0) + if (setsockopt(listensd, SOL_SOCKET, SO_REUSEADDR, (void*)&optval, sizeof(int)) < 0) { printf("net_reader: setsockopt SO_REUSEADDR failure: %d\n", errno); goto errout_with_listensd; @@ -256,8 +251,7 @@ void *net_reader(pthread_addr_t pvarg) addr.sin_port = HTONS(LISTENER_PORT); addr.sin_addr.s_addr = INADDR_ANY; - if (bind(listensd, (struct sockaddr *)&addr, - sizeof(struct sockaddr_in)) < 0) + if (bind(listensd, (struct sockaddr*)&addr, sizeof(struct sockaddr_in)) < 0) { printf("net_reader: bind failure: %d\n", errno); goto errout_with_listensd; @@ -273,15 +267,13 @@ void *net_reader(pthread_addr_t pvarg) /* Connection loop */ - for (; ; ) + for (;;) { /* Accept only one connection */ - printf("net_reader: Accepting new connections on port %d\n", - LISTENER_PORT); + printf("net_reader: Accepting new connections on port %d\n", LISTENER_PORT); addrlen = sizeof(struct sockaddr_in); - acceptsd = accept4(listensd, (struct sockaddr *)&addr, &addrlen, - SOCK_CLOEXEC); + acceptsd = accept(listensd, (struct sockaddr*)&addr, &addrlen); if (acceptsd < 0) { printf("net_reader: accept failure: %d\n", errno); @@ -290,16 +282,13 @@ void *net_reader(pthread_addr_t pvarg) printf("net_reader: Connection accepted on sd=%d\n", acceptsd); - /* Configure to "linger" until all data is sent when the socket is - * closed - */ + /* Configure to "linger" until all data is sent when the socket is closed */ #ifdef POLL_HAVE_SOLINGER ling.l_onoff = 1; ling.l_linger = 30; /* timeout is seconds */ - if (setsockopt(acceptsd, SOL_SOCKET, SO_LINGER, - &ling, sizeof(struct linger)) < 0) + if (setsockopt(acceptsd, SOL_SOCKET, SO_LINGER, &ling, sizeof(struct linger)) < 0) { printf("net_reader: setsockopt SO_LINGER failure: %d\n", errno); goto errout_with_acceptsd; diff --git a/examples/poll/poll_internal.h b/examples/poll/poll_internal.h index ba3a03fe6..72579528d 100644 --- a/examples/poll/poll_internal.h +++ b/examples/poll/poll_internal.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/poll/poll_internal.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/poll/poll_listener.c b/examples/poll/poll_listener.c index ce912357d..6446bf4a0 100644 --- a/examples/poll/poll_listener.c +++ b/examples/poll/poll_listener.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/poll/poll_listener.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -36,7 +34,7 @@ #include <poll.h> #include <fcntl.h> #include <errno.h> -#include <nuttx/debug.h> +#include <debug.h> #include <arpa/inet.h> @@ -93,18 +91,18 @@ void *poll_listener(pthread_addr_t pvarg) printf("poll_listener: Opening %s for non-blocking read\n", FIFO_PATH1); - fd = open(FIFO_PATH1, O_RDONLY | O_NONBLOCK); + fd = open(FIFO_PATH1, O_RDONLY|O_NONBLOCK); if (fd < 0) { printf("poll_listener: ERROR Failed to open FIFO %s: %d\n", FIFO_PATH1, errno); close(fd); - return (FAR void *)-1; + return (void*)-1; } /* Loop forever */ - for (; ; ) + for (;;) { printf("poll_listener: Calling poll()\n"); @@ -145,35 +143,32 @@ void *poll_listener(pthread_addr_t pvarg) nevents = 0; for (i = 0; i < NPOLLFDS; i++) { - printf("poll_listener: FIFO revents[%d]=%08" PRIx32 "\n", i, - fds[i].revents); + printf("poll_listener: FIFO revents[%d]=%02x\n", i, fds[i].revents); if (timeout) { if (fds[i].revents != 0) { - printf("poll_listener: ERROR? expected revents=00, " - "received revents[%d]=%08" PRIx32 "\n", - i, fds[i].revents); + printf("poll_listener: ERROR? expected revents=00, received revents[%d]=%02x\n", + fds[i].revents, i); } } else if (pollin) { - if (fds[i].revents == POLLIN) + if (fds[i].revents == POLLIN) + { + nevents++; + } + else if (fds[i].revents != 0) { - nevents++; - } - else if (fds[i].revents != 0) - { - printf("poll_listener: ERROR unexpected revents[%d]=" - "%08" PRIx32 "\n", i, fds[i].revents); - } + printf("poll_listener: ERROR unexpected revents[%d]=%02x\n", + i, fds[i].revents); + } } } if (pollin && nevents != ret) { - printf("poll_listener: ERROR found %d events, " - "poll reported %d\n", nevents, ret); + printf("poll_listener: ERROR found %d events, poll reported %d\n", nevents, ret); } /* In any event, read until the pipe/serial is empty */ @@ -215,26 +210,21 @@ void *poll_listener(pthread_addr_t pvarg) { if ((fds[i].revents & POLLIN) != 0) { - printf("poll_listener: ERROR no read" - " data[%d]\n", i); + printf("poll_listener: ERROR no read data[%d]\n", i); } } else if (errno != EINTR) { - printf("poll_listener: read[%d] failed: %d\n", - i, errno); + printf("poll_listener: read[%d] failed: %d\n", i, errno); } - nbytes = 0; } else { if (timeout) { - printf("poll_listener: ERROR? Poll timeout, " - "but data read[%d]\n", i); - printf(" (might just be " - "a race condition)\n"); + printf("poll_listener: ERROR? Poll timeout, but data read[%d]\n", i); + printf(" (might just be a race condition)\n"); } buffer[nbytes] = '\0'; @@ -242,9 +232,7 @@ void *poll_listener(pthread_addr_t pvarg) i, buffer, (long)nbytes); } - /* Suppress error report if no read data on the next - * time through - */ + /* Suppress error report if no read data on the next time through */ fds[i].revents = 0; } diff --git a/examples/poll/poll_main.c b/examples/poll/poll_main.c index 5dfb2d938..5e801b856 100644 --- a/examples/poll/poll_main.c +++ b/examples/poll/poll_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/poll/poll_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -36,7 +34,7 @@ #include <fcntl.h> #include <poll.h> #include <errno.h> -#include <nuttx/debug.h> +#include <debug.h> #include "poll_internal.h" @@ -136,8 +134,7 @@ int main(int argc, FAR char *argv[]) ret = pthread_create(&tid2, NULL, select_listener, NULL); if (ret != 0) { - printf("poll_main: Failed to create select_listener thread: %d\n", - ret); + printf("poll_main: Failed to create select_listener thread: %d\n", ret); exitcode = 6; goto errout; } @@ -158,10 +155,6 @@ int main(int argc, FAR char *argv[]) } #endif - /* Let the pthreads run first */ - - sleep(1); - /* Loop forever */ for (count = 0; ; count++) @@ -170,7 +163,7 @@ int main(int argc, FAR char *argv[]) * from the poll. */ - snprintf(buffer, sizeof(buffer), "Message %d", count); + sprintf(buffer, "Message %d", count); nbytes = write(fd1, buffer, strlen(buffer)); if (nbytes < 0) { diff --git a/examples/poll/select_listener.c b/examples/poll/select_listener.c index e99eda06d..932bb4a2c 100644 --- a/examples/poll/select_listener.c +++ b/examples/poll/select_listener.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/poll/select_listener.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -37,7 +35,7 @@ #include <pthread.h> #include <fcntl.h> #include <errno.h> -#include <nuttx/debug.h> +#include <debug.h> #include "poll_internal.h" @@ -79,18 +77,18 @@ void *select_listener(pthread_addr_t pvarg) /* Open the FIFO for non-blocking read */ printf("select_listener: Opening %s for non-blocking read\n", FIFO_PATH2); - fd = open(FIFO_PATH2, O_RDONLY | O_NONBLOCK); + fd = open(FIFO_PATH2, O_RDONLY|O_NONBLOCK); if (fd < 0) { printf("select_listener: ERROR Failed to open FIFO %s: %d\n", FIFO_PATH2, errno); close(fd); - return (void *)(uintptr_t)-1; + return (void*)-1; } /* Loop forever */ - for (; ; ) + for (;;) { printf("select_listener: Calling select()\n"); @@ -103,7 +101,7 @@ void *select_listener(pthread_addr_t pvarg) timeout = false; ready = false; - ret = select(fd + 1, &rfds, NULL, NULL, &tv); + ret = select(fd+1, (FAR fd_set*)&rfds, (FAR fd_set*)NULL, (FAR fd_set*)NULL, &tv); printf("\nselect_listener: select returned: %d\n", ret); if (ret < 0) @@ -150,20 +148,18 @@ void *select_listener(pthread_addr_t pvarg) { printf("select_listener: read failed: %d\n", errno); } - nbytes = 0; } else { if (timeout) { - printf("select_listener: ERROR? Poll timeout,\n"); - printf("but data read (might just be a race condition)\n"); + printf("select_listener: ERROR? Poll timeout, but data read\n"); + printf(" (might just be a race condition)\n"); } buffer[nbytes] = '\0'; - printf("select_listener: Read '%s' (%zd bytes)\n", - buffer, nbytes); + printf("select_listener: Read '%s' (%ld bytes)\n", buffer, (long)nbytes); } timeout = false; diff --git a/examples/popen/CMakeLists.txt b/examples/popen/CMakeLists.txt deleted file mode 100644 index b256ae717..000000000 --- a/examples/popen/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# ############################################################################## -# apps/examples/popen/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_POPEN) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_POPEN_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_POPEN_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_POPEN_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_POPEN} - SRCS - popen_main.c) -endif() diff --git a/examples/popen/Kconfig b/examples/popen/Kconfig index 2f571d121..3b2eba29e 100644 --- a/examples/popen/Kconfig +++ b/examples/popen/Kconfig @@ -7,7 +7,6 @@ config EXAMPLES_POPEN tristate "popen() example" default n depends on SYSTEM_POPEN - depends on !DISABLE_POSIX_TIMERS ---help--- Enable the popen() example diff --git a/examples/popen/Make.defs b/examples/popen/Make.defs index a91ae672c..a154c93e3 100644 --- a/examples/popen/Make.defs +++ b/examples/popen/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/popen/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/popen/Makefile b/examples/popen/Makefile index 73de35df6..a7a7cd89a 100644 --- a/examples/popen/Makefile +++ b/examples/popen/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/popen/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/popen/popen_main.c b/examples/popen/popen_main.c index c830085e5..1a6f35117 100644 --- a/examples/popen/popen_main.c +++ b/examples/popen/popen_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/popen/popen_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -26,11 +24,10 @@ #include <nuttx/config.h> -#include <errno.h> -#include <signal.h> #include <stdio.h> #include <stdlib.h> #include <time.h> +#include <errno.h> /**************************************************************************** * Public Functions @@ -169,8 +166,7 @@ int main(int argc, FAR char *argv[]) if (errcode == ECHILD) { - printf("The shell has already exited " - "(and exit status is not available)\n"); + printf("The shell has already exited (and exit status is not available)\n"); } else { diff --git a/examples/posix_spawn/CMakeLists.txt b/examples/posix_spawn/CMakeLists.txt deleted file mode 100644 index 453224edd..000000000 --- a/examples/posix_spawn/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -# ############################################################################## -# apps/examples/posix_spawn/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_POSIXSPAWN) - nuttx_add_application(NAME posix_spawn SRCS spawn_main.c) -endif() diff --git a/examples/posix_spawn/Kconfig b/examples/posix_spawn/Kconfig index 024484668..1d3824e46 100644 --- a/examples/posix_spawn/Kconfig +++ b/examples/posix_spawn/Kconfig @@ -6,12 +6,6 @@ config EXAMPLES_POSIXSPAWN tristate "posix_spawn Unit Test" default n - depends on !BINFMT_DISABLE - depends on !DISABLE_MOUNTPOINT - depends on BOARDCTL - depends on BOARDCTL_APP_SYMTAB - depends on ELF - depends on FS_ROMFS ---help--- Enable the posix_spawn() unit test diff --git a/examples/posix_spawn/Make.defs b/examples/posix_spawn/Make.defs index de98e6c38..e3f7eb9f6 100644 --- a/examples/posix_spawn/Make.defs +++ b/examples/posix_spawn/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/posix_spawn/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/posix_spawn/Makefile b/examples/posix_spawn/Makefile index 08e87cdf7..2e5aa7b58 100644 --- a/examples/posix_spawn/Makefile +++ b/examples/posix_spawn/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/posix_spawn/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -26,8 +24,6 @@ include $(APPDIR)/Make.defs CSRCS = romfs.c CSRCS += symtab.c -filesystem$(DELIM)symtab.c_CFLAGS = -fno-builtin -filesystem$(DELIM)symtab.c_CELFFLAGS = -fno-builtin MAINSRC = spawn_main.c PROGNAME = posix_spawn diff --git a/examples/posix_spawn/filesystem/Makefile b/examples/posix_spawn/filesystem/Makefile index 1632627ad..45008e5e1 100644 --- a/examples/posix_spawn/filesystem/Makefile +++ b/examples/posix_spawn/filesystem/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/posix_spawn/filesystem/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/posix_spawn/filesystem/hello/Makefile b/examples/posix_spawn/filesystem/hello/Makefile index c4f0056ab..0feee90e1 100644 --- a/examples/posix_spawn/filesystem/hello/Makefile +++ b/examples/posix_spawn/filesystem/hello/Makefile @@ -1,7 +1,5 @@ ############################################################################ -# apps/examples/posix_spawn/filesystem/hello/Makefile -# -# SPDX-License-Identifier: Apache-2.0 +# apps/examples/elf/tests/hello/Makefile # # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with diff --git a/examples/posix_spawn/filesystem/hello/hello.c b/examples/posix_spawn/filesystem/hello/hello.c index e460fa557..5269d0359 100644 --- a/examples/posix_spawn/filesystem/hello/hello.c +++ b/examples/posix_spawn/filesystem/hello/hello.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/posix_spawn/filesystem/hello/hello.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/posix_spawn/filesystem/redirect/Makefile b/examples/posix_spawn/filesystem/redirect/Makefile index a570c24a0..38bf2c17b 100644 --- a/examples/posix_spawn/filesystem/redirect/Makefile +++ b/examples/posix_spawn/filesystem/redirect/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/posix_spawn/filesystem/redirect/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/posix_spawn/filesystem/redirect/redirect.c b/examples/posix_spawn/filesystem/redirect/redirect.c index f8ecd48a8..fd34d18f6 100644 --- a/examples/posix_spawn/filesystem/redirect/redirect.c +++ b/examples/posix_spawn/filesystem/redirect/redirect.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/posix_spawn/filesystem/redirect/redirect.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/posix_spawn/spawn_main.c b/examples/posix_spawn/spawn_main.c index 34428d472..1c0a84346 100644 --- a/examples/posix_spawn/spawn_main.c +++ b/examples/posix_spawn/spawn_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/posix_spawn/spawn_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -37,7 +35,7 @@ #include <string.h> #include <fcntl.h> #include <spawn.h> -#include <nuttx/debug.h> +#include <debug.h> #include <errno.h> #include <nuttx/drivers/ramdisk.h> @@ -47,6 +45,38 @@ * Pre-processor Definitions ****************************************************************************/ +/* Check configuration. This is not all of the configuration settings that + * are required -- only the more obvious. + */ + +#ifdef CONFIG_BINFMT_DISABLE +# error "The binary loader is disabled (CONFIG_BINFMT_DISABLE)!" +#endif + +#ifndef CONFIG_ELF +# error "You must select CONFIG_ELF in your configuration file" +#endif + +#ifndef CONFIG_FS_ROMFS +# error "You must select CONFIG_FS_ROMFS in your configuration file" +#endif + +#ifdef CONFIG_DISABLE_MOUNTPOINT +# error "You must not disable mountpoints via CONFIG_DISABLE_MOUNTPOINT in your configuration file" +#endif + +#ifdef CONFIG_BINFMT_DISABLE +# error "You must not disable loadable modules via CONFIG_BINFMT_DISABLE in your configuration file" +#endif + +#ifndef CONFIG_BOARDCTL +# error "This configuration requires CONFIG_BOARDCTL" +#endif + +#ifndef CONFIG_BOARDCTL_APP_SYMTAB +# error "You must enable the symobol table interface with CONFIG_BOARDCTL_APP_SYMTAB" +#endif + /* Describe the ROMFS file system */ #define SECTORSIZE 512 @@ -232,7 +262,7 @@ int main(int argc, FAR char *argv[]) /* Make sure that we are using our symbol tablee */ - symdesc.symtab = g_spawn_exports; + symdesc.symtab = (FAR struct symtab_s *)g_spawn_exports; /* Discard 'const' */ symdesc.nsymbols = g_spawn_nexports; boardctl(BOARDIOC_APP_SYMTAB, (uintptr_t)&symdesc); @@ -275,7 +305,7 @@ int main(int argc, FAR char *argv[]) #ifdef CONFIG_LIBC_ENVPATH filepath = g_hello_argv[0]; #else - snprintf(fullpath, sizeof(fullpath), "%s/%s", MOUNTPT, g_hello_argv[0]); + snprintf(fullpath, 128, "%s/%s", MOUNTPT, g_hello_argv[0]); filepath = fullpath; #endif @@ -353,7 +383,7 @@ int main(int argc, FAR char *argv[]) posix_spawn_file_actions_dump(&file_actions); - snprintf(fullpath, sizeof(fullpath), "%s/%s", MOUNTPT, g_data); + snprintf(fullpath, 128, "%s/%s", MOUNTPT, g_data); ret = posix_spawn_file_actions_addopen(&file_actions, 0, fullpath, O_RDONLY, 0644); if (ret != 0) @@ -374,7 +404,7 @@ int main(int argc, FAR char *argv[]) #ifdef CONFIG_LIBC_ENVPATH filepath = g_redirect_argv[0]; #else - snprintf(fullpath, sizeof(fullpath), "%s/%s", MOUNTPT, g_redirect_argv[0]); + snprintf(fullpath, 128, "%s/%s", MOUNTPT, g_redirect_argv[0]); filepath = fullpath; #endif diff --git a/examples/posix_stdio/CMakeLists.txt b/examples/posix_stdio/CMakeLists.txt deleted file mode 100644 index e10cb5992..000000000 --- a/examples/posix_stdio/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# ############################################################################## -# apps/examples/posix_stdio/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_POSIX_STDIO) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_POSIX_STDIO_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_POSIX_STDIO_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_POSIX_STDIO_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_POSIX_STDIO} - SRCS - posix_stdio.c) -endif() diff --git a/examples/posix_stdio/Kconfig b/examples/posix_stdio/Kconfig deleted file mode 100644 index 8980223a1..000000000 --- a/examples/posix_stdio/Kconfig +++ /dev/null @@ -1,26 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config EXAMPLES_POSIX_STDIO - bool "Posix stdio example" - default n - ---help--- - Enable POSIX stdio example that shows how to use open(), write() and - close() via /dev/console. - -config EXAMPLES_POSIX_STDIO_PROGNAME - string "Program name" - default "posix_stdio" - depends on EXAMPLES_POSIX_STDIO - -config EXAMPLES_POSIX_STDIO_PRIORITY - int "POSIX_STDIO priority" - default 100 - depends on EXAMPLES_POSIX_STDIO - -config EXAMPLES_POSIX_STDIO_STACKSIZE - int "POSIX_STDIO stack size" - default DEFAULT_TASK_STACKSIZE - depends on EXAMPLES_POSIX_STDIO diff --git a/examples/posix_stdio/Make.defs b/examples/posix_stdio/Make.defs deleted file mode 100644 index 72d9594a4..000000000 --- a/examples/posix_stdio/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/examples/posix_stdio/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_EXAMPLES_POSIX_STDIO),) -CONFIGURED_APPS += $(APPDIR)/examples/posix_stdio -endif diff --git a/examples/posix_stdio/Makefile b/examples/posix_stdio/Makefile deleted file mode 100644 index 537176133..000000000 --- a/examples/posix_stdio/Makefile +++ /dev/null @@ -1,32 +0,0 @@ -############################################################################ -# apps/examples/posix_stdio/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -PROGNAME = $(CONFIG_EXAMPLES_POSIX_STDIO_PROGNAME) -PRIORITY = $(CONFIG_EXAMPLES_POSIX_STDIO_PRIORITY) -STACKSIZE = $(CONFIG_EXAMPLES_POSIX_STDIO_STACKSIZE) -MODULE = $(CONFIG_EXAMPLES_POSIX_STDIO) - -MAINSRC = posix_stdio.c - -include $(APPDIR)/Application.mk diff --git a/examples/posix_stdio/posix_stdio.c b/examples/posix_stdio/posix_stdio.c deleted file mode 100644 index 722f088ca..000000000 --- a/examples/posix_stdio/posix_stdio.c +++ /dev/null @@ -1,100 +0,0 @@ -/**************************************************************************** - * apps/examples/posix_stdio/posix_stdio.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * This is a single POSIX example that works for both Nuttx and Linux distros - * (with minimal changes). By this example its possible to learn how to use - * posix style and also works with onpen(), close() and write() functions. - * - * For linux, need to change the headers and the output device - * A) Headers: - * #include <fcntl.h> - * #include <unistd.h> - * #include <stdio.h> - * #include <string.h> - * - * B) output: - * /dev/tty - * - * To compile it on Linux, you can simple use gcc: - * gcc posix_stdio.c -o posix_stdio - * - * To run, just send the following command: ./posix_stdio - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> -#include <stdint.h> -#include <unistd.h> -#include <string.h> -#include <fcntl.h> -#include <stdio.h> - -/**************************************************************************** - * Pre-processor Definitions - * *************************************************************************/ - -/* define how many times the message will be printed in the console */ - -#ifndef PRINT_N_TIMES -# define PRINT_N_TIMES 10 -#endif - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -static void print_message(int fd) -{ - const char *message = "Hello, NuttX users, welcome!!!\n"; - - write(fd, message, strlen(message)); -} - -/**************************************************************************** - * hello_nuttx_main - ****************************************************************************/ - -int main(int argc, char *argv[]) -{ - int counter; - int fd = open("/dev/console", O_WRONLY); - - if (fd < 0) - { - fprintf(stderr, "Failed to open console\n"); - return 1; - } - - for (counter = 0; counter < PRINT_N_TIMES; counter++) - { - print_message(fd); - } - - close(fd); - return 0; -} - diff --git a/examples/powerled/CMakeLists.txt b/examples/powerled/CMakeLists.txt deleted file mode 100644 index 700c2daa5..000000000 --- a/examples/powerled/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# ############################################################################## -# apps/examples/powerled/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_POWERLED) - nuttx_add_application( - NAME - powerled - STACKSIZE - ${CONFIG_DEFAULT_TASK_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_POWERLED} - SRCS - powerled_main.c) -endif() diff --git a/examples/powerled/Kconfig b/examples/powerled/Kconfig index f625d0da4..f3056adb0 100644 --- a/examples/powerled/Kconfig +++ b/examples/powerled/Kconfig @@ -6,8 +6,6 @@ config EXAMPLES_POWERLED tristate "Powerled example" default n - depends on DRIVERS_POWERLED - depends on LIBC_FLOATINGPOINT ---help--- Enable the powerled driver example diff --git a/examples/powerled/Make.defs b/examples/powerled/Make.defs index a2e1b26bf..7015da255 100644 --- a/examples/powerled/Make.defs +++ b/examples/powerled/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/powerled/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/powerled/Makefile b/examples/powerled/Makefile index 7a489c932..ca02d8011 100644 --- a/examples/powerled/Makefile +++ b/examples/powerled/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/powerled/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/powerled/powerled_main.c b/examples/powerled/powerled_main.c index 6743b5e23..05edd594a 100644 --- a/examples/powerled/powerled_main.c +++ b/examples/powerled/powerled_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/powerled/powerled_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -35,21 +33,31 @@ #include <stdlib.h> #include <stdbool.h> #include <errno.h> -#include <nuttx/debug.h> +#include <debug.h> #include <sys/ioctl.h> -#ifndef CONFIG_NSH_ARCHINIT -#include <sys/boardctl.h> -#endif - #include <nuttx/fs/fs.h> #include <nuttx/power/powerled.h> +#if defined(CONFIG_EXAMPLES_POWERLED) + +#ifndef CONFIG_DRIVERS_POWERLED +# error "Powerled example requires powerled support" +#endif + /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ +#ifndef CONFIG_EXAMPLES_POWERLED_CURRENT_LIMIT +# error "LED current limit must be set!" +#endif + +#ifndef CONFIG_LIBC_FLOATINGPOINT +# error "CONFIG_LIBC_FLOATINGPOINT must be set!" +#endif + #define DEMO_CONT_BRIGHTNESS_MAX 100.0 #define DEMO_CONT_BRIGHTNESS_MIN 0.0 #define DEMO_CONT_BRIGHTNESS_STEP 10.0 @@ -62,7 +70,7 @@ #define DEMO_FLASH_BRIGHTNESS_SET 100.0 /**************************************************************************** - * Private Types + * Private Type Definition ****************************************************************************/ /* Example modes */ @@ -439,10 +447,16 @@ int main(int argc, char *argv[]) goto errout; } +#ifndef CONFIG_NSH_ARCHINIT + /* Perform architecture-specific initialization (if configured) */ + + boardctl(BOARDIOC_INIT, 0); + #ifdef CONFIG_BOARDCTL_FINALINIT /* Perform architecture-specific final-initialization (if configured) */ boardctl(BOARDIOC_FINALINIT, 0); +#endif #endif /* Set LED current limit */ @@ -739,6 +753,7 @@ int main(int argc, char *argv[]) } errout: + fflush(stdout); fflush(stderr); @@ -762,3 +777,4 @@ errout: return 0; } +#endif /* CONFIG_EXAMPLE_POWERLED */ diff --git a/examples/powermonitor/CMakeLists.txt b/examples/powermonitor/CMakeLists.txt deleted file mode 100644 index 522c2e27b..000000000 --- a/examples/powermonitor/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# ############################################################################## -# apps/examples/powermonitor/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_POWERMONITOR) - nuttx_add_application( - NAME - powermonitor - STACKSIZE - ${CONFIG_DEFAULT_TASK_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_POWERMONITOR} - SRCS - powermonitor_main.c) -endif() diff --git a/examples/powermonitor/Kconfig b/examples/powermonitor/Kconfig index 05abcb523..e483247c0 100644 --- a/examples/powermonitor/Kconfig +++ b/examples/powermonitor/Kconfig @@ -6,7 +6,6 @@ config EXAMPLES_POWERMONITOR tristate "LTC4151 powermonitor example" default n - depends on SENSORS_LTC4151 if EXAMPLES_POWERMONITOR endif # EXAMPLES_POWERMONITOR diff --git a/examples/powermonitor/Make.defs b/examples/powermonitor/Make.defs index 9a0248fea..d383969ed 100644 --- a/examples/powermonitor/Make.defs +++ b/examples/powermonitor/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/powermonitor/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/powermonitor/Makefile b/examples/powermonitor/Makefile index 05f669075..2de62f9ab 100644 --- a/examples/powermonitor/Makefile +++ b/examples/powermonitor/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/powermonitor/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/powermonitor/powermonitor_main.c b/examples/powermonitor/powermonitor_main.c index 0e13e3b4b..ef9c12b43 100644 --- a/examples/powermonitor/powermonitor_main.c +++ b/examples/powermonitor/powermonitor_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/powermonitor/powermonitor_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -28,7 +26,7 @@ #include <stdint.h> #include <stdbool.h> -#include <nuttx/debug.h> +#include <debug.h> #include <stdio.h> #include <fixedmath.h> #include <sys/types.h> @@ -36,7 +34,6 @@ #include <fcntl.h> #include <errno.h> #include <stdlib.h> -#include <unistd.h> #include <nuttx/sensors/ltc4151.h> diff --git a/examples/pppd/CMakeLists.txt b/examples/pppd/CMakeLists.txt deleted file mode 100644 index 7b07f05c2..000000000 --- a/examples/pppd/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# ############################################################################## -# apps/examples/pppd/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_PPPD) - nuttx_add_application( - NAME - pppd - STACKSIZE - ${CONFIG_EXAMPLES_PPPD_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_PPPD} - SRCS - pppd_main.c) -endif() diff --git a/examples/pppd/Make.defs b/examples/pppd/Make.defs index 9497a83d7..0adf2bf7c 100644 --- a/examples/pppd/Make.defs +++ b/examples/pppd/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/pppd/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/pppd/Makefile b/examples/pppd/Makefile index a1c4c7e1e..3f341d034 100644 --- a/examples/pppd/Makefile +++ b/examples/pppd/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/pppd/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/pppd/pppd_main.c b/examples/pppd/pppd_main.c index 78af8d1fa..ce80ae90b 100644 --- a/examples/pppd/pppd_main.c +++ b/examples/pppd/pppd_main.c @@ -1,9 +1,8 @@ /**************************************************************************** * apps/examples/pppd/pppd_main.c * - * SPDX-License-Identifier: BSD-3-Clause - * SPDX-FileCopyrightText: 2015 Brennan Ashton. All rights reserved. - * SPDX-FileContributor: Brennan Ashton <brennan@ombitron.com> + * Copyright (C) 2015 Brennan Ashton. All rights reserved. + * Author: Brennan Ashton <brennan@ombitron.com> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/examples/pty_test/CMakeLists.txt b/examples/pty_test/CMakeLists.txt deleted file mode 100644 index 0504a518d..000000000 --- a/examples/pty_test/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# ############################################################################## -# apps/examples/pty_test/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_PTYTEST) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_PTYTEST_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_PTYTEST_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_PTYTEST_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_PTYTEST} - SRCS - pty_test.c) -endif() diff --git a/examples/pty_test/Kconfig b/examples/pty_test/Kconfig index 3390088ab..1f3921cdb 100644 --- a/examples/pty_test/Kconfig +++ b/examples/pty_test/Kconfig @@ -41,11 +41,11 @@ config EXAMPLES_PTYTEST_DAEMONPRIO default 100 config EXAMPLES_PTYTEST_WAIT_CONNECTED - bool "Keep retrying open serial device" - ---help--- - For USB based serial devices, open will fail - if the other end is not connected (USB cable unplugged). - Enabling this option will retry the open() call every second - until connected. + bool "Keep retrying open serial device" + ---help--- + For USB based serial devices, open will fail + if the other end is not connected (USB cable unplugged). + Enabling this option will retry the open() call every second + until connected. endif diff --git a/examples/pty_test/Make.defs b/examples/pty_test/Make.defs index 870175688..870fc757c 100644 --- a/examples/pty_test/Make.defs +++ b/examples/pty_test/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/pty_test/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/pty_test/Makefile b/examples/pty_test/Makefile index 0fe41e9c7..92f1f773b 100644 --- a/examples/pty_test/Makefile +++ b/examples/pty_test/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/pty_test/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -22,14 +20,14 @@ include $(APPDIR)/Make.defs -# PTY Test built-in application info +# Hello, World! built-in application info PROGNAME = $(CONFIG_EXAMPLES_PTYTEST_PROGNAME) PRIORITY = $(CONFIG_EXAMPLES_PTYTEST_PRIORITY) STACKSIZE = $(CONFIG_EXAMPLES_PTYTEST_STACKSIZE) MODULE = $(CONFIG_EXAMPLES_PTYTEST) -# PTY Test Example +# PTY Test! Example MAINSRC = pty_test.c diff --git a/examples/pty_test/pty_test.c b/examples/pty_test/pty_test.c index 25c4c9fe0..f3016458c 100644 --- a/examples/pty_test/pty_test.c +++ b/examples/pty_test/pty_test.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/pty_test/pty_test.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -332,6 +330,7 @@ int main(int argc, FAR char *argv[]) #endif } +#ifdef CONFIG_SERIAL_TERMIOS /* Enable \n -> \r\n conversion during write */ ret = tcgetattr(termpair.fd_uart, &tio); @@ -348,6 +347,7 @@ int main(int argc, FAR char *argv[]) fprintf(stderr, "ERROR: tcsetattr() failed: %d\n", errno); goto error_serial; } +#endif printf("Starting a new NSH Session using %s\n", buffer); diff --git a/examples/pulsecount/CMakeLists.txt b/examples/pulsecount/CMakeLists.txt deleted file mode 100644 index 356b1b982..000000000 --- a/examples/pulsecount/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# ############################################################################## -# apps/examples/pulsecount/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_PULSECOUNT) - nuttx_add_application( - NAME - pulsecount - STACKSIZE - ${CONFIG_DEFAULT_TASK_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_PULSECOUNT} - SRCS - pulsecount_main.c) -endif() diff --git a/examples/pulsecount/Kconfig b/examples/pulsecount/Kconfig deleted file mode 100644 index 4f4526868..000000000 --- a/examples/pulsecount/Kconfig +++ /dev/null @@ -1,42 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config EXAMPLES_PULSECOUNT - tristate "pulsecount example" - default n - depends on PULSECOUNT - ---help--- - Enable the finite pulsecount example - -if EXAMPLES_PULSECOUNT - -config EXAMPLES_PULSECOUNT_DEVPATH - string "pulsecount device path" - default "/dev/pulsecount0" - ---help--- - The path to the pulsecount device. Default: /dev/pulsecount0 - -config EXAMPLES_PULSECOUNT_HIGH_NS - int "Default pulsecount high time" - default 5000000 - ---help--- - The default pulsecount high time in nanoseconds. - Default: 5000000 ns - -config EXAMPLES_PULSECOUNT_LOW_NS - int "Default pulsecount low time" - default 5000000 - ---help--- - The default pulsecount low time in nanoseconds. - Default: 5000000 ns - -config EXAMPLES_PULSECOUNT_COUNT - int "Default pulsecount count" - default 100 - range 1 2147483647 - ---help--- - The default number of pulses to generate. - -endif diff --git a/examples/pulsecount/Make.defs b/examples/pulsecount/Make.defs deleted file mode 100644 index db46b5478..000000000 --- a/examples/pulsecount/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/examples/pulsecount/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_EXAMPLES_PULSECOUNT),) -CONFIGURED_APPS += $(APPDIR)/examples/pulsecount -endif diff --git a/examples/pulsecount/Makefile b/examples/pulsecount/Makefile deleted file mode 100644 index b03e07503..000000000 --- a/examples/pulsecount/Makefile +++ /dev/null @@ -1,32 +0,0 @@ -############################################################################ -# apps/examples/pulsecount/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -MAINSRC = pulsecount_main.c - -PROGNAME = pulsecount -PRIORITY = SCHED_PRIORITY_DEFAULT -STACKSIZE = $(CONFIG_DEFAULT_TASK_STACKSIZE) -MODULE = $(CONFIG_EXAMPLES_PULSECOUNT) - -include $(APPDIR)/Application.mk diff --git a/examples/pulsecount/pulsecount_main.c b/examples/pulsecount/pulsecount_main.c deleted file mode 100644 index 82678be08..000000000 --- a/examples/pulsecount/pulsecount_main.c +++ /dev/null @@ -1,247 +0,0 @@ -/**************************************************************************** - * apps/examples/pulsecount/pulsecount_main.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <sys/ioctl.h> - -#include <errno.h> -#include <fcntl.h> -#include <inttypes.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> - -#include <nuttx/timers/pulsecount.h> - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -struct pulsecount_state_s -{ - FAR char *devpath; - uint32_t high_ns; - uint32_t low_ns; - uint32_t count; -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static void pulsecount_devpath(FAR struct pulsecount_state_s *state, - FAR const char *devpath) -{ - if (state->devpath != NULL) - { - free(state->devpath); - } - - state->devpath = strdup(devpath); -} - -static int arg_string(FAR char **arg, FAR char **value) -{ - FAR char *ptr = *arg; - - if (ptr[2] == '\0') - { - *value = arg[1]; - return 2; - } - - *value = &ptr[2]; - return 1; -} - -static int arg_decimal(FAR char **arg, FAR long *value) -{ - FAR char *string; - int ret; - - ret = arg_string(arg, &string); - *value = strtol(string, NULL, 10); - return ret; -} - -static void pulsecount_help(FAR struct pulsecount_state_s *state) -{ - printf("Usage: pulsecount [OPTIONS]\n"); - printf(" [-p devpath] Default: %s Current: %s\n", - CONFIG_EXAMPLES_PULSECOUNT_DEVPATH, - state->devpath != NULL ? state->devpath : "NONE"); - printf(" [-H high-ns] Default: %d ns Current: %" PRIu32 " ns\n", - CONFIG_EXAMPLES_PULSECOUNT_HIGH_NS, state->high_ns); - printf(" [-L low-ns] Default: %d ns Current: %" PRIu32 " ns\n", - CONFIG_EXAMPLES_PULSECOUNT_LOW_NS, state->low_ns); - printf(" [-n count] Default: %d Current: %" PRIu32 "\n", - CONFIG_EXAMPLES_PULSECOUNT_COUNT, state->count); - printf(" [-h] shows this message and exits\n"); -} - -static void parse_args(FAR struct pulsecount_state_s *state, int argc, - FAR char **argv) -{ - FAR char *str; - long value; - int index; - int nargs; - - for (index = 1; index < argc; ) - { - if (argv[index][0] != '-') - { - printf("Invalid options format: %s\n", argv[index]); - exit(1); - } - - switch (argv[index][1]) - { - case 'p': - nargs = arg_string(&argv[index], &str); - pulsecount_devpath(state, str); - index += nargs; - break; - - case 'H': - nargs = arg_decimal(&argv[index], &value); - if (value < 1) - { - printf("High time out of range: %ld\n", value); - exit(1); - } - - state->high_ns = (uint32_t)value; - index += nargs; - break; - - case 'L': - nargs = arg_decimal(&argv[index], &value); - if (value < 1) - { - printf("Low time out of range: %ld\n", value); - exit(1); - } - - state->low_ns = (uint32_t)value; - index += nargs; - break; - - case 'n': - nargs = arg_decimal(&argv[index], &value); - if (value < 1) - { - printf("Count out of range: %ld\n", value); - exit(1); - } - - state->count = (uint32_t)value; - index += nargs; - break; - - case 'h': - pulsecount_help(state); - exit(0); - - default: - printf("Unsupported option: %s\n", argv[index]); - pulsecount_help(state); - exit(1); - } - } -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -int main(int argc, FAR char *argv[]) -{ - struct pulsecount_state_s state; - struct pulsecount_info_s info; - int fd; - int ret; - - /* Defaults */ - - memset(&state, 0, sizeof(state)); - state.high_ns = CONFIG_EXAMPLES_PULSECOUNT_HIGH_NS; - state.low_ns = CONFIG_EXAMPLES_PULSECOUNT_LOW_NS; - state.count = CONFIG_EXAMPLES_PULSECOUNT_COUNT; - - /* Parse args */ - - parse_args(&state, argc, argv); - - if (state.devpath == NULL) - { - pulsecount_devpath(&state, CONFIG_EXAMPLES_PULSECOUNT_DEVPATH); - } - - fd = open(state.devpath, O_RDONLY); - if (fd < 0) - { - printf("pulsecount: open %s failed: %d\n", state.devpath, errno); - goto errout; - } - - memset(&info, 0, sizeof(info)); - info.high_ns = state.high_ns; - info.low_ns = state.low_ns; - info.count = state.count; - - printf("pulsecount: high: %" PRIu32 " ns low: %" PRIu32 - " ns count: %" PRIu32 "\n", - info.high_ns, info.low_ns, info.count); - - ret = ioctl(fd, PULSECOUNTIOC_SETCHARACTERISTICS, - (unsigned long)((uintptr_t)&info)); - if (ret < 0) - { - printf("pulsecount: ioctl(PULSECOUNTIOC_SETCHARACTERISTICS) " - "failed: %d\n", errno); - goto errout_with_dev; - } - - ret = ioctl(fd, PULSECOUNTIOC_START, 0); - if (ret < 0) - { - printf("pulsecount: ioctl(PULSECOUNTIOC_START) failed: %d\n", errno); - goto errout_with_dev; - } - - close(fd); - fflush(stdout); - return OK; - -errout_with_dev: - close(fd); -errout: - fflush(stdout); - return ERROR; -} diff --git a/examples/pwfb/CMakeLists.txt b/examples/pwfb/CMakeLists.txt deleted file mode 100644 index 584321e0f..000000000 --- a/examples/pwfb/CMakeLists.txt +++ /dev/null @@ -1,38 +0,0 @@ -# ############################################################################## -# apps/examples/pwfb/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_PWFB) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_PWFB_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_PWFB_CLIENT_PRIO} - STACKSIZE - ${CONFIG_EXAMPLES_PWFB_CLIENT_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_PWFB} - SRCS - pwfb_main.c - INCLUDE_DIRECTORIES - ${NUTTX_APPS_DIR}/graphics/nxglyphs/include) - target_sources(apps PRIVATE pwfb_events.c pwfb_motion.c) -endif() diff --git a/examples/pwfb/Make.defs b/examples/pwfb/Make.defs index 5c25ee26d..1b7e4a0a1 100644 --- a/examples/pwfb/Make.defs +++ b/examples/pwfb/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/pwfb/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/pwfb/Makefile b/examples/pwfb/Makefile index 8403725b6..efe528f2f 100644 --- a/examples/pwfb/Makefile +++ b/examples/pwfb/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/pwfb/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -25,7 +23,7 @@ include $(APPDIR)/Make.defs # NuttX per-window frame buffer graphics example. NXGLYPHS = $(APPDIR)$(DELIM)graphics$(DELIM)nxglyphs -CFLAGS += ${INCDIR_PREFIX}"$(NXGLYPHS)$(DELIM)include" +CFLAGS += ${shell $(INCDIR) "$(CC)" "$(NXGLYPHS)$(DELIM)include"} CSRCS = pwfb_events.c pwfb_motion.c MAINSRC = pwfb_main.c diff --git a/examples/pwfb/pwfb_events.c b/examples/pwfb/pwfb_events.c index bec7a845a..0dcdfbafd 100644 --- a/examples/pwfb/pwfb_events.c +++ b/examples/pwfb/pwfb_events.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/pwfb/pwfb_events.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -31,7 +29,7 @@ #include <stdio.h> #include <stdlib.h> #include <semaphore.h> -#include <nuttx/debug.h> +#include <debug.h> #include <errno.h> #include <nuttx/nx/nx.h> @@ -172,6 +170,8 @@ static void pwfb_tb_position(NXTKWINDOW hwnd, FAR void *arg) { #ifdef CONFIG_EXAMPLES_PWFB_VERBOSE + FAR struct nxeg_state_s *st = (FAR struct nxeg_state_s *)arg; + /* Report the position */ printf("pwfb_tb_position: hwnd=%p size=(%d,%d) pos=(%d,%d) " diff --git a/examples/pwfb/pwfb_internal.h b/examples/pwfb/pwfb_internal.h index f6742736e..3890d7acb 100644 --- a/examples/pwfb/pwfb_internal.h +++ b/examples/pwfb/pwfb_internal.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/pwfb/pwfb_internal.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -91,7 +89,7 @@ # define CONFIG_EXAMPLES_PWFB_BGCOLOR 0x7b5d # else # define CONFIG_EXAMPLES_PWFB_BGCOLOR ' ' -# endif +# endif #endif #ifndef CONFIG_EXAMPLES_PWFB_COLOR1 @@ -101,7 +99,7 @@ # define CONFIG_EXAMPLES_PWFB_COLOR1 0xe73f # else # define CONFIG_EXAMPLES_PWFB_COLOR1 '1' -# endif +# endif #endif #ifndef CONFIG_EXAMPLES_PWFB_COLOR2 @@ -111,16 +109,16 @@ # define CONFIG_EXAMPLES_PWFB_COLOR2 0xdefb # else # define CONFIG_EXAMPLES_PWFB_COLOR2 '2' -# endif +# endif #endif #ifndef CONFIG_EXAMPLES_PWFB_COLOR3 # if CONFIG_EXAMPLES_PWFB_BPP == 24 || CONFIG_EXAMPLES_PWFB_BPP == 32 -# define CONFIG_EXAMPLES_PWFB_COLOR3 0x00ffecb3 +# define CONFIG_EXAMPLES_PWFB_COLOR2 0x00ffecb3 # elif CONFIG_EXAMPLES_PWFB_BPP == 16 -# define CONFIG_EXAMPLES_PWFB_COLOR3 0xff76 +# define CONFIG_EXAMPLES_PWFB_COLOR2 0xff76 # else -# define CONFIG_EXAMPLES_PWFB_COLOR3 '3' +# define CONFIG_EXAMPLES_PWFB_COLOR2 '3' # endif #endif @@ -144,10 +142,6 @@ # endif #endif -#ifdef CONFIG_EXAMPLES_PWFB_DEFAULT_FONT -# define CONFIG_EXAMPLES_PWFB_FONTID FONTID_DEFAULT -#endif - /* Cursor timing */ #if CONFIG_EXAMPLES_PWFB_RATECONTROL > 0 diff --git a/examples/pwfb/pwfb_main.c b/examples/pwfb/pwfb_main.c index cd98a48e2..0d05e1ac9 100644 --- a/examples/pwfb/pwfb_main.c +++ b/examples/pwfb/pwfb_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/pwfb/pwfb_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -39,7 +37,7 @@ #include <pthread.h> #include <fixedmath.h> #include <errno.h> -#include <nuttx/debug.h> +#include <debug.h> #include <nuttx/arch.h> #include <nuttx/board.h> @@ -57,8 +55,6 @@ #include "pwfb_internal.h" -#define ARROW1_CURSOR_IMAGE g_arrow1##Cursor - /**************************************************************************** * Private Data ****************************************************************************/ @@ -117,22 +113,22 @@ static bool pwfb_server_initialize(FAR struct pwfb_state_s *st) #ifdef CONFIG_VNCSERVER /* Setup the VNC server to support keyboard/mouse inputs */ - struct boardioc_vncstart_s vnc = - { - 0, st->hnx - }; + struct boardioc_vncstart_s vnc = + { + 0, st->hnx + }; - ret = boardctl(BOARDIOC_VNC_START, (uintptr_t)&vnc); - if (ret < 0) - { - printf("pwfb_server_initialize: ERROR: " - "boardctl(BOARDIOC_VNC_START) failed: %d\n", - ret); + ret = boardctl(BOARDIOC_VNC_START, (uintptr_t)&vnc); + if (ret < 0) + { + printf("pwfb_server_initialize: ERROR: " + "boardctl(BOARDIOC_VNC_START) failed: %d\n", + ret); - nx_disconnect(st->hnx); - g_exitcode = NXEXIT_FBINITIALIZE; - return ERROR; - } + nx_disconnect(st->hnx); + g_exitcode = NXEXIT_FBINITIALIZE; + return ERROR; + } #endif } else @@ -170,10 +166,10 @@ static bool pwfb_listener_initialize(FAR struct pwfb_state_s *st) ret = pthread_create(&thread, &attr, pwfb_listener, st); if (ret != 0) { - printf("pwfb_listener_initialize: ERROR: " - "pthread_create failed: %d\n", - ret); - return false; + printf("pwfb_listener_initialize: ERROR: " + "pthread_create failed: %d\n", + ret); + return false; } /* Don't return until we are connected to the server */ @@ -341,9 +337,9 @@ static bool pwfb_putc(FAR struct pwfb_state_s *st, /* Render the glyph into the window */ - src = glyph->bitmap; - ret = nxtk_bitmapwindow(wndo->hwnd, &bounds, &src, - fpos, (unsigned int)glyph->stride); + src = (FAR const void *)glyph->bitmap; + ret = nxtk_bitmapwindow(wndo->hwnd, &bounds, &src, + fpos, (unsigned int)glyph->stride); if (ret < 0) { printf("pwfb_putc: ERROR: " @@ -512,8 +508,8 @@ static bool pwfb_configure_cursor(FAR struct pwfb_state_s *st, st->cursor.state = PFWB_CURSOR_MOVING; st->cursor.countdown = CURSOR_MOVING_DELAY; st->cursor.blinktime = 0; - st->cursor.xmax = itob16(st->xres - ARROW1_CURSOR_IMAGE.size.w - 1); - st->cursor.ymax = itob16(st->yres - ARROW1_CURSOR_IMAGE.size.h - 1); + st->cursor.xmax = itob16(st->xres - g_arrow1Cursor.size.w - 1); + st->cursor.ymax = itob16(st->yres - g_arrow1Cursor.size.h - 1); st->cursor.xpos = itob16(pos->x); st->cursor.ypos = itob16(pos->y); st->cursor.deltax = dtob16(deltax); @@ -521,7 +517,7 @@ static bool pwfb_configure_cursor(FAR struct pwfb_state_s *st, /* Set the cursor image */ - ret = nxcursor_setimage(st->hnx, &ARROW1_CURSOR_IMAGE); + ret = nxcursor_setimage(st->hnx, &g_arrow1Cursor); if (ret < 0) { printf("pwfb_configure_cursor: ERROR: " @@ -653,8 +649,7 @@ int main(int argc, FAR char *argv[]) pos.x = wstate.xres / 8; pos.y = wstate.yres / 8; - if (!pwfb_configure_window(&wstate, 0, &size, &pos, g_wndomsg1, - 4.200, 4.285)) + if (!pwfb_configure_window(&wstate, 0, &size, &pos, g_wndomsg1, 4.200, 4.285)) { printf("pwfb_main: ERROR: " "pwfb_configure_window failed for window 1\n"); @@ -684,8 +679,7 @@ int main(int argc, FAR char *argv[]) pos.x = wstate.xres / 4; pos.y = wstate.yres / 4; - if (!pwfb_configure_window(&wstate, 1, &size, &pos, g_wndomsg2, - -3.317, 5.0)) + if (!pwfb_configure_window(&wstate, 1, &size, &pos, g_wndomsg2, -3.317, 5.0)) { printf("pwfb_main: ERROR: " "pwfb_configure_window failed for window 2\n"); @@ -715,8 +709,7 @@ int main(int argc, FAR char *argv[]) pos.x = (3 * wstate.xres) / 8; pos.y = (3 * wstate.yres) / 8; - if (!pwfb_configure_window(&wstate, 2, &size, &pos, g_wndomsg3, - 4.600, -3.852)) + if (!pwfb_configure_window(&wstate, 2, &size, &pos, g_wndomsg3, 4.600, -3.852)) { printf("pwfb_main: ERROR: " "pwfb_configure_window failed for window 2\n"); @@ -802,7 +795,6 @@ errout_with_hwnd1: #endif errout_with_fontcache: - /* Release the font cache */ nxf_cache_disconnect(wstate.wndo[0].fcache); @@ -810,7 +802,6 @@ errout_with_fontcache: nxf_cache_disconnect(wstate.wndo[2].fcache); errout_with_nx: - /* Disconnect from the server */ printf("pwfb_main: Disconnect from the server\n"); diff --git a/examples/pwfb/pwfb_motion.c b/examples/pwfb/pwfb_motion.c index 37ce79d86..b2578ab12 100644 --- a/examples/pwfb/pwfb_motion.c +++ b/examples/pwfb/pwfb_motion.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/pwfb/pwfb_motion.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -179,7 +177,7 @@ static inline bool pwfb_move_cursor(FAR struct pwfb_state_s *st) #ifdef CONFIG_EXAMPLES_PWFB_VERBOSE printf("pwfb_move_cursor: State: %u countdown: %u blinktime: %u\n", (unsigned int)st->cursor.state, (unsigned int)st->cursor.countdown, - (unsigned int)st->cursor.blinktime); + (unsigned int)st->cursor.blinktime; printf("pwfb_move_cursor: Velocity: (%lx.%04lx,%lx.%04lx)\n", (unsigned long)st->cursor.deltax >> 16, (unsigned long)st->cursor.deltax & 0xffff, @@ -188,13 +186,12 @@ static inline bool pwfb_move_cursor(FAR struct pwfb_state_s *st) #endif /* Handle the update based on cursor state */ - /* If the state is not PFWB_CURSOR_STATIONARY, then update the cursor * position. */ - if (st->cursor.state != PFWB_CURSOR_STATIONARY) - { + if (st->cursor.state != PFWB_CURSOR_STATIONARY) + { /* Update X position */ newx = st->cursor.xpos + st->cursor.deltax; @@ -261,7 +258,7 @@ static inline bool pwfb_move_cursor(FAR struct pwfb_state_s *st) return false; } - } + } /* Check for state changes */ diff --git a/examples/pwlines/CMakeLists.txt b/examples/pwlines/CMakeLists.txt deleted file mode 100644 index 9cbe1d2c3..000000000 --- a/examples/pwlines/CMakeLists.txt +++ /dev/null @@ -1,37 +0,0 @@ -# ############################################################################## -# apps/examples/pwlines/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_PWLINES) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_PWLINES_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_PWLINES_CLIENT_PRIO} - STACKSIZE - ${CONFIG_EXAMPLES_PWLINES_CLIENT_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_PWLINES} - SRCS - pwlines_main.c) - target_sources(apps PRIVATE pwlines_events.c pwlines_motion.c - pwlines_update.c) -endif() diff --git a/examples/pwlines/Make.defs b/examples/pwlines/Make.defs index 0454dc2ef..3e6a64e93 100644 --- a/examples/pwlines/Make.defs +++ b/examples/pwlines/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/pwlines/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/pwlines/Makefile b/examples/pwlines/Makefile index fc85c7b86..342d9f2ca 100644 --- a/examples/pwlines/Makefile +++ b/examples/pwlines/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/pwlines/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/pwlines/pwlines_events.c b/examples/pwlines/pwlines_events.c index 3dcd0504c..2441ae091 100644 --- a/examples/pwlines/pwlines_events.c +++ b/examples/pwlines/pwlines_events.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/pwlines/pwlines_events.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -31,7 +29,7 @@ #include <stdio.h> #include <stdlib.h> #include <semaphore.h> -#include <nuttx/debug.h> +#include <debug.h> #include <errno.h> #include <nuttx/nx/nx.h> diff --git a/examples/pwlines/pwlines_internal.h b/examples/pwlines/pwlines_internal.h index 9b830cabe..2d6fefaf5 100644 --- a/examples/pwlines/pwlines_internal.h +++ b/examples/pwlines/pwlines_internal.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/pwlines/pwlines_internal.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -32,7 +30,6 @@ #include <stdint.h> #include <stdbool.h> #include <semaphore.h> -#include <sys/param.h> #include <fixedmath.h> #include <nuttx/nx/nx.h> @@ -83,7 +80,7 @@ # define CONFIG_EXAMPLES_PWLINES_BGCOLOR 0x7b5d # else # define CONFIG_EXAMPLES_PWLINES_BGCOLOR ' ' -# endif +# endif #endif #ifndef CONFIG_EXAMPLES_PWLINES_COLOR1 @@ -93,7 +90,7 @@ # define CONFIG_EXAMPLES_PWLINES_COLOR1 RGB16_DARKGREEN # else # define CONFIG_EXAMPLES_PWLINES_COLOR1 RGB8_DARKGREEN -# endif +# endif #endif #ifndef CONFIG_EXAMPLES_PWLINES_COLOR2 @@ -103,7 +100,7 @@ # define CONFIG_EXAMPLES_PWLINES_COLOR2 RGB16_GREEN # else # define CONFIG_EXAMPLES_PWLINES_COLOR2 RGB8_GREEN -# endif +# endif #endif #ifndef CONFIG_EXAMPLES_PWLINES_COLOR3 @@ -113,7 +110,7 @@ # define CONFIG_EXAMPLES_PWLINES_COLOR3 RGB16_LIGHTGREEN # else # define CONFIG_EXAMPLES_PWLINES_COLOR3 RGB8_LIGHTGREEN -# endif +# endif #endif #ifndef CONFIG_EXAMPLES_PWLINES_BORDERWIDTH @@ -154,6 +151,16 @@ # endif #endif +/* Helpers */ + +#ifndef MIN +# define MIN(a,b) (((a) < (b)) ? (a) : (b)) +#endif + +#ifndef MAX +# define MAX(a,b) (((a) > (b)) ? (a) : (b)) +#endif + /**************************************************************************** * Public Types ****************************************************************************/ diff --git a/examples/pwlines/pwlines_main.c b/examples/pwlines/pwlines_main.c index 53a2b3a53..894fd5a3c 100644 --- a/examples/pwlines/pwlines_main.c +++ b/examples/pwlines/pwlines_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/pwlines/pwlines_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -39,7 +37,7 @@ #include <pthread.h> #include <fixedmath.h> #include <errno.h> -#include <nuttx/debug.h> +#include <debug.h> #include <nuttx/arch.h> #include <nuttx/board.h> @@ -94,21 +92,21 @@ static bool pwlines_server_initialize(FAR struct pwlines_state_s *st) #ifdef CONFIG_VNCSERVER /* Setup the VNC server to support keyboard/mouse inputs */ - struct boardioc_vncstart_s vnc = - { - 0, st->hnx - }; + struct boardioc_vncstart_s vnc = + { + 0, st->hnx + }; - ret = boardctl(BOARDIOC_VNC_START, (uintptr_t)&vnc); - if (ret < 0) - { - printf("pwlines_server_initialize: ERROR: " - "boardctl(BOARDIOC_VNC_START) failed: %d\n", - ret); + ret = boardctl(BOARDIOC_VNC_START, (uintptr_t)&vnc); + if (ret < 0) + { + printf("pwlines_server_initialize: ERROR: " + "boardctl(BOARDIOC_VNC_START) failed: %d\n", + ret); - nx_disconnect(st->hnx); - return false; - } + nx_disconnect(st->hnx); + return false; + } #endif } else @@ -141,16 +139,15 @@ static bool pwlines_listener_initialize(FAR struct pwlines_state_s *st) pthread_attr_init(&attr); param.sched_priority = CONFIG_EXAMPLES_PWLINES_LISTENER_PRIO; pthread_attr_setschedparam(&attr, ¶m); - pthread_attr_setstacksize(&attr, - CONFIG_EXAMPLES_PWLINES_LISTENER_STACKSIZE); + pthread_attr_setstacksize(&attr, CONFIG_EXAMPLES_PWLINES_LISTENER_STACKSIZE); ret = pthread_create(&thread, &attr, pwlines_listener, st); if (ret != 0) { - printf("pwlines_listener_initialize: ERROR: " - "pthread_create failed: %d\n", - ret); - return false; + printf("pwlines_listener_initialize: ERROR: " + "pthread_create failed: %d\n", + ret); + return false; } /* Don't return until we are connected to the server */ @@ -194,8 +191,7 @@ static bool pwlines_state_initialize(FAR struct pwlines_state_s *st) * Name: pwlines_configure_window ****************************************************************************/ -static bool pwlines_configure_window(FAR struct pwlines_state_s *st, - int wndx, +static bool pwlines_configure_window(FAR struct pwlines_state_s *st, int wndx, FAR struct nxgl_size_s *size, FAR struct nxgl_point_s *pos, double deltax, double deltay) @@ -355,9 +351,8 @@ int main(int argc, FAR char *argv[]) printf("pwlines_main: Open window 1\n"); - wstate.wndo[0].hwnd = - nxtk_openwindow(wstate.hnx, NXBE_WINDOW_RAMBACKED, - &g_pwlines_wncb, (FAR void *)&wstate); + wstate.wndo[0].hwnd = nxtk_openwindow(wstate.hnx, NXBE_WINDOW_RAMBACKED, + &g_pwlines_wncb, (FAR void *)&wstate); if (wstate.wndo[0].hwnd == NULL) { printf("pwlines_main: ERROR: " @@ -389,8 +384,7 @@ int main(int argc, FAR char *argv[]) pos.x = wstate.xres / 8; pos.y = wstate.yres / 8; - if (!pwlines_configure_window(&wstate, 0, &size, &pos, - 4.200, 4.285)) + if (!pwlines_configure_window(&wstate, 0, &size, &pos, 4.200, 4.285)) { printf("pwlines_main: ERROR: " "pwlines_configure_window failed for window 1\n"); @@ -401,9 +395,8 @@ int main(int argc, FAR char *argv[]) printf("pwlines_main: Open window 2\n"); - wstate.wndo[1].hwnd = - nxtk_openwindow(wstate.hnx, NXBE_WINDOW_RAMBACKED, - &g_pwlines_wncb, (FAR void *)&wstate); + wstate.wndo[1].hwnd = nxtk_openwindow(wstate.hnx, NXBE_WINDOW_RAMBACKED, + &g_pwlines_wncb, (FAR void *)&wstate); if (wstate.wndo[1].hwnd == NULL) { printf("pwlines_main: ERROR: " @@ -419,8 +412,7 @@ int main(int argc, FAR char *argv[]) pos.x = wstate.xres / 4; pos.y = wstate.yres / 4; - if (!pwlines_configure_window(&wstate, 1, &size, &pos, - -3.317, 5.0)) + if (!pwlines_configure_window(&wstate, 1, &size, &pos, -3.317, 5.0)) { printf("pwlines_main: ERROR: " "pwlines_configure_window failed for window 2\n"); @@ -431,9 +423,8 @@ int main(int argc, FAR char *argv[]) printf("pwlines_main: Open window 3\n"); - wstate.wndo[2].hwnd = - nxtk_openwindow(wstate.hnx, NXBE_WINDOW_RAMBACKED, - &g_pwlines_wncb, (FAR void *)&wstate); + wstate.wndo[2].hwnd = nxtk_openwindow(wstate.hnx, NXBE_WINDOW_RAMBACKED, + &g_pwlines_wncb, (FAR void *)&wstate); if (wstate.wndo[2].hwnd == NULL) { printf("pwlines_main: ERROR: " @@ -449,8 +440,7 @@ int main(int argc, FAR char *argv[]) pos.x = (3 * wstate.xres) / 8; pos.y = (3 * wstate.yres) / 8; - if (!pwlines_configure_window(&wstate, 2, &size, &pos, - 4.600, -3.852)) + if (!pwlines_configure_window(&wstate, 2, &size, &pos, 4.600, -3.852)) { printf("pwlines_main: ERROR: " "pwlines_configure_window failed for window 2\n"); @@ -520,7 +510,6 @@ errout_with_hwnd1: } errout_with_nx: - /* Disconnect from the server */ printf("pwlines_main: Disconnect from the server\n"); diff --git a/examples/pwlines/pwlines_motion.c b/examples/pwlines/pwlines_motion.c index a812d4d73..cf33a6363 100644 --- a/examples/pwlines/pwlines_motion.c +++ b/examples/pwlines/pwlines_motion.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/pwlines/pwlines_motion.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/pwlines/pwlines_update.c b/examples/pwlines/pwlines_update.c index 37d41456e..527a963cd 100644 --- a/examples/pwlines/pwlines_update.c +++ b/examples/pwlines/pwlines_update.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/pwlines/pwlines_update.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -29,11 +27,10 @@ #include <stdint.h> #include <stdio.h> #include <stdlib.h> -#include <sys/param.h> #include <inttypes.h> #include <unistd.h> #include <string.h> -#include <nuttx/debug.h> +#include <debug.h> #include <fixedmath.h> #include <nuttx/nx/nx.h> @@ -55,6 +52,10 @@ # define CLEAR_WIDTH CONFIG_EXAMPLES_PWLINES_LINEWIDTH #endif +#ifndef MIN +# define MIN(a,b) (a < b ? a : b) +#endif + /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/examples/pwm/CMakeLists.txt b/examples/pwm/CMakeLists.txt deleted file mode 100644 index 2d39c573a..000000000 --- a/examples/pwm/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# ############################################################################## -# apps/examples/pwm/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_PWM) - nuttx_add_application( - NAME - pwm - STACKSIZE - ${CONFIG_DEFAULT_TASK_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_PWM} - SRCS - pwm_main.c) -endif() diff --git a/examples/pwm/Kconfig b/examples/pwm/Kconfig index facd1b6dd..3b406e3ab 100644 --- a/examples/pwm/Kconfig +++ b/examples/pwm/Kconfig @@ -28,7 +28,11 @@ config EXAMPLES_PWM_DURATION int "Default PWM duration" default 5 ---help--- - The default PWM pulse train duration in seconds. Default: 5 seconds + The default PWM pulse train duration in seconds. Used only if the current + pulse count is zero (pulse count is only supported if PWM_PULSECOUNT + is not defined). Default: 5 seconds + +if PWM_MULTICHAN config EXAMPLES_PWM_DUTYPCT1 int "First PWM duty percentage" @@ -40,7 +44,7 @@ config EXAMPLES_PWM_DUTYPCT1 config EXAMPLES_PWM_CHANNEL1 int "First PWM channel number" default 1 - range -1 6 + range 1 6 ---help--- The first PWM channel number. Default: 1 @@ -56,7 +60,7 @@ config EXAMPLES_PWM_DUTYPCT2 config EXAMPLES_PWM_CHANNEL2 int "Second PWM channel number" default 2 - range -1 6 + range 1 6 ---help--- The second PWM channel number. Default: 2 @@ -74,7 +78,7 @@ config EXAMPLES_PWM_DUTYPCT3 config EXAMPLES_PWM_CHANNEL3 int "Third PWM channel number" default 3 - range -1 6 + range 1 6 ---help--- The third PWM channel number. Default: 3 @@ -92,7 +96,7 @@ config EXAMPLES_PWM_DUTYPCT4 config EXAMPLES_PWM_CHANNEL4 int "Fourth PWM channel number" default 4 - range -1 6 + range 1 6 ---help--- The fourth PWM channel number. Default: 4 @@ -110,7 +114,7 @@ config EXAMPLES_PWM_DUTYPCT5 config EXAMPLES_PWM_CHANNEL5 int "Fifth PWM channel number" default 5 - range -1 6 + range 1 6 ---help--- The fifth PWM channel number. Default: 5 @@ -125,13 +129,35 @@ config EXAMPLES_PWM_DUTYPCT6 ---help--- The sixth PWM duty as a percentage. Default: 50% -config EXAMPLES_PWM_CHANNEL6 +config EXAMPLES_PWM_CHANNEL5 int "Sixth PWM channel number" default 6 - range -1 6 + range 1 6 ---help--- The sixth PWM channel number. Default: 6 endif endif + +if !PWM_MULTICHAN + +config EXAMPLES_PWM_DUTYPCT + int "Default PWM duty percentage" + default 50 + range 1 99 + ---help--- + The default PWM duty as a percentage. Default: 50% + +config EXAMPLES_PWM_PULSECOUNT + int "Default pulse count" + default 0 + depends on PWM_PULSECOUNT + ---help--- + The initial PWM pulse count. This option is only available if + PWM_PULSECOUNT is defined. Default: 0 (i.e., use the duration, not + the count). + +endif + +endif diff --git a/examples/pwm/Make.defs b/examples/pwm/Make.defs index 999dcb596..065f65636 100644 --- a/examples/pwm/Make.defs +++ b/examples/pwm/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/pwm/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/pwm/Makefile b/examples/pwm/Makefile index 785182d35..d2e44c072 100644 --- a/examples/pwm/Makefile +++ b/examples/pwm/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/pwm/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/pwm/pwm.h b/examples/pwm/pwm.h index 389241626..93cc1f36a 100644 --- a/examples/pwm/pwm.h +++ b/examples/pwm/pwm.h @@ -1,7 +1,5 @@ /**************************************************************************** - * apps/examples/pwm/pwm.h - * - * SPDX-License-Identifier: Apache-2.0 + * apps/examples/examples/pwm/pwm.h * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -32,21 +30,17 @@ /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ - /* Configuration ************************************************************/ - /* CONFIG_NSH_BUILTIN_APPS - Build the PWM test as an NSH built-in function. - * CONFIG_EXAMPLES_PWM_DEVPATH - The path to the PWM device. - * Default: /dev/pwm0 - * CONFIG_EXAMPLES_PWM_FREQUENCY - The initial PWM frequency. - * Default: 100 Hz - * CONFIG_EXAMPLES_PWM_DUTYPCTn - The initial PWM duty as a percentage for - * channel n. Default: 50% - * CONFIG_EXAMPLES_PWM_CHANNELn - The PWM channel number for channel n. - * Default: n - * CONFIG_EXAMPLES_PWM_DURATION - The initial PWM pulse train duration - * in seconds. - * Default: 5 seconds + * CONFIG_EXAMPLES_PWM_DEVPATH - The path to the PWM device. Default: /dev/pwm0 + * CONFIG_EXAMPLES_PWM_FREQUENCY - The initial PWM frequency. Default: 100 Hz + * CONFIG_EXAMPLES_PWM_DUTYPCT - The initial PWM duty as a percentage. Default: 50% + * CONFIG_EXAMPLES_PWM_DURATION - The initial PWM pulse train duration in seconds. + * Used only if the current pulse count is zero (pulse count is only supported + * if CONFIG_PWM_PULSECOUNT is defined). Default: 5 seconds + * CONFIG_EXAMPLES_PWM_PULSECOUNT - The initial PWM pulse count. This option is + * only available if CONFIG_PWM_PULSECOUNT is defined. Default: 0 (i.e., use + * the duration, not the count). */ #ifndef CONFIG_PWM @@ -61,10 +55,18 @@ # define CONFIG_EXAMPLES_PWM_FREQUENCY 100 #endif +#ifndef CONFIG_EXAMPLES_PWM_DUTYPCT +# define CONFIG_EXAMPLES_PWM_DUTYPCT 50 +#endif + #ifndef CONFIG_EXAMPLES_PWM_DURATION # define CONFIG_EXAMPLES_PWM_DURATION 5 #endif +#ifndef CONFIG_EXAMPLES_PWM_PULSECOUNT +# define CONFIG_EXAMPLES_PWM_PULSECOUNT 0 +#endif + /**************************************************************************** * Public Types ****************************************************************************/ diff --git a/examples/pwm/pwm_main.c b/examples/pwm/pwm_main.c index e373a5bb0..497d58abb 100644 --- a/examples/pwm/pwm_main.c +++ b/examples/pwm/pwm_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/pwm/pwm_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -34,7 +32,7 @@ #include <unistd.h> #include <fcntl.h> #include <errno.h> -#include <nuttx/debug.h> +#include <debug.h> #include <string.h> #include <inttypes.h> @@ -48,43 +46,45 @@ /* Configuration ************************************************************/ -#if CONFIG_PWM_NCHANNELS > 1 -# if CONFIG_EXAMPLES_PWM_CHANNEL1 == CONFIG_EXAMPLES_PWM_CHANNEL2 -# error "Channel numbers must be unique" +#ifdef CONFIG_PWM_MULTICHAN +# if CONFIG_PWM_NCHANNELS > 1 +# if CONFIG_EXAMPLES_PWM_CHANNEL1 == CONFIG_EXAMPLES_PWM_CHANNEL2 +# error "Channel numbers must be unique" +# endif # endif -#endif -#if CONFIG_PWM_NCHANNELS > 2 -# if CONFIG_EXAMPLES_PWM_CHANNEL1 == CONFIG_EXAMPLES_PWM_CHANNEL3 || \ +# if CONFIG_PWM_NCHANNELS > 2 +# if CONFIG_EXAMPLES_PWM_CHANNEL1 == CONFIG_EXAMPLES_PWM_CHANNEL3 || \ CONFIG_EXAMPLES_PWM_CHANNEL2 == CONFIG_EXAMPLES_PWM_CHANNEL3 -# error "Channel numbers must be unique" +# error "Channel numbers must be unique" +# endif # endif -#endif -#if CONFIG_PWM_NCHANNELS > 3 -# if CONFIG_EXAMPLES_PWM_CHANNEL1 == CONFIG_EXAMPLES_PWM_CHANNEL4 || \ +# if CONFIG_PWM_NCHANNELS > 3 +# if CONFIG_EXAMPLES_PWM_CHANNEL1 == CONFIG_EXAMPLES_PWM_CHANNEL4 || \ CONFIG_EXAMPLES_PWM_CHANNEL2 == CONFIG_EXAMPLES_PWM_CHANNEL4 || \ CONFIG_EXAMPLES_PWM_CHANNEL3 == CONFIG_EXAMPLES_PWM_CHANNEL4 -# error "Channel numbers must be unique" +# error "Channel numbers must be unique" +# endif # endif -#endif -#if CONFIG_PWM_NCHANNELS > 4 -# if CONFIG_EXAMPLES_PWM_CHANNEL1 == CONFIG_EXAMPLES_PWM_CHANNEL5 || \ +# if CONFIG_PWM_NCHANNELS > 4 +# if CONFIG_EXAMPLES_PWM_CHANNEL1 == CONFIG_EXAMPLES_PWM_CHANNEL5 || \ CONFIG_EXAMPLES_PWM_CHANNEL2 == CONFIG_EXAMPLES_PWM_CHANNEL5 || \ CONFIG_EXAMPLES_PWM_CHANNEL3 == CONFIG_EXAMPLES_PWM_CHANNEL5 || \ CONFIG_EXAMPLES_PWM_CHANNEL4 == CONFIG_EXAMPLES_PWM_CHANNEL5 -# error "Channel numbers must be unique" +# error "Channel numbers must be unique" +# endif # endif -#endif -#if CONFIG_PWM_NCHANNELS > 5 -# if CONFIG_EXAMPLES_PWM_CHANNEL1 == CONFIG_EXAMPLES_PWM_CHANNEL6 || \ +# if CONFIG_PWM_NCHANNELS > 5 +# if CONFIG_EXAMPLES_PWM_CHANNEL1 == CONFIG_EXAMPLES_PWM_CHANNEL6 || \ CONFIG_EXAMPLES_PWM_CHANNEL2 == CONFIG_EXAMPLES_PWM_CHANNEL6 || \ CONFIG_EXAMPLES_PWM_CHANNEL3 == CONFIG_EXAMPLES_PWM_CHANNEL6 || \ CONFIG_EXAMPLES_PWM_CHANNEL4 == CONFIG_EXAMPLES_PWM_CHANNEL6 || \ CONFIG_EXAMPLES_PWM_CHANNEL5 == CONFIG_EXAMPLES_PWM_CHANNEL6 -# error "Channel numbers must be unique" +# error "Channel numbers must be unique" +# endif +# endif +# if CONFIG_PWM_NCHANNELS > 6 +# error "Too many PWM channels" # endif -#endif -#if CONFIG_PWM_NCHANNELS > 6 -# error "Too many PWM channels" #endif /**************************************************************************** @@ -95,9 +95,16 @@ struct pwm_state_s { bool initialized; FAR char *devpath; - int8_t channels[CONFIG_PWM_NCHANNELS]; +#ifdef CONFIG_PWM_MULTICHAN + uint8_t channels[CONFIG_PWM_NCHANNELS]; uint8_t duties[CONFIG_PWM_NCHANNELS]; +#else + uint8_t duty; +#endif uint32_t freq; +#ifdef CONFIG_PWM_PULSECOUNT + uint32_t count; +#endif int duration; }; @@ -143,52 +150,54 @@ static void pwm_devpath(FAR struct pwm_state_s *pwm, FAR const char *devpath) static void pwm_help(FAR struct pwm_state_s *pwm) { - int8_t channels[CONFIG_PWM_NCHANNELS] = - { - CONFIG_EXAMPLES_PWM_CHANNEL1, +#ifdef CONFIG_PWM_MULTICHAN + uint8_t channels[CONFIG_PWM_NCHANNELS] = + { + CONFIG_EXAMPLES_PWM_CHANNEL1, #if CONFIG_PWM_NCHANNELS > 1 - CONFIG_EXAMPLES_PWM_CHANNEL2, + CONFIG_EXAMPLES_PWM_CHANNEL2, #endif #if CONFIG_PWM_NCHANNELS > 2 - CONFIG_EXAMPLES_PWM_CHANNEL3, + CONFIG_EXAMPLES_PWM_CHANNEL3, #endif #if CONFIG_PWM_NCHANNELS > 3 - CONFIG_EXAMPLES_PWM_CHANNEL4, + CONFIG_EXAMPLES_PWM_CHANNEL4, #endif #if CONFIG_PWM_NCHANNELS > 4 - CONFIG_EXAMPLES_PWM_CHANNEL5, + CONFIG_EXAMPLES_PWM_CHANNEL5, #endif #if CONFIG_PWM_NCHANNELS > 5 - CONFIG_EXAMPLES_PWM_CHANNEL6, + CONFIG_EXAMPLES_PWM_CHANNEL6, #endif - }; + }; uint8_t duties[CONFIG_PWM_NCHANNELS] = - { - CONFIG_EXAMPLES_PWM_DUTYPCT1, + { + CONFIG_EXAMPLES_PWM_DUTYPCT1, #if CONFIG_PWM_NCHANNELS > 1 - CONFIG_EXAMPLES_PWM_DUTYPCT2, + CONFIG_EXAMPLES_PWM_DUTYPCT2, #endif #if CONFIG_PWM_NCHANNELS > 2 - CONFIG_EXAMPLES_PWM_DUTYPCT3, + CONFIG_EXAMPLES_PWM_DUTYPCT3, #endif #if CONFIG_PWM_NCHANNELS > 3 - CONFIG_EXAMPLES_PWM_DUTYPCT4, + CONFIG_EXAMPLES_PWM_DUTYPCT4, #endif #if CONFIG_PWM_NCHANNELS > 4 - CONFIG_EXAMPLES_PWM_DUTYPCT5, + CONFIG_EXAMPLES_PWM_DUTYPCT5, #endif #if CONFIG_PWM_NCHANNELS > 5 - CONFIG_EXAMPLES_PWM_DUTYPCT6, + CONFIG_EXAMPLES_PWM_DUTYPCT6, #endif - }; + }; int i; +#endif printf("Usage: pwm [OPTIONS]\n"); printf("\nArguments are \"sticky\". " "For example, once the PWM frequency is\n"); - printf("specified, that frequency will be reused until it is changed.\n"); + printf("specified, that frequency will be re-used until it is changed.\n"); printf("\n\"sticky\" OPTIONS include:\n"); printf(" [-p devpath] selects the PWM device. " "Default: %s Current: %s\n", @@ -196,6 +205,7 @@ static void pwm_help(FAR struct pwm_state_s *pwm) printf(" [-f frequency] selects the pulse frequency. " "Default: %d Hz Current: %" PRIu32 " Hz\n", CONFIG_EXAMPLES_PWM_FREQUENCY, pwm->freq); +#ifdef CONFIG_PWM_MULTICHAN printf(" [[-c channel1] [[-c channel2] ...]] " "selects the channel number for each channel. "); printf("Default:"); @@ -227,6 +237,16 @@ static void pwm_help(FAR struct pwm_state_s *pwm) } printf("\n"); +#else + printf(" [-d duty] selects the pulse duty as a percentage. " + "Default: %d %% Current: %d %%\n", + CONFIG_EXAMPLES_PWM_DUTYPCT, pwm->duty); +#endif +#ifdef CONFIG_PWM_PULSECOUNT + printf(" [-n count] selects the pulse count. " + "Default: %d Current: %" PRIx32 "\n", + CONFIG_EXAMPLES_PWM_PULSECOUNT, pwm->count); +#endif printf(" [-t duration] is the duration of the pulse train in seconds. " "Default: %d Current: %d\n", CONFIG_EXAMPLES_PWM_DURATION, pwm->duration); @@ -279,10 +299,10 @@ static void parse_args(FAR struct pwm_state_s *pwm, int argc, long value; int index; int nargs; -#if CONFIG_PWM_NCHANNELS > 1 +#ifdef CONFIG_PWM_MULTICHAN int nchannels = 0; -#endif int nduties = 0; +#endif for (index = 1; index < argc; ) { @@ -307,7 +327,7 @@ static void parse_args(FAR struct pwm_state_s *pwm, int argc, index += nargs; break; -#if CONFIG_PWM_NCHANNELS > 1 +#ifdef CONFIG_PWM_MULTICHAN case 'c': nargs = arg_decimal(&argv[index], &value); if (value < -1 || value > CONFIG_PWM_NCHANNELS) @@ -339,6 +359,7 @@ static void parse_args(FAR struct pwm_state_s *pwm, int argc, exit(1); } +#ifdef CONFIG_PWM_MULTICHAN if (nduties < CONFIG_PWM_NCHANNELS) { nduties++; @@ -350,9 +371,26 @@ static void parse_args(FAR struct pwm_state_s *pwm, int argc, } pwm->duties[nduties - 1] = (uint8_t)value; +#else + pwm->duty = (uint8_t)value; +#endif index += nargs; break; +#ifdef CONFIG_PWM_PULSECOUNT + case 'n': + nargs = arg_decimal(&argv[index], &value); + if (value < 0) + { + printf("Count must be non-negative: %ld\n", value); + exit(1); + } + + pwm->count = (uint32_t)value; + index += nargs; + break; +#endif + case 'p': nargs = arg_string(&argv[index], &str); pwm_devpath(pwm, str); @@ -396,13 +434,16 @@ int main(int argc, FAR char *argv[]) struct pwm_info_s info; int fd; int ret; +#ifdef CONFIG_PWM_MULTICHAN int i; int j; +#endif /* Initialize the state data */ if (!g_pwmstate.initialized) { +#ifdef CONFIG_PWM_MULTICHAN g_pwmstate.channels[0] = CONFIG_EXAMPLES_PWM_CHANNEL1; g_pwmstate.duties[0] = CONFIG_EXAMPLES_PWM_DUTYPCT1; #if CONFIG_PWM_NCHANNELS > 1 @@ -424,9 +465,15 @@ int main(int argc, FAR char *argv[]) #if CONFIG_PWM_NCHANNELS > 5 g_pwmstate.channels[5] = CONFIG_EXAMPLES_PWM_CHANNEL6; g_pwmstate.duties[5] = CONFIG_EXAMPLES_PWM_DUTYPCT6; +#endif +#else + g_pwmstate.duty = CONFIG_EXAMPLES_PWM_DUTYPCT; #endif g_pwmstate.freq = CONFIG_EXAMPLES_PWM_FREQUENCY; g_pwmstate.duration = CONFIG_EXAMPLES_PWM_DURATION; +#ifdef CONFIG_PWM_PULSECOUNT + g_pwmstate.count = CONFIG_EXAMPLES_PWM_PULSECOUNT; +#endif g_pwmstate.initialized = true; } @@ -434,23 +481,19 @@ int main(int argc, FAR char *argv[]) parse_args(&g_pwmstate, argc, argv); - for (i = 0; i < CONFIG_PWM_NCHANNELS; i++) +#ifdef CONFIG_PWM_MULTICHAN + for (i = 0; i < CONFIG_PWM_MULTICHAN; i++) { - if (g_pwmstate.channels[i] < 1) + for (j = i + 1; j < CONFIG_PWM_MULTICHAN; j++) { - continue; - } - - for (j = i + 1; j < CONFIG_PWM_NCHANNELS; j++) - { - if (g_pwmstate.channels[j] > 0 && - g_pwmstate.channels[j] == g_pwmstate.channels[i]) + if (g_pwmstate.channels[j] == g_pwmstate.channels[i]) { printf("pwm_main: channel numbers must be unique\n"); goto errout; } } } +#endif /* Has a device been assigned? */ @@ -472,22 +515,39 @@ int main(int argc, FAR char *argv[]) /* Configure the characteristics of the pulse train */ - memset(&info, 0, sizeof(info)); info.frequency = g_pwmstate.freq; +#ifdef CONFIG_PWM_MULTICHAN printf("pwm_main: starting output with frequency: %" PRIu32, info.frequency); for (i = 0; i < CONFIG_PWM_NCHANNELS; i++) { info.channels[i].channel = g_pwmstate.channels[i]; - info.channels[i].duty = g_pwmstate.duties[i] ? \ - b16divi(uitoub16(g_pwmstate.duties[i]) - 1, 100) : 0; + info.channels[i].duty = b16divi(uitoub16(g_pwmstate.duties[i]), 100); printf(" channel: %d duty: %08" PRIx32, info.channels[i].channel, info.channels[i].duty); } printf("\n"); +#else + info.duty = b16divi(uitoub16(g_pwmstate.duty), 100); +# ifdef CONFIG_PWM_PULSECOUNT + info.count = g_pwmstate.count; + + printf("pwm_main: starting output " + "with frequency: %" PRIu32 " duty: %08" PRIx32 + " count: %" PRIx32 "\n", + info.frequency, (uint32_t)info.duty, info.count); + +# else + printf("pwm_main: starting output " + "with frequency: %" PRIu32 " duty: %08" PRIx32 "\n", + info.frequency, (uint32_t)info.duty); + +# endif +#endif + ret = ioctl(fd, PWMIOC_SETCHARACTERISTICS, (unsigned long)((uintptr_t)&info)); if (ret < 0) @@ -497,7 +557,9 @@ int main(int argc, FAR char *argv[]) goto errout_with_dev; } - /* Then start the pulse train. */ + /* Then start the pulse train. Since the driver was opened in blocking + * mode, this call will block if the count value is greater than zero. + */ ret = ioctl(fd, PWMIOC_START, 0); if (ret < 0) @@ -506,19 +568,28 @@ int main(int argc, FAR char *argv[]) goto errout_with_dev; } - /* Wait for the specified duration, then stop the PWM output. */ + /* It a non-zero count was not specified, then wait for the selected + * duration, then stop the PWM output. + */ - sleep(g_pwmstate.duration); - - /* Then stop the pulse train */ - - printf("pwm_main: stopping output\n"); - - ret = ioctl(fd, PWMIOC_STOP, 0); - if (ret < 0) +#ifdef CONFIG_PWM_PULSECOUNT + if (info.count == 0) +#endif { - printf("pwm_main: ioctl(PWMIOC_STOP) failed: %d\n", errno); - goto errout_with_dev; + /* Wait for the specified duration */ + + sleep(g_pwmstate.duration); + + /* Then stop the pulse train */ + + printf("pwm_main: stopping output\n"); + + ret = ioctl(fd, PWMIOC_STOP, 0); + if (ret < 0) + { + printf("pwm_main: ioctl(PWMIOC_STOP) failed: %d\n", errno); + goto errout_with_dev; + } } close(fd); diff --git a/examples/qencoder/CMakeLists.txt b/examples/qencoder/CMakeLists.txt deleted file mode 100644 index 308f9e4ad..000000000 --- a/examples/qencoder/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# ############################################################################## -# apps/examples/qencoder/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_QENCODER) - nuttx_add_application( - NAME - qe - STACKSIZE - ${CONFIG_DEFAULT_TASK_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_QENCODER} - SRCS - qe_main.c) -endif() diff --git a/examples/qencoder/Make.defs b/examples/qencoder/Make.defs index 46a43c14d..0778b6aad 100644 --- a/examples/qencoder/Make.defs +++ b/examples/qencoder/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/qencoder/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/qencoder/Makefile b/examples/qencoder/Makefile index 1e0866175..354c8ee2f 100644 --- a/examples/qencoder/Makefile +++ b/examples/qencoder/Makefile @@ -1,7 +1,5 @@ ############################################################################ -# apps/examples/qencoder/Makefile -# -# SPDX-License-Identifier: Apache-2.0 +# apps/examples/qe/Makefile # # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with @@ -22,7 +20,7 @@ include $(APPDIR)/Make.defs -# Quadrature Encoder example. +# NuttX NX Graphics Example. MAINSRC = qe_main.c diff --git a/examples/qencoder/qe.h b/examples/qencoder/qe.h index 2baa5de1e..2c001ba33 100644 --- a/examples/qencoder/qe.h +++ b/examples/qencoder/qe.h @@ -1,7 +1,5 @@ /**************************************************************************** - * apps/examples/qencoder/qe.h - * - * SPDX-License-Identifier: Apache-2.0 + * apps/examples/examples/qe/qe.h * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -41,7 +39,6 @@ struct qe_example_s { FAR char *devpath; /* Path to the QE device */ bool reset; /* True: set the count back to zero */ - bool use_qeindex; /* True: use the QEIOC_GETINDEX call to get samples */ unsigned int nloops; /* Collect this number of samples */ unsigned int delay; /* Delay this number of seconds between samples */ }; diff --git a/examples/qencoder/qe_main.c b/examples/qencoder/qe_main.c index 23e529802..eb23b5b3c 100644 --- a/examples/qencoder/qe_main.c +++ b/examples/qencoder/qe_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/qencoder/qe_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -37,7 +35,7 @@ #include <limits.h> #include <inttypes.h> #include <errno.h> -#include <nuttx/debug.h> +#include <debug.h> #include <nuttx/sensors/qencoder.h> @@ -105,7 +103,6 @@ static void qe_help(void) printf(" [-n samples] Number of samples\n"); printf(" [-t msec] Delay between samples (msec)\n"); printf(" [-r] Reset the position to zero\n"); - printf(" [-i] Use the QEIOC_GETINDEX call to obtain samples\n"); printf(" [-h] Shows this message and exits\n\n"); } @@ -155,10 +152,9 @@ static void parse_args(int argc, FAR char **argv) int index; int nargs; - g_qeexample.reset = false; - g_qeexample.use_qeindex = false; - g_qeexample.nloops = CONFIG_EXAMPLES_QENCODER_NSAMPLES; - g_qeexample.delay = CONFIG_EXAMPLES_QENCODER_DELAY; + g_qeexample.reset = false; + g_qeexample.nloops = CONFIG_EXAMPLES_QENCODER_NSAMPLES; + g_qeexample.delay = CONFIG_EXAMPLES_QENCODER_DELAY; for (index = 1; index < argc; ) { @@ -206,11 +202,6 @@ static void parse_args(int argc, FAR char **argv) index++; break; - case 'i': - g_qeexample.use_qeindex = true; - index++; - break; - case 'h': qe_help(); exit(EXIT_SUCCESS); @@ -238,7 +229,6 @@ int main(int argc, FAR char *argv[]) int exitval = EXIT_SUCCESS; int ret; int nloops; - struct qe_index_s index; /* Set the default values */ @@ -305,49 +295,19 @@ int main(int argc, FAR char *argv[]) /* Get the positions data using the ioctl */ - if (g_qeexample.use_qeindex) + ret = ioctl(fd, QEIOC_POSITION, (unsigned long)((uintptr_t)&position)); + if (ret < 0) { - ret = ioctl(fd, QEIOC_GETINDEX, - (unsigned long)((uintptr_t)&index)); - if (ret < 0) - { - printf("qe_main: ioctl(QEIOC_GETINDEX) failed: %d\n", - errno); - printf("Your MCU probably does not support this ioctl " - "call.\n"); - printf("Consider using this example without the -i option.\n"); - exitval = EXIT_FAILURE; - goto errout_with_dev; - } - - /* GETINDEX successful */ - - else - { - printf("qe_main: %3d. pos: %" PRIi32 ", " - "last index: %" PRIi32 ", " - "hit indexes: %" PRIi16 "\n", - nloops + 1, index.qenc_pos, index.indx_pos, - index.indx_cnt); - } + printf("qe_main: ioctl(QEIOC_POSITION) failed: %d\n", errno); + exitval = EXIT_FAILURE; + goto errout_with_dev; } + + /* Print the sample data on successful return */ + else { - ret = ioctl(fd, QEIOC_POSITION, - (unsigned long)((uintptr_t)&position)); - if (ret < 0) - { - printf("qe_main: ioctl(QEIOC_POSITION) failed: %d\n", errno); - exitval = EXIT_FAILURE; - goto errout_with_dev; - } - - /* Print the sample data on successful return */ - - else - { - printf("qe_main: %3d. %" PRIi32 "\n", nloops + 1, position); - } + printf("qe_main: %3d. %" PRIi32 "\n", nloops + 1, position); } /* Delay a little bit */ diff --git a/examples/random/CMakeLists.txt b/examples/random/CMakeLists.txt deleted file mode 100644 index e3385d489..000000000 --- a/examples/random/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# ############################################################################## -# apps/examples/random/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_RANDOM) - nuttx_add_application( - NAME - rand - STACKSIZE - ${CONFIG_DEFAULT_TASK_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_RANDOM} - SRCS - random_main.c) -endif() diff --git a/examples/random/Make.defs b/examples/random/Make.defs index 6771c5b65..e761c29ce 100644 --- a/examples/random/Make.defs +++ b/examples/random/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/random/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/random/Makefile b/examples/random/Makefile index ab02a154b..b064f1fdf 100644 --- a/examples/random/Makefile +++ b/examples/random/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/random/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/random/random_main.c b/examples/random/random_main.c index 3a35b4e89..d75cb6fa7 100644 --- a/examples/random/random_main.c +++ b/examples/random/random_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/random/random_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -31,13 +29,11 @@ #include <string.h> #include <fcntl.h> #include <errno.h> -#include <nuttx/debug.h> -#include <unistd.h> +#include <debug.h> /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ - /* Configuration ************************************************************/ #ifndef CONFIG_EXAMPLES_MAXSAMPLES @@ -91,9 +87,7 @@ int main(int argc, FAR char *argv[]) nsamples = CONFIG_EXAMPLES_MAXSAMPLES; } - /* fill buffer to make it super-clear as to what has and has not been - * written - */ + /* fill buffer to make it super-clear as to what has and has not been written */ memset(buffer, 0xcc, sizeof(buffer)); @@ -122,15 +116,15 @@ int main(int argc, FAR char *argv[]) if (nread != nsamples * sizeof(uint32_t)) { - fprintf(stderr, "ERROR: Read from /dev/random only produced %zd " - "bytes\n", nread); + fprintf(stderr, "ERROR: Read from /dev/random only produced %d bytes\n", + (int)nread); close(fd); exit(EXIT_FAILURE); } /* Dump the sample buffer */ - lib_dumpbuffer("Random values", (FAR const uint8_t *)buffer, nread); + lib_dumpbuffer("Random values", (FAR const uint8_t*)buffer, nread); close(fd); return EXIT_SUCCESS; } diff --git a/examples/relays/CMakeLists.txt b/examples/relays/CMakeLists.txt deleted file mode 100644 index cb1d9b729..000000000 --- a/examples/relays/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# ############################################################################## -# apps/examples/relays/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_RELAYS) - nuttx_add_application( - NAME - relays - STACKSIZE - ${CONFIG_DEFAULT_TASK_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_RELAYS} - SRCS - relays_main.c) -endif() diff --git a/examples/relays/Make.defs b/examples/relays/Make.defs index 3a1d05f3e..c762e8d7d 100644 --- a/examples/relays/Make.defs +++ b/examples/relays/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/relays/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/relays/Makefile b/examples/relays/Makefile index 4390ceb52..dffe7b4aa 100644 --- a/examples/relays/Makefile +++ b/examples/relays/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/relays/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -22,11 +20,11 @@ include $(APPDIR)/Make.defs -# Relays Example +# relays Example MAINSRC = relays_main.c -# Relays built-in application info +# Buttons built-in application info PROGNAME = relays PRIORITY = SCHED_PRIORITY_DEFAULT diff --git a/examples/relays/relays_main.c b/examples/relays/relays_main.c index 83e108419..33b62dcce 100644 --- a/examples/relays/relays_main.c +++ b/examples/relays/relays_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/relays/relays_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -34,7 +32,9 @@ #include <unistd.h> #include <string.h> #include <errno.h> -#include <nuttx/debug.h> +#include <debug.h> + +#include <nuttx/arch.h> #ifdef CONFIG_ARCH_RELAYS diff --git a/examples/rfid_readuid/CMakeLists.txt b/examples/rfid_readuid/CMakeLists.txt deleted file mode 100644 index d655272ed..000000000 --- a/examples/rfid_readuid/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# ############################################################################## -# apps/examples/rfid_readuid/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_RFID_READUID) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_RFID_READUID_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_RFID_READUID_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_RFID_READUID_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_RFID_READUID} - SRCS - rfid_readuid.c) -endif() diff --git a/examples/rfid_readuid/Kconfig b/examples/rfid_readuid/Kconfig index 1c08ba6cc..e117062b9 100644 --- a/examples/rfid_readuid/Kconfig +++ b/examples/rfid_readuid/Kconfig @@ -6,7 +6,6 @@ config EXAMPLES_RFID_READUID tristate "RFID Read UID example" default n - depends on CL_MFRC522 ---help--- Enable the RFID READUID example diff --git a/examples/rfid_readuid/Make.defs b/examples/rfid_readuid/Make.defs index ed720dbd5..3d61abc91 100644 --- a/examples/rfid_readuid/Make.defs +++ b/examples/rfid_readuid/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/rfid_readuid/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/rfid_readuid/Makefile b/examples/rfid_readuid/Makefile index 0a06297c5..dd13c901e 100644 --- a/examples/rfid_readuid/Makefile +++ b/examples/rfid_readuid/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/rfid_readuid/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/rfid_readuid/rfid_readuid.c b/examples/rfid_readuid/rfid_readuid.c index 0f1521d3e..2f8049ca7 100644 --- a/examples/rfid_readuid/rfid_readuid.c +++ b/examples/rfid_readuid/rfid_readuid.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/rfid_readuid/rfid_readuid.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -37,10 +35,15 @@ * Pre-processor Definitions ****************************************************************************/ +#ifndef CONFIG_CL_MFRC522 +# error "CONFIG_CL_MFRC522 is not defined in the configuration" +#endif + #ifndef CONFIG_EXAMPLES_RFID_READUID_DEVNAME # define CONFIG_EXAMPLES_RFID_READUID_DEVNAME "/dev/rfid0" #endif + /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/examples/rgbled/CMakeLists.txt b/examples/rgbled/CMakeLists.txt deleted file mode 100644 index edb6b62f2..000000000 --- a/examples/rgbled/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# ############################################################################## -# apps/examples/rgbled/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_RGBLED) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_RGBLED_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_RGBLED_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_RGBLED_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_RGBLED} - SRCS - rgbled.c) -endif() diff --git a/examples/rgbled/Make.defs b/examples/rgbled/Make.defs index e8c793757..bea3eee00 100644 --- a/examples/rgbled/Make.defs +++ b/examples/rgbled/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/rgbled/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/rgbled/Makefile b/examples/rgbled/Makefile index 9f0511c6a..3611b032e 100644 --- a/examples/rgbled/Makefile +++ b/examples/rgbled/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/rgbled/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/rgbled/rgbled.c b/examples/rgbled/rgbled.c index 4dd9aa2ec..c1d5ab5df 100644 --- a/examples/rgbled/rgbled.c +++ b/examples/rgbled/rgbled.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/rgbled/rgbled.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -25,12 +23,10 @@ ****************************************************************************/ #include <nuttx/config.h> - #include <stdio.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> -#include <unistd.h> /**************************************************************************** * Pre-processor Definitions @@ -67,37 +63,37 @@ int main(int argc, FAR char *argv[]) return -1; } - while (1) - { - red += sred; - green += sgreen; - blue += sblue; + while(1) + { + red += sred; + green += sgreen; + blue += sblue; - if (green == 255) - { - sred = 0; - sgreen = -1; - sblue = 1; - } + if (green == 255) + { + sred = 0; + sgreen = -1; + sblue = 1; + } - if (blue == 255) - { - sred = 1; - sgreen = 0; - sblue = -1; - } + if (blue == 255) + { + sred = 1; + sgreen = 0; + sblue = -1; + } - if (red == 255) - { - sred = -1; - sblue = 0; - sgreen = 1; - } + if (red == 255) + { + sred = -1; + sblue = 0; + sgreen = 1; + } - snprintf(buffer, sizeof(buffer), "#%02X%02X%02X", red, green, blue); - write(fd, buffer, 8); - usleep(5000); - } + sprintf(buffer, "#%02X%02X%02X", red, green, blue); + write(fd, buffer, 8); + usleep(5000); + } return 0; } diff --git a/examples/rng90/CMakeLists.txt b/examples/rng90/CMakeLists.txt deleted file mode 100644 index 65cda8f30..000000000 --- a/examples/rng90/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# ############################################################################## -# apps/examples/rng90/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_RNG90) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_RNG90_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_RNG90_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_RNG90_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_RNG90} - SRCS - rng90_main.c) -endif() diff --git a/examples/rng90/Kconfig b/examples/rng90/Kconfig deleted file mode 100644 index 86f1c0660..000000000 --- a/examples/rng90/Kconfig +++ /dev/null @@ -1,37 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config EXAMPLES_RNG90 - tristate "Microchip RNG90 TRNG example" - default n - depends on DEV_RNG90 - ---help--- - Enable the RNG90 example. It opens the RNG90 character device, - runs the built-in self-test and reads random bytes from it. - -if EXAMPLES_RNG90 - -config EXAMPLES_RNG90_PROGNAME - string "Program name" - default "rng90" - ---help--- - This is the name of the program that will be used when the NSH ELF - program is installed. - -config EXAMPLES_RNG90_DEVPATH - string "RNG90 device path" - default "/dev/rng0" - ---help--- - The default path of the RNG90 character device. - -config EXAMPLES_RNG90_PRIORITY - int "RNG90 task priority" - default 100 - -config EXAMPLES_RNG90_STACKSIZE - int "RNG90 stack size" - default DEFAULT_TASK_STACKSIZE - -endif diff --git a/examples/rng90/Make.defs b/examples/rng90/Make.defs deleted file mode 100644 index b2b20b4ba..000000000 --- a/examples/rng90/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/examples/rng90/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_EXAMPLES_RNG90),) -CONFIGURED_APPS += $(APPDIR)/examples/rng90 -endif diff --git a/examples/rng90/Makefile b/examples/rng90/Makefile deleted file mode 100644 index 6905cb569..000000000 --- a/examples/rng90/Makefile +++ /dev/null @@ -1,36 +0,0 @@ -############################################################################ -# apps/examples/rng90/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -# Microchip RNG90 TRNG example built-in application info - -PROGNAME = $(CONFIG_EXAMPLES_RNG90_PROGNAME) -PRIORITY = $(CONFIG_EXAMPLES_RNG90_PRIORITY) -STACKSIZE = $(CONFIG_EXAMPLES_RNG90_STACKSIZE) -MODULE = $(CONFIG_EXAMPLES_RNG90) - -# Microchip RNG90 TRNG example - -MAINSRC = rng90_main.c - -include $(APPDIR)/Application.mk diff --git a/examples/rng90/rng90_main.c b/examples/rng90/rng90_main.c deleted file mode 100644 index 3ef3ec899..000000000 --- a/examples/rng90/rng90_main.c +++ /dev/null @@ -1,162 +0,0 @@ -/**************************************************************************** - * apps/examples/rng90/rng90_main.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <stdio.h> -#include <stdlib.h> -#include <stdint.h> -#include <fcntl.h> -#include <unistd.h> -#include <errno.h> - -#include <nuttx/crypto/rng90.h> - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#ifndef CONFIG_EXAMPLES_RNG90_DEVPATH -# define CONFIG_EXAMPLES_RNG90_DEVPATH "/dev/rng0" -#endif - -#define RNG90_MAX_BYTES 32 - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: print_hex - * - * Description: - * Dump a buffer as a hex string, 16 bytes per line. - * - ****************************************************************************/ - -static void print_hex(FAR const uint8_t *buf, size_t len) -{ - size_t i; - - for (i = 0; i < len; i++) - { - printf("%02x", buf[i]); - if ((i & 0x0f) == 0x0f) - { - printf("\n"); - } - else - { - printf(" "); - } - } - - if ((len & 0x0f) != 0) - { - printf("\n"); - } -} - -/**************************************************************************** - * Name: usage - ****************************************************************************/ - -static void usage(FAR const char *progname) -{ - printf("Usage: %s [<devpath>] [<count>]\n", progname); - printf(" <devpath> RNG90 device (default %s)\n", - CONFIG_EXAMPLES_RNG90_DEVPATH); - printf(" <count> number of random bytes to read, 1..%d (default %d)\n", - RNG90_MAX_BYTES, RNG90_MAX_BYTES); -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * rng90_main - ****************************************************************************/ - -int main(int argc, FAR char *argv[]) -{ - FAR const char *devpath = CONFIG_EXAMPLES_RNG90_DEVPATH; - int count = RNG90_MAX_BYTES; - uint8_t buf[RNG90_MAX_BYTES]; - int fd; - int ret; - - /* Parse the optional command line arguments */ - - if (argc > 1) - { - if (argv[1][0] == '-') - { - usage(argv[0]); - return EXIT_FAILURE; - } - - devpath = argv[1]; - } - - if (argc > 2) - { - count = atoi(argv[2]); - if (count < 1 || count > RNG90_MAX_BYTES) - { - printf("Invalid count %d, clamping to %d\n", count, - RNG90_MAX_BYTES); - count = RNG90_MAX_BYTES; - } - } - - /* Opening the device wakes the RNG90 up; closing puts it to sleep. */ - - fd = open(devpath, O_RDONLY); - if (fd < 0) - { - printf("ERROR: Failed to open %s: %d\n", devpath, errno); - return EXIT_FAILURE; - } - - printf("RNG90 example: device %s\n", devpath); - - /* Read random bytes from the device */ - - ret = read(fd, buf, (size_t)count); - if (ret < 0) - { - printf("ERROR: read failed: %d\n", errno); - close(fd); - return EXIT_FAILURE; - } - - printf("Read %d random byte(s):\n", ret); - print_hex(buf, (size_t)ret); - - close(fd); - return EXIT_SUCCESS; -} diff --git a/examples/romfs/CMakeLists.txt b/examples/romfs/CMakeLists.txt deleted file mode 100644 index 7bde993d9..000000000 --- a/examples/romfs/CMakeLists.txt +++ /dev/null @@ -1,58 +0,0 @@ -# ############################################################################## -# apps/examples/romfs/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_ROMFS) - - add_custom_target( - testdir - COMMAND ${CMAKE_COMMAND} -E tar zxf ${CMAKE_CURRENT_LIST_DIR}/testdir.tar.gz - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - DEPENDS ${CMAKE_CURRENT_LIST_DIR}/testdir.tar.gz - COMMENT "EXAMPLES ROMFS Extracting testdir.tar.gz...") - - add_custom_target( - testdir_img - COMMAND genromfs -f testdir.img -d testdir -V "ROMFS_Test" - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - DEPENDS testdir - COMMENT "EXAMPLES ROMFS Generating testdir.img...") - - add_custom_target( - romfs_testdir_h - COMMAND xxd -i testdir.img > romfs_testdir.h - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - DEPENDS testdir_img - COMMENT "EXAMPLES ROMFS Generating romfs_testdir.h...") - - nuttx_add_application( - NAME - romfs - MODULE - ${CONFIG_EXAMPLES_ROMFS} - SRCS - romfs_main.c - INCLUDE_DIRECTORIES - ${CMAKE_CURRENT_BINARY_DIR} - DEPENDS - romfs_testdir_h) - -endif() diff --git a/examples/romfs/Kconfig b/examples/romfs/Kconfig index 260d4d453..e4a2308a4 100644 --- a/examples/romfs/Kconfig +++ b/examples/romfs/Kconfig @@ -6,16 +6,9 @@ config EXAMPLES_ROMFS tristate "ROMFS example" default n - depends on FS_ROMFS && BUILD_FLAT && BOARDCTL_ROMDISK + depends on FS_ROMFS && BUILD_FLAT ---help--- Enable the ROMFS example if EXAMPLES_ROMFS - -config EXAMPLES_ROMFS_RAMDEVNO - int "ROMFS example ramdevno" - default 10 - ---help--- - Custom RAMDisk number - endif diff --git a/examples/romfs/Make.defs b/examples/romfs/Make.defs index 9f06ff292..8755a91f3 100644 --- a/examples/romfs/Make.defs +++ b/examples/romfs/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/romfs/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/romfs/Makefile b/examples/romfs/Makefile index ba19d2372..99c00bc4c 100644 --- a/examples/romfs/Makefile +++ b/examples/romfs/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/romfs/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/romfs/romfs_main.c b/examples/romfs/romfs_main.c index 7a7395503..2f55f82c0 100644 --- a/examples/romfs/romfs_main.c +++ b/examples/romfs/romfs_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/romfs/romfs_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -391,15 +389,8 @@ static void readdirectories(const char *path, struct node_s *entry) /* Get the full path to the entry */ - snprintf(g_scratchbuffer, sizeof(g_scratchbuffer), - "%s/%s", path, direntry->d_name); + sprintf(g_scratchbuffer, "%s/%s", path, direntry->d_name); fullpath = strdup(g_scratchbuffer); - if (fullpath == NULL) - { - printf(" ERROR: Out of memory\n"); - g_nerrors++; - continue; - } if (DIRENT_ISDIRECTORY(direntry->d_type)) { diff --git a/examples/rpmsgsocket/CMakeLists.txt b/examples/rpmsgsocket/CMakeLists.txt deleted file mode 100644 index edb2dddc7..000000000 --- a/examples/rpmsgsocket/CMakeLists.txt +++ /dev/null @@ -1,42 +0,0 @@ -################################################################################ -# apps/examples/rpmsgsocket/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -################################################################################ - -if(CONFIG_EXAMPLES_RPMSGSOCKET) - nuttx_add_application( - NAME - rpsock_client - STACKSIZE - ${CONFIG_DEFAULT_TASK_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_RPMSGSOCKET} - SRCS - rpsock_client.c) - nuttx_add_application( - NAME - rpsock_server - STACKSIZE - ${CONFIG_DEFAULT_TASK_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_RPMSGSOCKET} - SRCS - rpsock_server.c) -endif() diff --git a/examples/rpmsgsocket/Kconfig b/examples/rpmsgsocket/Kconfig index 95c748a26..7be2c7caa 100644 --- a/examples/rpmsgsocket/Kconfig +++ b/examples/rpmsgsocket/Kconfig @@ -4,7 +4,7 @@ # config EXAMPLES_RPMSGSOCKET - tristate "Rpmsg socket example" + tristate "Rpmsg scoekt example" depends on NET_RPMSG default n ---help--- diff --git a/examples/rpmsgsocket/Make.defs b/examples/rpmsgsocket/Make.defs index e7ac29328..924623950 100644 --- a/examples/rpmsgsocket/Make.defs +++ b/examples/rpmsgsocket/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/rpmsgsocket/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/rpmsgsocket/Makefile b/examples/rpmsgsocket/Makefile index dffe32a44..acfc183be 100644 --- a/examples/rpmsgsocket/Makefile +++ b/examples/rpmsgsocket/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/rpmsgsocket/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/rpmsgsocket/rpsock_client.c b/examples/rpmsgsocket/rpsock_client.c index 80813404e..092283a2f 100644 --- a/examples/rpmsgsocket/rpsock_client.c +++ b/examples/rpmsgsocket/rpsock_client.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/rpmsgsocket/rpsock_client.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -26,28 +24,25 @@ #include <nuttx/config.h> -#include <errno.h> -#include <inttypes.h> +#include <sys/socket.h> #include <netpacket/rpmsg.h> -#include <poll.h> -#include <pthread.h> -#include <stdbool.h> + +#include <assert.h> #include <stdio.h> #include <stdlib.h> -#include <string.h> #include <unistd.h> -#include <sys/socket.h> +#include <string.h> +#include <poll.h> +#include <errno.h> /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ -#define SYNCSIZE CONFIG_NET_RPMSG_RXBUF_SIZE -#define BUFSIZE SYNCSIZE * 2 -#define BUFHEAD 64 -#ifndef ALIGN_UP -# define ALIGN_UP(num, align) (((num) + ((align) - 1)) & ~((align) - 1)) -#endif +#define ALIGN_UP(a) (((a) + 0x3) & ~0x3) +#define SYNCSIZE CONFIG_NET_RPMSG_RXBUF_SIZE +#define BUFSIZE SYNCSIZE * 2 +#define BUFHEAD 64 /**************************************************************************** * Private types @@ -55,23 +50,23 @@ struct rpsock_arg_s { - FAR char *inbuf; - FAR char *outbuf; + int fd; + char *inbuf; + char *outbuf; bool nonblock; int bufsize; int check; - int fd; }; /**************************************************************************** * Public Functions ****************************************************************************/ -static FAR void *rpsock_send_thread(FAR void *pvarg) +static void *rpsock_send_thread(pthread_addr_t pvarg) { - FAR struct rpsock_arg_s *args = pvarg; - FAR char *buf = args->outbuf; + struct rpsock_arg_s *args = pvarg; int bufsize = args->bufsize; + char *buf = args->outbuf; int fd = args->fd; int total = 0; ssize_t ret; @@ -79,13 +74,13 @@ static FAR void *rpsock_send_thread(FAR void *pvarg) while (cnt < 2000) { - FAR volatile uint32_t *intp; + volatile uint32_t *intp; struct pollfd pfd; - FAR char *tmp; + char *tmp; int snd; int i; - intp = (FAR uint32_t *)buf; + intp = (uint32_t *)buf; for (i = 0; i < bufsize / sizeof(uint32_t); i++) { intp[i] = cnt * bufsize / sizeof(uint32_t) + i; @@ -144,7 +139,7 @@ static FAR void *rpsock_send_thread(FAR void *pvarg) return NULL; } -static int rpsock_unsync_test(FAR struct rpsock_arg_s *args) +static int rpsock_unsync_test(struct rpsock_arg_s *args) { pthread_attr_t attr; pthread_t thread; @@ -154,7 +149,8 @@ static int rpsock_unsync_test(FAR struct rpsock_arg_s *args) pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 10 * 1024); - ret = pthread_create(&thread, &attr, rpsock_send_thread, args); + ret = pthread_create(&thread, &attr, rpsock_send_thread, + (pthread_addr_t)args); if (ret < 0) { return ret; @@ -183,7 +179,7 @@ static int rpsock_unsync_test(FAR struct rpsock_arg_s *args) ret = recv(args->fd, args->inbuf, args->bufsize, 0); if (ret > 0) { - FAR uint32_t *intp; + uint32_t *intp; int checks; int i; @@ -197,18 +193,17 @@ static int rpsock_unsync_test(FAR struct rpsock_arg_s *args) if (args->check && ret > 4) { - checks = ret - (ALIGN_UP(total, 4) - total); - intp = (FAR uint32_t *)(args->inbuf + - (ALIGN_UP(total, 4) - total)); + intp = (uint32_t *)(args->inbuf + (ALIGN_UP(total) - total)); + checks = ret - (ALIGN_UP(total) - total); for (i = 0; i < checks / sizeof(uint32_t); i++) { - if (intp[i] != ALIGN_UP(total, 4) / sizeof(uint32_t) + i) + if (intp[i] != ALIGN_UP(total) / sizeof(uint32_t) + i) { printf("client check fail total %d, \ - i %d, %08" PRIx32 ", %08zx\n", - ALIGN_UP(total, 4), i, intp[i], - ALIGN_UP(total, 4) / sizeof(uint32_t) + i); + i %d, %08x, %08x\n", + ALIGN_UP(total), i, intp[i], + ALIGN_UP(total) / sizeof(uint32_t) + i); } } } @@ -230,14 +225,14 @@ static int rpsock_unsync_test(FAR struct rpsock_arg_s *args) return 0; } -static int rpsock_stream_client(FAR char *argv[]) +static int rpsock_stream_client(int argc, char *argv[]) { struct sockaddr_rpmsg myaddr; struct rpsock_arg_s args; bool nonblock = false; int cnt = 0; - FAR char *outbuf; - FAR char *inbuf; + char *outbuf; + char *inbuf; int sockfd; int ret; @@ -279,11 +274,11 @@ static int rpsock_stream_client(FAR char *argv[]) /* Connect the socket to the server */ myaddr.rp_family = AF_RPMSG; - strlcpy(myaddr.rp_name, argv[3], RPMSG_SOCKET_NAME_SIZE); - strlcpy(myaddr.rp_cpu, argv[4], RPMSG_SOCKET_CPU_SIZE); + strncpy(myaddr.rp_name, argv[3], RPMSG_SOCKET_NAME_SIZE); + strncpy(myaddr.rp_cpu, argv[4], RPMSG_SOCKET_CPU_SIZE); printf("client: Connecting to %s,%s...\n", myaddr.rp_cpu, myaddr.rp_name); - ret = connect(sockfd, (FAR struct sockaddr *)&myaddr, sizeof(myaddr)); + ret = connect(sockfd, (struct sockaddr *)&myaddr, sizeof(myaddr)); if (ret < 0 && errno == EINPROGRESS) { struct pollfd pfd; @@ -311,9 +306,9 @@ static int rpsock_stream_client(FAR char *argv[]) size_t sendsize = BUFHEAD + cnt * (random() % 64); size_t recvsize = 0; ssize_t act; - FAR char *tmp; - FAR int *ptr; + char *tmp; int snd; + int *ptr; int i; if (sendsize > SYNCSIZE) @@ -324,13 +319,13 @@ static int rpsock_stream_client(FAR char *argv[]) snprintf(outbuf, BUFHEAD, "process%04d, msg%04d, name:%s", getpid(), cnt, argv[3]); - ptr = (FAR int *)(outbuf + BUFHEAD); + ptr = (int *)(outbuf + BUFHEAD); for (i = 0; i < (sendsize - BUFHEAD) / 4; i++) { ptr[i] = cnt * 100 + i; } - printf("client send data, cnt %d, total len %zu, BUFHEAD %s\n", + printf("client send data, cnt %d, total len %d, BUFHEAD %s\n", cnt, sendsize, outbuf); tmp = outbuf; @@ -373,7 +368,7 @@ static int rpsock_stream_client(FAR char *argv[]) } else if (act < 0) { - printf("client recv data failed %zd\n", act); + printf("client recv data failed %d\n", act); break; } @@ -387,13 +382,13 @@ static int rpsock_stream_client(FAR char *argv[]) if (recvsize >= sendsize) { - printf("client recv total %zu, send total %zu\n", - recvsize, sendsize); + printf("client recv total %d, send total %d\n", + recvsize, sendsize); break; } } - ptr = (FAR int *)(inbuf + BUFHEAD); + ptr = (int *)(inbuf + BUFHEAD); for (i = 0; i < (recvsize - BUFHEAD) / 4; i++) { if (ptr[i] != cnt * 100 + i) @@ -425,146 +420,13 @@ errout_with_buffers: return -errno; } -static int rpsock_stream_conn_multi_times_client(FAR char *argv[], int argc) -{ - struct sockaddr_rpmsg myaddr; - struct pollfd pfd; - size_t sendsize = BUFHEAD; - ssize_t act; - bool delayflag = false; - bool nonblock = false; - FAR char *outbuf; - FAR char *inbuf; - FAR char *tmp; - int sockfd; - int ret; - - /* Allocate buffers */ - - inbuf = malloc(2 * BUFSIZE); - outbuf = inbuf + BUFSIZE; - if (inbuf == NULL) - { - printf("client: failed to allocate buffers\n"); - ret = -ENOMEM; - goto errout_with_buffers; - } - - /* Create a new rpmsg domain socket */ - - if (strcmp(argv[2], "nonblock") == 0) - { - nonblock = true; - } - - if (argc >= 7 && strcmp(argv[6], "delay") == 0) - { - delayflag = true; - } - - printf("client: create socket SOCK_STREAM nonblock %d\n", nonblock); - - if (nonblock) - { - sockfd = socket(PF_RPMSG, SOCK_STREAM | SOCK_NONBLOCK, 0); - } - else - { - sockfd = socket(PF_RPMSG, SOCK_STREAM, 0); - } - - if (sockfd < 0) - { - printf("client socket failure %d\n", errno); - goto errout_with_buffers; - } - - /* Connect the socket to the server */ - - myaddr.rp_family = AF_RPMSG; - strlcpy(myaddr.rp_name, argv[3], RPMSG_SOCKET_NAME_SIZE); - strlcpy(myaddr.rp_cpu, argv[4], RPMSG_SOCKET_CPU_SIZE); - - printf("client: Connecting to %s,%s...\n", myaddr.rp_cpu, myaddr.rp_name); - ret = connect(sockfd, (FAR struct sockaddr *)&myaddr, sizeof(myaddr)); - if (ret < 0 && errno == EINPROGRESS) - { - memset(&pfd, 0, sizeof(struct pollfd)); - pfd.fd = sockfd; - pfd.events = POLLOUT; - - ret = poll(&pfd, 1, -1); - if (ret < 0) - { - printf("client: poll failure: %d\n", errno); - goto errout_with_socket; - } - } - else if (ret < 0) - { - printf("client: connect failure: %d\n", errno); - goto errout_with_socket; - } - - printf("client: Connected\n"); - - snprintf(outbuf, BUFHEAD, "process%04d, name:%s", getpid(), argv[3]); - - printf("client send data, total len %zu, BUFHEAD %s\n", sendsize, outbuf); - - tmp = outbuf; - - ret = send(sockfd, tmp, sendsize, 0); - if (ret < 0) - { - printf("client: send failure: %d\n", errno); - goto errout_with_socket; - } - - tmp = inbuf; - if (nonblock) - { - memset(&pfd, 0, sizeof(struct pollfd)); - pfd.fd = sockfd; - pfd.events = POLLIN; - - ret = poll(&pfd, 1, -1); - if (ret < 0) - { - printf("client: poll failure: %d\n", errno); - goto errout_with_socket; - } - } - - act = recv(sockfd, tmp, SYNCSIZE, 0); - if (act < 0) - { - printf("client recv data failed %zd\n", act); - goto errout_with_socket; - } - - printf("client: Terminating\n"); - - if (delayflag) - { - sleep(1); - } - -errout_with_socket: - close(sockfd); - -errout_with_buffers: - free(inbuf); - return -errno; -} - -static int rpsock_dgram_client(char *argv[]) +static int rpsock_dgram_client(int argc, char *argv[]) { struct sockaddr_rpmsg myaddr; struct rpsock_arg_s args; bool nonblock = false; - FAR char *outbuf; - FAR char *inbuf; + char *outbuf; + char *inbuf; int sockfd; int ret; @@ -606,11 +468,11 @@ static int rpsock_dgram_client(char *argv[]) /* Connect the socket to the server */ myaddr.rp_family = AF_RPMSG; - strlcpy(myaddr.rp_name, argv[3], RPMSG_SOCKET_NAME_SIZE); - strlcpy(myaddr.rp_cpu, argv[4], RPMSG_SOCKET_CPU_SIZE); + strncpy(myaddr.rp_name, argv[3], RPMSG_SOCKET_NAME_SIZE); + strncpy(myaddr.rp_cpu, argv[4], RPMSG_SOCKET_CPU_SIZE); printf("client: Connecting to %s,%s...\n", myaddr.rp_cpu, myaddr.rp_name); - ret = connect(sockfd, (FAR struct sockaddr *)&myaddr, sizeof(myaddr)); + ret = connect(sockfd, (struct sockaddr *)&myaddr, sizeof(myaddr)); if (ret < 0 && errno == EINPROGRESS) { struct pollfd pfd; @@ -653,58 +515,22 @@ errout_with_buffers: return -errno; } -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: rpsock_client_main - * - * Description: - * Main entry point for the rpsock_client example. - * - ****************************************************************************/ - -int main(int argc, FAR char *argv[]) +int main(int argc, char *argv[]) { - int times = 0; - int ret = 0; - int num = 0; - if (argc < 4) { - printf("Usage: rpsock_client stream/dgram/conn_multi_times/delay" - " block/nonblock rp_name rp_cpu times\n"); + printf("Usage: rpsock_client stream/dgram" + " block/nonblock rp_name rp_cpu\n"); return -EINVAL; } if (!strcmp(argv[1], "stream")) { - return rpsock_stream_client(argv); + return rpsock_stream_client(argc, argv); } else if (!strcmp(argv[1], "dgram")) { - return rpsock_dgram_client(argv); - } - else if (!strcmp(argv[1], "conn_multi_times")) - { - if (argc < 6 || atoi(argv[5]) <= 0) - { - printf("Usage: rpsock_client conn_multi_times" - " block/nonblock rp_name rp_cpu times (delay)\n"); - return -EINVAL; - } - - for (times = atoi(argv[5]); times > 0; times--) - { - printf("client conn_multi_times: %d\n", num++); - ret = rpsock_stream_conn_multi_times_client(argv, argc); - if (ret < 0 && ret != -EINPROGRESS) - { - printf("client socket failure %d\n", ret); - return ret; - } - } + return rpsock_dgram_client(argc, argv); } return -EINVAL; diff --git a/examples/rpmsgsocket/rpsock_server.c b/examples/rpmsgsocket/rpsock_server.c index 338818630..c4f3a6876 100644 --- a/examples/rpmsgsocket/rpsock_server.c +++ b/examples/rpmsgsocket/rpsock_server.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/rpmsgsocket/rpsock_server.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -26,18 +24,16 @@ #include <nuttx/config.h> -#include <assert.h> -#include <errno.h> +#include <sys/socket.h> #include <netpacket/rpmsg.h> -#include <pthread.h> -#include <poll.h> -#include <stdbool.h> + #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> -#include <sys/socket.h> -#include <sys/types.h> +#include <poll.h> +#include <assert.h> +#include <errno.h> /**************************************************************************** * Private types @@ -50,19 +46,19 @@ struct rpsock_arg_s }; /**************************************************************************** - * Private Functions + * Public Functions ****************************************************************************/ -static FAR void *rpsock_thread(FAR void *pvarg) +static void *rpsock_thread(pthread_addr_t pvarg) { - FAR struct rpsock_arg_s *args = pvarg; + struct rpsock_arg_s *args = pvarg; struct pollfd pfd; char buf[255]; ssize_t ret; while (1) { - FAR char *tmp; + char *tmp; int snd; if (args->nonblock) @@ -106,7 +102,7 @@ static FAR void *rpsock_thread(FAR void *pvarg) } else if (ret < 0) { - printf("server recv data failed ret %zd, errno %d\n", ret, errno); + printf("server recv data failed ret %d, errno %d\n", ret, errno); break; } @@ -151,12 +147,12 @@ static FAR void *rpsock_thread(FAR void *pvarg) } } - printf("server Complete ret %zd, errno %d\n", ret, errno); + printf("server Complete ret %d, errno %d\n", ret, errno); free(args); return NULL; } -static int rpsock_stream_server(int argc, FAR char *argv[]) +static int rpsock_stream_server(int argc, char *argv[]) { struct sockaddr_rpmsg myaddr; bool nonblock = false; @@ -191,10 +187,10 @@ static int rpsock_stream_server(int argc, FAR char *argv[]) /* Bind the socket to a local address */ myaddr.rp_family = AF_RPMSG; - strlcpy(myaddr.rp_name, argv[3], RPMSG_SOCKET_NAME_SIZE); + strncpy(myaddr.rp_name, argv[3], RPMSG_SOCKET_NAME_SIZE); if (argc == 5) { - strlcpy(myaddr.rp_cpu, argv[4], RPMSG_SOCKET_CPU_SIZE); + strncpy(myaddr.rp_cpu, argv[4], RPMSG_SOCKET_CPU_SIZE); } else { @@ -203,7 +199,7 @@ static int rpsock_stream_server(int argc, FAR char *argv[]) printf("server: bind cpu %s, name %s ...\n", myaddr.rp_cpu, myaddr.rp_name); - ret = bind(listensd, (FAR struct sockaddr *)&myaddr, sizeof(myaddr)); + ret = bind(listensd, (struct sockaddr *)&myaddr, sizeof(myaddr)); if (ret < 0) { printf("server: bind failure: %d\n", errno); @@ -222,7 +218,7 @@ static int rpsock_stream_server(int argc, FAR char *argv[]) while (1) { - FAR struct rpsock_arg_s *args; + struct rpsock_arg_s *args; pthread_t thread; struct pollfd pfd; int new; @@ -242,8 +238,7 @@ static int rpsock_stream_server(int argc, FAR char *argv[]) } printf("server: try accept ...\n"); - new = accept4(listensd, (FAR struct sockaddr *)&myaddr, &addrlen, - SOCK_CLOEXEC); + new = accept(listensd, (struct sockaddr *)&myaddr, &addrlen); if (new < 0) break; @@ -255,7 +250,8 @@ static int rpsock_stream_server(int argc, FAR char *argv[]) args->fd = new; args->nonblock = nonblock; - pthread_create(&thread, NULL, rpsock_thread, args); + pthread_create(&thread, NULL, rpsock_thread, + (pthread_addr_t)args); pthread_detach(thread); } @@ -269,195 +265,10 @@ errout_with_listensd: return -errno; } -static int rpsock_recv_send_single(FAR struct rpsock_arg_s *args) -{ - struct pollfd pfd; - ssize_t ret; - char buf[255]; - FAR char *tmp; - int snd; - - if (args->nonblock) - { - memset(&pfd, 0, sizeof(struct pollfd)); - pfd.fd = args->fd; - pfd.events = POLLIN; - - ret = poll(&pfd, 1, -1); - if (ret < 0) - { - printf("server poll failed errno %d\n", errno); - goto end; - } - } - - ret = recv(args->fd, buf, sizeof(buf), 0); - if (ret == 0 || (ret < 0 && errno == ECONNRESET)) - { - printf("server recv data normal exit\n"); - goto end; - } - else if (ret < 0 && errno == EINPROGRESS) - { - memset(&pfd, 0, sizeof(struct pollfd)); - pfd.fd = args->fd; - pfd.events = POLLOUT; - ret = poll(&pfd, 1, -1); - if (ret < 0) - { - printf("server: poll failure: %d\n", errno); - goto end; - } - } - else if(ret < 0) - { - printf("server recv data failed ret %zd, errno %d\n", ret, errno); - goto end; - } - - snd = ret; - tmp = buf; - - if (args->nonblock) - { - memset(&pfd, 0, sizeof(struct pollfd)); - pfd.fd = args->fd; - pfd.events = POLLOUT; - - ret = poll(&pfd, 1, -1); - if (ret < 0) - { - printf("server: poll failure: %d\n", errno); - goto end; - } - } - - ret = send(args->fd, tmp, snd, 0); - if (ret == 0) - { - printf("server send data normal exit\n"); - } - else if (ret < 0) - { - printf("server send data failed errno %d\n", errno); - } - -end: - printf("server Complete ret %zd, errno %d\n", ret, errno); - free(args); - return -errno; -} - -static int rpsock_stream_multi_times_server(FAR char *argv[]) +static int rpsock_dgram_server(int argc, char *argv[]) { struct sockaddr_rpmsg myaddr; - FAR struct rpsock_arg_s *args; - struct pollfd pfd; - socklen_t addrlen; - bool nonblock = false; - int fd; - int newfd; - int ret; - - /* Create a new rpmsg domain socket */ - - if (strcmp(argv[2], "nonblock") == 0) - { - nonblock = true; - } - - printf("server: create socket SOCK_STREAM nonblock %d\n", nonblock); - - if (nonblock) - { - fd = socket(PF_RPMSG, SOCK_STREAM | SOCK_NONBLOCK, 0); - } - else - { - fd = socket(PF_RPMSG, SOCK_STREAM, 0); - } - - if (fd < 0) - { - printf("server: socket failure: %d\n", errno); - return -errno; - } - - /* Bind the socket to a local address */ - - myaddr.rp_family = AF_RPMSG; - strlcpy(myaddr.rp_name, argv[3], RPMSG_SOCKET_NAME_SIZE); - strlcpy(myaddr.rp_cpu, argv[4], RPMSG_SOCKET_CPU_SIZE); - - printf("server: bind cpu %s, name %s ...\n", - myaddr.rp_cpu, myaddr.rp_name); - ret = bind(fd, (struct sockaddr *)&myaddr, sizeof(myaddr)); - if (ret < 0) - { - printf("server: bind failure: %d\n", errno); - goto errout_with_listensd; - } - - /* Listen for connections on the bound socket */ - - printf("server: listen ...\n"); - ret = listen(fd, 16); - if (ret < 0) - { - printf("server: listen failure %d\n", errno); - goto errout_with_listensd; - } - - if (nonblock) - { - memset(&pfd, 0, sizeof(struct pollfd)); - pfd.fd = fd; - pfd.events = POLLIN; - - ret = poll(&pfd, 1, -1); - if (ret < 0) - { - printf("server: poll failure: %d\n", errno); - goto errout_with_listensd; - } - } - - printf("server: try accept ...\n"); - newfd = accept4(fd, (FAR struct sockaddr *)&myaddr, &addrlen, - SOCK_CLOEXEC); - if (newfd < 0) - { - printf("server: accept4 failure: %d\n", errno); - goto errout_with_listensd; - } - - printf("server: Connection accepted -- %d\n", newfd); - - args = malloc(sizeof(struct rpsock_arg_s)); - assert(args); - - args->fd = newfd; - args->nonblock = nonblock; - - ret = rpsock_recv_send_single(args); - if (ret < 0) - { - printf("rpsock_recv_send_single failed errno %d\n", errno); - } - - printf("server: Terminating\n"); - close(fd); - return 0; - -errout_with_listensd: - close(fd); - return -errno; -} - -static int rpsock_dgram_server(int argc, FAR char *argv[]) -{ - struct sockaddr_rpmsg myaddr; - FAR struct rpsock_arg_s *args; + struct rpsock_arg_s *args; bool nonblock = false; int fd; int ret; @@ -489,10 +300,10 @@ static int rpsock_dgram_server(int argc, FAR char *argv[]) /* Bind the socket to a local address */ myaddr.rp_family = AF_RPMSG; - strlcpy(myaddr.rp_name, argv[3], RPMSG_SOCKET_NAME_SIZE); + strncpy(myaddr.rp_name, argv[3], RPMSG_SOCKET_NAME_SIZE); if (argc == 5) { - strlcpy(myaddr.rp_cpu, argv[4], RPMSG_SOCKET_CPU_SIZE); + strncpy(myaddr.rp_cpu, argv[4], RPMSG_SOCKET_CPU_SIZE); } else { @@ -501,8 +312,8 @@ static int rpsock_dgram_server(int argc, FAR char *argv[]) printf("server: bind cpu %s, name %s ...\n", myaddr.rp_cpu, myaddr.rp_name); - ret = bind(fd, (FAR struct sockaddr *)&myaddr, sizeof(myaddr)); - ret = connect(fd, (FAR struct sockaddr *)&myaddr, sizeof(myaddr)); + ret = bind(fd, (struct sockaddr *)&myaddr, sizeof(myaddr)); + ret = connect(fd, (struct sockaddr *)&myaddr, sizeof(myaddr)); if (ret < 0 && errno == EINPROGRESS) { struct pollfd pfd; @@ -537,28 +348,12 @@ static int rpsock_dgram_server(int argc, FAR char *argv[]) return 0; } -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: rpsock_server_main - * - * Description: - * Main entry point for the rpsock_server example. - * - ****************************************************************************/ - -int main(int argc, FAR char *argv[]) +int main(int argc, char *argv[]) { - int times = 0; - int ret = 0; - int num = 0; - - if (argc < 4) + if (argc != 4 && argc != 5) { - printf("Usage: rpsock_server stream/dgram/server_multi_times" - " block/nonblock rp_name [rp_cpu] times\n"); + printf("Usage: rpsock_server stream/dgram" + " block/nonblock rp_name [rp_cpu]\n"); return -EINVAL; } @@ -570,26 +365,6 @@ int main(int argc, FAR char *argv[]) { return rpsock_dgram_server(argc, argv); } - else if (!strcmp(argv[1], "server_multi_times")) - { - if (argc < 6 || atoi(argv[5]) <= 0) - { - printf("Usage: rpsock_server server_multi_times" - " block/nonblock rp_name rp_cpu times\n"); - return -EINVAL; - } - - for (times = atoi(argv[5]); times > 0; times--) - { - printf("server_multi_times: %d\n", num++); - ret = rpsock_stream_multi_times_server(argv); - if (ret < 0 && ret != -EINPROGRESS) - { - printf("server socket failure %d\n", ret); - return ret; - } - } - } return -EINVAL; } diff --git a/examples/rust/.gitignore b/examples/rust/.gitignore deleted file mode 100644 index 9e1d2593e..000000000 --- a/examples/rust/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/Kconfig diff --git a/examples/rust/CMakeLists.txt b/examples/rust/CMakeLists.txt deleted file mode 100644 index a4fe835a8..000000000 --- a/examples/rust/CMakeLists.txt +++ /dev/null @@ -1,24 +0,0 @@ -# ############################################################################## -# apps/examples/rust/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -nuttx_add_subdirectory() -nuttx_generate_kconfig(MENUDESC "Rust Examples") diff --git a/examples/rust/Make.defs b/examples/rust/Make.defs deleted file mode 100644 index e7fdfe51d..000000000 --- a/examples/rust/Make.defs +++ /dev/null @@ -1,23 +0,0 @@ -############################################################################ -# apps/examples/rust/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(wildcard $(APPDIR)/examples/rust/*/Make.defs) diff --git a/examples/rust/Makefile b/examples/rust/Makefile deleted file mode 100644 index 5d75f316e..000000000 --- a/examples/rust/Makefile +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/examples/rust/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -MENUDESC = "Rust Examples" - -include $(APPDIR)/Directory.mk diff --git a/examples/rust/baremetal/Make.defs b/examples/rust/baremetal/Make.defs deleted file mode 100644 index 9ea1b9f9f..000000000 --- a/examples/rust/baremetal/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/examples/rust/baremetal/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_EXAMPLES_HELLO_RUST),) -CONFIGURED_APPS += $(APPDIR)/examples/rust/baremetal -endif diff --git a/examples/rust/hello/.gitignore b/examples/rust/hello/.gitignore deleted file mode 100644 index eb5a316cb..000000000 --- a/examples/rust/hello/.gitignore +++ /dev/null @@ -1 +0,0 @@ -target diff --git a/examples/rust/hello/CMakeLists.txt b/examples/rust/hello/CMakeLists.txt deleted file mode 100644 index b84e0234a..000000000 --- a/examples/rust/hello/CMakeLists.txt +++ /dev/null @@ -1,36 +0,0 @@ -# ############################################################################## -# apps/examples/rust/hello/CMakeLists.txt -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_HELLO_RUST_CARGO) - - # Build the Rust crate using nuttx_add_rust - if(CONFIG_ARCH_SIM) - nuttx_add_rust(CRATE_NAME hello CRATE_PATH ${CMAKE_CURRENT_SOURCE_DIR} - FEATURES sim) - else() - nuttx_add_rust(CRATE_NAME hello CRATE_PATH ${CMAKE_CURRENT_SOURCE_DIR}) - endif() - - nuttx_add_application( - NAME ${CONFIG_EXAMPLES_HELLO_RUST_CARGO_PROGNAME} STACKSIZE - ${CONFIG_EXAMPLES_HELLO_RUST_CARGO_STACKSIZE} PRIORITY - ${CONFIG_EXAMPLES_HELLO_RUST_CARGO_PRIORITY}) - -endif() # CONFIG_EXAMPLES_HELLO_RUST_CARGO diff --git a/examples/rust/hello/Cargo.toml b/examples/rust/hello/Cargo.toml deleted file mode 100644 index d58728934..000000000 --- a/examples/rust/hello/Cargo.toml +++ /dev/null @@ -1,25 +0,0 @@ -[package] -name = "hello" -version = "0.1.0" -edition = "2021" - -[lib] -crate-type = ["staticlib"] - -[features] -sim = [] - -[profile.dev] -panic = "abort" - -[profile.release] -panic = "abort" -lto = true -codegen-units = 1 -opt-level = 'z' - -[dependencies] -serde = { version = "1.0", features = ["derive"] } -serde_json = "1.0" - -tokio = { version = "1", features = ["rt"] } diff --git a/examples/rust/hello/Kconfig b/examples/rust/hello/Kconfig deleted file mode 100644 index 47954ed0f..000000000 --- a/examples/rust/hello/Kconfig +++ /dev/null @@ -1,29 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config EXAMPLES_HELLO_RUST_CARGO - tristate "\"Hello, Rust!\" example with Cargo" - default n - ---help--- - Enable the \"Hello, Rust!\" example using Cargo to build. - -if EXAMPLES_HELLO_RUST_CARGO - -config EXAMPLES_HELLO_RUST_CARGO_PROGNAME - string "Program name" - default "hello_rust_cargo" - ---help--- - This is the name of the program that will be used when the - program is installed. - -config EXAMPLES_HELLO_RUST_CARGO_PRIORITY - int "Hello Rust task priority" - default 100 - -config EXAMPLES_HELLO_RUST_CARGO_STACKSIZE - int "Hello Rust stack size" - default DEFAULT_TASK_STACKSIZE - -endif diff --git a/examples/rust/hello/Make.defs b/examples/rust/hello/Make.defs deleted file mode 100644 index 829b1c507..000000000 --- a/examples/rust/hello/Make.defs +++ /dev/null @@ -1,26 +0,0 @@ -############################################################################ -# apps/examples/rust/hello/Make.defs -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/tools/Rust.mk - -ifneq ($(CONFIG_EXAMPLES_HELLO_RUST_CARGO),) -CONFIGURED_APPS += $(APPDIR)/examples/rust/hello -EXTRA_LIBS += $(call RUST_GET_BINDIR,hello,$(APPDIR)/examples/rust) -endif diff --git a/examples/rust/hello/Makefile b/examples/rust/hello/Makefile deleted file mode 100644 index 0e1b534c4..000000000 --- a/examples/rust/hello/Makefile +++ /dev/null @@ -1,47 +0,0 @@ -############################################################################ -# apps/examples/rust/hello/Makefile -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -# Hello, Rust! built-in application info - -PROGNAME = $(CONFIG_EXAMPLES_HELLO_RUST_CARGO_PROGNAME) -PRIORITY = $(CONFIG_EXAMPLES_HELLO_RUST_CARGO_PRIORITY) -STACKSIZE = $(CONFIG_EXAMPLES_HELLO_RUST_CARGO_STACKSIZE) -MODULE = $(CONFIG_EXAMPLES_HELLO_RUST_CARGO) - -RUST_LIB := $(call RUST_GET_BINDIR,hello,$(APPDIR)/examples/rust) -RUST_SRCS := $(call RUST_CARGO_SRCS,hello,$(APPDIR)/examples/rust) - -ifeq ($(CONFIG_ARCH_SIM),y) -HELLO_RUST_FEATURES := sim -endif - -$(RUST_LIB): $(RUST_SRCS) - $(call RUST_CARGO_BUILD,hello,$(APPDIR)/examples/rust,$(HELLO_RUST_FEATURES)) - -context:: $(RUST_LIB) - -all:: $(RUST_LIB) - -clean:: - $(call RUST_CARGO_CLEAN,hello,$(APPDIR)/examples/rust) - -include $(APPDIR)/Application.mk diff --git a/examples/rust/hello/src/lib.rs b/examples/rust/hello/src/lib.rs deleted file mode 100644 index e9b0e0ade..000000000 --- a/examples/rust/hello/src/lib.rs +++ /dev/null @@ -1,73 +0,0 @@ -extern crate serde; -extern crate serde_json; - -use core::ffi::{c_char, c_int, CStr}; -use serde::{Deserialize, Serialize}; - -#[derive(Serialize, Deserialize)] -struct Person { - name: String, - age: u8, -} - -fn print_args(argc: c_int, argv: *mut *mut c_char) { - if argv.is_null() { - return; - } - - for i in 1..argc { - let arg = unsafe { *argv.add(i as usize) }; - if arg.is_null() { - continue; - } - - let arg = unsafe { CStr::from_ptr(arg) }.to_string_lossy(); - println!("{}: {}", i, arg); - } -} - -// Function hello_rust_cargo without mangling -#[no_mangle] -pub extern "C" fn hello_rust_cargo_main(argc: c_int, argv: *mut *mut c_char) -> c_int { - print_args(argc, argv); - - #[cfg(feature = "sim")] - println!("On simulator"); - - let john = Person { - name: "John".to_string(), - age: 30, - }; - - let json_str = serde_json::to_string(&john).unwrap(); - println!("{}", json_str); - - let jane = Person { - name: "Jane".to_string(), - age: 25, - }; - - let json_str_jane = serde_json::to_string(&jane).unwrap(); - println!("{}", json_str_jane); - - let json_data = r#" - { - "name": "Alice", - "age": 28 - }"#; - - let alice: Person = serde_json::from_str(json_data).unwrap(); - println!("Deserialized: {} is {} years old", alice.name, alice.age); - - let pretty_json_str = serde_json::to_string_pretty(&alice).unwrap(); - println!("Pretty JSON:\n{}", pretty_json_str); - - tokio::runtime::Builder::new_current_thread() - .enable_all() - .build() - .unwrap() - .block_on(async { - println!("Hello world from tokio!"); - }); - 0 -} diff --git a/examples/rust/slint/.gitignore b/examples/rust/slint/.gitignore deleted file mode 100644 index eb5a316cb..000000000 --- a/examples/rust/slint/.gitignore +++ /dev/null @@ -1 +0,0 @@ -target diff --git a/examples/rust/slint/CMakeLists.txt b/examples/rust/slint/CMakeLists.txt deleted file mode 100644 index 6ed088aea..000000000 --- a/examples/rust/slint/CMakeLists.txt +++ /dev/null @@ -1,31 +0,0 @@ -# ############################################################################## -# apps/examples/rust/slint/CMakeLists.txt -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_RUST_SLINT) - - # Build the Rust crate using nuttx_add_rust - nuttx_add_rust(CRATE_NAME slint CRATE_PATH ${CMAKE_CURRENT_SOURCE_DIR}) - - nuttx_add_application( - NAME ${CONFIG_EXAMPLES_RUST_SLINT_PROGNAME} STACKSIZE - ${CONFIG_EXAMPLES_RUST_SLINT_STACKSIZE} PRIORITY - ${CONFIG_EXAMPLES_RUST_SLINT_PRIORITY}) - -endif() # CONFIG_EXAMPLES_RUST_SLINT diff --git a/examples/rust/slint/Cargo.toml b/examples/rust/slint/Cargo.toml deleted file mode 100644 index af585ceb1..000000000 --- a/examples/rust/slint/Cargo.toml +++ /dev/null @@ -1,24 +0,0 @@ -[package] -name = "slint" -version = "0.1.0" -edition = "2021" - -[lib] -crate-type = ["staticlib"] - -[profile.dev] -panic = "abort" - -[profile.release] -panic = "abort" -lto = true -codegen-units = 1 -opt-level = 'z' - -[dependencies] -libc = "0.2" -slint = { version = "1.9", default-features = false, features = ["compat-1-2", "renderer-software", "libm", "unsafe-single-threaded"] } -nuttx = { git = "https://github.com/no1wudi/nuttx-rs.git", branch = "main" } - -[build-dependencies] -slint-build = { version = "1.9" } diff --git a/examples/rust/slint/Kconfig b/examples/rust/slint/Kconfig deleted file mode 100644 index babc19d04..000000000 --- a/examples/rust/slint/Kconfig +++ /dev/null @@ -1,29 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config EXAMPLES_RUST_SLINT - tristate "Slint Basic Example" - default n - ---help--- - Enable the basic Slint example. - -if EXAMPLES_RUST_SLINT - -config EXAMPLES_RUST_SLINT_PROGNAME - string "Program name" - default "slint" - ---help--- - This is the name of the program that will be used when the - program is installed. - -config EXAMPLES_RUST_SLINT_PRIORITY - int "Task priority" - default 100 - -config EXAMPLES_RUST_SLINT_STACKSIZE - int "Stack size" - default DEFAULT_TASK_STACKSIZE - -endif diff --git a/examples/rust/slint/Make.defs b/examples/rust/slint/Make.defs deleted file mode 100644 index 9259913fc..000000000 --- a/examples/rust/slint/Make.defs +++ /dev/null @@ -1,26 +0,0 @@ -############################################################################ -# apps/examples/rust/slint/Make.defs -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/tools/Rust.mk - -ifneq ($(CONFIG_EXAMPLES_RUST_SLINT),) -CONFIGURED_APPS += $(APPDIR)/examples/rust/slint -EXTRA_LIBS += $(call RUST_GET_BINDIR,slint,$(APPDIR)/examples/rust) -endif diff --git a/examples/rust/slint/Makefile b/examples/rust/slint/Makefile deleted file mode 100644 index 747f8960b..000000000 --- a/examples/rust/slint/Makefile +++ /dev/null @@ -1,41 +0,0 @@ -############################################################################ -# apps/examples/rust/slint/Makefile -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -PROGNAME = $(CONFIG_EXAMPLES_RUST_SLINT_PROGNAME) -PRIORITY = $(CONFIG_EXAMPLES_RUST_SLINT_PRIORITY) -STACKSIZE = $(CONFIG_EXAMPLES_RUST_SLINT_STACKSIZE) -MODULE = $(CONFIG_EXAMPLES_RUST_SLINT) - -RUST_LIB := $(call RUST_GET_BINDIR,slint,$(APPDIR)/examples/rust) -RUST_SRCS := $(call RUST_CARGO_SRCS,slint,$(APPDIR)/examples/rust) - -$(RUST_LIB): $(RUST_SRCS) - $(call RUST_CARGO_BUILD,slint,$(APPDIR)/examples/rust) - -context:: $(RUST_LIB) - -all:: $(RUST_LIB) - -clean:: - $(call RUST_CARGO_CLEAN,slint,$(APPDIR)/examples/rust) - -include $(APPDIR)/Application.mk diff --git a/examples/rust/slint/build.rs b/examples/rust/slint/build.rs deleted file mode 100644 index 6142de92a..000000000 --- a/examples/rust/slint/build.rs +++ /dev/null @@ -1,28 +0,0 @@ -// ############################################################################## -// examples/rust/slint/build.rs -// -// Licensed to the Apache Software Foundation (ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with this work for -// additional information regarding copyright ownership. The ASF licenses this -// file to you under the Apache License, Version 2.0 (the "License"); you may not -// use this file except in compliance with the License. You may obtain a copy of -// the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -// License for the specific language governing permissions and limitations under -// the License. -// -// ############################################################################## - -fn main() { - slint_build::compile_with_config( - "ui/app.slint", - slint_build::CompilerConfiguration::new() - .embed_resources(slint_build::EmbedResourcesKind::EmbedForSoftwareRenderer), - ) - .unwrap(); -} diff --git a/examples/rust/slint/src/lib.rs b/examples/rust/slint/src/lib.rs deleted file mode 100644 index 7f81ce29c..000000000 --- a/examples/rust/slint/src/lib.rs +++ /dev/null @@ -1,171 +0,0 @@ -// ############################################################################## -// examples/rust/slint/src/lib.rs -// -// Licensed to the Apache Software Foundation (ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with this work for -// additional information regarding copyright ownership. The ASF licenses this -// file to you under the Apache License, Version 2.0 (the "License"); you may not -// use this file except in compliance with the License. You may obtain a copy of -// the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -// License for the specific language governing permissions and limitations under -// the License. -// -// ############################################################################## - -use std::rc::Rc; -use std::{cell::RefCell, ffi::CStr}; - -use slint::platform::software_renderer::{LineBufferProvider, Rgb565Pixel}; - -use nuttx::input::touchscreen::*; -use nuttx::video::fb::*; -use slint::platform::WindowEvent; - -slint::include_modules!(); - -struct NuttXPlatform { - window: Rc<slint::platform::software_renderer::MinimalSoftwareWindow>, -} - -impl slint::platform::Platform for NuttXPlatform { - fn create_window_adapter( - &self, - ) -> Result<Rc<dyn slint::platform::WindowAdapter>, slint::PlatformError> { - Ok(self.window.clone()) - } - fn duration_since_start(&self) -> std::time::Duration { - std::time::SystemTime::now() - .duration_since(std::time::UNIX_EPOCH) - .unwrap() - } -} - -fn create_slint_app() -> AppWindow { - AppWindow::new().expect("Failed to load UI") -} - -#[derive(Debug, Clone)] -struct NuttXRenderer { - frame_buffer: *mut u8, - line_buffer: Rc<RefCell<Vec<Rgb565Pixel>>>, - stride: usize, - lines: usize, -} - -impl LineBufferProvider for NuttXRenderer { - type TargetPixel = Rgb565Pixel; - fn process_line( - &mut self, - line: usize, - range: std::ops::Range<usize>, - render_fn: impl FnOnce(&mut [Self::TargetPixel]), - ) { - let fb_size = self.stride * self.lines; - let frame = unsafe { - std::slice::from_raw_parts_mut(self.frame_buffer as *mut Rgb565Pixel, fb_size) - }; - let mut buffer = self.line_buffer.borrow_mut(); - render_fn(&mut buffer[range.clone()]); - let offset = line * self.stride; - frame[offset..offset + range.end - range.start].copy_from_slice(&buffer[range]); - } -} - -#[no_mangle] -pub extern "C" fn slint_main() { - // Open the framebuffer device and get its information - let fbdev = match FrameBuffer::new(CStr::from_bytes_with_nul(b"/dev/fb0\0").unwrap()) { - Ok(fb) => fb, - Err(_) => { - println!("Failed to open framebuffer device"); - return; - } - }; - - let planeinfo = fbdev.get_plane_info().unwrap(); - let videoinfo = fbdev.get_video_info().unwrap(); - - println!("{:?}", planeinfo); - println!("{:?}", videoinfo); - - if videoinfo.fmt != FB_FMT_RGB16_565 as u8 { - println!("Unsupported pixel format, only RGB565 is supported for now"); - return; - } - - // Open the touchscreen device - let mut tsdev = match TouchScreen::open(CStr::from_bytes_with_nul(b"/dev/input0\0").unwrap()) { - Ok(ts) => ts, - Err(_) => { - println!("Failed to open touchscreen device"); - return; - } - }; - - // Setup the Slint backend - let window = slint::platform::software_renderer::MinimalSoftwareWindow::new(Default::default()); - window.set_size(slint::PhysicalSize::new( - videoinfo.xres.into(), - videoinfo.yres.into(), - )); - - // Set the platform - slint::platform::set_platform(Box::new(NuttXPlatform { - window: window.clone(), - })) - .unwrap(); - - // Configure the UI - let _ui = create_slint_app(); - - // Create the renderer for NuttX - let nxrender = NuttXRenderer { - frame_buffer: planeinfo.fbmem as *mut u8, - line_buffer: Rc::new(RefCell::new(vec![ - Rgb565Pixel::default(); - videoinfo.xres as usize - ])), - stride: videoinfo.xres.into(), - lines: videoinfo.yres.into(), - }; - - let button = slint::platform::PointerEventButton::Left; - let mut last_touch_down = false; - let mut last_position = Default::default(); - - loop { - slint::platform::update_timers_and_animations(); - window.draw_if_needed(|renderer| { - renderer.render_by_line(nxrender.clone()); - }); - - if let Ok(sample) = tsdev.read_sample() { - if sample.npoints > 0 { - let point = sample.point[0]; - if point.is_pos_valid() { - let position = slint::PhysicalPosition::new(point.x.into(), point.y.into()) - .to_logical(window.scale_factor()); - last_position = position; - if point.is_touch_down() || point.is_touch_move() { - last_touch_down = true; - window.dispatch_event(WindowEvent::PointerPressed { position, button }); - } - } - } - } else { - if last_touch_down { - window.dispatch_event(WindowEvent::PointerReleased { - position: last_position, - button, - }); - last_touch_down = false; - } - } - } -} diff --git a/examples/rust/slint/ui/app.slint b/examples/rust/slint/ui/app.slint deleted file mode 100644 index 29c14af06..000000000 --- a/examples/rust/slint/ui/app.slint +++ /dev/null @@ -1,25 +0,0 @@ -import { Button, VerticalBox, HorizontalBox , AboutSlint } from "std-widgets.slint"; - -export component AppWindow inherits Window { - property <int> counter: 0; - - timer := Timer { - interval: 1s; - running: true; - triggered() => { - counter += 1; - } - } - - VerticalBox { - Text { - horizontal-alignment: center; - vertical-alignment: center; - text: "Times since start on NuttX: \n\{root.counter}"; - font-size: 24px; - } - - AboutSlint { } - - } -} diff --git a/examples/scd41/CMakeLists.txt b/examples/scd41/CMakeLists.txt deleted file mode 100644 index 5f6d23f59..000000000 --- a/examples/scd41/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -################################################################################ -# apps/examples/scd41/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -################################################################################ - -if(CONFIG_EXAMPLES_SCD41) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_SCD41_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_SCD41_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_SCD41_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_SCD41} - SRCS - scd41_main.c) -endif() diff --git a/examples/scd41/Kconfig b/examples/scd41/Kconfig deleted file mode 100644 index 8c62677b3..000000000 --- a/examples/scd41/Kconfig +++ /dev/null @@ -1,36 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config EXAMPLES_SCD41 - tristate "SCD41 CO2 sensor example" - default n - depends on SENSORS_SCD41 - ---help--- - Enable the SCD41 CO2 sensor example - -if EXAMPLES_SCD41 - -config EXAMPLES_SCD41_PROGNAME - string "Program name" - default "scd41" - ---help--- - This is the name of the program that will be used when the NSH ELF - program is installed. - -config EXAMPLES_SCD41_DEVPATH - string "Device path" - default "/dev/co2" - ---help--- - The device path - -config EXAMPLES_SCD41_PRIORITY - int "scd41 task priority" - default 100 - -config EXAMPLES_SCD41_STACKSIZE - int "scd41 stack size" - default DEFAULT_TASK_STACKSIZE - -endif diff --git a/examples/scd41/Make.defs b/examples/scd41/Make.defs deleted file mode 100644 index 94c31ce0b..000000000 --- a/examples/scd41/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/examples/scd41/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_EXAMPLES_SCD41),) -CONFIGURED_APPS += $(APPDIR)/examples/scd41 -endif diff --git a/examples/scd41/Makefile b/examples/scd41/Makefile deleted file mode 100644 index 9b255a866..000000000 --- a/examples/scd41/Makefile +++ /dev/null @@ -1,36 +0,0 @@ -############################################################################ -# apps/examples/scd41/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -# scd41 co2 sensor built-in application info - -PROGNAME = $(CONFIG_EXAMPLES_SCD41_PROGNAME) -PRIORITY = $(CONFIG_EXAMPLES_SCD41_PRIORITY) -STACKSIZE = $(CONFIG_EXAMPLES_SCD41_STACKSIZE) -MODULE = $(CONFIG_EXAMPLES_SCD41) - -# scd41 co2 sensor Example - -MAINSRC = scd41_main.c - -include $(APPDIR)/Application.mk diff --git a/examples/scd41/scd41_main.c b/examples/scd41/scd41_main.c deleted file mode 100644 index b524ab55b..000000000 --- a/examples/scd41/scd41_main.c +++ /dev/null @@ -1,89 +0,0 @@ -/**************************************************************************** - * apps/examples/scd41/scd41_main.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> -#include <stdio.h> -#include <fcntl.h> -#include <unistd.h> -#include <sys/ioctl.h> -#include <sys/stat.h> -#include <sys/types.h> - -#include <nuttx/sensors/scd41.h> - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * scd41_main - ****************************************************************************/ - -int main(int argc, FAR char *argv[]) -{ - struct scd41_conv_data_s data; - int fd; - int ret; - int i; - - printf("scd41 app is running.\n"); - - fd = open(CONFIG_EXAMPLES_SCD41_DEVPATH, O_RDWR); - if (fd < 0) - { - printf("ERROR: open failed: %d\n", fd); - return -1; - } - - for (i = 0; i < 20; i++) - { - /* Sensor data is updated every 5 seconds. */ - - sleep(5); - - ret = ioctl(fd, SNIOC_READ_CONVERT_DATA, (unsigned long)&data); - if (ret < 0) - { - printf("Read error.\n"); - printf("Sensor reported error %d\n", ret); - } - else - { - printf("CO2[ppm]: %.2f, Temperature[C]: %.2f, RH[%%]: %.2f\n", - data.co2, data.temperature, data.humidity); - } - } - - ret = ioctl(fd, SNIOC_STOP, 0); - if (ret < 0) - { - printf("Failed to stop: %d\n", errno); - } - - close(fd); - - return 0; -} diff --git a/examples/sendmail/CMakeLists.txt b/examples/sendmail/CMakeLists.txt deleted file mode 100644 index 04f7f4445..000000000 --- a/examples/sendmail/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# ############################################################################## -# apps/examples/sendmail/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_SENDMAIL) - nuttx_add_application( - NAME - sendmail - STACKSIZE - ${CONFIG_DEFAULT_TASK_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_SENDMAIL} - SRCS - sendmail_main.c) -endif() diff --git a/examples/sendmail/Make.defs b/examples/sendmail/Make.defs index 4d6e9b6e0..328660712 100644 --- a/examples/sendmail/Make.defs +++ b/examples/sendmail/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/sendmail/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/sendmail/Makefile b/examples/sendmail/Makefile index 9013d24ea..61191601d 100644 --- a/examples/sendmail/Makefile +++ b/examples/sendmail/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/sendmail/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/sendmail/sendmail_main.c b/examples/sendmail/sendmail_main.c index 7a0abdf1a..5cd868777 100644 --- a/examples/sendmail/sendmail_main.c +++ b/examples/sendmail/sendmail_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/sendmail/sendmail_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/sensor_fusion/Kconfig b/examples/sensor_fusion/Kconfig deleted file mode 100644 index ba1fd6674..000000000 --- a/examples/sensor_fusion/Kconfig +++ /dev/null @@ -1,38 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config EXAMPLES_SENSOR_FUSION - bool "Sensor Fusion Example" - default n - ---help--- - Sensor fusion example that combines gyro and accelerometer data - using the Madgwick algorithm to provide yaw, pitch and roll angles. - -if EXAMPLES_SENSOR_FUSION - -config EXAMPLES_SENSOR_FUSION_SAMPLES - int "Number of samples to acquire" - default 100 - -config EXAMPLES_SENSOR_FUSION_SAMPLE_RATE - int "Sample rate in ms" - default 100 - -config EXAMPLES_SENSOR_FUSION_PROGNAME - string "Program name" - default "sensor_fusion" - ---help--- - This is the name of the program that will be used when the NSH ELF - program is installed. - -config EXAMPLES_SENSOR_FUSION_PRIORITY - int "Sensor Fusion task priority" - default 100 - -config EXAMPLES_SENSOR_FUSION_STACKSIZE - int "Sensor Fusion stack size" - default DEFAULT_TASK_STACKSIZE - -endif diff --git a/examples/sensor_fusion/Make.defs b/examples/sensor_fusion/Make.defs deleted file mode 100644 index 82c947955..000000000 --- a/examples/sensor_fusion/Make.defs +++ /dev/null @@ -1,26 +0,0 @@ -############################################################################ -# apps/examples/sensor_fusion/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_EXAMPLES_SENSOR_FUSION),) -CONFIGURED_APPS += $(APPDIR)/examples/sensor_fusion - -endif diff --git a/examples/sensor_fusion/Makefile b/examples/sensor_fusion/Makefile deleted file mode 100644 index 50a33cffc..000000000 --- a/examples/sensor_fusion/Makefile +++ /dev/null @@ -1,32 +0,0 @@ -############################################################################ -# apps/examples/sensor_fusion/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -PROGNAME = $(CONFIG_EXAMPLES_SENSOR_FUSION_PROGNAME) -PRIORITY = $(CONFIG_EXAMPLES_SENSOR_FUSION_PRIORITY) -STACKSIZE = $(CONFIG_EXAMPLES_SENSOR_FUSION_STACKSIZE) -MODULE = $(CONFIG_EXAMPLES_SENSOR_FUSION) - -MAINSRC = sensor_fusion_main.c - -include $(APPDIR)/Application.mk diff --git a/examples/sensor_fusion/sensor_fusion_main.c b/examples/sensor_fusion/sensor_fusion_main.c deleted file mode 100644 index cad590332..000000000 --- a/examples/sensor_fusion/sensor_fusion_main.c +++ /dev/null @@ -1,164 +0,0 @@ -/**************************************************************************** - * apps/examples/sensor_fusion/sensor_fusion_main.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> -#include <stdio.h> -#include <fcntl.h> -#include <unistd.h> -#include <nuttx/sensors/sensor.h> -#include "Fusion/Fusion.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define REG_LOW_MASK 0xFF00 -#define REG_HIGH_MASK 0x00FF -#define MPU6050_FS_SEL 32.8f -#define MPU6050_AFS_SEL 4096.0f - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -struct mpu6050_imu_msg -{ - int16_t acc_x; - int16_t acc_y; - int16_t acc_z; - int16_t temp; - int16_t gyro_x; - int16_t gyro_y; - int16_t gyro_z; -}; - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -void read_mpu6050(int fd, struct sensor_accel *acc_data, - struct sensor_gyro *gyro_data); - -/**************************************************************************** - * sensor_fusion_main - ****************************************************************************/ - -int main(int argc, char *argv[]) -{ - int fd; - int iterations = CONFIG_EXAMPLES_SENSOR_FUSION_SAMPLES; - float acq_period = CONFIG_EXAMPLES_SENSOR_FUSION_SAMPLE_RATE / 1000.0f; - - /* Minimal required data for Fusion library. Use of magnetometer data - * is optional and can improve performance. - */ - - struct sensor_accel imu_acc_data; - struct sensor_gyro imu_gyro_data; - FusionVector accelerometer; - FusionVector gyroscope; - FusionEuler euler; - FusionAhrs ahrs; - - FusionAhrsInitialise(&ahrs); - - printf("Sensor Fusion example\n"); - printf("Sample Rate: %.2f Hz\n", 1.0 / acq_period); - - fd = open("/dev/imu0", O_RDONLY); - if (fd < 0) - { - printf("Failed to open imu0\n"); - return EXIT_FAILURE; - } - - for (int i = 0; i < iterations; i++) - { - read_mpu6050(fd, &imu_acc_data, &imu_gyro_data); - - accelerometer.axis.x = imu_acc_data.x; - accelerometer.axis.y = imu_acc_data.y; - accelerometer.axis.z = imu_acc_data.z; - - gyroscope.axis.x = imu_gyro_data.x; - gyroscope.axis.y = imu_gyro_data.y; - gyroscope.axis.z = imu_gyro_data.z; - - FusionAhrsUpdateNoMagnetometer(&ahrs, - gyroscope, - accelerometer, - acq_period); - euler = FusionQuaternionToEuler(FusionAhrsGetQuaternion(&ahrs)); - - printf("Yaw: %.3f | Pitch: %.3f | Roll: %.3f\n", - euler.angle.yaw, euler.angle.pitch, euler.angle.roll); - usleep(CONFIG_EXAMPLES_SENSOR_FUSION_SAMPLE_RATE * 1000); - } - - close(fd); - - return EXIT_SUCCESS; -} - -void read_mpu6050(int fd, - struct sensor_accel *acc_data, - struct sensor_gyro *gyro_data) -{ - struct mpu6050_imu_msg raw_imu; - int16_t raw_data[7]; - memset(&raw_imu, 0, sizeof(raw_imu)); - - int ret = read(fd, &raw_data, sizeof(raw_data)); - if (ret != sizeof(raw_data)) - { - printf("Failed to read accelerometer data\n"); - } - else - { - raw_imu.acc_x = ((raw_data[0] & REG_HIGH_MASK) << 8) + - ((raw_data[0] & REG_LOW_MASK) >> 8); - raw_imu.acc_y = ((raw_data[1] & REG_HIGH_MASK) << 8) + - ((raw_data[1] & REG_LOW_MASK) >> 8); - raw_imu.acc_z = ((raw_data[2] & REG_HIGH_MASK) << 8) + - ((raw_data[2] & REG_LOW_MASK) >> 8); - raw_imu.gyro_x = ((raw_data[4] & REG_HIGH_MASK) << 8) + - ((raw_data[4] & REG_LOW_MASK) >> 8); - raw_imu.gyro_y = ((raw_data[5] & REG_HIGH_MASK) << 8) + - ((raw_data[5] & REG_LOW_MASK) >> 8); - raw_imu.gyro_z = ((raw_data[6] & REG_HIGH_MASK) << 8) + - ((raw_data[6] & REG_LOW_MASK) >> 8); - } - - acc_data->x = raw_imu.acc_x / MPU6050_AFS_SEL; - acc_data->y = raw_imu.acc_y / MPU6050_AFS_SEL; - acc_data->z = raw_imu.acc_z / MPU6050_AFS_SEL; - - /* Gyro data in ยบ/s (degrees per second) */ - - gyro_data->x = raw_imu.gyro_x / MPU6050_FS_SEL; - gyro_data->y = raw_imu.gyro_y / MPU6050_FS_SEL; - gyro_data->z = raw_imu.gyro_z / MPU6050_FS_SEL; -} diff --git a/examples/serialblaster/CMakeLists.txt b/examples/serialblaster/CMakeLists.txt deleted file mode 100644 index 4e3847922..000000000 --- a/examples/serialblaster/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# ############################################################################## -# apps/examples/serialblaster/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_SERIALBLASTER) - nuttx_add_application( - NAME - serialblaster - PRIORITY - ${CONFIG_EXAMPLES_SERIALBLASTER_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_SERIALBLASTER_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_SERIALBLASTER} - SRCS - serialblaster_main.c) -endif() diff --git a/examples/serialblaster/Make.defs b/examples/serialblaster/Make.defs index a41781010..c92ed53a7 100644 --- a/examples/serialblaster/Make.defs +++ b/examples/serialblaster/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/serialblaster/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/serialblaster/Makefile b/examples/serialblaster/Makefile index 79d849fa6..ce8fb45b2 100644 --- a/examples/serialblaster/Makefile +++ b/examples/serialblaster/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/serialblaster/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/serialblaster/serialblaster_main.c b/examples/serialblaster/serialblaster_main.c index b028efa18..bf43d640d 100644 --- a/examples/serialblaster/serialblaster_main.c +++ b/examples/serialblaster/serialblaster_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/serialblaster/serialblaster_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -61,8 +59,7 @@ int main(int argc, FAR char *argv[]) int ret; int fd; FAR char *devpath; - const int slength = sizeof(s)-1; - int size = slength; + int size = 0; int rem; if (argc == 1) @@ -87,25 +84,25 @@ int main(int argc, FAR char *argv[]) fd = open(devpath, O_RDWR); if (fd < 0) { - printf("%s: ERROR Failed to open %s\n", argv[0], devpath); + printf("dev_ttyS2: ERROR Failed to open /dev/ttyS2\n"); return -1; } rem = size; - printf("Sending %d bytes of data to %s (fd=%d)\n", size, devpath, fd); - while (rem > 0) + while (size > sizeof(s)) { - if (rem > slength) + if (rem > 26) { - ret = write(fd, s, slength); - rem = rem - slength; - } - else - { - ret = write(fd, s, rem); - rem = 0; + ret = write(fd, s, (sizeof(s)-1)); } + rem = rem - 26; + if (rem < 26) + { + ret = write(fd, s, rem); + } + + size = size - 26; UNUSED(ret); } diff --git a/examples/serialrx/CMakeLists.txt b/examples/serialrx/CMakeLists.txt deleted file mode 100644 index dab565f6f..000000000 --- a/examples/serialrx/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# ############################################################################## -# apps/examples/serialrx/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_SERIALRX) - nuttx_add_application( - NAME - serialrx - PRIORITY - ${CONFIG_EXAMPLES_SERIALRX_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_SERIALRX_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_SERIALRX} - SRCS - serialrx_main.c) -endif() diff --git a/examples/serialrx/Make.defs b/examples/serialrx/Make.defs index 40359140c..942c94f84 100644 --- a/examples/serialrx/Make.defs +++ b/examples/serialrx/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/serialrx/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/serialrx/Makefile b/examples/serialrx/Makefile index fbb9ec1ad..56cfa3ad2 100644 --- a/examples/serialrx/Makefile +++ b/examples/serialrx/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/serialrx/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/serialrx/serialrx_main.c b/examples/serialrx/serialrx_main.c index af7468e4d..bb69963ae 100644 --- a/examples/serialrx/serialrx_main.c +++ b/examples/serialrx/serialrx_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/serialrx/serialrx_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -32,8 +30,6 @@ #include <stdint.h> #include <stdio.h> #include <stdlib.h> -#include <unistd.h> - #include <nuttx/arch.h> /**************************************************************************** @@ -54,7 +50,7 @@ int main(int argc, FAR char *argv[]) #else int fd; int cnt; - + int bytecount = 0; #endif #ifdef CONFIG_EXAMPLES_SERIALRX_PRINTHYPHEN int count = 0; @@ -66,7 +62,6 @@ int main(int argc, FAR char *argv[]) bool eof = false; FAR char *buf; FAR char *devpath; - int bytecount = 0; if (argc == 1) { diff --git a/examples/serloop/CMakeLists.txt b/examples/serloop/CMakeLists.txt deleted file mode 100644 index 5a3c3e715..000000000 --- a/examples/serloop/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# ############################################################################## -# apps/examples/serloop/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_SERLOOP) - nuttx_add_application( - NAME - serloop - STACKSIZE - ${CONFIG_DEFAULT_TASK_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_SERLOOP} - SRCS - serloop_main.c) -endif() diff --git a/examples/serloop/Make.defs b/examples/serloop/Make.defs index 268fc5f90..2ea8de90a 100644 --- a/examples/serloop/Make.defs +++ b/examples/serloop/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/serloop/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/serloop/Makefile b/examples/serloop/Makefile index 3fcdc6ba3..782613a02 100644 --- a/examples/serloop/Makefile +++ b/examples/serloop/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/serloop/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/serloop/serloop_main.c b/examples/serloop/serloop_main.c index 00bf32253..a1e916e1f 100644 --- a/examples/serloop/serloop_main.c +++ b/examples/serloop/serloop_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/serloop/serloop_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/settings/Kconfig b/examples/settings/Kconfig deleted file mode 100644 index 81bf1e93d..000000000 --- a/examples/settings/Kconfig +++ /dev/null @@ -1,61 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config EXAMPLES_SETTINGS - tristate "Settings example" - default n - ---help--- - Enable the "settings" example. This uses the functions provided in - system/settings to test the storage and retrieval of various - configurable parameters - -if EXAMPLES_SETTINGS - -config EXAMPLES_SETTINGS_PROGNAME - string "Program name" - default "settings" - ---help--- - This is the name of the program that will be used when the NSH ELF - program is installed. - -config EXAMPLES_SETTINGS_PRIORITY - int "settings task priority" - default 100 - -config EXAMPLES_SETTINGS_STACKSIZE - int "settings stack size" - default DEFAULT_TASK_STACKSIZE - -choice - prompt "Select settings storage location" - default EXAMPLES_SETTINGS_USE_TMPFS - -config EXAMPLES_SETTINGS_USE_TMPFS - bool "Use TMPFS" - select FS_TMPFS - ---help--- - TMPFS will be enabled and used - -config EXAMPLES_SETTINGS_USE_OTHER - bool "Use existing/other storage media" - -endchoice # Select settings storage location - -if EXAMPLES_SETTINGS_USE_OTHER - -config EXAMPLES_SETTINGS_EXISTING_STORAGE - string "Path to existing storage media" - default "/mnt/mmcsd0" - -endif # EXAMPLES_SETTINGS_USE_OTHER - -config EXAMPLES_SETTINGS_FILENAME - string "Filename" - default "settings" - ---help--- - filename to be used. This append will append .txt and .bin - to this name to use/create two settings files. - -endif # EXAMPLES_SETTINGS diff --git a/examples/settings/Make.defs b/examples/settings/Make.defs deleted file mode 100644 index 6fac4077b..000000000 --- a/examples/settings/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/examples/settings/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_EXAMPLES_SETTINGS),) -CONFIGURED_APPS += $(APPDIR)/examples/settings -endif diff --git a/examples/settings/Makefile b/examples/settings/Makefile deleted file mode 100644 index 648563785..000000000 --- a/examples/settings/Makefile +++ /dev/null @@ -1,36 +0,0 @@ -############################################################################ -# apps/examples/settings/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -# settings built-in application info - -PROGNAME = $(CONFIG_EXAMPLES_SETTINGS_PROGNAME) -PRIORITY = $(CONFIG_EXAMPLES_SETTINGS_PRIORITY) -STACKSIZE = $(CONFIG_EXAMPLES_SETTINGS_STACKSIZE) -MODULE = $(CONFIG_EXAMPLES_SETTINGS) - -# Settings Example - -MAINSRC = settings_main.c - -include $(APPDIR)/Application.mk diff --git a/examples/settings/settings_main.c b/examples/settings/settings_main.c deleted file mode 100644 index 3f718aa7c..000000000 --- a/examples/settings/settings_main.c +++ /dev/null @@ -1,303 +0,0 @@ -/**************************************************************************** - * apps/examples/settings/settings_main.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <stdio.h> -#include <sys/stat.h> -#include <fcntl.h> -#include <errno.h> -#include <sys/mount.h> -#include <sys/param.h> - -#include "system/settings.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * settings_main - ****************************************************************************/ - -int settings_main(int argc, FAR char *argv[]) -{ - int ret; - int fd; - enum settings_type_e stype; - char text_path[CONFIG_PATH_MAX]; - char bin_path[CONFIG_PATH_MAX]; - const char teststr[] = "I'm a string"; - int testval = 0x5aa5; - char readstr[CONFIG_SYSTEM_SETTINGS_VALUE_SIZE]; -#ifdef CONFIG_EXAMPLES_SETTINGS_USE_TMPFS - struct stat sbuf; - -# ifndef CONFIG_FS_TMPFS -# error TMPFS must be enabled -# endif -# ifndef CONFIG_LIBC_TMPDIR -# error LIBC_TMPDIR must be defined -# endif - if (stat(CONFIG_LIBC_TMPDIR, &sbuf)) - { - ret = nx_mount(NULL, CONFIG_LIBC_TMPDIR, "tmpfs", 0, NULL); - if (ret < 0) - { - printf("ERROR: Failed to mount tmpfs at %s: %d\n", - CONFIG_LIBC_TMPDIR, ret); - goto end; - } - } - - strcpy(bin_path, CONFIG_LIBC_TMPDIR); -#else - strcpy(bin_path, CONFIG_EXAMPLES_SETTINGS_EXISTING_STORAGE); - if (bin_path == NULL) - { - printf("Settings filepath is empty!"); - goto end; - } -#endif - - strcat(bin_path, "/"); - strcat(bin_path, CONFIG_EXAMPLES_SETTINGS_FILENAME); - strcpy(text_path, bin_path); - strcat(bin_path, ".bin"); - strcat(text_path, ".txt"); - - printf("Example of settings usage to file: %s and %s:", - bin_path, text_path); - printf("--------------------------------------------------------------\n"); - - settings_init(); - - ret = settings_setstorage(bin_path, STORAGE_BINARY); - if (ret == -ENOENT) - { - printf("No existing binary storage file found. Creating it.\n"); - fd = open(bin_path, O_CREAT, 0666); - if (fd < 0) - { - printf("Failed to create settings file\n"); - goto end; - } - - close(fd); - } - else if (ret < 0) - { - printf("settings setstorage failed: %d\n", ret); - goto end; - } - else - { - printf("existing bin settings storage file found\n"); - } - - ret = settings_setstorage(text_path, STORAGE_TEXT); - if (ret == -ENOENT) - { - printf("No existing text storage file found. Creating it.\n"); - fd = open(text_path, O_CREAT, 0666); - if (fd < 0) - { - printf("Failed to create settings file\n"); - goto end; - } - - close(fd); - } - else if (ret < 0) - { - printf("settings setstorage failed: %d\n", ret); - goto end; - } - else - { - printf("existing text settings storage file found\n"); - } - - ret = settings_create("v1", SETTING_STRING, "default value"); - if (ret < 0) - { - printf("settings create failed: %d\n", ret); - goto end; - } - - /* if this app has been run before, the setting type is likely changed */ - - ret = settings_type("v1", &stype); - if (ret < 0) - { - printf("Failed to get settings type: %d\n", ret); - goto end; - } - - if (stype == SETTING_STRING) - { - ret = settings_get("v1", SETTING_STRING, &readstr, sizeof(readstr)); - if (ret < 0) - { - printf("settings retrieve failed: %d\n", ret); - goto end; - } - - printf("Retrieved settings value (v1) with value:%s\n", readstr); - } - else - { - ret = settings_get("v1", SETTING_INT, &testval, - CONFIG_SYSTEM_SETTINGS_VALUE_SIZE); - if (ret < 0) - { - printf("settings retrieve failed: %d\n", ret); - goto end; - } - - printf("Retrieved settings value (v1) with value:%d\n", testval); - } - - printf("Trying to (re)create a setting that already exists (v1)\n"); - - testval = 0xa5a5; - ret = settings_create("v1", SETTING_INT, testval); - if (ret == -EACCES) - { - printf("Deliberate fail: setting exists! Error: %d\n", ret); - } - else if (ret < 0) - { - printf("settings create failed: %d\n", ret); - goto end; - } - - ret = settings_type("v1", &stype); - if (ret < 0) - { - printf("failed to read settings type: %d\n", ret); - goto end; - } - - printf("Retrieved setting type is: %d\n", stype); - - printf("Trying to change setting (v1) to integer type\n"); - ret = settings_set("v1", SETTING_INT, &testval); - if (ret < 0) - { - printf("Deliberate fail: settings change invalid: %d\n", ret); - } - - ret = settings_get("v2", SETTING_INT, &testval); - if (ret < 0) - { - printf("Deliberate fail: non-existent setting requested. Error:%d\n", - ret); - } - - printf("Trying to change setting (v1) from int to string: %s\n", teststr); - ret = settings_set("v1", SETTING_STRING, &teststr); - if (ret < 0) - { - printf("Deliberate fail: settings change invalid: %d\n", ret); - } - - printf("Creating a string settings value (s1):%s\n", teststr); - ret = settings_create("s1", SETTING_STRING, teststr); - if (ret < 0) - { - printf("settings changed failed: %d\n", ret); - goto end; - } - - ret = settings_get("s1", SETTING_STRING, &readstr, sizeof(readstr)); - if (ret < 0) - { - printf("settings retrieve failed: %d\n", ret); - goto end; - } - - printf("Retrieved string settings value (s1) with value:%s\n", - readstr); - - FAR struct in_addr save_ip; - FAR struct in_addr load_ip; - save_ip.s_addr = 0xc0a86401; - - printf("Changing setting to an IP value (s1) with value:%d.%d.%d.%d\n", - (int)(save_ip.s_addr >> 24) & 0xff, - (int)(save_ip.s_addr >> 16) & 0xff, - (int)(save_ip.s_addr >> 8) & 0xff, - (int)(save_ip.s_addr >> 0) & 0xff); - ret = settings_set("s1", SETTING_IP_ADDR, &save_ip); - if (ret < 0) - { - printf("IP address settings create failed: %d\n", ret); - goto end; - } - - ret = settings_get("s1", SETTING_IP_ADDR, &load_ip); - if (ret < 0) - { - printf("IP address settings retrieve failed: %d\n", ret); - goto end; - } - - printf("Retrieved IP address settings value (s1) with value:0x%08lx\n", - load_ip.s_addr); - - printf("syncing storages\n"); - ret = settings_sync(true); /* wait for cached saves to complete - * (will only be done if caching enabled). - */ - if (ret < 0) - { - printf("Failed to sync storages: %d\n", ret); - goto end; - } - -end: - printf("exiting settings example app\n"); - fflush(stdout); - - return ret; -} diff --git a/examples/shm_test/CMakeLists.txt b/examples/shm_test/CMakeLists.txt deleted file mode 100644 index 19f5f8495..000000000 --- a/examples/shm_test/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# ############################################################################## -# apps/examples/shm_test/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_SHM) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_SHM_PROGNAME} - SRCS - shm_main.c - STACKSIZE - ${CONFIG_EXAMPLES_SHM_STACKSIZE} - PRIORITY - ${CONFIG_EXAMPLES_SHM_PRIORITY}) -endif() diff --git a/examples/shm_test/Kconfig b/examples/shm_test/Kconfig deleted file mode 100644 index 85c9957ec..000000000 --- a/examples/shm_test/Kconfig +++ /dev/null @@ -1,30 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config EXAMPLES_SHM - tristate "SHM example" - default n - depends on FS_SHMFS - ---help--- - Enable the SHM example which has an shm producer and consumer - -if EXAMPLES_SHM - -config EXAMPLES_SHM_PROGNAME - string "Program name" - default "shm_test" - ---help--- - This is the name of the program that will be used when the NSH ELF - program is installed. - -config EXAMPLES_SHM_PRIORITY - int "SHM task priority" - default 100 - -config EXAMPLES_SHM_STACKSIZE - int "SHM stack size" - default DEFAULT_TASK_STACKSIZE - -endif diff --git a/examples/shm_test/Make.defs b/examples/shm_test/Make.defs deleted file mode 100644 index a5e5e62ca..000000000 --- a/examples/shm_test/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/examples/shm_test/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_EXAMPLES_SHM),) -CONFIGURED_APPS += $(APPDIR)/examples/shm_test -endif diff --git a/examples/shm_test/Makefile b/examples/shm_test/Makefile deleted file mode 100644 index 1f1d900a0..000000000 --- a/examples/shm_test/Makefile +++ /dev/null @@ -1,44 +0,0 @@ -############################################################################ -# apps/examples/shm_test/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -# SHM test built-in application info - -PROGNAME = $(CONFIG_EXAMPLES_SHM_PROGNAME) -PRIORITY = $(CONFIG_EXAMPLES_SHM_PRIORITY) -STACKSIZE = $(CONFIG_EXAMPLES_SHM_STACKSIZE) -MODULE = $(CONFIG_EXAMPLES_SHM) - -# SHM test Example - -MAINSRC = shm_main.c - -# Build with WebAssembly when CONFIG_INTERPRETERS_WAMR is enabled - -WASM_BUILD = both - -# Mode of WebAssembly Micro Runtime - -WAMR_MODE = AOT - -include $(APPDIR)/Application.mk diff --git a/examples/shm_test/shm_main.c b/examples/shm_test/shm_main.c deleted file mode 100644 index e93758d59..000000000 --- a/examples/shm_test/shm_main.c +++ /dev/null @@ -1,118 +0,0 @@ -/**************************************************************************** - * apps/examples/shm_test/shm_main.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <fcntl.h> -#include <nuttx/config.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <sys/mman.h> -#include <sys/shm.h> -#include <sys/stat.h> -#include <unistd.h> - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -void shm_producer(const int shm_size, const char *shm_name) -{ - /* Write Hello World! to shared memory */ - - const char *message_0 = "Hello"; - const char *message_1 = "World!"; - - /* Shared memory file descriptor */ - - int shm_fd; - - /* Pointer to shared memory object */ - - void *ptr; - - /* Create the shared memory object */ - - shm_fd = shm_open(shm_name, O_CREAT | O_RDWR, 0666); - - /* Configure the size of the shared memory object */ - - ftruncate(shm_fd, shm_size); - - /* Memory map the shared memory object */ - - ptr = mmap(0, shm_size, PROT_WRITE, MAP_SHARED, shm_fd, 0); - - /* Write to the shared memory object */ - - sprintf(ptr, "%s", message_0); - - ptr += strlen(message_0); - sprintf(ptr, "%s", message_1); - ptr += strlen(message_1); - - printf("Producer Wrote to SHM: %s%s\n", message_0, message_1); -} - -void shm_consumer(const int shm_size, const char *shm_name) -{ - /* Shared memory file descriptor */ - - int shm_fd; - - /* Pointer to shared memory object */ - - void *ptr; - - /* Open the shared memory object */ - - shm_fd = shm_open(shm_name, O_RDONLY, 0666); - - /* Memory map the shared memory object */ - - ptr = mmap(0, shm_size, PROT_READ, MAP_SHARED, shm_fd, 0); - - /* Read from the shared memory object */ - - printf("Consumer Read from SHM: %s\n", (char *)ptr); - - /* Remove the shared memory object */ - - shm_unlink(shm_name); -} - -/**************************************************************************** - * shm_main - ****************************************************************************/ - -int main(int argc, FAR char *argv[]) -{ - const int shm_size = 2048; - const char *shm_name = "OS"; - - shm_producer(shm_size, shm_name); - shm_consumer(shm_size, shm_name); - return 0; -} diff --git a/examples/sht3x/CMakeLists.txt b/examples/sht3x/CMakeLists.txt deleted file mode 100644 index 8c22be54f..000000000 --- a/examples/sht3x/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# ############################################################################## -# apps/examples/sht3x/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_SHT3X) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_SHT3X_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_SHT3X_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_SHT3X_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_SHT3X} - SRCS - sht3x_main.c) -endif() diff --git a/examples/sht3x/Make.defs b/examples/sht3x/Make.defs index e4bec9832..cf752dca4 100644 --- a/examples/sht3x/Make.defs +++ b/examples/sht3x/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/sht3x/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/sht3x/Makefile b/examples/sht3x/Makefile index 6acd0fe07..0731f9eec 100644 --- a/examples/sht3x/Makefile +++ b/examples/sht3x/Makefile @@ -1,7 +1,5 @@ ############################################################################ -# apps/examples/sht3x/Makefile -# -# SPDX-License-Identifier: Apache-2.0 +# apps/examples/sht3x/Make.defs # # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with @@ -22,7 +20,7 @@ include $(APPDIR)/Make.defs -# SHT3X built-in application info +# Hello, World! built-in application info PROGNAME = $(CONFIG_EXAMPLES_SHT3X_PROGNAME) PRIORITY = $(CONFIG_EXAMPLES_SHT3X_PRIORITY) diff --git a/examples/sht3x/sht3x_main.c b/examples/sht3x/sht3x_main.c index 078979c7a..357e15f1a 100644 --- a/examples/sht3x/sht3x_main.c +++ b/examples/sht3x/sht3x_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/sht3x/sht3x_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -25,13 +23,12 @@ ****************************************************************************/ #include <nuttx/config.h> +#include <stdio.h> #include <sys/types.h> #include <sys/ioctl.h> #include <sys/stat.h> #include <fcntl.h> -#include <stdio.h> -#include <unistd.h> #include <nuttx/sensors/ioctl.h> #include <nuttx/sensors/sht3x.h> diff --git a/examples/shv-nxboot-updater/Kconfig b/examples/shv-nxboot-updater/Kconfig deleted file mode 100644 index 80ace34ba..000000000 --- a/examples/shv-nxboot-updater/Kconfig +++ /dev/null @@ -1,30 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -menuconfig EXAMPLES_SHV_NXBOOT_UPDATER - bool "Silicon Heaven Firmware updates for NXBoot" - depends on NETUTILS_LIBSHVC && ENABLE_ALL_SIGNALS - default n - ---help--- - Enable the shv-nxboot-updater application. - -if EXAMPLES_SHV_NXBOOT_UPDATER - -config EXAMPLES_SHV_NXBOOT_UPDATER_PROGNAME - string "shv-nxboot-updater App Name" - default "shv_nxboot_updater" - ---help--- - This is the name of the program that will be used when the NSH ELF - program is installed. - -config EXAMPLES_SHV_NXBOOT_UPDATER_PRIORITY - int "shv-nxboot-updater task priority" - default 100 - -config EXAMPLES_SHV_NXBOOT_UPDATER_STACKSIZE - int "shv-nxboot-updater task stack size" - default 4096 - -endif # EXAMPLES_NX_SHV_FWUPDATER diff --git a/examples/shv-nxboot-updater/Make.defs b/examples/shv-nxboot-updater/Make.defs deleted file mode 100644 index 745b86220..000000000 --- a/examples/shv-nxboot-updater/Make.defs +++ /dev/null @@ -1,23 +0,0 @@ -############################################################################ -# apps/examples/shv-nxboot-updater/Make.defs -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_EXAMPLES_SHV_NXBOOT_UPDATER),) -CONFIGURED_APPS += $(APPDIR)/examples/shv-nxboot-updater -endif diff --git a/examples/shv-nxboot-updater/Makefile b/examples/shv-nxboot-updater/Makefile deleted file mode 100644 index 339199a27..000000000 --- a/examples/shv-nxboot-updater/Makefile +++ /dev/null @@ -1,31 +0,0 @@ -############################################################################ -# apps/examples/shv-nxboot-updater/Makefile -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -MODULE = $(CONFIG_EXAMPLES_SHV_NXBOOT_UPDATER) - -PROGNAME += $(CONFIG_EXAMPLES_SHV_NXBOOT_UPDATER_PROGNAME) -PRIORITY += $(CONFIG_EXAMPLES_SHV_NXBOOT_UPDATER_PRIORITY) -STACKSIZE += $(CONFIG_EXAMPLES_SHV_NXBOOT_UPDATER_STACKSIZE) - -MAINSRC += shv_nxboot_updater.c - -include $(APPDIR)/Application.mk diff --git a/examples/shv-nxboot-updater/shv_nxboot_updater.c b/examples/shv-nxboot-updater/shv_nxboot_updater.c deleted file mode 100644 index 0a75cf727..000000000 --- a/examples/shv-nxboot-updater/shv_nxboot_updater.c +++ /dev/null @@ -1,392 +0,0 @@ -/**************************************************************************** - * apps/examples/shv-nxboot-updater/shv_nxboot_updater.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <shv/tree/shv_tree.h> -#include <shv/tree/shv_file_node.h> -#include <shv/tree/shv_connection.h> -#include <shv/tree/shv_methods.h> -#include <shv/tree/shv_clayer_posix.h> -#include <shv/tree/shv_dotdevice_node.h> -#include <shv/tree/shv_dotapp_node.h> - -#include <stdio.h> -#include <signal.h> -#include <time.h> -#include <unistd.h> -#include <stdlib.h> -#include <fcntl.h> -#include <sys/ioctl.h> -#include <semaphore.h> - -#include <nxboot.h> -#include <nuttx/mtd/mtd.h> -#include <sys/boardctl.h> - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -static int shv_nxboot_opener(struct shv_file_node *item); -static int shv_fwstable_confirm(struct shv_con_ctx *shv_ctx, - struct shv_node *item, int rid); -static int shv_fwstable_get(struct shv_con_ctx *shv_ctx, - struct shv_node *item, int rid); -static void quit_handler(int signum); -static void print_help(char *name); - -static struct shv_node *shv_tree_create(void); -static void attention_cb(struct shv_con_ctx *shv_ctx, - enum shv_attention_reason r); - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/* An execution barrier */ - -static sem_t running; - -/* ------------------------- ROOT METHODS --------------------------------- */ - -static const struct shv_method_des * const shv_dev_root_dmap_items[] = -{ - &shv_dmap_item_dir, - &shv_dmap_item_ls, -}; - -static const struct shv_dmap shv_dev_root_dmap = - SHV_CREATE_NODE_DMAP(root, shv_dev_root_dmap_items); - -/* ------------------------- fwstable METHODS ---------------------------- */ - -static const struct shv_method_des shv_dev_fwstable_dmap_item_confirm = -{ - .name = "confirm", - .method = shv_fwstable_confirm -}; - -static const struct shv_method_des shv_dev_fwstable_dmap_item_get = -{ - .name = "get", - .method = shv_fwstable_get -}; - -static const struct shv_method_des * const shv_dev_fwstable_dmap_items[] = -{ - &shv_dev_fwstable_dmap_item_confirm, - &shv_dmap_item_dir, - &shv_dev_fwstable_dmap_item_get, - &shv_dmap_item_ls -}; - -static const struct shv_dmap shv_dev_fwstable_dmap = - SHV_CREATE_NODE_DMAP(dotdevice, shv_dev_fwstable_dmap_items); - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static int shv_fwstable_confirm(struct shv_con_ctx *shv_ctx, - struct shv_node *item, int rid) -{ - shv_unpack_data(&shv_ctx->unpack_ctx, 0, 0); - nxboot_confirm(); - shv_send_empty_response(shv_ctx, rid); - return 0; -} - -static int shv_fwstable_get(struct shv_con_ctx *shv_ctx, - struct shv_node *item, int rid) -{ - shv_unpack_data(&shv_ctx->unpack_ctx, 0, 0); - int ret = nxboot_get_confirm(); - if (ret >= 0) - { - shv_send_int(shv_ctx, rid, ret); - } - else - { - shv_send_error(shv_ctx, rid, SHV_RE_PLATFORM_ERROR, - "nxboot_get_confirm failed"); - } - - return 0; -} - -static int shv_nxboot_opener(struct shv_file_node *item) -{ - struct shv_file_node_fctx *fctx = (struct shv_file_node_fctx *)item->fctx; - if (!(fctx->flags & SHV_FILE_POSIX_BITFLAG_OPENED)) - { - fctx->fd = nxboot_open_update_partition(); - if (fctx->fd < 0) - { - return -1; - } - - fctx->flags |= SHV_FILE_POSIX_BITFLAG_OPENED; - } - - return 0; -} - -static struct shv_node *shv_tree_create(void) -{ - struct shv_node *tree_root; - struct shv_node *fwstable_node; - struct shv_dotdevice_node *dotdevice_node; - struct shv_file_node *fwupdate_node; - struct shv_dotapp_node *dotapp_node; - - struct mtd_geometry_s geometry; - int flash_fd; - flash_fd = nxboot_open_update_partition(); - if (flash_fd < 0) - { - return NULL; - } - - puts("Creating the SHV Tree root"); - tree_root = shv_tree_node_new("", &shv_dev_root_dmap, 0); - if (tree_root == NULL) - { - close(flash_fd); - return NULL; - } - - fwupdate_node = shv_tree_file_node_new("fwUpdate", - &shv_file_node_dmap, 0); - if (fwupdate_node == NULL) - { - close(flash_fd); - free(tree_root); - return NULL; - } - - if (ioctl(flash_fd, MTDIOC_GEOMETRY, - (unsigned long)((uintptr_t)&geometry)) < 0) - { - close(flash_fd); - free(tree_root); - free(fwupdate_node); - return NULL; - } - - fwupdate_node->file_type = SHV_FILE_MTD; - fwupdate_node->file_maxsize = geometry.erasesize * geometry.neraseblocks; - fwupdate_node->file_pagesize = geometry.blocksize; - fwupdate_node->file_erasesize = geometry.erasesize; - - /* Update the fops table in the file node */ - - fwupdate_node->fops.opener = shv_nxboot_opener; - shv_tree_add_child(tree_root, &fwupdate_node->shv_node); - close(flash_fd); - - dotapp_node = shv_tree_dotapp_node_new(&shv_dotapp_dmap, 0); - if (dotapp_node == NULL) - { - free(tree_root); - free(fwupdate_node); - return NULL; - } - - dotapp_node->name = "NuttX shv-libs4c FW Updater"; - dotapp_node->version = "1.0.0"; - - shv_tree_add_child(tree_root, &dotapp_node->shv_node); - - dotdevice_node = shv_tree_dotdevice_node_new(&shv_dotdevice_dmap, 0); - if (dotdevice_node == NULL) - { - free(tree_root); - free(fwupdate_node); - free(dotapp_node); - return NULL; - } - - dotdevice_node->name = "SHV Compatible Device"; - dotdevice_node->serial_number = "0xDEADBEEF"; - dotdevice_node->version = "0.1.0"; - shv_tree_add_child(tree_root, &dotdevice_node->shv_node); - - fwstable_node = shv_tree_node_new("fwStable", &shv_dev_fwstable_dmap, 0); - if (fwstable_node == NULL) - { - free(tree_root); - free(fwupdate_node); - free(dotapp_node); - return NULL; - } - - shv_tree_add_child(tree_root, fwstable_node); - - return tree_root; -} - -static void quit_handler(int signum) -{ - puts("Stopping SHV FW Updater!"); - sem_post(&running); -} - -static void print_help(char *name) -{ - printf("%s: [OPTIONS]\n", name); - puts("SHV Firmware Updater for NXBoot"); - puts("Showcases the file handling capabilities and usage with NXBoot."); - puts("Mandatory options:"); - puts(" -m <mount-point>: mount point in the SHV broker"); - puts(" -i <ip-addr>: IPv4 address of the SHV broker"); - puts(" -p <passwd>: password to access the SHV broker"); - puts(" -t <port>: TCP/IP port of the SHV broker"); - puts(" -u <user>: user to access the SHV broker"); - puts("Nonmandatory options:"); - puts(" -h: print help"); -} - -static void attention_cb(struct shv_con_ctx *shv_ctx, - enum shv_attention_reason r) -{ - if (r == SHV_ATTENTION_ERROR) - { - printf("Error occurred in SHV, the reason is: %s\n", - shv_errno_str(shv_ctx)); - sem_post(&running); - } -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: main - ****************************************************************************/ - -int main(int argc, char *argv[]) -{ - /* Define the SHV Communication parameters */ - - int ret; - int opt; - struct shv_connection connection; - struct shv_node *tree_root; - struct shv_con_ctx *ctx; - const int comthrd_prio = CONFIG_EXAMPLES_SHV_NXBOOT_UPDATER_PRIORITY - 1; - - const char *user = NULL; - const char *passwd = NULL; - const char *mount = NULL; - const char *ip = NULL; - const char *port_s = NULL; - int port = 0; - - /* Initialize the communication. But only if parameters are passed. */ - - while ((opt = getopt(argc, argv, "hm:i:p:t:u:")) != -1) - { - switch (opt) - { - case 'h': - print_help(argv[0]); - return 0; - case 'm': - mount = optarg; - break; - case 'i': - ip = optarg; - break; - case 'p': - passwd = optarg; - break; - case 't': - port_s = optarg; - port = atoi(port_s); - break; - case 'u': - user = optarg; - break; - case '?': - print_help(argv[0]); - return 1; - } - } - - if (!user || !passwd || !mount || !ip || !port_s) - { - print_help(argv[0]); - return 1; - } - - shv_connection_init(&connection, SHV_TLAYER_TCPIP); - connection.broker_user = user; - connection.broker_password = passwd; - connection.broker_mount = mount; - connection.reconnect_period = 10; - connection.reconnect_retries = 0; - if (shv_connection_tcpip_init(&connection, ip, port) < 0) - { - fprintf(stderr, "Have you supplied valid params to shv_connection?\n"); - return 1; - } - - puts("SHV Connection Init OK"); - - tree_root = shv_tree_create(); - if (tree_root == NULL) - { - fprintf(stderr, "Can't create the SHV tree."); - return 1; - } - - puts("SHV Tree created!"); - ctx = shv_com_init(tree_root, &connection, attention_cb); - if (ctx == NULL) - { - fprintf(stderr, "Can't establish the comm with the broker.\n"); - return 1; - } - - ret = shv_create_process_thread(comthrd_prio, ctx); - if (ret < 0) - { - fprintf(stderr, "%s\n", shv_errno_str(ctx)); - free(ctx); - return 1; - } - - sem_init(&running, 0, 0); - signal(SIGTERM, quit_handler); - - sem_wait(&running); - - puts("Close the communication"); - shv_com_destroy(ctx); - shv_tree_destroy(tree_root); - - return 0; -} diff --git a/examples/shv-nxboot-updater/update-script/.gitignore b/examples/shv-nxboot-updater/update-script/.gitignore deleted file mode 100644 index ed8ebf583..000000000 --- a/examples/shv-nxboot-updater/update-script/.gitignore +++ /dev/null @@ -1 +0,0 @@ -__pycache__ \ No newline at end of file diff --git a/examples/shv-nxboot-updater/update-script/gui.py b/examples/shv-nxboot-updater/update-script/gui.py deleted file mode 100755 index 0298c2c07..000000000 --- a/examples/shv-nxboot-updater/update-script/gui.py +++ /dev/null @@ -1,236 +0,0 @@ -#!/usr/bin/env python3 - -############################################################################ -# apps/examples/shv-nxboot-updater/update-script/gui.py -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -import argparse -import asyncio -import logging -import sys -from typing import Any - -from PyQt6.QtCore import Qt, QThread -from PyQt6.QtWidgets import ( - QApplication, - QComboBox, - QDialog, - QGridLayout, - QLabel, - QLineEdit, - QProgressBar, - QPushButton, -) -from shvconfirm import shv_confirm -from shvflasher import shv_flasher - -log_levels = ( - logging.DEBUG, - logging.INFO, - logging.WARNING, - logging.ERROR, - logging.CRITICAL, -) - -PROGRESS_STYLE = """ -QProgressBar{ - border: 2px solid grey; - border-radius: 5px; - text-align: center -} - -QProgressBar::chunk { - background-color: green; -} -""" - - -def parse_args() -> argparse.Namespace: - """Parse passed arguments and return result.""" - parser = argparse.ArgumentParser( - description="GUI application for NuttX firmware flash over SHV" - ) - parser.add_argument( - "-v", - action="count", - default=0, - help="Increase verbosity level of logging", - ) - parser.add_argument( - "-q", - action="count", - default=0, - help="Decrease verbosity level of logging", - ) - parser.add_argument( - "-i", - "--image", - dest="image", - type=str, - default="nuttx.nximg", - help="Image path", - ) - parser.add_argument( - "-m", - "--mount", - dest="target_mount", - type=str, - default="test/nuttxdevice", - help="Target mount location on the SHV broker", - ) - parser.add_argument( - "-s", - "--server", - dest="shv_server", - type=str, - default="tcp://xyz@127.0.0.1:3755?password=xyz", - help="SHV server/broker", - ) - return parser.parse_args() - - -async def flashThreadAsync( - url: str, img: str, path_to_root, progress_bar: QProgressBar -) -> None: - queue: asyncio.Queue = asyncio.Queue() - task = asyncio.create_task(shv_flasher(url, img, path_to_root, queue)) - - while True: - progressVal = await queue.get() - progress_bar.setValue(progressVal) - - if progressVal == 100: - break - - await task - - -class flashThread(QThread): - def __init__( - self, - parent: Any, - url: str, - img: str, - path_to_root: str, - progress_bar: QProgressBar, - ) -> None: - QThread.__init__(self, parent) - self.url = url - self.img = img - self.path_to_root = path_to_root - self.progress_bar = progress_bar - - def run(self) -> None: - asyncio.run( - flashThreadAsync(self.url, self.img, self.path_to_root, self.progress_bar) - ) - - -class confirmThread(QThread): - def __init__(self, parent: Any, url: str, path_to_root: str) -> None: - QThread.__init__(self, parent) - self.url = url - self.path_to_root = path_to_root - - def run(self) -> None: - asyncio.run(shv_confirm(self.url, self.path_to_root)) - - -class ShvFlasherGui(QDialog): - def __init__(self, image=None, target_mount=None, shv_server=None) -> None: - super().__init__() - self.setWindowModality(Qt.WindowModality.ApplicationModal) - self.setWindowTitle("NuttX Firmware Flasher over SHV") - - lbl_shv_url = QLabel("SHV RCP URL") - self.set_interface(shv_server) - - lbl_image = QLabel("Image path") - self.image = QLineEdit(image if image is not None else "", self) - - lbl_target_mount = QLabel("Device mount") - self.target_mount = QLineEdit( - target_mount if target_mount is not None else "", self - ) - - self.progress_bar = QProgressBar(self) - self.progress_bar.setValue(0) - self.progress_bar.setStyleSheet(PROGRESS_STYLE) - - pb_flash = QPushButton("FLASH") - pb_confirm = QPushButton("CONFIRM") - pb_exit = QPushButton("EXIT") - grid = QGridLayout() - - grid.addWidget(lbl_shv_url, 0, 0) - grid.addWidget(self.interface, 0, 1) - grid.addWidget(lbl_image, 1, 0) - grid.addWidget(self.image, 1, 1) - grid.addWidget(lbl_target_mount, 2, 0) - grid.addWidget(self.target_mount, 2, 1) - grid.addWidget(self.progress_bar, 3, 0, 1, 3) - grid.addWidget(pb_flash, 4, 0) - grid.addWidget(pb_confirm, 4, 1) - grid.addWidget(pb_exit, 4, 2) - - pb_flash.clicked.connect(self.do_flash) - pb_confirm.clicked.connect(self.do_confirm) - pb_exit.clicked.connect(self.reject) - - self.setLayout(grid) - - def set_interface(self, shv_server=None) -> None: - self.interface = QComboBox() - self.interface.setEditable(True) - # tcp://user@localhost:3755?password=pass - self.interface.addItems([shv_server if shv_server is not None else ""]) - - def do_flash(self) -> None: - rpc_url = str(self.interface.currentText()) - img_path = str(self.image.text()) - path_to_root = str(self.target_mount.text()) - workerFlash = flashThread( - self, rpc_url, img_path, path_to_root, self.progress_bar - ) - workerFlash.start() - - def do_confirm(self) -> None: - rpc_url = str(self.interface.currentText()) - path_to_root = str(self.target_mount.text()) - worker = confirmThread(self, rpc_url, path_to_root) - worker.start() - - -def main() -> None: - args = parse_args() - logging.basicConfig( - level=log_levels[sorted([1 - args.v + args.q, 0, len(log_levels) - 1])[1]], - format="[%(asctime)s] [%(levelname)s] - %(message)s", - ) - - _ = QApplication(sys.argv) - - dialog = ShvFlasherGui( - image=args.image, target_mount=args.target_mount, shv_server=args.shv_server - ) - dialog.exec() - - -if __name__ == "__main__": - main() diff --git a/examples/shv-nxboot-updater/update-script/requirements.txt b/examples/shv-nxboot-updater/update-script/requirements.txt deleted file mode 100644 index b2c6ea55c..000000000 --- a/examples/shv-nxboot-updater/update-script/requirements.txt +++ /dev/null @@ -1,5 +0,0 @@ -pyshv==0.8.0 -PyQt6 -argparse -asyncio -logging diff --git a/examples/shv-nxboot-updater/update-script/shvconfirm.py b/examples/shv-nxboot-updater/update-script/shvconfirm.py deleted file mode 100644 index b01743483..000000000 --- a/examples/shv-nxboot-updater/update-script/shvconfirm.py +++ /dev/null @@ -1,32 +0,0 @@ -############################################################################ -# apps/examples/shv-nxboot-updater/update-script/shvconfirm.py -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -from shv import RpcUrl, SHVValueClient - - -async def shv_confirm(connection: str, path_to_root: str) -> None: - url = RpcUrl.parse(connection) - client = await SHVValueClient.connect(url) - assert client is not None - - await client.call(f"{path_to_root}/fwStable", "confirm") - - print("FW confirmed.") - await client.disconnect() diff --git a/examples/shv-nxboot-updater/update-script/shvflasher.py b/examples/shv-nxboot-updater/update-script/shvflasher.py deleted file mode 100644 index 8a5be6a96..000000000 --- a/examples/shv-nxboot-updater/update-script/shvflasher.py +++ /dev/null @@ -1,83 +0,0 @@ -############################################################################ -# apps/examples/shv-nxboot-updater/update-script/shvflasher.py -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -import asyncio -import io -import zlib - -from shv import RpcUrl, SHVBytes, SHVValueClient - - -async def shv_flasher( - connection: str, name: str, path_to_root: str, queue: asyncio.Queue | None -) -> None: - url = RpcUrl.parse(connection) - client = await SHVValueClient.connect(url) - assert client is not None - node_name = f"{path_to_root}/fwUpdate" - node_name_dotdevice = f"{path_to_root}/.device" - - res = await client.call(node_name, "stat") - - maxfilesize = res[1] - maxwrite = res[5] - print(f"Received maximum enabled write size {maxwrite}.") - print(f"Received maximum file size is {maxfilesize}") - print(f"Started uploading new firmware {name}... this may take some time.") - size = 0 - with open(name, mode="rb") as f: - # first, compute the CRC from the zlib library - # turns out, NuttX uses the same polynomial - - if queue: - f.seek(0, io.SEEK_END) - size = f.tell() - print(f"File's size is {size}") - f.seek(0, io.SEEK_SET) - transfers = size / maxwrite - - i = 0 - crc = 0 - while data := f.read(maxwrite): - print("Uploading chunk n.", i + 1) - crc = zlib.crc32(data, crc) - offset = i * maxwrite - res = await client.call(node_name, "write", [offset, SHVBytes(data)]) - i += 1 - if queue: - currProgress = (int)((i * 100) / transfers) - queue.put_nowait(currProgress) - - print("Flashing completed!") - - # now get the CRC from the device and reset the device, if OK - res = await client.call(node_name, "crc", [0, size]) - # just to be sure, make it unsigned - res = res & 0xFFFFFFFF - # the result of the CRC is signed, actually, so make reinterpret it as unsigned - print(f"Calculated CRC: {hex(crc)} and received: {hex(res)}") - - if res == crc: - print("Checksum match, perform reset!") - res = await client.call(node_name_dotdevice, "reset") - else: - print("Checksum mismatch!") - - await client.disconnect() diff --git a/examples/shv-test/Kconfig b/examples/shv-test/Kconfig deleted file mode 100644 index 26532c5dd..000000000 --- a/examples/shv-test/Kconfig +++ /dev/null @@ -1,30 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -menuconfig EXAMPLES_SHV_TEST - bool "Silicon Heaven Protocol showcase" - depends on NETUTILS_LIBSHVC - default n - ---help--- - Enable the shv-test application, to show off the capabilities of the SHV protocol. - -if EXAMPLES_SHV_TEST - -config EXAMPLES_SHV_TEST_PROGNAME - string "shv-test App Name" - default "shv_test" - ---help--- - This is the name of the program that will be used when the NSH ELF - program is installed. - -config EXAMPLES_SHV_TEST_PRIORITY - int "shv-test task priority" - default 100 - -config EXAMPLES_SHV_TEST_STACKSIZE - int "shv-test task stack size" - default 4096 - -endif # EXAMPLES_NX_SHV_FWUPDATER diff --git a/examples/shv-test/Makefile b/examples/shv-test/Makefile deleted file mode 100644 index 68a515ad6..000000000 --- a/examples/shv-test/Makefile +++ /dev/null @@ -1,31 +0,0 @@ -############################################################################ -# apps/examples/shv-test/Makefile -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -MODULE = $(CONFIG_EXAMPLES_SHV_TEST_UPDATER) - -PROGNAME += $(CONFIG_EXAMPLES_SHV_TEST_PROGNAME) -PRIORITY += $(CONFIG_EXAMPLES_SHV_TEST_PRIORITY) -STACKSIZE += $(CONFIG_EXAMPLES_SHV_TEST_STACKSIZE) - -MAINSRC += shv_test.c - -include $(APPDIR)/Application.mk diff --git a/examples/shv-test/shv_test.c b/examples/shv-test/shv_test.c deleted file mode 100644 index 1d2d1acf9..000000000 --- a/examples/shv-test/shv_test.c +++ /dev/null @@ -1,448 +0,0 @@ -/**************************************************************************** - * apps/examples/shv-test/shv_test.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <shv/tree/shv_tree.h> -#include <shv/tree/shv_file_node.h> -#include <shv/tree/shv_connection.h> -#include <shv/tree/shv_methods.h> -#include <shv/tree/shv_clayer_posix.h> -#include <shv/tree/shv_dotdevice_node.h> -#include <shv/tree/shv_dotapp_node.h> - -#include <nuttx/config.h> -#include <stdio.h> -#include <signal.h> -#include <semaphore.h> -#include <stdbool.h> - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -static int shv_nuttxtesting_set(struct shv_con_ctx *shv_ctx, - struct shv_node *item, int rid); -static int shv_nuttxtesting_get(struct shv_con_ctx *shv_ctx, - struct shv_node *item, int rid); -static int shv_nuttxtesting_art(struct shv_con_ctx *shv_ctx, - struct shv_node *item, int rid); - -static void quit_handler(int signum); -static void print_help(char *name); - -static struct shv_node *shv_tree_create_dynamically(int mode); -static void attention_cb(struct shv_con_ctx *shv_ctx, - enum shv_attention_reason r); - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/* An execution barrier */ - -static sem_t running; - -/* Testing variable */ - -static int g_testing_val; - -/* ------------------------- ROOT METHODS --------------------------------- */ - -static const struct shv_method_des * const shv_dev_root_dmap_items[] = -{ - &shv_dmap_item_dir, - &shv_dmap_item_ls, -}; - -static const struct shv_dmap shv_dev_root_dmap = - SHV_CREATE_NODE_DMAP(root, shv_dev_root_dmap_items); - -/* ----------------------- nuttxtesting METHODS -------------------------- */ - -static const struct shv_method_des shv_dev_nuttxtesting_dmap_item_set = -{ - .name = "setTestingVal", - .method = shv_nuttxtesting_set -}; - -static const struct shv_method_des shv_dev_nuttxtesting_dmap_item_get = -{ - .name = "getTestingVal", - .method = shv_nuttxtesting_get -}; - -static const struct shv_method_des shv_dev_nuttxtesting_dmap_item_art = -{ - .name = "asciiArt", - .method = shv_nuttxtesting_art -}; - -static const struct shv_method_des *const shv_dev_nuttxtesting_dmap_items[] = -{ - &shv_dev_nuttxtesting_dmap_item_art, - &shv_dmap_item_dir, - &shv_dev_nuttxtesting_dmap_item_get, - &shv_dmap_item_ls, - &shv_dev_nuttxtesting_dmap_item_set -}; - -static const struct shv_dmap shv_dev_nuttxtesting_dmap = - SHV_CREATE_NODE_DMAP(nuttxtesting, shv_dev_nuttxtesting_dmap_items); - -/* ------------------- Static const tree root creation ------------------- */ - -/* First, define all static nodes */ - -static const struct shv_dotdevice_node shv_static_node_dotdevice = -{ - .shv_node = - { - .name = ".device", - .dir = UL_CAST_UNQ1(struct shv_dmap *, &shv_dotdevice_dmap), - .children = - { - .mode = (SHV_NLIST_MODE_GSA | SHV_NLIST_MODE_STATIC) - } - }, - .devops = - { - .reset = shv_dotdevice_node_posix_reset, - .uptime = shv_dotdevice_node_posix_uptime - }, - .name = "SHV Compatible Device", - .serial_number = "0xDEADBEEF", - .version = "0.1.0" -}; - -static const struct shv_dotapp_node shv_static_node_dotapp = -{ - .shv_node = - { - .name = ".app", - .dir = UL_CAST_UNQ1(struct shv_dmap *, &shv_dotapp_dmap), - .children = - { - .mode = (SHV_NLIST_MODE_GSA | SHV_NLIST_MODE_STATIC) - } - }, - .appops = - { - .date = NULL /* As of September 25, date parsing not implemented yet */ - }, - .name = "NuttX libshvc example", - .version = "1.0.0" -}; - -static const struct shv_node shv_static_node_nuttxtesting = -{ - .name = "nuttxTesting", - .dir = UL_CAST_UNQ1(struct shv_dmap *, &shv_dev_nuttxtesting_dmap), - .children = - { - .mode = (SHV_NLIST_MODE_GSA | SHV_NLIST_MODE_STATIC) - } -}; - -/* Now, define tree root's children */ - -const struct shv_node *const shv_static_tree_root_items[] = -{ - &shv_static_node_dotapp.shv_node, - &shv_static_node_dotdevice.shv_node, - &shv_static_node_nuttxtesting -}; - -/* Construct the root. Yes, it's a bit cumbersome, - * but an automated code generator should have no problem with this! - */ - -const struct shv_node shv_static_tree_root = -{ - .dir = UL_CAST_UNQ1(struct shv_dmap *, &shv_dev_root_dmap), - .children = - { - .mode = (SHV_NLIST_MODE_GSA | SHV_NLIST_MODE_STATIC), - .list = - { - .gsa = - { - .root = - { - .items = (void **)shv_static_tree_root_items, - .count = sizeof(shv_static_tree_root_items) / - sizeof(shv_static_tree_root_items[0]), - .alloc_count = 0, - } - } - } - } -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static int shv_nuttxtesting_set(struct shv_con_ctx *shv_ctx, - struct shv_node *item, int rid) -{ - shv_unpack_data(&shv_ctx->unpack_ctx, &g_testing_val, 0); - printf("Testing val set to %d\n", g_testing_val); - shv_send_empty_response(shv_ctx, rid); - return 0; -} - -static int shv_nuttxtesting_get(struct shv_con_ctx *shv_ctx, - struct shv_node *item, int rid) -{ - shv_unpack_data(&shv_ctx->unpack_ctx, 0, 0); - shv_send_int(shv_ctx, rid, g_testing_val); - return 0; -} - -static int shv_nuttxtesting_art(struct shv_con_ctx *shv_ctx, - struct shv_node *item, int rid) -{ - /* Generated from https://budavariam.github.io/asciiart-text/ */ - - shv_unpack_data(&shv_ctx->unpack_ctx, 0, 0); - puts(" ____ _ ___ __"); - puts(" / __ || | | \\ \\ / /"); - puts(" \\___ \\| |_| |\\ \\ / / "); - puts(" ___) | _ | \\ V / "); - puts(" |____/|_| |_| \\_/ "); - shv_send_int(shv_ctx, rid, 0); - return 0; -} - -static struct shv_node *shv_tree_create_dynamically(int mode) -{ - struct shv_node *tree_root; - struct shv_dotapp_node *dotapp_node; - struct shv_node *nuttxtesting_node; - struct shv_dotdevice_node *dotdevice_node; - - tree_root = shv_tree_node_new("", &shv_dev_root_dmap, mode); - if (tree_root == NULL) - { - return NULL; - } - - dotapp_node = shv_tree_dotapp_node_new(&shv_dotapp_dmap, mode); - if (dotapp_node == NULL) - { - free(tree_root); - return NULL; - } - - dotapp_node->name = "NuttX libshvc example"; - dotapp_node->version = "1.0.0"; - - shv_tree_add_child(tree_root, &dotapp_node->shv_node); - - dotdevice_node = shv_tree_dotdevice_node_new(&shv_dotdevice_dmap, mode); - if (dotdevice_node == NULL) - { - free(tree_root); - free(dotapp_node); - return NULL; - } - - dotdevice_node->name = "SHV Compatible Device"; - dotdevice_node->serial_number = "0xDEADBEEF"; - dotdevice_node->version = "0.1.0"; - shv_tree_add_child(tree_root, &dotdevice_node->shv_node); - - nuttxtesting_node = shv_tree_node_new("nuttxTesting", - &shv_dev_nuttxtesting_dmap, mode); - if (nuttxtesting_node == NULL) - { - free(tree_root); - free(dotapp_node); - free(dotdevice_node); - return NULL; - } - - shv_tree_add_child(tree_root, nuttxtesting_node); - - return tree_root; -} - -static void quit_handler(int signum) -{ - puts("Stopping SHV FW Updater!"); - sem_post(&running); -} - -static void print_help(char *name) -{ - printf("%s: [OPTIONS]\n", name); - puts("Silicon Heaven NuttX example"); - puts("Showcases the tree creation."); - puts("Mandatory options:"); - puts(" -a <0-2>: chooses the tree alloc type:"); - puts(" 0: GAVL"); - puts(" 1: GSA"); - puts(" 2: GSA_STATIC: GSA with .rodata placed nodes"); - puts(" -m <mount-point>: mount point in the SHV broker"); - puts(" -i <ip-addr>: IPv4 address of the SHV broker"); - puts(" -p <passwd>: password to access the SHV broker"); - puts(" -t <port>: TCP/IP port of the SHV broker"); - puts(" -u <user>: user to access the SHV broker"); - puts("Nonmandatory options:"); - puts(" -h: print help"); -} - -static void attention_cb(struct shv_con_ctx *shv_ctx, - enum shv_attention_reason r) -{ - if (r == SHV_ATTENTION_ERROR) - { - printf("Error occurred in SHV, the reason is: %s\n", - shv_errno_str(shv_ctx)); - sem_post(&running); - } -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: main - ****************************************************************************/ - -int main(int argc, char *argv[]) -{ - /* Define the SHV Communication parameters */ - - int ret; - int opt; - struct shv_connection connection; - const struct shv_node *tree_root; - struct shv_con_ctx *ctx; - int alloc_mode = SHV_NLIST_MODE_GAVL; - const char *user = NULL; - const char *passwd = NULL; - const char *mount = NULL; - const char *ip = NULL; - const char *port_s = NULL; - int port = 0; - - /* Initialize the communication. But only if parameters are passed. */ - - while ((opt = getopt(argc, argv, "a:hm:i:p:t:u:")) != -1) - { - switch (opt) - { - case 'a': - alloc_mode = atoi(optarg); - break; - case 'h': - print_help(argv[0]); - return 0; - case 'm': - mount = optarg; - break; - case 'i': - ip = optarg; - break; - case 'p': - passwd = optarg; - break; - case 't': - port_s = optarg; - port = atoi(port_s); - break; - case 'u': - user = optarg; - break; - case '?': - print_help(argv[0]); - return 1; - } - } - - if (!user || !passwd || !mount || !ip || !port_s) - { - print_help(argv[0]); - return 1; - } - - shv_connection_init(&connection, SHV_TLAYER_TCPIP); - connection.broker_user = user; - connection.broker_password = passwd; - connection.broker_mount = mount; - connection.reconnect_period = 10; - connection.reconnect_retries = 0; - if (shv_connection_tcpip_init(&connection, ip, port) < 0) - { - fprintf(stderr, "Have you supplied valid params to shv_connection?\n"); - return 1; - } - - puts("SHV Connection Init OK"); - - if (alloc_mode != SHV_NLIST_MODE_STATIC) - { - tree_root = shv_tree_create_dynamically(alloc_mode); - if (tree_root == NULL) - { - fprintf(stderr, "Can't create the SHV tree."); - return 1; - } - } - else - { - tree_root = &shv_static_tree_root; - } - - puts("SHV Tree created!"); - ctx = shv_com_init((struct shv_node *)tree_root, &connection, - attention_cb); - if (ctx == NULL) - { - fprintf(stderr, "Can't establish the comm with the broker.\n"); - return 1; - } - - ret = shv_create_process_thread(99, ctx); - if (ret < 0) - { - fprintf(stderr, "%s\n", shv_errno_str(ctx)); - free(ctx); - return 1; - } - - sem_init(&running, 0, 0); - signal(SIGTERM, quit_handler); - - sem_wait(&running); - - puts("Close the communication"); - shv_com_destroy(ctx); - shv_tree_destroy(tree_root); - - return 0; -} diff --git a/examples/slcd/CMakeLists.txt b/examples/slcd/CMakeLists.txt deleted file mode 100644 index 280cabdb6..000000000 --- a/examples/slcd/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# ############################################################################## -# apps/examples/slcd/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_SLCD) - nuttx_add_application( - NAME - slcd - STACKSIZE - ${CONFIG_DEFAULT_TASK_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_SLCD} - SRCS - slcd_main.c) -endif() diff --git a/examples/slcd/Kconfig b/examples/slcd/Kconfig index c55478b33..98b25c5da 100644 --- a/examples/slcd/Kconfig +++ b/examples/slcd/Kconfig @@ -6,7 +6,6 @@ config EXAMPLES_SLCD tristate "Segment LCD test" default n - depends on SLCD ---help--- Enables a simple test of an alphanumer, segment LCD diff --git a/examples/slcd/Make.defs b/examples/slcd/Make.defs index 24c71d0ad..5346c20df 100644 --- a/examples/slcd/Make.defs +++ b/examples/slcd/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/slcd/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/slcd/Makefile b/examples/slcd/Makefile index 830fa2ead..8e3651ffb 100644 --- a/examples/slcd/Makefile +++ b/examples/slcd/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/slcd/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/slcd/slcd_main.c b/examples/slcd/slcd_main.c index e7aedd0c0..34b1dd6fb 100644 --- a/examples/slcd/slcd_main.c +++ b/examples/slcd/slcd_main.c @@ -1,7 +1,5 @@ /**************************************************************************** - * apps/examples/slcd/slcd_main.c - * - * SPDX-License-Identifier: Apache-2.0 + * apps/examples/clcd/slcd_main.c * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -33,7 +31,6 @@ #include <string.h> #include <fcntl.h> #include <errno.h> -#include <unistd.h> #include <nuttx/lcd/slcd_ioctl.h> #include <nuttx/lcd/slcd_codec.h> @@ -272,7 +269,7 @@ int main(int argc, FAR char *argv[]) /* Initialize the output stream */ memset(priv, 0, sizeof(struct slcd_test_s)); - priv->stream.putc = slcd_putc; + priv->stream.put = slcd_putc; #ifdef CONFIG_STDIO_LINEBUFFER priv->stream.flush = slcd_flush; #endif diff --git a/examples/smf/CMakeLists.txt b/examples/smf/CMakeLists.txt deleted file mode 100644 index bba48ca02..000000000 --- a/examples/smf/CMakeLists.txt +++ /dev/null @@ -1,18 +0,0 @@ -# ############################################################################## -# apps/examples/hsm_psicc2/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# ############################################################################## - -if(CONFIG_EXAMPLES_SMF) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_SMF_PROGNAME} - SRCS - smf_main.c - hsm_psicc2_thread.c - STACKSIZE - ${CONFIG_EXAMPLES_SMF_STACKSIZE} - PRIORITY - ${CONFIG_EXAMPLES_SMF_PRIORITY}) -endif() diff --git a/examples/smf/Kconfig b/examples/smf/Kconfig deleted file mode 100644 index 8d8efc1f7..000000000 --- a/examples/smf/Kconfig +++ /dev/null @@ -1,37 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config EXAMPLES_SMF - tristate "State Machine Framework PSICC2 demo (HSM)" - default n - depends on NSH_BUILTIN_APPS - depends on SYSTEM_SMF - depends on SYSTEM_SMF_ANCESTOR_SUPPORT - depends on SYSTEM_SMF_INITIAL_TRANSITION - -if EXAMPLES_SMF - -config EXAMPLES_SMF_PROGNAME - string "Program name" - default "hsm_psicc2" - -config EXAMPLES_SMF_PRIORITY - int "Priority" - default 100 - -config EXAMPLES_SMF_STACKSIZE - int "Stack size" - default 2048 - -config EXAMPLES_SMF_EVENT_QUEUE_SIZE - int "Event queue size" - default 10 - -config EXAMPLES_SMF_MQ_NAME - string "Message queue name" - default "/hsm_psicc2_mq" - -endif - diff --git a/examples/smf/Make.defs b/examples/smf/Make.defs deleted file mode 100644 index 00be28079..000000000 --- a/examples/smf/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/examples/hello/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_EXAMPLES_SMF),) -CONFIGURED_APPS += $(APPDIR)/examples/smf -endif diff --git a/examples/smf/Makefile b/examples/smf/Makefile deleted file mode 100644 index 2fd9309c1..000000000 --- a/examples/smf/Makefile +++ /dev/null @@ -1,37 +0,0 @@ -############################################################################ -# apps/examples/hsm_psicc2/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -# HSM PSICC2 (SMF demo) built-in application info - -PROGNAME = $(CONFIG_EXAMPLES_SMF_PROGNAME) -PRIORITY = $(CONFIG_EXAMPLES_SMF_PRIORITY) -STACKSIZE = $(CONFIG_EXAMPLES_SMF_STACKSIZE) -MODULE = $(CONFIG_EXAMPLES_SMF) - -# HSM PSICC2 Example - -MAINSRC = smf_main.c -CSRCS += hsm_psicc2_thread.c - -include $(APPDIR)/Application.mk diff --git a/examples/smf/hsm_psicc2_thread.c b/examples/smf/hsm_psicc2_thread.c deleted file mode 100644 index e457969e1..000000000 --- a/examples/smf/hsm_psicc2_thread.c +++ /dev/null @@ -1,626 +0,0 @@ -/**************************************************************************** - * apps/examples/smf/hsm_psicc2_thread.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright (c) 2024 Glenn Andrews - * State Machine example copyright (c) Miro Samek - * - * Implementation of the statechart in Figure 2.11 of - * Practical UML Statecharts in C/C++, 2nd Edition by Miro Samek - * https://www.state-machine.com/psicc2 - * Used with permission of the author. - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <errno.h> -#include <fcntl.h> -#include <mqueue.h> -#include <stdbool.h> -#include <stdio.h> -#include <string.h> -#include <sys/stat.h> -#include <unistd.h> - -#include <system/smf.h> - -#include "hsm_psicc2_thread.h" - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -struct s_object -{ - struct smf_ctx ctx; /* MUST be first (matches SMF_CTX(obj)) */ - struct hsm_psicc2_event event; - int foo; -}; - -enum demo_states -{ - STATE_INITIAL, - STATE_S, - STATE_S1, - STATE_S2, - STATE_S11, - STATE_S21, - STATE_S211 -}; - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static struct s_object s_obj; -static bool g_started; -static const struct smf_state demo_states[]; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * STATE_INITIAL - ****************************************************************************/ - -static void initial_entry(void *o) -{ - struct s_object *obj = (struct s_object *)o; - - printf("[psicc2] %s\n", __func__); - obj->foo = false; -} - -static enum smf_state_result initial_run(void *o) -{ - (void)o; - - printf("[psicc2] %s\n", __func__); - return SMF_EVENT_PROPAGATE; -} - -static void initial_exit(void *o) -{ - (void)o; - - printf("[psicc2] %s\n", __func__); -} - -/**************************************************************************** - * STATE_S - ****************************************************************************/ - -static void s_entry(void *o) -{ - (void)o; - - printf("[psicc2] %s", __func__); -} - -static enum smf_state_result s_run(void *o) -{ - struct s_object *obj = (struct s_object *)o; - - printf("[psicc2] %s\n", __func__); - - switch (obj->event.event_id) - { - case EVENT_E: - printf("[psicc2] %s received EVENT_E", __func__); - smf_set_state(SMF_CTX(obj), &demo_states[STATE_S11]); - break; - - case EVENT_I: - if (obj->foo) - { - printf("[psicc2] %s received EVENT_I and set foo false\n", - __func__); - obj->foo = false; - } - else - { - printf("[psicc2] %s received EVENT_I and did nothing\n", - __func__); - } - - return SMF_EVENT_HANDLED; - - case EVENT_TERMINATE: - printf("[psicc2] %s received EVENT_TERMINATE. Terminating\n", - __func__); - smf_set_terminate(SMF_CTX(obj), -1); - break; - - default: - break; - } - - return SMF_EVENT_PROPAGATE; -} - -static void s_exit(void *o) -{ - (void)o; - - printf("%s", __func__); -} - -/**************************************************************************** - * STATE_S1 - ****************************************************************************/ - -static void s1_entry(void *o) -{ - (void)o; - - printf("%s", __func__); -} - -static enum smf_state_result s1_run(void *o) -{ - struct s_object *obj = (struct s_object *)o; - - printf("[psicc2] %s\n", __func__); - - switch (obj->event.event_id) - { - case EVENT_A: - printf("[psicc2] %s received EVENT_A\n", __func__); - smf_set_state(SMF_CTX(obj), &demo_states[STATE_S1]); - break; - - case EVENT_B: - printf("[psicc2] %s received EVENT_B\n", __func__); - smf_set_state(SMF_CTX(obj), &demo_states[STATE_S11]); - break; - - case EVENT_C: - printf("[psicc2] %s received EVENT_C\n", __func__); - smf_set_state(SMF_CTX(obj), &demo_states[STATE_S2]); - break; - - case EVENT_D: - if (!obj->foo) - { - printf("[psicc2] %s received EVENT_D and acted on it\n", - __func__); - obj->foo = true; - smf_set_state(SMF_CTX(obj), &demo_states[STATE_S]); - } - else - { - printf("[psicc2] %s received EVENT_D and ignored it\n", - __func__); - } - break; - - case EVENT_F: - printf("[psicc2] %s received EVENT_F\n", __func__); - smf_set_state(SMF_CTX(obj), &demo_states[STATE_S211]); - break; - - case EVENT_I: - printf("[psicc2] %s received EVENT_I\n", __func__); - return SMF_EVENT_HANDLED; - - default: - break; - } - - return SMF_EVENT_PROPAGATE; -} - -static void s1_exit(void *o) -{ - (void)o; - - printf("[psicc2] %s\n", __func__); -} - -/**************************************************************************** - * STATE_S11 - ****************************************************************************/ - -static void s11_entry(void *o) -{ - (void)o; - - printf("[psicc2] %s\n", __func__); -} - -static enum smf_state_result s11_run(void *o) -{ - struct s_object *obj = (struct s_object *)o; - - printf("[psicc2] %s\n", __func__); - - switch (obj->event.event_id) - { - case EVENT_D: - if (obj->foo) - { - printf("[psicc2] %s received EVENT_D and acted upon it\n", - __func__); - obj->foo = false; - smf_set_state(SMF_CTX(obj), &demo_states[STATE_S1]); - } - else - { - printf("[psicc2] %s received EVENT_D and ignored it\n", - __func__); - } - break; - - case EVENT_G: - printf("[psicc2] %s received EVENT_G\n", __func__); - smf_set_state(SMF_CTX(obj), &demo_states[STATE_S21]); - break; - - case EVENT_H: - printf("[psicc2] %s received EVENT_H\n", __func__); - smf_set_state(SMF_CTX(obj), &demo_states[STATE_S]); - break; - - default: - break; - } - - return SMF_EVENT_PROPAGATE; -} - -static void s11_exit(void *o) -{ - (void)o; - - printf("[psicc2] %s\n", __func__); -} - -/**************************************************************************** - * STATE_S2 - ****************************************************************************/ - -static void s2_entry(void *o) -{ - (void)o; - - printf("[psicc2] %s\n", __func__); -} - -static enum smf_state_result s2_run(void *o) -{ - struct s_object *obj = (struct s_object *)o; - - printf("[psicc2] %s\n", __func__); - - switch (obj->event.event_id) - { - case EVENT_C: - printf("[psicc2] %s received EVENT_C\n", __func__); - smf_set_state(SMF_CTX(obj), &demo_states[STATE_S1]); - break; - - case EVENT_F: - printf("[psicc2] %s received EVENT_F\n", __func__); - smf_set_state(SMF_CTX(obj), &demo_states[STATE_S11]); - break; - - case EVENT_I: - if (!obj->foo) - { - printf("[psicc2] %s received EVENT_I and set foo true\n", - __func__); - obj->foo = true; - return SMF_EVENT_HANDLED; - } - else - { - printf("[psicc2] %s received EVENT_I and did nothing\n", - __func__); - } - break; - - default: - break; - } - - return SMF_EVENT_PROPAGATE; -} - -static void s2_exit(void *o) -{ - (void)o; - - printf("[psicc2] %s\n", __func__); -} - -/**************************************************************************** - * STATE_S21 - ****************************************************************************/ - -static void s21_entry(void *o) -{ - (void)o; - - printf("[psicc2] %s\n", __func__); -} - -static enum smf_state_result s21_run(void *o) -{ - struct s_object *obj = (struct s_object *)o; - - printf("[psicc2] %s\n", __func__); - - switch (obj->event.event_id) - { - case EVENT_A: - printf("[psicc2] %s received EVENT_A\n", __func__); - smf_set_state(SMF_CTX(obj), &demo_states[STATE_S21]); - break; - - case EVENT_B: - printf("[psicc2] %s received EVENT_B\n", __func__); - smf_set_state(SMF_CTX(obj), &demo_states[STATE_S211]); - break; - - case EVENT_G: - printf("[psicc2] %s received EVENT_G\n", __func__); - smf_set_state(SMF_CTX(obj), &demo_states[STATE_S1]); - break; - - default: - break; - } - - return SMF_EVENT_PROPAGATE; -} - -static void s21_exit(void *o) -{ - (void)o; - - printf("[psicc2] %s\n", __func__); -} - -/**************************************************************************** - * STATE_S211 - ****************************************************************************/ - -static void s211_entry(void *o) -{ - (void)o; - - printf("[psicc2] %s\n", __func__); -} - -static enum smf_state_result s211_run(void *o) -{ - struct s_object *obj = (struct s_object *)o; - - printf("[psicc2] %s\n", __func__); - - switch (obj->event.event_id) - { - case EVENT_D: - printf("[psicc2] %s received EVENT_D\n", __func__); - smf_set_state(SMF_CTX(obj), &demo_states[STATE_S21]); - break; - - case EVENT_H: - printf("[psicc2] %s received EVENT_H\n", __func__); - smf_set_state(SMF_CTX(obj), &demo_states[STATE_S]); - break; - - default: - break; - } - - return SMF_EVENT_PROPAGATE; -} - -static void s211_exit(void *o) -{ - (void)o; - - printf("[psicc2] %s\n", __func__); -} - -/**************************************************************************** - * State Table - ****************************************************************************/ - -static const struct smf_state demo_states[] = -{ - [STATE_INITIAL] = SMF_CREATE_STATE( - initial_entry, - initial_run, - initial_exit, - NULL, - &demo_states[STATE_S2] - ), - [STATE_S] = SMF_CREATE_STATE( - s_entry, - s_run, - s_exit, - &demo_states[STATE_INITIAL], - &demo_states[STATE_S11] - ), - [STATE_S1] = SMF_CREATE_STATE( - s1_entry, - s1_run, - s1_exit, - &demo_states[STATE_S], - &demo_states[STATE_S11] - ), - [STATE_S2] = SMF_CREATE_STATE( - s2_entry, - s2_run, - s2_exit, - &demo_states[STATE_S], - &demo_states[STATE_S211] - ), - [STATE_S11] = SMF_CREATE_STATE( - s11_entry, - s11_run, - s11_exit, - &demo_states[STATE_S1], - NULL - ), - [STATE_S21] = SMF_CREATE_STATE( - s21_entry, - s21_run, - s21_exit, - &demo_states[STATE_S2], - &demo_states[STATE_S211] - ), - [STATE_S211] = SMF_CREATE_STATE( - s211_entry, - s211_run, - s211_exit, - &demo_states[STATE_S21], - NULL - ) -}; - -/**************************************************************************** - * Name: hsm_psicc2_thread_main - ****************************************************************************/ - -static int hsm_psicc2_thread_main(int argc, char **argv) -{ - struct mq_attr attr; - mqd_t mq; - ssize_t n; - int rc; - - (void)argc; - (void)argv; - - memset(&attr, 0, sizeof(attr)); - attr.mq_maxmsg = CONFIG_EXAMPLES_SMF_EVENT_QUEUE_SIZE; - attr.mq_msgsize = sizeof(struct hsm_psicc2_event); - - mq = mq_open(CONFIG_EXAMPLES_SMF_MQ_NAME, O_CREAT | O_RDONLY, 0666, &attr); - if (mq == (mqd_t)-1) - { - printf("psicc2][ERR] mq_open(%s) failed: %d\n", - CONFIG_EXAMPLES_SMF_MQ_NAME, errno); - return -1; - } - - printf("[psicc2] State Machine thread started\n"); - - memset(&s_obj, 0, sizeof(s_obj)); - smf_set_initial(SMF_CTX(&s_obj), &demo_states[STATE_INITIAL]); - - while (true) - { - n = mq_receive(mq, (char *)&s_obj.event, sizeof(s_obj.event), NULL); - if (n < 0) - { - printf("psicc2][ERR] mq_receive failed: %d\n", errno); - continue; - } - - rc = smf_run_state(SMF_CTX(&s_obj)); - if (rc != 0) - { - printf("[psicc2] SMF terminated (rc=%d). Exiting thread\n", rc); - break; - } - } - - mq_close(mq); - mq_unlink(CONFIG_EXAMPLES_SMF_MQ_NAME); - - g_started = false; - memset(&s_obj, 0, sizeof(s_obj)); - - return 0; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: hsm_psicc2_thread_start - ****************************************************************************/ - -int hsm_psicc2_thread_start(void) -{ - int pid; - - if (g_started) - { - return 0; - } - - pid = task_create("psicc2_thread", - CONFIG_EXAMPLES_SMF_PRIORITY, - CONFIG_EXAMPLES_SMF_STACKSIZE, - hsm_psicc2_thread_main, - NULL); - if (pid < 0) - { - printf("psicc2][ERR] task_create failed: %d", errno); - return -1; - } - - g_started = true; - return 0; -} - -/**************************************************************************** - * Name: hsm_psicc2_post_event - ****************************************************************************/ - -int hsm_psicc2_post_event(uint32_t event_id) -{ - struct hsm_psicc2_event ev; - mqd_t mq; - int rc; - - ev.event_id = event_id; - - mq = mq_open(CONFIG_EXAMPLES_SMF_MQ_NAME, O_WRONLY | O_NONBLOCK); - if (mq == (mqd_t)-1) - { - printf("psicc2][ERR] mq_open(O_WRONLY) failed: %d " - "(did you run 'hsm_psicc2 start'?)\n", - errno); - return -1; - } - - rc = mq_send(mq, (const char *)&ev, sizeof(ev), 0); - if (rc < 0) - { - printf("psicc2][ERR] mq_send failed: %d\n", errno); - mq_close(mq); - return -1; - } - - mq_close(mq); - return 0; -} diff --git a/examples/smf/hsm_psicc2_thread.h b/examples/smf/hsm_psicc2_thread.h deleted file mode 100644 index 385a29703..000000000 --- a/examples/smf/hsm_psicc2_thread.h +++ /dev/null @@ -1,89 +0,0 @@ -/**************************************************************************** - * apps/examples/smf/hsm_psicc2_thread.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright (c) 2024 Glenn Andrews - * State Machine example copyright (c) Miro Samek - * - * Implementation of the statechart in Figure 2.11 of - * Practical UML Statecharts in C/C++, 2nd Edition by Miro Samek - * https://www.state-machine.com/psicc2 - * Used with permission of the author. - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __APPS_EXAMPLES_SMF_HSM_PSICC2_THREAD_H -#define __APPS_EXAMPLES_SMF_HSM_PSICC2_THREAD_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <stdint.h> - -#ifdef __cplusplus -#define EXTERN extern "C" -extern "C" -{ -#else -#define EXTERN extern -#endif - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -struct hsm_psicc2_event -{ - uint32_t event_id; -}; - -enum demo_events -{ - EVENT_A, - EVENT_B, - EVENT_C, - EVENT_D, - EVENT_E, - EVENT_F, - EVENT_G, - EVENT_H, - EVENT_I, - EVENT_TERMINATE -}; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -int hsm_psicc2_thread_start(void); -int hsm_psicc2_post_event(uint32_t event_id); - -#undef EXTERN -#ifdef __cplusplus -} -#endif - -#endif /* __APPS_EXAMPLES_SMF_HSM_PSICC2_THREAD_H */ diff --git a/examples/smf/smf_main.c b/examples/smf/smf_main.c deleted file mode 100644 index b6a9677a5..000000000 --- a/examples/smf/smf_main.c +++ /dev/null @@ -1,127 +0,0 @@ -/**************************************************************************** - * apps/examples/smf/smf_main.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright (c) 2024 Glenn Andrews - * State Machine example copyright (c) Miro Samek - * - * Implementation of the statechart in Figure 2.11 of - * Practical UML Statecharts in C/C++, 2nd Edition by Miro Samek - * https://www.state-machine.com/psicc2 - * Used with permission of the author. - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <ctype.h> -#include <stdio.h> -#include <string.h> - -#include "hsm_psicc2_thread.h" - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: usage - ****************************************************************************/ - -static void usage(void) -{ - printf("Usage:\n"); - printf(" hsm_psicc2 start\n"); - printf(" hsm_psicc2 event <A..I>\n"); - printf(" hsm_psicc2 terminate\n"); -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: main - ****************************************************************************/ - -int main(int argc, char *argv[]) -{ - if (argc < 2) - { - usage(); - return 1; - } - - if (strcmp(argv[1], "start") == 0) - { - printf("State Machine Framework Demo\n"); - printf("See PSiCC2 Fig 2.11 for the statechart\n"); - printf("https://www.state-machine.com/psicc2\n\n"); - return hsm_psicc2_thread_start(); - } - - if (strcmp(argv[1], "terminate") == 0) - { - return hsm_psicc2_post_event(EVENT_TERMINATE); - } - - if (strcmp(argv[1], "event") == 0) - { - int c; - - if (argc < 3 || argv[2] == NULL || argv[2][0] == '\0') - { - usage(); - return 1; - } - - c = toupper((unsigned char)argv[2][0]); - switch (c) - { - case 'A': - return hsm_psicc2_post_event(EVENT_A); - case 'B': - return hsm_psicc2_post_event(EVENT_B); - case 'C': - return hsm_psicc2_post_event(EVENT_C); - case 'D': - return hsm_psicc2_post_event(EVENT_D); - case 'E': - return hsm_psicc2_post_event(EVENT_E); - case 'F': - return hsm_psicc2_post_event(EVENT_F); - case 'G': - return hsm_psicc2_post_event(EVENT_G); - case 'H': - return hsm_psicc2_post_event(EVENT_H); - case 'I': - return hsm_psicc2_post_event(EVENT_I); - default: - printf("Invalid event '%c'\n", c); - return 1; - } - } - - usage(); - return 1; -} diff --git a/examples/smps/CMakeLists.txt b/examples/smps/CMakeLists.txt deleted file mode 100644 index 15344ae4a..000000000 --- a/examples/smps/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# ############################################################################## -# apps/examples/smps/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_SMPS) - nuttx_add_application( - NAME - smps - STACKSIZE - ${CONFIG_DEFAULT_TASK_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_SMPS} - SRCS - smps_main.c) -endif() diff --git a/examples/smps/Kconfig b/examples/smps/Kconfig index a89936405..2d45b0ebd 100644 --- a/examples/smps/Kconfig +++ b/examples/smps/Kconfig @@ -5,8 +5,6 @@ config EXAMPLES_SMPS tristate "Smps example" - depends on DRIVERS_SMPS - depends on LIBC_FLOATINGPOINT if EXAMPLES_SMPS diff --git a/examples/smps/Make.defs b/examples/smps/Make.defs index bb06f3541..9cae2ef55 100644 --- a/examples/smps/Make.defs +++ b/examples/smps/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/smps/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/smps/Makefile b/examples/smps/Makefile index edbb6e5f8..5c9799d5e 100644 --- a/examples/smps/Makefile +++ b/examples/smps/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/smps/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/smps/smps_main.c b/examples/smps/smps_main.c index b9ddbd827..5cdb0bd27 100644 --- a/examples/smps/smps_main.c +++ b/examples/smps/smps_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/smps/smps_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -35,17 +33,27 @@ #include <stdlib.h> #include <stdbool.h> #include <errno.h> -#include <nuttx/debug.h> +#include <debug.h> #include <sys/ioctl.h> #include <sys/boardctl.h> #include <nuttx/fs/fs.h> #include <nuttx/power/smps.h> +#if defined(CONFIG_EXAMPLES_SMPS) + +#ifndef CONFIG_DRIVERS_SMPS +# error "Smps example requires smps support" +#endif + /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ +#ifndef CONFIG_LIBC_FLOATINGPOINT +# error "CONFIG_LIBC_FLOATINGPOINT must be set!" +#endif + #ifndef CONFIG_EXAMPLES_SMPS_TIME_DEFAULT # define CONFIG_EXAMPLES_SMPS_TIME_DEFAULT 10 #endif @@ -79,7 +87,7 @@ #endif /**************************************************************************** - * Private Types + * Private Type Definition ****************************************************************************/ /* Application arguments */ @@ -476,10 +484,16 @@ int main(int argc, char *argv[]) goto errout; } +#ifndef CONFIG_NSH_ARCHINIT + /* Perform architecture-specific initialization (if configured) */ + + boardctl(BOARDIOC_INIT, 0); + #ifdef CONFIG_BOARDCTL_FINALINIT /* Perform architecture-specific final-initialization (if configured) */ boardctl(BOARDIOC_FINALINIT, 0); +#endif #endif /* Set SMPS mode */ @@ -601,6 +615,7 @@ int main(int argc, char *argv[]) } errout: + if (fd > 0) { printf("Stop smps driver\n"); @@ -621,3 +636,4 @@ errout: return 0; } +#endif /* CONFIG_EXAMPLE_SMPS */ diff --git a/examples/sotest/.gitignore b/examples/sotest/.gitignore deleted file mode 100644 index 8e29db973..000000000 --- a/examples/sotest/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/Kconfig -lib/ diff --git a/examples/sotest/CMakeLists.txt b/examples/sotest/CMakeLists.txt deleted file mode 100644 index 9daecfb74..000000000 --- a/examples/sotest/CMakeLists.txt +++ /dev/null @@ -1,24 +0,0 @@ -# ############################################################################## -# apps/examples/sotest/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -nuttx_add_subdirectory() -nuttx_generate_kconfig(MENUDESC "Sotest") diff --git a/examples/sotest/main/Kconfig b/examples/sotest/Kconfig similarity index 80% rename from examples/sotest/main/Kconfig rename to examples/sotest/Kconfig index 03ca9b962..0f376eb84 100644 --- a/examples/sotest/main/Kconfig +++ b/examples/sotest/Kconfig @@ -15,7 +15,7 @@ if EXAMPLES_SOTEST config EXAMPLES_SOTEST_BUILTINFS bool "Built-in File System" default y - depends on FS_ROMFS && BUILD_FLAT && BOARDCTL_ROMDISK + depends on FS_ROMFS && BUILD_FLAT ---help--- This example supports a very, non-standard but also very convenient way of testing with example using CONFIG_EXAMPLES_SOTEST_BUILTINFS. @@ -35,14 +35,21 @@ config EXAMPLES_SOTEST_BUILTINFS if EXAMPLES_SOTEST_BUILTINFS -config EXAMPLES_SOTEST_DEVMINOR_MAX - int "ROMFS Max Minor Device Number" - default 5 +config EXAMPLES_SOTEST_DEVMINOR + int "ROMFS Minor Device Number" + default 0 ---help--- - The max minor device number of the ROMFS block will be tried. - For example, from /dev/ram0 to /dev/ramN. + The minor device number of the ROMFS block. For example, the N in /dev/ramN. Used for registering the RAM block driver that will hold the ROMFS file system - containing the SOTEST executables to be tested. Default: 5 + containing the SOTEST executables to be tested. Default: 0 + +config EXAMPLES_SOTEST_DEVPATH + string "ROMFS Device Path" + default "/dev/ram0" + ---help--- + The path to the ROMFS block driver device. This must match EXAMPLES_SOTEST_DEVMINOR. + Used for registering the RAM block driver that will hold the ROMFS file system + containing the SOTEST executables to be tested. Default: "/dev/ram0" endif # EXAMPLES_SOTEST_BUILTINFS diff --git a/examples/sotest/Make.defs b/examples/sotest/Make.defs index 17afaca43..1f732f9ec 100644 --- a/examples/sotest/Make.defs +++ b/examples/sotest/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/sotest/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -20,11 +18,6 @@ # ############################################################################ -ifeq ($(CONFIG_EXAMPLES_SOTEST),y) -include $(APPDIR)/examples/sotest/main/Make.defs -endif - -ifneq ($(CONFIG_EXAMPLES_SOTEST),n) -include $(APPDIR)/examples/sotest/modprint/Make.defs -include $(APPDIR)/examples/sotest/sotest/Make.defs +ifneq ($(CONFIG_EXAMPLES_SOTEST),) +CONFIGURED_APPS += $(APPDIR)/examples/sotest endif diff --git a/examples/sotest/Makefile b/examples/sotest/Makefile index 0d23750cf..250455108 100644 --- a/examples/sotest/Makefile +++ b/examples/sotest/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/sotest/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -20,6 +18,39 @@ # ############################################################################ -MENUDESC = "sotest example" +include $(APPDIR)/Make.defs -include $(APPDIR)/Directory.mk +# Shared library example built-in application info + +PROGNAME = sotest +PRIORITY = SCHED_PRIORITY_DEFAULT +STACKSIZE = $(CONFIG_DEFAULT_TASK_STACKSIZE) +MODULE = $(CONFIG_EXAMPLES_SOTEST) + +# Shared Library Example + +ifeq ($(CONFIG_EXAMPLES_SOTEST_BUILTINFS),y) +CSRCS = romfs.c +endif +CSRCS += sot_symtab.c +MAINSRC = sotest_main.c + +DEPPATH += --dep-path lib + +# Build targets + +VPATH = lib + +ifeq ($(CONFIG_EXAMPLES_SOTEST_BUILTINFS),y) +lib/romfs.c: build +endif +lib/sot_symtab.c: build + +.PHONY: build +build: + +$(Q) $(MAKE) -C lib TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)" CROSSDEV=$(CROSSDEV) + +clean:: + +$(Q) $(MAKE) -C lib TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)" CROSSDEV=$(CROSSDEV) clean + +include $(APPDIR)/Application.mk diff --git a/examples/sotest/lib/.gitignore b/examples/sotest/lib/.gitignore new file mode 100644 index 000000000..f41ef9224 --- /dev/null +++ b/examples/sotest/lib/.gitignore @@ -0,0 +1,4 @@ +/fsroot +/romfs.c +/romfs.img +/sot_symtab.c diff --git a/examples/sotest/lib/Makefile b/examples/sotest/lib/Makefile new file mode 100644 index 000000000..734944203 --- /dev/null +++ b/examples/sotest/lib/Makefile @@ -0,0 +1,80 @@ +############################################################################ +# apps/examples/sotest/lib/Makefile +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. The +# ASF licenses this file to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance with the +# License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +############################################################################ + +include $(APPDIR)/Make.defs + +ALL_SUBDIRS = sotest +BUILD_SUBDIRS = sotest + +ifneq ($(CONFIG_MODLIB_MAXDEPEND),0) +ALL_SUBDIRS += modprint +BUILD_SUBDIRS += modprint +endif + +SOTEST_DIR = $(APPDIR)/examples/sotest +LIB_DIR = $(SOTEST_DIR)/lib +FSROOT_DIR = $(LIB_DIR)/fsroot +SYMTAB_SRC = $(LIB_DIR)/sot_symtab.c + +ifeq ($(CONFIG_EXAMPLES_SOTEST_BUILTINFS),y) + ROMFS_IMG = $(LIB_DIR)/romfs.img + ROMFS_SRC = $(LIB_DIR)/romfs.c +endif + +define DIR_template +$(1)_$(2): + +$(Q) $(MAKE) -C $(1) $(2) TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)" FSROOT_DIR="$(FSROOT_DIR)" CROSSDEV=$(CROSSDEV) +endef + +all: $(ROMFS_SRC) $(SYMTAB_SRC) +.PHONY: all clean install + +$(foreach DIR, $(ALL_SUBDIRS), $(eval $(call DIR_template,$(DIR),clean))) +$(foreach DIR, $(BUILD_SUBDIRS), $(eval $(call DIR_template,$(DIR),install))) + +# Install each program in the fsroot directory + +install: $(foreach DIR, $(BUILD_SUBDIRS), $(DIR)_install) + +ifeq ($(CONFIG_EXAMPLES_SOTEST_BUILTINFS),y) +# Create the romfs.img file from the populated fsroot directory + +$(ROMFS_IMG): install + $(Q) genromfs -f $@.tmp -d $(FSROOT_DIR) -V "SOTESTTEST" + $(Q) $(call TESTANDREPLACEFILE, $@.tmp, $@) + +# Create the romfs.c file from the romfs.img file + +$(ROMFS_SRC): $(ROMFS_IMG) + $(Q) (cd $(LIB_DIR) && echo "#include <nuttx/compiler.h>" >$@ && \ + xxd -i romfs.img | sed -e "s/^unsigned char/const unsigned char aligned_data(4)/g" >>$@) +endif + +# Create the exported symbol table + +$(SYMTAB_SRC): install + $(Q) $(APPDIR)$(DELIM)tools$(DELIM)mksymtab.sh $(FSROOT_DIR) g_sot | sed "/modprint/d" >$@.tmp + $(Q) $(call TESTANDREPLACEFILE, $@.tmp, $@) + +# Clean each subdirectory + +clean: $(foreach DIR, $(ALL_SUBDIRS), $(DIR)_clean) + $(Q) rm -f $(ROMFS_SRC) $(ROMFS_IMG) $(SYMTAB_SRC) + $(Q) rm -rf $(FSROOT_DIR) diff --git a/examples/sotest/lib/modprint/.gitignore b/examples/sotest/lib/modprint/.gitignore new file mode 100644 index 000000000..791ac9ac0 --- /dev/null +++ b/examples/sotest/lib/modprint/.gitignore @@ -0,0 +1 @@ +/modprint diff --git a/testing/nettest/Makefile b/examples/sotest/lib/modprint/Makefile similarity index 53% rename from testing/nettest/Makefile rename to examples/sotest/lib/modprint/Makefile index 2abd410bc..b755b8d54 100644 --- a/testing/nettest/Makefile +++ b/examples/sotest/lib/modprint/Makefile @@ -1,5 +1,5 @@ ############################################################################ -# apps/testing/nettest/Makefile +# apps/examples/sotest/lib/modprint/Makefile # # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with @@ -20,36 +20,45 @@ include $(APPDIR)/Make.defs -NETTEST_UTILS_DIR := $(APPDIR)/testing/nettest/utils - -PRIORITY = $(CONFIG_TESTING_NET_TEST_PRIORITY) -STACKSIZE = $(CONFIG_TESTING_NET_TEST_STACKSIZE) -MODULE = $(CONFIG_TESTING_NET_TEST) - -ifeq ($(CONFIG_TESTING_NET_TEST),y) - -CFLAGS += -I$(NETTEST_UTILS_DIR) - -ifeq ($(CONFIG_TESTING_NET_TCP),y) -MAINSRC += tcp/test_tcp.c -PROGNAME += cmocka_net_tcp -CSRCS += tcp/test_tcp_common.c utils/nettest_tcpserver.c - -ifeq ($(CONFIG_NET_IPv4), y) -CSRCS += tcp/test_tcp_connect_ipv4.c +ifeq ($(CONFIG_EXAMPLES_SOTEST_LIBGCC),y) +LIBGCC = "${shell $(CC) $(ARCHCPUFLAGS) -print-libgcc-file-name 2>/dev/null}" +ifneq ($(LIBGCC),) + LDLIBPATH += -L "${shell dirname $(LIBGCC)}" + LDLIBS += -lgcc +endif endif -ifeq ($(CONFIG_NET_IPv6), y) -CSRCS += tcp/test_tcp_connect_ipv6.c +ifeq ($(CONFIG_EXAMPLES_SOTEST_LIBC),y) +LDMODULEFLAGS += -Bstatic +LDLIBPATH += -L $(NUTTXLIB) endif +ifeq ($(CONFIG_EXAMPLES_SOTEST_LIBC),y) +LDLIBS += -lc endif -ifeq ($(CONFIG_TESTING_NET_OTHERS),y) -MAINSRC += others/test_others.c -PROGNAME += cmocka_net_others -CSRCS += others/test_others_common.c others/test_others_bufpool.c -endif +BIN = modprint -endif -include $(APPDIR)/Application.mk +SRCS = $(BIN).c +OBJS = $(SRCS:.c=$(OBJEXT)) + +all: $(BIN) +.PHONY: all clean install + +$(OBJS): %$(OBJEXT): %.c + @echo "MODULECC: $<" + $(Q) $(MODULECC) -c $(CMODULEFLAGS) $< -o $@ + +$(BIN): $(OBJS) + @echo "MODULELD: $<" + $(Q) $(MODULELD) $(LDMODULEFLAGS) $(LDLIBPATH) -o $@ $(ARCHCRT0OBJ) $^ $(LDLIBS) + +$(FSROOT_DIR)/$(BIN): $(BIN) + $(Q) mkdir -p $(FSROOT_DIR) + $(Q) install $(BIN) $(FSROOT_DIR)/$(BIN) + +install: $(FSROOT_DIR)/$(BIN) + +clean: + $(call DELFILE, $(BIN)) + $(call CLEAN) diff --git a/include/lte/lapi.h b/examples/sotest/lib/modprint/modprint.c similarity index 66% rename from include/lte/lapi.h rename to examples/sotest/lib/modprint/modprint.c index 4159d0e6d..ea14702a7 100644 --- a/include/lte/lapi.h +++ b/examples/sotest/lib/modprint/modprint.c @@ -1,7 +1,5 @@ /**************************************************************************** - * apps/include/lte/lapi.h - * - * SPDX-License-Identifier: Apache-2.0 + * apps/examples/sotest/lib/modprint/modprint.c * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -20,64 +18,84 @@ * ****************************************************************************/ -#ifndef __APPS_INCLUDE_LTE_LAPI_H -#define __APPS_INCLUDE_LTE_LAPI_H - /**************************************************************************** * Included Files ****************************************************************************/ -#include <stdint.h> -#include "lte/lte_api.h" +#include <nuttx/config.h> + +#include <sys/types.h> +#include <stdarg.h> +#include <dlfcn.h> +#include <syslog.h> + +#include <nuttx/symtab.h> +#include <nuttx/lib/modlib.h> /**************************************************************************** - * Pre-processor Definitions + * Private Function Prototypes ****************************************************************************/ +static void modprint(FAR const char *fmt, ...); + /**************************************************************************** - * Public Types + * Private Data ****************************************************************************/ -#ifdef __cplusplus -#define EXTERN extern "C" -extern "C" +static const struct symtab_s g_modprint_exports[1] = { -#else -#define EXTERN extern -#endif + { + (FAR const char *)"modprint", (FAR const void *)modprint, + } +}; /**************************************************************************** - * Public Function Prototyppes + * Private Functions ****************************************************************************/ /**************************************************************************** - * Name: lapi_evtinit + * Name: modprint ****************************************************************************/ -int lapi_evtinit(FAR const char *mqname); +static void modprint(FAR const char *fmt, ...) +{ + va_list ap; -/**************************************************************************** - * Name: lapi_evtdestoy - ****************************************************************************/ - -void lapi_evtdestoy(void); - -/**************************************************************************** - * Name: lapi_evtyield - ****************************************************************************/ - -int lapi_evtyield(int timeout_ms); - -/**************************************************************************** - * Name: lapi_req - ****************************************************************************/ - -int lapi_req(uint32_t cmdid, FAR void *inp, size_t insz, FAR void *outp, - size_t outsz, FAR void *cb); - -#undef EXTERN -#ifdef __cplusplus + va_start(ap, fmt); + vsyslog(LOG_INFO, fmt, ap); + va_end(ap); } -#endif -#endif /* __APPS_INCLUDE_LTE_LAPI_H */ +/**************************************************************************** + * Name: module_uninitialize + ****************************************************************************/ + +static int module_uninitialize(FAR void *arg) +{ + syslog(LOG_INFO, "module_uninitialize: arg=%p\n", arg); + return OK; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: module_initialize + * + * Description: + * Register /dev/sotest + * + ****************************************************************************/ + +int module_initialize(FAR struct mod_info_s *modinfo) +{ + syslog(LOG_INFO, "module_initialize:\n"); + + modinfo->uninitializer = module_uninitialize; + modinfo->arg = NULL; + modinfo->exports = g_modprint_exports; + modinfo->nexports = 1; + + return OK; +} diff --git a/examples/sotest/lib/sotest/.gitignore b/examples/sotest/lib/sotest/.gitignore new file mode 100644 index 000000000..256c42b57 --- /dev/null +++ b/examples/sotest/lib/sotest/.gitignore @@ -0,0 +1 @@ +/sotest diff --git a/examples/optee/Makefile b/examples/sotest/lib/sotest/Makefile similarity index 53% rename from examples/optee/Makefile rename to examples/sotest/lib/sotest/Makefile index f60644cd7..55338e1da 100644 --- a/examples/optee/Makefile +++ b/examples/sotest/lib/sotest/Makefile @@ -1,7 +1,5 @@ ############################################################################ -# apps/examples/optee/Makefile -# -# SPDX-License-Identifier: Apache-2.0 +# apps/examples/sotest/lib/sotest/Makefile # # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with @@ -22,13 +20,45 @@ include $(APPDIR)/Make.defs -# OP-TEE client built-in application info +ifeq ($(CONFIG_EXAMPLES_SOTEST_LIBGCC),y) +LIBGCC = "${shell $(CC) $(ARCHCPUFLAGS) -print-libgcc-file-name 2>/dev/null}" +ifneq ($(LIBGCC),) + LDLIBPATH += -L "${shell dirname $(LIBGCC)}" + LDLIBS += -lgcc +endif +endif -PROGNAME = $(CONFIG_EXAMPLES_OPTEE_PROGNAME) -PRIORITY = $(CONFIG_EXAMPLES_OPTEE_PRIORITY) -STACKSIZE = $(CONFIG_EXAMPLES_OPTEE_STACKSIZE) -MODULE = $(CONFIG_EXAMPLES_OPTEE) +ifeq ($(CONFIG_EXAMPLES_SOTEST_LIBC),y) +LDMODULEFLAGS += -Bstatic +LDLIBPATH += -L $(NUTTXLIB) +endif -MAINSRC = optee_main.c +ifeq ($(CONFIG_EXAMPLES_SOTEST_LIBC),y) +LDLIBS += -lc +endif -include $(APPDIR)/Application.mk +BIN = sotest + +SRCS = $(BIN).c +OBJS = $(SRCS:.c=$(OBJEXT)) + +all: $(BIN) +.PHONY: all clean install + +$(OBJS): %$(OBJEXT): %.c + @echo "MODULECC: $<" + $(Q) $(MODULECC) -c $(CMODULEFLAGS) $< -o $@ + +$(BIN): $(OBJS) + @echo "MODULELD: $<" + $(Q) $(MODULELD) $(LDMODULEFLAGS) $(LDLIBPATH) -o $@ $(ARCHCRT0OBJ) $^ $(LDLIBS) + +$(FSROOT_DIR)/$(BIN): $(BIN) + $(Q) mkdir -p $(FSROOT_DIR) + $(Q) install $(BIN) $(FSROOT_DIR)/$(BIN) + +install: $(FSROOT_DIR)/$(BIN) + +clean: + $(call DELFILE, $(BIN)) + $(call CLEAN) diff --git a/examples/sotest/sotest/sotest.c b/examples/sotest/lib/sotest/sotest.c similarity index 71% rename from examples/sotest/sotest/sotest.c rename to examples/sotest/lib/sotest/sotest.c index ff825cbac..549c15931 100644 --- a/examples/sotest/sotest/sotest.c +++ b/examples/sotest/lib/sotest/sotest.c @@ -1,7 +1,5 @@ /**************************************************************************** - * apps/examples/sotest/sotest/sotest.c - * - * SPDX-License-Identifier: Apache-2.0 + * apps/examples/sotest/lib/sotest/sotest.c * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -32,27 +30,54 @@ #include <syslog.h> #include <nuttx/symtab.h> -#include <nuttx/lib/elf.h> +#include <nuttx/lib/modlib.h> /**************************************************************************** * Public Function Prototypes ****************************************************************************/ -#if CONFIG_LIBC_ELF_MAXDEPEND > 0 -void modprint(FAR const char *fmt, ...) printf_like(1, 2); +#if CONFIG_MODLIB_MAXDEPEND > 0 +void modprint(FAR const char *fmt, ...); #endif /**************************************************************************** * Private Function Prototypes ****************************************************************************/ +static void testfunc1(FAR const char *msg); +static void testfunc2(FAR const char *msg); +static void testfunc3(FAR const char *msg); +static int module_uninitialize(FAR void *arg); + /**************************************************************************** * Private Data ****************************************************************************/ -visibility_default const char g_msg1[] = "Hello to you too!"; -visibility_default const char g_msg2[] = "Not so bad so far."; -visibility_default const char g_msg3[] = "Yes, don't be a stranger!"; +static const char g_msg1[] = "Hello to you too!"; +static const char g_msg2[] = "Not so bad so far."; +static const char g_msg3[] = "Yes, don't be a stranger!"; + +static const struct symtab_s g_sotest_exports[6] = +{ + { + (FAR const char *)"testfunc1", (FAR const void *)testfunc1, + }, + { + (FAR const char *)"testfunc2", (FAR const void *)testfunc2, + }, + { + (FAR const char *)"testfunc3", (FAR const void *)testfunc3, + }, + { + (FAR const char *)"g_msg1", (FAR const void *)g_msg1, + }, + { + (FAR const char *)"g_msg2", (FAR const void *)g_msg2, + }, + { + (FAR const char *)"g_msg3", (FAR const void *)g_msg3, + }, +}; /**************************************************************************** * Private Functions @@ -62,7 +87,7 @@ visibility_default const char g_msg3[] = "Yes, don't be a stranger!"; * Name: modprint ****************************************************************************/ -#if CONFIG_LIBC_ELF_MAXDEPEND < 1 +#if CONFIG_MODLIB_MAXDEPEND < 1 static void modprint(FAR const char *fmt, ...) { va_list ap; @@ -77,7 +102,7 @@ static void modprint(FAR const char *fmt, ...) * Name: testfunc1 ****************************************************************************/ -visibility_default void testfunc1(FAR const char *msg) +static void testfunc1(FAR const char *msg) { modprint("testfunc1: Hello, everyone!\n"); modprint(" caller: %s\n", msg); @@ -87,7 +112,7 @@ visibility_default void testfunc1(FAR const char *msg) * Name: testfunc2 ****************************************************************************/ -visibility_default void testfunc2(FAR const char *msg) +static void testfunc2(FAR const char *msg) { modprint("testfunc2: Hope you are having a great day!\n"); modprint(" caller: %s\n", msg); @@ -97,7 +122,7 @@ visibility_default void testfunc2(FAR const char *msg) * Name: testfunc3 ****************************************************************************/ -visibility_default void testfunc3(FAR const char *msg) +static void testfunc3(FAR const char *msg) { modprint("testfunc3: Let's talk again very soon\n"); modprint(" caller: %s\n", msg); @@ -107,9 +132,10 @@ visibility_default void testfunc3(FAR const char *msg) * Name: module_uninitialize ****************************************************************************/ -destructor_function static void module_uninitialize(void) +static int module_uninitialize(FAR void *arg) { - modprint("module_uninitialize\n"); + modprint("module_uninitialize: arg=%p\n", arg); + return OK; } /**************************************************************************** @@ -124,7 +150,14 @@ destructor_function static void module_uninitialize(void) * ****************************************************************************/ -constructor_fuction static void module_initialize(void) +int module_initialize(FAR struct mod_info_s *modinfo) { - modprint("module_initialize\n"); + modprint("module_initialize:\n"); + + modinfo->uninitializer = module_uninitialize; + modinfo->arg = NULL; + modinfo->exports = g_sotest_exports; + modinfo->nexports = 6; + + return OK; } diff --git a/examples/sotest/main/.gitignore b/examples/sotest/main/.gitignore deleted file mode 100644 index cb2478b33..000000000 --- a/examples/sotest/main/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -/sotest_symtab.c -/sotest_romfs.c -/sotest_romfs.img diff --git a/examples/sotest/main/CMakeLists.txt b/examples/sotest/main/CMakeLists.txt deleted file mode 100644 index 5c5cef5a6..000000000 --- a/examples/sotest/main/CMakeLists.txt +++ /dev/null @@ -1,127 +0,0 @@ -# ############################################################################## -# apps/examples/sotest/main/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_SOTEST) - set(SOTEST_SYMTAB ${CMAKE_CURRENT_BINARY_DIR}/sotest_symtab.c) - set(SOTEST_ROMFS_IMG ${CMAKE_CURRENT_BINARY_DIR}/sotest_romfs.img) - set(SOTEST_ROMFS_SRC ${CMAKE_CURRENT_BINARY_DIR}/sotest_romfs.c) - set(SOTEST_MODPRINT_ELF ${CMAKE_BINARY_DIR}/bin/modprint) - set(SOTEST_SHARED_ELF ${CMAKE_BINARY_DIR}/bin/sotest) - - # Dynamic applications are wrapped in ELF_* helper targets when the build uses - # the non-ELF-capable compiler path. - if(CMAKE_C_ELF_COMPILER) - set(SOTEST_MODPRINT_TARGET modprint) - set(SOTEST_SHARED_TARGET sotest) - else() - set(SOTEST_MODPRINT_TARGET ELF_modprint) - set(SOTEST_SHARED_TARGET ELF_sotest) - endif() - - add_custom_command( - OUTPUT ${SOTEST_SYMTAB} - COMMAND ${NUTTX_APPS_DIR}/tools/mksymtab.sh ${SOTEST_MODPRINT_ELF} - ${SOTEST_SHARED_ELF} g_sot > ${SOTEST_SYMTAB} - DEPENDS ${SOTEST_MODPRINT_TARGET} ${SOTEST_SHARED_TARGET}) - - set_source_files_properties(${SOTEST_SYMTAB} PROPERTIES GENERATED TRUE) - - set(SOTEST_GENERATED_OUTPUTS ${SOTEST_SYMTAB}) - set(SOTEST_SRCS sotest_main.c ${SOTEST_SYMTAB}) - - if(CONFIG_EXAMPLES_SOTEST_BUILTINFS) - set(SOTEST_ROMFS_DEPS ${SOTEST_MODPRINT_TARGET} ${SOTEST_SHARED_TARGET}) - - if(CONFIG_SYSTEM_NXPKG) - set(SOTEST_SHARED_INDEX ${CMAKE_BINARY_DIR}/bin/shared-index.json) - set(SOTEST_SHARED_SCRIPT ${CMAKE_BINARY_DIR}/bin/pkgsotest.nsh) - set(SOTEST_FIXTURE_HOST_DIR ${CMAKE_CURRENT_BINARY_DIR}/host) - set(SOTEST_FIXTURE_HOST_SRC - ${CMAKE_CURRENT_SOURCE_DIR}/host/CMakeLists.txt) - set(SOTEST_FIXTURE_TOOL - ${SOTEST_FIXTURE_HOST_DIR}/mk_pkg_fixture_shared${CMAKE_EXECUTABLE_SUFFIX} - ) - - if(CONFIG_ARCH_BOARD) - set(SOTEST_FIXTURE_COMPAT ${CONFIG_ARCH_BOARD}) - else() - set(SOTEST_FIXTURE_COMPAT ${CONFIG_ARCH_BOARD_CUSTOM_NAME}) - endif() - - add_custom_command( - OUTPUT ${SOTEST_FIXTURE_TOOL} - COMMAND ${CMAKE_COMMAND} -S ${CMAKE_CURRENT_SOURCE_DIR}/host -B - ${SOTEST_FIXTURE_HOST_DIR} - COMMAND ${CMAKE_COMMAND} --build ${SOTEST_FIXTURE_HOST_DIR} --target - mk_pkg_fixture_shared - DEPENDS ${SOTEST_FIXTURE_HOST_SRC} - ${CMAKE_CURRENT_SOURCE_DIR}/mk_pkg_fixture_shared.c - VERBATIM) - - add_custom_command( - OUTPUT ${SOTEST_SHARED_INDEX} ${SOTEST_SHARED_SCRIPT} - COMMAND - ${SOTEST_FIXTURE_TOOL} ${SOTEST_MODPRINT_ELF} ${SOTEST_SHARED_ELF} - ${SOTEST_SHARED_INDEX} ${SOTEST_SHARED_SCRIPT} ${CONFIG_ARCH} - ${SOTEST_FIXTURE_COMPAT} - DEPENDS ${SOTEST_MODPRINT_TARGET} ${SOTEST_SHARED_TARGET} - ${SOTEST_FIXTURE_TOOL} - VERBATIM) - - list(APPEND SOTEST_ROMFS_DEPS ${SOTEST_SHARED_INDEX} - ${SOTEST_SHARED_SCRIPT}) - endif() - - add_custom_command( - OUTPUT ${SOTEST_ROMFS_IMG} - COMMAND genromfs -f ${SOTEST_ROMFS_IMG} -d ${CMAKE_BINARY_DIR}/bin - DEPENDS ${SOTEST_ROMFS_DEPS} - VERBATIM) - - get_filename_component(SOTEST_ROMFS_IMG_NAME ${SOTEST_ROMFS_IMG} NAME) - - # xxd -i derives the generated array/length symbol names from the exact path - # it is given - sotest_main.c declares them as plain - # "sotest_romfs_img"/"sotest_romfs_img_len", so xxd must be run against just - # the bare filename (via WORKING_DIRECTORY) rather than the absolute - # ${SOTEST_ROMFS_IMG} path, or every non- alphanumeric character in that - # path (e.g. every "/" in the build directory) gets folded into the symbol - # name instead, leaving the names sotest_main.c expects undefined at link - # time. - - add_custom_command( - OUTPUT ${SOTEST_ROMFS_SRC} - COMMAND xxd -i ${SOTEST_ROMFS_IMG_NAME} > ${SOTEST_ROMFS_SRC} - DEPENDS ${SOTEST_ROMFS_IMG} - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) - - set_source_files_properties(${SOTEST_ROMFS_SRC} PROPERTIES GENERATED TRUE) - - list(APPEND SOTEST_GENERATED_OUTPUTS ${SOTEST_ROMFS_SRC}) - list(APPEND SOTEST_SRCS ${SOTEST_ROMFS_SRC}) - endif() - - add_custom_target(sotest_artifacts DEPENDS ${SOTEST_GENERATED_OUTPUTS}) - - nuttx_add_application(NAME sotest SRCS ${SOTEST_SRCS} DEPENDS - sotest_artifacts) -endif() diff --git a/examples/sotest/main/Make.defs b/examples/sotest/main/Make.defs deleted file mode 100644 index a904d0cef..000000000 --- a/examples/sotest/main/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/examples/sotest/main/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_EXAMPLES_SOTEST),) -CONFIGURED_APPS += $(APPDIR)/examples/sotest/main -endif diff --git a/examples/sotest/main/Makefile b/examples/sotest/main/Makefile deleted file mode 100644 index 327b60c9e..000000000 --- a/examples/sotest/main/Makefile +++ /dev/null @@ -1,98 +0,0 @@ -############################################################################ -# apps/examples/sotest/main/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -# Shared library example built-in application info - -PROGNAME = sotest -PRIORITY = SCHED_PRIORITY_DEFAULT -STACKSIZE = $(CONFIG_DEFAULT_TASK_STACKSIZE) -MODULE = $(CONFIG_EXAMPLES_SOTEST) - -# Shared Library Example - -MAINSRC = sotest_main.c - -SYMTABSRC = sotest_symtab.c -SYMTABOBJ = $(SYMTABSRC:.c=$(OBJEXT)) - -$(SYMTABSRC): - $(Q) $(APPDIR)$(DELIM)tools$(DELIM)mksymtab.sh $(BINDIR) g_sot >$@.tmp - $(Q) $(call TESTANDREPLACEFILE, $@.tmp, $@) - - -$(SYMTABOBJ): %$(OBJEXT): %.c - $(call COMPILE, $<, $@, -fno-lto -fno-builtin) - - -ifeq ($(CONFIG_EXAMPLES_SOTEST_BUILTINFS),y) - -ROMFSIMG = sotest_romfs.img -ROMFSSRC = sotest_romfs.c -ROMFSOBJ = $(ROMFSSRC:.c=$(OBJEXT)) -ifdef CONFIG_SYSTEM_NXPKG -HOSTOBJSEXT ?= hobj -PKGSHAREDINDEX = $(BINDIR)/shared-index.json -PKGSHAREDTEST = $(BINDIR)/pkgsotest.nsh -PKG_FIXTURE_GEN = mk_pkg_fixture_shared$(HOSTEXEEXT) -PKG_FIXTURE_SRCS = mk_pkg_fixture_shared.c -PKG_FIXTURE_OBJS = $(PKG_FIXTURE_SRCS:.c=.$(HOSTOBJSEXT)) -PKG_FIXTURE_OUTPUTS = $(PKGSHAREDINDEX) $(PKGSHAREDTEST) -PKG_FIXTURE_STAMP = $(BINDIR)/.pkgsotest.stamp -PKG_FIXTURE_COMPAT = $(if $(CONFIG_ARCH_BOARD),$(CONFIG_ARCH_BOARD),$(CONFIG_ARCH_BOARD_CUSTOM_NAME)) - -$(PKG_FIXTURE_OBJS): %.$(HOSTOBJSEXT): %.c - @echo "CC: $<" - $(Q) $(HOSTCC) -c $(HOSTCFLAGS) $< -o $@ - -$(PKG_FIXTURE_GEN): $(PKG_FIXTURE_OBJS) - $(Q) $(HOSTCC) $(HOSTLDFLAGS) $(PKG_FIXTURE_OBJS) -o $@ - -$(PKG_FIXTURE_OUTPUTS): $(PKG_FIXTURE_STAMP) - -$(PKG_FIXTURE_STAMP): $(BINDIR)/modprint $(BINDIR)/sotest $(PKG_FIXTURE_GEN) - $(Q) ./$(PKG_FIXTURE_GEN) $(BINDIR)/modprint $(BINDIR)/sotest \ - $(PKGSHAREDINDEX) $(PKGSHAREDTEST) $(CONFIG_ARCH) \ - $(PKG_FIXTURE_COMPAT) - $(Q) touch $@ -endif - -$(ROMFSIMG): $(PKG_FIXTURE_OUTPUTS) - $(Q) genromfs -d $(BINDIR) -f $@ - -$(ROMFSSRC): $(ROMFSIMG) - $(Q) (echo "#include <nuttx/compiler.h>" >$@ && \ - xxd -i $(ROMFSIMG) | sed -e "s/^unsigned char/const unsigned char aligned_data(4)/g" >>$@) - -$(ROMFSOBJ): %$(OBJEXT): %.c - $(call COMPILE, $<, $@, -fno-lto -fno-builtin) - -endif - -postinstall:: $(ROMFSOBJ) $(SYMTABOBJ) $(FSIMG_OBJ) - $(call ARLOCK, $(call CONVERT_PATH,$(BIN)), $^) - -distclean:: - $(Q) $(call DELFILE, $(SYMTABSRC) $(SYMTABOBJ) $(ROMFSSRC) $(ROMFSIMG) $(ROMFSOBJ) $(PKG_FIXTURE_GEN) $(PKG_FIXTURE_OBJS) $(PKG_FIXTURE_STAMP)) - -include $(APPDIR)/Application.mk diff --git a/examples/sotest/main/host/CMakeLists.txt b/examples/sotest/main/host/CMakeLists.txt deleted file mode 100644 index e83524d29..000000000 --- a/examples/sotest/main/host/CMakeLists.txt +++ /dev/null @@ -1,26 +0,0 @@ -# ############################################################################## -# apps/examples/sotest/main/host/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -cmake_minimum_required(VERSION 3.16) -project(sotest_fixture_host LANGUAGES C) - -add_executable(mk_pkg_fixture_shared ../mk_pkg_fixture_shared.c) diff --git a/examples/sotest/main/mk_pkg_fixture_shared.c b/examples/sotest/main/mk_pkg_fixture_shared.c deleted file mode 100644 index 713cd7115..000000000 --- a/examples/sotest/main/mk_pkg_fixture_shared.c +++ /dev/null @@ -1,433 +0,0 @@ -/**************************************************************************** - * apps/examples/sotest/main/mk_pkg_fixture_shared.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <errno.h> -#include <stdint.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define SHA256_BLOCK_SIZE 64 -#define SHA256_DIGEST_SIZE 32 - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -struct sha256_state_s -{ - uint32_t state[8]; - uint64_t bitcount; - uint8_t buffer[SHA256_BLOCK_SIZE]; - size_t buffer_len; -}; - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static const uint32_t g_sha256_init[8] = -{ - 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, - 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19 -}; - -static const uint32_t g_sha256_k[64] = -{ - 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, - 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, - 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, - 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, - 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, - 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, - 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, - 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, - 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, - 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, - 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, - 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, - 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, - 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, - 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, - 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2 -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static uint32_t sha256_rotr(uint32_t value, unsigned int bits) -{ - return (value >> bits) | (value << (32 - bits)); -} - -static uint32_t sha256_ch(uint32_t x, uint32_t y, uint32_t z) -{ - return (x & y) ^ (~x & z); -} - -static uint32_t sha256_maj(uint32_t x, uint32_t y, uint32_t z) -{ - return (x & y) ^ (x & z) ^ (y & z); -} - -static uint32_t sha256_bs0(uint32_t x) -{ - return sha256_rotr(x, 2) ^ sha256_rotr(x, 13) ^ sha256_rotr(x, 22); -} - -static uint32_t sha256_bs1(uint32_t x) -{ - return sha256_rotr(x, 6) ^ sha256_rotr(x, 11) ^ sha256_rotr(x, 25); -} - -static uint32_t sha256_ss0(uint32_t x) -{ - return sha256_rotr(x, 7) ^ sha256_rotr(x, 18) ^ (x >> 3); -} - -static uint32_t sha256_ss1(uint32_t x) -{ - return sha256_rotr(x, 17) ^ sha256_rotr(x, 19) ^ (x >> 10); -} - -static uint32_t sha256_load32(const uint8_t *src) -{ - return ((uint32_t)src[0] << 24) | ((uint32_t)src[1] << 16) | - ((uint32_t)src[2] << 8) | (uint32_t)src[3]; -} - -static void sha256_store32(uint8_t *dst, uint32_t value) -{ - dst[0] = (uint8_t)(value >> 24); - dst[1] = (uint8_t)(value >> 16); - dst[2] = (uint8_t)(value >> 8); - dst[3] = (uint8_t)value; -} - -static void sha256_transform(struct sha256_state_s *ctx, - const uint8_t block[SHA256_BLOCK_SIZE]) -{ - uint32_t schedule[64]; - uint32_t a; - uint32_t b; - uint32_t c; - uint32_t d; - uint32_t e; - uint32_t f; - uint32_t g; - uint32_t h; - int i; - - for (i = 0; i < 16; i++) - { - schedule[i] = sha256_load32(block + i * 4); - } - - for (; i < 64; i++) - { - schedule[i] = sha256_ss1(schedule[i - 2]) + schedule[i - 7] + - sha256_ss0(schedule[i - 15]) + schedule[i - 16]; - } - - a = ctx->state[0]; - b = ctx->state[1]; - c = ctx->state[2]; - d = ctx->state[3]; - e = ctx->state[4]; - f = ctx->state[5]; - g = ctx->state[6]; - h = ctx->state[7]; - - for (i = 0; i < 64; i++) - { - uint32_t t1 = h + sha256_bs1(e) + sha256_ch(e, f, g) + g_sha256_k[i] + - schedule[i]; - uint32_t t2 = sha256_bs0(a) + sha256_maj(a, b, c); - - h = g; - g = f; - f = e; - e = d + t1; - d = c; - c = b; - b = a; - a = t1 + t2; - } - - ctx->state[0] += a; - ctx->state[1] += b; - ctx->state[2] += c; - ctx->state[3] += d; - ctx->state[4] += e; - ctx->state[5] += f; - ctx->state[6] += g; - ctx->state[7] += h; -} - -static void sha256_init(struct sha256_state_s *ctx) -{ - memcpy(ctx->state, g_sha256_init, sizeof(g_sha256_init)); - ctx->bitcount = 0; - ctx->buffer_len = 0; -} - -static void sha256_update(struct sha256_state_s *ctx, const uint8_t *data, - size_t len) -{ - ctx->bitcount += (uint64_t)len * 8; - - while (len > 0) - { - size_t space = SHA256_BLOCK_SIZE - ctx->buffer_len; - size_t chunk = len < space ? len : space; - - memcpy(ctx->buffer + ctx->buffer_len, data, chunk); - ctx->buffer_len += chunk; - data += chunk; - len -= chunk; - - if (ctx->buffer_len == SHA256_BLOCK_SIZE) - { - sha256_transform(ctx, ctx->buffer); - ctx->buffer_len = 0; - } - } -} - -static void sha256_final(struct sha256_state_s *ctx, - uint8_t digest[SHA256_DIGEST_SIZE]) -{ - uint8_t length_bytes[8]; - uint8_t padding[SHA256_BLOCK_SIZE] = - { - 0x80 - }; - - int i; - - for (i = 0; i < 8; i++) - { - length_bytes[7 - i] = (uint8_t)(ctx->bitcount >> (i * 8)); - } - - if (ctx->buffer_len < 56) - { - sha256_update(ctx, padding, 56 - ctx->buffer_len); - } - else - { - sha256_update(ctx, padding, SHA256_BLOCK_SIZE - ctx->buffer_len); - sha256_update(ctx, padding + 1, 56); - } - - sha256_update(ctx, length_bytes, sizeof(length_bytes)); - - for (i = 0; i < 8; i++) - { - sha256_store32(digest + i * 4, ctx->state[i]); - } -} - -static int sha256_file(const char *path, char *digest_hex, size_t digest_len) -{ - struct sha256_state_s ctx; - uint8_t digest[SHA256_DIGEST_SIZE]; - uint8_t buffer[4096]; - static const char g_hex[] = "0123456789abcdef"; - FILE *stream; - size_t nread; - int i; - - if (digest_len < SHA256_DIGEST_SIZE * 2 + 1) - { - fprintf(stderr, "digest buffer is too small\n"); - return -1; - } - - stream = fopen(path, "rb"); - if (stream == NULL) - { - fprintf(stderr, "failed to open %s: %s\n", path, strerror(errno)); - return -1; - } - - sha256_init(&ctx); - - while ((nread = fread(buffer, 1, sizeof(buffer), stream)) > 0) - { - sha256_update(&ctx, buffer, nread); - } - - if (ferror(stream) != 0) - { - fprintf(stderr, "failed to read %s: %s\n", path, strerror(errno)); - fclose(stream); - return -1; - } - - fclose(stream); - sha256_final(&ctx, digest); - - for (i = 0; i < SHA256_DIGEST_SIZE; i++) - { - digest_hex[i * 2] = g_hex[digest[i] >> 4]; - digest_hex[i * 2 + 1] = g_hex[digest[i] & 0x0f]; - } - - digest_hex[SHA256_DIGEST_SIZE * 2] = '\0'; - return 0; -} - -static int write_text_file(const char *path, const char *content) -{ - FILE *stream = fopen(path, "w"); - - if (stream == NULL) - { - fprintf(stderr, "failed to open %s: %s\n", path, strerror(errno)); - return -1; - } - - if (fputs(content, stream) == EOF) - { - fprintf(stderr, "failed to write %s: %s\n", path, strerror(errno)); - fclose(stream); - return -1; - } - - if (fclose(stream) != 0) - { - fprintf(stderr, "failed to close %s: %s\n", path, strerror(errno)); - return -1; - } - - return 0; -} - -static int write_index_file(const char *path, const char *arch, - const char *compat, const char *modprint_digest, - const char *sotest_digest) -{ - FILE *stream = fopen(path, "w"); - - if (stream == NULL) - { - fprintf(stderr, "failed to open %s: %s\n", path, strerror(errno)); - return -1; - } - - if (fprintf(stream, - "{\"_nxpkg_source\":\"/etc/nxpkg/index.json\"," - "\"packages\":[" - "{\"name\":\"modprint\",\"version\":\"1.0.0\",\"arch\":\"%s\"," - "\"compat\":\"%s\"," - "\"artifact\":\"modprint\"," - "\"sha256\":\"%s\",\"type\":\"shared-lib\"}," - "{\"name\":\"modprint\",\"version\":\"9.9.9\"," - "\"arch\":\"arm\"," - "\"compat\":\"stm32f4discovery\"," - "\"artifact\":\"modprint\"," - "\"sha256\":\"%s\",\"type\":\"shared-lib\"}," - "{\"name\":\"sotest\",\"version\":\"1.0.0\",\"arch\":\"%s\"," - "\"compat\":\"%s\",\"artifact\":\"sotest\"," - "\"sha256\":\"%s\",\"type\":\"shared-lib\"}," - "{\"name\":\"sotest\",\"version\":\"9.9.9\",\"arch\":\"arm\"," - "\"compat\":\"stm32f4discovery\"," - "\"artifact\":\"sotest\"," - "\"sha256\":\"%s\",\"type\":\"shared-lib\"}" - "]}\n", - arch, compat, modprint_digest, modprint_digest, arch, compat, - sotest_digest, sotest_digest) < 0) - { - fprintf(stderr, "failed to write %s: %s\n", path, strerror(errno)); - fclose(stream); - return -1; - } - - if (fclose(stream) != 0) - { - fprintf(stderr, "failed to close %s: %s\n", path, strerror(errno)); - return -1; - } - - return 0; -} - -static void usage(const char *progname) -{ - fprintf(stderr, - "usage: %s <modprint-bin> <sotest-bin> <shared-index-json> " - "<pkgsotest-nsh> <arch> <compat>\n", - progname); -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -int main(int argc, char *argv[]) -{ - char modprint_digest[SHA256_DIGEST_SIZE * 2 + 1]; - char sotest_digest[SHA256_DIGEST_SIZE * 2 + 1]; - static const char g_pkgsotest[] = - "mount -t tmpfs /etc\n" - "mount -t tmpfs /var\n" - "mkdir /etc/nxpkg\n" - "cp /mnt/sotest/romfs/shared-index.json /etc/nxpkg/index.json\n" - "cp /mnt/sotest/romfs/modprint /etc/nxpkg/modprint\n" - "cp /mnt/sotest/romfs/sotest /etc/nxpkg/sotest\n" - "mkdir /var/lib\n" - "mkdir /var/lib/nxpkg\n" - "cp /mnt/sotest/romfs/shared-index.json /var/lib/nxpkg/index.jsn\n" - "nxpkg install modprint\n" - "nxpkg install sotest\n" - "cp /var/lib/nxpkg/pkgs/modprint/1.0.0/modprint /etc/m\n" - "cp /var/lib/nxpkg/pkgs/sotest/1.0.0/sotest /etc/s\n" - "sotest /etc/m /etc/s\n" - "nxpkg list\n"; - - if (argc != 7) - { - usage(argv[0]); - return EXIT_FAILURE; - } - - if (sha256_file(argv[1], modprint_digest, sizeof(modprint_digest)) < 0 || - sha256_file(argv[2], sotest_digest, sizeof(sotest_digest)) < 0 || - write_index_file(argv[3], argv[5], argv[6], modprint_digest, - sotest_digest) < 0 || - write_text_file(argv[4], g_pkgsotest) < 0) - { - return EXIT_FAILURE; - } - - return EXIT_SUCCESS; -} diff --git a/examples/sotest/modprint/.gitignore b/examples/sotest/modprint/.gitignore deleted file mode 100644 index c7de605bd..000000000 --- a/examples/sotest/modprint/.gitignore +++ /dev/null @@ -1 +0,0 @@ -*.map diff --git a/examples/sotest/modprint/CMakeLists.txt b/examples/sotest/modprint/CMakeLists.txt deleted file mode 100644 index 0fbeef868..000000000 --- a/examples/sotest/modprint/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -# ############################################################################## -# apps/examples/sotest/modprint/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_SOTEST) - nuttx_add_application(NAME modprint SRCS modprint.c DYNLIB y) -endif() diff --git a/examples/sotest/modprint/Kconfig b/examples/sotest/modprint/Kconfig deleted file mode 100644 index f72f3c094..000000000 --- a/examples/sotest/modprint/Kconfig +++ /dev/null @@ -1,4 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# diff --git a/examples/sotest/modprint/Make.defs b/examples/sotest/modprint/Make.defs deleted file mode 100644 index 07811511b..000000000 --- a/examples/sotest/modprint/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/examples/sotest/modprint/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_EXAMPLES_SOTEST),) -CONFIGURED_APPS += $(APPDIR)/examples/sotest/modprint -endif diff --git a/examples/sotest/modprint/Makefile b/examples/sotest/modprint/Makefile deleted file mode 100644 index 81f5c2c53..000000000 --- a/examples/sotest/modprint/Makefile +++ /dev/null @@ -1,30 +0,0 @@ -############################################################################ -# apps/examples/sotest/modprint/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -PROGNAME = modprint -DYNLIB = y - -MAINSRC = modprint.c - -include $(APPDIR)/Application.mk diff --git a/examples/sotest/sotest/.gitignore b/examples/sotest/sotest/.gitignore deleted file mode 100644 index c7de605bd..000000000 --- a/examples/sotest/sotest/.gitignore +++ /dev/null @@ -1 +0,0 @@ -*.map diff --git a/examples/sotest/sotest/CMakeLists.txt b/examples/sotest/sotest/CMakeLists.txt deleted file mode 100644 index d4f30c1c5..000000000 --- a/examples/sotest/sotest/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -# ############################################################################## -# apps/examples/sotest/sotest/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_SOTEST) - nuttx_add_application(NAME sotest SRCS sotest.c DYNLIB y) -endif() diff --git a/examples/sotest/sotest/Kconfig b/examples/sotest/sotest/Kconfig deleted file mode 100644 index f72f3c094..000000000 --- a/examples/sotest/sotest/Kconfig +++ /dev/null @@ -1,4 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# diff --git a/examples/sotest/sotest/Make.defs b/examples/sotest/sotest/Make.defs deleted file mode 100644 index 4a26bb121..000000000 --- a/examples/sotest/sotest/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/examples/sotest/sotest/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_EXAMPLES_SOTEST),) -CONFIGURED_APPS += $(APPDIR)/examples/sotest/sotest -endif diff --git a/examples/sotest/sotest/Makefile b/examples/sotest/sotest/Makefile deleted file mode 100644 index dfbec74a1..000000000 --- a/examples/sotest/sotest/Makefile +++ /dev/null @@ -1,30 +0,0 @@ -############################################################################ -# apps/examples/sotest/sotest/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -PROGNAME = sotest -DYNLIB = y - -MAINSRC = sotest.c - -include $(APPDIR)/Application.mk diff --git a/examples/sotest/main/sotest_main.c b/examples/sotest/sotest_main.c similarity index 65% rename from examples/sotest/main/sotest_main.c rename to examples/sotest/sotest_main.c index 6b2417ddb..0620e6b24 100644 --- a/examples/sotest/main/sotest_main.c +++ b/examples/sotest/sotest_main.c @@ -1,7 +1,5 @@ /**************************************************************************** - * apps/examples/sotest/main/sotest_main.c - * - * SPDX-License-Identifier: Apache-2.0 + * apps/examples/sotest/sotest_main.c * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -37,8 +35,7 @@ #include <syslog.h> #include <dlfcn.h> #include <errno.h> -#include <nuttx/debug.h> -#include <unistd.h> +#include <debug.h> #include <nuttx/symtab.h> @@ -71,39 +68,26 @@ # define SECTORSIZE 64 # define NSECTORS(b) (((b)+SECTORSIZE-1)/SECTORSIZE) -# define BINDIR "/mnt/sotest/romfs" +# define BINDIR "/mnt/romfs" -# ifndef CONFIG_EXAMPLES_SOTEST_DEVMINOR_MAX -# define CONFIG_EXAMPLES_SOTEST_DEVMINOR_MAX 5 +# ifndef CONFIG_EXAMPLES_SOTEST_DEVMINOR +# define CONFIG_EXAMPLES_SOTEST_DEVMINOR 0 +# endif + +# ifndef CONFIG_EXAMPLES_SOTEST_DEVPATH +# define CONFIG_EXAMPLES_SOTEST_DEVPATH "/dev/ram0" # endif #else # define BINDIR CONFIG_EXAMPLES_SOTEST_BINDIR #endif /* CONFIG_EXAMPLES_SOTEST_BUILTINFS */ -#define SOTEST_DEVPATH_FMT "/dev/ram%d" - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static void sotest_show_usage(FAR const char *progname) -{ -#if CONFIG_LIBC_ELF_MAXDEPEND > 0 - fprintf(stderr, - "Usage: %s [--mount] [<modprint-path> <sotest-path>]\n", - progname); -#else - fprintf(stderr, "Usage: %s [--mount] [<sotest-path>]\n", progname); -#endif -} - /**************************************************************************** * Symbols from Auto-Generated Code ****************************************************************************/ #ifdef CONFIG_EXAMPLES_SOTEST_BUILTINFS -extern const unsigned char sotest_romfs_img[]; -extern const unsigned int sotest_romfs_img_len; +extern const unsigned char romfs_img[]; +extern const unsigned int romfs_img_len; #endif extern const struct symtab_s g_sot_exports[]; @@ -119,14 +103,7 @@ extern const int g_sot_nexports; int main(int argc, FAR char *argv[]) { - FAR const char *modprint_path = NULL; - FAR const char *sotest_path = NULL; - bool mount_only = false; -#ifdef CONFIG_EXAMPLES_SOTEST_BUILTINFS - bool mounted_builtinfs = false; - char devname[32]; -#endif -#if CONFIG_LIBC_ELF_MAXDEPEND > 0 +#if CONFIG_MODLIB_MAXDEPEND > 0 FAR void *handle1; #endif FAR void *handle2; @@ -136,38 +113,6 @@ int main(int argc, FAR char *argv[]) #ifdef CONFIG_EXAMPLES_SOTEST_BUILTINFS struct boardioc_romdisk_s desc; #endif - -#if CONFIG_LIBC_ELF_MAXDEPEND > 0 - if (argc == 2 && strcmp(argv[1], "--mount") == 0) - { - mount_only = true; - } - else if (argc == 3) - { - modprint_path = argv[1]; - sotest_path = argv[2]; - } - else if (argc != 1) - { - sotest_show_usage(argv[0]); - return EXIT_FAILURE; - } -#else - if (argc == 2 && strcmp(argv[1], "--mount") == 0) - { - mount_only = true; - } - else if (argc == 2) - { - sotest_path = argv[1]; - } - else if (argc != 1) - { - sotest_show_usage(argv[0]); - return EXIT_FAILURE; - } -#endif - /* Set the shared library symbol table */ ret = dlsymtab((FAR struct symtab_s *)g_sot_exports, g_sot_nexports); @@ -178,91 +123,60 @@ int main(int argc, FAR char *argv[]) } #ifdef CONFIG_EXAMPLES_SOTEST_BUILTINFS - if (sotest_path == NULL || mount_only) - { /* Create a ROM disk for the ROMFS filesystem */ - desc.minor = 0; /* Minor device number of the ROM disk. */ - desc.nsectors = NSECTORS(sotest_romfs_img_len); /* The number of sectors in the ROM disk */ + desc.minor = CONFIG_EXAMPLES_SOTEST_DEVMINOR; /* Minor device number of the ROM disk. */ + desc.nsectors = NSECTORS(romfs_img_len); /* The number of sectors in the ROM disk */ desc.sectsize = SECTORSIZE; /* The size of one sector in bytes */ - desc.image = (FAR uint8_t *)sotest_romfs_img; /* File system image */ + desc.image = (FAR uint8_t *)romfs_img; /* File system image */ - for (; desc.minor <= CONFIG_EXAMPLES_SOTEST_DEVMINOR_MAX; desc.minor++) + printf("main: Registering romdisk at /dev/ram%d\n", + CONFIG_EXAMPLES_SOTEST_DEVMINOR); + + ret = boardctl(BOARDIOC_ROMDISK, (uintptr_t)&desc); + + if (ret < 0) { - syslog(LOG_INFO, "main: Registering romdisk at /dev/ram%d\n", - desc.minor); - - ret = boardctl(BOARDIOC_ROMDISK, (uintptr_t)&desc); - if (ret >= 0) - { - break; - } - - if (errno != EEXIST || - desc.minor == CONFIG_EXAMPLES_SOTEST_DEVMINOR_MAX) - { - fprintf(stderr, "ERROR: romdisk_register failed: %s\n", - strerror(errno)); - exit(EXIT_FAILURE); - } + fprintf(stderr, "ERROR: romdisk_register failed: %s\n", + strerror(errno)); + exit(EXIT_FAILURE); } /* Mount the file system */ - sprintf(devname, SOTEST_DEVPATH_FMT, desc.minor); - syslog(LOG_INFO, "main: Mounting ROMFS filesystem at " - "target=%s with source=%s\n", BINDIR, devname); + printf("main: Mounting ROMFS filesystem at target=%s with source=%s\n", + BINDIR, CONFIG_EXAMPLES_SOTEST_DEVPATH); - ret = mount(devname, BINDIR, "romfs", MS_RDONLY, + ret = mount(CONFIG_EXAMPLES_SOTEST_DEVPATH, BINDIR, "romfs", MS_RDONLY, NULL); if (ret < 0) { fprintf(stderr, "ERROR: mount(%s,%s,romfs) failed: %s\n", - devname, BINDIR, strerror(errno)); + CONFIG_EXAMPLES_SOTEST_DEVPATH, BINDIR, strerror(errno)); exit(EXIT_FAILURE); } - - mounted_builtinfs = true; - } #endif /* CONFIG_EXAMPLES_SOTEST_BUILTINFS */ - if (mount_only) - { - return EXIT_SUCCESS; - } - -#if CONFIG_LIBC_ELF_MAXDEPEND > 0 - if (modprint_path == NULL) - { - modprint_path = BINDIR "/modprint"; - } -#endif - - if (sotest_path == NULL) - { - sotest_path = BINDIR "/sotest"; - } - -#if CONFIG_LIBC_ELF_MAXDEPEND > 0 +#if CONFIG_MODLIB_MAXDEPEND > 0 /* Install the first test shared library. The first shared library only * verifies that symbols exported by one shared library can be used to * resolve undefined symbols in a second shared library. */ - handle1 = dlopen(modprint_path, RTLD_NOW | RTLD_LOCAL); + handle1 = dlopen(BINDIR "/modprint", RTLD_NOW | RTLD_LOCAL); if (handle1 == NULL) { - fprintf(stderr, "ERROR: dlopen(%s) failed\n", modprint_path); + fprintf(stderr, "ERROR: dlopen(/modprint) failed\n"); exit(EXIT_FAILURE); } #endif /* Install the second test shared library */ - handle2 = dlopen(sotest_path, RTLD_NOW | RTLD_LOCAL); + handle2 = dlopen(BINDIR "/sotest", RTLD_NOW | RTLD_LOCAL); if (handle2 == NULL) { - fprintf(stderr, "ERROR: dlopen(%s) failed\n", sotest_path); + fprintf(stderr, "ERROR: dlopen(/sotest) failed\n"); exit(EXIT_FAILURE); } @@ -326,7 +240,7 @@ int main(int argc, FAR char *argv[]) testfunc(msg); -#if CONFIG_LIBC_ELF_MAXDEPEND > 0 +#if CONFIG_MODLIB_MAXDEPEND > 0 /* This should fail because the second shared library depends on * the first. */ @@ -349,7 +263,7 @@ int main(int argc, FAR char *argv[]) exit(EXIT_FAILURE); } -#if CONFIG_LIBC_ELF_MAXDEPEND > 0 +#if CONFIG_MODLIB_MAXDEPEND > 0 /* Now we should be able to close the first shared library. */ ret = dlclose(handle1); @@ -361,17 +275,12 @@ int main(int argc, FAR char *argv[]) #endif #ifdef CONFIG_EXAMPLES_SOTEST_BUILTINFS - if (mounted_builtinfs) + ret = umount(BINDIR); + if (ret < 0) { - ret = umount(BINDIR); - if (ret < 0) - { - fprintf(stderr, "ERROR: umount(%s) failed: %d\n", - BINDIR, errno); - exit(EXIT_FAILURE); - } - - unlink(devname); + fprintf(stderr, "ERROR: umount(%s) failed: %d\n", + BINDIR, errno); + exit(EXIT_FAILURE); } #endif /* CONFIG_EXAMPLES_SOTEST_BUILTINFS */ diff --git a/examples/spislv_test/CMakeLists.txt b/examples/spislv_test/CMakeLists.txt deleted file mode 100644 index 137bc9134..000000000 --- a/examples/spislv_test/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# ############################################################################## -# apps/examples/spislv_test/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_SPISLV) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_SPISLV_PROGNAME} - SRCS - spislv_test.c - STACKSIZE - ${CONFIG_EXAMPLES_SPISLV_STACKSIZE} - PRIORITY - ${CONFIG_EXAMPLES_SPISLV_PRIORITY}) -endif() diff --git a/examples/spislv_test/Kconfig b/examples/spislv_test/Kconfig deleted file mode 100644 index 54dd827c5..000000000 --- a/examples/spislv_test/Kconfig +++ /dev/null @@ -1,36 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config EXAMPLES_SPISLV - tristate "\"SPI Slave Test\" example" - default n - ---help--- - Enable the "SPI Slave Test" example. - This tool can be used together with the SPI tool to validate communication between two devices. - -if EXAMPLES_SPISLV - -config EXAMPLES_SPISLV_DEFAULT_PATH - string "Default SPI Slave device path" - default "/dev/spislv0" - ---help--- - Default path for SPI Slave device - -config EXAMPLES_SPISLV_PROGNAME - string "Program name" - default "spislv" - ---help--- - This is the name of the program that will be used when the NSH ELF - program is installed. - -config EXAMPLES_SPISLV_PRIORITY - int "Spislv task priority" - default 100 - -config EXAMPLES_SPISLV_STACKSIZE - int "Spislv stack size" - default DEFAULT_TASK_STACKSIZE - -endif diff --git a/examples/spislv_test/Make.defs b/examples/spislv_test/Make.defs deleted file mode 100644 index 039cba106..000000000 --- a/examples/spislv_test/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/examples/spislv_test/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_EXAMPLES_SPISLV),) -CONFIGURED_APPS += $(APPDIR)/examples/spislv_test -endif diff --git a/examples/spislv_test/Makefile b/examples/spislv_test/Makefile deleted file mode 100644 index 1fb3e54c5..000000000 --- a/examples/spislv_test/Makefile +++ /dev/null @@ -1,36 +0,0 @@ -############################################################################ -# apps/examples/spislv_test/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -# SPI SLAVE TEST built-in application info - -PROGNAME = $(CONFIG_EXAMPLES_SPISLV_PROGNAME) -PRIORITY = $(CONFIG_EXAMPLES_SPISLV_PRIORITY) -STACKSIZE = $(CONFIG_EXAMPLES_SPISLV_STACKSIZE) -MODULE = $(CONFIG_EXAMPLES_SPISLV) - -# SPI SLAVE TEST Example - -MAINSRC = spislv_test.c - -include $(APPDIR)/Application.mk diff --git a/examples/spislv_test/spislv_test.c b/examples/spislv_test/spislv_test.c deleted file mode 100644 index dcde9fe3a..000000000 --- a/examples/spislv_test/spislv_test.c +++ /dev/null @@ -1,597 +0,0 @@ -/**************************************************************************** - * apps/examples/spislv_test/spislv_test.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <fcntl.h> -#include <errno.h> -#include <unistd.h> -#include <ctype.h> -#include <sys/select.h> - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* Define buffer sizes */ -#define RX_BUFFER_SIZE 64 -#define TX_BUFFER_SIZE 64 -#define DEFAULT_SPI_PATH CONFIG_EXAMPLES_SPISLV_DEFAULT_PATH - -/* Enumeration for operation modes */ - -typedef enum -{ - MODE_WRITE, - MODE_LISTEN, - MODE_ECHO, - MODE_INVALID -} operation_mode_t; - -/**************************************************************************** - * Structure to hold program configurations - ****************************************************************************/ - -typedef struct -{ - operation_mode_t mode; - int num_bytes; /* Applicable for write mode */ - int timeout_seconds; /* Applicable for all modes */ - const char *spi_path; /* SPI slave device path */ - unsigned char tx_buffer[TX_BUFFER_SIZE]; -} program_config_t; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static void print_usage(const char *progname) -{ - fprintf(stderr, "Usage:\n"); - fprintf(stderr, " %s -x <num_bytes> [-p <path>] [-t <sec>] <hex_bytes>\n", - progname); - fprintf(stderr, " %s -l [-p <path>] [-t <sec>]\n", progname); - fprintf(stderr, " %s -e [-p <path>] [-t <sec>]\n", progname); - fprintf(stderr, "\n"); - fprintf(stderr, "Options:\n"); - fprintf(stderr, " -p SPI slave device path [default: %s]\n", - DEFAULT_SPI_PATH); - fprintf(stderr, - " -t Timeout in seconds [default: 10]\n"); - fprintf(stderr, - " -x Number of bytes to queue <hex_bytes>\n"); - fprintf(stderr, - " -l Only listen for data from the master\n"); - fprintf(stderr, - " -e Echo received data back to the master\n"); - fprintf(stderr, "\n"); - fprintf(stderr, "Examples:\n"); - fprintf(stderr, " %s -x 2 abba\n", progname); - fprintf(stderr, " %s -l -t 5\n", progname); - fprintf(stderr, " %s -e -t 10\n", progname); - fprintf(stderr, " %s -p /dev/spislv2 -l\n", progname); -} - -/** - * @brief Converts a single hexadecimal character to its byte value. - * - * @param c The hexadecimal character. - * @return The byte value of the hexadecimal character, or -1 if invalid. - */ - -static int hexchar_to_byte(char c) -{ - if (c >= '0' && c <= '9') - { - return c - '0'; - } - - c = tolower(c); - - if (c >= 'a' && c <= 'f') - { - return c - 'a' + 10; - } - - return -1; -} - -/** - * @brief Converts a hexadecimal string to a byte array. - * - * @param hexstr The input hexadecimal string. - * @param bytes The output byte array. - * @param max_bytes The maximum number of bytes to convert. - * @return The number of bytes converted, or -1 on error. - */ - -static int hexstr_to_bytes(const char *hexstr, unsigned char *bytes, - size_t max_bytes) -{ - int len; - int i; - - len = strlen(hexstr); - if (len % 2 != 0 || len / 2 > max_bytes) - { - return -1; - } - - for (i = 0; i < len / 2; i++) - { - int high = hexchar_to_byte(hexstr[2 * i]); - int low = hexchar_to_byte(hexstr[2 * i + 1]); - - if (high == -1 || low == -1) - { - return -1; - } - - bytes[i] = (high << 4) | low; - } - - return len / 2; -} - -/** - * @brief Parses and validates command-line arguments. - * - * @param argc Argument count. - * @param argv Argument vector. - * @param config Pointer to the program configuration structure. - * @return 0 on success, -1 on failure. - */ - -static int parse_arguments(int argc, char *argv[], - program_config_t *config) -{ - int opt; - - /* Set default configurations */ - - config->mode = MODE_INVALID; - config->num_bytes = 0; - config->timeout_seconds = 10; /* Default timeout */ - config->spi_path = DEFAULT_SPI_PATH; - - /* Parse command-line options */ - - while ((opt = getopt(argc, argv, "p:x:t:le")) != -1) - { - switch (opt) - { - case 'p': - if (optarg[0] == '\0') - { - fprintf(stderr, - "Error: SPI device path (-p) must not be empty.\n"); - return -1; - } - - config->spi_path = optarg; - break; - - case 'x': - if (config->mode != MODE_INVALID) - { - fprintf(stderr, - "Error: Multiple operation modes specified.\n"); - return -1; - } - - config->mode = MODE_WRITE; - config->num_bytes = atoi(optarg); - if (config->num_bytes <= 0 || - config->num_bytes > TX_BUFFER_SIZE) - { - fprintf(stderr, - "Error: Invalid number of bytes for write mode.\n"); - return -1; - } - - break; - - case 't': - config->timeout_seconds = atoi(optarg); - if (config->timeout_seconds <= 0) - { - fprintf(stderr, - "Error: Timeout must be a positive integer.\n"); - return -1; - } - break; - - case 'l': - if (config->mode != MODE_INVALID) - { - fprintf(stderr, - "Error: Multiple operation modes specified.\n"); - return -1; - } - - config->mode = MODE_LISTEN; - break; - - case 'e': - if (config->mode != MODE_INVALID) - { - fprintf(stderr, - "Error: Multiple operation modes specified.\n"); - return -1; - } - - config->mode = MODE_ECHO; - break; - - default: - print_usage(argv[0]); - return -1; - } - } - - /* Validate mutual exclusivity and required arguments */ - - if (config->mode == MODE_WRITE) - { - if (optind >= argc) - { - fprintf(stderr, - "Error: Missing hexadecimal bytes to send.\n"); - print_usage(argv[0]); - return -1; - } - - char *hex_input = argv[optind]; - - /* Verify the hexadecimal string length */ - - if (strlen(hex_input) != (size_t)(config->num_bytes * 2)) - { - fprintf(stderr, - "Error: Hex string length must be %d characters\n" - "for %d bytes.\n", - config->num_bytes * 2, config->num_bytes); - return -1; - } - - /* Convert hexadecimal string to byte array */ - - int converted = hexstr_to_bytes(hex_input, config->tx_buffer, - TX_BUFFER_SIZE); - if (converted != config->num_bytes) - { - fprintf(stderr, "Error: Invalid hexadecimal string.\n"); - return -1; - } - } - - else if (config->mode == MODE_INVALID) - { - fprintf(stderr, "Error: No operation mode specified.\n"); - print_usage(argv[0]); - return -1; - } - - return 0; -} - -/** - * @brief Executes the write mode: sends specified bytes to the master. - * - * @param config Pointer to the program configuration structure. - * @param fd File descriptor for the SPI device. - * @return 0 on success, -1 on failure. - */ - -static int write_mode(program_config_t *config, int fd) -{ - ssize_t bytes_written; - char data_str[3 * TX_BUFFER_SIZE + 1]; /* Buffer for debug string */ - char *ptr = data_str; - int len; - int i; - - for (i = 0; i < config->num_bytes; i++) - { - len = snprintf(ptr, sizeof(data_str) - (ptr - data_str), - "%02X ", config->tx_buffer[i]); - if (len < 0 || len >= (int)(sizeof(data_str) - (ptr - data_str))) - { - break; - } - - ptr += len; - } - - *ptr = '\0'; - - printf("Slave: Queuing %d bytes for sending to master: %s\n", - config->num_bytes, data_str); - - bytes_written = write(fd, config->tx_buffer, config->num_bytes); - if (bytes_written < 0) - { - fprintf(stderr, "Error: Failed to write to %s: %s\n", - config->spi_path, strerror(errno)); - return -1; - } - - else if (bytes_written != config->num_bytes) - { - fprintf(stderr, "Error: Incomplete write. Expected %d, got %zd\n", - config->num_bytes, bytes_written); - return -1; - } - - return 0; -} - -/** - * @brief Executes the listen-only mode: waits for data from the master. - * - * @param config Pointer to the program configuration structure. - * @param fd File descriptor for the SPI device. - * @return 0 on success, -1 on failure. - */ - -static int listen_mode(program_config_t *config, int fd) -{ - printf("Slave: Listen-only mode activated. Waiting for data\n" - " from master.\n"); - - return 0; -} - -/** - * @brief Executes the echo mode: continuously echoes received data to - * the master. - * - * @param config Pointer to the program configuration structure. - * @param fd File descriptor for the SPI device. - * @return 0 on success, -1 on failure. - */ - -static int echo_mode_func(program_config_t *config, int fd) -{ - printf("Slave: Echo mode activated. Will echo received data until\n" - " timeout.\n"); - - return 0; -} - -/** - * @brief Reads data from the SPI device with a specified timeout. - * Depending on the mode, it either exits after the first read or - * continues (echo mode). - * - * @param config Pointer to the program configuration structure. - * @param fd File descriptor for the SPI device. - * @return 0 on success, -1 on failure or timeout. - */ - -static int read_with_timeout(program_config_t *config, int fd) -{ - unsigned char buffer_rx[RX_BUFFER_SIZE]; - ssize_t bytes_read; - ssize_t bytes_written; - int select_ret; - - while (1) - { - fd_set read_fds; - struct timeval timeout; - - FD_ZERO(&read_fds); - FD_SET(fd, &read_fds); - - timeout.tv_sec = config->timeout_seconds; - timeout.tv_usec = 0; - - select_ret = select(fd + 1, &read_fds, - NULL, NULL, &timeout); - if (select_ret == -1) - { - fprintf(stderr, "Error: Select failed: %s\n", - strerror(errno)); - return -1; - } - else if (select_ret == 0) - { - if (config->mode == MODE_ECHO) - { - printf("Communication timeout after %d seconds. No more\n" - "data received from master.\n", - config->timeout_seconds); - } - else - { - printf("Communication timeout after %d seconds. No data\n" - "received from master.\n", - config->timeout_seconds); - } - - return -1; - } - else - { - bytes_read = read(fd, buffer_rx, RX_BUFFER_SIZE); - if (bytes_read < 0) - { - fprintf(stderr, "Error: Failed to read from %s: %s\n", - config->spi_path, strerror(errno)); - return -1; - } - - else if (bytes_read == 0) - { - printf("No data received from master.\n"); - } - - else - { - printf("Data received from master (%zd bytes): ", - bytes_read); - for (int i = 0; i < bytes_read; i++) - { - printf("%02X ", buffer_rx[i]); - } - - printf("\n"); - if (config->mode == MODE_ECHO) - { - bytes_written = write(fd, buffer_rx, - bytes_read); - if (bytes_written < 0) - { - fprintf(stderr, - "Error: Failed to write to %s: %s\n", - config->spi_path, strerror(errno)); - return -1; - } - else if (bytes_written != bytes_read) - { - printf("Error: Incomplete write during echo. "); - fprintf(stderr, "Expected %zd, got %zd\n", - bytes_read, bytes_written); - return -1; - } - - printf("Echoed back %zd bytes to master.\n", - bytes_written); - } - - if (config->mode != MODE_ECHO) - { - break; - } - } - } - } - - return 0; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/** - * @brief Main function orchestrating the SPI slave operations based on - * user input. - * - * @param argc Argument count. - * @param argv Argument vector. - * @return 0 on success, -1 on failure. - */ - -int main(int argc, char *argv[]) -{ - program_config_t config; - int fd; - int ret = 0; - - if (parse_arguments(argc, argv, &config) != 0) - { - return -1; - } - - fd = open(config.spi_path, O_RDWR); - if (fd < 0) - { - fprintf(stderr, "Error: Failed to open %s: %s\n", - config.spi_path, strerror(errno)); - return -1; - } - - /* Ensure the file descriptor is in blocking mode */ - - int flags = fcntl(fd, F_GETFL, 0); - if (flags == -1) - { - fprintf(stderr, "Error: Failed to get file flags: %s\n", - strerror(errno)); - close(fd); - return -1; - } - - flags &= ~O_NONBLOCK; - if (fcntl(fd, F_SETFL, flags) == -1) - { - fprintf(stderr, "Error: Failed to set blocking mode: %s\n", - strerror(errno)); - close(fd); - return -1; - } - - /* Execute the selected mode */ - - switch (config.mode) - { - case MODE_WRITE: - ret = write_mode(&config, fd); - if (ret != 0) - { - close(fd); - return -1; - } - break; - - case MODE_LISTEN: - ret = listen_mode(&config, fd); - if (ret != 0) - { - close(fd); - return -1; - } - break; - - case MODE_ECHO: - ret = echo_mode_func(&config, fd); - if (ret != 0) - { - close(fd); - return -1; - } - break; - - default: - fprintf(stderr, "Error: Invalid operation mode.\n"); - close(fd); - return -1; - } - - ret = read_with_timeout(&config, fd); - if (ret != 0) - { - close(fd); - return -1; - } - - printf("\n"); - close(fd); - return 0; -} diff --git a/examples/stat/CMakeLists.txt b/examples/stat/CMakeLists.txt deleted file mode 100644 index c355cfa7d..000000000 --- a/examples/stat/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# ############################################################################## -# apps/examples/stat/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_STAT) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_STAT_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_STAT_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_STAT_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_STAT} - SRCS - stat_main.c) -endif() diff --git a/examples/stat/Make.defs b/examples/stat/Make.defs index c965dbda0..7532ebb25 100644 --- a/examples/stat/Make.defs +++ b/examples/stat/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/stat/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/stat/Makefile b/examples/stat/Makefile index afbb053a4..c86c9d03b 100644 --- a/examples/stat/Makefile +++ b/examples/stat/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/stat/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/stat/stat_main.c b/examples/stat/stat_main.c index fa04f7add..e3b962dd5 100644 --- a/examples/stat/stat_main.c +++ b/examples/stat/stat_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/stat/stat_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -33,7 +31,6 @@ #include <string.h> #include <fcntl.h> #include <errno.h> -#include <unistd.h> /**************************************************************************** * Private Data diff --git a/examples/stepper/CMakeLists.txt b/examples/stepper/CMakeLists.txt deleted file mode 100644 index d8e89647c..000000000 --- a/examples/stepper/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# ############################################################################## -# apps/examples/stepper/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_STEPPER) - nuttx_add_application( - NAME - stepper - STACKSIZE - ${CONFIG_DEFAULT_TASK_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_STEPPER} - SRCS - stepper.c) -endif() diff --git a/examples/stepper/Kconfig b/examples/stepper/Kconfig deleted file mode 100644 index 6294b96b1..000000000 --- a/examples/stepper/Kconfig +++ /dev/null @@ -1,10 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config EXAMPLES_STEPPER - tristate "Stepper controller test" - default n - ---help--- - Enable the stepper controller test diff --git a/examples/stepper/Make.defs b/examples/stepper/Make.defs deleted file mode 100644 index 859b09637..000000000 --- a/examples/stepper/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/examples/stepper/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_EXAMPLES_STEPPER),) -CONFIGURED_APPS += $(APPDIR)/examples/stepper -endif diff --git a/examples/stepper/Makefile b/examples/stepper/Makefile deleted file mode 100644 index ae9bad0c2..000000000 --- a/examples/stepper/Makefile +++ /dev/null @@ -1,36 +0,0 @@ -############################################################################ -# apps/examples/stepper/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -# Stepper example - -MAINSRC = stepper.c - -# stepper built-in application info - -PROGNAME = stepper -PRIORITY = SCHED_PRIORITY_DEFAULT -STACKSIZE = $(CONFIG_DEFAULT_TASK_STACKSIZE) -MODULE = $(CONFIG_EXAMPLES_STEPPER) - -include $(APPDIR)/Application.mk diff --git a/examples/stepper/stepper.c b/examples/stepper/stepper.c deleted file mode 100644 index 2d9acdaff..000000000 --- a/examples/stepper/stepper.c +++ /dev/null @@ -1,165 +0,0 @@ -/**************************************************************************** - * apps/examples/stepper/stepper.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <sys/ioctl.h> -#include <fcntl.h> -#include <stdio.h> -#include <stdbool.h> - -#include <nuttx/motor/stepper.h> - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -struct stepper_args -{ - FAR const char *path; - int microstep; - int speed; - int steps; -}; - -static int parse_args(int argc, FAR char *argv[], - FAR struct stepper_args *args) -{ - int i; - - if (argc < 3) - { - return -1; - } - - args->path = argv[1]; - args->microstep = -1; - args->speed = 200; - - for (i = 2; i < argc; ++i) - { - if (strncmp("-m", argv[i], 2) == 0) - { - i++; - if (i >= argc) - { - return -1; - } - - args->microstep = atoi(argv[i]); - i++; - } - - if (strncmp("-s", argv[i], 2) == 0) - { - i++; - if (i >= argc) - { - return -1; - } - - args->speed = atoi(argv[i]); - i++; - } - } - - args->steps = atoi(argv[argc - 1]); - return 0; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -int main(int argc, FAR char *argv[]) -{ - struct stepper_args args; - struct stepper_status_s status; - struct stepper_job_s job; - int fd; - int rc; - - if (parse_args(argc, argv, &args) < 0) - { - printf("usage:\n" - "stepper path\n" - " [-m microstep (sticky)]\n" - " [-s speed in steps/s (default 200)]\n" - " steps (positive: CW, negative: CCW)\n"); - return 1; - } - - fd = open(args.path, O_RDWR); - if (fd < 0) - { - printf("Oops: %s\n", strerror(errno)); - exit(1); - } - - if (args.microstep > 0) - { - printf("Set microstepping to %d\n", args.microstep); - rc = ioctl(fd, STEPIOC_MICROSTEPPING, args.microstep); - if (rc < 0) - { - printf("STEPIOC_MICROSTEPPING: %s\n", strerror(errno)); - exit(2); - } - } - - job.steps = args.steps; - job.speed = args.speed; - - /* Retrieve the absolute position - before movement */ - - rc = read(fd, &status, sizeof(struct stepper_status_s)); - if (rc != sizeof(struct stepper_status_s)) - { - printf("read: %s\n", strerror(errno)); - } - - printf("Position before stepper motor moving: %ld\n", status.position); - - /* Move the stepper */ - - printf("GO -> %ld @ %ld steps/s\n", job.steps, job.speed); - - rc = write(fd, &job, sizeof(struct stepper_job_s)); /* blocking */ - if (rc != sizeof(struct stepper_job_s)) - { - printf("write: %s\n", strerror(errno)); - } - - /* Retrieve the absolute position - after movement */ - - rc = read(fd, &status, sizeof(struct stepper_status_s)); - if (rc != sizeof(struct stepper_status_s)) - { - printf("read: %s\n", strerror(errno)); - } - - printf("Position after stepper motor moving: %ld\n", status.position); - - return 0; -} diff --git a/examples/sx127x_demo/CMakeLists.txt b/examples/sx127x_demo/CMakeLists.txt deleted file mode 100644 index b9982b87c..000000000 --- a/examples/sx127x_demo/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# ############################################################################## -# apps/examples/sx127x_demo/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_SX127X) - nuttx_add_application( - NAME - sx127x - STACKSIZE - ${CONFIG_DEFAULT_TASK_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_SX127X} - SRCS - sx127x_demo.c) -endif() diff --git a/examples/sx127x_demo/Make.defs b/examples/sx127x_demo/Make.defs index f569360a6..226a09820 100644 --- a/examples/sx127x_demo/Make.defs +++ b/examples/sx127x_demo/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/sx127x_demo/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/sx127x_demo/Makefile b/examples/sx127x_demo/Makefile index d24378ee6..e97f14ebd 100644 --- a/examples/sx127x_demo/Makefile +++ b/examples/sx127x_demo/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/sx127x_demo/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/sx127x_demo/sx127x_demo.c b/examples/sx127x_demo/sx127x_demo.c index a93fe74fe..50b4ee7de 100644 --- a/examples/sx127x_demo/sx127x_demo.c +++ b/examples/sx127x_demo/sx127x_demo.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/sx127x_demo/sx127x_demo.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -30,6 +28,7 @@ #include <sys/stat.h> #include <sys/ioctl.h> +#include <unistd.h> #include <stdint.h> #include <stdbool.h> #include <stdio.h> @@ -37,7 +36,7 @@ #include <string.h> #include <stdlib.h> #include <errno.h> -#include <nuttx/debug.h> +#include <debug.h> #include <poll.h> #include <fcntl.h> @@ -465,7 +464,7 @@ int main(int argc, FAR char *argv[]) if (ret != OK) { printf("sx127x_main: validate arguments failed!\n"); - return 0; + goto errout; } printf("Start sx127x_demo\n"); @@ -477,7 +476,7 @@ int main(int argc, FAR char *argv[]) { int errcode = errno; printf("ERROR: Failed to open device %s: %d\n", DEV_NAME, errcode); - return 0; + goto errout; } /* Set modulation */ diff --git a/examples/system/CMakeLists.txt b/examples/system/CMakeLists.txt deleted file mode 100644 index 23ad26812..000000000 --- a/examples/system/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# ############################################################################## -# apps/examples/system/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_SYSTEM) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_SYSTEM_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_SYSTEM_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_SYSTEM_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_SYSTEM} - SRCS - system_main.c) -endif() diff --git a/examples/system/Make.defs b/examples/system/Make.defs index ab6d63674..2e624e8fe 100644 --- a/examples/system/Make.defs +++ b/examples/system/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/system/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/system/Makefile b/examples/system/Makefile index ad4d9ba1d..19aa8750c 100644 --- a/examples/system/Makefile +++ b/examples/system/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/system/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/system/system_main.c b/examples/system/system_main.c index b0ff68d90..7b48e5bc8 100644 --- a/examples/system/system_main.c +++ b/examples/system/system_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/system/system_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -29,10 +27,6 @@ #include <stdio.h> #include <stdlib.h> -/**************************************************************************** - * Public Functions - ****************************************************************************/ - /**************************************************************************** * Name: system_main ****************************************************************************/ diff --git a/examples/tcp_ipc_client/CMakeLists.txt b/examples/tcp_ipc_client/CMakeLists.txt deleted file mode 100644 index 2a82875ba..000000000 --- a/examples/tcp_ipc_client/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# ############################################################################## -# apps/examples/tcp_ipc_client/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_TCP_IPC_CLIENT) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_TCP_IPC_CLIENT_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_TCP_IPC_CLIENT_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_TCP_IPC_CLIENT_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_TCP_IPC_CLIENT} - SRCS - tcp_ipc_client_main.c) -endif() diff --git a/examples/tcp_ipc_client/Kconfig b/examples/tcp_ipc_client/Kconfig deleted file mode 100644 index b63a303a8..000000000 --- a/examples/tcp_ipc_client/Kconfig +++ /dev/null @@ -1,37 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config EXAMPLES_TCP_IPC_CLIENT - bool "Client for TCP IPC NuttX" - default n - select ARCH_HAVE_NET - select ARCH_HAVE_NETDEV_STATISTICS - select NET_READAHEAD - select NET_TCP - select NET - select NET_SOCKOPTS - select NET_LOOPBACK - select NETDEV_LATEINIT - select SCHED_HPWORK - ---help--- - Enable the Client for TCP IPC NuttX example - -config EXAMPLES_TCP_IPC_CLIENT_PROGNAME - string "Program name" - default "CLIENT" - depends on EXAMPLES_TCP_IPC_CLIENT - ---help--- - This is the name of the program that will be used when the NSH ELF - program is installed. - -config EXAMPLES_TCP_IPC_CLIENT_PRIORITY - int "CLIENT task priority" - default 100 - depends on EXAMPLES_TCP_IPC_CLIENT - -config EXAMPLES_TCP_IPC_CLIENT_STACKSIZE - int "CLIENT stack size" - default 8192 - depends on EXAMPLES_TCP_IPC_CLIENT diff --git a/examples/tcp_ipc_client/Make.defs b/examples/tcp_ipc_client/Make.defs deleted file mode 100644 index e55733809..000000000 --- a/examples/tcp_ipc_client/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/examples/tcp_ipc_client/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_EXAMPLES_TCP_IPC_CLIENT),) -CONFIGURED_APPS += $(APPDIR)/examples/tcp_ipc_client -endif diff --git a/examples/tcp_ipc_client/Makefile b/examples/tcp_ipc_client/Makefile deleted file mode 100644 index fe60b4732..000000000 --- a/examples/tcp_ipc_client/Makefile +++ /dev/null @@ -1,36 +0,0 @@ -############################################################################ -# apps/examples/tcp_ipc_client/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -# Client tcp built-in application info - -PROGNAME = $(CONFIG_EXAMPLES_TCP_IPC_CLIENT_PROGNAME) -PRIORITY = $(CONFIG_EXAMPLES_TCP_IPC_CLIENT_PRIORITY) -STACKSIZE = $(CONFIG_EXAMPLES_TCP_IPC_CLIENT_STACKSIZE) -MODULE = $(CONFIG_EXAMPLES_TCP_IPC_CLIENT) - -# Client tcp Example - -MAINSRC = tcp_ipc_client_main.c - -include $(APPDIR)/Application.mk diff --git a/examples/tcp_ipc_client/protocol.h b/examples/tcp_ipc_client/protocol.h deleted file mode 100644 index 7e8f188be..000000000 --- a/examples/tcp_ipc_client/protocol.h +++ /dev/null @@ -1,43 +0,0 @@ -/**************************************************************************** - * apps/examples/tcp_ipc_client/protocol.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __APPS_EXAMPLES_TCP_IPC_CLIENT_PROTOCOL_H -#define __APPS_EXAMPLES_TCP_IPC_CLIENT_PROTOCOL_H - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -typedef struct -{ - unsigned char opcode; - unsigned char msg_size; - unsigned char msg[12]; -} protocolo_ipc; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -void send_msg_to_lpwan (unsigned char *msg, protocolo_ipc *pt_protocol); - -#endif /* __APPS_EXAMPLES_TCP_IPC_CLIENT_PROTOCOL_H */ diff --git a/examples/tcp_ipc_client/tcp_ipc_client_main.c b/examples/tcp_ipc_client/tcp_ipc_client_main.c deleted file mode 100644 index f1d5943ef..000000000 --- a/examples/tcp_ipc_client/tcp_ipc_client_main.c +++ /dev/null @@ -1,201 +0,0 @@ -/**************************************************************************** - * apps/examples/tcp_ipc_client/tcp_ipc_client_main.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/* This program consists of a client socket & custom messages that send - * data (hex-string formatted data) to a server (server_tcp). Then, - * server_tcp send this data over LoraWAN (using Radioenge LoRaWAn module) - * Both client and server work on local network. - * IMPORTANT NOTE: - * In order to test client_tcp & server_tcp together, there are two - * ways to proceed: - * 1) Init server manually (command: SERVER &), and after successfull - * server init, also init client manually (CLIENT 127.0.0.1) - * 2) Init server automatically after boot using NuttShell start up scripts. - */ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <sys/socket.h> -#include <sys/types.h> -#include <netinet/in.h> -#include <netdb.h> -#include <stdio.h> -#include <string.h> -#include <stdlib.h> -#include <unistd.h> -#include <errno.h> -#include <arpa/inet.h> - -#include "protocol.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static void show_usage(FAR const char *progname) -{ - fprintf(stderr, "USAGE: %s <Server-IP>\n", progname); - fprintf(stderr, " %s -h\n", progname); - fprintf(stderr, "Where:\n"); - fprintf(stderr, "\t<<Server-IP>: IP of server TCP/IP socket for IPC.\n"); -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -#define SOCKET_PORT 5000 -#define TCP_DATA_RCV_WITHOUT_FLAGS 0 -#define RCV_BUFFER_SIZE 520 -#define SEND_BUFFER_SIZE 500 -#define TIME_SECONDS_TO_SEND_NEXT_DATA 15 - -/**************************************************************************** - * Client_tcp_main - ****************************************************************************/ - -int main(int argc, char *argv[]) -{ - int socket_client = 0; - char rcv_buffer[RCV_BUFFER_SIZE]; - char buffer_to_send[SEND_BUFFER_SIZE]; - int bytes_read_from_server = 0; - struct sockaddr_in serv_addr; - protocolo_ipc tprotocol; - - /* Check if there are sufficient arguments passed to this program */ - - if (argc != 2) - { - printf("\nNot enough parameters: %s.\n", argv[0]); - return 1; - } - - if (strcmp(argv[1], "-h") == 0) - { - show_usage(argv[0]); - return EXIT_FAILURE; - } - - /* Create client socket */ - - memset(rcv_buffer, 0x00, sizeof(rcv_buffer)); - socket_client = socket(AF_INET, SOCK_STREAM, 0); - if (socket_client < 0) - { - perror("Failed to create client socket"); - exit(EXIT_FAILURE); - } - - /* Connect to server socket */ - - memset(&serv_addr, 0x00, sizeof(serv_addr)); - serv_addr.sin_family = AF_INET; - serv_addr.sin_port = htons(SOCKET_PORT); - - if (inet_pton(AF_INET, argv[1], &serv_addr.sin_addr) <= 0) - { - perror("Failed when executing inet_pton()"); - exit(EXIT_FAILURE); - } - - if (connect(socket_client, (struct sockaddr *)&serv_addr, - sizeof(serv_addr)) < 0) - { - perror("Failed to connect to server socket"); - exit(EXIT_FAILURE); - } - - /* Countinuosly send server data to be forwarded to LPWAN transceiver */ - - while (1) - { - /* Formats message to be sent to server (opcode, message size - * and message content) - */ - - tprotocol.opcode = 'U'; - tprotocol.msg_size = 4; - snprintf((char *)tprotocol.msg, sizeof(tprotocol.msg), "0102"); - - /* Send message to server */ - - memcpy(buffer_to_send, (unsigned char *)&tprotocol, - sizeof(protocolo_ipc)); - write(socket_client, buffer_to_send, strlen(buffer_to_send)); - printf("Message sent to server!\n\n"); - - /* Waits for server response */ - - bytes_read_from_server = recv(socket_client, rcv_buffer, - sizeof(protocolo_ipc), - TCP_DATA_RCV_WITHOUT_FLAGS); - - if (bytes_read_from_server < 0) - { - perror("Failed to get server response"); - exit(EXIT_FAILURE); - } - else - { - /* Server response successfully received. Print it on the screen */ - - memcpy((unsigned char *)&tprotocol, rcv_buffer, - sizeof(protocolo_ipc)); - printf("Protocol: opcode: %c\n", tprotocol.opcode); - printf("Protocol: message size: %d\n", tprotocol.msg_size); - printf("Protocol: message: %s\n", tprotocol.msg); - } - - /* Wait to send again */ - - sleep(TIME_SECONDS_TO_SEND_NEXT_DATA); - } - - return 0; -} diff --git a/examples/tcp_ipc_server/CMakeLists.txt b/examples/tcp_ipc_server/CMakeLists.txt deleted file mode 100644 index cf1174d9d..000000000 --- a/examples/tcp_ipc_server/CMakeLists.txt +++ /dev/null @@ -1,38 +0,0 @@ -# ############################################################################## -# apps/examples/tcp_ipc_server/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_TCP_IPC_SERVER) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_TCP_IPC_SERVER_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_TCP_IPC_SERVER_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_TCP_IPC_SERVER_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_TCP_IPC_SERVER} - SRCS - tcp_ipc_server_main.c - INCLUDE_DIRECTORIES - ${CMAKE_CURRENT_LIST_DIR}/lorawan) - target_sources(apps PRIVATE uart_lorawan_layer.c protocol.c) -endif() diff --git a/examples/tcp_ipc_server/Kconfig b/examples/tcp_ipc_server/Kconfig deleted file mode 100644 index c1f9634db..000000000 --- a/examples/tcp_ipc_server/Kconfig +++ /dev/null @@ -1,37 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config EXAMPLES_TCP_IPC_SERVER - bool "Server for TCP IPC NuttX" - default n - select ARCH_HAVE_NET - select ARCH_HAVE_NETDEV_STATISTICS - select NET_READAHEAD - select NET_TCP - select NET - select NET_SOCKOPTS - select NET_LOOPBACK - select NETDEV_LATEINIT - select SCHED_HPWORK - ---help--- - Enable the TCP SERVER example - -config EXAMPLES_TCP_IPC_SERVER_PROGNAME - string "Program name" - default "SERVER" - depends on EXAMPLES_TCP_IPC_SERVER - ---help--- - This is the name of the program that will be used when the NSH ELF - program is installed. - -config EXAMPLES_TCP_IPC_SERVER_PRIORITY - int "SERVER task priority" - default 100 - depends on EXAMPLES_TCP_IPC_SERVER - -config EXAMPLES_TCP_IPC_SERVER_STACKSIZE - int "SERVER stack size" - default DEFAULT_TASK_STACKSIZE - depends on EXAMPLES_TCP_IPC_SERVER diff --git a/examples/tcp_ipc_server/Make.defs b/examples/tcp_ipc_server/Make.defs deleted file mode 100644 index ea9f3533c..000000000 --- a/examples/tcp_ipc_server/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/examples/tcp_ipc_server/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_EXAMPLES_TCP_IPC_SERVER),) -CONFIGURED_APPS += $(APPDIR)/examples/tcp_ipc_server -endif diff --git a/examples/tcp_ipc_server/Makefile b/examples/tcp_ipc_server/Makefile deleted file mode 100644 index 6a9fd9227..000000000 --- a/examples/tcp_ipc_server/Makefile +++ /dev/null @@ -1,38 +0,0 @@ -############################################################################ -# apps/examples/tcp_ipc_server/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -# Server TCP built-in application info - -PROGNAME = $(CONFIG_EXAMPLES_TCP_IPC_SERVER_PROGNAME) -PRIORITY = $(CONFIG_EXAMPLES_TCP_IPC_SERVER_PRIORITY) -STACKSIZE = $(CONFIG_EXAMPLES_TCP_IPC_SERVER_STACKSIZE) -MODULE = $(CONFIG_EXAMPLES_TCP_IPC_SERVER) - -# Server TCP Example -CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/examples/tcp_ipc_server/lorawan -CSRCS = uart_lorawan_layer.c protocol.c - -MAINSRC = tcp_ipc_server_main.c - -include $(APPDIR)/Application.mk diff --git a/examples/tcp_ipc_server/lorawan/uart_lorawan_layer.h b/examples/tcp_ipc_server/lorawan/uart_lorawan_layer.h deleted file mode 100644 index 10f45ca6a..000000000 --- a/examples/tcp_ipc_server/lorawan/uart_lorawan_layer.h +++ /dev/null @@ -1,60 +0,0 @@ -/**************************************************************************** - * apps/examples/tcp_ipc_server/lorawan/uart_lorawan_layer.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __APPS_EXAMPLES_TCP_IPC_SERVER_LORAWAN_H -#define __APPS_EXAMPLES_TCP_IPC_SERVER_LORAWAN_H - -/**************************************************************************** - * Definitions - ****************************************************************************/ -#define APP_SESSION_KEY_SIZE 60 -#define NW_SESSION_KEY_SIZE 60 -#define APP_EUI_SIZE 30 -#define DEVICE_ADDRESS_SIZE 15 -#define CHANNEL_MASK_SIZE 35 -#define ERR_AT_BUSY_ERROR -1 - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -typedef struct -{ - char application_session_key[APP_SESSION_KEY_SIZE]; - char network_session_key[NW_SESSION_KEY_SIZE]; - char application_eui[APP_EUI_SIZE]; - char device_address[DEVICE_ADDRESS_SIZE]; - char channel_mask[CHANNEL_MASK_SIZE]; -} config_lorawan_radioenge_t; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -void lorawan_radioenge_init(config_lorawan_radioenge_t config_lorawan); -int lorawan_radioenge_send_msg(unsigned char * pt_payload_uplink_hexstring, - int size_uplink, - unsigned char * pt_payload_downlink_hexstring, - int max_size_downlink, - int time_to_wait_ms); - -#endif /* __APPS_EXAMPLES_TCP_IPC_SERVER_LORAWAN_H */ diff --git a/examples/tcp_ipc_server/protocol.c b/examples/tcp_ipc_server/protocol.c deleted file mode 100644 index 9449faf4b..000000000 --- a/examples/tcp_ipc_server/protocol.c +++ /dev/null @@ -1,119 +0,0 @@ -/**************************************************************************** - * apps/examples/tcp_ipc_server/protocol.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include "lorawan/uart_lorawan_layer.h" -#include "protocol.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -#define LORAWAN_DOWNLINK_TIME_MS 10000 -#define MAX_MESSAGE_SIZE 12 -#define SEND_MESSAGE 'U' -#define DOWNLINK_RESPONSE 'D' - -/**************************************************************************** - * Name: send_msg_to_lpwan - * Description: function that parses received message from a client and - * sends a message to UART LoRaWAN layer based on parsed - * data. - * Parameters: - pointer to char array containing received message from - * client - * - pointer to a protocol structure variable, which will contain - * the response to be sent back to client - * Return: nothing - ****************************************************************************/ - -void send_msg_to_lpwan(unsigned char *msg, protocolo_ipc *pt_protocol) -{ - protocolo_ipc tprotocol; - unsigned char buf_recv_downlink[12]; - int bytes_recv = 0; - - memcpy((unsigned char *)&tprotocol, msg, sizeof(protocolo_ipc)); - - /* Parse message accordingly to received opcode */ - - switch (tprotocol.opcode) - { - case SEND_MESSAGE: - /* A client wants to send a LoRaWAN message. Here, the message is - * forwarded to LoRaWAN transceiver - */ - - memset(buf_recv_downlink, 0x00, sizeof(buf_recv_downlink)); - bytes_recv = lorawan_radioenge_send_msg(tprotocol.msg, - tprotocol.msg_size, - buf_recv_downlink, - sizeof(buf_recv_downlink), - LORAWAN_DOWNLINK_TIME_MS); - printf("Number of Downlink bytes received: %d\n\n", bytes_recv); - - if (bytes_recv < MAX_MESSAGE_SIZE) - { - pt_protocol->opcode = DOWNLINK_RESPONSE; - pt_protocol->msg_size = (unsigned char) bytes_recv; - snprintf((char *)pt_protocol->msg, MAX_MESSAGE_SIZE, "%s", - buf_recv_downlink); - } - break; - - default: - break; - } -} diff --git a/examples/tcp_ipc_server/protocol.h b/examples/tcp_ipc_server/protocol.h deleted file mode 100644 index 5031977d2..000000000 --- a/examples/tcp_ipc_server/protocol.h +++ /dev/null @@ -1,43 +0,0 @@ -/**************************************************************************** - * apps/examples/tcp_ipc_server/protocol.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __APPS_EXAMPLES_SERVER_TCP_PROTOCOL_H -#define __APPS_EXAMPLES_SERVER_TCP_PROTOCOL_H - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -typedef struct -{ - unsigned char opcode; - unsigned char msg_size; - unsigned char msg[12]; -} protocolo_ipc; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -void send_msg_to_lpwan (unsigned char *msg, protocolo_ipc *pt_protocol); - -#endif /* __APPS_EXAMPLES_SERVER_TCP_PROTOCOL_H */ diff --git a/examples/tcp_ipc_server/tcp_ipc_server_main.c b/examples/tcp_ipc_server/tcp_ipc_server_main.c deleted file mode 100644 index af9aff823..000000000 --- a/examples/tcp_ipc_server/tcp_ipc_server_main.c +++ /dev/null @@ -1,278 +0,0 @@ -/**************************************************************************** - * apps/examples/tcp_ipc_server/tcp_ipc_server_main.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/* This program consists of a server socket & custom messages to establish - * IPC for multiple applications (clients) and one process that controls - * LoRaWAN connectivity (server). Both client and server work on local - * network. - * For more details about client side, see client-tcp example. - * - * IMPORTANT NOTE: - * In order to test client_tcp & server_tcp together, there are two - * ways to proceed: - * 1) Init server manually (command: SERVER &), and after successfull - * server init, also init client manually (CLIENT 127.0.0.1) - * 2) init server automatically after boot using NuttShell start up scripts. - */ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <stdio.h> -#include <stdlib.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <string.h> -#include <arpa/inet.h> -#include <fcntl.h> -#include <unistd.h> -#include <pthread.h> - -#include "protocol.h" -#include "lorawan/uart_lorawan_layer.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static int socket_clients_counter; - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static void *thread_socket_client(void *arg); - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -#define SOCKET_PORT 5000 -#define TX_BUFFER_SIZE 200 -#define RX_BUFFER_SIZE 150 -#define TCP_NO_FLAGS_WHEN_SENDING_DATA 0 -#define IP_SERVER "127.0.0.1" -#define MAX_PENDING_SOCKET_CONNECTIONS 20 -#define TIME_TO_CHECK_FOR_NEW_CLIENTS 500000 - -/**************************************************************************** - * Name: thread_socket_client - * Description: socket client thread. Each sonnected cleint socket will - * instantiate a thread, which handles all data traffic between - * this client and server. - * Parameters: thread arguments (in this case, file descriptor of client - * socket) - * Return: nothing - ****************************************************************************/ - -static void *thread_socket_client(void *arg) -{ - int socket_client_fd = *((int *)arg); - char tx_buffer[TX_BUFFER_SIZE]; - unsigned char rx_buffer[RX_BUFFER_SIZE]; - int bytes_read_from_server = 0; - int ret_send = 0; - protocolo_ipc tprotocol; - - memset(tx_buffer, 0x00, sizeof(tx_buffer)); - memset(rx_buffer, 0x00, sizeof(rx_buffer)); - - while (1) - { - bytes_read_from_server = read(socket_client_fd, - rx_buffer, - RX_BUFFER_SIZE); - - if (bytes_read_from_server == 0) - { - /* Socket disconnection has been detected. - * This thread will be terminated. - */ - - printf("\n\rDisconnection has been detected.\n\r"); - break; - } - else - { - printf("Client request received! Comm. with client...\n"); - send_msg_to_lpwan (rx_buffer, &tprotocol); - if (tprotocol.msg_size >= 0) - { - memcpy(tx_buffer, - (unsigned char *)&tprotocol, - sizeof(protocolo_ipc)); - ret_send = send(socket_client_fd, - tx_buffer, - sizeof(protocolo_ipc), - TCP_NO_FLAGS_WHEN_SENDING_DATA); - - if (ret_send > 0) - { - printf("\r\nSucess: %d bytes sent to client\r\n", - ret_send); - } - else - { - printf("\r\nError: fail to send %d bytes to client\r\n", - strlen(tx_buffer)); - } - } - else - { - printf("ERROR: invalid message size (<0)\n"); - } - } - } - - /* Terminate this thread */ - - close(socket_client_fd); - socket_clients_counter--; - pthread_exit(NULL); -} - -/**************************************************************************** - * Server_tcp_main - ****************************************************************************/ - -int main(int argc, char *argv[]) -{ - int socket_server_fd = 0; - int new_socket_client_fd = 0; - int ret_bind = 0; - struct sockaddr_in server_add; - struct sockaddr_storage server_storage; - socklen_t addr_size; - pthread_t tid[MAX_PENDING_SOCKET_CONNECTIONS]; - config_lorawan_radioenge_t lora_config; - - socket_clients_counter = 0; - - /* Configuring LoRaWAN credentials */ - - snprintf(lora_config.application_session_key, APP_SESSION_KEY_SIZE, - "00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00"); - snprintf(lora_config.network_session_key, NW_SESSION_KEY_SIZE, - "00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00"); - snprintf(lora_config.application_eui, APP_EUI_SIZE, - "00:00:00:00:00:00:00:00"); - snprintf(lora_config.device_address, DEVICE_ADDRESS_SIZE, - "00:00:00:00"); - snprintf(lora_config.channel_mask, CHANNEL_MASK_SIZE, - "00FF:0000:0000:0000:0000:0000"); - lorawan_radioenge_init(lora_config); - - /* Create socket (server) */ - - socket_server_fd = socket(PF_INET, SOCK_STREAM, 0); - if (socket_server_fd == 0) - { - perror("Failed to create server socket"); - exit(EXIT_FAILURE); - } - - /* Fill addr structure and do socket bind operation */ - - server_add.sin_family = AF_INET; - server_add.sin_port = htons(SOCKET_PORT); - server_add.sin_addr.s_addr = inet_addr(IP_SERVER); - memset(server_add.sin_zero, '\0', sizeof server_add.sin_zero); - - ret_bind = bind(socket_server_fd, (struct sockaddr *)&server_add, - sizeof(server_add)); - if (ret_bind < 0) - { - perror("Failed to do socket bind operation"); - exit(EXIT_FAILURE); - } - - /* Initiate listening process for client sockets connection requests. - * The maximum number client sockets pending connection is - * defined by MAX_PENDING_SOCKET_CONNECTIONS - */ - - if (listen(socket_server_fd, MAX_PENDING_SOCKET_CONNECTIONS) == 0) - { - printf("Listening for clients connections...\n"); - } - else - { - perror("Failed to listen for clients connections"); - } - - while (1) - { - /* Wait for a new client socket connection */ - - addr_size = sizeof server_storage; - new_socket_client_fd = accept4(socket_server_fd, - (struct sockaddr *)&server_storage, - &addr_size, SOCK_CLOEXEC); - - if (new_socket_client_fd < 0) - { - perror("Failed to accept new client socket connection"); - exit(EXIT_FAILURE); - } - - /* For each connected client socket, a new client thread - * is instantiated. - */ - - if (pthread_create(&tid[socket_clients_counter++], NULL, - thread_socket_client, &new_socket_client_fd) != 0) - { - perror("Failed to instantiate a thread for new client socket\n"); - } - - if (socket_clients_counter <= MAX_PENDING_SOCKET_CONNECTIONS) - { - pthread_join(tid[socket_clients_counter++], NULL); - socket_clients_counter++; - } - - usleep(TIME_TO_CHECK_FOR_NEW_CLIENTS); - } - - return 0; -} diff --git a/examples/tcp_ipc_server/uart_lorawan_layer.c b/examples/tcp_ipc_server/uart_lorawan_layer.c deleted file mode 100644 index dedafa08d..000000000 --- a/examples/tcp_ipc_server/uart_lorawan_layer.c +++ /dev/null @@ -1,533 +0,0 @@ -/**************************************************************************** - * apps/examples/tcp_ipc_server/uart_lorawan_layer.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> -#include <inttypes.h> -#include <stdio.h> -#include <fcntl.h> -#include <unistd.h> -#include <sys/time.h> -#include "lorawan/uart_lorawan_layer.h" - -/* Useful links: - * - * LoRaWAN module used here: Radioenge LoRaWAN module - * Radioenge LoRaWAN module page: - * https://www.radioenge.com.br/produto/modulo-lorawan/ - * Radioenge LoRaWAN module datasheet: - * https://www.radioenge.com.br/storage/2021/08/Manual_LoRaWAN_Jun2022.pdf - */ - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#ifndef CONFIG_ESP32_UART1 -# error "CONFIG_ESP32_UART1 needs to be defined in order to compile this program." -#endif - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static void clear_uart_rx_buffer(void); -static int send_uart_lorawan_at_commands(unsigned char * ptr_at_cmd, - int size_at_cmd); -static int read_uart_lorawan_resp(unsigned char * ptr_response_buffer, - int size_response_buffer, - int time_to_wait_ms); - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -#define PATH_TO_UART1 "/dev/ttyS1" -#define FULL_AT_CMD_MAX_SIZE 200 -#define TIME_BETWEEN_AT_CMDS 1 //s -#define MAX_ATTEMPTS_TO_SEND 3 - -/**************************************************************************** - * Public variables - ****************************************************************************/ - -static int fd_uart = 0; -static bool is_lorawan_busy = false; - -/**************************************************************************** - * Name: clear_uart_rx_buffer - * Description: clean UART RX buffer - * Parameters: nothing - * Return: nothing - ****************************************************************************/ - -static void clear_uart_rx_buffer(void) -{ - char rcv_byte_uart = 0x00; - - if (fd_uart <= -1) - { - /* invalid UART file descriptor */ - - return; - } - else - { - while (read(fd_uart, &rcv_byte_uart, 1) > 0); - } -} - -/**************************************************************************** - * Name: send_uart_lorawan_at_commands - * Description: send AT commands to LoRaWAN module via UART - * Parameters: - pointer to array containing AT command to send - * - AT command size - * Return: number of bytes written to UART - ****************************************************************************/ - -static int send_uart_lorawan_at_commands(unsigned char * ptr_at_cmd, - int size_at_cmd) -{ - int bytes_written_uart = 0; - - if (fd_uart <= -1) - { - /* invalid UART file descriptor */ - - goto END_UART_SEND_AT_CMD; - } - - /* Send AT command to LoRaWAN module */ - - bytes_written_uart = write(fd_uart, ptr_at_cmd, size_at_cmd); - -END_UART_SEND_AT_CMD: - return bytes_written_uart; -} - -/**************************************************************************** - * Name: read_uart_LoRaWAN_AT_command_response - * Description: read AT command response via UART - * Parameters: - pointer to array containing response buffer - * - response buffer size - * - time to wait for UART response - * Return: number of bytes read from UART - ****************************************************************************/ - -static int read_uart_lorawan_resp(unsigned char * ptr_response_buffer, - int size_response_buffer, - int time_to_wait_ms) -{ - int total_bytes_read_uart = 0; - int bytes_read_uart = 0; - bool keep_reading = true; - useconds_t time_to_wait_us = 0; - char full_response[50]; - char *pos_msg_downlink; - char *pos_msg_at_busy_error; - int status_read_uart_lorawan_resp = 0; - - memset(full_response, 0x00, sizeof(full_response)); - - if (fd_uart <= -1) - { - /* invalid UART file descriptor */ - - goto END_UART_READ_AT_CMD; - } - - /* Wait for UART response */ - - time_to_wait_us = time_to_wait_ms * 1000; - usleep(time_to_wait_us); - - do - { - bytes_read_uart = read(fd_uart, - full_response + total_bytes_read_uart, - 1); - - if (bytes_read_uart > 0) - { - ptr_response_buffer++; - total_bytes_read_uart++; - } - else - { - /* No more bytes to read */ - - keep_reading = false; - } - - if (total_bytes_read_uart >= 50) - { - keep_reading = false; - } - } - while (keep_reading == true); - - /* Check if response message is AT_BUSY_ERROR */ - - pos_msg_at_busy_error = strstr(full_response, "AT_BUSY_ERROR"); - - if (pos_msg_at_busy_error != NULL) - { - status_read_uart_lorawan_resp = ERR_AT_BUSY_ERROR; - goto END_UART_READ_AT_CMD; - } - - /* Check if response is a downlink message */ - - pos_msg_downlink = strstr(full_response, "RX:"); - - if (pos_msg_downlink == NULL) - { - status_read_uart_lorawan_resp = 0; - } - else - { - snprintf((char *)ptr_response_buffer, size_response_buffer, "%s", - pos_msg_downlink + 3); - status_read_uart_lorawan_resp = strlen((char *)ptr_response_buffer); - } - -END_UART_READ_AT_CMD: - return status_read_uart_lorawan_resp; -} - -/**************************************************************************** - * Name: LoRaWAN_Radioenge_init - * Description: init LoRaWAN module - * Parameters: LoRaWAN module config structure - * Return: nothing - ****************************************************************************/ - -void lorawan_radioenge_init(config_lorawan_radioenge_t config_lorawan) -{ - int bytes_written_at_cmd = 0; - unsigned char full_at_cmd[FULL_AT_CMD_MAX_SIZE]; - - memset(full_at_cmd, 0x00, sizeof(full_at_cmd)); - - /* Open UART communication with LoRaWAN module */ - - fd_uart = open(PATH_TO_UART1, O_RDWR | O_NONBLOCK); - - if (fd_uart <= -1) - { - perror("Cannot open UART communication with LoRaWAN module"); - goto END_UART_LORAWAN_MODULE_INIT; - } - - /* Configuration: LoRaWAN channel mask */ - - memset(full_at_cmd, 0x00, FULL_AT_CMD_MAX_SIZE); - snprintf((char *)full_at_cmd, FULL_AT_CMD_MAX_SIZE, "AT+CHMASK=%s\n\r", - config_lorawan.channel_mask); - bytes_written_at_cmd = send_uart_lorawan_at_commands(full_at_cmd, - strlen((char *)full_at_cmd)); - - if (bytes_written_at_cmd <= 0) - { - perror("Error when writting Channel Mask to LoRaWAN module"); - goto END_UART_LORAWAN_MODULE_INIT; - } - - sleep(TIME_BETWEEN_AT_CMDS); - printf("\n\r[LORAWAN] Channel mask configured\r\n"); - clear_uart_rx_buffer(); - - /* Configuration: join mode (ABP) */ - - memset(full_at_cmd, 0x00, FULL_AT_CMD_MAX_SIZE); - snprintf((char *)full_at_cmd, FULL_AT_CMD_MAX_SIZE, "AT+NJM=0\n\r"); - bytes_written_at_cmd = send_uart_lorawan_at_commands(full_at_cmd, - strlen((char *)full_at_cmd)); - - if (bytes_written_at_cmd <= 0) - { - perror("Error when writting Join Mode to LoRaWAN module"); - goto END_UART_LORAWAN_MODULE_INIT; - } - - sleep(TIME_BETWEEN_AT_CMDS); - printf("\n\r[LORAWAN] NJM configured\r\n"); - clear_uart_rx_buffer(); - - /* Configuration: device address */ - - memset(full_at_cmd, 0x00, FULL_AT_CMD_MAX_SIZE); - snprintf((char *)full_at_cmd, FULL_AT_CMD_MAX_SIZE, "AT+DADDR=%s\n\r", - config_lorawan.device_address); - bytes_written_at_cmd = send_uart_lorawan_at_commands(full_at_cmd, - strlen((char *)full_at_cmd)); - - if (bytes_written_at_cmd <= 0) - { - perror("Error when writting device address to LoRaWAN module"); - goto END_UART_LORAWAN_MODULE_INIT; - } - - sleep(TIME_BETWEEN_AT_CMDS); - printf("\n\r[LORAWAN] Device address configured\r\n"); - clear_uart_rx_buffer(); - - /* Configuration: Application EUI */ - - memset(full_at_cmd, 0x00, FULL_AT_CMD_MAX_SIZE); - snprintf((char *)full_at_cmd, FULL_AT_CMD_MAX_SIZE, "AT+APPEUI=%s\n\r", - config_lorawan.application_eui); - bytes_written_at_cmd = send_uart_lorawan_at_commands(full_at_cmd, - strlen((char *)full_at_cmd)); - - if (bytes_written_at_cmd <= 0) - { - perror("Error when writting application EUI to LoRaWAN module"); - goto END_UART_LORAWAN_MODULE_INIT; - } - - sleep(TIME_BETWEEN_AT_CMDS); - printf("\n\r[LORAWAN] APP EUI configured\r\n"); - clear_uart_rx_buffer(); - - /* Configuration: Application Session Key */ - - memset(full_at_cmd, 0x00, sizeof(full_at_cmd)); - snprintf((char *)full_at_cmd, sizeof(full_at_cmd), "AT+APPSKEY=%s\n\r", - config_lorawan.application_session_key); - bytes_written_at_cmd = send_uart_lorawan_at_commands(full_at_cmd, - strlen((char *)full_at_cmd)); - - if (bytes_written_at_cmd <= 0) - { - perror("Error when writting application session key" - "to LoRaWAN module"); - goto END_UART_LORAWAN_MODULE_INIT; - } - - sleep(TIME_BETWEEN_AT_CMDS); - printf("\n\r[LORAWAN] APPSKEY configured\r\n"); - clear_uart_rx_buffer(); - - /* Configuration: Network Session Key */ - - memset(full_at_cmd, 0x00, sizeof(full_at_cmd)); - snprintf((char *)full_at_cmd, sizeof(full_at_cmd), "AT+NWKSKEY=%s\n\r", - config_lorawan.network_session_key); - bytes_written_at_cmd = send_uart_lorawan_at_commands(full_at_cmd, - strlen((char *)full_at_cmd)); - - if (bytes_written_at_cmd <= 0) - { - perror("Error when writting network session key" - "to LoRaWAN module"); - goto END_UART_LORAWAN_MODULE_INIT; - } - - sleep(TIME_BETWEEN_AT_CMDS); - printf("\n\r[LORAWAN] NWSKEY configured\r\n"); - clear_uart_rx_buffer(); - - /* Configuration: ADR */ - - memset(full_at_cmd, 0x00, sizeof(full_at_cmd)); - snprintf((char *)full_at_cmd, sizeof(full_at_cmd), "AT+ADR=0\n\r"); - bytes_written_at_cmd = send_uart_lorawan_at_commands(full_at_cmd, - strlen((char *)full_at_cmd)); - - if (bytes_written_at_cmd <= 0) - { - perror("Error when writting ADR configuration to LoRaWAN module"); - goto END_UART_LORAWAN_MODULE_INIT; - } - - sleep(TIME_BETWEEN_AT_CMDS); - printf("\n\r[LORAWAN] ADR configured\r\n"); - clear_uart_rx_buffer(); - - /* Configuration: DR */ - - memset(full_at_cmd, 0x00, sizeof(full_at_cmd)); - snprintf((char *)full_at_cmd, sizeof(full_at_cmd), "AT+DR=0\n\r"); - bytes_written_at_cmd = send_uart_lorawan_at_commands(full_at_cmd, - strlen((char *)full_at_cmd)); - - if (bytes_written_at_cmd <= 0) - { - perror("Error when writting DR configuration to LoRaWAN module"); - goto END_UART_LORAWAN_MODULE_INIT; - } - - sleep(TIME_BETWEEN_AT_CMDS); - printf("\n\r[LORAWAN] DR configured\r\n"); - clear_uart_rx_buffer(); - - /* Configuration: LoRaWAN class */ - - memset(full_at_cmd, 0x00, sizeof(full_at_cmd)); - snprintf((char *)full_at_cmd, sizeof(full_at_cmd), "AT+CLASS=A\n\r"); - bytes_written_at_cmd = send_uart_lorawan_at_commands(full_at_cmd, - strlen((char *)full_at_cmd)); - - if (bytes_written_at_cmd <= 0) - { - perror("Error when writting LoRaWAN class to LoRaWAN module"); - goto END_UART_LORAWAN_MODULE_INIT; - } - - sleep(TIME_BETWEEN_AT_CMDS); - printf("\n\r[LORAWAN] LoRaWAN class A configured\r\n"); - clear_uart_rx_buffer(); - - /* Configuration: send confirmation */ - - memset(full_at_cmd, 0x00, sizeof(full_at_cmd)); - snprintf((char *)full_at_cmd, sizeof(full_at_cmd), "AT+CFM=1\n\r"); - bytes_written_at_cmd = send_uart_lorawan_at_commands(full_at_cmd, - strlen((char *)full_at_cmd)); - - if (bytes_written_at_cmd <= 0) - { - perror("Error when writting send confirmation to LoRaWAN module"); - } - - sleep(TIME_BETWEEN_AT_CMDS); - printf("\n\r[LORAWAN] CFM configured\r\n"); - clear_uart_rx_buffer(); - -END_UART_LORAWAN_MODULE_INIT: -} - -/**************************************************************************** - * Name: lorawan_radioenge_send_msg - * Description: send LoRaWAN message with waiting for a downlink message - * Parameters: - pointer to array containing uplink message (in Hex-String - * format) - * - uplink message size - * - pointer to array containing downlink message - * - downlink message array size - * - Time to wait for the downlink message (ms) - * Return: nothing - ****************************************************************************/ - -int lorawan_radioenge_send_msg(unsigned char * pt_uplink_hexstring, - int size_uplink, - unsigned char * pt_downlink_hexstring, - int max_size_downlink, - int time_to_wait_ms) -{ - int bytes_rcv_downlink_msg = 0; - int number_of_attempts = 0; - unsigned char at_cmd_send_message[FULL_AT_CMD_MAX_SIZE]; - - memset(at_cmd_send_message, 0x00, sizeof(at_cmd_send_message)); - - while (is_lorawan_busy == true); - is_lorawan_busy = true; - - /* Clear RX UART buffer before sending a new command - * (to clean all messages received from previous AT commands - */ - - clear_uart_rx_buffer(); - - /* Compose AT command */ - - snprintf((char *)at_cmd_send_message, - FULL_AT_CMD_MAX_SIZE, - "AT+SENDB=5:%s\n\r", - pt_uplink_hexstring); - printf("\n\r[LORAWAN] AT CMD: %s\n\r", at_cmd_send_message); - - /* Send uplink message (until success or number of attempts exceeds - * what is defined in MAX_ATTEMPTS_TO_SEND) - */ - - while (number_of_attempts < MAX_ATTEMPTS_TO_SEND) - { - if (send_uart_lorawan_at_commands(at_cmd_send_message, - strlen((char *)at_cmd_send_message)) <= 0) - { - printf("\n\rError when sending uplink message.\n\r"); - number_of_attempts++; - continue; - } - - /* Get downlink message */ - - bytes_rcv_downlink_msg = read_uart_lorawan_resp(pt_downlink_hexstring, - max_size_downlink, - time_to_wait_ms); - - /* If a AT_BUSY is received as command responde, command must - * be sent again - */ - - if (bytes_rcv_downlink_msg == ERR_AT_BUSY_ERROR) - { - number_of_attempts++; - continue; - } - - /* If there isn't AT_BUSY_ERROR response, check for downlink - * message - */ - - if (bytes_rcv_downlink_msg == 0) - { - printf("\n\rNo downlink message has been received.\n\r"); - break; - } - } - - if (number_of_attempts == MAX_ATTEMPTS_TO_SEND) - { - printf("\n\rError: failed to send command in all %d attempts\n\r", - MAX_ATTEMPTS_TO_SEND); - } - - is_lorawan_busy = false; - return bytes_rcv_downlink_msg; -} diff --git a/examples/tcpblaster/CMakeLists.txt b/examples/tcpblaster/CMakeLists.txt deleted file mode 100644 index 5e72826c1..000000000 --- a/examples/tcpblaster/CMakeLists.txt +++ /dev/null @@ -1,87 +0,0 @@ -# ############################################################################## -# apps/examples/tcpblaster/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_TCPBLASTER) - - if(NOT CONFIG_EXAMPLES_TCPBLASTER_TARGET2 - AND NOT CONFIG_EXAMPLES_TCPBLASTER_LOOPBACK) - include(tcpblaster_host.cmake) - endif() - - # Basic TCP networking test - - set(CSRCS tcpblaster_cmdline.c) - - if(CONFIG_EXAMPLES_TCPBLASTER_INIT) - list(APPEND CSRCS tcpblaster_netinit.c) - endif() - - # Target 1 Files - - if(CONFIG_EXAMPLES_TCPBLASTER_LOOPBACK) - list(APPEND CSRCS tcpblaster_server.c tcpblaster_client.c) - elseif(CONFIG_EXAMPLES_TCPBLASTER_SERVER) - list(APPEND CSRCS tcpblaster_server.c) - else() - list(APPEND CSRCS tcpblaster_client.c) - endif() - - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_TCPBLASTER_PROGNAME1} - PRIORITY - ${CONFIG_EXAMPLES_TCPBLASTER_PRIORITY1} - STACKSIZE - ${CONFIG_EXAMPLES_TCPBLASTER_STACKSIZE1} - MODULE - ${CONFIG_EXAMPLES_TCPBLASTER} - INCLUDE_DIRECTORIES - ${CMAKE_BINARY_DIR}/include/nuttx - SRCS - tcpblaster_target1.c - ${CSRCS}) - - # Target 2 Files - - if(CONFIG_EXAMPLES_TCPBLASTER_TARGET2) - if(CONFIG_EXAMPLES_TCPBLASTER_SERVER) - list(APPEND CSRCS tcpblaster_client.c) - else() - list(APPEND CSRCS tcpblaster_server.c) - endif() - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_TCPBLASTER_PROGNAME2} - PRIORITY - ${CONFIG_EXAMPLES_TCPBLASTER_PRIORITY2} - STACKSIZE - ${CONFIG_EXAMPLES_TCPBLASTER_STACKSIZE2} - MODULE - ${CONFIG_EXAMPLES_TCPBLASTER} - INCLUDE_DIRECTORIES - ${CMAKE_BINARY_DIR}/include/nuttx - SRCS - tcpblaster_target2.c - ${CSRCS}) - endif() - -endif() diff --git a/examples/tcpblaster/Kconfig b/examples/tcpblaster/Kconfig index 7c768ae09..7b5304744 100644 --- a/examples/tcpblaster/Kconfig +++ b/examples/tcpblaster/Kconfig @@ -146,7 +146,8 @@ endchoice # IP Domain config EXAMPLES_TCPBLASTER_INIT bool "Initialize network" - default !NSH_NETINIT + default n if NSH_NETINIT + default y if !NSH_NETINIT depends on !EXAMPLES_TCPBLASTER_LOOPBACK ---help--- Include logic to initialize the network. This should not be done if diff --git a/examples/tcpblaster/Make.defs b/examples/tcpblaster/Make.defs index bde73b878..8c834a90f 100644 --- a/examples/tcpblaster/Make.defs +++ b/examples/tcpblaster/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/tcpblaster/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/tcpblaster/Makefile b/examples/tcpblaster/Makefile index 50efef93a..c4fb38f7d 100644 --- a/examples/tcpblaster/Makefile +++ b/examples/tcpblaster/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/tcpblaster/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/tcpblaster/README.md b/examples/tcpblaster/README.md new file mode 100644 index 000000000..4b699a782 --- /dev/null +++ b/examples/tcpblaster/README.md @@ -0,0 +1,43 @@ +# Examples / `tcpblaster` TCP Performance Test + +To set up, do `make menuconfig` and select the _Apps_ โ†’ _Examples_ โ†’ +_tcpblaster_. By default, nuttx will the be the client which sends data; and the +host computer (Linux, macOS, or Windows) will be the server. + +Set up networking so the nuttx computer can ping the host, and the host can ping +nuttx. Now you are ready to run the test. + +On host: + +``` +$ ./tcpserver +Binding to IPv4 Address: 00000000 +server: Accepting connections on port 5471 +``` + +On nuttx: + +``` +nsh> tcpclient +Connecting to IPv4 Address: 0100000a +client: Connected +[2014-07-31 00:16:15.000] 0: Sent 200 4096-byte buffers: 800.0 KB (avg 4.0 KB) in 0.18 seconds ( 4444.4 KB/second) +``` + +Now on the host you should see something like: + +``` +$ ./tcpserver +Binding to IPv4 Address: 00000000 +server: Accepting connections on port 5471 +server: Connection accepted -- receiving +[2020-02-22 16:17:07.000] 0: Received 200 buffers: 502.9 KB (buffer average size: 2.5 KB) in 0.12 seconds ( 4194.8 KB/second) +[2020-02-22 16:17:07.000] 1: Received 200 buffers: 393.1 KB (buffer average size: 2.0 KB) in 0.09 seconds ( 4299.4 KB/second) +``` + +This will tell you the link speed in KB/sec โ€“ kilobytes per second. If you want +kilobits, multiply by `8`. + +You can use the `make menuconfig` to reverse the setup, and have nuttx be the +server, and the host be the client. If you do that, start the server first +(nuttx), then start the client (host). diff --git a/examples/tcpblaster/tcpblaster.h b/examples/tcpblaster/tcpblaster.h index 5d645f4ab..421f87e6c 100644 --- a/examples/tcpblaster/tcpblaster.h +++ b/examples/tcpblaster/tcpblaster.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/tcpblaster/tcpblaster.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -31,7 +29,7 @@ #ifdef TCPBLASTER_HOST #else -# include <nuttx/debug.h> +# include <debug.h> #endif /**************************************************************************** diff --git a/examples/tcpblaster/tcpblaster_client.c b/examples/tcpblaster/tcpblaster_client.c index 940651e4d..540a9644a 100644 --- a/examples/tcpblaster/tcpblaster_client.c +++ b/examples/tcpblaster/tcpblaster_client.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/tcpblaster/tcpblaster_client.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -150,7 +148,7 @@ void tcpblaster_client(void) memset(fds, 0, 1 * sizeof(struct pollfd)); fds[0].fd = sockfd; - fds[0].events = POLLOUT; + fds[0].events = POLLOUT | POLLHUP; /* Wait until we can send data or until the connection is lost */ diff --git a/examples/tcpblaster/tcpblaster_cmdline.c b/examples/tcpblaster/tcpblaster_cmdline.c index 6033fafd2..d47395961 100644 --- a/examples/tcpblaster/tcpblaster_cmdline.c +++ b/examples/tcpblaster/tcpblaster_cmdline.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/tcpblaster/tcpblaster_cmdline.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/tcpblaster/tcpblaster_host.c b/examples/tcpblaster/tcpblaster_host.c index f1667cc41..78868c2a7 100644 --- a/examples/tcpblaster/tcpblaster_host.c +++ b/examples/tcpblaster/tcpblaster_host.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/tcpblaster/tcpblaster_host.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/tcpblaster/tcpblaster_host.cmake b/examples/tcpblaster/tcpblaster_host.cmake deleted file mode 100644 index e2bf12e1a..000000000 --- a/examples/tcpblaster/tcpblaster_host.cmake +++ /dev/null @@ -1,57 +0,0 @@ -# ############################################################################## -# apps/examples/tcpblaster/tcpblaster_host.cmake -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## -# Configure project -cmake_minimum_required(VERSION 3.16) -project(tcpblaster_host LANGUAGES C) - -if(NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE - "Release" - CACHE STRING "Build type" FORCE) -endif() - -message(STATUS "NuttX apps examples tcpblaster host") - -include_directories(${CMAKE_BINARY_DIR}/include/nuttx) - -add_compile_definitions(TCPBLASTER_HOST=1) - -if(CONFIG_EXAMPLES_TCPBLASTER_SERVER) - add_compile_definitions(CONFIG_EXAMPLES_TCPBLASTER_SERVER=1) - add_compile_definitions( - CONFIG_EXAMPLES_TCPBLASTER_SERVERIP=${CONFIG_EXAMPLES_TCPBLASTER_SERVERIP}) - -endif() - -add_library(tcpblaster) -target_sources(tcpblaster PRIVATE tcpblaster_cmdline.c) -if(CONFIG_EXAMPLES_TCPBLASTER_SERVER) - target_sources(tcpblaster PRIVATE tcpblaster_client.c) - add_executable(tcpclient tcpblaster_host.c) - target_link_libraries(tcpclient PRIVATE tcpblaster) - install(TARGETS tcpclient DESTINATION bin) -else() - target_sources(tcpblaster PRIVATE tcpblaster_server.c) - add_executable(tcpserver tcpblaster_host.c) - target_link_libraries(tcpserver PRIVATE tcpblaster) - install(TARGETS tcpserver DESTINATION bin) -endif() diff --git a/examples/tcpblaster/tcpblaster_netinit.c b/examples/tcpblaster/tcpblaster_netinit.c index f9719d295..03fec0965 100644 --- a/examples/tcpblaster/tcpblaster_netinit.c +++ b/examples/tcpblaster/tcpblaster_netinit.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/tcpblaster/tcpblaster_netinit.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -28,7 +26,7 @@ #include <stdbool.h> #include <stdio.h> -#include <nuttx/debug.h> +#include <debug.h> #include <arpa/inet.h> #include <netinet/in.h> diff --git a/examples/tcpblaster/tcpblaster_server.c b/examples/tcpblaster/tcpblaster_server.c index 17f5244d7..ce12f7deb 100644 --- a/examples/tcpblaster/tcpblaster_server.c +++ b/examples/tcpblaster/tcpblaster_server.c @@ -1,7 +1,5 @@ /**************************************************************************** - * apps/examples/tcpblaster/tcpblaster_server.c - * - * SPDX-License-Identifier: Apache-2.0 + * apps/examples/tcpblaster/tcpblaster-server.c * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -155,12 +153,7 @@ void tcpblaster_server(void) printf("server: Accepting connections on port %d\n", CONFIG_EXAMPLES_TCPBLASTER_SERVER_PORTNO); -#ifdef __NuttX__ - acceptsd = accept4(listensd, (FAR struct sockaddr *)&myaddr, &addrlen, - SOCK_CLOEXEC); -#else acceptsd = accept(listensd, (FAR struct sockaddr *)&myaddr, &addrlen); -#endif if (acceptsd < 0) { printf("server: accept failure: %d\n", errno); @@ -198,7 +191,7 @@ void tcpblaster_server(void) memset(fds, 0, 1 * sizeof(struct pollfd)); fds[0].fd = acceptsd; - fds[0].events = POLLIN; + fds[0].events = POLLIN | POLLHUP; /* Wait until we can receive data or until the connection is lost */ diff --git a/examples/tcpblaster/tcpblaster_target1.c b/examples/tcpblaster/tcpblaster_target1.c index 827fe3a7d..fcfdae112 100644 --- a/examples/tcpblaster/tcpblaster_target1.c +++ b/examples/tcpblaster/tcpblaster_target1.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/tcpblaster/tcpblaster_target1.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -32,7 +30,7 @@ #include <stdio.h> #include <unistd.h> #include <sched.h> -#include <nuttx/debug.h> +#include <debug.h> #include "tcpblaster.h" diff --git a/examples/tcpblaster/tcpblaster_target2.c b/examples/tcpblaster/tcpblaster_target2.c index f14107c7d..bd32f92a6 100644 --- a/examples/tcpblaster/tcpblaster_target2.c +++ b/examples/tcpblaster/tcpblaster_target2.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/tcpblaster/tcpblaster_target2.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/tcpecho/CMakeLists.txt b/examples/tcpecho/CMakeLists.txt deleted file mode 100644 index c39b5892a..000000000 --- a/examples/tcpecho/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# ############################################################################## -# apps/examples/tcpecho/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_TCPECHO) - nuttx_add_application( - NAME - tcpecho - STACKSIZE - ${CONFIG_DEFAULT_TASK_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_TCPECHO} - SRCS - tcpecho_main.c) -endif() diff --git a/examples/tcpecho/Make.defs b/examples/tcpecho/Make.defs index 8670a03ad..fd6c24f69 100644 --- a/examples/tcpecho/Make.defs +++ b/examples/tcpecho/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/tcpecho/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/tcpecho/Makefile b/examples/tcpecho/Makefile index b1e2888bd..2ad89140e 100644 --- a/examples/tcpecho/Makefile +++ b/examples/tcpecho/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/tcpecho/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/tcpecho/tcpecho_main.c b/examples/tcpecho/tcpecho_main.c index 2de49f6af..0ff19eb6f 100644 --- a/examples/tcpecho/tcpecho_main.c +++ b/examples/tcpecho/tcpecho_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/tcpecho/tcpecho_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -28,7 +26,7 @@ * Included Files ****************************************************************************/ -#include <nuttx/debug.h> +#include <debug.h> #include <errno.h> #include <poll.h> #include <stdint.h> @@ -42,8 +40,13 @@ #include <netinet/in.h> #include <arpa/inet.h> +#include <nuttx/net/arp.h> #include "netutils/netlib.h" +#ifdef CONFIG_EXAMPLES_TCPECHO_DHCPC +# include <arpa/inet.h> +#endif + /* Here we include the header file for the application(s) we use in * our project as defined in the config/<board-name>/defconfig file */ @@ -76,7 +79,7 @@ static int tcpecho_server(void); * Private Functions ****************************************************************************/ -static int tcpecho_netsetup(void) +static int tcpecho_netsetup() { /* If this task is excecutated as an NSH built-in function, then the * network has already been configured by NSH's start-up logic. @@ -90,8 +93,6 @@ static int tcpecho_netsetup(void) #ifdef CONFIG_EXAMPLES_TCPECHO_DHCPC struct dhcpc_state ds; void *handle; - char inetaddr[INET_ADDRSTRLEN]; - int ret; #endif /* Many embedded network interfaces must have a software assigned MAC */ @@ -167,21 +168,13 @@ static int tcpecho_netsetup(void) netlib_set_dripv4addr("eth0", &ds.default_router); } - for (int i = 0; i < ds.num_dnsaddr; i++) + if (ds.dnsaddr.s_addr != 0) { - if (ds.dnsaddr[i].s_addr != 0) - { - ret = netlib_set_ipv4dnsaddr(&ds.dnsaddr[i]); - if (ret < 0) - { - nerr("ERROR: Set DNS server %d:%s address failed: %d\n", - i, inet_ntoa(ds.dnsaddr[i]), ret); - } - } + netlib_set_ipv4dnsaddr(&ds.dnsaddr); } dhcpc_close(handle); - printf("IP: %s\n", inet_ntoa_r(ds.ipaddr, inetaddr, sizeof(inetaddr))); + printf("IP: %s\n", inet_ntoa(ds.ipaddr)); #endif /* CONFIG_EXAMPLES_TCPECHO_DHCPC */ #endif /* CONFIG_NSH_NETINIT */ @@ -250,16 +243,12 @@ static int tcpecho_server(void) if (client[0].revents & POLLRDNORM) { - char inetaddr[INET_ADDRSTRLEN]; - /* new client connection */ clilen = sizeof(cliaddr); - connfd = accept4(listenfd, (struct sockaddr *)&cliaddr, &clilen, - SOCK_CLOEXEC); + connfd = accept(listenfd, (struct sockaddr *)&cliaddr, &clilen); - ninfo("new client: %s\n", - inet_ntoa_r(cliaddr.sin_addr, inetaddr, sizeof(inetaddr))); + ninfo("new client: %s\n", inet_ntoa(cliaddr.sin_addr)); for (i = 1; i < CONFIG_EXAMPLES_TCPECHO_NCONN; i++) { diff --git a/examples/telnetd/CMakeLists.txt b/examples/telnetd/CMakeLists.txt deleted file mode 100644 index 2f1280417..000000000 --- a/examples/telnetd/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# ############################################################################## -# apps/examples/telnetd/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_TELNETD) - nuttx_add_application( - NAME - example_telnetd - PRIORITY - ${CONFIG_EXAMPLES_TELNETD_DAEMONPRIO} - STACKSIZE - ${CONFIG_EXAMPLES_TELNETD_DAEMONSTACKSIZE} - MODULE - ${CONFIG_EXAMPLES_TELNETD} - SRCS - telnetd.c) -endif() diff --git a/examples/telnetd/Make.defs b/examples/telnetd/Make.defs index 59d1fe357..4bbccca3e 100644 --- a/examples/telnetd/Make.defs +++ b/examples/telnetd/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/telnetd/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/telnetd/Makefile b/examples/telnetd/Makefile index 427cf3a7f..b121c1f75 100644 --- a/examples/telnetd/Makefile +++ b/examples/telnetd/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/telnetd/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -28,9 +26,9 @@ MAINSRC = telnetd.c # Buttons built-in application info -PROGNAME = example_telnetd -PRIORITY = $(CONFIG_EXAMPLES_TELNETD_DAEMONPRIO) -STACKSIZE = $(CONFIG_EXAMPLES_TELNETD_DAEMONSTACKSIZE) +PROGNAME = telnetd +PRIORITY = SCHED_PRIORITY_DEFAULT +STACKSIZE = $(CONFIG_DEFAULT_TASK_STACKSIZE) MODULE = $(CONFIG_EXAMPLES_TELNETD) include $(APPDIR)/Application.mk diff --git a/examples/telnetd/README.md b/examples/telnetd/README.md new file mode 100644 index 000000000..28cd2e12e --- /dev/null +++ b/examples/telnetd/README.md @@ -0,0 +1,7 @@ +# Examples / `telnetd` Telnet Daemon + +This directory contains a functional port of the tiny uIP shell. In the NuttX +environment, the NuttShell (at `apps/nshlib`) supersedes this tiny shell and +also supports telnetd. + +This example is retained here for reference purposes only. diff --git a/examples/telnetd/telnetd.c b/examples/telnetd/telnetd.c index 270e6d53b..9bbc00683 100644 --- a/examples/telnetd/telnetd.c +++ b/examples/telnetd/telnetd.c @@ -1,11 +1,14 @@ /**************************************************************************** * apps/examples/telnetd/telnetd.c * - * SPDX-License-Identifier: BSD-3-Clause - * SPDX-FileCopyrightText: 2012, 2017 Gregory Nutt. All rights reserved. - * SPDX-FileCopyrightText: 2003, Adam Dunkels. All rights reserved. - * SPDX-FileContributor: Gregory Nutt <gnutt@nuttx.org> - * SPDX-FileContributor: Adam Dunkels <adam@sics.se> + * Copyright (C) 2012, 2017 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <gnutt@nuttx.org> + * + * This is a leverage of similar logic from uIP: + * + * Author: Adam Dunkels <adam@sics.se> + * Copyright (c) 2003, Adam Dunkels. + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -45,11 +48,6 @@ #include <arpa/inet.h> #include <netinet/in.h> -#ifdef CONFIG_BOARDCTL_RESET -# include <sys/boardctl.h> -# include <sys/ioctl.h> -#endif - #include "netutils/telnetd.h" #include "netutils/netlib.h" @@ -70,11 +68,6 @@ struct ptentry_s ****************************************************************************/ static void telnetd_help(int argc, char **argv); - -#ifdef CONFIG_BOARDCTL_RESET -static void telnetd_reset(int argc, char **argv); -#endif - static void telnetd_quit(int argc, char **argv); static void telnetd_unknown(int argc, char **argv); static void telnetd_parse(FAR char *line, int len); @@ -83,12 +76,9 @@ static void telnetd_parse(FAR char *line, int len); * Private Data ****************************************************************************/ -static const struct ptentry_s g_parsetab[] = +static struct ptentry_s g_parsetab[] = { {"help", telnetd_help}, - #ifdef CONFIG_BOARDCTL_RESET - {"reset", telnetd_reset}, - #endif {"exit", telnetd_quit}, {"?", telnetd_help}, {NULL, telnetd_unknown} @@ -106,9 +96,6 @@ static void telnetd_help(int argc, char **argv) { printf("Available commands:\n"); printf(" help, ? - show help\n"); - #ifdef CONFIG_BOARDCTL_RESET - printf(" reset - reset the board\n"); - #endif printf(" exit - exit shell\n"); } @@ -134,25 +121,13 @@ static void telnetd_quit(int argc, char **argv) exit(0); } -/**************************************************************************** - * Name: telnetd_reset - ****************************************************************************/ -#ifdef CONFIG_BOARDCTL_RESET -static void telnetd_reset(int argc, char **argv) -{ - printf("Reset!\n"); - boardctl(BOARDIOC_RESET, 0); - exit(0); -} -#endif - /**************************************************************************** * Name: telnetd_parse ****************************************************************************/ static void telnetd_parse(FAR char *line, int len) { - FAR const struct ptentry_s *entry; + struct ptentry_s *entry; FAR char *cmd; FAR char *saveptr; @@ -165,8 +140,7 @@ static void telnetd_parse(FAR char *line, int len) for (entry = g_parsetab; entry->commandstr != NULL; entry++) { - if (strncmp(entry->commandstr, cmd, - strlen(entry->commandstr)) == 0) + if (strncmp(entry->commandstr, cmd, strlen(entry->commandstr)) == 0) { break; } @@ -184,11 +158,10 @@ int telnetd_session(int argc, char *argv[]) { char line[128]; - printf("Device Configuration over Telnet\n"); - printf("You can add functions to setup your device\n"); - printf("Type '?' and press <enter> for help\n"); + printf("uIP command shell -- NuttX style\n"); + printf("Type '?' and return for help\n"); - for (; ; ) + for (;;) { printf(SHELL_PROMPT); fflush(stdout); @@ -215,7 +188,7 @@ static void telnetd_netinit(void) uint8_t mac[IFHWADDRLEN]; #endif - /* Many embedded network interfaces must have a software assigned MAC */ +/* Many embedded network interfaces must have a software assigned MAC */ #ifdef CONFIG_EXAMPLES_TELNETD_NOMAC mac[0] = 0x00; @@ -265,9 +238,10 @@ int main(int argc, FAR char *argv[]) /* Configure the telnet daemon */ - memset(&config, 0, sizeof(config)); config.d_port = HTONS(23); config.d_family = AF_INET; + config.d_priority = CONFIG_EXAMPLES_TELNETD_DAEMONPRIO; + config.d_stacksize = CONFIG_EXAMPLES_TELNETD_DAEMONSTACKSIZE; config.t_priority = CONFIG_EXAMPLES_TELNETD_CLIENTPRIO; config.t_stacksize = CONFIG_EXAMPLES_TELNETD_CLIENTSTACKSIZE; config.t_entry = telnetd_session; @@ -275,7 +249,7 @@ int main(int argc, FAR char *argv[]) /* Start the telnet daemon */ printf("telnetd_main: Starting the Telnet daemon\n"); - ret = telnetd_daemon(&config); + ret = telnetd_start(&config); if (ret < 0) { printf("Failed to start the Telnet daemon\n"); diff --git a/examples/telnetd/telnetd.h b/examples/telnetd/telnetd.h index d3661537a..fb5fdcd64 100644 --- a/examples/telnetd/telnetd.h +++ b/examples/telnetd/telnetd.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/telnetd/telnetd.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -26,9 +24,7 @@ /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ - /* Configuration ************************************************************/ - /* CONFIG_EXAMPLES_TELNETD_DAEMONPRIO - Priority of the Telnet daemon. * Default: SCHED_PRIORITY_DEFAULT * CONFIG_EXAMPLES_TELNETD_DAEMONSTACKSIZE - Stack size allocated for the @@ -39,12 +35,10 @@ * Telnet client. Default: 2048 * CONFIG_EXAMPLES_TELNETD_NOMAC - If the hardware has no MAC address of its * own, define this =y to provide a bogus address for testing. - * CONFIG_EXAMPLES_TELNETD_IPADDR - The target IP address. - * Default 10.0.0.2 - * CONFIG_EXAMPLES_TELNETD_DRIPADDR - The default router address. - * Default 10.0.0.1 - * CONFIG_EXAMPLES_TELNETD_NETMASK - The network mask. - * Default: 255.255.255.0 + * CONFIG_EXAMPLES_TELNETD_IPADDR - The target IP address. Default 10.0.0.2 + * CONFIG_EXAMPLES_TELNETD_DRIPADDR - The default router address. Default + * 10.0.0.1 + * CONFIG_EXAMPLES_TELNETD_NETMASK - The network mask. Default: 255.255.255.0 */ #ifndef CONFIG_EXAMPLES_TELNETD_DAEMONPRIO @@ -75,7 +69,7 @@ /* Other definitions ********************************************************/ -#define SHELL_PROMPT "cfg> " +#define SHELL_PROMPT "uIP 1.0> " /**************************************************************************** * Public Function Prototypes diff --git a/examples/termios/CMakeLists.txt b/examples/termios/CMakeLists.txt deleted file mode 100644 index 186686694..000000000 --- a/examples/termios/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# ############################################################################## -# apps/examples/termios/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_TERMIOS) - nuttx_add_application( - NAME - termios - PRIORITY - ${CONFIG_EXAMPLES_TERMIOS_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_TERMIOS_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_TERMIOS} - SRCS - termios_main.c) -endif() diff --git a/examples/termios/Make.defs b/examples/termios/Make.defs index dc6dd3a5a..06ac9be46 100644 --- a/examples/termios/Make.defs +++ b/examples/termios/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/termios/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/termios/Makefile b/examples/termios/Makefile index 84cb78ea3..142952325 100644 --- a/examples/termios/Makefile +++ b/examples/termios/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/termios/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/termios/termios_main.c b/examples/termios/termios_main.c index 91958a132..70c2d1cd3 100644 --- a/examples/termios/termios_main.c +++ b/examples/termios/termios_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/termios/termios_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -125,7 +123,7 @@ int main(int argc, FAR char *argv[]) */ } - close(fd); + (void)close(fd); /* Now, we should reopen the terminal with the new * attributes to see if they took effect; diff --git a/examples/thttpd/CMakeLists.txt b/examples/thttpd/CMakeLists.txt deleted file mode 100644 index 1e8a4336c..000000000 --- a/examples/thttpd/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -# ############################################################################## -# apps/examples/thttpd/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_THTTPD) - nuttx_add_application(NAME thttpd) -endif() diff --git a/examples/thttpd/Make.defs b/examples/thttpd/Make.defs index 4966689fc..162aa4cc2 100644 --- a/examples/thttpd/Make.defs +++ b/examples/thttpd/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/thttpd/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/thttpd/Makefile b/examples/thttpd/Makefile index 1891b10bf..4b4050904 100644 --- a/examples/thttpd/Makefile +++ b/examples/thttpd/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/thttpd/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -33,8 +31,6 @@ ifeq ($(CONFIG_THTTPD_BINFS),y) else CONTENT_MAKE += -f Makefile.nxflat CSRCS += symtab.c - content$(DELIM)symtab.c_CFLAGS = -fno-builtin - content$(DELIM)symtab.c_CELFFLAGS = -fno-builtin endif PROGNAME = thttp diff --git a/examples/thttpd/content/Makefile.binfs b/examples/thttpd/content/Makefile.binfs index 60a6a74ed..eeb241bba 100644 --- a/examples/thttpd/content/Makefile.binfs +++ b/examples/thttpd/content/Makefile.binfs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/thttpd/content/Makefile.binfs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -26,7 +24,7 @@ PROGNAME = hello tasks PRIORITY = $(CONFIG_THTTPD_CGI_PRIORITY) STACKSIZE = $(CONFIG_THTTPD_CGI_STACKSIZE) -MAINSRC = hello.c tasks.c +CSRCS = hello.c tasks.c DEPPATH += --dep-path hello --dep-path tasks VPATH += :hello:tasks diff --git a/examples/thttpd/content/Makefile.nxflat b/examples/thttpd/content/Makefile.nxflat index 795c8caf0..906a5c0fe 100644 --- a/examples/thttpd/content/Makefile.nxflat +++ b/examples/thttpd/content/Makefile.nxflat @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/thttpd/content/Makefile.nxflat # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -47,7 +45,7 @@ $(foreach DIR, $(SUBDIRS), $(eval $(call DIR_template,$(DIR),install))) # Install each program in the romfs directory install: $(foreach DIR, $(SUBDIRS), $(DIR)_install) - $(Q) (for file in $(INSTALL_FILES); do \ + $(Q) ( for file in $(INSTALL_FILES); do\ install -m 0644 -D $${file} $(ROMFS_DIR)/$${file}; \ done; ) diff --git a/examples/thttpd/content/hello/Makefile b/examples/thttpd/content/hello/Makefile index 67becfcf7..fceb1c366 100644 --- a/examples/thttpd/content/hello/Makefile +++ b/examples/thttpd/content/hello/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/thttpd/content/hello/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/thttpd/content/hello/hello.c b/examples/thttpd/content/hello/hello.c index 5a74ffedd..7c6b4b8e0 100644 --- a/examples/thttpd/content/hello/hello.c +++ b/examples/thttpd/content/hello/hello.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/thttpd/content/hello/hello.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/thttpd/content/tasks/Makefile b/examples/thttpd/content/tasks/Makefile index 5fcec6df6..b1a2f4035 100644 --- a/examples/thttpd/content/tasks/Makefile +++ b/examples/thttpd/content/tasks/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/thttpd/content/tasks/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/thttpd/content/tasks/tasks.c b/examples/thttpd/content/tasks/tasks.c index 089a751b6..e865d208c 100644 --- a/examples/thttpd/content/tasks/tasks.c +++ b/examples/thttpd/content/tasks/tasks.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/thttpd/content/tasks/tasks.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -26,36 +24,48 @@ #include <nuttx/config.h> -#include <ctype.h> -#include <dirent.h> -#include <errno.h> -#include <fcntl.h> -#include <stdbool.h> #include <stdio.h> -#include <string.h> +#include <stdlib.h> #include <unistd.h> +#include <sched.h> + +#include <nuttx/sched.h> /**************************************************************************** - * Pre-processor Definitions + * Private Data ****************************************************************************/ -#ifndef THTTPD_PROCFS_MOUNTPOINT -# define THTTPD_PROCFS_MOUNTPOINT "/proc" -#endif - -#define THTTPD_STATUS_SIZE 512 - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -struct thttpd_task_status_s +static const char *g_statenames[] = { - FAR const char *name; - FAR const char *type; - FAR const char *state; - FAR const char *priority; - FAR const char *policy; + "INVALID ", + "PENDING ", + "READY ", + "RUNNING ", + "INACTIVE", + "WAITSEM ", +#ifndef CONFIG_DISABLE_MQUEUE + "WAITSIG ", +#endif +#ifndef CONFIG_DISABLE_MQUEUE + "MQNEMPTY", + "MQNFULL " +#endif +}; + +static const char *g_ttypenames[4] = +{ + "TASK ", + "PTHREAD", + "KTHREAD", + "--?-- " +}; + +static FAR const char *g_policynames[4] = +{ + "FIFO", + "RR ", + "SPOR", + "OTHR" }; /**************************************************************************** @@ -66,210 +76,40 @@ struct thttpd_task_status_s * Private Functions ****************************************************************************/ -/**************************************************************************** - * Name: tasks_trim_value - ****************************************************************************/ +/* NOTEs: + * + * 1. One limitation in the use of NXFLAT is that functions that are + * referenced as a pointer-to-a-function must have global scope. + * Otherwise ARM GCC will generate some bad logic. + * 2. In general, when called back, there is no guarantee to that PIC + * registers will be valid and, unless you take special precautions, it + * could be dangerous to reference global variables in the callback + * function. + */ -static FAR char *tasks_trim_value(FAR char *line) +void show_task(FAR struct tcb_s *tcb, FAR void *arg) { - FAR char *end; + FAR const char *policy; - while (isblank((unsigned char)*line) && *line != '\0') - { - line++; - } + /* Show task/thread status */ - end = line + strlen(line); - while (end > line && - (*(end - 1) == '\n' || *(end - 1) == '\r' || - isblank((unsigned char)*(end - 1)))) - { - end--; - } - - *end = '\0'; - return line; -} - -/**************************************************************************** - * Name: tasks_is_pid_dir - ****************************************************************************/ - -static bool tasks_is_pid_dir(FAR const struct dirent *entryp) -{ - FAR const char *name = entryp->d_name; - - if (!DIRENT_ISDIRECTORY(entryp->d_type) || *name == '\0') - { - return false; - } - - for (; *name != '\0'; name++) - { - if (!isdigit((unsigned char)*name)) - { - return false; - } - } - - return true; -} - -/**************************************************************************** - * Name: tasks_parse_status_line - ****************************************************************************/ - -static void tasks_parse_status_line(FAR char *line, - FAR struct thttpd_task_status_s *status) -{ - if (strncmp(line, "Name:", 5) == 0) - { - status->name = tasks_trim_value(&line[5]); - } - else if (strncmp(line, "Type:", 5) == 0) - { - status->type = tasks_trim_value(&line[5]); - } - else if (strncmp(line, "State:", 6) == 0) - { - status->state = tasks_trim_value(&line[6]); - } - else if (strncmp(line, "Priority:", 9) == 0) - { - status->priority = tasks_trim_value(&line[9]); - } - else if (strncmp(line, "Scheduler:", 10) == 0) - { - status->policy = tasks_trim_value(&line[10]); - } -} - -/**************************************************************************** - * Name: tasks_parse_status - ****************************************************************************/ - -static void tasks_parse_status(FAR char *buffer, - FAR struct thttpd_task_status_s *status) -{ - FAR char *line = buffer; - - while (line != NULL && *line != '\0') - { - FAR char *next = strchr(line, '\n'); - if (next != NULL) - { - *next++ = '\0'; - } - - tasks_parse_status_line(line, status); - line = next; - } -} - -/**************************************************************************** - * Name: tasks_read_status - ****************************************************************************/ - -static int tasks_read_status(FAR const char *pid, FAR char *buffer, - size_t buflen, - FAR struct thttpd_task_status_s *status) -{ - char filepath[sizeof(THTTPD_PROCFS_MOUNTPOINT) + NAME_MAX + - sizeof("/status") + 1]; - ssize_t nread; - size_t total = 0; - int ret; - int fd; - - ret = snprintf(filepath, sizeof(filepath), "%s/%s/status", - THTTPD_PROCFS_MOUNTPOINT, pid); - if (ret < 0 || ret >= sizeof(filepath)) - { - return -ENAMETOOLONG; - } - - fd = open(filepath, O_RDONLY); - if (fd < 0) - { - return -errno; - } - - while (total < buflen - 1) - { - nread = read(fd, &buffer[total], buflen - 1 - total); - if (nread < 0) - { - ret = -errno; - close(fd); - return ret; - } - else if (nread == 0) - { - break; - } - - total += nread; - } - - close(fd); - buffer[total] = '\0'; - tasks_parse_status(buffer, status); - return OK; -} - -/**************************************************************************** - * Name: show_task - ****************************************************************************/ - -static void show_task(FAR const char *pid, - FAR const struct thttpd_task_status_s *status) -{ - printf("%5s %-12s %-14s %-7s %-18s %s\n", - pid, status->priority, status->policy, status->type, - status->state, status->name); -} - -/**************************************************************************** - * Name: show_tasks - ****************************************************************************/ - -static int show_tasks(void) -{ - FAR struct dirent *entryp; - DIR *dirp; - - dirp = opendir(THTTPD_PROCFS_MOUNTPOINT); - if (dirp == NULL) - { - printf("Unable to open %s (is procfs mounted?): %d\n", - THTTPD_PROCFS_MOUNTPOINT, errno); - return -errno; - } - - while ((entryp = readdir(dirp)) != NULL) - { - char buffer[THTTPD_STATUS_SIZE]; - struct thttpd_task_status_s status = - { - "", "", "", "", "" - }; - - if (!tasks_is_pid_dir(entryp)) - { - continue; - } - - if (tasks_read_status(entryp->d_name, buffer, sizeof(buffer), - &status) < 0) - { - continue; - } - - show_task(entryp->d_name, &status); - } - - closedir(dirp); - return OK; + policy = g_policynames[(tcb->flags & TCB_FLAG_POLICY_MASK) >> + TCB_FLAG_POLICY_SHIFT]; +#if CONFIG_TASK_NAME_SIZE > 0 + printf("%5d %3d %4s %7s%c%c %8s %s\n", +#else + printf("%5d %3d %4s %7s%c%c %8s\n", +#endif + tcb->pid, tcb->sched_priority, policy, + g_ttypenames[(tcb->flags & TCB_FLAG_TTYPE_MASK) >> + TCB_FLAG_TTYPE_SHIFT], + tcb->flags & TCB_FLAG_NONCANCELABLE ? 'N' : ' ', + tcb->flags & TCB_FLAG_CANCEL_PENDING ? 'P' : ' ', + g_statenames[tcb->task_state] +#if CONFIG_TASK_NAME_SIZE > 0 + , tcb->name +#endif + ); } /**************************************************************************** @@ -299,12 +139,10 @@ int main(int argc, char *argv[]) "<br>\r\n" "</div>\r\n" "<div class=\"contentblock\">\r\n" - "<pre>\r\n"); + "<pre>\r\n" + "PID PRI SCHD TYPE NP STATE NAME\r\n"); - printf("%5s %-12s %-14s %-7s %-18s %s\n", - "PID", "PRI", "SCHEDULER", "TYPE", "STATE", "NAME"); - - show_tasks(); + nxsched_foreach(show_task, NULL); puts( "</pre>\r\n" diff --git a/examples/thttpd/thttpd_main.c b/examples/thttpd/thttpd_main.c index 5ee01b455..ae9b82df8 100644 --- a/examples/thttpd/thttpd_main.c +++ b/examples/thttpd/thttpd_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/thttpd/thttpd_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -33,13 +31,14 @@ #include <stdlib.h> #include <unistd.h> #include <errno.h> -#include <nuttx/debug.h> +#include <debug.h> #include <net/if.h> #include <arpa/inet.h> #include <netinet/in.h> #include <netinet/ether.h> +#include <nuttx/net/arp.h> #include "netutils/netlib.h" #include "netutils/thttpd.h" @@ -49,6 +48,10 @@ # include <sys/boardctl.h> #endif +#ifdef CONFIG_THTTPD_BINFS +# include <nuttx/fs/unionfs.h> +#endif + #ifdef CONFIG_NET_SLIP # include <nuttx/net/net.h> #endif @@ -136,7 +139,7 @@ #ifdef CONFIG_THTTPD_BINFS # define ROMFS_MOUNTPT "/mnt/tmp1" -# define ROMFS_PREFIX "" +# define ROMFS_PREFIX NULL # define BINFS_MOUNTPT "/mnt/tmp2" # define BINFS_PREFIX "cgi-bin" # define UNIONFS_MOUNTPT CONFIG_THTTPD_PATH @@ -163,7 +166,7 @@ */ FAR const struct symtab_s *g_thttpdsymtab; -int g_thttpdnsymbols; +int g_thttpdnsymbols; #endif /**************************************************************************** @@ -292,9 +295,8 @@ int main(int argc, FAR char *argv[]) printf("Creating UNIONFS filesystem at %s\n", UNIONFS_MOUNTPT); - ret = mount(NULL, UNIONFS_MOUNTPT, "unionfs", 0, - "fspath1=" ROMFS_MOUNTPT ",prefix1=" ROMFS_PREFIX - ",fspath2=" BINFS_MOUNTPT ",prefix2=" BINFS_PREFIX); + ret = unionfs_mount(ROMFS_MOUNTPT, ROMFS_PREFIX, BINFS_MOUNTPT, + BINFS_PREFIX, UNIONFS_MOUNTPT); if (ret < 0) { printf("ERROR: Failed to create the union file system at %s: %d\n", diff --git a/examples/tiff/CMakeLists.txt b/examples/tiff/CMakeLists.txt deleted file mode 100644 index 1e3059a32..000000000 --- a/examples/tiff/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# ############################################################################## -# apps/examples/tiff/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_TIFF) - nuttx_add_application( - NAME - tiff - STACKSIZE - ${CONFIG_DEFAULT_TASK_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_TIFF} - SRCS - tiff_main.c) -endif() diff --git a/examples/tiff/Make.defs b/examples/tiff/Make.defs index 8f8fa9eeb..51e773d63 100644 --- a/examples/tiff/Make.defs +++ b/examples/tiff/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/tiff/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/tiff/Makefile b/examples/tiff/Makefile index a5afb58db..d04aa8906 100644 --- a/examples/tiff/Makefile +++ b/examples/tiff/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/tiff/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/tiff/tiff_main.c b/examples/tiff/tiff_main.c index e72bc7482..f511e9791 100644 --- a/examples/tiff/tiff_main.c +++ b/examples/tiff/tiff_main.c @@ -1,7 +1,5 @@ /**************************************************************************** - * apps/examples/tiff/tiff_main.c - * - * SPDX-License-Identifier: Apache-2.0 + * apps/graphics/tiff/tiff_main.c * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -35,13 +33,10 @@ /**************************************************************************** * Pre-Processor Definitions ****************************************************************************/ - /* Configuration ************************************************************/ - -/* This is a simple unit test for the TIFF creation library at - * apps/graphic/tiff. - * It is configured to work in the Linux user-mode simulation and - * has not been tested in any other environment. +/* This is a simple unit test for the TIFF creation library at apps/graphic/tiff. + * It is configured to work in the Linux user-mode simulation and has not been + * tested in any other environment. * * Other configuration options: * @@ -93,7 +88,7 @@ int main(int argc, FAR char *argv[]) { struct tiff_info_s info; - uint8_t strip[3 * 256]; + uint8_t strip[3*256]; uint8_t *ptr; int green; int blue; @@ -149,6 +144,5 @@ int main(int argc, FAR char *argv[]) printf("tiff_finalize() failed: %d\n", ret); exit(1); } - return 0; } diff --git a/examples/timer/CMakeLists.txt b/examples/timer/CMakeLists.txt deleted file mode 100644 index 897ff2ffa..000000000 --- a/examples/timer/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# ############################################################################## -# apps/examples/timer/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_TIMER) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_TIMER_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_TIMER_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_TIMER_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_TIMER} - SRCS - timer_main.c) -endif() diff --git a/examples/timer/Kconfig b/examples/timer/Kconfig index 3a997ccab..bc61b7dfb 100644 --- a/examples/timer/Kconfig +++ b/examples/timer/Kconfig @@ -38,7 +38,7 @@ config EXAMPLES_TIMER_NSAMPLES config EXAMPLES_TIMER_SIGNO int "Notification signal number" - default 32 + default 17 ---help--- This is the signal number that is used to notify the test of timer expiration events. diff --git a/examples/timer/Make.defs b/examples/timer/Make.defs index bb3ad4b03..cc24845fa 100644 --- a/examples/timer/Make.defs +++ b/examples/timer/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/timer/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/timer/Makefile b/examples/timer/Makefile index 5e01ed5fb..b2046da0b 100644 --- a/examples/timer/Makefile +++ b/examples/timer/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/timer/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/timer/timer_main.c b/examples/timer/timer_main.c index eec3cbd5a..13bc2b3a6 100644 --- a/examples/timer/timer_main.c +++ b/examples/timer/timer_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/timer/timer_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -33,8 +31,6 @@ #include <signal.h> #include <errno.h> #include <string.h> -#include <unistd.h> - #include <nuttx/timers/timer.h> /**************************************************************************** @@ -60,7 +56,7 @@ #endif #ifndef CONFIG_EXAMPLES_TIMER_SIGNO -# define CONFIG_EXAMPLES_TIMER_SIGNO 32 +# define CONFIG_EXAMPLES_TIMER_SIGNO 17 #endif /**************************************************************************** @@ -139,14 +135,14 @@ int main(int argc, FAR char *argv[]) int i; int opt; char devname[DEVNAME_SIZE]; - strlcpy(devname, CONFIG_EXAMPLES_TIMER_DEVNAME, sizeof(devname)); + strcpy(devname, CONFIG_EXAMPLES_TIMER_DEVNAME); while ((opt = getopt(argc, argv, ":d:")) != -1) { switch (opt) { case 'd': - strlcpy(devname, optarg, sizeof(devname)); + strcpy(devname, optarg); break; case ':': fprintf(stderr, "ERROR: Option needs a value\n"); @@ -221,8 +217,7 @@ int main(int argc, FAR char *argv[]) printf("Attach timer handler\n"); - notify.pid = getpid(); - notify.periodic = true; + notify.pid = getpid(); notify.event.sigev_notify = SIGEV_SIGNAL; notify.event.sigev_signo = CONFIG_EXAMPLES_TIMER_SIGNO; diff --git a/examples/timer_gpio/CMakeLists.txt b/examples/timer_gpio/CMakeLists.txt deleted file mode 100644 index 2d64ec353..000000000 --- a/examples/timer_gpio/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# ############################################################################## -# apps/examples/timer_gpio/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_TIMER_GPIO) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_TIMER_GPIO_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_TIMER_GPIO_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_TIMER_GPIO_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_TIMER_GPIO} - SRCS - timer_gpio_main.c) -endif() diff --git a/examples/timer_gpio/Kconfig b/examples/timer_gpio/Kconfig index 17c31c12d..f36b3b60d 100644 --- a/examples/timer_gpio/Kconfig +++ b/examples/timer_gpio/Kconfig @@ -15,7 +15,7 @@ config EXAMPLES_TIMER_GPIO connected to the digital output. This example differs from the timer example because it waits on a sigwaitinfo() instead of using a signal handler. This approach ensures a deterministic wake-up time when the - signal occurs. + signal occurs. if EXAMPLES_TIMER_GPIO @@ -39,7 +39,7 @@ config EXAMPLES_TIMER_GPIO_INTERVAL config EXAMPLES_TIMER_GPIO_SIGNO int "Notification signal number" - default 32 + default 17 ---help--- This is the signal number that is used to notify that a timer interrupt occurred. diff --git a/examples/timer_gpio/Make.defs b/examples/timer_gpio/Make.defs index ca5e2034e..90aa2b032 100644 --- a/examples/timer_gpio/Make.defs +++ b/examples/timer_gpio/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/timer_gpio/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -20,6 +18,6 @@ # ############################################################################ -ifneq ($(CONFIG_EXAMPLES_TIMER_GPIO),) +ifeq ($(CONFIG_EXAMPLES_TIMER_GPIO),y) CONFIGURED_APPS += $(APPDIR)/examples/timer_gpio endif diff --git a/examples/timer_gpio/Makefile b/examples/timer_gpio/Makefile index c324f17f3..6dd0841ed 100644 --- a/examples/timer_gpio/Makefile +++ b/examples/timer_gpio/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/timer_gpio/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/timer_gpio/timer_gpio_main.c b/examples/timer_gpio/timer_gpio_main.c index f39fa1256..a76e68e11 100644 --- a/examples/timer_gpio/timer_gpio_main.c +++ b/examples/timer_gpio/timer_gpio_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/timer_gpio/timer_gpio_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -33,8 +31,6 @@ #include <signal.h> #include <errno.h> #include <string.h> -#include <unistd.h> - #include <nuttx/timers/timer.h> #include <nuttx/ioexpander/gpio.h> @@ -180,9 +176,7 @@ static int timer_gpio_daemon(int argc, char *argv[]) printf("Configure the timer notification.\n"); - notify.pid = getpid(); - notify.periodic = true; - + notify.pid = getpid(); notify.event.sigev_notify = SIGEV_SIGNAL; notify.event.sigev_signo = CONFIG_EXAMPLES_TIMER_GPIO_SIGNO; notify.event.sigev_value.sival_ptr = NULL; @@ -269,10 +263,8 @@ int main(int argc, FAR char *argv[]) /* Use the ones configured on menuconfig */ - strlcpy(g_devtim, CONFIG_EXAMPLES_TIMER_GPIO_TIM_DEVNAME, - sizeof(g_devtim)); - strlcpy(g_devgpio, CONFIG_EXAMPLES_TIMER_GPIO_GPIO_DEVNAME, - sizeof(g_devgpio)); + strcpy(g_devtim, CONFIG_EXAMPLES_TIMER_GPIO_TIM_DEVNAME); + strcpy(g_devgpio, CONFIG_EXAMPLES_TIMER_GPIO_GPIO_DEVNAME); /* Or the ones passed as arguments */ @@ -281,10 +273,10 @@ int main(int argc, FAR char *argv[]) switch (opt) { case 't': - strlcpy(g_devtim, optarg, sizeof(g_devtim)); + strcpy(g_devtim, optarg); break; case 'g': - strlcpy(g_devgpio, optarg, sizeof(g_devgpio)); + strcpy(g_devgpio, optarg); break; case ':': fprintf(stderr, "ERROR: Option needs a value\n"); diff --git a/examples/tlpi/.gitignore b/examples/tlpi/.gitignore deleted file mode 100644 index 2f57dd394..000000000 --- a/examples/tlpi/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/tlpi diff --git a/examples/tlpi/0001-add-ename.c.inc.patch b/examples/tlpi/0001-add-ename.c.inc.patch deleted file mode 100644 index a877ebf7e..000000000 --- a/examples/tlpi/0001-add-ename.c.inc.patch +++ /dev/null @@ -1,57 +0,0 @@ -From 57d210aa51e9706c3e21156d873bf356527be8c7 Mon Sep 17 00:00:00 2001 -From: chenzhijia <chenzhijia@xiaomi.com> -Date: Tue, 19 Mar 2024 11:26:27 +0800 -Subject: [PATCH] Linux case base:add ename.c.inc - -add source code ename.c.inc - -Change-Id: Ie31e2ac3908ce46cfb22102d8cc18fa1b961deb4 -Signed-off-by: chenzhijia <chenzhijia@xiaomi.com> ---- - -diff --git a/lib/ename.c.inc b/lib/ename.c.inc -new file mode 100644 -index 0000000..42642e1 ---- /dev/null -+++ b/lib/ename.c.inc -@@ -0,0 +1,39 @@ -+/* ename.c.inc -+ -+ Built on GNU/Linux x86_64 with glibc 2.38 -+*/ -+static char *ename[] = { -+ /* 0 */ "", -+ /* 1 */ "EPERM", "ENOENT", "ESRCH", "EINTR", "EIO", "ENXIO", -+ /* 7 */ "E2BIG", "ENOEXEC", "EBADF", "ECHILD", -+ /* 11 */ "EAGAIN/EWOULDBLOCK", "ENOMEM", "EACCES", "EFAULT", -+ /* 15 */ "ENOTBLK", "EBUSY", "EEXIST", "EXDEV", "ENODEV", -+ /* 20 */ "ENOTDIR", "EISDIR", "EINVAL", "ENFILE", "EMFILE", -+ /* 25 */ "ENOTTY", "ETXTBSY", "EFBIG", "ENOSPC", "ESPIPE", -+ /* 30 */ "EROFS", "EMLINK", "EPIPE", "EDOM", "ERANGE", -+ /* 35 */ "EDEADLK/EDEADLOCK", "ENAMETOOLONG", "ENOLCK", "ENOSYS", -+ /* 39 */ "ENOTEMPTY", "ELOOP", "", "ENOMSG", "EIDRM", "ECHRNG", -+ /* 45 */ "EL2NSYNC", "EL3HLT", "EL3RST", "ELNRNG", "EUNATCH", -+ /* 50 */ "ENOCSI", "EL2HLT", "EBADE", "EBADR", "EXFULL", "ENOANO", -+ /* 56 */ "EBADRQC", "EBADSLT", "", "EBFONT", "ENOSTR", "ENODATA", -+ /* 62 */ "ETIME", "ENOSR", "ENONET", "ENOPKG", "EREMOTE", -+ /* 67 */ "ENOLINK", "EADV", "ESRMNT", "ECOMM", "EPROTO", -+ /* 72 */ "EMULTIHOP", "EDOTDOT", "EBADMSG", "EOVERFLOW", -+ /* 76 */ "ENOTUNIQ", "EBADFD", "EREMCHG", "ELIBACC", "ELIBBAD", -+ /* 81 */ "ELIBSCN", "ELIBMAX", "ELIBEXEC", "EILSEQ", "ERESTART", -+ /* 86 */ "ESTRPIPE", "EUSERS", "ENOTSOCK", "EDESTADDRREQ", -+ /* 90 */ "EMSGSIZE", "EPROTOTYPE", "ENOPROTOOPT", -+ /* 93 */ "EPROTONOSUPPORT", "ESOCKTNOSUPPORT", -+ /* 95 */ "EOPNOTSUPP/ENOTSUP", "EPFNOSUPPORT", "EAFNOSUPPORT", -+ /* 98 */ "EADDRINUSE", "EADDRNOTAVAIL", "ENETDOWN", "ENETUNREACH", -+ /* 102 */ "ENETRESET", "ECONNABORTED", "ECONNRESET", "ENOBUFS", -+ /* 106 */ "EISCONN", "ENOTCONN", "ESHUTDOWN", "ETOOMANYREFS", -+ /* 110 */ "ETIMEDOUT", "ECONNREFUSED", "EHOSTDOWN", "EHOSTUNREACH", -+ /* 114 */ "EALREADY", "EINPROGRESS", "ESTALE", "EUCLEAN", -+ /* 118 */ "ENOTNAM", "ENAVAIL", "EISNAM", "EREMOTEIO", "EDQUOT", -+ /* 123 */ "ENOMEDIUM", "EMEDIUMTYPE", "ECANCELED", "ENOKEY", -+ /* 127 */ "EKEYEXPIRED", "EKEYREVOKED", "EKEYREJECTED", -+ /* 130 */ "EOWNERDEAD", "ENOTRECOVERABLE", "ERFKILL", "EHWPOISON" -+}; -+ -+#define MAX_ENAME 133 -\ No newline at end of file diff --git a/examples/tlpi/0002-fix-setenv-compilation-error.patch b/examples/tlpi/0002-fix-setenv-compilation-error.patch deleted file mode 100644 index c5a7a01fd..000000000 --- a/examples/tlpi/0002-fix-setenv-compilation-error.patch +++ /dev/null @@ -1,111 +0,0 @@ -From f1154cd6558b99aa5827ac98b20a20753dabd865 Mon Sep 17 00:00:00 2001 -From: chenzhijia <chenzhijia@xiaomi.com> -Date: Tue, 18 Jun 2024 18:19:18 +0800 -Subject: [PATCH] tlpi/proc:fix setenv case - -Remove duplicate functions and invalid commands - -Change-Id: I59d84511356f6da7313844bfad63ac466fd3075f -Signed-off-by: chenzhijia <chenzhijia@xiaomi.com> ---- - -diff --git a/proc/setenv.c b/proc/setenv.c -index d396628..d75ae35 100644 ---- a/proc/setenv.c -+++ b/proc/setenv.c -@@ -21,92 +21,25 @@ - #include <errno.h> - - int --unsetenv(const char *name) --{ -- extern char **environ; -- char **ep, **sp; -- size_t len; -- -- if (name == NULL || name[0] == '\0' || strchr(name, '=') != NULL) { -- errno = EINVAL; -- return -1; -- } -- -- len = strlen(name); -- -- for (ep = environ; *ep != NULL; ) -- if (strncmp(*ep, name, len) == 0 && (*ep)[len] == '=') { -- -- /* Remove found entry by shifting all successive entries -- back one element */ -- -- for (sp = ep; *sp != NULL; sp++) -- *sp = *(sp + 1); -- -- /* Continue around the loop to further instances of 'name' */ -- -- } else { -- ep++; -- } -- -- return 0; --} -- --int --setenv(const char *name, const char *value, int overwrite) --{ -- char *es; -- -- if (name == NULL || name[0] == '\0' || strchr(name, '=') != NULL || -- value == NULL) { -- errno = EINVAL; -- return -1; -- } -- -- if (getenv(name) != NULL && overwrite == 0) -- return 0; -- -- unsetenv(name); /* Remove all occurrences */ -- -- es = malloc(strlen(name) + strlen(value) + 2); -- /* +2 for '=' and null terminator */ -- if (es == NULL) -- return -1; -- -- strcpy(es, name); -- strcat(es, "="); -- strcat(es, value); -- -- return (putenv(es) != 0) ? -1 : 0; --} -- --#ifdef TEST_IT -- --int - main() - { - if (putenv("TT=xxxxx") != 0) - perror("putenv"); - - system("echo '***** Environment before unsetenv(TT)'; " -- "printenv | grep ^TT"); -- system("echo 'Total lines from printenv:' `printenv | wc -l`"); -+ "env"); - - unsetenv("TT"); - - system("echo '***** Environment after unsetenv(TT)'; " -- "printenv | grep ^TT"); -- system("echo 'Total lines from printenv:' `printenv | wc -l`"); -+ "env"); - - setenv("xyz", "one", 1); - setenv("xyz", "two", 0); - setenv("xyz2", "222", 0); - - system("echo '***** Environment after setenv() calls'; " -- "printenv | grep ^x"); -- system("echo 'Total lines from printenv:' `printenv | wc -l`"); -+ "env"); - - exit(EXIT_SUCCESS); - } -- --#endif diff --git a/examples/tlpi/0003-fix-memoryleak-in-check_password.patch b/examples/tlpi/0003-fix-memoryleak-in-check_password.patch deleted file mode 100644 index 16feb06ed..000000000 --- a/examples/tlpi/0003-fix-memoryleak-in-check_password.patch +++ /dev/null @@ -1,66 +0,0 @@ -From 03445e7bf9916a58a4b80d7062d577f38ed2b279 Mon Sep 17 00:00:00 2001 -From: chenzhijia <chenzhijia@xiaomi.com> -Date: Tue, 14 May 2024 16:40:28 +0800 -Subject: [PATCH] tlpi/users_groups:Fix memory leak in check_password - -free memory before program exits - -Change-Id: I28789b5ceaec4aaa45bb13f66cb3f61de1111841 -Signed-off-by: chenzhijia <chenzhijia@xiaomi.com> ---- - -diff --git a/users_groups/check_password.c b/users_groups/check_password.c -index c142ac7..a70cbb6 100644 ---- a/users_groups/check_password.c -+++ b/users_groups/check_password.c -@@ -30,6 +30,22 @@ - #include <shadow.h> - #include "tlpi_hdr.h" - -+#define fatal(msg) \ -+ do \ -+ { \ -+ free(username); \ -+ fatal(msg); \ -+ } \ -+ while (0) -+ -+#define errExit(msg) \ -+ do \ -+ { \ -+ free(username); \ -+ errExit(msg); \ -+ } \ -+ while (0) -+ - int - main(int argc, char *argv[]) - { -@@ -53,7 +69,7 @@ - printf("Username: "); - fflush(stdout); - if (fgets(username, lnmax, stdin) == NULL) -- exit(EXIT_FAILURE); /* Exit on EOF */ -+ goto err; /* Exit on EOF */ - - len = strlen(username); - if (username[len - 1] == '\n') -@@ -85,12 +101,17 @@ - authOk = strcmp(encrypted, pwd->pw_passwd) == 0; - if (!authOk) { - printf("Incorrect password\n"); -- exit(EXIT_FAILURE); -+ goto err; - } - - printf("Successfully authenticated: UID=%ld\n", (long) pwd->pw_uid); - - /* Now do authenticated work... */ - -+ free(username); - exit(EXIT_SUCCESS); -+ -+err: -+ free(username); -+ exit(EXIT_FAILURE); - } diff --git a/examples/tlpi/0004-fix-compilation-error.patch b/examples/tlpi/0004-fix-compilation-error.patch deleted file mode 100644 index 1b1ce57bc..000000000 --- a/examples/tlpi/0004-fix-compilation-error.patch +++ /dev/null @@ -1,37 +0,0 @@ -From 65230c70d69b253028c0f912dcd1ae0cb7446015 Mon Sep 17 00:00:00 2001 -From: chenzhijia <chenzhijia@xiaomi.com> -Date: Wed, 30 Oct 2024 10:52:48 +0800 -Subject: [PATCH] tlpi/sockets:Fix compilation error - -Fix compilation error in qemu - -Change-Id: I854ed64d163398807a07fa697bdea89bfab77236 -Signed-off-by: chenzhijia <chenzhijia@xiaomi.com> ---- - -diff --git a/sockets/list_host_addresses.c b/sockets/list_host_addresses.c -index 4db58f6..e1864c8 100644 ---- a/sockets/list_host_addresses.c -+++ b/sockets/list_host_addresses.c -@@ -23,7 +23,7 @@ - #include <stdio.h> - #include <stdlib.h> - #include <unistd.h> --#include <linux/if_link.h> -+//#include <linux/if_link.h> - - int - main(int argc, char *argv[]) -diff --git a/sockets/sendfile.c b/sockets/sendfile.c -index 54549d7..3697099 100644 ---- a/sockets/sendfile.c -+++ b/sockets/sendfile.c -@@ -17,7 +17,7 @@ - #include "tlpi_hdr.h" - #define BUF_SIZE 8192 - --ssize_t -+static ssize_t - sendfile(int out_fd, int in_fd, off_t *offset, size_t count) - { - off_t orig; diff --git a/examples/tlpi/Kconfig b/examples/tlpi/Kconfig deleted file mode 100644 index 33b1113a1..000000000 --- a/examples/tlpi/Kconfig +++ /dev/null @@ -1,23 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config EXAMPLES_TLPI - tristate "The Linux Programming Interface Example" - default n - depends on ALLOW_GPL_COMPONENTS - ---help--- - Enable the tlpi - -if EXAMPLES_TLPI - -config EXAMPLES_TLPI_PRIORITY - int "Task priority" - default 100 - -config EXAMPLES_TLPI_STACKSIZE - int "Stack size" - default DEFAULT_TASK_STACKSIZE - -endif diff --git a/examples/tlpi/Make.defs b/examples/tlpi/Make.defs deleted file mode 100644 index 3177b58aa..000000000 --- a/examples/tlpi/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/examples/tlpi/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_EXAMPLES_TLPI),) -CONFIGURED_APPS += $(APPDIR)/examples/tlpi -endif diff --git a/examples/tlpi/Makefile b/examples/tlpi/Makefile deleted file mode 100644 index 519c93d31..000000000 --- a/examples/tlpi/Makefile +++ /dev/null @@ -1,494 +0,0 @@ -############################################################################ -# apps/examples/tlpi/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -PRIORITY = $(CONFIG_EXAMPLES_TLPI_PRIORITY) -STACKSIZE = $(CONFIG_EXAMPLES_TLPI_STACKSIZE) -MODULE = $(CONFIG_EXAMPLES_TLPI) -TLPI_DOWNLOAD_URL = https://github.com/bradfa/tlpi-dist/archive/refs/heads -TLPI_UNPACK = tlpi -TLPIDIR = $(APPDIR)/examples/tlpi/tlpi - -#CFLAGS += ${INCDIR_PREFIX}$(TLPIDIR)/cap -CFLAGS += ${INCDIR_PREFIX}$(TLPIDIR)/daemons -CFLAGS += ${INCDIR_PREFIX}$(TLPIDIR)/filelock -CFLAGS += ${INCDIR_PREFIX}$(TLPIDIR)/files -CFLAGS += ${INCDIR_PREFIX}$(TLPIDIR)/lib -CFLAGS += ${INCDIR_PREFIX}$(TLPIDIR)/namespaces -CFLAGS += ${INCDIR_PREFIX}$(TLPIDIR)/pipes -CFLAGS += ${INCDIR_PREFIX}$(TLPIDIR)/procexec -CFLAGS += ${INCDIR_PREFIX}$(TLPIDIR)/procres -CFLAGS += ${INCDIR_PREFIX}$(TLPIDIR)/pty -CFLAGS += ${INCDIR_PREFIX}$(TLPIDIR)/seccomp -CFLAGS += ${INCDIR_PREFIX}$(TLPIDIR)/signals -CFLAGS += ${INCDIR_PREFIX}$(TLPIDIR)/sockets -CFLAGS += ${INCDIR_PREFIX}$(TLPIDIR)/svmsg -CFLAGS += ${INCDIR_PREFIX}$(TLPIDIR)/svsem -CFLAGS += ${INCDIR_PREFIX}$(TLPIDIR)/time -CFLAGS += ${INCDIR_PREFIX}$(TLPIDIR)/timers -CFLAGS += ${INCDIR_PREFIX}$(TLPIDIR)/tty -CFLAGS += ${INCDIR_PREFIX}$(TLPIDIR)/users_groups -CFLAGS += -Wno-strict-prototypes -Wno-unused-variable -Wno-unused-function \ - -Wno-unused-but-set-variable -Wno-uninitialized - -#CSRCS += $(TLPIDIR)/cap/cap_functions.c \ -# $(TLPIDIR)/daemons/become_daemon.c -CSRCS += $(TLPIDIR)/filelock/create_pid_file.c \ - $(TLPIDIR)/filelock/region_locking.c \ - $(TLPIDIR)/files/file_perms.c \ - $(TLPIDIR)/lib/alt_functions.c \ - $(TLPIDIR)/lib/error_functions.c \ - $(TLPIDIR)/lib/get_num.c -# $(TLPIDIR)/namespaces/userns_functions.c -CSRCS += $(TLPIDIR)/procexec/print_wait_status.c \ - $(TLPIDIR)/procres/print_rlimit.c -# $(TLPIDIR)/procres/print_rusage.c \ -# $(TLPIDIR)/pty/pty_fork.c -CSRCS += $(TLPIDIR)/pty/pty_master_open.c -# $(TLPIDIR)/pty/pty_master_open_bsd.c \ -# $(TLPIDIR)/seccomp/seccomp_functions.c -CSRCS += $(TLPIDIR)/signals/signal.c \ - $(TLPIDIR)/signals/signal_functions.c \ - $(TLPIDIR)/sockets/inet_sockets.c \ - $(TLPIDIR)/sockets/rdwrn.c \ - $(TLPIDIR)/sockets/read_line.c \ - $(TLPIDIR)/sockets/read_line_buf.c \ - $(TLPIDIR)/sockets/scm_functions.c \ - $(TLPIDIR)/sockets/sendfile.c \ - $(TLPIDIR)/sockets/unix_sockets.c -# $(TLPIDIR)/svsem/binary_sems.c \ -# $(TLPIDIR)/svsem/event_flags.c \ -# $(TLPIDIR)/threads/strerror.c \ -# $(TLPIDIR)/threads/strerror_tls.c \ -# $(TLPIDIR)/threads/strerror_tsd.c -CSRCS += $(TLPIDIR)/time/curr_time.c \ - $(TLPIDIR)/timers/itimerspec_from_str.c \ - $(TLPIDIR)/tty/tty_functions.c \ - $(TLPIDIR)/users_groups/ugid_functions.c - -# acl -#MAINSRC += $(TLPIDIR)/acl/acl_update.c \ -# $(TLPIDIR)/acl/acl_view.c -# altio -MAINSRC += $(TLPIDIR)/altio/demo_sigio.c \ - $(TLPIDIR)/altio/epoll_flags_fork.c \ - $(TLPIDIR)/altio/epoll_input.c \ - $(TLPIDIR)/altio/multithread_epoll_wait.c \ - $(TLPIDIR)/altio/poll_pipes.c \ - $(TLPIDIR)/altio/select_mq.c \ - $(TLPIDIR)/altio/self_pipe.c \ - $(TLPIDIR)/altio/t_select.c -# cap -#MAINSRC += $(TLPIDIR)/cap/cap_launcher.c \ -# $(TLPIDIR)/cap/cap_text.c \ -# $(TLPIDIR)/cap/check_password_caps.c \ -# $(TLPIDIR)/cap/demo_file_caps.c \ -# $(TLPIDIR)/cap/show_secbits.c \ -# $(TLPIDIR)/cap/t_cap_get_file.c \ -# $(TLPIDIR)/cap/t_cap_get_pid.c \ -# $(TLPIDIR)/cap/t_cap_set_file.c \ -# $(TLPIDIR)/cap/view_cap_xattr.c -# cgroups -#MAINSRC += $(TLPIDIR)/cgroups/alloc_mem.c -MAINSRC += $(TLPIDIR)/cgroups/fork_bomb.c -# $(TLPIDIR)/cgroups/fork_bomb_simple.c - -# daemons -#MAINSRC += $(TLPIDIR)/daemons/daemon_SIGHUP.c -MAINSRC += $(TLPIDIR)/daemons/t_syslog.c -# $(TLPIDIR)/daemons/test_become_daemon.c -# dirs_links -MAINSRC += $(TLPIDIR)/dirs_links/file_type_stats.c \ - $(TLPIDIR)/dirs_links/list_files.c \ - $(TLPIDIR)/dirs_links/list_files_readdir_r.c \ - $(TLPIDIR)/dirs_links/nftw_dir_tree.c \ - $(TLPIDIR)/dirs_links/t_unlink.c \ - $(TLPIDIR)/dirs_links/t_dirbasename.c -ifneq ($(CONFIG_PSEUDOFS_SOFTLINKS),) -MAINSRC += $(TLPIDIR)/dirs_links/bad_symlink.c \ - $(TLPIDIR)/dirs_links/view_symlink.c -endif -# filebuff -MAINSRC += $(TLPIDIR)/filebuff/direct_read.c \ - $(TLPIDIR)/filebuff/mix23_linebuff.c \ - $(TLPIDIR)/filebuff/mix23io.c \ - $(TLPIDIR)/filebuff/write_bytes.c -# fileio -MAINSRC += $(TLPIDIR)/fileio/atomic_append.c \ - $(TLPIDIR)/fileio/bad_exclusive_open.c \ - $(TLPIDIR)/fileio/copy.c \ - $(TLPIDIR)/fileio/large_file.c \ - $(TLPIDIR)/fileio/multi_descriptors.c \ - $(TLPIDIR)/fileio/seek_io.c \ - $(TLPIDIR)/fileio/t_readv.c \ - $(TLPIDIR)/fileio/t_truncate.c -# filelock -MAINSRC += $(TLPIDIR)/filelock/i_fcntl_locking.c -# $(TLPIDIR)/filelock/t_flock.c -# files -# $(TLPIDIR)/files/chiflag.c -MAINSRC += $(TLPIDIR)/files/t_chown.c \ - $(TLPIDIR)/files/t_stat.c \ - $(TLPIDIR)/files/t_umask.c \ - $(TLPIDIR)/files/t_utime.c \ - $(TLPIDIR)/files/t_utimes.c -# filesys -#MAINSRC += $(TLPIDIR)/filesys/t_mount.c \ -# $(TLPIDIR)/filesys/t_statfs.c -MAINSRC += $(TLPIDIR)/filesys/t_statvfs.c \ - $(TLPIDIR)/filesys/t_umount.c -# getopt -MAINSRC += $(TLPIDIR)/getopt/t_getopt.c -ifneq ($(CONFIG_FS_NOTIFY),) -# inotify -MAINSRC += $(TLPIDIR)/inotify/demo_inotify.c -# $(TLPIDIR)/inotify/dnotify.c \ -# $(TLPIDIR)/inotify/inotify_dtree.c -endif -MAINSRC += $(TLPIDIR)/inotify/rand_dtree.c -# loginacct -#MAINSRC += $(TLPIDIR)/loginacct/dump_utmpx.c \ -# $(TLPIDIR)/loginacct/utmpx_login.c \ -# $(TLPIDIR)/loginacct/view_lastlog.c -# memalloc -ifneq ($(CONFIG_BUILD_KERNEL),) -MAINSRC += $(TLPIDIR)/memalloc/free_and_sbrk.c -endif -# mmap -MAINSRC += $(TLPIDIR)/mmap/anon_mmap.c \ - $(TLPIDIR)/mmap/mmcat.c \ - $(TLPIDIR)/mmap/mmcopy.c \ - $(TLPIDIR)/mmap/t_mmap.c -# $(TLPIDIR)/mmap/t_remap_file_pages.c -# namespaces -#MAINSRC += $(TLPIDIR)/namespaces/cred_launcher.c \ -# $(TLPIDIR)/namespaces/demo_userns.c \ -# $(TLPIDIR)/namespaces/demo_uts_namespaces.c -MAINSRC += $(TLPIDIR)/namespaces/hostname.c -# $(TLPIDIR)/namespaces/make_orphans.c \ -# $(TLPIDIR)/namespaces/multi_pidns.c \ -# $(TLPIDIR)/namespaces/ns_capable.c \ -# $(TLPIDIR)/namespaces/ns_child_exec.c \ -# $(TLPIDIR)/namespaces/ns_exec.c \ -# $(TLPIDIR)/namespaces/ns_run.c \ -# $(TLPIDIR)/namespaces/orphan.c \ -# $(TLPIDIR)/namespaces/pidns_init_sleep.c \ -# $(TLPIDIR)/namespaces/show_creds.c \ -# $(TLPIDIR)/namespaces/simple_init.c \ -# $(TLPIDIR)/namespaces/t_setns_userns.c \ -# $(TLPIDIR)/namespaces/unshare.c \ -# $(TLPIDIR)/namespaces/userns_child_exec.c \ -# $(TLPIDIR)/namespaces/userns_setns_test.c -# pgsjc -#MAINSRC += $(TLPIDIR)/pgsjc/catch_SIGHUP.c \ -# $(TLPIDIR)/pgsjc/disc_SIGHUP.c -MAINSRC += $(TLPIDIR)/pgsjc/handling_SIGTSTP.c -# $(TLPIDIR)/pgsjc/job_mon.c \ -# $(TLPIDIR)/pgsjc/orphaned_pgrp_SIGHUP.c \ -# $(TLPIDIR)/pgsjc/t_setsid.c -# pipes -MAINSRC += $(TLPIDIR)/pipes/change_case.c \ - $(TLPIDIR)/pipes/fifo_seqnum_client.c \ - $(TLPIDIR)/pipes/fifo_seqnum_server.c -# $(TLPIDIR)/pipes/popen_glob.c -ifneq ($(CONFIG_LIBC_EXECFUNCS),) -MAINSRC += $(TLPIDIR)/pipes/pipe_ls_wc.c -endif -MAINSRC += $(TLPIDIR)/pipes/pipe_sync.c \ - $(TLPIDIR)/pipes/simple_pipe.c -# pmsg -MAINSRC += $(TLPIDIR)/pmsg/mq_notify_sig.c \ - $(TLPIDIR)/pmsg/mq_notify_siginfo.c -# $(TLPIDIR)/pmsg/mq_notify_sigwaitinfo.c \ -# $(TLPIDIR)/pmsg/mq_notify_thread.c -MAINSRC += $(TLPIDIR)/pmsg/mq_notify_via_signal.c -# $(TLPIDIR)/pmsg/mq_notify_via_thread.c -MAINSRC += $(TLPIDIR)/pmsg/pmsg_create.c -# $(TLPIDIR)/pmsg/pmsg_getattr.c -MAINSRC += $(TLPIDIR)/pmsg/pmsg_receive.c \ - $(TLPIDIR)/pmsg/pmsg_send.c \ - $(TLPIDIR)/pmsg/pmsg_unlink.c -# proc -MAINSRC += $(TLPIDIR)/proc/bad_longjmp.c \ - $(TLPIDIR)/proc/display_env.c \ - $(TLPIDIR)/proc/longjmp.c \ - $(TLPIDIR)/proc/mem_segments.c \ - $(TLPIDIR)/proc/modify_env.c \ - $(TLPIDIR)/proc/necho.c \ - $(TLPIDIR)/proc/setenv.c \ - $(TLPIDIR)/proc/setjmp_vars.c \ - $(TLPIDIR)/proc/t_getenv.c -# proccred -#MAINSRC += $(TLPIDIR)/proccred/idshow.c -# procexec -#MAINSRC += $(TLPIDIR)/procexec/acct_on.c \ -# $(TLPIDIR)/procexec/acct_view.c \ -# $(TLPIDIR)/procexec/acct_v3_view.c \ -# $(TLPIDIR)/procexec/demo_clone.c -MAINSRC += $(TLPIDIR)/procexec/child_status.c \ - $(TLPIDIR)/procexec/envargs.c \ - $(TLPIDIR)/procexec/exit_handlers.c -ifneq ($(CONFIG_BUILD_KERNEL),) -MAINSRC += $(TLPIDIR)/procexec/footprint.c -endif -MAINSRC += $(TLPIDIR)/procexec/fork_file_sharing.c \ - $(TLPIDIR)/procexec/fork_stdio_buf.c \ - $(TLPIDIR)/procexec/fork_sig_sync.c \ - $(TLPIDIR)/procexec/fork_whos_on_first.c \ - $(TLPIDIR)/procexec/make_zombie.c \ - $(TLPIDIR)/procexec/multi_SIGCHLD.c \ - $(TLPIDIR)/procexec/multi_wait.c \ - $(TLPIDIR)/procexec/orphan.c -# $(TLPIDIR)/procexec/pdeath_signal.c -# $(TLPIDIR)/procexec/t_clone.c -ifneq ($(CONFIG_LIBC_EXECFUNCS),) -MAINSRC += $(TLPIDIR)/procexec/closeonexec.c \ - $(TLPIDIR)/procexec/t_execl.c \ - $(TLPIDIR)/procexec/t_execle.c \ - $(TLPIDIR)/procexec/t_execlp.c \ - $(TLPIDIR)/procexec/t_execve.c -endif -MAINSRC += $(TLPIDIR)/procexec/t_fork.c \ - $(TLPIDIR)/procexec/t_system.c \ - $(TLPIDIR)/procexec/t_vfork.c \ - $(TLPIDIR)/procexec/vfork_fd_test.c -# procpri -MAINSRC += $(TLPIDIR)/procpri/demo_sched_fifo.c \ - $(TLPIDIR)/procpri/sched_set.c \ - $(TLPIDIR)/procpri/sched_view.c \ - $(TLPIDIR)/procpri/t_sched_getaffinity.c \ - $(TLPIDIR)/procpri/t_sched_setaffinity.c \ - $(TLPIDIR)/procpri/t_setpriority.c -# procres -#MAINSRC += $(TLPIDIR)/procres/rlimit_nproc.c \ -# $(TLPIDIR)/procres/rusage.c -MAINSRC += $(TLPIDIR)/procres/rusage_wait.c -# progconc -MAINSRC += $(TLPIDIR)/progconc/syscall_speed.c -ifneq ($(CONFIG_FS_NAMED_SEMAPHORES),) -# psem -MAINSRC += $(TLPIDIR)/psem/psem_create.c \ - $(TLPIDIR)/psem/psem_getvalue.c \ - $(TLPIDIR)/psem/psem_timedwait.c \ - $(TLPIDIR)/psem/psem_trywait.c \ - $(TLPIDIR)/psem/psem_post.c \ - $(TLPIDIR)/psem/psem_unlink.c \ - $(TLPIDIR)/psem/psem_wait.c -endif -MAINSRC += $(TLPIDIR)/psem/thread_incr_psem.c - -# pshm -MAINSRC += $(TLPIDIR)/pshm/pshm_create.c \ - $(TLPIDIR)/pshm/pshm_read.c \ - $(TLPIDIR)/pshm/pshm_unlink.c \ - $(TLPIDIR)/pshm/pshm_write.c -# pty -#MAINSRC += $(TLPIDIR)/pty/script.c \ -# $(TLPIDIR)/pty/unbuffer.c -# shlibs -#MAINSRC += $(TLPIDIR)/seccomp/dump_seccomp_filter.c \ -# $(TLPIDIR)/seccomp/libseccomp_demo.c \ -# $(TLPIDIR)/seccomp/seccomp_arg64.c \ -# $(TLPIDIR)/seccomp/seccomp_bench.c \ -# $(TLPIDIR)/seccomp/seccomp_control_open.c \ -# $(TLPIDIR)/seccomp/seccomp_deny_open.c \ -# $(TLPIDIR)/seccomp/seccomp_deny_syscall.c \ -# $(TLPIDIR)/seccomp/seccomp_launch.c \ -# $(TLPIDIR)/seccomp/seccomp_logging.c \ -# $(TLPIDIR)/seccomp/seccomp_multiarch.c \ -# $(TLPIDIR)/seccomp/seccomp_perf.c \ -# $(TLPIDIR)/seccomp/seccomp_trap_sigsys.c \ -# $(TLPIDIR)/seccomp/seccomp_unotify_mkdir.c \ -# $(TLPIDIR)/seccomp/seccomp_unotify_openat.c -ifneq ($(CONFIG_LIBC_DLFCN),) -# shlibs -MAINSRC += $(TLPIDIR)/shlibs/dynload.c -endif -# signals -#MAINSRC += $(TLPIDIR)/signals/catch_rtsigs.c -MAINSRC += $(TLPIDIR)/signals/demo_SIGFPE.c \ - $(TLPIDIR)/signals/ignore_pending_sig.c \ - $(TLPIDIR)/signals/intquit.c -# $(TLPIDIR)/signals/nonreentrant.c -MAINSRC += $(TLPIDIR)/signals/ouch.c \ - $(TLPIDIR)/signals/sig_receiver.c \ - $(TLPIDIR)/signals/sig_sender.c \ - $(TLPIDIR)/signals/sig_speed_sigsuspend.c \ - $(TLPIDIR)/signals/sigmask_longjmp.c \ - $(TLPIDIR)/signals/signalfd_sigval.c \ - $(TLPIDIR)/signals/t_kill.c -# $(TLPIDIR)/signals/t_sigaltstack.c -MAINSRC += $(TLPIDIR)/signals/t_sigqueue.c \ - $(TLPIDIR)/signals/t_sigsuspend.c -# $(TLPIDIR)/signals/t_sigwaitinfo.c -# sockets -MAINSRC += $(TLPIDIR)/sockets/id_echo_cl.c -# $(TLPIDIR)/sockets/id_echo_sv.c -MAINSRC += $(TLPIDIR)/sockets/is_echo_cl.c \ - $(TLPIDIR)/sockets/is_echo_inetd_sv.c -# $(TLPIDIR)/sockets/is_echo_sv.c \ -# $(TLPIDIR)/sockets/is_echo_v2_sv.c -MAINSRC += $(TLPIDIR)/sockets/is_seqnum_cl.c \ - $(TLPIDIR)/sockets/is_seqnum_sv.c \ - $(TLPIDIR)/sockets/is_seqnum_v2_cl.c \ - $(TLPIDIR)/sockets/is_seqnum_v2_sv.c \ - $(TLPIDIR)/sockets/i6d_ucase_cl.c \ - $(TLPIDIR)/sockets/i6d_ucase_sv.c \ - $(TLPIDIR)/sockets/list_host_addresses.c -# $(TLPIDIR)/sockets/scm_cred_recv.c -MAINSRC += $(TLPIDIR)/sockets/scm_cred_send.c -# $(TLPIDIR)/sockets/scm_multi_recv.c -MAINSRC += $(TLPIDIR)/sockets/scm_multi_send.c \ - $(TLPIDIR)/sockets/scm_rights_recv.c \ - $(TLPIDIR)/sockets/scm_rights_send.c \ - $(TLPIDIR)/sockets/socknames.c -# $(TLPIDIR)/sockets/t_gethostbyname.c -MAINSRC += $(TLPIDIR)/sockets/t_getservbyname.c \ - $(TLPIDIR)/sockets/ud_ucase_cl.c \ - $(TLPIDIR)/sockets/ud_ucase_sv.c \ - $(TLPIDIR)/sockets/us_abstract_bind.c \ - $(TLPIDIR)/sockets/us_xfr_cl.c \ - $(TLPIDIR)/sockets/us_xfr_sv.c \ - $(TLPIDIR)/sockets/us_xfr_v2_cl.c \ - $(TLPIDIR)/sockets/us_xfr_v2_sv.c -# sysinfo -MAINSRC += $(TLPIDIR)/sysinfo/procfs_pidmax.c \ - $(TLPIDIR)/sysinfo/procfs_user_exe.c \ - $(TLPIDIR)/sysinfo/t_uname.c -# svipc -MAINSRC += $(TLPIDIR)/svipc/svmsg_demo_server.c \ - $(TLPIDIR)/svipc/t_ftok.c -# svmsg -MAINSRC += $(TLPIDIR)/svmsg/svmsg_chqbytes.c \ - $(TLPIDIR)/svmsg/svmsg_create.c \ - $(TLPIDIR)/svmsg/svmsg_file_client.c \ - $(TLPIDIR)/svmsg/svmsg_file_server.c -# $(TLPIDIR)/svmsg/svmsg_info.c \ -# $(TLPIDIR)/svmsg/svmsg_ls.c -MAINSRC += $(TLPIDIR)/svmsg/svmsg_receive.c \ - $(TLPIDIR)/svmsg/svmsg_rm.c \ - $(TLPIDIR)/svmsg/svmsg_send.c -# svsem -#MAINSRC += $(TLPIDIR)/svsem/svsem_bad_init.c \ -# $(TLPIDIR)/svsem/svsem_create.c \ -# $(TLPIDIR)/svsem/svsem_demo.c \ -# $(TLPIDIR)/svsem/svsem_good_init.c \ -# $(TLPIDIR)/svsem/svsem_info.c \ -# $(TLPIDIR)/svsem/svsem_mon.c \ -# $(TLPIDIR)/svsem/svsem_op.c \ -# $(TLPIDIR)/svsem/svsem_rm.c \ -# $(TLPIDIR)/svsem/svsem_setall.c -# svshm -ifneq ($(CONFIG_MM_SHM),) -MAINSRC += $(TLPIDIR)/svshm/svshm_attach.c \ - $(TLPIDIR)/svshm/svshm_create.c -# $(TLPIDIR)/svshm/svshm_info.c \ -# $(TLPIDIR)/svshm/svshm_lock.c -MAINSRC += $(TLPIDIR)/svshm/svshm_mon.c \ - $(TLPIDIR)/svshm/svshm_rm.c -# $(TLPIDIR)/svshm/svshm_unlock.c \ -# $(TLPIDIR)/svshm/svshm_xfr_reader.c \ -# $(TLPIDIR)/svshm/svshm_xfr_writer.c -# syslim -MAINSRC += $(TLPIDIR)/syslim/t_fpathconf.c -# $(TLPIDIR)/syslim/t_sysconf.c -endif -# threads -ifneq ($(CONFIG_PTHREAD_SPINLOCKS),) -MAINSRC += $(TLPIDIR)/threads/detached_attrib.c \ - $(TLPIDIR)/threads/one_time_init.c \ - $(TLPIDIR)/threads/prod_condvar.c \ - $(TLPIDIR)/threads/prod_no_condvar.c \ - $(TLPIDIR)/threads/pthread_barrier_demo.c \ - $(TLPIDIR)/threads/simple_thread.c \ - $(TLPIDIR)/threads/strerror_test.c \ - $(TLPIDIR)/threads/thread_cancel.c \ - $(TLPIDIR)/threads/thread_cleanup.c \ - $(TLPIDIR)/threads/thread_incr.c \ - $(TLPIDIR)/threads/thread_incr_mutex.c \ - $(TLPIDIR)/threads/thread_incr_rwlock.c \ - $(TLPIDIR)/threads/thread_incr_spinlock.c \ - $(TLPIDIR)/threads/thread_lock_speed.c \ - $(TLPIDIR)/threads/thread_multijoin.c -endif -# time -MAINSRC += $(TLPIDIR)/time/calendar_time.c \ - $(TLPIDIR)/time/process_time.c \ - $(TLPIDIR)/time/show_time.c \ - $(TLPIDIR)/time/strtime.c -# timers -MAINSRC += $(TLPIDIR)/timers/cpu_burner.c \ - $(TLPIDIR)/timers/cpu_multi_burner.c -# $(TLPIDIR)/timers/cpu_multithread_burner.c -MAINSRC += $(TLPIDIR)/timers/demo_timerfd.c \ - $(TLPIDIR)/timers/ptmr_null_evp.c \ - $(TLPIDIR)/timers/ptmr_sigev_signal.c \ - $(TLPIDIR)/timers/ptmr_sigev_thread.c \ - $(TLPIDIR)/timers/real_timer.c \ - $(TLPIDIR)/timers/timed_read.c \ - $(TLPIDIR)/timers/t_clock_nanosleep.c \ - $(TLPIDIR)/timers/t_nanosleep.c -# tty -MAINSRC += $(TLPIDIR)/tty/demo_SIGWINCH.c \ - $(TLPIDIR)/tty/new_intr.c \ - $(TLPIDIR)/tty/no_echo.c \ - $(TLPIDIR)/tty/test_tty_functions.c -# users_groups -ifneq ($(CONFIG_CRYPTO),) -MAINSRC += $(TLPIDIR)/users_groups/check_password.c -endif -MAINSRC += $(TLPIDIR)/users_groups/t_getpwent.c \ - $(TLPIDIR)/users_groups/t_getpwnam_r.c -# vdso -MAINSRC += $(TLPIDIR)/vdso/gettimeofday.c -# vmem -MAINSRC += $(TLPIDIR)/vmem/madvise_dontneed.c -# $(TLPIDIR)/vmem/memlock.c -MAINSRC += $(TLPIDIR)/vmem/t_mprotect.c -# xattr -#MAINSRC += $(TLPIDIR)/xattr/t_setxattr.c \ -# $(TLPIDIR)/xattr/xattr_view.c - -PROGNAME := $(notdir $(patsubst %.c,%, $(MAINSRC))) - -$(TLPI_UNPACK).zip: - $(call DOWNLOAD,$(TLPI_DOWNLOAD_URL),master.zip,tlpi.zip) - $(Q) unzip -o tlpi.zip - $(Q) rm -f tlpi.zip - $(Q) mv tlpi-dist-master $(TLPI_UNPACK) - $(Q) patch -d $(TLPI_UNPACK) -p1 < 0001-add-ename.c.inc.patch - $(Q) patch -d $(TLPI_UNPACK) -p1 < 0002-fix-setenv-compilation-error.patch - $(Q) patch -d $(TLPI_UNPACK) -p1 < 0003-fix-memoryleak-in-check_password.patch - $(Q) patch -d $(TLPI_UNPACK) -p1 < 0004-fix-compilation-error.patch - -$(TLPI_UNPACK): $(TLPI_UNPACK).zip - -# Download and unpack tarball if no git repo found -ifeq ($(wildcard $(TLPI_UNPACK)/.git),) -context:: $(TLPI_UNPACK) - -distclean:: - $(Q) rm -rf $(TLPI_UNPACK) -endif - -include $(APPDIR)/Application.mk diff --git a/examples/tmp112/CMakeLists.txt b/examples/tmp112/CMakeLists.txt deleted file mode 100644 index 7f75995bb..000000000 --- a/examples/tmp112/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# ############################################################################## -# apps/examples/tmp112/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_TMP112) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_TMP112_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_TMP112_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_TMP112_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_TMP112} - SRCS - tmp112_main.c) -endif() diff --git a/examples/tmp112/Kconfig b/examples/tmp112/Kconfig deleted file mode 100644 index a033ab2a5..000000000 --- a/examples/tmp112/Kconfig +++ /dev/null @@ -1,36 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config EXAMPLES_TMP112 - tristate "TMP112 temperature sensor example" - default n - depends on SENSORS_TMP112 - ---help--- - Enable the TMP112 example - -if EXAMPLES_TMP112 - -config EXAMPLES_TMP112_PROGNAME - string "Program name" - default "tmp112" - ---help--- - This is the name of the program that will be used when the NSH ELF - program is installed. - -config EXAMPLES_TMP112_PRIORITY - int "TMP112 task priority" - default 100 - -config EXAMPLES_TMP112_STACKSIZE - int "TMP112 stack size" - default DEFAULT_TASK_STACKSIZE - -config EXAMPLES_TMP112_DEVPATH - string "TMP112 device path" - default "/dev/temp0" - ---help--- - The default path to the TMP112 temperature sensor device - -endif diff --git a/examples/tmp112/Make.defs b/examples/tmp112/Make.defs deleted file mode 100644 index 097f31268..000000000 --- a/examples/tmp112/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/examples/tmp112/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_EXAMPLES_TMP112),) -CONFIGURED_APPS += $(APPDIR)/examples/tmp112 -endif diff --git a/examples/tmp112/Makefile b/examples/tmp112/Makefile deleted file mode 100644 index 745220032..000000000 --- a/examples/tmp112/Makefile +++ /dev/null @@ -1,36 +0,0 @@ -############################################################################ -# apps/examples/tmp112/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -# TMP112 temperature sensor example built-in application info - -PROGNAME = $(CONFIG_EXAMPLES_TMP112_PROGNAME) -PRIORITY = $(CONFIG_EXAMPLES_TMP112_PRIORITY) -STACKSIZE = $(CONFIG_EXAMPLES_TMP112_STACKSIZE) -MODULE = $(CONFIG_EXAMPLES_TMP112) - -# TMP112 temperature sensor example - -MAINSRC = tmp112_main.c - -include $(APPDIR)/Application.mk diff --git a/examples/tmp112/tmp112_main.c b/examples/tmp112/tmp112_main.c deleted file mode 100644 index 0fbf6f0f9..000000000 --- a/examples/tmp112/tmp112_main.c +++ /dev/null @@ -1,69 +0,0 @@ -/**************************************************************************** - * apps/examples/tmp112/tmp112_main.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> -#include <stdio.h> -#include <fcntl.h> -#include <unistd.h> - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: tmp112_main - ****************************************************************************/ - -int main(int argc, FAR char *argv[]) -{ - int fd; - int ret; - float sample; - - fd = open(CONFIG_EXAMPLES_TMP112_DEVPATH, O_RDONLY); - if (fd < 0) - { - printf("Failed to open TMP112 sensor at %s: %s (%d)\n", - CONFIG_EXAMPLES_TMP112_DEVPATH, strerror(errno), errno); - return EXIT_FAILURE; - } - - ret = read(fd, &sample, sizeof(float)); - if (ret != sizeof(sample)) - { - perror("Could not read"); - ret = EXIT_FAILURE; - } - else - { - printf("TMP112 = %.03f degrees Celsius\n", sample); - ret = EXIT_SUCCESS; - } - - close(fd); - - return ret; -} diff --git a/examples/touchscreen/CMakeLists.txt b/examples/touchscreen/CMakeLists.txt deleted file mode 100644 index f9630d8f4..000000000 --- a/examples/touchscreen/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# ############################################################################## -# apps/examples/touchscreen/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_TOUCHSCREEN) - nuttx_add_application( - NAME - tc - STACKSIZE - ${CONFIG_DEFAULT_TASK_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_TOUCHSCREEN} - SRCS - tc_main.c) -endif() diff --git a/examples/touchscreen/Make.defs b/examples/touchscreen/Make.defs index 10c766089..37d5c93f5 100644 --- a/examples/touchscreen/Make.defs +++ b/examples/touchscreen/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/touchscreen/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/touchscreen/Makefile b/examples/touchscreen/Makefile index 9102bc50f..217cb5f0c 100644 --- a/examples/touchscreen/Makefile +++ b/examples/touchscreen/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/touchscreen/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/touchscreen/tc.h b/examples/touchscreen/tc.h index 207417833..d525eee5f 100644 --- a/examples/touchscreen/tc.h +++ b/examples/touchscreen/tc.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/touchscreen/tc.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/touchscreen/tc_main.c b/examples/touchscreen/tc_main.c index b2f40a8f7..6b792a6ff 100644 --- a/examples/touchscreen/tc_main.c +++ b/examples/touchscreen/tc_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/touchscreen/tc_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -33,7 +31,7 @@ #include <unistd.h> #include <fcntl.h> #include <errno.h> -#include <nuttx/debug.h> +#include <debug.h> #ifdef CONFIG_EXAMPLES_TOUCHSCREEN_MOUSE # include <nuttx/input/mouse.h> @@ -128,7 +126,7 @@ int main(int argc, FAR char *argv[]) iinfo("Reading...\n"); nbytes = read(fd, &sample, sizeof(struct mouse_report_s)); - iinfo("Bytes read: %zd\n", nbytes); + iinfo("Bytes read: %d\n", nbytes); /* Handle unexpected return values */ @@ -147,7 +145,7 @@ int main(int argc, FAR char *argv[]) } else if (nbytes != sizeof(struct mouse_report_s)) { - printf("tc_main: Unexpected read size=%zd,expected=%zd,Ignoring\n", + printf("tc_main: Unexpected read size=%d, expected=%d, Ignoring\n", nbytes, sizeof(struct mouse_report_s)); } diff --git a/examples/txmorse/CMakeLists.txt b/examples/txmorse/CMakeLists.txt deleted file mode 100644 index 469455762..000000000 --- a/examples/txmorse/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# ############################################################################## -# apps/examples/txmorse/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_TXMORSE) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_TXMORSE_PROGNAME} - SRCS - txmorse_main.c - STACKSIZE - ${CONFIG_EXAMPLES_TXMORSE_STACKSIZE} - PRIORITY - ${CONFIG_EXAMPLES_TXMORSE_PRIORITY}) -endif() diff --git a/examples/txmorse/Kconfig b/examples/txmorse/Kconfig deleted file mode 100644 index 3754a9ffe..000000000 --- a/examples/txmorse/Kconfig +++ /dev/null @@ -1,30 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config EXAMPLES_TXMORSE - tristate "txmorse (Morse code transmitter)" - default n - depends on AUDIOUTILS_MORSEY - ---help--- - Enable the Morse code transmission example. - -if EXAMPLES_TXMORSE - -config EXAMPLES_TXMORSE_PROGNAME - string "Program name" - default "txmorse" - ---help--- - This is the name of the program that will be used when the NSH ELF - program is installed. - -config EXAMPLES_TXMORSE_PRIORITY - int "txmorse task priority" - default 100 - -config EXAMPLES_TXMORSE_STACKSIZE - int "txmorse stack size" - default DEFAULT_TASK_STACKSIZE - -endif diff --git a/examples/txmorse/Make.defs b/examples/txmorse/Make.defs deleted file mode 100644 index 0c52d4fb8..000000000 --- a/examples/txmorse/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/examples/txmorse/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_EXAMPLES_TXMORSE),) -CONFIGURED_APPS += $(APPDIR)/examples/txmorse -endif diff --git a/examples/txmorse/Makefile b/examples/txmorse/Makefile deleted file mode 100644 index 8d9bcefff..000000000 --- a/examples/txmorse/Makefile +++ /dev/null @@ -1,34 +0,0 @@ -############################################################################ -# apps/examples/txmorse/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -# Application info - -PROGNAME = $(CONFIG_EXAMPLES_TXMORSE_PROGNAME) -PRIORITY = $(CONFIG_EXAMPLES_TXMORSE_PRIORITY) -STACKSIZE = $(CONFIG_EXAMPLES_TXMORSE_STACKSIZE) -MODULE = $(CONFIG_EXAMPLES_TXMORSE) - -MAINSRC = txmorse_main.c - -include $(APPDIR)/Application.mk diff --git a/examples/txmorse/txmorse_main.c b/examples/txmorse/txmorse_main.c deleted file mode 100644 index cc2a3f957..000000000 --- a/examples/txmorse/txmorse_main.c +++ /dev/null @@ -1,294 +0,0 @@ -/**************************************************************************** - * apps/examples/txmorse/txmorse_main.c - * - * SPDX-License-Identifer: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <fcntl.h> -#include <getopt.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <sys/ioctl.h> -#include <unistd.h> - -#ifdef CONFIG_DEV_GPIO -#include <nuttx/ioexpander/gpio.h> -#endif - -#include <audioutils/morsey.h> - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* Default millisecond duration of dot (2.5WPM) */ - -#define DEFAULT_DURATION (240) - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: transmit_console - * - * Description: - * Transmit Morse code as printed characters to the console. - ****************************************************************************/ - -static void transmit_console(int on, unsigned duration_ms, void *arg) -{ - unsigned ms_per_unit = *((unsigned *)arg); - - if (on) - { - /* We are printing a dot or a dash */ - - if (duration_ms == ms_per_unit * MORSEY_UNITS_DOT) - { - putchar('.'); - } - else if (duration_ms == ms_per_unit * MORSEY_UNITS_DASH) - { - putchar('-'); - } - } - else - { - /* We are indicating separation */ - - if (duration_ms == ms_per_unit * MORSEY_UNITS_INTERELEM) - { - return; /* Inter-element gap, do nothing */ - } - else if (duration_ms == ms_per_unit * MORSEY_UNITS_INTERLET) - { - putchar(' '); /* Inter-letter gap, print a space */ - } - else if (duration_ms == ms_per_unit * MORSEY_UNITS_INTERWORD) - { - putchar('/'); /* Inter-word gap, print / delimiter */ - } - } -} - -/**************************************************************************** - * Name: cleanup_console - * - * Description: - * Default cleanup function; does nothing. - * - * Input Parameters: - * arg - User argument. - * - ****************************************************************************/ - -static void cleanup_console(void *arg) -{ - UNUSED(arg); - putchar('\n'); /* Newline character after message is done */ -} - -#ifdef CONFIG_DEV_GPIO - -/**************************************************************************** - * Name: transmit_gpio - * - * Description: - * Transmit Morse over a GPIO pin. - * - * Input Parameters: - * arg - Pointer to file descriptor of GPIO device - * - ****************************************************************************/ - -static void transmit_gpio(int on, unsigned duration_ms, void *arg) -{ - int err; - int fd = *((int *)arg); - - if (on) - { - err = ioctl(fd, GPIOC_WRITE, 1); - if (err < 0) - { - fprintf(stderr, "Failed to turn on GPIO: %d\n", errno); - return; - } - } - - usleep(duration_ms * 1000); - - err = ioctl(fd, GPIOC_WRITE, 0); - if (err < 0) - { - fprintf(stderr, "Failed to turn off GPIO: %d\n", errno); - } -} - -/**************************************************************************** - * Name: cleanup_gpio - * - * Description: - * Clean up a GPIO Morse sink. - * - * Input Parameters: - * arg - User argument (pointer to file descriptor) - * - ****************************************************************************/ - -static void cleanup_gpio(void *arg) -{ - int fd = *((int *)arg); - close(fd); -} - -#endif /* CONFIG_DEV_GPIO */ - -/**************************************************************************** - * Name: print_usage - * - * Description: - * Prints out the usage information for the program. - * - * Input Parameters: - * sink - The stream to output the usage information - * - ****************************************************************************/ - -static void print_usage(FILE *sink) -{ - fprintf(sink, "USAGE: " CONFIG_EXAMPLES_TXMORSE_PROGNAME - " [-d dot_duration_ms] \"my text\" [path/to/device]\n"); - fprintf(sink, - "Ex: " CONFIG_EXAMPLES_TXMORSE_PROGNAME " \"sos\" /dev/gpio1\n"); - fprintf(sink, "Default dot duration is 240 ms\n"); - fprintf(sink, "Default device is output to console\n"); -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -int main(int argc, char **argv) -{ - int err; - int c; - int fd; - struct morsey_state_s state; - - transmit_f txfunc = transmit_console; /* Default transmit */ - void (*cleanupfunc)(void *) = cleanup_console; /* Default cleanup */ - void *arg = NULL; - - unsigned duration = DEFAULT_DURATION; - char *devpath = NULL; - char *message = NULL; - - arg = &duration; /* Default argument */ - - /* Parse command line arguments */ - - while ((c = getopt(argc, argv, ":hd:")) != -1) - { - switch (c) - { - case 'h': - print_usage(stdout); - return EXIT_SUCCESS; - case 'd': - duration = strtoul(optarg, NULL, 10); - break; - case '?': - fprintf(stderr, "Unknown option -%c\n", optopt); - print_usage(stderr); - return EXIT_FAILURE; - } - } - - /* Get text to encode */ - - if (argc <= optind) - { - fprintf(stderr, "Missing text to encode!\n"); - return EXIT_FAILURE; - } - - message = argv[optind++]; - - /* Check for optional device path */ - - if (argc > optind) - { - devpath = argv[optind++]; - } - - /* Choose transmit function based on device path */ - - if (devpath == NULL) - { - txfunc = transmit_console; - cleanupfunc = cleanup_console; - arg = &duration; - } -#ifdef CONFIG_DEV_GPIO - else if (strstr(devpath, "gpio")) - { - txfunc = transmit_gpio; - cleanupfunc = cleanup_gpio; - fd = open(devpath, O_WRONLY); - if (fd < 0) - { - fprintf(stderr, "Couldn't open '%s': %d\n", devpath, errno); - return EXIT_FAILURE; - } - - arg = &fd; - } -#endif - else - { - fprintf(stderr, "Unrecognized device '%s', defaulting to console.\n", - devpath); - } - - /* Set up library to play */ - - morsey_init(&state, duration, 0); - - /* Transmit the text as Morse code */ - - err = morsey_transmit(message, strlen(message), &state, txfunc, arg); - if (err == 0) - { - cleanupfunc(arg); - return 0; - } - - fprintf(stderr, "Error transmitting: %d\n", err); - cleanupfunc(arg); - return err; -} diff --git a/examples/udgram/CMakeLists.txt b/examples/udgram/CMakeLists.txt deleted file mode 100644 index 2cd497dcb..000000000 --- a/examples/udgram/CMakeLists.txt +++ /dev/null @@ -1,47 +0,0 @@ -# ############################################################################## -# apps/examples/udgram/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_UDGRAM) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_UDGRAM_CLIENT_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_UDGRAM_CLIENT_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_UDGRAM_CLIENT_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_UDGRAM} - SRCS - udgram_client.c) - - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_UDGRAM_SERVER_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_UDGRAM_SERVER_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_UDGRAM_SERVER_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_UDGRAM} - SRCS - udgram_server.c) -endif() diff --git a/examples/udgram/Make.defs b/examples/udgram/Make.defs index 7db4f8262..a2389ebfe 100644 --- a/examples/udgram/Make.defs +++ b/examples/udgram/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/udgram/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/udgram/Makefile b/examples/udgram/Makefile index 57b32ba36..160dbe025 100644 --- a/examples/udgram/Makefile +++ b/examples/udgram/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/udgram/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/udgram/udgram.h b/examples/udgram/udgram.h index 273dd4a99..84c5adf04 100644 --- a/examples/udgram/udgram.h +++ b/examples/udgram/udgram.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/udgram/udgram.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/udgram/udgram_client.c b/examples/udgram/udgram_client.c index c0fd63a4f..dc7577e15 100644 --- a/examples/udgram/udgram_client.c +++ b/examples/udgram/udgram_client.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/udgram/udgram_client.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -54,7 +52,6 @@ static inline void fill_buffer(unsigned char *buf, int offset) { j = 1; } - buf[j] = ch; } } @@ -91,16 +88,17 @@ int main(int argc, FAR char *argv[]) /* Set up the server address */ - addrlen = sizeof(CONFIG_EXAMPLES_UDGRAM_ADDR); - if (addrlen > UNIX_PATH_MAX) + addrlen = strlen(CONFIG_EXAMPLES_UDGRAM_ADDR); + if (addrlen > UNIX_PATH_MAX - 1) { - addrlen = UNIX_PATH_MAX; + addrlen = UNIX_PATH_MAX - 1; } server.sun_family = AF_LOCAL; - strlcpy(server.sun_path, CONFIG_EXAMPLES_UDGRAM_ADDR, addrlen); + strncpy(server.sun_path, CONFIG_EXAMPLES_UDGRAM_ADDR, addrlen); + server.sun_path[addrlen] = '\0'; - addrlen += sizeof(sa_family_t); + addrlen += sizeof(sa_family_t) + 1; /* Send the message */ diff --git a/examples/udgram/udgram_server.c b/examples/udgram/udgram_server.c index cd1cc928c..37866007e 100644 --- a/examples/udgram/udgram_server.c +++ b/examples/udgram/udgram_server.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/udgram/udgram_server.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -55,11 +53,9 @@ static inline int check_buffer(unsigned char *buf) { j = 1; } - if (buf[j] != ch) { - printf("server: Buffer content error for offset=%d, index=%d\n", - offset, j); + printf("server: Buffer content error for offset=%d, index=%d\n", offset, j); ret = 0; } } @@ -93,18 +89,19 @@ int main(int argc, FAR char *argv[]) /* Bind the socket to a local address */ - addrlen = sizeof(CONFIG_EXAMPLES_UDGRAM_ADDR); - if (addrlen > UNIX_PATH_MAX) + addrlen = strlen(CONFIG_EXAMPLES_UDGRAM_ADDR); + if (addrlen > UNIX_PATH_MAX - 1) { - addrlen = UNIX_PATH_MAX; + addrlen = UNIX_PATH_MAX - 1; } server.sun_family = AF_LOCAL; - strlcpy(server.sun_path, CONFIG_EXAMPLES_UDGRAM_ADDR, addrlen); + strncpy(server.sun_path, CONFIG_EXAMPLES_UDGRAM_ADDR, addrlen); + server.sun_path[addrlen] = '\0'; - addrlen += sizeof(sa_family_t); + addrlen += sizeof(sa_family_t) + 1; - if (bind(sockfd, (struct sockaddr *)&server, addrlen) < 0) + if (bind(sockfd, (struct sockaddr*)&server, addrlen) < 0) { printf("server: ERROR bind failure: %d\n", errno); return 1; @@ -117,7 +114,7 @@ int main(int argc, FAR char *argv[]) printf("server: %d. Receiving up 1024 bytes\n", offset); recvlen = addrlen; nbytes = recvfrom(sockfd, inbuf, 1024, 0, - (struct sockaddr *)&client, &recvlen); + (struct sockaddr*)&client, &recvlen); if (nbytes < 0) { @@ -126,11 +123,10 @@ int main(int argc, FAR char *argv[]) return 1; } - if (recvlen < sizeof(sa_family_t) || - recvlen > sizeof(struct sockaddr_un)) + if (recvlen < sizeof(sa_family_t) || recvlen > sizeof(struct sockaddr_un)) { - printf("server: %d. ERROR Received %d bytes from client with " - "invalid length %d\n", offset, nbytes, recvlen); + printf("server: %d. ERROR Received %d bytes from client with invalid length %d\n", + offset, nbytes, recvlen); } else if (recvlen == sizeof(sa_family_t)) { @@ -147,8 +143,8 @@ int main(int argc, FAR char *argv[]) printf("server: ERROR path not NUL terminated\n"); } } - else /* if (recvlen > sizeof(sa_family_t) + 1 && - * recvlen <= sizeof(struct sockaddr_un)) */ + else /* if (recvlen > sizeof(sa_family_t)+1 && + recvlen <= sizeof(struct sockaddr_un)) */ { int pathlen = recvlen - sizeof(sa_family_t) - 1; diff --git a/examples/udp/CMakeLists.txt b/examples/udp/CMakeLists.txt deleted file mode 100644 index b3cbdf166..000000000 --- a/examples/udp/CMakeLists.txt +++ /dev/null @@ -1,80 +0,0 @@ -# ############################################################################## -# apps/examples/udp/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_UDP) - - # Basic UDP networking test - - set(CSRCS udp_cmdline.c) - - if(CONFIG_EXAMPLES_UDP_NETINIT) - list(APPEND CSRCS udp_netinit.c) - endif() - - # Target 1 Files - - if(CONFIG_EXAMPLES_UDP_SERVER1) - list(APPEND CSRCS udp_server.c) - else() - list(APPEND CSRCS udp_client.c) - endif() - - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_UDP_PROGNAME1} - PRIORITY - ${CONFIG_EXAMPLES_UDP_PRIORITY1} - STACKSIZE - ${CONFIG_EXAMPLES_UDP_STACKSIZE1} - MODULE - ${CONFIG_EXAMPLES_UDP} - INCLUDE_DIRECTORIES - ${CMAKE_BINARY_DIR}/include/nuttx - SRCS - udp_target1.c - ${CSRCS}) - - # Target 2 Files - - if(CONFIG_EXAMPLES_UDP_TARGET2) - if(CONFIG_EXAMPLES_UDP_SERVER1) - list(APPEND CSRCS udp_client.c) - else() - list(APPEND CSRCS udp_server.c) - endif() - - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_UDP_PROGNAME2} - PRIORITY - ${CONFIG_EXAMPLES_UDP_PRIORITY2} - STACKSIZE - ${CONFIG_EXAMPLES_UDP_STACKSIZE2} - MODULE - ${CONFIG_EXAMPLES_UDP} - INCLUDE_DIRECTORIES - ${CMAKE_BINARY_DIR}/include/nuttx - SRCS - udp_target2.c - ${CSRCS}) - endif() -endif() diff --git a/examples/udp/Kconfig b/examples/udp/Kconfig index 4b460bdf2..4914f655c 100644 --- a/examples/udp/Kconfig +++ b/examples/udp/Kconfig @@ -70,7 +70,8 @@ config EXAMPLES_UDP_DEVNAME config EXAMPLES_UDP_NETINIT bool "Initialize network" - default !NSH_NETINIT + default n if NSH_NETINIT + default y if !NSH_NETINIT ---help--- Selecting this option will enable logic in the example to perform some basic initialization of the network. You would probably only diff --git a/examples/udp/Make.defs b/examples/udp/Make.defs index c8db5a639..efdd724f1 100644 --- a/examples/udp/Make.defs +++ b/examples/udp/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/udp/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/udp/Makefile b/examples/udp/Makefile index cb3f95933..a0cc07608 100644 --- a/examples/udp/Makefile +++ b/examples/udp/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/udp/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/udp/udp.h b/examples/udp/udp.h index 2f15d8ea3..35f0f8220 100644 --- a/examples/udp/udp.h +++ b/examples/udp/udp.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/udp/udp.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -29,7 +27,7 @@ #ifdef EXAMPLES_UDP_HOST #else -# include <nuttx/debug.h> +# include <debug.h> #endif #include <arpa/inet.h> diff --git a/examples/udp/udp_client.c b/examples/udp/udp_client.c index f3d3f19dc..220637b1c 100644 --- a/examples/udp/udp_client.c +++ b/examples/udp/udp_client.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/udp/udp_client.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/udp/udp_cmdline.c b/examples/udp/udp_cmdline.c index cefff3586..64cb71425 100644 --- a/examples/udp/udp_cmdline.c +++ b/examples/udp/udp_cmdline.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/udp/udp_cmdline.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/udp/udp_host.c b/examples/udp/udp_host.c index 5f4aac5f3..f0bf0a99b 100644 --- a/examples/udp/udp_host.c +++ b/examples/udp/udp_host.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/udp/udp_host.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/udp/udp_netinit.c b/examples/udp/udp_netinit.c index d5851b22a..e937b0c2e 100644 --- a/examples/udp/udp_netinit.c +++ b/examples/udp/udp_netinit.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/udp/udp_netinit.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -28,7 +26,7 @@ #include <stdbool.h> #include <stdio.h> -#include <nuttx/debug.h> +#include <debug.h> #include <arpa/inet.h> #include <netinet/in.h> diff --git a/examples/udp/udp_server.c b/examples/udp/udp_server.c index 6e642e654..abde7ad02 100644 --- a/examples/udp/udp_server.c +++ b/examples/udp/udp_server.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/udp/udp_server.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -81,7 +79,7 @@ void udp_server(void) #else struct sockaddr_in server; struct sockaddr_in client; - char ip_str[INET_ADDRSTRLEN]; + in_addr_t tmpaddr; #endif unsigned char inbuf[1024]; socklen_t addrlen; @@ -106,7 +104,7 @@ void udp_server(void) /* Set socket to reuse address */ optval = 1; - if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &optval, + if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, (void *)&optval, sizeof(int)) < 0) { printf("server: setsockopt SO_REUSEADDR failure: %d\n", errno); @@ -169,10 +167,11 @@ void udp_server(void) client.sin6_addr.s6_addr[14], client.sin6_addr.s6_addr[15], ntohs(client.sin6_port)); #else - printf("server: %d. Received %d bytes from %s:%u\n", + tmpaddr = ntohl(client.sin_addr.s_addr); + printf("server: %d. Received %d bytes from %d.%d.%d.%d:%d\n", offset, nbytes, - inet_ntop(AF_INET, &client.sin_addr.s_addr, - ip_str, sizeof(ip_str)), + tmpaddr >> 24, (tmpaddr >> 16) & 0xff, + (tmpaddr >> 8) & 0xff, tmpaddr & 0xff, ntohs(client.sin_port)); #endif if (nbytes < 0) diff --git a/examples/udp/udp_target1.c b/examples/udp/udp_target1.c index 656213a29..3db14c05f 100644 --- a/examples/udp/udp_target1.c +++ b/examples/udp/udp_target1.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/udp/udp_target1.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/udp/udp_target2.c b/examples/udp/udp_target2.c index d0abce67e..03104ff92 100644 --- a/examples/udp/udp_target2.c +++ b/examples/udp/udp_target2.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/udp/udp_target2.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/udpblaster/CMakeLists.txt b/examples/udpblaster/CMakeLists.txt deleted file mode 100644 index 7a7f612a3..000000000 --- a/examples/udpblaster/CMakeLists.txt +++ /dev/null @@ -1,42 +0,0 @@ -# ############################################################################## -# apps/examples/udpblaster/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_UDPBLASTER) - - if(NOT CONFIG_EXAMPLES_TCPBLASTER_LOOPBACK) - include(udpblaster_host.cmake) - endif() - - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_UDPBLASTER_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_UDPBLASTER_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_UDPBLASTER_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_UDPBLASTER} - SRCS - udpblaster_target.c - udpblaster_text.c) - -endif() diff --git a/examples/udpblaster/Kconfig b/examples/udpblaster/Kconfig index 8dde2d619..606de1d5b 100644 --- a/examples/udpblaster/Kconfig +++ b/examples/udpblaster/Kconfig @@ -57,7 +57,8 @@ endchoice # IP Domain config EXAMPLES_UDPBLASTER_INIT bool "Initialize network" - default !NSH_NETINIT + default n if NSH_NETINIT + default y if !NSH_NETINIT depends on !EXAMPLES_UDPBLASTER_LOOPBACK ---help--- Include logic to initialize the network. This should not be done if diff --git a/examples/udpblaster/Make.defs b/examples/udpblaster/Make.defs index 406801530..3e8faec8a 100644 --- a/examples/udpblaster/Make.defs +++ b/examples/udpblaster/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/udpblaster/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/udpblaster/Makefile b/examples/udpblaster/Makefile index 2db46b110..0d4dce30d 100644 --- a/examples/udpblaster/Makefile +++ b/examples/udpblaster/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/udpblaster/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/udpblaster/udpblaster.h b/examples/udpblaster/udpblaster.h index ff727bc58..1c4fb0f16 100644 --- a/examples/udpblaster/udpblaster.h +++ b/examples/udpblaster/udpblaster.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/udpblaster/udpblaster.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -29,8 +27,6 @@ #include "config.h" -#include <sys/param.h> - #include <arpa/inet.h> /**************************************************************************** @@ -106,6 +102,10 @@ # error "Additional link layer definitions needed" #endif +#ifndef MIN +# define MIN(a,b) ((a)<(b)?(a):(b)) +#endif + #define UDPBLASTER_SENDSIZE MIN(UDPBLASTER_MSS, g_udpblaster_strlen) /**************************************************************************** diff --git a/examples/udpblaster/udpblaster_host.c b/examples/udpblaster/udpblaster_host.c index d3609c734..a39a506f5 100644 --- a/examples/udpblaster/udpblaster_host.c +++ b/examples/udpblaster/udpblaster_host.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/udpblaster/udpblaster_host.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/udpblaster/udpblaster_host.cmake b/examples/udpblaster/udpblaster_host.cmake deleted file mode 100644 index 769c8ded9..000000000 --- a/examples/udpblaster/udpblaster_host.cmake +++ /dev/null @@ -1,41 +0,0 @@ -# ############################################################################## -# apps/examples/udpblaster/udpblaster_host.cmake -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## -# Configure project -cmake_minimum_required(VERSION 3.16) -project(udpblaster_host LANGUAGES C) - -if(NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE - "Release" - CACHE STRING "Build type" FORCE) -endif() - -message(STATUS "NuttX apps examples udpblaster host") - -include_directories(${CMAKE_BINARY_DIR}/include/nuttx) - -add_compile_definitions(UDPBLASTER_HOST=1) -add_library(udpblaster) -target_sources(udpblaster PRIVATE udpblaster_text.c) -add_executable(host udpblaster_host.c) -target_link_libraries(host PRIVATE udpblaster) -install(TARGETS host DESTINATION bin) diff --git a/examples/udpblaster/udpblaster_target.c b/examples/udpblaster/udpblaster_target.c index be5908fbd..6611c815a 100644 --- a/examples/udpblaster/udpblaster_target.c +++ b/examples/udpblaster/udpblaster_target.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/udpblaster/udpblaster_target.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -31,8 +29,7 @@ #include <string.h> #include <poll.h> #include <errno.h> -#include <nuttx/debug.h> -#include <unistd.h> +#include <debug.h> #include <net/if.h> #include <arpa/inet.h> @@ -293,7 +290,7 @@ int main(int argc, FAR char *argv[]) memset(fds, 0, 1 * sizeof(struct pollfd)); fds[0].fd = sockfd; - fds[0].events = POLLOUT; + fds[0].events = POLLOUT | POLLHUP; /* Wait until we can send data or until the connection is lost */ diff --git a/examples/udpblaster/udpblaster_text.c b/examples/udpblaster/udpblaster_text.c index 367dd5f0f..0715f86f9 100644 --- a/examples/udpblaster/udpblaster_text.c +++ b/examples/udpblaster/udpblaster_text.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/udpblaster/udpblaster_text.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/uid/CMakeLists.txt b/examples/uid/CMakeLists.txt deleted file mode 100644 index 7ec80a486..000000000 --- a/examples/uid/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# ############################################################################## -# apps/examples/uid/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_UID) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_UID_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_UID_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_UID_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_UID} - SRCS - uid_main.c) -endif() diff --git a/examples/uid/Make.defs b/examples/uid/Make.defs index aee047fcf..c4ea55340 100644 --- a/examples/uid/Make.defs +++ b/examples/uid/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/uid/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/uid/Makefile b/examples/uid/Makefile index fa1d79f96..e17848e81 100644 --- a/examples/uid/Makefile +++ b/examples/uid/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/uid/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/uid/uid_main.c b/examples/uid/uid_main.c index 9792114be..f5f6e5fa0 100644 --- a/examples/uid/uid_main.c +++ b/examples/uid/uid_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/uid/uid_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -51,14 +49,10 @@ static void show_usage(FAR const char *progname, FAR FILE *stream, int exit_code) { fprintf(stream, "USAGE:\n"); - fprintf(stream, "\t%s -uid <uid> - Show user info by ID\n", - progname); - fprintf(stream, "\t%s -uname <name> - Show user info by name\n", - progname); - fprintf(stream, "\t%s -gid <gid> - Show group info by ID\n", - progname); - fprintf(stream, "\t%s -gname <name> - Show group info by name\n", - progname); + fprintf(stream, "\t%s -uid <uid> - Show user info by ID\n", progname); + fprintf(stream, "\t%s -uname <name> - Show user info by name\n", progname); + fprintf(stream, "\t%s -gid <gid> - Show group info by ID\n", progname); + fprintf(stream, "\t%s -gname <name> - Show group info by name\n", progname); fprintf(stream, "\t%s -h - Show this help info\n", progname); exit(exit_code); } diff --git a/examples/unionfs/CMakeLists.txt b/examples/unionfs/CMakeLists.txt deleted file mode 100644 index 10471bfb9..000000000 --- a/examples/unionfs/CMakeLists.txt +++ /dev/null @@ -1,61 +0,0 @@ -# ############################################################################## -# apps/examples/unionfs/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_UNIONFS) - - add_custom_target( - testdir - COMMAND ${CMAKE_COMMAND} -E copy_directory - ${CMAKE_CURRENT_LIST_DIR}/atestdir atestdir - COMMAND ${CMAKE_COMMAND} -E copy_directory - ${CMAKE_CURRENT_LIST_DIR}/btestdir btestdir - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - COMMENT "EXAMPLES UNIONFS Copy test dir...") - - add_custom_target( - testdir_img - COMMAND genromfs -f atestdir.img -d atestdir -V "UNIONFS_FS1" - COMMAND genromfs -f btestdir.img -d btestdir -V "UNIONFS_FS2" - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - DEPENDS testdir - COMMENT "EXAMPLES UNIONFS Generating testdir.img...") - - add_custom_target( - romfs_testdir_h - COMMAND xxd -i atestdir.img > romfs_atestdir.h - COMMAND xxd -i btestdir.img > romfs_btestdir.h - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - DEPENDS testdir_img - COMMENT "EXAMPLES UNIONFS Generating romfs_testdir.h...") - - nuttx_add_application( - NAME - unionfs - MODULE - ${CONFIG_EXAMPLES_UNIONFS} - SRCS - unionfs_main.c - INCLUDE_DIRECTORIES - ${CMAKE_CURRENT_BINARY_DIR} - DEPENDS - romfs_testdir_h) -endif() diff --git a/examples/unionfs/Kconfig b/examples/unionfs/Kconfig index c6df6e185..00e04c3d7 100644 --- a/examples/unionfs/Kconfig +++ b/examples/unionfs/Kconfig @@ -6,7 +6,7 @@ config EXAMPLES_UNIONFS tristate "Union file system example" default n - depends on FS_ROMFS && FS_UNIONFS && BUILD_FLAT + depends on (FS_ROMFS || FS_UNIONFS) && BUILD_FLAT ---help--- Enable the Union File System example diff --git a/examples/unionfs/Make.defs b/examples/unionfs/Make.defs index 73c0d1772..6912a1078 100644 --- a/examples/unionfs/Make.defs +++ b/examples/unionfs/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/unionfs/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/unionfs/Makefile b/examples/unionfs/Makefile index 30064e69c..ba95b901c 100644 --- a/examples/unionfs/Makefile +++ b/examples/unionfs/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/unionfs/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/unionfs/unionfs_main.c b/examples/unionfs/unionfs_main.c index b1a4a5020..8005b1103 100644 --- a/examples/unionfs/unionfs_main.c +++ b/examples/unionfs/unionfs_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/unionfs/unionfs_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -41,6 +39,7 @@ #include <errno.h> #include <nuttx/drivers/ramdisk.h> +#include <nuttx/fs/unionfs.h> #include "romfs_atestdir.h" #include "romfs_btestdir.h" @@ -76,15 +75,15 @@ #endif #ifndef CONFIG_EXAMPLES_UNIONFS_MOUNTPT -# define CONFIG_EXAMPLES_UNIONFS_MOUNTPT "/mnt/unionfs" +# define "/mnt/unionfs" #endif #ifndef CONFIG_EXAMPLES_UNIONFS_TMPA -# define CONFIG_EXAMPLES_UNIONFS_TMPA "/mnt/a" +# define "/mnt/a" #endif #ifndef CONFIG_EXAMPLES_UNIONFS_TMPB -# define CONFIG_EXAMPLES_UNIONFS_TMPB "/mnt/b" +# define "/mnt/b" #endif #define NSECTORS(b) (((b)+CONFIG_EXAMPLES_UNIONFS_SECTORSIZE-1)/CONFIG_EXAMPLES_UNIONFS_SECTORSIZE) @@ -176,9 +175,9 @@ int main(int argc, FAR char *argv[]) /* Now create and mount the union file system */ - ret = mount(NULL, CONFIG_EXAMPLES_UNIONFS_MOUNTPT, "unionfs", 0, - "fspath1=" CONFIG_EXAMPLES_UNIONFS_TMPA - ",fspath2=" CONFIG_EXAMPLES_UNIONFS_TMPB ",prefix2=offset"); + ret = unionfs_mount(CONFIG_EXAMPLES_UNIONFS_TMPA, NULL, + CONFIG_EXAMPLES_UNIONFS_TMPB, "offset", + CONFIG_EXAMPLES_UNIONFS_MOUNTPT); if (ret < 0) { printf("ERROR: Failed to create the union file system: %d\n", ret); diff --git a/examples/usbserial/CMakeLists.txt b/examples/usbserial/CMakeLists.txt deleted file mode 100644 index 6ddd3a4fb..000000000 --- a/examples/usbserial/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# ############################################################################## -# apps/examples/usbserial/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_USBSERIAL) - nuttx_add_application( - NAME - usbserial - STACKSIZE - ${CONFIG_DEFAULT_TASK_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_USBSERIAL} - SRCS - usbserial_main.c) -endif() diff --git a/examples/usbserial/Kconfig b/examples/usbserial/Kconfig index 017d58b3d..6e1bc5510 100644 --- a/examples/usbserial/Kconfig +++ b/examples/usbserial/Kconfig @@ -20,58 +20,6 @@ config EXAMPLES_USBSERIAL_BUFSIZE The size of the array that is used as an I/O buffer for USB serial data transfers. -choice - prompt "USB serial transfer" - default EXAMPLES_USBSERIAL_INANDOUT - ---help--- - Select usb serial transfer in or out - -config EXAMPLES_USBSERIAL_INANDOUT - bool "in and out" - -config EXAMPLES_USBSERIAL_INONLY - bool "in only" - -config EXAMPLES_USBSERIAL_OUTONLY - bool "out only" - -endchoice # USBSERIAL in or out - -config EXAMPLES_USBSERIAL_CONFIG_WAIT - bool "Config waiting time" - default n - ---help--- - Config waiting time after transfer - -if EXAMPLES_USBSERIAL_CONFIG_WAIT - -config EXAMPLES_USBSERIAL_IN_WAITING_TIME - int "In waiting time (ms)" - default 100 - -config EXAMPLES_USBSERIAL_OUT_WAITING_TIME - int "Out waiting time (ms)" - default 100 - -endif # USERSERIAL config wait - -choice - prompt "USB serial message" - default EXAMPLES_USBSERIAL_SMALLANDBIG - ---help--- - Select usb serial small or big message - -config EXAMPLES_USBSERIAL_SMALLANDBIG - bool "small and big" - -config EXAMPLES_USBSERIAL_ONLYSMALL - bool "only small" - -config EXAMPLES_USBSERIAL_ONLYBIG - bool "only big" - -endchoice # USBSERIAL small or big message - config EXAMPLES_USBSERIAL_TRACEINIT bool "USB Trace Initialization" default n diff --git a/examples/usbserial/Make.defs b/examples/usbserial/Make.defs index 8fd759570..44905ce59 100644 --- a/examples/usbserial/Make.defs +++ b/examples/usbserial/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/usbserial/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/usbserial/Makefile b/examples/usbserial/Makefile index 3146fd116..808a11de3 100644 --- a/examples/usbserial/Makefile +++ b/examples/usbserial/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/usbserial/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/usbserial/Makefile.host b/examples/usbserial/Makefile.host index d8bfb3eaa..3f50bf130 100644 --- a/examples/usbserial/Makefile.host +++ b/examples/usbserial/Makefile.host @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/usbserial/Makefile.host # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/usbserial/host.c b/examples/usbserial/host.c index 0e29ff525..2b158a388 100644 --- a/examples/usbserial/host.c +++ b/examples/usbserial/host.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/usbserial/host.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -24,6 +22,8 @@ * Included Files ****************************************************************************/ +#include <stdio.h> + #include <sys/types.h> #include <sys/stat.h> #include <stdio.h> @@ -38,17 +38,14 @@ * Pre-processor Definitions ****************************************************************************/ -#if defined(CONFIG_EXAMPLES_USBSERIAL_INONLY) && \ - defined(CONFIG_EXAMPLES_USBSERIAL_OUTONLY) +#if defined(CONFIG_EXAMPLES_USBSERIAL_INONLY) && defined(CONFIG_EXAMPLES_USBSERIAL_OUTONLY) # error "Cannot define both CONFIG_EXAMPLES_USBSERIAL_INONLY and _OUTONLY" #endif -#if defined(CONFIG_EXAMPLES_USBSERIAL_ONLYSMALL) && \ - defined(CONFIG_EXAMPLES_USBSERIAL_ONLYBIG) +#if defined(CONFIG_EXAMPLES_USBSERIAL_ONLYSMALL) && defined(CONFIG_EXAMPLES_USBSERIAL_ONLYBIG) # error "Cannot define both CONFIG_EXAMPLES_USBSERIAL_ONLYSMALL and _ONLYBIG" #endif -#if !defined(CONFIG_EXAMPLES_USBSERIAL_ONLYBIG) && \ - !defined(CONFIG_EXAMPLES_USBSERIAL_ONLYSMALL) +#if !defined(CONFIG_EXAMPLES_USBSERIAL_ONLYBIG) && !defined(CONFIG_EXAMPLES_USBSERIAL_ONLYSMALL) # ifndef CONFIG_EXAMPLES_USBSERIAL_INONLY # define COUNTER_NEEDED 1 # endif @@ -73,60 +70,56 @@ static const char g_shortmsg[] = "Sure... You betcha!!\n"; #ifndef CONFIG_EXAMPLES_USBSERIAL_ONLYSMALL static const char g_longmsg[] = - "I am proud to come to this city as the guest of your distinguished " - "Mayor, who has symbolized throughout the world the fighting spirit of " - "West Berlin. And I am proud to visit the Federal Republic with your " - "distinguished Chancellor who for so many years has committed Germany " - "to democracy and freedom and progress, and to come here in the company " - "of my fellow American, General Clay, who has been in this city during " - "its great moments of crisis and will come again if ever needed.\n" - "Two thousand years ago the proudest boast was \"civis Romanus sum.\" " - "Today, in the world of freedom, the proudest boast is " - "\"Ich bin ein Berliner.\"\r\"I appreciate my interpreter translating " - "my German!\nThere are many people in the world who really " - "don't understand, or say they don't, what is the great issue between " - "the free world and the Communist world. Let them come to Berlin. " - "There are some who say that communism is the wave of the future. " - "Let them come to Berlin. And there are some who say in Europe and " - "elsewhere we can work with the Communists. Let them come to Berlin. " - "And there are even a few who say that it is true that communism is " - "an evil system, but it permits us to make economic progress. " - "Lass' sie nach Berlin kommen. Let them come to Berlin.\n" - "Freedom has many difficulties and democracy is not perfect, but we have " - "never had to put a wall up to keep our people in, to prevent them from " - "leaving us. I want to say, on behalf of my countrymen, who live many " - "miles away on the other side of the Atlantic, who are far distant " - "from you, that they take the greatest pride that they have been able " - "to share with you, even from a distance, the story of the last 18 years. " - "I know of no town, no city, that has been besieged for 18 years that " - "still lives with the vitality and the force, and the hope and the " - "determination of the city of West Berlin. While the wall is the most " - "obvious and vivid demonstration of the failures of the Communist system, " - "for all the world to see, we take no satisfaction in it, for it is, " - "as your Mayor has said, an offense not only against history but an " - "offense against humanity, separating families, dividing husbands and " - "wives and brothers and sisters, and dividing a people who wish to be " - "joined together.\nWhat is true of this city is true of Germany--real, " - "lasting peace in Europe can never be assured as long as one German " - "out of four is denied the elementary right of free men, and that is " - "to make a free choice. In 18 years of peace and good faith, this " - "generation of Germans has earned the right to be free, including the " - "right to unite their families and their nation in lasting peace, " - "with good will to all people. You live in a defended island of freedom, " - "but your life is part of the main. So let me ask you as I close, to lift " - "your eyes beyond the dangers of today, to the hopes of tomorrow, beyond " - "the freedom merely of this city of Berlin, or your country of Germany, " - "to the advance of freedom everywhere, beyond the wall to the day of " - "peace with justice, beyond yourselves and ourselves to all mankind.\n" - "Freedom is indivisible, and when one man is enslaved, all are not free. " - "When all are free, then we can look forward to that day when this city " - "will be joined as one and this country and this great Continent of " - "Europe in a peaceful and hopeful globe. When that day finally comes, " - "as it will, the people of West Berlin can take sober satisfaction " - "in the fact that they were in the front lines for almost two decades.\n" - "All free men, wherever they may live, are citizens of Berlin, and, " - "therefore, as a free man, I take pride in the words " - "\"Ich bin ein Berliner.\"\n" + "I am proud to come to this city as the guest of your distinguished Mayor, " + "who has symbolized throughout the world the fighting spirit of West Berlin. " + "And I am proud to visit the Federal Republic with your distinguished Chancellor " + "who for so many years has committed Germany to democracy and freedom and " + "progress, and to come here in the company of my fellow American, General Clay, " + "who has been in this city during its great moments of crisis and will come " + "again if ever needed.\n" + "Two thousand years ago the proudest boast was \"civis Romanus sum.\" Today, " + "in the world of freedom, the proudest boast is \"Ich bin ein Berliner.\"\r\"" + "I appreciate my interpreter translating my German!\n" + "There are many people in the world who really don't understand, or say they " + "don't, what is the great issue between the free world and the Communist world. " + "Let them come to Berlin. There are some who say that communism is the wave of " + "the future. Let them come to Berlin. And there are some who say in Europe and " + "elsewhere we can work with the Communists. Let them come to Berlin. And there " + "are even a few who say that it is true that communism is an evil system, but it " + "permits us to make economic progress. Lass' sie nach Berlin kommen. Let them " + "come to Berlin.\n" + "Freedom has many difficulties and democracy is not perfect, but we have never " + "had to put a wall up to keep our people in, to prevent them from leaving us. I " + "want to say, on behalf of my countrymen, who live many miles away on the other " + "side of the Atlantic, who are far distant from you, that they take the greatest " + "pride that they have been able to share with you, even from a distance, the " + "story of the last 18 years. I know of no town, no city, that has been besieged " + "for 18 years that still lives with the vitality and the force, and the hope and " + "the determination of the city of West Berlin. While the wall is the most obvious " + "and vivid demonstration of the failures of the Communist system, for all the " + "world to see, we take no satisfaction in it, for it is, as your Mayor has said, " + "an offense not only against history but an offense against humanity, separating " + "families, dividing husbands and wives and brothers and sisters, and dividing a " + "people who wish to be joined together.\n" + "What is true of this city is true of Germany--real, lasting peace in Europe can " + "never be assured as long as one German out of four is denied the elementary " + "right of free men, and that is to make a free choice. In 18 years of peace and " + "good faith, this generation of Germans has earned the right to be free, " + "including the right to unite their families and their nation in lasting peace, " + "with good will to all people. You live in a defended island of freedom, but " + "your life is part of the main. So let me ask you as I close, to lift your eyes " + "beyond the dangers of today, to the hopes of tomorrow, beyond the freedom merely " + "of this city of Berlin, or your country of Germany, to the advance of freedom " + "everywhere, beyond the wall to the day of peace with justice, beyond yourselves " + "and ourselves to all mankind.\n" + "Freedom is indivisible, and when one man is enslaved, all are not free. When all " + "are free, then we can look forward to that day when this city will be joined as " + "one and this country and this great Continent of Europe in a peaceful and hopeful " + "globe. When that day finally comes, as it will, the people of West Berlin can take " + "sober satisfaction in the fact that they were in the front lines for almost two " + "decades.\n" + "All free men, wherever they may live, are citizens of Berlin, and, therefore, " + "as a free man, I take pride in the words \"Ich bin ein Berliner.\"\n" "President John F. Kennedy - June 26, 1963\n"; #endif @@ -207,11 +200,10 @@ int main(int argc, char **argv, char **envp) return 1; } - tty.c_iflag &= - ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON); + tty.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON); tty.c_oflag &= ~OPOST; - tty.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN); - tty.c_cflag &= ~(CSIZE | PARENB); + tty.c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN); + tty.c_cflag &= ~(CSIZE|PARENB); tty.c_cflag |= CS8; ret = tcsetattr(fd, TCSANOW, &tty); @@ -225,14 +217,14 @@ int main(int argc, char **argv, char **envp) /* Wait for and/or send messages -- forever */ - for (; ; ) + for (;;) { /* Test IN messages (device-to-host) */ #ifndef CONFIG_EXAMPLES_USBSERIAL_OUTONLY printf("main: Reading from the serial driver\n"); printf("main: ... (Control-C to terminate) ...\n"); - nbytes = read(fd, g_iobuffer, BUFFER_SIZE - 1); + nbytes = read(fd, g_iobuffer, BUFFER_SIZE-1); if (nbytes < 0) { printf("main: ERROR: Failed to read from %s: %s\n", @@ -257,8 +249,7 @@ int main(int argc, char **argv, char **envp) /* Test OUT messages (host-to-device) */ #ifndef CONFIG_EXAMPLES_USBSERIAL_INONLY -#if !defined(CONFIG_EXAMPLES_USBSERIAL_ONLYSMALL) && \ - !defined(CONFIG_EXAMPLES_USBSERIAL_ONLYBIG) +#if !defined(CONFIG_EXAMPLES_USBSERIAL_ONLYSMALL) && !defined(CONFIG_EXAMPLES_USBSERIAL_ONLYBIG) count++; if (count < 5) { @@ -285,8 +276,7 @@ int main(int argc, char **argv, char **envp) if (nbytes < 0) { - printf("main: ERROR: Failed to write to %s: %s\n", g_ttydev, - strerror(errno)); + printf("main: ERROR: Failed to write to %s: %s\n", g_ttydev, strerror(errno)); close(fd); return 2; } diff --git a/examples/usbserial/usbserial_main.c b/examples/usbserial/usbserial_main.c index e1eec27c8..17c051a49 100644 --- a/examples/usbserial/usbserial_main.c +++ b/examples/usbserial/usbserial_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/usbserial/usbserial_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -35,7 +33,7 @@ #include <string.h> #include <fcntl.h> #include <errno.h> -#include <nuttx/debug.h> +#include <debug.h> #include <nuttx/usb/usbdev.h> #include <nuttx/usb/usbdev_trace.h> @@ -122,30 +120,29 @@ static const char g_shortmsg[] = "Hello, World!!\n"; static const char g_longmsg[] = "The Spanish Armada a Speech by Queen Elizabeth I of England\n" "Addressed to the English army at Tilbury Fort - 1588\n" - "My loving people, we have been persuaded by some, that are careful of " - "our safety, to take heed how we commit ourselves to armed multitudes, " - "or fear of treachery; but I assure you, I do not desire to live to " - "distrust my faithful and loving people.\n" - "Let tyrants fear; I have always so behaved myself that, under God, I " - "have placed my chiefest strength and safeguard in the loyal hearts and " - "good will of my subjects. And therefore I am come amongst you at this " - "time, not as for my recreation or sport, but being resolved, in the " - "midst and heat of the battle, to live or die amongst you all; to lay " - "down, for my God, and for my kingdom, and for my people, my honour and " - "my blood, even the dust.\n" - "I know I have but the body of a weak and feeble woman; but I have the " - "heart of a king, and of a king of England, too; and think foul scorn " - "hat Parma or Spain, or any prince of Europe, should dare to invade the " - "borders of my realms: to which, rather than any dishonour should grow " - "by me, I myself will take up arms; I myself will be your general, " - "judge, and rewarder of every one of your virtues in the field.\n" + "My loving people, we have been persuaded by some, that are careful of our " + "safety, to take heed how we commit ourselves to armed multitudes, for fear " + "of treachery; but I assure you, I do not desire to live to distrust my " + "faithful and loving people.\n" + "Let tyrants fear; I have always so behaved myself that, under God, I have " + "placed my chiefest strength and safeguard in the loyal hearts and good will " + "of my subjects. And therefore I am come amongst you at this time, not as for " + "my recreation or sport, but being resolved, in the midst and heat of the " + "battle, to live or die amongst you all; to lay down, for my God, and for " + "my kingdom, and for my people, my honour and my blood, even the dust.\n" + "I know I have but the body of a weak and feeble woman; but I have the heart " + "of a king, and of a king of England, too; and think foul scorn that Parma " + "or Spain, or any prince of Europe, should dare to invade the borders of my " + "realms: to which, rather than any dishonour should grow by me, I myself will " + "take up arms; I myself will be your general, judge, and rewarder of every " + "one of your virtues in the field.\n" "I know already, by your forwardness, that you have deserved rewards and " - "crowns; and we do assure you, on the word of a prince, they shall be " - "duly paid you. In the mean my lieutenant general shall be in my stead, " - "than whom never prince commanded a more noble and worthy subject; not " - "doubting by your obedience to my general, by your concord in the camp, " - "and by your valour in the field, we shall shortly have a famous victory " - "over the enemies of my God, of my kingdom, and of my people.\n"; + "crowns; and we do assure you, on the word of a prince, they shall be duly " + "paid you. In the mean my lieutenant general shall be in my stead, than whom " + "never prince commanded a more noble and worthy subject; not doubting by " + "your obedience to my general, by your concord in the camp, and by your " + "valour in the field, we shall shortly have a famous victory over the enemies " + "of my God, of my kingdom, and of my people.\n"; #endif #ifndef CONFIG_EXAMPLES_USBSERIAL_INONLY @@ -194,48 +191,43 @@ int main(int argc, FAR char *argv[]) #endif ssize_t nbytes; #ifndef CONFIG_EXAMPLES_USBSERIAL_INONLY - int i; - int j; - int k; + int i, j, k; #endif int ret; - if (access(USBSER_DEVNAME, F_OK) < 0) - { - /* Initialize the USB serial driver */ + /* Initialize the USB serial driver */ - printf("usbserial_main: Registering USB serial driver\n"); + printf("usbserial_main: Registering USB serial driver\n"); #ifdef CONFIG_CDCACM - ctrl.usbdev = BOARDIOC_USBDEV_CDCACM; - ctrl.action = BOARDIOC_USBDEV_CONNECT; - ctrl.instance = 0; - ctrl.handle = &handle; + ctrl.usbdev = BOARDIOC_USBDEV_CDCACM; + ctrl.action = BOARDIOC_USBDEV_CONNECT; + ctrl.instance = 0; + ctrl.handle = &handle; #else - ctrl.usbdev = BOARDIOC_USBDEV_PL2303; - ctrl.action = BOARDIOC_USBDEV_CONNECT; - ctrl.instance = 0; - ctrl.handle = &handle; + ctrl.usbdev = BOARDIOC_USBDEV_PL2303; + ctrl.action = BOARDIOC_USBDEV_CONNECT; + ctrl.instance = 0; + ctrl.handle = &handle; #endif - ret = boardctl(BOARDIOC_USBDEV_CONTROL, (uintptr_t)&ctrl); - if (ret < 0) - { - printf("usbserial_main: ERROR: Failed to create the USB serial " - "device: %d\n", -ret); - return 1; - } - - printf("usbserial_main: Successfully registered the serial driver\n"); + ret = boardctl(BOARDIOC_USBDEV_CONTROL, (uintptr_t)&ctrl); + if (ret < 0) + { + printf("usbserial_main: ERROR: Failed to create the USB serial device: %d\n", + -ret); + return 1; } + printf("usbserial_main: Successfully registered the serial driver\n"); + #if defined(CONFIG_USBDEV_TRACE) && CONFIG_USBDEV_TRACE_INITIALIDSET != 0 - /* If USB tracing is enabled and tracing of initial USB events is - * specified, then dump all collected trace data to stdout + /* If USB tracing is enabled and tracing of initial USB events is specified, + * then dump all collected trace data to stdout */ sleep(5); @@ -263,7 +255,7 @@ int main(int argc, FAR char *argv[]) if (errcode == ENOTCONN) { - printf("usbserial_main: Not connected. Wait and try again.\n"); + printf("usbserial_main: Not connected. Wait and try again.\n"); sleep(5); } else @@ -275,9 +267,7 @@ int main(int argc, FAR char *argv[]) } } - /* If USB tracing is enabled, then dump all collected trace data - * to stdout - */ + /* If USB tracing is enabled, then dump all collected trace data to stdout */ dumptrace(); } @@ -288,7 +278,7 @@ int main(int argc, FAR char *argv[]) #ifndef CONFIG_EXAMPLES_USBSERIAL_INONLY #ifndef CONFIG_EXAMPLES_USBSERIAL_OUTONLY - infd = open(USBSER_DEVNAME, O_RDONLY | O_NONBLOCK); + infd = open(USBSER_DEVNAME, O_RDONLY|O_NONBLOCK); if (infd < 0) { printf("usbserial_main: ERROR: Failed to open " USBSER_DEVNAME @@ -299,7 +289,7 @@ int main(int argc, FAR char *argv[]) #else do { - infd = open(USBSER_DEVNAME, O_RDONLY | O_NONBLOCK); + infd = open(USBSER_DEVNAME, O_RDONLY|O_NONBLOCK); if (infd < 0) { int errcode = errno; @@ -310,7 +300,7 @@ int main(int argc, FAR char *argv[]) if (errcode == ENOTCONN) { - printf("usbserial_main: Not connected. Wait and try again.\n"); + printf("usbserial_main: Not connected. Wait and try again.\n"); sleep(5); } else @@ -322,9 +312,7 @@ int main(int argc, FAR char *argv[]) } } - /* If USB tracing is enabled, then dump all collected trace data - * to stdout - */ + /* If USB tracing is enabled, then dump all collected trace data to stdout */ dumptrace(); } @@ -336,9 +324,9 @@ int main(int argc, FAR char *argv[]) /* Send messages and get responses -- forever */ - for (; ; ) + for (;;) { - /* Test IN (device-to-host) messages */ + /* Test IN (device-to-host) messages */ #ifndef CONFIG_EXAMPLES_USBSERIAL_OUTONLY #if !defined(CONFIG_EXAMPLES_USBSERIAL_ONLYBIG) && !defined(CONFIG_EXAMPLES_USBSERIAL_ONLYSMALL) @@ -417,9 +405,9 @@ int main(int argc, FAR char *argv[]) printf(" "); } - if (j + k < nbytes) + if (j+k < nbytes) { - printf("%02x", g_iobuffer[j + k]); + printf("%02x", g_iobuffer[j+k]); } else { @@ -435,12 +423,11 @@ int main(int argc, FAR char *argv[]) printf(" "); } - if (j + k < nbytes) + if (j+k < nbytes) { - if (g_iobuffer[j + k] >= 0x20 && - g_iobuffer[j + k] < 0x7f) + if (g_iobuffer[j+k] >= 0x20 && g_iobuffer[j+k] < 0x7f) { - printf("%c", g_iobuffer[j + k]); + printf("%c", g_iobuffer[j+k]); } else { @@ -458,25 +445,15 @@ int main(int argc, FAR char *argv[]) } } -#ifdef CONFIG_EXAMPLES_USBSERIAL_CONFIG_WAIT - usleep(CONFIG_EXAMPLES_USBSERIAL_OUT_WAITING_TIME * 1000); -#else sleep(1); -#endif /* CONFIG_EXAMPLES_USBSERIAL_CONFIG_WAIT */ } #else /* CONFIG_EXAMPLES_USBSERIAL_INONLY */ printf("usbserial_main: Waiting\n"); -#ifdef CONFIG_EXAMPLES_USBSERIAL_CONFIG_WAIT - usleep(CONFIG_EXAMPLES_USBSERIAL_IN_WAITING_TIME * 1000); -#else sleep(5); -#endif /* CONFIG_EXAMPLES_USBSERIAL_CONFIG_WAIT */ #endif /* CONFIG_EXAMPLES_USBSERIAL_INONLY */ - /* If USB tracing is enabled, then dump all collected trace data - * to stdout - */ + /* If USB tracing is enabled, then dump all collected trace data to stdout */ dumptrace(); } diff --git a/examples/userfs/CMakeLists.txt b/examples/userfs/CMakeLists.txt deleted file mode 100644 index b594dbf79..000000000 --- a/examples/userfs/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# ############################################################################## -# apps/examples/userfs/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_USERFS) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_USERFS_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_USERFS_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_USERFS_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_USERFS} - SRCS - userfs_main.c) -endif() diff --git a/examples/userfs/Kconfig b/examples/userfs/Kconfig index c49764c5f..b1d868f5a 100644 --- a/examples/userfs/Kconfig +++ b/examples/userfs/Kconfig @@ -5,7 +5,6 @@ config EXAMPLES_USERFS tristate "UserFS test" - depends on FS_USERFS default n ---help--- Enables a simple test of the UserFS diff --git a/examples/userfs/Make.defs b/examples/userfs/Make.defs index 03ec72e72..b3f954594 100644 --- a/examples/userfs/Make.defs +++ b/examples/userfs/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/userfs/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/userfs/Makefile b/examples/userfs/Makefile index 3b4e2e69b..85cd484ba 100644 --- a/examples/userfs/Makefile +++ b/examples/userfs/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/userfs/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/userfs/userfs_main.c b/examples/userfs/userfs_main.c index d1d64fa80..1d80addd8 100644 --- a/examples/userfs/userfs_main.c +++ b/examples/userfs/userfs_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/userfs/userfs_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -26,14 +24,12 @@ #include <nuttx/config.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <fcntl.h> #include <dirent.h> #include <errno.h> -#include <fcntl.h> -#include <sched.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> #include <nuttx/fs/userfs.h> @@ -142,28 +138,19 @@ static char g_file3_data[UFSTEST_FILE3_MXSIZE] = "This is file 3"; static struct ufstest_file_s g_rootdir[UFSTEST_NFILES] = { { - { - .d_type = DTYPE_FILE, - .d_name = "File1" - }, + { DTYPE_FILE, "File1" }, UFSTEST_INIT_FILE1_SIZE, UFSTEST_FILE1_MXSIZE, g_file1_data }, { - { - .d_type = DTYPE_FILE, - .d_name = "File2" - }, + { DTYPE_FILE, "File2" }, UFSTEST_INIT_FILE2_SIZE, UFSTEST_FILE2_MXSIZE, g_file2_data }, { - { - .d_type = DTYPE_FILE, - .d_name = "File3" - }, + { DTYPE_FILE, "File3" }, UFSTEST_INIT_FILE3_SIZE, UFSTEST_FILE3_MXSIZE, g_file3_data @@ -245,7 +232,7 @@ static int ufstest_open(FAR void *volinfo, FAR const char *relpath, file->inuse = 0; } - if ((oflags & (O_WRONLY | O_APPEND)) == (O_WRONLY | O_APPEND)) + if ((oflags & (O_WROK | O_APPEND)) == (O_WROK | O_APPEND)) { opriv->pos = file->inuse; } @@ -256,7 +243,7 @@ static int ufstest_open(FAR void *volinfo, FAR const char *relpath, opriv->file = file; - /* Initially, there is one reference count on the open data. This may + /* Initiallly, there is one reference count on the open data. This may * be incremented in the event that the file is dup'ed. */ @@ -533,7 +520,7 @@ static int ufstest_rename(FAR void *volinfo, FAR const char *oldrelpath, file = ufstest_findbyname(oldrelpath); if (file != NULL) { - strlcpy(file->entry.d_name, newrelpath, NAME_MAX); + strncpy(file->entry.d_name, newrelpath, NAME_MAX + 1); return OK; } diff --git a/examples/usrsocktest/CMakeLists.txt b/examples/usrsocktest/CMakeLists.txt deleted file mode 100644 index a657ae2c8..000000000 --- a/examples/usrsocktest/CMakeLists.txt +++ /dev/null @@ -1,60 +0,0 @@ -# ############################################################################## -# apps/examples/usrsocktest/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_USRSOCKTEST) - - # USRSOCK Test built-in application info - - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_USRSOCKTEST_PROGNAME} - SRCS - usrsocktest_main.c - STACKSIZE - ${CONFIG_EXAMPLES_USRSOCKTEST_STACKSIZE} - PRIORITY - ${CONFIG_EXAMPLES_USRSOCKTEST_PRIORITY}) - - # NuttX USRSOCK Test - - set(CSRCS - usrsocktest_daemon.c - usrsocktest_basic_connect.c - usrsocktest_basic_daemon.c - usrsocktest_basic_getsockname.c - usrsocktest_basic_getsockopt.c - usrsocktest_basic_send.c - usrsocktest_basic_setsockopt.c - usrsocktest_block_recv.c - usrsocktest_block_send.c - usrsocktest_chardev.c - usrsocktest_multi_thread.c - usrsocktest_noblock_connect.c - usrsocktest_noblock_recv.c - usrsocktest_noblock_send.c - usrsocktest_nodaemon.c - usrsocktest_poll.c - usrsocktest_remote_disconnect.c - usrsocktest_wake_with_signal.c) - - target_sources(apps PRIVATE ${CSRCS}) -endif() diff --git a/examples/usrsocktest/Make.defs b/examples/usrsocktest/Make.defs index d107b19c3..0ae117ac2 100644 --- a/examples/usrsocktest/Make.defs +++ b/examples/usrsocktest/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/usrsocktest/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/usrsocktest/Makefile b/examples/usrsocktest/Makefile index 6d4a2b98b..2840881fa 100644 --- a/examples/usrsocktest/Makefile +++ b/examples/usrsocktest/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/usrsocktest/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/usrsocktest/defines.h b/examples/usrsocktest/defines.h index 938141223..84230f8b5 100644 --- a/examples/usrsocktest/defines.h +++ b/examples/usrsocktest/defines.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/usrsocktest/defines.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/usrsocktest/usrsocktest_basic_connect.c b/examples/usrsocktest/usrsocktest_basic_connect.c index b3f651d12..e442f4290 100644 --- a/examples/usrsocktest/usrsocktest_basic_connect.c +++ b/examples/usrsocktest/usrsocktest_basic_connect.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/usrsocktest/usrsocktest_basic_connect.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -31,7 +29,6 @@ #include <assert.h> #include <netinet/in.h> #include <arpa/inet.h> -#include <unistd.h> #include "defines.h" @@ -111,18 +108,18 @@ static void setup(FAR struct usrsocktest_daemon_conf_s *dconf) static void teardown(void) { - int unused_data ret; + int ret; if (sd >= 0) { ret = close(sd); - TEST_ASSERT_TRUE(ret >= 0); + assert(ret >= 0); } if (started) { ret = usrsocktest_daemon_stop(); - TEST_ASSERT_EQUAL(OK, ret); + assert(ret == OK); } } diff --git a/examples/usrsocktest/usrsocktest_basic_daemon.c b/examples/usrsocktest/usrsocktest_basic_daemon.c index 35f0568e3..80021ba40 100644 --- a/examples/usrsocktest/usrsocktest_basic_daemon.c +++ b/examples/usrsocktest/usrsocktest_basic_daemon.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/usrsocktest/usrsocktest_basic_daemon.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -335,7 +333,7 @@ static void basic_daemon_dup2(FAR struct usrsocktest_daemon_conf_s *dconf) TEST_ASSERT_EQUAL(2, usrsocktest_daemon_get_num_active_sockets()); ret = dup2(sd2, sd); - TEST_ASSERT_EQUAL(sd, ret); + TEST_ASSERT_EQUAL(0, ret); TEST_ASSERT_EQUAL(1, usrsocktest_daemon_get_num_active_sockets()); ret = close(sd2); @@ -504,29 +502,29 @@ TEST_SETUP(basic_daemon) TEST_TEAR_DOWN(basic_daemon) { - int unused_data ret; + int ret; if (sd >= 0) { ret = close(sd); - TEST_ASSERT_TRUE(ret >= 0); + assert(ret >= 0); } if (sd2 >= 0) { ret = close(sd2); - TEST_ASSERT_TRUE(ret >= 0); + assert(ret >= 0); } if (sd3 >= 0) { ret = close(sd3); - TEST_ASSERT_TRUE(ret >= 0); + assert(ret >= 0); } if (started) { ret = usrsocktest_daemon_stop(); - TEST_ASSERT_EQUAL(ret, OK); + assert(ret == OK); } } diff --git a/examples/usrsocktest/usrsocktest_basic_getsockname.c b/examples/usrsocktest/usrsocktest_basic_getsockname.c index ff6377c44..b32101e1c 100644 --- a/examples/usrsocktest/usrsocktest_basic_getsockname.c +++ b/examples/usrsocktest/usrsocktest_basic_getsockname.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/usrsocktest/usrsocktest_basic_getsockname.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -32,7 +30,6 @@ #include <netinet/in.h> #include <arpa/inet.h> #include <string.h> -#include <unistd.h> #include "defines.h" @@ -237,17 +234,17 @@ TEST_SETUP(basic_getsockname) TEST_TEAR_DOWN(basic_getsockname) { - int unused_data ret; + int ret; if (sd >= 0) { ret = close(sd); - TEST_ASSERT_TRUE(ret >= 0); + assert(ret >= 0); } if (started) { ret = usrsocktest_daemon_stop(); - TEST_ASSERT_EQUAL(ret, OK); + assert(ret == OK); } } diff --git a/examples/usrsocktest/usrsocktest_basic_getsockopt.c b/examples/usrsocktest/usrsocktest_basic_getsockopt.c index 1c6300d6e..287bfce66 100644 --- a/examples/usrsocktest/usrsocktest_basic_getsockopt.c +++ b/examples/usrsocktest/usrsocktest_basic_getsockopt.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/usrsocktest/usrsocktest_basic_getsockopt.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -29,7 +27,6 @@ #include <sys/types.h> #include <stdbool.h> #include <assert.h> -#include <unistd.h> #include "defines.h" @@ -216,17 +213,17 @@ TEST_SETUP(basic_getsockopt) TEST_TEAR_DOWN(basic_getsockopt) { - int unused_data ret; + int ret; if (sd >= 0) { ret = close(sd); - TEST_ASSERT_TRUE(ret >= 0); + assert(ret >= 0); } if (started) { ret = usrsocktest_daemon_stop(); - TEST_ASSERT_EQUAL(ret, OK); + assert(ret == OK); } } diff --git a/examples/usrsocktest/usrsocktest_basic_send.c b/examples/usrsocktest/usrsocktest_basic_send.c index 7a7fbb5a9..3e6ec878c 100644 --- a/examples/usrsocktest/usrsocktest_basic_send.c +++ b/examples/usrsocktest/usrsocktest_basic_send.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/usrsocktest/usrsocktest_basic_send.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -32,7 +30,6 @@ #include <netinet/in.h> #include <arpa/inet.h> #include <string.h> -#include <unistd.h> #include "defines.h" @@ -293,17 +290,17 @@ TEST_SETUP(basic_send) TEST_TEAR_DOWN(basic_send) { - int unused_data ret; + int ret; if (sd >= 0) { ret = close(sd); - TEST_ASSERT_TRUE(ret >= 0); + assert(ret >= 0); } if (started) { ret = usrsocktest_daemon_stop(); - TEST_ASSERT_EQUAL(ret, OK); + assert(ret == OK); } } diff --git a/examples/usrsocktest/usrsocktest_basic_setsockopt.c b/examples/usrsocktest/usrsocktest_basic_setsockopt.c index f38e57db9..3c15017d6 100644 --- a/examples/usrsocktest/usrsocktest_basic_setsockopt.c +++ b/examples/usrsocktest/usrsocktest_basic_setsockopt.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/usrsocktest/usrsocktest_basic_setsockopt.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -31,7 +29,6 @@ #include <assert.h> #include <netinet/in.h> #include <arpa/inet.h> -#include <unistd.h> #include "defines.h" @@ -184,17 +181,17 @@ TEST_SETUP(basic_setsockopt) TEST_TEAR_DOWN(basic_setsockopt) { - int unused_data ret; + int ret; if (sd >= 0) { ret = close(sd); - TEST_ASSERT_TRUE(ret >= 0); + assert(ret >= 0); } if (started) { ret = usrsocktest_daemon_stop(); - TEST_ASSERT_EQUAL(ret, OK); + assert(ret == OK); } } diff --git a/examples/usrsocktest/usrsocktest_block_recv.c b/examples/usrsocktest/usrsocktest_block_recv.c index b3832724d..d5126ca64 100644 --- a/examples/usrsocktest/usrsocktest_block_recv.c +++ b/examples/usrsocktest/usrsocktest_block_recv.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/usrsocktest/usrsocktest_block_recv.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -33,7 +31,6 @@ #include <netinet/in.h> #include <arpa/inet.h> #include <sys/time.h> -#include <unistd.h> #include "defines.h" @@ -197,7 +194,7 @@ static void no_block_connect(FAR struct usrsocktest_daemon_conf_s *dconf) dconf->endpoint_addr = "127.0.0.1"; dconf->endpoint_port = 255; - dconf->endpoint_block_connect = false; + dconf->endpoint_block_connect = true; dconf->endpoint_block_send = true; dconf->endpoint_recv_avail_from_start = true; dconf->endpoint_recv_avail = 6; @@ -251,8 +248,7 @@ static void no_block_connect(FAR struct usrsocktest_daemon_conf_s *dconf) TEST_ASSERT_EQUAL(1, ret); TEST_ASSERT_EQUAL_UINT8_ARRAY("a", data, 1); TEST_ASSERT_EQUAL(sizeof(remoteaddr), addrlen); - TEST_ASSERT_EQUAL_UINT8_ARRAY(&remoteaddr, &addr, - addrlen - sizeof(addr.sin_zero)); + TEST_ASSERT_EQUAL_UINT8_ARRAY(&remoteaddr, &addr, addrlen); TEST_ASSERT_EQUAL(1, usrsocktest_daemon_get_num_connected_sockets()); TEST_ASSERT_EQUAL(1, usrsocktest_daemon_get_num_active_sockets()); TEST_ASSERT_EQUAL(6, usrsocktest_daemon_get_recv_bytes()); @@ -269,8 +265,7 @@ static void no_block_connect(FAR struct usrsocktest_daemon_conf_s *dconf) TEST_ASSERT_EQUAL(5, ret); TEST_ASSERT_EQUAL_UINT8_ARRAY("abcde", data, 5); TEST_ASSERT_EQUAL(sizeof(remoteaddr), addrlen); - TEST_ASSERT_EQUAL_UINT8_ARRAY(&remoteaddr, &addr, - addrlen - sizeof(addr.sin_zero)); + TEST_ASSERT_EQUAL_UINT8_ARRAY(&remoteaddr, &addr, addrlen); TEST_ASSERT_EQUAL(1, usrsocktest_daemon_get_num_connected_sockets()); TEST_ASSERT_EQUAL(1, usrsocktest_daemon_get_num_active_sockets()); TEST_ASSERT_EQUAL(11, usrsocktest_daemon_get_recv_bytes()); @@ -359,7 +354,8 @@ static void receive_timeout(FAR struct usrsocktest_daemon_conf_s *dconf) tv.tv_sec = 0; tv.tv_usec = 100 * 1000; - ret = setsockopt(sd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)); + ret = setsockopt(sd, SOL_SOCKET, SO_RCVTIMEO, (FAR const void *)&tv, + sizeof(tv)); TEST_ASSERT_EQUAL(0, ret); /* Receive data from remote */ @@ -560,18 +556,18 @@ TEST_SETUP(block_recv) TEST_TEAR_DOWN(block_recv) { - int unused_data ret; + int ret; if (sd >= 0) { ret = close(sd); - TEST_ASSERT_TRUE(ret >= 0); + assert(ret >= 0); } if (started) { ret = usrsocktest_daemon_stop(); - TEST_ASSERT_EQUAL(ret, OK); + assert(ret == OK); } } diff --git a/examples/usrsocktest/usrsocktest_block_send.c b/examples/usrsocktest/usrsocktest_block_send.c index 87d9d9e30..d029ae465 100644 --- a/examples/usrsocktest/usrsocktest_block_send.c +++ b/examples/usrsocktest/usrsocktest_block_send.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/usrsocktest/usrsocktest_block_send.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -34,7 +32,6 @@ #include <arpa/inet.h> #include <string.h> #include <sys/time.h> -#include <unistd.h> #include "defines.h" @@ -287,7 +284,8 @@ static void send_timeout(FAR struct usrsocktest_daemon_conf_s *dconf) tv.tv_sec = 0; tv.tv_usec = 100 * 1000; - ret = setsockopt(sd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv)); + ret = setsockopt(sd, SOL_SOCKET, SO_SNDTIMEO, (FAR const void *)&tv, + sizeof(tv)); TEST_ASSERT_EQUAL(0, ret); /* Try send data to remote. */ @@ -360,17 +358,17 @@ TEST_SETUP(block_send) TEST_TEAR_DOWN(block_send) { - int unused_data ret; + int ret; if (sd >= 0) { ret = close(sd); - TEST_ASSERT_TRUE(ret >= 0); + assert(ret >= 0); } if (started) { ret = usrsocktest_daemon_stop(); - TEST_ASSERT_EQUAL(ret, OK); + assert(ret == OK); } } diff --git a/examples/usrsocktest/usrsocktest_chardev.c b/examples/usrsocktest/usrsocktest_chardev.c index 9ba0eb413..3e21c490e 100644 --- a/examples/usrsocktest/usrsocktest_chardev.c +++ b/examples/usrsocktest/usrsocktest_chardev.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/usrsocktest/usrsocktest_chardev.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -26,7 +24,6 @@ #include <fcntl.h> #include <errno.h> -#include <unistd.h> #include "defines.h" @@ -99,18 +96,18 @@ TEST_SETUP(char_dev) TEST_TEAR_DOWN(char_dev) { - int unused_data ret; + int ret; if (us_fd >= 0) { ret = close(us_fd); - TEST_ASSERT_TRUE(ret >= 0); + assert(ret >= 0); } if (us_fd_two >= 0) { ret = close(us_fd_two); - TEST_ASSERT_TRUE(ret >= 0); + assert(ret >= 0); } } diff --git a/examples/usrsocktest/usrsocktest_daemon.c b/examples/usrsocktest/usrsocktest_daemon.c index efa543591..e4fbad287 100644 --- a/examples/usrsocktest/usrsocktest_daemon.c +++ b/examples/usrsocktest/usrsocktest_daemon.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/usrsocktest/usrsocktest_daemon.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -31,19 +29,15 @@ #include <stdio.h> #include <string.h> #include <stdlib.h> -#include <nuttx/debug.h> +#include <debug.h> #include <fcntl.h> #include <errno.h> #include <poll.h> #include <pthread.h> -#include <unistd.h> -#include <sys/param.h> #include <sys/socket.h> -#include <sys/ioctl.h> #include <netinet/in.h> #include <arpa/inet.h> - #include <nuttx/net/usrsock.h> #include "defines.h" @@ -53,7 +47,7 @@ ****************************************************************************/ #ifndef dbg -# define dbg _warn + #define dbg _warn #endif #define usrsocktest_dbg(...) ((void)0) @@ -61,6 +55,10 @@ #define TEST_SOCKET_SOCKID_BASE 10000U #define TEST_SOCKET_COUNT 8 +#ifndef ARRAY_SIZE +# define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) +#endif + #define noinline /**************************************************************************** @@ -76,7 +74,6 @@ struct test_socket_s bool connect_refused:1; bool disconnected:1; int recv_avail_bytes; - int flags; FAR void *endp; struct usrsock_message_req_ack_s pending_resp; }; @@ -139,7 +136,7 @@ static int test_socket_alloc(FAR struct daemon_priv_s *priv) { int i; - for (i = 0; i < nitems(priv->test_sockets); i++) + for (i = 0; i < ARRAY_SIZE(priv->test_sockets); i++) { FAR struct test_socket_s *tsock = &priv->test_sockets[i]; @@ -171,7 +168,7 @@ static FAR struct test_socket_s *test_socket_get( } sockid -= TEST_SOCKET_SOCKID_BASE; - if (sockid >= nitems(priv->test_sockets)) + if (sockid >= ARRAY_SIZE(priv->test_sockets)) { return NULL; } @@ -244,19 +241,19 @@ static int tsock_send_event(int fd, FAR struct daemon_priv_s *priv, event.head.flags = USRSOCK_MESSAGE_FLAG_EVENT; event.head.msgid = USRSOCK_MESSAGE_SOCKET_EVENT; - for (i = 0; i < nitems(priv->test_sockets); i++) + for (i = 0; i < ARRAY_SIZE(priv->test_sockets); i++) { if (tsock == &priv->test_sockets[i]) break; } - if (i == nitems(priv->test_sockets)) + if (i == ARRAY_SIZE(priv->test_sockets)) { return -EINVAL; } event.usockid = i + TEST_SOCKET_SOCKID_BASE; - event.head.events = events; + event.events = events; wlen = write(fd, &event, sizeof(event)); if (wlen < 0) @@ -276,17 +273,17 @@ static FAR void *find_endpoint(FAR struct daemon_priv_s *priv, in_addr_t ipaddr) { FAR struct sockaddr_in *endpaddr; - int unused_data ok; + int ok; endpaddr = malloc(sizeof(*endpaddr)); usrsocktest_endp_malloc_cnt++; - DEBUGASSERT(endpaddr != NULL); + assert(endpaddr); ok = inet_pton(AF_INET, priv->conf->endpoint_addr, &endpaddr->sin_addr.s_addr); endpaddr->sin_family = AF_INET; endpaddr->sin_port = htons(priv->conf->endpoint_port); - DEBUGASSERT(ok); + assert(ok); if (endpaddr->sin_addr.s_addr == ipaddr) { @@ -380,9 +377,8 @@ static int socket_request(int fd, FAR struct daemon_priv_s *priv, /* Prepare response. */ - resp.head.msgid = USRSOCK_MESSAGE_RESPONSE_ACK; - resp.head.flags = 0; - resp.head.events = 0; + resp.head.msgid = USRSOCK_MESSAGE_RESPONSE_ACK; + resp.head.flags = 0; resp.xid = req->head.xid; resp.result = socketid; @@ -417,8 +413,7 @@ static int close_request(int fd, FAR struct daemon_priv_s *priv, /* Prepare response. */ - resp.head.msgid = USRSOCK_MESSAGE_RESPONSE_ACK; - resp.head.events = 0; + resp.head.msgid = USRSOCK_MESSAGE_RESPONSE_ACK; resp.xid = req->head.xid; if (priv->conf->delay_all_responses) { @@ -556,9 +551,8 @@ prepare: /* Prepare response. */ resp.xid = req->head.xid; - resp.head.msgid = USRSOCK_MESSAGE_RESPONSE_ACK; - resp.head.flags = 0; - resp.head.events = 0; + resp.head.msgid = USRSOCK_MESSAGE_RESPONSE_ACK; + resp.head.flags = 0; if (priv->conf->endpoint_block_connect) { @@ -750,9 +744,8 @@ prepare: /* Prepare response. */ resp.xid = req->head.xid; - resp.head.msgid = USRSOCK_MESSAGE_RESPONSE_ACK; - resp.head.flags = 0; - resp.head.events = 0; + resp.head.msgid = USRSOCK_MESSAGE_RESPONSE_ACK; + resp.head.flags = 0; if (priv->conf->delay_all_responses) { @@ -857,7 +850,7 @@ static int recvfrom_request(int fd, FAR struct daemon_priv_s *priv, if (!tsock->connected) { - ret = (tsock->endp) ? 0 : -ENOTCONN; + ret = -ENOTCONN; goto prepare; } @@ -887,9 +880,8 @@ prepare: /* Prepare response. */ resp.reqack.xid = req->head.xid; - resp.reqack.head.msgid = USRSOCK_MESSAGE_RESPONSE_DATA_ACK; - resp.reqack.head.flags = 0; - resp.reqack.head.events = 0; + resp.reqack.head.msgid = USRSOCK_MESSAGE_RESPONSE_DATA_ACK; + resp.reqack.head.flags = 0; if (priv->conf->delay_all_responses) { @@ -1079,9 +1071,8 @@ prepare: /* Prepare response. */ resp.xid = req->head.xid; - resp.head.msgid = USRSOCK_MESSAGE_RESPONSE_ACK; - resp.head.flags = 0; - resp.head.events = 0; + resp.head.msgid = USRSOCK_MESSAGE_RESPONSE_ACK; + resp.head.flags = 0; if (priv->conf->delay_all_responses) { @@ -1186,9 +1177,8 @@ prepare: /* Prepare response. */ resp.reqack.xid = req->head.xid; - resp.reqack.head.msgid = USRSOCK_MESSAGE_RESPONSE_DATA_ACK; - resp.reqack.head.flags = 0; - resp.reqack.head.events = 0; + resp.reqack.head.msgid = USRSOCK_MESSAGE_RESPONSE_DATA_ACK; + resp.reqack.head.flags = 0; if (priv->conf->delay_all_responses) { @@ -1298,143 +1288,8 @@ prepare: /* Prepare response. */ resp.reqack.xid = req->head.xid; - resp.reqack.head.msgid = USRSOCK_MESSAGE_RESPONSE_DATA_ACK; - resp.reqack.head.flags = 0; - resp.reqack.head.events = 0; - - if (priv->conf->delay_all_responses) - { - resp.reqack.head.flags = USRSOCK_MESSAGE_FLAG_REQ_IN_PROGRESS; - resp.reqack.result = -EINPROGRESS; - resp.valuelen = 0; - resp.valuelen_nontrunc = 0; - - /* Send ack response. */ - - wlen = write(fd, &resp, sizeof(resp)); - if (wlen < 0) - { - return -errno; - } - - if (wlen != sizeof(resp)) - { - return -ENOSPC; - } - - pthread_mutex_unlock(&daemon_mutex); - usleep(50 * 1000); - pthread_mutex_lock(&daemon_mutex); - - /* Previous write was acknowledgment to request, informing that request - * is still in progress. Now write actual completion response. - */ - - resp.reqack.head.msgid = USRSOCK_MESSAGE_RESPONSE_DATA_ACK; - resp.reqack.head.flags &= ~USRSOCK_MESSAGE_FLAG_REQ_IN_PROGRESS; - } - + resp.reqack.head.msgid = USRSOCK_MESSAGE_RESPONSE_DATA_ACK; resp.reqack.head.flags = 0; - resp.reqack.result = ret; - if (req->max_addrlen == 0) - { - resp.valuelen = 0; - resp.valuelen_nontrunc = sizeof(addr); - } - else if (ret >= 0) - { - resp.valuelen = sizeof(addr); - resp.valuelen_nontrunc = sizeof(addr); - if (resp.valuelen > req->max_addrlen) - { - resp.valuelen = req->max_addrlen; - } - } - else - { - resp.valuelen = 0; - resp.valuelen_nontrunc = 0; - } - - /* Send response. */ - - wlen = write(fd, &resp, sizeof(resp)); - if (wlen < 0) - { - return -errno; - } - - if (wlen != sizeof(resp)) - { - return -ENOSPC; - } - - if (resp.valuelen > 0) - { - /* Send address (value) */ - - wlen = write(fd, &addr, resp.valuelen); - if (wlen < 0) - { - return -errno; - } - - if (wlen != resp.valuelen) - { - return -ENOSPC; - } - } - - return OK; -} - -static int ioctl_request(int fd, FAR struct daemon_priv_s *priv, - FAR void *hdrbuf) -{ - FAR struct usrsock_request_ioctl_s *req = hdrbuf; - struct usrsock_message_datareq_ack_s resp = { - }; - - FAR struct test_socket_s *tsock; - uint32_t value; - ssize_t wlen; - ssize_t rlen; - int ret; - - /* Check if this socket exists. */ - - tsock = test_socket_get(priv, req->usockid); - if (!tsock) - { - ret = -EBADFD; - goto prepare; - } - - if (req->arglen != sizeof(value)) - { - ret = -EINVAL; - goto prepare; - } - - /* Read value. */ - - rlen = read(fd, &value, sizeof(value)); - if (rlen < 0 || rlen < sizeof(value)) - { - ret = -EFAULT; - goto prepare; - } - - ret = OK; - -prepare: - - /* Prepare response. */ - - resp.reqack.xid = req->head.xid; - resp.reqack.head.msgid = USRSOCK_MESSAGE_RESPONSE_DATA_ACK; - resp.reqack.head.flags = 0; - resp.reqack.head.events = 0; if (priv->conf->delay_all_responses) { @@ -1472,15 +1327,17 @@ prepare: resp.reqack.result = ret; if (ret >= 0) { - resp.valuelen = sizeof(value); - resp.valuelen_nontrunc = sizeof(value); - - tsock->flags |= value; - value = tsock->flags; + resp.valuelen = sizeof(addr); + resp.valuelen_nontrunc = sizeof(addr); + if (resp.valuelen > req->max_addrlen) + { + resp.valuelen = req->max_addrlen; + } } else { resp.valuelen = 0; + resp.valuelen_nontrunc = 0; } /* Send response. */ @@ -1500,7 +1357,7 @@ prepare: { /* Send address (value) */ - wlen = write(fd, &value, resp.valuelen); + wlen = write(fd, &addr, resp.valuelen); if (wlen < 0) { return -errno; @@ -1572,15 +1429,9 @@ static int handle_usrsock_request(int fd, FAR struct daemon_priv_s *priv) sizeof(struct usrsock_request_getsockname_s), getsockname_request, }, - - [USRSOCK_REQUEST_IOCTL] = - { - sizeof(struct usrsock_request_ioctl_s), - ioctl_request, - }, }; - uint8_t hdrbuf[32]; + uint8_t hdrbuf[16]; FAR struct usrsock_request_common_s *common_hdr = (FAR void *)hdrbuf; ssize_t rlen; @@ -1602,8 +1453,7 @@ static int handle_usrsock_request(int fd, FAR struct daemon_priv_s *priv) return -EIO; } - DEBUGASSERT(handlers[common_hdr->reqid].hdrlen < - sizeof(hdrbuf) - sizeof(*common_hdr)); + assert(handlers[common_hdr->reqid].hdrlen < sizeof(hdrbuf)); rlen = read_req(fd, common_hdr, hdrbuf, handlers[common_hdr->reqid].hdrlen); @@ -1699,7 +1549,6 @@ static int establish_blocked_connection(int fd, priv->sockets_waiting_connect--; resp->head.flags &= ~USRSOCK_MESSAGE_FLAG_REQ_IN_PROGRESS; - resp->head.events = 0; wlen = write(fd, resp, sizeof(*resp)); if (wlen < 0) @@ -1751,7 +1600,6 @@ static int fail_blocked_connection(int fd, FAR struct daemon_priv_s *priv, priv->sockets_waiting_connect--; resp->head.flags &= ~USRSOCK_MESSAGE_FLAG_REQ_IN_PROGRESS; - resp->head.events = 0; wlen = write(fd, resp, sizeof(*resp)); if (wlen < 0) @@ -1776,7 +1624,7 @@ static int for_each_connection(int fd, FAR struct daemon_priv_s *priv, { int i; - for (i = 0; i < nitems(priv->test_sockets); i++) + for (i = 0; i < ARRAY_SIZE(priv->test_sockets); i++) { FAR struct test_socket_s *tsock = &priv->test_sockets[i]; @@ -2055,12 +1903,6 @@ errout_closepipe: out: pthread_mutex_unlock(&daemon_mutex); usrsocktest_dbg("ret: %d\n", ret); - - if (ret == OK) - { - usleep(100); - } - return ret; } @@ -2086,10 +1928,10 @@ int usrsocktest_daemon_stop(void) goto out; } - item = (FAR struct delayed_cmd_s *)sq_peek(&priv->delayed_cmd_threads); + item = (void *)sq_peek(&priv->delayed_cmd_threads); while (item) { - next = (FAR struct delayed_cmd_s *)sq_next(&item->node); + next = (void *)sq_next(&item->node); pthread_mutex_unlock(&daemon_mutex); pthread_join(item->tid, &retval); @@ -2113,7 +1955,7 @@ int usrsocktest_daemon_stop(void) goto out; } - for (i = 0; i < nitems(priv->test_sockets); i++) + for (i = 0; i < ARRAY_SIZE(priv->test_sockets); i++) { if (priv->test_sockets[i].opened && priv->test_sockets[i].endp != NULL) { @@ -2337,11 +2179,6 @@ bool usrsocktest_send_delayed_command(const char cmd, sq_addlast(&delayed_cmd->node, &priv->delayed_cmd_threads); - if (ret == OK) - { - usleep(100); - } - return true; } diff --git a/examples/usrsocktest/usrsocktest_main.c b/examples/usrsocktest/usrsocktest_main.c index c6109423e..d7024c292 100644 --- a/examples/usrsocktest/usrsocktest_main.c +++ b/examples/usrsocktest/usrsocktest_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/usrsocktest/usrsocktest_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -32,7 +30,7 @@ #include <malloc.h> #include <stdio.h> #include <assert.h> -#include <nuttx/debug.h> +#include <debug.h> #include <fcntl.h> #include <errno.h> #include <unistd.h> @@ -51,11 +49,15 @@ ****************************************************************************/ #ifndef dbg -# define dbg _warn + #define dbg _warn #endif #define usrsocktest_dbg(...) ((void)0) +#ifndef ARRAY_SIZE +# define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) +#endif + /**************************************************************************** * Private Data ****************************************************************************/ diff --git a/examples/usrsocktest/usrsocktest_multi_thread.c b/examples/usrsocktest/usrsocktest_multi_thread.c index 8c3764310..6b6bd11e8 100644 --- a/examples/usrsocktest/usrsocktest_multi_thread.c +++ b/examples/usrsocktest/usrsocktest_multi_thread.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/usrsocktest/usrsocktest_multi_thread.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -24,12 +22,10 @@ * Included Files ****************************************************************************/ -#include <sys/param.h> #include <sys/socket.h> #include <assert.h> #include <netinet/in.h> #include <arpa/inet.h> -#include <unistd.h> #include "defines.h" @@ -37,6 +33,10 @@ * Pre-processor Definitions ****************************************************************************/ +#ifndef ARRAY_SIZE +# define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) +#endif + /**************************************************************************** * Private Types ****************************************************************************/ @@ -114,12 +114,12 @@ TEST_SETUP(multithread) { int i; - for (i = 0; i < nitems(sds); i++) + for (i = 0; i < ARRAY_SIZE(sds); i++) { sds[i] = -1; } - for (i = 0; i < nitems(tids); i++) + for (i = 0; i < ARRAY_SIZE(tids); i++) { tids[i] = -1; } @@ -146,33 +146,33 @@ TEST_SETUP(multithread) TEST_TEAR_DOWN(multithread) { - int unused_data ret; + int ret; int i; - for (i = 0; i < nitems(tids); i++) + for (i = 0; i < ARRAY_SIZE(tids); i++) { if (tids[i] != -1) { ret = pthread_cancel(tids[i]); - TEST_ASSERT_EQUAL(ret, OK); + assert(ret == OK); ret = pthread_join(tids[i], NULL); - TEST_ASSERT_EQUAL(ret, OK); + assert(ret == OK); } } - for (i = 0; i < nitems(sds); i++) + for (i = 0; i < ARRAY_SIZE(sds); i++) { if (sds[i] != -1) { ret = close(sds[i]); - TEST_ASSERT_TRUE(ret >= 0); + assert(ret >= 0); } } if (started) { ret = usrsocktest_daemon_stop(); - TEST_ASSERT_EQUAL(ret, OK); + assert(ret == OK); } } @@ -212,7 +212,7 @@ TEST(multithread, open_close) /* Launch worker threads. */ - for (i = 0; i < nitems(tids); i++) + for (i = 0; i < ARRAY_SIZE(tids); i++) { ret = pthread_create(&tids[i], NULL, usrsock_socket_multitask_thread, sds + i); diff --git a/examples/usrsocktest/usrsocktest_noblock_connect.c b/examples/usrsocktest/usrsocktest_noblock_connect.c index 32906e2a2..50a6a1138 100644 --- a/examples/usrsocktest/usrsocktest_noblock_connect.c +++ b/examples/usrsocktest/usrsocktest_noblock_connect.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/usrsocktest/usrsocktest_noblock_connect.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -30,7 +28,6 @@ #include <stdbool.h> #include <assert.h> #include <fcntl.h> -#include <unistd.h> #include <netinet/in.h> #include <arpa/inet.h> @@ -73,24 +70,24 @@ TEST_SETUP(no_block_connect) TEST_TEAR_DOWN(no_block_connect) { - int unused_data ret; + int ret; if (sd >= 0) { ret = close(sd); - TEST_ASSERT_EQUAL(ret, 0); + assert(ret == 0); } if (sd2 >= 0) { ret = close(sd2); - TEST_ASSERT_EQUAL(ret, 0); + assert(ret == 0); } if (started) { ret = usrsocktest_daemon_stop(); - TEST_ASSERT_EQUAL(ret, OK); + assert(ret == OK); } } @@ -120,13 +117,13 @@ TEST(no_block_connect, instant_connect) flags = fcntl(sd, F_GETFL, 0); TEST_ASSERT_TRUE(flags >= 0); - TEST_ASSERT_EQUAL(O_RDWR, flags & O_ACCMODE); + TEST_ASSERT_EQUAL(O_RDWR, flags & O_RDWR); TEST_ASSERT_EQUAL(0, flags & O_NONBLOCK); ret = fcntl(sd, F_SETFL, flags | O_NONBLOCK); TEST_ASSERT_EQUAL(0, ret); flags = fcntl(sd, F_GETFL, 0); TEST_ASSERT_TRUE(flags >= 0); - TEST_ASSERT_EQUAL(O_RDWR, flags & O_ACCMODE); + TEST_ASSERT_EQUAL(O_RDWR, flags & O_RDWR); TEST_ASSERT_EQUAL(O_NONBLOCK, flags & O_NONBLOCK); /* Do connect, should succeed instantly. */ @@ -188,13 +185,13 @@ TEST(no_block_connect, delayed_connect) flags = fcntl(sd, F_GETFL, 0); TEST_ASSERT_TRUE(flags >= 0); - TEST_ASSERT_EQUAL(O_RDWR, flags & O_ACCMODE); + TEST_ASSERT_EQUAL(O_RDWR, flags & O_RDWR); TEST_ASSERT_EQUAL(0, flags & O_NONBLOCK); ret = fcntl(sd, F_SETFL, flags | O_NONBLOCK); TEST_ASSERT_EQUAL(0, ret); flags = fcntl(sd, F_GETFL, 0); TEST_ASSERT_TRUE(flags >= 0); - TEST_ASSERT_EQUAL(O_RDWR, flags & O_ACCMODE); + TEST_ASSERT_EQUAL(O_RDWR, flags & O_RDWR); TEST_ASSERT_EQUAL(O_NONBLOCK, flags & O_NONBLOCK); /* Launch connect attempt, daemon delays actual connection until @@ -290,13 +287,13 @@ TEST(no_block_connect, close_not_connected) flags = fcntl(sd, F_GETFL, 0); TEST_ASSERT_TRUE(flags >= 0); - TEST_ASSERT_EQUAL(O_RDWR, flags & O_ACCMODE); + TEST_ASSERT_EQUAL(O_RDWR, flags & O_RDWR); TEST_ASSERT_EQUAL(0, flags & O_NONBLOCK); ret = fcntl(sd, F_SETFL, flags | O_NONBLOCK); TEST_ASSERT_EQUAL(0, ret); flags = fcntl(sd, F_GETFL, 0); TEST_ASSERT_TRUE(flags >= 0); - TEST_ASSERT_EQUAL(O_RDWR, flags & O_ACCMODE); + TEST_ASSERT_EQUAL(O_RDWR, flags & O_RDWR); TEST_ASSERT_EQUAL(O_NONBLOCK, flags & O_NONBLOCK); /* Launch connect attempt, daemon delays actual connection until @@ -363,13 +360,13 @@ TEST(no_block_connect, early_drop) flags = fcntl(sd, F_GETFL, 0); TEST_ASSERT_TRUE(flags >= 0); - TEST_ASSERT_EQUAL(O_RDWR, flags & O_ACCMODE); + TEST_ASSERT_EQUAL(O_RDWR, flags & O_RDWR); TEST_ASSERT_EQUAL(0, flags & O_NONBLOCK); ret = fcntl(sd, F_SETFL, flags | O_NONBLOCK); TEST_ASSERT_EQUAL(0, ret); flags = fcntl(sd, F_GETFL, 0); TEST_ASSERT_TRUE(flags >= 0); - TEST_ASSERT_EQUAL(O_RDWR, flags & O_ACCMODE); + TEST_ASSERT_EQUAL(O_RDWR, flags & O_RDWR); TEST_ASSERT_EQUAL(O_NONBLOCK, flags & O_NONBLOCK); /* Launch connect attempt, daemon delays actual connection until @@ -443,24 +440,24 @@ TEST(no_block_connect, multiple) flags = fcntl(sd, F_GETFL, 0); TEST_ASSERT_TRUE(flags >= 0); - TEST_ASSERT_EQUAL(O_RDWR, flags & O_ACCMODE); + TEST_ASSERT_EQUAL(O_RDWR, flags & O_RDWR); TEST_ASSERT_EQUAL(0, flags & O_NONBLOCK); ret = fcntl(sd, F_SETFL, flags | O_NONBLOCK); TEST_ASSERT_EQUAL(0, ret); flags = fcntl(sd, F_GETFL, 0); TEST_ASSERT_TRUE(flags >= 0); - TEST_ASSERT_EQUAL(O_RDWR, flags & O_ACCMODE); + TEST_ASSERT_EQUAL(O_RDWR, flags & O_RDWR); TEST_ASSERT_EQUAL(O_NONBLOCK, flags & O_NONBLOCK); flags = fcntl(sd2, F_GETFL, 0); TEST_ASSERT_TRUE(flags >= 0); - TEST_ASSERT_EQUAL(O_RDWR, flags & O_ACCMODE); + TEST_ASSERT_EQUAL(O_RDWR, flags & O_RDWR); TEST_ASSERT_EQUAL(0, flags & O_NONBLOCK); ret = fcntl(sd2, F_SETFL, flags | O_NONBLOCK); TEST_ASSERT_EQUAL(0, ret); flags = fcntl(sd2, F_GETFL, 0); TEST_ASSERT_TRUE(flags >= 0); - TEST_ASSERT_EQUAL(O_RDWR, flags & O_ACCMODE); + TEST_ASSERT_EQUAL(O_RDWR, flags & O_RDWR); TEST_ASSERT_EQUAL(O_NONBLOCK, flags & O_NONBLOCK); /* Launch connect attempts, daemon delays actual connection until @@ -552,24 +549,24 @@ TEST(no_block_connect, multiple) flags = fcntl(sd, F_GETFL, 0); TEST_ASSERT_TRUE(flags >= 0); - TEST_ASSERT_EQUAL(O_RDWR, flags & O_ACCMODE); + TEST_ASSERT_EQUAL(O_RDWR, flags & O_RDWR); TEST_ASSERT_EQUAL(0, flags & O_NONBLOCK); ret = fcntl(sd, F_SETFL, flags | O_NONBLOCK); TEST_ASSERT_EQUAL(0, ret); flags = fcntl(sd, F_GETFL, 0); TEST_ASSERT_TRUE(flags >= 0); - TEST_ASSERT_EQUAL(O_RDWR, flags & O_ACCMODE); + TEST_ASSERT_EQUAL(O_RDWR, flags & O_RDWR); TEST_ASSERT_EQUAL(O_NONBLOCK, flags & O_NONBLOCK); flags = fcntl(sd2, F_GETFL, 0); TEST_ASSERT_TRUE(flags >= 0); - TEST_ASSERT_EQUAL(O_RDWR, flags & O_ACCMODE); + TEST_ASSERT_EQUAL(O_RDWR, flags & O_RDWR); TEST_ASSERT_EQUAL(0, flags & O_NONBLOCK); ret = fcntl(sd2, F_SETFL, flags | O_NONBLOCK); TEST_ASSERT_EQUAL(0, ret); flags = fcntl(sd2, F_GETFL, 0); TEST_ASSERT_TRUE(flags >= 0); - TEST_ASSERT_EQUAL(O_RDWR, flags & O_ACCMODE); + TEST_ASSERT_EQUAL(O_RDWR, flags & O_RDWR); TEST_ASSERT_EQUAL(O_NONBLOCK, flags & O_NONBLOCK); /* Launch connect attempts, daemon delays actual connection until @@ -637,24 +634,24 @@ TEST(no_block_connect, multiple) flags = fcntl(sd, F_GETFL, 0); TEST_ASSERT_TRUE(flags >= 0); - TEST_ASSERT_EQUAL(O_RDWR, flags & O_ACCMODE); + TEST_ASSERT_EQUAL(O_RDWR, flags & O_RDWR); TEST_ASSERT_EQUAL(0, flags & O_NONBLOCK); ret = fcntl(sd, F_SETFL, flags | O_NONBLOCK); TEST_ASSERT_EQUAL(0, ret); flags = fcntl(sd, F_GETFL, 0); TEST_ASSERT_TRUE(flags >= 0); - TEST_ASSERT_EQUAL(O_RDWR, flags & O_ACCMODE); + TEST_ASSERT_EQUAL(O_RDWR, flags & O_RDWR); TEST_ASSERT_EQUAL(O_NONBLOCK, flags & O_NONBLOCK); flags = fcntl(sd2, F_GETFL, 0); TEST_ASSERT_TRUE(flags >= 0); - TEST_ASSERT_EQUAL(O_RDWR, flags & O_ACCMODE); + TEST_ASSERT_EQUAL(O_RDWR, flags & O_RDWR); TEST_ASSERT_EQUAL(0, flags & O_NONBLOCK); ret = fcntl(sd2, F_SETFL, flags | O_NONBLOCK); TEST_ASSERT_EQUAL(0, ret); flags = fcntl(sd2, F_GETFL, 0); TEST_ASSERT_TRUE(flags >= 0); - TEST_ASSERT_EQUAL(O_RDWR, flags & O_ACCMODE); + TEST_ASSERT_EQUAL(O_RDWR, flags & O_RDWR); TEST_ASSERT_EQUAL(O_NONBLOCK, flags & O_NONBLOCK); /* Launch connect attempt, daemon delays actual connection until @@ -758,13 +755,13 @@ TEST(no_block_connect, basic_daemon_dup2) flags = fcntl(sd, F_GETFL, 0); TEST_ASSERT_TRUE(flags >= 0); - TEST_ASSERT_EQUAL(O_RDWR, flags & O_ACCMODE); + TEST_ASSERT_EQUAL(O_RDWR, flags & O_RDWR); TEST_ASSERT_EQUAL(0, flags & O_NONBLOCK); ret = fcntl(sd, F_SETFL, flags | O_NONBLOCK); TEST_ASSERT_EQUAL(0, ret); flags = fcntl(sd, F_GETFL, 0); TEST_ASSERT_TRUE(flags >= 0); - TEST_ASSERT_EQUAL(O_RDWR, flags & O_ACCMODE); + TEST_ASSERT_EQUAL(O_RDWR, flags & O_RDWR); TEST_ASSERT_EQUAL(O_NONBLOCK, flags & O_NONBLOCK); /* Launch connect attempt, daemon delays actual connection until diff --git a/examples/usrsocktest/usrsocktest_noblock_recv.c b/examples/usrsocktest/usrsocktest_noblock_recv.c index ffacefde3..585843fe1 100644 --- a/examples/usrsocktest/usrsocktest_noblock_recv.c +++ b/examples/usrsocktest/usrsocktest_noblock_recv.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/usrsocktest/usrsocktest_noblock_recv.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -30,7 +28,6 @@ #include <stdbool.h> #include <assert.h> #include <fcntl.h> -#include <unistd.h> #include <netinet/in.h> #include <arpa/inet.h> @@ -114,13 +111,13 @@ static void receive(struct usrsocktest_daemon_conf_s *dconf) flags = fcntl(sd, F_GETFL, 0); TEST_ASSERT_TRUE(flags >= 0); - TEST_ASSERT_EQUAL(O_RDWR, flags & O_ACCMODE); + TEST_ASSERT_EQUAL(O_RDWR, flags & O_RDWR); TEST_ASSERT_EQUAL(0, flags & O_NONBLOCK); ret = fcntl(sd, F_SETFL, flags | O_NONBLOCK); TEST_ASSERT_EQUAL(0, ret); flags = fcntl(sd, F_GETFL, 0); TEST_ASSERT_TRUE(flags >= 0); - TEST_ASSERT_EQUAL(O_RDWR, flags & O_ACCMODE); + TEST_ASSERT_EQUAL(O_RDWR, flags & O_RDWR); TEST_ASSERT_EQUAL(O_NONBLOCK, flags & O_NONBLOCK); /* Do connect, should succeed instantly. */ @@ -183,8 +180,7 @@ static void receive(struct usrsocktest_daemon_conf_s *dconf) TEST_ASSERT_EQUAL(3, ret); TEST_ASSERT_EQUAL_UINT8_ARRAY("abc", data, 3); TEST_ASSERT_EQUAL(addrlen, sizeof(remoteaddr)); - TEST_ASSERT_EQUAL_UINT8_ARRAY(&remoteaddr, &addr, - addrlen - sizeof(addr.sin_zero)); + TEST_ASSERT_EQUAL_UINT8_ARRAY(&remoteaddr, &addr, addrlen); TEST_ASSERT_EQUAL(1, usrsocktest_daemon_get_num_connected_sockets()); TEST_ASSERT_EQUAL(1, usrsocktest_daemon_get_num_active_sockets()); TEST_ASSERT_EQUAL(datalen + ret, usrsocktest_daemon_get_recv_bytes()); @@ -310,13 +306,13 @@ static void delayed_connect(struct usrsocktest_daemon_conf_s *dconf) flags = fcntl(sd, F_GETFL, 0); TEST_ASSERT_TRUE(flags >= 0); - TEST_ASSERT_EQUAL(O_RDWR, flags & O_ACCMODE); + TEST_ASSERT_EQUAL(O_RDWR, flags & O_RDWR); TEST_ASSERT_EQUAL(0, flags & O_NONBLOCK); ret = fcntl(sd, F_SETFL, flags | O_NONBLOCK); TEST_ASSERT_EQUAL(0, ret); flags = fcntl(sd, F_GETFL, 0); TEST_ASSERT_TRUE(flags >= 0); - TEST_ASSERT_EQUAL(O_RDWR, flags & O_ACCMODE); + TEST_ASSERT_EQUAL(O_RDWR, flags & O_RDWR); TEST_ASSERT_EQUAL(O_NONBLOCK, flags & O_NONBLOCK); /* Launch connect attempt, daemon delays actual connection until @@ -369,7 +365,7 @@ static void delayed_connect(struct usrsocktest_daemon_conf_s *dconf) &addrlen); TEST_ASSERT_EQUAL(-1, ret); TEST_ASSERT_EQUAL(EAGAIN, errno); - TEST_ASSERT_EQUAL(sizeof(remoteaddr), addrlen); + TEST_ASSERT_EQUAL(0, addrlen); TEST_ASSERT_EQUAL(1, usrsocktest_daemon_get_num_connected_sockets()); TEST_ASSERT_EQUAL(1, usrsocktest_daemon_get_num_active_sockets()); TEST_ASSERT_EQUAL(0, usrsocktest_daemon_get_send_bytes()); @@ -463,17 +459,17 @@ TEST_SETUP(no_block_recv) TEST_TEAR_DOWN(no_block_recv) { - int unused_data ret; + int ret; if (sd >= 0) { ret = close(sd); - TEST_ASSERT_TRUE(ret >= 0); + assert(ret >= 0); } if (started) { ret = usrsocktest_daemon_stop(); - TEST_ASSERT_EQUAL(ret, OK); + assert(ret == OK); } } diff --git a/examples/usrsocktest/usrsocktest_noblock_send.c b/examples/usrsocktest/usrsocktest_noblock_send.c index 8526c29b2..9c3d4a40d 100644 --- a/examples/usrsocktest/usrsocktest_noblock_send.c +++ b/examples/usrsocktest/usrsocktest_noblock_send.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/usrsocktest/usrsocktest_noblock_send.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -33,7 +31,6 @@ #include <netinet/in.h> #include <arpa/inet.h> #include <string.h> -#include <unistd.h> #include "defines.h" @@ -110,13 +107,13 @@ static void _send(struct usrsocktest_daemon_conf_s *dconf) flags = fcntl(sd, F_GETFL, 0); TEST_ASSERT_TRUE(flags >= 0); - TEST_ASSERT_EQUAL(O_RDWR, flags & O_ACCMODE); + TEST_ASSERT_EQUAL(O_RDWR, flags & O_RDWR); TEST_ASSERT_EQUAL(0, flags & O_NONBLOCK); ret = fcntl(sd, F_SETFL, flags | O_NONBLOCK); TEST_ASSERT_EQUAL(0, ret); flags = fcntl(sd, F_GETFL, 0); TEST_ASSERT_TRUE(flags >= 0); - TEST_ASSERT_EQUAL(O_RDWR, flags & O_ACCMODE); + TEST_ASSERT_EQUAL(O_RDWR, flags & O_RDWR); TEST_ASSERT_EQUAL(O_NONBLOCK, flags & O_NONBLOCK); /* Do connect, should succeed instantly. */ @@ -231,13 +228,13 @@ static void connect_send(struct usrsocktest_daemon_conf_s *dconf) flags = fcntl(sd, F_GETFL, 0); TEST_ASSERT_TRUE(flags >= 0); - TEST_ASSERT_EQUAL(O_RDWR, flags & O_ACCMODE); + TEST_ASSERT_EQUAL(O_RDWR, flags & O_RDWR); TEST_ASSERT_EQUAL(0, flags & O_NONBLOCK); ret = fcntl(sd, F_SETFL, flags | O_NONBLOCK); TEST_ASSERT_EQUAL(0, ret); flags = fcntl(sd, F_GETFL, 0); TEST_ASSERT_TRUE(flags >= 0); - TEST_ASSERT_EQUAL(O_RDWR, flags & O_ACCMODE); + TEST_ASSERT_EQUAL(O_RDWR, flags & O_RDWR); TEST_ASSERT_EQUAL(O_NONBLOCK, flags & O_NONBLOCK); /* Launch connect attempt, daemon delays actual connection until @@ -353,17 +350,17 @@ TEST_SETUP(no_block_send) TEST_TEAR_DOWN(no_block_send) { - int unused_data ret; + int ret; if (sd >= 0) { ret = close(sd); - TEST_ASSERT_TRUE(ret >= 0); + assert(ret >= 0); } if (started) { ret = usrsocktest_daemon_stop(); - TEST_ASSERT_EQUAL(ret, OK); + assert(ret == OK); } } diff --git a/examples/usrsocktest/usrsocktest_nodaemon.c b/examples/usrsocktest/usrsocktest_nodaemon.c index 59c58465b..ca10ec6bc 100644 --- a/examples/usrsocktest/usrsocktest_nodaemon.c +++ b/examples/usrsocktest/usrsocktest_nodaemon.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/usrsocktest/usrsocktest_nodaemon.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -26,7 +24,6 @@ #include <sys/socket.h> #include <errno.h> -#include <unistd.h> #include "defines.h" @@ -97,12 +94,12 @@ TEST_SETUP(no_daemon) TEST_TEAR_DOWN(no_daemon) { - int unused_data ret; + int ret; if (sd >= 0) { ret = close(sd); - TEST_ASSERT_TRUE(ret >= 0); + assert(ret >= 0); } } diff --git a/examples/usrsocktest/usrsocktest_poll.c b/examples/usrsocktest/usrsocktest_poll.c index 66cda8aa6..85b1df382 100644 --- a/examples/usrsocktest/usrsocktest_poll.c +++ b/examples/usrsocktest/usrsocktest_poll.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/usrsocktest/usrsocktest_poll.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -34,7 +32,6 @@ #include <netinet/in.h> #include <arpa/inet.h> #include <string.h> -#include <unistd.h> #include "defines.h" @@ -115,13 +112,13 @@ static void connectreceive(struct usrsocktest_daemon_conf_s *dconf) flags = fcntl(sd, F_GETFL, 0); TEST_ASSERT_TRUE(flags >= 0); - TEST_ASSERT_EQUAL(O_RDWR, flags & O_ACCMODE); + TEST_ASSERT_EQUAL(O_RDWR, flags & O_RDWR); TEST_ASSERT_EQUAL(0, flags & O_NONBLOCK); ret = fcntl(sd, F_SETFL, flags | O_NONBLOCK); TEST_ASSERT_EQUAL(0, ret); flags = fcntl(sd, F_GETFL, 0); TEST_ASSERT_TRUE(flags >= 0); - TEST_ASSERT_EQUAL(O_RDWR, flags & O_ACCMODE); + TEST_ASSERT_EQUAL(O_RDWR, flags & O_RDWR); TEST_ASSERT_EQUAL(O_NONBLOCK, flags & O_NONBLOCK); /* poll for input (instant timeout). */ @@ -321,13 +318,13 @@ static void connectsend(struct usrsocktest_daemon_conf_s *dconf) flags = fcntl(sd, F_GETFL, 0); TEST_ASSERT_TRUE(flags >= 0); - TEST_ASSERT_EQUAL(O_RDWR, flags & O_ACCMODE); + TEST_ASSERT_EQUAL(O_RDWR, flags & O_RDWR); TEST_ASSERT_EQUAL(0, flags & O_NONBLOCK); ret = fcntl(sd, F_SETFL, flags | O_NONBLOCK); TEST_ASSERT_EQUAL(0, ret); flags = fcntl(sd, F_GETFL, 0); TEST_ASSERT_TRUE(flags >= 0); - TEST_ASSERT_EQUAL(O_RDWR, flags & O_ACCMODE); + TEST_ASSERT_EQUAL(O_RDWR, flags & O_RDWR); TEST_ASSERT_EQUAL(O_NONBLOCK, flags & O_NONBLOCK); /* poll for input (instant timeout). */ @@ -454,13 +451,13 @@ static void daemonabort(struct usrsocktest_daemon_conf_s *dconf) flags = fcntl(sd, F_GETFL, 0); TEST_ASSERT_TRUE(flags >= 0); - TEST_ASSERT_EQUAL(O_RDWR, flags & O_ACCMODE); + TEST_ASSERT_EQUAL(O_RDWR, flags & O_RDWR); TEST_ASSERT_EQUAL(0, flags & O_NONBLOCK); ret = fcntl(sd, F_SETFL, flags | O_NONBLOCK); TEST_ASSERT_EQUAL(0, ret); flags = fcntl(sd, F_GETFL, 0); TEST_ASSERT_TRUE(flags >= 0); - TEST_ASSERT_EQUAL(O_RDWR, flags & O_ACCMODE); + TEST_ASSERT_EQUAL(O_RDWR, flags & O_RDWR); TEST_ASSERT_EQUAL(O_NONBLOCK, flags & O_NONBLOCK); /* poll for input (instant timeout). */ @@ -572,17 +569,17 @@ TEST_SETUP(poll) TEST_TEAR_DOWN(poll) { - int unused_data ret; + int ret; if (sd >= 0) { ret = close(sd); - TEST_ASSERT_TRUE(ret >= 0); + assert(ret >= 0); } if (started) { ret = usrsocktest_daemon_stop(); - TEST_ASSERT_EQUAL(ret, OK); + assert(ret == OK); } } diff --git a/examples/usrsocktest/usrsocktest_remote_disconnect.c b/examples/usrsocktest/usrsocktest_remote_disconnect.c index a49acc03f..740096d25 100644 --- a/examples/usrsocktest/usrsocktest_remote_disconnect.c +++ b/examples/usrsocktest/usrsocktest_remote_disconnect.c @@ -1,7 +1,5 @@ /**************************************************************************** - * apps/examples/usrsocktest/usrsocktest_remote_disconnect.c - * - * SPDX-License-Identifier: Apache-2.0 + * apps/usrsocktest/usrsocktest_remote_disconnect.c * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -34,7 +32,6 @@ #include <netinet/in.h> #include <arpa/inet.h> #include <string.h> -#include <unistd.h> #include "defines.h" @@ -151,13 +148,13 @@ static void unreachable(struct usrsocktest_daemon_conf_s *dconf) flags = fcntl(sd, F_GETFL, 0); TEST_ASSERT_TRUE(flags >= 0); - TEST_ASSERT_EQUAL(O_RDWR, flags & O_ACCMODE); + TEST_ASSERT_EQUAL(O_RDWR, flags & O_RDWR); TEST_ASSERT_EQUAL(0, flags & O_NONBLOCK); ret = fcntl(sd, F_SETFL, flags | O_NONBLOCK); TEST_ASSERT_EQUAL(0, ret); flags = fcntl(sd, F_GETFL, 0); TEST_ASSERT_TRUE(flags >= 0); - TEST_ASSERT_EQUAL(O_RDWR, flags & O_ACCMODE); + TEST_ASSERT_EQUAL(O_RDWR, flags & O_RDWR); TEST_ASSERT_EQUAL(O_NONBLOCK, flags & O_NONBLOCK); /* Try connect, connection in progress. */ @@ -670,13 +667,13 @@ static void remote_disconnect_poll(struct usrsocktest_daemon_conf_s *dconf) flags = fcntl(sd, F_GETFL, 0); TEST_ASSERT_TRUE(flags >= 0); - TEST_ASSERT_EQUAL(O_RDWR, flags & O_ACCMODE); + TEST_ASSERT_EQUAL(O_RDWR, flags & O_RDWR); TEST_ASSERT_EQUAL(0, flags & O_NONBLOCK); ret = fcntl(sd, F_SETFL, flags | O_NONBLOCK); TEST_ASSERT_EQUAL(0, ret); flags = fcntl(sd, F_GETFL, 0); TEST_ASSERT_TRUE(flags >= 0); - TEST_ASSERT_EQUAL(O_RDWR, flags & O_ACCMODE); + TEST_ASSERT_EQUAL(O_RDWR, flags & O_RDWR); TEST_ASSERT_EQUAL(O_NONBLOCK, flags & O_NONBLOCK); /* Poll for input (instant timeout). */ @@ -797,13 +794,13 @@ static void remote_disconnect_poll2(struct usrsocktest_daemon_conf_s *dconf) flags = fcntl(sd, F_GETFL, 0); TEST_ASSERT_TRUE(flags >= 0); - TEST_ASSERT_EQUAL(O_RDWR, flags & O_ACCMODE); + TEST_ASSERT_EQUAL(O_RDWR, flags & O_RDWR); TEST_ASSERT_EQUAL(0, flags & O_NONBLOCK); ret = fcntl(sd, F_SETFL, flags | O_NONBLOCK); TEST_ASSERT_EQUAL(0, ret); flags = fcntl(sd, F_GETFL, 0); TEST_ASSERT_TRUE(flags >= 0); - TEST_ASSERT_EQUAL(O_RDWR, flags & O_ACCMODE); + TEST_ASSERT_EQUAL(O_RDWR, flags & O_RDWR); TEST_ASSERT_EQUAL(O_NONBLOCK, flags & O_NONBLOCK); /* Poll for input (instant timeout). */ @@ -871,6 +868,7 @@ static void remote_disconnect_poll2(struct usrsocktest_daemon_conf_s *dconf) TEST_ASSERT_EQUAL(1, ret); TEST_ASSERT_EQUAL(0, pfd.revents & POLLERR); TEST_ASSERT_EQUAL(POLLHUP, pfd.revents & POLLHUP); + TEST_ASSERT_EQUAL(*events & POLLIN, pfd.revents & POLLIN); TEST_ASSERT_EQUAL(0, pfd.revents & POLLOUT); TEST_ASSERT_EQUAL(1, usrsocktest_daemon_get_num_active_sockets()); TEST_ASSERT_EQUAL(0, usrsocktest_daemon_get_num_connected_sockets()); @@ -973,18 +971,18 @@ TEST_SETUP(remote_disconnect) TEST_TEAR_DOWN(remote_disconnect) { - int unused_data ret; + int ret; if (sd >= 0) { ret = close(sd); - TEST_ASSERT_TRUE(ret >= 0); + assert(ret >= 0); } if (started) { ret = usrsocktest_daemon_stop(); - TEST_ASSERT_EQUAL(ret, OK); + assert(ret == OK); } } diff --git a/examples/usrsocktest/usrsocktest_wake_with_signal.c b/examples/usrsocktest/usrsocktest_wake_with_signal.c index da460ab15..438ed934d 100644 --- a/examples/usrsocktest/usrsocktest_wake_with_signal.c +++ b/examples/usrsocktest/usrsocktest_wake_with_signal.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/usrsocktest/usrsocktest_wake_with_signal.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -30,9 +28,6 @@ #include <arpa/inet.h> #include <errno.h> #include <poll.h> -#include <unistd.h> - -#include <nuttx/clock.h> #include "defines.h" @@ -40,6 +35,10 @@ * Pre-processor Definitions ****************************************************************************/ +#ifndef ARRAY_SIZE +# define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) +#endif + #define TEST_FLAG_PAUSE_USRSOCK_HANDLING (1 << 0) #define TEST_FLAG_DAEMON_ABORT (1 << 1) #define TEST_FLAG_MULTI_THREAD (1 << 2) @@ -146,20 +145,11 @@ static void do_usrsock_blocking_socket_thread(FAR void *param) TEST_ASSERT_TRUE(test_hang); TEST_ASSERT_TRUE(test_abort); -#ifdef CONFIG_DISABLE_ALL_SIGNALS - pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); - pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL); -#endif - /* Allow main thread to hang usrsock daemon at this point. */ sem_post(&tid_startsem); sem_wait(&tid_releasesem); -#ifdef CONFIG_DISABLE_ALL_SIGNALS - pthread_testcancel(); -#endif - /* Attempt hanging open socket. */ sem_post(&tid_startsem); @@ -168,7 +158,7 @@ static void do_usrsock_blocking_socket_thread(FAR void *param) TEST_ASSERT_EQUAL(ENETDOWN, errno); } -static FAR void *usrsock_blocking_socket_thread(FAR void *param) +static FAR void * usrsock_blocking_socket_thread(FAR void *param) { do_usrsock_blocking_socket_thread(param); return NULL; @@ -185,11 +175,6 @@ static void do_usrsock_blocking_close_thread(FAR void *param) TEST_ASSERT_TRUE(test_hang); TEST_ASSERT_TRUE(test_abort); -#ifdef CONFIG_DISABLE_ALL_SIGNALS - pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); - pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL); -#endif - /* Open socket. */ test_sd[tidx] = socket(AF_INET, SOCK_STREAM, 0); @@ -204,10 +189,6 @@ static void do_usrsock_blocking_close_thread(FAR void *param) sem_post(&tid_startsem); sem_wait(&tid_releasesem); -#ifdef CONFIG_DISABLE_ALL_SIGNALS - pthread_testcancel(); -#endif - /* Attempt hanging close socket. */ sem_post(&tid_startsem); @@ -216,7 +197,7 @@ static void do_usrsock_blocking_close_thread(FAR void *param) test_sd[tidx] = -1; } -static FAR void *usrsock_blocking_close_thread(FAR void *param) +static FAR void * usrsock_blocking_close_thread(FAR void *param) { do_usrsock_blocking_close_thread(param); return NULL; @@ -232,11 +213,6 @@ static void do_usrsock_blocking_connect_thread(FAR void *param) TEST_ASSERT_TRUE(test_hang || !test_hang); -#ifdef CONFIG_DISABLE_ALL_SIGNALS - pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); - pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL); -#endif - /* Open socket. */ test_sd[tidx] = socket(AF_INET, SOCK_STREAM, 0); @@ -251,10 +227,6 @@ static void do_usrsock_blocking_connect_thread(FAR void *param) sem_post(&tid_startsem); sem_wait(&tid_releasesem); -#ifdef CONFIG_DISABLE_ALL_SIGNALS - pthread_testcancel(); -#endif - /* Attempt blocking connect. */ sem_post(&tid_startsem); @@ -269,7 +241,7 @@ static void do_usrsock_blocking_connect_thread(FAR void *param) test_sd[tidx] = -1; } -static FAR void *usrsock_blocking_connect_thread(FAR void *param) +static FAR void * usrsock_blocking_connect_thread(FAR void *param) { do_usrsock_blocking_connect_thread(param); return NULL; @@ -284,11 +256,6 @@ static void do_usrsock_blocking_setsockopt_thread(FAR void *param) bool test_abort = !!(test_flags & TEST_FLAG_DAEMON_ABORT); bool test_hang = !!(test_flags & TEST_FLAG_PAUSE_USRSOCK_HANDLING); -#ifdef CONFIG_DISABLE_ALL_SIGNALS - pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); - pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL); -#endif - /* Open socket. */ test_sd[tidx] = socket(AF_INET, SOCK_STREAM, 0); @@ -306,10 +273,6 @@ static void do_usrsock_blocking_setsockopt_thread(FAR void *param) sem_post(&tid_startsem); sem_wait(&tid_releasesem); -#ifdef CONFIG_DISABLE_ALL_SIGNALS - pthread_testcancel(); -#endif - /* Attempt hanging setsockopt. */ sem_post(&tid_startsem); @@ -324,7 +287,7 @@ static void do_usrsock_blocking_setsockopt_thread(FAR void *param) test_sd[tidx] = -1; } -static FAR void *usrsock_blocking_setsockopt_thread(FAR void *param) +static FAR void * usrsock_blocking_setsockopt_thread(FAR void *param) { do_usrsock_blocking_setsockopt_thread(param); return NULL; @@ -340,11 +303,6 @@ static void do_usrsock_blocking_getsockopt_thread(FAR void *param) bool test_abort = !!(test_flags & TEST_FLAG_DAEMON_ABORT); bool test_hang = !!(test_flags & TEST_FLAG_PAUSE_USRSOCK_HANDLING); -#ifdef CONFIG_DISABLE_ALL_SIGNALS - pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); - pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL); -#endif - /* Open socket. */ test_sd[tidx] = socket(AF_INET, SOCK_STREAM, 0); @@ -362,10 +320,6 @@ static void do_usrsock_blocking_getsockopt_thread(FAR void *param) sem_post(&tid_startsem); sem_wait(&tid_releasesem); -#ifdef CONFIG_DISABLE_ALL_SIGNALS - pthread_testcancel(); -#endif - /* Attempt hanging getsockopt. */ sem_post(&tid_startsem); @@ -381,7 +335,7 @@ static void do_usrsock_blocking_getsockopt_thread(FAR void *param) test_sd[tidx] = -1; } -static FAR void *usrsock_blocking_getsockopt_thread(FAR void *param) +static FAR void * usrsock_blocking_getsockopt_thread(FAR void *param) { do_usrsock_blocking_getsockopt_thread(param); return NULL; @@ -397,11 +351,6 @@ static void do_usrsock_blocking_send_thread(FAR void *param) TEST_ASSERT_TRUE(test_hang || !test_hang); -#ifdef CONFIG_DISABLE_ALL_SIGNALS - pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); - pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL); -#endif - /* Open socket. */ test_sd[tidx] = socket(AF_INET, SOCK_STREAM, 0); @@ -422,10 +371,6 @@ static void do_usrsock_blocking_send_thread(FAR void *param) sem_post(&tid_startsem); sem_wait(&tid_releasesem); -#ifdef CONFIG_DISABLE_ALL_SIGNALS - pthread_testcancel(); -#endif - /* Attempt blocking send. */ sem_post(&tid_startsem); @@ -439,7 +384,7 @@ static void do_usrsock_blocking_send_thread(FAR void *param) test_sd[tidx] = -1; } -static FAR void *usrsock_blocking_send_thread(FAR void *param) +static FAR void * usrsock_blocking_send_thread(FAR void *param) { do_usrsock_blocking_send_thread(param); return NULL; @@ -455,11 +400,6 @@ static void do_usrsock_blocking_recv_thread(FAR void *param) TEST_ASSERT_TRUE(test_hang || !test_hang); -#ifdef CONFIG_DISABLE_ALL_SIGNALS - pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); - pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL); -#endif - /* Open socket. */ test_sd[tidx] = socket(AF_INET, SOCK_STREAM, 0); @@ -480,10 +420,6 @@ static void do_usrsock_blocking_recv_thread(FAR void *param) sem_post(&tid_startsem); sem_wait(&tid_releasesem); -#ifdef CONFIG_DISABLE_ALL_SIGNALS - pthread_testcancel(); -#endif - /* Attempt blocking recv. */ sem_post(&tid_startsem); @@ -497,7 +433,7 @@ static void do_usrsock_blocking_recv_thread(FAR void *param) test_sd[tidx] = -1; } -static FAR void *usrsock_blocking_recv_thread(FAR void *param) +static FAR void * usrsock_blocking_recv_thread(FAR void *param) { do_usrsock_blocking_recv_thread(param); return NULL; @@ -517,11 +453,6 @@ static void do_usrsock_blocking_poll_thread(FAR void *param) TEST_ASSERT_TRUE(test_abort); TEST_ASSERT_TRUE(test_hang || !test_hang); -#ifdef CONFIG_DISABLE_ALL_SIGNALS - pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); - pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL); -#endif - /* Open socket. */ test_sd[tidx] = socket(AF_INET, SOCK_STREAM, 0); @@ -542,10 +473,6 @@ static void do_usrsock_blocking_poll_thread(FAR void *param) sem_post(&tid_startsem); sem_wait(&tid_releasesem); -#ifdef CONFIG_DISABLE_ALL_SIGNALS - pthread_testcancel(); -#endif - /* Attempt poll. */ pfd.fd = test_sd[tidx]; @@ -568,7 +495,7 @@ static void do_usrsock_blocking_poll_thread(FAR void *param) test_sd[tidx] = -1; } -static FAR void *usrsock_blocking_poll_thread(FAR void *param) +static FAR void * usrsock_blocking_poll_thread(FAR void *param) { do_usrsock_blocking_poll_thread(param); return NULL; @@ -632,11 +559,8 @@ static void do_wake_test(enum e_test_type type, int flags) for (tidx = 0; tidx < nthreads; tidx++) { -#ifdef CONFIG_DISABLE_ALL_SIGNALS - pthread_cancel(tid[tidx]); -#else - pthread_kill(tid[tidx], SIGUSR1); -#endif + pthread_kill(tid[tidx], 1); + /* Wait threads to complete work. */ ret = pthread_join(tid[tidx], NULL); @@ -725,7 +649,7 @@ TEST_SETUP(wake_with_signal) TEST_TEAR_DOWN(wake_with_signal) { - int unused_data ret; + int ret; int i; for (i = 0; i < MAX_THREADS; i++) @@ -733,9 +657,9 @@ TEST_TEAR_DOWN(wake_with_signal) if (tid[i] != -1) { ret = pthread_cancel(tid[i]); - TEST_ASSERT_EQUAL(ret, OK); + assert(ret == OK); ret = pthread_join(tid[i], NULL); - TEST_ASSERT_EQUAL(ret, OK); + assert(ret == OK); } if (test_sd[i] != -1) diff --git a/examples/ustream/CMakeLists.txt b/examples/ustream/CMakeLists.txt deleted file mode 100644 index 262c4770a..000000000 --- a/examples/ustream/CMakeLists.txt +++ /dev/null @@ -1,43 +0,0 @@ -# ############################################################################## -# apps/examples/ustream/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_USTREAM) - nuttx_add_application( - NAME - client - STACKSIZE - ${CONFIG_DEFAULT_TASK_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_USTREAM} - SRCS - ustream_client.c) - - nuttx_add_application( - NAME - server - STACKSIZE - ${CONFIG_DEFAULT_TASK_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_AJOYSTICK} - SRCS - ustream_server.c) -endif() diff --git a/examples/ustream/Make.defs b/examples/ustream/Make.defs index ec06c89a0..4cf4021f3 100644 --- a/examples/ustream/Make.defs +++ b/examples/ustream/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/ustream/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/ustream/Makefile b/examples/ustream/Makefile index 5be3c8686..16206b214 100644 --- a/examples/ustream/Makefile +++ b/examples/ustream/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/ustream/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/ustream/ustream.h b/examples/ustream/ustream.h index 193fa0551..f74bf48f4 100644 --- a/examples/ustream/ustream.h +++ b/examples/ustream/ustream.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/ustream/ustream.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/ustream/ustream_client.c b/examples/ustream/ustream_client.c index a80e185aa..fb92c9af1 100644 --- a/examples/ustream/ustream_client.c +++ b/examples/ustream/ustream_client.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/ustream/ustream_client.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -61,8 +59,8 @@ int main(int argc, FAR char *argv[]) /* Allocate buffers */ - outbuf = (FAR char *)malloc(SENDSIZE); - inbuf = (FAR char *)malloc(SENDSIZE); + outbuf = (char*)malloc(SENDSIZE); + inbuf = (char*)malloc(SENDSIZE); if (!outbuf || !inbuf) { printf("client: failed to allocate buffers\n"); @@ -80,18 +78,19 @@ int main(int argc, FAR char *argv[]) /* Connect the socket to the server */ - addrlen = sizeof(CONFIG_EXAMPLES_USTREAM_ADDR); - if (addrlen > UNIX_PATH_MAX) + addrlen = strlen(CONFIG_EXAMPLES_USTREAM_ADDR); + if (addrlen > UNIX_PATH_MAX - 1) { - addrlen = UNIX_PATH_MAX; + addrlen = UNIX_PATH_MAX - 1; } myaddr.sun_family = AF_LOCAL; - strlcpy(myaddr.sun_path, CONFIG_EXAMPLES_USTREAM_ADDR, addrlen); + strncpy(myaddr.sun_path, CONFIG_EXAMPLES_USTREAM_ADDR, addrlen); + myaddr.sun_path[addrlen] = '\0'; printf("client: Connecting to %s...\n", CONFIG_EXAMPLES_USTREAM_ADDR); - addrlen += sizeof(sa_family_t); - ret = connect(sockfd, (struct sockaddr *)&myaddr, addrlen); + addrlen += sizeof(sa_family_t) + 1; + ret = connect( sockfd, (struct sockaddr *)&myaddr, addrlen); if (ret < 0) { printf("client: connect failure: %d\n", errno); @@ -148,8 +147,7 @@ int main(int argc, FAR char *argv[]) } else if (nbytessent != SENDSIZE) { - printf("client: Bad send length: %d Expected: %d\n", - nbytessent, SENDSIZE); + printf("client: Bad send length: %d Expected: %d\n", nbytessent, SENDSIZE); goto errout_with_socket; } @@ -180,8 +178,7 @@ int main(int argc, FAR char *argv[]) #endif printf("client: Receiving...\n"); - nbytesrecvd = recv(sockfd, &inbuf[totalbytesrecvd], - SENDSIZE - totalbytesrecvd, 0); + nbytesrecvd = recv(sockfd, &inbuf[totalbytesrecvd], SENDSIZE - totalbytesrecvd, 0); if (nbytesrecvd < 0) { @@ -201,8 +198,7 @@ int main(int argc, FAR char *argv[]) if (totalbytesrecvd != SENDSIZE) { - printf("client: Bad recv length: %d Expected: %d\n", - totalbytesrecvd, SENDSIZE); + printf("client: Bad recv length: %d Expected: %d\n", totalbytesrecvd, SENDSIZE); goto errout_with_socket; } else if (memcmp(inbuf, outbuf, SENDSIZE) != 0) diff --git a/examples/ustream/ustream_server.c b/examples/ustream/ustream_server.c index a14c39574..e35c831fe 100644 --- a/examples/ustream/ustream_server.c +++ b/examples/ustream/ustream_server.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/ustream/ustream_server.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -43,14 +41,14 @@ * Public Functions ****************************************************************************/ -int main(int argc, char *argv[]) +int main(int argc, FAR char *argv[]) { #ifdef CONFIG_EXAMPLES_USTREAM_USE_POLL struct pollfd pfd; #endif struct sockaddr_un myaddr; socklen_t addrlen; - char *buffer; + FAR char *buffer; int listensd; int acceptsd; int nbytesread; @@ -62,7 +60,7 @@ int main(int argc, char *argv[]) /* Allocate a BIG buffer */ - buffer = (char *)malloc(2 * SENDSIZE); + buffer = (char*)malloc(2*SENDSIZE); if (!buffer) { printf("server: failed to allocate buffer\n"); @@ -80,17 +78,18 @@ int main(int argc, char *argv[]) /* Bind the socket to a local address */ - addrlen = sizeof(CONFIG_EXAMPLES_USTREAM_ADDR); - if (addrlen > UNIX_PATH_MAX) + addrlen = strlen(CONFIG_EXAMPLES_USTREAM_ADDR); + if (addrlen > UNIX_PATH_MAX - 1) { - addrlen = UNIX_PATH_MAX; + addrlen = UNIX_PATH_MAX - 1; } myaddr.sun_family = AF_LOCAL; - strlcpy(myaddr.sun_path, CONFIG_EXAMPLES_USTREAM_ADDR, addrlen); + strncpy(myaddr.sun_path, CONFIG_EXAMPLES_USTREAM_ADDR, addrlen); + myaddr.sun_path[addrlen] = '\0'; - addrlen += sizeof(sa_family_t); - ret = bind(listensd, (struct sockaddr *)&myaddr, addrlen); + addrlen += sizeof(sa_family_t) + 1; + ret = bind(listensd, (struct sockaddr*)&myaddr, addrlen); if (ret < 0) { printf("server: bind failure: %d\n", errno); @@ -99,8 +98,7 @@ int main(int argc, char *argv[]) /* Listen for connections on the bound socket */ - printf("server: Accepting connections on %s ...\n", - CONFIG_EXAMPLES_USTREAM_ADDR); + printf("server: Accepting connections on %s ...\n", CONFIG_EXAMPLES_USTREAM_ADDR); if (listen(listensd, 5) < 0) { @@ -133,8 +131,7 @@ int main(int argc, char *argv[]) } #endif - acceptsd = accept4(listensd, (struct sockaddr *)&myaddr, &addrlen, - SOCK_CLOEXEC); + acceptsd = accept(listensd, (struct sockaddr*)&myaddr, &addrlen); if (acceptsd < 0) { printf("server: accept failure: %d\n", errno); @@ -172,8 +169,7 @@ int main(int argc, char *argv[]) #endif printf("server: Reading...\n"); - nbytesread = recv(acceptsd, &buffer[totalbytesread], - 2 * SENDSIZE - totalbytesread, 0); + nbytesread = recv(acceptsd, &buffer[totalbytesread], 2*SENDSIZE - totalbytesread, 0); if (nbytesread < 0) { printf("server: recv failed: %d\n", errno); @@ -193,8 +189,7 @@ int main(int argc, char *argv[]) if (totalbytesread != SENDSIZE) { - printf("server: Received %d / Expected %d bytes\n", - totalbytesread, SENDSIZE); + printf("server: Received %d / Expected %d bytes\n", totalbytesread, SENDSIZE); goto errout_with_acceptsd; } @@ -203,8 +198,7 @@ int main(int argc, char *argv[]) { if (buffer[i] != ch) { - printf("server: Byte %d is %02x / Expected %02x\n", - i, buffer[i], ch); + printf("server: Byte %d is %02x / Expected %02x\n", i, buffer[i], ch); goto errout_with_acceptsd; } diff --git a/examples/uvc_cam/CMakeLists.txt b/examples/uvc_cam/CMakeLists.txt deleted file mode 100644 index 952fd3e4b..000000000 --- a/examples/uvc_cam/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# ############################################################################## -# apps/examples/uvc_cam/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_UVC_CAM) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_UVC_CAM_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_UVC_CAM_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_UVC_CAM_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_UVC_CAM} - SRCS - uvc_cam_main.c) -endif() diff --git a/examples/uvc_cam/Kconfig b/examples/uvc_cam/Kconfig deleted file mode 100644 index 83e6ca52d..000000000 --- a/examples/uvc_cam/Kconfig +++ /dev/null @@ -1,32 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config EXAMPLES_UVC_CAM - tristate "UVC Camera streaming example" - default n - depends on USBUVC && VIDEO - ---help--- - Captures frames from V4L2 camera and streams to USB host - via UVC gadget driver (/dev/uvc0). - -if EXAMPLES_UVC_CAM - -config EXAMPLES_UVC_CAM_PROGNAME - string "Program name" - default "uvc_cam" - -config EXAMPLES_UVC_CAM_PRIORITY - int "Task priority" - default 100 - -config EXAMPLES_UVC_CAM_STACKSIZE - int "Stack size" - default 4096 - -config EXAMPLES_UVC_CAM_NFRAMES - int "Number of frames (0=infinite)" - default 0 - -endif diff --git a/examples/uvc_cam/Make.defs b/examples/uvc_cam/Make.defs deleted file mode 100644 index 8a5c46a47..000000000 --- a/examples/uvc_cam/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/examples/uvc_cam/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_EXAMPLES_UVC_CAM),) -CONFIGURED_APPS += $(APPDIR)/examples/uvc_cam -endif diff --git a/examples/uvc_cam/Makefile b/examples/uvc_cam/Makefile deleted file mode 100644 index 409bc2494..000000000 --- a/examples/uvc_cam/Makefile +++ /dev/null @@ -1,34 +0,0 @@ -############################################################################ -# apps/examples/uvc_cam/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -# UVC Camera streaming application - -PROGNAME = $(CONFIG_EXAMPLES_UVC_CAM_PROGNAME) -PRIORITY = $(CONFIG_EXAMPLES_UVC_CAM_PRIORITY) -STACKSIZE = $(CONFIG_EXAMPLES_UVC_CAM_STACKSIZE) -MODULE = $(CONFIG_EXAMPLES_UVC_CAM) - -MAINSRC = uvc_cam_main.c - -include $(APPDIR)/Application.mk diff --git a/examples/uvc_cam/uvc_cam_main.c b/examples/uvc_cam/uvc_cam_main.c deleted file mode 100644 index a47d97e84..000000000 --- a/examples/uvc_cam/uvc_cam_main.c +++ /dev/null @@ -1,482 +0,0 @@ -/**************************************************************************** - * apps/examples/uvc_cam/uvc_cam_main.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * USB Video Class camera streaming application. - * Captures frames from V4L2 camera and streams to /dev/uvc0. - * - * Queries the sensor's native pixel format, resolution and frame rate - * via V4L2, then streams frames to the UVC gadget. - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <errno.h> -#include <fcntl.h> -#include <poll.h> -#include <unistd.h> -#include <sys/boardctl.h> -#include <sys/ioctl.h> -#include <sys/mman.h> - -#include <nuttx/video/video.h> -#include <nuttx/video/v4l2_cap.h> -#include <nuttx/usb/uvc.h> - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define UVC_DEV_DEFAULT "/dev/uvc0" -#define VIDEO_DEV_DEFAULT "/dev/video0" - -#ifndef CONFIG_EXAMPLES_UVC_CAM_NFRAMES -# define CONFIG_EXAMPLES_UVC_CAM_NFRAMES 0 /* 0 = infinite */ -#endif - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: pixfmt_to_bpp - * - * Description: - * Return bytes-per-pixel for common V4L2 pixel formats. - * - ****************************************************************************/ - -static int pixfmt_to_bpp(uint32_t pixfmt) -{ - switch (pixfmt) - { - case V4L2_PIX_FMT_YUYV: - case V4L2_PIX_FMT_RGB565: - return 2; - case V4L2_PIX_FMT_RGB24: - return 3; - default: - return 0; - } -} - -/**************************************************************************** - * Name: camera_init - * - * Description: - * Open and configure the V4L2 camera device. - * Queries the sensor's native pixel format, resolution and frame rate - * and returns them via output parameters. - * - ****************************************************************************/ - -static int camera_init(int fd, FAR uint32_t *pixfmt, FAR uint16_t *width, - FAR uint16_t *height, FAR uint16_t *fps) -{ - struct v4l2_fmtdesc fmtdesc; - struct v4l2_frmivalenum frmival; - struct v4l2_frmsizeenum frmsize; - struct v4l2_format fmt; - struct v4l2_requestbuffers req; - int ret; - - /* Query native pixel format from sensor */ - - memset(&fmtdesc, 0, sizeof(fmtdesc)); - fmtdesc.index = 0; - fmtdesc.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - - ret = ioctl(fd, VIDIOC_ENUM_FMT, &fmtdesc); - if (ret < 0) - { - printf("VIDIOC_ENUM_FMT failed: %d\n", errno); - return -errno; - } - - printf("Sensor format: %.4s\n", (FAR const char *)&fmtdesc.pixelformat); - - /* Query native resolution from sensor */ - - memset(&frmsize, 0, sizeof(frmsize)); - frmsize.index = 0; - frmsize.buf_type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - frmsize.pixel_format = fmtdesc.pixelformat; - - ret = ioctl(fd, VIDIOC_ENUM_FRAMESIZES, &frmsize); - if (ret < 0) - { - printf("VIDIOC_ENUM_FRAMESIZES failed: %d\n", errno); - return -errno; - } - - printf("Sensor native: %dx%d\n", - frmsize.discrete.width, frmsize.discrete.height); - - /* Set format โ€” capture at native resolution */ - - memset(&fmt, 0, sizeof(fmt)); - fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - fmt.fmt.pix.width = frmsize.discrete.width; - fmt.fmt.pix.height = frmsize.discrete.height; - fmt.fmt.pix.field = V4L2_FIELD_ANY; - fmt.fmt.pix.pixelformat = fmtdesc.pixelformat; - - ret = ioctl(fd, VIDIOC_S_FMT, &fmt); - if (ret < 0) - { - printf("VIDIOC_S_FMT failed: %d\n", errno); - return -errno; - } - - /* Request buffers โ€” match camcap: USERPTR + FIFO */ - - memset(&req, 0, sizeof(req)); - req.count = 1; - req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - req.memory = V4L2_MEMORY_USERPTR; - req.mode = V4L2_BUF_MODE_FIFO; - - ret = ioctl(fd, VIDIOC_REQBUFS, &req); - if (ret < 0) - { - printf("VIDIOC_REQBUFS failed: %d\n", errno); - return -errno; - } - - /* NOTE: Do NOT call VIDIOC_STREAMON here. - * With USERPTR + FIFO mode, STREAMON would start DMA capture - * immediately using the container's uninitialized userptr (0), - * causing DMA to write 153KB of video data to address 0 and - * corrupt memory. STREAMON must be called AFTER the first QBUF - * so that userptr points to a valid buffer. - */ - - /* Query frame interval from sensor */ - - memset(&frmival, 0, sizeof(frmival)); - frmival.index = 0; - frmival.buf_type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - frmival.pixel_format = fmtdesc.pixelformat; - frmival.width = frmsize.discrete.width; - frmival.height = frmsize.discrete.height; - - ret = ioctl(fd, VIDIOC_ENUM_FRAMEINTERVALS, &frmival); - if (ret < 0) - { - printf("VIDIOC_ENUM_FRAMEINTERVALS failed: %d\n", errno); - return -errno; - } - - *pixfmt = fmtdesc.pixelformat; - *width = frmsize.discrete.width; - *height = frmsize.discrete.height; - *fps = frmival.discrete.numerator > 0 - ? frmival.discrete.denominator / frmival.discrete.numerator - : 0; - return OK; -} - -/**************************************************************************** - * Name: camera_capture_frame - * - * Description: - * Capture one frame from V4L2 into the provided buffer. - * - ****************************************************************************/ - -static int camera_capture_frame(int camfd, FAR uint8_t *buf, size_t buflen, - bool do_streamon) -{ - struct v4l2_buffer vbuf; - int ret; - - memset(&vbuf, 0, sizeof(vbuf)); - vbuf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - vbuf.memory = V4L2_MEMORY_USERPTR; - vbuf.index = 0; - vbuf.m.userptr = (uintptr_t)buf; - vbuf.length = buflen; - - ret = ioctl(camfd, VIDIOC_QBUF, &vbuf); - if (ret < 0) - { - printf("VIDIOC_QBUF failed: %d\n", errno); - return -errno; - } - - /* Start streaming after the first QBUF so DMA has a valid buffer */ - - if (do_streamon) - { - enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - ret = ioctl(camfd, VIDIOC_STREAMON, &type); - if (ret < 0) - { - printf("VIDIOC_STREAMON failed: %d\n", errno); - return -errno; - } - } - - ret = ioctl(camfd, VIDIOC_DQBUF, &vbuf); - if (ret < 0) - { - printf("VIDIOC_DQBUF failed: %d\n", errno); - return -errno; - } - - return vbuf.bytesused > 0 ? (int)vbuf.bytesused : (int)buflen; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -int main(int argc, FAR char *argv[]) -{ - struct boardioc_usbdev_ctrl_s ctrl; - struct uvc_params_s uvc_params; - FAR void *uvc_handle = NULL; - FAR const char *video_dev = VIDEO_DEV_DEFAULT; - FAR const char *uvc_dev = UVC_DEV_DEFAULT; - FAR uint8_t *framebuf; - ssize_t written; - enum v4l2_buf_type cap_type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - uint32_t pixfmt = 0; - uint16_t width = 0; - uint16_t height = 0; - uint16_t fps = 0; - uint32_t frame_size; - int bpp; - int camfd; - int uvcfd; - int nframes; - int count = 0; - int ret; - - nframes = CONFIG_EXAMPLES_UVC_CAM_NFRAMES; - if (argc > 1) - { - nframes = atoi(argv[1]); - } - - if (argc > 2) - { - video_dev = argv[2]; - } - - if (argc > 3) - { - uvc_dev = argv[3]; - } - - /* Create capture device */ - - ret = capture_initialize(video_dev); - if (ret < 0 && ret != -EEXIST) - { - printf("Failed to initialize capture: %d\n", ret); - return EXIT_FAILURE; - } - - /* Open camera and query resolution */ - - camfd = open(video_dev, O_RDWR); - if (camfd < 0) - { - printf("Failed to open %s: %d\n", video_dev, errno); - return EXIT_FAILURE; - } - - ret = camera_init(camfd, &pixfmt, &width, &height, &fps); - if (ret < 0) - { - printf("Camera init failed: %d\n", ret); - close(camfd); - return EXIT_FAILURE; - } - - bpp = pixfmt_to_bpp(pixfmt); - if (bpp == 0) - { - printf("Unsupported pixel format: 0x%08lx\n", - (unsigned long)pixfmt); - close(camfd); - return EXIT_FAILURE; - } - - frame_size = (uint32_t)width * height * bpp; - printf("UVC Camera: %dx%d %.4s @%dfps, frames=%d (0=infinite)\n", - width, height, (FAR const char *)&pixfmt, fps, nframes); - - /* Allocate frame buffer โ€” 32-byte aligned for DMA (same as camcap) */ - - framebuf = memalign(32, frame_size); - if (!framebuf) - { - printf("Failed to allocate frame buffer (%lu bytes)\n", - (unsigned long)frame_size); - close(camfd); - return EXIT_FAILURE; - } - - /* Initialize and connect UVC gadget via boardctl. - * Pass video params queried from camera so USB descriptors - * match the actual sensor resolution. - */ - - uvc_params.width = width; - uvc_params.height = height; - uvc_params.fps = fps; - - uvc_handle = (FAR void *)&uvc_params; -#ifdef CONFIG_USBUVC_COMPOSITE - ctrl.usbdev = BOARDIOC_USBDEV_COMPOSITE; -#else - ctrl.usbdev = BOARDIOC_USBDEV_UVC; -#endif - ctrl.action = BOARDIOC_USBDEV_CONNECT; - ctrl.instance = 0; - ctrl.config = 0; - ctrl.handle = &uvc_handle; - - ret = boardctl(BOARDIOC_USBDEV_CONTROL, (uintptr_t)&ctrl); - - if (ret < 0) - { - printf("Failed to initialize UVC device: %d\n", ret); - close(camfd); - free(framebuf); - return EXIT_FAILURE; - } - - /* Open UVC device */ - - uvcfd = open(uvc_dev, O_WRONLY); - if (uvcfd < 0) - { - printf("Failed to open %s: %d\n", uvc_dev, errno); - ctrl.action = BOARDIOC_USBDEV_DISCONNECT; - boardctl(BOARDIOC_USBDEV_CONTROL, (uintptr_t)&ctrl); - close(camfd); - free(framebuf); - return EXIT_FAILURE; - } - - /* Wait for USB host to enumerate and start streaming */ - - struct pollfd pfd; - pfd.fd = uvcfd; - pfd.events = POLLOUT; - - printf("Waiting for USB host to connect...\n"); - while (poll(&pfd, 1, 500) <= 0 || !(pfd.revents & POLLOUT)) - { - } - - printf("Streaming started...\n"); - - /* Main capture-stream loop */ - - while (nframes == 0 || count < nframes) - { - ret = camera_capture_frame(camfd, framebuf, frame_size, - count == 0); - if (ret < 0) - { - printf("Capture failed: %d\n", ret); - break; - } - - /* Write frame to UVC directly from framebuf. - * DMA won't touch framebuf until next QBUF. - */ - - written = 0; - while (written < (ssize_t)frame_size) - { - ret = write(uvcfd, framebuf + written, - frame_size - written); - if (ret < 0) - { - if (errno == EAGAIN) - { - /* Host stopped streaming - wait for reconnect. - * - * NOTE: The printf inside the loop is required - * on boards where the USB-UART bridge (CH341) - * and the ESP32-S3 OTG share an on-board USB - * hub (e.g. lckfb-szpi). Continuous UART TX - * keeps the hub active and prevents the host - * from power-cycling the hub port, which would - * cause a full board POWERON reset. - */ - - printf("Host disconnected, waiting...\n"); - pfd.revents = 0; - while (poll(&pfd, 1, 500) <= 0 - || !(pfd.revents & POLLOUT)) - { - printf(".\n"); - } - - printf("Streaming restarted.\n"); - written = 0; - break; - } - - printf("UVC write failed: %d\n", errno); - goto out; - } - - written += ret; - } - - count++; - if ((count % 10) == 0) - { - printf("Streamed %d frames\n", count); - } - } - - printf("Done. Streamed %d frames total.\n", count); - -out: - ioctl(camfd, VIDIOC_STREAMOFF, &cap_type); - - close(uvcfd); - close(camfd); - - /* Disconnect UVC gadget */ - - ctrl.action = BOARDIOC_USBDEV_DISCONNECT; - boardctl(BOARDIOC_USBDEV_CONTROL, (uintptr_t)&ctrl); - - free(framebuf); - return EXIT_SUCCESS; -} diff --git a/examples/veml6070/CMakeLists.txt b/examples/veml6070/CMakeLists.txt deleted file mode 100644 index 2edc1015d..000000000 --- a/examples/veml6070/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# ############################################################################## -# apps/examples/veml6070/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_VEML6070) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_VEML6070_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_VEML6070_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_VEML6070_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_VEML6070} - SRCS - veml6070_main.c) -endif() diff --git a/examples/veml6070/Make.defs b/examples/veml6070/Make.defs index 4b4c59a9d..a2e051e40 100644 --- a/examples/veml6070/Make.defs +++ b/examples/veml6070/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/veml6070/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/veml6070/Makefile b/examples/veml6070/Makefile index 1a68781c3..32195bf72 100644 --- a/examples/veml6070/Makefile +++ b/examples/veml6070/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/veml6070/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/veml6070/veml6070_main.c b/examples/veml6070/veml6070_main.c index da5f23b32..facacce5e 100644 --- a/examples/veml6070/veml6070_main.c +++ b/examples/veml6070/veml6070_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/veml6070/veml6070_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/wamr_module/CMakeLists.txt b/examples/wamr_module/CMakeLists.txt deleted file mode 100644 index 8319424a6..000000000 --- a/examples/wamr_module/CMakeLists.txt +++ /dev/null @@ -1,29 +0,0 @@ -# ############################################################################## -# apps/examples/wamr_module/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_WAMR_MODULE) - - target_sources(apps PRIVATE module_hello.c) - - # register WAMR mod - nuttx_add_wamrmod(MODS hello) -endif() diff --git a/examples/wamr_module/Kconfig b/examples/wamr_module/Kconfig deleted file mode 100644 index 2f6e97aa5..000000000 --- a/examples/wamr_module/Kconfig +++ /dev/null @@ -1,11 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config EXAMPLES_WAMR_MODULE - tristate "WAMR module example" - default n - ---help--- - This example demonstrates how to register a external module - into WAMR runtime. diff --git a/examples/wamr_module/Make.defs b/examples/wamr_module/Make.defs deleted file mode 100644 index 7d4e5e274..000000000 --- a/examples/wamr_module/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/examples/wamr_module/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_EXAMPLES_WAMR_MODULE),) -CONFIGURED_APPS += $(APPDIR)/examples/wamr_module -endif diff --git a/examples/wamr_module/Makefile b/examples/wamr_module/Makefile deleted file mode 100644 index 448a5e066..000000000 --- a/examples/wamr_module/Makefile +++ /dev/null @@ -1,36 +0,0 @@ -############################################################################ -# apps/examples/wamr_module/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -# A Hello World WAMR C module - -CSRCS = module_hello.c - -# Set WAMR_MODULE_NAME and include Module.mk to add this module to the list of -# builtin modules for the WAMR runtime. WAMR_MODULE_NAME must be unique across all -# modules in system. - -WAMR_MODULE_NAME = hello - -include $(APPDIR)/interpreters/wamr/Module.mk -include $(APPDIR)/Application.mk diff --git a/examples/wamr_module/module_hello.c b/examples/wamr_module/module_hello.c deleted file mode 100644 index a406e2978..000000000 --- a/examples/wamr_module/module_hello.c +++ /dev/null @@ -1,77 +0,0 @@ -/**************************************************************************** - * apps/examples/wamr_module/module_hello.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <stdio.h> -#include <stddef.h> -#include <sys/param.h> - -#include "wasm_export.h" - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -static void hello_wrapper(wasm_exec_env_t env); - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static NativeSymbol g_hello_symbols[] = -{ - EXPORT_WASM_API_WITH_SIG2(hello, "()") -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: hello_wrapper - ****************************************************************************/ - -static void hello_wrapper(wasm_exec_env_t env) -{ - printf("Hello World from WAMR module!\n"); -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: wamr_module_hello_register - * - * The function prototype for the <WAMR_MODULE_NAME> module must be: - * `bool wamr_module_<WAMR_MODULE_NAME>_register(void)` - * - ****************************************************************************/ - -bool wamr_module_hello_register(void) -{ - return wasm_runtime_register_natives("hello", g_hello_symbols, - nitems(g_hello_symbols)); -} diff --git a/examples/watchdog/CMakeLists.txt b/examples/watchdog/CMakeLists.txt deleted file mode 100644 index f879250e5..000000000 --- a/examples/watchdog/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# ############################################################################## -# apps/examples/watchdog/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_WATCHDOG) - nuttx_add_application( - NAME - wdog - STACKSIZE - ${CONFIG_DEFAULT_TASK_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_WATCHDOG} - SRCS - watchdog_main.c) -endif() diff --git a/examples/watchdog/Make.defs b/examples/watchdog/Make.defs index fbf7ad3be..c18a8f241 100644 --- a/examples/watchdog/Make.defs +++ b/examples/watchdog/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/watchdog/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/watchdog/Makefile b/examples/watchdog/Makefile index ccb004a44..b8fca35de 100644 --- a/examples/watchdog/Makefile +++ b/examples/watchdog/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/watchdog/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/watchdog/watchdog.h b/examples/watchdog/watchdog.h index 45c66065d..4ab44dd5a 100644 --- a/examples/watchdog/watchdog.h +++ b/examples/watchdog/watchdog.h @@ -1,7 +1,5 @@ /**************************************************************************** - * apps/examples/watchdog/watchdog.h - * - * SPDX-License-Identifier: Apache-2.0 + * apps/examples/examples/watchdog/watchdog.h * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -32,9 +30,7 @@ /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ - /* Configuration ************************************************************/ - /* CONFIG_NSH_BUILTIN_APPS - Build the WATCHDOG test as an NSH built-in * function. * CONFIG_EXAMPLES_WATCHDOG_DEVPATH - The path to the Watchdog device. diff --git a/examples/watchdog/watchdog_main.c b/examples/watchdog/watchdog_main.c index 1167f3116..6a2c08816 100644 --- a/examples/watchdog/watchdog_main.c +++ b/examples/watchdog/watchdog_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/watchdog/watchdog_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -26,15 +24,15 @@ #include <nuttx/config.h> -#include <nuttx/debug.h> -#include <errno.h> -#include <fcntl.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> #include <sys/types.h> #include <sys/ioctl.h> + +#include <stdio.h> +#include <stdlib.h> #include <unistd.h> +#include <fcntl.h> +#include <errno.h> +#include <debug.h> #include <nuttx/timers/watchdog.h> @@ -138,8 +136,7 @@ static void parse_args(FAR struct wdog_example_s *wdog, int argc, wdog->pingtime = CONFIG_EXAMPLES_WATCHDOG_PINGTIME; wdog->pingdelay = CONFIG_EXAMPLES_WATCHDOG_PINGDELAY; wdog->timeout = CONFIG_EXAMPLES_WATCHDOG_TIMEOUT; - strlcpy(wdog->devname, CONFIG_EXAMPLES_WATCHDOG_DEVPATH, - sizeof(wdog->devname)); + strcpy(wdog->devname, CONFIG_EXAMPLES_WATCHDOG_DEVPATH); for (index = 1; index < argc; ) { @@ -152,7 +149,7 @@ static void parse_args(FAR struct wdog_example_s *wdog, int argc, switch (ptr[1]) { - case 'p': + case 'd': nargs = arg_decimal(&argv[index], &value); if (value < 1) { @@ -166,11 +163,11 @@ static void parse_args(FAR struct wdog_example_s *wdog, int argc, case 'i': nargs = arg_string(&argv[index], &string); - strlcpy(wdog->devname, string, sizeof(wdog->devname)); + strcpy(wdog->devname, string); index += nargs; break; - case 'd': + case 'p': nargs = arg_decimal(&argv[index], &value); if (value < 1 || value > INT_MAX) { @@ -308,7 +305,8 @@ int main(int argc, FAR char *argv[]) /* Get current time to calculate the elapsed time */ clock_gettime(CLOCK_REALTIME, &tnow); - current_time_ms = (tnow.tv_sec * 1000) + (tnow.tv_nsec / 1000000); + current_time_ms = (uint64_t)((tnow.tv_sec * 1000) + + (tnow.tv_nsec / 1000000)); } /* Then stop pinging */ @@ -344,7 +342,8 @@ int main(int argc, FAR char *argv[]) /* Get current time to calculate the elapsed time */ clock_gettime(CLOCK_REALTIME, &tnow); - current_time_ms = (tnow.tv_sec * 1000) + (tnow.tv_nsec / 1000000); + current_time_ms = (uint64_t)((tnow.tv_sec * 1000) + + (tnow.tv_nsec / 1000000)); } /* We should not get here */ diff --git a/examples/watched/CMakeLists.txt b/examples/watched/CMakeLists.txt deleted file mode 100644 index e6c89fa70..000000000 --- a/examples/watched/CMakeLists.txt +++ /dev/null @@ -1,36 +0,0 @@ -# ############################################################################## -# apps/examples/watched/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_WATCHED) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_WATCHED_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_WATCHED_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_WATCHED_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_WATCHED} - SRCS - watched_main.c) - target_sources(apps PRIVATE watched.c) -endif() diff --git a/examples/watched/Kconfig b/examples/watched/Kconfig index 8dcb10aed..84a3db887 100644 --- a/examples/watched/Kconfig +++ b/examples/watched/Kconfig @@ -10,10 +10,10 @@ config EXAMPLES_WATCHED ---help--- This application works with the watcher example and plays the role of the watched task. This process will create 2 - watched tasks. These tasks will subscribe to be watched. + watched tasks. These tasks will subscribe to be watched. One task will feed the dog and the other will starve the dog. So, the watchdog timer will expire and the offending task will - be printed. + be printed. if EXAMPLES_WATCHED diff --git a/examples/watched/Make.defs b/examples/watched/Make.defs index 530221fd0..62edd8757 100644 --- a/examples/watched/Make.defs +++ b/examples/watched/Make.defs @@ -1,7 +1,6 @@ ############################################################################ # apps/examples/watched/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 +# Adds selected applications to apps/ build # # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with diff --git a/examples/watched/Makefile b/examples/watched/Makefile index d34076071..7d0a746eb 100644 --- a/examples/watched/Makefile +++ b/examples/watched/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/watched/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -34,4 +32,4 @@ MODULE = $(CONFIG_EXAMPLES_WATCHED) CSRCS = watched.c MAINSRC = watched_main.c -include $(APPDIR)/Application.mk +include $(APPDIR)/Application.mk \ No newline at end of file diff --git a/examples/watched/watched.c b/examples/watched/watched.c index cad7095c0..2f6a49df7 100644 --- a/examples/watched/watched.c +++ b/examples/watched/watched.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/watched/watched.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/watched/watched.h b/examples/watched/watched.h index e483bd7e2..c49907b9d 100644 --- a/examples/watched/watched.h +++ b/examples/watched/watched.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/watched/watched.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/watched/watched_main.c b/examples/watched/watched_main.c index 343f636fe..cc44d0372 100644 --- a/examples/watched/watched_main.c +++ b/examples/watched/watched_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/watched/watched_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -28,8 +26,6 @@ #include <stdio.h> #include <errno.h> #include <stdlib.h> -#include <unistd.h> - #include "watched.h" /**************************************************************************** diff --git a/examples/watcher/CMakeLists.txt b/examples/watcher/CMakeLists.txt deleted file mode 100644 index daf17f484..000000000 --- a/examples/watcher/CMakeLists.txt +++ /dev/null @@ -1,36 +0,0 @@ -# ############################################################################## -# apps/examples/watcher/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_WATCHER) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_WATCHER_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_WATCHER_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_WATCHER_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_WATCHER} - SRCS - watcher_main.c) - target_sources(apps PRIVATE ramdisk.c wdt.c task_mn.c) -endif() diff --git a/examples/watcher/Kconfig b/examples/watcher/Kconfig index ec31685ec..fa8ceeb96 100644 --- a/examples/watcher/Kconfig +++ b/examples/watcher/Kconfig @@ -6,11 +6,11 @@ config EXAMPLES_WATCHER tristate "Watcher example" default n - depends on DRIVERS_NOTERAM + depends on DRIVER_NOTERAM depends on FSUTILS_MKFATFS ---help--- Enable the watcher example. The watcher is a task that will monitor - other tasks that have previously subscribed to be watched. If the + other tasks that have previously subscribed to be watched. If the watched tasks don't signal the watcher during the watchdog time period, the watchdog timer will expire and the watcher will print the tasks that did not signal and the ones that signaled. This example will only be supported diff --git a/examples/watcher/Make.defs b/examples/watcher/Make.defs index 6f929a790..0b605297d 100644 --- a/examples/watcher/Make.defs +++ b/examples/watcher/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/watcher/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/watcher/Makefile b/examples/watcher/Makefile index 99f97f943..da5862736 100644 --- a/examples/watcher/Makefile +++ b/examples/watcher/Makefile @@ -1,7 +1,5 @@ ############################################################################ -# apps/examples/watcher/Makefile -# -# SPDX-License-Identifier: Apache-2.0 +# apps/examples/watcher/Make.defs # # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with diff --git a/examples/watcher/ramdisk.c b/examples/watcher/ramdisk.c index 78dbf10da..717103eaf 100644 --- a/examples/watcher/ramdisk.c +++ b/examples/watcher/ramdisk.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/watcher/ramdisk.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/watcher/ramdisk.h b/examples/watcher/ramdisk.h index 07d16ccc2..bf10ba655 100644 --- a/examples/watcher/ramdisk.h +++ b/examples/watcher/ramdisk.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/watcher/ramdisk.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/watcher/task_mn.c b/examples/watcher/task_mn.c index 1d402c716..d2a68924f 100644 --- a/examples/watcher/task_mn.c +++ b/examples/watcher/task_mn.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/watcher/task_mn.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -25,15 +23,15 @@ ****************************************************************************/ #include <nuttx/config.h> +#include <sys/boardctl.h> #include <stdbool.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <errno.h> #include <fcntl.h> -#include <pthread.h> -#include <unistd.h> - +#include <sys/ioctl.h> +#include <nuttx/note/noteram_driver.h> #include "task_mn.h" /**************************************************************************** @@ -62,6 +60,7 @@ struct task_list_s watched_tasks = void task_mn_print_tasks_status(void) { int notefd; + struct noteram_get_taskname_s task; struct task_node_s *node; /* If the list is not empty */ @@ -70,10 +69,10 @@ void task_mn_print_tasks_status(void) { /* Open the note driver */ - notefd = open("/dev/note/ram", O_RDONLY); + notefd = open("/dev/note", O_RDONLY); if (notefd < 0) { - printf("Error: cannot open /dev/note/ram\n"); + printf("Error: cannot open /dev/note\n"); return; } @@ -81,15 +80,15 @@ void task_mn_print_tasks_status(void) for (node = watched_tasks.head; node != NULL; node = node->next) { - char taskname[CONFIG_NAME_MAX]; - pthread_getname_np(node->task_id, taskname, sizeof(taskname)); + task.pid = node->task_id; + ioctl(notefd, NOTERAM_GETTASKNAME, (unsigned long)&task); if (node->reset) { - printf("%s fed the dog.\n", taskname); + printf("%s fed the dog.\n", task.taskname); } else { - printf("%s starved the dog.\n", taskname); + printf("%s starved the dog.\n", task.taskname); } } @@ -240,16 +239,32 @@ void task_mn_remove_from_list(pid_t id) fprintf(stderr, "watcher daemon: This node is not in the list.\n"); } +void task_mn_get_task_name(struct noteram_get_taskname_s *task) +{ + int notefd; + + notefd = open("/dev/note", O_RDONLY); + if (notefd < 0) + { + fprintf(stderr, "trace: cannot open /dev/note\n"); + return; + } + + ioctl(notefd, NOTERAM_GETTASKNAME, (unsigned long)task); + close(notefd); +} + void task_mn_subscribe(pid_t id) { - char taskname[CONFIG_NAME_MAX]; + struct noteram_get_taskname_s task; /* Verify if the task exists in the list */ if (task_mn_is_task_subscribed(id) != NULL) { - pthread_getname_np(id, taskname, sizeof(taskname)); - printf("Task %s was already subscribed\n", taskname); + task.pid = id; + task_mn_get_task_name(&task); + printf("Task %s was already subscribed\n", task.taskname); } else { @@ -261,7 +276,7 @@ void task_mn_subscribe(pid_t id) void task_mn_unsubscribe(pid_t id) { - char taskname[CONFIG_NAME_MAX]; + struct noteram_get_taskname_s task; /* Verify if the task exists in the list */ @@ -273,8 +288,9 @@ void task_mn_unsubscribe(pid_t id) } else { - pthread_getname_np(id, taskname, sizeof(taskname)); - printf("Task %s is not subscribed\n", taskname); + task.pid = id; + task_mn_get_task_name(&task); + printf("Task %s is not subscribed\n", task.taskname); } } diff --git a/examples/watcher/task_mn.h b/examples/watcher/task_mn.h index f8d940755..d20b09505 100644 --- a/examples/watcher/task_mn.h +++ b/examples/watcher/task_mn.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/watcher/task_mn.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -73,6 +71,7 @@ void task_mn_reset_all(void); struct task_node_s *task_mn_is_task_subscribed(pid_t id); void task_mn_add_to_list(pid_t id); void task_mn_remove_from_list(pid_t id); +void task_mn_get_task_name(struct noteram_get_taskname_s *task); void task_mn_subscribe(pid_t id); void task_mn_unsubscribe(pid_t id); bool task_mn_all_tasks_fed(void); diff --git a/examples/watcher/watcher_main.c b/examples/watcher/watcher_main.c index 1fa4b259a..996d69d1c 100644 --- a/examples/watcher/watcher_main.c +++ b/examples/watcher/watcher_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/watcher/watcher_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -208,9 +206,9 @@ static int watcher_daemon(int argc, FAR char *argv[]) goto errout; } - fprintf(fp, "%d %d %d %d %d\n", watcher_pid, - CONFIG_EXAMPLES_WATCHER_SIGNAL, SUBSCRIBE_CMD, - FEED_CMD, UNSUBSCRIBE_CMD); + fprintf(fp, "%d %d %d %d %d\n", (int)watcher_pid, + (int)CONFIG_EXAMPLES_WATCHER_SIGNAL, (int)SUBSCRIBE_CMD, + (int)FEED_CMD, (int)UNSUBSCRIBE_CMD); fclose(fp); /* Suspends the calling thread until delivery of a non-blocked signal. */ diff --git a/examples/watcher/wdt.c b/examples/watcher/wdt.c index 667240dee..ea4ff6d8f 100644 --- a/examples/watcher/wdt.c +++ b/examples/watcher/wdt.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/watcher/wdt.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -32,10 +30,8 @@ #include <string.h> #include <errno.h> #include <fcntl.h> -#include <nuttx/debug.h> +#include <debug.h> #include <sys/ioctl.h> -#include <unistd.h> - #include "wdt.h" #include "task_mn.h" @@ -113,8 +109,7 @@ int wdt_init(void) { int fd; int ret; - strlcpy(wdog.devname, CONFIG_EXAMPLES_WATCHER_DEVPATH, - sizeof(wdog.devname)); + strcpy(wdog.devname, CONFIG_EXAMPLES_WATCHER_DEVPATH); /* Open the watchdog device for reading */ diff --git a/examples/watcher/wdt.h b/examples/watcher/wdt.h index 9f86c22d4..2d203958d 100644 --- a/examples/watcher/wdt.h +++ b/examples/watcher/wdt.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/watcher/wdt.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/webpanel/.gitignore b/examples/webpanel/.gitignore deleted file mode 100644 index 583a0928d..000000000 --- a/examples/webpanel/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -# ROMFS build artifacts (generated by Makefile) -/content diff --git a/examples/webpanel/CMakeLists.txt b/examples/webpanel/CMakeLists.txt deleted file mode 100644 index ed47cabbd..000000000 --- a/examples/webpanel/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -# ############################################################################## -# apps/examples/webpanel/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_WEBPANEL) - nuttx_add_application(NAME ${CONFIG_EXAMPLES_WEBPANEL_PROGNAME}) -endif() diff --git a/examples/webpanel/Kconfig b/examples/webpanel/Kconfig deleted file mode 100644 index b1392c725..000000000 --- a/examples/webpanel/Kconfig +++ /dev/null @@ -1,109 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config EXAMPLES_WEBPANEL - tristate "Web Panel for device management" - default n - depends on NET_TCP - depends on NETUTILS_THTTPD - depends on NETUTILS_LIBWEBSOCKETS - depends on NETUTILS_LIBWEBSOCKETS_SERVER - depends on FS_BINFS - depends on FS_UNIONFS - depends on PSEUDOTERM - depends on PSEUDOTERM_SUSV1 - ---help--- - Enable the Web Panel application, a Tasmota-inspired web - interface for NuttX devices. Provides a landing page served - via THTTPD from ROMFS, CGI handlers for system info, file - management, and a WebSocket-based NSH terminal (powered - by libwebsockets). - -if EXAMPLES_WEBPANEL - -config EXAMPLES_WEBPANEL_PROGNAME - string "Program name" - default "webpanel" - -config EXAMPLES_WEBPANEL_PRIORITY - int "Web Panel task priority" - default 100 - -config EXAMPLES_WEBPANEL_STACKSIZE - int "Web Panel stack size" - default 4096 - -config EXAMPLES_WEBPANEL_NETIF - string "Network interface name" - default "eth0" - ---help--- - Name of the network interface used by the web panel for - system info queries and DHCP renew (e.g. eth0, wlan0). - -config EXAMPLES_WEBPANEL_CGI_SYSINFO_PROGNAME - string "CGI sysinfo program name" - default "sysinfo" - -config EXAMPLES_WEBPANEL_CGI_SYSINFO_PRIORITY - int "CGI sysinfo task priority" - default 100 - -config EXAMPLES_WEBPANEL_CGI_SYSINFO_STACKSIZE - int "CGI sysinfo stack size" - default 4096 - -config EXAMPLES_WEBPANEL_CGI_FILES_PROGNAME - string "CGI files program name" - default "files" - -config EXAMPLES_WEBPANEL_CGI_FILES_PRIORITY - int "CGI files task priority" - default 100 - -config EXAMPLES_WEBPANEL_CGI_FILES_STACKSIZE - int "CGI files stack size" - default 4096 - -config EXAMPLES_WEBPANEL_CGI_UPLOAD_PROGNAME - string "CGI upload program name" - default "upload" - -config EXAMPLES_WEBPANEL_CGI_UPLOAD_PRIORITY - int "CGI upload task priority" - default 100 - -config EXAMPLES_WEBPANEL_CGI_UPLOAD_STACKSIZE - int "CGI upload stack size" - default 8192 - -config EXAMPLES_WEBPANEL_CGI_RENEW_PROGNAME - string "CGI DHCP renew program name" - default "dhcprenew" - -config EXAMPLES_WEBPANEL_CGI_RENEW_PRIORITY - int "CGI DHCP renew task priority" - default 100 - -config EXAMPLES_WEBPANEL_CGI_RENEW_STACKSIZE - int "CGI DHCP renew stack size" - default 4096 - -config EXAMPLES_WEBPANEL_WS_PORT - int "WebSocket terminal TCP port" - default 8080 - -config EXAMPLES_WEBPANEL_WS_PRIORITY - int "WebSocket server task priority" - default 100 - -config EXAMPLES_WEBPANEL_WS_STACKSIZE - int "WebSocket daemon stack size" - default 8192 - -config EXAMPLES_WEBPANEL_WS_NSH_STACKSIZE - int "WebSocket NSH session stack size" - default 4096 - -endif diff --git a/examples/webpanel/Make.defs b/examples/webpanel/Make.defs deleted file mode 100644 index bf880eb82..000000000 --- a/examples/webpanel/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/examples/webpanel/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_EXAMPLES_WEBPANEL),) -CONFIGURED_APPS += $(APPDIR)/examples/webpanel -endif diff --git a/examples/webpanel/Makefile b/examples/webpanel/Makefile deleted file mode 100644 index 12d6be8e6..000000000 --- a/examples/webpanel/Makefile +++ /dev/null @@ -1,94 +0,0 @@ -############################################################################ -# apps/examples/webpanel/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -# Web Panel application + CGI handlers -# NuttX multi-program build: space-separated lists, matched by position. - -CSRCS = romfs.c ws_terminal.c -MAINSRC = webpanel_main.c cgi_sysinfo.c cgi_files.c cgi_upload.c cgi_renew.c - -PROGNAME = $(CONFIG_EXAMPLES_WEBPANEL_PROGNAME) \ - $(CONFIG_EXAMPLES_WEBPANEL_CGI_SYSINFO_PROGNAME) \ - $(CONFIG_EXAMPLES_WEBPANEL_CGI_FILES_PROGNAME) \ - $(CONFIG_EXAMPLES_WEBPANEL_CGI_UPLOAD_PROGNAME) \ - $(CONFIG_EXAMPLES_WEBPANEL_CGI_RENEW_PROGNAME) -PRIORITY = $(CONFIG_EXAMPLES_WEBPANEL_PRIORITY) \ - $(CONFIG_EXAMPLES_WEBPANEL_CGI_SYSINFO_PRIORITY) \ - $(CONFIG_EXAMPLES_WEBPANEL_CGI_FILES_PRIORITY) \ - $(CONFIG_EXAMPLES_WEBPANEL_CGI_UPLOAD_PRIORITY) \ - $(CONFIG_EXAMPLES_WEBPANEL_CGI_RENEW_PRIORITY) -STACKSIZE = $(CONFIG_EXAMPLES_WEBPANEL_STACKSIZE) \ - $(CONFIG_EXAMPLES_WEBPANEL_CGI_SYSINFO_STACKSIZE) \ - $(CONFIG_EXAMPLES_WEBPANEL_CGI_FILES_STACKSIZE) \ - $(CONFIG_EXAMPLES_WEBPANEL_CGI_UPLOAD_STACKSIZE) \ - $(CONFIG_EXAMPLES_WEBPANEL_CGI_RENEW_STACKSIZE) - -LWS_DIR = $(APPDIR)/netutils/libwebsockets -CFLAGS += -I$(LWS_DIR) \ - -I$(LWS_DIR)/libwebsockets/include - -MODULE = $(CONFIG_EXAMPLES_WEBPANEL) - -VPATH += content -DEPPATH += --dep-path content - -# ROMFS image generation -# Static web content goes directly into the ROMFS root (no www/ subdir) - -WEBPANEL_DIR = $(APPDIR)/examples/webpanel -CONTENT_DIR = $(WEBPANEL_DIR)/content -ROMFS_DIR = $(CONTENT_DIR)/romfs -ROMFS_IMG = $(CONTENT_DIR)/romfs.img -ROMFS_SRC = $(CONTENT_DIR)/romfs.c - -WWW_FILES = $(wildcard $(CONTENT_DIR)/www/*) - -$(CONTENT_DIR)/.romfs_stamp: $(WWW_FILES) - $(Q) mkdir -p $(ROMFS_DIR) - $(Q) cp -a $(CONTENT_DIR)/www/* $(ROMFS_DIR)/ - $(Q) touch $@ - -$(ROMFS_IMG): $(CONTENT_DIR)/.romfs_stamp - $(Q) genromfs -f $@ -d $(ROMFS_DIR) -V "WebPanelROMFS" - -$(ROMFS_SRC): $(ROMFS_IMG) - $(Q) (cd $(CONTENT_DIR) && \ - echo "#include <nuttx/compiler.h>" >$@ && \ - xxd -i romfs.img | \ - sed -e "s/romfs_img/webpanel_romfs_img/g" | \ - sed -e "s/^unsigned char/const unsigned char aligned_data(4)/g" >>$@) - -content/romfs.c: $(ROMFS_SRC) - -context:: - -clean:: - $(call DELFILE, $(ROMFS_SRC)) - $(call DELFILE, $(ROMFS_IMG)) - $(call DELFILE, $(CONTENT_DIR)/.romfs_stamp) - $(Q) rm -rf $(ROMFS_DIR) - -distclean:: clean - -include $(APPDIR)/Application.mk diff --git a/examples/webpanel/cgi_files.c b/examples/webpanel/cgi_files.c deleted file mode 100644 index fdc67b868..000000000 --- a/examples/webpanel/cgi_files.c +++ /dev/null @@ -1,314 +0,0 @@ -/**************************************************************************** - * apps/examples/webpanel/cgi_files.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <dirent.h> -#include <sys/stat.h> -#include <unistd.h> - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define FILES_DIR "/mnt" - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -static void url_decode(char *dst, const char *src, size_t dstsize); -static const char *get_query_param(const char *qs, const char *key, - char *val, size_t vallen); -static void handle_list(void); -static void handle_delete(const char *name); - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: url_decode - * - * Description: - * Decode a URL-encoded string into a destination buffer. - * - * Input Parameters: - * dst - Destination buffer. - * src - Source URL-encoded string. - * dstsize - Size of destination buffer. - * - * Returned Value: - * None. - * - ****************************************************************************/ - -static void url_decode(char *dst, const char *src, size_t dstsize) -{ - size_t i = 0; - - while (*src && i < dstsize - 1) - { - if (*src == '%' && src[1] && src[2]) - { - char hex[3]; - - hex[0] = src[1]; - hex[1] = src[2]; - hex[2] = '\0'; - dst[i++] = (char)strtol(hex, NULL, 16); - src += 3; - } - else if (*src == '+') - { - dst[i++] = ' '; - src++; - } - else - { - dst[i++] = *src++; - } - } - - dst[i] = '\0'; -} - -/**************************************************************************** - * Name: get_query_param - * - * Description: - * Find and decode a key=value parameter from the QUERY_STRING. - * - * Input Parameters: - * qs - Query string. - * key - Parameter name to search for. - * val - Output buffer for decoded value. - * vallen - Size of output buffer. - * - * Returned Value: - * Pointer to val on success; NULL if not found or invalid input. - * - ****************************************************************************/ - -static const char *get_query_param(const char *qs, const char *key, - char *val, size_t vallen) -{ - const char *p; - size_t klen; - - if (qs == NULL || key == NULL) - { - return NULL; - } - - klen = strlen(key); - p = qs; - - while (*p) - { - if (strncmp(p, key, klen) == 0 && p[klen] == '=') - { - const char *start = p + klen + 1; - const char *end = strchr(start, '&'); - size_t len; - - if (end == NULL) - { - end = start + strlen(start); - } - - len = end - start; - if (len >= vallen) - { - len = vallen - 1; - } - - url_decode(val, start, len + 1); - return val; - } - - p = strchr(p, '&'); - if (p == NULL) - { - break; - } - - p++; - } - - return NULL; -} - -/**************************************************************************** - * Name: handle_list - * - * Description: - * Emit a JSON response listing files in FILES_DIR. - * - * Input Parameters: - * None. - * - * Returned Value: - * None. - * - ****************************************************************************/ - -static void handle_list(void) -{ - DIR *dir; - struct dirent *ent; - struct stat st; - char path[128]; - int first = 1; - - puts("Content-type: application/json\r\n" - "\r\n"); - - printf("{\"files\":["); - - dir = opendir(FILES_DIR); - if (dir != NULL) - { - while ((ent = readdir(dir)) != NULL) - { - if (ent->d_name[0] == '.') - { - continue; - } - - snprintf(path, sizeof(path), "%s/%s", FILES_DIR, ent->d_name); - - if (!first) - { - printf(","); - } - - first = 0; - - if (stat(path, &st) == 0) - { - printf("{\"name\":\"%s\",\"size\":%ld}", - ent->d_name, (long)st.st_size); - } - else - { - printf("{\"name\":\"%s\",\"size\":0}", ent->d_name); - } - } - - closedir(dir); - } - - printf("]}\n"); -} - -/**************************************************************************** - * Name: handle_delete - * - * Description: - * Delete the requested file from FILES_DIR and emit a JSON response. - * - * Input Parameters: - * name - File name to delete. - * - * Returned Value: - * None. - * - ****************************************************************************/ - -static void handle_delete(const char *name) -{ - char path[128]; - - if (name == NULL || name[0] == '\0' || strchr(name, '/') != NULL) - { - puts("Content-type: application/json\r\n" - "Status: 400\r\n" - "\r\n"); - printf("{\"error\":\"Invalid filename\"}\n"); - return; - } - - snprintf(path, sizeof(path), "%s/%s", FILES_DIR, name); - - if (unlink(path) == 0) - { - puts("Content-type: application/json\r\n" - "\r\n"); - printf("{\"ok\":true}\n"); - } - else - { - puts("Content-type: application/json\r\n" - "Status: 404\r\n" - "\r\n"); - printf("{\"error\":\"File not found\"}\n"); - } -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: files_main - * - * Description: - * Entry point for file list/delete CGI handling. - * - * Input Parameters: - * argc - Number of arguments. - * argv - Argument vector. - * - * Returned Value: - * Zero (OK). - * - ****************************************************************************/ - -int files_main(int argc, FAR char *argv[]) -{ - const char *qs; - char action[16]; - char name[64]; - - qs = getenv("QUERY_STRING"); - - if (qs != NULL && get_query_param(qs, "action", action, sizeof(action))) - { - if (strcmp(action, "delete") == 0) - { - get_query_param(qs, "name", name, sizeof(name)); - handle_delete(name); - return 0; - } - } - - handle_list(); - return 0; -} diff --git a/examples/webpanel/cgi_renew.c b/examples/webpanel/cgi_renew.c deleted file mode 100644 index 098995094..000000000 --- a/examples/webpanel/cgi_renew.c +++ /dev/null @@ -1,72 +0,0 @@ -/**************************************************************************** - * apps/examples/webpanel/cgi_renew.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <stdio.h> - -#include "netutils/netlib.h" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: dhcprenew_main - * - * Description: - * CGI entry point that renews the IPv4 address on the configured - * interface and returns the result as JSON. - * - * Input Parameters: - * argc - Number of arguments. - * argv - Argument vector. - * - * Returned Value: - * Zero on success; one on failure. - * - ****************************************************************************/ - -int dhcprenew_main(int argc, FAR char *argv[]) -{ - int ret; - - ret = netlib_obtain_ipv4addr(CONFIG_EXAMPLES_WEBPANEL_NETIF); - - puts("Content-type: application/json\r\n" - "\r\n"); - - if (ret >= 0) - { - puts("{\"status\":\"ok\"}\n"); - } - else - { - printf("{\"status\":\"error\",\"code\":%d}\n", ret); - } - - return ret < 0 ? 1 : 0; -} diff --git a/examples/webpanel/cgi_sysinfo.c b/examples/webpanel/cgi_sysinfo.c deleted file mode 100644 index 619eb4cf1..000000000 --- a/examples/webpanel/cgi_sysinfo.c +++ /dev/null @@ -1,414 +0,0 @@ -/**************************************************************************** - * apps/examples/webpanel/cgi_sysinfo.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> -#include <dirent.h> -#include <time.h> -#include <sys/ioctl.h> -#include <sys/socket.h> -#include <sys/utsname.h> -#include <net/if.h> -#include <arpa/inet.h> -#include <netinet/in.h> - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -static void get_version(char *ver, size_t vlen, - char *build, size_t blen, - char *board, size_t boardlen); -static void get_arch(char *arch, size_t archlen); -static unsigned long get_uptime(char *buf, size_t len); -static void get_net_info(char *ip, size_t iplen, - char *mask, size_t masklen, - char *gw, size_t gwlen, - char *mac, size_t maclen); -static int count_files(const char *path); - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: get_version - * - * Description: - * Read version, build hash, and board information from /proc/version. - * - * Input Parameters: - * ver - Output buffer for version string. - * vlen - Size of ver buffer. - * build - Output buffer for build/hash string. - * blen - Size of build buffer. - * board - Output buffer for board string. - * boardlen - Size of board buffer. - * - * Returned Value: - * None. - * - ****************************************************************************/ - -static void get_version(char *ver, size_t vlen, - char *build, size_t blen, - char *board, size_t boardlen) -{ - FILE *fp; - char line[256]; - char *p; - char *sp; - char *last; - char *tok; - size_t n; - - strncpy(ver, "unknown", vlen); - strncpy(build, "unknown", blen); - strncpy(board, "unknown", boardlen); - - fp = fopen("/proc/version", "r"); - if (fp == NULL) - { - return; - } - - if (fgets(line, sizeof(line), fp) != NULL) - { - /* Format: "NuttX version X.Y.Z HASH DATE TIME BOARD:CONFIG" */ - - p = strstr(line, "version "); - if (p != NULL) - { - p += 8; - - /* version token */ - - sp = strchr(p, ' '); - if (sp != NULL) - { - n = sp - p; - if (n >= vlen) - { - n = vlen - 1; - } - - memcpy(ver, p, n); - ver[n] = '\0'; - - /* build (git hash) token */ - - p = sp + 1; - sp = strchr(p, ' '); - if (sp != NULL) - { - n = sp - p; - if (n >= blen) - { - n = blen - 1; - } - - memcpy(build, p, n); - build[n] = '\0'; - } - } - } - - /* Board name is the last whitespace-separated token; trim :config */ - - last = NULL; - tok = strtok(line, " \t\r\n"); - while (tok != NULL) - { - last = tok; - tok = strtok(NULL, " \t\r\n"); - } - - if (last != NULL) - { - char *colon = strchr(last, ':'); - if (colon != NULL) - { - *colon = '\0'; - } - - strncpy(board, last, boardlen - 1); - board[boardlen - 1] = '\0'; - } - } - - fclose(fp); -} - -/**************************************************************************** - * Name: get_arch - * - * Description: - * Query architecture information via uname(). - * - * Input Parameters: - * arch - Output buffer for architecture string. - * archlen - Size of arch buffer. - * - * Returned Value: - * None. - * - ****************************************************************************/ - -static void get_arch(char *arch, size_t archlen) -{ - struct utsname uts; - - strncpy(arch, "unknown", archlen); - - if (uname(&uts) == 0) - { - strncpy(arch, uts.machine, archlen - 1); - arch[archlen - 1] = '\0'; - } -} - -/**************************************************************************** - * Name: get_uptime - * - * Description: - * Read system uptime based on CLOCK_MONOTONIC and format it. - * - * Input Parameters: - * buf - Output buffer for formatted uptime. - * len - Size of buf. - * - * Returned Value: - * Uptime in seconds; zero on error. - * - ****************************************************************************/ - -static unsigned long get_uptime(char *buf, size_t len) -{ - struct timespec ts; - - if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) - { - unsigned long secs = ts.tv_sec; - unsigned int days = secs / 86400; - unsigned int hrs = (secs % 86400) / 3600; - unsigned int mins = (secs % 3600) / 60; - unsigned int s = secs % 60; - - if (days > 0) - { - snprintf(buf, len, "%ud %02u:%02u:%02u", days, hrs, mins, s); - } - else - { - snprintf(buf, len, "%02u:%02u:%02u", hrs, mins, s); - } - - return secs; - } - - snprintf(buf, len, "unknown"); - return 0; -} - -/**************************************************************************** - * Name: get_net_info - * - * Description: - * Query IP, netmask, gateway, and MAC for the configured interface. - * - * Input Parameters: - * ip - Output buffer for IPv4 address. - * iplen - Size of ip buffer. - * mask - Output buffer for netmask. - * masklen - Size of mask buffer. - * gw - Output buffer for gateway. - * gwlen - Size of gw buffer. - * mac - Output buffer for MAC address. - * maclen - Size of mac buffer. - * - * Returned Value: - * None. - * - ****************************************************************************/ - -static void get_net_info(char *ip, size_t iplen, - char *mask, size_t masklen, - char *gw, size_t gwlen, - char *mac, size_t maclen) -{ - int sockfd; - struct ifreq ifr; - - strncpy(ip, "N/A", iplen); - strncpy(mask, "N/A", masklen); - strncpy(gw, "N/A", gwlen); - strncpy(mac, "N/A", maclen); - - sockfd = socket(AF_INET, SOCK_DGRAM, 0); - if (sockfd < 0) - { - return; - } - - memset(&ifr, 0, sizeof(ifr)); - strncpy(ifr.ifr_name, CONFIG_EXAMPLES_WEBPANEL_NETIF, IFNAMSIZ); - - if (ioctl(sockfd, SIOCGIFADDR, &ifr) == 0) - { - struct sockaddr_in *sa = (struct sockaddr_in *)&ifr.ifr_addr; - inet_ntop(AF_INET, &sa->sin_addr, ip, iplen); - } - - if (ioctl(sockfd, SIOCGIFNETMASK, &ifr) == 0) - { - struct sockaddr_in *sa = (struct sockaddr_in *)&ifr.ifr_netmask; - inet_ntop(AF_INET, &sa->sin_addr, mask, masklen); - } - - if (ioctl(sockfd, SIOCGIFDSTADDR, &ifr) == 0) - { - struct sockaddr_in *sa = (struct sockaddr_in *)&ifr.ifr_dstaddr; - inet_ntop(AF_INET, &sa->sin_addr, gw, gwlen); - } - - if (ioctl(sockfd, SIOCGIFHWADDR, &ifr) == 0) - { - unsigned char *hw = (unsigned char *)ifr.ifr_hwaddr.sa_data; - snprintf(mac, maclen, "%02x:%02x:%02x:%02x:%02x:%02x", - hw[0], hw[1], hw[2], hw[3], hw[4], hw[5]); - } - - close(sockfd); -} - -/**************************************************************************** - * Name: count_files - * - * Description: - * Count visible files in a directory. - * - * Input Parameters: - * path - Directory path. - * - * Returned Value: - * Number of visible entries. - * - ****************************************************************************/ - -static int count_files(const char *path) -{ - DIR *dir; - struct dirent *ent; - int count = 0; - - dir = opendir(path); - if (dir == NULL) - { - return 0; - } - - while ((ent = readdir(dir)) != NULL) - { - if (ent->d_name[0] != '.') - { - count++; - } - } - - closedir(dir); - return count; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: sysinfo_main - * - * Description: - * CGI entry point that returns board and runtime information as JSON. - * - * Input Parameters: - * argc - Number of arguments. - * argv - Argument vector. - * - * Returned Value: - * Zero (OK). - * - ****************************************************************************/ - -int sysinfo_main(int argc, FAR char *argv[]) -{ - char version[16]; - char build[16]; - char board[64]; - char arch[32]; - char uptime[32]; - char ip[16]; - char mask[16]; - char gw[16]; - char mac[24]; - unsigned long uptime_sec; - int nfiles; - - get_version(version, sizeof(version), build, sizeof(build), - board, sizeof(board)); - get_arch(arch, sizeof(arch)); - uptime_sec = get_uptime(uptime, sizeof(uptime)); - get_net_info(ip, sizeof(ip), mask, sizeof(mask), - gw, sizeof(gw), mac, sizeof(mac)); - nfiles = count_files("/mnt"); - - puts("Content-type: application/json\r\n" - "\r\n"); - - printf("{" - "\"chip\":\"" CONFIG_ARCH_CHIP "\"," - "\"board\":\"%s\"," - "\"os\":\"NuttX\"," - "\"version\":\"%s\"," - "\"build\":\"%s\"," - "\"arch\":\"%s\"," - "\"ifname\":\"" CONFIG_EXAMPLES_WEBPANEL_NETIF "\"," - "\"ip\":\"%s\"," - "\"mask\":\"%s\"," - "\"gw\":\"%s\"," - "\"mac\":\"%s\"," - "\"uptime\":\"%s\"," - "\"uptime_sec\":%lu," - "\"files\":%d" - "}\n", - board, version, build, arch, - ip, mask, gw, mac, - uptime, uptime_sec, nfiles); - - return 0; -} diff --git a/examples/webpanel/cgi_upload.c b/examples/webpanel/cgi_upload.c deleted file mode 100644 index 4dfd137ad..000000000 --- a/examples/webpanel/cgi_upload.c +++ /dev/null @@ -1,637 +0,0 @@ -/**************************************************************************** - * apps/examples/webpanel/cgi_upload.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> -#include <fcntl.h> -#include <errno.h> - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define UPLOAD_DIR "/mnt" -#define BUF_SIZE 512 -#define MAX_FILENAME 64 -#define MAX_BOUNDARY 80 - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -static void cgi_error(int status, const char *msg); -static void cgi_ok(const char *filename); -static int extract_boundary(const char *content_type, char *boundary, - size_t blen); -static int extract_filename(const char *line, char *name, size_t nlen); -static size_t read_stdin(char *buf, size_t n); -static char *memmem_local(const char *haystack, size_t hlen, - const char *needle, size_t nlen); - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: cgi_error - * - * Description: - * Emit a JSON error response with HTTP status. - * - * Input Parameters: - * status - HTTP status code. - * msg - Error message string. - * - * Returned Value: - * None. - * - ****************************************************************************/ - -static void cgi_error(int status, const char *msg) -{ - printf("Content-type: application/json\r\n" - "Status: %d\r\n" - "\r\n" - "{\"error\":\"%s\"}\n", status, msg); -} - -/**************************************************************************** - * Name: cgi_ok - * - * Description: - * Emit a JSON success response. - * - * Input Parameters: - * filename - Uploaded file name. - * - * Returned Value: - * None. - * - ****************************************************************************/ - -static void cgi_ok(const char *filename) -{ - printf("Content-type: application/json\r\n" - "\r\n" - "{\"ok\":true,\"name\":\"%s\"}\n", filename); -} - -/**************************************************************************** - * Name: extract_boundary - * - * Description: - * Extract multipart boundary from CONTENT_TYPE. - * - * Input Parameters: - * content_type - CONTENT_TYPE value. - * boundary - Output buffer for boundary token. - * blen - Size of boundary buffer. - * - * Returned Value: - * Zero on success; negated value on failure. - * - ****************************************************************************/ - -static int extract_boundary(const char *content_type, char *boundary, - size_t blen) -{ - const char *p; - char *q; - size_t len; - - p = strstr(content_type, "boundary="); - if (p == NULL) - { - return -1; - } - - p += 9; - - /* Skip optional quotes */ - - if (*p == '"') - { - p++; - } - - strncpy(boundary, p, blen - 1); - boundary[blen - 1] = '\0'; - - /* Remove trailing quote if present */ - - q = strchr(boundary, '"'); - if (q != NULL) - { - *q = '\0'; - } - - /* Remove trailing whitespace/CR/LF */ - - len = strlen(boundary); - while (len > 0 && - (boundary[len - 1] == '\r' || boundary[len - 1] == '\n' || - boundary[len - 1] == ' ')) - { - boundary[--len] = '\0'; - } - - return len > 0 ? 0 : -1; -} - -/**************************************************************************** - * Name: extract_filename - * - * Description: - * Extract a safe filename from a Content-Disposition header line. - * - * Input Parameters: - * line - Header line. - * name - Output buffer for filename. - * nlen - Size of name buffer. - * - * Returned Value: - * Zero on success; negated value on failure. - * - ****************************************************************************/ - -static int extract_filename(const char *line, char *name, size_t nlen) -{ - const char *p; - const char *end; - size_t len; - - p = strstr(line, "filename=\""); - if (p == NULL) - { - return -1; - } - - p += 10; - end = strchr(p, '"'); - if (end == NULL) - { - return -1; - } - - len = end - p; - if (len == 0 || len >= nlen) - { - return -1; - } - - /* Reject path separators in filename */ - - if (memchr(p, '/', len) != NULL || memchr(p, '\\', len) != NULL) - { - return -1; - } - - memcpy(name, p, len); - name[len] = '\0'; - return 0; -} - -/**************************************************************************** - * Name: read_stdin - * - * Description: - * Read exactly n bytes from standard input unless EOF/error occurs. - * - * Input Parameters: - * buf - Destination buffer. - * n - Requested number of bytes. - * - * Returned Value: - * Number of bytes actually read. - * - ****************************************************************************/ - -static size_t read_stdin(char *buf, size_t n) -{ - size_t total = 0; - while (total < n) - { - ssize_t r = read(STDIN_FILENO, buf + total, n - total); - if (r <= 0) - { - break; - } - - total += r; - } - - return total; -} - -/**************************************************************************** - * Name: memmem_local - * - * Description: - * Find a byte sequence inside a bounded memory region. - * - * Input Parameters: - * haystack - Input buffer. - * hlen - Size of haystack. - * needle - Pattern to search. - * nlen - Size of needle. - * - * Returned Value: - * Pointer to first match; NULL if not found. - * - ****************************************************************************/ - -static char *memmem_local(const char *haystack, size_t hlen, - const char *needle, size_t nlen) -{ - const char *p; - if (nlen == 0) - { - return (char *)haystack; - } - - if (hlen < nlen) - { - return NULL; - } - - p = haystack; - while (p <= haystack + hlen - nlen) - { - if (memcmp(p, needle, nlen) == 0) - { - return (char *)p; - } - - p++; - } - - return NULL; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: upload_main - * - * Description: - * CGI entry point for multipart file upload. - * - * Input Parameters: - * argc - Number of arguments. - * argv - Argument vector. - * - * Returned Value: - * Zero (OK). - * - ****************************************************************************/ - -int upload_main(int argc, FAR char *argv[]) -{ - const char *content_type; - const char *content_length_str; - char boundary_raw[MAX_BOUNDARY]; - char boundary[MAX_BOUNDARY + 4]; - size_t boundary_len; - char filename[MAX_FILENAME]; - char filepath[MAX_FILENAME + 8]; - char buf[BUF_SIZE]; - size_t content_length; - size_t total_read; - int fd = -1; - int state; - char linebuf[256]; - size_t linepos; - int headers_done; - - content_type = getenv("CONTENT_TYPE"); - content_length_str = getenv("CONTENT_LENGTH"); - - if (content_type == NULL || content_length_str == NULL) - { - cgi_error(400, "Missing Content-Type or Content-Length"); - return 0; - } - - content_length = strtoul(content_length_str, NULL, 10); - if (content_length == 0 || content_length > 1024 * 1024) - { - cgi_error(400, "Invalid content length (max 1MB)"); - return 0; - } - - if (extract_boundary(content_type, boundary_raw, sizeof(boundary_raw)) < 0) - { - cgi_error(400, "No boundary in Content-Type"); - return 0; - } - - /* Multipart boundaries in the body are prefixed with "--" */ - - snprintf(boundary, sizeof(boundary), "--%s", boundary_raw); - boundary_len = strlen(boundary); - - /* State machine for multipart parsing: - * 0 = looking for first boundary - * 1 = reading headers after boundary - * 2 = reading file data - * 3 = done - */ - - state = 0; - total_read = 0; - filename[0] = '\0'; - linepos = 0; - headers_done = 0; - - /* Read the entire POST body in chunks and process inline. - * We accumulate a line buffer for header parsing, and stream - * file data directly to disk. - */ - - while (total_read < content_length && state != 3) - { - size_t toread = content_length - total_read; - size_t nread; - - if (toread > sizeof(buf)) - { - toread = sizeof(buf); - } - - nread = read_stdin(buf, toread); - if (nread == 0) - { - break; - } - - total_read += nread; - - size_t i = 0; - while (i < nread && state != 3) - { - switch (state) - { - case 0: - - /* Accumulate until we find the first boundary line */ - - while (i < nread) - { - if (buf[i] == '\n') - { - linebuf[linepos] = '\0'; - - /* Strip trailing \r */ - - if (linepos > 0 && linebuf[linepos - 1] == '\r') - { - linebuf[--linepos] = '\0'; - } - - if (strncmp(linebuf, boundary, boundary_len) == 0) - { - state = 1; - headers_done = 0; - linepos = 0; - i++; - break; - } - - linepos = 0; - i++; - } - else - { - if (linepos < sizeof(linebuf) - 1) - { - linebuf[linepos++] = buf[i]; - } - - i++; - } - } - - break; - - case 1: - /* Parse headers after boundary, looking for - * Content-Disposition with filename. - * Headers end with an empty line. - */ - - while (i < nread && !headers_done) - { - if (buf[i] == '\n') - { - linebuf[linepos] = '\0'; - - if (linepos > 0 && linebuf[linepos - 1] == '\r') - { - linebuf[--linepos] = '\0'; - } - - if (linepos == 0) - { - /* Empty line = end of headers */ - - headers_done = 1; - - if (filename[0] == '\0') - { - cgi_error(400, "No filename in upload"); - if (fd >= 0) - { - close(fd); - } - - return 0; - } - - snprintf(filepath, sizeof(filepath), "%s/%s", - UPLOAD_DIR, filename); - - fd = open(filepath, - O_WRONLY | O_CREAT | O_TRUNC, - 0666); - if (fd < 0) - { - cgi_error(500, "Cannot create file"); - return 0; - } - - state = 2; - i++; - break; - } - - if (strstr(linebuf, "Content-Disposition") != NULL) - { - extract_filename(linebuf, filename, - sizeof(filename)); - } - - linepos = 0; - i++; - } - else - { - if (linepos < sizeof(linebuf) - 1) - { - linebuf[linepos++] = buf[i]; - } - - i++; - } - } - - break; - - case 2: - { - /* Write file data. We need to detect the closing boundary - * which appears as "\r\n--BOUNDARY" in the stream. - * Buffer the last boundary_len+4 bytes to check for the - * boundary. - */ - - size_t remaining = nread - i; - char *bnd; - - bnd = memmem_local(buf + i, remaining, - boundary, boundary_len); - if (bnd != NULL) - { - /* Found boundary. Write everything before it, - * minus the preceding \r\n. - */ - - size_t datalen = bnd - (buf + i); - if (datalen >= 2) - { - datalen -= 2; - } - - if (datalen > 0) - { - write(fd, buf + i, datalen); - } - - close(fd); - fd = -1; - state = 3; - break; - } - else - { - /* No boundary in this chunk. Write data but hold back - * enough bytes to avoid splitting a boundary across - * chunks. - */ - - size_t safe; - - if (remaining > boundary_len + 4) - { - safe = remaining - boundary_len - 4; - } - else - { - safe = 0; - } - - if (safe > 0) - { - write(fd, buf + i, safe); - i += safe; - } - else - { - /* Not enough data to be safe. This means we're near - * the end of a chunk and need more data. Just write - * what we have and hope the boundary comes in the - * next read. For simplicity, write it all - worst - * case we include a few extra bytes at end of file - * which will be fixed when the boundary is found. - */ - - write(fd, buf + i, remaining); - i = nread; - } - } - - break; - } - } - } - } - - /* Drain any remaining data from stdin */ - - while (total_read < content_length) - { - size_t toread = content_length - total_read; - size_t nread; - - if (toread > sizeof(buf)) - { - toread = sizeof(buf); - } - - nread = read_stdin(buf, toread); - if (nread == 0) - { - break; - } - - total_read += nread; - } - - if (fd >= 0) - { - close(fd); - } - - if (state == 3 && filename[0] != '\0') - { - cgi_ok(filename); - } - else if (filename[0] != '\0') - { - cgi_ok(filename); - } - else - { - cgi_error(400, "Upload incomplete or no file received"); - } - - return 0; -} diff --git a/examples/webpanel/content/www/index.html b/examples/webpanel/content/www/index.html deleted file mode 100644 index 7d4928e31..000000000 --- a/examples/webpanel/content/www/index.html +++ /dev/null @@ -1,454 +0,0 @@ -<!DOCTYPE html> -<html lang="en"> -<head> -<meta charset="utf-8"> -<meta name="viewport" content="width=device-width,initial-scale=1"> -<title>NuttX Web Panel - - - - - -
-

NuttX Web Panel --

- Uptime: -- -
- - - - -
-
-
-

System

-
Board--
-
OSNuttX
-
Version--
-
Build--
-
Arch--
-
-
-

🔌 Network

-
Interface--
-
IP--
-
Mask--
-
Gateway--
-
MAC--
-
-
-

💾 Storage

-
SmartFS/mnt
-
Web Root/data/www (ROMFS)
-
Files--
-
-
-

Quick Actions

-
- - - -
-
-
-
- - -
-
-

NSH Terminal

-
- - - Disconnected -
-
-
-
- - -
-
-

📁 File Manager — /mnt

-
- /mnt - -
-
-
Loading file list…
-
-
- - Drop file here or click to upload to /mnt -
-
-
- - -
-
-
-

🔌 --

-
-
StatusRUNNING
-
IP Address--
-
Netmask--
-
Gateway--
-
MAC--
-
MTU1500
-
-
-
-

📜 DHCP

-
ModeClient (auto)
-
Last Renew--
-
- - -
-
-
-
- -
- - - - - diff --git a/examples/webpanel/content/www/xterm.css b/examples/webpanel/content/www/xterm.css deleted file mode 100644 index e97b64390..000000000 --- a/examples/webpanel/content/www/xterm.css +++ /dev/null @@ -1,218 +0,0 @@ -/** - * Copyright (c) 2014 The xterm.js authors. All rights reserved. - * Copyright (c) 2012-2013, Christopher Jeffrey (MIT License) - * https://github.com/chjj/term.js - * @license MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - * Originally forked from (with the author's permission): - * Fabrice Bellard's javascript vt100 for jslinux: - * http://bellard.org/jslinux/ - * Copyright (c) 2011 Fabrice Bellard - * The original design remains. The terminal itself - * has been extended to include xterm CSI codes, among - * other features. - */ - -/** - * Default styles for xterm.js - */ - -.xterm { - cursor: text; - position: relative; - user-select: none; - -ms-user-select: none; - -webkit-user-select: none; -} - -.xterm.focus, -.xterm:focus { - outline: none; -} - -.xterm .xterm-helpers { - position: absolute; - top: 0; - /** - * The z-index of the helpers must be higher than the canvases in order for - * IMEs to appear on top. - */ - z-index: 5; -} - -.xterm .xterm-helper-textarea { - padding: 0; - border: 0; - margin: 0; - /* Move textarea out of the screen to the far left, so that the cursor is not visible */ - position: absolute; - opacity: 0; - left: -9999em; - top: 0; - width: 0; - height: 0; - z-index: -5; - /** Prevent wrapping so the IME appears against the textarea at the correct position */ - white-space: nowrap; - overflow: hidden; - resize: none; -} - -.xterm .composition-view { - /* TODO: Composition position got messed up somewhere */ - background: #000; - color: #FFF; - display: none; - position: absolute; - white-space: nowrap; - z-index: 1; -} - -.xterm .composition-view.active { - display: block; -} - -.xterm .xterm-viewport { - /* On OS X this is required in order for the scroll bar to appear fully opaque */ - background-color: #000; - overflow-y: scroll; - cursor: default; - position: absolute; - right: 0; - left: 0; - top: 0; - bottom: 0; -} - -.xterm .xterm-screen { - position: relative; -} - -.xterm .xterm-screen canvas { - position: absolute; - left: 0; - top: 0; -} - -.xterm .xterm-scroll-area { - visibility: hidden; -} - -.xterm-char-measure-element { - display: inline-block; - visibility: hidden; - position: absolute; - top: 0; - left: -9999em; - line-height: normal; -} - -.xterm.enable-mouse-events { - /* When mouse events are enabled (eg. tmux), revert to the standard pointer cursor */ - cursor: default; -} - -.xterm.xterm-cursor-pointer, -.xterm .xterm-cursor-pointer { - cursor: pointer; -} - -.xterm.column-select.focus { - /* Column selection mode */ - cursor: crosshair; -} - -.xterm .xterm-accessibility:not(.debug), -.xterm .xterm-message { - position: absolute; - left: 0; - top: 0; - bottom: 0; - right: 0; - z-index: 10; - color: transparent; - pointer-events: none; -} - -.xterm .xterm-accessibility-tree:not(.debug) *::selection { - color: transparent; -} - -.xterm .xterm-accessibility-tree { - user-select: text; - white-space: pre; -} - -.xterm .live-region { - position: absolute; - left: -9999px; - width: 1px; - height: 1px; - overflow: hidden; -} - -.xterm-dim { - /* Dim should not apply to background, so the opacity of the foreground color is applied - * explicitly in the generated class and reset to 1 here */ - opacity: 1 !important; -} - -.xterm-underline-1 { text-decoration: underline; } -.xterm-underline-2 { text-decoration: double underline; } -.xterm-underline-3 { text-decoration: wavy underline; } -.xterm-underline-4 { text-decoration: dotted underline; } -.xterm-underline-5 { text-decoration: dashed underline; } - -.xterm-overline { - text-decoration: overline; -} - -.xterm-overline.xterm-underline-1 { text-decoration: overline underline; } -.xterm-overline.xterm-underline-2 { text-decoration: overline double underline; } -.xterm-overline.xterm-underline-3 { text-decoration: overline wavy underline; } -.xterm-overline.xterm-underline-4 { text-decoration: overline dotted underline; } -.xterm-overline.xterm-underline-5 { text-decoration: overline dashed underline; } - -.xterm-strikethrough { - text-decoration: line-through; -} - -.xterm-screen .xterm-decoration-container .xterm-decoration { - z-index: 6; - position: absolute; -} - -.xterm-screen .xterm-decoration-container .xterm-decoration.xterm-decoration-top-layer { - z-index: 7; -} - -.xterm-decoration-overview-ruler { - z-index: 8; - position: absolute; - top: 0; - right: 0; - pointer-events: none; -} - -.xterm-decoration-top { - z-index: 2; - position: relative; -} diff --git a/examples/webpanel/content/www/xterm.min.js b/examples/webpanel/content/www/xterm.min.js deleted file mode 100644 index 0a51bfb69..000000000 --- a/examples/webpanel/content/www/xterm.min.js +++ /dev/null @@ -1,8 +0,0 @@ -/** - * Skipped minification because the original files appears to be already minified. - * Original file: /npm/@xterm/xterm@5.5.0/lib/xterm.js - * - * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files - */ -!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var i=t();for(var s in i)("object"==typeof exports?exports:e)[s]=i[s]}}(globalThis,(()=>(()=>{"use strict";var e={4567:function(e,t,i){var s=this&&this.__decorate||function(e,t,i,s){var r,n=arguments.length,o=n<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,i,s);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(o=(n<3?r(o):n>3?r(t,i,o):r(t,i))||o);return n>3&&o&&Object.defineProperty(t,i,o),o},r=this&&this.__param||function(e,t){return function(i,s){t(i,s,e)}};Object.defineProperty(t,"__esModule",{value:!0}),t.AccessibilityManager=void 0;const n=i(9042),o=i(9924),a=i(844),h=i(4725),c=i(2585),l=i(3656);let d=t.AccessibilityManager=class extends a.Disposable{constructor(e,t,i,s){super(),this._terminal=e,this._coreBrowserService=i,this._renderService=s,this._rowColumns=new WeakMap,this._liveRegionLineCount=0,this._charsToConsume=[],this._charsToAnnounce="",this._accessibilityContainer=this._coreBrowserService.mainDocument.createElement("div"),this._accessibilityContainer.classList.add("xterm-accessibility"),this._rowContainer=this._coreBrowserService.mainDocument.createElement("div"),this._rowContainer.setAttribute("role","list"),this._rowContainer.classList.add("xterm-accessibility-tree"),this._rowElements=[];for(let e=0;ethis._handleBoundaryFocus(e,0),this._bottomBoundaryFocusListener=e=>this._handleBoundaryFocus(e,1),this._rowElements[0].addEventListener("focus",this._topBoundaryFocusListener),this._rowElements[this._rowElements.length-1].addEventListener("focus",this._bottomBoundaryFocusListener),this._refreshRowsDimensions(),this._accessibilityContainer.appendChild(this._rowContainer),this._liveRegion=this._coreBrowserService.mainDocument.createElement("div"),this._liveRegion.classList.add("live-region"),this._liveRegion.setAttribute("aria-live","assertive"),this._accessibilityContainer.appendChild(this._liveRegion),this._liveRegionDebouncer=this.register(new o.TimeBasedDebouncer(this._renderRows.bind(this))),!this._terminal.element)throw new Error("Cannot enable accessibility before Terminal.open");this._terminal.element.insertAdjacentElement("afterbegin",this._accessibilityContainer),this.register(this._terminal.onResize((e=>this._handleResize(e.rows)))),this.register(this._terminal.onRender((e=>this._refreshRows(e.start,e.end)))),this.register(this._terminal.onScroll((()=>this._refreshRows()))),this.register(this._terminal.onA11yChar((e=>this._handleChar(e)))),this.register(this._terminal.onLineFeed((()=>this._handleChar("\n")))),this.register(this._terminal.onA11yTab((e=>this._handleTab(e)))),this.register(this._terminal.onKey((e=>this._handleKey(e.key)))),this.register(this._terminal.onBlur((()=>this._clearLiveRegion()))),this.register(this._renderService.onDimensionsChange((()=>this._refreshRowsDimensions()))),this.register((0,l.addDisposableDomListener)(document,"selectionchange",(()=>this._handleSelectionChange()))),this.register(this._coreBrowserService.onDprChange((()=>this._refreshRowsDimensions()))),this._refreshRows(),this.register((0,a.toDisposable)((()=>{this._accessibilityContainer.remove(),this._rowElements.length=0})))}_handleTab(e){for(let t=0;t0?this._charsToConsume.shift()!==e&&(this._charsToAnnounce+=e):this._charsToAnnounce+=e,"\n"===e&&(this._liveRegionLineCount++,21===this._liveRegionLineCount&&(this._liveRegion.textContent+=n.tooMuchOutput)))}_clearLiveRegion(){this._liveRegion.textContent="",this._liveRegionLineCount=0}_handleKey(e){this._clearLiveRegion(),/\p{Control}/u.test(e)||this._charsToConsume.push(e)}_refreshRows(e,t){this._liveRegionDebouncer.refresh(e,t,this._terminal.rows)}_renderRows(e,t){const i=this._terminal.buffer,s=i.lines.length.toString();for(let r=e;r<=t;r++){const e=i.lines.get(i.ydisp+r),t=[],n=e?.translateToString(!0,void 0,void 0,t)||"",o=(i.ydisp+r+1).toString(),a=this._rowElements[r];a&&(0===n.length?(a.innerText="ย ",this._rowColumns.set(a,[0,1])):(a.textContent=n,this._rowColumns.set(a,t)),a.setAttribute("aria-posinset",o),a.setAttribute("aria-setsize",s))}this._announceCharacters()}_announceCharacters(){0!==this._charsToAnnounce.length&&(this._liveRegion.textContent+=this._charsToAnnounce,this._charsToAnnounce="")}_handleBoundaryFocus(e,t){const i=e.target,s=this._rowElements[0===t?1:this._rowElements.length-2];if(i.getAttribute("aria-posinset")===(0===t?"1":`${this._terminal.buffer.lines.length}`))return;if(e.relatedTarget!==s)return;let r,n;if(0===t?(r=i,n=this._rowElements.pop(),this._rowContainer.removeChild(n)):(r=this._rowElements.shift(),n=i,this._rowContainer.removeChild(r)),r.removeEventListener("focus",this._topBoundaryFocusListener),n.removeEventListener("focus",this._bottomBoundaryFocusListener),0===t){const e=this._createAccessibilityTreeNode();this._rowElements.unshift(e),this._rowContainer.insertAdjacentElement("afterbegin",e)}else{const e=this._createAccessibilityTreeNode();this._rowElements.push(e),this._rowContainer.appendChild(e)}this._rowElements[0].addEventListener("focus",this._topBoundaryFocusListener),this._rowElements[this._rowElements.length-1].addEventListener("focus",this._bottomBoundaryFocusListener),this._terminal.scrollLines(0===t?-1:1),this._rowElements[0===t?1:this._rowElements.length-2].focus(),e.preventDefault(),e.stopImmediatePropagation()}_handleSelectionChange(){if(0===this._rowElements.length)return;const e=document.getSelection();if(!e)return;if(e.isCollapsed)return void(this._rowContainer.contains(e.anchorNode)&&this._terminal.clearSelection());if(!e.anchorNode||!e.focusNode)return void console.error("anchorNode and/or focusNode are null");let t={node:e.anchorNode,offset:e.anchorOffset},i={node:e.focusNode,offset:e.focusOffset};if((t.node.compareDocumentPosition(i.node)&Node.DOCUMENT_POSITION_PRECEDING||t.node===i.node&&t.offset>i.offset)&&([t,i]=[i,t]),t.node.compareDocumentPosition(this._rowElements[0])&(Node.DOCUMENT_POSITION_CONTAINED_BY|Node.DOCUMENT_POSITION_FOLLOWING)&&(t={node:this._rowElements[0].childNodes[0],offset:0}),!this._rowContainer.contains(t.node))return;const s=this._rowElements.slice(-1)[0];if(i.node.compareDocumentPosition(s)&(Node.DOCUMENT_POSITION_CONTAINED_BY|Node.DOCUMENT_POSITION_PRECEDING)&&(i={node:s,offset:s.textContent?.length??0}),!this._rowContainer.contains(i.node))return;const r=({node:e,offset:t})=>{const i=e instanceof Text?e.parentNode:e;let s=parseInt(i?.getAttribute("aria-posinset"),10)-1;if(isNaN(s))return console.warn("row is invalid. Race condition?"),null;const r=this._rowColumns.get(i);if(!r)return console.warn("columns is null. Race condition?"),null;let n=t=this._terminal.cols&&(++s,n=0),{row:s,column:n}},n=r(t),o=r(i);if(n&&o){if(n.row>o.row||n.row===o.row&&n.column>=o.column)throw new Error("invalid range");this._terminal.select(n.column,n.row,(o.row-n.row)*this._terminal.cols-n.column+o.column)}}_handleResize(e){this._rowElements[this._rowElements.length-1].removeEventListener("focus",this._bottomBoundaryFocusListener);for(let e=this._rowContainer.children.length;ee;)this._rowContainer.removeChild(this._rowElements.pop());this._rowElements[this._rowElements.length-1].addEventListener("focus",this._bottomBoundaryFocusListener),this._refreshRowsDimensions()}_createAccessibilityTreeNode(){const e=this._coreBrowserService.mainDocument.createElement("div");return e.setAttribute("role","listitem"),e.tabIndex=-1,this._refreshRowDimensions(e),e}_refreshRowsDimensions(){if(this._renderService.dimensions.css.cell.height){this._accessibilityContainer.style.width=`${this._renderService.dimensions.css.canvas.width}px`,this._rowElements.length!==this._terminal.rows&&this._handleResize(this._terminal.rows);for(let e=0;e{function i(e){return e.replace(/\r?\n/g,"\r")}function s(e,t){return t?"[200~"+e+"[201~":e}function r(e,t,r,n){e=s(e=i(e),r.decPrivateModes.bracketedPasteMode&&!0!==n.rawOptions.ignoreBracketedPasteMode),r.triggerDataEvent(e,!0),t.value=""}function n(e,t,i){const s=i.getBoundingClientRect(),r=e.clientX-s.left-10,n=e.clientY-s.top-10;t.style.width="20px",t.style.height="20px",t.style.left=`${r}px`,t.style.top=`${n}px`,t.style.zIndex="1000",t.focus()}Object.defineProperty(t,"__esModule",{value:!0}),t.rightClickHandler=t.moveTextAreaUnderMouseCursor=t.paste=t.handlePasteEvent=t.copyHandler=t.bracketTextForPaste=t.prepareTextForTerminal=void 0,t.prepareTextForTerminal=i,t.bracketTextForPaste=s,t.copyHandler=function(e,t){e.clipboardData&&e.clipboardData.setData("text/plain",t.selectionText),e.preventDefault()},t.handlePasteEvent=function(e,t,i,s){e.stopPropagation(),e.clipboardData&&r(e.clipboardData.getData("text/plain"),t,i,s)},t.paste=r,t.moveTextAreaUnderMouseCursor=n,t.rightClickHandler=function(e,t,i,s,r){n(e,t,i),r&&s.rightClickSelect(e),t.value=s.selectionText,t.select()}},7239:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ColorContrastCache=void 0;const s=i(1505);t.ColorContrastCache=class{constructor(){this._color=new s.TwoKeyMap,this._css=new s.TwoKeyMap}setCss(e,t,i){this._css.set(e,t,i)}getCss(e,t){return this._css.get(e,t)}setColor(e,t,i){this._color.set(e,t,i)}getColor(e,t){return this._color.get(e,t)}clear(){this._color.clear(),this._css.clear()}}},3656:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.addDisposableDomListener=void 0,t.addDisposableDomListener=function(e,t,i,s){e.addEventListener(t,i,s);let r=!1;return{dispose:()=>{r||(r=!0,e.removeEventListener(t,i,s))}}}},3551:function(e,t,i){var s=this&&this.__decorate||function(e,t,i,s){var r,n=arguments.length,o=n<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,i,s);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(o=(n<3?r(o):n>3?r(t,i,o):r(t,i))||o);return n>3&&o&&Object.defineProperty(t,i,o),o},r=this&&this.__param||function(e,t){return function(i,s){t(i,s,e)}};Object.defineProperty(t,"__esModule",{value:!0}),t.Linkifier=void 0;const n=i(3656),o=i(8460),a=i(844),h=i(2585),c=i(4725);let l=t.Linkifier=class extends a.Disposable{get currentLink(){return this._currentLink}constructor(e,t,i,s,r){super(),this._element=e,this._mouseService=t,this._renderService=i,this._bufferService=s,this._linkProviderService=r,this._linkCacheDisposables=[],this._isMouseOut=!0,this._wasResized=!1,this._activeLine=-1,this._onShowLinkUnderline=this.register(new o.EventEmitter),this.onShowLinkUnderline=this._onShowLinkUnderline.event,this._onHideLinkUnderline=this.register(new o.EventEmitter),this.onHideLinkUnderline=this._onHideLinkUnderline.event,this.register((0,a.getDisposeArrayDisposable)(this._linkCacheDisposables)),this.register((0,a.toDisposable)((()=>{this._lastMouseEvent=void 0,this._activeProviderReplies?.clear()}))),this.register(this._bufferService.onResize((()=>{this._clearCurrentLink(),this._wasResized=!0}))),this.register((0,n.addDisposableDomListener)(this._element,"mouseleave",(()=>{this._isMouseOut=!0,this._clearCurrentLink()}))),this.register((0,n.addDisposableDomListener)(this._element,"mousemove",this._handleMouseMove.bind(this))),this.register((0,n.addDisposableDomListener)(this._element,"mousedown",this._handleMouseDown.bind(this))),this.register((0,n.addDisposableDomListener)(this._element,"mouseup",this._handleMouseUp.bind(this)))}_handleMouseMove(e){this._lastMouseEvent=e;const t=this._positionFromMouseEvent(e,this._element,this._mouseService);if(!t)return;this._isMouseOut=!1;const i=e.composedPath();for(let e=0;e{e?.forEach((e=>{e.link.dispose&&e.link.dispose()}))})),this._activeProviderReplies=new Map,this._activeLine=e.y);let i=!1;for(const[s,r]of this._linkProviderService.linkProviders.entries())if(t){const t=this._activeProviderReplies?.get(s);t&&(i=this._checkLinkProviderResult(s,e,i))}else r.provideLinks(e.y,(t=>{if(this._isMouseOut)return;const r=t?.map((e=>({link:e})));this._activeProviderReplies?.set(s,r),i=this._checkLinkProviderResult(s,e,i),this._activeProviderReplies?.size===this._linkProviderService.linkProviders.length&&this._removeIntersectingLinks(e.y,this._activeProviderReplies)}))}_removeIntersectingLinks(e,t){const i=new Set;for(let s=0;se?this._bufferService.cols:s.link.range.end.x;for(let e=n;e<=o;e++){if(i.has(e)){r.splice(t--,1);break}i.add(e)}}}}_checkLinkProviderResult(e,t,i){if(!this._activeProviderReplies)return i;const s=this._activeProviderReplies.get(e);let r=!1;for(let t=0;tthis._linkAtPosition(e.link,t)));e&&(i=!0,this._handleNewLink(e))}if(this._activeProviderReplies.size===this._linkProviderService.linkProviders.length&&!i)for(let e=0;ethis._linkAtPosition(e.link,t)));if(s){i=!0,this._handleNewLink(s);break}}return i}_handleMouseDown(){this._mouseDownLink=this._currentLink}_handleMouseUp(e){if(!this._currentLink)return;const t=this._positionFromMouseEvent(e,this._element,this._mouseService);t&&this._mouseDownLink===this._currentLink&&this._linkAtPosition(this._currentLink.link,t)&&this._currentLink.link.activate(e,this._currentLink.link.text)}_clearCurrentLink(e,t){this._currentLink&&this._lastMouseEvent&&(!e||!t||this._currentLink.link.range.start.y>=e&&this._currentLink.link.range.end.y<=t)&&(this._linkLeave(this._element,this._currentLink.link,this._lastMouseEvent),this._currentLink=void 0,(0,a.disposeArray)(this._linkCacheDisposables))}_handleNewLink(e){if(!this._lastMouseEvent)return;const t=this._positionFromMouseEvent(this._lastMouseEvent,this._element,this._mouseService);t&&this._linkAtPosition(e.link,t)&&(this._currentLink=e,this._currentLink.state={decorations:{underline:void 0===e.link.decorations||e.link.decorations.underline,pointerCursor:void 0===e.link.decorations||e.link.decorations.pointerCursor},isHovered:!0},this._linkHover(this._element,e.link,this._lastMouseEvent),e.link.decorations={},Object.defineProperties(e.link.decorations,{pointerCursor:{get:()=>this._currentLink?.state?.decorations.pointerCursor,set:e=>{this._currentLink?.state&&this._currentLink.state.decorations.pointerCursor!==e&&(this._currentLink.state.decorations.pointerCursor=e,this._currentLink.state.isHovered&&this._element.classList.toggle("xterm-cursor-pointer",e))}},underline:{get:()=>this._currentLink?.state?.decorations.underline,set:t=>{this._currentLink?.state&&this._currentLink?.state?.decorations.underline!==t&&(this._currentLink.state.decorations.underline=t,this._currentLink.state.isHovered&&this._fireUnderlineEvent(e.link,t))}}}),this._linkCacheDisposables.push(this._renderService.onRenderedViewportChange((e=>{if(!this._currentLink)return;const t=0===e.start?0:e.start+1+this._bufferService.buffer.ydisp,i=this._bufferService.buffer.ydisp+1+e.end;if(this._currentLink.link.range.start.y>=t&&this._currentLink.link.range.end.y<=i&&(this._clearCurrentLink(t,i),this._lastMouseEvent)){const e=this._positionFromMouseEvent(this._lastMouseEvent,this._element,this._mouseService);e&&this._askForLink(e,!1)}}))))}_linkHover(e,t,i){this._currentLink?.state&&(this._currentLink.state.isHovered=!0,this._currentLink.state.decorations.underline&&this._fireUnderlineEvent(t,!0),this._currentLink.state.decorations.pointerCursor&&e.classList.add("xterm-cursor-pointer")),t.hover&&t.hover(i,t.text)}_fireUnderlineEvent(e,t){const i=e.range,s=this._bufferService.buffer.ydisp,r=this._createLinkUnderlineEvent(i.start.x-1,i.start.y-s-1,i.end.x,i.end.y-s-1,void 0);(t?this._onShowLinkUnderline:this._onHideLinkUnderline).fire(r)}_linkLeave(e,t,i){this._currentLink?.state&&(this._currentLink.state.isHovered=!1,this._currentLink.state.decorations.underline&&this._fireUnderlineEvent(t,!1),this._currentLink.state.decorations.pointerCursor&&e.classList.remove("xterm-cursor-pointer")),t.leave&&t.leave(i,t.text)}_linkAtPosition(e,t){const i=e.range.start.y*this._bufferService.cols+e.range.start.x,s=e.range.end.y*this._bufferService.cols+e.range.end.x,r=t.y*this._bufferService.cols+t.x;return i<=r&&r<=s}_positionFromMouseEvent(e,t,i){const s=i.getCoords(e,t,this._bufferService.cols,this._bufferService.rows);if(s)return{x:s[0],y:s[1]+this._bufferService.buffer.ydisp}}_createLinkUnderlineEvent(e,t,i,s,r){return{x1:e,y1:t,x2:i,y2:s,cols:this._bufferService.cols,fg:r}}};t.Linkifier=l=s([r(1,c.IMouseService),r(2,c.IRenderService),r(3,h.IBufferService),r(4,c.ILinkProviderService)],l)},9042:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.tooMuchOutput=t.promptLabel=void 0,t.promptLabel="Terminal input",t.tooMuchOutput="Too much output to announce, navigate to rows manually to read"},3730:function(e,t,i){var s=this&&this.__decorate||function(e,t,i,s){var r,n=arguments.length,o=n<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,i,s);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(o=(n<3?r(o):n>3?r(t,i,o):r(t,i))||o);return n>3&&o&&Object.defineProperty(t,i,o),o},r=this&&this.__param||function(e,t){return function(i,s){t(i,s,e)}};Object.defineProperty(t,"__esModule",{value:!0}),t.OscLinkProvider=void 0;const n=i(511),o=i(2585);let a=t.OscLinkProvider=class{constructor(e,t,i){this._bufferService=e,this._optionsService=t,this._oscLinkService=i}provideLinks(e,t){const i=this._bufferService.buffer.lines.get(e-1);if(!i)return void t(void 0);const s=[],r=this._optionsService.rawOptions.linkHandler,o=new n.CellData,a=i.getTrimmedLength();let c=-1,l=-1,d=!1;for(let t=0;tr?r.activate(e,t,n):h(0,t),hover:(e,t)=>r?.hover?.(e,t,n),leave:(e,t)=>r?.leave?.(e,t,n)})}d=!1,o.hasExtendedAttrs()&&o.extended.urlId?(l=t,c=o.extended.urlId):(l=-1,c=-1)}}t(s)}};function h(e,t){if(confirm(`Do you want to navigate to ${t}?\n\nWARNING: This link could potentially be dangerous`)){const e=window.open();if(e){try{e.opener=null}catch{}e.location.href=t}else console.warn("Opening link blocked as opener could not be cleared")}}t.OscLinkProvider=a=s([r(0,o.IBufferService),r(1,o.IOptionsService),r(2,o.IOscLinkService)],a)},6193:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.RenderDebouncer=void 0,t.RenderDebouncer=class{constructor(e,t){this._renderCallback=e,this._coreBrowserService=t,this._refreshCallbacks=[]}dispose(){this._animationFrame&&(this._coreBrowserService.window.cancelAnimationFrame(this._animationFrame),this._animationFrame=void 0)}addRefreshCallback(e){return this._refreshCallbacks.push(e),this._animationFrame||(this._animationFrame=this._coreBrowserService.window.requestAnimationFrame((()=>this._innerRefresh()))),this._animationFrame}refresh(e,t,i){this._rowCount=i,e=void 0!==e?e:0,t=void 0!==t?t:this._rowCount-1,this._rowStart=void 0!==this._rowStart?Math.min(this._rowStart,e):e,this._rowEnd=void 0!==this._rowEnd?Math.max(this._rowEnd,t):t,this._animationFrame||(this._animationFrame=this._coreBrowserService.window.requestAnimationFrame((()=>this._innerRefresh())))}_innerRefresh(){if(this._animationFrame=void 0,void 0===this._rowStart||void 0===this._rowEnd||void 0===this._rowCount)return void this._runRefreshCallbacks();const e=Math.max(this._rowStart,0),t=Math.min(this._rowEnd,this._rowCount-1);this._rowStart=void 0,this._rowEnd=void 0,this._renderCallback(e,t),this._runRefreshCallbacks()}_runRefreshCallbacks(){for(const e of this._refreshCallbacks)e(0);this._refreshCallbacks=[]}}},3236:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Terminal=void 0;const s=i(3614),r=i(3656),n=i(3551),o=i(9042),a=i(3730),h=i(1680),c=i(3107),l=i(5744),d=i(2950),_=i(1296),u=i(428),f=i(4269),v=i(5114),p=i(8934),g=i(3230),m=i(9312),S=i(4725),C=i(6731),b=i(8055),w=i(8969),y=i(8460),E=i(844),k=i(6114),L=i(8437),D=i(2584),R=i(7399),x=i(5941),A=i(9074),B=i(2585),T=i(5435),M=i(4567),O=i(779);class P extends w.CoreTerminal{get onFocus(){return this._onFocus.event}get onBlur(){return this._onBlur.event}get onA11yChar(){return this._onA11yCharEmitter.event}get onA11yTab(){return this._onA11yTabEmitter.event}get onWillOpen(){return this._onWillOpen.event}constructor(e={}){super(e),this.browser=k,this._keyDownHandled=!1,this._keyDownSeen=!1,this._keyPressHandled=!1,this._unprocessedDeadKey=!1,this._accessibilityManager=this.register(new E.MutableDisposable),this._onCursorMove=this.register(new y.EventEmitter),this.onCursorMove=this._onCursorMove.event,this._onKey=this.register(new y.EventEmitter),this.onKey=this._onKey.event,this._onRender=this.register(new y.EventEmitter),this.onRender=this._onRender.event,this._onSelectionChange=this.register(new y.EventEmitter),this.onSelectionChange=this._onSelectionChange.event,this._onTitleChange=this.register(new y.EventEmitter),this.onTitleChange=this._onTitleChange.event,this._onBell=this.register(new y.EventEmitter),this.onBell=this._onBell.event,this._onFocus=this.register(new y.EventEmitter),this._onBlur=this.register(new y.EventEmitter),this._onA11yCharEmitter=this.register(new y.EventEmitter),this._onA11yTabEmitter=this.register(new y.EventEmitter),this._onWillOpen=this.register(new y.EventEmitter),this._setup(),this._decorationService=this._instantiationService.createInstance(A.DecorationService),this._instantiationService.setService(B.IDecorationService,this._decorationService),this._linkProviderService=this._instantiationService.createInstance(O.LinkProviderService),this._instantiationService.setService(S.ILinkProviderService,this._linkProviderService),this._linkProviderService.registerLinkProvider(this._instantiationService.createInstance(a.OscLinkProvider)),this.register(this._inputHandler.onRequestBell((()=>this._onBell.fire()))),this.register(this._inputHandler.onRequestRefreshRows(((e,t)=>this.refresh(e,t)))),this.register(this._inputHandler.onRequestSendFocus((()=>this._reportFocus()))),this.register(this._inputHandler.onRequestReset((()=>this.reset()))),this.register(this._inputHandler.onRequestWindowsOptionsReport((e=>this._reportWindowsOptions(e)))),this.register(this._inputHandler.onColor((e=>this._handleColorEvent(e)))),this.register((0,y.forwardEvent)(this._inputHandler.onCursorMove,this._onCursorMove)),this.register((0,y.forwardEvent)(this._inputHandler.onTitleChange,this._onTitleChange)),this.register((0,y.forwardEvent)(this._inputHandler.onA11yChar,this._onA11yCharEmitter)),this.register((0,y.forwardEvent)(this._inputHandler.onA11yTab,this._onA11yTabEmitter)),this.register(this._bufferService.onResize((e=>this._afterResize(e.cols,e.rows)))),this.register((0,E.toDisposable)((()=>{this._customKeyEventHandler=void 0,this.element?.parentNode?.removeChild(this.element)})))}_handleColorEvent(e){if(this._themeService)for(const t of e){let e,i="";switch(t.index){case 256:e="foreground",i="10";break;case 257:e="background",i="11";break;case 258:e="cursor",i="12";break;default:e="ansi",i="4;"+t.index}switch(t.type){case 0:const s=b.color.toColorRGB("ansi"===e?this._themeService.colors.ansi[t.index]:this._themeService.colors[e]);this.coreService.triggerDataEvent(`${D.C0.ESC}]${i};${(0,x.toRgbString)(s)}${D.C1_ESCAPED.ST}`);break;case 1:if("ansi"===e)this._themeService.modifyColors((e=>e.ansi[t.index]=b.channels.toColor(...t.color)));else{const i=e;this._themeService.modifyColors((e=>e[i]=b.channels.toColor(...t.color)))}break;case 2:this._themeService.restoreColor(t.index)}}}_setup(){super._setup(),this._customKeyEventHandler=void 0}get buffer(){return this.buffers.active}focus(){this.textarea&&this.textarea.focus({preventScroll:!0})}_handleScreenReaderModeOptionChange(e){e?!this._accessibilityManager.value&&this._renderService&&(this._accessibilityManager.value=this._instantiationService.createInstance(M.AccessibilityManager,this)):this._accessibilityManager.clear()}_handleTextAreaFocus(e){this.coreService.decPrivateModes.sendFocus&&this.coreService.triggerDataEvent(D.C0.ESC+"[I"),this.element.classList.add("focus"),this._showCursor(),this._onFocus.fire()}blur(){return this.textarea?.blur()}_handleTextAreaBlur(){this.textarea.value="",this.refresh(this.buffer.y,this.buffer.y),this.coreService.decPrivateModes.sendFocus&&this.coreService.triggerDataEvent(D.C0.ESC+"[O"),this.element.classList.remove("focus"),this._onBlur.fire()}_syncTextArea(){if(!this.textarea||!this.buffer.isCursorInViewport||this._compositionHelper.isComposing||!this._renderService)return;const e=this.buffer.ybase+this.buffer.y,t=this.buffer.lines.get(e);if(!t)return;const i=Math.min(this.buffer.x,this.cols-1),s=this._renderService.dimensions.css.cell.height,r=t.getWidth(i),n=this._renderService.dimensions.css.cell.width*r,o=this.buffer.y*this._renderService.dimensions.css.cell.height,a=i*this._renderService.dimensions.css.cell.width;this.textarea.style.left=a+"px",this.textarea.style.top=o+"px",this.textarea.style.width=n+"px",this.textarea.style.height=s+"px",this.textarea.style.lineHeight=s+"px",this.textarea.style.zIndex="-5"}_initGlobal(){this._bindKeys(),this.register((0,r.addDisposableDomListener)(this.element,"copy",(e=>{this.hasSelection()&&(0,s.copyHandler)(e,this._selectionService)})));const e=e=>(0,s.handlePasteEvent)(e,this.textarea,this.coreService,this.optionsService);this.register((0,r.addDisposableDomListener)(this.textarea,"paste",e)),this.register((0,r.addDisposableDomListener)(this.element,"paste",e)),k.isFirefox?this.register((0,r.addDisposableDomListener)(this.element,"mousedown",(e=>{2===e.button&&(0,s.rightClickHandler)(e,this.textarea,this.screenElement,this._selectionService,this.options.rightClickSelectsWord)}))):this.register((0,r.addDisposableDomListener)(this.element,"contextmenu",(e=>{(0,s.rightClickHandler)(e,this.textarea,this.screenElement,this._selectionService,this.options.rightClickSelectsWord)}))),k.isLinux&&this.register((0,r.addDisposableDomListener)(this.element,"auxclick",(e=>{1===e.button&&(0,s.moveTextAreaUnderMouseCursor)(e,this.textarea,this.screenElement)})))}_bindKeys(){this.register((0,r.addDisposableDomListener)(this.textarea,"keyup",(e=>this._keyUp(e)),!0)),this.register((0,r.addDisposableDomListener)(this.textarea,"keydown",(e=>this._keyDown(e)),!0)),this.register((0,r.addDisposableDomListener)(this.textarea,"keypress",(e=>this._keyPress(e)),!0)),this.register((0,r.addDisposableDomListener)(this.textarea,"compositionstart",(()=>this._compositionHelper.compositionstart()))),this.register((0,r.addDisposableDomListener)(this.textarea,"compositionupdate",(e=>this._compositionHelper.compositionupdate(e)))),this.register((0,r.addDisposableDomListener)(this.textarea,"compositionend",(()=>this._compositionHelper.compositionend()))),this.register((0,r.addDisposableDomListener)(this.textarea,"input",(e=>this._inputEvent(e)),!0)),this.register(this.onRender((()=>this._compositionHelper.updateCompositionElements())))}open(e){if(!e)throw new Error("Terminal requires a parent element.");if(e.isConnected||this._logService.debug("Terminal.open was called on an element that was not attached to the DOM"),this.element?.ownerDocument.defaultView&&this._coreBrowserService)return void(this.element.ownerDocument.defaultView!==this._coreBrowserService.window&&(this._coreBrowserService.window=this.element.ownerDocument.defaultView));this._document=e.ownerDocument,this.options.documentOverride&&this.options.documentOverride instanceof Document&&(this._document=this.optionsService.rawOptions.documentOverride),this.element=this._document.createElement("div"),this.element.dir="ltr",this.element.classList.add("terminal"),this.element.classList.add("xterm"),e.appendChild(this.element);const t=this._document.createDocumentFragment();this._viewportElement=this._document.createElement("div"),this._viewportElement.classList.add("xterm-viewport"),t.appendChild(this._viewportElement),this._viewportScrollArea=this._document.createElement("div"),this._viewportScrollArea.classList.add("xterm-scroll-area"),this._viewportElement.appendChild(this._viewportScrollArea),this.screenElement=this._document.createElement("div"),this.screenElement.classList.add("xterm-screen"),this.register((0,r.addDisposableDomListener)(this.screenElement,"mousemove",(e=>this.updateCursorStyle(e)))),this._helperContainer=this._document.createElement("div"),this._helperContainer.classList.add("xterm-helpers"),this.screenElement.appendChild(this._helperContainer),t.appendChild(this.screenElement),this.textarea=this._document.createElement("textarea"),this.textarea.classList.add("xterm-helper-textarea"),this.textarea.setAttribute("aria-label",o.promptLabel),k.isChromeOS||this.textarea.setAttribute("aria-multiline","false"),this.textarea.setAttribute("autocorrect","off"),this.textarea.setAttribute("autocapitalize","off"),this.textarea.setAttribute("spellcheck","false"),this.textarea.tabIndex=0,this._coreBrowserService=this.register(this._instantiationService.createInstance(v.CoreBrowserService,this.textarea,e.ownerDocument.defaultView??window,this._document??"undefined"!=typeof window?window.document:null)),this._instantiationService.setService(S.ICoreBrowserService,this._coreBrowserService),this.register((0,r.addDisposableDomListener)(this.textarea,"focus",(e=>this._handleTextAreaFocus(e)))),this.register((0,r.addDisposableDomListener)(this.textarea,"blur",(()=>this._handleTextAreaBlur()))),this._helperContainer.appendChild(this.textarea),this._charSizeService=this._instantiationService.createInstance(u.CharSizeService,this._document,this._helperContainer),this._instantiationService.setService(S.ICharSizeService,this._charSizeService),this._themeService=this._instantiationService.createInstance(C.ThemeService),this._instantiationService.setService(S.IThemeService,this._themeService),this._characterJoinerService=this._instantiationService.createInstance(f.CharacterJoinerService),this._instantiationService.setService(S.ICharacterJoinerService,this._characterJoinerService),this._renderService=this.register(this._instantiationService.createInstance(g.RenderService,this.rows,this.screenElement)),this._instantiationService.setService(S.IRenderService,this._renderService),this.register(this._renderService.onRenderedViewportChange((e=>this._onRender.fire(e)))),this.onResize((e=>this._renderService.resize(e.cols,e.rows))),this._compositionView=this._document.createElement("div"),this._compositionView.classList.add("composition-view"),this._compositionHelper=this._instantiationService.createInstance(d.CompositionHelper,this.textarea,this._compositionView),this._helperContainer.appendChild(this._compositionView),this._mouseService=this._instantiationService.createInstance(p.MouseService),this._instantiationService.setService(S.IMouseService,this._mouseService),this.linkifier=this.register(this._instantiationService.createInstance(n.Linkifier,this.screenElement)),this.element.appendChild(t);try{this._onWillOpen.fire(this.element)}catch{}this._renderService.hasRenderer()||this._renderService.setRenderer(this._createRenderer()),this.viewport=this._instantiationService.createInstance(h.Viewport,this._viewportElement,this._viewportScrollArea),this.viewport.onRequestScrollLines((e=>this.scrollLines(e.amount,e.suppressScrollEvent,1))),this.register(this._inputHandler.onRequestSyncScrollBar((()=>this.viewport.syncScrollArea()))),this.register(this.viewport),this.register(this.onCursorMove((()=>{this._renderService.handleCursorMove(),this._syncTextArea()}))),this.register(this.onResize((()=>this._renderService.handleResize(this.cols,this.rows)))),this.register(this.onBlur((()=>this._renderService.handleBlur()))),this.register(this.onFocus((()=>this._renderService.handleFocus()))),this.register(this._renderService.onDimensionsChange((()=>this.viewport.syncScrollArea()))),this._selectionService=this.register(this._instantiationService.createInstance(m.SelectionService,this.element,this.screenElement,this.linkifier)),this._instantiationService.setService(S.ISelectionService,this._selectionService),this.register(this._selectionService.onRequestScrollLines((e=>this.scrollLines(e.amount,e.suppressScrollEvent)))),this.register(this._selectionService.onSelectionChange((()=>this._onSelectionChange.fire()))),this.register(this._selectionService.onRequestRedraw((e=>this._renderService.handleSelectionChanged(e.start,e.end,e.columnSelectMode)))),this.register(this._selectionService.onLinuxMouseSelection((e=>{this.textarea.value=e,this.textarea.focus(),this.textarea.select()}))),this.register(this._onScroll.event((e=>{this.viewport.syncScrollArea(),this._selectionService.refresh()}))),this.register((0,r.addDisposableDomListener)(this._viewportElement,"scroll",(()=>this._selectionService.refresh()))),this.register(this._instantiationService.createInstance(c.BufferDecorationRenderer,this.screenElement)),this.register((0,r.addDisposableDomListener)(this.element,"mousedown",(e=>this._selectionService.handleMouseDown(e)))),this.coreMouseService.areMouseEventsActive?(this._selectionService.disable(),this.element.classList.add("enable-mouse-events")):this._selectionService.enable(),this.options.screenReaderMode&&(this._accessibilityManager.value=this._instantiationService.createInstance(M.AccessibilityManager,this)),this.register(this.optionsService.onSpecificOptionChange("screenReaderMode",(e=>this._handleScreenReaderModeOptionChange(e)))),this.options.overviewRulerWidth&&(this._overviewRulerRenderer=this.register(this._instantiationService.createInstance(l.OverviewRulerRenderer,this._viewportElement,this.screenElement))),this.optionsService.onSpecificOptionChange("overviewRulerWidth",(e=>{!this._overviewRulerRenderer&&e&&this._viewportElement&&this.screenElement&&(this._overviewRulerRenderer=this.register(this._instantiationService.createInstance(l.OverviewRulerRenderer,this._viewportElement,this.screenElement)))})),this._charSizeService.measure(),this.refresh(0,this.rows-1),this._initGlobal(),this.bindMouse()}_createRenderer(){return this._instantiationService.createInstance(_.DomRenderer,this,this._document,this.element,this.screenElement,this._viewportElement,this._helperContainer,this.linkifier)}bindMouse(){const e=this,t=this.element;function i(t){const i=e._mouseService.getMouseReportCoords(t,e.screenElement);if(!i)return!1;let s,r;switch(t.overrideType||t.type){case"mousemove":r=32,void 0===t.buttons?(s=3,void 0!==t.button&&(s=t.button<3?t.button:3)):s=1&t.buttons?0:4&t.buttons?1:2&t.buttons?2:3;break;case"mouseup":r=0,s=t.button<3?t.button:3;break;case"mousedown":r=1,s=t.button<3?t.button:3;break;case"wheel":if(e._customWheelEventHandler&&!1===e._customWheelEventHandler(t))return!1;if(0===e.viewport.getLinesScrolled(t))return!1;r=t.deltaY<0?0:1,s=4;break;default:return!1}return!(void 0===r||void 0===s||s>4)&&e.coreMouseService.triggerMouseEvent({col:i.col,row:i.row,x:i.x,y:i.y,button:s,action:r,ctrl:t.ctrlKey,alt:t.altKey,shift:t.shiftKey})}const s={mouseup:null,wheel:null,mousedrag:null,mousemove:null},n={mouseup:e=>(i(e),e.buttons||(this._document.removeEventListener("mouseup",s.mouseup),s.mousedrag&&this._document.removeEventListener("mousemove",s.mousedrag)),this.cancel(e)),wheel:e=>(i(e),this.cancel(e,!0)),mousedrag:e=>{e.buttons&&i(e)},mousemove:e=>{e.buttons||i(e)}};this.register(this.coreMouseService.onProtocolChange((e=>{e?("debug"===this.optionsService.rawOptions.logLevel&&this._logService.debug("Binding to mouse events:",this.coreMouseService.explainEvents(e)),this.element.classList.add("enable-mouse-events"),this._selectionService.disable()):(this._logService.debug("Unbinding from mouse events."),this.element.classList.remove("enable-mouse-events"),this._selectionService.enable()),8&e?s.mousemove||(t.addEventListener("mousemove",n.mousemove),s.mousemove=n.mousemove):(t.removeEventListener("mousemove",s.mousemove),s.mousemove=null),16&e?s.wheel||(t.addEventListener("wheel",n.wheel,{passive:!1}),s.wheel=n.wheel):(t.removeEventListener("wheel",s.wheel),s.wheel=null),2&e?s.mouseup||(s.mouseup=n.mouseup):(this._document.removeEventListener("mouseup",s.mouseup),s.mouseup=null),4&e?s.mousedrag||(s.mousedrag=n.mousedrag):(this._document.removeEventListener("mousemove",s.mousedrag),s.mousedrag=null)}))),this.coreMouseService.activeProtocol=this.coreMouseService.activeProtocol,this.register((0,r.addDisposableDomListener)(t,"mousedown",(e=>{if(e.preventDefault(),this.focus(),this.coreMouseService.areMouseEventsActive&&!this._selectionService.shouldForceSelection(e))return i(e),s.mouseup&&this._document.addEventListener("mouseup",s.mouseup),s.mousedrag&&this._document.addEventListener("mousemove",s.mousedrag),this.cancel(e)}))),this.register((0,r.addDisposableDomListener)(t,"wheel",(e=>{if(!s.wheel){if(this._customWheelEventHandler&&!1===this._customWheelEventHandler(e))return!1;if(!this.buffer.hasScrollback){const t=this.viewport.getLinesScrolled(e);if(0===t)return;const i=D.C0.ESC+(this.coreService.decPrivateModes.applicationCursorKeys?"O":"[")+(e.deltaY<0?"A":"B");let s="";for(let e=0;e{if(!this.coreMouseService.areMouseEventsActive)return this.viewport.handleTouchStart(e),this.cancel(e)}),{passive:!0})),this.register((0,r.addDisposableDomListener)(t,"touchmove",(e=>{if(!this.coreMouseService.areMouseEventsActive)return this.viewport.handleTouchMove(e)?void 0:this.cancel(e)}),{passive:!1}))}refresh(e,t){this._renderService?.refreshRows(e,t)}updateCursorStyle(e){this._selectionService?.shouldColumnSelect(e)?this.element.classList.add("column-select"):this.element.classList.remove("column-select")}_showCursor(){this.coreService.isCursorInitialized||(this.coreService.isCursorInitialized=!0,this.refresh(this.buffer.y,this.buffer.y))}scrollLines(e,t,i=0){1===i?(super.scrollLines(e,t,i),this.refresh(0,this.rows-1)):this.viewport?.scrollLines(e)}paste(e){(0,s.paste)(e,this.textarea,this.coreService,this.optionsService)}attachCustomKeyEventHandler(e){this._customKeyEventHandler=e}attachCustomWheelEventHandler(e){this._customWheelEventHandler=e}registerLinkProvider(e){return this._linkProviderService.registerLinkProvider(e)}registerCharacterJoiner(e){if(!this._characterJoinerService)throw new Error("Terminal must be opened first");const t=this._characterJoinerService.register(e);return this.refresh(0,this.rows-1),t}deregisterCharacterJoiner(e){if(!this._characterJoinerService)throw new Error("Terminal must be opened first");this._characterJoinerService.deregister(e)&&this.refresh(0,this.rows-1)}get markers(){return this.buffer.markers}registerMarker(e){return this.buffer.addMarker(this.buffer.ybase+this.buffer.y+e)}registerDecoration(e){return this._decorationService.registerDecoration(e)}hasSelection(){return!!this._selectionService&&this._selectionService.hasSelection}select(e,t,i){this._selectionService.setSelection(e,t,i)}getSelection(){return this._selectionService?this._selectionService.selectionText:""}getSelectionPosition(){if(this._selectionService&&this._selectionService.hasSelection)return{start:{x:this._selectionService.selectionStart[0],y:this._selectionService.selectionStart[1]},end:{x:this._selectionService.selectionEnd[0],y:this._selectionService.selectionEnd[1]}}}clearSelection(){this._selectionService?.clearSelection()}selectAll(){this._selectionService?.selectAll()}selectLines(e,t){this._selectionService?.selectLines(e,t)}_keyDown(e){if(this._keyDownHandled=!1,this._keyDownSeen=!0,this._customKeyEventHandler&&!1===this._customKeyEventHandler(e))return!1;const t=this.browser.isMac&&this.options.macOptionIsMeta&&e.altKey;if(!t&&!this._compositionHelper.keydown(e))return this.options.scrollOnUserInput&&this.buffer.ybase!==this.buffer.ydisp&&this.scrollToBottom(),!1;t||"Dead"!==e.key&&"AltGraph"!==e.key||(this._unprocessedDeadKey=!0);const i=(0,R.evaluateKeyboardEvent)(e,this.coreService.decPrivateModes.applicationCursorKeys,this.browser.isMac,this.options.macOptionIsMeta);if(this.updateCursorStyle(e),3===i.type||2===i.type){const t=this.rows-1;return this.scrollLines(2===i.type?-t:t),this.cancel(e,!0)}return 1===i.type&&this.selectAll(),!!this._isThirdLevelShift(this.browser,e)||(i.cancel&&this.cancel(e,!0),!i.key||!!(e.key&&!e.ctrlKey&&!e.altKey&&!e.metaKey&&1===e.key.length&&e.key.charCodeAt(0)>=65&&e.key.charCodeAt(0)<=90)||(this._unprocessedDeadKey?(this._unprocessedDeadKey=!1,!0):(i.key!==D.C0.ETX&&i.key!==D.C0.CR||(this.textarea.value=""),this._onKey.fire({key:i.key,domEvent:e}),this._showCursor(),this.coreService.triggerDataEvent(i.key,!0),!this.optionsService.rawOptions.screenReaderMode||e.altKey||e.ctrlKey?this.cancel(e,!0):void(this._keyDownHandled=!0))))}_isThirdLevelShift(e,t){const i=e.isMac&&!this.options.macOptionIsMeta&&t.altKey&&!t.ctrlKey&&!t.metaKey||e.isWindows&&t.altKey&&t.ctrlKey&&!t.metaKey||e.isWindows&&t.getModifierState("AltGraph");return"keypress"===t.type?i:i&&(!t.keyCode||t.keyCode>47)}_keyUp(e){this._keyDownSeen=!1,this._customKeyEventHandler&&!1===this._customKeyEventHandler(e)||(function(e){return 16===e.keyCode||17===e.keyCode||18===e.keyCode}(e)||this.focus(),this.updateCursorStyle(e),this._keyPressHandled=!1)}_keyPress(e){let t;if(this._keyPressHandled=!1,this._keyDownHandled)return!1;if(this._customKeyEventHandler&&!1===this._customKeyEventHandler(e))return!1;if(this.cancel(e),e.charCode)t=e.charCode;else if(null===e.which||void 0===e.which)t=e.keyCode;else{if(0===e.which||0===e.charCode)return!1;t=e.which}return!(!t||(e.altKey||e.ctrlKey||e.metaKey)&&!this._isThirdLevelShift(this.browser,e)||(t=String.fromCharCode(t),this._onKey.fire({key:t,domEvent:e}),this._showCursor(),this.coreService.triggerDataEvent(t,!0),this._keyPressHandled=!0,this._unprocessedDeadKey=!1,0))}_inputEvent(e){if(e.data&&"insertText"===e.inputType&&(!e.composed||!this._keyDownSeen)&&!this.optionsService.rawOptions.screenReaderMode){if(this._keyPressHandled)return!1;this._unprocessedDeadKey=!1;const t=e.data;return this.coreService.triggerDataEvent(t,!0),this.cancel(e),!0}return!1}resize(e,t){e!==this.cols||t!==this.rows?super.resize(e,t):this._charSizeService&&!this._charSizeService.hasValidSize&&this._charSizeService.measure()}_afterResize(e,t){this._charSizeService?.measure(),this.viewport?.syncScrollArea(!0)}clear(){if(0!==this.buffer.ybase||0!==this.buffer.y){this.buffer.clearAllMarkers(),this.buffer.lines.set(0,this.buffer.lines.get(this.buffer.ybase+this.buffer.y)),this.buffer.lines.length=1,this.buffer.ydisp=0,this.buffer.ybase=0,this.buffer.y=0;for(let e=1;e{Object.defineProperty(t,"__esModule",{value:!0}),t.TimeBasedDebouncer=void 0,t.TimeBasedDebouncer=class{constructor(e,t=1e3){this._renderCallback=e,this._debounceThresholdMS=t,this._lastRefreshMs=0,this._additionalRefreshRequested=!1}dispose(){this._refreshTimeoutID&&clearTimeout(this._refreshTimeoutID)}refresh(e,t,i){this._rowCount=i,e=void 0!==e?e:0,t=void 0!==t?t:this._rowCount-1,this._rowStart=void 0!==this._rowStart?Math.min(this._rowStart,e):e,this._rowEnd=void 0!==this._rowEnd?Math.max(this._rowEnd,t):t;const s=Date.now();if(s-this._lastRefreshMs>=this._debounceThresholdMS)this._lastRefreshMs=s,this._innerRefresh();else if(!this._additionalRefreshRequested){const e=s-this._lastRefreshMs,t=this._debounceThresholdMS-e;this._additionalRefreshRequested=!0,this._refreshTimeoutID=window.setTimeout((()=>{this._lastRefreshMs=Date.now(),this._innerRefresh(),this._additionalRefreshRequested=!1,this._refreshTimeoutID=void 0}),t)}}_innerRefresh(){if(void 0===this._rowStart||void 0===this._rowEnd||void 0===this._rowCount)return;const e=Math.max(this._rowStart,0),t=Math.min(this._rowEnd,this._rowCount-1);this._rowStart=void 0,this._rowEnd=void 0,this._renderCallback(e,t)}}},1680:function(e,t,i){var s=this&&this.__decorate||function(e,t,i,s){var r,n=arguments.length,o=n<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,i,s);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(o=(n<3?r(o):n>3?r(t,i,o):r(t,i))||o);return n>3&&o&&Object.defineProperty(t,i,o),o},r=this&&this.__param||function(e,t){return function(i,s){t(i,s,e)}};Object.defineProperty(t,"__esModule",{value:!0}),t.Viewport=void 0;const n=i(3656),o=i(4725),a=i(8460),h=i(844),c=i(2585);let l=t.Viewport=class extends h.Disposable{constructor(e,t,i,s,r,o,h,c){super(),this._viewportElement=e,this._scrollArea=t,this._bufferService=i,this._optionsService=s,this._charSizeService=r,this._renderService=o,this._coreBrowserService=h,this.scrollBarWidth=0,this._currentRowHeight=0,this._currentDeviceCellHeight=0,this._lastRecordedBufferLength=0,this._lastRecordedViewportHeight=0,this._lastRecordedBufferHeight=0,this._lastTouchY=0,this._lastScrollTop=0,this._wheelPartialScroll=0,this._refreshAnimationFrame=null,this._ignoreNextScrollEvent=!1,this._smoothScrollState={startTime:0,origin:-1,target:-1},this._onRequestScrollLines=this.register(new a.EventEmitter),this.onRequestScrollLines=this._onRequestScrollLines.event,this.scrollBarWidth=this._viewportElement.offsetWidth-this._scrollArea.offsetWidth||15,this.register((0,n.addDisposableDomListener)(this._viewportElement,"scroll",this._handleScroll.bind(this))),this._activeBuffer=this._bufferService.buffer,this.register(this._bufferService.buffers.onBufferActivate((e=>this._activeBuffer=e.activeBuffer))),this._renderDimensions=this._renderService.dimensions,this.register(this._renderService.onDimensionsChange((e=>this._renderDimensions=e))),this._handleThemeChange(c.colors),this.register(c.onChangeColors((e=>this._handleThemeChange(e)))),this.register(this._optionsService.onSpecificOptionChange("scrollback",(()=>this.syncScrollArea()))),setTimeout((()=>this.syncScrollArea()))}_handleThemeChange(e){this._viewportElement.style.backgroundColor=e.background.css}reset(){this._currentRowHeight=0,this._currentDeviceCellHeight=0,this._lastRecordedBufferLength=0,this._lastRecordedViewportHeight=0,this._lastRecordedBufferHeight=0,this._lastTouchY=0,this._lastScrollTop=0,this._coreBrowserService.window.requestAnimationFrame((()=>this.syncScrollArea()))}_refresh(e){if(e)return this._innerRefresh(),void(null!==this._refreshAnimationFrame&&this._coreBrowserService.window.cancelAnimationFrame(this._refreshAnimationFrame));null===this._refreshAnimationFrame&&(this._refreshAnimationFrame=this._coreBrowserService.window.requestAnimationFrame((()=>this._innerRefresh())))}_innerRefresh(){if(this._charSizeService.height>0){this._currentRowHeight=this._renderDimensions.device.cell.height/this._coreBrowserService.dpr,this._currentDeviceCellHeight=this._renderDimensions.device.cell.height,this._lastRecordedViewportHeight=this._viewportElement.offsetHeight;const e=Math.round(this._currentRowHeight*this._lastRecordedBufferLength)+(this._lastRecordedViewportHeight-this._renderDimensions.css.canvas.height);this._lastRecordedBufferHeight!==e&&(this._lastRecordedBufferHeight=e,this._scrollArea.style.height=this._lastRecordedBufferHeight+"px")}const e=this._bufferService.buffer.ydisp*this._currentRowHeight;this._viewportElement.scrollTop!==e&&(this._ignoreNextScrollEvent=!0,this._viewportElement.scrollTop=e),this._refreshAnimationFrame=null}syncScrollArea(e=!1){if(this._lastRecordedBufferLength!==this._bufferService.buffer.lines.length)return this._lastRecordedBufferLength=this._bufferService.buffer.lines.length,void this._refresh(e);this._lastRecordedViewportHeight===this._renderService.dimensions.css.canvas.height&&this._lastScrollTop===this._activeBuffer.ydisp*this._currentRowHeight&&this._renderDimensions.device.cell.height===this._currentDeviceCellHeight||this._refresh(e)}_handleScroll(e){if(this._lastScrollTop=this._viewportElement.scrollTop,!this._viewportElement.offsetParent)return;if(this._ignoreNextScrollEvent)return this._ignoreNextScrollEvent=!1,void this._onRequestScrollLines.fire({amount:0,suppressScrollEvent:!0});const t=Math.round(this._lastScrollTop/this._currentRowHeight)-this._bufferService.buffer.ydisp;this._onRequestScrollLines.fire({amount:t,suppressScrollEvent:!0})}_smoothScroll(){if(this._isDisposed||-1===this._smoothScrollState.origin||-1===this._smoothScrollState.target)return;const e=this._smoothScrollPercent();this._viewportElement.scrollTop=this._smoothScrollState.origin+Math.round(e*(this._smoothScrollState.target-this._smoothScrollState.origin)),e<1?this._coreBrowserService.window.requestAnimationFrame((()=>this._smoothScroll())):this._clearSmoothScrollState()}_smoothScrollPercent(){return this._optionsService.rawOptions.smoothScrollDuration&&this._smoothScrollState.startTime?Math.max(Math.min((Date.now()-this._smoothScrollState.startTime)/this._optionsService.rawOptions.smoothScrollDuration,1),0):1}_clearSmoothScrollState(){this._smoothScrollState.startTime=0,this._smoothScrollState.origin=-1,this._smoothScrollState.target=-1}_bubbleScroll(e,t){const i=this._viewportElement.scrollTop+this._lastRecordedViewportHeight;return!(t<0&&0!==this._viewportElement.scrollTop||t>0&&i0&&(i=e),s=""}}return{bufferElements:r,cursorElement:i}}getLinesScrolled(e){if(0===e.deltaY||e.shiftKey)return 0;let t=this._applyScrollModifier(e.deltaY,e);return e.deltaMode===WheelEvent.DOM_DELTA_PIXEL?(t/=this._currentRowHeight+0,this._wheelPartialScroll+=t,t=Math.floor(Math.abs(this._wheelPartialScroll))*(this._wheelPartialScroll>0?1:-1),this._wheelPartialScroll%=1):e.deltaMode===WheelEvent.DOM_DELTA_PAGE&&(t*=this._bufferService.rows),t}_applyScrollModifier(e,t){const i=this._optionsService.rawOptions.fastScrollModifier;return"alt"===i&&t.altKey||"ctrl"===i&&t.ctrlKey||"shift"===i&&t.shiftKey?e*this._optionsService.rawOptions.fastScrollSensitivity*this._optionsService.rawOptions.scrollSensitivity:e*this._optionsService.rawOptions.scrollSensitivity}handleTouchStart(e){this._lastTouchY=e.touches[0].pageY}handleTouchMove(e){const t=this._lastTouchY-e.touches[0].pageY;return this._lastTouchY=e.touches[0].pageY,0!==t&&(this._viewportElement.scrollTop+=t,this._bubbleScroll(e,t))}};t.Viewport=l=s([r(2,c.IBufferService),r(3,c.IOptionsService),r(4,o.ICharSizeService),r(5,o.IRenderService),r(6,o.ICoreBrowserService),r(7,o.IThemeService)],l)},3107:function(e,t,i){var s=this&&this.__decorate||function(e,t,i,s){var r,n=arguments.length,o=n<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,i,s);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(o=(n<3?r(o):n>3?r(t,i,o):r(t,i))||o);return n>3&&o&&Object.defineProperty(t,i,o),o},r=this&&this.__param||function(e,t){return function(i,s){t(i,s,e)}};Object.defineProperty(t,"__esModule",{value:!0}),t.BufferDecorationRenderer=void 0;const n=i(4725),o=i(844),a=i(2585);let h=t.BufferDecorationRenderer=class extends o.Disposable{constructor(e,t,i,s,r){super(),this._screenElement=e,this._bufferService=t,this._coreBrowserService=i,this._decorationService=s,this._renderService=r,this._decorationElements=new Map,this._altBufferIsActive=!1,this._dimensionsChanged=!1,this._container=document.createElement("div"),this._container.classList.add("xterm-decoration-container"),this._screenElement.appendChild(this._container),this.register(this._renderService.onRenderedViewportChange((()=>this._doRefreshDecorations()))),this.register(this._renderService.onDimensionsChange((()=>{this._dimensionsChanged=!0,this._queueRefresh()}))),this.register(this._coreBrowserService.onDprChange((()=>this._queueRefresh()))),this.register(this._bufferService.buffers.onBufferActivate((()=>{this._altBufferIsActive=this._bufferService.buffer===this._bufferService.buffers.alt}))),this.register(this._decorationService.onDecorationRegistered((()=>this._queueRefresh()))),this.register(this._decorationService.onDecorationRemoved((e=>this._removeDecoration(e)))),this.register((0,o.toDisposable)((()=>{this._container.remove(),this._decorationElements.clear()})))}_queueRefresh(){void 0===this._animationFrame&&(this._animationFrame=this._renderService.addRefreshCallback((()=>{this._doRefreshDecorations(),this._animationFrame=void 0})))}_doRefreshDecorations(){for(const e of this._decorationService.decorations)this._renderDecoration(e);this._dimensionsChanged=!1}_renderDecoration(e){this._refreshStyle(e),this._dimensionsChanged&&this._refreshXPosition(e)}_createElement(e){const t=this._coreBrowserService.mainDocument.createElement("div");t.classList.add("xterm-decoration"),t.classList.toggle("xterm-decoration-top-layer","top"===e?.options?.layer),t.style.width=`${Math.round((e.options.width||1)*this._renderService.dimensions.css.cell.width)}px`,t.style.height=(e.options.height||1)*this._renderService.dimensions.css.cell.height+"px",t.style.top=(e.marker.line-this._bufferService.buffers.active.ydisp)*this._renderService.dimensions.css.cell.height+"px",t.style.lineHeight=`${this._renderService.dimensions.css.cell.height}px`;const i=e.options.x??0;return i&&i>this._bufferService.cols&&(t.style.display="none"),this._refreshXPosition(e,t),t}_refreshStyle(e){const t=e.marker.line-this._bufferService.buffers.active.ydisp;if(t<0||t>=this._bufferService.rows)e.element&&(e.element.style.display="none",e.onRenderEmitter.fire(e.element));else{let i=this._decorationElements.get(e);i||(i=this._createElement(e),e.element=i,this._decorationElements.set(e,i),this._container.appendChild(i),e.onDispose((()=>{this._decorationElements.delete(e),i.remove()}))),i.style.top=t*this._renderService.dimensions.css.cell.height+"px",i.style.display=this._altBufferIsActive?"none":"block",e.onRenderEmitter.fire(i)}}_refreshXPosition(e,t=e.element){if(!t)return;const i=e.options.x??0;"right"===(e.options.anchor||"left")?t.style.right=i?i*this._renderService.dimensions.css.cell.width+"px":"":t.style.left=i?i*this._renderService.dimensions.css.cell.width+"px":""}_removeDecoration(e){this._decorationElements.get(e)?.remove(),this._decorationElements.delete(e),e.dispose()}};t.BufferDecorationRenderer=h=s([r(1,a.IBufferService),r(2,n.ICoreBrowserService),r(3,a.IDecorationService),r(4,n.IRenderService)],h)},5871:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ColorZoneStore=void 0,t.ColorZoneStore=class{constructor(){this._zones=[],this._zonePool=[],this._zonePoolIndex=0,this._linePadding={full:0,left:0,center:0,right:0}}get zones(){return this._zonePool.length=Math.min(this._zonePool.length,this._zones.length),this._zones}clear(){this._zones.length=0,this._zonePoolIndex=0}addDecoration(e){if(e.options.overviewRulerOptions){for(const t of this._zones)if(t.color===e.options.overviewRulerOptions.color&&t.position===e.options.overviewRulerOptions.position){if(this._lineIntersectsZone(t,e.marker.line))return;if(this._lineAdjacentToZone(t,e.marker.line,e.options.overviewRulerOptions.position))return void this._addLineToZone(t,e.marker.line)}if(this._zonePoolIndex=e.startBufferLine&&t<=e.endBufferLine}_lineAdjacentToZone(e,t,i){return t>=e.startBufferLine-this._linePadding[i||"full"]&&t<=e.endBufferLine+this._linePadding[i||"full"]}_addLineToZone(e,t){e.startBufferLine=Math.min(e.startBufferLine,t),e.endBufferLine=Math.max(e.endBufferLine,t)}}},5744:function(e,t,i){var s=this&&this.__decorate||function(e,t,i,s){var r,n=arguments.length,o=n<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,i,s);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(o=(n<3?r(o):n>3?r(t,i,o):r(t,i))||o);return n>3&&o&&Object.defineProperty(t,i,o),o},r=this&&this.__param||function(e,t){return function(i,s){t(i,s,e)}};Object.defineProperty(t,"__esModule",{value:!0}),t.OverviewRulerRenderer=void 0;const n=i(5871),o=i(4725),a=i(844),h=i(2585),c={full:0,left:0,center:0,right:0},l={full:0,left:0,center:0,right:0},d={full:0,left:0,center:0,right:0};let _=t.OverviewRulerRenderer=class extends a.Disposable{get _width(){return this._optionsService.options.overviewRulerWidth||0}constructor(e,t,i,s,r,o,h){super(),this._viewportElement=e,this._screenElement=t,this._bufferService=i,this._decorationService=s,this._renderService=r,this._optionsService=o,this._coreBrowserService=h,this._colorZoneStore=new n.ColorZoneStore,this._shouldUpdateDimensions=!0,this._shouldUpdateAnchor=!0,this._lastKnownBufferLength=0,this._canvas=this._coreBrowserService.mainDocument.createElement("canvas"),this._canvas.classList.add("xterm-decoration-overview-ruler"),this._refreshCanvasDimensions(),this._viewportElement.parentElement?.insertBefore(this._canvas,this._viewportElement);const c=this._canvas.getContext("2d");if(!c)throw new Error("Ctx cannot be null");this._ctx=c,this._registerDecorationListeners(),this._registerBufferChangeListeners(),this._registerDimensionChangeListeners(),this.register((0,a.toDisposable)((()=>{this._canvas?.remove()})))}_registerDecorationListeners(){this.register(this._decorationService.onDecorationRegistered((()=>this._queueRefresh(void 0,!0)))),this.register(this._decorationService.onDecorationRemoved((()=>this._queueRefresh(void 0,!0))))}_registerBufferChangeListeners(){this.register(this._renderService.onRenderedViewportChange((()=>this._queueRefresh()))),this.register(this._bufferService.buffers.onBufferActivate((()=>{this._canvas.style.display=this._bufferService.buffer===this._bufferService.buffers.alt?"none":"block"}))),this.register(this._bufferService.onScroll((()=>{this._lastKnownBufferLength!==this._bufferService.buffers.normal.lines.length&&(this._refreshDrawHeightConstants(),this._refreshColorZonePadding())})))}_registerDimensionChangeListeners(){this.register(this._renderService.onRender((()=>{this._containerHeight&&this._containerHeight===this._screenElement.clientHeight||(this._queueRefresh(!0),this._containerHeight=this._screenElement.clientHeight)}))),this.register(this._optionsService.onSpecificOptionChange("overviewRulerWidth",(()=>this._queueRefresh(!0)))),this.register(this._coreBrowserService.onDprChange((()=>this._queueRefresh(!0)))),this._queueRefresh(!0)}_refreshDrawConstants(){const e=Math.floor(this._canvas.width/3),t=Math.ceil(this._canvas.width/3);l.full=this._canvas.width,l.left=e,l.center=t,l.right=e,this._refreshDrawHeightConstants(),d.full=0,d.left=0,d.center=l.left,d.right=l.left+l.center}_refreshDrawHeightConstants(){c.full=Math.round(2*this._coreBrowserService.dpr);const e=this._canvas.height/this._bufferService.buffer.lines.length,t=Math.round(Math.max(Math.min(e,12),6)*this._coreBrowserService.dpr);c.left=t,c.center=t,c.right=t}_refreshColorZonePadding(){this._colorZoneStore.setPadding({full:Math.floor(this._bufferService.buffers.active.lines.length/(this._canvas.height-1)*c.full),left:Math.floor(this._bufferService.buffers.active.lines.length/(this._canvas.height-1)*c.left),center:Math.floor(this._bufferService.buffers.active.lines.length/(this._canvas.height-1)*c.center),right:Math.floor(this._bufferService.buffers.active.lines.length/(this._canvas.height-1)*c.right)}),this._lastKnownBufferLength=this._bufferService.buffers.normal.lines.length}_refreshCanvasDimensions(){this._canvas.style.width=`${this._width}px`,this._canvas.width=Math.round(this._width*this._coreBrowserService.dpr),this._canvas.style.height=`${this._screenElement.clientHeight}px`,this._canvas.height=Math.round(this._screenElement.clientHeight*this._coreBrowserService.dpr),this._refreshDrawConstants(),this._refreshColorZonePadding()}_refreshDecorations(){this._shouldUpdateDimensions&&this._refreshCanvasDimensions(),this._ctx.clearRect(0,0,this._canvas.width,this._canvas.height),this._colorZoneStore.clear();for(const e of this._decorationService.decorations)this._colorZoneStore.addDecoration(e);this._ctx.lineWidth=1;const e=this._colorZoneStore.zones;for(const t of e)"full"!==t.position&&this._renderColorZone(t);for(const t of e)"full"===t.position&&this._renderColorZone(t);this._shouldUpdateDimensions=!1,this._shouldUpdateAnchor=!1}_renderColorZone(e){this._ctx.fillStyle=e.color,this._ctx.fillRect(d[e.position||"full"],Math.round((this._canvas.height-1)*(e.startBufferLine/this._bufferService.buffers.active.lines.length)-c[e.position||"full"]/2),l[e.position||"full"],Math.round((this._canvas.height-1)*((e.endBufferLine-e.startBufferLine)/this._bufferService.buffers.active.lines.length)+c[e.position||"full"]))}_queueRefresh(e,t){this._shouldUpdateDimensions=e||this._shouldUpdateDimensions,this._shouldUpdateAnchor=t||this._shouldUpdateAnchor,void 0===this._animationFrame&&(this._animationFrame=this._coreBrowserService.window.requestAnimationFrame((()=>{this._refreshDecorations(),this._animationFrame=void 0})))}};t.OverviewRulerRenderer=_=s([r(2,h.IBufferService),r(3,h.IDecorationService),r(4,o.IRenderService),r(5,h.IOptionsService),r(6,o.ICoreBrowserService)],_)},2950:function(e,t,i){var s=this&&this.__decorate||function(e,t,i,s){var r,n=arguments.length,o=n<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,i,s);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(o=(n<3?r(o):n>3?r(t,i,o):r(t,i))||o);return n>3&&o&&Object.defineProperty(t,i,o),o},r=this&&this.__param||function(e,t){return function(i,s){t(i,s,e)}};Object.defineProperty(t,"__esModule",{value:!0}),t.CompositionHelper=void 0;const n=i(4725),o=i(2585),a=i(2584);let h=t.CompositionHelper=class{get isComposing(){return this._isComposing}constructor(e,t,i,s,r,n){this._textarea=e,this._compositionView=t,this._bufferService=i,this._optionsService=s,this._coreService=r,this._renderService=n,this._isComposing=!1,this._isSendingComposition=!1,this._compositionPosition={start:0,end:0},this._dataAlreadySent=""}compositionstart(){this._isComposing=!0,this._compositionPosition.start=this._textarea.value.length,this._compositionView.textContent="",this._dataAlreadySent="",this._compositionView.classList.add("active")}compositionupdate(e){this._compositionView.textContent=e.data,this.updateCompositionElements(),setTimeout((()=>{this._compositionPosition.end=this._textarea.value.length}),0)}compositionend(){this._finalizeComposition(!0)}keydown(e){if(this._isComposing||this._isSendingComposition){if(229===e.keyCode)return!1;if(16===e.keyCode||17===e.keyCode||18===e.keyCode)return!1;this._finalizeComposition(!1)}return 229!==e.keyCode||(this._handleAnyTextareaChanges(),!1)}_finalizeComposition(e){if(this._compositionView.classList.remove("active"),this._isComposing=!1,e){const e={start:this._compositionPosition.start,end:this._compositionPosition.end};this._isSendingComposition=!0,setTimeout((()=>{if(this._isSendingComposition){let t;this._isSendingComposition=!1,e.start+=this._dataAlreadySent.length,t=this._isComposing?this._textarea.value.substring(e.start,e.end):this._textarea.value.substring(e.start),t.length>0&&this._coreService.triggerDataEvent(t,!0)}}),0)}else{this._isSendingComposition=!1;const e=this._textarea.value.substring(this._compositionPosition.start,this._compositionPosition.end);this._coreService.triggerDataEvent(e,!0)}}_handleAnyTextareaChanges(){const e=this._textarea.value;setTimeout((()=>{if(!this._isComposing){const t=this._textarea.value,i=t.replace(e,"");this._dataAlreadySent=i,t.length>e.length?this._coreService.triggerDataEvent(i,!0):t.lengththis.updateCompositionElements(!0)),0)}}};t.CompositionHelper=h=s([r(2,o.IBufferService),r(3,o.IOptionsService),r(4,o.ICoreService),r(5,n.IRenderService)],h)},9806:(e,t)=>{function i(e,t,i){const s=i.getBoundingClientRect(),r=e.getComputedStyle(i),n=parseInt(r.getPropertyValue("padding-left")),o=parseInt(r.getPropertyValue("padding-top"));return[t.clientX-s.left-n,t.clientY-s.top-o]}Object.defineProperty(t,"__esModule",{value:!0}),t.getCoords=t.getCoordsRelativeToElement=void 0,t.getCoordsRelativeToElement=i,t.getCoords=function(e,t,s,r,n,o,a,h,c){if(!o)return;const l=i(e,t,s);return l?(l[0]=Math.ceil((l[0]+(c?a/2:0))/a),l[1]=Math.ceil(l[1]/h),l[0]=Math.min(Math.max(l[0],1),r+(c?1:0)),l[1]=Math.min(Math.max(l[1],1),n),l):void 0}},9504:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.moveToCellSequence=void 0;const s=i(2584);function r(e,t,i,s){const r=e-n(e,i),a=t-n(t,i),l=Math.abs(r-a)-function(e,t,i){let s=0;const r=e-n(e,i),a=t-n(t,i);for(let n=0;n=0&&et?"A":"B"}function a(e,t,i,s,r,n){let o=e,a=t,h="";for(;o!==i||a!==s;)o+=r?1:-1,r&&o>n.cols-1?(h+=n.buffer.translateBufferLineToString(a,!1,e,o),o=0,e=0,a++):!r&&o<0&&(h+=n.buffer.translateBufferLineToString(a,!1,0,e+1),o=n.cols-1,e=o,a--);return h+n.buffer.translateBufferLineToString(a,!1,e,o)}function h(e,t){const i=t?"O":"[";return s.C0.ESC+i+e}function c(e,t){e=Math.floor(e);let i="";for(let s=0;s0?s-n(s,o):t;const _=s,u=function(e,t,i,s,o,a){let h;return h=r(i,s,o,a).length>0?s-n(s,o):t,e=i&&he?"D":"C",c(Math.abs(o-e),h(d,s));d=l>t?"D":"C";const _=Math.abs(l-t);return c(function(e,t){return t.cols-e}(l>t?e:o,i)+(_-1)*i.cols+1+((l>t?o:e)-1),h(d,s))}},1296:function(e,t,i){var s=this&&this.__decorate||function(e,t,i,s){var r,n=arguments.length,o=n<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,i,s);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(o=(n<3?r(o):n>3?r(t,i,o):r(t,i))||o);return n>3&&o&&Object.defineProperty(t,i,o),o},r=this&&this.__param||function(e,t){return function(i,s){t(i,s,e)}};Object.defineProperty(t,"__esModule",{value:!0}),t.DomRenderer=void 0;const n=i(3787),o=i(2550),a=i(2223),h=i(6171),c=i(6052),l=i(4725),d=i(8055),_=i(8460),u=i(844),f=i(2585),v="xterm-dom-renderer-owner-",p="xterm-rows",g="xterm-fg-",m="xterm-bg-",S="xterm-focus",C="xterm-selection";let b=1,w=t.DomRenderer=class extends u.Disposable{constructor(e,t,i,s,r,a,l,d,f,g,m,S,w){super(),this._terminal=e,this._document=t,this._element=i,this._screenElement=s,this._viewportElement=r,this._helperContainer=a,this._linkifier2=l,this._charSizeService=f,this._optionsService=g,this._bufferService=m,this._coreBrowserService=S,this._themeService=w,this._terminalClass=b++,this._rowElements=[],this._selectionRenderModel=(0,c.createSelectionRenderModel)(),this.onRequestRedraw=this.register(new _.EventEmitter).event,this._rowContainer=this._document.createElement("div"),this._rowContainer.classList.add(p),this._rowContainer.style.lineHeight="normal",this._rowContainer.setAttribute("aria-hidden","true"),this._refreshRowElements(this._bufferService.cols,this._bufferService.rows),this._selectionContainer=this._document.createElement("div"),this._selectionContainer.classList.add(C),this._selectionContainer.setAttribute("aria-hidden","true"),this.dimensions=(0,h.createRenderDimensions)(),this._updateDimensions(),this.register(this._optionsService.onOptionChange((()=>this._handleOptionsChanged()))),this.register(this._themeService.onChangeColors((e=>this._injectCss(e)))),this._injectCss(this._themeService.colors),this._rowFactory=d.createInstance(n.DomRendererRowFactory,document),this._element.classList.add(v+this._terminalClass),this._screenElement.appendChild(this._rowContainer),this._screenElement.appendChild(this._selectionContainer),this.register(this._linkifier2.onShowLinkUnderline((e=>this._handleLinkHover(e)))),this.register(this._linkifier2.onHideLinkUnderline((e=>this._handleLinkLeave(e)))),this.register((0,u.toDisposable)((()=>{this._element.classList.remove(v+this._terminalClass),this._rowContainer.remove(),this._selectionContainer.remove(),this._widthCache.dispose(),this._themeStyleElement.remove(),this._dimensionsStyleElement.remove()}))),this._widthCache=new o.WidthCache(this._document,this._helperContainer),this._widthCache.setFont(this._optionsService.rawOptions.fontFamily,this._optionsService.rawOptions.fontSize,this._optionsService.rawOptions.fontWeight,this._optionsService.rawOptions.fontWeightBold),this._setDefaultSpacing()}_updateDimensions(){const e=this._coreBrowserService.dpr;this.dimensions.device.char.width=this._charSizeService.width*e,this.dimensions.device.char.height=Math.ceil(this._charSizeService.height*e),this.dimensions.device.cell.width=this.dimensions.device.char.width+Math.round(this._optionsService.rawOptions.letterSpacing),this.dimensions.device.cell.height=Math.floor(this.dimensions.device.char.height*this._optionsService.rawOptions.lineHeight),this.dimensions.device.char.left=0,this.dimensions.device.char.top=0,this.dimensions.device.canvas.width=this.dimensions.device.cell.width*this._bufferService.cols,this.dimensions.device.canvas.height=this.dimensions.device.cell.height*this._bufferService.rows,this.dimensions.css.canvas.width=Math.round(this.dimensions.device.canvas.width/e),this.dimensions.css.canvas.height=Math.round(this.dimensions.device.canvas.height/e),this.dimensions.css.cell.width=this.dimensions.css.canvas.width/this._bufferService.cols,this.dimensions.css.cell.height=this.dimensions.css.canvas.height/this._bufferService.rows;for(const e of this._rowElements)e.style.width=`${this.dimensions.css.canvas.width}px`,e.style.height=`${this.dimensions.css.cell.height}px`,e.style.lineHeight=`${this.dimensions.css.cell.height}px`,e.style.overflow="hidden";this._dimensionsStyleElement||(this._dimensionsStyleElement=this._document.createElement("style"),this._screenElement.appendChild(this._dimensionsStyleElement));const t=`${this._terminalSelector} .${p} span { display: inline-block; height: 100%; vertical-align: top;}`;this._dimensionsStyleElement.textContent=t,this._selectionContainer.style.height=this._viewportElement.style.height,this._screenElement.style.width=`${this.dimensions.css.canvas.width}px`,this._screenElement.style.height=`${this.dimensions.css.canvas.height}px`}_injectCss(e){this._themeStyleElement||(this._themeStyleElement=this._document.createElement("style"),this._screenElement.appendChild(this._themeStyleElement));let t=`${this._terminalSelector} .${p} { color: ${e.foreground.css}; font-family: ${this._optionsService.rawOptions.fontFamily}; font-size: ${this._optionsService.rawOptions.fontSize}px; font-kerning: none; white-space: pre}`;t+=`${this._terminalSelector} .${p} .xterm-dim { color: ${d.color.multiplyOpacity(e.foreground,.5).css};}`,t+=`${this._terminalSelector} span:not(.xterm-bold) { font-weight: ${this._optionsService.rawOptions.fontWeight};}${this._terminalSelector} span.xterm-bold { font-weight: ${this._optionsService.rawOptions.fontWeightBold};}${this._terminalSelector} span.xterm-italic { font-style: italic;}`;const i=`blink_underline_${this._terminalClass}`,s=`blink_bar_${this._terminalClass}`,r=`blink_block_${this._terminalClass}`;t+=`@keyframes ${i} { 50% { border-bottom-style: hidden; }}`,t+=`@keyframes ${s} { 50% { box-shadow: none; }}`,t+=`@keyframes ${r} { 0% { background-color: ${e.cursor.css}; color: ${e.cursorAccent.css}; } 50% { background-color: inherit; color: ${e.cursor.css}; }}`,t+=`${this._terminalSelector} .${p}.${S} .xterm-cursor.xterm-cursor-blink.xterm-cursor-underline { animation: ${i} 1s step-end infinite;}${this._terminalSelector} .${p}.${S} .xterm-cursor.xterm-cursor-blink.xterm-cursor-bar { animation: ${s} 1s step-end infinite;}${this._terminalSelector} .${p}.${S} .xterm-cursor.xterm-cursor-blink.xterm-cursor-block { animation: ${r} 1s step-end infinite;}${this._terminalSelector} .${p} .xterm-cursor.xterm-cursor-block { background-color: ${e.cursor.css}; color: ${e.cursorAccent.css};}${this._terminalSelector} .${p} .xterm-cursor.xterm-cursor-block:not(.xterm-cursor-blink) { background-color: ${e.cursor.css} !important; color: ${e.cursorAccent.css} !important;}${this._terminalSelector} .${p} .xterm-cursor.xterm-cursor-outline { outline: 1px solid ${e.cursor.css}; outline-offset: -1px;}${this._terminalSelector} .${p} .xterm-cursor.xterm-cursor-bar { box-shadow: ${this._optionsService.rawOptions.cursorWidth}px 0 0 ${e.cursor.css} inset;}${this._terminalSelector} .${p} .xterm-cursor.xterm-cursor-underline { border-bottom: 1px ${e.cursor.css}; border-bottom-style: solid; height: calc(100% - 1px);}`,t+=`${this._terminalSelector} .${C} { position: absolute; top: 0; left: 0; z-index: 1; pointer-events: none;}${this._terminalSelector}.focus .${C} div { position: absolute; background-color: ${e.selectionBackgroundOpaque.css};}${this._terminalSelector} .${C} div { position: absolute; background-color: ${e.selectionInactiveBackgroundOpaque.css};}`;for(const[i,s]of e.ansi.entries())t+=`${this._terminalSelector} .${g}${i} { color: ${s.css}; }${this._terminalSelector} .${g}${i}.xterm-dim { color: ${d.color.multiplyOpacity(s,.5).css}; }${this._terminalSelector} .${m}${i} { background-color: ${s.css}; }`;t+=`${this._terminalSelector} .${g}${a.INVERTED_DEFAULT_COLOR} { color: ${d.color.opaque(e.background).css}; }${this._terminalSelector} .${g}${a.INVERTED_DEFAULT_COLOR}.xterm-dim { color: ${d.color.multiplyOpacity(d.color.opaque(e.background),.5).css}; }${this._terminalSelector} .${m}${a.INVERTED_DEFAULT_COLOR} { background-color: ${e.foreground.css}; }`,this._themeStyleElement.textContent=t}_setDefaultSpacing(){const e=this.dimensions.css.cell.width-this._widthCache.get("W",!1,!1);this._rowContainer.style.letterSpacing=`${e}px`,this._rowFactory.defaultSpacing=e}handleDevicePixelRatioChange(){this._updateDimensions(),this._widthCache.clear(),this._setDefaultSpacing()}_refreshRowElements(e,t){for(let e=this._rowElements.length;e<=t;e++){const e=this._document.createElement("div");this._rowContainer.appendChild(e),this._rowElements.push(e)}for(;this._rowElements.length>t;)this._rowContainer.removeChild(this._rowElements.pop())}handleResize(e,t){this._refreshRowElements(e,t),this._updateDimensions(),this.handleSelectionChanged(this._selectionRenderModel.selectionStart,this._selectionRenderModel.selectionEnd,this._selectionRenderModel.columnSelectMode)}handleCharSizeChanged(){this._updateDimensions(),this._widthCache.clear(),this._setDefaultSpacing()}handleBlur(){this._rowContainer.classList.remove(S),this.renderRows(0,this._bufferService.rows-1)}handleFocus(){this._rowContainer.classList.add(S),this.renderRows(this._bufferService.buffer.y,this._bufferService.buffer.y)}handleSelectionChanged(e,t,i){if(this._selectionContainer.replaceChildren(),this._rowFactory.handleSelectionChanged(e,t,i),this.renderRows(0,this._bufferService.rows-1),!e||!t)return;this._selectionRenderModel.update(this._terminal,e,t,i);const s=this._selectionRenderModel.viewportStartRow,r=this._selectionRenderModel.viewportEndRow,n=this._selectionRenderModel.viewportCappedStartRow,o=this._selectionRenderModel.viewportCappedEndRow;if(n>=this._bufferService.rows||o<0)return;const a=this._document.createDocumentFragment();if(i){const i=e[0]>t[0];a.appendChild(this._createSelectionElement(n,i?t[0]:e[0],i?e[0]:t[0],o-n+1))}else{const i=s===n?e[0]:0,h=n===r?t[0]:this._bufferService.cols;a.appendChild(this._createSelectionElement(n,i,h));const c=o-n-1;if(a.appendChild(this._createSelectionElement(n+1,0,this._bufferService.cols,c)),n!==o){const e=r===o?t[0]:this._bufferService.cols;a.appendChild(this._createSelectionElement(o,0,e))}}this._selectionContainer.appendChild(a)}_createSelectionElement(e,t,i,s=1){const r=this._document.createElement("div"),n=t*this.dimensions.css.cell.width;let o=this.dimensions.css.cell.width*(i-t);return n+o>this.dimensions.css.canvas.width&&(o=this.dimensions.css.canvas.width-n),r.style.height=s*this.dimensions.css.cell.height+"px",r.style.top=e*this.dimensions.css.cell.height+"px",r.style.left=`${n}px`,r.style.width=`${o}px`,r}handleCursorMove(){}_handleOptionsChanged(){this._updateDimensions(),this._injectCss(this._themeService.colors),this._widthCache.setFont(this._optionsService.rawOptions.fontFamily,this._optionsService.rawOptions.fontSize,this._optionsService.rawOptions.fontWeight,this._optionsService.rawOptions.fontWeightBold),this._setDefaultSpacing()}clear(){for(const e of this._rowElements)e.replaceChildren()}renderRows(e,t){const i=this._bufferService.buffer,s=i.ybase+i.y,r=Math.min(i.x,this._bufferService.cols-1),n=this._optionsService.rawOptions.cursorBlink,o=this._optionsService.rawOptions.cursorStyle,a=this._optionsService.rawOptions.cursorInactiveStyle;for(let h=e;h<=t;h++){const e=h+i.ydisp,t=this._rowElements[h],c=i.lines.get(e);if(!t||!c)break;t.replaceChildren(...this._rowFactory.createRow(c,e,e===s,o,a,r,n,this.dimensions.css.cell.width,this._widthCache,-1,-1))}}get _terminalSelector(){return`.${v}${this._terminalClass}`}_handleLinkHover(e){this._setCellUnderline(e.x1,e.x2,e.y1,e.y2,e.cols,!0)}_handleLinkLeave(e){this._setCellUnderline(e.x1,e.x2,e.y1,e.y2,e.cols,!1)}_setCellUnderline(e,t,i,s,r,n){i<0&&(e=0),s<0&&(t=0);const o=this._bufferService.rows-1;i=Math.max(Math.min(i,o),0),s=Math.max(Math.min(s,o),0),r=Math.min(r,this._bufferService.cols);const a=this._bufferService.buffer,h=a.ybase+a.y,c=Math.min(a.x,r-1),l=this._optionsService.rawOptions.cursorBlink,d=this._optionsService.rawOptions.cursorStyle,_=this._optionsService.rawOptions.cursorInactiveStyle;for(let o=i;o<=s;++o){const u=o+a.ydisp,f=this._rowElements[o],v=a.lines.get(u);if(!f||!v)break;f.replaceChildren(...this._rowFactory.createRow(v,u,u===h,d,_,c,l,this.dimensions.css.cell.width,this._widthCache,n?o===i?e:0:-1,n?(o===s?t:r)-1:-1))}}};t.DomRenderer=w=s([r(7,f.IInstantiationService),r(8,l.ICharSizeService),r(9,f.IOptionsService),r(10,f.IBufferService),r(11,l.ICoreBrowserService),r(12,l.IThemeService)],w)},3787:function(e,t,i){var s=this&&this.__decorate||function(e,t,i,s){var r,n=arguments.length,o=n<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,i,s);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(o=(n<3?r(o):n>3?r(t,i,o):r(t,i))||o);return n>3&&o&&Object.defineProperty(t,i,o),o},r=this&&this.__param||function(e,t){return function(i,s){t(i,s,e)}};Object.defineProperty(t,"__esModule",{value:!0}),t.DomRendererRowFactory=void 0;const n=i(2223),o=i(643),a=i(511),h=i(2585),c=i(8055),l=i(4725),d=i(4269),_=i(6171),u=i(3734);let f=t.DomRendererRowFactory=class{constructor(e,t,i,s,r,n,o){this._document=e,this._characterJoinerService=t,this._optionsService=i,this._coreBrowserService=s,this._coreService=r,this._decorationService=n,this._themeService=o,this._workCell=new a.CellData,this._columnSelectMode=!1,this.defaultSpacing=0}handleSelectionChanged(e,t,i){this._selectionStart=e,this._selectionEnd=t,this._columnSelectMode=i}createRow(e,t,i,s,r,a,h,l,_,f,p){const g=[],m=this._characterJoinerService.getJoinedCharacters(t),S=this._themeService.colors;let C,b=e.getNoBgTrimmedLength();i&&b0&&M===m[0][0]){O=!0;const t=m.shift();I=new d.JoinedCellData(this._workCell,e.translateToString(!0,t[0],t[1]),t[1]-t[0]),P=t[1]-1,b=I.getWidth()}const H=this._isCellInSelection(M,t),F=i&&M===a,W=T&&M>=f&&M<=p;let U=!1;this._decorationService.forEachDecorationAtCell(M,t,void 0,(e=>{U=!0}));let N=I.getChars()||o.WHITESPACE_CELL_CHAR;if(" "===N&&(I.isUnderline()||I.isOverline())&&(N="ย "),A=b*l-_.get(N,I.isBold(),I.isItalic()),C){if(w&&(H&&x||!H&&!x&&I.bg===E)&&(H&&x&&S.selectionForeground||I.fg===k)&&I.extended.ext===L&&W===D&&A===R&&!F&&!O&&!U){I.isInvisible()?y+=o.WHITESPACE_CELL_CHAR:y+=N,w++;continue}w&&(C.textContent=y),C=this._document.createElement("span"),w=0,y=""}else C=this._document.createElement("span");if(E=I.bg,k=I.fg,L=I.extended.ext,D=W,R=A,x=H,O&&a>=M&&a<=P&&(a=M),!this._coreService.isCursorHidden&&F&&this._coreService.isCursorInitialized)if(B.push("xterm-cursor"),this._coreBrowserService.isFocused)h&&B.push("xterm-cursor-blink"),B.push("bar"===s?"xterm-cursor-bar":"underline"===s?"xterm-cursor-underline":"xterm-cursor-block");else if(r)switch(r){case"outline":B.push("xterm-cursor-outline");break;case"block":B.push("xterm-cursor-block");break;case"bar":B.push("xterm-cursor-bar");break;case"underline":B.push("xterm-cursor-underline")}if(I.isBold()&&B.push("xterm-bold"),I.isItalic()&&B.push("xterm-italic"),I.isDim()&&B.push("xterm-dim"),y=I.isInvisible()?o.WHITESPACE_CELL_CHAR:I.getChars()||o.WHITESPACE_CELL_CHAR,I.isUnderline()&&(B.push(`xterm-underline-${I.extended.underlineStyle}`)," "===y&&(y="ย "),!I.isUnderlineColorDefault()))if(I.isUnderlineColorRGB())C.style.textDecorationColor=`rgb(${u.AttributeData.toColorRGB(I.getUnderlineColor()).join(",")})`;else{let e=I.getUnderlineColor();this._optionsService.rawOptions.drawBoldTextInBrightColors&&I.isBold()&&e<8&&(e+=8),C.style.textDecorationColor=S.ansi[e].css}I.isOverline()&&(B.push("xterm-overline")," "===y&&(y="ย ")),I.isStrikethrough()&&B.push("xterm-strikethrough"),W&&(C.style.textDecoration="underline");let $=I.getFgColor(),j=I.getFgColorMode(),z=I.getBgColor(),K=I.getBgColorMode();const q=!!I.isInverse();if(q){const e=$;$=z,z=e;const t=j;j=K,K=t}let V,G,X,J=!1;switch(this._decorationService.forEachDecorationAtCell(M,t,void 0,(e=>{"top"!==e.options.layer&&J||(e.backgroundColorRGB&&(K=50331648,z=e.backgroundColorRGB.rgba>>8&16777215,V=e.backgroundColorRGB),e.foregroundColorRGB&&(j=50331648,$=e.foregroundColorRGB.rgba>>8&16777215,G=e.foregroundColorRGB),J="top"===e.options.layer)})),!J&&H&&(V=this._coreBrowserService.isFocused?S.selectionBackgroundOpaque:S.selectionInactiveBackgroundOpaque,z=V.rgba>>8&16777215,K=50331648,J=!0,S.selectionForeground&&(j=50331648,$=S.selectionForeground.rgba>>8&16777215,G=S.selectionForeground)),J&&B.push("xterm-decoration-top"),K){case 16777216:case 33554432:X=S.ansi[z],B.push(`xterm-bg-${z}`);break;case 50331648:X=c.channels.toColor(z>>16,z>>8&255,255&z),this._addStyle(C,`background-color:#${v((z>>>0).toString(16),"0",6)}`);break;default:q?(X=S.foreground,B.push(`xterm-bg-${n.INVERTED_DEFAULT_COLOR}`)):X=S.background}switch(V||I.isDim()&&(V=c.color.multiplyOpacity(X,.5)),j){case 16777216:case 33554432:I.isBold()&&$<8&&this._optionsService.rawOptions.drawBoldTextInBrightColors&&($+=8),this._applyMinimumContrast(C,X,S.ansi[$],I,V,void 0)||B.push(`xterm-fg-${$}`);break;case 50331648:const e=c.channels.toColor($>>16&255,$>>8&255,255&$);this._applyMinimumContrast(C,X,e,I,V,G)||this._addStyle(C,`color:#${v($.toString(16),"0",6)}`);break;default:this._applyMinimumContrast(C,X,S.foreground,I,V,G)||q&&B.push(`xterm-fg-${n.INVERTED_DEFAULT_COLOR}`)}B.length&&(C.className=B.join(" "),B.length=0),F||O||U?C.textContent=y:w++,A!==this.defaultSpacing&&(C.style.letterSpacing=`${A}px`),g.push(C),M=P}return C&&w&&(C.textContent=y),g}_applyMinimumContrast(e,t,i,s,r,n){if(1===this._optionsService.rawOptions.minimumContrastRatio||(0,_.treatGlyphAsBackgroundColor)(s.getCode()))return!1;const o=this._getContrastCache(s);let a;if(r||n||(a=o.getColor(t.rgba,i.rgba)),void 0===a){const e=this._optionsService.rawOptions.minimumContrastRatio/(s.isDim()?2:1);a=c.color.ensureContrastRatio(r||t,n||i,e),o.setColor((r||t).rgba,(n||i).rgba,a??null)}return!!a&&(this._addStyle(e,`color:${a.css}`),!0)}_getContrastCache(e){return e.isDim()?this._themeService.colors.halfContrastCache:this._themeService.colors.contrastCache}_addStyle(e,t){e.setAttribute("style",`${e.getAttribute("style")||""}${t};`)}_isCellInSelection(e,t){const i=this._selectionStart,s=this._selectionEnd;return!(!i||!s)&&(this._columnSelectMode?i[0]<=s[0]?e>=i[0]&&t>=i[1]&&e=i[1]&&e>=s[0]&&t<=s[1]:t>i[1]&&t=i[0]&&e=i[0])}};function v(e,t,i){for(;e.length{Object.defineProperty(t,"__esModule",{value:!0}),t.WidthCache=void 0,t.WidthCache=class{constructor(e,t){this._flat=new Float32Array(256),this._font="",this._fontSize=0,this._weight="normal",this._weightBold="bold",this._measureElements=[],this._container=e.createElement("div"),this._container.classList.add("xterm-width-cache-measure-container"),this._container.setAttribute("aria-hidden","true"),this._container.style.whiteSpace="pre",this._container.style.fontKerning="none";const i=e.createElement("span");i.classList.add("xterm-char-measure-element");const s=e.createElement("span");s.classList.add("xterm-char-measure-element"),s.style.fontWeight="bold";const r=e.createElement("span");r.classList.add("xterm-char-measure-element"),r.style.fontStyle="italic";const n=e.createElement("span");n.classList.add("xterm-char-measure-element"),n.style.fontWeight="bold",n.style.fontStyle="italic",this._measureElements=[i,s,r,n],this._container.appendChild(i),this._container.appendChild(s),this._container.appendChild(r),this._container.appendChild(n),t.appendChild(this._container),this.clear()}dispose(){this._container.remove(),this._measureElements.length=0,this._holey=void 0}clear(){this._flat.fill(-9999),this._holey=new Map}setFont(e,t,i,s){e===this._font&&t===this._fontSize&&i===this._weight&&s===this._weightBold||(this._font=e,this._fontSize=t,this._weight=i,this._weightBold=s,this._container.style.fontFamily=this._font,this._container.style.fontSize=`${this._fontSize}px`,this._measureElements[0].style.fontWeight=`${i}`,this._measureElements[1].style.fontWeight=`${s}`,this._measureElements[2].style.fontWeight=`${i}`,this._measureElements[3].style.fontWeight=`${s}`,this.clear())}get(e,t,i){let s=0;if(!t&&!i&&1===e.length&&(s=e.charCodeAt(0))<256){if(-9999!==this._flat[s])return this._flat[s];const t=this._measure(e,0);return t>0&&(this._flat[s]=t),t}let r=e;t&&(r+="B"),i&&(r+="I");let n=this._holey.get(r);if(void 0===n){let s=0;t&&(s|=1),i&&(s|=2),n=this._measure(e,s),n>0&&this._holey.set(r,n)}return n}_measure(e,t){const i=this._measureElements[t];return i.textContent=e.repeat(32),i.offsetWidth/32}}},2223:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.TEXT_BASELINE=t.DIM_OPACITY=t.INVERTED_DEFAULT_COLOR=void 0;const s=i(6114);t.INVERTED_DEFAULT_COLOR=257,t.DIM_OPACITY=.5,t.TEXT_BASELINE=s.isFirefox||s.isLegacyEdge?"bottom":"ideographic"},6171:(e,t)=>{function i(e){return 57508<=e&&e<=57558}function s(e){return e>=128512&&e<=128591||e>=127744&&e<=128511||e>=128640&&e<=128767||e>=9728&&e<=9983||e>=9984&&e<=10175||e>=65024&&e<=65039||e>=129280&&e<=129535||e>=127462&&e<=127487}Object.defineProperty(t,"__esModule",{value:!0}),t.computeNextVariantOffset=t.createRenderDimensions=t.treatGlyphAsBackgroundColor=t.allowRescaling=t.isEmoji=t.isRestrictedPowerlineGlyph=t.isPowerlineGlyph=t.throwIfFalsy=void 0,t.throwIfFalsy=function(e){if(!e)throw new Error("value must not be falsy");return e},t.isPowerlineGlyph=i,t.isRestrictedPowerlineGlyph=function(e){return 57520<=e&&e<=57527},t.isEmoji=s,t.allowRescaling=function(e,t,r,n){return 1===t&&r>Math.ceil(1.5*n)&&void 0!==e&&e>255&&!s(e)&&!i(e)&&!function(e){return 57344<=e&&e<=63743}(e)},t.treatGlyphAsBackgroundColor=function(e){return i(e)||function(e){return 9472<=e&&e<=9631}(e)},t.createRenderDimensions=function(){return{css:{canvas:{width:0,height:0},cell:{width:0,height:0}},device:{canvas:{width:0,height:0},cell:{width:0,height:0},char:{width:0,height:0,left:0,top:0}}}},t.computeNextVariantOffset=function(e,t,i=0){return(e-(2*Math.round(t)-i))%(2*Math.round(t))}},6052:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.createSelectionRenderModel=void 0;class i{constructor(){this.clear()}clear(){this.hasSelection=!1,this.columnSelectMode=!1,this.viewportStartRow=0,this.viewportEndRow=0,this.viewportCappedStartRow=0,this.viewportCappedEndRow=0,this.startCol=0,this.endCol=0,this.selectionStart=void 0,this.selectionEnd=void 0}update(e,t,i,s=!1){if(this.selectionStart=t,this.selectionEnd=i,!t||!i||t[0]===i[0]&&t[1]===i[1])return void this.clear();const r=e.buffers.active.ydisp,n=t[1]-r,o=i[1]-r,a=Math.max(n,0),h=Math.min(o,e.rows-1);a>=e.rows||h<0?this.clear():(this.hasSelection=!0,this.columnSelectMode=s,this.viewportStartRow=n,this.viewportEndRow=o,this.viewportCappedStartRow=a,this.viewportCappedEndRow=h,this.startCol=t[0],this.endCol=i[0])}isCellSelected(e,t,i){return!!this.hasSelection&&(i-=e.buffer.active.viewportY,this.columnSelectMode?this.startCol<=this.endCol?t>=this.startCol&&i>=this.viewportCappedStartRow&&t=this.viewportCappedStartRow&&t>=this.endCol&&i<=this.viewportCappedEndRow:i>this.viewportStartRow&&i=this.startCol&&t=this.startCol)}}t.createSelectionRenderModel=function(){return new i}},456:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SelectionModel=void 0,t.SelectionModel=class{constructor(e){this._bufferService=e,this.isSelectAllActive=!1,this.selectionStartLength=0}clearSelection(){this.selectionStart=void 0,this.selectionEnd=void 0,this.isSelectAllActive=!1,this.selectionStartLength=0}get finalSelectionStart(){return this.isSelectAllActive?[0,0]:this.selectionEnd&&this.selectionStart&&this.areSelectionValuesReversed()?this.selectionEnd:this.selectionStart}get finalSelectionEnd(){if(this.isSelectAllActive)return[this._bufferService.cols,this._bufferService.buffer.ybase+this._bufferService.rows-1];if(this.selectionStart){if(!this.selectionEnd||this.areSelectionValuesReversed()){const e=this.selectionStart[0]+this.selectionStartLength;return e>this._bufferService.cols?e%this._bufferService.cols==0?[this._bufferService.cols,this.selectionStart[1]+Math.floor(e/this._bufferService.cols)-1]:[e%this._bufferService.cols,this.selectionStart[1]+Math.floor(e/this._bufferService.cols)]:[e,this.selectionStart[1]]}if(this.selectionStartLength&&this.selectionEnd[1]===this.selectionStart[1]){const e=this.selectionStart[0]+this.selectionStartLength;return e>this._bufferService.cols?[e%this._bufferService.cols,this.selectionStart[1]+Math.floor(e/this._bufferService.cols)]:[Math.max(e,this.selectionEnd[0]),this.selectionEnd[1]]}return this.selectionEnd}}areSelectionValuesReversed(){const e=this.selectionStart,t=this.selectionEnd;return!(!e||!t)&&(e[1]>t[1]||e[1]===t[1]&&e[0]>t[0])}handleTrim(e){return this.selectionStart&&(this.selectionStart[1]-=e),this.selectionEnd&&(this.selectionEnd[1]-=e),this.selectionEnd&&this.selectionEnd[1]<0?(this.clearSelection(),!0):(this.selectionStart&&this.selectionStart[1]<0&&(this.selectionStart[1]=0),!1)}}},428:function(e,t,i){var s=this&&this.__decorate||function(e,t,i,s){var r,n=arguments.length,o=n<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,i,s);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(o=(n<3?r(o):n>3?r(t,i,o):r(t,i))||o);return n>3&&o&&Object.defineProperty(t,i,o),o},r=this&&this.__param||function(e,t){return function(i,s){t(i,s,e)}};Object.defineProperty(t,"__esModule",{value:!0}),t.CharSizeService=void 0;const n=i(2585),o=i(8460),a=i(844);let h=t.CharSizeService=class extends a.Disposable{get hasValidSize(){return this.width>0&&this.height>0}constructor(e,t,i){super(),this._optionsService=i,this.width=0,this.height=0,this._onCharSizeChange=this.register(new o.EventEmitter),this.onCharSizeChange=this._onCharSizeChange.event;try{this._measureStrategy=this.register(new d(this._optionsService))}catch{this._measureStrategy=this.register(new l(e,t,this._optionsService))}this.register(this._optionsService.onMultipleOptionChange(["fontFamily","fontSize"],(()=>this.measure())))}measure(){const e=this._measureStrategy.measure();e.width===this.width&&e.height===this.height||(this.width=e.width,this.height=e.height,this._onCharSizeChange.fire())}};t.CharSizeService=h=s([r(2,n.IOptionsService)],h);class c extends a.Disposable{constructor(){super(...arguments),this._result={width:0,height:0}}_validateAndSet(e,t){void 0!==e&&e>0&&void 0!==t&&t>0&&(this._result.width=e,this._result.height=t)}}class l extends c{constructor(e,t,i){super(),this._document=e,this._parentElement=t,this._optionsService=i,this._measureElement=this._document.createElement("span"),this._measureElement.classList.add("xterm-char-measure-element"),this._measureElement.textContent="W".repeat(32),this._measureElement.setAttribute("aria-hidden","true"),this._measureElement.style.whiteSpace="pre",this._measureElement.style.fontKerning="none",this._parentElement.appendChild(this._measureElement)}measure(){return this._measureElement.style.fontFamily=this._optionsService.rawOptions.fontFamily,this._measureElement.style.fontSize=`${this._optionsService.rawOptions.fontSize}px`,this._validateAndSet(Number(this._measureElement.offsetWidth)/32,Number(this._measureElement.offsetHeight)),this._result}}class d extends c{constructor(e){super(),this._optionsService=e,this._canvas=new OffscreenCanvas(100,100),this._ctx=this._canvas.getContext("2d");const t=this._ctx.measureText("W");if(!("width"in t&&"fontBoundingBoxAscent"in t&&"fontBoundingBoxDescent"in t))throw new Error("Required font metrics not supported")}measure(){this._ctx.font=`${this._optionsService.rawOptions.fontSize}px ${this._optionsService.rawOptions.fontFamily}`;const e=this._ctx.measureText("W");return this._validateAndSet(e.width,e.fontBoundingBoxAscent+e.fontBoundingBoxDescent),this._result}}},4269:function(e,t,i){var s=this&&this.__decorate||function(e,t,i,s){var r,n=arguments.length,o=n<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,i,s);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(o=(n<3?r(o):n>3?r(t,i,o):r(t,i))||o);return n>3&&o&&Object.defineProperty(t,i,o),o},r=this&&this.__param||function(e,t){return function(i,s){t(i,s,e)}};Object.defineProperty(t,"__esModule",{value:!0}),t.CharacterJoinerService=t.JoinedCellData=void 0;const n=i(3734),o=i(643),a=i(511),h=i(2585);class c extends n.AttributeData{constructor(e,t,i){super(),this.content=0,this.combinedData="",this.fg=e.fg,this.bg=e.bg,this.combinedData=t,this._width=i}isCombined(){return 2097152}getWidth(){return this._width}getChars(){return this.combinedData}getCode(){return 2097151}setFromCharData(e){throw new Error("not implemented")}getAsCharData(){return[this.fg,this.getChars(),this.getWidth(),this.getCode()]}}t.JoinedCellData=c;let l=t.CharacterJoinerService=class e{constructor(e){this._bufferService=e,this._characterJoiners=[],this._nextCharacterJoinerId=0,this._workCell=new a.CellData}register(e){const t={id:this._nextCharacterJoinerId++,handler:e};return this._characterJoiners.push(t),t.id}deregister(e){for(let t=0;t1){const e=this._getJoinedRanges(s,a,n,t,r);for(let t=0;t1){const e=this._getJoinedRanges(s,a,n,t,r);for(let t=0;t{Object.defineProperty(t,"__esModule",{value:!0}),t.CoreBrowserService=void 0;const s=i(844),r=i(8460),n=i(3656);class o extends s.Disposable{constructor(e,t,i){super(),this._textarea=e,this._window=t,this.mainDocument=i,this._isFocused=!1,this._cachedIsFocused=void 0,this._screenDprMonitor=new a(this._window),this._onDprChange=this.register(new r.EventEmitter),this.onDprChange=this._onDprChange.event,this._onWindowChange=this.register(new r.EventEmitter),this.onWindowChange=this._onWindowChange.event,this.register(this.onWindowChange((e=>this._screenDprMonitor.setWindow(e)))),this.register((0,r.forwardEvent)(this._screenDprMonitor.onDprChange,this._onDprChange)),this._textarea.addEventListener("focus",(()=>this._isFocused=!0)),this._textarea.addEventListener("blur",(()=>this._isFocused=!1))}get window(){return this._window}set window(e){this._window!==e&&(this._window=e,this._onWindowChange.fire(this._window))}get dpr(){return this.window.devicePixelRatio}get isFocused(){return void 0===this._cachedIsFocused&&(this._cachedIsFocused=this._isFocused&&this._textarea.ownerDocument.hasFocus(),queueMicrotask((()=>this._cachedIsFocused=void 0))),this._cachedIsFocused}}t.CoreBrowserService=o;class a extends s.Disposable{constructor(e){super(),this._parentWindow=e,this._windowResizeListener=this.register(new s.MutableDisposable),this._onDprChange=this.register(new r.EventEmitter),this.onDprChange=this._onDprChange.event,this._outerListener=()=>this._setDprAndFireIfDiffers(),this._currentDevicePixelRatio=this._parentWindow.devicePixelRatio,this._updateDpr(),this._setWindowResizeListener(),this.register((0,s.toDisposable)((()=>this.clearListener())))}setWindow(e){this._parentWindow=e,this._setWindowResizeListener(),this._setDprAndFireIfDiffers()}_setWindowResizeListener(){this._windowResizeListener.value=(0,n.addDisposableDomListener)(this._parentWindow,"resize",(()=>this._setDprAndFireIfDiffers()))}_setDprAndFireIfDiffers(){this._parentWindow.devicePixelRatio!==this._currentDevicePixelRatio&&this._onDprChange.fire(this._parentWindow.devicePixelRatio),this._updateDpr()}_updateDpr(){this._outerListener&&(this._resolutionMediaMatchList?.removeListener(this._outerListener),this._currentDevicePixelRatio=this._parentWindow.devicePixelRatio,this._resolutionMediaMatchList=this._parentWindow.matchMedia(`screen and (resolution: ${this._parentWindow.devicePixelRatio}dppx)`),this._resolutionMediaMatchList.addListener(this._outerListener))}clearListener(){this._resolutionMediaMatchList&&this._outerListener&&(this._resolutionMediaMatchList.removeListener(this._outerListener),this._resolutionMediaMatchList=void 0,this._outerListener=void 0)}}},779:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.LinkProviderService=void 0;const s=i(844);class r extends s.Disposable{constructor(){super(),this.linkProviders=[],this.register((0,s.toDisposable)((()=>this.linkProviders.length=0)))}registerLinkProvider(e){return this.linkProviders.push(e),{dispose:()=>{const t=this.linkProviders.indexOf(e);-1!==t&&this.linkProviders.splice(t,1)}}}}t.LinkProviderService=r},8934:function(e,t,i){var s=this&&this.__decorate||function(e,t,i,s){var r,n=arguments.length,o=n<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,i,s);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(o=(n<3?r(o):n>3?r(t,i,o):r(t,i))||o);return n>3&&o&&Object.defineProperty(t,i,o),o},r=this&&this.__param||function(e,t){return function(i,s){t(i,s,e)}};Object.defineProperty(t,"__esModule",{value:!0}),t.MouseService=void 0;const n=i(4725),o=i(9806);let a=t.MouseService=class{constructor(e,t){this._renderService=e,this._charSizeService=t}getCoords(e,t,i,s,r){return(0,o.getCoords)(window,e,t,i,s,this._charSizeService.hasValidSize,this._renderService.dimensions.css.cell.width,this._renderService.dimensions.css.cell.height,r)}getMouseReportCoords(e,t){const i=(0,o.getCoordsRelativeToElement)(window,e,t);if(this._charSizeService.hasValidSize)return i[0]=Math.min(Math.max(i[0],0),this._renderService.dimensions.css.canvas.width-1),i[1]=Math.min(Math.max(i[1],0),this._renderService.dimensions.css.canvas.height-1),{col:Math.floor(i[0]/this._renderService.dimensions.css.cell.width),row:Math.floor(i[1]/this._renderService.dimensions.css.cell.height),x:Math.floor(i[0]),y:Math.floor(i[1])}}};t.MouseService=a=s([r(0,n.IRenderService),r(1,n.ICharSizeService)],a)},3230:function(e,t,i){var s=this&&this.__decorate||function(e,t,i,s){var r,n=arguments.length,o=n<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,i,s);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(o=(n<3?r(o):n>3?r(t,i,o):r(t,i))||o);return n>3&&o&&Object.defineProperty(t,i,o),o},r=this&&this.__param||function(e,t){return function(i,s){t(i,s,e)}};Object.defineProperty(t,"__esModule",{value:!0}),t.RenderService=void 0;const n=i(6193),o=i(4725),a=i(8460),h=i(844),c=i(7226),l=i(2585);let d=t.RenderService=class extends h.Disposable{get dimensions(){return this._renderer.value.dimensions}constructor(e,t,i,s,r,o,l,d){super(),this._rowCount=e,this._charSizeService=s,this._renderer=this.register(new h.MutableDisposable),this._pausedResizeTask=new c.DebouncedIdleTask,this._observerDisposable=this.register(new h.MutableDisposable),this._isPaused=!1,this._needsFullRefresh=!1,this._isNextRenderRedrawOnly=!0,this._needsSelectionRefresh=!1,this._canvasWidth=0,this._canvasHeight=0,this._selectionState={start:void 0,end:void 0,columnSelectMode:!1},this._onDimensionsChange=this.register(new a.EventEmitter),this.onDimensionsChange=this._onDimensionsChange.event,this._onRenderedViewportChange=this.register(new a.EventEmitter),this.onRenderedViewportChange=this._onRenderedViewportChange.event,this._onRender=this.register(new a.EventEmitter),this.onRender=this._onRender.event,this._onRefreshRequest=this.register(new a.EventEmitter),this.onRefreshRequest=this._onRefreshRequest.event,this._renderDebouncer=new n.RenderDebouncer(((e,t)=>this._renderRows(e,t)),l),this.register(this._renderDebouncer),this.register(l.onDprChange((()=>this.handleDevicePixelRatioChange()))),this.register(o.onResize((()=>this._fullRefresh()))),this.register(o.buffers.onBufferActivate((()=>this._renderer.value?.clear()))),this.register(i.onOptionChange((()=>this._handleOptionsChanged()))),this.register(this._charSizeService.onCharSizeChange((()=>this.handleCharSizeChanged()))),this.register(r.onDecorationRegistered((()=>this._fullRefresh()))),this.register(r.onDecorationRemoved((()=>this._fullRefresh()))),this.register(i.onMultipleOptionChange(["customGlyphs","drawBoldTextInBrightColors","letterSpacing","lineHeight","fontFamily","fontSize","fontWeight","fontWeightBold","minimumContrastRatio","rescaleOverlappingGlyphs"],(()=>{this.clear(),this.handleResize(o.cols,o.rows),this._fullRefresh()}))),this.register(i.onMultipleOptionChange(["cursorBlink","cursorStyle"],(()=>this.refreshRows(o.buffer.y,o.buffer.y,!0)))),this.register(d.onChangeColors((()=>this._fullRefresh()))),this._registerIntersectionObserver(l.window,t),this.register(l.onWindowChange((e=>this._registerIntersectionObserver(e,t))))}_registerIntersectionObserver(e,t){if("IntersectionObserver"in e){const i=new e.IntersectionObserver((e=>this._handleIntersectionChange(e[e.length-1])),{threshold:0});i.observe(t),this._observerDisposable.value=(0,h.toDisposable)((()=>i.disconnect()))}}_handleIntersectionChange(e){this._isPaused=void 0===e.isIntersecting?0===e.intersectionRatio:!e.isIntersecting,this._isPaused||this._charSizeService.hasValidSize||this._charSizeService.measure(),!this._isPaused&&this._needsFullRefresh&&(this._pausedResizeTask.flush(),this.refreshRows(0,this._rowCount-1),this._needsFullRefresh=!1)}refreshRows(e,t,i=!1){this._isPaused?this._needsFullRefresh=!0:(i||(this._isNextRenderRedrawOnly=!1),this._renderDebouncer.refresh(e,t,this._rowCount))}_renderRows(e,t){this._renderer.value&&(e=Math.min(e,this._rowCount-1),t=Math.min(t,this._rowCount-1),this._renderer.value.renderRows(e,t),this._needsSelectionRefresh&&(this._renderer.value.handleSelectionChanged(this._selectionState.start,this._selectionState.end,this._selectionState.columnSelectMode),this._needsSelectionRefresh=!1),this._isNextRenderRedrawOnly||this._onRenderedViewportChange.fire({start:e,end:t}),this._onRender.fire({start:e,end:t}),this._isNextRenderRedrawOnly=!0)}resize(e,t){this._rowCount=t,this._fireOnCanvasResize()}_handleOptionsChanged(){this._renderer.value&&(this.refreshRows(0,this._rowCount-1),this._fireOnCanvasResize())}_fireOnCanvasResize(){this._renderer.value&&(this._renderer.value.dimensions.css.canvas.width===this._canvasWidth&&this._renderer.value.dimensions.css.canvas.height===this._canvasHeight||this._onDimensionsChange.fire(this._renderer.value.dimensions))}hasRenderer(){return!!this._renderer.value}setRenderer(e){this._renderer.value=e,this._renderer.value&&(this._renderer.value.onRequestRedraw((e=>this.refreshRows(e.start,e.end,!0))),this._needsSelectionRefresh=!0,this._fullRefresh())}addRefreshCallback(e){return this._renderDebouncer.addRefreshCallback(e)}_fullRefresh(){this._isPaused?this._needsFullRefresh=!0:this.refreshRows(0,this._rowCount-1)}clearTextureAtlas(){this._renderer.value&&(this._renderer.value.clearTextureAtlas?.(),this._fullRefresh())}handleDevicePixelRatioChange(){this._charSizeService.measure(),this._renderer.value&&(this._renderer.value.handleDevicePixelRatioChange(),this.refreshRows(0,this._rowCount-1))}handleResize(e,t){this._renderer.value&&(this._isPaused?this._pausedResizeTask.set((()=>this._renderer.value?.handleResize(e,t))):this._renderer.value.handleResize(e,t),this._fullRefresh())}handleCharSizeChanged(){this._renderer.value?.handleCharSizeChanged()}handleBlur(){this._renderer.value?.handleBlur()}handleFocus(){this._renderer.value?.handleFocus()}handleSelectionChanged(e,t,i){this._selectionState.start=e,this._selectionState.end=t,this._selectionState.columnSelectMode=i,this._renderer.value?.handleSelectionChanged(e,t,i)}handleCursorMove(){this._renderer.value?.handleCursorMove()}clear(){this._renderer.value?.clear()}};t.RenderService=d=s([r(2,l.IOptionsService),r(3,o.ICharSizeService),r(4,l.IDecorationService),r(5,l.IBufferService),r(6,o.ICoreBrowserService),r(7,o.IThemeService)],d)},9312:function(e,t,i){var s=this&&this.__decorate||function(e,t,i,s){var r,n=arguments.length,o=n<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,i,s);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(o=(n<3?r(o):n>3?r(t,i,o):r(t,i))||o);return n>3&&o&&Object.defineProperty(t,i,o),o},r=this&&this.__param||function(e,t){return function(i,s){t(i,s,e)}};Object.defineProperty(t,"__esModule",{value:!0}),t.SelectionService=void 0;const n=i(9806),o=i(9504),a=i(456),h=i(4725),c=i(8460),l=i(844),d=i(6114),_=i(4841),u=i(511),f=i(2585),v=String.fromCharCode(160),p=new RegExp(v,"g");let g=t.SelectionService=class extends l.Disposable{constructor(e,t,i,s,r,n,o,h,d){super(),this._element=e,this._screenElement=t,this._linkifier=i,this._bufferService=s,this._coreService=r,this._mouseService=n,this._optionsService=o,this._renderService=h,this._coreBrowserService=d,this._dragScrollAmount=0,this._enabled=!0,this._workCell=new u.CellData,this._mouseDownTimeStamp=0,this._oldHasSelection=!1,this._oldSelectionStart=void 0,this._oldSelectionEnd=void 0,this._onLinuxMouseSelection=this.register(new c.EventEmitter),this.onLinuxMouseSelection=this._onLinuxMouseSelection.event,this._onRedrawRequest=this.register(new c.EventEmitter),this.onRequestRedraw=this._onRedrawRequest.event,this._onSelectionChange=this.register(new c.EventEmitter),this.onSelectionChange=this._onSelectionChange.event,this._onRequestScrollLines=this.register(new c.EventEmitter),this.onRequestScrollLines=this._onRequestScrollLines.event,this._mouseMoveListener=e=>this._handleMouseMove(e),this._mouseUpListener=e=>this._handleMouseUp(e),this._coreService.onUserInput((()=>{this.hasSelection&&this.clearSelection()})),this._trimListener=this._bufferService.buffer.lines.onTrim((e=>this._handleTrim(e))),this.register(this._bufferService.buffers.onBufferActivate((e=>this._handleBufferActivate(e)))),this.enable(),this._model=new a.SelectionModel(this._bufferService),this._activeSelectionMode=0,this.register((0,l.toDisposable)((()=>{this._removeMouseDownListeners()})))}reset(){this.clearSelection()}disable(){this.clearSelection(),this._enabled=!1}enable(){this._enabled=!0}get selectionStart(){return this._model.finalSelectionStart}get selectionEnd(){return this._model.finalSelectionEnd}get hasSelection(){const e=this._model.finalSelectionStart,t=this._model.finalSelectionEnd;return!(!e||!t||e[0]===t[0]&&e[1]===t[1])}get selectionText(){const e=this._model.finalSelectionStart,t=this._model.finalSelectionEnd;if(!e||!t)return"";const i=this._bufferService.buffer,s=[];if(3===this._activeSelectionMode){if(e[0]===t[0])return"";const r=e[0]e.replace(p," "))).join(d.isWindows?"\r\n":"\n")}clearSelection(){this._model.clearSelection(),this._removeMouseDownListeners(),this.refresh(),this._onSelectionChange.fire()}refresh(e){this._refreshAnimationFrame||(this._refreshAnimationFrame=this._coreBrowserService.window.requestAnimationFrame((()=>this._refresh()))),d.isLinux&&e&&this.selectionText.length&&this._onLinuxMouseSelection.fire(this.selectionText)}_refresh(){this._refreshAnimationFrame=void 0,this._onRedrawRequest.fire({start:this._model.finalSelectionStart,end:this._model.finalSelectionEnd,columnSelectMode:3===this._activeSelectionMode})}_isClickInSelection(e){const t=this._getMouseBufferCoords(e),i=this._model.finalSelectionStart,s=this._model.finalSelectionEnd;return!!(i&&s&&t)&&this._areCoordsInSelection(t,i,s)}isCellInSelection(e,t){const i=this._model.finalSelectionStart,s=this._model.finalSelectionEnd;return!(!i||!s)&&this._areCoordsInSelection([e,t],i,s)}_areCoordsInSelection(e,t,i){return e[1]>t[1]&&e[1]=t[0]&&e[0]=t[0]}_selectWordAtCursor(e,t){const i=this._linkifier.currentLink?.link?.range;if(i)return this._model.selectionStart=[i.start.x-1,i.start.y-1],this._model.selectionStartLength=(0,_.getRangeLength)(i,this._bufferService.cols),this._model.selectionEnd=void 0,!0;const s=this._getMouseBufferCoords(e);return!!s&&(this._selectWordAt(s,t),this._model.selectionEnd=void 0,!0)}selectAll(){this._model.isSelectAllActive=!0,this.refresh(),this._onSelectionChange.fire()}selectLines(e,t){this._model.clearSelection(),e=Math.max(e,0),t=Math.min(t,this._bufferService.buffer.lines.length-1),this._model.selectionStart=[0,e],this._model.selectionEnd=[this._bufferService.cols,t],this.refresh(),this._onSelectionChange.fire()}_handleTrim(e){this._model.handleTrim(e)&&this.refresh()}_getMouseBufferCoords(e){const t=this._mouseService.getCoords(e,this._screenElement,this._bufferService.cols,this._bufferService.rows,!0);if(t)return t[0]--,t[1]--,t[1]+=this._bufferService.buffer.ydisp,t}_getMouseEventScrollAmount(e){let t=(0,n.getCoordsRelativeToElement)(this._coreBrowserService.window,e,this._screenElement)[1];const i=this._renderService.dimensions.css.canvas.height;return t>=0&&t<=i?0:(t>i&&(t-=i),t=Math.min(Math.max(t,-50),50),t/=50,t/Math.abs(t)+Math.round(14*t))}shouldForceSelection(e){return d.isMac?e.altKey&&this._optionsService.rawOptions.macOptionClickForcesSelection:e.shiftKey}handleMouseDown(e){if(this._mouseDownTimeStamp=e.timeStamp,(2!==e.button||!this.hasSelection)&&0===e.button){if(!this._enabled){if(!this.shouldForceSelection(e))return;e.stopPropagation()}e.preventDefault(),this._dragScrollAmount=0,this._enabled&&e.shiftKey?this._handleIncrementalClick(e):1===e.detail?this._handleSingleClick(e):2===e.detail?this._handleDoubleClick(e):3===e.detail&&this._handleTripleClick(e),this._addMouseDownListeners(),this.refresh(!0)}}_addMouseDownListeners(){this._screenElement.ownerDocument&&(this._screenElement.ownerDocument.addEventListener("mousemove",this._mouseMoveListener),this._screenElement.ownerDocument.addEventListener("mouseup",this._mouseUpListener)),this._dragScrollIntervalTimer=this._coreBrowserService.window.setInterval((()=>this._dragScroll()),50)}_removeMouseDownListeners(){this._screenElement.ownerDocument&&(this._screenElement.ownerDocument.removeEventListener("mousemove",this._mouseMoveListener),this._screenElement.ownerDocument.removeEventListener("mouseup",this._mouseUpListener)),this._coreBrowserService.window.clearInterval(this._dragScrollIntervalTimer),this._dragScrollIntervalTimer=void 0}_handleIncrementalClick(e){this._model.selectionStart&&(this._model.selectionEnd=this._getMouseBufferCoords(e))}_handleSingleClick(e){if(this._model.selectionStartLength=0,this._model.isSelectAllActive=!1,this._activeSelectionMode=this.shouldColumnSelect(e)?3:0,this._model.selectionStart=this._getMouseBufferCoords(e),!this._model.selectionStart)return;this._model.selectionEnd=void 0;const t=this._bufferService.buffer.lines.get(this._model.selectionStart[1]);t&&t.length!==this._model.selectionStart[0]&&0===t.hasWidth(this._model.selectionStart[0])&&this._model.selectionStart[0]++}_handleDoubleClick(e){this._selectWordAtCursor(e,!0)&&(this._activeSelectionMode=1)}_handleTripleClick(e){const t=this._getMouseBufferCoords(e);t&&(this._activeSelectionMode=2,this._selectLineAt(t[1]))}shouldColumnSelect(e){return e.altKey&&!(d.isMac&&this._optionsService.rawOptions.macOptionClickForcesSelection)}_handleMouseMove(e){if(e.stopImmediatePropagation(),!this._model.selectionStart)return;const t=this._model.selectionEnd?[this._model.selectionEnd[0],this._model.selectionEnd[1]]:null;if(this._model.selectionEnd=this._getMouseBufferCoords(e),!this._model.selectionEnd)return void this.refresh(!0);2===this._activeSelectionMode?this._model.selectionEnd[1]0?this._model.selectionEnd[0]=this._bufferService.cols:this._dragScrollAmount<0&&(this._model.selectionEnd[0]=0));const i=this._bufferService.buffer;if(this._model.selectionEnd[1]0?(3!==this._activeSelectionMode&&(this._model.selectionEnd[0]=this._bufferService.cols),this._model.selectionEnd[1]=Math.min(e.ydisp+this._bufferService.rows,e.lines.length-1)):(3!==this._activeSelectionMode&&(this._model.selectionEnd[0]=0),this._model.selectionEnd[1]=e.ydisp),this.refresh()}}_handleMouseUp(e){const t=e.timeStamp-this._mouseDownTimeStamp;if(this._removeMouseDownListeners(),this.selectionText.length<=1&&t<500&&e.altKey&&this._optionsService.rawOptions.altClickMovesCursor){if(this._bufferService.buffer.ybase===this._bufferService.buffer.ydisp){const t=this._mouseService.getCoords(e,this._element,this._bufferService.cols,this._bufferService.rows,!1);if(t&&void 0!==t[0]&&void 0!==t[1]){const e=(0,o.moveToCellSequence)(t[0]-1,t[1]-1,this._bufferService,this._coreService.decPrivateModes.applicationCursorKeys);this._coreService.triggerDataEvent(e,!0)}}}else this._fireEventIfSelectionChanged()}_fireEventIfSelectionChanged(){const e=this._model.finalSelectionStart,t=this._model.finalSelectionEnd,i=!(!e||!t||e[0]===t[0]&&e[1]===t[1]);i?e&&t&&(this._oldSelectionStart&&this._oldSelectionEnd&&e[0]===this._oldSelectionStart[0]&&e[1]===this._oldSelectionStart[1]&&t[0]===this._oldSelectionEnd[0]&&t[1]===this._oldSelectionEnd[1]||this._fireOnSelectionChange(e,t,i)):this._oldHasSelection&&this._fireOnSelectionChange(e,t,i)}_fireOnSelectionChange(e,t,i){this._oldSelectionStart=e,this._oldSelectionEnd=t,this._oldHasSelection=i,this._onSelectionChange.fire()}_handleBufferActivate(e){this.clearSelection(),this._trimListener.dispose(),this._trimListener=e.activeBuffer.lines.onTrim((e=>this._handleTrim(e)))}_convertViewportColToCharacterIndex(e,t){let i=t;for(let s=0;t>=s;s++){const r=e.loadCell(s,this._workCell).getChars().length;0===this._workCell.getWidth()?i--:r>1&&t!==s&&(i+=r-1)}return i}setSelection(e,t,i){this._model.clearSelection(),this._removeMouseDownListeners(),this._model.selectionStart=[e,t],this._model.selectionStartLength=i,this.refresh(),this._fireEventIfSelectionChanged()}rightClickSelect(e){this._isClickInSelection(e)||(this._selectWordAtCursor(e,!1)&&this.refresh(!0),this._fireEventIfSelectionChanged())}_getWordAt(e,t,i=!0,s=!0){if(e[0]>=this._bufferService.cols)return;const r=this._bufferService.buffer,n=r.lines.get(e[1]);if(!n)return;const o=r.translateBufferLineToString(e[1],!1);let a=this._convertViewportColToCharacterIndex(n,e[0]),h=a;const c=e[0]-a;let l=0,d=0,_=0,u=0;if(" "===o.charAt(a)){for(;a>0&&" "===o.charAt(a-1);)a--;for(;h1&&(u+=s-1,h+=s-1);t>0&&a>0&&!this._isCharWordSeparator(n.loadCell(t-1,this._workCell));){n.loadCell(t-1,this._workCell);const e=this._workCell.getChars().length;0===this._workCell.getWidth()?(l++,t--):e>1&&(_+=e-1,a-=e-1),a--,t--}for(;i1&&(u+=e-1,h+=e-1),h++,i++}}h++;let f=a+c-l+_,v=Math.min(this._bufferService.cols,h-a+l+d-_-u);if(t||""!==o.slice(a,h).trim()){if(i&&0===f&&32!==n.getCodePoint(0)){const t=r.lines.get(e[1]-1);if(t&&n.isWrapped&&32!==t.getCodePoint(this._bufferService.cols-1)){const t=this._getWordAt([this._bufferService.cols-1,e[1]-1],!1,!0,!1);if(t){const e=this._bufferService.cols-t.start;f-=e,v+=e}}}if(s&&f+v===this._bufferService.cols&&32!==n.getCodePoint(this._bufferService.cols-1)){const t=r.lines.get(e[1]+1);if(t?.isWrapped&&32!==t.getCodePoint(0)){const t=this._getWordAt([0,e[1]+1],!1,!1,!0);t&&(v+=t.length)}}return{start:f,length:v}}}_selectWordAt(e,t){const i=this._getWordAt(e,t);if(i){for(;i.start<0;)i.start+=this._bufferService.cols,e[1]--;this._model.selectionStart=[i.start,e[1]],this._model.selectionStartLength=i.length}}_selectToWordAt(e){const t=this._getWordAt(e,!0);if(t){let i=e[1];for(;t.start<0;)t.start+=this._bufferService.cols,i--;if(!this._model.areSelectionValuesReversed())for(;t.start+t.length>this._bufferService.cols;)t.length-=this._bufferService.cols,i++;this._model.selectionEnd=[this._model.areSelectionValuesReversed()?t.start:t.start+t.length,i]}}_isCharWordSeparator(e){return 0!==e.getWidth()&&this._optionsService.rawOptions.wordSeparator.indexOf(e.getChars())>=0}_selectLineAt(e){const t=this._bufferService.buffer.getWrappedRangeForLine(e),i={start:{x:0,y:t.first},end:{x:this._bufferService.cols-1,y:t.last}};this._model.selectionStart=[0,t.first],this._model.selectionEnd=void 0,this._model.selectionStartLength=(0,_.getRangeLength)(i,this._bufferService.cols)}};t.SelectionService=g=s([r(3,f.IBufferService),r(4,f.ICoreService),r(5,h.IMouseService),r(6,f.IOptionsService),r(7,h.IRenderService),r(8,h.ICoreBrowserService)],g)},4725:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ILinkProviderService=t.IThemeService=t.ICharacterJoinerService=t.ISelectionService=t.IRenderService=t.IMouseService=t.ICoreBrowserService=t.ICharSizeService=void 0;const s=i(8343);t.ICharSizeService=(0,s.createDecorator)("CharSizeService"),t.ICoreBrowserService=(0,s.createDecorator)("CoreBrowserService"),t.IMouseService=(0,s.createDecorator)("MouseService"),t.IRenderService=(0,s.createDecorator)("RenderService"),t.ISelectionService=(0,s.createDecorator)("SelectionService"),t.ICharacterJoinerService=(0,s.createDecorator)("CharacterJoinerService"),t.IThemeService=(0,s.createDecorator)("ThemeService"),t.ILinkProviderService=(0,s.createDecorator)("LinkProviderService")},6731:function(e,t,i){var s=this&&this.__decorate||function(e,t,i,s){var r,n=arguments.length,o=n<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,i,s);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(o=(n<3?r(o):n>3?r(t,i,o):r(t,i))||o);return n>3&&o&&Object.defineProperty(t,i,o),o},r=this&&this.__param||function(e,t){return function(i,s){t(i,s,e)}};Object.defineProperty(t,"__esModule",{value:!0}),t.ThemeService=t.DEFAULT_ANSI_COLORS=void 0;const n=i(7239),o=i(8055),a=i(8460),h=i(844),c=i(2585),l=o.css.toColor("#ffffff"),d=o.css.toColor("#000000"),_=o.css.toColor("#ffffff"),u=o.css.toColor("#000000"),f={css:"rgba(255, 255, 255, 0.3)",rgba:4294967117};t.DEFAULT_ANSI_COLORS=Object.freeze((()=>{const e=[o.css.toColor("#2e3436"),o.css.toColor("#cc0000"),o.css.toColor("#4e9a06"),o.css.toColor("#c4a000"),o.css.toColor("#3465a4"),o.css.toColor("#75507b"),o.css.toColor("#06989a"),o.css.toColor("#d3d7cf"),o.css.toColor("#555753"),o.css.toColor("#ef2929"),o.css.toColor("#8ae234"),o.css.toColor("#fce94f"),o.css.toColor("#729fcf"),o.css.toColor("#ad7fa8"),o.css.toColor("#34e2e2"),o.css.toColor("#eeeeec")],t=[0,95,135,175,215,255];for(let i=0;i<216;i++){const s=t[i/36%6|0],r=t[i/6%6|0],n=t[i%6];e.push({css:o.channels.toCss(s,r,n),rgba:o.channels.toRgba(s,r,n)})}for(let t=0;t<24;t++){const i=8+10*t;e.push({css:o.channels.toCss(i,i,i),rgba:o.channels.toRgba(i,i,i)})}return e})());let v=t.ThemeService=class extends h.Disposable{get colors(){return this._colors}constructor(e){super(),this._optionsService=e,this._contrastCache=new n.ColorContrastCache,this._halfContrastCache=new n.ColorContrastCache,this._onChangeColors=this.register(new a.EventEmitter),this.onChangeColors=this._onChangeColors.event,this._colors={foreground:l,background:d,cursor:_,cursorAccent:u,selectionForeground:void 0,selectionBackgroundTransparent:f,selectionBackgroundOpaque:o.color.blend(d,f),selectionInactiveBackgroundTransparent:f,selectionInactiveBackgroundOpaque:o.color.blend(d,f),ansi:t.DEFAULT_ANSI_COLORS.slice(),contrastCache:this._contrastCache,halfContrastCache:this._halfContrastCache},this._updateRestoreColors(),this._setTheme(this._optionsService.rawOptions.theme),this.register(this._optionsService.onSpecificOptionChange("minimumContrastRatio",(()=>this._contrastCache.clear()))),this.register(this._optionsService.onSpecificOptionChange("theme",(()=>this._setTheme(this._optionsService.rawOptions.theme))))}_setTheme(e={}){const i=this._colors;if(i.foreground=p(e.foreground,l),i.background=p(e.background,d),i.cursor=p(e.cursor,_),i.cursorAccent=p(e.cursorAccent,u),i.selectionBackgroundTransparent=p(e.selectionBackground,f),i.selectionBackgroundOpaque=o.color.blend(i.background,i.selectionBackgroundTransparent),i.selectionInactiveBackgroundTransparent=p(e.selectionInactiveBackground,i.selectionBackgroundTransparent),i.selectionInactiveBackgroundOpaque=o.color.blend(i.background,i.selectionInactiveBackgroundTransparent),i.selectionForeground=e.selectionForeground?p(e.selectionForeground,o.NULL_COLOR):void 0,i.selectionForeground===o.NULL_COLOR&&(i.selectionForeground=void 0),o.color.isOpaque(i.selectionBackgroundTransparent)){const e=.3;i.selectionBackgroundTransparent=o.color.opacity(i.selectionBackgroundTransparent,e)}if(o.color.isOpaque(i.selectionInactiveBackgroundTransparent)){const e=.3;i.selectionInactiveBackgroundTransparent=o.color.opacity(i.selectionInactiveBackgroundTransparent,e)}if(i.ansi=t.DEFAULT_ANSI_COLORS.slice(),i.ansi[0]=p(e.black,t.DEFAULT_ANSI_COLORS[0]),i.ansi[1]=p(e.red,t.DEFAULT_ANSI_COLORS[1]),i.ansi[2]=p(e.green,t.DEFAULT_ANSI_COLORS[2]),i.ansi[3]=p(e.yellow,t.DEFAULT_ANSI_COLORS[3]),i.ansi[4]=p(e.blue,t.DEFAULT_ANSI_COLORS[4]),i.ansi[5]=p(e.magenta,t.DEFAULT_ANSI_COLORS[5]),i.ansi[6]=p(e.cyan,t.DEFAULT_ANSI_COLORS[6]),i.ansi[7]=p(e.white,t.DEFAULT_ANSI_COLORS[7]),i.ansi[8]=p(e.brightBlack,t.DEFAULT_ANSI_COLORS[8]),i.ansi[9]=p(e.brightRed,t.DEFAULT_ANSI_COLORS[9]),i.ansi[10]=p(e.brightGreen,t.DEFAULT_ANSI_COLORS[10]),i.ansi[11]=p(e.brightYellow,t.DEFAULT_ANSI_COLORS[11]),i.ansi[12]=p(e.brightBlue,t.DEFAULT_ANSI_COLORS[12]),i.ansi[13]=p(e.brightMagenta,t.DEFAULT_ANSI_COLORS[13]),i.ansi[14]=p(e.brightCyan,t.DEFAULT_ANSI_COLORS[14]),i.ansi[15]=p(e.brightWhite,t.DEFAULT_ANSI_COLORS[15]),e.extendedAnsi){const s=Math.min(i.ansi.length-16,e.extendedAnsi.length);for(let r=0;r{Object.defineProperty(t,"__esModule",{value:!0}),t.CircularList=void 0;const s=i(8460),r=i(844);class n extends r.Disposable{constructor(e){super(),this._maxLength=e,this.onDeleteEmitter=this.register(new s.EventEmitter),this.onDelete=this.onDeleteEmitter.event,this.onInsertEmitter=this.register(new s.EventEmitter),this.onInsert=this.onInsertEmitter.event,this.onTrimEmitter=this.register(new s.EventEmitter),this.onTrim=this.onTrimEmitter.event,this._array=new Array(this._maxLength),this._startIndex=0,this._length=0}get maxLength(){return this._maxLength}set maxLength(e){if(this._maxLength===e)return;const t=new Array(e);for(let i=0;ithis._length)for(let t=this._length;t=e;t--)this._array[this._getCyclicIndex(t+i.length)]=this._array[this._getCyclicIndex(t)];for(let t=0;tthis._maxLength){const e=this._length+i.length-this._maxLength;this._startIndex+=e,this._length=this._maxLength,this.onTrimEmitter.fire(e)}else this._length+=i.length}trimStart(e){e>this._length&&(e=this._length),this._startIndex+=e,this._length-=e,this.onTrimEmitter.fire(e)}shiftElements(e,t,i){if(!(t<=0)){if(e<0||e>=this._length)throw new Error("start argument out of range");if(e+i<0)throw new Error("Cannot shift elements in list beyond index 0");if(i>0){for(let s=t-1;s>=0;s--)this.set(e+s+i,this.get(e+s));const s=e+t+i-this._length;if(s>0)for(this._length+=s;this._length>this._maxLength;)this._length--,this._startIndex++,this.onTrimEmitter.fire(1)}else for(let s=0;s{Object.defineProperty(t,"__esModule",{value:!0}),t.clone=void 0,t.clone=function e(t,i=5){if("object"!=typeof t)return t;const s=Array.isArray(t)?[]:{};for(const r in t)s[r]=i<=1?t[r]:t[r]&&e(t[r],i-1);return s}},8055:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.contrastRatio=t.toPaddedHex=t.rgba=t.rgb=t.css=t.color=t.channels=t.NULL_COLOR=void 0;let i=0,s=0,r=0,n=0;var o,a,h,c,l;function d(e){const t=e.toString(16);return t.length<2?"0"+t:t}function _(e,t){return e>>0},e.toColor=function(t,i,s,r){return{css:e.toCss(t,i,s,r),rgba:e.toRgba(t,i,s,r)}}}(o||(t.channels=o={})),function(e){function t(e,t){return n=Math.round(255*t),[i,s,r]=l.toChannels(e.rgba),{css:o.toCss(i,s,r,n),rgba:o.toRgba(i,s,r,n)}}e.blend=function(e,t){if(n=(255&t.rgba)/255,1===n)return{css:t.css,rgba:t.rgba};const a=t.rgba>>24&255,h=t.rgba>>16&255,c=t.rgba>>8&255,l=e.rgba>>24&255,d=e.rgba>>16&255,_=e.rgba>>8&255;return i=l+Math.round((a-l)*n),s=d+Math.round((h-d)*n),r=_+Math.round((c-_)*n),{css:o.toCss(i,s,r),rgba:o.toRgba(i,s,r)}},e.isOpaque=function(e){return 255==(255&e.rgba)},e.ensureContrastRatio=function(e,t,i){const s=l.ensureContrastRatio(e.rgba,t.rgba,i);if(s)return o.toColor(s>>24&255,s>>16&255,s>>8&255)},e.opaque=function(e){const t=(255|e.rgba)>>>0;return[i,s,r]=l.toChannels(t),{css:o.toCss(i,s,r),rgba:t}},e.opacity=t,e.multiplyOpacity=function(e,i){return n=255&e.rgba,t(e,n*i/255)},e.toColorRGB=function(e){return[e.rgba>>24&255,e.rgba>>16&255,e.rgba>>8&255]}}(a||(t.color=a={})),function(e){let t,a;try{const e=document.createElement("canvas");e.width=1,e.height=1;const i=e.getContext("2d",{willReadFrequently:!0});i&&(t=i,t.globalCompositeOperation="copy",a=t.createLinearGradient(0,0,1,1))}catch{}e.toColor=function(e){if(e.match(/#[\da-f]{3,8}/i))switch(e.length){case 4:return i=parseInt(e.slice(1,2).repeat(2),16),s=parseInt(e.slice(2,3).repeat(2),16),r=parseInt(e.slice(3,4).repeat(2),16),o.toColor(i,s,r);case 5:return i=parseInt(e.slice(1,2).repeat(2),16),s=parseInt(e.slice(2,3).repeat(2),16),r=parseInt(e.slice(3,4).repeat(2),16),n=parseInt(e.slice(4,5).repeat(2),16),o.toColor(i,s,r,n);case 7:return{css:e,rgba:(parseInt(e.slice(1),16)<<8|255)>>>0};case 9:return{css:e,rgba:parseInt(e.slice(1),16)>>>0}}const h=e.match(/rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*(,\s*(0|1|\d?\.(\d+))\s*)?\)/);if(h)return i=parseInt(h[1]),s=parseInt(h[2]),r=parseInt(h[3]),n=Math.round(255*(void 0===h[5]?1:parseFloat(h[5]))),o.toColor(i,s,r,n);if(!t||!a)throw new Error("css.toColor: Unsupported css format");if(t.fillStyle=a,t.fillStyle=e,"string"!=typeof t.fillStyle)throw new Error("css.toColor: Unsupported css format");if(t.fillRect(0,0,1,1),[i,s,r,n]=t.getImageData(0,0,1,1).data,255!==n)throw new Error("css.toColor: Unsupported css format");return{rgba:o.toRgba(i,s,r,n),css:e}}}(h||(t.css=h={})),function(e){function t(e,t,i){const s=e/255,r=t/255,n=i/255;return.2126*(s<=.03928?s/12.92:Math.pow((s+.055)/1.055,2.4))+.7152*(r<=.03928?r/12.92:Math.pow((r+.055)/1.055,2.4))+.0722*(n<=.03928?n/12.92:Math.pow((n+.055)/1.055,2.4))}e.relativeLuminance=function(e){return t(e>>16&255,e>>8&255,255&e)},e.relativeLuminance2=t}(c||(t.rgb=c={})),function(e){function t(e,t,i){const s=e>>24&255,r=e>>16&255,n=e>>8&255;let o=t>>24&255,a=t>>16&255,h=t>>8&255,l=_(c.relativeLuminance2(o,a,h),c.relativeLuminance2(s,r,n));for(;l0||a>0||h>0);)o-=Math.max(0,Math.ceil(.1*o)),a-=Math.max(0,Math.ceil(.1*a)),h-=Math.max(0,Math.ceil(.1*h)),l=_(c.relativeLuminance2(o,a,h),c.relativeLuminance2(s,r,n));return(o<<24|a<<16|h<<8|255)>>>0}function a(e,t,i){const s=e>>24&255,r=e>>16&255,n=e>>8&255;let o=t>>24&255,a=t>>16&255,h=t>>8&255,l=_(c.relativeLuminance2(o,a,h),c.relativeLuminance2(s,r,n));for(;l>>0}e.blend=function(e,t){if(n=(255&t)/255,1===n)return t;const a=t>>24&255,h=t>>16&255,c=t>>8&255,l=e>>24&255,d=e>>16&255,_=e>>8&255;return i=l+Math.round((a-l)*n),s=d+Math.round((h-d)*n),r=_+Math.round((c-_)*n),o.toRgba(i,s,r)},e.ensureContrastRatio=function(e,i,s){const r=c.relativeLuminance(e>>8),n=c.relativeLuminance(i>>8);if(_(r,n)>8));if(o_(r,c.relativeLuminance(t>>8))?n:t}return n}const o=a(e,i,s),h=_(r,c.relativeLuminance(o>>8));if(h_(r,c.relativeLuminance(n>>8))?o:n}return o}},e.reduceLuminance=t,e.increaseLuminance=a,e.toChannels=function(e){return[e>>24&255,e>>16&255,e>>8&255,255&e]}}(l||(t.rgba=l={})),t.toPaddedHex=d,t.contrastRatio=_},8969:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.CoreTerminal=void 0;const s=i(844),r=i(2585),n=i(4348),o=i(7866),a=i(744),h=i(7302),c=i(6975),l=i(8460),d=i(1753),_=i(1480),u=i(7994),f=i(9282),v=i(5435),p=i(5981),g=i(2660);let m=!1;class S extends s.Disposable{get onScroll(){return this._onScrollApi||(this._onScrollApi=this.register(new l.EventEmitter),this._onScroll.event((e=>{this._onScrollApi?.fire(e.position)}))),this._onScrollApi.event}get cols(){return this._bufferService.cols}get rows(){return this._bufferService.rows}get buffers(){return this._bufferService.buffers}get options(){return this.optionsService.options}set options(e){for(const t in e)this.optionsService.options[t]=e[t]}constructor(e){super(),this._windowsWrappingHeuristics=this.register(new s.MutableDisposable),this._onBinary=this.register(new l.EventEmitter),this.onBinary=this._onBinary.event,this._onData=this.register(new l.EventEmitter),this.onData=this._onData.event,this._onLineFeed=this.register(new l.EventEmitter),this.onLineFeed=this._onLineFeed.event,this._onResize=this.register(new l.EventEmitter),this.onResize=this._onResize.event,this._onWriteParsed=this.register(new l.EventEmitter),this.onWriteParsed=this._onWriteParsed.event,this._onScroll=this.register(new l.EventEmitter),this._instantiationService=new n.InstantiationService,this.optionsService=this.register(new h.OptionsService(e)),this._instantiationService.setService(r.IOptionsService,this.optionsService),this._bufferService=this.register(this._instantiationService.createInstance(a.BufferService)),this._instantiationService.setService(r.IBufferService,this._bufferService),this._logService=this.register(this._instantiationService.createInstance(o.LogService)),this._instantiationService.setService(r.ILogService,this._logService),this.coreService=this.register(this._instantiationService.createInstance(c.CoreService)),this._instantiationService.setService(r.ICoreService,this.coreService),this.coreMouseService=this.register(this._instantiationService.createInstance(d.CoreMouseService)),this._instantiationService.setService(r.ICoreMouseService,this.coreMouseService),this.unicodeService=this.register(this._instantiationService.createInstance(_.UnicodeService)),this._instantiationService.setService(r.IUnicodeService,this.unicodeService),this._charsetService=this._instantiationService.createInstance(u.CharsetService),this._instantiationService.setService(r.ICharsetService,this._charsetService),this._oscLinkService=this._instantiationService.createInstance(g.OscLinkService),this._instantiationService.setService(r.IOscLinkService,this._oscLinkService),this._inputHandler=this.register(new v.InputHandler(this._bufferService,this._charsetService,this.coreService,this._logService,this.optionsService,this._oscLinkService,this.coreMouseService,this.unicodeService)),this.register((0,l.forwardEvent)(this._inputHandler.onLineFeed,this._onLineFeed)),this.register(this._inputHandler),this.register((0,l.forwardEvent)(this._bufferService.onResize,this._onResize)),this.register((0,l.forwardEvent)(this.coreService.onData,this._onData)),this.register((0,l.forwardEvent)(this.coreService.onBinary,this._onBinary)),this.register(this.coreService.onRequestScrollToBottom((()=>this.scrollToBottom()))),this.register(this.coreService.onUserInput((()=>this._writeBuffer.handleUserInput()))),this.register(this.optionsService.onMultipleOptionChange(["windowsMode","windowsPty"],(()=>this._handleWindowsPtyOptionChange()))),this.register(this._bufferService.onScroll((e=>{this._onScroll.fire({position:this._bufferService.buffer.ydisp,source:0}),this._inputHandler.markRangeDirty(this._bufferService.buffer.scrollTop,this._bufferService.buffer.scrollBottom)}))),this.register(this._inputHandler.onScroll((e=>{this._onScroll.fire({position:this._bufferService.buffer.ydisp,source:0}),this._inputHandler.markRangeDirty(this._bufferService.buffer.scrollTop,this._bufferService.buffer.scrollBottom)}))),this._writeBuffer=this.register(new p.WriteBuffer(((e,t)=>this._inputHandler.parse(e,t)))),this.register((0,l.forwardEvent)(this._writeBuffer.onWriteParsed,this._onWriteParsed))}write(e,t){this._writeBuffer.write(e,t)}writeSync(e,t){this._logService.logLevel<=r.LogLevelEnum.WARN&&!m&&(this._logService.warn("writeSync is unreliable and will be removed soon."),m=!0),this._writeBuffer.writeSync(e,t)}input(e,t=!0){this.coreService.triggerDataEvent(e,t)}resize(e,t){isNaN(e)||isNaN(t)||(e=Math.max(e,a.MINIMUM_COLS),t=Math.max(t,a.MINIMUM_ROWS),this._bufferService.resize(e,t))}scroll(e,t=!1){this._bufferService.scroll(e,t)}scrollLines(e,t,i){this._bufferService.scrollLines(e,t,i)}scrollPages(e){this.scrollLines(e*(this.rows-1))}scrollToTop(){this.scrollLines(-this._bufferService.buffer.ydisp)}scrollToBottom(){this.scrollLines(this._bufferService.buffer.ybase-this._bufferService.buffer.ydisp)}scrollToLine(e){const t=e-this._bufferService.buffer.ydisp;0!==t&&this.scrollLines(t)}registerEscHandler(e,t){return this._inputHandler.registerEscHandler(e,t)}registerDcsHandler(e,t){return this._inputHandler.registerDcsHandler(e,t)}registerCsiHandler(e,t){return this._inputHandler.registerCsiHandler(e,t)}registerOscHandler(e,t){return this._inputHandler.registerOscHandler(e,t)}_setup(){this._handleWindowsPtyOptionChange()}reset(){this._inputHandler.reset(),this._bufferService.reset(),this._charsetService.reset(),this.coreService.reset(),this.coreMouseService.reset()}_handleWindowsPtyOptionChange(){let e=!1;const t=this.optionsService.rawOptions.windowsPty;t&&void 0!==t.buildNumber&&void 0!==t.buildNumber?e=!!("conpty"===t.backend&&t.buildNumber<21376):this.optionsService.rawOptions.windowsMode&&(e=!0),e?this._enableWindowsWrappingHeuristics():this._windowsWrappingHeuristics.clear()}_enableWindowsWrappingHeuristics(){if(!this._windowsWrappingHeuristics.value){const e=[];e.push(this.onLineFeed(f.updateWindowsModeWrappedState.bind(null,this._bufferService))),e.push(this.registerCsiHandler({final:"H"},(()=>((0,f.updateWindowsModeWrappedState)(this._bufferService),!1)))),this._windowsWrappingHeuristics.value=(0,s.toDisposable)((()=>{for(const t of e)t.dispose()}))}}}t.CoreTerminal=S},8460:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.runAndSubscribe=t.forwardEvent=t.EventEmitter=void 0,t.EventEmitter=class{constructor(){this._listeners=[],this._disposed=!1}get event(){return this._event||(this._event=e=>(this._listeners.push(e),{dispose:()=>{if(!this._disposed)for(let t=0;tt.fire(e)))},t.runAndSubscribe=function(e,t){return t(void 0),e((e=>t(e)))}},5435:function(e,t,i){var s=this&&this.__decorate||function(e,t,i,s){var r,n=arguments.length,o=n<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,i,s);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(o=(n<3?r(o):n>3?r(t,i,o):r(t,i))||o);return n>3&&o&&Object.defineProperty(t,i,o),o},r=this&&this.__param||function(e,t){return function(i,s){t(i,s,e)}};Object.defineProperty(t,"__esModule",{value:!0}),t.InputHandler=t.WindowsOptionsReportType=void 0;const n=i(2584),o=i(7116),a=i(2015),h=i(844),c=i(482),l=i(8437),d=i(8460),_=i(643),u=i(511),f=i(3734),v=i(2585),p=i(1480),g=i(6242),m=i(6351),S=i(5941),C={"(":0,")":1,"*":2,"+":3,"-":1,".":2},b=131072;function w(e,t){if(e>24)return t.setWinLines||!1;switch(e){case 1:return!!t.restoreWin;case 2:return!!t.minimizeWin;case 3:return!!t.setWinPosition;case 4:return!!t.setWinSizePixels;case 5:return!!t.raiseWin;case 6:return!!t.lowerWin;case 7:return!!t.refreshWin;case 8:return!!t.setWinSizeChars;case 9:return!!t.maximizeWin;case 10:return!!t.fullscreenWin;case 11:return!!t.getWinState;case 13:return!!t.getWinPosition;case 14:return!!t.getWinSizePixels;case 15:return!!t.getScreenSizePixels;case 16:return!!t.getCellSizePixels;case 18:return!!t.getWinSizeChars;case 19:return!!t.getScreenSizeChars;case 20:return!!t.getIconTitle;case 21:return!!t.getWinTitle;case 22:return!!t.pushTitle;case 23:return!!t.popTitle;case 24:return!!t.setWinLines}return!1}var y;!function(e){e[e.GET_WIN_SIZE_PIXELS=0]="GET_WIN_SIZE_PIXELS",e[e.GET_CELL_SIZE_PIXELS=1]="GET_CELL_SIZE_PIXELS"}(y||(t.WindowsOptionsReportType=y={}));let E=0;class k extends h.Disposable{getAttrData(){return this._curAttrData}constructor(e,t,i,s,r,h,_,f,v=new a.EscapeSequenceParser){super(),this._bufferService=e,this._charsetService=t,this._coreService=i,this._logService=s,this._optionsService=r,this._oscLinkService=h,this._coreMouseService=_,this._unicodeService=f,this._parser=v,this._parseBuffer=new Uint32Array(4096),this._stringDecoder=new c.StringToUtf32,this._utf8Decoder=new c.Utf8ToUtf32,this._workCell=new u.CellData,this._windowTitle="",this._iconName="",this._windowTitleStack=[],this._iconNameStack=[],this._curAttrData=l.DEFAULT_ATTR_DATA.clone(),this._eraseAttrDataInternal=l.DEFAULT_ATTR_DATA.clone(),this._onRequestBell=this.register(new d.EventEmitter),this.onRequestBell=this._onRequestBell.event,this._onRequestRefreshRows=this.register(new d.EventEmitter),this.onRequestRefreshRows=this._onRequestRefreshRows.event,this._onRequestReset=this.register(new d.EventEmitter),this.onRequestReset=this._onRequestReset.event,this._onRequestSendFocus=this.register(new d.EventEmitter),this.onRequestSendFocus=this._onRequestSendFocus.event,this._onRequestSyncScrollBar=this.register(new d.EventEmitter),this.onRequestSyncScrollBar=this._onRequestSyncScrollBar.event,this._onRequestWindowsOptionsReport=this.register(new d.EventEmitter),this.onRequestWindowsOptionsReport=this._onRequestWindowsOptionsReport.event,this._onA11yChar=this.register(new d.EventEmitter),this.onA11yChar=this._onA11yChar.event,this._onA11yTab=this.register(new d.EventEmitter),this.onA11yTab=this._onA11yTab.event,this._onCursorMove=this.register(new d.EventEmitter),this.onCursorMove=this._onCursorMove.event,this._onLineFeed=this.register(new d.EventEmitter),this.onLineFeed=this._onLineFeed.event,this._onScroll=this.register(new d.EventEmitter),this.onScroll=this._onScroll.event,this._onTitleChange=this.register(new d.EventEmitter),this.onTitleChange=this._onTitleChange.event,this._onColor=this.register(new d.EventEmitter),this.onColor=this._onColor.event,this._parseStack={paused:!1,cursorStartX:0,cursorStartY:0,decodedLength:0,position:0},this._specialColors=[256,257,258],this.register(this._parser),this._dirtyRowTracker=new L(this._bufferService),this._activeBuffer=this._bufferService.buffer,this.register(this._bufferService.buffers.onBufferActivate((e=>this._activeBuffer=e.activeBuffer))),this._parser.setCsiHandlerFallback(((e,t)=>{this._logService.debug("Unknown CSI code: ",{identifier:this._parser.identToString(e),params:t.toArray()})})),this._parser.setEscHandlerFallback((e=>{this._logService.debug("Unknown ESC code: ",{identifier:this._parser.identToString(e)})})),this._parser.setExecuteHandlerFallback((e=>{this._logService.debug("Unknown EXECUTE code: ",{code:e})})),this._parser.setOscHandlerFallback(((e,t,i)=>{this._logService.debug("Unknown OSC code: ",{identifier:e,action:t,data:i})})),this._parser.setDcsHandlerFallback(((e,t,i)=>{"HOOK"===t&&(i=i.toArray()),this._logService.debug("Unknown DCS code: ",{identifier:this._parser.identToString(e),action:t,payload:i})})),this._parser.setPrintHandler(((e,t,i)=>this.print(e,t,i))),this._parser.registerCsiHandler({final:"@"},(e=>this.insertChars(e))),this._parser.registerCsiHandler({intermediates:" ",final:"@"},(e=>this.scrollLeft(e))),this._parser.registerCsiHandler({final:"A"},(e=>this.cursorUp(e))),this._parser.registerCsiHandler({intermediates:" ",final:"A"},(e=>this.scrollRight(e))),this._parser.registerCsiHandler({final:"B"},(e=>this.cursorDown(e))),this._parser.registerCsiHandler({final:"C"},(e=>this.cursorForward(e))),this._parser.registerCsiHandler({final:"D"},(e=>this.cursorBackward(e))),this._parser.registerCsiHandler({final:"E"},(e=>this.cursorNextLine(e))),this._parser.registerCsiHandler({final:"F"},(e=>this.cursorPrecedingLine(e))),this._parser.registerCsiHandler({final:"G"},(e=>this.cursorCharAbsolute(e))),this._parser.registerCsiHandler({final:"H"},(e=>this.cursorPosition(e))),this._parser.registerCsiHandler({final:"I"},(e=>this.cursorForwardTab(e))),this._parser.registerCsiHandler({final:"J"},(e=>this.eraseInDisplay(e,!1))),this._parser.registerCsiHandler({prefix:"?",final:"J"},(e=>this.eraseInDisplay(e,!0))),this._parser.registerCsiHandler({final:"K"},(e=>this.eraseInLine(e,!1))),this._parser.registerCsiHandler({prefix:"?",final:"K"},(e=>this.eraseInLine(e,!0))),this._parser.registerCsiHandler({final:"L"},(e=>this.insertLines(e))),this._parser.registerCsiHandler({final:"M"},(e=>this.deleteLines(e))),this._parser.registerCsiHandler({final:"P"},(e=>this.deleteChars(e))),this._parser.registerCsiHandler({final:"S"},(e=>this.scrollUp(e))),this._parser.registerCsiHandler({final:"T"},(e=>this.scrollDown(e))),this._parser.registerCsiHandler({final:"X"},(e=>this.eraseChars(e))),this._parser.registerCsiHandler({final:"Z"},(e=>this.cursorBackwardTab(e))),this._parser.registerCsiHandler({final:"`"},(e=>this.charPosAbsolute(e))),this._parser.registerCsiHandler({final:"a"},(e=>this.hPositionRelative(e))),this._parser.registerCsiHandler({final:"b"},(e=>this.repeatPrecedingCharacter(e))),this._parser.registerCsiHandler({final:"c"},(e=>this.sendDeviceAttributesPrimary(e))),this._parser.registerCsiHandler({prefix:">",final:"c"},(e=>this.sendDeviceAttributesSecondary(e))),this._parser.registerCsiHandler({final:"d"},(e=>this.linePosAbsolute(e))),this._parser.registerCsiHandler({final:"e"},(e=>this.vPositionRelative(e))),this._parser.registerCsiHandler({final:"f"},(e=>this.hVPosition(e))),this._parser.registerCsiHandler({final:"g"},(e=>this.tabClear(e))),this._parser.registerCsiHandler({final:"h"},(e=>this.setMode(e))),this._parser.registerCsiHandler({prefix:"?",final:"h"},(e=>this.setModePrivate(e))),this._parser.registerCsiHandler({final:"l"},(e=>this.resetMode(e))),this._parser.registerCsiHandler({prefix:"?",final:"l"},(e=>this.resetModePrivate(e))),this._parser.registerCsiHandler({final:"m"},(e=>this.charAttributes(e))),this._parser.registerCsiHandler({final:"n"},(e=>this.deviceStatus(e))),this._parser.registerCsiHandler({prefix:"?",final:"n"},(e=>this.deviceStatusPrivate(e))),this._parser.registerCsiHandler({intermediates:"!",final:"p"},(e=>this.softReset(e))),this._parser.registerCsiHandler({intermediates:" ",final:"q"},(e=>this.setCursorStyle(e))),this._parser.registerCsiHandler({final:"r"},(e=>this.setScrollRegion(e))),this._parser.registerCsiHandler({final:"s"},(e=>this.saveCursor(e))),this._parser.registerCsiHandler({final:"t"},(e=>this.windowOptions(e))),this._parser.registerCsiHandler({final:"u"},(e=>this.restoreCursor(e))),this._parser.registerCsiHandler({intermediates:"'",final:"}"},(e=>this.insertColumns(e))),this._parser.registerCsiHandler({intermediates:"'",final:"~"},(e=>this.deleteColumns(e))),this._parser.registerCsiHandler({intermediates:'"',final:"q"},(e=>this.selectProtected(e))),this._parser.registerCsiHandler({intermediates:"$",final:"p"},(e=>this.requestMode(e,!0))),this._parser.registerCsiHandler({prefix:"?",intermediates:"$",final:"p"},(e=>this.requestMode(e,!1))),this._parser.setExecuteHandler(n.C0.BEL,(()=>this.bell())),this._parser.setExecuteHandler(n.C0.LF,(()=>this.lineFeed())),this._parser.setExecuteHandler(n.C0.VT,(()=>this.lineFeed())),this._parser.setExecuteHandler(n.C0.FF,(()=>this.lineFeed())),this._parser.setExecuteHandler(n.C0.CR,(()=>this.carriageReturn())),this._parser.setExecuteHandler(n.C0.BS,(()=>this.backspace())),this._parser.setExecuteHandler(n.C0.HT,(()=>this.tab())),this._parser.setExecuteHandler(n.C0.SO,(()=>this.shiftOut())),this._parser.setExecuteHandler(n.C0.SI,(()=>this.shiftIn())),this._parser.setExecuteHandler(n.C1.IND,(()=>this.index())),this._parser.setExecuteHandler(n.C1.NEL,(()=>this.nextLine())),this._parser.setExecuteHandler(n.C1.HTS,(()=>this.tabSet())),this._parser.registerOscHandler(0,new g.OscHandler((e=>(this.setTitle(e),this.setIconName(e),!0)))),this._parser.registerOscHandler(1,new g.OscHandler((e=>this.setIconName(e)))),this._parser.registerOscHandler(2,new g.OscHandler((e=>this.setTitle(e)))),this._parser.registerOscHandler(4,new g.OscHandler((e=>this.setOrReportIndexedColor(e)))),this._parser.registerOscHandler(8,new g.OscHandler((e=>this.setHyperlink(e)))),this._parser.registerOscHandler(10,new g.OscHandler((e=>this.setOrReportFgColor(e)))),this._parser.registerOscHandler(11,new g.OscHandler((e=>this.setOrReportBgColor(e)))),this._parser.registerOscHandler(12,new g.OscHandler((e=>this.setOrReportCursorColor(e)))),this._parser.registerOscHandler(104,new g.OscHandler((e=>this.restoreIndexedColor(e)))),this._parser.registerOscHandler(110,new g.OscHandler((e=>this.restoreFgColor(e)))),this._parser.registerOscHandler(111,new g.OscHandler((e=>this.restoreBgColor(e)))),this._parser.registerOscHandler(112,new g.OscHandler((e=>this.restoreCursorColor(e)))),this._parser.registerEscHandler({final:"7"},(()=>this.saveCursor())),this._parser.registerEscHandler({final:"8"},(()=>this.restoreCursor())),this._parser.registerEscHandler({final:"D"},(()=>this.index())),this._parser.registerEscHandler({final:"E"},(()=>this.nextLine())),this._parser.registerEscHandler({final:"H"},(()=>this.tabSet())),this._parser.registerEscHandler({final:"M"},(()=>this.reverseIndex())),this._parser.registerEscHandler({final:"="},(()=>this.keypadApplicationMode())),this._parser.registerEscHandler({final:">"},(()=>this.keypadNumericMode())),this._parser.registerEscHandler({final:"c"},(()=>this.fullReset())),this._parser.registerEscHandler({final:"n"},(()=>this.setgLevel(2))),this._parser.registerEscHandler({final:"o"},(()=>this.setgLevel(3))),this._parser.registerEscHandler({final:"|"},(()=>this.setgLevel(3))),this._parser.registerEscHandler({final:"}"},(()=>this.setgLevel(2))),this._parser.registerEscHandler({final:"~"},(()=>this.setgLevel(1))),this._parser.registerEscHandler({intermediates:"%",final:"@"},(()=>this.selectDefaultCharset())),this._parser.registerEscHandler({intermediates:"%",final:"G"},(()=>this.selectDefaultCharset()));for(const e in o.CHARSETS)this._parser.registerEscHandler({intermediates:"(",final:e},(()=>this.selectCharset("("+e))),this._parser.registerEscHandler({intermediates:")",final:e},(()=>this.selectCharset(")"+e))),this._parser.registerEscHandler({intermediates:"*",final:e},(()=>this.selectCharset("*"+e))),this._parser.registerEscHandler({intermediates:"+",final:e},(()=>this.selectCharset("+"+e))),this._parser.registerEscHandler({intermediates:"-",final:e},(()=>this.selectCharset("-"+e))),this._parser.registerEscHandler({intermediates:".",final:e},(()=>this.selectCharset("."+e))),this._parser.registerEscHandler({intermediates:"/",final:e},(()=>this.selectCharset("/"+e)));this._parser.registerEscHandler({intermediates:"#",final:"8"},(()=>this.screenAlignmentPattern())),this._parser.setErrorHandler((e=>(this._logService.error("Parsing error: ",e),e))),this._parser.registerDcsHandler({intermediates:"$",final:"q"},new m.DcsHandler(((e,t)=>this.requestStatusString(e,t))))}_preserveStack(e,t,i,s){this._parseStack.paused=!0,this._parseStack.cursorStartX=e,this._parseStack.cursorStartY=t,this._parseStack.decodedLength=i,this._parseStack.position=s}_logSlowResolvingAsync(e){this._logService.logLevel<=v.LogLevelEnum.WARN&&Promise.race([e,new Promise(((e,t)=>setTimeout((()=>t("#SLOW_TIMEOUT")),5e3)))]).catch((e=>{if("#SLOW_TIMEOUT"!==e)throw e;console.warn("async parser handler taking longer than 5000 ms")}))}_getCurrentLinkId(){return this._curAttrData.extended.urlId}parse(e,t){let i,s=this._activeBuffer.x,r=this._activeBuffer.y,n=0;const o=this._parseStack.paused;if(o){if(i=this._parser.parse(this._parseBuffer,this._parseStack.decodedLength,t))return this._logSlowResolvingAsync(i),i;s=this._parseStack.cursorStartX,r=this._parseStack.cursorStartY,this._parseStack.paused=!1,e.length>b&&(n=this._parseStack.position+b)}if(this._logService.logLevel<=v.LogLevelEnum.DEBUG&&this._logService.debug("parsing data"+("string"==typeof e?` "${e}"`:` "${Array.prototype.map.call(e,(e=>String.fromCharCode(e))).join("")}"`),"string"==typeof e?e.split("").map((e=>e.charCodeAt(0))):e),this._parseBuffer.lengthb)for(let t=n;t0&&2===f.getWidth(this._activeBuffer.x-1)&&f.setCellFromCodepoint(this._activeBuffer.x-1,0,1,u);let v=this._parser.precedingJoinState;for(let g=t;ga)if(h){const e=f;let t=this._activeBuffer.x-m;for(this._activeBuffer.x=m,this._activeBuffer.y++,this._activeBuffer.y===this._activeBuffer.scrollBottom+1?(this._activeBuffer.y--,this._bufferService.scroll(this._eraseAttrData(),!0)):(this._activeBuffer.y>=this._bufferService.rows&&(this._activeBuffer.y=this._bufferService.rows-1),this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y).isWrapped=!0),f=this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y),m>0&&f instanceof l.BufferLine&&f.copyCellsFrom(e,t,0,m,!1);t=0;)f.setCellFromCodepoint(this._activeBuffer.x++,0,0,u)}else if(d&&(f.insertCells(this._activeBuffer.x,r-m,this._activeBuffer.getNullCell(u)),2===f.getWidth(a-1)&&f.setCellFromCodepoint(a-1,_.NULL_CELL_CODE,_.NULL_CELL_WIDTH,u)),f.setCellFromCodepoint(this._activeBuffer.x++,s,r,u),r>0)for(;--r;)f.setCellFromCodepoint(this._activeBuffer.x++,0,0,u)}this._parser.precedingJoinState=v,this._activeBuffer.x0&&0===f.getWidth(this._activeBuffer.x)&&!f.hasContent(this._activeBuffer.x)&&f.setCellFromCodepoint(this._activeBuffer.x,0,1,u),this._dirtyRowTracker.markDirty(this._activeBuffer.y)}registerCsiHandler(e,t){return"t"!==e.final||e.prefix||e.intermediates?this._parser.registerCsiHandler(e,t):this._parser.registerCsiHandler(e,(e=>!w(e.params[0],this._optionsService.rawOptions.windowOptions)||t(e)))}registerDcsHandler(e,t){return this._parser.registerDcsHandler(e,new m.DcsHandler(t))}registerEscHandler(e,t){return this._parser.registerEscHandler(e,t)}registerOscHandler(e,t){return this._parser.registerOscHandler(e,new g.OscHandler(t))}bell(){return this._onRequestBell.fire(),!0}lineFeed(){return this._dirtyRowTracker.markDirty(this._activeBuffer.y),this._optionsService.rawOptions.convertEol&&(this._activeBuffer.x=0),this._activeBuffer.y++,this._activeBuffer.y===this._activeBuffer.scrollBottom+1?(this._activeBuffer.y--,this._bufferService.scroll(this._eraseAttrData())):this._activeBuffer.y>=this._bufferService.rows?this._activeBuffer.y=this._bufferService.rows-1:this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y).isWrapped=!1,this._activeBuffer.x>=this._bufferService.cols&&this._activeBuffer.x--,this._dirtyRowTracker.markDirty(this._activeBuffer.y),this._onLineFeed.fire(),!0}carriageReturn(){return this._activeBuffer.x=0,!0}backspace(){if(!this._coreService.decPrivateModes.reverseWraparound)return this._restrictCursor(),this._activeBuffer.x>0&&this._activeBuffer.x--,!0;if(this._restrictCursor(this._bufferService.cols),this._activeBuffer.x>0)this._activeBuffer.x--;else if(0===this._activeBuffer.x&&this._activeBuffer.y>this._activeBuffer.scrollTop&&this._activeBuffer.y<=this._activeBuffer.scrollBottom&&this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y)?.isWrapped){this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y).isWrapped=!1,this._activeBuffer.y--,this._activeBuffer.x=this._bufferService.cols-1;const e=this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y);e.hasWidth(this._activeBuffer.x)&&!e.hasContent(this._activeBuffer.x)&&this._activeBuffer.x--}return this._restrictCursor(),!0}tab(){if(this._activeBuffer.x>=this._bufferService.cols)return!0;const e=this._activeBuffer.x;return this._activeBuffer.x=this._activeBuffer.nextStop(),this._optionsService.rawOptions.screenReaderMode&&this._onA11yTab.fire(this._activeBuffer.x-e),!0}shiftOut(){return this._charsetService.setgLevel(1),!0}shiftIn(){return this._charsetService.setgLevel(0),!0}_restrictCursor(e=this._bufferService.cols-1){this._activeBuffer.x=Math.min(e,Math.max(0,this._activeBuffer.x)),this._activeBuffer.y=this._coreService.decPrivateModes.origin?Math.min(this._activeBuffer.scrollBottom,Math.max(this._activeBuffer.scrollTop,this._activeBuffer.y)):Math.min(this._bufferService.rows-1,Math.max(0,this._activeBuffer.y)),this._dirtyRowTracker.markDirty(this._activeBuffer.y)}_setCursor(e,t){this._dirtyRowTracker.markDirty(this._activeBuffer.y),this._coreService.decPrivateModes.origin?(this._activeBuffer.x=e,this._activeBuffer.y=this._activeBuffer.scrollTop+t):(this._activeBuffer.x=e,this._activeBuffer.y=t),this._restrictCursor(),this._dirtyRowTracker.markDirty(this._activeBuffer.y)}_moveCursor(e,t){this._restrictCursor(),this._setCursor(this._activeBuffer.x+e,this._activeBuffer.y+t)}cursorUp(e){const t=this._activeBuffer.y-this._activeBuffer.scrollTop;return t>=0?this._moveCursor(0,-Math.min(t,e.params[0]||1)):this._moveCursor(0,-(e.params[0]||1)),!0}cursorDown(e){const t=this._activeBuffer.scrollBottom-this._activeBuffer.y;return t>=0?this._moveCursor(0,Math.min(t,e.params[0]||1)):this._moveCursor(0,e.params[0]||1),!0}cursorForward(e){return this._moveCursor(e.params[0]||1,0),!0}cursorBackward(e){return this._moveCursor(-(e.params[0]||1),0),!0}cursorNextLine(e){return this.cursorDown(e),this._activeBuffer.x=0,!0}cursorPrecedingLine(e){return this.cursorUp(e),this._activeBuffer.x=0,!0}cursorCharAbsolute(e){return this._setCursor((e.params[0]||1)-1,this._activeBuffer.y),!0}cursorPosition(e){return this._setCursor(e.length>=2?(e.params[1]||1)-1:0,(e.params[0]||1)-1),!0}charPosAbsolute(e){return this._setCursor((e.params[0]||1)-1,this._activeBuffer.y),!0}hPositionRelative(e){return this._moveCursor(e.params[0]||1,0),!0}linePosAbsolute(e){return this._setCursor(this._activeBuffer.x,(e.params[0]||1)-1),!0}vPositionRelative(e){return this._moveCursor(0,e.params[0]||1),!0}hVPosition(e){return this.cursorPosition(e),!0}tabClear(e){const t=e.params[0];return 0===t?delete this._activeBuffer.tabs[this._activeBuffer.x]:3===t&&(this._activeBuffer.tabs={}),!0}cursorForwardTab(e){if(this._activeBuffer.x>=this._bufferService.cols)return!0;let t=e.params[0]||1;for(;t--;)this._activeBuffer.x=this._activeBuffer.nextStop();return!0}cursorBackwardTab(e){if(this._activeBuffer.x>=this._bufferService.cols)return!0;let t=e.params[0]||1;for(;t--;)this._activeBuffer.x=this._activeBuffer.prevStop();return!0}selectProtected(e){const t=e.params[0];return 1===t&&(this._curAttrData.bg|=536870912),2!==t&&0!==t||(this._curAttrData.bg&=-536870913),!0}_eraseInBufferLine(e,t,i,s=!1,r=!1){const n=this._activeBuffer.lines.get(this._activeBuffer.ybase+e);n.replaceCells(t,i,this._activeBuffer.getNullCell(this._eraseAttrData()),r),s&&(n.isWrapped=!1)}_resetBufferLine(e,t=!1){const i=this._activeBuffer.lines.get(this._activeBuffer.ybase+e);i&&(i.fill(this._activeBuffer.getNullCell(this._eraseAttrData()),t),this._bufferService.buffer.clearMarkers(this._activeBuffer.ybase+e),i.isWrapped=!1)}eraseInDisplay(e,t=!1){let i;switch(this._restrictCursor(this._bufferService.cols),e.params[0]){case 0:for(i=this._activeBuffer.y,this._dirtyRowTracker.markDirty(i),this._eraseInBufferLine(i++,this._activeBuffer.x,this._bufferService.cols,0===this._activeBuffer.x,t);i=this._bufferService.cols&&(this._activeBuffer.lines.get(i+1).isWrapped=!1);i--;)this._resetBufferLine(i,t);this._dirtyRowTracker.markDirty(0);break;case 2:for(i=this._bufferService.rows,this._dirtyRowTracker.markDirty(i-1);i--;)this._resetBufferLine(i,t);this._dirtyRowTracker.markDirty(0);break;case 3:const e=this._activeBuffer.lines.length-this._bufferService.rows;e>0&&(this._activeBuffer.lines.trimStart(e),this._activeBuffer.ybase=Math.max(this._activeBuffer.ybase-e,0),this._activeBuffer.ydisp=Math.max(this._activeBuffer.ydisp-e,0),this._onScroll.fire(0))}return!0}eraseInLine(e,t=!1){switch(this._restrictCursor(this._bufferService.cols),e.params[0]){case 0:this._eraseInBufferLine(this._activeBuffer.y,this._activeBuffer.x,this._bufferService.cols,0===this._activeBuffer.x,t);break;case 1:this._eraseInBufferLine(this._activeBuffer.y,0,this._activeBuffer.x+1,!1,t);break;case 2:this._eraseInBufferLine(this._activeBuffer.y,0,this._bufferService.cols,!0,t)}return this._dirtyRowTracker.markDirty(this._activeBuffer.y),!0}insertLines(e){this._restrictCursor();let t=e.params[0]||1;if(this._activeBuffer.y>this._activeBuffer.scrollBottom||this._activeBuffer.ythis._activeBuffer.scrollBottom||this._activeBuffer.ythis._activeBuffer.scrollBottom||this._activeBuffer.ythis._activeBuffer.scrollBottom||this._activeBuffer.ythis._activeBuffer.scrollBottom||this._activeBuffer.ythis._activeBuffer.scrollBottom||this._activeBuffer.y65535?2:1}let h=a;for(let e=1;e0||(this._is("xterm")||this._is("rxvt-unicode")||this._is("screen")?this._coreService.triggerDataEvent(n.C0.ESC+"[?1;2c"):this._is("linux")&&this._coreService.triggerDataEvent(n.C0.ESC+"[?6c")),!0}sendDeviceAttributesSecondary(e){return e.params[0]>0||(this._is("xterm")?this._coreService.triggerDataEvent(n.C0.ESC+"[>0;276;0c"):this._is("rxvt-unicode")?this._coreService.triggerDataEvent(n.C0.ESC+"[>85;95;0c"):this._is("linux")?this._coreService.triggerDataEvent(e.params[0]+"c"):this._is("screen")&&this._coreService.triggerDataEvent(n.C0.ESC+"[>83;40003;0c")),!0}_is(e){return 0===(this._optionsService.rawOptions.termName+"").indexOf(e)}setMode(e){for(let t=0;te?1:2,u=e.params[0];return f=u,v=t?2===u?4:4===u?_(o.modes.insertMode):12===u?3:20===u?_(d.convertEol):0:1===u?_(i.applicationCursorKeys):3===u?d.windowOptions.setWinLines?80===h?2:132===h?1:0:0:6===u?_(i.origin):7===u?_(i.wraparound):8===u?3:9===u?_("X10"===s):12===u?_(d.cursorBlink):25===u?_(!o.isCursorHidden):45===u?_(i.reverseWraparound):66===u?_(i.applicationKeypad):67===u?4:1e3===u?_("VT200"===s):1002===u?_("DRAG"===s):1003===u?_("ANY"===s):1004===u?_(i.sendFocus):1005===u?4:1006===u?_("SGR"===r):1015===u?4:1016===u?_("SGR_PIXELS"===r):1048===u?1:47===u||1047===u||1049===u?_(c===l):2004===u?_(i.bracketedPasteMode):0,o.triggerDataEvent(`${n.C0.ESC}[${t?"":"?"}${f};${v}$y`),!0;var f,v}_updateAttrColor(e,t,i,s,r){return 2===t?(e|=50331648,e&=-16777216,e|=f.AttributeData.fromColorRGB([i,s,r])):5===t&&(e&=-50331904,e|=33554432|255&i),e}_extractColor(e,t,i){const s=[0,0,-1,0,0,0];let r=0,n=0;do{if(s[n+r]=e.params[t+n],e.hasSubParams(t+n)){const i=e.getSubParams(t+n);let o=0;do{5===s[1]&&(r=1),s[n+o+1+r]=i[o]}while(++o=2||2===s[1]&&n+r>=5)break;s[1]&&(r=1)}while(++n+t5)&&(e=1),t.extended.underlineStyle=e,t.fg|=268435456,0===e&&(t.fg&=-268435457),t.updateExtended()}_processSGR0(e){e.fg=l.DEFAULT_ATTR_DATA.fg,e.bg=l.DEFAULT_ATTR_DATA.bg,e.extended=e.extended.clone(),e.extended.underlineStyle=0,e.extended.underlineColor&=-67108864,e.updateExtended()}charAttributes(e){if(1===e.length&&0===e.params[0])return this._processSGR0(this._curAttrData),!0;const t=e.length;let i;const s=this._curAttrData;for(let r=0;r=30&&i<=37?(s.fg&=-50331904,s.fg|=16777216|i-30):i>=40&&i<=47?(s.bg&=-50331904,s.bg|=16777216|i-40):i>=90&&i<=97?(s.fg&=-50331904,s.fg|=16777224|i-90):i>=100&&i<=107?(s.bg&=-50331904,s.bg|=16777224|i-100):0===i?this._processSGR0(s):1===i?s.fg|=134217728:3===i?s.bg|=67108864:4===i?(s.fg|=268435456,this._processUnderline(e.hasSubParams(r)?e.getSubParams(r)[0]:1,s)):5===i?s.fg|=536870912:7===i?s.fg|=67108864:8===i?s.fg|=1073741824:9===i?s.fg|=2147483648:2===i?s.bg|=134217728:21===i?this._processUnderline(2,s):22===i?(s.fg&=-134217729,s.bg&=-134217729):23===i?s.bg&=-67108865:24===i?(s.fg&=-268435457,this._processUnderline(0,s)):25===i?s.fg&=-536870913:27===i?s.fg&=-67108865:28===i?s.fg&=-1073741825:29===i?s.fg&=2147483647:39===i?(s.fg&=-67108864,s.fg|=16777215&l.DEFAULT_ATTR_DATA.fg):49===i?(s.bg&=-67108864,s.bg|=16777215&l.DEFAULT_ATTR_DATA.bg):38===i||48===i||58===i?r+=this._extractColor(e,r,s):53===i?s.bg|=1073741824:55===i?s.bg&=-1073741825:59===i?(s.extended=s.extended.clone(),s.extended.underlineColor=-1,s.updateExtended()):100===i?(s.fg&=-67108864,s.fg|=16777215&l.DEFAULT_ATTR_DATA.fg,s.bg&=-67108864,s.bg|=16777215&l.DEFAULT_ATTR_DATA.bg):this._logService.debug("Unknown SGR attribute: %d.",i);return!0}deviceStatus(e){switch(e.params[0]){case 5:this._coreService.triggerDataEvent(`${n.C0.ESC}[0n`);break;case 6:const e=this._activeBuffer.y+1,t=this._activeBuffer.x+1;this._coreService.triggerDataEvent(`${n.C0.ESC}[${e};${t}R`)}return!0}deviceStatusPrivate(e){if(6===e.params[0]){const e=this._activeBuffer.y+1,t=this._activeBuffer.x+1;this._coreService.triggerDataEvent(`${n.C0.ESC}[?${e};${t}R`)}return!0}softReset(e){return this._coreService.isCursorHidden=!1,this._onRequestSyncScrollBar.fire(),this._activeBuffer.scrollTop=0,this._activeBuffer.scrollBottom=this._bufferService.rows-1,this._curAttrData=l.DEFAULT_ATTR_DATA.clone(),this._coreService.reset(),this._charsetService.reset(),this._activeBuffer.savedX=0,this._activeBuffer.savedY=this._activeBuffer.ybase,this._activeBuffer.savedCurAttrData.fg=this._curAttrData.fg,this._activeBuffer.savedCurAttrData.bg=this._curAttrData.bg,this._activeBuffer.savedCharset=this._charsetService.charset,this._coreService.decPrivateModes.origin=!1,!0}setCursorStyle(e){const t=e.params[0]||1;switch(t){case 1:case 2:this._optionsService.options.cursorStyle="block";break;case 3:case 4:this._optionsService.options.cursorStyle="underline";break;case 5:case 6:this._optionsService.options.cursorStyle="bar"}const i=t%2==1;return this._optionsService.options.cursorBlink=i,!0}setScrollRegion(e){const t=e.params[0]||1;let i;return(e.length<2||(i=e.params[1])>this._bufferService.rows||0===i)&&(i=this._bufferService.rows),i>t&&(this._activeBuffer.scrollTop=t-1,this._activeBuffer.scrollBottom=i-1,this._setCursor(0,0)),!0}windowOptions(e){if(!w(e.params[0],this._optionsService.rawOptions.windowOptions))return!0;const t=e.length>1?e.params[1]:0;switch(e.params[0]){case 14:2!==t&&this._onRequestWindowsOptionsReport.fire(y.GET_WIN_SIZE_PIXELS);break;case 16:this._onRequestWindowsOptionsReport.fire(y.GET_CELL_SIZE_PIXELS);break;case 18:this._bufferService&&this._coreService.triggerDataEvent(`${n.C0.ESC}[8;${this._bufferService.rows};${this._bufferService.cols}t`);break;case 22:0!==t&&2!==t||(this._windowTitleStack.push(this._windowTitle),this._windowTitleStack.length>10&&this._windowTitleStack.shift()),0!==t&&1!==t||(this._iconNameStack.push(this._iconName),this._iconNameStack.length>10&&this._iconNameStack.shift());break;case 23:0!==t&&2!==t||this._windowTitleStack.length&&this.setTitle(this._windowTitleStack.pop()),0!==t&&1!==t||this._iconNameStack.length&&this.setIconName(this._iconNameStack.pop())}return!0}saveCursor(e){return this._activeBuffer.savedX=this._activeBuffer.x,this._activeBuffer.savedY=this._activeBuffer.ybase+this._activeBuffer.y,this._activeBuffer.savedCurAttrData.fg=this._curAttrData.fg,this._activeBuffer.savedCurAttrData.bg=this._curAttrData.bg,this._activeBuffer.savedCharset=this._charsetService.charset,!0}restoreCursor(e){return this._activeBuffer.x=this._activeBuffer.savedX||0,this._activeBuffer.y=Math.max(this._activeBuffer.savedY-this._activeBuffer.ybase,0),this._curAttrData.fg=this._activeBuffer.savedCurAttrData.fg,this._curAttrData.bg=this._activeBuffer.savedCurAttrData.bg,this._charsetService.charset=this._savedCharset,this._activeBuffer.savedCharset&&(this._charsetService.charset=this._activeBuffer.savedCharset),this._restrictCursor(),!0}setTitle(e){return this._windowTitle=e,this._onTitleChange.fire(e),!0}setIconName(e){return this._iconName=e,!0}setOrReportIndexedColor(e){const t=[],i=e.split(";");for(;i.length>1;){const e=i.shift(),s=i.shift();if(/^\d+$/.exec(e)){const i=parseInt(e);if(D(i))if("?"===s)t.push({type:0,index:i});else{const e=(0,S.parseColor)(s);e&&t.push({type:1,index:i,color:e})}}}return t.length&&this._onColor.fire(t),!0}setHyperlink(e){const t=e.split(";");return!(t.length<2)&&(t[1]?this._createHyperlink(t[0],t[1]):!t[0]&&this._finishHyperlink())}_createHyperlink(e,t){this._getCurrentLinkId()&&this._finishHyperlink();const i=e.split(":");let s;const r=i.findIndex((e=>e.startsWith("id=")));return-1!==r&&(s=i[r].slice(3)||void 0),this._curAttrData.extended=this._curAttrData.extended.clone(),this._curAttrData.extended.urlId=this._oscLinkService.registerLink({id:s,uri:t}),this._curAttrData.updateExtended(),!0}_finishHyperlink(){return this._curAttrData.extended=this._curAttrData.extended.clone(),this._curAttrData.extended.urlId=0,this._curAttrData.updateExtended(),!0}_setOrReportSpecialColor(e,t){const i=e.split(";");for(let e=0;e=this._specialColors.length);++e,++t)if("?"===i[e])this._onColor.fire([{type:0,index:this._specialColors[t]}]);else{const s=(0,S.parseColor)(i[e]);s&&this._onColor.fire([{type:1,index:this._specialColors[t],color:s}])}return!0}setOrReportFgColor(e){return this._setOrReportSpecialColor(e,0)}setOrReportBgColor(e){return this._setOrReportSpecialColor(e,1)}setOrReportCursorColor(e){return this._setOrReportSpecialColor(e,2)}restoreIndexedColor(e){if(!e)return this._onColor.fire([{type:2}]),!0;const t=[],i=e.split(";");for(let e=0;e=this._bufferService.rows&&(this._activeBuffer.y=this._bufferService.rows-1),this._restrictCursor(),!0}tabSet(){return this._activeBuffer.tabs[this._activeBuffer.x]=!0,!0}reverseIndex(){if(this._restrictCursor(),this._activeBuffer.y===this._activeBuffer.scrollTop){const e=this._activeBuffer.scrollBottom-this._activeBuffer.scrollTop;this._activeBuffer.lines.shiftElements(this._activeBuffer.ybase+this._activeBuffer.y,e,1),this._activeBuffer.lines.set(this._activeBuffer.ybase+this._activeBuffer.y,this._activeBuffer.getBlankLine(this._eraseAttrData())),this._dirtyRowTracker.markRangeDirty(this._activeBuffer.scrollTop,this._activeBuffer.scrollBottom)}else this._activeBuffer.y--,this._restrictCursor();return!0}fullReset(){return this._parser.reset(),this._onRequestReset.fire(),!0}reset(){this._curAttrData=l.DEFAULT_ATTR_DATA.clone(),this._eraseAttrDataInternal=l.DEFAULT_ATTR_DATA.clone()}_eraseAttrData(){return this._eraseAttrDataInternal.bg&=-67108864,this._eraseAttrDataInternal.bg|=67108863&this._curAttrData.bg,this._eraseAttrDataInternal}setgLevel(e){return this._charsetService.setgLevel(e),!0}screenAlignmentPattern(){const e=new u.CellData;e.content=1<<22|"E".charCodeAt(0),e.fg=this._curAttrData.fg,e.bg=this._curAttrData.bg,this._setCursor(0,0);for(let t=0;t(this._coreService.triggerDataEvent(`${n.C0.ESC}${e}${n.C0.ESC}\\`),!0))('"q'===e?`P1$r${this._curAttrData.isProtected()?1:0}"q`:'"p'===e?'P1$r61;1"p':"r"===e?`P1$r${i.scrollTop+1};${i.scrollBottom+1}r`:"m"===e?"P1$r0m":" q"===e?`P1$r${{block:2,underline:4,bar:6}[s.cursorStyle]-(s.cursorBlink?1:0)} q`:"P0$r")}markRangeDirty(e,t){this._dirtyRowTracker.markRangeDirty(e,t)}}t.InputHandler=k;let L=class{constructor(e){this._bufferService=e,this.clearRange()}clearRange(){this.start=this._bufferService.buffer.y,this.end=this._bufferService.buffer.y}markDirty(e){ethis.end&&(this.end=e)}markRangeDirty(e,t){e>t&&(E=e,e=t,t=E),ethis.end&&(this.end=t)}markAllDirty(){this.markRangeDirty(0,this._bufferService.rows-1)}};function D(e){return 0<=e&&e<256}L=s([r(0,v.IBufferService)],L)},844:(e,t)=>{function i(e){for(const t of e)t.dispose();e.length=0}Object.defineProperty(t,"__esModule",{value:!0}),t.getDisposeArrayDisposable=t.disposeArray=t.toDisposable=t.MutableDisposable=t.Disposable=void 0,t.Disposable=class{constructor(){this._disposables=[],this._isDisposed=!1}dispose(){this._isDisposed=!0;for(const e of this._disposables)e.dispose();this._disposables.length=0}register(e){return this._disposables.push(e),e}unregister(e){const t=this._disposables.indexOf(e);-1!==t&&this._disposables.splice(t,1)}},t.MutableDisposable=class{constructor(){this._isDisposed=!1}get value(){return this._isDisposed?void 0:this._value}set value(e){this._isDisposed||e===this._value||(this._value?.dispose(),this._value=e)}clear(){this.value=void 0}dispose(){this._isDisposed=!0,this._value?.dispose(),this._value=void 0}},t.toDisposable=function(e){return{dispose:e}},t.disposeArray=i,t.getDisposeArrayDisposable=function(e){return{dispose:()=>i(e)}}},1505:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.FourKeyMap=t.TwoKeyMap=void 0;class i{constructor(){this._data={}}set(e,t,i){this._data[e]||(this._data[e]={}),this._data[e][t]=i}get(e,t){return this._data[e]?this._data[e][t]:void 0}clear(){this._data={}}}t.TwoKeyMap=i,t.FourKeyMap=class{constructor(){this._data=new i}set(e,t,s,r,n){this._data.get(e,t)||this._data.set(e,t,new i),this._data.get(e,t).set(s,r,n)}get(e,t,i,s){return this._data.get(e,t)?.get(i,s)}clear(){this._data.clear()}}},6114:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.isChromeOS=t.isLinux=t.isWindows=t.isIphone=t.isIpad=t.isMac=t.getSafariVersion=t.isSafari=t.isLegacyEdge=t.isFirefox=t.isNode=void 0,t.isNode="undefined"!=typeof process&&"title"in process;const i=t.isNode?"node":navigator.userAgent,s=t.isNode?"node":navigator.platform;t.isFirefox=i.includes("Firefox"),t.isLegacyEdge=i.includes("Edge"),t.isSafari=/^((?!chrome|android).)*safari/i.test(i),t.getSafariVersion=function(){if(!t.isSafari)return 0;const e=i.match(/Version\/(\d+)/);return null===e||e.length<2?0:parseInt(e[1])},t.isMac=["Macintosh","MacIntel","MacPPC","Mac68K"].includes(s),t.isIpad="iPad"===s,t.isIphone="iPhone"===s,t.isWindows=["Windows","Win16","Win32","WinCE"].includes(s),t.isLinux=s.indexOf("Linux")>=0,t.isChromeOS=/\bCrOS\b/.test(i)},6106:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SortedList=void 0;let i=0;t.SortedList=class{constructor(e){this._getKey=e,this._array=[]}clear(){this._array.length=0}insert(e){0!==this._array.length?(i=this._search(this._getKey(e)),this._array.splice(i,0,e)):this._array.push(e)}delete(e){if(0===this._array.length)return!1;const t=this._getKey(e);if(void 0===t)return!1;if(i=this._search(t),-1===i)return!1;if(this._getKey(this._array[i])!==t)return!1;do{if(this._array[i]===e)return this._array.splice(i,1),!0}while(++i=this._array.length)&&this._getKey(this._array[i])===e))do{yield this._array[i]}while(++i=this._array.length)&&this._getKey(this._array[i])===e))do{t(this._array[i])}while(++i=t;){let s=t+i>>1;const r=this._getKey(this._array[s]);if(r>e)i=s-1;else{if(!(r0&&this._getKey(this._array[s-1])===e;)s--;return s}t=s+1}}return t}}},7226:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.DebouncedIdleTask=t.IdleTaskQueue=t.PriorityTaskQueue=void 0;const s=i(6114);class r{constructor(){this._tasks=[],this._i=0}enqueue(e){this._tasks.push(e),this._start()}flush(){for(;this._ir)return s-t<-20&&console.warn(`task queue exceeded allotted deadline by ${Math.abs(Math.round(s-t))}ms`),void this._start();s=r}this.clear()}}class n extends r{_requestCallback(e){return setTimeout((()=>e(this._createDeadline(16))))}_cancelCallback(e){clearTimeout(e)}_createDeadline(e){const t=Date.now()+e;return{timeRemaining:()=>Math.max(0,t-Date.now())}}}t.PriorityTaskQueue=n,t.IdleTaskQueue=!s.isNode&&"requestIdleCallback"in window?class extends r{_requestCallback(e){return requestIdleCallback(e)}_cancelCallback(e){cancelIdleCallback(e)}}:n,t.DebouncedIdleTask=class{constructor(){this._queue=new t.IdleTaskQueue}set(e){this._queue.clear(),this._queue.enqueue(e)}flush(){this._queue.flush()}}},9282:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.updateWindowsModeWrappedState=void 0;const s=i(643);t.updateWindowsModeWrappedState=function(e){const t=e.buffer.lines.get(e.buffer.ybase+e.buffer.y-1),i=t?.get(e.cols-1),r=e.buffer.lines.get(e.buffer.ybase+e.buffer.y);r&&i&&(r.isWrapped=i[s.CHAR_DATA_CODE_INDEX]!==s.NULL_CELL_CODE&&i[s.CHAR_DATA_CODE_INDEX]!==s.WHITESPACE_CELL_CODE)}},3734:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ExtendedAttrs=t.AttributeData=void 0;class i{constructor(){this.fg=0,this.bg=0,this.extended=new s}static toColorRGB(e){return[e>>>16&255,e>>>8&255,255&e]}static fromColorRGB(e){return(255&e[0])<<16|(255&e[1])<<8|255&e[2]}clone(){const e=new i;return e.fg=this.fg,e.bg=this.bg,e.extended=this.extended.clone(),e}isInverse(){return 67108864&this.fg}isBold(){return 134217728&this.fg}isUnderline(){return this.hasExtendedAttrs()&&0!==this.extended.underlineStyle?1:268435456&this.fg}isBlink(){return 536870912&this.fg}isInvisible(){return 1073741824&this.fg}isItalic(){return 67108864&this.bg}isDim(){return 134217728&this.bg}isStrikethrough(){return 2147483648&this.fg}isProtected(){return 536870912&this.bg}isOverline(){return 1073741824&this.bg}getFgColorMode(){return 50331648&this.fg}getBgColorMode(){return 50331648&this.bg}isFgRGB(){return 50331648==(50331648&this.fg)}isBgRGB(){return 50331648==(50331648&this.bg)}isFgPalette(){return 16777216==(50331648&this.fg)||33554432==(50331648&this.fg)}isBgPalette(){return 16777216==(50331648&this.bg)||33554432==(50331648&this.bg)}isFgDefault(){return 0==(50331648&this.fg)}isBgDefault(){return 0==(50331648&this.bg)}isAttributeDefault(){return 0===this.fg&&0===this.bg}getFgColor(){switch(50331648&this.fg){case 16777216:case 33554432:return 255&this.fg;case 50331648:return 16777215&this.fg;default:return-1}}getBgColor(){switch(50331648&this.bg){case 16777216:case 33554432:return 255&this.bg;case 50331648:return 16777215&this.bg;default:return-1}}hasExtendedAttrs(){return 268435456&this.bg}updateExtended(){this.extended.isEmpty()?this.bg&=-268435457:this.bg|=268435456}getUnderlineColor(){if(268435456&this.bg&&~this.extended.underlineColor)switch(50331648&this.extended.underlineColor){case 16777216:case 33554432:return 255&this.extended.underlineColor;case 50331648:return 16777215&this.extended.underlineColor;default:return this.getFgColor()}return this.getFgColor()}getUnderlineColorMode(){return 268435456&this.bg&&~this.extended.underlineColor?50331648&this.extended.underlineColor:this.getFgColorMode()}isUnderlineColorRGB(){return 268435456&this.bg&&~this.extended.underlineColor?50331648==(50331648&this.extended.underlineColor):this.isFgRGB()}isUnderlineColorPalette(){return 268435456&this.bg&&~this.extended.underlineColor?16777216==(50331648&this.extended.underlineColor)||33554432==(50331648&this.extended.underlineColor):this.isFgPalette()}isUnderlineColorDefault(){return 268435456&this.bg&&~this.extended.underlineColor?0==(50331648&this.extended.underlineColor):this.isFgDefault()}getUnderlineStyle(){return 268435456&this.fg?268435456&this.bg?this.extended.underlineStyle:1:0}getUnderlineVariantOffset(){return this.extended.underlineVariantOffset}}t.AttributeData=i;class s{get ext(){return this._urlId?-469762049&this._ext|this.underlineStyle<<26:this._ext}set ext(e){this._ext=e}get underlineStyle(){return this._urlId?5:(469762048&this._ext)>>26}set underlineStyle(e){this._ext&=-469762049,this._ext|=e<<26&469762048}get underlineColor(){return 67108863&this._ext}set underlineColor(e){this._ext&=-67108864,this._ext|=67108863&e}get urlId(){return this._urlId}set urlId(e){this._urlId=e}get underlineVariantOffset(){const e=(3758096384&this._ext)>>29;return e<0?4294967288^e:e}set underlineVariantOffset(e){this._ext&=536870911,this._ext|=e<<29&3758096384}constructor(e=0,t=0){this._ext=0,this._urlId=0,this._ext=e,this._urlId=t}clone(){return new s(this._ext,this._urlId)}isEmpty(){return 0===this.underlineStyle&&0===this._urlId}}t.ExtendedAttrs=s},9092:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Buffer=t.MAX_BUFFER_SIZE=void 0;const s=i(6349),r=i(7226),n=i(3734),o=i(8437),a=i(4634),h=i(511),c=i(643),l=i(4863),d=i(7116);t.MAX_BUFFER_SIZE=4294967295,t.Buffer=class{constructor(e,t,i){this._hasScrollback=e,this._optionsService=t,this._bufferService=i,this.ydisp=0,this.ybase=0,this.y=0,this.x=0,this.tabs={},this.savedY=0,this.savedX=0,this.savedCurAttrData=o.DEFAULT_ATTR_DATA.clone(),this.savedCharset=d.DEFAULT_CHARSET,this.markers=[],this._nullCell=h.CellData.fromCharData([0,c.NULL_CELL_CHAR,c.NULL_CELL_WIDTH,c.NULL_CELL_CODE]),this._whitespaceCell=h.CellData.fromCharData([0,c.WHITESPACE_CELL_CHAR,c.WHITESPACE_CELL_WIDTH,c.WHITESPACE_CELL_CODE]),this._isClearing=!1,this._memoryCleanupQueue=new r.IdleTaskQueue,this._memoryCleanupPosition=0,this._cols=this._bufferService.cols,this._rows=this._bufferService.rows,this.lines=new s.CircularList(this._getCorrectBufferLength(this._rows)),this.scrollTop=0,this.scrollBottom=this._rows-1,this.setupTabStops()}getNullCell(e){return e?(this._nullCell.fg=e.fg,this._nullCell.bg=e.bg,this._nullCell.extended=e.extended):(this._nullCell.fg=0,this._nullCell.bg=0,this._nullCell.extended=new n.ExtendedAttrs),this._nullCell}getWhitespaceCell(e){return e?(this._whitespaceCell.fg=e.fg,this._whitespaceCell.bg=e.bg,this._whitespaceCell.extended=e.extended):(this._whitespaceCell.fg=0,this._whitespaceCell.bg=0,this._whitespaceCell.extended=new n.ExtendedAttrs),this._whitespaceCell}getBlankLine(e,t){return new o.BufferLine(this._bufferService.cols,this.getNullCell(e),t)}get hasScrollback(){return this._hasScrollback&&this.lines.maxLength>this._rows}get isCursorInViewport(){const e=this.ybase+this.y-this.ydisp;return e>=0&&et.MAX_BUFFER_SIZE?t.MAX_BUFFER_SIZE:i}fillViewportRows(e){if(0===this.lines.length){void 0===e&&(e=o.DEFAULT_ATTR_DATA);let t=this._rows;for(;t--;)this.lines.push(this.getBlankLine(e))}}clear(){this.ydisp=0,this.ybase=0,this.y=0,this.x=0,this.lines=new s.CircularList(this._getCorrectBufferLength(this._rows)),this.scrollTop=0,this.scrollBottom=this._rows-1,this.setupTabStops()}resize(e,t){const i=this.getNullCell(o.DEFAULT_ATTR_DATA);let s=0;const r=this._getCorrectBufferLength(t);if(r>this.lines.maxLength&&(this.lines.maxLength=r),this.lines.length>0){if(this._cols0&&this.lines.length<=this.ybase+this.y+n+1?(this.ybase--,n++,this.ydisp>0&&this.ydisp--):this.lines.push(new o.BufferLine(e,i)));else for(let e=this._rows;e>t;e--)this.lines.length>t+this.ybase&&(this.lines.length>this.ybase+this.y+1?this.lines.pop():(this.ybase++,this.ydisp++));if(r0&&(this.lines.trimStart(e),this.ybase=Math.max(this.ybase-e,0),this.ydisp=Math.max(this.ydisp-e,0),this.savedY=Math.max(this.savedY-e,0)),this.lines.maxLength=r}this.x=Math.min(this.x,e-1),this.y=Math.min(this.y,t-1),n&&(this.y+=n),this.savedX=Math.min(this.savedX,e-1),this.scrollTop=0}if(this.scrollBottom=t-1,this._isReflowEnabled&&(this._reflow(e,t),this._cols>e))for(let t=0;t.1*this.lines.length&&(this._memoryCleanupPosition=0,this._memoryCleanupQueue.enqueue((()=>this._batchedMemoryCleanup())))}_batchedMemoryCleanup(){let e=!0;this._memoryCleanupPosition>=this.lines.length&&(this._memoryCleanupPosition=0,e=!1);let t=0;for(;this._memoryCleanupPosition100)return!0;return e}get _isReflowEnabled(){const e=this._optionsService.rawOptions.windowsPty;return e&&e.buildNumber?this._hasScrollback&&"conpty"===e.backend&&e.buildNumber>=21376:this._hasScrollback&&!this._optionsService.rawOptions.windowsMode}_reflow(e,t){this._cols!==e&&(e>this._cols?this._reflowLarger(e,t):this._reflowSmaller(e,t))}_reflowLarger(e,t){const i=(0,a.reflowLargerGetLinesToRemove)(this.lines,this._cols,e,this.ybase+this.y,this.getNullCell(o.DEFAULT_ATTR_DATA));if(i.length>0){const s=(0,a.reflowLargerCreateNewLayout)(this.lines,i);(0,a.reflowLargerApplyNewLayout)(this.lines,s.layout),this._reflowLargerAdjustViewport(e,t,s.countRemoved)}}_reflowLargerAdjustViewport(e,t,i){const s=this.getNullCell(o.DEFAULT_ATTR_DATA);let r=i;for(;r-- >0;)0===this.ybase?(this.y>0&&this.y--,this.lines.length=0;n--){let h=this.lines.get(n);if(!h||!h.isWrapped&&h.getTrimmedLength()<=e)continue;const c=[h];for(;h.isWrapped&&n>0;)h=this.lines.get(--n),c.unshift(h);const l=this.ybase+this.y;if(l>=n&&l0&&(s.push({start:n+c.length+r,newLines:v}),r+=v.length),c.push(...v);let p=_.length-1,g=_[p];0===g&&(p--,g=_[p]);let m=c.length-u-1,S=d;for(;m>=0;){const e=Math.min(S,g);if(void 0===c[p])break;if(c[p].copyCellsFrom(c[m],S-e,g-e,e,!0),g-=e,0===g&&(p--,g=_[p]),S-=e,0===S){m--;const e=Math.max(m,0);S=(0,a.getWrappedLineTrimmedLength)(c,e,this._cols)}}for(let t=0;t0;)0===this.ybase?this.y0){const e=[],t=[];for(let e=0;e=0;c--)if(a&&a.start>n+h){for(let e=a.newLines.length-1;e>=0;e--)this.lines.set(c--,a.newLines[e]);c++,e.push({index:n+1,amount:a.newLines.length}),h+=a.newLines.length,a=s[++o]}else this.lines.set(c,t[n--]);let c=0;for(let t=e.length-1;t>=0;t--)e[t].index+=c,this.lines.onInsertEmitter.fire(e[t]),c+=e[t].amount;const l=Math.max(0,i+r-this.lines.maxLength);l>0&&this.lines.onTrimEmitter.fire(l)}}translateBufferLineToString(e,t,i=0,s){const r=this.lines.get(e);return r?r.translateToString(t,i,s):""}getWrappedRangeForLine(e){let t=e,i=e;for(;t>0&&this.lines.get(t).isWrapped;)t--;for(;i+10;);return e>=this._cols?this._cols-1:e<0?0:e}nextStop(e){for(null==e&&(e=this.x);!this.tabs[++e]&&e=this._cols?this._cols-1:e<0?0:e}clearMarkers(e){this._isClearing=!0;for(let t=0;t{t.line-=e,t.line<0&&t.dispose()}))),t.register(this.lines.onInsert((e=>{t.line>=e.index&&(t.line+=e.amount)}))),t.register(this.lines.onDelete((e=>{t.line>=e.index&&t.linee.index&&(t.line-=e.amount)}))),t.register(t.onDispose((()=>this._removeMarker(t)))),t}_removeMarker(e){this._isClearing||this.markers.splice(this.markers.indexOf(e),1)}}},8437:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.BufferLine=t.DEFAULT_ATTR_DATA=void 0;const s=i(3734),r=i(511),n=i(643),o=i(482);t.DEFAULT_ATTR_DATA=Object.freeze(new s.AttributeData);let a=0;class h{constructor(e,t,i=!1){this.isWrapped=i,this._combined={},this._extendedAttrs={},this._data=new Uint32Array(3*e);const s=t||r.CellData.fromCharData([0,n.NULL_CELL_CHAR,n.NULL_CELL_WIDTH,n.NULL_CELL_CODE]);for(let t=0;t>22,2097152&t?this._combined[e].charCodeAt(this._combined[e].length-1):i]}set(e,t){this._data[3*e+1]=t[n.CHAR_DATA_ATTR_INDEX],t[n.CHAR_DATA_CHAR_INDEX].length>1?(this._combined[e]=t[1],this._data[3*e+0]=2097152|e|t[n.CHAR_DATA_WIDTH_INDEX]<<22):this._data[3*e+0]=t[n.CHAR_DATA_CHAR_INDEX].charCodeAt(0)|t[n.CHAR_DATA_WIDTH_INDEX]<<22}getWidth(e){return this._data[3*e+0]>>22}hasWidth(e){return 12582912&this._data[3*e+0]}getFg(e){return this._data[3*e+1]}getBg(e){return this._data[3*e+2]}hasContent(e){return 4194303&this._data[3*e+0]}getCodePoint(e){const t=this._data[3*e+0];return 2097152&t?this._combined[e].charCodeAt(this._combined[e].length-1):2097151&t}isCombined(e){return 2097152&this._data[3*e+0]}getString(e){const t=this._data[3*e+0];return 2097152&t?this._combined[e]:2097151&t?(0,o.stringFromCodePoint)(2097151&t):""}isProtected(e){return 536870912&this._data[3*e+2]}loadCell(e,t){return a=3*e,t.content=this._data[a+0],t.fg=this._data[a+1],t.bg=this._data[a+2],2097152&t.content&&(t.combinedData=this._combined[e]),268435456&t.bg&&(t.extended=this._extendedAttrs[e]),t}setCell(e,t){2097152&t.content&&(this._combined[e]=t.combinedData),268435456&t.bg&&(this._extendedAttrs[e]=t.extended),this._data[3*e+0]=t.content,this._data[3*e+1]=t.fg,this._data[3*e+2]=t.bg}setCellFromCodepoint(e,t,i,s){268435456&s.bg&&(this._extendedAttrs[e]=s.extended),this._data[3*e+0]=t|i<<22,this._data[3*e+1]=s.fg,this._data[3*e+2]=s.bg}addCodepointToCell(e,t,i){let s=this._data[3*e+0];2097152&s?this._combined[e]+=(0,o.stringFromCodePoint)(t):2097151&s?(this._combined[e]=(0,o.stringFromCodePoint)(2097151&s)+(0,o.stringFromCodePoint)(t),s&=-2097152,s|=2097152):s=t|1<<22,i&&(s&=-12582913,s|=i<<22),this._data[3*e+0]=s}insertCells(e,t,i){if((e%=this.length)&&2===this.getWidth(e-1)&&this.setCellFromCodepoint(e-1,0,1,i),t=0;--i)this.setCell(e+t+i,this.loadCell(e+i,s));for(let s=0;sthis.length){if(this._data.buffer.byteLength>=4*i)this._data=new Uint32Array(this._data.buffer,0,i);else{const e=new Uint32Array(i);e.set(this._data),this._data=e}for(let i=this.length;i=e&&delete this._combined[s]}const s=Object.keys(this._extendedAttrs);for(let t=0;t=e&&delete this._extendedAttrs[i]}}return this.length=e,4*i*2=0;--e)if(4194303&this._data[3*e+0])return e+(this._data[3*e+0]>>22);return 0}getNoBgTrimmedLength(){for(let e=this.length-1;e>=0;--e)if(4194303&this._data[3*e+0]||50331648&this._data[3*e+2])return e+(this._data[3*e+0]>>22);return 0}copyCellsFrom(e,t,i,s,r){const n=e._data;if(r)for(let r=s-1;r>=0;r--){for(let e=0;e<3;e++)this._data[3*(i+r)+e]=n[3*(t+r)+e];268435456&n[3*(t+r)+2]&&(this._extendedAttrs[i+r]=e._extendedAttrs[t+r])}else for(let r=0;r=t&&(this._combined[r-t+i]=e._combined[r])}}translateToString(e,t,i,s){t=t??0,i=i??this.length,e&&(i=Math.min(i,this.getTrimmedLength())),s&&(s.length=0);let r="";for(;t>22||1}return s&&s.push(t),r}}t.BufferLine=h},4841:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.getRangeLength=void 0,t.getRangeLength=function(e,t){if(e.start.y>e.end.y)throw new Error(`Buffer range end (${e.end.x}, ${e.end.y}) cannot be before start (${e.start.x}, ${e.start.y})`);return t*(e.end.y-e.start.y)+(e.end.x-e.start.x+1)}},4634:(e,t)=>{function i(e,t,i){if(t===e.length-1)return e[t].getTrimmedLength();const s=!e[t].hasContent(i-1)&&1===e[t].getWidth(i-1),r=2===e[t+1].getWidth(0);return s&&r?i-1:i}Object.defineProperty(t,"__esModule",{value:!0}),t.getWrappedLineTrimmedLength=t.reflowSmallerGetNewLineLengths=t.reflowLargerApplyNewLayout=t.reflowLargerCreateNewLayout=t.reflowLargerGetLinesToRemove=void 0,t.reflowLargerGetLinesToRemove=function(e,t,s,r,n){const o=[];for(let a=0;a=a&&r0&&(e>d||0===l[e].getTrimmedLength());e--)v++;v>0&&(o.push(a+l.length-v),o.push(v)),a+=l.length-1}return o},t.reflowLargerCreateNewLayout=function(e,t){const i=[];let s=0,r=t[s],n=0;for(let o=0;oi(e,r,t))).reduce(((e,t)=>e+t));let o=0,a=0,h=0;for(;hc&&(o-=c,a++);const l=2===e[a].getWidth(o-1);l&&o--;const d=l?s-1:s;r.push(d),h+=d}return r},t.getWrappedLineTrimmedLength=i},5295:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.BufferSet=void 0;const s=i(8460),r=i(844),n=i(9092);class o extends r.Disposable{constructor(e,t){super(),this._optionsService=e,this._bufferService=t,this._onBufferActivate=this.register(new s.EventEmitter),this.onBufferActivate=this._onBufferActivate.event,this.reset(),this.register(this._optionsService.onSpecificOptionChange("scrollback",(()=>this.resize(this._bufferService.cols,this._bufferService.rows)))),this.register(this._optionsService.onSpecificOptionChange("tabStopWidth",(()=>this.setupTabStops())))}reset(){this._normal=new n.Buffer(!0,this._optionsService,this._bufferService),this._normal.fillViewportRows(),this._alt=new n.Buffer(!1,this._optionsService,this._bufferService),this._activeBuffer=this._normal,this._onBufferActivate.fire({activeBuffer:this._normal,inactiveBuffer:this._alt}),this.setupTabStops()}get alt(){return this._alt}get active(){return this._activeBuffer}get normal(){return this._normal}activateNormalBuffer(){this._activeBuffer!==this._normal&&(this._normal.x=this._alt.x,this._normal.y=this._alt.y,this._alt.clearAllMarkers(),this._alt.clear(),this._activeBuffer=this._normal,this._onBufferActivate.fire({activeBuffer:this._normal,inactiveBuffer:this._alt}))}activateAltBuffer(e){this._activeBuffer!==this._alt&&(this._alt.fillViewportRows(e),this._alt.x=this._normal.x,this._alt.y=this._normal.y,this._activeBuffer=this._alt,this._onBufferActivate.fire({activeBuffer:this._alt,inactiveBuffer:this._normal}))}resize(e,t){this._normal.resize(e,t),this._alt.resize(e,t),this.setupTabStops(e)}setupTabStops(e){this._normal.setupTabStops(e),this._alt.setupTabStops(e)}}t.BufferSet=o},511:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.CellData=void 0;const s=i(482),r=i(643),n=i(3734);class o extends n.AttributeData{constructor(){super(...arguments),this.content=0,this.fg=0,this.bg=0,this.extended=new n.ExtendedAttrs,this.combinedData=""}static fromCharData(e){const t=new o;return t.setFromCharData(e),t}isCombined(){return 2097152&this.content}getWidth(){return this.content>>22}getChars(){return 2097152&this.content?this.combinedData:2097151&this.content?(0,s.stringFromCodePoint)(2097151&this.content):""}getCode(){return this.isCombined()?this.combinedData.charCodeAt(this.combinedData.length-1):2097151&this.content}setFromCharData(e){this.fg=e[r.CHAR_DATA_ATTR_INDEX],this.bg=0;let t=!1;if(e[r.CHAR_DATA_CHAR_INDEX].length>2)t=!0;else if(2===e[r.CHAR_DATA_CHAR_INDEX].length){const i=e[r.CHAR_DATA_CHAR_INDEX].charCodeAt(0);if(55296<=i&&i<=56319){const s=e[r.CHAR_DATA_CHAR_INDEX].charCodeAt(1);56320<=s&&s<=57343?this.content=1024*(i-55296)+s-56320+65536|e[r.CHAR_DATA_WIDTH_INDEX]<<22:t=!0}else t=!0}else this.content=e[r.CHAR_DATA_CHAR_INDEX].charCodeAt(0)|e[r.CHAR_DATA_WIDTH_INDEX]<<22;t&&(this.combinedData=e[r.CHAR_DATA_CHAR_INDEX],this.content=2097152|e[r.CHAR_DATA_WIDTH_INDEX]<<22)}getAsCharData(){return[this.fg,this.getChars(),this.getWidth(),this.getCode()]}}t.CellData=o},643:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WHITESPACE_CELL_CODE=t.WHITESPACE_CELL_WIDTH=t.WHITESPACE_CELL_CHAR=t.NULL_CELL_CODE=t.NULL_CELL_WIDTH=t.NULL_CELL_CHAR=t.CHAR_DATA_CODE_INDEX=t.CHAR_DATA_WIDTH_INDEX=t.CHAR_DATA_CHAR_INDEX=t.CHAR_DATA_ATTR_INDEX=t.DEFAULT_EXT=t.DEFAULT_ATTR=t.DEFAULT_COLOR=void 0,t.DEFAULT_COLOR=0,t.DEFAULT_ATTR=256|t.DEFAULT_COLOR<<9,t.DEFAULT_EXT=0,t.CHAR_DATA_ATTR_INDEX=0,t.CHAR_DATA_CHAR_INDEX=1,t.CHAR_DATA_WIDTH_INDEX=2,t.CHAR_DATA_CODE_INDEX=3,t.NULL_CELL_CHAR="",t.NULL_CELL_WIDTH=1,t.NULL_CELL_CODE=0,t.WHITESPACE_CELL_CHAR=" ",t.WHITESPACE_CELL_WIDTH=1,t.WHITESPACE_CELL_CODE=32},4863:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Marker=void 0;const s=i(8460),r=i(844);class n{get id(){return this._id}constructor(e){this.line=e,this.isDisposed=!1,this._disposables=[],this._id=n._nextId++,this._onDispose=this.register(new s.EventEmitter),this.onDispose=this._onDispose.event}dispose(){this.isDisposed||(this.isDisposed=!0,this.line=-1,this._onDispose.fire(),(0,r.disposeArray)(this._disposables),this._disposables.length=0)}register(e){return this._disposables.push(e),e}}t.Marker=n,n._nextId=1},7116:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.DEFAULT_CHARSET=t.CHARSETS=void 0,t.CHARSETS={},t.DEFAULT_CHARSET=t.CHARSETS.B,t.CHARSETS[0]={"`":"โ—†",a:"โ–’",b:"โ‰",c:"โŒ",d:"โ",e:"โŠ",f:"ยฐ",g:"ยฑ",h:"โค",i:"โ‹",j:"โ”˜",k:"โ”",l:"โ”Œ",m:"โ””",n:"โ”ผ",o:"โŽบ",p:"โŽป",q:"โ”€",r:"โŽผ",s:"โŽฝ",t:"โ”œ",u:"โ”ค",v:"โ”ด",w:"โ”ฌ",x:"โ”‚",y:"โ‰ค",z:"โ‰ฅ","{":"ฯ€","|":"โ‰ ","}":"ยฃ","~":"ยท"},t.CHARSETS.A={"#":"ยฃ"},t.CHARSETS.B=void 0,t.CHARSETS[4]={"#":"ยฃ","@":"ยพ","[":"ij","\\":"ยฝ","]":"|","{":"ยจ","|":"f","}":"ยผ","~":"ยด"},t.CHARSETS.C=t.CHARSETS[5]={"[":"ร„","\\":"ร–","]":"ร…","^":"รœ","`":"รฉ","{":"รค","|":"รถ","}":"รฅ","~":"รผ"},t.CHARSETS.R={"#":"ยฃ","@":"ร ","[":"ยฐ","\\":"รง","]":"ยง","{":"รฉ","|":"รน","}":"รจ","~":"ยจ"},t.CHARSETS.Q={"@":"ร ","[":"รข","\\":"รง","]":"รช","^":"รฎ","`":"รด","{":"รฉ","|":"รน","}":"รจ","~":"รป"},t.CHARSETS.K={"@":"ยง","[":"ร„","\\":"ร–","]":"รœ","{":"รค","|":"รถ","}":"รผ","~":"รŸ"},t.CHARSETS.Y={"#":"ยฃ","@":"ยง","[":"ยฐ","\\":"รง","]":"รฉ","`":"รน","{":"ร ","|":"รฒ","}":"รจ","~":"รฌ"},t.CHARSETS.E=t.CHARSETS[6]={"@":"ร„","[":"ร†","\\":"ร˜","]":"ร…","^":"รœ","`":"รค","{":"รฆ","|":"รธ","}":"รฅ","~":"รผ"},t.CHARSETS.Z={"#":"ยฃ","@":"ยง","[":"ยก","\\":"ร‘","]":"ยฟ","{":"ยฐ","|":"รฑ","}":"รง"},t.CHARSETS.H=t.CHARSETS[7]={"@":"ร‰","[":"ร„","\\":"ร–","]":"ร…","^":"รœ","`":"รฉ","{":"รค","|":"รถ","}":"รฅ","~":"รผ"},t.CHARSETS["="]={"#":"รน","@":"ร ","[":"รฉ","\\":"รง","]":"รช","^":"รฎ",_:"รจ","`":"รด","{":"รค","|":"รถ","}":"รผ","~":"รป"}},2584:(e,t)=>{var i,s,r;Object.defineProperty(t,"__esModule",{value:!0}),t.C1_ESCAPED=t.C1=t.C0=void 0,function(e){e.NUL="\0",e.SOH="",e.STX="",e.ETX="",e.EOT="",e.ENQ="",e.ACK="",e.BEL="",e.BS="\b",e.HT="\t",e.LF="\n",e.VT="\v",e.FF="\f",e.CR="\r",e.SO="",e.SI="",e.DLE="",e.DC1="",e.DC2="",e.DC3="",e.DC4="",e.NAK="",e.SYN="",e.ETB="",e.CAN="",e.EM="",e.SUB="",e.ESC="",e.FS="",e.GS="",e.RS="",e.US="",e.SP=" ",e.DEL=""}(i||(t.C0=i={})),function(e){e.PAD="ย€",e.HOP="ย",e.BPH="ย‚",e.NBH="ยƒ",e.IND="ย„",e.NEL="ย…",e.SSA="ย†",e.ESA="ย‡",e.HTS="ยˆ",e.HTJ="ย‰",e.VTS="ยŠ",e.PLD="ย‹",e.PLU="ยŒ",e.RI="ย",e.SS2="ยŽ",e.SS3="ย",e.DCS="ย",e.PU1="ย‘",e.PU2="ย’",e.STS="ย“",e.CCH="ย”",e.MW="ย•",e.SPA="ย–",e.EPA="ย—",e.SOS="ย˜",e.SGCI="ย™",e.SCI="ยš",e.CSI="ย›",e.ST="ยœ",e.OSC="ย",e.PM="ยž",e.APC="ยŸ"}(s||(t.C1=s={})),function(e){e.ST=`${i.ESC}\\`}(r||(t.C1_ESCAPED=r={}))},7399:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.evaluateKeyboardEvent=void 0;const s=i(2584),r={48:["0",")"],49:["1","!"],50:["2","@"],51:["3","#"],52:["4","$"],53:["5","%"],54:["6","^"],55:["7","&"],56:["8","*"],57:["9","("],186:[";",":"],187:["=","+"],188:[",","<"],189:["-","_"],190:[".",">"],191:["/","?"],192:["`","~"],219:["[","{"],220:["\\","|"],221:["]","}"],222:["'",'"']};t.evaluateKeyboardEvent=function(e,t,i,n){const o={type:0,cancel:!1,key:void 0},a=(e.shiftKey?1:0)|(e.altKey?2:0)|(e.ctrlKey?4:0)|(e.metaKey?8:0);switch(e.keyCode){case 0:"UIKeyInputUpArrow"===e.key?o.key=t?s.C0.ESC+"OA":s.C0.ESC+"[A":"UIKeyInputLeftArrow"===e.key?o.key=t?s.C0.ESC+"OD":s.C0.ESC+"[D":"UIKeyInputRightArrow"===e.key?o.key=t?s.C0.ESC+"OC":s.C0.ESC+"[C":"UIKeyInputDownArrow"===e.key&&(o.key=t?s.C0.ESC+"OB":s.C0.ESC+"[B");break;case 8:o.key=e.ctrlKey?"\b":s.C0.DEL,e.altKey&&(o.key=s.C0.ESC+o.key);break;case 9:if(e.shiftKey){o.key=s.C0.ESC+"[Z";break}o.key=s.C0.HT,o.cancel=!0;break;case 13:o.key=e.altKey?s.C0.ESC+s.C0.CR:s.C0.CR,o.cancel=!0;break;case 27:o.key=s.C0.ESC,e.altKey&&(o.key=s.C0.ESC+s.C0.ESC),o.cancel=!0;break;case 37:if(e.metaKey)break;a?(o.key=s.C0.ESC+"[1;"+(a+1)+"D",o.key===s.C0.ESC+"[1;3D"&&(o.key=s.C0.ESC+(i?"b":"[1;5D"))):o.key=t?s.C0.ESC+"OD":s.C0.ESC+"[D";break;case 39:if(e.metaKey)break;a?(o.key=s.C0.ESC+"[1;"+(a+1)+"C",o.key===s.C0.ESC+"[1;3C"&&(o.key=s.C0.ESC+(i?"f":"[1;5C"))):o.key=t?s.C0.ESC+"OC":s.C0.ESC+"[C";break;case 38:if(e.metaKey)break;a?(o.key=s.C0.ESC+"[1;"+(a+1)+"A",i||o.key!==s.C0.ESC+"[1;3A"||(o.key=s.C0.ESC+"[1;5A")):o.key=t?s.C0.ESC+"OA":s.C0.ESC+"[A";break;case 40:if(e.metaKey)break;a?(o.key=s.C0.ESC+"[1;"+(a+1)+"B",i||o.key!==s.C0.ESC+"[1;3B"||(o.key=s.C0.ESC+"[1;5B")):o.key=t?s.C0.ESC+"OB":s.C0.ESC+"[B";break;case 45:e.shiftKey||e.ctrlKey||(o.key=s.C0.ESC+"[2~");break;case 46:o.key=a?s.C0.ESC+"[3;"+(a+1)+"~":s.C0.ESC+"[3~";break;case 36:o.key=a?s.C0.ESC+"[1;"+(a+1)+"H":t?s.C0.ESC+"OH":s.C0.ESC+"[H";break;case 35:o.key=a?s.C0.ESC+"[1;"+(a+1)+"F":t?s.C0.ESC+"OF":s.C0.ESC+"[F";break;case 33:e.shiftKey?o.type=2:e.ctrlKey?o.key=s.C0.ESC+"[5;"+(a+1)+"~":o.key=s.C0.ESC+"[5~";break;case 34:e.shiftKey?o.type=3:e.ctrlKey?o.key=s.C0.ESC+"[6;"+(a+1)+"~":o.key=s.C0.ESC+"[6~";break;case 112:o.key=a?s.C0.ESC+"[1;"+(a+1)+"P":s.C0.ESC+"OP";break;case 113:o.key=a?s.C0.ESC+"[1;"+(a+1)+"Q":s.C0.ESC+"OQ";break;case 114:o.key=a?s.C0.ESC+"[1;"+(a+1)+"R":s.C0.ESC+"OR";break;case 115:o.key=a?s.C0.ESC+"[1;"+(a+1)+"S":s.C0.ESC+"OS";break;case 116:o.key=a?s.C0.ESC+"[15;"+(a+1)+"~":s.C0.ESC+"[15~";break;case 117:o.key=a?s.C0.ESC+"[17;"+(a+1)+"~":s.C0.ESC+"[17~";break;case 118:o.key=a?s.C0.ESC+"[18;"+(a+1)+"~":s.C0.ESC+"[18~";break;case 119:o.key=a?s.C0.ESC+"[19;"+(a+1)+"~":s.C0.ESC+"[19~";break;case 120:o.key=a?s.C0.ESC+"[20;"+(a+1)+"~":s.C0.ESC+"[20~";break;case 121:o.key=a?s.C0.ESC+"[21;"+(a+1)+"~":s.C0.ESC+"[21~";break;case 122:o.key=a?s.C0.ESC+"[23;"+(a+1)+"~":s.C0.ESC+"[23~";break;case 123:o.key=a?s.C0.ESC+"[24;"+(a+1)+"~":s.C0.ESC+"[24~";break;default:if(!e.ctrlKey||e.shiftKey||e.altKey||e.metaKey)if(i&&!n||!e.altKey||e.metaKey)!i||e.altKey||e.ctrlKey||e.shiftKey||!e.metaKey?e.key&&!e.ctrlKey&&!e.altKey&&!e.metaKey&&e.keyCode>=48&&1===e.key.length?o.key=e.key:e.key&&e.ctrlKey&&("_"===e.key&&(o.key=s.C0.US),"@"===e.key&&(o.key=s.C0.NUL)):65===e.keyCode&&(o.type=1);else{const t=r[e.keyCode],i=t?.[e.shiftKey?1:0];if(i)o.key=s.C0.ESC+i;else if(e.keyCode>=65&&e.keyCode<=90){const t=e.ctrlKey?e.keyCode-64:e.keyCode+32;let i=String.fromCharCode(t);e.shiftKey&&(i=i.toUpperCase()),o.key=s.C0.ESC+i}else if(32===e.keyCode)o.key=s.C0.ESC+(e.ctrlKey?s.C0.NUL:" ");else if("Dead"===e.key&&e.code.startsWith("Key")){let t=e.code.slice(3,4);e.shiftKey||(t=t.toLowerCase()),o.key=s.C0.ESC+t,o.cancel=!0}}else e.keyCode>=65&&e.keyCode<=90?o.key=String.fromCharCode(e.keyCode-64):32===e.keyCode?o.key=s.C0.NUL:e.keyCode>=51&&e.keyCode<=55?o.key=String.fromCharCode(e.keyCode-51+27):56===e.keyCode?o.key=s.C0.DEL:219===e.keyCode?o.key=s.C0.ESC:220===e.keyCode?o.key=s.C0.FS:221===e.keyCode&&(o.key=s.C0.GS)}return o}},482:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Utf8ToUtf32=t.StringToUtf32=t.utf32ToString=t.stringFromCodePoint=void 0,t.stringFromCodePoint=function(e){return e>65535?(e-=65536,String.fromCharCode(55296+(e>>10))+String.fromCharCode(e%1024+56320)):String.fromCharCode(e)},t.utf32ToString=function(e,t=0,i=e.length){let s="";for(let r=t;r65535?(t-=65536,s+=String.fromCharCode(55296+(t>>10))+String.fromCharCode(t%1024+56320)):s+=String.fromCharCode(t)}return s},t.StringToUtf32=class{constructor(){this._interim=0}clear(){this._interim=0}decode(e,t){const i=e.length;if(!i)return 0;let s=0,r=0;if(this._interim){const i=e.charCodeAt(r++);56320<=i&&i<=57343?t[s++]=1024*(this._interim-55296)+i-56320+65536:(t[s++]=this._interim,t[s++]=i),this._interim=0}for(let n=r;n=i)return this._interim=r,s;const o=e.charCodeAt(n);56320<=o&&o<=57343?t[s++]=1024*(r-55296)+o-56320+65536:(t[s++]=r,t[s++]=o)}else 65279!==r&&(t[s++]=r)}return s}},t.Utf8ToUtf32=class{constructor(){this.interim=new Uint8Array(3)}clear(){this.interim.fill(0)}decode(e,t){const i=e.length;if(!i)return 0;let s,r,n,o,a=0,h=0,c=0;if(this.interim[0]){let s=!1,r=this.interim[0];r&=192==(224&r)?31:224==(240&r)?15:7;let n,o=0;for(;(n=63&this.interim[++o])&&o<4;)r<<=6,r|=n;const h=192==(224&this.interim[0])?2:224==(240&this.interim[0])?3:4,l=h-o;for(;c=i)return 0;if(n=e[c++],128!=(192&n)){c--,s=!0;break}this.interim[o++]=n,r<<=6,r|=63&n}s||(2===h?r<128?c--:t[a++]=r:3===h?r<2048||r>=55296&&r<=57343||65279===r||(t[a++]=r):r<65536||r>1114111||(t[a++]=r)),this.interim.fill(0)}const l=i-4;let d=c;for(;d=i)return this.interim[0]=s,a;if(r=e[d++],128!=(192&r)){d--;continue}if(h=(31&s)<<6|63&r,h<128){d--;continue}t[a++]=h}else if(224==(240&s)){if(d>=i)return this.interim[0]=s,a;if(r=e[d++],128!=(192&r)){d--;continue}if(d>=i)return this.interim[0]=s,this.interim[1]=r,a;if(n=e[d++],128!=(192&n)){d--;continue}if(h=(15&s)<<12|(63&r)<<6|63&n,h<2048||h>=55296&&h<=57343||65279===h)continue;t[a++]=h}else if(240==(248&s)){if(d>=i)return this.interim[0]=s,a;if(r=e[d++],128!=(192&r)){d--;continue}if(d>=i)return this.interim[0]=s,this.interim[1]=r,a;if(n=e[d++],128!=(192&n)){d--;continue}if(d>=i)return this.interim[0]=s,this.interim[1]=r,this.interim[2]=n,a;if(o=e[d++],128!=(192&o)){d--;continue}if(h=(7&s)<<18|(63&r)<<12|(63&n)<<6|63&o,h<65536||h>1114111)continue;t[a++]=h}}return a}}},225:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.UnicodeV6=void 0;const s=i(1480),r=[[768,879],[1155,1158],[1160,1161],[1425,1469],[1471,1471],[1473,1474],[1476,1477],[1479,1479],[1536,1539],[1552,1557],[1611,1630],[1648,1648],[1750,1764],[1767,1768],[1770,1773],[1807,1807],[1809,1809],[1840,1866],[1958,1968],[2027,2035],[2305,2306],[2364,2364],[2369,2376],[2381,2381],[2385,2388],[2402,2403],[2433,2433],[2492,2492],[2497,2500],[2509,2509],[2530,2531],[2561,2562],[2620,2620],[2625,2626],[2631,2632],[2635,2637],[2672,2673],[2689,2690],[2748,2748],[2753,2757],[2759,2760],[2765,2765],[2786,2787],[2817,2817],[2876,2876],[2879,2879],[2881,2883],[2893,2893],[2902,2902],[2946,2946],[3008,3008],[3021,3021],[3134,3136],[3142,3144],[3146,3149],[3157,3158],[3260,3260],[3263,3263],[3270,3270],[3276,3277],[3298,3299],[3393,3395],[3405,3405],[3530,3530],[3538,3540],[3542,3542],[3633,3633],[3636,3642],[3655,3662],[3761,3761],[3764,3769],[3771,3772],[3784,3789],[3864,3865],[3893,3893],[3895,3895],[3897,3897],[3953,3966],[3968,3972],[3974,3975],[3984,3991],[3993,4028],[4038,4038],[4141,4144],[4146,4146],[4150,4151],[4153,4153],[4184,4185],[4448,4607],[4959,4959],[5906,5908],[5938,5940],[5970,5971],[6002,6003],[6068,6069],[6071,6077],[6086,6086],[6089,6099],[6109,6109],[6155,6157],[6313,6313],[6432,6434],[6439,6440],[6450,6450],[6457,6459],[6679,6680],[6912,6915],[6964,6964],[6966,6970],[6972,6972],[6978,6978],[7019,7027],[7616,7626],[7678,7679],[8203,8207],[8234,8238],[8288,8291],[8298,8303],[8400,8431],[12330,12335],[12441,12442],[43014,43014],[43019,43019],[43045,43046],[64286,64286],[65024,65039],[65056,65059],[65279,65279],[65529,65531]],n=[[68097,68099],[68101,68102],[68108,68111],[68152,68154],[68159,68159],[119143,119145],[119155,119170],[119173,119179],[119210,119213],[119362,119364],[917505,917505],[917536,917631],[917760,917999]];let o;t.UnicodeV6=class{constructor(){if(this.version="6",!o){o=new Uint8Array(65536),o.fill(1),o[0]=0,o.fill(0,1,32),o.fill(0,127,160),o.fill(2,4352,4448),o[9001]=2,o[9002]=2,o.fill(2,11904,42192),o[12351]=1,o.fill(2,44032,55204),o.fill(2,63744,64256),o.fill(2,65040,65050),o.fill(2,65072,65136),o.fill(2,65280,65377),o.fill(2,65504,65511);for(let e=0;et[r][1])return!1;for(;r>=s;)if(i=s+r>>1,e>t[i][1])s=i+1;else{if(!(e=131072&&e<=196605||e>=196608&&e<=262141?2:1}charProperties(e,t){let i=this.wcwidth(e),r=0===i&&0!==t;if(r){const e=s.UnicodeService.extractWidth(t);0===e?r=!1:e>i&&(i=e)}return s.UnicodeService.createPropertyValue(0,i,r)}}},5981:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WriteBuffer=void 0;const s=i(8460),r=i(844);class n extends r.Disposable{constructor(e){super(),this._action=e,this._writeBuffer=[],this._callbacks=[],this._pendingData=0,this._bufferOffset=0,this._isSyncWriting=!1,this._syncCalls=0,this._didUserInput=!1,this._onWriteParsed=this.register(new s.EventEmitter),this.onWriteParsed=this._onWriteParsed.event}handleUserInput(){this._didUserInput=!0}writeSync(e,t){if(void 0!==t&&this._syncCalls>t)return void(this._syncCalls=0);if(this._pendingData+=e.length,this._writeBuffer.push(e),this._callbacks.push(void 0),this._syncCalls++,this._isSyncWriting)return;let i;for(this._isSyncWriting=!0;i=this._writeBuffer.shift();){this._action(i);const e=this._callbacks.shift();e&&e()}this._pendingData=0,this._bufferOffset=2147483647,this._isSyncWriting=!1,this._syncCalls=0}write(e,t){if(this._pendingData>5e7)throw new Error("write data discarded, use flow control to avoid losing data");if(!this._writeBuffer.length){if(this._bufferOffset=0,this._didUserInput)return this._didUserInput=!1,this._pendingData+=e.length,this._writeBuffer.push(e),this._callbacks.push(t),void this._innerWrite();setTimeout((()=>this._innerWrite()))}this._pendingData+=e.length,this._writeBuffer.push(e),this._callbacks.push(t)}_innerWrite(e=0,t=!0){const i=e||Date.now();for(;this._writeBuffer.length>this._bufferOffset;){const e=this._writeBuffer[this._bufferOffset],s=this._action(e,t);if(s){const e=e=>Date.now()-i>=12?setTimeout((()=>this._innerWrite(0,e))):this._innerWrite(i,e);return void s.catch((e=>(queueMicrotask((()=>{throw e})),Promise.resolve(!1)))).then(e)}const r=this._callbacks[this._bufferOffset];if(r&&r(),this._bufferOffset++,this._pendingData-=e.length,Date.now()-i>=12)break}this._writeBuffer.length>this._bufferOffset?(this._bufferOffset>50&&(this._writeBuffer=this._writeBuffer.slice(this._bufferOffset),this._callbacks=this._callbacks.slice(this._bufferOffset),this._bufferOffset=0),setTimeout((()=>this._innerWrite()))):(this._writeBuffer.length=0,this._callbacks.length=0,this._pendingData=0,this._bufferOffset=0),this._onWriteParsed.fire()}}t.WriteBuffer=n},5941:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.toRgbString=t.parseColor=void 0;const i=/^([\da-f])\/([\da-f])\/([\da-f])$|^([\da-f]{2})\/([\da-f]{2})\/([\da-f]{2})$|^([\da-f]{3})\/([\da-f]{3})\/([\da-f]{3})$|^([\da-f]{4})\/([\da-f]{4})\/([\da-f]{4})$/,s=/^[\da-f]+$/;function r(e,t){const i=e.toString(16),s=i.length<2?"0"+i:i;switch(t){case 4:return i[0];case 8:return s;case 12:return(s+s).slice(0,3);default:return s+s}}t.parseColor=function(e){if(!e)return;let t=e.toLowerCase();if(0===t.indexOf("rgb:")){t=t.slice(4);const e=i.exec(t);if(e){const t=e[1]?15:e[4]?255:e[7]?4095:65535;return[Math.round(parseInt(e[1]||e[4]||e[7]||e[10],16)/t*255),Math.round(parseInt(e[2]||e[5]||e[8]||e[11],16)/t*255),Math.round(parseInt(e[3]||e[6]||e[9]||e[12],16)/t*255)]}}else if(0===t.indexOf("#")&&(t=t.slice(1),s.exec(t)&&[3,6,9,12].includes(t.length))){const e=t.length/3,i=[0,0,0];for(let s=0;s<3;++s){const r=parseInt(t.slice(e*s,e*s+e),16);i[s]=1===e?r<<4:2===e?r:3===e?r>>4:r>>8}return i}},t.toRgbString=function(e,t=16){const[i,s,n]=e;return`rgb:${r(i,t)}/${r(s,t)}/${r(n,t)}`}},5770:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.PAYLOAD_LIMIT=void 0,t.PAYLOAD_LIMIT=1e7},6351:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.DcsHandler=t.DcsParser=void 0;const s=i(482),r=i(8742),n=i(5770),o=[];t.DcsParser=class{constructor(){this._handlers=Object.create(null),this._active=o,this._ident=0,this._handlerFb=()=>{},this._stack={paused:!1,loopPosition:0,fallThrough:!1}}dispose(){this._handlers=Object.create(null),this._handlerFb=()=>{},this._active=o}registerHandler(e,t){void 0===this._handlers[e]&&(this._handlers[e]=[]);const i=this._handlers[e];return i.push(t),{dispose:()=>{const e=i.indexOf(t);-1!==e&&i.splice(e,1)}}}clearHandler(e){this._handlers[e]&&delete this._handlers[e]}setHandlerFallback(e){this._handlerFb=e}reset(){if(this._active.length)for(let e=this._stack.paused?this._stack.loopPosition-1:this._active.length-1;e>=0;--e)this._active[e].unhook(!1);this._stack.paused=!1,this._active=o,this._ident=0}hook(e,t){if(this.reset(),this._ident=e,this._active=this._handlers[e]||o,this._active.length)for(let e=this._active.length-1;e>=0;e--)this._active[e].hook(t);else this._handlerFb(this._ident,"HOOK",t)}put(e,t,i){if(this._active.length)for(let s=this._active.length-1;s>=0;s--)this._active[s].put(e,t,i);else this._handlerFb(this._ident,"PUT",(0,s.utf32ToString)(e,t,i))}unhook(e,t=!0){if(this._active.length){let i=!1,s=this._active.length-1,r=!1;if(this._stack.paused&&(s=this._stack.loopPosition-1,i=t,r=this._stack.fallThrough,this._stack.paused=!1),!r&&!1===i){for(;s>=0&&(i=this._active[s].unhook(e),!0!==i);s--)if(i instanceof Promise)return this._stack.paused=!0,this._stack.loopPosition=s,this._stack.fallThrough=!1,i;s--}for(;s>=0;s--)if(i=this._active[s].unhook(!1),i instanceof Promise)return this._stack.paused=!0,this._stack.loopPosition=s,this._stack.fallThrough=!0,i}else this._handlerFb(this._ident,"UNHOOK",e);this._active=o,this._ident=0}};const a=new r.Params;a.addParam(0),t.DcsHandler=class{constructor(e){this._handler=e,this._data="",this._params=a,this._hitLimit=!1}hook(e){this._params=e.length>1||e.params[0]?e.clone():a,this._data="",this._hitLimit=!1}put(e,t,i){this._hitLimit||(this._data+=(0,s.utf32ToString)(e,t,i),this._data.length>n.PAYLOAD_LIMIT&&(this._data="",this._hitLimit=!0))}unhook(e){let t=!1;if(this._hitLimit)t=!1;else if(e&&(t=this._handler(this._data,this._params),t instanceof Promise))return t.then((e=>(this._params=a,this._data="",this._hitLimit=!1,e)));return this._params=a,this._data="",this._hitLimit=!1,t}}},2015:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.EscapeSequenceParser=t.VT500_TRANSITION_TABLE=t.TransitionTable=void 0;const s=i(844),r=i(8742),n=i(6242),o=i(6351);class a{constructor(e){this.table=new Uint8Array(e)}setDefault(e,t){this.table.fill(e<<4|t)}add(e,t,i,s){this.table[t<<8|e]=i<<4|s}addMany(e,t,i,s){for(let r=0;rt)),i=(e,i)=>t.slice(e,i),s=i(32,127),r=i(0,24);r.push(25),r.push.apply(r,i(28,32));const n=i(0,14);let o;for(o in e.setDefault(1,0),e.addMany(s,0,2,0),n)e.addMany([24,26,153,154],o,3,0),e.addMany(i(128,144),o,3,0),e.addMany(i(144,152),o,3,0),e.add(156,o,0,0),e.add(27,o,11,1),e.add(157,o,4,8),e.addMany([152,158,159],o,0,7),e.add(155,o,11,3),e.add(144,o,11,9);return e.addMany(r,0,3,0),e.addMany(r,1,3,1),e.add(127,1,0,1),e.addMany(r,8,0,8),e.addMany(r,3,3,3),e.add(127,3,0,3),e.addMany(r,4,3,4),e.add(127,4,0,4),e.addMany(r,6,3,6),e.addMany(r,5,3,5),e.add(127,5,0,5),e.addMany(r,2,3,2),e.add(127,2,0,2),e.add(93,1,4,8),e.addMany(s,8,5,8),e.add(127,8,5,8),e.addMany([156,27,24,26,7],8,6,0),e.addMany(i(28,32),8,0,8),e.addMany([88,94,95],1,0,7),e.addMany(s,7,0,7),e.addMany(r,7,0,7),e.add(156,7,0,0),e.add(127,7,0,7),e.add(91,1,11,3),e.addMany(i(64,127),3,7,0),e.addMany(i(48,60),3,8,4),e.addMany([60,61,62,63],3,9,4),e.addMany(i(48,60),4,8,4),e.addMany(i(64,127),4,7,0),e.addMany([60,61,62,63],4,0,6),e.addMany(i(32,64),6,0,6),e.add(127,6,0,6),e.addMany(i(64,127),6,0,0),e.addMany(i(32,48),3,9,5),e.addMany(i(32,48),5,9,5),e.addMany(i(48,64),5,0,6),e.addMany(i(64,127),5,7,0),e.addMany(i(32,48),4,9,5),e.addMany(i(32,48),1,9,2),e.addMany(i(32,48),2,9,2),e.addMany(i(48,127),2,10,0),e.addMany(i(48,80),1,10,0),e.addMany(i(81,88),1,10,0),e.addMany([89,90,92],1,10,0),e.addMany(i(96,127),1,10,0),e.add(80,1,11,9),e.addMany(r,9,0,9),e.add(127,9,0,9),e.addMany(i(28,32),9,0,9),e.addMany(i(32,48),9,9,12),e.addMany(i(48,60),9,8,10),e.addMany([60,61,62,63],9,9,10),e.addMany(r,11,0,11),e.addMany(i(32,128),11,0,11),e.addMany(i(28,32),11,0,11),e.addMany(r,10,0,10),e.add(127,10,0,10),e.addMany(i(28,32),10,0,10),e.addMany(i(48,60),10,8,10),e.addMany([60,61,62,63],10,0,11),e.addMany(i(32,48),10,9,12),e.addMany(r,12,0,12),e.add(127,12,0,12),e.addMany(i(28,32),12,0,12),e.addMany(i(32,48),12,9,12),e.addMany(i(48,64),12,0,11),e.addMany(i(64,127),12,12,13),e.addMany(i(64,127),10,12,13),e.addMany(i(64,127),9,12,13),e.addMany(r,13,13,13),e.addMany(s,13,13,13),e.add(127,13,0,13),e.addMany([27,156,24,26],13,14,0),e.add(h,0,2,0),e.add(h,8,5,8),e.add(h,6,0,6),e.add(h,11,0,11),e.add(h,13,13,13),e}();class c extends s.Disposable{constructor(e=t.VT500_TRANSITION_TABLE){super(),this._transitions=e,this._parseStack={state:0,handlers:[],handlerPos:0,transition:0,chunkPos:0},this.initialState=0,this.currentState=this.initialState,this._params=new r.Params,this._params.addParam(0),this._collect=0,this.precedingJoinState=0,this._printHandlerFb=(e,t,i)=>{},this._executeHandlerFb=e=>{},this._csiHandlerFb=(e,t)=>{},this._escHandlerFb=e=>{},this._errorHandlerFb=e=>e,this._printHandler=this._printHandlerFb,this._executeHandlers=Object.create(null),this._csiHandlers=Object.create(null),this._escHandlers=Object.create(null),this.register((0,s.toDisposable)((()=>{this._csiHandlers=Object.create(null),this._executeHandlers=Object.create(null),this._escHandlers=Object.create(null)}))),this._oscParser=this.register(new n.OscParser),this._dcsParser=this.register(new o.DcsParser),this._errorHandler=this._errorHandlerFb,this.registerEscHandler({final:"\\"},(()=>!0))}_identifier(e,t=[64,126]){let i=0;if(e.prefix){if(e.prefix.length>1)throw new Error("only one byte as prefix supported");if(i=e.prefix.charCodeAt(0),i&&60>i||i>63)throw new Error("prefix must be in range 0x3c .. 0x3f")}if(e.intermediates){if(e.intermediates.length>2)throw new Error("only two bytes as intermediates are supported");for(let t=0;ts||s>47)throw new Error("intermediate must be in range 0x20 .. 0x2f");i<<=8,i|=s}}if(1!==e.final.length)throw new Error("final must be a single byte");const s=e.final.charCodeAt(0);if(t[0]>s||s>t[1])throw new Error(`final must be in range ${t[0]} .. ${t[1]}`);return i<<=8,i|=s,i}identToString(e){const t=[];for(;e;)t.push(String.fromCharCode(255&e)),e>>=8;return t.reverse().join("")}setPrintHandler(e){this._printHandler=e}clearPrintHandler(){this._printHandler=this._printHandlerFb}registerEscHandler(e,t){const i=this._identifier(e,[48,126]);void 0===this._escHandlers[i]&&(this._escHandlers[i]=[]);const s=this._escHandlers[i];return s.push(t),{dispose:()=>{const e=s.indexOf(t);-1!==e&&s.splice(e,1)}}}clearEscHandler(e){this._escHandlers[this._identifier(e,[48,126])]&&delete this._escHandlers[this._identifier(e,[48,126])]}setEscHandlerFallback(e){this._escHandlerFb=e}setExecuteHandler(e,t){this._executeHandlers[e.charCodeAt(0)]=t}clearExecuteHandler(e){this._executeHandlers[e.charCodeAt(0)]&&delete this._executeHandlers[e.charCodeAt(0)]}setExecuteHandlerFallback(e){this._executeHandlerFb=e}registerCsiHandler(e,t){const i=this._identifier(e);void 0===this._csiHandlers[i]&&(this._csiHandlers[i]=[]);const s=this._csiHandlers[i];return s.push(t),{dispose:()=>{const e=s.indexOf(t);-1!==e&&s.splice(e,1)}}}clearCsiHandler(e){this._csiHandlers[this._identifier(e)]&&delete this._csiHandlers[this._identifier(e)]}setCsiHandlerFallback(e){this._csiHandlerFb=e}registerDcsHandler(e,t){return this._dcsParser.registerHandler(this._identifier(e),t)}clearDcsHandler(e){this._dcsParser.clearHandler(this._identifier(e))}setDcsHandlerFallback(e){this._dcsParser.setHandlerFallback(e)}registerOscHandler(e,t){return this._oscParser.registerHandler(e,t)}clearOscHandler(e){this._oscParser.clearHandler(e)}setOscHandlerFallback(e){this._oscParser.setHandlerFallback(e)}setErrorHandler(e){this._errorHandler=e}clearErrorHandler(){this._errorHandler=this._errorHandlerFb}reset(){this.currentState=this.initialState,this._oscParser.reset(),this._dcsParser.reset(),this._params.reset(),this._params.addParam(0),this._collect=0,this.precedingJoinState=0,0!==this._parseStack.state&&(this._parseStack.state=2,this._parseStack.handlers=[])}_preserveStack(e,t,i,s,r){this._parseStack.state=e,this._parseStack.handlers=t,this._parseStack.handlerPos=i,this._parseStack.transition=s,this._parseStack.chunkPos=r}parse(e,t,i){let s,r=0,n=0,o=0;if(this._parseStack.state)if(2===this._parseStack.state)this._parseStack.state=0,o=this._parseStack.chunkPos+1;else{if(void 0===i||1===this._parseStack.state)throw this._parseStack.state=1,new Error("improper continuation due to previous async handler, giving up parsing");const t=this._parseStack.handlers;let n=this._parseStack.handlerPos-1;switch(this._parseStack.state){case 3:if(!1===i&&n>-1)for(;n>=0&&(s=t[n](this._params),!0!==s);n--)if(s instanceof Promise)return this._parseStack.handlerPos=n,s;this._parseStack.handlers=[];break;case 4:if(!1===i&&n>-1)for(;n>=0&&(s=t[n](),!0!==s);n--)if(s instanceof Promise)return this._parseStack.handlerPos=n,s;this._parseStack.handlers=[];break;case 6:if(r=e[this._parseStack.chunkPos],s=this._dcsParser.unhook(24!==r&&26!==r,i),s)return s;27===r&&(this._parseStack.transition|=1),this._params.reset(),this._params.addParam(0),this._collect=0;break;case 5:if(r=e[this._parseStack.chunkPos],s=this._oscParser.end(24!==r&&26!==r,i),s)return s;27===r&&(this._parseStack.transition|=1),this._params.reset(),this._params.addParam(0),this._collect=0}this._parseStack.state=0,o=this._parseStack.chunkPos+1,this.precedingJoinState=0,this.currentState=15&this._parseStack.transition}for(let i=o;i>4){case 2:for(let s=i+1;;++s){if(s>=t||(r=e[s])<32||r>126&&r=t||(r=e[s])<32||r>126&&r=t||(r=e[s])<32||r>126&&r=t||(r=e[s])<32||r>126&&r=0&&(s=o[a](this._params),!0!==s);a--)if(s instanceof Promise)return this._preserveStack(3,o,a,n,i),s;a<0&&this._csiHandlerFb(this._collect<<8|r,this._params),this.precedingJoinState=0;break;case 8:do{switch(r){case 59:this._params.addParam(0);break;case 58:this._params.addSubParam(-1);break;default:this._params.addDigit(r-48)}}while(++i47&&r<60);i--;break;case 9:this._collect<<=8,this._collect|=r;break;case 10:const c=this._escHandlers[this._collect<<8|r];let l=c?c.length-1:-1;for(;l>=0&&(s=c[l](),!0!==s);l--)if(s instanceof Promise)return this._preserveStack(4,c,l,n,i),s;l<0&&this._escHandlerFb(this._collect<<8|r),this.precedingJoinState=0;break;case 11:this._params.reset(),this._params.addParam(0),this._collect=0;break;case 12:this._dcsParser.hook(this._collect<<8|r,this._params);break;case 13:for(let s=i+1;;++s)if(s>=t||24===(r=e[s])||26===r||27===r||r>127&&r=t||(r=e[s])<32||r>127&&r{Object.defineProperty(t,"__esModule",{value:!0}),t.OscHandler=t.OscParser=void 0;const s=i(5770),r=i(482),n=[];t.OscParser=class{constructor(){this._state=0,this._active=n,this._id=-1,this._handlers=Object.create(null),this._handlerFb=()=>{},this._stack={paused:!1,loopPosition:0,fallThrough:!1}}registerHandler(e,t){void 0===this._handlers[e]&&(this._handlers[e]=[]);const i=this._handlers[e];return i.push(t),{dispose:()=>{const e=i.indexOf(t);-1!==e&&i.splice(e,1)}}}clearHandler(e){this._handlers[e]&&delete this._handlers[e]}setHandlerFallback(e){this._handlerFb=e}dispose(){this._handlers=Object.create(null),this._handlerFb=()=>{},this._active=n}reset(){if(2===this._state)for(let e=this._stack.paused?this._stack.loopPosition-1:this._active.length-1;e>=0;--e)this._active[e].end(!1);this._stack.paused=!1,this._active=n,this._id=-1,this._state=0}_start(){if(this._active=this._handlers[this._id]||n,this._active.length)for(let e=this._active.length-1;e>=0;e--)this._active[e].start();else this._handlerFb(this._id,"START")}_put(e,t,i){if(this._active.length)for(let s=this._active.length-1;s>=0;s--)this._active[s].put(e,t,i);else this._handlerFb(this._id,"PUT",(0,r.utf32ToString)(e,t,i))}start(){this.reset(),this._state=1}put(e,t,i){if(3!==this._state){if(1===this._state)for(;t0&&this._put(e,t,i)}}end(e,t=!0){if(0!==this._state){if(3!==this._state)if(1===this._state&&this._start(),this._active.length){let i=!1,s=this._active.length-1,r=!1;if(this._stack.paused&&(s=this._stack.loopPosition-1,i=t,r=this._stack.fallThrough,this._stack.paused=!1),!r&&!1===i){for(;s>=0&&(i=this._active[s].end(e),!0!==i);s--)if(i instanceof Promise)return this._stack.paused=!0,this._stack.loopPosition=s,this._stack.fallThrough=!1,i;s--}for(;s>=0;s--)if(i=this._active[s].end(!1),i instanceof Promise)return this._stack.paused=!0,this._stack.loopPosition=s,this._stack.fallThrough=!0,i}else this._handlerFb(this._id,"END",e);this._active=n,this._id=-1,this._state=0}}},t.OscHandler=class{constructor(e){this._handler=e,this._data="",this._hitLimit=!1}start(){this._data="",this._hitLimit=!1}put(e,t,i){this._hitLimit||(this._data+=(0,r.utf32ToString)(e,t,i),this._data.length>s.PAYLOAD_LIMIT&&(this._data="",this._hitLimit=!0))}end(e){let t=!1;if(this._hitLimit)t=!1;else if(e&&(t=this._handler(this._data),t instanceof Promise))return t.then((e=>(this._data="",this._hitLimit=!1,e)));return this._data="",this._hitLimit=!1,t}}},8742:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Params=void 0;const i=2147483647;class s{static fromArray(e){const t=new s;if(!e.length)return t;for(let i=Array.isArray(e[0])?1:0;i256)throw new Error("maxSubParamsLength must not be greater than 256");this.params=new Int32Array(e),this.length=0,this._subParams=new Int32Array(t),this._subParamsLength=0,this._subParamsIdx=new Uint16Array(e),this._rejectDigits=!1,this._rejectSubDigits=!1,this._digitIsSub=!1}clone(){const e=new s(this.maxLength,this.maxSubParamsLength);return e.params.set(this.params),e.length=this.length,e._subParams.set(this._subParams),e._subParamsLength=this._subParamsLength,e._subParamsIdx.set(this._subParamsIdx),e._rejectDigits=this._rejectDigits,e._rejectSubDigits=this._rejectSubDigits,e._digitIsSub=this._digitIsSub,e}toArray(){const e=[];for(let t=0;t>8,s=255&this._subParamsIdx[t];s-i>0&&e.push(Array.prototype.slice.call(this._subParams,i,s))}return e}reset(){this.length=0,this._subParamsLength=0,this._rejectDigits=!1,this._rejectSubDigits=!1,this._digitIsSub=!1}addParam(e){if(this._digitIsSub=!1,this.length>=this.maxLength)this._rejectDigits=!0;else{if(e<-1)throw new Error("values lesser than -1 are not allowed");this._subParamsIdx[this.length]=this._subParamsLength<<8|this._subParamsLength,this.params[this.length++]=e>i?i:e}}addSubParam(e){if(this._digitIsSub=!0,this.length)if(this._rejectDigits||this._subParamsLength>=this.maxSubParamsLength)this._rejectSubDigits=!0;else{if(e<-1)throw new Error("values lesser than -1 are not allowed");this._subParams[this._subParamsLength++]=e>i?i:e,this._subParamsIdx[this.length-1]++}}hasSubParams(e){return(255&this._subParamsIdx[e])-(this._subParamsIdx[e]>>8)>0}getSubParams(e){const t=this._subParamsIdx[e]>>8,i=255&this._subParamsIdx[e];return i-t>0?this._subParams.subarray(t,i):null}getSubParamsAll(){const e={};for(let t=0;t>8,s=255&this._subParamsIdx[t];s-i>0&&(e[t]=this._subParams.slice(i,s))}return e}addDigit(e){let t;if(this._rejectDigits||!(t=this._digitIsSub?this._subParamsLength:this.length)||this._digitIsSub&&this._rejectSubDigits)return;const s=this._digitIsSub?this._subParams:this.params,r=s[t-1];s[t-1]=~r?Math.min(10*r+e,i):e}}t.Params=s},5741:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.AddonManager=void 0,t.AddonManager=class{constructor(){this._addons=[]}dispose(){for(let e=this._addons.length-1;e>=0;e--)this._addons[e].instance.dispose()}loadAddon(e,t){const i={instance:t,dispose:t.dispose,isDisposed:!1};this._addons.push(i),t.dispose=()=>this._wrappedAddonDispose(i),t.activate(e)}_wrappedAddonDispose(e){if(e.isDisposed)return;let t=-1;for(let i=0;i{Object.defineProperty(t,"__esModule",{value:!0}),t.BufferApiView=void 0;const s=i(3785),r=i(511);t.BufferApiView=class{constructor(e,t){this._buffer=e,this.type=t}init(e){return this._buffer=e,this}get cursorY(){return this._buffer.y}get cursorX(){return this._buffer.x}get viewportY(){return this._buffer.ydisp}get baseY(){return this._buffer.ybase}get length(){return this._buffer.lines.length}getLine(e){const t=this._buffer.lines.get(e);if(t)return new s.BufferLineApiView(t)}getNullCell(){return new r.CellData}}},3785:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.BufferLineApiView=void 0;const s=i(511);t.BufferLineApiView=class{constructor(e){this._line=e}get isWrapped(){return this._line.isWrapped}get length(){return this._line.length}getCell(e,t){if(!(e<0||e>=this._line.length))return t?(this._line.loadCell(e,t),t):this._line.loadCell(e,new s.CellData)}translateToString(e,t,i){return this._line.translateToString(e,t,i)}}},8285:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.BufferNamespaceApi=void 0;const s=i(8771),r=i(8460),n=i(844);class o extends n.Disposable{constructor(e){super(),this._core=e,this._onBufferChange=this.register(new r.EventEmitter),this.onBufferChange=this._onBufferChange.event,this._normal=new s.BufferApiView(this._core.buffers.normal,"normal"),this._alternate=new s.BufferApiView(this._core.buffers.alt,"alternate"),this._core.buffers.onBufferActivate((()=>this._onBufferChange.fire(this.active)))}get active(){if(this._core.buffers.active===this._core.buffers.normal)return this.normal;if(this._core.buffers.active===this._core.buffers.alt)return this.alternate;throw new Error("Active buffer is neither normal nor alternate")}get normal(){return this._normal.init(this._core.buffers.normal)}get alternate(){return this._alternate.init(this._core.buffers.alt)}}t.BufferNamespaceApi=o},7975:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ParserApi=void 0,t.ParserApi=class{constructor(e){this._core=e}registerCsiHandler(e,t){return this._core.registerCsiHandler(e,(e=>t(e.toArray())))}addCsiHandler(e,t){return this.registerCsiHandler(e,t)}registerDcsHandler(e,t){return this._core.registerDcsHandler(e,((e,i)=>t(e,i.toArray())))}addDcsHandler(e,t){return this.registerDcsHandler(e,t)}registerEscHandler(e,t){return this._core.registerEscHandler(e,t)}addEscHandler(e,t){return this.registerEscHandler(e,t)}registerOscHandler(e,t){return this._core.registerOscHandler(e,t)}addOscHandler(e,t){return this.registerOscHandler(e,t)}}},7090:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.UnicodeApi=void 0,t.UnicodeApi=class{constructor(e){this._core=e}register(e){this._core.unicodeService.register(e)}get versions(){return this._core.unicodeService.versions}get activeVersion(){return this._core.unicodeService.activeVersion}set activeVersion(e){this._core.unicodeService.activeVersion=e}}},744:function(e,t,i){var s=this&&this.__decorate||function(e,t,i,s){var r,n=arguments.length,o=n<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,i,s);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(o=(n<3?r(o):n>3?r(t,i,o):r(t,i))||o);return n>3&&o&&Object.defineProperty(t,i,o),o},r=this&&this.__param||function(e,t){return function(i,s){t(i,s,e)}};Object.defineProperty(t,"__esModule",{value:!0}),t.BufferService=t.MINIMUM_ROWS=t.MINIMUM_COLS=void 0;const n=i(8460),o=i(844),a=i(5295),h=i(2585);t.MINIMUM_COLS=2,t.MINIMUM_ROWS=1;let c=t.BufferService=class extends o.Disposable{get buffer(){return this.buffers.active}constructor(e){super(),this.isUserScrolling=!1,this._onResize=this.register(new n.EventEmitter),this.onResize=this._onResize.event,this._onScroll=this.register(new n.EventEmitter),this.onScroll=this._onScroll.event,this.cols=Math.max(e.rawOptions.cols||0,t.MINIMUM_COLS),this.rows=Math.max(e.rawOptions.rows||0,t.MINIMUM_ROWS),this.buffers=this.register(new a.BufferSet(e,this))}resize(e,t){this.cols=e,this.rows=t,this.buffers.resize(e,t),this._onResize.fire({cols:e,rows:t})}reset(){this.buffers.reset(),this.isUserScrolling=!1}scroll(e,t=!1){const i=this.buffer;let s;s=this._cachedBlankLine,s&&s.length===this.cols&&s.getFg(0)===e.fg&&s.getBg(0)===e.bg||(s=i.getBlankLine(e,t),this._cachedBlankLine=s),s.isWrapped=t;const r=i.ybase+i.scrollTop,n=i.ybase+i.scrollBottom;if(0===i.scrollTop){const e=i.lines.isFull;n===i.lines.length-1?e?i.lines.recycle().copyFrom(s):i.lines.push(s.clone()):i.lines.splice(n+1,0,s.clone()),e?this.isUserScrolling&&(i.ydisp=Math.max(i.ydisp-1,0)):(i.ybase++,this.isUserScrolling||i.ydisp++)}else{const e=n-r+1;i.lines.shiftElements(r+1,e-1,-1),i.lines.set(n,s.clone())}this.isUserScrolling||(i.ydisp=i.ybase),this._onScroll.fire(i.ydisp)}scrollLines(e,t,i){const s=this.buffer;if(e<0){if(0===s.ydisp)return;this.isUserScrolling=!0}else e+s.ydisp>=s.ybase&&(this.isUserScrolling=!1);const r=s.ydisp;s.ydisp=Math.max(Math.min(s.ydisp+e,s.ybase),0),r!==s.ydisp&&(t||this._onScroll.fire(s.ydisp))}};t.BufferService=c=s([r(0,h.IOptionsService)],c)},7994:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.CharsetService=void 0,t.CharsetService=class{constructor(){this.glevel=0,this._charsets=[]}reset(){this.charset=void 0,this._charsets=[],this.glevel=0}setgLevel(e){this.glevel=e,this.charset=this._charsets[e]}setgCharset(e,t){this._charsets[e]=t,this.glevel===e&&(this.charset=t)}}},1753:function(e,t,i){var s=this&&this.__decorate||function(e,t,i,s){var r,n=arguments.length,o=n<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,i,s);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(o=(n<3?r(o):n>3?r(t,i,o):r(t,i))||o);return n>3&&o&&Object.defineProperty(t,i,o),o},r=this&&this.__param||function(e,t){return function(i,s){t(i,s,e)}};Object.defineProperty(t,"__esModule",{value:!0}),t.CoreMouseService=void 0;const n=i(2585),o=i(8460),a=i(844),h={NONE:{events:0,restrict:()=>!1},X10:{events:1,restrict:e=>4!==e.button&&1===e.action&&(e.ctrl=!1,e.alt=!1,e.shift=!1,!0)},VT200:{events:19,restrict:e=>32!==e.action},DRAG:{events:23,restrict:e=>32!==e.action||3!==e.button},ANY:{events:31,restrict:e=>!0}};function c(e,t){let i=(e.ctrl?16:0)|(e.shift?4:0)|(e.alt?8:0);return 4===e.button?(i|=64,i|=e.action):(i|=3&e.button,4&e.button&&(i|=64),8&e.button&&(i|=128),32===e.action?i|=32:0!==e.action||t||(i|=3)),i}const l=String.fromCharCode,d={DEFAULT:e=>{const t=[c(e,!1)+32,e.col+32,e.row+32];return t[0]>255||t[1]>255||t[2]>255?"":`${l(t[0])}${l(t[1])}${l(t[2])}`},SGR:e=>{const t=0===e.action&&4!==e.button?"m":"M";return`[<${c(e,!0)};${e.col};${e.row}${t}`},SGR_PIXELS:e=>{const t=0===e.action&&4!==e.button?"m":"M";return`[<${c(e,!0)};${e.x};${e.y}${t}`}};let _=t.CoreMouseService=class extends a.Disposable{constructor(e,t){super(),this._bufferService=e,this._coreService=t,this._protocols={},this._encodings={},this._activeProtocol="",this._activeEncoding="",this._lastEvent=null,this._onProtocolChange=this.register(new o.EventEmitter),this.onProtocolChange=this._onProtocolChange.event;for(const e of Object.keys(h))this.addProtocol(e,h[e]);for(const e of Object.keys(d))this.addEncoding(e,d[e]);this.reset()}addProtocol(e,t){this._protocols[e]=t}addEncoding(e,t){this._encodings[e]=t}get activeProtocol(){return this._activeProtocol}get areMouseEventsActive(){return 0!==this._protocols[this._activeProtocol].events}set activeProtocol(e){if(!this._protocols[e])throw new Error(`unknown protocol "${e}"`);this._activeProtocol=e,this._onProtocolChange.fire(this._protocols[e].events)}get activeEncoding(){return this._activeEncoding}set activeEncoding(e){if(!this._encodings[e])throw new Error(`unknown encoding "${e}"`);this._activeEncoding=e}reset(){this.activeProtocol="NONE",this.activeEncoding="DEFAULT",this._lastEvent=null}triggerMouseEvent(e){if(e.col<0||e.col>=this._bufferService.cols||e.row<0||e.row>=this._bufferService.rows)return!1;if(4===e.button&&32===e.action)return!1;if(3===e.button&&32!==e.action)return!1;if(4!==e.button&&(2===e.action||3===e.action))return!1;if(e.col++,e.row++,32===e.action&&this._lastEvent&&this._equalEvents(this._lastEvent,e,"SGR_PIXELS"===this._activeEncoding))return!1;if(!this._protocols[this._activeProtocol].restrict(e))return!1;const t=this._encodings[this._activeEncoding](e);return t&&("DEFAULT"===this._activeEncoding?this._coreService.triggerBinaryEvent(t):this._coreService.triggerDataEvent(t,!0)),this._lastEvent=e,!0}explainEvents(e){return{down:!!(1&e),up:!!(2&e),drag:!!(4&e),move:!!(8&e),wheel:!!(16&e)}}_equalEvents(e,t,i){if(i){if(e.x!==t.x)return!1;if(e.y!==t.y)return!1}else{if(e.col!==t.col)return!1;if(e.row!==t.row)return!1}return e.button===t.button&&e.action===t.action&&e.ctrl===t.ctrl&&e.alt===t.alt&&e.shift===t.shift}};t.CoreMouseService=_=s([r(0,n.IBufferService),r(1,n.ICoreService)],_)},6975:function(e,t,i){var s=this&&this.__decorate||function(e,t,i,s){var r,n=arguments.length,o=n<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,i,s);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(o=(n<3?r(o):n>3?r(t,i,o):r(t,i))||o);return n>3&&o&&Object.defineProperty(t,i,o),o},r=this&&this.__param||function(e,t){return function(i,s){t(i,s,e)}};Object.defineProperty(t,"__esModule",{value:!0}),t.CoreService=void 0;const n=i(1439),o=i(8460),a=i(844),h=i(2585),c=Object.freeze({insertMode:!1}),l=Object.freeze({applicationCursorKeys:!1,applicationKeypad:!1,bracketedPasteMode:!1,origin:!1,reverseWraparound:!1,sendFocus:!1,wraparound:!0});let d=t.CoreService=class extends a.Disposable{constructor(e,t,i){super(),this._bufferService=e,this._logService=t,this._optionsService=i,this.isCursorInitialized=!1,this.isCursorHidden=!1,this._onData=this.register(new o.EventEmitter),this.onData=this._onData.event,this._onUserInput=this.register(new o.EventEmitter),this.onUserInput=this._onUserInput.event,this._onBinary=this.register(new o.EventEmitter),this.onBinary=this._onBinary.event,this._onRequestScrollToBottom=this.register(new o.EventEmitter),this.onRequestScrollToBottom=this._onRequestScrollToBottom.event,this.modes=(0,n.clone)(c),this.decPrivateModes=(0,n.clone)(l)}reset(){this.modes=(0,n.clone)(c),this.decPrivateModes=(0,n.clone)(l)}triggerDataEvent(e,t=!1){if(this._optionsService.rawOptions.disableStdin)return;const i=this._bufferService.buffer;t&&this._optionsService.rawOptions.scrollOnUserInput&&i.ybase!==i.ydisp&&this._onRequestScrollToBottom.fire(),t&&this._onUserInput.fire(),this._logService.debug(`sending data "${e}"`,(()=>e.split("").map((e=>e.charCodeAt(0))))),this._onData.fire(e)}triggerBinaryEvent(e){this._optionsService.rawOptions.disableStdin||(this._logService.debug(`sending binary "${e}"`,(()=>e.split("").map((e=>e.charCodeAt(0))))),this._onBinary.fire(e))}};t.CoreService=d=s([r(0,h.IBufferService),r(1,h.ILogService),r(2,h.IOptionsService)],d)},9074:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.DecorationService=void 0;const s=i(8055),r=i(8460),n=i(844),o=i(6106);let a=0,h=0;class c extends n.Disposable{get decorations(){return this._decorations.values()}constructor(){super(),this._decorations=new o.SortedList((e=>e?.marker.line)),this._onDecorationRegistered=this.register(new r.EventEmitter),this.onDecorationRegistered=this._onDecorationRegistered.event,this._onDecorationRemoved=this.register(new r.EventEmitter),this.onDecorationRemoved=this._onDecorationRemoved.event,this.register((0,n.toDisposable)((()=>this.reset())))}registerDecoration(e){if(e.marker.isDisposed)return;const t=new l(e);if(t){const e=t.marker.onDispose((()=>t.dispose()));t.onDispose((()=>{t&&(this._decorations.delete(t)&&this._onDecorationRemoved.fire(t),e.dispose())})),this._decorations.insert(t),this._onDecorationRegistered.fire(t)}return t}reset(){for(const e of this._decorations.values())e.dispose();this._decorations.clear()}*getDecorationsAtCell(e,t,i){let s=0,r=0;for(const n of this._decorations.getKeyIterator(t))s=n.options.x??0,r=s+(n.options.width??1),e>=s&&e{a=t.options.x??0,h=a+(t.options.width??1),e>=a&&e{Object.defineProperty(t,"__esModule",{value:!0}),t.InstantiationService=t.ServiceCollection=void 0;const s=i(2585),r=i(8343);class n{constructor(...e){this._entries=new Map;for(const[t,i]of e)this.set(t,i)}set(e,t){const i=this._entries.get(e);return this._entries.set(e,t),i}forEach(e){for(const[t,i]of this._entries.entries())e(t,i)}has(e){return this._entries.has(e)}get(e){return this._entries.get(e)}}t.ServiceCollection=n,t.InstantiationService=class{constructor(){this._services=new n,this._services.set(s.IInstantiationService,this)}setService(e,t){this._services.set(e,t)}getService(e){return this._services.get(e)}createInstance(e,...t){const i=(0,r.getServiceDependencies)(e).sort(((e,t)=>e.index-t.index)),s=[];for(const t of i){const i=this._services.get(t.id);if(!i)throw new Error(`[createInstance] ${e.name} depends on UNKNOWN service ${t.id}.`);s.push(i)}const n=i.length>0?i[0].index:t.length;if(t.length!==n)throw new Error(`[createInstance] First service dependency of ${e.name} at position ${n+1} conflicts with ${t.length} static arguments`);return new e(...[...t,...s])}}},7866:function(e,t,i){var s=this&&this.__decorate||function(e,t,i,s){var r,n=arguments.length,o=n<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,i,s);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(o=(n<3?r(o):n>3?r(t,i,o):r(t,i))||o);return n>3&&o&&Object.defineProperty(t,i,o),o},r=this&&this.__param||function(e,t){return function(i,s){t(i,s,e)}};Object.defineProperty(t,"__esModule",{value:!0}),t.traceCall=t.setTraceLogger=t.LogService=void 0;const n=i(844),o=i(2585),a={trace:o.LogLevelEnum.TRACE,debug:o.LogLevelEnum.DEBUG,info:o.LogLevelEnum.INFO,warn:o.LogLevelEnum.WARN,error:o.LogLevelEnum.ERROR,off:o.LogLevelEnum.OFF};let h,c=t.LogService=class extends n.Disposable{get logLevel(){return this._logLevel}constructor(e){super(),this._optionsService=e,this._logLevel=o.LogLevelEnum.OFF,this._updateLogLevel(),this.register(this._optionsService.onSpecificOptionChange("logLevel",(()=>this._updateLogLevel()))),h=this}_updateLogLevel(){this._logLevel=a[this._optionsService.rawOptions.logLevel]}_evalLazyOptionalParams(e){for(let t=0;tJSON.stringify(e))).join(", ")})`);const t=s.apply(this,e);return h.trace(`GlyphRenderer#${s.name} return`,t),t}}},7302:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.OptionsService=t.DEFAULT_OPTIONS=void 0;const s=i(8460),r=i(844),n=i(6114);t.DEFAULT_OPTIONS={cols:80,rows:24,cursorBlink:!1,cursorStyle:"block",cursorWidth:1,cursorInactiveStyle:"outline",customGlyphs:!0,drawBoldTextInBrightColors:!0,documentOverride:null,fastScrollModifier:"alt",fastScrollSensitivity:5,fontFamily:"courier-new, courier, monospace",fontSize:15,fontWeight:"normal",fontWeightBold:"bold",ignoreBracketedPasteMode:!1,lineHeight:1,letterSpacing:0,linkHandler:null,logLevel:"info",logger:null,scrollback:1e3,scrollOnUserInput:!0,scrollSensitivity:1,screenReaderMode:!1,smoothScrollDuration:0,macOptionIsMeta:!1,macOptionClickForcesSelection:!1,minimumContrastRatio:1,disableStdin:!1,allowProposedApi:!1,allowTransparency:!1,tabStopWidth:8,theme:{},rescaleOverlappingGlyphs:!1,rightClickSelectsWord:n.isMac,windowOptions:{},windowsMode:!1,windowsPty:{},wordSeparator:" ()[]{}',\"`",altClickMovesCursor:!0,convertEol:!1,termName:"xterm",cancelEvents:!1,overviewRulerWidth:0};const o=["normal","bold","100","200","300","400","500","600","700","800","900"];class a extends r.Disposable{constructor(e){super(),this._onOptionChange=this.register(new s.EventEmitter),this.onOptionChange=this._onOptionChange.event;const i={...t.DEFAULT_OPTIONS};for(const t in e)if(t in i)try{const s=e[t];i[t]=this._sanitizeAndValidateOption(t,s)}catch(e){console.error(e)}this.rawOptions=i,this.options={...i},this._setupOptions(),this.register((0,r.toDisposable)((()=>{this.rawOptions.linkHandler=null,this.rawOptions.documentOverride=null})))}onSpecificOptionChange(e,t){return this.onOptionChange((i=>{i===e&&t(this.rawOptions[e])}))}onMultipleOptionChange(e,t){return this.onOptionChange((i=>{-1!==e.indexOf(i)&&t()}))}_setupOptions(){const e=e=>{if(!(e in t.DEFAULT_OPTIONS))throw new Error(`No option with key "${e}"`);return this.rawOptions[e]},i=(e,i)=>{if(!(e in t.DEFAULT_OPTIONS))throw new Error(`No option with key "${e}"`);i=this._sanitizeAndValidateOption(e,i),this.rawOptions[e]!==i&&(this.rawOptions[e]=i,this._onOptionChange.fire(e))};for(const t in this.rawOptions){const s={get:e.bind(this,t),set:i.bind(this,t)};Object.defineProperty(this.options,t,s)}}_sanitizeAndValidateOption(e,i){switch(e){case"cursorStyle":if(i||(i=t.DEFAULT_OPTIONS[e]),!function(e){return"block"===e||"underline"===e||"bar"===e}(i))throw new Error(`"${i}" is not a valid value for ${e}`);break;case"wordSeparator":i||(i=t.DEFAULT_OPTIONS[e]);break;case"fontWeight":case"fontWeightBold":if("number"==typeof i&&1<=i&&i<=1e3)break;i=o.includes(i)?i:t.DEFAULT_OPTIONS[e];break;case"cursorWidth":i=Math.floor(i);case"lineHeight":case"tabStopWidth":if(i<1)throw new Error(`${e} cannot be less than 1, value: ${i}`);break;case"minimumContrastRatio":i=Math.max(1,Math.min(21,Math.round(10*i)/10));break;case"scrollback":if((i=Math.min(i,4294967295))<0)throw new Error(`${e} cannot be less than 0, value: ${i}`);break;case"fastScrollSensitivity":case"scrollSensitivity":if(i<=0)throw new Error(`${e} cannot be less than or equal to 0, value: ${i}`);break;case"rows":case"cols":if(!i&&0!==i)throw new Error(`${e} must be numeric, value: ${i}`);break;case"windowsPty":i=i??{}}return i}}t.OptionsService=a},2660:function(e,t,i){var s=this&&this.__decorate||function(e,t,i,s){var r,n=arguments.length,o=n<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,i,s);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(o=(n<3?r(o):n>3?r(t,i,o):r(t,i))||o);return n>3&&o&&Object.defineProperty(t,i,o),o},r=this&&this.__param||function(e,t){return function(i,s){t(i,s,e)}};Object.defineProperty(t,"__esModule",{value:!0}),t.OscLinkService=void 0;const n=i(2585);let o=t.OscLinkService=class{constructor(e){this._bufferService=e,this._nextId=1,this._entriesWithId=new Map,this._dataByLinkId=new Map}registerLink(e){const t=this._bufferService.buffer;if(void 0===e.id){const i=t.addMarker(t.ybase+t.y),s={data:e,id:this._nextId++,lines:[i]};return i.onDispose((()=>this._removeMarkerFromLink(s,i))),this._dataByLinkId.set(s.id,s),s.id}const i=e,s=this._getEntryIdKey(i),r=this._entriesWithId.get(s);if(r)return this.addLineToLink(r.id,t.ybase+t.y),r.id;const n=t.addMarker(t.ybase+t.y),o={id:this._nextId++,key:this._getEntryIdKey(i),data:i,lines:[n]};return n.onDispose((()=>this._removeMarkerFromLink(o,n))),this._entriesWithId.set(o.key,o),this._dataByLinkId.set(o.id,o),o.id}addLineToLink(e,t){const i=this._dataByLinkId.get(e);if(i&&i.lines.every((e=>e.line!==t))){const e=this._bufferService.buffer.addMarker(t);i.lines.push(e),e.onDispose((()=>this._removeMarkerFromLink(i,e)))}}getLinkData(e){return this._dataByLinkId.get(e)?.data}_getEntryIdKey(e){return`${e.id};;${e.uri}`}_removeMarkerFromLink(e,t){const i=e.lines.indexOf(t);-1!==i&&(e.lines.splice(i,1),0===e.lines.length&&(void 0!==e.data.id&&this._entriesWithId.delete(e.key),this._dataByLinkId.delete(e.id)))}};t.OscLinkService=o=s([r(0,n.IBufferService)],o)},8343:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.createDecorator=t.getServiceDependencies=t.serviceRegistry=void 0;const i="di$target",s="di$dependencies";t.serviceRegistry=new Map,t.getServiceDependencies=function(e){return e[s]||[]},t.createDecorator=function(e){if(t.serviceRegistry.has(e))return t.serviceRegistry.get(e);const r=function(e,t,n){if(3!==arguments.length)throw new Error("@IServiceName-decorator can only be used to decorate a parameter");!function(e,t,r){t[i]===t?t[s].push({id:e,index:r}):(t[s]=[{id:e,index:r}],t[i]=t)}(r,e,n)};return r.toString=()=>e,t.serviceRegistry.set(e,r),r}},2585:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.IDecorationService=t.IUnicodeService=t.IOscLinkService=t.IOptionsService=t.ILogService=t.LogLevelEnum=t.IInstantiationService=t.ICharsetService=t.ICoreService=t.ICoreMouseService=t.IBufferService=void 0;const s=i(8343);var r;t.IBufferService=(0,s.createDecorator)("BufferService"),t.ICoreMouseService=(0,s.createDecorator)("CoreMouseService"),t.ICoreService=(0,s.createDecorator)("CoreService"),t.ICharsetService=(0,s.createDecorator)("CharsetService"),t.IInstantiationService=(0,s.createDecorator)("InstantiationService"),function(e){e[e.TRACE=0]="TRACE",e[e.DEBUG=1]="DEBUG",e[e.INFO=2]="INFO",e[e.WARN=3]="WARN",e[e.ERROR=4]="ERROR",e[e.OFF=5]="OFF"}(r||(t.LogLevelEnum=r={})),t.ILogService=(0,s.createDecorator)("LogService"),t.IOptionsService=(0,s.createDecorator)("OptionsService"),t.IOscLinkService=(0,s.createDecorator)("OscLinkService"),t.IUnicodeService=(0,s.createDecorator)("UnicodeService"),t.IDecorationService=(0,s.createDecorator)("DecorationService")},1480:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.UnicodeService=void 0;const s=i(8460),r=i(225);class n{static extractShouldJoin(e){return 0!=(1&e)}static extractWidth(e){return e>>1&3}static extractCharKind(e){return e>>3}static createPropertyValue(e,t,i=!1){return(16777215&e)<<3|(3&t)<<1|(i?1:0)}constructor(){this._providers=Object.create(null),this._active="",this._onChange=new s.EventEmitter,this.onChange=this._onChange.event;const e=new r.UnicodeV6;this.register(e),this._active=e.version,this._activeProvider=e}dispose(){this._onChange.dispose()}get versions(){return Object.keys(this._providers)}get activeVersion(){return this._active}set activeVersion(e){if(!this._providers[e])throw new Error(`unknown Unicode version "${e}"`);this._active=e,this._activeProvider=this._providers[e],this._onChange.fire(e)}register(e){this._providers[e.version]=e}wcwidth(e){return this._activeProvider.wcwidth(e)}getStringCellWidth(e){let t=0,i=0;const s=e.length;for(let r=0;r=s)return t+this.wcwidth(o);const i=e.charCodeAt(r);56320<=i&&i<=57343?o=1024*(o-55296)+i-56320+65536:t+=this.wcwidth(i)}const a=this.charProperties(o,i);let h=n.extractWidth(a);n.extractShouldJoin(a)&&(h-=n.extractWidth(i)),t+=h,i=a}return t}charProperties(e,t){return this._activeProvider.charProperties(e,t)}}t.UnicodeService=n}},t={};function i(s){var r=t[s];if(void 0!==r)return r.exports;var n=t[s]={exports:{}};return e[s].call(n.exports,n,n.exports,i),n.exports}var s={};return(()=>{var e=s;Object.defineProperty(e,"__esModule",{value:!0}),e.Terminal=void 0;const t=i(9042),r=i(3236),n=i(844),o=i(5741),a=i(8285),h=i(7975),c=i(7090),l=["cols","rows"];class d extends n.Disposable{constructor(e){super(),this._core=this.register(new r.Terminal(e)),this._addonManager=this.register(new o.AddonManager),this._publicOptions={...this._core.options};const t=e=>this._core.options[e],i=(e,t)=>{this._checkReadonlyOptions(e),this._core.options[e]=t};for(const e in this._core.options){const s={get:t.bind(this,e),set:i.bind(this,e)};Object.defineProperty(this._publicOptions,e,s)}}_checkReadonlyOptions(e){if(l.includes(e))throw new Error(`Option "${e}" can only be set in the constructor`)}_checkProposedApi(){if(!this._core.optionsService.rawOptions.allowProposedApi)throw new Error("You must set the allowProposedApi option to true to use proposed API")}get onBell(){return this._core.onBell}get onBinary(){return this._core.onBinary}get onCursorMove(){return this._core.onCursorMove}get onData(){return this._core.onData}get onKey(){return this._core.onKey}get onLineFeed(){return this._core.onLineFeed}get onRender(){return this._core.onRender}get onResize(){return this._core.onResize}get onScroll(){return this._core.onScroll}get onSelectionChange(){return this._core.onSelectionChange}get onTitleChange(){return this._core.onTitleChange}get onWriteParsed(){return this._core.onWriteParsed}get element(){return this._core.element}get parser(){return this._parser||(this._parser=new h.ParserApi(this._core)),this._parser}get unicode(){return this._checkProposedApi(),new c.UnicodeApi(this._core)}get textarea(){return this._core.textarea}get rows(){return this._core.rows}get cols(){return this._core.cols}get buffer(){return this._buffer||(this._buffer=this.register(new a.BufferNamespaceApi(this._core))),this._buffer}get markers(){return this._checkProposedApi(),this._core.markers}get modes(){const e=this._core.coreService.decPrivateModes;let t="none";switch(this._core.coreMouseService.activeProtocol){case"X10":t="x10";break;case"VT200":t="vt200";break;case"DRAG":t="drag";break;case"ANY":t="any"}return{applicationCursorKeysMode:e.applicationCursorKeys,applicationKeypadMode:e.applicationKeypad,bracketedPasteMode:e.bracketedPasteMode,insertMode:this._core.coreService.modes.insertMode,mouseTrackingMode:t,originMode:e.origin,reverseWraparoundMode:e.reverseWraparound,sendFocusMode:e.sendFocus,wraparoundMode:e.wraparound}}get options(){return this._publicOptions}set options(e){for(const t in e)this._publicOptions[t]=e[t]}blur(){this._core.blur()}focus(){this._core.focus()}input(e,t=!0){this._core.input(e,t)}resize(e,t){this._verifyIntegers(e,t),this._core.resize(e,t)}open(e){this._core.open(e)}attachCustomKeyEventHandler(e){this._core.attachCustomKeyEventHandler(e)}attachCustomWheelEventHandler(e){this._core.attachCustomWheelEventHandler(e)}registerLinkProvider(e){return this._core.registerLinkProvider(e)}registerCharacterJoiner(e){return this._checkProposedApi(),this._core.registerCharacterJoiner(e)}deregisterCharacterJoiner(e){this._checkProposedApi(),this._core.deregisterCharacterJoiner(e)}registerMarker(e=0){return this._verifyIntegers(e),this._core.registerMarker(e)}registerDecoration(e){return this._checkProposedApi(),this._verifyPositiveIntegers(e.x??0,e.width??0,e.height??0),this._core.registerDecoration(e)}hasSelection(){return this._core.hasSelection()}select(e,t,i){this._verifyIntegers(e,t,i),this._core.select(e,t,i)}getSelection(){return this._core.getSelection()}getSelectionPosition(){return this._core.getSelectionPosition()}clearSelection(){this._core.clearSelection()}selectAll(){this._core.selectAll()}selectLines(e,t){this._verifyIntegers(e,t),this._core.selectLines(e,t)}dispose(){super.dispose()}scrollLines(e){this._verifyIntegers(e),this._core.scrollLines(e)}scrollPages(e){this._verifyIntegers(e),this._core.scrollPages(e)}scrollToTop(){this._core.scrollToTop()}scrollToBottom(){this._core.scrollToBottom()}scrollToLine(e){this._verifyIntegers(e),this._core.scrollToLine(e)}clear(){this._core.clear()}write(e,t){this._core.write(e,t)}writeln(e,t){this._core.write(e),this._core.write("\r\n",t)}paste(e){this._core.paste(e)}refresh(e,t){this._verifyIntegers(e,t),this._core.refresh(e,t)}reset(){this._core.reset()}clearTextureAtlas(){this._core.clearTextureAtlas()}loadAddon(e){this._addonManager.loadAddon(this,e)}static get strings(){return t}_verifyIntegers(...e){for(const t of e)if(t===1/0||isNaN(t)||t%1!=0)throw new Error("This API only accepts integers")}_verifyPositiveIntegers(...e){for(const t of e)if(t&&(t===1/0||isNaN(t)||t%1!=0||t<0))throw new Error("This API only accepts positive integers")}}e.Terminal=d})(),s})())); -//# sourceMappingURL=xterm.js.map \ No newline at end of file diff --git a/examples/webpanel/webpanel_main.c b/examples/webpanel/webpanel_main.c deleted file mode 100644 index 7831808f3..000000000 --- a/examples/webpanel/webpanel_main.c +++ /dev/null @@ -1,207 +0,0 @@ -/**************************************************************************** - * apps/examples/webpanel/webpanel_main.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "netutils/thttpd.h" -#include "fsutils/mksmartfs.h" -#include "ws_terminal.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define SECTORSIZE 64 -#define NSECTORS(b) (((b) + SECTORSIZE - 1) / SECTORSIZE) -#define WEBPANEL_RAMDISK_MINOR 2 -#define ROMFSDEV "/dev/ram2" - -#define ROMFS_MOUNTPT "/data/tmp_romfs" -#define BINFS_MOUNTPT "/data/tmp_binfs" -#define BINFS_PREFIX "cgi-bin" -#define UNIONFS_MOUNTPT CONFIG_THTTPD_PATH - -#define SMARTFS_DEV "/dev/smart0" -#define SMARTFS_MNT "/mnt" - -/**************************************************************************** - * External References - ****************************************************************************/ - -extern const unsigned char webpanel_romfs_img[]; -extern const unsigned int webpanel_romfs_img_len; - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: main - * - * Description: - * Initialize WebPanel filesystem mounts, start the websocket daemon, - * then launch the THTTPD server. - * - * Input Parameters: - * argc - Number of arguments. - * argv - Argument vector. - * - * Returned Value: - * EXIT_SUCCESS on success; EXIT_FAILURE on setup error. - * - ****************************************************************************/ - -int main(int argc, FAR char *argv[]) -{ - struct boardioc_romdisk_s desc; - char *thttpd_argv = "thttpd"; - struct statfs check_fs; - struct statfs sfs; - int ret; - - /* Prevent duplicate startup (e.g. rcS runs again in child NSH) */ - - if (statfs(UNIONFS_MOUNTPT, &check_fs) == 0) - { - return 0; - } - - /* Register the ROMFS image as a ramdisk */ - - printf("WebPanel: Registering ROMFS ramdisk\n"); - - desc.minor = WEBPANEL_RAMDISK_MINOR; - desc.nsectors = NSECTORS(webpanel_romfs_img_len); - desc.sectsize = SECTORSIZE; - desc.image = (FAR uint8_t *)webpanel_romfs_img; - - ret = boardctl(BOARDIOC_ROMDISK, (uintptr_t)&desc); - if (ret < 0 && errno != EEXIST) - { - printf("WebPanel: ERROR romdisk_register failed: %d\n", ret); - return EXIT_FAILURE; - } - - /* Create mount point directories */ - - mkdir("/data", 0777); - mkdir(ROMFS_MOUNTPT, 0777); - mkdir(BINFS_MOUNTPT, 0777); - - /* Mount ROMFS at temp location */ - - printf("WebPanel: Mounting ROMFS at %s\n", ROMFS_MOUNTPT); - - ret = mount(ROMFSDEV, ROMFS_MOUNTPT, "romfs", MS_RDONLY, NULL); - if (ret < 0 && errno != EBUSY) - { - printf("WebPanel: ERROR mount ROMFS failed: %d\n", errno); - return EXIT_FAILURE; - } - - /* Mount BINFS at temp location (exposes built-in apps as CGI) */ - - printf("WebPanel: Mounting BINFS at %s\n", BINFS_MOUNTPT); - - ret = mount(NULL, BINFS_MOUNTPT, "binfs", MS_RDONLY, NULL); - if (ret < 0 && errno != EBUSY) - { - printf("WebPanel: ERROR mount BINFS failed: %d\n", errno); - return EXIT_FAILURE; - } - - /* Create UNIONFS: ROMFS content + BINFS under cgi-bin/ prefix */ - - printf("WebPanel: Creating UNIONFS at %s\n", UNIONFS_MOUNTPT); - - ret = mount(NULL, UNIONFS_MOUNTPT, "unionfs", 0, - "fspath1=" ROMFS_MOUNTPT ",prefix1=" - ",fspath2=" BINFS_MOUNTPT ",prefix2=" BINFS_PREFIX); - if (ret < 0 && errno != EBUSY) - { - printf("WebPanel: ERROR mount UNIONFS failed: %d\n", errno); - return EXIT_FAILURE; - } - - /* Ensure SmartFS is formatted and mounted at /mnt for user files */ - - if (statfs(SMARTFS_MNT, &sfs) != 0) - { - printf("WebPanel: SmartFS not mounted, formatting %s\n", - SMARTFS_DEV); - ret = mksmartfs(SMARTFS_DEV, 0); - if (ret < 0) - { - printf("WebPanel: WARNING mksmartfs failed: %d\n", errno); - } - else - { - mkdir(SMARTFS_MNT, 0777); - ret = mount(SMARTFS_DEV, SMARTFS_MNT, "smartfs", 0, NULL); - if (ret < 0) - { - printf("WebPanel: WARNING mount SmartFS failed: %d\n", - errno); - } - else - { - printf("WebPanel: SmartFS mounted at %s\n", SMARTFS_MNT); - } - } - } - else - { - printf("WebPanel: SmartFS already mounted at %s\n", SMARTFS_MNT); - } - - /* Start WebSocket terminal server */ - - ret = ws_terminal_start(); - if (ret < 0) - { - printf("WebPanel: WARNING WebSocket server failed to start\n"); - } - - /* Start THTTPD */ - - printf("WebPanel: Starting THTTPD (serving from %s)\n", UNIONFS_MOUNTPT); - fflush(stdout); - - thttpd_main(1, &thttpd_argv); - - printf("WebPanel: THTTPD terminated\n"); - return 0; -} diff --git a/examples/webpanel/ws_terminal.c b/examples/webpanel/ws_terminal.c deleted file mode 100644 index 7db8d7392..000000000 --- a/examples/webpanel/ws_terminal.c +++ /dev/null @@ -1,350 +0,0 @@ -/**************************************************************************** - * apps/examples/webpanel/ws_terminal.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "ws_terminal.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#ifndef CONFIG_EXAMPLES_WEBPANEL_WS_PORT -# define CONFIG_EXAMPLES_WEBPANEL_WS_PORT 8080 -#endif - -#ifndef CONFIG_EXAMPLES_WEBPANEL_WS_PRIORITY -# define CONFIG_EXAMPLES_WEBPANEL_WS_PRIORITY 100 -#endif - -#ifndef CONFIG_EXAMPLES_WEBPANEL_WS_STACKSIZE -# define CONFIG_EXAMPLES_WEBPANEL_WS_STACKSIZE 8192 -#endif - -#ifndef CONFIG_EXAMPLES_WEBPANEL_WS_NSH_STACKSIZE -# define CONFIG_EXAMPLES_WEBPANEL_WS_NSH_STACKSIZE 4096 -#endif - -#define WS_IOBUF_SIZE 512 - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -struct ws_session -{ - int masterfd; - pid_t nshpid; - unsigned char txbuf[LWS_PRE + WS_IOBUF_SIZE]; - size_t txlen; -}; - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -static int ws_spawn_nsh(int masterfd, pid_t *pid); -static int ws_callback(struct lws *wsi, - enum lws_callback_reasons reason, - void *user, void *in, size_t len); -static int ws_daemon(int argc, FAR char *argv[]); - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static const struct lws_protocols g_protocols[] = -{ - { - "", - ws_callback, - sizeof(struct ws_session), - WS_IOBUF_SIZE, - 0, NULL, 0 - }, - LWS_PROTOCOL_LIST_TERM -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: ws_spawn_nsh - * - * Description: - * Spawn an NSH instance attached to a PTY slave. - * - * Input Parameters: - * masterfd - PTY master descriptor. - * pid - Location to receive spawned task PID. - * - * Returned Value: - * Zero on success; negated errno on failure. - * - ****************************************************************************/ - -static int ws_spawn_nsh(int masterfd, pid_t *pid) -{ - char slavepath[32]; - FAR char *nshargv[] = - { - "nsh", NULL - }; - - posix_spawn_file_actions_t actions; - posix_spawnattr_t attr; - struct sched_param param; - int ret; - - ret = grantpt(masterfd); - if (ret < 0) - { - return ret; - } - - ret = unlockpt(masterfd); - if (ret < 0) - { - return ret; - } - - ret = ptsname_r(masterfd, slavepath, sizeof(slavepath)); - if (ret < 0) - { - return ret; - } - - posix_spawn_file_actions_init(&actions); - posix_spawn_file_actions_addopen(&actions, 0, slavepath, - O_RDWR, 0); - posix_spawn_file_actions_adddup2(&actions, 0, 1); - posix_spawn_file_actions_adddup2(&actions, 0, 2); - - posix_spawnattr_init(&attr); - param.sched_priority = CONFIG_EXAMPLES_WEBPANEL_WS_PRIORITY; - posix_spawnattr_setflags(&attr, POSIX_SPAWN_SETSCHEDPARAM); - posix_spawnattr_setschedparam(&attr, ¶m); - posix_spawnattr_setstacksize(&attr, - CONFIG_EXAMPLES_WEBPANEL_WS_NSH_STACKSIZE); - - ret = posix_spawn(pid, "nsh", &actions, &attr, nshargv, NULL); - - posix_spawn_file_actions_destroy(&actions); - posix_spawnattr_destroy(&attr); - - return ret == 0 ? 0 : -ret; -} - -/**************************************************************************** - * Name: ws_callback - * - * Description: - * libwebsockets protocol callback for the NSH terminal relay. - * - ****************************************************************************/ - -static int ws_callback(struct lws *wsi, - enum lws_callback_reasons reason, - void *user, void *in, size_t len) -{ - struct ws_session *sess = (struct ws_session *)user; - ssize_t n; - - switch (reason) - { - case LWS_CALLBACK_ESTABLISHED: - sess->masterfd = open("/dev/ptmx", O_RDWR | O_NOCTTY); - if (sess->masterfd < 0) - { - printf("ws_terminal: failed to open PTY\n"); - return -1; - } - - sess->nshpid = -1; - if (ws_spawn_nsh(sess->masterfd, &sess->nshpid) < 0) - { - printf("ws_terminal: failed to spawn NSH\n"); - close(sess->masterfd); - sess->masterfd = -1; - return -1; - } - - /* Make PTY master non-blocking for polling */ - - fcntl(sess->masterfd, F_SETFL, - fcntl(sess->masterfd, F_GETFL) | O_NONBLOCK); - - sess->txlen = 0; - printf("ws_terminal: client connected\n"); - - lws_set_timer_usecs(wsi, 50 * LWS_USEC_PER_SEC / 1000); - break; - - case LWS_CALLBACK_RECEIVE: - if (sess->masterfd >= 0 && len > 0) - { - write(sess->masterfd, in, len); - } - - break; - - case LWS_CALLBACK_SERVER_WRITEABLE: - if (sess->masterfd < 0) - { - break; - } - - n = read(sess->masterfd, - &sess->txbuf[LWS_PRE], - WS_IOBUF_SIZE); - if (n > 0) - { - lws_write(wsi, &sess->txbuf[LWS_PRE], n, LWS_WRITE_TEXT); - lws_set_timer_usecs(wsi, 10 * LWS_USEC_PER_SEC / 1000); - } - else - { - lws_set_timer_usecs(wsi, 50 * LWS_USEC_PER_SEC / 1000); - } - - break; - - case LWS_CALLBACK_TIMER: - lws_callback_on_writable(wsi); - break; - - case LWS_CALLBACK_CLOSED: - printf("ws_terminal: client disconnected\n"); - if (sess->nshpid > 0) - { - task_delete(sess->nshpid); - sess->nshpid = -1; - } - - if (sess->masterfd >= 0) - { - close(sess->masterfd); - sess->masterfd = -1; - } - - break; - - default: - break; - } - - return 0; -} - -/**************************************************************************** - * Name: ws_daemon - * - * Description: - * WebSocket terminal daemon using libwebsockets. - * - ****************************************************************************/ - -static int ws_daemon(int argc, FAR char *argv[]) -{ - struct lws_context_creation_info info; - struct lws_context *context; - int n; - - lws_set_log_level(LLL_ERR | LLL_WARN, NULL); - - memset(&info, 0, sizeof(info)); - info.port = CONFIG_EXAMPLES_WEBPANEL_WS_PORT; - info.protocols = g_protocols; - info.vhost_name = "localhost"; - info.options = 0; - - context = lws_create_context(&info); - if (context == NULL) - { - printf("ws_terminal: ERROR creating lws context\n"); - return EXIT_FAILURE; - } - - printf("WebPanel: WebSocket terminal listening on port %d\n", - CONFIG_EXAMPLES_WEBPANEL_WS_PORT); - - n = 0; - while (n >= 0) - { - n = lws_service(context, 100); - } - - lws_context_destroy(context); - return EXIT_FAILURE; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: ws_terminal_start - * - * Description: - * Start the websocket terminal daemon task. - * - * Input Parameters: - * None. - * - * Returned Value: - * Task PID on success; negated errno value on failure. - * - ****************************************************************************/ - -int ws_terminal_start(void) -{ - int pid; - - pid = task_create("ws_daemon", - CONFIG_EXAMPLES_WEBPANEL_WS_PRIORITY, - CONFIG_EXAMPLES_WEBPANEL_WS_STACKSIZE, - ws_daemon, NULL); - if (pid < 0) - { - printf("WebPanel: ERROR failed to start WebSocket server: %d\n", - errno); - return -errno; - } - - return pid; -} diff --git a/examples/webpanel/ws_terminal.h b/examples/webpanel/ws_terminal.h deleted file mode 100644 index 91cc637d9..000000000 --- a/examples/webpanel/ws_terminal.h +++ /dev/null @@ -1,63 +0,0 @@ -/**************************************************************************** - * apps/examples/webpanel/ws_terminal.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __APPS_EXAMPLES_WEBPANEL_WS_TERMINAL_H -#define __APPS_EXAMPLES_WEBPANEL_WS_TERMINAL_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#ifdef __cplusplus -#define EXTERN extern "C" -extern "C" -{ -#else -#define EXTERN extern -#endif - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Name: ws_terminal_start - * - * Description: - * Start the websocket terminal daemon task. - * - * Input Parameters: - * None. - * - * Returned Value: - * Task PID on success; negated errno value on failure. - * - ****************************************************************************/ - -int ws_terminal_start(void); - -#undef EXTERN -#ifdef __cplusplus -} -#endif - -#endif /* __APPS_EXAMPLES_WEBPANEL_WS_TERMINAL_H */ diff --git a/examples/webserver/CMakeLists.txt b/examples/webserver/CMakeLists.txt deleted file mode 100644 index 7020d25bf..000000000 --- a/examples/webserver/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -# ############################################################################## -# apps/examples/webserver/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_WEBSERVER) - nuttx_add_application(NAME webserver) -endif() diff --git a/examples/webserver/Make.defs b/examples/webserver/Make.defs index 6150f4262..b4eee076c 100644 --- a/examples/webserver/Make.defs +++ b/examples/webserver/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/webserver/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/webserver/Makefile b/examples/webserver/Makefile index d07ef23de..41bc98421 100644 --- a/examples/webserver/Makefile +++ b/examples/webserver/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/webserver/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/webserver/cgi.c b/examples/webserver/cgi.c index 2b113d5b0..38f40668a 100644 --- a/examples/webserver/cgi.c +++ b/examples/webserver/cgi.c @@ -1,9 +1,10 @@ /**************************************************************************** * apps/examples/webserver/cgi.c + * Web server script interface + * Author: Adam Dunkels * - * SPDX-License-Identifier: BSD-3-Clause - * SPDX-FileCopyrightText: 2001-2006, Adam Dunkels. All rights reserved. - * SPDX-FileContributor: Adam Dunkels + * Copyright (c) 2001-2006, Adam Dunkels. + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -60,10 +61,6 @@ HTTPD_CGI_CALL(file, "file-stats", file_stats); HTTPD_CGI_CALL(net, "net-stats", net_stats); #endif -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Name: net_stats ****************************************************************************/ @@ -81,8 +78,7 @@ static void net_stats(struct httpd_state *pstate, char *ptr) for (i = 0; i < sizeof(g_netstats) / sizeof(net_stats_t); i++) { - snprintf(buffer, sizeof(buffer), "%5u\n", - ((net_stats_t *)&g_netstats)[i]); + snprintf(buffer, 16, "%5u\n", ((net_stats_t *)&g_netstats)[i]); httpd_send_datachunk(pstate->ht_sockfd, buffer, strlen(buffer), chunked_http_tx); } @@ -104,21 +100,17 @@ static void file_stats(struct httpd_state *pstate, char *ptr) chunked_http_tx = pstate->ht_chunked; #endif - snprintf(buffer, sizeof(buffer), "%5u", httpd_fs_count(pcount)); + snprintf(buffer, 16, "%5u", httpd_fs_count(pcount)); httpd_send_datachunk(pstate->ht_sockfd, buffer, strlen(buffer), chunked_http_tx); } #endif -/**************************************************************************** - * Public Functions - ****************************************************************************/ - /**************************************************************************** * Name: cgi_register ****************************************************************************/ -void cgi_register(void) +void cgi_register() { #ifdef CONFIG_NETUTILS_HTTPDFILESTATS httpd_cgi_register(&file); diff --git a/examples/webserver/cgi.h b/examples/webserver/cgi.h index d19887821..1f0dae9ed 100644 --- a/examples/webserver/cgi.h +++ b/examples/webserver/cgi.h @@ -1,9 +1,10 @@ /**************************************************************************** * apps/examples/webserver/cgi.h + * Web server script interface header file + * Author: Adam Dunkels * - * SPDX-License-Identifier: BSD-3-Clause - * SPDX-FileCopyrightText: 2001-2006, Adam Dunkels. All rights reserved. - * SPDX-FileContributor: Adam Dunkels + * Copyright (c) 2001, Adam Dunkels. + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/examples/webserver/webserver_main.c b/examples/webserver/webserver_main.c index 8309f59c8..1c1856774 100644 --- a/examples/webserver/webserver_main.c +++ b/examples/webserver/webserver_main.c @@ -51,11 +51,12 @@ #include #include #include -#include +#include #include #include +#include #include "netutils/netlib.h" #ifdef CONFIG_EXAMPLES_WEBSERVER_DHCPC @@ -69,7 +70,7 @@ /* DHCPC may be used in conjunction with any other feature (or not) */ #ifdef CONFIG_EXAMPLES_WEBSERVER_DHCPC -# include "netutils/dhcpc.h" +# include "netutils/dhcpc.h" #endif /* Include uIP webserver definitions */ @@ -82,10 +83,6 @@ * Pre-processor Definitions ****************************************************************************/ -#ifndef CONFIG_NETUTILS_WEBSERVER -# error "CONFIG_NETUTILS_WEBSERVER is required to get WebServer working" -#endif - /**************************************************************************** * Private Data ****************************************************************************/ @@ -110,7 +107,7 @@ int main(int argc, FAR char *argv[]) uint8_t mac[IFHWADDRLEN]; #endif #ifdef CONFIG_EXAMPLES_WEBSERVER_DHCPC - FAR void *handle; + void *handle; #endif /* Many embedded network interfaces must have a software assigned MAC */ @@ -168,9 +165,6 @@ int main(int argc, FAR char *argv[]) if (handle) { struct dhcpc_state ds; - char inetaddr[INET_ADDRSTRLEN]; - int ret; - dhcpc_request(handle, &ds); netlib_set_ipv4addr("eth0", &ds.ipaddr); @@ -184,21 +178,13 @@ int main(int argc, FAR char *argv[]) netlib_set_dripv4addr("eth0", &ds.default_router); } - for (int i = 0; i < ds.num_dnsaddr; i++) + if (ds.dnsaddr.s_addr != 0) { - if (ds.dnsaddr[i].s_addr != 0) - { - ret = netlib_set_ipv4dnsaddr(&ds.dnsaddr[i]); - if (ret < 0) - { - nerr("ERROR: Set DNS server %d:%s address failed: %d\n", - i, inet_ntoa(ds.dnsaddr[i]), ret); - } - } + netlib_set_ipv4dnsaddr(&ds.dnsaddr); } dhcpc_close(handle); - printf("IP: %s\n", inet_ntoa_r(ds.ipaddr, inetaddr, sizeof(inetaddr))); + printf("IP: %s\n", inet_ntoa(ds.ipaddr)); } #endif #endif /* CONFIG_NSH_NETINIT */ diff --git a/examples/wget/CMakeLists.txt b/examples/wget/CMakeLists.txt deleted file mode 100644 index f62ebb355..000000000 --- a/examples/wget/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# ############################################################################## -# apps/examples/wget/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_WGET) - nuttx_add_application( - NAME - wget - STACKSIZE - ${CONFIG_EXAMPLES_WGET_STACKSIZ} - MODULE - ${CONFIG_EXAMPLES_WGET} - SRCS - wget_main.c) -endif() diff --git a/examples/wget/Make.defs b/examples/wget/Make.defs index ffdb66179..7ee796a10 100644 --- a/examples/wget/Make.defs +++ b/examples/wget/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/wget/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/wget/Makefile b/examples/wget/Makefile index 19309dfcb..4cb01370c 100644 --- a/examples/wget/Makefile +++ b/examples/wget/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/wget/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/wget/wget_main.c b/examples/wget/wget_main.c index 53a970c6e..d8c8c29c8 100644 --- a/examples/wget/wget_main.c +++ b/examples/wget/wget_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/wget/wget_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/examples/wgetjson/CMakeLists.txt b/examples/wgetjson/CMakeLists.txt deleted file mode 100644 index e131d013f..000000000 --- a/examples/wgetjson/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# ############################################################################## -# apps/examples/wgetjson/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_WGETJSON) - nuttx_add_application( - NAME - wgetjson - STACKSIZE - ${CONFIG_DEFAULT_TASK_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_WGETJSON} - SRCS - wgetjson_main.c) -endif() diff --git a/examples/wgetjson/Make.defs b/examples/wgetjson/Make.defs index e3786b699..d0b2be3ce 100644 --- a/examples/wgetjson/Make.defs +++ b/examples/wgetjson/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/wgetjson/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/wgetjson/Makefile b/examples/wgetjson/Makefile index 5a87b9b77..a8f724532 100644 --- a/examples/wgetjson/Makefile +++ b/examples/wgetjson/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/wgetjson/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -22,11 +20,11 @@ include $(APPDIR)/Make.defs -# WGETJSON Example +# Hello, World! Example MAINSRC = wgetjson_main.c -# WGETJSON built-in application info +# Buttons built-in application info PROGNAME = wgetjson PRIORITY = SCHED_PRIORITY_DEFAULT diff --git a/examples/wgetjson/wgetjson_main.c b/examples/wgetjson/wgetjson_main.c index 5e2679a6b..6f7715341 100644 --- a/examples/wgetjson/wgetjson_main.c +++ b/examples/wgetjson/wgetjson_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/wgetjson/wgetjson_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -34,7 +32,7 @@ #include #include #include -#include +#include #include "netutils/netlib.h" #include "netutils/webclient.h" @@ -45,15 +43,15 @@ ****************************************************************************/ #ifndef CONFIG_EXAMPLES_WGETJSON_MAXSIZE -# define CONFIG_EXAMPLES_WGETJSON_MAXSIZE 1024 +# define CONFIG_EXAMPLES_WGETJSON_MAXSIZE 1024 #endif #ifndef CONFIG_EXAMPLES_WGETJSON_URL -# define CONFIG_EXAMPLES_WGETJSON_URL "http://10.0.0.1/wgetjson/json_cmd.php" +# define CONFIG_EXAMPLES_WGETJSON_URL "http://10.0.0.1/wgetjson/json_cmd.php" #endif #ifndef CONFIG_EXAMPLES_WGETPOST_URL -# define CONFIG_EXAMPLES_WGETPOST_URL "http://10.0.0.1/wgetjson/post_cmd.php" +# define CONFIG_EXAMPLES_WGETPOST_URL "http://10.0.0.1/wgetjson/post_cmd.php" #endif #define MULTI_POST_NDATA 3 @@ -110,14 +108,9 @@ static int wgetjson_callback(FAR char **buffer, int offset, int datend, return 0; } - if (g_json_buff == NULL) + if (!g_json_buff) { g_json_buff = malloc(len + 1); - if (g_json_buff == NULL) - { - return -ENOMEM; - } - memcpy(g_json_buff, &((*buffer)[offset]), len); g_json_buff[len] = 0; g_json_bufflen = len; @@ -256,14 +249,8 @@ static void wgetjson_json_item_scan(cJSON *item, const char *prefix) while (item) { const char *string = item->string ? item->string : "(null)"; - size_t len = strlen(prefix) + strlen(string) + 2; - newprefix = malloc(len); - if (newprefix == NULL) - { - return; - } - - snprintf(newprefix, len, "%s/%s", prefix, string); + newprefix = malloc(strlen(prefix) + strlen(string) + 2); + sprintf(newprefix, "%s/%s", prefix, string); dorecurse = wgetjson_json_item_callback(newprefix, item->type, item); if (item->child && dorecurse) @@ -380,11 +367,6 @@ int main(int argc, FAR char *argv[]) } buffer = malloc(buffer_len); - if (buffer == NULL) - { - return -ENOMEM; - } - wgetjson_json_release(); struct webclient_context ctx; @@ -403,12 +385,6 @@ int main(int argc, FAR char *argv[]) post_multi_values, MULTI_POST_NDATA); post_buff = malloc(post_buff_len); - if (post_buff == NULL) - { - ret = -ENOMEM; - goto out; - } - web_posts_str(post_buff, &post_buff_len, post_multi_names, post_multi_values, MULTI_POST_NDATA); } @@ -417,24 +393,21 @@ int main(int argc, FAR char *argv[]) post_buff_len = web_post_strlen(post_single_name, post_single_value); post_buff = malloc(post_buff_len); - if (post_buff == NULL) - { - ret = -ENOMEM; - goto out; - } - web_post_str(post_buff, &post_buff_len, post_single_name, post_single_value); } - const char *header = "Content-Type: " - "application/x-www-form-urlencoded"; - ctx.method = "POST"; - ctx.url = url; - ctx.headers = &header; - ctx.nheaders = 1; - webclient_set_static_body(&ctx, post_buff, strlen(post_buff)); - ret = webclient_perform(&ctx); + if (post_buff) + { + const char *header = "Content-Type: " + "application/x-www-form-urlencoded"; + ctx.method = "POST"; + ctx.url = url; + ctx.headers = &header; + ctx.nheaders = 1; + webclient_set_static_body(&ctx, post_buff, strlen(post_buff)); + ret = webclient_perform(&ctx); + } } else { @@ -463,7 +436,6 @@ int main(int argc, FAR char *argv[]) g_has_json = false; } -out: wgetjson_json_release(); free(buffer); if (post_buff) @@ -471,5 +443,5 @@ out: free(post_buff); } - return ret < 0 ? ret : 0; + return 0; } diff --git a/examples/wiegand/Kconfig b/examples/wiegand/Kconfig deleted file mode 100644 index 7617bda4a..000000000 --- a/examples/wiegand/Kconfig +++ /dev/null @@ -1,29 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config EXAMPLES_WIEGAND - tristate "Wiegand example" - default n - ---help--- - Enable the wiegand example - -if EXAMPLES_WIEGAND - -config EXAMPLES_WIEGAND_PROGNAME - string "Program name" - default "wiegand" - ---help--- - This is the name of the program that will be used when the NSH ELF - program is installed. - -config EXAMPLES_WIEGAND_PRIORITY - int "wiegand task priority" - default 100 - -config EXAMPLES_WIEGAND_STACKSIZE - int "wiegand stack size" - default DEFAULT_TASK_STACKSIZE - -endif diff --git a/examples/wiegand/Make.defs b/examples/wiegand/Make.defs deleted file mode 100644 index 3fc0ce9d1..000000000 --- a/examples/wiegand/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/examples/wiegand/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_EXAMPLES_WIEGAND),) -CONFIGURED_APPS += $(APPDIR)/examples/wiegand -endif diff --git a/examples/wiegand/Makefile b/examples/wiegand/Makefile deleted file mode 100644 index bc4c3ed8f..000000000 --- a/examples/wiegand/Makefile +++ /dev/null @@ -1,36 +0,0 @@ -############################################################################ -# apps/examples/wiegand/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -# wiegand built-in application info - -PROGNAME = $(CONFIG_EXAMPLES_WIEGAND_PROGNAME) -PRIORITY = $(CONFIG_EXAMPLES_WIEGAND_PRIORITY) -STACKSIZE = $(CONFIG_EXAMPLES_WIEGAND_STACKSIZE) -MODULE = $(CONFIG_EXAMPLES_WIEGAND) - -# wiegand Example - -MAINSRC = wiegand.c - -include $(APPDIR)/Application.mk diff --git a/examples/wiegand/wiegand.c b/examples/wiegand/wiegand.c deleted file mode 100644 index 8beee23da..000000000 --- a/examples/wiegand/wiegand.c +++ /dev/null @@ -1,79 +0,0 @@ -/**************************************************************************** - * apps/examples/wiegand/wiegand.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include -#include -#include - -#include - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Wiegand - ****************************************************************************/ - -int main(int argc, FAR char *argv[]) -{ - int fd; - int ret; - struct wiegand_data_s data; - - fd = open ("/dev/wiega0", O_RDONLY); - - if (fd < 0) - { - printf("Erro: Failed to open \n"); - return -1; - } - - printf("Wiegand app is running\n"); - - while (1) - { - ret = read(fd, &data, sizeof(data)); - if (ret > 0) - { - if (data.status == WIEGAND_SUCCESS) - { - printf("ABA Code: %d\n", data.aba_code); - printf("FC: %04x \n", data.facility_code); - printf("ID: %06x\n", data.id); - break; - } - } - - sleep(1); - } - - close (fd); - - return 0; -} diff --git a/examples/ws2812/CMakeLists.txt b/examples/ws2812/CMakeLists.txt deleted file mode 100644 index 8f6ad8904..000000000 --- a/examples/ws2812/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# ############################################################################## -# apps/examples/ws2812/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_WS2812) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_WS2812_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_WS2812_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_WS2812_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_WS2812} - SRCS - ws2812_main.c) -endif() diff --git a/examples/ws2812/Kconfig b/examples/ws2812/Kconfig deleted file mode 100644 index 67e6248b9..000000000 --- a/examples/ws2812/Kconfig +++ /dev/null @@ -1,34 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config EXAMPLES_WS2812 - tristate "ws2812 Demo Program" - default n - depends on WS2812 - ---help--- - Enable the ws2812 demo - -if EXAMPLES_WS2812 - -config EXAMPLES_WS2812_PROGNAME - string "Program Name" - default "ws2812" - ---help--- - This is the name of the program that will be used when the NSH ELF - program is installed. - -config EXAMPLES_WS2812_PRIORITY - int "Task Priority" - default 100 - -config EXAMPLES_WS2812_STACKSIZE - int "Stack Size" - default DEFAULT_TASK_STACKSIZE - -config EXAMPLES_WS2812_DEFAULT_DEV - string "Default Device" - default "/dev/leds0" - -endif diff --git a/examples/ws2812/Make.defs b/examples/ws2812/Make.defs deleted file mode 100644 index 888daea23..000000000 --- a/examples/ws2812/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/examples/ws2812/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_EXAMPLES_WS2812),) -CONFIGURED_APPS += $(APPDIR)/examples/ws2812 -endif diff --git a/examples/ws2812/Makefile b/examples/ws2812/Makefile deleted file mode 100644 index 0abf2c590..000000000 --- a/examples/ws2812/Makefile +++ /dev/null @@ -1,34 +0,0 @@ -############################################################################ -# apps/examples/ws2812/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -# MTD R/W buffer test Example - -PROGNAME = $(CONFIG_EXAMPLES_WS2812_PROGNAME) -PRIORITY = $(CONFIG_EXAMPLES_WS2812_PRIORITY) -STACKSIZE = $(CONFIG_EXAMPLES_WS2812_STACKSIZE) -MODULE = $(CONFIG_EXAMPLES_WS2812) - -MAINSRC = ws2812_main.c - -include $(APPDIR)/Application.mk diff --git a/examples/ws2812/ws2812_main.c b/examples/ws2812/ws2812_main.c deleted file mode 100644 index ebb16b575..000000000 --- a/examples/ws2812/ws2812_main.c +++ /dev/null @@ -1,317 +0,0 @@ -/**************************************************************************** - * apps/examples/ws2812/ws2812_main.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -struct neo_config_s -{ - FAR char *path; - int loops; - int leds; - int delay; -}; - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -struct neo_config_s config = -{ - NULL, /* path - default set in main */ - 4, /* loop - all colors 4 times */ - CONFIG_WS2812_LED_COUNT, /* leds - based on config */ - 20000 /* delay - (in ยตs) ~50Hz */ -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: help - ****************************************************************************/ - -static void help(FAR struct neo_config_s *conf) -{ - printf("Usage: ws2812 [OPTIONS]\n"); - - printf("\nArguments are \"sticky\". " - "For example, once the device path is\n"); - printf("specified, that path will be reused until it is changed.\n"); - - printf(" [-p path] selects the ws2812 device. " - "Default: %s Current: %s\n", - CONFIG_EXAMPLES_WS2812_DEFAULT_DEV, conf->path ? conf->path - : "NONE"); - - printf(" [-l leds] selects number of ws2812s in the chain. " - "Default: %d Current: %d\n", - CONFIG_WS2812_LED_COUNT, conf->leds); - - printf(" [-r repeat] selects the number change cycles. " - "Default: %d Current: %d\n", - 4, conf->loops); - - printf(" [-d delay] selects delay between updates. " - "Default: %d us Current: %d us\n", - 20000, conf->delay); -} - -/**************************************************************************** - * Name: set_devpath - ****************************************************************************/ - -static void set_devpath(FAR struct neo_config_s *conf, - FAR const char *devpath) -{ - /* Get rid of any old device path */ - - if (conf->path != NULL) - { - free(conf->path); - } - - /* Then set-up the new device path by copying the string */ - - conf->path = strdup(devpath); -} - -/**************************************************************************** - * Name: arg_string - ****************************************************************************/ - -static int arg_string(FAR char **arg, FAR char **value) -{ - FAR char *ptr = *arg; - - if (ptr[2] == '\0') - { - *value = arg[1]; - return 2; - } - else - { - *value = &ptr[2]; - return 1; - } -} - -/**************************************************************************** - * Name: arg_decimal - ****************************************************************************/ - -static int arg_decimal(FAR char **arg, FAR long *value) -{ - FAR char *string; - int ret; - - ret = arg_string(arg, &string); - *value = strtol(string, NULL, 10); - return ret; -} - -/**************************************************************************** - * Name: parse_args - ****************************************************************************/ - -static void parse_args(FAR struct neo_config_s *conf, - int argc, - FAR char **argv) -{ - FAR char *ptr; - FAR char *str; - long value; - int index; - int nargs; - - for (index = 1; index < argc; ) - { - ptr = argv[index]; - if (ptr[0] != '-') - { - fprintf(stderr, "Invalid options format: %s\n", ptr); - exit(1); - } - - switch (ptr[1]) - { - case 'l': - nargs = arg_decimal(&argv[index], &value); - if (value < 1 || value > INT_MAX) - { - fprintf(stderr, "Led count out of range: %ld\n", value); - exit(1); - } - - conf->leds = (uint32_t)value; - index += nargs; - break; - - case 'r': - nargs = arg_decimal(&argv[index], &value); - if (value < 1 || value > INT_MAX) - { - fprintf(stderr, "Repeat out of range: %ld\n", value); - exit(1); - } - - conf->loops = (uint32_t)value; - index += nargs; - break; - - case 'p': - nargs = arg_string(&argv[index], &str); - set_devpath(conf, str); - index += nargs; - break; - - case 'd': - nargs = arg_decimal(&argv[index], &value); - if (value < 1 || value > INT_MAX) - { - fprintf(stderr, "Delay out of range: %ld\n", value); - exit(1); - } - - conf->delay = (int)value; - index += nargs; - break; - - case 'h': - help(conf); - exit(0); - - default: - fprintf(stderr, "Unsupported option: %s\n", ptr); - help(conf); - exit(1); - } - } -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * ws2812_main - ****************************************************************************/ - -int main(int argc, FAR char *argv[]) -{ - FAR uint32_t *buffer; - FAR uint32_t *bp; - ssize_t result; - - if (config.path == NULL) - { - config.path = strdup(CONFIG_EXAMPLES_WS2812_DEFAULT_DEV); - } - - /* Parse the command line */ - - parse_args(&config, argc, argv); - - /* Run the display loop */ - - int fd = open(config.path, O_WRONLY); - if (fd < 0) - { - fprintf(stderr, - "ws2812_main: open %s failed: %d\n", - config.path, - errno); - goto errout; - } - - buffer = calloc(4, config.leds); - - if (buffer == NULL) - { - fprintf(stderr, "ws2812_main: buffer allocation failed: %d\n", errno); - goto errout; - } - - for (int i = 0; i < config.loops; ++i) - { - for (int j = 0; j < 256; ++j) - { - bp = buffer; - - for (int k = 0; k < config.leds; ++k) - { - *bp++ = ws2812_gamma_correct( - ws2812_hsv_to_rgb((j + k) & 0xff, - 0xff, - 0xff)); - } - - lseek(fd, 0, SEEK_SET); - - result = write(fd, buffer, 4 * config.leds); - if (result != 4 * config.leds) - { - fprintf(stderr, - "ws2812_main: write failed: %d %d\n", - result, - errno); - - goto errout_with_dev; - } - - usleep(config.delay); - } - } - - free(buffer); - close(fd); - fflush(stdout); - return OK; - -errout_with_dev: - close(fd); - -errout: - fflush(stdout); - return ERROR; -} diff --git a/examples/ws2812esp32rmt/CMakeLists.txt b/examples/ws2812esp32rmt/CMakeLists.txt deleted file mode 100644 index 4834b46b6..000000000 --- a/examples/ws2812esp32rmt/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# ############################################################################## -# apps/examples/ws2812esp32rmt/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_WS2812_ESP32_RMT) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_WS2812_ESP32_RMT_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_WS2812_ESP32_RMT_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_WS2812_ESP32_RMT_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_WS2812_ESP32_RMT} - SRCS - ws2812esp32rmt_main.c) -endif() diff --git a/examples/ws2812esp32rmt/Kconfig b/examples/ws2812esp32rmt/Kconfig deleted file mode 100644 index abfa97ddc..000000000 --- a/examples/ws2812esp32rmt/Kconfig +++ /dev/null @@ -1,30 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config EXAMPLES_WS2812_ESP32_RMT - tristate "ws2812 Demo Program using ESP32_RMT" - depends on ESP32_RMT - default n - ---help--- - Enable the ws2812 demo, using ESP32 RMT peripheral to generate the pulses - -if EXAMPLES_WS2812_ESP32_RMT - -config EXAMPLES_WS2812_ESP32_RMT_PROGNAME - string "Program Name" - default "ws2812esp32" - ---help--- - This is the name of the program that will be used when the NSH ELF - program is installed. - -config EXAMPLES_WS2812_ESP32_RMT_PRIORITY - int "Task Priority" - default 100 - -config EXAMPLES_WS2812_ESP32_RMT_STACKSIZE - int "Stack Size" - default DEFAULT_TASK_STACKSIZE - -endif diff --git a/examples/ws2812esp32rmt/Make.defs b/examples/ws2812esp32rmt/Make.defs deleted file mode 100644 index 6216a183d..000000000 --- a/examples/ws2812esp32rmt/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/examples/ws2812esp32rmt/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_EXAMPLES_WS2812_ESP32_RMT),) -CONFIGURED_APPS += $(APPDIR)/examples/ws2812esp32rmt -endif diff --git a/examples/ws2812esp32rmt/Makefile b/examples/ws2812esp32rmt/Makefile deleted file mode 100644 index 27da0eb28..000000000 --- a/examples/ws2812esp32rmt/Makefile +++ /dev/null @@ -1,34 +0,0 @@ -############################################################################ -# apps/examples/ws2812esp32rmt/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -# MTD R/W buffer test Example - -PROGNAME = $(CONFIG_EXAMPLES_WS2812_ESP32_RMT_PROGNAME) -PRIORITY = $(CONFIG_EXAMPLES_WS2812_ESP32_RMT_PRIORITY) -STACKSIZE = $(CONFIG_EXAMPLES_WS2812_ESP32_RMT_STACKSIZE) -MODULE = $(CONFIG_EXAMPLES_WS2812_ESP32_RMT) - -MAINSRC = ws2812esp32rmt_main.c - -include $(APPDIR)/Application.mk diff --git a/examples/ws2812esp32rmt/ws2812esp32rmt_main.c b/examples/ws2812esp32rmt/ws2812esp32rmt_main.c deleted file mode 100644 index 7eb8dd6fe..000000000 --- a/examples/ws2812esp32rmt/ws2812esp32rmt_main.c +++ /dev/null @@ -1,282 +0,0 @@ -/**************************************************************************** - * apps/examples/ws2812esp32rmt/ws2812esp32rmt_main.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define APB_PERIOD (12.5) - -#define T0H ((uint16_t)(350 / APB_PERIOD)) // ns -#define T0L ((uint16_t)(900 / APB_PERIOD)) // ns -#define T1H ((uint16_t)(900 / APB_PERIOD)) // ns -#define T1L ((uint16_t)(350 / APB_PERIOD)) // ns -#define RES ((uint16_t)(60000 / APB_PERIOD)) // ns - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -struct led_s - { - uint8_t r; - uint8_t g; - uint8_t b; - }; - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static int fd; -static uint32_t *rmt_buffer; -static uint32_t rmt_buffer_len_in_words; -static uint32_t leds_buffer_len_in_bytes; -static struct led_s *leds_buffer; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static uint32_t map_byte_to_words(uint8_t byte, uint32_t *dst) -{ - uint32_t ret = 0; - uint8_t mask = 0x80; - for (int i = 0; i < 8; i++) - { - uint8_t bit = byte&mask; - mask >>= 1; - uint32_t word; - if (bit) - { - word = (T1L << 16) | (0x8000 | T1H); - } - else - { - word = (T0L << 16) | (0x8000 | T0H); - } - - *dst = word; - dst++; - ret++; - } - - return ret; -} - -static int map_leds_to_words(struct led_s *leds, - uint32_t n_leds, - uint32_t *dst, - uint32_t dst_len_in_words - ) -{ - int ret = OK; - - if (!dst || !leds) - { - return -1; - } - - uint32_t required_words = n_leds * 3 * 8; - - if (required_words >= dst_len_in_words) - { - _err("Required %d words, but buffer has only:%d", - required_words, dst_len_in_words - ); - return -1; - } - - uint32_t dst_offset = 0; - for (uint32_t led_idx = 0; led_idx < n_leds; led_idx++) - { - dst_offset += map_byte_to_words(leds[led_idx].g, dst + dst_offset); - dst_offset += map_byte_to_words(leds[led_idx].r, dst + dst_offset); - dst_offset += map_byte_to_words(leds[led_idx].b, dst + dst_offset); - } - - return ret; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * ws2812esp32rmt_main - ****************************************************************************/ - -int main(int argc, FAR char *argv[]) -{ - if (argc < 2) - { - printf("usage: %s channel led_count\n", argv[0]); - exit(1); - } - - int ch_idx = atoi(argv[1]); - if (ch_idx >= 8) - { - printf("channel must be int the range 0~7\n"); - exit(1); - } - - uint32_t n_leds = atoi(argv[2]); - - char devname[50]; - snprintf(devname, sizeof(devname), "/dev/rmt%d", ch_idx); - fd = open(devname, O_WRONLY); - if (fd < 0) - { - fprintf(stderr, - "%s: open %s failed: %d\n", - argv[0], - devname, - errno); - goto errout_with_dev; - } - - _info("size of (struct led_s) is:%d", sizeof(struct led_s)); - - leds_buffer_len_in_bytes = sizeof(struct led_s)*n_leds; - leds_buffer = (struct led_s *)malloc(leds_buffer_len_in_bytes); - _info("leds:%d - leds_buffer %p len:%d\n", - n_leds, - leds_buffer, - leds_buffer_len_in_bytes - ); - - if (!leds_buffer) - { - _err("failure allocating %d bytes for LED buffer", - leds_buffer_len_in_bytes - ); - goto errout; - } - - rmt_buffer_len_in_words = (leds_buffer_len_in_bytes * 8 + 1); - rmt_buffer = (uint32_t *)malloc(rmt_buffer_len_in_words * 4); - _info("words:%d - rmt_buffer %p rmt_buffer_len_in_words:%d\n", - rmt_buffer_len_in_words, - rmt_buffer, - rmt_buffer_len_in_words - ); - - if (!rmt_buffer) - { - _err("failure allocating %d words for RMT word buffer", - rmt_buffer_len_in_words - ); - goto errout; - } - - int pos = 0; - int direction = 0; - - /* Run the display loop */ - - while (1) - { - int n_loops = 30; - for (int i = 0; i < n_loops; ++i) - { - for (int l = 0; l < n_leds; l++) - { - if (!direction) - leds_buffer[l].r = i; - else - leds_buffer[l].r = 30 - i; - - leds_buffer[l].g = 0x00; - leds_buffer[l].b = 0x00; - - if (l == pos) - { - leds_buffer[l].r = 0x00; - leds_buffer[l].g = 0xff; - leds_buffer[l].b = 0x00; - } - } - - if (pos++ >= n_leds) - pos = 0; - int ret; - ret = map_leds_to_words(leds_buffer, - n_leds, - rmt_buffer, - rmt_buffer_len_in_words - ); - - if (ret) - { - _err("error mapping leds to words"); - goto errout; - } - - ret = write(fd, rmt_buffer, rmt_buffer_len_in_words * 4); - - if (ret < 0) - { - _err("error writing to device, %d errno:%d", ret, errno); - goto errout_with_dev; - } - -/**************************************************************************** - * Must sleep so the WS2812 can understand the EOT - ****************************************************************************/ - - usleep(50000); - } - - direction = !direction; - } - - free(leds_buffer); - free(rmt_buffer); - close(fd); - fflush(stdout); - return OK; - -errout_with_dev: - close(fd); - -errout: - fflush(stdout); - return ERROR; -} diff --git a/examples/xbc_test/CMakeLists.txt b/examples/xbc_test/CMakeLists.txt deleted file mode 100644 index fac0a8c77..000000000 --- a/examples/xbc_test/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# ############################################################################## -# apps/examples/xbc_test/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_XBC_TEST) - nuttx_add_application( - NAME - ${CONFIG_EXAMPLES_XBC_TEST_PROGNAME} - PRIORITY - ${CONFIG_EXAMPLES_XBC_TEST_PRIORITY} - STACKSIZE - ${CONFIG_EXAMPLES_XBC_TEST_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_XBC_TEST} - SRCS - xbc_test_main.c) -endif() diff --git a/examples/xbc_test/Kconfig b/examples/xbc_test/Kconfig index d7b3d572a..99f99f7e4 100644 --- a/examples/xbc_test/Kconfig +++ b/examples/xbc_test/Kconfig @@ -6,8 +6,6 @@ config EXAMPLES_XBC_TEST tristate "XBox Controller Test example" default n - depends on USBHOST - depends on !USBHOST_INT_DISABLE ---help--- Enable the XBox Controller Test example diff --git a/examples/xbc_test/Make.defs b/examples/xbc_test/Make.defs index 5e94cf0b6..b0b6369fd 100644 --- a/examples/xbc_test/Make.defs +++ b/examples/xbc_test/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/xbc_test/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/xbc_test/Makefile b/examples/xbc_test/Makefile index 75032b942..ba74b42c0 100644 --- a/examples/xbc_test/Makefile +++ b/examples/xbc_test/Makefile @@ -1,7 +1,5 @@ ############################################################################ -# apps/examples/xbc_test/Makefile -# -# SPDX-License-Identifier: Apache-2.0 +# apps/examples/hello/Makefile # # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with @@ -29,7 +27,7 @@ PRIORITY = $(CONFIG_EXAMPLES_XBC_TEST_PRIORITY) STACKSIZE = $(CONFIG_EXAMPLES_XBC_TEST_STACKSIZE) MODULE = $(CONFIG_EXAMPLES_XBC_TEST) -# Xbc_Test Example +# Xbc_Test, World! Example MAINSRC = xbc_test_main.c diff --git a/examples/xbc_test/xbc_test_main.c b/examples/xbc_test/xbc_test_main.c index 28096c606..c8ce21083 100644 --- a/examples/xbc_test/xbc_test_main.c +++ b/examples/xbc_test/xbc_test_main.c @@ -1,11 +1,11 @@ /**************************************************************************** * apps/examples/xbc_test/xbc_test_main.c * - * SPDX-License-Identifier: BSD-3-Clause - * SPDX-FileCopyrightText: 2017 Brian Webb. All rights reserved. - * SPDX-FileCopyrightText: 2008, 2011-2012 Gregory Nutt. All rights reserved. - * SPDX-FileContributor: Gregory Nutt - * SPDX-FileContributor: Brian Webb + * Copyright (C) 2008, 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Copyright (C) 2017 Brian Webb. All rights reserved. + * Author: Brian Webb * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -53,6 +53,17 @@ /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ +/* Configuration ************************************************************/ + +/* Sanity checking */ + +#ifndef CONFIG_USBHOST +# error "CONFIG_USBHOST is not defined" +#endif + +#ifdef CONFIG_USBHOST_INT_DISABLE +# error "Interrupt endpoints are disabled (CONFIG_USBHOST_INT_DISABLE)" +#endif /* Provide some default values for other configuration settings */ @@ -78,7 +89,7 @@ int main(int argc, FAR char *argv[]) * controller test. */ - for (; ; ) + for (;;) { /* Open the controller device. Loop until the device is successfully * opened. @@ -111,33 +122,24 @@ int main(int argc, FAR char *argv[]) { /* On success, echo the buffer to stdout */ - printf("%zd bytes read\n", nbytes); - if (nbytes == sizeof(struct xbox_controller_buttonstate_s)) - { - struct xbox_controller_buttonstate_s *rpt = - (FAR struct xbox_controller_buttonstate_s *)buffer; - printf("guide: %d sync: %d start: %d back: %d - a: %d b: %d x: %d y: %d\n", - rpt->guide, rpt->sync, rpt->start, - rpt->back, rpt->a, rpt->b, rpt->x, rpt->y); - printf("dpad_u: %d d: %d l: %d r: %d bump_l: %d - r: %d stick_l: %d r: %d\n", - rpt->dpad_up, rpt->dpad_down, rpt->dpad_left, - rpt->dpad_right, rpt->bumper_left, - rpt->bumper_right, rpt->stick_click_left, - rpt->stick_click_right); - printf("stick_left_x: %d y: %d right_x: %d y: %d - trigger_l: %d r: %d\n", - rpt->stick_left_x, rpt->stick_left_y, - rpt->stick_right_x, rpt->stick_right_y, - rpt->trigger_left, rpt->trigger_right); - } - } + printf("%d bytes read\n", nbytes); + if (nbytes == sizeof(struct xbox_controller_buttonstate_s)) + { + struct xbox_controller_buttonstate_s *rpt = (struct xbox_controller_buttonstate_s*)buffer; + printf("guide: %d sync: %d start: %d back: %d a: %d b: %d x: %d y: %d\n", + rpt->guide, rpt->sync, rpt->start, rpt->back, rpt->a, rpt->b, rpt->x, rpt->y); + printf("dpad_u: %d d: %d l: %d r: %d bump_l: %d r: %d stick_l: %d r: %d\n", + rpt->dpad_up, rpt->dpad_down, rpt->dpad_left, rpt->dpad_right, + rpt->bumper_left, rpt->bumper_right, rpt->stick_click_left, rpt->stick_click_right); + printf("stick_left_x: %d y: %d right_x: %d y: %d trigger_l: %d r: %d\n", + rpt->stick_left_x, rpt->stick_left_y, rpt->stick_right_x, rpt->stick_right_y, + rpt->trigger_left, rpt->trigger_right); + } + } } while (nbytes > 0); - printf("Closing device %s: %zd\n", CONFIG_EXAMPLES_XBC_DEVNAME, - nbytes); + printf("Closing device %s: %d\n", CONFIG_EXAMPLES_XBC_DEVNAME, (int)nbytes); fflush(stdout); close(fd); break; diff --git a/examples/xedge_demo/Kconfig b/examples/xedge_demo/Kconfig deleted file mode 100644 index 183f18b28..000000000 --- a/examples/xedge_demo/Kconfig +++ /dev/null @@ -1,41 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config EXAMPLES_XEDGE_DEMO - tristate "Xedge IoT Toolkit Demo" - depends on NETUTILS_XEDGE && ALLOW_GPL_COMPONENTS && ENABLE_ALL_SIGNALS - default n - ---help--- - Simple demonstration of the Xedge IoT Toolkit library. - - This example shows how to integrate and use the Xedge library - in your NuttX application. Xedge provides a high-level development - environment for creating IoT and industrial device applications - using Lua scripting with access to HTTP(S), WebSockets, MQTT, - file system, and device I/O. - - Note: This example requires the NETUTILS_XEDGE library to be enabled. - -if EXAMPLES_XEDGE_DEMO - -config EXAMPLES_XEDGE_DEMO_PROGNAME - string "Program name" - default "xedge_demo" - ---help--- - This is the name of the ELF executable for the Xedge demo application in NSH. - -config EXAMPLES_XEDGE_DEMO_PRIORITY - int "Xedge demo task priority" - default 100 - ---help--- - Set the task priority for the Xedge demo application. - -config EXAMPLES_XEDGE_DEMO_STACKSIZE - int "Xedge demo stack size" - default 20000 - ---help--- - Set the stack size for the Xedge demo application. - -endif diff --git a/examples/xedge_demo/Make.defs b/examples/xedge_demo/Make.defs deleted file mode 100644 index 1f9464a5b..000000000 --- a/examples/xedge_demo/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/examples/xedge_demo/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_EXAMPLES_XEDGE_DEMO),) -CONFIGURED_APPS += $(APPDIR)/examples/xedge_demo -endif \ No newline at end of file diff --git a/examples/xedge_demo/Makefile b/examples/xedge_demo/Makefile deleted file mode 100644 index 720c88000..000000000 --- a/examples/xedge_demo/Makefile +++ /dev/null @@ -1,33 +0,0 @@ -# ############################################################################## -# apps/examples/xedge_demo/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - - -include $(APPDIR)/Make.defs - -PROGNAME = $(CONFIG_EXAMPLES_XEDGE_DEMO_PROGNAME) -PRIORITY = $(CONFIG_EXAMPLES_XEDGE_DEMO_PRIORITY) -STACKSIZE = $(CONFIG_EXAMPLES_XEDGE_DEMO_STACKSIZE) -MODULE = $(CONFIG_EXAMPLES_XEDGE_DEMO) - -MAINSRC = xedge_main.c - -include $(APPDIR)/Application.mk \ No newline at end of file diff --git a/examples/xedge_demo/xedge_main.c b/examples/xedge_demo/xedge_main.c deleted file mode 100644 index b0c2c56c6..000000000 --- a/examples/xedge_demo/xedge_main.c +++ /dev/null @@ -1,240 +0,0 @@ -/*************************************************************************** - * apps/examples/xedge_demo/xedge_main.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ***************************************************************************/ - -/* Xedge NuttX Startup Code (may need adjustments) - * - * Additional License Note: Xedge, based on the Barracuda - * App Server, uses the license options explained here: - * https://github.com/RealTimeLogic/BAS#license - * This repo does not include Xedge and the Barracuda App Server - * library and must be downloaded separately. The dependencies - * are automatically downloaded in apps/netutils/xedge/. - */ - -/*************************************************************************** - * Included Files - ***************************************************************************/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "../../netutils/xedge/BAS/examples/xedge/src/xedge.h" - -/*************************************************************************** - * Pre-processor Definitions - ***************************************************************************/ - -/* The code uses identifiers from the third-party Barracuda App Server - * library, which follows a camelCase naming style: - * https://realtimelogic.com/ba/doc/en/C/introduction.html#oo_c - * These identifiers are used directly and will trigger "Mixed Case" - * warnings in tools like nxstyle, which are safe to ignore in this case. - */ - -/*************************************************************************** - * Private Data - ***************************************************************************/ - -static int running = FALSE; /* Running mode: 2 running, 1 exiting, 0 stopped */ - -/* BAS is configured to use dlmalloc for NuttX. This is the pool. - * 2M : recommended minimum - */ - -static char poolbuf[2 * 1024 * 1024]; - -extern LThreadMgr ltMgr; /* The LThreadMgr configured in xedge.c */ - -/*************************************************************************** - * External Function Prototypes - ***************************************************************************/ - -/* barracuda(): BAS/examples/xedge/src/xedge.c */ - -extern void barracuda(void); -extern void init_dlmalloc(char *heapstart, char *heapend); /* dlmalloc.c */ -extern int (*platformInitDiskIo)(DiskIo *io); /* xedge.c */ - -/*************************************************************************** - * Private Functions - ***************************************************************************/ - -/* The following two functions are copied from the example: - * https://github.com/RealTimeLogic/BAS/blob/main/examples/xedge/src/led.c - * Details: - * https://realtimelogic.com/ba/examples/xedge/readme.html#time - */ - -/* This callback is called by one of the threads managed by LThreadMgr - * when a job is taken off the queue and executed. The callback - * attempts to find the global Lua function '_XedgeEvent', and if the - * function is found, it will be executed as follows: _XedgeEvent("sntp") - */ - -static void execevent(ThreadJob *job, int msgh, LThreadMgr *mgr) -{ - lua_State *L = job->Lt; - lua_pushglobaltable(L); - lua_getfield(L, -1, "_XedgeEvent"); - - if (lua_isfunction(L, -1)) - { - lua_pushstring(L, "sntp"); - lua_pcall(L, 1, 0, msgh); - } -} - -/* Thread started by xedgeOpenAUX() */ - -static void *checktimethread(void *arg) -{ - ThreadMutex *dm = HttpServer_getMutex(ltMgr.server); - const char *d = __DATE__; - char buf[50]; - - (void)arg; - - if (!(basnprintf(buf, sizeof(buf), "Mon, %c%c %c%c%c %s %s", - d[4], d[5], d[0], d[1], d[2], d + 7, __TIME__) < 0)) - { - BaTime t = baParseDate(buf); - if (t) - { - t -= 24 * 60 * 60; - while (baGetUnixTime() < t) - { - Thread_sleep(500); - } - - ThreadJob *job = ThreadJob_lcreate(sizeof(ThreadJob), execevent); - ThreadMutex_set(dm); - LThreadMgr_run(<Mgr, job); - ThreadMutex_release(dm); - } - } - - return NULL; -} - -static void panic(BaFatalErrorCodes ecode1, - unsigned int ecode2, - const char *file, - int line) -{ - syslog(LOG_ERR, "Fatal error in Barracuda %d %d %s %d\n", - ecode1, ecode2, file, line); - exit(1); -} - -/* Redirect server's HttpTrace to syslog. - * https://realtimelogic.com/ba/doc/en/C/reference/html/structHttpTrace.html - */ - -static void flushtrace(char *buf, int buflen) -{ - buf[buflen] = 0; - syslog(LOG_INFO, "%s", buf); -} - -static void sighandler(int signo) -{ - if (running) - { - printf("\nGot SIGTERM; exiting...\n"); - setDispExit(); - - /* NuttX feature: Must wait for socket select() to return */ - - Thread_sleep(2000); - } -} - -/*************************************************************************** - * Public Functions - ***************************************************************************/ - -/* xedge.c calls this to initialize the IO. - * Change "/mnt/lfs" to your preference. - */ - -int xedgeInitDiskIo(DiskIo *io) -{ - if (DiskIo_setRootDir(io, "/mnt/lfs")) - { - syslog(LOG_ERR, "Error: cannot set root to /mnt/lfs\n"); - return -1; - } - - return 0; -} - -/* xedge.c calls this; include your Lua bindings here. - * Tutorial: https://tutorial.realtimelogic.com/Lua-Bindings.lsp - */ - -int xedgeOpenAUX(XedgeOpenAUX *aux) -{ - pthread_t thread; - pthread_attr_t attr; - struct sched_param param; - - (void)aux; - - pthread_attr_init(&attr); - pthread_attr_setstacksize(&attr, 4096); - param.sched_priority = SCHED_PRIORITY_DEFAULT; - pthread_attr_setschedparam(&attr, ¶m); - pthread_create(&thread, &attr, checktimethread, NULL); - - return 0; -} - -int main(int argc, FAR char *argv[]) -{ - if (running) - { - printf("Already running!\n"); - return 1; - } - - signal(SIGINT, sighandler); - signal(SIGTERM, sighandler); - - ntpc_start(); - init_dlmalloc(poolbuf, poolbuf + sizeof(poolbuf)); - HttpTrace_setFLushCallback(flushtrace); - HttpServer_setErrHnd(panic); - - running = TRUE; - barracuda(); - running = FALSE; - - printf("Exiting Xedge\n"); - return 0; -} diff --git a/examples/xmlrpc/CMakeLists.txt b/examples/xmlrpc/CMakeLists.txt deleted file mode 100644 index 9cd0df950..000000000 --- a/examples/xmlrpc/CMakeLists.txt +++ /dev/null @@ -1,34 +0,0 @@ -# ############################################################################## -# apps/examples/xmlrpc/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_XMLRPC) - nuttx_add_application( - NAME - xmlrpc - STACKSIZE - ${CONFIG_DEFAULT_TASK_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_XMLRPC} - SRCS - xmlrpc_main.c) - target_sources(apps PRIVATE calls.c) -endif() diff --git a/examples/xmlrpc/Make.defs b/examples/xmlrpc/Make.defs index 9a3918d15..c2c2435fb 100644 --- a/examples/xmlrpc/Make.defs +++ b/examples/xmlrpc/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/xmlrpc/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/xmlrpc/Makefile b/examples/xmlrpc/Makefile index 9951eb949..4a4e7623e 100644 --- a/examples/xmlrpc/Makefile +++ b/examples/xmlrpc/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/xmlrpc/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/xmlrpc/calls.c b/examples/xmlrpc/calls.c index c2d817a5c..aedb94006 100644 --- a/examples/xmlrpc/calls.c +++ b/examples/xmlrpc/calls.c @@ -1,10 +1,14 @@ /**************************************************************************** * apps/examples/xmlrpc/calls.c * - * SPDX-License-Identifier: BSD-3-Clause - * SPDX-FileCopyrightText: 2012 Max Holtzberg. All rights reserved. - * SPDX-FileCopyrightText: 2002 Cogito LLC. All rights reserved. - * SPDX-FileContributor: Max Holtzberg + * Copyright (C) 2012 Max Holtzberg. All rights reserved. + * Author: Max Holtzberg + * + * Based on the embeddable lightweight XML-RPC server code discussed + * in the article at: http://www.drdobbs.com/web-development/\ + * an-embeddable-lightweight-xml-rpc-server/184405364 + * + * Copyright (c) 2002 Cogito LLC. All rights reserved. * * Redistribution and use in source and binary forms, with or * without modification, is hereby granted without fee provided @@ -36,11 +40,6 @@ * POSSIBILITY OF SUCH DAMAGE. ****************************************************************************/ -/* Based on the embeddable lightweight XML-RPC server code discussed - * in the article at: http://www.drdobbs.com/web-development/\ - * an-embeddable-lightweight-xml-rpc-server/184405364 - */ - /**************************************************************************** * Included Files ****************************************************************************/ @@ -70,13 +69,9 @@ struct xmlrpc_entry_s get_device_stats = static int calls_get_device_stats(struct xmlrpc_s *xmlcall) { - char username[CONFIG_XMLRPC_STRINGSIZE + 1]; - char password[CONFIG_XMLRPC_STRINGSIZE + 1]; - char lastcmd[CONFIG_XMLRPC_STRINGSIZE + 1]; - char curstate[CONFIG_XMLRPC_STRINGSIZE + 1]; - int request = 0; - int status; - int ret; + char username[80], password[80]; + char lastCommand[80], curState[80]; + int request = 0, status, ret; do { @@ -105,13 +100,13 @@ static int calls_get_device_stats(struct xmlrpc_s *xmlcall) /* Dummy up some data... */ status = 1; - strlcpy(lastcmd, "reboot", sizeof(lastcmd)); - strlcpy(curstate, "Normal Operation", sizeof(curstate)); + strcpy(lastCommand, "reboot"); + strcpy(curState, "Normal Operation"); ret = xmlrpc_buildresponse(xmlcall, "{iss}", "status", status, - "lastCommand", lastcmd, - "currentState", curstate); + "lastCommand", lastCommand, + "currentState", curState); } return ret; diff --git a/examples/xmlrpc/xmlrpc_main.c b/examples/xmlrpc/xmlrpc_main.c index f170d7fc5..649fc7f68 100644 --- a/examples/xmlrpc/xmlrpc_main.c +++ b/examples/xmlrpc/xmlrpc_main.c @@ -1,11 +1,15 @@ /**************************************************************************** * apps/examples/xmlrpc/xmlrpc_main.c * - * SPDX-License-Identifier: BSD-3-Clause - * SPDX-FileCopyrightText: 2012 Max Holtzberg. All rights reserved. - * SPDX-FileCopyrightText: 2015 Gregory Nutt. All rights reserved. - * SPDX-FileCopyrightText: 2002 Cogito LLC. All rights reserved. - * SPDX-FileContributor: Max Holtzberg + * Copyright (C) 2012 Max Holtzberg. All rights reserved. + * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Author: Max Holtzberg + * + * Based on the embeddable lightweight XML-RPC server code discussed + * in the article at: http://www.drdobbs.com/web-development/\ + * an-embeddable-lightweight-xml-rpc-server/184405364 + * + * Copyright (c) 2002 Cogito LLC. All rights reserved. * * Redistribution and use in source and binary forms, with or * without modification, is hereby granted without fee provided @@ -37,14 +41,10 @@ * POSSIBILITY OF SUCH DAMAGE. ****************************************************************************/ -/* Based on the embeddable lightweight XML-RPC server code discussed - * in the article at: http://www.drdobbs.com/web-development/\ - * an-embeddable-lightweight-xml-rpc-server/184405364 - */ - -/* Lightweight Embedded XML-RPC Server main +/* + * Lightweight Embedded XML-RPC Server main * - * mtj@cogitollc.com + * mtj@cogitollc.com * */ @@ -52,7 +52,7 @@ * Included Files ****************************************************************************/ -#include +#include #include #include #include @@ -66,9 +66,14 @@ #include #include +#include #include "netutils/netlib.h" #include "netutils/xmlrpc.h" +#ifdef CONFIG_EXAMPLES_XMLRPC_DHCPC +# include +#endif + /* Here we include the header file for the application(s) we use in * our project as defined in the config//defconfig file */ @@ -83,8 +88,8 @@ * Private Data ****************************************************************************/ -static const FAR char *notimplemented = "HTTP/1.1 501 Not Implemented\n\n"; -static const FAR char *separator = "\015\012\015\012"; +static const char *notimplemented = { "HTTP/1.1 501 Not Implemented\n\n" }; +static const char *separator = { "\015\012\015\012" }; /**************************************************************************** * External Function Prototypes @@ -128,17 +133,11 @@ static char *xmlrpc_findbody(char *buf) * ****************************************************************************/ -static int xmlrpc_getheader(FAR char *buffer, FAR char *header, - FAR char *value, int size) +static int xmlrpc_getheader(char *buffer, char *header, char *value, int size) { - FAR char *temp; + char *temp; int i = 0; - if (size <= 0) - { - return -1; - } - temp = strstr(buffer, header); if (temp) { @@ -155,7 +154,7 @@ static int xmlrpc_getheader(FAR char *buffer, FAR char *header, /* Copy the rest to the value parameter */ - while ((*temp != ' ') && (*temp != '\n') && (i < size - 1)) + while ((*temp != ' ') && (*temp != '\n') && (i < size)) { value[i++] = *temp++; } @@ -179,17 +178,10 @@ static void xmlrpc_handler(int fd) { fd_set rfds; struct timeval tv; - int ret; - int len; - int max = 0; - int loadlen = -1; - char buffer[CONFIG_EXAMPLES_XMLRPC_BUFFERSIZE] = - { - 0 - }; - + int ret, len, max = 0, loadlen = -1; + char buffer[CONFIG_EXAMPLES_XMLRPC_BUFFERSIZE] = { 0 }; char value[CONFIG_XMLRPC_STRINGSIZE + 1]; - FAR char *temp; + char *temp; /* Read in the Request Header */ @@ -218,7 +210,7 @@ static void xmlrpc_handler(int fd) buffer[max] = 0; ret = xmlrpc_getheader(buffer, "Content-Length:", value, - sizeof(value)); + CONFIG_EXAMPLES_XMLRPC_BUFFERSIZE); if (ret > 0) loadlen = atoi(value); } @@ -245,6 +237,7 @@ static void xmlrpc_handler(int fd) if (strlen(temp) - 4 == loadlen) break; } + } while (1); @@ -271,8 +264,8 @@ static void xmlrpc_handler(int fd) static int xmlrpc_netinit(void) { - /* If this task is excecutated as an NSH built-in function, - * then the network has already been configured by NSH's start-up logic. + /* If this task is excecutated as an NSH built-in function, then the network + * has already been configured by NSH's start-up logic. */ #ifndef CONFIG_NSH_NETINIT @@ -284,7 +277,7 @@ static int xmlrpc_netinit(void) void *handle; #endif - /* Many embedded network interfaces must have a software assigned MAC */ +/* Many embedded network interfaces must have a software assigned MAC */ #ifdef CONFIG_EXAMPLES_XMLRPC_NOMAC mac[0] = 0x00; @@ -330,18 +323,15 @@ static int xmlrpc_netinit(void) handle = dhcpc_open("eth0", &mac, IFHWADDRLEN); - /* Get an IP address. Note: there is no logic here for renewing the - * address in this example. The address should be renewed in - * ds.lease_time/2 seconds. + /* Get an IP address. Note: there is no logic here for renewing the address + * in this example. The address should be renewed in ds.lease_time/2 + * seconds. */ printf("Getting IP address\n"); if (handle) { struct dhcpc_state ds; - char inetaddr[INET_ADDRSTRLEN]; - int ret; - dhcpc_request(handle, &ds); netlib_set_ipv4addr("eth0", &ds.ipaddr); @@ -355,21 +345,13 @@ static int xmlrpc_netinit(void) netlib_set_dripv4addr("eth0", &ds.default_router); } - for (int i = 0; i < ds.num_dnsaddr; i++) + if (ds.dnsaddr.s_addr != 0) { - if (ds.dnsaddr[i].s_addr != 0) - { - ret = netlib_set_ipv4dnsaddr(&ds.dnsaddr[i]); - if (ret < 0) - { - nerr("ERROR: Set DNS server %d:%s address failed: %d\n", - i, inet_ntoa(ds.dnsaddr[i]), ret); - } - } + netlib_set_ipv4dnsaddr(&ds.dnsaddr); } dhcpc_close(handle); - printf("IP: %s\n", inet_ntoa_r(ds.ipaddr, inetaddr, sizeof(inetaddr))); + printf("IP: %s\n", inet_ntoa(ds.ipaddr)); } #endif /* CONFIG_EXAMPLES_XMLRPC_DHCPC */ @@ -392,12 +374,9 @@ static int xmlrpc_netinit(void) int main(int argc, FAR char *argv[]) { - int listenfd; - int connfd; - int on = 1; + int listenfd, connfd, on = 1; socklen_t clilen; - struct sockaddr_in cliaddr; - struct sockaddr_in servaddr; + struct sockaddr_in cliaddr, servaddr; if (xmlrpc_netinit() < 0) { @@ -413,7 +392,7 @@ int main(int argc, FAR char *argv[]) setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)); - memset(&servaddr, 0, sizeof(servaddr)); + memset((void *)&servaddr, 0, sizeof(servaddr)); servaddr.sin_family = AF_INET; servaddr.sin_addr.s_addr = htonl(INADDR_ANY); servaddr.sin_port = htons(80); @@ -422,16 +401,14 @@ int main(int argc, FAR char *argv[]) listen(listenfd, 5); - for (; ; ) + for (;;) { clilen = sizeof(cliaddr); - connfd = accept4(listenfd, (struct sockaddr *)&cliaddr, &clilen, - SOCK_CLOEXEC); + connfd = accept(listenfd, (struct sockaddr *)&cliaddr, &clilen); if (connfd <= 0) { break; } - ninfo("Connection accepted: %d\n", connfd); xmlrpc_handler(connfd); diff --git a/examples/zerocross/CMakeLists.txt b/examples/zerocross/CMakeLists.txt deleted file mode 100644 index f77c12bfb..000000000 --- a/examples/zerocross/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# ############################################################################## -# apps/examples/zerocross/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_EXAMPLES_ZEROCROSS) - nuttx_add_application( - NAME - zerocross - STACKSIZE - ${CONFIG_DEFAULT_TASK_STACKSIZE} - MODULE - ${CONFIG_EXAMPLES_ZEROCROSS} - SRCS - zerocross_main.c) -endif() diff --git a/examples/zerocross/Kconfig b/examples/zerocross/Kconfig index 758c4781a..d5c1245b2 100644 --- a/examples/zerocross/Kconfig +++ b/examples/zerocross/Kconfig @@ -6,7 +6,7 @@ config EXAMPLES_ZEROCROSS tristate "Zero Cross Detection example" default n - depends on SENSORS_ZEROCROSS && ENABLE_ALL_SIGNALS + depends on SENSORS_ZEROCROSS ---help--- Enable the zero cross detection example @@ -18,6 +18,6 @@ config EXAMPLES_ZEROCROSS_DEVNAME config EXAMPLES_ZEROCROSS_SIGNO int "Zero Cross signal" - default 32 + default 13 endif diff --git a/examples/zerocross/Make.defs b/examples/zerocross/Make.defs index 5ca4c7c16..f967a3188 100644 --- a/examples/zerocross/Make.defs +++ b/examples/zerocross/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/zerocross/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/zerocross/Makefile b/examples/zerocross/Makefile index 773fa6eb1..62d83ef5e 100644 --- a/examples/zerocross/Makefile +++ b/examples/zerocross/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/examples/zerocross/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/examples/zerocross/zerocross_main.c b/examples/zerocross/zerocross_main.c index 2b6da5b62..63da486a8 100644 --- a/examples/zerocross/zerocross_main.c +++ b/examples/zerocross/zerocross_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/examples/zerocross/zerocross_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -27,13 +25,11 @@ #include #include -#include #include #include #include #include -#include -#include +#include #include @@ -52,7 +48,16 @@ #endif #ifndef CONFIG_EXAMPLES_ZEROCROSS_SIGNO -# define CONFIG_EXAMPLES_ZEROCROSS_SIGNO 32 +# define CONFIG_EXAMPLES_ZEROCROSS_SIGNO 13 +#endif + +/* Helpers ******************************************************************/ + +#ifndef MIN +# define MIN(a,b) (a < b ? a : b) +#endif +#ifndef MAX +# define MAX(a,b) (a > b ? a : b) #endif /**************************************************************************** diff --git a/fsutils/CMakeLists.txt b/fsutils/CMakeLists.txt deleted file mode 100644 index 0215201de..000000000 --- a/fsutils/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -# ############################################################################## -# apps/fsutils/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -nuttx_add_subdirectory() - -nuttx_generate_kconfig(MENUDESC "File System Utilities") diff --git a/fsutils/Make.defs b/fsutils/Make.defs index 2a6a4b825..93c71c38e 100644 --- a/fsutils/Make.defs +++ b/fsutils/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/fsutils/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/fsutils/Makefile b/fsutils/Makefile index b2d19cf1b..a31d2e0e2 100644 --- a/fsutils/Makefile +++ b/fsutils/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/fsutils/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/fsutils/flash_eraseall/CMakeLists.txt b/fsutils/flash_eraseall/CMakeLists.txt deleted file mode 100644 index 0a7086f4b..000000000 --- a/fsutils/flash_eraseall/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -# ############################################################################## -# apps/fsutils/flash_eraseall/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_FSUTILS_FLASH_ERASEALL) - target_sources(apps PRIVATE flash_eraseall.c) -endif() diff --git a/fsutils/flash_eraseall/Make.defs b/fsutils/flash_eraseall/Make.defs index 217a1d947..2788ea6e8 100644 --- a/fsutils/flash_eraseall/Make.defs +++ b/fsutils/flash_eraseall/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/fsutils/flash_eraseall/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -20,6 +18,6 @@ # ############################################################################ -ifneq ($(CONFIG_FSUTILS_FLASH_ERASEALL),) +ifeq ($(CONFIG_FSUTILS_FLASH_ERASEALL),y) CONFIGURED_APPS += $(APPDIR)/fsutils/flash_eraseall endif diff --git a/fsutils/flash_eraseall/Makefile b/fsutils/flash_eraseall/Makefile index b620ec031..8c1ff75b0 100644 --- a/fsutils/flash_eraseall/Makefile +++ b/fsutils/flash_eraseall/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/fsutils/flash_eraseall/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/fsutils/flash_eraseall/flash_eraseall.c b/fsutils/flash_eraseall/flash_eraseall.c index fda7b7e04..36a4cbd1c 100644 --- a/fsutils/flash_eraseall/flash_eraseall.c +++ b/fsutils/flash_eraseall/flash_eraseall.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/fsutils/flash_eraseall/flash_eraseall.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -30,7 +28,7 @@ #include #include #include -#include +#include #include #include "fsutils/flash_eraseall.h" @@ -71,14 +69,13 @@ int flash_eraseall(FAR const char *driver) if (ret < 0) { errcode = errno; - ferr("ERROR: MTD ioctl(%04x) failed: %d\n", - MTDIOC_BULKERASE, errcode); + ferr("ERROR: MTD ioctl(%04x) failed: %d\n", MTDIOC_BULKERASE, errcode); ret = -errcode; } /* Close the block driver */ - close(fd); + close(fd); } return ret; diff --git a/fsutils/flashtool/CMakeLists.txt b/fsutils/flashtool/CMakeLists.txt deleted file mode 100644 index 338c1a394..000000000 --- a/fsutils/flashtool/CMakeLists.txt +++ /dev/null @@ -1,24 +0,0 @@ -# ############################################################################## -# apps/fsutils/flashtool/CMakeLists.txt -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_FSUTILS_FLASHTOOL) - nuttx_add_application(MODULE ${CONFIG_FSUTILS_FLASHTOOL} NAME flashtool SRCS - flashtool_main.c) -endif() diff --git a/fsutils/flashtool/Kconfig b/fsutils/flashtool/Kconfig deleted file mode 100644 index 07f89671a..000000000 --- a/fsutils/flashtool/Kconfig +++ /dev/null @@ -1,29 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config FSUTILS_FLASHTOOL - tristate "FLASH Tool Command" - default n - depends on MTD - depends on BCH - ---help--- - Enable support for the FLASH tool. - -if FSUTILS_FLASHTOOL - -config FSUTILS_FLASHTOOL_STACKSIZE - int "flashtool stack size" - default DEFAULT_TASK_STACKSIZE - ---help--- - This is the stack size that will be used when starting the flashtool. - -config FSUTILS_FLASHTOOL_PRIORITY - int "flashtool priority" - default 100 - ---help--- - This is the task priority that will be used when starting the flashtool. - -endif - diff --git a/fsutils/flashtool/flashtool_main.c b/fsutils/flashtool/flashtool_main.c deleted file mode 100644 index bbb07a6d2..000000000 --- a/fsutils/flashtool/flashtool_main.c +++ /dev/null @@ -1,374 +0,0 @@ -/**************************************************************************** - * apps/fsutils/flashtool/flashtool_main.c - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -enum opr_list -{ - HELP, DEVICE_INFO, READ_PAGE, WRITE_PAGE, ERASE_BLOCK, ERASE_ALL, - CHECK_BAD_BLOCK -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static void display_help(void) -{ - printf("Usage : flashtool [OPTION [ARG]] device_name ...\n"); - printf("-h show this help statement\n"); - printf("-i display device geometry information\n"); - printf("-r read the specified pages\n"); - printf("-w write the specified pages\n"); - printf("-e erase the specified blocks\n"); - printf("-n number of pages or blocks\n"); - printf("-f file name for read or write\n"); - printf("-b check whether is bad\n"); - printf("-c erase all of the flash\n"); - printf("-d device name\n"); -} - -static void display_device_info(FAR const struct mtd_geometry_s *geo) -{ - printf("Size of one read/write page: %lu\n", geo->blocksize); - printf("Size of one erase block: %lu\n", geo->erasesize); - printf("Number of erase blocks: %lu\n", geo->neraseblocks); -} - -static int read_page(int fd, FAR const struct mtd_geometry_s *geo, - off_t start_page, size_t npages) -{ - FAR unsigned char *buf; - ssize_t ret = OK; - off_t seek; - size_t i; - - buf = malloc(geo->blocksize); - if (!buf) - { - printf("ERROR: read_page cannot allocate memory %d\n", geo->blocksize); - return ERROR; - } - - seek = geo->blocksize * start_page; - if (lseek(fd, seek, SEEK_SET) != seek) - { - printf("ERROR: Cannot seek mtd to offset %lld: %d", seek, errno); - goto oops; - } - - printf("Flash pages contents:\n"); - for (i = 0; i < npages; i++) - { - ret = read(fd, buf, geo->blocksize); - if (ret < 0) - { - printf("ERROR: Read error: %d!\n", errno); - goto oops; - } - - printf("Flash page %lld:\n", start_page + i); - lib_dumpbuffer(NULL, buf, ret); - } - -oops: - free(buf); - return ret; -} - -/* Write npages data from img to flash - * If size of img is less than npags, only write img size - */ - -static int write_page(int fd, FAR const struct mtd_geometry_s *geo, - off_t start_page, size_t npages, FAR const char *img) -{ - FAR unsigned char *buf; - off_t imglen; - off_t seek; - off_t i; - int fd_src; - int ret = OK; - - if (img == NULL) - { - printf("ERROR: Need source file path!\n"); - return ERROR; - } - - printf("Write data from %s...\n", img); - seek = geo->blocksize * start_page; - if (lseek(fd, seek, SEEK_SET) != seek) - { - printf("ERROR: cannot seek mtd to offset %lld: %d", seek, errno); - return ERROR; - } - - fd_src = open(img, O_RDONLY); - if (fd_src < 0) - { - printf("ERROR: Open file %s failed: %d\n", img, errno); - return ERROR; - } - - imglen = lseek(fd_src, 0, SEEK_END); - if (lseek(fd_src, 0, SEEK_SET) != 0) - { - close(fd_src); - return ERROR; - } - - /* Malloc a size of page for buf */ - - buf = malloc(geo->blocksize); - if (!buf) - { - printf("ERROR: write_page cannot allocate memory %d\n", - geo->blocksize); - close(fd_src); - return ERROR; - } - - for (i = start_page; i < start_page + npages; i++) - { - ret = read(fd_src, buf, - (imglen < geo->blocksize) ? imglen : geo->blocksize); - if (ret < 0) - { - printf("ERROR: read source file error: %d!\n", errno); - goto oops; - } - - ret = write(fd, buf, geo->blocksize); - if (ret < 0) - { - printf("ERROR: write error: %d!\n", errno); - goto oops; - } - - imglen -= geo->blocksize; - if (imglen <= 0) - { - break; - } - } - -oops: - close(fd_src); - free(buf); - return ret; -} - -static int erase_block(int fd, off_t start_block, - size_t nblocks) -{ - struct mtd_erase_s erase; - int ret; - - printf("Erase block from %lld to %lld!\n", start_block, - start_block + nblocks -1); - erase.startblock = start_block; - erase.nblocks = nblocks; - ret = ioctl(fd, MTDIOC_ERASESECTORS, &erase); - if (ret < 0) - { - printf("ERROR: Erase failed: %d!\n", errno); - } - - return ret; -} - -static int erase_all(int fd) -{ - if (ioctl(fd, MTDIOC_BULKERASE, 0) < 0) - { - printf("ERROR: MTD ioctl(MTDIOC_BULKERASE) failed: %d\n", errno); - return ERROR; - } - - return OK; -} - -static int check_bad_block(int fd, FAR const struct mtd_geometry_s *geo) -{ - struct mtd_bad_block_s bad_block; - int flag = 0; - int ret; - int i; - - printf("Check bad blocks in flash......\n"); - for (i = 0; i < geo->neraseblocks; i++) - { - bad_block.block_num = i; - ret = ioctl(fd, MTDIOC_ISBAD, &bad_block); - if (ret != OK) - { - printf("ERROR: MTDIOC_ISBAD failed: %d!\n", errno); - return ERROR; - } - else - { - if (bad_block.bad_flag) - { - printf("Block %d is bad!\n", i); - flag = 1; - } - } - } - - if (flag == 0) - { - printf("No bad blocks!\n"); - } - - return OK; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -int main(int argc, FAR char *argv[]) -{ - FAR char *mtddev = NULL; - FAR char *img = NULL; - struct mtd_geometry_s geo; - enum opr_list opr = HELP; - off_t npages = 1; - off_t start; - int option; - int mode = O_RDONLY; - int fd; - int ret; - - while ((option = getopt(argc, argv, ":hir:w:e:n:f:bcd:")) != -1) - { - switch (option) - { - case 'h': - display_help(); - exit(0); - case 'i': - opr = DEVICE_INFO; - break; - case 'r': - opr = READ_PAGE; - start = strtoul(optarg, NULL, 0); - break; - case 'w': - opr = WRITE_PAGE; - mode = O_RDWR; - start = strtoul(optarg, NULL, 0); - break; - case 'e': - opr = ERASE_BLOCK; - start = strtoul(optarg, NULL, 0); - break; - case 'n': - npages = strtoul(optarg, NULL, 0); - break; - case 'f': - img = optarg; - break; - case 'b': - opr = CHECK_BAD_BLOCK; - break; - case 'c': - opr = ERASE_ALL; - break; - case 'd': - mtddev = optarg; - break; - case ':': - printf("Error: Missing required argument\n"); - exit(1); - case '?': - printf("Error: Unrecognized option\n"); - exit(1); - } - } - - if (mtddev == NULL) - { - printf("Error: Device name is required!\n"); - return -1; - } - - fd = open(mtddev, mode, 0777); - if (fd < 0) - { - printf("ERROR: Failed to open '%s': %d\n", mtddev, errno); - return -1; - } - - ret = ioctl(fd, MTDIOC_GEOMETRY, &geo); - if (ret < 0) - { - printf("ERROR: Ioctl MTDIOC_GEOMETRY failed: %d\n", errno); - goto oops; - } - - switch (opr) - { - case DEVICE_INFO: - display_device_info(&geo); - break; - case READ_PAGE: - ret = read_page(fd, &geo, start, npages); - break; - case WRITE_PAGE: - ret = write_page(fd, &geo, start, npages, img); - break; - case ERASE_BLOCK: - ret = erase_block(fd, start, npages); - break; - case ERASE_ALL: - ret = erase_all(fd); - break; - case CHECK_BAD_BLOCK: - ret = check_bad_block(fd, &geo); - break; - default: - break; - } - -oops: - close(fd); - return ret; -} diff --git a/fsutils/inifile/CMakeLists.txt b/fsutils/inifile/CMakeLists.txt deleted file mode 100644 index 652fbb536..000000000 --- a/fsutils/inifile/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -# ############################################################################## -# apps/fsutils/inifile/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_FSUTILS_INIFILE) - target_sources(apps PRIVATE inifile.c) -endif() diff --git a/fsutils/inifile/Make.defs b/fsutils/inifile/Make.defs index 4568f378f..f62090e9a 100644 --- a/fsutils/inifile/Make.defs +++ b/fsutils/inifile/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/fsutils/inifile/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -20,6 +18,6 @@ # ############################################################################ -ifneq ($(CONFIG_FSUTILS_INIFILE),) +ifeq ($(CONFIG_FSUTILS_INIFILE),y) CONFIGURED_APPS += $(APPDIR)/fsutils/inifile endif diff --git a/fsutils/inifile/Makefile b/fsutils/inifile/Makefile index 257e982d7..a70f219e5 100644 --- a/fsutils/inifile/Makefile +++ b/fsutils/inifile/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/fsutils/inifile/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/fsutils/inifile/README.md b/fsutils/inifile/README.md new file mode 100644 index 000000000..86590cbcb --- /dev/null +++ b/fsutils/inifile/README.md @@ -0,0 +1,144 @@ +# File System Utilities / `inifile` INI File + +## Syntax + +This directory contains a very simple INI file parser. An INI file consists of a +sequence of lines up to the end of file. A line may be one of the following: + +1. A blank line. + +2. A comment line. Any line beginning with `;` + +3. A section header. Definitions are divided into sections. Each section begins + with a line containing the section name enclosed in square brackets. For + example, `[section1]`. The left bracket must be the first character on the + line. Section names are case insensitive, i.e., `SECTION1` and `Section1` + refer to the same section. + +4. Variable assignments. A variable assignment is a variable name followed by + the `=` sign and then the value of the variable. For example, `A=B`: `A` is + the variable name; `B` is the variable value. All variables following the + section header belong in the section. + + Variable names may be preceded with white space. Whitespace is not permitted + before the `=` sign. Variable names are case insensitive, i.e., `A` and `a` + refer to the same variable name. + + Variable values may be numeric (any base) or a string. The case of string + arguments is preserved. + +## Programming Interfaces + +See `apps/include/fsutils/inifile.h` for interfaces supported by the INI file +parser. + +## Test Program + +Below is a simple test program: + +```c +int main(int argc, char *argv[]) +{ + INIHANDLE handle; + FILE *stream; + FAR char *ptr; + long value; + + stream = fopen("/tmp/file.ini", "w"); + fprintf(stream, "; Test INI file\n"); + fprintf(stream, "[section1]\n"); + fprintf(stream, " VAR1=1\n"); + fprintf(stream, " VAR2=2\n"); + fprintf(stream, " VAR3=3\n"); + fprintf(stream, "\n"); + fprintf(stream, "[section2]\n"); + fprintf(stream, " VAR4=4\n"); + fprintf(stream, " VAR5=5\n"); + fprintf(stream, "VAR6=6\n"); + fprintf(stream, "\n"); + fclose(stream); + + handle = inifile_initialize("/tmp/file.ini"); + + ptr = inifile_read_string(handle, "section2", "VAR5", "OOPS"); + printf("Section: %s Variable: %s String: %s\n", "section2", "VAR5", ptr); + inifile_free_string(ptr); + + ptr = inifile_read_string(handle, "section1", "VAR2", "OOPS"); + printf("Section: %s Variable: %s String: %s\n", "section1", "VAR2", ptr); + inifile_free_string(ptr); + + ptr = inifile_read_string(handle, "section3", "VAR3", "OOPS"); + printf("Section: %s Variable: %s String: %s\n", "section3", "VAR3", ptr); + inifile_free_string(ptr); + + ptr = inifile_read_string(handle, "section1", "VAR3", "OOPS"); + printf("Section: %s Variable: %s String: %s\n", "section1", "VAR3", ptr); + inifile_free_string(ptr); + + ptr = inifile_read_string(handle, "section1", "VAR1", "OOPS"); + printf("Section: %s Variable: %s String: %s\n", "section1", "VAR1", ptr); + inifile_free_string(ptr); + + ptr = inifile_read_string(handle, "section1", "VAR42", "OOPS"); + printf("Section: %s Variable: %s String: %s\n", "section1", "VAR42", ptr); + inifile_free_string(ptr); + + ptr = inifile_read_string(handle, "section2", "VAR6", "OOPS"); + printf("Section: %s Variable: %s String: %s\n", "section2", "VAR6", ptr); + inifile_free_string(ptr); + + ptr = inifile_read_string(handle, "section2", "VAR4", "OOPS"); + printf("Section: %s Variable: %s String: %s\n", "section2", "VAR4", ptr); + inifile_free_string(ptr); + + value = inifile_read_integer(handle, "section1", "VAR3", 0); + printf("Section: %s Variable: %s Value: %ld\n", "section1", "VAR3", value); + + value = inifile_read_integer(handle, "section3", "VAR3", 0); + printf("Section: %s Variable: %s String: %ld\n", "section3", "VAR3", value); + + value = inifile_read_integer(handle, "section1", "VAR1", 0); + printf("Section: %s Variable: %s Value: %ld\n", "section1", "VAR1", value); + + value = inifile_read_integer(handle, "section2", "VAR5", 0); + printf("Section: %s Variable: %s Value: %ld\n", "section2", "VAR5", value); + + value = inifile_read_integer(handle, "section2", "VAR6", 0); + printf("Section: %s Variable: %s Value: %ld\n", "section2", "VAR6", value); + + value = inifile_read_integer(handle, "section1", "VAR42", 0); + printf("Section: %s Variable: %s String: %ld\n", "section1", "VAR42", value); + + value = inifile_read_integer(handle, "section1", "VAR2", 0); + printf("Section: %s Variable: %s Value: %ld\n", "section1", "VAR2", value); + + value = inifile_read_integer(handle, "section2", "VAR4", 0); + printf("Section: %s Variable: %s Value: %ld\n", "section2", "VAR4", value); + + inifile_uninitialize(handle); + return 0; +} +``` + +Test program output: + +``` +Section: section2 Variable: VAR5 String: 5 +Section: section1 Variable: VAR2 String: 2 +Section: section3 Variable: VAR3 String: OOPS +Section: section1 Variable: VAR3 String: 3 +Section: section1 Variable: VAR1 String: 1 +Section: section1 Variable: VAR42 String: OOPS +Section: section2 Variable: VAR6 String: 6 +Section: section2 Variable: VAR4 String: 4 + +Section: section1 Variable: VAR3 Value: 3 +Section: section3 Variable: VAR3 Value: 0 +Section: section1 Variable: VAR1 Value: 1 +Section: section2 Variable: VAR5 Value: 5 +Section: section2 Variable: VAR6 Value: 6 +Section: section1 Variable: VAR42 String: 0 +Section: section1 Variable: VAR2 Value: 2 +Section: section2 Variable: VAR4 Value: 4 +``` diff --git a/fsutils/inifile/inifile.c b/fsutils/inifile/inifile.c index 8bb52326b..c95905386 100644 --- a/fsutils/inifile/inifile.c +++ b/fsutils/inifile/inifile.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/fsutils/inifile/inifile.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -29,7 +27,7 @@ #include #include #include -#include +#include #include "fsutils/inifile.h" @@ -488,7 +486,7 @@ INIHANDLE inifile_initialize(FAR const char *inifile_name) if (!priv) { inidbg("ERROR: Failed to allocate state structure\n"); - return NULL; + return (INIHANDLE)NULL; } /* Open the specified INI file for reading */ @@ -506,7 +504,7 @@ INIHANDLE inifile_initialize(FAR const char *inifile_name) { inidbg("ERROR: Could not open \"%s\"\n", inifile_name); free(priv); - return NULL; + return (INIHANDLE)NULL; } } @@ -605,7 +603,7 @@ long inifile_read_integer(INIHANDLE handle, /* Assume failure to find the requested value */ - iniinfo("section=\"%s\" variable=\"%s\" defvalue=%ld\n", + iniinfo("section=\"%s\" variable=\"%s\" defvalue=%d\n", section, variable, defvalue); /* Get the value as a string first */ @@ -626,7 +624,7 @@ long inifile_read_integer(INIHANDLE handle, /* Return the value that we found. */ - iniinfo("Returning %ld\n", ret); + iniinfo("Returning %d\n", ret); return ret; } diff --git a/fsutils/inih/CMakeLists.txt b/fsutils/inih/CMakeLists.txt deleted file mode 100644 index 7f8196623..000000000 --- a/fsutils/inih/CMakeLists.txt +++ /dev/null @@ -1,88 +0,0 @@ -# ############################################################################## -# apps/fsutils/inih/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_FSUTILS_INIH) - - # ############################################################################ - # Config and Fetch inih lib - # ############################################################################ - set(INIH_DIR ${CMAKE_CURRENT_LIST_DIR}/inih-r42) - - if(NOT EXISTS ${INIH_DIR}) - set(INIH_URL https://github.com/benhoyt/inih/archive/r42.tar.gz) - FetchContent_Declare( - inih_fetch - URL ${INIH_URL} SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/inih-r42 BINARY_DIR - ${CMAKE_BINARY_DIR}/apps/fsutils/inih/inih-r42 - DOWNLOAD_NO_PROGRESS true - TIMEOUT 30) - - FetchContent_GetProperties(inih_fetch) - if(NOT inih_fetch_POPULATED) - FetchContent_Populate(inih_fetch) - endif() - endif() - - # ############################################################################ - # Flags - # ############################################################################ - - set(CFLAGS - -DINI_MAX_LINE=${CONFIG_INIH_MAX_LINE} -DINI_ALLOW_BOM=0 - -DINI_ALLOW_INLINE_COMMENTS=1 -DINI_STOP_ON_FIRST_ERROR=0 - -DINI_HANDLER_LINENO=1) - - if(CONFIG_INIH_MULTI_LINE_ENTRIES) - list(APPEND CFLAGS -DINI_ALLOW_MULTILINE=1) - else() - list(APPEND CFLAGS -DINI_ALLOW_MULTILINE=0) - endif() - - if(CONFIG_INIH_USE_MALLOC) - list(APPEND CFLAGS -DINI_USE_STACK=0 -DINI_ALLOW_REALLOC=1 - -DINI_INITIAL_ALLOC=${CONFIG_INIH_INITIAL_ALLOC}) - else() - list(APPEND CFLAGS -DINI_USE_STACK=1 -DINI_ALLOW_REALLOC=0) - endif() - # ############################################################################ - # Sources - # ############################################################################ - - file(GLOB CSRCS ${LIBTOMMATH_DIR}/*.c) - set(CSRCS ${INIH_DIR}/ini.c) - - # ############################################################################ - # Include Directory - # ############################################################################ - - set(INCDIR ${INIH_DIR}) - - # ############################################################################ - # Library Configuration - # ############################################################################ - - nuttx_add_library(inih STATIC) - target_compile_options(inih PRIVATE ${CFLAGS}) - target_sources(inih PRIVATE ${CSRCS}) - target_include_directories(inih PRIVATE ${INCDIR}) - -endif() diff --git a/fsutils/inih/Make.defs b/fsutils/inih/Make.defs index c965b3273..7d897e689 100644 --- a/fsutils/inih/Make.defs +++ b/fsutils/inih/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/fsutils/inih/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -20,6 +18,6 @@ # ############################################################################ -ifneq ($(CONFIG_FSUTILS_INIH),) +ifeq ($(CONFIG_FSUTILS_INIH),y) CONFIGURED_APPS += $(APPDIR)/fsutils/inih endif diff --git a/fsutils/inih/Makefile b/fsutils/inih/Makefile index f89ea7269..b4c3b0454 100644 --- a/fsutils/inih/Makefile +++ b/fsutils/inih/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/fsutils/inih/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/fsutils/ipcfg/CMakeLists.txt b/fsutils/ipcfg/CMakeLists.txt deleted file mode 100644 index 66accd482..000000000 --- a/fsutils/ipcfg/CMakeLists.txt +++ /dev/null @@ -1,32 +0,0 @@ -# ############################################################################## -# apps/fsutils/ipcfg/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_FSUTILS_IPCFG) - target_sources(apps PRIVATE ipcfg.c) - - if(CONFIG_IPCFG_BINARY) - target_sources(apps PRIVATE ipcfg_binary.c) - else() - target_sources(apps PRIVATE ipcfg_text.c) - endif() - -endif() diff --git a/fsutils/ipcfg/Make.defs b/fsutils/ipcfg/Make.defs index 399b334c1..5e44ae68c 100644 --- a/fsutils/ipcfg/Make.defs +++ b/fsutils/ipcfg/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/fsutils/ipcfg/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -20,6 +18,6 @@ # ############################################################################ -ifneq ($(CONFIG_FSUTILS_IPCFG),) +ifeq ($(CONFIG_FSUTILS_IPCFG),y) CONFIGURED_APPS += $(APPDIR)/fsutils/ipcfg endif diff --git a/fsutils/ipcfg/Makefile b/fsutils/ipcfg/Makefile index 757070628..7b63d6e02 100644 --- a/fsutils/ipcfg/Makefile +++ b/fsutils/ipcfg/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/fsutils/ipcfg/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/fsutils/ipcfg/ipcfg.c b/fsutils/ipcfg/ipcfg.c index 9f6deab5b..ae73608ed 100644 --- a/fsutils/ipcfg/ipcfg.c +++ b/fsutils/ipcfg/ipcfg.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/fsutils/ipcfg/ipcfg.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -29,7 +27,7 @@ #include #include #include -#include +#include #include "fsutils/ipcfg.h" #include "ipcfg.h" diff --git a/fsutils/ipcfg/ipcfg.h b/fsutils/ipcfg/ipcfg.h index 6f5ae1f49..ebc473aa9 100644 --- a/fsutils/ipcfg/ipcfg.h +++ b/fsutils/ipcfg/ipcfg.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/fsutils/ipcfg/ipcfg.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/fsutils/ipcfg/ipcfg_binary.c b/fsutils/ipcfg/ipcfg_binary.c index c12a7ada4..6b7bb968c 100644 --- a/fsutils/ipcfg/ipcfg_binary.c +++ b/fsutils/ipcfg/ipcfg_binary.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/fsutils/ipcfg/ipcfg_binary.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -31,7 +29,7 @@ #include #include #include -#include +#include #include "fsutils/ipcfg.h" #include "ipcfg.h" @@ -154,7 +152,7 @@ static int ipcfg_read_binary(int fd, FAR void *buffer, size_t nbytes) * Input Parameters: * fd - File descriptor of the open file to write to * buffer - Location to write to - * nbytes - Number of bytes to write + * nbytes - Number of bytes to wrtie * * Returned Value: * Zero is returned on success; a negated errno value is returned on any @@ -265,7 +263,7 @@ static int ipcfg_find_binary(int fd, sa_family_t af) * * Input Parameters: * path - The full path to the IP configuration file - * ipv4cfg - Location to read IPv4 configuration to + * ipv4cfg - Location to read IPv4 configration to * * Returned Value: * Zero is returned on success; a negated errno value is returned on any @@ -316,7 +314,7 @@ errout_with_fd: * * Input Parameters: * path - The full path to the IP configuration file - * ipv6cfg - Location to read IPv6 configuration to + * ipv6cfg - Location to read IPv6 configration to * * Returned Value: * Zero is returned on success; a negated errno value is returned on any @@ -367,7 +365,7 @@ errout_with_fd: * * Input Parameters: * path - The full path to the IP configuration file - * ipv4cfg - The IPv4 configuration to write + * ipv4cfg - The IPv4 configration to write * * Returned Value: * Zero is returned on success; a negated errno value is returned on any @@ -474,7 +472,7 @@ errout_with_fd: * * Input Parameters: * path - The full path to the IP configuration file - * ipv6cfg - The IPv6 configuration to write + * ipv6cfg - The IPv6 configration to write * * Returned Value: * Zero is returned on success; a negated errno value is returned on any diff --git a/fsutils/ipcfg/ipcfg_text.c b/fsutils/ipcfg/ipcfg_text.c index f0e64f8e8..ab9f9d0da 100644 --- a/fsutils/ipcfg/ipcfg_text.c +++ b/fsutils/ipcfg/ipcfg_text.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/fsutils/ipcfg/ipcfg_text.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -31,7 +29,7 @@ #include #include #include -#include +#include #include @@ -238,7 +236,7 @@ static int ipcfg_put_ipv6addr(FAR FILE *stream, FAR const char *variable, * * Input Parameters: * stream - Stream of the open file to write to - * ipv4cfg - The IPv4 configuration to write + * ipv4cfg - The IPv4 configration to write * * Returned Value: * Zero is returned on success; a negated errno value is returned on any @@ -278,7 +276,7 @@ static int ipcfg_write_ipv4(FAR FILE *stream, * * Input Parameters: * stream - Stream of the open file to write to - * ipv6cfg - The IPv6 configuration to write + * ipv6cfg - The IPv6 configration to write * * Returned Value: * Zero is returned on success; a negated errno value is returned on any @@ -322,7 +320,7 @@ static int ipcfg_write_ipv6(FAR FILE *stream, * Input Parameters: * path - The full path to the IP configuration file * netdev - Network device name string - * ipv4cfg - Location to read IPv4 configuration to + * ipv4cfg - Location to read IPv4 configration to * * Returned Value: * Zero is returned on success; a negated errno value is returned on any @@ -473,7 +471,7 @@ int ipcfg_read_text_ipv4(FAR const char *path, FAR const char *netdev, * Input Parameters: * path - The full path to the IP configuration file * netdev - Network device name string - * ipv6cfg - Location to read IPv6 configuration to + * ipv6cfg - Location to read IPv6 configration to * * Returned Value: * Zero is returned on success; a negated errno value is returned on any @@ -639,7 +637,7 @@ int ipcfg_read_text_ipv6(FAR const char *path, FAR const char *netdev, * Input Parameters: * path - The full path to the IP configuration file * netdev - Network device name string - * ipv4cfg - The IPv4 configuration to write + * ipv4cfg - The IPv4 configration to write * * Returned Value: * Zero is returned on success; a negated errno value is returned on any @@ -726,7 +724,7 @@ int ipcfg_write_text_ipv4(FAR const char *path, FAR const char *netdev, * Input Parameters: * path - The full path to the IP configuration file * netdev - Network device name string - * ipv6cfg - The IPv6 configuration to write + * ipv6cfg - The IPv6 configration to write * * Returned Value: * Zero is returned on success; a negated errno value is returned on any diff --git a/fsutils/libtinycbor/.gitignore b/fsutils/libtinycbor/.gitignore deleted file mode 100644 index 8252e6cbd..000000000 --- a/fsutils/libtinycbor/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/tinycbor -/*.zip diff --git a/fsutils/libtinycbor/CMakeLists.txt b/fsutils/libtinycbor/CMakeLists.txt deleted file mode 100644 index dd8ddfca5..000000000 --- a/fsutils/libtinycbor/CMakeLists.txt +++ /dev/null @@ -1,80 +0,0 @@ -# ############################################################################## -# apps/fsutils/libtinycbor/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_FSUTILS_TINYCBOR_LIB) - - # ############################################################################ - # Config and Fetch libtinycbor - # ############################################################################ - set(TINYCBOR_DIR ${CMAKE_CURRENT_LIST_DIR}/tinycbor) - - if(NOT EXISTS ${TINYCBOR_DIR}) - set(TINYCBOR_VERSION 3cba6b11aaa0f6f674cd56ebaa573c4b65f71ee7) - set(TINYCBOR_URL - https://github.com/intel/tinycbor/archive/${TINYCBOR_VERSION}.zip) - file(DOWNLOAD ${TINYCBOR_URL} ${CMAKE_CURRENT_LIST_DIR}/tinycbor.zip) - execute_process(COMMAND unzip -o -j tinycbor.zip -d ${TINYCBOR_DIR} - WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}) - execute_process(COMMAND patch -Np1 -i fix_open_memstream.patch - WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}) - endif() - - # ############################################################################ - # Flags - # ############################################################################ - - set(CFLAGS -std=c99) - - # ############################################################################ - # Sources - # ############################################################################ - - set(CSRCS - ${TINYCBOR_DIR}/cborencoder.c - ${TINYCBOR_DIR}/cborencoder_close_container_checked.c - ${TINYCBOR_DIR}/cborencoder_float.c - ${TINYCBOR_DIR}/cborerrorstrings.c - ${TINYCBOR_DIR}/cborparser.c - ${TINYCBOR_DIR}/cborparser_dup_string.c - ${TINYCBOR_DIR}/cborparser_float.c - ${TINYCBOR_DIR}/cborpretty.c - ${TINYCBOR_DIR}/cborpretty_stdio.c - ${TINYCBOR_DIR}/cbortojson.c - ${TINYCBOR_DIR}/cborvalidation.c - ${TINYCBOR_DIR}/open_memstream.c) - - # ############################################################################ - # Include Directory - # ############################################################################ - - set(INCDIR ${CMAKE_CURRENT_LIST_DIR}) - - # ############################################################################ - # Library Configuration - # ############################################################################ - - nuttx_add_library(tinycbor STATIC) - target_sources(tinycbor PRIVATE ${CSRCS}) - target_include_directories(tinycbor PRIVATE ${INCDIR}) - target_compile_options(tinycbor PRIVATE ${CFLAGS}) - -endif() diff --git a/fsutils/libtinycbor/Kconfig b/fsutils/libtinycbor/Kconfig deleted file mode 100644 index e9f865e25..000000000 --- a/fsutils/libtinycbor/Kconfig +++ /dev/null @@ -1,17 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config FSUTILS_TINYCBOR_LIB - bool "TinyCBOR Library (RFC 8949)" - default n - depends on ALLOW_MIT_COMPONENTS - ---help--- - Enable support for the TinyCBOR library. This is an - implementation of RFC-8949 (Concise Binary Object - Representation). - More info: https://lupyuen.github.io/articles/cbor2 - -if FSUTILS_TINYCBOR_LIB -endif diff --git a/fsutils/libtinycbor/Make.defs b/fsutils/libtinycbor/Make.defs deleted file mode 100644 index 4465760a3..000000000 --- a/fsutils/libtinycbor/Make.defs +++ /dev/null @@ -1,26 +0,0 @@ -############################################################################ -# apps/fsutils/libtinycbor/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_FSUTILS_TINYCBOR_LIB),) -CONFIGURED_APPS += $(APPDIR)/fsutils/libtinycbor -CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/fsutils/libtinycbor -endif diff --git a/fsutils/libtinycbor/Makefile b/fsutils/libtinycbor/Makefile deleted file mode 100644 index 8d3424567..000000000 --- a/fsutils/libtinycbor/Makefile +++ /dev/null @@ -1,67 +0,0 @@ -############################################################################ -# apps/fsutils/libtinycbor/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -TINYCBOR_URL ?= "https://github.com/intel/tinycbor/archive" -TINYCBOR_VERSION ?= c0aad2fb2137a31b9845fbaae3653540c410f215 - -TINYCBOR_UNPACKNAME = tinycbor - -$(TINYCBOR_UNPACKNAME): - @echo "Downloading: $(TINYCBOR_UNPACKNAME)" - $(Q) curl -O -L $(TINYCBOR_URL)/$(TINYCBOR_VERSION).zip - $(Q) mkdir $(TINYCBOR_UNPACKNAME) - $(Q) unzip -o -j $(TINYCBOR_VERSION).zip -d $(TINYCBOR_UNPACKNAME) - $(Q) patch -Np1 < fix_open_memstream.patch - $(call DELFILE, $(TINYCBOR_VERSION).zip) - -# Files - -CSRCS += tinycbor/cborencoder.c -CSRCS += tinycbor/cborencoder_close_container_checked.c -CSRCS += tinycbor/cborencoder_float.c -CSRCS += tinycbor/cborerrorstrings.c -CSRCS += tinycbor/cborparser.c -CSRCS += tinycbor/cborparser_dup_string.c -CSRCS += tinycbor/cborparser_float.c -CSRCS += tinycbor/cborpretty.c -CSRCS += tinycbor/cborpretty_stdio.c -CSRCS += tinycbor/cbortojson.c -CSRCS += tinycbor/cborvalidation.c -CSRCS += tinycbor/open_memstream.c - -CFLAGS += -std=c99 -CFLAGS += -DCBOR_NO_HALF_FLOAT_TYPE - -clean:: - $(call DELFILE, $(OBJS)) - -# Download and unpack tarball if no git repo found -ifeq ($(wildcard $(TINYCBOR_UNPACKNAME)/.git),) -context:: $(TINYCBOR_UNPACKNAME) - -distclean:: - $(call DELDIR, $(TINYCBOR_UNPACKNAME)) -endif - -include $(APPDIR)/Application.mk diff --git a/fsutils/libtinycbor/fix_open_memstream.patch b/fsutils/libtinycbor/fix_open_memstream.patch deleted file mode 100644 index 832eff712..000000000 --- a/fsutils/libtinycbor/fix_open_memstream.patch +++ /dev/null @@ -1,33 +0,0 @@ -diff --git a/tinycbor/open_memstream.c b/tinycbor/open_memstream.c -index 3365378..37a0d08 100644 ---- a/tinycbor/open_memstream.c -+++ b/tinycbor/open_memstream.c -@@ -32,13 +32,13 @@ - #include - #include - --#if defined(__unix__) || defined(__APPLE__) -+#if defined(__unix__) || defined(__APPLE__) || defined(__NuttX__) - # include - #endif --#ifdef __APPLE__ -+#if defined(__APPLE__) - typedef int RetType; - typedef int LenType; --#elif __linux__ -+#elif defined(__linux__) || defined(__NuttX__) - typedef ssize_t RetType; - typedef size_t LenType; - #else -@@ -99,9 +99,9 @@ FILE *open_memstream(char **bufptr, size_t *lenptr) - *bufptr = NULL; - *lenptr = 0; - --#ifdef __APPLE__ -+#if defined(__APPLE__) - return funopen(b, NULL, write_to_buffer, NULL, close_buffer); --#elif __linux__ -+#elif defined(__linux__) || defined(__NuttX__) - static const cookie_io_functions_t vtable = { - NULL, - write_to_buffer, diff --git a/fsutils/mkfatfs/CMakeLists.txt b/fsutils/mkfatfs/CMakeLists.txt deleted file mode 100644 index 1c891d0bc..000000000 --- a/fsutils/mkfatfs/CMakeLists.txt +++ /dev/null @@ -1,31 +0,0 @@ -# ############################################################################## -# apps/fsutils/mkfatfs/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_FSUTILS_MKFATFS) - set(SRCS) - - include_directories(${CMAKE_CURRENT_BINARY_DIR}) - - list(APPEND SRCS mkfatfs.c configfat.c writefat.c) - - target_sources(apps PRIVATE ${SRCS}) -endif() diff --git a/fsutils/mkfatfs/Make.defs b/fsutils/mkfatfs/Make.defs index bdcae96a2..c1e6505f0 100644 --- a/fsutils/mkfatfs/Make.defs +++ b/fsutils/mkfatfs/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/fsutils/mkfatfs/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -20,6 +18,6 @@ # ############################################################################ -ifneq ($(CONFIG_FSUTILS_MKFATFS),) +ifeq ($(CONFIG_FSUTILS_MKFATFS),y) CONFIGURED_APPS += $(APPDIR)/fsutils/mkfatfs endif diff --git a/fsutils/mkfatfs/Makefile b/fsutils/mkfatfs/Makefile index 3c5c7d0ae..4a140de89 100644 --- a/fsutils/mkfatfs/Makefile +++ b/fsutils/mkfatfs/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/fsutils/mkfatfs/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/fsutils/mkfatfs/configfat.c b/fsutils/mkfatfs/configfat.c index 20f54d5af..94f72f7d9 100644 --- a/fsutils/mkfatfs/configfat.c +++ b/fsutils/mkfatfs/configfat.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/fsutils/mkfatfs/configfat.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -29,7 +27,7 @@ #include #include #include -#include +#include #include #include "fsutils/mkfatfs.h" @@ -76,7 +74,7 @@ struct fat_config_s * offset 3. */ -static const uint8_t g_bootcodeblob[] = +static uint8_t g_bootcodeblob[] = { 0x0e, 0x1f, 0xbe, 0x00, 0x7c, 0xac, 0x22, 0xc0, 0x74, 0x0b, 0x56, 0xb4, 0x0e, 0xbb, 0x07, 0x00, 0xcd, 0x10, 0x5e, 0xeb, 0xf0, 0x32, @@ -121,8 +119,13 @@ static inline uint32_t mkfatfs_nfatsect12(FAR struct fat_format_s *fmt, FAR struct fat_var_s *var, uint32_t navailsects) { +#ifdef CONFIG_HAVE_LONG_LONG uint64_t denom; uint64_t number; +#else + uint32_t denom; + uint32_t number; +#endif /* For FAT12, the cluster number is held in a 12-bit number or 1.5 bytes * per cluster reference. So each FAT sector will hold sectorsize/1.5 @@ -151,12 +154,25 @@ mkfatfs_nfatsect12(FAR struct fat_format_s *fmt, FAR struct fat_var_s *var, * navailsects > 0x55555555 - 2 * clustersize */ - denom = (fmt->ff_nfats << 1) + fmt->ff_nfats - + (var->fv_sectorsize << (fmt->ff_clustshift + 1)); - number = (navailsects << 1) + navailsects - + (1 << (fmt->ff_clustshift + 2)) - + (1 << (fmt->ff_clustshift + 1)); - return (uint32_t)((number + denom - 1) / denom); +#ifndef CONFIG_HAVE_LONG_LONG + if (navailsects <= (0x55555555 - (1 << (fmt->ff_clustshift + 1)))) + { +#endif + + denom = (fmt->ff_nfats << 1) + fmt->ff_nfats + + (var->fv_sectorsize << (fmt->ff_clustshift + 1)); + number = (navailsects << 1) + navailsects + + (1 << (fmt->ff_clustshift + 2)) + + (1 << (fmt->ff_clustshift + 1)); + return (uint32_t)((number + denom - 1) / denom); + +#ifndef CONFIG_HAVE_LONG_LONG + } + else + { + return 0; + } +#endif } /**************************************************************************** @@ -183,8 +199,13 @@ static inline uint32_t mkfatfs_nfatsect16(FAR struct fat_format_s *fmt, FAR struct fat_var_s *var, uint32_t navailsects) { +#ifdef CONFIG_HAVE_LONG_LONG uint64_t denom; uint64_t number; +#else + uint32_t denom; + uint32_t number; +#endif /* For FAT16, the cluster number is held in a 16-bit number or 2 bytes per * cluster reference. So each FAT sector will hold sectorsize/2 cluster @@ -247,8 +268,13 @@ static inline uint32_t mkfatfs_nfatsect32(FAR struct fat_format_s *fmt, FAR struct fat_var_s *var, uint32_t navailsects) { +#ifdef CONFIG_HAVE_LONG_LONG uint64_t denom; uint64_t number; +#else + uint32_t denom; + uint32_t number; +#endif /* For FAT32, the cluster number is held in a 32-bit number or 4 bytes per * cluster reference. So each FAT sector will hold sectorsize/4 cluster @@ -315,8 +341,6 @@ static inline uint8_t mkfatfs_clustersearchlimits(FAR struct fat_format_s *fmt, FAR struct fat_var_s *var) { - UNUSED(var); - uint8_t mxclustshift; /* Did the caller already pick the cluster size? If not, the clustshift @@ -697,7 +721,7 @@ mkfatfs_clustersearch(FAR struct fat_format_s *fmt, if (var->fv_fattype != 32) { - /* Calculate the number of sectors required to contain the selected + /* Calculate the number of sectors reqired to contain the selected * number of root directory entries. This value is save in the var * structure but will be overwritten if FAT32 is selected. FAT32 uses * a cluster chain for the root directory, so the concept of the number @@ -770,7 +794,7 @@ mkfatfs_clustersearch(FAR struct fat_format_s *fmt, { if ((!var->fv_fattype && fatconfig16.fc_nclusters > fatconfig12.fc_nclusters) || - (var->fv_fattype == 16)) + (var ->fv_fattype == 16)) { /* The caller has selected FAT16 -OR- no FAT type has been * selected, but the FAT16 selection has more clusters. @@ -899,7 +923,7 @@ int mkfatfs_configfatfs(FAR struct fat_format_s *fmt, var->fv_jump[0] = OPCODE_JMP_REL8; var->fv_jump[2] = OPCODE_NOP; - var->fv_bootcodeblob = g_bootcodeblob; + var->fv_bootcode = g_bootcodeblob; var->fv_bootcodesize = sizeof(g_bootcodeblob); if (var->fv_fattype != 32) @@ -908,15 +932,15 @@ int mkfatfs_configfatfs(FAR struct fat_format_s *fmt, /* Patch in the correct offset to the boot code */ - var->fv_jump[1] = MBR16_BOOTCODE - 2; - var->fv_bootcodepatch = MBR16_BOOTCODE + BOOTCODE_MSGOFFSET; + var->fv_jump[1] = MBR16_BOOTCODE - 2; + g_bootcodeblob[3] = MBR16_BOOTCODE + BOOTCODE_MSGOFFSET; } else { /* Patch in the correct offset to the boot code */ - var->fv_jump[1] = MBR32_BOOTCODE - 2; - var->fv_bootcodepatch = MBR32_BOOTCODE + BOOTCODE_MSGOFFSET; + var->fv_jump[1] = MBR32_BOOTCODE - 2; + g_bootcodeblob[3] = MBR32_BOOTCODE + BOOTCODE_MSGOFFSET; /* The root directory is a cluster chain... its is initialize size is * one cluster diff --git a/fsutils/mkfatfs/fat32.h b/fsutils/mkfatfs/fat32.h index 133e6f08b..a7a529b21 100644 --- a/fsutils/mkfatfs/fat32.h +++ b/fsutils/mkfatfs/fat32.h @@ -1,7 +1,5 @@ /**************************************************************************** - * apps/fsutils/mkfatfs/fat32.h - * - * SPDX-License-Identifier: Apache-2.0 + * apps/futils/mkfatfs/fat32.h * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -36,6 +34,7 @@ #include #include +#include /**************************************************************************** * Pre-processor Definitions @@ -111,14 +110,12 @@ #define EXTBOOT_SIGNATURE 0x29 -/* These offsets describes the partition table. - * 446@0: Generally unused and zero; but may include IDM Boot Manager menu - * entry at 8@394 +/**************************************************************************** + * These offsets describes the partition table. */ - -/* n = 0,1,2,3 */ - -#define PART_ENTRY(n) (446+((n) << 4)) + /* 446@0: Generally unused and zero; but may + * include IDM Boot Manager menu entry at 8@394 */ +#define PART_ENTRY(n) (446+((n) << 4)) /* n = 0,1,2,3 */ #define PART_ENTRY1 446 /* 16@446: Partition table, first entry */ #define PART_ENTRY2 462 /* 16@462: Partition table, second entry */ #define PART_ENTRY3 478 /* 16@478: Partition table, third entry */ @@ -262,48 +259,50 @@ #define CLUS_NDXMASK(f) ((f)->fs_fatsecperclus - 1) -/* The FAT "long" file name (LFN) directory entry */ +/**************************************************************************** + * The FAT "long" file name (LFN) directory entry */ #ifdef CONFIG_FAT_LFN /* Sizes and limits */ -# ifndef CONFIG_FAT_MAXFNAME /* The maximum support filename can be limited */ -# define LDIR_MAXFNAME 255 /* Max unicode characters in file name */ -# elif CONFIG_FAT_MAXFNAME <= 255 -# define LDIR_MAXFNAME CONFIG_FAT_MAXFNAME -# else -# error "Illegal value for CONFIG_FAT_MAXFNAME" -# endif +# ifndef CONFIG_FAT_MAXFNAME /* The maximum support filename can be limited */ +# define LDIR_MAXFNAME 255 /* Max unicode characters in file name */ +# elif CONFIG_FAT_MAXFNAME <= 255 +# define LDIR_MAXFNAME CONFIG_FAT_MAXFNAME +# else +# error "Illegal value for CONFIG_FAT_MAXFNAME" +# endif -# define LDIR_MAXLFNCHARS 13 /* Max unicode characters in one LFN entry */ -# define LDIR_MAXLFNS 20 /* Max number of LFN entries */ +# define LDIR_MAXLFNCHARS 13 /* Max unicode characters in one LFN entry */ +# define LDIR_MAXLFNS 20 /* Max number of LFN entries */ /* LFN directory entry offsets */ -# define LDIR_SEQ 0 /* 1@ 0: Sequence number */ -# define LDIR_WCHAR1_5 1 /* 10@ 1: File name characters 1-5 (5 Unicode characters) */ -# define LDIR_ATTRIBUTES 11 /* 1@11: File attributes (always 0x0f) */ -# define LDIR_NTRES 12 /* 1@12: Reserved for use by NT (always 0x00) */ -# define LDIR_CHECKSUM 13 /* 1@13: Checksum of the DOS filename */ -# define LDIR_WCHAR6_11 14 /* 12@14: File name characters 6-11 (6 Unicode characters) */ -# define LDIR_FSTCLUSTLO 26 /* 2@26: First cluster (always 0x0000) */ -# define LDIR_WCHAR12_13 28 /* 4@28: File name characters 12-13 (2 Unicode characters) */ +# define LDIR_SEQ 0 /* 1@ 0: Sequence number */ +# define LDIR_WCHAR1_5 1 /* 10@ 1: File name characters 1-5 (5 Unicode characters) */ +# define LDIR_ATTRIBUTES 11 /* 1@11: File attributes (always 0x0f) */ +# define LDIR_NTRES 12 /* 1@12: Reserved for use by NT (always 0x00) */ +# define LDIR_CHECKSUM 13 /* 1@13: Checksum of the DOS filename */ +# define LDIR_WCHAR6_11 14 /* 12@14: File name characters 6-11 (6 Unicode characters) */ +# define LDIR_FSTCLUSTLO 26 /* 2@26: First cluster (always 0x0000) */ +# define LDIR_WCHAR12_13 28 /* 4@28: File name characters 12-13 (2 Unicode characters) */ /* LFN sequence number and allocation status */ -# define LDIR0_EMPTY DIR0_EMPTY /* The directory entry is empty */ -# define LDIR0_ALLEMPTY DIR0_ALLEMPTY /* This entry and all following are empty */ -# define LDIR0_E5 DIR0_E5 /* The actual value is 0xe5 */ -# define LDIR0_LAST 0x40 /* Last LFN in file name (appears first) */ -# define LDIR0_SEQ_MASK 0x1f /* Mask for sequence number (1-20) */ +# define LDIR0_EMPTY DIR0_EMPTY /* The directory entry is empty */ +# define LDIR0_ALLEMPTY DIR0_ALLEMPTY /* This entry and all following are empty */ +# define LDIR0_E5 DIR0_E5 /* The actual value is 0xe5 */ +# define LDIR0_LAST 0x40 /* Last LFN in file name (appears first) */ +# define LDIR0_SEQ_MASK 0x1f /* Mask for sequence number (1-20) */ /* The LFN entry attribute */ -# define LDDIR_LFNATTR 0x0f +# define LDDIR_LFNATTR 0x0f #endif -/* File system types */ +/**************************************************************************** + * File system types */ #define FSTYPE_FAT12 0 #define FSTYPE_FAT16 1 @@ -343,8 +342,8 @@ * between FAT12, 16, and 32. */ -/* FAT12: For M$, the calculation is ((1 << 12) - 19). But we will follow - * the Linux tradition of allowing slightly more clusters for FAT12. +/* FAT12: For M$, the calculation is ((1 << 12) - 19). But we will follow the + * Linux tradition of allowing slightly more clusters for FAT12. */ #define FAT_MAXCLUST12 ((1 << 12) - 16) @@ -357,15 +356,16 @@ #define FAT_MAXCLUST16 (((uint32_t)1 << 16) - 16) /* FAT32: M$ reserves the MS 4 bits of a FAT32 FAT entry so only 18 bits are - * available. For M$, the calculation is ((1 << 28) - 19). (The uint32_t - * cast is needed for architectures where int is only 16 bits). M$ also - * claims that the minimum size is 65,527. + * available. For M$, the calculation is ((1 << 28) - 19). (The uint32_t cast + * is needed for architectures where int is only 16 bits). M$ also claims + * that the minimum size is 65,527. */ #define FAT_MINCLUST32 65524 /* #define FAT_MINCLUST32 (FAT_MAXCLUST16 + 1) */ #define FAT_MAXCLUST32 (((uint32_t)1 << 28) - 16) +/****************************************************************************/ /* Endian-ness helpers */ #ifdef CONFIG_ENDIAN_BIG @@ -455,10 +455,10 @@ #define DIR_PUTCRTTIMETENTH(p,v) UBYTE_PUT(p,DIR_CRTTIMETENTH,v) #ifdef CONFIG_FAT_LFN -# define LDIR_PUTSEQ(p,v) UBYTE_PUT(p,LDIR_SEQ,v) -# define LDIR_PUTATTRIBUTES(p,v) UBYTE_PUT(p,LDIR_ATTRIBUTES,v) -# define LDIR_PUTNTRES(p,v) UBYTE_PUT(p,LDIR_NTRES,v) -# define LDIR_PUTCHECKSUM(p,v) UBYTE_PUT(p,LDIR_CHECKSUM,v) +# define LDIR_PUTSEQ(p,v) UBYTE_PUT(p,LDIR_SEQ,v) +# define LDIR_PUTATTRIBUTES(p,v) UBYTE_PUT(p,LDIR_ATTRIBUTES,v) +# define LDIR_PUTNTRES(p,v) UBYTE_PUT(p,LDIR_NTRES,v) +# define LDIR_PUTCHECKSUM(p,v) UBYTE_PUT(p,LDIR_CHECKSUM,v) #endif /* For the all targets, unaligned values need to be accessed byte-by-byte. @@ -492,9 +492,9 @@ #define PART4_PUTSIZE(p,v) FAT_PUTUINT32(UBYTE_PTR(p,PART_ENTRY4+PART_SIZE),v) #ifdef CONFIG_FAT_LFN -# define LDIR_PTRWCHAR1_5(p) UBYTE_PTR(p,LDIR_WCHAR1_5) -# define LDIR_PTRWCHAR6_11(p) UBYTE_PTR(p,LDIR_WCHAR6_11) -# define LDIR_PTRWCHAR12_13(p) UBYTE_PTR(p,LDIR_WCHAR12_13) +# define LDIR_PTRWCHAR1_5(p) UBYTE_PTR(p,LDIR_WCHAR1_5) +# define LDIR_PTRWCHAR6_11(p) UBYTE_PTR(p,LDIR_WCHAR6_11) +# define LDIR_PTRWCHAR12_13(p) UBYTE_PTR(p,LDIR_WCHAR12_13) #endif /* But for multi-byte values, the endian-ness of the target vs. the little @@ -508,73 +508,73 @@ * accessed byte-by-byte. */ -# define MBR_PUTRESVDSECCOUNT(p,v) FAT_PUTUINT16(UBYTE_PTR(p,MBR_RESVDSECCOUNT),v) -# define MBR_PUTFATSZ16(p,v) FAT_PUTUINT16(UBYTE_PTR(p,MBR_FATSZ16),v) -# define MBR_PUTSECPERTRK(p,v) FAT_PUTUINT16(UBYTE_PTR(p,MBR_SECPERTRK),v) -# define MBR_PUTNUMHEADS(p,v) FAT_PUTUINT16(UBYTE_PTR(p,MBR_NUMHEADS),v) -# define MBR_PUTHIDSEC(p,v) FAT_PUTUINT32(UBYTE_PTR(p,MBR_HIDSEC),v) -# define MBR_PUTTOTSEC32(p,v) FAT_PUTUINT32(UBYTE_PTR(p,MBR_TOTSEC32),v) -# define MBR_PUTFATSZ32(p,v) FAT_PUTUINT32(UBYTE_PTR(p,MBR32_FATSZ32),v) -# define MBR_PUTEXTFLAGS(p,v) FAT_PUTUINT16(UBYTE_PTR(p,MBR32_EXTFLAGS),v) -# define MBR_PUTFSVER(p,v) FAT_PUTUINT16(UBYTE_PTR(p,MBR32_FSVER),v) -# define MBR_PUTROOTCLUS(p,v) FAT_PUTUINT32(UBYTE_PTR(p,MBR32_ROOTCLUS),v) -# define MBR_PUTFSINFO(p,v) FAT_PUTUINT16(UBYTE_PTR(p,MBR32_FSINFO),v) -# define MBR_PUTBKBOOTSEC(p,v) FAT_PUTUINT16(UBYTE_PTR(p,MBR32_BKBOOTSEC),v) -# define MBR_PUTSIGNATURE(p,v) FAT_PUTUINT16(UBYTE_PTR(p,MBR_SIGNATURE),v) +# define MBR_PUTRESVDSECCOUNT(p,v) FAT_PUTUINT16(UBYTE_PTR(p,MBR_RESVDSECCOUNT),v) +# define MBR_PUTFATSZ16(p,v) FAT_PUTUINT16(UBYTE_PTR(p,MBR_FATSZ16),v) +# define MBR_PUTSECPERTRK(p,v) FAT_PUTUINT16(UBYTE_PTR(p,MBR_SECPERTRK),v) +# define MBR_PUTNUMHEADS(p,v) FAT_PUTUINT16(UBYTE_PTR(p,MBR_NUMHEADS),v) +# define MBR_PUTHIDSEC(p,v) FAT_PUTUINT32(UBYTE_PTR(p,MBR_HIDSEC),v) +# define MBR_PUTTOTSEC32(p,v) FAT_PUTUINT32(UBYTE_PTR(p,MBR_TOTSEC32),v) +# define MBR_PUTFATSZ32(p,v) FAT_PUTUINT32(UBYTE_PTR(p,MBR32_FATSZ32),v) +# define MBR_PUTEXTFLAGS(p,v) FAT_PUTUINT16(UBYTE_PTR(p,MBR32_EXTFLAGS),v) +# define MBR_PUTFSVER(p,v) FAT_PUTUINT16(UBYTE_PTR(p,MBR32_FSVER),v) +# define MBR_PUTROOTCLUS(p,v) FAT_PUTUINT32(UBYTE_PTR(p,MBR32_ROOTCLUS),v) +# define MBR_PUTFSINFO(p,v) FAT_PUTUINT16(UBYTE_PTR(p,MBR32_FSINFO),v) +# define MBR_PUTBKBOOTSEC(p,v) FAT_PUTUINT16(UBYTE_PTR(p,MBR32_BKBOOTSEC),v) +# define MBR_PUTSIGNATURE(p,v) FAT_PUTUINT16(UBYTE_PTR(p,MBR_SIGNATURE),v) -# define FBR_PUTRESVDSECCOUNT(p,v) fat_putuint16(UBYTE_PTR(p,FBR_RESVDSECCOUNT),v) -# define FBR_PUTFATSZ16(p,v) fat_putuint16(UBYTE_PTR(p,FBR_FATSZ16),v) -# define FBR_PUTSECPERTRK(p,v) fat_putuint16(UBYTE_PTR(p,FBR_SECPERTRK),v) -# define FBR_PUTNUMHEADS(p,v) fat_putuint16(UBYTE_PTR(p,FBR_NUMHEADS),v) -# define FBR_PUTHIDSEC(p,v) fat_putuint32(UBYTE_PTR(p,FBR_HIDSEC),v) -# define FBR_PUTTOTSEC32(p,v) fat_putuint32(UBYTE_PTR(p,FBR_TOTSEC32),v) -# define FBR_PUTFATSZ32(p,v) fat_putuint32(UBYTE_PTR(p,FBR_FATSZ32),v) -# define FBR_PUTEXTFLAGS(p,v) fat_putuint16(UBYTE_PTR(p,FBR_EXTFLAGS),v) -# define FBR_PUTFSVER(p,v) fat_putuint16(UBYTE_PTR(p,FBR_FSVER),v) -# define FBR_PUTROOTCLUS(p,v) fat_putuint32(UBYTE_PTR(p,FBR_ROOTCLUS),v) -# define FBR_PUTFSINFO(p,v) fat_putuint16(UBYTE_PTR(p,FBR_FSINFO),v) -# define FBR_PUTBKBOOTSEC(p,v) fat_putuint16(UBYTE_PTR(p,FBR_BKBOOTSEC),v) -# define FBR_PUTSIGNATURE(p,v) fat_putuint16(UBYTE_PTR(p,FBR_SIGNATURE),v) +# define FBR_PUTRESVDSECCOUNT(p,v) fat_putuint16(UBYTE_PTR(p,FBR_RESVDSECCOUNT),v) +# define FBR_PUTFATSZ16(p,v) fat_putuint16(UBYTE_PTR(p,FBR_FATSZ16),v) +# define FBR_PUTSECPERTRK(p,v) fat_putuint16(UBYTE_PTR(p,FBR_SECPERTRK),v) +# define FBR_PUTNUMHEADS(p,v) fat_putuint16(UBYTE_PTR(p,FBR_NUMHEADS),v) +# define FBR_PUTHIDSEC(p,v) fat_putuint32(UBYTE_PTR(p,FBR_HIDSEC),v) +# define FBR_PUTTOTSEC32(p,v) fat_putuint32(UBYTE_PTR(p,FBR_TOTSEC32),v) +# define FBR_PUTFATSZ32(p,v) fat_putuint32(UBYTE_PTR(p,FBR_FATSZ32),v) +# define FBR_PUTEXTFLAGS(p,v) fat_putuint16(UBYTE_PTR(p,FBR_EXTFLAGS),v) +# define FBR_PUTFSVER(p,v) fat_putuint16(UBYTE_PTR(p,FBR_FSVER),v) +# define FBR_PUTROOTCLUS(p,v) fat_putuint32(UBYTE_PTR(p,FBR_ROOTCLUS),v) +# define FBR_PUTFSINFO(p,v) fat_putuint16(UBYTE_PTR(p,FBR_FSINFO),v) +# define FBR_PUTBKBOOTSEC(p,v) fat_putuint16(UBYTE_PTR(p,FBR_BKBOOTSEC),v) +# define FBR_PUTSIGNATURE(p,v) fat_putuint16(UBYTE_PTR(p,FBR_SIGNATURE),v) -# define FSI_PUTLEADSIG(p,v) FAT_PUTUINT32(UBYTE_PTR(p,FSI_LEADSIG),v) -# define FSI_PUTSTRUCTSIG(p,v) FAT_PUTUINT32(UBYTE_PTR(p,FSI_STRUCTSIG),v) -# define FSI_PUTFREECOUNT(p,v) FAT_PUTUINT32(UBYTE_PTR(p,FSI_FREECOUNT),v) -# define FSI_PUTNXTFREE(p,v) FAT_PUTUINT32(UBYTE_PTR(p,FSI_NXTFREE),v) -# define FSI_PUTTRAILSIG(p,v) FAT_PUTUINT32(UBYTE_PTR(p,FSI_TRAILSIG),v) +# define FSI_PUTLEADSIG(p,v) FAT_PUTUINT32(UBYTE_PTR(p,FSI_LEADSIG),v) +# define FSI_PUTSTRUCTSIG(p,v) FAT_PUTUINT32(UBYTE_PTR(p,FSI_STRUCTSIG),v) +# define FSI_PUTFREECOUNT(p,v) FAT_PUTUINT32(UBYTE_PTR(p,FSI_FREECOUNT),v) +# define FSI_PUTNXTFREE(p,v) FAT_PUTUINT32(UBYTE_PTR(p,FSI_NXTFREE),v) +# define FSI_PUTTRAILSIG(p,v) FAT_PUTUINT32(UBYTE_PTR(p,FSI_TRAILSIG),v) -# define DIR_PUTCRTIME(p,v) FAT_PUTUINT16(UBYTE_PTR(p,DIR_CRTIME),v) -# define DIR_PUTCRDATE(p,v) FAT_PUTUINT16(UBYTE_PTR(p,DIR_CRDATE),v) -# define DIR_PUTLASTACCDATE(p,v) FAT_PUTUINT16(UBYTE_PTR(p,DIR_LASTACCDATE),v) -# define DIR_PUTFSTCLUSTHI(p,v) FAT_PUTUINT16(UBYTE_PTR(p,DIR_FSTCLUSTHI),v) -# define DIR_PUTWRTTIME(p,v) FAT_PUTUINT16(UBYTE_PTR(p,DIR_WRTTIME),v) -# define DIR_PUTWRTDATE(p,v) FAT_PUTUINT16(UBYTE_PTR(p,DIR_WRTDATE),v) -# define DIR_PUTFSTCLUSTLO(p,v) FAT_PUTUINT16(UBYTE_PTR(p,DIR_FSTCLUSTLO),v) -# define DIR_PUTFILESIZE(p,v) FAT_PUTUINT32(UBYTE_PTR(p,DIR_FILESIZE),v) +# define DIR_PUTCRTIME(p,v) FAT_PUTUINT16(UBYTE_PTR(p,DIR_CRTIME),v) +# define DIR_PUTCRDATE(p,v) FAT_PUTUINT16(UBYTE_PTR(p,DIR_CRDATE),v) +# define DIR_PUTLASTACCDATE(p,v) FAT_PUTUINT16(UBYTE_PTR(p,DIR_LASTACCDATE),v) +# define DIR_PUTFSTCLUSTHI(p,v) FAT_PUTUINT16(UBYTE_PTR(p,DIR_FSTCLUSTHI),v) +# define DIR_PUTWRTTIME(p,v) FAT_PUTUINT16(UBYTE_PTR(p,DIR_WRTTIME),v) +# define DIR_PUTWRTDATE(p,v) FAT_PUTUINT16(UBYTE_PTR(p,DIR_WRTDATE),v) +# define DIR_PUTFSTCLUSTLO(p,v) FAT_PUTUINT16(UBYTE_PTR(p,DIR_FSTCLUSTLO),v) +# define DIR_PUTFILESIZE(p,v) FAT_PUTUINT32(UBYTE_PTR(p,DIR_FILESIZE),v) -# ifdef CONFIG_FAT_LFN -# define LDIR_PUTWCHAR1(p) FAT_PUTUINT16(UBYTE_PTR(p,LDIR_WCHAR1_5),v) -# define LDIR_PUTWCHAR2(p) FAT_PUTUINT16(UBYTE_PTR(p,LDIR_WCHAR1_5+2),v) -# define LDIR_PUTWCHAR3(p) FAT_PUTUINT16(UBYTE_PTR(p,LDIR_WCHAR1_5+4),v) -# define LDIR_PUTWCHAR4(p) FAT_PUTUINT16(UBYTE_PTR(p,LDIR_WCHAR1_5+6),v) -# define LDIR_PUTWCHAR5(p) FAT_PUTUINT16(UBYTE_PTR(p,LDIR_WCHAR1_5+8),v) -# define LDIR_PUTWCHAR6(p) FAT_PUTUINT16(UBYTE_PTR(p,LDIR_WCHAR6_11),v) -# define LDIR_PUTWCHAR7(p) FAT_PUTUINT16(UBYTE_PTR(p,LDIR_WCHAR6_11+2),v) -# define LDIR_PUTWCHAR8(p) FAT_PUTUINT16(UBYTE_PTR(p,LDIR_WCHAR6_11+4),v) -# define LDIR_PUTWCHAR9(p) FAT_PUTUINT16(UBYTE_PTR(p,LDIR_WCHAR6_11+6),v) -# define LDIR_PUTWCHAR10(p) FAT_PUTUINT16(UBYTE_PTR(p,LDIR_WCHAR6_11+8),v) -# define LDIR_PUTWCHAR11(p) FAT_PUTUINT16(UBYTE_PTR(p,LDIR_WCHAR6_11+10),v) -# define LDIR_PUTWCHAR12(p) FAT_PUTUINT16(UBYTE_PTR(p,LDIR_WCHAR12_13),v) -# define LDIR_PUTWCHAR13(p) FAT_PUTUINT16(UBYTE_PTR(p,LDIR_WCHAR12_13+2),v) -# endif +# ifdef CONFIG_FAT_LFN +# define LDIR_PUTWCHAR1(p) FAT_PUTUINT16(UBYTE_PTR(p,LDIR_WCHAR1_5),v) +# define LDIR_PUTWCHAR2(p) FAT_PUTUINT16(UBYTE_PTR(p,LDIR_WCHAR1_5+2),v) +# define LDIR_PUTWCHAR3(p) FAT_PUTUINT16(UBYTE_PTR(p,LDIR_WCHAR1_5+4),v) +# define LDIR_PUTWCHAR4(p) FAT_PUTUINT16(UBYTE_PTR(p,LDIR_WCHAR1_5+6),v) +# define LDIR_PUTWCHAR5(p) FAT_PUTUINT16(UBYTE_PTR(p,LDIR_WCHAR1_5+8),v) +# define LDIR_PUTWCHAR6(p) FAT_PUTUINT16(UBYTE_PTR(p,LDIR_WCHAR6_11),v) +# define LDIR_PUTWCHAR7(p) FAT_PUTUINT16(UBYTE_PTR(p,LDIR_WCHAR6_11+2),v) +# define LDIR_PUTWCHAR8(p) FAT_PUTUINT16(UBYTE_PTR(p,LDIR_WCHAR6_11+4),v) +# define LDIR_PUTWCHAR9(p) FAT_PUTUINT16(UBYTE_PTR(p,LDIR_WCHAR6_11+6),v) +# define LDIR_PUTWCHAR10(p) FAT_PUTUINT16(UBYTE_PTR(p,LDIR_WCHAR6_11+8),v) +# define LDIR_PUTWCHAR11(p) FAT_PUTUINT16(UBYTE_PTR(p,LDIR_WCHAR6_11+10),v) +# define LDIR_PUTWCHAR12(p) FAT_PUTUINT16(UBYTE_PTR(p,LDIR_WCHAR12_13),v) +# define LDIR_PUTWCHAR13(p) FAT_PUTUINT16(UBYTE_PTR(p,LDIR_WCHAR12_13+2),v) +# endif -# define FSI_PUTLEADSIG(p,v) FAT_PUTUINT32(UBYTE_PTR(p,FSI_LEADSIG),v) -# define FSI_PUTSTRUCTSIG(p,v) FAT_PUTUINT32(UBYTE_PTR(p,FSI_STRUCTSIG),v) -# define FSI_PUTFREECOUNT(p,v) FAT_PUTUINT32(UBYTE_PTR(p,FSI_FREECOUNT),v) -# define FSI_PUTNXTFREE(p,v) FAT_PUTUINT32(UBYTE_PTR(p,FSI_NXTFREE),v) -# define FSI_PUTTRAILSIG(p,v) FAT_PUTUINT32(UBYTE_PTR(p,FSI_TRAILSIG),v) +# define FSI_PUTLEADSIG(p,v) FAT_PUTUINT32(UBYTE_PTR(p,FSI_LEADSIG),v) +# define FSI_PUTSTRUCTSIG(p,v) FAT_PUTUINT32(UBYTE_PTR(p,FSI_STRUCTSIG),v) +# define FSI_PUTFREECOUNT(p,v) FAT_PUTUINT32(UBYTE_PTR(p,FSI_FREECOUNT),v) +# define FSI_PUTNXTFREE(p,v) FAT_PUTUINT32(UBYTE_PTR(p,FSI_NXTFREE),v) +# define FSI_PUTTRAILSIG(p,v) FAT_PUTUINT32(UBYTE_PTR(p,FSI_TRAILSIG),v) -# define FAT_PUTFAT16(p,i,v) FAT_PUTUINT16(UBYTE_PTR(p,i),v) -# define FAT_PUTFAT32(p,i,v) FAT_PUTUINT32(UBYTE_PTR(p,i),v) +# define FAT_PUTFAT16(p,i,v) FAT_PUTUINT16(UBYTE_PTR(p,i),v) +# define FAT_PUTFAT32(p,i,v) FAT_PUTUINT32(UBYTE_PTR(p,i),v) #else @@ -582,73 +582,73 @@ * to aligned multibyte values. */ -# define MBR_PUTRESVDSECCOUNT(p,v) UINT16_PUT(p,MBR_RESVDSECCOUNT,v) -# define MBR_PUTFATSZ16(p,v) UINT16_PUT(p,MBR_FATSZ16,v) -# define MBR_PUTSECPERTRK(p,v) UINT16_PUT(p,MBR_SECPERTRK,v) -# define MBR_PUTNUMHEADS(p,v) UINT16_PUT(p,MBR_NUMHEADS,v) -# define MBR_PUTHIDSEC(p,v) UINT32_PUT(p,MBR_HIDSEC,v) -# define MBR_PUTTOTSEC32(p,v) UINT32_PUT(p,MBR_TOTSEC32,v) -# define MBR_PUTFATSZ32(p,v) UINT32_PUT(p,MBR32_FATSZ32,v) -# define MBR_PUTEXTFLAGS(p,v) UINT16_PUT(p,MBR32_EXTFLAGS,v) -# define MBR_PUTFSVER(p,v) UINT16_PUT(p,MBR32_FSVER,v) -# define MBR_PUTROOTCLUS(p,v) UINT32_PUT(p,MBR32_ROOTCLUS,v) -# define MBR_PUTFSINFO(p,v) UINT16_PUT(p,MBR32_FSINFO,v) -# define MBR_PUTBKBOOTSEC(p,v) UINT16_PUT(p,MBR32_BKBOOTSEC,v) -# define MBR_PUTSIGNATURE(p,v) UINT16_PUT(p,MBR_SIGNATURE,v) +# define MBR_PUTRESVDSECCOUNT(p,v) UINT16_PUT(p,MBR_RESVDSECCOUNT,v) +# define MBR_PUTFATSZ16(p,v) UINT16_PUT(p,MBR_FATSZ16,v) +# define MBR_PUTSECPERTRK(p,v) UINT16_PUT(p,MBR_SECPERTRK,v) +# define MBR_PUTNUMHEADS(p,v) UINT16_PUT(p,MBR_NUMHEADS,v) +# define MBR_PUTHIDSEC(p,v) UINT32_PUT(p,MBR_HIDSEC,v) +# define MBR_PUTTOTSEC32(p,v) UINT32_PUT(p,MBR_TOTSEC32,v) +# define MBR_PUTFATSZ32(p,v) UINT32_PUT(p,MBR32_FATSZ32,v) +# define MBR_PUTEXTFLAGS(p,v) UINT16_PUT(p,MBR32_EXTFLAGS,v) +# define MBR_PUTFSVER(p,v) UINT16_PUT(p,MBR32_FSVER,v) +# define MBR_PUTROOTCLUS(p,v) UINT32_PUT(p,MBR32_ROOTCLUS,v) +# define MBR_PUTFSINFO(p,v) UINT16_PUT(p,MBR32_FSINFO,v) +# define MBR_PUTBKBOOTSEC(p,v) UINT16_PUT(p,MBR32_BKBOOTSEC,v) +# define MBR_PUTSIGNATURE(p,v) UINT16_PUT(p,MBR_SIGNATURE,v) -# define FBR_PUTRESVDSECCOUNT(p,v) UINT16_PUT(p,FBR_RESVDSECCOUNT,v) -# define FBR_PUTFATSZ16(p,v) UINT16_PUT(p,FBR_FATSZ16,v) -# define FBR_PUTSECPERTRK(p,v) UINT16_PUT(p,FBR_SECPERTRK,v) -# define FBR_PUTNUMHEADS(p,v) UINT16_PUT(p,FBR_NUMHEADS,v) -# define FBR_PUTHIDSEC(p,v) UINT32_PUT(p,FBR_HIDSEC,v) -# define FBR_PUTTOTSEC32(p,v) UINT32_PUT(p,FBR_TOTSEC32,v) -# define FBR_PUTFATSZ32(p,v) UINT32_PUT(p,FBR_FATSZ32,v) -# define FBR_PUTEXTFLAGS(p,v) UINT16_PUT(p,FBR_EXTFLAGS,v) -# define FBR_PUTFSVER(p,v) UINT16_PUT(p,FBR_FSVER,v) -# define FBR_PUTROOTCLUS(p,v) UINT32_PUT(p,FBR_ROOTCLUS,v) -# define FBR_PUTFSINFO(p,v) UINT16_PUT(p,FBR_FSINFO,v) -# define FBR_PUTBKBOOTSEC(p,v) UINT16_PUT(p,FBR_BKBOOTSEC,v) -# define FBR_PUTSIGNATURE(p,v) UINT16_PUT(p,FBR_SIGNATURE,v) +# define FBR_PUTRESVDSECCOUNT(p,v) UINT16_PUT(p,FBR_RESVDSECCOUNT,v) +# define FBR_PUTFATSZ16(p,v) UINT16_PUT(p,FBR_FATSZ16,v) +# define FBR_PUTSECPERTRK(p,v) UINT16_PUT(p,FBR_SECPERTRK,v) +# define FBR_PUTNUMHEADS(p,v) UINT16_PUT(p,FBR_NUMHEADS,v) +# define FBR_PUTHIDSEC(p,v) UINT32_PUT(p,FBR_HIDSEC,v) +# define FBR_PUTTOTSEC32(p,v) UINT32_PUT(p,FBR_TOTSEC32,v) +# define FBR_PUTFATSZ32(p,v) UINT32_PUT(p,FBR_FATSZ32,v) +# define FBR_PUTEXTFLAGS(p,v) UINT16_PUT(p,FBR_EXTFLAGS,v) +# define FBR_PUTFSVER(p,v) UINT16_PUT(p,FBR_FSVER,v) +# define FBR_PUTROOTCLUS(p,v) UINT32_PUT(p,FBR_ROOTCLUS,v) +# define FBR_PUTFSINFO(p,v) UINT16_PUT(p,FBR_FSINFO,v) +# define FBR_PUTBKBOOTSEC(p,v) UINT16_PUT(p,FBR_BKBOOTSEC,v) +# define FBR_PUTSIGNATURE(p,v) UINT16_PUT(p,FBR_SIGNATURE,v) -# define FSI_PUTLEADSIG(p,v) UINT32_PUT(p,FSI_LEADSIG,v) -# define FSI_PUTSTRUCTSIG(p,v) UINT32_PUT(p,FSI_STRUCTSIG,v) -# define FSI_PUTFREECOUNT(p,v) UINT32_PUT(p,FSI_FREECOUNT,v) -# define FSI_PUTNXTFREE(p,v) UINT32_PUT(p,FSI_NXTFREE,v) -# define FSI_PUTTRAILSIG(p,v) UINT32_PUT(p,FSI_TRAILSIG,v) +# define FSI_PUTLEADSIG(p,v) UINT32_PUT(p,FSI_LEADSIG,v) +# define FSI_PUTSTRUCTSIG(p,v) UINT32_PUT(p,FSI_STRUCTSIG,v) +# define FSI_PUTFREECOUNT(p,v) UINT32_PUT(p,FSI_FREECOUNT,v) +# define FSI_PUTNXTFREE(p,v) UINT32_PUT(p,FSI_NXTFREE,v) +# define FSI_PUTTRAILSIG(p,v) UINT32_PUT(p,FSI_TRAILSIG,v) -# define DIR_PUTCRTIME(p,v) UINT16_PUT(p,DIR_CRTIME,v) -# define DIR_PUTCRDATE(p,v) UINT16_PUT(p,DIR_CRDATE,v) -# define DIR_PUTLASTACCDATE(p,v) UINT16_PUT(p,DIR_LASTACCDATE,v) -# define DIR_PUTFSTCLUSTHI(p,v) UINT16_PUT(p,DIR_FSTCLUSTHI,v) -# define DIR_PUTWRTTIME(p,v) UINT16_PUT(p,DIR_WRTTIME,v) -# define DIR_PUTWRTDATE(p,v) UINT16_PUT(p,DIR_WRTDATE,v) -# define DIR_PUTFSTCLUSTLO(p,v) UINT16_PUT(p,DIR_FSTCLUSTLO,v) -# define DIR_PUTFILESIZE(p,v) UINT32_PUT(p,DIR_FILESIZE,v) +# define DIR_PUTCRTIME(p,v) UINT16_PUT(p,DIR_CRTIME,v) +# define DIR_PUTCRDATE(p,v) UINT16_PUT(p,DIR_CRDATE,v) +# define DIR_PUTLASTACCDATE(p,v) UINT16_PUT(p,DIR_LASTACCDATE,v) +# define DIR_PUTFSTCLUSTHI(p,v) UINT16_PUT(p,DIR_FSTCLUSTHI,v) +# define DIR_PUTWRTTIME(p,v) UINT16_PUT(p,DIR_WRTTIME,v) +# define DIR_PUTWRTDATE(p,v) UINT16_PUT(p,DIR_WRTDATE,v) +# define DIR_PUTFSTCLUSTLO(p,v) UINT16_PUT(p,DIR_FSTCLUSTLO,v) +# define DIR_PUTFILESIZE(p,v) UINT32_PUT(p,DIR_FILESIZE,v) # ifdef CONFIG_FAT_LFN -# define LDIR_PUTWCHAR1(p,v) UINT16_PUT(p,LDIR_WCHAR1_5,v) -# define LDIR_PUTWCHAR2(p,v) UINT16_PUT(p,LDIR_WCHAR1_5+2,v) -# define LDIR_PUTWCHAR3(p,v) UINT16_PUT(p,LDIR_WCHAR1_5+4,v) -# define LDIR_PUTWCHAR4(p,v) UINT16_PUT(p,LDIR_WCHAR1_5+6,v) -# define LDIR_PUTWCHAR5(p,v) UINT16_PUT(p,LDIR_WCHAR1_5+8,v) -# define LDIR_PUTWCHAR6(p,v) UINT16_PUT(p,LDIR_WCHAR6_11,v) -# define LDIR_PUTWCHAR7(p,v) UINT16_PUT(p,LDIR_WCHAR6_11+2,v) -# define LDIR_PUTWCHAR8(p,v) UINT16_PUT(p,LDIR_WCHAR6_11+4,v) -# define LDIR_PUTWCHAR9(p,v) UINT16_PUT(p,LDIR_WCHAR6_11+6,v) -# define LDIR_PUTWCHAR10(p,v) UINT16_PUT(p,LDIR_WCHAR6_11+8,v) -# define LDIR_PUTWCHAR11(p,v) UINT16_PUT(p,LDIR_WCHAR6_11+10,v) -# define LDIR_PUTWCHAR12(p,v) UINT16_PUT(p,LDIR_WCHAR12_13,v) -# define LDIR_PUTWCHAR13(p,v) UINT16_PUT(p,LDIR_WCHAR12_13+2,v) -# endif +# define LDIR_PUTWCHAR1(p,v) UINT16_PUT(p,LDIR_WCHAR1_5,v) +# define LDIR_PUTWCHAR2(p,v) UINT16_PUT(p,LDIR_WCHAR1_5+2,v) +# define LDIR_PUTWCHAR3(p,v) UINT16_PUT(p,LDIR_WCHAR1_5+4,v) +# define LDIR_PUTWCHAR4(p,v) UINT16_PUT(p,LDIR_WCHAR1_5+6,v) +# define LDIR_PUTWCHAR5(p,v) UINT16_PUT(p,LDIR_WCHAR1_5+8,v) +# define LDIR_PUTWCHAR6(p,v) UINT16_PUT(p,LDIR_WCHAR6_11,v) +# define LDIR_PUTWCHAR7(p,v) UINT16_PUT(p,LDIR_WCHAR6_11+2,v) +# define LDIR_PUTWCHAR8(p,v) UINT16_PUT(p,LDIR_WCHAR6_11+4,v) +# define LDIR_PUTWCHAR9(p,v) UINT16_PUT(p,LDIR_WCHAR6_11+6,v) +# define LDIR_PUTWCHAR10(p,v) UINT16_PUT(p,LDIR_WCHAR6_11+8,v) +# define LDIR_PUTWCHAR11(p,v) UINT16_PUT(p,LDIR_WCHAR6_11+10,v) +# define LDIR_PUTWCHAR12(p,v) UINT16_PUT(p,LDIR_WCHAR12_13,v) +# define LDIR_PUTWCHAR13(p,v) UINT16_PUT(p,LDIR_WCHAR12_13+2,v) +# endif -# define FSI_PUTLEADSIG(p,v) UINT32_PUT(p,FSI_LEADSIG,v) -# define FSI_PUTSTRUCTSIG(p,v) UINT32_PUT(p,FSI_STRUCTSIG,v) -# define FSI_PUTFREECOUNT(p,v) UINT32_PUT(p,FSI_FREECOUNT,v) -# define FSI_PUTNXTFREE(p,v) UINT32_PUT(p,FSI_NXTFREE,v) -# define FSI_PUTTRAILSIG(p,v) UINT32_PUT(p,FSI_TRAILSIG,v) +# define FSI_PUTLEADSIG(p,v) UINT32_PUT(p,FSI_LEADSIG,v) +# define FSI_PUTSTRUCTSIG(p,v) UINT32_PUT(p,FSI_STRUCTSIG,v) +# define FSI_PUTFREECOUNT(p,v) UINT32_PUT(p,FSI_FREECOUNT,v) +# define FSI_PUTNXTFREE(p,v) UINT32_PUT(p,FSI_NXTFREE,v) +# define FSI_PUTTRAILSIG(p,v) UINT32_PUT(p,FSI_TRAILSIG,v) -# define FAT_PUTFAT16(p,i,v) UINT16_PUT(p,i,v) -# define FAT_PUTFAT32(p,i,v) UINT32_PUT(p,i,v) +# define FAT_PUTFAT16(p,i,v) UINT16_PUT(p,i,v) +# define FAT_PUTFAT32(p,i,v) UINT32_PUT(p,i,v) #endif diff --git a/fsutils/mkfatfs/mkfatfs.c b/fsutils/mkfatfs/mkfatfs.c index 629d6bb76..15ba4a63a 100644 --- a/fsutils/mkfatfs/mkfatfs.c +++ b/fsutils/mkfatfs/mkfatfs.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/fsutils/mkfatfs/mkfatfs.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -31,9 +29,8 @@ #include #include #include -#include +#include #include -#include #include @@ -92,7 +89,7 @@ static uint32_t fat_systime2fattime(void) { /* Break done the seconds in date and time units */ - if (gmtime_r(&ts.tv_sec, &tm) != NULL) + if (gmtime_r((FAR const time_t *)&ts.tv_sec, &tm) != NULL) { /* FAT can only represent dates since 1980. struct tm can * represent dates since 1900. diff --git a/fsutils/mkfatfs/mkfatfs.h b/fsutils/mkfatfs/mkfatfs.h index e12e162cf..ad149911b 100644 --- a/fsutils/mkfatfs/mkfatfs.h +++ b/fsutils/mkfatfs/mkfatfs.h @@ -1,7 +1,5 @@ /**************************************************************************** - * apps/fsutils/mkfatfs/mkfatfs.h - * - * SPDX-License-Identifier: Apache-2.0 + * apps/futils/mkfatfs/mkfatfs.h * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -74,8 +72,7 @@ struct fat_var_s uint32_t fv_nfatsects; /* Number of sectors in each FAT */ uint32_t fv_nclusters; /* Number of clusters */ uint8_t *fv_sect; /* Allocated working sector buffer */ - uint8_t fv_bootcodepatch; /* FAT16/FAT32 Bootcode offset patch */ - const uint8_t *fv_bootcodeblob; /* Points to boot code to put into MBR */ + const uint8_t *fv_bootcode; /* Points to boot code to put into MBR */ }; /**************************************************************************** diff --git a/fsutils/mkfatfs/writefat.c b/fsutils/mkfatfs/writefat.c index 01837d05c..7bda89d0f 100644 --- a/fsutils/mkfatfs/writefat.c +++ b/fsutils/mkfatfs/writefat.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/fsutils/mkfatfs/writefat.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -31,8 +29,7 @@ #include #include #include -#include -#include +#include #include @@ -70,7 +67,7 @@ static int mkfatfs_devwrite(FAR const struct fat_format_s *fmt, /* Convert the sector number to a byte offset */ - if (sector < 0 || sector >= (off_t)fmt->ff_nsectors) + if (sector < 0 || sector >= fmt->ff_nsectors) { ferr("sector out of range: %ju\n", (intmax_t)sector); return -ESPIPE; @@ -140,7 +137,7 @@ static inline void mkfatfs_initmbr(FAR struct fat_format_s *fmt, /* 8@3: Usually "MSWIN4.1" */ - memcpy(&var->fv_sect[MBR_OEMNAME], "NUTTX ", 8); + strcpy((FAR char *)&var->fv_sect[MBR_OEMNAME], "NUTTX "); /* 2@11: Bytes per sector: 512, 1024, 2048, 4096 */ @@ -206,7 +203,7 @@ static inline void mkfatfs_initmbr(FAR struct fat_format_s *fmt, /* The following fields are only valid for FAT12/16 */ - /* 1@36: Drive number for MS-DOS bootstrap -- left zero */ + /* 1@36: Drive number for MSDOS bootstrap -- left zero */ /* 1@37: Reserved (zero) */ @@ -235,12 +232,8 @@ static inline void mkfatfs_initmbr(FAR struct fat_format_s *fmt, /* Boot code may be placed in the remainder of the sector */ - memcpy(&var->fv_sect[MBR16_BOOTCODE], var->fv_bootcodeblob, + memcpy(&var->fv_sect[MBR16_BOOTCODE], var->fv_bootcode, var->fv_bootcodesize); - - /* Patch in the correct offset to the boot code */ - - var->fv_sect[MBR16_BOOTCODE + 3] = var->fv_bootcodepatch; } else { @@ -268,7 +261,7 @@ static inline void mkfatfs_initmbr(FAR struct fat_format_s *fmt, /* 12@52: Reserved (zero) */ - /* 1@64: Drive number for MS-DOS bootstrap -- left zero */ + /* 1@64: Drive number for MSDOS bootstrap -- left zero */ /* 1@65: Reserved (zero) */ @@ -290,12 +283,8 @@ static inline void mkfatfs_initmbr(FAR struct fat_format_s *fmt, /* Boot code may be placed in the remainder of the sector */ - memcpy(&var->fv_sect[MBR32_BOOTCODE], var->fv_bootcodeblob, + memcpy(&var->fv_sect[MBR32_BOOTCODE], var->fv_bootcode, var->fv_bootcodesize); - - /* Patch in the correct offset to the boot code */ - - var->fv_sect[MBR32_BOOTCODE + 3] = var->fv_bootcodepatch; } /* The magic bytes at the end of the MBR are common to FAT12/16/32 */ @@ -323,8 +312,6 @@ static inline void mkfatfs_initmbr(FAR struct fat_format_s *fmt, static inline void mkfatfs_initfsinfo(FAR struct fat_format_s *fmt, FAR struct fat_var_s *var) { - UNUSED(fmt); - memset(var->fv_sect, 0, var->fv_sectorsize); /* 4@0: 0x41615252 = "RRaA" */ @@ -486,8 +473,8 @@ static inline int mkfatfs_writefat(FAR struct fat_format_s *fmt, FAR struct fat_var_s *var) { off_t offset = fmt->ff_rsvdseccount; - uint8_t fatno; - uint32_t sectno; + int fatno; + int sectno; int ret; /* Loop for each FAT copy */ diff --git a/fsutils/mkgpt/CMakeLists.txt b/fsutils/mkgpt/CMakeLists.txt deleted file mode 100644 index a4e580279..000000000 --- a/fsutils/mkgpt/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# ############################################################################## -# apps/fsutils/mkgpt/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_FSUTILS_MKGPT) - nuttx_add_application( - NAME - mkgpt - PRIORITY - 100 - STACKSIZE - ${CONFIG_DEFAULT_TASK_STACKSIZE} - MODULE - ${CONFIG_FSUTILS_MKGPT} - SRCS - mkgpt.c) -endif() diff --git a/fsutils/mkgpt/Make.defs b/fsutils/mkgpt/Make.defs index b003bdabc..9f92d81cf 100644 --- a/fsutils/mkgpt/Make.defs +++ b/fsutils/mkgpt/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/fsutils/mkgpt/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/fsutils/mkgpt/Makefile b/fsutils/mkgpt/Makefile index 71deb540d..1379ac488 100644 --- a/fsutils/mkgpt/Makefile +++ b/fsutils/mkgpt/Makefile @@ -1,7 +1,5 @@ ############################################################################ -# apps/fsutils/mkgpt/Makefile -# -# SPDX-License-Identifier: Apache-2.0 +# apps/fsutils/mkgpt/Make.defs # # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with diff --git a/fsutils/mkgpt/mkgpt.c b/fsutils/mkgpt/mkgpt.c index 994902067..ac2744861 100644 --- a/fsutils/mkgpt/mkgpt.c +++ b/fsutils/mkgpt/mkgpt.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/fsutils/mkgpt/mkgpt.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -24,6 +22,7 @@ * Included Files ****************************************************************************/ +#include #include #include #include @@ -32,13 +31,10 @@ #include #include #include -#include #include #include -#include - /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ @@ -131,7 +127,13 @@ static const uint8_t g_partition_type_swap[16] = static void get_uuid(FAR uint8_t *uuid) { - arc4random_buf(uuid, 16); + int fd; + fd = open("/dev/urandom", O_RDONLY); + if (fd > 0) + { + read(fd, uuid, 16); + close(fd); + } } static void init_mbr(FAR uint8_t *mbr, uint32_t blocks) @@ -470,12 +472,6 @@ int main(int argc, FAR char **argv) } ret = verify_gpt_pratition(ptbl); - if (ret < 0) - { - lib_dumpbuffer("Dump GPT partition:", (FAR uint8_t *)ptbl, - sizeof(*ptbl)); - } - goto out; } diff --git a/fsutils/mkmbr/CMakeLists.txt b/fsutils/mkmbr/CMakeLists.txt deleted file mode 100644 index e7d16ae66..000000000 --- a/fsutils/mkmbr/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# ############################################################################## -# apps/fsutils/mkmbr/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_FSUTILS_MKMBR) - nuttx_add_application( - NAME - mkmbr - PRIORITY - 100 - STACKSIZE - ${CONFIG_DEFAULT_TASK_STACKSIZE} - MODULE - ${CONFIG_FSUTILS_MKMBR} - SRCS - mkmbr.c) -endif() diff --git a/fsutils/mkmbr/Make.defs b/fsutils/mkmbr/Make.defs index efa3c5bb8..89de722cc 100644 --- a/fsutils/mkmbr/Make.defs +++ b/fsutils/mkmbr/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/fsutils/mkmbr/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/fsutils/mkmbr/Makefile b/fsutils/mkmbr/Makefile index 7da62a0c9..96abeff1a 100644 --- a/fsutils/mkmbr/Makefile +++ b/fsutils/mkmbr/Makefile @@ -1,7 +1,5 @@ ############################################################################ -# apps/fsutils/mkmbr/Makefile -# -# SPDX-License-Identifier: Apache-2.0 +# apps/fsutils/mkmbr/Make.defs # # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with diff --git a/fsutils/mkmbr/mkmbr.c b/fsutils/mkmbr/mkmbr.c index 233e7ac89..9c0251233 100644 --- a/fsutils/mkmbr/mkmbr.c +++ b/fsutils/mkmbr/mkmbr.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/fsutils/mkmbr/mkmbr.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -113,10 +111,8 @@ int main(int argc, FAR char *argv[]) int argn; int fd; int ret; - int nr_part; - nr_part = (argc - 2) / 2; - if (argc < 4 || argc % 2 != 0 || nr_part > 4) + if (argc < 4 || argc % 2 != 0) { print_usage(); return EINVAL; @@ -137,7 +133,7 @@ int main(int argc, FAR char *argv[]) next = 1; bsize = st.st_size / 512; mbr_init(&mbr); - for (partn = 0; partn < nr_part && next < bsize; partn++) + for (partn = 0; partn < 4 && next < bsize; partn++) { argn = 2 * (partn + 1); if (!strcmp(argv[argn], "auto")) diff --git a/fsutils/mksmartfs/CMakeLists.txt b/fsutils/mksmartfs/CMakeLists.txt deleted file mode 100644 index 822704e68..000000000 --- a/fsutils/mksmartfs/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -# ############################################################################## -# apps/fsutils/mksmartfs/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_FSUTILS_MKSMARTFS) - target_sources(apps PRIVATE mksmartfs.c) -endif() diff --git a/fsutils/mksmartfs/Make.defs b/fsutils/mksmartfs/Make.defs index 5430e44e0..d9b5afeb0 100644 --- a/fsutils/mksmartfs/Make.defs +++ b/fsutils/mksmartfs/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/fsutils/mksmartfs/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -20,6 +18,6 @@ # ############################################################################ -ifneq ($(CONFIG_FSUTILS_MKSMARTFS),) +ifeq ($(CONFIG_FSUTILS_MKSMARTFS),y) CONFIGURED_APPS += $(APPDIR)/fsutils/mksmartfs endif diff --git a/fsutils/mksmartfs/Makefile b/fsutils/mksmartfs/Makefile index a54bb4db3..a6da40b04 100644 --- a/fsutils/mksmartfs/Makefile +++ b/fsutils/mksmartfs/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/fsutils/mksmartfs/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/fsutils/mksmartfs/mksmartfs.c b/fsutils/mksmartfs/mksmartfs.c index 9e16840cf..46f17ef2a 100644 --- a/fsutils/mksmartfs/mksmartfs.c +++ b/fsutils/mksmartfs/mksmartfs.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/fsutils/mksmartfs/mksmartfs.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/fsutils/passwd/CMakeLists.txt b/fsutils/passwd/CMakeLists.txt deleted file mode 100644 index 16caf1258..000000000 --- a/fsutils/passwd/CMakeLists.txt +++ /dev/null @@ -1,44 +0,0 @@ -# ############################################################################## -# apps/fsutils/passwd/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_FSUTILS_PASSWD) - set(CSRCS) - - list(APPEND CSRCS passwd_verify.c passwd_find.c passwd_encrypt.c - passwd_pbkdf2.c) - - if(NOT CONFIG_FSUTILS_PASSWD_READONLY) - list( - APPEND - CSRCS - passwd_adduser.c - passwd_deluser.c - passwd_update.c - passwd_append.c - passwd_delete.c - passwd_lock.c) - endif() - - set_property(GLOBAL APPEND PROPERTY NUTTX_APPS_LIBRARIES ${TARGET}) - target_sources(apps PRIVATE ${CSRCS}) - -endif() diff --git a/fsutils/passwd/Kconfig b/fsutils/passwd/Kconfig index 9d6ba3944..4f40349fc 100644 --- a/fsutils/passwd/Kconfig +++ b/fsutils/passwd/Kconfig @@ -6,22 +6,8 @@ config FSUTILS_PASSWD bool "Password file support" default n - depends on CRYPTO_CRYPTODEV - depends on CRYPTO_CRYPTODEV_SOFTWARE_CRYPTO || CRYPTO_CRYPTODEV_HARDWARE - depends on NETUTILS_CODECS - depends on CODECS_BASE64 ---help--- - Enables support for /etc/passwd file access routines. - - Requires CONFIG_CRYPTO=y, CRYPTO_CRYPTODEV (and - ALLOW_BSD_COMPONENTS), a cryptodev backend - (CONFIG_CRYPTO_CRYPTODEV_SOFTWARE_CRYPTO or - CONFIG_CRYPTO_CRYPTODEV_HARDWARE), plus NETUTILS_CODECS/CODECS_BASE64 - for base64url hash encoding. - - NOTE: Password hashes use PBKDF2-HMAC-SHA256 (modular crypt format). - Existing TEA-encrypted /etc/passwd entries are NOT compatible and - must be regenerated. + Enables support for /etc/passwd file access routines if FSUTILS_PASSWD @@ -37,14 +23,20 @@ config FSUTILS_PASSWD_IOBUFFER_SIZE int "Allocated I/O buffer size" default 512 -config FSUTILS_PASSWD_PBKDF2_ITERATIONS - int "Default PBKDF2 iteration count for new passwords" - default 10000 - range 1000 200000 - ---help--- - Number of PBKDF2-HMAC-SHA256 iterations applied when setting a new - password. Higher values slow brute-force attacks but also increase - login latency on low-MHz MCUs. The iteration count is stored in each - hash string, so changing this option only affects newly-set passwords. +config FSUTILS_PASSWD_KEY1 + hex "Encryption key value 1" + default 0x12345678 + +config FSUTILS_PASSWD_KEY2 + hex "Encryption key value 2" + default 0x9abcdef0 + +config FSUTILS_PASSWD_KEY3 + hex "Encryption key value 3" + default 0x12345678 + +config FSUTILS_PASSWD_KEY4 + hex "Encryption key value 4" + default 0x9abcdef0 endif # FSUTILS_PASSWD diff --git a/fsutils/passwd/Make.defs b/fsutils/passwd/Make.defs index 021b4d62c..6163c32e0 100644 --- a/fsutils/passwd/Make.defs +++ b/fsutils/passwd/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/fsutils/passwd/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -20,6 +18,6 @@ # ############################################################################ -ifneq ($(CONFIG_FSUTILS_PASSWD),) +ifeq ($(CONFIG_FSUTILS_PASSWD),y) CONFIGURED_APPS += $(APPDIR)/fsutils/passwd endif diff --git a/fsutils/passwd/Makefile b/fsutils/passwd/Makefile index d15b1c6db..0efe36ce3 100644 --- a/fsutils/passwd/Makefile +++ b/fsutils/passwd/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/fsutils/passwd/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -26,7 +24,6 @@ include $(APPDIR)/Make.defs ifeq ($(CONFIG_FSUTILS_PASSWD),y) CSRCS += passwd_verify.c passwd_find.c passwd_encrypt.c -CSRCS += passwd_pbkdf2.c ifneq ($(CONFIG_FSUTILS_PASSWD_READONLY),y) CSRCS += passwd_adduser.c passwd_deluser.c passwd_update.c passwd_append.c CSRCS += passwd_delete.c passwd_lock.c diff --git a/fsutils/passwd/passwd.h b/fsutils/passwd/passwd.h index e617cef37..2169ce988 100644 --- a/fsutils/passwd/passwd.h +++ b/fsutils/passwd/passwd.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/fsutils/passwd/passwd.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -36,18 +34,17 @@ * Pre-processor Definitions ****************************************************************************/ -/* MCF format: $pbkdf2-sha256$$$ */ +#define MAX_ENCRYPTED 48 /* Maximum size of a password (encrypted, ASCII) */ +#define MAX_USERNAME 48 /* Maximum size of a username */ +#define MAX_RECORD (MAX_USERNAME + MAX_ENCRYPTED + 1) -#define PASSWD_MCF_PREFIX "$pbkdf2-sha256$" -#define PASSWD_SALT_BYTES 16 -#define PASSWD_HASH_BYTES 32 +/* The TEA incryption algorithm generates 8 bytes of encrypted data per + * 8 bytes of unencrypted data. The encrypted presentation is base64 which + * is 8-bits of ASCII for each 6 bits of data. That is a 3-to-4 expansion + * ratio. MAX_ENCRYPTED must be a multiple of 8 bytes. + */ -/* 15 + 6 + 1 + 22 + 1 + 43 = 88 bytes for default parameters */ - -#define MAX_ENCRYPTED 96 -#define MAX_USERNAME 48 -#define MAX_RECORD (MAX_USERNAME + MAX_ENCRYPTED + 1) -#define MAX_PASSWORD 256 +#define MAX_PASSWORD (3 * MAX_ENCRYPTED / 4) /**************************************************************************** * Public Types @@ -56,7 +53,7 @@ struct passwd_s { off_t offset; /* File offset (start of record) */ - char encrypted[MAX_ENCRYPTED + 1]; /* Password hash in file */ + char encrypted[MAX_ENCRYPTED + 1]; /* Encrtyped password in file */ }; /**************************************************************************** @@ -95,11 +92,10 @@ void passwd_unlock(FAR sem_t *sem); * Name: passwd_encrypt * * Description: - * Hash a password with PBKDF2-HMAC-SHA256 and encode the result in modular - * crypt format for storage in /etc/passwd. + * Encrypt a password. Currently uses the Tiny Encryption Algorithm. * * Input Parameters: - * password -- The password string to be hashed + * password -- The password string to be encrypted * * Returned Value: * Zero (OK) is returned on success; a negated errno value is returned on diff --git a/fsutils/passwd/passwd_adduser.c b/fsutils/passwd/passwd_adduser.c index 3a14ac812..9dd6d8d3b 100644 --- a/fsutils/passwd/passwd_adduser.c +++ b/fsutils/passwd/passwd_adduser.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/fsutils/passwd/passwd_adduser.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/fsutils/passwd/passwd_append.c b/fsutils/passwd/passwd_append.c index 125a4cfe6..32f7a0381 100644 --- a/fsutils/passwd/passwd_append.c +++ b/fsutils/passwd/passwd_append.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/fsutils/passwd/passwd_append.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -66,11 +64,11 @@ int passwd_append(FAR const char *username, FAR const char *password) stream = fopen(CONFIG_FSUTILS_PASSWD_PATH, "a"); if (stream == NULL) - { + { int errcode = errno; DEBUGASSERT(errcode > 0); - return -errcode; - } + return errcode; + } /* The format of the password file is: * diff --git a/fsutils/passwd/passwd_delete.c b/fsutils/passwd/passwd_delete.c index cb9562c4e..5ac12be94 100644 --- a/fsutils/passwd/passwd_delete.c +++ b/fsutils/passwd/passwd_delete.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/fsutils/passwd/passwd_delete.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/fsutils/passwd/passwd_deluser.c b/fsutils/passwd/passwd_deluser.c index 0c4b07746..a1a26c0f5 100644 --- a/fsutils/passwd/passwd_deluser.c +++ b/fsutils/passwd/passwd_deluser.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/fsutils/passwd/passwd_deluser.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -27,6 +25,7 @@ #include #include "fsutils/passwd.h" + #include "passwd.h" /**************************************************************************** diff --git a/fsutils/passwd/passwd_encrypt.c b/fsutils/passwd/passwd_encrypt.c index c1e8b941e..2db003108 100644 --- a/fsutils/passwd/passwd_encrypt.c +++ b/fsutils/passwd/passwd_encrypt.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/fsutils/passwd/passwd_encrypt.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -25,145 +23,85 @@ ****************************************************************************/ #include -#include -#include -#include -#include +#include #include #include -#include -#include +#include -#include +#include #include "passwd.h" -#include "passwd_pbkdf2.h" /**************************************************************************** - * Pre-processor Definitions + * Private Data ****************************************************************************/ -#ifndef CONFIG_FSUTILS_PASSWD_PBKDF2_ITERATIONS -# define CONFIG_FSUTILS_PASSWD_PBKDF2_ITERATIONS 10000 -#endif +/* This should be better protected */ -#define PASSWD_MIN_LENGTH 8 - -static const char g_password_specials[] = - "!@#$%^&*()_+-=[]{}|;:,.<>?"; +static uint32_t g_tea_key[4] = +{ + CONFIG_FSUTILS_PASSWD_KEY1, + CONFIG_FSUTILS_PASSWD_KEY2, + CONFIG_FSUTILS_PASSWD_KEY3, + CONFIG_FSUTILS_PASSWD_KEY4 +}; /**************************************************************************** * Private Functions ****************************************************************************/ -static int validate_password_complexity(FAR const char *password) -{ - FAR const char *p; - size_t passlen; - int has_upper = 0; - int has_lower = 0; - int has_digit = 0; - int has_special = 0; - - passlen = strlen(password); - if (passlen < PASSWD_MIN_LENGTH) - { - _err("ERROR: password must be at least %d characters\n", - PASSWD_MIN_LENGTH); - return -EINVAL; - } - - if (passlen > MAX_PASSWORD) - { - _err("ERROR: password must be at most %d characters\n", MAX_PASSWORD); - return -EINVAL; - } - - for (p = password; *p != '\0'; p++) - { - if (isupper((unsigned char)*p)) - { - has_upper = 1; - } - else if (islower((unsigned char)*p)) - { - has_lower = 1; - } - else if (isdigit((unsigned char)*p)) - { - has_digit = 1; - } - else if (strchr(g_password_specials, *p) != NULL) - { - has_special = 1; - } - } - - if (!has_upper) - { - _err("ERROR: password must contain at least one uppercase " - "letter (A-Z)\n"); - return -EINVAL; - } - - if (!has_lower) - { - _err("ERROR: password must contain at least one lowercase " - "letter (a-z)\n"); - return -EINVAL; - } - - if (!has_digit) - { - _err("ERROR: password must contain at least one digit (0-9)\n"); - return -EINVAL; - } - - if (!has_special) - { - _err("ERROR: password must contain at least one special " - "character (!@#$%%^&*()_+-=[]{}|;:,.<>?)\n"); - return -EINVAL; - } - - return OK; -} - /**************************************************************************** - * Name: passwd_fill_random + * Name: passwd_base64 * * Description: - * Fill a buffer with random bytes using getrandom() or /dev/urandom. + * Encode a 5 bit value as a base64 character. + * + * Input Parameters: + * binary - 5 bit value + * + * Returned Value: + * The ASCII base64 character. Must not return the field delimiter ':' * ****************************************************************************/ -static int passwd_fill_random(FAR uint8_t *buf, size_t len) +static char passwd_base64(uint8_t binary) { - ssize_t nread; - int fd; + /* 0-26 -> 'A'-'Z' */ - nread = getrandom(buf, len, 0); - if (nread == (ssize_t)len) + binary &= 63; + if (binary < 26) { - return OK; + return 'A' + binary; } - fd = open("/dev/urandom", O_RDONLY); - if (fd < 0) + /* 26-51 -> 'a'-'z' */ + + binary -= 26; + if (binary < 26) { - return -errno; + return 'a' + binary; } - nread = read(fd, buf, len); - close(fd); + /* 52->61 -> '0'-'9' */ - if (nread != (ssize_t)len) + binary -= 26; + if (binary < 10) { - return nread < 0 ? -errno : -EIO; + return '0' + binary; } - return OK; + /* 62 -> '+' */ + + binary -= 10; + if (binary == 0) + { + return '+'; + } + + /* 63 -> '/' */ + + return '/'; } /**************************************************************************** @@ -174,66 +112,109 @@ static int passwd_fill_random(FAR uint8_t *buf, size_t len) * Name: passwd_encrypt * * Description: - * Hash a password with PBKDF2-HMAC-SHA256 and encode as modular crypt - * format: $pbkdf2-sha256$$$ + * Encrypt a password. Currently uses the Tiny Encryption Algorithm. + * + * Input Parameters: + * password -- The password string to be encrypted + * + * Returned Value: + * Zero (OK) is returned on success; a negated errno value is returned on + * failure. * ****************************************************************************/ -int passwd_encrypt(FAR const char *password, - char encrypted[MAX_ENCRYPTED + 1]) +int passwd_encrypt(FAR const char *password, char encrypted[MAX_ENCRYPTED + 1]) { - uint8_t salt[PASSWD_SALT_BYTES]; - uint8_t hash[PASSWD_HASH_BYTES]; - char salt_b64[32]; - char hash_b64[48]; - size_t passlen; - int ret; + union + { + char b[8]; + uint16_t h[4]; + uint32_t l[2]; + } value; - ret = validate_password_complexity(password); - if (ret < 0) - { - return ret; - } + FAR const char *src; + FAR char *bptr; + FAR char *dest; + uint32_t tmp; + uint8_t remainder; + int remaining; + int converted; + int gulpsize; + int nbits; + int i; - passlen = strlen(password); + /* How long is the password? */ - ret = passwd_fill_random(salt, sizeof(salt)); - if (ret < 0) - { - return ret; - } - - ret = passwd_pbkdf2_hmac_sha256((FAR const uint8_t *)password, passlen, - salt, sizeof(salt), - CONFIG_FSUTILS_PASSWD_PBKDF2_ITERATIONS, - hash, sizeof(hash)); - if (ret < 0) - { - return ret; - } - - ret = base64url_encode(salt, sizeof(salt), salt_b64, - sizeof(salt_b64)); - if (ret < 0) - { - return ret; - } - - ret = base64url_encode(hash, sizeof(hash), hash_b64, - sizeof(hash_b64)); - if (ret < 0) - { - return ret; - } - - ret = snprintf(encrypted, MAX_ENCRYPTED + 1, - PASSWD_MCF_PREFIX "%u$%s$%s", - CONFIG_FSUTILS_PASSWD_PBKDF2_ITERATIONS, - salt_b64, hash_b64); - if (ret < 0 || (size_t)ret > MAX_ENCRYPTED) + remaining = strlen(password); + if (remaining > MAX_PASSWORD) { return -E2BIG; } + /* Convert the password in 8-byte TEA cycles */ + + src = password; + dest = encrypted; + *dest = '\0'; + + remainder = 0; + nbits = 0; + + for (converted = 0; converted < remaining; converted += 8) + { + /* Copy bytes */ + + gulpsize = 8; + if (gulpsize > remaining) + { + gulpsize = remaining; + } + + bptr = value.b; + for (i = 0; i < gulpsize; i++) + { + *bptr++ = *src++; + } + + /* Pad with spaces if necessary */ + + for (; i < 8; i++) + { + *bptr++ = ' '; + } + + /* Perform the conversion for this cycle */ + + tea_encrypt(value.l, g_tea_key); + + /* Generate the base64 output string from this cycle */ + + tmp = remainder; + + for (i = 0; i < 4; i++) + { + tmp = (uint32_t)value.h[i] << nbits | tmp; + nbits += 16; + + while (nbits >= 6) + { + *dest++ = passwd_base64((uint8_t)(tmp & 0x3f)); + tmp >>= 6; + nbits -= 6; + } + } + + remainder = (uint8_t)tmp; + *dest = '\0'; + } + + /* Handle any remainder */ + + if (nbits > 0) + { + *dest++ = passwd_base64(remainder); + *dest = '\0'; + } + return OK; } diff --git a/fsutils/passwd/passwd_find.c b/fsutils/passwd/passwd_find.c index d12d7fbef..0ba671ed0 100644 --- a/fsutils/passwd/passwd_find.c +++ b/fsutils/passwd/passwd_find.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/fsutils/passwd/passwd_find.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -75,10 +73,6 @@ int passwd_find(FAR const char *username, FAR struct passwd_s *passwd) stream = fopen(CONFIG_FSUTILS_PASSWD_PATH, "r"); if (stream == NULL) { - /* Free an I/O buffer for the transfer */ - - free(iobuffer); - int errcode = errno; DEBUGASSERT(errcode > 0); return -errcode; @@ -155,7 +149,8 @@ int passwd_find(FAR const char *username, FAR struct passwd_s *passwd) } passwd->offset = offset; - strlcpy(passwd->encrypted, encrypted, MAX_ENCRYPTED); + strncpy(passwd->encrypted, encrypted, MAX_ENCRYPTED); + passwd->encrypted[MAX_ENCRYPTED] = '\0'; ret = OK; break; diff --git a/fsutils/passwd/passwd_lock.c b/fsutils/passwd/passwd_lock.c index 4cfd38094..1ed64d62e 100644 --- a/fsutils/passwd/passwd_lock.c +++ b/fsutils/passwd/passwd_lock.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/fsutils/passwd/passwd_lock.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/fsutils/passwd/passwd_pbkdf2.c b/fsutils/passwd/passwd_pbkdf2.c deleted file mode 100644 index e070387ab..000000000 --- a/fsutils/passwd/passwd_pbkdf2.c +++ /dev/null @@ -1,114 +0,0 @@ -/**************************************************************************** - * apps/fsutils/passwd/passwd_pbkdf2.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include -#include -#include -#include -#include - -#include "passwd_pbkdf2.h" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -int passwd_pbkdf2_hmac_sha256(FAR const uint8_t *pass, size_t passlen, - FAR const uint8_t *salt, size_t saltlen, - uint32_t iterations, - FAR uint8_t *out, size_t outlen) -{ - struct session_op session; - struct crypt_op cryp; - int cryptodev_fd = -1; - int fd = -1; - int ret = 0; - - if (pass == NULL || salt == NULL || out == NULL || passlen == 0 || - saltlen == 0 || iterations == 0 || outlen == 0) - { - return -EINVAL; - } - - fd = open("/dev/crypto", O_RDWR, 0); - if (fd < 0) - { - return -errno; - } - - if (ioctl(fd, CRIOGET, &cryptodev_fd) < 0) - { - ret = -errno; - goto errout; - } - - memset(&session, 0, sizeof(session)); - session.cipher = 0; - session.mac = CRYPTO_PBKDF2_HMAC_SHA256; - session.mackey = (caddr_t)pass; - session.mackeylen = passlen; - - if (ioctl(cryptodev_fd, CIOCGSESSION, &session) < 0) - { - ret = -errno; - goto errout; - } - - memset(&cryp, 0, sizeof(cryp)); - cryp.ses = session.ses; - cryp.op = COP_ENCRYPT; - cryp.src = (caddr_t)salt; - cryp.len = saltlen; - cryp.mac = (caddr_t)out; - cryp.iterations = iterations; - cryp.olen = outlen; - - if (ioctl(cryptodev_fd, CIOCCRYPT, &cryp) < 0) - { - ret = -errno; - goto errout_with_session; - } - -errout_with_session: - ioctl(cryptodev_fd, CIOCFSESSION, &session.ses); - -errout: - if (cryptodev_fd >= 0) - { - close(cryptodev_fd); - } - - if (fd >= 0) - { - close(fd); - } - - return ret; -} diff --git a/fsutils/passwd/passwd_pbkdf2.h b/fsutils/passwd/passwd_pbkdf2.h deleted file mode 100644 index 1a66109fa..000000000 --- a/fsutils/passwd/passwd_pbkdf2.h +++ /dev/null @@ -1,44 +0,0 @@ -/**************************************************************************** - * apps/fsutils/passwd/passwd_pbkdf2.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __APPS_FSUTILS_PASSWD_PASSWD_PBKDF2_H -#define __APPS_FSUTILS_PASSWD_PASSWD_PBKDF2_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -int passwd_pbkdf2_hmac_sha256(FAR const uint8_t *pass, size_t passlen, - FAR const uint8_t *salt, size_t saltlen, - uint32_t iterations, - FAR uint8_t *out, size_t outlen); - -#endif /* __APPS_FSUTILS_PASSWD_PASSWD_PBKDF2_H */ diff --git a/fsutils/passwd/passwd_update.c b/fsutils/passwd/passwd_update.c index 3066dbb5d..b96e79396 100644 --- a/fsutils/passwd/passwd_update.c +++ b/fsutils/passwd/passwd_update.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/fsutils/passwd/passwd_update.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -27,7 +25,7 @@ #include #include "fsutils/passwd.h" -#include "passwd.h" +#include /**************************************************************************** * Public Functions diff --git a/fsutils/passwd/passwd_verify.c b/fsutils/passwd/passwd_verify.c index fef8da6df..08b96989d 100644 --- a/fsutils/passwd/passwd_verify.c +++ b/fsutils/passwd/passwd_verify.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/fsutils/passwd/passwd_verify.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -24,105 +22,11 @@ * Included Files ****************************************************************************/ -#include - -#include -#include -#include #include +#include -#include -#include - +#include "fsutils/passwd.h" #include "passwd.h" -#include "passwd_pbkdf2.h" - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: passwd_verify_hash - * - * Description: - * Verify a password against a stored PBKDF2-SHA256 modular crypt hash. - * Rejects any hash not in $pbkdf2-sha256$ format. - * - * Returned Value: - * 0 on match, -1 on mismatch or parse error. - * - ****************************************************************************/ - -static int passwd_verify_hash(FAR const char *stored, - FAR const char *password) -{ - FAR const char *p; - FAR const char *salt_b64; - FAR const char *hash_b64; - char *endptr; - uint8_t salt[PASSWD_SALT_BYTES]; - uint8_t expected[PASSWD_HASH_BYTES]; - uint8_t actual[PASSWD_HASH_BYTES]; - size_t saltlen; - size_t hashlen; - size_t passlen; - unsigned long iterations; - int ret; - - if (strncmp(stored, PASSWD_MCF_PREFIX, strlen(PASSWD_MCF_PREFIX)) != 0) - { - return -1; - } - - p = stored + strlen(PASSWD_MCF_PREFIX); - iterations = strtoul(p, &endptr, 10); - if (endptr == p || *endptr != '$' || iterations < 1 || - iterations > 200000) - { - return -1; - } - - salt_b64 = endptr + 1; - hash_b64 = strchr(salt_b64, '$'); - if (hash_b64 == NULL) - { - return -1; - } - - ret = base64url_decode(salt_b64, salt, sizeof(salt), &saltlen); - if (ret < 0 || saltlen == 0) - { - return -1; - } - - ret = base64url_decode(hash_b64 + 1, expected, sizeof(expected), - &hashlen); - if (ret < 0 || hashlen != PASSWD_HASH_BYTES) - { - return -1; - } - - passlen = strlen(password); - if (passlen == 0 || passlen > MAX_PASSWORD) - { - return -1; - } - - ret = passwd_pbkdf2_hmac_sha256((FAR const uint8_t *)password, passlen, - salt, saltlen, (uint32_t)iterations, - actual, sizeof(actual)); - if (ret < 0) - { - return -1; - } - - if (timingsafe_bcmp(actual, expected, sizeof(expected)) != 0) - { - return -1; - } - - return 0; -} /**************************************************************************** * Public Functions @@ -133,33 +37,53 @@ static int passwd_verify_hash(FAR const char *stored, * * Description: * Return true if the username exists in the /etc/passwd file and if the - * password matches the user password in that file. + * password matches the user password in that failed. + * + * Input Parameters: * * Returned Value: - * Zero (0) is returned on a successful match, -1 on mismatch or invalid - * hash format; a negated errno value is returned on other failures. + * One (1) is returned on success match, Zero (OK) is returned on an + * unsuccessful match; a negated errno value is returned on any other + * failure. * ****************************************************************************/ int passwd_verify(FAR const char *username, FAR const char *password) { struct passwd_s passwd; + char encrypted[MAX_ENCRYPTED + 1]; PASSWD_SEM_DECL(sem); int ret; + /* Get exclusive access to the /etc/passwd file */ + ret = passwd_lock(&sem); if (ret < 0) { return ret; } + /* Verify that the username exists in the /etc/passwd file */ + ret = passwd_find(username, &passwd); + if (ret < 0) + { + /* The username does not exist in the /etc/passwd file */ + + goto errout_with_lock; + } + + /* Encrypt the provided password */ + + ret = passwd_encrypt(password, encrypted); if (ret < 0) { goto errout_with_lock; } - ret = passwd_verify_hash(passwd.encrypted, password); + /* Compare the encrypted passwords */ + + ret = (strcmp(passwd.encrypted, encrypted) == 0) ? 1 : 0; errout_with_lock: passwd_unlock(sem); diff --git a/games/.gitignore b/games/.gitignore deleted file mode 100644 index 9e1d2593e..000000000 --- a/games/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/Kconfig diff --git a/games/CMakeLists.txt b/games/CMakeLists.txt deleted file mode 100644 index 51680d9d6..000000000 --- a/games/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -# ############################################################################## -# apps/games/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -nuttx_add_subdirectory() - -nuttx_generate_kconfig(MENUDESC "Games") diff --git a/games/Makefile b/games/Makefile deleted file mode 100644 index 480a6fc94..000000000 --- a/games/Makefile +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/games/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -MENUDESC = "Games" - -include $(APPDIR)/Directory.mk diff --git a/games/NXDoom/.gitignore b/games/NXDoom/.gitignore deleted file mode 100644 index 58cf415e6..000000000 --- a/games/NXDoom/.gitignore +++ /dev/null @@ -1,70 +0,0 @@ -CMDLINE -INSTALL -Makefile.in -Make.dep -TAGS -aclocal.m4 -autom4te.cache -autotools -bin -config.hin -config.log -config.status -configure -lib -obj -rpm.spec -stamp-h -stamp-h.in -stamp-h1 -tags -\#*\# -DOOM*.png -HTIC*.png -HEXEN*.png -STRIFE*.png -DOOM*.pcx -HTIC*.pcx -HEXEN*.pcx -STRIFE*.pcx - -# CMake-specific ignores -/.vs -/build* -/CMakeSettings.json -/out - -# These are the default patterns globally ignored by Subversion: -.depend -.built -*.o -*.gcno -*.gcda -*.lo -*.la -*.al -.libs -*.so -*.so.[0-9]* -*.a -*.pyc -*.pyo -*.rej -*~ -.#* -.*.swp -.DS_store - -# Ignore GNU Global tags and html files -GPATH -GRTAGS -GTAGS -/HTML/ - -# VSCode settings - -/.vscode/ - -# clangd settings -/.cache/clangd -compile_commands.json diff --git a/games/NXDoom/AUTHORS b/games/NXDoom/AUTHORS deleted file mode 100644 index 6324caae4..000000000 --- a/games/NXDoom/AUTHORS +++ /dev/null @@ -1,7 +0,0 @@ -Simon Howard -James Haley -Samuel Villarreal -Fabian Greffrath -Jonathan Dowland -Alexey Khokholov -Turo Lamminen diff --git a/games/NXDoom/COPYING.md b/games/NXDoom/COPYING.md deleted file mode 100644 index 28fbecabf..000000000 --- a/games/NXDoom/COPYING.md +++ /dev/null @@ -1,361 +0,0 @@ -### GNU GENERAL PUBLIC LICENSE - -Version 2, June 1991 - - Copyright (C) 1989, 1991 Free Software Foundation, Inc. - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA - - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - -### Preamble - -The licenses for most software are designed to take away your freedom -to share and change it. By contrast, the GNU General Public License is -intended to guarantee your freedom to share and change free -software--to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Lesser General Public License instead.) You can apply it to -your programs, too. - -When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -this service if you wish), that you receive source code or can get it -if you want it, that you can change the software or use pieces of it -in new free programs; and that you know you can do these things. - -To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if -you distribute copies of the software, or if you modify it. - -For example, if you distribute copies of such a program, whether -gratis or for a fee, you must give the recipients all the rights that -you have. You must make sure that they, too, receive or can get the -source code. And you must show them these terms so they know their -rights. - -We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. - -Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, -we want its recipients to know that what they have is not the -original, so that any problems introduced by others will not reflect -on the original authors' reputations. - -Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at -all. - -The precise terms and conditions for copying, distribution and -modification follow. - -### TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - -**0.** This License applies to any program or other work which -contains a notice placed by the copyright holder saying it may be -distributed under the terms of this General Public License. The -"Program", below, refers to any such program or work, and a "work -based on the Program" means either the Program or any derivative work -under copyright law: that is to say, a work containing the Program or -a portion of it, either verbatim or with modifications and/or -translated into another language. (Hereinafter, translation is -included without limitation in the term "modification".) Each licensee -is addressed as "you". - -Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the Program -(independent of having been made by running the Program). Whether that -is true depends on what the Program does. - -**1.** You may copy and distribute verbatim copies of the Program's -source code as you receive it, in any medium, provided that you -conspicuously and appropriately publish on each copy an appropriate -copyright notice and disclaimer of warranty; keep intact all the -notices that refer to this License and to the absence of any warranty; -and give any other recipients of the Program a copy of this License -along with the Program. - -You may charge a fee for the physical act of transferring a copy, and -you may at your option offer warranty protection in exchange for a -fee. - -**2.** You may modify your copy or copies of the Program or any -portion of it, thus forming a work based on the Program, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - -**a)** You must cause the modified files to carry prominent notices -stating that you changed the files and the date of any change. - - -**b)** You must cause any work that you distribute or publish, that in -whole or in part contains or is derived from the Program or any part -thereof, to be licensed as a whole at no charge to all third parties -under the terms of this License. - - -**c)** If the modified program normally reads commands interactively -when run, you must cause it, when started running for such interactive -use in the most ordinary way, to print or display an announcement -including an appropriate copyright notice and a notice that there is -no warranty (or else, saying that you provide a warranty) and that -users may redistribute the program under these conditions, and telling -the user how to view a copy of this License. (Exception: if the -Program itself is interactive but does not normally print such an -announcement, your work based on the Program is not required to print -an announcement.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Program, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote -it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Program. - -In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - -**3.** You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: - - -**a)** Accompany it with the complete corresponding machine-readable -source code, which must be distributed under the terms of Sections 1 -and 2 above on a medium customarily used for software interchange; or, - - -**b)** Accompany it with a written offer, valid for at least three -years, to give any third party, for a charge no more than your cost of -physically performing source distribution, a complete machine-readable -copy of the corresponding source code, to be distributed under the -terms of Sections 1 and 2 above on a medium customarily used for -software interchange; or, - - -**c)** Accompany it with the information you received as to the offer -to distribute corresponding source code. (This alternative is allowed -only for noncommercial distribution and only if you received the -program in object code or executable form with such an offer, in -accord with Subsection b above.) - -The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, complete source -code means all the source code for all modules it contains, plus any -associated interface definition files, plus the scripts used to -control compilation and installation of the executable. However, as a -special exception, the source code distributed need not include -anything that is normally distributed (in either source or binary -form) with the major components (compiler, kernel, and so on) of the -operating system on which the executable runs, unless that component -itself accompanies the executable. - -If distribution of executable or object code is made by offering -access to copy from a designated place, then offering equivalent -access to copy the source code from the same place counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. - -**4.** You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt otherwise -to copy, modify, sublicense or distribute the Program is void, and -will automatically terminate your rights under this License. However, -parties who have received copies, or rights, from you under this -License will not have their licenses terminated so long as such -parties remain in full compliance. - -**5.** You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. - -**6.** Each time you redistribute the Program (or any work based on -the Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program subject to -these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to -this License. - -**7.** If, as a consequence of a court judgment or allegation of -patent infringement or for any other reason (not limited to patent -issues), conditions are imposed on you (whether by court order, -agreement or otherwise) that contradict the conditions of this -License, they do not excuse you from the conditions of this License. -If you cannot distribute so as to satisfy simultaneously your -obligations under this License and any other pertinent obligations, -then as a consequence you may not distribute the Program at all. For -example, if a patent license would not permit royalty-free -redistribution of the Program by all those who receive copies directly -or indirectly through you, then the only way you could satisfy both it -and this License would be to refrain entirely from distribution of the -Program. - -If any portion of this section is held invalid or unenforceable under -any particular circumstance, the balance of the section is intended to -apply and the section as a whole is intended to apply in other -circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system, which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - -**8.** If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program under this License -may add an explicit geographical distribution limitation excluding -those countries, so that distribution is permitted only in or among -countries not thus excluded. In such case, this License incorporates -the limitation as if written in the body of this License. - -**9.** The Free Software Foundation may publish revised and/or new -versions of the General Public License from time to time. Such new -versions will be similar in spirit to the present version, but may -differ in detail to address new problems or concerns. - -Each version is given a distinguishing version number. If the Program -specifies a version number of this License which applies to it and -"any later version", you have the option of following the terms and -conditions either of that version or of any later version published by -the Free Software Foundation. If the Program does not specify a -version number of this License, you may choose any version ever -published by the Free Software Foundation. - -**10.** If you wish to incorporate parts of the Program into other -free programs whose distribution conditions are different, write to -the author to ask for permission. For software which is copyrighted by -the Free Software Foundation, write to the Free Software Foundation; -we sometimes make exceptions for this. Our decision will be guided by -the two goals of preserving the free status of all derivatives of our -free software and of promoting the sharing and reuse of software -generally. - -**NO WARRANTY** - -**11.** BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO -WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. -EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR -OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY -KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE -PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME -THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - -**12.** IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN -WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY -AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU -FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR -CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE -PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING -RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A -FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF -SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH -DAMAGES. - -### END OF TERMS AND CONDITIONS - -### How to Apply These Terms to Your New Programs - -If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these -terms. - -To do so, attach the following notices to the program. It is safest to -attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - one line to give the program's name and an idea of what it does. - Copyright (C) yyyy name of author - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License - as published by the Free Software Foundation; either version 2 - of the License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - -Also add information on how to contact you by electronic and paper -mail. - -If the program is interactive, make it output a short notice like this -when it starts in an interactive mode: - - Gnomovision version 69, Copyright (C) year name of author - Gnomovision comes with ABSOLUTELY NO WARRANTY; for details - type `show w'. This is free software, and you are welcome - to redistribute it under certain conditions; type `show c' - for details. - -The hypothetical commands \`show w' and \`show c' should show the -appropriate parts of the General Public License. Of course, the -commands you use may be called something other than \`show w' and -\`show c'; they could even be mouse-clicks or menu items--whatever -suits your program. - -You should also get your employer (if you work as a programmer) or -your school, if any, to sign a "copyright disclaimer" for the program, -if necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright - interest in the program `Gnomovision' - (which makes passes at compilers) written - by James Hacker. - - signature of Ty Coon, 1 April 1989 - Ty Coon, President of Vice - -This General Public License does not permit incorporating your program -into proprietary programs. If your program is a subroutine library, -you may consider it more useful to permit linking proprietary -applications with the library. If this is what you want to do, use the -[GNU Lesser General Public -License](https://www.gnu.org/licenses/lgpl.html) instead of this -License. diff --git a/games/NXDoom/Kconfig b/games/NXDoom/Kconfig deleted file mode 100644 index d2bd2080f..000000000 --- a/games/NXDoom/Kconfig +++ /dev/null @@ -1,262 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config GAMES_NXDOOM - bool "NXDoom" - default n - depends on ALLOW_GPL_COMPONENTS - depends on VIDEO_FB - depends on CRYPTO - depends on LIBC_LOCALE - ---help--- - Play DOOM on NuttX! - -if GAMES_NXDOOM - -comment "Program options" - -config GAMES_NXDOOM_PRIORITY - int "Priority" - default 100 - ---help--- - The task priority for the NXDoom application. - -config GAMES_NXDOOM_STACKSIZE - int "Stack size" - default 4096 - ---help--- - The stack size for the NXDoom application. - -comment "General game options" - -choice # Language - prompt "Game language" - default GAMES_NXDOOM_LANG_EN - - config GAMES_NXDOOM_LANG_EN - bool "English" - ---help--- - English language support (original). - - config GAMES_NXDOOM_LANG_FR - bool "French" - ---help--- - French language support. -endchoice # Language - -config GAMES_NXDOOM_PREFDIR - string "DOOM data directory" - default "/data" - ---help--- - Directory where DOOM WAD files are stored. - -config GAMES_NXDOOM_ENDOOM - bool "Show ENDOOM" - default n - ---help--- - Show the ENDOOM screen (https://www.doomwiki.org/wiki/ENDOOM). - -comment "Networking options" - -config GAMES_NXDOOM_NET - bool "Enable network features" - default n - ---help--- - Not ported! Will not work. - -if GAMES_NXDOOM_NET - -config GAMES_NXDOOM_NET_LOGS - bool "Enable network logging" - default n - ---help--- - Enables log information from the network features. - -config GAMES_NXDOOM_NET_MAXPLAYERS - int "Maximum number of players" - default 6 - ---help--- - The maximum number of players, multiplayer/networking. - This is the maximum supported by the networking code; individual games - have their own values for MAXPLAYERS that can be smaller. - ChocolateDOOM default was 8. - -config GAMES_NXDOOM_NET_BACKUPTICS - int "Maximum number of backup tics" - default 32 - ---help--- - The maximum number of backup tics to store locally during a net game. - ChocalateDOOM default was 128. - -config GAMES_NXDOOM_NET_MAXPLAYERNAME - int "Maximum player name length" - default 16 - ---help--- - The maximum number of characters in a player name for netgames. - ChocalateDOOM default was 30. - -endif # GAMES_NXDOOM_NET - -comment "Sound options" - -config GAMES_NXDOOM_SOUND - bool "Enable sound features" - default n - ---help--- - Not ported! Will not work. - -if GAMES_NXDOOM_SOUND - -config GAMES_NXDOOM_RTTTL_MUSIC - bool "RTTTL music" - default n - depends on AUDIOUTILS_RTTTL_C - depends on !DISABLE_PTHREAD - ---help--- - Play music using RTTTL. - -config GAMES_NXDOOM_RTTTL_DEVICE - string "RTTTL device" - default "/dev/pwm0" - depends on GAMES_NXDOOM_RTTTL_MUSIC - ---help--- - Device for RTTTL output (only PWM currently supported). - -endif # GAMES_NXDOOM_SOUND - -comment "Graphics options" - -config GAMES_NXDOOM_FBPATH - string "Framebuffer path" - default "/dev/fb0" - ---help--- - Path to the framebuffer character driver to use for rendering. - -comment "Input options" - -choice # Input method - prompt "NXDoom input method" - default GAMES_NXDOOM_KEYBOARD - - config GAMES_NXDOOM_KEYBOARD - bool "Keyboard" - ---help--- - Use a NuttX keyboard character driver. - -endchoice # Input method - -if GAMES_NXDOOM_KEYBOARD - -config GAMES_NXDOOM_KBDPATH - string "Keyboard device path" - default "/dev/kbd0" - ---help--- - Path to the keyboard device to use as input. - -endif # GAMES_NXDOOM_KEYBOARD - -config GAMES_NXDOOM_FB_CMAP - bool "Draw through the frame buffer colour map" - default n - ---help--- - DOOM draws into an 8-bit palettised buffer and normally converts - every pixel to the pixel format of the frame buffer as it blits. - A frame buffer that has a colour map of its own can do that - conversion in hardware while it scans the display out, so enable - this to load the DOOM palette into the colour map and blit the - palette indices unconverted. - - This needs a frame buffer that is 8 bits per pixel and supports - FBIOPUT_CMAP, such as an STM32 LTDC layer configured for L8. It - both removes the conversion and halves the amount of data written - per frame, which matters most when the frame buffer is external - memory. - -config GAMES_NXDOOM_FILLSCREEN - bool "Stretch the image to the whole display" - default n - ---help--- - By default the 320x200 image is scaled by the largest whole number - that fits, which leaves a border on a display whose size is not an - exact multiple of it. Enable this to stretch the image over the - entire frame buffer instead, which fills the display at the cost of - a scale factor that is not uniform across the image. - -config GAMES_NXDOOM_ROWSTAGE - bool "Build each output row in a staging buffer" - default n - ---help--- - Expand each row into a staging buffer and copy it to the frame - buffer, rather than writing the frame buffer a pixel at a time. - Every frame buffer access then becomes a burst-friendly copy, which - is worth a lot when the frame buffer is external memory and the - data cache is in write-through mode, and little otherwise. - - Costs a few kilobytes of .bss for the buffer. A row that does not - fit is written directly, as if this were disabled. - -config GAMES_NXDOOM_STATIC_SCRNBUF - bool "Place the render target in .bss" - default n - ---help--- - DOOM renders into a 320x200 buffer that is normally taken from the - heap. On a board whose heap is mostly slow external memory the - allocation lands there, which is close to the worst case: the - renderer draws in vertical columns, so consecutive writes are one - screen width apart and none of them coalesce. - - Enable this to make the buffer a static object instead, so the - linker places it in internal RAM along with the rest of .bss. It - costs 64000 bytes of RAM whether DOOM runs or not, so it is only - worth it when internal RAM is plentiful and the heap is not. - -comment "Optimizations" - -config GAMES_NXDOOM_MAXVISPLANES - int "Maximum number of visplanes" - default 96 - ---help--- - DOOM allocates a static number of 'visplanes' to use for gameplay. The - original ChocolateDOOM source uses 128 of these. They take a significant - amount of memory, so you may reduce the number. However, too few planes - may cause 'visplane overflow' errors, which is more common in complex - levels. - -config GAMES_NXDOOM_MAXOPENINGS - int "Maximum number of openings" - default 32 - ---help--- - DOOM allocates a static number of 'openings' to use for gameplay. These - are defined as multiples of the SCREENWIDTH (320). The original - ChocolateDOOM source uses 64 as the multiplier. They take a significant - amount of memory, so you may reduce the number. However, too few - openings will cause 'opening overflow' errors. - -config GAMES_NXDOOM_MAXVISSPRITES - int "Maximum number of visible sprites" - default 96 - ---help--- - DOOM allocates a static number of 'vissprites' to use for gameplay. The - original ChocolateDOOM source uses 128. They take a significant amount - of memory, so you may reduce the number. However, too few will cause - overflow errors. - -config GAMES_NXDOOM_MAXDRAWSEGS - int "Maximum number of drawsegs" - default 192 - ---help--- - DOOM allocates a static number of 'drawsegs' to use for gameplay. The - original ChocolateDOOM source uses 256. They take a significant amount of - memory, so you may reduce the number. However, too few will cause - rendering issues (overflow is checked to avoid crashes). - -config GAMES_NXDOOM_RANGECHECK - bool "Perform range checks" - default y - ---help--- - The ChocolateDOOM source includes the ability to optionally exclude - range checking on some array operations. - -endif # GAMES_NXDOOM diff --git a/games/NXDoom/Make.defs b/games/NXDoom/Make.defs deleted file mode 100644 index b0fa11c3f..000000000 --- a/games/NXDoom/Make.defs +++ /dev/null @@ -1,3 +0,0 @@ -ifneq ($(CONFIG_GAMES_NXDOOM),) -CONFIGURED_APPS += $(APPDIR)/games/NXDoom -endif diff --git a/games/NXDoom/Makefile b/games/NXDoom/Makefile deleted file mode 100644 index b22390654..000000000 --- a/games/NXDoom/Makefile +++ /dev/null @@ -1,209 +0,0 @@ -include $(APPDIR)/Make.defs - -# Program options - -MODULE = $(CONFIG_GAMES_NXDOOM) -PRIORITY = $(CONFIG_GAMES_NXDOOM_PRIORITY) -STACKSIZE = $(CONFIG_GAMES_NXDOOM_STACKSIZE) -PROGNAME = nxdoom - -# Source files - -COMMONSRCDIR = src -TEXTSCREENSRCDIR = textscreen -DOOMSRCDIR = $(COMMONSRCDIR)/doom -PCSOUNDSRCDIR = pcsound - -# Includes - -CFLAGS += -I$(COMMONSRCDIR) -I$(DOOMSRCDIR) -I$(TEXTSCREENSRCDIR) -CFLAGS += -I$(PCSOUNDSRCDIR) - -# Source files - -COMMONSRCS = i_system.c m_argv.c m_misc.c # Excluding i_main.c -COMMONSRCS += z_native.c # Native memory allocation - -DEHACKEDSRCS = deh_io.c deh_main.c deh_mapping.c deh_text.c - -BASESRCS = \ - aes_prng.c \ - d_event.c \ - d_iwad.c \ - d_loop.c \ - d_mode.c \ - deh_str.c \ - gusconf.c \ - i_glob.c \ - i_input.c \ - i_joystick.c \ - i_timer.c \ - i_video.c \ - m_bbox.c \ - m_cheat.c \ - m_config.c \ - m_controls.c \ - m_fixed.c \ - p_rejectpad.c \ - memio.c \ - tables.c \ - v_diskicon.c \ - v_video.c \ - w_checksum.c \ - w_main.c \ - w_wad.c \ - w_file.c \ - w_file_stdc.c \ - w_merge.c \ - -# Only add ENDOOM stuff if the user wants it - -ifeq ($(CONFIG_GAMES_NXDOOM_ENDOOM),y) -BASESRCS += i_endoom.c -endif - -NETSRCS = \ - net_client.c \ - net_common.c \ - net_dedicated.c \ - net_gui.c \ - net_io.c \ - net_loop.c \ - net_packet.c \ - net_query.c \ - net_sdl.c \ - net_server.c \ - net_structrw.c \ - -DOOMSRCS = \ - am_map.c \ - deh_ammo.c \ - deh_bexstr.c \ - deh_cheat.c \ - deh_doom.c \ - deh_frame.c \ - deh_misc.c \ - deh_ptr.c \ - deh_thing.c \ - deh_weapon.c \ - d_items.c \ - d_main.c \ - d_net.c \ - doomdef.c \ - doomstat.c \ - dstrings.c \ - f_finale.c \ - f_wipe.c \ - g_game.c \ - hu_lib.c \ - hu_stuff.c \ - info.c \ - m_menu.c \ - m_random.c \ - p_ceilng.c \ - p_doors.c \ - p_enemy.c \ - p_floor.c \ - p_inter.c \ - p_lights.c \ - p_map.c \ - p_maputl.c \ - p_mobj.c \ - p_plats.c \ - p_pspr.c \ - p_saveg.c \ - p_setup.c \ - p_sight.c \ - p_spec.c \ - p_switch.c \ - p_telept.c \ - p_tick.c \ - p_user.c \ - r_bsp.c \ - r_data.c \ - r_draw.c \ - r_main.c \ - r_plane.c \ - r_segs.c \ - r_sky.c \ - r_things.c \ - statdump.c \ - st_lib.c \ - st_stuff.c \ - wi_stuff.c - -TXTSCREENSRCS = \ - txt_conditional.c \ - txt_checkbox.c \ - txt_desktop.c \ - txt_dropdown.c \ - txt_fileselect.c \ - txt_gui.c \ - txt_inputbox.c \ - txt_io.c \ - txt_button.c \ - txt_label.c \ - txt_radiobutton.c \ - txt_scrollpane.c \ - txt_separator.c \ - txt_spinctrl.c \ - txt_sdl.c \ - txt_strut.c \ - txt_table.c \ - txt_utf8.c \ - txt_widget.c \ - txt_window.c \ - txt_window_action.c - -CSRCS += $(patsubst %,$(COMMONSRCDIR)/%,$(COMMONSRCS)) -CSRCS += $(patsubst %,$(COMMONSRCDIR)/%,$(DEHACKEDSRCS)) -CSRCS += $(patsubst %,$(COMMONSRCDIR)/%,$(BASESRCS)) -CSRCS += $(patsubst %,$(DOOMSRCDIR)/%,$(DOOMSRCS)) - -# Textscreen stuff only needs to be included for networking stuff -# or if the user wants to see ENDOOM - -ifeq ($(CONFIG_GAMES_NXDOOM_ENDOOM),y) -ADDTXTSCREEN = y -endif - -ifeq ($(CONFIG_GAMES_NXDOOM_NET),y) -ADDTXTSCREEN = y -endif - -# Only include textscreen code if needed - -ifeq ($(ADDTXTSCREEN),y) -CSRCS += $(patsubst %,$(TEXTSCREENSRCDIR)/%,$(TXTSCREENSRCS)) -endif - -# Only include networking logic if enabled - -ifeq ($(CONFIG_GAMES_NXDOOM_NET),y) -CSRCS += $(patsubst %,$(COMMONSRCDIR)/%,$(NETSRCS)) -endif - -# Only include sound logic if enabled - -ifeq ($(CONFIG_GAMES_NXDOOM_SOUND),y) -CSRCS += $(COMMONSRCDIR)/i_musicpack.c -CSRCS += $(COMMONSRCDIR)/i_pcsound.c -CSRCS += $(COMMONSRCDIR)/i_sdlmusic.c -CSRCS += $(COMMONSRCDIR)/i_sound.c -CSRCS += $(COMMONSRCDIR)/midifile.c -CSRCS += $(COMMONSRCDIR)/mus2mid.c - -CSRCS += $(DOOMSRCDIR)/sounds.c -CSRCS += $(DOOMSRCDIR)/s_sound.c -CSRCS += $(DOOMSRCDIR)/deh_sound.c -endif - -# If we have chosen RTTTL music, then add that source - -ifeq ($(CONFIG_GAMES_NXDOOM_RTTTL_MUSIC),y) -CSRCS += $(COMMONSRCDIR)/i_rtttl_music.c -endif - -MAINSRC = $(COMMONSRCDIR)/i_main.c - -include $(APPDIR)/Application.mk diff --git a/games/NXDoom/pcsound/.gitignore b/games/NXDoom/pcsound/.gitignore deleted file mode 100644 index 022c663ee..000000000 --- a/games/NXDoom/pcsound/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -Makefile.in -Makefile -.deps -libpcsound.a -*.rc -tags -TAGS - diff --git a/games/NXDoom/pcsound/pcsound.c b/games/NXDoom/pcsound/pcsound.c deleted file mode 100644 index 8e7b73bd6..000000000 --- a/games/NXDoom/pcsound/pcsound.c +++ /dev/null @@ -1,129 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/pcsound/pcsound.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * PC speaker interface. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include - -#include "config.h" -#include "pcsound.h" -#include "pcsound_internal.h" - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static pcsound_driver_t *g_drivers[] = -{ -#ifdef HAVE_LINUX_KD_H - &pcsound_linux_driver, -#endif - NULL, -}; - -static pcsound_driver_t *g_pcsound_driver = NULL; - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -int pcsound_sample_rate; - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -void pc_sound_set_sample_rate(int rate) -{ - pcsound_sample_rate = rate; -} - -int pc_sound_init(pcsound_callback_func callback_func) -{ - char *driver_name; - int i; - - if (g_pcsound_driver != NULL) - { - return 1; - } - - /* Check if the environment variable is set */ - - driver_name = getenv("PCSOUND_DRIVER"); - - if (driver_name != NULL) - { - for (i = 0; g_drivers[i] != NULL; ++i) - { - if (!strcmp(g_drivers[i]->name, driver_name)) - { - /* Found the driver! */ - - if (g_drivers[i]->init_func(callback_func)) - { - g_pcsound_driver = g_drivers[i]; - } - else - { - printf("Failed to initialize PC sound driver: %s\n", - g_drivers[i]->name); - break; - } - } - } - } - else - { - /* Try all drivers until we find a working one */ - - for (i = 0; g_drivers[i] != NULL; ++i) - { - if (g_drivers[i]->init_func(callback_func)) - { - g_pcsound_driver = g_drivers[i]; - break; - } - } - } - - if (g_pcsound_driver != NULL) - { - printf("Using PC sound driver: %s\n", g_pcsound_driver->name); - return 1; - } - else - { - printf("Failed to find a working PC sound driver.\n"); - return 0; - } -} - -void pc_sound_shutdown(void) -{ - g_pcsound_driver->shutdown_func(); - g_pcsound_driver = NULL; -} diff --git a/games/NXDoom/pcsound/pcsound.h b/games/NXDoom/pcsound/pcsound.h deleted file mode 100644 index 0d1e0f3ba..000000000 --- a/games/NXDoom/pcsound/pcsound.h +++ /dev/null @@ -1,52 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/pcsound/pcsound.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * PC speaker interface. - * - ****************************************************************************/ - -#ifndef PCSOUND_H -#define PCSOUND_H - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -typedef void (*pcsound_callback_func)(int *duration, int *frequency); - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/* Initialise the PC speaker subsystem. The given function is called - * periodically to request more sound data to play. - */ - -int pc_sound_init(pcsound_callback_func callback_func); - -/* Shut down the PC speaker subsystem. */ - -void pc_sound_shutdown(void); - -/* Set the preferred output sample rate when emulating a PC speaker. - * This must be called before pc_sound_init. - */ - -void pc_sound_set_sample_rate(int rate); - -#endif /* PCSOUND_H */ diff --git a/games/NXDoom/pcsound/pcsound_internal.h b/games/NXDoom/pcsound/pcsound_internal.h deleted file mode 100644 index 295ad6266..000000000 --- a/games/NXDoom/pcsound/pcsound_internal.h +++ /dev/null @@ -1,65 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/pcsound/pcsound_internal.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * PC speaker interface. - * - ****************************************************************************/ - -#ifndef PCSOUND_INTERNAL_H -#define PCSOUND_INTERNAL_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "pcsound.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define PCSOUND_8253_FREQUENCY (1193280) - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -typedef struct pcsound_driver_s pcsound_driver_t; -typedef int (*pcsound_init_func)(pcsound_callback_func callback); -typedef void (*pcsound_shutdown_func)(void); - -struct pcsound_driver_s -{ - const char *name; - pcsound_init_func init_func; - pcsound_shutdown_func shutdown_func; -}; - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -extern int pcsound_sample_rate; - -#ifdef HAVE_LINUX_KD_H -extern pcsound_driver_t pcsound_linux_driver; -#endif - -extern pcsound_driver_t pcsound_sdl_driver; - -#endif /* PCSOUND_INTERNAL_H */ diff --git a/games/NXDoom/src/.gitignore b/games/NXDoom/src/.gitignore deleted file mode 100644 index a3127e6bd..000000000 --- a/games/NXDoom/src/.gitignore +++ /dev/null @@ -1,22 +0,0 @@ -Makefile -Makefile.in -.deps -*.rc -chocolate-doom -chocolate-heretic -chocolate-hexen -chocolate-server -chocolate-strife -chocolate-doom-setup -chocolate-heretic-setup -chocolate-hexen-setup -chocolate-strife-setup -chocolate-setup -*.cfg -*.exe -*.desktop -*.txt -!CMakeLists.txt -*.metainfo.xml -tags -TAGS diff --git a/games/NXDoom/src/aes_prng.c b/games/NXDoom/src/aes_prng.c deleted file mode 100644 index 04de172ef..000000000 --- a/games/NXDoom/src/aes_prng.c +++ /dev/null @@ -1,930 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/aes_prng.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * - * This implements a cryptographically secure pseudorandom number - * generator for implementing secure demos. The approach taken is to - * use the AES (Rijndael) stream cipher in "counter" mode, encrypting - * an incrementing counter. The cipher key acts as the random seed. - * Cryptanalysis of AES used in this way has shown it to be an - * effective PRNG (see: Empirical Evidence concerning AES, Hellekalek - * & Wegenkittl, 2003). - * - * AES implementation is taken from the Linux kernel's AES - * implementation, found in crypto/aes_generic.c. It has been hacked - * up to work independently. - * - * AES Cipher Algorithm. - * - * Based on Brian Gladman's code. - * - * Linux developers: - * Alexander Kjeldaas - * Herbert Valerio Riedel - * Kyle McMartin - * Adam J. Richter (conversion to 2.5 API). - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * Copyright (c) 2002, Dr Brian Gladman , Worcester, UK. - * All rights reserved. - * - * LICENSE TERMS - * - * The free distribution and use of this software in both source and binary - * form is allowed (with or without changes) provided that: - * - * 1. distributions of this source code include the above copyright - * notice, this list of conditions and the following disclaimer; - * - * 2. distributions in binary form include the above copyright - * notice, this list of conditions and the following disclaimer - * in the documentation and/or other associated materials; - * - * 3. the copyright holder's name is not used to endorse products - * built using this software without specific written permission. - * - * ALTERNATIVELY, provided that this notice is retained in full, this - * product may be distributed under the terms of the GNU General Public - * License (GPL), in which case the provisions of the GPL apply INSTEAD OF - * those given above. - * - * DISCLAIMER - * - * This software is provided 'as is' with no explicit or implied warranties - * in respect of its properties, including, but not limited to, correctness - * and/or fitness for purpose. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include "aes_prng.h" -#include "doomtype.h" -#include "i_swap.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define AES_MIN_KEY_SIZE 16 -#define AES_MAX_KEY_SIZE 32 -#define AES_KEYSIZE_128 16 -#define AES_KEYSIZE_192 24 -#define AES_KEYSIZE_256 32 -#define AES_BLOCK_SIZE 16 -#define AES_MAX_KEYLENGTH (15 * 16) -#define AES_MAX_KEYLENGTH_U32 (AES_MAX_KEYLENGTH / sizeof(uint32_t)) - -#define cpu_to_le32(x) htole32(x) -#define le32_to_cpu(x) le32toh(x) - -#define star_x(x) \ - (((x) & 0x7f7f7f7f) << 1) ^ ((((x) & 0x80808080) >> 7) * 0x1b) - -#define imix_col(y, x) \ - do \ - { \ - u = star_x(x); \ - v = star_x(u); \ - w = star_x(v); \ - t = w ^ (x); \ - (y) = u ^ v ^ w; \ - (y) ^= aes_ror32(u ^ t, 8) ^ aes_ror32(v ^ t, 16) ^ aes_ror32(t, 24); \ - } \ - while (0) - -#define ls_box(x) \ - crypto_fl_tab[0][get_byte(x, 0)] ^ crypto_fl_tab[1][get_byte(x, 1)] ^ \ - crypto_fl_tab[2][get_byte(x, 2)] ^ crypto_fl_tab[3][get_byte(x, 3)] - -#define loop4(i) \ - do \ - { \ - t = aes_ror32(t, 8); \ - t = ls_box(t) ^ rco_tab[i]; \ - t ^= ctx->key_enc[4 * i]; \ - ctx->key_enc[4 * i + 4] = t; \ - t ^= ctx->key_enc[4 * i + 1]; \ - ctx->key_enc[4 * i + 5] = t; \ - t ^= ctx->key_enc[4 * i + 2]; \ - ctx->key_enc[4 * i + 6] = t; \ - t ^= ctx->key_enc[4 * i + 3]; \ - ctx->key_enc[4 * i + 7] = t; \ - } \ - while (0) - -#define loop6(i) \ - do \ - { \ - t = aes_ror32(t, 8); \ - t = ls_box(t) ^ rco_tab[i]; \ - t ^= ctx->key_enc[6 * i]; \ - ctx->key_enc[6 * i + 6] = t; \ - t ^= ctx->key_enc[6 * i + 1]; \ - ctx->key_enc[6 * i + 7] = t; \ - t ^= ctx->key_enc[6 * i + 2]; \ - ctx->key_enc[6 * i + 8] = t; \ - t ^= ctx->key_enc[6 * i + 3]; \ - ctx->key_enc[6 * i + 9] = t; \ - t ^= ctx->key_enc[6 * i + 4]; \ - ctx->key_enc[6 * i + 10] = t; \ - t ^= ctx->key_enc[6 * i + 5]; \ - ctx->key_enc[6 * i + 11] = t; \ - } \ - while (0) - -#define loop8tophalf(i) \ - do \ - { \ - t = aes_ror32(t, 8); \ - t = ls_box(t) ^ rco_tab[i]; \ - t ^= ctx->key_enc[8 * i]; \ - ctx->key_enc[8 * i + 8] = t; \ - t ^= ctx->key_enc[8 * i + 1]; \ - ctx->key_enc[8 * i + 9] = t; \ - t ^= ctx->key_enc[8 * i + 2]; \ - ctx->key_enc[8 * i + 10] = t; \ - t ^= ctx->key_enc[8 * i + 3]; \ - ctx->key_enc[8 * i + 11] = t; \ - } \ - while (0) - -#define loop8(i) \ - do \ - { \ - loop8tophalf(i); \ - t = ctx->key_enc[8 * i + 4] ^ ls_box(t); \ - ctx->key_enc[8 * i + 12] = t; \ - t ^= ctx->key_enc[8 * i + 5]; \ - ctx->key_enc[8 * i + 13] = t; \ - t ^= ctx->key_enc[8 * i + 6]; \ - ctx->key_enc[8 * i + 14] = t; \ - t ^= ctx->key_enc[8 * i + 7]; \ - ctx->key_enc[8 * i + 15] = t; \ - } \ - while (0) - -/* encrypt a block of text */ - -#define f_rn(bo, bi, n, k) \ - do \ - { \ - bo[n] = crypto_ft_tab[0][get_byte(bi[n], 0)] ^ \ - crypto_ft_tab[1][get_byte(bi[(n + 1) & 3], 1)] ^ \ - crypto_ft_tab[2][get_byte(bi[(n + 2) & 3], 2)] ^ \ - crypto_ft_tab[3][get_byte(bi[(n + 3) & 3], 3)] ^ *(k + n); \ - } \ - while (0) - -#define f_nround(bo, bi, k) \ - do \ - { \ - f_rn(bo, bi, 0, k); \ - f_rn(bo, bi, 1, k); \ - f_rn(bo, bi, 2, k); \ - f_rn(bo, bi, 3, k); \ - k += 4; \ - } \ - while (0) - -#define f_rl(bo, bi, n, k) \ - do \ - { \ - bo[n] = crypto_fl_tab[0][get_byte(bi[n], 0)] ^ \ - crypto_fl_tab[1][get_byte(bi[(n + 1) & 3], 1)] ^ \ - crypto_fl_tab[2][get_byte(bi[(n + 2) & 3], 2)] ^ \ - crypto_fl_tab[3][get_byte(bi[(n + 3) & 3], 3)] ^ *(k + n); \ - } \ - while (0) - -#define f_lround(bo, bi, k) \ - do \ - { \ - f_rl(bo, bi, 0, k); \ - f_rl(bo, bi, 1, k); \ - f_rl(bo, bi, 2, k); \ - f_rl(bo, bi, 3, k); \ - } \ - while (0) - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/* Please ensure that the first two fields are 16-byte aligned - * relative to the start of the structure, i.e., don't move them! - */ - -typedef struct -{ - uint32_t key_enc[AES_MAX_KEYLENGTH_U32]; - uint32_t key_dec[AES_MAX_KEYLENGTH_U32]; - uint32_t key_length; -} aes_context_t; - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static boolean prng_enabled = false; -static aes_context_t prng_context; -static uint32_t prng_input_counter; -static uint32_t prng_values[4]; -static unsigned int prng_value_index = 0; - -static const uint32_t rco_tab[10] = -{ - 1, 2, 4, 8, 16, 32, 64, 128, 27, 54, -}; - -static const uint32_t crypto_ft_tab[4][256] = -{ - { - 0xa56363c6, 0x847c7cf8, 0x997777ee, 0x8d7b7bf6, 0x0df2f2ff, - 0xbd6b6bd6, 0xb16f6fde, 0x54c5c591, 0x50303060, 0x03010102, - 0xa96767ce, 0x7d2b2b56, 0x19fefee7, 0x62d7d7b5, 0xe6abab4d, - 0x9a7676ec, 0x45caca8f, 0x9d82821f, 0x40c9c989, 0x877d7dfa, - 0x15fafaef, 0xeb5959b2, 0xc947478e, 0x0bf0f0fb, 0xecadad41, - 0x67d4d4b3, 0xfda2a25f, 0xeaafaf45, 0xbf9c9c23, 0xf7a4a453, - 0x967272e4, 0x5bc0c09b, 0xc2b7b775, 0x1cfdfde1, 0xae93933d, - 0x6a26264c, 0x5a36366c, 0x413f3f7e, 0x02f7f7f5, 0x4fcccc83, - 0x5c343468, 0xf4a5a551, 0x34e5e5d1, 0x08f1f1f9, 0x937171e2, - 0x73d8d8ab, 0x53313162, 0x3f15152a, 0x0c040408, 0x52c7c795, - 0x65232346, 0x5ec3c39d, 0x28181830, 0xa1969637, 0x0f05050a, - 0xb59a9a2f, 0x0907070e, 0x36121224, 0x9b80801b, 0x3de2e2df, - 0x26ebebcd, 0x6927274e, 0xcdb2b27f, 0x9f7575ea, 0x1b090912, - 0x9e83831d, 0x742c2c58, 0x2e1a1a34, 0x2d1b1b36, 0xb26e6edc, - 0xee5a5ab4, 0xfba0a05b, 0xf65252a4, 0x4d3b3b76, 0x61d6d6b7, - 0xceb3b37d, 0x7b292952, 0x3ee3e3dd, 0x712f2f5e, 0x97848413, - 0xf55353a6, 0x68d1d1b9, 0x00000000, 0x2cededc1, 0x60202040, - 0x1ffcfce3, 0xc8b1b179, 0xed5b5bb6, 0xbe6a6ad4, 0x46cbcb8d, - 0xd9bebe67, 0x4b393972, 0xde4a4a94, 0xd44c4c98, 0xe85858b0, - 0x4acfcf85, 0x6bd0d0bb, 0x2aefefc5, 0xe5aaaa4f, 0x16fbfbed, - 0xc5434386, 0xd74d4d9a, 0x55333366, 0x94858511, 0xcf45458a, - 0x10f9f9e9, 0x06020204, 0x817f7ffe, 0xf05050a0, 0x443c3c78, - 0xba9f9f25, 0xe3a8a84b, 0xf35151a2, 0xfea3a35d, 0xc0404080, - 0x8a8f8f05, 0xad92923f, 0xbc9d9d21, 0x48383870, 0x04f5f5f1, - 0xdfbcbc63, 0xc1b6b677, 0x75dadaaf, 0x63212142, 0x30101020, - 0x1affffe5, 0x0ef3f3fd, 0x6dd2d2bf, 0x4ccdcd81, 0x140c0c18, - 0x35131326, 0x2fececc3, 0xe15f5fbe, 0xa2979735, 0xcc444488, - 0x3917172e, 0x57c4c493, 0xf2a7a755, 0x827e7efc, 0x473d3d7a, - 0xac6464c8, 0xe75d5dba, 0x2b191932, 0x957373e6, 0xa06060c0, - 0x98818119, 0xd14f4f9e, 0x7fdcdca3, 0x66222244, 0x7e2a2a54, - 0xab90903b, 0x8388880b, 0xca46468c, 0x29eeeec7, 0xd3b8b86b, - 0x3c141428, 0x79dedea7, 0xe25e5ebc, 0x1d0b0b16, 0x76dbdbad, - 0x3be0e0db, 0x56323264, 0x4e3a3a74, 0x1e0a0a14, 0xdb494992, - 0x0a06060c, 0x6c242448, 0xe45c5cb8, 0x5dc2c29f, 0x6ed3d3bd, - 0xefacac43, 0xa66262c4, 0xa8919139, 0xa4959531, 0x37e4e4d3, - 0x8b7979f2, 0x32e7e7d5, 0x43c8c88b, 0x5937376e, 0xb76d6dda, - 0x8c8d8d01, 0x64d5d5b1, 0xd24e4e9c, 0xe0a9a949, 0xb46c6cd8, - 0xfa5656ac, 0x07f4f4f3, 0x25eaeacf, 0xaf6565ca, 0x8e7a7af4, - 0xe9aeae47, 0x18080810, 0xd5baba6f, 0x887878f0, 0x6f25254a, - 0x722e2e5c, 0x241c1c38, 0xf1a6a657, 0xc7b4b473, 0x51c6c697, - 0x23e8e8cb, 0x7cdddda1, 0x9c7474e8, 0x211f1f3e, 0xdd4b4b96, - 0xdcbdbd61, 0x868b8b0d, 0x858a8a0f, 0x907070e0, 0x423e3e7c, - 0xc4b5b571, 0xaa6666cc, 0xd8484890, 0x05030306, 0x01f6f6f7, - 0x120e0e1c, 0xa36161c2, 0x5f35356a, 0xf95757ae, 0xd0b9b969, - 0x91868617, 0x58c1c199, 0x271d1d3a, 0xb99e9e27, 0x38e1e1d9, - 0x13f8f8eb, 0xb398982b, 0x33111122, 0xbb6969d2, 0x70d9d9a9, - 0x898e8e07, 0xa7949433, 0xb69b9b2d, 0x221e1e3c, 0x92878715, - 0x20e9e9c9, 0x49cece87, 0xff5555aa, 0x78282850, 0x7adfdfa5, - 0x8f8c8c03, 0xf8a1a159, 0x80898909, 0x170d0d1a, 0xdabfbf65, - 0x31e6e6d7, 0xc6424284, 0xb86868d0, 0xc3414182, 0xb0999929, - 0x772d2d5a, 0x110f0f1e, 0xcbb0b07b, 0xfc5454a8, 0xd6bbbb6d, - 0x3a16162c, - }, - { - 0x6363c6a5, 0x7c7cf884, 0x7777ee99, 0x7b7bf68d, 0xf2f2ff0d, - 0x6b6bd6bd, 0x6f6fdeb1, 0xc5c59154, 0x30306050, 0x01010203, - 0x6767cea9, 0x2b2b567d, 0xfefee719, 0xd7d7b562, 0xabab4de6, - 0x7676ec9a, 0xcaca8f45, 0x82821f9d, 0xc9c98940, 0x7d7dfa87, - 0xfafaef15, 0x5959b2eb, 0x47478ec9, 0xf0f0fb0b, 0xadad41ec, - 0xd4d4b367, 0xa2a25ffd, 0xafaf45ea, 0x9c9c23bf, 0xa4a453f7, - 0x7272e496, 0xc0c09b5b, 0xb7b775c2, 0xfdfde11c, 0x93933dae, - 0x26264c6a, 0x36366c5a, 0x3f3f7e41, 0xf7f7f502, 0xcccc834f, - 0x3434685c, 0xa5a551f4, 0xe5e5d134, 0xf1f1f908, 0x7171e293, - 0xd8d8ab73, 0x31316253, 0x15152a3f, 0x0404080c, 0xc7c79552, - 0x23234665, 0xc3c39d5e, 0x18183028, 0x969637a1, 0x05050a0f, - 0x9a9a2fb5, 0x07070e09, 0x12122436, 0x80801b9b, 0xe2e2df3d, - 0xebebcd26, 0x27274e69, 0xb2b27fcd, 0x7575ea9f, 0x0909121b, - 0x83831d9e, 0x2c2c5874, 0x1a1a342e, 0x1b1b362d, 0x6e6edcb2, - 0x5a5ab4ee, 0xa0a05bfb, 0x5252a4f6, 0x3b3b764d, 0xd6d6b761, - 0xb3b37dce, 0x2929527b, 0xe3e3dd3e, 0x2f2f5e71, 0x84841397, - 0x5353a6f5, 0xd1d1b968, 0x00000000, 0xededc12c, 0x20204060, - 0xfcfce31f, 0xb1b179c8, 0x5b5bb6ed, 0x6a6ad4be, 0xcbcb8d46, - 0xbebe67d9, 0x3939724b, 0x4a4a94de, 0x4c4c98d4, 0x5858b0e8, - 0xcfcf854a, 0xd0d0bb6b, 0xefefc52a, 0xaaaa4fe5, 0xfbfbed16, - 0x434386c5, 0x4d4d9ad7, 0x33336655, 0x85851194, 0x45458acf, - 0xf9f9e910, 0x02020406, 0x7f7ffe81, 0x5050a0f0, 0x3c3c7844, - 0x9f9f25ba, 0xa8a84be3, 0x5151a2f3, 0xa3a35dfe, 0x404080c0, - 0x8f8f058a, 0x92923fad, 0x9d9d21bc, 0x38387048, 0xf5f5f104, - 0xbcbc63df, 0xb6b677c1, 0xdadaaf75, 0x21214263, 0x10102030, - 0xffffe51a, 0xf3f3fd0e, 0xd2d2bf6d, 0xcdcd814c, 0x0c0c1814, - 0x13132635, 0xececc32f, 0x5f5fbee1, 0x979735a2, 0x444488cc, - 0x17172e39, 0xc4c49357, 0xa7a755f2, 0x7e7efc82, 0x3d3d7a47, - 0x6464c8ac, 0x5d5dbae7, 0x1919322b, 0x7373e695, 0x6060c0a0, - 0x81811998, 0x4f4f9ed1, 0xdcdca37f, 0x22224466, 0x2a2a547e, - 0x90903bab, 0x88880b83, 0x46468cca, 0xeeeec729, 0xb8b86bd3, - 0x1414283c, 0xdedea779, 0x5e5ebce2, 0x0b0b161d, 0xdbdbad76, - 0xe0e0db3b, 0x32326456, 0x3a3a744e, 0x0a0a141e, 0x494992db, - 0x06060c0a, 0x2424486c, 0x5c5cb8e4, 0xc2c29f5d, 0xd3d3bd6e, - 0xacac43ef, 0x6262c4a6, 0x919139a8, 0x959531a4, 0xe4e4d337, - 0x7979f28b, 0xe7e7d532, 0xc8c88b43, 0x37376e59, 0x6d6ddab7, - 0x8d8d018c, 0xd5d5b164, 0x4e4e9cd2, 0xa9a949e0, 0x6c6cd8b4, - 0x5656acfa, 0xf4f4f307, 0xeaeacf25, 0x6565caaf, 0x7a7af48e, - 0xaeae47e9, 0x08081018, 0xbaba6fd5, 0x7878f088, 0x25254a6f, - 0x2e2e5c72, 0x1c1c3824, 0xa6a657f1, 0xb4b473c7, 0xc6c69751, - 0xe8e8cb23, 0xdddda17c, 0x7474e89c, 0x1f1f3e21, 0x4b4b96dd, - 0xbdbd61dc, 0x8b8b0d86, 0x8a8a0f85, 0x7070e090, 0x3e3e7c42, - 0xb5b571c4, 0x6666ccaa, 0x484890d8, 0x03030605, 0xf6f6f701, - 0x0e0e1c12, 0x6161c2a3, 0x35356a5f, 0x5757aef9, 0xb9b969d0, - 0x86861791, 0xc1c19958, 0x1d1d3a27, 0x9e9e27b9, 0xe1e1d938, - 0xf8f8eb13, 0x98982bb3, 0x11112233, 0x6969d2bb, 0xd9d9a970, - 0x8e8e0789, 0x949433a7, 0x9b9b2db6, 0x1e1e3c22, 0x87871592, - 0xe9e9c920, 0xcece8749, 0x5555aaff, 0x28285078, 0xdfdfa57a, - 0x8c8c038f, 0xa1a159f8, 0x89890980, 0x0d0d1a17, 0xbfbf65da, - 0xe6e6d731, 0x424284c6, 0x6868d0b8, 0x414182c3, 0x999929b0, - 0x2d2d5a77, 0x0f0f1e11, 0xb0b07bcb, 0x5454a8fc, 0xbbbb6dd6, - 0x16162c3a, - }, - { - 0x63c6a563, 0x7cf8847c, 0x77ee9977, 0x7bf68d7b, 0xf2ff0df2, - 0x6bd6bd6b, 0x6fdeb16f, 0xc59154c5, 0x30605030, 0x01020301, - 0x67cea967, 0x2b567d2b, 0xfee719fe, 0xd7b562d7, 0xab4de6ab, - 0x76ec9a76, 0xca8f45ca, 0x821f9d82, 0xc98940c9, 0x7dfa877d, - 0xfaef15fa, 0x59b2eb59, 0x478ec947, 0xf0fb0bf0, 0xad41ecad, - 0xd4b367d4, 0xa25ffda2, 0xaf45eaaf, 0x9c23bf9c, 0xa453f7a4, - 0x72e49672, 0xc09b5bc0, 0xb775c2b7, 0xfde11cfd, 0x933dae93, - 0x264c6a26, 0x366c5a36, 0x3f7e413f, 0xf7f502f7, 0xcc834fcc, - 0x34685c34, 0xa551f4a5, 0xe5d134e5, 0xf1f908f1, 0x71e29371, - 0xd8ab73d8, 0x31625331, 0x152a3f15, 0x04080c04, 0xc79552c7, - 0x23466523, 0xc39d5ec3, 0x18302818, 0x9637a196, 0x050a0f05, - 0x9a2fb59a, 0x070e0907, 0x12243612, 0x801b9b80, 0xe2df3de2, - 0xebcd26eb, 0x274e6927, 0xb27fcdb2, 0x75ea9f75, 0x09121b09, - 0x831d9e83, 0x2c58742c, 0x1a342e1a, 0x1b362d1b, 0x6edcb26e, - 0x5ab4ee5a, 0xa05bfba0, 0x52a4f652, 0x3b764d3b, 0xd6b761d6, - 0xb37dceb3, 0x29527b29, 0xe3dd3ee3, 0x2f5e712f, 0x84139784, - 0x53a6f553, 0xd1b968d1, 0x00000000, 0xedc12ced, 0x20406020, - 0xfce31ffc, 0xb179c8b1, 0x5bb6ed5b, 0x6ad4be6a, 0xcb8d46cb, - 0xbe67d9be, 0x39724b39, 0x4a94de4a, 0x4c98d44c, 0x58b0e858, - 0xcf854acf, 0xd0bb6bd0, 0xefc52aef, 0xaa4fe5aa, 0xfbed16fb, - 0x4386c543, 0x4d9ad74d, 0x33665533, 0x85119485, 0x458acf45, - 0xf9e910f9, 0x02040602, 0x7ffe817f, 0x50a0f050, 0x3c78443c, - 0x9f25ba9f, 0xa84be3a8, 0x51a2f351, 0xa35dfea3, 0x4080c040, - 0x8f058a8f, 0x923fad92, 0x9d21bc9d, 0x38704838, 0xf5f104f5, - 0xbc63dfbc, 0xb677c1b6, 0xdaaf75da, 0x21426321, 0x10203010, - 0xffe51aff, 0xf3fd0ef3, 0xd2bf6dd2, 0xcd814ccd, 0x0c18140c, - 0x13263513, 0xecc32fec, 0x5fbee15f, 0x9735a297, 0x4488cc44, - 0x172e3917, 0xc49357c4, 0xa755f2a7, 0x7efc827e, 0x3d7a473d, - 0x64c8ac64, 0x5dbae75d, 0x19322b19, 0x73e69573, 0x60c0a060, - 0x81199881, 0x4f9ed14f, 0xdca37fdc, 0x22446622, 0x2a547e2a, - 0x903bab90, 0x880b8388, 0x468cca46, 0xeec729ee, 0xb86bd3b8, - 0x14283c14, 0xdea779de, 0x5ebce25e, 0x0b161d0b, 0xdbad76db, - 0xe0db3be0, 0x32645632, 0x3a744e3a, 0x0a141e0a, 0x4992db49, - 0x060c0a06, 0x24486c24, 0x5cb8e45c, 0xc29f5dc2, 0xd3bd6ed3, - 0xac43efac, 0x62c4a662, 0x9139a891, 0x9531a495, 0xe4d337e4, - 0x79f28b79, 0xe7d532e7, 0xc88b43c8, 0x376e5937, 0x6ddab76d, - 0x8d018c8d, 0xd5b164d5, 0x4e9cd24e, 0xa949e0a9, 0x6cd8b46c, - 0x56acfa56, 0xf4f307f4, 0xeacf25ea, 0x65caaf65, 0x7af48e7a, - 0xae47e9ae, 0x08101808, 0xba6fd5ba, 0x78f08878, 0x254a6f25, - 0x2e5c722e, 0x1c38241c, 0xa657f1a6, 0xb473c7b4, 0xc69751c6, - 0xe8cb23e8, 0xdda17cdd, 0x74e89c74, 0x1f3e211f, 0x4b96dd4b, - 0xbd61dcbd, 0x8b0d868b, 0x8a0f858a, 0x70e09070, 0x3e7c423e, - 0xb571c4b5, 0x66ccaa66, 0x4890d848, 0x03060503, 0xf6f701f6, - 0x0e1c120e, 0x61c2a361, 0x356a5f35, 0x57aef957, 0xb969d0b9, - 0x86179186, 0xc19958c1, 0x1d3a271d, 0x9e27b99e, 0xe1d938e1, - 0xf8eb13f8, 0x982bb398, 0x11223311, 0x69d2bb69, 0xd9a970d9, - 0x8e07898e, 0x9433a794, 0x9b2db69b, 0x1e3c221e, 0x87159287, - 0xe9c920e9, 0xce8749ce, 0x55aaff55, 0x28507828, 0xdfa57adf, - 0x8c038f8c, 0xa159f8a1, 0x89098089, 0x0d1a170d, 0xbf65dabf, - 0xe6d731e6, 0x4284c642, 0x68d0b868, 0x4182c341, 0x9929b099, - 0x2d5a772d, 0x0f1e110f, 0xb07bcbb0, 0x54a8fc54, 0xbb6dd6bb, - 0x162c3a16, - }, - { - 0xc6a56363, 0xf8847c7c, 0xee997777, 0xf68d7b7b, 0xff0df2f2, - 0xd6bd6b6b, 0xdeb16f6f, 0x9154c5c5, 0x60503030, 0x02030101, - 0xcea96767, 0x567d2b2b, 0xe719fefe, 0xb562d7d7, 0x4de6abab, - 0xec9a7676, 0x8f45caca, 0x1f9d8282, 0x8940c9c9, 0xfa877d7d, - 0xef15fafa, 0xb2eb5959, 0x8ec94747, 0xfb0bf0f0, 0x41ecadad, - 0xb367d4d4, 0x5ffda2a2, 0x45eaafaf, 0x23bf9c9c, 0x53f7a4a4, - 0xe4967272, 0x9b5bc0c0, 0x75c2b7b7, 0xe11cfdfd, 0x3dae9393, - 0x4c6a2626, 0x6c5a3636, 0x7e413f3f, 0xf502f7f7, 0x834fcccc, - 0x685c3434, 0x51f4a5a5, 0xd134e5e5, 0xf908f1f1, 0xe2937171, - 0xab73d8d8, 0x62533131, 0x2a3f1515, 0x080c0404, 0x9552c7c7, - 0x46652323, 0x9d5ec3c3, 0x30281818, 0x37a19696, 0x0a0f0505, - 0x2fb59a9a, 0x0e090707, 0x24361212, 0x1b9b8080, 0xdf3de2e2, - 0xcd26ebeb, 0x4e692727, 0x7fcdb2b2, 0xea9f7575, 0x121b0909, - 0x1d9e8383, 0x58742c2c, 0x342e1a1a, 0x362d1b1b, 0xdcb26e6e, - 0xb4ee5a5a, 0x5bfba0a0, 0xa4f65252, 0x764d3b3b, 0xb761d6d6, - 0x7dceb3b3, 0x527b2929, 0xdd3ee3e3, 0x5e712f2f, 0x13978484, - 0xa6f55353, 0xb968d1d1, 0x00000000, 0xc12ceded, 0x40602020, - 0xe31ffcfc, 0x79c8b1b1, 0xb6ed5b5b, 0xd4be6a6a, 0x8d46cbcb, - 0x67d9bebe, 0x724b3939, 0x94de4a4a, 0x98d44c4c, 0xb0e85858, - 0x854acfcf, 0xbb6bd0d0, 0xc52aefef, 0x4fe5aaaa, 0xed16fbfb, - 0x86c54343, 0x9ad74d4d, 0x66553333, 0x11948585, 0x8acf4545, - 0xe910f9f9, 0x04060202, 0xfe817f7f, 0xa0f05050, 0x78443c3c, - 0x25ba9f9f, 0x4be3a8a8, 0xa2f35151, 0x5dfea3a3, 0x80c04040, - 0x058a8f8f, 0x3fad9292, 0x21bc9d9d, 0x70483838, 0xf104f5f5, - 0x63dfbcbc, 0x77c1b6b6, 0xaf75dada, 0x42632121, 0x20301010, - 0xe51affff, 0xfd0ef3f3, 0xbf6dd2d2, 0x814ccdcd, 0x18140c0c, - 0x26351313, 0xc32fecec, 0xbee15f5f, 0x35a29797, 0x88cc4444, - 0x2e391717, 0x9357c4c4, 0x55f2a7a7, 0xfc827e7e, 0x7a473d3d, - 0xc8ac6464, 0xbae75d5d, 0x322b1919, 0xe6957373, 0xc0a06060, - 0x19988181, 0x9ed14f4f, 0xa37fdcdc, 0x44662222, 0x547e2a2a, - 0x3bab9090, 0x0b838888, 0x8cca4646, 0xc729eeee, 0x6bd3b8b8, - 0x283c1414, 0xa779dede, 0xbce25e5e, 0x161d0b0b, 0xad76dbdb, - 0xdb3be0e0, 0x64563232, 0x744e3a3a, 0x141e0a0a, 0x92db4949, - 0x0c0a0606, 0x486c2424, 0xb8e45c5c, 0x9f5dc2c2, 0xbd6ed3d3, - 0x43efacac, 0xc4a66262, 0x39a89191, 0x31a49595, 0xd337e4e4, - 0xf28b7979, 0xd532e7e7, 0x8b43c8c8, 0x6e593737, 0xdab76d6d, - 0x018c8d8d, 0xb164d5d5, 0x9cd24e4e, 0x49e0a9a9, 0xd8b46c6c, - 0xacfa5656, 0xf307f4f4, 0xcf25eaea, 0xcaaf6565, 0xf48e7a7a, - 0x47e9aeae, 0x10180808, 0x6fd5baba, 0xf0887878, 0x4a6f2525, - 0x5c722e2e, 0x38241c1c, 0x57f1a6a6, 0x73c7b4b4, 0x9751c6c6, - 0xcb23e8e8, 0xa17cdddd, 0xe89c7474, 0x3e211f1f, 0x96dd4b4b, - 0x61dcbdbd, 0x0d868b8b, 0x0f858a8a, 0xe0907070, 0x7c423e3e, - 0x71c4b5b5, 0xccaa6666, 0x90d84848, 0x06050303, 0xf701f6f6, - 0x1c120e0e, 0xc2a36161, 0x6a5f3535, 0xaef95757, 0x69d0b9b9, - 0x17918686, 0x9958c1c1, 0x3a271d1d, 0x27b99e9e, 0xd938e1e1, - 0xeb13f8f8, 0x2bb39898, 0x22331111, 0xd2bb6969, 0xa970d9d9, - 0x07898e8e, 0x33a79494, 0x2db69b9b, 0x3c221e1e, 0x15928787, - 0xc920e9e9, 0x8749cece, 0xaaff5555, 0x50782828, 0xa57adfdf, - 0x038f8c8c, 0x59f8a1a1, 0x09808989, 0x1a170d0d, 0x65dabfbf, - 0xd731e6e6, 0x84c64242, 0xd0b86868, 0x82c34141, 0x29b09999, - 0x5a772d2d, 0x1e110f0f, 0x7bcbb0b0, 0xa8fc5454, 0x6dd6bbbb, - 0x2c3a1616, - }, -}; - -static const uint32_t crypto_fl_tab[4][256] = -{ - { - 0x00000063, 0x0000007c, 0x00000077, 0x0000007b, 0x000000f2, - 0x0000006b, 0x0000006f, 0x000000c5, 0x00000030, 0x00000001, - 0x00000067, 0x0000002b, 0x000000fe, 0x000000d7, 0x000000ab, - 0x00000076, 0x000000ca, 0x00000082, 0x000000c9, 0x0000007d, - 0x000000fa, 0x00000059, 0x00000047, 0x000000f0, 0x000000ad, - 0x000000d4, 0x000000a2, 0x000000af, 0x0000009c, 0x000000a4, - 0x00000072, 0x000000c0, 0x000000b7, 0x000000fd, 0x00000093, - 0x00000026, 0x00000036, 0x0000003f, 0x000000f7, 0x000000cc, - 0x00000034, 0x000000a5, 0x000000e5, 0x000000f1, 0x00000071, - 0x000000d8, 0x00000031, 0x00000015, 0x00000004, 0x000000c7, - 0x00000023, 0x000000c3, 0x00000018, 0x00000096, 0x00000005, - 0x0000009a, 0x00000007, 0x00000012, 0x00000080, 0x000000e2, - 0x000000eb, 0x00000027, 0x000000b2, 0x00000075, 0x00000009, - 0x00000083, 0x0000002c, 0x0000001a, 0x0000001b, 0x0000006e, - 0x0000005a, 0x000000a0, 0x00000052, 0x0000003b, 0x000000d6, - 0x000000b3, 0x00000029, 0x000000e3, 0x0000002f, 0x00000084, - 0x00000053, 0x000000d1, 0x00000000, 0x000000ed, 0x00000020, - 0x000000fc, 0x000000b1, 0x0000005b, 0x0000006a, 0x000000cb, - 0x000000be, 0x00000039, 0x0000004a, 0x0000004c, 0x00000058, - 0x000000cf, 0x000000d0, 0x000000ef, 0x000000aa, 0x000000fb, - 0x00000043, 0x0000004d, 0x00000033, 0x00000085, 0x00000045, - 0x000000f9, 0x00000002, 0x0000007f, 0x00000050, 0x0000003c, - 0x0000009f, 0x000000a8, 0x00000051, 0x000000a3, 0x00000040, - 0x0000008f, 0x00000092, 0x0000009d, 0x00000038, 0x000000f5, - 0x000000bc, 0x000000b6, 0x000000da, 0x00000021, 0x00000010, - 0x000000ff, 0x000000f3, 0x000000d2, 0x000000cd, 0x0000000c, - 0x00000013, 0x000000ec, 0x0000005f, 0x00000097, 0x00000044, - 0x00000017, 0x000000c4, 0x000000a7, 0x0000007e, 0x0000003d, - 0x00000064, 0x0000005d, 0x00000019, 0x00000073, 0x00000060, - 0x00000081, 0x0000004f, 0x000000dc, 0x00000022, 0x0000002a, - 0x00000090, 0x00000088, 0x00000046, 0x000000ee, 0x000000b8, - 0x00000014, 0x000000de, 0x0000005e, 0x0000000b, 0x000000db, - 0x000000e0, 0x00000032, 0x0000003a, 0x0000000a, 0x00000049, - 0x00000006, 0x00000024, 0x0000005c, 0x000000c2, 0x000000d3, - 0x000000ac, 0x00000062, 0x00000091, 0x00000095, 0x000000e4, - 0x00000079, 0x000000e7, 0x000000c8, 0x00000037, 0x0000006d, - 0x0000008d, 0x000000d5, 0x0000004e, 0x000000a9, 0x0000006c, - 0x00000056, 0x000000f4, 0x000000ea, 0x00000065, 0x0000007a, - 0x000000ae, 0x00000008, 0x000000ba, 0x00000078, 0x00000025, - 0x0000002e, 0x0000001c, 0x000000a6, 0x000000b4, 0x000000c6, - 0x000000e8, 0x000000dd, 0x00000074, 0x0000001f, 0x0000004b, - 0x000000bd, 0x0000008b, 0x0000008a, 0x00000070, 0x0000003e, - 0x000000b5, 0x00000066, 0x00000048, 0x00000003, 0x000000f6, - 0x0000000e, 0x00000061, 0x00000035, 0x00000057, 0x000000b9, - 0x00000086, 0x000000c1, 0x0000001d, 0x0000009e, 0x000000e1, - 0x000000f8, 0x00000098, 0x00000011, 0x00000069, 0x000000d9, - 0x0000008e, 0x00000094, 0x0000009b, 0x0000001e, 0x00000087, - 0x000000e9, 0x000000ce, 0x00000055, 0x00000028, 0x000000df, - 0x0000008c, 0x000000a1, 0x00000089, 0x0000000d, 0x000000bf, - 0x000000e6, 0x00000042, 0x00000068, 0x00000041, 0x00000099, - 0x0000002d, 0x0000000f, 0x000000b0, 0x00000054, 0x000000bb, - 0x00000016, - }, - { - 0x00006300, 0x00007c00, 0x00007700, 0x00007b00, 0x0000f200, - 0x00006b00, 0x00006f00, 0x0000c500, 0x00003000, 0x00000100, - 0x00006700, 0x00002b00, 0x0000fe00, 0x0000d700, 0x0000ab00, - 0x00007600, 0x0000ca00, 0x00008200, 0x0000c900, 0x00007d00, - 0x0000fa00, 0x00005900, 0x00004700, 0x0000f000, 0x0000ad00, - 0x0000d400, 0x0000a200, 0x0000af00, 0x00009c00, 0x0000a400, - 0x00007200, 0x0000c000, 0x0000b700, 0x0000fd00, 0x00009300, - 0x00002600, 0x00003600, 0x00003f00, 0x0000f700, 0x0000cc00, - 0x00003400, 0x0000a500, 0x0000e500, 0x0000f100, 0x00007100, - 0x0000d800, 0x00003100, 0x00001500, 0x00000400, 0x0000c700, - 0x00002300, 0x0000c300, 0x00001800, 0x00009600, 0x00000500, - 0x00009a00, 0x00000700, 0x00001200, 0x00008000, 0x0000e200, - 0x0000eb00, 0x00002700, 0x0000b200, 0x00007500, 0x00000900, - 0x00008300, 0x00002c00, 0x00001a00, 0x00001b00, 0x00006e00, - 0x00005a00, 0x0000a000, 0x00005200, 0x00003b00, 0x0000d600, - 0x0000b300, 0x00002900, 0x0000e300, 0x00002f00, 0x00008400, - 0x00005300, 0x0000d100, 0x00000000, 0x0000ed00, 0x00002000, - 0x0000fc00, 0x0000b100, 0x00005b00, 0x00006a00, 0x0000cb00, - 0x0000be00, 0x00003900, 0x00004a00, 0x00004c00, 0x00005800, - 0x0000cf00, 0x0000d000, 0x0000ef00, 0x0000aa00, 0x0000fb00, - 0x00004300, 0x00004d00, 0x00003300, 0x00008500, 0x00004500, - 0x0000f900, 0x00000200, 0x00007f00, 0x00005000, 0x00003c00, - 0x00009f00, 0x0000a800, 0x00005100, 0x0000a300, 0x00004000, - 0x00008f00, 0x00009200, 0x00009d00, 0x00003800, 0x0000f500, - 0x0000bc00, 0x0000b600, 0x0000da00, 0x00002100, 0x00001000, - 0x0000ff00, 0x0000f300, 0x0000d200, 0x0000cd00, 0x00000c00, - 0x00001300, 0x0000ec00, 0x00005f00, 0x00009700, 0x00004400, - 0x00001700, 0x0000c400, 0x0000a700, 0x00007e00, 0x00003d00, - 0x00006400, 0x00005d00, 0x00001900, 0x00007300, 0x00006000, - 0x00008100, 0x00004f00, 0x0000dc00, 0x00002200, 0x00002a00, - 0x00009000, 0x00008800, 0x00004600, 0x0000ee00, 0x0000b800, - 0x00001400, 0x0000de00, 0x00005e00, 0x00000b00, 0x0000db00, - 0x0000e000, 0x00003200, 0x00003a00, 0x00000a00, 0x00004900, - 0x00000600, 0x00002400, 0x00005c00, 0x0000c200, 0x0000d300, - 0x0000ac00, 0x00006200, 0x00009100, 0x00009500, 0x0000e400, - 0x00007900, 0x0000e700, 0x0000c800, 0x00003700, 0x00006d00, - 0x00008d00, 0x0000d500, 0x00004e00, 0x0000a900, 0x00006c00, - 0x00005600, 0x0000f400, 0x0000ea00, 0x00006500, 0x00007a00, - 0x0000ae00, 0x00000800, 0x0000ba00, 0x00007800, 0x00002500, - 0x00002e00, 0x00001c00, 0x0000a600, 0x0000b400, 0x0000c600, - 0x0000e800, 0x0000dd00, 0x00007400, 0x00001f00, 0x00004b00, - 0x0000bd00, 0x00008b00, 0x00008a00, 0x00007000, 0x00003e00, - 0x0000b500, 0x00006600, 0x00004800, 0x00000300, 0x0000f600, - 0x00000e00, 0x00006100, 0x00003500, 0x00005700, 0x0000b900, - 0x00008600, 0x0000c100, 0x00001d00, 0x00009e00, 0x0000e100, - 0x0000f800, 0x00009800, 0x00001100, 0x00006900, 0x0000d900, - 0x00008e00, 0x00009400, 0x00009b00, 0x00001e00, 0x00008700, - 0x0000e900, 0x0000ce00, 0x00005500, 0x00002800, 0x0000df00, - 0x00008c00, 0x0000a100, 0x00008900, 0x00000d00, 0x0000bf00, - 0x0000e600, 0x00004200, 0x00006800, 0x00004100, 0x00009900, - 0x00002d00, 0x00000f00, 0x0000b000, 0x00005400, 0x0000bb00, - 0x00001600, - }, - { - 0x00630000, 0x007c0000, 0x00770000, 0x007b0000, 0x00f20000, - 0x006b0000, 0x006f0000, 0x00c50000, 0x00300000, 0x00010000, - 0x00670000, 0x002b0000, 0x00fe0000, 0x00d70000, 0x00ab0000, - 0x00760000, 0x00ca0000, 0x00820000, 0x00c90000, 0x007d0000, - 0x00fa0000, 0x00590000, 0x00470000, 0x00f00000, 0x00ad0000, - 0x00d40000, 0x00a20000, 0x00af0000, 0x009c0000, 0x00a40000, - 0x00720000, 0x00c00000, 0x00b70000, 0x00fd0000, 0x00930000, - 0x00260000, 0x00360000, 0x003f0000, 0x00f70000, 0x00cc0000, - 0x00340000, 0x00a50000, 0x00e50000, 0x00f10000, 0x00710000, - 0x00d80000, 0x00310000, 0x00150000, 0x00040000, 0x00c70000, - 0x00230000, 0x00c30000, 0x00180000, 0x00960000, 0x00050000, - 0x009a0000, 0x00070000, 0x00120000, 0x00800000, 0x00e20000, - 0x00eb0000, 0x00270000, 0x00b20000, 0x00750000, 0x00090000, - 0x00830000, 0x002c0000, 0x001a0000, 0x001b0000, 0x006e0000, - 0x005a0000, 0x00a00000, 0x00520000, 0x003b0000, 0x00d60000, - 0x00b30000, 0x00290000, 0x00e30000, 0x002f0000, 0x00840000, - 0x00530000, 0x00d10000, 0x00000000, 0x00ed0000, 0x00200000, - 0x00fc0000, 0x00b10000, 0x005b0000, 0x006a0000, 0x00cb0000, - 0x00be0000, 0x00390000, 0x004a0000, 0x004c0000, 0x00580000, - 0x00cf0000, 0x00d00000, 0x00ef0000, 0x00aa0000, 0x00fb0000, - 0x00430000, 0x004d0000, 0x00330000, 0x00850000, 0x00450000, - 0x00f90000, 0x00020000, 0x007f0000, 0x00500000, 0x003c0000, - 0x009f0000, 0x00a80000, 0x00510000, 0x00a30000, 0x00400000, - 0x008f0000, 0x00920000, 0x009d0000, 0x00380000, 0x00f50000, - 0x00bc0000, 0x00b60000, 0x00da0000, 0x00210000, 0x00100000, - 0x00ff0000, 0x00f30000, 0x00d20000, 0x00cd0000, 0x000c0000, - 0x00130000, 0x00ec0000, 0x005f0000, 0x00970000, 0x00440000, - 0x00170000, 0x00c40000, 0x00a70000, 0x007e0000, 0x003d0000, - 0x00640000, 0x005d0000, 0x00190000, 0x00730000, 0x00600000, - 0x00810000, 0x004f0000, 0x00dc0000, 0x00220000, 0x002a0000, - 0x00900000, 0x00880000, 0x00460000, 0x00ee0000, 0x00b80000, - 0x00140000, 0x00de0000, 0x005e0000, 0x000b0000, 0x00db0000, - 0x00e00000, 0x00320000, 0x003a0000, 0x000a0000, 0x00490000, - 0x00060000, 0x00240000, 0x005c0000, 0x00c20000, 0x00d30000, - 0x00ac0000, 0x00620000, 0x00910000, 0x00950000, 0x00e40000, - 0x00790000, 0x00e70000, 0x00c80000, 0x00370000, 0x006d0000, - 0x008d0000, 0x00d50000, 0x004e0000, 0x00a90000, 0x006c0000, - 0x00560000, 0x00f40000, 0x00ea0000, 0x00650000, 0x007a0000, - 0x00ae0000, 0x00080000, 0x00ba0000, 0x00780000, 0x00250000, - 0x002e0000, 0x001c0000, 0x00a60000, 0x00b40000, 0x00c60000, - 0x00e80000, 0x00dd0000, 0x00740000, 0x001f0000, 0x004b0000, - 0x00bd0000, 0x008b0000, 0x008a0000, 0x00700000, 0x003e0000, - 0x00b50000, 0x00660000, 0x00480000, 0x00030000, 0x00f60000, - 0x000e0000, 0x00610000, 0x00350000, 0x00570000, 0x00b90000, - 0x00860000, 0x00c10000, 0x001d0000, 0x009e0000, 0x00e10000, - 0x00f80000, 0x00980000, 0x00110000, 0x00690000, 0x00d90000, - 0x008e0000, 0x00940000, 0x009b0000, 0x001e0000, 0x00870000, - 0x00e90000, 0x00ce0000, 0x00550000, 0x00280000, 0x00df0000, - 0x008c0000, 0x00a10000, 0x00890000, 0x000d0000, 0x00bf0000, - 0x00e60000, 0x00420000, 0x00680000, 0x00410000, 0x00990000, - 0x002d0000, 0x000f0000, 0x00b00000, 0x00540000, 0x00bb0000, - 0x00160000, - }, - { - 0x63000000, 0x7c000000, 0x77000000, 0x7b000000, 0xf2000000, - 0x6b000000, 0x6f000000, 0xc5000000, 0x30000000, 0x01000000, - 0x67000000, 0x2b000000, 0xfe000000, 0xd7000000, 0xab000000, - 0x76000000, 0xca000000, 0x82000000, 0xc9000000, 0x7d000000, - 0xfa000000, 0x59000000, 0x47000000, 0xf0000000, 0xad000000, - 0xd4000000, 0xa2000000, 0xaf000000, 0x9c000000, 0xa4000000, - 0x72000000, 0xc0000000, 0xb7000000, 0xfd000000, 0x93000000, - 0x26000000, 0x36000000, 0x3f000000, 0xf7000000, 0xcc000000, - 0x34000000, 0xa5000000, 0xe5000000, 0xf1000000, 0x71000000, - 0xd8000000, 0x31000000, 0x15000000, 0x04000000, 0xc7000000, - 0x23000000, 0xc3000000, 0x18000000, 0x96000000, 0x05000000, - 0x9a000000, 0x07000000, 0x12000000, 0x80000000, 0xe2000000, - 0xeb000000, 0x27000000, 0xb2000000, 0x75000000, 0x09000000, - 0x83000000, 0x2c000000, 0x1a000000, 0x1b000000, 0x6e000000, - 0x5a000000, 0xa0000000, 0x52000000, 0x3b000000, 0xd6000000, - 0xb3000000, 0x29000000, 0xe3000000, 0x2f000000, 0x84000000, - 0x53000000, 0xd1000000, 0x00000000, 0xed000000, 0x20000000, - 0xfc000000, 0xb1000000, 0x5b000000, 0x6a000000, 0xcb000000, - 0xbe000000, 0x39000000, 0x4a000000, 0x4c000000, 0x58000000, - 0xcf000000, 0xd0000000, 0xef000000, 0xaa000000, 0xfb000000, - 0x43000000, 0x4d000000, 0x33000000, 0x85000000, 0x45000000, - 0xf9000000, 0x02000000, 0x7f000000, 0x50000000, 0x3c000000, - 0x9f000000, 0xa8000000, 0x51000000, 0xa3000000, 0x40000000, - 0x8f000000, 0x92000000, 0x9d000000, 0x38000000, 0xf5000000, - 0xbc000000, 0xb6000000, 0xda000000, 0x21000000, 0x10000000, - 0xff000000, 0xf3000000, 0xd2000000, 0xcd000000, 0x0c000000, - 0x13000000, 0xec000000, 0x5f000000, 0x97000000, 0x44000000, - 0x17000000, 0xc4000000, 0xa7000000, 0x7e000000, 0x3d000000, - 0x64000000, 0x5d000000, 0x19000000, 0x73000000, 0x60000000, - 0x81000000, 0x4f000000, 0xdc000000, 0x22000000, 0x2a000000, - 0x90000000, 0x88000000, 0x46000000, 0xee000000, 0xb8000000, - 0x14000000, 0xde000000, 0x5e000000, 0x0b000000, 0xdb000000, - 0xe0000000, 0x32000000, 0x3a000000, 0x0a000000, 0x49000000, - 0x06000000, 0x24000000, 0x5c000000, 0xc2000000, 0xd3000000, - 0xac000000, 0x62000000, 0x91000000, 0x95000000, 0xe4000000, - 0x79000000, 0xe7000000, 0xc8000000, 0x37000000, 0x6d000000, - 0x8d000000, 0xd5000000, 0x4e000000, 0xa9000000, 0x6c000000, - 0x56000000, 0xf4000000, 0xea000000, 0x65000000, 0x7a000000, - 0xae000000, 0x08000000, 0xba000000, 0x78000000, 0x25000000, - 0x2e000000, 0x1c000000, 0xa6000000, 0xb4000000, 0xc6000000, - 0xe8000000, 0xdd000000, 0x74000000, 0x1f000000, 0x4b000000, - 0xbd000000, 0x8b000000, 0x8a000000, 0x70000000, 0x3e000000, - 0xb5000000, 0x66000000, 0x48000000, 0x03000000, 0xf6000000, - 0x0e000000, 0x61000000, 0x35000000, 0x57000000, 0xb9000000, - 0x86000000, 0xc1000000, 0x1d000000, 0x9e000000, 0xe1000000, - 0xf8000000, 0x98000000, 0x11000000, 0x69000000, 0xd9000000, - 0x8e000000, 0x94000000, 0x9b000000, 0x1e000000, 0x87000000, - 0xe9000000, 0xce000000, 0x55000000, 0x28000000, 0xdf000000, - 0x8c000000, 0xa1000000, 0x89000000, 0x0d000000, 0xbf000000, - 0xe6000000, 0x42000000, 0x68000000, 0x41000000, 0x99000000, - 0x2d000000, 0x0f000000, 0xb0000000, 0x54000000, 0xbb000000, - 0x16000000, - }, -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static inline uint8_t get_byte(const uint32_t x, const unsigned n) -{ - return x >> (n << 3); -} - -/* initialise the key schedule from the user supplied key */ - -static uint32_t aes_ror32(uint32_t word, unsigned int shift) -{ - return (word >> shift) | (word << (32 - shift)); -} - -/* aes_expand_key - Expands the AES key as described in FIPS-197 - * @ctx: The location where the computed key will be stored. - * @in_key: The supplied key. - * @key_len: The length of the supplied key. - * - * Returns 0 on success. The function fails only if an invalid key size (or - * pointer) is supplied. - * - * The expanded key size is 240 bytes (max of 14 rounds with a unique 16 - * bytes key schedule plus a 16 bytes key which is used before the first - * round). The decryption key is prepared for the "Equivalent Inverse Cipher" - * as described in FIPS-197. The first slot (16 bytes) of each key (enc or - * dec) is for the initial combination, the second slot for the first round - * and so on. - */ - -static int aes_expand_key(aes_context_t *ctx, const uint8_t *in_key, - unsigned int key_len) -{ - const uint32_t *key = (const uint32_t *)in_key; - uint32_t i; - uint32_t t; - uint32_t u; - uint32_t v; - uint32_t w; - uint32_t j; - - if (key_len != AES_KEYSIZE_128 && key_len != AES_KEYSIZE_192 && - key_len != AES_KEYSIZE_256) - { - return -1; - } - - ctx->key_length = key_len; - - ctx->key_dec[key_len + 24] = ctx->key_enc[0] = le32_to_cpu(key[0]); - ctx->key_dec[key_len + 25] = ctx->key_enc[1] = le32_to_cpu(key[1]); - ctx->key_dec[key_len + 26] = ctx->key_enc[2] = le32_to_cpu(key[2]); - ctx->key_dec[key_len + 27] = ctx->key_enc[3] = le32_to_cpu(key[3]); - - switch (key_len) - { - case AES_KEYSIZE_128: - t = ctx->key_enc[3]; - for (i = 0; i < 10; ++i) - loop4(i); - break; - - case AES_KEYSIZE_192: - ctx->key_enc[4] = le32_to_cpu(key[4]); - t = ctx->key_enc[5] = le32_to_cpu(key[5]); - for (i = 0; i < 8; ++i) - loop6(i); - break; - - case AES_KEYSIZE_256: - ctx->key_enc[4] = le32_to_cpu(key[4]); - ctx->key_enc[5] = le32_to_cpu(key[5]); - ctx->key_enc[6] = le32_to_cpu(key[6]); - t = ctx->key_enc[7] = le32_to_cpu(key[7]); - for (i = 0; i < 6; ++i) - loop8(i); - loop8tophalf(i); - break; - } - - ctx->key_dec[0] = ctx->key_enc[key_len + 24]; - ctx->key_dec[1] = ctx->key_enc[key_len + 25]; - ctx->key_dec[2] = ctx->key_enc[key_len + 26]; - ctx->key_dec[3] = ctx->key_enc[key_len + 27]; - - for (i = 4; i < key_len + 24; ++i) - { - j = key_len + 24 - (i & ~3) + (i & 3); - imix_col(ctx->key_dec[j], ctx->key_enc[i]); - } - - return 0; -} - -/* aes_set_key - Set the AES key. - * @ctx: AES context struct. - * @in_key: The input key. - * @key_len: The size of the key. - * - * Returns 0 on success, on failure -1 is returned. - * The function uses aes_expand_key() to expand the key. - */ - -static int aes_set_key(aes_context_t *ctx, const uint8_t *in_key, - unsigned int key_len) -{ - int ret; - - ret = aes_expand_key(ctx, in_key, key_len); - if (!ret) return 0; - - return -1; -} - -static void aes_encrypt(aes_context_t *ctx, uint8_t *out, const uint8_t *in) -{ - const uint32_t *src = (const uint32_t *)in; - uint32_t *dst = (uint32_t *)out; - uint32_t b0[4]; - uint32_t b1[4]; - const uint32_t *kp = ctx->key_enc + 4; - const int key_len = ctx->key_length; - - b0[0] = le32_to_cpu(src[0]) ^ ctx->key_enc[0]; - b0[1] = le32_to_cpu(src[1]) ^ ctx->key_enc[1]; - b0[2] = le32_to_cpu(src[2]) ^ ctx->key_enc[2]; - b0[3] = le32_to_cpu(src[3]) ^ ctx->key_enc[3]; - - if (key_len > 24) - { - f_nround(b1, b0, kp); - f_nround(b0, b1, kp); - } - - if (key_len > 16) - { - f_nround(b1, b0, kp); - f_nround(b0, b1, kp); - } - - f_nround(b1, b0, kp); - f_nround(b0, b1, kp); - f_nround(b1, b0, kp); - f_nround(b0, b1, kp); - f_nround(b1, b0, kp); - f_nround(b0, b1, kp); - f_nround(b1, b0, kp); - f_nround(b0, b1, kp); - f_nround(b1, b0, kp); - f_lround(b0, b1, kp); - - dst[0] = cpu_to_le32(b0[0]); - dst[1] = cpu_to_le32(b0[1]); - dst[2] = cpu_to_le32(b0[2]); - dst[3] = cpu_to_le32(b0[3]); -} - -/* Generate a set of new PRNG values by encrypting a new block. */ - -static void prng_generate(void) -{ - byte input[16]; - byte output[16]; - unsigned int i; - - /* Input for the cipher is a consecutively increasing 32-bit counter. */ - - for (i = 0; i < 4; ++i) - { - input[4 * i] = prng_input_counter & 0xff; - input[4 * i + 1] = (prng_input_counter >> 8) & 0xff; - input[4 * i + 2] = (prng_input_counter >> 16) & 0xff; - input[4 * i + 3] = (prng_input_counter >> 24) & 0xff; - ++prng_input_counter; - } - - aes_encrypt(&prng_context, output, input); - - for (i = 0; i < 4; ++i) - { - prng_values[i] = output[4 * i] | (output[4 * i + 1] << 8) | - (output[4 * i + 2] << 16) | (output[4 * i + 3] << 24); - } - - prng_value_index = 0; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/* Initialize Pseudo-RNG using the specified 128-bit key. */ - -void prng_start(prng_seed_t key) -{ - aes_set_key(&prng_context, key, sizeof(prng_seed_t)); - prng_value_index = 4; - prng_input_counter = 0; - prng_enabled = true; -} - -void prng_stop(void) -{ - prng_enabled = false; -} - -/* Read a random 32-bit integer from the PRNG. */ - -unsigned int prng_random(void) -{ - unsigned int result; - - if (!prng_enabled) - { - return 0; - } - - if (prng_value_index >= 4) - { - prng_generate(); - } - - result = prng_values[prng_value_index]; - ++prng_value_index; - - return result; -} diff --git a/games/NXDoom/src/aes_prng.h b/games/NXDoom/src/aes_prng.h deleted file mode 100644 index eed8dd78c..000000000 --- a/games/NXDoom/src/aes_prng.h +++ /dev/null @@ -1,44 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/aes_prng.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Pseudo-random number generator for secure demos. - * - ****************************************************************************/ - -#ifndef __AES_PRNG_H__ -#define __AES_PRNG_H__ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "doomtype.h" - -/* Nonce value used as random seed for secure demos. */ - -typedef byte prng_seed_t[16]; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -void prng_start(prng_seed_t seed); -void prng_stop(void); -unsigned int prng_random(void); - -#endif /* __AES_PRNG_H__ */ diff --git a/games/NXDoom/src/config.h b/games/NXDoom/src/config.h deleted file mode 100644 index b64275300..000000000 --- a/games/NXDoom/src/config.h +++ /dev/null @@ -1,25 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/config.h - * - * SPDX-License-Identifer: GPLv2 - * - * NuttX compatible config.h file. - * - * TODO: can we take a cleaner approach later by baking this into logic? - * - ****************************************************************************/ - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define HAVE_DECL_STRCASECMP 1 -#define HAVE_DECL_STRNCASECMP 1 - -#define PACKAGE_TARNAME "nxdoom" -#define PACKAGE_NAME "NXDoom" -#define PACKAGE_STRING "NXDoom v0.0.0" -#define PROGRAM_PREFIX "" - -#define DISABLE_SDL2MIXER -#define DISABLE_SDL2NET diff --git a/games/NXDoom/src/d_dedicated.c b/games/NXDoom/src/d_dedicated.c deleted file mode 100644 index 307010f34..000000000 --- a/games/NXDoom/src/d_dedicated.c +++ /dev/null @@ -1,60 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/d_dedicated.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * Code specific to the standalone dedicated server. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include - -#include "config.h" - -#include "m_argv.h" -#include "net_defs.h" - -#include "net_dedicated.h" -#include "net_server.h" -#include "z_zone.h" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -void net_cl_run(void) -{ - /* No client present :-) - * - * This is here because the server code sometimes runs this - * to let the client do some processing if it needs to. - * In a standalone dedicated server, we don't have a client. - */ -} - -void d_doom_main(void) -{ - printf(PACKAGE_NAME " standalone dedicated server\n"); - - z_init(); - - net_dedicated_server(); -} diff --git a/games/NXDoom/src/d_event.c b/games/NXDoom/src/d_event.c deleted file mode 100644 index 0b2a29e6c..000000000 --- a/games/NXDoom/src/d_event.c +++ /dev/null @@ -1,81 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/d_event.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: Event handling. - * - * Events are asynchronous inputs generally generated by the game user. - * Events can be discarded if no responder claims them - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "d_event.h" -#include - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define MAXEVENTS 64 - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static event_t events[MAXEVENTS]; -static int eventhead; -static int eventtail; - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/* d_post_event - * Called by the I/O functions when input is detected - */ - -void d_post_event(event_t *ev) -{ - events[eventhead] = *ev; - eventhead = (eventhead + 1) % MAXEVENTS; -} - -/* Read an event from the queue. */ - -event_t *d_pop_event(void) -{ - event_t *result; - - /* No more events waiting. */ - - if (eventtail == eventhead) - { - return NULL; - } - - result = &events[eventtail]; - - /* Advance to the next event in the queue. */ - - eventtail = (eventtail + 1) % MAXEVENTS; - - return result; -} diff --git a/games/NXDoom/src/d_event.h b/games/NXDoom/src/d_event.h deleted file mode 100644 index f1f43133f..000000000 --- a/games/NXDoom/src/d_event.h +++ /dev/null @@ -1,192 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/d_event.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * - ****************************************************************************/ - -#ifndef __D_EVENT__ -#define __D_EVENT__ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "doomtype.h" - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -/* Event handling. */ - -/* Input event types. */ - -typedef enum -{ - /* Key press/release events. - * data1: Key code (from doomkeys.h) of the key that was - * pressed or released. This is the key as it appears - * on a US keyboard layout, and does not change with - * layout. - * For ev_keydown only: - * data2: ASCII representation of the key that was pressed that - * changes with the keyboard layout; eg. if 'Z' is - * pressed on a German keyboard, data1='y',data2='z'. - * Not affected by modifier keys. - * data3: ASCII input, fully modified according to keyboard - * layout and any modifier keys that are held down. - * Only set if i_start_text_input() has been called. - */ - - ev_keydown, - ev_keyup, - - /* Mouse movement event. - * data1: Bitfield of buttons currently held down. - * (bit 0 = left; bit 1 = right; bit 2 = middle). - * data2: X axis mouse movement (turn). - * data3: Y axis mouse movement (forward/backward). - */ - - ev_mouse, - - /* Joystick state. - * data1: Bitfield of buttons currently pressed. - * data2: X axis mouse movement (turn). - * data3: Y axis mouse movement (forward/backward). - * data4: Third axis mouse movement (strafe). - * data5: Fourth axis mouse movement (look) - * data6: Dpad and analog stick direction. - */ - - ev_joystick, - - /* Quit event. Triggered when the user clicks the "close" button - * to terminate the application. - */ - - ev_quit -} evtype_t; - -/* Event structure. */ - -typedef struct -{ - evtype_t type; - - /* Event-specific data; see the descriptions given above. */ - - int data1; - int data2; - int data3; - int data4; - int data5; - int data6; -} event_t; - -/* Button/action code definitions. */ - -typedef enum -{ - /* Press "Fire". */ - - BT_ATTACK = 1, - - /* Use button, to open doors, activate switches. */ - - BT_USE = 2, - - /* Flag: game events, not really buttons. */ - - BT_SPECIAL = 128, - BT_SPECIALMASK = 3, - - /* Flag, weapon change pending. - * If true, the next 3 bits hold weapon num. - */ - - BT_CHANGE = 4, - - /* The 3bit weapon mask and shift, convenience. */ - - BT_WEAPONMASK = (8 + 16 + 32), - BT_WEAPONSHIFT = 3, - - /* Pause the game. */ - - BTS_PAUSE = 1, - - /* Save the game at each console. */ - - BTS_SAVEGAME = 2, - - /* Savegame slot numbers occupy the second byte of buttons. */ - - BTS_SAVEMASK = (4 + 8 + 16), - BTS_SAVESHIFT = 2, -} buttoncode_t; - -/* villsa [STRIFE] Strife specific buttons - * TODO - not finished - */ - -typedef enum -{ - /* Player view look up */ - - BT2_LOOKUP = 1, - - /* Player view look down */ - - BT2_LOOKDOWN = 2, - - /* Center player's view */ - - BT2_CENTERVIEW = 4, - - /* Use inventory item */ - - BT2_INVUSE = 8, - - /* Drop inventory item */ - - BT2_INVDROP = 16, - - /* Jump up and down */ - - BT2_JUMP = 32, - - /* Use medkit */ - - BT2_HEALTH = 128, -} buttoncode2_t; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/* Called by IO functions when input is detected. */ - -void d_post_event(event_t *ev); - -/* Read an event from the event queue */ - -event_t *d_pop_event(void); - -#endif /* __D_EVENT__ */ diff --git a/games/NXDoom/src/d_iwad.c b/games/NXDoom/src/d_iwad.c deleted file mode 100644 index a6f1cd945..000000000 --- a/games/NXDoom/src/d_iwad.c +++ /dev/null @@ -1,539 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/d_iwad.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Search for and locate an IWAD file, and initialize according - * to the IWAD type. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include -#include - -#include "d_iwad.h" -#include "deh_str.h" -#include "doomkeys.h" -#include "i_system.h" -#include "m_argv.h" -#include "m_config.h" -#include "m_misc.h" -#include "w_wad.h" -#include "z_zone.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* Array of locations to search for IWAD files - * - * "128 IWAD search directories should be enough for anybody". - */ - -#define MAX_IWAD_DIRS 128 - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static const iwad_t g_iwads[] = -{ - {"doom2.wad", doom2, commercial, "Doom II"}, - {"plutonia.wad", pack_plut, commercial, "Final Doom: Plutonia Experiment"}, - {"tnt.wad", pack_tnt, commercial, "Final Doom: TNT: Evilution"}, - {"doom.wad", doom, retail, "Doom"}, - {"doom1.wad", doom, shareware, "Doom Shareware"}, - {"doom2f.wad", doom2, commercial, "Doom II: L'Enfer sur Terre"}, - {"chex.wad", pack_chex, retail, "Chex Quest"}, - {"hacx.wad", pack_hacx, commercial, "Hacx"}, - {"freedoom2.wad", doom2, commercial, "Freedoom: Phase 2"}, - {"freedoom1.wad", doom, retail, "Freedoom: Phase 1"}, - {"freedm.wad", doom2, commercial, "FreeDM"}, - {"heretic.wad", heretic, retail, "Heretic"}, - {"heretic1.wad", heretic, shareware, "Heretic Shareware"}, - {"hexen.wad", hexen, commercial, "Hexen"}, - {"strife1.wad", strife, commercial, "Strife"}, -}; - -static boolean iwad_dirs_built = false; -static const char *iwad_dirs[MAX_IWAD_DIRS]; -static int num_iwad_dirs = 0; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static void add_iwad_dir(const char *dir) -{ - if (num_iwad_dirs < MAX_IWAD_DIRS) - { - iwad_dirs[num_iwad_dirs] = dir; - ++num_iwad_dirs; - } -} - -/* Returns true if the specified path is a path to a file - * of the specified name. - */ - -static boolean dir_is_file(const char *path, const char *filename) -{ - return strchr(path, DIR_SEPARATOR) != NULL && - !strcasecmp(m_base_name(path), filename); -} - -/* Check if the specified directory contains the specified IWAD - * file, returning the full path to the IWAD if found, or NULL - * if not found. - */ - -static char *check_dir_has_iwad(const char *dir, const char *iwadname) -{ - char *filename; - char *probe; - - /* As a special case, the "directory" may refer directly to an - * IWAD file if the path comes from DOOMWADDIR or DOOMWADPATH. - */ - - probe = m_file_case_exists(dir); - if (dir_is_file(dir, iwadname) && probe != NULL) - { - return probe; - } - - /* Construct the full path to the IWAD if it is located in - * this directory, and check if it exists. - */ - - if (!strcmp(dir, ".")) - { - filename = m_string_duplicate(iwadname); - } - else - { - filename = m_string_join(dir, DIR_SEPARATOR_S, iwadname, NULL); - } - - free(probe); - probe = m_file_case_exists(filename); - free(filename); - - if (probe != NULL) - { - return probe; - } - - return NULL; -} - -/* Search a directory to try to find an IWAD - * Returns the location of the IWAD if found, otherwise NULL. - */ - -static char *search_dir_for_iwad(const char *dir, int mask, - gamemission_t *mission) -{ - char *filename; - size_t i; - - for (i = 0; i < arrlen(g_iwads); ++i) - { - if (((1 << g_iwads[i].mission) & mask) == 0) - { - continue; - } - - filename = check_dir_has_iwad(dir, (g_iwads[i].name)); - - if (filename != NULL) - { - *mission = g_iwads[i].mission; - - return filename; - } - } - - return NULL; -} - -/* When given an IWAD with the '-iwad' parameter, - * attempt to identify it by its name. - */ - -static gamemission_t identify_iwad_by_name(const char *name, int mask) -{ - size_t i; - gamemission_t mission; - - name = m_base_name(name); - mission = none; - - for (i = 0; i < arrlen(g_iwads); ++i) - { - /* Check if the filename is this IWAD name. - * Only use supported missions: - */ - - if (((1 << g_iwads[i].mission) & mask) == 0) continue; - - /* Check if it ends in this IWAD name. */ - - if (!strcasecmp(name, g_iwads[i].name)) - { - mission = g_iwads[i].mission; - break; - } - } - - return mission; -} - -/* Add IWAD directories parsed from splitting a path string containing - * paths separated by PATH_SEPARATOR. 'suffix' is a string to concatenate - * to the end of the paths before adding them. - */ - -static void add_iwad_path(const char *path, const char *suffix) -{ - char *left; - char *p; - char *dup_path; - - dup_path = m_string_duplicate(path); - - /* Split into individual dirs within the list. */ - - left = dup_path; - - for (; ; ) - { - p = strchr(left, PATH_SEPARATOR); - if (p != NULL) - { - /* Break at the separator and use the left hand side - * as another iwad dir - */ - - *p = '\0'; - - add_iwad_dir(m_string_join(left, suffix, NULL)); - left = p + 1; - } - else - { - break; - } - } - - add_iwad_dir(m_string_join(left, suffix, NULL)); - - free(dup_path); -} - -/* Build a list of IWAD files */ - -static void buld_iwad_dir_list(void) -{ - char *env; - - if (iwad_dirs_built) - { - return; - } - - /* Look in the current directory. Doom always does this. */ - - add_iwad_dir("."); - - /* Next check the directory where the executable is located. This might - * be different from the current directory. - */ - - add_iwad_dir(m_dir_name(myargv[0])); - - /* Add DOOMWADDIR if it is in the environment */ - - env = getenv("DOOMWADDIR"); - if (env != NULL) - { - add_iwad_dir(env); - } - - /* Add dirs from DOOMWADPATH: */ - - env = getenv("DOOMWADPATH"); - if (env != NULL) - { - add_iwad_path(env, ""); - } - - /* Don't run this function again. */ - - iwad_dirs_built = true; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/* Searches WAD search paths for an WAD with a specific filename. */ - -char *d_find_wad_by_name(const char *name) -{ - char *path; - char *probe; - int i; - - /* Absolute path? */ - - probe = m_file_case_exists(name); - if (probe != NULL) - { - return probe; - } - - buld_iwad_dir_list(); - - /* Search through all IWAD paths for a file with the given name. */ - - for (i = 0; i < num_iwad_dirs; ++i) - { - /* As a special case, if this is in DOOMWADDIR or DOOMWADPATH, - * the "directory" may actually refer directly to an IWAD - * file. - */ - - probe = m_file_case_exists(iwad_dirs[i]); - if (dir_is_file(iwad_dirs[i], name) && probe != NULL) - { - return probe; - } - - free(probe); - - /* Construct a string for the full path */ - - path = m_string_join(iwad_dirs[i], DIR_SEPARATOR_S, name, NULL); - - probe = m_file_case_exists(path); - if (probe != NULL) - { - return probe; - } - - free(path); - } - - /* File not found */ - - return NULL; -} - -/* d_try_find_wad_by_name - * - * Searches for a WAD by its filename, or returns a copy of the filename - * if not found. - */ - -char *d_try_find_wad_by_name(const char *filename) -{ - char *result; - - result = d_find_wad_by_name(filename); - - if (result != NULL) - { - return result; - } - else - { - return m_string_duplicate(filename); - } -} - -/* FindIWAD - * Checks availability of IWAD files by name, - * to determine whether registered/commercial features - * should be executed (notably loading PWADs). - */ - -char *d_find_iwad(int mask, gamemission_t *mission) -{ - char *result; - const char *iwadfile; - int iwadparm; - int i; - - /* Check for the -iwad parameter - * - * Specify an IWAD file to use. - * - * @arg - * - */ - - iwadparm = m_check_parm_with_args("-iwad", 1); - - if (iwadparm) - { - /* Search through IWAD dirs for an IWAD with the given name. */ - - iwadfile = myargv[iwadparm + 1]; - - result = d_find_wad_by_name(iwadfile); - - if (result == NULL) - { - i_error("IWAD file '%s' not found!", iwadfile); - } - - *mission = identify_iwad_by_name(result, mask); - } - else - { - /* Search through the list and look for an IWAD */ - - result = NULL; - - buld_iwad_dir_list(); - - for (i = 0; result == NULL && i < num_iwad_dirs; ++i) - { - result = search_dir_for_iwad(iwad_dirs[i], mask, mission); - } - } - - return result; -} - -/* Find all IWADs in the IWAD search path matching the given mask. */ - -const iwad_t **d_find_all_iwads(int mask) -{ - const iwad_t **result; - int result_len; - char *filename; - int i; - - result = malloc(sizeof(iwad_t *) * (arrlen(g_iwads) + 1)); - result_len = 0; - - /* Try to find all IWADs */ - - for (i = 0; i < arrlen(g_iwads); ++i) - { - if (((1 << g_iwads[i].mission) & mask) == 0) - { - continue; - } - - filename = d_find_wad_by_name(g_iwads[i].name); - - if (filename != NULL) - { - result[result_len] = &g_iwads[i]; - ++result_len; - } - } - - /* End of list */ - - result[result_len] = NULL; - - return result; -} - -/* Get the IWAD name used for savegames. */ - -const char *d_save_game_iwad_name(gamemission_t gamemission, - game_variant_t gamevariant) -{ - size_t i; - - /* Determine the IWAD name to use for savegames. - * This determines the directory the savegame files get put into. - * - * Note that we match on gamemission rather than on IWAD name. - * This ensures that doom1.wad and doom.wad saves are stored - * in the same place. - */ - - if (gamevariant == freedoom) - { - if (gamemission == doom) - { - return "freedoom1.wad"; - } - else if (gamemission == doom2) - { - return "freedoom2.wad"; - } - } - else if (gamevariant == freedm && gamemission == doom2) - { - return "freedm.wad"; - } - - for (i = 0; i < arrlen(g_iwads); ++i) - { - if (gamemission == g_iwads[i].mission) - { - return g_iwads[i].name; - } - } - - /* Default fallback: */ - - return "unknown.wad"; -} - -const char *d_suggest_iwad_name(gamemission_t mission, game_mode_t mode) -{ - int i; - - for (i = 0; i < arrlen(g_iwads); ++i) - { - if (g_iwads[i].mission == mission && g_iwads[i].mode == mode) - { - return g_iwads[i].name; - } - } - - return "unknown.wad"; -} - -const char *d_suggest_game_name(gamemission_t mission, game_mode_t mode) -{ - int i; - - for (i = 0; i < arrlen(g_iwads); ++i) - { - if (g_iwads[i].mission == mission && - (mode == indetermined || g_iwads[i].mode == mode)) - { - return g_iwads[i].description; - } - } - - return "Unknown game?"; -} diff --git a/games/NXDoom/src/d_iwad.h b/games/NXDoom/src/d_iwad.h deleted file mode 100644 index bb2681c8b..000000000 --- a/games/NXDoom/src/d_iwad.h +++ /dev/null @@ -1,68 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/d_iwad.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Find IWAD and initialize according to IWAD type. - * - ****************************************************************************/ - -#ifndef __D_IWAD__ -#define __D_IWAD__ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "d_mode.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define IWAD_MASK_DOOM \ - ((1 << doom) | (1 << doom2) | (1 << pack_tnt) | (1 << pack_plut) | \ - (1 << pack_chex) | (1 << pack_hacx)) -#define IWAD_MASK_HERETIC (1 << heretic) -#define IWAD_MASK_HEXEN (1 << hexen) -#define IWAD_MASK_STRIFE (1 << strife) - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -typedef struct -{ - const char *name; - gamemission_t mission; - game_mode_t mode; - const char *description; -} iwad_t; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -char *d_find_wad_by_name(const char *filename); -char *d_try_find_wad_by_name(const char *filename); -char *d_find_iwad(int mask, gamemission_t *mission); -const iwad_t **d_find_all_iwads(int mask); -const char *d_save_game_iwad_name(gamemission_t gamemission, - game_variant_t gamevariant); -const char *d_suggest_iwad_name(gamemission_t mission, game_mode_t mode); -const char *d_suggest_game_name(gamemission_t mission, game_mode_t mode); - -#endif /* __D_IWAD__ */ diff --git a/games/NXDoom/src/d_loop.c b/games/NXDoom/src/d_loop.c deleted file mode 100644 index 28b00dfaa..000000000 --- a/games/NXDoom/src/d_loop.c +++ /dev/null @@ -1,955 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/d_loop.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Main loop code. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -#include "d_event.h" -#include "d_loop.h" -#include "d_ticcmd.h" - -#include "i_system.h" -#include "i_timer.h" -#include "i_video.h" - -#include "m_argv.h" -#include "m_fixed.h" - -#ifdef CONFIG_GAMES_NXDOOM_NET -#include "net_client.h" -#include "net_gui.h" -#include "net_io.h" -#include "net_loop.h" -#include "net_query.h" -#include "net_sdl.h" -#include "net_server.h" -#endif - -/* TODO: Move nonvanilla demo functions into a dedicated file. */ - -#include "m_misc.h" -#include "w_wad.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* Maximum time that we wait in try_run_tics() for netgame data to be - * received before we bail out and render a frame anyway. - * Vanilla Doom used 20 for this value, but we use a smaller value - * instead for better responsiveness of the menu when we're stuck. - */ - -#define MAX_NETGAME_STALL_TICS 5 - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/* The complete set of data for a particular tic. */ - -typedef struct -{ - ticcmd_t cmds[CONFIG_GAMES_NXDOOM_NET_MAXPLAYERS]; - boolean ingame[CONFIG_GAMES_NXDOOM_NET_MAXPLAYERS]; -} ticcmd_set_t; - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/* gametic is the tic about to (or currently being) run - * maketic is the tic that hasn't had control made for it yet - * recvtic is the latest tic received from the server. - * - * a gametic cannot be run until ticcmds are received for it - * from all players. - */ - -static ticcmd_set_t ticdata[CONFIG_GAMES_NXDOOM_NET_BACKUPTICS]; - -/* The index of the next tic to be made (with a call to build_ticcmd). */ - -static int maketic; - -/* The number of complete tics received from the server so far. */ - -static int recvtic; - -/* Index of the local player. */ - -static int localplayer; - -/* Used for original sync code. */ - -static int skiptics = 0; - -/* Use new client synchronization code */ - -static boolean new_sync = true; - -/* Callback functions for loop code. */ - -static loop_interface_t *loop_interface = NULL; - -/* Current players in the multiplayer game. - * This is distinct from playeringame[] used by the game code, which may - * modify playeringame[] when playing back multiplayer demos. - */ - -static boolean local_playeringame[CONFIG_GAMES_NXDOOM_NET_MAXPLAYERS]; - -/* Requested player class "sent" to the server on connect. - * If we are only doing a single player game then this needs to be remembered - * and saved in the game settings. - */ - -static int player_class; - -#ifndef CONFIG_GAMES_NXDOOM_NET -static boolean net_client_connected = false; -static boolean drone = false; -#endif - -static int frameon; -static int frameskip[4]; -static int oldnettics; - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/* The number of tics that have been run (using run_tic) so far. */ - -int gametic; - -/* When set to true, a single tic is run each time try_run_tics() is called. - * This is used for -timedemo mode. - */ - -boolean singletics = false; - -/* Reduce the bandwidth needed by sampling game input less and transmitting - * less. If ticdup is 2, sample half normal, 3 = one third normal, etc. - */ - -int ticdup; - -/* Amount to offset the timer for game sync. */ - -fixed_t offsetms; - -int lasttime; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/* 35 fps clock adjusted by offsetms milliseconds */ - -static int get_adjusted_time(void) -{ - int time_ms; - - time_ms = i_get_time_ms(); - - if (new_sync) - { - /* Use the adjustments from net_client.c only if we are - * using the new sync mode. - */ - - time_ms += (offsetms / FRACUNIT); - } - - return (time_ms * TICRATE) / 1000; -} - -static boolean build_new_tic(void) -{ - int gameticdiv; - ticcmd_t cmd; - - gameticdiv = gametic / ticdup; - - i_start_tic(); - loop_interface->process_events(); - - /* Always run the menu */ - - loop_interface->run_menu(); - - if (drone) - { - /* In drone mode, do not generate any ticcmds. */ - - return false; - } - - if (new_sync) - { - /* If playing single player, do not allow tics to buffer - * up very far - */ - - if (!net_client_connected && maketic - gameticdiv > 2) return false; - - /* Never go more than ~200ms ahead */ - - if (maketic - gameticdiv > 8) return false; - } - else - { - if (maketic - gameticdiv >= 5) return false; - } - - /* printf ("mk:%i ",maketic); */ - - memset(&cmd, 0, sizeof(ticcmd_t)); - loop_interface->build_ticcmd(&cmd, maketic); - -#ifdef CONFIG_GAMES_NXDOOM_NET - if (net_client_connected) - { - net_cl_send_ticcmd(&cmd, maketic); - } -#endif - - ticdata[maketic % CONFIG_GAMES_NXDOOM_NET_BACKUPTICS].cmds[localplayer] = - cmd; - ticdata[maketic % CONFIG_GAMES_NXDOOM_NET_BACKUPTICS].ingame[localplayer] = - true; - - ++maketic; - - return true; -} - -static boolean strict_demos(void) -{ - /* @category demo - * - * When recording or playing back demos, disable any extensions - * of the vanilla demo format - record demos as vanilla would do, - * and play back demos as vanilla would do. - * - */ - - return m_parm_exists("-strictdemos"); -} - -static void d_disconnected(void) -{ - /* In drone mode, the game cannot continue once disconnected. */ - - if (drone) - { - i_error("Disconnected from server in drone mode."); - } - - /* disconnected from server */ - - printf("Disconnected from server.\n"); -} - -static int get_low_tic(void) -{ - int lowtic; - - lowtic = maketic; - - if (net_client_connected) - { - if (drone || recvtic < lowtic) - { - lowtic = recvtic; - } - } - - return lowtic; -} - -static void old_net_sync(void) -{ - unsigned int i; - int keyplayer = -1; - - frameon++; - - /* ideally maketic should be 1 - 3 tics above lowtic - * if we are consistently slower, speed up time - */ - - for (i = 0; i < CONFIG_GAMES_NXDOOM_NET_MAXPLAYERS; i++) - { - if (local_playeringame[i]) - { - keyplayer = i; - break; - } - } - - if (keyplayer < 0) - { - /* If there are no players, we can never advance anyway */ - - return; - } - - if (localplayer == keyplayer) - { - /* the key player does not adapt */ - } - else - { - if (maketic <= recvtic) - { - lasttime--; - } - - frameskip[frameon & 3] = oldnettics > recvtic; - oldnettics = maketic; - - if (frameskip[0] && frameskip[1] && frameskip[2] && frameskip[3]) - { - skiptics = 1; - } - } -} - -/* Returns true if there are players in the game: */ - -static boolean players_in_game(void) -{ - boolean result = false; - unsigned int i; - - /* If we are connected to a server, check if there are any players - * in the game. - */ - - if (net_client_connected) - { - for (i = 0; i < CONFIG_GAMES_NXDOOM_NET_MAXPLAYERS; ++i) - { - result = result || local_playeringame[i]; - } - } - - /* Whether single or multi-player, unless we are running as a drone, - * we are in the game. - */ - - if (!drone) - { - result = true; - } - - return result; -} - -/* When using ticdup, certain values must be cleared out when running - * the duplicate ticcmds. - */ - -static void ticdup_squash(ticcmd_set_t *set) -{ - ticcmd_t *cmd; - unsigned int i; - - for (i = 0; i < CONFIG_GAMES_NXDOOM_NET_MAXPLAYERS; ++i) - { - cmd = &set->cmds[i]; - cmd->chatchar = 0; - if (cmd->buttons & BT_SPECIAL) cmd->buttons = 0; - } -} - -/* When running in single player mode, clear all the ingame[] array - * except the local player. - */ - -static void single_player_clear(ticcmd_set_t *set) -{ - unsigned int i; - - for (i = 0; i < CONFIG_GAMES_NXDOOM_NET_MAXPLAYERS; ++i) - { - if (i != localplayer) - { - set->ingame[i] = false; - } - } -} - -/* Returns true if the given lump number corresponds to data from a .lmp - * file, as opposed to a WAD. - */ - -static boolean is_demo_file(int lumpnum) -{ - char *lower; - boolean result; - - lower = m_string_duplicate(lumpinfo[lumpnum]->wad_file->path); - m_force_lowercase(lower); - result = m_string_ends_with(lower, ".lmp"); - free(lower); - - return result; -} - -/* Block until the game start message is received from the server. */ - -#ifdef CONFIG_GAMES_NXDOOM_NET -static void block_until_start(net_gamesettings_t *settings, - netgame_startup_callback_t callback) -{ - while (!net_cl_get_settings(settings)) - { - net_cl_run(); - net_sv_run(); - - if (!net_client_connected) - { - i_error("Lost connection to server"); - } - - if (callback != NULL && !callback(net_client_wait_data.ready_players, - net_client_wait_data.num_players)) - { - i_error("Netgame startup aborted."); - } - - usleep(100000); - } -} - -/* d_quit_net_game - * - * Called before quitting to leave a net game without hanging the other - * players - * - * Broadcasts special packets to other players to notify of game exit - */ - -static void d_quit_net_game(void) -{ - net_sv_shutdown(); - net_cl_disconnect(); -} -#endif /* CONFIG_GAMES_NXDOOM_NET */ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/* net_update - * Builds ticcmds for console player, sends out a packet - */ - -void net_update(void) -{ - int nowtime; - int newtics; - int i; - - /* If we are running with singletics (timing a demo), this - * is all done separately. - */ - - if (singletics) return; - - /* Run network subsystems */ - -#ifdef CONFIG_GAMES_NXDOOM_NET - net_cl_run(); - net_sv_run(); -#endif - - /* check time */ - - nowtime = get_adjusted_time() / ticdup; - newtics = nowtime - lasttime; - - lasttime = nowtime; - - if (skiptics <= newtics) - { - newtics -= skiptics; - skiptics = 0; - } - else - { - skiptics -= newtics; - newtics = 0; - } - - /* build new ticcmds for console player */ - - for (i = 0; i < newtics; i++) - { - if (!build_new_tic()) - { - break; - } - } -} - -/* Invoked by the network engine when a complete set of ticcmds is - * available. - */ - -void d_receive_tic(ticcmd_t *ticcmds, boolean *players_mask) -{ - int i; - - /* Disconnected from server? */ - - if (ticcmds == NULL && players_mask == NULL) - { - d_disconnected(); - return; - } - - for (i = 0; i < CONFIG_GAMES_NXDOOM_NET_MAXPLAYERS; ++i) - { - if (!drone && i == localplayer) - { - /* This is us. Don't overwrite it. */ - } - else - { - ticdata[recvtic % CONFIG_GAMES_NXDOOM_NET_BACKUPTICS].cmds[i] = - ticcmds[i]; - ticdata[recvtic % CONFIG_GAMES_NXDOOM_NET_BACKUPTICS].ingame[i] = - players_mask[i]; - } - } - - ++recvtic; -} - -/**************************************************************************** - * Name: d_start_game_loop - * - * Description: - * Called after the screen is set but before the game starts running. - * - ****************************************************************************/ - -void d_start_game_loop(void) -{ - lasttime = get_adjusted_time() / ticdup; -} - -void d_start_net_game(net_gamesettings_t *settings, - netgame_startup_callback_t callback) -{ - int i; - - offsetms = 0; - recvtic = 0; - - settings->consoleplayer = 0; - settings->num_players = 1; - settings->player_classes[0] = player_class; - - /* @category net - * - * Use original network client sync code rather than the improved - * sync code. - */ - - settings->new_sync = !m_parm_exists("-oldsync"); - - /* @category net - * @arg - * - * Send n extra tics in every packet as insurance against dropped - * packets. - */ - - i = m_check_parm_with_args("-extratics", 1); - - if (i > 0) - settings->extratics = atoi(myargv[i + 1]); - else - settings->extratics = 1; - - /* @category net - * @arg - * - * Reduce the resolution of the game by a factor of n, reducing - * the amount of network bandwidth needed. - */ - - i = m_check_parm_with_args("-dup", 1); - - if (i > 0) - settings->ticdup = atoi(myargv[i + 1]); - else - settings->ticdup = 1; - -#ifdef CONFIG_GAMES_NXDOOM_NET - if (net_client_connected) - { - /* Send our game settings and block until game start is received - * from the server. - */ - - net_cl_start_game(settings); - block_until_start(settings, callback); - - /* Read the game settings that were received. */ - - net_cl_get_settings(settings); - } - - if (drone) - { - settings->consoleplayer = 0; - } -#endif - - /* Set the local player and playeringame[] values. */ - - localplayer = settings->consoleplayer; - - for (i = 0; i < CONFIG_GAMES_NXDOOM_NET_MAXPLAYERS; ++i) - { - local_playeringame[i] = i < settings->num_players; - } - - /* Copy settings to global variables. */ - - ticdup = settings->ticdup; - new_sync = settings->new_sync; - - if (ticdup < 1) - { - i_error("d_start_net_game: invalid ticdup value (%d)", ticdup); - } - - /* TODO: Message disabled until we fix new_sync. - * - * if (!new_sync) - * { - * printf("Syncing netgames like Vanilla Doom.\n"); - * } - */ -} - -boolean d_init_net_game(net_connect_data_t *connect_data) -{ -#ifdef CONFIG_GAMES_NXDOOM_NET - boolean result = false; - net_addr_t *addr = NULL; - int i; - - /* Call d_quit_net_game on exit: */ - - i_at_exit(d_quit_net_game, true); -#endif - - player_class = connect_data->player_class; - -#ifdef CONFIG_GAMES_NXDOOM_NET - /* @category net - * - * Start a multiplayer server, listening for connections. - */ - - if (m_check_parm("-server") > 0 || m_check_parm("-privateserver") > 0) - { - net_sv_init(); - net_sv_add_module(&net_loop_server_module); - net_sv_add_module(&net_sdl_module); - net_sv_register_with_master(); - - net_loop_client_module.init_client(); - addr = net_loop_client_module.resolve_address(NULL); - net_reference_address(addr); - } - else - { - /* @category net - * - * Automatically search the local LAN for a multiplayer - * server and join it. - */ - - i = m_check_parm("-autojoin"); - - if (i > 0) - { - addr = net_find_lan_server(); - - if (addr == NULL) - { - i_error("No server found on local LAN"); - } - } - - /* @arg
- * @category net - * - * Connect to a multiplayer server running on the given - * address. - */ - - i = m_check_parm_with_args("-connect", 1); - - if (i > 0) - { - net_sdl_module.init_client(); - addr = net_sdl_module.resolve_address(myargv[i + 1]); - net_reference_address(addr); - - if (addr == NULL) - { - i_error("Unable to resolve '%s'\n", myargv[i + 1]); - } - } - } - - if (addr != NULL) - { - if (m_check_parm("-drone") > 0) - { - connect_data->drone = true; - } - - if (!net_cl_connect(addr, connect_data)) - { - i_error("d_init_net_game: Failed to connect to %s:\n%s\n", - net_addr_to_string(addr), net_client_reject_reason); - } - - printf("d_init_net_game: Connected to %s\n", net_addr_to_string(addr)); - net_release_address(addr); - - /* Wait for launch message received from server. */ - - net_wait_for_launch(); - - result = true; - } - - return result; -#endif - return false; -} - -/* try_run_tics */ - -void try_run_tics(void) -{ - int i; - int lowtic; - int entertic; - static int oldentertics; - int realtics; - int availabletics; - int counts; - - /* get real tics */ - - entertic = i_get_time() / ticdup; - realtics = entertic - oldentertics; - oldentertics = entertic; - - /* in singletics mode, run a single tic every time this function - * is called. - */ - - if (singletics) - { - build_new_tic(); - } - else - { - net_update(); - } - - lowtic = get_low_tic(); - - availabletics = lowtic - gametic / ticdup; - - /* decide how many tics to run */ - - if (new_sync) - { - counts = availabletics; - } - else - { - /* decide how many tics to run */ - - if (realtics < availabletics - 1) - counts = realtics + 1; - else if (realtics < availabletics) - counts = realtics; - else - counts = availabletics; - - if (counts < 1) counts = 1; - - if (net_client_connected) - { - old_net_sync(); - } - } - - if (counts < 1) counts = 1; - - /* wait for new tics if needed */ - - while (!players_in_game() || lowtic < gametic / ticdup + counts) - { - net_update(); - - lowtic = get_low_tic(); - - if (lowtic < gametic / ticdup) - i_error("try_run_tics: lowtic < gametic"); - - /* Still no tics to run? Sleep until some are available. */ - - if (lowtic < gametic / ticdup + counts) - { - /* If we're in a netgame, we might spin forever waiting for - * new network data to be received. So don't stay in here - * forever - give the menu a chance to work. - */ - - if (i_get_time() / ticdup - entertic >= MAX_NETGAME_STALL_TICS) - { - return; - } - - usleep(1000); - } - } - - /* run the count * ticdup dics */ - - while (counts--) - { - ticcmd_set_t *set; - - if (!players_in_game()) - { - return; - } - - set = &ticdata[(gametic / ticdup) % - CONFIG_GAMES_NXDOOM_NET_BACKUPTICS]; - - if (!net_client_connected) - { - single_player_clear(set); - } - - for (i = 0; i < ticdup; i++) - { - if (gametic / ticdup > lowtic) i_error("gametic>lowtic"); - - memcpy(local_playeringame, set->ingame, - sizeof(local_playeringame)); - - loop_interface->run_tic(set->cmds, set->ingame); - gametic++; - - /* modify command for duplicated tics */ - - ticdup_squash(set); - } - - net_update(); /* check for new console commands */ - } -} - -void d_register_loop_callbacks(loop_interface_t *i) -{ - loop_interface = i; -} - -/* If the provided conditional value is true, we're trying to record - * a demo file that will include a non-vanilla extension. The function - * will return true if the conditional is true and it's allowed to use - * this extension (no extensions are allowed if -strictdemos is given - * on the command line). A warning is shown on the console using the - * provided string describing the non-vanilla expansion. - */ - -boolean d_non_vanilla_record(boolean conditional, const char *feature) -{ - if (!conditional || strict_demos()) - { - return false; - } - - printf("Warning: Recording a demo file with a non-vanilla extension " - "(%s). Use -strictdemos to disable this extension.\n", - feature); - - return true; -} - -/* If the provided conditional value is true, we're trying to play back - * a demo that includes a non-vanilla extension. We return true if the - * conditional is true and it's allowed to use this extension, checking - * that: - * - The -strictdemos command line argument is not provided. - * - The given lumpnum identifying the demo to play back identifies a - * demo that comes from a .lmp file, not a .wad file. - * - Before proceeding, a warning is shown to the user on the console. - */ - -boolean d_non_vanilla_playback(boolean conditional, int lumpnum, - const char *feature) -{ - if (!conditional || strict_demos()) - { - return false; - } - - if (!is_demo_file(lumpnum)) - { - printf("Warning: WAD contains demo with a non-vanilla extension " - "(%s)\n", - feature); - return false; - } - - printf("Warning: Playing back a demo file with a non-vanilla extension " - "(%s). Use -strictdemos to disable this extension.\n", - feature); - - return true; -} diff --git a/games/NXDoom/src/d_loop.h b/games/NXDoom/src/d_loop.h deleted file mode 100644 index 95c2f7a3c..000000000 --- a/games/NXDoom/src/d_loop.h +++ /dev/null @@ -1,118 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/d_loop.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Main loop stuff. - * - ****************************************************************************/ - -#ifndef __D_LOOP__ -#define __D_LOOP__ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "m_fixed.h" -#include "net_defs.h" - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -/* Callback function invoked while waiting for the netgame to start. - * The callback is invoked when new players are ready. The callback - * should return true, or return false to abort startup. - */ - -typedef boolean (*netgame_startup_callback_t)(int ready_players, - int num_players); - -typedef struct -{ - /* Read events from the event queue, and process them. */ - - void (*process_events)(void); - - /* Given the current input state, fill in the fields of the specified - * ticcmd_t structure with data for a new tic. - */ - - void (*build_ticcmd)(ticcmd_t *cmd, int maketic); - - /* Advance the game forward one tic, using the specified player input. */ - - void (*run_tic)(ticcmd_t *cmds, boolean *ingame); - - /* Run the menu (runs independently of the game). */ - - void (*run_menu)(void); -} loop_interface_t; - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -extern boolean singletics; -extern int gametic; -extern int ticdup; -extern fixed_t offsetms; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/* Register callback functions for the main loop code to use. */ - -void d_register_loop_callbacks(loop_interface_t *i); - -/* Create any new ticcmds and broadcast to other players. */ - -void net_update(void); - -/* ? how many ticks to run? */ - -void try_run_tics(void); - -/* Called at start of game loop to initialize timers */ - -void d_start_game_loop(void); - -/* Initialize networking code and connect to server. */ - -boolean d_init_net_game(net_connect_data_t *connect_data); - -/* Start game with specified settings. The structure will be updated - * with the actual settings for the game. - */ - -void d_start_net_game(net_gamesettings_t *settings, - netgame_startup_callback_t callback); - -/* Check if it is permitted to record a demo with a non-vanilla feature. */ - -boolean d_non_vanilla_record(boolean conditional, const char *feature); - -/* Check if it is permitted to play back a demo with a non-vanilla feature. */ - -boolean d_non_vanilla_playback(boolean conditional, int lumpnum, - const char *feature); - -void d_receive_tic(ticcmd_t *ticcmds, boolean *playeringame); - -#endif /* __D_LOOP__ */ diff --git a/games/NXDoom/src/d_mode.c b/games/NXDoom/src/d_mode.c deleted file mode 100644 index 6c4891cc1..000000000 --- a/games/NXDoom/src/d_mode.c +++ /dev/null @@ -1,247 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/d_mode.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Functions and definitions relating to the game type and operational - * mode. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "d_mode.h" -#include "doomtype.h" - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/* Valid game mode/mission combinations, with the number of - * episodes/maps for each. - */ - -struct modemission -{ - gamemission_t mission; - game_mode_t mode; - int episode; - int map; -}; - -struct gameversion -{ - gamemission_t mission; - game_version_t version; -}; - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static struct modemission g_valid_modes[] = -{ - {.mission = doom, .mode = shareware, .episode = 1, .map = 9}, - {.mission = doom, .mode = registered, .episode = 3, .map = 9}, - {.mission = doom, .mode = retail, .episode = 4, .map = 9}, - {.mission = doom2, .mode = commercial, .episode = 1, .map = 32}, -}; - -/* Table of valid versions */ - -static struct gameversion g_valid_versions[] = -{ - {.mission = doom, .version = exe_doom_1_2}, - {.mission = doom, .version = exe_doom_1_5}, - {.mission = doom, .version = exe_doom_1_666}, - {.mission = doom, .version = exe_doom_1_7}, - {.mission = doom, .version = exe_doom_1_8}, - {.mission = doom, .version = exe_doom_1_9}, - {.mission = doom, .version = exe_hacx}, - {.mission = doom, .version = exe_ultimate}, - {.mission = doom, .version = exe_final}, - {.mission = doom, .version = exe_final2}, - {.mission = doom, .version = exe_chex}, -}; - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/* Check that a gamemode + gamemission received over the network is valid. */ - -boolean d_valid_game_mode(gamemission_t mission, game_mode_t mode) -{ - int i; - - for (i = 0; i < arrlen(g_valid_modes); ++i) - { - if (g_valid_modes[i].mode == mode && - g_valid_modes[i].mission == mission) - { - return true; - } - } - - return false; -} - -boolean d_valid_episode_map(gamemission_t mission, game_mode_t mode, - int episode, int map) -{ - int i; - - /* Hacks for Heretic secret episodes */ - - if (mission == heretic) - { - if (mode == retail && episode == 6) - { - return map >= 1 && map <= 3; - } - else if (mode == registered && episode == 4) - { - return map == 1; - } - } - - /* Find the table entry for this mission/mode combination. */ - - for (i = 0; i < arrlen(g_valid_modes); ++i) - { - if (mission == g_valid_modes[i].mission && - mode == g_valid_modes[i].mode) - { - return episode >= 1 && episode <= g_valid_modes[i].episode && - map >= 1 && map <= g_valid_modes[i].map; - } - } - - /* Unknown mode/mission combination */ - - return false; -} - -/* Get the number of valid episodes for the specified mission/mode. */ - -int d_get_num_episodes(gamemission_t mission, game_mode_t mode) -{ - int episode; - - episode = 1; - - while (d_valid_episode_map(mission, mode, episode, 1)) - { - ++episode; - } - - return episode - 1; -} - -boolean d_valid_game_version(gamemission_t mission, game_version_t version) -{ - int i; - - /* All Doom variants can use the Doom versions. */ - - if (mission == doom2 || mission == pack_plut || mission == pack_tnt || - mission == pack_hacx || mission == pack_chex) - { - mission = doom; - } - - for (i = 0; i < arrlen(g_valid_versions); ++i) - { - if (g_valid_versions[i].mission == mission && - g_valid_versions[i].version == version) - { - return true; - } - } - - return false; -} - -/* Does this mission type use ExMy form, rather than MAPxy form? */ - -boolean d_is_episode_map(gamemission_t mission) -{ - switch (mission) - { - case doom: - case heretic: - case pack_chex: - return true; - - case none: - case hexen: - case doom2: - case pack_hacx: - case pack_tnt: - case pack_plut: - case strife: - default: - return false; - } -} - -const char *d_game_mission_string(gamemission_t mission) -{ - switch (mission) - { - case none: - default: - return "none"; - case doom: - return "doom"; - case doom2: - return "doom2"; - case pack_tnt: - return "tnt"; - case pack_plut: - return "plutonia"; - case pack_hacx: - return "hacx"; - case pack_chex: - return "chex"; - case heretic: - return "heretic"; - case hexen: - return "hexen"; - case strife: - return "strife"; - } -} - -const char *d_game_mode_string(game_mode_t mode) -{ - switch (mode) - { - case shareware: - return "shareware"; - case registered: - return "registered"; - case commercial: - return "commercial"; - case retail: - return "retail"; - case indetermined: - default: - return "unknown"; - } -} diff --git a/games/NXDoom/src/d_mode.h b/games/NXDoom/src/d_mode.h deleted file mode 100644 index 26c282753..000000000 --- a/games/NXDoom/src/d_mode.h +++ /dev/null @@ -1,126 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/d_mode.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Functions and definitions relating to the game type and operational - * mode. - * - ****************************************************************************/ - -#ifndef __D_MODE__ -#define __D_MODE__ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "doomtype.h" - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -/* The "mission" controls what game we are playing. */ - -typedef enum -{ - doom, /* Doom 1 */ - doom2, /* Doom 2 */ - pack_tnt, /* Final Doom: TNT: Evilution */ - pack_plut, /* Final Doom: The Plutonia Experiment */ - pack_chex, /* Chex Quest (modded doom) */ - pack_hacx, /* Hacx (modded doom2) */ - heretic, /* Heretic */ - hexen, /* Hexen */ - strife, /* Strife */ - doom2f, /* Doom 2: L'Enfer sur Terre */ - none -} gamemission_t; - -/* The "mode" allows more accurate specification of the game mode we are - * in: eg. shareware vs. registered. So doom1.wad and doom.wad are the - * same mission, but a different mode. - */ - -typedef enum -{ - shareware, /* Doom/Heretic shareware */ - registered, /* Doom/Heretic registered */ - commercial, /* Doom II/Hexen */ - retail, /* Ultimate Doom */ - indetermined /* Unknown. */ -} game_mode_t; - -/* What version are we emulating? */ - -typedef enum -{ - exe_doom_1_2, /* Doom 1.2: shareware and registered */ - exe_doom_1_5, /* Doom 1.5: " */ - exe_doom_1_666, /* Doom 1.666: for shareware, registered and commercial */ - exe_doom_1_7, /* Doom 1.7/1.7a: " */ - exe_doom_1_8, /* Doom 1.8: " */ - exe_doom_1_9, /* Doom 1.9: " */ - exe_hacx, /* Hacx */ - exe_ultimate, /* Ultimate Doom (retail) */ - exe_final, /* Final Doom */ - exe_final2, /* Final Doom (alternate exe) */ - exe_chex, /* Chex Quest executable (based on Final Doom) */ - exe_heretic_1_3, /* Heretic 1.3 */ - exe_hexen_1_1, /* Hexen 1.1 */ - exe_hexen_1_1r2, /* Hexen 1.1 (alternate exe) */ - exe_strife_1_2, /* Strife v1.2 */ - exe_strife_1_31 /* Strife v1.31 */ -} game_version_t; - -/* What IWAD variant are we using? */ - -typedef enum -{ - vanilla, /* Vanilla Doom */ - freedoom, /* FreeDoom: Phase 1 + 2 */ - freedm, /* FreeDM */ - bfgedition, /* Doom Classic (Doom 3: BFG Edition) */ -} game_variant_t; - -/* Skill level. */ - -typedef enum -{ - sk_noitems = -1, /* the "-skill 0" hack */ - sk_baby = 0, - sk_easy, - sk_medium, - sk_hard, - sk_nightmare -} skill_t; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -boolean d_valid_game_mode(gamemission_t mission, game_mode_t mode); -boolean d_valid_game_version(gamemission_t mission, game_version_t version); -boolean d_valid_episode_map(gamemission_t mission, game_mode_t mode, - int episode, int map); -int d_get_num_episodes(gamemission_t mission, game_mode_t mode); -boolean d_is_episode_map(gamemission_t mission); -const char *d_game_mission_string(gamemission_t mission); -const char *d_game_mode_string(game_mode_t mode); - -#endif /* __D_MODE__ */ diff --git a/games/NXDoom/src/d_ticcmd.h b/games/NXDoom/src/d_ticcmd.h deleted file mode 100644 index c67340727..000000000 --- a/games/NXDoom/src/d_ticcmd.h +++ /dev/null @@ -1,69 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/d_ticcmd.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 1993-2008 Raven Software - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * System specific interface stuff. - * - ****************************************************************************/ - -#ifndef __D_TICCMD__ -#define __D_TICCMD__ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "doomtype.h" - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -/* The data sampled per tick (single player) - * and transmitted to other peers (multiplayer). - * Mainly movements/button commands per game tick, - * plus a checksum for internal state consistency. - */ - -typedef struct -{ - signed char forwardmove; /* *2048 for move */ - signed char sidemove; /* *2048 for move */ - short angleturn; /* <<16 for angle delta */ - byte chatchar; - byte buttons; - - /* villsa [STRIFE] according to the asm, - * consistency is a short, not a byte - */ - - byte consistency; /* checks for net game */ - - /* villsa - Strife specific: */ - - byte buttons2; - int inventory; - - /* Heretic/Hexen specific: */ - - byte lookfly; /* look/fly up/down/centering */ - byte arti; /* artitype_t to use */ -} ticcmd_t; - -#endif /* __D_TICCMD__ */ diff --git a/games/NXDoom/src/deh_defs.h b/games/NXDoom/src/deh_defs.h deleted file mode 100644 index f4f5c1ea4..000000000 --- a/games/NXDoom/src/deh_defs.h +++ /dev/null @@ -1,120 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/deh_defs.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * Definitions for use in the dehacked code - * - ****************************************************************************/ - -#ifndef DEH_DEFS_H -#define DEH_DEFS_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "sha1.h" - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -typedef struct deh_context_s deh_context_t; -typedef struct deh_section_s deh_section_t; -typedef void (*deh_section_init_t)(void); -typedef void *(*deh_section_start_t)(deh_context_t *context, char *line); -typedef void (*deh_section_end_t)(deh_context_t *context, void *tag); -typedef void (*deh_line_parser_t)(deh_context_t *context, char *line, - void *tag); -typedef void (*deh_sha1_hash_t)(SHA1_CTX *context); - -struct deh_section_s -{ - const char *name; - - /* Called on startup to initialize code */ - - deh_section_init_t init; - - /* This is called when a new section is started. The pointer - * returned is used as a tag for the following calls. - */ - - deh_section_start_t start; - - /* This is called for each line in the section */ - - deh_line_parser_t line_parser; - - /* This is called at the end of the section for any cleanup */ - - deh_section_end_t end; - - /* Called when generating an SHA1 sum of the dehacked state */ - - deh_sha1_hash_t sha1_hash; -}; - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -extern deh_section_t *deh_section_types[]; -extern const char *deh_signatures[]; - -/* deh_ammo.c: */ - -extern deh_section_t deh_section_ammo; - -/* deh_cheat.c: */ - -extern deh_section_t deh_section_cheat; - -/* deh_frame.c: */ - -extern deh_section_t deh_section_frame; - -/* deh_misc.c: */ - -extern deh_section_t deh_section_misc; - -/* deh_ptr.c: */ - -extern deh_section_t deh_section_pointer; - -/* deh_sound.c */ - -#ifdef CONFIG_GAMES_NXDOOM_SOUND -extern deh_section_t deh_section_sound; -#endif - -/* deh_text.c: */ - -extern deh_section_t deh_section_text; - -/* deh_thing.c: */ - -extern deh_section_t deh_section_thing; - -/* deh_weapon.c: */ - -extern deh_section_t deh_section_weapon; - -/* deh_bexstr.c: */ - -extern deh_section_t deh_section_bexstr; - -#endif /* DEH_DEFS_H */ diff --git a/games/NXDoom/src/deh_io.c b/games/NXDoom/src/deh_io.c deleted file mode 100644 index fa1102bb5..000000000 --- a/games/NXDoom/src/deh_io.c +++ /dev/null @@ -1,392 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/deh_io.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * - * Dehacked I/O code (does all reads from dehacked files) - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include -#include -#include - -#include "m_misc.h" -#include "w_wad.h" -#include "z_zone.h" - -#include "deh_defs.h" -#include "deh_io.h" - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -typedef enum -{ - DEH_INPUT_FILE, - DEH_INPUT_LUMP -} deh_input_type_t; - -struct deh_context_s -{ - deh_input_type_t type; - char *filename; - - /* If the input comes from a memory buffer, pointer to the memory - * buffer. - */ - - unsigned char *input_buffer; - size_t input_buffer_len; - unsigned int input_buffer_pos; - int lumpnum; - - /* If the input comes from a file, the file stream for reading - * data. - */ - - FILE *stream; - - /* Current line number that we have reached: */ - - int linenum; - - /* Used by deh_read_line: */ - - boolean last_was_newline; - char *readbuffer; - int readbuffer_size; - - /* Error handling. */ - - boolean had_error; -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static deh_context_t *deh_new_context(void) -{ - deh_context_t *context; - - context = z_malloc(sizeof(*context), PU_STATIC, NULL); - - /* Initial read buffer size of 128 bytes */ - - context->readbuffer_size = 128; - context->readbuffer = z_malloc(context->readbuffer_size, PU_STATIC, NULL); - context->linenum = 0; - context->last_was_newline = true; - - context->had_error = false; - - return context; -} - -/* Increase the read buffer size */ - -static void increase_read_buffer(deh_context_t *context) -{ - char *newbuffer; - int newbuffer_size; - - newbuffer_size = context->readbuffer_size * 2; - newbuffer = z_malloc(newbuffer_size, PU_STATIC, NULL); - - memcpy(newbuffer, context->readbuffer, context->readbuffer_size); - - z_free(context->readbuffer); - - context->readbuffer = newbuffer; - context->readbuffer_size = newbuffer_size; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/* Open a dehacked file for reading - * Returns NULL if open failed - */ - -deh_context_t *deh_open_file(const char *filename) -{ - FILE *fstream; - deh_context_t *context; - - fstream = fopen(filename, "r"); - - if (fstream == NULL) return NULL; - - context = deh_new_context(); - - context->type = DEH_INPUT_FILE; - context->stream = fstream; - context->filename = m_string_duplicate(filename); - - return context; -} - -/* Open a WAD lump for reading. */ - -deh_context_t *deh_open_lump(int lumpnum) -{ - deh_context_t *context; - void *lump; - - lump = w_cache_lump_num(lumpnum, PU_STATIC); - - context = deh_new_context(); - - context->type = DEH_INPUT_LUMP; - context->lumpnum = lumpnum; - context->input_buffer = lump; - context->input_buffer_len = w_lump_length(lumpnum); - context->input_buffer_pos = 0; - - context->filename = malloc(9); - m_str_copy(context->filename, lumpinfo[lumpnum]->name, 9); - - return context; -} - -/* Close dehacked file */ - -void deh_close_file(deh_context_t *context) -{ - if (context->type == DEH_INPUT_FILE) - { - fclose(context->stream); - } - else if (context->type == DEH_INPUT_LUMP) - { - w_release_lump_num(context->lumpnum); - } - - free(context->filename); - z_free(context->readbuffer); - z_free(context); -} - -int deh_get_char_file(deh_context_t *context) -{ - if (feof(context->stream)) - { - /* end of file */ - - return -1; - } - - return fgetc(context->stream); -} - -int deh_get_char_lump(deh_context_t *context) -{ - int result; - - if (context->input_buffer_pos >= context->input_buffer_len) - { - return -1; - } - - result = context->input_buffer[context->input_buffer_pos]; - ++context->input_buffer_pos; - - return result; -} - -/* Reads a single character from a dehacked file */ - -int deh_get_char(deh_context_t *context) -{ - int result = 0; - boolean last_was_cr = false; - - /* Track the current line number */ - - if (context->last_was_newline) - { - ++context->linenum; - } - - /* Read characters, converting CRLF to LF */ - - do - { - switch (context->type) - { - case DEH_INPUT_FILE: - result = deh_get_char_file(context); - break; - - case DEH_INPUT_LUMP: - result = deh_get_char_lump(context); - break; - } - - /* Handle \r characters not paired with \n */ - - if (last_was_cr && result != '\n') - { - switch (context->type) - { - case DEH_INPUT_FILE: - ungetc(result, context->stream); - break; - - case DEH_INPUT_LUMP: - --context->input_buffer_pos; - break; - } - - return '\r'; - } - - last_was_cr = result == '\r'; - } - while (last_was_cr); - - context->last_was_newline = result == '\n'; - - return result; -} - -/* Read a whole line */ - -char *deh_read_line(deh_context_t *context, boolean extended) -{ - int c; - int pos; - boolean escaped = false; - - for (pos = 0; ; ) - { - c = deh_get_char(context); - - if (c < 0 && pos == 0) - { - /* end of file */ - - return NULL; - } - - /* cope with lines of any length: increase the buffer size */ - - if (pos >= context->readbuffer_size) - { - increase_read_buffer(context); - } - - /* extended string support */ - - if (extended && c == '\\') - { - c = deh_get_char(context); - - /* "\n" in the middle of a string indicates an internal linefeed */ - - if (c == 'n') - { - context->readbuffer[pos] = '\n'; - ++pos; - continue; - } - - /* values to be assigned may be split onto multiple lines by ending - * each line that is to be continued with a backslash - */ - - if (c == '\n') - { - escaped = true; - continue; - } - } - - /* blanks before the backslash are included in the string - * but indentation after the linefeed is not - */ - - if (escaped && c >= 0 && isspace(c) && c != '\n') - { - continue; - } - else - { - escaped = false; - } - - if (c == '\n' || c < 0) - { - /* end of line: a full line has been read */ - - context->readbuffer[pos] = '\0'; - break; - } - else if (c != '\0') - { - /* normal character; don't allow NUL characters to be - * added. - */ - - context->readbuffer[pos] = (char)c; - ++pos; - } - } - - return context->readbuffer; -} - -void deh_warning(deh_context_t *context, const char *msg, ...) -{ - va_list args; - - va_start(args, msg); - - fprintf(stderr, "%s:%i: warning: ", context->filename, context->linenum); - vfprintf(stderr, msg, args); - fprintf(stderr, "\n"); - - va_end(args); -} - -void deh_error(deh_context_t *context, const char *msg, ...) -{ - va_list args; - - va_start(args, msg); - - fprintf(stderr, "%s:%i: ", context->filename, context->linenum); - vfprintf(stderr, msg, args); - fprintf(stderr, "\n"); - - va_end(args); - - context->had_error = true; -} - -boolean deh_had_error(deh_context_t *context) -{ - return context->had_error; -} diff --git a/games/NXDoom/src/deh_io.h b/games/NXDoom/src/deh_io.h deleted file mode 100644 index 8ee12b5c0..000000000 --- a/games/NXDoom/src/deh_io.h +++ /dev/null @@ -1,46 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/deh_io.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * Dehacked I/O code (does all reads from dehacked files) - * - ****************************************************************************/ - -#ifndef DEH_IO_H -#define DEH_IO_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "deh_defs.h" - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -deh_context_t *deh_open_file(const char *filename); -deh_context_t *deh_open_lump(int lumpnum); -void deh_close_file(deh_context_t *context); -int deh_get_char(deh_context_t *context); -char *deh_read_line(deh_context_t *context, boolean extended); -void deh_error(deh_context_t *context, const char *msg, ...) - PRINTF_ATTR(2, 3); -void deh_warning(deh_context_t *context, const char *msg, ...) - PRINTF_ATTR(2, 3); -boolean deh_had_error(deh_context_t *context); - -#endif /* DEH_IO_H */ diff --git a/games/NXDoom/src/deh_main.c b/games/NXDoom/src/deh_main.c deleted file mode 100644 index f6eb667ac..000000000 --- a/games/NXDoom/src/deh_main.c +++ /dev/null @@ -1,554 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/deh_main.c - * - * SPDX-License-Identifier: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * Main dehacked code - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include -#include - -#include "d_iwad.h" -#include "doomtype.h" -#include "i_glob.h" -#include "i_system.h" -#include "m_argv.h" -#include "w_wad.h" - -#include "deh_defs.h" -#include "deh_io.h" -#include "deh_main.h" - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static boolean deh_initialized = false; - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/* If true, we can parse [STRINGS] sections in BEX format. */ - -boolean deh_allow_extended_strings = false; - -/* If true, we can do long string replacements. */ - -boolean deh_allow_long_strings = false; - -/* If true, we can do cheat replacements longer than the originals. */ - -boolean deh_allow_long_cheats = false; - -/* If false, dehacked cheat replacements are ignored. */ - -boolean deh_apply_cheats = true; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/* Called on startup to call the Init functions */ - -static void initialize_sections(void) -{ - unsigned int i; - - for (i = 0; deh_section_types[i] != NULL; ++i) - { - if (deh_section_types[i]->init != NULL) - { - deh_section_types[i]->init(); - } - } -} - -static void deh_init(void) -{ - /* @category mod - * - * Ignore cheats in dehacked files. - */ - - if (m_check_parm("-nocheats") > 0) - { - deh_apply_cheats = false; - } - - /* Call init functions for all the section definitions. */ - - initialize_sections(); - - deh_initialized = true; -} - -/* Given a section name, get the section structure which corresponds */ - -static deh_section_t *get_section_by_name(char *name) -{ - unsigned int i; - - /* we explicitly do not recognize [STRINGS] sections at all - * if extended strings are not allowed - */ - - if (!deh_allow_extended_strings && !strncasecmp("[STRINGS]", name, 9)) - { - return NULL; - } - - for (i = 0; deh_section_types[i] != NULL; ++i) - { - if (!strcasecmp(deh_section_types[i]->name, name)) - { - return deh_section_types[i]; - } - } - - return NULL; -} - -/* Is the string passed just whitespace? */ - -static boolean is_whitespace(char *s) -{ - for (; *s; ++s) - { - if (!isspace(*s)) return false; - } - - return true; -} - -/* Strip whitespace from the start and end of a string */ - -static char *clean_string(char *s) -{ - char *strending; - - /* Leading whitespace */ - - while (*s && isspace(*s)) - ++s; - - /* Trailing whitespace */ - - strending = s + strlen(s) - 1; - - while (strlen(s) > 0 && isspace(*strending)) - { - *strending = '\0'; - --strending; - } - - return s; -} - -static boolean check_signatures(deh_context_t *context) -{ - size_t i; - char *line; - - /* Read the first line */ - - line = deh_read_line(context, false); - - if (line == NULL) - { - return false; - } - - /* Check all signatures to see if one matches */ - - for (i = 0; deh_signatures[i] != NULL; ++i) - { - if (!strcmp(deh_signatures[i], line)) - { - return true; - } - } - - return false; -} - -/* Parses a comment string in a dehacked file. */ - -static void deh_parse_comment(char *comment) -{ - /* Welcome, to the super-secret Chocolate Doom-specific Dehacked - * overrides function. - * - * Putting these magic comments into your Dehacked lumps will - * allow you to go beyond the normal limits of Vanilla Dehacked. - * Because of this, these comments are deliberately undocumented, - * and if you're using them you should be aware that your mod - * is not compatible with Vanilla Doom and you're probably a - * very naughty person. - * - - * Allow comments containing this special value to allow string - * replacements longer than those permitted by DOS dehacked. - * This allows us to use a dehacked patch for doing string - * replacements for emulating Chex Quest. - * - * If you use this, your dehacked patch may not work in Vanilla - * Doom. - */ - - if (strstr(comment, "*allow-long-strings*") != NULL) - { - deh_allow_long_strings = true; - } - - /* Allow magic comments to allow longer cheat replacements than - * those permitted by DOS dehacked. This is also for Chex - * Quest. - */ - - if (strstr(comment, "*allow-long-cheats*") != NULL) - { - deh_allow_long_cheats = true; - } - - /* Allow magic comments to allow parsing [STRINGS] section - * that are usually only found in BEX format files. This allows - * for substitution of map and episode names when loading - * Freedoom/FreeDM IWADs. - */ - - if (strstr(comment, "*allow-extended-strings*") != NULL) - { - deh_allow_extended_strings = true; - } -} - -/* Parses a dehacked file by reading from the context */ - -static void deh_parse_context(deh_context_t *context) -{ - deh_section_t *current_section = NULL; - char section_name[20]; - void *tag = NULL; - boolean extended; - char *line; - - /* Read the header and check it matches the signature */ - - if (!check_signatures(context)) - { - deh_error(context, "This is not a valid dehacked patch file!"); - } - - /* Read the file */ - - while (!deh_had_error(context)) - { - /* Read the next line. We only allow the special extended parsing - * for the BEX [STRINGS] section. - */ - - extended = current_section != NULL && - !strcasecmp(current_section->name, "[STRINGS]"); - line = deh_read_line(context, extended); - - /* end of file? */ - - if (line == NULL) - { - return; - } - - while (line[0] != '\0' && isspace(line[0])) - ++line; - - if (line[0] == '#') - { - /* comment */ - - deh_parse_comment(line); - continue; - } - - if (is_whitespace(line)) - { - if (current_section != NULL) - { - /* end of section */ - - if (current_section->end != NULL) - { - current_section->end(context, tag); - } - - current_section = NULL; - } - } - else - { - if (current_section != NULL) - { - /* parse this line */ - - current_section->line_parser(context, line, tag); - } - else - { - /* possibly the start of a new section */ - - sscanf(line, "%19s", section_name); - - current_section = get_section_by_name(section_name); - - if (current_section != NULL) - { - tag = current_section->start(context, line); - } - else - { - /* printf("unknown section name %s\n", section_name); */ - } - } - } - } -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -void deh_checksum(sha1_digest_t digest) -{ - SHA1_CTX sha1_context; - unsigned int i; - - sha1init(&sha1_context); - - for (i = 0; deh_section_types[i] != NULL; ++i) - { - if (deh_section_types[i]->sha1_hash != NULL) - { - deh_section_types[i]->sha1_hash(&sha1_context); - } - } - - sha1final(digest, &sha1_context); -} - -/* This pattern is used a lot of times in different sections, - * an assignment is essentially just a statement of the form: - * - * Variable Name = Value - * - * The variable name can include spaces or any other characters. - * The string is split on the '=', essentially. - * - * Returns true if read correctly - */ - -boolean deh_parse_assignment(char *line, char **variable_name, char **value) -{ - char *p; - - /* find the equals */ - - p = strchr(line, '='); - - if (p == NULL) - { - return false; - } - - /* variable name at the start - * turn the '=' into a \0 to terminate the string here - */ - - *p = '\0'; - *variable_name = clean_string(line); - - /* value immediately follows the '=' */ - - *value = clean_string(p + 1); - - return true; -} - -/* Parses a dehacked file */ - -int deh_loadfile(const char *filename) -{ - deh_context_t *context; - boolean had_error; - - if (!deh_initialized) - { - deh_init(); - } - - /* Before parsing a new file, reset special override flags to false. - * Magic comments should only apply to the file in which they were - * defined, and shouldn't carry over to subsequent files as well. - */ - - deh_allow_long_strings = false; - deh_allow_long_cheats = false; - deh_allow_extended_strings = false; - - printf(" loading %s\n", filename); - - context = deh_open_file(filename); - - if (context == NULL) - { - fprintf(stderr, "deh_loadfile: Unable to open %s\n", filename); - return 0; - } - - deh_parse_context(context); - - had_error = deh_had_error(context); - - deh_close_file(context); - - if (had_error) - { - i_error("Error parsing dehacked file"); - } - - return 1; -} - -/* Load all dehacked patches from the given directory. */ - -void deh_auto_load_patches(const char *path) -{ - const char *filename; - glob_t *glob; - - glob = i_start_multi_glob(path, GLOB_FLAG_NOCASE | GLOB_FLAG_SORTED, - "*.deh", "*.hhe", "*.seh", NULL); - for (; ; ) - { - filename = i_next_glob(glob); - if (filename == NULL) - { - break; - } - - printf(" [autoload]"); - deh_loadfile(filename); - } - - i_end_glob(glob); -} - -/* Load dehacked file from WAD lump. - * If allow_long is set, allow long strings and cheats just for this lump. - */ - -int deh_load_lump(int lumpnum, boolean allow_long, boolean allow_error) -{ - deh_context_t *context; - boolean had_error; - - if (!deh_initialized) - { - deh_init(); - } - - /* Reset all special flags to defaults. */ - - deh_allow_long_strings = allow_long; - deh_allow_long_cheats = allow_long; - deh_allow_extended_strings = false; - - context = deh_open_lump(lumpnum); - - if (context == NULL) - { - fprintf(stderr, "deh_loadfile: Unable to open lump %i\n", lumpnum); - return 0; - } - - deh_parse_context(context); - - had_error = deh_had_error(context); - - deh_close_file(context); - - /* If there was an error while parsing, abort with an error, but allow - * errors to just be ignored if allow_error=true. - */ - - if (!allow_error && had_error) - { - i_error("Error parsing dehacked lump"); - } - - return 1; -} - -int deh_load_lump_by_name(const char *name, boolean allow_long, - boolean allow_error) -{ - int lumpnum; - - lumpnum = w_check_num_for_name(name); - - if (lumpnum == -1) - { - fprintf(stderr, "deh_load_lump_by_name: '%s' lump not found\n", name); - return 0; - } - - return deh_load_lump(lumpnum, allow_long, allow_error); -} - -/* Check the command line for -deh argument, and others. */ - -void deh_parse_command_line(void) -{ - char *filename; - int p; - - /* @arg - * @category mod - * - * Load the given dehacked patch(es) - */ - - p = m_check_parm("-deh"); - - if (p > 0) - { - ++p; - - while (p < myargc && myargv[p][0] != '-') - { - filename = d_try_find_wad_by_name(myargv[p]); - deh_loadfile(filename); - free(filename); - ++p; - } - } -} diff --git a/games/NXDoom/src/deh_main.h b/games/NXDoom/src/deh_main.h deleted file mode 100644 index 8ae728243..000000000 --- a/games/NXDoom/src/deh_main.h +++ /dev/null @@ -1,69 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/deh_main.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * Dehacked entrypoint and common code - * - ****************************************************************************/ - -#ifndef DEH_MAIN_H -#define DEH_MAIN_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "deh_str.h" -#include "doomtype.h" -#include "sha1.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* These are the limits that dehacked uses (from dheinit.h in the dehacked - * source). If these limits are exceeded, it does not generate an error, but - * a warning is displayed. - */ - -#define DEH_VANILLA_NUMSTATES 966 -#define DEH_VANILLA_NUMSFX 107 - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -extern boolean deh_allow_extended_strings; -extern boolean deh_allow_long_strings; -extern boolean deh_allow_long_cheats; -extern boolean deh_apply_cheats; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -void deh_parse_command_line(void); -int deh_loadfile(const char *filename); -void deh_auto_load_patches(const char *path); -int deh_load_lump(int lumpnum, boolean allow_long, boolean allow_error); -int deh_load_lump_by_name(const char *name, boolean allow_long, - boolean allow_error); - -boolean deh_parse_assignment(char *line, char **variable_name, char **value); - -void deh_checksum(sha1_digest_t digest); - -#endif /* DEH_MAIN_H */ diff --git a/games/NXDoom/src/deh_mapping.c b/games/NXDoom/src/deh_mapping.c deleted file mode 100644 index 17bed2074..000000000 --- a/games/NXDoom/src/deh_mapping.c +++ /dev/null @@ -1,206 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/deh_mapping.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * Dehacked "mapping" code - * Allows the fields in structures to be mapped out and accessed by - * name - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include - -#include "doomtype.h" -#include "i_system.h" -#include "m_misc.h" - -#include "deh_mapping.h" - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static deh_mapping_entry_t *get_mapping_entry_by_name(deh_context_t *context, - deh_mapping_t *mapping, - char *name) -{ - int i; - - for (i = 0; mapping->entries[i].name != NULL; ++i) - { - deh_mapping_entry_t *entry = &mapping->entries[i]; - - if (!strcasecmp(entry->name, name)) - { - if (entry->location == NULL) - { - deh_warning(context, "Field '%s' is unsupported", name); - return NULL; - } - - return entry; - } - } - - /* Not found. */ - - deh_warning(context, "Field named '%s' not found", name); - - return NULL; -} - -/* Get the location of the specified field in the specified structure. */ - -static void *get_struct_field(void *structptr, deh_mapping_t *mapping, - deh_mapping_entry_t *entry) -{ - unsigned int offset; - - offset = (uint8_t *)entry->location - (uint8_t *)mapping->base; - - return (uint8_t *)structptr + offset; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/* Set the value of a particular field in a structure by name */ - -boolean deh_set_mapping(deh_context_t *context, deh_mapping_t *mapping, - void *structptr, char *name, int value) -{ - deh_mapping_entry_t *entry; - void *location; - - entry = get_mapping_entry_by_name(context, mapping, name); - - if (entry == NULL) - { - return false; - } - - /* Sanity check: */ - - if (entry->is_string) - { - deh_error(context, "Tried to set '%s' as integer (BUG)", name); - return false; - } - - location = get_struct_field(structptr, mapping, entry); - - /* Set field content based on its type: */ - - switch (entry->size) - { - case 1: - *((uint8_t *)location) = value; - break; - case 2: - *((uint16_t *)location) = value; - break; - case 4: - *((uint32_t *)location) = value; - break; - default: - deh_error(context, "Unknown field type for '%s' (BUG)", name); - return false; - } - - return true; -} - -/* Set the value of a string field in a structure by name */ - -boolean deh_set_string_mapping(deh_context_t *context, - deh_mapping_t *mapping, void *structptr, char *name, char *value) -{ - deh_mapping_entry_t *entry; - void *location; - - entry = get_mapping_entry_by_name(context, mapping, name); - - if (entry == NULL) - { - return false; - } - - /* Sanity check: */ - - if (!entry->is_string) - { - deh_error(context, "Tried to set '%s' as string (BUG)", name); - return false; - } - - location = get_struct_field(structptr, mapping, entry); - - /* Copy value into field: */ - - m_str_copy(location, value, entry->size); - - return true; -} - -void deh_struct_sha1_sum(SHA1_CTX *context, deh_mapping_t *mapping, - void *structptr) -{ - int i; - - /* Go through each mapping */ - - for (i = 0; mapping->entries[i].name != NULL; ++i) - { - deh_mapping_entry_t *entry = &mapping->entries[i]; - void *location; - - if (entry->location == NULL) - { - /* Unsupported field */ - - continue; - } - - /* Add in data for this field */ - - location = (uint8_t *)structptr + - ((uint8_t *)entry->location - (uint8_t *)mapping->base); - - switch (entry->size) - { - case 1: - sha1_updateint32(context, *((uint8_t *)location)); - break; - case 2: - sha1_updateint32(context, *((uint16_t *)location)); - break; - case 4: - sha1_updateint32(context, *((uint32_t *)location)); - break; - default: - i_error("Unknown dehacked mapping field type for '%s' (BUG)", - entry->name); - break; - } - } -} diff --git a/games/NXDoom/src/deh_mapping.h b/games/NXDoom/src/deh_mapping.h deleted file mode 100644 index cd5cf5bf6..000000000 --- a/games/NXDoom/src/deh_mapping.h +++ /dev/null @@ -1,106 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/deh_mapping.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * Dehacked "mapping" code - * Allows the fields in structures to be mapped out and accessed by - * name - * - ****************************************************************************/ - -#ifndef DEH_MAPPING_H -#define DEH_MAPPING_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "deh_io.h" -#include "doomtype.h" -#include "sha1.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define DEH_BEGIN_MAPPING(mapping_name, structname) \ - static structname deh_mapping_base; \ - static deh_mapping_t mapping_name = {&deh_mapping_base, { - -#define DEH_MAPPING(deh_name, fieldname) \ - {deh_name, &deh_mapping_base.fieldname, \ - sizeof(deh_mapping_base.fieldname), false}, - -#define DEH_MAPPING_STRING(deh_name, fieldname) \ - {deh_name, &deh_mapping_base.fieldname, \ - sizeof(deh_mapping_base.fieldname), true}, - -#define DEH_UNSUPPORTED_MAPPING(deh_name) {deh_name, NULL, -1, false}, - -#define DEH_END_MAPPING \ - {NULL, NULL, -1} \ - } \ - } \ - ; - -#define MAX_MAPPING_ENTRIES 32 - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -typedef struct deh_mapping_s deh_mapping_t; -typedef struct deh_mapping_entry_s deh_mapping_entry_t; - -struct deh_mapping_entry_s -{ - /* field name */ - - const char *name; - - /* location relative to the base in the deh_mapping_t struct - * If this is NULL, it is an unsupported mapping - */ - - void *location; - - /* field size */ - - int size; - - /* if true, this is a string value. */ - - boolean is_string; -}; - -struct deh_mapping_s -{ - void *base; - deh_mapping_entry_t entries[MAX_MAPPING_ENTRIES]; -}; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -boolean deh_set_mapping(deh_context_t *context, deh_mapping_t *mapping, - void *structptr, char *name, int value); -boolean deh_set_string_mapping(deh_context_t *context, - deh_mapping_t *mapping, void *structptr, char *name, char *value); -void deh_struct_sha1_sum(SHA1_CTX *context, deh_mapping_t *mapping, - void *structptr); - -#endif /* DEH_MAPPING_H */ diff --git a/games/NXDoom/src/deh_str.c b/games/NXDoom/src/deh_str.c deleted file mode 100644 index 9c3f8b8b4..000000000 --- a/games/NXDoom/src/deh_str.c +++ /dev/null @@ -1,228 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/deh_str.c - * - * SPDX-License-Identifier: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * - * Parses Text substitution sections in dehacked files - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include -#include - -#include "deh_str.h" -#include "doomtype.h" -#include "m_misc.h" - -#include "z_zone.h" - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -typedef struct -{ - char *from_text; - char *to_text; -} deh_substitution_t; - -typedef enum -{ - FORMAT_ARG_INVALID, - FORMAT_ARG_INT, - FORMAT_ARG_FLOAT, - FORMAT_ARG_CHAR, - FORMAT_ARG_STRING, - FORMAT_ARG_PTR, - FORMAT_ARG_SAVE_POS -} format_arg_t; - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static deh_substitution_t **hash_table = NULL; -static int hash_table_entries; -static int hash_table_length = -1; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/* This is the algorithm used by glib */ - -static unsigned int strhash(const char *s) -{ - const char *p = s; - unsigned int h = *p; - - if (h) - { - for (p += 1; *p; p++) - h = (h << 5) - h + *p; - } - - return h; -} - -static deh_substitution_t *substitution_for_string(const char *s) -{ - int entry; - - /* Fallback if we have not initialized the hash table yet */ - - if (hash_table_length < 0) return NULL; - - entry = strhash(s) % hash_table_length; - - while (hash_table[entry] != NULL) - { - if (!strcmp(hash_table[entry]->from_text, s)) - { - return hash_table[entry]; /* substitution found! */ - } - - entry = (entry + 1) % hash_table_length; - } - - /* no substitution found */ - - return NULL; -} - -static void init_hash_table(void) -{ - /* init hash table */ - - hash_table_entries = 0; - hash_table_length = 16; - hash_table = z_malloc(sizeof(deh_substitution_t *) * hash_table_length, - PU_STATIC, NULL); - memset(hash_table, 0, sizeof(deh_substitution_t *) * hash_table_length); -} - -static void deh_add_to_hashtable(deh_substitution_t *sub); - -static void increase_hashtable(void) -{ - deh_substitution_t **old_table; - int old_table_length; - int i; - - /* save the old table */ - - old_table = hash_table; - old_table_length = hash_table_length; - - /* double the size */ - - hash_table_length *= 2; - hash_table = z_malloc(sizeof(deh_substitution_t *) * hash_table_length, - PU_STATIC, NULL); - memset(hash_table, 0, sizeof(deh_substitution_t *) * hash_table_length); - - /* go through the old table and insert all the old entries */ - - for (i = 0; i < old_table_length; ++i) - { - if (old_table[i] != NULL) - { - deh_add_to_hashtable(old_table[i]); - } - } - - /* free the old table */ - - z_free(old_table); -} - -static void deh_add_to_hashtable(deh_substitution_t *sub) -{ - int entry; - - /* if the hash table is more than 60% full, increase its size */ - - if ((hash_table_entries * 10) / hash_table_length > 6) - { - increase_hashtable(); - } - - /* find where to insert it */ - - entry = strhash(sub->from_text) % hash_table_length; - - while (hash_table[entry] != NULL) - { - entry = (entry + 1) % hash_table_length; - } - - hash_table[entry] = sub; - ++hash_table_entries; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -void deh_add_string_replacement(const char *from_text, const char *to_text) -{ - deh_substitution_t *sub; - size_t len; - - /* Initialize the hash table if this is the first time */ - - if (hash_table_length < 0) - { - init_hash_table(); - } - - /* Check to see if there is an existing substitution already in place. */ - - sub = substitution_for_string(from_text); - - if (sub != NULL) - { - z_free(sub->to_text); - - len = strlen(to_text) + 1; - sub->to_text = z_malloc(len, PU_STATIC, NULL); - memcpy(sub->to_text, to_text, len); - } - else - { - /* We need to allocate a new substitution. */ - - sub = z_malloc(sizeof(*sub), PU_STATIC, 0); - - /* We need to create our own duplicates of the provided strings. */ - - len = strlen(from_text) + 1; - sub->from_text = z_malloc(len, PU_STATIC, NULL); - memcpy(sub->from_text, from_text, len); - - len = strlen(to_text) + 1; - sub->to_text = z_malloc(len, PU_STATIC, NULL); - memcpy(sub->to_text, to_text, len); - - deh_add_to_hashtable(sub); - } -} diff --git a/games/NXDoom/src/deh_str.h b/games/NXDoom/src/deh_str.h deleted file mode 100644 index 3b2e6fefe..000000000 --- a/games/NXDoom/src/deh_str.h +++ /dev/null @@ -1,33 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/deh_str.h - * - * SPDX-License-Identifier: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * Dehacked string replacements - * - ****************************************************************************/ - -#ifndef DEH_STR_H -#define DEH_STR_H - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/* Used to do dehacked text substitutions throughout the program */ - -void deh_add_string_replacement(const char *from_text, const char *to_text); - -#endif /* DEH_STR_H */ diff --git a/games/NXDoom/src/deh_text.c b/games/NXDoom/src/deh_text.c deleted file mode 100644 index 927a3e7c6..000000000 --- a/games/NXDoom/src/deh_text.c +++ /dev/null @@ -1,140 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/deh_text.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * Parses Text substitution sections in dehacked files - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include - -#include "doomtype.h" - -#include "z_zone.h" - -#include "deh_defs.h" -#include "deh_io.h" -#include "deh_main.h" - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -static void deh_text_parse_line(deh_context_t *context, char *line, - void *tag); -static void *deh_text_start(deh_context_t *context, char *line); -static void *deh_text_start(deh_context_t *context, char *line); - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -deh_section_t deh_section_text = -{ - "Text", NULL, deh_text_start, deh_text_parse_line, NULL, NULL, -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/* Given a string length, find the maximum length of a string that can - * replace it. - */ - -static int txt_max_string_length(int len) -{ - /* Enough bytes for the string and the NUL terminator */ - - len += 1; - - /* All strings in doom.exe are on 4-byte boundaries, so we may be able - * to support a slightly longer string. - * Extend up to the next 4-byte boundary - */ - - len += (4 - (len % 4)) % 4; - - /* Less one for the NUL terminator. */ - - return len - 1; -} - -static void *deh_text_start(deh_context_t *context, char *line) -{ - char *from_text; - char *to_text; - int fromlen; - int to_len; - int i; - - if (sscanf(line, "Text %i %i", &fromlen, &to_len) != 2) - { - deh_warning(context, "Parse error on section start"); - return NULL; - } - - /* Only allow string replacements that are possible in Vanilla Doom. - * Chocolate Doom is unforgiving! - */ - - if (!deh_allow_long_strings && to_len > txt_max_string_length(fromlen)) - { - deh_error(context, "Replacement string is longer than the maximum " - "possible in doom.exe"); - return NULL; - } - - from_text = malloc(fromlen + 1); - to_text = malloc(to_len + 1); - - /* read in the "from" text */ - - for (i = 0; i < fromlen; ++i) - { - from_text[i] = deh_get_char(context); - } - - from_text[fromlen] = '\0'; - - /* read in the "to" text */ - - for (i = 0; i < to_len; ++i) - { - to_text[i] = deh_get_char(context); - } - - to_text[to_len] = '\0'; - - deh_add_string_replacement(from_text, to_text); - - free(from_text); - free(to_text); - - return NULL; -} - -static void deh_text_parse_line(deh_context_t *context, char *line, - void *tag) -{ - /* not used */ -} diff --git a/games/NXDoom/src/doom/.gitignore b/games/NXDoom/src/doom/.gitignore deleted file mode 100644 index d4e88e5a2..000000000 --- a/games/NXDoom/src/doom/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -Makefile -Makefile.in -.deps -tags -TAGS diff --git a/games/NXDoom/src/doom/am_map.c b/games/NXDoom/src/doom/am_map.c deleted file mode 100644 index 31daeb30b..000000000 --- a/games/NXDoom/src/doom/am_map.c +++ /dev/null @@ -1,1817 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/am_map.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: the automap code - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include "deh_main.h" - -#include "doomdef.h" -#include "doomkeys.h" -#include "p_local.h" -#include "st_stuff.h" -#include "w_wad.h" -#include "z_zone.h" - -#include "i_system.h" -#include "i_timer.h" -#include "i_video.h" -#include "m_cheat.h" -#include "m_controls.h" -#include "m_misc.h" - -/* Needs access to LFB. */ - -#include "v_video.h" - -#include "doomstat.h" -#include "r_state.h" - -#include "dstrings.h" - -#include "am_map.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* For use if I do walls with outsides/insides */ - -#define REDS (256 - 5 * 16) -#define REDRANGE 16 -#define BLUES (256 - 4 * 16 + 8) -#define BLUERANGE 8 -#define GREENS (7 * 16) -#define GREENRANGE 16 -#define GRAYS (6 * 16) -#define GRAYSRANGE 16 -#define BROWNS (4 * 16) -#define BROWNRANGE 16 -#define YELLOWS (256 - 32 + 7) -#define YELLOWRANGE 1 -#define BLACK 0 -#define WHITE (256 - 47) - -/* Automap colors */ - -#define BACKGROUND BLACK -#define YOURCOLORS WHITE -#define YOURRANGE 0 -#define WALLCOLORS REDS -#define WALLRANGE REDRANGE -#define TSWALLCOLORS GRAYS -#define TSWALLRANGE GRAYSRANGE -#define FDWALLCOLORS BROWNS -#define FDWALLRANGE BROWNRANGE -#define CDWALLCOLORS YELLOWS -#define CDWALLRANGE YELLOWRANGE -#define THINGCOLORS GREENS -#define THINGRANGE GREENRANGE -#define SECRETWALLCOLORS WALLCOLORS -#define SECRETWALLRANGE WALLRANGE -#define GRIDCOLORS (GRAYS + GRAYSRANGE / 2) -#define GRIDRANGE 0 -#define XHAIRCOLORS GRAYS - -/* drawing stuff */ - -#define AM_NUMMARKPOINTS 10 - -/* scale on entry */ - -#define INITSCALEMTOF (.2 * FRACUNIT) - -/* how much the automap moves window per tic in frame-buffer coordinates - * moves 140 pixels in 1 second - */ - -#define F_PANINC 4 - -/* how much zoom-in per tic goes to 2x in 1 second */ - -#define M_ZOOMIN ((int)(1.02 * FRACUNIT)) - -/* how much zoom-out per tic pulls out to 0.5x in 1 second */ - -#define M_ZOOMOUT ((int)(FRACUNIT / 1.02)) - -/* translates between frame-buffer and map distances */ - -#define FTOM(x) fixed_mul(((x) << FRACBITS), scale_ftom) -#define MTOF(x) (fixed_mul((x), scale_mtof) >> FRACBITS) - -/* translates between frame-buffer and map coordinates */ - -#define CXMTOF(x) (f_x + MTOF((x) - m_x)) -#define CYMTOF(y) (f_y + (f_h - MTOF((y) - m_y))) - -/* the following is crap */ - -#define LINE_NEVERSEE ML_DONTDRAW - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -typedef struct -{ - int x; - int y; -} fpoint_t; - -typedef struct -{ - fpoint_t a; - fpoint_t b; -} fline_t; - -typedef struct -{ - fixed_t x; - fixed_t y; -} mpoint_t; - -typedef struct -{ - mpoint_t a; - mpoint_t b; -} mline_t; - -typedef struct -{ - fixed_t slp; - fixed_t islp; -} islope_t; - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/* The vector graphics for the automap. A line drawing of the player pointing - * right, starting from the middle. - */ - -#define R ((8 * PLAYERRADIUS) / 7) -mline_t player_arrow[] = -{ - { - { - -R + R / 8, - 0, - }, - { - R, - 0, - }, - }, /* ----- */ - { - { - R, - 0, - }, - { - R - R / 2, - R / 4, - }, - }, /* -----> */ - { - { - R, - 0, - }, - { - R - R / 2, - -R / 4, - }, - }, - { - { - -R + R / 8, - 0, - }, - { - -R - R / 8, - R / 4, - }, - }, /* >----> */ - { - { - -R + R / 8, - 0, - }, - { - -R - R / 8, - -R / 4, - }, - }, - { - { - -R + 3 * R / 8, - 0, - }, - { - -R + R / 8, - R / 4, - }, - }, /* >>---> */ - { - { - -R + 3 * R / 8, - 0, - }, - { - -R + R / 8, - -R / 4, - }, - }, -}; -#undef R - -#define R ((8 * PLAYERRADIUS) / 7) -mline_t cheat_player_arrow[] = -{ - { - { - -R + R / 8, - 0, - }, - { - R, - 0, - }, - }, /* ----- */ - { - { - R, - 0, - }, - { - R - R / 2, - R / 6, - }, - }, /* -----> */ - { - { - R, - 0, - }, - { - R - R / 2, - -R / 6, - }, - }, - { - { - -R + R / 8, - 0, - }, - { - -R - R / 8, - R / 6, - }, - }, /* >-----> */ - { - { - -R + R / 8, - 0, - }, - { - -R - R / 8, - -R / 6, - }, - }, - { - { - -R + 3 * R / 8, - 0, - }, - { - -R + R / 8, - R / 6, - }, - }, /* >>-----> */ - { - { - -R + 3 * R / 8, - 0, - }, - { - -R + R / 8, - -R / 6, - }, - }, - { - { - -R / 2, - 0, - }, - { - -R / 2, - -R / 6, - }, - }, /* >>-d---> */ - { - { - -R / 2, - -R / 6, - }, - { - -R / 2 + R / 6, - -R / 6, - }, - }, - { - { - -R / 2 + R / 6, - -R / 6, - }, - { - -R / 2 + R / 6, - R / 4, - }, - }, - { - { - -R / 6, - 0, - }, - { - -R / 6, - -R / 6, - }, - }, /* >>-dd--> */ - { - { - -R / 6, - -R / 6, - }, - { - 0, - -R / 6, - }, - }, - { - { - 0, - -R / 6, - }, - { - 0, - R / 4, - }, - }, - { - { - R / 6, - R / 4, - }, - { - R / 6, - -R / 7, - }, - }, /* >>-ddt-> */ - { - { - R / 6, - -R / 7, - }, - { - R / 6 + R / 32, - -R / 7 - R / 32, - }, - }, - { - { - R / 6 + R / 32, - -R / 7 - R / 32, - }, - { - R / 6 + R / 10, - -R / 7, - }, - }, -}; -#undef R - -#define R (FRACUNIT) -mline_t triangle_guy[] = -{ - { - { - (fixed_t)(-.867 * R), - (fixed_t)(-.5 * R), - }, - { - (fixed_t)(.867 * R), - (fixed_t)(-.5 * R), - }, - }, - { - { - (fixed_t)(.867 * R), - (fixed_t)(-.5 * R), - }, - { - (fixed_t)(0), - (fixed_t)(R), - }, - }, - { - { - (fixed_t)(0), - (fixed_t)(R), - }, - { - (fixed_t)(-.867 * R), - (fixed_t)(-.5 * R), - }, - }, -}; -#undef R - -#define R (FRACUNIT) -mline_t thintriangle_guy[] = -{ - { - { - (fixed_t)(-.5 * R), - (fixed_t)(-.7 * R), - }, - { - (fixed_t)(R), - (fixed_t)(0), - }, - }, - { - { - (fixed_t)(R), - (fixed_t)(0), - }, - { - (fixed_t)(-.5 * R), - (fixed_t)(.7 * R), - }, - }, - { - { - (fixed_t)(-.5 * R), - (fixed_t)(.7 * R), - }, - { - (fixed_t)(-.5 * R), - (fixed_t)(-.7 * R), - }, - }, -}; -#undef R - -boolean automapactive = false; - -cheatseq_t cheat_amap = CHEAT("iddt", 0); - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static int cheating = 0; -static int grid = 0; - -static int finit_width = SCREENWIDTH; -static int finit_height = SCREENHEIGHT - ST_HEIGHT; - -/* location of window on screen */ - -static int f_x; -static int f_y; - -/* size of window on screen */ - -static int f_w; -static int f_h; - -static int lightlev; /* used for funky strobing effect */ -static pixel_t *fb; /* pseudo-frame buffer */ -static int amclock; - -/* how far the window pans each tic (map coords) */ - -static mpoint_t m_paninc; - -/* how far the window zooms in each tic (map coords) */ - -static fixed_t mtof_zoommul; - -/* how far the window zooms in each tic (fb coords) */ - -static fixed_t ftom_zoommul; - -/* LL x,y where the window is on the map (map coords) */ - -static fixed_t m_x; -static fixed_t m_y; - -/* UR x,y where the window is on the map (map coords) */ - -static fixed_t m_x2; -static fixed_t m_y2; - -/* width/height of window on map (map coords) */ - -static fixed_t m_w; -static fixed_t m_h; - -/* based on level size */ - -static fixed_t min_x; -static fixed_t min_y; -static fixed_t max_x; -static fixed_t max_y; - -static fixed_t max_w; /* max_x-min_x, */ -static fixed_t max_h; /* max_y-min_y */ - -/* based on player size */ - -static fixed_t min_w; -static fixed_t min_h; - -static fixed_t min_scale_mtof; /* used to tell when to stop zooming out */ -static fixed_t max_scale_mtof; /* used to tell when to stop zooming in */ - -/* old stuff for recovery later */ - -static fixed_t old_m_w; -static fixed_t old_m_h; -static fixed_t old_m_x; -static fixed_t old_m_y; - -/* old location used by the Follower routine */ - -static mpoint_t f_oldloc; - -/* used by MTOF to scale from map-to-frame-buffer coords */ - -static fixed_t scale_mtof = (fixed_t)INITSCALEMTOF; - -/* used by FTOM to scale from frame-buffer-to-map coords (=1/scale_mtof) */ - -static fixed_t scale_ftom; - -static player_t *plr; /* the player represented by an arrow */ - -static patch_t *marknums[10]; /* numbers used for marking by the automap */ - -static mpoint_t markpoints[AM_NUMMARKPOINTS]; /* where the points are */ - -static int markpointnum = 0; /* next point to be assigned */ - -/* specifies whether to follow the player around */ - -static int followplayer = 1; - -static boolean stopped = true; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: am_get_i_slope - * - * Description: - * Calculates the slope and slope according to the x-axis of a line - * segment in map coordinates (with the upright y-axis n' all) so - * that it can be used with the brain-dead drawing stuff. - * - ****************************************************************************/ - -#if 0 /* UNUSED */ -static void am_get_i_slope(mline_t *ml, islope_t *is) -{ - int dx; - int dy; - - dy = ml->a.y - ml->b.y; - dx = ml->b.x - ml->a.x; - if (!dy) - is->islp = (dx < 0 ? -INT_MAX : INT_MAX); - else - is->islp = fixed_div(dx, dy); - if (!dx) - is->slp = (dy < 0 ? -INT_MAX : INT_MAX); - else - is->slp = fixed_div(dy, dx); -} -#endif - -/**************************************************************************** - * Name: am_activate_new_scale - ****************************************************************************/ - -static void am_activate_new_scale(void) -{ - m_x += m_w / 2; - m_y += m_h / 2; - m_w = FTOM(f_w); - m_h = FTOM(f_h); - m_x -= m_w / 2; - m_y -= m_h / 2; - m_x2 = m_x + m_w; - m_y2 = m_y + m_h; -} - -/**************************************************************************** - * Name: am_save_scale_and_loc - ****************************************************************************/ - -static void am_save_scale_and_loc(void) -{ - old_m_x = m_x; - old_m_y = m_y; - old_m_w = m_w; - old_m_h = m_h; -} - -/**************************************************************************** - * Name: am_restore_scale_and_loc - ****************************************************************************/ - -static void am_restore_scale_and_loc(void) -{ - m_w = old_m_w; - m_h = old_m_h; - - if (!followplayer) - { - m_x = old_m_x; - m_y = old_m_y; - } - else - { - m_x = plr->mo->x - m_w / 2; - m_y = plr->mo->y - m_h / 2; - } - - m_x2 = m_x + m_w; - m_y2 = m_y + m_h; - - /* Change the scaling multipliers */ - - scale_mtof = fixed_div(f_w << FRACBITS, m_w); - scale_ftom = fixed_div(FRACUNIT, scale_mtof); -} - -/**************************************************************************** - * Name: am_add_mark - * - * Description: - * adds a marker at the current location - * - ****************************************************************************/ - -static void am_add_mark(void) -{ - markpoints[markpointnum].x = m_x + m_w / 2; - markpoints[markpointnum].y = m_y + m_h / 2; - markpointnum = (markpointnum + 1) % AM_NUMMARKPOINTS; -} - -/**************************************************************************** - * Name: am_find_minmax_boundaries - * - * Description: - * Determines bounding box of all vertices, sets global variables - * controlling zoom range. - * - ****************************************************************************/ - -static void am_find_minmax_boundaries(void) -{ - int i; - fixed_t a; - fixed_t b; - - min_x = min_y = INT_MAX; - max_x = max_y = -INT_MAX; - - for (i = 0; i < numvertices; i++) - { - if (vertices[i].x < min_x) - min_x = vertices[i].x; - else if (vertices[i].x > max_x) - max_x = vertices[i].x; - - if (vertices[i].y < min_y) - min_y = vertices[i].y; - else if (vertices[i].y > max_y) - max_y = vertices[i].y; - } - - max_w = max_x - min_x; - max_h = max_y - min_y; - - min_w = 2 * PLAYERRADIUS; /* const? never changed? */ - min_h = 2 * PLAYERRADIUS; - - a = fixed_div(f_w << FRACBITS, max_w); - b = fixed_div(f_h << FRACBITS, max_h); - - min_scale_mtof = a < b ? a : b; - max_scale_mtof = fixed_div(f_h << FRACBITS, 2 * PLAYERRADIUS); -} - -/**************************************************************************** - * Name: am_change_window_loc - ****************************************************************************/ - -static void am_change_window_loc(void) -{ - if (m_paninc.x || m_paninc.y) - { - followplayer = 0; - f_oldloc.x = INT_MAX; - } - - m_x += m_paninc.x; - m_y += m_paninc.y; - - if (m_x + m_w / 2 > max_x) - m_x = max_x - m_w / 2; - else if (m_x + m_w / 2 < min_x) - m_x = min_x - m_w / 2; - - if (m_y + m_h / 2 > max_y) - m_y = max_y - m_h / 2; - else if (m_y + m_h / 2 < min_y) - m_y = min_y - m_h / 2; - - m_x2 = m_x + m_w; - m_y2 = m_y + m_h; -} - -/**************************************************************************** - * Name: am_init_variables - ****************************************************************************/ - -static void am_init_variables(void) -{ - int pnum; - static event_t st_notify = - { - ev_keyup, AM_MSGENTERED, 0, 0 - }; - - automapactive = true; - fb = i_video_buffer; - - f_oldloc.x = INT_MAX; - amclock = 0; - lightlev = 0; - - m_paninc.x = m_paninc.y = 0; - ftom_zoommul = FRACUNIT; - mtof_zoommul = FRACUNIT; - - m_w = FTOM(f_w); - m_h = FTOM(f_h); - - /* find player to center on initially */ - - if (playeringame[consoleplayer]) - { - plr = &players[consoleplayer]; - } - else - { - plr = &players[0]; - - for (pnum = 0; pnum < MAXPLAYERS; pnum++) - { - if (playeringame[pnum]) - { - plr = &players[pnum]; - break; - } - } - } - - m_x = plr->mo->x - m_w / 2; - m_y = plr->mo->y - m_h / 2; - am_change_window_loc(); - - /* for saving & restoring */ - - old_m_x = m_x; - old_m_y = m_y; - old_m_w = m_w; - old_m_h = m_h; - - /* inform the status bar of the change */ - - st_responder(&st_notify); -} - -/**************************************************************************** - * Name: am_load_pics - ****************************************************************************/ - -static void am_load_pics(void) -{ - int i; - char namebuf[9]; - - for (i = 0; i < 10; i++) - { - snprintf(namebuf, 9, "AMMNUM%d", i); - marknums[i] = w_cache_lump_name(namebuf, PU_STATIC); - } -} - -/**************************************************************************** - * Name: am_unload_pics - ****************************************************************************/ - -static void am_unload_pics(void) -{ - int i; - char namebuf[9]; - - for (i = 0; i < 10; i++) - { - snprintf(namebuf, 9, "AMMNUM%d", i); - w_release_lump_name(namebuf); - } -} - -/**************************************************************************** - * Name: am_clear_marks - ****************************************************************************/ - -static void am_clear_marks(void) -{ - int i; - - for (i = 0; i < AM_NUMMARKPOINTS; i++) - { - markpoints[i].x = -1; /* means empty */ - } - - markpointnum = 0; -} - -/**************************************************************************** - * Name: am_level_init - * - * Description: - * should be called at the start of every level right now, i figure it out - * myself - * - ****************************************************************************/ - -static void am_level_init(void) -{ - f_x = f_y = 0; - f_w = finit_width; - f_h = finit_height; - - am_clear_marks(); - - am_find_minmax_boundaries(); - scale_mtof = fixed_div(min_scale_mtof, (int)(0.7 * FRACUNIT)); - if (scale_mtof > max_scale_mtof) scale_mtof = min_scale_mtof; - scale_ftom = fixed_div(FRACUNIT, scale_mtof); -} - -/**************************************************************************** - * Name: am_start - ****************************************************************************/ - -static void am_start(void) -{ - static int lastlevel = -1; - static int lastepisode = -1; - - if (!stopped) am_stop(); - stopped = false; - if (lastlevel != gamemap || lastepisode != gameepisode) - { - am_level_init(); - lastlevel = gamemap; - lastepisode = gameepisode; - } - - am_init_variables(); - am_load_pics(); -} - -/**************************************************************************** - * Name: am_min_out_window_scale - * - * Description: - * set the window scale to the maximum size - * - ****************************************************************************/ - -static void am_min_out_window_scale(void) -{ - scale_mtof = min_scale_mtof; - scale_ftom = fixed_div(FRACUNIT, scale_mtof); - am_activate_new_scale(); -} - -/**************************************************************************** - * Name: am_max_out_window_scale - * - * Description: - * set the window scale to the minimum size - * - ****************************************************************************/ - -static void am_max_out_window_scale(void) -{ - scale_mtof = max_scale_mtof; - scale_ftom = fixed_div(FRACUNIT, scale_mtof); - am_activate_new_scale(); -} - -/**************************************************************************** - * Name: am_change_window_scale - * - * Description: - * Zooming - * - ****************************************************************************/ - -static void am_change_window_scale(void) -{ - /* Change the scaling multipliers */ - - scale_mtof = fixed_mul(scale_mtof, mtof_zoommul); - scale_ftom = fixed_div(FRACUNIT, scale_mtof); - - if (scale_mtof < min_scale_mtof) - am_min_out_window_scale(); - else if (scale_mtof > max_scale_mtof) - am_max_out_window_scale(); - else - am_activate_new_scale(); -} - -/**************************************************************************** - * Name: am_do_follow_player - ****************************************************************************/ - -static void am_do_follow_player(void) -{ - if (f_oldloc.x != plr->mo->x || f_oldloc.y != plr->mo->y) - { - m_x = FTOM(MTOF(plr->mo->x)) - m_w / 2; - m_y = FTOM(MTOF(plr->mo->y)) - m_h / 2; - m_x2 = m_x + m_w; - m_y2 = m_y + m_h; - f_oldloc.x = plr->mo->x; - f_oldloc.y = plr->mo->y; - - /* m_x = FTOM(MTOF(plr->mo->x - m_w/2)); - * m_y = FTOM(MTOF(plr->mo->y - m_h/2)); - * m_x = plr->mo->x - m_w/2; - * m_y = plr->mo->y - m_h/2; - */ - } -} - -/**************************************************************************** - * Name: am_update_light_lev - ****************************************************************************/ - -#if 0 /* UNUSED */ -static void am_update_light_lev(void) -{ - static int nexttic = 0; - - /* static int litelevels[] = { 0, 3, 5, 6, 6, 7, 7, 7 }; */ - - static int litelevels[] = - { - 0, 4, 7, 10, 12, 14, 15, 15 - }; - - static int litelevelscnt = 0; - - /* Change light level */ - - if (amclock > nexttic) - { - lightlev = litelevels[litelevelscnt++]; - if (litelevelscnt == arrlen(litelevels)) litelevelscnt = 0; - nexttic = amclock + 6 - (amclock % 6); - } -} -#endif - -/**************************************************************************** - * Name: am_clear_fb - * - * Description: - * Clear automap frame buffer. - * - ****************************************************************************/ - -static void am_clear_fb(int color) -{ - memset(fb, color, f_w * f_h * sizeof(*fb)); -} - -/**************************************************************************** - * Name: am_clip_m_line - * - * Description: - * Automap clipping of lines. - * Based on Cohen-Sutherland clipping algorithm but with a slightly - * faster reject and precalculated slopes. If the speed is needed, - * use a hash algorithm to handle the common cases. - * - ****************************************************************************/ - -static boolean am_clip_m_line(mline_t *ml, fline_t *fl) -{ - enum - { - LEFT = 1, - RIGHT = 2, - BOTTOM = 4, - TOP = 8 - }; - - register int outcode1 = 0; - register int outcode2 = 0; - register int outside; - - fpoint_t tmp; - int dx; - int dy; - -#define DOOUTCODE(oc, mx, my) \ - (oc) = 0; \ - if ((my) < 0) \ - (oc) |= TOP; \ - else if ((my) >= f_h) \ - (oc) |= BOTTOM; \ - if ((mx) < 0) \ - (oc) |= LEFT; \ - else if ((mx) >= f_w) \ - (oc) |= RIGHT; - - /* do trivial rejects and outcodes */ - - if (ml->a.y > m_y2) - outcode1 = TOP; - else if (ml->a.y < m_y) - outcode1 = BOTTOM; - - if (ml->b.y > m_y2) - outcode2 = TOP; - else if (ml->b.y < m_y) - outcode2 = BOTTOM; - - if (outcode1 & outcode2) return false; /* trivially outside */ - - if (ml->a.x < m_x) - outcode1 |= LEFT; - else if (ml->a.x > m_x2) - outcode1 |= RIGHT; - - if (ml->b.x < m_x) - outcode2 |= LEFT; - else if (ml->b.x > m_x2) - outcode2 |= RIGHT; - - if (outcode1 & outcode2) return false; /* trivially outside */ - - /* transform to frame-buffer coordinates. */ - - fl->a.x = CXMTOF(ml->a.x); - fl->a.y = CYMTOF(ml->a.y); - fl->b.x = CXMTOF(ml->b.x); - fl->b.y = CYMTOF(ml->b.y); - - DOOUTCODE(outcode1, fl->a.x, fl->a.y); - DOOUTCODE(outcode2, fl->b.x, fl->b.y); - - if (outcode1 & outcode2) return false; - - while (outcode1 | outcode2) - { - /* may be partially inside box find an outside point */ - - if (outcode1) - outside = outcode1; - else - outside = outcode2; - - /* clip to each side */ - - if (outside & TOP) - { - dy = fl->a.y - fl->b.y; - dx = fl->b.x - fl->a.x; - tmp.x = fl->a.x + (dx * (fl->a.y)) / dy; - tmp.y = 0; - } - else if (outside & BOTTOM) - { - dy = fl->a.y - fl->b.y; - dx = fl->b.x - fl->a.x; - tmp.x = fl->a.x + (dx * (fl->a.y - f_h)) / dy; - tmp.y = f_h - 1; - } - else if (outside & RIGHT) - { - dy = fl->b.y - fl->a.y; - dx = fl->b.x - fl->a.x; - tmp.y = fl->a.y + (dy * (f_w - 1 - fl->a.x)) / dx; - tmp.x = f_w - 1; - } - else if (outside & LEFT) - { - dy = fl->b.y - fl->a.y; - dx = fl->b.x - fl->a.x; - tmp.y = fl->a.y + (dy * (-fl->a.x)) / dx; - tmp.x = 0; - } - else - { - tmp.x = 0; - tmp.y = 0; - } - - if (outside == outcode1) - { - fl->a = tmp; - DOOUTCODE(outcode1, fl->a.x, fl->a.y); - } - else - { - fl->b = tmp; - DOOUTCODE(outcode2, fl->b.x, fl->b.y); - } - - if (outcode1 & outcode2) return false; /* trivially outside */ - } - - return true; -} -#undef DOOUTCODE - -/**************************************************************************** - * Name: am_draw_f_line - * - * Description: - * Classic Bresenham w/ whatever optimizations needed for speed - * - ****************************************************************************/ - -static void am_draw_f_line(fline_t *fl, int color) -{ - register int x; - register int y; - register int dx; - register int dy; - register int sx; - register int sy; - register int ax; - register int ay; - register int d; - - static int fuck = 0; - - /* For debugging only */ - - if (fl->a.x < 0 || fl->a.x >= f_w || fl->a.y < 0 || fl->a.y >= f_h || - fl->b.x < 0 || fl->b.x >= f_w || fl->b.y < 0 || fl->b.y >= f_h) - { - fprintf(stderr, "fuck %d \r", fuck++); - return; - } - -#define PUTDOT(xx, yy, cc) fb[(yy) * f_w + (xx)] = (cc) - - dx = fl->b.x - fl->a.x; - ax = 2 * (dx < 0 ? -dx : dx); - sx = dx < 0 ? -1 : 1; - - dy = fl->b.y - fl->a.y; - ay = 2 * (dy < 0 ? -dy : dy); - sy = dy < 0 ? -1 : 1; - - x = fl->a.x; - y = fl->a.y; - - if (ax > ay) - { - d = ay - ax / 2; - while (1) - { - PUTDOT(x, y, color); - if (x == fl->b.x) return; - if (d >= 0) - { - y += sy; - d -= ax; - } - - x += sx; - d += ay; - } - } - else - { - d = ax - ay / 2; - while (1) - { - PUTDOT(x, y, color); - if (y == fl->b.y) return; - if (d >= 0) - { - x += sx; - d -= ay; - } - - y += sy; - d += ax; - } - } -} - -/**************************************************************************** - * Name: am_draw_m_line - * - * Description: - * Clip lines, draw visible part sof lines. - * - ****************************************************************************/ - -void am_draw_m_line(mline_t *ml, int color) -{ - static fline_t fl; - - if (am_clip_m_line(ml, &fl)) - { - /* draws it on frame buffer using fb coords */ - - am_draw_f_line(&fl, color); - } -} - -/**************************************************************************** - * Name: am_draw_grid - * - * Description: - * Draws flat (floor/ceiling tile) aligned grid lines. - * - ****************************************************************************/ - -static void am_draw_grid(int color) -{ - fixed_t x, y; - fixed_t start; - fixed_t end; - mline_t ml; - - /* Figure out start of vertical gridlines */ - - start = m_x; - if ((start - bmaporgx) % (MAPBLOCKUNITS << FRACBITS)) - start += (MAPBLOCKUNITS << FRACBITS) - - ((start - bmaporgx) % (MAPBLOCKUNITS << FRACBITS)); - end = m_x + m_w; - - /* draw vertical gridlines */ - - ml.a.y = m_y; - ml.b.y = m_y + m_h; - for (x = start; x < end; x += (MAPBLOCKUNITS << FRACBITS)) - { - ml.a.x = x; - ml.b.x = x; - am_draw_m_line(&ml, color); - } - - /* Figure out start of horizontal gridlines */ - - start = m_y; - if ((start - bmaporgy) % (MAPBLOCKUNITS << FRACBITS)) - start += (MAPBLOCKUNITS << FRACBITS) - - ((start - bmaporgy) % (MAPBLOCKUNITS << FRACBITS)); - end = m_y + m_h; - - /* draw horizontal gridlines */ - - ml.a.x = m_x; - ml.b.x = m_x + m_w; - for (y = start; y < end; y += (MAPBLOCKUNITS << FRACBITS)) - { - ml.a.y = y; - ml.b.y = y; - am_draw_m_line(&ml, color); - } -} - -/**************************************************************************** - * Name: am_draw_walls - * - * Description: - * Determines visible lines, draws them. This is LineDef based, not LineSeg - * based. - * - ****************************************************************************/ - -static void am_draw_walls(void) -{ - int i; - static mline_t l; - - for (i = 0; i < numlines; i++) - { - l.a.x = lines[i].v1->x; - l.a.y = lines[i].v1->y; - l.b.x = lines[i].v2->x; - l.b.y = lines[i].v2->y; - if (cheating || (lines[i].flags & ML_MAPPED)) - { - if ((lines[i].flags & LINE_NEVERSEE) && !cheating) continue; - if (!lines[i].backsector) - { - am_draw_m_line(&l, WALLCOLORS + lightlev); - } - else - { - if (lines[i].special == 39) - { - /* teleporters */ - - am_draw_m_line(&l, WALLCOLORS + WALLRANGE / 2); - } - else if (lines[i].flags & ML_SECRET) /* secret door */ - { - if (cheating) - am_draw_m_line(&l, SECRETWALLCOLORS + lightlev); - else - am_draw_m_line(&l, WALLCOLORS + lightlev); - } - else if (lines[i].backsector->floorheight != - lines[i].frontsector->floorheight) - { - /* floor level change */ - - am_draw_m_line(&l, FDWALLCOLORS + lightlev); - } - else if (lines[i].backsector->ceilingheight != - lines[i].frontsector->ceilingheight) - { - /* ceiling level change */ - - am_draw_m_line(&l, CDWALLCOLORS + lightlev); - } - else if (cheating) - { - am_draw_m_line(&l, TSWALLCOLORS + lightlev); - } - } - } - else if (plr->powers[pw_allmap]) - { - if (!(lines[i].flags & LINE_NEVERSEE)) - { - am_draw_m_line(&l, GRAYS + 3); - } - } - } -} - -/**************************************************************************** - * Name: am_rotate - * - * Description: - * Rotation in 2D. - * Used to rotate player arrow line character. - * - ****************************************************************************/ - -static void am_rotate(fixed_t *x, fixed_t *y, angle_t a) -{ - fixed_t tmpx; - - tmpx = fixed_mul(*x, finecosine[a >> ANGLETOFINESHIFT]) - - fixed_mul(*y, finesine[a >> ANGLETOFINESHIFT]); - - *y = fixed_mul(*x, finesine[a >> ANGLETOFINESHIFT]) + - fixed_mul(*y, finecosine[a >> ANGLETOFINESHIFT]); - - *x = tmpx; -} - -static void am_draw_line_character(mline_t *lineguy, int lineguylines, - fixed_t scale, angle_t angle, int color, - fixed_t x, fixed_t y) -{ - int i; - mline_t l; - - for (i = 0; i < lineguylines; i++) - { - l.a.x = lineguy[i].a.x; - l.a.y = lineguy[i].a.y; - - if (scale) - { - l.a.x = fixed_mul(scale, l.a.x); - l.a.y = fixed_mul(scale, l.a.y); - } - - if (angle) am_rotate(&l.a.x, &l.a.y, angle); - - l.a.x += x; - l.a.y += y; - - l.b.x = lineguy[i].b.x; - l.b.y = lineguy[i].b.y; - - if (scale) - { - l.b.x = fixed_mul(scale, l.b.x); - l.b.y = fixed_mul(scale, l.b.y); - } - - if (angle) am_rotate(&l.b.x, &l.b.y, angle); - - l.b.x += x; - l.b.y += y; - - am_draw_m_line(&l, color); - } -} - -static void am_draw_players(void) -{ - int i; - player_t *p; - int their_color = -1; - int color; - - static int their_colors[] = - { - GREENS, GRAYS, BROWNS, REDS - }; - - if (!netgame) - { - if (cheating) - { - am_draw_line_character( - cheat_player_arrow, arrlen(cheat_player_arrow), 0, - plr->mo->angle, WHITE, plr->mo->x, plr->mo->y); - } - else - { - am_draw_line_character(player_arrow, arrlen(player_arrow), 0, - plr->mo->angle, WHITE, plr->mo->x, - plr->mo->y); - } - - return; - } - - for (i = 0; i < MAXPLAYERS; i++) - { - their_color++; - p = &players[i]; - - if ((deathmatch && !singledemo) && p != plr) continue; - - if (!playeringame[i]) continue; - - if (p->powers[pw_invisibility]) - color = 246; /* *close* to black */ - else - color = their_colors[their_color]; - - am_draw_line_character(player_arrow, arrlen(player_arrow), 0, - p->mo->angle, color, p->mo->x, p->mo->y); - } -} - -static void am_draw_things(int colors, int colorrange) -{ - int i; - mobj_t *t; - - for (i = 0; i < numsectors; i++) - { - t = sectors[i].thinglist; - while (t) - { - am_draw_line_character(thintriangle_guy, arrlen(thintriangle_guy), - 16 << FRACBITS, t->angle, colors + lightlev, - t->x, t->y); - t = t->snext; - } - } -} - -static void am_draw_marks(void) -{ - int i; - int fx; - int fy; - int w; - int h; - - for (i = 0; i < AM_NUMMARKPOINTS; i++) - { - if (markpoints[i].x != -1) - { - /* w = SHORT(marknums[i]->width); - * h = SHORT(marknums[i]->height); - */ - - w = 5; /* because something's wrong with the wad, i guess */ - h = 6; /* because something's wrong with the wad, i guess */ - fx = CXMTOF(markpoints[i].x); - fy = CYMTOF(markpoints[i].y); - if (fx >= f_x && fx <= f_w - w && fy >= f_y && fy <= f_h - h) - v_draw_patch(fx, fy, marknums[i]); - } - } -} - -static void am_draw_crosshair(int color) -{ - fb[(f_w * (f_h + 1)) / 2] = color; /* single point for now */ -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: am_stop - ****************************************************************************/ - -void am_stop(void) -{ - static event_t st_notify = - { - 0, ev_keyup, AM_MSGEXITED, 0 - }; - - am_unload_pics(); - automapactive = false; - st_responder(&st_notify); - stopped = true; -} - -/**************************************************************************** - * Name: am_ticker - * - * Description: - * Updates on Game Tick - * - ****************************************************************************/ - -void am_ticker(void) -{ - if (!automapactive) return; - - amclock++; - - if (followplayer) am_do_follow_player(); - - /* Change the zoom if necessary */ - - if (ftom_zoommul != FRACUNIT) am_change_window_scale(); - - /* Change x,y location */ - - if (m_paninc.x || m_paninc.y) am_change_window_loc(); - - /* Update light level */ - - /* am_update_light_lev(); */ -} - -/**************************************************************************** - * Name: am_responder - * - * Description: - * Handle events (user inputs) in automap mode - * - ****************************************************************************/ - -boolean am_responder(event_t *ev) -{ - int rc; - static int bigstate = 0; - static char buffer[20]; - int key; - - rc = false; - - if (ev->type == ev_joystick && joybautomap >= 0 && - (ev->data1 & (1 << joybautomap)) != 0) - { - joywait = i_get_time() + 5; - - if (!automapactive) - { - am_start(); - viewactive = false; - } - else - { - bigstate = 0; - viewactive = true; - am_stop(); - } - - return true; - } - - if (!automapactive) - { - if (ev->type == ev_keydown && ev->data1 == key_map_toggle) - { - am_start(); - viewactive = false; - rc = true; - } - } - else if (ev->type == ev_keydown) - { - rc = true; - key = ev->data1; - - if (key == key_map_east) /* pan right */ - { - if (!followplayer) - m_paninc.x = FTOM(F_PANINC); - else - rc = false; - } - else if (key == key_map_west) /* pan left */ - { - if (!followplayer) - m_paninc.x = -FTOM(F_PANINC); - else - rc = false; - } - else if (key == key_map_north) /* pan up */ - { - if (!followplayer) - m_paninc.y = FTOM(F_PANINC); - else - rc = false; - } - else if (key == key_map_south) /* pan down */ - { - if (!followplayer) - m_paninc.y = -FTOM(F_PANINC); - else - rc = false; - } - else if (key == key_map_zoomout) /* zoom out */ - { - mtof_zoommul = M_ZOOMOUT; - ftom_zoommul = M_ZOOMIN; - } - else if (key == key_map_zoomin) /* zoom in */ - { - mtof_zoommul = M_ZOOMIN; - ftom_zoommul = M_ZOOMOUT; - } - else if (key == key_map_toggle) - { - bigstate = 0; - viewactive = true; - am_stop(); - } - else if (key == key_map_maxzoom) - { - bigstate = !bigstate; - if (bigstate) - { - am_save_scale_and_loc(); - am_min_out_window_scale(); - } - else - am_restore_scale_and_loc(); - } - else if (key == key_map_follow) - { - followplayer = !followplayer; - f_oldloc.x = INT_MAX; - if (followplayer) - plr->message = (AMSTR_FOLLOWON); - else - plr->message = (AMSTR_FOLLOWOFF); - } - else if (key == key_map_grid) - { - grid = !grid; - if (grid) - plr->message = (AMSTR_GRIDON); - else - plr->message = (AMSTR_GRIDOFF); - } - else if (key == key_map_mark) - { - snprintf(buffer, sizeof(buffer), "%s %d", (AMSTR_MARKEDSPOT), - markpointnum); - plr->message = buffer; - am_add_mark(); - } - else if (key == key_map_clearmark) - { - am_clear_marks(); - plr->message = (AMSTR_MARKSCLEARED); - } - else - { - rc = false; - } - - if ((!deathmatch || gameversion <= exe_doom_1_8) && - cht_check_cheat(&cheat_amap, ev->data2)) - { - rc = false; - cheating = (cheating + 1) % 3; - } - } - else if (ev->type == ev_keyup) - { - rc = false; - key = ev->data1; - - if (key == key_map_east) - { - if (!followplayer) m_paninc.x = 0; - } - else if (key == key_map_west) - { - if (!followplayer) m_paninc.x = 0; - } - else if (key == key_map_north) - { - if (!followplayer) m_paninc.y = 0; - } - else if (key == key_map_south) - { - if (!followplayer) m_paninc.y = 0; - } - else if (key == key_map_zoomout || key == key_map_zoomin) - { - mtof_zoommul = FRACUNIT; - ftom_zoommul = FRACUNIT; - } - } - - return rc; -} - -void am_drawer(void) -{ - if (!automapactive) return; - - am_clear_fb(BACKGROUND); - if (grid) am_draw_grid(GRIDCOLORS); - am_draw_walls(); - am_draw_players(); - if (cheating == 2) am_draw_things(THINGCOLORS, THINGRANGE); - am_draw_crosshair(XHAIRCOLORS); - - am_draw_marks(); - - v_mark_rect(f_x, f_y, f_w, f_h); -} diff --git a/games/NXDoom/src/doom/am_map.h b/games/NXDoom/src/doom/am_map.h deleted file mode 100644 index 38b8e4ab1..000000000 --- a/games/NXDoom/src/doom/am_map.h +++ /dev/null @@ -1,95 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/am_map.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * AutoMap module. - * - ****************************************************************************/ - -#ifndef __AMMAP_H__ -#define __AMMAP_H__ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "d_event.h" -#include "m_cheat.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* Used by ST StatusBar stuff. */ - -#define AM_MSGHEADER (('a' << 24) + ('m' << 16)) -#define AM_MSGENTERED (AM_MSGHEADER | ('e' << 8)) -#define AM_MSGEXITED (AM_MSGHEADER | ('x' << 8)) - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -extern cheatseq_t cheat_amap; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Name: am_responder - * - * Description: - * Called by main loop. - * - ****************************************************************************/ - -boolean am_responder(event_t *ev); - -/**************************************************************************** - * Name: am_ticker - * - * Description: - * Called by main loop. - * - ****************************************************************************/ - -void am_ticker(void); - -/**************************************************************************** - * Name: am_ticker - * - * Description: - * Called by main loop. Called instead of view drawer if automap active. - * - ****************************************************************************/ - -void am_drawer(void); - -/**************************************************************************** - * Name: am_stop - * - * Description: - * Called to force the automap to quit if the level is completed while it is - * up. - * - ****************************************************************************/ - -void am_stop(void); - -#endif /* __AMMAP_H__ */ diff --git a/games/NXDoom/src/doom/d_englsh.h b/games/NXDoom/src/doom/d_englsh.h deleted file mode 100644 index 3f0945fc9..000000000 --- a/games/NXDoom/src/doom/d_englsh.h +++ /dev/null @@ -1,695 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/d_englsh.h - * - * SPDX-License-Identifier: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Printed strings for translation. - * English language support (default). - * - ****************************************************************************/ - -#ifndef __D_ENGLSH__ -#define __D_ENGLSH__ - -/* Printed strings for translation */ - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* D_Main.C */ - -#define D_DEVSTR "Development mode ON.\n" -#define D_CDROM "CD-ROM Version: default.cfg from c:\\doomdata\n" - -/* M_Menu.C */ - -#define PRESSKEY "press a key." -#define PRESSYN "press y or n." -#define QUITMSG "are you sure you want to\nquit this great game?" -#define LOADNET "you can't do load while in a net game!\n\n" PRESSKEY -#define QLOADNET "you can't quickload during a netgame!\n\n" PRESSKEY -#define QSAVESPOT "you haven't picked a quicksave slot yet!\n\n" PRESSKEY -#define SAVEDEAD "you can't save if you aren't playing!\n\n" PRESSKEY -#define QSPROMPT "quicksave over your game named\n\n'%s'?\n\n" PRESSYN -#define QLPROMPT \ - "do you want to quickload the game named\n\n'%s'?\n\n" PRESSYN - -#define NEWGAME \ - "you can't start a new game\n" \ - "while in a network game.\n\n" PRESSKEY - -#define NIGHTMARE \ - "are you sure? this skill level\n" \ - "isn't even remotely fair.\n\n" PRESSYN - -#define SWSTRING \ - "this is the shareware version of doom.\n\n" \ - "you need to order the entire trilogy.\n\n" PRESSKEY - -#define MSGOFF "Messages OFF" -#define MSGON "Messages ON" -#define NETEND "you can't end a netgame!\n\n" PRESSKEY -#define ENDGAME "are you sure you want to end the game?\n\n" PRESSYN - -#define DOSY "(press y to quit to dos.)" - -#define DETAILHI "High detail" -#define DETAILLO "Low detail" -#define GAMMALVL0 "Gamma correction OFF" -#define GAMMALVL1 "Gamma correction level 1" -#define GAMMALVL2 "Gamma correction level 2" -#define GAMMALVL3 "Gamma correction level 3" -#define GAMMALVL4 "Gamma correction level 4" -#define EMPTYSTRING "empty slot" - -/* P_inter.C */ - -#define GOTARMOR "Picked up the armor." -#define GOTMEGA "Picked up the MegaArmor!" -#define GOTHTHBONUS "Picked up a health bonus." -#define GOTARMBONUS "Picked up an armor bonus." -#define GOTSTIM "Picked up a stimpack." -#define GOTMEDINEED "Picked up a medikit that you REALLY need!" -#define GOTMEDIKIT "Picked up a medikit." -#define GOTSUPER "Supercharge!" - -#define GOTBLUECARD "Picked up a blue keycard." -#define GOTYELWCARD "Picked up a yellow keycard." -#define GOTREDCARD "Picked up a red keycard." -#define GOTBLUESKUL "Picked up a blue skull key." -#define GOTYELWSKUL "Picked up a yellow skull key." -#define GOTREDSKULL "Picked up a red skull key." - -#define GOTINVUL "Invulnerability!" -#define GOTBERSERK "Berserk!" -#define GOTINVIS "Partial Invisibility" -#define GOTSUIT "Radiation Shielding Suit" -#define GOTMAP "Computer Area Map" -#define GOTVISOR "Light Amplification Visor" -#define GOTMSPHERE "MegaSphere!" - -#define GOTCLIP "Picked up a clip." -#define GOTCLIPBOX "Picked up a box of bullets." -#define GOTROCKET "Picked up a rocket." -#define GOTROCKBOX "Picked up a box of rockets." -#define GOTCELL "Picked up an energy cell." -#define GOTCELLBOX "Picked up an energy cell pack." -#define GOTSHELLS "Picked up 4 shotgun shells." -#define GOTSHELLBOX "Picked up a box of shotgun shells." -#define GOTBACKPACK "Picked up a backpack full of ammo!" - -#define GOTBFG9000 "You got the BFG9000! Oh, yes." -#define GOTCHAINGUN "You got the chaingun!" -#define GOTCHAINSAW "A chainsaw! Find some meat!" -#define GOTLAUNCHER "You got the rocket launcher!" -#define GOTPLASMA "You got the plasma gun!" -#define GOTSHOTGUN "You got the shotgun!" -#define GOTSHOTGUN2 "You got the super shotgun!" - -/* P_Doors.C */ - -#define PD_BLUEO "You need a blue key to activate this object" -#define PD_REDO "You need a red key to activate this object" -#define PD_YELLOWO "You need a yellow key to activate this object" -#define PD_BLUEK "You need a blue key to open this door" -#define PD_REDK "You need a red key to open this door" -#define PD_YELLOWK "You need a yellow key to open this door" - -/* G_game.C */ - -#define GGSAVED "game saved." - -/* HU_stuff.C */ - -#define HUSTR_MSGU "[Message unsent]" - -#define HUSTR_E1M1 "E1M1: Hangar" -#define HUSTR_E1M2 "E1M2: Nuclear Plant" -#define HUSTR_E1M3 "E1M3: Toxin Refinery" -#define HUSTR_E1M4 "E1M4: Command Control" -#define HUSTR_E1M5 "E1M5: Phobos Lab" -#define HUSTR_E1M6 "E1M6: Central Processing" -#define HUSTR_E1M7 "E1M7: Computer Station" -#define HUSTR_E1M8 "E1M8: Phobos Anomaly" -#define HUSTR_E1M9 "E1M9: Military Base" - -#define HUSTR_E2M1 "E2M1: Deimos Anomaly" -#define HUSTR_E2M2 "E2M2: Containment Area" -#define HUSTR_E2M3 "E2M3: Refinery" -#define HUSTR_E2M4 "E2M4: Deimos Lab" -#define HUSTR_E2M5 "E2M5: Command Center" -#define HUSTR_E2M6 "E2M6: Halls of the Damned" -#define HUSTR_E2M7 "E2M7: Spawning Vats" -#define HUSTR_E2M8 "E2M8: Tower of Babel" -#define HUSTR_E2M9 "E2M9: Fortress of Mystery" - -#define HUSTR_E3M1 "E3M1: Hell Keep" -#define HUSTR_E3M2 "E3M2: Slough of Despair" -#define HUSTR_E3M3 "E3M3: Pandemonium" -#define HUSTR_E3M4 "E3M4: House of Pain" -#define HUSTR_E3M5 "E3M5: Unholy Cathedral" -#define HUSTR_E3M6 "E3M6: Mt. Erebus" -#define HUSTR_E3M7 "E3M7: Limbo" -#define HUSTR_E3M8 "E3M8: Dis" -#define HUSTR_E3M9 "E3M9: Warrens" - -#define HUSTR_E4M1 "E4M1: Hell Beneath" -#define HUSTR_E4M2 "E4M2: Perfect Hatred" -#define HUSTR_E4M3 "E4M3: Sever The Wicked" -#define HUSTR_E4M4 "E4M4: Unruly Evil" -#define HUSTR_E4M5 "E4M5: They Will Repent" -#define HUSTR_E4M6 "E4M6: Against Thee Wickedly" -#define HUSTR_E4M7 "E4M7: And Hell Followed" -#define HUSTR_E4M8 "E4M8: Unto The Cruel" -#define HUSTR_E4M9 "E4M9: Fear" - -#define HUSTR_1 "level 1: entryway" -#define HUSTR_2 "level 2: underhalls" -#define HUSTR_3 "level 3: the gantlet" -#define HUSTR_4 "level 4: the focus" -#define HUSTR_5 "level 5: the waste tunnels" -#define HUSTR_6 "level 6: the crusher" -#define HUSTR_7 "level 7: dead simple" -#define HUSTR_8 "level 8: tricks and traps" -#define HUSTR_9 "level 9: the pit" -#define HUSTR_10 "level 10: refueling base" -#define HUSTR_11 "level 11: 'o' of destruction!" - -#define HUSTR_12 "level 12: the factory" -#define HUSTR_13 "level 13: downtown" -#define HUSTR_14 "level 14: the inmost dens" -#define HUSTR_15 "level 15: industrial zone" -#define HUSTR_16 "level 16: suburbs" -#define HUSTR_17 "level 17: tenements" -#define HUSTR_18 "level 18: the courtyard" -#define HUSTR_19 "level 19: the citadel" -#define HUSTR_20 "level 20: gotcha!" - -#define HUSTR_21 "level 21: nirvana" -#define HUSTR_22 "level 22: the catacombs" -#define HUSTR_23 "level 23: barrels o' fun" -#define HUSTR_24 "level 24: the chasm" -#define HUSTR_25 "level 25: bloodfalls" -#define HUSTR_26 "level 26: the abandoned mines" -#define HUSTR_27 "level 27: monster condo" -#define HUSTR_28 "level 28: the spirit world" -#define HUSTR_29 "level 29: the living end" -#define HUSTR_30 "level 30: icon of sin" - -#define HUSTR_31 "level 31: wolfenstein" -#define HUSTR_32 "level 32: grosse" - -#define PHUSTR_1 "level 1: congo" -#define PHUSTR_2 "level 2: well of souls" -#define PHUSTR_3 "level 3: aztec" -#define PHUSTR_4 "level 4: caged" -#define PHUSTR_5 "level 5: ghost town" -#define PHUSTR_6 "level 6: baron's lair" -#define PHUSTR_7 "level 7: caughtyard" -#define PHUSTR_8 "level 8: realm" -#define PHUSTR_9 "level 9: abattoire" -#define PHUSTR_10 "level 10: onslaught" -#define PHUSTR_11 "level 11: hunted" - -#define PHUSTR_12 "level 12: speed" -#define PHUSTR_13 "level 13: the crypt" -#define PHUSTR_14 "level 14: genesis" -#define PHUSTR_15 "level 15: the twilight" -#define PHUSTR_16 "level 16: the omen" -#define PHUSTR_17 "level 17: compound" -#define PHUSTR_18 "level 18: neurosphere" -#define PHUSTR_19 "level 19: nme" -#define PHUSTR_20 "level 20: the death domain" - -#define PHUSTR_21 "level 21: slayer" -#define PHUSTR_22 "level 22: impossible mission" -#define PHUSTR_23 "level 23: tombstone" -#define PHUSTR_24 "level 24: the final frontier" -#define PHUSTR_25 "level 25: the temple of darkness" -#define PHUSTR_26 "level 26: bunker" -#define PHUSTR_27 "level 27: anti-christ" -#define PHUSTR_28 "level 28: the sewers" -#define PHUSTR_29 "level 29: odyssey of noises" -#define PHUSTR_30 "level 30: the gateway of hell" - -#define PHUSTR_31 "level 31: cyberden" -#define PHUSTR_32 "level 32: go 2 it" - -#define THUSTR_1 "level 1: system control" -#define THUSTR_2 "level 2: human bbq" -#define THUSTR_3 "level 3: power control" -#define THUSTR_4 "level 4: wormhole" -#define THUSTR_5 "level 5: hanger" -#define THUSTR_6 "level 6: open season" -#define THUSTR_7 "level 7: prison" -#define THUSTR_8 "level 8: metal" -#define THUSTR_9 "level 9: stronghold" -#define THUSTR_10 "level 10: redemption" -#define THUSTR_11 "level 11: storage facility" - -#define THUSTR_12 "level 12: crater" -#define THUSTR_13 "level 13: nukage processing" -#define THUSTR_14 "level 14: steel works" -#define THUSTR_15 "level 15: dead zone" -#define THUSTR_16 "level 16: deepest reaches" -#define THUSTR_17 "level 17: processing area" -#define THUSTR_18 "level 18: mill" -#define THUSTR_19 "level 19: shipping/respawning" -#define THUSTR_20 "level 20: central processing" - -#define THUSTR_21 "level 21: administration center" -#define THUSTR_22 "level 22: habitat" -#define THUSTR_23 "level 23: lunar mining project" -#define THUSTR_24 "level 24: quarry" -#define THUSTR_25 "level 25: baron's den" -#define THUSTR_26 "level 26: ballistyx" -#define THUSTR_27 "level 27: mount pain" -#define THUSTR_28 "level 28: heck" -#define THUSTR_29 "level 29: river styx" -#define THUSTR_30 "level 30: last call" - -#define THUSTR_31 "level 31: pharaoh" -#define THUSTR_32 "level 32: caribbean" - -#define HUSTR_CHATMACRO1 "I'm ready to kick butt!" -#define HUSTR_CHATMACRO2 "I'm OK." -#define HUSTR_CHATMACRO3 "I'm not looking too good!" -#define HUSTR_CHATMACRO4 "Help!" -#define HUSTR_CHATMACRO5 "You suck!" -#define HUSTR_CHATMACRO6 "Next time, scumbag..." -#define HUSTR_CHATMACRO7 "Come here!" -#define HUSTR_CHATMACRO8 "I'll take care of it." -#define HUSTR_CHATMACRO9 "Yes" -#define HUSTR_CHATMACRO0 "No" - -#define HUSTR_TALKTOSELF1 "You mumble to yourself" -#define HUSTR_TALKTOSELF2 "Who's there?" -#define HUSTR_TALKTOSELF3 "You scare yourself" -#define HUSTR_TALKTOSELF4 "You start to rave" -#define HUSTR_TALKTOSELF5 "You've lost it..." - -#define HUSTR_MESSAGESENT "[Message Sent]" - -/* The following should NOT be changed unless it seems just AWFULLY - * necessary - */ - -#define HUSTR_PLRGREEN "Green: " -#define HUSTR_PLRINDIGO "Indigo: " -#define HUSTR_PLRBROWN "Brown: " -#define HUSTR_PLRRED "Red: " - -#define HUSTR_KEYGREEN 'g' -#define HUSTR_KEYINDIGO 'i' -#define HUSTR_KEYBROWN 'b' -#define HUSTR_KEYRED 'r' - -/* AM_map.C */ - -#define AMSTR_FOLLOWON "Follow Mode ON" -#define AMSTR_FOLLOWOFF "Follow Mode OFF" - -#define AMSTR_GRIDON "Grid ON" -#define AMSTR_GRIDOFF "Grid OFF" - -#define AMSTR_MARKEDSPOT "Marked Spot" -#define AMSTR_MARKSCLEARED "All Marks Cleared" - -/* ST_stuff.C */ - -#define STSTR_MUS "Music Change" -#define STSTR_NOMUS "IMPOSSIBLE SELECTION" -#define STSTR_DQDON "Degreelessness Mode On" -#define STSTR_DQDOFF "Degreelessness Mode Off" - -#define STSTR_KFAADDED "Very Happy Ammo Added" -#define STSTR_FAADDED "Ammo (no keys) Added" - -#define STSTR_NCON "No Clipping Mode ON" -#define STSTR_NCOFF "No Clipping Mode OFF" - -#define STSTR_BEHOLD "inVuln, Str, Inviso, Rad, Allmap, or Lite-amp" -#define STSTR_BEHOLDX "Power-up Toggled" - -#define STSTR_CHOPPERS "... doesn't suck - GM" -#define STSTR_CLEV "Changing Level..." - -/* F_Finale.C */ - -#define E1TEXT \ - "Once you beat the big badasses and\n" \ - "clean out the moon base you're supposed\n" \ - "to win, aren't you? Aren't you? Where's\n" \ - "your fat reward and ticket home? What\n" \ - "the hell is this? It's not supposed to\n" \ - "end this way!\n" \ - "\n" \ - "It stinks like rotten meat, but looks\n" \ - "like the lost Deimos base. Looks like\n" \ - "you're stuck on The Shores of Hell.\n" \ - "The only way out is through.\n" \ - "\n" \ - "To continue the DOOM experience, play\n" \ - "The Shores of Hell and its amazing\n" \ - "sequel, Inferno!\n" - -#define E2TEXT \ - "You've done it! The hideous cyber-\n" \ - "demon lord that ruled the lost Deimos\n" \ - "moon base has been slain and you\n" \ - "are triumphant! But ... where are\n" \ - "you? You clamber to the edge of the\n" \ - "moon and look down to see the awful\n" \ - "truth.\n" \ - "\n" \ - "Deimos floats above Hell itself!\n" \ - "You've never heard of anyone escaping\n" \ - "from Hell, but you'll make the bastards\n" \ - "sorry they ever heard of you! Quickly,\n" \ - "you rappel down to the surface of\n" \ - "Hell.\n" \ - "\n" \ - "Now, it's on to the final chapter of\n" \ - "DOOM! -- Inferno." - -#define E3TEXT \ - "The loathsome spiderdemon that\n" \ - "masterminded the invasion of the moon\n" \ - "bases and caused so much death has had\n" \ - "its ass kicked for all time.\n" \ - "\n" \ - "A hidden doorway opens and you enter.\n" \ - "You've proven too tough for Hell to\n" \ - "contain, and now Hell at last plays\n" \ - "fair -- for you emerge from the door\n" \ - "to see the green fields of Earth!\n" \ - "Home at last.\n" \ - "\n" \ - "You wonder what's been happening on\n" \ - "Earth while you were battling evil\n" \ - "unleashed. It's good that no Hell-\n" \ - "spawn could have come through that\n" \ - "door with you ..." - -#define E4TEXT \ - "the spider mastermind must have sent forth\n" \ - "its legions of hellspawn before your\n" \ - "final confrontation with that terrible\n" \ - "beast from hell. but you stepped forward\n" \ - "and brought forth eternal damnation and\n" \ - "suffering upon the horde as a true hero\n" \ - "would in the face of something so evil.\n" \ - "\n" \ - "besides, someone was gonna pay for what\n" \ - "happened to daisy, your pet rabbit.\n" \ - "\n" \ - "but now, you see spread before you more\n" \ - "potential pain and gibbitude as a nation\n" \ - "of demons run amok among our cities.\n" \ - "\n" \ - "next stop, hell on earth!" - -/* after level 6, put this: */ - -#define C1TEXT \ - "YOU HAVE ENTERED DEEPLY INTO THE INFESTED\n" \ - "STARPORT. BUT SOMETHING IS WRONG. THE\n" \ - "MONSTERS HAVE BROUGHT THEIR OWN REALITY\n" \ - "WITH THEM, AND THE STARPORT'S TECHNOLOGY\n" \ - "IS BEING SUBVERTED BY THEIR PRESENCE.\n" \ - "\n" \ - "AHEAD, YOU SEE AN OUTPOST OF HELL, A\n" \ - "FORTIFIED ZONE. IF YOU CAN GET PAST IT,\n" \ - "YOU CAN PENETRATE INTO THE HAUNTED HEART\n" \ - "OF THE STARBASE AND FIND THE CONTROLLING\n" \ - "SWITCH WHICH HOLDS EARTH'S POPULATION\n" \ - "HOSTAGE." - -/* After level 11, put this: */ - -#define C2TEXT \ - "YOU HAVE WON! YOUR VICTORY HAS ENABLED\n" \ - "HUMANKIND TO EVACUATE EARTH AND ESCAPE\n" \ - "THE NIGHTMARE. NOW YOU ARE THE ONLY\n" \ - "HUMAN LEFT ON THE FACE OF THE PLANET.\n" \ - "CANNIBAL MUTATIONS, CARNIVOROUS ALIENS,\n" \ - "AND EVIL SPIRITS ARE YOUR ONLY NEIGHBORS.\n" \ - "YOU SIT BACK AND WAIT FOR DEATH, CONTENT\n" \ - "THAT YOU HAVE SAVED YOUR SPECIES.\n" \ - "\n" \ - "BUT THEN, EARTH CONTROL BEAMS DOWN A\n" \ - "MESSAGE FROM SPACE: \"SENSORS HAVE LOCATED\n" \ - "THE SOURCE OF THE ALIEN INVASION. IF YOU\n" \ - "GO THERE, YOU MAY BE ABLE TO BLOCK THEIR\n" \ - "ENTRY. THE ALIEN BASE IS IN THE HEART OF\n" \ - "YOUR OWN HOME CITY, NOT FAR FROM THE\n" \ - "STARPORT.\" SLOWLY AND PAINFULLY YOU GET\n" \ - "UP AND RETURN TO THE FRAY." - -/* After level 20, put this: */ - -#define C3TEXT \ - "YOU ARE AT THE CORRUPT HEART OF THE CITY,\n" \ - "SURROUNDED BY THE CORPSES OF YOUR ENEMIES.\n" \ - "YOU SEE NO WAY TO DESTROY THE CREATURES'\n" \ - "ENTRYWAY ON THIS SIDE, SO YOU CLENCH YOUR\n" \ - "TEETH AND PLUNGE THROUGH IT.\n" \ - "\n" \ - "THERE MUST BE A WAY TO CLOSE IT ON THE\n" \ - "OTHER SIDE. WHAT DO YOU CARE IF YOU'VE\n" \ - "GOT TO GO THROUGH HELL TO GET TO IT?" - -/* After level 29, put this: */ - -#define C4TEXT \ - "THE HORRENDOUS VISAGE OF THE BIGGEST\n" \ - "DEMON YOU'VE EVER SEEN CRUMBLES BEFORE\n" \ - "YOU, AFTER YOU PUMP YOUR ROCKETS INTO\n" \ - "HIS EXPOSED BRAIN. THE MONSTER SHRIVELS\n" \ - "UP AND DIES, ITS THRASHING LIMBS\n" \ - "DEVASTATING UNTOLD MILES OF HELL'S\n" \ - "SURFACE.\n" \ - "\n" \ - "YOU'VE DONE IT. THE INVASION IS OVER.\n" \ - "EARTH IS SAVED. HELL IS A WRECK. YOU\n" \ - "WONDER WHERE BAD FOLKS WILL GO WHEN THEY\n" \ - "DIE, NOW. WIPING THE SWEAT FROM YOUR\n" \ - "FOREHEAD YOU BEGIN THE LONG TREK BACK\n" \ - "HOME. REBUILDING EARTH OUGHT TO BE A\n" \ - "LOT MORE FUN THAN RUINING IT WAS.\n" - -/* Before level 31, put this: */ - -#define C5TEXT \ - "CONGRATULATIONS, YOU'VE FOUND THE SECRET\n" \ - "LEVEL! LOOKS LIKE IT'S BEEN BUILT BY\n" \ - "HUMANS, RATHER THAN DEMONS. YOU WONDER\n" \ - "WHO THE INMATES OF THIS CORNER OF HELL\n" \ - "WILL BE." - -/* Before level 32, put this: */ - -#define C6TEXT \ - "CONGRATULATIONS, YOU'VE FOUND THE\n" \ - "SUPER SECRET LEVEL! YOU'D BETTER\n" \ - "BLAZE THROUGH THIS ONE!\n" - -/* after map 06 */ - -#define P1TEXT \ - "You gloat over the steaming carcass of the\n" \ - "Guardian. With its death, you've wrested\n" \ - "the Accelerator from the stinking claws\n" \ - "of Hell. You relax and glance around the\n" \ - "room. Damn! There was supposed to be at\n" \ - "least one working prototype, but you can't\n" \ - "see it. The demons must have taken it.\n" \ - "\n" \ - "You must find the prototype, or all your\n" \ - "struggles will have been wasted. Keep\n" \ - "moving, keep fighting, keep killing.\n" \ - "Oh yes, keep living, too." - -/* after map 11 */ - -#define P2TEXT \ - "Even the deadly Arch-Vile labyrinth could\n" \ - "not stop you, and you've gotten to the\n" \ - "prototype Accelerator which is soon\n" \ - "efficiently and permanently deactivated.\n" \ - "\n" \ - "You're good at that kind of thing." - -/* after map 20 */ - -#define P3TEXT \ - "You've bashed and battered your way into\n" \ - "the heart of the devil-hive. Time for a\n" \ - "Search-and-Destroy mission, aimed at the\n" \ - "Gatekeeper, whose foul offspring is\n" \ - "cascading to Earth. Yeah, he's bad. But\n" \ - "you know who's worse!\n" \ - "\n" \ - "Grinning evilly, you check your gear, and\n" \ - "get ready to give the bastard a little Hell\n" \ - "of your own making!" - -/* after map 30 */ - -#define P4TEXT \ - "The Gatekeeper's evil face is splattered\n" \ - "all over the place. As its tattered corpse\n" \ - "collapses, an inverted Gate forms and\n" \ - "sucks down the shards of the last\n" \ - "prototype Accelerator, not to mention the\n" \ - "few remaining demons. You're done. Hell\n" \ - "has gone back to pounding bad dead folks \n" \ - "instead of good live ones. Remember to\n" \ - "tell your grandkids to put a rocket\n" \ - "launcher in your coffin. If you go to Hell\n" \ - "when you die, you'll need it for some\n" \ - "final cleaning-up ..." - -/* before map 31 */ - -#define P5TEXT \ - "You've found the second-hardest level we\n" \ - "got. Hope you have a saved game a level or\n" \ - "two previous. If not, be prepared to die\n" \ - "aplenty. For master marines only." - -/* before map 32 */ - -#define P6TEXT \ - "Betcha wondered just what WAS the hardest\n" \ - "level we had ready for ya? Now you know.\n" \ - "No one gets out alive." - -#define T1TEXT \ - "You've fought your way out of the infested\n" \ - "experimental labs. It seems that UAC has\n" \ - "once again gulped it down. With their\n" \ - "high turnover, it must be hard for poor\n" \ - "old UAC to buy corporate health insurance\n" \ - "nowadays..\n" \ - "\n" \ - "Ahead lies the military complex, now\n" \ - "swarming with diseased horrors hot to get\n" \ - "their teeth into you. With luck, the\n" \ - "complex still has some warlike ordnance\n" \ - "laying around." - -#define T2TEXT \ - "You hear the grinding of heavy machinery\n" \ - "ahead. You sure hope they're not stamping\n" \ - "out new hellspawn, but you're ready to\n" \ - "ream out a whole herd if you have to.\n" \ - "They might be planning a blood feast, but\n" \ - "you feel about as mean as two thousand\n" \ - "maniacs packed into one mad killer.\n" \ - "\n" \ - "You don't plan to go down easy." - -#define T3TEXT \ - "The vista opening ahead looks real damn\n" \ - "familiar. Smells familiar, too -- like\n" \ - "fried excrement. You didn't like this\n" \ - "place before, and you sure as hell ain't\n" \ - "planning to like it now. The more you\n" \ - "brood on it, the madder you get.\n" \ - "Hefting your gun, an evil grin trickles\n" \ - "onto your face. Time to take some names." - -#define T4TEXT \ - "Suddenly, all is silent, from one horizon\n" \ - "to the other. The agonizing echo of Hell\n" \ - "fades away, the nightmare sky turns to\n" \ - "blue, the heaps of monster corpses start \n" \ - "to evaporate along with the evil stench \n" \ - "that filled the air. Jeeze, maybe you've\n" \ - "done it. Have you really won?\n" \ - "\n" \ - "Something rumbles in the distance.\n" \ - "A blue light begins to glow inside the\n" \ - "ruined skull of the demon-spitter." - -#define T5TEXT \ - "What now? Looks totally different. Kind\n" \ - "of like King Tut's condo. Well,\n" \ - "whatever's here can't be any worse\n" \ - "than usual. Can it? Or maybe it's best\n" \ - "to let sleeping gods lie.." - -#define T6TEXT \ - "Time for a vacation. You've burst the\n" \ - "bowels of hell and by golly you're ready\n" \ - "for a break. You mutter to yourself,\n" \ - "Maybe someone else can kick Hell's ass\n" \ - "next time around. Ahead lies a quiet town,\n" \ - "with peaceful flowing water, quaint\n" \ - "buildings, and presumably no Hellspawn.\n" \ - "\n" \ - "As you step off the transport, you hear\n" \ - "the stomp of a cyberdemon's iron shoe." - -/* Character cast strings F_FINALE.C */ - -#define CC_ZOMBIE "ZOMBIEMAN" -#define CC_SHOTGUN "SHOTGUN GUY" -#define CC_HEAVY "HEAVY WEAPON DUDE" -#define CC_IMP "IMP" -#define CC_DEMON "DEMON" -#define CC_LOST "LOST SOUL" -#define CC_CACO "CACODEMON" -#define CC_HELL "HELL KNIGHT" -#define CC_BARON "BARON OF HELL" -#define CC_ARACH "ARACHNOTRON" -#define CC_PAIN "PAIN ELEMENTAL" -#define CC_REVEN "REVENANT" -#define CC_MANCU "MANCUBUS" -#define CC_ARCH "ARCH-VILE" -#define CC_SPIDER "THE SPIDER MASTERMIND" -#define CC_CYBER "THE CYBERDEMON" -#define CC_HERO "OUR HERO" - -/* DOOM end messages */ - -#define DOOM1_ENDMSG \ - "are you sure you want to\nquit this great game?", \ - "please don't leave, there's more\ndemons to toast!", \ - "let's beat it -- this is turning\ninto a bloodbath!", \ - "i wouldn't leave if i were you.\ndos is much worse.", \ - "you're trying to say you like dos\nbetter than me, right?", \ - "don't leave yet -- there's a\ndemon around that corner!", \ - "ya know, next time you come in here\ni'm gonna toast ya.", \ - "go ahead and leave. see if i care.", - -/* QuitDOOM II messages */ - -#define DOOM2_ENDMSG \ - "are you sure you want to\nquit this great game?", \ - "you want to quit?\nthen, thou hast lost an eighth!", \ - "don't go now, there's a \ndimensional shambler waiting\nat the dos " \ - "prompt!", \ - "get outta here and go back\nto your boring programs.", \ - "if i were your boss, i'd \n deathmatch ya in a minute!", \ - "look, bud. you leave now\nand you forfeit your body count!", \ - "just leave. when you come\nback, i'll be waiting with a bat.", \ - "you're lucky i don't smack\nyou for thinking about leaving.", - -#endif /* __D_ENGLSH__ */ diff --git a/games/NXDoom/src/doom/d_french.h b/games/NXDoom/src/doom/d_french.h deleted file mode 100644 index 0252aa747..000000000 --- a/games/NXDoom/src/doom/d_french.h +++ /dev/null @@ -1,698 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/d_french.h - * - * SPDX-License-Identifier: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Printed strings for translation. - * French language support. - * TODO: finish implementation - * WARN: Non-ascii text does not render properly. Find a solution or cope. - * - ****************************************************************************/ - -#ifndef __D_FRENCH__ -#define __D_FRENCH__ - -/* Printed strings for translation */ - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* D_Main.C */ - -#define D_DEVSTR "Mode dรฉveloppement activรฉ.\n" -#define D_CDROM "Version CD-ROM: default.cfg de c:\\doomdata\n" - -/* M_Menu.C */ - -#define PRESSKEY "appuie une touche." -#define PRESSYN "appuie y ou n." -#define QUITMSG "es-tu certain que tu veux quitter ce super jeu ?" -#define LOADNET "tu ne peux pas charger pendant un jeu en ligne!\n\n" PRESSKEY -#define QLOADNET \ - "tu ne peux pas charger rapidement pendant un jeu en ligne!\n\n" PRESSKEY -#define QSAVESPOT "tu n'as pas choisi un slot sauvegarde rapide\n\n" PRESSKEY -#define SAVEDEAD "tu ne peux pas sauvegarder si tu ne joue pas\n\n" PRESSKEY -#define QSPROMPT "sauvegarde ton jeu nommรฉ\n\n'%s'?\n\n" PRESSYN -#define QLPROMPT \ - "tu veux charger rapidement le jeu nommรฉ\n\n'%s'?\n\n" PRESSYN - -#define NEWGAME \ - "tu ne peux pas commencer un nouveau jeu\n" \ - "durant un jeu en ligne.\n\n" PRESSKEY - -#define NIGHTMARE \ - "es-tu sure? ce niveau\n" \ - "n'est absolument pas juste.\n\n" PRESSYN - -#define SWSTRING \ - "ceci est le version shareware de doom.\n\n" \ - "tu besoin de commander la trilogie entiere.\n\n" PRESSKEY - -#define MSGOFF "Messages Dร‰SACTIVร‰S" -#define MSGON "Messages ACTIVร‰S" -#define NETEND "tu ne peux pas quitter un jeu en ligne!\n\n" PRESSKEY -#define ENDGAME "es-tu sure que tu veux quitter le jeu?\n\n" PRESSYN - -#define DOSY "(appuie y pour quitter vers dos.)" - -#define DETAILHI "Haute dรฉfinition" -#define DETAILLO "Faible dรฉfinition" -#define GAMMALVL0 "Correction gamma Dร‰SACTIVร‰" -#define GAMMALVL1 "Correction gamma niveau 1" -#define GAMMALVL2 "Correction gamma niveau 2" -#define GAMMALVL3 "Correction gamma niveau 3" -#define GAMMALVL4 "Correction gamma niveau 4" -#define EMPTYSTRING "slot vide" - -/* P_inter.C */ - -#define GOTARMOR "Ramassรฉ l'armure." -#define GOTMEGA "Ramassรฉ le Mega Armure!" -#define GOTHTHBONUS "Ramassรฉ un bonus de santรฉ." -#define GOTARMBONUS "Ramassรฉ un bonus d'armure." -#define GOTSTIM "Ramassรฉ un stimpack." -#define GOTMEDINEED "Ramassรฉ un medikit que tu as VRAIMENT besoin!" -#define GOTMEDIKIT "Ramassรฉ un medikit." -#define GOTSUPER "Superchargรฉ!" - -#define GOTBLUECARD "Ramassรฉ une carte d'accรจs bleue." -#define GOTYELWCARD "Ramassรฉ une carte d'accรจs jaune." -#define GOTREDCARD "Ramassรฉ une carte d'accรจs rouge." -#define GOTBLUESKUL "Ramassรฉ une clรฉ crรขne bleue." -#define GOTYELWSKUL "Ramassรฉ une clรฉ crรขne jaune." -#define GOTREDSKULL "Ramassรฉ une clรฉ crรขne rouge." - -#define GOTINVUL "Invulnรฉrabilitรฉ!" -#define GOTBERSERK "Berserk!" -#define GOTINVIS "Invisibilitรฉ Partielle" -#define GOTSUIT "Radiation Shielding Suit" // TODO? -#define GOTMAP "Carte de la Zone Informatique" -#define GOTVISOR "Light Amplification Visor" // TODO? -#define GOTMSPHERE "MegaSphere!" - -#define GOTCLIP "Ramassรฉ un clip." -#define GOTCLIPBOX "Ramassรฉ une boรฎte de balles." -#define GOTROCKET "Ramassรฉ une fusรฉe." -#define GOTROCKBOX "Ramassรฉ une boรฎte de fusรฉes." -#define GOTCELL "Ramassรฉ une cellule รฉnergรฉtique." -#define GOTCELLBOX "Ramassรฉ un paquet de cellules รฉnergรฉtiques." -#define GOTSHELLS "Ramassรฉ 4 cartouches de fusil de chasse." -#define GOTSHELLBOX "Ramassรฉ une boรฎte de cartouches de fusil de chasse." -#define GOTBACKPACK "Ramassรฉ une sac ร  dos plein d'ammo!" - -#define GOTBFG9000 "Tu as eu le BFG9000! Hohoho, oui!" -#define GOTCHAINGUN "Tu as eu le chaingun!" -#define GOTCHAINSAW "Un scie ร  chaรฎne! Trouve de la viande!" -#define GOTLAUNCHER "Tu as eu la lance-roquettes!" -#define GOTPLASMA "Tu as eu le pistolet ร  plasma!" -#define GOTSHOTGUN "Tu as eu le fusil de chasse!" -#define GOTSHOTGUN2 "Tu as eu le super fusil de chasse!" - -/* P_Doors.C */ - -#define PD_BLUEO "You need a blue key to activate this object" -#define PD_REDO "You need a red key to activate this object" -#define PD_YELLOWO "You need a yellow key to activate this object" -#define PD_BLUEK "You need a blue key to open this door" -#define PD_REDK "You need a red key to open this door" -#define PD_YELLOWK "You need a yellow key to open this door" - -/* G_game.C */ - -#define GGSAVED "game saved." - -/* HU_stuff.C */ - -#define HUSTR_MSGU "[Message unsent]" - -#define HUSTR_E1M1 "E1M1: Hangar" -#define HUSTR_E1M2 "E1M2: Nuclear Plant" -#define HUSTR_E1M3 "E1M3: Toxin Refinery" -#define HUSTR_E1M4 "E1M4: Command Control" -#define HUSTR_E1M5 "E1M5: Phobos Lab" -#define HUSTR_E1M6 "E1M6: Central Processing" -#define HUSTR_E1M7 "E1M7: Computer Station" -#define HUSTR_E1M8 "E1M8: Phobos Anomaly" -#define HUSTR_E1M9 "E1M9: Military Base" - -#define HUSTR_E2M1 "E2M1: Deimos Anomaly" -#define HUSTR_E2M2 "E2M2: Containment Area" -#define HUSTR_E2M3 "E2M3: Refinery" -#define HUSTR_E2M4 "E2M4: Deimos Lab" -#define HUSTR_E2M5 "E2M5: Command Center" -#define HUSTR_E2M6 "E2M6: Halls of the Damned" -#define HUSTR_E2M7 "E2M7: Spawning Vats" -#define HUSTR_E2M8 "E2M8: Tower of Babel" -#define HUSTR_E2M9 "E2M9: Fortress of Mystery" - -#define HUSTR_E3M1 "E3M1: Hell Keep" -#define HUSTR_E3M2 "E3M2: Slough of Despair" -#define HUSTR_E3M3 "E3M3: Pandemonium" -#define HUSTR_E3M4 "E3M4: House of Pain" -#define HUSTR_E3M5 "E3M5: Unholy Cathedral" -#define HUSTR_E3M6 "E3M6: Mt. Erebus" -#define HUSTR_E3M7 "E3M7: Limbo" -#define HUSTR_E3M8 "E3M8: Dis" -#define HUSTR_E3M9 "E3M9: Warrens" - -#define HUSTR_E4M1 "E4M1: Hell Beneath" -#define HUSTR_E4M2 "E4M2: Perfect Hatred" -#define HUSTR_E4M3 "E4M3: Sever The Wicked" -#define HUSTR_E4M4 "E4M4: Unruly Evil" -#define HUSTR_E4M5 "E4M5: They Will Repent" -#define HUSTR_E4M6 "E4M6: Against Thee Wickedly" -#define HUSTR_E4M7 "E4M7: And Hell Followed" -#define HUSTR_E4M8 "E4M8: Unto The Cruel" -#define HUSTR_E4M9 "E4M9: Fear" - -#define HUSTR_1 "niveau 1: entryway" -#define HUSTR_2 "niveau 2: underhalls" -#define HUSTR_3 "niveau 3: the gantlet" -#define HUSTR_4 "niveau 4: the focus" -#define HUSTR_5 "niveau 5: the waste tunnels" -#define HUSTR_6 "niveau 6: the crusher" -#define HUSTR_7 "niveau 7: dead simple" -#define HUSTR_8 "niveau 8: tricks and traps" -#define HUSTR_9 "niveau 9: the pit" -#define HUSTR_10 "niveau 10: refueling base" -#define HUSTR_11 "niveau 11: 'o' of destruction!" - -#define HUSTR_12 "niveau 12: the factory" -#define HUSTR_13 "niveau 13: downtown" -#define HUSTR_14 "niveau 14: the inmost dens" -#define HUSTR_15 "niveau 15: industrial zone" -#define HUSTR_16 "niveau 16: suburbs" -#define HUSTR_17 "niveau 17: tenements" -#define HUSTR_18 "niveau 18: the courtyard" -#define HUSTR_19 "niveau 19: the citadel" -#define HUSTR_20 "niveau 20: gotcha!" - -#define HUSTR_21 "niveau 21: nirvana" -#define HUSTR_22 "niveau 22: the catacombs" -#define HUSTR_23 "niveau 23: barrels o' fun" -#define HUSTR_24 "niveau 24: the chasm" -#define HUSTR_25 "niveau 25: bloodfalls" -#define HUSTR_26 "niveau 26: the abandoned mines" -#define HUSTR_27 "niveau 27: monster condo" -#define HUSTR_28 "niveau 28: the spirit world" -#define HUSTR_29 "niveau 29: the living end" -#define HUSTR_30 "niveau 30: icon of sin" - -#define HUSTR_31 "niveau 31: wolfenstein" -#define HUSTR_32 "niveau 32: grosse" - -#define PHUSTR_1 "niveau 1: congo" -#define PHUSTR_2 "niveau 2: well of souls" -#define PHUSTR_3 "niveau 3: aztec" -#define PHUSTR_4 "niveau 4: caged" -#define PHUSTR_5 "niveau 5: ghost town" -#define PHUSTR_6 "niveau 6: baron's lair" -#define PHUSTR_7 "niveau 7: caughtyard" -#define PHUSTR_8 "niveau 8: realm" -#define PHUSTR_9 "niveau 9: abattoire" -#define PHUSTR_10 "niveau 10: onslaught" -#define PHUSTR_11 "niveau 11: hunted" - -#define PHUSTR_12 "niveau 12: speed" -#define PHUSTR_13 "niveau 13: the crypt" -#define PHUSTR_14 "niveau 14: genesis" -#define PHUSTR_15 "niveau 15: the twilight" -#define PHUSTR_16 "niveau 16: the omen" -#define PHUSTR_17 "niveau 17: compound" -#define PHUSTR_18 "niveau 18: neurosphere" -#define PHUSTR_19 "niveau 19: nme" -#define PHUSTR_20 "niveau 20: the death domain" - -#define PHUSTR_21 "niveau 21: slayer" -#define PHUSTR_22 "niveau 22: impossible mission" -#define PHUSTR_23 "niveau 23: tombstone" -#define PHUSTR_24 "niveau 24: the final frontier" -#define PHUSTR_25 "niveau 25: the temple of darkness" -#define PHUSTR_26 "niveau 26: bunker" -#define PHUSTR_27 "niveau 27: anti-christ" -#define PHUSTR_28 "niveau 28: the sewers" -#define PHUSTR_29 "niveau 29: odyssey of noises" -#define PHUSTR_30 "niveau 30: the gateway of hell" - -#define PHUSTR_31 "niveau 31: cyberden" -#define PHUSTR_32 "niveau 32: go 2 it" - -#define THUSTR_1 "niveau 1: system control" -#define THUSTR_2 "niveau 2: human bbq" -#define THUSTR_3 "niveau 3: power control" -#define THUSTR_4 "niveau 4: wormhole" -#define THUSTR_5 "niveau 5: hanger" -#define THUSTR_6 "niveau 6: open season" -#define THUSTR_7 "niveau 7: prison" -#define THUSTR_8 "niveau 8: metal" -#define THUSTR_9 "niveau 9: stronghold" -#define THUSTR_10 "niveau 10: redemption" -#define THUSTR_11 "niveau 11: storage facility" - -#define THUSTR_12 "niveau 12: crater" -#define THUSTR_13 "niveau 13: nukage processing" -#define THUSTR_14 "niveau 14: steel works" -#define THUSTR_15 "niveau 15: dead zone" -#define THUSTR_16 "niveau 16: deepest reaches" -#define THUSTR_17 "niveau 17: processing area" -#define THUSTR_18 "niveau 18: mill" -#define THUSTR_19 "niveau 19: shipping/respawning" -#define THUSTR_20 "niveau 20: central processing" - -#define THUSTR_21 "niveau 21: administration center" -#define THUSTR_22 "niveau 22: habitat" -#define THUSTR_23 "niveau 23: lunar mining project" -#define THUSTR_24 "niveau 24: quarry" -#define THUSTR_25 "niveau 25: baron's den" -#define THUSTR_26 "niveau 26: ballistyx" -#define THUSTR_27 "niveau 27: mount pain" -#define THUSTR_28 "niveau 28: heck" -#define THUSTR_29 "niveau 29: river styx" -#define THUSTR_30 "niveau 30: last call" - -#define THUSTR_31 "niveau 31: pharaoh" -#define THUSTR_32 "niveau 32: caribbean" - -#define HUSTR_CHATMACRO1 "I'm ready to kick butt!" -#define HUSTR_CHATMACRO2 "I'm OK." -#define HUSTR_CHATMACRO3 "I'm not looking too good!" -#define HUSTR_CHATMACRO4 "Help!" -#define HUSTR_CHATMACRO5 "You suck!" -#define HUSTR_CHATMACRO6 "Next time, scumbag..." -#define HUSTR_CHATMACRO7 "Come here!" -#define HUSTR_CHATMACRO8 "I'll take care of it." -#define HUSTR_CHATMACRO9 "Oui" -#define HUSTR_CHATMACRO0 "Non" - -#define HUSTR_TALKTOSELF1 "You mumble to yourself" -#define HUSTR_TALKTOSELF2 "Who's there?" -#define HUSTR_TALKTOSELF3 "You scare yourself" -#define HUSTR_TALKTOSELF4 "You start to rave" -#define HUSTR_TALKTOSELF5 "You've lost it..." - -#define HUSTR_MESSAGESENT "[Message Sent]" - -/* The following should NOT be changed unless it seems just AWFULLY - * necessary - */ - -#define HUSTR_PLRGREEN "Vert: " -#define HUSTR_PLRINDIGO "Indigo: " -#define HUSTR_PLRBROWN "Brun: " -#define HUSTR_PLRRED "Rouge: " - -#define HUSTR_KEYGREEN 'g' -#define HUSTR_KEYINDIGO 'i' -#define HUSTR_KEYBROWN 'b' -#define HUSTR_KEYRED 'r' - -/* AM_map.C */ - -#define AMSTR_FOLLOWON "Follow Mode ON" -#define AMSTR_FOLLOWOFF "Follow Mode OFF" - -#define AMSTR_GRIDON "Grid ON" -#define AMSTR_GRIDOFF "Grid OFF" - -#define AMSTR_MARKEDSPOT "Marked Spot" -#define AMSTR_MARKSCLEARED "All Marks Cleared" - -/* ST_stuff.C */ - -#define STSTR_MUS "Music Change" -#define STSTR_NOMUS "IMPOSSIBLE SELECTION" -#define STSTR_DQDON "Degreelessness Mode On" -#define STSTR_DQDOFF "Degreelessness Mode Off" - -#define STSTR_KFAADDED "Very Happy Ammo Added" -#define STSTR_FAADDED "Ammo (no keys) Added" - -#define STSTR_NCON "No Clipping Mode ON" -#define STSTR_NCOFF "No Clipping Mode OFF" - -#define STSTR_BEHOLD "inVuln, Str, Inviso, Rad, Allmap, or Lite-amp" -#define STSTR_BEHOLDX "Power-up Toggled" - -#define STSTR_CHOPPERS "... doesn't suck - GM" -#define STSTR_CLEV "Changing Level..." - -/* F_Finale.C */ - -#define E1TEXT \ - "Once you beat the big badasses and\n" \ - "clean out the moon base you're supposed\n" \ - "to win, aren't you? Aren't you? Where's\n" \ - "your fat reward and ticket home? What\n" \ - "the hell is this? It's not supposed to\n" \ - "end this way!\n" \ - "\n" \ - "It stinks like rotten meat, but looks\n" \ - "like the lost Deimos base. Looks like\n" \ - "you're stuck on The Shores of Hell.\n" \ - "The only way out is through.\n" \ - "\n" \ - "To continue the DOOM experience, play\n" \ - "The Shores of Hell and its amazing\n" \ - "sequel, Inferno!\n" - -#define E2TEXT \ - "You've done it! The hideous cyber-\n" \ - "demon lord that ruled the lost Deimos\n" \ - "moon base has been slain and you\n" \ - "are triumphant! But ... where are\n" \ - "you? You clamber to the edge of the\n" \ - "moon and look down to see the awful\n" \ - "truth.\n" \ - "\n" \ - "Deimos floats above Hell itself!\n" \ - "You've never heard of anyone escaping\n" \ - "from Hell, but you'll make the bastards\n" \ - "sorry they ever heard of you! Quickly,\n" \ - "you rappel down to the surface of\n" \ - "Hell.\n" \ - "\n" \ - "Now, it's on to the final chapter of\n" \ - "DOOM! -- Inferno." - -#define E3TEXT \ - "The loathsome spiderdemon that\n" \ - "masterminded the invasion of the moon\n" \ - "bases and caused so much death has had\n" \ - "its ass kicked for all time.\n" \ - "\n" \ - "A hidden doorway opens and you enter.\n" \ - "You've proven too tough for Hell to\n" \ - "contain, and now Hell at last plays\n" \ - "fair -- for you emerge from the door\n" \ - "to see the green fields of Earth!\n" \ - "Home at last.\n" \ - "\n" \ - "You wonder what's been happening on\n" \ - "Earth while you were battling evil\n" \ - "unleashed. It's good that no Hell-\n" \ - "spawn could have come through that\n" \ - "door with you ..." - -#define E4TEXT \ - "the spider mastermind must have sent forth\n" \ - "its legions of hellspawn before your\n" \ - "final confrontation with that terrible\n" \ - "beast from hell. but you stepped forward\n" \ - "and brought forth eternal damnation and\n" \ - "suffering upon the horde as a true hero\n" \ - "would in the face of something so evil.\n" \ - "\n" \ - "besides, someone was gonna pay for what\n" \ - "happened to daisy, your pet rabbit.\n" \ - "\n" \ - "but now, you see spread before you more\n" \ - "potential pain and gibbitude as a nation\n" \ - "of demons run amok among our cities.\n" \ - "\n" \ - "next stop, hell on earth!" - -/* after niveau 6, put this: */ - -#define C1TEXT \ - "YOU HAVE ENTERED DEEPLY INTO THE INFESTED\n" \ - "STARPORT. BUT SOMETHING IS WRONG. THE\n" \ - "MONSTERS HAVE BROUGHT THEIR OWN REALITY\n" \ - "WITH THEM, AND THE STARPORT'S TECHNOLOGY\n" \ - "IS BEING SUBVERTED BY THEIR PRESENCE.\n" \ - "\n" \ - "AHEAD, YOU SEE AN OUTPOST OF HELL, A\n" \ - "FORTIFIED ZONE. IF YOU CAN GET PAST IT,\n" \ - "YOU CAN PENETRATE INTO THE HAUNTED HEART\n" \ - "OF THE STARBASE AND FIND THE CONTROLLING\n" \ - "SWITCH WHICH HOLDS EARTH'S POPULATION\n" \ - "HOSTAGE." - -/* After niveau 11, put this: */ - -#define C2TEXT \ - "YOU HAVE WON! YOUR VICTORY HAS ENABLED\n" \ - "HUMANKIND TO EVACUATE EARTH AND ESCAPE\n" \ - "THE NIGHTMARE. NOW YOU ARE THE ONLY\n" \ - "HUMAN LEFT ON THE FACE OF THE PLANET.\n" \ - "CANNIBAL MUTATIONS, CARNIVOROUS ALIENS,\n" \ - "AND EVIL SPIRITS ARE YOUR ONLY NEIGHBORS.\n" \ - "YOU SIT BACK AND WAIT FOR DEATH, CONTENT\n" \ - "THAT YOU HAVE SAVED YOUR SPECIES.\n" \ - "\n" \ - "BUT THEN, EARTH CONTROL BEAMS DOWN A\n" \ - "MESSAGE FROM SPACE: \"SENSORS HAVE LOCATED\n" \ - "THE SOURCE OF THE ALIEN INVASION. IF YOU\n" \ - "GO THERE, YOU MAY BE ABLE TO BLOCK THEIR\n" \ - "ENTRY. THE ALIEN BASE IS IN THE HEART OF\n" \ - "YOUR OWN HOME CITY, NOT FAR FROM THE\n" \ - "STARPORT.\" SLOWLY AND PAINFULLY YOU GET\n" \ - "UP AND RETURN TO THE FRAY." - -/* After niveau 20, put this: */ - -#define C3TEXT \ - "YOU ARE AT THE CORRUPT HEART OF THE CITY,\n" \ - "SURROUNDED BY THE CORPSES OF YOUR ENEMIES.\n" \ - "YOU SEE NO WAY TO DESTROY THE CREATURES'\n" \ - "ENTRYWAY ON THIS SIDE, SO YOU CLENCH YOUR\n" \ - "TEETH AND PLUNGE THROUGH IT.\n" \ - "\n" \ - "THERE MUST BE A WAY TO CLOSE IT ON THE\n" \ - "OTHER SIDE. WHAT DO YOU CARE IF YOU'VE\n" \ - "GOT TO GO THROUGH HELL TO GET TO IT?" - -/* After niveau 29, put this: */ - -#define C4TEXT \ - "THE HORRENDOUS VISAGE OF THE BIGGEST\n" \ - "DEMON YOU'VE EVER SEEN CRUMBLES BEFORE\n" \ - "YOU, AFTER YOU PUMP YOUR ROCKETS INTO\n" \ - "HIS EXPOSED BRAIN. THE MONSTER SHRIVELS\n" \ - "UP AND DIES, ITS THRASHING LIMBS\n" \ - "DEVASTATING UNTOLD MILES OF HELL'S\n" \ - "SURFACE.\n" \ - "\n" \ - "YOU'VE DONE IT. THE INVASION IS OVER.\n" \ - "EARTH IS SAVED. HELL IS A WRECK. YOU\n" \ - "WONDER WHERE BAD FOLKS WILL GO WHEN THEY\n" \ - "DIE, NOW. WIPING THE SWEAT FROM YOUR\n" \ - "FOREHEAD YOU BEGIN THE LONG TREK BACK\n" \ - "HOME. REBUILDING EARTH OUGHT TO BE A\n" \ - "LOT MORE FUN THAN RUINING IT WAS.\n" - -/* Before niveau 31, put this: */ - -#define C5TEXT \ - "CONGRATULATIONS, YOU'VE FOUND THE SECRET\n" \ - "LEVEL! LOOKS LIKE IT'S BEEN BUILT BY\n" \ - "HUMANS, RATHER THAN DEMONS. YOU WONDER\n" \ - "WHO THE INMATES OF THIS CORNER OF HELL\n" \ - "WILL BE." - -/* Before niveau 32, put this: */ - -#define C6TEXT \ - "CONGRATULATIONS, YOU'VE FOUND THE\n" \ - "SUPER SECRET LEVEL! YOU'D BETTER\n" \ - "BLAZE THROUGH THIS ONE!\n" - -/* after map 06 */ - -#define P1TEXT \ - "You gloat over the steaming carcass of the\n" \ - "Guardian. With its death, you've wrested\n" \ - "the Accelerator from the stinking claws\n" \ - "of Hell. You relax and glance around the\n" \ - "room. Damn! There was supposed to be at\n" \ - "least one working prototype, but you can't\n" \ - "see it. The demons must have taken it.\n" \ - "\n" \ - "You must find the prototype, or all your\n" \ - "struggles will have been wasted. Keep\n" \ - "moving, keep fighting, keep killing.\n" \ - "Oh yes, keep living, too." - -/* after map 11 */ - -#define P2TEXT \ - "Even the deadly Arch-Vile labyrinth could\n" \ - "not stop you, and you've gotten to the\n" \ - "prototype Accelerator which is soon\n" \ - "efficiently and permanently deactivated.\n" \ - "\n" \ - "You're good at that kind of thing." - -/* after map 20 */ - -#define P3TEXT \ - "You've bashed and battered your way into\n" \ - "the heart of the devil-hive. Time for a\n" \ - "Search-and-Destroy mission, aimed at the\n" \ - "Gatekeeper, whose foul offspring is\n" \ - "cascading to Earth. Yeah, he's bad. But\n" \ - "you know who's worse!\n" \ - "\n" \ - "Grinning evilly, you check your gear, and\n" \ - "get ready to give the bastard a little Hell\n" \ - "of your own making!" - -/* after map 30 */ - -#define P4TEXT \ - "The Gatekeeper's evil face is splattered\n" \ - "all over the place. As its tattered corpse\n" \ - "collapses, an inverted Gate forms and\n" \ - "sucks down the shards of the last\n" \ - "prototype Accelerator, not to mention the\n" \ - "few remaining demons. You're done. Hell\n" \ - "has gone back to pounding bad dead folks \n" \ - "instead of good live ones. Remember to\n" \ - "tell your grandkids to put a rocket\n" \ - "launcher in your coffin. If you go to Hell\n" \ - "when you die, you'll need it for some\n" \ - "final cleaning-up ..." - -/* before map 31 */ - -#define P5TEXT \ - "You've found the second-hardest niveau we\n" \ - "got. Hope you have a saved game a niveau or\n" \ - "two previous. If not, be prepared to die\n" \ - "aplenty. For master marines only." - -/* before map 32 */ - -#define P6TEXT \ - "Betcha wondered just what WAS the hardest\n" \ - "niveau we had ready for ya? Now you know.\n" \ - "No one gets out alive." - -#define T1TEXT \ - "You've fought your way out of the infested\n" \ - "experimental labs. It seems that UAC has\n" \ - "once again gulped it down. With their\n" \ - "high turnover, it must be hard for poor\n" \ - "old UAC to buy corporate health insurance\n" \ - "nowadays..\n" \ - "\n" \ - "Ahead lies the military complex, now\n" \ - "swarming with diseased horrors hot to get\n" \ - "their teeth into you. With luck, the\n" \ - "complex still has some warlike ordnance\n" \ - "laying around." - -#define T2TEXT \ - "You hear the grinding of heavy machinery\n" \ - "ahead. You sure hope they're not stamping\n" \ - "out new hellspawn, but you're ready to\n" \ - "ream out a whole herd if you have to.\n" \ - "They might be planning a blood feast, but\n" \ - "you feel about as mean as two thousand\n" \ - "maniacs packed into one mad killer.\n" \ - "\n" \ - "You don't plan to go down easy." - -#define T3TEXT \ - "The vista opening ahead looks real damn\n" \ - "familiar. Smells familiar, too -- like\n" \ - "fried excrement. You didn't like this\n" \ - "place before, and you sure as hell ain't\n" \ - "planning to like it now. The more you\n" \ - "brood on it, the madder you get.\n" \ - "Hefting your gun, an evil grin trickles\n" \ - "onto your face. Time to take some names." - -#define T4TEXT \ - "Suddenly, all is silent, from one horizon\n" \ - "to the other. The agonizing echo of Hell\n" \ - "fades away, the nightmare sky turns to\n" \ - "blue, the heaps of monster corpses start \n" \ - "to evaporate along with the evil stench \n" \ - "that filled the air. Jeeze, maybe you've\n" \ - "done it. Have you really won?\n" \ - "\n" \ - "Something rumbles in the distance.\n" \ - "A blue light begins to glow inside the\n" \ - "ruined skull of the demon-spitter." - -#define T5TEXT \ - "What now? Looks totally different. Kind\n" \ - "of like King Tut's condo. Well,\n" \ - "whatever's here can't be any worse\n" \ - "than usual. Can it? Or maybe it's best\n" \ - "to let sleeping gods lie.." - -#define T6TEXT \ - "Time for a vacation. You've burst the\n" \ - "bowels of hell and by golly you're ready\n" \ - "for a break. You mutter to yourself,\n" \ - "Maybe someone else can kick Hell's ass\n" \ - "next time around. Ahead lies a quiet town,\n" \ - "with peaceful flowing water, quaint\n" \ - "buildings, and presumably no Hellspawn.\n" \ - "\n" \ - "As you step off the transport, you hear\n" \ - "the stomp of a cyberdemon's iron shoe." - -/* Character cast strings F_FINALE.C */ - -#define CC_ZOMBIE "ZOMBIEMAN" -#define CC_SHOTGUN "SHOTGUN GUY" -#define CC_HEAVY "HEAVY WEAPON DUDE" -#define CC_IMP "IMP" -#define CC_DEMON "DEMON" -#define CC_LOST "LOST SOUL" -#define CC_CACO "CACODEMON" -#define CC_HELL "HELL KNIGHT" -#define CC_BARON "BARON OF HELL" -#define CC_ARACH "ARACHNOTRON" -#define CC_PAIN "PAIN ELEMENTAL" -#define CC_REVEN "REVENANT" -#define CC_MANCU "MANCUBUS" -#define CC_ARCH "ARCH-VILE" -#define CC_SPIDER "THE SPIDER MASTERMIND" -#define CC_CYBER "THE CYBERDEMON" -#define CC_HERO "OUR HERO" - -/* DOOM end messages */ - -#define DOOM1_ENDMSG \ - "are you sure you want to\nquit this great game?", \ - "please don't leave, there's more\ndemons to toast!", \ - "let's beat it -- this is turning\ninto a bloodbath!", \ - "i wouldn't leave if i were you.\ndos is much worse.", \ - "you're trying to say you like dos\nbetter than me, right?", \ - "don't leave yet -- there's a\ndemon around that corner!", \ - "ya know, next time you come in here\ni'm gonna toast ya.", \ - "go ahead and leave. see if i care.", - -/* QuitDOOM II messages */ - -#define DOOM2_ENDMSG \ - "are you sure you want to\nquit this great game?", \ - "you want to quit?\nthen, thou hast lost an eighth!", \ - "don't go now, there's a \ndimensional shambler waiting\nat the dos " \ - "prompt!", \ - "get outta here and go back\nto your boring programs.", \ - "if i were your boss, i'd \n deathmatch ya in a minute!", \ - "look, bud. you leave now\nand you forfeit your body count!", \ - "just leave. when you come\nback, i'll be waiting with a bat.", \ - "you're lucky i don't smack\nyou for thinking about leaving.", - -#endif /* __D_FRENCH__ */ diff --git a/games/NXDoom/src/doom/d_items.c b/games/NXDoom/src/doom/d_items.c deleted file mode 100644 index 8fc606b6c..000000000 --- a/games/NXDoom/src/doom/d_items.c +++ /dev/null @@ -1,143 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/d_items.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -/* We are referring to sprite numbers. */ - -#include "info.h" - -#include "d_items.h" - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/* PSPRITE ACTIONS for weapons. - * This struct controls the weapon animations. - * - * Each entry is: - * ammo/ammunition type - * upstate - * downstate - * readystate - * atkstate, i.e. attack/fire/hit frame - * flashstate, muzzle flash - */ - -weaponinfo_t weaponinfo[NUMWEAPONS] = -{ - { - /* fist */ - - am_noammo, - S_PUNCHUP, - S_PUNCHDOWN, - S_PUNCH, - S_PUNCH1, - S_NULL, - }, - { - /* pistol */ - - am_clip, - S_PISTOLUP, - S_PISTOLDOWN, - S_PISTOL, - S_PISTOL1, - S_PISTOLFLASH, - }, - { - /* shotgun */ - - am_shell, - S_SGUNUP, - S_SGUNDOWN, - S_SGUN, - S_SGUN1, - S_SGUNFLASH1, - }, - { - /* chaingun */ - - am_clip, - S_CHAINUP, - S_CHAINDOWN, - S_CHAIN, - S_CHAIN1, - S_CHAINFLASH1, - }, - { - /* missile launcher */ - - am_misl, - S_MISSILEUP, - S_MISSILEDOWN, - S_MISSILE, - S_MISSILE1, - S_MISSILEFLASH1, - }, - { - /* plasma rifle */ - - am_cell, - S_PLASMAUP, - S_PLASMADOWN, - S_PLASMA, - S_PLASMA1, - S_PLASMAFLASH1, - }, - { - /* bfg 9000 */ - - am_cell, - S_BFGUP, - S_BFGDOWN, - S_BFG, - S_BFG1, - S_BFGFLASH1, - }, - { - /* chainsaw */ - - am_noammo, - S_SAWUP, - S_SAWDOWN, - S_SAW, - S_SAW1, - S_NULL, - }, - { - /* super shotgun */ - - am_shell, - S_DSGUNUP, - S_DSGUNDOWN, - S_DSGUN, - S_DSGUN1, - S_DSGUNFLASH1, - }, -}; - -/**************************************************************************** - * Public Functions - ****************************************************************************/ diff --git a/games/NXDoom/src/doom/d_items.h b/games/NXDoom/src/doom/d_items.h deleted file mode 100644 index bcc50b9af..000000000 --- a/games/NXDoom/src/doom/d_items.h +++ /dev/null @@ -1,55 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/d_items.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Items: key cards, artifacts, weapon, ammunition. - * - ****************************************************************************/ - -#ifndef __D_ITEMS__ -#define __D_ITEMS__ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "doomdef.h" - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -/* Weapon info: sprite frames, ammunition use. */ - -typedef struct -{ - ammotype_t ammo; - int upstate; - int downstate; - int readystate; - int atkstate; - int flashstate; -} weaponinfo_t; - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -extern weaponinfo_t weaponinfo[NUMWEAPONS]; - -#endif /* __D_ITEMS__ */ diff --git a/games/NXDoom/src/doom/d_main.c b/games/NXDoom/src/doom/d_main.c deleted file mode 100644 index 52df6eda1..000000000 --- a/games/NXDoom/src/doom/d_main.c +++ /dev/null @@ -1,2184 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/d_main.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * DOOM main program (d_doom_main) and game loop (d_doomloop), - * plus functions to determine game mode (shareware, registered), - * parse command line parameters, configure game parameters (turbo), - * and call the startup functions. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include -#include - -#include "config.h" -#include "deh_main.h" -#include "doomdef.h" -#include "doomstat.h" - -#include "dstrings.h" - -#ifdef CONFIG_GAMES_NXDOOM_SOUND -#include "s_sound.h" -#include "sounds.h" -#endif - -#include "d_iwad.h" - -#include "v_diskicon.h" -#include "v_video.h" -#include "w_main.h" -#include "w_wad.h" -#include "z_zone.h" - -#include "f_finale.h" -#include "f_wipe.h" - -#include "m_argv.h" -#include "m_config.h" -#include "m_controls.h" -#include "m_menu.h" -#include "m_misc.h" -#include "p_saveg.h" - -#include "i_endoom.h" -#include "i_input.h" -#include "i_joystick.h" -#include "i_system.h" -#include "i_timer.h" -#include "i_video.h" - -#include "g_game.h" - -#include "am_map.h" -#include "hu_stuff.h" -#include "st_stuff.h" -#include "wi_stuff.h" - -#ifdef CONFIG_GAMES_NXDOOM_NET -#include "net_client.h" -#include "net_dedicated.h" -#include "net_query.h" -#endif - -#include "p_setup.h" -#include "r_local.h" -#include "statdump.h" - -#include "d_main.h" - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -struct pack -{ - const char *name; - int mission; -}; - -struct gameversion -{ - const char *description; - const char *cmdline; - game_version_t version; -}; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/* D-DoomLoop() - * - * Not a globally visible function, just included for source reference, - * called by d_doom_main, never exits. - * - * Manages timing and IO, calls all ?_Responder, ?_Ticker, and ?_Drawer, - * calls i_get_time, i_start_frame, and i_start_tic - */ - -void d_doomloop(void); - -void d_connect_net_game(void); -void d_check_net_game(void); - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/* Location where savegames are stored */ - -char *savegamedir; - -/* location of IWAD and WAD files */ - -char *iwadfile; - -boolean devparm; /* started game with -devparm */ -boolean nomonsters; /* checkparm of -nomonsters */ -boolean respawnparm; /* checkparm of -respawn */ -boolean fastparm; /* checkparm of -fast */ - -skill_t startskill; -int startepisode; -int startmap; -boolean autostart; -int startloadgame; - -boolean advancedemo; - -/* Store demo, do not accept any inputs */ - -boolean storedemo; - -/* If true, the main game loop has started. */ - -boolean main_loop_started = false; - -int show_endoom = 1; -int show_diskicon = 1; - -/* wipegamestate can be set to -1 to force a wipe on the next draw */ - -gamestate_t wipegamestate = GS_DEMOSCREEN; - -/* DEMO LOOP */ - -int demosequence; -int pagetic; -const char *pagename; - -/* print title for every printed line */ - -char title[128]; - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/* Copyright message banners - * Some dehacked mods replace these. These are only displayed if they are - * replaced by dehacked. - */ - -static const char *g_copyright_banners[] = -{ - "========================================================================" - "===\n" - "ATTENTION: This version of DOOM has been modified. If you would like " - "to\n" - "get a copy of the original game, call 1-800-IDGAMES or see the readme " - "file.\n" - " You will not receive technical support for modified games.\n" - " press enter to continue\n" - "========================================================================" - "===\n", - - "========================================================================" - "===\n" - " Commercial product - do not distribute!\n" - " Please report software piracy to the SPA: 1-800-388-PIR8\n" - "========================================================================" - "===\n", - - "========================================================================" - "===\n" - " Shareware!\n" - "========================================================================" - "===\n", -}; - -/* These are the lumps that will be checked in IWAD, - * if any one is not present, execution will be aborted. - */ - -static char g_name[23][8] = -{ - "e2m1", "e2m2", "e2m3", "e2m4", "e2m5", "e2m6", - "e2m7", "e2m8", "e2m9", "e3m1", "e3m3", "e3m3", - "e3m4", "e3m5", "e3m6", "e3m7", "e3m8", "e3m9", - "dphoof", "bfgga0", "heada1", "cybra1", "spida1d1", -}; - -static char *g_gamedescription; - -/* Add configuration file variable bindings. */ - -static const char *const g_chat_macro_defaults[10] = -{ - HUSTR_CHATMACRO0, HUSTR_CHATMACRO1, HUSTR_CHATMACRO2, HUSTR_CHATMACRO3, - HUSTR_CHATMACRO4, HUSTR_CHATMACRO5, HUSTR_CHATMACRO6, HUSTR_CHATMACRO7, - HUSTR_CHATMACRO8, HUSTR_CHATMACRO9, -}; - -/* Strings for dehacked replacements of the startup banner - * - * These are from the original source: some of them are perhaps - * not used in any dehacked patches - */ - -static const char *g_banners[] = -{ - /* doom2.wad */ - - " " - "DOOM 2: Hell on Earth v%i.%i" - " ", - - /* doom2.wad v1.666 */ - - " " - "DOOM 2: Hell on Earth v%i.%i66" - " ", - - /* doom1.wad */ - - " " - "DOOM Shareware Startup v%i.%i" - " ", - - /* doom.wad */ - - " " - "DOOM Registered Startup v%i.%i" - " ", - - /* Registered DOOM uses this */ - - " " - "DOOM System Startup v%i.%i" - " ", - - /* Doom v1.666 */ - - " " - "DOOM System Startup v%i.%i66" - " " - - /* doom.wad (Ultimate DOOM) */ - - " " - "The Ultimate DOOM Startup v%i.%i" - " ", - - /* tnt.wad */ - - " " - "DOOM 2: TNT - Evilution v%i.%i" - " ", - - /* plutonia.wad */ - - " " - "DOOM 2: Plutonia Experiment v%i.%i" - " ", -}; - -static const struct gameversion g_gameversions[] = -{ - {"Doom 1.2", "1.2", exe_doom_1_2}, - {"Doom 1.5", "1.5", exe_doom_1_5}, - {"Doom 1.666", "1.666", exe_doom_1_666}, - {"Doom 1.7/1.7a", "1.7", exe_doom_1_7}, - {"Doom 1.8", "1.8", exe_doom_1_8}, - {"Doom 1.9", "1.9", exe_doom_1_9}, - {"Hacx", "hacx", exe_hacx}, - {"Ultimate Doom", "ultimate", exe_ultimate}, - {"Final Doom", "final", exe_final}, - {"Final Doom (alt)", "final2", exe_final2}, - {"Chex Quest", "chex", exe_chex}, - {NULL, NULL, 0}, -}; - -static const struct pack g_packs[] = -{ - {"doom2", doom2}, - {"tnt", pack_tnt}, - {"plutonia", pack_plut}, -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static void enable_loading_disk(void) -{ - const char *disk_lump_name; - - if (show_diskicon) - { - if (m_check_parm("-cdrom") > 0) - { - disk_lump_name = ("STCDROM"); - } - else - { - disk_lump_name = ("STDISK"); - } - - v_enable_loading_disk(disk_lump_name, SCREENWIDTH - LOADING_DISK_W, - SCREENHEIGHT - LOADING_DISK_H); - } -} - -static void d_bind_variables(void) -{ - int i; - - m_apply_platform_defaults(); - - i_bind_input_variables(); - i_bind_video_variables(); - i_bind_joystick_variables(); -#ifdef CONFIG_GAMES_NXDOOM_SOUND - i_bind_sound_variables(); -#endif - - m_bind_base_controls(); - m_bind_weapon_controls(); - m_bind_map_controls(); - m_bind_menu_controls(); - m_bind_chat_controls(MAXPLAYERS); - - key_multi_msgplayer[0] = HUSTR_KEYGREEN; - key_multi_msgplayer[1] = HUSTR_KEYINDIGO; - key_multi_msgplayer[2] = HUSTR_KEYBROWN; - key_multi_msgplayer[3] = HUSTR_KEYRED; - -#ifdef CONFIG_GAMES_NXDOOM_NET - net_bind_variables(); -#endif - - m_bind_int_variable("mouse_sensitivity", &g_mouse_sensitivity); -#ifdef CONFIG_GAMES_NXDOOM_SOUND - m_bind_int_variable("sfx_volume", &g_sfx_volume); - m_bind_int_variable("music_volume", &g_music_volume); - m_bind_int_variable("snd_channels", &snd_channels); -#endif - m_bind_int_variable("show_messages", &g_show_messages); - m_bind_int_variable("screenblocks", &screenblocks); - m_bind_int_variable("detaillevel", &g_detail_level); - m_bind_int_variable("vanilla_savegame_limit", &vanilla_savegame_limit); - m_bind_int_variable("vanilla_demo_limit", &vanilla_demo_limit); - m_bind_int_variable("show_endoom", &show_endoom); - m_bind_int_variable("show_diskicon", &show_diskicon); - - /* Multiplayer chat macros */ - - for (i = 0; i < 10; ++i) - { - char buf[12]; - - chat_macros[i] = m_string_duplicate(g_chat_macro_defaults[i]); - snprintf(buf, sizeof(buf), "chatmacro%i", i); - m_bind_string_variable(buf, &chat_macros[i]); - } -} - -/* Function called at exit to display the ENDOOM screen */ - -static void d_endoom(void) -{ -#ifdef CONFIG_GAMES_NXDOOM_ENDOOM - byte *endoom; - - /* Don't show ENDOOM if we have it disabled, or we're running - * in screensaver or control test mode. Only show it once the - * game has actually started. - */ - - if (!show_endoom || !main_loop_started || screensaver_mode || - m_check_parm("-testcontrols") > 0) - { - return; - } - - endoom = w_cache_lump_name(("ENDOOM"), PU_STATIC); - - i_endoom(endoom); -#else - return; -#endif -} - -static boolean is_french_iwad(void) -{ - return (gamemission == doom2 && w_check_num_for_name("M_RDTHIS") < 0 && - w_check_num_for_name("M_EPISOD") < 0 && - w_check_num_for_name("M_EPI1") < 0 && - w_check_num_for_name("M_EPI2") < 0 && - w_check_num_for_name("M_EPI3") < 0 && - w_check_num_for_name("WIOSTF") < 0 && - w_check_num_for_name("WIOBJ") >= 0); -} - -/* Load dehacked patches needed for certain IWADs. */ - -static void load_iwad_deh(void) -{ - /* The Freedoom IWADs have DEHACKED lumps that must be loaded. */ - - if (gamevariant == freedoom || gamevariant == freedm) - { - /* Old versions of Freedoom (before 2014-09) did not have technically - * valid DEHACKED lumps, so ignore errors and just continue if this - * is an old IWAD. - */ - - deh_load_lump_by_name("DEHACKED", false, true); - } - - /* If this is the HACX IWAD, we need to load the DEHACKED lump. */ - - if (gameversion == exe_hacx) - { - if (!deh_load_lump_by_name("DEHACKED", true, false)) - { - i_error("DEHACKED lump not found. Please check that this is the " - "Hacx v1.2 IWAD."); - } - } - - /* Chex Quest needs a separate Dehacked patch which must be downloaded - * and installed next to the IWAD. - */ - - if (gameversion == exe_chex) - { - char *chex_deh = NULL; - char *dirname; - - /* Look for chex.deh in the same directory as the IWAD file. */ - - dirname = m_dir_name(iwadfile); - chex_deh = m_string_join(dirname, DIR_SEPARATOR_S, "chex.deh", NULL); - free(dirname); - - /* If the dehacked patch isn't found, try searching the WAD - * search path instead. We might find it... - */ - - if (!m_file_exists(chex_deh)) - { - free(chex_deh); - chex_deh = d_find_wad_by_name("chex.deh"); - } - - /* Still not found? */ - - if (chex_deh == NULL) - { - i_error("Unable to find Chex Quest dehacked file (chex.deh).\n" - "The dehacked file is required in order to emulate\n" - "chex.exe correctly. It can be found in your nearest\n" - "/idgames repository mirror at:\n\n" - " themes/chex/chexdeh.zip"); - } - - if (!deh_loadfile(chex_deh)) - { - i_error("Failed to load chex.deh needed for emulating chex.exe."); - } - } - - if (is_french_iwad()) - { - char *french_deh = NULL; - char *dirname; - - /* Look for french.deh in the same directory as the IWAD file. */ - - dirname = m_dir_name(iwadfile); - french_deh = - m_string_join(dirname, DIR_SEPARATOR_S, "french.deh", NULL); - printf("French version\n"); - free(dirname); - - /* If the dehacked patch isn't found, try searching the WAD - * search path instead. We might find it... - */ - - if (!m_file_exists(french_deh)) - { - free(french_deh); - french_deh = d_find_wad_by_name("french.deh"); - } - - /* Still not found? */ - - if (french_deh == NULL) - { - i_error( - "Unable to find French Doom II dehacked file\n" - "(french.deh). The dehacked file is required in order to\n" - "emulate French doom2.exe correctly. It can be found in\n" - "your nearest /idgames repository mirror at:\n\n" - " utils/exe_edit/patches/french.zip" - ); - } - - if (!deh_loadfile(french_deh)) - { - i_error("Failed to load french.deh needed for emulating French\n" - "doom2.exe."); - } - } -} - -static void g_check_demo_status_at_exit(void) -{ - g_check_demo_status(); -} - -/* draw current display, possibly wiping it from the previous */ - -static boolean d_display(void) -{ - static boolean viewactivestate = false; - static boolean g_menuactivestate = false; - static boolean inhelpscreensstate = false; - static boolean d_fullscreen = false; - static gamestate_t oldgamestate = -1; - static int borderdrawcount; - int y; - boolean wipe; - boolean redrawsbar; - - redrawsbar = false; - - /* change the view size if needed */ - - if (setsizeneeded) - { - r_execute_set_view_size(); - oldgamestate = -1; /* force background redraw */ - borderdrawcount = 3; - } - - /* save the current screen if about to wipe */ - - if (gamestate != wipegamestate) - { - wipe = true; - wipe_start_screen(0, 0, SCREENWIDTH, SCREENHEIGHT); - } - else - { - wipe = false; - } - - if (gamestate == GS_LEVEL && gametic) - { - hu_erase(); - } - - /* do buffered drawing */ - - switch (gamestate) - { - case GS_LEVEL: - - if (!gametic) - { - break; - } - - if (automapactive) - { - am_drawer(); - } - - if (wipe || (viewheight != SCREENHEIGHT && d_fullscreen)) - { - redrawsbar = true; - } - - if (inhelpscreensstate && !inhelpscreens) - { - redrawsbar = true; /* just put away the help screen */ - } - - st_drawer(viewheight == SCREENHEIGHT, redrawsbar); - d_fullscreen = viewheight == SCREENHEIGHT; - break; - - case GS_INTERMISSION: - wi_drawer(); - break; - - case GS_FINALE: - f_drawer(); - break; - - case GS_DEMOSCREEN: - d_page_drawer(); - break; - } - - /* draw buffered stuff to screen */ - - i_update_no_blit(); - - /* draw the view directly */ - - if (gamestate == GS_LEVEL && !automapactive && gametic) - { - r_render_player_view(&players[displayplayer]); - } - - if (gamestate == GS_LEVEL && gametic) - { - hu_drawer(); - } - - /* clean up border stuff */ - - if (gamestate != oldgamestate && gamestate != GS_LEVEL) - i_set_palette(w_cache_lump_name(("PLAYPAL"), PU_CACHE)); - - /* see if the border needs to be initially drawn */ - - if (gamestate == GS_LEVEL && oldgamestate != GS_LEVEL) - { - viewactivestate = false; /* view was not active */ - r_fill_back_screen(); /* draw the pattern into the back screen */ - } - - /* see if the border needs to be updated to the screen */ - - if (gamestate == GS_LEVEL && !automapactive && - scaledviewwidth != SCREENWIDTH) - { - if (g_menuactive || g_menuactivestate || !viewactivestate) - borderdrawcount = 3; - if (borderdrawcount) - { - r_draw_view_border(); /* erase old menu stuff */ - borderdrawcount--; - } - } - - if (testcontrols) - { - /* Box showing current mouse speed */ - - v_draw_mouse_speed_box(testcontrols_mousespeed); - } - - g_menuactivestate = g_menuactive; - viewactivestate = viewactive; - inhelpscreensstate = inhelpscreens; - oldgamestate = wipegamestate = gamestate; - - /* draw pause pic */ - - if (paused) - { - if (automapactive) - y = 4; - else - y = viewwindowy + 4; - v_draw_patch_direct(viewwindowx + (scaledviewwidth - 68) / 2, y, - w_cache_lump_name(("M_PAUSE"), PU_CACHE)); - } - - /* menus go directly to the screen */ - - m_drawer(); /* menu is drawn even on top of everything */ - net_update(); /* send out any new accumulation */ - - return wipe; -} - -/**************************************************************************** - * Name: d_grab_mouse_callback - * - * Description: - * Called to determine whether to grab the mouse pointer - * - ****************************************************************************/ - -static boolean d_grab_mouse_callback(void) -{ - /* Drone players don't need mouse focus */ - -#ifdef CONFIG_GAMES_NXDOOM_NET - if (drone) return false; -#endif - - /* when menu is active or game is paused, release the mouse */ - - if (g_menuactive || paused) return false; - - /* only grab mouse when playing levels (but not demos) */ - - return (gamestate == GS_LEVEL) && !demoplayback && !advancedemo; -} - -/**************************************************************************** - * Name: d_run_frame - ****************************************************************************/ - -static void d_run_frame(void) -{ - int nowtime; - int tics; - static int wipestart; - static boolean wipe; - - if (wipe) - { - do - { - nowtime = i_get_time(); - tics = nowtime - wipestart; - usleep(1000); - } - while (tics <= 0); - - wipestart = nowtime; - wipe = !wipe_screen_wipe(WIPE_MELT, 0, 0, - SCREENWIDTH, SCREENHEIGHT, tics); - i_update_no_blit(); - m_drawer(); /* menu is drawn even on top of wipes */ - i_finish_update(); /* page flip or blit buffer */ - return; - } - - /* frame synchronous IO operations */ - - i_start_frame(); - - try_run_tics(); /* will run at least one tic */ - -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_update_sounds(players[consoleplayer].mo); /* move positional sounds */ -#endif - - /* Update display, next frame, with current state if no profiling is on */ - - if (screenvisible && !nodrawers) - { - if ((wipe = d_display())) - { - /* start wipe on this frame */ - - wipe_endscreen(0, 0, SCREENWIDTH, SCREENHEIGHT); - - wipestart = i_get_time() - 1; - } - else - { - /* normal update */ - - i_finish_update(); /* page flip or blit buffer */ - } - } -} - -/* Get game name: if the startup banner has been replaced, use that. - * Otherwise, use the name given - */ - -static char *get_game_name(const char *gamename) -{ - size_t i; - - for (i = 0; i < arrlen(g_banners); ++i) - { - const char *deh_sub; - - /* Has the banner been replaced? */ - - deh_sub = (g_banners[i]); - - if (deh_sub != g_banners[i]) - { - size_t gamename_size; - int version; - char *deh_gamename; - - /* Has been replaced. - * We need to expand via printf to include the Doom version number - * We also need to cut off spaces to get the basic name - */ - - gamename_size = strlen(deh_sub) + 10; - deh_gamename = malloc(gamename_size); - if (deh_gamename == NULL) - { - i_error("GetGameName: Failed to allocate new string"); - } - - version = g_vanilla_version_code(); - snprintf(deh_gamename, gamename_size, g_banners[i], version / 100, - version % 100); - - while (deh_gamename[0] != '\0' && isspace(deh_gamename[0])) - { - memmove(deh_gamename, deh_gamename + 1, gamename_size - 1); - } - - while (deh_gamename[0] != '\0' && - isspace(deh_gamename[strlen(deh_gamename) - 1])) - { - deh_gamename[strlen(deh_gamename) - 1] = '\0'; - } - - return deh_gamename; - } - } - - return m_string_duplicate(gamename); -} - -static void set_mission_for_pack_name(const char *pack_name) -{ - int i; - - for (i = 0; i < arrlen(g_packs); ++i) - { - if (!strcasecmp(pack_name, g_packs[i].name)) - { - gamemission = g_packs[i].mission; - return; - } - } - - printf("Valid mission packs are:\n"); - - for (i = 0; i < arrlen(g_packs); ++i) - { - printf("\t%s\n", g_packs[i].name); - } - - i_error("Unknown mission pack name: %s", pack_name); -} - -/* Find out what version of Doom is playing. */ - -static void d_identify_version(void) -{ - /* gamemission is set up by the d_find_iwad function. But if - * we specify '-iwad', we have to identify using - * IdentifyIWADByName. However, if the iwad does not match - * any known IWAD name, we may have a dilemma. Try to - * identify by its contents. - */ - - if (gamemission == none) - { - unsigned int i; - - for (i = 0; i < numlumps; ++i) - { - if (!strncasecmp(lumpinfo[i]->name, "MAP01", 8)) - { - gamemission = doom2; - break; - } - else if (!strncasecmp(lumpinfo[i]->name, "E1M1", 8)) - { - gamemission = doom; - break; - } - } - - if (gamemission == none) - { - /* Still no idea. I don't think this is going to work. */ - - i_error("Unknown or invalid IWAD file."); - } - } - - /* Make sure gamemode is set up correctly */ - - if (logical_gamemission == doom) - { - /* Doom 1. But which version? */ - - if (w_check_num_for_name("E4M1") > 0) - { - /* Ultimate Doom */ - - gamemode = retail; - } - else if (w_check_num_for_name("E3M1") > 0) - { - gamemode = registered; - } - else - { - gamemode = shareware; - } - } - else - { - int p; - - /* Doom 2 of some kind. */ - - gamemode = commercial; - - /* We can manually override the gamemission that we got from the - * IWAD detection code. This allows us to eg. play Plutonia 2 - * with Freedoom and get the right level names. - */ - - /* @category compat - * @arg - * - * Explicitly specify a Doom II "mission pack" to run as, instead of - * detecting it based on the filename. Valid values are: "doom2", - * "tnt" and "plutonia". - * - */ - - p = m_check_parm_with_args("-pack", 1); - if (p > 0) - { - set_mission_for_pack_name(myargv[p + 1]); - } - } -} - -/* Set the gamedescription string */ - -static void d_set_game_description(void) -{ - if (logical_gamemission == doom) - { - /* Doom 1. But which version? */ - - if (gamevariant == freedoom) - { - g_gamedescription = get_game_name("Freedoom: Phase 1"); - } - else if (gamemode == retail) - { - /* Ultimate Doom */ - - g_gamedescription = get_game_name("The Ultimate DOOM"); - } - else if (gamemode == registered) - { - g_gamedescription = get_game_name("DOOM Registered"); - } - else if (gamemode == shareware) - { - g_gamedescription = get_game_name("DOOM Shareware"); - } - } - else - { - /* Doom 2 of some kind. But which mission? */ - - if (gamevariant == freedm) - { - g_gamedescription = get_game_name("FreeDM"); - } - else if (gamevariant == freedoom) - { - g_gamedescription = get_game_name("Freedoom: Phase 2"); - } - else if (logical_gamemission == doom2) - { - g_gamedescription = get_game_name("DOOM 2: Hell on Earth"); - } - else if (logical_gamemission == pack_plut) - { - g_gamedescription = get_game_name("DOOM 2: Plutonia Experiment"); - } - else if (logical_gamemission == pack_tnt) - { - g_gamedescription = get_game_name("DOOM 2: TNT - Evilution"); - } - } - - if (g_gamedescription == NULL) - { - g_gamedescription = m_string_duplicate("Unknown"); - } -} - -static boolean d_addfile(char *filename) -{ - wad_file_t *handle; - - printf(" adding %s\n", filename); - handle = w_add_file(filename); - - return handle != NULL; -} - -/* Prints a message only if it has been modified by dehacked. */ - -static void print_dehacked_banners(void) -{ - size_t i; - - for (i = 0; i < arrlen(g_copyright_banners); ++i) - { - const char *deh_s; - - deh_s = (g_copyright_banners[i]); - - if (deh_s != g_copyright_banners[i]) - { - printf("%s", deh_s); - - /* Make sure the modified banner always ends in a newline - * character. If it doesn't, add a newline. This fixes av.wad. - */ - - if (deh_s[strlen(deh_s) - 1] != '\n') - { - printf("\n"); - } - } - } -} - -/* Initialize the game version */ - -static void init_game_version(void) -{ - byte *demolump; - char demolumpname[6]; - int demoversion; - int p; - int i; - boolean status; - - /* @arg - * @category compat - * - * Emulate a specific version of Doom. Valid values are "1.2", - * "1.5", "1.666", "1.7", "1.8", "1.9", "ultimate", "final", - * "final2", "hacx" and "chex". - * - */ - - p = m_check_parm_with_args("-gameversion", 1); - - if (p) - { - for (i = 0; g_gameversions[i].description != NULL; ++i) - { - if (!strcmp(myargv[p + 1], g_gameversions[i].cmdline)) - { - gameversion = g_gameversions[i].version; - break; - } - } - - if (g_gameversions[i].description == NULL) - { - printf("Supported game versions:\n"); - - for (i = 0; g_gameversions[i].description != NULL; ++i) - { - printf("\t%s (%s)\n", g_gameversions[i].cmdline, - g_gameversions[i].description); - } - - i_error("Unknown game version '%s'", myargv[p + 1]); - } - } - else - { - /* Determine automatically */ - - if (gamemission == pack_chex) - { - /* chex.exe - identified by iwad filename */ - - gameversion = exe_chex; - } - else if (gamemission == pack_hacx) - { - /* hacx.exe: identified by iwad filename */ - - gameversion = exe_hacx; - } - else if (gamemode == shareware || gamemode == registered || - (gamemode == commercial && gamemission == doom2)) - { - /* original */ - - gameversion = exe_doom_1_9; - - /* Detect version from demo lump */ - - for (i = 1; i <= 3; ++i) - { - snprintf(demolumpname, 6, "demo%i", i); - if (w_check_num_for_name(demolumpname) > 0) - { - demolump = w_cache_lump_name(demolumpname, PU_STATIC); - demoversion = demolump[0]; - w_release_lump_name(demolumpname); - status = true; - switch (demoversion) - { - case 0: - case 1: - case 2: - case 3: - case 4: - gameversion = exe_doom_1_2; - break; - case 106: - gameversion = exe_doom_1_666; - break; - case 107: - gameversion = exe_doom_1_7; - break; - case 108: - gameversion = exe_doom_1_8; - break; - case 109: - gameversion = exe_doom_1_9; - break; - default: - status = false; - break; - } - - if (status) - { - break; - } - } - } - } - else if (gamemode == retail) - { - gameversion = exe_ultimate; - } - else if (gamemode == commercial) - { - /* Final Doom: tnt or plutonia - * Defaults to emulating the first Final Doom executable, - * which has the crash in the demo loop; however, having - * this as the default should mean that it plays back - * most demos correctly. - */ - - gameversion = exe_final; - } - } - - /* Deathmatch 2.0 did not exist until Doom v1.4 */ - - if (gameversion <= exe_doom_1_2 && deathmatch == 2) - { - deathmatch = 1; - } - - /* The original exe does not support retail - 4th episode not supported */ - - if (gameversion < exe_ultimate && gamemode == retail) - { - gamemode = registered; - } - - /* EXEs prior to the Final Doom exes do not support Final Doom. */ - - if (gameversion < exe_final && gamemode == commercial && - (gamemission == pack_tnt || gamemission == pack_plut)) - { - gamemission = doom2; - } -} - -static void print_game_version(void) -{ - int i; - - for (i = 0; g_gameversions[i].description != NULL; ++i) - { - if (g_gameversions[i].version == gameversion) - { - printf("Emulating the behavior of the " - "'%s' executable.\n", - g_gameversions[i].description); - break; - } - } -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/* d_process_events - * Send all the events of the given timestamp down the responder chain - */ - -void d_process_events(void) -{ - event_t *ev; - - /* IF STORE DEMO, DO NOT ACCEPT INPUT */ - - if (storedemo) return; - - while ((ev = d_pop_event()) != NULL) - { - if (m_responder(ev)) continue; /* menu ate the event */ - g_responder(ev); - } -} - -/* d_doomloop */ - -void d_doomloop(void) -{ - if (gamevariant == bfgedition && - (demorecording || (gameaction == ga_playdemo) || netgame)) - { - printf(" WARNING: You are playing using one of the Doom Classic\n" - " IWAD files shipped with the Doom 3: BFG Edition. These are\n" - " known to be incompatible with the regular IWAD files and\n" - " may cause demos and network games to get out of sync.\n"); - } - - if (demorecording) - { - g_begin_recording(); - } - - main_loop_started = true; - - i_set_window_title(g_gamedescription); - i_graphics_check_commandline(); - i_set_grab_mouse_callback(d_grab_mouse_callback); - i_init_graphics(); - enable_loading_disk(); - - try_run_tics(); - - v_restore_buffer(); - r_execute_set_view_size(); - - d_start_game_loop(); - - if (testcontrols) - { - wipegamestate = gamestate; - } - - while (1) - { - d_run_frame(); - } -} - -/* d_page_ticker - * Handles timing for warped projection - */ - -void d_page_ticker(void) -{ - if (--pagetic < 0) d_advance_demo(); -} - -/**************************************************************************** - * Name: d_page_drawer - ****************************************************************************/ - -void d_page_drawer(void) -{ - v_draw_patch(0, 0, w_cache_lump_name(pagename, PU_CACHE)); -} - -/**************************************************************************** - * Name: d_advance_demo - * - * Description: - * Called after each demo or intro demosequence finishes - * - ****************************************************************************/ - -void d_advance_demo(void) -{ - advancedemo = true; -} - -/**************************************************************************** - * Name: d_do_advance_demo - * - * Description: - * This cycles through the demo sequences. - * FIXME - version dependent demo numbers? - * - ****************************************************************************/ - -void d_do_advance_demo(void) -{ - players[consoleplayer].playerstate = PST_LIVE; /* not reborn */ - advancedemo = false; - usergame = false; /* no save / end game here */ - paused = false; - gameaction = ga_nothing; - - /* The Ultimate Doom executable changed the demo sequence to add - * a DEMO4 demo. Final Doom was based on Ultimate, so also - * includes this change; however, the Final Doom IWADs do not - * include a DEMO4 lump, so the game bombs out with an error - * when it reaches this point in the demo sequence. - * - * However! There is an alternate version of Final Doom that - * includes a fixed executable. - */ - - if (gameversion == exe_ultimate || gameversion == exe_final) - demosequence = (demosequence + 1) % 7; - else - demosequence = (demosequence + 1) % 6; - - switch (demosequence) - { - case 0: - if (gamemode == commercial) - pagetic = TICRATE * 11; - else - pagetic = 170; - gamestate = GS_DEMOSCREEN; - pagename = ("TITLEPIC"); - -#ifdef CONFIG_GAMES_NXDOOM_SOUND - if (gamemode == commercial) - { - s_start_music(MUS_DM2TTL); - } - else - { - s_start_music(MUS_INTRO); - } -#endif - - break; - case 1: - g_defered_play_demo(("demo1")); - break; - case 2: - pagetic = 200; - gamestate = GS_DEMOSCREEN; - pagename = ("CREDIT"); - break; - case 3: - g_defered_play_demo(("demo2")); - break; - case 4: - gamestate = GS_DEMOSCREEN; - if (gamemode == commercial) - { - pagetic = TICRATE * 11; - pagename = ("TITLEPIC"); -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_music(MUS_DM2TTL); -#endif - } - else - { - pagetic = 200; - - if (gameversion >= exe_ultimate) - pagename = ("CREDIT"); - else - pagename = ("HELP2"); - } - break; - case 5: - g_defered_play_demo(("demo3")); - break; - - /* THE DEFINITIVE DOOM Special Edition demo */ - - case 6: - g_defered_play_demo(("demo4")); - break; - } - - /* The Doom 3: BFG Edition version of doom2.wad does not have a - * TITLETPIC lump. Use INTERPIC instead as a workaround. - */ - - if (gamevariant == bfgedition && !strcasecmp(pagename, "TITLEPIC") && - w_check_num_for_name("titlepic") < 0) - { - pagename = ("INTERPIC"); - } -} - -/* d_start_title */ - -void d_start_title(void) -{ - gameaction = ga_nothing; - demosequence = -1; - d_advance_demo(); -} - -/* d_doom_main */ - -void d_doom_main(void) -{ - int p; - char file[256]; - char demolumpname[9]; - - i_at_exit(d_endoom, false); - - /* print banner */ - - i_print_banner(PACKAGE_STRING); - - printf("z_init: Init zone memory allocation daemon. \n"); - z_init(); - -#ifdef CONFIG_GAMES_NXDOOM_NET - /* @category net - * - * Start a dedicated server, routing packets but not participating - * in the game itself. - * - */ - - if (m_check_parm("-dedicated") > 0) - { - printf("Dedicated server mode.\n"); - net_dedicated_server(); - - /* Never returns */ - } - - /* @category net - * - * Query the Internet master server for a global list of active - * servers. - * - */ - - if (m_check_parm("-search")) - { - net_master_query(); - exit(0); - } - - /* @arg
- * @category net - * - * Query the status of the server running on the given IP - * address. - * - */ - - p = m_check_parm_with_args("-query", 1); - - if (p) - { - net_query_address(myargv[p + 1]); - exit(0); - } - - /* @category net - * - * Search the local LAN for running servers. - * - */ - - if (m_check_parm("-localsearch")) - { - net_lan_query(); - exit(0); - } -#endif - - /* @category game - * @vanilla - * - * Disable monsters. - * - */ - - nomonsters = m_check_parm("-nomonsters"); - - /* @category game - * @vanilla - * - * Monsters respawn after being killed. - * - */ - - respawnparm = m_check_parm("-respawn"); - - /* @category game - * @vanilla - * - * Monsters move faster. - * - */ - - fastparm = m_check_parm("-fast"); - - /* @vanilla - * - * Developer mode. F1 saves a screenshot in the current working - * directory. - * - */ - - devparm = m_check_parm("-devparm"); - - i_display_fps_dots(devparm); - - /* @category net - * @vanilla - * - * Start a deathmatch game. - * - */ - - if (m_check_parm("-deathmatch")) deathmatch = 1; - - /* @category net - * @vanilla - * - * Start a deathmatch 2.0 game. Weapons do not stay in place and - * all items respawn after 30 seconds. - * - */ - - if (m_check_parm("-altdeath")) deathmatch = 2; - - if (devparm) - { - printf(D_DEVSTR); - } - - /* find which dir to use for config files */ - - /* Auto-detect the configuration dir. */ - - m_set_config_dir(NULL); - - /* @category game - * @arg - * @vanilla - * - * Turbo mode. The player's speed is multiplied by x%. If unspecified, - * x defaults to 200. Values are rounded up to 10 and down to 400. - * - */ - - if ((p = m_check_parm("-turbo"))) - { - int scale = 200; - - if (p < myargc - 1) scale = atoi(myargv[p + 1]); - if (scale < 10) scale = 10; - if (scale > 400) scale = 400; - printf("turbo scale: %i%%\n", scale); - forwardmove[0] = forwardmove[0] * scale / 100; - forwardmove[1] = forwardmove[1] * scale / 100; - sidemove[0] = sidemove[0] * scale / 100; - sidemove[1] = sidemove[1] * scale / 100; - } - - /* init subsystems */ - - printf("v_init: allocate screens.\n"); - v_init(); - - /* Load configuration files before initialising other subsystems. */ - - printf("m_load_defaults: Load system defaults.\n"); - m_set_config_filenames("default.cfg", PROGRAM_PREFIX "doom.cfg"); - d_bind_variables(); - m_load_defaults(); - - /* Save configuration at exit. */ - - i_at_exit(m_save_defaults, false); - - /* Find main IWAD file and load it. */ - - iwadfile = d_find_iwad(IWAD_MASK_DOOM, &gamemission); - - /* None found? */ - - if (iwadfile == NULL) - { - i_error("Game mode indeterminate. No IWAD file was found. Try\n" - "specifying one with the '-iwad' command line parameter.\n"); - } - - modifiedgame = false; - - printf("W_Init: Init WADfiles.\n"); - d_addfile(iwadfile); - - w_check_correct_iwad(doom); - - /* Now that we've loaded the IWAD, we can figure out what gamemission - * we're playing and which version of Vanilla Doom we need to emulate. - */ - - d_identify_version(); - init_game_version(); - - /* Check which IWAD variant we are using. */ - - if (w_check_num_for_name("FREEDOOM") >= 0) - { - if (w_check_num_for_name("FREEDM") >= 0) - { - gamevariant = freedm; - } - else - { - gamevariant = freedoom; - } - } - else if (w_check_num_for_name("DMENUPIC") >= 0) - { - gamevariant = bfgedition; - } - - /* @category mod - * - * Disable automatic loading of Dehacked patches for certain - * IWAD files. - * - */ - - if (!m_parm_exists("-nodeh")) - { - /* Some IWADs have dehacked patches that need to be loaded for - * them to be played properly. - */ - - load_iwad_deh(); - } - - /* Doom 3: BFG Edition includes modified versions of the classic - * IWADs which can be identified by an additional DMENUPIC lump. - * Furthermore, the M_GDHIGH lumps have been modified in a way that - * makes them incompatible to Vanilla Doom and the modified version - * of doom2.wad is missing the TITLEPIC lump. - * We specifically check for DMENUPIC here, before PWADs have been - * loaded which could probably include a lump of that name. - */ - - if (gamevariant == bfgedition) - { - printf("BFG Edition: Using workarounds as needed.\n"); - - /* BFG Edition changes the names of the secret levels to - * censor the Wolfenstein references. It also has an extra - * secret level (MAP33). In Vanilla Doom (meaning the DOS - * version), MAP33 overflows into the Plutonia level names - * array, so HUSTR_33 is actually PHUSTR_1. - */ - - deh_add_string_replacement(HUSTR_31, "level 31: idkfa"); - deh_add_string_replacement(HUSTR_32, "level 32: keen"); - deh_add_string_replacement(PHUSTR_1, "level 33: betray"); - - /* The BFG edition doesn't have the "low detail" menu option (fair - * enough). But bizarrely, it reuses the M_GDHIGH patch as a label - * for the options menu (says "Fullscreen:"). Why the perpetrators - * couldn't just add a new graphic lump and had to reuse this one, - * I don't know. - * - * The end result is that M_GDHIGH is too wide and causes the game - * to crash. As a workaround to get a minimum level of support for - * the BFG edition IWADs, use the "ON"/"OFF" graphics instead. - */ - - deh_add_string_replacement("M_GDHIGH", "M_MSGON"); - deh_add_string_replacement("M_GDLOW", "M_MSGOFF"); - - /* The BFG edition's "Screen Size:" graphic has also been changed - * to say "Gamepad:". Fortunately, it (along with the original - * Doom IWADs) has an unused graphic that says "Display". So we - * can swap this in instead, and it kind of makes sense. - */ - - deh_add_string_replacement("M_SCRNSZ", "M_DISP"); - } - - /* @category mod - * - * Disable auto-loading of .wad and .deh files. - * - */ - - if (!m_parm_exists("-noautoload") && gamemode != shareware) - { - char *autoload_dir; - - /* common auto-loaded files for all Doom flavors */ - - if (gamemission < pack_chex) - { - autoload_dir = m_get_autoload_dir("doom-all"); - if (autoload_dir != NULL) - { - deh_auto_load_patches(autoload_dir); - w_auto_load_wads(autoload_dir); - free(autoload_dir); - } - } - - /* auto-loaded files per IWAD */ - - autoload_dir = m_get_autoload_dir( - d_save_game_iwad_name(gamemission, gamevariant)); - - if (autoload_dir != NULL) - { - deh_auto_load_patches(autoload_dir); - w_auto_load_wads(autoload_dir); - free(autoload_dir); - } - } - - /* Load Dehacked patches specified on the command line with -deh. - * Note that there's a very careful and deliberate ordering to how - * Dehacked patches are loaded. The order we use is: - * 1. IWAD dehacked patches. - * 2. Command line dehacked patches specified with -deh. - * 3. PWAD dehacked patches in DEHACKED lumps. - */ - - deh_parse_command_line(); - - /* Load PWAD files. */ - - modifiedgame = w_parse_command_line(); - - /* Debug: - * w_print_directory(); - */ - - /* @arg - * @category demo - * @vanilla - * - * Play back the demo named demo.lmp. - * - */ - - p = m_check_parm_with_args("-playdemo", 1); - - if (!p) - { - /* @arg - * @category demo - * @vanilla - * - * Play back the demo named demo.lmp, determining the framerate - * of the screen. - * - */ - - p = m_check_parm_with_args("-timedemo", 1); - } - - if (p) - { - char *uc_filename = strdup(myargv[p + 1]); - m_force_uppercase(uc_filename); - - /* With Vanilla you have to specify the file without extension, - * but make that optional. - */ - - if (m_string_ends_with(uc_filename, ".LMP")) - { - m_str_copy(file, myargv[p + 1], sizeof(file)); - } - else - { - snprintf(file, sizeof(file), "%s.lmp", myargv[p + 1]); - } - - free(uc_filename); - - if (d_addfile(file)) - { - m_str_copy(demolumpname, lumpinfo[numlumps - 1]->name, - sizeof(demolumpname)); - } - else - { - /* If file failed to load, still continue trying to play - * the demo in the same way as Vanilla Doom. This makes - * tricks like "-playdemo demo1" possible. - */ - - m_str_copy(demolumpname, myargv[p + 1], sizeof(demolumpname)); - } - - printf("Playing demo %s.\n", file); - } - - i_at_exit(g_check_demo_status_at_exit, true); - - /* Generate the WAD hash table. Speed things up a bit. */ - - w_generate_hash_table(); - - /* Load DEHACKED lumps from WAD files - but only if we give the right - * command line parameter. - */ - - /* @category mod - * - * Load Dehacked patches from DEHACKED lumps contained in one of the - * loaded PWAD files. - * - */ - - if (m_parm_exists("-dehlump")) - { - int i; - int loaded = 0; - int numiwadlumps = numlumps; - - while (!w_is_iwad_lump(lumpinfo[numiwadlumps - 1])) - { - numiwadlumps--; - } - - for (i = numiwadlumps; i < numlumps; ++i) - { - if (!strncmp(lumpinfo[i]->name, "DEHACKED", 8)) - { - deh_load_lump(i, false, false); - loaded++; - } - } - - printf(" loaded %i DEHACKED lumps from PWAD files.\n", loaded); - } - - /* Set the gamedescription string. This is only possible now that - * we've finished loading Dehacked patches. - */ - - d_set_game_description(); - - savegamedir = - m_get_save_game_dir(d_save_game_iwad_name(gamemission, gamevariant)); - - /* Check for -file in shareware */ - - if (modifiedgame && (gamevariant != freedoom)) - { - int i; - - if (gamemode == shareware) - i_error(("\nYou cannot -file with the shareware " - "version. Register!")); - - /* Check for fake IWAD with right name, - * but w/o all the lumps of the registered version. - */ - - if (gamemode == registered) - { - for (i = 0; i < 23; i++) - { - if (w_check_num_for_name(g_name[i]) < 0) - { - i_error(("\nThis is not the registered version.")); - } - } - } - } - - if (w_check_num_for_name("SS_START") >= 0 || - w_check_num_for_name("FF_END") >= 0) - { - i_print_divider(); - printf(" WARNING: The loaded WAD file contains modified sprites or\n" - " floor textures. You may want to use the '-merge' command\n" - " line option instead of '-file'.\n"); - } - - i_print_startup_banner(g_gamedescription); - print_dehacked_banners(); - - printf("i_init: Setting up machine state.\n"); - i_check_is_screensaver(); - i_init_timer(); - i_init_joystick(); -#ifdef CONFIG_GAMES_NXDOOM_SOUND - i_init_sound(doom); - i_init_music(); -#endif - -#ifdef CONFIG_GAMES_NXDOOM_NET - printf("net_init: Init network subsystem.\n"); - net_init(); -#endif - - /* Initial netgame startup. Connect to server etc. */ - - d_connect_net_game(); - - /* get skill / episode / map from params */ - - startskill = sk_medium; - startepisode = 1; - startmap = 1; - autostart = false; - - /* @category game - * @arg - * @vanilla - * - * Set the game skill, 1-5 (1: easiest, 5: hardest). A skill of - * 0 disables all monsters. - * - */ - - p = m_check_parm_with_args("-skill", 1); - - if (p) - { - startskill = myargv[p + 1][0] - '1'; - autostart = true; - } - - /* @category game - * @arg - * @vanilla - * - * Start playing episode n (1-4). - * - */ - - p = m_check_parm_with_args("-episode", 1); - - if (p) - { - startepisode = myargv[p + 1][0] - '0'; - startmap = 1; - autostart = true; - } - - timelimit = 0; - - /* @arg - * @category net - * @vanilla - * - * For multiplayer games: exit each level after n minutes. - * - */ - - p = m_check_parm_with_args("-timer", 1); - - if (p) - { - timelimit = atoi(myargv[p + 1]); - } - - /* @category net - * @vanilla - * - * Austin Virtual Gaming: end levels after 20 minutes. - * - */ - - p = m_check_parm("-avg"); - - if (p) - { - timelimit = 20; - } - - /* @category game - * @arg [ | ] - * @vanilla - * - * Start a game immediately, warping to ExMy (Doom 1) or MAPxy - * (Doom 2). - * - */ - - p = m_check_parm_with_args("-warp", 1); - - if (p) - { - if (gamemode == commercial) - startmap = atoi(myargv[p + 1]); - else - { - startepisode = myargv[p + 1][0] - '0'; - - if (p + 2 < myargc) - { - startmap = myargv[p + 2][0] - '0'; - } - else - { - startmap = 1; - } - } - - autostart = true; - } - - /* Undocumented: - * Invoked by setup to test the controls. - */ - - p = m_check_parm("-testcontrols"); - - if (p > 0) - { - startepisode = 1; - startmap = 1; - autostart = true; - testcontrols = true; - } - - /* Check for load game parameter - * We do this here and save the slot number, so that the network code - * can override it or send the load slot to other players. - */ - - /* @category game - * @arg - * @vanilla - * - * Load the game in slot s. - * - */ - - p = m_check_parm_with_args("-loadgame", 1); - - if (p) - { - startloadgame = atoi(myargv[p + 1]); - } - else - { - startloadgame = -1; /* Not loading a game */ - } - - printf("m_init: Init miscellaneous info.\n"); - m_init(); - - printf("r_init: Init DOOM refresh daemon - "); - r_init(); - - printf("\np_init: Init Playloop state.\n"); - p_init(); - -#ifdef CONFIG_GAMES_NXDOOM_SOUND - printf("s_init: Setting up sound.\n"); - s_init(g_sfx_volume * 8, g_music_volume * 8); -#endif - - printf("d_check_net_game: Checking network game status.\n"); - d_check_net_game(); - - print_game_version(); - - printf("hu_init: Setting up heads up display.\n"); - hu_init(); - - printf("st_init: Init status bar.\n"); - st_init(); - - /* If Doom II without a MAP01 lump, this is a store demo. - * Moved this here so that MAP01 isn't constantly looked up - * in the main loop. - */ - - if (gamemode == commercial && w_check_num_for_name("map01") < 0) - storedemo = true; - - if (m_check_parm_with_args("-statdump", 1)) - { - i_at_exit(stat_dump, true); - printf("External statistics registered.\n"); - } - - /* @arg - * @category demo - * @vanilla - * - * Record a demo named x.lmp. - */ - - p = m_check_parm_with_args("-record", 1); - - if (p) - { - g_record_demo(myargv[p + 1]); - autostart = true; - } - - p = m_check_parm_with_args("-playdemo", 1); - if (p) - { - singledemo = true; /* quit after one demo */ - g_defered_play_demo(demolumpname); - d_doomloop(); /* never returns */ - } - - p = m_check_parm_with_args("-timedemo", 1); - if (p) - { - g_time_demo(demolumpname); - d_doomloop(); /* never returns */ - } - - if (startloadgame >= 0) - { - m_str_copy(file, p_save_game_file(startloadgame), sizeof(file)); - g_load_game(file); - } - - if (gameaction != ga_loadgame) - { - if (autostart || netgame) - g_init_new(startskill, startepisode, startmap); - else - d_start_title(); /* start up intro loop */ - } - - d_doomloop(); /* never returns */ -} diff --git a/games/NXDoom/src/doom/d_main.h b/games/NXDoom/src/doom/d_main.h deleted file mode 100644 index f97422597..000000000 --- a/games/NXDoom/src/doom/d_main.h +++ /dev/null @@ -1,58 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/d_main.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * System specific interface stuff. - * - ****************************************************************************/ - -#ifndef __D_MAIN__ -#define __D_MAIN__ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "doomdef.h" - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -extern gameaction_t gameaction; -extern boolean advancedemo; - -extern const char *pagename; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/* Read events from all input devices */ - -void d_process_events(void); - -/* BASE LEVEL */ - -void d_page_ticker(void); -void d_page_drawer(void); -void d_advance_demo(void); -void d_do_advance_demo(void); -void d_start_title(void); - -#endif /* __D_MAIN__ */ diff --git a/games/NXDoom/src/doom/d_net.c b/games/NXDoom/src/doom/d_net.c deleted file mode 100644 index 3be74240c..000000000 --- a/games/NXDoom/src/doom/d_net.c +++ /dev/null @@ -1,333 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/d_net.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * DOOM Network game communication and protocol, all OS independent parts. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include "d_main.h" -#include "doomdef.h" -#include "doomstat.h" -#include "g_game.h" -#include "i_system.h" -#include "i_timer.h" -#include "i_video.h" -#include "m_argv.h" -#include "m_menu.h" -#include "m_misc.h" -#include "w_checksum.h" -#include "w_wad.h" - -#include "deh_main.h" - -#include "d_loop.h" - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -static void run_tic(ticcmd_t *cmds, boolean *ingame); - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static loop_interface_t g_doom_loop_interface = -{ - d_process_events, - g_build_ticcmd, - run_tic, - m_ticker, -}; - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -ticcmd_t *netcmds; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: player_quit_game - * - * Description: - * Called when a player leaves the game - * - ****************************************************************************/ - -static void player_quit_game(player_t *player) -{ - static char exitmsg[80]; - unsigned int player_num; - - player_num = player - players; - - /* Do this the same way as Vanilla Doom does, to allow dehacked - * replacements of this message - */ - - m_str_copy(exitmsg, ("Player 1 left the game"), sizeof(exitmsg)); - - exitmsg[7] += player_num; - - playeringame[player_num] = false; - players[consoleplayer].message = exitmsg; - - /* TODO: check if it is sensible to do this: */ - - if (demorecording) - { - g_check_demo_status(); - } -} - -static void run_tic(ticcmd_t *cmds, boolean *ingame) -{ - unsigned int i; - - /* Check for player quits. */ - - for (i = 0; i < MAXPLAYERS; ++i) - { - if (!demoplayback && playeringame[i] && !ingame[i]) - { - player_quit_game(&players[i]); - } - } - - netcmds = cmds; - - /* check that there are players in the game. if not, we cannot - * run a tic. - */ - - if (advancedemo) d_do_advance_demo(); - - g_ticker(); -} - -/**************************************************************************** - * Name: Load_Game_Settings - * - * Description: - * Load game settings from the specified structure and - * set global variables. - * - ****************************************************************************/ - -static void load_game_settings(net_gamesettings_t *settings) -{ - unsigned int i; - - deathmatch = settings->deathmatch; - startepisode = settings->episode; - startmap = settings->map; - startskill = settings->skill; - startloadgame = settings->loadgame; - lowres_turn = settings->lowres_turn; - nomonsters = settings->nomonsters; - fastparm = settings->fast_monsters; - respawnparm = settings->respawn_monsters; - timelimit = settings->timelimit; - consoleplayer = settings->consoleplayer; - - if (lowres_turn) - { - printf("NOTE: Turning resolution is reduced; this is probably " - "because there is a client recording a Vanilla demo.\n"); - } - - for (i = 0; i < MAXPLAYERS; ++i) - { - playeringame[i] = i < settings->num_players; - } -} - -/**************************************************************************** - * Name: save_game_settings - * - * Description: - * Save the game settings from global variables to the specified - * game settings structure. - * - ****************************************************************************/ - -static void save_game_settings(net_gamesettings_t *settings) -{ - /* Fill in game settings structure with appropriate parameters - * for the new game - */ - - settings->deathmatch = deathmatch; - settings->episode = startepisode; - settings->map = startmap; - settings->skill = startskill; - settings->loadgame = startloadgame; - settings->gameversion = gameversion; - settings->nomonsters = nomonsters; - settings->fast_monsters = fastparm; - settings->respawn_monsters = respawnparm; - settings->timelimit = timelimit; - - settings->lowres_turn = - (m_parm_exists("-record") && !m_parm_exists("-longtics")) || - m_parm_exists("-shorttics"); -} - -static void init_connect_data(net_connect_data_t *connect_data) -{ - boolean shorttics; - - connect_data->max_players = MAXPLAYERS; - connect_data->drone = false; - - /* @category net - * - * Run as the left screen in three screen mode. - */ - - if (m_check_parm("-left") > 0) - { - viewangleoffset = ANG90; - connect_data->drone = true; - } - - /* @category net - * - * Run as the right screen in three screen mode. - */ - - if (m_check_parm("-right") > 0) - { - viewangleoffset = ANG270; - connect_data->drone = true; - } - - /* Connect data */ - - /* Game type fields: */ - - connect_data->gamemode = gamemode; - connect_data->gamemission = gamemission; - - /* @category demo - * - * Play with low turning resolution to emulate demo recording. - */ - - shorttics = m_parm_exists("-shorttics"); - - /* Are we recording a demo? Possibly set lowres turn mode */ - - connect_data->lowres_turn = - (m_parm_exists("-record") && !m_parm_exists("-longtics")) || shorttics; - - /* Read checksums of our WAD directory and dehacked information */ - - w_checksum(connect_data->wad_sha1sum); - deh_checksum(connect_data->deh_sha1sum); - - /* Are we playing with the Freedoom IWAD? */ - - connect_data->is_freedoom = w_check_num_for_name("FREEDOOM") >= 0; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -void d_connect_net_game(void) -{ - net_connect_data_t connect_data; - - init_connect_data(&connect_data); - netgame = d_init_net_game(&connect_data); - -#ifdef CONFIG_GAMES_NXDOOM_NET - /* @category net - * - * Start the game playing as though in a netgame with a single - * player. This can also be used to play back single player netgame - * demos. - */ - - if (m_check_parm("-solo-net") > 0) - { - netgame = true; - } -#endif -} - -/**************************************************************************** - * Name: d_check_net_game - * - * Description: - * Works out player numbers among the net participants - * - ****************************************************************************/ - -void d_check_net_game(void) -{ - net_gamesettings_t settings; - - if (netgame) - { - autostart = true; - } - - d_register_loop_callbacks(&g_doom_loop_interface); - - save_game_settings(&settings); - d_start_net_game(&settings, NULL); - load_game_settings(&settings); - - printf("startskill %i deathmatch: %i startmap: %i startepisode: %i\n", - startskill, deathmatch, startmap, startepisode); - - printf("player %i of %i (%i nodes)\n", consoleplayer + 1, - settings.num_players, settings.num_players); - - /* Show players here; the server might have specified a time limit */ - - if (timelimit > 0 && deathmatch) - { - /* Gross hack to work like Vanilla: */ - - if (timelimit == 20 && m_check_parm("-avg")) - { - printf("Austin Virtual Gaming: Levels will end " - "after 20 minutes\n"); - } - else - { - printf("Levels will end after %d minute", timelimit); - if (timelimit > 1) printf("s"); - printf(".\n"); - } - } -} diff --git a/games/NXDoom/src/doom/d_player.h b/games/NXDoom/src/doom/d_player.h deleted file mode 100644 index 54defc586..000000000 --- a/games/NXDoom/src/doom/d_player.h +++ /dev/null @@ -1,236 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/d_player.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * - ****************************************************************************/ - -#ifndef __D_PLAYER__ -#define __D_PLAYER__ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -/* The player data structure depends on a number - * of other structs: items (internal inventory), - * animation states (closely tied to the sprites - * used to represent them, unfortunately). - */ - -#include "d_items.h" -#include "p_pspr.h" - -/* In addition, the player is just a special - * case of the generic moving object/actor. - */ - -#include "p_mobj.h" - -/* Finally, for odd reasons, the player input - * is buffered within the player data struct, - * as commands per game tick. - */ - -#include "d_ticcmd.h" - -#include "net_defs.h" - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -/* Player states. */ - -typedef enum -{ - PST_LIVE, /* Playing or camping. */ - PST_DEAD, /* Dead on the ground, view follows killer. */ - PST_REBORN /* Ready to restart/respawn??? */ -} playerstate_t; - -/* Player internal flags, for cheats and debug. */ - -typedef enum -{ - CF_NOCLIP = 1, /* No clipping, walk through barriers. */ - CF_GODMODE = 2, /* No damage, no health loss. */ - CF_NOMOMENTUM = 4 /* Not really a cheat, just a debug aid. */ -} cheat_t; - -/* Extended player object info: player_t */ - -typedef struct player_s -{ - mobj_t *mo; - playerstate_t playerstate; - ticcmd_t cmd; - - /* Determine POV, including viewpoint bobbing during movement. - * Focal origin above r.z - */ - - fixed_t viewz; - - /* Base height above floor for viewz. */ - - fixed_t viewheight; - - /* Bob/squat speed. */ - - fixed_t deltaviewheight; - - /* bounded/scaled total momentum. */ - - fixed_t bob; - - /* This is only used between levels, - * mo->health is used during levels. - */ - - int health; - int armorpoints; - - /* Armor type is 0-2. */ - - int armortype; - - /* Power ups. invinc and invis are tic counters. */ - - int powers[NUMPOWERS]; - boolean cards[NUMCARDS]; - boolean backpack; - - /* Frags, kills of other players. */ - - int frags[MAXPLAYERS]; - weapontype_t readyweapon; - - /* Is wp_nochange if not changing. */ - - weapontype_t pendingweapon; - - int weaponowned[NUMWEAPONS]; - int ammo[NUMAMMO]; - int maxammo[NUMAMMO]; - - /* True if button down last tic. */ - - int attackdown; - int usedown; - - /* Bit flags, for cheats and debug. - * See cheat_t, above. - */ - - int cheats; - - /* Refired shots are less accurate. */ - - int refire; - - /* For intermission stats. */ - - int killcount; - int itemcount; - int secretcount; - - /* Hint messages. */ - - const char *message; - - /* For screen flashing (red or bright). */ - - int damagecount; - int bonuscount; - - /* Who did damage (NULL for floors/ceilings). */ - - mobj_t *attacker; - - /* So gun flashes light up areas. */ - - int extralight; - - /* Current PLAYPAL, ??? can be set to REDCOLORMAP for pain, etc. - */ - - int fixedcolormap; - - /* Player skin colorshift, 0-3 for which color to draw player. - */ - - int colormap; - - /* Overlay view sprites (gun, etc). */ - - pspdef_t psprites[NUMPSPRITES]; - - /* True if secret level has been done. */ - - boolean didsecret; -} player_t; - -/* INTERMISSION - * Structure passed e.g. to wi_start(wb) - */ - -typedef struct -{ - boolean in; /* whether the player is in game */ - - /* Player stats, kills, collected items etc. */ - - int skills; - int sitems; - int ssecret; - int stime; - int frags[4]; - int score; /* current score on entry, modified on return */ -} wbplayerstruct_t; - -typedef struct -{ - int epsd; /* episode # (0-2) */ - - /* if true, splash the secret level */ - - boolean didsecret; - - /* previous and next levels, origin 0 */ - - int last; - int next; - - int maxkills; - int maxitems; - int maxsecret; - int maxfrags; - - /* the par time */ - - int partime; - - /* index of this player in game */ - - int pnum; - - wbplayerstruct_t plyr[MAXPLAYERS]; -} wbstartstruct_t; - -#endif /* __D_PLAYER__ */ diff --git a/games/NXDoom/src/doom/d_textur.h b/games/NXDoom/src/doom/d_textur.h deleted file mode 100644 index cf77f38b4..000000000 --- a/games/NXDoom/src/doom/d_textur.h +++ /dev/null @@ -1,50 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/d_textur.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Typedefs related to to textures etc., - * isolated here to make it easier separating modules. - * - ****************************************************************************/ - -#ifndef __D_TEXTUR__ -#define __D_TEXTUR__ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "doomtype.h" - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -/* Flats? - * - * a pic is an unmasked block of pixels - */ - -typedef struct -{ - byte width; - byte height; - byte data; -} pic_t; - -#endif /* __D_TEXTUR__ */ diff --git a/games/NXDoom/src/doom/d_think.h b/games/NXDoom/src/doom/d_think.h deleted file mode 100644 index 8ec8ada7f..000000000 --- a/games/NXDoom/src/doom/d_think.h +++ /dev/null @@ -1,64 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/d_think.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * MapObj data. Map Objects or mobjs are actors, entities, - * thinker, take-your-pick... anything that moves, acts, or - * suffers state changes of more or less violent nature. - * - ****************************************************************************/ - -#ifndef __D_THINK__ -#define __D_THINK__ - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -/* Experimental stuff. - * To compile this as "ANSI C with classes" we will need to handle the - * various action functions cleanly. - */ - -typedef void (*actionf_v)(void); -typedef void (*actionf_p1)(void *); -typedef void (*actionf_p2)(void *, void *); - -typedef union -{ - actionf_v acv; - actionf_p1 acp1; - actionf_p2 acp2; -} actionf_t; - -/* Historically, "think_t" is yet another function pointer to a routine to - * handle an actor. - */ - -typedef actionf_t think_t; - -/* Doubly linked list of actors. */ - -typedef struct thinker_s -{ - struct thinker_s *prev; - struct thinker_s *next; - think_t function; -} thinker_t; - -#endif /* __D_THINK__ */ diff --git a/games/NXDoom/src/doom/deh_ammo.c b/games/NXDoom/src/doom/deh_ammo.c deleted file mode 100644 index 83aabf00e..000000000 --- a/games/NXDoom/src/doom/deh_ammo.c +++ /dev/null @@ -1,128 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/deh_ammo.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * Parses "Ammo" sections in dehacked files - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include - -#include "deh_defs.h" -#include "deh_io.h" -#include "deh_main.h" -#include "doomdef.h" -#include "doomtype.h" -#include "p_local.h" - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -static void *deh_ammo_start(deh_context_t *context, char *line); -static void deh_ammo_parse_line(deh_context_t *context, char *line, - void *tag); -static void deh_ammo_sha1_hash(SHA1_CTX *context); - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -deh_section_t deh_section_ammo = -{ - "Ammo", - NULL, - deh_ammo_start, - deh_ammo_parse_line, - NULL, - deh_ammo_sha1_hash, -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static void *deh_ammo_start(deh_context_t *context, char *line) -{ - int ammo_number = 0; - - if (sscanf(line, "Ammo %i", &ammo_number) != 1) - { - deh_warning(context, "Parse error on section start"); - return NULL; - } - - if (ammo_number < 0 || ammo_number >= NUMAMMO) - { - deh_warning(context, "Invalid ammo number: %i", ammo_number); - return NULL; - } - - return &maxammo[ammo_number]; -} - -static void deh_ammo_parse_line(deh_context_t *context, char *line, - void *tag) -{ - char *variable_name; - char *value; - int ivalue; - int ammo_number; - - if (tag == NULL) return; - - ammo_number = ((int *)tag) - maxammo; - - /* Parse the assignment */ - - if (!deh_parse_assignment(line, &variable_name, &value)) - { - /* Failed to parse */ - - deh_warning(context, "Failed to parse assignment"); - return; - } - - ivalue = atoi(value); - - /* maxammo */ - - if (!strcasecmp(variable_name, "Per ammo")) - clipammo[ammo_number] = ivalue; - else if (!strcasecmp(variable_name, "Max ammo")) - maxammo[ammo_number] = ivalue; - else - { - deh_warning(context, "Field named '%s' not found", variable_name); - } -} - -static void deh_ammo_sha1_hash(SHA1_CTX *context) -{ - int i; - - for (i = 0; i < NUMAMMO; ++i) - { - sha1_updateint32(context, clipammo[i]); - sha1_updateint32(context, maxammo[i]); - } -} diff --git a/games/NXDoom/src/doom/deh_bexstr.c b/games/NXDoom/src/doom/deh_bexstr.c deleted file mode 100644 index c1ff9c83d..000000000 --- a/games/NXDoom/src/doom/deh_bexstr.c +++ /dev/null @@ -1,406 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/deh_bexstr.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * Copyright(C) 2014 Fabian Greffrath - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * Parses [STRINGS] sections in BEX files - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -#include "deh_defs.h" -#include "deh_io.h" -#include "deh_main.h" - -#include "dstrings.h" - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -typedef struct -{ - const char *macro; - const char *string; -} bex_string_t; - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -static void *deh_bex_str_start(deh_context_t *context, char *line); -static void deh_bex_str_parse_line(deh_context_t *context, char *line, - void *tag); - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/* mnemonic keys table */ - -static const bex_string_t g_bex_stringtable[] = -{ - {"D_DEVSTR", D_DEVSTR}, /* part 1 - general initialization and prompts */ - {"D_CDROM", D_CDROM}, - {"QUITMSG", QUITMSG}, - {"LOADNET", LOADNET}, - {"QLOADNET", QLOADNET}, - {"QSAVESPOT", QSAVESPOT}, - {"SAVEDEAD", SAVEDEAD}, - {"QSPROMPT", QSPROMPT}, - {"QLPROMPT", QLPROMPT}, - {"NEWGAME", NEWGAME}, - {"NIGHTMARE", NIGHTMARE}, - {"SWSTRING", SWSTRING}, - {"MSGOFF", MSGOFF}, - {"MSGON", MSGON}, - {"NETEND", NETEND}, - {"ENDGAME", ENDGAME}, - {"DETAILHI", DETAILHI}, - {"DETAILLO", DETAILLO}, - {"GAMMALVL0", GAMMALVL0}, - {"GAMMALVL1", GAMMALVL1}, - {"GAMMALVL2", GAMMALVL2}, - {"GAMMALVL3", GAMMALVL3}, - {"GAMMALVL4", GAMMALVL4}, - {"EMPTYSTRING", EMPTYSTRING}, - {"GGSAVED", GGSAVED}, - {"SAVEGAMENAME", SAVEGAMENAME}, - {"GOTARMOR", - GOTARMOR}, /* part 2 - messages when the player gets things */ - {"GOTMEGA", GOTMEGA}, - {"GOTHTHBONUS", GOTHTHBONUS}, - {"GOTARMBONUS", GOTARMBONUS}, - {"GOTSTIM", GOTSTIM}, - {"GOTMEDINEED", GOTMEDINEED}, - {"GOTMEDIKIT", GOTMEDIKIT}, - {"GOTSUPER", GOTSUPER}, - {"GOTBLUECARD", GOTBLUECARD}, - {"GOTYELWCARD", GOTYELWCARD}, - {"GOTREDCARD", GOTREDCARD}, - {"GOTBLUESKUL", GOTBLUESKUL}, - {"GOTYELWSKUL", GOTYELWSKUL}, - {"GOTREDSKULL", GOTREDSKULL}, - {"GOTINVUL", GOTINVUL}, - {"GOTBERSERK", GOTBERSERK}, - {"GOTINVIS", GOTINVIS}, - {"GOTSUIT", GOTSUIT}, - {"GOTMAP", GOTMAP}, - {"GOTVISOR", GOTVISOR}, - {"GOTMSPHERE", GOTMSPHERE}, - {"GOTCLIP", GOTCLIP}, - {"GOTCLIPBOX", GOTCLIPBOX}, - {"GOTROCKET", GOTROCKET}, - {"GOTROCKBOX", GOTROCKBOX}, - {"GOTCELL", GOTCELL}, - {"GOTCELLBOX", GOTCELLBOX}, - {"GOTSHELLS", GOTSHELLS}, - {"GOTSHELLBOX", GOTSHELLBOX}, - {"GOTBACKPACK", GOTBACKPACK}, - {"GOTBFG9000", GOTBFG9000}, - {"GOTCHAINGUN", GOTCHAINGUN}, - {"GOTCHAINSAW", GOTCHAINSAW}, - {"GOTLAUNCHER", GOTLAUNCHER}, - {"GOTPLASMA", GOTPLASMA}, - {"GOTSHOTGUN", GOTSHOTGUN}, - {"GOTSHOTGUN2", GOTSHOTGUN2}, - {"PD_BLUEO", PD_BLUEO}, /* part 3 - messages when keys are needed */ - {"PD_REDO", PD_REDO}, - {"PD_YELLOWO", PD_YELLOWO}, - {"PD_BLUEK", PD_BLUEK}, - {"PD_REDK", PD_REDK}, - {"PD_YELLOWK", PD_YELLOWK}, - {"HUSTR_MSGU", HUSTR_MSGU}, /* part 4 - multiplayer messaging */ - {"HUSTR_MESSAGESENT", HUSTR_MESSAGESENT}, - {"HUSTR_CHATMACRO0", HUSTR_CHATMACRO0}, - {"HUSTR_CHATMACRO1", HUSTR_CHATMACRO1}, - {"HUSTR_CHATMACRO2", HUSTR_CHATMACRO2}, - {"HUSTR_CHATMACRO3", HUSTR_CHATMACRO3}, - {"HUSTR_CHATMACRO4", HUSTR_CHATMACRO4}, - {"HUSTR_CHATMACRO5", HUSTR_CHATMACRO5}, - {"HUSTR_CHATMACRO6", HUSTR_CHATMACRO6}, - {"HUSTR_CHATMACRO7", HUSTR_CHATMACRO7}, - {"HUSTR_CHATMACRO8", HUSTR_CHATMACRO8}, - {"HUSTR_CHATMACRO9", HUSTR_CHATMACRO9}, - {"HUSTR_TALKTOSELF1", HUSTR_TALKTOSELF1}, - {"HUSTR_TALKTOSELF2", HUSTR_TALKTOSELF2}, - {"HUSTR_TALKTOSELF3", HUSTR_TALKTOSELF3}, - {"HUSTR_TALKTOSELF4", HUSTR_TALKTOSELF4}, - {"HUSTR_TALKTOSELF5", HUSTR_TALKTOSELF5}, - {"HUSTR_PLRGREEN", HUSTR_PLRGREEN}, - {"HUSTR_PLRINDIGO", HUSTR_PLRINDIGO}, - {"HUSTR_PLRBROWN", HUSTR_PLRBROWN}, - {"HUSTR_PLRRED", HUSTR_PLRRED}, - {"HUSTR_E1M1", HUSTR_E1M1}, /* part 5 - level names in the automap */ - {"HUSTR_E1M2", HUSTR_E1M2}, - {"HUSTR_E1M3", HUSTR_E1M3}, - {"HUSTR_E1M4", HUSTR_E1M4}, - {"HUSTR_E1M5", HUSTR_E1M5}, - {"HUSTR_E1M6", HUSTR_E1M6}, - {"HUSTR_E1M7", HUSTR_E1M7}, - {"HUSTR_E1M8", HUSTR_E1M8}, - {"HUSTR_E1M9", HUSTR_E1M9}, - {"HUSTR_E2M1", HUSTR_E2M1}, - {"HUSTR_E2M2", HUSTR_E2M2}, - {"HUSTR_E2M3", HUSTR_E2M3}, - {"HUSTR_E2M4", HUSTR_E2M4}, - {"HUSTR_E2M5", HUSTR_E2M5}, - {"HUSTR_E2M6", HUSTR_E2M6}, - {"HUSTR_E2M7", HUSTR_E2M7}, - {"HUSTR_E2M8", HUSTR_E2M8}, - {"HUSTR_E2M9", HUSTR_E2M9}, - {"HUSTR_E3M1", HUSTR_E3M1}, - {"HUSTR_E3M2", HUSTR_E3M2}, - {"HUSTR_E3M3", HUSTR_E3M3}, - {"HUSTR_E3M4", HUSTR_E3M4}, - {"HUSTR_E3M5", HUSTR_E3M5}, - {"HUSTR_E3M6", HUSTR_E3M6}, - {"HUSTR_E3M7", HUSTR_E3M7}, - {"HUSTR_E3M8", HUSTR_E3M8}, - {"HUSTR_E3M9", HUSTR_E3M9}, - {"HUSTR_E4M1", HUSTR_E4M1}, - {"HUSTR_E4M2", HUSTR_E4M2}, - {"HUSTR_E4M3", HUSTR_E4M3}, - {"HUSTR_E4M4", HUSTR_E4M4}, - {"HUSTR_E4M5", HUSTR_E4M5}, - {"HUSTR_E4M6", HUSTR_E4M6}, - {"HUSTR_E4M7", HUSTR_E4M7}, - {"HUSTR_E4M8", HUSTR_E4M8}, - {"HUSTR_E4M9", HUSTR_E4M9}, - {"HUSTR_1", HUSTR_1}, - {"HUSTR_2", HUSTR_2}, - {"HUSTR_3", HUSTR_3}, - {"HUSTR_4", HUSTR_4}, - {"HUSTR_5", HUSTR_5}, - {"HUSTR_6", HUSTR_6}, - {"HUSTR_7", HUSTR_7}, - {"HUSTR_8", HUSTR_8}, - {"HUSTR_9", HUSTR_9}, - {"HUSTR_10", HUSTR_10}, - {"HUSTR_11", HUSTR_11}, - {"HUSTR_12", HUSTR_12}, - {"HUSTR_13", HUSTR_13}, - {"HUSTR_14", HUSTR_14}, - {"HUSTR_15", HUSTR_15}, - {"HUSTR_16", HUSTR_16}, - {"HUSTR_17", HUSTR_17}, - {"HUSTR_18", HUSTR_18}, - {"HUSTR_19", HUSTR_19}, - {"HUSTR_20", HUSTR_20}, - {"HUSTR_21", HUSTR_21}, - {"HUSTR_22", HUSTR_22}, - {"HUSTR_23", HUSTR_23}, - {"HUSTR_24", HUSTR_24}, - {"HUSTR_25", HUSTR_25}, - {"HUSTR_26", HUSTR_26}, - {"HUSTR_27", HUSTR_27}, - {"HUSTR_28", HUSTR_28}, - {"HUSTR_29", HUSTR_29}, - {"HUSTR_30", HUSTR_30}, - {"HUSTR_31", HUSTR_31}, - {"HUSTR_32", HUSTR_32}, - {"PHUSTR_1", PHUSTR_1}, - {"PHUSTR_2", PHUSTR_2}, - {"PHUSTR_3", PHUSTR_3}, - {"PHUSTR_4", PHUSTR_4}, - {"PHUSTR_5", PHUSTR_5}, - {"PHUSTR_6", PHUSTR_6}, - {"PHUSTR_7", PHUSTR_7}, - {"PHUSTR_8", PHUSTR_8}, - {"PHUSTR_9", PHUSTR_9}, - {"PHUSTR_10", PHUSTR_10}, - {"PHUSTR_11", PHUSTR_11}, - {"PHUSTR_12", PHUSTR_12}, - {"PHUSTR_13", PHUSTR_13}, - {"PHUSTR_14", PHUSTR_14}, - {"PHUSTR_15", PHUSTR_15}, - {"PHUSTR_16", PHUSTR_16}, - {"PHUSTR_17", PHUSTR_17}, - {"PHUSTR_18", PHUSTR_18}, - {"PHUSTR_19", PHUSTR_19}, - {"PHUSTR_20", PHUSTR_20}, - {"PHUSTR_21", PHUSTR_21}, - {"PHUSTR_22", PHUSTR_22}, - {"PHUSTR_23", PHUSTR_23}, - {"PHUSTR_24", PHUSTR_24}, - {"PHUSTR_25", PHUSTR_25}, - {"PHUSTR_26", PHUSTR_26}, - {"PHUSTR_27", PHUSTR_27}, - {"PHUSTR_28", PHUSTR_28}, - {"PHUSTR_29", PHUSTR_29}, - {"PHUSTR_30", PHUSTR_30}, - {"PHUSTR_31", PHUSTR_31}, - {"PHUSTR_32", PHUSTR_32}, - {"THUSTR_1", THUSTR_1}, - {"THUSTR_2", THUSTR_2}, - {"THUSTR_3", THUSTR_3}, - {"THUSTR_4", THUSTR_4}, - {"THUSTR_5", THUSTR_5}, - {"THUSTR_6", THUSTR_6}, - {"THUSTR_7", THUSTR_7}, - {"THUSTR_8", THUSTR_8}, - {"THUSTR_9", THUSTR_9}, - {"THUSTR_10", THUSTR_10}, - {"THUSTR_11", THUSTR_11}, - {"THUSTR_12", THUSTR_12}, - {"THUSTR_13", THUSTR_13}, - {"THUSTR_14", THUSTR_14}, - {"THUSTR_15", THUSTR_15}, - {"THUSTR_16", THUSTR_16}, - {"THUSTR_17", THUSTR_17}, - {"THUSTR_18", THUSTR_18}, - {"THUSTR_19", THUSTR_19}, - {"THUSTR_20", THUSTR_20}, - {"THUSTR_21", THUSTR_21}, - {"THUSTR_22", THUSTR_22}, - {"THUSTR_23", THUSTR_23}, - {"THUSTR_24", THUSTR_24}, - {"THUSTR_25", THUSTR_25}, - {"THUSTR_26", THUSTR_26}, - {"THUSTR_27", THUSTR_27}, - {"THUSTR_28", THUSTR_28}, - {"THUSTR_29", THUSTR_29}, - {"THUSTR_30", THUSTR_30}, - {"THUSTR_31", THUSTR_31}, - {"THUSTR_32", THUSTR_32}, - {"AMSTR_FOLLOWON", - AMSTR_FOLLOWON}, /* part 6 - messages as a result of toggling states */ - {"AMSTR_FOLLOWOFF", AMSTR_FOLLOWOFF}, - {"AMSTR_GRIDON", AMSTR_GRIDON}, - {"AMSTR_GRIDOFF", AMSTR_GRIDOFF}, - {"AMSTR_MARKEDSPOT", AMSTR_MARKEDSPOT}, - {"AMSTR_MARKSCLEARED", AMSTR_MARKSCLEARED}, - {"STSTR_MUS", STSTR_MUS}, - {"STSTR_NOMUS", STSTR_NOMUS}, - {"STSTR_DQDON", STSTR_DQDON}, - {"STSTR_DQDOFF", STSTR_DQDOFF}, - {"STSTR_KFAADDED", STSTR_KFAADDED}, - {"STSTR_FAADDED", STSTR_FAADDED}, - {"STSTR_NCON", STSTR_NCON}, - {"STSTR_NCOFF", STSTR_NCOFF}, - {"STSTR_BEHOLD", STSTR_BEHOLD}, - {"STSTR_BEHOLDX", STSTR_BEHOLDX}, - {"STSTR_CHOPPERS", STSTR_CHOPPERS}, - {"STSTR_CLEV", STSTR_CLEV}, - {"E1TEXT", E1TEXT}, /* part 7 - episode intermission texts */ - {"E2TEXT", E2TEXT}, - {"E3TEXT", E3TEXT}, - {"E4TEXT", E4TEXT}, - {"C1TEXT", C1TEXT}, - {"C2TEXT", C2TEXT}, - {"C3TEXT", C3TEXT}, - {"C4TEXT", C4TEXT}, - {"C5TEXT", C5TEXT}, - {"C6TEXT", C6TEXT}, - {"P1TEXT", P1TEXT}, - {"P2TEXT", P2TEXT}, - {"P3TEXT", P3TEXT}, - {"P4TEXT", P4TEXT}, - {"P5TEXT", P5TEXT}, - {"P6TEXT", P6TEXT}, - {"T1TEXT", T1TEXT}, - {"T2TEXT", T2TEXT}, - {"T3TEXT", T3TEXT}, - {"T4TEXT", T4TEXT}, - {"T5TEXT", T5TEXT}, - {"T6TEXT", T6TEXT}, - {"CC_ZOMBIE", CC_ZOMBIE}, /* part 8 - creature names for the finale */ - {"CC_SHOTGUN", CC_SHOTGUN}, - {"CC_HEAVY", CC_HEAVY}, - {"CC_IMP", CC_IMP}, - {"CC_DEMON", CC_DEMON}, - {"CC_LOST", CC_LOST}, - {"CC_CACO", CC_CACO}, - {"CC_HELL", CC_HELL}, - {"CC_BARON", CC_BARON}, - {"CC_ARACH", CC_ARACH}, - {"CC_PAIN", CC_PAIN}, - {"CC_REVEN", CC_REVEN}, - {"CC_MANCU", CC_MANCU}, - {"CC_ARCH", CC_ARCH}, - {"CC_SPIDER", CC_SPIDER}, - {"CC_CYBER", CC_CYBER}, - {"CC_HERO", CC_HERO}, - {"BGFLATE1", "FLOOR4_8"}, /* part 9 - intermission tiled backgrounds */ - {"BGFLATE2", "SFLR6_1"}, - {"BGFLATE3", "MFLR8_4"}, - {"BGFLATE4", "MFLR8_3"}, - {"BGFLAT06", "SLIME16"}, - {"BGFLAT11", "RROCK14"}, - {"BGFLAT20", "RROCK07"}, - {"BGFLAT30", "RROCK17"}, - {"BGFLAT15", "RROCK13"}, - {"BGFLAT31", "RROCK19"}, - {"BGCASTCALL", "BOSSBACK"}, -}; - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -deh_section_t deh_section_bexstr = -{ - "[STRINGS]", - NULL, - deh_bex_str_start, - deh_bex_str_parse_line, - NULL, - NULL, -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static void *deh_bex_str_start(deh_context_t *context, char *line) -{ - char s[10]; - - if (sscanf(line, "%9s", s) == 0 || strncmp("[STRINGS]", s, sizeof(s))) - { - deh_warning(context, "Parse error on section start"); - } - - return NULL; -} - -static void deh_bex_str_parse_line(deh_context_t *context, char *line, - void *tag) -{ - char *variable_name; - char *value; - int i; - - if (!deh_parse_assignment(line, &variable_name, &value)) - { - deh_warning(context, "Failed to parse assignment"); - return; - } - - for (i = 0; i < arrlen(g_bex_stringtable); i++) - { - if (!strcmp(g_bex_stringtable[i].macro, variable_name)) - { - deh_add_string_replacement(g_bex_stringtable[i].string, value); - } - } -} diff --git a/games/NXDoom/src/doom/deh_cheat.c b/games/NXDoom/src/doom/deh_cheat.c deleted file mode 100644 index f01c08976..000000000 --- a/games/NXDoom/src/doom/deh_cheat.c +++ /dev/null @@ -1,179 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/deh_cheat.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * Parses "Cheat" sections in dehacked files - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -#include "doomtype.h" - -#include "am_map.h" -#include "deh_defs.h" -#include "deh_io.h" -#include "deh_main.h" -#include "st_stuff.h" - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -typedef struct -{ - const char *name; - cheatseq_t *seq; -} deh_cheat_t; - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -static void *deh_cheat_start(deh_context_t *context, char *line); -static void deh_cheat_parse_line(deh_context_t *context, char *line, - void *tag); - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static deh_cheat_t g_allcheats[] = -{ - {"Change music", &cheat_mus}, - {"Chainsaw", &cheat_choppers}, - {"God mode", &cheat_god}, - {"Ammo & Keys", &cheat_ammo}, - {"Ammo", &cheat_ammonokey}, - {"No Clipping 1", &cheat_noclip}, - {"No Clipping 2", &cheat_commercial_noclip}, - {"Invincibility", &cheat_powerup[0]}, - {"Berserk", &cheat_powerup[1]}, - {"Invisibility", &cheat_powerup[2]}, - {"Radiation Suit", &cheat_powerup[3]}, - {"Auto-map", &cheat_powerup[4]}, - {"Lite-Amp Goggles", &cheat_powerup[5]}, - {"BEHOLD menu", &cheat_powerup[6]}, - {"Level Warp", &cheat_clev}, - {"Player Position", &cheat_mypos}, - {"Map cheat", &cheat_amap}, -}; - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -deh_section_t deh_section_cheat = -{ - "Cheat", - NULL, - deh_cheat_start, - deh_cheat_parse_line, - NULL, - NULL, -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static deh_cheat_t *find_cheat_by_name(char *name) -{ - size_t i; - - for (i = 0; i < arrlen(g_allcheats); ++i) - { - if (!strcasecmp(g_allcheats[i].name, name)) return &g_allcheats[i]; - } - - return NULL; -} - -static void *deh_cheat_start(deh_context_t *context, char *line) -{ - return NULL; -} - -static void deh_cheat_parse_line(deh_context_t *context, char *line, - void *tag) -{ - deh_cheat_t *cheat; - char *variable_name; - char *value; - unsigned char *unsvalue; - unsigned int i; - - if (!deh_parse_assignment(line, &variable_name, &value)) - { - /* Failed to parse */ - - deh_warning(context, "Failed to parse assignment"); - return; - } - - unsvalue = (unsigned char *)value; - - cheat = find_cheat_by_name(variable_name); - - if (cheat == NULL) - { - deh_warning(context, "Unknown cheat '%s'", variable_name); - return; - } - - /* write the value into the cheat sequence */ - - i = 0; - - while (unsvalue[i] != 0 && unsvalue[i] != 0xff) - { - /* If the cheat length exceeds the Vanilla limit, stop. This - * does not apply if we have the limit turned off. - */ - - if (!deh_allow_long_cheats && i >= cheat->seq->sequence_len) - { - deh_warning(context, "Cheat sequence longer than supported by " - "Vanilla dehacked"); - break; - } - - if (deh_apply_cheats) - { - cheat->seq->sequence[i] = unsvalue[i]; - } - - ++i; - - /* Absolute limit - don't exceed */ - - if (i >= MAX_CHEAT_LEN - cheat->seq->parameter_chars) - { - deh_error(context, "Cheat sequence too long!"); - return; - } - } - - if (deh_apply_cheats) - { - cheat->seq->sequence[i] = '\0'; - } -} diff --git a/games/NXDoom/src/doom/deh_doom.c b/games/NXDoom/src/doom/deh_doom.c deleted file mode 100644 index 419caffa8..000000000 --- a/games/NXDoom/src/doom/deh_doom.c +++ /dev/null @@ -1,65 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/deh_doom.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * - * Top-level dehacked definitions for Doom dehacked. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "deh_defs.h" -#include "deh_main.h" -#include - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -const char *deh_signatures[] = -{ - "Patch File for DeHackEd v2.3", - "Patch File for DeHackEd v3.0", - NULL, -}; - -/* List of section types: */ - -deh_section_t *deh_section_types[] = -{ - &deh_section_ammo, - &deh_section_cheat, - &deh_section_frame, - &deh_section_misc, - &deh_section_pointer, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - &deh_section_sound, -#else - NULL, -#endif - &deh_section_text, - &deh_section_thing, - &deh_section_weapon, - &deh_section_bexstr, - NULL, -}; - -/**************************************************************************** - * Public Functions - ****************************************************************************/ diff --git a/games/NXDoom/src/doom/deh_frame.c b/games/NXDoom/src/doom/deh_frame.c deleted file mode 100644 index d5ec55216..000000000 --- a/games/NXDoom/src/doom/deh_frame.c +++ /dev/null @@ -1,198 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/deh_frame.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * Parses "Frame" sections in dehacked files - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -#include "d_items.h" -#include "doomtype.h" -#include "info.h" - -#include "deh_defs.h" -#include "deh_io.h" -#include "deh_main.h" -#include "deh_mapping.h" - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -DEH_BEGIN_MAPPING(state_mapping, state_t) -DEH_MAPPING("Sprite number", sprite) -DEH_MAPPING("Sprite subnumber", frame) -DEH_MAPPING("Duration", tics) -DEH_MAPPING("Next frame", nextstate) -#if 0 -DEH_MAPPING("Unknown 1", misc1) -DEH_MAPPING("Unknown 2", misc2) -#endif -DEH_UNSUPPORTED_MAPPING("Codep frame") -DEH_END_MAPPING - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -static void *deh_frame_start(deh_context_t *context, char *line); -static void deh_frame_overflow(deh_context_t *context, char *varname, - int value); -static void deh_frame_parse_line(deh_context_t *context, char *line, - void *tag); -static void deh_frame_sha1_sum(SHA1_CTX *context); - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -deh_section_t deh_section_frame = -{ - "Frame", - NULL, - deh_frame_start, - deh_frame_parse_line, - NULL, - deh_frame_sha1_sum, -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static void *deh_frame_start(deh_context_t *context, char *line) -{ - int frame_number = 0; - state_t *state; - - if (sscanf(line, "Frame %i", &frame_number) != 1) - { - deh_warning(context, "Parse error on section start"); - return NULL; - } - - if (frame_number < 0 || frame_number >= NUMSTATES) - { - deh_warning(context, "Invalid frame number: %i", frame_number); - return NULL; - } - - if (frame_number >= DEH_VANILLA_NUMSTATES) - { - deh_warning(context, - "Attempt to modify frame %i: this will cause " - "problems in Vanilla dehacked.", - frame_number); - } - - state = &states[frame_number]; - - return state; -} - -/* Simulate a frame overflow: Doom has 967 frames in the states[] array, but - * DOS dehacked internally only allocates memory for 966. As a result, - * attempts to set frame 966 (the last frame) will overflow the dehacked - * array and overwrite the weaponinfo[] array instead. - * - * This is noticeable in Batman Doom where it is impossible to switch weapons - * away from the fist once selected. - */ - -static void deh_frame_overflow(deh_context_t *context, char *varname, - int value) -{ - if (!strcasecmp(varname, "Duration")) - { - weaponinfo[0].ammo = value; - } - else if (!strcasecmp(varname, "Codep frame")) - { - weaponinfo[0].upstate = value; - } - else if (!strcasecmp(varname, "Next frame")) - { - weaponinfo[0].downstate = value; - } - else if (!strcasecmp(varname, "Unknown 1")) - { - weaponinfo[0].readystate = value; - } - else if (!strcasecmp(varname, "Unknown 2")) - { - weaponinfo[0].atkstate = value; - } - else - { - deh_error(context, "Unable to simulate frame overflow: field '%s'", - varname); - } -} - -static void deh_frame_parse_line(deh_context_t *context, char *line, - void *tag) -{ - state_t *state; - char *variable_name; - char *value; - int ivalue; - - if (tag == NULL) return; - - state = (state_t *)tag; - - /* Parse the assignment */ - - if (!deh_parse_assignment(line, &variable_name, &value)) - { - /* Failed to parse */ - - deh_warning(context, "Failed to parse assignment"); - return; - } - - /* all values are integers */ - - ivalue = atoi(value); - - if (state == &states[NUMSTATES - 1]) - { - deh_frame_overflow(context, variable_name, ivalue); - } - else - { - /* set the appropriate field */ - - deh_set_mapping(context, &state_mapping, state, variable_name, ivalue); - } -} - -static void deh_frame_sha1_sum(SHA1_CTX *context) -{ - int i; - - for (i = 0; i < NUMSTATES; ++i) - { - deh_struct_sha1_sum(context, &state_mapping, &states[i]); - } -} diff --git a/games/NXDoom/src/doom/deh_misc.c b/games/NXDoom/src/doom/deh_misc.c deleted file mode 100644 index e932ce3df..000000000 --- a/games/NXDoom/src/doom/deh_misc.c +++ /dev/null @@ -1,281 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/deh_misc.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * Parses "Misc" sections in dehacked files - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -#include "deh_defs.h" -#include "deh_io.h" -#include "deh_main.h" -#include "deh_misc.h" -#include "doomtype.h" - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -struct misc_settings -{ - const char *deh_name; - int *value; -}; - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -static void *deh_misc_start(deh_context_t *context, char *line); -static void deh_misc_parse_line(deh_context_t *context, char *line, - void *tag); -static void deh_misc_sha1_sum(SHA1_CTX *context); - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/* Dehacked: "Initial Health" - * This is the initial health a player has when starting anew. - * See g_player_reborn in g_game.c - */ - -int deh_initial_health = DEH_DEFAULT_INITIAL_HEALTH; - -/* Dehacked: "Initial bullets" - * This is the number of bullets the player has when starting anew. - * See g_player_reborn in g_game.c - */ - -int deh_initial_bullets = DEH_DEFAULT_INITIAL_BULLETS; - -/* Dehacked: "Max Health" - * This is the maximum health that can be reached using health - * potions. See p_touch_special_thing in p_inter.c - */ - -int deh_max_health = DEH_DEFAULT_MAX_HEALTH; - -/* Dehacked: "Max Armor" - * This is the maximum armor which can be reached by picking up - * armor helmets. See p_touch_special_thing in p_inter.c - */ - -int deh_max_armor = DEH_DEFAULT_MAX_ARMOR; - -/* Dehacked: "Green Armor Class" - * This is the armor class that is given when picking up the green - * armor or an armor helmet. See p_touch_special_thing in p_inter.c - * - * DOS dehacked only modifies the behavior of the green armor shirt, - * the armor class set by armor helmets is not affected. - */ - -int deh_green_armor_class = DEH_DEFAULT_GREEN_ARMOR_CLASS; - -/* Dehacked: "Blue Armor Class" - * This is the armor class that is given when picking up the blue - * armor or a megasphere. See p_touch_special_thing in p_inter.c - * - * DOS dehacked only modifies the MegaArmor behavior and not - * the MegaSphere, which always gives armor type 2. - */ - -int deh_blue_armor_class = DEH_DEFAULT_BLUE_ARMOR_CLASS; - -/* Dehacked: "Max soulsphere" - * The maximum health which can be reached by picking up the - * soulsphere. See p_touch_special_thing in p_inter.c - */ - -int deh_max_soulsphere = DEH_DEFAULT_MAX_SOULSPHERE; - -/* Dehacked: "Soulsphere health" - * The amount of health bonus that picking up a soulsphere - * gives. See p_touch_special_thing in p_inter.c - */ - -int deh_soulsphere_health = DEH_DEFAULT_SOULSPHERE_HEALTH; - -/* Dehacked: "Megasphere health" - * This is what the health is set to after picking up a - * megasphere. See p_touch_special_thing in p_inter.c - */ - -int deh_megasphere_health = DEH_DEFAULT_MEGASPHERE_HEALTH; - -/* Dehacked: "God mode health" - * This is what the health value is set to when cheating using - * the IDDQD god mode cheat. See st_responder in st_stuff.c - */ - -int deh_god_mode_health = DEH_DEFAULT_GOD_MODE_HEALTH; - -/* Dehacked: "IDFA Armor" - * This is what the armor is set to when using the IDFA cheat. - * See st_responder in st_stuff.c - */ - -int deh_idfa_armor = DEH_DEFAULT_IDFA_ARMOR; - -/* Dehacked: "IDFA Armor Class" - * This is what the armor class is set to when using the IDFA cheat. - * See st_responder in st_stuff.c - */ - -int deh_idfa_armor_class = DEH_DEFAULT_IDFA_ARMOR_CLASS; - -/* Dehacked: "IDKFA Armor" - * This is what the armor is set to when using the IDKFA cheat. - * See st_responder in st_stuff.c - */ - -int deh_idkfa_armor = DEH_DEFAULT_IDKFA_ARMOR; - -/* Dehacked: "IDKFA Armor Class" - * This is what the armor class is set to when using the IDKFA cheat. - * See st_responder in st_stuff.c - */ - -int deh_idkfa_armor_class = DEH_DEFAULT_IDKFA_ARMOR_CLASS; - -/* Dehacked: "BFG Cells/Shot" - * This is the number of CELLs firing the BFG uses up. - * See p_check_ammo and a_fire_bfg in p_pspr.c - */ - -int deh_bfg_cells_per_shot = DEH_DEFAULT_BFG_CELLS_PER_SHOT; - -/* Dehacked: "Monsters infight" - * This controls whether monsters can harm other monsters of the same - * species. For example, whether an imp fireball will damage other - * imps. The value of this in dehacked patches is weird - '202' means - * off, while '221' means on. - * - * See pit_check_thing in p_map.c - */ - -int deh_species_infighting = DEH_DEFAULT_SPECIES_INFIGHTING; - -deh_section_t deh_section_misc = -{ - "Misc", - NULL, - deh_misc_start, - deh_misc_parse_line, - NULL, - deh_misc_sha1_sum, -}; - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static struct misc_settings misc_settings[] = -{ - {"Initial Health", &deh_initial_health}, - {"Initial Bullets", &deh_initial_bullets}, - {"Max Health", &deh_max_health}, - {"Max Armor", &deh_max_armor}, - {"Green Armor Class", &deh_green_armor_class}, - {"Blue Armor Class", &deh_blue_armor_class}, - {"Max Soulsphere", &deh_max_soulsphere}, - {"Soulsphere Health", &deh_soulsphere_health}, - {"Megasphere Health", &deh_megasphere_health}, - {"God Mode Health", &deh_god_mode_health}, - {"IDFA Armor", &deh_idfa_armor}, - {"IDFA Armor Class", &deh_idfa_armor_class}, - {"IDKFA Armor", &deh_idkfa_armor}, - {"IDKFA Armor Class", &deh_idkfa_armor_class}, - {"BFG Cells/Shot", &deh_bfg_cells_per_shot}, -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static void *deh_misc_start(deh_context_t *context, char *line) -{ - return NULL; -} - -static void deh_misc_parse_line(deh_context_t *context, char *line, - void *tag) -{ - char *variable_name; - char *value; - int ivalue; - size_t i; - - if (!deh_parse_assignment(line, &variable_name, &value)) - { - /* Failed to parse */ - - deh_warning(context, "Failed to parse assignment"); - return; - } - - ivalue = atoi(value); - - if (!strcasecmp(variable_name, "Monsters Infight")) - { - /* See notes above. */ - - if (ivalue == 202) - { - deh_species_infighting = 0; - } - else if (ivalue == 221) - { - deh_species_infighting = 1; - } - else - { - deh_warning(context, "Invalid value for 'Monsters Infight': %i", - ivalue); - } - - return; - } - - for (i = 0; i < arrlen(misc_settings); ++i) - { - if (!strcasecmp(variable_name, misc_settings[i].deh_name)) - { - *misc_settings[i].value = ivalue; - return; - } - } - - deh_warning(context, "Unknown Misc variable '%s'", variable_name); -} - -static void deh_misc_sha1_sum(SHA1_CTX *context) -{ - unsigned int i; - - for (i = 0; i < arrlen(misc_settings); ++i) - { - sha1_updateint32(context, *misc_settings[i].value); - } -} diff --git a/games/NXDoom/src/doom/deh_misc.h b/games/NXDoom/src/doom/deh_misc.h deleted file mode 100644 index a55eb6452..000000000 --- a/games/NXDoom/src/doom/deh_misc.h +++ /dev/null @@ -1,90 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/deh_misc.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * Parses "Misc" sections in dehacked files - * - ****************************************************************************/ - -#ifndef DEH_MISC_H -#define DEH_MISC_H - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define DEH_DEFAULT_INITIAL_HEALTH 100 -#define DEH_DEFAULT_INITIAL_BULLETS 50 -#define DEH_DEFAULT_MAX_HEALTH 200 -#define DEH_DEFAULT_MAX_ARMOR 200 -#define DEH_DEFAULT_GREEN_ARMOR_CLASS 1 -#define DEH_DEFAULT_BLUE_ARMOR_CLASS 2 -#define DEH_DEFAULT_MAX_SOULSPHERE 200 -#define DEH_DEFAULT_SOULSPHERE_HEALTH 100 -#define DEH_DEFAULT_MEGASPHERE_HEALTH 200 -#define DEH_DEFAULT_GOD_MODE_HEALTH 100 -#define DEH_DEFAULT_IDFA_ARMOR 200 -#define DEH_DEFAULT_IDFA_ARMOR_CLASS 2 -#define DEH_DEFAULT_IDKFA_ARMOR 200 -#define DEH_DEFAULT_IDKFA_ARMOR_CLASS 2 -#define DEH_DEFAULT_BFG_CELLS_PER_SHOT 40 -#define DEH_DEFAULT_SPECIES_INFIGHTING 0 - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -extern int deh_initial_health; -extern int deh_initial_bullets; -extern int deh_max_health; -extern int deh_max_armor; -extern int deh_green_armor_class; -extern int deh_blue_armor_class; -extern int deh_max_soulsphere; -extern int deh_soulsphere_health; -extern int deh_megasphere_health; -extern int deh_god_mode_health; -extern int deh_idfa_armor; -extern int deh_idfa_armor_class; -extern int deh_idkfa_armor; -extern int deh_idkfa_armor_class; -extern int deh_bfg_cells_per_shot; -extern int deh_species_infighting; - -#if 0 - -/* To compile without dehacked, it's possible to use these: */ - -#define deh_initial_health DEH_DEFAULT_INITIAL_HEALTH -#define deh_initial_bullets DEH_DEFAULT_INITIAL_BULLETS -#define deh_max_health DEH_DEFAULT_MAX_HEALTH -#define deh_max_armor DEH_DEFAULT_MAX_ARMOR -#define deh_green_armor_class DEH_DEFAULT_GREEN_ARMOR_CLASS -#define deh_blue_armor_class DEH_DEFAULT_BLUE_ARMOR_CLASS -#define deh_max_soulsphere DEH_DEFAULT_MAX_SOULSPHERE -#define deh_soulsphere_health DEH_DEFAULT_SOULSPHERE_HEALTH -#define deh_megasphere_health DEH_DEFAULT_MEGASPHERE_HEALTH -#define deh_god_mode_health DEH_DEFAULT_GOD_MODE_HEALTH -#define deh_idfa_armor DEH_DEFAULT_IDFA_ARMOR -#define deh_idfa_armor_class DEH_DEFAULT_IDFA_ARMOR_CLASS -#define deh_idkfa_armor DEH_DEFAULT_IDKFA_ARMOR -#define deh_idkfa_armor_class DEH_DEFAULT_IDKFA_ARMOR_CLASS -#define deh_bfg_cells_per_shot DEH_DEFAULT_BFG_CELLS_PER_SHOT -#define deh_species_infighting DEH_DEFAULT_SPECIES_INFIGHTING - -#endif - -#endif /* DEH_MISC_H */ diff --git a/games/NXDoom/src/doom/deh_ptr.c b/games/NXDoom/src/doom/deh_ptr.c deleted file mode 100644 index 78c14c75e..000000000 --- a/games/NXDoom/src/doom/deh_ptr.c +++ /dev/null @@ -1,172 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/deh_ptr.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * Parses Action Pointer entries in dehacked files - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include - -#include "doomtype.h" -#include "info.h" - -#include "deh_defs.h" -#include "deh_io.h" -#include "deh_main.h" - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -static void deh_pointer_init(void); -static void *deh_pointer_start(deh_context_t *context, char *line); -static void deh_pointer_parse_line(deh_context_t *context, char *line, - void *tag); -static void deh_pointer_sha1_sum(SHA1_CTX *context); - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static actionf_t codeptrs[NUMSTATES]; - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -deh_section_t deh_section_pointer = -{ - "Pointer", - deh_pointer_init, - deh_pointer_start, - deh_pointer_parse_line, - NULL, - deh_pointer_sha1_sum, -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static int code_pointer_index(actionf_t *ptr) -{ - int i; - - for (i = 0; i < NUMSTATES; ++i) - { - if (!memcmp(&codeptrs[i], ptr, sizeof(actionf_t))) - { - return i; - } - } - - return -1; -} - -static void deh_pointer_init(void) -{ - int i; - - /* Initialize list of dehacked pointers */ - - for (i = 0; i < NUMSTATES; ++i) - codeptrs[i] = states[i].action; -} - -static void *deh_pointer_start(deh_context_t *context, char *line) -{ - int frame_number = 0; - - /* FIXME: can the third argument here be something other than "Frame" - * or are we ok? - */ - - if (sscanf(line, "Pointer %*i (%*s %i)", &frame_number) != 1) - { - deh_warning(context, "Parse error on section start"); - return NULL; - } - - if (frame_number < 0 || frame_number >= NUMSTATES) - { - deh_warning(context, "Invalid frame number: %i", frame_number); - return NULL; - } - - return &states[frame_number]; -} - -static void deh_pointer_parse_line(deh_context_t *context, char *line, - void *tag) -{ - state_t *state; - char *variable_name; - char *value; - int ivalue; - - if (tag == NULL) return; - - state = (state_t *)tag; - - /* Parse the assignment */ - - if (!deh_parse_assignment(line, &variable_name, &value)) - { - /* Failed to parse */ - - deh_warning(context, "Failed to parse assignment"); - return; - } - - /* all values are integers */ - - ivalue = atoi(value); - - /* set the appropriate field */ - - if (!strcasecmp(variable_name, "Codep frame")) - { - if (ivalue < 0 || ivalue >= NUMSTATES) - { - deh_warning(context, "Invalid state '%i'", ivalue); - } - else - { - state->action = codeptrs[ivalue]; - } - } - else - { - deh_warning(context, "Unknown variable name '%s'", variable_name); - } -} - -static void deh_pointer_sha1_sum(SHA1_CTX *context) -{ - int i; - - for (i = 0; i < NUMSTATES; ++i) - { - sha1_updateint32(context, code_pointer_index(&states[i].action)); - } -} diff --git a/games/NXDoom/src/doom/deh_sound.c b/games/NXDoom/src/doom/deh_sound.c deleted file mode 100644 index e3a8d12c7..000000000 --- a/games/NXDoom/src/doom/deh_sound.c +++ /dev/null @@ -1,133 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/deh_sound.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * Parses "Sound" sections in dehacked files - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -#include "deh_defs.h" -#include "deh_main.h" -#include "deh_mapping.h" -#include "doomtype.h" -#include "sounds.h" - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -DEH_BEGIN_MAPPING(sound_mapping, sfxinfo_t) -DEH_UNSUPPORTED_MAPPING("Offset") -DEH_UNSUPPORTED_MAPPING("Zero/One") -DEH_MAPPING("Value", priority) -DEH_MAPPING("Zero 1", link) -DEH_MAPPING("Zero 2", pitch) -DEH_MAPPING("Zero 3", volume) -DEH_UNSUPPORTED_MAPPING("Zero 4") -DEH_MAPPING("Neg. One 1", usefulness) -DEH_MAPPING("Neg. One 2", lumpnum) -DEH_END_MAPPING - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -static void *deh_sound_start(deh_context_t *context, char *line); -static void deh_sound_parse_line(deh_context_t *context, char *line, - void *tag); - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -deh_section_t deh_section_sound = -{ - "Sound", - NULL, - deh_sound_start, - deh_sound_parse_line, - NULL, - NULL, -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static void *deh_sound_start(deh_context_t *context, char *line) -{ - int sound_number = 0; - - if (sscanf(line, "Sound %i", &sound_number) != 1) - { - deh_warning(context, "Parse error on section start"); - return NULL; - } - - if (sound_number < 0 || sound_number >= SFX_NUMSFX) - { - deh_warning(context, "Invalid sound number: %i", sound_number); - return NULL; - } - - if (sound_number >= DEH_VANILLA_NUMSFX) - { - deh_warning(context, - "Attempt to modify SFX %i. This will cause " - "problems in Vanilla dehacked.", - sound_number); - } - - return &s_sfx[sound_number]; -} - -static void deh_sound_parse_line(deh_context_t *context, char *line, - void *tag) -{ - sfxinfo_t *sfx; - char *variable_name; - char *value; - int ivalue; - - if (tag == NULL) return; - - sfx = (sfxinfo_t *)tag; - - /* Parse the assignment */ - - if (!deh_parse_assignment(line, &variable_name, &value)) - { - /* Failed to parse */ - - deh_warning(context, "Failed to parse assignment"); - return; - } - - /* all values are integers */ - - ivalue = atoi(value); - - /* Set the field value */ - - deh_set_mapping(context, &sound_mapping, sfx, variable_name, ivalue); -} diff --git a/games/NXDoom/src/doom/deh_thing.c b/games/NXDoom/src/doom/deh_thing.c deleted file mode 100644 index 964b423b2..000000000 --- a/games/NXDoom/src/doom/deh_thing.c +++ /dev/null @@ -1,161 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/deh_thing.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * Parses "Thing" sections in dehacked files - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -#include "doomtype.h" - -#include "deh_defs.h" -#include "deh_main.h" -#include "deh_mapping.h" - -#include "info.h" - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -DEH_BEGIN_MAPPING(thing_mapping, mobjinfo_t) -DEH_MAPPING("Bits", flags) -DEH_MAPPING("Width", radius) -DEH_MAPPING("Height", height) -DEH_MAPPING("Mass", mass) -DEH_MAPPING("Speed", speed) -DEH_MAPPING("ID #", doomednum) -DEH_MAPPING("Hit points", spawnhealth) -DEH_MAPPING("Initial frame", spawnstate) -DEH_MAPPING("First moving frame", seestate) -DEH_MAPPING("Injury frame", painstate) -DEH_MAPPING("Pain chance", painchance) -DEH_MAPPING("Close attack frame", meleestate) -DEH_MAPPING("Far attack frame", missilestate) -DEH_MAPPING("Death frame", deathstate) -DEH_MAPPING("Exploding frame", xdeathstate) -DEH_MAPPING("Respawn frame", raisestate) -DEH_MAPPING("Missile damage", damage) -#ifdef CONFIG_GAMES_NXDOOM_SOUND -DEH_MAPPING("Reaction time", reactiontime) -DEH_MAPPING("Alert sound", seesound) -DEH_MAPPING("Attack sound", attacksound) -DEH_MAPPING("Pain sound", painsound) -DEH_MAPPING("Death sound", deathsound) -DEH_MAPPING("Action sound", activesound) -#endif -DEH_END_MAPPING - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -static void *deh_thing_start(deh_context_t *context, char *line); -static void deh_thing_parse_line(deh_context_t *context, char *line, - void *tag); -static void deh_thing_sha1_sum(SHA1_CTX *context); - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -deh_section_t deh_section_thing = -{ - "Thing", - NULL, - deh_thing_start, - deh_thing_parse_line, - NULL, - deh_thing_sha1_sum, -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static void *deh_thing_start(deh_context_t *context, char *line) -{ - int thing_number = 0; - mobjinfo_t *mobj; - - if (sscanf(line, "Thing %i", &thing_number) != 1) - { - deh_warning(context, "Parse error on section start"); - return NULL; - } - - /* dehacked files are indexed from 1 */ - - --thing_number; - - if (thing_number < 0 || thing_number >= NUMMOBJTYPES) - { - deh_warning(context, "Invalid thing number: %i", thing_number); - return NULL; - } - - mobj = &mobjinfo[thing_number]; - - return mobj; -} - -static void deh_thing_parse_line(deh_context_t *context, char *line, - void *tag) -{ - mobjinfo_t *mobj; - char *variable_name; - char *value; - int ivalue; - - if (tag == NULL) return; - - mobj = (mobjinfo_t *)tag; - - /* Parse the assignment */ - - if (!deh_parse_assignment(line, &variable_name, &value)) - { - /* Failed to parse */ - - deh_warning(context, "Failed to parse assignment"); - return; - } - - /* all values are integers */ - - ivalue = atoi(value); - - /* Set the field value */ - - deh_set_mapping(context, &thing_mapping, mobj, variable_name, ivalue); -} - -static void deh_thing_sha1_sum(SHA1_CTX *context) -{ - int i; - - for (i = 0; i < NUMMOBJTYPES; ++i) - { - deh_struct_sha1_sum(context, &thing_mapping, &mobjinfo[i]); - } -} diff --git a/games/NXDoom/src/doom/deh_weapon.c b/games/NXDoom/src/doom/deh_weapon.c deleted file mode 100644 index 7c2ea08c3..000000000 --- a/games/NXDoom/src/doom/deh_weapon.c +++ /dev/null @@ -1,131 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/deh_weapon.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * Parses "Weapon" sections in dehacked files - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include - -#include "doomtype.h" - -#include "d_items.h" - -#include "deh_defs.h" -#include "deh_main.h" -#include "deh_mapping.h" - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -DEH_BEGIN_MAPPING(weapon_mapping, weaponinfo_t) -DEH_MAPPING("Ammo type", ammo) -DEH_MAPPING("Deselect frame", upstate) -DEH_MAPPING("Select frame", downstate) -DEH_MAPPING("Bobbing frame", readystate) -DEH_MAPPING("Shooting frame", atkstate) -DEH_MAPPING("Firing frame", flashstate) -DEH_END_MAPPING - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -static void *deh_weapon_start(deh_context_t *context, char *line); -static void deh_weapon_parse_line(deh_context_t *context, char *line, - void *tag); -static void deh_weapon_sha1_sum(SHA1_CTX *context); - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -deh_section_t deh_section_weapon = -{ - "Weapon", - NULL, - deh_weapon_start, - deh_weapon_parse_line, - NULL, - deh_weapon_sha1_sum, -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static void *deh_weapon_start(deh_context_t *context, char *line) -{ - int weapon_number = 0; - - if (sscanf(line, "Weapon %i", &weapon_number) != 1) - { - deh_warning(context, "Parse error on section start"); - return NULL; - } - - if (weapon_number < 0 || weapon_number >= NUMWEAPONS) - { - deh_warning(context, "Invalid weapon number: %i", weapon_number); - return NULL; - } - - return &weaponinfo[weapon_number]; -} - -static void deh_weapon_parse_line(deh_context_t *context, char *line, - void *tag) -{ - char *variable_name; - char *value; - weaponinfo_t *weapon; - int ivalue; - - if (tag == NULL) return; - - weapon = (weaponinfo_t *)tag; - - if (!deh_parse_assignment(line, &variable_name, &value)) - { - /* Failed to parse */ - - deh_warning(context, "Failed to parse assignment"); - return; - } - - ivalue = atoi(value); - - deh_set_mapping(context, &weapon_mapping, weapon, variable_name, ivalue); -} - -static void deh_weapon_sha1_sum(SHA1_CTX *context) -{ - int i; - - for (i = 0; i < NUMWEAPONS; ++i) - { - deh_struct_sha1_sum(context, &weapon_mapping, &weaponinfo[i]); - } -} - diff --git a/games/NXDoom/src/doom/doomdata.h b/games/NXDoom/src/doom/doomdata.h deleted file mode 100644 index ede23cf5e..000000000 --- a/games/NXDoom/src/doom/doomdata.h +++ /dev/null @@ -1,248 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/doomdata.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * all external data is defined here - * most of the data is loaded into different structures at run time - * some internal structures shared by many modules are here - * - ****************************************************************************/ - -#ifndef __DOOMDATA__ -#define __DOOMDATA__ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -/* The most basic types we use, portability. */ - -#include "doomtype.h" - -/* Some global defines, that configure the game. */ - -#include "doomdef.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* LineDef attributes. */ - -/* Solid, is an obstacle. */ - -#define ML_BLOCKING 1 - -/* Blocks monsters only. */ - -#define ML_BLOCKMONSTERS 2 - -/* Backside will not be present at all if not two sided. */ - -#define ML_TWOSIDED 4 - -/* If a texture is pegged, the texture will have the end exposed to air held - * constant at the top or bottom of the texture (stairs or pulled down - * things) and will move with a height change of one of the neighbor sectors. - * - * Unpegged textures always have the first row of the texture at the top - * pixel the line for both top and bottom textures (use next to windows). - */ - -/* upper texture unpegged */ - -#define ML_DONTPEGTOP 8 - -/* lower texture unpegged */ - -#define ML_DONTPEGBOTTOM 16 - -/* In AutoMap: don't map as two sided: IT'S A SECRET! */ - -#define ML_SECRET 32 - -/* Sound rendering: don't let sound cross two of these. */ - -#define ML_SOUNDBLOCK 64 - -/* Don't draw on the automap at all. */ - -#define ML_DONTDRAW 128 - -/* Set if already seen, thus drawn in automap. */ - -#define ML_MAPPED 256 - -/* Indicate a leaf. */ - -#define NF_SUBSECTOR 0x8000 - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -/* Map level types. - * The following data structures define the persistent format - * used in the lumps of the WAD files. - */ - -/* Lump order in a map WAD: each map needs a couple of lumps - * to provide a complete scene geometry description. - */ - -enum -{ - ML_LABEL, /* A separator, name, ExMx or MAPxx */ - ML_THINGS, /* Monsters, items.. */ - ML_LINEDEFS, /* LineDefs, from editing */ - ML_SIDEDEFS, /* SideDefs, from editing */ - ML_VERTICES, /* Vertices, edited and BSP splits generated */ - ML_SEGS, /* LineSegs, from LineDefs split by BSP */ - ML_SSECTORS, /* SubSectors, list of LineSegs */ - ML_NODES, /* BSP nodes */ - ML_SECTORS, /* Sectors, from editing */ - ML_REJECT, /* LUT, sector-sector visibility */ - ML_BLOCKMAP /* LUT, motion clipping, walls/grid element */ -}; - -/* A single Vertex. */ - -begin_packed_struct struct mapvertex_t -{ - short x; - short y; -} end_packed_struct; - -typedef struct mapvertex_t mapvertex_t; - -/* A SideDef, defining the visual appearance of a wall, by setting textures - * and offsets. - */ - -begin_packed_struct struct mapsidedef_t -{ - short textureoffset; - short rowoffset; - char toptexture[8]; - char bottomtexture[8]; - char midtexture[8]; - short sector; -} end_packed_struct; - -typedef struct mapsidedef_t mapsidedef_t; - -/* A LineDef, as used for editing, and as input to the BSP builder. - */ - -begin_packed_struct struct maplinedef_t -{ - short v1; - short v2; - short flags; - short special; - short tag; - - /* sidenum[1] will be -1 if one sided */ - - short sidenum[2]; -} end_packed_struct; - -typedef struct maplinedef_t maplinedef_t; - -/* Sector definition, from editing. */ - -begin_packed_struct struct mapsector_t -{ - short floorheight; - short ceilingheight; - char floorpic[8]; - char ceilingpic[8]; - short lightlevel; - short special; - short tag; -} end_packed_struct; - -typedef struct mapsector_t mapsector_t; - -/* SubSector, as generated by BSP. */ - -begin_packed_struct struct mapsubsector_t -{ - short numsegs; - - /* Index of first one, segs are stored sequentially. */ - - short firstseg; -} end_packed_struct; - -typedef struct mapsubsector_t mapsubsector_t; - -/* LineSeg, generated by splitting LineDefs using partition lines selected by - * BSP builder. - */ - -begin_packed_struct struct mapseg_t -{ - short v1; - short v2; - short angle; - short linedef; - short side; - short offset; -} end_packed_struct; - -typedef struct mapseg_t mapseg_t; - -/* BSP node structure. */ - -begin_packed_struct struct mapnode_t -{ - /* Partition line from (x,y) to x+dx,y+dy */ - - short x; - short y; - short dx; - short dy; - - /* Bounding box for each child, clip against view frustum. */ - - short bbox[2][4]; - - /* If NF_SUBSECTOR its a subsector, else it's a node of another subtree. */ - - unsigned short children[2]; -} end_packed_struct; - -typedef struct mapnode_t mapnode_t; - -/* Thing definition, position, orientation and type, plus skill/visibility - * flags and attributes. - */ - -begin_packed_struct struct mapthing_t -{ - short x; - short y; - short angle; - short type; - short options; -} end_packed_struct; - -typedef struct mapthing_t mapthing_t; - -#endif /* __DOOMDATA__ */ diff --git a/games/NXDoom/src/doom/doomdef.c b/games/NXDoom/src/doom/doomdef.c deleted file mode 100644 index 5cc227884..000000000 --- a/games/NXDoom/src/doom/doomdef.c +++ /dev/null @@ -1,33 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/doomdef.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * DoomDef - basic defines for DOOM, e.g. Version, game mode - * and skill level, and display parameters. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "doomdef.h" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ diff --git a/games/NXDoom/src/doom/doomdef.h b/games/NXDoom/src/doom/doomdef.h deleted file mode 100644 index cf00f12ee..000000000 --- a/games/NXDoom/src/doom/doomdef.h +++ /dev/null @@ -1,171 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/doomdef.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Internally used data structures for virtually everything, lots of other - * stuff. - * - ****************************************************************************/ - -#ifndef __DOOMDEF__ -#define __DOOMDEF__ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -#include "d_mode.h" -#include "doomtype.h" -#include "i_timer.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* DOOM version */ - -#define DOOM_VERSION 109 - -/* Version code for cph's longtics hack ("v1.91") */ - -#define DOOM_191_VERSION 111 - -/* The maximum number of players, multiplayer/networking. */ - -#define MAXPLAYERS 4 - -/* Difficulty/skill settings/filters. */ - -/* Skill flags. */ - -#define MTF_EASY 1 -#define MTF_NORMAL 2 -#define MTF_HARD 4 - -/* Deaf monsters/do not react to sound. */ - -#define MTF_AMBUSH 8 - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -/* The current state of the game: whether we are playing, gazing at the - * intermission screen, the game final animation, or a demo. - */ - -typedef enum -{ - GS_LEVEL, - GS_INTERMISSION, - GS_FINALE, - GS_DEMOSCREEN, -} gamestate_t; - -typedef enum -{ - ga_nothing, - ga_loadlevel, - ga_newgame, - ga_loadgame, - ga_savegame, - ga_playdemo, - ga_completed, - ga_victory, - ga_worlddone, - ga_screenshot -} gameaction_t; - -/* Key cards. */ - -typedef enum -{ - it_bluecard, - it_yellowcard, - it_redcard, - it_blueskull, - it_yellowskull, - it_redskull, - - NUMCARDS -} card_t; - -/* The defined weapons, including a marker indicating user has not changed - * weapon. - */ - -typedef enum -{ - wp_fist, - wp_pistol, - wp_shotgun, - wp_chaingun, - wp_missile, - wp_plasma, - wp_bfg, - wp_chainsaw, - wp_supershotgun, - - NUMWEAPONS, - - /* No pending weapon change. */ - - wp_nochange -} weapontype_t; - -/* Ammunition types defined. */ - -typedef enum -{ - am_clip, /* Pistol / chaingun ammo. */ - am_shell, /* Shotgun / double barreled shotgun. */ - am_cell, /* Plasma rifle, BFG. */ - am_misl, /* Missile launcher. */ - NUMAMMO, - am_noammo /* Unlimited for chainsaw / fist. */ -} ammotype_t; - -/* Power up artifacts. */ - -typedef enum -{ - pw_invulnerability, - pw_strength, - pw_invisibility, - pw_ironfeet, - pw_allmap, - pw_infrared, - NUMPOWERS -} powertype_t; - -/* Power up durations, how many seconds till expiration, assuming TICRATE is - * 35 ticks/second. - */ - -typedef enum -{ - INVULNTICS = (30 * TICRATE), - INVISTICS = (60 * TICRATE), - INFRATICS = (120 * TICRATE), - IRONTICS = (60 * TICRATE) -} powerduration_t; - -#endif /* __DOOMDEF__ */ diff --git a/games/NXDoom/src/doom/doomstat.c b/games/NXDoom/src/doom/doomstat.c deleted file mode 100644 index 5f38dd84c..000000000 --- a/games/NXDoom/src/doom/doomstat.c +++ /dev/null @@ -1,49 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/doomstat.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Put all global state variables here. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include "doomstat.h" - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/* Game Mode - identify IWAD as shareware, retail etc. */ - -game_mode_t gamemode = indetermined; -gamemission_t gamemission = doom; -game_version_t gameversion = exe_final2; -game_variant_t gamevariant = vanilla; - -/* Set if homebrew PWAD stuff has been added. */ - -boolean modifiedgame; - -/**************************************************************************** - * Public Functions - ****************************************************************************/ diff --git a/games/NXDoom/src/doom/doomstat.h b/games/NXDoom/src/doom/doomstat.h deleted file mode 100644 index 55f31f130..000000000 --- a/games/NXDoom/src/doom/doomstat.h +++ /dev/null @@ -1,273 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/doomstat.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * All the global variables that store the internal state. - * Theoretically speaking, the internal state of the engine - * should be found by looking at the variables collected - * here, and every relevant module will have to include - * this header file. - * In practice, things are a bit messy. - * - ****************************************************************************/ - -#ifndef __D_STATE__ -#define __D_STATE__ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -/* We need globally shared data structures, for defining the global state - * variables. - */ - -#include "d_loop.h" -#include "doomdata.h" - -/* We need the player data structure as well. */ - -#include "d_player.h" - -/* Game mode/mission */ - -#include "d_mode.h" - -#include "net_defs.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* Convenience macro. - * 'gamemission' can be equal to pack_chex or pack_hacx, but these are - * just modified versions of doom and doom2, and should be interpreted - * as the same most of the time. - */ - -#define logical_gamemission \ - (gamemission == pack_chex ? doom \ - : gamemission == pack_hacx ? doom2 \ - : gamemission) - -#define MAX_DM_STARTS 10 - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/* Command line parameters. */ - -extern boolean nomonsters; /* checkparm of -nomonsters */ -extern boolean respawnparm; /* checkparm of -respawn */ -extern boolean fastparm; /* checkparm of -fast */ - -extern boolean devparm; /* DEBUG: launched with -devparm */ - -/* Game Mode - identify IWAD as shareware, retail etc. */ - -extern game_mode_t gamemode; -extern gamemission_t gamemission; -extern game_version_t gameversion; -extern game_variant_t gamevariant; - -/* Set if homebrew PWAD stuff has been added. */ - -extern boolean modifiedgame; - -/* Selected skill type, map etc. */ - -/* Defaults for menu, methinks. */ - -extern skill_t startskill; -extern int startepisode; -extern int startmap; - -/* Savegame slot to load on startup. This is the value provided to - * the -loadgame option. If this has not been provided, this is -1. - */ - -extern int startloadgame; - -extern boolean autostart; - -/* Selected by user. */ - -extern skill_t gameskill; -extern int gameepisode; -extern int gamemap; - -/* If non-zero, exit the level after this number of minutes */ - -extern int timelimit; - -/* Nightmare mode flag, single player. */ - -extern boolean respawnmonsters; - -/* Netgame? Only true if >1 player. */ - -extern boolean netgame; - -/* 0=Cooperative; 1=Deathmatch; 2=Altdeath */ - -extern int deathmatch; - -/* Internal parameters for sound rendering. - * These have been taken from the DOS version, - * but are not (yet) supported with Linux - * (e.g. no sound volume adjustment with menu. - * From m_menu.c: - * Sound FX volume has default, 0 - 15 - * Music volume has default, 0 - 15 - * These are multiplied by 8. - */ - -extern int g_sfx_volume; -extern int g_music_volume; - -/* Status flags for refresh. */ - -/* Depending on view size - no status bar? - * Note that there is no way to disable the status bar explicitly. - */ - -extern boolean statusbaractive; - -extern boolean automapactive; /* In AutoMap mode? */ -extern boolean g_menuactive; /* Menu over-layed? */ -extern boolean paused; /* Game Pause? */ - -extern boolean viewactive; - -extern boolean nodrawers; - -extern boolean testcontrols; -extern int testcontrols_mousespeed; - -/* This one is related to the 3-screen display mode. - * ANG90 = left side, ANG270 = right - */ - -extern int viewangleoffset; - -/* Player taking events, and displaying. */ - -extern int consoleplayer; -extern int displayplayer; - -/* Scores, rating. - * Statistics on a given map, for intermission. - */ - -extern int totalkills; -extern int totalitems; -extern int totalsecret; - -/* Timer, for scores. */ - -extern int levelstarttic; /* gametic at level start */ -extern int leveltime; /* tics in game play for par */ - -/* DEMO playback/recording related stuff. - * No demo, there is a human player in charge? - * Disable save/end game? - */ - -extern boolean usergame; - -/* ? */ - -extern boolean demoplayback; -extern boolean demorecording; - -/* Round angleturn in ticcmds to the nearest 256. This is used when - * recording Vanilla demos in netgames. - */ - -extern boolean lowres_turn; - -/* Quit after playing a demo from cmdline. */ - -extern boolean singledemo; - -/* ? */ - -extern gamestate_t gamestate; - -/* Internal parameters, fixed. - * These are set by the engine, and not changed - * according to user inputs. Partly load from - * WAD, partly set at startup time. - */ - -/* Bookkeeping on players - state. */ - -extern player_t players[MAXPLAYERS]; - -/* Alive? Disconnected? */ - -extern boolean playeringame[MAXPLAYERS]; - -/* Player spawn spots for deathmatch. */ - -extern mapthing_t deathmatchstarts[MAX_DM_STARTS]; -extern mapthing_t *deathmatch_p; - -/* Player spawn spots. */ - -extern mapthing_t playerstarts[MAXPLAYERS]; -extern boolean playerstartsingame[MAXPLAYERS]; - -/* Intermission stats. - * Parameters for world map / intermission. - */ - -extern wbstartstruct_t wminfo; - -/* Internal parameters, used for engine. */ - -/* File handling stuff. */ - -extern char *savegamedir; - -/* if true, load all graphics at level load */ - -extern boolean precache; - -/* wipegamestate can be set to -1 to force a wipe on the next draw */ - -extern gamestate_t wipegamestate; - -extern int g_mouse_sensitivity; - -extern int bodyqueslot; - -/* Needed to store the number of the dummy sky flat. - * Used for rendering, as well as tracking projectiles etc. - */ - -extern int skyflatnum; - -/* Netgame stuff (buffers and pointers, i.e. indices). */ - -extern int rndindex; - -extern ticcmd_t *netcmds; - -#endif /* __D_STATE__ */ diff --git a/games/NXDoom/src/doom/dstrings.c b/games/NXDoom/src/doom/dstrings.c deleted file mode 100644 index 514e8c408..000000000 --- a/games/NXDoom/src/doom/dstrings.c +++ /dev/null @@ -1,71 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/dstrings.c - * - * SPDX-License-Identifier: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Globally defined strings. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "dstrings.h" - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -const char *doom1_endmsg[] = -{ - DOOM1_ENDMSG -}; - -const char *doom2_endmsg[] = -{ - DOOM2_ENDMSG -}; - -/* UNUSED messages included in the source release */ - -#if 0 -char *endmsg[] = -{ - /* DOOM1 */ - - QUITMSG, - - /* FinalDOOM? */ - - "fuck you, pussy!\nget the fuck out!", - "you quit and i'll jizz\nin your cystholes!", - "if you leave, i'll make\nthe lord drink my jizz.", - "hey, ron! can we say\n'fuck' in the game?", - "i'd leave: this is just\nmore monsters and levels.\nwhat a load.", - "suck it down, asshole!\nyou're a fucking wimp!", - "don't quit now! we're \nstill spending your money!", - - /* Internal debug. Different style, too. */ - - "THIS IS NO MESSAGE!\nPage intentionally left blank.", -}; -#endif - -/**************************************************************************** - * Public Functions - ****************************************************************************/ diff --git a/games/NXDoom/src/doom/dstrings.h b/games/NXDoom/src/doom/dstrings.h deleted file mode 100644 index b1330f66d..000000000 --- a/games/NXDoom/src/doom/dstrings.h +++ /dev/null @@ -1,62 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/dstrings.h - * - * SPDX-License-Identifier: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * DOOM strings, by language. - * - ****************************************************************************/ - -#ifndef __DSTRINGS__ -#define __DSTRINGS__ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -/* All important printed strings. */ - -#if defined(CONFIG_GAMES_NXDOOM_LANG_EN) -#include "d_englsh.h" -#elif defined(CONFIG_GAMES_NXDOOM_LANG_FR) -#include "d_french.h" -#else -#error "Unsupported language choice." -#endif - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* Misc. other strings. */ - -#define SAVEGAMENAME "doomsav" - -/* QuitDOOM messages; 8 per each game type */ - -#define NUM_QUITMESSAGES (8) - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -extern const char *doom1_endmsg[]; -extern const char *doom2_endmsg[]; - -#endif /* __DSTRINGS__ */ diff --git a/games/NXDoom/src/doom/f_finale.c b/games/NXDoom/src/doom/f_finale.c deleted file mode 100644 index a9d964aff..000000000 --- a/games/NXDoom/src/doom/f_finale.c +++ /dev/null @@ -1,769 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/f_finale.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Game completion, final screen animation. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include - -/* Functions. */ - -#include "deh_main.h" -#include "i_swap.h" -#include "i_system.h" -#include "v_video.h" -#include "w_wad.h" -#include "z_zone.h" - -#ifdef CONFIG_GAMES_NXDOOM_SOUND -#include "s_sound.h" -#include "sounds.h" -#endif - -/* Data. */ - -#include "d_main.h" -#include "dstrings.h" - -#include "doomstat.h" -#include "r_state.h" - -#include "hu_stuff.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define TEXTSPEED 3 -#define TEXTWAIT 250 - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -typedef enum -{ - F_STAGE_TEXT, - F_STAGE_ARTSCREEN, - F_STAGE_CAST, -} finalestage_t; - -/* ? - * #include "doomstat.h" - * #include "r_local.h" - * #include "f_finale.h" - */ - -typedef struct -{ - gamemission_t mission; - int episode; - int level; - const char *background; - const char *text; -} textscreen_t; - -typedef struct -{ - const char *name; - mobjtype_t type; -} castinfo_t; - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static textscreen_t g_textscreens[] = -{ - {doom, 1, 8, "FLOOR4_8", E1TEXT}, - {doom, 2, 8, "SFLR6_1", E2TEXT}, - {doom, 3, 8, "MFLR8_4", E3TEXT}, - {doom, 4, 8, "MFLR8_3", E4TEXT}, - {doom2, 1, 6, "SLIME16", C1TEXT}, - {doom2, 1, 11, "RROCK14", C2TEXT}, - {doom2, 1, 20, "RROCK07", C3TEXT}, - {doom2, 1, 30, "RROCK17", C4TEXT}, - {doom2, 1, 15, "RROCK13", C5TEXT}, - {doom2, 1, 31, "RROCK19", C6TEXT}, - {pack_tnt, 1, 6, "SLIME16", T1TEXT}, - {pack_tnt, 1, 11, "RROCK14", T2TEXT}, - {pack_tnt, 1, 20, "RROCK07", T3TEXT}, - {pack_tnt, 1, 30, "RROCK17", T4TEXT}, - {pack_tnt, 1, 15, "RROCK13", T5TEXT}, - {pack_tnt, 1, 31, "RROCK19", T6TEXT}, - {pack_plut, 1, 6, "SLIME16", P1TEXT}, - {pack_plut, 1, 11, "RROCK14", P2TEXT}, - {pack_plut, 1, 20, "RROCK07", P3TEXT}, - {pack_plut, 1, 30, "RROCK17", P4TEXT}, - {pack_plut, 1, 15, "RROCK13", P5TEXT}, - {pack_plut, 1, 31, "RROCK19", P6TEXT}, -}; - -/* Final DOOM 2 animation - * Casting by id Software. in order of appearance - */ - -static castinfo_t g_castorder[] = -{ - {CC_ZOMBIE, MT_POSSESSED}, - {CC_SHOTGUN, MT_SHOTGUY}, - {CC_HEAVY, MT_CHAINGUY}, - {CC_IMP, MT_TROOP}, - {CC_DEMON, MT_SERGEANT}, - {CC_LOST, MT_SKULL}, - {CC_CACO, MT_HEAD}, - {CC_HELL, MT_KNIGHT}, - {CC_BARON, MT_BRUISER}, - {CC_ARACH, MT_BABY}, - {CC_PAIN, MT_PAIN}, - {CC_REVEN, MT_UNDEAD}, - {CC_MANCU, MT_FATSO}, - {CC_ARCH, MT_VILE}, - {CC_SPIDER, MT_SPIDER}, - {CC_CYBER, MT_CYBORG}, - {CC_HERO, MT_PLAYER}, - {NULL, 0}, -}; - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/* Stage of animation: */ - -finalestage_t finalestage; -unsigned int finalecount; - -const char *finaletext; -const char *finaleflat; - -int castnum; -int casttics; -state_t *caststate; -boolean castdeath; -int castframes; -int castonmelee; -boolean castattacking; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static void f_start_cast(void) -{ - wipegamestate = -1; /* force a screen wipe */ - castnum = 0; - caststate = &states[mobjinfo[g_castorder[castnum].type].seestate]; - casttics = caststate->tics; - castdeath = false; - finalestage = F_STAGE_CAST; - castframes = 0; - castonmelee = 0; - castattacking = false; -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_change_music(MUS_EVIL, true); -#endif -} - -static void f_text_write(void) -{ - byte *src; - pixel_t *dest; - int x; - int y; - int w; - signed int count; - const char *ch; - int c; - int cx; - int cy; - - /* erase the entire screen to a tiled background */ - - src = w_cache_lump_name(finaleflat, PU_CACHE); - dest = i_video_buffer; - - for (y = 0; y < SCREENHEIGHT; y++) - { - for (x = 0; x < SCREENWIDTH / 64; x++) - { - memcpy(dest, src + ((y & 63) << 6), 64); - dest += 64; - } - - if (SCREENWIDTH & 63) - { - memcpy(dest, src + ((y & 63) << 6), SCREENWIDTH & 63); - dest += (SCREENWIDTH & 63); - } - } - - v_mark_rect(0, 0, SCREENWIDTH, SCREENHEIGHT); - - /* draw some of the text onto the screen */ - - cx = 10; - cy = 10; - ch = finaletext; - - count = ((signed int)finalecount - 10) / TEXTSPEED; - if (count < 0) count = 0; - for (; count; count--) - { - c = *ch++; - if (!c) break; - if (c == '\n') - { - cx = 10; - cy += 11; - continue; - } - - c = toupper(c) - HU_FONTSTART; - if (c < 0 || c >= HU_FONTSIZE) - { - cx += 4; - continue; - } - - w = SHORT(hu_font[c]->width); - if (cx + w > SCREENWIDTH) break; - v_draw_patch(cx, cy, hu_font[c]); - cx += w; - } -} - -static void f_cast_ticker(void) -{ - int st; -#ifdef CONFIG_GAMES_NXDOOM_SOUND - int sfx; -#endif - - if (--casttics > 0) return; /* not time to change state yet */ - - if (caststate->tics == -1 || caststate->nextstate == S_NULL) - { - /* switch from deathstate to next monster */ - - castnum++; - castdeath = false; - if (g_castorder[castnum].name == NULL) castnum = 0; - -#ifdef CONFIG_GAMES_NXDOOM_SOUND - if (mobjinfo[g_castorder[castnum].type].seesound) - { - s_start_sound(NULL, mobjinfo[g_castorder[castnum].type].seesound); - } - -#endif - - caststate = &states[mobjinfo[g_castorder[castnum].type].seestate]; - castframes = 0; - } - else - { - /* just advance to next state in animation */ - - if (caststate == &states[S_PLAY_ATK1]) - { - goto stopattack; /* Oh, gross hack! */ - } - - st = caststate->nextstate; - caststate = &states[st]; - castframes++; - - /* sound hacks.... */ - -#ifdef CONFIG_GAMES_NXDOOM_SOUND - switch (st) - { - case S_PLAY_ATK1: - sfx = SFX_DSHTGN; - break; - case S_POSS_ATK2: - sfx = SFX_PISTOL; - break; - case S_SPOS_ATK2: - sfx = SFX_SHOTGN; - break; - case S_VILE_ATK2: - sfx = SFX_VILATK; - break; - case S_SKEL_FIST2: - sfx = SFX_SKESWG; - break; - case S_SKEL_FIST4: - sfx = SFX_SKEPCH; - break; - case S_SKEL_MISS2: - sfx = SFX_SKEATK; - break; - case S_FATT_ATK8: - case S_FATT_ATK5: - case S_FATT_ATK2: - sfx = SFX_FIRSHT; - break; - case S_CPOS_ATK2: - case S_CPOS_ATK3: - case S_CPOS_ATK4: - sfx = SFX_SHOTGN; - break; - case S_TROO_ATK3: - sfx = SFX_CLAW; - break; - case S_SARG_ATK2: - sfx = SFX_SGTATK; - break; - case S_BOSS_ATK2: - case S_BOS2_ATK2: - case S_HEAD_ATK2: - sfx = SFX_FIRSHT; - break; - case S_SKULL_ATK2: - sfx = SFX_SKLATK; - break; - case S_SPID_ATK2: - case S_SPID_ATK3: - sfx = SFX_SHOTGN; - break; - case S_BSPI_ATK2: - sfx = SFX_PLASMA; - break; - case S_CYBER_ATK2: - case S_CYBER_ATK4: - case S_CYBER_ATK6: - sfx = SFX_RLAUNC; - break; - case S_PAIN_ATK3: - sfx = SFX_SKLATK; - break; - default: - sfx = 0; - break; - } - - if (sfx) s_start_sound(NULL, sfx); -#endif - } - - if (castframes == 12) - { - /* go into attack frame */ - - castattacking = true; - - if (castonmelee) - { - caststate = - &states[mobjinfo[g_castorder[castnum].type].meleestate]; - } - else - { - caststate = - &states[mobjinfo[g_castorder[castnum].type].missilestate]; - } - - castonmelee ^= 1; - - if (caststate == &states[S_NULL]) - { - if (castonmelee) - { - caststate = - &states[mobjinfo[g_castorder[castnum].type].meleestate]; - } - else - { - caststate = - &states[mobjinfo[g_castorder[castnum].type].missilestate]; - } - } - } - - if (castattacking) - { - if (castframes == 24 || - caststate == &states[mobjinfo[g_castorder[castnum].type].seestate]) - { - stopattack: - castattacking = false; - castframes = 0; - caststate = &states[mobjinfo[g_castorder[castnum].type].seestate]; - } - } - - casttics = caststate->tics; - if (casttics == -1) casttics = 15; -} - -static boolean f_cast_responder(event_t *ev) -{ - if (ev->type != ev_keydown) return false; - - if (castdeath) return true; /* already in dying frames */ - - /* go into death frame */ - - castdeath = true; - caststate = &states[mobjinfo[g_castorder[castnum].type].deathstate]; - casttics = caststate->tics; - castframes = 0; - castattacking = false; - -#ifdef CONFIG_GAMES_NXDOOM_SOUND - if (mobjinfo[g_castorder[castnum].type].deathsound) - { - s_start_sound(NULL, mobjinfo[g_castorder[castnum].type].deathsound); - } -#endif - - return true; -} - -static void f_cast_print(const char *text) -{ - const char *ch; - int c; - int cx; - int w; - int width; - - /* find width */ - - ch = text; - width = 0; - - while (ch) - { - c = *ch++; - if (!c) break; - c = toupper(c) - HU_FONTSTART; - if (c < 0 || c >= HU_FONTSIZE) - { - width += 4; - continue; - } - - w = SHORT(hu_font[c]->width); - width += w; - } - - /* draw it */ - - cx = SCREENWIDTH / 2 - width / 2; - ch = text; - while (ch) - { - c = *ch++; - if (!c) break; - c = toupper(c) - HU_FONTSTART; - if (c < 0 || c >= HU_FONTSIZE) - { - cx += 4; - continue; - } - - w = SHORT(hu_font[c]->width); - v_draw_patch(cx, 180, hu_font[c]); - cx += w; - } -} - -static void f_cast_drawer(void) -{ - spritedef_t *sprdef; - spriteframe_t *sprframe; - int lump; - boolean flip; - patch_t *patch; - - /* erase the entire screen to a background */ - - v_draw_patch(0, 0, w_cache_lump_name(("BOSSBACK"), PU_CACHE)); - - f_cast_print((g_castorder[castnum].name)); - - /* draw the current frame in the middle of the screen */ - - sprdef = &sprites[caststate->sprite]; - sprframe = &sprdef->spriteframes[caststate->frame & FF_FRAMEMASK]; - lump = sprframe->lump[0]; - flip = (boolean)sprframe->flip[0]; - - patch = w_cache_lump_num(lump + firstspritelump, PU_CACHE); - if (flip) - v_draw_patch_flipped(SCREENWIDTH / 2, 170, patch); - else - v_draw_patch(SCREENWIDTH / 2, 170, patch); -} - -static void f_draw_patch_col(int x, patch_t *patch, int col) -{ - column_t *column; - byte *source; - pixel_t *dest; - pixel_t *desttop; - int count; - - column = (column_t *)((byte *)patch + LONG(patch->columnofs[col])); - desttop = i_video_buffer + x; - - /* step through the posts in a column */ - - while (column->topdelta != 0xff) - { - source = (byte *)column + 3; - dest = desttop + column->topdelta * SCREENWIDTH; - count = column->length; - - while (count--) - { - *dest = *source++; - dest += SCREENWIDTH; - } - - column = (column_t *)((byte *)column + column->length + 4); - } -} - -static void f_bunny_scroll(void) -{ - signed int scrolled; - int x; - patch_t *p1; - patch_t *p2; - char name[10]; - int stage; - static int laststage; - - p1 = w_cache_lump_name(("PFUB2"), PU_LEVEL); - p2 = w_cache_lump_name(("PFUB1"), PU_LEVEL); - - v_mark_rect(0, 0, SCREENWIDTH, SCREENHEIGHT); - - scrolled = (SCREENWIDTH - ((signed int)finalecount - 230) / 2); - if (scrolled > SCREENWIDTH) scrolled = SCREENWIDTH; - if (scrolled < 0) scrolled = 0; - - for (x = 0; x < SCREENWIDTH; x++) - { - if (x + scrolled < SCREENWIDTH) - f_draw_patch_col(x, p1, x + scrolled); - else - f_draw_patch_col(x, p2, x + scrolled - SCREENWIDTH); - } - - if (finalecount < 1130) return; - if (finalecount < 1180) - { - v_draw_patch((SCREENWIDTH - 13 * 8) / 2, (SCREENHEIGHT - 8 * 8) / 2, - w_cache_lump_name(("END0"), PU_CACHE)); - laststage = 0; - return; - } - - stage = (finalecount - 1180) / 5; - if (stage > 6) stage = 6; - if (stage > laststage) - { -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(NULL, SFX_PISTOL); -#endif - laststage = stage; - } - - snprintf(name, 10, "END%i", stage); - v_draw_patch((SCREENWIDTH - 13 * 8) / 2, (SCREENHEIGHT - 8 * 8) / 2, - w_cache_lump_name(name, PU_CACHE)); -} - -static void f_art_screen_drawer(void) -{ - const char *lumpname; - - if (gameepisode == 3) - { - f_bunny_scroll(); - } - else - { - switch (gameepisode) - { - case 1: - if (gameversion >= exe_ultimate) - { - lumpname = "CREDIT"; - } - else - { - lumpname = "HELP2"; - } - break; - case 2: - lumpname = "VICTORY2"; - break; - case 4: - lumpname = "ENDPIC"; - break; - default: - return; - } - - lumpname = (lumpname); - - v_draw_patch(0, 0, w_cache_lump_name(lumpname, PU_CACHE)); - } -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/* f_start_finale */ - -void f_start_finale(void) -{ - size_t i; - - gameaction = ga_nothing; - gamestate = GS_FINALE; - viewactive = false; - automapactive = false; - -#ifdef CONFIG_GAMES_NXDOOM_SOUND - if (logical_gamemission == doom) - { - s_change_music(MUS_VICTOR, true); - } - else - { - s_change_music(MUS_READ_M, true); - } -#endif - - /* Find the right screen and set the text and background */ - - for (i = 0; i < arrlen(g_textscreens); ++i) - { - textscreen_t *screen = &g_textscreens[i]; - - /* Hack for Chex Quest */ - - if (gameversion == exe_chex && screen->mission == doom) - { - screen->level = 5; - } - - if (logical_gamemission == screen->mission && - (logical_gamemission != doom || gameepisode == screen->episode) && - gamemap == screen->level) - { - finaletext = screen->text; - finaleflat = screen->background; - } - } - - /* Do dehacked substitutions of strings */ - - finaletext = (finaletext); - finaleflat = (finaleflat); - - finalestage = F_STAGE_TEXT; - finalecount = 0; -} - -boolean f_responder(event_t *event) -{ - if (finalestage == F_STAGE_CAST) return f_cast_responder(event); - - return false; -} - -void f_ticker(void) -{ - size_t i; - - /* check for skipping */ - - if ((gamemode == commercial) && (finalecount > 50)) - { - /* go on to the next level */ - - for (i = 0; i < MAXPLAYERS; i++) - { - if (players[i].cmd.buttons) break; - } - - if (i < MAXPLAYERS) - { - if (gamemap == 30) - f_start_cast(); - else - gameaction = ga_worlddone; - } - } - - /* advance animation */ - - finalecount++; - - if (finalestage == F_STAGE_CAST) - { - f_cast_ticker(); - return; - } - - if (gamemode == commercial) return; - - if (finalestage == F_STAGE_TEXT && - finalecount > strlen(finaletext) * TEXTSPEED + TEXTWAIT) - { - finalecount = 0; - finalestage = F_STAGE_ARTSCREEN; - wipegamestate = -1; /* force a wipe */ -#ifdef CONFIG_GAMES_NXDOOM_SOUND - if (gameepisode == 3) s_start_music(MUS_BUNNY); -#endif - } -} - -void f_drawer(void) -{ - switch (finalestage) - { - case F_STAGE_CAST: - f_cast_drawer(); - break; - case F_STAGE_TEXT: - f_text_write(); - break; - case F_STAGE_ARTSCREEN: - f_art_screen_drawer(); - break; - } -} diff --git a/games/NXDoom/src/doom/f_finale.h b/games/NXDoom/src/doom/f_finale.h deleted file mode 100644 index 3e60e15a7..000000000 --- a/games/NXDoom/src/doom/f_finale.h +++ /dev/null @@ -1,49 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/f_finale.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - ****************************************************************************/ - -#ifndef __F_FINALE__ -#define __F_FINALE__ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "d_event.h" -#include "doomtype.h" - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/* Called by main loop. */ - -boolean f_responder(event_t *ev); - -/* Called by main loop. */ - -void f_ticker(void); - -/* Called by main loop. */ - -void f_drawer(void); - -void f_start_finale(void); - -#endif /* __F_FINALE__ */ diff --git a/games/NXDoom/src/doom/f_wipe.c b/games/NXDoom/src/doom/f_wipe.c deleted file mode 100644 index e10a0bd21..000000000 --- a/games/NXDoom/src/doom/f_wipe.c +++ /dev/null @@ -1,296 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/f_wipe.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Mission begin melt/wipe screen special effect. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include "i_video.h" -#include "m_random.h" -#include "v_video.h" -#include "z_zone.h" - -#include "doomtype.h" - -#include "f_wipe.h" - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -static void wipe_shitty_col_major_xform(dpixel_t *array, int width, - int height); -static int wip_init_colour_xform(int width, int height, int ticks); -static int wipe_do_colour_xform(int width, int height, int ticks); -static int wip_exit_color_xform(int width, int height, int ticks); -static int wipe_init_melt(int width, int height, int ticks); -static int wipe_do_melt(int width, int height, int ticks); -static int wipe_exit_melt(int width, int height, int ticks); - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/* when zero, stop the wipe */ - -static boolean go = 0; - -static pixel_t *wipe_scr_start; -static pixel_t *wipe_scr_end; -static pixel_t *wipe_scr; - -static int *g_y; - -static int (*g_wipes[])(int, int, int) = -{ - wip_init_colour_xform, wipe_do_colour_xform, wip_exit_color_xform, - wipe_init_melt, wipe_do_melt, wipe_exit_melt, -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static void wipe_shitty_col_major_xform(dpixel_t *array, int width, - int height) -{ - int x; - int y; - dpixel_t *dest; - - dest = (dpixel_t *)z_malloc(width * height * sizeof(*dest), PU_STATIC, 0); - - for (y = 0; y < height; y++) - { - for (x = 0; x < width; x++) - { - dest[x * height + y] = array[y * width + x]; - } - } - - memcpy(array, dest, width * height * sizeof(*dest)); - - z_free(dest); -} - -static int wip_init_colour_xform(int width, int height, int ticks) -{ - memcpy(wipe_scr, wipe_scr_start, width * height * sizeof(*wipe_scr)); - return 0; -} - -static int wipe_do_colour_xform(int width, int height, int ticks) -{ - boolean changed; - pixel_t *w; - pixel_t *e; - int newval; - - changed = false; - w = wipe_scr; - e = wipe_scr_end; - - while (w != wipe_scr + width * height) - { - if (*w != *e) - { - if (*w > *e) - { - newval = *w - ticks; - if (newval < *e) - *w = *e; - else - *w = newval; - changed = true; - } - else if (*w < *e) - { - newval = *w + ticks; - if (newval > *e) - *w = *e; - else - *w = newval; - changed = true; - } - } - - w++; - e++; - } - - return !changed; -} - -static int wip_exit_color_xform(int width, int height, int ticks) -{ - return 0; -} - -static int wipe_init_melt(int width, int height, int ticks) -{ - int i; - int r; - - /* copy start screen to main screen */ - - memcpy(wipe_scr, wipe_scr_start, width * height * sizeof(*wipe_scr)); - - /* makes this wipe faster (in theory) - * to have stuff in column-major format - */ - - wipe_shitty_col_major_xform((dpixel_t *)wipe_scr_start, width / 2, height); - wipe_shitty_col_major_xform((dpixel_t *)wipe_scr_end, width / 2, height); - - /* setup initial column positions - * (y<0 => not ready to scroll yet) - */ - - g_y = (int *)z_malloc(width * sizeof(int), PU_STATIC, 0); - g_y[0] = -(m_random() % 16); - for (i = 1; i < width; i++) - { - r = (m_random() % 3) - 1; - g_y[i] = g_y[i - 1] + r; - if (g_y[i] > 0) - g_y[i] = 0; - else if (g_y[i] == -16) - g_y[i] = -15; - } - - return 0; -} - -static int wipe_do_melt(int width, int height, int ticks) -{ - int i; - int j; - int dy; - int idx; - - dpixel_t *s; - dpixel_t *d; - boolean done = true; - - width /= 2; - - while (ticks--) - { - for (i = 0; i < width; i++) - { - if (g_y[i] < 0) - { - g_y[i]++; - done = false; - } - else if (g_y[i] < height) - { - dy = (g_y[i] < 16) ? g_y[i] + 1 : 8; - if (g_y[i] + dy >= height) dy = height - g_y[i]; - s = &((dpixel_t *)wipe_scr_end)[i * height + g_y[i]]; - d = &((dpixel_t *)wipe_scr)[g_y[i] * width + i]; - idx = 0; - for (j = dy; j; j--) - { - d[idx] = *(s++); - idx += width; - } - - g_y[i] += dy; - s = &((dpixel_t *)wipe_scr_start)[i * height]; - d = &((dpixel_t *)wipe_scr)[g_y[i] * width + i]; - idx = 0; - for (j = height - g_y[i]; j; j--) - { - d[idx] = *(s++); - idx += width; - } - - done = false; - } - } - } - - return done; -} - -static int wipe_exit_melt(int width, int height, int ticks) -{ - z_free(g_y); - z_free(wipe_scr_start); - z_free(wipe_scr_end); - return 0; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -int wipe_start_screen(int x, int y, int width, int height) -{ - wipe_scr_start = z_malloc( - SCREENWIDTH * SCREENHEIGHT * sizeof(*wipe_scr_start), PU_STATIC, NULL); - i_read_screen(wipe_scr_start); - return 0; -} - -int wipe_endscreen(int x, int y, int width, int height) -{ - wipe_scr_end = z_malloc(SCREENWIDTH * SCREENHEIGHT * sizeof(*wipe_scr_end), - PU_STATIC, NULL); - i_read_screen(wipe_scr_end); - v_draw_block(x, y, width, height, wipe_scr_start); /* restore start scr. */ - return 0; -} - -int wipe_screen_wipe(int wipeno, int x, int y, int width, int height, - int ticks) -{ - int rc; - - /* initial stuff */ - - if (!go) - { - go = 1; - wipe_scr = i_video_buffer; - (*g_wipes[wipeno * 3])(width, height, ticks); - } - - /* do a piece of wipe-in */ - - v_mark_rect(0, 0, width, height); - rc = (*g_wipes[wipeno * 3 + 1])(width, height, ticks); - - /* final stuff */ - - if (rc) - { - go = 0; - (*g_wipes[wipeno * 3 + 2])(width, height, ticks); - } - - return !go; -} diff --git a/games/NXDoom/src/doom/f_wipe.h b/games/NXDoom/src/doom/f_wipe.h deleted file mode 100644 index c421385a5..000000000 --- a/games/NXDoom/src/doom/f_wipe.h +++ /dev/null @@ -1,53 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/f_wipe.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Mission start screen wipe/melt, special effects. - * - ****************************************************************************/ - -#ifndef __F_WIPE_H__ -#define __F_WIPE_H__ - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -/* SCREEN WIPE PACKAGE */ - -enum -{ - /* simple gradual pixel change for 8-bit only */ - - WIPE_COLORXFORM, - WIPE_MELT, /* weird screen melt */ - WIPE_NUMWIPES -}; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -int wipe_start_screen(int x, int y, int width, int height); - -int wipe_endscreen(int x, int y, int width, int height); - -int wipe_screen_wipe(int wipeno, int x, int y, int width, int height, - int ticks); - -#endif /* __F_WIPE_H__ */ diff --git a/games/NXDoom/src/doom/g_game.c b/games/NXDoom/src/doom/g_game.c deleted file mode 100644 index 241ffcfa6..000000000 --- a/games/NXDoom/src/doom/g_game.c +++ /dev/null @@ -1,2466 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/g_game.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: none - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include - -#include "doomdef.h" -#include "doomkeys.h" -#include "doomstat.h" - -#include "deh_main.h" -#include "deh_misc.h" - -#include "f_finale.h" -#include "i_input.h" -#include "i_joystick.h" -#include "i_swap.h" -#include "i_system.h" -#include "i_timer.h" -#include "i_video.h" -#include "m_argv.h" -#include "m_controls.h" -#include "m_menu.h" -#include "m_misc.h" -#include "m_random.h" -#include "z_zone.h" - -#include "p_saveg.h" -#include "p_setup.h" -#include "p_tick.h" - -#include "d_main.h" - -#include "am_map.h" -#include "hu_stuff.h" -#include "st_stuff.h" -#include "statdump.h" -#include "wi_stuff.h" - -/* Needs access to LFB. */ - -#include "v_video.h" - -#include "w_wad.h" - -#include "p_local.h" - -#ifdef CONFIG_GAMES_NXDOOM_SOUND -#include "s_sound.h" -#include "sounds.h" -#endif - -/* Data. */ - -#include "dstrings.h" - -/* SKY handling - still the wrong place. */ - -#include "r_data.h" -#include "r_sky.h" - -#include "g_game.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define SAVEGAMESIZE 0x2c000 - -#define MAXPLMOVE (forwardmove[1]) - -#define TURBOTHRESHOLD 0x32 - -#define BODYQUESIZE 32 - -#define SLOWTURNTICS 6 - -#define NUMKEYS 256 -#define MAX_JOY_BUTTONS 20 - -#define DEMOMARKER 0x80 - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -struct weapon_order -{ - weapontype_t weapon; - weapontype_t weapon_num; -}; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -void p_spawn_player(mapthing_t *mthing); -void g_player_reborn(int player); - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/* Gamestate the last time g_ticker was called. */ - -gamestate_t oldgamestate; - -gameaction_t gameaction; -gamestate_t gamestate; -skill_t gameskill; -boolean respawnmonsters; -int gameepisode; -int gamemap; - -/* If non-zero, exit the level after this number of minutes. */ - -int timelimit; - -boolean paused; -boolean sendpause; /* send a pause event next tic */ -boolean sendsave; /* send a save event next tic */ -boolean usergame; /* ok to save / end game */ - -boolean timingdemo; /* if true, exit with report on completion */ -boolean nodrawers; /* for comparative timing purposes */ -int starttime; /* for comparative timing purposes */ - -boolean viewactive; - -int deathmatch; /* only if started as net death */ -boolean netgame; /* only true if packets are broadcast */ -boolean playeringame[MAXPLAYERS]; -player_t players[MAXPLAYERS]; - -boolean turbodetected[MAXPLAYERS]; - -int consoleplayer; /* player taking events and displaying */ -int displayplayer; /* view being displayed */ -int levelstarttic; /* gametic at level start */ -int totalkills; -int totalitems; -int totalsecret; /* for intermission */ - -char *demoname; -boolean demorecording; -boolean longtics; /* cph's doom 1.91 longtics hack */ -boolean lowres_turn; /* low resolution turning for longtics */ -boolean demoplayback; -boolean netdemo; -byte *demobuffer; -byte *demo_p; -byte *demoend; -boolean singledemo; /* quit after playing a demo from cmdline */ - -boolean precache = true; /* if true, load all graphics at start */ - -boolean testcontrols = false; /* Invoked by setup to test controls */ -int testcontrols_mousespeed; - -wbstartstruct_t wminfo; /* params for world map / intermission */ - -byte consistency[MAXPLAYERS][CONFIG_GAMES_NXDOOM_NET_BACKUPTICS]; - -fixed_t forwardmove[2] = -{ - 0x19, 0x32 -}; - -fixed_t sidemove[2] = -{ - 0x18, 0x28 -}; - -/* + slow turn */ - -fixed_t angleturn[3] = -{ - 640, 1280, 320 -}; - -/* mouse values are used once */ - -int mousex; -int mousey; - -mobj_t *bodyque[BODYQUESIZE]; -int bodyqueslot; - -int vanilla_savegame_limit = 1; -int vanilla_demo_limit = 1; - -/* G_DoCompleted */ - -boolean secretexit; - -char savename[256]; - -skill_t d_skill; -int d_episode; -int d_map; - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static int *weapon_keys[] = -{ - &key_weapon1, &key_weapon2, &key_weapon3, &key_weapon4, - &key_weapon5, &key_weapon6, &key_weapon7, &key_weapon8, -}; - -/* Set to -1 or +1 to switch to the previous or next weapon. */ - -static int next_weapon = 0; - -/* Used for prev/next weapon keys. */ - -static const struct weapon_order weapon_order_table[] = -{ - {wp_fist, wp_fist}, - {wp_chainsaw, wp_fist}, - {wp_pistol, wp_pistol}, - {wp_shotgun, wp_shotgun}, - {wp_supershotgun, wp_shotgun}, - {wp_chaingun, wp_chaingun}, - {wp_missile, wp_missile}, - {wp_plasma, wp_plasma}, - {wp_bfg, wp_bfg}, -}; - -static boolean gamekeydown[NUMKEYS]; -static int turnheld; /* for accelerative turning */ - -static boolean mousearray[MAX_MOUSE_BUTTONS + 1]; -static boolean *mousebuttons = &mousearray[1]; /* allow [-1] */ - -static int dclicktime; -static boolean dclickstate; -static int dclicks; -static int dclicktime2; -static boolean dclickstate2; -static int dclicks2; - -/* joystick values are repeated */ - -static int joyxmove; -static int joyymove; -static int joystrafemove; -static boolean joyarray[MAX_JOY_BUTTONS + 1]; -static boolean *joybuttons = &joyarray[1]; /* allow [-1] */ - -static int savegameslot; -static char savedescription[32]; - -/* DOOM Par Times */ - -static const int pars[4][10] = -{ - {0}, - {0, 30, 75, 120, 90, 165, 180, 180, 30, 165}, - {0, 90, 90, 90, 120, 90, 360, 240, 30, 170}, - {0, 90, 45, 90, 150, 90, 90, 165, 30, 135}, -}; - -/* DOOM II Par Times */ - -static const int cpars[32] = -{ - 30, 90, 120, 120, 90, 150, 120, 120, 270, 90, /* 1-10 */ - 210, 150, 150, 150, 210, 150, 420, 150, 210, 150, /* 11-20 */ - 240, 150, 180, 150, 150, 300, 330, 420, 300, 180, /* 21-30 */ - 120, 30, /* 31-32 */ -}; - -/* Chex Quest Par Times */ - -static const int chexpars[6] = -{ - 0, 120, 360, 480, 200, 360, -}; - -static const char *defdemoname; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static boolean weapon_selectable(weapontype_t weapon) -{ - /* Can't select the super shotgun in Doom 1. */ - - if (weapon == wp_supershotgun && logical_gamemission == doom) - { - return false; - } - - /* These weapons aren't available in shareware. */ - - if ((weapon == wp_plasma || weapon == wp_bfg) && gamemission == doom && - gamemode == shareware) - { - return false; - } - - /* Can't select a weapon if we don't own it. */ - - if (!players[consoleplayer].weaponowned[weapon]) - { - return false; - } - - /* Can't select the fist if we have the chainsaw, unless - * we also have the berserk pack. - */ - - if (weapon == wp_fist && players[consoleplayer].weaponowned[wp_chainsaw] && - !players[consoleplayer].powers[pw_strength]) - { - return false; - } - - return true; -} - -static int g_next_weapon(int direction) -{ - weapontype_t weapon; - int start_i; - int i; - - /* Find index in the table. */ - - if (players[consoleplayer].pendingweapon == wp_nochange) - { - weapon = players[consoleplayer].readyweapon; - } - else - { - weapon = players[consoleplayer].pendingweapon; - } - - for (i = 0; i < arrlen(weapon_order_table); ++i) - { - if (weapon_order_table[i].weapon == weapon) - { - break; - } - } - - /* The current weapon must be present in weapon_order_table - * otherwise something has gone terribly wrong - */ - - if (i >= arrlen(weapon_order_table)) - { - i_error("Internal error: weapon %d not present in weapon_order_table", - weapon); - } - - /* Switch weapon. Don't loop forever. */ - - start_i = i; - do - { - i += direction; - i = (i + arrlen(weapon_order_table)) % arrlen(weapon_order_table); - } - while (i != start_i && !weapon_selectable(weapon_order_table[i].weapon)); - - return weapon_order_table[i].weapon_num; -} - -#if 0 /* UNUSED */ -static int g_cmd_checksum(ticcmd_t *cmd) -{ - size_t i; - int sum = 0; - - for (i = 0; i < sizeof(*cmd) / 4 - 1; i++) - sum += ((int *)cmd)[i]; - - return sum; -} -#endif - -static void g_do_load_level(void) -{ - int i; - - /* Set the sky map. - * First thing, we have a dummy sky texture name, - * a flat. The data is in the WAD only because - * we look for an actual index, instead of simply - * setting one. - */ - - skyflatnum = r_flat_num_for_name((SKYFLATNAME)); - - /* The "Sky never changes in Doom II" bug was fixed in - * the id Anthology version of doom2.exe for Final Doom. - */ - - if ((gamemode == commercial) && - (gameversion == exe_final2 || gameversion == exe_chex)) - { - const char *skytexturename; - - if (gamemap < 12) - { - skytexturename = "SKY1"; - } - else if (gamemap < 21) - { - skytexturename = "SKY2"; - } - else - { - skytexturename = "SKY3"; - } - - skytexturename = (skytexturename); - - skytexture = r_texture_num_for_name(skytexturename); - } - - levelstarttic = gametic; /* for time calculation */ - - if (wipegamestate == GS_LEVEL) wipegamestate = -1; /* force a wipe */ - - gamestate = GS_LEVEL; - - for (i = 0; i < MAXPLAYERS; i++) - { - turbodetected[i] = false; - if (playeringame[i] && players[i].playerstate == PST_DEAD) - players[i].playerstate = PST_REBORN; - memset(players[i].frags, 0, sizeof(players[i].frags)); - } - - p_setup_level(gameepisode, gamemap, 0, gameskill); - displayplayer = consoleplayer; /* view the guy you are playing */ - gameaction = ga_nothing; - z_check_heap(); - - /* clear cmd building stuff */ - - memset(gamekeydown, 0, sizeof(gamekeydown)); - joyxmove = joyymove = joystrafemove = 0; - mousex = mousey = 0; - sendpause = sendsave = paused = false; - memset(mousearray, 0, sizeof(mousearray)); - memset(joyarray, 0, sizeof(joyarray)); - - if (testcontrols) - { - players[consoleplayer].message = "Press escape to quit."; - } -} - -static void set_joy_buttons(unsigned int buttons_mask) -{ - int i; - - for (i = 0; i < MAX_JOY_BUTTONS; ++i) - { - int button_on = (buttons_mask & (1 << i)) != 0; - - /* Detect button press: */ - - if (!joybuttons[i] && button_on) - { - /* Weapon cycling: */ - - if (i == joybprevweapon) - { - next_weapon = -1; - } - else if (i == joybnextweapon) - { - next_weapon = 1; - } - } - - joybuttons[i] = button_on; - } -} - -static void set_mouse_buttons(unsigned int buttons_mask) -{ - int i; - - for (i = 0; i < MAX_MOUSE_BUTTONS; ++i) - { - unsigned int button_on = (buttons_mask & (1 << i)) != 0; - - /* Detect button press: */ - - if (!mousebuttons[i] && button_on) - { - if (i == mousebprevweapon) - { - next_weapon = -1; - } - else if (i == mousebnextweapon) - { - next_weapon = 1; - } - } - - mousebuttons[i] = button_on; - } -} - -/* g_check_spot - * Returns false if the player cannot be respawned - * at the given mapthing_t spot because something is occupying it - */ - -static boolean g_check_spot(int playernum, mapthing_t *mthing) -{ - fixed_t x; - fixed_t y; - subsector_t *ss; - mobj_t *mo; - int i; - - if (!players[playernum].mo) - { - /* first spawn of level, before corpses */ - - for (i = 0; i < playernum; i++) - { - if (players[i].mo->x == mthing->x << FRACBITS && - players[i].mo->y == mthing->y << FRACBITS) - { - return false; - } - } - - return true; - } - - x = mthing->x << FRACBITS; - y = mthing->y << FRACBITS; - - if (!p_check_position(players[playernum].mo, x, y)) return false; - - /* flush an old corpse if needed */ - - if (bodyqueslot >= BODYQUESIZE) - { - p_remove_mobj(bodyque[bodyqueslot % BODYQUESIZE]); - } - - bodyque[bodyqueslot % BODYQUESIZE] = players[playernum].mo; - bodyqueslot++; - - /* spawn a teleport fog */ - - ss = r_point_in_subsector(x, y); - - /* The code in the released source looks like this: - * - * an = ( ANG45 * (((unsigned int) mthing->angle)/45) ) - * >> ANGLETOFINESHIFT; - * mo = p_spawn_mobj (x+20*finecosine[an], y+20*finesine[an] - * , ss->sector->floorheight - * , MT_TFOG); - * - * But 'an' can be a signed value in the DOS version. This means that - * we get a negative index and the lookups into finecosine/finesine - * end up dereferencing values in finetangent[]. - * A player spawning on a deathmatch start facing directly west spawns - * "silently" with no spawn fog. Emulate this. - * - * This code is imported from PrBoom+. - */ - - fixed_t xa; - fixed_t ya; - signed int an; - - /* This calculation overflows in Vanilla Doom, but here we deliberately - * avoid integer overflow as it is undefined behavior, so the value of - * 'an' will always be positive. - */ - - an = (ANG45 >> ANGLETOFINESHIFT) * ((signed int)mthing->angle / 45); - - switch (an) - { - case 4096: /* -4096: */ - xa = finetangent[2048]; /* finecosine[-4096] */ - ya = finetangent[0]; /* finesine[-4096] */ - break; - case 5120: /* -3072: */ - xa = finetangent[3072]; /* finecosine[-3072] */ - ya = finetangent[1024]; /* finesine[-3072] */ - break; - case 6144: /* -2048: */ - xa = finesine[0]; /* finecosine[-2048] */ - ya = finetangent[2048]; /* finesine[-2048] */ - break; - case 7168: /* -1024: */ - xa = finesine[1024]; /* finecosine[-1024] */ - ya = finetangent[3072]; /* finesine[-1024] */ - break; - case 0: - case 1024: - case 2048: - case 3072: - xa = finecosine[an]; - ya = finesine[an]; - break; - case 8192: /* 360 deg: */ - xa = tantoangle[0]; /* finecosine[8192] */ - ya = finesine[8192]; /* finesine[8192] */ - break; - default: - i_error("g_check_spot: unexpected angle %d\n", an); - xa = ya = 0; - break; - } - - mo = p_spawn_mobj(x + 20 * xa, y + 20 * ya, ss->sector->floorheight, - MT_TFOG); - -#ifdef CONFIG_GAMES_NXDOOM_SOUND - if (players[consoleplayer].viewz != 1) - { - /* don't start sound on first frame */ - - s_start_sound(mo, SFX_TELEPT); - } -#else - UNUSED(mo); -#endif - - return true; -} - -static void g_do_reborn(int playernum) -{ - int i; - - if (!netgame) - { - /* reload the level from scratch */ - - gameaction = ga_loadlevel; - } - else - { - /* respawn at the start first disassociate the corpse */ - - players[playernum].mo->player = NULL; - - /* spawn at random spot if in death match */ - - if (deathmatch) - { - g_death_match_spawn_player(playernum); - return; - } - - if (g_check_spot(playernum, &playerstarts[playernum])) - { - p_spawn_player(&playerstarts[playernum]); - return; - } - - /* try to spawn at one of the other players spots */ - - for (i = 0; i < MAXPLAYERS; i++) - { - if (g_check_spot(playernum, &playerstarts[i])) - { - playerstarts[i].type = playernum + 1; /* fake as other player */ - p_spawn_player(&playerstarts[i]); - playerstarts[i].type = i + 1; /* restore */ - return; - } - - /* he's going to be inside something. Too bad. */ - } - - p_spawn_player(&playerstarts[playernum]); - } -} - -static void g_do_new_game(void) -{ - demoplayback = false; - netdemo = false; - netgame = false; - deathmatch = false; - playeringame[1] = playeringame[2] = playeringame[3] = 0; - respawnparm = false; - fastparm = false; - nomonsters = false; - consoleplayer = 0; - g_init_new(d_skill, d_episode, d_map); - gameaction = ga_nothing; -} - -static void g_do_save_game(void) -{ - char *savegame_file; - char *temp_savegame_file; - char *recovery_savegame_file; - - recovery_savegame_file = NULL; - temp_savegame_file = p_temp_save_game_file(); - savegame_file = p_save_game_file(savegameslot); - - /* Open the savegame file for writing. We write to a temporary file - * and then rename it at the end if it was successfully written. - * This prevents an existing savegame from being overwritten by - * a corrupted one, or if a savegame buffer overrun occurs. - */ - - save_stream = fopen(temp_savegame_file, "wb"); - - if (save_stream == NULL) - { - /* Failed to save the game, so we're going to have to abort. But - * to be nice, save to somewhere else before we call i_error(). - */ - - recovery_savegame_file = m_temp_file("recovery.dsg"); - save_stream = fopen(recovery_savegame_file, "wb"); - if (save_stream == NULL) - { - i_error("Failed to open either '%s' or '%s' to write savegame.", - temp_savegame_file, recovery_savegame_file); - } - } - - savegame_error = false; - - p_write_save_game_header(savedescription); - - p_archive_players(); - p_archive_world(); - p_archive_thinkers(); - p_archive_specials(); - - p_write_save_game_eof(); - - /* Enforce the same savegame size limit as in Vanilla Doom, - * except if the vanilla_savegame_limit setting is turned off. - */ - - if (vanilla_savegame_limit && ftell(save_stream) > SAVEGAMESIZE) - { - i_error("Savegame buffer overrun"); - } - - /* Finish up, close the savegame file. */ - - fclose(save_stream); - - if (recovery_savegame_file != NULL) - { - /* We failed to save to the normal location, but we wrote a - * recovery file to the temp directory. Now we can bomb out - * with an error. - */ - - i_error("Failed to open savegame file '%s' for writing.\n" - "But your game has been saved to '%s' for recovery.", - temp_savegame_file, recovery_savegame_file); - } - - /* Now rename the temporary savegame file to the actual savegame - * file, overwriting the old savegame if there was one there. - */ - - remove(savegame_file); - rename(temp_savegame_file, savegame_file); - - gameaction = ga_nothing; - m_str_copy(savedescription, "", sizeof(savedescription)); - - players[consoleplayer].message = (GGSAVED); - - /* draw the pattern into the back screen */ - - r_fill_back_screen(); -} - -/* Generate a string describing a demo version */ - -static const char *demo_version_description(int version) -{ - static char resultbuf[24]; - - switch (version) - { - case 104: - return "v1.4"; - case 105: - return "v1.5"; - case 106: - return "v1.6/v1.666"; - case 107: - return "v1.7/v1.7a"; - case 108: - return "v1.8"; - case 109: - return "v1.9"; - case 111: - return "v1.91 hack demo?"; - default: - break; - } - - /* Unknown version. Perhaps this is a pre-v1.4 IWAD? If the version - * byte is in the range 0-4 then it can be a v1.0-v1.2 demo. - */ - - if (version >= 0 && version <= 4) - { - return "v1.0/v1.1/v1.2"; - } - else - { - snprintf(resultbuf, sizeof(resultbuf), "%i.%i (unknown)", - version / 100, version % 100); - return resultbuf; - } -} - -static void g_do_play_demo(void) -{ - skill_t skill; - int i; - int lumpnum; - int episode; - int map; - int demoversion; - boolean olddemo = false; - - lumpnum = w_get_num_for_name(defdemoname); - gameaction = ga_nothing; - demobuffer = w_cache_lump_num(lumpnum, PU_STATIC); - demo_p = demobuffer; - - demoversion = *demo_p++; - - if (demoversion >= 0 && demoversion <= 4) - { - olddemo = true; - demo_p--; - } - - longtics = false; - - /* Longtics demos use the modified format that is generated by cph's - * hacked "v1.91" doom exe. This is a non-vanilla extension. - */ - - if (d_non_vanilla_playback(demoversion == DOOM_191_VERSION, lumpnum, - "Doom 1.91 demo format")) - { - longtics = true; - } - else if (demoversion != g_vanilla_version_code() && - !(gameversion <= exe_doom_1_2 && olddemo)) - { - const char *message = "Demo is from a different game version!\n" - "(read %i, should be %i)\n" - "\n" - "*** You may need to upgrade your version " - "of Doom to v1.9. ***\n" - " See: https://www.doomworld.com/classicdoom" - "/info/patches.php\n" - " This appears to be %s."; - - i_error(message, demoversion, g_vanilla_version_code(), - demo_version_description(demoversion)); - } - - skill = *demo_p++; - episode = *demo_p++; - map = *demo_p++; - - if (!olddemo) - { - deathmatch = *demo_p++; - respawnparm = *demo_p++; - fastparm = *demo_p++; - nomonsters = *demo_p++; - consoleplayer = *demo_p++; - } - else - { - deathmatch = 0; - respawnparm = 0; - fastparm = 0; - nomonsters = 0; - consoleplayer = 0; - } - - for (i = 0; i < MAXPLAYERS; i++) - playeringame[i] = *demo_p++; - - if (playeringame[1] || m_check_parm("-solo-net") > 0 || - m_check_parm("-netdemo") > 0) - { - netgame = true; - netdemo = true; - } - - /* don't spend a lot of time in loadlevel */ - - precache = false; - g_init_new(skill, episode, map); - precache = true; - starttime = i_get_time(); - - usergame = false; - demoplayback = true; -} - -/* g_playerfinishlevel - * Can when a player completes a level. - */ - -static void g_player_finish_level(int player) -{ - player_t *p; - - p = &players[player]; - - memset(p->powers, 0, sizeof(p->powers)); - memset(p->cards, 0, sizeof(p->cards)); - p->mo->flags &= ~MF_SHADOW; /* cancel invisibility */ - p->extralight = 0; /* cancel gun flashes */ - p->fixedcolormap = 0; /* cancel ir gogles */ - p->damagecount = 0; /* no palette changes */ - p->bonuscount = 0; -} - -static void g_do_completed(void) -{ - int i; - - gameaction = ga_nothing; - - for (i = 0; i < MAXPLAYERS; i++) - { - if (playeringame[i]) - { - g_player_finish_level(i); /* take away cards and stuff */ - } - } - - if (automapactive) am_stop(); - - if (gamemode != commercial) - { - /* Chex Quest ends after 5 levels, rather than 8. */ - - if (gameversion == exe_chex) - { - if (gamemap == 5) - { - gameaction = ga_victory; - return; - } - } - else - { - switch (gamemap) - { - case 8: - gameaction = ga_victory; - return; - case 9: - for (i = 0; i < MAXPLAYERS; i++) - players[i].didsecret = true; - break; - } - } - } - - /* #if 0 Hmmm - why? */ - - if ((gamemap == 8) && (gamemode != commercial)) - { - /* victory */ - - gameaction = ga_victory; - return; - } - - if ((gamemap == 9) && (gamemode != commercial)) - { - /* exit secret level */ - - for (i = 0; i < MAXPLAYERS; i++) - players[i].didsecret = true; - } - - /* #endif */ - - wminfo.didsecret = players[consoleplayer].didsecret; - wminfo.epsd = gameepisode - 1; - wminfo.last = gamemap - 1; - - /* wminfo.next is 0 biased, unlike gamemap */ - - if (gamemode == commercial) - { - if (secretexit) switch (gamemap) - { - case 15: - wminfo.next = 30; - break; - case 31: - wminfo.next = 31; - break; - } - else - switch (gamemap) - { - case 31: - case 32: - wminfo.next = 15; - break; - default: - wminfo.next = gamemap; - } - } - else - { - if (secretexit) - wminfo.next = 8; /* go to secret level */ - else if (gamemap == 9) - { - /* returning from secret level */ - - switch (gameepisode) - { - case 1: - wminfo.next = 3; - break; - case 2: - wminfo.next = 5; - break; - case 3: - wminfo.next = 6; - break; - case 4: - wminfo.next = 2; - break; - } - } - else - wminfo.next = gamemap; /* go to next level */ - } - - wminfo.maxkills = totalkills; - wminfo.maxitems = totalitems; - wminfo.maxsecret = totalsecret; - wminfo.maxfrags = 0; - - /* Set par time. Exceptions are added for purposes of - * statcheck regression testing. - */ - - if (gamemode == commercial) - { - /* map33 reads its par time from beyond the cpars[] array */ - - if (gamemap == 33) - { - int cpars32; - - memcpy(&cpars32, (GAMMALVL0), sizeof(int)); - cpars32 = LONG(cpars32); - - wminfo.partime = TICRATE * cpars32; - } - else - { - wminfo.partime = TICRATE * cpars[gamemap - 1]; - } - } - - /* Doom episode 4 doesn't have a par time, so this - * overflows into the cpars array. - */ - - else if (gameepisode < 4) - { - if (gameversion == exe_chex && gameepisode == 1 && gamemap < 6) - { - wminfo.partime = TICRATE * chexpars[gamemap]; - } - else - { - wminfo.partime = TICRATE * pars[gameepisode][gamemap]; - } - } - else - { - wminfo.partime = TICRATE * cpars[gamemap]; - } - - wminfo.pnum = consoleplayer; - - for (i = 0; i < MAXPLAYERS; i++) - { - wminfo.plyr[i].in = playeringame[i]; - wminfo.plyr[i].skills = players[i].killcount; - wminfo.plyr[i].sitems = players[i].itemcount; - wminfo.plyr[i].ssecret = players[i].secretcount; - wminfo.plyr[i].stime = leveltime; - memcpy(wminfo.plyr[i].frags, players[i].frags, - sizeof(wminfo.plyr[i].frags)); - } - - gamestate = GS_INTERMISSION; - viewactive = false; - automapactive = false; - - stat_copy(&wminfo); - - wi_start(&wminfo); -} - -static void g_do_world_done(void) -{ - gamestate = GS_LEVEL; - gamemap = wminfo.next + 1; - g_do_load_level(); - gameaction = ga_nothing; - viewactive = true; -} - -/* Increase the size of the demo buffer to allow unlimited demos */ - -static void increase_demo_buffer(void) -{ - int current_length; - byte *new_demobuffer; - byte *new_demop; - int new_length; - - /* Find the current size */ - - current_length = demoend - demobuffer; - - /* Generate a new buffer twice the size */ - - new_length = current_length * 2; - - new_demobuffer = z_malloc(new_length, PU_STATIC, 0); - new_demop = new_demobuffer + (demo_p - demobuffer); - - /* Copy over the old data */ - - memcpy(new_demobuffer, demobuffer, current_length); - - /* Free the old buffer and point the demo pointers at the new buffer. */ - - z_free(demobuffer); - - demobuffer = new_demobuffer; - demo_p = new_demop; - demoend = demobuffer + new_length; -} - -/* DEMO RECORDING */ - -static void g_read_demo_ticcmd(ticcmd_t *cmd) -{ - if (*demo_p == DEMOMARKER) - { - /* end of demo data stream */ - - g_check_demo_status(); - return; - } - - cmd->forwardmove = ((signed char)*demo_p++); - cmd->sidemove = ((signed char)*demo_p++); - - /* If this is a longtics demo, read back in higher resolution */ - - if (longtics) - { - cmd->angleturn = *demo_p++; - cmd->angleturn |= (*demo_p++) << 8; - } - else - { - cmd->angleturn = ((unsigned char)*demo_p++) << 8; - } - - cmd->buttons = (unsigned char)*demo_p++; -} - -static void g_write_demo_ticcmd(ticcmd_t *cmd) -{ - byte *demo_start; - - if (gamekeydown[key_demo_quit]) /* press q to end demo recording */ - g_check_demo_status(); - - demo_start = demo_p; - - *demo_p++ = cmd->forwardmove; - *demo_p++ = cmd->sidemove; - - /* If this is a longtics demo, record in higher resolution */ - - if (longtics) - { - *demo_p++ = (cmd->angleturn & 0xff); - *demo_p++ = (cmd->angleturn >> 8) & 0xff; - } - else - { - *demo_p++ = cmd->angleturn >> 8; - } - - *demo_p++ = cmd->buttons; - - /* reset demo pointer back */ - - demo_p = demo_start; - - if (demo_p > demoend - 16) - { - if (vanilla_demo_limit) - { - /* no more space */ - - g_check_demo_status(); - return; - } - else - { - /* Vanilla demo limit disabled: unlimited - * demo lengths! - */ - - increase_demo_buffer(); - } - } - - g_read_demo_ticcmd(cmd); /* make SURE it is exactly the same */ -} - -/* Called at the start. - * Called by the game initialization functions. - */ - -#if 0 /* UNUSED */ -static void g_init_player(int player) -{ - /* clear everything else to defaults */ - - g_player_reborn(player); -} -#endif - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/* g_build_ticcmd - * Builds a ticcmd from all of the available inputs - * or reads it from the demo buffer. - * If recording a demo, write it out - */ - -void g_build_ticcmd(ticcmd_t *cmd, int maketic) -{ - int i; - boolean strafe; - boolean bstrafe; - int speed; - int tspeed; - int forward; - int side; - - memset(cmd, 0, sizeof(ticcmd_t)); - - cmd->consistency = - consistency[consoleplayer] - [maketic % CONFIG_GAMES_NXDOOM_NET_BACKUPTICS]; - - strafe = gamekeydown[key_strafe] || mousebuttons[mousebstrafe] || - joybuttons[joybstrafe]; - - /* fraggle: support the old "joyb_speed = 31" hack which - * allowed an autorun effect - */ - - speed = key_speed >= NUMKEYS || joybspeed >= MAX_JOY_BUTTONS || - gamekeydown[key_speed] || joybuttons[joybspeed] || - mousebuttons[mousebspeed]; - - forward = side = 0; - - /* use two stage accelerative turning - * on the keyboard and joystick - */ - - if (joyxmove < 0 || joyxmove > 0 || gamekeydown[key_right] || - gamekeydown[key_left] || mousebuttons[mousebturnright] || - mousebuttons[mousebturnleft]) - { - turnheld += ticdup; - } - else - { - turnheld = 0; - } - - if (turnheld < SLOWTURNTICS) - { - tspeed = 2; /* slow turn */ - } - else - { - tspeed = speed; - } - - /* let movement keys cancel each other out */ - - if (strafe) - { - if (gamekeydown[key_right] || mousebuttons[mousebturnright]) - { - side += sidemove[speed]; - } - - if (gamekeydown[key_left] || mousebuttons[mousebturnleft]) - { - side -= sidemove[speed]; - } - - if (use_analog && joyxmove) - { - joyxmove = joyxmove * joystick_move_sensitivity / 10; - joyxmove = (joyxmove > FRACUNIT) ? FRACUNIT : joyxmove; - joyxmove = (joyxmove < -FRACUNIT) ? -FRACUNIT : joyxmove; - side += fixed_mul(sidemove[speed], joyxmove); - } - else if (joystick_move_sensitivity) - { - if (joyxmove > 0) side += sidemove[speed]; - if (joyxmove < 0) side -= sidemove[speed]; - } - } - else - { - if (gamekeydown[key_right] || mousebuttons[mousebturnright]) - cmd->angleturn -= angleturn[tspeed]; - if (gamekeydown[key_left] || mousebuttons[mousebturnleft]) - cmd->angleturn += angleturn[tspeed]; - if (use_analog && joyxmove) - { - /* Cubic response curve allows for finer control when stick - * deflection is small. - */ - - joyxmove = fixed_mul(fixed_mul(joyxmove, joyxmove), joyxmove); - joyxmove = joyxmove * joystick_turn_sensitivity / 10; - cmd->angleturn -= fixed_mul(angleturn[1], joyxmove); - } - else if (joystick_turn_sensitivity) - { - if (joyxmove > 0) cmd->angleturn -= angleturn[tspeed]; - if (joyxmove < 0) cmd->angleturn += angleturn[tspeed]; - } - } - - if (gamekeydown[key_up]) - { - forward += forwardmove[speed]; - } - - if (gamekeydown[key_down]) - { - forward -= forwardmove[speed]; - } - - if (use_analog && joyymove) - { - joyymove = joyymove * joystick_move_sensitivity / 10; - joyymove = (joyymove > FRACUNIT) ? FRACUNIT : joyymove; - joyymove = (joyymove < -FRACUNIT) ? -FRACUNIT : joyymove; - forward -= fixed_mul(forwardmove[speed], joyymove); - } - else if (joystick_move_sensitivity) - { - if (joyymove < 0) forward += forwardmove[speed]; - if (joyymove > 0) forward -= forwardmove[speed]; - } - - if (gamekeydown[key_strafeleft] || joybuttons[joybstrafeleft] || - mousebuttons[mousebstrafeleft]) - { - side -= sidemove[speed]; - } - - if (gamekeydown[key_straferight] || joybuttons[joybstraferight] || - mousebuttons[mousebstraferight]) - { - side += sidemove[speed]; - } - - if (use_analog && joystrafemove) - { - joystrafemove = joystrafemove * joystick_move_sensitivity / 10; - joystrafemove = (joystrafemove > FRACUNIT) ? FRACUNIT : joystrafemove; - joystrafemove = - (joystrafemove < -FRACUNIT) ? -FRACUNIT : joystrafemove; - side += fixed_mul(sidemove[speed], joystrafemove); - } - else if (joystick_move_sensitivity) - { - if (joystrafemove < 0) side -= sidemove[speed]; - if (joystrafemove > 0) side += sidemove[speed]; - } - - /* buttons */ - - cmd->chatchar = hu_dequeue_chat_char(); - - if (gamekeydown[key_fire] || mousebuttons[mousebfire] || - joybuttons[joybfire]) - cmd->buttons |= BT_ATTACK; - - if (gamekeydown[key_use] || joybuttons[joybuse] || mousebuttons[mousebuse]) - { - cmd->buttons |= BT_USE; - dclicks = 0; /* clear double clicks if hit use button */ - } - - /* If the previous or next weapon button is pressed, the - * next_weapon variable is set to change weapons when - * we generate a ticcmd. Choose a new weapon. - */ - - if (gamestate == GS_LEVEL && next_weapon != 0) - { - i = g_next_weapon(next_weapon); - cmd->buttons |= BT_CHANGE; - cmd->buttons |= i << BT_WEAPONSHIFT; - } - else - { - /* Check weapon keys. */ - - for (i = 0; i < arrlen(weapon_keys); ++i) - { - int key = *weapon_keys[i]; - - if (gamekeydown[key]) - { - cmd->buttons |= BT_CHANGE; - cmd->buttons |= i << BT_WEAPONSHIFT; - break; - } - } - } - - next_weapon = 0; - - /* mouse */ - - if (mousebuttons[mousebforward]) - { - forward += forwardmove[speed]; - } - - if (mousebuttons[mousebbackward]) - { - forward -= forwardmove[speed]; - } - - if (dclick_use) - { - /* forward double click */ - - if (mousebuttons[mousebforward] != dclickstate && dclicktime > 1) - { - dclickstate = mousebuttons[mousebforward]; - if (dclickstate) dclicks++; - if (dclicks == 2) - { - cmd->buttons |= BT_USE; - dclicks = 0; - } - else - dclicktime = 0; - } - else - { - dclicktime += ticdup; - if (dclicktime > 20) - { - dclicks = 0; - dclickstate = 0; - } - } - - /* strafe double click */ - - bstrafe = mousebuttons[mousebstrafe] || joybuttons[joybstrafe]; - if (bstrafe != dclickstate2 && dclicktime2 > 1) - { - dclickstate2 = bstrafe; - if (dclickstate2) dclicks2++; - if (dclicks2 == 2) - { - cmd->buttons |= BT_USE; - dclicks2 = 0; - } - else - dclicktime2 = 0; - } - else - { - dclicktime2 += ticdup; - if (dclicktime2 > 20) - { - dclicks2 = 0; - dclickstate2 = 0; - } - } - } - - forward += mousey; - - if (strafe) - side += mousex * 2; - else - cmd->angleturn -= mousex * 0x8; - - if (mousex == 0) - { - /* No movement in the previous frame */ - - testcontrols_mousespeed = 0; - } - - mousex = mousey = 0; - - if (forward > MAXPLMOVE) - forward = MAXPLMOVE; - else if (forward < -MAXPLMOVE) - forward = -MAXPLMOVE; - if (side > MAXPLMOVE) - side = MAXPLMOVE; - else if (side < -MAXPLMOVE) - side = -MAXPLMOVE; - - cmd->forwardmove += forward; - cmd->sidemove += side; - - /* special buttons */ - - if (sendpause) - { - sendpause = false; - cmd->buttons = BT_SPECIAL | BTS_PAUSE; - } - - if (sendsave) - { - sendsave = false; - cmd->buttons = - BT_SPECIAL | BTS_SAVEGAME | (savegameslot << BTS_SAVESHIFT); - } - - /* low-res turning */ - - if (lowres_turn) - { - static signed short carry = 0; - signed short desired_angleturn; - - desired_angleturn = cmd->angleturn + carry; - - /* round angleturn to the nearest 256 unit boundary - * for recording demos with single byte values for turn - */ - - cmd->angleturn = (desired_angleturn + 128) & 0xff00; - - /* Carry forward the error from the reduced resolution to the - * next tic, so that successive small movements can accumulate. - */ - - carry = desired_angleturn - cmd->angleturn; - } -} - -/* g_responder - * Get info needed to make ticcmd_ts for the players. - */ - -boolean g_responder(event_t *ev) -{ - /* allow spy mode changes even during the demo */ - - if (gamestate == GS_LEVEL && ev->type == ev_keydown && - ev->data1 == key_spy && (singledemo || !deathmatch)) - { - /* spy mode */ - - do - { - displayplayer++; - if (displayplayer == MAXPLAYERS) displayplayer = 0; - } - while (!playeringame[displayplayer] && displayplayer != consoleplayer); - return true; - } - - /* any other key pops up menu if in demos */ - - if (gameaction == ga_nothing && !singledemo && - (demoplayback || gamestate == GS_DEMOSCREEN)) - { - if (ev->type == ev_keydown || (ev->type == ev_mouse && ev->data1) || - (ev->type == ev_joystick && ev->data1)) - { - m_start_control_panel(); - joywait = i_get_time() + 5; - return true; - } - - return false; - } - - if (gamestate == GS_LEVEL) - { -#if 0 - if (devparm && ev->type == ev_keydown && ev->data1 == ';') - { - g_death_match_spawn_player(0); - return true; - } - -#endif - if (hu_responder(ev)) return true; /* chat ate the event */ - if (st_responder(ev)) return true; /* status window ate it */ - if (am_responder(ev)) return true; /* automap ate it */ - } - - if (gamestate == GS_FINALE) - { - if (f_responder(ev)) return true; /* finale ate the event */ - } - - if (testcontrols && ev->type == ev_mouse) - { - /* If we are invoked by setup to test the controls, save the - * mouse speed so that we can display it on-screen. - * Perform a low pass filter on this so that the thermometer - * appears to move smoothly. - */ - - testcontrols_mousespeed = abs(ev->data2); - } - - /* If the next/previous weapon keys are pressed, set the next_weapon - * variable to change weapons when the next ticcmd is generated. - */ - - if (ev->type == ev_keydown && ev->data1 == key_prevweapon) - { - next_weapon = -1; - } - else if (ev->type == ev_keydown && ev->data1 == key_nextweapon) - { - next_weapon = 1; - } - - switch (ev->type) - { - case ev_keydown: - if (ev->data1 == key_pause) - { - sendpause = true; - } - else if (ev->data1 < NUMKEYS) - { - gamekeydown[ev->data1] = true; - } - - return true; /* eat key down events */ - - case ev_keyup: - if (ev->data1 < NUMKEYS) gamekeydown[ev->data1] = false; - return false; /* always let key up events filter down */ - - case ev_mouse: - set_mouse_buttons(ev->data1); - mousex = ev->data2 * (g_mouse_sensitivity + 5) / 10; - mousey = ev->data3 * (g_mouse_sensitivity + 5) / 10; - return true; /* eat events */ - - case ev_joystick: - set_joy_buttons(ev->data1); - joyxmove = ev->data2; - joyymove = ev->data3; - joystrafemove = ev->data4; - return true; /* eat events */ - - default: - break; - } - - return false; -} - -/* g_ticker - * Make ticcmd_ts for the players. - */ - -void g_ticker(void) -{ - int i; - int buf; - ticcmd_t *cmd; - - /* do player reborns if needed */ - - for (i = 0; i < MAXPLAYERS; i++) - { - if (playeringame[i] && players[i].playerstate == PST_REBORN) - { - g_do_reborn(i); - } - } - - /* do things to change the game state */ - - while (gameaction != ga_nothing) - { - switch (gameaction) - { - case ga_loadlevel: - g_do_load_level(); - break; - case ga_newgame: - g_do_new_game(); - break; - case ga_loadgame: - g_do_load_game(); - break; - case ga_savegame: - g_do_save_game(); - break; - case ga_playdemo: - g_do_play_demo(); - break; - case ga_completed: - g_do_completed(); - break; - case ga_victory: - f_start_finale(); - break; - case ga_worlddone: - g_do_world_done(); - break; - case ga_screenshot: - v_screenshot("DOOM%02i.%s"); - players[consoleplayer].message = ("screen shot"); - gameaction = ga_nothing; - break; - case ga_nothing: - break; - } - } - - /* get commands, check consistency, and build new consistency check */ - - buf = (gametic / ticdup) % CONFIG_GAMES_NXDOOM_NET_BACKUPTICS; - - for (i = 0; i < MAXPLAYERS; i++) - { - if (playeringame[i]) - { - cmd = &players[i].cmd; - - memcpy(cmd, &netcmds[i], sizeof(ticcmd_t)); - - if (demoplayback) g_read_demo_ticcmd(cmd); - if (demorecording) g_write_demo_ticcmd(cmd); - - /* check for turbo cheats - * check ~ 4 seconds whether to display the turbo message. - * store if the turbo threshold was exceeded in any tics - * over the past 4 seconds. offset the checking period - * for each player so messages are not displayed at the - * same time. - */ - - if (cmd->forwardmove > TURBOTHRESHOLD) - { - turbodetected[i] = true; - } - - if ((gametic & 31) == 0 && ((gametic >> 5) % MAXPLAYERS) == i && - turbodetected[i]) - { - static char turbomessage[80]; - snprintf(turbomessage, sizeof(turbomessage), "%s is turbo!", - player_names[i]); - players[consoleplayer].message = turbomessage; - turbodetected[i] = false; - } - - if (netgame && !netdemo && !(gametic % ticdup)) - { - if (gametic > CONFIG_GAMES_NXDOOM_NET_BACKUPTICS && - consistency[i][buf] != cmd->consistency) - { - i_error("consistency failure (%i should be %i)", - cmd->consistency, consistency[i][buf]); - } - - if (players[i].mo) - consistency[i][buf] = players[i].mo->x; - else - consistency[i][buf] = rndindex; - } - } - } - - /* check for special buttons */ - - for (i = 0; i < MAXPLAYERS; i++) - { - if (playeringame[i]) - { - if (players[i].cmd.buttons & BT_SPECIAL) - { - switch (players[i].cmd.buttons & BT_SPECIALMASK) - { - case BTS_PAUSE: - paused ^= 1; -#ifdef CONFIG_GAMES_NXDOOM_SOUND - if (paused) - s_pause_sound(); - else - s_resume_sound(); - break; -#endif - - case BTS_SAVEGAME: - if (!savedescription[0]) - { - m_str_copy(savedescription, "NET GAME", - sizeof(savedescription)); - } - - savegameslot = (players[i].cmd.buttons & BTS_SAVEMASK) >> - BTS_SAVESHIFT; - gameaction = ga_savegame; - break; - } - } - } - } - - /* Have we just finished displaying an intermission screen? */ - - if (oldgamestate == GS_INTERMISSION && gamestate != GS_INTERMISSION) - { - wi_end(); - } - - oldgamestate = gamestate; - - /* do main actions */ - - switch (gamestate) - { - case GS_LEVEL: - p_ticker(); - st_ticker(); - am_ticker(); - hu_ticker(); - break; - - case GS_INTERMISSION: - wi_ticker(); - break; - - case GS_FINALE: - f_ticker(); - break; - - case GS_DEMOSCREEN: - d_page_ticker(); - break; - } -} - -/* PLAYER STRUCTURE FUNCTIONS - * also see p_spawn_player in P_Things - */ - -/* g_player_reborn - * Called after a player dies almost everything is cleared and initialized - */ - -void g_player_reborn(int player) -{ - player_t *p; - int i; - int frags[MAXPLAYERS]; - int killcount; - int itemcount; - int secretcount; - - memcpy(frags, players[player].frags, sizeof(frags)); - killcount = players[player].killcount; - itemcount = players[player].itemcount; - secretcount = players[player].secretcount; - - p = &players[player]; - memset(p, 0, sizeof(*p)); - - memcpy(players[player].frags, frags, sizeof(players[player].frags)); - players[player].killcount = killcount; - players[player].itemcount = itemcount; - players[player].secretcount = secretcount; - - p->usedown = p->attackdown = true; /* don't do anything immediately */ - p->playerstate = PST_LIVE; - p->health = deh_initial_health; /* Use dehacked value */ - p->readyweapon = p->pendingweapon = wp_pistol; - p->weaponowned[wp_fist] = true; - p->weaponowned[wp_pistol] = true; - p->ammo[am_clip] = deh_initial_bullets; - - for (i = 0; i < NUMAMMO; i++) - p->maxammo[i] = maxammo[i]; -} - -/* g_death_match_spawn_player - * Spawns a player at one of the random death match spots - * called at level load and each death - */ - -void g_death_match_spawn_player(int playernum) -{ - int i; - int j; - int selections; - - selections = deathmatch_p - deathmatchstarts; - if (selections < 4) - i_error("Only %i deathmatch spots, 4 required", selections); - - for (j = 0; j < 20; j++) - { - i = p_random() % selections; - if (g_check_spot(playernum, &deathmatchstarts[i])) - { - deathmatchstarts[i].type = playernum + 1; - p_spawn_player(&deathmatchstarts[i]); - return; - } - } - - /* no good spot, so the player will probably get stuck */ - - p_spawn_player(&playerstarts[playernum]); -} - -void g_screenshot(void) -{ - gameaction = ga_screenshot; -} - -void g_exit_level(void) -{ - secretexit = false; - gameaction = ga_completed; -} - -/* Here's for the german edition. */ - -void g_secret_exit_level(void) -{ - /* IF NO WOLF3D LEVELS, NO SECRET EXIT! */ - - if ((gamemode == commercial) && (w_check_num_for_name("map31") < 0)) - secretexit = false; - else - secretexit = true; - gameaction = ga_completed; -} - -void g_world_done(void) -{ - gameaction = ga_worlddone; - - if (secretexit) players[consoleplayer].didsecret = true; - - if (gamemode == commercial) - { - switch (gamemap) - { - case 15: - case 31: - if (!secretexit) break; - case 6: - case 11: - case 20: - case 30: - f_start_finale(); - break; - } - } -} - -/* g_initfromsavegame - * Can be called by the startup code or the menu task. - */ - -void g_load_game(char *name) -{ - m_str_copy(savename, name, sizeof(savename)); - gameaction = ga_loadgame; -} - -void g_do_load_game(void) -{ - int savedleveltime; - - gameaction = ga_nothing; - - save_stream = fopen(savename, "rb"); - - if (save_stream == NULL) - { - i_error("Could not load savegame %s", savename); - } - - savegame_error = false; - - if (!p_read_save_game_header()) - { - fclose(save_stream); - return; - } - - savedleveltime = leveltime; - - /* load a base level */ - - g_init_new(gameskill, gameepisode, gamemap); - - leveltime = savedleveltime; - - /* dearchive all the modifications */ - - p_unarchive_players(); - p_unarchive_world(); - p_unarchive_thinkers(); - p_unarchive_specials(); - - if (!p_read_save_game_eof()) i_error("Bad savegame"); - - fclose(save_stream); - - if (setsizeneeded) r_execute_set_view_size(); - - /* draw the pattern into the back screen */ - - r_fill_back_screen(); -} - -/* g_save_game - * Called by the menu task. - * Description is a 24 byte text string - */ - -void g_save_game(int slot, char *description) -{ - savegameslot = slot; - m_str_copy(savedescription, description, sizeof(savedescription)); - sendsave = true; -} - -/* g_init_new - * Can be called by the startup code or the menu task, - * consoleplayer, displayplayer, playeringame[] should be set. - */ - -void g_deferred_init_new(skill_t skill, int episode, int map) -{ - d_skill = skill; - d_episode = episode; - d_map = map; - gameaction = ga_newgame; -} - -void g_init_new(skill_t skill, int episode, int map) -{ - const char *skytexturename; - int i; - - if (paused) - { - paused = false; -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_resume_sound(); -#endif - } - - /* Note: This commented-out block of code was added at some point - * between the DOS version(s) and the Doom source release. It isn't - * found in disassemblies of the DOS version and causes IDCLEV and - * the -warp command line parameter to behave differently. - * This is left here for posterity. - * This was quite messy with SPECIAL and commented parts. - * Supposedly hacks to make the latest edition work. - * It might not work properly. - * - * if (episode < 1) - * episode = 1; - * if ( gamemode == retail ) - * { - * if (episode > 4) - * episode = 4; - * } - * else if ( gamemode == shareware ) - * { - * if (episode > 1) - * episode = 1; // only start episode 1 on shareware - * } - * else - * { - * if (episode > 3) - * episode = 3; - * } - */ - - if (skill > sk_nightmare) skill = sk_nightmare; - - if (gameversion >= exe_ultimate) - { - if (episode == 0) - { - episode = 4; - } - } - else - { - if (episode < 1) - { - episode = 1; - } - - if (episode > 3) - { - episode = 3; - } - } - - if (episode > 1 && gamemode == shareware) - { - episode = 1; - } - - if (map < 1) map = 1; - - if ((map > 9) && (gamemode != commercial)) map = 9; - - m_clear_random(); - - if (skill == sk_nightmare || respawnparm) - respawnmonsters = true; - else - respawnmonsters = false; - - if (fastparm || (skill == sk_nightmare && gameskill != sk_nightmare)) - { - for (i = S_SARG_RUN1; i <= S_SARG_PAIN2; i++) - states[i].tics >>= 1; - mobjinfo[MT_BRUISERSHOT].speed = 20 * FRACUNIT; - mobjinfo[MT_HEADSHOT].speed = 20 * FRACUNIT; - mobjinfo[MT_TROOPSHOT].speed = 20 * FRACUNIT; - } - else if (skill != sk_nightmare && gameskill == sk_nightmare) - { - for (i = S_SARG_RUN1; i <= S_SARG_PAIN2; i++) - states[i].tics <<= 1; - mobjinfo[MT_BRUISERSHOT].speed = 15 * FRACUNIT; - mobjinfo[MT_HEADSHOT].speed = 10 * FRACUNIT; - mobjinfo[MT_TROOPSHOT].speed = 10 * FRACUNIT; - } - - /* force players to be initialized upon first level load */ - - for (i = 0; i < MAXPLAYERS; i++) - players[i].playerstate = PST_REBORN; - - usergame = true; /* will be set false if a demo */ - paused = false; - demoplayback = false; - automapactive = false; - viewactive = true; - gameepisode = episode; - gamemap = map; - gameskill = skill; - - /* Set the sky to use. - * - * Note: This IS broken, but it is how Vanilla Doom behaves. - * See http: *doomwiki.org/wiki/Sky_never_changes_in_Doom_II. - * - * Because we set the sky here at the start of a game, not at the - * start of a level, the sky texture never changes unless we - * restore from a saved game. This was fixed before the Doom - * source release, but this IS the way Vanilla DOS Doom behaves. - */ - - if (gamemode == commercial) - { - skytexturename = ("SKY3"); - skytexture = r_texture_num_for_name(skytexturename); - if (gamemap < 21) - { - skytexturename = (gamemap < 12 ? "SKY1" : "SKY2"); - skytexture = r_texture_num_for_name(skytexturename); - } - } - else - { - switch (gameepisode) - { - default: - case 1: - skytexturename = "SKY1"; - break; - case 2: - skytexturename = "SKY2"; - break; - case 3: - skytexturename = "SKY3"; - break; - case 4: /* Special Edition sky */ - skytexturename = "SKY4"; - break; - } - - skytexturename = (skytexturename); - skytexture = r_texture_num_for_name(skytexturename); - } - - g_do_load_level(); -} - -void g_record_demo(const char *name) -{ - size_t demoname_size; - int i; - int maxsize; - - usergame = false; - demoname_size = strlen(name) + 5; - demoname = z_malloc(demoname_size, PU_STATIC, NULL); - snprintf(demoname, demoname_size, "%s.lmp", name); - maxsize = 0x20000; - - /* @arg - * @category demo - * @vanilla - * - * Specify the demo buffer size (KiB) - */ - - i = m_check_parm_with_args("-maxdemo", 1); - if (i) maxsize = atoi(myargv[i + 1]) * 1024; - demobuffer = z_malloc(maxsize, PU_STATIC, NULL); - demoend = demobuffer + maxsize; - - demorecording = true; -} - -/* Get the demo version code appropriate for the version set in gameversion. - */ - -int g_vanilla_version_code(void) -{ - switch (gameversion) - { - case exe_doom_1_666: - return 106; - case exe_doom_1_7: - return 107; - case exe_doom_1_8: - return 108; - case exe_doom_1_9: - default: /* All other versions are variants on v1.9: */ - return 109; - } -} - -void g_begin_recording(void) -{ - int i; - - demo_p = demobuffer; - - /* @category demo - * - * Record a high resolution "Doom 1.91" demo. - */ - - longtics = d_non_vanilla_record(m_parm_exists("-longtics"), - "Doom 1.91 demo format"); - - /* If not recording a longtics demo, record in low res */ - - lowres_turn = !longtics; - - if (longtics) - { - *demo_p++ = DOOM_191_VERSION; - } - else if (gameversion > exe_doom_1_2) - { - *demo_p++ = g_vanilla_version_code(); - } - - *demo_p++ = gameskill; - *demo_p++ = gameepisode; - *demo_p++ = gamemap; - if (longtics || gameversion > exe_doom_1_2) - { - *demo_p++ = deathmatch; - *demo_p++ = respawnparm; - *demo_p++ = fastparm; - *demo_p++ = nomonsters; - *demo_p++ = consoleplayer; - } - - for (i = 0; i < MAXPLAYERS; i++) - *demo_p++ = playeringame[i]; -} - -void g_defered_play_demo(const char *name) -{ - defdemoname = name; - gameaction = ga_playdemo; -} - -void g_time_demo(char *name) -{ - /* @category video - * @vanilla - * - * Disable rendering the screen entirely. - */ - - nodrawers = m_check_parm("-nodraw"); - - timingdemo = true; - singletics = true; - - defdemoname = name; - gameaction = ga_playdemo; -} - -/* g_check_demo_status - * - * Called after a death or level completion to allow demos to be cleaned up - * Returns true if a new demo loop action will take place - */ - -boolean g_check_demo_status(void) -{ - int endtime; - - if (timingdemo) - { - float fps; - int realtics; - - endtime = i_get_time(); - realtics = endtime - starttime; - fps = ((float)gametic * TICRATE) / realtics; - - /* Prevent recursive calls */ - - timingdemo = false; - demoplayback = false; - - i_error("timed %i gametics in %i realtics (%f fps)", gametic, realtics, - fps); - } - - if (demoplayback) - { - w_release_lump_name(defdemoname); - demoplayback = false; - netdemo = false; - netgame = false; - deathmatch = false; - playeringame[1] = playeringame[2] = playeringame[3] = 0; - respawnparm = false; - fastparm = false; - nomonsters = false; - consoleplayer = 0; - - if (singledemo) - i_quit(); - else - d_advance_demo(); - - return true; - } - - if (demorecording) - { - *demo_p++ = DEMOMARKER; - m_write_file(demoname, demobuffer, demo_p - demobuffer); - z_free(demobuffer); - demorecording = false; - i_error("Demo %s recorded", demoname); - } - - return false; -} diff --git a/games/NXDoom/src/doom/g_game.h b/games/NXDoom/src/doom/g_game.h deleted file mode 100644 index 80c3fe2ee..000000000 --- a/games/NXDoom/src/doom/g_game.h +++ /dev/null @@ -1,105 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/g_game.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Duh. - * - ****************************************************************************/ - -#ifndef __G_GAME__ -#define __G_GAME__ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "d_event.h" -#include "d_ticcmd.h" -#include "doomdef.h" -#include "m_fixed.h" - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -extern int vanilla_savegame_limit; -extern int vanilla_demo_limit; - -extern fixed_t forwardmove[2]; -extern fixed_t sidemove[2]; - -extern boolean sendpause; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/* GAME */ - -void g_death_match_spawn_player(int playernum); - -void g_init_new(skill_t skill, int episode, int map); - -/* Can be called by the startup code or m_responder. - * A normal game starts at map 1, - * but a warp test can start elsewhere - */ - -void g_deferred_init_new(skill_t skill, int episode, int map); - -void g_defered_play_demo(const char *demo); - -/* Can be called by the startup code or m_responder, - * calls p_setup_level or W_EnterWorld. - */ - -void g_load_game(char *name); - -void g_do_load_game(void); - -/* Called by m_responder. */ - -void g_save_game(int slot, char *description); - -/* Only called by startup code. */ - -void g_record_demo(const char *name); - -void g_begin_recording(void); - -void g_play_demo(char *name); -void g_time_demo(char *name); -boolean g_check_demo_status(void); - -void g_exit_level(void); -void g_secret_exit_level(void); - -void g_world_done(void); - -/* Read current data from inputs and build a player movement command. */ - -void g_build_ticcmd(ticcmd_t *cmd, int maketic); - -void g_ticker(void); -boolean g_responder(event_t *ev); - -void g_screenshot(void); - -int g_vanilla_version_code(void); - -#endif /* __G_GAME__ */ diff --git a/games/NXDoom/src/doom/hu_lib.c b/games/NXDoom/src/doom/hu_lib.c deleted file mode 100644 index cfa962331..000000000 --- a/games/NXDoom/src/doom/hu_lib.c +++ /dev/null @@ -1,318 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/hu_lib.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: heads-up text and input code - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include "doomdef.h" -#include "doomkeys.h" -#include "doomstat.h" - -#include "i_swap.h" -#include "v_video.h" - -#include "hu_lib.h" -#include "r_draw.h" -#include "r_local.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* boolean : whether the screen is always erased */ - -#define noterased viewwindowx - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -void hu_lib_clear_text(hu_textline_t *t) -{ - t->len = 0; - t->l[0] = 0; - t->needsupdate = true; -} - -void hu_lib_init_text_line(hu_textline_t *t, int x, int y, patch_t **f, - int sc) -{ - t->x = x; - t->y = y; - t->f = f; - t->sc = sc; - hu_lib_clear_text(t); -} - -boolean hu_lib_add_char_to_text_line(hu_textline_t *t, char ch) -{ - if (t->len == HU_MAXLINELENGTH) - { - return false; - } - else - { - t->l[t->len++] = ch; - t->l[t->len] = 0; - t->needsupdate = 4; - return true; - } -} - -boolean hu_lib_del_char_from_text_line(hu_textline_t *t) -{ - if (!t->len) - { - return false; - } - else - { - t->l[--t->len] = 0; - t->needsupdate = 4; - return true; - } -} - -void hu_lib_draw_text_line(hu_textline_t *l, boolean drawcursor) -{ - int i; - int w; - int x; - unsigned char c; - - /* draw the new stuff */ - - x = l->x; - for (i = 0; i < l->len; i++) - { - c = toupper(l->l[i]); - if (c != ' ' && c >= l->sc && c <= '_') - { - w = SHORT(l->f[c - l->sc]->width); - if (x + w > SCREENWIDTH) break; - v_draw_patch_direct(x, l->y, l->f[c - l->sc]); - x += w; - } - else - { - x += 4; - if (x >= SCREENWIDTH) break; - } - } - - /* draw the cursor if requested */ - - if (drawcursor && x + SHORT(l->f['_' - l->sc]->width) <= SCREENWIDTH) - { - v_draw_patch_direct(x, l->y, l->f['_' - l->sc]); - } -} - -/* sorta called by hu_erase and just better darn get things straight */ - -void hu_lib_erase_text_line(hu_textline_t *l) -{ - int lh; - int y; - int yoffset; - - /* Only erases when NOT in automap and the screen is reduced, and the text - * must either need updating or refreshing (because of a recent change back - * from the automap) - */ - - if (!automapactive && viewwindowx && l->needsupdate) - { - lh = SHORT(l->f[0]->height) + 1; - for (y = l->y, yoffset = y * SCREENWIDTH; y < l->y + lh; - y++, yoffset += SCREENWIDTH) - { - if (y < viewwindowy || y >= viewwindowy + viewheight) - r_video_erase(yoffset, SCREENWIDTH); /* erase entire line */ - else - { - r_video_erase(yoffset, viewwindowx); /* erase left border */ - r_video_erase(yoffset + viewwindowx + viewwidth, viewwindowx); - - /* erase right border */ - } - } - } - - if (l->needsupdate) l->needsupdate--; -} - -void hu_lib_init_stext(hu_stext_t *s, int x, int y, int h, patch_t **font, - int startchar, boolean *on) -{ - int i; - - s->h = h; - s->on = on; - s->laston = true; - s->cl = 0; - for (i = 0; i < h; i++) - hu_lib_init_text_line(&s->l[i], x, y - i * (SHORT(font[0]->height) + 1), - font, startchar); -} - -void hu_lib_add_line_to_stext(hu_stext_t *s) -{ - int i; - - /* add a clear line */ - - if (++s->cl == s->h) s->cl = 0; - hu_lib_clear_text(&s->l[s->cl]); - - /* everything needs updating */ - - for (i = 0; i < s->h; i++) - { - s->l[i].needsupdate = 4; - } -} - -void hu_lib_add_messsage_to_stext(hu_stext_t *s, const char *prefix, - const char *msg) -{ - hu_lib_add_line_to_stext(s); - - if (prefix) - { - while (*prefix) - { - hu_lib_add_char_to_text_line(&s->l[s->cl], *(prefix++)); - } - } - - while (*msg) - { - hu_lib_add_char_to_text_line(&s->l[s->cl], *(msg++)); - } -} - -void hu_lib_draw_stext(hu_stext_t *s) -{ - int i; - int idx; - hu_textline_t *l; - - if (!*s->on) return; /* if not on, don't draw */ - - /* draw everything */ - - for (i = 0; i < s->h; i++) - { - idx = s->cl - i; - if (idx < 0) idx += s->h; /* handle queue of lines */ - - l = &s->l[idx]; - - /* need a decision made here on whether to skip the draw */ - - hu_lib_draw_text_line(l, false); /* no cursor, please */ - } -} - -void hu_lib_erase_stext(hu_stext_t *s) -{ - int i; - - for (i = 0; i < s->h; i++) - { - if (s->laston && !*s->on) s->l[i].needsupdate = 4; - hu_lib_erase_text_line(&s->l[i]); - } - - s->laston = *s->on; -} - -void hu_lib_init_itext(hu_itext_t *it, int x, int y, patch_t **font, - int startchar, boolean *on) -{ - it->lm = 0; /* default left margin is start of text */ - it->on = on; - it->laston = true; - hu_lib_init_text_line(&it->l, x, y, font, startchar); -} - -/* The following deletion routines adhere to the left margin restriction */ - -void hu_lib_del_char_from_itext(hu_itext_t *it) -{ - if (it->l.len != it->lm) hu_lib_del_char_from_text_line(&it->l); -} - -/* Resets left margin as well */ - -void hu_lib_reset_itext(hu_itext_t *it) -{ - it->lm = 0; - hu_lib_clear_text(&it->l); -} - -/* wrapper function for handling general keyed input. - * returns true if it ate the key - */ - -boolean hu_lib_key_in_itext(hu_itext_t *it, unsigned char ch) -{ - ch = toupper(ch); - - if (ch >= ' ' && ch <= '_') - { - hu_lib_add_char_to_text_line(&it->l, (char)ch); - } - else if (ch == KEY_BACKSPACE) - { - hu_lib_del_char_from_itext(it); - } - else if (ch != KEY_ENTER) - { - return false; /* did not eat key */ - } - - return true; /* ate the key */ -} - -void hu_lib_draw_itext(hu_itext_t *it) -{ - hu_textline_t *l = &it->l; - - if (!*it->on) return; - hu_lib_draw_text_line(l, true); /* draw the line w/ cursor */ -} - -void hu_lib_erase_itext(hu_itext_t *it) -{ - if (it->laston && !*it->on) it->l.needsupdate = 4; - hu_lib_erase_text_line(&it->l); - it->laston = *it->on; -} diff --git a/games/NXDoom/src/doom/hu_lib.h b/games/NXDoom/src/doom/hu_lib.h deleted file mode 100644 index e9ab12a24..000000000 --- a/games/NXDoom/src/doom/hu_lib.h +++ /dev/null @@ -1,178 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/hu_lib.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: none - * - ****************************************************************************/ - -#ifndef __HULIB__ -#define __HULIB__ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -/* We are referring to patches. */ - -#include "r_defs.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* font stuff */ - -#define HU_CHARERASE KEY_BACKSPACE - -#define HU_MAXLINES 4 -#define HU_MAXLINELENGTH 80 - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -/* Typedefs of widgets */ - -/* Text Line widget - * (parent of Scrolling Text and Input Text widgets) - */ - -typedef struct -{ - /* left-justified position of scrolling text window */ - - int x; - int y; - - patch_t **f; /* font */ - int sc; /* start character */ - char l[HU_MAXLINELENGTH + 1]; /* line of text */ - int len; /* current line length */ - - /* whether this line needs to be updated */ - - int needsupdate; -} hu_textline_t; - -/* Scrolling Text window widget (child of Text Line widget) */ - -typedef struct -{ - hu_textline_t l[HU_MAXLINES]; /* text lines to draw */ - int h; /* height in lines */ - int cl; /* current line number */ - - /* pointer to boolean stating whether to update window */ - - boolean *on; - boolean laston; /* last value of *->on. */ -} hu_stext_t; - -/* Input Text Line widget (child of Text Line widget) */ - -typedef struct -{ - hu_textline_t l; /* text line to input on */ - - /* left margin past which I am not to delete characters */ - - int lm; - - /* pointer to boolean stating whether to update window */ - - boolean *on; - boolean laston; /* last value of *->on; */ -} hu_itext_t; - -/* Widget creation, access, and update routines */ - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/* textline code */ - -/* clear a line of text */ - -void hu_lib_clear_text(hu_textline_t *t); - -void hu_lib_init_text_line(hu_textline_t *t, int x, int y, patch_t **f, - int sc); - -/* returns success */ - -boolean hu_lib_add_char_to_text_line(hu_textline_t *t, char ch); - -/* returns success */ - -boolean hu_lib_del_char_from_text_line(hu_textline_t *t); - -/* draws tline */ - -void hu_lib_draw_text_line(hu_textline_t *l, boolean drawcursor); - -/* erases text line */ - -void hu_lib_erase_text_line(hu_textline_t *l); - -/* Scrolling Text window widget routines */ - -void hu_lib_init_stext(hu_stext_t *s, int x, int y, int h, patch_t **font, - int startchar, boolean *on); - -/* add a new line */ - -void hu_lib_add_line_to_stext(hu_stext_t *s); - -/* ? */ - -void hu_lib_add_messsage_to_stext(hu_stext_t *s, const char *prefix, - const char *msg); - -/* draws stext */ - -void hu_lib_draw_stext(hu_stext_t *s); - -/* erases all stext lines */ - -void hu_lib_erase_stext(hu_stext_t *s); - -/* Input Text Line widget routines */ - -void hu_lib_init_itext(hu_itext_t *it, int x, int y, patch_t **font, - int startchar, boolean *on); - -/* enforces left margin */ - -void hu_lib_del_char_from_itext(hu_itext_t *it); - -/* resets line and left margin */ - -void hu_lib_reset_itext(hu_itext_t *it); - -/* whether eaten */ - -boolean hu_lib_key_in_itext(hu_itext_t *it, unsigned char ch); - -void hu_lib_draw_itext(hu_itext_t *it); - -/* erases all itext lines */ - -void hu_lib_erase_itext(hu_itext_t *it); - -#endif /* __HULIB__ */ diff --git a/games/NXDoom/src/doom/hu_stuff.c b/games/NXDoom/src/doom/hu_stuff.c deleted file mode 100644 index 9dfd61abc..000000000 --- a/games/NXDoom/src/doom/hu_stuff.c +++ /dev/null @@ -1,641 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/hu_stuff.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: Heads-up displays - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -#include "doomdef.h" -#include "doomkeys.h" - -#include "z_zone.h" - -#include "deh_main.h" -#include "i_input.h" -#include "i_swap.h" -#include "i_video.h" - -#include "hu_lib.h" -#include "hu_stuff.h" -#include "m_controls.h" -#include "m_menu.h" -#include "m_misc.h" -#include "w_wad.h" - -#ifdef CONFIG_GAMES_NXDOOM_SOUND -#include "s_sound.h" -#include "sounds.h" -#endif - -#include "doomstat.h" - -/* Data. */ - -#include "dstrings.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* Locally used constants, shortcuts. */ - -#define HU_TITLE (mapnames[(gameepisode - 1) * 9 + gamemap - 1]) -#define HU_TITLE2 (mapnames_commercial[gamemap - 1]) -#define HU_TITLEP (mapnames_commercial[gamemap - 1 + 32]) -#define HU_TITLET (mapnames_commercial[gamemap - 1 + 64]) -#define HU_TITLE_CHEX (mapnames_chex[(gameepisode - 1) * 9 + gamemap - 1]) -#define HU_TITLEHEIGHT 1 -#define HU_TITLEX 0 -#define HU_TITLEY (167 - SHORT(hu_font[0]->height)) - -#define HU_INPUTTOGGLE 't' -#define HU_INPUTX HU_MSGX -#define HU_INPUTY (HU_MSGY + HU_MSGHEIGHT * (SHORT(hu_font[0]->height) + 1)) -#define HU_INPUTWIDTH 64 -#define HU_INPUTHEIGHT 1 - -#define QUEUESIZE 128 - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static player_t *plr; -static hu_textline_t w_title; -static hu_itext_t w_chat; -static boolean always_off = false; -static char chat_dest[MAXPLAYERS]; -static hu_itext_t w_inputbuffer[MAXPLAYERS]; - -static boolean message_on; -static boolean message_nottobefuckedwith; - -static hu_stext_t w_message; -static int message_counter; - -static boolean headsupactive = false; - -static char chatchars[QUEUESIZE]; -static int head = 0; -static int tail = 0; - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -char *chat_macros[10]; - -const char *player_names[] = -{ - HUSTR_PLRGREEN, - HUSTR_PLRINDIGO, - HUSTR_PLRBROWN, - HUSTR_PLRRED, -}; - -char chat_char; /* remove later. */ - -patch_t *hu_font[HU_FONTSIZE]; -boolean chat_on; -boolean message_dontfuckwithme; - -/* Builtin map names. - * The actual names can be found in DStrings.h. - */ - -/* DOOM shareware/registered/retail (Ultimate) names. */ - -const char *mapnames[] = -{ - HUSTR_E1M1, HUSTR_E1M2, HUSTR_E1M3, HUSTR_E1M4, HUSTR_E1M5, HUSTR_E1M6, - HUSTR_E1M7, HUSTR_E1M8, HUSTR_E1M9, HUSTR_E2M1, HUSTR_E2M2, HUSTR_E2M3, - HUSTR_E2M4, HUSTR_E2M5, HUSTR_E2M6, HUSTR_E2M7, HUSTR_E2M8, HUSTR_E2M9, - HUSTR_E3M1, HUSTR_E3M2, HUSTR_E3M3, HUSTR_E3M4, HUSTR_E3M5, HUSTR_E3M6, - HUSTR_E3M7, HUSTR_E3M8, HUSTR_E3M9, HUSTR_E4M1, HUSTR_E4M2, HUSTR_E4M3, - HUSTR_E4M4, HUSTR_E4M5, HUSTR_E4M6, HUSTR_E4M7, HUSTR_E4M8, HUSTR_E4M9, - "NEWLEVEL", "NEWLEVEL", "NEWLEVEL", "NEWLEVEL", "NEWLEVEL", "NEWLEVEL", - "NEWLEVEL", "NEWLEVEL", "NEWLEVEL", -}; - -/* Chex Quest names. */ - -const char *mapnames_chex[] = -{ - HUSTR_E1M1, HUSTR_E1M2, HUSTR_E1M3, HUSTR_E1M4, HUSTR_E1M5, - HUSTR_E1M5, HUSTR_E1M5, HUSTR_E1M5, HUSTR_E1M5, HUSTR_E1M5, - HUSTR_E1M5, HUSTR_E1M5, HUSTR_E1M5, HUSTR_E1M5, HUSTR_E1M5, - HUSTR_E1M5, HUSTR_E1M5, HUSTR_E1M5, HUSTR_E1M5, HUSTR_E1M5, - HUSTR_E1M5, HUSTR_E1M5, HUSTR_E1M5, HUSTR_E1M5, HUSTR_E1M5, - HUSTR_E1M5, HUSTR_E1M5, HUSTR_E1M5, HUSTR_E1M5, HUSTR_E1M5, - HUSTR_E1M5, HUSTR_E1M5, HUSTR_E1M5, HUSTR_E1M5, HUSTR_E1M5, - HUSTR_E1M5, "NEWLEVEL", "NEWLEVEL", "NEWLEVEL", "NEWLEVEL", - "NEWLEVEL", "NEWLEVEL", "NEWLEVEL", "NEWLEVEL", "NEWLEVEL", -}; - -/* List of names for levels in commercial IWADs - * (doom2.wad, plutonia.wad, tnt.wad). These are stored in a - * single large array; WADs like pl2.wad have a MAP33, and rely on - * the layout in the Vanilla executable, where it is possible to - * overflow the end of one array into the next. - */ - -const char *mapnames_commercial[] = -{ - HUSTR_1, /* DOOM 2 map names. */ - HUSTR_2, - HUSTR_3, - HUSTR_4, - HUSTR_5, - HUSTR_6, - HUSTR_7, - HUSTR_8, - HUSTR_9, - HUSTR_10, - HUSTR_11, - HUSTR_12, - HUSTR_13, - HUSTR_14, - HUSTR_15, - HUSTR_16, - HUSTR_17, - HUSTR_18, - HUSTR_19, - HUSTR_20, - HUSTR_21, - HUSTR_22, - HUSTR_23, - HUSTR_24, - HUSTR_25, - HUSTR_26, - HUSTR_27, - HUSTR_28, - HUSTR_29, - HUSTR_30, - HUSTR_31, - HUSTR_32, - PHUSTR_1, /* Plutonia WAD map names. */ - PHUSTR_2, - PHUSTR_3, - PHUSTR_4, - PHUSTR_5, - PHUSTR_6, - PHUSTR_7, - PHUSTR_8, - PHUSTR_9, - PHUSTR_10, - PHUSTR_11, - PHUSTR_12, - PHUSTR_13, - PHUSTR_14, - PHUSTR_15, - PHUSTR_16, - PHUSTR_17, - PHUSTR_18, - PHUSTR_19, - PHUSTR_20, - PHUSTR_21, - PHUSTR_22, - PHUSTR_23, - PHUSTR_24, - PHUSTR_25, - PHUSTR_26, - PHUSTR_27, - PHUSTR_28, - PHUSTR_29, - PHUSTR_30, - PHUSTR_31, - PHUSTR_32, - THUSTR_1, /* TNT WAD map names. */ - THUSTR_2, - THUSTR_3, - THUSTR_4, - THUSTR_5, - THUSTR_6, - THUSTR_7, - THUSTR_8, - THUSTR_9, - THUSTR_10, - THUSTR_11, - THUSTR_12, - THUSTR_13, - THUSTR_14, - THUSTR_15, - THUSTR_16, - THUSTR_17, - THUSTR_18, - THUSTR_19, - THUSTR_20, - THUSTR_21, - THUSTR_22, - THUSTR_23, - THUSTR_24, - THUSTR_25, - THUSTR_26, - THUSTR_27, - THUSTR_28, - THUSTR_29, - THUSTR_30, - THUSTR_31, - THUSTR_32, - - /* Emulation: TNT maps 33-35 can be warped to and played if they exist - * so include blank names instead of spilling over - */ - - "", - "", - "", -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static void hu_stop(void) -{ - headsupactive = false; -} - -static void hu_queue_chat_char(char c) -{ - if (((head + 1) & (QUEUESIZE - 1)) == tail) - { - plr->message = (HUSTR_MSGU); - } - else - { - chatchars[head] = c; - head = (head + 1) & (QUEUESIZE - 1); - } -} - -static void start_chat_input(int dest) -{ - chat_on = true; - hu_lib_reset_itext(&w_chat); - hu_queue_chat_char(HU_BROADCAST); - - i_start_text_input(0, 8, SCREENWIDTH, 16); -} - -static void stop_chat_input(void) -{ - chat_on = false; - i_stop_text_input(); -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -void hu_init(void) -{ - uint8_t i; - uint8_t j; - char buffer[9]; - - /* load the heads-up font */ - - j = HU_FONTSTART; - for (i = 0; i < HU_FONTSIZE; i++) - { - snprintf(buffer, 9, "STCFN%.3u", j++); - hu_font[i] = (patch_t *)w_cache_lump_name(buffer, PU_STATIC); - } -} - -void hu_start(void) -{ - int i; - const char *s; - - if (headsupactive) hu_stop(); - - plr = &players[consoleplayer]; - message_on = false; - message_dontfuckwithme = false; - message_nottobefuckedwith = false; - chat_on = false; - - /* create the message widget */ - - hu_lib_init_stext(&w_message, HU_MSGX, HU_MSGY, HU_MSGHEIGHT, hu_font, - HU_FONTSTART, &message_on); - - /* create the map title widget */ - - hu_lib_init_text_line(&w_title, HU_TITLEX, HU_TITLEY, hu_font, - HU_FONTSTART); - - switch (logical_gamemission) - { - case doom: - s = HU_TITLE; - break; - case doom2: - s = HU_TITLE2; - - /* Pre-Final Doom compatibility: map33-map35 names don't spill over */ - - if (gameversion <= exe_doom_1_9 && gamemap >= 33) - { - s = ""; - } - - break; - case pack_plut: - s = HU_TITLEP; - break; - case pack_tnt: - s = HU_TITLET; - break; - default: - s = "Unknown level"; - break; - } - - if (logical_gamemission == doom && gameversion == exe_chex) - { - s = HU_TITLE_CHEX; - } - - /* dehacked substitution to get modified level name */ - - s = (s); - while (*s) - { - hu_lib_add_char_to_text_line(&w_title, *(s++)); - } - - /* create the chat widget */ - - hu_lib_init_itext(&w_chat, HU_INPUTX, HU_INPUTY, hu_font, HU_FONTSTART, - &chat_on); - - /* create the inputbuffer widgets */ - - for (i = 0; i < MAXPLAYERS; i++) - { - hu_lib_init_itext(&w_inputbuffer[i], 0, 0, 0, 0, &always_off); - } - - headsupactive = true; -} - -void hu_drawer(void) -{ - hu_lib_draw_stext(&w_message); - hu_lib_draw_itext(&w_chat); - if (automapactive) hu_lib_draw_text_line(&w_title, false); -} - -void hu_erase(void) -{ - hu_lib_erase_stext(&w_message); - hu_lib_erase_itext(&w_chat); - hu_lib_erase_text_line(&w_title); -} - -void hu_ticker(void) -{ - int i; - int rc; - char c; - - /* tick down message counter if message is up */ - - if (message_counter && !--message_counter) - { - message_on = false; - message_nottobefuckedwith = false; - } - - if (g_show_messages || message_dontfuckwithme) - { - /* display message if necessary */ - - if ((plr->message && !message_nottobefuckedwith) || - (plr->message && message_dontfuckwithme)) - { - hu_lib_add_messsage_to_stext(&w_message, 0, plr->message); - plr->message = 0; - message_on = true; - message_counter = HU_MSGTIMEOUT; - message_nottobefuckedwith = message_dontfuckwithme; - message_dontfuckwithme = 0; - } - } - - /* check for incoming chat characters */ - - if (netgame) - { - for (i = 0; i < MAXPLAYERS; i++) - { - if (!playeringame[i]) continue; - if (i != consoleplayer && (c = players[i].cmd.chatchar)) - { - if (c <= HU_BROADCAST) - chat_dest[i] = c; - else - { - rc = hu_lib_key_in_itext(&w_inputbuffer[i], c); - if (rc && c == KEY_ENTER) - { - if (w_inputbuffer[i].l.len && - (chat_dest[i] == consoleplayer + 1 || - chat_dest[i] == HU_BROADCAST)) - { - hu_lib_add_messsage_to_stext(&w_message, - (player_names[i]), - w_inputbuffer[i].l.l); - - message_nottobefuckedwith = true; - message_on = true; - message_counter = HU_MSGTIMEOUT; -#ifdef CONFIG_GAMES_NXDOOM_SOUND - if (gamemode == commercial) - s_start_sound(0, SFX_RADIO); - else if (gameversion > exe_doom_1_2) - s_start_sound(0, SFX_TINK); -#endif - } - - hu_lib_reset_itext(&w_inputbuffer[i]); - } - } - - players[i].cmd.chatchar = 0; - } - } - } -} - -char hu_dequeue_chat_char(void) -{ - char c; - - if (head != tail) - { - c = chatchars[tail]; - tail = (tail + 1) & (QUEUESIZE - 1); - } - else - { - c = 0; - } - - return c; -} - -boolean hu_responder(event_t *ev) -{ - static char lastmessage[HU_MAXLINELENGTH + 1]; - const char *macromessage; - boolean eatkey = false; - static boolean altdown = false; - unsigned char c; - int i; - int numplayers; - - static int num_nobrainers = 0; - - numplayers = 0; - for (i = 0; i < MAXPLAYERS; i++) - numplayers += playeringame[i]; - - if (ev->data1 == KEY_RSHIFT) - { - return false; - } - else if (ev->data1 == KEY_RALT || ev->data1 == KEY_LALT) - { - altdown = ev->type == ev_keydown; - return false; - } - - if (ev->type != ev_keydown) return false; - - if (!chat_on) - { - if (ev->data1 == key_message_refresh) - { - message_on = true; - message_counter = HU_MSGTIMEOUT; - eatkey = true; - } - else if (netgame && ev->data2 == key_multi_msg) - { - eatkey = true; - start_chat_input(HU_BROADCAST); - } - else if (netgame && numplayers > 2) - { - for (i = 0; i < MAXPLAYERS; i++) - { - if (ev->data2 == key_multi_msgplayer[i]) - { - if (playeringame[i] && i != consoleplayer) - { - eatkey = true; - start_chat_input(i + 1); - break; - } - else if (i == consoleplayer) - { - num_nobrainers++; - if (num_nobrainers < 3) - plr->message = (HUSTR_TALKTOSELF1); - else if (num_nobrainers < 6) - plr->message = (HUSTR_TALKTOSELF2); - else if (num_nobrainers < 9) - plr->message = (HUSTR_TALKTOSELF3); - else if (num_nobrainers < 32) - plr->message = (HUSTR_TALKTOSELF4); - else - plr->message = (HUSTR_TALKTOSELF5); - } - } - } - } - } - else - { - /* send a macro */ - - if (altdown) - { - c = ev->data1 - '0'; - if (c > 9) return false; - macromessage = chat_macros[c]; - - /* kill last message with a '\n' */ - - hu_queue_chat_char(KEY_ENTER); /* DEBUG!!! */ - - /* send the macro message */ - - while (*macromessage) - { - hu_queue_chat_char(*macromessage++); - } - - hu_queue_chat_char(KEY_ENTER); - - /* leave chat mode and notify that it was sent */ - - stop_chat_input(); - m_str_copy(lastmessage, chat_macros[c], sizeof(lastmessage)); - plr->message = lastmessage; - eatkey = true; - } - else - { - c = ev->data3; - - eatkey = hu_lib_key_in_itext(&w_chat, c); - if (eatkey) - { - hu_queue_chat_char(c); - } - - if (c == KEY_ENTER) - { - stop_chat_input(); - if (w_chat.l.len) - { - m_str_copy(lastmessage, w_chat.l.l, sizeof(lastmessage)); - plr->message = lastmessage; - } - } - else if (c == KEY_ESCAPE) - { - stop_chat_input(); - } - } - } - - return eatkey; -} diff --git a/games/NXDoom/src/doom/hu_stuff.h b/games/NXDoom/src/doom/hu_stuff.h deleted file mode 100644 index 646a916c2..000000000 --- a/games/NXDoom/src/doom/hu_stuff.h +++ /dev/null @@ -1,84 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/hu_stuff.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: Head up display - * - ****************************************************************************/ - -#ifndef __HU_STUFF_H__ -#define __HU_STUFF_H__ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "d_event.h" -#include "v_patch.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* Globally visible constants. */ - -#define HU_FONTSTART '!' /* the first font characters */ -#define HU_FONTEND '_' /* the last font characters */ - -/* Calculate # of glyphs in font. */ - -#define HU_FONTSIZE (HU_FONTEND - HU_FONTSTART + 1) - -#define HU_BROADCAST 5 - -#define HU_MSGX 0 -#define HU_MSGY 0 -#define HU_MSGWIDTH 64 /* in characters */ -#define HU_MSGHEIGHT 1 /* in lines */ - -#define HU_MSGTIMEOUT (4 * TICRATE) - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -extern const char *player_names[4]; -extern char *chat_macros[10]; - -extern patch_t *hu_font[HU_FONTSIZE]; - -extern boolean message_dontfuckwithme; - -extern boolean chat_on; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/* HEADS UP TEXT */ - -void hu_init(void); -void hu_start(void); - -boolean hu_responder(event_t *ev); - -void hu_ticker(void); -void hu_drawer(void); -char hu_dequeue_chat_char(void); -void hu_erase(void); - -#endif /* __HU_STUFF_H__ */ diff --git a/games/NXDoom/src/doom/info.c b/games/NXDoom/src/doom/info.c deleted file mode 100644 index e1d6e8ac8..000000000 --- a/games/NXDoom/src/doom/info.c +++ /dev/null @@ -1,5356 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/info.c - * - * SPDX-License-Identifier: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Thing frame/state LUT, generated by multigen utility. - * This one is the original DOOM version, preserved. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -#include "m_fixed.h" -#include "sounds.h" - -#include "info.h" - -#include "p_mobj.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#if 0 - -/* Using misc1 & misc2 */ - -#define STATE_ENTRY(s, f, t, a, ns) \ - { \ - .sprite = (s), \ - .frame = (f), \ - .tics = (t), \ - .action = {(a)}, \ - .nextstate = (ns), \ - .misc1 = 0, \ - .misc2 = 0, \ - } -#else - -/* No misc1 & misc2 members */ - -#define STATE_ENTRY(s, f, t, a, ns) \ - { \ - .sprite = (s), \ - .frame = (f), \ - .tics = (t), \ - .action = {(void *)(a)}, \ - .nextstate = (ns), \ - } -#endif - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -const char *sprnames[] = -{ - "TROO", "SHTG", "PUNG", "PISG", "PISF", "SHTF", "SHT2", "CHGG", "CHGF", - "MISG", "MISF", "SAWG", "PLSG", "PLSF", "BFGG", "BFGF", "BLUD", "PUFF", - "BAL1", "BAL2", "PLSS", "PLSE", "MISL", "BFS1", "BFE1", "BFE2", "TFOG", - "IFOG", "PLAY", "POSS", "SPOS", "VILE", "FIRE", "FATB", "FBXP", "SKEL", - "MANF", "FATT", "CPOS", "SARG", "HEAD", "BAL7", "BOSS", "BOS2", "SKUL", - "SPID", "BSPI", "APLS", "APBX", "CYBR", "PAIN", "SSWV", "KEEN", "BBRN", - "BOSF", "ARM1", "ARM2", "BAR1", "BEXP", "FCAN", "BON1", "BON2", "BKEY", - "RKEY", "YKEY", "BSKU", "RSKU", "YSKU", "STIM", "MEDI", "SOUL", "PINV", - "PSTR", "PINS", "MEGA", "SUIT", "PMAP", "PVIS", "CLIP", "AMMO", "ROCK", - "BROK", "CELL", "CELP", "SHEL", "SBOX", "BPAK", "BFUG", "MGUN", "CSAW", - "LAUN", "PLAS", "SHOT", "SGN2", "COLU", "SMT2", "GOR1", "POL2", "POL5", - "POL4", "POL3", "POL1", "POL6", "GOR2", "GOR3", "GOR4", "GOR5", "SMIT", - "COL1", "COL2", "COL3", "COL4", "CAND", "CBRA", "COL6", "TRE1", "TRE2", - "ELEC", "CEYE", "FSKU", "COL5", "TBLU", "TGRN", "TRED", "SMBT", "SMGT", - "SMRT", "HDB1", "HDB2", "HDB3", "HDB4", "HDB5", "HDB6", "POB1", "POB2", - "BRS1", "TLMP", "TLP2", NULL, -}; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/* Doesn't work with g++, needs actionf_p1 */ - -void a_light0(void *, void *); -void a_weapon_ready(void *, void *); -void a_lower(void *, void *); -void a_raise(void *, void *); -void a_punch(void *, void *); -void a_refire(void *, void *); -void a_fire_pistol(void *, void *); -void a_light1(void *, void *); -void a_fire_shotgun(void *, void *); -void a_light2(void *, void *); -void a_fire_shotgun2(void *, void *); -void a_check_reload(void *, void *); -void a_open_shotgun2(void *, void *); -void a_load_shotgun2(void *, void *); -void a_close_shotgun2(void *, void *); -void a_fire_cgun(void *, void *); -void a_gun_flash(void *, void *); -void a_fire_missile(void *, void *); -void a_saw(void *, void *); -void a_fire_plasma(void *, void *); -void a_bfg_sound(void *, void *); -void a_fire_bfg(void *, void *); -void a_bfg_spray(void *); -void a_explode(void *); -void a_pain(void *); -void a_player_screm(void *); -void a_fall(void *); -void a_xscream(void *); -void a_look(void *); -void a_chase(void *); -void a_face_target(void *); -void a_pos_attack(void *); -void a_scream(void *); -void a_s_pos_attack(void *); -void a_vile_chase(void *); -void a_vile_start(void *); -void a_vile_target(void *); -void a_vile_attack(void *); -void a_start_fire(void *); -void a_fire(void *); -void a_fire_crackle(void *); -void a_tracer(void *); -void a_skel_woosh(void *); -void a_skel_fist(void *); -void a_skel_missile(void *); -void a_fat_raise(void *); -void a_fat_attack1(void *); -void a_fat_attack2(void *); -void a_fat_attack3(void *); -void a_boss_death(void *); -void a_c_pos_attack(void *); -void a_c_pos_refire(void *); -void a_troop_attack(void *); -void a_sarg_attack(void *); -void a_head_attack(void *); -void a_bruis_attack(void *); -void a_skull_attack(void *); -void a_metal(void *); -void a_spid_refire(void *); -void a_baby_metal(void *); -void a_bspi_attack(void *); -void a_hoof(void *); -void a_cyber_attack(void *); -void a_pain_attack(void *); -void a_pain_die(void *); -void a_keen_die(void *); -void a_brain_pain(void *); -void a_brain_scream(void *); -void a_brain_die(void *); -void a_brain_awake(void *); -void a_brain_split(void *); -void a_spawn_sound(void *); -void a_spawn_fly(void *); -void a_brain_explode(void *); - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -state_t states[NUMSTATES] = -{ - STATE_ENTRY(SPR_TROO, 0, -1, NULL, S_NULL), /* S_NULL */ - STATE_ENTRY(SPR_SHTG, 4, 0, a_light0, S_NULL), /* S_LIGHTDONE */ - STATE_ENTRY(SPR_PUNG, 0, 1, a_weapon_ready, S_PUNCH), /* S_PUNCH */ - STATE_ENTRY(SPR_PUNG, 0, 1, a_lower, S_PUNCHDOWN), /* S_PUNCHDOWN */ - STATE_ENTRY(SPR_PUNG, 0, 1, a_raise, S_PUNCHUP), /* S_PUNCHUP */ - STATE_ENTRY(SPR_PUNG, 1, 4, NULL, S_PUNCH2), /* S_PUNCH1 */ - STATE_ENTRY(SPR_PUNG, 2, 4, a_punch, S_PUNCH3), /* S_PUNCH2 */ - STATE_ENTRY(SPR_PUNG, 3, 5, NULL, S_PUNCH4), /* S_PUNCH3 */ - STATE_ENTRY(SPR_PUNG, 2, 4, NULL, S_PUNCH5), /* S_PUNCH4 */ - STATE_ENTRY(SPR_PUNG, 1, 5, a_refire, S_PUNCH), /* S_PUNCH5 */ - STATE_ENTRY(SPR_PISG, 0, 1, a_weapon_ready, S_PISTOL), /* S_PISTOL */ - STATE_ENTRY(SPR_PISG, 0, 1, a_lower, S_PISTOLDOWN), /* S_PISTOLDOWN */ - STATE_ENTRY(SPR_PISG, 0, 1, a_raise, S_PISTOLUP), /* S_PISTOLUP */ - STATE_ENTRY(SPR_PISG, 0, 4, NULL, S_PISTOL2), /* S_PISTOL1 */ - STATE_ENTRY(SPR_PISG, 1, 6, a_fire_pistol, S_PISTOL3), /* S_PISTOL2 */ - STATE_ENTRY(SPR_PISG, 2, 4, NULL, S_PISTOL4), /* S_PISTOL3 */ - STATE_ENTRY(SPR_PISG, 1, 5, a_refire, S_PISTOL), /* S_PISTOL4 */ - STATE_ENTRY(SPR_PISF, 32768, 7, a_light1, - S_LIGHTDONE), /* S_PISTOLFLASH */ - STATE_ENTRY(SPR_SHTG, 0, 1, a_weapon_ready, S_SGUN), /* S_SGUN */ - STATE_ENTRY(SPR_SHTG, 0, 1, a_lower, S_SGUNDOWN), /* S_SGUNDOWN */ - STATE_ENTRY(SPR_SHTG, 0, 1, a_raise, S_SGUNUP), /* S_SGUNUP */ - STATE_ENTRY(SPR_SHTG, 0, 3, NULL, S_SGUN2), /* S_SGUN1 */ - STATE_ENTRY(SPR_SHTG, 0, 7, a_fire_shotgun, S_SGUN3), /* S_SGUN2 */ - STATE_ENTRY(SPR_SHTG, 1, 5, NULL, S_SGUN4), /* S_SGUN3 */ - STATE_ENTRY(SPR_SHTG, 2, 5, NULL, S_SGUN5), /* S_SGUN4 */ - STATE_ENTRY(SPR_SHTG, 3, 4, NULL, S_SGUN6), /* S_SGUN5 */ - STATE_ENTRY(SPR_SHTG, 2, 5, NULL, S_SGUN7), /* S_SGUN6 */ - STATE_ENTRY(SPR_SHTG, 1, 5, NULL, S_SGUN8), /* S_SGUN7 */ - STATE_ENTRY(SPR_SHTG, 0, 3, NULL, S_SGUN9), /* S_SGUN8 */ - STATE_ENTRY(SPR_SHTG, 0, 7, a_refire, S_SGUN), /* S_SGUN9 */ - STATE_ENTRY(SPR_SHTF, 32768, 4, a_light1, - S_SGUNFLASH2), /* S_SGUNFLASH1 */ - STATE_ENTRY(SPR_SHTF, 32769, 3, a_light2, S_LIGHTDONE), /* S_SGUNFLASH2 */ - STATE_ENTRY(SPR_SHT2, 0, 1, a_weapon_ready, S_DSGUN), /* S_DSGUN */ - STATE_ENTRY(SPR_SHT2, 0, 1, a_lower, S_DSGUNDOWN), /* S_DSGUNDOWN */ - STATE_ENTRY(SPR_SHT2, 0, 1, a_raise, S_DSGUNUP), /* S_DSGUNUP */ - STATE_ENTRY(SPR_SHT2, 0, 3, NULL, S_DSGUN2), /* S_DSGUN1 */ - STATE_ENTRY(SPR_SHT2, 0, 7, a_fire_shotgun2, S_DSGUN3), /* S_DSGUN2 */ - STATE_ENTRY(SPR_SHT2, 1, 7, NULL, S_DSGUN4), /* S_DSGUN3 */ - STATE_ENTRY(SPR_SHT2, 2, 7, a_check_reload, S_DSGUN5), /* S_DSGUN4 */ - STATE_ENTRY(SPR_SHT2, 3, 7, a_open_shotgun2, S_DSGUN6), /* S_DSGUN5 */ - STATE_ENTRY(SPR_SHT2, 4, 7, NULL, S_DSGUN7), /* S_DSGUN6 */ - STATE_ENTRY(SPR_SHT2, 5, 7, a_load_shotgun2, S_DSGUN8), /* S_DSGUN7 */ - STATE_ENTRY(SPR_SHT2, 6, 6, NULL, S_DSGUN9), /* S_DSGUN8 */ - STATE_ENTRY(SPR_SHT2, 7, 6, a_close_shotgun2, S_DSGUN10), /* S_DSGUN9 */ - STATE_ENTRY(SPR_SHT2, 0, 5, a_refire, S_DSGUN), /* S_DSGUN10 */ - STATE_ENTRY(SPR_SHT2, 1, 7, NULL, S_DSNR2), /* S_DSNR1 */ - STATE_ENTRY(SPR_SHT2, 0, 3, NULL, S_DSGUNDOWN), /* S_DSNR2 */ - STATE_ENTRY(SPR_SHT2, 32776, 5, a_light1, - S_DSGUNFLASH2), /* S_DSGUNFLASH1 */ - STATE_ENTRY(SPR_SHT2, 32777, 4, a_light2, - S_LIGHTDONE), /* S_DSGUNFLASH2 */ - STATE_ENTRY(SPR_CHGG, 0, 1, a_weapon_ready, S_CHAIN), /* S_CHAIN */ - STATE_ENTRY(SPR_CHGG, 0, 1, a_lower, S_CHAINDOWN), /* S_CHAINDOWN */ - STATE_ENTRY(SPR_CHGG, 0, 1, a_raise, S_CHAINUP), /* S_CHAINUP */ - STATE_ENTRY(SPR_CHGG, 0, 4, a_fire_cgun, S_CHAIN2), /* S_CHAIN1 */ - STATE_ENTRY(SPR_CHGG, 1, 4, a_fire_cgun, S_CHAIN3), /* S_CHAIN2 */ - STATE_ENTRY(SPR_CHGG, 1, 0, a_refire, S_CHAIN), /* S_CHAIN3 */ - STATE_ENTRY(SPR_CHGF, 32768, 5, a_light1, - S_LIGHTDONE), /* S_CHAINFLASH1 */ - STATE_ENTRY(SPR_CHGF, 32769, 5, a_light2, - S_LIGHTDONE), /* S_CHAINFLASH2 */ - STATE_ENTRY(SPR_MISG, 0, 1, a_weapon_ready, S_MISSILE), /* S_MISSILE */ - STATE_ENTRY(SPR_MISG, 0, 1, a_lower, S_MISSILEDOWN), /* S_MISSILEDOWN */ - STATE_ENTRY(SPR_MISG, 0, 1, a_raise, S_MISSILEUP), /* S_MISSILEUP */ - STATE_ENTRY(SPR_MISG, 1, 8, a_gun_flash, S_MISSILE2), /* S_MISSILE1 */ - STATE_ENTRY(SPR_MISG, 1, 12, a_fire_missile, S_MISSILE3), /* S_MISSILE2 */ - STATE_ENTRY(SPR_MISG, 1, 0, a_refire, S_MISSILE), /* S_MISSILE3 */ - STATE_ENTRY(SPR_MISF, 32768, 3, a_light1, - S_MISSILEFLASH2), /* S_MISSILEFLASH1 */ - STATE_ENTRY(SPR_MISF, 32769, 4, NULL, - S_MISSILEFLASH3), /* S_MISSILEFLASH2 */ - STATE_ENTRY(SPR_MISF, 32770, 4, a_light2, - S_MISSILEFLASH4), /* S_MISSILEFLASH3 */ - STATE_ENTRY(SPR_MISF, 32771, 4, a_light2, - S_LIGHTDONE), /* S_MISSILEFLASH4 */ - STATE_ENTRY(SPR_SAWG, 2, 4, a_weapon_ready, S_SAWB), /* S_SAW */ - STATE_ENTRY(SPR_SAWG, 3, 4, a_weapon_ready, S_SAW), /* S_SAWB */ - STATE_ENTRY(SPR_SAWG, 2, 1, a_lower, S_SAWDOWN), /* S_SAWDOWN */ - STATE_ENTRY(SPR_SAWG, 2, 1, a_raise, S_SAWUP), /* S_SAWUP */ - STATE_ENTRY(SPR_SAWG, 0, 4, a_saw, S_SAW2), /* S_SAW1 */ - STATE_ENTRY(SPR_SAWG, 1, 4, a_saw, S_SAW3), /* S_SAW2 */ - STATE_ENTRY(SPR_SAWG, 1, 0, a_refire, S_SAW), /* S_SAW3 */ - STATE_ENTRY(SPR_PLSG, 0, 1, a_weapon_ready, S_PLASMA), /* S_PLASMA */ - STATE_ENTRY(SPR_PLSG, 0, 1, a_lower, S_PLASMADOWN), /* S_PLASMADOWN */ - STATE_ENTRY(SPR_PLSG, 0, 1, a_raise, S_PLASMAUP), /* S_PLASMAUP */ - STATE_ENTRY(SPR_PLSG, 0, 3, a_fire_plasma, S_PLASMA2), /* S_PLASMA1 */ - STATE_ENTRY(SPR_PLSG, 1, 20, a_refire, S_PLASMA), /* S_PLASMA2 */ - STATE_ENTRY(SPR_PLSF, 32768, 4, a_light1, - S_LIGHTDONE), /* S_PLASMAFLASH1 */ - STATE_ENTRY(SPR_PLSF, 32769, 4, a_light1, - S_LIGHTDONE), /* S_PLASMAFLASH2 */ - STATE_ENTRY(SPR_BFGG, 0, 1, a_weapon_ready, S_BFG), /* S_BFG */ - STATE_ENTRY(SPR_BFGG, 0, 1, a_lower, S_BFGDOWN), /* S_BFGDOWN */ - STATE_ENTRY(SPR_BFGG, 0, 1, a_raise, S_BFGUP), /* S_BFGUP */ - STATE_ENTRY(SPR_BFGG, 0, 20, a_bfg_sound, S_BFG2), /* S_BFG1 */ - STATE_ENTRY(SPR_BFGG, 1, 10, a_gun_flash, S_BFG3), /* S_BFG2 */ - STATE_ENTRY(SPR_BFGG, 1, 10, a_fire_bfg, S_BFG4), /* S_BFG3 */ - STATE_ENTRY(SPR_BFGG, 1, 20, a_refire, S_BFG), /* S_BFG4 */ - STATE_ENTRY(SPR_BFGF, 32768, 11, a_light1, S_BFGFLASH2), /* S_BFGFLASH1 */ - STATE_ENTRY(SPR_BFGF, 32769, 6, a_light2, S_LIGHTDONE), /* S_BFGFLASH2 */ - STATE_ENTRY(SPR_BLUD, 2, 8, NULL, S_BLOOD2), /* S_BLOOD1 */ - STATE_ENTRY(SPR_BLUD, 1, 8, NULL, S_BLOOD3), /* S_BLOOD2 */ - STATE_ENTRY(SPR_BLUD, 0, 8, NULL, S_NULL), /* S_BLOOD3 */ - STATE_ENTRY(SPR_PUFF, 32768, 4, NULL, S_PUFF2), /* S_PUFF1 */ - STATE_ENTRY(SPR_PUFF, 1, 4, NULL, S_PUFF3), /* S_PUFF2 */ - STATE_ENTRY(SPR_PUFF, 2, 4, NULL, S_PUFF4), /* S_PUFF3 */ - STATE_ENTRY(SPR_PUFF, 3, 4, NULL, S_NULL), /* S_PUFF4 */ - STATE_ENTRY(SPR_BAL1, 32768, 4, NULL, S_TBALL2), /* S_TBALL1 */ - STATE_ENTRY(SPR_BAL1, 32769, 4, NULL, S_TBALL1), /* S_TBALL2 */ - STATE_ENTRY(SPR_BAL1, 32770, 6, NULL, S_TBALLX2), /* S_TBALLX1 */ - STATE_ENTRY(SPR_BAL1, 32771, 6, NULL, S_TBALLX3), /* S_TBALLX2 */ - STATE_ENTRY(SPR_BAL1, 32772, 6, NULL, S_NULL), /* S_TBALLX3 */ - STATE_ENTRY(SPR_BAL2, 32768, 4, NULL, S_RBALL2), /* S_RBALL1 */ - STATE_ENTRY(SPR_BAL2, 32769, 4, NULL, S_RBALL1), /* S_RBALL2 */ - STATE_ENTRY(SPR_BAL2, 32770, 6, NULL, S_RBALLX2), /* S_RBALLX1 */ - STATE_ENTRY(SPR_BAL2, 32771, 6, NULL, S_RBALLX3), /* S_RBALLX2 */ - STATE_ENTRY(SPR_BAL2, 32772, 6, NULL, S_NULL), /* S_RBALLX3 */ - STATE_ENTRY(SPR_PLSS, 32768, 6, NULL, S_PLASBALL2), /* S_PLASBALL */ - STATE_ENTRY(SPR_PLSS, 32769, 6, NULL, S_PLASBALL), /* S_PLASBALL2 */ - STATE_ENTRY(SPR_PLSE, 32768, 4, NULL, S_PLASEXP2), /* S_PLASEXP */ - STATE_ENTRY(SPR_PLSE, 32769, 4, NULL, S_PLASEXP3), /* S_PLASEXP2 */ - STATE_ENTRY(SPR_PLSE, 32770, 4, NULL, S_PLASEXP4), /* S_PLASEXP3 */ - STATE_ENTRY(SPR_PLSE, 32771, 4, NULL, S_PLASEXP5), /* S_PLASEXP4 */ - STATE_ENTRY(SPR_PLSE, 32772, 4, NULL, S_NULL), /* S_PLASEXP5 */ - STATE_ENTRY(SPR_MISL, 32768, 1, NULL, S_ROCKET), /* S_ROCKET */ - STATE_ENTRY(SPR_BFS1, 32768, 4, NULL, S_BFGSHOT2), /* S_BFGSHOT */ - STATE_ENTRY(SPR_BFS1, 32769, 4, NULL, S_BFGSHOT), /* S_BFGSHOT2 */ - STATE_ENTRY(SPR_BFE1, 32768, 8, NULL, S_BFGLAND2), /* S_BFGLAND */ - STATE_ENTRY(SPR_BFE1, 32769, 8, NULL, S_BFGLAND3), /* S_BFGLAND2 */ - STATE_ENTRY(SPR_BFE1, 32770, 8, a_bfg_spray, S_BFGLAND4), /* S_BFGLAND3 */ - STATE_ENTRY(SPR_BFE1, 32771, 8, NULL, S_BFGLAND5), /* S_BFGLAND4 */ - STATE_ENTRY(SPR_BFE1, 32772, 8, NULL, S_BFGLAND6), /* S_BFGLAND5 */ - STATE_ENTRY(SPR_BFE1, 32773, 8, NULL, S_NULL), /* S_BFGLAND6 */ - STATE_ENTRY(SPR_BFE2, 32768, 8, NULL, S_BFGEXP2), /* S_BFGEXP */ - STATE_ENTRY(SPR_BFE2, 32769, 8, NULL, S_BFGEXP3), /* S_BFGEXP2 */ - STATE_ENTRY(SPR_BFE2, 32770, 8, NULL, S_BFGEXP4), /* S_BFGEXP3 */ - STATE_ENTRY(SPR_BFE2, 32771, 8, NULL, S_NULL), /* S_BFGEXP4 */ - STATE_ENTRY(SPR_MISL, 32769, 8, a_explode, S_EXPLODE2), /* S_EXPLODE1 */ - STATE_ENTRY(SPR_MISL, 32770, 6, NULL, S_EXPLODE3), /* S_EXPLODE2 */ - STATE_ENTRY(SPR_MISL, 32771, 4, NULL, S_NULL), /* S_EXPLODE3 */ - STATE_ENTRY(SPR_TFOG, 32768, 6, NULL, S_TFOG01), /* S_TFOG */ - STATE_ENTRY(SPR_TFOG, 32769, 6, NULL, S_TFOG02), /* S_TFOG01 */ - STATE_ENTRY(SPR_TFOG, 32768, 6, NULL, S_TFOG2), /* S_TFOG02 */ - STATE_ENTRY(SPR_TFOG, 32769, 6, NULL, S_TFOG3), /* S_TFOG2 */ - STATE_ENTRY(SPR_TFOG, 32770, 6, NULL, S_TFOG4), /* S_TFOG3 */ - STATE_ENTRY(SPR_TFOG, 32771, 6, NULL, S_TFOG5), /* S_TFOG4 */ - STATE_ENTRY(SPR_TFOG, 32772, 6, NULL, S_TFOG6), /* S_TFOG5 */ - STATE_ENTRY(SPR_TFOG, 32773, 6, NULL, S_TFOG7), /* S_TFOG6 */ - STATE_ENTRY(SPR_TFOG, 32774, 6, NULL, S_TFOG8), /* S_TFOG7 */ - STATE_ENTRY(SPR_TFOG, 32775, 6, NULL, S_TFOG9), /* S_TFOG8 */ - STATE_ENTRY(SPR_TFOG, 32776, 6, NULL, S_TFOG10), /* S_TFOG9 */ - STATE_ENTRY(SPR_TFOG, 32777, 6, NULL, S_NULL), /* S_TFOG10 */ - STATE_ENTRY(SPR_IFOG, 32768, 6, NULL, S_IFOG01), /* S_IFOG */ - STATE_ENTRY(SPR_IFOG, 32769, 6, NULL, S_IFOG02), /* S_IFOG01 */ - STATE_ENTRY(SPR_IFOG, 32768, 6, NULL, S_IFOG2), /* S_IFOG02 */ - STATE_ENTRY(SPR_IFOG, 32769, 6, NULL, S_IFOG3), /* S_IFOG2 */ - STATE_ENTRY(SPR_IFOG, 32770, 6, NULL, S_IFOG4), /* S_IFOG3 */ - STATE_ENTRY(SPR_IFOG, 32771, 6, NULL, S_IFOG5), /* S_IFOG4 */ - STATE_ENTRY(SPR_IFOG, 32772, 6, NULL, S_NULL), /* S_IFOG5 */ - STATE_ENTRY(SPR_PLAY, 0, -1, NULL, S_NULL), /* S_PLAY */ - STATE_ENTRY(SPR_PLAY, 0, 4, NULL, S_PLAY_RUN2), /* S_PLAY_RUN1 */ - STATE_ENTRY(SPR_PLAY, 1, 4, NULL, S_PLAY_RUN3), /* S_PLAY_RUN2 */ - STATE_ENTRY(SPR_PLAY, 2, 4, NULL, S_PLAY_RUN4), /* S_PLAY_RUN3 */ - STATE_ENTRY(SPR_PLAY, 3, 4, NULL, S_PLAY_RUN1), /* S_PLAY_RUN4 */ - STATE_ENTRY(SPR_PLAY, 4, 12, NULL, S_PLAY), /* S_PLAY_ATK1 */ - STATE_ENTRY(SPR_PLAY, 32773, 6, NULL, S_PLAY_ATK1), /* S_PLAY_ATK2 */ - STATE_ENTRY(SPR_PLAY, 6, 4, NULL, S_PLAY_PAIN2), /* S_PLAY_PAIN */ - STATE_ENTRY(SPR_PLAY, 6, 4, a_pain, S_PLAY), /* S_PLAY_PAIN2 */ - STATE_ENTRY(SPR_PLAY, 7, 10, NULL, S_PLAY_DIE2), /* S_PLAY_DIE1 */ - STATE_ENTRY(SPR_PLAY, 8, 10, a_player_screm, - S_PLAY_DIE3), /* S_PLAY_DIE2 */ - STATE_ENTRY(SPR_PLAY, 9, 10, a_fall, S_PLAY_DIE4), /* S_PLAY_DIE3 */ - STATE_ENTRY(SPR_PLAY, 10, 10, NULL, S_PLAY_DIE5), /* S_PLAY_DIE4 */ - STATE_ENTRY(SPR_PLAY, 11, 10, NULL, S_PLAY_DIE6), /* S_PLAY_DIE5 */ - STATE_ENTRY(SPR_PLAY, 12, 10, NULL, S_PLAY_DIE7), /* S_PLAY_DIE6 */ - STATE_ENTRY(SPR_PLAY, 13, -1, NULL, S_NULL), /* S_PLAY_DIE7 */ - STATE_ENTRY(SPR_PLAY, 14, 5, NULL, S_PLAY_XDIE2), /* S_PLAY_XDIE1 */ - STATE_ENTRY(SPR_PLAY, 15, 5, a_xscream, S_PLAY_XDIE3), /* S_PLAY_XDIE2 */ - STATE_ENTRY(SPR_PLAY, 16, 5, a_fall, S_PLAY_XDIE4), /* S_PLAY_XDIE3 */ - STATE_ENTRY(SPR_PLAY, 17, 5, NULL, S_PLAY_XDIE5), /* S_PLAY_XDIE4 */ - STATE_ENTRY(SPR_PLAY, 18, 5, NULL, S_PLAY_XDIE6), /* S_PLAY_XDIE5 */ - STATE_ENTRY(SPR_PLAY, 19, 5, NULL, S_PLAY_XDIE7), /* S_PLAY_XDIE6 */ - STATE_ENTRY(SPR_PLAY, 20, 5, NULL, S_PLAY_XDIE8), /* S_PLAY_XDIE7 */ - STATE_ENTRY(SPR_PLAY, 21, 5, NULL, S_PLAY_XDIE9), /* S_PLAY_XDIE8 */ - STATE_ENTRY(SPR_PLAY, 22, -1, NULL, S_NULL), /* S_PLAY_XDIE9 */ - STATE_ENTRY(SPR_POSS, 0, 10, a_look, S_POSS_STND2), /* S_POSS_STND */ - STATE_ENTRY(SPR_POSS, 1, 10, a_look, S_POSS_STND), /* S_POSS_STND2 */ - STATE_ENTRY(SPR_POSS, 0, 4, a_chase, S_POSS_RUN2), /* S_POSS_RUN1 */ - STATE_ENTRY(SPR_POSS, 0, 4, a_chase, S_POSS_RUN3), /* S_POSS_RUN2 */ - STATE_ENTRY(SPR_POSS, 1, 4, a_chase, S_POSS_RUN4), /* S_POSS_RUN3 */ - STATE_ENTRY(SPR_POSS, 1, 4, a_chase, S_POSS_RUN5), /* S_POSS_RUN4 */ - STATE_ENTRY(SPR_POSS, 2, 4, a_chase, S_POSS_RUN6), /* S_POSS_RUN5 */ - STATE_ENTRY(SPR_POSS, 2, 4, a_chase, S_POSS_RUN7), /* S_POSS_RUN6 */ - STATE_ENTRY(SPR_POSS, 3, 4, a_chase, S_POSS_RUN8), /* S_POSS_RUN7 */ - STATE_ENTRY(SPR_POSS, 3, 4, a_chase, S_POSS_RUN1), /* S_POSS_RUN8 */ - STATE_ENTRY(SPR_POSS, 4, 10, a_face_target, - S_POSS_ATK2), /* S_POSS_ATK1 */ - STATE_ENTRY(SPR_POSS, 5, 8, a_pos_attack, S_POSS_ATK3), /* S_POSS_ATK2 */ - STATE_ENTRY(SPR_POSS, 4, 8, NULL, S_POSS_RUN1), /* S_POSS_ATK3 */ - STATE_ENTRY(SPR_POSS, 6, 3, NULL, S_POSS_PAIN2), /* S_POSS_PAIN */ - STATE_ENTRY(SPR_POSS, 6, 3, a_pain, S_POSS_RUN1), /* S_POSS_PAIN2 */ - STATE_ENTRY(SPR_POSS, 7, 5, NULL, S_POSS_DIE2), /* S_POSS_DIE1 */ - STATE_ENTRY(SPR_POSS, 8, 5, a_scream, S_POSS_DIE3), /* S_POSS_DIE2 */ - STATE_ENTRY(SPR_POSS, 9, 5, a_fall, S_POSS_DIE4), /* S_POSS_DIE3 */ - STATE_ENTRY(SPR_POSS, 10, 5, NULL, S_POSS_DIE5), /* S_POSS_DIE4 */ - STATE_ENTRY(SPR_POSS, 11, -1, NULL, S_NULL), /* S_POSS_DIE5 */ - STATE_ENTRY(SPR_POSS, 12, 5, NULL, S_POSS_XDIE2), /* S_POSS_XDIE1 */ - STATE_ENTRY(SPR_POSS, 13, 5, a_xscream, S_POSS_XDIE3), /* S_POSS_XDIE2 */ - STATE_ENTRY(SPR_POSS, 14, 5, a_fall, S_POSS_XDIE4), /* S_POSS_XDIE3 */ - STATE_ENTRY(SPR_POSS, 15, 5, NULL, S_POSS_XDIE5), /* S_POSS_XDIE4 */ - STATE_ENTRY(SPR_POSS, 16, 5, NULL, S_POSS_XDIE6), /* S_POSS_XDIE5 */ - STATE_ENTRY(SPR_POSS, 17, 5, NULL, S_POSS_XDIE7), /* S_POSS_XDIE6 */ - STATE_ENTRY(SPR_POSS, 18, 5, NULL, S_POSS_XDIE8), /* S_POSS_XDIE7 */ - STATE_ENTRY(SPR_POSS, 19, 5, NULL, S_POSS_XDIE9), /* S_POSS_XDIE8 */ - STATE_ENTRY(SPR_POSS, 20, -1, NULL, S_NULL), /* S_POSS_XDIE9 */ - STATE_ENTRY(SPR_POSS, 10, 5, NULL, S_POSS_RAISE2), /* S_POSS_RAISE1 */ - STATE_ENTRY(SPR_POSS, 9, 5, NULL, S_POSS_RAISE3), /* S_POSS_RAISE2 */ - STATE_ENTRY(SPR_POSS, 8, 5, NULL, S_POSS_RAISE4), /* S_POSS_RAISE3 */ - STATE_ENTRY(SPR_POSS, 7, 5, NULL, S_POSS_RUN1), /* S_POSS_RAISE4 */ - STATE_ENTRY(SPR_SPOS, 0, 10, a_look, S_SPOS_STND2), /* S_SPOS_STND */ - STATE_ENTRY(SPR_SPOS, 1, 10, a_look, S_SPOS_STND), /* S_SPOS_STND2 */ - STATE_ENTRY(SPR_SPOS, 0, 3, a_chase, S_SPOS_RUN2), /* S_SPOS_RUN1 */ - STATE_ENTRY(SPR_SPOS, 0, 3, a_chase, S_SPOS_RUN3), /* S_SPOS_RUN2 */ - STATE_ENTRY(SPR_SPOS, 1, 3, a_chase, S_SPOS_RUN4), /* S_SPOS_RUN3 */ - STATE_ENTRY(SPR_SPOS, 1, 3, a_chase, S_SPOS_RUN5), /* S_SPOS_RUN4 */ - STATE_ENTRY(SPR_SPOS, 2, 3, a_chase, S_SPOS_RUN6), /* S_SPOS_RUN5 */ - STATE_ENTRY(SPR_SPOS, 2, 3, a_chase, S_SPOS_RUN7), /* S_SPOS_RUN6 */ - STATE_ENTRY(SPR_SPOS, 3, 3, a_chase, S_SPOS_RUN8), /* S_SPOS_RUN7 */ - STATE_ENTRY(SPR_SPOS, 3, 3, a_chase, S_SPOS_RUN1), /* S_SPOS_RUN8 */ - STATE_ENTRY(SPR_SPOS, 4, 10, a_face_target, - S_SPOS_ATK2), /* S_SPOS_ATK1 */ - STATE_ENTRY(SPR_SPOS, 32773, 10, a_s_pos_attack, - S_SPOS_ATK3), /* S_SPOS_ATK2 */ - STATE_ENTRY(SPR_SPOS, 4, 10, NULL, S_SPOS_RUN1), /* S_SPOS_ATK3 */ - STATE_ENTRY(SPR_SPOS, 6, 3, NULL, S_SPOS_PAIN2), /* S_SPOS_PAIN */ - STATE_ENTRY(SPR_SPOS, 6, 3, a_pain, S_SPOS_RUN1), /* S_SPOS_PAIN2 */ - STATE_ENTRY(SPR_SPOS, 7, 5, NULL, S_SPOS_DIE2), /* S_SPOS_DIE1 */ - STATE_ENTRY(SPR_SPOS, 8, 5, a_scream, S_SPOS_DIE3), /* S_SPOS_DIE2 */ - STATE_ENTRY(SPR_SPOS, 9, 5, a_fall, S_SPOS_DIE4), /* S_SPOS_DIE3 */ - STATE_ENTRY(SPR_SPOS, 10, 5, NULL, S_SPOS_DIE5), /* S_SPOS_DIE4 */ - STATE_ENTRY(SPR_SPOS, 11, -1, NULL, S_NULL), /* S_SPOS_DIE5 */ - STATE_ENTRY(SPR_SPOS, 12, 5, NULL, S_SPOS_XDIE2), /* S_SPOS_XDIE1 */ - STATE_ENTRY(SPR_SPOS, 13, 5, a_xscream, S_SPOS_XDIE3), /* S_SPOS_XDIE2 */ - STATE_ENTRY(SPR_SPOS, 14, 5, a_fall, S_SPOS_XDIE4), /* S_SPOS_XDIE3 */ - STATE_ENTRY(SPR_SPOS, 15, 5, NULL, S_SPOS_XDIE5), /* S_SPOS_XDIE4 */ - STATE_ENTRY(SPR_SPOS, 16, 5, NULL, S_SPOS_XDIE6), /* S_SPOS_XDIE5 */ - STATE_ENTRY(SPR_SPOS, 17, 5, NULL, S_SPOS_XDIE7), /* S_SPOS_XDIE6 */ - STATE_ENTRY(SPR_SPOS, 18, 5, NULL, S_SPOS_XDIE8), /* S_SPOS_XDIE7 */ - STATE_ENTRY(SPR_SPOS, 19, 5, NULL, S_SPOS_XDIE9), /* S_SPOS_XDIE8 */ - STATE_ENTRY(SPR_SPOS, 20, -1, NULL, S_NULL), /* S_SPOS_XDIE9 */ - STATE_ENTRY(SPR_SPOS, 11, 5, NULL, S_SPOS_RAISE2), /* S_SPOS_RAISE1 */ - STATE_ENTRY(SPR_SPOS, 10, 5, NULL, S_SPOS_RAISE3), /* S_SPOS_RAISE2 */ - STATE_ENTRY(SPR_SPOS, 9, 5, NULL, S_SPOS_RAISE4), /* S_SPOS_RAISE3 */ - STATE_ENTRY(SPR_SPOS, 8, 5, NULL, S_SPOS_RAISE5), /* S_SPOS_RAISE4 */ - STATE_ENTRY(SPR_SPOS, 7, 5, NULL, S_SPOS_RUN1), /* S_SPOS_RAISE5 */ - STATE_ENTRY(SPR_VILE, 0, 10, a_look, S_VILE_STND2), /* S_VILE_STND */ - STATE_ENTRY(SPR_VILE, 1, 10, a_look, S_VILE_STND), /* S_VILE_STND2 */ - STATE_ENTRY(SPR_VILE, 0, 2, a_vile_chase, S_VILE_RUN2), /* S_VILE_RUN1 */ - STATE_ENTRY(SPR_VILE, 0, 2, a_vile_chase, S_VILE_RUN3), /* S_VILE_RUN2 */ - STATE_ENTRY(SPR_VILE, 1, 2, a_vile_chase, S_VILE_RUN4), /* S_VILE_RUN3 */ - STATE_ENTRY(SPR_VILE, 1, 2, a_vile_chase, S_VILE_RUN5), /* S_VILE_RUN4 */ - STATE_ENTRY(SPR_VILE, 2, 2, a_vile_chase, S_VILE_RUN6), /* S_VILE_RUN5 */ - STATE_ENTRY(SPR_VILE, 2, 2, a_vile_chase, S_VILE_RUN7), /* S_VILE_RUN6 */ - STATE_ENTRY(SPR_VILE, 3, 2, a_vile_chase, S_VILE_RUN8), /* S_VILE_RUN7 */ - STATE_ENTRY(SPR_VILE, 3, 2, a_vile_chase, S_VILE_RUN9), /* S_VILE_RUN8 */ - STATE_ENTRY(SPR_VILE, 4, 2, a_vile_chase, S_VILE_RUN10), /* S_VILE_RUN9 */ - STATE_ENTRY(SPR_VILE, 4, 2, a_vile_chase, - S_VILE_RUN11), /* S_VILE_RUN10 */ - STATE_ENTRY(SPR_VILE, 5, 2, a_vile_chase, - S_VILE_RUN12), /* S_VILE_RUN11 */ - STATE_ENTRY(SPR_VILE, 5, 2, a_vile_chase, S_VILE_RUN1), /* S_VILE_RUN12 */ - STATE_ENTRY(SPR_VILE, 32774, 0, a_vile_start, - S_VILE_ATK2), /* S_VILE_ATK1 */ - STATE_ENTRY(SPR_VILE, 32774, 10, a_face_target, - S_VILE_ATK3), /* S_VILE_ATK2 */ - STATE_ENTRY(SPR_VILE, 32775, 8, a_vile_target, - S_VILE_ATK4), /* S_VILE_ATK3 */ - STATE_ENTRY(SPR_VILE, 32776, 8, a_face_target, - S_VILE_ATK5), /* S_VILE_ATK4 */ - STATE_ENTRY(SPR_VILE, 32777, 8, a_face_target, - S_VILE_ATK6), /* S_VILE_ATK5 */ - STATE_ENTRY(SPR_VILE, 32778, 8, a_face_target, - S_VILE_ATK7), /* S_VILE_ATK6 */ - STATE_ENTRY(SPR_VILE, 32779, 8, a_face_target, - S_VILE_ATK8), /* S_VILE_ATK7 */ - STATE_ENTRY(SPR_VILE, 32780, 8, a_face_target, - S_VILE_ATK9), /* S_VILE_ATK8 */ - STATE_ENTRY(SPR_VILE, 32781, 8, a_face_target, - S_VILE_ATK10), /* S_VILE_ATK9 */ - STATE_ENTRY(SPR_VILE, 32782, 8, a_vile_attack, - S_VILE_ATK11), /* S_VILE_ATK10 */ - STATE_ENTRY(SPR_VILE, 32783, 20, NULL, S_VILE_RUN1), /* S_VILE_ATK11 */ - STATE_ENTRY(SPR_VILE, 32794, 10, NULL, S_VILE_HEAL2), /* S_VILE_HEAL1 */ - STATE_ENTRY(SPR_VILE, 32795, 10, NULL, S_VILE_HEAL3), /* S_VILE_HEAL2 */ - STATE_ENTRY(SPR_VILE, 32796, 10, NULL, S_VILE_RUN1), /* S_VILE_HEAL3 */ - STATE_ENTRY(SPR_VILE, 16, 5, NULL, S_VILE_PAIN2), /* S_VILE_PAIN */ - STATE_ENTRY(SPR_VILE, 16, 5, a_pain, S_VILE_RUN1), /* S_VILE_PAIN2 */ - STATE_ENTRY(SPR_VILE, 16, 7, NULL, S_VILE_DIE2), /* S_VILE_DIE1 */ - STATE_ENTRY(SPR_VILE, 17, 7, a_scream, S_VILE_DIE3), /* S_VILE_DIE2 */ - STATE_ENTRY(SPR_VILE, 18, 7, a_fall, S_VILE_DIE4), /* S_VILE_DIE3 */ - STATE_ENTRY(SPR_VILE, 19, 7, NULL, S_VILE_DIE5), /* S_VILE_DIE4 */ - STATE_ENTRY(SPR_VILE, 20, 7, NULL, S_VILE_DIE6), /* S_VILE_DIE5 */ - STATE_ENTRY(SPR_VILE, 21, 7, NULL, S_VILE_DIE7), /* S_VILE_DIE6 */ - STATE_ENTRY(SPR_VILE, 22, 7, NULL, S_VILE_DIE8), /* S_VILE_DIE7 */ - STATE_ENTRY(SPR_VILE, 23, 5, NULL, S_VILE_DIE9), /* S_VILE_DIE8 */ - STATE_ENTRY(SPR_VILE, 24, 5, NULL, S_VILE_DIE10), /* S_VILE_DIE9 */ - STATE_ENTRY(SPR_VILE, 25, -1, NULL, S_NULL), /* S_VILE_DIE10 */ - STATE_ENTRY(SPR_FIRE, 32768, 2, a_start_fire, - S_FIRE2), /* S_FIRE1 */ - STATE_ENTRY(SPR_FIRE, 32769, 2, a_fire, S_FIRE3), /* S_FIRE2 */ - STATE_ENTRY(SPR_FIRE, 32768, 2, a_fire, S_FIRE4), /* S_FIRE3 */ - STATE_ENTRY(SPR_FIRE, 32769, 2, a_fire, S_FIRE5), /* S_FIRE4 */ - STATE_ENTRY(SPR_FIRE, 32770, 2, a_fire_crackle, - S_FIRE6), /* S_FIRE5 */ - STATE_ENTRY(SPR_FIRE, 32769, 2, a_fire, S_FIRE7), /* S_FIRE6 */ - STATE_ENTRY(SPR_FIRE, 32770, 2, a_fire, S_FIRE8), /* S_FIRE7 */ - STATE_ENTRY(SPR_FIRE, 32769, 2, a_fire, S_FIRE9), /* S_FIRE8 */ - STATE_ENTRY(SPR_FIRE, 32770, 2, a_fire, S_FIRE10), /* S_FIRE9 */ - STATE_ENTRY(SPR_FIRE, 32771, 2, a_fire, S_FIRE11), /* S_FIRE10 */ - STATE_ENTRY(SPR_FIRE, 32770, 2, a_fire, S_FIRE12), /* S_FIRE11 */ - STATE_ENTRY(SPR_FIRE, 32771, 2, a_fire, S_FIRE13), /* S_FIRE12 */ - STATE_ENTRY(SPR_FIRE, 32770, 2, a_fire, S_FIRE14), /* S_FIRE13 */ - STATE_ENTRY(SPR_FIRE, 32771, 2, a_fire, S_FIRE15), /* S_FIRE14 */ - STATE_ENTRY(SPR_FIRE, 32772, 2, a_fire, S_FIRE16), /* S_FIRE15 */ - STATE_ENTRY(SPR_FIRE, 32771, 2, a_fire, S_FIRE17), /* S_FIRE16 */ - STATE_ENTRY(SPR_FIRE, 32772, 2, a_fire, S_FIRE18), /* S_FIRE17 */ - STATE_ENTRY(SPR_FIRE, 32771, 2, a_fire, S_FIRE19), /* S_FIRE18 */ - STATE_ENTRY(SPR_FIRE, 32772, 2, a_fire_crackle, - S_FIRE20), /* S_FIRE19 */ - STATE_ENTRY(SPR_FIRE, 32773, 2, a_fire, S_FIRE21), /* S_FIRE20 */ - STATE_ENTRY(SPR_FIRE, 32772, 2, a_fire, S_FIRE22), /* S_FIRE21 */ - STATE_ENTRY(SPR_FIRE, 32773, 2, a_fire, S_FIRE23), /* S_FIRE22 */ - STATE_ENTRY(SPR_FIRE, 32772, 2, a_fire, S_FIRE24), /* S_FIRE23 */ - STATE_ENTRY(SPR_FIRE, 32773, 2, a_fire, S_FIRE25), /* S_FIRE24 */ - STATE_ENTRY(SPR_FIRE, 32774, 2, a_fire, S_FIRE26), /* S_FIRE25 */ - STATE_ENTRY(SPR_FIRE, 32775, 2, a_fire, S_FIRE27), /* S_FIRE26 */ - STATE_ENTRY(SPR_FIRE, 32774, 2, a_fire, S_FIRE28), /* S_FIRE27 */ - STATE_ENTRY(SPR_FIRE, 32775, 2, a_fire, S_FIRE29), /* S_FIRE28 */ - STATE_ENTRY(SPR_FIRE, 32774, 2, a_fire, S_FIRE30), /* S_FIRE29 */ - STATE_ENTRY(SPR_FIRE, 32775, 2, a_fire, S_NULL), /* S_FIRE30 */ - STATE_ENTRY(SPR_PUFF, 1, 4, NULL, S_SMOKE2), /* S_SMOKE1 */ - STATE_ENTRY(SPR_PUFF, 2, 4, NULL, S_SMOKE3), /* S_SMOKE2 */ - STATE_ENTRY(SPR_PUFF, 1, 4, NULL, S_SMOKE4), /* S_SMOKE3 */ - STATE_ENTRY(SPR_PUFF, 2, 4, NULL, S_SMOKE5), /* S_SMOKE4 */ - STATE_ENTRY(SPR_PUFF, 3, 4, NULL, S_NULL), /* S_SMOKE5 */ - STATE_ENTRY(SPR_FATB, 32768, 2, a_tracer, S_TRACER2), /* S_TRACER */ - STATE_ENTRY(SPR_FATB, 32769, 2, a_tracer, S_TRACER), /* S_TRACER2 */ - STATE_ENTRY(SPR_FBXP, 32768, 8, NULL, S_TRACEEXP2), /* S_TRACEEXP1 */ - STATE_ENTRY(SPR_FBXP, 32769, 6, NULL, S_TRACEEXP3), /* S_TRACEEXP2 */ - STATE_ENTRY(SPR_FBXP, 32770, 4, NULL, S_NULL), /* S_TRACEEXP3 */ - STATE_ENTRY(SPR_SKEL, 0, 10, a_look, S_SKEL_STND2), /* S_SKEL_STND */ - STATE_ENTRY(SPR_SKEL, 1, 10, a_look, S_SKEL_STND), /* S_SKEL_STND2 */ - STATE_ENTRY(SPR_SKEL, 0, 2, a_chase, S_SKEL_RUN2), /* S_SKEL_RUN1 */ - STATE_ENTRY(SPR_SKEL, 0, 2, a_chase, S_SKEL_RUN3), /* S_SKEL_RUN2 */ - STATE_ENTRY(SPR_SKEL, 1, 2, a_chase, S_SKEL_RUN4), /* S_SKEL_RUN3 */ - STATE_ENTRY(SPR_SKEL, 1, 2, a_chase, S_SKEL_RUN5), /* S_SKEL_RUN4 */ - STATE_ENTRY(SPR_SKEL, 2, 2, a_chase, S_SKEL_RUN6), /* S_SKEL_RUN5 */ - STATE_ENTRY(SPR_SKEL, 2, 2, a_chase, S_SKEL_RUN7), /* S_SKEL_RUN6 */ - STATE_ENTRY(SPR_SKEL, 3, 2, a_chase, S_SKEL_RUN8), /* S_SKEL_RUN7 */ - STATE_ENTRY(SPR_SKEL, 3, 2, a_chase, S_SKEL_RUN9), /* S_SKEL_RUN8 */ - STATE_ENTRY(SPR_SKEL, 4, 2, a_chase, S_SKEL_RUN10), /* S_SKEL_RUN9 */ - STATE_ENTRY(SPR_SKEL, 4, 2, a_chase, S_SKEL_RUN11), /* S_SKEL_RUN10 */ - STATE_ENTRY(SPR_SKEL, 5, 2, a_chase, S_SKEL_RUN12), /* S_SKEL_RUN11 */ - STATE_ENTRY(SPR_SKEL, 5, 2, a_chase, S_SKEL_RUN1), /* S_SKEL_RUN12 */ - STATE_ENTRY(SPR_SKEL, 6, 0, a_face_target, - S_SKEL_FIST2), /* S_SKEL_FIST1 */ - STATE_ENTRY(SPR_SKEL, 6, 6, a_skel_woosh, - S_SKEL_FIST3), /* S_SKEL_FIST2 */ - STATE_ENTRY(SPR_SKEL, 7, 6, a_face_target, - S_SKEL_FIST4), /* S_SKEL_FIST3 */ - STATE_ENTRY(SPR_SKEL, 8, 6, a_skel_fist, S_SKEL_RUN1), /* S_SKEL_FIST4 */ - STATE_ENTRY(SPR_SKEL, 32777, 0, a_face_target, - S_SKEL_MISS2), /* S_SKEL_MISS1 */ - STATE_ENTRY(SPR_SKEL, 32777, 10, a_face_target, - S_SKEL_MISS3), /* S_SKEL_MISS2 */ - STATE_ENTRY(SPR_SKEL, 10, 10, a_skel_missile, - S_SKEL_MISS4), /* S_SKEL_MISS3 */ - STATE_ENTRY(SPR_SKEL, 10, 10, a_face_target, - S_SKEL_RUN1), /* S_SKEL_MISS4 */ - STATE_ENTRY(SPR_SKEL, 11, 5, NULL, S_SKEL_PAIN2), /* S_SKEL_PAIN */ - STATE_ENTRY(SPR_SKEL, 11, 5, a_pain, S_SKEL_RUN1), /* S_SKEL_PAIN2 */ - STATE_ENTRY(SPR_SKEL, 11, 7, NULL, S_SKEL_DIE2), /* S_SKEL_DIE1 */ - STATE_ENTRY(SPR_SKEL, 12, 7, NULL, S_SKEL_DIE3), /* S_SKEL_DIE2 */ - STATE_ENTRY(SPR_SKEL, 13, 7, a_scream, S_SKEL_DIE4), /* S_SKEL_DIE3 */ - STATE_ENTRY(SPR_SKEL, 14, 7, a_fall, S_SKEL_DIE5), /* S_SKEL_DIE4 */ - STATE_ENTRY(SPR_SKEL, 15, 7, NULL, S_SKEL_DIE6), /* S_SKEL_DIE5 */ - STATE_ENTRY(SPR_SKEL, 16, -1, NULL, S_NULL), /* S_SKEL_DIE6 */ - STATE_ENTRY(SPR_SKEL, 16, 5, NULL, S_SKEL_RAISE2), /* S_SKEL_RAISE1 */ - STATE_ENTRY(SPR_SKEL, 15, 5, NULL, S_SKEL_RAISE3), /* S_SKEL_RAISE2 */ - STATE_ENTRY(SPR_SKEL, 14, 5, NULL, S_SKEL_RAISE4), /* S_SKEL_RAISE3 */ - STATE_ENTRY(SPR_SKEL, 13, 5, NULL, S_SKEL_RAISE5), /* S_SKEL_RAISE4 */ - STATE_ENTRY(SPR_SKEL, 12, 5, NULL, S_SKEL_RAISE6), /* S_SKEL_RAISE5 */ - STATE_ENTRY(SPR_SKEL, 11, 5, NULL, S_SKEL_RUN1), /* S_SKEL_RAISE6 */ - STATE_ENTRY(SPR_MANF, 32768, 4, NULL, S_FATSHOT2), /* S_FATSHOT1 */ - STATE_ENTRY(SPR_MANF, 32769, 4, NULL, S_FATSHOT1), /* S_FATSHOT2 */ - STATE_ENTRY(SPR_MISL, 32769, 8, NULL, S_FATSHOTX2), /* S_FATSHOTX1 */ - STATE_ENTRY(SPR_MISL, 32770, 6, NULL, S_FATSHOTX3), /* S_FATSHOTX2 */ - STATE_ENTRY(SPR_MISL, 32771, 4, NULL, S_NULL), /* S_FATSHOTX3 */ - STATE_ENTRY(SPR_FATT, 0, 15, a_look, S_FATT_STND2), /* S_FATT_STND */ - STATE_ENTRY(SPR_FATT, 1, 15, a_look, S_FATT_STND), /* S_FATT_STND2 */ - STATE_ENTRY(SPR_FATT, 0, 4, a_chase, S_FATT_RUN2), /* S_FATT_RUN1 */ - STATE_ENTRY(SPR_FATT, 0, 4, a_chase, S_FATT_RUN3), /* S_FATT_RUN2 */ - STATE_ENTRY(SPR_FATT, 1, 4, a_chase, S_FATT_RUN4), /* S_FATT_RUN3 */ - STATE_ENTRY(SPR_FATT, 1, 4, a_chase, S_FATT_RUN5), /* S_FATT_RUN4 */ - STATE_ENTRY(SPR_FATT, 2, 4, a_chase, S_FATT_RUN6), /* S_FATT_RUN5 */ - STATE_ENTRY(SPR_FATT, 2, 4, a_chase, S_FATT_RUN7), /* S_FATT_RUN6 */ - STATE_ENTRY(SPR_FATT, 3, 4, a_chase, S_FATT_RUN8), /* S_FATT_RUN7 */ - STATE_ENTRY(SPR_FATT, 3, 4, a_chase, S_FATT_RUN9), /* S_FATT_RUN8 */ - STATE_ENTRY(SPR_FATT, 4, 4, a_chase, S_FATT_RUN10), /* S_FATT_RUN9 */ - STATE_ENTRY(SPR_FATT, 4, 4, a_chase, S_FATT_RUN11), /* S_FATT_RUN10 */ - STATE_ENTRY(SPR_FATT, 5, 4, a_chase, S_FATT_RUN12), /* S_FATT_RUN11 */ - STATE_ENTRY(SPR_FATT, 5, 4, a_chase, S_FATT_RUN1), /* S_FATT_RUN12 */ - STATE_ENTRY(SPR_FATT, 6, 20, a_fat_raise, S_FATT_ATK2), /* S_FATT_ATK1 */ - STATE_ENTRY(SPR_FATT, 32775, 10, a_fat_attack1, - S_FATT_ATK3), /* S_FATT_ATK2 */ - STATE_ENTRY(SPR_FATT, 8, 5, a_face_target, S_FATT_ATK4), /* S_FATT_ATK3 */ - STATE_ENTRY(SPR_FATT, 6, 5, a_face_target, S_FATT_ATK5), /* S_FATT_ATK4 */ - STATE_ENTRY(SPR_FATT, 32775, 10, a_fat_attack2, - S_FATT_ATK6), /* S_FATT_ATK5 */ - STATE_ENTRY(SPR_FATT, 8, 5, a_face_target, S_FATT_ATK7), /* S_FATT_ATK6 */ - STATE_ENTRY(SPR_FATT, 6, 5, a_face_target, S_FATT_ATK8), /* S_FATT_ATK7 */ - STATE_ENTRY(SPR_FATT, 32775, 10, a_fat_attack3, - S_FATT_ATK9), /* S_FATT_ATK8 */ - STATE_ENTRY(SPR_FATT, 8, 5, a_face_target, - S_FATT_ATK10), /* S_FATT_ATK9 */ - STATE_ENTRY(SPR_FATT, 6, 5, a_face_target, - S_FATT_RUN1), /* S_FATT_ATK10 */ - STATE_ENTRY(SPR_FATT, 9, 3, NULL, S_FATT_PAIN2), /* S_FATT_PAIN */ - STATE_ENTRY(SPR_FATT, 9, 3, a_pain, S_FATT_RUN1), /* S_FATT_PAIN2 */ - STATE_ENTRY(SPR_FATT, 10, 6, NULL, S_FATT_DIE2), /* S_FATT_DIE1 */ - STATE_ENTRY(SPR_FATT, 11, 6, a_scream, S_FATT_DIE3), /* S_FATT_DIE2 */ - STATE_ENTRY(SPR_FATT, 12, 6, a_fall, S_FATT_DIE4), /* S_FATT_DIE3 */ - STATE_ENTRY(SPR_FATT, 13, 6, NULL, S_FATT_DIE5), /* S_FATT_DIE4 */ - STATE_ENTRY(SPR_FATT, 14, 6, NULL, S_FATT_DIE6), /* S_FATT_DIE5 */ - STATE_ENTRY(SPR_FATT, 15, 6, NULL, S_FATT_DIE7), /* S_FATT_DIE6 */ - STATE_ENTRY(SPR_FATT, 16, 6, NULL, S_FATT_DIE8), /* S_FATT_DIE7 */ - STATE_ENTRY(SPR_FATT, 17, 6, NULL, S_FATT_DIE9), /* S_FATT_DIE8 */ - STATE_ENTRY(SPR_FATT, 18, 6, NULL, S_FATT_DIE10), /* S_FATT_DIE9 */ - STATE_ENTRY(SPR_FATT, 19, -1, a_boss_death, S_NULL), /* S_FATT_DIE10 */ - STATE_ENTRY(SPR_FATT, 17, 5, NULL, S_FATT_RAISE2), /* S_FATT_RAISE1 */ - STATE_ENTRY(SPR_FATT, 16, 5, NULL, S_FATT_RAISE3), /* S_FATT_RAISE2 */ - STATE_ENTRY(SPR_FATT, 15, 5, NULL, S_FATT_RAISE4), /* S_FATT_RAISE3 */ - STATE_ENTRY(SPR_FATT, 14, 5, NULL, S_FATT_RAISE5), /* S_FATT_RAISE4 */ - STATE_ENTRY(SPR_FATT, 13, 5, NULL, S_FATT_RAISE6), /* S_FATT_RAISE5 */ - STATE_ENTRY(SPR_FATT, 12, 5, NULL, S_FATT_RAISE7), /* S_FATT_RAISE6 */ - STATE_ENTRY(SPR_FATT, 11, 5, NULL, S_FATT_RAISE8), /* S_FATT_RAISE7 */ - STATE_ENTRY(SPR_FATT, 10, 5, NULL, S_FATT_RUN1), /* S_FATT_RAISE8 */ - STATE_ENTRY(SPR_CPOS, 0, 10, a_look, S_CPOS_STND2), /* S_CPOS_STND */ - STATE_ENTRY(SPR_CPOS, 1, 10, a_look, S_CPOS_STND), /* S_CPOS_STND2 */ - STATE_ENTRY(SPR_CPOS, 0, 3, a_chase, S_CPOS_RUN2), /* S_CPOS_RUN1 */ - STATE_ENTRY(SPR_CPOS, 0, 3, a_chase, S_CPOS_RUN3), /* S_CPOS_RUN2 */ - STATE_ENTRY(SPR_CPOS, 1, 3, a_chase, S_CPOS_RUN4), /* S_CPOS_RUN3 */ - STATE_ENTRY(SPR_CPOS, 1, 3, a_chase, S_CPOS_RUN5), /* S_CPOS_RUN4 */ - STATE_ENTRY(SPR_CPOS, 2, 3, a_chase, S_CPOS_RUN6), /* S_CPOS_RUN5 */ - STATE_ENTRY(SPR_CPOS, 2, 3, a_chase, S_CPOS_RUN7), /* S_CPOS_RUN6 */ - STATE_ENTRY(SPR_CPOS, 3, 3, a_chase, S_CPOS_RUN8), /* S_CPOS_RUN7 */ - STATE_ENTRY(SPR_CPOS, 3, 3, a_chase, S_CPOS_RUN1), /* S_CPOS_RUN8 */ - STATE_ENTRY(SPR_CPOS, 4, 10, a_face_target, - S_CPOS_ATK2), /* S_CPOS_ATK1 */ - STATE_ENTRY(SPR_CPOS, 32773, 4, a_c_pos_attack, - S_CPOS_ATK3), /* S_CPOS_ATK2 */ - STATE_ENTRY(SPR_CPOS, 32772, 4, a_c_pos_attack, - S_CPOS_ATK4), /* S_CPOS_ATK3 */ - STATE_ENTRY(SPR_CPOS, 5, 1, a_c_pos_refire, - S_CPOS_ATK2), /* S_CPOS_ATK4 */ - STATE_ENTRY(SPR_CPOS, 6, 3, NULL, S_CPOS_PAIN2), /* S_CPOS_PAIN */ - STATE_ENTRY(SPR_CPOS, 6, 3, a_pain, S_CPOS_RUN1), /* S_CPOS_PAIN2 */ - STATE_ENTRY(SPR_CPOS, 7, 5, NULL, S_CPOS_DIE2), /* S_CPOS_DIE1 */ - STATE_ENTRY(SPR_CPOS, 8, 5, a_scream, S_CPOS_DIE3), /* S_CPOS_DIE2 */ - STATE_ENTRY(SPR_CPOS, 9, 5, a_fall, S_CPOS_DIE4), /* S_CPOS_DIE3 */ - STATE_ENTRY(SPR_CPOS, 10, 5, NULL, S_CPOS_DIE5), /* S_CPOS_DIE4 */ - STATE_ENTRY(SPR_CPOS, 11, 5, NULL, S_CPOS_DIE6), /* S_CPOS_DIE5 */ - STATE_ENTRY(SPR_CPOS, 12, 5, NULL, S_CPOS_DIE7), /* S_CPOS_DIE6 */ - STATE_ENTRY(SPR_CPOS, 13, -1, NULL, S_NULL), /* S_CPOS_DIE7 */ - STATE_ENTRY(SPR_CPOS, 14, 5, NULL, S_CPOS_XDIE2), /* S_CPOS_XDIE1 */ - STATE_ENTRY(SPR_CPOS, 15, 5, a_xscream, S_CPOS_XDIE3), /* S_CPOS_XDIE2 */ - STATE_ENTRY(SPR_CPOS, 16, 5, a_fall, S_CPOS_XDIE4), /* S_CPOS_XDIE3 */ - STATE_ENTRY(SPR_CPOS, 17, 5, NULL, S_CPOS_XDIE5), /* S_CPOS_XDIE4 */ - STATE_ENTRY(SPR_CPOS, 18, 5, NULL, S_CPOS_XDIE6), /* S_CPOS_XDIE5 */ - STATE_ENTRY(SPR_CPOS, 19, -1, NULL, S_NULL), /* S_CPOS_XDIE6 */ - STATE_ENTRY(SPR_CPOS, 13, 5, NULL, S_CPOS_RAISE2), /* S_CPOS_RAISE1 */ - STATE_ENTRY(SPR_CPOS, 12, 5, NULL, S_CPOS_RAISE3), /* S_CPOS_RAISE2 */ - STATE_ENTRY(SPR_CPOS, 11, 5, NULL, S_CPOS_RAISE4), /* S_CPOS_RAISE3 */ - STATE_ENTRY(SPR_CPOS, 10, 5, NULL, S_CPOS_RAISE5), /* S_CPOS_RAISE4 */ - STATE_ENTRY(SPR_CPOS, 9, 5, NULL, S_CPOS_RAISE6), /* S_CPOS_RAISE5 */ - STATE_ENTRY(SPR_CPOS, 8, 5, NULL, S_CPOS_RAISE7), /* S_CPOS_RAISE6 */ - STATE_ENTRY(SPR_CPOS, 7, 5, NULL, S_CPOS_RUN1), /* S_CPOS_RAISE7 */ - STATE_ENTRY(SPR_TROO, 0, 10, a_look, S_TROO_STND2), /* S_TROO_STND */ - STATE_ENTRY(SPR_TROO, 1, 10, a_look, S_TROO_STND), /* S_TROO_STND2 */ - STATE_ENTRY(SPR_TROO, 0, 3, a_chase, S_TROO_RUN2), /* S_TROO_RUN1 */ - STATE_ENTRY(SPR_TROO, 0, 3, a_chase, S_TROO_RUN3), /* S_TROO_RUN2 */ - STATE_ENTRY(SPR_TROO, 1, 3, a_chase, S_TROO_RUN4), /* S_TROO_RUN3 */ - STATE_ENTRY(SPR_TROO, 1, 3, a_chase, S_TROO_RUN5), /* S_TROO_RUN4 */ - STATE_ENTRY(SPR_TROO, 2, 3, a_chase, S_TROO_RUN6), /* S_TROO_RUN5 */ - STATE_ENTRY(SPR_TROO, 2, 3, a_chase, S_TROO_RUN7), /* S_TROO_RUN6 */ - STATE_ENTRY(SPR_TROO, 3, 3, a_chase, S_TROO_RUN8), /* S_TROO_RUN7 */ - STATE_ENTRY(SPR_TROO, 3, 3, a_chase, S_TROO_RUN1), /* S_TROO_RUN8 */ - STATE_ENTRY(SPR_TROO, 4, 8, a_face_target, S_TROO_ATK2), /* S_TROO_ATK1 */ - STATE_ENTRY(SPR_TROO, 5, 8, a_face_target, S_TROO_ATK3), /* S_TROO_ATK2 */ - STATE_ENTRY(SPR_TROO, 6, 6, a_troop_attack, - S_TROO_RUN1), /* S_TROO_ATK3 */ - STATE_ENTRY(SPR_TROO, 7, 2, NULL, S_TROO_PAIN2), /* S_TROO_PAIN */ - STATE_ENTRY(SPR_TROO, 7, 2, a_pain, S_TROO_RUN1), /* S_TROO_PAIN2 */ - STATE_ENTRY(SPR_TROO, 8, 8, NULL, S_TROO_DIE2), /* S_TROO_DIE1 */ - STATE_ENTRY(SPR_TROO, 9, 8, a_scream, S_TROO_DIE3), /* S_TROO_DIE2 */ - STATE_ENTRY(SPR_TROO, 10, 6, NULL, S_TROO_DIE4), /* S_TROO_DIE3 */ - STATE_ENTRY(SPR_TROO, 11, 6, a_fall, S_TROO_DIE5), /* S_TROO_DIE4 */ - STATE_ENTRY(SPR_TROO, 12, -1, NULL, S_NULL), /* S_TROO_DIE5 */ - STATE_ENTRY(SPR_TROO, 13, 5, NULL, S_TROO_XDIE2), /* S_TROO_XDIE1 */ - STATE_ENTRY(SPR_TROO, 14, 5, a_xscream, S_TROO_XDIE3), /* S_TROO_XDIE2 */ - STATE_ENTRY(SPR_TROO, 15, 5, NULL, S_TROO_XDIE4), /* S_TROO_XDIE3 */ - STATE_ENTRY(SPR_TROO, 16, 5, a_fall, S_TROO_XDIE5), /* S_TROO_XDIE4 */ - STATE_ENTRY(SPR_TROO, 17, 5, NULL, S_TROO_XDIE6), /* S_TROO_XDIE5 */ - STATE_ENTRY(SPR_TROO, 18, 5, NULL, S_TROO_XDIE7), /* S_TROO_XDIE6 */ - STATE_ENTRY(SPR_TROO, 19, 5, NULL, S_TROO_XDIE8), /* S_TROO_XDIE7 */ - STATE_ENTRY(SPR_TROO, 20, -1, NULL, S_NULL), /* S_TROO_XDIE8 */ - STATE_ENTRY(SPR_TROO, 12, 8, NULL, S_TROO_RAISE2), /* S_TROO_RAISE1 */ - STATE_ENTRY(SPR_TROO, 11, 8, NULL, S_TROO_RAISE3), /* S_TROO_RAISE2 */ - STATE_ENTRY(SPR_TROO, 10, 6, NULL, S_TROO_RAISE4), /* S_TROO_RAISE3 */ - STATE_ENTRY(SPR_TROO, 9, 6, NULL, S_TROO_RAISE5), /* S_TROO_RAISE4 */ - STATE_ENTRY(SPR_TROO, 8, 6, NULL, S_TROO_RUN1), /* S_TROO_RAISE5 */ - STATE_ENTRY(SPR_SARG, 0, 10, a_look, S_SARG_STND2), /* S_SARG_STND */ - STATE_ENTRY(SPR_SARG, 1, 10, a_look, S_SARG_STND), /* S_SARG_STND2 */ - STATE_ENTRY(SPR_SARG, 0, 2, a_chase, S_SARG_RUN2), /* S_SARG_RUN1 */ - STATE_ENTRY(SPR_SARG, 0, 2, a_chase, S_SARG_RUN3), /* S_SARG_RUN2 */ - STATE_ENTRY(SPR_SARG, 1, 2, a_chase, S_SARG_RUN4), /* S_SARG_RUN3 */ - STATE_ENTRY(SPR_SARG, 1, 2, a_chase, S_SARG_RUN5), /* S_SARG_RUN4 */ - STATE_ENTRY(SPR_SARG, 2, 2, a_chase, S_SARG_RUN6), /* S_SARG_RUN5 */ - STATE_ENTRY(SPR_SARG, 2, 2, a_chase, S_SARG_RUN7), /* S_SARG_RUN6 */ - STATE_ENTRY(SPR_SARG, 3, 2, a_chase, S_SARG_RUN8), /* S_SARG_RUN7 */ - STATE_ENTRY(SPR_SARG, 3, 2, a_chase, S_SARG_RUN1), /* S_SARG_RUN8 */ - STATE_ENTRY(SPR_SARG, 4, 8, a_face_target, S_SARG_ATK2), /* S_SARG_ATK1 */ - STATE_ENTRY(SPR_SARG, 5, 8, a_face_target, S_SARG_ATK3), /* S_SARG_ATK2 */ - STATE_ENTRY(SPR_SARG, 6, 8, a_sarg_attack, S_SARG_RUN1), /* S_SARG_ATK3 */ - STATE_ENTRY(SPR_SARG, 7, 2, NULL, S_SARG_PAIN2), /* S_SARG_PAIN */ - STATE_ENTRY(SPR_SARG, 7, 2, a_pain, S_SARG_RUN1), /* S_SARG_PAIN2 */ - STATE_ENTRY(SPR_SARG, 8, 8, NULL, S_SARG_DIE2), /* S_SARG_DIE1 */ - STATE_ENTRY(SPR_SARG, 9, 8, a_scream, S_SARG_DIE3), /* S_SARG_DIE2 */ - STATE_ENTRY(SPR_SARG, 10, 4, NULL, S_SARG_DIE4), /* S_SARG_DIE3 */ - STATE_ENTRY(SPR_SARG, 11, 4, a_fall, S_SARG_DIE5), /* S_SARG_DIE4 */ - STATE_ENTRY(SPR_SARG, 12, 4, NULL, S_SARG_DIE6), /* S_SARG_DIE5 */ - STATE_ENTRY(SPR_SARG, 13, -1, NULL, S_NULL), /* S_SARG_DIE6 */ - STATE_ENTRY(SPR_SARG, 13, 5, NULL, S_SARG_RAISE2), /* S_SARG_RAISE1 */ - STATE_ENTRY(SPR_SARG, 12, 5, NULL, S_SARG_RAISE3), /* S_SARG_RAISE2 */ - STATE_ENTRY(SPR_SARG, 11, 5, NULL, S_SARG_RAISE4), /* S_SARG_RAISE3 */ - STATE_ENTRY(SPR_SARG, 10, 5, NULL, S_SARG_RAISE5), /* S_SARG_RAISE4 */ - STATE_ENTRY(SPR_SARG, 9, 5, NULL, S_SARG_RAISE6), /* S_SARG_RAISE5 */ - STATE_ENTRY(SPR_SARG, 8, 5, NULL, S_SARG_RUN1), /* S_SARG_RAISE6 */ - STATE_ENTRY(SPR_HEAD, 0, 10, a_look, S_HEAD_STND), /* S_HEAD_STND */ - STATE_ENTRY(SPR_HEAD, 0, 3, a_chase, S_HEAD_RUN1), /* S_HEAD_RUN1 */ - STATE_ENTRY(SPR_HEAD, 1, 5, a_face_target, S_HEAD_ATK2), /* S_HEAD_ATK1 */ - STATE_ENTRY(SPR_HEAD, 2, 5, a_face_target, S_HEAD_ATK3), /* S_HEAD_ATK2 */ - STATE_ENTRY(SPR_HEAD, 32771, 5, a_head_attack, - S_HEAD_RUN1), /* S_HEAD_ATK3 */ - STATE_ENTRY(SPR_HEAD, 4, 3, NULL, S_HEAD_PAIN2), /* S_HEAD_PAIN */ - STATE_ENTRY(SPR_HEAD, 4, 3, a_pain, S_HEAD_PAIN3), /* S_HEAD_PAIN2 */ - STATE_ENTRY(SPR_HEAD, 5, 6, NULL, S_HEAD_RUN1), /* S_HEAD_PAIN3 */ - STATE_ENTRY(SPR_HEAD, 6, 8, NULL, S_HEAD_DIE2), /* S_HEAD_DIE1 */ - STATE_ENTRY(SPR_HEAD, 7, 8, a_scream, S_HEAD_DIE3), /* S_HEAD_DIE2 */ - STATE_ENTRY(SPR_HEAD, 8, 8, NULL, S_HEAD_DIE4), /* S_HEAD_DIE3 */ - STATE_ENTRY(SPR_HEAD, 9, 8, NULL, S_HEAD_DIE5), /* S_HEAD_DIE4 */ - STATE_ENTRY(SPR_HEAD, 10, 8, a_fall, S_HEAD_DIE6), /* S_HEAD_DIE5 */ - STATE_ENTRY(SPR_HEAD, 11, -1, NULL, S_NULL), /* S_HEAD_DIE6 */ - STATE_ENTRY(SPR_HEAD, 11, 8, NULL, S_HEAD_RAISE2), /* S_HEAD_RAISE1 */ - STATE_ENTRY(SPR_HEAD, 10, 8, NULL, S_HEAD_RAISE3), /* S_HEAD_RAISE2 */ - STATE_ENTRY(SPR_HEAD, 9, 8, NULL, S_HEAD_RAISE4), /* S_HEAD_RAISE3 */ - STATE_ENTRY(SPR_HEAD, 8, 8, NULL, S_HEAD_RAISE5), /* S_HEAD_RAISE4 */ - STATE_ENTRY(SPR_HEAD, 7, 8, NULL, S_HEAD_RAISE6), /* S_HEAD_RAISE5 */ - STATE_ENTRY(SPR_HEAD, 6, 8, NULL, S_HEAD_RUN1), /* S_HEAD_RAISE6 */ - STATE_ENTRY(SPR_BAL7, 32768, 4, NULL, S_BRBALL2), /* S_BRBALL1 */ - STATE_ENTRY(SPR_BAL7, 32769, 4, NULL, S_BRBALL1), /* S_BRBALL2 */ - STATE_ENTRY(SPR_BAL7, 32770, 6, NULL, S_BRBALLX2), /* S_BRBALLX1 */ - STATE_ENTRY(SPR_BAL7, 32771, 6, NULL, S_BRBALLX3), /* S_BRBALLX2 */ - STATE_ENTRY(SPR_BAL7, 32772, 6, NULL, S_NULL), /* S_BRBALLX3 */ - STATE_ENTRY(SPR_BOSS, 0, 10, a_look, S_BOSS_STND2), /* S_BOSS_STND */ - STATE_ENTRY(SPR_BOSS, 1, 10, a_look, S_BOSS_STND), /* S_BOSS_STND2 */ - STATE_ENTRY(SPR_BOSS, 0, 3, a_chase, S_BOSS_RUN2), /* S_BOSS_RUN1 */ - STATE_ENTRY(SPR_BOSS, 0, 3, a_chase, S_BOSS_RUN3), /* S_BOSS_RUN2 */ - STATE_ENTRY(SPR_BOSS, 1, 3, a_chase, S_BOSS_RUN4), /* S_BOSS_RUN3 */ - STATE_ENTRY(SPR_BOSS, 1, 3, a_chase, S_BOSS_RUN5), /* S_BOSS_RUN4 */ - STATE_ENTRY(SPR_BOSS, 2, 3, a_chase, S_BOSS_RUN6), /* S_BOSS_RUN5 */ - STATE_ENTRY(SPR_BOSS, 2, 3, a_chase, S_BOSS_RUN7), /* S_BOSS_RUN6 */ - STATE_ENTRY(SPR_BOSS, 3, 3, a_chase, S_BOSS_RUN8), /* S_BOSS_RUN7 */ - STATE_ENTRY(SPR_BOSS, 3, 3, a_chase, S_BOSS_RUN1), /* S_BOSS_RUN8 */ - STATE_ENTRY(SPR_BOSS, 4, 8, a_face_target, S_BOSS_ATK2), /* S_BOSS_ATK1 */ - STATE_ENTRY(SPR_BOSS, 5, 8, a_face_target, S_BOSS_ATK3), /* S_BOSS_ATK2 */ - STATE_ENTRY(SPR_BOSS, 6, 8, a_bruis_attack, - S_BOSS_RUN1), /* S_BOSS_ATK3 */ - STATE_ENTRY(SPR_BOSS, 7, 2, NULL, S_BOSS_PAIN2), /* S_BOSS_PAIN */ - STATE_ENTRY(SPR_BOSS, 7, 2, a_pain, S_BOSS_RUN1), /* S_BOSS_PAIN2 */ - STATE_ENTRY(SPR_BOSS, 8, 8, NULL, S_BOSS_DIE2), /* S_BOSS_DIE1 */ - STATE_ENTRY(SPR_BOSS, 9, 8, a_scream, S_BOSS_DIE3), /* S_BOSS_DIE2 */ - STATE_ENTRY(SPR_BOSS, 10, 8, NULL, S_BOSS_DIE4), /* S_BOSS_DIE3 */ - STATE_ENTRY(SPR_BOSS, 11, 8, a_fall, S_BOSS_DIE5), /* S_BOSS_DIE4 */ - STATE_ENTRY(SPR_BOSS, 12, 8, NULL, S_BOSS_DIE6), /* S_BOSS_DIE5 */ - STATE_ENTRY(SPR_BOSS, 13, 8, NULL, S_BOSS_DIE7), /* S_BOSS_DIE6 */ - STATE_ENTRY(SPR_BOSS, 14, -1, a_boss_death, S_NULL), /* S_BOSS_DIE7 */ - STATE_ENTRY(SPR_BOSS, 14, 8, NULL, S_BOSS_RAISE2), /* S_BOSS_RAISE1 */ - STATE_ENTRY(SPR_BOSS, 13, 8, NULL, S_BOSS_RAISE3), /* S_BOSS_RAISE2 */ - STATE_ENTRY(SPR_BOSS, 12, 8, NULL, S_BOSS_RAISE4), /* S_BOSS_RAISE3 */ - STATE_ENTRY(SPR_BOSS, 11, 8, NULL, S_BOSS_RAISE5), /* S_BOSS_RAISE4 */ - STATE_ENTRY(SPR_BOSS, 10, 8, NULL, S_BOSS_RAISE6), /* S_BOSS_RAISE5 */ - STATE_ENTRY(SPR_BOSS, 9, 8, NULL, S_BOSS_RAISE7), /* S_BOSS_RAISE6 */ - STATE_ENTRY(SPR_BOSS, 8, 8, NULL, S_BOSS_RUN1), /* S_BOSS_RAISE7 */ - STATE_ENTRY(SPR_BOS2, 0, 10, a_look, S_BOS2_STND2), /* S_BOS2_STND */ - STATE_ENTRY(SPR_BOS2, 1, 10, a_look, S_BOS2_STND), /* S_BOS2_STND2 */ - STATE_ENTRY(SPR_BOS2, 0, 3, a_chase, S_BOS2_RUN2), /* S_BOS2_RUN1 */ - STATE_ENTRY(SPR_BOS2, 0, 3, a_chase, S_BOS2_RUN3), /* S_BOS2_RUN2 */ - STATE_ENTRY(SPR_BOS2, 1, 3, a_chase, S_BOS2_RUN4), /* S_BOS2_RUN3 */ - STATE_ENTRY(SPR_BOS2, 1, 3, a_chase, S_BOS2_RUN5), /* S_BOS2_RUN4 */ - STATE_ENTRY(SPR_BOS2, 2, 3, a_chase, S_BOS2_RUN6), /* S_BOS2_RUN5 */ - STATE_ENTRY(SPR_BOS2, 2, 3, a_chase, S_BOS2_RUN7), /* S_BOS2_RUN6 */ - STATE_ENTRY(SPR_BOS2, 3, 3, a_chase, S_BOS2_RUN8), /* S_BOS2_RUN7 */ - STATE_ENTRY(SPR_BOS2, 3, 3, a_chase, S_BOS2_RUN1), /* S_BOS2_RUN8 */ - STATE_ENTRY(SPR_BOS2, 4, 8, a_face_target, S_BOS2_ATK2), /* S_BOS2_ATK1 */ - STATE_ENTRY(SPR_BOS2, 5, 8, a_face_target, S_BOS2_ATK3), /* S_BOS2_ATK2 */ - STATE_ENTRY(SPR_BOS2, 6, 8, a_bruis_attack, - S_BOS2_RUN1), /* S_BOS2_ATK3 */ - STATE_ENTRY(SPR_BOS2, 7, 2, NULL, S_BOS2_PAIN2), /* S_BOS2_PAIN */ - STATE_ENTRY(SPR_BOS2, 7, 2, a_pain, S_BOS2_RUN1), /* S_BOS2_PAIN2 */ - STATE_ENTRY(SPR_BOS2, 8, 8, NULL, S_BOS2_DIE2), /* S_BOS2_DIE1 */ - STATE_ENTRY(SPR_BOS2, 9, 8, a_scream, S_BOS2_DIE3), /* S_BOS2_DIE2 */ - STATE_ENTRY(SPR_BOS2, 10, 8, NULL, S_BOS2_DIE4), /* S_BOS2_DIE3 */ - STATE_ENTRY(SPR_BOS2, 11, 8, a_fall, S_BOS2_DIE5), /* S_BOS2_DIE4 */ - STATE_ENTRY(SPR_BOS2, 12, 8, NULL, S_BOS2_DIE6), /* S_BOS2_DIE5 */ - STATE_ENTRY(SPR_BOS2, 13, 8, NULL, S_BOS2_DIE7), /* S_BOS2_DIE6 */ - STATE_ENTRY(SPR_BOS2, 14, -1, NULL, S_NULL), /* S_BOS2_DIE7 */ - STATE_ENTRY(SPR_BOS2, 14, 8, NULL, S_BOS2_RAISE2), /* S_BOS2_RAISE1 */ - STATE_ENTRY(SPR_BOS2, 13, 8, NULL, S_BOS2_RAISE3), /* S_BOS2_RAISE2 */ - STATE_ENTRY(SPR_BOS2, 12, 8, NULL, S_BOS2_RAISE4), /* S_BOS2_RAISE3 */ - STATE_ENTRY(SPR_BOS2, 11, 8, NULL, S_BOS2_RAISE5), /* S_BOS2_RAISE4 */ - STATE_ENTRY(SPR_BOS2, 10, 8, NULL, S_BOS2_RAISE6), /* S_BOS2_RAISE5 */ - STATE_ENTRY(SPR_BOS2, 9, 8, NULL, S_BOS2_RAISE7), /* S_BOS2_RAISE6 */ - STATE_ENTRY(SPR_BOS2, 8, 8, NULL, S_BOS2_RUN1), /* S_BOS2_RAISE7 */ - STATE_ENTRY(SPR_SKUL, 32768, 10, a_look, - S_SKULL_STND2), /* S_SKULL_STND */ - STATE_ENTRY(SPR_SKUL, 32769, 10, a_look, - S_SKULL_STND), /* S_SKULL_STND2 */ - STATE_ENTRY(SPR_SKUL, 32768, 6, a_chase, - S_SKULL_RUN2), /* S_SKULL_RUN1 */ - STATE_ENTRY(SPR_SKUL, 32769, 6, a_chase, - S_SKULL_RUN1), /* S_SKULL_RUN2 */ - STATE_ENTRY(SPR_SKUL, 32770, 10, a_face_target, - S_SKULL_ATK2), /* S_SKULL_ATK1 */ - STATE_ENTRY(SPR_SKUL, 32771, 4, a_skull_attack, - S_SKULL_ATK3), /* S_SKULL_ATK2 */ - STATE_ENTRY(SPR_SKUL, 32770, 4, NULL, S_SKULL_ATK4), /* S_SKULL_ATK3 */ - STATE_ENTRY(SPR_SKUL, 32771, 4, NULL, S_SKULL_ATK3), /* S_SKULL_ATK4 */ - STATE_ENTRY(SPR_SKUL, 32772, 3, NULL, S_SKULL_PAIN2), /* S_SKULL_PAIN */ - STATE_ENTRY(SPR_SKUL, 32772, 3, a_pain, S_SKULL_RUN1), /* S_SKULL_PAIN2 */ - STATE_ENTRY(SPR_SKUL, 32773, 6, NULL, S_SKULL_DIE2), /* S_SKULL_DIE1 */ - STATE_ENTRY(SPR_SKUL, 32774, 6, a_scream, - S_SKULL_DIE3), /* S_SKULL_DIE2 */ - STATE_ENTRY(SPR_SKUL, 32775, 6, NULL, S_SKULL_DIE4), /* S_SKULL_DIE3 */ - STATE_ENTRY(SPR_SKUL, 32776, 6, a_fall, S_SKULL_DIE5), /* S_SKULL_DIE4 */ - STATE_ENTRY(SPR_SKUL, 9, 6, NULL, S_SKULL_DIE6), /* S_SKULL_DIE5 */ - STATE_ENTRY(SPR_SKUL, 10, 6, NULL, S_NULL), /* S_SKULL_DIE6 */ - STATE_ENTRY(SPR_SPID, 0, 10, a_look, S_SPID_STND2), /* S_SPID_STND */ - STATE_ENTRY(SPR_SPID, 1, 10, a_look, S_SPID_STND), /* S_SPID_STND2 */ - STATE_ENTRY(SPR_SPID, 0, 3, a_metal, S_SPID_RUN2), /* S_SPID_RUN1 */ - STATE_ENTRY(SPR_SPID, 0, 3, a_chase, S_SPID_RUN3), /* S_SPID_RUN2 */ - STATE_ENTRY(SPR_SPID, 1, 3, a_chase, S_SPID_RUN4), /* S_SPID_RUN3 */ - STATE_ENTRY(SPR_SPID, 1, 3, a_chase, S_SPID_RUN5), /* S_SPID_RUN4 */ - STATE_ENTRY(SPR_SPID, 2, 3, a_metal, S_SPID_RUN6), /* S_SPID_RUN5 */ - STATE_ENTRY(SPR_SPID, 2, 3, a_chase, S_SPID_RUN7), /* S_SPID_RUN6 */ - STATE_ENTRY(SPR_SPID, 3, 3, a_chase, S_SPID_RUN8), /* S_SPID_RUN7 */ - STATE_ENTRY(SPR_SPID, 3, 3, a_chase, S_SPID_RUN9), /* S_SPID_RUN8 */ - STATE_ENTRY(SPR_SPID, 4, 3, a_metal, S_SPID_RUN10), /* S_SPID_RUN9 */ - STATE_ENTRY(SPR_SPID, 4, 3, a_chase, S_SPID_RUN11), /* S_SPID_RUN10 */ - STATE_ENTRY(SPR_SPID, 5, 3, a_chase, S_SPID_RUN12), /* S_SPID_RUN11 */ - STATE_ENTRY(SPR_SPID, 5, 3, a_chase, S_SPID_RUN1), /* S_SPID_RUN12 */ - STATE_ENTRY(SPR_SPID, 32768, 20, a_face_target, - S_SPID_ATK2), /* S_SPID_ATK1 */ - STATE_ENTRY(SPR_SPID, 32774, 4, a_s_pos_attack, - S_SPID_ATK3), /* S_SPID_ATK2 */ - STATE_ENTRY(SPR_SPID, 32775, 4, a_s_pos_attack, - S_SPID_ATK4), /* S_SPID_ATK3 */ - STATE_ENTRY(SPR_SPID, 32775, 1, a_spid_refire, - S_SPID_ATK2), /* S_SPID_ATK4 */ - STATE_ENTRY(SPR_SPID, 8, 3, NULL, S_SPID_PAIN2), /* S_SPID_PAIN */ - STATE_ENTRY(SPR_SPID, 8, 3, a_pain, S_SPID_RUN1), /* S_SPID_PAIN2 */ - STATE_ENTRY(SPR_SPID, 9, 20, a_scream, S_SPID_DIE2), /* S_SPID_DIE1 */ - STATE_ENTRY(SPR_SPID, 10, 10, a_fall, S_SPID_DIE3), /* S_SPID_DIE2 */ - STATE_ENTRY(SPR_SPID, 11, 10, NULL, S_SPID_DIE4), /* S_SPID_DIE3 */ - STATE_ENTRY(SPR_SPID, 12, 10, NULL, S_SPID_DIE5), /* S_SPID_DIE4 */ - STATE_ENTRY(SPR_SPID, 13, 10, NULL, S_SPID_DIE6), /* S_SPID_DIE5 */ - STATE_ENTRY(SPR_SPID, 14, 10, NULL, S_SPID_DIE7), /* S_SPID_DIE6 */ - STATE_ENTRY(SPR_SPID, 15, 10, NULL, S_SPID_DIE8), /* S_SPID_DIE7 */ - STATE_ENTRY(SPR_SPID, 16, 10, NULL, S_SPID_DIE9), /* S_SPID_DIE8 */ - STATE_ENTRY(SPR_SPID, 17, 10, NULL, S_SPID_DIE10), /* S_SPID_DIE9 */ - STATE_ENTRY(SPR_SPID, 18, 30, NULL, S_SPID_DIE11), /* S_SPID_DIE10 */ - STATE_ENTRY(SPR_SPID, 18, -1, a_boss_death, S_NULL), /* S_SPID_DIE11 */ - STATE_ENTRY(SPR_BSPI, 0, 10, a_look, S_BSPI_STND2), /* S_BSPI_STND */ - STATE_ENTRY(SPR_BSPI, 1, 10, a_look, S_BSPI_STND), /* S_BSPI_STND2 */ - STATE_ENTRY(SPR_BSPI, 0, 20, NULL, S_BSPI_RUN1), /* S_BSPI_SIGHT */ - STATE_ENTRY(SPR_BSPI, 0, 3, a_baby_metal, S_BSPI_RUN2), /* S_BSPI_RUN1 */ - STATE_ENTRY(SPR_BSPI, 0, 3, a_chase, S_BSPI_RUN3), /* S_BSPI_RUN2 */ - STATE_ENTRY(SPR_BSPI, 1, 3, a_chase, S_BSPI_RUN4), /* S_BSPI_RUN3 */ - STATE_ENTRY(SPR_BSPI, 1, 3, a_chase, S_BSPI_RUN5), /* S_BSPI_RUN4 */ - STATE_ENTRY(SPR_BSPI, 2, 3, a_chase, S_BSPI_RUN6), /* S_BSPI_RUN5 */ - STATE_ENTRY(SPR_BSPI, 2, 3, a_chase, S_BSPI_RUN7), /* S_BSPI_RUN6 */ - STATE_ENTRY(SPR_BSPI, 3, 3, a_baby_metal, S_BSPI_RUN8), /* S_BSPI_RUN7 */ - STATE_ENTRY(SPR_BSPI, 3, 3, a_chase, S_BSPI_RUN9), /* S_BSPI_RUN8 */ - STATE_ENTRY(SPR_BSPI, 4, 3, a_chase, S_BSPI_RUN10), /* S_BSPI_RUN9 */ - STATE_ENTRY(SPR_BSPI, 4, 3, a_chase, S_BSPI_RUN11), /* S_BSPI_RUN10 */ - STATE_ENTRY(SPR_BSPI, 5, 3, a_chase, S_BSPI_RUN12), /* S_BSPI_RUN11 */ - STATE_ENTRY(SPR_BSPI, 5, 3, a_chase, S_BSPI_RUN1), /* S_BSPI_RUN12 */ - STATE_ENTRY(SPR_BSPI, 32768, 20, a_face_target, - S_BSPI_ATK2), /* S_BSPI_ATK1 */ - STATE_ENTRY(SPR_BSPI, 32774, 4, a_bspi_attack, - S_BSPI_ATK3), /* S_BSPI_ATK2 */ - STATE_ENTRY(SPR_BSPI, 32775, 4, NULL, S_BSPI_ATK4), /* S_BSPI_ATK3 */ - STATE_ENTRY(SPR_BSPI, 32775, 1, a_spid_refire, - S_BSPI_ATK2), /* S_BSPI_ATK4 */ - STATE_ENTRY(SPR_BSPI, 8, 3, NULL, S_BSPI_PAIN2), /* S_BSPI_PAIN */ - STATE_ENTRY(SPR_BSPI, 8, 3, a_pain, S_BSPI_RUN1), /* S_BSPI_PAIN2 */ - STATE_ENTRY(SPR_BSPI, 9, 20, a_scream, S_BSPI_DIE2), /* S_BSPI_DIE1 */ - STATE_ENTRY(SPR_BSPI, 10, 7, a_fall, S_BSPI_DIE3), /* S_BSPI_DIE2 */ - STATE_ENTRY(SPR_BSPI, 11, 7, NULL, S_BSPI_DIE4), /* S_BSPI_DIE3 */ - STATE_ENTRY(SPR_BSPI, 12, 7, NULL, S_BSPI_DIE5), /* S_BSPI_DIE4 */ - STATE_ENTRY(SPR_BSPI, 13, 7, NULL, S_BSPI_DIE6), /* S_BSPI_DIE5 */ - STATE_ENTRY(SPR_BSPI, 14, 7, NULL, S_BSPI_DIE7), /* S_BSPI_DIE6 */ - STATE_ENTRY(SPR_BSPI, 15, -1, a_boss_death, S_NULL), /* S_BSPI_DIE7 */ - STATE_ENTRY(SPR_BSPI, 15, 5, NULL, S_BSPI_RAISE2), /* S_BSPI_RAISE1 */ - STATE_ENTRY(SPR_BSPI, 14, 5, NULL, S_BSPI_RAISE3), /* S_BSPI_RAISE2 */ - STATE_ENTRY(SPR_BSPI, 13, 5, NULL, S_BSPI_RAISE4), /* S_BSPI_RAISE3 */ - STATE_ENTRY(SPR_BSPI, 12, 5, NULL, S_BSPI_RAISE5), /* S_BSPI_RAISE4 */ - STATE_ENTRY(SPR_BSPI, 11, 5, NULL, S_BSPI_RAISE6), /* S_BSPI_RAISE5 */ - STATE_ENTRY(SPR_BSPI, 10, 5, NULL, S_BSPI_RAISE7), /* S_BSPI_RAISE6 */ - STATE_ENTRY(SPR_BSPI, 9, 5, NULL, S_BSPI_RUN1), /* S_BSPI_RAISE7 */ - STATE_ENTRY(SPR_APLS, 32768, 5, NULL, S_ARACH_PLAZ2), /* S_ARACH_PLAZ */ - STATE_ENTRY(SPR_APLS, 32769, 5, NULL, S_ARACH_PLAZ), /* S_ARACH_PLAZ2 */ - STATE_ENTRY(SPR_APBX, 32768, 5, NULL, S_ARACH_PLEX2), /* S_ARACH_PLEX */ - STATE_ENTRY(SPR_APBX, 32769, 5, NULL, S_ARACH_PLEX3), /* S_ARACH_PLEX2 */ - STATE_ENTRY(SPR_APBX, 32770, 5, NULL, S_ARACH_PLEX4), /* S_ARACH_PLEX3 */ - STATE_ENTRY(SPR_APBX, 32771, 5, NULL, S_ARACH_PLEX5), /* S_ARACH_PLEX4 */ - STATE_ENTRY(SPR_APBX, 32772, 5, NULL, S_NULL), /* S_ARACH_PLEX5 */ - STATE_ENTRY(SPR_CYBR, 0, 10, a_look, S_CYBER_STND2), /* S_CYBER_STND */ - STATE_ENTRY(SPR_CYBR, 1, 10, a_look, S_CYBER_STND), /* S_CYBER_STND2 */ - STATE_ENTRY(SPR_CYBR, 0, 3, a_hoof, S_CYBER_RUN2), /* S_CYBER_RUN1 */ - STATE_ENTRY(SPR_CYBR, 0, 3, a_chase, S_CYBER_RUN3), /* S_CYBER_RUN2 */ - STATE_ENTRY(SPR_CYBR, 1, 3, a_chase, S_CYBER_RUN4), /* S_CYBER_RUN3 */ - STATE_ENTRY(SPR_CYBR, 1, 3, a_chase, S_CYBER_RUN5), /* S_CYBER_RUN4 */ - STATE_ENTRY(SPR_CYBR, 2, 3, a_chase, S_CYBER_RUN6), /* S_CYBER_RUN5 */ - STATE_ENTRY(SPR_CYBR, 2, 3, a_chase, S_CYBER_RUN7), /* S_CYBER_RUN6 */ - STATE_ENTRY(SPR_CYBR, 3, 3, a_metal, S_CYBER_RUN8), /* S_CYBER_RUN7 */ - STATE_ENTRY(SPR_CYBR, 3, 3, a_chase, S_CYBER_RUN1), /* S_CYBER_RUN8 */ - STATE_ENTRY(SPR_CYBR, 4, 6, a_face_target, - S_CYBER_ATK2), /* S_CYBER_ATK1 */ - STATE_ENTRY(SPR_CYBR, 5, 12, a_cyber_attack, - S_CYBER_ATK3), /* S_CYBER_ATK2 */ - STATE_ENTRY(SPR_CYBR, 4, 12, a_face_target, - S_CYBER_ATK4), /* S_CYBER_ATK3 */ - STATE_ENTRY(SPR_CYBR, 5, 12, a_cyber_attack, - S_CYBER_ATK5), /* S_CYBER_ATK4 */ - STATE_ENTRY(SPR_CYBR, 4, 12, a_face_target, - S_CYBER_ATK6), /* S_CYBER_ATK5 */ - STATE_ENTRY(SPR_CYBR, 5, 12, a_cyber_attack, - S_CYBER_RUN1), /* S_CYBER_ATK6 */ - STATE_ENTRY(SPR_CYBR, 6, 10, a_pain, S_CYBER_RUN1), /* S_CYBER_PAIN */ - STATE_ENTRY(SPR_CYBR, 7, 10, NULL, S_CYBER_DIE2), /* S_CYBER_DIE1 */ - STATE_ENTRY(SPR_CYBR, 8, 10, a_scream, S_CYBER_DIE3), /* S_CYBER_DIE2 */ - STATE_ENTRY(SPR_CYBR, 9, 10, NULL, S_CYBER_DIE4), /* S_CYBER_DIE3 */ - STATE_ENTRY(SPR_CYBR, 10, 10, NULL, S_CYBER_DIE5), /* S_CYBER_DIE4 */ - STATE_ENTRY(SPR_CYBR, 11, 10, NULL, S_CYBER_DIE6), /* S_CYBER_DIE5 */ - STATE_ENTRY(SPR_CYBR, 12, 10, a_fall, S_CYBER_DIE7), /* S_CYBER_DIE6 */ - STATE_ENTRY(SPR_CYBR, 13, 10, NULL, S_CYBER_DIE8), /* S_CYBER_DIE7 */ - STATE_ENTRY(SPR_CYBR, 14, 10, NULL, S_CYBER_DIE9), /* S_CYBER_DIE8 */ - STATE_ENTRY(SPR_CYBR, 15, 30, NULL, S_CYBER_DIE10), /* S_CYBER_DIE9 */ - STATE_ENTRY(SPR_CYBR, 15, -1, a_boss_death, S_NULL), /* S_CYBER_DIE10 */ - STATE_ENTRY(SPR_PAIN, 0, 10, a_look, S_PAIN_STND), /* S_PAIN_STND */ - STATE_ENTRY(SPR_PAIN, 0, 3, a_chase, S_PAIN_RUN2), /* S_PAIN_RUN1 */ - STATE_ENTRY(SPR_PAIN, 0, 3, a_chase, S_PAIN_RUN3), /* S_PAIN_RUN2 */ - STATE_ENTRY(SPR_PAIN, 1, 3, a_chase, S_PAIN_RUN4), /* S_PAIN_RUN3 */ - STATE_ENTRY(SPR_PAIN, 1, 3, a_chase, S_PAIN_RUN5), /* S_PAIN_RUN4 */ - STATE_ENTRY(SPR_PAIN, 2, 3, a_chase, S_PAIN_RUN6), /* S_PAIN_RUN5 */ - STATE_ENTRY(SPR_PAIN, 2, 3, a_chase, S_PAIN_RUN1), /* S_PAIN_RUN6 */ - STATE_ENTRY(SPR_PAIN, 3, 5, a_face_target, S_PAIN_ATK2), /* S_PAIN_ATK1 */ - STATE_ENTRY(SPR_PAIN, 4, 5, a_face_target, S_PAIN_ATK3), /* S_PAIN_ATK2 */ - STATE_ENTRY(SPR_PAIN, 32773, 5, a_face_target, - S_PAIN_ATK4), /* S_PAIN_ATK3 */ - STATE_ENTRY(SPR_PAIN, 32773, 0, a_pain_attack, - S_PAIN_RUN1), /* S_PAIN_ATK4 */ - STATE_ENTRY(SPR_PAIN, 6, 6, NULL, S_PAIN_PAIN2), /* S_PAIN_PAIN */ - STATE_ENTRY(SPR_PAIN, 6, 6, a_pain, S_PAIN_RUN1), /* S_PAIN_PAIN2 */ - STATE_ENTRY(SPR_PAIN, 32775, 8, NULL, S_PAIN_DIE2), /* S_PAIN_DIE1 */ - STATE_ENTRY(SPR_PAIN, 32776, 8, a_scream, S_PAIN_DIE3), /* S_PAIN_DIE2 */ - STATE_ENTRY(SPR_PAIN, 32777, 8, NULL, S_PAIN_DIE4), /* S_PAIN_DIE3 */ - STATE_ENTRY(SPR_PAIN, 32778, 8, NULL, S_PAIN_DIE5), /* S_PAIN_DIE4 */ - STATE_ENTRY(SPR_PAIN, 32779, 8, a_pain_die, - S_PAIN_DIE6), /* S_PAIN_DIE5 */ - STATE_ENTRY(SPR_PAIN, 32780, 8, NULL, S_NULL), /* S_PAIN_DIE6 */ - STATE_ENTRY(SPR_PAIN, 12, 8, NULL, S_PAIN_RAISE2), /* S_PAIN_RAISE1 */ - STATE_ENTRY(SPR_PAIN, 11, 8, NULL, S_PAIN_RAISE3), /* S_PAIN_RAISE2 */ - STATE_ENTRY(SPR_PAIN, 10, 8, NULL, S_PAIN_RAISE4), /* S_PAIN_RAISE3 */ - STATE_ENTRY(SPR_PAIN, 9, 8, NULL, S_PAIN_RAISE5), /* S_PAIN_RAISE4 */ - STATE_ENTRY(SPR_PAIN, 8, 8, NULL, S_PAIN_RAISE6), /* S_PAIN_RAISE5 */ - STATE_ENTRY(SPR_PAIN, 7, 8, NULL, S_PAIN_RUN1), /* S_PAIN_RAISE6 */ - STATE_ENTRY(SPR_SSWV, 0, 10, a_look, S_SSWV_STND2), /* S_SSWV_STND */ - STATE_ENTRY(SPR_SSWV, 1, 10, a_look, S_SSWV_STND), /* S_SSWV_STND2 */ - STATE_ENTRY(SPR_SSWV, 0, 3, a_chase, S_SSWV_RUN2), /* S_SSWV_RUN1 */ - STATE_ENTRY(SPR_SSWV, 0, 3, a_chase, S_SSWV_RUN3), /* S_SSWV_RUN2 */ - STATE_ENTRY(SPR_SSWV, 1, 3, a_chase, S_SSWV_RUN4), /* S_SSWV_RUN3 */ - STATE_ENTRY(SPR_SSWV, 1, 3, a_chase, S_SSWV_RUN5), /* S_SSWV_RUN4 */ - STATE_ENTRY(SPR_SSWV, 2, 3, a_chase, S_SSWV_RUN6), /* S_SSWV_RUN5 */ - STATE_ENTRY(SPR_SSWV, 2, 3, a_chase, S_SSWV_RUN7), /* S_SSWV_RUN6 */ - STATE_ENTRY(SPR_SSWV, 3, 3, a_chase, S_SSWV_RUN8), /* S_SSWV_RUN7 */ - STATE_ENTRY(SPR_SSWV, 3, 3, a_chase, S_SSWV_RUN1), /* S_SSWV_RUN8 */ - STATE_ENTRY(SPR_SSWV, 4, 10, a_face_target, - S_SSWV_ATK2), /* S_SSWV_ATK1 */ - STATE_ENTRY(SPR_SSWV, 5, 10, a_face_target, - S_SSWV_ATK3), /* S_SSWV_ATK2 */ - STATE_ENTRY(SPR_SSWV, 32774, 4, a_c_pos_attack, - S_SSWV_ATK4), /* S_SSWV_ATK3 */ - STATE_ENTRY(SPR_SSWV, 5, 6, a_face_target, S_SSWV_ATK5) , /* S_SSWV_ATK4 */ - STATE_ENTRY(SPR_SSWV, 32774, 4, a_c_pos_attack, - S_SSWV_ATK6), /* S_SSWV_ATK5 */ - STATE_ENTRY(SPR_SSWV, 5, 1, a_c_pos_refire, - S_SSWV_ATK2), /* S_SSWV_ATK6 */ - STATE_ENTRY(SPR_SSWV, 7, 3, NULL, S_SSWV_PAIN2), /* S_SSWV_PAIN */ - STATE_ENTRY(SPR_SSWV, 7, 3, a_pain, S_SSWV_RUN1), /* S_SSWV_PAIN2 */ - STATE_ENTRY(SPR_SSWV, 8, 5, NULL, S_SSWV_DIE2), /* S_SSWV_DIE1 */ - STATE_ENTRY(SPR_SSWV, 9, 5, a_scream, S_SSWV_DIE3), /* S_SSWV_DIE2 */ - STATE_ENTRY(SPR_SSWV, 10, 5, a_fall, S_SSWV_DIE4), /* S_SSWV_DIE3 */ - STATE_ENTRY(SPR_SSWV, 11, 5, NULL, S_SSWV_DIE5), /* S_SSWV_DIE4 */ - STATE_ENTRY(SPR_SSWV, 12, -1, NULL, S_NULL), /* S_SSWV_DIE5 */ - STATE_ENTRY(SPR_SSWV, 13, 5, NULL, S_SSWV_XDIE2), /* S_SSWV_XDIE1 */ - STATE_ENTRY(SPR_SSWV, 14, 5, a_xscream, S_SSWV_XDIE3), /* S_SSWV_XDIE2 */ - STATE_ENTRY(SPR_SSWV, 15, 5, a_fall, S_SSWV_XDIE4), /* S_SSWV_XDIE3 */ - STATE_ENTRY(SPR_SSWV, 16, 5, NULL, S_SSWV_XDIE5), /* S_SSWV_XDIE4 */ - STATE_ENTRY(SPR_SSWV, 17, 5, NULL, S_SSWV_XDIE6), /* S_SSWV_XDIE5 */ - STATE_ENTRY(SPR_SSWV, 18, 5, NULL, S_SSWV_XDIE7), /* S_SSWV_XDIE6 */ - STATE_ENTRY(SPR_SSWV, 19, 5, NULL, S_SSWV_XDIE8), /* S_SSWV_XDIE7 */ - STATE_ENTRY(SPR_SSWV, 20, 5, NULL, S_SSWV_XDIE9), /* S_SSWV_XDIE8 */ - STATE_ENTRY(SPR_SSWV, 21, -1, NULL, S_NULL), /* S_SSWV_XDIE9 */ - STATE_ENTRY(SPR_SSWV, 12, 5, NULL, S_SSWV_RAISE2), /* S_SSWV_RAISE1 */ - STATE_ENTRY(SPR_SSWV, 11, 5, NULL, S_SSWV_RAISE3), /* S_SSWV_RAISE2 */ - STATE_ENTRY(SPR_SSWV, 10, 5, NULL, S_SSWV_RAISE4), /* S_SSWV_RAISE3 */ - STATE_ENTRY(SPR_SSWV, 9, 5, NULL, S_SSWV_RAISE5), /* S_SSWV_RAISE4 */ - STATE_ENTRY(SPR_SSWV, 8, 5, NULL, S_SSWV_RUN1), /* S_SSWV_RAISE5 */ - STATE_ENTRY(SPR_KEEN, 0, -1, NULL, S_KEENSTND), /* S_KEENSTND */ - STATE_ENTRY(SPR_KEEN, 0, 6, NULL, S_COMMKEEN2), /* S_COMMKEEN */ - STATE_ENTRY(SPR_KEEN, 1, 6, NULL, S_COMMKEEN3), /* S_COMMKEEN2 */ - STATE_ENTRY(SPR_KEEN, 2, 6, a_scream, S_COMMKEEN4), /* S_COMMKEEN3 */ - STATE_ENTRY(SPR_KEEN, 3, 6, NULL, S_COMMKEEN5), /* S_COMMKEEN4 */ - STATE_ENTRY(SPR_KEEN, 4, 6, NULL, S_COMMKEEN6), /* S_COMMKEEN5 */ - STATE_ENTRY(SPR_KEEN, 5, 6, NULL, S_COMMKEEN7), /* S_COMMKEEN6 */ - STATE_ENTRY(SPR_KEEN, 6, 6, NULL, S_COMMKEEN8), /* S_COMMKEEN7 */ - STATE_ENTRY(SPR_KEEN, 7, 6, NULL, S_COMMKEEN9), /* S_COMMKEEN8 */ - STATE_ENTRY(SPR_KEEN, 8, 6, NULL, S_COMMKEEN10), /* S_COMMKEEN9 */ - STATE_ENTRY(SPR_KEEN, 9, 6, NULL, S_COMMKEEN11), /* S_COMMKEEN10 */ - STATE_ENTRY(SPR_KEEN, 10, 6, a_keen_die, S_COMMKEEN12), /* S_COMMKEEN11 */ - STATE_ENTRY(SPR_KEEN, 11, -1, NULL, S_NULL), /* S_COMMKEEN12 */ - STATE_ENTRY(SPR_KEEN, 12, 4, NULL, S_KEENPAIN2), /* S_KEENPAIN */ - STATE_ENTRY(SPR_KEEN, 12, 8, a_pain, S_KEENSTND), /* S_KEENPAIN2 */ - STATE_ENTRY(SPR_BBRN, 0, -1, NULL, S_NULL), /* S_BRAIN */ - STATE_ENTRY(SPR_BBRN, 1, 36, a_brain_pain, S_BRAIN), /* S_BRAIN_PAIN */ - STATE_ENTRY(SPR_BBRN, 0, 100, a_brain_scream, - S_BRAIN_DIE2), /* S_BRAIN_DIE1 */ - STATE_ENTRY(SPR_BBRN, 0, 10, NULL, S_BRAIN_DIE3), /* S_BRAIN_DIE2 */ - STATE_ENTRY(SPR_BBRN, 0, 10, NULL, S_BRAIN_DIE4), /* S_BRAIN_DIE3 */ - STATE_ENTRY(SPR_BBRN, 0, -1, a_brain_die, S_NULL), /* S_BRAIN_DIE4 */ - STATE_ENTRY(SPR_SSWV, 0, 10, a_look, S_BRAINEYE), /* S_BRAINEYE */ - STATE_ENTRY(SPR_SSWV, 0, 181, - a_brain_awake, S_BRAINEYE1), /* S_BRAINEYESEE */ - STATE_ENTRY(SPR_SSWV, 0, 150, - a_brain_split, S_BRAINEYE1), /* S_BRAINEYE1 */ - STATE_ENTRY(SPR_BOSF, 32768, 3, a_spawn_sound, S_SPAWN2), /* S_SPAWN1 */ - STATE_ENTRY(SPR_BOSF, 32769, 3, a_spawn_fly, S_SPAWN3), /* S_SPAWN2 */ - STATE_ENTRY(SPR_BOSF, 32770, 3, a_spawn_fly, S_SPAWN4), /* S_SPAWN3 */ - STATE_ENTRY(SPR_BOSF, 32771, 3, a_spawn_fly, S_SPAWN1), /* S_SPAWN4 */ - STATE_ENTRY(SPR_FIRE, 32768, 4, a_fire, S_SPAWNFIRE2), /* S_SPAWNFIRE1 */ - STATE_ENTRY(SPR_FIRE, 32769, 4, a_fire, S_SPAWNFIRE3), /* S_SPAWNFIRE2 */ - STATE_ENTRY(SPR_FIRE, 32770, 4, a_fire, S_SPAWNFIRE4), /* S_SPAWNFIRE3 */ - STATE_ENTRY(SPR_FIRE, 32771, 4, a_fire, S_SPAWNFIRE5), /* S_SPAWNFIRE4 */ - STATE_ENTRY(SPR_FIRE, 32772, 4, a_fire, S_SPAWNFIRE6), /* S_SPAWNFIRE5 */ - STATE_ENTRY(SPR_FIRE, 32773, 4, a_fire, S_SPAWNFIRE7), /* S_SPAWNFIRE6 */ - STATE_ENTRY(SPR_FIRE, 32774, 4, a_fire, S_SPAWNFIRE8), /* S_SPAWNFIRE7 */ - STATE_ENTRY(SPR_FIRE, 32775, 4, a_fire, S_NULL), /* S_SPAWNFIRE8 */ - STATE_ENTRY(SPR_MISL, 32769, 10, NULL, - S_BRAINEXPLODE2), /* S_BRAINEXPLODE1 */ - STATE_ENTRY(SPR_MISL, 32770, 10, NULL, - S_BRAINEXPLODE3), /* S_BRAINEXPLODE2 */ - STATE_ENTRY(SPR_MISL, 32771, 10, a_brain_explode, - S_NULL), /* S_BRAINEXPLODE3 */ - STATE_ENTRY(SPR_ARM1, 0, 6, NULL, S_ARM1A), /* S_ARM1 */ - STATE_ENTRY(SPR_ARM1, 32769, 7, NULL, S_ARM1), /* S_ARM1A */ - STATE_ENTRY(SPR_ARM2, 0, 6, NULL, S_ARM2A), /* S_ARM2 */ - STATE_ENTRY(SPR_ARM2, 32769, 6, NULL, S_ARM2), /* S_ARM2A */ - STATE_ENTRY(SPR_BAR1, 0, 6, NULL, S_BAR2), /* S_BAR1 */ - STATE_ENTRY(SPR_BAR1, 1, 6, NULL, S_BAR1), /* S_BAR2 */ - STATE_ENTRY(SPR_BEXP, 32768, 5, NULL, S_BEXP2), /* S_BEXP */ - STATE_ENTRY(SPR_BEXP, 32769, 5, a_scream, S_BEXP3), /* S_BEXP2 */ - STATE_ENTRY(SPR_BEXP, 32770, 5, NULL, S_BEXP4), /* S_BEXP3 */ - STATE_ENTRY(SPR_BEXP, 32771, 10, a_explode, S_BEXP5), /* S_BEXP4 */ - STATE_ENTRY(SPR_BEXP, 32772, 10, NULL, S_NULL), /* S_BEXP5 */ - STATE_ENTRY(SPR_FCAN, 32768, 4, NULL, S_BBAR2), /* S_BBAR1 */ - STATE_ENTRY(SPR_FCAN, 32769, 4, NULL, S_BBAR3), /* S_BBAR2 */ - STATE_ENTRY(SPR_FCAN, 32770, 4, NULL, S_BBAR1), /* S_BBAR3 */ - STATE_ENTRY(SPR_BON1, 0, 6, NULL, S_BON1A), /* S_BON1 */ - STATE_ENTRY(SPR_BON1, 1, 6, NULL, S_BON1B), /* S_BON1A */ - STATE_ENTRY(SPR_BON1, 2, 6, NULL, S_BON1C), /* S_BON1B */ - STATE_ENTRY(SPR_BON1, 3, 6, NULL, S_BON1D), /* S_BON1C */ - STATE_ENTRY(SPR_BON1, 2, 6, NULL, S_BON1E), /* S_BON1D */ - STATE_ENTRY(SPR_BON1, 1, 6, NULL, S_BON1), /* S_BON1E */ - STATE_ENTRY(SPR_BON2, 0, 6, NULL, S_BON2A), /* S_BON2 */ - STATE_ENTRY(SPR_BON2, 1, 6, NULL, S_BON2B), /* S_BON2A */ - STATE_ENTRY(SPR_BON2, 2, 6, NULL, S_BON2C), /* S_BON2B */ - STATE_ENTRY(SPR_BON2, 3, 6, NULL, S_BON2D), /* S_BON2C */ - STATE_ENTRY(SPR_BON2, 2, 6, NULL, S_BON2E), /* S_BON2D */ - STATE_ENTRY(SPR_BON2, 1, 6, NULL, S_BON2), /* S_BON2E */ - STATE_ENTRY(SPR_BKEY, 0, 10, NULL, S_BKEY2), /* S_BKEY */ - STATE_ENTRY(SPR_BKEY, 32769, 10, NULL, S_BKEY), /* S_BKEY2 */ - STATE_ENTRY(SPR_RKEY, 0, 10, NULL, S_RKEY2), /* S_RKEY */ - STATE_ENTRY(SPR_RKEY, 32769, 10, NULL, S_RKEY), /* S_RKEY2 */ - STATE_ENTRY(SPR_YKEY, 0, 10, NULL, S_YKEY2), /* S_YKEY */ - STATE_ENTRY(SPR_YKEY, 32769, 10, NULL, S_YKEY), /* S_YKEY2 */ - STATE_ENTRY(SPR_BSKU, 0, 10, NULL, S_BSKULL2), /* S_BSKULL */ - STATE_ENTRY(SPR_BSKU, 32769, 10, NULL, S_BSKULL), /* S_BSKULL2 */ - STATE_ENTRY(SPR_RSKU, 0, 10, NULL, S_RSKULL2), /* S_RSKULL */ - STATE_ENTRY(SPR_RSKU, 32769, 10, NULL, S_RSKULL), /* S_RSKULL2 */ - STATE_ENTRY(SPR_YSKU, 0, 10, NULL, S_YSKULL2), /* S_YSKULL */ - STATE_ENTRY(SPR_YSKU, 32769, 10, NULL, S_YSKULL), /* S_YSKULL2 */ - STATE_ENTRY(SPR_STIM, 0, -1, NULL, S_NULL), /* S_STIM */ - STATE_ENTRY(SPR_MEDI, 0, -1, NULL, S_NULL), /* S_MEDI */ - STATE_ENTRY(SPR_SOUL, 32768, 6, NULL, S_SOUL2), /* S_SOUL */ - STATE_ENTRY(SPR_SOUL, 32769, 6, NULL, S_SOUL3), /* S_SOUL2 */ - STATE_ENTRY(SPR_SOUL, 32770, 6, NULL, S_SOUL4), /* S_SOUL3 */ - STATE_ENTRY(SPR_SOUL, 32771, 6, NULL, S_SOUL5), /* S_SOUL4 */ - STATE_ENTRY(SPR_SOUL, 32770, 6, NULL, S_SOUL6), /* S_SOUL5 */ - STATE_ENTRY(SPR_SOUL, 32769, 6, NULL, S_SOUL), /* S_SOUL6 */ - STATE_ENTRY(SPR_PINV, 32768, 6, NULL, S_PINV2), /* S_PINV */ - STATE_ENTRY(SPR_PINV, 32769, 6, NULL, S_PINV3), /* S_PINV2 */ - STATE_ENTRY(SPR_PINV, 32770, 6, NULL, S_PINV4), /* S_PINV3 */ - STATE_ENTRY(SPR_PINV, 32771, 6, NULL, S_PINV), /* S_PINV4 */ - STATE_ENTRY(SPR_PSTR, 32768, -1, NULL, S_NULL), /* S_PSTR */ - STATE_ENTRY(SPR_PINS, 32768, 6, NULL, S_PINS2), /* S_PINS */ - STATE_ENTRY(SPR_PINS, 32769, 6, NULL, S_PINS3), /* S_PINS2 */ - STATE_ENTRY(SPR_PINS, 32770, 6, NULL, S_PINS4), /* S_PINS3 */ - STATE_ENTRY(SPR_PINS, 32771, 6, NULL, S_PINS), /* S_PINS4 */ - STATE_ENTRY(SPR_MEGA, 32768, 6, NULL, S_MEGA2), /* S_MEGA */ - STATE_ENTRY(SPR_MEGA, 32769, 6, NULL, S_MEGA3), /* S_MEGA2 */ - STATE_ENTRY(SPR_MEGA, 32770, 6, NULL, S_MEGA4), /* S_MEGA3 */ - STATE_ENTRY(SPR_MEGA, 32771, 6, NULL, S_MEGA), /* S_MEGA4 */ - STATE_ENTRY(SPR_SUIT, 32768, -1, NULL, S_NULL), /* S_SUIT */ - STATE_ENTRY(SPR_PMAP, 32768, 6, NULL, S_PMAP2), /* S_PMAP */ - STATE_ENTRY(SPR_PMAP, 32769, 6, NULL, S_PMAP3), /* S_PMAP2 */ - STATE_ENTRY(SPR_PMAP, 32770, 6, NULL, S_PMAP4), /* S_PMAP3 */ - STATE_ENTRY(SPR_PMAP, 32771, 6, NULL, S_PMAP5), /* S_PMAP4 */ - STATE_ENTRY(SPR_PMAP, 32770, 6, NULL, S_PMAP6), /* S_PMAP5 */ - STATE_ENTRY(SPR_PMAP, 32769, 6, NULL, S_PMAP), /* S_PMAP6 */ - STATE_ENTRY(SPR_PVIS, 32768, 6, NULL, S_PVIS2), /* S_PVIS */ - STATE_ENTRY(SPR_PVIS, 1, 6, NULL, S_PVIS), /* S_PVIS2 */ - STATE_ENTRY(SPR_CLIP, 0, -1, NULL, S_NULL), /* S_CLIP */ - STATE_ENTRY(SPR_AMMO, 0, -1, NULL, S_NULL), /* S_AMMO */ - STATE_ENTRY(SPR_ROCK, 0, -1, NULL, S_NULL), /* S_ROCK */ - STATE_ENTRY(SPR_BROK, 0, -1, NULL, S_NULL), /* S_BROK */ - STATE_ENTRY(SPR_CELL, 0, -1, NULL, S_NULL), /* S_CELL */ - STATE_ENTRY(SPR_CELP, 0, -1, NULL, S_NULL), /* S_CELP */ - STATE_ENTRY(SPR_SHEL, 0, -1, NULL, S_NULL), /* S_SHEL */ - STATE_ENTRY(SPR_SBOX, 0, -1, NULL, S_NULL), /* S_SBOX */ - STATE_ENTRY(SPR_BPAK, 0, -1, NULL, S_NULL), /* S_BPAK */ - STATE_ENTRY(SPR_BFUG, 0, -1, NULL, S_NULL), /* S_BFUG */ - STATE_ENTRY(SPR_MGUN, 0, -1, NULL, S_NULL), /* S_MGUN */ - STATE_ENTRY(SPR_CSAW, 0, -1, NULL, S_NULL), /* S_CSAW */ - STATE_ENTRY(SPR_LAUN, 0, -1, NULL, S_NULL), /* S_LAUN */ - STATE_ENTRY(SPR_PLAS, 0, -1, NULL, S_NULL), /* S_PLAS */ - STATE_ENTRY(SPR_SHOT, 0, -1, NULL, S_NULL), /* S_SHOT */ - STATE_ENTRY(SPR_SGN2, 0, -1, NULL, S_NULL), /* S_SHOT2 */ - STATE_ENTRY(SPR_COLU, 32768, -1, NULL, S_NULL), /* S_COLU */ - STATE_ENTRY(SPR_SMT2, 0, -1, NULL, S_NULL), /* S_STALAG */ - STATE_ENTRY(SPR_GOR1, 0, 10, NULL, S_BLOODYTWITCH2), /* S_BLOODYTWITCH */ - STATE_ENTRY(SPR_GOR1, 1, 15, NULL, S_BLOODYTWITCH3), /* S_BLOODYTWITCH2 */ - STATE_ENTRY(SPR_GOR1, 2, 8, NULL, S_BLOODYTWITCH4), /* S_BLOODYTWITCH3 */ - STATE_ENTRY(SPR_GOR1, 1, 6, NULL, S_BLOODYTWITCH), /* S_BLOODYTWITCH4 */ - STATE_ENTRY(SPR_PLAY, 13, -1, NULL, S_NULL), /* S_DEADTORSO */ - STATE_ENTRY(SPR_PLAY, 18, -1, NULL, S_NULL), /* S_DEADBOTTOM */ - STATE_ENTRY(SPR_POL2, 0, -1, NULL, S_NULL), /* S_HEADSONSTICK */ - STATE_ENTRY(SPR_POL5, 0, -1, NULL, S_NULL), /* S_GIBS */ - STATE_ENTRY(SPR_POL4, 0, -1, NULL, S_NULL), /* S_HEADONASTICK */ - STATE_ENTRY(SPR_POL3, 32768, 6, NULL, S_HEADCANDLES2), /* S_HEADCANDLES */ - STATE_ENTRY(SPR_POL3, 32769, 6, NULL, S_HEADCANDLES), /* S_HEADCANDLES2 */ - STATE_ENTRY(SPR_POL1, 0, -1, NULL, S_NULL), /* S_DEADSTICK */ - STATE_ENTRY(SPR_POL6, 0, 6, NULL, S_LIVESTICK2), /* S_LIVESTICK */ - STATE_ENTRY(SPR_POL6, 1, 8, NULL, S_LIVESTICK), /* S_LIVESTICK2 */ - STATE_ENTRY(SPR_GOR2, 0, -1, NULL, S_NULL), /* S_MEAT2 */ - STATE_ENTRY(SPR_GOR3, 0, -1, NULL, S_NULL), /* S_MEAT3 */ - STATE_ENTRY(SPR_GOR4, 0, -1, NULL, S_NULL), /* S_MEAT4 */ - STATE_ENTRY(SPR_GOR5, 0, -1, NULL, S_NULL), /* S_MEAT5 */ - STATE_ENTRY(SPR_SMIT, 0, -1, NULL, S_NULL), /* S_STALAGTITE */ - STATE_ENTRY(SPR_COL1, 0, -1, NULL, S_NULL), /* S_TALLGRNCOL */ - STATE_ENTRY(SPR_COL2, 0, -1, NULL, S_NULL), /* S_SHRTGRNCOL */ - STATE_ENTRY(SPR_COL3, 0, -1, NULL, S_NULL), /* S_TALLREDCOL */ - STATE_ENTRY(SPR_COL4, 0, -1, NULL, S_NULL), /* S_SHRTREDCOL */ - STATE_ENTRY(SPR_CAND, 32768, -1, NULL, S_NULL), /* S_CANDLESTIK */ - STATE_ENTRY(SPR_CBRA, 32768, -1, NULL, S_NULL), /* S_CANDELABRA */ - STATE_ENTRY(SPR_COL6, 0, -1, NULL, S_NULL), /* S_SKULLCOL */ - STATE_ENTRY(SPR_TRE1, 0, -1, NULL, S_NULL), /* S_TORCHTREE */ - STATE_ENTRY(SPR_TRE2, 0, -1, NULL, S_NULL), /* S_BIGTREE */ - STATE_ENTRY(SPR_ELEC, 0, -1, NULL, S_NULL), /* S_TECHPILLAR */ - STATE_ENTRY(SPR_CEYE, 32768, 6, NULL, S_EVILEYE2), /* S_EVILEYE */ - STATE_ENTRY(SPR_CEYE, 32769, 6, NULL, S_EVILEYE3), /* S_EVILEYE2 */ - STATE_ENTRY(SPR_CEYE, 32770, 6, NULL, S_EVILEYE4), /* S_EVILEYE3 */ - STATE_ENTRY(SPR_CEYE, 32769, 6, NULL, S_EVILEYE), /* S_EVILEYE4 */ - STATE_ENTRY(SPR_FSKU, 32768, 6, NULL, S_FLOATSKULL2), /* S_FLOATSKULL */ - STATE_ENTRY(SPR_FSKU, 32769, 6, NULL, S_FLOATSKULL3), /* S_FLOATSKULL2 */ - STATE_ENTRY(SPR_FSKU, 32770, 6, NULL, S_FLOATSKULL), /* S_FLOATSKULL3 */ - STATE_ENTRY(SPR_COL5, 0, 14, NULL, S_HEARTCOL2), /* S_HEARTCOL */ - STATE_ENTRY(SPR_COL5, 1, 14, NULL, S_HEARTCOL), /* S_HEARTCOL2 */ - STATE_ENTRY(SPR_TBLU, 32768, 4, NULL, S_BLUETORCH2), /* S_BLUETORCH */ - STATE_ENTRY(SPR_TBLU, 32769, 4, NULL, S_BLUETORCH3), /* S_BLUETORCH2 */ - STATE_ENTRY(SPR_TBLU, 32770, 4, NULL, S_BLUETORCH4), /* S_BLUETORCH3 */ - STATE_ENTRY(SPR_TBLU, 32771, 4, NULL, S_BLUETORCH), /* S_BLUETORCH4 */ - STATE_ENTRY(SPR_TGRN, 32768, 4, NULL, S_GREENTORCH2), /* S_GREENTORCH */ - STATE_ENTRY(SPR_TGRN, 32769, 4, NULL, S_GREENTORCH3), /* S_GREENTORCH2 */ - STATE_ENTRY(SPR_TGRN, 32770, 4, NULL, S_GREENTORCH4), /* S_GREENTORCH3 */ - STATE_ENTRY(SPR_TGRN, 32771, 4, NULL, S_GREENTORCH), /* S_GREENTORCH4 */ - STATE_ENTRY(SPR_TRED, 32768, 4, NULL, S_REDTORCH2), /* S_REDTORCH */ - STATE_ENTRY(SPR_TRED, 32769, 4, NULL, S_REDTORCH3), /* S_REDTORCH2 */ - STATE_ENTRY(SPR_TRED, 32770, 4, NULL, S_REDTORCH4), /* S_REDTORCH3 */ - STATE_ENTRY(SPR_TRED, 32771, 4, NULL, S_REDTORCH), /* S_REDTORCH4 */ - STATE_ENTRY(SPR_SMBT, 32768, 4, NULL, S_BTORCHSHRT2), /* S_BTORCHSHRT */ - STATE_ENTRY(SPR_SMBT, 32769, 4, NULL, S_BTORCHSHRT3), /* S_BTORCHSHRT2 */ - STATE_ENTRY(SPR_SMBT, 32770, 4, NULL, S_BTORCHSHRT4), /* S_BTORCHSHRT3 */ - STATE_ENTRY(SPR_SMBT, 32771, 4, NULL, S_BTORCHSHRT), /* S_BTORCHSHRT4 */ - STATE_ENTRY(SPR_SMGT, 32768, 4, NULL, S_GTORCHSHRT2), /* S_GTORCHSHRT */ - STATE_ENTRY(SPR_SMGT, 32769, 4, NULL, S_GTORCHSHRT3), /* S_GTORCHSHRT2 */ - STATE_ENTRY(SPR_SMGT, 32770, 4, NULL, S_GTORCHSHRT4), /* S_GTORCHSHRT3 */ - STATE_ENTRY(SPR_SMGT, 32771, 4, NULL, S_GTORCHSHRT), /* S_GTORCHSHRT4 */ - STATE_ENTRY(SPR_SMRT, 32768, 4, NULL, S_RTORCHSHRT2), /* S_RTORCHSHRT */ - STATE_ENTRY(SPR_SMRT, 32769, 4, NULL, S_RTORCHSHRT3), /* S_RTORCHSHRT2 */ - STATE_ENTRY(SPR_SMRT, 32770, 4, NULL, S_RTORCHSHRT4), /* S_RTORCHSHRT3 */ - STATE_ENTRY(SPR_SMRT, 32771, 4, NULL, S_RTORCHSHRT), /* S_RTORCHSHRT4 */ - STATE_ENTRY(SPR_HDB1, 0, -1, NULL, S_NULL), /* S_HANGNOGUTS */ - STATE_ENTRY(SPR_HDB2, 0, -1, NULL, S_NULL), /* S_HANGBNOBRAIN */ - STATE_ENTRY(SPR_HDB3, 0, -1, NULL, S_NULL), /* S_HANGTLOOKDN */ - STATE_ENTRY(SPR_HDB4, 0, -1, NULL, S_NULL), /* S_HANGTSKULL */ - STATE_ENTRY(SPR_HDB5, 0, -1, NULL, S_NULL), /* S_HANGTLOOKUP */ - STATE_ENTRY(SPR_HDB6, 0, -1, NULL, S_NULL), /* S_HANGTNOBRAIN */ - STATE_ENTRY(SPR_POB1, 0, -1, NULL, S_NULL), /* S_COLONGIBS */ - STATE_ENTRY(SPR_POB2, 0, -1, NULL, S_NULL), /* S_SMALLPOOL */ - STATE_ENTRY(SPR_BRS1, 0, -1, NULL, S_NULL), /* S_BRAINSTEM */ - STATE_ENTRY(SPR_TLMP, 32768, 4, NULL, S_TECHLAMP2), /* S_TECHLAMP */ - STATE_ENTRY(SPR_TLMP, 32769, 4, NULL, S_TECHLAMP3), /* S_TECHLAMP2 */ - STATE_ENTRY(SPR_TLMP, 32770, 4, NULL, S_TECHLAMP4), /* S_TECHLAMP3 */ - STATE_ENTRY(SPR_TLMP, 32771, 4, NULL, S_TECHLAMP), /* S_TECHLAMP4 */ - STATE_ENTRY(SPR_TLP2, 32768, 4, NULL, S_TECH2LAMP2), /* S_TECH2LAMP */ - STATE_ENTRY(SPR_TLP2, 32769, 4, NULL, S_TECH2LAMP3), /* S_TECH2LAMP2 */ - STATE_ENTRY(SPR_TLP2, 32770, 4, NULL, S_TECH2LAMP4), /* S_TECH2LAMP3 */ - STATE_ENTRY(SPR_TLP2, 32771, 4, NULL, S_TECH2LAMP) /* S_TECH2LAMP4 */ -}; - -mobjinfo_t mobjinfo[NUMMOBJTYPES] = -{ - { - /* MT_PLAYER */ - - .doomednum = -1, - .spawnstate = S_PLAY, - .spawnhealth = 100, - .seestate = S_PLAY_RUN1, - .reactiontime = 0, - .painstate = S_PLAY_PAIN, - .painchance = 255, - .meleestate = S_NULL, - .missilestate = S_PLAY_ATK1, - .deathstate = S_PLAY_DIE1, - .xdeathstate = S_PLAY_XDIE1, - .speed = 0, - .radius = 16 * FRACUNIT, - .height = 56 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SOLID | MF_SHOOTABLE | MF_DROPOFF | - MF_PICKUP | MF_NOTDMATCH, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_PLPAIN, - .deathsound = SFX_PLDETH, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_POSSESSED */ - - .doomednum = 3004, - .spawnstate = S_POSS_STND, - .spawnhealth = 20, - .seestate = S_POSS_RUN1, - .reactiontime = 8, - .painstate = S_POSS_PAIN, - .painchance = 200, - .meleestate = 0, - .missilestate = S_POSS_ATK1, - .deathstate = S_POSS_DIE1, - .xdeathstate = S_POSS_XDIE1, - .speed = 8, - .radius = 20 * FRACUNIT, - .height = 56 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SOLID | MF_SHOOTABLE | MF_COUNTKILL, - .raisestate = S_POSS_RAISE1, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_PISTOL, - .painsound = SFX_POPAIN, - .deathsound = SFX_PODTH1, - .activesound = SFX_POSACT, - .seesound = SFX_POSIT1, -#endif - }, - - { - /* MT_SHOTGUY */ - - .doomednum = 9, - .spawnstate = S_SPOS_STND, - .spawnhealth = 30, - .seestate = S_SPOS_RUN1, - .reactiontime = 8, - .painstate = S_SPOS_PAIN, - .painchance = 170, - .meleestate = 0, - .missilestate = S_SPOS_ATK1, - .deathstate = S_SPOS_DIE1, - .xdeathstate = S_SPOS_XDIE1, - .speed = 8, - .radius = 20 * FRACUNIT, - .height = 56 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SOLID | MF_SHOOTABLE | MF_COUNTKILL, - .raisestate = S_SPOS_RAISE1, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = 0, - .painsound = SFX_POPAIN, - .deathsound = SFX_PODTH2, - .activesound = SFX_POSACT, - .seesound = SFX_POSIT2, -#endif - }, - - { - /* MT_VILE */ - - .doomednum = 64, - .spawnstate = S_VILE_STND, - .spawnhealth = 700, - .seestate = S_VILE_RUN1, - .reactiontime = 8, - .painstate = S_VILE_PAIN, - .painchance = 10, - .meleestate = 0, - .missilestate = S_VILE_ATK1, - .deathstate = S_VILE_DIE1, - .xdeathstate = S_NULL, - .speed = 15, - .radius = 20 * FRACUNIT, - .height = 56 * FRACUNIT, - .mass = 500, - .damage = 0, - .flags = MF_SOLID | MF_SHOOTABLE | MF_COUNTKILL, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = 0, - .painsound = SFX_VIPAIN, - .deathsound = SFX_VILDTH, - .activesound = SFX_VILACT, - .seesound = SFX_VILSIT, -#endif - }, - - { - /* MT_FIRE */ - - .doomednum = -1, - .spawnstate = S_FIRE1, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 20 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_NOBLOCKMAP | MF_NOGRAVITY, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_UNDEAD */ - - .doomednum = 66, - .spawnstate = S_SKEL_STND, - .spawnhealth = 300, - .seestate = S_SKEL_RUN1, - .reactiontime = 8, - .painstate = S_SKEL_PAIN, - .painchance = 100, - .meleestate = S_SKEL_FIST1, - .missilestate = S_SKEL_MISS1, - .deathstate = S_SKEL_DIE1, - .xdeathstate = S_NULL, - .speed = 10, - .radius = 20 * FRACUNIT, - .height = 56 * FRACUNIT, - .mass = 500, - .damage = 0, - .flags = MF_SOLID | MF_SHOOTABLE | MF_COUNTKILL, - .raisestate = S_SKEL_RAISE1, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = 0, - .painsound = SFX_POPAIN, - .deathsound = SFX_SKEDTH, - .activesound = SFX_SKEACT, - .seesound = SFX_SKESIT, -#endif - }, - - { - /* MT_TRACER */ - - .doomednum = -1, - .spawnstate = S_TRACER, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_TRACEEXP1, - .xdeathstate = S_NULL, - .speed = 10 * FRACUNIT, - .radius = 11 * FRACUNIT, - .height = 8 * FRACUNIT, - .mass = 100, - .damage = 10, - .flags = MF_NOBLOCKMAP | MF_MISSILE | MF_DROPOFF | MF_NOGRAVITY, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_BAREXP, - .activesound = SFX_NONE, - .seesound = SFX_SKEATK, -#endif - }, - - { - /* MT_SMOKE */ - - .doomednum = -1, - .spawnstate = S_SMOKE1, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 20 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_NOBLOCKMAP | MF_NOGRAVITY, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_FATSO */ - - .doomednum = 67, - .spawnstate = S_FATT_STND, - .spawnhealth = 600, - .seestate = S_FATT_RUN1, - .reactiontime = 8, - .painstate = S_FATT_PAIN, - .painchance = 80, - .meleestate = 0, - .missilestate = S_FATT_ATK1, - .deathstate = S_FATT_DIE1, - .xdeathstate = S_NULL, - .speed = 8, - .radius = 48 * FRACUNIT, - .height = 64 * FRACUNIT, - .mass = 1000, - .damage = 0, - .flags = MF_SOLID | MF_SHOOTABLE | MF_COUNTKILL, - .raisestate = S_FATT_RAISE1, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = 0, - .painsound = SFX_MNPAIN, - .deathsound = SFX_MANDTH, - .activesound = SFX_POSACT, - .seesound = SFX_MANSIT, -#endif - }, - - { - /* MT_FATSHOT */ - - .doomednum = -1, - .spawnstate = S_FATSHOT1, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_FATSHOTX1, - .xdeathstate = S_NULL, - .speed = 20 * FRACUNIT, - .radius = 6 * FRACUNIT, - .height = 8 * FRACUNIT, - .mass = 100, - .damage = 8, - .flags = MF_NOBLOCKMAP | MF_MISSILE | MF_DROPOFF | MF_NOGRAVITY, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_FIRXPL, - .activesound = SFX_NONE, - .seesound = SFX_FIRSHT, -#endif - }, - - { - /* MT_CHAINGUY */ - - .doomednum = 65, - .spawnstate = S_CPOS_STND, - .spawnhealth = 70, - .seestate = S_CPOS_RUN1, - .reactiontime = 8, - .painstate = S_CPOS_PAIN, - .painchance = 170, - .meleestate = 0, - .missilestate = S_CPOS_ATK1, - .deathstate = S_CPOS_DIE1, - .xdeathstate = S_CPOS_XDIE1, - .speed = 8, - .radius = 20 * FRACUNIT, - .height = 56 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SOLID | MF_SHOOTABLE | MF_COUNTKILL, - .raisestate = S_CPOS_RAISE1, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = 0, - .painsound = SFX_POPAIN, - .deathsound = SFX_PODTH2, - .activesound = SFX_POSACT, - .seesound = SFX_POSIT2, -#endif - }, - - { - /* MT_TROOP */ - - .doomednum = 3001, - .spawnstate = S_TROO_STND, - .spawnhealth = 60, - .seestate = S_TROO_RUN1, - .reactiontime = 8, - .painstate = S_TROO_PAIN, - .painchance = 200, - .meleestate = S_TROO_ATK1, - .missilestate = S_TROO_ATK1, - .deathstate = S_TROO_DIE1, - .xdeathstate = S_TROO_XDIE1, - .speed = 8, - .radius = 20 * FRACUNIT, - .height = 56 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SOLID | MF_SHOOTABLE | MF_COUNTKILL, - .raisestate = S_TROO_RAISE1, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = 0, - .painsound = SFX_POPAIN, - .deathsound = SFX_BGDTH1, - .activesound = SFX_BGACT, - .seesound = SFX_BGSIT1, -#endif - }, - - { - /* MT_SERGEANT */ - - .doomednum = 3002, - .spawnstate = S_SARG_STND, - .spawnhealth = 150, - .seestate = S_SARG_RUN1, - .reactiontime = 8, - .painstate = S_SARG_PAIN, - .painchance = 180, - .meleestate = S_SARG_ATK1, - .missilestate = 0, - .deathstate = S_SARG_DIE1, - .xdeathstate = S_NULL, - .speed = 10, - .radius = 30 * FRACUNIT, - .height = 56 * FRACUNIT, - .mass = 400, - .damage = 0, - .flags = MF_SOLID | MF_SHOOTABLE | MF_COUNTKILL, - .raisestate = S_SARG_RAISE1, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_SGTATK, - .painsound = SFX_DMPAIN, - .deathsound = SFX_SGTDTH, - .activesound = SFX_DMACT, - .seesound = SFX_SGTSIT, -#endif - }, - - { - /* MT_SHADOWS */ - - .doomednum = 58, - .spawnstate = S_SARG_STND, - .spawnhealth = 150, - .seestate = S_SARG_RUN1, - .reactiontime = 8, - .painstate = S_SARG_PAIN, - .painchance = 180, - .meleestate = S_SARG_ATK1, - .missilestate = 0, - .deathstate = S_SARG_DIE1, - .xdeathstate = S_NULL, - .speed = 10, - .radius = 30 * FRACUNIT, - .height = 56 * FRACUNIT, - .mass = 400, - .damage = 0, - .flags = MF_SOLID | MF_SHOOTABLE | MF_SHADOW | MF_COUNTKILL, - .raisestate = S_SARG_RAISE1, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_SGTATK, - .painsound = SFX_DMPAIN, - .deathsound = SFX_SGTDTH, - .activesound = SFX_DMACT, - .seesound = SFX_SGTSIT, -#endif - }, - - { - /* MT_HEAD */ - - .doomednum = 3005, - .spawnstate = S_HEAD_STND, - .spawnhealth = 400, - .seestate = S_HEAD_RUN1, - .reactiontime = 8, - .painstate = S_HEAD_PAIN, - .painchance = 128, - .meleestate = 0, - .missilestate = S_HEAD_ATK1, - .deathstate = S_HEAD_DIE1, - .xdeathstate = S_NULL, - .speed = 8, - .radius = 31 * FRACUNIT, - .height = 56 * FRACUNIT, - .mass = 400, - .damage = 0, - .flags = MF_SOLID | MF_SHOOTABLE | MF_FLOAT | - MF_NOGRAVITY | MF_COUNTKILL, - .raisestate = S_HEAD_RAISE1, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = 0, - .painsound = SFX_DMPAIN, - .deathsound = SFX_CACDTH, - .activesound = SFX_DMACT, - .seesound = SFX_CACSIT, -#endif - }, - - { - /* MT_BRUISER */ - - .doomednum = 3003, - .spawnstate = S_BOSS_STND, - .spawnhealth = 1000, - .seestate = S_BOSS_RUN1, - .reactiontime = 8, - .painstate = S_BOSS_PAIN, - .painchance = 50, - .meleestate = S_BOSS_ATK1, - .missilestate = S_BOSS_ATK1, - .deathstate = S_BOSS_DIE1, - .xdeathstate = S_NULL, - .speed = 8, - .radius = 24 * FRACUNIT, - .height = 64 * FRACUNIT, - .mass = 1000, - .damage = 0, - .flags = MF_SOLID | MF_SHOOTABLE | MF_COUNTKILL, - .raisestate = S_BOSS_RAISE1, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = 0, - .painsound = SFX_DMPAIN, - .deathsound = SFX_BRSDTH, - .activesound = SFX_DMACT, - .seesound = SFX_BRSSIT, -#endif - }, - - { - /* MT_BRUISERSHOT */ - - .doomednum = -1, - .spawnstate = S_BRBALL1, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_BRBALLX1, - .xdeathstate = S_NULL, - .speed = 15 * FRACUNIT, - .radius = 6 * FRACUNIT, - .height = 8 * FRACUNIT, - .mass = 100, - .damage = 8, - .flags = MF_NOBLOCKMAP | MF_MISSILE | MF_DROPOFF | MF_NOGRAVITY, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_FIRXPL, - .activesound = SFX_NONE, - .seesound = SFX_FIRSHT, -#endif - }, - - { - /* MT_KNIGHT */ - - .doomednum = 69, - .spawnstate = S_BOS2_STND, - .spawnhealth = 500, - .seestate = S_BOS2_RUN1, - .reactiontime = 8, - .painstate = S_BOS2_PAIN, - .painchance = 50, - .meleestate = S_BOS2_ATK1, - .missilestate = S_BOS2_ATK1, - .deathstate = S_BOS2_DIE1, - .xdeathstate = S_NULL, - .speed = 8, - .radius = 24 * FRACUNIT, - .height = 64 * FRACUNIT, - .mass = 1000, - .damage = 0, - .flags = MF_SOLID | MF_SHOOTABLE | MF_COUNTKILL, - .raisestate = S_BOS2_RAISE1, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = 0, - .painsound = SFX_DMPAIN, - .deathsound = SFX_KNTDTH, - .activesound = SFX_DMACT, - .seesound = SFX_KNTSIT, -#endif - }, - - { - /* MT_SKULL */ - - .doomednum = 3006, - .spawnstate = S_SKULL_STND, - .spawnhealth = 100, - .seestate = S_SKULL_RUN1, - .reactiontime = 8, - .painstate = S_SKULL_PAIN, - .painchance = 256, - .meleestate = 0, - .missilestate = S_SKULL_ATK1, - .deathstate = S_SKULL_DIE1, - .xdeathstate = S_NULL, - .speed = 8, - .radius = 16 * FRACUNIT, - .height = 56 * FRACUNIT, - .mass = 50, - .damage = 3, - .flags = MF_SOLID | MF_SHOOTABLE | MF_FLOAT | MF_NOGRAVITY, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_SKLATK, - .painsound = SFX_DMPAIN, - .deathsound = SFX_FIRXPL, - .activesound = SFX_DMACT, - .seesound = 0, -#endif - }, - - { - /* MT_SPIDER */ - - .doomednum = 7, - .spawnstate = S_SPID_STND, - .spawnhealth = 3000, - .seestate = S_SPID_RUN1, - .reactiontime = 8, - .painstate = S_SPID_PAIN, - .painchance = 40, - .meleestate = 0, - .missilestate = S_SPID_ATK1, - .deathstate = S_SPID_DIE1, - .xdeathstate = S_NULL, - .speed = 12, - .radius = 128 * FRACUNIT, - .height = 100 * FRACUNIT, - .mass = 1000, - .damage = 0, - .flags = MF_SOLID | MF_SHOOTABLE | MF_COUNTKILL, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_SHOTGN, - .painsound = SFX_DMPAIN, - .deathsound = SFX_SPIDTH, - .activesound = SFX_DMACT, - .seesound = SFX_SPISIT, -#endif - }, - - { - /* MT_BABY */ - - .doomednum = 68, - .spawnstate = S_BSPI_STND, - .spawnhealth = 500, - .seestate = S_BSPI_SIGHT, - .reactiontime = 8, - .painstate = S_BSPI_PAIN, - .painchance = 128, - .meleestate = 0, - .missilestate = S_BSPI_ATK1, - .deathstate = S_BSPI_DIE1, - .xdeathstate = S_NULL, - .speed = 12, - .radius = 64 * FRACUNIT, - .height = 64 * FRACUNIT, - .mass = 600, - .damage = 0, - .flags = MF_SOLID | MF_SHOOTABLE | MF_COUNTKILL, - .raisestate = S_BSPI_RAISE1, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = 0, - .painsound = SFX_DMPAIN, - .deathsound = SFX_BSPDTH, - .activesound = SFX_BSPACT, - .seesound = SFX_BSPSIT, -#endif - }, - - { - /* MT_CYBORG */ - - .doomednum = 16, - .spawnstate = S_CYBER_STND, - .spawnhealth = 4000, - .seestate = S_CYBER_RUN1, - .reactiontime = 8, - .painstate = S_CYBER_PAIN, - .painchance = 20, - .meleestate = 0, - .missilestate = S_CYBER_ATK1, - .deathstate = S_CYBER_DIE1, - .xdeathstate = S_NULL, - .speed = 16, - .radius = 40 * FRACUNIT, - .height = 110 * FRACUNIT, - .mass = 1000, - .damage = 0, - .flags = MF_SOLID | MF_SHOOTABLE | MF_COUNTKILL, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = 0, - .painsound = SFX_DMPAIN, - .deathsound = SFX_CYBDTH, - .activesound = SFX_DMACT, - .seesound = SFX_CYBSIT, -#endif - }, - - { - /* MT_PAIN */ - - .doomednum = 71, - .spawnstate = S_PAIN_STND, - .spawnhealth = 400, - .seestate = S_PAIN_RUN1, - .reactiontime = 8, - .painstate = S_PAIN_PAIN, - .painchance = 128, - .meleestate = 0, - .missilestate = S_PAIN_ATK1, - .deathstate = S_PAIN_DIE1, - .xdeathstate = S_NULL, - .speed = 8, - .radius = 31 * FRACUNIT, - .height = 56 * FRACUNIT, - .mass = 400, - .damage = 0, - .flags = MF_SOLID | MF_SHOOTABLE | MF_FLOAT | - MF_NOGRAVITY | MF_COUNTKILL, - .raisestate = S_PAIN_RAISE1, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = 0, - .painsound = SFX_PEPAIN, - .deathsound = SFX_PEDTH, - .activesound = SFX_DMACT, - .seesound = SFX_PESIT, -#endif - }, - - { - /* MT_WOLFSS */ - - .doomednum = 84, - .spawnstate = S_SSWV_STND, - .spawnhealth = 50, - .seestate = S_SSWV_RUN1, - .reactiontime = 8, - .painstate = S_SSWV_PAIN, - .painchance = 170, - .meleestate = 0, - .missilestate = S_SSWV_ATK1, - .deathstate = S_SSWV_DIE1, - .xdeathstate = S_SSWV_XDIE1, - .speed = 8, - .radius = 20 * FRACUNIT, - .height = 56 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SOLID | MF_SHOOTABLE | MF_COUNTKILL, - .raisestate = S_SSWV_RAISE1, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = 0, - .painsound = SFX_POPAIN, - .deathsound = SFX_SSDTH, - .activesound = SFX_POSACT, - .seesound = SFX_SSSIT, -#endif - }, - - { - /* MT_KEEN */ - - .doomednum = 72, - .spawnstate = S_KEENSTND, - .spawnhealth = 100, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_KEENPAIN, - .painchance = 256, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_COMMKEEN, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 16 * FRACUNIT, - .height = 72 * FRACUNIT, - .mass = 10000000, - .damage = 0, - .flags = MF_SOLID | MF_SPAWNCEILING | MF_NOGRAVITY | - MF_SHOOTABLE | MF_COUNTKILL, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_KEENPN, - .deathsound = SFX_KEENDT, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_BOSSBRAIN */ - - .doomednum = 88, - .spawnstate = S_BRAIN, - .spawnhealth = 250, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_BRAIN_PAIN, - .painchance = 255, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_BRAIN_DIE1, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 16 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 10000000, - .damage = 0, - .flags = MF_SOLID | MF_SHOOTABLE, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_BOSPN, - .deathsound = SFX_BOSDTH, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_BOSSSPIT */ - - .doomednum = 89, - .spawnstate = S_BRAINEYE, - .spawnhealth = 1000, - .seestate = S_BRAINEYESEE, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 20 * FRACUNIT, - .height = 32 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_NOBLOCKMAP | MF_NOSECTOR, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_BOSSTARGET */ - - .doomednum = 87, - .spawnstate = S_NULL, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 20 * FRACUNIT, - .height = 32 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_NOBLOCKMAP | MF_NOSECTOR, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_SPAWNSHOT */ - - .doomednum = -1, - .spawnstate = S_SPAWN1, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 10 * FRACUNIT, - .radius = 6 * FRACUNIT, - .height = 32 * FRACUNIT, - .mass = 100, - .damage = 3, - .flags = MF_NOBLOCKMAP | MF_MISSILE | MF_DROPOFF | - MF_NOGRAVITY | MF_NOCLIP, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_FIRXPL, - .activesound = SFX_NONE, - .seesound = SFX_BOSPIT, -#endif - }, - - { - /* MT_SPAWNFIRE */ - - .doomednum = -1, - .spawnstate = S_SPAWNFIRE1, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 20 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_NOBLOCKMAP | MF_NOGRAVITY, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_BARREL */ - - .doomednum = 2035, - .spawnstate = S_BAR1, - .spawnhealth = 20, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_BEXP, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 10 * FRACUNIT, - .height = 42 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SOLID | MF_SHOOTABLE | MF_NOBLOOD, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_BAREXP, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_TROOPSHOT */ - - .doomednum = -1, - .spawnstate = S_TBALL1, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_TBALLX1, - .xdeathstate = S_NULL, - .speed = 10 * FRACUNIT, - .radius = 6 * FRACUNIT, - .height = 8 * FRACUNIT, - .mass = 100, - .damage = 3, - .flags = MF_NOBLOCKMAP | MF_MISSILE | MF_DROPOFF | MF_NOGRAVITY, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_FIRXPL, - .activesound = SFX_NONE, - .seesound = SFX_FIRSHT, -#endif - }, - - { - /* MT_HEADSHOT */ - - .doomednum = -1, - .spawnstate = S_RBALL1, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_RBALLX1, - .xdeathstate = S_NULL, - .speed = 10 * FRACUNIT, - .radius = 6 * FRACUNIT, - .height = 8 * FRACUNIT, - .mass = 100, - .damage = 5, - .flags = MF_NOBLOCKMAP | MF_MISSILE | MF_DROPOFF | MF_NOGRAVITY, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_FIRXPL, - .activesound = SFX_NONE, - .seesound = SFX_FIRSHT, -#endif - }, - - { - /* MT_ROCKET */ - - .doomednum = -1, - .spawnstate = S_ROCKET, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_EXPLODE1, - .xdeathstate = S_NULL, - .speed = 20 * FRACUNIT, - .radius = 11 * FRACUNIT, - .height = 8 * FRACUNIT, - .mass = 100, - .damage = 20, - .flags = MF_NOBLOCKMAP | MF_MISSILE | MF_DROPOFF | MF_NOGRAVITY, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_BAREXP, - .activesound = SFX_NONE, - .seesound = SFX_RLAUNC, -#endif - }, - - { - /* MT_PLASMA */ - - .doomednum = -1, - .spawnstate = S_PLASBALL, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_PLASEXP, - .xdeathstate = S_NULL, - .speed = 25 * FRACUNIT, - .radius = 13 * FRACUNIT, - .height = 8 * FRACUNIT, - .mass = 100, - .damage = 5, - .flags = MF_NOBLOCKMAP | MF_MISSILE | MF_DROPOFF | MF_NOGRAVITY, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_FIRXPL, - .activesound = SFX_NONE, - .seesound = SFX_PLASMA, -#endif - }, - - { - /* MT_BFG */ - - .doomednum = -1, - .spawnstate = S_BFGSHOT, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_BFGLAND, - .xdeathstate = S_NULL, - .speed = 25 * FRACUNIT, - .radius = 13 * FRACUNIT, - .height = 8 * FRACUNIT, - .mass = 100, - .damage = 100, - .flags = MF_NOBLOCKMAP | MF_MISSILE | MF_DROPOFF | MF_NOGRAVITY, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_RXPLOD, - .activesound = SFX_NONE, - .seesound = 0, -#endif - }, - - { - /* MT_ARACHPLAZ */ - - .doomednum = -1, - .spawnstate = S_ARACH_PLAZ, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_ARACH_PLEX, - .xdeathstate = S_NULL, - .speed = 25 * FRACUNIT, - .radius = 13 * FRACUNIT, - .height = 8 * FRACUNIT, - .mass = 100, - .damage = 5, - .flags = MF_NOBLOCKMAP | MF_MISSILE | MF_DROPOFF | MF_NOGRAVITY, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_FIRXPL, - .activesound = SFX_NONE, - .seesound = SFX_PLASMA, -#endif - }, - - { - /* MT_PUFF */ - - .doomednum = -1, - .spawnstate = S_PUFF1, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 20 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_NOBLOCKMAP | MF_NOGRAVITY, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_BLOOD */ - - .doomednum = -1, - .spawnstate = S_BLOOD1, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 20 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_NOBLOCKMAP, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_TFOG */ - - .doomednum = -1, - .spawnstate = S_TFOG, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 20 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_NOBLOCKMAP | MF_NOGRAVITY, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_IFOG */ - - .doomednum = -1, - .spawnstate = S_IFOG, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 20 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_NOBLOCKMAP | MF_NOGRAVITY, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_TELEPORTMAN */ - - .doomednum = 14, - .spawnstate = S_NULL, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 20 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_NOBLOCKMAP | MF_NOSECTOR, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_EXTRABFG */ - - .doomednum = -1, - .spawnstate = S_BFGEXP, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 20 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_NOBLOCKMAP | MF_NOGRAVITY, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC0 */ - - .doomednum = 2018, - .spawnstate = S_ARM1, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 20 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SPECIAL, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC1 */ - - .doomednum = 2019, - .spawnstate = S_ARM2, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 20 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SPECIAL, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC2 */ - - .doomednum = 2014, - .spawnstate = S_BON1, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 20 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SPECIAL | MF_COUNTITEM, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC3 */ - - .doomednum = 2015, - .spawnstate = S_BON2, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 20 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SPECIAL | MF_COUNTITEM, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC4 */ - - .doomednum = 5, - .spawnstate = S_BKEY, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 20 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SPECIAL | MF_NOTDMATCH, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC5 */ - - .doomednum = 13, - .spawnstate = S_RKEY, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 20 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SPECIAL | MF_NOTDMATCH, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC6 */ - - .doomednum = 6, - .spawnstate = S_YKEY, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 20 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SPECIAL | MF_NOTDMATCH, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC7 */ - - .doomednum = 39, - .spawnstate = S_YSKULL, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 20 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SPECIAL | MF_NOTDMATCH, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC8 */ - - .doomednum = 38, - .spawnstate = S_RSKULL, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 20 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SPECIAL | MF_NOTDMATCH, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC9 */ - - .doomednum = 40, - .spawnstate = S_BSKULL, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 20 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SPECIAL | MF_NOTDMATCH, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC10 */ - - .doomednum = 2011, - .spawnstate = S_STIM, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 20 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SPECIAL, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC11 */ - - .doomednum = 2012, - .spawnstate = S_MEDI, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 20 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SPECIAL, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC12 */ - - .doomednum = 2013, - .spawnstate = S_SOUL, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 20 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SPECIAL | MF_COUNTITEM, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_INV */ - - .doomednum = 2022, - .spawnstate = S_PINV, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 20 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SPECIAL | MF_COUNTITEM, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC13 */ - - .doomednum = 2023, - .spawnstate = S_PSTR, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 20 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SPECIAL | MF_COUNTITEM, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_INS */ - - .doomednum = 2024, - .spawnstate = S_PINS, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 20 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SPECIAL | MF_COUNTITEM, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC14 */ - - .doomednum = 2025, - .spawnstate = S_SUIT, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 20 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SPECIAL, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC15 */ - - .doomednum = 2026, - .spawnstate = S_PMAP, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 20 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SPECIAL | MF_COUNTITEM, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC16 */ - - .doomednum = 2045, - .spawnstate = S_PVIS, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 20 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SPECIAL | MF_COUNTITEM, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MEGA */ - - .doomednum = 83, - .spawnstate = S_MEGA, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 20 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SPECIAL | MF_COUNTITEM, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_CLIP */ - - .doomednum = 2007, - .spawnstate = S_CLIP, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 20 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SPECIAL, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC17 */ - - .doomednum = 2048, - .spawnstate = S_AMMO, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 20 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SPECIAL, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC18 */ - - .doomednum = 2010, - .spawnstate = S_ROCK, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 20 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SPECIAL, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC19 */ - - .doomednum = 2046, - .spawnstate = S_BROK, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 20 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SPECIAL, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC20 */ - - .doomednum = 2047, - .spawnstate = S_CELL, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 20 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SPECIAL, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC21 */ - - .doomednum = 17, - .spawnstate = S_CELP, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 20 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SPECIAL, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC22 */ - - .doomednum = 2008, - .spawnstate = S_SHEL, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 20 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SPECIAL, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC23 */ - - .doomednum = 2049, - .spawnstate = S_SBOX, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 20 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SPECIAL, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC24 */ - - .doomednum = 8, - .spawnstate = S_BPAK, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 20 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SPECIAL, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC25 */ - - .doomednum = 2006, - .spawnstate = S_BFUG, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 20 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SPECIAL, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_CHAINGUN */ - - .doomednum = 2002, - .spawnstate = S_MGUN, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 20 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SPECIAL, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC26 */ - - .doomednum = 2005, - .spawnstate = S_CSAW, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 20 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SPECIAL, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC27 */ - - .doomednum = 2003, - .spawnstate = S_LAUN, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 20 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SPECIAL, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC28 */ - - .doomednum = 2004, - .spawnstate = S_PLAS, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 20 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SPECIAL, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_SHOTGUN */ - - .doomednum = 2001, - .spawnstate = S_SHOT, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 20 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SPECIAL, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_SUPERSHOTGUN */ - - .doomednum = 82, - .spawnstate = S_SHOT2, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 20 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SPECIAL, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC29 */ - - .doomednum = 85, - .spawnstate = S_TECHLAMP, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 16 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SOLID, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC30 */ - - .doomednum = 86, - .spawnstate = S_TECH2LAMP, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 16 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SOLID, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC31 */ - - .doomednum = 2028, - .spawnstate = S_COLU, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 16 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SOLID, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC32 */ - - .doomednum = 30, - .spawnstate = S_TALLGRNCOL, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 16 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SOLID, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC33 */ - - .doomednum = 31, - .spawnstate = S_SHRTGRNCOL, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 16 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SOLID, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC34 */ - - .doomednum = 32, - .spawnstate = S_TALLREDCOL, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 16 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SOLID, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC35 */ - - .doomednum = 33, - .spawnstate = S_SHRTREDCOL, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 16 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SOLID, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC36 */ - - .doomednum = 37, - .spawnstate = S_SKULLCOL, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 16 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SOLID, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC37 */ - - .doomednum = 36, - .spawnstate = S_HEARTCOL, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 16 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SOLID, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC38 */ - - .doomednum = 41, - .spawnstate = S_EVILEYE, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 16 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SOLID, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC39 */ - - .doomednum = 42, - .spawnstate = S_FLOATSKULL, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 16 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SOLID, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC40 */ - - .doomednum = 43, - .spawnstate = S_TORCHTREE, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 16 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SOLID, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC41 */ - - .doomednum = 44, - .spawnstate = S_BLUETORCH, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 16 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SOLID, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC42 */ - - .doomednum = 45, - .spawnstate = S_GREENTORCH, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 16 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SOLID, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC43 */ - - .doomednum = 46, - .spawnstate = S_REDTORCH, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 16 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SOLID, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC44 */ - - .doomednum = 55, - .spawnstate = S_BTORCHSHRT, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 16 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SOLID, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC45 */ - - .doomednum = 56, - .spawnstate = S_GTORCHSHRT, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 16 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SOLID, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC46 */ - - .doomednum = 57, - .spawnstate = S_RTORCHSHRT, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 16 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SOLID, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC47 */ - - .doomednum = 47, - .spawnstate = S_STALAGTITE, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 16 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SOLID, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC48 */ - - .doomednum = 48, - .spawnstate = S_TECHPILLAR, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 16 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SOLID, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC49 */ - - .doomednum = 34, - .spawnstate = S_CANDLESTIK, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 20 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = 0, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC50 */ - - .doomednum = 35, - .spawnstate = S_CANDELABRA, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 16 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SOLID, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC51 */ - - .doomednum = 49, - .spawnstate = S_BLOODYTWITCH, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 16 * FRACUNIT, - .height = 68 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SOLID | MF_SPAWNCEILING | MF_NOGRAVITY, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC52 */ - - .doomednum = 50, - .spawnstate = S_MEAT2, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 16 * FRACUNIT, - .height = 84 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SOLID | MF_SPAWNCEILING | MF_NOGRAVITY, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC53 */ - - .doomednum = 51, - .spawnstate = S_MEAT3, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 16 * FRACUNIT, - .height = 84 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SOLID | MF_SPAWNCEILING | MF_NOGRAVITY, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC54 */ - - .doomednum = 52, - .spawnstate = S_MEAT4, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 16 * FRACUNIT, - .height = 68 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SOLID | MF_SPAWNCEILING | MF_NOGRAVITY, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC55 */ - - .doomednum = 53, - .spawnstate = S_MEAT5, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 16 * FRACUNIT, - .height = 52 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SOLID | MF_SPAWNCEILING | MF_NOGRAVITY, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC56 */ - - .doomednum = 59, - .spawnstate = S_MEAT2, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 20 * FRACUNIT, - .height = 84 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SPAWNCEILING | MF_NOGRAVITY, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC57 */ - - .doomednum = 60, - .spawnstate = S_MEAT4, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 20 * FRACUNIT, - .height = 68 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SPAWNCEILING | MF_NOGRAVITY, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC58 */ - - .doomednum = 61, - .spawnstate = S_MEAT3, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 20 * FRACUNIT, - .height = 52 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SPAWNCEILING | MF_NOGRAVITY, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC59 */ - - .doomednum = 62, - .spawnstate = S_MEAT5, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 20 * FRACUNIT, - .height = 52 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SPAWNCEILING | MF_NOGRAVITY, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC60 */ - - .doomednum = 63, - .spawnstate = S_BLOODYTWITCH, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 20 * FRACUNIT, - .height = 68 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SPAWNCEILING | MF_NOGRAVITY, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC61 */ - - .doomednum = 22, - .spawnstate = S_HEAD_DIE6, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 20 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = 0, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC62 */ - - .doomednum = 15, - .spawnstate = S_PLAY_DIE7, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 20 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = 0, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC63 */ - - .doomednum = 18, - .spawnstate = S_POSS_DIE5, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 20 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = 0, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC64 */ - - .doomednum = 21, - .spawnstate = S_SARG_DIE6, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 20 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = 0, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC65 */ - - .doomednum = 23, - .spawnstate = S_SKULL_DIE6, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 20 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = 0, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC66 */ - - .doomednum = 20, - .spawnstate = S_TROO_DIE5, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 20 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = 0, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC67 */ - - .doomednum = 19, - .spawnstate = S_SPOS_DIE5, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 20 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = 0, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC68 */ - - .doomednum = 10, - .spawnstate = S_PLAY_XDIE9, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 20 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = 0, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC69 */ - - .doomednum = 12, - .spawnstate = S_PLAY_XDIE9, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 20 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = 0, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC70 */ - - .doomednum = 28, - .spawnstate = S_HEADSONSTICK, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 16 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SOLID, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC71 */ - - .doomednum = 24, - .spawnstate = S_GIBS, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 20 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = 0, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC72 */ - - .doomednum = 27, - .spawnstate = S_HEADONASTICK, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 16 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SOLID, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC73 */ - - .doomednum = 29, - .spawnstate = S_HEADCANDLES, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 16 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SOLID, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC74 */ - - .doomednum = 25, - .spawnstate = S_DEADSTICK, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 16 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SOLID, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC75 */ - - .doomednum = 26, - .spawnstate = S_LIVESTICK, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 16 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SOLID, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC76 */ - - .doomednum = 54, - .spawnstate = S_BIGTREE, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 32 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SOLID, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC77 */ - - .doomednum = 70, - .spawnstate = S_BBAR1, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 16 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SOLID, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC78 */ - - .doomednum = 73, - .spawnstate = S_HANGNOGUTS, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 16 * FRACUNIT, - .height = 88 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SOLID | MF_SPAWNCEILING | MF_NOGRAVITY, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC79 */ - - .doomednum = 74, - .spawnstate = S_HANGBNOBRAIN, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 16 * FRACUNIT, - .height = 88 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SOLID | MF_SPAWNCEILING | MF_NOGRAVITY, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC80 */ - - .doomednum = 75, - .spawnstate = S_HANGTLOOKDN, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 16 * FRACUNIT, - .height = 64 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SOLID | MF_SPAWNCEILING | MF_NOGRAVITY, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC81 */ - - .doomednum = 76, - .spawnstate = S_HANGTSKULL, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 16 * FRACUNIT, - .height = 64 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SOLID | MF_SPAWNCEILING | MF_NOGRAVITY, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC82 */ - - .doomednum = 77, - .spawnstate = S_HANGTLOOKUP, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 16 * FRACUNIT, - .height = 64 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SOLID | MF_SPAWNCEILING | MF_NOGRAVITY, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC83 */ - - .doomednum = 78, - .spawnstate = S_HANGTNOBRAIN, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 16 * FRACUNIT, - .height = 64 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_SOLID | MF_SPAWNCEILING | MF_NOGRAVITY, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC84 */ - - .doomednum = 79, - .spawnstate = S_COLONGIBS, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 20 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_NOBLOCKMAP, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC85 */ - - .doomednum = 80, - .spawnstate = S_SMALLPOOL, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 20 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_NOBLOCKMAP, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, - .seesound = SFX_NONE, -#endif - }, - - { - /* MT_MISC86 */ - - .doomednum = 81, - .spawnstate = S_BRAINSTEM, - .spawnhealth = 1000, - .seestate = S_NULL, - .reactiontime = 8, - .painstate = S_NULL, - .painchance = 0, - .meleestate = S_NULL, - .missilestate = S_NULL, - .deathstate = S_NULL, - .xdeathstate = S_NULL, - .speed = 0, - .radius = 20 * FRACUNIT, - .height = 16 * FRACUNIT, - .mass = 100, - .damage = 0, - .flags = MF_NOBLOCKMAP, - .raisestate = S_NULL, -#ifdef CONFIG_GAMES_NXDOOM_SOUND - .seesound = SFX_NONE, - .attacksound = SFX_NONE, - .painsound = SFX_NONE, - .deathsound = SFX_NONE, - .activesound = SFX_NONE, -#endif - }, -}; - -/**************************************************************************** - * Public Functions - ****************************************************************************/ diff --git a/games/NXDoom/src/doom/info.h b/games/NXDoom/src/doom/info.h deleted file mode 100644 index 4cace8cdf..000000000 --- a/games/NXDoom/src/doom/info.h +++ /dev/null @@ -1,1378 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/info.h - * - * SPDX-License-Identifier: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Thing frame/state LUT, generated by multigen utility. - * This one is the original DOOM version, preserved. - * - ****************************************************************************/ - -#ifndef __INFO__ -#define __INFO__ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -/* Needed for action function pointer handling. */ - -#include "d_think.h" - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -typedef enum -{ - SPR_TROO, - SPR_SHTG, - SPR_PUNG, - SPR_PISG, - SPR_PISF, - SPR_SHTF, - SPR_SHT2, - SPR_CHGG, - SPR_CHGF, - SPR_MISG, - SPR_MISF, - SPR_SAWG, - SPR_PLSG, - SPR_PLSF, - SPR_BFGG, - SPR_BFGF, - SPR_BLUD, - SPR_PUFF, - SPR_BAL1, - SPR_BAL2, - SPR_PLSS, - SPR_PLSE, - SPR_MISL, - SPR_BFS1, - SPR_BFE1, - SPR_BFE2, - SPR_TFOG, - SPR_IFOG, - SPR_PLAY, - SPR_POSS, - SPR_SPOS, - SPR_VILE, - SPR_FIRE, - SPR_FATB, - SPR_FBXP, - SPR_SKEL, - SPR_MANF, - SPR_FATT, - SPR_CPOS, - SPR_SARG, - SPR_HEAD, - SPR_BAL7, - SPR_BOSS, - SPR_BOS2, - SPR_SKUL, - SPR_SPID, - SPR_BSPI, - SPR_APLS, - SPR_APBX, - SPR_CYBR, - SPR_PAIN, - SPR_SSWV, - SPR_KEEN, - SPR_BBRN, - SPR_BOSF, - SPR_ARM1, - SPR_ARM2, - SPR_BAR1, - SPR_BEXP, - SPR_FCAN, - SPR_BON1, - SPR_BON2, - SPR_BKEY, - SPR_RKEY, - SPR_YKEY, - SPR_BSKU, - SPR_RSKU, - SPR_YSKU, - SPR_STIM, - SPR_MEDI, - SPR_SOUL, - SPR_PINV, - SPR_PSTR, - SPR_PINS, - SPR_MEGA, - SPR_SUIT, - SPR_PMAP, - SPR_PVIS, - SPR_CLIP, - SPR_AMMO, - SPR_ROCK, - SPR_BROK, - SPR_CELL, - SPR_CELP, - SPR_SHEL, - SPR_SBOX, - SPR_BPAK, - SPR_BFUG, - SPR_MGUN, - SPR_CSAW, - SPR_LAUN, - SPR_PLAS, - SPR_SHOT, - SPR_SGN2, - SPR_COLU, - SPR_SMT2, - SPR_GOR1, - SPR_POL2, - SPR_POL5, - SPR_POL4, - SPR_POL3, - SPR_POL1, - SPR_POL6, - SPR_GOR2, - SPR_GOR3, - SPR_GOR4, - SPR_GOR5, - SPR_SMIT, - SPR_COL1, - SPR_COL2, - SPR_COL3, - SPR_COL4, - SPR_CAND, - SPR_CBRA, - SPR_COL6, - SPR_TRE1, - SPR_TRE2, - SPR_ELEC, - SPR_CEYE, - SPR_FSKU, - SPR_COL5, - SPR_TBLU, - SPR_TGRN, - SPR_TRED, - SPR_SMBT, - SPR_SMGT, - SPR_SMRT, - SPR_HDB1, - SPR_HDB2, - SPR_HDB3, - SPR_HDB4, - SPR_HDB5, - SPR_HDB6, - SPR_POB1, - SPR_POB2, - SPR_BRS1, - SPR_TLMP, - SPR_TLP2, - NUMSPRITES -} spritenum_t; - -typedef enum -{ - S_NULL, - S_LIGHTDONE, - S_PUNCH, - S_PUNCHDOWN, - S_PUNCHUP, - S_PUNCH1, - S_PUNCH2, - S_PUNCH3, - S_PUNCH4, - S_PUNCH5, - S_PISTOL, - S_PISTOLDOWN, - S_PISTOLUP, - S_PISTOL1, - S_PISTOL2, - S_PISTOL3, - S_PISTOL4, - S_PISTOLFLASH, - S_SGUN, - S_SGUNDOWN, - S_SGUNUP, - S_SGUN1, - S_SGUN2, - S_SGUN3, - S_SGUN4, - S_SGUN5, - S_SGUN6, - S_SGUN7, - S_SGUN8, - S_SGUN9, - S_SGUNFLASH1, - S_SGUNFLASH2, - S_DSGUN, - S_DSGUNDOWN, - S_DSGUNUP, - S_DSGUN1, - S_DSGUN2, - S_DSGUN3, - S_DSGUN4, - S_DSGUN5, - S_DSGUN6, - S_DSGUN7, - S_DSGUN8, - S_DSGUN9, - S_DSGUN10, - S_DSNR1, - S_DSNR2, - S_DSGUNFLASH1, - S_DSGUNFLASH2, - S_CHAIN, - S_CHAINDOWN, - S_CHAINUP, - S_CHAIN1, - S_CHAIN2, - S_CHAIN3, - S_CHAINFLASH1, - S_CHAINFLASH2, - S_MISSILE, - S_MISSILEDOWN, - S_MISSILEUP, - S_MISSILE1, - S_MISSILE2, - S_MISSILE3, - S_MISSILEFLASH1, - S_MISSILEFLASH2, - S_MISSILEFLASH3, - S_MISSILEFLASH4, - S_SAW, - S_SAWB, - S_SAWDOWN, - S_SAWUP, - S_SAW1, - S_SAW2, - S_SAW3, - S_PLASMA, - S_PLASMADOWN, - S_PLASMAUP, - S_PLASMA1, - S_PLASMA2, - S_PLASMAFLASH1, - S_PLASMAFLASH2, - S_BFG, - S_BFGDOWN, - S_BFGUP, - S_BFG1, - S_BFG2, - S_BFG3, - S_BFG4, - S_BFGFLASH1, - S_BFGFLASH2, - S_BLOOD1, - S_BLOOD2, - S_BLOOD3, - S_PUFF1, - S_PUFF2, - S_PUFF3, - S_PUFF4, - S_TBALL1, - S_TBALL2, - S_TBALLX1, - S_TBALLX2, - S_TBALLX3, - S_RBALL1, - S_RBALL2, - S_RBALLX1, - S_RBALLX2, - S_RBALLX3, - S_PLASBALL, - S_PLASBALL2, - S_PLASEXP, - S_PLASEXP2, - S_PLASEXP3, - S_PLASEXP4, - S_PLASEXP5, - S_ROCKET, - S_BFGSHOT, - S_BFGSHOT2, - S_BFGLAND, - S_BFGLAND2, - S_BFGLAND3, - S_BFGLAND4, - S_BFGLAND5, - S_BFGLAND6, - S_BFGEXP, - S_BFGEXP2, - S_BFGEXP3, - S_BFGEXP4, - S_EXPLODE1, - S_EXPLODE2, - S_EXPLODE3, - S_TFOG, - S_TFOG01, - S_TFOG02, - S_TFOG2, - S_TFOG3, - S_TFOG4, - S_TFOG5, - S_TFOG6, - S_TFOG7, - S_TFOG8, - S_TFOG9, - S_TFOG10, - S_IFOG, - S_IFOG01, - S_IFOG02, - S_IFOG2, - S_IFOG3, - S_IFOG4, - S_IFOG5, - S_PLAY, - S_PLAY_RUN1, - S_PLAY_RUN2, - S_PLAY_RUN3, - S_PLAY_RUN4, - S_PLAY_ATK1, - S_PLAY_ATK2, - S_PLAY_PAIN, - S_PLAY_PAIN2, - S_PLAY_DIE1, - S_PLAY_DIE2, - S_PLAY_DIE3, - S_PLAY_DIE4, - S_PLAY_DIE5, - S_PLAY_DIE6, - S_PLAY_DIE7, - S_PLAY_XDIE1, - S_PLAY_XDIE2, - S_PLAY_XDIE3, - S_PLAY_XDIE4, - S_PLAY_XDIE5, - S_PLAY_XDIE6, - S_PLAY_XDIE7, - S_PLAY_XDIE8, - S_PLAY_XDIE9, - S_POSS_STND, - S_POSS_STND2, - S_POSS_RUN1, - S_POSS_RUN2, - S_POSS_RUN3, - S_POSS_RUN4, - S_POSS_RUN5, - S_POSS_RUN6, - S_POSS_RUN7, - S_POSS_RUN8, - S_POSS_ATK1, - S_POSS_ATK2, - S_POSS_ATK3, - S_POSS_PAIN, - S_POSS_PAIN2, - S_POSS_DIE1, - S_POSS_DIE2, - S_POSS_DIE3, - S_POSS_DIE4, - S_POSS_DIE5, - S_POSS_XDIE1, - S_POSS_XDIE2, - S_POSS_XDIE3, - S_POSS_XDIE4, - S_POSS_XDIE5, - S_POSS_XDIE6, - S_POSS_XDIE7, - S_POSS_XDIE8, - S_POSS_XDIE9, - S_POSS_RAISE1, - S_POSS_RAISE2, - S_POSS_RAISE3, - S_POSS_RAISE4, - S_SPOS_STND, - S_SPOS_STND2, - S_SPOS_RUN1, - S_SPOS_RUN2, - S_SPOS_RUN3, - S_SPOS_RUN4, - S_SPOS_RUN5, - S_SPOS_RUN6, - S_SPOS_RUN7, - S_SPOS_RUN8, - S_SPOS_ATK1, - S_SPOS_ATK2, - S_SPOS_ATK3, - S_SPOS_PAIN, - S_SPOS_PAIN2, - S_SPOS_DIE1, - S_SPOS_DIE2, - S_SPOS_DIE3, - S_SPOS_DIE4, - S_SPOS_DIE5, - S_SPOS_XDIE1, - S_SPOS_XDIE2, - S_SPOS_XDIE3, - S_SPOS_XDIE4, - S_SPOS_XDIE5, - S_SPOS_XDIE6, - S_SPOS_XDIE7, - S_SPOS_XDIE8, - S_SPOS_XDIE9, - S_SPOS_RAISE1, - S_SPOS_RAISE2, - S_SPOS_RAISE3, - S_SPOS_RAISE4, - S_SPOS_RAISE5, - S_VILE_STND, - S_VILE_STND2, - S_VILE_RUN1, - S_VILE_RUN2, - S_VILE_RUN3, - S_VILE_RUN4, - S_VILE_RUN5, - S_VILE_RUN6, - S_VILE_RUN7, - S_VILE_RUN8, - S_VILE_RUN9, - S_VILE_RUN10, - S_VILE_RUN11, - S_VILE_RUN12, - S_VILE_ATK1, - S_VILE_ATK2, - S_VILE_ATK3, - S_VILE_ATK4, - S_VILE_ATK5, - S_VILE_ATK6, - S_VILE_ATK7, - S_VILE_ATK8, - S_VILE_ATK9, - S_VILE_ATK10, - S_VILE_ATK11, - S_VILE_HEAL1, - S_VILE_HEAL2, - S_VILE_HEAL3, - S_VILE_PAIN, - S_VILE_PAIN2, - S_VILE_DIE1, - S_VILE_DIE2, - S_VILE_DIE3, - S_VILE_DIE4, - S_VILE_DIE5, - S_VILE_DIE6, - S_VILE_DIE7, - S_VILE_DIE8, - S_VILE_DIE9, - S_VILE_DIE10, - S_FIRE1, - S_FIRE2, - S_FIRE3, - S_FIRE4, - S_FIRE5, - S_FIRE6, - S_FIRE7, - S_FIRE8, - S_FIRE9, - S_FIRE10, - S_FIRE11, - S_FIRE12, - S_FIRE13, - S_FIRE14, - S_FIRE15, - S_FIRE16, - S_FIRE17, - S_FIRE18, - S_FIRE19, - S_FIRE20, - S_FIRE21, - S_FIRE22, - S_FIRE23, - S_FIRE24, - S_FIRE25, - S_FIRE26, - S_FIRE27, - S_FIRE28, - S_FIRE29, - S_FIRE30, - S_SMOKE1, - S_SMOKE2, - S_SMOKE3, - S_SMOKE4, - S_SMOKE5, - S_TRACER, - S_TRACER2, - S_TRACEEXP1, - S_TRACEEXP2, - S_TRACEEXP3, - S_SKEL_STND, - S_SKEL_STND2, - S_SKEL_RUN1, - S_SKEL_RUN2, - S_SKEL_RUN3, - S_SKEL_RUN4, - S_SKEL_RUN5, - S_SKEL_RUN6, - S_SKEL_RUN7, - S_SKEL_RUN8, - S_SKEL_RUN9, - S_SKEL_RUN10, - S_SKEL_RUN11, - S_SKEL_RUN12, - S_SKEL_FIST1, - S_SKEL_FIST2, - S_SKEL_FIST3, - S_SKEL_FIST4, - S_SKEL_MISS1, - S_SKEL_MISS2, - S_SKEL_MISS3, - S_SKEL_MISS4, - S_SKEL_PAIN, - S_SKEL_PAIN2, - S_SKEL_DIE1, - S_SKEL_DIE2, - S_SKEL_DIE3, - S_SKEL_DIE4, - S_SKEL_DIE5, - S_SKEL_DIE6, - S_SKEL_RAISE1, - S_SKEL_RAISE2, - S_SKEL_RAISE3, - S_SKEL_RAISE4, - S_SKEL_RAISE5, - S_SKEL_RAISE6, - S_FATSHOT1, - S_FATSHOT2, - S_FATSHOTX1, - S_FATSHOTX2, - S_FATSHOTX3, - S_FATT_STND, - S_FATT_STND2, - S_FATT_RUN1, - S_FATT_RUN2, - S_FATT_RUN3, - S_FATT_RUN4, - S_FATT_RUN5, - S_FATT_RUN6, - S_FATT_RUN7, - S_FATT_RUN8, - S_FATT_RUN9, - S_FATT_RUN10, - S_FATT_RUN11, - S_FATT_RUN12, - S_FATT_ATK1, - S_FATT_ATK2, - S_FATT_ATK3, - S_FATT_ATK4, - S_FATT_ATK5, - S_FATT_ATK6, - S_FATT_ATK7, - S_FATT_ATK8, - S_FATT_ATK9, - S_FATT_ATK10, - S_FATT_PAIN, - S_FATT_PAIN2, - S_FATT_DIE1, - S_FATT_DIE2, - S_FATT_DIE3, - S_FATT_DIE4, - S_FATT_DIE5, - S_FATT_DIE6, - S_FATT_DIE7, - S_FATT_DIE8, - S_FATT_DIE9, - S_FATT_DIE10, - S_FATT_RAISE1, - S_FATT_RAISE2, - S_FATT_RAISE3, - S_FATT_RAISE4, - S_FATT_RAISE5, - S_FATT_RAISE6, - S_FATT_RAISE7, - S_FATT_RAISE8, - S_CPOS_STND, - S_CPOS_STND2, - S_CPOS_RUN1, - S_CPOS_RUN2, - S_CPOS_RUN3, - S_CPOS_RUN4, - S_CPOS_RUN5, - S_CPOS_RUN6, - S_CPOS_RUN7, - S_CPOS_RUN8, - S_CPOS_ATK1, - S_CPOS_ATK2, - S_CPOS_ATK3, - S_CPOS_ATK4, - S_CPOS_PAIN, - S_CPOS_PAIN2, - S_CPOS_DIE1, - S_CPOS_DIE2, - S_CPOS_DIE3, - S_CPOS_DIE4, - S_CPOS_DIE5, - S_CPOS_DIE6, - S_CPOS_DIE7, - S_CPOS_XDIE1, - S_CPOS_XDIE2, - S_CPOS_XDIE3, - S_CPOS_XDIE4, - S_CPOS_XDIE5, - S_CPOS_XDIE6, - S_CPOS_RAISE1, - S_CPOS_RAISE2, - S_CPOS_RAISE3, - S_CPOS_RAISE4, - S_CPOS_RAISE5, - S_CPOS_RAISE6, - S_CPOS_RAISE7, - S_TROO_STND, - S_TROO_STND2, - S_TROO_RUN1, - S_TROO_RUN2, - S_TROO_RUN3, - S_TROO_RUN4, - S_TROO_RUN5, - S_TROO_RUN6, - S_TROO_RUN7, - S_TROO_RUN8, - S_TROO_ATK1, - S_TROO_ATK2, - S_TROO_ATK3, - S_TROO_PAIN, - S_TROO_PAIN2, - S_TROO_DIE1, - S_TROO_DIE2, - S_TROO_DIE3, - S_TROO_DIE4, - S_TROO_DIE5, - S_TROO_XDIE1, - S_TROO_XDIE2, - S_TROO_XDIE3, - S_TROO_XDIE4, - S_TROO_XDIE5, - S_TROO_XDIE6, - S_TROO_XDIE7, - S_TROO_XDIE8, - S_TROO_RAISE1, - S_TROO_RAISE2, - S_TROO_RAISE3, - S_TROO_RAISE4, - S_TROO_RAISE5, - S_SARG_STND, - S_SARG_STND2, - S_SARG_RUN1, - S_SARG_RUN2, - S_SARG_RUN3, - S_SARG_RUN4, - S_SARG_RUN5, - S_SARG_RUN6, - S_SARG_RUN7, - S_SARG_RUN8, - S_SARG_ATK1, - S_SARG_ATK2, - S_SARG_ATK3, - S_SARG_PAIN, - S_SARG_PAIN2, - S_SARG_DIE1, - S_SARG_DIE2, - S_SARG_DIE3, - S_SARG_DIE4, - S_SARG_DIE5, - S_SARG_DIE6, - S_SARG_RAISE1, - S_SARG_RAISE2, - S_SARG_RAISE3, - S_SARG_RAISE4, - S_SARG_RAISE5, - S_SARG_RAISE6, - S_HEAD_STND, - S_HEAD_RUN1, - S_HEAD_ATK1, - S_HEAD_ATK2, - S_HEAD_ATK3, - S_HEAD_PAIN, - S_HEAD_PAIN2, - S_HEAD_PAIN3, - S_HEAD_DIE1, - S_HEAD_DIE2, - S_HEAD_DIE3, - S_HEAD_DIE4, - S_HEAD_DIE5, - S_HEAD_DIE6, - S_HEAD_RAISE1, - S_HEAD_RAISE2, - S_HEAD_RAISE3, - S_HEAD_RAISE4, - S_HEAD_RAISE5, - S_HEAD_RAISE6, - S_BRBALL1, - S_BRBALL2, - S_BRBALLX1, - S_BRBALLX2, - S_BRBALLX3, - S_BOSS_STND, - S_BOSS_STND2, - S_BOSS_RUN1, - S_BOSS_RUN2, - S_BOSS_RUN3, - S_BOSS_RUN4, - S_BOSS_RUN5, - S_BOSS_RUN6, - S_BOSS_RUN7, - S_BOSS_RUN8, - S_BOSS_ATK1, - S_BOSS_ATK2, - S_BOSS_ATK3, - S_BOSS_PAIN, - S_BOSS_PAIN2, - S_BOSS_DIE1, - S_BOSS_DIE2, - S_BOSS_DIE3, - S_BOSS_DIE4, - S_BOSS_DIE5, - S_BOSS_DIE6, - S_BOSS_DIE7, - S_BOSS_RAISE1, - S_BOSS_RAISE2, - S_BOSS_RAISE3, - S_BOSS_RAISE4, - S_BOSS_RAISE5, - S_BOSS_RAISE6, - S_BOSS_RAISE7, - S_BOS2_STND, - S_BOS2_STND2, - S_BOS2_RUN1, - S_BOS2_RUN2, - S_BOS2_RUN3, - S_BOS2_RUN4, - S_BOS2_RUN5, - S_BOS2_RUN6, - S_BOS2_RUN7, - S_BOS2_RUN8, - S_BOS2_ATK1, - S_BOS2_ATK2, - S_BOS2_ATK3, - S_BOS2_PAIN, - S_BOS2_PAIN2, - S_BOS2_DIE1, - S_BOS2_DIE2, - S_BOS2_DIE3, - S_BOS2_DIE4, - S_BOS2_DIE5, - S_BOS2_DIE6, - S_BOS2_DIE7, - S_BOS2_RAISE1, - S_BOS2_RAISE2, - S_BOS2_RAISE3, - S_BOS2_RAISE4, - S_BOS2_RAISE5, - S_BOS2_RAISE6, - S_BOS2_RAISE7, - S_SKULL_STND, - S_SKULL_STND2, - S_SKULL_RUN1, - S_SKULL_RUN2, - S_SKULL_ATK1, - S_SKULL_ATK2, - S_SKULL_ATK3, - S_SKULL_ATK4, - S_SKULL_PAIN, - S_SKULL_PAIN2, - S_SKULL_DIE1, - S_SKULL_DIE2, - S_SKULL_DIE3, - S_SKULL_DIE4, - S_SKULL_DIE5, - S_SKULL_DIE6, - S_SPID_STND, - S_SPID_STND2, - S_SPID_RUN1, - S_SPID_RUN2, - S_SPID_RUN3, - S_SPID_RUN4, - S_SPID_RUN5, - S_SPID_RUN6, - S_SPID_RUN7, - S_SPID_RUN8, - S_SPID_RUN9, - S_SPID_RUN10, - S_SPID_RUN11, - S_SPID_RUN12, - S_SPID_ATK1, - S_SPID_ATK2, - S_SPID_ATK3, - S_SPID_ATK4, - S_SPID_PAIN, - S_SPID_PAIN2, - S_SPID_DIE1, - S_SPID_DIE2, - S_SPID_DIE3, - S_SPID_DIE4, - S_SPID_DIE5, - S_SPID_DIE6, - S_SPID_DIE7, - S_SPID_DIE8, - S_SPID_DIE9, - S_SPID_DIE10, - S_SPID_DIE11, - S_BSPI_STND, - S_BSPI_STND2, - S_BSPI_SIGHT, - S_BSPI_RUN1, - S_BSPI_RUN2, - S_BSPI_RUN3, - S_BSPI_RUN4, - S_BSPI_RUN5, - S_BSPI_RUN6, - S_BSPI_RUN7, - S_BSPI_RUN8, - S_BSPI_RUN9, - S_BSPI_RUN10, - S_BSPI_RUN11, - S_BSPI_RUN12, - S_BSPI_ATK1, - S_BSPI_ATK2, - S_BSPI_ATK3, - S_BSPI_ATK4, - S_BSPI_PAIN, - S_BSPI_PAIN2, - S_BSPI_DIE1, - S_BSPI_DIE2, - S_BSPI_DIE3, - S_BSPI_DIE4, - S_BSPI_DIE5, - S_BSPI_DIE6, - S_BSPI_DIE7, - S_BSPI_RAISE1, - S_BSPI_RAISE2, - S_BSPI_RAISE3, - S_BSPI_RAISE4, - S_BSPI_RAISE5, - S_BSPI_RAISE6, - S_BSPI_RAISE7, - S_ARACH_PLAZ, - S_ARACH_PLAZ2, - S_ARACH_PLEX, - S_ARACH_PLEX2, - S_ARACH_PLEX3, - S_ARACH_PLEX4, - S_ARACH_PLEX5, - S_CYBER_STND, - S_CYBER_STND2, - S_CYBER_RUN1, - S_CYBER_RUN2, - S_CYBER_RUN3, - S_CYBER_RUN4, - S_CYBER_RUN5, - S_CYBER_RUN6, - S_CYBER_RUN7, - S_CYBER_RUN8, - S_CYBER_ATK1, - S_CYBER_ATK2, - S_CYBER_ATK3, - S_CYBER_ATK4, - S_CYBER_ATK5, - S_CYBER_ATK6, - S_CYBER_PAIN, - S_CYBER_DIE1, - S_CYBER_DIE2, - S_CYBER_DIE3, - S_CYBER_DIE4, - S_CYBER_DIE5, - S_CYBER_DIE6, - S_CYBER_DIE7, - S_CYBER_DIE8, - S_CYBER_DIE9, - S_CYBER_DIE10, - S_PAIN_STND, - S_PAIN_RUN1, - S_PAIN_RUN2, - S_PAIN_RUN3, - S_PAIN_RUN4, - S_PAIN_RUN5, - S_PAIN_RUN6, - S_PAIN_ATK1, - S_PAIN_ATK2, - S_PAIN_ATK3, - S_PAIN_ATK4, - S_PAIN_PAIN, - S_PAIN_PAIN2, - S_PAIN_DIE1, - S_PAIN_DIE2, - S_PAIN_DIE3, - S_PAIN_DIE4, - S_PAIN_DIE5, - S_PAIN_DIE6, - S_PAIN_RAISE1, - S_PAIN_RAISE2, - S_PAIN_RAISE3, - S_PAIN_RAISE4, - S_PAIN_RAISE5, - S_PAIN_RAISE6, - S_SSWV_STND, - S_SSWV_STND2, - S_SSWV_RUN1, - S_SSWV_RUN2, - S_SSWV_RUN3, - S_SSWV_RUN4, - S_SSWV_RUN5, - S_SSWV_RUN6, - S_SSWV_RUN7, - S_SSWV_RUN8, - S_SSWV_ATK1, - S_SSWV_ATK2, - S_SSWV_ATK3, - S_SSWV_ATK4, - S_SSWV_ATK5, - S_SSWV_ATK6, - S_SSWV_PAIN, - S_SSWV_PAIN2, - S_SSWV_DIE1, - S_SSWV_DIE2, - S_SSWV_DIE3, - S_SSWV_DIE4, - S_SSWV_DIE5, - S_SSWV_XDIE1, - S_SSWV_XDIE2, - S_SSWV_XDIE3, - S_SSWV_XDIE4, - S_SSWV_XDIE5, - S_SSWV_XDIE6, - S_SSWV_XDIE7, - S_SSWV_XDIE8, - S_SSWV_XDIE9, - S_SSWV_RAISE1, - S_SSWV_RAISE2, - S_SSWV_RAISE3, - S_SSWV_RAISE4, - S_SSWV_RAISE5, - S_KEENSTND, - S_COMMKEEN, - S_COMMKEEN2, - S_COMMKEEN3, - S_COMMKEEN4, - S_COMMKEEN5, - S_COMMKEEN6, - S_COMMKEEN7, - S_COMMKEEN8, - S_COMMKEEN9, - S_COMMKEEN10, - S_COMMKEEN11, - S_COMMKEEN12, - S_KEENPAIN, - S_KEENPAIN2, - S_BRAIN, - S_BRAIN_PAIN, - S_BRAIN_DIE1, - S_BRAIN_DIE2, - S_BRAIN_DIE3, - S_BRAIN_DIE4, - S_BRAINEYE, - S_BRAINEYESEE, - S_BRAINEYE1, - S_SPAWN1, - S_SPAWN2, - S_SPAWN3, - S_SPAWN4, - S_SPAWNFIRE1, - S_SPAWNFIRE2, - S_SPAWNFIRE3, - S_SPAWNFIRE4, - S_SPAWNFIRE5, - S_SPAWNFIRE6, - S_SPAWNFIRE7, - S_SPAWNFIRE8, - S_BRAINEXPLODE1, - S_BRAINEXPLODE2, - S_BRAINEXPLODE3, - S_ARM1, - S_ARM1A, - S_ARM2, - S_ARM2A, - S_BAR1, - S_BAR2, - S_BEXP, - S_BEXP2, - S_BEXP3, - S_BEXP4, - S_BEXP5, - S_BBAR1, - S_BBAR2, - S_BBAR3, - S_BON1, - S_BON1A, - S_BON1B, - S_BON1C, - S_BON1D, - S_BON1E, - S_BON2, - S_BON2A, - S_BON2B, - S_BON2C, - S_BON2D, - S_BON2E, - S_BKEY, - S_BKEY2, - S_RKEY, - S_RKEY2, - S_YKEY, - S_YKEY2, - S_BSKULL, - S_BSKULL2, - S_RSKULL, - S_RSKULL2, - S_YSKULL, - S_YSKULL2, - S_STIM, - S_MEDI, - S_SOUL, - S_SOUL2, - S_SOUL3, - S_SOUL4, - S_SOUL5, - S_SOUL6, - S_PINV, - S_PINV2, - S_PINV3, - S_PINV4, - S_PSTR, - S_PINS, - S_PINS2, - S_PINS3, - S_PINS4, - S_MEGA, - S_MEGA2, - S_MEGA3, - S_MEGA4, - S_SUIT, - S_PMAP, - S_PMAP2, - S_PMAP3, - S_PMAP4, - S_PMAP5, - S_PMAP6, - S_PVIS, - S_PVIS2, - S_CLIP, - S_AMMO, - S_ROCK, - S_BROK, - S_CELL, - S_CELP, - S_SHEL, - S_SBOX, - S_BPAK, - S_BFUG, - S_MGUN, - S_CSAW, - S_LAUN, - S_PLAS, - S_SHOT, - S_SHOT2, - S_COLU, - S_STALAG, - S_BLOODYTWITCH, - S_BLOODYTWITCH2, - S_BLOODYTWITCH3, - S_BLOODYTWITCH4, - S_DEADTORSO, - S_DEADBOTTOM, - S_HEADSONSTICK, - S_GIBS, - S_HEADONASTICK, - S_HEADCANDLES, - S_HEADCANDLES2, - S_DEADSTICK, - S_LIVESTICK, - S_LIVESTICK2, - S_MEAT2, - S_MEAT3, - S_MEAT4, - S_MEAT5, - S_STALAGTITE, - S_TALLGRNCOL, - S_SHRTGRNCOL, - S_TALLREDCOL, - S_SHRTREDCOL, - S_CANDLESTIK, - S_CANDELABRA, - S_SKULLCOL, - S_TORCHTREE, - S_BIGTREE, - S_TECHPILLAR, - S_EVILEYE, - S_EVILEYE2, - S_EVILEYE3, - S_EVILEYE4, - S_FLOATSKULL, - S_FLOATSKULL2, - S_FLOATSKULL3, - S_HEARTCOL, - S_HEARTCOL2, - S_BLUETORCH, - S_BLUETORCH2, - S_BLUETORCH3, - S_BLUETORCH4, - S_GREENTORCH, - S_GREENTORCH2, - S_GREENTORCH3, - S_GREENTORCH4, - S_REDTORCH, - S_REDTORCH2, - S_REDTORCH3, - S_REDTORCH4, - S_BTORCHSHRT, - S_BTORCHSHRT2, - S_BTORCHSHRT3, - S_BTORCHSHRT4, - S_GTORCHSHRT, - S_GTORCHSHRT2, - S_GTORCHSHRT3, - S_GTORCHSHRT4, - S_RTORCHSHRT, - S_RTORCHSHRT2, - S_RTORCHSHRT3, - S_RTORCHSHRT4, - S_HANGNOGUTS, - S_HANGBNOBRAIN, - S_HANGTLOOKDN, - S_HANGTSKULL, - S_HANGTLOOKUP, - S_HANGTNOBRAIN, - S_COLONGIBS, - S_SMALLPOOL, - S_BRAINSTEM, - S_TECHLAMP, - S_TECHLAMP2, - S_TECHLAMP3, - S_TECHLAMP4, - S_TECH2LAMP, - S_TECH2LAMP2, - S_TECH2LAMP3, - S_TECH2LAMP4, - NUMSTATES -} statenum_t; - -struct state_t -{ - actionf_t action; /* void (*action) (); */ - spritenum_t sprite; - statenum_t nextstate; - - int32_t tics; /* -1 to 181 */ - - uint16_t frame; /* 0 to 32796 */ - - /* NOTE: as far as I can tell, these fields are never used. They are set to - * zero in the state lookup table, and the only other place directly - * referencing them is P_SetPsprite, which uses them seemingly as a fixed - * point number to set some other coordinates later. However, in my - * gameplay, the check for `if (state->misc1)` never evaluates to true. - * Therefore, in my quest to save memory in one of the games largest lookup - * tables, I am removing these fields. - */ - -#if 0 - int misc1; - int misc2; -#endif -}; - -typedef struct state_t state_t; - -typedef enum -{ - MT_PLAYER, - MT_POSSESSED, - MT_SHOTGUY, - MT_VILE, - MT_FIRE, - MT_UNDEAD, - MT_TRACER, - MT_SMOKE, - MT_FATSO, - MT_FATSHOT, - MT_CHAINGUY, - MT_TROOP, - MT_SERGEANT, - MT_SHADOWS, - MT_HEAD, - MT_BRUISER, - MT_BRUISERSHOT, - MT_KNIGHT, - MT_SKULL, - MT_SPIDER, - MT_BABY, - MT_CYBORG, - MT_PAIN, - MT_WOLFSS, - MT_KEEN, - MT_BOSSBRAIN, - MT_BOSSSPIT, - MT_BOSSTARGET, - MT_SPAWNSHOT, - MT_SPAWNFIRE, - MT_BARREL, - MT_TROOPSHOT, - MT_HEADSHOT, - MT_ROCKET, - MT_PLASMA, - MT_BFG, - MT_ARACHPLAZ, - MT_PUFF, - MT_BLOOD, - MT_TFOG, - MT_IFOG, - MT_TELEPORTMAN, - MT_EXTRABFG, - MT_MISC0, - MT_MISC1, - MT_MISC2, - MT_MISC3, - MT_MISC4, - MT_MISC5, - MT_MISC6, - MT_MISC7, - MT_MISC8, - MT_MISC9, - MT_MISC10, - MT_MISC11, - MT_MISC12, - MT_INV, - MT_MISC13, - MT_INS, - MT_MISC14, - MT_MISC15, - MT_MISC16, - MT_MEGA, - MT_CLIP, - MT_MISC17, - MT_MISC18, - MT_MISC19, - MT_MISC20, - MT_MISC21, - MT_MISC22, - MT_MISC23, - MT_MISC24, - MT_MISC25, - MT_CHAINGUN, - MT_MISC26, - MT_MISC27, - MT_MISC28, - MT_SHOTGUN, - MT_SUPERSHOTGUN, - MT_MISC29, - MT_MISC30, - MT_MISC31, - MT_MISC32, - MT_MISC33, - MT_MISC34, - MT_MISC35, - MT_MISC36, - MT_MISC37, - MT_MISC38, - MT_MISC39, - MT_MISC40, - MT_MISC41, - MT_MISC42, - MT_MISC43, - MT_MISC44, - MT_MISC45, - MT_MISC46, - MT_MISC47, - MT_MISC48, - MT_MISC49, - MT_MISC50, - MT_MISC51, - MT_MISC52, - MT_MISC53, - MT_MISC54, - MT_MISC55, - MT_MISC56, - MT_MISC57, - MT_MISC58, - MT_MISC59, - MT_MISC60, - MT_MISC61, - MT_MISC62, - MT_MISC63, - MT_MISC64, - MT_MISC65, - MT_MISC66, - MT_MISC67, - MT_MISC68, - MT_MISC69, - MT_MISC70, - MT_MISC71, - MT_MISC72, - MT_MISC73, - MT_MISC74, - MT_MISC75, - MT_MISC76, - MT_MISC77, - MT_MISC78, - MT_MISC79, - MT_MISC80, - MT_MISC81, - MT_MISC82, - MT_MISC83, - MT_MISC84, - MT_MISC85, - MT_MISC86, - NUMMOBJTYPES -} mobjtype_t; - -/* Ranges for these members were obtained by analyzing the `mobjinfo` - * array at game startup. - */ - -begin_packed_struct struct mobjinfo_t -{ - uint32_t flags; /* 0 to 33557510 */ - uint32_t radius; /* 393216 to 8388608 */ - uint32_t height; /* 524288 to 7208960 */ - uint32_t mass; /* 50 to 10000000 */ - uint32_t speed; /* 0 to 1638400 */ - int16_t doomednum; /* -1 to 3006 */ - uint16_t spawnhealth; /* 20 to 4000 */ - uint16_t spawnstate; /* 0 to 963 */ - uint16_t seestate; /* 0 to 785 */ - uint16_t painstate; /* 0 to 779 */ - uint16_t painchance; /* 0 to 256 */ - uint16_t meleestate; /* 0 to 566 */ - uint16_t missilestate; /* 0 to 736 */ - uint16_t deathstate; /* 0 to 808 */ - uint16_t xdeathstate; /* 0 to 749 */ - uint16_t raisestate; /* 0 to 758 */ - uint8_t damage; /* 0 to 100 */ - uint8_t reactiontime; /* 0 to 8 */ -#ifdef CONFIG_GAMES_NXDOOM_SOUND - uint8_t seesound; /* 0 to 107 */ - uint8_t attacksound; /* 0 to 52 */ - uint8_t painsound; /* 0 to 103 */ - uint8_t deathsound; /* 0 to 104 */ - uint8_t activesound; /* 0 to 105 */ -#endif -} end_packed_struct; - -typedef struct mobjinfo_t mobjinfo_t; - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -extern state_t states[NUMSTATES]; -extern const char *sprnames[]; - -/* Size before opt: 0000000000012604 - * Size after opt with sound: 0000000000007124 - * Size after opt without sound: 0000000000006028 - * - * Best improvement: 6576 bytes - * Best improvement: 6.42KB - */ - -extern mobjinfo_t mobjinfo[NUMMOBJTYPES]; - -#endif /* __INFO__ */ diff --git a/games/NXDoom/src/doom/m_menu.c b/games/NXDoom/src/doom/m_menu.c deleted file mode 100644 index 77e878f94..000000000 --- a/games/NXDoom/src/doom/m_menu.c +++ /dev/null @@ -1,2155 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/m_menu.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * DOOM selection menu, options, episode etc. - * Sliders and icons. Kinda widget stuff. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -#include "doomdef.h" -#include "doomkeys.h" -#include "dstrings.h" - -#include "d_main.h" -#include "deh_main.h" - -#include "i_input.h" -#include "i_joystick.h" -#include "i_swap.h" -#include "i_system.h" -#include "i_timer.h" -#include "i_video.h" -#include "m_misc.h" -#include "v_video.h" -#include "w_wad.h" -#include "z_zone.h" - -#include "r_local.h" - -#include "hu_stuff.h" - -#include "g_game.h" - -#include "m_argv.h" -#include "m_controls.h" -#include "p_saveg.h" -#include "p_setup.h" - -#ifdef CONFIG_GAMES_NXDOOM_SOUND -#include "s_sound.h" -#include "sounds.h" -#endif - -#include "doomstat.h" - -/* Data. */ - -#include "m_menu.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define SKULLXOFF -32 -#define LINEHEIGHT 16 - -#define JOY_BUTTON_MAPPED(x) ((x) >= 0) -#define JOY_BUTTON_PRESSED(x) \ - (JOY_BUTTON_MAPPED(x) && (ev->data1 & (1 << (x))) != 0) - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -void (*message_routine)(int response); - -/* MENU TYPEDEFS */ - -typedef struct -{ - /* 0 = no cursor here, 1 = ok, 2 = arrows ok */ - - short status; - - char name[10]; - - /* choice = menu item #. - * if status = 2, - * choice=0:leftarrow,1:rightarrow - */ - - void (*routine)(int choice); - - /* hotkey in menu */ - - char alpha_key; -} menuitem_t; - -typedef struct menu_s -{ - short numitems; /* # of menu items */ - struct menu_s *prev_menu; /* previous menu */ - menuitem_t *menu_items; /* menu items */ - void (*routine)(void); /* draw routine */ - short x; - short y; /* x,y of menu */ - short last_on; /* last item user was on in menu */ -} menu_t; - -/* DOOM MENU */ - -enum -{ - MAIN_NEWGAME = 0, - MAIN_OPTIONS, - MAIN_LOADGAME, - MAIN_SAVEGAME, - MAIN_READTHIS, - MAIN_QUITDOOM, - MAIN_END -} main_e; - -/* EPISODE SELECT */ - -enum -{ - EPISODE_EP1, - EPISODE_EP2, - EPISODE_EP3, - EPISODE_EP4, - EPISODE_END -} episodes_e; - -/* NEW GAME */ - -enum -{ - NEWGAME_KILLTHINGS, - NEWGAME_TOOROUGH, - NEWGAME_HURTME, - NEWGAME_VIOLANCE, - NEWGAME_NIGHTMARE, - NEWGAME_END -} newgame_e; - -/* OPTIONS MENU */ - -enum -{ - OPT_ENDGAME, - OPT_MESSAGES, - OPT_DETAIL, - OPT_SCRNSIZE, - OPT_EMPTY1, - OPT_MOUSESENS, - OPT_EMPTY2, - OPT_SOUNDVOL, - OPT_END -} options_e; - -enum -{ - RDTHSEMPTY1, - READ1_END -} read_e; - -enum -{ - RDTHSEMPTY2, - READ2_END -} read_e2; - -/* SOUND VOLUME MENU */ - -enum -{ - SOUND_SFXVOL, - SOUND_SFXEMPTY1, - SOUND_MUSICVOL, - SOUND_SFXEMPTY2, - SOUND_END -} sound_e; - -/* LOAD GAME MENU */ - -enum -{ - LOAD_1, - LOAD_2, - LOAD_3, - LOAD_4, - LOAD_5, - LOAD_6, - LOAD_END -} load_e; - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -static void m_new_game(int choice); -static void m_episode(int choice); -static void m_choose_skill(int choice); -static void m_load_game(int choice); -static void m_save_game(int choice); -static void m_options(int choice); -static void m_end_game(int choice); -static void m_read_this(int choice); -static void m_read_this2(int choice); -static void m_quit_doom(int choice); - -static void m_change_messages(int choice); -static void m_change_sensitivity(int choice); -static void m_sound(int choice); -static void m_change_detail(int choice); -static void m_size_display(int choice); - -static void m_finish_read_this(int choice); -static void m_load_select(int choice); -static void m_save_select(int choice); -static void m_read_save_strings(void); -static void m_quick_save(void); -static void m_quick_load(void); - -static void m_drawmain_menu(void); -static void m_draw_read_this1(void); -static void m_draw_read_this2(void); -static void m_draw_new_game(void); -static void m_draw_episode(void); -static void m_draw_options(void); -static void m_draw_load(void); -static void m_draw_save(void); - -static void m_draw_save_load_border(int x, int y); -static void m_setup_next_menu(menu_t *menudef); -static void m_draw_thermo(int x, int y, int therm_width, int therm_dot); -static void m_write_text(int x, int y, const char *string); -static int m_string_width(const char *string); -static int m_string_height(const char *string); -static void m_start_message(const char *string, - void *routine, boolean input); -static void m_clear_menus(void); - -#ifdef CONFIG_GAMES_NXDOOM_SOUND -static void m_sfx_vol(int choice); -static void m_music_vol(int choice); -static void m_draw_sound(void); -#endif - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/* defaulted values */ - -int g_mouse_sensitivity = 5; - -/* Show messages has default, 0 = off, 1 = on */ - -int g_show_messages = 1; - -/* Blocky mode, has default, 0 = high, 1 = normal */ - -int g_detail_level = 0; -int screenblocks = 9; - -boolean g_menuactive; -boolean inhelpscreens; - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/* message x & y */ - -static int g_message_last_menu_active; - -/* timed message = no input from user */ - -static boolean g_message_needs_input; - -static char g_gammamsg[5][26] = -{ - GAMMALVL0, GAMMALVL1, GAMMALVL2, GAMMALVL3, GAMMALVL4, -}; - -/* we are going to be entering a savegame string */ - -static int g_save_string_enter; -static int g_save_slot; /* which slot to save in */ -static int g_save_char_index; /* which char we're editing */ - -/* old save description before edit */ - -static char g_save_old_string[SAVESTRINGSIZE]; - -static char g_save_game_strings[10][SAVESTRINGSIZE]; - -static char g_endstring[160]; - -static short g_item_on; /* menu item skull is on */ -static short g_skull_anim_counter; /* skull animation counter */ -static short g_which_skull; /* which skull to draw */ - -/* temp for screenblocks (0-9) */ - -static int g_screen_size; - -/* -1 = no quicksave slot picked! */ - -static int g_quick_save_slot; - -/* 1 = message to be printed */ - -static int g_message_to_print; - -/* ...and here is the message string! */ - -static const char *g_message_string; - -static int g_epi; - -/* graphic name of skulls - * warning: initializer-string for array of chars is too long - */ - -static const char *g_skull_name[2] = -{ - "M_SKULL1", - "M_SKULL2", -}; - -#ifdef CONFIG_GAMES_NXDOOM_SOUND -static int g_quitsounds[8] = -{ - SFX_PLDETH, SFX_DMPAIN, SFX_POPAIN, SFX_SLOP, - SFX_TELEPT, SFX_POSIT1, SFX_POSIT3, SFX_SGTATK, -}; - -static int g_quitsounds2[8] = -{ - SFX_VILACT, SFX_GETPOW, SFX_BOSCUB, SFX_SLOP, - SFX_SKESWG, SFX_KNTDTH, SFX_BSPACT, SFX_SGTATK, -}; -#endif - -/* was the save action initiated by joypad? */ - -static boolean g_joypad_save = false; - -static char g_tempstring[90]; - -static const char *g_detail_names[2] = -{ - "M_GDHIGH", - "M_GDLOW", -}; - -static const char *g_msg_names[2] = -{ - "M_MSGOFF", - "M_MSGON", -}; - -/* current menudef */ - -static menu_t *g_current_menu; - -static menuitem_t g_main_menu[] = -{ - {1, "M_NGAME", m_new_game, 'n'}, - {1, "M_OPTION", m_options, 'o'}, - {1, "M_LOADG", m_load_game, 'l'}, - {1, "M_SAVEG", m_save_game, 's'}, - {1, "M_RDTHIS", m_read_this, 'r'}, /* Another hiccup with Special edition. */ - {1, "M_QUITG", m_quit_doom, 'q'}, -}; - -static menu_t g_main_def = -{ - MAIN_END, NULL, g_main_menu, m_drawmain_menu, 97, 64, 0, -}; - -static menuitem_t g_episode_menu[] = -{ - {1, "M_EPI1", m_episode, 'k'}, - {1, "M_EPI2", m_episode, 't'}, - {1, "M_EPI3", m_episode, 'i'}, - {1, "M_EPI4", m_episode, 't'}, -}; - -static menu_t g_epi_def = -{ - EPISODE_END, /* # of menu items */ - &g_main_def, /* previous menu */ - g_episode_menu, /* menuitem_t -> */ - m_draw_episode, /* drawing routine -> */ - 48, - 63, /* x,y */ - EPISODE_EP1 /* lastOn */ -}; - -static menuitem_t new_game_menu[] = -{ - {1, "M_JKILL", m_choose_skill, 'i'}, - {1, "M_ROUGH", m_choose_skill, 'h'}, - {1, "M_HURT", m_choose_skill, 'h'}, - {1, "M_ULTRA", m_choose_skill, 'u'}, - {1, "M_NMARE", m_choose_skill, 'n'}, -}; - -static menu_t g_new_def = -{ - NEWGAME_END, /* # of menu items */ - &g_epi_def, /* previous menu */ - new_game_menu, /* menuitem_t -> */ - m_draw_new_game, /* drawing routine -> */ - 48, - 63, /* x,y */ - NEWGAME_HURTME /* lastOn */ -}; - -static menuitem_t g_options_menu[] = -{ - { - 1, - "M_ENDGAM", - m_end_game, - 'e', - }, - { - 1, - "M_MESSG", - m_change_messages, - 'm', - }, - { - 1, - "M_DETAIL", - m_change_detail, - 'g', - }, - { - 2, - "M_SCRNSZ", - m_size_display, - 's', - }, - { - -1, - "", - 0, - '\0', - }, - { - 2, - "M_MSENS", - m_change_sensitivity, - 'm', - }, - { - -1, - "", - 0, - '\0', - }, - { - 1, - "M_SVOL", - m_sound, - 's', - }, -}; - -static menu_t g_options_def = -{ - OPT_END, &g_main_def, g_options_menu, m_draw_options, 60, 37, 0, -}; - -/* Read This! MENU 1 & 2 */ - -static menuitem_t g_read_menu1[] = -{ - {1, "", m_read_this2, 0}, -}; - -static menu_t g_read_def1 = -{ - READ1_END, &g_main_def, g_read_menu1, m_draw_read_this1, 280, 185, 0, -}; - -static menuitem_t g_read_menu2[] = -{ - {1, "", m_finish_read_this, 0}, -}; - -static menu_t g_read_def2 = -{ - READ2_END, &g_read_def1, g_read_menu2, m_draw_read_this2, 330, 175, 0, -}; - -#ifdef CONFIG_GAMES_NXDOOM_SOUND -static menuitem_t g_sound_menu[] = -{ - { - 2, - "M_SFXVOL", - m_sfx_vol, - 's', - }, - { - -1, - "", - 0, - '\0', - }, - { - 2, - "M_MUSVOL", - m_music_vol, - 'm', - }, - { - -1, - "", - 0, - '\0', - }, -}; - -static menu_t g_sound_def = -{ - SOUND_END, &g_options_def, g_sound_menu, m_draw_sound, 80, 64, 0, -}; -#endif - -static menuitem_t g_load_menu[] = -{ - {1, "", m_load_select, '1'}, - {1, "", m_load_select, '2'}, - {1, "", m_load_select, '3'}, - {1, "", m_load_select, '4'}, - {1, "", m_load_select, '5'}, - {1, "", m_load_select, '6'}, -}; - -static menu_t g_load_def = -{ - LOAD_END, &g_main_def, g_load_menu, m_draw_load, 80, 54, 0, -}; - -/* SAVE GAME MENU */ - -static menuitem_t g_save_menu[] = -{ - {1, "", m_save_select, '1'}, - {1, "", m_save_select, '2'}, - {1, "", m_save_select, '3'}, - {1, "", m_save_select, '4'}, - {1, "", m_save_select, '5'}, - {1, "", m_save_select, '6'}, -}; - -static menu_t g_save_def = -{ - LOAD_END, &g_main_def, g_save_menu, m_draw_save, 80, 54, 0, -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/* Generate a default save slot name when the user saves to - * an empty slot via the joypad. - */ - -static void set_default_save_name(int slot) -{ - /* map from IWAD or PWAD? */ - - if (w_is_iwad_lump(maplumpinfo) && strcmp(savegamedir, "")) - { - snprintf(g_save_game_strings[g_item_on], SAVESTRINGSIZE, "%s", - maplumpinfo->name); - } - else - { - char *wadname = m_string_duplicate(w_wad_name_for_lump(maplumpinfo)); - char *ext = strrchr(wadname, '.'); - - if (ext != NULL) - { - *ext = '\0'; - } - - snprintf(g_save_game_strings[g_item_on], SAVESTRINGSIZE, "%s (%s)", - maplumpinfo->name, wadname); - free(wadname); - } - - m_force_uppercase(g_save_game_strings[g_item_on]); - g_joypad_save = false; -} - -/* m_responder calls this when user is finished */ - -static void m_do_save(int slot) -{ - g_save_game(slot, g_save_game_strings[slot]); - m_clear_menus(); - - /* PICK QUICKSAVE SLOT YET? */ - - if (g_quick_save_slot == -2) g_quick_save_slot = slot; -} - -static void m_quick_save_response(int key) -{ - if (key == key_menu_confirm) - { - m_do_save(g_quick_save_slot); -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(NULL, SFX_SWTCHX); -#endif - } -} - -static void m_quick_load_response(int key) -{ - if (key == key_menu_confirm) - { - m_load_select(g_quick_save_slot); -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(NULL, SFX_SWTCHX); -#endif - } -} - -/* These keys evaluate to a "null" key in Vanilla Doom that allows weird - * jumping in the menus. Preserve this behavior for accuracy. - */ - -static boolean is_null_key(int key) -{ - return key == KEY_PAUSE || key == KEY_CAPSLOCK || key == KEY_SCRLCK || - key == KEY_NUMLOCK; -} - -static void m_start_message(const char *string, void *routine, boolean input) -{ - g_message_last_menu_active = g_menuactive; - g_message_to_print = 1; - g_message_string = string; - message_routine = routine; - g_message_needs_input = input; - g_menuactive = true; - return; -} - -static const char *m_select_end_message(void) -{ - const char **endmsg; - - if (logical_gamemission == doom) - { - /* Doom 1 */ - - endmsg = doom1_endmsg; - } - else - { - /* Doom 2 */ - - endmsg = doom2_endmsg; - } - - return endmsg[gametic % NUM_QUITMESSAGES]; -} - -static void m_quit_response(int key) -{ - if (key != key_menu_confirm) return; - if (!netgame) - { -#ifdef CONFIG_GAMES_NXDOOM_SOUND - if (gamemode == commercial) - s_start_sound(NULL, g_quitsounds2[(gametic >> 2) & 7]); - else - s_start_sound(NULL, g_quitsounds[(gametic >> 2) & 7]); -#endif - i_wait_vbl(105); - } - - i_quit(); -} - -static void m_end_game_response(int key) -{ - if (key != key_menu_confirm) return; - - g_current_menu->last_on = g_item_on; - m_clear_menus(); - d_start_title(); -} - -static void m_draw_read_this_commercial(void) -{ - inhelpscreens = true; - - v_draw_patch_direct(0, 0, w_cache_lump_name(("HELP"), PU_CACHE)); -} - -static void m_verify_nightmare(int key) -{ - if (key != key_menu_confirm) return; - - g_deferred_init_new(NEWGAME_NIGHTMARE, g_epi + 1, 1); - m_clear_menus(); -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/* read the strings from the savegame files */ - -void m_read_save_strings(void) -{ - FILE *handle; - int i; - char name[256]; - - for (i = 0; i < LOAD_END; i++) - { - int retval; - m_str_copy(name, p_save_game_file(i), sizeof(name)); - - handle = fopen(name, "rb"); - if (handle == NULL) - { - m_str_copy(g_save_game_strings[i], EMPTYSTRING, SAVESTRINGSIZE); - g_load_menu[i].status = 0; - continue; - } - - retval = fread(&g_save_game_strings[i], 1, SAVESTRINGSIZE, handle); - fclose(handle); - g_load_menu[i].status = retval == SAVESTRINGSIZE; - } -} - -void m_draw_load(void) -{ - int i; - - v_draw_patch_direct(72, 28, w_cache_lump_name(("M_LOADG"), PU_CACHE)); - - for (i = 0; i < LOAD_END; i++) - { - m_draw_save_load_border(g_load_def.x, g_load_def.y + LINEHEIGHT * i); - m_write_text(g_load_def.x, g_load_def.y + LINEHEIGHT * i, - g_save_game_strings[i]); - } -} - -/* Draw border for the savegame description */ - -void m_draw_save_load_border(int x, int y) -{ - int i; - - v_draw_patch_direct(x - 8, y + 7, - w_cache_lump_name(("M_LSLEFT"), PU_CACHE)); - - for (i = 0; i < 24; i++) - { - v_draw_patch_direct(x, y + 7, - w_cache_lump_name(("M_LSCNTR"), PU_CACHE)); - x += 8; - } - - v_draw_patch_direct(x, y + 7, w_cache_lump_name(("M_LSRGHT"), PU_CACHE)); -} - -/* User wants to load this game */ - -void m_load_select(int choice) -{ - char name[256]; - - m_str_copy(name, p_save_game_file(choice), sizeof(name)); - - g_load_game(name); - m_clear_menus(); -} - -/* Selected from DOOM menu */ - -void m_load_game(int choice) -{ - if (netgame) - { - m_start_message((LOADNET), NULL, false); - return; - } - - m_setup_next_menu(&g_load_def); - m_read_save_strings(); -} - -/* M_SaveGame & Cie. */ - -void m_draw_save(void) -{ - int i; - - v_draw_patch_direct(72, 28, w_cache_lump_name(("M_SAVEG"), PU_CACHE)); - for (i = 0; i < LOAD_END; i++) - { - m_draw_save_load_border(g_load_def.x, g_load_def.y + LINEHEIGHT * i); - m_write_text(g_load_def.x, g_load_def.y + LINEHEIGHT * i, - g_save_game_strings[i]); - } - - if (g_save_string_enter) - { - i = m_string_width(g_save_game_strings[g_save_slot]); - m_write_text(g_load_def.x + i, - g_load_def.y + LINEHEIGHT * g_save_slot, "_"); - } -} - -/* User wants to save. Start string input for m_responder */ - -void m_save_select(int choice) -{ - int x; - int y; - - /* we are going to be intercepting all chars */ - - g_save_string_enter = 1; - - /* We need to turn on text input: */ - - x = g_load_def.x - 11; - y = g_load_def.y + choice * LINEHEIGHT - 4; - i_start_text_input(x, y, x + 8 + 24 * 8 + 8, y + LINEHEIGHT - 2); - - g_save_slot = choice; - m_str_copy(g_save_old_string, g_save_game_strings[choice], SAVESTRINGSIZE); - if (!strcmp(g_save_game_strings[choice], EMPTYSTRING)) - { - g_save_game_strings[choice][0] = 0; - - if (g_joypad_save) - { - set_default_save_name(choice); - } - } - - g_save_char_index = strlen(g_save_game_strings[choice]); -} - -/* Selected from DOOM menu */ - -void m_save_game(int choice) -{ - if (!usergame) - { - m_start_message((SAVEDEAD), NULL, false); - return; - } - - if (gamestate != GS_LEVEL) return; - - m_setup_next_menu(&g_save_def); - m_read_save_strings(); -} - -void m_quick_save(void) -{ - if (!usergame) - { -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(NULL, SFX_OOF); -#endif - return; - } - - if (gamestate != GS_LEVEL) return; - - if (g_quick_save_slot < 0) - { - m_start_control_panel(); - m_read_save_strings(); - m_setup_next_menu(&g_save_def); - g_quick_save_slot = -2; /* means to pick a slot now */ - return; - } - - snprintf(g_tempstring, sizeof(g_tempstring), QSPROMPT, - g_save_game_strings[g_quick_save_slot]); - m_start_message(g_tempstring, m_quick_save_response, true); -} - -static void m_quick_load(void) -{ - if (netgame) - { - m_start_message((QLOADNET), NULL, false); - return; - } - - if (g_quick_save_slot < 0) - { - m_start_message((QSAVESPOT), NULL, false); - return; - } - - snprintf(g_tempstring, sizeof(g_tempstring), QLPROMPT, - g_save_game_strings[g_quick_save_slot]); - m_start_message(g_tempstring, m_quick_load_response, true); -} - -/* Read This Menus - * Had a "quick hack to fix romero bug" - */ - -static void m_draw_read_this1(void) -{ - inhelpscreens = true; - - v_draw_patch_direct(0, 0, w_cache_lump_name(("HELP2"), PU_CACHE)); -} - -/* Read This Menus - optional second page. */ - -static void m_draw_read_this2(void) -{ - inhelpscreens = true; - - /* We only ever draw the second page if this is - * gameversion == exe_doom_1_9 and gamemode == registered - */ - - v_draw_patch_direct(0, 0, w_cache_lump_name(("HELP1"), PU_CACHE)); -} - -/* Change Sfx & Music volumes */ - -#ifdef CONFIG_GAMES_NXDOOM_SOUND -static void m_draw_sound(void) -{ - v_draw_patch_direct(60, 38, w_cache_lump_name(("M_SVOL"), PU_CACHE)); - - m_draw_thermo(g_sound_def.x, - g_sound_def.y + LINEHEIGHT * (SOUND_SFXVOL + 1), 16, - g_sfx_volume); - - m_draw_thermo(g_sound_def.x, - g_sound_def.y + LINEHEIGHT * (SOUND_MUSICVOL + 1), 16, - g_music_volume); -} -#endif - -static void m_sound(int choice) -{ -#ifdef CONFIG_GAMES_NXDOOM_SOUND - m_setup_next_menu(&g_sound_def); -#endif -} - -#ifdef CONFIG_GAMES_NXDOOM_SOUND -static void m_sfx_vol(int choice) -{ - switch (choice) - { - case 0: - if (g_sfx_volume) g_sfx_volume--; - break; - case 1: - if (g_sfx_volume < 15) g_sfx_volume++; - break; - } - - s_set_sfx_volume(g_sfx_volume * 8); -} -#endif - -#ifdef CONFIG_GAMES_NXDOOM_SOUND -static void m_music_vol(int choice) -{ - switch (choice) - { - case 0: - if (g_music_volume) g_music_volume--; - break; - case 1: - if (g_music_volume < 15) g_music_volume++; - break; - } - - s_set_music_volume(g_music_volume * 8); -} -#endif - -void m_drawmain_menu(void) -{ - v_draw_patch_direct(94, 2, w_cache_lump_name(("M_DOOM"), PU_CACHE)); -} - -void m_draw_new_game(void) -{ - v_draw_patch_direct(96, 14, w_cache_lump_name(("M_NEWG"), PU_CACHE)); - v_draw_patch_direct(54, 38, w_cache_lump_name(("M_SKILL"), PU_CACHE)); -} - -void m_new_game(int choice) -{ - if (netgame && !demoplayback) - { - m_start_message((NEWGAME), NULL, false); - return; - } - - /* Chex Quest disabled the episode select screen, as did Doom II. */ - - if (gamemode == commercial || gameversion == exe_chex) - m_setup_next_menu(&g_new_def); - else - m_setup_next_menu(&g_epi_def); -} - -void m_draw_episode(void) -{ - v_draw_patch_direct(54, 38, w_cache_lump_name(("M_EPISOD"), PU_CACHE)); -} - -void m_choose_skill(int choice) -{ - if (choice == NEWGAME_NIGHTMARE) - { - m_start_message((NIGHTMARE), m_verify_nightmare, true); - return; - } - - g_deferred_init_new(choice, g_epi + 1, 1); - m_clear_menus(); -} - -void m_episode(int choice) -{ - if ((gamemode == shareware) && choice) - { - m_start_message((SWSTRING), NULL, false); - m_setup_next_menu(&g_read_def1); - return; - } - - g_epi = choice; - m_setup_next_menu(&g_new_def); -} - -void m_draw_options(void) -{ - v_draw_patch_direct(108, 15, w_cache_lump_name(("M_OPTTTL"), PU_CACHE)); - - v_draw_patch_direct( - g_options_def.x + 175, g_options_def.y + LINEHEIGHT * OPT_DETAIL, - w_cache_lump_name((g_detail_names[g_detail_level]), PU_CACHE)); - - v_draw_patch_direct( - g_options_def.x + 120, g_options_def.y + LINEHEIGHT * OPT_MESSAGES, - w_cache_lump_name((g_msg_names[g_show_messages]), PU_CACHE)); - - m_draw_thermo(g_options_def.x, - g_options_def.y + LINEHEIGHT * (OPT_MOUSESENS + 1), 10, - g_mouse_sensitivity); - - m_draw_thermo(g_options_def.x, - g_options_def.y + LINEHEIGHT * (OPT_SCRNSIZE + 1), 9, - g_screen_size); -} - -void m_options(int choice) -{ - m_setup_next_menu(&g_options_def); -} - -/* Toggle messages on/off */ - -void m_change_messages(int choice) -{ - /* warning: unused parameter `int choice' */ - - choice = 0; - g_show_messages = 1 - g_show_messages; - - if (!g_show_messages) - players[consoleplayer].message = (MSGOFF); - else - players[consoleplayer].message = (MSGON); - - message_dontfuckwithme = true; -} - -void m_end_game(int choice) -{ - choice = 0; - if (!usergame) - { -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(NULL, SFX_OOF); -#endif - return; - } - - if (netgame) - { - m_start_message((NETEND), NULL, false); - return; - } - - m_start_message((ENDGAME), m_end_game_response, true); -} - -void m_read_this(int choice) -{ - choice = 0; - m_setup_next_menu(&g_read_def1); -} - -void m_read_this2(int choice) -{ - choice = 0; - m_setup_next_menu(&g_read_def2); -} - -void m_finish_read_this(int choice) -{ - choice = 0; - m_setup_next_menu(&g_main_def); -} - -void m_quit_doom(int choice) -{ - snprintf(g_endstring, sizeof(g_endstring), "%s\n\n" DOSY, - (m_select_end_message())); - - m_start_message(g_endstring, m_quit_response, true); -} - -void m_change_sensitivity(int choice) -{ - switch (choice) - { - case 0: - if (g_mouse_sensitivity) g_mouse_sensitivity--; - break; - case 1: - if (g_mouse_sensitivity < 9) g_mouse_sensitivity++; - break; - } -} - -void m_change_detail(int choice) -{ - choice = 0; - g_detail_level = 1 - g_detail_level; - - r_set_view_size(screenblocks, g_detail_level); - - if (!g_detail_level) - players[consoleplayer].message = (DETAILHI); - else - players[consoleplayer].message = (DETAILLO); -} - -void m_size_display(int choice) -{ - switch (choice) - { - case 0: - if (g_screen_size > 0) - { - screenblocks--; - g_screen_size--; - } - break; - case 1: - if (g_screen_size < 8) - { - screenblocks++; - g_screen_size++; - } - break; - } - - r_set_view_size(screenblocks, g_detail_level); -} - -/* Menu Functions */ - -void m_draw_thermo(int x, int y, int therm_width, int therm_dot) -{ - int xx; - int i; - - xx = x; - v_draw_patch_direct(xx, y, w_cache_lump_name(("M_THERML"), PU_CACHE)); - xx += 8; - for (i = 0; i < therm_width; i++) - { - v_draw_patch_direct(xx, y, w_cache_lump_name(("M_THERMM"), PU_CACHE)); - xx += 8; - } - - v_draw_patch_direct(xx, y, w_cache_lump_name(("M_THERMR"), PU_CACHE)); - - v_draw_patch_direct((x + 8) + therm_dot * 8, y, - w_cache_lump_name(("M_THERMO"), PU_CACHE)); -} - -/* Find string width from hu_font chars */ - -int m_string_width(const char *string) -{ - size_t i; - int w = 0; - int c; - - for (i = 0; i < strlen(string); i++) - { - c = toupper(string[i]) - HU_FONTSTART; - if (c < 0 || c >= HU_FONTSIZE) - w += 4; - else - w += SHORT(hu_font[c]->width); - } - - return w; -} - -/* Find string height from hu_font chars */ - -int m_string_height(const char *string) -{ - size_t i; - int h; - int height = SHORT(hu_font[0]->height); - - h = height; - for (i = 0; i < strlen(string); i++) - { - if (string[i] == '\n') h += height; - } - - return h; -} - -/* Write a string using the hu_font */ - -void m_write_text(int x, int y, const char *string) -{ - int w; - const char *ch; - int c; - int cx; - int cy; - - ch = string; - cx = x; - cy = y; - - while (1) - { - c = *ch++; - if (!c) break; - if (c == '\n') - { - cx = x; - cy += 12; - continue; - } - - c = toupper(c) - HU_FONTSTART; - if (c < 0 || c >= HU_FONTSIZE) - { - cx += 4; - continue; - } - - w = SHORT(hu_font[c]->width); - if (cx + w > SCREENWIDTH) break; - v_draw_patch_direct(cx, cy, hu_font[c]); - cx += w; - } -} - -/* CONTROL PANEL */ - -boolean m_responder(event_t *ev) -{ - int ch; - int key; - int i; - static int mousewait = 0; - static int mousey = 0; - static int lasty = 0; - static int mousex = 0; - static int lastx = 0; - int dir; - - /* In testcontrols mode, none of the function keys should do anything - * - the only key is escape to quit. - */ - - if (testcontrols) - { - if (ev->type == ev_quit || - (ev->type == ev_keydown && - (ev->data1 == key_menu_activate || ev->data1 == key_menu_quit))) - { - i_quit(); - return true; - } - - return false; - } - - /* "close" button pressed on window? */ - - if (ev->type == ev_quit) - { - /* First click on close button = bring up quit confirm message. - * Second click on close button = confirm quit - */ - - if (g_menuactive && g_message_to_print && - message_routine == m_quit_response) - { - m_quit_response(key_menu_confirm); - } - else - { -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(NULL, SFX_SWTCHN); -#endif - m_quit_doom(0); - } - - return true; - } - - /* key is the key pressed, ch is the actual character typed */ - - ch = 0; - key = -1; - - if (ev->type == ev_joystick) - { - /* Simulate key presses from joystick events to interact with the menu. - */ - - if (g_menuactive) - { - if (JOY_GET_DPAD(ev->data6) != JOY_DIR_NONE) - { - dir = JOY_GET_DPAD(ev->data6); - } - else if (JOY_GET_LSTICK(ev->data6) != JOY_DIR_NONE) - { - dir = JOY_GET_LSTICK(ev->data6); - } - else - { - dir = JOY_GET_RSTICK(ev->data6); - } - - if (dir & JOY_DIR_UP) - { - key = key_menu_up; - joywait = i_get_time() + 5; - } - else if (dir & JOY_DIR_DOWN) - { - key = key_menu_down; - joywait = i_get_time() + 5; - } - - if (dir & JOY_DIR_LEFT) - { - key = key_menu_left; - joywait = i_get_time() + 5; - } - else if (dir & JOY_DIR_RIGHT) - { - key = key_menu_right; - joywait = i_get_time() + 5; - } - - if (JOY_BUTTON_PRESSED(joybfire)) - { - /* Simulate a 'Y' keypress when Doom show a Y/N dialog with - * Fire button. - */ - - if (g_message_to_print && g_message_needs_input) - { - key = key_menu_confirm; - } - - /* Simulate pressing "Enter" when we are supplying a save slot - * name - */ - - else if (g_save_string_enter) - { - key = KEY_ENTER; - } - else - { - /* if selecting a save slot via joypad, set a flag */ - - if (g_current_menu == &g_save_def) - { - g_joypad_save = true; - } - - key = key_menu_forward; - } - - joywait = i_get_time() + 5; - } - - if (JOY_BUTTON_PRESSED(joybuse)) - { - /* Simulate a 'N' keypress when Doom show a Y/N dialog with Use - * button. - */ - - if (g_message_to_print && g_message_needs_input) - { - key = key_menu_abort; - } - - /* If user was entering a save name, back out */ - - else if (g_save_string_enter) - { - key = KEY_ESCAPE; - } - else - { - key = key_menu_back; - } - - joywait = i_get_time() + 5; - } - } - - if (JOY_BUTTON_PRESSED(joybmenu)) - { - key = key_menu_activate; - joywait = i_get_time() + 5; - } - } - else - { - if (ev->type == ev_mouse && mousewait < i_get_time() && g_menuactive) - { - mousey += ev->data3; - if (mousey < lasty - 30) - { - key = key_menu_down; - mousewait = i_get_time() + 5; - mousey = lasty -= 30; - } - else if (mousey > lasty + 30) - { - key = key_menu_up; - mousewait = i_get_time() + 5; - mousey = lasty += 30; - } - - mousex += ev->data2; - if (mousex < lastx - 30) - { - key = key_menu_left; - mousewait = i_get_time() + 5; - mousex = lastx -= 30; - } - else if (mousex > lastx + 30) - { - key = key_menu_right; - mousewait = i_get_time() + 5; - mousex = lastx += 30; - } - - if (ev->data1 & 1) - { - key = key_menu_forward; - mousewait = i_get_time() + 15; - } - - if (ev->data1 & 2) - { - key = key_menu_back; - mousewait = i_get_time() + 15; - } - } - else - { - if (ev->type == ev_keydown) - { - key = ev->data1; - ch = ev->data2; - } - } - } - - if (key == -1) return false; - - /* Save Game string input */ - - if (g_save_string_enter) - { - switch (key) - { - case KEY_BACKSPACE: - if (g_save_char_index > 0) - { - g_save_char_index--; - g_save_game_strings[g_save_slot][g_save_char_index] = 0; - } - break; - - case KEY_ESCAPE: - g_save_string_enter = 0; - i_stop_text_input(); - m_str_copy(g_save_game_strings[g_save_slot], g_save_old_string, - SAVESTRINGSIZE); - break; - - case KEY_ENTER: - g_save_string_enter = 0; - i_stop_text_input(); - if (g_save_game_strings[g_save_slot][0]) m_do_save(g_save_slot); - break; - - default: - /* Savegame name entry. This is complicated. - * Vanilla has a bug where the shift key is ignored when entering - * a savegame name. If vanilla_keyboard_mapping is on, we want - * to emulate this bug by using ev->data1. But if it's turned off, - * it implies the user doesn't care about Vanilla emulation: - * instead, use ev->data3 which gives the fully-translated and - * modified key input. - */ - - if (ev->type != ev_keydown) - { - break; - } - - if (vanilla_keyboard_mapping) - { - ch = ev->data1; - } - else - { - ch = ev->data3; - } - - ch = toupper(ch); - - if (ch != ' ' && - (ch - HU_FONTSTART < 0 || ch - HU_FONTSTART >= HU_FONTSIZE)) - { - break; - } - - if (ch >= 32 && ch <= 127 && - g_save_char_index < SAVESTRINGSIZE - 1 && - m_string_width(g_save_game_strings[g_save_slot]) < - (SAVESTRINGSIZE - 2) * 8) - { - g_save_game_strings[g_save_slot][g_save_char_index++] = ch; - g_save_game_strings[g_save_slot][g_save_char_index] = 0; - } - - break; - } - - return true; - } - - /* Take care of any messages that need input */ - - if (g_message_to_print) - { - if (g_message_needs_input) - { - if (key != ' ' && key != KEY_ESCAPE && key != key_menu_confirm && - key != key_menu_abort) - { - return false; - } - } - - g_menuactive = g_message_last_menu_active; - g_message_to_print = 0; - if (message_routine) message_routine(key); - - g_menuactive = false; -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(NULL, SFX_SWTCHX); -#endif - return true; - } - - if ((devparm && key == key_menu_help) || - (key != 0 && key == key_menu_screenshot)) - { - g_screenshot(); - return true; - } - - /* F-Keys */ - - if (!g_menuactive) - { - if (key == key_menu_decscreen) /* Screen size down */ - { - if (automapactive || chat_on) return false; - m_size_display(0); -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(NULL, SFX_STNMOV); -#endif - return true; - } - else if (key == key_menu_incscreen) /* Screen size up */ - { - if (automapactive || chat_on) return false; - m_size_display(1); -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(NULL, SFX_STNMOV); -#endif - return true; - } - else if (key == key_menu_help) /* Help key */ - { - m_start_control_panel(); - - if (gameversion >= exe_ultimate) - g_current_menu = &g_read_def2; - else - g_current_menu = &g_read_def1; - - g_item_on = 0; -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(NULL, SFX_SWTCHN); -#endif - return true; - } - else if (key == key_menu_save) /* Save */ - { - m_start_control_panel(); -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(NULL, SFX_SWTCHN); -#endif - m_save_game(0); - return true; - } - else if (key == key_menu_load) /* Load */ - { - m_start_control_panel(); -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(NULL, SFX_SWTCHN); -#endif - m_load_game(0); - return true; - } - else if (key == key_menu_volume) /* Sound Volume */ - { - m_start_control_panel(); - g_item_on = SOUND_SFXVOL; -#ifdef CONFIG_GAMES_NXDOOM_SOUND - g_current_menu = &g_sound_def; - s_start_sound(NULL, SFX_SWTCHN); -#endif - return true; - } - else if (key == key_menu_detail) /* Detail toggle */ - { - m_change_detail(0); -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(NULL, SFX_SWTCHN); -#endif - return true; - } - else if (key == key_menu_qsave) /* Quicksave */ - { -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(NULL, SFX_SWTCHN); -#endif - m_quick_save(); - return true; - } - else if (key == key_menu_endgame) /* End game */ - { -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(NULL, SFX_SWTCHN); -#endif - m_end_game(0); - return true; - } - else if (key == key_menu_messages) /* Toggle messages */ - { - m_change_messages(0); -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(NULL, SFX_SWTCHN); -#endif - return true; - } - else if (key == key_menu_qload) /* Quickload */ - { -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(NULL, SFX_SWTCHN); -#endif - m_quick_load(); - return true; - } - else if (key == key_menu_quit) /* Quit DOOM */ - { -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(NULL, SFX_SWTCHN); -#endif - m_quit_doom(0); - return true; - } - else if (key == key_menu_gamma) /* gamma toggle */ - { - usegamma++; - if (usegamma > 4) usegamma = 0; - players[consoleplayer].message = (g_gammamsg[usegamma]); - i_set_palette(w_cache_lump_name(("PLAYPAL"), PU_CACHE)); - return true; - } - } - - /* Pop-up menu? */ - - if (!g_menuactive) - { - if (key == key_menu_activate) - { - m_start_control_panel(); -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(NULL, SFX_SWTCHN); -#endif - return true; - } - - return false; - } - - /* Keys usable within menu */ - - if (key == key_menu_down) - { - /* Move down to next item */ - - do - { - if (g_item_on + 1 > g_current_menu->numitems - 1) - g_item_on = 0; - else - g_item_on++; -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(NULL, SFX_PSTOP); -#endif - } - while (g_current_menu->menu_items[g_item_on].status == -1); - - return true; - } - else if (key == key_menu_up) - { - /* Move back up to previous item */ - - do - { - if (!g_item_on) - g_item_on = g_current_menu->numitems - 1; - else - g_item_on--; -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(NULL, SFX_PSTOP); -#endif - } - while (g_current_menu->menu_items[g_item_on].status == -1); - - return true; - } - else if (key == key_menu_left) - { - /* Slide slider left */ - - if (g_current_menu->menu_items[g_item_on].routine && - g_current_menu->menu_items[g_item_on].status == 2) - { -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(NULL, SFX_STNMOV); -#endif - g_current_menu->menu_items[g_item_on].routine(0); - } - - return true; - } - else if (key == key_menu_right) - { - /* Slide slider right */ - - if (g_current_menu->menu_items[g_item_on].routine && - g_current_menu->menu_items[g_item_on].status == 2) - { -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(NULL, SFX_STNMOV); -#endif - g_current_menu->menu_items[g_item_on].routine(1); - } - - return true; - } - else if (key == key_menu_forward) - { - /* Activate menu item */ - - if (g_current_menu->menu_items[g_item_on].routine && - g_current_menu->menu_items[g_item_on].status) - { - g_current_menu->last_on = g_item_on; - if (g_current_menu->menu_items[g_item_on].status == 2) - { - g_current_menu->menu_items[g_item_on].routine( - 1); /* right arrow */ -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(NULL, SFX_STNMOV); -#endif - } - else - { - g_current_menu->menu_items[g_item_on].routine(g_item_on); -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(NULL, SFX_PISTOL); -#endif - } - } - - return true; - } - else if (key == key_menu_activate) - { - /* Deactivate menu */ - - g_current_menu->last_on = g_item_on; - m_clear_menus(); -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(NULL, SFX_SWTCHX); -#endif - return true; - } - else if (key == key_menu_back) - { - /* Go back to previous menu */ - - g_current_menu->last_on = g_item_on; - if (g_current_menu->prev_menu) - { - g_current_menu = g_current_menu->prev_menu; - g_item_on = g_current_menu->last_on; -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(NULL, SFX_SWTCHN); -#endif - } - - return true; - } - - /* Keyboard shortcut? - * Vanilla Doom has a weird behavior where it jumps to the scroll bars - * when the certain keys are pressed, so emulate this. - */ - - else if (ch != 0 || is_null_key(key)) - { - for (i = g_item_on + 1; i < g_current_menu->numitems; i++) - { - if (g_current_menu->menu_items[i].alpha_key == ch) - { - g_item_on = i; -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(NULL, SFX_PSTOP); -#endif - return true; - } - } - - for (i = 0; i <= g_item_on; i++) - { - if (g_current_menu->menu_items[i].alpha_key == ch) - { - g_item_on = i; -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(NULL, SFX_PSTOP); -#endif - return true; - } - } - } - - return false; -} - -void m_start_control_panel(void) -{ - /* intro might call this repeatedly */ - - if (g_menuactive) return; - - g_menuactive = 1; - g_current_menu = &g_main_def; /* JDC */ - g_item_on = g_current_menu->last_on; /* JDC */ -} - -/* Display OPL debug messages - hack for GENMIDI development. */ - -#if 0 -static void m_draw_opl_dev(void) -{ - char debug[1024]; - char *curr; - char *p; - int line; - -#ifdef CONFIG_GAMES_NXDOOM_SOUND - i_opl_dev_messages(debug, sizeof(debug)); -#endif - curr = debug; - line = 0; - - for (; ; ) - { - p = strchr(curr, '\n'); - - if (p != NULL) - { - *p = '\0'; - } - - m_write_text(0, line * 8, curr); - ++line; - - if (p == NULL) - { - break; - } - - curr = p + 1; - } -} -#endif - -/* m_drawer - * Called after the view has been rendered, - * but before it has been blitted. - */ - -void m_drawer(void) -{ - static short x; - static short y; - unsigned int i; - unsigned int max; - char string[80]; - const char *name; - int start; - - inhelpscreens = false; - - /* Horiz. & Vertically center string and print it. */ - - if (g_message_to_print) - { - start = 0; - y = SCREENHEIGHT / 2 - m_string_height(g_message_string) / 2; - while (g_message_string[start] != '\0') - { - boolean foundnewline = false; - - for (i = 0; g_message_string[start + i] != '\0'; i++) - { - if (g_message_string[start + i] == '\n') - { - m_str_copy(string, g_message_string + start, - sizeof(string)); - if (i < sizeof(string)) - { - string[i] = '\0'; - } - - foundnewline = true; - start += i + 1; - break; - } - } - - if (!foundnewline) - { - m_str_copy(string, g_message_string + start, sizeof(string)); - start += strlen(string); - } - - x = SCREENWIDTH / 2 - m_string_width(string) / 2; - m_write_text(x, y, string); - y += SHORT(hu_font[0]->height); - } - - return; - } - - if (!g_menuactive) return; - - if (g_current_menu->routine) - g_current_menu->routine(); /* call Draw routine */ - - /* DRAW MENU */ - - x = g_current_menu->x; - y = g_current_menu->y; - max = g_current_menu->numitems; - - for (i = 0; i < max; i++) - { - name = (g_current_menu->menu_items[i].name); - - if (name[0] && w_check_num_for_name(name) > 0) - { - v_draw_patch_direct(x, y, w_cache_lump_name(name, PU_CACHE)); - } - - y += LINEHEIGHT; - } - - /* DRAW SKULL */ - - v_draw_patch_direct( - x + SKULLXOFF, g_current_menu->y - 5 + g_item_on * LINEHEIGHT, - w_cache_lump_name((g_skull_name[g_which_skull]), PU_CACHE)); -} - -void m_clear_menus(void) -{ - g_menuactive = 0; -} - -void m_setup_next_menu(menu_t *menudef) -{ - g_current_menu = menudef; - g_item_on = g_current_menu->last_on; -} - -void m_ticker(void) -{ - if (--g_skull_anim_counter <= 0) - { - g_which_skull ^= 1; - g_skull_anim_counter = 8; - } -} - -void m_init(void) -{ - g_current_menu = &g_main_def; - g_menuactive = 0; - g_item_on = g_current_menu->last_on; - g_which_skull = 0; - g_skull_anim_counter = 10; - g_screen_size = screenblocks - 3; - g_message_to_print = 0; - g_message_string = NULL; - g_message_last_menu_active = g_menuactive; - g_quick_save_slot = -1; - - /* Here we could catch other version dependencies, like HELP1/2, and four - * episodes. - */ - - /* The same hacks were used in the original Doom EXEs. */ - - if (gameversion >= exe_ultimate) - { - g_main_menu[MAIN_READTHIS].routine = m_read_this2; - g_read_def2.prev_menu = NULL; - } - - if (gameversion >= exe_final && gameversion <= exe_final2) - { - g_read_def2.routine = m_draw_read_this_commercial; - } - - if (gamemode == commercial) - { - g_main_menu[MAIN_READTHIS] = g_main_menu[MAIN_QUITDOOM]; - g_main_def.numitems--; - g_main_def.y += 8; - g_new_def.prev_menu = &g_main_def; - g_read_def1.routine = m_draw_read_this_commercial; - g_read_def1.x = 330; - g_read_def1.y = 165; - g_read_menu1[RDTHSEMPTY1].routine = m_finish_read_this; - } - - /* Versions of doom.exe before the Ultimate Doom release only had - * three episodes; if we're emulating one of those then don't try - * to show episode four. If we are, then do show episode four - * (should crash if missing). - */ - - if (gameversion < exe_ultimate) - { - g_epi_def.numitems--; - } - - /* chex.exe shows only one episode. */ - - else if (gameversion == exe_chex) - { - g_epi_def.numitems = 1; - } -} diff --git a/games/NXDoom/src/doom/m_menu.h b/games/NXDoom/src/doom/m_menu.h deleted file mode 100644 index 545f3eb8a..000000000 --- a/games/NXDoom/src/doom/m_menu.h +++ /dev/null @@ -1,76 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/m_menu.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Menu widget stuff, episode selection and such. - * - ****************************************************************************/ - -#ifndef __M_MENU__ -#define __M_MENU__ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "d_event.h" - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -extern int g_detail_level; -extern int screenblocks; - -extern boolean inhelpscreens; -extern int g_show_messages; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/* MENUS - * - * Called by main loop, - * saves config file and calls i_quit when user exits. - * Even when the menu is not displayed, - * this can resize the view and change game parameters. - * Does all the real work of the menu interaction. - */ - -boolean m_responder(event_t *ev); - -/* Called by main loop, only used for menu (skull cursor) animation. */ - -void m_ticker(void); - -/* Called by main loop, draws the menus directly into the screen buffer. */ - -void m_drawer(void); - -/* Called by d_doom_main, loads the config file. */ - -void m_init(void); - -/* Called by intro code to force menu up upon a keypress, does nothing if - * menu is already up. - */ - -void m_start_control_panel(void); - -#endif /* __M_MENU__ */ diff --git a/games/NXDoom/src/doom/m_random.c b/games/NXDoom/src/doom/m_random.c deleted file mode 100644 index 1c846cc0c..000000000 --- a/games/NXDoom/src/doom/m_random.c +++ /dev/null @@ -1,90 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/m_random.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Random number LUT. - * - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/* m_random - * Returns a 0-255 number - */ - -static const unsigned char rndtable[256] = -{ - 0, 8, 109, 220, 222, 241, 149, 107, 75, 248, 254, 140, 16, 66, 74, - 21, 211, 47, 80, 242, 154, 27, 205, 128, 161, 89, 77, 36, 95, 110, - 85, 48, 212, 140, 211, 249, 22, 79, 200, 50, 28, 188, 52, 140, 202, - 120, 68, 145, 62, 70, 184, 190, 91, 197, 152, 224, 149, 104, 25, 178, - 252, 182, 202, 182, 141, 197, 4, 81, 181, 242, 145, 42, 39, 227, 156, - 198, 225, 193, 219, 93, 122, 175, 249, 0, 175, 143, 70, 239, 46, 246, - 163, 53, 163, 109, 168, 135, 2, 235, 25, 92, 20, 145, 138, 77, 69, - 166, 78, 176, 173, 212, 166, 113, 94, 161, 41, 50, 239, 49, 111, 164, - 70, 60, 2, 37, 171, 75, 136, 156, 11, 56, 42, 146, 138, 229, 73, - 146, 77, 61, 98, 196, 135, 106, 63, 197, 195, 86, 96, 203, 113, 101, - 170, 247, 181, 113, 80, 250, 108, 7, 255, 237, 129, 226, 79, 107, 112, - 166, 103, 241, 24, 223, 239, 120, 198, 58, 60, 82, 128, 3, 184, 66, - 143, 224, 145, 224, 81, 206, 163, 45, 63, 90, 168, 114, 59, 33, 159, - 95, 28, 139, 123, 98, 125, 196, 15, 70, 194, 253, 54, 14, 109, 226, - 71, 17, 161, 93, 186, 87, 244, 138, 20, 52, 123, 251, 26, 36, 17, - 46, 52, 231, 232, 76, 31, 221, 84, 37, 216, 165, 212, 106, 197, 242, - 98, 43, 39, 175, 254, 145, 190, 84, 118, 222, 187, 136, 120, 163, 236, - 249, -}; - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -int rndindex = 0; -int prndindex = 0; - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/* Which one is deterministic? */ - -int p_random(void) -{ - prndindex = (prndindex + 1) & 0xff; - return rndtable[prndindex]; -} - -int m_random(void) -{ - rndindex = (rndindex + 1) & 0xff; - return rndtable[rndindex]; -} - -void m_clear_random(void) -{ - rndindex = prndindex = 0; -} - -/* inspired by the same routine in Eternity, thanks haleyjd */ - -int p_sub_random(void) -{ - int r = p_random(); - return r - p_random(); -} diff --git a/games/NXDoom/src/doom/m_random.h b/games/NXDoom/src/doom/m_random.h deleted file mode 100644 index f5f5cf74a..000000000 --- a/games/NXDoom/src/doom/m_random.h +++ /dev/null @@ -1,50 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/m_random.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - ****************************************************************************/ - -#ifndef __M_RANDOM__ -#define __M_RANDOM__ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "doomtype.h" - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/* Returns a number from 0 to 255, from a lookup table. */ - -int m_random(void); - -/* As m_random, but used only by the play simulation. */ - -int p_random(void); - -/* Fix randoms for demos. */ - -void m_clear_random(void); - -/* Defined version of p_random() - p_random() */ - -int p_sub_random(void); - -#endif /* __M_RANDOM__ */ diff --git a/games/NXDoom/src/doom/p_ceilng.c b/games/NXDoom/src/doom/p_ceilng.c deleted file mode 100644 index 582ad604e..000000000 --- a/games/NXDoom/src/doom/p_ceilng.c +++ /dev/null @@ -1,327 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/p_ceilng.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: Ceiling aninmation (lowering, crushing, raising) - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "doomdef.h" -#include "p_local.h" -#include "z_zone.h" - -#ifdef CONFIG_GAMES_NXDOOM_SOUND -#include "s_sound.h" -#include "sounds.h" -#endif - -/* State. */ - -#include "doomstat.h" -#include "r_state.h" - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/* CEILINGS */ - -ceiling_t *activeceilings[MAXCEILINGS]; - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/* t_move_ceiling */ - -void t_move_ceiling(ceiling_t *ceiling) -{ - result_e res; - - switch (ceiling->direction) - { - case 0: /* IN STASIS */ - break; - case 1: /* UP */ - res = t_move_plane(ceiling->sector, ceiling->speed, ceiling->topheight, - false, 1, ceiling->direction); - - if (!(leveltime & 7)) - { - switch (ceiling->type) - { - case CEIL_SILENTCRUSHANDRAISE: - break; - default: -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(&ceiling->sector->soundorg, SFX_STNMOV); -#endif - /* ? */ - - break; - } - } - - if (res == pastdest) - { - switch (ceiling->type) - { - case CEIL_RAISETOHIGHEST: - p_remove_active_ceiling(ceiling); - break; - - case CEIL_SILENTCRUSHANDRAISE: -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(&ceiling->sector->soundorg, SFX_PSTOP); -#endif - case CEIL_FASTCRUSHANDRAISE: - case CEIL_CRUSHANDRAISE: - ceiling->direction = -1; - break; - - default: - break; - } - } - break; - - case -1: /* DOWN */ - res = t_move_plane(ceiling->sector, ceiling->speed, - ceiling->bottomheight, ceiling->crush, 1, ceiling->direction); - - if (!(leveltime & 7)) - { - switch (ceiling->type) - { - case CEIL_SILENTCRUSHANDRAISE: - break; -#ifdef CONFIG_GAMES_NXDOOM_SOUND - default: - s_start_sound(&ceiling->sector->soundorg, SFX_STNMOV); -#else - default: - break; -#endif - } - } - - if (res == pastdest) - { - switch (ceiling->type) - { - case CEIL_SILENTCRUSHANDRAISE: -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(&ceiling->sector->soundorg, SFX_PSTOP); -#endif - case CEIL_CRUSHANDRAISE: - ceiling->speed = CEILSPEED; - case CEIL_FASTCRUSHANDRAISE: - ceiling->direction = 1; - break; - - case CEIL_LOWERANDCRUSH: - case CEIL_LOWERTOFLOOR: - p_remove_active_ceiling(ceiling); - break; - - default: - break; - } - } - else /* ( res != pastdest ) */ - { - if (res == crushed) - { - switch (ceiling->type) - { - case CEIL_SILENTCRUSHANDRAISE: - case CEIL_CRUSHANDRAISE: - case CEIL_LOWERANDCRUSH: - ceiling->speed = CEILSPEED / 8; - break; - - default: - break; - } - } - } - break; - } -} - -/* ev_do_ceiling - * Move a ceiling up/down and all around! - */ - -int ev_do_ceiling(line_t *line, ceiling_e type) -{ - int secnum; - int rtn; - sector_t *sec; - ceiling_t *ceiling; - - secnum = -1; - rtn = 0; - - /* Reactivate in-stasis ceilings... for certain types. */ - - switch (type) - { - case CEIL_FASTCRUSHANDRAISE: - case CEIL_SILENTCRUSHANDRAISE: - case CEIL_CRUSHANDRAISE: - p_activate_in_stasis_ceiling(line); - default: - break; - } - - while ((secnum = p_find_sector_from_line_tag(line, secnum)) >= 0) - { - sec = §ors[secnum]; - if (sec->specialdata) continue; - - /* new door thinker */ - - rtn = 1; - ceiling = z_malloc(sizeof(*ceiling), PU_LEVSPEC, 0); - p_add_thinker(&ceiling->thinker); - sec->specialdata = ceiling; - ceiling->thinker.function.acp1 = (actionf_p1)t_move_ceiling; - ceiling->sector = sec; - ceiling->crush = false; - - switch (type) - { - case CEIL_FASTCRUSHANDRAISE: - ceiling->crush = true; - ceiling->topheight = sec->ceilingheight; - ceiling->bottomheight = sec->floorheight + (8 * FRACUNIT); - ceiling->direction = -1; - ceiling->speed = CEILSPEED * 2; - break; - - case CEIL_SILENTCRUSHANDRAISE: - case CEIL_CRUSHANDRAISE: - ceiling->crush = true; - ceiling->topheight = sec->ceilingheight; - case CEIL_LOWERANDCRUSH: - case CEIL_LOWERTOFLOOR: - ceiling->bottomheight = sec->floorheight; - if (type != CEIL_LOWERTOFLOOR) - { - ceiling->bottomheight += 8 * FRACUNIT; - } - - ceiling->direction = -1; - ceiling->speed = CEILSPEED; - break; - - case CEIL_RAISETOHIGHEST: - ceiling->topheight = p_find_heighest_ceiling_surrounding(sec); - ceiling->direction = 1; - ceiling->speed = CEILSPEED; - break; - } - - ceiling->tag = sec->tag; - ceiling->type = type; - p_add_active_ceiling(ceiling); - } - - return rtn; -} - -/* Add an active ceiling */ - -void p_add_active_ceiling(ceiling_t *c) -{ - int i; - - for (i = 0; i < MAXCEILINGS; i++) - { - if (activeceilings[i] == NULL) - { - activeceilings[i] = c; - return; - } - } -} - -/* Remove a ceiling's thinker */ - -void p_remove_active_ceiling(ceiling_t *c) -{ - int i; - - for (i = 0; i < MAXCEILINGS; i++) - { - if (activeceilings[i] == c) - { - activeceilings[i]->sector->specialdata = NULL; - p_remove_thinker(&activeceilings[i]->thinker); - activeceilings[i] = NULL; - break; - } - } -} - -/* Restart a ceiling that's in-stasis */ - -void p_activate_in_stasis_ceiling(line_t *line) -{ - int i; - - for (i = 0; i < MAXCEILINGS; i++) - { - if (activeceilings[i] && (activeceilings[i]->tag == line->tag) && - (activeceilings[i]->direction == 0)) - { - activeceilings[i]->direction = activeceilings[i]->olddirection; - activeceilings[i]->thinker.function.acp1 = - (actionf_p1)t_move_ceiling; - } - } -} - -/* ev_ceiling_crush_stop - * Stop a ceiling from crushing! - */ - -int ev_ceiling_crush_stop(line_t *line) -{ - int i; - int rtn; - - rtn = 0; - for (i = 0; i < MAXCEILINGS; i++) - { - if (activeceilings[i] && (activeceilings[i]->tag == line->tag) && - (activeceilings[i]->direction != 0)) - { - activeceilings[i]->olddirection = activeceilings[i]->direction; - activeceilings[i]->thinker.function.acv = (actionf_v)NULL; - activeceilings[i]->direction = 0; /* in-stasis */ - rtn = 1; - } - } - - return rtn; -} diff --git a/games/NXDoom/src/doom/p_doors.c b/games/NXDoom/src/doom/p_doors.c deleted file mode 100644 index 324fefa4b..000000000 --- a/games/NXDoom/src/doom/p_doors.c +++ /dev/null @@ -1,802 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/p_doors.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: Door animation code (opening/closing) - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "deh_main.h" -#include "doomdef.h" -#include "i_system.h" -#include "p_local.h" -#include "z_zone.h" - -#ifdef CONFIG_GAMES_NXDOOM_SOUND -#include "s_sound.h" -#include "sounds.h" -#endif - -/* State. */ - -#include "doomstat.h" -#include "r_state.h" - -/* Data. */ - -#include "dstrings.h" - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/* Sliding door frame information */ - -#if 0 -slidename_t g_slide_frame_names[MAXSLIDEDOORS] = -{ -{ - "GDOORF1", "GDOORF2", "GDOORF3", "GDOORF4", /* front */ - "GDOORB1", "GDOORB2", "GDOORB3", "GDOORB4" /* back */ -}, -{ - "\0", "\0", "\0", "\0" -} -}; - -slideframe_t g_slide_frames[MAXSLIDEDOORS]; -#endif - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/* VERTICAL DOORS */ - -void t_vertical_door(vldoor_t *door) -{ - result_e res; - - switch (door->direction) - { - case 0: /* WAITING */ - if (!--door->topcountdown) - { - switch (door->type) - { - case VLD_BLAZERAISE: - door->direction = -1; /* time to go back down */ -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(&door->sector->soundorg, SFX_BDCLS); -#endif - break; - - case VLD_NORMAL: - door->direction = -1; /* time to go back down */ -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(&door->sector->soundorg, SFX_DORCLS); -#endif - break; - - case VLD_CLOSE30THENOPEN: - door->direction = 1; -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(&door->sector->soundorg, SFX_DOROPN); -#endif - break; - - default: - break; - } - } - break; - - case 2: /* INITIAL WAIT */ - if (!--door->topcountdown) - { - switch (door->type) - { - case VLD_RAISEIN5MINS: - door->direction = 1; - door->type = VLD_NORMAL; -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(&door->sector->soundorg, SFX_DOROPN); -#endif - break; - - default: - break; - } - } - - break; - - case -1: /* DOWN */ - res = t_move_plane(door->sector, door->speed, - door->sector->floorheight, false, 1, door->direction); - - if (res == pastdest) - { - switch (door->type) - { - case VLD_BLAZERAISE: - case VLD_BLAZECLOSE: - door->sector->specialdata = NULL; - p_remove_thinker(&door->thinker); /* unlink and free */ -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(&door->sector->soundorg, SFX_BDCLS); -#endif - break; - - case VLD_NORMAL: - case VLD_CLOSE: - door->sector->specialdata = NULL; - p_remove_thinker(&door->thinker); /* unlink and free */ - break; - - case VLD_CLOSE30THENOPEN: - door->direction = 0; - door->topcountdown = TICRATE * 30; - break; - - default: - break; - } - } - else if (res == crushed) - { - switch (door->type) - { - case VLD_BLAZECLOSE: - case VLD_CLOSE: /* DO NOT GO BACK UP! */ - break; - - default: - door->direction = 1; -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(&door->sector->soundorg, SFX_DOROPN); -#endif - break; - } - } - break; - - case 1: /* UP */ - res = t_move_plane(door->sector, door->speed, door->topheight, - false, 1, door->direction); - - if (res == pastdest) - { - switch (door->type) - { - case VLD_BLAZERAISE: - case VLD_NORMAL: - door->direction = 0; /* wait at top */ - door->topcountdown = door->topwait; - break; - - case VLD_CLOSE30THENOPEN: - case VLD_BLAZEOPEN: - case VLD_OPEN: - door->sector->specialdata = NULL; - p_remove_thinker(&door->thinker); /* unlink and free */ - break; - - default: - break; - } - } - - break; - } -} - -/* ev_do_locked_door - * Move a locked door up/down - */ - -int ev_do_locked_door(line_t *line, vldoor_e type, mobj_t *thing) -{ - player_t *p; - - p = thing->player; - - if (!p) return 0; - - switch (line->special) - { - case 99: /* Blue Lock */ - case 133: - if (!p->cards[it_bluecard] && !p->cards[it_blueskull]) - { - p->message = (PD_BLUEO); -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(NULL, SFX_OOF); -#endif - return 0; - } - break; - - case 134: /* Red Lock */ - case 135: - if (!p->cards[it_redcard] && !p->cards[it_redskull]) - { - p->message = (PD_REDO); -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(NULL, SFX_OOF); -#endif - return 0; - } - break; - - case 136: /* Yellow Lock */ - case 137: - if (!p->cards[it_yellowcard] && !p->cards[it_yellowskull]) - { - p->message = (PD_YELLOWO); -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(NULL, SFX_OOF); -#endif - return 0; - } - - break; - } - - return ev_do_door(line, type); -} - -int ev_do_door(line_t *line, vldoor_e type) -{ - int secnum; - int rtn; - sector_t *sec; - vldoor_t *door; - - secnum = -1; - rtn = 0; - - while ((secnum = p_find_sector_from_line_tag(line, secnum)) >= 0) - { - sec = §ors[secnum]; - if (sec->specialdata) continue; - - /* new door thinker */ - - rtn = 1; - door = z_malloc(sizeof(*door), PU_LEVSPEC, 0); - p_add_thinker(&door->thinker); - sec->specialdata = door; - - door->thinker.function.acp1 = (actionf_p1)t_vertical_door; - door->sector = sec; - door->type = type; - door->topwait = VDOORWAIT; - door->speed = VDOORSPEED; - - switch (type) - { - case VLD_BLAZECLOSE: - door->topheight = p_find_lowest_ceiling_surrounding(sec); - door->topheight -= 4 * FRACUNIT; - door->direction = -1; - door->speed = VDOORSPEED * 4; -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(&door->sector->soundorg, SFX_BDCLS); -#endif - break; - - case VLD_CLOSE: - door->topheight = p_find_lowest_ceiling_surrounding(sec); - door->topheight -= 4 * FRACUNIT; - door->direction = -1; -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(&door->sector->soundorg, SFX_DORCLS); -#endif - break; - - case VLD_CLOSE30THENOPEN: - door->topheight = sec->ceilingheight; - door->direction = -1; -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(&door->sector->soundorg, SFX_DORCLS); -#endif - break; - - case VLD_BLAZERAISE: - case VLD_BLAZEOPEN: - door->direction = 1; - door->topheight = p_find_lowest_ceiling_surrounding(sec); - door->topheight -= 4 * FRACUNIT; - door->speed = VDOORSPEED * 4; -#ifdef CONFIG_GAMES_NXDOOM_SOUND - if (door->topheight != sec->ceilingheight) - s_start_sound(&door->sector->soundorg, SFX_BDOPN); -#endif - break; - - case VLD_NORMAL: - case VLD_OPEN: - door->direction = 1; - door->topheight = p_find_lowest_ceiling_surrounding(sec); - door->topheight -= 4 * FRACUNIT; -#ifdef CONFIG_GAMES_NXDOOM_SOUND - if (door->topheight != sec->ceilingheight) - s_start_sound(&door->sector->soundorg, SFX_DOROPN); -#endif - break; - - default: - break; - } - } - - return rtn; -} - -/* ev_vertical_door : open a door manually, no tag value */ - -void ev_vertical_door(line_t *line, mobj_t *thing) -{ - player_t *player; - sector_t *sec; - vldoor_t *door; - int side; - - side = 0; /* only front sides can be used */ - - /* Check for locks */ - - player = thing->player; - - switch (line->special) - { - case 26: /* Blue Lock */ - case 32: - if (!player) return; - - if (!player->cards[it_bluecard] && !player->cards[it_blueskull]) - { - player->message = (PD_BLUEK); -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(NULL, SFX_OOF); -#endif - return; - } - break; - - case 27: /* Yellow Lock */ - case 34: - if (!player) return; - - if (!player->cards[it_yellowcard] && !player->cards[it_yellowskull]) - { - player->message = (PD_YELLOWK); -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(NULL, SFX_OOF); -#endif - return; - } - break; - - case 28: /* Red Lock */ - case 33: - if (!player) return; - - if (!player->cards[it_redcard] && !player->cards[it_redskull]) - { - player->message = (PD_REDK); -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(NULL, SFX_OOF); -#endif - return; - } - break; - } - - /* if the sector has an active thinker, use it */ - - if (line->sidenum[side ^ 1] == -1) - { - i_error("ev_vertical_door: DR special type on 1-sided linedef"); - } - - sec = sides[line->sidenum[side ^ 1]].sector; - - if (sec->specialdata) - { - door = sec->specialdata; - switch (line->special) - { - case 1: /* ONLY FOR "RAISE" DOORS, NOT "OPEN"s */ - case 26: - case 27: - case 28: - case 117: - if (door->direction == -1) - door->direction = 1; /* go back up */ - else - { - if (!thing->player) return; /* JDC: bad guys never close doors */ - - /* When is a door not a door? - * In Vanilla, door->direction is set, even though - * "specialdata" might not actually point at a door. - */ - - if (door->thinker.function.acp1 == - (actionf_p1)t_vertical_door) - { - door->direction = -1; /* start going down immediately */ - } - else if (door->thinker.function.acp1 == - (actionf_p1)t_plat_raise) - { - /* Erm, this is a plat, not a door. - * This notably causes a problem in ep1-0500.lmp where - * a plat and a door are cross-referenced; the door - * doesn't open on 64-bit. - * The direction field in vldoor_t corresponds to the wait - * field in plat_t. Let's set that to -1 instead. - */ - - plat_t *plat; - - plat = (plat_t *)door; - plat->wait = -1; - } - else - { - /* This isn't a door OR a plat. Now we're in trouble. */ - - fprintf(stderr, "ev_vertical_door: Tried to close " - "something that wasn't a door.\n"); - - /* Try closing it anyway. At least it will work on 32-bit - * machines. - */ - - door->direction = -1; - } - } - - return; - } - } - -#ifdef CONFIG_GAMES_NXDOOM_SOUND - /* for proper sound */ - - switch (line->special) - { - case 117: /* BLAZING DOOR RAISE */ - case 118: /* BLAZING DOOR OPEN */ - s_start_sound(&sec->soundorg, SFX_BDOPN); - break; - - case 1: /* NORMAL DOOR SOUND */ - case 31: - s_start_sound(&sec->soundorg, SFX_DOROPN); - break; - - default: /* LOCKED DOOR SOUND */ - s_start_sound(&sec->soundorg, SFX_DOROPN); - break; - } -#endif - - /* new door thinker */ - - door = z_malloc(sizeof(*door), PU_LEVSPEC, 0); - p_add_thinker(&door->thinker); - sec->specialdata = door; - door->thinker.function.acp1 = (actionf_p1)t_vertical_door; - door->sector = sec; - door->direction = 1; - door->speed = VDOORSPEED; - door->topwait = VDOORWAIT; - - switch (line->special) - { - case 1: - case 26: - case 27: - case 28: - door->type = VLD_NORMAL; - break; - - case 31: - case 32: - case 33: - case 34: - door->type = VLD_OPEN; - line->special = 0; - break; - - case 117: /* blazing door raise */ - door->type = VLD_BLAZERAISE; - door->speed = VDOORSPEED * 4; - break; - case 118: /* blazing door open */ - door->type = VLD_BLAZEOPEN; - line->special = 0; - door->speed = VDOORSPEED * 4; - break; - } - - /* find the top and bottom of the movement range */ - - door->topheight = p_find_lowest_ceiling_surrounding(sec); - door->topheight -= 4 * FRACUNIT; -} - -/* Spawn a door that closes after 30 seconds */ - -void p_spawn_door_close_in30(sector_t *sec) -{ - vldoor_t *door; - - door = z_malloc(sizeof(*door), PU_LEVSPEC, 0); - - p_add_thinker(&door->thinker); - - sec->specialdata = door; - sec->special = 0; - - door->thinker.function.acp1 = (actionf_p1)t_vertical_door; - door->sector = sec; - door->direction = 0; - door->type = VLD_NORMAL; - door->speed = VDOORSPEED; - door->topcountdown = 30 * TICRATE; -} - -/* Spawn a door that opens after 5 minutes */ - -void p_spawn_door_raise_in_5min(sector_t *sec, int secnum) -{ - vldoor_t *door; - - door = z_malloc(sizeof(*door), PU_LEVSPEC, 0); - - p_add_thinker(&door->thinker); - - sec->specialdata = door; - sec->special = 0; - - door->thinker.function.acp1 = (actionf_p1)t_vertical_door; - door->sector = sec; - door->direction = 2; - door->type = VLD_RAISEIN5MINS; - door->speed = VDOORSPEED; - door->topheight = p_find_lowest_ceiling_surrounding(sec); - door->topheight -= 4 * FRACUNIT; - door->topwait = VDOORWAIT; - door->topcountdown = 5 * 60 * TICRATE; -} - -/* UNUSED - * Separate into p_slidoor.c? - */ - -#if 0 /* ABANDONED TO THE MISTS OF TIME!!! */ - -/* ev_sliding_door : slide a door horizontally - * (animate midtexture, then set noblocking line) - */ - -void p_init_sliding_door_frames(void) -{ - int i; - int f1; - int f2; - int f3; - int f4; - - /* DOOM II ONLY... */ - - if (gamemode != commercial) return; - - for (i = 0; i < MAXSLIDEDOORS; i++) - { - if (!g_slide_frame_names[i].front_frame1[0]) break; - - f1 = r_texture_num_for_name(g_slide_frame_names[i].front_frame1); - f2 = r_texture_num_for_name(g_slide_frame_names[i].front_frame2); - f3 = r_texture_num_for_name(g_slide_frame_names[i].front_frame3); - f4 = r_texture_num_for_name(g_slide_frame_names[i].front_frame4); - - g_slide_frames[i].front_frames[0] = f1; - g_slide_frames[i].front_frames[1] = f2; - g_slide_frames[i].front_frames[2] = f3; - g_slide_frames[i].front_frames[3] = f4; - - f1 = r_texture_num_for_name(g_slide_frame_names[i].back_frame1); - f2 = r_texture_num_for_name(g_slide_frame_names[i].back_frame2); - f3 = r_texture_num_for_name(g_slide_frame_names[i].back_frame3); - f4 = r_texture_num_for_name(g_slide_frame_names[i].back_frame4); - - g_slide_frames[i].back_frames[0] = f1; - g_slide_frames[i].back_frames[1] = f2; - g_slide_frames[i].back_frames[2] = f3; - g_slide_frames[i].back_frames[3] = f4; - } -} - -/* Return index into "g_slide_frames" array for which door type to use */ - -static int p_find_sliding_door(line_t *line) -{ - int i; - int val; - - for (i = 0; i < MAXSLIDEDOORS; i++) - { - val = sides[line->sidenum[0]].midtexture; - if (val == g_slide_frames[i].front_frames[0]) return i; - } - - return -1; -} - -static void t_sliding_door(slidedoor_t *door) -{ - switch (door->status) - { - case sd_opening: - if (!door->timer--) - { - if (++door->frame == SNUMFRAMES) - { - /* IF DOOR IS DONE OPENING... */ - - sides[door->line->sidenum[0]].midtexture = 0; - sides[door->line->sidenum[1]].midtexture = 0; - door->line->flags &= ML_BLOCKING ^ 0xff; - - if (door->type == SDT_OPENONLY) - { - door->frontsector->specialdata = NULL; - p_remove_thinker(&door->thinker); - break; - } - - door->timer = SDOORWAIT; - door->status = sd_waiting; - } - else - { - /* IF DOOR NEEDS TO ANIMATE TO NEXT FRAME... */ - - door->timer = SWAITTICS; - - sides[door->line->sidenum[0]].midtexture = - g_slide_frames[door->which_door_index] - .front_frames[door->frame]; - sides[door->line->sidenum[1]].midtexture = - g_slide_frames[door->which_door_index] - .back_frames[door->frame]; - } - } - break; - - case sd_waiting: - - /* IF DOOR IS DONE WAITING... */ - - if (!door->timer--) - { - /* CAN DOOR CLOSE? */ - - if (door->frontsector->thinglist != NULL || - door->backsector->thinglist != NULL) - { - door->timer = SDOORWAIT; - break; - } - - /* door->frame = SNUMFRAMES-1; */ - - door->status = sd_closing; - door->timer = SWAITTICS; - } - break; - - case sd_closing: - if (!door->timer--) - { - if (--door->frame < 0) - { - /* IF DOOR IS DONE CLOSING... */ - - door->line->flags |= ML_BLOCKING; - door->frontsector->specialdata = NULL; - p_remove_thinker(&door->thinker); - break; - } - else - { - /* IF DOOR NEEDS TO ANIMATE TO NEXT FRAME... */ - - door->timer = SWAITTICS; - - sides[door->line->sidenum[0]].midtexture = - g_slide_frames[door->which_door_index] - .front_frames[door->frame]; - sides[door->line->sidenum[1]].midtexture = - g_slide_frames[door->which_door_index] - .back_frames[door->frame]; - } - } - break; - } -} - -void ev_sliding_door(line_t *line, mobj_t *thing) -{ - sector_t *sec; - slidedoor_t *door; - - /* DOOM II ONLY... */ - - if (gamemode != commercial) return; - - /* Make sure door isn't already being animated */ - - sec = line->frontsector; - door = NULL; - if (sec->specialdata) - { - if (!thing->player) return; - - door = sec->specialdata; - if (door->type == SDT_OPENANDCLOSE) - { - if (door->status == sd_waiting) door->status = sd_closing; - } - else - return; - } - - /* Init sliding door vars */ - - if (!door) - { - door = z_malloc(sizeof(*door), PU_LEVSPEC, 0); - p_add_thinker(&door->thinker); - sec->specialdata = door; - - door->type = SDT_OPENANDCLOSE; - door->status = sd_opening; - door->which_door_index = p_find_sliding_door(line); - - if (door->which_door_index < 0) - i_error("ev_sliding_door: Can't use texture for sliding door!"); - - door->frontsector = sec; - door->backsector = line->backsector; - door->thinker.function = t_sliding_door; - door->timer = SWAITTICS; - door->frame = 0; - door->line = line; - } -} -#endif /* UNUSED */ diff --git a/games/NXDoom/src/doom/p_enemy.c b/games/NXDoom/src/doom/p_enemy.c deleted file mode 100644 index cf10325af..000000000 --- a/games/NXDoom/src/doom/p_enemy.c +++ /dev/null @@ -1,1932 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/p_enemy.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Enemy thinking, AI. - * Action Pointer Functions - * that are associated with states/frames. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -#include "i_system.h" -#include "m_random.h" - -#include "doomdef.h" -#include "p_local.h" - -#ifdef CONFIG_GAMES_NXDOOM_SOUND -#include "s_sound.h" -#include "sounds.h" -#endif - -#include "g_game.h" - -/* State. */ - -#include "doomstat.h" -#include "r_state.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define TRACEANGLE 0xc000000 - -#define FATSPREAD (ANG90 / 8) - -#define SKULLSPEED (20 * FRACUNIT) - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/* Data. */ - -typedef enum -{ - DI_EAST, - DI_NORTHEAST, - DI_NORTH, - DI_NORTHWEST, - DI_WEST, - DI_SOUTHWEST, - DI_SOUTH, - DI_SOUTHEAST, - DI_NODIR, - NUMDIRS -} dirtype_t; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -void a_fall(mobj_t *actor); -void a_refire(player_t *player, pspdef_t *psp); - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/* p_new_chase_dir related LUT. */ - -dirtype_t opposite[] = -{ - DI_WEST, DI_SOUTHWEST, DI_SOUTH, DI_SOUTHEAST, DI_EAST, - DI_NORTHEAST, DI_NORTH, DI_NORTHWEST, DI_NODIR, -}; - -dirtype_t diags[] = -{ - DI_NORTHWEST, - DI_NORTHEAST, - DI_SOUTHWEST, - DI_SOUTHEAST, -}; - -/* ENEMY THINKING - * Enemies are always spawned with targetplayer = -1, threshold = 0 - * Most monsters are spawned unaware of all players, but some can be made - * preaware - */ - -/* Called by p_noise_alert. - * Recursively traverse adjacent sectors, sound blocking lines cut off - * traversal. - */ - -mobj_t *soundtarget; - -fixed_t xspeed[8] = -{ - FRACUNIT, 47000, 0, -47000, -FRACUNIT, -47000, 0, 47000 -}; - -fixed_t yspeed[8] = -{ - 0, 47000, FRACUNIT, 47000, 0, -47000, -FRACUNIT, -47000 -}; - -mobj_t *corpsehit; -mobj_t *vileobj; -fixed_t viletryx; -fixed_t viletryy; - -mobj_t *braintargets[32]; -int numbraintargets; -int braintargeton = 0; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static void p_recursive_sound(sector_t *sec, int soundblocks) -{ - int i; - line_t *check; - sector_t *other; - - /* wake up all monsters in this sector */ - - if (sec->validcount == validcount && - sec->soundtraversed <= soundblocks + 1) - { - return; /* already flooded */ - } - - sec->validcount = validcount; - sec->soundtraversed = soundblocks + 1; - sec->soundtarget = soundtarget; - - for (i = 0; i < sec->linecount; i++) - { - check = sec->lines[i]; - if (!(check->flags & ML_TWOSIDED)) continue; - - p_line_opening(check); - - if (openrange <= 0) continue; /* closed door */ - - if (sides[check->sidenum[0]].sector == sec) - other = sides[check->sidenum[1]].sector; - else - other = sides[check->sidenum[0]].sector; - - if (check->flags & ML_SOUNDBLOCK) - { - if (!soundblocks) p_recursive_sound(other, 1); - } - else - p_recursive_sound(other, soundblocks); - } -} - -static boolean p_check_missile_range(mobj_t *actor) -{ - fixed_t dist; - - if (!p_check_sight(actor, actor->target)) return false; - - if (actor->flags & MF_JUSTHIT) - { - /* the target just hit the enemy, so fight back! */ - - actor->flags &= ~MF_JUSTHIT; - return true; - } - - if (actor->reactiontime) return false; /* do not attack yet */ - - /* OPTIMIZE: get this from a global checksight */ - - dist = p_approx_distance(actor->x - actor->target->x, - actor->y - actor->target->y) - - 64 * FRACUNIT; - - if (!actor->info->meleestate) - dist -= 128 * FRACUNIT; /* no melee attack, so fire more */ - - dist >>= FRACBITS; - - if (actor->type == MT_VILE) - { - if (dist > 14 * 64) return false; /* too far away */ - } - - if (actor->type == MT_UNDEAD) - { - if (dist < 196) return false; /* close for fist attack */ - dist >>= 1; - } - - if (actor->type == MT_CYBORG || actor->type == MT_SPIDER || - actor->type == MT_SKULL) - { - dist >>= 1; - } - - if (dist > 200) dist = 200; - - if (actor->type == MT_CYBORG && dist > 160) dist = 160; - - if (p_random() < dist) return false; - - return true; -} - -/* p_move - * Move in the current direction, returns false if the move is blocked. - */ - -static boolean p_move(mobj_t *actor) -{ - fixed_t tryx; - fixed_t tryy; - - line_t *ld; - - /* warning: 'catch', 'throw', and 'try' are all C++ reserved words */ - - boolean try_ok; - boolean good; - - if (actor->movedir == DI_NODIR) return false; - - if ((unsigned)actor->movedir >= 8) i_error("Weird actor->movedir!"); - - tryx = actor->x + actor->info->speed * xspeed[actor->movedir]; - tryy = actor->y + actor->info->speed * yspeed[actor->movedir]; - - try_ok = p_try_move(actor, tryx, tryy); - - if (!try_ok) - { - /* open any specials */ - - if (actor->flags & MF_FLOAT && floatok) - { - /* must adjust height */ - - if (actor->z < tmfloorz) - actor->z += FLOATSPEED; - else - actor->z -= FLOATSPEED; - - actor->flags |= MF_INFLOAT; - return true; - } - - if (!numspechit) return false; - - actor->movedir = DI_NODIR; - good = false; - while (numspechit--) - { - ld = spechit[numspechit]; - - /* if the special is not a door that can be opened, return false */ - - if (p_use_special_line(actor, ld, 0)) good = true; - } - - return good; - } - else - { - actor->flags &= ~MF_INFLOAT; - } - - if (!(actor->flags & MF_FLOAT)) actor->z = actor->floorz; - return true; -} - -/* p_try_walk - * - * Attempts to move actor on in its current (ob->moveangle) direction. - * If blocked by either a wall or an actor returns FALSE - * If move is either clear or blocked only by a door, returns TRUE and - * sets... - * If a door is in the way, an OpenDoor call is made to start it opening. - */ - -static boolean p_try_walk(mobj_t *actor) -{ - if (!p_move(actor)) - { - return false; - } - - actor->movecount = p_random() & 15; - return true; -} - -static void p_new_chase_dir(mobj_t *actor) -{ - fixed_t deltax; - fixed_t deltay; - - dirtype_t d[3]; - - int tdir; - dirtype_t olddir; - - dirtype_t turnaround; - - if (!actor->target) i_error("p_new_chase_dir: called with no target"); - - olddir = actor->movedir; - turnaround = opposite[olddir]; - - deltax = actor->target->x - actor->x; - deltay = actor->target->y - actor->y; - - if (deltax > 10 * FRACUNIT) - d[1] = DI_EAST; - else if (deltax < -10 * FRACUNIT) - d[1] = DI_WEST; - else - d[1] = DI_NODIR; - - if (deltay < -10 * FRACUNIT) - d[2] = DI_SOUTH; - else if (deltay > 10 * FRACUNIT) - d[2] = DI_NORTH; - else - d[2] = DI_NODIR; - - /* try direct route */ - - if (d[1] != DI_NODIR && d[2] != DI_NODIR) - { - actor->movedir = diags[((deltay < 0) << 1) + (deltax > 0)]; - if (actor->movedir != (int)turnaround && p_try_walk(actor)) return; - } - - /* try other directions */ - - if (p_random() > 200 || abs(deltay) > abs(deltax)) - { - tdir = d[1]; - d[1] = d[2]; - d[2] = tdir; - } - - if (d[1] == turnaround) d[1] = DI_NODIR; - if (d[2] == turnaround) d[2] = DI_NODIR; - - if (d[1] != DI_NODIR) - { - actor->movedir = d[1]; - if (p_try_walk(actor)) - { - return; /* either moved forward or attacked */ - } - } - - if (d[2] != DI_NODIR) - { - actor->movedir = d[2]; - - if (p_try_walk(actor)) return; - } - - /* there is no direct path to the player, so pick another direction. */ - - if (olddir != DI_NODIR) - { - actor->movedir = olddir; - - if (p_try_walk(actor)) return; - } - - /* randomly determine direction of search */ - - if (p_random() & 1) - { - for (tdir = DI_EAST; tdir <= DI_SOUTHEAST; tdir++) - { - if (tdir != (int)turnaround) - { - actor->movedir = tdir; - - if (p_try_walk(actor)) return; - } - } - } - else - { - for (tdir = DI_SOUTHEAST; tdir != (DI_EAST - 1); tdir--) - { - if (tdir != (int)turnaround) - { - actor->movedir = tdir; - - if (p_try_walk(actor)) return; - } - } - } - - if (turnaround != DI_NODIR) - { - actor->movedir = turnaround; - if (p_try_walk(actor)) return; - } - - actor->movedir = DI_NODIR; /* can not move */ -} - -/* p_look_for_players - * If allaround is false, only look 180 degrees in front. Returns true if a - * player is targeted. - */ - -static boolean p_look_for_players(mobj_t *actor, boolean allaround) -{ - int c; - int stop; - player_t *player; - angle_t an; - fixed_t dist; - - c = 0; - stop = (actor->lastlook - 1) & 3; - - for (; ; actor->lastlook = (actor->lastlook + 1) & 3) - { - if (!playeringame[actor->lastlook]) continue; - - if (c++ == 2 || actor->lastlook == stop) - { - return false; /* done looking */ - } - - player = &players[actor->lastlook]; - - if (player->health <= 0) continue; /* dead */ - - if (!p_check_sight(actor, player->mo)) continue; /* out of sight */ - - if (!allaround) - { - an = r_point_to_angle2(actor->x, actor->y, player->mo->x, - player->mo->y) - - actor->angle; - - if (an > ANG90 && an < ANG270) - { - dist = p_approx_distance(player->mo->x - actor->x, - player->mo->y - actor->y); - - /* if real close, react anyway */ - - if (dist > MELEERANGE) continue; /* behind back */ - } - } - - actor->target = player->mo; - return true; - } - - return false; -} - -/* pit_vile_check - * Detect a corpse that could be raised. - */ - -static boolean pit_vile_check(mobj_t *thing) -{ - int maxdist; - boolean check; - - if (!(thing->flags & MF_CORPSE)) return true; /* not a monster */ - - if (thing->tics != -1) return true; /* not lying still yet */ - - if (thing->info->raisestate == S_NULL) - { - return true; /* monster doesn't have a raise state */ - } - - maxdist = thing->info->radius + mobjinfo[MT_VILE].radius; - - if (abs(thing->x - viletryx) > maxdist || - abs(thing->y - viletryy) > maxdist) - { - return true; /* not actually touching */ - } - - corpsehit = thing; - corpsehit->momx = corpsehit->momy = 0; - corpsehit->height <<= 2; - check = p_check_position(corpsehit, corpsehit->x, corpsehit->y); - corpsehit->height >>= 2; - - if (!check) return true; /* doesn't fit here */ - - return false; /* got one, so stop checking */ -} - -/* Check whether the death of the specified monster type is allowed - * to trigger the end of episode special action. - * - * This behavior changed in v1.9, the most notable effect of which - * was to break uac_dead.wad - */ - -static boolean check_boss_end(mobjtype_t motype) -{ - if (gameversion < exe_ultimate) - { - if (gamemap != 8) - { - return false; - } - - /* Baron death on later episodes is nothing special. */ - - if (motype == MT_BRUISER && gameepisode != 1) - { - return false; - } - - return true; - } - else - { - /* New logic that appeared in Ultimate Doom. - * Looks like the logic was overhauled while adding in the - * episode 4 support. Now bosses only trigger on their - * specific episode. - */ - - switch (gameepisode) - { - case 1: - return gamemap == 8 && motype == MT_BRUISER; - - case 2: - return gamemap == 8 && motype == MT_CYBORG; - - case 3: - return gamemap == 8 && motype == MT_SPIDER; - - case 4: - return (gamemap == 6 && motype == MT_CYBORG) || - (gamemap == 8 && motype == MT_SPIDER); - - default: - return gamemap == 8; - } - } -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/* p_noise_alert - * If a monster yells at a player, - * it will alert other monsters to the player. - */ - -void p_noise_alert(mobj_t *target, mobj_t *emmiter) -{ - soundtarget = target; - validcount++; - p_recursive_sound(emmiter->subsector->sector, 0); -} - -boolean p_check_melee_range(mobj_t *actor) -{ - mobj_t *pl; - fixed_t dist; - fixed_t range; - - if (!actor->target) return false; - - pl = actor->target; - dist = p_approx_distance(pl->x - actor->x, pl->y - actor->y); - - if (gameversion < exe_doom_1_5) - range = MELEERANGE; - else - range = MELEERANGE - 20 * FRACUNIT + pl->info->radius; - - if (dist >= range) return false; - - if (!p_check_sight(actor, actor->target)) return false; - - return true; -} - -/* a_keen_die - * DOOM II special, map 32. Uses special tag 666. - */ - -void a_keen_die(mobj_t *mo) -{ - thinker_t *th; - mobj_t *mo2; - line_t junk; - - a_fall(mo); - - /* scan the remaining thinkers to see if all Keens are dead */ - - for (th = thinkercap.next; th != &thinkercap; th = th->next) - { - if (th->function.acp1 != (actionf_p1)p_mobj_thinker) continue; - - mo2 = (mobj_t *)th; - if (mo2 != mo && mo2->type == mo->type && mo2->health > 0) - { - return; /* other Keen not dead */ - } - } - - junk.tag = 666; - ev_do_door(&junk, VLD_OPEN); -} - -/* ACTION ROUTINES */ - -/* a_look - * Stay in state until a player is sighted. - */ - -void a_look(mobj_t *actor) -{ - mobj_t *targ; - - actor->threshold = 0; /* any shot will wake up */ - targ = actor->subsector->sector->soundtarget; - - if (targ && (targ->flags & MF_SHOOTABLE)) - { - actor->target = targ; - - if (actor->flags & MF_AMBUSH) - { - if (p_check_sight(actor, actor->target)) goto seeyou; - } - else - { - goto seeyou; - } - } - - if (!p_look_for_players(actor, false)) return; - - /* go into chase state */ - -seeyou: -#ifdef CONFIG_GAMES_NXDOOM_SOUND - if (actor->info->seesound) - { - int sound; - - switch (actor->info->seesound) - { - case SFX_POSIT1: - case SFX_POSIT2: - case SFX_POSIT3: - sound = SFX_POSIT1 + p_random() % 3; - break; - - case SFX_BGSIT1: - case SFX_BGSIT2: - sound = SFX_BGSIT1 + p_random() % 2; - break; - - default: - sound = actor->info->seesound; - break; - } - - if (actor->type == MT_SPIDER || actor->type == MT_CYBORG) - { - /* full volume */ - - s_start_sound(NULL, sound); - } - else - s_start_sound(actor, sound); - } -#endif - - p_set_mobj_state(actor, actor->info->seestate); -} - -/* a_chase - * Actor has a melee attack, so it tries to close as fast as possible - */ - -void a_chase(mobj_t *actor) -{ - int delta; - - if (actor->reactiontime) actor->reactiontime--; - - /* modify target threshold */ - - if (actor->threshold) - { - if (gameversion > exe_doom_1_2 && - (!actor->target || actor->target->health <= 0)) - { - actor->threshold = 0; - } - else - actor->threshold--; - } - - /* turn towards movement direction if not there yet */ - - if (actor->movedir < 8) - { - actor->angle &= (7u << 29); - delta = actor->angle - (actor->movedir << 29); - - if (delta > 0) - actor->angle -= ANG90 / 2; - else if (delta < 0) - actor->angle += ANG90 / 2; - } - - if (!actor->target || !(actor->target->flags & MF_SHOOTABLE)) - { - /* look for a new target */ - - if (p_look_for_players(actor, true)) return; /* got a new target */ - - p_set_mobj_state(actor, actor->info->spawnstate); - return; - } - - /* do not attack twice in a row */ - - if (actor->flags & MF_JUSTATTACKED) - { - actor->flags &= ~MF_JUSTATTACKED; - if (gameskill != sk_nightmare && !fastparm) p_new_chase_dir(actor); - return; - } - - /* check for melee attack */ - - if (actor->info->meleestate && p_check_melee_range(actor)) - { -#ifdef CONFIG_GAMES_NXDOOM_SOUND - if (actor->info->attacksound) - s_start_sound(actor, actor->info->attacksound); -#endif - - p_set_mobj_state(actor, actor->info->meleestate); - return; - } - - /* check for missile attack */ - - if (actor->info->missilestate) - { - if (gameskill < sk_nightmare && !fastparm && actor->movecount) - { - goto nomissile; - } - - if (!p_check_missile_range(actor)) goto nomissile; - - p_set_mobj_state(actor, actor->info->missilestate); - actor->flags |= MF_JUSTATTACKED; - return; - } - - /* ? */ - -nomissile: - - /* possibly choose another target */ - - if (netgame && !actor->threshold && !p_check_sight(actor, actor->target)) - { - if (p_look_for_players(actor, true)) return; /* got a new target */ - } - - /* chase towards player */ - - if (--actor->movecount < 0 || !p_move(actor)) - { - p_new_chase_dir(actor); - } - -#ifdef CONFIG_GAMES_NXDOOM_SOUND - - /* make active sound */ - - if (actor->info->activesound && p_random() < 3) - { - s_start_sound(actor, actor->info->activesound); - } -#endif -} - -void a_face_target(mobj_t *actor) -{ - if (!actor->target) return; - - actor->flags &= ~MF_AMBUSH; - - actor->angle = r_point_to_angle2(actor->x, actor->y, actor->target->x, - actor->target->y); - - if (actor->target->flags & MF_SHADOW) actor->angle += p_sub_random() << 21; -} - -void a_pos_attack(mobj_t *actor) -{ - int angle; - int damage; - int slope; - - if (!actor->target) return; - - a_face_target(actor); - angle = actor->angle; - slope = p_aim_line_attack(actor, angle, MISSILERANGE); - -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(actor, SFX_PISTOL); -#endif - angle += p_sub_random() << 20; - damage = ((p_random() % 5) + 1) * 3; - p_line_attack(actor, angle, MISSILERANGE, slope, damage); -} - -void a_s_pos_attack(mobj_t *actor) -{ - int i; - int angle; - int bangle; - int damage; - int slope; - - if (!actor->target) return; - -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(actor, SFX_SHOTGN); -#endif - a_face_target(actor); - bangle = actor->angle; - slope = p_aim_line_attack(actor, bangle, MISSILERANGE); - - for (i = 0; i < 3; i++) - { - angle = bangle + (p_sub_random() << 20); - damage = ((p_random() % 5) + 1) * 3; - p_line_attack(actor, angle, MISSILERANGE, slope, damage); - } -} - -void a_c_pos_attack(mobj_t *actor) -{ - int angle; - int bangle; - int damage; - int slope; - - if (!actor->target) return; - -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(actor, SFX_SHOTGN); -#endif - a_face_target(actor); - bangle = actor->angle; - slope = p_aim_line_attack(actor, bangle, MISSILERANGE); - - angle = bangle + (p_sub_random() << 20); - damage = ((p_random() % 5) + 1) * 3; - p_line_attack(actor, angle, MISSILERANGE, slope, damage); -} - -void a_c_pos_refire(mobj_t *actor) -{ - /* keep firing unless target got out of sight */ - - a_face_target(actor); - - if (p_random() < 40) return; - - if (!actor->target || actor->target->health <= 0 || - !p_check_sight(actor, actor->target)) - { - p_set_mobj_state(actor, actor->info->seestate); - } -} - -void a_spid_refire(mobj_t *actor) -{ - /* keep firing unless target got out of sight */ - - a_face_target(actor); - - if (p_random() < 10) return; - - if (!actor->target || actor->target->health <= 0 || - !p_check_sight(actor, actor->target)) - { - p_set_mobj_state(actor, actor->info->seestate); - } -} - -void a_bspi_attack(mobj_t *actor) -{ - if (!actor->target) return; - - a_face_target(actor); - - /* launch a missile */ - - p_spawn_missile(actor, actor->target, MT_ARACHPLAZ); -} - -void a_troop_attack(mobj_t *actor) -{ - int damage; - - if (!actor->target) return; - - a_face_target(actor); - if (p_check_melee_range(actor)) - { -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(actor, SFX_CLAW); -#endif - damage = (p_random() % 8 + 1) * 3; - p_damage_mobj(actor->target, actor, actor, damage); - return; - } - - /* launch a missile */ - - p_spawn_missile(actor, actor->target, MT_TROOPSHOT); -} - -void a_sarg_attack(mobj_t *actor) -{ - int damage; - - if (!actor->target) return; - - a_face_target(actor); - - if (gameversion >= exe_doom_1_5) - { - if (!p_check_melee_range(actor)) return; - } - - damage = ((p_random() % 10) + 1) * 4; - - if (gameversion <= exe_doom_1_2) - p_line_attack(actor, actor->angle, MELEERANGE, 0, damage); - else - p_damage_mobj(actor->target, actor, actor, damage); -} - -void a_head_attack(mobj_t *actor) -{ - int damage; - - if (!actor->target) return; - - a_face_target(actor); - if (p_check_melee_range(actor)) - { - damage = (p_random() % 6 + 1) * 10; - p_damage_mobj(actor->target, actor, actor, damage); - return; - } - - /* launch a missile */ - - p_spawn_missile(actor, actor->target, MT_HEADSHOT); -} - -void a_cyber_attack(mobj_t *actor) -{ - if (!actor->target) return; - - a_face_target(actor); - p_spawn_missile(actor, actor->target, MT_ROCKET); -} - -void a_bruis_attack(mobj_t *actor) -{ - int damage; - - if (!actor->target) return; - - if (p_check_melee_range(actor)) - { -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(actor, SFX_CLAW); -#endif - damage = (p_random() % 8 + 1) * 10; - p_damage_mobj(actor->target, actor, actor, damage); - return; - } - - /* launch a missile */ - - p_spawn_missile(actor, actor->target, MT_BRUISERSHOT); -} - -void a_skel_missile(mobj_t *actor) -{ - mobj_t *mo; - - if (!actor->target) return; - - a_face_target(actor); - actor->z += 16 * FRACUNIT; /* so missile spawns higher */ - mo = p_spawn_missile(actor, actor->target, MT_TRACER); - actor->z -= 16 * FRACUNIT; /* back to normal */ - - mo->x += mo->momx; - mo->y += mo->momy; - mo->tracer = actor->target; -} - -void a_tracer(mobj_t *actor) -{ - angle_t exact; - fixed_t dist; - fixed_t slope; - mobj_t *dest; - mobj_t *th; - - if (gametic & 3) return; - - /* spawn a puff of smoke behind the rocket */ - - p_spawn_puff(actor->x, actor->y, actor->z); - - th = p_spawn_mobj(actor->x - actor->momx, actor->y - actor->momy, actor->z, - MT_SMOKE); - - th->momz = FRACUNIT; - th->tics -= p_random() & 3; - if (th->tics < 1) th->tics = 1; - - /* adjust direction */ - - dest = actor->tracer; - - if (!dest || dest->health <= 0) return; - - /* change angle */ - - exact = r_point_to_angle2(actor->x, actor->y, dest->x, dest->y); - - if (exact != actor->angle) - { - if (exact - actor->angle > 0x80000000) - { - actor->angle -= TRACEANGLE; - if (exact - actor->angle < 0x80000000) actor->angle = exact; - } - else - { - actor->angle += TRACEANGLE; - if (exact - actor->angle > 0x80000000) actor->angle = exact; - } - } - - exact = actor->angle >> ANGLETOFINESHIFT; - actor->momx = fixed_mul(actor->info->speed, finecosine[exact]); - actor->momy = fixed_mul(actor->info->speed, finesine[exact]); - - /* change slope */ - - dist = p_approx_distance(dest->x - actor->x, dest->y - actor->y); - - dist = dist / actor->info->speed; - - if (dist < 1) dist = 1; - slope = (dest->z + 40 * FRACUNIT - actor->z) / dist; - - if (slope < actor->momz) - actor->momz -= FRACUNIT / 8; - else - actor->momz += FRACUNIT / 8; -} - -void a_skel_woosh(mobj_t *actor) -{ - if (!actor->target) return; - a_face_target(actor); -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(actor, SFX_SKESWG); -#endif -} - -void a_skel_fist(mobj_t *actor) -{ - int damage; - - if (!actor->target) return; - - a_face_target(actor); - - if (p_check_melee_range(actor)) - { - damage = ((p_random() % 10) + 1) * 6; -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(actor, SFX_SKEPCH); -#endif - p_damage_mobj(actor->target, actor, actor, damage); - } -} - -/* a_vile_chase - * Check for resurrecting a body - */ - -void a_vile_chase(mobj_t *actor) -{ - int xl; - int xh; - int yl; - int yh; - - int bx; - int by; - - mobjinfo_t *info; - mobj_t *temp; - - if (actor->movedir != DI_NODIR) - { - /* check for corpses to raise */ - - viletryx = actor->x + actor->info->speed * xspeed[actor->movedir]; - viletryy = actor->y + actor->info->speed * yspeed[actor->movedir]; - - xl = (viletryx - bmaporgx - MAXRADIUS * 2) >> MAPBLOCKSHIFT; - xh = (viletryx - bmaporgx + MAXRADIUS * 2) >> MAPBLOCKSHIFT; - yl = (viletryy - bmaporgy - MAXRADIUS * 2) >> MAPBLOCKSHIFT; - yh = (viletryy - bmaporgy + MAXRADIUS * 2) >> MAPBLOCKSHIFT; - - vileobj = actor; - for (bx = xl; bx <= xh; bx++) - { - for (by = yl; by <= yh; by++) - { - /* Call pit_vile_check to check whether object is a corpse that - * can be raised. - */ - - if (!p_block_things_iterator(bx, by, pit_vile_check)) - { - /* got one! */ - - temp = actor->target; - actor->target = corpsehit; - a_face_target(actor); - actor->target = temp; - - p_set_mobj_state(actor, S_VILE_HEAL1); -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(corpsehit, SFX_SLOP); -#endif - info = corpsehit->info; - - p_set_mobj_state(corpsehit, info->raisestate); - corpsehit->height <<= 2; - corpsehit->flags = info->flags; - corpsehit->health = info->spawnhealth; - corpsehit->target = NULL; - - return; - } - } - } - } - - /* Return to normal attack. */ - - a_chase(actor); -} - -/* Keep fire in front of player unless out of sight */ - -void a_fire(mobj_t *actor) -{ - mobj_t *dest; - mobj_t *target; - unsigned an; - - dest = actor->tracer; - if (!dest) return; - - target = p_subst_null_mobj(actor->target); - - /* don't move it if the vile lost sight */ - - if (!p_check_sight(target, dest)) return; - - an = dest->angle >> ANGLETOFINESHIFT; - - p_unset_thing_position(actor); - actor->x = dest->x + fixed_mul(24 * FRACUNIT, finecosine[an]); - actor->y = dest->y + fixed_mul(24 * FRACUNIT, finesine[an]); - actor->z = dest->z; - p_set_thing_position(actor); -} - -void a_vile_start(mobj_t *actor) -{ -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(actor, SFX_VILATK); -#endif -} - -void a_start_fire(mobj_t *actor) -{ -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(actor, SFX_FLAMST); -#endif - a_fire(actor); -} - -void a_fire_crackle(mobj_t *actor) -{ -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(actor, SFX_FLAME); -#endif - a_fire(actor); -} - -/* a_vile_target - * Spawn the hellfire - */ - -void a_vile_target(mobj_t *actor) -{ - mobj_t *fog; - - if (!actor->target) return; - - a_face_target(actor); - - fog = p_spawn_mobj(actor->target->x, actor->target->x, actor->target->z, - MT_FIRE); - - actor->tracer = fog; - fog->target = actor; - fog->tracer = actor->target; - a_fire(fog); -} - -void a_vile_attack(mobj_t *actor) -{ - mobj_t *fire; - int an; - - if (!actor->target) return; - - a_face_target(actor); - - if (!p_check_sight(actor, actor->target)) return; - -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(actor, SFX_BAREXP); -#endif - p_damage_mobj(actor->target, actor, actor, 20); - actor->target->momz = 1000 * FRACUNIT / actor->target->info->mass; - - an = actor->angle >> ANGLETOFINESHIFT; - - fire = actor->tracer; - - if (!fire) return; - - /* move the fire between the vile and the player */ - - fire->x = actor->target->x - fixed_mul(24 * FRACUNIT, finecosine[an]); - fire->y = actor->target->y - fixed_mul(24 * FRACUNIT, finesine[an]); - p_radius_attack(fire, actor, 70); -} - -/* Mancubus attack, - * firing three missiles (bruisers) in three different directions? - * Doesn't look like it. - */ - -void a_fat_raise(mobj_t *actor) -{ - a_face_target(actor); -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(actor, SFX_MANATK); -#endif -} - -void a_fat_attack1(mobj_t *actor) -{ - mobj_t *mo; - mobj_t *target; - int an; - - a_face_target(actor); - - /* Change direction to ... */ - - actor->angle += FATSPREAD; - target = p_subst_null_mobj(actor->target); - p_spawn_missile(actor, target, MT_FATSHOT); - - mo = p_spawn_missile(actor, target, MT_FATSHOT); - mo->angle += FATSPREAD; - an = mo->angle >> ANGLETOFINESHIFT; - mo->momx = fixed_mul(mo->info->speed, finecosine[an]); - mo->momy = fixed_mul(mo->info->speed, finesine[an]); -} - -void a_fat_attack2(mobj_t *actor) -{ - mobj_t *mo; - mobj_t *target; - int an; - - a_face_target(actor); - - /* Now here choose opposite deviation. */ - - actor->angle -= FATSPREAD; - target = p_subst_null_mobj(actor->target); - p_spawn_missile(actor, target, MT_FATSHOT); - - mo = p_spawn_missile(actor, target, MT_FATSHOT); - mo->angle -= FATSPREAD * 2; - an = mo->angle >> ANGLETOFINESHIFT; - mo->momx = fixed_mul(mo->info->speed, finecosine[an]); - mo->momy = fixed_mul(mo->info->speed, finesine[an]); -} - -void a_fat_attack3(mobj_t *actor) -{ - mobj_t *mo; - mobj_t *target; - int an; - - a_face_target(actor); - - target = p_subst_null_mobj(actor->target); - - mo = p_spawn_missile(actor, target, MT_FATSHOT); - mo->angle -= FATSPREAD / 2; - an = mo->angle >> ANGLETOFINESHIFT; - mo->momx = fixed_mul(mo->info->speed, finecosine[an]); - mo->momy = fixed_mul(mo->info->speed, finesine[an]); - - mo = p_spawn_missile(actor, target, MT_FATSHOT); - mo->angle += FATSPREAD / 2; - an = mo->angle >> ANGLETOFINESHIFT; - mo->momx = fixed_mul(mo->info->speed, finecosine[an]); - mo->momy = fixed_mul(mo->info->speed, finesine[an]); -} - -/* SkullAttack - * Fly at the player like a missile. - */ - -void a_skull_attack(mobj_t *actor) -{ - mobj_t *dest; - angle_t an; - int dist; - - if (!actor->target) return; - - dest = actor->target; - actor->flags |= MF_SKULLFLY; - -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(actor, actor->info->attacksound); -#endif - a_face_target(actor); - an = actor->angle >> ANGLETOFINESHIFT; - actor->momx = fixed_mul(SKULLSPEED, finecosine[an]); - actor->momy = fixed_mul(SKULLSPEED, finesine[an]); - dist = p_approx_distance(dest->x - actor->x, dest->y - actor->y); - dist = dist / SKULLSPEED; - - if (dist < 1) dist = 1; - actor->momz = (dest->z + (dest->height >> 1) - actor->z) / dist; -} - -/* a_pain_shoot_skull - * Spawn a lost soul and launch it at the target - */ - -void a_pain_shoot_skull(mobj_t *actor, angle_t angle) -{ - fixed_t x; - fixed_t y; - fixed_t z; - - mobj_t *newmobj; - angle_t an; - int prestep; - int count; - thinker_t *currentthinker; - - /* count total number of skull currently on the level */ - - count = 0; - - currentthinker = thinkercap.next; - while (currentthinker != &thinkercap) - { - if ((currentthinker->function.acp1 == (actionf_p1)p_mobj_thinker) && - ((mobj_t *)currentthinker)->type == MT_SKULL) - count++; - currentthinker = currentthinker->next; - } - - /* if there are already 20 skulls on the level, don't spit another one */ - - if (count > 20) return; - - /* okay, there's player for another one */ - - an = angle >> ANGLETOFINESHIFT; - - prestep = 4 * FRACUNIT + - 3 * (actor->info->radius + mobjinfo[MT_SKULL].radius) / 2; - - x = actor->x + fixed_mul(prestep, finecosine[an]); - y = actor->y + fixed_mul(prestep, finesine[an]); - z = actor->z + 8 * FRACUNIT; - - newmobj = p_spawn_mobj(x, y, z, MT_SKULL); - - /* Check for movements. */ - - if (!p_try_move(newmobj, newmobj->x, newmobj->y)) - { - /* kill it immediately */ - - p_damage_mobj(newmobj, actor, actor, 10000); - return; - } - - newmobj->target = actor->target; - a_skull_attack(newmobj); -} - -/* a_pain_attack - * Spawn a lost soul and launch it at the target - */ - -void a_pain_attack(mobj_t *actor) -{ - if (!actor->target) return; - - a_face_target(actor); - a_pain_shoot_skull(actor, actor->angle); -} - -void a_pain_die(mobj_t *actor) -{ - a_fall(actor); - a_pain_shoot_skull(actor, actor->angle + ANG90); - a_pain_shoot_skull(actor, actor->angle + ANG180); - a_pain_shoot_skull(actor, actor->angle + ANG270); -} - -void a_scream(mobj_t *actor) -{ -#ifdef CONFIG_GAMES_NXDOOM_SOUND - int sound; - - switch (actor->info->deathsound) - { - case 0: - return; - - case SFX_PODTH1: - case SFX_PODTH2: - case SFX_PODTH3: - sound = SFX_PODTH1 + p_random() % 3; - break; - - case SFX_BGDTH1: - case SFX_BGDTH2: - sound = SFX_BGDTH1 + p_random() % 2; - break; - - default: - sound = actor->info->deathsound; - break; - } - - /* Check for bosses. */ - - if (actor->type == MT_SPIDER || actor->type == MT_CYBORG) - { - s_start_sound(NULL, sound); /* full volume */ - } - else - s_start_sound(actor, sound); -#endif -} - -void a_xscream(mobj_t *actor) -{ -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(actor, SFX_SLOP); -#endif -} - -void a_pain(mobj_t *actor) -{ -#ifdef CONFIG_GAMES_NXDOOM_SOUND - if (actor->info->painsound) s_start_sound(actor, actor->info->painsound); -#endif -} - -void a_fall(mobj_t *actor) -{ - /* actor is on ground, it can be walked over */ - - actor->flags &= ~MF_SOLID; - - /* So change this if corpse objects are meant to be obstacles. */ -} - -void a_explode(mobj_t *thingy) -{ - p_radius_attack(thingy, thingy->target, 128); -} - -/* a_boss_death - * Possibly trigger special effects if on first boss level - */ - -void a_boss_death(mobj_t *mo) -{ - thinker_t *th; - mobj_t *mo2; - line_t junk; - int i; - - if (gamemode == commercial) - { - if (gamemap != 7) return; - - if ((mo->type != MT_FATSO) && (mo->type != MT_BABY)) return; - } - else - { - if (!check_boss_end(mo->type)) - { - return; - } - } - - /* make sure there is a player alive for victory */ - - for (i = 0; i < MAXPLAYERS; i++) - { - if (playeringame[i] && players[i].health > 0) break; - } - - if (i == MAXPLAYERS) return; /* no one left alive, so do not end game */ - - /* scan the remaining thinkers to see if all bosses are dead */ - - for (th = thinkercap.next; th != &thinkercap; th = th->next) - { - if (th->function.acp1 != (actionf_p1)p_mobj_thinker) continue; - - mo2 = (mobj_t *)th; - if (mo2 != mo && mo2->type == mo->type && mo2->health > 0) - { - return; /* other boss not dead */ - } - } - - /* victory! */ - - if (gamemode == commercial) - { - if (gamemap == 7) - { - if (mo->type == MT_FATSO) - { - junk.tag = 666; - ev_do_floor(&junk, FLOOR_LOWERFLOORTOLOWEST); - return; - } - - if (mo->type == MT_BABY) - { - junk.tag = 667; - ev_do_floor(&junk, FLOOR_RAISETOTEXTURE); - return; - } - } - } - else - { - switch (gameepisode) - { - case 1: - junk.tag = 666; - ev_do_floor(&junk, FLOOR_LOWERFLOORTOLOWEST); - return; - break; - - case 4: - switch (gamemap) - { - case 6: - junk.tag = 666; - ev_do_door(&junk, VLD_BLAZEOPEN); - return; - break; - - case 8: - junk.tag = 666; - ev_do_floor(&junk, FLOOR_LOWERFLOORTOLOWEST); - return; - break; - } - } - } - - g_exit_level(); -} - -void a_hoof(mobj_t *mo) -{ -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(mo, SFX_HOOF); -#endif - a_chase(mo); -} - -void a_metal(mobj_t *mo) -{ -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(mo, SFX_METAL); -#endif - a_chase(mo); -} - -void a_baby_metal(mobj_t *mo) -{ -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(mo, SFX_BSPWLK); -#endif - a_chase(mo); -} - -void a_open_shotgun2(player_t *player, pspdef_t *psp) -{ -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(player->mo, SFX_DBOPN); -#endif -} - -void a_load_shotgun2(player_t *player, pspdef_t *psp) -{ -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(player->mo, SFX_DBLOAD); -#endif -} - -void a_close_shotgun2(player_t *player, pspdef_t *psp) -{ -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(player->mo, SFX_DBCLS); -#endif - a_refire(player, psp); -} - -void a_brain_awake(mobj_t *mo) -{ - thinker_t *thinker; - mobj_t *m; - - /* find all the target spots */ - - numbraintargets = 0; - braintargeton = 0; - - for (thinker = thinkercap.next; thinker != &thinkercap; - thinker = thinker->next) - { - if (thinker->function.acp1 != (actionf_p1)p_mobj_thinker) - { - continue; /* not a mobj */ - } - - m = (mobj_t *)thinker; - - if (m->type == MT_BOSSTARGET) - { - braintargets[numbraintargets] = m; - numbraintargets++; - } - } - -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(NULL, SFX_BOSSIT); -#endif -} - -void a_brain_pain(mobj_t *mo) -{ -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(NULL, SFX_BOSPN); -#endif -} - -void a_brain_scream(mobj_t *mo) -{ - int x; - int y; - int z; - mobj_t *th; - - for (x = mo->x - 196 * FRACUNIT; x < mo->x + 320 * FRACUNIT; - x += FRACUNIT * 8) - { - y = mo->y - 320 * FRACUNIT; - z = 128 + p_random() * 2 * FRACUNIT; - th = p_spawn_mobj(x, y, z, MT_ROCKET); - th->momz = p_random() * 512; - - p_set_mobj_state(th, S_BRAINEXPLODE1); - - th->tics -= p_random() & 7; - if (th->tics < 1) th->tics = 1; - } - -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(NULL, SFX_BOSDTH); -#endif -} - -void a_brain_explode(mobj_t *mo) -{ - int x; - int y; - int z; - mobj_t *th; - - x = mo->x + p_sub_random() * 2048; - y = mo->y; - z = 128 + p_random() * 2 * FRACUNIT; - th = p_spawn_mobj(x, y, z, MT_ROCKET); - th->momz = p_random() * 512; - - p_set_mobj_state(th, S_BRAINEXPLODE1); - - th->tics -= p_random() & 7; - if (th->tics < 1) th->tics = 1; -} - -void a_brain_die(mobj_t *mo) -{ - g_exit_level(); -} - -void a_brain_split(mobj_t *mo) -{ - mobj_t *targ; - mobj_t *newmobj; - - static int easy = 0; - - easy ^= 1; - if (gameskill <= sk_easy && (!easy)) return; - - /* shoot a cube at current target */ - - targ = braintargets[braintargeton]; - if (numbraintargets == 0) - { - i_error("a_brain_split: numbraintargets was 0 (vanilla crashes here)"); - } - - braintargeton = (braintargeton + 1) % numbraintargets; - - /* spawn brain missile */ - - newmobj = p_spawn_missile(mo, targ, MT_SPAWNSHOT); - newmobj->target = targ; - newmobj->reactiontime = - ((targ->y - mo->y) / newmobj->momy) / newmobj->state->tics; - -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(NULL, SFX_BOSPIT); -#endif -} - -void a_spawn_fly(mobj_t *mo) -{ - mobj_t *newmobj; - mobj_t *fog; - mobj_t *targ; - int r; - mobjtype_t type; - - if (--mo->reactiontime) return; /* still flying */ - - targ = p_subst_null_mobj(mo->target); - - /* First spawn teleport fog. */ - - fog = p_spawn_mobj(targ->x, targ->y, targ->z, MT_SPAWNFIRE); -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(fog, SFX_TELEPT); -#else - UNUSED(fog); -#endif - - /* Randomly select monster to spawn. */ - - r = p_random(); - - /* Probability distribution (kind of :), decreasing likelihood. */ - - if (r < 50) - type = MT_TROOP; - else if (r < 90) - type = MT_SERGEANT; - else if (r < 120) - type = MT_SHADOWS; - else if (r < 130) - type = MT_PAIN; - else if (r < 160) - type = MT_HEAD; - else if (r < 162) - type = MT_VILE; - else if (r < 172) - type = MT_UNDEAD; - else if (r < 192) - type = MT_BABY; - else if (r < 222) - type = MT_FATSO; - else if (r < 246) - type = MT_KNIGHT; - else - type = MT_BRUISER; - - newmobj = p_spawn_mobj(targ->x, targ->y, targ->z, type); - if (p_look_for_players(newmobj, true)) - p_set_mobj_state(newmobj, newmobj->info->seestate); - - /* telefrag anything in this spot */ - - p_teleport_move(newmobj, newmobj->x, newmobj->y); - - /* remove self (i.e., cube). */ - - p_remove_mobj(mo); -} - -/* travelling cube sound */ - -void a_spawn_sound(mobj_t *mo) -{ -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(mo, SFX_BOSCUB); -#endif - a_spawn_fly(mo); -} - -void a_player_screm(mobj_t *mo) -{ -#ifdef CONFIG_GAMES_NXDOOM_SOUND - - /* Default death sound. */ - - int sound = SFX_PLDETH; - - if ((gamemode == commercial) && (mo->health < -50)) - { - /* IF THE PLAYER DIES LESS THAN -50% WITHOUT GIBBING */ - - sound = SFX_PDIEHI; - } - - s_start_sound(mo, sound); -#else - UNUSED(mo); -#endif -} diff --git a/games/NXDoom/src/doom/p_floor.c b/games/NXDoom/src/doom/p_floor.c deleted file mode 100644 index 656240785..000000000 --- a/games/NXDoom/src/doom/p_floor.c +++ /dev/null @@ -1,569 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/p_floor.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Floor animation: raising stairs. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "doomdef.h" -#include "p_local.h" -#include "z_zone.h" - -#ifdef CONFIG_GAMES_NXDOOM_SOUND -#include "s_sound.h" -#include "sounds.h" -#endif - -/* State. */ - -#include "doomstat.h" -#include "r_state.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* e6y */ - -#define STAIRS_UNINITIALIZED_CRUSH_FIELD_VALUE 10 - -/* FLOORS */ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/* Move a plane (floor or ceiling) and check for crushing */ - -result_e t_move_plane(sector_t *sector, fixed_t speed, fixed_t dest, - boolean crush, int floor_or_ceiling, int direction) -{ - boolean flag; - fixed_t lastpos; - - switch (floor_or_ceiling) - { - case 0: /* FLOOR */ - switch (direction) - { - case -1: /* DOWN */ - if (sector->floorheight - speed < dest) - { - lastpos = sector->floorheight; - sector->floorheight = dest; - flag = p_change_sector(sector, crush); - if (flag == true) - { - sector->floorheight = lastpos; - p_change_sector(sector, crush); - - /* return crushed; */ - } - - return pastdest; - } - else - { - lastpos = sector->floorheight; - sector->floorheight -= speed; - flag = p_change_sector(sector, crush); - if (flag == true) - { - sector->floorheight = lastpos; - p_change_sector(sector, crush); - return crushed; - } - } - - break; - - case 1: /* UP */ - if (sector->floorheight + speed > dest) - { - lastpos = sector->floorheight; - sector->floorheight = dest; - flag = p_change_sector(sector, crush); - if (flag == true) - { - sector->floorheight = lastpos; - p_change_sector(sector, crush); - - /* return crushed; */ - } - - return pastdest; - } - else - { - /* COULD GET CRUSHED */ - - lastpos = sector->floorheight; - sector->floorheight += speed; - flag = p_change_sector(sector, crush); - if (flag == true) - { - if (crush == true) return crushed; - sector->floorheight = lastpos; - p_change_sector(sector, crush); - return crushed; - } - } - break; - } - break; - - case 1: /* CEILING */ - switch (direction) - { - case -1: /* DOWN */ - if (sector->ceilingheight - speed < dest) - { - lastpos = sector->ceilingheight; - sector->ceilingheight = dest; - flag = p_change_sector(sector, crush); - - if (flag == true) - { - sector->ceilingheight = lastpos; - p_change_sector(sector, crush); - - /* return crushed; */ - } - - return pastdest; - } - else - { - /* COULD GET CRUSHED */ - - lastpos = sector->ceilingheight; - sector->ceilingheight -= speed; - flag = p_change_sector(sector, crush); - - if (flag == true) - { - if (crush == true) return crushed; - sector->ceilingheight = lastpos; - p_change_sector(sector, crush); - return crushed; - } - } - break; - - case 1: /* UP */ - if (sector->ceilingheight + speed > dest) - { - lastpos = sector->ceilingheight; - sector->ceilingheight = dest; - flag = p_change_sector(sector, crush); - if (flag == true) - { - sector->ceilingheight = lastpos; - p_change_sector(sector, crush); - - /* return crushed; */ - } - - return pastdest; - } - else - { - lastpos = sector->ceilingheight; - sector->ceilingheight += speed; - flag = p_change_sector(sector, crush); - -#if 0 /* UNUSED */ - if (flag == true) - { - sector->ceilingheight = lastpos; - p_change_sector(sector, crush); - return crushed; - } -#endif - } - break; - } - break; - } - - return ok; -} - -/* MOVE A FLOOR TO IT'S DESTINATION (UP OR DOWN) */ - -void t_move_floor(floormove_t *floor) -{ - result_e res; - - res = t_move_plane(floor->sector, floor->speed, floor->floordestheight, - floor->crush, 0, floor->direction); - -#ifdef CONFIG_GAMES_NXDOOM_SOUND - if (!(leveltime & 7)) s_start_sound(&floor->sector->soundorg, SFX_STNMOV); -#endif - - if (res == pastdest) - { - floor->sector->specialdata = NULL; - - if (floor->direction == 1) - { - switch (floor->type) - { - case FLOOR_DONUTRAISE: - floor->sector->special = floor->newspecial; - floor->sector->floorpic = floor->texture; - default: - break; - } - } - else if (floor->direction == -1) - { - switch (floor->type) - { - case FLOOR_LOWERANDCHANGE: - floor->sector->special = floor->newspecial; - floor->sector->floorpic = floor->texture; - default: - break; - } - } - - p_remove_thinker(&floor->thinker); - -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(&floor->sector->soundorg, SFX_PSTOP); -#endif - } -} - -/* HANDLE FLOOR TYPES */ - -int ev_do_floor(line_t *line, floor_e floortype) -{ - int secnum; - int rtn; - int i; - sector_t *sec; - floormove_t *floor; - - secnum = -1; - rtn = 0; - while ((secnum = p_find_sector_from_line_tag(line, secnum)) >= 0) - { - sec = §ors[secnum]; - - /* ALREADY MOVING? IF SO, KEEP GOING... */ - - if (sec->specialdata) continue; - - /* new floor thinker */ - - rtn = 1; - floor = z_malloc(sizeof(*floor), PU_LEVSPEC, 0); - p_add_thinker(&floor->thinker); - sec->specialdata = floor; - floor->thinker.function.acp1 = (actionf_p1)t_move_floor; - floor->type = floortype; - floor->crush = false; - - switch (floortype) - { - case FLOOR_LOWERFLOOR: - floor->direction = -1; - floor->sector = sec; - floor->speed = FLOORSPEED; - floor->floordestheight = p_find_highest_floor_surrounding(sec); - break; - - case FLOOR_LOWERFLOORTOLOWEST: - floor->direction = -1; - floor->sector = sec; - floor->speed = FLOORSPEED; - floor->floordestheight = p_find_lowest_floor_surrounding(sec); - break; - - case FLOOR_TURBOLOWER: - floor->direction = -1; - floor->sector = sec; - floor->speed = FLOORSPEED * 4; - floor->floordestheight = p_find_highest_floor_surrounding(sec); - if (gameversion <= exe_doom_1_2 || - floor->floordestheight != sec->floorheight) - floor->floordestheight += 8 * FRACUNIT; - break; - - case FLOOR_RAISEFLOORCRUSH: - floor->crush = true; - case FLOOR_RAISEFLOOR: - floor->direction = 1; - floor->sector = sec; - floor->speed = FLOORSPEED; - floor->floordestheight = p_find_lowest_ceiling_surrounding(sec); - if (floor->floordestheight > sec->ceilingheight) - floor->floordestheight = sec->ceilingheight; - floor->floordestheight -= - (8 * FRACUNIT) * (floortype == FLOOR_RAISEFLOORCRUSH); - break; - - case FLOOR_RAISEFLOORTURBO: - floor->direction = 1; - floor->sector = sec; - floor->speed = FLOORSPEED * 4; - floor->floordestheight = - p_find_next_highest_floor(sec, sec->floorheight); - break; - - case FLOOR_RAISEFLOORTONEAREST: - floor->direction = 1; - floor->sector = sec; - floor->speed = FLOORSPEED; - floor->floordestheight = - p_find_next_highest_floor(sec, sec->floorheight); - break; - - case FLOOR_RAISEFLOOR24: - floor->direction = 1; - floor->sector = sec; - floor->speed = FLOORSPEED; - floor->floordestheight = - floor->sector->floorheight + 24 * FRACUNIT; - break; - - case FLOOR_RAISEFLOOR512: - floor->direction = 1; - floor->sector = sec; - floor->speed = FLOORSPEED; - floor->floordestheight = - floor->sector->floorheight + 512 * FRACUNIT; - break; - - case FLOOR_RAISEFLOOR24ANDCHANGE: - floor->direction = 1; - floor->sector = sec; - floor->speed = FLOORSPEED; - floor->floordestheight = - floor->sector->floorheight + 24 * FRACUNIT; - sec->floorpic = line->frontsector->floorpic; - sec->special = line->frontsector->special; - break; - - case FLOOR_RAISETOTEXTURE: - { - int minsize = INT_MAX; - side_t *side; - - floor->direction = 1; - floor->sector = sec; - floor->speed = FLOORSPEED; - for (i = 0; i < sec->linecount; i++) - { - if (two_sided(secnum, i)) - { - side = get_side(secnum, i, 0); - if (side->bottomtexture >= 0) - if (textureheight[side->bottomtexture] < minsize) - minsize = textureheight[side->bottomtexture]; - side = get_side(secnum, i, 1); - if (side->bottomtexture >= 0) - if (textureheight[side->bottomtexture] < minsize) - minsize = textureheight[side->bottomtexture]; - } - } - - floor->floordestheight = floor->sector->floorheight + minsize; - } - break; - - case FLOOR_LOWERANDCHANGE: - floor->direction = -1; - floor->sector = sec; - floor->speed = FLOORSPEED; - floor->floordestheight = p_find_lowest_floor_surrounding(sec); - floor->texture = sec->floorpic; - - for (i = 0; i < sec->linecount; i++) - { - if (two_sided(secnum, i)) - { - if (get_side(secnum, i, 0)->sector - sectors == secnum) - { - sec = get_sector(secnum, i, 1); - - if (sec->floorheight == floor->floordestheight) - { - floor->texture = sec->floorpic; - floor->newspecial = sec->special; - break; - } - } - else - { - sec = get_sector(secnum, i, 0); - - if (sec->floorheight == floor->floordestheight) - { - floor->texture = sec->floorpic; - floor->newspecial = sec->special; - break; - } - } - } - } - - default: - break; - } - } - - return rtn; -} - -/* BUILD A STAIRCASE! */ - -int ev_build_stairs(line_t *line, stair_e type) -{ - int secnum; - int height; - int i; - int newsecnum; - int texture; - int is_ok; - int rtn; - - sector_t *sec; - sector_t *tsec; - - floormove_t *floor; - - fixed_t stairsize = 0; - fixed_t speed = 0; - - secnum = -1; - rtn = 0; - while ((secnum = p_find_sector_from_line_tag(line, secnum)) >= 0) - { - sec = §ors[secnum]; - - /* ALREADY MOVING? IF SO, KEEP GOING... */ - - if (sec->specialdata) continue; - - /* new floor thinker */ - - rtn = 1; - floor = z_malloc(sizeof(*floor), PU_LEVSPEC, 0); - p_add_thinker(&floor->thinker); - sec->specialdata = floor; - floor->thinker.function.acp1 = (actionf_p1)t_move_floor; - floor->direction = 1; - floor->sector = sec; - - switch (type) - { - case STAIR_BUILD8: - speed = FLOORSPEED / 4; - stairsize = 8 * FRACUNIT; - break; - case STAIR_TURBO16: - speed = FLOORSPEED * 4; - stairsize = 16 * FRACUNIT; - break; - } - - floor->speed = speed; - height = sec->floorheight + stairsize; - floor->floordestheight = height; - - /* Initialize */ - - floor->type = FLOOR_LOWERFLOOR; - - /* e6y - * Uninitialized crush field will not be equal to 0 or 1 (true) - * with high probability. So, initialize it with any other value - */ - - floor->crush = STAIRS_UNINITIALIZED_CRUSH_FIELD_VALUE; - - texture = sec->floorpic; - - /* Find next sector to raise - * 1. Find 2-sided line with same sector side[0] - * 2. Other side is the next sector to raise - */ - - do - { - is_ok = 0; - for (i = 0; i < sec->linecount; i++) - { - if (!((sec->lines[i])->flags & ML_TWOSIDED)) continue; - - tsec = (sec->lines[i])->frontsector; - newsecnum = tsec - sectors; - - if (secnum != newsecnum) continue; - - tsec = (sec->lines[i])->backsector; - newsecnum = tsec - sectors; - - if (tsec->floorpic != texture) continue; - - height += stairsize; - - if (tsec->specialdata) continue; - - sec = tsec; - secnum = newsecnum; - floor = z_malloc(sizeof(*floor), PU_LEVSPEC, 0); - - p_add_thinker(&floor->thinker); - - sec->specialdata = floor; - floor->thinker.function.acp1 = (actionf_p1)t_move_floor; - floor->direction = 1; - floor->sector = sec; - floor->speed = speed; - floor->floordestheight = height; - - /* Initialize */ - - floor->type = FLOOR_LOWERFLOOR; - - /* e6y - * Uninitialized crush field will not be equal to 0 or 1 - * (true) with high probability. So, initialize it with any - * other value - */ - - floor->crush = STAIRS_UNINITIALIZED_CRUSH_FIELD_VALUE; - is_ok = 1; - break; - } - } - while (is_ok); - } - - return rtn; -} diff --git a/games/NXDoom/src/doom/p_inter.c b/games/NXDoom/src/doom/p_inter.c deleted file mode 100644 index cd77f8ca7..000000000 --- a/games/NXDoom/src/doom/p_inter.c +++ /dev/null @@ -1,890 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/p_inter.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Handling interactions (i.e., collisions). - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -/* Data. */ - -#include "doomdef.h" -#include "dstrings.h" - -#include "deh_main.h" -#include "deh_misc.h" -#include "doomstat.h" - -#include "i_system.h" -#include "m_random.h" - -#include "am_map.h" - -#include "p_local.h" - -#ifdef CONFIG_GAMES_NXDOOM_SOUND -#include "s_sound.h" -#include "sounds.h" -#endif - -#include "p_inter.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define BONUSADD 6 - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/* a weapon is found with two clip loads, a big item has five clip loads */ - -int maxammo[NUMAMMO] = -{ - 200, 50, 300, 50 -}; - -int clipammo[NUMAMMO] = -{ - 10, 4, 20, 1 -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/* GET STUFF */ - -/* p_give_ammo - * - * Num is the number of clip loads, not the individual count (0= 1/2 clip). - * - * Returns false if the ammo can't be picked up at all - */ - -static boolean p_give_ammo(player_t *player, ammotype_t ammo, int num) -{ - int oldammo; - - if (ammo == am_noammo) return false; - - if (ammo >= NUMAMMO) i_error("p_give_ammo: bad type %i", ammo); - - if (player->ammo[ammo] == player->maxammo[ammo]) return false; - - if (num) - num *= clipammo[ammo]; - else - num = clipammo[ammo] / 2; - - if (gameskill == sk_baby || gameskill == sk_nightmare) - { - /* give double ammo in trainer mode, you'll need in nightmare */ - - num <<= 1; - } - - oldammo = player->ammo[ammo]; - player->ammo[ammo] += num; - - if (player->ammo[ammo] > player->maxammo[ammo]) - player->ammo[ammo] = player->maxammo[ammo]; - - /* If non zero ammo, don't change up weapons, player was lower on purpose. - */ - - if (oldammo) return true; - - /* We were down to zero, so select a new weapon. Preferences are not user - * selectable. - */ - - switch (ammo) - { - case am_clip: - if (player->readyweapon == wp_fist) - { - if (player->weaponowned[wp_chaingun]) - player->pendingweapon = wp_chaingun; - else - player->pendingweapon = wp_pistol; - } - - break; - - case am_shell: - if (player->readyweapon == wp_fist || player->readyweapon == wp_pistol) - { - if (player->weaponowned[wp_shotgun]) - player->pendingweapon = wp_shotgun; - } - - break; - - case am_cell: - if (player->readyweapon == wp_fist || player->readyweapon == wp_pistol) - { - if (player->weaponowned[wp_plasma]) - player->pendingweapon = wp_plasma; - } - - break; - - case am_misl: - if (player->readyweapon == wp_fist) - { - if (player->weaponowned[wp_missile]) - player->pendingweapon = wp_missile; - } - - default: - break; - } - - return true; -} - -/* p_give_weapon - * - * The weapon name may have a MF_DROPPED flag ored in. - */ - -static boolean p_give_weapon(player_t *player, weapontype_t weapon, - boolean dropped) -{ - boolean gaveammo; - boolean gaveweapon; - - if (netgame && (deathmatch != 2) && !dropped) - { - /* leave placed weapons forever on net games */ - - if (player->weaponowned[weapon]) return false; - - player->bonuscount += BONUSADD; - player->weaponowned[weapon] = true; - - if (deathmatch) - p_give_ammo(player, weaponinfo[weapon].ammo, 5); - else - p_give_ammo(player, weaponinfo[weapon].ammo, 2); - player->pendingweapon = weapon; - -#ifdef CONFIG_GAMES_NXDOOM_SOUND - if (player == &players[consoleplayer]) s_start_sound(NULL, SFX_WPNUP); -#endif - return false; - } - - if (weaponinfo[weapon].ammo != am_noammo) - { - /* give one clip with a dropped weapon, two clips with a found weapon */ - - if (dropped) - gaveammo = p_give_ammo(player, weaponinfo[weapon].ammo, 1); - else - gaveammo = p_give_ammo(player, weaponinfo[weapon].ammo, 2); - } - else - gaveammo = false; - - if (player->weaponowned[weapon]) - gaveweapon = false; - else - { - gaveweapon = true; - player->weaponowned[weapon] = true; - player->pendingweapon = weapon; - } - - return (gaveweapon || gaveammo); -} - -/* p_give_body - * Returns false if the body isn't needed at all - */ - -static boolean p_give_body(player_t *player, int num) -{ - if (player->health >= MAXHEALTH) return false; - - player->health += num; - if (player->health > MAXHEALTH) player->health = MAXHEALTH; - player->mo->health = player->health; - - return true; -} - -/* p_give_armor - * Returns false if the armor is worse than the current armor. - */ - -static boolean p_give_armor(player_t *player, int armortype) -{ - int hits; - - hits = armortype * 100; - if (player->armorpoints >= hits) return false; /* don't pick up */ - - player->armortype = armortype; - player->armorpoints = hits; - - return true; -} - -static void p_give_card(player_t *player, card_t card) -{ - if (player->cards[card]) return; - - player->bonuscount = BONUSADD; - player->cards[card] = 1; -} - -static void p_kill_mobj(mobj_t *source, mobj_t *target) -{ - mobjtype_t item; - mobj_t *mo; - - target->flags &= ~(MF_SHOOTABLE | MF_FLOAT | MF_SKULLFLY); - - if (target->type != MT_SKULL) target->flags &= ~MF_NOGRAVITY; - - target->flags |= MF_CORPSE | MF_DROPOFF; - target->height >>= 2; - - if (source && source->player) - { - /* count for intermission */ - - if (target->flags & MF_COUNTKILL) source->player->killcount++; - - if (target->player) source->player->frags[target->player - players]++; - } - else if (!netgame && (target->flags & MF_COUNTKILL)) - { - /* count all monster deaths, even those caused by other monsters */ - - players[0].killcount++; - } - - if (target->player) - { - /* count environment kills against you */ - - if (!source) target->player->frags[target->player - players]++; - - target->flags &= ~MF_SOLID; - target->player->playerstate = PST_DEAD; - p_drop_weapon(target->player); - - if (target->player == &players[consoleplayer] && automapactive) - { - /* don't die in auto map, switch view prior to dying */ - - am_stop(); - } - } - - if (target->health < -target->info->spawnhealth && - target->info->xdeathstate) - { - p_set_mobj_state(target, target->info->xdeathstate); - } - else - p_set_mobj_state(target, target->info->deathstate); - - target->tics -= p_random() & 3; - - if (target->tics < 1) target->tics = 1; - - /* In Chex Quest, monsters don't drop items. */ - - if (gameversion == exe_chex) - { - return; - } - - /* Drop stuff. - * This determines the kind of object spawned during the death frame of a - * thing. - */ - - switch (target->type) - { - case MT_WOLFSS: - case MT_POSSESSED: - item = MT_CLIP; - break; - - case MT_SHOTGUY: - item = MT_SHOTGUN; - break; - - case MT_CHAINGUY: - item = MT_CHAINGUN; - break; - - default: - return; - } - - mo = p_spawn_mobj(target->x, target->y, ONFLOORZ, item); - mo->flags |= MF_DROPPED; /* special versions of items */ -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -boolean p_give_power(player_t *player, int /* powertype_t */ power) -{ - if (power == pw_invulnerability) - { - player->powers[power] = INVULNTICS; - return true; - } - - if (power == pw_invisibility) - { - player->powers[power] = INVISTICS; - player->mo->flags |= MF_SHADOW; - return true; - } - - if (power == pw_infrared) - { - player->powers[power] = INFRATICS; - return true; - } - - if (power == pw_ironfeet) - { - player->powers[power] = IRONTICS; - return true; - } - - if (power == pw_strength) - { - p_give_body(player, 100); - player->powers[power] = 1; - return true; - } - - if (player->powers[power]) return false; /* already got it */ - - player->powers[power] = 1; - return true; -} - -void p_touch_special_thing(mobj_t *special, mobj_t *toucher) -{ - player_t *player; - int i; - fixed_t delta; -#ifdef CONFIG_GAMES_NXDOOM_SOUND - int sound; -#endif - - delta = special->z - toucher->z; - - if (delta > toucher->height || delta < -8 * FRACUNIT) - { - return; /* out of reach */ - } - -#ifdef CONFIG_GAMES_NXDOOM_SOUND - sound = SFX_ITEMUP; -#endif - player = toucher->player; - - /* Dead thing touching. Can happen with a sliding player corpse. */ - - if (toucher->health <= 0) return; - - /* Identify by sprite. */ - - switch (special->sprite) - { - /* armor */ - - case SPR_ARM1: - if (!p_give_armor(player, deh_green_armor_class)) return; - player->message = (GOTARMOR); - break; - - case SPR_ARM2: - if (!p_give_armor(player, deh_blue_armor_class)) return; - player->message = (GOTMEGA); - break; - - /* bonus items */ - - case SPR_BON1: - player->health++; /* can go over 100% */ - if (player->health > deh_max_health) player->health = deh_max_health; - player->mo->health = player->health; - player->message = (GOTHTHBONUS); - break; - - case SPR_BON2: - player->armorpoints++; /* can go over 100% */ - if (player->armorpoints > deh_max_armor && gameversion > exe_doom_1_2) - { - player->armorpoints = deh_max_armor; - } - - /* deh_green_armor_class only applies to the green armor shirt; - * for the armor helmets, armortype 1 is always used. - */ - - if (!player->armortype) player->armortype = 1; - player->message = (GOTARMBONUS); - break; - - case SPR_SOUL: - player->health += deh_soulsphere_health; - if (player->health > deh_max_soulsphere) - player->health = deh_max_soulsphere; - player->mo->health = player->health; - player->message = (GOTSUPER); - -#ifdef CONFIG_GAMES_NXDOOM_SOUND - if (gameversion > exe_doom_1_2) sound = SFX_GETPOW; -#endif - break; - - case SPR_MEGA: - if (gamemode != commercial) return; - player->health = deh_megasphere_health; - player->mo->health = player->health; - - /* We always give armor type 2 for the megasphere; dehacked only - * affects the MegaArmor. - */ - - p_give_armor(player, 2); - player->message = (GOTMSPHERE); -#ifdef CONFIG_GAMES_NXDOOM_SOUND - if (gameversion > exe_doom_1_2) sound = SFX_GETPOW; -#endif - break; - - /* cards - * leave cards for everyone - */ - - case SPR_BKEY: - if (!player->cards[it_bluecard]) player->message = (GOTBLUECARD); - p_give_card(player, it_bluecard); - if (!netgame) break; - return; - - case SPR_YKEY: - if (!player->cards[it_yellowcard]) player->message = (GOTYELWCARD); - p_give_card(player, it_yellowcard); - if (!netgame) break; - return; - - case SPR_RKEY: - if (!player->cards[it_redcard]) player->message = (GOTREDCARD); - p_give_card(player, it_redcard); - if (!netgame) break; - return; - - case SPR_BSKU: - if (!player->cards[it_blueskull]) player->message = (GOTBLUESKUL); - p_give_card(player, it_blueskull); - if (!netgame) break; - return; - - case SPR_YSKU: - if (!player->cards[it_yellowskull]) player->message = (GOTYELWSKUL); - p_give_card(player, it_yellowskull); - if (!netgame) break; - return; - - case SPR_RSKU: - if (!player->cards[it_redskull]) player->message = (GOTREDSKULL); - p_give_card(player, it_redskull); - if (!netgame) break; - return; - - /* medikits, heals */ - - case SPR_STIM: - if (!p_give_body(player, 10)) return; - player->message = (GOTSTIM); - break; - - case SPR_MEDI: - if (!p_give_body(player, 25)) return; - - if (player->health < 25) - player->message = (GOTMEDINEED); - else - player->message = (GOTMEDIKIT); - break; - - /* power ups */ - - case SPR_PINV: - if (!p_give_power(player, pw_invulnerability)) return; - player->message = (GOTINVUL); -#ifdef CONFIG_GAMES_NXDOOM_SOUND - if (gameversion > exe_doom_1_2) sound = SFX_GETPOW; -#endif - break; - - case SPR_PSTR: - if (!p_give_power(player, pw_strength)) return; - player->message = (GOTBERSERK); - if (player->readyweapon != wp_fist) player->pendingweapon = wp_fist; -#ifdef CONFIG_GAMES_NXDOOM_SOUND - if (gameversion > exe_doom_1_2) sound = SFX_GETPOW; -#endif - break; - - case SPR_PINS: - if (!p_give_power(player, pw_invisibility)) return; - player->message = (GOTINVIS); -#ifdef CONFIG_GAMES_NXDOOM_SOUND - if (gameversion > exe_doom_1_2) sound = SFX_GETPOW; -#endif - break; - - case SPR_SUIT: - if (!p_give_power(player, pw_ironfeet)) return; - player->message = (GOTSUIT); -#ifdef CONFIG_GAMES_NXDOOM_SOUND - if (gameversion > exe_doom_1_2) sound = SFX_GETPOW; -#endif - break; - - case SPR_PMAP: - if (!p_give_power(player, pw_allmap)) return; - player->message = (GOTMAP); -#ifdef CONFIG_GAMES_NXDOOM_SOUND - if (gameversion > exe_doom_1_2) sound = SFX_GETPOW; -#endif - break; - - case SPR_PVIS: - if (!p_give_power(player, pw_infrared)) return; - player->message = (GOTVISOR); -#ifdef CONFIG_GAMES_NXDOOM_SOUND - if (gameversion > exe_doom_1_2) sound = SFX_GETPOW; -#endif - break; - - /* ammo */ - - case SPR_CLIP: - if (special->flags & MF_DROPPED) - { - if (!p_give_ammo(player, am_clip, 0)) return; - } - else - { - if (!p_give_ammo(player, am_clip, 1)) return; - } - - player->message = (GOTCLIP); - break; - - case SPR_AMMO: - if (!p_give_ammo(player, am_clip, 5)) return; - player->message = (GOTCLIPBOX); - break; - - case SPR_ROCK: - if (!p_give_ammo(player, am_misl, 1)) return; - player->message = (GOTROCKET); - break; - - case SPR_BROK: - if (!p_give_ammo(player, am_misl, 5)) return; - player->message = (GOTROCKBOX); - break; - - case SPR_CELL: - if (!p_give_ammo(player, am_cell, 1)) return; - player->message = (GOTCELL); - break; - - case SPR_CELP: - if (!p_give_ammo(player, am_cell, 5)) return; - player->message = (GOTCELLBOX); - break; - - case SPR_SHEL: - if (!p_give_ammo(player, am_shell, 1)) return; - player->message = (GOTSHELLS); - break; - - case SPR_SBOX: - if (!p_give_ammo(player, am_shell, 5)) return; - player->message = (GOTSHELLBOX); - break; - - case SPR_BPAK: - if (!player->backpack) - { - for (i = 0; i < NUMAMMO; i++) - player->maxammo[i] *= 2; - player->backpack = true; - } - - for (i = 0; i < NUMAMMO; i++) - p_give_ammo(player, i, 1); - player->message = (GOTBACKPACK); - break; - - /* weapons */ - - case SPR_BFUG: - if (!p_give_weapon(player, wp_bfg, false)) return; - player->message = (GOTBFG9000); -#ifdef CONFIG_GAMES_NXDOOM_SOUND - sound = SFX_WPNUP; -#endif - break; - - case SPR_MGUN: - if (!p_give_weapon(player, wp_chaingun, - (special->flags & MF_DROPPED) != 0)) - return; - player->message = (GOTCHAINGUN); -#ifdef CONFIG_GAMES_NXDOOM_SOUND - sound = SFX_WPNUP; -#endif - break; - - case SPR_CSAW: - if (!p_give_weapon(player, wp_chainsaw, false)) return; - player->message = (GOTCHAINSAW); -#ifdef CONFIG_GAMES_NXDOOM_SOUND - sound = SFX_WPNUP; -#endif - break; - - case SPR_LAUN: - if (!p_give_weapon(player, wp_missile, false)) return; - player->message = (GOTLAUNCHER); -#ifdef CONFIG_GAMES_NXDOOM_SOUND - sound = SFX_WPNUP; -#endif - break; - - case SPR_PLAS: - if (!p_give_weapon(player, wp_plasma, false)) return; - player->message = (GOTPLASMA); -#ifdef CONFIG_GAMES_NXDOOM_SOUND - sound = SFX_WPNUP; -#endif - break; - - case SPR_SHOT: - if (!p_give_weapon(player, wp_shotgun, - (special->flags & MF_DROPPED) != 0)) - return; - player->message = (GOTSHOTGUN); -#ifdef CONFIG_GAMES_NXDOOM_SOUND - sound = SFX_WPNUP; -#endif - break; - - case SPR_SGN2: - if (!p_give_weapon(player, wp_supershotgun, - (special->flags & MF_DROPPED) != 0)) - return; - player->message = (GOTSHOTGUN2); -#ifdef CONFIG_GAMES_NXDOOM_SOUND - sound = SFX_WPNUP; -#endif - break; - - default: - i_error("P_SpecialThing: Unknown gettable thing"); - } - - if (special->flags & MF_COUNTITEM) player->itemcount++; - p_remove_mobj(special); - player->bonuscount += BONUSADD; -#ifdef CONFIG_GAMES_NXDOOM_SOUND - if (player == &players[consoleplayer]) s_start_sound(NULL, sound); -#endif -} - -/* p_damage_mobj - * Damages both enemies and players "inflictor" is the thing that caused the - * damage creature or missile, can be NULL (slime, etc) "source" is the thing - * to target after taking damage creature or NULL - * - * Source and inflictor are the same for melee attacks. - * Source can be NULL for slime, barrel explosions and other environmental - * stuff. - */ - -void p_damage_mobj(mobj_t *target, mobj_t *inflictor, mobj_t *source, - int damage) -{ - unsigned ang; - int saved; - player_t *player; - fixed_t thrust; - int temp; - - if (!(target->flags & MF_SHOOTABLE)) return; /* shouldn't happen... */ - - if (target->health <= 0) return; - - if (target->flags & MF_SKULLFLY) - { - target->momx = target->momy = target->momz = 0; - } - - player = target->player; - if (player && gameskill == sk_baby) - damage >>= 1; /* take half damage in trainer mode */ - - /* Some close combat weapons should not - * inflict thrust and push the victim out of reach, - * thus kick away unless using the chainsaw. - */ - - if (inflictor && !(target->flags & MF_NOCLIP) && - (!source || !source->player || - source->player->readyweapon != wp_chainsaw)) - { - ang = r_point_to_angle2(inflictor->x, inflictor->y, - target->x, target->y); - - thrust = damage * (FRACUNIT >> 3) * 100 / target->info->mass; - - /* make fall forwards sometimes */ - - if (damage < 40 && damage > target->health && - target->z - inflictor->z > 64 * FRACUNIT && (p_random() & 1)) - { - ang += ANG180; - thrust *= 4; - } - - ang >>= ANGLETOFINESHIFT; - target->momx += fixed_mul(thrust, finecosine[ang]); - target->momy += fixed_mul(thrust, finesine[ang]); - } - - /* player specific */ - - if (player) - { - /* end of game hell hack */ - - if (target->subsector->sector->special == 11 && - damage >= target->health) - { - damage = target->health - 1; - } - - /* Below certain threshold, ignore damage in GOD mode, or with INVUL - * power. - */ - - if (damage < 1000 && ((player->cheats & CF_GODMODE) || - player->powers[pw_invulnerability])) - { - return; - } - - if (player->armortype) - { - if (player->armortype == 1) - saved = damage / 3; - else - saved = damage / 2; - - if (player->armorpoints <= saved) - { - /* armor is used up */ - - saved = player->armorpoints; - player->armortype = 0; - } - - player->armorpoints -= saved; - damage -= saved; - } - - player->health -= damage; /* mirror mobj health here for Dave */ - if (player->health < 0) player->health = 0; - - player->attacker = source; - player->damagecount += damage; /* add damage after armor / invuln */ - - if (player->damagecount > 100) - { - player->damagecount = 100; /* teleport stomp does 10k points... */ - } - - temp = damage < 100 ? damage : 100; - - if (player == &players[consoleplayer]) - { - i_tactile(40, 10, 40 + temp * 2); - } - } - - /* do the damage */ - - target->health -= damage; - if (target->health <= 0) - { - p_kill_mobj(source, target); - return; - } - - if ((p_random() < target->info->painchance) && - !(target->flags & MF_SKULLFLY)) - { - target->flags |= MF_JUSTHIT; /* fight back! */ - - p_set_mobj_state(target, target->info->painstate); - } - - target->reactiontime = 0; /* we're awake now... */ - - if ((!target->threshold || target->type == MT_VILE) && source && - (source != target || gameversion < exe_doom_1_5) && - source->type != MT_VILE) - { - /* if not intent on another player, chase after this one */ - - target->target = source; - target->threshold = BASETHRESHOLD; - if (target->state == &states[target->info->spawnstate] && - target->info->seestate != S_NULL) - p_set_mobj_state(target, target->info->seestate); - } -} diff --git a/games/NXDoom/src/doom/p_inter.h b/games/NXDoom/src/doom/p_inter.h deleted file mode 100644 index 450349e9c..000000000 --- a/games/NXDoom/src/doom/p_inter.h +++ /dev/null @@ -1,30 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/p_inter.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - ****************************************************************************/ - -#ifndef __P_INTER__ -#define __P_INTER__ - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -boolean p_give_power(player_t *, int); - -#endif /* __P_INTER__ */ diff --git a/games/NXDoom/src/doom/p_lights.c b/games/NXDoom/src/doom/p_lights.c deleted file mode 100644 index 019e1c941..000000000 --- a/games/NXDoom/src/doom/p_lights.c +++ /dev/null @@ -1,314 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/p_lights.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Handle Sector base lighting effects. - * Muzzle flash? - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "m_random.h" -#include "z_zone.h" - -#include "doomdef.h" -#include "p_local.h" - -/* State. */ - -#include "r_state.h" - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/* FIRELIGHT FLICKER */ - -/* t_fire_flicker */ - -static void t_fire_flicker(fireflicker_t *flick) -{ - int amount; - - if (--flick->count) return; - - amount = (p_random() & 3) * 16; - - if (flick->sector->lightlevel - amount < flick->minlight) - flick->sector->lightlevel = flick->minlight; - else - flick->sector->lightlevel = flick->maxlight - amount; - - flick->count = 4; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -void p_spawn_fire_flicker(sector_t *sector) -{ - fireflicker_t *flick; - - /* Note that we are resetting sector attributes. Nothing special about it - * during gameplay. - */ - - sector->special = 0; - - flick = z_malloc(sizeof(*flick), PU_LEVSPEC, 0); - - p_add_thinker(&flick->thinker); - - flick->thinker.function.acp1 = (actionf_p1)t_fire_flicker; - flick->sector = sector; - flick->maxlight = sector->lightlevel; - flick->minlight = p_find_min_surrounding(sector, sector->lightlevel) + 16; - flick->count = 4; -} - -/* BROKEN LIGHT FLASHING */ - -/* t_light_flash - * Do flashing lights. - */ - -void t_light_flash(lightflash_t *flash) -{ - if (--flash->count) return; - - if (flash->sector->lightlevel == flash->maxlight) - { - flash->sector->lightlevel = flash->minlight; - flash->count = (p_random() & flash->mintime) + 1; - } - else - { - flash->sector->lightlevel = flash->maxlight; - flash->count = (p_random() & flash->maxtime) + 1; - } -} - -/* p_spawn_light_flash - * After the map has been loaded, scan each sector for specials that spawn - * thinkers - */ - -void p_spawn_light_flash(sector_t *sector) -{ - lightflash_t *flash; - - /* nothing special about it during gameplay */ - - sector->special = 0; - - flash = z_malloc(sizeof(*flash), PU_LEVSPEC, 0); - - p_add_thinker(&flash->thinker); - - flash->thinker.function.acp1 = (actionf_p1)t_light_flash; - flash->sector = sector; - flash->maxlight = sector->lightlevel; - - flash->minlight = p_find_min_surrounding(sector, sector->lightlevel); - flash->maxtime = 64; - flash->mintime = 7; - flash->count = (p_random() & flash->maxtime) + 1; -} - -/* STROBE LIGHT FLASHING */ - -void t_strobe_flash(strobe_t *flash) -{ - if (--flash->count) return; - - if (flash->sector->lightlevel == flash->minlight) - { - flash->sector->lightlevel = flash->maxlight; - flash->count = flash->brighttime; - } - else - { - flash->sector->lightlevel = flash->minlight; - flash->count = flash->darktime; - } -} - -/* p_spawn_strobe_flash - * After the map has been loaded, scan each sector for specials that spawn - * thinkers - */ - -void p_spawn_strobe_flash(sector_t *sector, int fast_or_slow, int in_sync) -{ - strobe_t *flash; - - flash = z_malloc(sizeof(*flash), PU_LEVSPEC, 0); - - p_add_thinker(&flash->thinker); - - flash->sector = sector; - flash->darktime = fast_or_slow; - flash->brighttime = STROBEBRIGHT; - flash->thinker.function.acp1 = (actionf_p1)t_strobe_flash; - flash->maxlight = sector->lightlevel; - flash->minlight = p_find_min_surrounding(sector, sector->lightlevel); - - if (flash->minlight == flash->maxlight) flash->minlight = 0; - - /* nothing special about it during gameplay */ - - sector->special = 0; - - if (!in_sync) - flash->count = (p_random() & 7) + 1; - else - flash->count = 1; -} - -/* Start strobing lights (usually from a trigger) */ - -void ev_start_light_strobing(line_t *line) -{ - int secnum; - sector_t *sec; - - secnum = -1; - while ((secnum = p_find_sector_from_line_tag(line, secnum)) >= 0) - { - sec = §ors[secnum]; - if (sec->specialdata) continue; - - p_spawn_strobe_flash(sec, SLOWDARK, 0); - } -} - -/* TURN LINE'S TAG LIGHTS OFF */ - -void ev_turn_tag_lights_off(line_t *line) -{ - int i; - int j; - int min; - sector_t *sector; - sector_t *tsec; - line_t *templine; - - sector = sectors; - - for (j = 0; j < numsectors; j++, sector++) - { - if (sector->tag == line->tag) - { - min = sector->lightlevel; - for (i = 0; i < sector->linecount; i++) - { - templine = sector->lines[i]; - tsec = get_next_sector(templine, sector); - if (!tsec) continue; - if (tsec->lightlevel < min) min = tsec->lightlevel; - } - - sector->lightlevel = min; - } - } -} - -/* TURN LINE'S TAG LIGHTS ON */ - -void ev_light_turn_on(line_t *line, int bright) -{ - int i; - int j; - sector_t *sector; - sector_t *temp; - line_t *templine; - - sector = sectors; - - for (i = 0; i < numsectors; i++, sector++) - { - if (sector->tag == line->tag) - { - /* bright = 0 means to search for highest light level surrounding - * sector - */ - - if (!bright) - { - for (j = 0; j < sector->linecount; j++) - { - templine = sector->lines[j]; - temp = get_next_sector(templine, sector); - - if (!temp) continue; - - if (temp->lightlevel > bright) bright = temp->lightlevel; - } - } - - sector->lightlevel = bright; - } - } -} - -/* Spawn glowing light */ - -void t_glow(glow_t *g) -{ - switch (g->direction) - { - case -1: /* DOWN */ - g->sector->lightlevel -= GLOWSPEED; - if (g->sector->lightlevel <= g->minlight) - { - g->sector->lightlevel += GLOWSPEED; - g->direction = 1; - } - break; - - case 1: /* UP */ - g->sector->lightlevel += GLOWSPEED; - if (g->sector->lightlevel >= g->maxlight) - { - g->sector->lightlevel -= GLOWSPEED; - g->direction = -1; - } - break; - } -} - -void p_spawn_glowing_light(sector_t *sector) -{ - glow_t *g; - - g = z_malloc(sizeof(*g), PU_LEVSPEC, 0); - - p_add_thinker(&g->thinker); - - g->sector = sector; - g->minlight = p_find_min_surrounding(sector, sector->lightlevel); - g->maxlight = sector->lightlevel; - g->thinker.function.acp1 = (actionf_p1)t_glow; - g->direction = -1; - - sector->special = 0; -} diff --git a/games/NXDoom/src/doom/p_local.h b/games/NXDoom/src/doom/p_local.h deleted file mode 100644 index 30bd51d63..000000000 --- a/games/NXDoom/src/doom/p_local.h +++ /dev/null @@ -1,268 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/p_local.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Play functions, animation, global header. - * - ****************************************************************************/ - -#ifndef __P_LOCAL__ -#define __P_LOCAL__ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#ifndef __R_LOCAL__ -#include "r_local.h" -#endif - -/* P_SPEC */ - -#include "p_spec.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define FLOATSPEED (FRACUNIT * 4) - -#define MAXHEALTH 100 -#define VIEWHEIGHT (41 * FRACUNIT) - -/* mapblocks are used to check movement against lines and things */ - -#define MAPBLOCKUNITS 128 -#define MAPBLOCKSIZE (MAPBLOCKUNITS * FRACUNIT) -#define MAPBLOCKSHIFT (FRACBITS + 7) -#define MAPBMASK (MAPBLOCKSIZE - 1) -#define MAPBTOFRAC (MAPBLOCKSHIFT - FRACBITS) - -/* player radius for movement checking */ - -#define PLAYERRADIUS 16 * FRACUNIT - -/* MAXRADIUS is for precalculated sector block boxes the spider demon is - * larger, but we do not have any moving sectors nearby - */ - -#define MAXRADIUS 32 * FRACUNIT - -#define GRAVITY FRACUNIT -#define MAXMOVE (30 * FRACUNIT) - -#define USERANGE (64 * FRACUNIT) -#define MELEERANGE (64 * FRACUNIT) -#define MISSILERANGE (32 * 64 * FRACUNIT) - -/* follow a player exclusively for 3 seconds */ - -#define BASETHRESHOLD 100 - -#define ONFLOORZ INT_MIN -#define ONCEILINGZ INT_MAX - -/* Time interval for item respawning. */ - -#define ITEMQUESIZE 128 - -/* Extended MAXINTERCEPTS, to allow for intercepts overrun emulation. */ - -#define MAXINTERCEPTS_ORIGINAL 128 -#define MAXINTERCEPTS (MAXINTERCEPTS_ORIGINAL + 61) - -#define PT_ADDLINES 1 -#define PT_ADDTHINGS 2 -#define PT_EARLYOUT 4 - -/* fraggle: I have increased the size of this buffer. In the original Doom, - * overrunning past this limit caused other bits of memory to be overwritten, - * affecting demo playback. However, in doing so, the limit was still - * exceeded. So we have to support more than 8 specials. - * - * We keep the original limit, to detect what variables in memory were - * overwritten (see SpechitOverrun()) - */ - -#define MAXSPECIALCROSS 20 -#define MAXSPECIALCROSS_ORIGINAL 8 - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -/* P_MAPUTL */ - -typedef struct -{ - fixed_t x; - fixed_t y; - fixed_t dx; - fixed_t dy; -} divline_t; - -typedef struct -{ - fixed_t frac; /* along trace line */ - boolean isaline; - union - { - mobj_t *thing; - line_t *line; - } d; -} intercept_t; - -typedef boolean (*traverser_t)(intercept_t *in); - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/* P_TICK */ - -/* both the head and tail of the thinker list */ - -extern thinker_t thinkercap; - -extern mapthing_t itemrespawnque[ITEMQUESIZE]; -extern int itemrespawntime[ITEMQUESIZE]; -extern int iquehead; -extern int iquetail; - -extern intercept_t intercepts[MAXINTERCEPTS]; -extern intercept_t *intercept_p; - -extern fixed_t opentop; -extern fixed_t openbottom; -extern fixed_t openrange; -extern fixed_t lowfloor; - -extern divline_t trace; - -/* If "floatok" true, move would be ok if within "tmfloorz - tmceilingz". */ - -extern boolean floatok; -extern fixed_t tmfloorz; -extern fixed_t tmceilingz; - -extern line_t *ceilingline; - -extern line_t *spechit[MAXSPECIALCROSS]; -extern int numspechit; - -extern mobj_t *linetarget; /* who got hit (or NULL) */ - -extern fixed_t attackrange; - -/* slopes to top and bottom of target */ - -extern fixed_t topslope; -extern fixed_t bottomslope; - -extern byte *rejectmatrix; /* for fast sight rejection */ -extern short *blockmaplump; /* offsets in blockmap are from here */ -extern short *blockmap; -extern int bmapwidth; -extern int bmapheight; /* in mapblocks */ -extern fixed_t bmaporgx; -extern fixed_t bmaporgy; /* origin of block map */ -extern mobj_t **blocklinks; /* for thing chains */ - -extern int maxammo[NUMAMMO]; -extern int clipammo[NUMAMMO]; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -void p_init_thinkers(void); -void p_add_thinker(thinker_t *thinker); -void p_remove_thinker(thinker_t *thinker); - -/* P_PSPR */ - -void p_setup_psprites(player_t *curplayer); -void p_move_psprites(player_t *curplayer); -void p_drop_weapon(player_t *player); - -/* P_USER */ - -void p_player_think(player_t *player); - -/* P_MOBJ */ - -void p_respawn_specials(void); - -mobj_t *p_spawn_mobj(fixed_t x, fixed_t y, fixed_t z, mobjtype_t type); - -void p_remove_mobj(mobj_t *th); -mobj_t *p_subst_null_mobj(mobj_t *th); -boolean p_set_mobj_state(mobj_t *mobj, statenum_t state); -void p_mobj_thinker(mobj_t *mobj); - -void p_spawn_puff(fixed_t x, fixed_t y, fixed_t z); -void p_spawn_blood(fixed_t x, fixed_t y, fixed_t z, int damage); -mobj_t *p_spawn_missile(mobj_t *source, mobj_t *dest, mobjtype_t type); -void p_spawn_player_missile(mobj_t *source, mobjtype_t type); - -/* P_ENEMY */ - -void p_noise_alert(mobj_t *target, mobj_t *emmiter); - -fixed_t p_approx_distance(fixed_t dx, fixed_t dy); -int p_point_on_line_side(fixed_t x, fixed_t y, line_t *line); -int p_point_on_divline_side(fixed_t x, fixed_t y, divline_t *line); -int p_box_on_line_side(fixed_t *tmbox, line_t *ld); - -void p_line_opening(line_t *linedef); - -boolean p_block_lines_iterator(int x, int y, boolean (*func)(line_t *)); -boolean p_block_things_iterator(int x, int y, boolean (*func)(mobj_t *)); - -boolean p_path_traverse(fixed_t x1, fixed_t y1, fixed_t x2, fixed_t y2, - int flags, boolean (*trav)(intercept_t *)); - -void p_unset_thing_position(mobj_t *thing); -void p_set_thing_position(mobj_t *thing); - -/* P_MAP */ - -boolean p_check_position(mobj_t *thing, fixed_t x, fixed_t y); -boolean p_try_move(mobj_t *thing, fixed_t x, fixed_t y); -boolean p_teleport_move(mobj_t *thing, fixed_t x, fixed_t y); -void p_slide_move(mobj_t *mo); -boolean p_check_sight(mobj_t *t1, mobj_t *t2); -void p_use_lines(player_t *player); - -boolean p_change_sector(sector_t *sector, boolean crunch); - -fixed_t p_aim_line_attack(mobj_t *t1, angle_t angle, fixed_t distance); - -void p_line_attack(mobj_t *t1, angle_t angle, fixed_t distance, - fixed_t slope, int damage); - -void p_radius_attack(mobj_t *spot, mobj_t *source, int damage); - -/* P_INTER */ - -void p_touch_special_thing(mobj_t *special, mobj_t *toucher); - -void p_damage_mobj(mobj_t *target, mobj_t *inflictor, mobj_t *source, - int damage); - -#endif /* __P_LOCAL__ */ diff --git a/games/NXDoom/src/doom/p_map.c b/games/NXDoom/src/doom/p_map.c deleted file mode 100644 index 2b4aa4386..000000000 --- a/games/NXDoom/src/doom/p_map.c +++ /dev/null @@ -1,1470 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/p_map.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard, Andrey Budko - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Movement, collision handling. - * Shooting and aiming. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -#include "deh_misc.h" - -#include "i_system.h" -#include "m_bbox.h" -#include "m_random.h" - -#include "doomdef.h" -#include "m_argv.h" -#include "m_misc.h" -#include "p_local.h" - -#ifdef CONFIG_GAMES_NXDOOM_SOUND -#include "s_sound.h" -#include "sounds.h" -#endif - -#include "doomstat.h" -#include "r_state.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* Spechit overrun magic value. - * - * This is the value used by PrBoom-plus. I think the value below is - * actually better and works with more demos. However, I think - * it's better for the spechits emulation to be compatible with - * PrBoom-plus, at least so that the big spechits emulation list - * on Doomworld can also be used with Chocolate Doom. - */ - -#define DEFAULT_SPECHIT_MAGIC 0x01C09C98 - -/* This is from a post by myk on the Doomworld forums, - * outputted from entryway's spechit_magic generator for - * s205n546.lmp. The _exact_ value of this isn't too - * important; as long as it is in the right general - * range, it will usually work. Otherwise, we can use - * the generator (hacked doom2.exe) and provide it - * with -spechit. - */ - -/* #define DEFAULT_SPECHIT_MAGIC 0x84f968e8 */ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -fixed_t tmbbox[4]; -mobj_t *tmthing; -int tmflags; -fixed_t tmx; -fixed_t tmy; - -/* If "floatok" true, move would be ok - * if within "tmfloorz - tmceilingz". - */ - -boolean floatok; - -fixed_t tmfloorz; -fixed_t tmceilingz; -fixed_t tmdropoffz; - -/* keep track of the line that lowers the ceiling, - * so missiles don't explode against sky hack walls - */ - -line_t *ceilingline; - -/* keep track of special lines as they are hit, - * but don't process them until the move is proven valid - */ - -line_t *spechit[MAXSPECIALCROSS]; -int numspechit; - -/* SLIDE MOVE - * Allows the player to slide along any angled walls. - */ - -fixed_t bestslidefrac; -fixed_t secondslidefrac; - -line_t *bestslideline; -line_t *secondslideline; - -mobj_t *slidemo; - -fixed_t tmxmove; -fixed_t tmymove; - -/* p_line_attack */ - -mobj_t *linetarget; /* who got hit (or NULL) */ -mobj_t *shootthing; - -/* Height if not aiming up or down - * ???: use slope for monsters? - */ - -fixed_t shootz; - -int la_damage; -fixed_t attackrange; - -fixed_t aimslope; - -/* USE LINES */ - -mobj_t *usething; - -/* RADIUS ATTACK */ - -mobj_t *bombsource; -mobj_t *bombspot; -int bombdamage; - -/* SECTOR HEIGHT CHANGING - * After modifying a sectors floor or ceiling height, - * call this routine to adjust the positions - * of all things that touch the sector. - * - * If anything doesn't fit anymore, true will be returned. - * - * If crunch is true, they will take damage as they are being crushed. - * - * If Crunch is false, you should set the sector height back the way it was - * and call p_change_sector again to undo the changes. - */ - -boolean crushchange; -boolean nofit; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/* TELEPORT MOVE */ - -static boolean pit_stomp_thing(mobj_t *thing) -{ - fixed_t blockdist; - - if (!(thing->flags & MF_SHOOTABLE)) return true; - - blockdist = thing->radius + tmthing->radius; - - if (abs(thing->x - tmx) >= blockdist || abs(thing->y - tmy) >= blockdist) - { - return true; /* didn't hit it */ - } - - /* don't clip against self */ - - if (thing == tmthing) return true; - - /* monsters don't stomp things except on boss level */ - - if (!tmthing->player && gamemap != 30) return false; - - p_damage_mobj(thing, tmthing, tmthing, 10000); - - return true; -} - -/* Code to emulate the behavior of Vanilla Doom when encountering an overrun - * of the spechit array. This is by Andrey Budko (e6y) and comes from his - * PrBoom plus port. A big thanks to Andrey for this. - */ - -static void spechit_overrun(line_t *ld) -{ - static unsigned int baseaddr = 0; - unsigned int addr; - - if (baseaddr == 0) - { - int p; - - /* This is the first time we have had an overrun. Work out - * what base address we are going to use. - * Allow a spechit value to be specified on the command line. - */ - - /* @category compat - * @arg - * - * Use the specified magic value when emulating spechit overruns. - */ - - p = m_check_parm_with_args("-spechit", 1); - - if (p > 0) - { - m_str_to_int(myargv[p + 1], (int *)&baseaddr); - } - else - { - baseaddr = DEFAULT_SPECHIT_MAGIC; - } - } - - /* Calculate address used in doom2.exe */ - - addr = baseaddr + (ld - lines) * 0x3e; - - switch (numspechit) - { - case 9: - case 10: - case 11: - case 12: - tmbbox[numspechit - 9] = addr; - break; - case 13: - crushchange = addr; - break; - case 14: - nofit = addr; - break; - default: - fprintf(stderr, - "SpechitOverrun: Warning: unable to emulate" - "an overrun where numspechit=%i\n", - numspechit); - break; - } -} - -/* pit_check_line - * Adjusts tmfloorz and tmceilingz as lines are contacted - */ - -static boolean pit_check_line(line_t *ld) -{ - if (tmbbox[BOXRIGHT] <= ld->bbox[BOXLEFT] || - tmbbox[BOXLEFT] >= ld->bbox[BOXRIGHT] || - tmbbox[BOXTOP] <= ld->bbox[BOXBOTTOM] || - tmbbox[BOXBOTTOM] >= ld->bbox[BOXTOP]) - { - return true; - } - - if (p_box_on_line_side(tmbbox, ld) != -1) return true; - - /* A line has been hit */ - - /* The moving thing's destination position will cross - * the given line. - * If this should not be allowed, return false. - * If the line is special, keep track of it - * to process later if the move is proven ok. - * NOTE: specials are NOT sorted by order, - * so two special lines that are only 8 pixels apart - * could be crossed in either order. - */ - - if (!ld->backsector) return false; /* one sided line */ - - if (!(tmthing->flags & MF_MISSILE)) - { - if (ld->flags & ML_BLOCKING) - { - return false; /* explicitly blocking everything */ - } - - if (!tmthing->player && ld->flags & ML_BLOCKMONSTERS) - { - return false; /* block monsters only */ - } - } - - /* set openrange, opentop, openbottom */ - - p_line_opening(ld); - - /* adjust floor / ceiling heights */ - - if (opentop < tmceilingz) - { - tmceilingz = opentop; - ceilingline = ld; - } - - if (openbottom > tmfloorz) tmfloorz = openbottom; - - if (lowfloor < tmdropoffz) tmdropoffz = lowfloor; - - /* if contacted a special line, add it to the list */ - - if (ld->special) - { - spechit[numspechit] = ld; - numspechit++; - - /* fraggle: spechits overrun emulation code from prboom-plus */ - - if (numspechit > MAXSPECIALCROSS_ORIGINAL) - { - spechit_overrun(ld); - } - } - - return true; -} - -/* pit_radius_attack - * "bombsource" is the creature that caused the explosion at "bombspot". - */ - -static boolean pit_radius_attack(mobj_t *thing) -{ - fixed_t dx; - fixed_t dy; - fixed_t dist; - - if (!(thing->flags & MF_SHOOTABLE)) return true; - - /* Boss spider and cyborg take no damage from concussion. */ - - if (thing->type == MT_CYBORG || thing->type == MT_SPIDER) return true; - - dx = abs(thing->x - bombspot->x); - dy = abs(thing->y - bombspot->y); - - dist = dx > dy ? dx : dy; - dist = (dist - thing->radius) >> FRACBITS; - - if (dist < 0) dist = 0; - - if (dist >= bombdamage) return true; /* out of range */ - - if (p_check_sight(thing, bombspot)) - { - /* must be in direct path */ - - p_damage_mobj(thing, bombspot, bombsource, bombdamage - dist); - } - - return true; -} - -/* p_things_height_clip - * Takes a valid thing and adjusts the thing->floorz, thing->ceilingz, and - * possibly thing->z. - * - * This is called for all nearby monsters whenever a sector changes height. - * - * If the thing doesn't fit, the z will be set to the lowest value and false - * will be returned. - */ - -static boolean p_things_height_clip(mobj_t *thing) -{ - boolean onfloor; - - onfloor = (thing->z == thing->floorz); - - p_check_position(thing, thing->x, thing->y); - - /* what about stranding a monster partially off an edge? */ - - thing->floorz = tmfloorz; - thing->ceilingz = tmceilingz; - - if (onfloor) - { - /* walking monsters rise and fall with the floor */ - - thing->z = thing->floorz; - } - else - { - /* don't adjust a floating monster unless forced to */ - - if (thing->z + thing->height > thing->ceilingz) - thing->z = thing->ceilingz - thing->height; - } - - if (thing->ceilingz - thing->floorz < thing->height) return false; - - return true; -} - -/* p_hit_slide_line - * Adjusts the xmove / ymove so that the next move will slide along the wall. - */ - -static void p_hit_slide_line(line_t *ld) -{ - int side; - - angle_t lineangle; - angle_t moveangle; - angle_t deltaangle; - - fixed_t movelen; - fixed_t newlen; - - if (ld->slopetype == ST_HORIZONTAL) - { - tmymove = 0; - return; - } - - if (ld->slopetype == ST_VERTICAL) - { - tmxmove = 0; - return; - } - - side = p_point_on_line_side(slidemo->x, slidemo->y, ld); - - lineangle = r_point_to_angle2(0, 0, ld->dx, ld->dy); - - if (side == 1) lineangle += ANG180; - - moveangle = r_point_to_angle2(0, 0, tmxmove, tmymove); - deltaangle = moveangle - lineangle; - - if (deltaangle > ANG180) deltaangle += ANG180; - - lineangle >>= ANGLETOFINESHIFT; - deltaangle >>= ANGLETOFINESHIFT; - - movelen = p_approx_distance(tmxmove, tmymove); - newlen = fixed_mul(movelen, finecosine[deltaangle]); - - tmxmove = fixed_mul(newlen, finecosine[lineangle]); - tmymove = fixed_mul(newlen, finesine[lineangle]); -} - -/* ptr_slide_traverse */ - -static boolean ptr_slide_traverse(intercept_t *in) -{ - line_t *li; - - if (!in->isaline) i_error("ptr_slide_traverse: not a line?"); - - li = in->d.line; - - if (!(li->flags & ML_TWOSIDED)) - { - if (p_point_on_line_side(slidemo->x, slidemo->y, li)) - { - return true; /* don't hit the back side */ - } - - goto isblocking; - } - - /* set openrange, opentop, openbottom */ - - p_line_opening(li); - - if (openrange < slidemo->height) - { - goto isblocking; /* doesn't fit */ - } - - if (opentop - slidemo->z < slidemo->height) - { - goto isblocking; /* mobj is too high */ - } - - if (openbottom - slidemo->z > 24 * FRACUNIT) - { - goto isblocking; /* too big a step up */ - } - - /* this line doesn't block movement */ - - return true; - - /* the line does block movement, - * see if it is closer than best so far - */ - -isblocking: - if (in->frac < bestslidefrac) - { - secondslidefrac = bestslidefrac; - secondslideline = bestslideline; - bestslidefrac = in->frac; - bestslideline = li; - } - - return false; /* stop */ -} - -static boolean ptr_use_traverse(intercept_t *in) -{ - int side; - - if (!in->d.line->special) - { - p_line_opening(in->d.line); - if (openrange <= 0) - { -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(usething, SFX_NOWAY); -#endif - - /* can't use through a wall */ - - return false; - } - - /* not a special line, but keep checking */ - - return true; - } - - side = 0; - if (p_point_on_line_side(usething->x, usething->y, in->d.line) == 1) - { - side = 1; - } - - /* return false; don't use back side */ - - p_use_special_line(usething, in->d.line, side); - - /* can't use for than one special line in a row */ - - return false; -} - -/* ptr_aim_traverse - * Sets linetaget and aimslope when a target is aimed at. - */ - -static boolean ptr_aim_traverse(intercept_t *in) -{ - line_t *li; - mobj_t *th; - fixed_t slope; - fixed_t thingtopslope; - fixed_t thingbottomslope; - fixed_t dist; - - if (in->isaline) - { - li = in->d.line; - - if (!(li->flags & ML_TWOSIDED)) return false; /* stop */ - - /* Crosses a two sided line. - * A two sided line will restrict - * the possible target ranges. - */ - - p_line_opening(li); - - if (openbottom >= opentop) return false; /* stop */ - - dist = fixed_mul(attackrange, in->frac); - - if (li->backsector == NULL || - li->frontsector->floorheight != li->backsector->floorheight) - { - slope = fixed_div(openbottom - shootz, dist); - if (slope > bottomslope) bottomslope = slope; - } - - if (li->backsector == NULL || - li->frontsector->ceilingheight != li->backsector->ceilingheight) - { - slope = fixed_div(opentop - shootz, dist); - if (slope < topslope) topslope = slope; - } - - if (topslope <= bottomslope) return false; /* stop */ - - return true; /* shot continues */ - } - - /* shoot a thing */ - - th = in->d.thing; - if (th == shootthing) return true; /* can't shoot self */ - - if (!(th->flags & MF_SHOOTABLE)) return true; /* corpse or something */ - - /* check angles to see if the thing can be aimed at */ - - dist = fixed_mul(attackrange, in->frac); - thingtopslope = fixed_div(th->z + th->height - shootz, dist); - - if (thingtopslope < bottomslope) return true; /* shot over the thing */ - - thingbottomslope = fixed_div(th->z - shootz, dist); - - if (thingbottomslope > topslope) return true; /* shot under the thing */ - - /* this thing can be hit! */ - - if (thingtopslope > topslope) thingtopslope = topslope; - - if (thingbottomslope < bottomslope) thingbottomslope = bottomslope; - - aimslope = (thingtopslope + thingbottomslope) / 2; - linetarget = th; - - return false; /* don't go any farther */ -} - -/* ptr_shoot_traverse */ - -static boolean ptr_shoot_traverse(intercept_t *in) -{ - fixed_t x; - fixed_t y; - fixed_t z; - fixed_t frac; - - line_t *li; - - mobj_t *th; - - fixed_t slope; - fixed_t dist; - fixed_t thingtopslope; - fixed_t thingbottomslope; - - if (in->isaline) - { - li = in->d.line; - - if (li->special) p_shoot_special_line(shootthing, li); - - if (!(li->flags & ML_TWOSIDED)) goto hitline; - - /* crosses a two sided line */ - - p_line_opening(li); - - dist = fixed_mul(attackrange, in->frac); - - /* e6y: emulation of missed back side on two-sided lines. - * backsector can be NULL when emulating missing back side. - */ - - if (li->backsector == NULL) - { - slope = fixed_div(openbottom - shootz, dist); - if (slope > aimslope) goto hitline; - - slope = fixed_div(opentop - shootz, dist); - if (slope < aimslope) goto hitline; - } - else - { - if (li->frontsector->floorheight - != li->backsector->floorheight) - { - slope = fixed_div(openbottom - shootz, dist); - if (slope > aimslope) goto hitline; - } - - if (li->frontsector->ceilingheight - != li->backsector->ceilingheight) - { - slope = fixed_div(opentop - shootz, dist); - if (slope < aimslope) goto hitline; - } - } - - /* shot continues */ - - return true; - - /* hit line */ - - hitline: - - /* position a bit closer */ - - frac = in->frac - fixed_div(4 * FRACUNIT, attackrange); - x = trace.x + fixed_mul(trace.dx, frac); - y = trace.y + fixed_mul(trace.dy, frac); - z = shootz + fixed_mul(aimslope, fixed_mul(frac, attackrange)); - - if (li->frontsector->ceilingpic == skyflatnum) - { - /* don't shoot the sky! */ - - if (z > li->frontsector->ceilingheight) return false; - - /* it's a sky hack wall */ - - if (li->backsector && - li->backsector->ceilingpic == skyflatnum) - { - return false; - } - } - - /* Spawn bullet puffs. */ - - p_spawn_puff(x, y, z); - - /* don't go any farther */ - - return false; - } - - /* shoot a thing */ - - th = in->d.thing; - if (th == shootthing) return true; /* can't shoot self */ - - if (!(th->flags & MF_SHOOTABLE)) return true; /* corpse or something */ - - /* check angles to see if the thing can be aimed at */ - - dist = fixed_mul(attackrange, in->frac); - thingtopslope = fixed_div(th->z + th->height - shootz, dist); - - if (thingtopslope < aimslope) return true; /* shot over the thing */ - - thingbottomslope = fixed_div(th->z - shootz, dist); - - if (thingbottomslope > aimslope) return true; /* shot under the thing */ - - /* hit thing position a bit closer */ - - frac = in->frac - fixed_div(10 * FRACUNIT, attackrange); - - x = trace.x + fixed_mul(trace.dx, frac); - y = trace.y + fixed_mul(trace.dy, frac); - z = shootz + fixed_mul(aimslope, fixed_mul(frac, attackrange)); - - /* Spawn bullet puffs or blod spots, - * depending on target type. - */ - - if (in->d.thing->flags & MF_NOBLOOD) - p_spawn_puff(x, y, z); - else - p_spawn_blood(x, y, z, la_damage); - - if (la_damage) p_damage_mobj(th, shootthing, shootthing, la_damage); - - /* don't go any farther */ - - return false; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/* p_teleport_move */ - -boolean p_teleport_move(mobj_t *thing, fixed_t x, fixed_t y) -{ - int xl; - int xh; - int yl; - int yh; - int bx; - int by; - - subsector_t *newsubsec; - - /* kill anything occupying the position */ - - tmthing = thing; - tmflags = thing->flags; - - tmx = x; - tmy = y; - - tmbbox[BOXTOP] = y + tmthing->radius; - tmbbox[BOXBOTTOM] = y - tmthing->radius; - tmbbox[BOXRIGHT] = x + tmthing->radius; - tmbbox[BOXLEFT] = x - tmthing->radius; - - newsubsec = r_point_in_subsector(x, y); - ceilingline = NULL; - - /* The base floor/ceiling is from the subsector - * that contains the point. - * Any contacted lines the step closer together - * will adjust them. - */ - - tmfloorz = tmdropoffz = newsubsec->sector->floorheight; - tmceilingz = newsubsec->sector->ceilingheight; - - validcount++; - numspechit = 0; - - /* stomp on any things contacted */ - - xl = (tmbbox[BOXLEFT] - bmaporgx - MAXRADIUS) >> MAPBLOCKSHIFT; - xh = (tmbbox[BOXRIGHT] - bmaporgx + MAXRADIUS) >> MAPBLOCKSHIFT; - yl = (tmbbox[BOXBOTTOM] - bmaporgy - MAXRADIUS) >> MAPBLOCKSHIFT; - yh = (tmbbox[BOXTOP] - bmaporgy + MAXRADIUS) >> MAPBLOCKSHIFT; - - for (bx = xl; bx <= xh; bx++) - { - for (by = yl; by <= yh; by++) - { - if (!p_block_things_iterator(bx, by, pit_stomp_thing)) - { - return false; - } - } - } - - /* the move is ok, - * so link the thing into its new position - */ - - p_unset_thing_position(thing); - - thing->floorz = tmfloorz; - thing->ceilingz = tmceilingz; - thing->x = x; - thing->y = y; - - p_set_thing_position(thing); - - return true; -} - -boolean pit_check_thing(mobj_t *thing) -{ - fixed_t blockdist; - boolean solid; - int damage; - - if (!(thing->flags & (MF_SOLID | MF_SPECIAL | MF_SHOOTABLE))) return true; - - blockdist = thing->radius + tmthing->radius; - - if (abs(thing->x - tmx) >= blockdist || abs(thing->y - tmy) >= blockdist) - { - return true; /* didn't hit it */ - } - - /* don't clip against self */ - - if (thing == tmthing) return true; - - /* check for skulls slamming into things */ - - if (tmthing->flags & MF_SKULLFLY) - { - damage = ((p_random() % 8) + 1) * tmthing->info->damage; - - p_damage_mobj(thing, tmthing, tmthing, damage); - - tmthing->flags &= ~MF_SKULLFLY; - tmthing->momx = tmthing->momy = tmthing->momz = 0; - - p_set_mobj_state(tmthing, tmthing->info->spawnstate); - - return false; /* stop moving */ - } - - /* missiles can hit other things */ - - if (tmthing->flags & MF_MISSILE) - { - /* see if it went over / under */ - - if (tmthing->z > thing->z + thing->height) - { - return true; /* overhead */ - } - - if (tmthing->z + tmthing->height < thing->z) - { - return true; /* underneath */ - } - - if (tmthing->target && - (tmthing->target->type == thing->type || - (tmthing->target->type == MT_KNIGHT && - thing->type == MT_BRUISER) || - (tmthing->target->type == MT_BRUISER && - thing->type == MT_KNIGHT))) - { - /* Don't hit same species as originator. */ - - if (thing == tmthing->target) return true; - - /* sdh: Add deh_species_infighting here. We can override the - * "monsters of the same species can't hurt each other" behavior - * through dehacked patches - */ - - if (thing->type != MT_PLAYER && !deh_species_infighting) - { - /* Explode, but do no damage. - * Let players missile other players. - */ - - return false; - } - } - - if (!(thing->flags & MF_SHOOTABLE)) - { - /* didn't do any damage */ - - return !(thing->flags & MF_SOLID); - } - - /* damage / explode */ - - damage = ((p_random() % 8) + 1) * tmthing->info->damage; - p_damage_mobj(thing, tmthing, tmthing->target, damage); - - /* don't traverse any more */ - - return false; - } - - /* check for special pickup */ - - if (thing->flags & MF_SPECIAL) - { - solid = (thing->flags & MF_SOLID) != 0; - if (tmflags & MF_PICKUP) - { - /* can remove thing */ - - p_touch_special_thing(thing, tmthing); - } - - return !solid; - } - - return !(thing->flags & MF_SOLID); -} - -/* MOVEMENT CLIPPING */ - -/* p_check_position - * This is purely informative, nothing is modified - * (except things picked up). - * - * in: - * a mobj_t (can be valid or invalid) - * a position to be checked - * (doesn't need to be related to the mobj_t->x,y) - * - * during: - * special things are touched if MF_PICKUP - * early out on solid lines? - * - * out: - * newsubsec - * floorz - * ceilingz - * tmdropoffz - * the lowest point contacted - * (monsters won't move to a dropoff) - * speciallines[] - * numspeciallines - */ - -boolean p_check_position(mobj_t *thing, fixed_t x, fixed_t y) -{ - int xl; - int xh; - int yl; - int yh; - int bx; - int by; - subsector_t *newsubsec; - - tmthing = thing; - tmflags = thing->flags; - - tmx = x; - tmy = y; - - tmbbox[BOXTOP] = y + tmthing->radius; - tmbbox[BOXBOTTOM] = y - tmthing->radius; - tmbbox[BOXRIGHT] = x + tmthing->radius; - tmbbox[BOXLEFT] = x - tmthing->radius; - - newsubsec = r_point_in_subsector(x, y); - ceilingline = NULL; - - /* The base floor / ceiling is from the subsector - * that contains the point. - * Any contacted lines the step closer together - * will adjust them. - */ - - tmfloorz = tmdropoffz = newsubsec->sector->floorheight; - tmceilingz = newsubsec->sector->ceilingheight; - - validcount++; - numspechit = 0; - - if (tmflags & MF_NOCLIP) return true; - - /* Check things first, possibly picking things up. - * The bounding box is extended by MAXRADIUS - * because mobj_ts are grouped into mapblocks - * based on their origin point, and can overlap - * into adjacent blocks by up to MAXRADIUS units. - */ - - xl = (tmbbox[BOXLEFT] - bmaporgx - MAXRADIUS) >> MAPBLOCKSHIFT; - xh = (tmbbox[BOXRIGHT] - bmaporgx + MAXRADIUS) >> MAPBLOCKSHIFT; - yl = (tmbbox[BOXBOTTOM] - bmaporgy - MAXRADIUS) >> MAPBLOCKSHIFT; - yh = (tmbbox[BOXTOP] - bmaporgy + MAXRADIUS) >> MAPBLOCKSHIFT; - - for (bx = xl; bx <= xh; bx++) - { - for (by = yl; by <= yh; by++) - { - if (!p_block_things_iterator(bx, by, pit_check_thing)) - { - return false; - } - } - } - - /* check lines */ - - xl = (tmbbox[BOXLEFT] - bmaporgx) >> MAPBLOCKSHIFT; - xh = (tmbbox[BOXRIGHT] - bmaporgx) >> MAPBLOCKSHIFT; - yl = (tmbbox[BOXBOTTOM] - bmaporgy) >> MAPBLOCKSHIFT; - yh = (tmbbox[BOXTOP] - bmaporgy) >> MAPBLOCKSHIFT; - - for (bx = xl; bx <= xh; bx++) - { - for (by = yl; by <= yh; by++) - { - if (!p_block_lines_iterator(bx, by, pit_check_line)) - { - return false; - } - } - } - - return true; -} - -/* p_try_move - * Attempt to move to a new position, - * crossing special lines unless MF_TELEPORT is set. - */ - -boolean p_try_move(mobj_t *thing, fixed_t x, fixed_t y) -{ - fixed_t oldx; - fixed_t oldy; - int side; - int oldside; - line_t *ld; - - floatok = false; - if (!p_check_position(thing, x, y)) - { - return false; /* solid wall or thing */ - } - - if (!(thing->flags & MF_NOCLIP)) - { - if (tmceilingz - tmfloorz < thing->height) - { - return false; /* doesn't fit */ - } - - floatok = true; - - if (!(thing->flags & MF_TELEPORT) && - tmceilingz - thing->z < thing->height) - { - return false; /* mobj must lower itself to fit */ - } - - if (!(thing->flags & MF_TELEPORT) && - tmfloorz - thing->z > 24 * FRACUNIT) - { - return false; /* too big a step up */ - } - - if (!(thing->flags & (MF_DROPOFF | MF_FLOAT)) && - tmfloorz - tmdropoffz > 24 * FRACUNIT) - { - return false; /* don't stand over a dropoff */ - } - } - - /* the move is ok, - * so link the thing into its new position - */ - - p_unset_thing_position(thing); - - oldx = thing->x; - oldy = thing->y; - thing->floorz = tmfloorz; - thing->ceilingz = tmceilingz; - thing->x = x; - thing->y = y; - - p_set_thing_position(thing); - - /* if any special lines were hit, do the effect */ - - if (!(thing->flags & (MF_TELEPORT | MF_NOCLIP))) - { - while (numspechit--) - { - /* see if the line was crossed */ - - ld = spechit[numspechit]; - side = p_point_on_line_side(thing->x, thing->y, ld); - oldside = p_point_on_line_side(oldx, oldy, ld); - if (side != oldside) - { - if (ld->special) - { - p_cross_special_line(ld - lines, oldside, thing); - } - } - } - } - - return true; -} - -/* p_slide_move - * The momx / momy move is bad, so try to slide - * along a wall. - * Find the first line hit, move flush to it, - * and slide along it - * - * This is a kludgy mess. - */ - -void p_slide_move(mobj_t *mo) -{ - fixed_t leadx; - fixed_t leady; - fixed_t trailx; - fixed_t traily; - fixed_t newx; - fixed_t newy; - int hitcount; - - slidemo = mo; - hitcount = 0; - -retry: - if (++hitcount == 3) goto stairstep; /* don't loop forever */ - - /* trace along the three leading corners */ - - if (mo->momx > 0) - { - leadx = mo->x + mo->radius; - trailx = mo->x - mo->radius; - } - else - { - leadx = mo->x - mo->radius; - trailx = mo->x + mo->radius; - } - - if (mo->momy > 0) - { - leady = mo->y + mo->radius; - traily = mo->y - mo->radius; - } - else - { - leady = mo->y - mo->radius; - traily = mo->y + mo->radius; - } - - bestslidefrac = FRACUNIT + 1; - - p_path_traverse(leadx, leady, leadx + mo->momx, leady + mo->momy, - PT_ADDLINES, ptr_slide_traverse); - p_path_traverse(trailx, leady, trailx + mo->momx, leady + mo->momy, - PT_ADDLINES, ptr_slide_traverse); - p_path_traverse(leadx, traily, leadx + mo->momx, traily + mo->momy, - PT_ADDLINES, ptr_slide_traverse); - - /* move up to the wall */ - - if (bestslidefrac == FRACUNIT + 1) - { - /* the move most have hit the middle, so stairstep */ - - stairstep: - if (!p_try_move(mo, mo->x, mo->y + mo->momy)) - p_try_move(mo, mo->x + mo->momx, mo->y); - return; - } - - /* fudge a bit to make sure it doesn't hit */ - - bestslidefrac -= 0x800; - if (bestslidefrac > 0) - { - newx = fixed_mul(mo->momx, bestslidefrac); - newy = fixed_mul(mo->momy, bestslidefrac); - - if (!p_try_move(mo, mo->x + newx, mo->y + newy)) goto stairstep; - } - - /* Now continue along the wall. - * First calculate remainder. - */ - - bestslidefrac = FRACUNIT - (bestslidefrac + 0x800); - - if (bestslidefrac > FRACUNIT) bestslidefrac = FRACUNIT; - - if (bestslidefrac <= 0) return; - - tmxmove = fixed_mul(mo->momx, bestslidefrac); - tmymove = fixed_mul(mo->momy, bestslidefrac); - - p_hit_slide_line(bestslideline); /* clip the moves */ - - mo->momx = tmxmove; - mo->momy = tmymove; - - if (!p_try_move(mo, mo->x + tmxmove, mo->y + tmymove)) - { - goto retry; - } -} - -/* p_aim_line_attack */ - -fixed_t p_aim_line_attack(mobj_t *t1, angle_t angle, fixed_t distance) -{ - fixed_t x2; - fixed_t y2; - - t1 = p_subst_null_mobj(t1); - - angle >>= ANGLETOFINESHIFT; - shootthing = t1; - - x2 = t1->x + (distance >> FRACBITS) * finecosine[angle]; - y2 = t1->y + (distance >> FRACBITS) * finesine[angle]; - shootz = t1->z + (t1->height >> 1) + 8 * FRACUNIT; - - /* can't shoot outside view angles */ - - topslope = (SCREENHEIGHT / 2) * FRACUNIT / (SCREENWIDTH / 2); - bottomslope = -(SCREENHEIGHT / 2) * FRACUNIT / (SCREENWIDTH / 2); - - attackrange = distance; - linetarget = NULL; - - p_path_traverse(t1->x, t1->y, x2, y2, PT_ADDLINES | PT_ADDTHINGS, - ptr_aim_traverse); - - if (linetarget) return aimslope; - - return 0; -} - -/* p_line_attack - * - * If damage == 0, it is just a test trace that will leave linetarget set. - */ - -void p_line_attack(mobj_t *t1, angle_t angle, fixed_t distance, - fixed_t slope, int damage) -{ - fixed_t x2; - fixed_t y2; - - angle >>= ANGLETOFINESHIFT; - shootthing = t1; - la_damage = damage; - x2 = t1->x + (distance >> FRACBITS) * finecosine[angle]; - y2 = t1->y + (distance >> FRACBITS) * finesine[angle]; - shootz = t1->z + (t1->height >> 1) + 8 * FRACUNIT; - attackrange = distance; - aimslope = slope; - - p_path_traverse(t1->x, t1->y, x2, y2, PT_ADDLINES | PT_ADDTHINGS, - ptr_shoot_traverse); -} - -/* p_use_lines - * Looks for special lines in front of the player to activate. - */ - -void p_use_lines(player_t *player) -{ - int angle; - fixed_t x1; - fixed_t y1; - fixed_t x2; - fixed_t y2; - - usething = player->mo; - - angle = player->mo->angle >> ANGLETOFINESHIFT; - - x1 = player->mo->x; - y1 = player->mo->y; - x2 = x1 + (USERANGE >> FRACBITS) * finecosine[angle]; - y2 = y1 + (USERANGE >> FRACBITS) * finesine[angle]; - - p_path_traverse(x1, y1, x2, y2, PT_ADDLINES, ptr_use_traverse); -} - -/* p_radius_attack - * Source is the creature that caused the explosion at spot. - */ - -void p_radius_attack(mobj_t *spot, mobj_t *source, int damage) -{ - int x; - int y; - - int xl; - int xh; - int yl; - int yh; - - fixed_t dist; - - dist = (damage + MAXRADIUS) << FRACBITS; - yh = (spot->y + dist - bmaporgy) >> MAPBLOCKSHIFT; - yl = (spot->y - dist - bmaporgy) >> MAPBLOCKSHIFT; - xh = (spot->x + dist - bmaporgx) >> MAPBLOCKSHIFT; - xl = (spot->x - dist - bmaporgx) >> MAPBLOCKSHIFT; - bombspot = spot; - bombsource = source; - bombdamage = damage; - - for (y = yl; y <= yh; y++) - { - for (x = xl; x <= xh; x++) - { - p_block_things_iterator(x, y, pit_radius_attack); - } - } -} - -/* pit_change_sector */ - -static boolean pit_change_sector(mobj_t *thing) -{ - mobj_t *mo; - - if (p_things_height_clip(thing)) - { - return true; /* keep checking */ - } - - /* crunch bodies to giblets */ - - if (thing->health <= 0) - { - p_set_mobj_state(thing, S_GIBS); - - if (gameversion > exe_doom_1_2) thing->flags &= ~MF_SOLID; - thing->height = 0; - thing->radius = 0; - - /* keep checking */ - - return true; - } - - /* crunch dropped items */ - - if (thing->flags & MF_DROPPED) - { - p_remove_mobj(thing); - - return true; /* keep checking */ - } - - if (!(thing->flags & MF_SHOOTABLE)) - { - return true; /* assume it is bloody gibs or something */ - } - - nofit = true; - - if (crushchange && !(leveltime & 3)) - { - p_damage_mobj(thing, NULL, NULL, 10); - - /* spray blood in a random direction */ - - mo = p_spawn_mobj(thing->x, thing->y, thing->z + thing->height / 2, - MT_BLOOD); - - mo->momx = p_sub_random() << 12; - mo->momy = p_sub_random() << 12; - } - - /* keep checking (crush other things) */ - - return true; -} - -/* p_change_sector */ - -boolean p_change_sector(sector_t *sector, boolean crunch) -{ - int x; - int y; - - nofit = false; - crushchange = crunch; - - /* re-check heights for all things near the moving sector */ - - for (x = sector->blockbox[BOXLEFT]; x <= sector->blockbox[BOXRIGHT]; x++) - { - for (y = sector->blockbox[BOXBOTTOM]; y <= sector->blockbox[BOXTOP]; - y++) - { - p_block_things_iterator(x, y, pit_change_sector); - } - } - - return nofit; -} diff --git a/games/NXDoom/src/doom/p_maputl.c b/games/NXDoom/src/doom/p_maputl.c deleted file mode 100644 index f5c193274..000000000 --- a/games/NXDoom/src/doom/p_maputl.c +++ /dev/null @@ -1,939 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/p_maputl.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * Copyright(C) 2005, 2006 Andrey Budko - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Movement/collision utility functions, - * as used by function in p_map.c. - * BLOCKMAP Iterator functions, - * and some PIT_* functions to use for iteration. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include "m_bbox.h" -#include "m_misc.h" - -#include "doomdef.h" -#include "doomstat.h" -#include "p_local.h" - -/* State. */ - -#include "r_state.h" - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/* Intercepts Overrun emulation, from PrBoom-plus. - * Thanks to Andrey Budko (entryway) for researching this and his - * implementation of Intercepts Overrun emulation in PrBoom-plus - * which this is based on. - */ - -typedef struct -{ - int len; - void *addr; - boolean int16_array; -} intercepts_overrun_t; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -fixed_t p_intercept_vector(divline_t *v2, divline_t *v1); - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/* Intercepts memory table. This is where various variables are located - * in memory in Vanilla Doom. When the intercepts table overflows, we - * need to write to them. - * - * Almost all of the values to overwrite are 32-bit integers, except for - * playerstarts, which is effectively an array of 16-bit integers and - * must be treated differently. - */ - -static intercepts_overrun_t g_intercepts_overrun[] = -{ - {4, NULL, false}, - {4, NULL, /* &earlyout, */ false}, - {4, NULL, /* &intercept_p, */ false}, - {4, &lowfloor, false}, - {4, &openbottom, false}, - {4, &opentop, false}, - {4, &openrange, false}, - {4, NULL, false}, - {120, NULL, /* &activeplats, */ false}, - {8, NULL, false}, - {4, &bulletslope, false}, - {4, NULL, /* &swingx, */ false}, - {4, NULL, /* &swingy, */ false}, - {4, NULL, false}, - {40, &playerstarts, true}, - {4, NULL, /* &blocklinks, */ false}, - {4, &bmapwidth, false}, - {4, NULL, /* &blockmap, */ false}, - {4, &bmaporgx, false}, - {4, &bmaporgy, false}, - {4, NULL, /* &blockmaplump, */ false}, - {4, &bmapheight, false}, - {0, NULL, false}, -}; - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -fixed_t opentop; -fixed_t openbottom; -fixed_t openrange; -fixed_t lowfloor; - -/* INTERCEPT ROUTINES */ - -intercept_t intercepts[MAXINTERCEPTS]; -intercept_t *intercept_p; - -divline_t trace; -boolean earlyout; -int ptflags; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static void p_make_divline(line_t *li, divline_t *dl) -{ - dl->x = li->v1->x; - dl->y = li->v1->y; - dl->dx = li->dx; - dl->dy = li->dy; -} - -/* Overwrite a specific memory location with a value. */ - -static void intercepts_mem_overrun(int location, int value) -{ - int i; - int offset; - int index; - void *addr; - - i = 0; - offset = 0; - - /* Search down the array until we find the right entry */ - - while (g_intercepts_overrun[i].len != 0) - { - if (offset + g_intercepts_overrun[i].len > location) - { - addr = g_intercepts_overrun[i].addr; - - /* Write the value to the memory location. - * 16-bit and 32-bit values are written differently. - */ - - if (addr != NULL) - { - if (g_intercepts_overrun[i].int16_array) - { - index = (location - offset) / 2; - ((short *)addr)[index] = value & 0xffff; - ((short *)addr)[index + 1] = (value >> 16) & 0xffff; - } - else - { - index = (location - offset) / 4; - ((int *)addr)[index] = value; - } - } - - break; - } - - offset += g_intercepts_overrun[i].len; - ++i; - } -} - -/* Emulate overruns of the intercepts[] array. */ - -static void intercepts_overrun(int num_intercepts, intercept_t *intercept) -{ - int location; - - if (num_intercepts <= MAXINTERCEPTS_ORIGINAL) - { - return; /* No overrun */ - } - - location = (num_intercepts - MAXINTERCEPTS_ORIGINAL - 1) * 12; - - /* Overwrite memory that is overwritten in Vanilla Doom, using - * the values from the intercept structure. - * - * Note: the ->d.{thing,line} member should really have its - * address translated into the correct address value for - * Vanilla Doom. - */ - - intercepts_mem_overrun(location, intercept->frac); - intercepts_mem_overrun(location + 4, intercept->isaline); - intercepts_mem_overrun(location + 8, (intptr_t)intercept->d.thing); -} - -/* pit_add_line_intercepts. - * Looks for lines in the given block - * that intercept the given trace - * to add to the intercepts list. - * - * A line is crossed if its endpoints - * are on opposite sides of the trace. - * Returns true if earlyout and a solid line hit. - */ - -static boolean pit_add_line_intercepts(line_t *ld) -{ - int s1; - int s2; - fixed_t frac; - divline_t dl; - - /* avoid precision problems with two routines */ - - if (trace.dx > FRACUNIT * 16 || trace.dy > FRACUNIT * 16 || - trace.dx < -FRACUNIT * 16 || trace.dy < -FRACUNIT * 16) - { - s1 = p_point_on_divline_side(ld->v1->x, ld->v1->y, &trace); - s2 = p_point_on_divline_side(ld->v2->x, ld->v2->y, &trace); - } - else - { - s1 = p_point_on_line_side(trace.x, trace.y, ld); - s2 = p_point_on_line_side(trace.x + trace.dx, trace.y + trace.dy, ld); - } - - if (s1 == s2) return true; /* line isn't crossed */ - - /* hit the line */ - - p_make_divline(ld, &dl); - frac = p_intercept_vector(&trace, &dl); - - if (frac < 0) return true; /* behind source */ - - /* try to early out the check */ - - if (earlyout && frac < FRACUNIT && !ld->backsector) - { - return false; /* stop checking */ - } - - intercept_p->frac = frac; - intercept_p->isaline = true; - intercept_p->d.line = ld; - intercepts_overrun(intercept_p - intercepts, intercept_p); - intercept_p++; - - return true; /* continue */ -} - -static boolean pit_add_thing_intercepts(mobj_t *thing) -{ - fixed_t x1; - fixed_t y1; - fixed_t x2; - fixed_t y2; - - int s1; - int s2; - - boolean tracepositive; - - divline_t dl; - - fixed_t frac; - - tracepositive = (trace.dx ^ trace.dy) > 0; - - /* check a corner to corner cross-section for hit */ - - if (tracepositive) - { - x1 = thing->x - thing->radius; - y1 = thing->y + thing->radius; - - x2 = thing->x + thing->radius; - y2 = thing->y - thing->radius; - } - else - { - x1 = thing->x - thing->radius; - y1 = thing->y - thing->radius; - - x2 = thing->x + thing->radius; - y2 = thing->y + thing->radius; - } - - s1 = p_point_on_divline_side(x1, y1, &trace); - s2 = p_point_on_divline_side(x2, y2, &trace); - - if (s1 == s2) return true; /* line isn't crossed */ - - dl.x = x1; - dl.y = y1; - dl.dx = x2 - x1; - dl.dy = y2 - y1; - - frac = p_intercept_vector(&trace, &dl); - - if (frac < 0) return true; /* behind source */ - - intercept_p->frac = frac; - intercept_p->isaline = false; - intercept_p->d.thing = thing; - intercepts_overrun(intercept_p - intercepts, intercept_p); - intercept_p++; - - return true; /* keep going */ -} - -/* p_traverse_intercepts - * Returns true if the traverser function returns true for all lines. - */ - -static boolean p_traverse_intercepts(traverser_t func, fixed_t maxfrac) -{ - int count; - fixed_t dist; - intercept_t *scan; - intercept_t *in; - - count = intercept_p - intercepts; - - in = 0; /* shut up compiler warning */ - - while (count--) - { - dist = INT_MAX; - for (scan = intercepts; scan < intercept_p; scan++) - { - if (scan->frac < dist) - { - dist = scan->frac; - in = scan; - } - } - - if (dist > maxfrac) return true; /* checked everything in range */ - -#if 0 /* UNUSED */ - - /* don't check these yet, there may be others inserted */ - - in = scan = intercepts; - for (scan = intercepts; scan < intercept_p; scan++) - { - if (scan->frac > maxfrac) *in++ = *scan; - } - - intercept_p = in; - return false; -#endif - - if (!func(in)) return false; /* don't bother going farther */ - - in->frac = INT_MAX; - } - - return true; /* everything was traversed */ -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/* p_approx_distance - * Gives an estimation of distance (not exact) - */ - -fixed_t p_approx_distance(fixed_t dx, fixed_t dy) -{ - dx = abs(dx); - dy = abs(dy); - if (dx < dy) return dx + dy - (dx >> 1); - return dx + dy - (dy >> 1); -} - -/* p_point_on_line_side - * Returns 0 or 1 - */ - -int p_point_on_line_side(fixed_t x, fixed_t y, line_t *line) -{ - fixed_t dx; - fixed_t dy; - fixed_t left; - fixed_t right; - - if (!line->dx) - { - if (x <= line->v1->x) return line->dy > 0; - - return line->dy < 0; - } - - if (!line->dy) - { - if (y <= line->v1->y) return line->dx < 0; - - return line->dx > 0; - } - - dx = (x - line->v1->x); - dy = (y - line->v1->y); - - left = fixed_mul(line->dy >> FRACBITS, dx); - right = fixed_mul(dy, line->dx >> FRACBITS); - - if (right < left) return 0; /* front side */ - - return 1; /* back side */ -} - -/* p_box_on_line_side - * Considers the line to be infinite - * Returns side 0 or 1, -1 if box crosses the line. - */ - -int p_box_on_line_side(fixed_t *tmbox, line_t *ld) -{ - int p1 = 0; - int p2 = 0; - - switch (ld->slopetype) - { - case ST_HORIZONTAL: - p1 = tmbox[BOXTOP] > ld->v1->y; - p2 = tmbox[BOXBOTTOM] > ld->v1->y; - if (ld->dx < 0) - { - p1 ^= 1; - p2 ^= 1; - } - break; - - case ST_VERTICAL: - p1 = tmbox[BOXRIGHT] < ld->v1->x; - p2 = tmbox[BOXLEFT] < ld->v1->x; - if (ld->dy < 0) - { - p1 ^= 1; - p2 ^= 1; - } - break; - - case ST_POSITIVE: - p1 = p_point_on_line_side(tmbox[BOXLEFT], tmbox[BOXTOP], ld); - p2 = p_point_on_line_side(tmbox[BOXRIGHT], tmbox[BOXBOTTOM], ld); - break; - - case ST_NEGATIVE: - p1 = p_point_on_line_side(tmbox[BOXRIGHT], tmbox[BOXTOP], ld); - p2 = p_point_on_line_side(tmbox[BOXLEFT], tmbox[BOXBOTTOM], ld); - break; - } - - if (p1 == p2) return p1; - return -1; -} - -/* p_point_on_divline_side - * Returns 0 or 1. - */ - -int p_point_on_divline_side(fixed_t x, fixed_t y, divline_t *line) -{ - fixed_t dx; - fixed_t dy; - fixed_t left; - fixed_t right; - - if (!line->dx) - { - if (x <= line->x) return line->dy > 0; - - return line->dy < 0; - } - - if (!line->dy) - { - if (y <= line->y) return line->dx < 0; - - return line->dx > 0; - } - - dx = (x - line->x); - dy = (y - line->y); - - /* try to quickly decide by looking at sign bits */ - - if ((line->dy ^ line->dx ^ dx ^ dy) & 0x80000000) - { - if ((line->dy ^ dx) & 0x80000000) return 1; /* (left is negative) */ - return 0; - } - - left = fixed_mul(line->dy >> 8, dx >> 8); - right = fixed_mul(dy >> 8, line->dx >> 8); - - if (right < left) return 0; /* front side */ - - return 1; /* back side */ -} - -/* p_intercept_vector - * - * Returns the fractional intercept point along the first divline. - * This is only called by the addthings and addlines traversers. - */ - -fixed_t p_intercept_vector(divline_t *v2, divline_t *v1) -{ -#if 1 - fixed_t frac; - fixed_t num; - fixed_t den; - - den = fixed_mul(v1->dy >> 8, v2->dx) - fixed_mul(v1->dx >> 8, v2->dy); - - if (den == 0) return 0; - - num = fixed_mul((v1->x - v2->x) >> 8, v1->dy) + - fixed_mul((v2->y - v1->y) >> 8, v1->dx); - - frac = fixed_div(num, den); - - return frac; -#else /* UNUSED, float debug. */ - float frac; - float num; - float den; - float v1x; - float v1y; - float v1dx; - float v1dy; - float v2x; - float v2y; - float v2dx; - float v2dy; - - v1x = (float)v1->x / FRACUNIT; - v1y = (float)v1->y / FRACUNIT; - v1dx = (float)v1->dx / FRACUNIT; - v1dy = (float)v1->dy / FRACUNIT; - v2x = (float)v2->x / FRACUNIT; - v2y = (float)v2->y / FRACUNIT; - v2dx = (float)v2->dx / FRACUNIT; - v2dy = (float)v2->dy / FRACUNIT; - - den = v1dy * v2dx - v1dx * v2dy; - - if (den == 0) return 0; /* parallel */ - - num = (v1x - v2x) * v1dy + (v2y - v1y) * v1dx; - frac = num / den; - - return frac * FRACUNIT; -#endif -} - -/* p_line_opening - * Sets opentop and openbottom to the window through a two sided line. - * OPTIMIZE: keep this precalculated - */ - -void p_line_opening(line_t *p_linedef) -{ - sector_t *front; - sector_t *back; - - if (p_linedef->sidenum[1] == -1) - { - /* single sided line */ - - openrange = 0; - return; - } - - front = p_linedef->frontsector; - back = p_linedef->backsector; - - if (front->ceilingheight < back->ceilingheight) - opentop = front->ceilingheight; - else - opentop = back->ceilingheight; - - if (front->floorheight > back->floorheight) - { - openbottom = front->floorheight; - lowfloor = back->floorheight; - } - else - { - openbottom = back->floorheight; - lowfloor = front->floorheight; - } - - openrange = opentop - openbottom; -} - -/* THING POSITION SETTING */ - -/* p_unset_thing_position - * - * Unlinks a thing from block map and sectors. - * - * On each position change, BLOCKMAP and other lookups maintaining lists to - * things inside these structures need to be updated. - */ - -void p_unset_thing_position(mobj_t *thing) -{ - int blockx; - int blocky; - - if (!(thing->flags & MF_NOSECTOR)) - { - /* inert things don't need to be in blockmap? unlink from subsector */ - - if (thing->snext) thing->snext->sprev = thing->sprev; - - if (thing->sprev) - thing->sprev->snext = thing->snext; - else - thing->subsector->sector->thinglist = thing->snext; - } - - if (!(thing->flags & MF_NOBLOCKMAP)) - { - /* inert things don't need to be in blockmap unlink from block map */ - - if (thing->bnext) thing->bnext->bprev = thing->bprev; - - if (thing->bprev) - thing->bprev->bnext = thing->bnext; - else - { - blockx = (thing->x - bmaporgx) >> MAPBLOCKSHIFT; - blocky = (thing->y - bmaporgy) >> MAPBLOCKSHIFT; - - if (blockx >= 0 && blockx < bmapwidth && blocky >= 0 && - blocky < bmapheight) - { - blocklinks[blocky * bmapwidth + blockx] = thing->bnext; - } - } - } -} - -/* p_set_thing_position - * Links a thing into both a block and a subsector based on it's x y. - * Sets thing->subsector properly - */ - -void p_set_thing_position(mobj_t *thing) -{ - subsector_t *ss; - sector_t *sec; - int blockx; - int blocky; - mobj_t **link; - - /* link into subsector */ - - ss = r_point_in_subsector(thing->x, thing->y); - thing->subsector = ss; - - if (!(thing->flags & MF_NOSECTOR)) - { - /* invisible things don't go into the sector links */ - - sec = ss->sector; - - thing->sprev = NULL; - thing->snext = sec->thinglist; - - if (sec->thinglist) sec->thinglist->sprev = thing; - - sec->thinglist = thing; - } - - /* link into blockmap */ - - if (!(thing->flags & MF_NOBLOCKMAP)) - { - /* inert things don't need to be in blockmap */ - - blockx = (thing->x - bmaporgx) >> MAPBLOCKSHIFT; - blocky = (thing->y - bmaporgy) >> MAPBLOCKSHIFT; - - if (blockx >= 0 && blockx < bmapwidth && blocky >= 0 && - blocky < bmapheight) - { - link = &blocklinks[blocky * bmapwidth + blockx]; - thing->bprev = NULL; - thing->bnext = *link; - if (*link) (*link)->bprev = thing; - - *link = thing; - } - else - { - /* thing is off the map */ - - thing->bnext = thing->bprev = NULL; - } - } -} - -/* BLOCK MAP ITERATORS - * For each line/thing in the given mapblock, - * call the passed PIT_* function. - * If the function returns false, - * exit with false without checking anything else. - */ - -/* p_block_lines_iterator - * The validcount flags are used to avoid checking lines - * that are marked in multiple mapblocks, - * so increment validcount before the first call - * to p_block_lines_iterator, then make one or more calls - * to it. - */ - -boolean p_block_lines_iterator(int x, int y, boolean (*func)(line_t *)) -{ - int offset; - short *list; - line_t *ld; - - if (x < 0 || y < 0 || x >= bmapwidth || y >= bmapheight) - { - return true; - } - - offset = y * bmapwidth + x; - - offset = *(blockmap + offset); - - for (list = blockmaplump + offset; *list != -1; list++) - { - ld = &lines[*list]; - - if (ld->validcount == validcount) - continue; /* line has already been checked */ - - ld->validcount = validcount; - - if (!func(ld)) return false; - } - - return true; /* everything was checked */ -} - -boolean p_block_things_iterator(int x, int y, boolean (*func)(mobj_t *)) -{ - mobj_t *mobj; - - if (x < 0 || y < 0 || x >= bmapwidth || y >= bmapheight) - { - return true; - } - - LINKED_LIST_CHECK_NO_CYCLE(mobj_t, blocklinks[y * bmapwidth + x], bnext); - - for (mobj = blocklinks[y * bmapwidth + x]; mobj; mobj = mobj->bnext) - { - if (!func(mobj)) return false; - } - - return true; -} - -/* p_path_traverse - * - * Traces a line from x1,y1 to x2,y2, calling the traverser function for - * each. - * Returns true if the traverser function returns true for all lines. - */ - -boolean p_path_traverse(fixed_t x1, fixed_t y1, fixed_t x2, fixed_t y2, - int flags, boolean (*trav)(intercept_t *)) -{ - fixed_t xt1; - fixed_t yt1; - fixed_t xt2; - fixed_t yt2; - - fixed_t xstep; - fixed_t ystep; - - fixed_t partial; - - fixed_t xintercept; - fixed_t yintercept; - - int mapx; - int mapy; - - int mapxstep; - int mapystep; - - int count; - - earlyout = (flags & PT_EARLYOUT) != 0; - - validcount++; - intercept_p = intercepts; - - if (((x1 - bmaporgx) & (MAPBLOCKSIZE - 1)) == 0) - { - x1 += FRACUNIT; /* don't side exactly on a line */ - } - - if (((y1 - bmaporgy) & (MAPBLOCKSIZE - 1)) == 0) - { - y1 += FRACUNIT; /* don't side exactly on a line */ - } - - trace.x = x1; - trace.y = y1; - trace.dx = x2 - x1; - trace.dy = y2 - y1; - - x1 -= bmaporgx; - y1 -= bmaporgy; - xt1 = x1 >> MAPBLOCKSHIFT; - yt1 = y1 >> MAPBLOCKSHIFT; - - x2 -= bmaporgx; - y2 -= bmaporgy; - xt2 = x2 >> MAPBLOCKSHIFT; - yt2 = y2 >> MAPBLOCKSHIFT; - - if (xt2 > xt1) - { - mapxstep = 1; - partial = FRACUNIT - ((x1 >> MAPBTOFRAC) & (FRACUNIT - 1)); - ystep = fixed_div(y2 - y1, abs(x2 - x1)); - } - else if (xt2 < xt1) - { - mapxstep = -1; - partial = (x1 >> MAPBTOFRAC) & (FRACUNIT - 1); - ystep = fixed_div(y2 - y1, abs(x2 - x1)); - } - else - { - mapxstep = 0; - partial = FRACUNIT; - ystep = 256 * FRACUNIT; - } - - yintercept = (y1 >> MAPBTOFRAC) + fixed_mul(partial, ystep); - - if (yt2 > yt1) - { - mapystep = 1; - partial = FRACUNIT - ((y1 >> MAPBTOFRAC) & (FRACUNIT - 1)); - xstep = fixed_div(x2 - x1, abs(y2 - y1)); - } - else if (yt2 < yt1) - { - mapystep = -1; - partial = (y1 >> MAPBTOFRAC) & (FRACUNIT - 1); - xstep = fixed_div(x2 - x1, abs(y2 - y1)); - } - else - { - mapystep = 0; - partial = FRACUNIT; - xstep = 256 * FRACUNIT; - } - - xintercept = (x1 >> MAPBTOFRAC) + fixed_mul(partial, xstep); - - /* Step through map blocks. - * Count is present to prevent a round off error - * from skipping the break. - */ - - mapx = xt1; - mapy = yt1; - - for (count = 0; count < 64; count++) - { - if (flags & PT_ADDLINES) - { - if (!p_block_lines_iterator(mapx, mapy, pit_add_line_intercepts)) - { - return false; /* early out */ - } - } - - if (flags & PT_ADDTHINGS) - { - if (!p_block_things_iterator(mapx, mapy, pit_add_thing_intercepts)) - { - return false; /* early out */ - } - } - - if (mapx == xt2 && mapy == yt2) - { - break; - } - - if ((yintercept >> FRACBITS) == mapy) - { - yintercept += ystep; - mapx += mapxstep; - } - else if ((xintercept >> FRACBITS) == mapx) - { - xintercept += xstep; - mapy += mapystep; - } - } - - /* go through the sorted list */ - - return p_traverse_intercepts(trav, FRACUNIT); -} diff --git a/games/NXDoom/src/doom/p_mobj.c b/games/NXDoom/src/doom/p_mobj.c deleted file mode 100644 index 4b81fa45a..000000000 --- a/games/NXDoom/src/doom/p_mobj.c +++ /dev/null @@ -1,1126 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/p_mobj.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Moving object handling. Spawn functions. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include "i_system.h" -#include "m_random.h" -#include "z_zone.h" - -#include "doomdef.h" -#include "p_local.h" - -#include "hu_stuff.h" -#include "st_stuff.h" - -#ifdef CONFIG_GAMES_NXDOOM_SOUND -#include "s_sound.h" -#include "sounds.h" -#endif - -#include "doomstat.h" - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -/* Use a heuristic approach to detect infinite state cycles: Count the number - * of times the loop in p_set_mobj_state() executes and exit with an error - * once an arbitrary very large limit is reached. - */ - -#define MOBJ_CYCLE_LIMIT 1000000 - -#define STOPSPEED 0x1000 -#define FRICTION 0xe800 - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -int test; - -mapthing_t itemrespawnque[ITEMQUESIZE]; -int itemrespawntime[ITEMQUESIZE]; -int iquehead; -int iquetail; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -void g_player_reborn(int player); -void p_spawn_map_thing(mapthing_t *mthing); - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: p_explode_missile - ****************************************************************************/ - -static void p_explode_missile(mobj_t *mo) -{ - mo->momx = mo->momy = mo->momz = 0; - - p_set_mobj_state(mo, mobjinfo[mo->type].deathstate); - - mo->tics -= p_random() & 3; - - if (mo->tics < 1) mo->tics = 1; - - mo->flags &= ~MF_MISSILE; - -#ifdef CONFIG_GAMES_NXDOOM_SOUND - if (mo->info->deathsound) s_start_sound(mo, mo->info->deathsound); -#endif -} - -/**************************************************************************** - * Name: p_xy_movement - ****************************************************************************/ - -static void p_xy_movement(mobj_t *mo) -{ - fixed_t ptryx; - fixed_t ptryy; - player_t *player; - fixed_t xmove; - fixed_t ymove; - - if (!mo->momx && !mo->momy) - { - if (mo->flags & MF_SKULLFLY) - { - /* the skull slammed into something */ - - mo->flags &= ~MF_SKULLFLY; - mo->momx = mo->momy = mo->momz = 0; - - p_set_mobj_state(mo, mo->info->spawnstate); - } - - return; - } - - player = mo->player; - - if (mo->momx > MAXMOVE) - mo->momx = MAXMOVE; - else if (mo->momx < -MAXMOVE) - mo->momx = -MAXMOVE; - - if (mo->momy > MAXMOVE) - mo->momy = MAXMOVE; - else if (mo->momy < -MAXMOVE) - mo->momy = -MAXMOVE; - - xmove = mo->momx; - ymove = mo->momy; - - do - { - if (xmove > MAXMOVE / 2 || ymove > MAXMOVE / 2) - { - ptryx = mo->x + xmove / 2; - ptryy = mo->y + ymove / 2; - xmove >>= 1; - ymove >>= 1; - } - else - { - ptryx = mo->x + xmove; - ptryy = mo->y + ymove; - xmove = ymove = 0; - } - - if (!p_try_move(mo, ptryx, ptryy)) - { - /* blocked move */ - - if (mo->player) - { - /* try to slide along it */ - - p_slide_move(mo); - } - else if (mo->flags & MF_MISSILE) - { - /* explode a missile */ - - if (ceilingline && ceilingline->backsector && - ceilingline->backsector->ceilingpic == skyflatnum) - { - /* Hack to prevent missiles exploding - * against the sky. - * Does not handle sky floors. - */ - - p_remove_mobj(mo); - return; - } - - p_explode_missile(mo); - } - else - mo->momx = mo->momy = 0; - } - } - while (xmove || ymove); - - /* slow down */ - - if (player && player->cheats & CF_NOMOMENTUM) - { - /* debug option for no sliding at all */ - - mo->momx = mo->momy = 0; - return; - } - - if (mo->flags & (MF_MISSILE | MF_SKULLFLY)) - return; /* no friction for missiles ever */ - - if (mo->z > mo->floorz) return; /* no friction when airborne */ - - if (mo->flags & MF_CORPSE) - { - /* do not stop sliding - * if halfway off a step with some momentum - */ - - if (mo->momx > FRACUNIT / 4 || mo->momx < -FRACUNIT / 4 || - mo->momy > FRACUNIT / 4 || mo->momy < -FRACUNIT / 4) - { - if (mo->floorz != mo->subsector->sector->floorheight) return; - } - } - - if (mo->momx > -STOPSPEED && mo->momx < STOPSPEED && - mo->momy > -STOPSPEED && mo->momy < STOPSPEED && - (!player || - (player->cmd.forwardmove == 0 && player->cmd.sidemove == 0))) - { - /* if in a walking frame, stop moving */ - - if (player && - (unsigned)((player->mo->state - states) - S_PLAY_RUN1) < 4) - p_set_mobj_state(player->mo, S_PLAY); - - mo->momx = 0; - mo->momy = 0; - } - else - { - mo->momx = fixed_mul(mo->momx, FRICTION); - mo->momy = fixed_mul(mo->momy, FRICTION); - } -} - -/**************************************************************************** - * Name: p_z_movement - ****************************************************************************/ - -static void p_z_movement(mobj_t *mo) -{ - fixed_t dist; - fixed_t delta; - - /* check for smooth step up */ - - if (mo->player && mo->z < mo->floorz) - { - mo->player->viewheight -= mo->floorz - mo->z; - - mo->player->deltaviewheight = - (VIEWHEIGHT - mo->player->viewheight) >> 3; - } - - mo->z += mo->momz; /* adjust height */ - - if (mo->flags & MF_FLOAT && mo->target) - { - /* float down towards target if too close */ - - if (!(mo->flags & MF_SKULLFLY) && !(mo->flags & MF_INFLOAT)) - { - dist = p_approx_distance(mo->x - mo->target->x, - mo->y - mo->target->y); - - delta = (mo->target->z + (mo->height >> 1)) - mo->z; - - if (delta < 0 && dist < -(delta * 3)) - mo->z -= FLOATSPEED; - else if (delta > 0 && dist < (delta * 3)) - mo->z += FLOATSPEED; - } - } - - /* clip movement */ - - if (mo->z <= mo->floorz) - { - /* hit the floor */ - - /* Note (id): - * somebody left this after the setting momz to 0, - * kinda useless there. - * - * cph - This was the a bug in the linuxdoom-1.10 source which - * caused it not to sync Doom 2 v1.9 demos. Someone - * added the above comment and moved up the following code. So - * demos would desync in close lost soul fights. - * Note that this only applies to original Doom 1 or Doom2 demos - not - * Final Doom and Ultimate Doom. So we test demo_compatibility *and* - * gamemission. (Note we assume that Doom1 is always Ult Doom, which - * seems to hold for most published demos.) - * - * fraggle - cph got the logic here slightly wrong. There are three - * versions of Doom 1.9: - * - * * The version used in registered doom 1.9 + doom2 - no bounce - * * The version used in ultimate doom - has bounce - * * The version used in final doom - has bounce - * - * So we need to check that this is either retail or commercial - * (but not doom2) - */ - - int correct_lost_soul_bounce = gameversion >= exe_ultimate; - - if (correct_lost_soul_bounce && mo->flags & MF_SKULLFLY) - { - /* the skull slammed into something */ - - mo->momz = -mo->momz; - } - - if (mo->momz < 0) - { - if (mo->player && mo->momz < -GRAVITY * 8) - { - /* Squat down. - * Decrease viewheight for a moment after hitting the ground - * (hard), and utter appropriate sound. - */ - - mo->player->deltaviewheight = mo->momz >> 3; -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(mo, SFX_OOF); -#endif - } - - mo->momz = 0; - } - - mo->z = mo->floorz; - - /* cph 2001/05/26 - - * See lost soul bouncing comment above. We need this here for bug - * compatibility with original Doom2 v1.9 - if a soul is charging and - * hit by a raising floor this incorrectly reverses its Y momentum. - */ - - if (!correct_lost_soul_bounce && mo->flags & MF_SKULLFLY) - mo->momz = -mo->momz; - - if ((mo->flags & MF_MISSILE) && !(mo->flags & MF_NOCLIP)) - { - p_explode_missile(mo); - return; - } - } - else if (!(mo->flags & MF_NOGRAVITY)) - { - if (mo->momz == 0) - mo->momz = -GRAVITY * 2; - else - mo->momz -= GRAVITY; - } - - if (mo->z + mo->height > mo->ceilingz) - { - /* hit the ceiling */ - - if (mo->momz > 0) - { - mo->momz = 0; - } - - mo->z = mo->ceilingz - mo->height; - - if (mo->flags & MF_SKULLFLY) - { - /* the skull slammed into something */ - - mo->momz = -mo->momz; - } - - if ((mo->flags & MF_MISSILE) && !(mo->flags & MF_NOCLIP)) - { - p_explode_missile(mo); - return; - } - } -} - -/**************************************************************************** - * Name: p_nightmare_respawn - ****************************************************************************/ - -static void p_nightmare_respawn(mobj_t *mobj) -{ - fixed_t x; - fixed_t y; - fixed_t z; - subsector_t *ss; - mobj_t *mo; - mapthing_t *mthing; - - x = mobj->spawnpoint.x << FRACBITS; - y = mobj->spawnpoint.y << FRACBITS; - - /* something is occupying it's position? */ - - if (!p_check_position(mobj, x, y)) return; /* no respawn */ - - /* spawn a teleport fog at old spot because of removal of the body? */ - - mo = p_spawn_mobj(mobj->x, mobj->y, mobj->subsector->sector->floorheight, - MT_TFOG); - -#ifdef CONFIG_GAMES_NXDOOM_SOUND - /* initiate teleport sound */ - - s_start_sound(mo, SFX_TELEPT); -#endif - - /* spawn a teleport fog at the new spot */ - - ss = r_point_in_subsector(x, y); - - mo = p_spawn_mobj(x, y, ss->sector->floorheight, MT_TFOG); - -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(mo, SFX_TELEPT); -#endif - - mthing = &mobj->spawnpoint; /* spawn the new monster */ - - /* spawn it */ - - if (mobj->info->flags & MF_SPAWNCEILING) - z = ONCEILINGZ; - else - z = ONFLOORZ; - - /* inherit attributes from deceased one */ - - mo = p_spawn_mobj(x, y, z, mobj->type); - mo->spawnpoint = mobj->spawnpoint; - mo->angle = ANG45 * (mthing->angle / 45); - - if (mthing->options & MTF_AMBUSH) mo->flags |= MF_AMBUSH; - - mo->reactiontime = 18; - - /* remove the old monster, */ - - p_remove_mobj(mobj); -} - -/**************************************************************************** - * Name: p_check_missile_spawn - * - * Description: - * Moves the missile forward a bit and possibly explodes it right there. - * - ****************************************************************************/ - -static void p_check_missile_spawn(mobj_t *th) -{ - th->tics -= p_random() & 3; - if (th->tics < 1) th->tics = 1; - - /* move a little forward so an angle can be computed if it immediately - * explodes - */ - - th->x += (th->momx >> 1); - th->y += (th->momy >> 1); - th->z += (th->momz >> 1); - - if (!p_try_move(th, th->x, th->y)) p_explode_missile(th); -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: p_set_mobj_state - * - * Description: - * Returns true if the mobj is still present. - * - ****************************************************************************/ - -boolean p_set_mobj_state(mobj_t *mobj, statenum_t state) -{ - state_t *st; - int cycle_counter = 0; - - do - { - if (state == S_NULL) - { - mobj->state = (state_t *)S_NULL; - p_remove_mobj(mobj); - return false; - } - - st = &states[state]; - mobj->state = st; - mobj->tics = st->tics; - mobj->sprite = st->sprite; - mobj->frame = st->frame; - - /* Modified handling. - * Call action functions when the state is set - */ - - if (st->action.acp1) st->action.acp1(mobj); - - state = st->nextstate; - - if (cycle_counter++ > MOBJ_CYCLE_LIMIT) - { - i_error("p_set_mobj_state: Infinite state cycle detected!"); - } - } - while (!mobj->tics); - - return true; -} - -/**************************************************************************** - * Name: p_mobj_thinker - ****************************************************************************/ - -void p_mobj_thinker(mobj_t *mobj) -{ - /* momentum movement */ - - if (mobj->momx || mobj->momy || (mobj->flags & MF_SKULLFLY)) - { - p_xy_movement(mobj); - - /* FIXME: decent NOP/NULL/Nil function pointer please. */ - - if (mobj->thinker.function.acv == (actionf_v)(-1)) - return; /* mobj was removed */ - } - - if ((mobj->z != mobj->floorz) || mobj->momz) - { - p_z_movement(mobj); - - /* FIXME: decent NOP/NULL/Nil function pointer please. */ - - if (mobj->thinker.function.acv == (actionf_v)(-1)) - return; /* mobj was removed */ - } - - /* cycle through states, calling action functions at transitions */ - - if (mobj->tics != -1) - { - mobj->tics--; - - /* you can cycle through multiple states in a tic */ - - if (!mobj->tics) - { - if (!p_set_mobj_state(mobj, mobj->state->nextstate)) - { - return; /* freed itself */ - } - } - } - else - { - /* check for nightmare respawn */ - - if (!(mobj->flags & MF_COUNTKILL)) return; - - if (!respawnmonsters) return; - - mobj->movecount++; - - if (mobj->movecount < 12 * TICRATE) return; - - if (leveltime & 31) return; - - if (p_random() > 4) return; - - p_nightmare_respawn(mobj); - } -} - -/**************************************************************************** - * Name: p_spawn_mobj - ****************************************************************************/ - -mobj_t *p_spawn_mobj(fixed_t x, fixed_t y, fixed_t z, mobjtype_t type) -{ - mobj_t *mobj; - state_t *st; - mobjinfo_t *info; - - mobj = z_malloc(sizeof(*mobj), PU_LEVEL, NULL); - memset(mobj, 0, sizeof(*mobj)); - info = &mobjinfo[type]; - - mobj->type = type; - mobj->info = info; - mobj->x = x; - mobj->y = y; - mobj->radius = info->radius; - mobj->height = info->height; - mobj->flags = info->flags; - mobj->health = info->spawnhealth; - - if (gameskill != sk_nightmare) mobj->reactiontime = info->reactiontime; - - mobj->lastlook = p_random() % MAXPLAYERS; - - /* do not set the state with p_set_mobj_state, - * because action routines can not be called yet - */ - - st = &states[info->spawnstate]; - - mobj->state = st; - mobj->tics = st->tics; - mobj->sprite = st->sprite; - mobj->frame = st->frame; - - /* set subsector and/or block links */ - - p_set_thing_position(mobj); - - mobj->floorz = mobj->subsector->sector->floorheight; - mobj->ceilingz = mobj->subsector->sector->ceilingheight; - - if (z == ONFLOORZ) - mobj->z = mobj->floorz; - else if (z == ONCEILINGZ) - mobj->z = mobj->ceilingz - mobj->info->height; - else - mobj->z = z; - - mobj->thinker.function.acp1 = (actionf_p1)p_mobj_thinker; - - p_add_thinker(&mobj->thinker); - - return mobj; -} - -/**************************************************************************** - * Name: p_remove_mobj - ****************************************************************************/ - -void p_remove_mobj(mobj_t *mobj) -{ - if ((mobj->flags & MF_SPECIAL) && !(mobj->flags & MF_DROPPED) && - (mobj->type != MT_INV) && (mobj->type != MT_INS)) - { - itemrespawnque[iquehead] = mobj->spawnpoint; - itemrespawntime[iquehead] = leveltime; - iquehead = (iquehead + 1) & (ITEMQUESIZE - 1); - - /* lose one off the end? */ - - if (iquehead == iquetail) - { - iquetail = (iquetail + 1) & (ITEMQUESIZE - 1); - } - } - - /* unlink from sector and block lists */ - - p_unset_thing_position(mobj); - -#ifdef CONFIG_GAMES_NXDOOM_SOUND - /* stop any playing sound */ - - s_stop_sound(mobj); -#endif - - p_remove_thinker((thinker_t *)mobj); /* free block */ -} - -/**************************************************************************** - * Name: p_respawn_specials - ****************************************************************************/ - -void p_respawn_specials(void) -{ - fixed_t x; - fixed_t y; - fixed_t z; - - subsector_t *ss; - mobj_t *mo; - mapthing_t *mthing; - - int i; - - /* only respawn items in deathmatch */ - - if (deathmatch != 2) return; - - /* nothing left to respawn? */ - - if (iquehead == iquetail) return; - - /* wait at least 30 seconds */ - - if (leveltime - itemrespawntime[iquetail] < 30 * TICRATE) return; - - mthing = &itemrespawnque[iquetail]; - - x = mthing->x << FRACBITS; - y = mthing->y << FRACBITS; - - /* spawn a teleport fog at the new spot */ - - ss = r_point_in_subsector(x, y); - mo = p_spawn_mobj(x, y, ss->sector->floorheight, MT_IFOG); -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(mo, SFX_ITMBK); -#endif - - /* find which type to spawn */ - - for (i = 0; i < NUMMOBJTYPES; i++) - { - if (mthing->type == mobjinfo[i].doomednum) break; - } - - if (i >= NUMMOBJTYPES) - { - i_error("p_respawn_specials: Failed to find mobj type with doomednum " - "%d when respawning thing. This would cause a buffer overrun " - "in vanilla Doom", - mthing->type); - } - - /* spawn it */ - - if (mobjinfo[i].flags & MF_SPAWNCEILING) - z = ONCEILINGZ; - else - z = ONFLOORZ; - - mo = p_spawn_mobj(x, y, z, i); - mo->spawnpoint = *mthing; - mo->angle = ANG45 * (mthing->angle / 45); - - /* pull it from the que */ - - iquetail = (iquetail + 1) & (ITEMQUESIZE - 1); -} - -/**************************************************************************** - * Name: p_spawn_player - * - * Description: - * Called when a player is spawned on the level. - * Most of the player structure stays unchanged between levels. - * - ****************************************************************************/ - -void p_spawn_player(mapthing_t *mthing) -{ - player_t *p; - fixed_t x; - fixed_t y; - fixed_t z; - - mobj_t *mobj; - - int i; - - if (mthing->type == 0) - { - return; - } - - /* not playing? */ - - if (!playeringame[mthing->type - 1]) return; - - p = &players[mthing->type - 1]; - - if (p->playerstate == PST_REBORN) g_player_reborn(mthing->type - 1); - - x = mthing->x << FRACBITS; - y = mthing->y << FRACBITS; - z = ONFLOORZ; - mobj = p_spawn_mobj(x, y, z, MT_PLAYER); - - /* set color translations for player sprites */ - - if (mthing->type > 1) mobj->flags |= (mthing->type - 1) << MF_TRANSSHIFT; - - mobj->angle = ANG45 * (mthing->angle / 45); - mobj->player = p; - mobj->health = p->health; - - p->mo = mobj; - p->playerstate = PST_LIVE; - p->refire = 0; - p->message = NULL; - p->damagecount = 0; - p->bonuscount = 0; - p->extralight = 0; - p->fixedcolormap = 0; - p->viewheight = VIEWHEIGHT; - - p_setup_psprites(p); /* setup gun psprite */ - - /* give all cards in death match mode */ - - if (deathmatch) - { - for (i = 0; i < NUMCARDS; i++) - { - p->cards[i] = true; - } - } - - if (mthing->type - 1 == consoleplayer) - { - st_start(); /* wake up the status bar */ - hu_start(); /* wake up the heads up text */ - } -} - -/**************************************************************************** - * Name: p_spawn_map_thing - * - * Description: - * The fields of the mapthing should already be in host byte order. - * - ****************************************************************************/ - -void p_spawn_map_thing(mapthing_t *mthing) -{ - int i; - int bit; - mobj_t *mobj; - fixed_t x; - fixed_t y; - fixed_t z; - - /* count deathmatch start positions */ - - if (mthing->type == 11) - { - if (deathmatch_p < &deathmatchstarts[10]) - { - memcpy(deathmatch_p, mthing, sizeof(*mthing)); - deathmatch_p++; - } - - return; - } - - if (mthing->type <= 0) - { - /* Thing type 0 is actually "player -1 start". - * For some reason, Vanilla Doom accepts/ignores this. - */ - - return; - } - - /* check for players specially */ - - if (mthing->type <= 4) - { - /* save spots for respawning in network games */ - - playerstarts[mthing->type - 1] = *mthing; - playerstartsingame[mthing->type - 1] = true; - if (!deathmatch) p_spawn_player(mthing); - - return; - } - - /* check for appropriate skill level */ - - if (!netgame && (mthing->options & 16)) return; - - if (gameskill == sk_baby) - { - bit = 1; - } - else if (gameskill == sk_nightmare) - { - bit = 4; - } - else - { - /* avoid undefined behavior (left shift by negative value and rhs too - * big) by accurately emulating what doom.exe did: reduce mod 32. For - * more details check: - * https://github.com/chocolate-doom/chocolate-doom/issues/1677 - */ - - bit = (int)(1U << ((gameskill - 1) & 0x1f)); - } - - if (!(mthing->options & bit)) return; - - /* find which type to spawn */ - - for (i = 0; i < NUMMOBJTYPES; i++) - { - if (mthing->type == mobjinfo[i].doomednum) break; - } - - if (i == NUMMOBJTYPES) - i_error("p_spawn_map_thing: Unknown type %i at (%i, %i)", mthing->type, - mthing->x, mthing->y); - - /* don't spawn keycards and players in deathmatch */ - - if (deathmatch && mobjinfo[i].flags & MF_NOTDMATCH) return; - - /* don't spawn any monsters if -nomonsters */ - - if (nomonsters && (i == MT_SKULL || (mobjinfo[i].flags & MF_COUNTKILL))) - { - return; - } - - /* spawn it */ - - x = mthing->x << FRACBITS; - y = mthing->y << FRACBITS; - - if (mobjinfo[i].flags & MF_SPAWNCEILING) - z = ONCEILINGZ; - else - z = ONFLOORZ; - - mobj = p_spawn_mobj(x, y, z, i); - mobj->spawnpoint = *mthing; - - if (mobj->tics > 0) mobj->tics = 1 + (p_random() % mobj->tics); - if (mobj->flags & MF_COUNTKILL) totalkills++; - if (mobj->flags & MF_COUNTITEM) totalitems++; - - mobj->angle = ANG45 * (mthing->angle / 45); - if (mthing->options & MTF_AMBUSH) mobj->flags |= MF_AMBUSH; -} - -/* GAME SPAWN FUNCTIONS */ - -/**************************************************************************** - * Name: p_spawn_puff - ****************************************************************************/ - -void p_spawn_puff(fixed_t x, fixed_t y, fixed_t z) -{ - mobj_t *th; - - z += (p_sub_random() << 10); - - th = p_spawn_mobj(x, y, z, MT_PUFF); - th->momz = FRACUNIT; - th->tics -= p_random() & 3; - - if (th->tics < 1) th->tics = 1; - - /* don't make punches spark on the wall */ - - if (attackrange == MELEERANGE) p_set_mobj_state(th, S_PUFF3); -} - -/**************************************************************************** - * Name: p_spawn_blood - ****************************************************************************/ - -void p_spawn_blood(fixed_t x, fixed_t y, fixed_t z, int damage) -{ - mobj_t *th; - - z += (p_sub_random() << 10); - th = p_spawn_mobj(x, y, z, MT_BLOOD); - th->momz = FRACUNIT * 2; - th->tics -= p_random() & 3; - - if (th->tics < 1) th->tics = 1; - - if (damage <= 12 && damage >= 9) - p_set_mobj_state(th, S_BLOOD2); - else if (damage < 9) - p_set_mobj_state(th, S_BLOOD3); -} - -/**************************************************************************** - * Name: p_subst_null_mobj - * - * Description: - * Certain functions assume that a mobj_t pointer is non-NULL, - * causing a crash in some situations where it is NULL. Vanilla - * Doom did not crash because of the lack of proper memory - * protection. This function substitutes NULL pointers for - * pointers to a dummy mobj, to avoid a crash. - * - ****************************************************************************/ - -mobj_t *p_subst_null_mobj(mobj_t *mobj) -{ - if (mobj == NULL) - { - static mobj_t dummy_mobj; - - dummy_mobj.x = 0; - dummy_mobj.y = 0; - dummy_mobj.z = 0; - dummy_mobj.flags = 0; - - mobj = &dummy_mobj; - } - - return mobj; -} - -/**************************************************************************** - * Name: p_spawn_missile - ****************************************************************************/ - -mobj_t *p_spawn_missile(mobj_t *source, mobj_t *dest, mobjtype_t type) -{ - mobj_t *th; - angle_t an; - int dist; - - th = p_spawn_mobj(source->x, source->y, - source->z + 4 * 8 * FRACUNIT, type); - -#ifdef CONFIG_GAMES_NXDOOM_SOUND - if (th->info->seesound) s_start_sound(th, th->info->seesound); -#endif - - th->target = source; /* where it came from */ - an = r_point_to_angle2(source->x, source->y, dest->x, dest->y); - - /* fuzzy player */ - - if (dest->flags & MF_SHADOW) an += p_sub_random() << 20; - - th->angle = an; - an >>= ANGLETOFINESHIFT; - th->momx = fixed_mul(th->info->speed, finecosine[an]); - th->momy = fixed_mul(th->info->speed, finesine[an]); - - dist = p_approx_distance(dest->x - source->x, dest->y - source->y); - dist = dist / th->info->speed; - - if (dist < 1) dist = 1; - - th->momz = (dest->z - source->z) / dist; - p_check_missile_spawn(th); - - return th; -} - -/**************************************************************************** - * Name: p_spawn_player_missile - * - * Description: - * Tries to aim at a nearby monster - * - ****************************************************************************/ - -void p_spawn_player_missile(mobj_t *source, mobjtype_t type) -{ - mobj_t *th; - angle_t an; - - fixed_t x; - fixed_t y; - fixed_t z; - fixed_t slope; - - /* see which target is to be aimed at */ - - an = source->angle; - slope = p_aim_line_attack(source, an, 16 * 64 * FRACUNIT); - - if (!linetarget) - { - an += 1 << 26; - slope = p_aim_line_attack(source, an, 16 * 64 * FRACUNIT); - - if (!linetarget) - { - an -= 2 << 26; - slope = p_aim_line_attack(source, an, 16 * 64 * FRACUNIT); - } - - if (!linetarget) - { - an = source->angle; - slope = 0; - } - } - - x = source->x; - y = source->y; - z = source->z + 4 * 8 * FRACUNIT; - - th = p_spawn_mobj(x, y, z, type); - -#ifdef CONFIG_GAMES_NXDOOM_SOUND - if (th->info->seesound) s_start_sound(th, th->info->seesound); -#endif - - th->target = source; - th->angle = an; - th->momx = fixed_mul(th->info->speed, finecosine[an >> ANGLETOFINESHIFT]); - th->momy = fixed_mul(th->info->speed, finesine[an >> ANGLETOFINESHIFT]); - th->momz = fixed_mul(th->info->speed, slope); - - p_check_missile_spawn(th); -} diff --git a/games/NXDoom/src/doom/p_mobj.h b/games/NXDoom/src/doom/p_mobj.h deleted file mode 100644 index 6cd73f3a6..000000000 --- a/games/NXDoom/src/doom/p_mobj.h +++ /dev/null @@ -1,357 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/p_mobj.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Map Objects, MObj, definition and handling. - * - ****************************************************************************/ - -#ifndef __P_MOBJ__ -#define __P_MOBJ__ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -/* Basics. */ - -#include "m_fixed.h" -#include "tables.h" - -/* We need the thinker_t stuff. */ - -#include "d_think.h" - -/* We need the WAD data structure for Map things, from the THINGS lump. */ - -#include "doomdata.h" - -/* States are tied to finite states are tied to animation frames. - * Needs precompiled tables/data structures. - */ - -#include "info.h" - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -/* NOTES: mobj_t - * - * mobj_ts are used to tell the refresh where to draw an image, - * tell the world simulation when objects are contacted, - * and tell the sound driver how to position a sound. - * - * The refresh uses the next and prev links to follow - * lists of things in sectors as they are being drawn. - * The sprite, frame, and angle elements determine which patch_t - * is used to draw the sprite if it is visible. - * The sprite and frame values are almost always set - * from state_t structures. - * The statescr.exe utility generates the states.h and states.c - * files that contain the sprite/frame numbers from the - * statescr.txt source file. - * The xyz origin point represents a point at the bottom middle - * of the sprite (between the feet of a biped). - * This is the default origin position for patch_ts grabbed - * with lumpy.exe. - * A walking creature will have its z equal to the floor - * it is standing on. - * - * The sound code uses the x,y, and subsector fields - * to do stereo positioning of any sound effited by the mobj_t. - * - * The play simulation uses the blocklinks, x,y,z, radius, height - * to determine when mobj_ts are touching each other, - * touching lines in the map, or hit by trace lines (gunshots, - * lines of sight, etc). - * The mobj_t->flags element has various bit flags - * used by the simulation. - * - * Every mobj_t is linked into a single sector - * based on its origin coordinates. - * The subsector_t is found with r_point_in_subsector(x,y), - * and the sector_t can be found with subsector->sector. - * The sector links are only used by the rendering code, - * the play simulation does not care about them at all. - * - * Any mobj_t that needs to be acted upon by something else - * in the play world (block movement, be shot, etc) will also - * need to be linked into the blockmap. - * If the thing has the MF_NOBLOCK flag set, it will not use - * the block links. It can still interact with other things, - * but only as the instigator (missiles will run into other - * things, but nothing can run into a missile). - * Each block in the grid is 128*128 units, and knows about - * every line_t that it contains a piece of, and every - * interactable mobj_t that has its origin contained. - * - * A valid mobj_t is a mobj_t that has the proper subsector_t - * filled in for its xy coordinates and is linked into the - * sector from which the subsector was made, or has the - * MF_NOSECTOR flag set (the subsector_t needs to be valid - * even if MF_NOSECTOR is set), and is linked into a blockmap - * block or has the MF_NOBLOCKMAP flag set. - * Links should only be modified by the P_[Un]SetThingPosition() - * functions. - * Do not change the MF_NO? flags while a thing is valid. - * - * Any questions? - */ - -/* Misc. mobj flags */ - -typedef enum -{ - MF_SPECIAL = 1, /* Call P_SpecialThing when touched. */ - MF_SOLID = 2, /* Blocks. */ - MF_SHOOTABLE = 4, /* Can be hit. */ - - /* Don't use the sector links (invisible but touchable). */ - - MF_NOSECTOR = 8, - - /* Don't use the blocklinks (inert but displayable) */ - - MF_NOBLOCKMAP = 16, - - /* Not to be activated by sound, deaf monster. */ - - MF_AMBUSH = 32, - - /* Will try to attack right back. */ - - MF_JUSTHIT = 64, - - /* Will take at least one step before attacking. */ - - MF_JUSTATTACKED = 128, - - /* On level spawning (initial position), hang from ceiling instead of stand - * on floor. - */ - - MF_SPAWNCEILING = 256, - - /* Don't apply gravity (every tic), that is, object will float, keeping - * current height or changing it actively. - */ - - MF_NOGRAVITY = 512, - - /* Movement flags. This allows jumps from high places. */ - - MF_DROPOFF = 0x400, - - /* For players, will pick up items. */ - - MF_PICKUP = 0x800, - - /* Player cheat. ??? */ - - MF_NOCLIP = 0x1000, - - /* Player: keep info about sliding along walls. */ - - MF_SLIDE = 0x2000, - - /* Allow moves to any height, no gravity. - * For active floaters, e.g. cacodemons, pain elementals. - */ - - MF_FLOAT = 0x4000, - - /* Don't cross lines ??? or look at heights on teleport. */ - - MF_TELEPORT = 0x8000, - - /* Don't hit same species, explode on block. - * Player missiles as well as fireballs of various kinds. - */ - - MF_MISSILE = 0x10000, - - /* Dropped by a demon, not level spawned. - * E.g. ammo clips dropped by dying former humans. - */ - - MF_DROPPED = 0x20000, - - /* Use fuzzy draw (shadow demons or spectres), temporary player - * invisibility powerup. - */ - - MF_SHADOW = 0x40000, - - /* Flag: don't bleed when shot (use puff), barrels and shootable furniture - * shall not bleed. - */ - - MF_NOBLOOD = 0x80000, - - /* Don't stop moving halfway off a step, that is, have dead bodies slide - * down all the way. - */ - - MF_CORPSE = 0x100000, - - /* Floating to a height for a move, ??? don't auto float to target's - * height. - */ - - MF_INFLOAT = 0x200000, - - /* On kill, count this enemy object towards intermission kill total. - * Happy gathering. - */ - - MF_COUNTKILL = 0x400000, - - /* On picking up, count this item object towards intermission item total. */ - - MF_COUNTITEM = 0x800000, - - /* Special handling: skull in flight. - * Neither a cacodemon nor a missile. - */ - - MF_SKULLFLY = 0x1000000, - - /* Don't spawn this object in death match mode (e.g. key cards). - */ - - MF_NOTDMATCH = 0x2000000, - - /* Player sprites in multiplayer modes are modified using an internal color - * lookup table for re-indexing. - * - * If 0x4 0x8 or 0xc, use a translation table for player colormaps - */ - - MF_TRANSLATION = 0xc000000, - - /* Hmm ???. */ - - MF_TRANSSHIFT = 26 -} mobjflag_t; - -/* Map Object definition. */ - -typedef struct mobj_s -{ - /* List: thinker links. */ - - thinker_t thinker; - - /* Info for drawing: position. */ - - fixed_t x; - fixed_t y; - fixed_t z; - - /* More list: links in sector (if needed) */ - - struct mobj_s *snext; - struct mobj_s *sprev; - - /* More drawing info: to determine current sprite. */ - - angle_t angle; /* orientation */ - spritenum_t sprite; /* used to find patch_t and flip value */ - int frame; /* might be ORed with FF_FULLBRIGHT */ - - /* Interaction info, by BLOCKMAP. - * Links in blocks (if needed). - */ - - struct mobj_s *bnext; - struct mobj_s *bprev; - - struct subsector_s *subsector; - - /* The closest interval over all contacted Sectors. */ - - fixed_t floorz; - fixed_t ceilingz; - - /* For movement checking. */ - - fixed_t radius; - fixed_t height; - - /* Momentums, used to update position. */ - - fixed_t momx; - fixed_t momy; - fixed_t momz; - - /* If == validcount, already checked. */ - - int validcount; - - mobjtype_t type; - mobjinfo_t *info; /* &mobjinfo[mobj->type] */ - - int tics; /* state tic counter */ - state_t *state; - int flags; - int health; - - /* Movement direction, movement generation (zig-zagging). */ - - int movedir; /* 0-7 */ - int movecount; /* when 0, select a new dir */ - - /* Thing being chased/attacked (or NULL), - * also the originator for missiles. - */ - - struct mobj_s *target; - - /* Reaction time: if non 0, don't attack yet. - * Used by player to freeze a bit after teleporting. - */ - - int reactiontime; - - /* If >0, the target will be chased - * no matter what (even if shot) - */ - - int threshold; - - /* Additional info record for player avatars only. - * Only valid if type == MT_PLAYER - */ - - struct player_s *player; - - /* Player number last looked for. */ - - int lastlook; - - /* For nightmare re-spawn. */ - - mapthing_t spawnpoint; - - /* Thing being chased/attacked for tracers. */ - - struct mobj_s *tracer; -} mobj_t; - -#endif /* __P_MOBJ__ */ diff --git a/games/NXDoom/src/doom/p_plats.c b/games/NXDoom/src/doom/p_plats.c deleted file mode 100644 index 8cbbf7052..000000000 --- a/games/NXDoom/src/doom/p_plats.c +++ /dev/null @@ -1,336 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/p_plats.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Plats (i.e. elevator platforms) code, raising/lowering. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include "i_system.h" -#include "m_random.h" -#include "z_zone.h" - -#include "doomdef.h" -#include "p_local.h" - -#ifdef CONFIG_GAMES_NXDOOM_SOUND -#include "s_sound.h" -#include "sounds.h" -#endif - -/* State. */ - -#include "doomstat.h" -#include "r_state.h" - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -plat_t *activeplats[MAXPLATS]; - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/* Move a plat up and down */ - -void t_plat_raise(plat_t *plat) -{ - result_e res; - - switch (plat->status) - { - case up: - res = t_move_plane(plat->sector, plat->speed, - plat->high, plat->crush, 0, 1); - -#ifdef CONFIG_GAMES_NXDOOM_SOUND - if (plat->type == PLAT_RAISEANDCHANGE || - plat->type == PLAT_RAISETONEARESTANDCHANGE) - { - if (!(leveltime & 7)) - s_start_sound(&plat->sector->soundorg, SFX_STNMOV); - } -#endif - - if (res == crushed && (!plat->crush)) - { - plat->count = plat->wait; - plat->status = down; -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(&plat->sector->soundorg, SFX_PSTART); -#endif - } - else - { - if (res == pastdest) - { - plat->count = plat->wait; - plat->status = waiting; -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(&plat->sector->soundorg, SFX_PSTOP); -#endif - - switch (plat->type) - { - case PLAT_BLAZEDWUS: - case PLAT_DOWNWAITUPSTAY: - p_remove_active_plat(plat); - break; - - case PLAT_RAISEANDCHANGE: - case PLAT_RAISETONEARESTANDCHANGE: - p_remove_active_plat(plat); - break; - - default: - break; - } - } - } - break; - - case down: - res = t_move_plane(plat->sector, plat->speed, plat->low, false, 0, -1); - - if (res == pastdest) - { - plat->count = plat->wait; - plat->status = waiting; -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(&plat->sector->soundorg, SFX_PSTOP); -#endif - } - break; - - case waiting: - if (!--plat->count) - { - if (plat->sector->floorheight == plat->low) - plat->status = up; - else - plat->status = down; -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(&plat->sector->soundorg, SFX_PSTART); -#endif - } - - case in_stasis: - break; - } -} - -/* Do Platforms - * "amount" is only used for SOME platforms. - */ - -int ev_do_plat(line_t *line, plattype_e type, int amount) -{ - plat_t *plat; - int secnum; - int rtn; - sector_t *sec; - - secnum = -1; - rtn = 0; - - /* Activate all plats that are in_stasis */ - - switch (type) - { - case PLAT_PERPETUALRAISE: - p_activate_in_stasis(line->tag); - break; - - default: - break; - } - - while ((secnum = p_find_sector_from_line_tag(line, secnum)) >= 0) - { - sec = §ors[secnum]; - - if (sec->specialdata) continue; - - /* Find lowest & highest floors around sector */ - - rtn = 1; - plat = z_malloc(sizeof(*plat), PU_LEVSPEC, 0); - p_add_thinker(&plat->thinker); - - plat->type = type; - plat->sector = sec; - plat->sector->specialdata = plat; - plat->thinker.function.acp1 = (actionf_p1)t_plat_raise; - plat->crush = false; - plat->tag = line->tag; - - switch (type) - { - case PLAT_RAISETONEARESTANDCHANGE: - plat->speed = PLATSPEED / 2; - sec->floorpic = sides[line->sidenum[0]].sector->floorpic; - plat->high = p_find_next_highest_floor(sec, sec->floorheight); - plat->wait = 0; - plat->status = up; - - /* NO MORE DAMAGE, IF APPLICABLE */ - - sec->special = 0; - -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(&sec->soundorg, SFX_STNMOV); -#endif - break; - - case PLAT_RAISEANDCHANGE: - plat->speed = PLATSPEED / 2; - sec->floorpic = sides[line->sidenum[0]].sector->floorpic; - plat->high = sec->floorheight + amount * FRACUNIT; - plat->wait = 0; - plat->status = up; - -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(&sec->soundorg, SFX_STNMOV); -#endif - break; - - case PLAT_DOWNWAITUPSTAY: - plat->speed = PLATSPEED * 4; - plat->low = p_find_lowest_floor_surrounding(sec); - - if (plat->low > sec->floorheight) plat->low = sec->floorheight; - - plat->high = sec->floorheight; - plat->wait = TICRATE * PLATWAIT; - plat->status = down; -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(&sec->soundorg, SFX_PSTART); -#endif - break; - - case PLAT_BLAZEDWUS: - plat->speed = PLATSPEED * 8; - plat->low = p_find_lowest_floor_surrounding(sec); - - if (plat->low > sec->floorheight) plat->low = sec->floorheight; - - plat->high = sec->floorheight; - plat->wait = TICRATE * PLATWAIT; - plat->status = down; -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(&sec->soundorg, SFX_PSTART); -#endif - break; - - case PLAT_PERPETUALRAISE: - plat->speed = PLATSPEED; - plat->low = p_find_lowest_floor_surrounding(sec); - - if (plat->low > sec->floorheight) plat->low = sec->floorheight; - - plat->high = p_find_highest_floor_surrounding(sec); - - if (plat->high < sec->floorheight) plat->high = sec->floorheight; - - plat->wait = TICRATE * PLATWAIT; - plat->status = p_random() & 1; - -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(&sec->soundorg, SFX_PSTART); -#endif - break; - } - - p_add_active_plat(plat); - } - - return rtn; -} - -void p_activate_in_stasis(int tag) -{ - int i; - - for (i = 0; i < MAXPLATS; i++) - { - if (activeplats[i] && (activeplats[i])->tag == tag && - (activeplats[i])->status == in_stasis) - { - (activeplats[i])->status = (activeplats[i])->oldstatus; - (activeplats[i])->thinker.function.acp1 = (actionf_p1)t_plat_raise; - } - } -} - -void ev_stop_plat(line_t *line) -{ - int j; - - for (j = 0; j < MAXPLATS; j++) - { - if (activeplats[j] && ((activeplats[j])->status != in_stasis) && - ((activeplats[j])->tag == line->tag)) - { - (activeplats[j])->oldstatus = (activeplats[j])->status; - (activeplats[j])->status = in_stasis; - (activeplats[j])->thinker.function.acv = (actionf_v)NULL; - } - } -} - -void p_add_active_plat(plat_t *plat) -{ - int i; - - for (i = 0; i < MAXPLATS; i++) - { - if (activeplats[i] == NULL) - { - activeplats[i] = plat; - return; - } - } - - i_error("p_add_active_plat: no more plats!"); -} - -void p_remove_active_plat(plat_t *plat) -{ - int i; - for (i = 0; i < MAXPLATS; i++) - { - if (plat == activeplats[i]) - { - (activeplats[i])->sector->specialdata = NULL; - p_remove_thinker(&(activeplats[i])->thinker); - activeplats[i] = NULL; - - return; - } - } - - i_error("p_remove_active_plat: can't find plat!"); -} diff --git a/games/NXDoom/src/doom/p_pspr.c b/games/NXDoom/src/doom/p_pspr.c deleted file mode 100644 index 42a58f23a..000000000 --- a/games/NXDoom/src/doom/p_pspr.c +++ /dev/null @@ -1,788 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/p_pspr.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Weapon sprite animation, weapon objects. - * Action functions for weapons. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "d_event.h" -#include "doomdef.h" - -#include "deh_misc.h" - -#include "m_random.h" -#include "p_local.h" - -#ifdef CONFIG_GAMES_NXDOOM_SOUND -#include "s_sound.h" -#include "sounds.h" -#endif - -/* State. */ - -#include "doomstat.h" - -/* Data. */ - -#include "p_pspr.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define LOWERSPEED FRACUNIT * 6 -#define RAISESPEED FRACUNIT * 6 - -#define WEAPONBOTTOM 128 * FRACUNIT -#define WEAPONTOP 32 * FRACUNIT - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -fixed_t swingx; -fixed_t swingy; - -fixed_t bulletslope; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static void p_set_psprite(player_t *player, int position, statenum_t stnum) -{ - pspdef_t *psp; - state_t *state; - - psp = &player->psprites[position]; - - do - { - if (!stnum) - { - /* object removed itself */ - - psp->state = NULL; - break; - } - - state = &states[stnum]; - psp->state = state; - psp->tics = state->tics; /* could be 0 */ - -#if 0 /* Unused as far as I can tell */ - if (state->misc1) - { - /* coordinate set */ - - psp->sx = state->misc1 << FRACBITS; - psp->sy = state->misc2 << FRACBITS; - } -#endif - - /* Call action routine. - * Modified handling. - */ - - if (state->action.acp2) - { - state->action.acp2(player, psp); - if (!psp->state) break; - } - - stnum = psp->state->nextstate; - } - while (!psp->tics); - - /* an initial state of 0 could cycle through */ -} - -#if 0 /* UNUSED */ -static void p_calc_swing(player_t *player) -{ - fixed_t swing; - int angle; - - /* OPTIMIZE: tablify this. - * A LUT would allow for different modes, and add flexibility. - */ - - swing = player->bob; - - angle = (FINEANGLES / 70 * leveltime) & FINEMASK; - swingx = fixed_mul(swing, finesine[angle]); - - angle = (FINEANGLES / 70 * leveltime + FINEANGLES / 2) & FINEMASK; - swingy = -fixed_mul(swingx, finesine[angle]); -} -#endif - -/* p_bringup_weapon - * Starts bringing the pending weapon up from the bottom of the screen. Uses - * player - */ - -static void p_bringup_weapon(player_t *player) -{ - statenum_t newstate; - - if (player->pendingweapon == wp_nochange) - player->pendingweapon = player->readyweapon; - -#ifdef CONFIG_GAMES_NXDOOM_SOUND - if (player->pendingweapon == wp_chainsaw) - s_start_sound(player->mo, SFX_SAWUP); -#endif - - newstate = weaponinfo[player->pendingweapon].upstate; - - player->pendingweapon = wp_nochange; - player->psprites[ps_weapon].sy = WEAPONBOTTOM; - - p_set_psprite(player, ps_weapon, newstate); -} - -/* Doom does not check the bounds of the ammo array. As a result, - * it is possible to use an ammo type > 4 that overflows into the - * maxammo array and affects that instead. Through dehacked, for - * example, it is possible to make a weapon that decreases the max - * number of ammo for another weapon. Emulate this. - */ - -static void decrease_ammo(player_t *player, int ammonum, int amount) -{ - if (ammonum < NUMAMMO) - { - player->ammo[ammonum] -= amount; - } - else - { - player->maxammo[ammonum - NUMAMMO] -= amount; - } -} - -/* p_bullet_slope - * Sets a slope so a near miss is at approximately - * the height of the intended target - */ - -static void p_bullet_slope(mobj_t *mo) -{ - angle_t an; - - /* see which target is to be aimed at */ - - an = mo->angle; - bulletslope = p_aim_line_attack(mo, an, 16 * 64 * FRACUNIT); - - if (!linetarget) - { - an += 1 << 26; - bulletslope = p_aim_line_attack(mo, an, 16 * 64 * FRACUNIT); - if (!linetarget) - { - an -= 2 << 26; - bulletslope = p_aim_line_attack(mo, an, 16 * 64 * FRACUNIT); - } - } -} - -static void p_gunshot(mobj_t *mo, boolean accurate) -{ - angle_t angle; - int damage; - - damage = 5 * (p_random() % 3 + 1); - angle = mo->angle; - - if (!accurate) angle += p_sub_random() << 18; - - p_line_attack(mo, angle, MISSILERANGE, bulletslope, damage); -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/* p_check_ammo - * Returns true if there is enough ammo to shoot. - * If not, selects the next weapon to use. - */ - -boolean p_check_ammo(player_t *player) -{ - ammotype_t ammo; - int count; - - ammo = weaponinfo[player->readyweapon].ammo; - - /* Minimal amount for one shot varies. */ - - if (player->readyweapon == wp_bfg) - count = deh_bfg_cells_per_shot; - else if (player->readyweapon == wp_supershotgun) - count = 2; /* Double barrel. */ - else - count = 1; /* Regular. */ - - /* Some do not need ammunition anyway. - * Return if current ammunition sufficient. - */ - - if (ammo == am_noammo || player->ammo[ammo] >= count) return true; - - /* Out of ammo, pick a weapon to change to. - * Preferences are set here. - */ - - do - { - if (player->weaponowned[wp_plasma] && player->ammo[am_cell] && - (gamemode != shareware)) - { - player->pendingweapon = wp_plasma; - } - else if (player->weaponowned[wp_supershotgun] && - player->ammo[am_shell] > 2 && (gamemode == commercial)) - { - player->pendingweapon = wp_supershotgun; - } - else if (player->weaponowned[wp_chaingun] && player->ammo[am_clip]) - { - player->pendingweapon = wp_chaingun; - } - else if (player->weaponowned[wp_shotgun] && player->ammo[am_shell]) - { - player->pendingweapon = wp_shotgun; - } - else if (player->ammo[am_clip]) - { - player->pendingweapon = wp_pistol; - } - else if (player->weaponowned[wp_chainsaw]) - { - player->pendingweapon = wp_chainsaw; - } - else if (player->weaponowned[wp_missile] && player->ammo[am_misl]) - { - player->pendingweapon = wp_missile; - } - else if (player->weaponowned[wp_bfg] && player->ammo[am_cell] > 40 && - (gamemode != shareware)) - { - player->pendingweapon = wp_bfg; - } - else - { - /* If everything fails. */ - - player->pendingweapon = wp_fist; - } - } - while (player->pendingweapon == wp_nochange); - - /* Now set appropriate weapon overlay. */ - - p_set_psprite(player, ps_weapon, - weaponinfo[player->readyweapon].downstate); - return false; -} - -static void p_fire_weapon(player_t *player) -{ - statenum_t newstate; - - if (!p_check_ammo(player)) return; - - p_set_mobj_state(player->mo, S_PLAY_ATK1); - newstate = weaponinfo[player->readyweapon].atkstate; - p_set_psprite(player, ps_weapon, newstate); - p_noise_alert(player->mo, player->mo); -} - -/* p_drop_weapon - * Player died, so put the weapon away. - */ - -void p_drop_weapon(player_t *player) -{ - p_set_psprite(player, ps_weapon, - weaponinfo[player->readyweapon].downstate); -} - -/* a_weapon_ready - * The player can fire the weapon or change to another weapon at this time. - * Follows after getting weapon up, or after previous attack/fire sequence. - */ - -void a_weapon_ready(player_t *player, pspdef_t *psp) -{ - statenum_t newstate; - int angle; - - /* get out of attack state */ - - if (player->mo->state == &states[S_PLAY_ATK1] || - player->mo->state == &states[S_PLAY_ATK2]) - { - p_set_mobj_state(player->mo, S_PLAY); - } - - if (player->readyweapon == wp_chainsaw && psp->state == &states[S_SAW]) - { -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(player->mo, SFX_SAWIDL); -#endif - } - - /* check for change if player is dead, put the weapon away */ - - if (player->pendingweapon != wp_nochange || !player->health) - { - /* change weapon (pending weapon should already be validated) */ - - newstate = weaponinfo[player->readyweapon].downstate; - p_set_psprite(player, ps_weapon, newstate); - return; - } - - /* check for fire the missile launcher and bfg do not auto fire */ - - if (player->cmd.buttons & BT_ATTACK) - { - if (!player->attackdown || (player->readyweapon != wp_missile && - player->readyweapon != wp_bfg)) - { - player->attackdown = true; - p_fire_weapon(player); - return; - } - } - else - player->attackdown = false; - - /* bob the weapon based on movement speed */ - - angle = (128 * leveltime) & FINEMASK; - psp->sx = FRACUNIT + fixed_mul(player->bob, finecosine[angle]); - angle &= FINEANGLES / 2 - 1; - psp->sy = WEAPONTOP + fixed_mul(player->bob, finesine[angle]); -} - -/* a_refire - * The player can re-fire the weapon without lowering it entirely. - */ - -void a_refire(player_t *player, pspdef_t *psp) -{ - /* check for fire (if a weaponchange is pending, let it go through instead) - */ - - if ((player->cmd.buttons & BT_ATTACK) && - player->pendingweapon == wp_nochange && player->health) - { - player->refire++; - p_fire_weapon(player); - } - else - { - player->refire = 0; - p_check_ammo(player); - } -} - -void a_check_reload(player_t *player, pspdef_t *psp) -{ - p_check_ammo(player); -#if 0 - if (player->ammo[am_shell] < 2) - { - p_set_psprite(player, ps_weapon, S_DSNR1); - } -#endif -} - -/* a_lower - * Lowers current weapon, and changes weapon at bottom. - */ - -void a_lower(player_t *player, pspdef_t *psp) -{ - psp->sy += LOWERSPEED; - - /* Is already down. */ - - if (psp->sy < WEAPONBOTTOM) return; - - /* Player is dead. */ - - if (player->playerstate == PST_DEAD) - { - psp->sy = WEAPONBOTTOM; - - /* don't bring weapon back up */ - - return; - } - - /* The old weapon has been lowered off the screen, so change the weapon and - * start raising it - */ - - if (!player->health) - { - /* Player is dead, so keep the weapon off screen. */ - - p_set_psprite(player, ps_weapon, S_NULL); - return; - } - - player->readyweapon = player->pendingweapon; - - p_bringup_weapon(player); -} - -void a_raise(player_t *player, pspdef_t *psp) -{ - statenum_t newstate; - - psp->sy -= RAISESPEED; - - if (psp->sy > WEAPONTOP) return; - - psp->sy = WEAPONTOP; - - /* The weapon has been raised all the way, so change to the ready state. */ - - newstate = weaponinfo[player->readyweapon].readystate; - - p_set_psprite(player, ps_weapon, newstate); -} - -void a_gun_flash(player_t *player, pspdef_t *psp) -{ - p_set_mobj_state(player->mo, S_PLAY_ATK2); - p_set_psprite(player, ps_flash, - weaponinfo[player->readyweapon].flashstate); -} - -/* WEAPON ATTACKS */ - -void a_punch(player_t *player, pspdef_t *psp) -{ - angle_t angle; - int damage; - int slope; - - damage = (p_random() % 10 + 1) << 1; - - if (player->powers[pw_strength]) damage *= 10; - - angle = player->mo->angle; - angle += p_sub_random() << 18; - slope = p_aim_line_attack(player->mo, angle, MELEERANGE); - p_line_attack(player->mo, angle, MELEERANGE, slope, damage); - - /* turn to face target */ - - if (linetarget) - { -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(player->mo, SFX_PUNCH); -#endif - player->mo->angle = r_point_to_angle2(player->mo->x, player->mo->y, - linetarget->x, linetarget->y); - } -} - -void a_saw(player_t *player, pspdef_t *psp) -{ - angle_t angle; - int damage; - int slope; - - damage = 2 * (p_random() % 10 + 1); - angle = player->mo->angle; - angle += p_sub_random() << 18; - - /* use meleerange + 1 se the puff doesn't skip the flash */ - - slope = p_aim_line_attack(player->mo, angle, MELEERANGE + 1); - p_line_attack(player->mo, angle, MELEERANGE + 1, slope, damage); - - if (!linetarget) - { -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(player->mo, SFX_SAWFUL); -#endif - return; - } - -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(player->mo, SFX_SAWHIT); -#endif - - /* turn to face target */ - - angle = r_point_to_angle2(player->mo->x, player->mo->y, linetarget->x, - linetarget->y); - if (angle - player->mo->angle > ANG180) - { - if ((signed int)(angle - player->mo->angle) < -ANG90 / 20) - player->mo->angle = angle + ANG90 / 21; - else - player->mo->angle -= ANG90 / 20; - } - else - { - if (angle - player->mo->angle > ANG90 / 20) - player->mo->angle = angle - ANG90 / 21; - else - player->mo->angle += ANG90 / 20; - } - - player->mo->flags |= MF_JUSTATTACKED; -} - -void a_fire_missile(player_t *player, pspdef_t *psp) -{ - decrease_ammo(player, weaponinfo[player->readyweapon].ammo, 1); - p_spawn_player_missile(player->mo, MT_ROCKET); -} - -void a_fire_bfg(player_t *player, pspdef_t *psp) -{ - decrease_ammo(player, weaponinfo[player->readyweapon].ammo, - deh_bfg_cells_per_shot); - p_spawn_player_missile(player->mo, MT_BFG); -} - -void a_fire_plasma(player_t *player, pspdef_t *psp) -{ - decrease_ammo(player, weaponinfo[player->readyweapon].ammo, 1); - - p_set_psprite(player, ps_flash, - weaponinfo[player->readyweapon].flashstate + - (p_random() & 1)); - - p_spawn_player_missile(player->mo, MT_PLASMA); -} - -void a_fire_pistol(player_t *player, pspdef_t *psp) -{ -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(player->mo, SFX_PISTOL); -#endif - - p_set_mobj_state(player->mo, S_PLAY_ATK2); - decrease_ammo(player, weaponinfo[player->readyweapon].ammo, 1); - - p_set_psprite(player, ps_flash, - weaponinfo[player->readyweapon].flashstate); - - p_bullet_slope(player->mo); - p_gunshot(player->mo, !player->refire); -} - -void a_fire_shotgun(player_t *player, pspdef_t *psp) -{ - int i; - -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(player->mo, SFX_SHOTGN); -#endif - p_set_mobj_state(player->mo, S_PLAY_ATK2); - - decrease_ammo(player, weaponinfo[player->readyweapon].ammo, 1); - - p_set_psprite(player, ps_flash, - weaponinfo[player->readyweapon].flashstate); - - p_bullet_slope(player->mo); - - for (i = 0; i < 7; i++) - p_gunshot(player->mo, false); -} - -void a_fire_shotgun2(player_t *player, pspdef_t *psp) -{ - int i; - angle_t angle; - int damage; - -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(player->mo, SFX_DSHTGN); -#endif - p_set_mobj_state(player->mo, S_PLAY_ATK2); - - decrease_ammo(player, weaponinfo[player->readyweapon].ammo, 2); - - p_set_psprite(player, ps_flash, - weaponinfo[player->readyweapon].flashstate); - - p_bullet_slope(player->mo); - - for (i = 0; i < 20; i++) - { - damage = 5 * (p_random() % 3 + 1); - angle = player->mo->angle; - angle += p_sub_random() << ANGLETOFINESHIFT; - p_line_attack(player->mo, angle, MISSILERANGE, - bulletslope + (p_sub_random() << 5), damage); - } -} - -void a_fire_cgun(player_t *player, pspdef_t *psp) -{ -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(player->mo, SFX_PISTOL); -#endif - - if (!player->ammo[weaponinfo[player->readyweapon].ammo]) return; - - p_set_mobj_state(player->mo, S_PLAY_ATK2); - decrease_ammo(player, weaponinfo[player->readyweapon].ammo, 1); - - p_set_psprite(player, ps_flash, - weaponinfo[player->readyweapon].flashstate + psp->state - - &states[S_CHAIN1]); - - p_bullet_slope(player->mo); - - p_gunshot(player->mo, !player->refire); -} - -/* ? */ - -void a_light0(player_t *player, pspdef_t *psp) -{ - player->extralight = 0; -} - -void a_light1(player_t *player, pspdef_t *psp) -{ - player->extralight = 1; -} - -void a_light2(player_t *player, pspdef_t *psp) -{ - player->extralight = 2; -} - -/* a_bfg_spray - * Spawn a BFG explosion on every monster in view - */ - -void a_bfg_spray(mobj_t *mo) -{ - int i; - int j; - int damage; - angle_t an; - - /* offset angles from its attack angle */ - - for (i = 0; i < 40; i++) - { - an = mo->angle - ANG90 / 2 + ANG90 / 40 * i; - - /* mo->target is the originator (player) of the missile */ - - p_aim_line_attack(mo->target, an, 16 * 64 * FRACUNIT); - - if (!linetarget) continue; - - p_spawn_mobj(linetarget->x, linetarget->y, - linetarget->z + (linetarget->height >> 2), MT_EXTRABFG); - - damage = 0; - for (j = 0; j < 15; j++) - damage += (p_random() & 7) + 1; - - p_damage_mobj(linetarget, mo->target, mo->target, damage); - } -} - -/* a_bfg_sound */ - -void a_bfg_sound(player_t *player, pspdef_t *psp) -{ -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(player->mo, SFX_BFG); -#endif -} - -/* p_setup_psprites - * Called at start of level for each player. - */ - -void p_setup_psprites(player_t *player) -{ - int i; - - /* remove all psprites */ - - for (i = 0; i < NUMPSPRITES; i++) - player->psprites[i].state = NULL; - - /* spawn the gun */ - - player->pendingweapon = player->readyweapon; - p_bringup_weapon(player); -} - -/* p_move_psprites - * Called every tic by player thinking routine. - */ - -void p_move_psprites(player_t *player) -{ - int i; - pspdef_t *psp; - - psp = &player->psprites[0]; - for (i = 0; i < NUMPSPRITES; i++, psp++) - { - /* a null state means not active */ - - if (psp->state) - { - /* drop tic count and possibly change state */ - - /* a -1 tic count never changes */ - - if (psp->tics != -1) - { - psp->tics--; - if (!psp->tics) - { - p_set_psprite(player, i, psp->state->nextstate); - } - } - } - } - - player->psprites[ps_flash].sx = player->psprites[ps_weapon].sx; - player->psprites[ps_flash].sy = player->psprites[ps_weapon].sy; -} diff --git a/games/NXDoom/src/doom/p_pspr.h b/games/NXDoom/src/doom/p_pspr.h deleted file mode 100644 index 83ab57f6a..000000000 --- a/games/NXDoom/src/doom/p_pspr.h +++ /dev/null @@ -1,88 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/p_pspr.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Sprite animation. - * - ****************************************************************************/ - -#ifndef __P_PSPR__ -#define __P_PSPR__ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -/* Basic data types. - * Needs fixed point, and BAM angles. - */ - -#include "m_fixed.h" -#include "tables.h" - -/* Needs to include the precompiled sprite animation tables. - * - * Header generated by multigen utility. - * - * This includes all the data for thing animation, - * i.e. the Thing Attributes table and the Frame Sequence table. - */ - -#include "info.h" - -/* Frame flags: - * handles maximum brightness (torches, muzzle flare, light sources) - */ - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define FF_FULLBRIGHT 0x8000 /* flag in thing->frame */ -#define FF_FRAMEMASK 0x7fff - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -/* Overlay psprites are scaled shapes drawn directly on the view screen, - * coordinates are given for a 320*200 view screen. - */ - -typedef enum -{ - ps_weapon, - ps_flash, - NUMPSPRITES -} psprnum_t; - -typedef struct -{ - state_t *state; /* a NULL state means not active */ - int tics; - fixed_t sx; - fixed_t sy; -} pspdef_t; - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -extern fixed_t bulletslope; - -#endif /* __P_PSPR__ */ diff --git a/games/NXDoom/src/doom/p_saveg.c b/games/NXDoom/src/doom/p_saveg.c deleted file mode 100644 index 5c5439cb9..000000000 --- a/games/NXDoom/src/doom/p_saveg.c +++ /dev/null @@ -1,2129 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/p_saveg.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Archiving: SaveGame I/O. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -#include "deh_main.h" -#include "dstrings.h" -#include "i_system.h" -#include "p_local.h" -#include "p_saveg.h" -#include "z_zone.h" - -/* State. */ - -#include "doomstat.h" -#include "g_game.h" -#include "m_misc.h" -#include "r_state.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* Enum values are 32-bit integers. */ - -#define saveg_read_enum saveg_read32 -#define saveg_write_enum saveg_write32 - -/* think_t - * This is just an actionf_t. - */ - -#define saveg_read_think_t saveg_read_actionf_t -#define saveg_write_think_t saveg_write_actionf_t - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -enum -{ - tc_ceiling, - tc_door, - tc_floor, - tc_plat, - tc_flash, - tc_strobe, - tc_glow, - tc_endspecials -} specials_e; - -/* Thinkers */ - -typedef enum -{ - tc_end, - tc_mobj -} thinkerclass_t; - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -FILE *save_stream; -int savegamelength; -boolean savegame_error; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/* Endian-safe integer read/write functions */ - -static byte saveg_read8(void) -{ - byte result = -1; - - if (fread(&result, 1, 1, save_stream) < 1) - { - if (!savegame_error) - { - fprintf(stderr, "saveg_read8: Unexpected end of file while " - "reading save game\n"); - - savegame_error = true; - } - } - - return result; -} - -static void saveg_write8(byte value) -{ - if (fwrite(&value, 1, 1, save_stream) < 1) - { - if (!savegame_error) - { - fprintf(stderr, "saveg_write8: Error while writing save game\n"); - - savegame_error = true; - } - } -} - -static short saveg_read16(void) -{ - int result; - - result = saveg_read8(); - result |= saveg_read8() << 8; - - return result; -} - -static void saveg_write16(short value) -{ - saveg_write8(value & 0xff); - saveg_write8((value >> 8) & 0xff); -} - -static int saveg_read32(void) -{ - int result; - - result = saveg_read8(); - result |= saveg_read8() << 8; - result |= saveg_read8() << 16; - result |= saveg_read8() << 24; - - return result; -} - -static void saveg_write32(int value) -{ - saveg_write8(value & 0xff); - saveg_write8((value >> 8) & 0xff); - saveg_write8((value >> 16) & 0xff); - saveg_write8((value >> 24) & 0xff); -} - -/* Pad to 4-byte boundaries */ - -static void saveg_read_pad(void) -{ - unsigned long pos; - int padding; - int i; - - pos = ftell(save_stream); - - padding = (4 - (pos & 3)) & 3; - - for (i = 0; i < padding; ++i) - { - saveg_read8(); - } -} - -static void saveg_write_pad(void) -{ - unsigned long pos; - int padding; - int i; - - pos = ftell(save_stream); - - padding = (4 - (pos & 3)) & 3; - - for (i = 0; i < padding; ++i) - { - saveg_write8(0); - } -} - -/* Pointers */ - -static void *saveg_readp(void) -{ - return (void *)(intptr_t)saveg_read32(); -} - -static void saveg_writep(const void *p) -{ - saveg_write32((intptr_t)p); -} - -/* Structure read/write functions */ - -/* mapthing_t */ - -static void saveg_read_mapthing_t(mapthing_t *str) -{ - /* short x; */ - - str->x = saveg_read16(); - - /* short y; */ - - str->y = saveg_read16(); - - /* short angle; */ - - str->angle = saveg_read16(); - - /* short type; */ - - str->type = saveg_read16(); - - /* short options; */ - - str->options = saveg_read16(); -} - -static void saveg_write_mapthing_t(mapthing_t *str) -{ - /* short x; */ - - saveg_write16(str->x); - - /* short y; */ - - saveg_write16(str->y); - - /* short angle; */ - - saveg_write16(str->angle); - - /* short type; */ - - saveg_write16(str->type); - - /* short options; */ - - saveg_write16(str->options); -} - -/* actionf_t */ - -static void saveg_read_actionf_t(actionf_t *str) -{ - /* actionf_p1 acp1; */ - - str->acp1 = saveg_readp(); -} - -static void saveg_write_actionf_t(actionf_t *str) -{ - /* actionf_p1 acp1; */ - - saveg_writep(str->acp1); -} - -/* thinker_t */ - -static void saveg_read_thinker_t(thinker_t *str) -{ - /* struct thinker_s* prev; */ - - str->prev = saveg_readp(); - - /* struct thinker_s* next; */ - - str->next = saveg_readp(); - - /* think_t function; */ - - saveg_read_think_t(&str->function); -} - -static void saveg_write_thinker_t(thinker_t *str) -{ - /* struct thinker_s* prev; */ - - saveg_writep(str->prev); - - /* struct thinker_s* next; */ - - saveg_writep(str->next); - - /* think_t function; */ - - saveg_write_think_t(&str->function); -} - -/* mobj_t */ - -static void saveg_read_mobj_t(mobj_t *str) -{ - int pl; - - /* thinker_t thinker; */ - - saveg_read_thinker_t(&str->thinker); - - /* fixed_t x; */ - - str->x = saveg_read32(); - - /* fixed_t y; */ - - str->y = saveg_read32(); - - /* fixed_t z; */ - - str->z = saveg_read32(); - - /* struct mobj_s* snext; */ - - str->snext = saveg_readp(); - - /* struct mobj_s* sprev; */ - - str->sprev = saveg_readp(); - - /* angle_t angle; */ - - str->angle = saveg_read32(); - - /* spritenum_t sprite; */ - - str->sprite = saveg_read_enum(); - - /* int frame; */ - - str->frame = saveg_read32(); - - /* struct mobj_s* bnext; */ - - str->bnext = saveg_readp(); - - /* struct mobj_s* bprev; */ - - str->bprev = saveg_readp(); - - /* struct subsector_s* subsector; */ - - str->subsector = saveg_readp(); - - /* fixed_t floorz; */ - - str->floorz = saveg_read32(); - - /* fixed_t ceilingz; */ - - str->ceilingz = saveg_read32(); - - /* fixed_t radius; */ - - str->radius = saveg_read32(); - - /* fixed_t height; */ - - str->height = saveg_read32(); - - /* fixed_t momx; */ - - str->momx = saveg_read32(); - - /* fixed_t momy; */ - - str->momy = saveg_read32(); - - /* fixed_t momz; */ - - str->momz = saveg_read32(); - - /* int validcount; */ - - str->validcount = saveg_read32(); - - /* mobjtype_t type; */ - - str->type = saveg_read_enum(); - - /* mobjinfo_t* info; */ - - str->info = saveg_readp(); - - /* int tics; */ - - str->tics = saveg_read32(); - - /* state_t* state; */ - - str->state = &states[saveg_read32()]; - - /* int flags; */ - - str->flags = saveg_read32(); - - /* int health; */ - - str->health = saveg_read32(); - - /* int movedir; */ - - str->movedir = saveg_read32(); - - /* int movecount; */ - - str->movecount = saveg_read32(); - - /* struct mobj_s* target; */ - - str->target = saveg_readp(); - - /* int reactiontime; */ - - str->reactiontime = saveg_read32(); - - /* int threshold; */ - - str->threshold = saveg_read32(); - - /* struct player_s* player; */ - - pl = saveg_read32(); - - if (pl > 0) - { - str->player = &players[pl - 1]; - str->player->mo = str; - } - else - { - str->player = NULL; - } - - /* int lastlook; */ - - str->lastlook = saveg_read32(); - - /* mapthing_t spawnpoint; */ - - saveg_read_mapthing_t(&str->spawnpoint); - - /* struct mobj_s* tracer; */ - - str->tracer = saveg_readp(); -} - -static void saveg_write_mobj_t(mobj_t *str) -{ - /* thinker_t thinker; */ - - saveg_write_thinker_t(&str->thinker); - - /* fixed_t x; */ - - saveg_write32(str->x); - - /* fixed_t y; */ - - saveg_write32(str->y); - - /* fixed_t z; */ - - saveg_write32(str->z); - - /* struct mobj_s* snext; */ - - saveg_writep(str->snext); - - /* struct mobj_s* sprev; */ - - saveg_writep(str->sprev); - - /* angle_t angle; */ - - saveg_write32(str->angle); - - /* spritenum_t sprite; */ - - saveg_write_enum(str->sprite); - - /* int frame; */ - - saveg_write32(str->frame); - - /* struct mobj_s* bnext; */ - - saveg_writep(str->bnext); - - /* struct mobj_s* bprev; */ - - saveg_writep(str->bprev); - - /* struct subsector_s* subsector; */ - - saveg_writep(str->subsector); - - /* fixed_t floorz; */ - - saveg_write32(str->floorz); - - /* fixed_t ceilingz; */ - - saveg_write32(str->ceilingz); - - /* fixed_t radius; */ - - saveg_write32(str->radius); - - /* fixed_t height; */ - - saveg_write32(str->height); - - /* fixed_t momx; */ - - saveg_write32(str->momx); - - /* fixed_t momy; */ - - saveg_write32(str->momy); - - /* fixed_t momz; */ - - saveg_write32(str->momz); - - /* int validcount; */ - - saveg_write32(str->validcount); - - /* mobjtype_t type; */ - - saveg_write_enum(str->type); - - /* mobjinfo_t* info; */ - - saveg_writep(str->info); - - /* int tics; */ - - saveg_write32(str->tics); - - /* state_t* state; */ - - saveg_write32(str->state - states); - - /* int flags; */ - - saveg_write32(str->flags); - - /* int health; */ - - saveg_write32(str->health); - - /* int movedir; */ - - saveg_write32(str->movedir); - - /* int movecount; */ - - saveg_write32(str->movecount); - - /* struct mobj_s* target; */ - - saveg_writep(str->target); - - /* int reactiontime; */ - - saveg_write32(str->reactiontime); - - /* int threshold; */ - - saveg_write32(str->threshold); - - /* struct player_s* player; */ - - if (str->player) - { - saveg_write32(str->player - players + 1); - } - else - { - saveg_write32(0); - } - - /* int lastlook; */ - - saveg_write32(str->lastlook); - - /* mapthing_t spawnpoint; */ - - saveg_write_mapthing_t(&str->spawnpoint); - - /* struct mobj_s* tracer; */ - - saveg_writep(str->tracer); -} - -/* ticcmd_t */ - -static void saveg_read_ticcmd_t(ticcmd_t *str) -{ - /* signed char forwardmove; */ - - str->forwardmove = saveg_read8(); - - /* signed char sidemove; */ - - str->sidemove = saveg_read8(); - - /* short angleturn; */ - - str->angleturn = saveg_read16(); - - /* short consistency; */ - - str->consistency = saveg_read16(); - - /* byte chatchar; */ - - str->chatchar = saveg_read8(); - - /* byte buttons; */ - - str->buttons = saveg_read8(); -} - -static void saveg_write_ticcmd_t(ticcmd_t *str) -{ - /* signed char forwardmove; */ - - saveg_write8(str->forwardmove); - - /* signed char sidemove; */ - - saveg_write8(str->sidemove); - - /* short angleturn; */ - - saveg_write16(str->angleturn); - - /* short consistency; */ - - saveg_write16(str->consistency); - - /* byte chatchar; */ - - saveg_write8(str->chatchar); - - /* byte buttons; */ - - saveg_write8(str->buttons); -} - -/* pspdef_t */ - -static void saveg_read_pspdef_t(pspdef_t *str) -{ - int state; - - /* state_t* state; */ - - state = saveg_read32(); - - if (state > 0) - { - str->state = &states[state]; - } - else - { - str->state = NULL; - } - - /* int tics; */ - - str->tics = saveg_read32(); - - /* fixed_t sx; */ - - str->sx = saveg_read32(); - - /* fixed_t sy; */ - - str->sy = saveg_read32(); -} - -static void saveg_write_pspdef_t(pspdef_t *str) -{ - /* state_t* state; */ - - if (str->state) - { - saveg_write32(str->state - states); - } - else - { - saveg_write32(0); - } - - /* int tics; */ - - saveg_write32(str->tics); - - /* fixed_t sx; */ - - saveg_write32(str->sx); - - /* fixed_t sy; */ - - saveg_write32(str->sy); -} - -/* player_t */ - -static void saveg_read_player_t(player_t *str) -{ - int i; - - /* mobj_t* mo; */ - - str->mo = saveg_readp(); - - /* playerstate_t playerstate; */ - - str->playerstate = saveg_read_enum(); - - /* ticcmd_t cmd; */ - - saveg_read_ticcmd_t(&str->cmd); - - /* fixed_t viewz; */ - - str->viewz = saveg_read32(); - - /* fixed_t viewheight; */ - - str->viewheight = saveg_read32(); - - /* fixed_t deltaviewheight; */ - - str->deltaviewheight = saveg_read32(); - - /* fixed_t bob; */ - - str->bob = saveg_read32(); - - /* int health; */ - - str->health = saveg_read32(); - - /* int armorpoints; */ - - str->armorpoints = saveg_read32(); - - /* int armortype; */ - - str->armortype = saveg_read32(); - - /* int powers[NUMPOWERS]; */ - - for (i = 0; i < NUMPOWERS; ++i) - { - str->powers[i] = saveg_read32(); - } - - /* boolean cards[NUMCARDS]; */ - - for (i = 0; i < NUMCARDS; ++i) - { - str->cards[i] = saveg_read32(); - } - - /* boolean backpack; */ - - str->backpack = saveg_read32(); - - /* int frags[MAXPLAYERS]; */ - - for (i = 0; i < MAXPLAYERS; ++i) - { - str->frags[i] = saveg_read32(); - } - - /* weapontype_t readyweapon; */ - - str->readyweapon = saveg_read_enum(); - - /* weapontype_t pendingweapon; */ - - str->pendingweapon = saveg_read_enum(); - - /* boolean weaponowned[NUMWEAPONS]; */ - - for (i = 0; i < NUMWEAPONS; ++i) - { - str->weaponowned[i] = saveg_read32(); - } - - /* int ammo[NUMAMMO]; */ - - for (i = 0; i < NUMAMMO; ++i) - { - str->ammo[i] = saveg_read32(); - } - - /* int maxammo[NUMAMMO]; */ - - for (i = 0; i < NUMAMMO; ++i) - { - str->maxammo[i] = saveg_read32(); - } - - /* int attackdown; */ - - str->attackdown = saveg_read32(); - - /* int usedown; */ - - str->usedown = saveg_read32(); - - /* int cheats; */ - - str->cheats = saveg_read32(); - - /* int refire; */ - - str->refire = saveg_read32(); - - /* int killcount; */ - - str->killcount = saveg_read32(); - - /* int itemcount; */ - - str->itemcount = saveg_read32(); - - /* int secretcount; */ - - str->secretcount = saveg_read32(); - - /* char* message; */ - - str->message = saveg_readp(); - - /* int damagecount; */ - - str->damagecount = saveg_read32(); - - /* int bonuscount; */ - - str->bonuscount = saveg_read32(); - - /* mobj_t* attacker; */ - - str->attacker = saveg_readp(); - - /* int extralight; */ - - str->extralight = saveg_read32(); - - /* int fixedcolormap; */ - - str->fixedcolormap = saveg_read32(); - - /* int colormap; */ - - str->colormap = saveg_read32(); - - /* pspdef_t psprites[NUMPSPRITES]; */ - - for (i = 0; i < NUMPSPRITES; ++i) - { - saveg_read_pspdef_t(&str->psprites[i]); - } - - /* boolean didsecret; */ - - str->didsecret = saveg_read32(); -} - -static void saveg_write_player_t(player_t *str) -{ - int i; - - /* mobj_t* mo; */ - - saveg_writep(str->mo); - - /* playerstate_t playerstate; */ - - saveg_write_enum(str->playerstate); - - /* ticcmd_t cmd; */ - - saveg_write_ticcmd_t(&str->cmd); - - /* fixed_t viewz; */ - - saveg_write32(str->viewz); - - /* fixed_t viewheight; */ - - saveg_write32(str->viewheight); - - /* fixed_t deltaviewheight; */ - - saveg_write32(str->deltaviewheight); - - /* fixed_t bob; */ - - saveg_write32(str->bob); - - /* int health; */ - - saveg_write32(str->health); - - /* int armorpoints; */ - - saveg_write32(str->armorpoints); - - /* int armortype; */ - - saveg_write32(str->armortype); - - /* int powers[NUMPOWERS]; */ - - for (i = 0; i < NUMPOWERS; ++i) - { - saveg_write32(str->powers[i]); - } - - /* boolean cards[NUMCARDS]; */ - - for (i = 0; i < NUMCARDS; ++i) - { - saveg_write32(str->cards[i]); - } - - /* boolean backpack; */ - - saveg_write32(str->backpack); - - /* int frags[MAXPLAYERS]; */ - - for (i = 0; i < MAXPLAYERS; ++i) - { - saveg_write32(str->frags[i]); - } - - /* weapontype_t readyweapon; */ - - saveg_write_enum(str->readyweapon); - - /* weapontype_t pendingweapon; */ - - saveg_write_enum(str->pendingweapon); - - /* boolean weaponowned[NUMWEAPONS]; */ - - for (i = 0; i < NUMWEAPONS; ++i) - { - saveg_write32(str->weaponowned[i]); - } - - /* int ammo[NUMAMMO]; */ - - for (i = 0; i < NUMAMMO; ++i) - { - saveg_write32(str->ammo[i]); - } - - /* int maxammo[NUMAMMO]; */ - - for (i = 0; i < NUMAMMO; ++i) - { - saveg_write32(str->maxammo[i]); - } - - /* int attackdown; */ - - saveg_write32(str->attackdown); - - /* int usedown; */ - - saveg_write32(str->usedown); - - /* int cheats; */ - - saveg_write32(str->cheats); - - /* int refire; */ - - saveg_write32(str->refire); - - /* int killcount; */ - - saveg_write32(str->killcount); - - /* int itemcount; */ - - saveg_write32(str->itemcount); - - /* int secretcount; */ - - saveg_write32(str->secretcount); - - /* char* message; */ - - saveg_writep(str->message); - - /* int damagecount; */ - - saveg_write32(str->damagecount); - - /* int bonuscount; */ - - saveg_write32(str->bonuscount); - - /* mobj_t* attacker; */ - - saveg_writep(str->attacker); - - /* int extralight; */ - - saveg_write32(str->extralight); - - /* int fixedcolormap; */ - - saveg_write32(str->fixedcolormap); - - /* int colormap; */ - - saveg_write32(str->colormap); - - /* pspdef_t psprites[NUMPSPRITES]; */ - - for (i = 0; i < NUMPSPRITES; ++i) - { - saveg_write_pspdef_t(&str->psprites[i]); - } - - /* boolean didsecret; */ - - saveg_write32(str->didsecret); -} - -/* ceiling_t */ - -static void saveg_read_ceiling_t(ceiling_t *str) -{ - int sector; - - /* thinker_t thinker; */ - - saveg_read_thinker_t(&str->thinker); - - /* ceiling_e type; */ - - str->type = saveg_read_enum(); - - /* sector_t* sector; */ - - sector = saveg_read32(); - str->sector = §ors[sector]; - - /* fixed_t bottomheight; */ - - str->bottomheight = saveg_read32(); - - /* fixed_t topheight; */ - - str->topheight = saveg_read32(); - - /* fixed_t speed; */ - - str->speed = saveg_read32(); - - /* boolean crush; */ - - str->crush = saveg_read32(); - - /* int direction; */ - - str->direction = saveg_read32(); - - /* int tag; */ - - str->tag = saveg_read32(); - - /* int olddirection; */ - - str->olddirection = saveg_read32(); -} - -static void saveg_write_ceiling_t(ceiling_t *str) -{ - /* thinker_t thinker; */ - - saveg_write_thinker_t(&str->thinker); - - /* ceiling_e type; */ - - saveg_write_enum(str->type); - - /* sector_t* sector; */ - - saveg_write32(str->sector - sectors); - - /* fixed_t bottomheight; */ - - saveg_write32(str->bottomheight); - - /* fixed_t topheight; */ - - saveg_write32(str->topheight); - - /* fixed_t speed; */ - - saveg_write32(str->speed); - - /* boolean crush; */ - - saveg_write32(str->crush); - - /* int direction; */ - - saveg_write32(str->direction); - - /* int tag; */ - - saveg_write32(str->tag); - - /* int olddirection; */ - - saveg_write32(str->olddirection); -} - -/* vldoor_t */ - -static void saveg_read_vldoor_t(vldoor_t *str) -{ - int sector; - - /* thinker_t thinker; */ - - saveg_read_thinker_t(&str->thinker); - - /* vldoor_e type; */ - - str->type = saveg_read_enum(); - - /* sector_t* sector; */ - - sector = saveg_read32(); - str->sector = §ors[sector]; - - /* fixed_t topheight; */ - - str->topheight = saveg_read32(); - - /* fixed_t speed; */ - - str->speed = saveg_read32(); - - /* int direction; */ - - str->direction = saveg_read32(); - - /* int topwait; */ - - str->topwait = saveg_read32(); - - /* int topcountdown; */ - - str->topcountdown = saveg_read32(); -} - -static void saveg_write_vldoor_t(vldoor_t *str) -{ - /* thinker_t thinker; */ - - saveg_write_thinker_t(&str->thinker); - - /* vldoor_e type; */ - - saveg_write_enum(str->type); - - /* sector_t* sector; */ - - saveg_write32(str->sector - sectors); - - /* fixed_t topheight; */ - - saveg_write32(str->topheight); - - /* fixed_t speed; */ - - saveg_write32(str->speed); - - /* int direction; */ - - saveg_write32(str->direction); - - /* int topwait; */ - - saveg_write32(str->topwait); - - /* int topcountdown; */ - - saveg_write32(str->topcountdown); -} - -/* floormove_t */ - -static void saveg_read_floormove_t(floormove_t *str) -{ - int sector; - - /* thinker_t thinker; */ - - saveg_read_thinker_t(&str->thinker); - - /* floor_e type; */ - - str->type = saveg_read_enum(); - - /* boolean crush; */ - - str->crush = saveg_read32(); - - /* sector_t* sector; */ - - sector = saveg_read32(); - str->sector = §ors[sector]; - - /* int direction; */ - - str->direction = saveg_read32(); - - /* int newspecial; */ - - str->newspecial = saveg_read32(); - - /* short texture; */ - - str->texture = saveg_read16(); - - /* fixed_t floordestheight; */ - - str->floordestheight = saveg_read32(); - - /* fixed_t speed; */ - - str->speed = saveg_read32(); -} - -static void saveg_write_floormove_t(floormove_t *str) -{ - /* thinker_t thinker; */ - - saveg_write_thinker_t(&str->thinker); - - /* floor_e type; */ - - saveg_write_enum(str->type); - - /* boolean crush; */ - - saveg_write32(str->crush); - - /* sector_t* sector; */ - - saveg_write32(str->sector - sectors); - - /* int direction; */ - - saveg_write32(str->direction); - - /* int newspecial; */ - - saveg_write32(str->newspecial); - - /* short texture; */ - - saveg_write16(str->texture); - - /* fixed_t floordestheight; */ - - saveg_write32(str->floordestheight); - - /* fixed_t speed; */ - - saveg_write32(str->speed); -} - -/* plat_t */ - -static void saveg_read_plat_t(plat_t *str) -{ - int sector; - - /* thinker_t thinker; */ - - saveg_read_thinker_t(&str->thinker); - - /* sector_t* sector; */ - - sector = saveg_read32(); - str->sector = §ors[sector]; - - /* fixed_t speed; */ - - str->speed = saveg_read32(); - - /* fixed_t low; */ - - str->low = saveg_read32(); - - /* fixed_t high; */ - - str->high = saveg_read32(); - - /* int wait; */ - - str->wait = saveg_read32(); - - /* int count; */ - - str->count = saveg_read32(); - - /* plat_e status; */ - - str->status = saveg_read_enum(); - - /* plat_e oldstatus; */ - - str->oldstatus = saveg_read_enum(); - - /* boolean crush; */ - - str->crush = saveg_read32(); - - /* int tag; */ - - str->tag = saveg_read32(); - - /* plattype_e type; */ - - str->type = saveg_read_enum(); -} - -static void saveg_write_plat_t(plat_t *str) -{ - /* thinker_t thinker; */ - - saveg_write_thinker_t(&str->thinker); - - /* sector_t* sector; */ - - saveg_write32(str->sector - sectors); - - /* fixed_t speed; */ - - saveg_write32(str->speed); - - /* fixed_t low; */ - - saveg_write32(str->low); - - /* fixed_t high; */ - - saveg_write32(str->high); - - /* int wait; */ - - saveg_write32(str->wait); - - /* int count; */ - - saveg_write32(str->count); - - /* plat_e status; */ - - saveg_write_enum(str->status); - - /* plat_e oldstatus; */ - - saveg_write_enum(str->oldstatus); - - /* boolean crush; */ - - saveg_write32(str->crush); - - /* int tag; */ - - saveg_write32(str->tag); - - /* plattype_e type; */ - - saveg_write_enum(str->type); -} - -/* lightflash_t */ - -static void saveg_read_lightflash_t(lightflash_t *str) -{ - int sector; - - /* thinker_t thinker; */ - - saveg_read_thinker_t(&str->thinker); - - /* sector_t* sector; */ - - sector = saveg_read32(); - str->sector = §ors[sector]; - - /* int count; */ - - str->count = saveg_read32(); - - /* int maxlight; */ - - str->maxlight = saveg_read32(); - - /* int minlight; */ - - str->minlight = saveg_read32(); - - /* int maxtime; */ - - str->maxtime = saveg_read32(); - - /* int mintime; */ - - str->mintime = saveg_read32(); -} - -static void saveg_write_lightflash_t(lightflash_t *str) -{ - /* thinker_t thinker; */ - - saveg_write_thinker_t(&str->thinker); - - /* sector_t* sector; */ - - saveg_write32(str->sector - sectors); - - /* int count; */ - - saveg_write32(str->count); - - /* int maxlight; */ - - saveg_write32(str->maxlight); - - /* int minlight; */ - - saveg_write32(str->minlight); - - /* int maxtime; */ - - saveg_write32(str->maxtime); - - /* int mintime; */ - - saveg_write32(str->mintime); -} - -/* strobe_t */ - -static void saveg_read_strobe_t(strobe_t *str) -{ - int sector; - - /* thinker_t thinker; */ - - saveg_read_thinker_t(&str->thinker); - - /* sector_t* sector; */ - - sector = saveg_read32(); - str->sector = §ors[sector]; - - /* int count; */ - - str->count = saveg_read32(); - - /* int minlight; */ - - str->minlight = saveg_read32(); - - /* int maxlight; */ - - str->maxlight = saveg_read32(); - - /* int darktime; */ - - str->darktime = saveg_read32(); - - /* int brighttime; */ - - str->brighttime = saveg_read32(); -} - -static void saveg_write_strobe_t(strobe_t *str) -{ - /* thinker_t thinker; */ - - saveg_write_thinker_t(&str->thinker); - - /* sector_t* sector; */ - - saveg_write32(str->sector - sectors); - - /* int count; */ - - saveg_write32(str->count); - - /* int minlight; */ - - saveg_write32(str->minlight); - - /* int maxlight; */ - - saveg_write32(str->maxlight); - - /* int darktime; */ - - saveg_write32(str->darktime); - - /* int brighttime; */ - - saveg_write32(str->brighttime); -} - -/* glow_t */ - -static void saveg_read_glow_t(glow_t *str) -{ - int sector; - - /* thinker_t thinker; */ - - saveg_read_thinker_t(&str->thinker); - - /* sector_t* sector; */ - - sector = saveg_read32(); - str->sector = §ors[sector]; - - /* int minlight; */ - - str->minlight = saveg_read32(); - - /* int maxlight; */ - - str->maxlight = saveg_read32(); - - /* int direction; */ - - str->direction = saveg_read32(); -} - -static void saveg_write_glow_t(glow_t *str) -{ - /* thinker_t thinker; */ - - saveg_write_thinker_t(&str->thinker); - - /* sector_t* sector; */ - - saveg_write32(str->sector - sectors); - - /* int minlight; */ - - saveg_write32(str->minlight); - - /* int maxlight; */ - - saveg_write32(str->maxlight); - - /* int direction; */ - - saveg_write32(str->direction); -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/* Write the header for a savegame */ - -void p_write_save_game_header(char *description) -{ - char name[VERSIONSIZE]; - int i; - - for (i = 0; description[i] != '\0'; ++i) - saveg_write8(description[i]); - for (; i < SAVESTRINGSIZE; ++i) - saveg_write8(0); - - memset(name, 0, sizeof(name)); - snprintf(name, sizeof(name), "version %i", g_vanilla_version_code()); - - for (i = 0; i < VERSIONSIZE; ++i) - saveg_write8(name[i]); - - saveg_write8(gameskill); - saveg_write8(gameepisode); - saveg_write8(gamemap); - - for (i = 0; i < MAXPLAYERS; i++) - saveg_write8(playeringame[i]); - - saveg_write8((leveltime >> 16) & 0xff); - saveg_write8((leveltime >> 8) & 0xff); - saveg_write8(leveltime & 0xff); -} - -/* Get the filename of a temporary file to write the savegame to. After - * the file has been successfully saved, it will be renamed to the - * real file. - */ - -char *p_temp_save_game_file(void) -{ - static char *filename = NULL; - - if (filename == NULL) - { - filename = m_string_join(savegamedir, "temp.dsg", NULL); - } - - return filename; -} - -/* Get the filename of the save game file to use for the specified slot. */ - -char *p_save_game_file(int slot) -{ - static char *filename = NULL; - static size_t filename_size = 0; - char basename[32]; - - if (filename == NULL) - { - filename_size = strlen(savegamedir) + 32; - filename = malloc(filename_size); - } - - snprintf(basename, 32, SAVEGAMENAME "%d.dsg", slot); - snprintf(filename, filename_size, "%s%s", savegamedir, basename); - - return filename; -} - -/* Read the header for a savegame */ - -boolean p_read_save_game_header(void) -{ - int i; - byte a, b, c; - char vcheck[VERSIONSIZE]; - char read_vcheck[VERSIONSIZE]; - - /* skip the description field */ - - for (i = 0; i < SAVESTRINGSIZE; ++i) - saveg_read8(); - - for (i = 0; i < VERSIONSIZE; ++i) - read_vcheck[i] = saveg_read8(); - - memset(vcheck, 0, sizeof(vcheck)); - snprintf(vcheck, sizeof(vcheck), "version %i", g_vanilla_version_code()); - if (strcmp(read_vcheck, vcheck) != 0) return false; /* bad version */ - - gameskill = saveg_read8(); - gameepisode = saveg_read8(); - gamemap = saveg_read8(); - - for (i = 0; i < MAXPLAYERS; i++) - playeringame[i] = saveg_read8(); - - /* get the times */ - - a = saveg_read8(); - b = saveg_read8(); - c = saveg_read8(); - leveltime = (a << 16) + (b << 8) + c; - - return true; -} - -/* Read the end of file marker. Returns true if read successfully. */ - -boolean p_read_save_game_eof(void) -{ - int value; - - value = saveg_read8(); - - return value == SAVEGAME_EOF; -} - -/* Write the end of file marker */ - -void p_write_save_game_eof(void) -{ - saveg_write8(SAVEGAME_EOF); -} - -void p_archive_players(void) -{ - int i; - - for (i = 0; i < MAXPLAYERS; i++) - { - if (!playeringame[i]) continue; - - saveg_write_pad(); - - saveg_write_player_t(&players[i]); - } -} - -void p_unarchive_players(void) -{ - int i; - - for (i = 0; i < MAXPLAYERS; i++) - { - if (!playeringame[i]) continue; - - saveg_read_pad(); - - saveg_read_player_t(&players[i]); - - /* will be set when unarc thinker */ - - players[i].mo = NULL; - players[i].message = NULL; - players[i].attacker = NULL; - } -} - -void p_archive_world(void) -{ - int i; - int j; - sector_t *sec; - line_t *li; - side_t *si; - - /* do sectors */ - - for (i = 0, sec = sectors; i < numsectors; i++, sec++) - { - saveg_write16(sec->floorheight >> FRACBITS); - saveg_write16(sec->ceilingheight >> FRACBITS); - saveg_write16(sec->floorpic); - saveg_write16(sec->ceilingpic); - saveg_write16(sec->lightlevel); - saveg_write16(sec->special); /* needed? */ - - saveg_write16(sec->tag); /* needed? */ - } - - /* do lines */ - - for (i = 0, li = lines; i < numlines; i++, li++) - { - saveg_write16(li->flags); - saveg_write16(li->special); - saveg_write16(li->tag); - for (j = 0; j < 2; j++) - { - if (li->sidenum[j] == -1) continue; - - si = &sides[li->sidenum[j]]; - - saveg_write16(si->textureoffset >> FRACBITS); - saveg_write16(si->rowoffset >> FRACBITS); - saveg_write16(si->toptexture); - saveg_write16(si->bottomtexture); - saveg_write16(si->midtexture); - } - } -} - -void p_unarchive_world(void) -{ - int i; - int j; - sector_t *sec; - line_t *li; - side_t *si; - - /* do sectors */ - - for (i = 0, sec = sectors; i < numsectors; i++, sec++) - { - sec->floorheight = saveg_read16() << FRACBITS; - sec->ceilingheight = saveg_read16() << FRACBITS; - sec->floorpic = saveg_read16(); - sec->ceilingpic = saveg_read16(); - sec->lightlevel = saveg_read16(); - sec->special = saveg_read16(); /* needed? */ - - sec->tag = saveg_read16(); /* needed? */ - - sec->specialdata = 0; - sec->soundtarget = 0; - } - - /* do lines */ - - for (i = 0, li = lines; i < numlines; i++, li++) - { - li->flags = saveg_read16(); - li->special = saveg_read16(); - li->tag = saveg_read16(); - for (j = 0; j < 2; j++) - { - if (li->sidenum[j] == -1) continue; - si = &sides[li->sidenum[j]]; - si->textureoffset = saveg_read16() << FRACBITS; - si->rowoffset = saveg_read16() << FRACBITS; - si->toptexture = saveg_read16(); - si->bottomtexture = saveg_read16(); - si->midtexture = saveg_read16(); - } - } -} - -void p_archive_thinkers(void) -{ - thinker_t *th; - - /* save off the current thinkers */ - - for (th = thinkercap.next; th != &thinkercap; th = th->next) - { - if (th->function.acp1 == (actionf_p1)p_mobj_thinker) - { - saveg_write8(tc_mobj); - saveg_write_pad(); - saveg_write_mobj_t((mobj_t *)th); - - continue; - } - } - - /* add a terminating marker */ - - saveg_write8(tc_end); -} - -void p_unarchive_thinkers(void) -{ - byte tclass; - thinker_t *currentthinker; - thinker_t *next; - mobj_t *mobj; - - /* remove all the current thinkers */ - - currentthinker = thinkercap.next; - while (currentthinker != &thinkercap) - { - next = currentthinker->next; - - if (currentthinker->function.acp1 == (actionf_p1)p_mobj_thinker) - p_remove_mobj((mobj_t *)currentthinker); - else - z_free(currentthinker); - - currentthinker = next; - } - - p_init_thinkers(); - - /* read in saved thinkers */ - - while (1) - { - tclass = saveg_read8(); - switch (tclass) - { - case tc_end: - return; /* end of list */ - - case tc_mobj: - saveg_read_pad(); - mobj = z_malloc(sizeof(*mobj), PU_LEVEL, NULL); - saveg_read_mobj_t(mobj); - - mobj->target = NULL; - mobj->tracer = NULL; - p_set_thing_position(mobj); - mobj->info = &mobjinfo[mobj->type]; - mobj->floorz = mobj->subsector->sector->floorheight; - mobj->ceilingz = mobj->subsector->sector->ceilingheight; - mobj->thinker.function.acp1 = (actionf_p1)p_mobj_thinker; - p_add_thinker(&mobj->thinker); - break; - - default: - i_error("Unknown tclass %i in savegame", tclass); - } - } -} - -/* Things to handle: - * - * t_move_ceiling, (ceiling_t: sector_t * swizzle), - active list - * t_vertical_door, (vldoor_t: sector_t * swizzle), - * t_move_floor, (floormove_t: sector_t * swizzle), - * t_light_flash, (lightflash_t: sector_t * swizzle), - * t_strobe_flash, (strobe_t: sector_t *), - * t_glow, (glow_t: sector_t *), - * t_plat_raise, (plat_t: sector_t *), - active list - */ - -void p_archive_specials(void) -{ - thinker_t *th; - int i; - - /* save off the current thinkers */ - - for (th = thinkercap.next; th != &thinkercap; th = th->next) - { - if (th->function.acv == (actionf_v)NULL) - { - for (i = 0; i < MAXCEILINGS; i++) - { - if (activeceilings[i] == (ceiling_t *)th) break; - } - - if (i < MAXCEILINGS) - { - saveg_write8(tc_ceiling); - saveg_write_pad(); - saveg_write_ceiling_t((ceiling_t *)th); - } - - continue; - } - - if (th->function.acp1 == (actionf_p1)t_move_ceiling) - { - saveg_write8(tc_ceiling); - saveg_write_pad(); - saveg_write_ceiling_t((ceiling_t *)th); - continue; - } - - if (th->function.acp1 == (actionf_p1)t_vertical_door) - { - saveg_write8(tc_door); - saveg_write_pad(); - saveg_write_vldoor_t((vldoor_t *)th); - continue; - } - - if (th->function.acp1 == (actionf_p1)t_move_floor) - { - saveg_write8(tc_floor); - saveg_write_pad(); - saveg_write_floormove_t((floormove_t *)th); - continue; - } - - if (th->function.acp1 == (actionf_p1)t_plat_raise) - { - saveg_write8(tc_plat); - saveg_write_pad(); - saveg_write_plat_t((plat_t *)th); - continue; - } - - if (th->function.acp1 == (actionf_p1)t_light_flash) - { - saveg_write8(tc_flash); - saveg_write_pad(); - saveg_write_lightflash_t((lightflash_t *)th); - continue; - } - - if (th->function.acp1 == (actionf_p1)t_strobe_flash) - { - saveg_write8(tc_strobe); - saveg_write_pad(); - saveg_write_strobe_t((strobe_t *)th); - continue; - } - - if (th->function.acp1 == (actionf_p1)t_glow) - { - saveg_write8(tc_glow); - saveg_write_pad(); - saveg_write_glow_t((glow_t *)th); - continue; - } - } - - /* add a terminating marker */ - - saveg_write8(tc_endspecials); -} - -void p_unarchive_specials(void) -{ - byte tclass; - ceiling_t *ceiling; - vldoor_t *door; - floormove_t *floor; - plat_t *plat; - lightflash_t *flash; - strobe_t *strobe; - glow_t *glow; - - /* read in saved thinkers */ - - while (1) - { - tclass = saveg_read8(); - - switch (tclass) - { - case tc_endspecials: - return; /* end of list */ - - case tc_ceiling: - saveg_read_pad(); - ceiling = z_malloc(sizeof(*ceiling), PU_LEVEL, NULL); - saveg_read_ceiling_t(ceiling); - ceiling->sector->specialdata = ceiling; - - if (ceiling->thinker.function.acp1) - ceiling->thinker.function.acp1 = (actionf_p1)t_move_ceiling; - - p_add_thinker(&ceiling->thinker); - p_add_active_ceiling(ceiling); - break; - - case tc_door: - saveg_read_pad(); - door = z_malloc(sizeof(*door), PU_LEVEL, NULL); - saveg_read_vldoor_t(door); - door->sector->specialdata = door; - door->thinker.function.acp1 = (actionf_p1)t_vertical_door; - p_add_thinker(&door->thinker); - break; - - case tc_floor: - saveg_read_pad(); - floor = z_malloc(sizeof(*floor), PU_LEVEL, NULL); - saveg_read_floormove_t(floor); - floor->sector->specialdata = floor; - floor->thinker.function.acp1 = (actionf_p1)t_move_floor; - p_add_thinker(&floor->thinker); - break; - - case tc_plat: - saveg_read_pad(); - plat = z_malloc(sizeof(*plat), PU_LEVEL, NULL); - saveg_read_plat_t(plat); - plat->sector->specialdata = plat; - - if (plat->thinker.function.acp1) - plat->thinker.function.acp1 = (actionf_p1)t_plat_raise; - - p_add_thinker(&plat->thinker); - p_add_active_plat(plat); - break; - - case tc_flash: - saveg_read_pad(); - flash = z_malloc(sizeof(*flash), PU_LEVEL, NULL); - saveg_read_lightflash_t(flash); - flash->thinker.function.acp1 = (actionf_p1)t_light_flash; - p_add_thinker(&flash->thinker); - break; - - case tc_strobe: - saveg_read_pad(); - strobe = z_malloc(sizeof(*strobe), PU_LEVEL, NULL); - saveg_read_strobe_t(strobe); - strobe->thinker.function.acp1 = (actionf_p1)t_strobe_flash; - p_add_thinker(&strobe->thinker); - break; - - case tc_glow: - saveg_read_pad(); - glow = z_malloc(sizeof(*glow), PU_LEVEL, NULL); - saveg_read_glow_t(glow); - glow->thinker.function.acp1 = (actionf_p1)t_glow; - p_add_thinker(&glow->thinker); - break; - - default: - i_error("P_UnarchiveSpecials:Unknown tclass %i " - "in savegame", - tclass); - } - } -} diff --git a/games/NXDoom/src/doom/p_saveg.h b/games/NXDoom/src/doom/p_saveg.h deleted file mode 100644 index 8c27b6dc7..000000000 --- a/games/NXDoom/src/doom/p_saveg.h +++ /dev/null @@ -1,86 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/p_saveg.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Savegame I/O, archiving, persistence. - * - ****************************************************************************/ - -#ifndef __P_SAVEG__ -#define __P_SAVEG__ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define SAVEGAME_EOF 0x1d -#define VERSIONSIZE 16 - -/* maximum size of a savegame description */ - -#define SAVESTRINGSIZE 24 - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -extern FILE *save_stream; -extern boolean savegame_error; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/* temporary filename to use while saving. */ - -char *p_temp_save_game_file(void); - -/* filename to use for a savegame slot */ - -char *p_save_game_file(int slot); - -/* Savegame file header read/write functions */ - -boolean p_read_save_game_header(void); -void p_write_save_game_header(char *description); - -/* Savegame end-of-file read/write functions */ - -boolean p_read_save_game_eof(void); -void p_write_save_game_eof(void); - -/* Persistent storage/archiving. - * These are the load / save game routines. - */ - -void p_archive_players(void); -void p_unarchive_players(void); -void p_archive_world(void); -void p_unarchive_world(void); -void p_archive_thinkers(void); -void p_unarchive_thinkers(void); -void p_archive_specials(void); -void p_unarchive_specials(void); - -#endif /* __P_SAVEG__ */ diff --git a/games/NXDoom/src/doom/p_setup.c b/games/NXDoom/src/doom/p_setup.c deleted file mode 100644 index 3dc608abf..000000000 --- a/games/NXDoom/src/doom/p_setup.c +++ /dev/null @@ -1,834 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/p_setup.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Do all the WAD I/O, get map description, set up initial state and misc. - * LUTs. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -#include "z_zone.h" - -#include "deh_main.h" -#include "i_swap.h" -#include "m_argv.h" -#include "m_bbox.h" - -#include "g_game.h" - -#include "i_system.h" -#include "w_wad.h" - -#include "doomdef.h" -#include "p_local.h" -#include "p_rejectpad.h" - -#ifdef CONFIG_GAMES_NXDOOM_SOUND -#include "s_sound.h" -#endif - -#include "doomstat.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* Maintain single and multi player starting spots. */ - -#define MAX_DEATHMATCH_STARTS 10 - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -void p_spawn_map_thing(mapthing_t *mthing); - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static int totallines; - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/* MAP related Lookup tables. - * Store VERTICES, LINEDEFS, SIDEDEFS, etc. - */ - -int numvertices; -vertex_t *vertices; - -int numsegs; -seg_t *segs; - -int numsectors; -sector_t *sectors; - -int numsubsectors; -subsector_t *subsectors; - -int numnodes; -node_t *nodes; - -int numlines; -line_t *lines; - -int numsides; -side_t *sides; - -/* BLOCKMAP - * Created from axis aligned bounding box - * of the map, a rectangular array of - * blocks of size ... - * Used to speed up collision detection - * by spatial subdivision in 2D. - */ - -/* Blockmap size. */ - -int bmapwidth; -int bmapheight; /* size in mapblocks */ -short *blockmap; /* int for larger maps */ - -/* offsets in blockmap are from here */ - -short *blockmaplump; - -/* origin of block map */ - -fixed_t bmaporgx; -fixed_t bmaporgy; - -/* for thing chains */ - -mobj_t **blocklinks; - -/* REJECT - * For fast sight rejection. - * Speeds up enemy AI by skipping detailed LineOf Sight calculation. - * Without special effect, this could be used as a PVS lookup as well. - */ - -byte *rejectmatrix; - -mapthing_t deathmatchstarts[MAX_DEATHMATCH_STARTS]; -mapthing_t *deathmatch_p; -mapthing_t playerstarts[MAXPLAYERS]; -boolean playerstartsingame[MAXPLAYERS]; - -/* pointer to the current map lump info struct */ - -lumpinfo_t *maplumpinfo; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static void p_load_vertices(int lump) -{ - byte *data; - int i; - mapvertex_t *ml; - vertex_t *li; - - /* Determine number of lumps: total lump length / vertex record length. */ - - numvertices = w_lump_length(lump) / sizeof(mapvertex_t); - - /* Allocate zone memory for buffer. */ - - vertices = z_malloc(numvertices * sizeof(vertex_t), PU_LEVEL, 0); - - /* Load data into cache. */ - - data = w_cache_lump_num(lump, PU_STATIC); - - ml = (mapvertex_t *)data; - li = vertices; - - /* Copy and convert vertex coordinates, internal representation as fixed. */ - - for (i = 0; i < numvertices; i++, li++, ml++) - { - li->x = SHORT(ml->x) << FRACBITS; - li->y = SHORT(ml->y) << FRACBITS; - } - - /* Free buffer memory. */ - - w_release_lump_num(lump); -} - -static sector_t *get_sector_at_null_address(void) -{ - static boolean null_sector_is_initialized = false; - static sector_t null_sector; - - if (!null_sector_is_initialized) - { - memset(&null_sector, 0, sizeof(null_sector)); - i_get_memory_value(0, &null_sector.floorheight, 4); - i_get_memory_value(4, &null_sector.ceilingheight, 4); - null_sector_is_initialized = true; - } - - return &null_sector; -} - -static void p_load_segs(int lump) -{ - byte *data; - int i; - mapseg_t *ml; - seg_t *li; - line_t *ldef; - int linedef_int; - int side; - int sidenum; - - numsegs = w_lump_length(lump) / sizeof(mapseg_t); - segs = z_malloc(numsegs * sizeof(seg_t), PU_LEVEL, 0); - memset(segs, 0, numsegs * sizeof(seg_t)); - data = w_cache_lump_num(lump, PU_STATIC); - - ml = (mapseg_t *)data; - li = segs; - for (i = 0; i < numsegs; i++, li++, ml++) - { - li->v1 = &vertices[SHORT(ml->v1)]; - li->v2 = &vertices[SHORT(ml->v2)]; - - li->angle = (SHORT(ml->angle)) << FRACBITS; - li->offset = (SHORT(ml->offset)) << FRACBITS; - linedef_int = SHORT(ml->linedef); - ldef = &lines[linedef_int]; - li->linedef = ldef; - side = SHORT(ml->side); - - /* e6y: check for wrong indexes */ - - if ((unsigned)ldef->sidenum[side] >= (unsigned)numsides) - { - i_error("p_load_segs: linedef %d for seg %d references a " - "non-existent sidedef %d", - linedef_int, i, (unsigned)ldef->sidenum[side]); - } - - li->sidedef = &sides[ldef->sidenum[side]]; - li->frontsector = sides[ldef->sidenum[side]].sector; - - if (ldef->flags & ML_TWOSIDED) - { - sidenum = ldef->sidenum[side ^ 1]; - - /* If the sidenum is out of range, this may be a "glass hack" - * impassable window. Point at side #0 (this may not be - * the correct Vanilla behavior; however, it seems to work for - * OTTAWAU.WAD, which is the one place I've seen this trick - * used). - */ - - if (sidenum < 0 || sidenum >= numsides) - { - li->backsector = get_sector_at_null_address(); - } - else - { - li->backsector = sides[sidenum].sector; - } - } - else - { - li->backsector = 0; - } - } - - w_release_lump_num(lump); -} - -static void p_load_subsectors(int lump) -{ - byte *data; - int i; - mapsubsector_t *ms; - subsector_t *ss; - - numsubsectors = w_lump_length(lump) / sizeof(mapsubsector_t); - subsectors = z_malloc(numsubsectors * sizeof(subsector_t), PU_LEVEL, 0); - data = w_cache_lump_num(lump, PU_STATIC); - - ms = (mapsubsector_t *)data; - memset(subsectors, 0, numsubsectors * sizeof(subsector_t)); - ss = subsectors; - - for (i = 0; i < numsubsectors; i++, ss++, ms++) - { - ss->numlines = SHORT(ms->numsegs); - ss->firstline = SHORT(ms->firstseg); - } - - w_release_lump_num(lump); -} - -static void p_load_sectors(int lump) -{ - byte *data; - int i; - mapsector_t *ms; - sector_t *ss; - - numsectors = w_lump_length(lump) / sizeof(mapsector_t); - sectors = z_malloc(numsectors * sizeof(sector_t), PU_LEVEL, 0); - memset(sectors, 0, numsectors * sizeof(sector_t)); - data = w_cache_lump_num(lump, PU_STATIC); - - ms = (mapsector_t *)data; - ss = sectors; - for (i = 0; i < numsectors; i++, ss++, ms++) - { - ss->floorheight = SHORT(ms->floorheight) << FRACBITS; - ss->ceilingheight = SHORT(ms->ceilingheight) << FRACBITS; - ss->floorpic = r_flat_num_for_name(ms->floorpic); - ss->ceilingpic = r_flat_num_for_name(ms->ceilingpic); - ss->lightlevel = SHORT(ms->lightlevel); - ss->special = SHORT(ms->special); - ss->tag = SHORT(ms->tag); - ss->thinglist = NULL; - } - - w_release_lump_num(lump); -} - -static void p_load_nodes(int lump) -{ - byte *data; - int i; - int j; - int k; - mapnode_t *mn; - node_t *no; - - numnodes = w_lump_length(lump) / sizeof(mapnode_t); - nodes = z_malloc(numnodes * sizeof(node_t), PU_LEVEL, 0); - data = w_cache_lump_num(lump, PU_STATIC); - - mn = (mapnode_t *)data; - no = nodes; - - for (i = 0; i < numnodes; i++, no++, mn++) - { - no->x = SHORT(mn->x) << FRACBITS; - no->y = SHORT(mn->y) << FRACBITS; - no->dx = SHORT(mn->dx) << FRACBITS; - no->dy = SHORT(mn->dy) << FRACBITS; - for (j = 0; j < 2; j++) - { - no->children[j] = SHORT(mn->children[j]); - for (k = 0; k < 4; k++) - no->bbox[j][k] = SHORT(mn->bbox[j][k]) << FRACBITS; - } - } - - w_release_lump_num(lump); -} - -static void p_load_things(int lump) -{ - byte *data; - int i; - mapthing_t *mt; - mapthing_t spawnthing; - int numthings; - boolean spawn; - - data = w_cache_lump_num(lump, PU_STATIC); - numthings = w_lump_length(lump) / sizeof(mapthing_t); - - mt = (mapthing_t *)data; - for (i = 0; i < numthings; i++, mt++) - { - spawn = true; - - /* Do not spawn cool, new monsters if !commercial */ - - if (gamemode != commercial) - { - switch (SHORT(mt->type)) - { - case 68: /* Arachnotron */ - case 64: /* Archvile */ - case 88: /* Boss Brain */ - case 89: /* Boss Shooter */ - case 69: /* Hell Knight */ - case 67: /* Mancubus */ - case 71: /* Pain Elemental */ - case 65: /* Former Human Commando */ - case 66: /* Revenant */ - case 84: /* Wolf SS */ - spawn = false; - break; - } - } - - if (spawn == false) break; - - /* Do spawn all other stuff. */ - - spawnthing.x = SHORT(mt->x); - spawnthing.y = SHORT(mt->y); - spawnthing.angle = SHORT(mt->angle); - spawnthing.type = SHORT(mt->type); - spawnthing.options = SHORT(mt->options); - - p_spawn_map_thing(&spawnthing); - } - - if (!deathmatch) - { - for (i = 0; i < MAXPLAYERS; i++) - { - if (playeringame[i] && !playerstartsingame[i]) - { - i_error("p_load_things: Player %d start missing (vanilla " - "crashes here)", - i + 1); - } - - playerstartsingame[i] = false; - } - } - - w_release_lump_num(lump); -} - -/* p_load_linedefs - * Also counts secret lines for intermissions. - */ - -static void p_load_linedefs(int lump) -{ - byte *data; - int i; - maplinedef_t *mld; - line_t *ld; - vertex_t *v1; - vertex_t *v2; - - numlines = w_lump_length(lump) / sizeof(maplinedef_t); - lines = z_malloc(numlines * sizeof(line_t), PU_LEVEL, 0); - memset(lines, 0, numlines * sizeof(line_t)); - data = w_cache_lump_num(lump, PU_STATIC); - - mld = (maplinedef_t *)data; - ld = lines; - for (i = 0; i < numlines; i++, mld++, ld++) - { - ld->flags = SHORT(mld->flags); - ld->special = SHORT(mld->special); - ld->tag = SHORT(mld->tag); - v1 = ld->v1 = &vertices[SHORT(mld->v1)]; - v2 = ld->v2 = &vertices[SHORT(mld->v2)]; - ld->dx = v2->x - v1->x; - ld->dy = v2->y - v1->y; - - if (!ld->dx) - ld->slopetype = ST_VERTICAL; - else if (!ld->dy) - ld->slopetype = ST_HORIZONTAL; - else - { - if (fixed_div(ld->dy, ld->dx) > 0) - ld->slopetype = ST_POSITIVE; - else - ld->slopetype = ST_NEGATIVE; - } - - if (v1->x < v2->x) - { - ld->bbox[BOXLEFT] = v1->x; - ld->bbox[BOXRIGHT] = v2->x; - } - else - { - ld->bbox[BOXLEFT] = v2->x; - ld->bbox[BOXRIGHT] = v1->x; - } - - if (v1->y < v2->y) - { - ld->bbox[BOXBOTTOM] = v1->y; - ld->bbox[BOXTOP] = v2->y; - } - else - { - ld->bbox[BOXBOTTOM] = v2->y; - ld->bbox[BOXTOP] = v1->y; - } - - ld->sidenum[0] = SHORT(mld->sidenum[0]); - ld->sidenum[1] = SHORT(mld->sidenum[1]); - - if (ld->sidenum[0] != -1) - ld->frontsector = sides[ld->sidenum[0]].sector; - else - ld->frontsector = 0; - - if (ld->sidenum[1] != -1) - ld->backsector = sides[ld->sidenum[1]].sector; - else - ld->backsector = 0; - } - - w_release_lump_num(lump); -} - -static void p_load_side_defs(int lump) -{ - byte *data; - int i; - mapsidedef_t *msd; - side_t *sd; - - numsides = w_lump_length(lump) / sizeof(mapsidedef_t); - sides = z_malloc(numsides * sizeof(side_t), PU_LEVEL, 0); - memset(sides, 0, numsides * sizeof(side_t)); - data = w_cache_lump_num(lump, PU_STATIC); - - msd = (mapsidedef_t *)data; - sd = sides; - for (i = 0; i < numsides; i++, msd++, sd++) - { - sd->textureoffset = SHORT(msd->textureoffset) << FRACBITS; - sd->rowoffset = SHORT(msd->rowoffset) << FRACBITS; - sd->toptexture = r_texture_num_for_name(msd->toptexture); - sd->bottomtexture = r_texture_num_for_name(msd->bottomtexture); - sd->midtexture = r_texture_num_for_name(msd->midtexture); - sd->sector = §ors[SHORT(msd->sector)]; - } - - w_release_lump_num(lump); -} - -static void p_load_block_map(int lump) -{ - int i; - int count; - int lumplen; - - lumplen = w_lump_length(lump); - count = lumplen / 2; - - blockmaplump = z_malloc(lumplen, PU_LEVEL, NULL); - w_read_lump(lump, blockmaplump); - blockmap = blockmaplump + 4; - - /* Swap all short integers to native byte ordering. */ - - for (i = 0; i < count; i++) - { - blockmaplump[i] = SHORT(blockmaplump[i]); - } - - /* Read the header */ - - bmaporgx = blockmaplump[0] << FRACBITS; - bmaporgy = blockmaplump[1] << FRACBITS; - bmapwidth = blockmaplump[2]; - bmapheight = blockmaplump[3]; - - /* Clear out mobj chains */ - - count = sizeof(*blocklinks) * bmapwidth * bmapheight; - blocklinks = z_malloc(count, PU_LEVEL, 0); - memset(blocklinks, 0, count); -} - -/* p_group_lines - * Builds sector line lists and subsector sector numbers. - * Finds block bounding boxes for sectors. - */ - -static void p_group_lines(void) -{ - line_t **linebuffer; - int i; - int j; - line_t *li; - sector_t *sector; - subsector_t *ss; - seg_t *seg; - fixed_t bbox[4]; - int block; - - /* look up sector number for each subsector */ - - ss = subsectors; - for (i = 0; i < numsubsectors; i++, ss++) - { - seg = &segs[ss->firstline]; - ss->sector = seg->sidedef->sector; - } - - /* count number of lines in each sector */ - - li = lines; - totallines = 0; - for (i = 0; i < numlines; i++, li++) - { - totallines++; - li->frontsector->linecount++; - - if (li->backsector && li->backsector != li->frontsector) - { - li->backsector->linecount++; - totallines++; - } - } - - /* build line tables for each sector */ - - linebuffer = z_malloc(totallines * sizeof(line_t *), PU_LEVEL, 0); - - for (i = 0; i < numsectors; ++i) - { - /* Assign the line buffer for this sector */ - - sectors[i].lines = linebuffer; - linebuffer += sectors[i].linecount; - - /* Reset linecount to zero so in the next stage we can count - * lines into the list. - */ - - sectors[i].linecount = 0; - } - - /* Assign lines to sectors */ - - for (i = 0; i < numlines; ++i) - { - li = &lines[i]; - - if (li->frontsector != NULL) - { - sector = li->frontsector; - - sector->lines[sector->linecount] = li; - ++sector->linecount; - } - - if (li->backsector != NULL && li->frontsector != li->backsector) - { - sector = li->backsector; - - sector->lines[sector->linecount] = li; - ++sector->linecount; - } - } - - /* Generate bounding boxes for sectors */ - - sector = sectors; - for (i = 0; i < numsectors; i++, sector++) - { - m_clear_box(bbox); - - for (j = 0; j < sector->linecount; j++) - { - li = sector->lines[j]; - - m_add_to_box(bbox, li->v1->x, li->v1->y); - m_add_to_box(bbox, li->v2->x, li->v2->y); - } - - /* set the degenmobj_t to the middle of the bounding box */ - - sector->soundorg.x = (bbox[BOXRIGHT] + bbox[BOXLEFT]) / 2; - sector->soundorg.y = (bbox[BOXTOP] + bbox[BOXBOTTOM]) / 2; - - /* adjust bounding box to map blocks */ - - block = (bbox[BOXTOP] - bmaporgy + MAXRADIUS) >> MAPBLOCKSHIFT; - block = block >= bmapheight ? bmapheight - 1 : block; - sector->blockbox[BOXTOP] = block; - - block = (bbox[BOXBOTTOM] - bmaporgy - MAXRADIUS) >> MAPBLOCKSHIFT; - block = block < 0 ? 0 : block; - sector->blockbox[BOXBOTTOM] = block; - - block = (bbox[BOXRIGHT] - bmaporgx + MAXRADIUS) >> MAPBLOCKSHIFT; - block = block >= bmapwidth ? bmapwidth - 1 : block; - sector->blockbox[BOXRIGHT] = block; - - block = (bbox[BOXLEFT] - bmaporgx - MAXRADIUS) >> MAPBLOCKSHIFT; - block = block < 0 ? 0 : block; - sector->blockbox[BOXLEFT] = block; - } -} - -static void p_load_reject(int lumpnum) -{ - int minlength; - int lumplen; - - /* Calculate the size that the REJECT lump *should* be. */ - - minlength = (numsectors * numsectors + 7) / 8; - - /* If the lump meets the minimum length, it can be loaded directly. - * Otherwise, we need to allocate a buffer of the correct size - * and pad it with appropriate data. - */ - - lumplen = w_lump_length(lumpnum); - - if (lumplen >= minlength) - { - rejectmatrix = w_cache_lump_num(lumpnum, PU_LEVEL); - } - else - { - rejectmatrix = z_malloc(minlength, PU_LEVEL, &rejectmatrix); - w_read_lump(lumpnum, rejectmatrix); - - pad_reject_array(rejectmatrix + lumplen, minlength - lumplen, - totallines); - } -} - -/* p_setup_level */ - -void p_setup_level(int episode, int map, int playermask, skill_t skill) -{ - int i; - char lumpname[9]; - int lumpnum; - - totalkills = totalitems = totalsecret = wminfo.maxfrags = 0; - wminfo.partime = 180; - for (i = 0; i < MAXPLAYERS; i++) - { - players[i].killcount = players[i].secretcount = players[i].itemcount = - 0; - } - - /* Initial height of PointOfView will be set by player think. */ - - players[consoleplayer].viewz = 1; - - /* Make sure all sounds are stopped before z_free_tags. */ - -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start(); -#endif - - z_free_tags(PU_LEVEL, PU_PURGELEVEL - 1); - - /* UNUSED w_profile (); */ - - p_init_thinkers(); - - /* if working with a development map, reload it */ - - w_reload(); - - /* find map name */ - - if (gamemode == commercial) - { - if (map < 10) - snprintf(lumpname, 9, "map0%d", (int8_t)map); - else - snprintf(lumpname, 9, "map%d", (int8_t)map); - } - else - { - lumpname[0] = 'E'; - lumpname[1] = '0' + episode; - lumpname[2] = 'M'; - lumpname[3] = '0' + map; - lumpname[4] = 0; - } - - lumpnum = w_get_num_for_name(lumpname); - - maplumpinfo = lumpinfo[lumpnum]; - - leveltime = 0; - - /* note: most of this ordering is important */ - - p_load_block_map(lumpnum + ML_BLOCKMAP); - p_load_vertices(lumpnum + ML_VERTICES); - p_load_sectors(lumpnum + ML_SECTORS); - p_load_side_defs(lumpnum + ML_SIDEDEFS); - - p_load_linedefs(lumpnum + ML_LINEDEFS); - p_load_subsectors(lumpnum + ML_SSECTORS); - p_load_nodes(lumpnum + ML_NODES); - p_load_segs(lumpnum + ML_SEGS); - - p_group_lines(); - p_load_reject(lumpnum + ML_REJECT); - - bodyqueslot = 0; - deathmatch_p = deathmatchstarts; - p_load_things(lumpnum + ML_THINGS); - - /* if deathmatch, randomly spawn the active players */ - - if (deathmatch) - { - for (i = 0; i < MAXPLAYERS; i++) - { - if (playeringame[i]) - { - players[i].mo = NULL; - g_death_match_spawn_player(i); - } - } - } - - /* clear special respawning que */ - - iquehead = iquetail = 0; - - /* set up world state */ - - p_spawn_specials(); - - /* preload graphics */ - - if (precache) r_precache_level(); -} - -void p_init(void) -{ - p_init_switch_list(); - p_init_pic_anims(); - r_init_sprites(sprnames); -} diff --git a/games/NXDoom/src/doom/p_setup.h b/games/NXDoom/src/doom/p_setup.h deleted file mode 100644 index ee4cdb563..000000000 --- a/games/NXDoom/src/doom/p_setup.h +++ /dev/null @@ -1,51 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/p_setup.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Setup a game, startup stuff. - * - ****************************************************************************/ - -#ifndef __P_SETUP__ -#define __P_SETUP__ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "w_wad.h" - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -extern lumpinfo_t *maplumpinfo; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/* NOT called by W_Ticker. Fixme. */ - -void p_setup_level(int episode, int map, int playermask, skill_t skill); - -/* Called by startup code. */ - -void p_init(void); - -#endif /* __P_SETUP__ */ diff --git a/games/NXDoom/src/doom/p_sight.c b/games/NXDoom/src/doom/p_sight.c deleted file mode 100644 index 84167065e..000000000 --- a/games/NXDoom/src/doom/p_sight.c +++ /dev/null @@ -1,405 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/p_sight.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * LineOfSight/Visibility checks, uses REJECT Lookup Table. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "doomdef.h" -#include "doomstat.h" - -#include "i_system.h" -#include "p_local.h" - -/* State. */ - -#include "r_state.h" - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/* p_check_sight */ - -fixed_t sightzstart; /* eye z of looker */ -fixed_t topslope; -fixed_t bottomslope; /* slopes to top and bottom of target */ - -divline_t strace; /* from t1 to t2 */ -fixed_t t2x; -fixed_t t2y; - -int sightcounts[2]; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/* PTR_SightTraverse() for Doom 1.2 sight calculations - * taken from prboom-plus/src/p_sight.c:69-102 - */ - -static boolean ptr_sight_traverse(intercept_t *in) -{ - line_t *li; - fixed_t slope; - - li = in->d.line; - - /* crosses a two sided line */ - - p_line_opening(li); - - /* quick test for totally closed doors */ - - if (openbottom >= opentop) - { - return false; /* stop */ - } - - if (li->frontsector->floorheight != li->backsector->floorheight) - { - slope = fixed_div(openbottom - sightzstart, in->frac); - if (slope > bottomslope) bottomslope = slope; - } - - if (li->frontsector->ceilingheight != li->backsector->ceilingheight) - { - slope = fixed_div(opentop - sightzstart, in->frac); - if (slope < topslope) topslope = slope; - } - - if (topslope <= bottomslope) return false; /* stop */ - - return true; /* keep going */ -} - -/* p_divline_side - * Returns side 0 (front), 1 (back), or 2 (on). - */ - -static int p_divline_side(fixed_t x, fixed_t y, divline_t *node) -{ - fixed_t dx; - fixed_t dy; - fixed_t left; - fixed_t right; - - if (!node->dx) - { - if (x == node->x) return 2; - - if (x <= node->x) return node->dy > 0; - - return node->dy < 0; - } - - if (!node->dy) - { - if (x == node->y) return 2; - - if (y <= node->y) return node->dx < 0; - - return node->dx > 0; - } - - dx = (x - node->x); - dy = (y - node->y); - - left = (node->dy >> FRACBITS) * (dx >> FRACBITS); - right = (dy >> FRACBITS) * (node->dx >> FRACBITS); - - if (right < left) return 0; /* front side */ - - if (left == right) return 2; - return 1; /* back side */ -} - -/* p_intercept_vector2 - * Returns the fractional intercept point along the first divline. - * This is only called by the addthings and addlines traversers. - */ - -static fixed_t p_intercept_vector2(divline_t *v2, divline_t *v1) -{ - fixed_t frac; - fixed_t num; - fixed_t den; - - den = fixed_mul(v1->dy >> 8, v2->dx) - fixed_mul(v1->dx >> 8, v2->dy); - - if (den == 0) return 0; - - num = fixed_mul((v1->x - v2->x) >> 8, v1->dy) + - fixed_mul((v2->y - v1->y) >> 8, v1->dx); - frac = fixed_div(num, den); - - return frac; -} - -/* p_cross_subsector - * Returns true if strace crosses the given subsector successfully. - */ - -static boolean p_cross_subsector(int num) -{ - seg_t *seg; - line_t *line; - int s1; - int s2; - int count; - subsector_t *sub; - sector_t *front; - sector_t *back; - fixed_t l_opentop; - fixed_t l_openbottom; - divline_t divl; - vertex_t *v1; - vertex_t *v2; - fixed_t frac; - fixed_t slope; - -#ifdef CONFIG_GAMES_NXDOOM_RANGECHECK - if (num >= numsubsectors) - i_error("p_cross_subsector: ss %i with numss = %i", num, numsubsectors); -#endif - - sub = &subsectors[num]; - - /* check lines */ - - count = sub->numlines; - seg = &segs[sub->firstline]; - - for (; count; seg++, count--) - { - line = seg->linedef; - - /* already checked other side? */ - - if (line->validcount == validcount) continue; - - line->validcount = validcount; - - v1 = line->v1; - v2 = line->v2; - s1 = p_divline_side(v1->x, v1->y, &strace); - s2 = p_divline_side(v2->x, v2->y, &strace); - - /* line isn't crossed? */ - - if (s1 == s2) continue; - - divl.x = v1->x; - divl.y = v1->y; - divl.dx = v2->x - v1->x; - divl.dy = v2->y - v1->y; - s1 = p_divline_side(strace.x, strace.y, &divl); - s2 = p_divline_side(t2x, t2y, &divl); - - /* line isn't crossed? */ - - if (s1 == s2) continue; - - /* Backsector may be NULL if this is an "impassable - * glass" hack line. - */ - - if (line->backsector == NULL) - { - return false; - } - - /* stop because it is not two sided anyway - * might do this after updating validcount? - */ - - if (!(line->flags & ML_TWOSIDED)) return false; - - /* crosses a two sided line */ - - front = seg->frontsector; - back = seg->backsector; - - /* no wall to block sight with? */ - - if (front->floorheight == back->floorheight && - front->ceilingheight == back->ceilingheight) - continue; - - /* possible occluder - * because of ceiling height differences - */ - - if (front->ceilingheight < back->ceilingheight) - l_opentop = front->ceilingheight; - else - l_opentop = back->ceilingheight; - - /* because of ceiling height differences */ - - if (front->floorheight > back->floorheight) - l_openbottom = front->floorheight; - else - l_openbottom = back->floorheight; - - /* quick test for totally closed doors */ - - if (l_openbottom >= l_opentop) return false; /* stop */ - - frac = p_intercept_vector2(&strace, &divl); - - if (front->floorheight != back->floorheight) - { - slope = fixed_div(l_openbottom - sightzstart, frac); - if (slope > bottomslope) bottomslope = slope; - } - - if (front->ceilingheight != back->ceilingheight) - { - slope = fixed_div(l_opentop - sightzstart, frac); - if (slope < topslope) topslope = slope; - } - - if (topslope <= bottomslope) return false; /* stop */ - } - - /* passed the subsector ok */ - - return true; -} - -/* p_cross_bsp_node - * Returns true if strace crosses the given node successfully. - */ - -static boolean p_cross_bsp_node(int bspnum) -{ - node_t *bsp; - int side; - - if (bspnum & NF_SUBSECTOR) - { - if (bspnum == -1) - { - return p_cross_subsector(0); - } - else - { - return p_cross_subsector(bspnum & (~NF_SUBSECTOR)); - } - } - - bsp = &nodes[bspnum]; - - /* decide which side the start point is on */ - - side = p_divline_side(strace.x, strace.y, (divline_t *)bsp); - if (side == 2) side = 0; /* an "on" should cross both sides */ - - /* cross the starting side */ - - if (!p_cross_bsp_node(bsp->children[side])) return false; - - /* the partition plane is crossed here */ - - if (side == p_divline_side(t2x, t2y, (divline_t *)bsp)) - { - /* the line doesn't touch the other side */ - - return true; - } - - /* cross the ending side */ - - return p_cross_bsp_node(bsp->children[side ^ 1]); -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/* p_check_sight - * Returns true if a straight line between t1 and t2 is unobstructed. - * Uses REJECT. - */ - -boolean p_check_sight(mobj_t *t1, mobj_t *t2) -{ - int s1; - int s2; - int pnum; - int bytenum; - int bitnum; - - /* First check for trivial rejection. */ - - /* Determine subsector entries in REJECT table. */ - - s1 = (t1->subsector->sector - sectors); - s2 = (t2->subsector->sector - sectors); - pnum = s1 * numsectors + s2; - bytenum = pnum >> 3; - bitnum = 1 << (pnum & 7); - - /* Check in REJECT table. */ - - if (rejectmatrix[bytenum] & bitnum) - { - sightcounts[0]++; - - /* can't possibly be connected */ - - return false; - } - - /* An unobstructed LOS is possible. - * Now look from eyes of t1 to any part of t2. - */ - - sightcounts[1]++; - - validcount++; - - sightzstart = t1->z + t1->height - (t1->height >> 2); - topslope = (t2->z + t2->height) - sightzstart; - bottomslope = (t2->z) - sightzstart; - - if (gameversion <= exe_doom_1_2) - { - return p_path_traverse(t1->x, t1->y, t2->x, t2->y, - PT_EARLYOUT | PT_ADDLINES, - ptr_sight_traverse); - } - - strace.x = t1->x; - strace.y = t1->y; - t2x = t2->x; - t2y = t2->y; - strace.dx = t2->x - t1->x; - strace.dy = t2->y - t1->y; - - /* the head node is the last node output */ - - return p_cross_bsp_node(numnodes - 1); -} diff --git a/games/NXDoom/src/doom/p_spec.c b/games/NXDoom/src/doom/p_spec.c deleted file mode 100644 index 2b095210d..000000000 --- a/games/NXDoom/src/doom/p_spec.c +++ /dev/null @@ -1,1376 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/p_spec.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Implements special effects: - * Texture animation, height or lighting changes according to adjacent - * sectors, respective utility functions, etc. - * Line Tag handling. Line and Sector triggers. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include "doomdef.h" -#include "doomstat.h" - -#include "deh_main.h" -#include "i_system.h" -#include "m_argv.h" -#include "m_misc.h" -#include "m_random.h" -#include "w_wad.h" -#include "z_zone.h" - -#include "p_local.h" -#include "r_local.h" - -#include "g_game.h" - -#ifdef CONFIG_GAMES_NXDOOM_SOUND -#include "s_sound.h" -#include "sounds.h" -#endif - -/* State. */ - -#include "r_state.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define MAXANIMS 32 - -/* Animating line specials */ - -#define MAXLINEANIMS 64 - -/* version <= 1.2 did not have a limit and could handle up to 66 scrolling - * linedefs before displaying adverse effects. All other versions have a - * limit of 64. - */ - -#define MAXLINEANIMS1_2 66 - -/* Thanks to entryway for the Vanilla overflow emulation. - * 20 adjoining sectors max! - */ - -#define MAX_ADJOINING_SECTORS 20 - -/* Donut overrun emulation - * - * Derived from the code from PrBoom+. Thanks go to Andrey Budko (entryway) - * as usual :-) - */ - -#define DONUT_FLOORHEIGHT_DEFAULT 0x00000000 -#define DONUT_FLOORPIC_DEFAULT 0x16 - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/* Animating textures and planes - * There is another anim_t used in wi_stuff, unrelated. - */ - -typedef struct -{ - boolean istexture; - int picnum; - int basepic; - int numpics; - int speed; -} anim_t; - -/* source animation definition */ - -typedef struct -{ - int istexture; /* if false, it is a flat */ - char endname[9]; - char startname[9]; - int speed; -} animdef_t; - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/* p_init_pic_anims */ - -/* Floor/ceiling animation sequences, defined by first and last frame, i.e. - * the flat (64x64 tile) name to be used. - * - * The full animation sequence is given using all the flats between the start - * and end entry, in the order found in the WAD file. - */ - -static animdef_t g_animdefs[] = -{ - {false, "NUKAGE3", "NUKAGE1", 8}, - {false, "FWATER4", "FWATER1", 8}, - {false, "SWATER4", "SWATER1", 8}, - {false, "LAVA4", "LAVA1", 8}, - {false, "BLOOD3", "BLOOD1", 8}, - {false, "RROCK08", "RROCK05", 8}, /* DOOM II flat animations. */ - {false, "SLIME04", "SLIME01", 8}, - {false, "SLIME08", "SLIME05", 8}, - {false, "SLIME12", "SLIME09", 8}, - {true, "BLODGR4", "BLODGR1", 8}, - {true, "SLADRIP3", "SLADRIP1", 8}, - {true, "BLODRIP4", "BLODRIP1", 8}, - {true, "FIREWALL", "FIREWALA", 8}, - {true, "GSTFONT3", "GSTFONT1", 8}, - {true, "FIRELAVA", "FIRELAV3", 8}, - {true, "FIREMAG3", "FIREMAG1", 8}, - {true, "FIREBLU2", "FIREBLU1", 8}, - {true, "ROCKRED3", "ROCKRED1", 8}, - {true, "BFALL4", "BFALL1", 8}, - {true, "SFALL4", "SFALL1", 8}, - {true, "WFALL4", "WFALL1", 8}, - {true, "DBRAIN4", "DBRAIN1", 8}, - { -1, "", "", 0}, -}; - -static anim_t g_anims[MAXANIMS]; -static anim_t *g_lastanim; - -static short g_numlinespecials; -static line_t *g_linespeciallist[MAXLINEANIMS1_2]; - -/* p_update_specials - * Animate planes, scroll walls, etc. - */ - -static boolean g_level_timer; -static int g_level_time_count; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static void donut_overrun(fixed_t *s3_floorheight, short *s3_floorpic, - line_t *line, sector_t *pillar_sector) -{ - static int first = 1; - static int tmp_s3_floorheight; - static int tmp_s3_floorpic; - - if (first) - { - int p; - - /* This is the first time we have had an overrun. */ - - first = 0; - - /* Default values */ - - tmp_s3_floorheight = DONUT_FLOORHEIGHT_DEFAULT; - tmp_s3_floorpic = DONUT_FLOORPIC_DEFAULT; - - /* @category compat - * @arg - * - * Use the specified magic values when emulating behavior caused - * by memory overruns from improperly constructed donuts. - * In Vanilla Doom this can differ depending on the operating - * system. The default (if this option is not specified) is to - * emulate the behavior when running under Windows 98. - */ - - p = m_check_parm_with_args("-donut", 2); - - if (p > 0) - { - /* Dump of needed memory: (fixed_t)0000:0000 and (short)0000:0008 - * - * C:\>debug - * -d 0:0 - * - * DOS 6.22: - * 0000:0000 (57 92 19 00) F4 06 70 00-(16 00) - * DOS 7.1: - * 0000:0000 (9E 0F C9 00) 65 04 70 00-(16 00) - * Win98: - * 0000:0000 (00 00 00 00) 65 04 70 00-(16 00) - * DOSBox under XP: - * 0000:0000 (00 00 00 F1) ?? ?? ?? 00-(07 00) - */ - - m_str_to_int(myargv[p + 1], &tmp_s3_floorheight); - m_str_to_int(myargv[p + 2], &tmp_s3_floorpic); - - if (tmp_s3_floorpic >= numflats) - { - fprintf(stderr, - "DonutOverrun: The second parameter for \"-donut\" " - "switch should be greater than 0 and less than number " - "of flats (%d). Using default value (%d) instead. \n", - numflats, DONUT_FLOORPIC_DEFAULT); - tmp_s3_floorpic = DONUT_FLOORPIC_DEFAULT; - } - } - } - - *s3_floorheight = (fixed_t)tmp_s3_floorheight; - *s3_floorpic = (short)tmp_s3_floorpic; -} - -/* p_spawn_specials - * After the map has been loaded, scan for specials that spawn thinkers - */ - -static unsigned int num_scrollers(void) -{ - unsigned int i; - unsigned int scrollers = 0; - - for (i = 0; i < numlines; i++) - { - if (48 == lines[i].special) - { - scrollers++; - } - } - - return scrollers; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -void p_init_pic_anims(void) -{ - int i; - - /* Init animation */ - - g_lastanim = g_anims; - for (i = 0; g_animdefs[i].istexture != -1; i++) - { - const char *startname; - const char *endname; - - startname = (g_animdefs[i].startname); - endname = (g_animdefs[i].endname); - - if (g_animdefs[i].istexture) - { - /* different episode ? */ - - if (r_check_texture_num_for_name(startname) == -1) continue; - - g_lastanim->picnum = r_texture_num_for_name(endname); - g_lastanim->basepic = r_texture_num_for_name(startname); - } - else - { - if (w_check_num_for_name(startname) == -1) continue; - - g_lastanim->picnum = r_flat_num_for_name(endname); - g_lastanim->basepic = r_flat_num_for_name(startname); - } - - g_lastanim->istexture = g_animdefs[i].istexture; - g_lastanim->numpics = g_lastanim->picnum - g_lastanim->basepic + 1; - - if (g_lastanim->numpics < 2) - i_error("p_init_pic_anims: bad cycle from %s to %s", startname, - endname); - - g_lastanim->speed = g_animdefs[i].speed; - g_lastanim++; - } -} - -/* UTILITIES */ - -/* get_side() - * Will return a side_t* given the number of the current sector, the line - * number, and the side (0/1) that you want. - */ - -side_t *get_side(int current_sector, int line, int side) -{ - return &sides[(sectors[current_sector].lines[line])->sidenum[side]]; -} - -/* get_sector() - * Will return a sector_t* given the number of the current sector, the line - * number and the side (0/1) that you want. - */ - -sector_t *get_sector(int current_sector, int line, int side) -{ - return sides[(sectors[current_sector].lines[line])->sidenum[side]].sector; -} - -/* two_sided() - * Given the sector number and the line number, it will tell you whether the - * line is two-sided or not. - */ - -int two_sided(int sector, int line) -{ - return (sectors[sector].lines[line])->flags & ML_TWOSIDED; -} - -/* get_next_sector() - * Return sector_t * of sector next to current. NULL if not two-sided line - */ - -sector_t *get_next_sector(line_t *line, sector_t *sec) -{ - if (!(line->flags & ML_TWOSIDED)) return NULL; - - if (line->frontsector == sec) return line->backsector; - - return line->frontsector; -} - -/* p_find_lowest_floor_surrounding() - * FIND LOWEST FLOOR HEIGHT IN SURROUNDING SECTORS - */ - -fixed_t p_find_lowest_floor_surrounding(sector_t *sec) -{ - int i; - line_t *check; - sector_t *other; - fixed_t floor = sec->floorheight; - - for (i = 0; i < sec->linecount; i++) - { - check = sec->lines[i]; - other = get_next_sector(check, sec); - - if (!other) continue; - - if (other->floorheight < floor) floor = other->floorheight; - } - - return floor; -} - -/* p_find_highest_floor_surrounding() - * FIND HIGHEST FLOOR HEIGHT IN SURROUNDING SECTORS - */ - -fixed_t p_find_highest_floor_surrounding(sector_t *sec) -{ - int i; - line_t *check; - sector_t *other; - fixed_t floor = -500 * FRACUNIT; - - for (i = 0; i < sec->linecount; i++) - { - check = sec->lines[i]; - other = get_next_sector(check, sec); - - if (!other) continue; - - if (other->floorheight > floor) floor = other->floorheight; - } - - return floor; -} - -/* p_find_next_highest_floor - * FIND NEXT HIGHEST FLOOR IN SURROUNDING SECTORS - * Note: this should be doable w/o a fixed array. - */ - -fixed_t p_find_next_highest_floor(sector_t *sec, int currentheight) -{ - int i; - int h; - int min; - line_t *check; - sector_t *other; - fixed_t height = currentheight; - fixed_t heightlist[MAX_ADJOINING_SECTORS + 2]; - - for (i = 0, h = 0; i < sec->linecount; i++) - { - check = sec->lines[i]; - other = get_next_sector(check, sec); - - if (!other) continue; - - if (other->floorheight > height) - { - /* Emulation of memory (stack) overflow */ - - if (h == MAX_ADJOINING_SECTORS + 1) - { - height = other->floorheight; - } - else if (h == MAX_ADJOINING_SECTORS + 2) - { - /* Fatal overflow: game crashes at 22 sectors */ - - i_error("Sector with more than 22 adjoining sectors. " - "Vanilla will crash here"); - } - - heightlist[h++] = other->floorheight; - } - } - - /* Find lowest height in list */ - - if (!h) - { - return currentheight; - } - - min = heightlist[0]; - - /* Range checking? */ - - for (i = 1; i < h; i++) - { - if (heightlist[i] < min) - { - min = heightlist[i]; - } - } - - return min; -} - -/* FIND LOWEST CEILING IN THE SURROUNDING SECTORS */ - -fixed_t p_find_lowest_ceiling_surrounding(sector_t *sec) -{ - int i; - line_t *check; - sector_t *other; - fixed_t height = INT_MAX; - - for (i = 0; i < sec->linecount; i++) - { - check = sec->lines[i]; - other = get_next_sector(check, sec); - - if (!other) continue; - - if (other->ceilingheight < height) height = other->ceilingheight; - } - - return height; -} - -/* FIND HIGHEST CEILING IN THE SURROUNDING SECTORS */ - -fixed_t p_find_heighest_ceiling_surrounding(sector_t *sec) -{ - int i; - line_t *check; - sector_t *other; - fixed_t height = 0; - - for (i = 0; i < sec->linecount; i++) - { - check = sec->lines[i]; - other = get_next_sector(check, sec); - - if (!other) continue; - - if (other->ceilingheight > height) height = other->ceilingheight; - } - - return height; -} - -/* RETURN NEXT SECTOR # THAT LINE TAG REFERS TO */ - -int p_find_sector_from_line_tag(line_t *line, int start) -{ - int i; - - for (i = start + 1; i < numsectors; i++) - { - if (sectors[i].tag == line->tag) - { - return i; - } - } - - return -1; -} - -/* Find minimum light from an adjacent sector */ - -int p_find_min_surrounding(sector_t *sector, int max) -{ - int i; - int min; - line_t *line; - sector_t *check; - - min = max; - for (i = 0; i < sector->linecount; i++) - { - line = sector->lines[i]; - check = get_next_sector(line, sector); - - if (!check) continue; - - if (check->lightlevel < min) min = check->lightlevel; - } - - return min; -} - -/* EVENTS - * Events are operations triggered by using, crossing, - * or shooting special lines, or by timed thinkers. - */ - -/* p_cross_special_line - TRIGGER - * Called every time a thing origin is about to cross a line with a non 0 - * special. - */ - -void p_cross_special_line(int linenum, int side, mobj_t *thing) -{ - line_t *line; - int is_ok; - - line = &lines[linenum]; - - if (gameversion <= exe_doom_1_2) - { - if (line->special > 98 && line->special != 104) - { - return; - } - } - else - { - /* Triggers that other things can activate */ - - if (!thing->player) - { - /* Things that should NOT trigger specials... */ - - switch (thing->type) - { - case MT_ROCKET: - case MT_PLASMA: - case MT_BFG: - case MT_TROOPSHOT: - case MT_HEADSHOT: - case MT_BRUISERSHOT: - return; - - default: - break; - } - } - } - - if (!thing->player) - { - is_ok = 0; - switch (line->special) - { - case 39: /* TELEPORT TRIGGER */ - case 97: /* TELEPORT RETRIGGER */ - case 125: /* TELEPORT MONSTERONLY TRIGGER */ - case 126: /* TELEPORT MONSTERONLY RETRIGGER */ - case 4: /* RAISE DOOR */ - case 10: /* PLAT DOWN-WAIT-UP-STAY TRIGGER */ - case 88: /* PLAT DOWN-WAIT-UP-STAY RETRIGGER */ - is_ok = 1; - break; - } - - if (!is_ok) return; - } - - /* Note: could use some const's here. */ - - switch (line->special) - { - /* TRIGGERS. - * All from here to RETRIGGERS. - */ - - case 2: /* Open Door */ - ev_do_door(line, VLD_OPEN); - line->special = 0; - break; - - case 3: /* Close Door */ - ev_do_door(line, VLD_CLOSE); - line->special = 0; - break; - - case 4: /* Raise Door */ - ev_do_door(line, VLD_NORMAL); - line->special = 0; - break; - - case 5: /* Raise Floor */ - ev_do_floor(line, FLOOR_RAISEFLOOR); - line->special = 0; - break; - - case 6: /* Fast Ceiling Crush & Raise */ - ev_do_ceiling(line, CEIL_FASTCRUSHANDRAISE); - line->special = 0; - break; - - case 8: /* Build Stairs */ - ev_build_stairs(line, STAIR_BUILD8); - line->special = 0; - break; - - case 10: /* PlatDownWaitUp */ - ev_do_plat(line, PLAT_DOWNWAITUPSTAY, 0); - line->special = 0; - break; - - case 12: /* Light Turn On - brightest near */ - ev_light_turn_on(line, 0); - line->special = 0; - break; - - case 13: /* Light Turn On 255 */ - ev_light_turn_on(line, 255); - line->special = 0; - break; - - case 16: /* Close Door 30 */ - ev_do_door(line, VLD_CLOSE30THENOPEN); - line->special = 0; - break; - - case 17: /* Start Light Strobing */ - ev_start_light_strobing(line); - line->special = 0; - break; - - case 19: /* Lower Floor */ - ev_do_floor(line, FLOOR_LOWERFLOOR); - line->special = 0; - break; - - case 22: /* Raise floor to nearest height and change texture */ - ev_do_plat(line, PLAT_RAISETONEARESTANDCHANGE, 0); - line->special = 0; - break; - - case 25: /* Ceiling Crush and Raise */ - ev_do_ceiling(line, CEIL_CRUSHANDRAISE); - line->special = 0; - break; - - case 30: - - /* Raise floor to shortest texture height on either side of lines. */ - - ev_do_floor(line, FLOOR_RAISETOTEXTURE); - line->special = 0; - break; - - case 35: /* Lights Very Dark */ - ev_light_turn_on(line, 35); - line->special = 0; - break; - - case 36: /* Lower Floor (TURBO) */ - ev_do_floor(line, FLOOR_TURBOLOWER); - line->special = 0; - break; - - case 37: /* LowerAndChange */ - ev_do_floor(line, FLOOR_LOWERANDCHANGE); - line->special = 0; - break; - - case 38: /* Lower Floor To Lowest */ - ev_do_floor(line, FLOOR_LOWERFLOORTOLOWEST); - line->special = 0; - break; - - case 39: /* TELEPORT! */ - ev_teleport(line, side, thing); - line->special = 0; - break; - - case 40: /* RaiseCeilingLowerFloor */ - ev_do_ceiling(line, CEIL_RAISETOHIGHEST); - ev_do_floor(line, FLOOR_LOWERFLOORTOLOWEST); - line->special = 0; - break; - - case 44: /* Ceiling Crush */ - ev_do_ceiling(line, CEIL_LOWERANDCRUSH); - line->special = 0; - break; - - case 52: /* EXIT! */ - g_exit_level(); - break; - - case 53: /* Perpetual Platform Raise */ - ev_do_plat(line, PLAT_PERPETUALRAISE, 0); - line->special = 0; - break; - - case 54: /* Platform Stop */ - ev_stop_plat(line); - line->special = 0; - break; - - case 56: /* Raise Floor Crush */ - ev_do_floor(line, FLOOR_RAISEFLOORCRUSH); - line->special = 0; - break; - - case 57: /* Ceiling Crush Stop */ - ev_ceiling_crush_stop(line); - line->special = 0; - break; - - case 58: /* Raise Floor 24 */ - ev_do_floor(line, FLOOR_RAISEFLOOR24); - line->special = 0; - break; - - case 59: /* Raise Floor 24 And Change */ - ev_do_floor(line, FLOOR_RAISEFLOOR24ANDCHANGE); - line->special = 0; - break; - - case 104: /* Turn lights off in sector(tag) */ - ev_turn_tag_lights_off(line); - line->special = 0; - break; - - case 108: /* Blazing Door Raise (faster than TURBO!) */ - ev_do_door(line, VLD_BLAZERAISE); - line->special = 0; - break; - - case 109: /* Blazing Door Open (faster than TURBO!) */ - ev_do_door(line, VLD_BLAZEOPEN); - line->special = 0; - break; - - case 100: /* Build Stairs Turbo 16 */ - ev_build_stairs(line, STAIR_TURBO16); - line->special = 0; - break; - - case 110: /* Blazing Door Close (faster than TURBO!) */ - ev_do_door(line, VLD_BLAZECLOSE); - line->special = 0; - break; - - case 119: /* Raise floor to nearest surr. floor */ - ev_do_floor(line, FLOOR_RAISEFLOORTONEAREST); - line->special = 0; - break; - - case 121: /* Blazing PlatDownWaitUpStay */ - ev_do_plat(line, PLAT_BLAZEDWUS, 0); - line->special = 0; - break; - - case 124: /* Secret EXIT */ - g_secret_exit_level(); - break; - - case 125: /* TELEPORT MonsterONLY */ - if (!thing->player) - { - ev_teleport(line, side, thing); - line->special = 0; - } - break; - - case 130: /* Raise Floor Turbo */ - ev_do_floor(line, FLOOR_RAISEFLOORTURBO); - line->special = 0; - break; - - case 141: /* Silent Ceiling Crush & Raise */ - ev_do_ceiling(line, CEIL_SILENTCRUSHANDRAISE); - line->special = 0; - break; - - /* RETRIGGERS. All from here till end. */ - - case 72: /* Ceiling Crush */ - ev_do_ceiling(line, CEIL_LOWERANDCRUSH); - break; - - case 73: /* Ceiling Crush and Raise */ - ev_do_ceiling(line, CEIL_CRUSHANDRAISE); - break; - - case 74: /* Ceiling Crush Stop */ - ev_ceiling_crush_stop(line); - break; - - case 75: /* Close Door */ - ev_do_door(line, VLD_CLOSE); - break; - - case 76: /* Close Door 30 */ - ev_do_door(line, VLD_CLOSE30THENOPEN); - break; - - case 77: /* Fast Ceiling Crush & Raise */ - ev_do_ceiling(line, CEIL_FASTCRUSHANDRAISE); - break; - - case 79: /* Lights Very Dark */ - ev_light_turn_on(line, 35); - break; - - case 80: /* Light Turn On - brightest near */ - ev_light_turn_on(line, 0); - break; - - case 81: /* Light Turn On 255 */ - ev_light_turn_on(line, 255); - break; - - case 82: /* Lower Floor To Lowest */ - ev_do_floor(line, FLOOR_LOWERFLOORTOLOWEST); - break; - - case 83: /* Lower Floor */ - ev_do_floor(line, FLOOR_LOWERFLOOR); - break; - - case 84: /* LowerAndChange */ - ev_do_floor(line, FLOOR_LOWERANDCHANGE); - break; - - case 86: /* Open Door */ - ev_do_door(line, VLD_OPEN); - break; - - case 87: /* Perpetual Platform Raise */ - ev_do_plat(line, PLAT_PERPETUALRAISE, 0); - break; - - case 88: /* PlatDownWaitUp */ - ev_do_plat(line, PLAT_DOWNWAITUPSTAY, 0); - break; - - case 89: /* Platform Stop */ - ev_stop_plat(line); - break; - - case 90: /* Raise Door */ - ev_do_door(line, VLD_NORMAL); - break; - - case 91: /* Raise Floor */ - ev_do_floor(line, FLOOR_RAISEFLOOR); - break; - - case 92: /* Raise Floor 24 */ - ev_do_floor(line, FLOOR_RAISEFLOOR24); - break; - - case 93: /* Raise Floor 24 And Change */ - ev_do_floor(line, FLOOR_RAISEFLOOR24ANDCHANGE); - break; - - case 94: /* Raise Floor Crush */ - ev_do_floor(line, FLOOR_RAISEFLOORCRUSH); - break; - - case 95: /* Raise floor to nearest height and change texture. */ - ev_do_plat(line, PLAT_RAISETONEARESTANDCHANGE, 0); - break; - - case 96: - - /* Raise floor to shortest texture height on either side of lines. */ - - ev_do_floor(line, FLOOR_RAISETOTEXTURE); - break; - - case 97: /* TELEPORT! */ - ev_teleport(line, side, thing); - break; - - case 98: /* Lower Floor (TURBO) */ - ev_do_floor(line, FLOOR_TURBOLOWER); - break; - - case 105: /* Blazing Door Raise (faster than TURBO!) */ - ev_do_door(line, VLD_BLAZERAISE); - break; - - case 106: /* Blazing Door Open (faster than TURBO!) */ - ev_do_door(line, VLD_BLAZEOPEN); - break; - - case 107: /* Blazing Door Close (faster than TURBO!) */ - ev_do_door(line, VLD_BLAZECLOSE); - break; - - case 120: /* Blazing PlatDownWaitUpStay. */ - ev_do_plat(line, PLAT_BLAZEDWUS, 0); - break; - - case 126: /* TELEPORT MonsterONLY. */ - if (!thing->player) ev_teleport(line, side, thing); - break; - - case 128: /* Raise To Nearest Floor */ - ev_do_floor(line, FLOOR_RAISEFLOORTONEAREST); - break; - - case 129: /* Raise Floor Turbo */ - ev_do_floor(line, FLOOR_RAISEFLOORTURBO); - break; - } -} - -/* p_shoot_special_line - IMPACT SPECIALS - * Called when a thing shoots a special line. - */ - -void p_shoot_special_line(mobj_t *thing, line_t *line) -{ - int is_ok; - - /* Impacts that other things can activate. */ - - if (!thing->player) - { - is_ok = 0; - switch (line->special) - { - case 46: /* OPEN DOOR IMPACT */ - is_ok = 1; - break; - } - - if (!is_ok) return; - } - - switch (line->special) - { - case 24: /* RAISE FLOOR */ - ev_do_floor(line, FLOOR_RAISEFLOOR); - p_change_switch_texture(line, 0); - break; - - case 46: /* OPEN DOOR */ - ev_do_door(line, VLD_OPEN); - p_change_switch_texture(line, 1); - break; - - case 47: /* RAISE FLOOR NEAR AND CHANGE */ - ev_do_plat(line, PLAT_RAISETONEARESTANDCHANGE, 0); - p_change_switch_texture(line, 0); - break; - } -} - -/* p_player_in_special_sector - * Called every tic frame that the player origin is in a special sector - */ - -void p_player_in_special_sector(player_t *player) -{ - sector_t *sector; - - sector = player->mo->subsector->sector; - - /* Falling, not all the way down yet? */ - - if (player->mo->z != sector->floorheight) return; - - /* Has hitten ground. */ - - switch (sector->special) - { - case 5: /* HELLSLIME DAMAGE */ - if (!player->powers[pw_ironfeet]) - { - if (!(leveltime & 0x1f)) p_damage_mobj(player->mo, NULL, NULL, 10); - } - - break; - - case 7: /* NUKAGE DAMAGE */ - if (!player->powers[pw_ironfeet]) - { - if (!(leveltime & 0x1f)) p_damage_mobj(player->mo, NULL, NULL, 5); - } - - break; - - case 16: /* SUPER HELLSLIME DAMAGE */ - case 4: /* STROBE HURT */ - if (!player->powers[pw_ironfeet] || (p_random() < 5)) - { - if (!(leveltime & 0x1f)) p_damage_mobj(player->mo, NULL, NULL, 20); - } - - break; - - case 9: /* SECRET SECTOR */ - player->secretcount++; - sector->special = 0; - break; - - case 11: /* EXIT SUPER DAMAGE! (for E1M8 finale) */ - player->cheats &= ~CF_GODMODE; - - if (!(leveltime & 0x1f)) p_damage_mobj(player->mo, NULL, NULL, 20); - - if (player->health <= 10) g_exit_level(); - break; - - default: - i_error("p_player_in_special_sector: " - "unknown special %i", - sector->special); - break; - }; -} - -void p_update_specials(void) -{ - anim_t *anim; - int pic; - int i; - line_t *line; - - /* LEVEL TIMER */ - - if (g_level_timer == true) - { - g_level_time_count--; - if (!g_level_time_count) g_exit_level(); - } - - /* ANIMATE FLATS AND TEXTURES GLOBALLY */ - - for (anim = g_anims; anim < g_lastanim; anim++) - { - for (i = anim->basepic; i < anim->basepic + anim->numpics; i++) - { - pic = anim->basepic + - ((leveltime / anim->speed + i) % anim->numpics); - - if (anim->istexture) - texturetranslation[i] = pic; - else - flattranslation[i] = pic; - } - } - - /* ANIMATE LINE SPECIALS */ - - for (i = 0; i < g_numlinespecials; i++) - { - line = g_linespeciallist[i]; - switch (line->special) - { - case 48: /* EFFECT FIRSTCOL SCROLL + */ - sides[line->sidenum[0]].textureoffset += FRACUNIT; - break; - } - } - - /* DO BUTTONS */ - - for (i = 0; i < MAXBUTTONS; i++) - if (buttonlist[i].btimer) - { - buttonlist[i].btimer--; - if (!buttonlist[i].btimer) - { - switch (buttonlist[i].where) - { - case top: - sides[buttonlist[i].line->sidenum[0]].toptexture = - buttonlist[i].btexture; - break; - - case middle: - sides[buttonlist[i].line->sidenum[0]].midtexture = - buttonlist[i].btexture; - break; - - case bottom: - sides[buttonlist[i].line->sidenum[0]].bottomtexture = - buttonlist[i].btexture; - break; - } - -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(&buttonlist[i].soundorg, SFX_SWTCHN); -#endif - memset(&buttonlist[i], 0, sizeof(button_t)); - } - } -} - -/* Special Stuff that can not be categorized */ - -int ev_do_donut(line_t *line) -{ - sector_t *s1; - sector_t *s2; - sector_t *s3; - int secnum; - int rtn; - int i; - floormove_t *floor; - fixed_t s3_floorheight; - short s3_floorpic; - - secnum = -1; - rtn = 0; - while ((secnum = p_find_sector_from_line_tag(line, secnum)) >= 0) - { - s1 = §ors[secnum]; - - /* ALREADY MOVING? IF SO, KEEP GOING... */ - - if (s1->specialdata) continue; - - rtn = 1; - s2 = get_next_sector(s1->lines[0], s1); - - /* Vanilla Doom does not check if the linedef is one sided. The - * game does not crash, but reads invalid memory and causes the - * sector floor to move "down" to some unknown height. - * DOSbox prints a warning about an invalid memory access. - * - * I'm not sure exactly what invalid memory is being read. This - * isn't something that should be done, anyway. - * Just print a warning and return. - */ - - if (s2 == NULL) - { - fprintf(stderr, - "ev_do_donut: linedef had no second sidedef! " - "Unexpected behavior may occur in Vanilla Doom. \n"); - break; - } - - for (i = 0; i < s2->linecount; i++) - { - s3 = s2->lines[i]->backsector; - - if (s3 == s1) continue; - - if (s3 == NULL) - { - /* e6y - * s3 is NULL, so - * s3->floorheight is an int at 0000:0000 - * s3->floorpic is a short at 0000:0008 - * Trying to emulate - */ - - fprintf(stderr, "ev_do_donut: WARNING: emulating buffer " - "overrun due to NULL back sector. Unexpected " - "behavior may occur in Vanilla Doom.\n"); - - donut_overrun(&s3_floorheight, &s3_floorpic, line, s1); - } - else - { - s3_floorheight = s3->floorheight; - s3_floorpic = s3->floorpic; - } - - /* Spawn rising slime */ - - floor = z_malloc(sizeof(*floor), PU_LEVSPEC, 0); - p_add_thinker(&floor->thinker); - s2->specialdata = floor; - floor->thinker.function.acp1 = (actionf_p1)t_move_floor; - floor->type = FLOOR_DONUTRAISE; - floor->crush = false; - floor->direction = 1; - floor->sector = s2; - floor->speed = FLOORSPEED / 2; - floor->texture = s3_floorpic; - floor->newspecial = 0; - floor->floordestheight = s3_floorheight; - - /* Spawn lowering donut-hole */ - - floor = z_malloc(sizeof(*floor), PU_LEVSPEC, 0); - p_add_thinker(&floor->thinker); - s1->specialdata = floor; - floor->thinker.function.acp1 = (actionf_p1)t_move_floor; - floor->type = FLOOR_LOWERFLOOR; - floor->crush = false; - floor->direction = -1; - floor->sector = s1; - floor->speed = FLOORSPEED / 2; - floor->floordestheight = s3_floorheight; - break; - } - } - - return rtn; -} - -/* SPECIAL SPAWNING */ - -/* Parses command line parameters. */ - -void p_spawn_specials(void) -{ - sector_t *sector; - int i; - short maxlineanims = - (gameversion <= exe_doom_1_2) ? MAXLINEANIMS1_2 : MAXLINEANIMS; - - /* See if -TIMER was specified. */ - - if (timelimit > 0 && deathmatch) - { - g_level_timer = true; - g_level_time_count = timelimit * 60 * TICRATE; - } - else - { - g_level_timer = false; - } - - /* Init special SECTORs. */ - - sector = sectors; - for (i = 0; i < numsectors; i++, sector++) - { - if (!sector->special) continue; - - switch (sector->special) - { - case 1: /* FLICKERING LIGHTS */ - p_spawn_light_flash(sector); - break; - - case 2: /* STROBE FAST */ - p_spawn_strobe_flash(sector, FASTDARK, 0); - break; - - case 3: /* STROBE SLOW */ - p_spawn_strobe_flash(sector, SLOWDARK, 0); - break; - - case 4: /* STROBE FAST/DEATH SLIME */ - p_spawn_strobe_flash(sector, FASTDARK, 0); - sector->special = 4; - break; - - case 8: /* GLOWING LIGHT */ - p_spawn_glowing_light(sector); - break; - - case 9: /* SECRET SECTOR */ - totalsecret++; - break; - - case 10: /* DOOR CLOSE IN 30 SECONDS */ - p_spawn_door_close_in30(sector); - break; - - case 12: /* SYNC STROBE SLOW */ - p_spawn_strobe_flash(sector, SLOWDARK, 1); - break; - - case 13: /* SYNC STROBE FAST */ - p_spawn_strobe_flash(sector, FASTDARK, 1); - break; - - case 14: /* DOOR RAISE IN 5 MINUTES */ - p_spawn_door_raise_in_5min(sector, i); - break; - - case 17: /* first introduced in official v1.4 beta */ - if (gameversion > exe_doom_1_2) - { - p_spawn_fire_flicker(sector); - } - break; - } - } - - /* Init line EFFECTs */ - - g_numlinespecials = 0; - - for (i = 0; i < numlines; i++) - { - switch (lines[i].special) - { - case 48: - if (g_numlinespecials >= maxlineanims) - { - i_error("p_spawn_specials: Too many scrolling wall linedefs " - "(%d)! (Vanilla limit is %d)", - num_scrollers(), maxlineanims); - } - - /* EFFECT FIRSTCOL SCROLL+ */ - - g_linespeciallist[g_numlinespecials] = &lines[i]; - g_numlinespecials++; - break; - } - } - - /* Init other misc stuff */ - - for (i = 0; i < MAXCEILINGS; i++) - activeceilings[i] = NULL; - - for (i = 0; i < MAXPLATS; i++) - activeplats[i] = NULL; - - for (i = 0; i < MAXBUTTONS; i++) - memset(&buttonlist[i], 0, sizeof(button_t)); - - /* UNUSED: no horizontal sliders. - * p_init_sliding_door_frames(); - */ -} diff --git a/games/NXDoom/src/doom/p_spec.h b/games/NXDoom/src/doom/p_spec.h deleted file mode 100644 index f69c818b4..000000000 --- a/games/NXDoom/src/doom/p_spec.h +++ /dev/null @@ -1,503 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/p_spec.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: none - * Implements special effects: - * Texture animation, height or lighting changes according to adjacent - * sectors, respective utility functions, etc. - * - ****************************************************************************/ - -#ifndef __P_SPEC__ -#define __P_SPEC__ - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* Define values for map objects */ - -#define MO_TELEPORTMAN 14 - -#define GLOWSPEED 8 -#define STROBEBRIGHT 5 -#define FASTDARK 15 -#define SLOWDARK 35 - -/* max # of wall switches in a level */ - -#define MAXSWITCHES 50 - -/* 4 players, 4 buttons each at once, max. */ - -#define MAXBUTTONS 16 - -/* 1 second, in ticks. */ - -#define BUTTONTIME 35 - -#define PLATWAIT 3 -#define PLATSPEED FRACUNIT -#define MAXPLATS 30 - -#define FLOORSPEED FRACUNIT - -#define VDOORSPEED FRACUNIT * 2 -#define VDOORWAIT 150 - -#define CEILSPEED FRACUNIT -#define CEILWAIT 150 -#define MAXCEILINGS 30 - -#if 0 /* UNUSED */ - -/* how many frames of animation */ - -#define SNUMFRAMES 4 - -#define SDOORWAIT 35 * 3 -#define SWAITTICS 4 - -/* how many diff. types of anims */ - -#define MAXSLIDEDOORS 5 -#endif - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -/* P_LIGHTS */ - -typedef struct -{ - thinker_t thinker; - sector_t *sector; - int count; - int maxlight; - int minlight; -} fireflicker_t; - -typedef struct -{ - thinker_t thinker; - sector_t *sector; - int count; - int maxlight; - int minlight; - int maxtime; - int mintime; -} lightflash_t; - -typedef struct -{ - thinker_t thinker; - sector_t *sector; - int count; - int minlight; - int maxlight; - int darktime; - int brighttime; -} strobe_t; - -typedef struct -{ - thinker_t thinker; - sector_t *sector; - int minlight; - int maxlight; - int direction; -} glow_t; - -/* P_SWITCH */ - -typedef struct -{ - char name1[9]; - char name2[9]; - short episode; -} switchlist_t; - -typedef enum -{ - top, - middle, - bottom -} bwhere_e; - -typedef struct -{ - line_t *line; - bwhere_e where; - int btexture; - int btimer; - degenmobj_t *soundorg; -} button_t; - -/* P_PLATS */ - -typedef enum -{ - up, - down, - waiting, - in_stasis -} plat_e; - -typedef enum -{ - PLAT_PERPETUALRAISE, - PLAT_DOWNWAITUPSTAY, - PLAT_RAISEANDCHANGE, - PLAT_RAISETONEARESTANDCHANGE, - PLAT_BLAZEDWUS -} plattype_e; - -typedef struct -{ - thinker_t thinker; - sector_t *sector; - fixed_t speed; - fixed_t low; - fixed_t high; - int wait; - int count; - plat_e status; - plat_e oldstatus; - boolean crush; - int tag; - plattype_e type; -} plat_t; - -/* P_FLOOR */ - -typedef enum -{ - /* lower floor to highest surrounding floor */ - - FLOOR_LOWERFLOOR, - - /* lower floor to lowest surrounding floor */ - - FLOOR_LOWERFLOORTOLOWEST, - - /* lower floor to highest surrounding floor VERY FAST */ - - FLOOR_TURBOLOWER, - - /* raise floor to lowest surrounding CEILING */ - - FLOOR_RAISEFLOOR, - - /* raise floor to next highest surrounding floor */ - - FLOOR_RAISEFLOORTONEAREST, - - /* raise floor to shortest height texture around it */ - - FLOOR_RAISETOTEXTURE, - - /* lower floor to lowest surrounding floor and change floorpic */ - - FLOOR_LOWERANDCHANGE, - - FLOOR_RAISEFLOOR24, - FLOOR_RAISEFLOOR24ANDCHANGE, - FLOOR_RAISEFLOORCRUSH, - - /* raise to next highest floor, turbo-speed */ - - FLOOR_RAISEFLOORTURBO, - FLOOR_DONUTRAISE, - FLOOR_RAISEFLOOR512 -} floor_e; - -typedef enum -{ - STAIR_BUILD8, /* slowly build by 8 */ - STAIR_TURBO16 /* quickly build by 16 */ -} stair_e; - -typedef struct -{ - thinker_t thinker; - floor_e type; - boolean crush; - sector_t *sector; - int direction; - int newspecial; - short texture; - fixed_t floordestheight; - fixed_t speed; -} floormove_t; - -typedef enum -{ - ok, - crushed, - pastdest -} result_e; - -typedef enum -{ - VLD_NORMAL, - VLD_CLOSE30THENOPEN, - VLD_CLOSE, - VLD_OPEN, - VLD_RAISEIN5MINS, - VLD_BLAZERAISE, - VLD_BLAZEOPEN, - VLD_BLAZECLOSE -} vldoor_e; - -typedef struct -{ - thinker_t thinker; - vldoor_e type; - sector_t *sector; - fixed_t topheight; - fixed_t speed; - - /* 1 = up, 0 = waiting at top, -1 = down */ - - int direction; - - /* tics to wait at the top */ - - int topwait; - - /* (keep in case a door going down is reset) - * when it reaches 0, start going down - */ - - int topcountdown; -} vldoor_t; - -/* P_CEILNG */ - -typedef enum -{ - CEIL_LOWERTOFLOOR, - CEIL_RAISETOHIGHEST, - CEIL_LOWERANDCRUSH, - CEIL_CRUSHANDRAISE, - CEIL_FASTCRUSHANDRAISE, - CEIL_SILENTCRUSHANDRAISE -} ceiling_e; - -typedef struct -{ - thinker_t thinker; - ceiling_e type; - sector_t *sector; - fixed_t bottomheight; - fixed_t topheight; - fixed_t speed; - boolean crush; - - /* 1 = up, 0 = waiting, -1 = down */ - - int direction; - - /* ID */ - - int tag; - int olddirection; -} ceiling_t; - -#if 0 /* UNUSED */ - -/* Sliding doors... */ - -typedef enum -{ - sd_opening, - sd_waiting, - sd_closing -} sd_e; - -typedef enum -{ - SDT_OPENONLY, - SDT_CLOSEONLY, - SDT_OPENANDCLOSE -} sdt_e; - -typedef struct -{ - thinker_t thinker; - sdt_e type; - line_t *line; - int frame; - int which_door_index; - int timer; - sector_t *frontsector; - sector_t *backsector; - sd_e status; -} slidedoor_t; - -typedef struct -{ - char front_frame1[9]; - char front_frame2[9]; - char front_frame3[9]; - char front_frame4[9]; - char back_frame1[9]; - char back_frame2[9]; - char back_frame3[9]; - char back_frame4[9]; -} slidename_t; - -typedef struct -{ - int front_frames[4]; - int back_frames[4]; -} slideframe_t; -#endif - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/* End-level timer (-TIMER option) */ - -extern button_t buttonlist[MAXBUTTONS]; - -extern plat_t *activeplats[MAXPLATS]; - -extern ceiling_t *activeceilings[MAXCEILINGS]; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/* at game start */ - -void p_init_pic_anims(void); - -/* at map load */ - -void p_spawn_specials(void); - -/* every tic */ - -void p_update_specials(void); - -/* when needed */ - -boolean p_use_special_line(mobj_t *thing, line_t *line, int side); - -void p_shoot_special_line(mobj_t *thing, line_t *line); - -void p_cross_special_line(int linenum, int side, mobj_t *thing); - -void p_player_in_special_sector(player_t *player); - -int two_sided(int sector, int line); - -sector_t *get_sector(int current_sector, int line, int side); - -side_t *get_side(int current_sector, int line, int side); - -fixed_t p_find_lowest_floor_surrounding(sector_t *sec); -fixed_t p_find_highest_floor_surrounding(sector_t *sec); - -fixed_t p_find_next_highest_floor(sector_t *sec, int currentheight); - -fixed_t p_find_lowest_ceiling_surrounding(sector_t *sec); -fixed_t p_find_heighest_ceiling_surrounding(sector_t *sec); - -int p_find_sector_from_line_tag(line_t *line, int start); - -int p_find_min_surrounding(sector_t *sector, int max); - -sector_t *get_next_sector(line_t *line, sector_t *sec); - -/* SPECIAL */ - -int ev_do_donut(line_t *line); - -void p_spawn_fire_flicker(sector_t *sector); -void t_light_flash(lightflash_t *flash); -void p_spawn_light_flash(sector_t *sector); -void t_strobe_flash(strobe_t *flash); - -void p_spawn_strobe_flash(sector_t *sector, int fast_or_slow, int in_sync); - -void ev_start_light_strobing(line_t *line); -void ev_turn_tag_lights_off(line_t *line); - -void ev_light_turn_on(line_t *line, int bright); - -void t_glow(glow_t *g); -void p_spawn_glowing_light(sector_t *sector); - -void p_change_switch_texture(line_t *line, int use_again); - -void p_init_switch_list(void); - -void t_plat_raise(plat_t *plat); - -int ev_do_plat(line_t *line, plattype_e type, int amount); - -void p_add_active_plat(plat_t *plat); -void p_remove_active_plat(plat_t *plat); -void ev_stop_plat(line_t *line); -void p_activate_in_stasis(int tag); - -/* P_DOORS */ - -void ev_vertical_door(line_t *line, mobj_t *thing); - -int ev_do_door(line_t *line, vldoor_e type); - -int ev_do_locked_door(line_t *line, vldoor_e type, mobj_t *thing); - -void t_vertical_door(vldoor_t *door); -void p_spawn_door_close_in30(sector_t *sec); - -void p_spawn_door_raise_in_5min(sector_t *sec, int secnum); - -int ev_do_ceiling(line_t *line, ceiling_e type); - -void t_move_ceiling(ceiling_t *ceiling); -void p_add_active_ceiling(ceiling_t *c); -void p_remove_active_ceiling(ceiling_t *c); -int ev_ceiling_crush_stop(line_t *line); -void p_activate_in_stasis_ceiling(line_t *line); - -result_e t_move_plane(sector_t *sector, fixed_t speed, fixed_t dest, - boolean crush, int floor_or_ceiling, int direction); - -int ev_build_stairs(line_t *line, stair_e type); - -int ev_do_floor(line_t *line, floor_e floortype); - -void t_move_floor(floormove_t *floor); - -/* P_TELEPT */ - -int ev_teleport(line_t *line, int side, mobj_t *thing); - -#if 0 /* UNUSED */ -void p_init_sliding_door_frames(void); - -void ev_sliding_door(line_t *line, mobj_t *thing); -#endif - -#endif /* __P_SPEC__ */ diff --git a/games/NXDoom/src/doom/p_switch.c b/games/NXDoom/src/doom/p_switch.c deleted file mode 100644 index 27640d5ec..000000000 --- a/games/NXDoom/src/doom/p_switch.c +++ /dev/null @@ -1,596 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/p_switch.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * - * DESCRIPTION: - * Switches, buttons. Two-state animation. Exits. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include "deh_main.h" -#include "doomdef.h" -#include "i_system.h" -#include "p_local.h" - -#include "g_game.h" - -#ifdef CONFIG_GAMES_NXDOOM_SOUND -#include "s_sound.h" -#include "sounds.h" -#endif - -/* State. */ - -#include "doomstat.h" -#include "r_state.h" - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/* CHANGE THE TEXTURE OF A WALL SWITCH TO ITS OPPOSITE */ - -static switchlist_t g_alph_switch_list[] = -{ - {"SW1BRCOM", "SW2BRCOM", 1}, /* Doom shareware episode 1 switches */ - {"SW1BRN1", "SW2BRN1", 1}, - {"SW1BRN2", "SW2BRN2", 1}, - {"SW1BRNGN", "SW2BRNGN", 1}, - {"SW1BROWN", "SW2BROWN", 1}, - {"SW1COMM", "SW2COMM", 1}, - {"SW1COMP", "SW2COMP", 1}, - {"SW1DIRT", "SW2DIRT", 1}, - {"SW1EXIT", "SW2EXIT", 1}, - {"SW1GRAY", "SW2GRAY", 1}, - {"SW1GRAY1", "SW2GRAY1", 1}, - {"SW1METAL", "SW2METAL", 1}, - {"SW1PIPE", "SW2PIPE", 1}, - {"SW1SLAD", "SW2SLAD", 1}, - {"SW1STARG", "SW2STARG", 1}, - {"SW1STON1", "SW2STON1", 1}, - {"SW1STON2", "SW2STON2", 1}, - {"SW1STONE", "SW2STONE", 1}, - {"SW1STRTN", "SW2STRTN", 1}, - {"SW1BLUE", "SW2BLUE", 2}, /* Doom registered episodes 2 & 3 switches */ - {"SW1CMT", "SW2CMT", 2}, - {"SW1GARG", "SW2GARG", 2}, - {"SW1GSTON", "SW2GSTON", 2}, - {"SW1HOT", "SW2HOT", 2}, - {"SW1LION", "SW2LION", 2}, - {"SW1SATYR", "SW2SATYR", 2}, - {"SW1SKIN", "SW2SKIN", 2}, - {"SW1VINE", "SW2VINE", 2}, - {"SW1WOOD", "SW2WOOD", 2}, - {"SW1PANEL", "SW2PANEL", 3}, /* Doom II switches */ - {"SW1ROCK", "SW2ROCK", 3}, - {"SW1MET2", "SW2MET2", 3}, - {"SW1WDMET", "SW2WDMET", 3}, - {"SW1BRIK", "SW2BRIK", 3}, - {"SW1MOD1", "SW2MOD1", 3}, - {"SW1ZIM", "SW2ZIM", 3}, - {"SW1STON6", "SW2STON6", 3}, - {"SW1TEK", "SW2TEK", 3}, - {"SW1MARB", "SW2MARB", 3}, - {"SW1SKULL", "SW2SKULL", 3}, -}; - -static int g_numswitches; - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -int switchlist[MAXSWITCHES * 2]; -button_t buttonlist[MAXBUTTONS]; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/* Start a button counting down till it turns off. */ - -static void p_start_button(line_t *line, bwhere_e w, int texture, int time) -{ - int i; - - /* See if button is already pressed */ - - for (i = 0; i < MAXBUTTONS; i++) - { - if (buttonlist[i].btimer && buttonlist[i].line == line) - { - return; - } - } - - for (i = 0; i < MAXBUTTONS; i++) - { - if (!buttonlist[i].btimer) - { - buttonlist[i].line = line; - buttonlist[i].where = w; - buttonlist[i].btexture = texture; - buttonlist[i].btimer = time; - buttonlist[i].soundorg = &line->frontsector->soundorg; - return; - } - } - - i_error("P_StartButton: no button slots left!"); -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/* p_init_switch_list - * Only called at game initialization. - */ - -void p_init_switch_list(void) -{ - int i; - int slindex; - int episode; - - /* Note that this is called "episode" here but it's actually something - * quite different. As we progress from Shareware->Registered->Doom II - * we support more switch textures. - */ - - switch (gamemode) - { - case registered: - case retail: - episode = 2; - break; - case commercial: - episode = 3; - break; - default: - episode = 1; - break; - } - - slindex = 0; - - for (i = 0; i < arrlen(g_alph_switch_list); i++) - { - if (g_alph_switch_list[i].episode <= episode) - { - switchlist[slindex++] = - r_texture_num_for_name((g_alph_switch_list[i].name1)); - switchlist[slindex++] = - r_texture_num_for_name((g_alph_switch_list[i].name2)); - } - } - - g_numswitches = slindex / 2; - switchlist[slindex] = -1; -} - -/* Function that changes wall texture. - * Tell it if switch is ok to use again (1=yes, it's a button). - */ - -void p_change_switch_texture(line_t *line, int use_again) -{ - int tex_top; - int tex_mid; - int tex_bot; - int i; -#ifdef CONFIG_GAMES_NXDOOM_SOUND - int sound; -#endif - - if (!use_again) line->special = 0; - - tex_top = sides[line->sidenum[0]].toptexture; - tex_mid = sides[line->sidenum[0]].midtexture; - tex_bot = sides[line->sidenum[0]].bottomtexture; - -#ifdef CONFIG_GAMES_NXDOOM_SOUND - sound = SFX_SWTCHN; - - /* EXIT SWITCH? */ - - if (line->special == 11) sound = SFX_SWTCHX; -#endif - - for (i = 0; i < g_numswitches * 2; i++) - { - if (switchlist[i] == tex_top) - { -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(buttonlist->soundorg, sound); -#endif - sides[line->sidenum[0]].toptexture = switchlist[i ^ 1]; - - if (use_again) - { - p_start_button(line, top, switchlist[i], BUTTONTIME); - } - - return; - } - else - { - if (switchlist[i] == tex_mid) - { -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(buttonlist->soundorg, sound); -#endif - sides[line->sidenum[0]].midtexture = switchlist[i ^ 1]; - - if (use_again) - p_start_button(line, middle, switchlist[i], BUTTONTIME); - - return; - } - else - { - if (switchlist[i] == tex_bot) - { -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(buttonlist->soundorg, sound); -#endif - sides[line->sidenum[0]].bottomtexture = switchlist[i ^ 1]; - - if (use_again) - p_start_button(line, bottom, switchlist[i], BUTTONTIME); - - return; - } - } - } - } -} - -/* p_use_special_line - * Called when a thing uses a special line. - * Only the front sides of lines are usable. - */ - -boolean p_use_special_line(mobj_t *thing, line_t *line, int side) -{ - /* Err... - * Use the back sides of VERY SPECIAL lines... - */ - - if (side) - { - switch (line->special) - { - case 124: - - /* Sliding door open & close - * UNUSED? - */ - - break; - - default: - return false; - break; - } - } - - /* Switches that other things can activate. */ - - if (!thing->player) - { - /* never open secret doors */ - - if (line->flags & ML_SECRET) return false; - - switch (line->special) - { - case 1: /* MANUAL DOOR RAISE */ - case 32: /* MANUAL BLUE */ - case 33: /* MANUAL RED */ - case 34: /* MANUAL YELLOW */ - break; - - default: - return false; - break; - } - } - - /* do something */ - - switch (line->special) - { - /* MANUALS */ - - case 1: /* Vertical Door */ - case 26: /* Blue Door/Locked */ - case 27: /* Yellow Door /Locked */ - case 28: /* Red Door /Locked */ - - case 31: /* Manual door open */ - case 32: /* Blue locked door open */ - case 33: /* Red locked door open */ - case 34: /* Yellow locked door open */ - - case 117: /* Blazing door raise */ - case 118: /* Blazing door open */ - ev_vertical_door(line, thing); - break; - - /* UNUSED - Door Slide Open&Close - * case 124: - * ev_sliding_door (line, thing); - * break; - */ - - /* SWITCHES */ - - case 7: /* Build Stairs */ - if (ev_build_stairs(line, STAIR_BUILD8)) - p_change_switch_texture(line, 0); - break; - - case 9: /* Change Donut */ - if (ev_do_donut(line)) p_change_switch_texture(line, 0); - break; - - case 11: /* Exit level */ - p_change_switch_texture(line, 0); - g_exit_level(); - break; - - case 14: /* Raise Floor 32 and change texture */ - if (ev_do_plat(line, PLAT_RAISEANDCHANGE, 32)) - p_change_switch_texture(line, 0); - break; - - case 15: /* Raise Floor 24 and change texture */ - if (ev_do_plat(line, PLAT_RAISEANDCHANGE, 24)) - p_change_switch_texture(line, 0); - break; - - case 18: /* Raise Floor to next highest floor */ - if (ev_do_floor(line, FLOOR_RAISEFLOORTONEAREST)) - p_change_switch_texture(line, 0); - break; - - case 20: /* Raise Plat next highest floor and change texture */ - if (ev_do_plat(line, PLAT_RAISETONEARESTANDCHANGE, 0)) - p_change_switch_texture(line, 0); - break; - - case 21: /* PlatDownWaitUpStay */ - if (ev_do_plat(line, PLAT_DOWNWAITUPSTAY, 0)) - p_change_switch_texture(line, 0); - break; - - case 23: /* Lower Floor to Lowest */ - if (ev_do_floor(line, FLOOR_LOWERFLOORTOLOWEST)) - p_change_switch_texture(line, 0); - break; - - case 29: /* Raise Door */ - if (ev_do_door(line, VLD_NORMAL)) p_change_switch_texture(line, 0); - break; - - case 41: /* Lower Ceiling to Floor */ - if (ev_do_ceiling(line, CEIL_LOWERTOFLOOR)) - p_change_switch_texture(line, 0); - break; - - case 71: /* Turbo Lower Floor */ - if (ev_do_floor(line, FLOOR_TURBOLOWER)) - p_change_switch_texture(line, 0); - break; - - case 49: /* Ceiling Crush And Raise */ - if (ev_do_ceiling(line, CEIL_CRUSHANDRAISE)) - p_change_switch_texture(line, 0); - break; - - case 50: /* Close Door */ - if (ev_do_door(line, VLD_CLOSE)) p_change_switch_texture(line, 0); - break; - - case 51: /* Secret EXIT */ - p_change_switch_texture(line, 0); - g_secret_exit_level(); - break; - - case 55: /* Raise Floor Crush */ - if (ev_do_floor(line, FLOOR_RAISEFLOORCRUSH)) - p_change_switch_texture(line, 0); - break; - - case 101: /* Raise Floor */ - if (ev_do_floor(line, FLOOR_RAISEFLOOR)) - p_change_switch_texture(line, 0); - break; - - case 102: /* Lower Floor to Surrounding floor height */ - if (ev_do_floor(line, FLOOR_LOWERFLOOR)) - p_change_switch_texture(line, 0); - break; - - case 103: /* Open Door */ - if (ev_do_door(line, VLD_OPEN)) p_change_switch_texture(line, 0); - break; - - case 111: /* Blazing Door Raise (faster than TURBO!) */ - if (ev_do_door(line, VLD_BLAZERAISE)) p_change_switch_texture(line, 0); - break; - - case 112: /* Blazing Door Open (faster than TURBO!) */ - if (ev_do_door(line, VLD_BLAZEOPEN)) p_change_switch_texture(line, 0); - break; - - case 113: /* Blazing Door Close (faster than TURBO!) */ - if (ev_do_door(line, VLD_BLAZECLOSE)) p_change_switch_texture(line, 0); - break; - - case 122: /* Blazing PlatDownWaitUpStay */ - if (ev_do_plat(line, PLAT_BLAZEDWUS, 0)) - p_change_switch_texture(line, 0); - break; - - case 127: /* Build Stairs Turbo 16 */ - if (ev_build_stairs(line, STAIR_TURBO16)) - p_change_switch_texture(line, 0); - break; - - case 131: /* Raise Floor Turbo */ - if (ev_do_floor(line, FLOOR_RAISEFLOORTURBO)) - p_change_switch_texture(line, 0); - break; - - case 133: /* BlzOpenDoor BLUE */ - case 135: /* BlzOpenDoor RED */ - case 137: /* BlzOpenDoor YELLOW */ - if (ev_do_locked_door(line, VLD_BLAZEOPEN, thing)) - p_change_switch_texture(line, 0); - break; - - case 140: /* Raise Floor 512 */ - if (ev_do_floor(line, FLOOR_RAISEFLOOR512)) - p_change_switch_texture(line, 0); - break; - - /* BUTTONS */ - - case 42: /* Close Door */ - if (ev_do_door(line, VLD_CLOSE)) p_change_switch_texture(line, 1); - break; - - case 43: /* Lower Ceiling to Floor */ - if (ev_do_ceiling(line, CEIL_LOWERTOFLOOR)) - p_change_switch_texture(line, 1); - break; - - case 45: /* Lower Floor to Surrounding floor height */ - if (ev_do_floor(line, FLOOR_LOWERFLOOR)) - p_change_switch_texture(line, 1); - break; - - case 60: /* Lower Floor to Lowest */ - if (ev_do_floor(line, FLOOR_LOWERFLOORTOLOWEST)) - p_change_switch_texture(line, 1); - break; - - case 61: /* Open Door */ - if (ev_do_door(line, VLD_OPEN)) p_change_switch_texture(line, 1); - break; - - case 62: /* PlatDownWaitUpStay */ - if (ev_do_plat(line, PLAT_DOWNWAITUPSTAY, 1)) - p_change_switch_texture(line, 1); - break; - - case 63: /* Raise Door */ - if (ev_do_door(line, VLD_NORMAL)) p_change_switch_texture(line, 1); - break; - - case 64: /* Raise Floor to ceiling */ - if (ev_do_floor(line, FLOOR_RAISEFLOOR)) - p_change_switch_texture(line, 1); - break; - - case 66: /* Raise Floor 24 and change texture */ - if (ev_do_plat(line, PLAT_RAISEANDCHANGE, 24)) - p_change_switch_texture(line, 1); - break; - - case 67: /* Raise Floor 32 and change texture */ - if (ev_do_plat(line, PLAT_RAISEANDCHANGE, 32)) - p_change_switch_texture(line, 1); - break; - - case 65: /* Raise Floor Crush */ - if (ev_do_floor(line, FLOOR_RAISEFLOORCRUSH)) - p_change_switch_texture(line, 1); - break; - - case 68: /* Raise Plat to next highest floor and change texture */ - if (ev_do_plat(line, PLAT_RAISETONEARESTANDCHANGE, 0)) - p_change_switch_texture(line, 1); - break; - - case 69: /* Raise Floor to next highest floor */ - if (ev_do_floor(line, FLOOR_RAISEFLOORTONEAREST)) - p_change_switch_texture(line, 1); - break; - - case 70: /* Turbo Lower Floor */ - if (ev_do_floor(line, FLOOR_TURBOLOWER)) - p_change_switch_texture(line, 1); - break; - - case 114: /* Blazing Door Raise (faster than TURBO!) */ - if (ev_do_door(line, VLD_BLAZERAISE)) p_change_switch_texture(line, 1); - break; - - case 115: /* Blazing Door Open (faster than TURBO!) */ - if (ev_do_door(line, VLD_BLAZEOPEN)) p_change_switch_texture(line, 1); - break; - - case 116: /* Blazing Door Close (faster than TURBO!) */ - if (ev_do_door(line, VLD_BLAZECLOSE)) p_change_switch_texture(line, 1); - break; - - case 123: /* Blazing PlatDownWaitUpStay */ - if (ev_do_plat(line, PLAT_BLAZEDWUS, 0)) - p_change_switch_texture(line, 1); - break; - - case 132: /* Raise Floor Turbo */ - if (ev_do_floor(line, FLOOR_RAISEFLOORTURBO)) - p_change_switch_texture(line, 1); - break; - - case 99: /* BlzOpenDoor BLUE */ - case 134: /* BlzOpenDoor RED */ - case 136: /* BlzOpenDoor YELLOW */ - if (ev_do_locked_door(line, VLD_BLAZEOPEN, thing)) - p_change_switch_texture(line, 1); - break; - - case 138: - - /* Light Turn On */ - - ev_light_turn_on(line, 255); - p_change_switch_texture(line, 1); - break; - - case 139: - - /* Light Turn Off */ - - ev_light_turn_on(line, 35); - p_change_switch_texture(line, 1); - break; - } - - return true; -} diff --git a/games/NXDoom/src/doom/p_telept.c b/games/NXDoom/src/doom/p_telept.c deleted file mode 100644 index 3986a0543..000000000 --- a/games/NXDoom/src/doom/p_telept.c +++ /dev/null @@ -1,141 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/p_telept.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Teleportation. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "doomdef.h" -#include "doomstat.h" - -#ifdef CONFIG_GAMES_NXDOOM_SOUND -#include "s_sound.h" -#include "sounds.h" -#endif - -#include "p_local.h" - -/* State. */ - -#include "r_state.h" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -int ev_teleport(line_t *line, int side, mobj_t *thing) -{ - int i; - int tag; - mobj_t *m; - mobj_t *fog; - unsigned an; - thinker_t *thinker; - sector_t *sector; - fixed_t oldx; - fixed_t oldy; - fixed_t oldz; - - /* don't teleport missiles */ - - if (thing->flags & MF_MISSILE) return 0; - - /* Don't teleport if hit back of line, so you can get out of teleporter. */ - - if (side == 1) return 0; - - tag = line->tag; - for (i = 0; i < numsectors; i++) - { - if (sectors[i].tag == tag) - { - for (thinker = thinkercap.next; thinker != &thinkercap; - thinker = thinker->next) - { - /* not a mobj */ - - if (thinker->function.acp1 != (actionf_p1)p_mobj_thinker) - continue; - - m = (mobj_t *)thinker; - - /* not a teleportman */ - - if (m->type != MT_TELEPORTMAN) continue; - - sector = m->subsector->sector; - - /* wrong sector */ - - if (sector - sectors != i) continue; - - oldx = thing->x; - oldy = thing->y; - oldz = thing->z; - - if (!p_teleport_move(thing, m->x, m->y)) return 0; - - /* The first Final Doom executable does not set thing->z - * when teleporting. This quirk is unique to this - * particular version; the later version included in - * some versions of the Id Anthology fixed this. - */ - - if (gameversion != exe_final) thing->z = thing->floorz; - - if (thing->player) - thing->player->viewz = thing->z + thing->player->viewheight; - - /* spawn teleport fog at source and destination */ - - fog = p_spawn_mobj(oldx, oldy, oldz, MT_TFOG); -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(fog, SFX_TELEPT); -#endif - an = m->angle >> ANGLETOFINESHIFT; - fog = p_spawn_mobj(m->x + 20 * finecosine[an], - m->y + 20 * finesine[an], - thing->z, MT_TFOG); - -#ifdef CONFIG_GAMES_NXDOOM_SOUND - - /* emit sound, where? */ - - s_start_sound(fog, SFX_TELEPT); -#else - UNUSED(fog); -#endif - - /* don't move for a bit */ - - if (thing->player) thing->reactiontime = 18; - - thing->angle = m->angle; - thing->momx = thing->momy = thing->momz = 0; - return 1; - } - } - } - - return 0; -} diff --git a/games/NXDoom/src/doom/p_tick.c b/games/NXDoom/src/doom/p_tick.c deleted file mode 100644 index d2655dd18..000000000 --- a/games/NXDoom/src/doom/p_tick.c +++ /dev/null @@ -1,145 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/p_tick.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Archiving: SaveGame I/O. - * Thinker, Ticker. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "p_local.h" -#include "z_zone.h" - -#include "doomstat.h" - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -int leveltime; - -/* THINKERS - * All thinkers should be allocated by z_malloc - * so they can be operated on uniformly. - * The actual structures will vary in size, - * but the first element must be thinker_t. - */ - -/* Both the head and tail of the thinker list. */ - -thinker_t thinkercap; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static void p_run_thinkers(void) -{ - thinker_t *currentthinker, *nextthinker; - - currentthinker = thinkercap.next; - while (currentthinker != &thinkercap) - { - if (currentthinker->function.acv == (actionf_v)(-1)) - { - /* time to remove it */ - - nextthinker = currentthinker->next; - currentthinker->next->prev = currentthinker->prev; - currentthinker->prev->next = currentthinker->next; - z_free(currentthinker); - } - else - { - if (currentthinker->function.acp1) - currentthinker->function.acp1(currentthinker); - nextthinker = currentthinker->next; - } - - currentthinker = nextthinker; - } -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -void p_init_thinkers(void) -{ - thinkercap.prev = thinkercap.next = &thinkercap; -} - -/* p_add_thinker - * Adds a new thinker at the end of the list. - */ - -void p_add_thinker(thinker_t *thinker) -{ - thinkercap.prev->next = thinker; - thinker->next = &thinkercap; - thinker->prev = thinkercap.prev; - thinkercap.prev = thinker; -} - -/* p_remove_thinker Deallocation is lazy -- it will not actually be freed - * until its thinking turn comes up. - */ - -void p_remove_thinker(thinker_t *thinker) -{ - /* FIXME: NOP. */ - - thinker->function.acv = (actionf_v)(-1); -} - -void p_ticker(void) -{ - int i; - - /* run the tic */ - - if (paused) return; - - /* pause if in menu and at least one tic has been run */ - - if (!netgame && g_menuactive && !demoplayback && - players[consoleplayer].viewz != 1) - { - return; - } - - for (i = 0; i < MAXPLAYERS; i++) - { - if (playeringame[i]) - { - p_player_think(&players[i]); - } - } - - p_run_thinkers(); - p_update_specials(); - p_respawn_specials(); - - /* for par times */ - - leveltime++; -} diff --git a/games/NXDoom/src/doom/p_tick.h b/games/NXDoom/src/doom/p_tick.h deleted file mode 100644 index 0b2d5dee1..000000000 --- a/games/NXDoom/src/doom/p_tick.h +++ /dev/null @@ -1,32 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/p_tick.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: ? - * - ****************************************************************************/ - -#ifndef __P_TICK__ -#define __P_TICK__ - -/* Called by C_Ticker, can call G_PlayerExited. - * Carries out all thinking of monsters and players. - */ - -void p_ticker(void); - -#endif /* __P_TICK__ */ diff --git a/games/NXDoom/src/doom/p_user.c b/games/NXDoom/src/doom/p_user.c deleted file mode 100644 index 0a5d0107b..000000000 --- a/games/NXDoom/src/doom/p_user.c +++ /dev/null @@ -1,371 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/p_user.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Player related stuff. - * Bobbing POV/weapon, movement. - * Pending weapon. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "d_event.h" -#include "doomdef.h" - -#include "p_local.h" - -#include "doomstat.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* Index of the special effects (INVUL inverse) map. */ - -#define INVERSECOLORMAP 32 - -/* Movement. */ - -/* 16 pixels of bob */ - -#define MAXBOB 0x100000 - -#define ANG5 (ANG90 / 18) - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -boolean onground; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/* P_Thrust - * Moves the given origin along a given angle. - */ - -static void p_thrust(player_t *player, angle_t angle, fixed_t move) -{ - angle >>= ANGLETOFINESHIFT; - - player->mo->momx += fixed_mul(move, finecosine[angle]); - player->mo->momy += fixed_mul(move, finesine[angle]); -} - -/* Calculate the walking / running height adjustment */ - -static void p_calc_height(player_t *player) -{ - int angle; - fixed_t bob; - - /* Regular movement bobbing - * (needs to be calculated for gun swing - * even if not on ground) - * OPTIMIZE: tablify angle - * Note: a LUT allows for effects - * like a ramp with low health. - */ - - player->bob = fixed_mul(player->mo->momx, player->mo->momx) + - fixed_mul(player->mo->momy, player->mo->momy); - - player->bob >>= 2; - - if (player->bob > MAXBOB) player->bob = MAXBOB; - - if ((player->cheats & CF_NOMOMENTUM) || !onground) - { - player->viewz = player->mo->z + VIEWHEIGHT; - - if (player->viewz > player->mo->ceilingz - 4 * FRACUNIT) - player->viewz = player->mo->ceilingz - 4 * FRACUNIT; - - player->viewz = player->mo->z + player->viewheight; - return; - } - - angle = (FINEANGLES / 20 * leveltime) & FINEMASK; - bob = fixed_mul(player->bob / 2, finesine[angle]); - - /* move viewheight */ - - if (player->playerstate == PST_LIVE) - { - player->viewheight += player->deltaviewheight; - - if (player->viewheight > VIEWHEIGHT) - { - player->viewheight = VIEWHEIGHT; - player->deltaviewheight = 0; - } - - if (player->viewheight < VIEWHEIGHT / 2) - { - player->viewheight = VIEWHEIGHT / 2; - if (player->deltaviewheight <= 0) player->deltaviewheight = 1; - } - - if (player->deltaviewheight) - { - player->deltaviewheight += FRACUNIT / 4; - if (!player->deltaviewheight) player->deltaviewheight = 1; - } - } - - player->viewz = player->mo->z + player->viewheight + bob; - - if (player->viewz > player->mo->ceilingz - 4 * FRACUNIT) - player->viewz = player->mo->ceilingz - 4 * FRACUNIT; -} - -static void p_move_player(player_t *player) -{ - ticcmd_t *cmd; - - cmd = &player->cmd; - - player->mo->angle += (cmd->angleturn << FRACBITS); - - /* Do not let the player control movement if not onground. */ - - onground = (player->mo->z <= player->mo->floorz); - - if (cmd->forwardmove && onground) - p_thrust(player, player->mo->angle, cmd->forwardmove * 2048); - - if (cmd->sidemove && onground) - p_thrust(player, player->mo->angle - ANG90, cmd->sidemove * 2048); - - if ((cmd->forwardmove || cmd->sidemove) && - player->mo->state == &states[S_PLAY]) - { - p_set_mobj_state(player->mo, S_PLAY_RUN1); - } -} - -/* P_DeathThink - * Fall on your face when dying. - * Decrease POV height to floor height. - */ - -static void p_death_think(player_t *player) -{ - angle_t angle; - angle_t delta; - - p_move_psprites(player); - - /* fall to the ground */ - - if (player->viewheight > 6 * FRACUNIT) player->viewheight -= FRACUNIT; - - if (player->viewheight < 6 * FRACUNIT) player->viewheight = 6 * FRACUNIT; - - player->deltaviewheight = 0; - onground = (player->mo->z <= player->mo->floorz); - p_calc_height(player); - - if (player->attacker && player->attacker != player->mo) - { - angle = r_point_to_angle2(player->mo->x, player->mo->y, - player->attacker->x, player->attacker->y); - - delta = angle - player->mo->angle; - - if (delta < ANG5 || delta > (unsigned)-ANG5) - { - /* Looking at killer, so fade damage flash down. */ - - player->mo->angle = angle; - - if (player->damagecount) player->damagecount--; - } - else if (delta < ANG180) - player->mo->angle += ANG5; - else - player->mo->angle -= ANG5; - } - else if (player->damagecount) - player->damagecount--; - - if (player->cmd.buttons & BT_USE) player->playerstate = PST_REBORN; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -void p_player_think(player_t *player) -{ - ticcmd_t *cmd; - weapontype_t newweapon; - - /* fixme: do this in the cheat code */ - - if (player->cheats & CF_NOCLIP) - player->mo->flags |= MF_NOCLIP; - else - player->mo->flags &= ~MF_NOCLIP; - - /* chain saw run forward */ - - cmd = &player->cmd; - if (player->mo->flags & MF_JUSTATTACKED) - { - cmd->angleturn = 0; - cmd->forwardmove = 0xc800 / 512; - cmd->sidemove = 0; - player->mo->flags &= ~MF_JUSTATTACKED; - } - - if (player->playerstate == PST_DEAD) - { - p_death_think(player); - return; - } - - /* Move around. - * Reactiontime is used to prevent movement for a bit after a teleport. - */ - - if (player->mo->reactiontime) - player->mo->reactiontime--; - else - p_move_player(player); - - p_calc_height(player); - - if (player->mo->subsector->sector->special) - { - p_player_in_special_sector(player); - } - - /* Check for weapon change. */ - - /* A special event has no other buttons. */ - - if (cmd->buttons & BT_SPECIAL) cmd->buttons = 0; - - if (cmd->buttons & BT_CHANGE) - { - /* The actual changing of the weapon is done - * when the weapon psprite can do it - * (read: not in the middle of an attack). - */ - - newweapon = (cmd->buttons & BT_WEAPONMASK) >> BT_WEAPONSHIFT; - - if (newweapon == wp_fist && player->weaponowned[wp_chainsaw] && - !(player->readyweapon == wp_chainsaw && - player->powers[pw_strength])) - { - newweapon = wp_chainsaw; - } - - if ((gamemode == commercial) && newweapon == wp_shotgun && - player->weaponowned[wp_supershotgun] && - player->readyweapon != wp_supershotgun) - { - newweapon = wp_supershotgun; - } - - if (player->weaponowned[newweapon] && newweapon != player->readyweapon) - { - /* Do not go to plasma or BFG in shareware, even if cheated. */ - - if ((newweapon != wp_plasma && newweapon != wp_bfg) || - (gamemode != shareware)) - { - player->pendingweapon = newweapon; - } - } - } - - /* check for use */ - - if (cmd->buttons & BT_USE) - { - if (!player->usedown) - { - p_use_lines(player); - player->usedown = true; - } - } - else - player->usedown = false; - - /* cycle psprites */ - - p_move_psprites(player); - - /* Counters, time dependent power ups. */ - - /* Strength counts up to diminish fade. */ - - if (player->powers[pw_strength]) player->powers[pw_strength]++; - - if (player->powers[pw_invulnerability]) - player->powers[pw_invulnerability]--; - - if (player->powers[pw_invisibility]) - { - if (!--player->powers[pw_invisibility]) - { - player->mo->flags &= ~MF_SHADOW; - } - } - - if (player->powers[pw_infrared]) player->powers[pw_infrared]--; - - if (player->powers[pw_ironfeet]) player->powers[pw_ironfeet]--; - - if (player->damagecount) player->damagecount--; - - if (player->bonuscount) player->bonuscount--; - - /* Handling colormaps. */ - - if (player->powers[pw_invulnerability]) - { - if (player->powers[pw_invulnerability] > 4 * 32 || - (player->powers[pw_invulnerability] & 8)) - player->fixedcolormap = INVERSECOLORMAP; - else - player->fixedcolormap = 0; - } - else if (player->powers[pw_infrared]) - { - if (player->powers[pw_infrared] > 4 * 32 || - (player->powers[pw_infrared] & 8)) - { - /* almost full bright */ - - player->fixedcolormap = 1; - } - else - player->fixedcolormap = 0; - } - else - player->fixedcolormap = 0; -} diff --git a/games/NXDoom/src/doom/r_bsp.c b/games/NXDoom/src/doom/r_bsp.c deleted file mode 100644 index 605b21bea..000000000 --- a/games/NXDoom/src/doom/r_bsp.c +++ /dev/null @@ -1,684 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/r_bsp.c - * - * SPDX-License-Identifier: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * BSP traversal, handling of LineSegs for rendering. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "doomdef.h" - -#include "m_bbox.h" - -#include "i_system.h" - -#include "r_main.h" -#include "r_plane.h" -#include "r_things.h" - -#include "doomstat.h" -#include "r_state.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* We must expand MAXSEGS to the theoretical limit of the number of solidsegs - * that can be generated in a scene by the DOOM engine. This was determined - * by Lee Killough during BOOM development to be a function of the - * screensize. The simplest thing we can do, other than fix this bug, is to - * let the game render overage and then bomb out by detecting the overflow - * after the fact. -haleyjd - */ - -/* #define MAXSEGS 32 */ - -#define MAXSEGS (SCREENWIDTH / 2 + 1) - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/* ClipWallSegment - * Clips the given range of columns and includes it in the new clip list. - */ - -typedef struct -{ - int first; - int last; -} cliprange_t; - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -seg_t *curline; -side_t *sidedef; -line_t *linedef; -sector_t *frontsector; -sector_t *backsector; - -drawseg_t drawsegs[CONFIG_GAMES_NXDOOM_MAXDRAWSEGS]; -drawseg_t *ds_p; - -/* newend is one past the last valid seg */ - -cliprange_t *newend; -cliprange_t solidsegs[MAXSEGS]; - -int checkcoord[12][4] = -{ - { - 3, - 0, - 2, - 1, - }, - { - 3, - 0, - 2, - 0, - }, - { - 3, - 1, - 2, - 0, - }, - { - 0, - }, - { - 2, - 0, - 2, - 1, - }, - { - 0, - 0, - 0, - 0, - }, - { - 3, - 1, - 3, - 0, - }, - { - 0, - }, - { - 2, - 0, - 3, - 1, - }, - { - 2, - 1, - 3, - 1, - }, - { - 2, - 1, - 3, - 0, - }, -}; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -void r_store_wall_range(int start, int stop); -void r_clip_solid_wall_segment(int first, int last); - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: r_clip_pass_wall_segment - * - * Description: - * Clips the given range of columns, - * but does not includes it in the clip list. - * Does handle windows, - * e.g. LineDefs with upper and lower texture. - * - ****************************************************************************/ - -static void r_clip_pass_wall_segment(int first, int last) -{ - cliprange_t *start; - - /* Find the first range that touches the range - * (adjacent pixels are touching). - */ - - start = solidsegs; - while (start->last < first - 1) - start++; - - if (first < start->first) - { - if (last < start->first - 1) - { - /* Post is entirely visible (above start). */ - - r_store_wall_range(first, last); - return; - } - - /* There is a fragment above *start. */ - - r_store_wall_range(first, start->first - 1); - } - - /* Bottom contained in start? */ - - if (last <= start->last) return; - - while (last >= (start + 1)->first - 1) - { - /* There is a fragment between two posts. */ - - r_store_wall_range(start->last + 1, (start + 1)->first - 1); - start++; - - if (last <= start->last) return; - } - - /* There is a fragment after *next. */ - - r_store_wall_range(start->last + 1, last); -} - -/* r_check_b_box - * Checks BSP node/subtree bounding box. - * Returns true if some part of the bbox might be visible. - */ - -static boolean r_check_b_box(fixed_t *bspcoord) -{ - int boxx; - int boxy; - int boxpos; - - fixed_t x1; - fixed_t y1; - fixed_t x2; - fixed_t y2; - - angle_t angle1; - angle_t angle2; - angle_t span; - angle_t tspan; - - cliprange_t *start; - - int sx1; - int sx2; - - /* Find the corners of the box - * that define the edges from current viewpoint. - */ - - if (viewx <= bspcoord[BOXLEFT]) - boxx = 0; - else if (viewx < bspcoord[BOXRIGHT]) - boxx = 1; - else - boxx = 2; - - if (viewy >= bspcoord[BOXTOP]) - boxy = 0; - else if (viewy > bspcoord[BOXBOTTOM]) - boxy = 1; - else - boxy = 2; - - boxpos = (boxy << 2) + boxx; - if (boxpos == 5) return true; - - x1 = bspcoord[checkcoord[boxpos][0]]; - y1 = bspcoord[checkcoord[boxpos][1]]; - x2 = bspcoord[checkcoord[boxpos][2]]; - y2 = bspcoord[checkcoord[boxpos][3]]; - - /* check clip list for an open space */ - - angle1 = r_point_to_angle(x1, y1) - viewangle; - angle2 = r_point_to_angle(x2, y2) - viewangle; - - span = angle1 - angle2; - - /* Sitting on a line? */ - - if (span >= ANG180) return true; - - tspan = angle1 + clipangle; - - if (tspan > 2 * clipangle) - { - tspan -= 2 * clipangle; - - /* Totally off the left edge? */ - - if (tspan >= span) return false; - - angle1 = clipangle; - } - - tspan = clipangle - angle2; - if (tspan > 2 * clipangle) - { - tspan -= 2 * clipangle; - - /* Totally off the left edge? */ - - if (tspan >= span) return false; - - angle2 = -clipangle; - } - - /* Find the first clippost - * that touches the source post - * (adjacent pixels are touching). - */ - - angle1 = (angle1 + ANG90) >> ANGLETOFINESHIFT; - angle2 = (angle2 + ANG90) >> ANGLETOFINESHIFT; - sx1 = viewangletox[angle1]; - sx2 = viewangletox[angle2]; - - /* Does not cross a pixel. */ - - if (sx1 == sx2) return false; - sx2--; - - start = solidsegs; - while (start->last < sx2) - start++; - - if (sx1 >= start->first && sx2 <= start->last) - { - /* The clippost contains the new span. */ - - return false; - } - - return true; -} - -/**************************************************************************** - * Name: r_add_line - * - * Description: - * Clips the given segment - * and adds any visible pieces to the line list. - * - ****************************************************************************/ - -static void r_add_line(seg_t *line) -{ - int x1; - int x2; - angle_t angle1; - angle_t angle2; - angle_t span; - angle_t tspan; - - curline = line; - - /* OPTIMIZE: quickly reject orthogonal back sides. */ - - angle1 = r_point_to_angle(line->v1->x, line->v1->y); - angle2 = r_point_to_angle(line->v2->x, line->v2->y); - - /* Clip to view edges. - * OPTIMIZE: make constant out of 2*clipangle (FIELDOFVIEW). - */ - - span = angle1 - angle2; - - /* Back side? I.e. backface culling? */ - - if (span >= ANG180) return; - - /* Global angle needed by segcalc. */ - - rw_angle1 = angle1; - angle1 -= viewangle; - angle2 -= viewangle; - - tspan = angle1 + clipangle; - if (tspan > 2 * clipangle) - { - tspan -= 2 * clipangle; - - /* Totally off the left edge? */ - - if (tspan >= span) return; - - angle1 = clipangle; - } - - tspan = clipangle - angle2; - if (tspan > 2 * clipangle) - { - tspan -= 2 * clipangle; - - /* Totally off the left edge? */ - - if (tspan >= span) return; - angle2 = -clipangle; - } - - /* The seg is in the view range, but not necessarily visible. */ - - angle1 = (angle1 + ANG90) >> ANGLETOFINESHIFT; - angle2 = (angle2 + ANG90) >> ANGLETOFINESHIFT; - x1 = viewangletox[angle1]; - x2 = viewangletox[angle2]; - - /* Does not cross a pixel? */ - - if (x1 == x2) return; - - backsector = line->backsector; - - /* Single sided line? */ - - if (!backsector) goto clipsolid; - - /* Closed door. */ - - if (backsector->ceilingheight <= frontsector->floorheight || - backsector->floorheight >= frontsector->ceilingheight) - { - goto clipsolid; - } - - /* Window. */ - - if (backsector->ceilingheight != frontsector->ceilingheight || - backsector->floorheight != frontsector->floorheight) - { - goto clippass; - } - - /* Reject empty lines used for triggers - * and special events. - * Identical floor and ceiling on both sides, - * identical light levels on both sides, - * and no middle texture. - */ - - if (backsector->ceilingpic == frontsector->ceilingpic && - backsector->floorpic == frontsector->floorpic && - backsector->lightlevel == frontsector->lightlevel && - curline->sidedef->midtexture == 0) - { - return; - } - -clippass: - r_clip_pass_wall_segment(x1, x2 - 1); - return; - -clipsolid: - r_clip_solid_wall_segment(x1, x2 - 1); -} - -/* r_subsector - * Determine floor/ceiling planes. - * Add sprites of things in sector. - * Draw one or more line segments. - */ - -static void r_subsector(int num) -{ - int count; - seg_t *line; - subsector_t *sub; - -#ifdef CONFIG_GAMES_NXDOOM_RANGECHECK - if (num >= numsubsectors) - i_error("R_Subsector: ss %i with numss = %i", num, numsubsectors); -#endif - - sscount++; - sub = &subsectors[num]; - frontsector = sub->sector; - count = sub->numlines; - line = &segs[sub->firstline]; - - if (frontsector->floorheight < viewz) - { - floorplane = - r_find_plane(frontsector->floorheight, frontsector->floorpic, - frontsector->lightlevel); - } - else - floorplane = NULL; - - if (frontsector->ceilingheight > viewz || - frontsector->ceilingpic == skyflatnum) - { - ceilingplane = - r_find_plane(frontsector->ceilingheight, frontsector->ceilingpic, - frontsector->lightlevel); - } - else - ceilingplane = NULL; - - r_add_sprites(frontsector); - - while (count--) - { - r_add_line(line); - line++; - } - - /* check for solidsegs overflow - extremely unsatisfactory! */ - - if (newend > &solidsegs[32]) - { - i_error("R_Subsector: solidsegs overflow (vanilla may crash here)\n"); - } -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: r_clear_draw_segs - ****************************************************************************/ - -void r_clear_draw_segs(void) -{ - ds_p = drawsegs; -} - -/**************************************************************************** - * Name: r_clip_solid_wall_segment - * - * Description: - * Does handle solid walls, e.g. single sided LineDefs (middle texture) - * that entirely block the view. - * - ****************************************************************************/ - -void r_clip_solid_wall_segment(int first, int last) -{ - cliprange_t *next; - cliprange_t *start; - - /* Find the first range that touches the range - * (adjacent pixels are touching). - */ - - start = solidsegs; - while (start->last < first - 1) - start++; - - if (first < start->first) - { - if (last < start->first - 1) - { - /* Post is entirely visible (above start), - * so insert a new clippost. - */ - - r_store_wall_range(first, last); - next = newend; - newend++; - - while (next != start) - { - *next = *(next - 1); - next--; - } - - next->first = first; - next->last = last; - return; - } - - /* There is a fragment above *start. */ - - r_store_wall_range(first, start->first - 1); - - /* Now adjust the clip size. */ - - start->first = first; - } - - /* Bottom contained in start? */ - - if (last <= start->last) return; - - next = start; - while (last >= (next + 1)->first - 1) - { - /* There is a fragment between two posts. */ - - r_store_wall_range(next->last + 1, (next + 1)->first - 1); - next++; - - if (last <= next->last) - { - /* Bottom is contained in next. - * Adjust the clip size. - */ - - start->last = next->last; - goto crunch; - } - } - - /* There is a fragment after *next. */ - - r_store_wall_range(next->last + 1, last); - - /* Adjust the clip size. */ - - start->last = last; - - /* Remove start+1 to next from the clip list, - * because start now covers their area. - */ - -crunch: - if (next == start) - { - /* Post just extended past the bottom of one post. */ - - return; - } - - while (next++ != newend) - { - /* Remove a post. */ - - *++start = *next; - } - - newend = start + 1; -} - -/**************************************************************************** - * Name: r_clear_clip_segs - ****************************************************************************/ - -void r_clear_clip_segs(void) -{ - solidsegs[0].first = -0x7fffffff; - solidsegs[0].last = -1; - solidsegs[1].first = viewwidth; - solidsegs[1].last = 0x7fffffff; - newend = solidsegs + 2; -} - -/* RenderBSPNode - * Renders all subsectors below a given node, traversing subtree recursively. - * Just call with BSP root. - */ - -void r_render_bsp_node(int bspnum) -{ - node_t *bsp; - int side; - - /* Found a subsector? */ - - if (bspnum & NF_SUBSECTOR) - { - if (bspnum == -1) - r_subsector(0); - else - r_subsector(bspnum & (~NF_SUBSECTOR)); - return; - } - - bsp = &nodes[bspnum]; - - /* Decide which side the view point is on. */ - - side = r_point_on_side(viewx, viewy, bsp); - - /* Recursively divide front space. */ - - r_render_bsp_node(bsp->children[side]); - - /* Possibly divide back space. */ - - if (r_check_b_box(bsp->bbox[side ^ 1])) - r_render_bsp_node(bsp->children[side ^ 1]); -} diff --git a/games/NXDoom/src/doom/r_bsp.h b/games/NXDoom/src/doom/r_bsp.h deleted file mode 100644 index 66c6d611f..000000000 --- a/games/NXDoom/src/doom/r_bsp.h +++ /dev/null @@ -1,73 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/r_bsp.h - * - * SPDX-License-Identifier: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Refresh module, BSP traversal and handling. - * - ****************************************************************************/ - -#ifndef __R_BSP__ -#define __R_BSP__ - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -typedef void (*drawfunc_t)(int start, int stop); - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -extern seg_t *curline; -extern side_t *sidedef; -extern line_t *linedef; -extern sector_t *frontsector; -extern sector_t *backsector; - -extern int rw_x; -extern int rw_stopx; - -extern boolean segtextured; - -/* false if the back side is the same plane */ - -extern boolean markfloor; -extern boolean markceiling; - -extern boolean skymap; - -extern drawseg_t drawsegs[CONFIG_GAMES_NXDOOM_MAXDRAWSEGS]; -extern drawseg_t *ds_p; - -extern lighttable_t **hscalelight; -extern lighttable_t **vscalelight; -extern lighttable_t **dscalelight; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/* BSP? */ - -void r_clear_clip_segs(void); -void r_clear_draw_segs(void); - -void r_render_bsp_node(int bspnum); - -#endif /* __R_BSP__ */ diff --git a/games/NXDoom/src/doom/r_data.c b/games/NXDoom/src/doom/r_data.c deleted file mode 100644 index 2a35c2eda..000000000 --- a/games/NXDoom/src/doom/r_data.c +++ /dev/null @@ -1,944 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/r_data.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Preparation of data for rendering, - * generation of lookups, caching, retrieval by name. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include "deh_main.h" -#include "i_swap.h" -#include "i_system.h" -#include "z_zone.h" - -#include "w_wad.h" - -#include "doomdef.h" -#include "m_misc.h" -#include "p_local.h" -#include "r_local.h" - -#include "doomstat.h" -#include "r_sky.h" - -#include "r_data.h" - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/* Graphics. - * DOOM graphics for walls and sprites - * is stored in vertical runs of opaque pixels (posts). - * A column is composed of zero or more posts, - * a patch or sprite is composed of zero or more columns. - */ - -/* Texture definition. - * Each texture is composed of one or more patches, - * with patches being lumps stored in the WAD. - * The lumps are referenced by number, and patched - * into the rectangular texture space using origin - * and possibly other attributes. - */ - -begin_packed_struct struct mappatch_t -{ - short originx; - short originy; - short patch; - short stepdir; - short colormap; -} end_packed_struct; - -typedef struct mappatch_t mappatch_t; - -/* Texture definition. - * A DOOM wall texture is a list of patches - * which are to be combined in a predefined order. - */ - -begin_packed_struct struct maptexture_t -{ - char name[8]; - int masked; - short width; - short height; - int obsolete; - short patchcount; - mappatch_t patches[1]; -} end_packed_struct; - -typedef struct maptexture_t maptexture_t; - -/* A single patch from a texture definition, basically a rectangular area - * within the texture rectangle. - */ - -typedef struct -{ - /* Block origin (always UL), which has already accounted for the internal - * origin of the patch. - */ - - short originx; - short originy; - int patch; -} texpatch_t; - -/* A maptexturedef_t describes a rectangular texture, which is composed of - * one or more mappatch_t structures that arrange graphic patches. - */ - -typedef struct texture_s texture_t; - -struct texture_s -{ - /* Keep name for switch changing, etc. */ - - char name[8]; - short width; - short height; - - /* Index in textures list */ - - int index; - - /* Next in hash table chain */ - - texture_t *next; - - /* All the patches[patchcount] are drawn back to front into the cached - * texture. - */ - - short patchcount; - texpatch_t patches[1]; -}; - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -int firstflat; -int lastflat; -int numflats; - -int firstpatch; -int lastpatch; -int numpatches; - -int firstspritelump; -int lastspritelump; -int numspritelumps; - -int numtextures; -texture_t **textures; -texture_t **textures_hashtable; - -int *texturewidthmask; - -/* needed for texture pegging */ - -fixed_t *textureheight; -int *texturecompositesize; -short **texturecolumnlump; -unsigned short **texturecolumnofs; -byte **texturecomposite; - -/* for global animation */ - -int *flattranslation; -int *texturetranslation; - -/* needed for pre rendering */ - -fixed_t *spritewidth; -fixed_t *spriteoffset; -fixed_t *spritetopoffset; - -lighttable_t *colormaps; - -int flatmemory; -int texturememory; -int spritememory; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static void generate_texture_hashtable(void) -{ - texture_t **rover; - int i; - int key; - - textures_hashtable = - z_malloc(sizeof(texture_t *) * numtextures, PU_STATIC, 0); - - memset(textures_hashtable, 0, sizeof(texture_t *) * numtextures); - - /* Add all textures to hash table */ - - for (i = 0; i < numtextures; ++i) - { - /* Store index */ - - textures[i]->index = i; - - /* Vanilla Doom does a linear search of the textures array - * and stops at the first entry it finds. If there are two - * entries with the same name, the first one in the array - * wins. The new entry must therefore be added at the end - * of the hash chain, so that earlier entries win. - */ - - key = w_lump_name_hash(textures[i]->name) % numtextures; - - rover = &textures_hashtable[key]; - - while (*rover != NULL) - { - rover = &(*rover)->next; - } - - /* Hook into hash table */ - - textures[i]->next = NULL; - *rover = textures[i]; - } -} - -/**************************************************************************** - * Name: r_generate_lookup - ****************************************************************************/ - -static void r_generate_lookup(int texnum) -{ - texture_t *texture; - byte *patchcount; /* patchcount[texture->width] */ - texpatch_t *patch; - patch_t *realpatch; - int x; - int x1; - int x2; - int i; - short *collump; - unsigned short *colofs; - - texture = textures[texnum]; - - /* Composited texture not created yet. */ - - texturecomposite[texnum] = 0; - - texturecompositesize[texnum] = 0; - collump = texturecolumnlump[texnum]; - colofs = texturecolumnofs[texnum]; - - /* Now count the number of columns that are covered by more than one patch. - * - * Fill in the lump / offset, so columns with only a single patch are all - * done. - */ - - patchcount = (byte *)z_malloc(texture->width, PU_STATIC, &patchcount); - memset(patchcount, 0, texture->width); - - for (i = 0, patch = texture->patches; - i < texture->patchcount; - i++, patch++) - { - realpatch = w_cache_lump_num(patch->patch, PU_CACHE); - x1 = patch->originx; - x2 = x1 + SHORT(realpatch->width); - - if (x1 < 0) - x = 0; - else - x = x1; - - if (x2 > texture->width) x2 = texture->width; - for (; x < x2; x++) - { - patchcount[x]++; - collump[x] = patch->patch; - colofs[x] = LONG(realpatch->columnofs[x - x1]) + 3; - } - } - - for (x = 0; x < texture->width; x++) - { - if (!patchcount[x]) - { - printf("r_generate_lookup: column without a patch (%s)\n", - texture->name); - return; - } - - if (patchcount[x] > 1) - { - /* Use the cached block. */ - - collump[x] = -1; - colofs[x] = texturecompositesize[texnum]; - - if (texturecompositesize[texnum] > 0x10000 - texture->height) - { - i_error("r_generate_lookup: texture %i is >64k", texnum); - } - - texturecompositesize[texnum] += texture->height; - } - } - - z_free(patchcount); -} - -/* MAPTEXTURE_T CACHING - * - * When a texture is first needed, it counts the number of composite columns - * required in the texture and allocates space for a column directory and any - * new columns. - * - * The directory will simply point inside other patches if there is only one - * patch in a given column, but any columns with multiple patches will have - * new column_ts generated. - */ - -/**************************************************************************** - * Name: r_init_textures - * - * Description: - * Initializes the texture list - * with the textures from the world map. - * - ****************************************************************************/ - -static void r_init_textures(void) -{ - maptexture_t *mtexture; - texture_t *texture; - mappatch_t *mpatch; - texpatch_t *patch; - - int i; - int j; - - int *maptex; - int *maptex2; - int *maptex1; - - char name[9]; - char *names; - char *name_p; - - int *patchlookup; - - int nummappatches; - int offset; - int maxoff; - int maxoff2; - int numtextures1; - int numtextures2; - - int *directory; - - int temp1; - int temp2; - int temp3; - - /* Load the patch names from pnames.lmp. */ - - name[8] = 0; - names = w_cache_lump_name(("PNAMES"), PU_STATIC); - nummappatches = LONG(*((int *)names)); - name_p = names + 4; - patchlookup = - z_malloc(nummappatches * sizeof(*patchlookup), PU_STATIC, NULL); - - for (i = 0; i < nummappatches; i++) - { - m_str_copy(name, name_p + i * 8, sizeof(name)); - patchlookup[i] = w_check_num_for_name(name); - } - - w_release_lump_name(("PNAMES")); - - /* Load the map texture definitions from textures.lmp. - * The data is contained in one or two lumps, - * TEXTURE1 for shareware, plus TEXTURE2 for commercial. - */ - - maptex = maptex1 = w_cache_lump_name(("TEXTURE1"), PU_STATIC); - numtextures1 = LONG(*maptex); - maxoff = w_lump_length(w_get_num_for_name(("TEXTURE1"))); - directory = maptex + 1; - - if (w_check_num_for_name(("TEXTURE2")) != -1) - { - maptex2 = w_cache_lump_name(("TEXTURE2"), PU_STATIC); - numtextures2 = LONG(*maptex2); - maxoff2 = w_lump_length(w_get_num_for_name(("TEXTURE2"))); - } - else - { - maptex2 = NULL; - numtextures2 = 0; - maxoff2 = 0; - } - - numtextures = numtextures1 + numtextures2; - - textures = z_malloc(numtextures * sizeof(*textures), PU_STATIC, 0); - texturecolumnlump = - z_malloc(numtextures * sizeof(*texturecolumnlump), PU_STATIC, 0); - texturecolumnofs = - z_malloc(numtextures * sizeof(*texturecolumnofs), PU_STATIC, 0); - texturecomposite = - z_malloc(numtextures * sizeof(*texturecomposite), PU_STATIC, 0); - texturecompositesize = - z_malloc(numtextures * sizeof(*texturecompositesize), PU_STATIC, 0); - texturewidthmask = - z_malloc(numtextures * sizeof(*texturewidthmask), PU_STATIC, 0); - textureheight = - z_malloc(numtextures * sizeof(*textureheight), PU_STATIC, 0); - - /* Really complex printing shit... */ - - temp1 = w_get_num_for_name(("S_START")); /* P_??????? */ - temp2 = w_get_num_for_name(("S_END")) - 1; - temp3 = ((temp2 - temp1 + 63) / 64) + ((numtextures + 63) / 64); - - /* If stdout is a real console, use the classic vanilla "filling - * up the box" effect, which uses backspace to "step back" inside - * the box. If stdout is a file, don't draw the box. - */ - - if (i_console_stdout()) - { - printf("["); - for (i = 0; i < temp3 + 9; i++) - printf(" "); - printf("]"); - for (i = 0; i < temp3 + 10; i++) - printf("\b"); - } - - for (i = 0; i < numtextures; i++, directory++) - { - if (!(i & 63)) printf("."); - - if (i == numtextures1) - { - /* Start looking in second texture file. */ - - maptex = maptex2; - maxoff = maxoff2; - directory = maptex + 1; - } - - offset = LONG(*directory); - - if (offset > maxoff) i_error("r_init_textures: bad texture directory"); - - mtexture = (maptexture_t *)((byte *)maptex + offset); - - texture = textures[i] = - z_malloc(sizeof(texture_t) + - sizeof(texpatch_t) * (SHORT(mtexture->patchcount) - 1), - PU_STATIC, 0); - - texture->width = SHORT(mtexture->width); - texture->height = SHORT(mtexture->height); - texture->patchcount = SHORT(mtexture->patchcount); - - memcpy(texture->name, mtexture->name, sizeof(texture->name)); - mpatch = &mtexture->patches[0]; - patch = &texture->patches[0]; - - for (j = 0; j < texture->patchcount; j++, mpatch++, patch++) - { - patch->originx = SHORT(mpatch->originx); - patch->originy = SHORT(mpatch->originy); - patch->patch = patchlookup[SHORT(mpatch->patch)]; - if (patch->patch == -1) - { - i_error("r_init_textures: Missing patch in texture %s", - texture->name); - } - } - - texturecolumnlump[i] = z_malloc( - texture->width * sizeof(**texturecolumnlump), PU_STATIC, 0); - texturecolumnofs[i] = - z_malloc(texture->width * sizeof(**texturecolumnofs), - PU_STATIC, 0); - - j = 1; - while (j * 2 <= texture->width) - j <<= 1; - - texturewidthmask[i] = j - 1; - textureheight[i] = texture->height << FRACBITS; - } - - z_free(patchlookup); - - w_release_lump_name(("TEXTURE1")); - if (maptex2) w_release_lump_name(("TEXTURE2")); - - /* Precalculate whatever possible. */ - - for (i = 0; i < numtextures; i++) - r_generate_lookup(i); - - /* Create translation table for global animation. */ - - texturetranslation = - z_malloc((numtextures + 1) * sizeof(*texturetranslation), - PU_STATIC, 0); - - for (i = 0; i < numtextures; i++) - texturetranslation[i] = i; - - generate_texture_hashtable(); -} - -/**************************************************************************** - * Name: r_init_flats - ****************************************************************************/ - -static void r_init_flats(void) -{ - int i; - - firstflat = w_get_num_for_name(("F_START")) + 1; - lastflat = w_get_num_for_name(("F_END")) - 1; - numflats = lastflat - firstflat + 1; - - /* Create translation table for global animation. */ - - flattranslation = - z_malloc((numflats + 1) * sizeof(*flattranslation), PU_STATIC, 0); - - for (i = 0; i < numflats; i++) - flattranslation[i] = i; -} - -/**************************************************************************** - * Name: r_init_sprite_lumps - * - * Description: - * Finds the width and hoffset of all sprites in the wad, - * so the sprite does not need to be cached completely - * just for having the header info ready during rendering. - * - ****************************************************************************/ - -static void r_init_sprite_lumps(void) -{ - int i; - patch_t *patch; - - firstspritelump = w_get_num_for_name(("S_START")) + 1; - lastspritelump = w_get_num_for_name(("S_END")) - 1; - - numspritelumps = lastspritelump - firstspritelump + 1; - spritewidth = - z_malloc(numspritelumps * sizeof(*spritewidth), PU_STATIC, 0); - spriteoffset = - z_malloc(numspritelumps * sizeof(*spriteoffset), PU_STATIC, 0); - spritetopoffset = - z_malloc(numspritelumps * sizeof(*spritetopoffset), PU_STATIC, 0); - - for (i = 0; i < numspritelumps; i++) - { - if (!(i & 63)) printf("."); - - patch = w_cache_lump_num(firstspritelump + i, PU_CACHE); - spritewidth[i] = SHORT(patch->width) << FRACBITS; - spriteoffset[i] = SHORT(patch->leftoffset) << FRACBITS; - spritetopoffset[i] = SHORT(patch->topoffset) << FRACBITS; - } -} - -/**************************************************************************** - * Name: r_init_colourmaps - ****************************************************************************/ - -static void r_init_colourmaps(void) -{ - int lump; - - /* Load in the light tables, 256 byte align tables. */ - - lump = w_get_num_for_name(("COLORMAP")); - colormaps = w_cache_lump_num(lump, PU_STATIC); -} - -/**************************************************************************** - * Name: r_draw_column_in_cache - * - * Description: - * Clip and draw a column from a patch into a cached post. - * - ****************************************************************************/ - -static void r_draw_column_in_cache(column_t *patch, byte *cache, int originy, - int cacheheight) -{ - int count; - int position; - byte *source; - - while (patch->topdelta != 0xff) - { - source = (byte *)patch + 3; - count = patch->length; - position = originy + patch->topdelta; - - if (position < 0) - { - count += position; - position = 0; - } - - if (position + count > cacheheight) count = cacheheight - position; - - if (count > 0) memcpy(cache + position, source, count); - - patch = (column_t *)((byte *)patch + patch->length + 4); - } -} - -/**************************************************************************** - * Name: r_generate_composite - * - * Description: - * Using the texture definition, the composite texture is created from the - * patches, and each column is cached. - * - ****************************************************************************/ - -static void r_generate_composite(int texnum) -{ - byte *block; - texture_t *texture; - texpatch_t *patch; - patch_t *realpatch; - int x; - int x1; - int x2; - int i; - column_t *patchcol; - short *collump; - unsigned short *colofs; - - texture = textures[texnum]; - - block = z_malloc(texturecompositesize[texnum], PU_STATIC, - &texturecomposite[texnum]); - - collump = texturecolumnlump[texnum]; - colofs = texturecolumnofs[texnum]; - - /* Composite the columns together. */ - - for (i = 0, patch = texture->patches; - i < texture->patchcount; - i++, patch++) - { - realpatch = w_cache_lump_num(patch->patch, PU_CACHE); - x1 = patch->originx; - x2 = x1 + SHORT(realpatch->width); - - if (x1 < 0) - x = 0; - else - x = x1; - - if (x2 > texture->width) x2 = texture->width; - - for (; x < x2; x++) - { - /* Column does not have multiple patches? */ - - if (collump[x] >= 0) continue; - - patchcol = (column_t *)((byte *)realpatch + - LONG(realpatch->columnofs[x - x1])); - r_draw_column_in_cache(patchcol, block + colofs[x], - patch->originy, texture->height); - } - } - - /* Now that the texture has been built in column cache, - * it is purgeable from zone memory. - */ - - z_change_tag(block, PU_CACHE); -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: r_get_column - ****************************************************************************/ - -byte *r_get_column(int tex, int col) -{ - int lump; - int ofs; - - col &= texturewidthmask[tex]; - lump = texturecolumnlump[tex][col]; - ofs = texturecolumnofs[tex][col]; - - if (lump > 0) return (byte *)w_cache_lump_num(lump, PU_CACHE) + ofs; - - if (!texturecomposite[tex]) r_generate_composite(tex); - - return texturecomposite[tex] + ofs; -} - -/**************************************************************************** - * Name: r_init_data - * - * Description: - * Locates all the lumps that will be used by all views - * Must be called after W_Init. - * - ****************************************************************************/ - -void r_init_data(void) -{ - r_init_textures(); - printf("."); - r_init_flats(); - printf("."); - r_init_sprite_lumps(); - printf("."); - r_init_colourmaps(); -} - -/**************************************************************************** - * Name: r_flat_num_for_name - * - * Description: - * Retrieval, get a flat number for a flat name. - * - ****************************************************************************/ - -int r_flat_num_for_name(const char *name) -{ - int i; - char namet[9]; - - i = w_check_num_for_name(name); - - if (i == -1) - { - namet[8] = 0; - memcpy(namet, name, 8); - i_error("r_flat_num_for_name: %s not found", namet); - } - - return i - firstflat; -} - -/**************************************************************************** - * Name: r_check_texture_num_for_name - * - * Description: - * Check whether texture is available. - * Filter out NoTexture indicator. - * - ****************************************************************************/ - -int r_check_texture_num_for_name(const char *name) -{ - texture_t *texture; - int key; - - /* "NoTexture" marker. */ - - if (name[0] == '-') return 0; - - key = w_lump_name_hash(name) % numtextures; - - texture = textures_hashtable[key]; - - while (texture != NULL) - { - if (!strncasecmp(texture->name, name, 8)) return texture->index; - - texture = texture->next; - } - - return -1; -} - -/**************************************************************************** - * Name: r_texture_num_for_name - * - * Description: - * Calls r_check_texture_num_for_name, aborts with error message. - * - ****************************************************************************/ - -int r_texture_num_for_name(const char *name) -{ - int i; - - i = r_check_texture_num_for_name(name); - - if (i == -1) - { - i_error("r_texture_num_for_name: %s not found", name); - } - - return i; -} - -/**************************************************************************** - * Name: r_precache_level - * - * Description: - * Preloads all relevant graphics for the level. - * - ****************************************************************************/ - -void r_precache_level(void) -{ - char *flatpresent; - char *texturepresent; - char *spritepresent; - - int i; - int j; - int k; - int lump; - - texture_t *texture; - thinker_t *th; - spriteframe_t *sf; - - if (demoplayback) return; - - /* Precache flats. */ - - flatpresent = z_malloc(numflats, PU_STATIC, NULL); - memset(flatpresent, 0, numflats); - - for (i = 0; i < numsectors; i++) - { - flatpresent[sectors[i].floorpic] = 1; - flatpresent[sectors[i].ceilingpic] = 1; - } - - flatmemory = 0; - - for (i = 0; i < numflats; i++) - { - if (flatpresent[i]) - { - lump = firstflat + i; - flatmemory += lumpinfo[lump]->size; - w_cache_lump_num(lump, PU_CACHE); - } - } - - z_free(flatpresent); - - /* Precache textures. */ - - texturepresent = z_malloc(numtextures, PU_STATIC, NULL); - memset(texturepresent, 0, numtextures); - - for (i = 0; i < numsides; i++) - { - texturepresent[sides[i].toptexture] = 1; - texturepresent[sides[i].midtexture] = 1; - texturepresent[sides[i].bottomtexture] = 1; - } - - /* Sky texture is always present. - * Note that F_SKY1 is the name used to indicate a sky floor/ceiling as a - * flat, while the sky texture is stored like a wall texture, with an - * episode dependent name. - */ - - texturepresent[skytexture] = 1; - - texturememory = 0; - for (i = 0; i < numtextures; i++) - { - if (!texturepresent[i]) continue; - - texture = textures[i]; - - for (j = 0; j < texture->patchcount; j++) - { - lump = texture->patches[j].patch; - texturememory += lumpinfo[lump]->size; - w_cache_lump_num(lump, PU_CACHE); - } - } - - z_free(texturepresent); - - /* Precache sprites. */ - - spritepresent = z_malloc(numsprites, PU_STATIC, NULL); - memset(spritepresent, 0, numsprites); - - for (th = thinkercap.next; th != &thinkercap; th = th->next) - { - if (th->function.acp1 == (actionf_p1)p_mobj_thinker) - spritepresent[((mobj_t *)th)->sprite] = 1; - } - - spritememory = 0; - for (i = 0; i < numsprites; i++) - { - if (!spritepresent[i]) continue; - - for (j = 0; j < sprites[i].numframes; j++) - { - sf = &sprites[i].spriteframes[j]; - for (k = 0; k < 8; k++) - { - lump = firstspritelump + sf->lump[k]; - spritememory += lumpinfo[lump]->size; - w_cache_lump_num(lump, PU_CACHE); - } - } - } - - z_free(spritepresent); -} diff --git a/games/NXDoom/src/doom/r_data.h b/games/NXDoom/src/doom/r_data.h deleted file mode 100644 index f320ed0f7..000000000 --- a/games/NXDoom/src/doom/r_data.h +++ /dev/null @@ -1,68 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/r_data.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Refresh module, data I/O, caching, retrieval of graphics - * by name. - * - ****************************************************************************/ - -#ifndef __R_DATA__ -#define __R_DATA__ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "r_defs.h" -#include "r_state.h" - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -extern int numflats; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/* Retrieve column data for span blitting. */ - -byte *r_get_column(int tex, int col); - -/* I/O, setting up the stuff. */ - -void r_init_data(void); -void r_precache_level(void); - -/* Retrieval. - * Floor/ceiling opaque texture tiles, - * lookup by name. For animation? - */ - -int r_flat_num_for_name(const char *name); - -/* Called by p_ticker for switches and animations, - * returns the texture number for the texture name. - */ - -int r_texture_num_for_name(const char *name); -int r_check_texture_num_for_name(const char *name); - -#endif /* __R_DATA__ */ diff --git a/games/NXDoom/src/doom/r_defs.h b/games/NXDoom/src/doom/r_defs.h deleted file mode 100644 index ae84ae63e..000000000 --- a/games/NXDoom/src/doom/r_defs.h +++ /dev/null @@ -1,444 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/r_defs.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Refresh/rendering module, shared data struct definitions. - * - ****************************************************************************/ - -#ifndef __R_DEFS__ -#define __R_DEFS__ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -/* Screenwidth. */ - -#include "doomdef.h" - -/* Some more or less basic data types we depend on. */ - -#include "m_fixed.h" - -/* We rely on the thinker data struct to handle sound origins in sectors. */ - -#include "d_think.h" - -/* SECTORS do store MObjs anyway. */ - -#include "p_mobj.h" - -#include "i_video.h" - -#include "v_patch.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* Silhouette, needed for clipping Segs (mainly) and sprites representing - * things. - */ - -#define SIL_NONE 0 -#define SIL_BOTTOM 1 -#define SIL_TOP 2 -#define SIL_BOTH 3 - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -/* INTERNAL MAP TYPES used by play and refresh */ - -/* Your plain vanilla vertex. - * - * Note: transformed values not buffered locally, like some DOOM-alikes - * ("wt", "WebView") did. - */ - -typedef struct -{ - fixed_t x; - fixed_t y; -} vertex_t; - -/* Forward of LineDefs, for Sectors. */ - -struct line_s; - -/* Each sector has a degenmobj_t in its center for sound origin purposes. - * - * I suppose this does not handle sound from moving objects (doppler), - * because position is prolly just buffered, not updated. - */ - -typedef struct -{ - thinker_t thinker; /* not used for anything */ - fixed_t x; - fixed_t y; - fixed_t z; -} degenmobj_t; - -/* The SECTORS record, at runtime. Stores things/mobjs. */ - -typedef struct -{ - fixed_t floorheight; - fixed_t ceilingheight; - short floorpic; - short ceilingpic; - short lightlevel; - short special; - short tag; - - /* 0 = untraversed, 1,2 = sndlines -1 */ - - int soundtraversed; - - /* thing that made a sound (or null) */ - - mobj_t *soundtarget; - - /* mapblock bounding box for height changes */ - - int blockbox[4]; - - /* origin for any sounds played by the sector */ - - degenmobj_t soundorg; - - /* if == validcount, already checked */ - - int validcount; - - /* list of mobjs in sector */ - - mobj_t *thinglist; - - /* thinker_t for reversible actions */ - - void *specialdata; - - int linecount; - struct line_s **lines; /* [linecount] size */ -} sector_t; - -/* The SideDef. */ - -typedef struct -{ - /* add this to the calculated texture column */ - - fixed_t textureoffset; - - /* add this to the calculated texture top */ - - fixed_t rowoffset; - - /* Texture indices. We do not maintain names here. */ - - short toptexture; - short bottomtexture; - short midtexture; - - /* Sector the SideDef is facing. */ - - sector_t *sector; -} side_t; - -/* Move clipping aid for LineDefs. */ - -typedef enum -{ - ST_HORIZONTAL, - ST_VERTICAL, - ST_POSITIVE, - ST_NEGATIVE -} slopetype_t; - -typedef struct line_s -{ - /* Vertices, from v1 to v2. */ - - vertex_t *v1; - vertex_t *v2; - - /* Precalculated v2 - v1 for side checking. */ - - fixed_t dx; - fixed_t dy; - - /* Animation related. */ - - short flags; - short special; - short tag; - - /* Visual appearance: SideDefs. sidenum[1] will be -1 if one sided */ - - short sidenum[2]; - - /* Neat. Another bounding box, for the extent of the LineDef. */ - - fixed_t bbox[4]; - - /* To aid move clipping. */ - - slopetype_t slopetype; - - /* Front and back sector. - * Note: redundant? Can be retrieved from SideDefs. - */ - - sector_t *frontsector; - sector_t *backsector; - - /* if == validcount, already checked */ - - int validcount; - - /* thinker_t for reversible actions */ - - void *specialdata; -} line_t; - -/* A SubSector. - * References a Sector. - * - * Basically, this is a list of LineSegs, indicating the visible walls that - * define (all or some) sides of a convex BSP leaf. - */ - -typedef struct subsector_s -{ - sector_t *sector; - short numlines; - short firstline; -} subsector_t; - -/* The LineSeg. */ - -typedef struct -{ - vertex_t *v1; - vertex_t *v2; - - fixed_t offset; - - angle_t angle; - - side_t *sidedef; - line_t *linedef; - - /* Sector references. - * Could be retrieved from linedef, too. - * backsector is NULL for one sided lines - */ - - sector_t *frontsector; - sector_t *backsector; -} seg_t; - -/* BSP node. */ - -typedef struct -{ - /* Partition line. */ - - fixed_t x; - fixed_t y; - fixed_t dx; - fixed_t dy; - - /* Bounding box for each child. */ - - fixed_t bbox[2][4]; - - /* If NF_SUBSECTOR its a subsector. */ - - unsigned short children[2]; -} node_t; - -/* PC direct to screen pointers - * B UNUSED - keep till detailshift in r_draw.c resolved - * extern byte* destview; - * extern byte* destscreen; - */ - -/* OTHER TYPES */ - -/* This could be wider for >8 bit display. - * - * Indeed, true color support is possible precalculating 24bpp - * lightmap/colormap LUT. from darkening PLAYPAL to all black. Could even - * use more than 32 levels. - */ - -typedef pixel_t lighttable_t; - -/* ? */ - -typedef struct drawseg_s -{ - seg_t *curline; - int x1; - int x2; - - fixed_t scale1; - fixed_t scale2; - fixed_t scalestep; - - /* 0=none, 1=bottom, 2=top, 3=both */ - - int silhouette; - - /* do not clip sprites above this */ - - fixed_t bsilheight; - - /* do not clip sprites below this */ - - fixed_t tsilheight; - - /* Pointers to lists for sprite clipping, all three adjusted so [x1] is - * first value. - */ - - short *sprtopclip; - short *sprbottomclip; - short *maskedtexturecol; -} drawseg_t; - -/* A vissprite_t is a thing that will be drawn during a refresh. - * - * I.e. a sprite object that is partly visible. - */ - -typedef struct vissprite_s -{ - /* Doubly linked list. */ - - struct vissprite_s *prev; - struct vissprite_s *next; - - int x1; - int x2; - - /* for line side calculation */ - - fixed_t gx; - fixed_t gy; - - /* global bottom / top for silhouette clipping */ - - fixed_t gz; - fixed_t gzt; - - /* horizontal position of x1 */ - - fixed_t startfrac; - - fixed_t scale; - - /* negative if flipped */ - - fixed_t xiscale; - - fixed_t texturemid; - int patch; - - /* for color translation and shadow draw, maxbright frames as well */ - - lighttable_t *colormap; - - int mobjflags; -} vissprite_t; - -/* Sprites are patches with a special naming convention so they can be - * recognized by r_init_sprites. - * - * The base name is NNNNFx or NNNNFxFx, with x indicating the rotation, - * x = 0, 1-7. - * - * The sprite and frame specified by a thing_t is range checked at run time. - * - * A sprite is a patch_t that is assumed to represent a three dimensional - * object and may have multiple rotations pre drawn. - * - * Horizontal flipping is used to save space, thus NNNNF2F5 defines a - * mirrored patch. - * - * Some sprites will only have one picture used for all views: NNNNF0 - */ - -typedef struct -{ - /* If false use 0 for any position. - * Note: as eight entries are available, we might as well insert the same - * name eight times. - */ - - boolean rotate; - - /* Lump to use for view angles 0-7. */ - - short lump[8]; - - /* Flip bit (1 = flip) to use for view angles 0-7. */ - - byte flip[8]; -} spriteframe_t; - -/* A sprite definition: a number of animation frames. */ - -typedef struct -{ - int numframes; - spriteframe_t *spriteframes; -} spritedef_t; - -/* Now what is a visplane, anyway? */ - -typedef struct -{ - fixed_t height; - int picnum; - int lightlevel; - int minx; - int maxx; - - /* leave pads for [minx-1]/[maxx+1] */ - - byte pad1; - - /* Here lies the rub for all dynamic resize/change of resolution. */ - - byte top[SCREENWIDTH]; - byte pad2; - byte pad3; - - /* See above. */ - - byte bottom[SCREENWIDTH]; - byte pad4; -} visplane_t; - -#endif /* __R_DEFS__ */ diff --git a/games/NXDoom/src/doom/r_draw.c b/games/NXDoom/src/doom/r_draw.c deleted file mode 100644 index ff243912a..000000000 --- a/games/NXDoom/src/doom/r_draw.c +++ /dev/null @@ -1,965 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/r_draw.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * The actual span/column drawing functions. - * Here find the main potential for optimization, e.g. inline assembly, - * different algorithms. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "deh_main.h" -#include "doomdef.h" - -#include "i_system.h" -#include "w_wad.h" -#include "z_zone.h" - -#include "r_local.h" - -/* Needs access to LFB (guess what). */ - -#include "v_video.h" - -/* State. */ - -#include "doomstat.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* ? */ - -#define MAXWIDTH 1120 -#define MAXHEIGHT 832 - -/* status bar height at bottom of screen */ - -#define SBARHEIGHT 32 - -/* Spectre/Invisibility. */ - -#define FUZZTABLE 50 -#define FUZZOFF (SCREENWIDTH) - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/* All drawing to the view buffer is accomplished in this file. - * - * The other refresh files only know about coordinates, not the architecture - * of the frame buffer. - * - * Conveniently, the frame buffer is a linear one, and we need only the base - * address, and the total size == width*height*depth/8., - */ - -byte *viewimage; -int viewwidth; -int scaledviewwidth; -int viewheight; -int viewwindowx; -int viewwindowy; -pixel_t *ylookup[MAXHEIGHT]; -int columnofs[MAXWIDTH]; - -/* Color tables for different players, translate a limited part to another - * (color ramps used for suit colors). - */ - -byte translations[3][256]; - -lighttable_t *dc_colormap; -int dc_x; -int dc_yl; -int dc_yh; -fixed_t dc_iscale; -fixed_t dc_texturemid; - -/* first pixel in a column (possibly virtual) */ - -byte *dc_source; - -int fuzzoffset[FUZZTABLE] = -{ - FUZZOFF, -FUZZOFF, FUZZOFF, -FUZZOFF, FUZZOFF, FUZZOFF, -FUZZOFF, - FUZZOFF, FUZZOFF, -FUZZOFF, FUZZOFF, FUZZOFF, FUZZOFF, -FUZZOFF, - FUZZOFF, FUZZOFF, FUZZOFF, -FUZZOFF, -FUZZOFF, -FUZZOFF, -FUZZOFF, - FUZZOFF, -FUZZOFF, -FUZZOFF, FUZZOFF, FUZZOFF, FUZZOFF, FUZZOFF, - -FUZZOFF, FUZZOFF, -FUZZOFF, FUZZOFF, FUZZOFF, -FUZZOFF, -FUZZOFF, - FUZZOFF, FUZZOFF, -FUZZOFF, -FUZZOFF, -FUZZOFF, -FUZZOFF, FUZZOFF, - FUZZOFF, FUZZOFF, FUZZOFF, -FUZZOFF, FUZZOFF, FUZZOFF, -FUZZOFF, - FUZZOFF, -}; - -int fuzzpos = 0; - -byte *dc_translation; -byte *translationtables; - -int ds_y; -int ds_x1; -int ds_x2; - -lighttable_t *ds_colormap; - -fixed_t ds_xfrac; -fixed_t ds_yfrac; -fixed_t ds_xstep; -fixed_t ds_ystep; - -/* start of a 64*64 tile image */ - -byte *ds_source; - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/* Backing buffer containing the bezel drawn around the screen and - * surrounding background. - */ - -static pixel_t *background_buffer = NULL; - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/* Source is the top of the column to scale. - * - * A column is a vertical slice/span from a wall texture that, given the DOOM - * style restrictions on the view orientation, will always have constant z - * depth. - * - * Thus a special case loop for very fast rendering can be used. It has also - * been used with Wolfenstein 3D. - */ - -void r_draw_column(void) -{ - int count; - pixel_t *dest; - fixed_t frac; - fixed_t fracstep; - - count = dc_yh - dc_yl; - - /* Zero length, column does not exceed a pixel. */ - - if (count < 0) return; - -#ifdef CONFIG_GAMES_NXDOOM_RANGECHECK - if ((unsigned)dc_x >= SCREENWIDTH || dc_yl < 0 || dc_yh >= SCREENHEIGHT) - i_error("r_draw_column: %i to %i at %i", dc_yl, dc_yh, dc_x); -#endif - - /* Framebuffer destination address. - * Use ylookup LUT to avoid multiply with ScreenWidth. - * Use columnofs LUT for subwindows? - */ - - dest = ylookup[dc_yl] + columnofs[dc_x]; - - /* Determine scaling, which is the only mapping to be done. */ - - fracstep = dc_iscale; - frac = dc_texturemid + (dc_yl - centery) * fracstep; - - /* Inner loop that does the actual texture mapping, - * e.g. a DDA-lile scaling. - * This is as fast as it gets. - */ - - do - { - /* Re-map color indices from wall texture column - * using a lighting/special effects LUT. - */ - - *dest = dc_colormap[dc_source[(frac >> FRACBITS) & 127]]; - - dest += SCREENWIDTH; - frac += fracstep; - } - while (count--); -} - -/* UNUSED. Loop unrolled. */ - -#if 0 -void r_draw_column(void) -{ - int count; - byte *source; - byte *dest; - byte *colormap; - - unsigned frac; - unsigned fracstep; - unsigned fracstep2; - unsigned fracstep3; - unsigned fracstep4; - - count = dc_yh - dc_yl + 1; - - source = dc_source; - colormap = dc_colormap; - dest = ylookup[dc_yl] + columnofs[dc_x]; - - fracstep = dc_iscale << 9; - frac = (dc_texturemid + (dc_yl - centery) * dc_iscale) << 9; - - fracstep2 = fracstep + fracstep; - fracstep3 = fracstep2 + fracstep; - fracstep4 = fracstep3 + fracstep; - - while (count >= 8) - { - dest[0] = colormap[source[frac >> 25]]; - dest[SCREENWIDTH] = colormap[source[(frac + fracstep) >> 25]]; - dest[SCREENWIDTH * 2] = colormap[source[(frac + fracstep2) >> 25]]; - dest[SCREENWIDTH * 3] = colormap[source[(frac + fracstep3) >> 25]]; - - frac += fracstep4; - - dest[SCREENWIDTH * 4] = colormap[source[frac >> 25]]; - dest[SCREENWIDTH * 5] = colormap[source[(frac + fracstep) >> 25]]; - dest[SCREENWIDTH * 6] = colormap[source[(frac + fracstep2) >> 25]]; - dest[SCREENWIDTH * 7] = colormap[source[(frac + fracstep3) >> 25]]; - - frac += fracstep4; - dest += SCREENWIDTH * 8; - count -= 8; - } - - while (count > 0) - { - *dest = colormap[source[frac >> 25]]; - dest += SCREENWIDTH; - frac += fracstep; - count--; - } -} -#endif - -void r_draw_column_low(void) -{ - int count; - pixel_t *dest; - pixel_t *dest2; - fixed_t frac; - fixed_t fracstep; - int x; - - count = dc_yh - dc_yl; - - /* Zero length. */ - - if (count < 0) return; - -#ifdef CONFIG_GAMES_NXDOOM_RANGECHECK - if ((unsigned)dc_x >= SCREENWIDTH || dc_yl < 0 || dc_yh >= SCREENHEIGHT) - { - i_error("r_draw_column: %i to %i at %i", dc_yl, dc_yh, dc_x); - } -#endif - - /* Blocky mode, need to multiply by 2. */ - - x = dc_x << 1; - - dest = ylookup[dc_yl] + columnofs[x]; - dest2 = ylookup[dc_yl] + columnofs[x + 1]; - - fracstep = dc_iscale; - frac = dc_texturemid + (dc_yl - centery) * fracstep; - - do - { - /* Hack. Does not work correctly. */ - - *dest2 = *dest = dc_colormap[dc_source[(frac >> FRACBITS) & 127]]; - dest += SCREENWIDTH; - dest2 += SCREENWIDTH; - frac += fracstep; - } - while (count--); -} - -/* Framebuffer postprocessing. - * - * Creates a fuzzy image by copying pixels from adjacent ones to left and - * right. - * - * Used with an all black colormap, this could create the SHADOW effect, i.e. - * spectres and invisible players. - */ - -void r_draw_fuzz_column(void) -{ - int count; - pixel_t *dest; - - /* Adjust borders. Low... */ - - if (!dc_yl) dc_yl = 1; - - /* .. and high. */ - - if (dc_yh == viewheight - 1) dc_yh = viewheight - 2; - - count = dc_yh - dc_yl; - - /* Zero length. */ - - if (count < 0) return; - -#ifdef CONFIG_GAMES_NXDOOM_RANGECHECK - if ((unsigned)dc_x >= SCREENWIDTH || dc_yl < 0 || dc_yh >= SCREENHEIGHT) - { - i_error("r_draw_fuzz_column: %i to %i at %i", dc_yl, dc_yh, dc_x); - } -#endif - - dest = ylookup[dc_yl] + columnofs[dc_x]; - - /* Looks like an attempt at dithering, - * using the colormap #6 (of 0-31, a bit - * brighter than average). - */ - - do - { - /* Lookup framebuffer, and retrieve a pixel that is either one column - * left or right of the current one. Add index from colormap to index. - */ - - *dest = colormaps[6 * 256 + dest[fuzzoffset[fuzzpos]]]; - - /* Clamp table lookup index. */ - - if (++fuzzpos == FUZZTABLE) fuzzpos = 0; - - dest += SCREENWIDTH; - } - while (count--); -} - -/* low detail mode version */ - -void r_draw_fuzz_column_low(void) -{ - int count; - pixel_t *dest; - pixel_t *dest2; - int x; - - /* Adjust borders. Low... */ - - if (!dc_yl) dc_yl = 1; - - /* .. and high. */ - - if (dc_yh == viewheight - 1) dc_yh = viewheight - 2; - - count = dc_yh - dc_yl; - - /* Zero length. */ - - if (count < 0) return; - - /* low detail mode, need to multiply by 2 */ - - x = dc_x << 1; - -#ifdef CONFIG_GAMES_NXDOOM_RANGECHECK - if ((unsigned)x >= SCREENWIDTH || dc_yl < 0 || dc_yh >= SCREENHEIGHT) - { - i_error("r_draw_fuzz_column: %i to %i at %i", dc_yl, dc_yh, dc_x); - } -#endif - - dest = ylookup[dc_yl] + columnofs[x]; - dest2 = ylookup[dc_yl] + columnofs[x + 1]; - - /* Looks like an attempt at dithering, using the colormap #6 - * (of 0-31, a bit brighter than average). - */ - - do - { - /* Lookup framebuffer, and retrieve a pixel that is either one column - * left or right of the current one. Add index from colormap to index. - */ - - *dest = colormaps[6 * 256 + dest[fuzzoffset[fuzzpos]]]; - *dest2 = colormaps[6 * 256 + dest2[fuzzoffset[fuzzpos]]]; - - /* Clamp table lookup index. */ - - if (++fuzzpos == FUZZTABLE) fuzzpos = 0; - - dest += SCREENWIDTH; - dest2 += SCREENWIDTH; - } - while (count--); -} - -/* r_draw_translated_column - * - * Used to draw player sprites with the green colorramp mapped to others. - * - * Could be used with different translation tables, e.g. the lighter colored - * version of the BaronOfHell, the HellKnight, uses identical sprites, kinda - * brightened up. - */ - -void r_draw_translated_column(void) -{ - int count; - pixel_t *dest; - fixed_t frac; - fixed_t fracstep; - - count = dc_yh - dc_yl; - if (count < 0) return; - -#ifdef CONFIG_GAMES_NXDOOM_RANGECHECK - if ((unsigned)dc_x >= SCREENWIDTH || dc_yl < 0 || dc_yh >= SCREENHEIGHT) - { - i_error("r_draw_column: %i to %i at %i", dc_yl, dc_yh, dc_x); - } - -#endif - - dest = ylookup[dc_yl] + columnofs[dc_x]; - - /* Looks familiar. */ - - fracstep = dc_iscale; - frac = dc_texturemid + (dc_yl - centery) * fracstep; - - /* Here we do an additional index re-mapping. */ - - do - { - /* Translation tables are used to map certain colorramps to other ones, - * used with PLAY sprites. - * - * Thus the "green" ramp of the player 0 sprite is mapped to gray, red, - * black/indigo. - */ - - *dest = dc_colormap[dc_translation[dc_source[frac >> FRACBITS]]]; - dest += SCREENWIDTH; - - frac += fracstep; - } - while (count--); -} - -void r_draw_translated_column_low(void) -{ - int count; - pixel_t *dest; - pixel_t *dest2; - fixed_t frac; - fixed_t fracstep; - int x; - - count = dc_yh - dc_yl; - if (count < 0) return; - - /* low detail, need to scale by 2 */ - - x = dc_x << 1; - -#ifdef CONFIG_GAMES_NXDOOM_RANGECHECK - if ((unsigned)x >= SCREENWIDTH || dc_yl < 0 || dc_yh >= SCREENHEIGHT) - { - i_error("r_draw_column: %i to %i at %i", dc_yl, dc_yh, x); - } - -#endif - - dest = ylookup[dc_yl] + columnofs[x]; - dest2 = ylookup[dc_yl] + columnofs[x + 1]; - - /* Looks familiar. */ - - fracstep = dc_iscale; - frac = dc_texturemid + (dc_yl - centery) * fracstep; - - /* Here we do an additional index re-mapping. */ - - do - { - /* Translation tables are used to map certain colorramps to other ones, - * used with PLAY sprites. - * - * Thus the "green" ramp of the player 0 sprite is mapped to gray, red, - * black/indigo. - */ - - *dest = dc_colormap[dc_translation[dc_source[frac >> FRACBITS]]]; - *dest2 = dc_colormap[dc_translation[dc_source[frac >> FRACBITS]]]; - dest += SCREENWIDTH; - dest2 += SCREENWIDTH; - - frac += fracstep; - } - while (count--); -} - -/* r_init_translation_table - * - * Creates the translation tables to map the green color ramp to gray, brown, - * red. - * - * Assumes a given structure of the PLAYPAL. Could be read from a lump - * instead. - */ - -void r_init_translation_table(void) -{ - int i; - - translationtables = z_malloc(256 * 3, PU_STATIC, 0); - - /* translate just the 16 green colors */ - - for (i = 0; i < 256; i++) - { - if (i >= 0x70 && i <= 0x7f) - { - /* map green ramp to gray, brown, red */ - - translationtables[i] = 0x60 + (i & 0xf); - translationtables[i + 256] = 0x40 + (i & 0xf); - translationtables[i + 512] = 0x20 + (i & 0xf); - } - else - { - /* Keep all other colors as is. */ - - translationtables[i] = translationtables[i + 256] = - translationtables[i + 512] = i; - } - } -} - -/* r_draw_span - * - * With DOOM style restrictions on view orientation, the floors and ceilings - * consist of horizontal slices or spans with constant z depth. - * - * However, rotation around the world z axis is possible, thus this mapping, - * while simpler and faster than perspective correct texture mapping, has to - * traverse the texture at an angle in all but a few cases. - * - * In consequence, flats are not stored by column (like walls), and the inner - * loop has to step in texture space u and v. - * - * Draws the actual span. - */ - -void r_draw_span(void) -{ - unsigned int position; - unsigned int step; - pixel_t *dest; - int count; - int spot; - unsigned int xtemp; - unsigned int ytemp; - -#ifdef CONFIG_GAMES_NXDOOM_RANGECHECK - if (ds_x2 < ds_x1 || ds_x1 < 0 || ds_x2 >= SCREENWIDTH || - (unsigned)ds_y > SCREENHEIGHT) - { - i_error("r_draw_span: %i to %i at %i", ds_x1, ds_x2, ds_y); - } -#endif - - /* Pack position and step variables into a single 32-bit integer, - * with x in the top 16 bits and y in the bottom 16 bits. For - * each 16-bit part, the top 6 bits are the integer part and the - * bottom 10 bits are the fractional part of the pixel position. - */ - - position = ((ds_xfrac << 10) & 0xffff0000) | - ((ds_yfrac >> 6) & 0x0000ffff); - step = ((ds_xstep << 10) & 0xffff0000) | ((ds_ystep >> 6) & 0x0000ffff); - - dest = ylookup[ds_y] + columnofs[ds_x1]; - - /* We do not check for zero spans here? */ - - count = ds_x2 - ds_x1; - - do - { - /* Calculate current texture index in u,v. */ - - ytemp = (position >> 4) & 0x0fc0; - xtemp = (position >> 26); - spot = xtemp | ytemp; - - /* Lookup pixel from flat texture tile, re-index using light/colormap. - */ - - *dest++ = ds_colormap[ds_source[spot]]; - - position += step; - } - while (count--); -} - -/* UNUSED. Loop unrolled by 4. */ - -#if 0 -void r_draw_span(void) -{ - unsigned position; - unsigned step; - - byte *source; - byte *colormap; - pixel_t *dest; - - unsigned count; - usingned spot; - unsigned value; - unsigned temp; - unsigned xtemp; - unsigned ytemp; - - position = ((ds_xfrac << 10) & 0xffff0000) | ((ds_yfrac >> 6) & 0xffff); - step = ((ds_xstep << 10) & 0xffff0000) | ((ds_ystep >> 6) & 0xffff); - - source = ds_source; - colormap = ds_colormap; - dest = ylookup[ds_y] + columnofs[ds_x1]; - count = ds_x2 - ds_x1 + 1; - - while (count >= 4) - { - ytemp = position >> 4; - ytemp = ytemp & 4032; - xtemp = position >> 26; - spot = xtemp | ytemp; - position += step; - dest[0] = colormap[source[spot]]; - - ytemp = position >> 4; - ytemp = ytemp & 4032; - xtemp = position >> 26; - spot = xtemp | ytemp; - position += step; - dest[1] = colormap[source[spot]]; - - ytemp = position >> 4; - ytemp = ytemp & 4032; - xtemp = position >> 26; - spot = xtemp | ytemp; - position += step; - dest[2] = colormap[source[spot]]; - - ytemp = position >> 4; - ytemp = ytemp & 4032; - xtemp = position >> 26; - spot = xtemp | ytemp; - position += step; - dest[3] = colormap[source[spot]]; - - count -= 4; - dest += 4; - } - while (count > 0) - { - ytemp = position >> 4; - ytemp = ytemp & 4032; - xtemp = position >> 26; - spot = xtemp | ytemp; - position += step; - *dest++ = colormap[source[spot]]; - count--; - } -} -#endif - -/* Again.. */ - -void r_draw_span_low(void) -{ - unsigned int position; - unsigned int step; - unsigned int xtemp; - unsigned int ytemp; - pixel_t *dest; - int count; - int spot; - -#ifdef CONFIG_GAMES_NXDOOM_RANGECHECK - if (ds_x2 < ds_x1 || ds_x1 < 0 || ds_x2 >= SCREENWIDTH || - (unsigned)ds_y > SCREENHEIGHT) - { - i_error("r_draw_span: %i to %i at %i", ds_x1, ds_x2, ds_y); - } -#endif - - position = ((ds_xfrac << 10) & 0xffff0000) | - ((ds_yfrac >> 6) & 0x0000ffff); - step = ((ds_xstep << 10) & 0xffff0000) | ((ds_ystep >> 6) & 0x0000ffff); - - count = (ds_x2 - ds_x1); - - /* Blocky mode, need to multiply by 2. */ - - ds_x1 <<= 1; - ds_x2 <<= 1; - - dest = ylookup[ds_y] + columnofs[ds_x1]; - - do - { - /* Calculate current texture index in u,v. */ - - ytemp = (position >> 4) & 0x0fc0; - xtemp = (position >> 26); - spot = xtemp | ytemp; - - /* Lowres/blocky mode does it twice, while scale is adjusted - * appropriately. - */ - - *dest++ = ds_colormap[ds_source[spot]]; - *dest++ = ds_colormap[ds_source[spot]]; - - position += step; - } - while (count--); -} - -/* r_init_buffer - * - * Creates lookup tables that avoid multiplies and other hazzles for getting - * the framebuffer address of a pixel to draw. - */ - -void r_init_buffer(int width, int height) -{ - int i; - - /* Handle resize, - * e.g. smaller view windows - * with border and/or status bar. - */ - - viewwindowx = (SCREENWIDTH - width) >> 1; - - /* Column offset. For windows. */ - - for (i = 0; i < width; i++) - columnofs[i] = viewwindowx + i; - - /* Samw with base row offset. */ - - if (width == SCREENWIDTH) - viewwindowy = 0; - else - viewwindowy = (SCREENHEIGHT - SBARHEIGHT - height) >> 1; - - /* Preclaculate all row offsets. */ - - for (i = 0; i < height; i++) - ylookup[i] = i_video_buffer + (i + viewwindowy) * SCREENWIDTH; -} - -/* r_fill_back_screen - * - * Fills the back screen with a pattern for variable screen sizes - * Also draws a beveled edge. - */ - -void r_fill_back_screen(void) -{ - byte *src; - pixel_t *dest; - int x; - int y; - patch_t *patch; - - /* DOOM border patch. */ - - const char *name1 = ("FLOOR7_2"); - - /* DOOM II border patch. */ - - const char *name2 = ("GRNROCK"); - - const char *name; - - /* If we are running full screen, there is no need to do any of this, - * and the background buffer can be freed if it was previously in use. - */ - - if (scaledviewwidth == SCREENWIDTH) - { - if (background_buffer != NULL) - { - z_free(background_buffer); - background_buffer = NULL; - } - - return; - } - - /* Allocate the background buffer if necessary */ - - if (background_buffer == NULL) - { - background_buffer = z_malloc( - SCREENWIDTH * (SCREENHEIGHT - SBARHEIGHT) * - sizeof(*background_buffer), PU_STATIC, NULL); - } - - if (gamemode == commercial) - name = name2; - else - name = name1; - - src = w_cache_lump_name(name, PU_CACHE); - dest = background_buffer; - - for (y = 0; y < SCREENHEIGHT - SBARHEIGHT; y++) - { - for (x = 0; x < SCREENWIDTH / 64; x++) - { - memcpy(dest, src + ((y & 63) << 6), 64); - dest += 64; - } - - if (SCREENWIDTH & 63) - { - memcpy(dest, src + ((y & 63) << 6), SCREENWIDTH & 63); - dest += (SCREENWIDTH & 63); - } - } - - /* Draw screen and bezel; this is done to a separate screen buffer. */ - - v_use_buffer(background_buffer); - - patch = w_cache_lump_name(("brdr_t"), PU_CACHE); - - for (x = 0; x < scaledviewwidth; x += 8) - v_draw_patch(viewwindowx + x, viewwindowy - 8, patch); - patch = w_cache_lump_name(("brdr_b"), PU_CACHE); - - for (x = 0; x < scaledviewwidth; x += 8) - v_draw_patch(viewwindowx + x, viewwindowy + viewheight, patch); - patch = w_cache_lump_name(("brdr_l"), PU_CACHE); - - for (y = 0; y < viewheight; y += 8) - v_draw_patch(viewwindowx - 8, viewwindowy + y, patch); - patch = w_cache_lump_name(("brdr_r"), PU_CACHE); - - for (y = 0; y < viewheight; y += 8) - v_draw_patch(viewwindowx + scaledviewwidth, viewwindowy + y, patch); - - /* Draw beveled edge. */ - - v_draw_patch(viewwindowx - 8, viewwindowy - 8, - w_cache_lump_name(("brdr_tl"), PU_CACHE)); - - v_draw_patch(viewwindowx + scaledviewwidth, viewwindowy - 8, - w_cache_lump_name(("brdr_tr"), PU_CACHE)); - - v_draw_patch(viewwindowx - 8, viewwindowy + viewheight, - w_cache_lump_name(("brdr_bl"), PU_CACHE)); - - v_draw_patch(viewwindowx + scaledviewwidth, viewwindowy + viewheight, - w_cache_lump_name(("brdr_br"), PU_CACHE)); - - v_restore_buffer(); -} - -/* Copy a screen buffer. */ - -void r_video_erase(unsigned ofs, int count) -{ - /* LFB copy. - * This might not be a good idea if memcpy is not optional, e.g. byte by - * byte on a 32bit CPU, as GNU GCC/Linux libc did at one point. - */ - - if (background_buffer != NULL) - { - memcpy(i_video_buffer + ofs, background_buffer + ofs, - count * sizeof(*i_video_buffer)); - } -} - -/* r_draw_view_border - * Draws the border around the view for different size windows? - */ - -void r_draw_view_border(void) -{ - int top; - int side; - int ofs; - int i; - - if (scaledviewwidth == SCREENWIDTH) return; - - top = ((SCREENHEIGHT - SBARHEIGHT) - viewheight) / 2; - side = (SCREENWIDTH - scaledviewwidth) / 2; - - /* copy top and one line of left side */ - - r_video_erase(0, top * SCREENWIDTH + side); - - /* copy one line of right side and bottom */ - - ofs = (viewheight + top) * SCREENWIDTH - side; - r_video_erase(ofs, top * SCREENWIDTH + side); - - /* copy sides using wraparound */ - - ofs = top * SCREENWIDTH + SCREENWIDTH - side; - side <<= 1; - - for (i = 1; i < viewheight; i++) - { - r_video_erase(ofs, side); - ofs += SCREENWIDTH; - } - - /* ? */ - - v_mark_rect(0, 0, SCREENWIDTH, SCREENHEIGHT - SBARHEIGHT); -} diff --git a/games/NXDoom/src/doom/r_draw.h b/games/NXDoom/src/doom/r_draw.h deleted file mode 100644 index 47e85c1ed..000000000 --- a/games/NXDoom/src/doom/r_draw.h +++ /dev/null @@ -1,107 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/r_draw.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * System specific interface stuff. - * - ****************************************************************************/ - -#ifndef __R_DRAW__ -#define __R_DRAW__ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -extern lighttable_t *dc_colormap; -extern int dc_x; -extern int dc_yl; -extern int dc_yh; -extern fixed_t dc_iscale; -extern fixed_t dc_texturemid; - -/* first pixel in a column */ - -extern byte *dc_source; - -extern int ds_y; -extern int ds_x1; -extern int ds_x2; - -extern lighttable_t *ds_colormap; - -extern fixed_t ds_xfrac; -extern fixed_t ds_yfrac; -extern fixed_t ds_xstep; -extern fixed_t ds_ystep; - -/* start of a 64*64 tile image */ - -extern byte *ds_source; - -extern byte *translationtables; -extern byte *dc_translation; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/* Span blitting for rows, floor/ceiling. No Spectre effect needed. */ - -void r_draw_span(void); - -/* Low resolution mode, 160x200? */ - -void r_draw_span_low(void); - -void r_init_buffer(int width, int height); - -/* Initialize color translation tables, for player rendering etc. */ - -void r_init_translation_table(void); - -/* Rendering function. */ - -void r_fill_back_screen(void); - -/* If the view size is not full screen, draws a border around it. */ - -void r_draw_view_border(void); - -/* The span blitting interface. - * Hook in assembler or system specific BLT here. - */ - -void r_draw_column(void); -void r_draw_column_low(void); - -/* The Spectre/Invisibility effect. */ - -void r_draw_fuzz_column(void); -void r_draw_fuzz_column_low(void); - -/* Draw with color translation tables, for player sprite rendering, - * Green/Red/Blue/Indigo shirts. - */ - -void r_draw_translated_column(void); -void r_draw_translated_column_low(void); - -void r_video_erase(unsigned ofs, int count); - -#endif /* __R_DRAW__ */ diff --git a/games/NXDoom/src/doom/r_local.h b/games/NXDoom/src/doom/r_local.h deleted file mode 100644 index b1fd33e1c..000000000 --- a/games/NXDoom/src/doom/r_local.h +++ /dev/null @@ -1,54 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/r_local.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Refresh (R_*) module, global header. - * All the rendering/drawing stuff is here. - * - ****************************************************************************/ - -#ifndef __R_LOCAL__ -#define __R_LOCAL__ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -/* Binary Angles, sine/cosine/atan lookups. */ - -#include "tables.h" - -/* Screen size related parameters. */ - -#include "doomdef.h" - -/* Include the refresh/render data structs. */ - -#include "r_data.h" - -/* Separate header file for each module. */ - -#include "r_bsp.h" -#include "r_data.h" -#include "r_draw.h" -#include "r_main.h" -#include "r_plane.h" -#include "r_segs.h" -#include "r_things.h" - -#endif /* __R_LOCAL__ */ diff --git a/games/NXDoom/src/doom/r_main.c b/games/NXDoom/src/doom/r_main.c deleted file mode 100644 index b50cdc337..000000000 --- a/games/NXDoom/src/doom/r_main.c +++ /dev/null @@ -1,883 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/r_main.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Rendering main loop and setup functions, utility functions (BSP, - * geometry, trigonometry). See tables.c, too. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -#include "d_loop.h" -#include "doomdef.h" - -#include "m_bbox.h" -#include "m_menu.h" - -#include "r_local.h" -#include "r_sky.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* Fineangles in the SCREENWIDTH wide window. */ - -#define FIELDOFVIEW 2048 - -#define DISTMAP 2 - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -int viewangleoffset; - -/* increment every time a check is made */ - -int validcount = 1; - -lighttable_t *fixedcolormap; - -int centerx; -int centery; - -fixed_t centerxfrac; -fixed_t centeryfrac; -fixed_t projection; - -/* just for profiling purposes */ - -int framecount; - -int sscount; -int linecount; -int loopcount; - -fixed_t viewx; -fixed_t viewy; -fixed_t viewz; - -angle_t viewangle; - -fixed_t viewcos; -fixed_t viewsin; - -player_t *viewplayer; - -/* 0 = high, 1 = low */ - -int detailshift; - -/* precalculated math tables */ - -angle_t clipangle; - -/* The viewangletox[viewangle + FINEANGLES/4] lookup - * maps the visible view angles to screen X coordinates, - * flattening the arc to a flat projection plane. - * There will be many angles mapped to the same X. - */ - -int viewangletox[FINEANGLES / 2]; - -/* The xtoviewangleangle[] table maps a screen pixel - * to the lowest viewangle that maps back to x ranges - * from clipangle to -clipangle. - */ - -angle_t xtoviewangle[SCREENWIDTH + 1]; - -lighttable_t *scalelight[LIGHTLEVELS][MAXLIGHTSCALE]; -lighttable_t *scalelightfixed[MAXLIGHTSCALE]; -lighttable_t *zlight[LIGHTLEVELS][MAXLIGHTZ]; - -/* bumped light from gun blasts */ - -int extralight; - -void (*colfunc)(void); -void (*basecolfunc)(void); -void (*fuzzcolfunc)(void); -void (*transcolfunc)(void); -void (*spanfunc)(void); - -boolean setsizeneeded; -int setblocks; -int setdetail; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: r_add_point_to_box - * - * Description: - * Expand a given bbox so that it encloses a given point. - * - ****************************************************************************/ - -#if 0 /* UNUSED */ -static void r_add_point_to_box(int x, int y, fixed_t *box) -{ - if (x < box[BOXLEFT]) box[BOXLEFT] = x; - if (x > box[BOXRIGHT]) box[BOXRIGHT] = x; - if (y < box[BOXBOTTOM]) box[BOXBOTTOM] = y; - if (y > box[BOXTOP]) box[BOXTOP] = y; -} -#endif - -/**************************************************************************** - * Name: r_setup_frame - ****************************************************************************/ - -static void r_setup_frame(player_t *player) -{ - int i; - - viewplayer = player; - viewx = player->mo->x; - viewy = player->mo->y; - viewangle = player->mo->angle + viewangleoffset; - extralight = player->extralight; - - viewz = player->viewz; - - viewsin = finesine[viewangle >> ANGLETOFINESHIFT]; - viewcos = finecosine[viewangle >> ANGLETOFINESHIFT]; - - sscount = 0; - - if (player->fixedcolormap) - { - fixedcolormap = colormaps + player->fixedcolormap * 256; - - walllights = scalelightfixed; - - for (i = 0; i < MAXLIGHTSCALE; i++) - scalelightfixed[i] = fixedcolormap; - } - else - fixedcolormap = 0; - - framecount++; - validcount++; -} - -/**************************************************************************** - * Name: r_init_light_tables - * - * Description: - * Only inits the zlight table, because the scalelight table changes with - * view size. - * - ****************************************************************************/ - -static void r_init_light_tables(void) -{ - int i; - int j; - int level; - int startmap; - int scale; - - /* Calculate the light levels to use for each level / distance combination. - */ - - for (i = 0; i < LIGHTLEVELS; i++) - { - startmap = ((LIGHTLEVELS - 1 - i) * 2) * NUMCOLORMAPS / LIGHTLEVELS; - for (j = 0; j < MAXLIGHTZ; j++) - { - scale = fixed_div((SCREENWIDTH / 2 * FRACUNIT), - (j + 1) << LIGHTZSHIFT); - scale >>= LIGHTSCALESHIFT; - level = startmap - scale / DISTMAP; - - if (level < 0) level = 0; - - if (level >= NUMCOLORMAPS) level = NUMCOLORMAPS - 1; - - zlight[i][j] = colormaps + level * 256; - } - } -} - -/**************************************************************************** - * Name: r_init_tables - ****************************************************************************/ - -static void r_init_tables(void) -{ -#if 0 /* UNUSED: now getting from tables.c */ - int i; - float a; - float fv; - int t; - - /* viewangle tangent table */ - - for (i = 0; i < FINEANGLES / 2; i++) - { - a = (i - FINEANGLES / 4 + 0.5) * PI * 2 / FINEANGLES; - fv = FRACUNIT * tan(a); - t = fv; - finetangent[i] = t; - } - - /* finesine table */ - - for (i = 0; i < 5 * FINEANGLES / 4; i++) - { - /* OPTIMIZE: mirror... */ - - a = (i + 0.5) * PI * 2 / FINEANGLES; - t = FRACUNIT * sin(a); - finesine[i] = t; - } -#endif -} - -/**************************************************************************** - * Name: r_init_point_to_angle - ****************************************************************************/ - -static void r_init_point_to_angle(void) -{ -#if 0 /* UNUSED - now getting from tables.c */ - int i; - long t; - float f; - - /* slope (tangent) to angle lookup */ - - for (i = 0; i <= SLOPERANGE; i++) - { - f = atan((float)i / SLOPERANGE) / (3.141592657 * 2); - t = 0xffffffff * f; - tantoangle[i] = t; - } -#endif -} - -/**************************************************************************** - * Name: r_init_texture_mapping - ****************************************************************************/ - -static void r_init_texture_mapping(void) -{ - int i; - int x; - int t; - fixed_t focallength; - - /* Use tangent table to generate viewangletox: - * viewangletox will give the next greatest x - * after the view angle. - * - * Calc focallength - * so FIELDOFVIEW angles covers SCREENWIDTH. - */ - - focallength = - fixed_div(centerxfrac, finetangent[FINEANGLES / 4 + FIELDOFVIEW / 2]); - - for (i = 0; i < FINEANGLES / 2; i++) - { - if (finetangent[i] > FRACUNIT * 2) - t = -1; - else if (finetangent[i] < -FRACUNIT * 2) - t = viewwidth + 1; - else - { - t = fixed_mul(finetangent[i], focallength); - t = (centerxfrac - t + FRACUNIT - 1) >> FRACBITS; - - if (t < -1) - t = -1; - else if (t > viewwidth + 1) - t = viewwidth + 1; - } - - viewangletox[i] = t; - } - - /* Scan viewangletox[] to generate xtoviewangle[]: - * xtoviewangle will give the smallest view angle - * that maps to x. - */ - - for (x = 0; x <= viewwidth; x++) - { - i = 0; - while (viewangletox[i] > x) - i++; - xtoviewangle[x] = (i << ANGLETOFINESHIFT) - ANG90; - } - - /* Take out the fencepost cases from viewangletox. */ - - for (i = 0; i < FINEANGLES / 2; i++) - { - t = fixed_mul(finetangent[i], focallength); - t = centerx - t; - - if (viewangletox[i] == -1) - viewangletox[i] = 0; - else if (viewangletox[i] == viewwidth + 1) - viewangletox[i] = viewwidth; - } - - clipangle = xtoviewangle[0]; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: r_point_on_side - * - * Description: - * Traverse BSP (sub) tree, check point against partition plane. - * - * Returns: - * Side 0 (front) or 1 (back). - ****************************************************************************/ - -int r_point_on_side(fixed_t x, fixed_t y, node_t *node) -{ - fixed_t dx; - fixed_t dy; - fixed_t left; - fixed_t right; - - if (!node->dx) - { - if (x <= node->x) return node->dy > 0; - - return node->dy < 0; - } - - if (!node->dy) - { - if (y <= node->y) return node->dx < 0; - - return node->dx > 0; - } - - dx = (x - node->x); - dy = (y - node->y); - - /* Try to quickly decide by looking at sign bits. */ - - if ((node->dy ^ node->dx ^ dx ^ dy) & 0x80000000) - { - if ((node->dy ^ dx) & 0x80000000) - { - return 1; /* (left is negative) */ - } - - return 0; - } - - left = fixed_mul(node->dy >> FRACBITS, dx); - right = fixed_mul(dy, node->dx >> FRACBITS); - - if (right < left) - { - return 0; /* front side */ - } - - return 1; /* back side */ -} - -/**************************************************************************** - * Name: r_point_on_seg_side - ****************************************************************************/ - -int r_point_on_seg_side(fixed_t x, fixed_t y, seg_t *line) -{ - fixed_t lx; - fixed_t ly; - fixed_t ldx; - fixed_t ldy; - fixed_t dx; - fixed_t dy; - fixed_t left; - fixed_t right; - - lx = line->v1->x; - ly = line->v1->y; - - ldx = line->v2->x - lx; - ldy = line->v2->y - ly; - - if (!ldx) - { - if (x <= lx) return ldy > 0; - - return ldy < 0; - } - - if (!ldy) - { - if (y <= ly) return ldx < 0; - - return ldx > 0; - } - - dx = (x - lx); - dy = (y - ly); - - /* Try to quickly decide by looking at sign bits. */ - - if ((ldy ^ ldx ^ dx ^ dy) & 0x80000000) - { - if ((ldy ^ dx) & 0x80000000) - { - return 1; /* (left is negative) */ - } - - return 0; - } - - left = fixed_mul(ldy >> FRACBITS, dx); - right = fixed_mul(dy, ldx >> FRACBITS); - - if (right < left) - { - return 0; /* front side */ - } - - return 1; /* back side */ -} - -/**************************************************************************** - * Name: r_point_to_angle - * - * Description: - * To get a global angle from cartesian coordinates, the coordinates are - * flipped until they are in the first octant of the coordinate system, then - * the y (<=x) is scaled and divided by x to get a tangent (slope) value - * which is looked up in the tantoangle[] table. - * - ****************************************************************************/ - -angle_t r_point_to_angle(fixed_t x, fixed_t y) -{ - x -= viewx; - y -= viewy; - - if ((!x) && (!y)) return 0; - - if (x >= 0) - { - /* x >=0 */ - - if (y >= 0) - { - /* y>= 0 */ - - if (x > y) - { - return tantoangle[slope_div(y, x)]; /* octant 0 */ - } - else - { - return ANG90 - 1 - tantoangle[slope_div(x, y)]; /* octant 1 */ - } - } - else - { - /* y<0 */ - - y = -y; - - if (x > y) - { - return -tantoangle[slope_div(y, x)]; /* octant 8 */ - } - else - { - return ANG270 + tantoangle[slope_div(x, y)]; /* octant 7 */ - } - } - } - else - { - /* x<0 */ - - x = -x; - - if (y >= 0) - { - /* y>= 0 */ - - if (x > y) - { - return ANG180 - 1 - tantoangle[slope_div(y, x)]; /* octant 3 */ - } - else - { - return ANG90 + tantoangle[slope_div(x, y)]; /* octant 2 */ - } - } - else - { - y = -y; /* y<0 */ - - if (x > y) - { - return ANG180 + tantoangle[slope_div(y, x)]; /* octant 4 */ - } - else - { - return ANG270 - 1 - tantoangle[slope_div(x, y)]; /* octant 5 */ - } - } - } - - return 0; -} - -/**************************************************************************** - * Name: r_point_to_angle2 - ****************************************************************************/ - -angle_t r_point_to_angle2(fixed_t x1, fixed_t y1, fixed_t x2, fixed_t y2) -{ - viewx = x1; - viewy = y1; - - return r_point_to_angle(x2, y2); -} - -/**************************************************************************** - * Name: r_point_to_dist - ****************************************************************************/ - -fixed_t r_point_to_dist(fixed_t x, fixed_t y) -{ - int angle; - fixed_t dx; - fixed_t dy; - fixed_t temp; - fixed_t dist; - fixed_t frac; - - dx = abs(x - viewx); - dy = abs(y - viewy); - - if (dy > dx) - { - temp = dx; - dx = dy; - dy = temp; - } - - /* Fix crashes in udm1.wad */ - - if (dx != 0) - { - frac = fixed_div(dy, dx); - } - else - { - frac = 0; - } - - angle = (tantoangle[frac >> DBITS] + ANG90) >> ANGLETOFINESHIFT; - - dist = fixed_div(dx, finesine[angle]); /* use as cosine */ - - return dist; -} - -/**************************************************************************** - * Name: r_scale_from_global_angle - * - * Description: - * Returns the texture mapping scale for the current line (horizontal span) - * at the given angle. rw_distance must be calculated first. - * - ****************************************************************************/ - -fixed_t r_scale_from_global_angle(angle_t visangle) -{ - fixed_t scale; - angle_t anglea; - angle_t angleb; - int sinea; - int sineb; - fixed_t num; - int den; - -#if 0 /* UNUSED */ - fixed_t dist; - fixed_t z; - fixed_t sinv; - fixed_t cosv; - - sinv = finesine[(visangle - rw_normalangle) >> ANGLETOFINESHIFT]; - dist = fixed_div(rw_distance, sinv); - cosv = finecosine[(viewangle - visangle) >> ANGLETOFINESHIFT]; - z = abs(fixed_mul(dist, cosv)); - scale = fixed_div(projection, z); - return scale; -#endif - - anglea = ANG90 + (visangle - viewangle); - angleb = ANG90 + (visangle - rw_normalangle); - - /* both sines are always positive */ - - sinea = finesine[anglea >> ANGLETOFINESHIFT]; - sineb = finesine[angleb >> ANGLETOFINESHIFT]; - num = fixed_mul(projection, sineb) << detailshift; - den = fixed_mul(rw_distance, sinea); - - if (den > num >> FRACBITS) - { - scale = fixed_div(num, den); - - if (scale > 64 * FRACUNIT) - scale = 64 * FRACUNIT; - else if (scale < 256) - scale = 256; - } - else - scale = 64 * FRACUNIT; - - return scale; -} - -/**************************************************************************** - * Name: r_set_view_size - * - * Description: - * Do not really change anything here, because it might be in the middle - * of a refresh. The change will take effect next refresh. - * - ****************************************************************************/ - -void r_set_view_size(int blocks, int detail) -{ - setsizeneeded = true; - setblocks = blocks; - setdetail = detail; -} - -/**************************************************************************** - * Name: r_execute_set_view_size - ****************************************************************************/ - -void r_execute_set_view_size(void) -{ - fixed_t cosadj; - fixed_t dy; - int i; - int j; - int level; - int startmap; - - setsizeneeded = false; - - if (setblocks == 11) - { - scaledviewwidth = SCREENWIDTH; - viewheight = SCREENHEIGHT; - } - else - { - scaledviewwidth = setblocks * 32; - viewheight = (setblocks * 168 / 10) & ~7; - } - - detailshift = setdetail; - viewwidth = scaledviewwidth >> detailshift; - - centery = viewheight / 2; - centerx = viewwidth / 2; - centerxfrac = centerx << FRACBITS; - centeryfrac = centery << FRACBITS; - projection = centerxfrac; - - if (!detailshift) - { - colfunc = basecolfunc = r_draw_column; - fuzzcolfunc = r_draw_fuzz_column; - transcolfunc = r_draw_translated_column; - spanfunc = r_draw_span; - } - else - { - colfunc = basecolfunc = r_draw_column_low; - fuzzcolfunc = r_draw_fuzz_column_low; - transcolfunc = r_draw_translated_column_low; - spanfunc = r_draw_span_low; - } - - r_init_buffer(scaledviewwidth, viewheight); - - r_init_texture_mapping(); - - /* psprite scales */ - - pspritescale = FRACUNIT * viewwidth / SCREENWIDTH; - pspriteiscale = FRACUNIT * SCREENWIDTH / viewwidth; - - /* thing clipping */ - - for (i = 0; i < viewwidth; i++) - screenheightarray[i] = viewheight; - - /* planes */ - - for (i = 0; i < viewheight; i++) - { - dy = ((i - viewheight / 2) << FRACBITS) + FRACUNIT / 2; - dy = abs(dy); - yslope[i] = fixed_div((viewwidth << detailshift) / 2 * FRACUNIT, dy); - } - - for (i = 0; i < viewwidth; i++) - { - cosadj = abs(finecosine[xtoviewangle[i] >> ANGLETOFINESHIFT]); - distscale[i] = fixed_div(FRACUNIT, cosadj); - } - - /* Calculate the light levels to use for each level / scale combination. */ - - for (i = 0; i < LIGHTLEVELS; i++) - { - startmap = ((LIGHTLEVELS - 1 - i) * 2) * NUMCOLORMAPS / LIGHTLEVELS; - for (j = 0; j < MAXLIGHTSCALE; j++) - { - level = startmap - - j * SCREENWIDTH / (viewwidth << detailshift) / DISTMAP; - - if (level < 0) level = 0; - - if (level >= NUMCOLORMAPS) level = NUMCOLORMAPS - 1; - - scalelight[i][j] = colormaps + level * 256; - } - } -} - -/**************************************************************************** - * Name: r_init - ****************************************************************************/ - -void r_init(void) -{ - r_init_data(); - printf("."); - r_init_point_to_angle(); - printf("."); - r_init_tables(); - - /* viewwidth / viewheight / g_detail_level are set by the defaults */ - - printf("."); - - r_set_view_size(screenblocks, g_detail_level); - r_init_planes(); - printf("."); - r_init_light_tables(); - printf("."); - r_init_sky_map(); - r_init_translation_table(); - printf("."); - - framecount = 0; -} - -/**************************************************************************** - * Name: r_point_in_subsector - ****************************************************************************/ - -subsector_t *r_point_in_subsector(fixed_t x, fixed_t y) -{ - node_t *node; - int side; - int nodenum; - - /* single subsector is a special case */ - - if (!numnodes) return subsectors; - - nodenum = numnodes - 1; - - while (!(nodenum & NF_SUBSECTOR)) - { - node = &nodes[nodenum]; - side = r_point_on_side(x, y, node); - nodenum = node->children[side]; - } - - return &subsectors[nodenum & ~NF_SUBSECTOR]; -} - -/**************************************************************************** - * Name: r_render_player_view - ****************************************************************************/ - -void r_render_player_view(player_t *player) -{ - r_setup_frame(player); - - /* Clear buffers. */ - - r_clear_clip_segs(); - r_clear_draw_segs(); - r_clear_planes(); - r_clear_sprites(); - - /* check for new console commands. */ - - net_update(); - - /* The head node is the last node output. */ - - r_render_bsp_node(numnodes - 1); - - /* Check for new console commands. */ - - net_update(); - - r_draw_planes(); - - /* Check for new console commands. */ - - net_update(); - - r_draw_masked(); - - /* Check for new console commands. */ - - net_update(); -} diff --git a/games/NXDoom/src/doom/r_main.h b/games/NXDoom/src/doom/r_main.h deleted file mode 100644 index 706ddb660..000000000 --- a/games/NXDoom/src/doom/r_main.h +++ /dev/null @@ -1,150 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/r_main.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * System specific interface stuff. - * - ****************************************************************************/ - -#ifndef __R_MAIN__ -#define __R_MAIN__ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "d_player.h" -#include "r_data.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* Lighting LUT. - * Used for z-depth cuing per column/row, and other lighting effects (sector - * ambient, flash). - */ - -/* Lighting constants. Now why not 32 levels here? */ - -#define LIGHTLEVELS 16 -#define LIGHTSEGSHIFT 4 - -#define MAXLIGHTSCALE 48 -#define LIGHTSCALESHIFT 12 -#define MAXLIGHTZ 128 -#define LIGHTZSHIFT 20 - -/* Number of diminishing brightness levels. - * There a 0-31, i.e. 32 LUT in the COLORMAP lump. - */ - -#define NUMCOLORMAPS 32 - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -/* Function pointers to switch refresh/drawing functions. - * Used to select shadow mode etc. - */ - -extern void (*colfunc)(void); -extern void (*transcolfunc)(void); -extern void (*basecolfunc)(void); -extern void (*fuzzcolfunc)(void); - -/* No shadow effects on floors. */ - -extern void (*spanfunc)(void); - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/* POV related. */ - -extern fixed_t viewcos; -extern fixed_t viewsin; - -extern int viewwindowx; -extern int viewwindowy; - -extern int centerx; -extern int centery; - -extern fixed_t centerxfrac; -extern fixed_t centeryfrac; -extern fixed_t projection; - -extern int validcount; - -extern int linecount; -extern int loopcount; - -extern boolean setsizeneeded; - -extern lighttable_t *scalelight[LIGHTLEVELS][MAXLIGHTSCALE]; -extern lighttable_t *scalelightfixed[MAXLIGHTSCALE]; -extern lighttable_t *zlight[LIGHTLEVELS][MAXLIGHTZ]; - -extern int extralight; -extern lighttable_t *fixedcolormap; - -/* Blocky/low detail mode. B remove this? 0 = high, 1 = low - */ - -extern int detailshift; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/* Utility functions. */ - -int r_point_on_side(fixed_t x, fixed_t y, node_t *node); - -int r_point_on_seg_side(fixed_t x, fixed_t y, seg_t *line); - -angle_t r_point_to_angle(fixed_t x, fixed_t y); - -angle_t r_point_to_angle2(fixed_t x1, fixed_t y1, fixed_t x2, fixed_t y2); - -fixed_t r_point_to_dist(fixed_t x, fixed_t y); - -fixed_t r_scale_from_global_angle(angle_t visangle); - -subsector_t *r_point_in_subsector(fixed_t x, fixed_t y); - -/* REFRESH - the actual rendering functions. */ - -/* Called by G_Drawer. */ - -void r_render_player_view(player_t *player); - -/* Called by startup code. */ - -void r_init(void); - -/* Called by m_responder. */ - -void r_set_view_size(int blocks, int detail); - -void r_execute_set_view_size(void); - -#endif /* __R_MAIN__ */ diff --git a/games/NXDoom/src/doom/r_plane.c b/games/NXDoom/src/doom/r_plane.c deleted file mode 100644 index 65a2c2fa7..000000000 --- a/games/NXDoom/src/doom/r_plane.c +++ /dev/null @@ -1,417 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/r_plane.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Here is a core component: drawing the floors and ceilings, while - * maintaining a per column clipping list only. Moreover, the sky areas - * have to be determined. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -#include "i_system.h" -#include "w_wad.h" -#include "z_zone.h" - -#include "doomdef.h" -#include "doomstat.h" - -#include "r_local.h" -#include "r_sky.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define MAXOPENINGS (SCREENWIDTH * CONFIG_GAMES_NXDOOM_MAXOPENINGS) - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -planefunction_t floorfunc; -planefunction_t ceilingfunc; - -/* opening */ - -/* Here comes the obnoxious "visplane". */ - -visplane_t visplanes[CONFIG_GAMES_NXDOOM_MAXVISPLANES]; -visplane_t *lastvisplane; -visplane_t *floorplane; -visplane_t *ceilingplane; - -short openings[MAXOPENINGS]; -short *lastopening; - -/* Clip values are the solid pixel bounding the range. floorclip starts out - * SCREENHEIGHT ceilingclip starts out -1 - */ - -short floorclip[SCREENWIDTH]; -short ceilingclip[SCREENWIDTH]; - -/* spanstart holds the start of a plane span initialized to 0 at start */ - -int spanstart[SCREENHEIGHT]; -int spanstop[SCREENHEIGHT]; - -/* texture mapping */ - -lighttable_t **planezlight; -fixed_t planeheight; - -fixed_t yslope[SCREENHEIGHT]; -fixed_t distscale[SCREENWIDTH]; -fixed_t basexscale; -fixed_t baseyscale; - -fixed_t cachedheight[SCREENHEIGHT]; -fixed_t cacheddistance[SCREENHEIGHT]; -fixed_t cachedxstep[SCREENHEIGHT]; -fixed_t cachedystep[SCREENHEIGHT]; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/* Uses global vars: - * planeheight - * ds_source - * basexscale - * baseyscale - * viewx - * viewy - * - * BASIC PRIMITIVE - */ - -static void r_map_plane(int y, int x1, int x2) -{ - angle_t angle; - fixed_t distance; - fixed_t length; - unsigned index; - -#ifdef CONFIG_GAMES_NXDOOM_RANGECHECK - if (x2 < x1 || x1 < 0 || x2 >= viewwidth || y > viewheight) - { - i_error("R_MapPlane: %i, %i at %i", x1, x2, y); - } -#endif - - if (planeheight != cachedheight[y]) - { - cachedheight[y] = planeheight; - distance = cacheddistance[y] = fixed_mul(planeheight, yslope[y]); - ds_xstep = cachedxstep[y] = fixed_mul(distance, basexscale); - ds_ystep = cachedystep[y] = fixed_mul(distance, baseyscale); - } - else - { - distance = cacheddistance[y]; - ds_xstep = cachedxstep[y]; - ds_ystep = cachedystep[y]; - } - - length = fixed_mul(distance, distscale[x1]); - angle = (viewangle + xtoviewangle[x1]) >> ANGLETOFINESHIFT; - ds_xfrac = viewx + fixed_mul(finecosine[angle], length); - ds_yfrac = -viewy - fixed_mul(finesine[angle], length); - - if (fixedcolormap) - ds_colormap = fixedcolormap; - else - { - index = distance >> LIGHTZSHIFT; - - if (index >= MAXLIGHTZ) index = MAXLIGHTZ - 1; - - ds_colormap = planezlight[index]; - } - - ds_y = y; - ds_x1 = x1; - ds_x2 = x2; - - /* high or low detail */ - - spanfunc(); -} - -static void r_make_spans(int x, int t1, int b1, int t2, int b2) -{ - while (t1 < t2 && t1 <= b1) - { - r_map_plane(t1, spanstart[t1], x - 1); - t1++; - } - while (b1 > b2 && b1 >= t1) - { - r_map_plane(b1, spanstart[b1], x - 1); - b1--; - } - - while (t2 < t1 && t2 <= b2) - { - spanstart[t2] = x; - t2++; - } - while (b2 > b1 && b2 >= t2) - { - spanstart[b2] = x; - b2--; - } -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/* r_init_planes - * Only at game startup. - */ - -void r_init_planes(void) -{ - /* Doh! */ -} - -/* r_clear_planes - * At beginning of frame. - */ - -void r_clear_planes(void) -{ - int i; - angle_t angle; - - /* opening / clipping determination */ - - for (i = 0; i < viewwidth; i++) - { - floorclip[i] = viewheight; - ceilingclip[i] = -1; - } - - lastvisplane = visplanes; - lastopening = openings; - - /* texture calculation */ - - memset(cachedheight, 0, sizeof(cachedheight)); - - /* left to right mapping */ - - angle = (viewangle - ANG90) >> ANGLETOFINESHIFT; - - /* scale will be unit scale at SCREENWIDTH/2 distance */ - - basexscale = fixed_div(finecosine[angle], centerxfrac); - baseyscale = -fixed_div(finesine[angle], centerxfrac); -} - -visplane_t *r_find_plane(fixed_t height, int picnum, int lightlevel) -{ - visplane_t *check; - - if (picnum == skyflatnum) - { - height = 0; /* all skys map together */ - lightlevel = 0; - } - - for (check = visplanes; check < lastvisplane; check++) - { - if (height == check->height && picnum == check->picnum && - lightlevel == check->lightlevel) - { - break; - } - } - - if (check < lastvisplane) return check; - - if (lastvisplane - visplanes == CONFIG_GAMES_NXDOOM_MAXVISPLANES) - i_error("r_find_plane: no more visplanes"); - - lastvisplane++; - - check->height = height; - check->picnum = picnum; - check->lightlevel = lightlevel; - check->minx = SCREENWIDTH; - check->maxx = -1; - - memset(check->top, 0xff, sizeof(check->top)); - - return check; -} - -visplane_t *r_check_plane(visplane_t *pl, int start, int stop) -{ - int intrl; - int intrh; - int unionl; - int unionh; - int x; - - if (start < pl->minx) - { - intrl = pl->minx; - unionl = start; - } - else - { - unionl = pl->minx; - intrl = start; - } - - if (stop > pl->maxx) - { - intrh = pl->maxx; - unionh = stop; - } - else - { - unionh = pl->maxx; - intrh = stop; - } - - for (x = intrl; x <= intrh; x++) - { - if (pl->top[x] != 0xff) break; - } - - if (x > intrh) - { - pl->minx = unionl; - pl->maxx = unionh; - - return pl; /* use the same one */ - } - - /* make a new visplane */ - - lastvisplane->height = pl->height; - lastvisplane->picnum = pl->picnum; - lastvisplane->lightlevel = pl->lightlevel; - - if (lastvisplane - visplanes == CONFIG_GAMES_NXDOOM_MAXVISPLANES) - i_error("r_check_plane: no more visplanes"); - - pl = lastvisplane++; - pl->minx = start; - pl->maxx = stop; - - memset(pl->top, 0xff, sizeof(pl->top)); - - return pl; -} - -/* At the end of each frame. */ - -void r_draw_planes(void) -{ - visplane_t *pl; - int light; - int x; - int stop; - int angle; - int lumpnum; - -#ifdef CONFIG_GAMES_NXDOOM_RANGECHECK - if (ds_p - drawsegs > CONFIG_GAMES_NXDOOM_MAXDRAWSEGS) - i_error("r_draw_planes: drawsegs overflow (%td)", ds_p - drawsegs); - - if (lastvisplane - visplanes > CONFIG_GAMES_NXDOOM_MAXVISPLANES) - i_error("r_draw_planes: visplane overflow (%td)", - lastvisplane - visplanes); - - if (lastopening - openings > MAXOPENINGS) - i_error("r_draw_planes: opening overflow (%td)", lastopening - openings); -#endif - - for (pl = visplanes; pl < lastvisplane; pl++) - { - if (pl->minx > pl->maxx) continue; - - /* sky flat */ - - if (pl->picnum == skyflatnum) - { - dc_iscale = pspriteiscale >> detailshift; - - /* Sky is always drawn full bright, i.e. colormaps[0] is used. - * Because of this hack, sky is not affected by INVUL inverse - * mapping. - */ - - dc_colormap = colormaps; - dc_texturemid = skytexturemid; - for (x = pl->minx; x <= pl->maxx; x++) - { - dc_yl = pl->top[x]; - dc_yh = pl->bottom[x]; - - if (dc_yl <= dc_yh) - { - angle = (viewangle + xtoviewangle[x]) >> ANGLETOSKYSHIFT; - dc_x = x; - dc_source = r_get_column(skytexture, angle); - colfunc(); - } - } - - continue; - } - - /* regular flat */ - - lumpnum = firstflat + flattranslation[pl->picnum]; - ds_source = w_cache_lump_num(lumpnum, PU_STATIC); - - planeheight = abs(pl->height - viewz); - light = (pl->lightlevel >> LIGHTSEGSHIFT) + extralight; - - if (light >= LIGHTLEVELS) light = LIGHTLEVELS - 1; - - if (light < 0) light = 0; - - planezlight = zlight[light]; - - pl->top[pl->maxx + 1] = 0xff; - pl->top[pl->minx - 1] = 0xff; - - stop = pl->maxx + 1; - - for (x = pl->minx; x <= stop; x++) - { - r_make_spans(x, pl->top[x - 1], pl->bottom[x - 1], pl->top[x], - pl->bottom[x]); - } - - w_release_lump_num(lumpnum); - } -} diff --git a/games/NXDoom/src/doom/r_plane.h b/games/NXDoom/src/doom/r_plane.h deleted file mode 100644 index 1ae3b7925..000000000 --- a/games/NXDoom/src/doom/r_plane.h +++ /dev/null @@ -1,69 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/r_plane.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Refresh, visplane stuff (floor, ceilings). - * - ****************************************************************************/ - -#ifndef __R_PLANE__ -#define __R_PLANE__ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "r_data.h" - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -typedef void (*planefunction_t)(int top, int bottom); - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/* Visplane related. */ - -extern short *lastopening; - -extern planefunction_t floorfunc; -extern planefunction_t ceilingfunc_t; - -extern short floorclip[SCREENWIDTH]; -extern short ceilingclip[SCREENWIDTH]; - -extern fixed_t yslope[SCREENHEIGHT]; -extern fixed_t distscale[SCREENWIDTH]; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -void r_init_planes(void); -void r_clear_planes(void); - -void r_draw_planes(void); - -visplane_t *r_find_plane(fixed_t height, int picnum, int lightlevel); - -visplane_t *r_check_plane(visplane_t *pl, int start, int stop); - -#endif /* __R_PLANE__ */ diff --git a/games/NXDoom/src/doom/r_segs.c b/games/NXDoom/src/doom/r_segs.c deleted file mode 100644 index 83d9b026f..000000000 --- a/games/NXDoom/src/doom/r_segs.c +++ /dev/null @@ -1,787 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/r_segs.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * All the clipping: columns, horizontal spans, sky columns. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -#include "i_system.h" - -#include "doomdef.h" -#include "doomstat.h" - -#include "r_local.h" -#include "r_sky.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define HEIGHTBITS 12 -#define HEIGHTUNIT (1 << HEIGHTBITS) - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/* OPTIMIZE: closed two sided lines as single sided */ - -/* True if any of the segs textures might be visible. */ - -boolean segtextured; - -/* False if the back side is the same plane. */ - -boolean markfloor; -boolean markceiling; - -boolean maskedtexture; -int toptexture; -int bottomtexture; -int midtexture; - -angle_t rw_normalangle; - -/* angle to line origin */ - -int rw_angle1; - -/* regular wall */ - -int rw_x; -int rw_stopx; -angle_t rw_centerangle; -fixed_t rw_offset; -fixed_t rw_distance; -fixed_t rw_scale; -fixed_t rw_scalestep; -fixed_t rw_midtexturemid; -fixed_t rw_toptexturemid; -fixed_t rw_bottomtexturemid; - -int worldtop; -int worldbottom; -int worldhigh; -int worldlow; - -fixed_t pixhigh; -fixed_t pixlow; -fixed_t pixhighstep; -fixed_t pixlowstep; - -fixed_t topfrac; -fixed_t topstep; - -fixed_t bottomfrac; -fixed_t bottomstep; - -lighttable_t **walllights; - -short *maskedtexturecol; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/* Draws zero, one, or two textures (and possibly a masked texture) for - * walls. - * - * Can draw or mark the starting pixel of floor and ceiling textures. - * CALLED: CORE LOOPING ROUTINE. - */ - -static void r_render_seg_loop(void) -{ - angle_t angle; - unsigned index; - int yl; - int yh; - int mid; - fixed_t texturecolumn; - int top; - int bottom; - - for (; rw_x < rw_stopx; rw_x++) - { - /* mark floor / ceiling areas */ - - yl = (topfrac + HEIGHTUNIT - 1) >> HEIGHTBITS; - - /* no space above wall? */ - - if (yl < ceilingclip[rw_x] + 1) yl = ceilingclip[rw_x] + 1; - - if (markceiling) - { - top = ceilingclip[rw_x] + 1; - bottom = yl - 1; - - if (bottom >= floorclip[rw_x]) bottom = floorclip[rw_x] - 1; - - if (top <= bottom) - { - ceilingplane->top[rw_x] = top; - ceilingplane->bottom[rw_x] = bottom; - } - } - - yh = bottomfrac >> HEIGHTBITS; - - if (yh >= floorclip[rw_x]) yh = floorclip[rw_x] - 1; - - if (markfloor) - { - top = yh + 1; - bottom = floorclip[rw_x] - 1; - if (top <= ceilingclip[rw_x]) top = ceilingclip[rw_x] + 1; - if (top <= bottom) - { - floorplane->top[rw_x] = top; - floorplane->bottom[rw_x] = bottom; - } - } - - /* texturecolumn and lighting are independent of wall tiers */ - - if (segtextured) - { - /* calculate texture offset */ - - angle = (rw_centerangle + xtoviewangle[rw_x]) >> ANGLETOFINESHIFT; - texturecolumn = - rw_offset - fixed_mul(finetangent[angle], rw_distance); - texturecolumn >>= FRACBITS; - - /* calculate lighting */ - - index = rw_scale >> LIGHTSCALESHIFT; - - if (index >= MAXLIGHTSCALE) index = MAXLIGHTSCALE - 1; - - dc_colormap = walllights[index]; - dc_x = rw_x; - dc_iscale = 0xffffffffu / (unsigned)rw_scale; - } - else - { - /* purely to shut up the compiler */ - - texturecolumn = 0; - } - - /* draw the wall tiers */ - - if (midtexture) - { - /* single sided line */ - - dc_yl = yl; - dc_yh = yh; - dc_texturemid = rw_midtexturemid; - dc_source = r_get_column(midtexture, texturecolumn); - colfunc(); - ceilingclip[rw_x] = viewheight; - floorclip[rw_x] = -1; - } - else - { - /* two sided line */ - - if (toptexture) - { - /* top wall */ - - mid = pixhigh >> HEIGHTBITS; - pixhigh += pixhighstep; - - if (mid >= floorclip[rw_x]) mid = floorclip[rw_x] - 1; - - if (mid >= yl) - { - dc_yl = yl; - dc_yh = mid; - dc_texturemid = rw_toptexturemid; - dc_source = r_get_column(toptexture, texturecolumn); - colfunc(); - ceilingclip[rw_x] = mid; - } - else - ceilingclip[rw_x] = yl - 1; - } - else - { - /* no top wall */ - - if (markceiling) ceilingclip[rw_x] = yl - 1; - } - - if (bottomtexture) - { - /* bottom wall */ - - mid = (pixlow + HEIGHTUNIT - 1) >> HEIGHTBITS; - pixlow += pixlowstep; - - /* no space above wall? */ - - if (mid <= ceilingclip[rw_x]) mid = ceilingclip[rw_x] + 1; - - if (mid <= yh) - { - dc_yl = mid; - dc_yh = yh; - dc_texturemid = rw_bottomtexturemid; - dc_source = r_get_column(bottomtexture, texturecolumn); - colfunc(); - floorclip[rw_x] = mid; - } - else - floorclip[rw_x] = yh + 1; - } - else - { - /* no bottom wall */ - - if (markfloor) floorclip[rw_x] = yh + 1; - } - - if (maskedtexture) - { - /* save texturecol - * for backdrawing of masked mid texture - */ - - maskedtexturecol[rw_x] = texturecolumn; - } - } - - rw_scale += rw_scalestep; - topfrac += topstep; - bottomfrac += bottomstep; - } -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -void r_render_masked_seg_range(drawseg_t *ds, int x1, int x2) -{ - unsigned index; - column_t *col; - int lightnum; - int texnum; - - /* Calculate light table. - * Use different light tables for horizontal / vertical / diagonal. - * Diagonal? OPTIMIZE: get rid of LIGHTSEGSHIFT globally - */ - - curline = ds->curline; - frontsector = curline->frontsector; - backsector = curline->backsector; - texnum = texturetranslation[curline->sidedef->midtexture]; - - lightnum = (frontsector->lightlevel >> LIGHTSEGSHIFT) + extralight; - - if (curline->v1->y == curline->v2->y) - lightnum--; - else if (curline->v1->x == curline->v2->x) - lightnum++; - - if (lightnum < 0) - walllights = scalelight[0]; - else if (lightnum >= LIGHTLEVELS) - walllights = scalelight[LIGHTLEVELS - 1]; - else - walllights = scalelight[lightnum]; - - maskedtexturecol = ds->maskedtexturecol; - - rw_scalestep = ds->scalestep; - spryscale = ds->scale1 + (x1 - ds->x1) * rw_scalestep; - mfloorclip = ds->sprbottomclip; - mceilingclip = ds->sprtopclip; - - /* find positioning */ - - if (curline->linedef->flags & ML_DONTPEGBOTTOM) - { - dc_texturemid = frontsector->floorheight > backsector->floorheight - ? frontsector->floorheight - : backsector->floorheight; - dc_texturemid = dc_texturemid + textureheight[texnum] - viewz; - } - else - { - dc_texturemid = frontsector->ceilingheight < backsector->ceilingheight - ? frontsector->ceilingheight - : backsector->ceilingheight; - dc_texturemid = dc_texturemid - viewz; - } - - dc_texturemid += curline->sidedef->rowoffset; - - if (fixedcolormap) dc_colormap = fixedcolormap; - - /* draw the columns */ - - for (dc_x = x1; dc_x <= x2; dc_x++) - { - /* calculate lighting */ - - if (maskedtexturecol[dc_x] != SHRT_MAX) - { - if (!fixedcolormap) - { - index = spryscale >> LIGHTSCALESHIFT; - - if (index >= MAXLIGHTSCALE) index = MAXLIGHTSCALE - 1; - - dc_colormap = walllights[index]; - } - - sprtopscreen = centeryfrac - fixed_mul(dc_texturemid, spryscale); - dc_iscale = 0xffffffffu / (unsigned)spryscale; - - /* draw the texture */ - - col = (column_t *)((byte *)r_get_column(texnum, - maskedtexturecol[dc_x]) - - 3); - - r_draw_masked_column(col); - maskedtexturecol[dc_x] = SHRT_MAX; - } - - spryscale += rw_scalestep; - } -} - -/* r_store_wall_range - * A wall segment will be drawn between start and stop pixels (inclusive). - */ - -void r_store_wall_range(int start, int stop) -{ - fixed_t hyp; - fixed_t sineval; - angle_t distangle, offsetangle; - fixed_t vtop; - int lightnum; - - /* don't overflow and crash */ - - if (ds_p == &drawsegs[CONFIG_GAMES_NXDOOM_MAXDRAWSEGS]) return; - -#ifdef CONFIG_GAMES_NXDOOM_RANGECHECK - if (start >= viewwidth || start > stop) - i_error("Bad R_RenderWallRange: %i to %i", start, stop); -#endif - - sidedef = curline->sidedef; - linedef = curline->linedef; - - /* mark the segment as visible for auto map */ - - linedef->flags |= ML_MAPPED; - - /* calculate rw_distance for scale calculation */ - - rw_normalangle = curline->angle + ANG90; - offsetangle = abs((int)rw_normalangle - (int)rw_angle1); - - if (offsetangle > ANG90) offsetangle = ANG90; - - distangle = ANG90 - offsetangle; - hyp = r_point_to_dist(curline->v1->x, curline->v1->y); - sineval = finesine[distangle >> ANGLETOFINESHIFT]; - rw_distance = fixed_mul(hyp, sineval); - - ds_p->x1 = rw_x = start; - ds_p->x2 = stop; - ds_p->curline = curline; - rw_stopx = stop + 1; - - /* calculate scale at both ends and step */ - - ds_p->scale1 = rw_scale = - r_scale_from_global_angle(viewangle + xtoviewangle[start]); - - if (stop > start) - { - ds_p->scale2 = - r_scale_from_global_angle(viewangle + xtoviewangle[stop]); - ds_p->scalestep = rw_scalestep = - (ds_p->scale2 - rw_scale) / (stop - start); - } - else - { -#if 0 /* UNUSED: try to fix the stretched line bug */ - if (rw_distance < FRACUNIT / 2) - { - fixed_t trx, try; - fixed_t gxt, gyt; - - trx = curline->v1->x - viewx; - try = curline->v1->y - viewy; - - gxt = fixed_mul(trx, viewcos); - gyt = -fixed_mul(try, viewsin); - ds_p->scale1 = fixed_div(projection, gxt - gyt) << detailshift; - } - -#endif - ds_p->scale2 = ds_p->scale1; - } - - /* calculate texture boundaries and decide if floor / ceiling marks are - * needed - */ - - worldtop = frontsector->ceilingheight - viewz; - worldbottom = frontsector->floorheight - viewz; - - midtexture = toptexture = bottomtexture = maskedtexture = 0; - ds_p->maskedtexturecol = NULL; - - if (!backsector) - { - /* single sided line */ - - midtexture = texturetranslation[sidedef->midtexture]; - - /* a single sided line is terminal, so it must mark ends */ - - markfloor = markceiling = true; - if (linedef->flags & ML_DONTPEGBOTTOM) - { - vtop = - frontsector->floorheight + textureheight[sidedef->midtexture]; - - /* bottom of texture at bottom */ - - rw_midtexturemid = vtop - viewz; - } - else - { - /* top of texture at top */ - - rw_midtexturemid = worldtop; - } - - rw_midtexturemid += sidedef->rowoffset; - - ds_p->silhouette = SIL_BOTH; - ds_p->sprtopclip = screenheightarray; - ds_p->sprbottomclip = negonearray; - ds_p->bsilheight = INT_MAX; - ds_p->tsilheight = INT_MIN; - } - else - { - /* two sided line */ - - ds_p->sprtopclip = ds_p->sprbottomclip = NULL; - ds_p->silhouette = 0; - - if (frontsector->floorheight > backsector->floorheight) - { - ds_p->silhouette = SIL_BOTTOM; - ds_p->bsilheight = frontsector->floorheight; - } - else if (backsector->floorheight > viewz) - { - ds_p->silhouette = SIL_BOTTOM; - ds_p->bsilheight = INT_MAX; - - /* ds_p->sprbottomclip = negonearray; */ - } - - if (frontsector->ceilingheight < backsector->ceilingheight) - { - ds_p->silhouette |= SIL_TOP; - ds_p->tsilheight = frontsector->ceilingheight; - } - else if (backsector->ceilingheight < viewz) - { - ds_p->silhouette |= SIL_TOP; - ds_p->tsilheight = INT_MIN; - - /* ds_p->sprtopclip = screenheightarray; */ - } - - if (backsector->ceilingheight <= frontsector->floorheight) - { - ds_p->sprbottomclip = negonearray; - ds_p->bsilheight = INT_MAX; - ds_p->silhouette |= SIL_BOTTOM; - } - - if (backsector->floorheight >= frontsector->ceilingheight) - { - ds_p->sprtopclip = screenheightarray; - ds_p->tsilheight = INT_MIN; - ds_p->silhouette |= SIL_TOP; - } - - worldhigh = backsector->ceilingheight - viewz; - worldlow = backsector->floorheight - viewz; - - /* hack to allow height changes in outdoor areas */ - - if (frontsector->ceilingpic == skyflatnum && - backsector->ceilingpic == skyflatnum) - { - worldtop = worldhigh; - } - - if (worldlow != worldbottom || - backsector->floorpic != frontsector->floorpic || - backsector->lightlevel != frontsector->lightlevel) - { - markfloor = true; - } - else - { - /* same plane on both sides */ - - markfloor = false; - } - - if (worldhigh != worldtop || - backsector->ceilingpic != frontsector->ceilingpic || - backsector->lightlevel != frontsector->lightlevel) - { - markceiling = true; - } - else - { - /* same plane on both sides */ - - markceiling = false; - } - - if (backsector->ceilingheight <= frontsector->floorheight || - backsector->floorheight >= frontsector->ceilingheight) - { - /* closed door */ - - markceiling = markfloor = true; - } - - if (worldhigh < worldtop) - { - /* top texture */ - - toptexture = texturetranslation[sidedef->toptexture]; - if (linedef->flags & ML_DONTPEGTOP) - { - /* top of texture at top */ - - rw_toptexturemid = worldtop; - } - else - { - vtop = backsector->ceilingheight + - textureheight[sidedef->toptexture]; - - /* bottom of texture */ - - rw_toptexturemid = vtop - viewz; - } - } - - if (worldlow > worldbottom) - { - /* bottom texture */ - - bottomtexture = texturetranslation[sidedef->bottomtexture]; - - if (linedef->flags & ML_DONTPEGBOTTOM) - { - /* bottom of texture at bottom top of texture at top */ - - rw_bottomtexturemid = worldtop; - } - else /* top of texture at top */ - rw_bottomtexturemid = worldlow; - } - - rw_toptexturemid += sidedef->rowoffset; - rw_bottomtexturemid += sidedef->rowoffset; - - /* allocate space for masked texture tables */ - - if (sidedef->midtexture) - { - /* masked midtexture */ - - maskedtexture = true; - ds_p->maskedtexturecol = maskedtexturecol = lastopening - rw_x; - lastopening += rw_stopx - rw_x; - } - } - - /* calculate rw_offset (only needed for textured lines) */ - - segtextured = midtexture | toptexture | bottomtexture | maskedtexture; - - if (segtextured) - { - offsetangle = rw_normalangle - rw_angle1; - - if (offsetangle > ANG180) offsetangle = -offsetangle; - - if (offsetangle > ANG90) offsetangle = ANG90; - - sineval = finesine[offsetangle >> ANGLETOFINESHIFT]; - rw_offset = fixed_mul(hyp, sineval); - - if (rw_normalangle - rw_angle1 < ANG180) rw_offset = -rw_offset; - - rw_offset += sidedef->textureoffset + curline->offset; - rw_centerangle = ANG90 + viewangle - rw_normalangle; - - /* calculate light table use different light tables for horizontal / - * vertical / diagonal - * - * OPTIMIZE: get rid of LIGHTSEGSHIFT globally - */ - - if (!fixedcolormap) - { - lightnum = (frontsector->lightlevel >> LIGHTSEGSHIFT) + extralight; - - if (curline->v1->y == curline->v2->y) - lightnum--; - else if (curline->v1->x == curline->v2->x) - lightnum++; - - if (lightnum < 0) - walllights = scalelight[0]; - else if (lightnum >= LIGHTLEVELS) - walllights = scalelight[LIGHTLEVELS - 1]; - else - walllights = scalelight[lightnum]; - } - } - - /* if a floor / ceiling plane is on the wrong side of the view plane, it is - * definitely invisible and doesn't need to be marked. - */ - - if (frontsector->floorheight >= viewz) - { - /* above view plane */ - - markfloor = false; - } - - if (frontsector->ceilingheight <= viewz && - frontsector->ceilingpic != skyflatnum) - { - /* below view plane */ - - markceiling = false; - } - - /* calculate incremental stepping values for texture edges */ - - worldtop >>= 4; - worldbottom >>= 4; - - topstep = -fixed_mul(rw_scalestep, worldtop); - topfrac = (centeryfrac >> 4) - fixed_mul(worldtop, rw_scale); - - bottomstep = -fixed_mul(rw_scalestep, worldbottom); - bottomfrac = (centeryfrac >> 4) - fixed_mul(worldbottom, rw_scale); - - if (backsector) - { - worldhigh >>= 4; - worldlow >>= 4; - - if (worldhigh < worldtop) - { - pixhigh = (centeryfrac >> 4) - fixed_mul(worldhigh, rw_scale); - pixhighstep = -fixed_mul(rw_scalestep, worldhigh); - } - - if (worldlow > worldbottom) - { - pixlow = (centeryfrac >> 4) - fixed_mul(worldlow, rw_scale); - pixlowstep = -fixed_mul(rw_scalestep, worldlow); - } - } - - /* render it */ - - if (markceiling) - { - ceilingplane = r_check_plane(ceilingplane, rw_x, rw_stopx - 1); - } - - if (markfloor) - { - floorplane = r_check_plane(floorplane, rw_x, rw_stopx - 1); - } - - r_render_seg_loop(); - - /* save sprite clipping info */ - - if (((ds_p->silhouette & SIL_TOP) || maskedtexture) && !ds_p->sprtopclip) - { - memcpy(lastopening, ceilingclip + start, - sizeof(*lastopening) * (rw_stopx - start)); - ds_p->sprtopclip = lastopening - start; - lastopening += rw_stopx - start; - } - - if (((ds_p->silhouette & SIL_BOTTOM) || maskedtexture) && - !ds_p->sprbottomclip) - { - memcpy(lastopening, floorclip + start, - sizeof(*lastopening) * (rw_stopx - start)); - ds_p->sprbottomclip = lastopening - start; - lastopening += rw_stopx - start; - } - - if (maskedtexture && !(ds_p->silhouette & SIL_TOP)) - { - ds_p->silhouette |= SIL_TOP; - ds_p->tsilheight = INT_MIN; - } - - if (maskedtexture && !(ds_p->silhouette & SIL_BOTTOM)) - { - ds_p->silhouette |= SIL_BOTTOM; - ds_p->bsilheight = INT_MAX; - } - - ds_p++; -} diff --git a/games/NXDoom/src/doom/r_segs.h b/games/NXDoom/src/doom/r_segs.h deleted file mode 100644 index 8bd13275f..000000000 --- a/games/NXDoom/src/doom/r_segs.h +++ /dev/null @@ -1,39 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/r_segs.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Refresh module, drawing LineSegs from BSP. - * - ****************************************************************************/ - -#ifndef __R_SEGS__ -#define __R_SEGS__ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -extern lighttable_t **walllights; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -void r_render_masked_seg_range(drawseg_t *ds, int x1, int x2); - -#endif /* __R_SEGS__ */ diff --git a/games/NXDoom/src/doom/r_sky.c b/games/NXDoom/src/doom/r_sky.c deleted file mode 100644 index d84e6729b..000000000 --- a/games/NXDoom/src/doom/r_sky.c +++ /dev/null @@ -1,68 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/r_sky.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Sky rendering. The DOOM sky is a texture map like any - * wall, wrapping around. A 1024 columns equal 360 degrees. - * The default sky map is 256 columns and repeats 4 times - * on a 320 screen? - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -/* Needed for FRACUNIT. */ - -#include "m_fixed.h" - -/* Needed for Flat retrieval. */ - -#include "r_data.h" - -#include "r_sky.h" - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/* sky mapping */ - -int skyflatnum; -int skytexture; -int skytexturemid; - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: r_init_sky_map - * - * Description: - * Called whenever the view size changes. - * - ****************************************************************************/ - -void r_init_sky_map(void) -{ - /* skyflatnum = r_flat_num_for_name ( SKYFLATNAME ); */ - - skytexturemid = SCREENHEIGHT / 2 * FRACUNIT; -} diff --git a/games/NXDoom/src/doom/r_sky.h b/games/NXDoom/src/doom/r_sky.h deleted file mode 100644 index e9455b72e..000000000 --- a/games/NXDoom/src/doom/r_sky.h +++ /dev/null @@ -1,54 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/r_sky.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Sky rendering. - * - ****************************************************************************/ - -#ifndef __R_SKY__ -#define __R_SKY__ - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* SKY, store the number for name. */ - -#define SKYFLATNAME "F_SKY1" - -/* The sky map is 256*128*4 maps. */ - -#define ANGLETOSKYSHIFT 22 - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -extern int skytexture; -extern int skytexturemid; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/* Called whenever the view size changes. */ - -void r_init_sky_map(void); - -#endif diff --git a/games/NXDoom/src/doom/r_state.h b/games/NXDoom/src/doom/r_state.h deleted file mode 100644 index cab81830d..000000000 --- a/games/NXDoom/src/doom/r_state.h +++ /dev/null @@ -1,130 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/r_state.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Refresh/render internal state variables (global). - * - ****************************************************************************/ - -#ifndef __R_STATE__ -#define __R_STATE__ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -/* Need data structure definitions. */ - -#include "d_player.h" -#include "r_data.h" - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/* Refresh internal data structures, for rendering. */ - -/* needed for texture pegging */ - -extern fixed_t *textureheight; - -/* needed for pre rendering (fracs) */ - -extern fixed_t *spritewidth; - -extern fixed_t *spriteoffset; -extern fixed_t *spritetopoffset; - -extern lighttable_t *colormaps; - -extern int viewwidth; -extern int scaledviewwidth; -extern int viewheight; - -extern int firstflat; - -/* for global animation */ - -extern int *flattranslation; -extern int *texturetranslation; - -/* Sprite.... */ - -extern int firstspritelump; -extern int lastspritelump; -extern int numspritelumps; - -/* Lookup tables for map data. */ - -extern int numsprites; -extern spritedef_t *sprites; - -extern int numvertices; -extern vertex_t *vertices; - -extern int numsegs; -extern seg_t *segs; - -extern int numsectors; -extern sector_t *sectors; - -extern int numsubsectors; -extern subsector_t *subsectors; - -extern int numnodes; -extern node_t *nodes; - -extern int numlines; -extern line_t *lines; - -extern int numsides; -extern side_t *sides; - -/* POV data. */ - -extern fixed_t viewx; -extern fixed_t viewy; -extern fixed_t viewz; - -extern angle_t viewangle; -extern player_t *viewplayer; - -/* ? */ - -extern angle_t clipangle; - -extern int viewangletox[FINEANGLES / 2]; -extern angle_t xtoviewangle[SCREENWIDTH + 1]; - -/* extern fixed_t finetangent[FINEANGLES/2]; */ - -extern fixed_t rw_distance; -extern angle_t rw_normalangle; - -/* angle to line origin */ - -extern int rw_angle1; - -/* Segs count? */ - -extern int sscount; - -extern visplane_t *floorplane; -extern visplane_t *ceilingplane; - -#endif /* __R_STATE__ */ diff --git a/games/NXDoom/src/doom/r_things.c b/games/NXDoom/src/doom/r_things.c deleted file mode 100644 index 019d83a70..000000000 --- a/games/NXDoom/src/doom/r_things.c +++ /dev/null @@ -1,974 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/r_things.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Refresh of things, i.e. objects represented by sprites. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -#include "deh_main.h" -#include "doomdef.h" - -#include "i_swap.h" -#include "i_system.h" -#include "w_wad.h" -#include "z_zone.h" - -#include "r_local.h" - -#include "doomstat.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define MINZ (FRACUNIT * 4) -#define BASEYCENTER (SCREENHEIGHT / 2) - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -typedef struct -{ - int x1; - int x2; - - int column; - int topclip; - int bottomclip; -} maskdraw_t; - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/* Sprite rotation 0 is facing the viewer, rotation 1 is one angle turn - * CLOCKWISE around the axis. - * - * This is not the same as the angle, which increases counter clockwise - * (protractor). There was a lot of stuff grabbed wrong, so I changed it... - */ - -fixed_t pspritescale; -fixed_t pspriteiscale; - -lighttable_t **spritelights; - -/* constant arrays used for psprite clipping and initializing clipping */ - -short negonearray[SCREENWIDTH]; -short screenheightarray[SCREENWIDTH]; - -/* INITIALIZATION FUNCTIONS */ - -/* variables used to look up and range check thing_t sprites patches */ - -spritedef_t *sprites; -int numsprites; - -spriteframe_t sprtemp[29]; -int maxframe; -const char *spritename; - -vissprite_t vissprites[CONFIG_GAMES_NXDOOM_MAXVISSPRITES]; -vissprite_t *vissprite_p; -int newvissprite; - -vissprite_t overflowsprite; - -short *mfloorclip; -short *mceilingclip; - -fixed_t spryscale; -fixed_t sprtopscreen; - -vissprite_t vsprsortedhead; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/* R_InstallSpriteLump - * Local function for r_init_sprites. - */ - -static void r_install_sprite_lump(int lump, unsigned frame, - unsigned rotation, boolean flipped) -{ - int r; - - if (frame >= 29 || rotation > 8) - i_error("R_InstallSpriteLump: " - "Bad frame characters in lump %i", - lump); - - if ((int)frame > maxframe) maxframe = frame; - - if (rotation == 0) - { - /* the lump should be used for all rotations */ - - if (sprtemp[frame].rotate == false) - i_error("r_init_sprites: Sprite %s frame %c has " - "multip rot=0 lump", - spritename, 'A' + frame); - - if (sprtemp[frame].rotate == true) - i_error("r_init_sprites: Sprite %s frame %c has rotations " - "and a rot=0 lump", - spritename, 'A' + frame); - - sprtemp[frame].rotate = false; - for (r = 0; r < 8; r++) - { - sprtemp[frame].lump[r] = lump - firstspritelump; - sprtemp[frame].flip[r] = (byte)flipped; - } - - return; - } - - /* the lump is only used for one rotation */ - - if (sprtemp[frame].rotate == false) - i_error("r_init_sprites: Sprite %s frame %c has rotations " - "and a rot=0 lump", - spritename, 'A' + frame); - - sprtemp[frame].rotate = true; - - /* make 0 based */ - - rotation--; - if (sprtemp[frame].lump[rotation] != -1) - i_error("r_init_sprites: Sprite %s : %c : %c " - "has two lumps mapped to it", - spritename, 'A' + frame, '1' + rotation); - - sprtemp[frame].lump[rotation] = lump - firstspritelump; - sprtemp[frame].flip[rotation] = (byte)flipped; -} - -/* r_init_sprite_defs - * - * Pass a null terminated list of sprite names (4 chars exactly) to be used. - * - * Builds the sprite rotation matrixes to account for horizontally flipped - * sprites. - * - * Will report an error if the lumps are inconsistent. Only called at - * startup. - * - * Sprite lump names are 4 characters for the actor, a letter for the frame, - * and a number for the rotation. - * - * A sprite that is flippable will have an additional letter/number appended. - * - * The rotation character can be 0 to signify no rotations. - */ - -static void r_init_sprite_defs(const char **namelist) -{ - const char **check; - int i; - int l; - int frame; - int rotation; - int start; - int end; - int patched; - - /* count the number of sprite names */ - - check = namelist; - while (*check != NULL) - check++; - - numsprites = check - namelist; - - if (!numsprites) return; - - sprites = z_malloc(numsprites * sizeof(*sprites), PU_STATIC, NULL); - - start = firstspritelump - 1; - end = lastspritelump + 1; - - /* scan all the lump names for each of the names, noting the highest frame - * letter. Just compare 4 characters as ints - */ - - for (i = 0; i < numsprites; i++) - { - spritename = (namelist[i]); - memset(sprtemp, -1, sizeof(sprtemp)); - - maxframe = -1; - - /* scan the lumps, filling in the frames for whatever is found - */ - - for (l = start + 1; l < end; l++) - { - if (!strncasecmp(lumpinfo[l]->name, spritename, 4)) - { - frame = lumpinfo[l]->name[4] - 'A'; - rotation = lumpinfo[l]->name[5] - '0'; - - if (modifiedgame) - patched = w_get_num_for_name(lumpinfo[l]->name); - else - patched = l; - - r_install_sprite_lump(patched, frame, rotation, false); - - if (lumpinfo[l]->name[6]) - { - frame = lumpinfo[l]->name[6] - 'A'; - rotation = lumpinfo[l]->name[7] - '0'; - r_install_sprite_lump(l, frame, rotation, true); - } - } - } - - /* check the frames that were found for completeness */ - - if (maxframe == -1) - { - sprites[i].numframes = 0; - continue; - } - - maxframe++; - - for (frame = 0; frame < maxframe; frame++) - { - switch ((int)sprtemp[frame].rotate) - { - case -1: - - /* no rotations were found for that frame at all */ - - i_error("r_init_sprites: No patches found " - "for %s frame %c", - spritename, frame + 'A'); - break; - - case 0: - break; /* only the first rotation is needed */ - - case 1: - - /* must have all 8 frames */ - - for (rotation = 0; rotation < 8; rotation++) - if (sprtemp[frame].lump[rotation] == -1) - i_error("r_init_sprites: Sprite %s frame %c " - "is missing rotations", - spritename, frame + 'A'); - break; - } - } - - /* allocate space for the frames present and copy sprtemp to it */ - - sprites[i].numframes = maxframe; - sprites[i].spriteframes = - z_malloc(maxframe * sizeof(spriteframe_t), PU_STATIC, NULL); - memcpy(sprites[i].spriteframes, sprtemp, - maxframe * sizeof(spriteframe_t)); - } -} - -static vissprite_t *r_new_vis_sprite(void) -{ - if (vissprite_p == &vissprites[CONFIG_GAMES_NXDOOM_MAXVISSPRITES]) - { - return &overflowsprite; - } - - vissprite_p++; - return vissprite_p - 1; -} - -/* R_DrawVisSprite - * mfloorclip and mceilingclip should also be set. - */ - -static void r_draw_vis_sprite(vissprite_t *vis, int x1, int x2) -{ - column_t *column; - int texturecolumn; - fixed_t frac; - patch_t *patch; - - patch = w_cache_lump_num(vis->patch + firstspritelump, PU_CACHE); - - dc_colormap = vis->colormap; - - if (!dc_colormap) - { - /* NULL colormap = shadow draw */ - - colfunc = fuzzcolfunc; - } - else if (vis->mobjflags & MF_TRANSLATION) - { - colfunc = transcolfunc; - dc_translation = - translationtables - 256 + - ((vis->mobjflags & MF_TRANSLATION) >> (MF_TRANSSHIFT - 8)); - } - - dc_iscale = abs(vis->xiscale) >> detailshift; - dc_texturemid = vis->texturemid; - frac = vis->startfrac; - spryscale = vis->scale; - sprtopscreen = centeryfrac - fixed_mul(dc_texturemid, spryscale); - - for (dc_x = vis->x1; dc_x <= vis->x2; dc_x++, frac += vis->xiscale) - { - texturecolumn = frac >> FRACBITS; - -#ifdef CONFIG_GAMES_NXDOOM_RANGECHECK - if (texturecolumn < 0 || texturecolumn >= SHORT(patch->width)) - { - i_error("R_DrawSpriteRange: bad texturecolumn"); - } - -#endif - - column = (column_t *)((byte *)patch + - LONG(patch->columnofs[texturecolumn])); - r_draw_masked_column(column); - } - - colfunc = basecolfunc; -} - -/* R_ProjectSprite - * Generates a vissprite for a thing if it might be visible. - */ - -static void r_project_sprite(mobj_t *thing) -{ - fixed_t tr_x; - fixed_t tr_y; - - fixed_t gxt; - fixed_t gyt; - - fixed_t tx; - fixed_t tz; - - fixed_t xscale; - - int x1; - int x2; - - spritedef_t *sprdef; - spriteframe_t *sprframe; - int lump; - - unsigned rot; - boolean flip; - - int index; - - vissprite_t *vis; - - angle_t ang; - fixed_t iscale; - - /* transform the origin point */ - - tr_x = thing->x - viewx; - tr_y = thing->y - viewy; - - gxt = fixed_mul(tr_x, viewcos); - gyt = -fixed_mul(tr_y, viewsin); - - tz = gxt - gyt; - - /* thing is behind view plane? */ - - if (tz < MINZ) return; - - xscale = fixed_div(projection, tz); - - gxt = -fixed_mul(tr_x, viewsin); - gyt = fixed_mul(tr_y, viewcos); - tx = -(gyt + gxt); - - /* too far off the side? */ - - if (abs(tx) > (tz << 2)) return; - - /* decide which patch to use for sprite relative to player */ - -#ifdef CONFIG_GAMES_NXDOOM_RANGECHECK - if ((unsigned int)thing->sprite >= (unsigned int)numsprites) - i_error("R_ProjectSprite: invalid sprite number %i ", thing->sprite); -#endif - sprdef = &sprites[thing->sprite]; -#ifdef CONFIG_GAMES_NXDOOM_RANGECHECK - if ((thing->frame & FF_FRAMEMASK) >= sprdef->numframes) - i_error("R_ProjectSprite: invalid sprite frame %i : %i ", thing->sprite, - thing->frame); -#endif - sprframe = &sprdef->spriteframes[thing->frame & FF_FRAMEMASK]; - - if (sprframe->rotate) - { - /* choose a different rotation based on player view */ - - ang = r_point_to_angle(thing->x, thing->y); - rot = (ang - thing->angle + (unsigned)(ANG45 / 2) * 9) >> 29; - lump = sprframe->lump[rot]; - flip = (boolean)sprframe->flip[rot]; - } - else - { - /* use single rotation for all views */ - - lump = sprframe->lump[0]; - flip = (boolean)sprframe->flip[0]; - } - - /* calculate edges of the shape */ - - tx -= spriteoffset[lump]; - x1 = (centerxfrac + fixed_mul(tx, xscale)) >> FRACBITS; - - /* off the right side? */ - - if (x1 > viewwidth) return; - - tx += spritewidth[lump]; - x2 = ((centerxfrac + fixed_mul(tx, xscale)) >> FRACBITS) - 1; - - /* off the left side */ - - if (x2 < 0) return; - - /* store information in a vissprite */ - - vis = r_new_vis_sprite(); - vis->mobjflags = thing->flags; - vis->scale = xscale << detailshift; - vis->gx = thing->x; - vis->gy = thing->y; - vis->gz = thing->z; - vis->gzt = thing->z + spritetopoffset[lump]; - vis->texturemid = vis->gzt - viewz; - vis->x1 = x1 < 0 ? 0 : x1; - vis->x2 = x2 >= viewwidth ? viewwidth - 1 : x2; - iscale = fixed_div(FRACUNIT, xscale); - - if (flip) - { - vis->startfrac = spritewidth[lump] - 1; - vis->xiscale = -iscale; - } - else - { - vis->startfrac = 0; - vis->xiscale = iscale; - } - - if (vis->x1 > x1) vis->startfrac += vis->xiscale * (vis->x1 - x1); - vis->patch = lump; - - /* get light level */ - - if (thing->flags & MF_SHADOW) - { - /* shadow draw */ - - vis->colormap = NULL; - } - else if (fixedcolormap) - { - /* fixed map */ - - vis->colormap = fixedcolormap; - } - else if (thing->frame & FF_FULLBRIGHT) - { - /* full bright */ - - vis->colormap = colormaps; - } - - else - { - /* diminished light */ - - index = xscale >> (LIGHTSCALESHIFT - detailshift); - - if (index >= MAXLIGHTSCALE) index = MAXLIGHTSCALE - 1; - - vis->colormap = spritelights[index]; - } -} - -/* R_DrawPSprite */ - -static void r_draw_psprite(pspdef_t *psp) -{ - fixed_t tx; - int x1; - int x2; - spritedef_t *sprdef; - spriteframe_t *sprframe; - int lump; - boolean flip; - vissprite_t *vis; - vissprite_t avis; - - /* decide which patch to use */ - -#ifdef CONFIG_GAMES_NXDOOM_RANGECHECK - if ((unsigned)psp->state->sprite >= (unsigned int)numsprites) - { - i_error("R_ProjectSprite: invalid sprite number %i ", - psp->state->sprite); - } - -#endif - - sprdef = &sprites[psp->state->sprite]; - -#ifdef CONFIG_GAMES_NXDOOM_RANGECHECK - if ((psp->state->frame & FF_FRAMEMASK) >= sprdef->numframes) - { - i_error("R_ProjectSprite: invalid sprite frame %i : %i ", - psp->state->sprite, psp->state->frame); - } - -#endif - sprframe = &sprdef->spriteframes[psp->state->frame & FF_FRAMEMASK]; - - lump = sprframe->lump[0]; - flip = (boolean)sprframe->flip[0]; - - /* calculate edges of the shape */ - - tx = psp->sx - (SCREENWIDTH / 2) * FRACUNIT; - - tx -= spriteoffset[lump]; - x1 = (centerxfrac + fixed_mul(tx, pspritescale)) >> FRACBITS; - - /* off the right side */ - - if (x1 > viewwidth) return; - - tx += spritewidth[lump]; - x2 = ((centerxfrac + fixed_mul(tx, pspritescale)) >> FRACBITS) - 1; - - /* off the left side */ - - if (x2 < 0) return; - - /* store information in a vissprite */ - - vis = &avis; - vis->mobjflags = 0; - vis->texturemid = (BASEYCENTER << FRACBITS) + FRACUNIT / 2 - - (psp->sy - spritetopoffset[lump]); - vis->x1 = x1 < 0 ? 0 : x1; - vis->x2 = x2 >= viewwidth ? viewwidth - 1 : x2; - vis->scale = pspritescale << detailshift; - - if (flip) - { - vis->xiscale = -pspriteiscale; - vis->startfrac = spritewidth[lump] - 1; - } - else - { - vis->xiscale = pspriteiscale; - vis->startfrac = 0; - } - - if (vis->x1 > x1) vis->startfrac += vis->xiscale * (vis->x1 - x1); - - vis->patch = lump; - - if (viewplayer->powers[pw_invisibility] > 4 * 32 || - viewplayer->powers[pw_invisibility] & 8) - { - vis->colormap = NULL; /* shadow draw */ - } - else if (fixedcolormap) - { - vis->colormap = fixedcolormap; /* fixed color */ - } - else if (psp->state->frame & FF_FULLBRIGHT) - { - vis->colormap = colormaps; /* full bright */ - } - else - { - vis->colormap = spritelights[MAXLIGHTSCALE - 1]; /* local light */ - } - - r_draw_vis_sprite(vis, vis->x1, vis->x2); -} - -static void r_draw_player_sprites(void) -{ - int i; - int lightnum; - pspdef_t *psp; - - /* get light level */ - - lightnum = - (viewplayer->mo->subsector->sector->lightlevel >> LIGHTSEGSHIFT) + - extralight; - - if (lightnum < 0) - spritelights = scalelight[0]; - else if (lightnum >= LIGHTLEVELS) - spritelights = scalelight[LIGHTLEVELS - 1]; - else - spritelights = scalelight[lightnum]; - - /* clip to screen bounds */ - - mfloorclip = screenheightarray; - mceilingclip = negonearray; - - /* add all active psprites */ - - for (i = 0, psp = viewplayer->psprites; i < NUMPSPRITES; i++, psp++) - { - if (psp->state) r_draw_psprite(psp); - } -} - -static void r_sort_vis_sprites(void) -{ - int i; - int count; - vissprite_t *ds; - vissprite_t *best; - static vissprite_t unsorted; - fixed_t bestscale; - - count = vissprite_p - vissprites; - - unsorted.next = unsorted.prev = &unsorted; - - if (!count) return; - - for (ds = vissprites; ds < vissprite_p; ds++) - { - ds->next = ds + 1; - ds->prev = ds - 1; - } - - vissprites[0].prev = &unsorted; - unsorted.next = &vissprites[0]; - (vissprite_p - 1)->next = &unsorted; - unsorted.prev = vissprite_p - 1; - - /* pull the vissprites out by scale */ - - vsprsortedhead.next = vsprsortedhead.prev = &vsprsortedhead; - for (i = 0; i < count; i++) - { - bestscale = INT_MAX; - best = unsorted.next; - - for (ds = unsorted.next; ds != &unsorted; ds = ds->next) - { - if (ds->scale < bestscale) - { - bestscale = ds->scale; - best = ds; - } - } - - best->next->prev = best->prev; - best->prev->next = best->next; - best->next = &vsprsortedhead; - best->prev = vsprsortedhead.prev; - vsprsortedhead.prev->next = best; - vsprsortedhead.prev = best; - } -} - -static void r_draw_sprite(vissprite_t *spr) -{ - drawseg_t *ds; - short clipbot[SCREENWIDTH]; - short cliptop[SCREENWIDTH]; - int x; - int r1; - int r2; - fixed_t scale; - fixed_t lowscale; - int silhouette; - - for (x = spr->x1; x <= spr->x2; x++) - clipbot[x] = cliptop[x] = -2; - - /* Scan drawsegs from end to start for obscuring segs. - * The first drawseg that has a greater scale is the clip seg. - */ - - for (ds = ds_p - 1; ds >= drawsegs; ds--) - { - /* determine if the drawseg obscures the sprite */ - - if (ds->x1 > spr->x2 || ds->x2 < spr->x1 || - (!ds->silhouette && !ds->maskedtexturecol)) - { - continue; /* does not cover sprite */ - } - - r1 = ds->x1 < spr->x1 ? spr->x1 : ds->x1; - r2 = ds->x2 > spr->x2 ? spr->x2 : ds->x2; - - if (ds->scale1 > ds->scale2) - { - lowscale = ds->scale2; - scale = ds->scale1; - } - else - { - lowscale = ds->scale1; - scale = ds->scale2; - } - - if (scale < spr->scale || - (lowscale < spr->scale && - !r_point_on_seg_side(spr->gx, spr->gy, ds->curline))) - { - /* masked mid texture? */ - - if (ds->maskedtexturecol) r_render_masked_seg_range(ds, r1, r2); - continue; /* seg is behind sprite */ - } - - /* clip this piece of the sprite */ - - silhouette = ds->silhouette; - - if (spr->gz >= ds->bsilheight) silhouette &= ~SIL_BOTTOM; - - if (spr->gzt <= ds->tsilheight) silhouette &= ~SIL_TOP; - - if (silhouette == 1) - { - /* bottom sil */ - - for (x = r1; x <= r2; x++) - { - if (clipbot[x] == -2) clipbot[x] = ds->sprbottomclip[x]; - } - } - else if (silhouette == 2) - { - /* top sil */ - - for (x = r1; x <= r2; x++) - { - if (cliptop[x] == -2) cliptop[x] = ds->sprtopclip[x]; - } - } - else if (silhouette == 3) - { - /* both */ - - for (x = r1; x <= r2; x++) - { - if (clipbot[x] == -2) clipbot[x] = ds->sprbottomclip[x]; - if (cliptop[x] == -2) cliptop[x] = ds->sprtopclip[x]; - } - } - } - - /* all clipping has been performed, so draw the sprite */ - - /* check for unclipped columns */ - - for (x = spr->x1; x <= spr->x2; x++) - { - if (clipbot[x] == -2) clipbot[x] = viewheight; - - if (cliptop[x] == -2) cliptop[x] = -1; - } - - mfloorclip = clipbot; - mceilingclip = cliptop; - r_draw_vis_sprite(spr, spr->x1, spr->x2); -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/* r_init_sprites - * Called at program start. - */ - -void r_init_sprites(const char **namelist) -{ - int i; - - for (i = 0; i < SCREENWIDTH; i++) - { - negonearray[i] = -1; - } - - r_init_sprite_defs(namelist); -} - -/* Called at frame start. */ - -void r_clear_sprites(void) -{ - vissprite_p = vissprites; -} - -/* r_draw_masked_column - * Used for sprites and masked mid textures. - * Masked means: partly transparent, i.e. stored in posts/runs of opaque - * pixels. - */ - -void r_draw_masked_column(column_t *column) -{ - int topscreen; - int bottomscreen; - fixed_t basetexturemid; - - basetexturemid = dc_texturemid; - - for (; column->topdelta != 0xff; ) - { - /* calculate unclipped screen coordinates for post */ - - topscreen = sprtopscreen + spryscale * column->topdelta; - bottomscreen = topscreen + spryscale * column->length; - - dc_yl = (topscreen + FRACUNIT - 1) >> FRACBITS; - dc_yh = (bottomscreen - 1) >> FRACBITS; - - if (dc_yh >= mfloorclip[dc_x]) dc_yh = mfloorclip[dc_x] - 1; - if (dc_yl <= mceilingclip[dc_x]) dc_yl = mceilingclip[dc_x] + 1; - - if (dc_yl <= dc_yh) - { - dc_source = (byte *)column + 3; - dc_texturemid = basetexturemid - (column->topdelta << FRACBITS); - - /* Drawn by either r_draw_column or (SHADOW) r_draw_fuzz_column. - */ - - colfunc(); - } - - column = (column_t *)((byte *)column + column->length + 4); - } - - dc_texturemid = basetexturemid; -} - -/* r_add_sprites - * During BSP traversal, this adds sprites by sector. - */ - -void r_add_sprites(sector_t *sec) -{ - mobj_t *thing; - int lightnum; - - /* BSP is traversed by subsector. - * A sector might have been split into several subsectors during BSP - * building. Thus we check whether its already added. - */ - - if (sec->validcount == validcount) return; - - /* Well, now it will be done. */ - - sec->validcount = validcount; - - lightnum = (sec->lightlevel >> LIGHTSEGSHIFT) + extralight; - - if (lightnum < 0) - spritelights = scalelight[0]; - else if (lightnum >= LIGHTLEVELS) - spritelights = scalelight[LIGHTLEVELS - 1]; - else - spritelights = scalelight[lightnum]; - - /* Handle all things in sector. */ - - for (thing = sec->thinglist; thing; thing = thing->snext) - r_project_sprite(thing); -} - -void r_draw_masked(void) -{ - vissprite_t *spr; - drawseg_t *ds; - - r_sort_vis_sprites(); - - if (vissprite_p > vissprites) - { - /* draw all vissprites back to front */ - - for (spr = vsprsortedhead.next; - spr != &vsprsortedhead; - spr = spr->next) - { - r_draw_sprite(spr); - } - } - - /* render any remaining masked mid textures */ - - for (ds = ds_p - 1; ds >= drawsegs; ds--) - { - if (ds->maskedtexturecol) - { - r_render_masked_seg_range(ds, ds->x1, ds->x2); - } - } - - /* draw the psprites on top of everything but does not draw on side views - */ - - if (!viewangleoffset) - { - r_draw_player_sprites(); - } -} diff --git a/games/NXDoom/src/doom/r_things.h b/games/NXDoom/src/doom/r_things.h deleted file mode 100644 index cdd299483..000000000 --- a/games/NXDoom/src/doom/r_things.h +++ /dev/null @@ -1,61 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/r_things.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Rendering of moving objects, sprites. - * - ****************************************************************************/ - -#ifndef __R_THINGS__ -#define __R_THINGS__ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -extern vissprite_t vissprites[CONFIG_GAMES_NXDOOM_MAXVISSPRITES]; -extern vissprite_t *vissprite_p; -extern vissprite_t vsprsortedhead; - -/* Constant arrays used for psprite clipping and initializing clipping. */ - -extern short negonearray[SCREENWIDTH]; -extern short screenheightarray[SCREENWIDTH]; - -/* vars for r_draw_masked_column */ - -extern short *mfloorclip; -extern short *mceilingclip; -extern fixed_t spryscale; -extern fixed_t sprtopscreen; - -extern fixed_t pspritescale; -extern fixed_t pspriteiscale; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -void r_draw_masked_column(column_t *column); - -void r_add_sprites(sector_t *sec); -void r_init_sprites(const char **namelist); -void r_clear_sprites(void); -void r_draw_masked(void); - -#endif /* __R_THINGS__ */ diff --git a/games/NXDoom/src/doom/s_sound.c b/games/NXDoom/src/doom/s_sound.c deleted file mode 100644 index dbca08a57..000000000 --- a/games/NXDoom/src/doom/s_sound.c +++ /dev/null @@ -1,771 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/s_sound.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: none - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -#include "i_sound.h" -#include "i_system.h" - -#include "deh_str.h" - -#include "doomstat.h" -#include "doomtype.h" - -#include "s_sound.h" -#include "sounds.h" - -#include "m_argv.h" -#include "m_misc.h" -#include "m_random.h" - -#include "p_local.h" -#include "w_wad.h" -#include "z_zone.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* when to clip out sounds - * Does not fit the large outdoor areas. - */ - -#define S_CLIPPING_DIST (1200 * FRACUNIT) - -/* Distance tp origin when sounds should be maxed out. - * This should relate to movement clipping resolution - * (see BLOCKMAP handling). - * In the source code release: (160*FRACUNIT). Changed back to the - * Vanilla value of 200 (why was this changed?) - */ - -#define S_CLOSE_DIST (200 * FRACUNIT) - -/* The range over which sound attenuates */ - -#define S_ATTENUATOR ((S_CLIPPING_DIST - S_CLOSE_DIST) >> FRACBITS) - -/* Stereo separation */ - -#define S_STEREO_SWING (96 * FRACUNIT) - -#define NORM_PRIORITY 64 -#define NORM_SEP 128 - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -typedef struct -{ - /* sound information (if null, channel avail.) */ - - sfxinfo_t *sfxinfo; - - /* origin of sound */ - - mobj_t *origin; - - /* handle of the sound being played */ - - int handle; - - int pitch; -} channel_t; - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/* The set of channels available */ - -static channel_t *channels; - -/* Internal volume level, ranging from 0-127 */ - -static int g_snd_sfx_volume; - -/* Whether songs are mus_paused */ - -static boolean mus_paused; - -/* Music currently being played */ - -static musicinfo_t *mus_playing = NULL; - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/* Maximum volume of a sound effect. - * Internal default is max out of 0-15. - */ - -int g_sfx_volume = 8; - -/* Maximum volume of music. */ - -int g_music_volume = 8; - -/* Number of channels to use */ - -int snd_channels = 8; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static void s_stop_channel(int cnum) -{ - int i; - channel_t *c; - - c = &channels[cnum]; - - if (c->sfxinfo) - { - /* stop the sound playing */ - - if (i_sound_playing(c->handle)) - { - i_stop_sound(c->handle); - } - - /* check to see if other channels are playing the sound */ - - for (i = 0; i < snd_channels; i++) - { - if (cnum != i && c->sfxinfo == channels[i].sfxinfo) - { - break; - } - } - - /* degrade usefulness of sound data */ - - c->sfxinfo->usefulness--; - c->sfxinfo = NULL; - c->origin = NULL; - } -} - -/* S_GetChannel: If none available, return -1. Otherwise channel #. */ - -static int s_get_channel(mobj_t *origin, sfxinfo_t *sfxinfo) -{ - /* channel number to use */ - - int cnum; - - channel_t *c; - - /* Find an open channel */ - - for (cnum = 0; cnum < snd_channels; cnum++) - { - if (!channels[cnum].sfxinfo) - { - break; - } - else if (origin && channels[cnum].origin == origin) - { - s_stop_channel(cnum); - break; - } - } - - /* None available */ - - if (cnum == snd_channels) - { - /* Look for lower priority */ - - for (cnum = 0; cnum < snd_channels; cnum++) - { - if (channels[cnum].sfxinfo->priority >= sfxinfo->priority) - { - break; - } - } - - if (cnum == snd_channels) - { - /* FUCK! No lower priority. Sorry, Charlie. */ - - return -1; - } - else - { - /* Otherwise, kick out lower priority. */ - - s_stop_channel(cnum); - } - } - - c = &channels[cnum]; - - /* channel is decided to be cnum. */ - - c->sfxinfo = sfxinfo; - c->origin = origin; - - return cnum; -} - -/* Changes volume and stereo-separation variables from the norm of a sound - * effect to be played. If the sound is not audible, returns a 0. Otherwise, - * modifies parameters and returns 1. - */ - -static int s_adjust_sound_params(mobj_t *listener, mobj_t *source, int *vol, - int *sep) -{ - fixed_t approx_dist; - fixed_t adx; - fixed_t ady; - angle_t angle; - - /* calculate the distance to sound origin and clip it if necessary */ - - adx = abs(listener->x - source->x); - ady = abs(listener->y - source->y); - - /* From _GG1_ p.428. Appox. Euclidean distance fast. */ - - approx_dist = adx + ady - ((adx < ady ? adx : ady) >> 1); - - if (gamemap != 8 && approx_dist > S_CLIPPING_DIST) - { - return 0; - } - - /* angle of source to listener */ - - angle = r_point_to_angle2(listener->x, listener->y, source->x, source->y); - - if (angle > listener->angle) - { - angle = angle - listener->angle; - } - else - { - angle = angle + (0xffffffff - listener->angle); - } - - angle >>= ANGLETOFINESHIFT; - - /* stereo separation */ - - *sep = 128 - (fixed_mul(S_STEREO_SWING, finesine[angle]) >> FRACBITS); - - /* volume calculation */ - - if (approx_dist < S_CLOSE_DIST) - { - *vol = g_snd_sfx_volume; - } - else if (gamemap == 8) - { - if (approx_dist > S_CLIPPING_DIST) - { - approx_dist = S_CLIPPING_DIST; - } - - *vol = 15 + ((g_snd_sfx_volume - 15) * - ((S_CLIPPING_DIST - approx_dist) >> FRACBITS)) / - S_ATTENUATOR; - } - else - { - /* distance effect */ - - *vol = (g_snd_sfx_volume * - ((S_CLIPPING_DIST - approx_dist) >> FRACBITS) - ) / S_ATTENUATOR; - } - - return (*vol > 0); -} - -/* clamp supplied integer to the range 0 <= x <= 255. */ - -static int clamp(int x) -{ - if (x < 0) - { - return 0; - } - else if (x > 255) - { - return 255; - } - - return x; -} - -static void s_shutdown(void) -{ - i_shutdown_sound(); - i_shutdown_music(); -} - -static void s_stop_music(void) -{ - if (mus_playing) - { - if (mus_paused) - { - i_resume_song(); - } - - i_stop_song(); - i_unregister_song(mus_playing->handle); - w_release_lump_num(mus_playing->lumpnum); - mus_playing->data = NULL; - mus_playing = NULL; - } -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/* Initializes sound stuff, including volume - * - * Sets channels, SFX and music volume, allocates channel buffer, sets s_sfx - * lookup. - */ - -void s_init(int sfxvolume, int musicvolume) -{ - int i; - -#if 0 - if (gameversion == exe_doom_1_666) - { - if (logical_gamemission == doom) - { - i_set_opl_driver_ver(opl_doom1_1_666); - } - else - { - i_set_opl_driver_ver(opl_doom2_1_666); - } - } - else - { - i_set_opl_driver_ver(opl_doom_1_9); - } -#endif - - i_precache_sounds(s_sfx, SFX_NUMSFX); - - s_set_sfx_volume(sfxvolume); - s_set_music_volume(musicvolume); - - /* Allocating the internal channels for mixing - * (the maximum number of sounds rendered - * simultaneously) within zone memory. - */ - - channels = z_malloc(snd_channels * sizeof(channel_t), PU_STATIC, 0); - - /* Free all channels for use */ - - for (i = 0; i < snd_channels; i++) - { - channels[i].sfxinfo = 0; - } - - /* no sounds are playing, and they are not mus_paused */ - - mus_paused = 0; - - /* Note that sounds have not been cached (yet). */ - - for (i = 1; i < SFX_NUMSFX; i++) - { - s_sfx[i].lumpnum = s_sfx[i].usefulness = -1; - } - - /* Doom defaults to pitch-shifting off. */ - - if (snd_pitchshift == -1) - { - snd_pitchshift = 0; - } - - i_at_exit(s_shutdown, true); -} - -/* Per level startup code. - * Kills playing sounds at start of level, determines music if any, changes - * music. - */ - -void s_start(void) -{ - int cnum; - int mnum; - - /* kill all playing sounds at start of level (trust me - a good idea) - */ - - for (cnum = 0; cnum < snd_channels; cnum++) - { - if (channels[cnum].sfxinfo) - { - s_stop_channel(cnum); - } - } - - /* start new music for the level */ - - mus_paused = 0; - - if (gamemode == commercial) - { - mnum = MUS_RUNNIN + gamemap - 1; - } - else - { - int spmus[] = { - /* Song - Who? - Where? */ - - MUS_E3M4, /* American e4m1 */ - MUS_E3M2, /* Romero e4m2 */ - MUS_E3M3, /* Shawn e4m3 */ - MUS_E1M5, /* American e4m4 */ - MUS_E2M7, /* Tim e4m5 */ - MUS_E2M4, /* Romero e4m6 */ - MUS_E2M6, /* J.Anderson e4m7 CHIRON.WAD */ - MUS_E2M5, /* Shawn e4m8 */ - MUS_E1M9, /* Tim e4m9 */ - }; - - if (gameepisode < 4) - { - mnum = MUS_E1M1 + (gameepisode - 1) * 9 + gamemap - 1; - } - else - { - mnum = spmus[gamemap - 1]; - } - } - - s_change_music(mnum, true); -} - -void s_stop_sound(mobj_t *origin) -{ - int cnum; - - for (cnum = 0; cnum < snd_channels; cnum++) - { - if (channels[cnum].sfxinfo && channels[cnum].origin == origin) - { - s_stop_channel(cnum); - break; - } - } -} - -void s_start_sound(void *origin_p, int sfx_id) -{ - sfxinfo_t *sfx; - mobj_t *origin; - int rc; - int sep; - int pitch; - int cnum; - int volume; - - origin = (mobj_t *)origin_p; - volume = g_snd_sfx_volume; - - /* check for bogus sound # */ - - if (sfx_id < 1 || sfx_id > SFX_NUMSFX) - { - i_error("Bad sfx #: %d", sfx_id); - } - - sfx = &s_sfx[sfx_id]; - - /* Initialize sound parameters */ - - pitch = NORM_PITCH; - if (sfx->link) - { - volume += sfx->volume; - pitch = sfx->pitch; - - if (volume < 1) - { - return; - } - - if (volume > g_snd_sfx_volume) - { - volume = g_snd_sfx_volume; - } - } - - /* Check to see if it is audible, and if not, modify the params */ - - if (origin && origin != players[consoleplayer].mo) - { - rc = s_adjust_sound_params(players[consoleplayer].mo, origin, &volume, - &sep); - - if (origin->x == players[consoleplayer].mo->x && - origin->y == players[consoleplayer].mo->y) - { - sep = NORM_SEP; - } - - if (!rc) - { - return; - } - } - else - { - sep = NORM_SEP; - } - - /* hacks to vary the sfx pitches */ - - if (sfx_id >= SFX_SAWUP && sfx_id <= SFX_SAWHIT) - { - pitch += 8 - (m_random() & 15); - } - else if (sfx_id != SFX_ITEMUP && sfx_id != SFX_TINK) - { - pitch += 16 - (m_random() & 31); - } - - pitch = clamp(pitch); - - s_stop_sound(origin); /* kill old sound */ - - /* try to find a channel */ - - cnum = s_get_channel(origin, sfx); - - if (cnum < 0) - { - return; - } - - /* increase the usefulness */ - - if (sfx->usefulness++ < 0) - { - sfx->usefulness = 1; - } - - if (sfx->lumpnum < 0) - { - sfx->lumpnum = i_get_sfx_lumpnum(sfx); - } - - channels[cnum].pitch = pitch; - channels[cnum].handle = - i_start_sound(sfx, cnum, volume, sep, channels[cnum].pitch); -} - -/* Stop and resume music, during game PAUSE. */ - -void s_pause_sound(void) -{ - if (mus_playing && !mus_paused) - { - i_pause_song(); - mus_paused = true; - } -} - -void s_resume_sound(void) -{ - if (mus_playing && mus_paused) - { - i_resume_song(); - mus_paused = false; - } -} - -/* Updates music & sounds */ - -void s_update_sounds(mobj_t *listener) -{ - int audible; - int cnum; - int volume; - int sep; - sfxinfo_t *sfx; - channel_t *c; - - i_update_sound(); - - for (cnum = 0; cnum < snd_channels; cnum++) - { - c = &channels[cnum]; - sfx = c->sfxinfo; - - if (c->sfxinfo) - { - if (i_sound_playing(c->handle)) - { - /* initialize parameters */ - - volume = g_snd_sfx_volume; - sep = NORM_SEP; - - if (sfx->link) - { - volume += sfx->volume; - if (volume < 1) - { - s_stop_channel(cnum); - continue; - } - else if (volume > g_snd_sfx_volume) - { - volume = g_snd_sfx_volume; - } - } - - /* check non-local sounds for distance clipping or modify their - * params - */ - - if (c->origin && listener != c->origin) - { - audible = s_adjust_sound_params(listener, c->origin, - &volume, &sep); - - if (!audible) - { - s_stop_channel(cnum); - } - else - { - i_update_sound_params(c->handle, volume, sep); - } - } - } - else - { - /* if channel is allocated but sound has stopped, free it - */ - - s_stop_channel(cnum); - } - } - } -} - -void s_set_music_volume(int volume) -{ - if (volume < 0 || volume > 127) - { - i_error("Attempt to set music volume at %d", volume); - } - - i_set_music_volume(volume); -} - -void s_set_sfx_volume(int volume) -{ - if (volume < 0 || volume > 127) - { - i_error("Attempt to set sfx volume at %d", volume); - } - - g_snd_sfx_volume = volume; -} - -/* Starts some music with the music id found in sounds.h. */ - -void s_start_music(int m_id) -{ - s_change_music(m_id, false); -} - -void s_change_music(int musicnum, int looping) -{ - musicinfo_t *music = NULL; - char namebuf[9]; - void *handle; - - /* The Doom IWAD file has two versions of the intro music: d_intro - * and d_introa. The latter is used for OPL playback. - */ - - if (musicnum == MUS_INTRO && - (snd_musicdevice == SNDDEVICE_ADLIB || - snd_musicdevice == SNDDEVICE_SB) && - w_check_num_for_name("D_INTROA") >= 0) - { - musicnum = MUS_INTROA; - } - - if (musicnum <= MUS_NONE || musicnum >= MUS_NUMMUSIC) - { - i_error("Bad music number %d", musicnum); - } - else - { - music = &s_music[musicnum]; - } - - if (mus_playing == music) - { - return; - } - - /* shutdown old music */ - - s_stop_music(); - - /* get lumpnum if necessary */ - - if (!music->lumpnum) - { - snprintf(namebuf, sizeof(namebuf), "d_%s", (music->name)); - music->lumpnum = w_get_num_for_name(namebuf); - } - - music->data = w_cache_lump_num(music->lumpnum, PU_STATIC); - - handle = i_register_song(music->data, w_lump_length(music->lumpnum)); - music->handle = handle; - i_play_song(handle, looping); - - mus_playing = music; -} diff --git a/games/NXDoom/src/doom/s_sound.h b/games/NXDoom/src/doom/s_sound.h deleted file mode 100644 index 21f569d9b..000000000 --- a/games/NXDoom/src/doom/s_sound.h +++ /dev/null @@ -1,86 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/s_sound.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * The not so system specific sound interface. - * - ****************************************************************************/ - -#ifndef __S_SOUND__ -#define __S_SOUND__ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "p_mobj.h" -#include "sounds.h" - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -extern int snd_channels; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/* Initializes sound stuff, including volume - * Sets channels, SFX and music volume, allocates channel buffer, sets s_sfx - * lookup. - */ - -void s_init(int sfxvolume, int musicvolume); - -/* Per level startup code. - * Kills playing sounds at start of level, determines music if any, changes - * music. - */ - -void s_start(void); - -/* Start sound for thing at using from sounds.h */ - -void s_start_sound(void *origin, int sound_id); - -/* Stop sound for thing at */ - -void s_stop_sound(mobj_t *origin); - -/* Start music using from sounds.h */ - -void s_start_music(int music_id); - -/* Start music using from sounds.h, and set whether looping */ - -void s_change_music(int music_id, int looping); - -/* Stop and resume music, during game PAUSE. */ - -void s_pause_sound(void); -void s_resume_sound(void); - -/* Updates music & sounds */ - -void s_update_sounds(mobj_t *listener); - -void s_set_music_volume(int volume); -void s_set_sfx_volume(int volume); - -#endif /* __S_SOUND__ */ diff --git a/games/NXDoom/src/doom/sounds.c b/games/NXDoom/src/doom/sounds.c deleted file mode 100644 index b1282cdb2..000000000 --- a/games/NXDoom/src/doom/sounds.c +++ /dev/null @@ -1,189 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/sounds.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Created by a sound utility. - * Kept as a sample, DOOM2 sounds. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include "doomtype.h" -#include "sounds.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* Information about all the music */ - -#define MUSIC(name) {name, 0, NULL, NULL} - -/* Information about all the sfx */ - -#define SOUND(name, priority) \ - {NULL, name, priority, NULL, -1, -1, 0, 0, -1, NULL} -#define SOUND_LINK(name, priority, link_id, pitch, volume) \ - {NULL, name, priority, &s_sfx[link_id], pitch, volume, 0, 0, -1, NULL} - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -musicinfo_t s_music[] = -{ - MUSIC(NULL), MUSIC("e1m1"), MUSIC("e1m2"), MUSIC("e1m3"), - MUSIC("e1m4"), MUSIC("e1m5"), MUSIC("e1m6"), MUSIC("e1m7"), - MUSIC("e1m8"), MUSIC("e1m9"), MUSIC("e2m1"), MUSIC("e2m2"), - MUSIC("e2m3"), MUSIC("e2m4"), MUSIC("e2m5"), MUSIC("e2m6"), - MUSIC("e2m7"), MUSIC("e2m8"), MUSIC("e2m9"), MUSIC("e3m1"), - MUSIC("e3m2"), MUSIC("e3m3"), MUSIC("e3m4"), MUSIC("e3m5"), - MUSIC("e3m6"), MUSIC("e3m7"), MUSIC("e3m8"), MUSIC("e3m9"), - MUSIC("inter"), MUSIC("intro"), MUSIC("bunny"), MUSIC("victor"), - MUSIC("introa"), MUSIC("runnin"), MUSIC("stalks"), MUSIC("countd"), - MUSIC("betwee"), MUSIC("doom"), MUSIC("the_da"), MUSIC("shawn"), - MUSIC("ddtblu"), MUSIC("in_cit"), MUSIC("dead"), MUSIC("stlks2"), - MUSIC("theda2"), MUSIC("doom2"), MUSIC("ddtbl2"), MUSIC("runni2"), - MUSIC("dead2"), MUSIC("stlks3"), MUSIC("romero"), MUSIC("shawn2"), - MUSIC("messag"), MUSIC("count2"), MUSIC("ddtbl3"), MUSIC("ampie"), - MUSIC("theda3"), MUSIC("adrian"), MUSIC("messg2"), MUSIC("romer2"), - MUSIC("tense"), MUSIC("shawn3"), MUSIC("openin"), MUSIC("evil"), - MUSIC("ultima"), MUSIC("read_m"), MUSIC("dm2ttl"), MUSIC("dm2int"), -}; - -sfxinfo_t s_sfx[] = -{ - SOUND("none", 0), /* s_sfx[0] needs to be a dummy for odd reasons. */ - SOUND("pistol", 64), - SOUND("shotgn", 64), - SOUND("sgcock", 64), - SOUND("dshtgn", 64), - SOUND("dbopn", 64), - SOUND("dbcls", 64), - SOUND("dbload", 64), - SOUND("plasma", 64), - SOUND("bfg", 64), - SOUND("sawup", 64), - SOUND("sawidl", 118), - SOUND("sawful", 64), - SOUND("sawhit", 64), - SOUND("rlaunc", 64), - SOUND("rxplod", 70), - SOUND("firsht", 70), - SOUND("firxpl", 70), - SOUND("pstart", 100), - SOUND("pstop", 100), - SOUND("doropn", 100), - SOUND("dorcls", 100), - SOUND("stnmov", 119), - SOUND("swtchn", 78), - SOUND("swtchx", 78), - SOUND("plpain", 96), - SOUND("dmpain", 96), - SOUND("popain", 96), - SOUND("vipain", 96), - SOUND("mnpain", 96), - SOUND("pepain", 96), - SOUND("slop", 78), - SOUND("itemup", 78), - SOUND("wpnup", 78), - SOUND("oof", 96), - SOUND("telept", 32), - SOUND("posit1", 98), - SOUND("posit2", 98), - SOUND("posit3", 98), - SOUND("bgsit1", 98), - SOUND("bgsit2", 98), - SOUND("sgtsit", 98), - SOUND("cacsit", 98), - SOUND("brssit", 94), - SOUND("cybsit", 92), - SOUND("spisit", 90), - SOUND("bspsit", 90), - SOUND("kntsit", 90), - SOUND("vilsit", 90), - SOUND("mansit", 90), - SOUND("pesit", 90), - SOUND("sklatk", 70), - SOUND("sgtatk", 70), - SOUND("skepch", 70), - SOUND("vilatk", 70), - SOUND("claw", 70), - SOUND("skeswg", 70), - SOUND("pldeth", 32), - SOUND("pdiehi", 32), - SOUND("podth1", 70), - SOUND("podth2", 70), - SOUND("podth3", 70), - SOUND("bgdth1", 70), - SOUND("bgdth2", 70), - SOUND("sgtdth", 70), - SOUND("cacdth", 70), - SOUND("skldth", 70), - SOUND("brsdth", 32), - SOUND("cybdth", 32), - SOUND("spidth", 32), - SOUND("bspdth", 32), - SOUND("vildth", 32), - SOUND("kntdth", 32), - SOUND("pedth", 32), - SOUND("skedth", 32), - SOUND("posact", 120), - SOUND("bgact", 120), - SOUND("dmact", 120), - SOUND("bspact", 100), - SOUND("bspwlk", 100), - SOUND("vilact", 100), - SOUND("noway", 78), - SOUND("barexp", 60), - SOUND("punch", 64), - SOUND("hoof", 70), - SOUND("metal", 70), - SOUND_LINK("chgun", 64, SFX_PISTOL, 150, 0), - SOUND("tink", 60), - SOUND("bdopn", 100), - SOUND("bdcls", 100), - SOUND("itmbk", 100), - SOUND("flame", 32), - SOUND("flamst", 32), - SOUND("getpow", 60), - SOUND("bospit", 70), - SOUND("boscub", 70), - SOUND("bossit", 70), - SOUND("bospn", 70), - SOUND("bosdth", 70), - SOUND("manatk", 70), - SOUND("mandth", 70), - SOUND("sssit", 70), - SOUND("ssdth", 70), - SOUND("keenpn", 70), - SOUND("keendt", 70), - SOUND("skeact", 70), - SOUND("skesit", 70), - SOUND("skeatk", 70), - SOUND("radio", 60), -}; - -/**************************************************************************** - * Public Functions - ****************************************************************************/ diff --git a/games/NXDoom/src/doom/sounds.h b/games/NXDoom/src/doom/sounds.h deleted file mode 100644 index a2d9b371f..000000000 --- a/games/NXDoom/src/doom/sounds.h +++ /dev/null @@ -1,241 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/sounds.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Created by the sound utility written by Dave Taylor. - * Kept as a sample, DOOM2 sounds. Frozen. - * - ****************************************************************************/ - -#ifndef __SOUNDS__ -#define __SOUNDS__ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "i_sound.h" - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -/* Identifiers for all music in game. */ - -typedef enum -{ - MUS_NONE, - MUS_E1M1, - MUS_E1M2, - MUS_E1M3, - MUS_E1M4, - MUS_E1M5, - MUS_E1M6, - MUS_E1M7, - MUS_E1M8, - MUS_E1M9, - MUS_E2M1, - MUS_E2M2, - MUS_E2M3, - MUS_E2M4, - MUS_E2M5, - MUS_E2M6, - MUS_E2M7, - MUS_E2M8, - MUS_E2M9, - MUS_E3M1, - MUS_E3M2, - MUS_E3M3, - MUS_E3M4, - MUS_E3M5, - MUS_E3M6, - MUS_E3M7, - MUS_E3M8, - MUS_E3M9, - MUS_INTER, - MUS_INTRO, - MUS_BUNNY, - MUS_VICTOR, - MUS_INTROA, - MUS_RUNNIN, - MUS_STALKS, - MUS_COUNTD, - MUS_BETWEE, - MUS_DOOM, - MUS_THE_DA, - MUS_SHAWN, - MUS_DDTBLU, - MUS_IN_CIT, - MUS_DEAD, - MUS_STLKS2, - MUS_THEDA2, - MUS_DOOM2, - MUS_DDTBL2, - MUS_RUNNI2, - MUS_DEAD2, - MUS_STLKS3, - MUS_ROMERO, - MUS_SHAWN2, - MUS_MESSAG, - MUS_COUNT2, - MUS_DDTBL3, - MUS_AMPIE, - MUS_THEDA3, - MUS_ADRIAN, - MUS_MESSG2, - MUS_ROMER2, - MUS_TENSE, - MUS_SHAWN3, - MUS_OPENIN, - MUS_EVIL, - MUS_ULTIMA, - MUS_READ_M, - MUS_DM2TTL, - MUS_DM2INT, - MUS_NUMMUSIC -} musicenum_t; - -/* Identifiers for all sfx in game. */ - -typedef enum -{ - SFX_NONE, - SFX_PISTOL, - SFX_SHOTGN, - SFX_SGCOCK, - SFX_DSHTGN, - SFX_DBOPN, - SFX_DBCLS, - SFX_DBLOAD, - SFX_PLASMA, - SFX_BFG, - SFX_SAWUP, - SFX_SAWIDL, - SFX_SAWFUL, - SFX_SAWHIT, - SFX_RLAUNC, - SFX_RXPLOD, - SFX_FIRSHT, - SFX_FIRXPL, - SFX_PSTART, - SFX_PSTOP, - SFX_DOROPN, - SFX_DORCLS, - SFX_STNMOV, - SFX_SWTCHN, - SFX_SWTCHX, - SFX_PLPAIN, - SFX_DMPAIN, - SFX_POPAIN, - SFX_VIPAIN, - SFX_MNPAIN, - SFX_PEPAIN, - SFX_SLOP, - SFX_ITEMUP, - SFX_WPNUP, - SFX_OOF, - SFX_TELEPT, - SFX_POSIT1, - SFX_POSIT2, - SFX_POSIT3, - SFX_BGSIT1, - SFX_BGSIT2, - SFX_SGTSIT, - SFX_CACSIT, - SFX_BRSSIT, - SFX_CYBSIT, - SFX_SPISIT, - SFX_BSPSIT, - SFX_KNTSIT, - SFX_VILSIT, - SFX_MANSIT, - SFX_PESIT, - SFX_SKLATK, - SFX_SGTATK, - SFX_SKEPCH, - SFX_VILATK, - SFX_CLAW, - SFX_SKESWG, - SFX_PLDETH, - SFX_PDIEHI, - SFX_PODTH1, - SFX_PODTH2, - SFX_PODTH3, - SFX_BGDTH1, - SFX_BGDTH2, - SFX_SGTDTH, - SFX_CACDTH, - SFX_SKLDTH, - SFX_BRSDTH, - SFX_CYBDTH, - SFX_SPIDTH, - SFX_BSPDTH, - SFX_VILDTH, - SFX_KNTDTH, - SFX_PEDTH, - SFX_SKEDTH, - SFX_POSACT, - SFX_BGACT, - SFX_DMACT, - SFX_BSPACT, - SFX_BSPWLK, - SFX_VILACT, - SFX_NOWAY, - SFX_BAREXP, - SFX_PUNCH, - SFX_HOOF, - SFX_METAL, - SFX_CHGUN, - SFX_TINK, - SFX_BDOPN, - SFX_BDCLS, - SFX_ITMBK, - SFX_FLAME, - SFX_FLAMST, - SFX_GETPOW, - SFX_BOSPIT, - SFX_BOSCUB, - SFX_BOSSIT, - SFX_BOSPN, - SFX_BOSDTH, - SFX_MANATK, - SFX_MANDTH, - SFX_SSSIT, - SFX_SSDTH, - SFX_KEENPN, - SFX_KEENDT, - SFX_SKEACT, - SFX_SKESIT, - SFX_SKEATK, - SFX_RADIO, - SFX_NUMSFX -} sfxenum_t; - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/* the complete set of sound effects */ - -extern sfxinfo_t s_sfx[]; - -/* the complete set of music */ - -extern musicinfo_t s_music[]; - -#endif /* __SOUNDS__ */ diff --git a/games/NXDoom/src/doom/st_lib.c b/games/NXDoom/src/doom/st_lib.c deleted file mode 100644 index d8aeda710..000000000 --- a/games/NXDoom/src/doom/st_lib.c +++ /dev/null @@ -1,238 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/st_lib.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * The status bar widget code. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -#include "deh_main.h" -#include "doomdef.h" - -#include "v_video.h" -#include "z_zone.h" - -#include "i_swap.h" -#include "i_system.h" - -#include "w_wad.h" - -#include "r_local.h" -#include "st_lib.h" -#include "st_stuff.h" - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/* Hack display negative frags. Loads and store the stminus lump. */ - -patch_t *sttminus; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: stlib_draw_num - * - * Description: - * A fairly efficient way to draw a number based on differences from the old - * number. Note: worth the trouble? - * - ****************************************************************************/ - -static void stlib_draw_num(st_number_t *n, boolean refresh) -{ - int numdigits = n->width; - int num = *n->num; - - int w = SHORT(n->p[0]->width); - int h = SHORT(n->p[0]->height); - int x = n->x; - - int neg; - - n->oldnum = *n->num; - - neg = num < 0; - - if (neg) - { - if (numdigits == 2 && num < -9) - num = -9; - else if (numdigits == 3 && num < -99) - num = -99; - - num = -num; - } - - /* clear the area */ - - x = n->x - numdigits * w; - - if (n->y - ST_Y < 0) i_error("drawNum: n->y - ST_Y < 0"); - - v_copy_rect(x, n->y - ST_Y, st_backing_screen, w * numdigits, h, x, n->y); - - if (num == 1994) return; /* if non-number, do not draw it */ - - x = n->x; - - /* in the special case of 0, you draw 0 */ - - if (!num) v_draw_patch(x - w, n->y, n->p[0]); - - /* draw the new number */ - - while (num && numdigits--) - { - x -= w; - v_draw_patch(x, n->y, n->p[num % 10]); - num /= 10; - } - - /* draw a minus sign if necessary */ - - if (neg && sttminus) v_draw_patch(x - 8, n->y, sttminus); -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -void stlib_init(void) -{ - if (w_check_num_for_name(("STTMINUS")) >= 0) - sttminus = (patch_t *)w_cache_lump_name(("STTMINUS"), PU_STATIC); - else - sttminus = NULL; -} - -/* ? */ - -void stlib_init_num(st_number_t *n, int x, int y, patch_t **pl, int *num, - boolean *on, int width) -{ - n->x = x; - n->y = y; - n->oldnum = 0; - n->width = width; - n->num = num; - n->on = on; - n->p = pl; -} - -void stlib_update_num(st_number_t *n, boolean refresh) -{ - if (*n->on) stlib_draw_num(n, refresh); -} - -void stlib_init_percent(st_percent_t *p, int x, int y, patch_t **pl, - int *num, boolean *on, patch_t *percent) -{ - stlib_init_num(&p->n, x, y, pl, num, on, 3); - p->p = percent; -} - -void stlib_update_percent(st_percent_t *per, int refresh) -{ - if (refresh && *per->n.on) v_draw_patch(per->n.x, per->n.y, per->p); - - stlib_update_num(&per->n, refresh); -} - -void stlib_init_mutl_icon(st_multicon_t *i, int x, int y, patch_t **il, - int *inum, boolean *on) -{ - i->x = x; - i->y = y; - i->oldinum = -1; - i->inum = inum; - i->on = on; - i->p = il; -} - -void stlib_update_mult_icon(st_multicon_t *mi, boolean refresh) -{ - int w; - int h; - int x; - int y; - - if (*mi->on && (mi->oldinum != *mi->inum || refresh) && (*mi->inum != -1)) - { - if (mi->oldinum != -1) - { - x = mi->x - SHORT(mi->p[mi->oldinum]->leftoffset); - y = mi->y - SHORT(mi->p[mi->oldinum]->topoffset); - w = SHORT(mi->p[mi->oldinum]->width); - h = SHORT(mi->p[mi->oldinum]->height); - - if (y - ST_Y < 0) i_error("updateMultIcon: y - ST_Y < 0"); - - v_copy_rect(x, y - ST_Y, st_backing_screen, w, h, x, y); - } - - v_draw_patch(mi->x, mi->y, mi->p[*mi->inum]); - mi->oldinum = *mi->inum; - } -} - -void stlib_init_bin_icon(st_binicon_t *b, int x, int y, patch_t *i, - boolean *val, boolean *on) -{ - b->x = x; - b->y = y; - b->oldval = false; - b->val = val; - b->on = on; - b->p = i; -} - -void stlib_update_bin_icon(st_binicon_t *bi, boolean refresh) -{ - int x; - int y; - int w; - int h; - - if (*bi->on && (bi->oldval != *bi->val || refresh)) - { - x = bi->x - SHORT(bi->p->leftoffset); - y = bi->y - SHORT(bi->p->topoffset); - w = SHORT(bi->p->width); - h = SHORT(bi->p->height); - - if (y - ST_Y < 0) i_error("updateBinIcon: y - ST_Y < 0"); - - if (*bi->val) - v_draw_patch(bi->x, bi->y, bi->p); - else - v_copy_rect(x, y - ST_Y, st_backing_screen, w, h, x, y); - - bi->oldval = *bi->val; - } -} diff --git a/games/NXDoom/src/doom/st_lib.h b/games/NXDoom/src/doom/st_lib.h deleted file mode 100644 index b1fa3867b..000000000 --- a/games/NXDoom/src/doom/st_lib.h +++ /dev/null @@ -1,187 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/st_lib.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * The status bar widget code. - * - ****************************************************************************/ - -#ifndef __STLIB__ -#define __STLIB__ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -/* We are referring to patches. */ - -#include "r_defs.h" - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -/* Typedefs of widgets */ - -/* Number widget */ - -typedef struct -{ - /* upper right-hand corner of the number (right-justified) - */ - - int x; - int y; - - /* max # of digits in number */ - - int width; - - /* last number value */ - - int oldnum; - - /* pointer to current value */ - - int *num; - - /* pointer to boolean stating whether to update number */ - - boolean *on; - - /* list of patches for 0-9 */ - - patch_t **p; - - /* user data */ - - int data; -} st_number_t; - -/* Percent widget ("child" of number widget, or, more precisely, contains a - * number widget.) - */ - -typedef struct -{ - /* number information */ - - st_number_t n; - - /* percent sign graphic */ - - patch_t *p; -} st_percent_t; - -/* Multiple Icon widget */ - -typedef struct -{ - /* center-justified location of icons */ - - int x; - int y; - - /* last icon number */ - - int oldinum; - - /* pointer to current icon */ - - int *inum; - - /* pointer to boolean stating whether to update icon */ - - boolean *on; - - /* list of icons */ - - patch_t **p; - - /* user data */ - - int data; -} st_multicon_t; - -/* Binary Icon widget */ - -typedef struct -{ - /* center-justified location of icon */ - - int x; - int y; - - /* last icon value */ - - boolean oldval; - - /* pointer to current icon status */ - - boolean *val; - - /* pointer to boolean stating whether to update icon */ - - boolean *on; - - patch_t *p; /* icon */ - int data; /* user data */ -} st_binicon_t; - -/* Widget creation, access, and update routines */ - -/* Initializes widget library. - * More precisely, initialize STMINUS, - * everything else is done somewhere else. - */ - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -void stlib_init(void); - -/* Number widget routines */ - -void stlib_init_num(st_number_t *n, int x, int y, patch_t **pl, int *num, - boolean *on, int width); - -void stlib_update_num(st_number_t *n, boolean refresh); - -/* Percent widget routines */ - -void stlib_init_percent(st_percent_t *p, int x, int y, patch_t **pl, - int *num, boolean *on, patch_t *percent); - -void stlib_update_percent(st_percent_t *per, int refresh); - -/* Multiple Icon widget routines */ - -void stlib_init_mutl_icon(st_multicon_t *mi, int x, int y, patch_t **il, - int *inum, boolean *on); - -void stlib_update_mult_icon(st_multicon_t *mi, boolean refresh); - -/* Binary Icon widget routines */ - -void stlib_init_bin_icon(st_binicon_t *b, int x, int y, patch_t *i, - boolean *val, boolean *on); - -void stlib_update_bin_icon(st_binicon_t *bi, boolean refresh); - -#endif /* __STLIB__ */ diff --git a/games/NXDoom/src/doom/st_stuff.c b/games/NXDoom/src/doom/st_stuff.c deleted file mode 100644 index c6e55ee67..000000000 --- a/games/NXDoom/src/doom/st_stuff.c +++ /dev/null @@ -1,1418 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/st_stuff.c - * - * SPDX-License-Identifier: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Status bar code. - * Does the face/direction indicator animating. - * Does palette indicators as well (red pain/berserk, bright pickup) - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -#include "i_system.h" -#include "i_video.h" -#include "m_misc.h" -#include "m_random.h" -#include "w_wad.h" -#include "z_zone.h" - -#include "deh_main.h" -#include "deh_misc.h" -#include "doomdef.h" -#include "doomkeys.h" - -#include "g_game.h" - -#include "r_local.h" -#include "st_lib.h" -#include "st_stuff.h" - -#include "p_inter.h" -#include "p_local.h" - -#include "am_map.h" -#include "m_cheat.h" - -#ifdef CONFIG_GAMES_NXDOOM_SOUND -#include "s_sound.h" -#include "sounds.h" -#endif - -/* Needs access to LFB. */ - -#include "v_video.h" - -/* State. */ - -#include "doomstat.h" - -/* Data. */ - -#include "dstrings.h" - -/* STATUS BAR DATA */ - -/* Palette indices. - * For damage/bonus red-/gold-shifts - */ - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define STARTREDPALS 1 -#define STARTBONUSPALS 9 -#define NUMREDPALS 8 -#define NUMBONUSPALS 4 - -/* Radiation suit, green shift. */ - -#define RADIATIONPAL 13 - -/* Location of status bar */ - -#define ST_X 0 -#define ST_X2 104 - -#define ST_FX 143 -#define ST_FY 169 - -/* Number of status faces. */ - -#define ST_NUMPAINFACES 5 -#define ST_NUMSTRAIGHTFACES 3 -#define ST_NUMTURNFACES 2 -#define ST_NUMSPECIALFACES 3 - -#define ST_FACESTRIDE \ - (ST_NUMSTRAIGHTFACES + ST_NUMTURNFACES + ST_NUMSPECIALFACES) - -#define ST_NUMEXTRAFACES 2 - -#define ST_NUMFACES (ST_FACESTRIDE * ST_NUMPAINFACES + ST_NUMEXTRAFACES) - -#define ST_TURNOFFSET (ST_NUMSTRAIGHTFACES) -#define ST_OUCHOFFSET (ST_TURNOFFSET + ST_NUMTURNFACES) -#define ST_EVILGRINOFFSET (ST_OUCHOFFSET + 1) -#define ST_RAMPAGEOFFSET (ST_EVILGRINOFFSET + 1) -#define ST_GODFACE (ST_NUMPAINFACES * ST_FACESTRIDE) -#define ST_DEADFACE (ST_GODFACE + 1) - -#define ST_FACESX 143 -#define ST_FACESY 168 - -#define ST_EVILGRINCOUNT (2 * TICRATE) -#define ST_STRAIGHTFACECOUNT (TICRATE / 2) -#define ST_TURNCOUNT (1 * TICRATE) -#define ST_OUCHCOUNT (1 * TICRATE) -#define ST_RAMPAGEDELAY (2 * TICRATE) - -#define ST_MUCHPAIN 20 - -/* Location and size of statistics, - * justified according to widget type. - * Problem is, within which space? STbar? Screen? - * Note: this could be read in by a lump. - * Problem is, is the stuff rendered - * into a buffer, - * or into the frame buffer? - */ - -/* AMMO number pos. */ - -#define ST_AMMOWIDTH 3 -#define ST_AMMOX 44 -#define ST_AMMOY 171 - -/* HEALTH number pos. */ - -#define ST_HEALTHWIDTH 3 -#define ST_HEALTHX 90 -#define ST_HEALTHY 171 - -/* Weapon pos. */ - -#define ST_ARMSX 111 -#define ST_ARMSY 172 -#define ST_ARMSBGX 104 -#define ST_ARMSBGY 168 -#define ST_ARMSXSPACE 12 -#define ST_ARMSYSPACE 10 - -/* Frags pos. */ - -#define ST_FRAGSX 138 -#define ST_FRAGSY 171 -#define ST_FRAGSWIDTH 2 - -/* ARMOR number pos. */ - -#define ST_ARMORWIDTH 3 -#define ST_ARMORX 221 -#define ST_ARMORY 171 - -/* Key icon positions. */ - -#define ST_KEY0WIDTH 8 -#define ST_KEY0HEIGHT 5 -#define ST_KEY0X 239 -#define ST_KEY0Y 171 -#define ST_KEY1WIDTH ST_KEY0WIDTH -#define ST_KEY1X 239 -#define ST_KEY1Y 181 -#define ST_KEY2WIDTH ST_KEY0WIDTH -#define ST_KEY2X 239 -#define ST_KEY2Y 191 - -/* Ammunition counter. */ - -#define ST_AMMO0WIDTH 3 -#define ST_AMMO0HEIGHT 6 -#define ST_AMMO0X 288 -#define ST_AMMO0Y 173 -#define ST_AMMO1WIDTH ST_AMMO0WIDTH -#define ST_AMMO1X 288 -#define ST_AMMO1Y 179 -#define ST_AMMO2WIDTH ST_AMMO0WIDTH -#define ST_AMMO2X 288 -#define ST_AMMO2Y 191 -#define ST_AMMO3WIDTH ST_AMMO0WIDTH -#define ST_AMMO3X 288 -#define ST_AMMO3Y 185 - -/* Indicate maximum ammunition. - * Only needed because backpack exists. - */ - -#define ST_MAXAMMO0WIDTH 3 -#define ST_MAXAMMO0HEIGHT 5 -#define ST_MAXAMMO0X 314 -#define ST_MAXAMMO0Y 173 -#define ST_MAXAMMO1WIDTH ST_MAXAMMO0WIDTH -#define ST_MAXAMMO1X 314 -#define ST_MAXAMMO1Y 179 -#define ST_MAXAMMO2WIDTH ST_MAXAMMO0WIDTH -#define ST_MAXAMMO2X 314 -#define ST_MAXAMMO2Y 191 -#define ST_MAXAMMO3WIDTH ST_MAXAMMO0WIDTH -#define ST_MAXAMMO3X 314 -#define ST_MAXAMMO3Y 185 - -/* Dimensions given in characters. */ - -#define ST_MSGWIDTH 52 - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -typedef void (*load_callback_t)(const char *lumpname, patch_t **variable); - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/* main player in game */ - -static player_t *plyr; - -/* st_start() has just been called */ - -static boolean st_firsttime; - -/* lump number for PLAYPAL */ - -static int lu_palette; - -/* used for making messages go away */ - -static int st_msgcounter = 0; - -/* whether left-side main status bar is active */ - -static boolean st_statusbaron; - -/* whether status bar chat is active */ - -static boolean st_chat; - -/* value of st_chat before message popped up */ - -static boolean st_oldchat; - -/* !deathmatch */ - -static boolean st_notdeathmatch; - -/* !deathmatch && st_statusbaron */ - -static boolean st_armson; - -/* !deathmatch */ - -static boolean st_fragson; - -/* main bar left */ - -static patch_t *sbar; - -/* main bar right, for doom 1.0 */ - -static patch_t *sbarr; - -/* 0-9, tall numbers */ - -static patch_t *tallnum[10]; - -/* tall % sign */ - -static patch_t *tallpercent; - -/* 0-9, short, yellow (,different!) numbers */ - -static patch_t *shortnum[10]; - -/* 3 key-cards, 3 skulls */ - -static patch_t *keys[NUMCARDS]; - -/* face status patches */ - -static patch_t *faces[ST_NUMFACES]; - -/* face background */ - -static patch_t *faceback; - -/* main bar right */ - -static patch_t *armsbg; - -/* weapon ownership patches */ - -static patch_t *arms[6][2]; - -/* ready-weapon widget */ - -static st_number_t w_ready; - -/* in deathmatch only, summary of frags stats */ - -static st_number_t w_frags; - -/* health widget */ - -static st_percent_t w_health; - -/* arms background */ - -static st_binicon_t w_armsbg; - -/* weapon ownership widgets */ - -static st_multicon_t w_arms[6]; - -/* face status widget */ - -static st_multicon_t w_faces; - -/* keycard widgets */ - -static st_multicon_t w_keyboxes[3]; - -/* armor widget */ - -static st_percent_t w_armor; - -/* ammo widgets */ - -static st_number_t w_ammo[4]; - -/* max ammo widgets */ - -static st_number_t w_maxammo[4]; - -/* number of frags so far in deathmatch */ - -static int st_fragscount; - -/* used to use appropriately pained face */ - -static int st_oldhealth = -1; - -/* used for evil grin */ - -static boolean oldweaponsowned[NUMWEAPONS]; - -/* count until face changes */ - -static int st_facecount = 0; - -/* current face index, used by w_faces */ - -static int st_faceindex = 0; - -/* holds key-type for each key box on bar */ - -static int keyboxes[3]; - -/* a random number per tick */ - -static int st_randomnumber; - -static int st_palette = 0; - -static boolean st_stopped = true; - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/* graphics are drawn to a backing screen and blitted to the real screen */ - -pixel_t *st_backing_screen; - -cheatseq_t cheat_mus = CHEAT("idmus", 2); -cheatseq_t cheat_god = CHEAT("iddqd", 0); -cheatseq_t cheat_ammo = CHEAT("idkfa", 0); -cheatseq_t cheat_ammonokey = CHEAT("idfa", 0); -cheatseq_t cheat_noclip = CHEAT("idspispopd", 0); -cheatseq_t cheat_commercial_noclip = CHEAT("idclip", 0); - -cheatseq_t cheat_powerup[7] = -{ - CHEAT("idbeholdv", 0), CHEAT("idbeholds", 0), CHEAT("idbeholdi", 0), - CHEAT("idbeholdr", 0), CHEAT("idbeholda", 0), CHEAT("idbeholdl", 0), - CHEAT("idbehold", 0), -}; - -cheatseq_t cheat_choppers = CHEAT("idchoppers", 0); -cheatseq_t cheat_clev = CHEAT("idclev", 2); -cheatseq_t cheat_mypos = CHEAT("idmypos", 0); - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static void st_stop(void) -{ - if (st_stopped) return; - - i_set_palette(w_cache_lump_num(lu_palette, PU_CACHE)); - st_stopped = true; -} - -static void st_refresh_background(void) -{ - if (st_statusbaron) - { - v_use_buffer(st_backing_screen); - - v_draw_patch(ST_X, 0, sbar); - - /* draw right side of bar if needed (Doom 1.0) */ - - if (sbarr) v_draw_patch(ST_ARMSBGX, 0, sbarr); - - if (netgame) v_draw_patch(ST_FX, 0, faceback); - - v_restore_buffer(); - - v_copy_rect(ST_X, 0, st_backing_screen, ST_WIDTH, ST_HEIGHT, ST_X, - ST_Y); - } -} - -static int st_calc_paint_offset(void) -{ - int health; - static int lastcalc; - static int oldhealth = -1; - - health = plyr->health > 100 ? 100 : plyr->health; - - if (health != oldhealth) - { - lastcalc = ST_FACESTRIDE * (((100 - health) * ST_NUMPAINFACES) / 101); - oldhealth = health; - } - - return lastcalc; -} - -/* This is a not-very-pretty routine which handles the face states and their - * timing. the precedence of expressions is: dead > evil grin > turned head > - * straight ahead - */ - -static void st_update_face_widget(void) -{ - int i; - angle_t badguyangle; - angle_t diffang; - static int lastattackdown = -1; - static int priority = 0; - boolean doevilgrin; - - if (priority < 10) - { - /* dead */ - - if (!plyr->health) - { - priority = 9; - st_faceindex = ST_DEADFACE; - st_facecount = 1; - } - } - - if (priority < 9) - { - if (plyr->bonuscount) - { - /* picking up bonus */ - - doevilgrin = false; - - for (i = 0; i < NUMWEAPONS; i++) - { - if (oldweaponsowned[i] != plyr->weaponowned[i]) - { - doevilgrin = true; - oldweaponsowned[i] = plyr->weaponowned[i]; - } - } - - if (doevilgrin) - { - /* evil grin if just picked up weapon */ - - priority = 8; - st_facecount = ST_EVILGRINCOUNT; - st_faceindex = st_calc_paint_offset() + ST_EVILGRINOFFSET; - } - } - } - - if (priority < 8) - { - if (plyr->damagecount && plyr->attacker && plyr->attacker != plyr->mo) - { - /* being attacked */ - - priority = 7; - - if (plyr->health - st_oldhealth > ST_MUCHPAIN) - { - st_facecount = ST_TURNCOUNT; - st_faceindex = st_calc_paint_offset() + ST_OUCHOFFSET; - } - else - { - badguyangle = - r_point_to_angle2(plyr->mo->x, plyr->mo->y, - plyr->attacker->x, plyr->attacker->y); - - if (badguyangle > plyr->mo->angle) - { - /* whether right or left */ - - diffang = badguyangle - plyr->mo->angle; - i = diffang > ANG180; - } - else - { - /* whether left or right */ - - diffang = plyr->mo->angle - badguyangle; - i = diffang <= ANG180; - } - - /* confusing, aint it? */ - - st_facecount = ST_TURNCOUNT; - st_faceindex = st_calc_paint_offset(); - - if (diffang < ANG45) - { - /* head-on */ - - st_faceindex += ST_RAMPAGEOFFSET; - } - else if (i) - { - /* turn face right */ - - st_faceindex += ST_TURNOFFSET; - } - else - { - /* turn face left */ - - st_faceindex += ST_TURNOFFSET + 1; - } - } - } - } - - if (priority < 7) - { - /* getting hurt because of your own damn stupidity */ - - if (plyr->damagecount) - { - if (plyr->health - st_oldhealth > ST_MUCHPAIN) - { - priority = 7; - st_facecount = ST_TURNCOUNT; - st_faceindex = st_calc_paint_offset() + ST_OUCHOFFSET; - } - else - { - priority = 6; - st_facecount = ST_TURNCOUNT; - st_faceindex = st_calc_paint_offset() + ST_RAMPAGEOFFSET; - } - } - } - - if (priority < 6) - { - /* rapid firing */ - - if (plyr->attackdown) - { - if (lastattackdown == -1) - lastattackdown = ST_RAMPAGEDELAY; - else if (!--lastattackdown) - { - priority = 5; - st_faceindex = st_calc_paint_offset() + ST_RAMPAGEOFFSET; - st_facecount = 1; - lastattackdown = 1; - } - } - else - lastattackdown = -1; - } - - if (priority < 5) - { - /* invulnerability */ - - if ((plyr->cheats & CF_GODMODE) || plyr->powers[pw_invulnerability]) - { - priority = 4; - - st_faceindex = ST_GODFACE; - st_facecount = 1; - } - } - - /* look left or look right if the facecount has timed out */ - - if (!st_facecount) - { - st_faceindex = st_calc_paint_offset() + (st_randomnumber % 3); - st_facecount = ST_STRAIGHTFACECOUNT; - priority = 0; - } - - st_facecount--; -} - -static void st_update_widgets(void) -{ - static int largeammo = 1994; /* means "n/a" */ - int i; - - /* must redirect the pointer if the ready weapon has changed. - * if (w_ready.data != plyr->readyweapon) - * { - */ - - if (weaponinfo[plyr->readyweapon].ammo == am_noammo) - w_ready.num = &largeammo; - else - w_ready.num = &plyr->ammo[weaponinfo[plyr->readyweapon].ammo]; - - /* { - * static int tic=0; - * static int dir=-1; - * if (!(tic&15)) - * plyr->ammo[weaponinfo[plyr->readyweapon].ammo]+=dir; - * if (plyr->ammo[weaponinfo[plyr->readyweapon].ammo] == -100) - * dir = 1; - * tic++; - * } - */ - - w_ready.data = plyr->readyweapon; - - /* if (*w_ready.on) - * stlib_update_num(&w_ready, true); - * refresh weapon change - * } - */ - - /* update keycard multiple widgets */ - - for (i = 0; i < 3; i++) - { - keyboxes[i] = plyr->cards[i] ? i : -1; - - if (plyr->cards[i + 3]) keyboxes[i] = i + 3; - } - - /* refresh everything if this is him coming back to life */ - - st_update_face_widget(); - - /* used by the w_armsbg widget */ - - st_notdeathmatch = !deathmatch; - - /* used by w_arms[] widgets */ - - st_armson = st_statusbaron && !deathmatch; - - /* used by w_frags widget */ - - st_fragson = deathmatch && st_statusbaron; - st_fragscount = 0; - - for (i = 0; i < MAXPLAYERS; i++) - { - if (i != consoleplayer) - st_fragscount += plyr->frags[i]; - else - st_fragscount -= plyr->frags[i]; - } - - /* get rid of chat window if up because of message */ - - if (!--st_msgcounter) st_chat = st_oldchat; -} - -static void st_do_palette_stuff(void) -{ - int palette; - byte *pal; - int cnt; - int bzc; - - cnt = plyr->damagecount; - - if (plyr->powers[pw_strength]) - { - /* slowly fade the berzerk out */ - - bzc = 12 - (plyr->powers[pw_strength] >> 6); - - if (bzc > cnt) cnt = bzc; - } - - if (cnt) - { - palette = (cnt + 7) >> 3; - - if (palette >= NUMREDPALS) palette = NUMREDPALS - 1; - - palette += STARTREDPALS; - } - - else if (plyr->bonuscount) - { - palette = (plyr->bonuscount + 7) >> 3; - - if (palette >= NUMBONUSPALS) palette = NUMBONUSPALS - 1; - - palette += STARTBONUSPALS; - } - - else if (plyr->powers[pw_ironfeet] > 4 * 32 || - plyr->powers[pw_ironfeet] & 8) - palette = RADIATIONPAL; - else - palette = 0; - - /* In Chex Quest, the player never sees red. Instead, the - * radiation suit palette is used to tint the screen green, - * as though the player is being covered in goo by an - * attacking flemoid. - */ - - if (gameversion == exe_chex && palette >= STARTREDPALS && - palette < STARTREDPALS + NUMREDPALS) - { - palette = RADIATIONPAL; - } - - if (palette != st_palette) - { - st_palette = palette; - pal = (byte *)w_cache_lump_num(lu_palette, PU_CACHE) + palette * 768; - i_set_palette(pal); - } -} - -static void st_draw_widgets(boolean refresh) -{ - int i; - - /* used by w_arms[] widgets */ - - st_armson = st_statusbaron && !deathmatch; - - /* used by w_frags widget */ - - st_fragson = deathmatch && st_statusbaron; - - stlib_update_num(&w_ready, refresh); - - for (i = 0; i < 4; i++) - { - stlib_update_num(&w_ammo[i], refresh); - stlib_update_num(&w_maxammo[i], refresh); - } - - stlib_update_percent(&w_health, refresh); - stlib_update_percent(&w_armor, refresh); - - stlib_update_bin_icon(&w_armsbg, refresh); - - for (i = 0; i < 6; i++) - stlib_update_mult_icon(&w_arms[i], refresh); - - stlib_update_mult_icon(&w_faces, refresh); - - for (i = 0; i < 3; i++) - stlib_update_mult_icon(&w_keyboxes[i], refresh); - - stlib_update_num(&w_frags, refresh); -} - -static void st_do_refresh(void) -{ - st_firsttime = false; - - /* draw status bar background to off-screen buff */ - - st_refresh_background(); - - /* and refresh all widgets */ - - st_draw_widgets(true); -} - -static void st_diff_draw(void) -{ - /* update all widgets */ - - st_draw_widgets(false); -} - -/* Iterates through all graphics to be loaded or unloaded, along with - * the variable they use, invoking the specified callback function. - */ - -static void st_load_unload_graphics(load_callback_t callback) -{ - int i; - int j; - int facenum; - - char namebuf[9]; - - /* Load the numbers, tall and short */ - - for (i = 0; i < 10; i++) - { - snprintf(namebuf, 9, "STTNUM%d", i); - callback(namebuf, &tallnum[i]); - - snprintf(namebuf, 9, "STYSNUM%d", i); - callback(namebuf, &shortnum[i]); - } - - /* Load percent key. - * Note: why not load STMINUS here, too? - */ - - callback(("STTPRCNT"), &tallpercent); - - /* key cards */ - - for (i = 0; i < NUMCARDS; i++) - { - snprintf(namebuf, 9, "STKEYS%d", i); - callback(namebuf, &keys[i]); - } - - /* arms background */ - - callback(("STARMS"), &armsbg); - - /* arms ownership widgets */ - - for (i = 0; i < 6; i++) - { - snprintf(namebuf, 9, "STGNUM%d", i + 2); - - /* gray # */ - - callback(namebuf, &arms[i][0]); - - /* yellow # */ - - arms[i][1] = shortnum[i + 2]; - } - - /* face backgrounds for different color players */ - - snprintf(namebuf, 9, "STFB%d", consoleplayer); - callback(namebuf, &faceback); - - /* status bar background bits */ - - if (w_check_num_for_name("STBAR") >= 0) - { - callback(("STBAR"), &sbar); - sbarr = NULL; - } - else - { - callback(("STMBARL"), &sbar); - callback(("STMBARR"), &sbarr); - } - - /* face states */ - - facenum = 0; - for (i = 0; i < ST_NUMPAINFACES; i++) - { - for (j = 0; j < ST_NUMSTRAIGHTFACES; j++) - { - snprintf(namebuf, 9, "STFST%d%d", i, j); - callback(namebuf, &faces[facenum]); - ++facenum; - } - - snprintf(namebuf, 9, "STFTR%d0", i); /* turn right */ - callback(namebuf, &faces[facenum]); - ++facenum; - snprintf(namebuf, 9, "STFTL%d0", i); /* turn left */ - callback(namebuf, &faces[facenum]); - ++facenum; - snprintf(namebuf, 9, "STFOUCH%d", i); /* ouch! */ - callback(namebuf, &faces[facenum]); - ++facenum; - snprintf(namebuf, 9, "STFEVL%d", i); /* evil grin ;) */ - callback(namebuf, &faces[facenum]); - ++facenum; - snprintf(namebuf, 9, "STFKILL%d", i); /* pissed off */ - callback(namebuf, &faces[facenum]); - ++facenum; - } - - callback(("STFGOD0"), &faces[facenum]); - ++facenum; - callback(("STFDEAD0"), &faces[facenum]); - ++facenum; -} - -static void st_load_callback(const char *lumpname, patch_t **variable) -{ - *variable = w_cache_lump_name(lumpname, PU_STATIC); -} - -static void st_load_graphics(void) -{ - st_load_unload_graphics(st_load_callback); -} - -static void st_load_data(void) -{ - lu_palette = w_get_num_for_name(("PLAYPAL")); - st_load_graphics(); -} - -#if 0 /* UNUSED */ -static void st_unload_callback(const char *lumpname, patch_t **variable) -{ - w_release_lump_name(lumpname); - *variable = NULL; -} - -static void st_unload_graphics(void) -{ - st_load_unload_graphics(st_unload_callback); -} -#endif - -static void st_init_data(void) -{ - int i; - - st_firsttime = true; - plyr = &players[consoleplayer]; - - st_statusbaron = true; - st_oldchat = st_chat = false; - - st_faceindex = 0; - st_palette = -1; - - st_oldhealth = -1; - - for (i = 0; i < NUMWEAPONS; i++) - oldweaponsowned[i] = plyr->weaponowned[i]; - - for (i = 0; i < 3; i++) - keyboxes[i] = -1; - - stlib_init(); -} - -static void st_create_widgets(void) -{ - int i; - - /* ready weapon ammo */ - - stlib_init_num(&w_ready, ST_AMMOX, ST_AMMOY, tallnum, - &plyr->ammo[weaponinfo[plyr->readyweapon].ammo], - &st_statusbaron, ST_AMMOWIDTH); - - /* the last weapon type */ - - w_ready.data = plyr->readyweapon; - - /* health percentage */ - - stlib_init_percent(&w_health, ST_HEALTHX, ST_HEALTHY, tallnum, - &plyr->health, &st_statusbaron, tallpercent); - - /* arms background */ - - stlib_init_bin_icon(&w_armsbg, ST_ARMSBGX, ST_ARMSBGY, armsbg, - &st_notdeathmatch, &st_statusbaron); - - /* weapons owned */ - - for (i = 0; i < 6; i++) - { - stlib_init_mutl_icon(&w_arms[i], ST_ARMSX + (i % 3) * ST_ARMSXSPACE, - ST_ARMSY + (i / 3) * ST_ARMSYSPACE, arms[i], - &plyr->weaponowned[i + 1], &st_armson); - } - - /* frags sum */ - - stlib_init_num(&w_frags, ST_FRAGSX, ST_FRAGSY, tallnum, &st_fragscount, - &st_fragson, ST_FRAGSWIDTH); - - /* faces */ - - stlib_init_mutl_icon(&w_faces, ST_FACESX, ST_FACESY, faces, &st_faceindex, - &st_statusbaron); - - /* armor percentage - should be colored later */ - - stlib_init_percent(&w_armor, ST_ARMORX, ST_ARMORY, tallnum, - &plyr->armorpoints, &st_statusbaron, tallpercent); - - /* keyboxes 0-2 */ - - stlib_init_mutl_icon(&w_keyboxes[0], ST_KEY0X, ST_KEY0Y, keys, - &keyboxes[0], &st_statusbaron); - - stlib_init_mutl_icon(&w_keyboxes[1], ST_KEY1X, ST_KEY1Y, keys, - &keyboxes[1], &st_statusbaron); - - stlib_init_mutl_icon(&w_keyboxes[2], ST_KEY2X, ST_KEY2Y, keys, - &keyboxes[2], &st_statusbaron); - - /* ammo count (all four kinds) */ - - stlib_init_num(&w_ammo[0], ST_AMMO0X, ST_AMMO0Y, shortnum, &plyr->ammo[0], - &st_statusbaron, ST_AMMO0WIDTH); - - stlib_init_num(&w_ammo[1], ST_AMMO1X, ST_AMMO1Y, shortnum, &plyr->ammo[1], - &st_statusbaron, ST_AMMO1WIDTH); - - stlib_init_num(&w_ammo[2], ST_AMMO2X, ST_AMMO2Y, shortnum, &plyr->ammo[2], - &st_statusbaron, ST_AMMO2WIDTH); - - stlib_init_num(&w_ammo[3], ST_AMMO3X, ST_AMMO3Y, shortnum, &plyr->ammo[3], - &st_statusbaron, ST_AMMO3WIDTH); - - /* max ammo count (all four kinds) */ - - stlib_init_num(&w_maxammo[0], ST_MAXAMMO0X, ST_MAXAMMO0Y, shortnum, - &plyr->maxammo[0], &st_statusbaron, ST_MAXAMMO0WIDTH); - - stlib_init_num(&w_maxammo[1], ST_MAXAMMO1X, ST_MAXAMMO1Y, shortnum, - &plyr->maxammo[1], &st_statusbaron, ST_MAXAMMO1WIDTH); - - stlib_init_num(&w_maxammo[2], ST_MAXAMMO2X, ST_MAXAMMO2Y, shortnum, - &plyr->maxammo[2], &st_statusbaron, ST_MAXAMMO2WIDTH); - - stlib_init_num(&w_maxammo[3], ST_MAXAMMO3X, ST_MAXAMMO3Y, shortnum, - &plyr->maxammo[3], &st_statusbaron, ST_MAXAMMO3WIDTH); -} - -/**************************************************************************** - * Public Function - ****************************************************************************/ - -/* Respond to keyboard input events, intercept cheats. */ - -boolean st_responder(event_t *ev) -{ - int i; - - /* Filter automap on/off. */ - - if (ev->type == ev_keyup && ((ev->data1 & 0xffff0000) == AM_MSGHEADER)) - { - switch (ev->data1) - { - case AM_MSGENTERED: - st_firsttime = true; - break; - - case AM_MSGEXITED: - break; - } - } - - /* if a user keypress... */ - - else if (ev->type == ev_keydown) - { - if (!netgame && gameskill != sk_nightmare) - { - /* 'dqd' cheat for toggleable god mode */ - - if (cht_check_cheat(&cheat_god, ev->data2)) - { - plyr->cheats ^= CF_GODMODE; - if (plyr->cheats & CF_GODMODE) - { - if (plyr->mo) plyr->mo->health = deh_god_mode_health; - - plyr->health = deh_god_mode_health; - plyr->message = (STSTR_DQDON); - } - else - plyr->message = (STSTR_DQDOFF); - } - - /* 'fa' cheat for killer fucking arsenal */ - - else if (cht_check_cheat(&cheat_ammonokey, ev->data2)) - { - plyr->armorpoints = deh_idfa_armor; - plyr->armortype = deh_idfa_armor_class; - - for (i = 0; i < NUMWEAPONS; i++) - plyr->weaponowned[i] = true; - - for (i = 0; i < NUMAMMO; i++) - plyr->ammo[i] = plyr->maxammo[i]; - - plyr->message = (STSTR_FAADDED); - } - - /* 'kfa' cheat for key full ammo */ - - else if (cht_check_cheat(&cheat_ammo, ev->data2)) - { - plyr->armorpoints = deh_idkfa_armor; - plyr->armortype = deh_idkfa_armor_class; - - for (i = 0; i < NUMWEAPONS; i++) - plyr->weaponowned[i] = true; - - for (i = 0; i < NUMAMMO; i++) - plyr->ammo[i] = plyr->maxammo[i]; - - for (i = 0; i < NUMCARDS; i++) - plyr->cards[i] = true; - - plyr->message = (STSTR_KFAADDED); - } - - /* 'mus' cheat for changing music */ - - else if (cht_check_cheat(&cheat_mus, ev->data2)) - { - char buf[3]; -#ifdef CONFIG_GAMES_NXDOOM_SOUND - int musnum; -#endif - - plyr->message = (STSTR_MUS); - ch_get_param(&cheat_mus, buf); - - /* Note: The original v1.9 had a bug that tried to play back - * the Doom II music regardless of gamemode. This was fixed - * in the Ultimate Doom executable so that it would work for - * the Doom 1 music as well. - */ - - if (gamemode == commercial || gameversion < exe_ultimate) - { -#ifdef CONFIG_GAMES_NXDOOM_SOUND - musnum = - MUS_RUNNIN + (buf[0] - '0') * 10 + buf[1] - '0' - 1; -#endif - - if (((buf[0] - '0') * 10 + buf[1] - '0') > 35 && - gameversion >= exe_doom_1_8) - plyr->message = (STSTR_NOMUS); - else - { -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_change_music(musnum, 1); -#endif - } - } - else - { -#ifdef CONFIG_GAMES_NXDOOM_SOUND - musnum = MUS_E1M1 + (buf[0] - '1') * 9 + (buf[1] - '1'); -#endif - - if (((buf[0] - '1') * 9 + buf[1] - '1') > 31) - plyr->message = (STSTR_NOMUS); - else - { -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_change_music(musnum, 1); -#endif - } - } - } - else if ((logical_gamemission == doom && - cht_check_cheat(&cheat_noclip, ev->data2)) || - (logical_gamemission != doom && - cht_check_cheat(&cheat_commercial_noclip, ev->data2))) - { - /* Noclip cheat. - * For Doom 1, use the idspipsopd cheat; for all others, use - * idclip - */ - - plyr->cheats ^= CF_NOCLIP; - - if (plyr->cheats & CF_NOCLIP) - plyr->message = (STSTR_NCON); - else - plyr->message = (STSTR_NCOFF); - } - - /* 'behold?' power-up cheats */ - - for (i = 0; i < 6; i++) - { - if (cht_check_cheat(&cheat_powerup[i], ev->data2)) - { - if (!plyr->powers[i]) - p_give_power(plyr, i); - else if (i != pw_strength) - plyr->powers[i] = 1; - else - plyr->powers[i] = 0; - - plyr->message = (STSTR_BEHOLDX); - } - } - - /* 'behold' power-up menu */ - - if (cht_check_cheat(&cheat_powerup[6], ev->data2)) - { - plyr->message = (STSTR_BEHOLD); - } - - /* 'choppers' invulnerability & chainsaw */ - - else if (cht_check_cheat(&cheat_choppers, ev->data2)) - { - plyr->weaponowned[wp_chainsaw] = true; - plyr->powers[pw_invulnerability] = true; - plyr->message = (STSTR_CHOPPERS); - } - - /* 'mypos' for player position */ - - else if (cht_check_cheat(&cheat_mypos, ev->data2)) - { - static char buf[ST_MSGWIDTH]; - snprintf(buf, sizeof(buf), "ang=0x%x;x,y=(0x%x,0x%x)", - players[consoleplayer].mo->angle, - players[consoleplayer].mo->x, - players[consoleplayer].mo->y); - plyr->message = buf; - } - } - - /* 'clev' change-level cheat */ - - if (!netgame && cht_check_cheat(&cheat_clev, ev->data2)) - { - char buf[3]; - int epsd; - int map; - - ch_get_param(&cheat_clev, buf); - - if (gamemode == commercial) - { - epsd = 0; - map = (buf[0] - '0') * 10 + buf[1] - '0'; - } - else - { - epsd = buf[0] - '0'; - map = buf[1] - '0'; - - /* Chex.exe always warps to episode 1. */ - - if (gameversion == exe_chex) - { - if (epsd > 1) - { - epsd = 1; - } - - if (map > 5) - { - map = 5; - } - } - } - - /* Catch invalid maps. */ - - if (gamemode != commercial) - { - if (epsd < 1) - { - return false; - } - - if (epsd > 4) - { - return false; - } - - if (epsd == 4 && gameversion < exe_ultimate) - { - return false; - } - - if (map < 1) - { - return false; - } - - if (map > 9) - { - return false; - } - } - else - { - if (map < 1) - { - return false; - } - - if (map > 40) - { - return false; - } - } - - /* So be it. */ - - plyr->message = (STSTR_CLEV); - g_deferred_init_new(gameskill, epsd, map); - } - } - - return false; -} - -void st_ticker(void) -{ - st_randomnumber = m_random(); - st_update_widgets(); - st_oldhealth = plyr->health; -} - -void st_drawer(boolean p_fullscreen, boolean refresh) -{ - st_statusbaron = (!p_fullscreen) || automapactive; - st_firsttime = st_firsttime || refresh; - - /* Do red-/gold-shifts from damage/items */ - - st_do_palette_stuff(); - - /* If just after st_start(), refresh all */ - - if (st_firsttime) - { - st_do_refresh(); - } - else - { - /* Otherwise, update as little as possible */ - - st_diff_draw(); - } -} - -void st_start(void) -{ - if (!st_stopped) - { - st_stop(); - } - - st_init_data(); - st_create_widgets(); - st_stopped = false; -} - -void st_init(void) -{ - st_load_data(); - st_backing_screen = (pixel_t *)z_malloc( - ST_WIDTH * ST_HEIGHT * sizeof(*st_backing_screen), PU_STATIC, 0); -} diff --git a/games/NXDoom/src/doom/st_stuff.h b/games/NXDoom/src/doom/st_stuff.h deleted file mode 100644 index f68279e66..000000000 --- a/games/NXDoom/src/doom/st_stuff.h +++ /dev/null @@ -1,91 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/st_stuff.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Status bar code. - * Does the face/direction indicator animating. - * Does palette indicators as well (red pain/berserk, bright pickup) - * - ****************************************************************************/ - -#ifndef __STSTUFF_H__ -#define __STSTUFF_H__ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "d_event.h" -#include "doomtype.h" -#include "m_cheat.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* Size of statusbar. - * Now sensitive for scaling. - */ - -#define ST_HEIGHT 32 -#define ST_WIDTH SCREENWIDTH -#define ST_Y (SCREENHEIGHT - ST_HEIGHT) - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -extern pixel_t *st_backing_screen; -extern cheatseq_t cheat_mus; -extern cheatseq_t cheat_god; -extern cheatseq_t cheat_ammo; -extern cheatseq_t cheat_ammonokey; -extern cheatseq_t cheat_noclip; -extern cheatseq_t cheat_commercial_noclip; -extern cheatseq_t cheat_powerup[7]; -extern cheatseq_t cheat_choppers; -extern cheatseq_t cheat_clev; -extern cheatseq_t cheat_mypos; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/* STATUS BAR */ - -/* Called by main loop. */ - -boolean st_responder(event_t *ev); - -/* Called by main loop. */ - -void st_ticker(void); - -/* Called by main loop. */ - -void st_drawer(boolean fullscreen, boolean refresh); - -/* Called when the console player is spawned on each level. */ - -void st_start(void); - -/* Called by startup code. */ - -void st_init(void); - -#endif /* __STSTUFF_H__ */ diff --git a/games/NXDoom/src/doom/statdump.c b/games/NXDoom/src/doom/statdump.c deleted file mode 100644 index 1db5657ab..000000000 --- a/games/NXDoom/src/doom/statdump.c +++ /dev/null @@ -1,388 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/statdump.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * Functions for presenting the information captured from the statistics - * buffer to a file. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include - -#include "d_mode.h" -#include "d_player.h" -#include "m_argv.h" -#include "m_misc.h" - -#include "statdump.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define MAX_CAPTURES 32 - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/* Par times for E1M1-E1M9. */ - -static const int doom1_par_times[] = -{ - 30, 75, 120, 90, 165, 180, 180, 30, 165, -}; - -/* Par times for MAP01-MAP09. */ - -static const int doom2_par_times[] = -{ - 30, 90, 120, 120, 90, 150, 120, 120, 270, -}; - -/* Player colors. */ - -static const char *player_colors[] = -{ - "Green", - "Indigo", - "Brown", - "Red", -}; - -/* Array of end-of-level statistics that have been captured. */ - -static wbstartstruct_t captured_stats[MAX_CAPTURES]; -static int num_captured_stats = 0; - -static gamemission_t discovered_gamemission = none; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/* Try to work out whether this is a Doom 1 or Doom 2 game, by looking - * at the episode and map, and the par times. This is used to decide - * how to format the level name. Unfortunately, in some cases it is - * impossible to determine whether this is Doom 1 or Doom 2. - */ - -static void discover_game_mode(const wbstartstruct_t *stats, int num_stats) -{ - int partime; - int level; - int i; - - if (discovered_gamemission != none) - { - return; - } - - for (i = 0; i < num_stats; ++i) - { - level = stats[i].last; - - /* If episode 2, 3 or 4, this is Doom 1. */ - - if (stats[i].epsd > 0) - { - discovered_gamemission = doom; - return; - } - - /* This is episode 1. If this is level 10 or higher, it must be - * Doom 2. - */ - - if (level >= 9) - { - discovered_gamemission = doom2; - return; - } - - /* Try to work out if this is Doom 1 or Doom 2 by looking at the par - * time. - */ - - partime = stats[i].partime; - - if (partime == doom1_par_times[level] * TICRATE && - partime != doom2_par_times[level] * TICRATE) - { - discovered_gamemission = doom; - return; - } - - if (partime != doom1_par_times[level] * TICRATE && - partime == doom2_par_times[level] * TICRATE) - { - discovered_gamemission = doom2; - return; - } - } -} - -/* Returns the number of players active in the given stats buffer. */ - -static int get_num_players(const wbstartstruct_t *stats) -{ - int i; - int num_players = 0; - - for (i = 0; i < MAXPLAYERS; ++i) - { - if (stats->plyr[i].in) - { - ++num_players; - } - } - - return num_players; -} - -static void print_banner(FILE *stream) -{ - fprintf(stream, "===========================================\n"); -} - -static void print_percentage(FILE *stream, int amount, int total) -{ - if (total == 0) - { - fprintf(stream, "0"); - } - else - { - fprintf(stream, "%i / %i", amount, total); - - /* statdump.exe is a 16-bit program, so very occasionally an - * integer overflow can occur when doing this calculation with - * a large value. Therefore, cast to short to give the same - * output. - */ - - fprintf(stream, " (%i%%)", (short)(amount * 100) / total); - } -} - -/* Display statistics for a single player. */ - -static void print_player_stats(FILE *stream, const wbstartstruct_t *stats, - int player_num) -{ - const wbplayerstruct_t *player = &stats->plyr[player_num]; - - fprintf(stream, "Player %i (%s):\n", player_num + 1, - player_colors[player_num]); - - /* Kills percentage */ - - fprintf(stream, "\tKills: "); - print_percentage(stream, player->skills, stats->maxkills); - fprintf(stream, "\n"); - - /* Items percentage */ - - fprintf(stream, "\tItems: "); - print_percentage(stream, player->sitems, stats->maxitems); - fprintf(stream, "\n"); - - /* Secrets percentage */ - - fprintf(stream, "\tSecrets: "); - print_percentage(stream, player->ssecret, stats->maxsecret); - fprintf(stream, "\n"); -} - -/* Frags table for multiplayer games. */ - -static void print_frags_table(FILE *stream, const wbstartstruct_t *stats) -{ - int x; - int y; - - fprintf(stream, "Frags:\n"); - - /* Print header */ - - fprintf(stream, "\t\t"); - - for (x = 0; x < MAXPLAYERS; ++x) - { - if (!stats->plyr[x].in) - { - continue; - } - - fprintf(stream, "%s\t", player_colors[x]); - } - - fprintf(stream, "\n"); - - fprintf(stream, "\t\t-------------------------------- VICTIMS\n"); - - /* Print table */ - - for (y = 0; y < MAXPLAYERS; ++y) - { - if (!stats->plyr[y].in) - { - continue; - } - - fprintf(stream, "\t%s\t|", player_colors[y]); - - for (x = 0; x < MAXPLAYERS; ++x) - { - if (!stats->plyr[x].in) - { - continue; - } - - fprintf(stream, "%i\t", stats->plyr[y].frags[x]); - } - - fprintf(stream, "\n"); - } - - fprintf(stream, "\t\t|\n"); - fprintf(stream, "\t KILLERS\n"); -} - -/* Displays the level name: MAPxy or ExMy, depending on game mode. */ - -static void print_level_name(FILE *stream, int episode, int level) -{ - print_banner(stream); - - switch (discovered_gamemission) - { - case doom: - fprintf(stream, "E%iM%i\n", episode + 1, level + 1); - break; - case doom2: - fprintf(stream, "MAP%02i\n", level + 1); - break; - default: - case none: - fprintf(stream, "E%iM%i / MAP%02i\n", episode + 1, level + 1, - level + 1); - break; - } - - print_banner(stream); -} - -/* Print details of a statistics buffer to the given file. */ - -static void print_stats(FILE *stream, const wbstartstruct_t *stats) -{ - short leveltime; - short partime; - int i; - - print_level_name(stream, stats->epsd, stats->last); - fprintf(stream, "\n"); - - leveltime = stats->plyr[0].stime / TICRATE; - partime = stats->partime / TICRATE; - fprintf(stream, "Time: %i:%02i", leveltime / 60, leveltime % 60); - fprintf(stream, " (par: %i:%02i)\n", partime / 60, partime % 60); - fprintf(stream, "\n"); - - for (i = 0; i < MAXPLAYERS; ++i) - { - if (stats->plyr[i].in) - { - print_player_stats(stream, stats, i); - } - } - - if (get_num_players(stats) >= 2) - { - print_frags_table(stream, stats); - } - - fprintf(stream, "\n"); -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -void stat_copy(const wbstartstruct_t *stats) -{ - if (m_parm_exists("-statdump") && num_captured_stats < MAX_CAPTURES) - { - memcpy(&captured_stats[num_captured_stats], stats, - sizeof(wbstartstruct_t)); - ++num_captured_stats; - } -} - -void stat_dump(void) -{ - FILE *dumpfile; - int i; - - /* @category compat - * @arg - * - * Dump statistics information to the specified file on the levels - * that were played. The output from this option matches the output - * from statdump.exe (see ctrlapi.zip in the /idgames archive). - */ - - i = m_check_parm_with_args("-statdump", 1); - - if (i > 0) - { - printf("Statistics captured for %i level(s)\n", num_captured_stats); - - /* We actually know what the real gamemission is, but this has - * to match the output from statdump.exe. - */ - - discover_game_mode(captured_stats, num_captured_stats); - - /* Allow "-" as output file, for stdout. */ - - if (strcmp(myargv[i + 1], "-") != 0) - { - dumpfile = fopen(myargv[i + 1], "w"); - } - else - { - dumpfile = stdout; - } - - for (i = 0; i < num_captured_stats; ++i) - { - print_stats(dumpfile, &captured_stats[i]); - } - - if (dumpfile != stdout) - { - fclose(dumpfile); - } - } -} diff --git a/games/NXDoom/src/doom/statdump.h b/games/NXDoom/src/doom/statdump.h deleted file mode 100644 index 57073aa08..000000000 --- a/games/NXDoom/src/doom/statdump.h +++ /dev/null @@ -1,30 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/statdump.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - ****************************************************************************/ - -#ifndef DOOM_STATDUMP_H -#define DOOM_STATDUMP_H - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -void stat_copy(const wbstartstruct_t *stats); -void stat_dump(void); - -#endif /* DOOM_STATDUMP_H */ diff --git a/games/NXDoom/src/doom/wi_stuff.c b/games/NXDoom/src/doom/wi_stuff.c deleted file mode 100644 index fdb5964ad..000000000 --- a/games/NXDoom/src/doom/wi_stuff.c +++ /dev/null @@ -1,1893 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/wi_stuff.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Intermission screens. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include "z_zone.h" - -#include "m_misc.h" -#include "m_random.h" - -#include "deh_main.h" -#include "i_swap.h" -#include "i_system.h" - -#include "w_wad.h" - -#include "g_game.h" - -#include "r_local.h" - -#ifdef CONFIG_GAMES_NXDOOM_SOUND -#include "s_sound.h" -#include "sounds.h" -#endif - -#include "doomstat.h" - -/* Needs access to LFB. */ - -#include "v_video.h" - -#include "wi_stuff.h" - -/**************************************************************************** - * Pre-Processor Definitions - ****************************************************************************/ - -/* Data needed to add patches to full screen intermission pics. - * Patches are statistics messages, and animations. - * Loads of by-pixel layout and placement, offsets etc. - */ - -/* Different between registered DOOM (1994) and - * Ultimate DOOM - Final edition (retail, 1995?). - * This is supposedly ignored for commercial - * release (aka DOOM II), which had 34 maps - * in one episode. So there. - */ - -#define NUMEPISODES 4 -#define NUMMAPS 9 - -/* in tics - * U #define PAUSELEN (TICRATE*2) - * U #define SCORESTEP 100 - * U #define ANIMPERIOD 32 - * pixel distance from "(YOU)" to "PLAYER N" - * U #define STARDIST 10 - * U #define WK 1 - */ - -/* GLOBAL LOCATIONS */ - -#define WI_TITLEY 2 -#define WI_SPACINGY 33 - -/* SINGLE-PLAYER STUFF */ - -#define SP_STATSX 50 -#define SP_STATSY 50 - -#define SP_TIMEX 16 -#define SP_TIMEY (SCREENHEIGHT - 32) - -/* NET GAME STUFF */ - -#define NG_STATSY 50 -#define NG_STATSX (32 + SHORT(star->width) / 2 + 32 * !dofrags) - -#define NG_SPACINGX 64 - -/* DEATHMATCH STUFF */ - -#define DM_MATRIXX 42 -#define DM_MATRIXY 68 - -#define DM_SPACINGX 40 - -#define DM_TOTALSX 269 - -#define DM_KILLERSX 10 -#define DM_KILLERSY 100 -#define DM_VICTIMSX 5 -#define DM_VICTIMSY 50 - -/* Animation locations for episode 0 (1). - * Using patches saves a lot of space, - * as they replace 320x200 full screen frames. - */ - -#define ANIM(type, period, nanims, x, y, nexttic) \ - {(type), (period), (nanims), {(x), (y)}, (nexttic), 0, {NULL, NULL, NULL}, \ - 0, 0, 0, 0} - -/* GENERAL DATA */ - -/* Locally used stuff. */ - -/* States for single-player */ - -#define SP_KILLS 0 -#define SP_ITEMS 2 -#define SP_SECRET 4 -#define SP_FRAGS 6 -#define SP_TIME 8 -#define SP_PAR ST_TIME - -#define SP_PAUSE 1 - -/* in seconds */ - -#define SHOWNEXTLOCDELAY 4 - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -typedef enum -{ - ANIM_ALWAYS, - ANIM_RANDOM, - ANIM_LEVEL -} animenum_t; - -/* States for the intermission */ - -typedef enum -{ - NO_STATE = -1, - STAT_COUNT, - SHOW_NEXT_LOC, -} stateenum_t; - -typedef struct -{ - int x; - int y; -} point_t; - -/* Animation. - * There is another anim_t used in p_spec. - */ - -typedef struct -{ - animenum_t type; - - /* period in tics between animations */ - - int period; - - /* number of animation frames */ - - int nanims; - - /* location of animation */ - - point_t loc; - - /* ALWAYS: n/a, - * RANDOM: period deviation (<256), - * LEVEL: level - */ - - int data1; - - /* ALWAYS: n/a, - * RANDOM: random base period, - * LEVEL: n/a - */ - - int data2; - - /* actual graphics for frames of animations */ - - patch_t *p[3]; - - /* following must be initialized to zero before use! */ - - /* next value of bcnt (used in conjunction with period) */ - - int nexttic; - - /* last drawn animation frame */ - - int lastdrawn; - - /* next frame number to animate */ - - int ctr; - - /* used by RANDOM and LEVEL when animating */ - - int state; -} anim_t; - -typedef void (*load_callback_t)(const char *lumpname, patch_t **variable); - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static point_t lnodes[NUMEPISODES][NUMMAPS] = -{ - /* Episode 0 World Map */ - - { - {185, 164}, /* location of level 0 (CJ) */ - {148, 143}, /* location of level 1 (CJ) */ - {69, 122}, /* location of level 2 (CJ) */ - {209, 102}, /* location of level 3 (CJ) */ - {116, 89}, /* location of level 4 (CJ) */ - {166, 55}, /* location of level 5 (CJ) */ - {71, 56}, /* location of level 6 (CJ) */ - {135, 29}, /* location of level 7 (CJ) */ - {71, 24}, /* location of level 8 (CJ) */ - }, - - /* Episode 1 World Map should go here */ - - { - {254, 25}, /* location of level 0 (CJ) */ - {97, 50}, /* location of level 1 (CJ) */ - {188, 64}, /* location of level 2 (CJ) */ - {128, 78}, /* location of level 3 (CJ) */ - {214, 92}, /* location of level 4 (CJ) */ - {133, 130}, /* location of level 5 (CJ) */ - {208, 136}, /* location of level 6 (CJ) */ - {148, 140}, /* location of level 7 (CJ) */ - {235, 158}, /* location of level 8 (CJ) */ - }, - - /* Episode 2 World Map should go here */ - - { - {156, 168}, /* location of level 0 (CJ) */ - {48, 154}, /* location of level 1 (CJ) */ - {174, 95}, /* location of level 2 (CJ) */ - {265, 75}, /* location of level 3 (CJ) */ - {130, 48}, /* location of level 4 (CJ) */ - {279, 23}, /* location of level 5 (CJ) */ - {198, 48}, /* location of level 6 (CJ) */ - {140, 25}, /* location of level 7 (CJ) */ - {281, 136}, /* location of level 8 (CJ) */ - }, -}; - -static anim_t epsd0animinfo[] = -{ - ANIM(ANIM_ALWAYS, TICRATE / 3, 3, 224, 104, 0), - ANIM(ANIM_ALWAYS, TICRATE / 3, 3, 184, 160, 0), - ANIM(ANIM_ALWAYS, TICRATE / 3, 3, 112, 136, 0), - ANIM(ANIM_ALWAYS, TICRATE / 3, 3, 72, 112, 0), - ANIM(ANIM_ALWAYS, TICRATE / 3, 3, 88, 96, 0), - ANIM(ANIM_ALWAYS, TICRATE / 3, 3, 64, 48, 0), - ANIM(ANIM_ALWAYS, TICRATE / 3, 3, 192, 40, 0), - ANIM(ANIM_ALWAYS, TICRATE / 3, 3, 136, 16, 0), - ANIM(ANIM_ALWAYS, TICRATE / 3, 3, 80, 16, 0), - ANIM(ANIM_ALWAYS, TICRATE / 3, 3, 64, 24, 0), -}; - -static anim_t epsd1animinfo[] = -{ - ANIM(ANIM_LEVEL, TICRATE / 3, 1, 128, 136, 1), - ANIM(ANIM_LEVEL, TICRATE / 3, 1, 128, 136, 2), - ANIM(ANIM_LEVEL, TICRATE / 3, 1, 128, 136, 3), - ANIM(ANIM_LEVEL, TICRATE / 3, 1, 128, 136, 4), - ANIM(ANIM_LEVEL, TICRATE / 3, 1, 128, 136, 5), - ANIM(ANIM_LEVEL, TICRATE / 3, 1, 128, 136, 6), - ANIM(ANIM_LEVEL, TICRATE / 3, 1, 128, 136, 7), - ANIM(ANIM_LEVEL, TICRATE / 3, 3, 192, 144, 8), - ANIM(ANIM_LEVEL, TICRATE / 3, 1, 128, 136, 8), -}; - -static anim_t epsd2animinfo[] = -{ - ANIM(ANIM_ALWAYS, TICRATE / 3, 3, 104, 168, 0), - ANIM(ANIM_ALWAYS, TICRATE / 3, 3, 40, 136, 0), - ANIM(ANIM_ALWAYS, TICRATE / 3, 3, 160, 96, 0), - ANIM(ANIM_ALWAYS, TICRATE / 3, 3, 104, 80, 0), - ANIM(ANIM_ALWAYS, TICRATE / 3, 3, 120, 32, 0), - ANIM(ANIM_ALWAYS, TICRATE / 4, 3, 40, 0, 0), -}; - -static int NUMANIMS[NUMEPISODES] = -{ - arrlen(epsd0animinfo), - arrlen(epsd1animinfo), - arrlen(epsd2animinfo), -}; - -static anim_t *anims[NUMEPISODES] = -{ - epsd0animinfo, - epsd1animinfo, - epsd2animinfo, -}; - -/* used to accelerate or skip a stage */ - -static int acceleratestage; - -/* wbs->pnum */ - -static int me; - -/* specifies current state */ - -static stateenum_t state; - -/* contains information passed into intermission */ - -static wbstartstruct_t *wbs; - -static wbplayerstruct_t *plrs; /* wbs->plyr[] */ - -/* used for general timing */ - -static int cnt; - -/* used for timing of background animation */ - -static int bcnt; - -/* signals to refresh everything for one frame */ - -static int firstrefresh; - -static int cnt_kills[MAXPLAYERS]; -static int cnt_items[MAXPLAYERS]; -static int cnt_secret[MAXPLAYERS]; -static int cnt_time; -static int cnt_par; -static int cnt_pause; - -/* # of commercial levels */ - -static int NUMCMAPS; - -/* GRAPHICS */ - -/* You Are Here graphic */ - -static patch_t *yah[3] = -{ - NULL, - NULL, - NULL, -}; - -/* splat */ - -static patch_t *splat[2] = -{ - NULL, - NULL, -}; - -/* %, : graphics */ - -static patch_t *percent; -static patch_t *colon; - -/* 0-9 graphic */ - -static patch_t *num[10]; - -/* minus sign */ - -static patch_t *wiminus; - -/* "Finished!" graphics */ - -static patch_t *finished; - -/* "Entering" graphic */ - -static patch_t *entering; - -/* "secret" */ - -static patch_t *sp_secret; - -/* "Kills", "Scrt", "Items", "Frags" */ - -static patch_t *kills; -static patch_t *secret; -static patch_t *items; -static patch_t *frags; - -/* Time sucks. */ - -static patch_t *timepatch; -static patch_t *par; -static patch_t *sucks; - -/* "killers", "victims" */ - -static patch_t *killers; -static patch_t *victims; - -/* "Total", your face, your dead face */ - -static patch_t *total; -static patch_t *star; -static patch_t *bstar; - -/* "red P[1..MAXPLAYERS]" */ - -static patch_t *p[MAXPLAYERS]; - -/* "gray P[1..MAXPLAYERS]" */ - -static patch_t *bp[MAXPLAYERS]; - -/* Name graphics of each level (centered) */ - -static patch_t **lnames; - -/* Buffer storing the backdrop */ - -static patch_t *background; - -static int dm_state; -static int dm_frags[MAXPLAYERS][MAXPLAYERS]; -static int dm_totals[MAXPLAYERS]; - -static int cnt_frags[MAXPLAYERS]; -static int dofrags; -static int ng_state; - -static int sp_state; - -static boolean snl_pointeron = false; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/* Common load/unload function. Iterates over all the graphics - * lumps to be loaded/unloaded into memory. - */ - -static void wi_load_unload_data(load_callback_t callback) -{ - int8_t i; - int8_t j; - char name[23]; - anim_t *a; - - if (gamemode == commercial) - { - for (i = 0; i < NUMCMAPS; i++) - { - snprintf(name, sizeof(name), "CWILV%2.2d", i); - callback(name, &lnames[i]); - } - } - else - { - for (i = 0; i < NUMMAPS; i++) - { - snprintf(name, sizeof(name), "WILV%d%d", wbs->epsd, i); - callback(name, &lnames[i]); - } - - /* you are here */ - - callback(("WIURH0"), &yah[0]); - - /* you are here (alt.) */ - - callback(("WIURH1"), &yah[1]); - - /* splat */ - - callback(("WISPLAT"), &splat[0]); - - if (wbs->epsd < 3) - { - for (j = 0; j < NUMANIMS[wbs->epsd]; j++) - { - a = &anims[wbs->epsd][j]; - for (i = 0; i < a->nanims; i++) - { - /* MONDO HACK! */ - - if (wbs->epsd != 1 || j != 8) - { - /* animations */ - - snprintf(name, sizeof(name), "WIA%d%.2d%.2d", - wbs->epsd, j, i); - callback(name, &a->p[i]); - } - else - { - /* HACK ALERT! */ - - a->p[i] = anims[1][4].p[i]; - } - } - } - } - } - - /* More hacks on minus sign. */ - - if (w_check_num_for_name(("WIMINUS")) > 0) - callback(("WIMINUS"), &wiminus); - else - wiminus = NULL; - - for (i = 0; i < 10; i++) - { - /* numbers 0-9 */ - - snprintf(name, sizeof(name), "WINUM%d", i); - callback(name, &num[i]); - } - - /* percent sign */ - - callback(("WIPCNT"), &percent); - - /* "finished" */ - - callback(("WIF"), &finished); - - /* "entering" */ - - callback(("WIENTER"), &entering); - - /* "kills" */ - - callback(("WIOSTK"), &kills); - - /* "scrt" */ - - callback(("WIOSTS"), &secret); - - /* "secret" */ - - callback(("WISCRT2"), &sp_secret); - - /* french wad uses WIOBJ (?) */ - - if (w_check_num_for_name(("WIOBJ")) >= 0) - { - /* "items" */ - - if (netgame && !deathmatch) - callback(("WIOBJ"), &items); - else - callback(("WIOSTI"), &items); - } - else - { - callback(("WIOSTI"), &items); - } - - /* "frgs" */ - - callback(("WIFRGS"), &frags); - - /* ":" */ - - callback(("WICOLON"), &colon); - - /* "time" */ - - callback(("WITIME"), &timepatch); - - /* "sucks" */ - - callback(("WISUCKS"), &sucks); - - /* "par" */ - - callback(("WIPAR"), &par); - - /* "killers" (vertical) */ - - callback(("WIKILRS"), &killers); - - /* "victims" (horiz) */ - - callback(("WIVCTMS"), &victims); - - /* "total" */ - - callback(("WIMSTT"), &total); - - for (i = 0; i < MAXPLAYERS; i++) - { - /* "1,2,3,4" */ - - snprintf(name, sizeof(name), "STPB%d", i); - callback(name, &p[i]); - - /* "1,2,3,4" */ - - snprintf(name, sizeof(name), "WIBP%d", i + 1); - callback(name, &bp[i]); - } - - /* Background image */ - - if (gamemode == commercial) - { - m_str_copy(name, ("INTERPIC"), sizeof(name)); - } - else if (gameversion >= exe_ultimate && wbs->epsd == 3) - { - m_str_copy(name, ("INTERPIC"), sizeof(name)); - } - else - { - snprintf(name, sizeof(name), "WIMAP%d", wbs->epsd); - } - - /* Draw backdrop and save to a temporary buffer */ - - callback(name, &background); -} - -static void wi_load_callback(const char *name, patch_t **variable) -{ - *variable = w_cache_lump_name(name, PU_STATIC); -} - -static void wi_unload_callback(const char *name, patch_t **variable) -{ - w_release_lump_name(name); - *variable = NULL; -} - -static void wi_load_data(void) -{ - if (gamemode == commercial) - { - NUMCMAPS = 32; - lnames = (patch_t **)z_malloc(sizeof(patch_t *) * NUMCMAPS, - PU_STATIC, NULL); - } - else - { - lnames = - (patch_t **)z_malloc(sizeof(patch_t *) * NUMMAPS, PU_STATIC, NULL); - } - - wi_load_unload_data(wi_load_callback); - - /* These two graphics are special cased because we're sharing them with the - * status bar code - */ - - /* your face */ - - star = w_cache_lump_name(("STFST01"), PU_STATIC); - - /* dead face */ - - bstar = w_cache_lump_name(("STFDEAD0"), PU_STATIC); -} - -static void wi_unload_data(void) -{ - wi_load_unload_data(wi_unload_callback); - - /* We do not free these lumps as they are shared with the status - * bar code. - */ - - /* w_release_lump_name("STFST01"); - * w_release_lump_name("STFDEAD0"); - */ -} - -/* slam background */ - -static void wi_slam_background(void) -{ - v_draw_patch(0, 0, background); -} - -/* Draws " Finished!" */ - -static void wi_draw_lf(void) -{ - int y = WI_TITLEY; - - if (gamemode != commercial || wbs->last < NUMCMAPS) - { - /* draw */ - - v_draw_patch((SCREENWIDTH - SHORT(lnames[wbs->last]->width)) / 2, y, - lnames[wbs->last]); - - /* draw "Finished!" */ - - y += (5 * SHORT(lnames[wbs->last]->height)) / 4; - - v_draw_patch((SCREENWIDTH - SHORT(finished->width)) / 2, y, finished); - } - else if (wbs->last == NUMCMAPS) - { - /* MAP33 - draw "Finished!" only */ - - v_draw_patch((SCREENWIDTH - SHORT(finished->width)) / 2, y, finished); - } - else if (wbs->last > NUMCMAPS) - { - /* > MAP33. Doom bombs out here with a Bad v_draw_patch error. - * I'm pretty sure that doom2.exe is just reading into random - * bits of memory at this point, but let's try to be accurate - * anyway. This deliberately triggers a v_draw_patch error. - */ - - patch_t tmp = - { - SCREENWIDTH, - SCREENHEIGHT, - 1, - 1, - { - 0, 0, 0, 0, 0, 0, 0, 0 - }, - }; - - v_draw_patch(0, y, &tmp); - } -} - -/* Draws "Entering " */ - -static void wi_draw_e(void) -{ - int y = WI_TITLEY; - - /* draw "Entering" */ - - v_draw_patch((SCREENWIDTH - SHORT(entering->width)) / 2, y, entering); - - /* draw level */ - - y += (5 * SHORT(lnames[wbs->next]->height)) / 4; - - v_draw_patch((SCREENWIDTH - SHORT(lnames[wbs->next]->width)) / 2, y, - lnames[wbs->next]); -} - -static void wi_draw_on_lnode(int n, patch_t *c[]) -{ - int i; - int left; - int top; - int right; - int bottom; - boolean fits = false; - - i = 0; - do - { - left = lnodes[wbs->epsd][n].x - SHORT(c[i]->leftoffset); - top = lnodes[wbs->epsd][n].y - SHORT(c[i]->topoffset); - right = left + SHORT(c[i]->width); - bottom = top + SHORT(c[i]->height); - - if (left >= 0 && right < SCREENWIDTH && top >= 0 && - bottom < SCREENHEIGHT) - { - fits = true; - } - else - { - i++; - } - } - while (!fits && i != 2 && c[i] != NULL); - - if (fits && i < 2) - { - v_draw_patch(lnodes[wbs->epsd][n].x, lnodes[wbs->epsd][n].y, c[i]); - } - else - { - printf("Could not place patch on level %d", n + 1); /* DEBUG */ - } -} - -static void wi_init_animate_back(void) -{ - int i; - anim_t *a; - - if (gamemode == commercial) return; - - if (wbs->epsd > 2) return; - - for (i = 0; i < NUMANIMS[wbs->epsd]; i++) - { - a = &anims[wbs->epsd][i]; - - /* init variables */ - - a->ctr = -1; - - /* specify the next time to draw it */ - - if (a->type == ANIM_ALWAYS) - a->nexttic = bcnt + 1 + (m_random() % a->period); - else if (a->type == ANIM_RANDOM) - a->nexttic = bcnt + 1 + a->data2 + (m_random() % a->data1); - else if (a->type == ANIM_LEVEL) - a->nexttic = bcnt + 1; - } -} - -static void wi_update_animated_block(void) -{ - int i; - anim_t *a; - - if (gamemode == commercial) return; - - if (wbs->epsd > 2) return; - - for (i = 0; i < NUMANIMS[wbs->epsd]; i++) - { - a = &anims[wbs->epsd][i]; - - if (bcnt == a->nexttic) - { - switch (a->type) - { - case ANIM_ALWAYS: - if (++a->ctr >= a->nanims) a->ctr = 0; - a->nexttic = bcnt + a->period; - break; - - case ANIM_RANDOM: - a->ctr++; - if (a->ctr == a->nanims) - { - a->ctr = -1; - a->nexttic = bcnt + a->data2 + (m_random() % a->data1); - } - else - a->nexttic = bcnt + a->period; - break; - - case ANIM_LEVEL: - - /* gawd-awful hack for level anims */ - - if (!(state == STAT_COUNT && i == 7) && wbs->next == a->data1) - { - a->ctr++; - if (a->ctr == a->nanims) a->ctr--; - a->nexttic = bcnt + a->period; - } - break; - } - } - } -} - -static void wi_draw_animated_back(void) -{ - int i; - anim_t *a; - - if (gamemode == commercial) return; - - if (wbs->epsd > 2) return; - - for (i = 0; i < NUMANIMS[wbs->epsd]; i++) - { - a = &anims[wbs->epsd][i]; - - if (a->ctr >= 0) v_draw_patch(a->loc.x, a->loc.y, a->p[a->ctr]); - } -} - -/* Draws a number. - * If digits > 0, then use that many digits minimum, otherwise only use as - * many as necessary. Returns new x position. - */ - -static int wi_draw_num(int x, int y, int n, int digits) -{ - int fontwidth = SHORT(num[0]->width); - int neg; - int temp; - - if (digits < 0) - { - if (!n) - { - /* make variable-length zeros 1 digit long */ - - digits = 1; - } - else - { - /* figure out # of digits in # */ - - digits = 0; - temp = n; - - while (temp) - { - temp /= 10; - digits++; - } - } - } - - neg = n < 0; - if (neg) n = -n; - - /* if non-number, do not draw it */ - - if (n == 1994) return 0; - - /* draw the new number */ - - while (digits--) - { - x -= fontwidth; - v_draw_patch(x, y, num[n % 10]); - n /= 10; - } - - /* draw a minus sign if necessary */ - - if (neg && wiminus) v_draw_patch(x -= 8, y, wiminus); - - return x; -} - -static void wi_draw_percent(int x, int y, int p_p) -{ - if (p_p < 0) return; - - v_draw_patch(x, y, percent); - wi_draw_num(x, y, p_p, -1); -} - -/* Display level completion time and par, or "sucks" message if overflow. - */ - -static void wi_draw_time(int x, int y, int t) -{ - int div; - int n; - - if (t < 0) return; - - if (t <= 61 * 59) - { - div = 1; - - do - { - n = (t / div) % 60; - x = wi_draw_num(x, y, n, 2) - SHORT(colon->width); - div *= 60; - - /* draw */ - - if (div == 60 || t / div) v_draw_patch(x, y, colon); - } - while (t / div); - } - else - { - /* "sucks" */ - - v_draw_patch(x - SHORT(sucks->width), y, sucks); - } -} - -static void wi_init_nostate(void) -{ - state = NO_STATE; - acceleratestage = 0; - cnt = 10; -} - -static void wi_update_no_state(void) -{ - wi_update_animated_block(); - - if (!--cnt) - { - /* Don't call wi_end yet. g_world_done doesn't immediately - * change gamestate, so wi_drawer is still going to get - * run until that happens. If we do that after wi_end - * (which unloads all the graphics), we're in trouble. - * wi_end(); - */ - - g_world_done(); - } -} - -static void wi_init_show_next_loc(void) -{ - state = SHOW_NEXT_LOC; - acceleratestage = 0; - cnt = SHOWNEXTLOCDELAY * TICRATE; - - wi_init_animate_back(); -} - -static void wi_update_show_next_loc(void) -{ - wi_update_animated_block(); - - if (!--cnt || acceleratestage) - wi_init_nostate(); - else - snl_pointeron = (cnt & 31) < 20; -} - -static void wi_draw_show_next_loc(void) -{ - int i; - int last; - - wi_slam_background(); - - /* draw animated background */ - - wi_draw_animated_back(); - - if (gamemode != commercial) - { - if (wbs->epsd > 2) - { - wi_draw_e(); - return; - } - - last = (wbs->last == 8) ? wbs->next - 1 : wbs->last; - - /* draw a splat on taken cities. */ - - for (i = 0; i <= last; i++) - wi_draw_on_lnode(i, splat); - - /* splat the secret level? */ - - if (wbs->didsecret) wi_draw_on_lnode(8, splat); - - /* draw flashing ptr */ - - if (snl_pointeron) wi_draw_on_lnode(wbs->next, yah); - } - - /* draws which level you are entering.. */ - - if ((gamemode != commercial) || wbs->next != 30) wi_draw_e(); -} - -static void wi_draw_no_state(void) -{ - snl_pointeron = true; - wi_draw_show_next_loc(); -} - -static int wi_frag_sum(int playernum) -{ - int i; - int l_frags = 0; - - for (i = 0; i < MAXPLAYERS; i++) - { - if (playeringame[i] && i != playernum) - { - l_frags += plrs[playernum].frags[i]; - } - } - - /* JDC hack - negative frags. */ - - l_frags -= plrs[playernum].frags[playernum]; - - /* UNUSED if (frags < 0) - * frags = 0; - */ - - return l_frags; -} - -static void wi_init_deathmatch_stats(void) -{ - int i; - int j; - - state = STAT_COUNT; - acceleratestage = 0; - dm_state = 1; - - cnt_pause = TICRATE; - - for (i = 0; i < MAXPLAYERS; i++) - { - if (playeringame[i]) - { - for (j = 0; j < MAXPLAYERS; j++) - { - if (playeringame[j]) dm_frags[i][j] = 0; - } - - dm_totals[i] = 0; - } - } - - wi_init_animate_back(); -} - -static void wi_update_deathmatch_stats(void) -{ - int i; - int j; - - boolean stillticking; - - wi_update_animated_block(); - - if (acceleratestage && dm_state != 4) - { - acceleratestage = 0; - - for (i = 0; i < MAXPLAYERS; i++) - { - if (playeringame[i]) - { - for (j = 0; j < MAXPLAYERS; j++) - { - if (playeringame[j]) dm_frags[i][j] = plrs[i].frags[j]; - } - - dm_totals[i] = wi_frag_sum(i); - } - } - -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(0, SFX_BAREXP); -#endif - dm_state = 4; - } - - if (dm_state == 2) - { -#ifdef CONFIG_GAMES_NXDOOM_SOUND - if (!(bcnt & 3)) s_start_sound(0, SFX_PISTOL); -#endif - - stillticking = false; - - for (i = 0; i < MAXPLAYERS; i++) - { - if (playeringame[i]) - { - for (j = 0; j < MAXPLAYERS; j++) - { - if (playeringame[j] && dm_frags[i][j] != plrs[i].frags[j]) - { - if (plrs[i].frags[j] < 0) - dm_frags[i][j]--; - else - dm_frags[i][j]++; - - if (dm_frags[i][j] > 99) dm_frags[i][j] = 99; - - if (dm_frags[i][j] < -99) dm_frags[i][j] = -99; - - stillticking = true; - } - } - - dm_totals[i] = wi_frag_sum(i); - - if (dm_totals[i] > 99) dm_totals[i] = 99; - - if (dm_totals[i] < -99) dm_totals[i] = -99; - } - } - - if (!stillticking) - { -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(0, SFX_BAREXP); -#endif - dm_state++; - } - } - else if (dm_state == 4) - { - if (acceleratestage) - { -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(0, SFX_SLOP); -#endif - - if (gamemode == commercial) - wi_init_nostate(); - else - wi_init_show_next_loc(); - } - } - else if (dm_state & 1) - { - if (!--cnt_pause) - { - dm_state++; - cnt_pause = TICRATE; - } - } -} - -static void wi_draw_deathmatch_stats(void) -{ - int i; - int j; - int x; - int y; - int w; - - wi_slam_background(); - - /* draw animated background */ - - wi_draw_animated_back(); - wi_draw_lf(); - - /* draw stat titles (top line) */ - - v_draw_patch(DM_TOTALSX - SHORT(total->width) / 2, - DM_MATRIXY - WI_SPACINGY + 10, total); - - v_draw_patch(DM_KILLERSX, DM_KILLERSY, killers); - v_draw_patch(DM_VICTIMSX, DM_VICTIMSY, victims); - - /* draw P? */ - - x = DM_MATRIXX + DM_SPACINGX; - y = DM_MATRIXY; - - for (i = 0; i < MAXPLAYERS; i++) - { - if (playeringame[i]) - { - v_draw_patch(x - SHORT(p[i]->width) / 2, DM_MATRIXY - WI_SPACINGY, - p[i]); - - v_draw_patch(DM_MATRIXX - SHORT(p[i]->width) / 2, y, p[i]); - - if (i == me) - { - v_draw_patch(x - SHORT(p[i]->width) / 2, - DM_MATRIXY - WI_SPACINGY, bstar); - - v_draw_patch(DM_MATRIXX - SHORT(p[i]->width) / 2, y, star); - } - } - else - { - /* v_draw_patch(x-SHORT(bp[i]->width)/2, - * DM_MATRIXY - WI_SPACINGY, bp[i]); - * v_draw_patch(DM_MATRIXX-SHORT(bp[i]->width)/2, - * y, bp[i]); - */ - } - - x += DM_SPACINGX; - y += WI_SPACINGY; - } - - /* draw stats */ - - y = DM_MATRIXY + 10; - w = SHORT(num[0]->width); - - for (i = 0; i < MAXPLAYERS; i++) - { - x = DM_MATRIXX + DM_SPACINGX; - - if (playeringame[i]) - { - for (j = 0; j < MAXPLAYERS; j++) - { - if (playeringame[j]) wi_draw_num(x + w, y, dm_frags[i][j], 2); - - x += DM_SPACINGX; - } - - wi_draw_num(DM_TOTALSX + w, y, dm_totals[i], 2); - } - - y += WI_SPACINGY; - } -} - -static void wi_init_netgame_stats(void) -{ - int i; - - state = STAT_COUNT; - acceleratestage = 0; - ng_state = 1; - - cnt_pause = TICRATE; - - for (i = 0; i < MAXPLAYERS; i++) - { - if (!playeringame[i]) continue; - - cnt_kills[i] = cnt_items[i] = cnt_secret[i] = cnt_frags[i] = 0; - - dofrags += wi_frag_sum(i); - } - - dofrags = !!dofrags; - - wi_init_animate_back(); -} - -static void wi_update_netgame_stats(void) -{ - int i; - int fsum; - - boolean stillticking; - - wi_update_animated_block(); - - if (acceleratestage && ng_state != 10) - { - acceleratestage = 0; - - for (i = 0; i < MAXPLAYERS; i++) - { - if (!playeringame[i]) continue; - - cnt_kills[i] = (plrs[i].skills * 100) / wbs->maxkills; - cnt_items[i] = (plrs[i].sitems * 100) / wbs->maxitems; - cnt_secret[i] = (plrs[i].ssecret * 100) / wbs->maxsecret; - - if (dofrags) cnt_frags[i] = wi_frag_sum(i); - } - -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(0, SFX_BAREXP); -#endif - ng_state = 10; - } - - if (ng_state == 2) - { -#ifdef CONFIG_GAMES_NXDOOM_SOUND - if (!(bcnt & 3)) s_start_sound(0, SFX_PISTOL); -#endif - - stillticking = false; - - for (i = 0; i < MAXPLAYERS; i++) - { - if (!playeringame[i]) continue; - - cnt_kills[i] += 2; - - if (cnt_kills[i] >= (plrs[i].skills * 100) / wbs->maxkills) - cnt_kills[i] = (plrs[i].skills * 100) / wbs->maxkills; - else - stillticking = true; - } - - if (!stillticking) - { -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(0, SFX_BAREXP); -#endif - ng_state++; - } - } - else if (ng_state == 4) - { -#ifdef CONFIG_GAMES_NXDOOM_SOUND - if (!(bcnt & 3)) s_start_sound(0, SFX_PISTOL); -#endif - - stillticking = false; - - for (i = 0; i < MAXPLAYERS; i++) - { - if (!playeringame[i]) continue; - - cnt_items[i] += 2; - if (cnt_items[i] >= (plrs[i].sitems * 100) / wbs->maxitems) - cnt_items[i] = (plrs[i].sitems * 100) / wbs->maxitems; - else - stillticking = true; - } - - if (!stillticking) - { -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(0, SFX_BAREXP); -#endif - ng_state++; - } - } - else if (ng_state == 6) - { -#ifdef CONFIG_GAMES_NXDOOM_SOUND - if (!(bcnt & 3)) s_start_sound(0, SFX_PISTOL); -#endif - - stillticking = false; - - for (i = 0; i < MAXPLAYERS; i++) - { - if (!playeringame[i]) continue; - - cnt_secret[i] += 2; - - if (cnt_secret[i] >= (plrs[i].ssecret * 100) / wbs->maxsecret) - cnt_secret[i] = (plrs[i].ssecret * 100) / wbs->maxsecret; - else - stillticking = true; - } - - if (!stillticking) - { -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(0, SFX_BAREXP); -#endif - ng_state += 1 + 2 * !dofrags; - } - } - else if (ng_state == 8) - { -#ifdef CONFIG_GAMES_NXDOOM_SOUND - if (!(bcnt & 3)) s_start_sound(0, SFX_PISTOL); -#endif - - stillticking = false; - - for (i = 0; i < MAXPLAYERS; i++) - { - if (!playeringame[i]) continue; - - cnt_frags[i] += 1; - - if (cnt_frags[i] >= (fsum = wi_frag_sum(i))) - cnt_frags[i] = fsum; - else - stillticking = true; - } - - if (!stillticking) - { -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(0, SFX_PLDETH); -#endif - ng_state++; - } - } - else if (ng_state == 10) - { - if (acceleratestage) - { -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(0, SFX_SGCOCK); -#endif - if (gamemode == commercial) - wi_init_nostate(); - else - wi_init_show_next_loc(); - } - } - else if (ng_state & 1) - { - if (!--cnt_pause) - { - ng_state++; - cnt_pause = TICRATE; - } - } -} - -static void wi_init_stats(void) -{ - state = STAT_COUNT; - acceleratestage = 0; - sp_state = 1; - cnt_kills[0] = cnt_items[0] = cnt_secret[0] = -1; - cnt_time = cnt_par = -1; - cnt_pause = TICRATE; - - wi_init_animate_back(); -} - -static void wi_update_stats(void) -{ - wi_update_animated_block(); - - if (acceleratestage && sp_state != 10) - { - acceleratestage = 0; - cnt_kills[0] = (plrs[me].skills * 100) / wbs->maxkills; - cnt_items[0] = (plrs[me].sitems * 100) / wbs->maxitems; - cnt_secret[0] = (plrs[me].ssecret * 100) / wbs->maxsecret; - cnt_time = plrs[me].stime / TICRATE; - cnt_par = wbs->partime / TICRATE; -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(0, SFX_BAREXP); -#endif - sp_state = 10; - } - - if (sp_state == 2) - { - cnt_kills[0] += 2; - -#ifdef CONFIG_GAMES_NXDOOM_SOUND - if (!(bcnt & 3)) s_start_sound(0, SFX_PISTOL); -#endif - - if (cnt_kills[0] >= (plrs[me].skills * 100) / wbs->maxkills) - { - cnt_kills[0] = (plrs[me].skills * 100) / wbs->maxkills; -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(0, SFX_BAREXP); -#endif - sp_state++; - } - } - else if (sp_state == 4) - { - cnt_items[0] += 2; - -#ifdef CONFIG_GAMES_NXDOOM_SOUND - if (!(bcnt & 3)) s_start_sound(0, SFX_PISTOL); -#endif - - if (cnt_items[0] >= (plrs[me].sitems * 100) / wbs->maxitems) - { - cnt_items[0] = (plrs[me].sitems * 100) / wbs->maxitems; -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(0, SFX_BAREXP); -#endif - sp_state++; - } - } - else if (sp_state == 6) - { - cnt_secret[0] += 2; - -#ifdef CONFIG_GAMES_NXDOOM_SOUND - if (!(bcnt & 3)) s_start_sound(0, SFX_PISTOL); -#endif - - if (cnt_secret[0] >= (plrs[me].ssecret * 100) / wbs->maxsecret) - { - cnt_secret[0] = (plrs[me].ssecret * 100) / wbs->maxsecret; -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(0, SFX_BAREXP); -#endif - sp_state++; - } - } - - else if (sp_state == 8) - { -#ifdef CONFIG_GAMES_NXDOOM_SOUND - if (!(bcnt & 3)) s_start_sound(0, SFX_PISTOL); -#endif - - cnt_time += 3; - - if (cnt_time >= plrs[me].stime / TICRATE) - cnt_time = plrs[me].stime / TICRATE; - - cnt_par += 3; - - if (cnt_par >= wbs->partime / TICRATE) - { - cnt_par = wbs->partime / TICRATE; - - if (cnt_time >= plrs[me].stime / TICRATE) - { -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(0, SFX_BAREXP); -#endif - sp_state++; - } - } - } - else if (sp_state == 10) - { - if (acceleratestage) - { -#ifdef CONFIG_GAMES_NXDOOM_SOUND - s_start_sound(0, SFX_SGCOCK); -#endif - - if (gamemode == commercial) - wi_init_nostate(); - else - wi_init_show_next_loc(); - } - } - else if (sp_state & 1) - { - if (!--cnt_pause) - { - sp_state++; - cnt_pause = TICRATE; - } - } -} - -static void wi_draw_netgame_stats(void) -{ - int i; - int x; - int y; - int pwidth = SHORT(percent->width); - - wi_slam_background(); - - /* draw animated background */ - - wi_draw_animated_back(); - - wi_draw_lf(); - - /* draw stat titles (top line) */ - - v_draw_patch(NG_STATSX + NG_SPACINGX - SHORT(kills->width), NG_STATSY, - kills); - - v_draw_patch(NG_STATSX + 2 * NG_SPACINGX - SHORT(items->width), NG_STATSY, - items); - - v_draw_patch(NG_STATSX + 3 * NG_SPACINGX - SHORT(secret->width), NG_STATSY, - secret); - - if (dofrags) - { - v_draw_patch(NG_STATSX + 4 * NG_SPACINGX - SHORT(frags->width), - NG_STATSY, frags); - } - - /* draw stats */ - - y = NG_STATSY + SHORT(kills->height); - - for (i = 0; i < MAXPLAYERS; i++) - { - if (!playeringame[i]) continue; - - x = NG_STATSX; - v_draw_patch(x - SHORT(p[i]->width), y, p[i]); - - if (i == me) v_draw_patch(x - SHORT(p[i]->width), y, star); - - x += NG_SPACINGX; - wi_draw_percent(x - pwidth, y + 10, cnt_kills[i]); - x += NG_SPACINGX; - wi_draw_percent(x - pwidth, y + 10, cnt_items[i]); - x += NG_SPACINGX; - wi_draw_percent(x - pwidth, y + 10, cnt_secret[i]); - x += NG_SPACINGX; - - if (dofrags) wi_draw_num(x, y + 10, cnt_frags[i], -1); - - y += WI_SPACINGY; - } -} - -static void wi_draw_stats(void) -{ - int lh; /* line height */ - - lh = (3 * SHORT(num[0]->height)) / 2; - - wi_slam_background(); - - /* draw animated background */ - - wi_draw_animated_back(); - - wi_draw_lf(); - - v_draw_patch(SP_STATSX, SP_STATSY, kills); - wi_draw_percent(SCREENWIDTH - SP_STATSX, SP_STATSY, cnt_kills[0]); - - v_draw_patch(SP_STATSX, SP_STATSY + lh, items); - wi_draw_percent(SCREENWIDTH - SP_STATSX, SP_STATSY + lh, cnt_items[0]); - - v_draw_patch(SP_STATSX, SP_STATSY + 2 * lh, sp_secret); - wi_draw_percent(SCREENWIDTH - SP_STATSX, SP_STATSY + 2 * lh, - cnt_secret[0]); - - v_draw_patch(SP_TIMEX, SP_TIMEY, timepatch); - wi_draw_time(SCREENWIDTH / 2 - SP_TIMEX, SP_TIMEY, cnt_time); - - if (wbs->epsd < 3) - { - v_draw_patch(SCREENWIDTH / 2 + SP_TIMEX, SP_TIMEY, par); - wi_draw_time(SCREENWIDTH - SP_TIMEX, SP_TIMEY, cnt_par); - } -} - -static void wi_check_for_accelerate(void) -{ - int i; - player_t *player; - - /* check for button presses to skip delays */ - - for (i = 0, player = players; i < MAXPLAYERS; i++, player++) - { - if (playeringame[i]) - { - if (player->cmd.buttons & BT_ATTACK) - { - if (!player->attackdown) acceleratestage = 1; - player->attackdown = true; - } - else - player->attackdown = false; - if (player->cmd.buttons & BT_USE) - { - if (!player->usedown) acceleratestage = 1; - player->usedown = true; - } - else - player->usedown = false; - } - } -} - -static void wi_init_variables(wbstartstruct_t *wbstartstruct) -{ - wbs = wbstartstruct; - - acceleratestage = 0; - cnt = bcnt = 0; - firstrefresh = 1; - me = wbs->pnum; - plrs = wbs->plyr; - - if (!wbs->maxkills) wbs->maxkills = 1; - - if (!wbs->maxitems) wbs->maxitems = 1; - - if (!wbs->maxsecret) wbs->maxsecret = 1; - - if (gameversion < exe_ultimate) - { - if (wbs->epsd > 2) wbs->epsd -= 3; - } -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -void wi_end(void) -{ - wi_unload_data(); -} - -/* Updates stuff each tick */ - -void wi_ticker(void) -{ - /* counter for general background animation */ - - bcnt++; - - if (bcnt == 1) - { -#ifdef CONFIG_GAMES_NXDOOM_SOUND - /* intermission music */ - - if (gamemode == commercial) - s_change_music(MUS_DM2INT, true); - else - s_change_music(MUS_INTER, true); -#endif - } - - wi_check_for_accelerate(); - - switch (state) - { - case STAT_COUNT: - if (deathmatch) - wi_update_deathmatch_stats(); - else if (netgame) - wi_update_netgame_stats(); - else - wi_update_stats(); - break; - - case SHOW_NEXT_LOC: - wi_update_show_next_loc(); - break; - - case NO_STATE: - wi_update_no_state(); - break; - } -} - -void wi_drawer(void) -{ - switch (state) - { - case STAT_COUNT: - if (deathmatch) - wi_draw_deathmatch_stats(); - else if (netgame) - wi_draw_netgame_stats(); - else - wi_draw_stats(); - break; - - case SHOW_NEXT_LOC: - wi_draw_show_next_loc(); - break; - - case NO_STATE: - wi_draw_no_state(); - break; - } -} - -void wi_start(wbstartstruct_t *wbstartstruct) -{ - wi_init_variables(wbstartstruct); - wi_load_data(); - - if (deathmatch) - wi_init_deathmatch_stats(); - else if (netgame) - wi_init_netgame_stats(); - else - wi_init_stats(); -} diff --git a/games/NXDoom/src/doom/wi_stuff.h b/games/NXDoom/src/doom/wi_stuff.h deleted file mode 100644 index 78c689d78..000000000 --- a/games/NXDoom/src/doom/wi_stuff.h +++ /dev/null @@ -1,78 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doom/wi_stuff.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Intermission. - * - ****************************************************************************/ - -#ifndef __WI_STUFF__ -#define __WI_STUFF__ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "doomdef.h" - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Name: wi_ticker - * - * Description: - * Called by main loop, animate the intermission. - * - ****************************************************************************/ - -void wi_ticker(void); - -/**************************************************************************** - * Name: wi_drawer - * - * Description: - * Called by main loop, draws the intermission directly into the screen - * buffer. - * - ****************************************************************************/ - -void wi_drawer(void); - -/**************************************************************************** - * Name: wi_start - * - * Description: - * Setup for an intermission screen. - * - ****************************************************************************/ - -void wi_start(wbstartstruct_t *wbstartstruct); - -/**************************************************************************** - * Name: wi_end - * - * Description: - * Shut down the intermission screen - * - ****************************************************************************/ - -void wi_end(void); - -#endif /* __WI_STUFF__ */ diff --git a/games/NXDoom/src/doomkeys.h b/games/NXDoom/src/doomkeys.h deleted file mode 100644 index f29a2b782..000000000 --- a/games/NXDoom/src/doomkeys.h +++ /dev/null @@ -1,302 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doomkeys.h - * - * SPDX-License-Identifier: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Key definitions - * - * - ****************************************************************************/ - -#ifndef __DOOMKEYS__ -#define __DOOMKEYS__ - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* DOOM keyboard definition. - * This is the stuff configured by Setup.Exe. - * Most key data are simple ascii (uppercased). - */ - -#define KEY_RIGHTARROW 0xae -#define KEY_LEFTARROW 0xac -#define KEY_UPARROW 0xad -#define KEY_DOWNARROW 0xaf -#define KEY_ESCAPE 27 -#define KEY_ENTER 13 -#define KEY_TAB 9 -#define KEY_F1 (0x80 + 0x3b) -#define KEY_F2 (0x80 + 0x3c) -#define KEY_F3 (0x80 + 0x3d) -#define KEY_F4 (0x80 + 0x3e) -#define KEY_F5 (0x80 + 0x3f) -#define KEY_F6 (0x80 + 0x40) -#define KEY_F7 (0x80 + 0x41) -#define KEY_F8 (0x80 + 0x42) -#define KEY_F9 (0x80 + 0x43) -#define KEY_F10 (0x80 + 0x44) -#define KEY_F11 (0x80 + 0x57) -#define KEY_F12 (0x80 + 0x58) - -#define KEY_BACKSPACE 0x7f -#define KEY_PAUSE 0xff - -#define KEY_EQUALS 0x3d -#define KEY_MINUS 0x2d - -#define KEY_RSHIFT (0x80 + 0x36) -#define KEY_RCTRL (0x80 + 0x1d) -#define KEY_RALT (0x80 + 0x38) - -#define KEY_LALT KEY_RALT - -/* new keys: */ - -#define KEY_CAPSLOCK (0x80 + 0x3a) -#define KEY_NUMLOCK (0x80 + 0x45) -#define KEY_SCRLCK (0x80 + 0x46) -#define KEY_PRTSCR (0x80 + 0x59) - -#define KEY_HOME (0x80 + 0x47) -#define KEY_END (0x80 + 0x4f) -#define KEY_PGUP (0x80 + 0x49) -#define KEY_PGDN (0x80 + 0x51) -#define KEY_INS (0x80 + 0x52) -#define KEY_DEL (0x80 + 0x53) - -#define KEYP_0 KEY_INS -#define KEYP_1 KEY_END -#define KEYP_2 KEY_DOWNARROW -#define KEYP_3 KEY_PGDN -#define KEYP_4 KEY_LEFTARROW -#define KEYP_5 (0x80 + 0x4c) -#define KEYP_6 KEY_RIGHTARROW -#define KEYP_7 KEY_HOME -#define KEYP_8 KEY_UPARROW -#define KEYP_9 KEY_PGUP - -#define KEYP_DIVIDE '/' -#define KEYP_PLUS '+' -#define KEYP_MINUS '-' -#define KEYP_MULTIPLY '*' -#define KEYP_PERIOD 0 -#define KEYP_EQUALS KEY_EQUALS -#define KEYP_ENTER KEY_ENTER - -#define KEY_NONUSBACKSLASH '\\' - -#define SCANCODE_TO_KEYS_ARRAY \ - { \ - 0, \ - 0, \ - 0, \ - 0, \ - 'a', /* 0-9 */ \ - 'b', \ - 'c', \ - 'd', \ - 'e', \ - 'f', \ - 'g', \ - 'h', \ - 'i', \ - 'j', \ - 'k', /* 10-19 */ \ - 'l', \ - 'm', \ - 'n', \ - 'o', \ - 'p', \ - 'q', \ - 'r', \ - 's', \ - 't', \ - 'u', /* 20-29 */ \ - 'v', \ - 'w', \ - 'x', \ - 'y', \ - 'z', \ - '1', \ - '2', \ - '3', \ - '4', \ - '5', /* 30-39 */ \ - '6', \ - '7', \ - '8', \ - '9', \ - '0', \ - KEY_ENTER, \ - KEY_ESCAPE, \ - KEY_BACKSPACE, \ - KEY_TAB, \ - ' ', /* 40-49 */ \ - KEY_MINUS, \ - KEY_EQUALS, \ - '[', \ - ']', \ - '\\', \ - 0, \ - ';', \ - '\'', \ - '`', \ - ',', /* 50-59 */ \ - '.', \ - '/', \ - KEY_CAPSLOCK, \ - KEY_F1, \ - KEY_F2, \ - KEY_F3, \ - KEY_F4, \ - KEY_F5, \ - KEY_F6, \ - KEY_F7, /* 60-69 */ \ - KEY_F8, \ - KEY_F9, \ - KEY_F10, \ - KEY_F11, \ - KEY_F12, \ - KEY_PRTSCR, \ - KEY_SCRLCK, \ - KEY_PAUSE, \ - KEY_INS, \ - KEY_HOME, /* 70-79 */ \ - KEY_PGUP, \ - KEY_DEL, \ - KEY_END, \ - KEY_PGDN, \ - KEY_RIGHTARROW, \ - KEY_LEFTARROW, \ - KEY_DOWNARROW, \ - KEY_UPARROW, /* 80-89 */ \ - KEY_NUMLOCK, \ - KEYP_DIVIDE, \ - KEYP_MULTIPLY, \ - KEYP_MINUS, \ - KEYP_PLUS, \ - KEYP_ENTER, \ - KEYP_1, \ - KEYP_2, \ - KEYP_3, \ - KEYP_4, \ - KEYP_5, \ - KEYP_6, /* 90-99 */ \ - KEYP_7, \ - KEYP_8, \ - KEYP_9, \ - KEYP_0, \ - KEYP_PERIOD, \ - KEY_NONUSBACKSLASH, \ - 0, \ - 0, \ - KEYP_EQUALS, /* 100-103 */ \ - } - -/* Default names for keys, to use in English or as fallback. */ - -#define KEY_NAMES_ARRAY \ - { \ - {KEY_BACKSPACE, "BACKSP"}, \ - {KEY_TAB, "TAB"}, \ - {KEY_INS, "INS"}, \ - {KEY_DEL, "DEL"}, \ - {KEY_PGUP, "PGUP"}, \ - {KEY_PGDN, "PGDN"}, \ - {KEY_ENTER, "ENTER"}, \ - {KEY_ESCAPE, "ESC"}, \ - {KEY_F1, "F1"}, \ - {KEY_F2, "F2"}, \ - {KEY_F3, "F3"}, \ - {KEY_F4, "F4"}, \ - {KEY_F5, "F5"}, \ - {KEY_F6, "F6"}, \ - {KEY_F7, "F7"}, \ - {KEY_F8, "F8"}, \ - {KEY_F9, "F9"}, \ - {KEY_F10, "F10"}, \ - {KEY_F11, "F11"}, \ - {KEY_F12, "F12"}, \ - {KEY_HOME, "HOME"}, \ - {KEY_END, "END"}, \ - {KEY_MINUS, "-"}, \ - {KEY_EQUALS, "="}, \ - {KEY_NUMLOCK, "NUMLCK"}, \ - {KEY_SCRLCK, "SCRLCK"}, \ - {KEY_PAUSE, "PAUSE"}, \ - {KEY_PRTSCR, "PRTSC"}, \ - {KEY_UPARROW, "UP"}, \ - {KEY_DOWNARROW, "DOWN"}, \ - {KEY_LEFTARROW, "LEFT"}, \ - {KEY_RIGHTARROW, "RIGHT"}, \ - {KEY_RALT, "ALT"}, \ - {KEY_LALT, "ALT"}, \ - {KEY_RSHIFT, "SHIFT"}, \ - {KEY_CAPSLOCK, "CAPS"}, \ - {KEY_RCTRL, "CTRL"}, \ - {KEYP_5, "NUM5"}, \ - {' ', "SPACE"}, \ - {'a', "A"}, \ - {'b', "B"}, \ - {'c', "C"}, \ - {'d', "D"}, \ - {'e', "E"}, \ - {'f', "F"}, \ - {'g', "G"}, \ - {'h', "H"}, \ - {'i', "I"}, \ - {'j', "J"}, \ - {'k', "K"}, \ - {'l', "L"}, \ - {'m', "M"}, \ - {'n', "N"}, \ - {'o', "O"}, \ - {'p', "P"}, \ - {'q', "Q"}, \ - {'r', "R"}, \ - {'s', "S"}, \ - {'t', "T"}, \ - {'u', "U"}, \ - {'v', "V"}, \ - {'w', "W"}, \ - {'x', "X"}, \ - {'y', "Y"}, \ - {'z', "Z"}, \ - {'0', "0"}, \ - {'1', "1"}, \ - {'2', "2"}, \ - {'3', "3"}, \ - {'4', "4"}, \ - {'5', "5"}, \ - {'6', "6"}, \ - {'7', "7"}, \ - {'8', "8"}, \ - {'9', "9"}, \ - {'[', "["}, \ - {']', "]"}, \ - {';', ";"}, \ - {'`', "`"}, \ - {',', ","}, \ - {'.', "."}, \ - {'/', "/"}, \ - {'\\', "\\"}, \ - {'\'', "\'"}, \ - } - -#endif /* __DOOMKEYS__ */ diff --git a/games/NXDoom/src/doomtype.h b/games/NXDoom/src/doomtype.h deleted file mode 100644 index 2029723ad..000000000 --- a/games/NXDoom/src/doomtype.h +++ /dev/null @@ -1,119 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/doomtype.h - * - * SPDX-License-Identifier: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Simple basic typedefs, isolated here to make it easier - * separating modules. - * - ****************************************************************************/ - -#ifndef __DOOMTYPE__ -#define __DOOMTYPE__ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include - -/* What is really wanted here is stdint.h; however, some old versions - * of Solaris don't have stdint.h and only have inttypes.h (the - * pre-standardisation version). inttypes.h is also in the C99 - * standard and defined to include stdint.h, so include this. - */ - -#include -#include - -#include - -#include "config.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define DIR_SEPARATOR '/' -#define DIR_SEPARATOR_S "/" -#define PATH_SEPARATOR ':' - -#define arrlen(array) (sizeof(array) / sizeof(*array)) - -/* The packed attribute forces structures to be packed into the minimum - * space necessary. If this is not done, the compiler may align structure - * fields differently to optimize memory access, inflating the overall - * structure size. It is important to use the packed attribute on certain - * structures where alignment is important, particularly data read/written - * to disk. - */ - -#ifdef __GNUC__ - -#define PACKEDATTR __attribute__((packed)) - -#define PRINTF_ATTR(fmt, first) __attribute__((format(printf, fmt, first))) -#define PRINTF_ARG_ATTR(x) __attribute__((format_arg(x))) -#define NORETURN __attribute__((noreturn)) - -#else -#if defined(_MSC_VER) -#define PACKEDATTR __pragma(pack(pop)) -#else -#define PACKEDATTR -#endif -#define PRINTF_ATTR(fmt, first) -#define PRINTF_ARG_ATTR(x) -#define NORETURN -#endif /* __GNUC__ */ - -#define PACKEDPREFIX - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -/* C99 integer types; with gcc we just use this. Other compilers - * should add conditional statements that define the C99 types. - */ - -#if defined(__cplusplus) || defined(__bool_true_false_are_defined) - -/* The C++/C99 bool type (or _Bool that is) can only have two values: - * 0 or 1. However, the Doom source code assumes any non-zero value - * to evaluate to true, so we have to use an int type here. - */ - -typedef int boolean; - -#else - -typedef enum -{ - false, - true -} boolean; - -#endif - -typedef uint8_t byte; -typedef uint8_t pixel_t; -typedef int16_t dpixel_t; - -#endif /* __DOOMTYPE__ */ diff --git a/games/NXDoom/src/gusconf.c b/games/NXDoom/src/gusconf.c deleted file mode 100644 index 01f6606c5..000000000 --- a/games/NXDoom/src/gusconf.c +++ /dev/null @@ -1,337 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/gusconf.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * GUS emulation code. - * - * Actually emulating a GUS is far too much work; fortunately - * GUS "emulation" already exists in the form of Timidity, which - * supports GUS patch files. This code therefore converts Doom's - * DMXGUS lump into an equivalent Timidity configuration file. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include -#include - -#include "m_misc.h" -#include "w_wad.h" -#include "z_zone.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define MAX_INSTRUMENTS 256 - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -typedef struct -{ - char *patch_names[MAX_INSTRUMENTS]; - int used[MAX_INSTRUMENTS]; - int mapping[MAX_INSTRUMENTS]; - unsigned int count; -} gus_config_t; - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -char *gus_patch_path = ""; -int gus_ram_kb = 1024; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static unsigned int mapping_index(void) -{ - unsigned int result = gus_ram_kb / 256; - - if (result < 1) - { - return 1; - } - else if (result > 4) - { - return 4; - } - else - { - return result; - } -} - -static int split_line(char *line, char **fields, unsigned int max_fields) -{ - unsigned int num_fields; - char *p; - - fields[0] = line; - num_fields = 1; - - for (p = line; *p != '\0'; ++p) - { - if (*p == ',') - { - *p = '\0'; - - /* Skip spaces following the comma. */ - - do - { - ++p; - } - while (*p != '\0' && isspace(*p)); - - fields[num_fields] = p; - ++num_fields; - --p; - - if (num_fields >= max_fields) - { - break; - } - } - else if (*p == '#') - { - *p = '\0'; - break; - } - } - - /* Strip off trailing whitespace from the end of the line. */ - - p = fields[num_fields - 1] + strlen(fields[num_fields - 1]); - while (p > fields[num_fields - 1] && isspace(*(p - 1))) - { - --p; - *p = '\0'; - } - - return num_fields; -} - -static void parse_line(gus_config_t *config, char *line) -{ - char *fields[6]; - unsigned int i; - unsigned int num_fields; - unsigned int instr_id; - unsigned int mapped_id; - - num_fields = split_line(line, fields, 6); - - if (num_fields < 6) - { - return; - } - - instr_id = atoi(fields[0]); - - /* Skip non GM percussions. */ - - if ((instr_id >= 128 && instr_id < 128 + 35) || instr_id > 128 + 81) - { - return; - } - - mapped_id = atoi(fields[mapping_index()]); - - for (i = 0; i < config->count; i++) - { - if (config->used[i] == mapped_id) - { - break; - } - } - - if (i == config->count) - { - /* DMX uses wrong patch name (we should use name of 'mapped_id' - * instrument, but DMX uses name of 'instr_id' instead). - */ - - free(config->patch_names[i]); - config->patch_names[i] = m_string_duplicate(fields[5]); - config->used[i] = mapped_id; - config->count++; - } - - config->mapping[instr_id] = i; -} - -static void parse_dmx_config(char *dmxconf, gus_config_t *config) -{ - char *p; - char *newline; - unsigned int i; - - memset(config, 0, sizeof(gus_config_t)); - - for (i = 0; i < MAX_INSTRUMENTS; ++i) - { - config->mapping[i] = -1; - config->used[i] = -1; - } - - config->count = 0; - - p = dmxconf; - - for (; ; ) - { - newline = strchr(p, '\n'); - - if (newline != NULL) - { - *newline = '\0'; - } - - parse_line(config, p); - - if (newline == NULL) - { - break; - } - else - { - p = newline + 1; - } - } -} - -static void free_dmx_config(gus_config_t *config) -{ - unsigned int i; - - for (i = 0; i < MAX_INSTRUMENTS; ++i) - { - free(config->patch_names[i]); - } -} - -static char *read_dmx_config(void) -{ - int lumpnum; - unsigned int len; - char *data; - - /* TODO: This should be chosen based on gamemode == commercial: */ - - lumpnum = w_check_num_for_name("DMXGUS"); - - if (lumpnum < 0) - { - lumpnum = w_get_num_for_name("DMXGUSC"); - } - - len = w_lump_length(lumpnum); - data = z_malloc(len + 1, PU_STATIC, NULL); - w_read_lump(lumpnum, data); - - data[len] = '\0'; - return data; -} - -static boolean write_timidity_config(char *path, gus_config_t *config) -{ - FILE *fstream; - unsigned int i; - - fstream = fopen(path, "w"); - - if (fstream == NULL) - { - return false; - } - - fprintf(fstream, "# Autogenerated Timidity config.\n\n"); - - fprintf(fstream, "dir \"%s\"\n", gus_patch_path); - - fprintf(fstream, "\nbank 0\n\n"); - - for (i = 0; i < 128; ++i) - { - if (config->mapping[i] >= 0 && config->mapping[i] < MAX_INSTRUMENTS && - config->patch_names[config->mapping[i]] != NULL) - { - fprintf(fstream, "%u %s\n", i, - config->patch_names[config->mapping[i]]); - } - } - - fprintf(fstream, "\ndrumset 0\n\n"); - - for (i = 128 + 35; i <= 128 + 81; ++i) - { - if (config->mapping[i] >= 0 && config->mapping[i] < MAX_INSTRUMENTS && - config->patch_names[config->mapping[i]] != NULL) - { - fprintf(fstream, "%u %s\n", i - 128, - config->patch_names[config->mapping[i]]); - } - } - - fprintf(fstream, "\n"); - - fclose(fstream); - - return true; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -boolean gus_write_config(char *path) -{ - boolean result; - char *dmxconf; - gus_config_t config; - - if (!strcmp(gus_patch_path, "")) - { - printf("You haven't configured gus_patch_path.\n"); - printf("gus_patch_path needs to point to the location of " - "your GUS patch set.\n" - "To get a copy of the \"standard\" GUS patches, " - "download a copy of dgguspat.zip.\n"); - - return false; - } - - dmxconf = read_dmx_config(); - parse_dmx_config(dmxconf, &config); - - result = write_timidity_config(path, &config); - - free_dmx_config(&config); - z_free(dmxconf); - - return result; -} diff --git a/games/NXDoom/src/gusconf.h b/games/NXDoom/src/gusconf.h deleted file mode 100644 index aef259d5e..000000000 --- a/games/NXDoom/src/gusconf.h +++ /dev/null @@ -1,45 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/gusconf.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * GUS emulation code. - * - ****************************************************************************/ - -#ifndef __GUSCONF_H__ -#define __GUSCONF_H__ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "doomtype.h" - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -extern char *gus_patch_path; -extern int gus_ram_kb; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -boolean gus_write_config(char *path); - -#endif /* __GUSCONF_H__ */ diff --git a/games/NXDoom/src/i_endoom.c b/games/NXDoom/src/i_endoom.c deleted file mode 100644 index 97a797ee8..000000000 --- a/games/NXDoom/src/i_endoom.c +++ /dev/null @@ -1,99 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/i_endoom.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Exit text-mode ENDOOM screen. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -#include "config.h" -#include "doomtype.h" -#include "i_video.h" - -#include "txt_main.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define ENDOOM_W 80 -#define ENDOOM_H 25 - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: i_endoom - * - * Description: - * Displays the text mode ending screen after the game quits - * - ****************************************************************************/ - -void i_endoom(byte *endoom_data) -{ - unsigned char *screendata; - int y; - int indent; - - /* Set up text mode screen */ - - txt_init(); - - txt_set_window_title(PACKAGE_STRING); - - /* SDL2-TODO i_init_window_title(); - */ - - /* Write the data to the screen memory */ - - screendata = txt_get_screen_data(); - - indent = (ENDOOM_W - TXT_SCREEN_W) / 2; - - for (y = 0; y < TXT_SCREEN_H; ++y) - { - memcpy(screendata + (y * TXT_SCREEN_W * 2), - endoom_data + (y * ENDOOM_W + indent) * 2, TXT_SCREEN_W * 2); - } - - /* Wait for a keypress */ - - while (true) - { - txt_update_screen(); - - if (txt_getchar() > 0) - { - break; - } - - txt_sleep(0); - } - - /* Shut down text mode screen */ - - txt_shutdown(); -} diff --git a/games/NXDoom/src/i_endoom.h b/games/NXDoom/src/i_endoom.h deleted file mode 100644 index 22a773dc4..000000000 --- a/games/NXDoom/src/i_endoom.h +++ /dev/null @@ -1,40 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/i_endoom.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Exit text-mode ENDOOM screen. - * - ****************************************************************************/ - -#ifndef __I_ENDOOM__ -#define __I_ENDOOM__ - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -#ifdef CONFIG_GAMES_NXDOOM_ENDOOM - -/* Display the Endoom screen on shutdown. Pass a pointer to the - * ENDOOM lump. - */ - -void i_endoom(byte *data); -#endif - -#endif /* __I_ENDOOM__ */ diff --git a/games/NXDoom/src/i_glob.c b/games/NXDoom/src/i_glob.c deleted file mode 100644 index c60158937..000000000 --- a/games/NXDoom/src/i_glob.c +++ /dev/null @@ -1,397 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/i_glob.c - * - * SPDX-License-Identifier: GPLv2 - * - * Copyright(C) 2018 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * - * File globbing API. This allows the contents of the filesystem - * to be interrogated. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include - -#include "config.h" -#include "i_glob.h" -#include "m_misc.h" - -#include - -#include -#include - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -struct glob_s -{ - char **globs; - int num_globs; - int flags; - DIR *dir; - char *directory; - char *last_filename; - - /* These fields are only used when the GLOB_FLAG_SORTED flag is set: - */ - - char **filenames; - int filenames_len; - int next_index; -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/* Only the fields d_name and (as an XSI extension) d_ino are specified - * in POSIX.1. Other than Linux, the d_type field is available mainly - * only on BSD systems. The remaining fields are available on many, but - * not all systems. - */ - -static boolean is_directory(char *dir, struct dirent *de) -{ -#if defined(_DIRENT_HAVE_D_TYPE) - if (de->d_type != DT_UNKNOWN && de->d_type != DT_LNK) - { - return de->d_type == DT_DIR; - } - else -#endif - { - char *filename; - struct stat sb; - int result; - - filename = m_string_join(dir, DIR_SEPARATOR_S, de->d_name, NULL); - result = stat(filename, &sb); - free(filename); - - if (result != 0) - { - return false; - } - - return S_ISDIR(sb.st_mode); - } -} - -static void free_string_list(char **globs, int num_globs) -{ - int i; - for (i = 0; i < num_globs; ++i) - { - free(globs[i]); - } - - free(globs); -} - -static boolean matches_glob(const char *name, const char *glob, int flags) -{ - int n; - int g; - - while (*glob != '\0') - { - n = *name; - g = *glob; - - if ((flags & GLOB_FLAG_NOCASE) != 0) - { - n = tolower(n); - g = tolower(g); - } - - if (g == '*') - { - /* To handle *-matching we skip past the * and recurse - * to check each subsequent character in turn. If none - * match then the whole match is a failure. - */ - - while (*name != '\0') - { - if (matches_glob(name, glob + 1, flags)) - { - return true; - } - - ++name; - } - - return glob[1] == '\0'; - } - else if (g != '?' && n != g) - { - /* For normal characters the name must match the glob, - * but for ? we don't care what the character is. - */ - - return false; - } - - ++name; - ++glob; - } - - /* Match successful when glob and name end at the same time. */ - - return *name == '\0'; -} - -static boolean matches_any_glob(const char *name, glob_t *glob) -{ - int i; - - for (i = 0; i < glob->num_globs; ++i) - { - if (matches_glob(name, glob->globs[i], glob->flags)) - { - return true; - } - } - - return false; -} - -static char *next_glob(glob_t *glob) -{ - struct dirent *de; - - do - { - de = readdir(glob->dir); - if (de == NULL) - { - return NULL; - } - } - while (is_directory(glob->directory, de) || - !matches_any_glob(de->d_name, glob)); - - /* Return the fully-qualified path, not just the bare filename. */ - - return m_string_join(glob->directory, DIR_SEPARATOR_S, de->d_name, NULL); -} - -static void read_all_filenames(glob_t *glob) -{ - char *name; - - glob->filenames = NULL; - glob->filenames_len = 0; - glob->next_index = 0; - - for (; ; ) - { - name = next_glob(glob); - if (name == NULL) - { - break; - } - - glob->filenames = realloc(glob->filenames, - (glob->filenames_len + 1) * sizeof(char *)); - glob->filenames[glob->filenames_len] = name; - ++glob->filenames_len; - } -} - -static void sort_filenames(char **filenames, int len, int flags) -{ - char *pivot; - char *tmp; - int i; - int left_len; - int cmp; - - if (len <= 1) - { - return; - } - - pivot = filenames[len - 1]; - left_len = 0; - for (i = 0; i < len - 1; ++i) - { - if ((flags & GLOB_FLAG_NOCASE) != 0) - { - cmp = strcasecmp(filenames[i], pivot); - } - else - { - cmp = strcmp(filenames[i], pivot); - } - - if (cmp < 0) - { - tmp = filenames[i]; - filenames[i] = filenames[left_len]; - filenames[left_len] = tmp; - ++left_len; - } - } - - filenames[len - 1] = filenames[left_len]; - filenames[left_len] = pivot; - - sort_filenames(filenames, left_len, flags); - sort_filenames(&filenames[left_len + 1], len - left_len - 1, flags); -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -glob_t *i_start_multi_glob(const char *directory, int flags, - const char *glob, ...) -{ - char **globs; - int num_globs; - glob_t *result; - va_list args; - - globs = malloc(sizeof(char *)); - if (globs == NULL) - { - return NULL; - } - - globs[0] = m_string_duplicate(glob); - num_globs = 1; - - va_start(args, glob); - for (; ; ) - { - const char *arg = va_arg(args, const char *); - char **new_globs; - - if (arg == NULL) - { - break; - } - - new_globs = realloc(globs, sizeof(char *) * (num_globs + 1)); - if (new_globs == NULL) - { - free_string_list(globs, num_globs); - } - - globs = new_globs; - globs[num_globs] = m_string_duplicate(arg); - ++num_globs; - } - - va_end(args); - - result = malloc(sizeof(glob_t)); - if (result == NULL) - { - free_string_list(globs, num_globs); - return NULL; - } - - result->dir = opendir(directory); - if (result->dir == NULL) - { - free_string_list(globs, num_globs); - free(result); - return NULL; - } - - result->directory = m_string_duplicate(directory); - result->globs = globs; - result->num_globs = num_globs; - result->flags = flags; - result->last_filename = NULL; - result->filenames = NULL; - result->filenames_len = 0; - result->next_index = -1; - return result; -} - -glob_t *i_start_glob(const char *directory, const char *glob, int flags) -{ - return i_start_multi_glob(directory, flags, glob, NULL); -} - -void i_end_glob(glob_t *glob) -{ - if (glob == NULL) - { - return; - } - - free_string_list(glob->globs, glob->num_globs); - free_string_list(glob->filenames, glob->filenames_len); - - free(glob->directory); - free(glob->last_filename); - (void)closedir(glob->dir); - free(glob); -} - -const char *i_next_glob(glob_t *glob) -{ - const char *result; - - if (glob == NULL) - { - return NULL; - } - - /* In unsorted mode we just return the filenames as we read - * them back from the system API. - */ - - if ((glob->flags & GLOB_FLAG_SORTED) == 0) - { - free(glob->last_filename); - glob->last_filename = next_glob(glob); - return glob->last_filename; - } - - /* In sorted mode we read the whole list of filenames into memory, - * sort them and return them one at a time. - */ - - if (glob->next_index < 0) - { - read_all_filenames(glob); - sort_filenames(glob->filenames, glob->filenames_len, glob->flags); - } - - if (glob->next_index >= glob->filenames_len) - { - return NULL; - } - - result = glob->filenames[glob->next_index]; - ++glob->next_index; - return result; -} diff --git a/games/NXDoom/src/i_glob.h b/games/NXDoom/src/i_glob.h deleted file mode 100644 index a151795ad..000000000 --- a/games/NXDoom/src/i_glob.h +++ /dev/null @@ -1,87 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/i_glob.h - * - * SPDX-License-Identifier: GPLv2 - * - * Copyright(C) 2018 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * System specific file globbing interface. - * - ****************************************************************************/ - -#ifndef __I_GLOB__ -#define __I_GLOB__ - -/**************************************************************************** - * Preprocessor Definitions - ****************************************************************************/ - -#define GLOB_FLAG_NOCASE 0x01 -#define GLOB_FLAG_SORTED 0x02 - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -typedef struct glob_s glob_t; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Name: i_start_glob - * - * Description: - * Start reading a list of file paths from the given directory which match - * the given glob pattern. i_end_glob() must be called on completion. - * - ****************************************************************************/ - -glob_t *i_start_glob(const char *directory, const char *glob, int flags); - -/**************************************************************************** - * Name: i_start_multi_glob - * - * Description: - * Same as i_start_glob but multiple glob patterns can be provided. The list - * of patterns must be terminated with NULL. - * - ****************************************************************************/ - -glob_t *i_start_multi_glob(const char *directory, int flags, - const char *glob, ...); - -/**************************************************************************** - * Name: i_end_glob - * - * Description: - * Finish reading file list. - * - ****************************************************************************/ - -void i_end_glob(glob_t *glob); - -/**************************************************************************** - * Name: i_next_glob - * - * Description: - * Read the name of the next globbed filename. NULL is returned if there - * are no more found. - * - ****************************************************************************/ - -const char *i_next_glob(glob_t *glob); - -#endif /* __I_GLOB__ */ diff --git a/games/NXDoom/src/i_input.c b/games/NXDoom/src/i_input.c deleted file mode 100644 index 8cb3a8630..000000000 --- a/games/NXDoom/src/i_input.c +++ /dev/null @@ -1,402 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/i_input.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * SDL implementation of system-specific input interface. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include -#include - -#ifdef CONFIG_GAMES_NXDOOM_KEYBOARD -#include -#endif - -#include "d_event.h" -#include "doomkeys.h" -#include "doomtype.h" -#include "i_input.h" -#include "m_argv.h" -#include "m_config.h" - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -struct keyboard_dev -{ - int fd; - bool inited; -}; - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -#ifdef CONFIG_GAMES_NXDOOM_KEYBOARD -struct keyboard_dev g_kbd_dev = -{ - .fd = -1, - .inited = false, -}; -#endif - -#if 0 -static const int g_scancode_translate_table[] = SCANCODE_TO_KEYS_ARRAY; - -/* Lookup table for mapping ASCII characters to their equivalent when - * shift is pressed on a US layout keyboard. This is the original table - * as found in the Doom sources, comments and all. - */ - -static const char shiftxform[] = -{ - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, - 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, - 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, - 31, ' ', '!', '"', '#', '$', '%', '&', - '"', /* shift-' */ - '(', ')', '*', '+', - '<', /* shift-, */ - '_', /* shift-- */ - '>', /* shift-. */ - '?', /* shift-/ */ - ')', /* shift-0 */ - '!', /* shift-1 */ - '@', /* shift-2 */ - '#', /* shift-3 */ - '$', /* shift-4 */ - '%', /* shift-5 */ - '^', /* shift-6 */ - '&', /* shift-7 */ - '*', /* shift-8 */ - '(', /* shift-9 */ - ':', - ':', /* shift-; */ - '<', - '+', /* shift-= */ - '>', '?', '@', - 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', - 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', - '[', /* shift-[ */ - '!', /* shift-backslash - OH MY GOD DOES WATCOM SUCK */ - ']', /* shift-] */ - '"', '_', - '\'', /* shift-` */ - 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', - 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', - '{', '|', '}', '~', 127 -}; - -/* If true, i_start_text_input() has been called, and we are populating - * the data3 field of ev_keydown events. - */ - -static boolean text_input_enabled = true; - -/* Bit mask of mouse button state. */ - -static unsigned int mouse_button_state = 0; -#endif - -/* Disallow mouse and joystick movement to cause forward/backward - * motion. Specified with the '-novert' command line parameter. - * This is an int to allow saving to config file - */ - -int novert = 0; - -/* If true, keyboard mapping is ignored, like in Vanilla Doom. - * The sensible thing to do is to disable this if you have a non-US - * keyboard. - */ - -int vanilla_keyboard_mapping = true; - -/* Mouse acceleration - * - * This emulates some of the behavior of DOS mouse drivers by increasing - * the speed when the mouse is moved fast. - * - * The mouse input values are input directly to the game, but when - * the values exceed the value of mouse_threshold, they are multiplied - * by mouse_acceleration to increase the speed. - */ - -float mouse_acceleration = 2.0; -int mouse_threshold = 10; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: init_kbd_dev - * - * Description: - * Set up the keyboard device for getting keyboard events. - * - * Return: - * 0 on success, error code otherwise. - * - ****************************************************************************/ - -static int init_kbd_dev(struct keyboard_dev *dev) -{ - if (dev->inited) - { - return 0; - } - - dev->fd = open(CONFIG_GAMES_NXDOOM_KBDPATH, O_RDONLY | O_NONBLOCK); - if (dev->fd < 0) - { - return errno; - } - - dev->inited = true; - return 0; -} - -/**************************************************************************** - * Name: translate_key - * - * Description: - * Translates a NuttX key code into one from doomkeys.h. - * - * Return: - * The translated key code. - * - ****************************************************************************/ - -static int translate_key(uint32_t keycode) -{ - switch (keycode) - { - case KEYCODE_LEFT: - return KEY_LEFTARROW; - case KEYCODE_RIGHT: - return KEY_RIGHTARROW; - case KEYCODE_UP: - return KEY_UPARROW; - case KEYCODE_DOWN: - return KEY_DOWNARROW; - case KEYCODE_ENTER: - return KEY_ENTER; - default: - return keycode; - } -} - -/**************************************************************************** - * Name: get_localized_key - * - * Description: - * Get the localized version of the key press. This takes into account the - * keyboard layout, but does not apply any changes due to modifiers, (eg. - * shift-, alt-, etc.) - * - ****************************************************************************/ - -static int get_localized_key(uint32_t sym) -{ - /* NOTE: Argument was SDL_Keysym *sym */ - - /* When using Vanilla mapping, we just base everything off the scancode - * and always pretend the user is using a US layout keyboard. - */ - - if (vanilla_keyboard_mapping) - { - return translate_key(sym); - } - else - { - int result = sym; - - if (result < 0 || result >= 128) - { - result = 0; - } - - return result; - } -} - -/**************************************************************************** - * Name: get_typed_char - * - * Description: - * Get the equivalent ASCII (Unicode?) character for a keypress. - * - ****************************************************************************/ - -static int get_typed_char(uint32_t sym) -{ - return 0; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -#ifdef CONFIG_GAMES_NXDOOM_KEYBOARD - -/**************************************************************************** - * Name: get_kbd_event - * - * Description: - * Read a single keyboard event from the keyboard device. - * - * Return: - * 0 on success, error code otherwise. - * - ****************************************************************************/ - -int get_kbd_event(struct keyboard_event_s *sample) -{ - int err; - ssize_t nbytes; - - /* Initialize the keyboard device if it isn't already */ - - err = init_kbd_dev(&g_kbd_dev); - if (err) - { - return err; - } - - /* Read events until we're out of them */ - - nbytes = read(g_kbd_dev.fd, sample, sizeof(*sample)); - if (nbytes < 0) - { - err = errno; - if (err != EINTR) - { - return err; - } - } - else if (nbytes != sizeof(*sample)) - { - return EIO; - } - else if (nbytes == 0) - { - return EAGAIN; /* No event */ - } - - return 0; -} -#endif - -void i_handle_keyboard_event(struct keyboard_event_s *kevent) -{ - /* XXX: passing pointers to event for access after this function - * has terminated is undefined behaviour - */ - - event_t event; - - switch (kevent->type) - { - case KEYBOARD_PRESS: - event.type = ev_keydown; - event.data1 = translate_key(kevent->code); - event.data2 = get_localized_key(kevent->code); - event.data3 = get_typed_char(kevent->code); - - if (event.data1 != 0) - { - d_post_event(&event); - } - break; - - case KEYBOARD_RELEASE: - event.type = ev_keyup; - event.data1 = translate_key(kevent->code); - - /* data2/data3 are initialized to zero for ev_keyup. - * For ev_keydown it's the shifted Unicode character - * that was typed, but if something wants to detect - * key releases it should do so based on data1 - * (key ID), not the printable char. - */ - - event.data2 = 0; - event.data3 = 0; - - if (event.data1 != 0) - { - d_post_event(&event); - } - break; - - default: - break; - } -} - -void i_start_text_input(int x1, int y1, int x2, int y2) -{ -} - -void i_stop_text_input(void) -{ -} - -void i_handle_mouse_event(void) -{ - /* Argument was SDL_Event *sdlevent */ -} - -/**************************************************************************** - * Name: i_read_mouse - * - * Description: - * Read the change in mouse state to generate mouse motion events. This is - * to combine all mouse movement for a tic into one mouse motion event. - * - ****************************************************************************/ - -void i_read_mouse(void) -{ -} - -/**************************************************************************** - * Name: i_bind_input_variables - * - * Description: - * Bind all variables controlling input options. - * - ****************************************************************************/ - -void i_bind_input_variables(void) -{ - m_bind_float_variable("mouse_acceleration", &mouse_acceleration); - m_bind_int_variable("mouse_threshold", &mouse_threshold); - m_bind_int_variable("vanilla_keyboard_mapping", &vanilla_keyboard_mapping); - m_bind_int_variable("novert", &novert); -} diff --git a/games/NXDoom/src/i_input.h b/games/NXDoom/src/i_input.h deleted file mode 100644 index 97fc81bf7..000000000 --- a/games/NXDoom/src/i_input.h +++ /dev/null @@ -1,77 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/i_input.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * System-specific keyboard/mouse input. - * - ****************************************************************************/ - -#ifndef __I_INPUT__ -#define __I_INPUT__ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "doomtype.h" - -#ifdef CONFIG_GAMES_NXDOOM_KEYBOARD -#include -#endif - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define MAX_MOUSE_BUTTONS 8 - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -extern float mouse_acceleration; -extern int mouse_threshold; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -void i_bind_input_variables(void); -void i_read_mouse(void); - -/* i_start_text_input begins text input, activating the on-screen keyboard - * (if one is used). The caller indicates that any entered text will be - * displayed in the rectangle given by the provided set of coordinates. - */ - -void i_start_text_input(int x1, int y1, int x2, int y2); - -/* i_stop_text_input finishes text input, deactivating the on-screen keyboard - * (if one is used). - */ - -void i_stop_text_input(void); - -void i_handle_keyboard_event(struct keyboard_event_s *kevent); -void i_handle_mouse_event(void); - -#ifdef CONFIG_GAMES_NXDOOM_KEYBOARD -int get_kbd_event(struct keyboard_event_s *sample); -#endif - -#endif /* __I_INPUT__ */ diff --git a/games/NXDoom/src/i_joystick.c b/games/NXDoom/src/i_joystick.c deleted file mode 100644 index 4ae0b3a32..000000000 --- a/games/NXDoom/src/i_joystick.c +++ /dev/null @@ -1,181 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/i_joystick.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * SDL Joystick code. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include - -#include "d_event.h" -#include "doomtype.h" -#include "i_joystick.h" -#include "i_system.h" - -#include "m_config.h" -#include "m_fixed.h" -#include "m_misc.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define DIRECTION_DEADZONE (50 * 32768 / 100) - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/* Configuration variables: */ - -/* Standard default.cfg Joystick enable/disable */ - -static int usejoystick = 0; - -/* Use SDL_gamecontroller interface for the selected device */ - -static int use_gamepad = 0; - -/* SDL_GameControllerType of gamepad */ - -static int gamepad_type = 0; - -/* SDL GUID and index of the joystick to use. */ - -static char *joystick_guid = ""; -static int joystick_index = -1; - -/* Which joystick axis to use for horizontal movement, and whether to - * invert the direction: - */ - -static int joystick_x_axis = 0; -static int joystick_x_invert = 0; - -/* Which joystick axis to use for vertical movement, and whether to - * invert the direction: - */ - -static int joystick_y_axis = 1; -static int joystick_y_invert = 0; - -/* Which joystick axis to use for strafing? */ - -static int joystick_strafe_axis = -1; -static int joystick_strafe_invert = 0; - -/* Which joystick axis to use for looking? */ - -static int joystick_look_axis = -1; -static int joystick_look_invert = 0; - -/* Configurable dead zone for each axis, specified as a percentage of the - * axis max value. - */ - -static int joystick_x_dead_zone = 33; -static int joystick_y_dead_zone = 33; -static int joystick_strafe_dead_zone = 33; -static int joystick_look_dead_zone = 33; - -/* Virtual to physical button joystick button mapping. By default this - * is a straight mapping. - */ - -static int joystick_physical_buttons[NUM_VIRTUAL_BUTTONS] = -{ - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 -}; - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -int use_analog = 0; - -int joystick_turn_sensitivity = 10; -int joystick_move_sensitivity = 10; -int joystick_look_sensitivity = 10; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -void i_init_joystick(void) -{ -} - -void i_update_gamepad(void) -{ -} - -void i_shutdown_joystick(void) -{ -} - -void i_update_joystick(void) -{ -} - -void i_bind_joystick_variables(void) -{ - int i; - - m_bind_int_variable("use_joystick", &usejoystick); - m_bind_int_variable("use_gamepad", &use_gamepad); - m_bind_int_variable("gamepad_type", &gamepad_type); - m_bind_string_variable("joystick_guid", &joystick_guid); - m_bind_int_variable("joystick_index", &joystick_index); - m_bind_int_variable("joystick_x_axis", &joystick_x_axis); - m_bind_int_variable("joystick_y_axis", &joystick_y_axis); - m_bind_int_variable("joystick_strafe_axis", &joystick_strafe_axis); - m_bind_int_variable("joystick_x_invert", &joystick_x_invert); - m_bind_int_variable("joystick_y_invert", &joystick_y_invert); - m_bind_int_variable("joystick_strafe_invert", &joystick_strafe_invert); - m_bind_int_variable("joystick_look_axis", &joystick_look_axis); - m_bind_int_variable("joystick_look_invert", &joystick_look_invert); - m_bind_int_variable("joystick_x_dead_zone", &joystick_x_dead_zone); - m_bind_int_variable("joystick_y_dead_zone", &joystick_y_dead_zone); - m_bind_int_variable("joystick_strafe_dead_zone", - &joystick_strafe_dead_zone); - m_bind_int_variable("joystick_look_dead_zone", &joystick_look_dead_zone); - m_bind_int_variable("use_analog", &use_analog); - m_bind_int_variable("joystick_turn_sensitivity", - &joystick_turn_sensitivity); - m_bind_int_variable("joystick_move_sensitivity", - &joystick_move_sensitivity); - m_bind_int_variable("joystick_look_sensitivity", - &joystick_look_sensitivity); - - for (i = 0; i < NUM_VIRTUAL_BUTTONS; ++i) - { - char name[32]; - snprintf(name, sizeof(name), "joystick_physical_button%i", i); - m_bind_int_variable(name, &joystick_physical_buttons[i]); - } -} diff --git a/games/NXDoom/src/i_joystick.h b/games/NXDoom/src/i_joystick.h deleted file mode 100644 index 6c1ff3df5..000000000 --- a/games/NXDoom/src/i_joystick.h +++ /dev/null @@ -1,152 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/i_joystick.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * System-specific joystick interface. - * - ****************************************************************************/ - -#ifndef __I_JOYSTICK__ -#define __I_JOYSTICK__ - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* Number of "virtual" joystick buttons defined in configuration files. - * This needs to be at least as large as the number of different key - * bindings supported by the higher-level game code (joyb* variables). - */ - -#define NUM_VIRTUAL_BUTTONS 17 - -/* Max allowed number of virtual mappings. Chosen to be less than joybspeed - * autorun value. - */ - -#define MAX_VIRTUAL_BUTTONS 20 - -/* If this bit is set in a configuration file axis value, the axis is - * not actually a joystick axis, but instead is a "button axis". This - * means that instead of reading an SDL joystick axis, we read the - * state of two buttons to get the axis value. This is needed for eg. - * the PS3 SIXAXIS controller, where the D-pad buttons register as - * buttons, not as two axes. - */ - -#define BUTTON_AXIS 0x10000 - -/* Query whether a given axis value describes a button axis. */ - -#define IS_BUTTON_AXIS(axis) ((axis) >= 0 && ((axis) & BUTTON_AXIS) != 0) - -/* Get the individual buttons from a button axis value. */ - -#define BUTTON_AXIS_NEG(axis) ((axis) & 0xff) -#define BUTTON_AXIS_POS(axis) (((axis) >> 8) & 0xff) - -/* Create a button axis value from two button values. */ - -#define CREATE_BUTTON_AXIS(neg, pos) (BUTTON_AXIS | (neg) | ((pos) << 8)) - -/* If this bit is set in an axis value, the axis is not actually a - * joystick axis, but is a "hat" axis. This means that we read (one of) - * the hats on the joystick. - */ - -#define HAT_AXIS 0x20000 - -#define IS_HAT_AXIS(axis) ((axis) >= 0 && ((axis) & HAT_AXIS) != 0) - -/* Get the hat number from a hat axis value. */ - -#define HAT_AXIS_HAT(axis) ((axis) & 0xff) - -/* Which axis of the hat? (horizontal or vertical) */ - -#define HAT_AXIS_DIRECTION(axis) (((axis) >> 8) & 0xff) - -#define CREATE_HAT_AXIS(hat, direction) \ - (HAT_AXIS | (hat) | ((direction) << 8)) - -#define HAT_AXIS_HORIZONTAL 1 -#define HAT_AXIS_VERTICAL 2 - -/* When a trigger reads greater than this, consider it to be pressed. 30 - * comes from XINPUT_GAMEPAD_TRIGGER_THRESHOLD in xinput.h, and is scaled - * here for the SDL_GameController trigger max value. - */ - -#define TRIGGER_THRESHOLD (30 * 32767 / 255) - -/* To be used with SDL_JoystickGetGUIDString; see SDL_joystick.h */ - -#define GUID_STRING_BUF_SIZE 33 - -/* Helper macros for bitpacked directional data from gamepad inputs. */ - -#define DPAD_SHIFT 0 -#define LSTICK_SHIFT 4 -#define RSTICK_SHIFT 8 -#define JOY_GET_DPAD(x) (((x) >> DPAD_SHIFT) & 0xf) -#define JOY_GET_LSTICK(x) (((x) >> LSTICK_SHIFT) & 0xf) -#define JOY_GET_RSTICK(x) (((x) >> RSTICK_SHIFT) & 0xf) - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -/* 4-way direction data for gamepad directional inputs. */ - -enum -{ - JOY_DIR_NONE = 0x0, - JOY_DIR_UP = 0x1, - JOY_DIR_DOWN = 0x2, - JOY_DIR_LEFT = 0x4, - JOY_DIR_RIGHT = 0x8 -}; - -/* Extend the SDL_GameControllerButton enum to include the triggers. */ - -enum -{ - GAMEPAD_BUTTON_TRIGGERLEFT, /* = SDL_CONTROLLER_BUTTON_MAX, */ - GAMEPAD_BUTTON_TRIGGERRIGHT, - GAMEPAD_BUTTON_MAX -}; - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -extern int use_analog; -extern int joystick_turn_sensitivity; -extern int joystick_move_sensitivity; -extern int joystick_look_sensitivity; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -void i_init_joystick(void); -void i_shutdown_joystick(void); -void i_update_joystick(void); - -void i_bind_joystick_variables(void); - -#endif /* __I_JOYSTICK__ */ diff --git a/games/NXDoom/src/i_main.c b/games/NXDoom/src/i_main.c deleted file mode 100644 index bd9dab609..000000000 --- a/games/NXDoom/src/i_main.c +++ /dev/null @@ -1,87 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/i_main.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Main program, simply calls d_doom_main high level loop. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "config.h" - -#include -#include -#include - -#include "doomtype.h" -#include "i_system.h" -#include "m_argv.h" -#include "m_misc.h" - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Name: d_doom_main() - * - * Description: - * Not a globally visible function, just included for source reference, - * calls all startup code, parses command line options. - * - ****************************************************************************/ - -void d_doom_main(void); - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -int main(int argc, char **argv) -{ - /* save arguments */ - - myargc = argc; - myargv = malloc(argc * sizeof(char *)); - assert(myargv != NULL); - - for (int i = 0; i < argc; i++) - { - myargv[i] = m_string_duplicate(argv[i]); - } - - /* Print the program version and exit. */ - - if (m_parm_exists("-version") || m_parm_exists("--version")) - { - puts(PACKAGE_STRING); - exit(0); - } - - m_find_response_file(); - m_set_exe_dir(); - - /* start doom */ - - d_doom_main(); - - return 0; -} diff --git a/games/NXDoom/src/i_musicpack.c b/games/NXDoom/src/i_musicpack.c deleted file mode 100644 index 733a45c7c..000000000 --- a/games/NXDoom/src/i_musicpack.c +++ /dev/null @@ -1,152 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/i_musicpack.c - * - * SPDX-License-Identifier: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * System interface for music. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include -#include - -#include "i_glob.h" - -#include "config.h" -#include "doomtype.h" -#include "memio.h" -#include "mus2mid.h" - -#include "deh_str.h" -#include "gusconf.h" -#include "i_sound.h" -#include "i_swap.h" -#include "i_system.h" -#include "m_argv.h" -#include "m_config.h" -#include "m_misc.h" -#include "sha1.h" -#include "w_wad.h" -#include "z_zone.h" - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -static boolean i_null_init_music(void); -static void i_null_shutdown_music(void); -static void i_null_set_music_volume(int volume); -static void i_null_pause_song(void); -static void i_null_resume_song(void); -static void *i_null_register_song(void *data, int len); -static void i_null_unregister_song(void *handle); -static void i_null_play_song(void *handle, boolean looping); -static void i_null_stop_song(void); -static boolean i_null_musicisplaying(void); -static void i_null_pollmusic(void); - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -char *music_pack_path = ""; - -const music_module_t music_pack_module = -{ - NULL, - 0, - i_null_init_music, - i_null_shutdown_music, - i_null_set_music_volume, - i_null_pause_song, - i_null_resume_song, - i_null_register_song, - i_null_unregister_song, - i_null_play_song, - i_null_stop_song, - i_null_musicisplaying, - i_null_pollmusic, -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static boolean i_null_init_music(void) -{ - return false; -} - -static void i_null_shutdown_music(void) -{ - return; -} - -static void i_null_set_music_volume(int volume) -{ - return; -} - -static void i_null_pause_song(void) -{ - return; -} - -static void i_null_resume_song(void) -{ - return; -} - -static void *i_null_register_song(void *data, int len) -{ - return NULL; -} - -static void i_null_unregister_song(void *handle) -{ - return; -} - -static void i_null_play_song(void *handle, boolean looping) -{ - return; -} - -static void i_null_stop_song(void) -{ - return; -} - -static boolean i_null_musicisplaying(void) -{ - return false; -} - -static void i_null_pollmusic(void) -{ - return; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ diff --git a/games/NXDoom/src/i_pcsound.c b/games/NXDoom/src/i_pcsound.c deleted file mode 100644 index b6251c0e2..000000000 --- a/games/NXDoom/src/i_pcsound.c +++ /dev/null @@ -1,256 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/i_pcsound.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * System interface for PC speaker sound. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include "doomtype.h" - -#include "deh_str.h" -#include "i_sound.h" -#include "m_misc.h" -#include "w_wad.h" -#include "z_zone.h" - -#include "pcsound.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define TIMER_FREQ 1193181 /* Hz */ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -static int i_pcs_start_sound(sfxinfo_t *sfxinfo, int channel, int vol, - int sep, int pitch); -static void i_pcs_stop_sound(int handle); -static int i_pcs_get_sfx_lumpnum(sfxinfo_t *sfx); -static boolean i_pcs_sound_is_playing(int handle); -static boolean i_pcs_init_sound(gamemission_t mission); -static void i_pcs_shutdown_sound(void); -static void i_pcs_update_sound(void); -static void i_pcs_update_sound_params(int channel, int vol, int sep); - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static boolean g_pcs_initialized = false; - -static gamemission_t g_gamemission; - -static uint8_t *g_current_sound_lump = NULL; -#if 0 /* UNUSED */ -static uint8_t *g_current_sound_pos = NULL; -#endif -static unsigned int g_current_sound_remaining = 0; -static int g_current_sound_handle = 0; -#if 0 /* UNUSED */ -static int g_current_sound_lump_num = -1; - -static const uint16_t g_divisors[] = -{ - 0, 6818, 6628, 6449, 6279, 6087, 5906, 5736, 5575, 5423, 5279, 5120, - 4971, 4830, 4697, 4554, 4435, 4307, 4186, 4058, 3950, 3836, 3728, 3615, - 3519, 3418, 3323, 3224, 3131, 3043, 2960, 2875, 2794, 2711, 2633, 2560, - 2485, 2415, 2348, 2281, 2213, 2153, 2089, 2032, 1975, 1918, 1864, 1810, - 1757, 1709, 1659, 1612, 1565, 1521, 1478, 1435, 1395, 1355, 1316, 1280, - 1242, 1207, 1173, 1140, 1107, 1075, 1045, 1015, 986, 959, 931, 905, - 879, 854, 829, 806, 783, 760, 739, 718, 697, 677, 658, 640, - 621, 604, 586, 570, 553, 538, 522, 507, 493, 479, 465, 452, - 439, 427, 415, 403, 391, 380, 369, 359, 348, 339, 329, 319, - 310, 302, 293, 285, 276, 269, 261, 253, 246, 239, 232, 226, - 219, 213, 207, 201, 195, 190, 184, 179, -}; -#endif - -static const snddevice_t g_sound_pcsound_devices[] = -{ - SNDDEVICE_PCSPEAKER, -}; - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -const sound_module_t sound_pcsound_module = -{ - .sound_devices = g_sound_pcsound_devices, - .num_sound_devices = arrlen(g_sound_pcsound_devices), - .init = i_pcs_init_sound, - .shutdown = i_pcs_shutdown_sound, - .get_sfx_lumpnum = i_pcs_get_sfx_lumpnum, - .update = i_pcs_update_sound, - .update_sound_params = i_pcs_update_sound_params, - .start_sound = i_pcs_start_sound, - .stop_sound = i_pcs_stop_sound, - .sound_is_playing = i_pcs_sound_is_playing, -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -#if 0 /* UNUSED */ -static void pcs_callback_func(int *duration, int *freq) -{ -} - -static boolean cache_pcs_lump(sfxinfo_t *sfxinfo) -{ - int lumplen; - int headerlen; - - /* Free the current sound lump back to the cache */ - - if (g_current_sound_lump != NULL) - { - w_release_lump_num(g_current_sound_lump_num); - g_current_sound_lump = NULL; - } - - /* Load from WAD */ - - g_current_sound_lump = w_cache_lump_num(sfxinfo->lumpnum, PU_STATIC); - lumplen = w_lump_length(sfxinfo->lumpnum); - - /* Read header */ - - if (g_current_sound_lump[0] != 0x00 || g_current_sound_lump[1] != 0x00) - { - return false; - } - - headerlen = (g_current_sound_lump[3] << 8) | g_current_sound_lump[2]; - - if (headerlen > lumplen - 4) - { - return false; - } - - /* Header checks out ok */ - - g_current_sound_remaining = headerlen; - g_current_sound_pos = g_current_sound_lump + 4; - g_current_sound_lump_num = sfxinfo->lumpnum; - - return true; -} - -/* These Doom PC speaker sounds are not played - this can be seen in the - * Heretic source code, where there are remnants of this left over - * from Doom. - */ - -static boolean is_disabled_sound(sfxinfo_t *sfxinfo) -{ - int i; - const char *disabled_sounds[] = { - "posact", "bgact", "dmact", "dmpain", "popain", "sawidl", "rifle", - }; - - for (i = 0; i < arrlen(disabled_sounds); ++i) - { - if (!strcmp(sfxinfo->name, disabled_sounds[i])) - { - return true; - } - } - - return false; -} -#endif /* UNUSED */ - -static int i_pcs_start_sound(sfxinfo_t *sfxinfo, int channel, int vol, - int sep, int pitch) -{ - return 0; -} - -static void i_pcs_stop_sound(int handle) -{ -} - -/* Retrieve the raw data lump index for a given SFX name. */ - -static int i_pcs_get_sfx_lumpnum(sfxinfo_t *sfx) -{ - char namebuf[16]; - - if (g_gamemission == doom || g_gamemission == strife) - { - snprintf(namebuf, sizeof(namebuf), "dp%s", (sfx->name)); - - if (g_gamemission == strife && w_check_num_for_name(namebuf) == -1) - { - /* Missing sounds replaced with DPRIFLE. */ - - snprintf(namebuf, sizeof(namebuf), "dp%s", ("rifle")); - } - } - else - { - m_str_copy(namebuf, (sfx->name), sizeof(namebuf)); - } - - return w_get_num_for_name(namebuf); -} - -static boolean i_pcs_sound_is_playing(int handle) -{ - if (!g_pcs_initialized) - { - return false; - } - - if (handle != g_current_sound_handle) - { - return false; - } - - return g_current_sound_lump != NULL && g_current_sound_remaining > 0; -} - -static boolean i_pcs_init_sound(gamemission_t mission) -{ - return false; -} - -static void i_pcs_shutdown_sound(void) -{ -} - -static void i_pcs_update_sound(void) -{ - /* no-op. */ -} - -static void i_pcs_update_sound_params(int channel, int vol, int sep) -{ - /* no-op. */ -} diff --git a/games/NXDoom/src/i_rtttl_music.c b/games/NXDoom/src/i_rtttl_music.c deleted file mode 100644 index 78dd7122c..000000000 --- a/games/NXDoom/src/i_rtttl_music.c +++ /dev/null @@ -1,522 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/i_rtttl_music.c - * - * SPDX-License-Identifier: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * System interface for music. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "i_glob.h" - -#include "config.h" -#include "doomtype.h" -#include "memio.h" -#include "mus2mid.h" - -#include "deh_str.h" -#include "gusconf.h" -#include "i_sound.h" -#include "i_swap.h" -#include "i_system.h" -#include "m_argv.h" -#include "m_config.h" -#include "m_misc.h" -#include "sha1.h" -#include "w_wad.h" -#include "z_zone.h" - -#ifdef CONFIG_PWM -#include -#endif - -#include - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -static boolean i_rtttl_init_music(void); -static void i_rtttl_shutdown_music(void); -static void i_rtttl_set_music_volume(int volume); -static void i_rtttl_pause_song(void); -static void i_rtttl_resume_song(void); -static void *i_rtttl_register_song(void *data, int len); -static void i_rtttl_unregister_song(void *handle); -static void i_rtttl_play_song(void *handle, boolean looping); -static void i_rtttl_stop_song(void); -static boolean i_rtttl_musicisplaying(void); -static void i_rtttl_pollmusic(void); - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -const char g_doom_rtttl[] = - "Doom:d=32,o=5,b=56:f,f,f6,f,f,d#6,f,f,c#6,f,f,b,f,f,c6,c#6,f,f,f6,f,f,d#" - "6,f,f,c#6,f,f,8b.,f,f,f6,f,f,d#6,f,f,c#6,f,f,b,f,f,c6,c#6,f,f,f6,f,f,d#" - "6,f,f,c#6,f,f,8b.,a#,a#,a#6,a#,a#,g#6,a#,a#,f#6,a#,a#,e6,a#,a#,f6,f#6,a#" - ",a#,a#6,a#,a#,g#6,a#,a#,f#6,a#,a#,8e6"; - -/* List of sound devices that this sound module is used for. - * It appears in i_sound.c that the default music device is 'SNDDEVICE_SB', - * so I have just put that here. In reality, we may either wish to add an - * additional sound device for RTTL, or put this as something else - * (PCSPEAKER?). I don't know what most of the snddevice_t enum options - * refer to. - */ - -static const snddevice_t g_rtttl_sound_devices[] = -{ - SNDDEVICE_SB, -}; - -/* Player state */ - -static void (*g_player)(struct rtttl_tone); -static int g_fd = -1; -static bool g_playing = false; -static bool g_loop = true; - -/* Player thread state */ - -static pthread_t g_thread; -static pthread_mutex_t g_player_lock; -static pthread_cond_t g_pausecond; -static pthread_cond_t g_playingcond; -static bool g_paused; - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -const music_module_t g_rtttl_music_module = -{ - .sound_devices = g_rtttl_sound_devices, - .num_sound_devices = arrlen(g_rtttl_sound_devices), - .init = i_rtttl_init_music, - .shutdown = i_rtttl_shutdown_music, - .set_music_volume = i_rtttl_set_music_volume, - .pause_music = i_rtttl_pause_song, - .resume_music = i_rtttl_resume_song, - .register_song = i_rtttl_register_song, - .unregister_song = i_rtttl_unregister_song, - .play_song = i_rtttl_play_song, - .stop_song = i_rtttl_stop_song, - .music_is_playing = i_rtttl_musicisplaying, - .poll = i_rtttl_pollmusic, -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: wait_while_paused - * - * Description: - * Wait while the music is paused. - * - ****************************************************************************/ - -static void wait_while_paused(void) -{ - pthread_mutex_lock(&g_player_lock); - - while (g_paused) - { - pthread_cond_wait(&g_pausecond, &g_player_lock); - } - - pthread_mutex_unlock(&g_player_lock); -} - -/**************************************************************************** - * Name: wait_while_stopped - * - * Description: - * Wait until we are told that a song is started (i.e. while song stopped - * and nothing is playing). - * - ****************************************************************************/ - -static void wait_while_stopped(void) -{ - pthread_mutex_lock(&g_player_lock); - - while (!g_playing) - { - pthread_cond_wait(&g_playingcond, &g_player_lock); - } - - pthread_mutex_unlock(&g_player_lock); -} - -/**************************************************************************** - * Name: play_default - * - * Description: - * Default player which does nothing. - * - * Input Parameters: - * sound - The sound to play - * - ****************************************************************************/ - -static void play_default(struct rtttl_tone sound) -{ - wait_while_paused(); - return; -} - -#ifdef CONFIG_PWM - -/**************************************************************************** - * Name: play_pwm - * - * Description: - * RTTTL player for audio sinks using PWM devices - * - * Input Parameters: - * sound - The sound to play - * - ****************************************************************************/ - -static void play_pwm(struct rtttl_tone sound) -{ - int err; - int i; - struct pwm_info_s info; - - wait_while_paused(); /* Wait until unpaused */ - - /* If we are not meant to be playing (i.e. song was stopped), we should - * return from this function. - */ - - if (!g_playing) - { - return; - } - - info.channels[0].channel = 1; - info.channels[0].duty = b16divi(uitoub16(50) - 1, 100); /* 50% duty cycle */ - info.channels[0].cpol = PWM_CPOL_NDEF; /* Default */ - info.channels[0].dcpol = PWM_DCPOL_NDEF; /* Default */ - info.frequency = sound.frequency_100hz / 100; - - /* Copy settings to all channels */ - - for (i = 1; i < CONFIG_PWM_NCHANNELS; i++) - { - info.channels[i] = info.channels[0]; - info.channels[i].channel = i + 1; - } - - err = ioctl(g_fd, PWMIOC_SETCHARACTERISTICS, &info); - if (err < 0) - { - fprintf(stderr, "Failed to set PWM characteristics: %d\n", errno); - return; - } - - err = ioctl(g_fd, PWMIOC_START, 0); - if (err < 0) - { - fprintf(stderr, "Failed to start PWM: %d\n", errno); - return; - } - - usleep(sound.duration_us); /* Wait */ - - err = ioctl(g_fd, PWMIOC_STOP, 0); - if (err < 0) - { - fprintf(stderr, "Failed to stop PWM: %d\n", errno); - } -} -#endif - -static void *player_thread(void *arg) -{ - for (; ; ) - { - /* If there is nothing playing (i.e. song stopped or done), block here - * until the main DOOM player logic tells us it wants to play a song. - */ - - wait_while_stopped(); - - rtttl_play(g_doom_rtttl, g_player); - - /* If we are not meant to loop, then after one play we will indicate - * that we are 'not playing'. This will causes the thread to block. - * Otherwise, this will continue forever. - */ - - if (!g_loop) - { - pthread_mutex_lock(&g_player_lock); - g_playing = false; - g_paused = false; - pthread_mutex_unlock(&g_player_lock); - } - } - - return NULL; -} - -/**************************************************************************** - * Name: i_rtttl_init_music - * - * Description: - * Choose the appropriate player implementation for RTTTl based on the - * configured music device. - * - * Returned Value: - * True on success, false otherwise. - * - ****************************************************************************/ - -static boolean i_rtttl_init_music(void) -{ - int err; - g_player = play_default; -#ifdef CONFIG_PWM - if (strstr(CONFIG_GAMES_NXDOOM_RTTTL_DEVICE, "pwm")) - { - g_player = play_pwm; - } -#endif - - /* Initialize thread state */ - - pthread_mutex_init(&g_player_lock, NULL); - pthread_cond_init(&g_pausecond, NULL); - pthread_cond_init(&g_playingcond, NULL); - g_paused = true; - g_loop = false; - g_playing = false; - - /* Start the music playing thread */ - - err = pthread_create(&g_thread, NULL, player_thread, NULL); - if (err) - { - return false; - } - - /* We only managed to match with the default player. */ - - if (g_player == play_default) - { - return true; - } - - /* If we're not using the default player, we need to open a file - * descriptor. - */ - - g_fd = open(CONFIG_GAMES_NXDOOM_RTTTL_DEVICE, O_RDWR); - if (g_fd < 0) - { - fprintf(stderr, - "Couldn't open RTTL device '" CONFIG_GAMES_NXDOOM_RTTTL_DEVICE - "': %d", - errno); - return false; - } - - return true; -} - -/**************************************************************************** - * Name: i_rtttl_shutdown_music - * - * Description: - * Turns off the music and de-initializes the module. - * - ****************************************************************************/ - -static void i_rtttl_shutdown_music(void) -{ - i_rtttl_stop_song(); /* Stop music */ - pthread_cancel(g_thread); /* Kill thread */ - close(g_fd); /* Clean up device */ -} - -static void i_rtttl_set_music_volume(int volume) -{ - return; /* Currently not possible */ -} - -/**************************************************************************** - * Name: i_rtttl_pause_song - * - * Description: - * Pauses the currently playing song. Right now, this is implemented by - * causing the RTTL `play` function to block on a condition variable. - * - ****************************************************************************/ - -static void i_rtttl_pause_song(void) -{ - pthread_mutex_lock(&g_player_lock); - g_paused = true; - pthread_mutex_unlock(&g_player_lock); -} - -/**************************************************************************** - * Name: i_rtttl_resume_song - * - * Description: - * Resume the currently paused song. Unblocks the RTTL `play` function by - * signalling the condition variable. - * - ****************************************************************************/ - -static void i_rtttl_resume_song(void) -{ - pthread_mutex_lock(&g_player_lock); - g_paused = false; - pthread_cond_signal(&g_pausecond); - pthread_mutex_unlock(&g_player_lock); -} - -/**************************************************************************** - * Name: i_rtttl_register_song - * - * Description: - * Appears to be used to register song data from the DOOM lump. Right now, - * we are using a statically stored RTTL string so we just ignore this. It - * would be good to have RTTL data substituted for lump data in the future - * so we can play the different songs provided by DOOM WADS. - * - * Input Parameters: - * data - Song data - * len - The length of the song data in bytes - * - * Returns: In theory, a handle representing the registered song. However, in - * practice, we return NULL to indicate this function isn't doing anything. - * - ****************************************************************************/ - -static void *i_rtttl_register_song(void *data, int len) -{ - /* TODO: no idea what this would be for; right now we play only the theme */ - - return NULL; -} - -/**************************************************************************** - * Name: i_rtttl_unregister_song - * - * Description: - * Unregisters one of the registered songs from `i_rtttl_register_song`. - * Currently unimplemented since we register nothing. - * - * Input Parameters: - * handle - The returned handle to the registered song - * - ****************************************************************************/ - -static void i_rtttl_unregister_song(void *handle) -{ - /* TODO: no idea what this would be for */ - - return; -} - -/**************************************************************************** - * Name: i_rtttl_play_song - * - * Description: - * Plays a previously registered song via the RTTTL library. - * - * Input Parameters: - * handle - The handle to a previously registered song - * looping - True if the song should loop, false otherwise - * - ****************************************************************************/ - -static void i_rtttl_play_song(void *handle, boolean looping) -{ - pthread_mutex_lock(&g_player_lock); - g_playing = true; - g_paused = false; - g_loop = looping; - pthread_cond_signal(&g_playingcond); - pthread_mutex_unlock(&g_player_lock); -} - -/**************************************************************************** - * Name: i_rtttl_stop_song - * - * Description: - * Stops playing the currently playing song (fully, not paused). - * - ****************************************************************************/ - -static void i_rtttl_stop_song(void) -{ - pthread_mutex_lock(&g_player_lock); - g_playing = false; - - /* Song not paused, allows play function to return early by also unblocking - * it. Then control is returned to the thread's main loop instead of the - * loop inside the RTTL library thread, where the thread can then block - * until a new song is played. - */ - - if (g_paused) - { - g_paused = false; - pthread_cond_signal(&g_pausecond); - } - - g_loop = false; - pthread_mutex_unlock(&g_player_lock); -} - -static boolean i_rtttl_musicisplaying(void) -{ - return g_playing; -} - -static void i_rtttl_pollmusic(void) -{ - /* Unsure what this function does */ - - return; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ diff --git a/games/NXDoom/src/i_sdlmusic.c b/games/NXDoom/src/i_sdlmusic.c deleted file mode 100644 index 29af65a4e..000000000 --- a/games/NXDoom/src/i_sdlmusic.c +++ /dev/null @@ -1,149 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/i_sdlmusic.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * System interface for music. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include -#include - -#include "config.h" -#include "doomtype.h" -#include "memio.h" -#include "mus2mid.h" - -#include "deh_str.h" -#include "gusconf.h" -#include "i_sound.h" -#include "i_swap.h" -#include "i_system.h" -#include "m_argv.h" -#include "m_config.h" -#include "m_misc.h" -#include "sha1.h" -#include "w_wad.h" -#include "z_zone.h" - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static char *temp_timidity_cfg = NULL; - -/* putenv requires a non-const string whose lifetime is the whole program - * so can't use a string directly, have to do this silliness - */ - -static char sdl_mixer_disable_fluidsynth[] = - "SDL_MIXER_DISABLE_FLUIDSYNTH=1"; - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -char *timidity_cfg_path = ""; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/* If the temp_timidity_cfg config variable is set, generate a "wrapper" - * config file for Timidity to point to the actual config file. This - * is needed to inject a "dir" command so that the patches are read - * relative to the actual config file. - */ - -static boolean write_wrapper_timidity_config(char *write_path) -{ - char *path; - FILE *fstream; - - if (!strcmp(timidity_cfg_path, "")) - { - return false; - } - - fstream = fopen(write_path, "w"); - - if (fstream == NULL) - { - return false; - } - - path = m_dir_name(timidity_cfg_path); - fprintf(fstream, "dir %s\n", path); - free(path); - - fprintf(fstream, "source %s\n", timidity_cfg_path); - fclose(fstream); - - return true; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -void i_init_timidity_config(void) -{ - char *env_string; - boolean success; - - temp_timidity_cfg = m_temp_file("timidity.cfg"); - - if (snd_musicdevice == SNDDEVICE_GUS) - { - success = gus_write_config(temp_timidity_cfg); - } - else - { - success = write_wrapper_timidity_config(temp_timidity_cfg); - } - - /* Set the TIMIDITY_CFG environment variable to point to the temporary - * config file. - */ - - if (success) - { - env_string = m_string_join("TIMIDITY_CFG=", temp_timidity_cfg, NULL); - putenv(env_string); - - /* env_string deliberately not freed; see putenv manpage - * If we're explicitly configured to use Timidity (either through - * timidity_cfg_path or GUS mode), then disable Fluidsynth, because - * SDL_mixer considers Fluidsynth a higher priority than Timidity and - * therefore can end up circumventing Timidity entirely. - */ - - putenv(sdl_mixer_disable_fluidsynth); - } - else - { - free(temp_timidity_cfg); - temp_timidity_cfg = NULL; - } -} diff --git a/games/NXDoom/src/i_sound.c b/games/NXDoom/src/i_sound.c deleted file mode 100644 index 8c8cafaed..000000000 --- a/games/NXDoom/src/i_sound.c +++ /dev/null @@ -1,525 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/i_sound.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -#include "config.h" -#include "doomtype.h" - -#include "gusconf.h" -#include "i_sound.h" -#include "i_video.h" -#include "m_argv.h" -#include "m_config.h" - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/* Sound sample rate to use for digital output (Hz) */ - -int snd_samplerate = 44100; - -/* Maximum number of bytes to dedicate to allocated sound effects. - * (Default: 64MB) - */ - -int snd_cachesize = 64 * 1024 * 1024; - -/* Config variable that controls the sound buffer size. - * We default to 28ms (1000 / 35fps = 1 buffer per tic). - */ - -int snd_maxslicetime_ms = 28; - -/* External command to invoke to play back music. */ - -char *snd_musiccmd = ""; - -/* Whether to vary the pitch of sound effects - * Each game will set the default differently - */ - -int snd_pitchshift = -1; - -int snd_musicdevice = SNDDEVICE_SB; -int snd_sfxdevice = SNDDEVICE_SB; - -/* Scale factor used when converting libsamplerate floating point numbers - * to integers. Too high means the sounds can clip; too low means they - * will be too quiet. This is an amount that should avoid clipping most - * of the time: with all the Doom IWAD sound effects, at least. If a PWAD - * is used, clipping might occur. - * - * NOTE: originally from i_sdlsound.c - */ - -float libsamplerate_scale = 0.65f; -int use_libsamplerate = 0; - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/* Low-level sound and music modules we are using */ - -static const sound_module_t *sound_module; -static const music_module_t *music_module; - -/* If true, the music pack module was successfully initialized. */ - -static boolean music_packs_active = false; - -/* This is either equal to music_module or &music_pack_module, - * depending on whether the current track is substituted. - */ - -static const music_module_t *active_music_module; - -/* DOS-specific options: These are unused but should be maintained - * so that the config file can be shared between chocolate - * doom and doom.exe - */ - -static int snd_sbport = 0; -static int snd_sbirq = 0; -static int snd_sbdma = 0; -static int snd_mport = 0; - -/* Compiled-in sound modules: */ - -static const sound_module_t *sound_modules[] = -{ - &sound_pcsound_module, - NULL, -}; - -/* Compiled-in music modules: */ - -static const music_module_t *g_music_modules[] = -{ -#if 0 - &music_opl_module, -#endif -#ifdef CONFIG_GAMES_NXDOOM_RTTTL_MUSIC - &g_rtttl_music_module, -#endif - NULL, -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/* Check if a sound device is in the given list of devices */ - -static boolean snd_device_in_list(snddevice_t device, - const snddevice_t *list, int len) -{ - int i; - - for (i = 0; i < len; ++i) - { - if (device == list[i]) - { - return true; - } - } - - return false; -} - -/* Find and initialize a sound_module_t appropriate for the setting - * in snd_sfxdevice. - */ - -static void init_sfx_module(gamemission_t mission) -{ - int i; - - sound_module = NULL; - - for (i = 0; sound_modules[i] != NULL; ++i) - { - /* Is the sfx device in the list of devices supported by - * this module? - */ - - if (snd_device_in_list(snd_sfxdevice, sound_modules[i]->sound_devices, - sound_modules[i]->num_sound_devices)) - { - /* initialize the module */ - - if (sound_modules[i]->init(mission)) - { - sound_module = sound_modules[i]; - return; - } - } - } -} - -/* initialize music according to snd_musicdevice. */ - -static void init_music_module(void) -{ - int i; - - music_module = NULL; - - for (i = 0; g_music_modules[i] != NULL; ++i) - { - /* Is the music device in the list of devices supported - * by this module? - */ - - if (snd_device_in_list(snd_musicdevice, - g_music_modules[i]->sound_devices, - g_music_modules[i]->num_sound_devices)) - { - /* initialize the module */ - - if (g_music_modules[i]->init()) - { - music_module = g_music_modules[i]; - return; - } - } - } -} - -static void check_volume_separation(int *vol, int *sep) -{ - if (*sep < 0) - { - *sep = 0; - } - else if (*sep > 254) - { - *sep = 254; - } - - if (*vol < 0) - { - *vol = 0; - } - else if (*vol > 127) - { - *vol = 127; - } -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/* initializes sound stuff, including volume - * Sets channels, SFX and music volume, allocates channel buffer, sets s_sfx - * lookup. - */ - -void i_init_sound(gamemission_t mission) -{ - boolean nosound; - boolean nosfx; - boolean nomusic; - boolean nomusicpacks; - - /* @vanilla - * - * Disable all sound output. - */ - - nosound = m_check_parm("-nosound") > 0; - - /* @vanilla - * - * Disable sound effects. - */ - - nosfx = m_check_parm("-nosfx") > 0; - - /* @vanilla - * - * Disable music. - */ - - nomusic = m_check_parm("-nomusic") > 0; - - /* Disable substitution music packs. */ - - nomusicpacks = m_parm_exists("-nomusicpacks"); - - /* Auto configure the music pack directory. */ - - m_set_music_pack_dir(); - - /* initialize the sound and music subsystems. */ - - if (!nosound && !screensaver_mode) - { - /* This is kind of a hack. If native MIDI is enabled, set up - * the TIMIDITY_CFG environment variable here before SDL_mixer - * is opened. - */ - - if (!nomusic && (snd_musicdevice == SNDDEVICE_GENMIDI || - snd_musicdevice == SNDDEVICE_GUS)) - { - i_init_timidity_config(); - } - - if (!nosfx) - { - init_sfx_module(mission); - } - - if (!nomusic) - { - init_music_module(); - active_music_module = music_module; - } - - /* We may also have substitute MIDIs we can load. */ - - if (!nomusicpacks && music_module != NULL) - { - music_packs_active = music_pack_module.init(); - } - } -} - -void i_shutdown_sound(void) -{ - if (sound_module != NULL) - { - sound_module->shutdown(); - } - - if (music_packs_active) - { - music_pack_module.shutdown(); - } - - if (music_module != NULL) - { - music_module->shutdown(); - } -} - -int i_get_sfx_lumpnum(sfxinfo_t *sfxinfo) -{ - if (sound_module != NULL) - { - return sound_module->get_sfx_lumpnum(sfxinfo); - } - else - { - return 0; - } -} - -void i_update_sound(void) -{ - if (sound_module != NULL) - { - sound_module->update(); - } - - if (active_music_module != NULL && active_music_module->poll != NULL) - { - active_music_module->poll(); - } -} - -void i_update_sound_params(int channel, int vol, int sep) -{ - if (sound_module != NULL) - { - check_volume_separation(&vol, &sep); - sound_module->update_sound_params(channel, vol, sep); - } -} - -int i_start_sound(sfxinfo_t *sfxinfo, int channel, int vol, int sep, - int pitch) -{ - if (sound_module != NULL) - { - check_volume_separation(&vol, &sep); - return sound_module->start_sound(sfxinfo, channel, vol, sep, pitch); - } - else - { - return 0; - } -} - -void i_stop_sound(int channel) -{ - if (sound_module != NULL) - { - sound_module->stop_sound(channel); - } -} - -boolean i_sound_playing(int channel) -{ - if (sound_module != NULL) - { - return sound_module->sound_is_playing(channel); - } - else - { - return false; - } -} - -void i_precache_sounds(sfxinfo_t *sounds, int num_sounds) -{ - if (sound_module != NULL && sound_module->cache_sounds != NULL) - { - sound_module->cache_sounds(sounds, num_sounds); - } -} - -void i_init_music(void) -{ - printf("i_init_music: Music initialized\n"); -} - -void i_shutdown_music(void) -{ -} - -void i_set_music_volume(int volume) -{ - if (music_module != NULL) - { - music_module->set_music_volume(volume); - - if (music_packs_active && music_module != &music_pack_module) - { - music_pack_module.set_music_volume(volume); - } - } -} - -void i_pause_song(void) -{ - if (active_music_module != NULL) - { - active_music_module->pause_music(); - } -} - -void i_resume_song(void) -{ - if (active_music_module != NULL) - { - active_music_module->resume_music(); - } -} - -void *i_register_song(void *data, int len) -{ - /* If the music pack module is active, check to see if there is a - * valid substitution for this track. If there is, we set the - * active_music_module pointer to the music pack module for the - * duration of this particular track. - */ - - if (music_packs_active) - { - void *handle; - - handle = music_pack_module.register_song(data, len); - if (handle != NULL) - { - active_music_module = &music_pack_module; - return handle; - } - } - - /* No substitution for this track, so use the main module. */ - - active_music_module = music_module; - if (active_music_module != NULL) - { - return active_music_module->register_song(data, len); - } - else - { - return NULL; - } -} - -void i_unregister_song(void *handle) -{ - if (active_music_module != NULL) - { - active_music_module->unregister_song(handle); - } -} - -void i_play_song(void *handle, boolean looping) -{ - printf("i_play_song: Playing on %p\n", active_music_module); - if (active_music_module != NULL) - { - active_music_module->play_song(handle, looping); - } -} - -void i_stop_song(void) -{ - if (active_music_module != NULL) - { - active_music_module->stop_song(); - } -} - -void i_bind_sound_variables(void) -{ - m_bind_int_variable("snd_musicdevice", &snd_musicdevice); - m_bind_int_variable("snd_sfxdevice", &snd_sfxdevice); - m_bind_int_variable("snd_sbport", &snd_sbport); - m_bind_int_variable("snd_sbirq", &snd_sbirq); - m_bind_int_variable("snd_sbdma", &snd_sbdma); - m_bind_int_variable("snd_mport", &snd_mport); - m_bind_int_variable("snd_maxslicetime_ms", &snd_maxslicetime_ms); - m_bind_string_variable("snd_musiccmd", &snd_musiccmd); - m_bind_int_variable("snd_samplerate", &snd_samplerate); - m_bind_int_variable("snd_cachesize", &snd_cachesize); - m_bind_int_variable("snd_pitchshift", &snd_pitchshift); - - m_bind_string_variable("music_pack_path", &music_pack_path); - m_bind_string_variable("timidity_cfg_path", &timidity_cfg_path); - m_bind_string_variable("gus_patch_path", &gus_patch_path); - m_bind_int_variable("gus_ram_kb", &gus_ram_kb); - - m_bind_int_variable("use_libsamplerate", &use_libsamplerate); - m_bind_float_variable("libsamplerate_scale", &libsamplerate_scale); -} diff --git a/games/NXDoom/src/i_sound.h b/games/NXDoom/src/i_sound.h deleted file mode 100644 index 6827df992..000000000 --- a/games/NXDoom/src/i_sound.h +++ /dev/null @@ -1,318 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/i_sound.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * The not so system specific sound interface. - * - ****************************************************************************/ - -#ifndef __I_SOUND__ -#define __I_SOUND__ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "d_mode.h" -#include "doomtype.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* so that the individual game logic and sound driver code agree */ - -#define NORM_PITCH 127 - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -/* SoundFX struct. */ - -typedef struct sfxinfo_struct sfxinfo_t; - -struct sfxinfo_struct -{ - /* tag name, used for hexen. */ - - const char *tagname; - - /* lump name. If we are running with use_sfx_prefix=true, a - * 'DS' (or 'DP' for PC speaker sounds) is prepended to this. - */ - - char name[9]; - - /* Sfx priority */ - - int priority; - - /* referenced sound if a link */ - - sfxinfo_t *link; - - /* pitch if a link (Doom), whether to pitch-shift (Hexen) */ - - int pitch; - - /* volume if a link */ - - int volume; - - /* this is checked every second to see if sound - * can be thrown out (if 0, then decrement, if -1, - * then throw out, if > 0, then it is in use) - */ - - int usefulness; - - /* lump number of sfx */ - - int lumpnum; - - /* Maximum number of channels that the sound can be played on - * (Heretic) - */ - - int numchannels; - - /* data used by the low level code */ - - void *driver_data; -}; - -/* MusicInfo struct. */ - -typedef struct -{ - /* up to 6-character name */ - - const char *name; - - /* lump number of music */ - - int lumpnum; - - /* music data */ - - void *data; - - /* music handle once registered */ - - void *handle; -} musicinfo_t; - -typedef enum -{ - SNDDEVICE_NONE = 0, - SNDDEVICE_PCSPEAKER = 1, - SNDDEVICE_ADLIB = 2, - SNDDEVICE_SB = 3, - SNDDEVICE_PAS = 4, - SNDDEVICE_GUS = 5, - SNDDEVICE_WAVEBLASTER = 6, - SNDDEVICE_SOUNDCANVAS = 7, - SNDDEVICE_GENMIDI = 8, - SNDDEVICE_AWE32 = 9, - SNDDEVICE_CD = 10, - SNDDEVICE_FSYNTH = 11, -} snddevice_t; - -/* Interface for sound modules */ - -typedef struct -{ - /* List of sound devices that this sound module is used for. */ - - const snddevice_t *sound_devices; - int num_sound_devices; - - /* initialise sound module - * Returns true if successfully initialised - */ - - boolean (*init)(gamemission_t mission); - - /* shutdown sound module */ - - void (*shutdown)(void); - - /* Returns the lump index of the given sound. */ - - int (*get_sfx_lumpnum)(sfxinfo_t *sfxinfo); - - /* Called periodically to update the subsystem. */ - - void (*update)(void); - - /* Update the sound settings on the given channel. */ - - void (*update_sound_params)(int channel, int vol, int sep); - - /* Start a sound on a given channel. Returns the channel id - * or -1 on failure. - */ - - int (*start_sound)(sfxinfo_t *sfxinfo, int channel, int vol, int sep, - int pitch); - - /* Stop the sound playing on the given channel. */ - - void (*stop_sound)(int channel); - - /* Query if a sound is playing on the given channel */ - - boolean (*sound_is_playing)(int channel); - - /* Called on startup to precache sound effects (if necessary) */ - - void (*cache_sounds)(sfxinfo_t *sounds, int num_sounds); -} sound_module_t; - -/* Interface for music modules */ - -typedef struct -{ - /* List of sound devices that this music module is used for. */ - - const snddevice_t *sound_devices; - int num_sound_devices; - - /* initialise the music subsystem */ - - boolean (*init)(void); - - /* shutdown the music subsystem */ - - void (*shutdown)(void); - - /* Set music volume - range 0-127 */ - - void (*set_music_volume)(int volume); - - /* Pause music */ - - void (*pause_music)(void); - - /* Un-pause music */ - - void (*resume_music)(void); - - /* Register a song handle from data - * Returns a handle that can be used to play the song - */ - - void *(*register_song)(void *data, int len); - - /* Un-register (free) song data */ - - void (*unregister_song)(void *handle); - - /* Play the song */ - - void (*play_song)(void *handle, boolean looping); - - /* Stop playing the current song. */ - - void (*stop_song)(void); - - /* Query if music is playing. */ - - boolean (*music_is_playing)(void); - - /* Invoked periodically to poll. */ - - void (*poll)(void); -} music_module_t; - -#if 0 -/* DMX version to emulate for OPL emulation: */ - -typedef enum -{ - opl_doom1_1_666, /* Doom 1 v1.666 */ - opl_doom2_1_666, /* Doom 2 v1.666, Hexen, Heretic */ - opl_doom_1_9 /* Doom v1.9, Strife */ -} opl_driver_ver_t; -#endif - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -extern int snd_sfxdevice; -extern int snd_musicdevice; -extern int snd_samplerate; -extern int snd_cachesize; -extern int snd_maxslicetime_ms; -extern char *snd_musiccmd; -extern int snd_pitchshift; -extern int use_libsamplerate; -extern float libsamplerate_scale; - -extern const sound_module_t sound_pcsound_module; - -extern const music_module_t music_pack_module; - -#ifdef CONFIG_GAMES_NXDOOM_RTTTL_MUSIC -extern const music_module_t g_rtttl_music_module; -#endif - -/* For native music module: */ - -extern char *music_pack_path; -extern char *timidity_cfg_path; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -void i_init_sound(gamemission_t mission); -void i_shutdown_sound(void); -int i_get_sfx_lumpnum(sfxinfo_t *sfxinfo); -void i_update_sound(void); -void i_update_sound_params(int channel, int vol, int sep); -int i_start_sound(sfxinfo_t *sfxinfo, int channel, int vol, int sep, - int pitch); -void i_stop_sound(int channel); -boolean i_sound_playing(int channel); -void i_precache_sounds(sfxinfo_t *sounds, int num_sounds); - -void i_init_music(void); -void i_shutdown_music(void); -void i_set_music_volume(int volume); -void i_pause_song(void); -void i_resume_song(void); -void *i_register_song(void *data, int len); -void i_unregister_song(void *handle); -void i_play_song(void *handle, boolean looping); -void i_stop_song(void); - -void i_bind_sound_variables(void); - -#if 0 -void i_set_opl_driver_ver(opl_driver_ver_t ver); -void i_opl_dev_messages(char *, size_t); -#endif - -/* Sound modules */ - -void i_init_timidity_config(void); - -#endif /* __I_SOUND__ */ diff --git a/games/NXDoom/src/i_swap.h b/games/NXDoom/src/i_swap.h deleted file mode 100644 index 72b64236f..000000000 --- a/games/NXDoom/src/i_swap.h +++ /dev/null @@ -1,54 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/i_swap.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Endianness handling, swapping 16bit and 32bit. - * - ****************************************************************************/ - -#ifndef __I_SWAP__ -#define __I_SWAP__ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* Endianness handling. - * WAD files are stored little endian. - */ - -/* These are deliberately cast to signed values; this is the behaviour - * of the macros in the original source and some code relies on it. - */ - -#define SHORT(x) ((signed short)le16toh(x)) -#define LONG(x) ((signed int)le32toh(x)) - -/* Defines for checking the endianness of the system. */ - -#if BYTE_ORDER == BIG_ENDIAN -#define SYS_BIG_ENDIAN -#endif - -#endif /* __I_SWAP__ */ diff --git a/games/NXDoom/src/i_system.c b/games/NXDoom/src/i_system.c deleted file mode 100644 index b3867e0ad..000000000 --- a/games/NXDoom/src/i_system.c +++ /dev/null @@ -1,482 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/i_system.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include -#include -#include - -#include "config.h" - -#include "deh_str.h" -#include "doomtype.h" -#include "i_joystick.h" -#include "i_sound.h" -#include "i_timer.h" -#include "i_video.h" -#include "m_argv.h" -#include "m_config.h" -#include "m_misc.h" - -#include "i_system.h" - -#include "w_wad.h" -#include "z_zone.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define DEFAULT_RAM 16 /* MiB */ -#define MIN_RAM 4 /* MiB */ - -#define DOS_MEM_DUMP_SIZE 10 - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -typedef struct atexit_listentry_s atexit_listentry_t; - -struct atexit_listentry_s -{ - atexit_func_t func; - boolean run_on_error; - atexit_listentry_t *next; -}; - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static atexit_listentry_t *exit_funcs = NULL; - -static boolean already_quitting = false; - -/* Read Access Violation emulation. - * - * From PrBoom+, by entryway. - */ - -/* C:\>debug - * -d 0:0 - * - * DOS 6.22: - * 0000:0000 (57 92 19 00) F4 06 70 00-(16 00) - * DOS 7.1: - * 0000:0000 (9E 0F C9 00) 65 04 70 00-(16 00) - * Win98: - * 0000:0000 (9E 0F C9 00) 65 04 70 00-(16 00) - * DOSBox under XP: - * 0000:0000 (00 00 00 F1) ?? ?? ?? 00-(07 00) - */ - -static const unsigned char mem_dump_dos622[DOS_MEM_DUMP_SIZE] = -{ - 0x57, 0x92, 0x19, 0x00, 0xf4, 0x06, 0x70, 0x00, 0x16, 0x00, -}; - -static const unsigned char mem_dump_win98[DOS_MEM_DUMP_SIZE] = -{ - 0x9e, 0x0f, 0xc9, 0x00, 0x65, 0x04, 0x70, 0x00, 0x16, 0x00, -}; - -static const unsigned char mem_dump_dosbox[DOS_MEM_DUMP_SIZE] = -{ - 0x00, 0x00, 0x00, 0xf1, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, -}; - -static unsigned char mem_dump_custom[DOS_MEM_DUMP_SIZE]; - -static const unsigned char *dos_mem_dump = mem_dump_dos622; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/* Zone memory auto-allocation function that allocates the zone size - * by trying progressively smaller zone sizes until one is found that - * works. - */ - -static byte *auto_alloc_memory(int *size, int default_ram, int min_ram) -{ - byte *zonemem; - - /* Allocate the zone memory. This loop tries progressively smaller - * zone sizes until a size is found that can be allocated. - * If we used the -mb command line parameter, only the parameter - * provided is accepted. - */ - - zonemem = NULL; - - while (zonemem == NULL) - { - /* We need a reasonable minimum amount of RAM to start. */ - - if (default_ram < min_ram) - { - i_error("Unable to allocate %i MiB of RAM for zone", default_ram); - } - - /* Try to allocate the zone memory. */ - - *size = default_ram * 1024 * 1024; - - zonemem = malloc(*size); - - /* Failed to allocate? Reduce zone size until we reach a size - * that is acceptable. - */ - - if (zonemem == NULL) - { - default_ram -= 1; - } - } - - return zonemem; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -void i_at_exit(atexit_func_t func, boolean run_on_error) -{ - atexit_listentry_t *entry; - - entry = malloc(sizeof(*entry)); - - entry->func = func; - entry->run_on_error = run_on_error; - entry->next = exit_funcs; - exit_funcs = entry; -} - -/* Tactile feedback function, probably used for the Logitech Cyberman */ - -void i_tactile(int on, int off, int total) -{ -} - -byte *i_zone_base(int *size) -{ - byte *zonemem; - int min_ram; - int default_ram; - int p; - - /* @category obscure - * @arg - * - * Specify the heap size, in MiB. - */ - - p = m_check_parm_with_args("-mb", 1); - - if (p > 0) - { - default_ram = atoi(myargv[p + 1]); - min_ram = default_ram; - } - else - { - /* Because of the 8-byte pointer size in a 64-bit build, the default - * heap size (16 MiB) is insufficient compared to a 32-bit build. For - * example, the Alien Vendetta avm62402.lmp demo completes successfully - * on a 32-bit build, but terminates with an out of memory error on a - * 64-bit build. Therefore, to maintain consistency with a 32-bit - * build, the heap size should be increased. - */ - - if (sizeof(void *) == 8) - { - default_ram = DEFAULT_RAM * 2; - } - else - { - default_ram = DEFAULT_RAM; - } - - min_ram = MIN_RAM; - } - - zonemem = auto_alloc_memory(size, default_ram, min_ram); - - printf("zone memory: %p, %x allocated for zone\n", zonemem, *size); - - return zonemem; -} - -void i_print_banner(const char *msg) -{ - int i; - int spaces = 35 - (strlen(msg) / 2); - - for (i = 0; i < spaces; ++i) - putchar(' '); - - puts(msg); -} - -void i_print_divider(void) -{ - int i; - - for (i = 0; i < 75; ++i) - { - putchar('='); - } - - putchar('\n'); -} - -void i_print_startup_banner(const char *gamedescription) -{ - i_print_divider(); - i_print_banner(gamedescription); - i_print_divider(); - - printf( - " " PACKAGE_NAME - " is free software, covered by the GNU General Public\n" - " License. There is NO warranty; not even for MERCHANTABILITY or " - "FITNESS\n" - " FOR A PARTICULAR PURPOSE. You are welcome to change and distribute\n" - " copies under certain conditions. See the source for more " - "information.\n"); - - i_print_divider(); -} - -/* i_console_stdout - * - * Returns true if stdout is a real console, false if it is a file - */ - -boolean i_console_stdout(void) -{ - return isatty(fileno(stdout)); -} - -/* i_init */ - -#if 0 -void i_init(void) -{ - i_check_is_screensaver(); - i_init_timer(); - i_init_joystick(); -} - -void i_bind_variables(void) -{ - i_bind_video_variables(); - i_bind_joystick_variables(); - i_bind_sound_variables(); -} -#endif - -/* i_quit */ - -void i_quit(void) -{ - atexit_listentry_t *entry; - - /* Run through all exit functions */ - - entry = exit_funcs; - - while (entry != NULL) - { - entry->func(); - entry = entry->next; - } - - exit(0); -} - -void i_error(const char *error, ...) -{ - char msgbuf[512]; - va_list argptr; - atexit_listentry_t *entry; - boolean exit_gui_popup; - - if (already_quitting) - { - fprintf(stderr, "Warning: recursive call to i_error detected.\n"); - exit(-1); - } - else - { - already_quitting = true; - } - - /* Message first. */ - - va_start(argptr, error); - - vfprintf(stderr, error, argptr); - fprintf(stderr, "\n\n"); - va_end(argptr); - fflush(stderr); - - /* Write a copy of the message into buffer. */ - - va_start(argptr, error); - memset(msgbuf, 0, sizeof(msgbuf)); - vsnprintf(msgbuf, sizeof(msgbuf), error, argptr); - va_end(argptr); - - /* Shutdown. Here might be other errors. */ - - entry = exit_funcs; - - while (entry != NULL) - { - if (entry->run_on_error) - { - entry->func(); - } - - entry = entry->next; - } - - /* @category obscure - * - * If specified, don't show a GUI window for error messages when the - * game exits with an error. - */ - - exit_gui_popup = !m_parm_exists("-nogui"); - - /* Pop up a GUI dialog box to show the error message, if the - * game was not run from the console (and the user will - * therefore be unable to otherwise see the message). - */ - - if (exit_gui_popup && !i_console_stdout()) - { - } - - /* abort(); */ - - exit(-1); -} - -void *i_realloc(void *ptr, size_t size) -{ - void *new_ptr; - - new_ptr = realloc(ptr, size); - - if (size != 0 && new_ptr == NULL) - { - i_error("i_realloc: failed on reallocation of %zu bytes", size); - } - - return new_ptr; -} - -boolean i_get_memory_value(unsigned int offset, void *value, int size) -{ - static boolean firsttime = true; - - if (firsttime) - { - int p; - int i; - int val; - - firsttime = false; - i = 0; - - /* @category compat - * @arg - * - * Specify DOS version to emulate for NULL pointer dereference - * emulation. Supported versions are: dos622, dos71, dosbox. - * The default is to emulate DOS 7.1 (Windows 98). - */ - - p = m_check_parm_with_args("-setmem", 1); - - if (p > 0) - { - if (!strcasecmp(myargv[p + 1], "dos622")) - { - dos_mem_dump = mem_dump_dos622; - } - - if (!strcasecmp(myargv[p + 1], "dos71")) - { - dos_mem_dump = mem_dump_win98; - } - else if (!strcasecmp(myargv[p + 1], "dosbox")) - { - dos_mem_dump = mem_dump_dosbox; - } - else - { - for (i = 0; i < DOS_MEM_DUMP_SIZE; ++i) - { - ++p; - - if (p >= myargc || myargv[p][0] == '-') - { - break; - } - - m_str_to_int(myargv[p], &val); - mem_dump_custom[i++] = (unsigned char)val; - } - - dos_mem_dump = mem_dump_custom; - } - } - } - - switch (size) - { - case 1: - *((unsigned char *)value) = dos_mem_dump[offset]; - return true; - case 2: - *((unsigned short *)value) = - dos_mem_dump[offset] | (dos_mem_dump[offset + 1] << 8); - return true; - case 4: - *((unsigned int *)value) = - dos_mem_dump[offset] | (dos_mem_dump[offset + 1] << 8) | - (dos_mem_dump[offset + 2] << 16) | - (dos_mem_dump[offset + 3] << 24); - return true; - } - - return false; -} diff --git a/games/NXDoom/src/i_system.h b/games/NXDoom/src/i_system.h deleted file mode 100644 index ae1c56806..000000000 --- a/games/NXDoom/src/i_system.h +++ /dev/null @@ -1,107 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/i_system.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * System specific interface stuff. - * - ****************************************************************************/ - -#ifndef __I_SYSTEM__ -#define __I_SYSTEM__ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "d_event.h" -#include "d_ticcmd.h" - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -typedef void (*atexit_func_t)(void); - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/* Called by DoomMain. */ - -void i_init(void); - -/* Called by startup code to get the amount of memory to malloc for the zone - * management. - */ - -byte *i_zone_base(int *size); - -boolean i_console_stdout(void); - -/* Asynchronous interrupt functions should maintain private queues - * that are read by the synchronous functions - * to be converted into events. - */ - -#if 0 /* Unused */ - -/* Either returns a null ticcmd, or calls a loadable driver to build it. - * This ticcmd will then be modified by the gameloop for normal input. - */ - -ticcmd_t *i_base_ticcmd(void); -#endif - -/* Called by m_responder when quit is selected. - * Clean exit, displays sell blurb. - */ - -void i_quit(void) NORETURN; - -void i_error(const char *error, ...) NORETURN PRINTF_ATTR(1, 2); - -void i_tactile(int on, int off, int total); - -void *i_realloc(void *ptr, size_t size); - -boolean i_get_memory_value(unsigned int offset, void *value, int size); - -/* Schedule a function to be called when the program exits. - * If run_if_error is true, the function is called if the exit - * is due to an error (i_error) - */ - -void i_at_exit(atexit_func_t func, boolean run_if_error); - -/* Add all system-specific config file variable bindings. */ - -void i_bind_variables(void); - -/* Print startup banner copyright message. */ - -void i_print_startup_banner(const char *gamedescription); - -/* Print a centered text banner displaying the given string. */ - -void i_print_banner(const char *text); - -/* Print a dividing line for startup banners. */ - -void i_print_divider(void); - -#endif /* __I_SYSTEM__ */ diff --git a/games/NXDoom/src/i_timer.c b/games/NXDoom/src/i_timer.c deleted file mode 100644 index abde6d4c9..000000000 --- a/games/NXDoom/src/i_timer.c +++ /dev/null @@ -1,107 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/i_timer.c - * - * SPDX-License-Identifier: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Timer functions. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -#include "doomtype.h" -#include "i_timer.h" - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/* The start time of the game used as the base for tic calculations. */ - -static struct timespec basetime = -{ - .tv_nsec = 0, .tv_sec = 0 -}; - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: i_get_time - * - * Description: - * Called by D_DoomLoop. - * - * Returns: - * The current time in 1/35th second tics. - ****************************************************************************/ - -int i_get_time(void) -{ - return (i_get_time_ms() * TICRATE) / 1000; -} - -/**************************************************************************** - * Name: i_get_time_ms - * - * Returns: - * The current time in ms. - ****************************************************************************/ - -int i_get_time_ms(void) -{ - struct timespec curtime; - - /* NOTE: we ignore any possible error here */ - - clock_gettime(CLOCK_MONOTONIC, &curtime); - if (basetime.tv_sec == 0 && basetime.tv_nsec == 0) - { - clock_gettime(CLOCK_MONOTONIC, &basetime); - } - - return (clock_time2usec(&curtime) - clock_time2usec(&basetime)) / 1000; -} - -/**************************************************************************** - * Name: i_init_timer - * - * Description: - * Initialize timer. - ****************************************************************************/ - -void i_init_timer(void) -{ -} - -/**************************************************************************** - * Name: i_wait_vbl - * - * Description: - * Wait for vertical retrace or pause a bit. - ****************************************************************************/ - -void i_wait_vbl(int count) -{ - usleep((count * 1000000) / 70); -} diff --git a/games/NXDoom/src/i_timer.h b/games/NXDoom/src/i_timer.h deleted file mode 100644 index eb9d7756c..000000000 --- a/games/NXDoom/src/i_timer.h +++ /dev/null @@ -1,76 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/i_timer.h - * - * SPDX-License-Identifier: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * System-specific timer interface - * - ****************************************************************************/ - -#ifndef __I_TIMER__ -#define __I_TIMER__ - -/**************************************************************************** - * Preprocessor Definitions - ****************************************************************************/ - -#define TICRATE 35 - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Name: i_get_time - * - * Description: - * Called by d_doomloop. - * - * Returns: - * The current time in tics. - ****************************************************************************/ - -int i_get_time(void); - -/**************************************************************************** - * Name: i_get_time_ms - * - * Returns: - * The current time in ms. - ****************************************************************************/ - -int i_get_time_ms(void); - -/**************************************************************************** - * Name: i_init_timer - * - * Description: - * Initialize timer. - ****************************************************************************/ - -void i_init_timer(void); - -/**************************************************************************** - * Name: i_wait_vbl - * - * Description: - * Wait for vertical retrace or pause a bit. - ****************************************************************************/ - -void i_wait_vbl(int count); - -#endif /* __I_TIMER__ */ diff --git a/games/NXDoom/src/i_video.c b/games/NXDoom/src/i_video.c deleted file mode 100644 index cf3c83780..000000000 --- a/games/NXDoom/src/i_video.c +++ /dev/null @@ -1,1077 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/i_video.c - * - * SPDX-License-Identifier: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * DOOM graphics stuff for SDL. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include - -#include -#include -#include -#include -#include - -#include "config.h" -#include "d_loop.h" -#include "deh_str.h" -#include "doomtype.h" -#include "i_input.h" -#include "i_joystick.h" -#include "i_system.h" -#include "i_timer.h" -#include "i_video.h" -#include "m_argv.h" -#include "m_config.h" -#include "m_misc.h" -#include "tables.h" -#include "v_diskicon.h" -#include "v_video.h" -#include "w_wad.h" -#include "z_zone.h" - -/**************************************************************************** - * Preprocessor Definitions - ****************************************************************************/ - -#define RESIZE_DELAY 500 - -#define MAX(a, b) (((a) > (b)) ? (a) : (b)) - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -struct graphics_state_s -{ - int fd; /* File descriptor handle to frame buffer */ - - /* The 320x200x32 RGBA intermediate buffer is what we blit the former - * buffer to. On NuttX, this is the frame buffer memory `fbmem`. It may not - * have 32-bit depth, but if it doesn't, the code is adjusted accordingly. - */ - - FAR void *fbmem; - - /* 8-bit depth screen buffer (320x200x8) that we draw to (i.e. the one that - * holds i_video_buffer) - */ - - pixel_t *scrnbuf; - - /* Information about the frame buffer needed for rendering. */ - - struct fb_videoinfo_s vinfo; - struct fb_planeinfo_s pinfo; - - /* Scale multiplier for rendering large image */ - - uint8_t scale; - - /* Byte offset into the frame buffer of the top left corner of the scaled - * image, so that it is centred on displays it does not fill. - */ - - size_t origin; - - /* Size of the scaled image in pixels. This is an integer multiple of the - * DOOM resolution unless the image is stretched to fill the display. - */ - - unsigned outw; - unsigned outh; - - /* Maps an output column onto the source column it is drawn from, so that - * the inner loop needs neither a division nor a separate case for - * fractional scaling. - */ - - FAR uint16_t *colmap; - - bool inited; /* Track initialization */ -}; - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/* NuttX graphics state */ - -static struct graphics_state_s g_graphics_state = -{ - 0 -}; - -#ifdef CONFIG_GAMES_NXDOOM_STATIC_SCRNBUF -/* The buffer DOOM renders into. Keeping it in .bss rather than on the heap - * puts it in internal RAM on boards whose heap is mostly external memory. - */ - -static pixel_t g_scrnbuf[SCREENWIDTH * SCREENHEIGHT]; -#endif - -#ifdef CONFIG_GAMES_NXDOOM_ROWSTAGE -/* Staging area for one output row. Expanding a row here and then copying it - * out keeps the per-pixel writes in internal RAM and turns every frame - * buffer access into a burst-friendly copy, which is what an external frame - * buffer wants. Declared as uint32_t for alignment; it holds one row at the - * largest scale and pixel size it can serve. - */ - -#define BLIT_MAX_STAGED_SCALE 4 - -static uint32_t g_rowbuf[SCREENWIDTH * BLIT_MAX_STAGED_SCALE]; -#endif - -/* Window title */ - -static const char *g_window_title = ""; - -/* Colour palette map from 8-bit colour to 32-bit */ - -static struct argbcolor_s g_palette[256]; - -/* The same palette, pre-converted to the pixel format of the frame buffer. - * Doing the conversion once per palette change instead of once per pixel - * keeps blit_screen() down to a lookup and a store. - */ - -static uint32_t g_palette_native[256]; - -static boolean palette_to_set; - -/* disable mouse? */ - -static boolean nomouse = false; - -/* Maximum number of pixels to use for intermediate scale buffer. */ - -static int max_scaling_buffer_pixels = 16000000; - -/* Time to wait for the screen to settle on startup before starting the game - * (ms) - */ - -static int startup_delay = 1000; - -/* Grab the mouse? (int type for config code). nograbmouse_override allows - * this to be temporarily disabled via the command line. - */ - -static int grabmouse = true; -static boolean nograbmouse_override = false; - -/* If true, we display dots at the bottom of the screen to - * indicate FPS. - */ - -static boolean display_fps_dots; - -/* If this is true, the screen is rendered but not blitted to the - * video buffer. - */ - -static boolean noblit; - -/* Callback function to invoke to determine whether to grab the - * mouse pointer. - */ - -static grabmouse_callback_t grabmouse_callback = NULL; - -/* Does the window currently have focus? */ - -static boolean window_focused = true; - -/* Window resize state. */ - -#if 0 -static boolean need_resize = false; -static unsigned int last_resize_time; -#endif - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -int usemouse = 1; - -/* Save screenshots in PNG format. */ - -int png_screenshots = 0; - -/* SDL video driver name */ - -char *video_driver = ""; - -/* Window position: */ - -char *window_position = "center"; - -/* SDL display number on which to run. */ - -int video_display = 0; - -/* Screen width and height, from configuration file. */ - -int window_width = 320; -int window_height = 200; - -/* Fullscreen mode, 0x0 for SDL_WINDOW_FULLSCREEN_DESKTOP. */ - -int fullscreen_width = 0; -int fullscreen_height = 0; - -/* Run in full screen mode? (int type for config code) */ - -int fullscreen = true; - -/* Smooth pixel scaling */ - -int smooth_pixel_scaling = true; - -/* Force integer scales for resolution-independent rendering */ - -int integer_scaling = false; - -/* VGA Porch palette change emulation */ - -int vga_porch_flash = false; - -/* Force software rendering, for systems which lack effective hardware - * acceleration - */ - -int force_software_renderer = false; - -/* The screen buffer; this is modified to draw things to the screen */ - -pixel_t *i_video_buffer = NULL; - -/* If true, game is running as a screensaver */ - -boolean screensaver_mode = false; - -/* Flag indicating whether the screen is currently visible: - * when the screen isn't visible, don't render the screen - */ - -boolean screenvisible = true; - -/* Gamma correction level to use */ - -int usegamma = 0; - -/* Joystick/gamepad hysteresis */ - -unsigned int joywait = 0; - -/* TODO: I'm sure more of the variables above can be private */ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: update_native_palette - * - * Description: - * Convert the ARGB palette into the pixel format of the frame buffer so - * that blitting is a plain table lookup. - * - ****************************************************************************/ - -static void update_native_palette(void) -{ - int i; - -#ifdef CONFIG_GAMES_NXDOOM_FB_CMAP - uint8_t red[256]; - uint8_t green[256]; - uint8_t blue[256]; -#ifdef CONFIG_FB_TRANSPARENCY - uint8_t transp[256]; -#endif - struct fb_cmap_s cmap; - - /* Hand the palette to the display and leave the lookup an identity, so - * that blitting writes the palette index and the hardware converts it - * while it scans the display out. - */ - - for (i = 0; i < 256; i++) - { - red[i] = g_palette[i].r; - green[i] = g_palette[i].g; - blue[i] = g_palette[i].b; -#ifdef CONFIG_FB_TRANSPARENCY - transp[i] = 0xff; -#endif - g_palette_native[i] = i; - } - - cmap.first = 0; - cmap.len = 256; - cmap.red = red; - cmap.green = green; - cmap.blue = blue; -#ifdef CONFIG_FB_TRANSPARENCY - cmap.transp = transp; -#endif - - if (ioctl(g_graphics_state.fd, FBIOPUT_CMAP, - (unsigned long)((uintptr_t)&cmap)) < 0) - { - i_error("ioctl(FBIOPUT_CMAP) failed: %d\n", errno); - } -#else - for (i = 0; i < 256; i++) - { - switch (g_graphics_state.pinfo.bpp) - { - case 8: - g_palette_native[i] = RGBTO8(g_palette[i].r, g_palette[i].g, - g_palette[i].b); - break; - - case 16: - g_palette_native[i] = RGBTO16(g_palette[i].r, g_palette[i].g, - g_palette[i].b); - break; - - case 24: - g_palette_native[i] = RGBTO24(g_palette[i].r, g_palette[i].g, - g_palette[i].b); - break; - - default: - g_palette_native[i] = ARGBTO32(g_palette[i].a, g_palette[i].r, - g_palette[i].g, g_palette[i].b); - break; - } - } -#endif -} - -/**************************************************************************** - * Name: blit_screen - * - * Description: - * Blit the 8-bit depth buffer that DOOM renders to onto the frame buffer, - * converting to the pixel format of the frame buffer and scaling up by an - * integer factor. - * - ****************************************************************************/ - -static void blit_screen(void) -{ - FAR uint8_t *fbbase = (FAR uint8_t *)g_graphics_state.fbmem + - g_graphics_state.origin; - FAR const uint16_t *colmap = g_graphics_state.colmap; - unsigned stride = g_graphics_state.pinfo.stride; - unsigned pixlen = g_graphics_state.pinfo.bpp >> 3; - unsigned outw = g_graphics_state.outw; - unsigned outh = g_graphics_state.outh; - unsigned rowbytes = outw * pixlen; -#ifdef CONFIG_GAMES_NXDOOM_ROWSTAGE - bool staged = rowbytes <= sizeof(g_rowbuf); -#else - const bool staged = false; -#endif - FAR uint8_t *prevrow = NULL; - unsigned prevsy = SCREENHEIGHT; - unsigned x; - unsigned oy; - unsigned sy; - - for (oy = 0; oy < outh; oy++) - { - FAR uint8_t *dst = fbbase + oy * stride; -#ifdef CONFIG_GAMES_NXDOOM_ROWSTAGE - FAR uint8_t *out = staged ? (FAR uint8_t *)g_rowbuf : dst; -#else - FAR uint8_t *out = dst; -#endif - FAR const pixel_t *src; - FAR uint8_t *dest8 = out; - FAR uint16_t *dest16 = (FAR uint16_t *)out; - FAR uint32_t *dest32 = (FAR uint32_t *)out; - uint32_t pixel; - - /* Which source row this output row comes from. Several output rows - * map to the same source row whenever the image is scaled up. - */ - - sy = oy * SCREENHEIGHT / outh; - if (sy == prevsy) - { - /* Identical to the row just built, so copy it rather than - * converting the same pixels again. - */ - - memcpy(dst, prevrow, rowbytes); - continue; - } - - /* Expand one source row. The column map turns this into a lookup per - * output pixel, with no division and no special case for a scale - * factor that is not a whole number. - */ - - src = &g_graphics_state.scrnbuf[sy * SCREENWIDTH]; - - switch (g_graphics_state.pinfo.bpp) - { - case 8: - for (x = 0; x < outw; x++) - { - *dest8++ = g_palette_native[src[colmap[x]]]; - } - break; - - case 16: - for (x = 0; x < outw; x++) - { - *dest16++ = g_palette_native[src[colmap[x]]]; - } - break; - - case 24: - for (x = 0; x < outw; x++) - { - pixel = g_palette_native[src[colmap[x]]]; - - *dest8++ = pixel; - *dest8++ = pixel >> 8; - *dest8++ = pixel >> 16; - } - break; - - default: - for (x = 0; x < outw; x++) - { - *dest32++ = g_palette_native[src[colmap[x]]]; - } - break; - } - - if (staged) - { - memcpy(dst, out, rowbytes); - } - - prevsy = sy; - prevrow = out; - } -} - -static void update_grab(void) -{ -} - -static void set_video_mode(void) -{ -} - -static void i_get_event(void) -{ - int err; -#if CONFIG_GAMES_NXDOOM_KEYBOARD - struct keyboard_event_s kbdevent; - - while ((err = get_kbd_event(&kbdevent)) == 0) - { - switch (kbdevent.type) - { - case KEYBOARD_PRESS: - - /* deliberate fall-though */ - - case KEYBOARD_RELEASE: - i_handle_keyboard_event(&kbdevent); - break; - - default: - break; - } - } -#endif -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -void i_set_grab_mouse_callback(grabmouse_callback_t func) -{ - grabmouse_callback = func; -} - -/* Set the variable controlling FPS dots. */ - -void i_display_fps_dots(boolean dots_on) -{ - display_fps_dots = dots_on; -} - -void i_shutdown_graphics(void) -{ - if (!g_graphics_state.inited) - { - return; - } - - close(g_graphics_state.fd); - munmap(g_graphics_state.fbmem, g_graphics_state.pinfo.fblen); -#ifndef CONFIG_GAMES_NXDOOM_STATIC_SCRNBUF - free(g_graphics_state.scrnbuf); -#endif - free(g_graphics_state.colmap); - g_graphics_state.inited = false; -} - -void i_start_frame(void) -{ - /* er? */ -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -void i_start_tic(void) -{ - if (!g_graphics_state.inited) - { - return; - } - - i_get_event(); - - if (usemouse && !nomouse && window_focused) - { - i_read_mouse(); - } - - if (joywait < i_get_time()) - { - i_update_joystick(); - } -} - -void i_update_no_blit(void) -{ - /* what is this? */ -} - -void i_finish_update(void) -{ - static int lasttic; - int tics; - int i; - - if (!g_graphics_state.inited) return; - - if (noblit) return; - - /* draws little dots on the bottom of the screen */ - - if (display_fps_dots) - { - i = i_get_time(); - tics = i - lasttic; - lasttic = i; - if (tics > 20) tics = 20; - - for (i = 0; i < tics * 4; i += 4) - i_video_buffer[(SCREENHEIGHT - 1) * SCREENWIDTH + i] = 0xff; - for (; i < 20 * 4; i += 4) - i_video_buffer[(SCREENHEIGHT - 1) * SCREENWIDTH + i] = 0x0; - } - - /* Draw disk icon before blit, if necessary. */ - - v_draw_disk_icon(); - - if (palette_to_set) - { - palette_to_set = false; - update_native_palette(); - } - - blit_screen(); - - /* Draw! */ - - /* Restore background and undo the disk indicator, if it was drawn. */ - - v_restore_disk_background(); -} - -void i_read_screen(pixel_t *scr) -{ - memcpy(scr, i_video_buffer, SCREENWIDTH * SCREENHEIGHT * sizeof(*scr)); -} - -/**************************************************************************** - * Name: i_set_palette - ****************************************************************************/ - -void i_set_palette(byte *doompalette) -{ - for (int i = 0; i < 256; ++i) - { - /* Zero out the bottom two bits of each channel - the PC VGA - * controller only supports 6 bits of accuracy. - */ - - g_palette[i].a = 0xffu; - g_palette[i].r = gammatable[usegamma][*doompalette++] & ~3; - g_palette[i].g = gammatable[usegamma][*doompalette++] & ~3; - g_palette[i].b = gammatable[usegamma][*doompalette++] & ~3; - } - - palette_to_set = true; -} - -/**************************************************************************** - * Name: i_get_palette_index - * - * Description: - * Given an RGB value, find the closest matching palette index. - * - * Return: - * An index into the palette lookup table for the best match. - * - ****************************************************************************/ - -int i_get_palette_index(int r, int g, int b) -{ - int best = 0; - int best_diff = INT_MAX; - int diff; - - for (int i = 0; i < 256; ++i) - { - diff = (r - g_palette[i].r) * (r - g_palette[i].r) + - (g - g_palette[i].g) * (g - g_palette[i].g) + - (b - g_palette[i].b) * (b - g_palette[i].b); - - if (diff < best_diff) - { - best = i; - best_diff = diff; - } - - if (diff == 0) - { - break; - } - } - - return best; -} - -/**************************************************************************** - * Name: i_set_window_title - * - * Description: - * Set the window title internally. - * - ****************************************************************************/ - -void i_set_window_title(const char *title) -{ - g_window_title = title; -} - -/**************************************************************************** - * Name: i_init_window_title - * - * Description: - * Actually cause the window title to update with whatever window title was - * last set via i_set_window_title. - * - ****************************************************************************/ - -void i_init_window_title(void) -{ -} - -/**************************************************************************** - * Name: i_set_window_title - ****************************************************************************/ - -void i_graphics_check_commandline(void) -{ - int i; - - /* @category video - * @vanilla - * - * Disable blitting the screen. - */ - - noblit = m_check_parm("-noblit"); - - /* @category video - * - * Don't grab the mouse when running in windowed mode. - */ - - nograbmouse_override = m_parm_exists("-nograbmouse"); - - /* default to fullscreen mode, allow override with command line - * nofullscreen because we love prboom - */ - - /* @category video - * - * Run in a window. - */ - - if (m_check_parm("-window") || m_check_parm("-nofullscreen")) - { - fullscreen = false; - } - - /* @category video - * - * Run in fullscreen mode. - */ - - if (m_check_parm("-fullscreen")) - { - fullscreen = true; - } - - /* @category video - * - * Disable the mouse. - */ - - nomouse = m_check_parm("-nomouse") > 0; - - /* @category video - * @arg - * - * Specify the screen width, in pixels. Implies -window. - */ - - i = m_check_parm_with_args("-width", 1); - - if (i > 0) - { - window_width = atoi(myargv[i + 1]); - fullscreen = false; - } - - /* @category video - * @arg - * - * Specify the screen height, in pixels. Implies -window. - */ - - i = m_check_parm_with_args("-height", 1); - - if (i > 0) - { - window_height = atoi(myargv[i + 1]); - fullscreen = false; - } - - /* @category video - * @arg - * - * Specify the dimensions of the window. Implies -window. - */ - - i = m_check_parm_with_args("-geometry", 1); - - if (i > 0) - { - int w; - int h; - int s; - - s = sscanf(myargv[i + 1], "%ix%i", &w, &h); - if (s == 2) - { - window_width = w; - window_height = h; - fullscreen = false; - } - } - - /* @category video - * @arg - * - * Specify the display number on which to show the screen. - */ - - i = m_check_parm_with_args("-display", 1); - - if (i > 0) - { - int display = atoi(myargv[i + 1]); - if (display >= 0) - { - video_display = display; - } - } -} - -/* Check if we have been invoked as a screensaver by xscreensaver. */ - -void i_check_is_screensaver(void) -{ - char *env; - - env = getenv("XSCREENSAVER_WINDOW"); - - if (env != NULL) - { - screensaver_mode = true; - } -} - -/* Check the display bounds of the display referred to by 'video_display' and - * set x and y to a location that places the window in the center of that - * display. - */ - -static void center_window(int *x, int *y, int w, int h) -{ - *x = MAX((g_graphics_state.vinfo.xres - w) / 2, 0); - *y = MAX((g_graphics_state.vinfo.yres - h) / 2, 0); -} - -void i_get_window_position(int *x, int *y, int w, int h) -{ - /* in fullscreen mode, the window "position" still matters, because - * we use it to control which display we run fullscreen on. - */ - - if (fullscreen) - { - center_window(x, y, w, h); - return; - } -} - -void i_init_graphics(void) -{ - uint8_t xscale; - uint8_t yscale; - unsigned i; - int err; - byte *doompal; - - /* Open frame buffer */ - - g_graphics_state.fd = open(CONFIG_GAMES_NXDOOM_FBPATH, O_RDWR | O_CLOEXEC); - if (g_graphics_state.fd < 0) - { - i_error("Failed to open frame buffer: %d", errno); - } - - /* Get frame buffer characteristics */ - - err = ioctl(g_graphics_state.fd, FBIOGET_VIDEOINFO, - (unsigned long)(uintptr_t)&g_graphics_state.vinfo); - if (err < 0) - { - close(g_graphics_state.fd); - i_error("Failed to get video info: %d", errno); - } - - /* Here, we check the dimensions of the frame buffer. If we have enough - * space to scale up the rendered image in both width and height, record - * that so we can make use of it elsewhere. - * - * If we don't have enough frame buffer space for the game, quit! - */ - - if (g_graphics_state.vinfo.xres < SCREENWIDTH) - { - i_error("Resolution width of %u px < minimum of %u px\n", - g_graphics_state.vinfo.xres, SCREENWIDTH); - } - - if (g_graphics_state.vinfo.yres < SCREENHEIGHT) - { - i_error("Resolution height of %u px < minimum of %u px\n", - g_graphics_state.vinfo.yres, SCREENHEIGHT); - } - - xscale = g_graphics_state.vinfo.xres / SCREENWIDTH; - yscale = g_graphics_state.vinfo.yres / SCREENHEIGHT; - g_graphics_state.scale = xscale > yscale ? yscale : xscale; - -#ifdef CONFIG_GAMES_NXDOOM_FILLSCREEN - /* Stretch to the whole display. The scale factor is then generally not an - * integer, which the column map below takes care of. - */ - - g_graphics_state.outw = g_graphics_state.vinfo.xres; - g_graphics_state.outh = g_graphics_state.vinfo.yres; -#else - g_graphics_state.outw = SCREENWIDTH * g_graphics_state.scale; - g_graphics_state.outh = SCREENHEIGHT * g_graphics_state.scale; -#endif - - /* Centre the scaled image in the frame buffer */ - - g_graphics_state.origin = - (g_graphics_state.vinfo.yres - g_graphics_state.outh) / 2 * - g_graphics_state.pinfo.stride + - (g_graphics_state.vinfo.xres - g_graphics_state.outw) / 2 * - (g_graphics_state.pinfo.bpp >> 3); - - /* Build the output column to source column map once */ - - g_graphics_state.colmap = malloc(g_graphics_state.outw * sizeof(uint16_t)); - if (g_graphics_state.colmap == NULL) - { - i_error("Couldn't allocate column map: %d\n", errno); - } - - for (i = 0; i < g_graphics_state.outw; i++) - { - g_graphics_state.colmap[i] = i * SCREENWIDTH / g_graphics_state.outw; - } - - /* Get frame buffer plane info */ - - if (ioctl(g_graphics_state.fd, FBIOGET_PLANEINFO, - (unsigned long)((uintptr_t)&g_graphics_state.pinfo)) < 0) - { - i_error("ioctl(FBIOGET_PLANEINFO) failed: %d\n", errno); - } - - /* Initialize frame buffer memory for actual rendering */ - - g_graphics_state.fbmem = - mmap(NULL, g_graphics_state.pinfo.fblen, PROT_READ | PROT_WRITE, - MAP_SHARED | MAP_FILE, g_graphics_state.fd, 0); - if (g_graphics_state.fbmem == MAP_FAILED) - { - i_error("mmap() of frame buffer failed: %d\n", errno); - } - - /* Create an 8-bit depth screen buffer for DOOM to render to */ - -#ifdef CONFIG_GAMES_NXDOOM_STATIC_SCRNBUF - g_graphics_state.scrnbuf = g_scrnbuf; -#else - g_graphics_state.scrnbuf = malloc(SCREENWIDTH * SCREENHEIGHT); -#endif - if (g_graphics_state.scrnbuf == NULL) - { - i_error("Couldn't allocate screen buffer: %d\n", errno); - } - - /* Create the game window; this may switch graphic modes depending - * on configuration. - * AdjustWindowSize(); - */ - - set_video_mode(); - - /* Start with a clear black screen - * (screen will be flipped after we set the palette) - */ - - memset(g_graphics_state.scrnbuf, 0, SCREENHEIGHT * SCREENWIDTH); - - /* Set the palette */ - - doompal = w_cache_lump_name(("PLAYPAL"), PU_CACHE); - i_set_palette(doompal); - - update_grab(); - - /* On some systems, it takes a second or so for the screen to settle - * after changing modes. We include the option to add a delay when - * setting the screen mode, so that the game doesn't start immediately - * with the player unable to see anything. - */ - - if (fullscreen && !screensaver_mode) - { - usleep(startup_delay * 1000); - } - - /* The actual 320x200 canvas that we draw to. This is the pixel buffer of - * the 8-bit paletted screen buffer that gets blit on an intermediate - * 32-bit RGBA screen buffer that gets loaded into a texture that gets - * finally rendered into our window or full screen in i_finish_update(). - */ - - i_video_buffer = g_graphics_state.scrnbuf; - v_restore_buffer(); - - /* Clear the screen to black. */ - - memset(i_video_buffer, 0, - SCREENWIDTH * SCREENHEIGHT * sizeof(*i_video_buffer)); - - /* clear out any events waiting at the start and center the mouse */ - - g_graphics_state.inited = true; - - /* Call i_shutdown_graphics on quit */ - - i_at_exit(i_shutdown_graphics, true); -} - -/* Bind all variables controlling video options into the configuration - * file system. - */ - -void i_bind_video_variables(void) -{ - m_bind_int_variable("use_mouse", &usemouse); - m_bind_int_variable("fullscreen", &fullscreen); - m_bind_int_variable("video_display", &video_display); - m_bind_int_variable("integer_scaling", &integer_scaling); - m_bind_int_variable("smooth_pixel_scaling", &smooth_pixel_scaling); - m_bind_int_variable("vga_porch_flash", &vga_porch_flash); - m_bind_int_variable("startup_delay", &startup_delay); - m_bind_int_variable("fullscreen_width", &fullscreen_width); - m_bind_int_variable("fullscreen_height", &fullscreen_height); - m_bind_int_variable("force_software_renderer", &force_software_renderer); - m_bind_int_variable("max_scaling_buffer_pixels", - &max_scaling_buffer_pixels); - m_bind_int_variable("window_width", &window_width); - m_bind_int_variable("window_height", &window_height); - m_bind_int_variable("grabmouse", &grabmouse); - m_bind_string_variable("video_driver", &video_driver); - m_bind_string_variable("window_position", &window_position); - m_bind_int_variable("usegamma", &usegamma); - m_bind_int_variable("png_screenshots", &png_screenshots); -} diff --git a/games/NXDoom/src/i_video.h b/games/NXDoom/src/i_video.h deleted file mode 100644 index 322160f9b..000000000 --- a/games/NXDoom/src/i_video.h +++ /dev/null @@ -1,154 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/i_video.h - * - * SPDX-License-Identifier: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * System specific interface stuff. - * - ****************************************************************************/ - -#ifndef __I_VIDEO__ -#define __I_VIDEO__ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "doomtype.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* Screen width and height. */ - -#define SCREENWIDTH 320 -#define SCREENHEIGHT 200 - -/* Screen height used when aspect_ratio_correct=true. */ - -#define SCREENHEIGHT_4_3 240 - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -typedef boolean (*grabmouse_callback_t)(void); - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -extern char *video_driver; -extern boolean screenvisible; - -extern int vanilla_keyboard_mapping; -extern boolean screensaver_mode; -extern int usegamma; -extern pixel_t *i_video_buffer; - -extern int screen_width; -extern int screen_height; -extern int fullscreen; -extern int aspect_ratio_correct; -extern int integer_scaling; -extern int smooth_pixel_scaling; -extern int vga_porch_flash; -extern int force_software_renderer; - -extern int png_screenshots; - -extern char *window_position; - -/* Joystic/gamepad hysteresis */ - -extern unsigned int joywait; - -extern int usemouse; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Name: i_init_graphics - * - * Description: - * Called by d_doom_main, determines the hardware configuration and sets up - * the video mode. - * - ****************************************************************************/ - -void i_init_graphics(void); - -void i_graphics_check_commandline(void); - -void i_shutdown_graphics(void); - -/**************************************************************************** - * Name: i_set_palette - * - * Description: - * Takes full 8 bit values. - * - ****************************************************************************/ - -void i_set_palette(byte *palette); - -int i_get_palette_index(int r, int g, int b); - -void i_update_no_blit(void); -void i_finish_update(void); - -void i_read_screen(pixel_t *scr); - -void i_set_window_title(const char *title); - -void i_check_is_screensaver(void); -void i_set_grab_mouse_callback(grabmouse_callback_t func); - -void i_display_fps_dots(boolean dots_on); -void i_bind_video_variables(void); - -void i_init_window_title(void); - -/**************************************************************************** - * Name: i_start_frame - * - * Description: - * Called before processing any tics in a frame (just after displaying a - * frame). Time consuming synchronous operations are performed here - * (joystick reading). - * - ****************************************************************************/ - -void i_start_frame(void); - -/**************************************************************************** - * Name: i_start_tic - * - * Description: - * Called before processing each tic in a frame. Quick synchronous - * operations are performed here. - * - ****************************************************************************/ - -void i_start_tic(void); - -void i_get_window_position(int *x, int *y, int w, int h); - -#endif /* __I_VIDEO__ */ diff --git a/games/NXDoom/src/m_argv.c b/games/NXDoom/src/m_argv.c deleted file mode 100644 index a9b0ccd14..000000000 --- a/games/NXDoom/src/m_argv.c +++ /dev/null @@ -1,349 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/m_argv.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include -#include - -#include "d_iwad.h" -#include "doomtype.h" -#include "i_system.h" -#include "m_argv.h" -#include "m_misc.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define MAXARGVS 100 - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -int myargc; -char **myargv; - -char *exedir = NULL; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static void load_response_file(int argv_index, const char *filename) -{ - FILE *handle; - int size; - char *infile; - char *file; - char **newargv; - int newargc; - int i; - int k; - - /* Read the response file into memory */ - - handle = fopen(filename, "rb"); - - if (handle == NULL) - { - printf("\nNo such response file!"); - exit(1); - } - - printf("Found response file %s!\n", filename); - - size = m_file_length(handle); - - /* Read in the entire file - * Allocate one byte extra - this is in case there is an argument - * at the end of the response file, in which case a '\0' will be - * needed. - */ - - file = malloc(size + 1); - - i = 0; - - while (i < size) - { - k = fread(file + i, 1, size - i, handle); - - if (k < 0) - { - i_error("Failed to read full contents of '%s'", filename); - } - - i += k; - } - - fclose(handle); - - /* Create new arguments list array */ - - newargv = malloc(sizeof(char *) * MAXARGVS); - newargc = 0; - memset(newargv, 0, sizeof(char *) * MAXARGVS); - - /* Copy all the arguments in the list up to the response file */ - - if (argv_index >= MAXARGVS) - { - i_error("Too many arguments up to the response file!"); - } - - for (i = 0; i < argv_index; ++i) - { - newargv[i] = myargv[i]; - myargv[i] = NULL; - ++newargc; - } - - infile = file; - k = 0; - - while (k < size) - { - /* Skip past space characters to the next argument */ - - while (k < size && isspace(infile[k])) - { - ++k; - } - - if (k >= size) - { - break; - } - - /* If the next argument is enclosed in quote marks, treat - * the contents as a single argument. This allows long filenames - * to be specified. - */ - - if (infile[k] == '\"') - { - char *argstart; - - /* Skip the first character(") */ - - ++k; - - argstart = &infile[k]; - - /* Read all characters between quotes */ - - while (k < size && infile[k] != '\"' && infile[k] != '\n') - { - ++k; - } - - if (k >= size || infile[k] == '\n') - { - i_error("Quotes unclosed in response file '%s'", filename); - } - - /* Cut off the string at the closing quote */ - - infile[k] = '\0'; - ++k; - - if (newargc >= MAXARGVS) - { - i_error("Too many arguments in the response file!"); - } - - newargv[newargc++] = m_string_duplicate(argstart); - } - else - { - char *argstart; - - /* Read in the next argument until a space is reached */ - - argstart = &infile[k]; - - while (k < size && !isspace(infile[k])) - { - ++k; - } - - /* Cut off the end of the argument at the first space */ - - infile[k] = '\0'; - ++k; - - if (newargc >= MAXARGVS) - { - i_error("Too many arguments in the response file!"); - } - - newargv[newargc++] = m_string_duplicate(argstart); - } - } - - /* Add arguments following the response file argument */ - - if (newargc + myargc - (argv_index + 1) >= MAXARGVS) - { - i_error("Too many arguments following the response file!"); - } - - for (i = argv_index + 1; i < myargc; ++i) - { - newargv[newargc] = myargv[i]; - myargv[i] = NULL; - ++newargc; - } - - /* Free any old strings in myargv which were not moved to newargv */ - - for (i = 0; i < myargc; ++i) - { - if (myargv[i] != NULL) - { - free(myargv[i]); - myargv[i] = NULL; - } - } - - free(myargv); - myargv = newargv; - myargc = newargc; - - free(file); - -#if 0 - /* Disabled - Vanilla Doom does not do this. - * Display arguments - */ - - printf("%d command-line args:\n", myargc); - - for (k = 1; k < myargc; k++) - { - printf("'%s'\n", myargv[k]); - } -#endif -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/* m_check_parm - * Checks for the given parameter in the program's command line arguments. - * Returns the argument number (1 to argc-1) or 0 if not present - */ - -int m_check_parm_with_args(const char *check, int num_args) -{ - int i; - - /* Check if myargv[i] has been set to NULL in load_response_file(), - * which may call i_error(), which in turn calls m_parm_exists("-nogui"). - */ - - for (i = 1; i < myargc - num_args && myargv[i]; i++) - { - if (!strcasecmp(check, myargv[i])) return i; - } - - return 0; -} - -/* m_parm_exists - * - * Returns true if the given parameter exists in the program's command - * line arguments, false if not. - */ - -boolean m_parm_exists(const char *check) -{ - return m_check_parm(check) != 0; -} - -int m_check_parm(const char *check) -{ - return m_check_parm_with_args(check, 0); -} - -/* Find a Response File */ - -void m_find_response_file(void) -{ - int i; - - for (i = 1; i < myargc; i++) - { - if (myargv[i][0] == '@') - { - load_response_file(i, myargv[i] + 1); - } - } - - for (; ; ) - { - /* @arg - * - * Load extra command-line arguments from the given response - * file. Arguments read from the file are inserted into the - * command line, replacing this argument. A response file can - * also be loaded using the abbreviated syntax '@file.rsp'. - */ - - i = m_check_parm_with_args("-response", 1); - if (i <= 0) - { - break; - } - - /* Replace the -response argument so that the next time through - * the loop we'll ignore it. Since some parameters stop reading when - * an argument beginning with a '-' is encountered, we keep something - * that starts with a '-'. - */ - - free(myargv[i]); - myargv[i] = m_string_duplicate("-_"); - load_response_file(i + 1, myargv[i + 1]); - } -} - -/* Return the name of the executable used to start the program: */ - -const char *m_get_executable_name(void) -{ - return m_base_name(myargv[0]); -} - -void m_set_exe_dir(void) -{ - char *dirname; - - dirname = m_dir_name(myargv[0]); - exedir = m_string_join(dirname, DIR_SEPARATOR_S, NULL); - free(dirname); -} diff --git a/games/NXDoom/src/m_argv.h b/games/NXDoom/src/m_argv.h deleted file mode 100644 index bb7f6a8cb..000000000 --- a/games/NXDoom/src/m_argv.h +++ /dev/null @@ -1,92 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/m_argv.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - ****************************************************************************/ - -#ifndef __M_ARGV__ -#define __M_ARGV__ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "doomtype.h" - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -extern int myargc; -extern char **myargv; - -extern char *exedir; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -void m_set_exe_dir(void); - -/**************************************************************************** - * Name: m_check_parm - * - * Description: - * Returns the position of the given parameter in the arg list. - * - * Returns: - * The position of the given parameter in the arg list (0 if not found). - * - ****************************************************************************/ - -int m_check_parm(const char *check); - -/**************************************************************************** - * Name: m_check_parm_with_args - * - * Description: - * Same as m_check_parm, but checks that num_args arguments are available - * following the specified argument. - * - ****************************************************************************/ - -int m_check_parm_with_args(const char *check, int num_args); - -void m_find_response_file(void); -void m_add_loose_files(void); - -/**************************************************************************** - * Name: m_parm_exists - * - * Description: - * Parameter has been specified? - * - ****************************************************************************/ - -boolean m_parm_exists(const char *check); - -/**************************************************************************** - * Name: m_get_executable_name - * - * Description: - * Get name of executable used to run this program. - * - ****************************************************************************/ - -const char *m_get_executable_name(void); - -#endif diff --git a/games/NXDoom/src/m_bbox.c b/games/NXDoom/src/m_bbox.c deleted file mode 100644 index 226237fbb..000000000 --- a/games/NXDoom/src/m_bbox.c +++ /dev/null @@ -1,53 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/m_bbox.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Main loop menu stuff. - * Random number LUT. - * Default Config File. - * PCX Screenshots. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "m_bbox.h" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -void m_clear_box(fixed_t *box) -{ - box[BOXTOP] = box[BOXRIGHT] = INT_MIN; - box[BOXBOTTOM] = box[BOXLEFT] = INT_MAX; -} - -void m_add_to_box(fixed_t *box, fixed_t x, fixed_t y) -{ - if (x < box[BOXLEFT]) - box[BOXLEFT] = x; - else if (x > box[BOXRIGHT]) - box[BOXRIGHT] = x; - if (y < box[BOXBOTTOM]) - box[BOXBOTTOM] = y; - else if (y > box[BOXTOP]) - box[BOXTOP] = y; -} diff --git a/games/NXDoom/src/m_bbox.h b/games/NXDoom/src/m_bbox.h deleted file mode 100644 index a36d545d5..000000000 --- a/games/NXDoom/src/m_bbox.h +++ /dev/null @@ -1,59 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/m_bbox.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Nil. - * - ****************************************************************************/ - -#ifndef __M_BBOX__ -#define __M_BBOX__ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include "m_fixed.h" - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -/* Bounding box coordinate storage. */ - -enum -{ - BOXTOP, - BOXBOTTOM, - BOXLEFT, - BOXRIGHT -}; /* bbox coordinates */ - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/* Bounding box functions. */ - -void m_clear_box(fixed_t *box); - -void m_add_to_box(fixed_t *box, fixed_t x, fixed_t y); - -#endif /* __M_BBOX__ */ diff --git a/games/NXDoom/src/m_cheat.c b/games/NXDoom/src/m_cheat.c deleted file mode 100644 index 038d77107..000000000 --- a/games/NXDoom/src/m_cheat.c +++ /dev/null @@ -1,95 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/m_cheat.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Cheat sequence checking. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include "doomtype.h" -#include "m_cheat.h" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/* CHEAT SEQUENCE PACKAGE */ - -/* Called in st_stuff module, which handles the input. - * Returns a 1 if the cheat was successful, 0 if failed. - */ - -int cht_check_cheat(cheatseq_t *cht, char key) -{ - /* if we make a short sequence on a cheat with parameters, this - * will not work in vanilla doom. behave the same. - */ - - if (cht->parameter_chars > 0 && strlen(cht->sequence) < cht->sequence_len) - { - return false; - } - - if (cht->chars_read < strlen(cht->sequence)) - { - /* still reading characters from the cheat code - * and verifying. reset back to the beginning - * if a key is wrong - */ - - if (key == cht->sequence[cht->chars_read]) - ++cht->chars_read; - else - cht->chars_read = 0; - - cht->param_chars_read = 0; - } - else if (cht->param_chars_read < cht->parameter_chars) - { - /* we have passed the end of the cheat sequence and are - * entering parameters now - */ - - cht->parameter_buf[cht->param_chars_read] = key; - - ++cht->param_chars_read; - } - - if (cht->chars_read >= strlen(cht->sequence) && - cht->param_chars_read >= cht->parameter_chars) - { - cht->chars_read = cht->param_chars_read = 0; - - return true; - } - - /* cheat not matched yet */ - - return false; -} - -void ch_get_param(cheatseq_t *cht, char *buffer) -{ - memcpy(buffer, cht->parameter_buf, cht->parameter_chars); -} diff --git a/games/NXDoom/src/m_cheat.h b/games/NXDoom/src/m_cheat.h deleted file mode 100644 index 8fa745615..000000000 --- a/games/NXDoom/src/m_cheat.h +++ /dev/null @@ -1,68 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/m_cheat.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Cheat code checking. - * - ****************************************************************************/ - -#ifndef __M_CHEAT__ -#define __M_CHEAT__ - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* CHEAT SEQUENCE PACKAGE */ - -/* declaring a cheat */ - -#define CHEAT(value, parameters) \ - {value, sizeof(value) - 1, parameters, 0, 0, ""} - -#define MAX_CHEAT_LEN 25 -#define MAX_CHEAT_PARAMS 5 - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -typedef struct -{ - /* settings for this cheat */ - - char sequence[MAX_CHEAT_LEN]; - size_t sequence_len; - int parameter_chars; - - /* state used during the game */ - - size_t chars_read; - int param_chars_read; - char parameter_buf[MAX_CHEAT_PARAMS]; -} cheatseq_t; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -int cht_check_cheat(cheatseq_t *cht, char key); - -void ch_get_param(cheatseq_t *cht, char *buffer); - -#endif /* __M_CHEAT__ */ diff --git a/games/NXDoom/src/m_config.c b/games/NXDoom/src/m_config.c deleted file mode 100644 index d4441f5ea..000000000 --- a/games/NXDoom/src/m_config.c +++ /dev/null @@ -1,2494 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/m_config.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 1993-2008 Raven Software - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Configuration file interface. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include -#include -#include -#include -#include - -#include "config.h" - -#include "doomkeys.h" -#include "doomtype.h" -#include "i_system.h" -#include "m_argv.h" -#include "m_config.h" -#include "m_misc.h" - -#include "z_zone.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define CONFIG_VARIABLE_GENERIC(name, type) {#name, {NULL}, type, 0, 0, false} - -#define CONFIG_VARIABLE_KEY(name) CONFIG_VARIABLE_GENERIC(name, DEFAULT_KEY) -#define CONFIG_VARIABLE_INT(name) CONFIG_VARIABLE_GENERIC(name, DEFAULT_INT) -#define CONFIG_VARIABLE_INT_HEX(name) \ - CONFIG_VARIABLE_GENERIC(name, DEFAULT_INT_HEX) -#define CONFIG_VARIABLE_FLOAT(name) \ - CONFIG_VARIABLE_GENERIC(name, DEFAULT_FLOAT) -#define CONFIG_VARIABLE_STRING(name) \ - CONFIG_VARIABLE_GENERIC(name, DEFAULT_STRING) - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -typedef enum -{ - DEFAULT_INT, - DEFAULT_INT_HEX, - DEFAULT_STRING, - DEFAULT_FLOAT, - DEFAULT_KEY, -} default_type_t; - -typedef struct -{ - /* Name of the variable */ - - const char *name; - - /* Pointer to the location in memory of the variable */ - - union - { - int *i; - char **s; - float *f; - } location; - - /* Type of the variable */ - - default_type_t type; - - /* If this is a key value, the original integer scancode we read from - * the config file before translating it to the internal key value. - * If zero, we didn't read this value from a config file. - */ - - int untranslated; - - /* The value we translated the scancode into when we read the - * config file on startup. If the variable value is different from - * this, it has been changed and needs to be converted; otherwise, - * use the 'untranslated' value. - */ - - int original_translated; - - /* If true, this config variable has been bound to a variable - * and is being used. - */ - - boolean bound; -} default_t; - -typedef struct -{ - default_t *defaults; - int numdefaults; - const char *filename; -} default_collection_t; - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static char *autoload_path = ""; - -/* Default filenames for configuration files. */ - -static const char *default_main_config; -static const char *default_extra_config; - -/* @begin_config_file default */ - -static default_t doom_defaults_list[] = -{ - /* Mouse sensitivity. This value is used to multiply input mouse - * movement to control the effect of moving the mouse. - * - * The "normal" maximum value available for this through the - * in-game options menu is 9. A value of 31 or greater will cause - * the game to crash when entering the options menu. - * - */ - - CONFIG_VARIABLE_INT(mouse_sensitivity), - - /* Volume of sound effects, range 0-15. */ - - CONFIG_VARIABLE_INT(sfx_volume), - - /* Volume of in-game music, range 0-15. */ - - CONFIG_VARIABLE_INT(music_volume), - - /* @game strife - * - * If non-zero, dialogue text is displayed over characters' pictures - * when engaging actors who have voices. - */ - - CONFIG_VARIABLE_INT(show_talk), - - /* @game strife - * - * Volume of voice sound effects, range 0-15. - */ - - CONFIG_VARIABLE_INT(voice_volume), - - /* @game doom - * - * If non-zero, messages are displayed on the heads-up display - * in the game ("picked up a clip", etc). If zero, these messages - * are not displayed. - */ - - CONFIG_VARIABLE_INT(show_messages), - - /* Keyboard key to turn right. */ - - CONFIG_VARIABLE_KEY(key_right), - - /* Keyboard key to turn left. */ - - CONFIG_VARIABLE_KEY(key_left), - - /* Keyboard key to move forward. */ - - CONFIG_VARIABLE_KEY(key_up), - - /* Keyboard key to move backward. */ - - CONFIG_VARIABLE_KEY(key_down), - - /* Keyboard key to strafe left. */ - - CONFIG_VARIABLE_KEY(key_strafeleft), - - /* Keyboard key to strafe right. */ - - CONFIG_VARIABLE_KEY(key_straferight), - - /* @game strife - * - * Keyboard key to use health. - */ - - CONFIG_VARIABLE_KEY(key_use_health), - - /* @game hexen - * - * Keyboard key to jump. - */ - - CONFIG_VARIABLE_KEY(key_jump), - - /* @game heretic hexen - * - * Keyboard key to fly upward. - */ - - CONFIG_VARIABLE_KEY(key_flyup), - - /* @game heretic hexen - * - * Keyboard key to fly downwards. - */ - - CONFIG_VARIABLE_KEY(key_flydown), - - /* @game heretic hexen - * - * Keyboard key to center flying. - */ - - CONFIG_VARIABLE_KEY(key_flycenter), - - /* @game heretic hexen - * - * Keyboard key to look up. - */ - - CONFIG_VARIABLE_KEY(key_lookup), - - /* @game heretic hexen - * - * Keyboard key to look down. - */ - - CONFIG_VARIABLE_KEY(key_lookdown), - - /* @game heretic hexen - * - * Keyboard key to center the view. - */ - - CONFIG_VARIABLE_KEY(key_lookcenter), - - /* @game strife - * - * Keyboard key to query inventory. - */ - - CONFIG_VARIABLE_KEY(key_invquery), - - /* @game strife - * - * Keyboard key to display mission objective. - */ - - CONFIG_VARIABLE_KEY(key_mission), - - /* @game strife - * - * Keyboard key to display inventory popup. - */ - - CONFIG_VARIABLE_KEY(key_inv_pop), - - /* @game strife - * - * Keyboard key to display keys popup. - */ - - CONFIG_VARIABLE_KEY(key_inv_key), - - /* @game strife - * - * Keyboard key to jump to start of inventory. - */ - - CONFIG_VARIABLE_KEY(key_inv_home), - - /* @game strife - * - * Keyboard key to jump to end of inventory. - */ - - CONFIG_VARIABLE_KEY(key_inv_end), - - /* @game heretic hexen - * - * Keyboard key to scroll left in the inventory. - */ - - CONFIG_VARIABLE_KEY(key_invleft), - - /* @game heretic hexen - * - * Keyboard key to scroll right in the inventory. - */ - - CONFIG_VARIABLE_KEY(key_invright), - - /* @game strife - * - * Keyboard key to scroll left in the inventory. - */ - - CONFIG_VARIABLE_KEY(key_inv_left), - - /* @game strife - * - * Keyboard key to scroll right in the inventory. - */ - - CONFIG_VARIABLE_KEY(key_inv_right), - - /* @game heretic hexen - * - * Keyboard key to use the current item in the inventory. - */ - - CONFIG_VARIABLE_KEY(key_useartifact), - - /* @game strife - * - * Keyboard key to use inventory item. - */ - - CONFIG_VARIABLE_KEY(key_inv_use), - - /* @game strife - * - * Keyboard key to drop an inventory item. - */ - - CONFIG_VARIABLE_KEY(key_inv_drop), - - /* @game strife - * - * Keyboard key to look up. - */ - - CONFIG_VARIABLE_KEY(key_look_up), - - /* @game strife - * - * Keyboard key to look down. - */ - - CONFIG_VARIABLE_KEY(key_look_down), - - /* Keyboard key to fire the currently selected weapon. */ - - CONFIG_VARIABLE_KEY(key_fire), - - /* Keyboard key to "use" an object, eg. a door or switch. */ - - CONFIG_VARIABLE_KEY(key_use), - - /* Keyboard key to turn on strafing. When held down, pressing the - * key to turn left or right causes the player to strafe left or - * right instead. - */ - - CONFIG_VARIABLE_KEY(key_strafe), - - /* Keyboard key to make the player run. */ - - CONFIG_VARIABLE_KEY(key_speed), - - /* If non-zero, mouse input is enabled. If zero, mouse input is - * disabled. - */ - - CONFIG_VARIABLE_INT(use_mouse), - - /* Mouse button to fire the currently selected weapon. */ - - CONFIG_VARIABLE_INT(mouseb_fire), - - /* Mouse button to turn on strafing. When held down, the player - * will strafe left and right instead of turning left and right. - */ - - CONFIG_VARIABLE_INT(mouseb_strafe), - - /* Mouse button to move forward. */ - - CONFIG_VARIABLE_INT(mouseb_forward), - - /* Mouse button to turn on running. When held down, the player - * will run while moving. - */ - - CONFIG_VARIABLE_INT(mouseb_speed), - - /* @game hexen strife - * - * Mouse button to jump. - */ - - CONFIG_VARIABLE_INT(mouseb_jump), - - /* If non-zero, joystick input is enabled. */ - - CONFIG_VARIABLE_INT(use_joystick), - - /* Joystick virtual button that fires the current weapon. */ - - CONFIG_VARIABLE_INT(joyb_fire), - - /* Joystick virtual button that makes the player strafe while - * held down. - */ - - CONFIG_VARIABLE_INT(joyb_strafe), - - /* Joystick virtual button to "use" an object, eg. a door or switch. */ - - CONFIG_VARIABLE_INT(joyb_use), - - /* Joystick virtual button that makes the player run while held - * down. - * - * If this has a value of 20 or greater, the player will always run, - * even if use_joystick is 0. - */ - - CONFIG_VARIABLE_INT(joyb_speed), - - /* @game hexen strife - * - * Joystick virtual button that makes the player jump. - */ - - CONFIG_VARIABLE_INT(joyb_jump), - - /* @game doom heretic hexen - * - * Screen size, range 3-11. - * - * A value of 11 gives a full-screen view with the status bar not - * displayed. A value of 10 gives a full-screen view with the - * status bar displayed. - */ - - CONFIG_VARIABLE_INT(screenblocks), - - /* @game strife - * - * Screen size, range 3-11. - * - * A value of 11 gives a full-screen view with the status bar not - * displayed. A value of 10 gives a full-screen view with the - * status bar displayed. - */ - - CONFIG_VARIABLE_INT(screensize), - - /* @game doom - * - * Screen detail. Zero gives normal "high detail" mode, while - * a non-zero value gives "low detail" mode. - */ - - CONFIG_VARIABLE_INT(detaillevel), - - /* Number of sounds that will be played simultaneously. */ - - CONFIG_VARIABLE_INT(snd_channels), - - /* Music output device. A non-zero value gives MIDI sound output, - * while a value of zero disables music. - */ - - CONFIG_VARIABLE_INT(snd_musicdevice), - - /* Sound effects device. A value of zero disables in-game sound - * effects, a value of 1 enables PC speaker sound effects, while - * a value in the range 2-9 enables the "normal" digital sound - * effects. - */ - - CONFIG_VARIABLE_INT(snd_sfxdevice), - - /* SoundBlaster I/O port. Unused. */ - - CONFIG_VARIABLE_INT(snd_sbport), - - /* SoundBlaster IRQ. Unused. */ - - CONFIG_VARIABLE_INT(snd_sbirq), - - /* SoundBlaster DMA channel. Unused. */ - - CONFIG_VARIABLE_INT(snd_sbdma), - - /* Output port to use for OPL MIDI playback. Unused. */ - - CONFIG_VARIABLE_INT(snd_mport), - - /* Gamma correction level. A value of zero disables gamma - * correction, while a value in the range 1-4 gives increasing - * levels of gamma correction. - */ - - CONFIG_VARIABLE_INT(usegamma), - - /* @game hexen - * - * Directory in which to store savegames. - */ - - CONFIG_VARIABLE_STRING(savedir), - - /* @game hexen - * - * Controls whether messages are displayed in the heads-up display. - * If this has a non-zero value, messages are displayed. - */ - - CONFIG_VARIABLE_INT(messageson), - - /* @game strife - * - * Name of background flat used by view border. - */ - - CONFIG_VARIABLE_STRING(back_flat), - - /* @game strife - * - * Multiplayer nickname (?). - */ - - CONFIG_VARIABLE_STRING(nickname), - - /* Multiplayer chat macro: message to send when alt+0 is pressed. */ - - CONFIG_VARIABLE_STRING(chatmacro0), - - /* Multiplayer chat macro: message to send when alt+1 is pressed. */ - - CONFIG_VARIABLE_STRING(chatmacro1), - - /* Multiplayer chat macro: message to send when alt+2 is pressed. */ - - CONFIG_VARIABLE_STRING(chatmacro2), - - /* Multiplayer chat macro: message to send when alt+3 is pressed. */ - - CONFIG_VARIABLE_STRING(chatmacro3), - - /* Multiplayer chat macro: message to send when alt+4 is pressed. */ - - CONFIG_VARIABLE_STRING(chatmacro4), - - /* Multiplayer chat macro: message to send when alt+5 is pressed. */ - - CONFIG_VARIABLE_STRING(chatmacro5), - - /* Multiplayer chat macro: message to send when alt+6 is pressed. */ - - CONFIG_VARIABLE_STRING(chatmacro6), - - /* Multiplayer chat macro: message to send when alt+7 is pressed. */ - - CONFIG_VARIABLE_STRING(chatmacro7), - - /* Multiplayer chat macro: message to send when alt+8 is pressed. */ - - CONFIG_VARIABLE_STRING(chatmacro8), - - /* Multiplayer chat macro: message to send when alt+9 is pressed. */ - - CONFIG_VARIABLE_STRING(chatmacro9), - - /* @game strife - * - * Serial port number to use for SERSETUP.EXE (unused). - */ - - CONFIG_VARIABLE_INT(comport), -}; - -static default_collection_t doom_defaults = -{ - doom_defaults_list, - arrlen(doom_defaults_list), - NULL, -}; - -/* @begin_config_file extended */ - -static default_t extra_defaults_list[] = -{ - /* Name of the SDL video driver to use. If this is an empty string, - * the default video driver is used. - */ - - CONFIG_VARIABLE_STRING(video_driver), - - /* Position of the window on the screen when running in windowed - * mode. Accepted values are: "" (empty string) - don't care, - * "center" - place window at center of screen, "x,y" - place - * window at the specified coordinates. - */ - - CONFIG_VARIABLE_STRING(window_position), - - /* If non-zero, the game will run in full screen mode. If zero, - * the game will run in a window. - */ - - CONFIG_VARIABLE_INT(fullscreen), - - /* Index of the display on which the game should run. This has no - * effect if running in windowed mode (fullscreen=0) and - * window_position is not set to "center". - */ - - CONFIG_VARIABLE_INT(video_display), - - /* If non-zero, the screen will be stretched vertically to display - * correctly on a square pixel video mode. - */ - - CONFIG_VARIABLE_INT(aspect_ratio_correct), - - /* If non-zero, the screen will have smooth scaling. */ - - CONFIG_VARIABLE_INT(smooth_pixel_scaling), - - /* If non-zero, forces integer scales for resolution-independent - * rendering. - */ - - CONFIG_VARIABLE_INT(integer_scaling), - - /* If non-zero, any pillar/letter boxes drawn around the game area - * will "flash" when the game palette changes, simulating the VGA - * "porch" - */ - - CONFIG_VARIABLE_INT(vga_porch_flash), - - /* Window width when running in windowed mode. */ - - CONFIG_VARIABLE_INT(window_width), - - /* Window height when running in windowed mode. */ - - CONFIG_VARIABLE_INT(window_height), - - /* Width for screen mode when running fullscreen. - * If this and fullscreen_height are both set to zero, we run - * fullscreen as a desktop window that covers the entire screen, - * rather than ever switching screen modes. It should usually - * be unnecessary to set this value. - */ - - CONFIG_VARIABLE_INT(fullscreen_width), - - /* Height for screen mode when running fullscreen. - * See documentation for fullscreen_width. - */ - - CONFIG_VARIABLE_INT(fullscreen_height), - - /* If non-zero, force the use of a software renderer. For use on - * systems lacking hardware acceleration. - */ - - CONFIG_VARIABLE_INT(force_software_renderer), - - /* Maximum number of pixels to use for intermediate scaling buffer. - * More pixels mean that the screen can be rendered more precisely, - * but there are diminishing returns on quality. The default limits to - * 16,000,000 pixels, which is enough to cover 4K monitor standards. - */ - - CONFIG_VARIABLE_INT(max_scaling_buffer_pixels), - - /* Number of milliseconds to wait on startup after the video mode - * has been set, before the game will start. This allows the - * screen to settle on some monitors that do not display an image - * for a brief interval after changing video modes. - */ - - CONFIG_VARIABLE_INT(startup_delay), - - /* @game heretic hexen strife - * - * If non-zero, display the graphical startup screen. - */ - - CONFIG_VARIABLE_INT(graphical_startup), - - /* @game doom heretic strife - * - * If non-zero, the ENDOOM text screen is displayed when exiting the - * game. If zero, the ENDOOM screen is not displayed. - */ - - CONFIG_VARIABLE_INT(show_endoom), - - /* @game doom strife - * - * If non-zero, a disk activity indicator is displayed when data is read - * from disk. If zero, the disk activity indicator is not displayed. - */ - - CONFIG_VARIABLE_INT(show_diskicon), - - /* If non-zero, save screenshots in PNG format. If zero, screenshots are - * saved in PCX format, as Vanilla Doom does. - */ - - CONFIG_VARIABLE_INT(png_screenshots), - - /* Sound output sample rate, in Hz. Typical values to use are - * 11025, 22050, 44100 and 48000. - */ - - CONFIG_VARIABLE_INT(snd_samplerate), - - /* Maximum number of bytes to allocate for caching converted sound - * effects in memory. If set to zero, there is no limit applied. - */ - - CONFIG_VARIABLE_INT(snd_cachesize), - - /* Maximum size of the output sound buffer size in milliseconds. - * Sound output is generated periodically in slices. Higher values - * might be more efficient but will introduce latency to the - * sound output. The default is 28ms (one slice per tic with the - * 35fps timer). - */ - - CONFIG_VARIABLE_INT(snd_maxslicetime_ms), - - /* If non-zero, sound effects will have their pitch varied up or - * down by a random amount during play. If zero, sound effects - * play back at their default pitch. - */ - - CONFIG_VARIABLE_INT(snd_pitchshift), - - /* External command to invoke to perform MIDI playback. If set to - * the empty string, SDL_mixer's internal MIDI playback is used. - * This only has any effect when snd_musicdevice is set to General - * MIDI output. - */ - - CONFIG_VARIABLE_STRING(snd_musiccmd), - - /* Controls whether libsamplerate support is used for performing - * sample rate conversions of sound effects. Support for this - * must be compiled into the program. - * - * If zero, libsamplerate support is disabled. If non-zero, - * libsamplerate is enabled. Increasing values roughly correspond - * to higher quality conversion; the higher the quality, the - * slower the conversion process. Linear conversion = 1; - * Zero order hold = 2; Fast Sinc filter = 3; Medium quality - * Sinc filter = 4; High quality Sinc filter = 5. - */ - - CONFIG_VARIABLE_INT(use_libsamplerate), - - /* Scaling factor used by libsamplerate. This is used when converting - * sounds internally back into integer form; normally it should not - * be necessary to change it from the default value. The only time - * it might be needed is if a PWAD file is loaded that contains very - * loud sounds, in which case the conversion may cause sound clipping - * and the scale factor should be reduced. The lower the value, the - * quieter the sound effects become, so it should be set as high as is - * possible without clipping occurring. - */ - - CONFIG_VARIABLE_FLOAT(libsamplerate_scale), - - /* Full path to a directory in which WAD files and dehacked patches - * can be placed to be automatically loaded on startup. A subdirectory - * of this directory matching the IWAD name is checked to find the - * files to load. - */ - - CONFIG_VARIABLE_STRING(autoload_path), - - /* Full path to a directory containing configuration files for - * substitute music packs. These packs contain high quality renderings - * of game music to be played instead of using the system's built-in - * MIDI playback. - */ - - CONFIG_VARIABLE_STRING(music_pack_path), - -#ifdef HAVE_FLUIDSYNTH - /* If 1, activate the FluidSynth chorus effects module. If 0, no chorus - * will be added to the output signal. - */ - - CONFIG_VARIABLE_INT(fsynth_chorus_active), - - /* Specifies the modulation depth of the FluidSynth chorus. Default is - * 5.0, range is 0.0 to 256.0. - */ - - CONFIG_VARIABLE_FLOAT(fsynth_chorus_depth), - - /* Specifies the output amplitude of the FluidSynth chorus signal. Default - * is 0.35, range is 0.0 to 10.0. - */ - - CONFIG_VARIABLE_FLOAT(fsynth_chorus_level), - - /* Sets the voice count of the FluidSynth chorus signal. Default is 3, - * range is 0 to 99. - */ - - CONFIG_VARIABLE_INT(fsynth_chorus_nr), - - /* Sets the FluidSynth chorus modulation speed in Hz. Default is 0.3, - * range is 0.1 to 5.0. - */ - - CONFIG_VARIABLE_FLOAT(fsynth_chorus_speed), - - /* This setting defines how FluidSynth interprets Bank Select messages. - * The default is "gs". Other possible values are "gm", "xg" and "mma". - */ - - CONFIG_VARIABLE_STRING(fsynth_midibankselect), - - /* Sets the number of FluidSynth voices that can be played in parallel. - * Default is 256, range is 1 - 65535. - */ - - CONFIG_VARIABLE_INT(fsynth_polyphony), - - /* If 1, activate the FluidSynth reverb effects module. If 0, no reverb - * will be added to the output signal. - */ - - CONFIG_VARIABLE_INT(fsynth_reverb_active), - - /* Sets the amount of FluidSynth reverb damping. Default is 0.4, range is - * 0.0 to 1.0. - */ - - CONFIG_VARIABLE_FLOAT(fsynth_reverb_damp), - - /* Sets the FluidSynth reverb amplitude. Default is 0.15, range is 0.0 - - * 1.0. - */ - - CONFIG_VARIABLE_FLOAT(fsynth_reverb_level), - - /* Sets the room size(i.e. amount of wet) FluidSynth reverb. Default is - * 0.6, range is 0.0 - 1.0. - */ - - CONFIG_VARIABLE_FLOAT(fsynth_reverb_roomsize), - - /* Sets the stereo spread of the FluidSynth reverb signal. Default is - * 0.4, range is 0.0 - 100.0. - */ - - CONFIG_VARIABLE_FLOAT(fsynth_reverb_width), - - /* Fine tune the FluidSynth output level. Default is 1.0, - * range is 0.0 - 10.0. - */ - - CONFIG_VARIABLE_FLOAT(fsynth_gain), - - /* Full path to a soundfont file to use with FluidSynth MIDI playback. */ - - CONFIG_VARIABLE_STRING(fsynth_sf_path), -#endif /* HAVE_FLUIDSYNTH */ - - /* Full path to a Timidity configuration file to use for MIDI - * playback. The file will be evaluated from the directory where - * it is evaluated, so there is no need to add "dir" commands - * into it. - */ - - CONFIG_VARIABLE_STRING(timidity_cfg_path), - - /* Path to GUS patch files to use when operating in GUS emulation - * mode. - */ - - CONFIG_VARIABLE_STRING(gus_patch_path), - - /* Number of kilobytes of RAM to use in GUS emulation mode. Valid - * values are 256, 512, 768 or 1024. - */ - - CONFIG_VARIABLE_INT(gus_ram_kb), - - /* @game doom strife - * - * If non-zero, the Vanilla savegame limit is enforced; if the - * savegame exceeds 180224 bytes in size, the game will exit with - * an error. If this has a value of zero, there is no limit to - * the size of savegames. - */ - - CONFIG_VARIABLE_INT(vanilla_savegame_limit), - - /* @game doom strife - * - * If non-zero, the Vanilla demo size limit is enforced; the game - * exits with an error when a demo exceeds the demo size limit - * (128KiB by default). If this has a value of zero, there is no - * limit to the size of demos. - */ - - CONFIG_VARIABLE_INT(vanilla_demo_limit), - - /* If non-zero, the game behaves like Vanilla Doom, always assuming - * an American keyboard mapping. If this has a value of zero, the - * native keyboard mapping of the keyboard is used. - */ - - CONFIG_VARIABLE_INT(vanilla_keyboard_mapping), - - /* Name to use in network games for identification. This is only - * used on the "waiting" screen while waiting for the game to start. - */ - - CONFIG_VARIABLE_STRING(player_name), - - /* If this is non-zero, the mouse will be "grabbed" when running - * in windowed mode so that it can be used as an input device. - * When running full screen, this has no effect. - */ - - CONFIG_VARIABLE_INT(grabmouse), - - /* If non-zero, all vertical mouse movement is ignored. This - * emulates the behavior of the "novert" tool available under DOS - * that performs the same function. - */ - - CONFIG_VARIABLE_INT(novert), - - /* Mouse acceleration factor. When the speed of mouse movement - * exceeds the threshold value (mouse_threshold), the speed is - * multiplied by this value. - */ - - CONFIG_VARIABLE_FLOAT(mouse_acceleration), - - /* Mouse acceleration threshold. When the speed of mouse movement - * exceeds this threshold value, the speed is multiplied by an - * acceleration factor (mouse_acceleration). - */ - - CONFIG_VARIABLE_INT(mouse_threshold), - - /* Mouse button to strafe left. */ - - CONFIG_VARIABLE_INT(mouseb_strafeleft), - - /* Mouse button to strafe right. */ - - CONFIG_VARIABLE_INT(mouseb_straferight), - - /* Mouse button to turn left. */ - - CONFIG_VARIABLE_INT(mouseb_turnleft), - - /* Mouse button to turn right. */ - - CONFIG_VARIABLE_INT(mouseb_turnright), - - /* Mouse button to "use" an object, eg. a door or switch. */ - - CONFIG_VARIABLE_INT(mouseb_use), - - /* Mouse button to move backwards. */ - - CONFIG_VARIABLE_INT(mouseb_backward), - - /* Mouse button to cycle to the previous weapon. */ - - CONFIG_VARIABLE_INT(mouseb_prevweapon), - - /* Mouse button to cycle to the next weapon. */ - - CONFIG_VARIABLE_INT(mouseb_nextweapon), - - /* @game heretic - * - * Mouse button to move to the left in the inventory. - */ - - CONFIG_VARIABLE_INT(mouseb_invleft), - - /* @game heretic - * - * Mouse button to move to the right in the inventory. - */ - - CONFIG_VARIABLE_INT(mouseb_invright), - - /* @game heretic hexen - * - * Mouse button to use artifact. - */ - - CONFIG_VARIABLE_INT(mouseb_useartifact), - - /* If non-zero, double-clicking a mouse button acts like pressing - * the "use" key to use an object in-game, eg. a door or switch. - */ - - CONFIG_VARIABLE_INT(dclick_use), - - /* SDL GUID string indicating the joystick to use. An empty string - * indicates that no joystick is configured. - */ - - CONFIG_VARIABLE_STRING(joystick_guid), - - /* Index of SDL joystick to use; this is only used in the case where - * multiple identical joystick devices are connected which have the - * same GUID, to distinguish between devices. - */ - - CONFIG_VARIABLE_INT(joystick_index), - - /* If non-zero, use analog movement when playing with a gamepad. */ - - CONFIG_VARIABLE_INT(use_analog), - - /* Joystick axis to use to for horizontal (X) movement. */ - - CONFIG_VARIABLE_INT(joystick_x_axis), - - /* If non-zero, movement on the horizontal joystick axis is inverted. */ - - CONFIG_VARIABLE_INT(joystick_x_invert), - - /* Joystick turn analog sensitivity, specified as a value between 0 - * and 20. - */ - - CONFIG_VARIABLE_INT(joystick_turn_sensitivity), - - /* Joystick axis to use to for vertical (Y) movement. */ - - CONFIG_VARIABLE_INT(joystick_y_axis), - - /* If non-zero, movement on the vertical joystick axis is inverted. */ - - CONFIG_VARIABLE_INT(joystick_y_invert), - - /* Joystick axis to use to for strafing movement. */ - - CONFIG_VARIABLE_INT(joystick_strafe_axis), - - /* If non-zero, movement on the joystick axis used for strafing - * is inverted. - */ - - CONFIG_VARIABLE_INT(joystick_strafe_invert), - - /* Joystick move and strafe analog sensitivity, specified as a value - * between 0 and 20. - */ - - CONFIG_VARIABLE_INT(joystick_move_sensitivity), - - /* Joystick axis to use to for looking up and down. */ - - CONFIG_VARIABLE_INT(joystick_look_axis), - - /* If non-zero, movement on the joystick axis used for looking - * is inverted. - */ - - CONFIG_VARIABLE_INT(joystick_look_invert), - - /* Joystick look analog sensitivity, specified as a value between 0 - * and 20. - */ - - CONFIG_VARIABLE_INT(joystick_look_sensitivity), - - /* The physical joystick button that corresponds to joystick - * virtual button #0. - */ - - CONFIG_VARIABLE_INT(joystick_physical_button0), - - /* The physical joystick button that corresponds to joystick - * virtual button #1. - */ - - CONFIG_VARIABLE_INT(joystick_physical_button1), - - /* The physical joystick button that corresponds to joystick - * virtual button #2. - */ - - CONFIG_VARIABLE_INT(joystick_physical_button2), - - /* The physical joystick button that corresponds to joystick - * virtual button #3. - */ - - CONFIG_VARIABLE_INT(joystick_physical_button3), - - /* The physical joystick button that corresponds to joystick - * virtual button #4. - */ - - CONFIG_VARIABLE_INT(joystick_physical_button4), - - /* The physical joystick button that corresponds to joystick - * virtual button #5. - */ - - CONFIG_VARIABLE_INT(joystick_physical_button5), - - /* The physical joystick button that corresponds to joystick - * virtual button #6. - */ - - CONFIG_VARIABLE_INT(joystick_physical_button6), - - /* The physical joystick button that corresponds to joystick - * virtual button #7. - */ - - CONFIG_VARIABLE_INT(joystick_physical_button7), - - /* The physical joystick button that corresponds to joystick - * virtual button #8. - */ - - CONFIG_VARIABLE_INT(joystick_physical_button8), - - /* The physical joystick button that corresponds to joystick - * virtual button #9. - */ - - CONFIG_VARIABLE_INT(joystick_physical_button9), - - /* The physical joystick button that corresponds to joystick - * virtual button #10. - */ - - CONFIG_VARIABLE_INT(joystick_physical_button10), - - /* The physical joystick button that corresponds to joystick - * virtual button #11. - */ - - CONFIG_VARIABLE_INT(joystick_physical_button11), - - /* The physical joystick button that corresponds to joystick - * virtual button #12. - */ - - CONFIG_VARIABLE_INT(joystick_physical_button12), - - /* The physical joystick button that corresponds to joystick - * virtual button #13. - */ - - CONFIG_VARIABLE_INT(joystick_physical_button13), - - /* The physical joystick button that corresponds to joystick - * virtual button #14. - */ - - CONFIG_VARIABLE_INT(joystick_physical_button14), - - /* The physical joystick button that corresponds to joystick - * virtual button #15. - */ - - CONFIG_VARIABLE_INT(joystick_physical_button15), - - /* The physical joystick button that corresponds to joystick - * virtual button #16. - */ - - CONFIG_VARIABLE_INT(joystick_physical_button16), - - /* If non-zero, use the SDL_GameController interface instead of the - * SDL_Joystick interface. - */ - - CONFIG_VARIABLE_INT(use_gamepad), - - /* Stores the SDL_GameControllerType of the last configured gamepad. */ - - CONFIG_VARIABLE_INT(gamepad_type), - - /* Joystick x axis dead zone, specified as a percentage of the axis max - * value. - */ - - CONFIG_VARIABLE_INT(joystick_x_dead_zone), - - /* Joystick y axis dead zone, specified as a percentage of the axis max - * value. - */ - - CONFIG_VARIABLE_INT(joystick_y_dead_zone), - - /* Joystick strafe axis dead zone, specified as a percentage of the axis - * max value. - */ - - CONFIG_VARIABLE_INT(joystick_strafe_dead_zone), - - /* Joystick look axis dead zone, specified as a percentage of the axis max - * value. - */ - - CONFIG_VARIABLE_INT(joystick_look_dead_zone), - - /* Joystick virtual button to make the player strafe left. */ - - CONFIG_VARIABLE_INT(joyb_strafeleft), - - /* Joystick virtual button to make the player strafe right. */ - - CONFIG_VARIABLE_INT(joyb_straferight), - - /* Joystick virtual button to activate the menu. */ - - CONFIG_VARIABLE_INT(joyb_menu_activate), - - /* Joystick virtual button to toggle the automap. */ - - CONFIG_VARIABLE_INT(joyb_toggle_automap), - - /* Joystick virtual button that cycles to the previous weapon. */ - - CONFIG_VARIABLE_INT(joyb_prevweapon), - - /* Joystick virtual button that cycles to the next weapon. */ - - CONFIG_VARIABLE_INT(joyb_nextweapon), - - /* @game heretic hexen - * Joystick virtual button to activate artifact. - */ - - CONFIG_VARIABLE_INT(joyb_useartifact), - - /* @game heretic hexen - * Joystick virtual button to move left in the inventory. - */ - - CONFIG_VARIABLE_INT(joyb_invleft), - - /* @game heretic hexen - * Joystick virtual button to move right in the inventory. - */ - - CONFIG_VARIABLE_INT(joyb_invright), - - /* @game heretic hexen - * Joystick virtual button to fly up. - */ - - CONFIG_VARIABLE_INT(joyb_flyup), - - /* @game heretic hexen - * Joystick virtual button to fly down. - */ - - CONFIG_VARIABLE_INT(joyb_flydown), - - /* @game heretic hexen - * Joystick virtual button to center flying. - */ - - CONFIG_VARIABLE_INT(joyb_flycenter), - - /* Key to pause or unpause the game. */ - - CONFIG_VARIABLE_KEY(key_pause), - - /* Key that activates the menu when pressed. */ - - CONFIG_VARIABLE_KEY(key_menu_activate), - - /* Key that moves the cursor up on the menu. */ - - CONFIG_VARIABLE_KEY(key_menu_up), - - /* Key that moves the cursor down on the menu. */ - - CONFIG_VARIABLE_KEY(key_menu_down), - - /* Key that moves the currently selected slider on the menu left. */ - - CONFIG_VARIABLE_KEY(key_menu_left), - - /* Key that moves the currently selected slider on the menu right. */ - - CONFIG_VARIABLE_KEY(key_menu_right), - - /* Key to go back to the previous menu. */ - - CONFIG_VARIABLE_KEY(key_menu_back), - - /* Key to activate the currently selected menu item. */ - - CONFIG_VARIABLE_KEY(key_menu_forward), - - /* Key to answer 'yes' to a question in the menu. */ - - CONFIG_VARIABLE_KEY(key_menu_confirm), - - /* Key to answer 'no' to a question in the menu. */ - - CONFIG_VARIABLE_KEY(key_menu_abort), - - /* Keyboard shortcut to bring up the help screen. */ - - CONFIG_VARIABLE_KEY(key_menu_help), - - /* Keyboard shortcut to bring up the save game menu. */ - - CONFIG_VARIABLE_KEY(key_menu_save), - - /* Keyboard shortcut to bring up the load game menu. */ - - CONFIG_VARIABLE_KEY(key_menu_load), - - /* Keyboard shortcut to bring up the sound volume menu. */ - - CONFIG_VARIABLE_KEY(key_menu_volume), - - /* Keyboard shortcut to toggle the detail level. */ - - CONFIG_VARIABLE_KEY(key_menu_detail), - - /* Keyboard shortcut to quicksave the current game. */ - - CONFIG_VARIABLE_KEY(key_menu_qsave), - - /* Keyboard shortcut to end the game. */ - - CONFIG_VARIABLE_KEY(key_menu_endgame), - - /* Keyboard shortcut to toggle heads-up messages. */ - - CONFIG_VARIABLE_KEY(key_menu_messages), - - /* Keyboard shortcut to load the last quicksave. */ - - CONFIG_VARIABLE_KEY(key_menu_qload), - - /* Keyboard shortcut to quit the game. */ - - CONFIG_VARIABLE_KEY(key_menu_quit), - - /* Keyboard shortcut to toggle the gamma correction level. */ - - CONFIG_VARIABLE_KEY(key_menu_gamma), - - /* Keyboard shortcut to switch view in multiplayer. */ - - CONFIG_VARIABLE_KEY(key_spy), - - /* Keyboard shortcut to increase the screen size. */ - - CONFIG_VARIABLE_KEY(key_menu_incscreen), - - /* Keyboard shortcut to decrease the screen size. */ - - CONFIG_VARIABLE_KEY(key_menu_decscreen), - - /* Keyboard shortcut to save a screenshot. */ - - CONFIG_VARIABLE_KEY(key_menu_screenshot), - - /* Key to toggle the map view. */ - - CONFIG_VARIABLE_KEY(key_map_toggle), - - /* Key to pan north when in the map view. */ - - CONFIG_VARIABLE_KEY(key_map_north), - - /* Key to pan south when in the map view. */ - - CONFIG_VARIABLE_KEY(key_map_south), - - /* Key to pan east when in the map view. */ - - CONFIG_VARIABLE_KEY(key_map_east), - - /* Key to pan west when in the map view. */ - - CONFIG_VARIABLE_KEY(key_map_west), - - /* Key to zoom in when in the map view. */ - - CONFIG_VARIABLE_KEY(key_map_zoomin), - - /* Key to zoom out when in the map view. */ - - CONFIG_VARIABLE_KEY(key_map_zoomout), - - /* Key to zoom out the maximum amount when in the map view. */ - - CONFIG_VARIABLE_KEY(key_map_maxzoom), - - /* Key to toggle follow mode when in the map view. */ - - CONFIG_VARIABLE_KEY(key_map_follow), - - /* Key to toggle the grid display when in the map view. */ - - CONFIG_VARIABLE_KEY(key_map_grid), - - /* Key to set a mark when in the map view. */ - - CONFIG_VARIABLE_KEY(key_map_mark), - - /* Key to clear all marks when in the map view. */ - - CONFIG_VARIABLE_KEY(key_map_clearmark), - - /* Key to select weapon 1. */ - - CONFIG_VARIABLE_KEY(key_weapon1), - - /* Key to select weapon 2. */ - - CONFIG_VARIABLE_KEY(key_weapon2), - - /* Key to select weapon 3. */ - - CONFIG_VARIABLE_KEY(key_weapon3), - - /* Key to select weapon 4. */ - - CONFIG_VARIABLE_KEY(key_weapon4), - - /* Key to select weapon 5. */ - - CONFIG_VARIABLE_KEY(key_weapon5), - - /* Key to select weapon 6. */ - - CONFIG_VARIABLE_KEY(key_weapon6), - - /* Key to select weapon 7. */ - - CONFIG_VARIABLE_KEY(key_weapon7), - - /* Key to select weapon 8. */ - - CONFIG_VARIABLE_KEY(key_weapon8), - - /* Key to cycle to the previous weapon. */ - - CONFIG_VARIABLE_KEY(key_prevweapon), - - /* Key to cycle to the next weapon. */ - - CONFIG_VARIABLE_KEY(key_nextweapon), - - /* @game heretic - * - * Key to use "quartz flask" artifact. - */ - - CONFIG_VARIABLE_KEY(key_arti_quartz), - - /* @game heretic - * - * Key to use "mystic urn" artifact. - */ - - CONFIG_VARIABLE_KEY(key_arti_urn), - - /* @game heretic - * - * Key to use "timebomb of the ancients" artifact. - */ - - CONFIG_VARIABLE_KEY(key_arti_bomb), - - /* @game heretic - * - * Key to use "tome of power" artifact. - */ - - CONFIG_VARIABLE_KEY(key_arti_tome), - - /* @game heretic - * - * Key to use "ring of invincibility" artifact. - */ - - CONFIG_VARIABLE_KEY(key_arti_ring), - - /* @game heretic - * - * Key to use "chaos device" artifact. - */ - - CONFIG_VARIABLE_KEY(key_arti_chaosdevice), - - /* @game heretic - * - * Key to use "shadowsphere" artifact. - */ - - CONFIG_VARIABLE_KEY(key_arti_shadowsphere), - - /* @game heretic - * - * Key to use "wings of wrath" artifact. - */ - - CONFIG_VARIABLE_KEY(key_arti_wings), - - /* @game heretic - * - * Key to use "torch" artifact. - */ - - CONFIG_VARIABLE_KEY(key_arti_torch), - - /* @game heretic - * - * Key to use "morph ovum" artifact. - */ - - CONFIG_VARIABLE_KEY(key_arti_morph), - - /* @game hexen - * - * Key to use one of each artifact. - */ - - CONFIG_VARIABLE_KEY(key_arti_all), - - /* @game hexen - * - * Key to use "quartz flask" artifact. - */ - - CONFIG_VARIABLE_KEY(key_arti_health), - - /* @game hexen - * - * Key to use "flechette" artifact. - */ - - CONFIG_VARIABLE_KEY(key_arti_poisonbag), - - /* @game hexen - * - * Key to use "disc of repulsion" artifact. - */ - - CONFIG_VARIABLE_KEY(key_arti_blastradius), - - /* @game hexen - * - * Key to use "chaos device" artifact. - */ - - CONFIG_VARIABLE_KEY(key_arti_teleport), - - /* @game hexen - * - * Key to use "banishment device" artifact. - */ - - CONFIG_VARIABLE_KEY(key_arti_teleportother), - - /* @game hexen - * - * Key to use "porkalator" artifact. - */ - - CONFIG_VARIABLE_KEY(key_arti_egg), - - /* @game hexen - * - * Key to use "icon of the defender" artifact. - */ - - CONFIG_VARIABLE_KEY(key_arti_invulnerability), - - /* Key to re-display last message. */ - - CONFIG_VARIABLE_KEY(key_message_refresh), - - /* Key to quit the game when recording a demo. */ - - CONFIG_VARIABLE_KEY(key_demo_quit), - - /* Key to send a message during multiplayer games. */ - - CONFIG_VARIABLE_KEY(key_multi_msg), - - /* Key to send a message to player 1 during multiplayer games. */ - - CONFIG_VARIABLE_KEY(key_multi_msgplayer1), - - /* Key to send a message to player 2 during multiplayer games. */ - - CONFIG_VARIABLE_KEY(key_multi_msgplayer2), - - /* Key to send a message to player 3 during multiplayer games. */ - - CONFIG_VARIABLE_KEY(key_multi_msgplayer3), - - /* Key to send a message to player 4 during multiplayer games. */ - - CONFIG_VARIABLE_KEY(key_multi_msgplayer4), - - /* @game hexen strife - * - * Key to send a message to player 5 during multiplayer games. - */ - - CONFIG_VARIABLE_KEY(key_multi_msgplayer5), - - /* @game hexen strife - * - * Key to send a message to player 6 during multiplayer games. - */ - - CONFIG_VARIABLE_KEY(key_multi_msgplayer6), - - /* @game hexen strife - * - * Key to send a message to player 7 during multiplayer games. - */ - - CONFIG_VARIABLE_KEY(key_multi_msgplayer7), - - /* @game hexen strife - * - * Key to send a message to player 8 during multiplayer games. - */ - - CONFIG_VARIABLE_KEY(key_multi_msgplayer8), -}; - -static default_collection_t extra_defaults = -{ - extra_defaults_list, - arrlen(extra_defaults_list), - NULL, -}; - -/* Mapping from DOS keyboard scan code to internal key code (as defined - * in doomkey.h). I think I (fraggle) reused this from somewhere else - * but I can't find where. Anyway, notes: - * * KEY_PAUSE is wrong - it's in the KEY_NUMLOCK spot. This shouldn't - * matter in terms of Vanilla compatibility because neither of - * those were valid for key bindings. - * * There is no proper scan code for PrintScreen (on DOS machines it - * sends an interrupt). So I added a fake scan code of 126 for it. - * The presence of this is important so we can bind PrintScreen as - * a screenshot key. - */ - -static const int scantokey[128] = -{ - 0, - 27, - '1', - '2', - '3', - '4', - '5', - '6', - '7', - '8', - '9', - '0', - '-', - '=', - KEY_BACKSPACE, - 9, - 'q', - 'w', - 'e', - 'r', - 't', - 'y', - 'u', - 'i', - 'o', - 'p', - '[', - ']', - 13, - KEY_RCTRL, - 'a', - 's', - 'd', - 'f', - 'g', - 'h', - 'j', - 'k', - 'l', - ';', - '\'', - '`', - KEY_RSHIFT, - '\\', - 'z', - 'x', - 'c', - 'v', - 'b', - 'n', - 'm', - ',', - '.', - '/', - KEY_RSHIFT, - KEYP_MULTIPLY, - KEY_RALT, - ' ', - KEY_CAPSLOCK, - KEY_F1, - KEY_F2, - KEY_F3, - KEY_F4, - KEY_F5, - KEY_F6, - KEY_F7, - KEY_F8, - KEY_F9, - KEY_F10, - - /* KEY_NUMLOCK? */ - - KEY_PAUSE, - KEY_SCRLCK, - KEY_HOME, - KEY_UPARROW, - KEY_PGUP, - KEY_MINUS, - KEY_LEFTARROW, - KEYP_5, - KEY_RIGHTARROW, - KEYP_PLUS, - KEY_END, - KEY_DOWNARROW, - KEY_PGDN, - KEY_INS, - KEY_DEL, - 0, - 0, - 0, - KEY_F11, - KEY_F12, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - KEY_PRTSCR, - 0, -}; - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/* DEFAULTS */ - -/* Location where all configuration data is stored - default.cfg, savegames, - * etc. - */ - -const char *configdir; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: search_collection - * - * Description: - * Search a collection for a variable - * - ****************************************************************************/ - -static default_t *search_collection(default_collection_t *collection, - const char *name) -{ - int i; - - for (i = 0; i < collection->numdefaults; ++i) - { - if (!strcmp(name, collection->defaults[i].name)) - { - return &collection->defaults[i]; - } - } - - return NULL; -} - -static void save_default_collection(default_collection_t *collection) -{ - default_t *defaults; - int i; - int v; - FILE *f; - - f = fopen(collection->filename, "w"); - if (!f) return; /* can't write the file, but don't complain */ - - defaults = collection->defaults; - - for (i = 0; i < collection->numdefaults; i++) - { - int chars_written; - - /* Ignore unbound variables */ - - if (!defaults[i].bound) - { - continue; - } - - /* Print the name and line up all values at 30 characters */ - - chars_written = fprintf(f, "%s ", defaults[i].name); - - for (; chars_written < 30; ++chars_written) - fprintf(f, " "); - - /* Print the value */ - - switch (defaults[i].type) - { - case DEFAULT_KEY: - - /* use the untranslated version if we can, to reduce - * the possibility of screwing up the user's config - * file - */ - - v = *defaults[i].location.i; - - if (v == KEY_RSHIFT) - { - /* Special case: for shift, force scan code for - * right shift, as this is what Vanilla uses. - * This overrides the change check below, to fix - * configuration files made by old versions that - * mistakenly used the scan code for left shift. - */ - - v = 54; - } - else if (defaults[i].untranslated && - v == defaults[i].original_translated) - { - /* Has not been changed since the last time we read the config - * file. - */ - - v = defaults[i].untranslated; - } - else - { - /* search for a reverse mapping back to a scancode - * in the scantokey table - */ - - int s; - - for (s = 0; s < 128; ++s) - { - if (scantokey[s] == v) - { - v = s; - break; - } - } - } - - fprintf(f, "%i", v); - break; - - case DEFAULT_INT: - fprintf(f, "%i", *defaults[i].location.i); - break; - - case DEFAULT_INT_HEX: - fprintf(f, "0x%x", *defaults[i].location.i); - break; - - case DEFAULT_FLOAT: - fprintf(f, "%f", *defaults[i].location.f); - break; - - case DEFAULT_STRING: - fprintf(f, "\"%s\"", *defaults[i].location.s); - break; - } - - fprintf(f, "\n"); - } - - fclose(f); -} - -/**************************************************************************** - * Name: parse_int_parameter - * - * Description: - * Parses integer values in the configuration file - * - ****************************************************************************/ - -static int parse_int_parameter(const char *strparm) -{ - int param; - - if (strparm[0] == '0' && strparm[1] == 'x') - sscanf(strparm + 2, "%x", (unsigned int *)¶m); - else - sscanf(strparm, "%i", ¶m); - - return param; -} - -static void set_variable(default_t *def, const char *value) -{ - int intparm; - - /* parameter found */ - - switch (def->type) - { - case DEFAULT_STRING: - *def->location.s = m_string_duplicate(value); - break; - - case DEFAULT_INT: - case DEFAULT_INT_HEX: - *def->location.i = parse_int_parameter(value); - break; - - case DEFAULT_KEY: - - /* translate scancodes read from config - * file (save the old value in untranslated) - */ - - intparm = parse_int_parameter(value); - def->untranslated = intparm; - if (intparm >= 0 && intparm < 128) - { - intparm = scantokey[intparm]; - } - else - { - intparm = 0; - } - - def->original_translated = intparm; - *def->location.i = intparm; - break; - - case DEFAULT_FLOAT: - { - /* Different locales use different decimal separators. - * However, the choice of the current locale isn't always - * under our own control. If the atof() function fails to - * parse the string representing the floating point number - * using the current locale's decimal separator, it will - * return 0, resulting in silent sound effects. To - * mitigate this, we replace the first non-digit, - * non-minus character in the string with the current - * locale's decimal separator before passing it to atof(). - */ - - struct lconv *lc = localeconv(); - char dec; - char *str; - int i = 0; - - dec = lc->decimal_point[0]; - str = m_string_duplicate(value); - - /* Skip sign indicators. */ - - if (str[i] == '-' || str[i] == '+') - { - i++; - } - - for (; str[i] != '\0'; i++) - { - if (!isdigit(str[i])) - { - str[i] = dec; - break; - } - } - - *def->location.f = (float)atof(str); - free(str); - } - break; - } -} - -static void load_default_collection(default_collection_t *collection) -{ - FILE *f; - default_t *def; - char defname[80]; - char strparm[100]; - - /* read the file in, overriding any set defaults */ - - f = fopen(collection->filename, "r"); - - if (f == NULL) - { - /* File not opened, but don't complain. - * It's probably just the first time they ran the game. - */ - - return; - } - - while (!feof(f)) - { - if (fscanf(f, "%79s %99[^\n]\n", defname, strparm) != 2) - { - /* This line doesn't match */ - - continue; - } - - /* Find the setting in the list */ - - def = search_collection(collection, defname); - - if (def == NULL || !def->bound) - { - /* Unknown variable? Unbound variables are also treated - * as unknown. - */ - - continue; - } - - /* Strip off trailing non-printable characters (\r characters - * from DOS text files) - */ - - while (strlen(strparm) > 0 && !isprint(strparm[strlen(strparm) - 1])) - { - strparm[strlen(strparm) - 1] = '\0'; - } - - /* Surrounded by quotes? If so, remove them. */ - - if (strlen(strparm) >= 2 && strparm[0] == '"' && - strparm[strlen(strparm) - 1] == '"') - { - strparm[strlen(strparm) - 1] = '\0'; - memmove(strparm, strparm + 1, sizeof(strparm) - 1); - } - - set_variable(def, strparm); - } - - fclose(f); -} - -/* Get a configuration file variable by its name */ - -static default_t *get_default_for_name(const char *name) -{ - default_t *result; - - /* Try the main list and the extras */ - - result = search_collection(&doom_defaults, name); - - if (result == NULL) - { - result = search_collection(&extra_defaults, name); - } - - /* Not found? Internal error. */ - - if (result == NULL) - { - i_error("Unknown configuration variable: '%s'", name); - } - - return result; -} - -/* Get the path to the default configuration dir to use, if NULL - * is passed to m_set_config_dir. - */ - -static char *get_default_config_dir(void) -{ - /* Configuration settings are stored in an OS-appropriate path - * determined by SDL. On typical Unix systems, this might be - * ~/.local/share/chocolate-doom. On Windows, we behave like - * Vanilla Doom and save in the current directory. - */ - - char *result = CONFIG_GAMES_NXDOOM_PREFDIR "/"; - char *copy = m_string_duplicate(result); - return copy; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/* Set the default filenames to use for configuration files. */ - -void m_set_config_filenames(const char *main_config, - const char *extra_config) -{ - default_main_config = main_config; - default_extra_config = extra_config; -} - -void m_save_defaults(void) -{ - save_default_collection(&doom_defaults); - save_default_collection(&extra_defaults); -} - -/* Save defaults to alternate filenames */ - -void m_save_defaults_alternate(const char *main, const char *extra) -{ - const char *orig_main; - const char *orig_extra; - - /* Temporarily change the filenames */ - - orig_main = doom_defaults.filename; - orig_extra = extra_defaults.filename; - - doom_defaults.filename = main; - extra_defaults.filename = extra; - - m_save_defaults(); - - /* Restore normal filenames */ - - doom_defaults.filename = orig_main; - extra_defaults.filename = orig_extra; -} - -void m_load_defaults(void) -{ - int i; - - /* This variable is a special snowflake for no good reason. */ - - m_bind_string_variable("autoload_path", &autoload_path); - - /* check for a custom default file */ - - /* @arg - * @vanilla - * - * Load main configuration from the specified file, instead of the - * default. - */ - - i = m_check_parm_with_args("-config", 1); - - if (i) - { - doom_defaults.filename = myargv[i + 1]; - printf("\tdefault file: %s\n", doom_defaults.filename); - } - else - { - doom_defaults.filename = - m_string_join(configdir, default_main_config, NULL); - } - - printf("saving config in %s\n", doom_defaults.filename); - - /* @arg - * - * Load additional configuration from the specified file, instead of - * the default. - */ - - i = m_check_parm_with_args("-extraconfig", 1); - - if (i) - { - extra_defaults.filename = myargv[i + 1]; - printf(" extra configuration file: %s\n", - extra_defaults.filename); - } - else - { - extra_defaults.filename = - m_string_join(configdir, default_extra_config, NULL); - } - - load_default_collection(&doom_defaults); - load_default_collection(&extra_defaults); -} - -/* Bind a variable to a given configuration file variable, by name. */ - -void m_bind_int_variable(const char *name, int *location) -{ - default_t *variable; - - variable = get_default_for_name(name); - assert(variable->type == DEFAULT_INT || - variable->type == DEFAULT_INT_HEX || variable->type == DEFAULT_KEY); - - variable->location.i = location; - variable->bound = true; -} - -void m_bind_float_variable(const char *name, float *location) -{ - default_t *variable; - - variable = get_default_for_name(name); - assert(variable->type == DEFAULT_FLOAT); - - variable->location.f = location; - variable->bound = true; -} - -void m_bind_string_variable(const char *name, char **location) -{ - default_t *variable; - - variable = get_default_for_name(name); - assert(variable->type == DEFAULT_STRING); - - variable->location.s = location; - variable->bound = true; -} - -/* Set the value of a particular variable; an API function for other - * parts of the program to assign values to config variables by name. - */ - -boolean m_set_variable(const char *name, const char *value) -{ - default_t *variable; - - variable = get_default_for_name(name); - - if (variable == NULL || !variable->bound) - { - return false; - } - - set_variable(variable, value); - - return true; -} - -const char *m_get_string_variable(const char *name) -{ - default_t *variable; - - variable = get_default_for_name(name); - - if (variable == NULL || !variable->bound || - variable->type != DEFAULT_STRING) - { - return NULL; - } - - return *variable->location.s; -} - -/* SetConfigDir: - * - * Sets the location of the configuration directory, where configuration - * files are stored - default.cfg, chocolate-doom.cfg, savegames, etc. - */ - -void m_set_config_dir(const char *dir) -{ - /* Use the directory that was passed, or find the default. */ - - if (dir != NULL) - { - configdir = dir; - } - else - { - configdir = get_default_config_dir(); - } - - if (strcmp(configdir, exedir) != 0) - { - printf("Using %s for configuration and saves\n", configdir); - } - - /* Make the directory if it doesn't already exist: */ - - m_make_directory(configdir); -} - -/* Set the value of music_pack_path if it is currently empty, and create - * the directory if necessary. - */ - -void m_set_music_pack_dir(void) -{ - const char *current_path; - char *prefdir; - char *music_pack_path; - - current_path = m_get_string_variable("music_pack_path"); - - if (current_path != NULL && strlen(current_path) > 0) - { - return; - } - - prefdir = CONFIG_GAMES_NXDOOM_PREFDIR "/"; - music_pack_path = m_string_join(prefdir, "music-packs", NULL); - - m_make_directory(prefdir); - m_make_directory(music_pack_path); - m_set_variable("music_pack_path", music_pack_path); - - free(music_pack_path); -} - -/* Calculate the path to the directory to use to store save games. - * Creates the directory as necessary. - */ - -char *m_get_save_game_dir(const char *iwadname) -{ - char *savegamedir; - char *topdir; - int p; - - /* @arg - * - * Specify a path from which to load and save games. If the - * directory does not exist then it will automatically be created. - */ - - p = m_check_parm_with_args("-savedir", 1); - if (p) - { - savegamedir = myargv[p + 1]; - if (!m_file_exists(savegamedir)) - { - m_make_directory(savegamedir); - } - - /* add separator at end just in case */ - - savegamedir = m_string_join(savegamedir, DIR_SEPARATOR_S, NULL); - - printf("Save directory changed to %s.\n", savegamedir); - } - - /* If not "doing" a configuration directory (Windows), don't "do" - * a savegame directory, either. - */ - - else if (!strcmp(configdir, exedir)) - { - savegamedir = m_string_duplicate(""); - } - else - { - /* ~/.local/share/chocolate-doom/savegames */ - - topdir = m_string_join(configdir, "savegames", NULL); - m_make_directory(topdir); - - /* eg. ~/.local/share/chocolate-doom/savegames/doom2.wad/ */ - - savegamedir = m_string_join(topdir, DIR_SEPARATOR_S, iwadname, - DIR_SEPARATOR_S, NULL); - - m_make_directory(savegamedir); - - free(topdir); - } - - return savegamedir; -} - -/* Calculate the path to the directory for autoloaded WADs/DEHs. - * Creates the directory as necessary. - */ - -char *m_get_autoload_dir(const char *iwadname) -{ - char *result; - - if (autoload_path == NULL || strlen(autoload_path) == 0) - { - char *prefdir = CONFIG_GAMES_NXDOOM_PREFDIR "/"; - autoload_path = m_string_join(prefdir, "autoload", NULL); - } - - m_make_directory(autoload_path); - - result = m_string_join(autoload_path, DIR_SEPARATOR_S, iwadname, NULL); - m_make_directory(result); - - /* TODO: Add README file */ - - return result; -} diff --git a/games/NXDoom/src/m_config.h b/games/NXDoom/src/m_config.h deleted file mode 100644 index 5dd8358b7..000000000 --- a/games/NXDoom/src/m_config.h +++ /dev/null @@ -1,58 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/m_config.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Configuration file interface. - * - ****************************************************************************/ - -#ifndef __M_CONFIG__ -#define __M_CONFIG__ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "doomtype.h" - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -extern const char *configdir; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -void m_load_defaults(void); -void m_save_defaults(void); -void m_save_defaults_alternate(const char *main, const char *extra); -void m_set_config_dir(const char *dir); -void m_set_music_pack_dir(void); -void m_bind_int_variable(const char *name, int *variable); -void m_bind_float_variable(const char *name, float *variable); -void m_bind_string_variable(const char *name, char **variable); -boolean m_set_variable(const char *name, const char *value); -const char *m_get_string_variable(const char *name); -void m_set_config_filenames(const char *main_config, - const char *extra_config); -char *m_get_save_game_dir(const char *iwadname); -char *m_get_autoload_dir(const char *iwadname); - -#endif /* __M_CONFIG__ */ diff --git a/games/NXDoom/src/m_controls.c b/games/NXDoom/src/m_controls.c deleted file mode 100644 index 2266df2ce..000000000 --- a/games/NXDoom/src/m_controls.c +++ /dev/null @@ -1,467 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/m_controls.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 1993-2008 Raven Software - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include "doomkeys.h" -#include "doomtype.h" - -#include "m_config.h" -#include "m_misc.h" - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/* Keyboard controls */ - -int key_right = KEY_RIGHTARROW; -int key_left = KEY_LEFTARROW; - -int key_up = KEY_UPARROW; -int key_down = KEY_DOWNARROW; -int key_strafeleft = 0x2c; /* Comma, ',' */ -int key_straferight = '.'; -int key_fire = KEY_RCTRL; -int key_use = ' '; -int key_strafe = KEY_RALT; -int key_speed = KEY_RSHIFT; - -/* Heretic keyboard controls */ - -int key_flyup = KEY_PGUP; -int key_flydown = KEY_INS; -int key_flycenter = KEY_HOME; - -int key_lookup = KEY_PGDN; -int key_lookdown = KEY_DEL; -int key_lookcenter = KEY_END; - -int key_invleft = '['; -int key_invright = ']'; -int key_useartifact = KEY_ENTER; - -int key_arti_quartz = 0; -int key_arti_urn = 0; -int key_arti_bomb = 0; -int key_arti_tome = 127; -int key_arti_ring = 0; -int key_arti_chaosdevice = 0; -int key_arti_shadowsphere = 0; -int key_arti_wings = 0; -int key_arti_torch = 0; -int key_arti_morph = 0; - -/* Hexen key controls */ - -int key_jump = '/'; - -int key_arti_all = KEY_BACKSPACE; -int key_arti_health = '\\'; -int key_arti_poisonbag = '0'; -int key_arti_blastradius = '9'; -int key_arti_teleport = '8'; -int key_arti_teleportother = '7'; -int key_arti_egg = '6'; -int key_arti_invulnerability = '5'; - -/* Strife key controls - * - * haleyjd 09/01/10 - * - * Note: Strife also uses key_invleft, key_invright, key_jump, key_lookup, - * and key_lookdown, but with different default values. - */ - -int key_usehealth = 'h'; -int key_invquery = 'q'; -int key_mission = 'w'; -int key_invpop = 'z'; -int key_invkey = 'k'; -int key_invhome = KEY_HOME; -int key_invend = KEY_END; -int key_invuse = KEY_ENTER; -int key_invdrop = KEY_BACKSPACE; - -/* Mouse controls */ - -int mousebfire = 0; -int mousebstrafe = 1; -int mousebforward = 2; -int mousebspeed = 3; - -int mousebjump = -1; - -int mousebstrafeleft = -1; -int mousebstraferight = -1; -int mousebturnleft = -1; -int mousebturnright = -1; -int mousebbackward = -1; -int mousebuse = -1; - -int mousebprevweapon = -1; -int mousebnextweapon = -1; -int mousebinvleft = -1; -int mousebinvright = -1; -int mousebuseartifact = -1; - -int key_message_refresh = KEY_ENTER; -int key_pause = KEY_PAUSE; -int key_demo_quit = 'q'; -int key_spy = KEY_F12; - -/* Multiplayer chat keys: */ - -int key_multi_msg = 't'; -int key_multi_msgplayer[8]; - -/* Weapon selection keys: */ - -int key_weapon1 = '1'; -int key_weapon2 = '2'; -int key_weapon3 = '3'; -int key_weapon4 = '4'; -int key_weapon5 = '5'; -int key_weapon6 = '6'; -int key_weapon7 = '7'; -int key_weapon8 = '8'; -int key_prevweapon = 0; -int key_nextweapon = 0; - -/* Map control keys: */ - -int key_map_north = KEY_UPARROW; -int key_map_south = KEY_DOWNARROW; -int key_map_east = KEY_RIGHTARROW; -int key_map_west = KEY_LEFTARROW; -int key_map_zoomin = '='; -int key_map_zoomout = '-'; -int key_map_toggle = KEY_TAB; -int key_map_maxzoom = '0'; -int key_map_follow = 'f'; -int key_map_grid = 'g'; -int key_map_mark = 'm'; -int key_map_clearmark = 'c'; - -/* menu keys: */ - -int key_menu_activate = KEY_ESCAPE; -int key_menu_up = KEY_UPARROW; -int key_menu_down = KEY_DOWNARROW; -int key_menu_left = KEY_LEFTARROW; -int key_menu_right = KEY_RIGHTARROW; -int key_menu_back = KEY_BACKSPACE; -int key_menu_forward = KEY_ENTER; -int key_menu_confirm = 'y'; -int key_menu_abort = 'n'; - -int key_menu_help = KEY_F1; -int key_menu_save = KEY_F2; -int key_menu_load = KEY_F3; -int key_menu_volume = KEY_F4; -int key_menu_detail = KEY_F5; -int key_menu_qsave = KEY_F6; -int key_menu_endgame = KEY_F7; -int key_menu_messages = KEY_F8; -int key_menu_qload = KEY_F9; -int key_menu_quit = KEY_F10; -int key_menu_gamma = KEY_F11; - -int key_menu_incscreen = KEY_EQUALS; -int key_menu_decscreen = KEY_MINUS; -int key_menu_screenshot = 0; - -/* Joystick controls */ - -int joybfire = 0; -int joybstrafe = 1; -int joybuse = 3; -int joybspeed = 2; - -int joybstrafeleft = -1; -int joybstraferight = -1; - -int joybjump = -1; - -int joybprevweapon = -1; -int joybnextweapon = -1; - -int joybmenu = -1; -int joybautomap = -1; - -int joybuseartifact = -1; -int joybinvleft = -1; -int joybinvright = -1; - -int joybflyup = -1; -int joybflydown = -1; -int joybflycenter = -1; - -/* Control whether if a mouse button is double clicked, it acts like - * "use" has been pressed - */ - -int dclick_use = 1; - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/* Bind all of the common controls used by Doom and all other games. */ - -void m_bind_base_controls(void) -{ - m_bind_int_variable("key_right", &key_right); - m_bind_int_variable("key_left", &key_left); - m_bind_int_variable("key_up", &key_up); - m_bind_int_variable("key_down", &key_down); - m_bind_int_variable("key_strafeleft", &key_strafeleft); - m_bind_int_variable("key_straferight", &key_straferight); - m_bind_int_variable("key_fire", &key_fire); - m_bind_int_variable("key_use", &key_use); - m_bind_int_variable("key_strafe", &key_strafe); - m_bind_int_variable("key_speed", &key_speed); - - m_bind_int_variable("mouseb_fire", &mousebfire); - m_bind_int_variable("mouseb_strafe", &mousebstrafe); - m_bind_int_variable("mouseb_forward", &mousebforward); - m_bind_int_variable("mouseb_speed", &mousebspeed); - - m_bind_int_variable("joyb_fire", &joybfire); - m_bind_int_variable("joyb_strafe", &joybstrafe); - m_bind_int_variable("joyb_use", &joybuse); - m_bind_int_variable("joyb_speed", &joybspeed); - - m_bind_int_variable("joyb_menu_activate", &joybmenu); - m_bind_int_variable("joyb_toggle_automap", &joybautomap); - - /* Extra controls that are not in the Vanilla versions: */ - - m_bind_int_variable("joyb_strafeleft", &joybstrafeleft); - m_bind_int_variable("joyb_straferight", &joybstraferight); - m_bind_int_variable("mouseb_strafeleft", &mousebstrafeleft); - m_bind_int_variable("mouseb_straferight", &mousebstraferight); - m_bind_int_variable("mouseb_turnleft", &mousebturnleft); - m_bind_int_variable("mouseb_turnright", &mousebturnright); - m_bind_int_variable("mouseb_use", &mousebuse); - m_bind_int_variable("mouseb_backward", &mousebbackward); - m_bind_int_variable("dclick_use", &dclick_use); - m_bind_int_variable("key_pause", &key_pause); - m_bind_int_variable("key_message_refresh", &key_message_refresh); -} - -void m_bind_heretic_controls(void) -{ - m_bind_int_variable("key_flyup", &key_flyup); - m_bind_int_variable("key_flydown", &key_flydown); - m_bind_int_variable("key_flycenter", &key_flycenter); - - m_bind_int_variable("key_lookup", &key_lookup); - m_bind_int_variable("key_lookdown", &key_lookdown); - m_bind_int_variable("key_lookcenter", &key_lookcenter); - - m_bind_int_variable("key_invleft", &key_invleft); - m_bind_int_variable("key_invright", &key_invright); - m_bind_int_variable("key_useartifact", &key_useartifact); - - m_bind_int_variable("mouseb_invleft", &mousebinvleft); - m_bind_int_variable("mouseb_invright", &mousebinvright); - m_bind_int_variable("mouseb_useartifact", &mousebuseartifact); - - m_bind_int_variable("joyb_invleft", &joybinvleft); - m_bind_int_variable("joyb_invright", &joybinvright); - m_bind_int_variable("joyb_useartifact", &joybuseartifact); - - m_bind_int_variable("joyb_flyup", &joybflyup); - m_bind_int_variable("joyb_flydown", &joybflydown); - m_bind_int_variable("joyb_flycenter", &joybflycenter); - - m_bind_int_variable("key_arti_quartz", &key_arti_quartz); - m_bind_int_variable("key_arti_urn", &key_arti_urn); - m_bind_int_variable("key_arti_bomb", &key_arti_bomb); - m_bind_int_variable("key_arti_tome", &key_arti_tome); - m_bind_int_variable("key_arti_ring", &key_arti_ring); - m_bind_int_variable("key_arti_chaosdevice", &key_arti_chaosdevice); - m_bind_int_variable("key_arti_shadowsphere", &key_arti_shadowsphere); - m_bind_int_variable("key_arti_wings", &key_arti_wings); - m_bind_int_variable("key_arti_torch", &key_arti_torch); - m_bind_int_variable("key_arti_morph", &key_arti_morph); -} - -void m_bind_hexen_controls(void) -{ - m_bind_int_variable("key_jump", &key_jump); - m_bind_int_variable("mouseb_jump", &mousebjump); - m_bind_int_variable("joyb_jump", &joybjump); - - m_bind_int_variable("key_arti_all", &key_arti_all); - m_bind_int_variable("key_arti_health", &key_arti_health); - m_bind_int_variable("key_arti_poisonbag", &key_arti_poisonbag); - m_bind_int_variable("key_arti_blastradius", &key_arti_blastradius); - m_bind_int_variable("key_arti_teleport", &key_arti_teleport); - m_bind_int_variable("key_arti_teleportother", &key_arti_teleportother); - m_bind_int_variable("key_arti_egg", &key_arti_egg); - m_bind_int_variable("key_arti_invulnerability", &key_arti_invulnerability); -} - -void m_bind_strife_controls(void) -{ - /* These are shared with all games, but have different defaults: */ - - key_message_refresh = '/'; - - /* These keys are shared with Heretic/Hexen but have different defaults: */ - - key_jump = 'a'; - key_lookup = KEY_PGUP; - key_lookdown = KEY_PGDN; - key_invleft = KEY_INS; - key_invright = KEY_DEL; - - m_bind_int_variable("key_jump", &key_jump); - m_bind_int_variable("key_look_up", &key_lookup); - m_bind_int_variable("key_look_down", &key_lookdown); - m_bind_int_variable("key_inv_left", &key_invleft); - m_bind_int_variable("key_inv_right", &key_invright); - - /* Custom Strife-only Keys: */ - - m_bind_int_variable("key_use_health", &key_usehealth); - m_bind_int_variable("key_invquery", &key_invquery); - m_bind_int_variable("key_mission", &key_mission); - m_bind_int_variable("key_inv_pop", &key_invpop); - m_bind_int_variable("key_inv_key", &key_invkey); - m_bind_int_variable("key_invHome", &key_invhome); - m_bind_int_variable("key_inv_end", &key_invend); - m_bind_int_variable("key_inv_use", &key_invuse); - m_bind_int_variable("key_inv_drop", &key_invdrop); - - /* Strife also supports jump on mouse and joystick, and in the exact same - * manner as Hexen! - */ - - m_bind_int_variable("mouseb_jump", &mousebjump); - m_bind_int_variable("joyb_jump", &joybjump); - - /* Subset of inventory actions common to Heretic/Hexen and Strife. */ - - m_bind_int_variable("joyb_invleft", &joybinvleft); - m_bind_int_variable("joyb_invright", &joybinvright); - - /* This is technically "invuse" in Strife, but let's reuse the value. */ - - m_bind_int_variable("joyb_useartifact", &joybuseartifact); -} - -void m_bind_weapon_controls(void) -{ - m_bind_int_variable("key_weapon1", &key_weapon1); - m_bind_int_variable("key_weapon2", &key_weapon2); - m_bind_int_variable("key_weapon3", &key_weapon3); - m_bind_int_variable("key_weapon4", &key_weapon4); - m_bind_int_variable("key_weapon5", &key_weapon5); - m_bind_int_variable("key_weapon6", &key_weapon6); - m_bind_int_variable("key_weapon7", &key_weapon7); - m_bind_int_variable("key_weapon8", &key_weapon8); - - m_bind_int_variable("key_prevweapon", &key_prevweapon); - m_bind_int_variable("key_nextweapon", &key_nextweapon); - - m_bind_int_variable("joyb_prevweapon", &joybprevweapon); - m_bind_int_variable("joyb_nextweapon", &joybnextweapon); - - m_bind_int_variable("mouseb_prevweapon", &mousebprevweapon); - m_bind_int_variable("mouseb_nextweapon", &mousebnextweapon); -} - -void m_bind_map_controls(void) -{ - m_bind_int_variable("key_map_north", &key_map_north); - m_bind_int_variable("key_map_south", &key_map_south); - m_bind_int_variable("key_map_east", &key_map_east); - m_bind_int_variable("key_map_west", &key_map_west); - m_bind_int_variable("key_map_zoomin", &key_map_zoomin); - m_bind_int_variable("key_map_zoomout", &key_map_zoomout); - m_bind_int_variable("key_map_toggle", &key_map_toggle); - m_bind_int_variable("key_map_maxzoom", &key_map_maxzoom); - m_bind_int_variable("key_map_follow", &key_map_follow); - m_bind_int_variable("key_map_grid", &key_map_grid); - m_bind_int_variable("key_map_mark", &key_map_mark); - m_bind_int_variable("key_map_clearmark", &key_map_clearmark); -} - -void m_bind_menu_controls(void) -{ - m_bind_int_variable("key_menu_activate", &key_menu_activate); - m_bind_int_variable("key_menu_up", &key_menu_up); - m_bind_int_variable("key_menu_down", &key_menu_down); - m_bind_int_variable("key_menu_left", &key_menu_left); - m_bind_int_variable("key_menu_right", &key_menu_right); - m_bind_int_variable("key_menu_back", &key_menu_back); - m_bind_int_variable("key_menu_forward", &key_menu_forward); - m_bind_int_variable("key_menu_confirm", &key_menu_confirm); - m_bind_int_variable("key_menu_abort", &key_menu_abort); - - m_bind_int_variable("key_menu_help", &key_menu_help); - m_bind_int_variable("key_menu_save", &key_menu_save); - m_bind_int_variable("key_menu_load", &key_menu_load); - m_bind_int_variable("key_menu_volume", &key_menu_volume); - m_bind_int_variable("key_menu_detail", &key_menu_detail); - m_bind_int_variable("key_menu_qsave", &key_menu_qsave); - m_bind_int_variable("key_menu_endgame", &key_menu_endgame); - m_bind_int_variable("key_menu_messages", &key_menu_messages); - m_bind_int_variable("key_menu_qload", &key_menu_qload); - m_bind_int_variable("key_menu_quit", &key_menu_quit); - m_bind_int_variable("key_menu_gamma", &key_menu_gamma); - - m_bind_int_variable("key_menu_incscreen", &key_menu_incscreen); - m_bind_int_variable("key_menu_decscreen", &key_menu_decscreen); - m_bind_int_variable("key_menu_screenshot", &key_menu_screenshot); - m_bind_int_variable("key_demo_quit", &key_demo_quit); - m_bind_int_variable("key_spy", &key_spy); -} - -void m_bind_chat_controls(unsigned int num_players) -{ - char name[32]; /* haleyjd: 20 not large enough - Thank you, come again! */ - unsigned int i; /* haleyjd: signedness conflict */ - - m_bind_int_variable("key_multi_msg", &key_multi_msg); - - for (i = 0; i < num_players; ++i) - { - snprintf(name, sizeof(name), "key_multi_msgplayer%i", i + 1); - m_bind_int_variable(name, &key_multi_msgplayer[i]); - } -} - -/* Apply custom patches to the default values depending on the - * platform we are running on. - */ - -void m_apply_platform_defaults(void) -{ - /* no-op. Add your platform-specific patches here. */ -} diff --git a/games/NXDoom/src/m_controls.h b/games/NXDoom/src/m_controls.h deleted file mode 100644 index fb756ec11..000000000 --- a/games/NXDoom/src/m_controls.h +++ /dev/null @@ -1,207 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/m_controls.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 1993-2008 Raven Software - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - ****************************************************************************/ - -#ifndef __M_CONTROLS_H__ -#define __M_CONTROLS_H__ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -extern int key_right; -extern int key_left; - -extern int key_up; -extern int key_down; -extern int key_strafeleft; -extern int key_straferight; -extern int key_fire; -extern int key_use; -extern int key_strafe; -extern int key_speed; - -extern int key_jump; - -extern int key_flyup; -extern int key_flydown; -extern int key_flycenter; -extern int key_lookup; -extern int key_lookdown; -extern int key_lookcenter; -extern int key_invleft; -extern int key_invright; -extern int key_useartifact; - -/* villsa [STRIFE] strife keys */ - -extern int key_usehealth; -extern int key_invquery; -extern int key_mission; -extern int key_invpop; -extern int key_invkey; -extern int key_invhome; -extern int key_invend; -extern int key_invuse; -extern int key_invdrop; - -extern int key_message_refresh; -extern int key_pause; - -extern int key_multi_msg; -extern int key_multi_msgplayer[8]; - -extern int key_weapon1; -extern int key_weapon2; -extern int key_weapon3; -extern int key_weapon4; -extern int key_weapon5; -extern int key_weapon6; -extern int key_weapon7; -extern int key_weapon8; - -extern int key_arti_quartz; -extern int key_arti_urn; -extern int key_arti_bomb; -extern int key_arti_tome; -extern int key_arti_ring; -extern int key_arti_chaosdevice; -extern int key_arti_shadowsphere; -extern int key_arti_wings; -extern int key_arti_torch; -extern int key_arti_morph; - -extern int key_arti_all; -extern int key_arti_health; -extern int key_arti_poisonbag; -extern int key_arti_blastradius; -extern int key_arti_teleport; -extern int key_arti_teleportother; -extern int key_arti_egg; -extern int key_arti_invulnerability; - -extern int key_demo_quit; -extern int key_spy; -extern int key_prevweapon; -extern int key_nextweapon; - -extern int key_map_north; -extern int key_map_south; -extern int key_map_east; -extern int key_map_west; -extern int key_map_zoomin; -extern int key_map_zoomout; -extern int key_map_toggle; -extern int key_map_maxzoom; -extern int key_map_follow; -extern int key_map_grid; -extern int key_map_mark; -extern int key_map_clearmark; - -/* menu keys: */ - -extern int key_menu_activate; -extern int key_menu_up; -extern int key_menu_down; -extern int key_menu_left; -extern int key_menu_right; -extern int key_menu_back; -extern int key_menu_forward; -extern int key_menu_confirm; -extern int key_menu_abort; - -extern int key_menu_help; -extern int key_menu_save; -extern int key_menu_load; -extern int key_menu_volume; -extern int key_menu_detail; -extern int key_menu_qsave; -extern int key_menu_endgame; -extern int key_menu_messages; -extern int key_menu_qload; -extern int key_menu_quit; -extern int key_menu_gamma; - -extern int key_menu_incscreen; -extern int key_menu_decscreen; -extern int key_menu_screenshot; - -extern int mousebfire; -extern int mousebstrafe; -extern int mousebforward; -extern int mousebspeed; - -extern int mousebjump; - -extern int mousebstrafeleft; -extern int mousebstraferight; -extern int mousebturnleft; -extern int mousebturnright; -extern int mousebbackward; -extern int mousebuse; - -extern int mousebprevweapon; -extern int mousebnextweapon; -extern int mousebinvleft; -extern int mousebinvright; -extern int mousebuseartifact; - -extern int joybfire; -extern int joybstrafe; -extern int joybuse; -extern int joybspeed; - -extern int joybjump; - -extern int joybstrafeleft; -extern int joybstraferight; - -extern int joybprevweapon; -extern int joybnextweapon; - -extern int joybmenu; -extern int joybautomap; - -extern int joybuseartifact; -extern int joybinvleft; -extern int joybinvright; - -extern int joybflyup; -extern int joybflydown; -extern int joybflycenter; - -extern int dclick_use; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -void m_bind_base_controls(void); -void m_bind_heretic_controls(void); -void m_bind_hexen_controls(void); -void m_bind_strife_controls(void); -void m_bind_weapon_controls(void); -void m_bind_map_controls(void); -void m_bind_menu_controls(void); -void m_bind_chat_controls(unsigned int num_players); - -void m_apply_platform_defaults(void); - -#endif /* __M_CONTROLS_H__ */ diff --git a/games/NXDoom/src/m_fixed.c b/games/NXDoom/src/m_fixed.c deleted file mode 100644 index c8931d96c..000000000 --- a/games/NXDoom/src/m_fixed.c +++ /dev/null @@ -1,62 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/m_fixed.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Fixed point implementation. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "stdlib.h" - -#include "doomtype.h" -#include "i_system.h" - -#include "m_fixed.h" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/* Fixme. __USE_C_FIXED__ or something. */ - -fixed_t fixed_mul(fixed_t a, fixed_t b) -{ - return ((int64_t)a * (int64_t)b) >> FRACBITS; -} - -/* fixed_div, C version. */ - -fixed_t fixed_div(fixed_t a, fixed_t b) -{ - if ((abs(a) >> 14) >= abs(b)) - { - return (a ^ b) < 0 ? INT_MIN : INT_MAX; - } - else - { - int64_t result; - - result = ((int64_t)a << FRACBITS) / b; - - return (fixed_t)result; - } -} diff --git a/games/NXDoom/src/m_fixed.h b/games/NXDoom/src/m_fixed.h deleted file mode 100644 index abb837b31..000000000 --- a/games/NXDoom/src/m_fixed.h +++ /dev/null @@ -1,49 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/m_fixed.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Fixed point arithemtics, implementation. - * - ****************************************************************************/ - -#ifndef __M_FIXED__ -#define __M_FIXED__ - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* Fixed point, 32bit as 16.16. */ - -#define FRACBITS 16 -#define FRACUNIT (1 << FRACBITS) - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -typedef int fixed_t; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -fixed_t fixed_mul(fixed_t a, fixed_t b); -fixed_t fixed_div(fixed_t a, fixed_t b); - -#endif /* __M_FIXED__ */ diff --git a/games/NXDoom/src/m_misc.c b/games/NXDoom/src/m_misc.c deleted file mode 100644 index 515ff46f0..000000000 --- a/games/NXDoom/src/m_misc.c +++ /dev/null @@ -1,621 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/m_misc.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 1993-2008 Raven Software - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Miscellaneous. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include -#include -#include - -#include - -#include "doomtype.h" - -#include "i_system.h" -#include "m_misc.h" -#include "z_zone.h" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -void m_make_directory(const char *path) -{ - mkdir(path, 0755); -} - -boolean m_file_exists(const char *filename) -{ - FILE *fstream; - - fstream = fopen(filename, "r"); - - if (fstream != NULL) - { - fclose(fstream); - return true; - } - else - { - /* If we can't open because the file is a directory, the - * "file" exists at least! - */ - - return errno == EISDIR; - } -} - -/* Check if a file exists by probing for common case variation of its - * filename. Returns a newly allocated string that the caller is responsible - * for freeing. - */ - -char *m_file_case_exists(const char *path) -{ - char *path_dup; - char *filename; - char *ext; - - path_dup = m_string_duplicate(path); - - /* 0: actual path */ - - if (m_file_exists(path_dup)) - { - return path_dup; - } - - filename = strrchr(path_dup, DIR_SEPARATOR); - if (filename != NULL) - { - filename++; - } - else - { - filename = path_dup; - } - - /* 1: lowercase filename, e.g. doom2.wad */ - - m_force_lowercase(filename); - - if (m_file_exists(path_dup)) - { - return path_dup; - } - - /* 2: uppercase filename, e.g. DOOM2.WAD */ - - m_force_uppercase(filename); - - if (m_file_exists(path_dup)) - { - return path_dup; - } - - /* 3. uppercase basename with lowercase extension, e.g. DOOM2.wad */ - - ext = strrchr(path_dup, '.'); - if (ext != NULL && ext > filename) - { - m_force_lowercase(ext + 1); - - if (m_file_exists(path_dup)) - { - return path_dup; - } - } - - /* 4. lowercase filename with uppercase first letter, e.g. Doom2.wad */ - - if (strlen(filename) > 1) - { - m_force_lowercase(filename + 1); - - if (m_file_exists(path_dup)) - { - return path_dup; - } - } - - /* 5. no luck */ - - free(path_dup); - return NULL; -} - -long m_file_length(FILE *handle) -{ - long savedpos; - long length; - - /* save the current position in the file */ - - savedpos = ftell(handle); - - /* jump to the end and find the length */ - - fseek(handle, 0, SEEK_END); - length = ftell(handle); - - /* go back to the old location */ - - fseek(handle, savedpos, SEEK_SET); - - return length; -} - -boolean m_write_file(const char *name, const void *source, int length) -{ - FILE *handle; - int count; - - handle = fopen(name, "wb"); - - if (handle == NULL) return false; - - count = fwrite(source, 1, length, handle); - fclose(handle); - - if (count < length) return false; - - return true; -} - -int m_read_file(const char *name, byte **buffer) -{ - FILE *handle; - int count; - int length; - byte *buf; - - handle = fopen(name, "rb"); - if (handle == NULL) i_error("Couldn't read file %s", name); - - /* find the size of the file by seeking to the end and - * reading the current position - */ - - length = m_file_length(handle); - - buf = z_malloc(length + 1, PU_STATIC, NULL); - count = fread(buf, 1, length, handle); - fclose(handle); - - if (count < length) i_error("Couldn't read file %s", name); - - buf[length] = '\0'; - *buffer = buf; - return length; -} - -/* Returns the path to a temporary file of the given name, stored - * inside the system temporary directory. - * - * The returned value must be freed with z_free after use. - */ - -char *m_temp_file(const char *s) -{ - const char *tempdir; - - /* Check the $TMPDIR environment variable to find the location. */ - - tempdir = getenv("TMPDIR"); - - if (tempdir == NULL) - { - tempdir = "/tmp"; - } - - return m_string_join(tempdir, DIR_SEPARATOR_S, s, NULL); -} - -boolean m_str_to_int(const char *str, int *result) -{ - return sscanf(str, " 0x%x", (unsigned int *)result) == 1 || - sscanf(str, " 0X%x", (unsigned int *)result) == 1 || - sscanf(str, " 0%o", (unsigned int *)result) == 1 || - sscanf(str, " %d", result) == 1; -} - -/* Returns the directory portion of the given path, without the trailing - * slash separator character. If no directory is described in the path, - * the string "." is returned. In either case, the result is newly allocated - * and must be freed by the caller after use. - */ - -char *m_dir_name(const char *path) -{ - char *result; - const char *pf; - const char *pb; - - pf = strrchr(path, '/'); - pb = NULL; - - if (pf == NULL && pb == NULL) - { - return m_string_duplicate("."); - } - else - { - const char *p = (pb > pf) ? pb : pf; - result = m_string_duplicate(path); - result[p - path] = '\0'; - return result; - } -} - -/* Returns the base filename described by the given path (without the - * directory name). The result points inside path and nothing new is - * allocated. - */ - -const char *m_base_name(const char *path) -{ - const char *pf; - const char *pb; - - pf = strrchr(path, '/'); - pb = NULL; - - if (pf == NULL && pb == NULL) - { - return path; - } - else - { - const char *p = (pb > pf) ? pb : pf; - return p + 1; - } -} - -void m_extract_file_base(const char *path, char *dest) -{ - const char *src; - const char *filename; - int length; - - src = path + strlen(path) - 1; - - /* back up until a \ or the start */ - - while (src != path && *(src - 1) != DIR_SEPARATOR) - { - src--; - } - - filename = src; - - /* Copy up to eight characters - * Note: Vanilla Doom exits with an error if a filename is specified - * with a base of more than eight characters. To remove the 8.3 - * filename limit, instead we simply truncate the name. - */ - - length = 0; - memset(dest, 0, 8); - - while (*src != '\0' && *src != '.') - { - if (length >= 8) - { - printf("Warning: Truncated '%s' lump name to '%.8s'.\n", filename, - dest); - break; - } - - dest[length++] = toupper((int)*src++); - } -} - -/**************************************************************************** - * Name: m_force_uppercase - * - * Description: - * (PROC) Change string to uppercase. - * - ****************************************************************************/ - -void m_force_uppercase(char *text) -{ - char *p; - - for (p = text; *p != '\0'; ++p) - { - *p = toupper(*p); - } -} - -/**************************************************************************** - * Name: m_force_lowercase - * - * Description: - * (PROC) Change string to lowercase. - * - ****************************************************************************/ - -void m_force_lowercase(char *text) -{ - char *p; - - for (p = text; *p != '\0'; ++p) - { - *p = tolower(*p); - } -} - -/**************************************************************************** - * Name: m_string_duplicate - * - * Description: - * Safe version of strdup() that checks the string was successfully - * allocated. - * - ****************************************************************************/ - -char *m_string_duplicate(const char *orig) -{ - char *result; - - result = strdup(orig); - - if (result == NULL) - { - i_error("Failed to duplicate string (length %zu)\n", strlen(orig)); - } - - return result; -} - -char *m_string_replace(const char *haystack, const char *needle, - const char *replacement) -{ - char *result; - char *dst; - const char *p; - size_t needle_len = strlen(needle); - size_t result_len; - size_t dst_len; - - /* Iterate through occurrences of 'needle' and calculate the size of - * the new string. - */ - - result_len = strlen(haystack) + 1; - p = haystack; - - for (; ; ) - { - p = strstr(p, needle); - if (p == NULL) - { - break; - } - - p += needle_len; - result_len += strlen(replacement) - needle_len; - } - - /* Construct new string. */ - - result = malloc(result_len); - if (result == NULL) - { - i_error("m_string_replace: Failed to allocate new string"); - return NULL; - } - - dst = result; - dst_len = result_len; - p = haystack; - - while (*p != '\0') - { - if (!strncmp(p, needle, needle_len)) - { - m_str_copy(dst, replacement, dst_len); - p += needle_len; - dst += strlen(replacement); - dst_len -= strlen(replacement); - } - else - { - *dst = *p; - ++dst; - --dst_len; - ++p; - } - } - - *dst = '\0'; - - return result; -} - -/* Safe string copy function that works like OpenBSD's strlcpy(). - * Returns true if the string was not truncated. - */ - -boolean m_str_copy(char *dest, const char *src, size_t dest_size) -{ - size_t len; - - if (dest_size >= 1) - { - dest[dest_size - 1] = '\0'; - strncpy(dest, src, dest_size - 1); - } - else - { - return false; - } - - len = strlen(dest); - return src[len] == '\0'; -} - -/* Safe string concat function that works like OpenBSD's strlcat(). - * Returns true if string not truncated. - */ - -boolean m_string_concat(char *dest, const char *src, size_t dest_size) -{ - size_t offset; - - offset = strlen(dest); - if (offset > dest_size) - { - offset = dest_size; - } - - return m_str_copy(dest + offset, src, dest_size - offset); -} - -/* Returns true if 's' begins with the specified prefix. */ - -boolean m_string_starts_with(const char *s, const char *prefix) -{ - return strlen(s) >= strlen(prefix) && - strncmp(s, prefix, strlen(prefix)) == 0; -} - -/* Returns true if 's' ends with the specified suffix. */ - -boolean m_string_ends_with(const char *s, const char *suffix) -{ - return strlen(s) >= strlen(suffix) && - strcmp(s + strlen(s) - strlen(suffix), suffix) == 0; -} - -/* Return a newly-malloced string with all the strings given as arguments - * concatenated together. - */ - -char *m_string_join(const char *s, ...) -{ - char *result; - const char *v; - va_list args; - size_t result_len; - - result_len = strlen(s) + 1; - - va_start(args, s); - - for (; ; ) - { - v = va_arg(args, const char *); - if (v == NULL) - { - break; - } - - result_len += strlen(v); - } - - va_end(args); - - result = malloc(result_len); - - if (result == NULL) - { - i_error("m_string_join: Failed to allocate new string."); - return NULL; - } - - m_str_copy(result, s, result_len); - - va_start(args, s); - - for (; ; ) - { - v = va_arg(args, const char *); - if (v == NULL) - { - break; - } - - m_string_concat(result, v, result_len); - } - - va_end(args); - - return result; -} - -/**************************************************************************** - * Name: m_normalize_slashes - * - * Description: - * Remove trailing slashes, translate backslashes to slashes. The string to - * normalize is passed and returned in str. - * - * killough 11/98: rewritten - * - * [STRIFE] - haleyjd 20110210: Borrowed from Eternity and adapted to - * respect the DIR_SEPARATOR define used by Choco Doom. This routine - * originated in BOOM. - * - ****************************************************************************/ - -void m_normalize_slashes(char *str) -{ - char *p; - - /* Convert all slashes/backslashes to DIR_SEPARATOR */ - - for (p = str; *p; p++) - { - if ((*p == '/' || *p == '\\') && *p != DIR_SEPARATOR) - { - *p = DIR_SEPARATOR; - } - } - - /* Remove trailing slashes */ - - while (p > str && *--p == DIR_SEPARATOR) - { - *p = 0; - } - - /* Collapse multiple slashes */ - - for (p = str; (*str++ = *p); ) - { - if (*p++ == DIR_SEPARATOR) - { - while (*p == DIR_SEPARATOR) - { - p++; - } - } - } -} diff --git a/games/NXDoom/src/m_misc.h b/games/NXDoom/src/m_misc.h deleted file mode 100644 index 0b310371e..000000000 --- a/games/NXDoom/src/m_misc.h +++ /dev/null @@ -1,111 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/m_misc.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Miscellaneous. - * - ****************************************************************************/ - -#ifndef __M_MISC__ -#define __M_MISC__ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include - -#include "doomtype.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* debugging code to check there are no loops in a linked list - * disabled unless explicitly requested - */ - -#ifdef DEBUG_LINKED_LISTS - -#define LINKED_LIST_CHECK_NO_CYCLE(list_type, list, next_member) \ - do \ - { \ - if (list != NULL) \ - { \ - list_type *slow, *fast; \ - slow = list; \ - fast = list->next_member; \ - while (fast) \ - { \ - if (!fast->next_member) \ - { \ - break; \ - } \ - fast = fast->next_member->next_member; \ - slow = slow->next_member; \ - if (slow == fast) \ - { \ - fprintf(stderr, "loop in linked list " #list " in %s:%d", \ - __FILE__, __LINE__); \ - __builtin_trap(); \ - } \ - } \ - } \ - } \ - while (0) - -#else /* DEBUG_LINKED_LISTS */ - -#define LINKED_LIST_CHECK_NO_CYCLE(list_type, list, next_member) \ - do \ - { \ - } \ - while (0) - -#endif /* DEBUG_LINKED_LISTS */ - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -boolean m_write_file(const char *name, const void *source, int length); -int m_read_file(const char *name, byte **buffer); -void m_make_directory(const char *dir); -char *m_temp_file(const char *s); -boolean m_file_exists(const char *file); -char *m_file_case_exists(const char *file); -long m_file_length(FILE *handle); -boolean m_str_to_int(const char *str, int *result); -char *m_dir_name(const char *path); -const char *m_base_name(const char *path); -void m_extract_file_base(const char *path, char *dest); -void m_force_uppercase(char *text); -void m_force_lowercase(char *text); -char *m_string_duplicate(const char *orig); -boolean m_str_copy(char *dest, const char *src, size_t dest_size); -boolean m_string_concat(char *dest, const char *src, size_t dest_size); -char *m_string_replace(const char *haystack, const char *needle, - const char *replacement); -char *m_string_join(const char *s, ...); -boolean m_string_starts_with(const char *s, const char *prefix); -boolean m_string_ends_with(const char *s, const char *suffix); -void m_normalize_slashes(char *str); - -#endif /* __M_MISC__ */ diff --git a/games/NXDoom/src/manifest.xml b/games/NXDoom/src/manifest.xml deleted file mode 100644 index 05a19e7ad..000000000 --- a/games/NXDoom/src/manifest.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - true - - - - diff --git a/games/NXDoom/src/memio.c b/games/NXDoom/src/memio.c deleted file mode 100644 index aeb8ac8a8..000000000 --- a/games/NXDoom/src/memio.c +++ /dev/null @@ -1,215 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/memio.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * Emulates the IO functions in C stdio.h reading and writing to - * memory. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include - -#include "memio.h" - -#include "z_zone.h" - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -typedef enum -{ - MODE_READ, - MODE_WRITE, -} memfile_mode_t; - -struct _MEMFILE -{ - unsigned char *buf; - size_t buflen; - size_t alloced; - unsigned int position; - memfile_mode_t mode; -}; - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/* Open a memory area for reading */ - -MEMFILE *mem_fopen_read(void *buf, size_t buflen) -{ - MEMFILE *file; - - file = z_malloc(sizeof(MEMFILE), PU_STATIC, 0); - - file->buf = (unsigned char *)buf; - file->buflen = buflen; - file->position = 0; - file->mode = MODE_READ; - - return file; -} - -/* Read bytes */ - -size_t mem_fread(void *buf, size_t size, size_t nmemb, MEMFILE *stream) -{ - size_t items; - - if (stream->mode != MODE_READ) - { - printf("not a read stream\n"); - return -1; - } - - /* Trying to read more bytes than we have left? */ - - items = nmemb; - - if (items * size > stream->buflen - stream->position) - { - items = (stream->buflen - stream->position) / size; - } - - /* Copy bytes to buffer */ - - memcpy(buf, stream->buf + stream->position, items * size); - - /* Update position */ - - stream->position += items * size; - - return items; -} - -/* Open a memory area for writing */ - -MEMFILE *mem_fopen_write(void) -{ - MEMFILE *file; - - file = z_malloc(sizeof(MEMFILE), PU_STATIC, 0); - - file->alloced = 1024; - file->buf = z_malloc(file->alloced, PU_STATIC, 0); - file->buflen = 0; - file->position = 0; - file->mode = MODE_WRITE; - - return file; -} - -/* Write bytes to stream */ - -size_t mem_fwrite(const void *ptr, size_t size, size_t nmemb, - MEMFILE *stream) -{ - size_t bytes; - - if (stream->mode != MODE_WRITE) - { - return -1; - } - - /* More bytes than can fit in the buffer? - * If so, reallocate bigger. - */ - - bytes = size * nmemb; - - while (bytes > stream->alloced - stream->position) - { - unsigned char *newbuf; - - newbuf = z_malloc(stream->alloced * 2, PU_STATIC, 0); - memcpy(newbuf, stream->buf, stream->alloced); - z_free(stream->buf); - stream->buf = newbuf; - stream->alloced *= 2; - } - - /* Copy into buffer */ - - memcpy(stream->buf + stream->position, ptr, bytes); - stream->position += bytes; - - if (stream->position > stream->buflen) stream->buflen = stream->position; - - return nmemb; -} - -void mem_get_buf(MEMFILE *stream, void **buf, size_t *buflen) -{ - *buf = stream->buf; - *buflen = stream->buflen; -} - -void mem_fclose(MEMFILE *stream) -{ - if (stream->mode == MODE_WRITE) - { - z_free(stream->buf); - } - - z_free(stream); -} - -long mem_ftell(MEMFILE *stream) -{ - return stream->position; -} - -int mem_fseek(MEMFILE *stream, signed long position, mem_rel_t whence) -{ - unsigned int newpos; - - switch (whence) - { - case MEM_SEEK_SET: - newpos = (int)position; - break; - - case MEM_SEEK_CUR: - newpos = (int)(stream->position + position); - break; - - case MEM_SEEK_END: - newpos = (int)(stream->buflen + position); - break; - default: - return -1; - } - - if (newpos < stream->buflen) - { - stream->position = newpos; - return 0; - } - else - { - printf("Error seeking to %u\n", newpos); - return -1; - } -} diff --git a/games/NXDoom/src/memio.h b/games/NXDoom/src/memio.h deleted file mode 100644 index 275fbc753..000000000 --- a/games/NXDoom/src/memio.h +++ /dev/null @@ -1,51 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/memio.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - ****************************************************************************/ - -#ifndef MEMIO_H -#define MEMIO_H - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -typedef struct _MEMFILE MEMFILE; - -typedef enum -{ - MEM_SEEK_SET, - MEM_SEEK_CUR, - MEM_SEEK_END, -} mem_rel_t; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -MEMFILE *mem_fopen_read(void *buf, size_t buflen); -size_t mem_fread(void *buf, size_t size, size_t nmemb, MEMFILE *stream); -MEMFILE *mem_fopen_write(void); -size_t mem_fwrite(const void *ptr, size_t size, size_t nmemb, - MEMFILE *stream); -void mem_get_buf(MEMFILE *stream, void **buf, size_t *buflen); -void mem_fclose(MEMFILE *stream); -long mem_ftell(MEMFILE *stream); -int mem_fseek(MEMFILE *stream, signed long offset, mem_rel_t whence); - -#endif /* MEMIO_H */ diff --git a/games/NXDoom/src/midifile.c b/games/NXDoom/src/midifile.c deleted file mode 100644 index 8374ac50d..000000000 --- a/games/NXDoom/src/midifile.c +++ /dev/null @@ -1,878 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/midifile.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Reading of MIDI files. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include -#include - -#include "doomtype.h" -#include "i_swap.h" -#include "i_system.h" -#include "m_misc.h" -#include "midifile.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define HEADER_CHUNK_ID "MThd" -#define TRACK_CHUNK_ID "MTrk" -#define MAX_BUFFER_SIZE 0x10000 - -/* haleyjd 09/09/10: packing required */ - -#ifdef _MSC_VER -#pragma pack(push, 1) -#endif - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -begin_packed_struct struct chunk_header_t -{ - byte chunk_id[4]; - unsigned int chunk_size; -} end_packed_struct; - -typedef struct chunk_header_t chunk_header_t; - -begin_packed_struct struct midi_header_t -{ - chunk_header_t chunk_header; - unsigned short format_type; - unsigned short num_tracks; - unsigned short time_division; -} begin_packed_struct; - -typedef struct midi_header_t midi_header_t; - -/* haleyjd 09/09/10: packing off. */ - -#ifdef _MSC_VER -#pragma pack(pop) -#endif - -typedef struct -{ - /* Length in bytes: */ - - unsigned int data_len; - - /* Events in this track: */ - - midi_event_t *events; - int num_events; -} midi_track_t; - -struct midi_track_iter_s -{ - midi_track_t *track; - unsigned int position; - unsigned int loop_point; -}; - -struct midi_file_s -{ - midi_header_t header; - - /* All tracks in this file: */ - - midi_track_t *tracks; - unsigned int num_tracks; - - /* Data buffer used to store data read for SysEx or meta events: */ - - byte *buffer; - unsigned int buffer_size; -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/* Check the header of a chunk: */ - -static boolean check_chunk_header(chunk_header_t *chunk, - const char *expected_id) -{ - boolean result; - - result = (memcmp((char *)chunk->chunk_id, expected_id, 4) == 0); - - if (!result) - { - fprintf(stderr, - "check_chunk_header: Expected '%s' chunk header, " - "got '%c%c%c%c'\n", - expected_id, chunk->chunk_id[0], chunk->chunk_id[1], - chunk->chunk_id[2], chunk->chunk_id[3]); - } - - return result; -} - -/* Read a single byte. Returns false on error. */ - -static boolean read_byte(byte *result, FILE *stream) -{ - int c; - - c = fgetc(stream); - - if (c == EOF) - { - fprintf(stderr, "read_byte: Unexpected end of file\n"); - return false; - } - else - { - *result = (byte)c; - - return true; - } -} - -/* Read a variable-length value. */ - -static boolean read_variable_length(unsigned int *result, FILE *stream) -{ - int i; - byte b = 0; - - *result = 0; - - for (i = 0; i < 4; ++i) - { - if (!read_byte(&b, stream)) - { - fprintf(stderr, "read_variable_length: Error while reading " - "variable-length value\n"); - return false; - } - - /* Insert the bottom seven bits from this byte. */ - - *result <<= 7; - *result |= b & 0x7f; - - /* If the top bit is not set, this is the end. */ - - if ((b & 0x80) == 0) - { - return true; - } - } - - fprintf(stderr, "read_variable_length: Variable-length value too " - "long: maximum of four bytes\n"); - return false; -} - -/* Read a byte sequence into the data buffer. */ - -static void *read_byte_sequence(unsigned int num_bytes, FILE *stream) -{ - unsigned int i; - byte *result; - - /* Allocate a buffer. Allocate one extra byte, as malloc(0) is - * non-portable. - */ - - result = malloc(num_bytes + 1); - - if (result == NULL) - { - fprintf(stderr, "read_byte_sequence: Failed to allocate buffer\n"); - return NULL; - } - - /* Read the data: */ - - for (i = 0; i < num_bytes; ++i) - { - if (!read_byte(&result[i], stream)) - { - fprintf(stderr, - "read_byte_sequence: Error while reading byte %u\n", i); - free(result); - return NULL; - } - } - - return result; -} - -/* Read a MIDI channel event. - * two_param indicates that the event type takes two parameters - * (three byte) otherwise it is single parameter (two byte) - */ - -static boolean read_channel_event(midi_event_t *event, byte event_type, - boolean two_param, FILE *stream) -{ - byte b = 0; - - /* Set basics: */ - - event->event_type = event_type & 0xf0; - event->data.channel.channel = event_type & 0x0f; - - /* Read parameters: */ - - if (!read_byte(&b, stream)) - { - fprintf(stderr, "read_channel_event: Error while reading channel " - "event parameters\n"); - return false; - } - - event->data.channel.param1 = b; - - /* Second parameter: */ - - if (two_param) - { - if (!read_byte(&b, stream)) - { - fprintf(stderr, "read_channel_event: Error while reading channel " - "event parameters\n"); - return false; - } - - event->data.channel.param2 = b; - } - - return true; -} - -/* Read sysex event: */ - -static boolean read_sys_ex_event(midi_event_t *event, int event_type, - FILE *stream) -{ - event->event_type = event_type; - - if (!read_variable_length(&event->data.sysex.length, stream)) - { - fprintf(stderr, "read_sys_ex_event: Failed to read length of " - "SysEx block\n"); - return false; - } - - /* Read the byte sequence: */ - - event->data.sysex.data = - read_byte_sequence(event->data.sysex.length, stream); - - if (event->data.sysex.data == NULL) - { - fprintf(stderr, - "read_sys_ex_event: Failed while reading SysEx event\n"); - return false; - } - - return true; -} - -/* Read meta event: */ - -static boolean read_meta_event(midi_event_t *event, FILE *stream) -{ - byte b = 0; - - event->event_type = MIDI_EVENT_META; - - /* Read meta event type: */ - - if (!read_byte(&b, stream)) - { - fprintf(stderr, "read_meta_event: Failed to read meta event type\n"); - return false; - } - - event->data.meta.type = b; - - /* Read length of meta event data: */ - - if (!read_variable_length(&event->data.meta.length, stream)) - { - fprintf(stderr, "read_sys_ex_event: Failed to read length of " - "SysEx block\n"); - return false; - } - - /* Read the byte sequence: */ - - event->data.meta.data = - read_byte_sequence(event->data.meta.length, stream); - - if (event->data.meta.data == NULL) - { - fprintf(stderr, - "read_sys_ex_event: Failed while reading SysEx event\n"); - return false; - } - - return true; -} - -static boolean read_event(midi_event_t *event, unsigned int *last_event_type, - FILE *stream) -{ - byte event_type = 0; - - if (!read_variable_length(&event->delta_time, stream)) - { - fprintf(stderr, "read_event: Failed to read event timestamp\n"); - return false; - } - - if (!read_byte(&event_type, stream)) - { - fprintf(stderr, "read_event: Failed to read event type\n"); - return false; - } - - /* All event types have their top bit set. Therefore, if - * the top bit is not set, it is because we are using the "same - * as previous event type" shortcut to save a byte. Skip back - * a byte so that we read this byte again. - */ - - if ((event_type & 0x80) == 0) - { - event_type = *last_event_type; - - if (fseek(stream, -1, SEEK_CUR) < 0) - { - fprintf(stderr, "read_event: Unable to seek in stream\n"); - return false; - } - } - else - { - *last_event_type = event_type; - } - - /* Check event type: */ - - switch (event_type & 0xf0) - { - /* Two parameter channel events: */ - - case MIDI_EVENT_NOTE_OFF: - case MIDI_EVENT_NOTE_ON: - case MIDI_EVENT_AFTERTOUCH: - case MIDI_EVENT_CONTROLLER: - case MIDI_EVENT_PITCH_BEND: - return read_channel_event(event, event_type, true, stream); - - /* Single parameter channel events: */ - - case MIDI_EVENT_PROGRAM_CHANGE: - case MIDI_EVENT_CHAN_AFTERTOUCH: - return read_channel_event(event, event_type, false, stream); - - default: - break; - } - - /* Specific value? */ - - switch (event_type) - { - case MIDI_EVENT_SYSEX: - case MIDI_EVENT_SYSEX_SPLIT: - return read_sys_ex_event(event, event_type, stream); - - case MIDI_EVENT_META: - return read_meta_event(event, stream); - - default: - break; - } - - fprintf(stderr, "read_event: Unknown MIDI event type: 0x%x\n", event_type); - return false; -} - -/* Free an event: */ - -static void free_event(midi_event_t *event) -{ - /* Some event types have dynamically allocated buffers assigned - * to them that must be freed. - */ - - switch (event->event_type) - { - case MIDI_EVENT_SYSEX: - case MIDI_EVENT_SYSEX_SPLIT: - free(event->data.sysex.data); - break; - - case MIDI_EVENT_META: - free(event->data.meta.data); - break; - - default: - break; /* Nothing to do. */ - } -} - -/* Read and check the track chunk header */ - -static boolean read_track_header(midi_track_t *track, FILE *stream) -{ - size_t records_read; - chunk_header_t chunk_header; - - records_read = fread(&chunk_header, sizeof(chunk_header_t), 1, stream); - - if (records_read < 1) - { - return false; - } - - if (!check_chunk_header(&chunk_header, TRACK_CHUNK_ID)) - { - return false; - } - - track->data_len = be32toh(chunk_header.chunk_size); - - return true; -} - -static boolean read_track(midi_track_t *track, FILE *stream) -{ - midi_event_t *new_events; - midi_event_t *event; - unsigned int last_event_type; - - track->num_events = 0; - track->events = NULL; - - /* Read the header: */ - - if (!read_track_header(track, stream)) - { - return false; - } - - /* Then the events: */ - - last_event_type = 0; - - for (; ; ) - { - /* Resize the track slightly larger to hold another event: */ - - new_events = i_realloc(track->events, - sizeof(midi_event_t) * (track->num_events + 1)); - track->events = new_events; - - /* Read the next event: */ - - event = &track->events[track->num_events]; - if (!read_event(event, &last_event_type, stream)) - { - return false; - } - - ++track->num_events; - - /* End of track? */ - - if (event->event_type == MIDI_EVENT_META && - event->data.meta.type == MIDI_META_END_OF_TRACK) - { - break; - } - } - - return true; -} - -/* Free a track: */ - -static void free_track(midi_track_t *track) -{ - unsigned int i; - - for (i = 0; i < track->num_events; ++i) - { - free_event(&track->events[i]); - } - - free(track->events); -} - -static boolean read_all_tracks(midi_file_t *file, FILE *stream) -{ - unsigned int i; - - /* Allocate list of tracks and read each track: */ - - file->tracks = malloc(sizeof(midi_track_t) * file->num_tracks); - - if (file->tracks == NULL) - { - return false; - } - - memset(file->tracks, 0, sizeof(midi_track_t) * file->num_tracks); - - /* Read each track: */ - - for (i = 0; i < file->num_tracks; ++i) - { - if (!read_track(&file->tracks[i], stream)) - { - return false; - } - } - - return true; -} - -/* Read and check the header chunk. */ - -static boolean read_file_header(midi_file_t *file, FILE *stream) -{ - size_t records_read; - unsigned int format_type; - - records_read = fread(&file->header, sizeof(midi_header_t), 1, stream); - - if (records_read < 1) - { - return false; - } - - if (!check_chunk_header(&file->header.chunk_header, HEADER_CHUNK_ID) || - be32toh(file->header.chunk_header.chunk_size) != 6) - { - fprintf(stderr, - "read_file_header: Invalid MIDI chunk header! " - "chunk_size=%i\n", - be32toh(file->header.chunk_header.chunk_size)); - return false; - } - - format_type = be32toh(file->header.format_type); - file->num_tracks = be32toh(file->header.num_tracks); - - if ((format_type != 0 && format_type != 1) || file->num_tracks < 1) - { - fprintf(stderr, "read_file_header: Only type 0/1 " - "MIDI files supported!\n"); - return false; - } - - return true; -} - -void midi_free_file(midi_file_t *file) -{ - int i; - - if (file->tracks != NULL) - { - for (i = 0; i < file->num_tracks; ++i) - { - free_track(&file->tracks[i]); - } - - free(file->tracks); - } - - free(file); -} - -midi_file_t *midi_loadfile(char *filename) -{ - midi_file_t *file; - FILE *stream; - - file = malloc(sizeof(midi_file_t)); - - if (file == NULL) - { - return NULL; - } - - file->tracks = NULL; - file->num_tracks = 0; - file->buffer = NULL; - file->buffer_size = 0; - - /* Open file */ - - stream = fopen(filename, "rb"); - - if (stream == NULL) - { - fprintf(stderr, "midi_loadfile: Failed to open '%s'\n", filename); - midi_free_file(file); - return NULL; - } - - /* Read MIDI file header */ - - if (!read_file_header(file, stream)) - { - fclose(stream); - midi_free_file(file); - return NULL; - } - - /* Read all tracks: */ - - if (!read_all_tracks(file, stream)) - { - fclose(stream); - midi_free_file(file); - return NULL; - } - - fclose(stream); - - return file; -} - -#ifdef TEST -static char *midi_event_type_to_string(midi_event_type_t event_type) -{ - switch (event_type) - { - case MIDI_EVENT_NOTE_OFF: - return "MIDI_EVENT_NOTE_OFF"; - case MIDI_EVENT_NOTE_ON: - return "MIDI_EVENT_NOTE_ON"; - case MIDI_EVENT_AFTERTOUCH: - return "MIDI_EVENT_AFTERTOUCH"; - case MIDI_EVENT_CONTROLLER: - return "MIDI_EVENT_CONTROLLER"; - case MIDI_EVENT_PROGRAM_CHANGE: - return "MIDI_EVENT_PROGRAM_CHANGE"; - case MIDI_EVENT_CHAN_AFTERTOUCH: - return "MIDI_EVENT_CHAN_AFTERTOUCH"; - case MIDI_EVENT_PITCH_BEND: - return "MIDI_EVENT_PITCH_BEND"; - case MIDI_EVENT_SYSEX: - return "MIDI_EVENT_SYSEX"; - case MIDI_EVENT_SYSEX_SPLIT: - return "MIDI_EVENT_SYSEX_SPLIT"; - case MIDI_EVENT_META: - return "MIDI_EVENT_META"; - - default: - return "(unknown)"; - } -} -#endif - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/* Get the number of tracks in a MIDI file. */ - -unsigned int midi_num_tracks(midi_file_t *file) -{ - return file->num_tracks; -} - -/* Start iterating over the events in a track. */ - -midi_track_iter_t *midi_iterate_track(midi_file_t *file, unsigned int track) -{ - midi_track_iter_t *iter; - - assert(track < file->num_tracks); - - iter = malloc(sizeof(*iter)); - iter->track = &file->tracks[track]; - iter->position = 0; - iter->loop_point = 0; - - return iter; -} - -void midi_free_iterator(midi_track_iter_t *iter) -{ - free(iter); -} - -/* Get the time until the next MIDI event in a track. */ - -unsigned int midi_get_delta_time(midi_track_iter_t *iter) -{ - if (iter->position < iter->track->num_events) - { - midi_event_t *next_event; - - next_event = &iter->track->events[iter->position]; - - return next_event->delta_time; - } - else - { - return 0; - } -} - -/* Get a pointer to the next MIDI event. */ - -int midi_get_next_event(midi_track_iter_t *iter, midi_event_t **event) -{ - if (iter->position < iter->track->num_events) - { - *event = &iter->track->events[iter->position]; - ++iter->position; - - return 1; - } - else - { - return 0; - } -} - -unsigned int midi_get_file_time_division(midi_file_t *file) -{ - short result = be16toh(file->header.time_division); - - /* Negative time division indicates SMPTE time and must be handled - * differently. - */ - - if (result < 0) - { - return (signed int)(-(result / 256)) * - (signed int)(result & 0xff); - } - else - { - return result; - } -} - -void midi_restart_iterator(midi_track_iter_t *iter) -{ - iter->position = 0; - iter->loop_point = 0; -} - -void midi_set_loop_point(midi_track_iter_t *iter) -{ - iter->loop_point = iter->position; -} - -void midi_restart_at_loop_point(midi_track_iter_t *iter) -{ - iter->position = iter->loop_point; -} - -#ifdef TEST -void print_track(midi_track_t *track) -{ - midi_event_t *event; - unsigned int i; - - for (i = 0; i < track->num_events; ++i) - { - event = &track->events[i]; - - if (event->delta_time > 0) - { - printf("Delay: %u ticks\n", event->delta_time); - } - - printf("Event type: %s (%i)\n", - midi_event_type_to_string(event->event_type), - event->event_type); - - switch (event->event_type) - { - case MIDI_EVENT_NOTE_OFF: - case MIDI_EVENT_NOTE_ON: - case MIDI_EVENT_AFTERTOUCH: - case MIDI_EVENT_CONTROLLER: - case MIDI_EVENT_PROGRAM_CHANGE: - case MIDI_EVENT_CHAN_AFTERTOUCH: - case MIDI_EVENT_PITCH_BEND: - printf("\tChannel: %u\n", event->data.channel.channel); - printf("\tParameter 1: %u\n", event->data.channel.param1); - printf("\tParameter 2: %u\n", event->data.channel.param2); - break; - - case MIDI_EVENT_SYSEX: - case MIDI_EVENT_SYSEX_SPLIT: - printf("\tLength: %u\n", event->data.sysex.length); - break; - - case MIDI_EVENT_META: - printf("\tMeta type: %u\n", event->data.meta.type); - printf("\tLength: %u\n", event->data.meta.length); - break; - } - } -} - -int main(int argc, char *argv[]) -{ - midi_file_t *file; - unsigned int i; - - if (argc < 2) - { - printf("Usage: %s \n", argv[0]); - exit(1); - } - - file = midi_loadfile(argv[1]); - - if (file == NULL) - { - fprintf(stderr, "Failed to open %s\n", argv[1]); - exit(1); - } - - for (i = 0; i < file->num_tracks; ++i) - { - printf("\n== Track %u ==\n\n", i); - - print_track(&file->tracks[i]); - } - - return 0; -} -#endif diff --git a/games/NXDoom/src/midifile.h b/games/NXDoom/src/midifile.h deleted file mode 100644 index e6dc9166e..000000000 --- a/games/NXDoom/src/midifile.h +++ /dev/null @@ -1,251 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/midifile.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * MIDI file parsing. - * - ****************************************************************************/ - -#ifndef MIDIFILE_H -#define MIDIFILE_H - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define MIDI_CHANNELS_PER_TRACK 16 - -#define MIDI_RPN_MSB 0x00 -#define MIDI_RPN_PITCH_BEND_SENS_LSB 0x00 -#define MIDI_RPN_FINE_TUNING_LSB 0x01 -#define MIDI_RPN_COARSE_TUNING_LSB 0x02 -#define MIDI_RPN_NULL 0x7f - -#define EMIDI_LOOP_FLAG 0x7f - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -typedef struct midi_file_s midi_file_t; -typedef struct midi_track_iter_s midi_track_iter_t; - -typedef enum -{ - MIDI_EVENT_NOTE_OFF = 0x80, - MIDI_EVENT_NOTE_ON = 0x90, - MIDI_EVENT_AFTERTOUCH = 0xa0, - MIDI_EVENT_CONTROLLER = 0xb0, - MIDI_EVENT_PROGRAM_CHANGE = 0xc0, - MIDI_EVENT_CHAN_AFTERTOUCH = 0xd0, - MIDI_EVENT_PITCH_BEND = 0xe0, - - MIDI_EVENT_SYSEX = 0xf0, - MIDI_EVENT_SYSEX_SPLIT = 0xf7, - MIDI_EVENT_META = 0xff, -} midi_event_type_t; - -typedef enum -{ - MIDI_CONTROLLER_BANK_SELECT_MSB = 0x00, - MIDI_CONTROLLER_MODULATION = 0x01, - MIDI_CONTROLLER_BREATH_CONTROL = 0x02, - MIDI_CONTROLLER_FOOT_CONTROL = 0x04, - MIDI_CONTROLLER_PORTAMENTO = 0x05, - MIDI_CONTROLLER_DATA_ENTRY_MSB = 0x06, - MIDI_CONTROLLER_VOLUME_MSB = 0x07, - MIDI_CONTROLLER_PAN = 0x0a, - MIDI_CONTROLLER_EXPRESSION = 0x0b, - - MIDI_CONTROLLER_BANK_SELECT_LSB = 0x20, - MIDI_CONTROLLER_DATA_ENTRY_LSB = 0x26, - MIDI_CONTROLLER_VOLUME_LSB = 0X27, - - MIDI_CONTROLLER_HOLD1_PEDAL = 0x40, - MIDI_CONTROLLER_SOFT_PEDAL = 0x43, - - MIDI_CONTROLLER_REVERB = 0x5b, - MIDI_CONTROLLER_CHORUS = 0x5d, - - MIDI_CONTROLLER_NRPN_LSB = 0x62, - MIDI_CONTROLLER_NRPN_MSB = 0x63, - MIDI_CONTROLLER_RPN_LSB = 0x64, - MIDI_CONTROLLER_RPN_MSB = 0x65, - - MIDI_CONTROLLER_ALL_SOUND_OFF = 0x78, - MIDI_CONTROLLER_RESET_ALL_CTRLS = 0x79, - MIDI_CONTROLLER_ALL_NOTES_OFF = 0x7b, - - MIDI_CONTROLLER_POLY_MODE_OFF = 0x7e, - MIDI_CONTROLLER_POLY_MODE_ON = 0x7f, -} midi_controller_t; - -typedef enum -{ - MIDI_META_SEQUENCE_NUMBER = 0x00, - - MIDI_META_TEXT = 0x01, - MIDI_META_COPYRIGHT = 0x02, - MIDI_META_TRACK_NAME = 0x03, - MIDI_META_INSTR_NAME = 0x04, - MIDI_META_LYRICS = 0x05, - MIDI_META_MARKER = 0x06, - MIDI_META_CUE_POINT = 0x07, - - MIDI_META_CHANNEL_PREFIX = 0x20, - MIDI_META_END_OF_TRACK = 0x2f, - - MIDI_META_SET_TEMPO = 0x51, - MIDI_META_SMPTE_OFFSET = 0x54, - MIDI_META_TIME_SIGNATURE = 0x58, - MIDI_META_KEY_SIGNATURE = 0x59, - MIDI_META_SEQUENCER_SPECIFIC = 0x7f, -} midi_meta_event_type_t; - -typedef enum -{ - EMIDI_DEVICE_GENERAL_MIDI = 0x00, - EMIDI_DEVICE_SOUND_CANVAS = 0x01, - EMIDI_DEVICE_AWE32 = 0x02, - EMIDI_DEVICE_WAVE_BLASTER = 0x03, - EMIDI_DEVICE_SOUND_BLASTER = 0x04, - EMIDI_DEVICE_PRO_AUDIO = 0x05, - EMIDI_DEVICE_SOUND_MAN_16 = 0x06, - EMIDI_DEVICE_ADLIB = 0x07, - EMIDI_DEVICE_SOUNDSCAPE = 0x08, - EMIDI_DEVICE_ULTRASOUND = 0x09, - EMIDI_DEVICE_ALL = 0x7f, -} emidi_device_t; - -typedef enum -{ - EMIDI_CONTROLLER_TRACK_DESIGNATION = 0x6e, - EMIDI_CONTROLLER_TRACK_EXCLUSION = 0x6f, - EMIDI_CONTROLLER_PROGRAM_CHANGE = 0x70, - EMIDI_CONTROLLER_VOLUME = 0x71, - EMIDI_CONTROLLER_LOOP_BEGIN = 0x74, - EMIDI_CONTROLLER_LOOP_END = 0x75, - EMIDI_CONTROLLER_GLOBAL_LOOP_BEGIN = 0x76, - EMIDI_CONTROLLER_GLOBAL_LOOP_END = 0x77, -} emidi_controller_t; - -typedef struct -{ - /* Meta event type: */ - - unsigned int type; - - /* Length: */ - - unsigned int length; - - /* Meta event data: */ - - byte *data; -} midi_meta_event_data_t; - -typedef struct -{ - /* Length: */ - - unsigned int length; - - /* Event data: */ - - byte *data; -} midi_sysex_event_data_t; - -typedef struct -{ - /* The channel number to which this applies: */ - - unsigned int channel; - - /* Extra parameters: */ - - unsigned int param1; - unsigned int param2; -} midi_channel_event_data_t; - -typedef struct -{ - /* Time between the previous event and this event. */ - - unsigned int delta_time; - - /* Type of event: */ - - midi_event_type_t event_type; - - union - { - midi_channel_event_data_t channel; - midi_meta_event_data_t meta; - midi_sysex_event_data_t sysex; - } data; -} midi_event_t; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/* Load a MIDI file. */ - -midi_file_t *midi_loadfile(char *filename); - -/* Free a MIDI file. */ - -void midi_free_file(midi_file_t *file); - -/* Get the time division value from the MIDI header. */ - -unsigned int midi_get_file_time_division(midi_file_t *file); - -/* Get the number of tracks in a MIDI file. */ - -unsigned int midi_num_tracks(midi_file_t *file); - -/* Start iterating over the events in a track. */ - -midi_track_iter_t *midi_iterate_track(midi_file_t *file, - unsigned int track_num); - -/* Free an iterator. */ - -void midi_free_iterator(midi_track_iter_t *iter); - -/* Get the time until the next MIDI event in a track. */ - -unsigned int midi_get_delta_time(midi_track_iter_t *iter); - -/* Get a pointer to the next MIDI event. */ - -int midi_get_next_event(midi_track_iter_t *iter, midi_event_t **event); - -/* Reset an iterator to the beginning of a track. */ - -void midi_restart_iterator(midi_track_iter_t *iter); - -/* Set loop point to current position. */ - -void midi_set_loop_point(midi_track_iter_t *iter); - -/* Set position to saved loop point. */ - -void midi_restart_at_loop_point(midi_track_iter_t *iter); - -#endif /* MIDIFILE_H */ diff --git a/games/NXDoom/src/mus2mid.c b/games/NXDoom/src/mus2mid.c deleted file mode 100644 index 502e10252..000000000 --- a/games/NXDoom/src/mus2mid.c +++ /dev/null @@ -1,794 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/mus2mid.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * Copyright(C) 2006 Ben Ryves 2006 - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * mus2mid.c - Ben Ryves 2006 - http: *benryves.com - benryves@benryves.com - * Use to convert a MUS file into a single track, type 0 MIDI file. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -#include "doomtype.h" -#include "i_swap.h" - -#include "memio.h" -#include "mus2mid.h" - -#ifdef STANDALONE -#include "m_misc.h" -#include "z_zone.h" -#endif - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define NUM_CHANNELS 16 - -#define MIDI_PERCUSSION_CHAN 9 -#define MUS_PERCUSSION_CHAN 15 - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/* MUS event codes */ - -typedef enum -{ - mus_releasekey = 0x00, - mus_presskey = 0x10, - mus_pitchwheel = 0x20, - mus_systemevent = 0x30, - mus_changecontroller = 0x40, - mus_scoreend = 0x60 -} musevent; - -/* MIDI event codes */ - -typedef enum -{ - midi_releasekey = 0x80, - midi_presskey = 0x90, - midi_aftertouchkey = 0xa0, - midi_changecontroller = 0xb0, - midi_changepatch = 0xc0, - midi_aftertouchchannel = 0xd0, - midi_pitchwheel = 0xe0 -} midievent; - -/* Structure to hold MUS file header */ - -begin_packed_struct struct musheader -{ - byte id[4]; - unsigned short scorelength; - unsigned short scorestart; - unsigned short primarychannels; - unsigned short secondarychannels; - unsigned short instrumentcount; -} end_packed_struct; - -typedef struct musheader musheader; - -/* Standard MIDI type 0 header + track header */ - -static const byte midiheader[] = -{ - 'M', 'T', 'h', 'd', /* Main header */ - 0x00, 0x00, 0x00, 0x06, /* Header size */ - 0x00, 0x00, /* MIDI type (0) */ - 0x00, 0x01, /* Number of tracks */ - 0x00, 0x46, /* Resolution */ - 'M', 'T', 'r', 'k', /* Start of track */ - 0x00, 0x00, 0x00, 0x00 /* Placeholder for track length */ -}; - -/* Cached channel velocities */ - -static byte channelvelocities[] = -{ - 127, 127, 127, 127, 127, 127, 127, 127, - 127, 127, 127, 127, 127, 127, 127, 127, -}; - -/* Timestamps between sequences of MUS events */ - -static unsigned int queuedtime = 0; - -/* Counter for the length of the track */ - -static unsigned int tracksize; - -static const byte controller_map[] = -{ - 0x00, 0x20, 0x01, 0x07, 0x0a, 0x0b, 0x5b, 0x5d, - 0x40, 0x43, 0x78, 0x7b, 0x7e, 0x7f, 0x79, -}; - -static int channel_map[NUM_CHANNELS]; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/* Write timestamp to a MIDI file. */ - -static boolean write_time(unsigned int time, MEMFILE *midioutput) -{ - unsigned int buffer = time & 0x7f; - byte writeval; - - while ((time >>= 7) != 0) - { - buffer <<= 8; - buffer |= ((time & 0x7f) | 0x80); - } - - for (; ; ) - { - writeval = (byte)(buffer & 0xff); - - if (mem_fwrite(&writeval, 1, 1, midioutput) != 1) - { - return true; - } - - ++tracksize; - - if ((buffer & 0x80) != 0) - { - buffer >>= 8; - } - else - { - queuedtime = 0; - return false; - } - } -} - -/* Write the end of track marker */ - -static boolean write_end_track(MEMFILE *midioutput) -{ - byte endtrack[] = - { - 0xff, 0x2f, 0x00 - }; - - if (write_time(queuedtime, midioutput)) - { - return true; - } - - if (mem_fwrite(endtrack, 1, 3, midioutput) != 3) - { - return true; - } - - tracksize += 3; - return false; -} - -/* Write a key press event */ - -static boolean write_press_key(byte channel, byte key, byte velocity, - MEMFILE *midioutput) -{ - byte working = midi_presskey | channel; - - if (write_time(queuedtime, midioutput)) - { - return true; - } - - if (mem_fwrite(&working, 1, 1, midioutput) != 1) - { - return true; - } - - working = key & 0x7f; - - if (mem_fwrite(&working, 1, 1, midioutput) != 1) - { - return true; - } - - working = velocity & 0x7f; - - if (mem_fwrite(&working, 1, 1, midioutput) != 1) - { - return true; - } - - tracksize += 3; - - return false; -} - -/* Write a key release event */ - -static boolean write_release_key(byte channel, byte key, MEMFILE *midioutput) -{ - byte working = midi_releasekey | channel; - - if (write_time(queuedtime, midioutput)) - { - return true; - } - - if (mem_fwrite(&working, 1, 1, midioutput) != 1) - { - return true; - } - - working = key & 0x7f; - - if (mem_fwrite(&working, 1, 1, midioutput) != 1) - { - return true; - } - - working = 0; - - if (mem_fwrite(&working, 1, 1, midioutput) != 1) - { - return true; - } - - tracksize += 3; - - return false; -} - -/* Write a pitch wheel/bend event */ - -static boolean write_pitch_wheel(byte channel, short wheel, - MEMFILE *midioutput) -{ - byte working = midi_pitchwheel | channel; - - if (write_time(queuedtime, midioutput)) - { - return true; - } - - if (mem_fwrite(&working, 1, 1, midioutput) != 1) - { - return true; - } - - working = wheel & 0x7f; - - if (mem_fwrite(&working, 1, 1, midioutput) != 1) - { - return true; - } - - working = (wheel >> 7) & 0x7f; - - if (mem_fwrite(&working, 1, 1, midioutput) != 1) - { - return true; - } - - tracksize += 3; - return false; -} - -/* Write a patch change event */ - -static boolean write_change_patch(byte channel, byte patch, - MEMFILE *midioutput) -{ - byte working = midi_changepatch | channel; - - if (write_time(queuedtime, midioutput)) - { - return true; - } - - if (mem_fwrite(&working, 1, 1, midioutput) != 1) - { - return true; - } - - working = patch & 0x7f; - - if (mem_fwrite(&working, 1, 1, midioutput) != 1) - { - return true; - } - - tracksize += 2; - - return false; -} - -/* Write a valued controller change event */ - -static boolean write_change_controller_valued(byte channel, byte control, - byte value, MEMFILE *midioutput) -{ - byte working = midi_changecontroller | channel; - - if (write_time(queuedtime, midioutput)) - { - return true; - } - - if (mem_fwrite(&working, 1, 1, midioutput) != 1) - { - return true; - } - - working = control & 0x7f; - - if (mem_fwrite(&working, 1, 1, midioutput) != 1) - { - return true; - } - - /* Quirk in vanilla DOOM? MUS controller values should be - * 7-bit, not 8-bit. - */ - - working = value; /* & 0x7F; */ - - /* Fix on said quirk to stop MIDI players from complaining that - * the value is out of range: - */ - - if (working & 0x80) - { - working = 0x7f; - } - - if (mem_fwrite(&working, 1, 1, midioutput) != 1) - { - return true; - } - - tracksize += 3; - - return false; -} - -/* Write a valueless controller change event */ - -static boolean write_change_controller_valueless(byte channel, byte control, - MEMFILE *midioutput) -{ - return write_change_controller_valued(channel, control, 0, midioutput); -} - -/* Allocate a free MIDI channel. */ - -static int allocate_midi_channel(void) -{ - int result; - int max; - int i; - - /* Find the current highest-allocated channel. */ - - max = -1; - - for (i = 0; i < NUM_CHANNELS; ++i) - { - if (channel_map[i] > max) - { - max = channel_map[i]; - } - } - - /* max is now equal to the highest-allocated MIDI channel. We can - * now allocate the next available channel. This also works if - * no channels are currently allocated (max=-1) - */ - - result = max + 1; - - /* Don't allocate the MIDI percussion channel! */ - - if (result == MIDI_PERCUSSION_CHAN) - { - ++result; - } - - return result; -} - -/* Given a MUS channel number, get the MIDI channel number to use - * in the outputted file. - */ - -static int get_midi_channel(int mus_channel, MEMFILE *midioutput) -{ - /* Find the MIDI channel to use for this MUS channel. - * MUS channel 15 is the percusssion channel. - */ - - if (mus_channel == MUS_PERCUSSION_CHAN) - { - return MIDI_PERCUSSION_CHAN; - } - else - { - /* If a MIDI channel hasn't been allocated for this MUS channel - * yet, allocate the next free MIDI channel. - */ - - if (channel_map[mus_channel] == -1) - { - channel_map[mus_channel] = allocate_midi_channel(); - - /* First time using the channel, send an "all notes off" - * event. This fixes "The D_DDTBLU disease" described here: - * https: *www.doomworld.com/vb/source-ports/66802-the - */ - - write_change_controller_valueless(channel_map[mus_channel], 0x7b, - midioutput); - } - - return channel_map[mus_channel]; - } -} - -static boolean read_mus_header(MEMFILE *file, musheader *header) -{ - boolean result; - - result = - mem_fread(&header->id, sizeof(byte), 4, file) == 4 && - mem_fread(&header->scorelength, sizeof(short), 1, file) == 1 && - mem_fread(&header->scorestart, sizeof(short), 1, file) == 1 && - mem_fread(&header->primarychannels, sizeof(short), 1, file) == 1 && - mem_fread(&header->secondarychannels, sizeof(short), 1, file) == 1 && - mem_fread(&header->instrumentcount, sizeof(short), 1, file) == 1; - - if (result) - { - header->scorelength = SHORT(header->scorelength); - header->scorestart = SHORT(header->scorestart); - header->primarychannels = SHORT(header->primarychannels); - header->secondarychannels = SHORT(header->secondarychannels); - header->instrumentcount = SHORT(header->instrumentcount); - } - - return result; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/* Read a MUS file from a stream (musinput) and output a MIDI file to - * a stream (midioutput). - * - * Returns 0 on success or 1 on failure. - */ - -boolean mus2mid(MEMFILE *musinput, MEMFILE *midioutput) -{ - /* Header for the MUS file */ - - musheader musfileheader; - - /* Descriptor for the current MUS event */ - - byte eventdescriptor; - int channel; /* Channel number */ - musevent event; - - /* Bunch of vars read from MUS lump */ - - byte key; - byte controllernumber; - byte controllervalue; - - /* Buffer used for MIDI track size record */ - - byte tracksizebuffer[4]; - - /* Flag for when the score end marker is hit. */ - - int hitscoreend = 0; - - /* Temp working byte */ - - byte working; - - /* Used in building up time delays */ - - unsigned int timedelay; - - /* Initialise channel map to mark all channels as unused. */ - - for (channel = 0; channel < NUM_CHANNELS; ++channel) - { - channel_map[channel] = -1; - } - - /* Grab the header */ - - if (!read_mus_header(musinput, &musfileheader)) - { - return true; - } - - /* Check MUS header */ - -#ifdef CHECK_MUS_HEADER - if (musfileheader.id[0] != 'M' || musfileheader.id[1] != 'U' || - musfileheader.id[2] != 'S' || musfileheader.id[3] != 0x1a) - { - return true; - } -#endif - - /* Seek to where the data is held */ - - if (mem_fseek(musinput, (long)musfileheader.scorestart, MEM_SEEK_SET) != 0) - { - return true; - } - - /* So, we can assume the MUS file is faintly legit. Let's start - * writing MIDI data... - */ - - mem_fwrite(midiheader, 1, sizeof(midiheader), midioutput); - tracksize = 0; - - /* Now, process the MUS file: */ - - while (!hitscoreend) - { - /* Handle a block of events: */ - - while (!hitscoreend) - { - /* Fetch channel number and event code: */ - - if (mem_fread(&eventdescriptor, 1, 1, musinput) != 1) - { - return true; - } - - channel = get_midi_channel(eventdescriptor & 0x0f, midioutput); - event = eventdescriptor & 0x70; - - switch (event) - { - case mus_releasekey: - if (mem_fread(&key, 1, 1, musinput) != 1) - { - return true; - } - - if (write_release_key(channel, key, midioutput)) - { - return true; - } - - break; - - case mus_presskey: - if (mem_fread(&key, 1, 1, musinput) != 1) - { - return true; - } - - if (key & 0x80) - { - if (mem_fread(&channelvelocities[channel], 1, 1, - musinput) != 1) - { - return true; - } - - channelvelocities[channel] &= 0x7f; - } - - if (write_press_key(channel, key, channelvelocities[channel], - midioutput)) - { - return true; - } - - break; - - case mus_pitchwheel: - if (mem_fread(&key, 1, 1, musinput) != 1) - { - break; - } - - if (write_pitch_wheel(channel, (short)(key * 64), midioutput)) - { - return true; - } - - break; - - case mus_systemevent: - if (mem_fread(&controllernumber, 1, 1, musinput) != 1) - { - return true; - } - - if (controllernumber < 10 || controllernumber > 14) - { - return true; - } - - if (write_change_controller_valueless( - channel, controller_map[controllernumber], midioutput)) - { - return true; - } - - break; - - case mus_changecontroller: - if (mem_fread(&controllernumber, 1, 1, musinput) != 1) - { - return true; - } - - if (mem_fread(&controllervalue, 1, 1, musinput) != 1) - { - return true; - } - - if (controllernumber == 0) - { - if (write_change_patch(channel, controllervalue, - midioutput)) - { - return true; - } - } - else - { - if (controllernumber < 1 || controllernumber > 9) - { - return true; - } - - if (write_change_controller_valued( - channel, controller_map[controllernumber], - controllervalue, midioutput)) - { - return true; - } - } - - break; - - case mus_scoreend: - hitscoreend = 1; - break; - - default: - return true; - break; - } - - if (eventdescriptor & 0x80) - { - break; - } - } - - /* Now we need to read the time code: */ - - if (!hitscoreend) - { - timedelay = 0; - for (; ; ) - { - if (mem_fread(&working, 1, 1, musinput) != 1) - { - return true; - } - - timedelay = timedelay * 128 + (working & 0x7f); - if ((working & 0x80) == 0) - { - break; - } - } - - queuedtime += timedelay; - } - } - - /* End of track */ - - if (write_end_track(midioutput)) - { - return true; - } - - /* Write the track size into the stream */ - - if (mem_fseek(midioutput, 18, MEM_SEEK_SET)) - { - return true; - } - - tracksizebuffer[0] = (tracksize >> 24) & 0xff; - tracksizebuffer[1] = (tracksize >> 16) & 0xff; - tracksizebuffer[2] = (tracksize >> 8) & 0xff; - tracksizebuffer[3] = tracksize & 0xff; - - if (mem_fwrite(tracksizebuffer, 1, 4, midioutput) != 4) - { - return true; - } - - return false; -} - -#ifdef STANDALONE -int main(int argc, char *argv[]) -{ - MEMFILE *src, *dst; - byte *infile; - long infile_len; - void *outfile; - size_t outfile_len; - - if (argc != 3) - { - printf("Usage: %s \n", argv[0]); - exit(-1); - } - - z_init(); - - infile_len = m_read_file(argv[1], &infile); - - src = mem_fopen_read(infile, infile_len); - dst = mem_fopen_write(); - - if (mus2mid(src, dst)) - { - fprintf(stderr, "mus2mid() failed\n"); - exit(-1); - } - - /* Write result to output file: */ - - mem_get_buf(dst, &outfile, &outfile_len); - - m_write_file(argv[2], outfile, outfile_len); - - return 0; -} -#endif /* STANDALONE */ diff --git a/games/NXDoom/src/mus2mid.h b/games/NXDoom/src/mus2mid.h deleted file mode 100644 index e8cafc4a8..000000000 --- a/games/NXDoom/src/mus2mid.h +++ /dev/null @@ -1,41 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/mus2mid.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * Copyright(C) 2006 Ben Ryves 2006 - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * mus2mid.h - Ben Ryves 2006 - http: *benryves.com - benryves@benryves.com - * Use to convert a MUS file into a single track, type 0 MIDI file. - * - ****************************************************************************/ - -#ifndef MUS2MID_H -#define MUS2MID_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "doomtype.h" -#include "memio.h" - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -boolean mus2mid(MEMFILE *musinput, MEMFILE *midioutput); - -#endif /* MUS2MID_H */ diff --git a/games/NXDoom/src/net_client.c b/games/NXDoom/src/net_client.c deleted file mode 100644 index fb589f692..000000000 --- a/games/NXDoom/src/net_client.c +++ /dev/null @@ -1,1311 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/net_client.c - * - * SPDX-License-Identifier: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * Network client code - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include -#include - -#include "config.h" -#include "d_loop.h" -#include "deh_main.h" -#include "deh_str.h" -#include "doomtype.h" -#include "i_system.h" -#include "i_timer.h" -#include "m_argv.h" -#include "m_config.h" -#include "m_fixed.h" -#include "m_misc.h" -#include "net_client.h" -#include "net_common.h" -#include "net_defs.h" -#include "net_gui.h" -#include "net_io.h" -#include "net_packet.h" -#include "net_query.h" -#include "net_server.h" -#include "net_structrw.h" -#include "w_checksum.h" -#include "w_wad.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define net_cl_expand_ticnum(b) net_expand_tic_num(recvwindow_start, (b)) - -#define KP 0.1 -#define KI 0.01 -#define KD 0.02 - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -typedef enum -{ - /* waiting for the game to launch */ - - CLIENT_STATE_WAITING_LAUNCH, - - /* waiting for the game to start */ - - CLIENT_STATE_WAITING_START, - - /* in game */ - - CLIENT_STATE_IN_GAME, -} net_clientstate_t; - -/* Type of structure used in the receive window */ - -typedef struct -{ - /* Whether this tic has been received yet */ - - boolean active; - - /* Last time we sent a resend request for this tic */ - - unsigned int resend_time; - - /* Tic data from server */ - - net_full_ticcmd_t cmd; -} net_server_recv_t; - -/* Type of structure used in the send window */ - -typedef struct -{ - /* Whether this slot is active yet */ - - boolean active; - - /* The tic number */ - - unsigned int seq; - - /* Time the command was generated */ - - unsigned int time; - - /* Ticcmd diff */ - - net_ticdiff_t cmd; -} net_server_send_t; - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static net_connection_t client_connection; -static net_clientstate_t client_state; -static net_addr_t *server_addr; -static net_context_t *client_context; - -/* game settings, as received from the server when the game started */ - -static net_gamesettings_t settings; - -/* The last ticcmd constructed */ - -static ticcmd_t last_ticcmd; - -/* Buffer of ticcmd diffs being sent to the server */ - -static net_server_send_t send_queue[CONFIG_GAMES_NXDOOM_NET_BACKUPTICS]; - -/* Receive window */ - -static ticcmd_t recvwindow_cmd_base[CONFIG_GAMES_NXDOOM_NET_MAXPLAYERS]; -static int recvwindow_start; -static net_server_recv_t recvwindow[CONFIG_GAMES_NXDOOM_NET_BACKUPTICS]; - -/* Whether we need to send an acknowledgement and - * when gamedata was last received. - */ - -static boolean need_to_acknowledge; -static unsigned int gamedata_recv_time; - -/* The latency (time between when we sent our command and we got all - * the other players' commands from the server) for the last tic we - * received. We include this latency in tics we send to the server so - * that they can adjust to us. - */ - -static int last_latency; - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/* Why did the server reject us? */ - -char *net_client_reject_reason = NULL; - -/* true if the client code is in use */ - -boolean net_client_connected; - -/* true if we have received waiting data from the server, - * and the wait data that was received. - */ - -boolean net_client_received_wait_data; -net_waitdata_t net_client_wait_data; - -/* Waiting at the initial wait screen for the game to be launched? */ - -boolean net_waiting_for_launch = false; - -/* Name that we send to the server */ - -char *net_player_name = NULL; - -/* Connected but not participating in the game (observer) */ - -boolean drone = false; - -/* Hash checksums of our wad directory and dehacked data. */ - -sha1_digest_t net_local_wad_sha1sum; -sha1_digest_t net_local_deh_sha1sum; - -/* Are we playing with the freedoom IWAD? */ - -unsigned int net_local_is_freedoom; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/* Called when we become disconnected from the server */ - -static void net_cl_disconnected(void) -{ - d_receive_tic(NULL, NULL); -} - -/* Called when a packet is received from the server containing game - * data. This updates the clock synchronization variable (offsetms) - * using a PID filter that keeps client clocks in sync. - */ - -static void update_clock_sync(unsigned int seq, unsigned int remote_latency) -{ - static int last_error; - static int cumul_error; - int latency; - int error; - - if (seq == send_queue[seq % CONFIG_GAMES_NXDOOM_NET_BACKUPTICS].seq) - { - latency = i_get_time_ms() - - send_queue[seq % CONFIG_GAMES_NXDOOM_NET_BACKUPTICS].time; - } - else if (seq > send_queue[seq % CONFIG_GAMES_NXDOOM_NET_BACKUPTICS].seq) - { - /* We have received the ticcmd from the server before we have - * even sent ours - */ - - latency = 0; - } - else - { - return; - } - - /* PID filter. These are manually trained parameters. */ - - /* How does our latency compare to the worst other player? */ - - error = latency - remote_latency; - cumul_error += error; - - offsetms = KP * (FRACUNIT * error) - KI * (FRACUNIT * cumul_error) + - (KD * FRACUNIT) * (last_error - error); - - last_error = error; - last_latency = latency; - - net_log_info( - "client: latency %d, remote %d -> offset=%dms, cumul_error=%d", - latency, remote_latency, offsetms / FRACUNIT, cumul_error); -} - -/* Expand a net_full_ticcmd_t, applying the diffs in cmd->cmds as - * patches against recvwindow_cmd_base. Place the results into - * the d_net.c structures (netcmds/nettics) and save the new ticcmd - * back into recvwindow_cmd_base. - */ - -static void net_cl_expand_full_ticcmd(net_full_ticcmd_t *cmd, - unsigned int seq, ticcmd_t *ticcmds) -{ - int i; - - /* Expand tic diffs for all players */ - - for (i = 0; i < CONFIG_GAMES_NXDOOM_NET_MAXPLAYERS; ++i) - { - if (i == settings.consoleplayer && !drone) - { - continue; - } - - if (cmd->playeringame[i]) - { - net_ticdiff_t *diff; - - diff = &cmd->cmds[i]; - - /* Use the ticcmd diff to patch the previous ticcmd to - * the new ticcmd - */ - - net_ticcmd_patch(&recvwindow_cmd_base[i], diff, &ticcmds[i]); - - /* Store a copy for next time */ - - recvwindow_cmd_base[i] = ticcmds[i]; - } - } -} - -/* Advance the receive window */ - -static void net_cl_advance_window(void) -{ - ticcmd_t ticcmds[CONFIG_GAMES_NXDOOM_NET_MAXPLAYERS]; - - while (recvwindow[0].active) - { - /* Expand tic diff data into d_net.c structures */ - - net_cl_expand_full_ticcmd(&recvwindow[0].cmd, recvwindow_start, - ticcmds); - d_receive_tic(ticcmds, recvwindow[0].cmd.playeringame); - - /* Advance the window */ - - memmove(recvwindow, recvwindow + 1, - sizeof(net_server_recv_t) * - (CONFIG_GAMES_NXDOOM_NET_BACKUPTICS - 1)); - memset(&recvwindow[CONFIG_GAMES_NXDOOM_NET_BACKUPTICS - 1], 0, - sizeof(net_server_recv_t)); - - ++recvwindow_start; - - net_log_info("client: advanced receive window to %d", - recvwindow_start); - } -} - -/* Shut down the client code, etc. Invoked after a disconnect. */ - -static void net_cl_shutdown(void) -{ - if (net_client_connected) - { - net_client_connected = false; - - net_release_address(server_addr); - - /* Shut down network module, etc. To do. */ - } -} - -static void net_cl_send_game_data_ack(void) -{ - net_packet_t *packet; - - packet = net_new_packet(10); - - net_write_int16(packet, NET_PACKET_TYPE_GAMEDATA_ACK); - net_write_int8(packet, recvwindow_start & 0xff); - - net_conn_send_packet(&client_connection, packet); - - net_free_packet(packet); - - need_to_acknowledge = false; -} - -static void net_cl_send_tics(int start, int end) -{ - net_packet_t *packet; - int i; - - if (!net_client_connected) - { - /* Disconnected from server */ - - return; - } - - if (start < 0) start = 0; - - /* Build a new packet to send to the server */ - - packet = net_new_packet(512); - net_write_int16(packet, NET_PACKET_TYPE_GAMEDATA); - - /* Write the start tic and number of tics. Send only the low byte - * of start - it can be inferred by the server. - */ - - net_write_int8(packet, recvwindow_start & 0xff); - net_write_int8(packet, start & 0xff); - net_write_int8(packet, end - start + 1); - - /* Add the tics. */ - - for (i = start; i <= end; ++i) - { - net_server_send_t *sendobj; - - sendobj = &send_queue[i % CONFIG_GAMES_NXDOOM_NET_BACKUPTICS]; - - net_write_int16(packet, last_latency); - - net_write_ticcmd_diff(packet, &sendobj->cmd, settings.lowres_turn); - } - - /* Send the packet */ - - net_conn_send_packet(&client_connection, packet); - - /* All done! */ - - net_free_packet(packet); - - /* Acknowledgement has been sent as part of the packet */ - - need_to_acknowledge = false; -} - -/* Parse a SYN packet received back from the server indicating a successful - * connection attempt. - */ - -static void net_cl_parse_syn(net_packet_t *packet) -{ - net_protocol_t protocol; - char *server_version; - - net_log_info("client: processing SYN response"); - - server_version = net_read_safe_string(packet); - if (server_version == NULL) - { - net_log_err("client: failed to read server version"); - return; - } - - protocol = net_read_protocol(packet); - if (protocol == NET_PROTOCOL_UNKNOWN) - { - net_log_err("client: can't find a common protocol"); - return; - } - - /* We are now successfully connected. */ - - net_log_info("client: connected to server"); - client_connection.state = NET_CONN_STATE_CONNECTED; - client_connection.protocol = protocol; - - /* Even though we have negotiated a compatible protocol, the game may still - * desync. Chocolate Doom's philosophy makes this unlikely, but if we're - * playing with a forked version, or even against a different version that - * fixes a compatibility issue, we may still have problems. - */ - - if (strcmp(server_version, PACKAGE_STRING) != 0) - { - fprintf(stderr, - "NET_CL_ParseSYN: This is '%s', but the server is " - "'%s'. It is possible that this mismatch may cause the game " - "to desync.\n", - PACKAGE_STRING, server_version); - } -} - -static void set_reject_reason(const char *s) -{ - free(net_client_reject_reason); - if (s != NULL) - { - net_client_reject_reason = strdup(s); - } - else - { - net_client_reject_reason = NULL; - } -} - -static void net_cl_parse_reject(net_packet_t *packet) -{ - char *msg; - - msg = net_read_safe_string(packet); - if (msg == NULL) - { - return; - } - - if (client_connection.state == NET_CONN_STATE_CONNECTING) - { - client_connection.state = NET_CONN_STATE_DISCONNECTED; - client_connection.disconnect_reason = NET_DISCONNECT_REMOTE; - set_reject_reason(msg); - } -} - -/* data received while we are waiting for the game to start */ - -static void net_cl_parse_waiting_data(net_packet_t *packet) -{ - net_waitdata_t wait_data; - - if (!net_read_wait_data(packet, &wait_data)) - { - /* Invalid packet? */ - - return; - } - - if (wait_data.num_players > wait_data.max_players || - wait_data.ready_players > wait_data.num_players || - wait_data.max_players > CONFIG_GAMES_NXDOOM_NET_MAXPLAYERS) - { - /* insane data */ - - return; - } - - if ((wait_data.consoleplayer >= 0 && drone) || - (wait_data.consoleplayer < 0 && !drone) || - (wait_data.consoleplayer >= wait_data.num_players)) - { - /* Invalid player number */ - - return; - } - - memcpy(&net_client_wait_data, &wait_data, sizeof(net_waitdata_t)); - net_client_received_wait_data = true; -} - -static void net_cl_parse_launch(net_packet_t *packet) -{ - unsigned int num_players; - - net_log_info("client: processing launch packet"); - - if (client_state != CLIENT_STATE_WAITING_LAUNCH) - { - net_log_err("client: not in waiting launch state, client_state=%d", - client_state); - return; - } - - /* The launch packet contains the number of players that will be - * in the game when it starts, so that we can do the startup - * progress indicator (the wait data is unreliable). - */ - - if (!net_read_int8(packet, &num_players)) - { - net_log_err("client: failed to read number of players"); - return; - } - - net_client_wait_data.num_players = num_players; - client_state = CLIENT_STATE_WAITING_START; - net_log_err("client: now waiting for game start"); -} - -static void net_cl_parse_game_start(net_packet_t *packet) -{ - net_log_info("client: processing game start packet"); - - if (!net_read_settings(packet, &settings)) - { - net_log_err("client: failed to read settings"); - return; - } - - if (client_state != CLIENT_STATE_WAITING_START) - { - net_log_err("client: not in waiting start state, client_state=%d", - client_state); - return; - } - - if (settings.num_players > CONFIG_GAMES_NXDOOM_NET_MAXPLAYERS || - settings.consoleplayer >= (signed int)settings.num_players) - { - /* insane values */ - - net_log_err("client: bad settings, num_players=%d, consoleplayer=%d", - settings.num_players, settings.consoleplayer); - return; - } - - if ((drone && settings.consoleplayer >= 0) || - (!drone && settings.consoleplayer < 0)) - { - /* Invalid player number: must be positive for real players, - * negative for drones - */ - - net_log_err("client: mismatch: drone=%d, consoleplayer=%d", drone, - settings.consoleplayer); - return; - } - - net_log_info("client: beginning game state"); - client_state = CLIENT_STATE_IN_GAME; - - /* Clear the receive window */ - - memset(recvwindow, 0, sizeof(recvwindow)); - recvwindow_start = 0; - memset(&recvwindow_cmd_base, 0, sizeof(recvwindow_cmd_base)); - - /* Clear the send queue */ - - memset(&send_queue, 0x00, sizeof(send_queue)); -} - -static void net_cl_send_resend_request(int start, int end) -{ - net_packet_t *packet; - unsigned int nowtime; - int i; - - packet = net_new_packet(64); - net_write_int16(packet, NET_PACKET_TYPE_GAMEDATA_RESEND); - net_write_int32(packet, start); - net_write_int8(packet, end - start + 1); - net_conn_send_packet(&client_connection, packet); - net_free_packet(packet); - - nowtime = i_get_time_ms(); - - /* Save the time we sent the resend request */ - - for (i = start; i <= end; ++i) - { - int index; - - index = i - recvwindow_start; - - if (index < 0 || index >= CONFIG_GAMES_NXDOOM_NET_BACKUPTICS) continue; - - recvwindow[index].resend_time = nowtime; - } -} - -/* Check for expired resend requests */ - -static void net_cl_check_resends(void) -{ - int i; - int resend_start; - int resend_end; - unsigned int nowtime; - boolean maybe_deadlocked; - - nowtime = i_get_time_ms(); - maybe_deadlocked = nowtime - gamedata_recv_time > 1000; - - resend_start = -1; - resend_end = -1; - - for (i = 0; i < CONFIG_GAMES_NXDOOM_NET_BACKUPTICS; ++i) - { - net_server_recv_t *recvobj; - boolean need_resend; - - recvobj = &recvwindow[i]; - - /* if need_resend is true, this tic needs another retransmit - * request (300ms timeout) - */ - - need_resend = !recvobj->active && recvobj->resend_time != 0 && - nowtime > recvobj->resend_time + 300; - - /* if no game data has been received in a long time, we may be in - * a deadlock scenario where tics from the server have been lost, so - * we've stopped generating any more, so the server isn't sending us - * any, so we don't get any to trigger a resend request. So force the - * first few tics in the receive window to be requested. - */ - - if (i == 0 && !recvobj->active && recvobj->resend_time == 0 && - maybe_deadlocked) - { - need_resend = true; - } - - if (need_resend) - { - /* Start a new run of resend tics? */ - - if (resend_start < 0) - { - resend_start = i; - } - - resend_end = i; - } - else if (resend_start >= 0) - { - /* End of a run of resend tics */ - - net_log_info("client: resend request timed out for %d-%d (%d)", - recvwindow_start + resend_start, - recvwindow_start + resend_end, - recvwindow[resend_start].resend_time); - net_cl_send_resend_request(recvwindow_start + resend_start, - recvwindow_start + resend_end); - resend_start = -1; - } - } - - if (resend_start >= 0) - { - net_log_info("client: resend request timed out for %d-%d (%d)", - recvwindow_start + resend_start, - recvwindow_start + resend_end, - recvwindow[resend_start].resend_time); - net_cl_send_resend_request(recvwindow_start + resend_start, - recvwindow_start + resend_end); - } - - /* We have received some data from the server and not acknowledged - * it yet. Normally this gets acknowledged when we send our game - * data, but if the client is a drone we need to do this. - */ - - if (need_to_acknowledge && nowtime - gamedata_recv_time > 200) - { - net_log_info("client: no game data received since %d: triggering ack", - gamedata_recv_time); - net_cl_send_game_data_ack(); - } -} - -/* Parsing of NET_PACKET_TYPE_GAMEDATA packets - * (packets containing the actual ticcmd data) - */ - -static void net_cl_parse_game_data(net_packet_t *packet) -{ - net_server_recv_t *recvobj; - unsigned int seq; - unsigned int num_tics; - unsigned int nowtime; - int resend_start; - int resend_end; - size_t i; - int index; - - net_log_info("client: processing game data packet"); - - /* Read header */ - - if (!net_read_int8(packet, &seq) || !net_read_int8(packet, &num_tics)) - { - net_log_info("client: error: failed to read header"); - return; - } - - nowtime = i_get_time_ms(); - - /* Whatever happens, we now need to send an acknowledgement of our - * current receive point. - */ - - if (!need_to_acknowledge) - { - need_to_acknowledge = true; - gamedata_recv_time = nowtime; - } - - /* Expand byte value into the full tic number */ - - seq = net_cl_expand_ticnum(seq); - net_log_info("client: got game data, seq=%d, num_tics=%d", seq, num_tics); - - for (i = 0; i < num_tics; ++i) - { - net_full_ticcmd_t cmd; - - index = seq - recvwindow_start + i; - - if (!net_read_full_ticcmd(packet, &cmd, settings.lowres_turn)) - { - net_log_err("client: failed to read ticcmd %zu", i); - return; - } - - if (index < 0 || index >= CONFIG_GAMES_NXDOOM_NET_BACKUPTICS) - { - /* Out of range of the recv window */ - - continue; - } - - /* Store in the receive window */ - - recvobj = &recvwindow[index]; - - recvobj->active = true; - recvobj->cmd = cmd; - net_log_info("client: stored tic %zu in receive window", seq + i); - - /* If a packet is lost or arrives out of order, we might get - * the tic in the next packet instead (because of extratic). - * If that's the case then the latency for receiving that tic - * now will be bogus. So we only use the last tic in the packet - * to trigger a clock sync update. - */ - - if (i == num_tics - 1) - { - update_clock_sync(seq + i, cmd.latency); - } - } - - /* Has this been received out of sequence, ie. have we not received - * all tics before the first tic in this packet? If so, send a - * resend request. - */ - - resend_end = seq - recvwindow_start; - - if (resend_end <= 0) return; - - if (resend_end >= CONFIG_GAMES_NXDOOM_NET_BACKUPTICS) - { - resend_end = CONFIG_GAMES_NXDOOM_NET_BACKUPTICS - 1; - } - - index = resend_end - 1; - resend_start = resend_end; - - while (index >= 0) - { - recvobj = &recvwindow[index]; - - if (recvobj->active) - { - /* ended our run of unreceived tics */ - - break; - } - - if (recvobj->resend_time != 0) - { - /* Already sent a resend request for this tic */ - - break; - } - - resend_start = index; - --index; - } - - /* Possibly send a resend request */ - - if (resend_start < resend_end) - { - net_log_info("client: request resend for %d-%d before %d", - recvwindow_start + resend_start, - recvwindow_start + resend_end - 1, seq); - net_cl_send_resend_request(recvwindow_start + resend_start, - recvwindow_start + resend_end - 1); - } -} - -/* Parse a resend request from the server due to a dropped packet */ - -static void net_cl_parse_resend_request(net_packet_t *packet) -{ - static unsigned int start; - static unsigned int end; - static unsigned int num_tics; - - net_log_info("client: processing resend request"); - - if (drone) - { - /* Drones don't send gamedata. */ - - net_log_err("client: resend request but we're a drone?"); - return; - } - - if (!net_read_int32(packet, &start) || !net_read_int8(packet, &num_tics)) - { - net_log_err("client: couldn't read start and num_tics"); - return; - } - - end = start + num_tics - 1; - - net_log_info("client: resend request: start=%d, num_tics=%d", start, - num_tics); - - /* Check we have the tics being requested. If not, reduce the - * window of tics to only what we have. - */ - - while ( - start <= end && - (!send_queue[start % CONFIG_GAMES_NXDOOM_NET_BACKUPTICS].active || - send_queue[start % CONFIG_GAMES_NXDOOM_NET_BACKUPTICS].seq != start)) - { - ++start; - } - - while (start <= end && - (!send_queue[end % CONFIG_GAMES_NXDOOM_NET_BACKUPTICS].active || - send_queue[end % CONFIG_GAMES_NXDOOM_NET_BACKUPTICS].seq != end)) - { - --end; - } - - /* Resend those tics */ - - if (start <= end) - { - net_log_info("client: resending %d-%d", start, end); - net_cl_send_tics(start, end); - } - else - { - net_log_info("client: don't have the tics to resend"); - } -} - -/* Console message that the server wants the client to print */ - -static void net_cl_parse_console_message(net_packet_t *packet) -{ - char *msg; - - msg = net_read_safe_string(packet); - - if (msg == NULL) - { - return; - } - - printf("Message from server:\n%s\n", msg); -} - -/* parse a received packet */ - -static void net_cl_parse_packet(net_packet_t *packet) -{ - unsigned int packet_type; - - if (!net_read_int16(packet, &packet_type)) - { - return; - } - - net_log_info("client: packet from server, type %d", - packet_type & ~NET_RELIABLE_PACKET); - net_log_packet(packet); - - if (net_conn_packet(&client_connection, packet, &packet_type)) - { - /* Packet eaten by the common connection code */ - } - else - { - switch (packet_type) - { - case NET_PACKET_TYPE_SYN: - net_cl_parse_syn(packet); - break; - - case NET_PACKET_TYPE_REJECTED: - net_cl_parse_reject(packet); - break; - - case NET_PACKET_TYPE_WAITING_DATA: - net_cl_parse_waiting_data(packet); - break; - - case NET_PACKET_TYPE_LAUNCH: - net_cl_parse_launch(packet); - break; - - case NET_PACKET_TYPE_GAMESTART: - net_cl_parse_game_start(packet); - break; - - case NET_PACKET_TYPE_GAMEDATA: - net_cl_parse_game_data(packet); - break; - - case NET_PACKET_TYPE_GAMEDATA_RESEND: - net_cl_parse_resend_request(packet); - break; - - case NET_PACKET_TYPE_CONSOLE_MESSAGE: - net_cl_parse_console_message(packet); - break; - - default: - break; - } - } -} - -static void net_cl_send_syn(net_connect_data_t *data) -{ - net_packet_t *packet; - - net_log_info("client: sending SYN"); - - packet = net_new_packet(10); - net_write_int16(packet, NET_PACKET_TYPE_SYN); - net_write_int32(packet, NET_MAGIC_NUMBER); - net_write_string(packet, PACKAGE_STRING); - net_write_protocol_list(packet); - net_write_connect_data(packet, data); - net_write_string(packet, net_player_name); - net_conn_send_packet(&client_connection, packet); - net_free_packet(packet); -} - -static void net_cl_init(void) -{ - /* Try to set from the USER and USERNAME environment variables - * Otherwise, fallback to "Player" - */ - - if (net_player_name == NULL) - { - net_player_name = "Player"; - } -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -void net_cl_launch_game(void) -{ - net_conn_new_reliable(&client_connection, NET_PACKET_TYPE_LAUNCH); -} - -void net_cl_start_game(net_gamesettings_t *p_settings) -{ - net_packet_t *packet; - - /* Start from a ticcmd of all zeros */ - - memset(&last_ticcmd, 0, sizeof(ticcmd_t)); - - /* Send packet */ - - packet = - net_conn_new_reliable(&client_connection, NET_PACKET_TYPE_GAMESTART); - - net_write_settings(packet, p_settings); -} - -/* Add a new ticcmd to the send queue */ - -void net_cl_send_ticcmd(ticcmd_t *ticcmd, int maketic) -{ - net_ticdiff_t diff; - net_server_send_t *sendobj; - int starttic; - int endtic; - - /* Calculate the difference to the last ticcmd */ - - net_ticcmd_diff(&last_ticcmd, ticcmd, &diff); - - /* Store in the send queue */ - - sendobj = &send_queue[maketic % CONFIG_GAMES_NXDOOM_NET_BACKUPTICS]; - sendobj->active = true; - sendobj->seq = maketic; - sendobj->time = i_get_time_ms(); - sendobj->cmd = diff; - - last_ticcmd = *ticcmd; - - /* Send to server. */ - - starttic = maketic - settings.extratics; - endtic = maketic; - - if (starttic < 0) starttic = 0; - - net_log_info("client: generated tic %d, sending %d-%d", maketic, starttic, - endtic); - net_cl_send_tics(starttic, endtic); -} - -/* "Run" the client code: check for new packets, send packets as - * needed - */ - -void net_cl_run(void) -{ - net_addr_t *addr; - net_packet_t *packet; - - if (!net_client_connected) - { - return; - } - - while (net_recv_packet(client_context, &addr, &packet)) - { - /* only accept packets from the server */ - - if (addr == server_addr) - { - net_cl_parse_packet(packet); - } - - net_free_packet(packet); - net_release_address(addr); - } - - /* Run the common connection code to send any packets as needed */ - - net_conn_run(&client_connection); - - if (client_connection.state == NET_CONN_STATE_DISCONNECTED || - client_connection.state == NET_CONN_STATE_DISCONNECTED_SLEEP) - { - net_cl_disconnected(); - - net_cl_shutdown(); - } - - net_waiting_for_launch = - client_connection.state == NET_CONN_STATE_CONNECTED && - client_state == CLIENT_STATE_WAITING_LAUNCH; - - if (client_state == CLIENT_STATE_IN_GAME) - { - /* Possibly advance the receive window */ - - net_cl_advance_window(); - - /* Check if our resend requests have timed out */ - - net_cl_check_resends(); - } -} - -/* Connect to a server */ - -boolean net_cl_connect(net_addr_t *addr, net_connect_data_t *data) -{ - int start_time; - int last_send_time; - boolean sent_hole_punch; - - server_addr = addr; - net_reference_address(addr); - - memcpy(net_local_wad_sha1sum, data->wad_sha1sum, sizeof(sha1_digest_t)); - memcpy(net_local_deh_sha1sum, data->deh_sha1sum, sizeof(sha1_digest_t)); - net_local_is_freedoom = data->is_freedoom; - - /* create a new network I/O context and add just the necessary module */ - - client_context = net_new_context(); - - /* initialize module for client mode */ - - if (!addr->module->init_client()) - { - set_reject_reason("Failed to initialize client module"); - return false; - } - - net_add_module(client_context, addr->module); - - net_client_connected = true; - net_client_received_wait_data = false; - sent_hole_punch = false; - - net_conn_init_client(&client_connection, addr, NET_PROTOCOL_UNKNOWN); - - /* try to connect */ - - start_time = i_get_time_ms(); - last_send_time = -1; - set_reject_reason("Unknown reason"); - - while (client_connection.state == NET_CONN_STATE_CONNECTING) - { - int nowtime = i_get_time_ms(); - - /* Send a SYN packet every second. */ - - if (nowtime - last_send_time > 1000 || last_send_time < 0) - { - net_cl_send_syn(data); - last_send_time = nowtime; - } - - /* time out after 5 seconds */ - - if (nowtime - start_time > 5000) - { - set_reject_reason("No response from server"); - break; - } - - if (!sent_hole_punch && nowtime - start_time > 2000) - { - net_log_warn("client: no response to SYN, requesting hole punch"); - net_request_hole_punch(client_context, addr); - sent_hole_punch = true; - } - - /* run client code */ - - net_cl_run(); - - /* run the server, just in case we are doing a loopback connect */ - - net_sv_run(); - - /* Don't hog the CPU */ - - usleep(1000); - } - - if (client_connection.state == NET_CONN_STATE_CONNECTED) - { - /* connected ok! */ - - net_log_info("client: connected successfully"); - set_reject_reason(NULL); - client_state = CLIENT_STATE_WAITING_LAUNCH; - drone = data->drone; - - return true; - } - else - { - /* failed to connect */ - - net_log_err("client: failed to connect"); - net_cl_shutdown(); - - return false; - } -} - -/* read game settings received from server */ - -boolean net_cl_get_settings(net_gamesettings_t *_settings) -{ - if (client_state != CLIENT_STATE_IN_GAME) - { - return false; - } - - memcpy(_settings, &settings, sizeof(net_gamesettings_t)); - - return true; -} - -/* disconnect from the server */ - -void net_cl_disconnect(void) -{ - int start_time; - - if (!net_client_connected) - { - return; - } - - net_log_info("client: beginning disconnect"); - net_conn_disconnect(&client_connection); - - start_time = i_get_time_ms(); - - while (client_connection.state != NET_CONN_STATE_DISCONNECTED && - client_connection.state != NET_CONN_STATE_DISCONNECTED_SLEEP) - { - if (i_get_time_ms() - start_time > 5000) - { - /* time out after 5 seconds */ - - net_log_err("client: no acknowledgement of disconnect received"); - client_state = CLIENT_STATE_WAITING_START; - - fprintf(stderr, "net_cl_disconnect: Timeout while disconnecting " - "from server\n"); - break; - } - - net_cl_run(); - net_sv_run(); - - usleep(1000); - } - - /* Finished sending disconnect packets, etc. */ - - net_log_info("client: disconnect complete"); - net_cl_shutdown(); -} - -void net_init(void) -{ - net_cl_init(); -} - -void net_bind_variables(void) -{ - m_bind_string_variable("player_name", &net_player_name); -} diff --git a/games/NXDoom/src/net_client.h b/games/NXDoom/src/net_client.h deleted file mode 100644 index abe3d1b82..000000000 --- a/games/NXDoom/src/net_client.h +++ /dev/null @@ -1,69 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/net_client.h - * - * SPDX-License-Identifier: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * Network client code - * - ****************************************************************************/ - -#ifndef NET_CLIENT_H -#define NET_CLIENT_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "d_ticcmd.h" -#include "doomtype.h" -#include "net_defs.h" -#include "sha1.h" - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -extern boolean net_client_connected; -extern boolean net_client_received_wait_data; -extern net_waitdata_t net_client_wait_data; -extern char *net_client_reject_reason; -extern boolean net_waiting_for_launch; -extern char *net_player_name; - -extern sha1_digest_t net_server_wad_sha1sum; -extern sha1_digest_t net_server_deh_sha1sum; -extern unsigned int net_server_is_freedoom; -extern sha1_digest_t net_local_wad_sha1sum; -extern sha1_digest_t net_local_deh_sha1sum; -extern unsigned int net_local_is_freedoom; - -extern boolean drone; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -boolean net_cl_connect(net_addr_t *addr, net_connect_data_t *data); -void net_cl_disconnect(void); -void net_cl_run(void); -void net_cl_launch_game(void); -void net_cl_start_game(net_gamesettings_t *settings); -void net_cl_send_ticcmd(ticcmd_t *ticcmd, int maketic); -boolean net_cl_get_settings(net_gamesettings_t *_settings); -void net_init(void); - -void net_bind_variables(void); - -#endif /* NET_CLIENT_H */ diff --git a/games/NXDoom/src/net_common.c b/games/NXDoom/src/net_common.c deleted file mode 100644 index 62dac01ca..000000000 --- a/games/NXDoom/src/net_common.c +++ /dev/null @@ -1,532 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/net_common.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * Common code shared between the client and server - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include -#include - -#include "d_mode.h" -#include "doomtype.h" -#include "i_system.h" -#include "i_timer.h" -#include "m_argv.h" -#include "m_misc.h" - -#include "net_common.h" -#include "net_io.h" -#include "net_packet.h" -#include "net_structrw.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* connections time out after 30 seconds */ - -#define CONNECTION_TIMEOUT_LEN 30 - -/* maximum time between sending packets */ - -#define KEEPALIVE_PERIOD 1 - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/* reliable packet that is guaranteed to reach its destination */ - -struct net_reliable_packet_s -{ - net_packet_t *packet; - int last_send_time; - int seq; - net_reliable_packet_t *next; -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static void net_conn_init(net_connection_t *conn, net_addr_t *addr, - net_protocol_t protocol) -{ - conn->last_send_time = -1; - conn->num_retries = 0; - conn->addr = addr; - conn->protocol = protocol; - conn->reliable_packets = NULL; - conn->reliable_send_seq = 0; - conn->reliable_recv_seq = 0; - conn->keepalive_recv_time = i_get_time_ms(); -} - -static void net_conn_parse_disconnect(net_connection_t *conn, - net_packet_t *packet) -{ - net_packet_t *reply; - - /* Other end wants to disconnect - * Send a DISCONNECT_ACK reply. - */ - - reply = net_new_packet(10); - net_write_int16(reply, NET_PACKET_TYPE_DISCONNECT_ACK); - net_conn_send_packet(conn, reply); - net_free_packet(reply); - - conn->last_send_time = i_get_time_ms(); - - conn->state = NET_CONN_STATE_DISCONNECTED_SLEEP; - conn->disconnect_reason = NET_DISCONNECT_REMOTE; -} - -/* Parse a DISCONNECT_ACK packet */ - -static void net_conn_parse_disconnect_ack(net_connection_t *conn, - net_packet_t *packet) -{ - if (conn->state == NET_CONN_STATE_DISCONNECTING) - { - /* We have received an acknowledgement to our disconnect - * request. We have been disconnected successfully. - */ - - conn->state = NET_CONN_STATE_DISCONNECTED; - conn->disconnect_reason = NET_DISCONNECT_LOCAL; - conn->last_send_time = -1; - } -} - -static void net_conn_parse_reliable_ack(net_connection_t *conn, - net_packet_t *packet) -{ - unsigned int seq; - - if (!net_read_int8(packet, &seq)) - { - return; - } - - if (conn->reliable_packets == NULL) - { - return; - } - - /* Is this an acknowledgement for the first packet in the list? */ - - if (seq == (unsigned int)((conn->reliable_packets->seq + 1) & 0xff)) - { - net_reliable_packet_t *rp; - - /* Discard it, then. - * Unlink from the list. - */ - - rp = conn->reliable_packets; - conn->reliable_packets = rp->next; - - net_free_packet(rp->packet); - free(rp); - } -} - -/* Process the header of a reliable packet - * - * Returns true if the packet should be discarded (incorrect sequence) - */ - -static boolean net_connect_reliable_packet(net_connection_t *conn, - net_packet_t *packet) -{ - unsigned int seq; - net_packet_t *reply; - boolean result; - - /* Read the sequence number */ - - if (!net_read_int8(packet, &seq)) - { - return true; - } - - if (seq != (unsigned int)(conn->reliable_recv_seq & 0xff)) - { - /* This is not the next expected packet in the sequence! - * - * Discard the packet. If we were smart, we would use a proper - * sliding window protocol to do this, but I'm lazy. - */ - - result = true; - } - else - { - /* Now we can receive the next packet in the sequence. */ - - conn->reliable_recv_seq = (conn->reliable_recv_seq + 1) & 0xff; - - result = false; - } - - /* Send an acknowledgement */ - - /* Note: this is braindead. It would be much more sensible to - * include this in the next packet, rather than the overhead of - * sending a complete packet just for one byte of information. - */ - - reply = net_new_packet(10); - - net_write_int16(reply, NET_PACKET_TYPE_RELIABLE_ACK); - net_write_int8(reply, conn->reliable_recv_seq & 0xff); - - net_conn_send_packet(conn, reply); - - net_free_packet(reply); - - return result; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/* Initialize as a client connection */ - -void net_conn_init_client(net_connection_t *conn, net_addr_t *addr, - net_protocol_t protocol) -{ - net_conn_init(conn, addr, protocol); - conn->state = NET_CONN_STATE_CONNECTING; -} - -/* Initialize as a server connection */ - -void net_conn_init_server(net_connection_t *conn, net_addr_t *addr, - net_protocol_t protocol) -{ - net_conn_init(conn, addr, protocol); - conn->state = NET_CONN_STATE_CONNECTED; -} - -/* Send a packet to a connection - * All packets should be sent through this interface, as it maintains the - * keepalive_send_time counter. - */ - -void net_conn_send_packet(net_connection_t *conn, net_packet_t *packet) -{ - conn->keepalive_send_time = i_get_time_ms(); - net_send_packet(conn->addr, packet); -} - -/* Process a packet received by the server - * - * Returns true if eaten by common code - */ - -boolean net_conn_packet(net_connection_t *conn, net_packet_t *packet, - unsigned int *packet_type) -{ - conn->keepalive_recv_time = i_get_time_ms(); - - /* Is this a reliable packet? */ - - if (*packet_type & NET_RELIABLE_PACKET) - { - if (net_connect_reliable_packet(conn, packet)) - { - /* Invalid packet: eat it. */ - - return true; - } - - /* Remove the reliable bit */ - - *packet_type &= ~NET_RELIABLE_PACKET; - } - - switch (*packet_type) - { - case NET_PACKET_TYPE_DISCONNECT: - net_conn_parse_disconnect(conn, packet); - break; - case NET_PACKET_TYPE_DISCONNECT_ACK: - net_conn_parse_disconnect_ack(conn, packet); - break; - case NET_PACKET_TYPE_KEEPALIVE: - break; /* No special action needed. */ - case NET_PACKET_TYPE_RELIABLE_ACK: - net_conn_parse_reliable_ack(conn, packet); - break; - default: - return false; /* Not a common packet */ - } - - /* We found a packet that we found interesting, and ate it. */ - - return true; -} - -void net_conn_disconnect(net_connection_t *conn) -{ - if (conn->state != NET_CONN_STATE_DISCONNECTED && - conn->state != NET_CONN_STATE_DISCONNECTING && - conn->state != NET_CONN_STATE_DISCONNECTED_SLEEP) - { - conn->state = NET_CONN_STATE_DISCONNECTING; - conn->disconnect_reason = NET_DISCONNECT_LOCAL; - conn->last_send_time = -1; - conn->num_retries = 0; - } -} - -void net_conn_run(net_connection_t *conn) -{ - net_packet_t *packet; - unsigned int nowtime; - - nowtime = i_get_time_ms(); - - if (conn->state == NET_CONN_STATE_CONNECTED) - { - /* Check the keepalive counters */ - - if (nowtime - conn->keepalive_recv_time > - CONNECTION_TIMEOUT_LEN * 1000) - { - /* Haven't received any packets from the other end in a long - * time. Assume disconnected. - */ - - conn->state = NET_CONN_STATE_DISCONNECTED; - conn->disconnect_reason = NET_DISCONNECT_TIMEOUT; - } - - if (nowtime - conn->keepalive_send_time > KEEPALIVE_PERIOD * 1000) - { - /* We have not sent anything in a long time. - * Send a keepalive. - */ - - packet = net_new_packet(10); - net_write_int16(packet, NET_PACKET_TYPE_KEEPALIVE); - net_conn_send_packet(conn, packet); - net_free_packet(packet); - } - - /* Check the reliable packet list. Has the first packet in the - * list timed out? - * - * NB. This is braindead, we have a fixed time of one second. - */ - - if (conn->reliable_packets != NULL && - (conn->reliable_packets->last_send_time < 0 || - nowtime - conn->reliable_packets->last_send_time > 1000)) - { - /* Packet timed out, time to resend */ - - net_conn_send_packet(conn, conn->reliable_packets->packet); - conn->reliable_packets->last_send_time = nowtime; - } - } - else if (conn->state == NET_CONN_STATE_DISCONNECTING) - { - /* Waiting for a reply to our DISCONNECT request. */ - - if (conn->last_send_time < 0 || nowtime - conn->last_send_time > 1000) - { - /* it has been a second since the last disconnect packet - * was sent, and still no reply. - */ - - if (conn->num_retries < MAX_RETRIES) - { - /* send another disconnect */ - - packet = net_new_packet(10); - net_write_int16(packet, NET_PACKET_TYPE_DISCONNECT); - net_conn_send_packet(conn, packet); - net_free_packet(packet); - conn->last_send_time = nowtime; - - ++conn->num_retries; - } - else - { - /* No more retries allowed. Force disconnect. */ - - conn->state = NET_CONN_STATE_DISCONNECTED; - conn->disconnect_reason = NET_DISCONNECT_LOCAL; - } - } - } - else if (conn->state == NET_CONN_STATE_DISCONNECTED_SLEEP) - { - /* We are disconnected, waiting in case we need to send - * a DISCONNECT_ACK to the server again. - */ - - if (nowtime - conn->last_send_time > 5000) - { - /* Idle for 5 seconds, switch state */ - - conn->state = NET_CONN_STATE_DISCONNECTED; - conn->disconnect_reason = NET_DISCONNECT_REMOTE; - } - } -} - -net_packet_t *net_conn_new_reliable(net_connection_t *conn, int packet_type) -{ - net_packet_t *packet; - net_reliable_packet_t *rp; - net_reliable_packet_t **listend; - - /* Generate a packet with the right header */ - - packet = net_new_packet(100); - - net_write_int16(packet, packet_type | NET_RELIABLE_PACKET); - - /* write the low byte of the send sequence number */ - - net_write_int8(packet, conn->reliable_send_seq & 0xff); - - /* Add to the list of reliable packets */ - - rp = malloc(sizeof(net_reliable_packet_t)); - rp->packet = packet; - rp->next = NULL; - rp->seq = conn->reliable_send_seq; - rp->last_send_time = -1; - - for (listend = &conn->reliable_packets; *listend != NULL; - listend = &((*listend)->next)) - ; - - *listend = rp; - - /* Count along the sequence */ - - conn->reliable_send_seq = (conn->reliable_send_seq + 1) & 0xff; - - /* Finished */ - - return packet; -} - -/* Used to expand the least significant byte of a tic number into - * the full tic number, from the current tic number - */ - -unsigned int net_expand_tic_num(unsigned int relative, unsigned int b) -{ - unsigned int l; - unsigned int h; - unsigned int result; - - h = relative & ~0xff; - l = relative & 0xff; - - result = h | b; - - if (l < 0x40 && b > 0xb0) result -= 0x100; - if (l > 0xb0 && b < 0x40) result += 0x100; - - return result; -} - -/* Check that game settings are valid */ - -boolean net_valid_game_settings(game_mode_t mode, gamemission_t mission, - net_gamesettings_t *settings) -{ - if (settings->ticdup <= 0) - { - return false; - } - - if (settings->extratics < 0) - { - return false; - } - - if (settings->deathmatch < 0 || settings->deathmatch > 2) - { - return false; - } - - if (settings->skill < sk_noitems || settings->skill > sk_nightmare) - { - return false; - } - - if (!d_valid_game_version(mission, settings->gameversion)) - { - return false; - } - - if (!d_valid_episode_map(mission, mode, settings->episode, settings->map)) - { - return false; - } - - return true; -} - -#ifdef CONFIG_GAMES_NXDOOM_NET_LOGS -void net_log_packet(net_packet_t *packet) -{ - int i; - int bytes; - - bytes = packet->len - packet->pos; - if (bytes == 0) - { - return; - } - - fprintf(stderr, "\t%02x", packet->data[packet->pos]); - - for (i = 1; i < bytes; ++i) - { - if ((i % 16) == 0) - { - fprintf(stderr, "\n\t"); - } - else - { - fprintf(stderr, " "); - } - - fprintf(stderr, "%02x", packet->data[packet->pos + i]); - } - - fprintf(stderr, "\n"); -} -#endif /* CONFIG_GAMES_NXDOOM_NET_LOGS */ diff --git a/games/NXDoom/src/net_common.h b/games/NXDoom/src/net_common.h deleted file mode 100644 index 09770a1b2..000000000 --- a/games/NXDoom/src/net_common.h +++ /dev/null @@ -1,145 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/net_common.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * Common code shared between the client and server - * - ****************************************************************************/ - -#ifndef NET_COMMON_H -#define NET_COMMON_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include "d_mode.h" -#include "net_defs.h" -#include "net_packet.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define MAX_RETRIES 5 - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -typedef enum -{ - /* Client has sent a SYN, is waiting for a SYN in response. */ - - NET_CONN_STATE_CONNECTING, - - /* Successfully connected. */ - - NET_CONN_STATE_CONNECTED, - - /* Sent a DISCONNECT packet, waiting for a DISCONNECT_ACK reply */ - - NET_CONN_STATE_DISCONNECTING, - - /* Client successfully disconnected */ - - NET_CONN_STATE_DISCONNECTED, - - /* We are disconnected, but in a sleep state, waiting for several - * seconds. This is in case the DISCONNECT_ACK we sent failed - * to arrive, and we need to send another one. We keep this as - * a valid connection for a few seconds until we are sure that - * the other end has successfully disconnected as well. - */ - - NET_CONN_STATE_DISCONNECTED_SLEEP, -} net_connstate_t; - -/* Reason a connection was terminated */ - -typedef enum -{ - /* As the result of a local disconnect request */ - - NET_DISCONNECT_LOCAL, - - /* As the result of a remote disconnect request */ - - NET_DISCONNECT_REMOTE, - - /* Timeout (no data received in a long time) */ - - NET_DISCONNECT_TIMEOUT, -} net_disconnect_reason_t; - -typedef struct net_reliable_packet_s net_reliable_packet_t; - -typedef struct -{ - net_connstate_t state; - net_disconnect_reason_t disconnect_reason; - net_addr_t *addr; - net_protocol_t protocol; - int last_send_time; - int num_retries; - int keepalive_send_time; - int keepalive_recv_time; - net_reliable_packet_t *reliable_packets; - int reliable_send_seq; - int reliable_recv_seq; -} net_connection_t; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -void net_conn_send_packet(net_connection_t *conn, net_packet_t *packet); -void net_conn_init_client(net_connection_t *conn, net_addr_t *addr, - net_protocol_t protocol); -void net_conn_init_server(net_connection_t *conn, net_addr_t *addr, - net_protocol_t protocol); -boolean net_conn_packet(net_connection_t *conn, net_packet_t *packet, - unsigned int *packet_type); -void net_conn_disconnect(net_connection_t *conn); -void net_conn_run(net_connection_t *conn); -net_packet_t *net_conn_new_reliable(net_connection_t *conn, int packet_type); - -/* Other miscellaneous common functions */ - -unsigned int net_expand_tic_num(unsigned int relative, unsigned int b); -boolean net_valid_game_settings(game_mode_t mode, gamemission_t mission, - net_gamesettings_t *settings); - -/* Conditional logging */ - -#ifdef CONFIG_GAMES_NXDOOM_NET_LOGS -#define net_log_info(fmt, ...) syslog(LOG_USER | LOG_INFO, fmt, ##__VA_ARGS__) -#define net_log_warn(fmt, ...) \ - syslog(LOG_USER | LOG_WARNING, fmt, ##__VA_ARGS__) -#define net_log_err(fmt, ...) syslog(LOG_USER | LOG_ERR, fmt, ##__VA_ARGS__) - -void net_log_packet(net_packet_t *packet); -#else -#define net_log_info(fmt, ...) -#define net_log_warn(fmt, ...) -#define net_log_err(fmt, ...) - -#define net_log_packet(pkt) -#endif /* CONFIG_GAMES_NXDOOM_NET_LOGS */ - -#endif /* NET_COMMON_H */ diff --git a/games/NXDoom/src/net_dedicated.c b/games/NXDoom/src/net_dedicated.c deleted file mode 100644 index 8c59fb7bb..000000000 --- a/games/NXDoom/src/net_dedicated.c +++ /dev/null @@ -1,101 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/net_dedicated.c - * - * SPDX-License-Identifier: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * Dedicated server code. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -#include "doomtype.h" - -#include "i_system.h" -#include "i_timer.h" - -#include "m_argv.h" - -#include "net_common.h" -#include "net_sdl.h" -#include "net_server.h" - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/* People can become confused about how dedicated servers work. Game - * options are specified to the controlling player who is the first to - * join a game. Bomb out with an error message if game options are - * specified to a dedicated server. - */ - -static const char *not_dedicated_options[] = -{ - "-deh", "-iwad", "-cdrom", "-gameversion", "-nomonsters", - "-respawn", "-fast", "-altdeath", "-deathmatch", "-turbo", - "-merge", "-af", "-as", "-aa", "-file", - "-wart", "-skill", "-episode", "-timer", "-avg", - "-warp", "-loadgame", "-longtics", "-extratics", "-dup", - "-shorttics", NULL, -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static void check_for_client_options(void) -{ - int i; - - for (i = 0; not_dedicated_options[i] != NULL; ++i) - { - if (m_check_parm(not_dedicated_options[i]) > 0) - { - i_error("The command line parameter '%s' was specified to a " - "dedicated server.\nGame parameters should be specified " - "to the first player to join a server, \nnot to the " - "server itself. ", - not_dedicated_options[i]); - } - } -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -void net_dedicated_server(void) -{ - check_for_client_options(); - - net_sv_init(); - net_sv_add_module(&net_sdl_module); - net_sv_register_with_master(); - - while (true) - { - net_sv_run(); - - /* TODO: Block on socket instead of polling. */ - - usleep(1000); - } -} diff --git a/games/NXDoom/src/net_dedicated.h b/games/NXDoom/src/net_dedicated.h deleted file mode 100644 index 2f87bc5d5..000000000 --- a/games/NXDoom/src/net_dedicated.h +++ /dev/null @@ -1,32 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/net_dedicated.h - * - * SPDX-License-Identifier: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Dedicated server code. - * - ****************************************************************************/ - -#ifndef NET_DEDICATED_H -#define NET_DEDICATED_H - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -void net_dedicated_server(void); - -#endif /* NET_DEDICATED_H */ diff --git a/games/NXDoom/src/net_defs.h b/games/NXDoom/src/net_defs.h deleted file mode 100644 index be7358630..000000000 --- a/games/NXDoom/src/net_defs.h +++ /dev/null @@ -1,323 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/net_defs.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Definitions for use in networking code. - * - ****************************************************************************/ - -#ifndef NET_DEFS_H -#define NET_DEFS_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include "d_ticcmd.h" -#include "doomtype.h" -#include "sha1.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* Absolute maximum number of "nodes" in the game. This is different to - * NET_MAXPLAYERS, as there may be observers that are not participating - * (eg. left/right monitors) - */ - -#define MAXNETNODES 16 - -#ifndef CONFIG_GAMES_NXDOOM_NET_MAXPLAYERNAME - -/* We don't need player names. TODO: I should be smarter about this - * and avoid compiling ANY networking related stuff (i.e. player name - * members in the structs below) at all when net stuff is not enabled. - */ - -#define CONFIG_GAMES_NXDOOM_NET_MAXPLAYERNAME (1) -#endif /* CONFIG_GAMES_NXDOOM_NET_MAXPLAYERNAME */ - -/* The maximum number of players, multiplayer/networking. - * This is the maximum supported by the networking code; individual games - * have their own values for MAXPLAYERS that can be smaller. - */ - -#ifndef CONFIG_GAMES_NXDOOM_NET_MAXPLAYERS - -/* No players if not set up for networking */ - -#define CONFIG_GAMES_NXDOOM_NET_MAXPLAYERS (1) -#endif /* CONFIG_GAMES_NXDOOM_NET_MAXPLAYERS */ - -/* Networking and tick handling related. */ - -#ifndef CONFIG_GAMES_NXDOOM_NET_BACKUPTICS - -/* Surely we don't need any for a local game? */ - -#define CONFIG_GAMES_NXDOOM_NET_BACKUPTICS (1) -#endif /* CONFIG_GAMES_NXDOOM_NET_BACKUPTICS */ - -/* Magic number sent when connecting to check this is a valid client */ - -#define NET_MAGIC_NUMBER 1454104972U - -/* Old magic number used by Chocolate Doom versions before v3.0: */ - -#define NET_OLD_MAGIC_NUMBER 3436803284U - -/* header field value indicating that the packet is a reliable packet */ - -#define NET_RELIABLE_PACKET (1 << 15) - -#define NET_TICDIFF_FORWARD (1 << 0) -#define NET_TICDIFF_SIDE (1 << 1) -#define NET_TICDIFF_TURN (1 << 2) -#define NET_TICDIFF_BUTTONS (1 << 3) -#define NET_TICDIFF_CONSISTANCY (1 << 4) -#define NET_TICDIFF_CHATCHAR (1 << 5) -#define NET_TICDIFF_RAVEN (1 << 6) -#define NET_TICDIFF_STRIFE (1 << 7) - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -typedef struct _net_module_s net_module_t; -typedef struct _net_packet_s net_packet_t; -typedef struct _net_addr_s net_addr_t; -typedef struct _net_context_s net_context_t; - -struct _net_packet_s -{ - byte *data; - size_t len; - size_t alloced; - unsigned int pos; -}; - -struct _net_module_s -{ - /* Initialize this module for use as a client */ - - boolean (*init_client)(void); - - /* Initialize this module for use as a server */ - - boolean (*init_server)(void); - - /* Send a packet */ - - void (*send_packet)(net_addr_t *addr, net_packet_t *packet); - - /* Check for new packets to receive - * - * Returns true if packet received - */ - - boolean (*recv_packet)(net_addr_t **addr, net_packet_t **packet); - - /* Converts an address to a string */ - - void (*addr_to_string)(net_addr_t *addr, char *buffer, int buffer_len); - - /* Free back an address when no longer in use */ - - void (*free_address)(net_addr_t *addr); - - /* Try to resolve a name to an address */ - - net_addr_t *(*resolve_address)(const char *addr); -}; - -/* net_addr_t */ - -struct _net_addr_s -{ - net_module_t *module; - int refcount; - void *handle; -}; - -/* Supported protocols. If you're developing a fork of Chocolate - * Doom, you can add your own entry to this list while maintaining - * compatibility with Chocolate Doom servers. Higher-numbered enum values - * will be preferred when negotiating a protocol for the client and server - * to use, so the order matters. - * NOTE: The values in this enum do not have any special value outside of - * the program they're compiled in. What matters is the string - * representation. - */ - -typedef enum -{ - /* Protocol introduced with Chocolate Doom v3.0. Each compatibility- - * breaking change to the network protocol will produce a new protocol - * number in this enum. - */ - - NET_PROTOCOL_CHOCOLATE_DOOM_0, - - /* Add your own protocol here; be sure to add a name for it to the list - * in net_common.c too. - */ - - NET_NUM_PROTOCOLS, - NET_PROTOCOL_UNKNOWN, -} net_protocol_t; - -/* packet types */ - -typedef enum -{ - NET_PACKET_TYPE_SYN, - NET_PACKET_TYPE_ACK, /* deprecated */ - NET_PACKET_TYPE_REJECTED, - NET_PACKET_TYPE_KEEPALIVE, - NET_PACKET_TYPE_WAITING_DATA, - NET_PACKET_TYPE_GAMESTART, - NET_PACKET_TYPE_GAMEDATA, - NET_PACKET_TYPE_GAMEDATA_ACK, - NET_PACKET_TYPE_DISCONNECT, - NET_PACKET_TYPE_DISCONNECT_ACK, - NET_PACKET_TYPE_RELIABLE_ACK, - NET_PACKET_TYPE_GAMEDATA_RESEND, - NET_PACKET_TYPE_CONSOLE_MESSAGE, - NET_PACKET_TYPE_QUERY, - NET_PACKET_TYPE_QUERY_RESPONSE, - NET_PACKET_TYPE_LAUNCH, - NET_PACKET_TYPE_NAT_HOLE_PUNCH, -} net_packet_type_t; - -typedef enum -{ - NET_MASTER_PACKET_TYPE_ADD, - NET_MASTER_PACKET_TYPE_ADD_RESPONSE, - NET_MASTER_PACKET_TYPE_QUERY, - NET_MASTER_PACKET_TYPE_QUERY_RESPONSE, - NET_MASTER_PACKET_TYPE_GET_METADATA, - NET_MASTER_PACKET_TYPE_GET_METADATA_RESPONSE, - NET_MASTER_PACKET_TYPE_SIGN_START, - NET_MASTER_PACKET_TYPE_SIGN_START_RESPONSE, - NET_MASTER_PACKET_TYPE_SIGN_END, - NET_MASTER_PACKET_TYPE_SIGN_END_RESPONSE, - NET_MASTER_PACKET_TYPE_NAT_HOLE_PUNCH, - NET_MASTER_PACKET_TYPE_NAT_HOLE_PUNCH_ALL, -} net_master_packet_type_t; - -/* Settings specified when the client connects to the server. */ - -typedef struct -{ - int gamemode; - int gamemission; - int lowres_turn; - int drone; - int max_players; - int is_freedoom; - sha1_digest_t wad_sha1sum; - sha1_digest_t deh_sha1sum; - int player_class; -} net_connect_data_t; - -/* Game settings sent by client to server when initiating game start, - * and received from the server by clients when the game starts. - */ - -typedef struct -{ - int ticdup; - int extratics; - int deathmatch; - int episode; - int nomonsters; - int fast_monsters; - int respawn_monsters; - int map; - int skill; - int gameversion; - int lowres_turn; - int new_sync; - int timelimit; - int loadgame; - int random; /* [Strife only] */ - - /* These fields are only used by the server when sending a game - * start message: - */ - - int num_players; - int consoleplayer; - - /* Hexen player classes: */ - - int player_classes[CONFIG_GAMES_NXDOOM_NET_MAXPLAYERS]; -} net_gamesettings_t; - -typedef struct -{ - unsigned int diff; - ticcmd_t cmd; -} net_ticdiff_t; - -/* Complete set of ticcmds from all players */ - -typedef struct -{ - signed int latency; - unsigned int seq; - boolean playeringame[CONFIG_GAMES_NXDOOM_NET_MAXPLAYERS]; - net_ticdiff_t cmds[CONFIG_GAMES_NXDOOM_NET_MAXPLAYERS]; -} net_full_ticcmd_t; - -/* Data sent in response to server queries */ - -typedef struct -{ - const char *version; - int server_state; - int num_players; - int max_players; - int gamemode; - int gamemission; - const char *description; - net_protocol_t protocol; -} net_querydata_t; - -/* Data sent by the server while waiting for the game to start. */ - -typedef struct -{ - int num_players; - int num_drones; - int ready_players; - int max_players; - int is_controller; - int consoleplayer; - char player_names[CONFIG_GAMES_NXDOOM_NET_MAXPLAYERS] - [CONFIG_GAMES_NXDOOM_NET_MAXPLAYERNAME]; - char player_addrs[CONFIG_GAMES_NXDOOM_NET_MAXPLAYERS] - [CONFIG_GAMES_NXDOOM_NET_MAXPLAYERNAME]; - sha1_digest_t wad_sha1sum; - sha1_digest_t deh_sha1sum; - int is_freedoom; -} net_waitdata_t; - -#endif /* NET_DEFS_H */ diff --git a/games/NXDoom/src/net_gui.c b/games/NXDoom/src/net_gui.c deleted file mode 100644 index f731693ca..000000000 --- a/games/NXDoom/src/net_gui.c +++ /dev/null @@ -1,469 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/net_gui.c - * - * SPDX-License-Identifier: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * Graphical stuff related to the networking code: - * - * * The client waiting screen when we are waiting for the server to - * start the game. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include -#include - -#include "config.h" -#include "doomkeys.h" - -#include "i_system.h" -#include "i_timer.h" -#include "i_video.h" -#include "m_argv.h" -#include "m_misc.h" - -#include "net_client.h" -#include "net_gui.h" -#include "net_query.h" -#include "net_server.h" - -#include "textscreen.h" - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static txt_window_t *window; -static int old_max_players; -static txt_label_t *player_labels[CONFIG_GAMES_NXDOOM_NET_MAXPLAYERS]; -static txt_label_t *ip_labels[CONFIG_GAMES_NXDOOM_NET_MAXPLAYERS]; -static txt_label_t *drone_label; -static txt_label_t *master_msg_label; -static boolean had_warning; - -/* Number of players we expect to be in the game. When the number is - * reached, we auto-start the game (if we're the controller). If - * zero, do not autostart. - */ - -static int expected_nodes; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static void escape_pressed(TXT_UNCAST_ARG(widget), void *unused) -{ - txt_shutdown(); - i_quit(); -} - -static void start_game(TXT_UNCAST_ARG(widget), TXT_UNCAST_ARG(unused)) -{ - net_cl_launch_game(); -} - -static void open_wait_dialog(void) -{ - txt_window_action_t *cancel; - - txt_set_desktop_title(PACKAGE_STRING); - - window = txt_new_window("Waiting for game start..."); - - txt_add_widget(window, txt_new_label("\nPlease wait...\n\n")); - - cancel = txt_new_window_action(KEY_ESCAPE, "Cancel"); - txt_signal_connect(cancel, "pressed", escape_pressed, NULL); - - txt_set_window_action(window, TXT_HORIZ_LEFT, cancel); - txt_set_window_position(window, TXT_HORIZ_CENTER, TXT_VERT_BOTTOM, - TXT_SCREEN_W / 2, TXT_SCREEN_H - 9); - - old_max_players = 0; -} - -static void build_window(void) -{ - char buf[50]; - txt_table_t *table; - int i; - - txt_clear_table(window); - table = txt_new_table(3); - txt_add_widget(window, table); - - /* Add spacers */ - - txt_add_widget(table, NULL); - txt_add_widget(table, txt_new_strut(25, 1)); - txt_add_widget(table, txt_new_strut(17, 1)); - - /* Player labels */ - - for (i = 0; i < net_client_wait_data.max_players; ++i) - { - snprintf(buf, sizeof(buf), " %i. ", i + 1); - txt_add_widget(table, txt_new_label(buf)); - player_labels[i] = txt_new_label(""); - ip_labels[i] = txt_new_label(""); - txt_add_widget(table, player_labels[i]); - txt_add_widget(table, ip_labels[i]); - } - - drone_label = txt_new_label(""); - - txt_add_widget(window, drone_label); -} - -static void update_gui(void) -{ - txt_window_action_t *startgame; - char buf[50]; - unsigned int i; - - /* If the value of max_players changes, we must rebuild the - * contents of the window. This includes when the first - * waiting data packet is received. - */ - - if (net_client_received_wait_data) - { - if (net_client_wait_data.max_players != old_max_players) - { - build_window(); - } - } - else - { - return; - } - - for (i = 0; i < net_client_wait_data.max_players; ++i) - { - txt_color_t color = TXT_COLOR_BRIGHT_WHITE; - - if ((signed)i == net_client_wait_data.consoleplayer) - { - color = TXT_COLOR_YELLOW; - } - - txt_set_fg_colour(player_labels[i], color); - txt_set_fg_colour(ip_labels[i], color); - - if (i < net_client_wait_data.num_players) - { - txt_set_label(player_labels[i], - net_client_wait_data.player_names[i]); - txt_set_label(ip_labels[i], net_client_wait_data.player_addrs[i]); - } - else - { - txt_set_label(player_labels[i], ""); - txt_set_label(ip_labels[i], ""); - } - } - - if (net_client_wait_data.num_drones > 0) - { - snprintf(buf, sizeof(buf), " (+%i observer clients)", - net_client_wait_data.num_drones); - txt_set_label(drone_label, buf); - } - else - { - txt_set_label(drone_label, ""); - } - - if (net_client_wait_data.is_controller) - { - startgame = txt_new_window_action(' ', "Start game"); - txt_signal_connect(startgame, "pressed", start_game, NULL); - } - else - { - startgame = NULL; - } - - txt_set_window_action(window, TXT_HORIZ_RIGHT, startgame); -} - -static void build_master_status_window(void) -{ - txt_window_t *master_window; - - master_window = txt_new_window(NULL); - master_msg_label = txt_new_label(""); - txt_add_widget(master_window, master_msg_label); - - /* This window is here purely for information, so it should be - * in the background. - */ - - txt_lower_window(master_window); - txt_set_window_position(master_window, TXT_HORIZ_CENTER, TXT_VERT_CENTER, - TXT_SCREEN_W / 2, TXT_SCREEN_H - 4); - txt_set_window_action(master_window, TXT_HORIZ_LEFT, NULL); - txt_set_window_action(master_window, TXT_HORIZ_CENTER, NULL); - txt_set_window_action(master_window, TXT_HORIZ_RIGHT, NULL); -} - -static void check_master_status(void) -{ - boolean added; - - if (!net_query_check_added_to_master(&added)) - { - return; - } - - if (master_msg_label == NULL) - { - build_master_status_window(); - } - - if (added) - { - txt_set_label( - master_msg_label, - "Your server is now registered with the global master server.\n" - "Other players can find your server online."); - } - else - { - txt_set_label( - master_msg_label, - "Failed to register with the master server. Your server is not\n" - "publicly accessible. You may need to reconfigure your Internet\n" - "router to add a port forward for UDP port 2342. Look up\n" - "information on port forwarding online."); - } -} - -static void print_sha1_digest(const char *s, const byte *digest) -{ - unsigned int i; - - printf("%s: ", s); - - for (i = 0; i < sizeof(sha1_digest_t); ++i) - { - printf("%02x", digest[i]); - } - - printf("\n"); -} - -static void close_window(TXT_UNCAST_ARG(widget), TXT_UNCAST_ARG(p_window)) -{ - TXT_CAST_ARG(txt_window_t, p_window); - - txt_close_window(p_window); -} - -static void check_sha1_sums(void) -{ - boolean correct_wad; - boolean correct_deh; - boolean same_freedoom; - txt_window_t *l_window; - txt_window_action_t *cont_button; - - if (!net_client_received_wait_data || had_warning) - { - return; - } - - correct_wad = - memcmp(net_local_wad_sha1sum, net_client_wait_data.wad_sha1sum, - sizeof(sha1_digest_t)) == 0; - correct_deh = - memcmp(net_local_deh_sha1sum, net_client_wait_data.deh_sha1sum, - sizeof(sha1_digest_t)) == 0; - same_freedoom = net_client_wait_data.is_freedoom == net_local_is_freedoom; - - if (correct_wad && correct_deh && same_freedoom) - { - return; - } - - if (!correct_wad) - { - printf("Warning: WAD SHA1 does not match server:\n"); - print_sha1_digest("Local", net_local_wad_sha1sum); - print_sha1_digest("Server", net_client_wait_data.wad_sha1sum); - } - - if (!same_freedoom) - { - printf("Warning: Mixing Freedoom with non-Freedoom\n"); - printf("Local: %u Server: %i\n", net_local_is_freedoom, - net_client_wait_data.is_freedoom); - } - - if (!correct_deh) - { - printf("Warning: Dehacked SHA1 does not match server:\n"); - print_sha1_digest("Local", net_local_deh_sha1sum); - print_sha1_digest("Server", net_client_wait_data.deh_sha1sum); - } - - l_window = txt_new_window("WARNING!"); - - cont_button = txt_new_window_action(KEY_ENTER, "Continue"); - txt_signal_connect(cont_button, "pressed", close_window, l_window); - - txt_set_window_action(l_window, TXT_HORIZ_LEFT, NULL); - txt_set_window_action(l_window, TXT_HORIZ_CENTER, cont_button); - txt_set_window_action(l_window, TXT_HORIZ_RIGHT, NULL); - - if (!same_freedoom) - { - /* If Freedoom and Doom IWADs are mixed, the WAD directory - * will be wrong, but this is not necessarily a problem. - * Display a different message to the WAD directory message. - */ - - if (net_local_is_freedoom) - { - txt_add_widget( - l_window, - txt_new_label( - "You are using the Freedoom IWAD to play with players\n" - "using an official Doom IWAD. Make sure that you are\n" - "playing the same levels as other players.\n")); - } - else - { - txt_add_widget( - l_window, - txt_new_label( - "You are using an official IWAD to play with players\n" - "using the Freedoom IWAD. Make sure that you are\n" - "playing the same levels as other players.\n")); - } - } - else if (!correct_wad) - { - txt_add_widget( - l_window, - txt_new_label( - "Your WAD directory does not match other players in the game.\n" - "Check that you have loaded the exact same WAD files as other\n" - "players.\n") - ); - } - - if (!correct_deh) - { - txt_add_widget( - l_window, - txt_new_label( - "Your dehacked signature does not match other players in the\n" - "game. Check that you have loaded the same dehacked patches\n" - "as other players.\n")); - } - - txt_add_widget( - l_window, - txt_new_label("If you continue, this may cause your game to desync.")); - - had_warning = true; -} - -static void parse_command_line_args(void) -{ - int i; - - /* @arg - * @category net - * - * Autostart the netgame when n nodes (clients) have joined the server. - */ - - i = m_check_parm_with_args("-nodes", 1); - if (i > 0) - { - expected_nodes = atoi(myargv[i + 1]); - } -} - -static void check_auto_latch(void) -{ - int nodes; - - if (net_client_received_wait_data && net_client_wait_data.is_controller && - expected_nodes > 0) - { - nodes = - net_client_wait_data.num_players + net_client_wait_data.num_drones; - - if (nodes >= expected_nodes) - { - start_game(NULL, NULL); - expected_nodes = 0; - } - } -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -void net_wait_for_launch(void) -{ - if (!txt_init()) - { - fprintf(stderr, "Failed to initialize GUI\n"); - exit(-1); - } - - /* Romero's "funky blue" color */ - - txt_set_colour(TXT_COLOR_BLUE, 0x04, 0x14, 0x40); - - parse_command_line_args(); - open_wait_dialog(); - had_warning = false; - - while (net_waiting_for_launch) - { - update_gui(); - check_auto_latch(); - check_sha1_sums(); - check_master_status(); - - txt_dispatch_events(); - txt_draw_desktop(); - - net_cl_run(); - net_sv_run(); - - if (!net_client_connected) - { - i_error("Lost connection to server"); - } - - txt_sleep(100); - } - - txt_shutdown(); -} diff --git a/games/NXDoom/src/net_gui.h b/games/NXDoom/src/net_gui.h deleted file mode 100644 index 377b6646c..000000000 --- a/games/NXDoom/src/net_gui.h +++ /dev/null @@ -1,40 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/net_gui.h - * - * SPDX-License-Identifier: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * Graphical stuff related to the networking code: - * - * * The client waiting screen when we are waiting for the server to - * start the game. - * - ****************************************************************************/ - -#ifndef NET_GUI_H -#define NET_GUI_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "doomtype.h" - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -extern void net_wait_for_launch(void); - -#endif /* NET_GUI_H */ diff --git a/games/NXDoom/src/net_io.c b/games/NXDoom/src/net_io.c deleted file mode 100644 index 0c9c4a4fb..000000000 --- a/games/NXDoom/src/net_io.c +++ /dev/null @@ -1,170 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/net_io.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Network packet I/O. Base layer for sending/receiving packets, - * through the network module system - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include "i_system.h" -#include "net_defs.h" -#include "net_io.h" -#include "z_zone.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define MAX_MODULES 16 - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -struct _net_context_s -{ - net_module_t *modules[MAX_MODULES]; - int num_modules; -}; - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -net_addr_t net_broadcast_addr; - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -net_context_t *net_new_context(void) -{ - net_context_t *context; - - context = z_malloc(sizeof(net_context_t), PU_STATIC, 0); - context->num_modules = 0; - - return context; -} - -void net_add_module(net_context_t *context, net_module_t *module) -{ - if (context->num_modules >= MAX_MODULES) - { - i_error("net_add_module: No more modules for context"); - } - - context->modules[context->num_modules] = module; - ++context->num_modules; -} - -net_addr_t *net_resolve_address(net_context_t *context, const char *addr) -{ - int i; - net_addr_t *result; - - for (i = 0; i < context->num_modules; ++i) - { - result = context->modules[i]->resolve_address(addr); - - if (result != NULL) - { - net_reference_address(result); - return result; - } - } - - return NULL; -} - -void net_send_packet(net_addr_t *addr, net_packet_t *packet) -{ - addr->module->send_packet(addr, packet); -} - -void net_send_broadcast(net_context_t *context, net_packet_t *packet) -{ - int i; - - for (i = 0; i < context->num_modules; ++i) - { - context->modules[i]->send_packet(&net_broadcast_addr, packet); - } -} - -boolean net_recv_packet(net_context_t *context, net_addr_t **addr, - net_packet_t **packet) -{ - int i; - - /* check all modules for new packets */ - - for (i = 0; i < context->num_modules; ++i) - { - if (context->modules[i]->recv_packet(addr, packet)) - { - net_reference_address(*addr); - return true; - } - } - - return false; -} - -/* Note: this prints into a static buffer, calling again overwrites - * the first result - */ - -char *net_addr_to_string(net_addr_t *addr) -{ - static char buf[128]; - - addr->module->addr_to_string(addr, buf, sizeof(buf) - 1); - - return buf; -} - -void net_reference_address(net_addr_t *addr) -{ - if (addr == NULL) - { - return; - } - - ++addr->refcount; -} - -void net_release_address(net_addr_t *addr) -{ - if (addr == NULL) - { - return; - } - - --addr->refcount; - if (addr->refcount <= 0) - { - addr->module->free_address(addr); - } -} diff --git a/games/NXDoom/src/net_io.h b/games/NXDoom/src/net_io.h deleted file mode 100644 index d83d3ace3..000000000 --- a/games/NXDoom/src/net_io.h +++ /dev/null @@ -1,90 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/net_io.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Network packet manipulation (net_packet_t) - * - ****************************************************************************/ - -#ifndef NET_IO_H -#define NET_IO_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "net_defs.h" - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -extern net_addr_t net_broadcast_addr; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/* Create a new network context. */ - -net_context_t *net_new_context(void); - -/* Add a network module to a context. */ - -void net_add_module(net_context_t *context, net_module_t *module); - -/* Send a packet to the given address. */ - -void net_send_packet(net_addr_t *addr, net_packet_t *packet); - -/* Send a broadcast using all modules in the given context. */ - -void net_send_broadcast(net_context_t *context, net_packet_t *packet); - -/* Check all modules in the given context and receive a packet, returning - * true if a packet was received. The result is stored in *packet and the - * source is stored in *addr, with an implicit reference added. The packet - * must be freed by the caller and the reference released. - */ - -boolean net_recv_packet(net_context_t *context, net_addr_t **addr, - net_packet_t **packet); - -/* Return a string representation of the given address. The result points - * to a static buffer and will become invalid with the next call. - */ - -char *net_addr_to_string(net_addr_t *addr); - -/* Add a reference to the given address. */ - -void net_reference_address(net_addr_t *addr); - -/* Release a reference to the given address. When there are no more - * references, the address will be freed. - */ - -void net_release_address(net_addr_t *addr); - -/* Resolve a string representation of an address. If successful, a net_addr_t - * pointer is received with an implicit reference that must be freed by the - * caller when it is no longer needed. - */ - -net_addr_t *net_resolve_address(net_context_t *context, const char *address); - -#endif /* NET_IO_H */ diff --git a/games/NXDoom/src/net_loop.c b/games/NXDoom/src/net_loop.c deleted file mode 100644 index d31d29cfc..000000000 --- a/games/NXDoom/src/net_loop.c +++ /dev/null @@ -1,272 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/net_loop.c - * - * SPDX-License-Identifier: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Loopback network module for server compiled into the client - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -#include "doomtype.h" -#include "i_system.h" -#include "m_misc.h" -#include "net_defs.h" -#include "net_loop.h" -#include "net_packet.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define MAX_QUEUE_SIZE 16 - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -typedef struct -{ - net_packet_t *packets[MAX_QUEUE_SIZE]; - int head; - int tail; -} packet_queue_t; - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static packet_queue_t client_queue; -static packet_queue_t server_queue; -static net_addr_t client_addr; -static net_addr_t server_addr; - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -static boolean net_cl_init_client(void); -static boolean net_cl_init_server(void); -static void net_cl_send_packet(net_addr_t *addr, net_packet_t *packet); -static boolean net_cl_recv_packet(net_addr_t **addr, net_packet_t **packet); -static void net_cl_addr_to_string(net_addr_t *addr, char *buffer, - int buffer_len); -static void net_cl_free_address(net_addr_t *addr); -static net_addr_t *net_cl_resolve_address(const char *address); - -static boolean net_sv_init_client(void); -static boolean net_sv_init_server(void); -static void net_sv_send_packet(net_addr_t *addr, net_packet_t *packet); -static boolean net_sv_recv_packet(net_addr_t **addr, net_packet_t **packet); -static void net_sv_addr_to_string(net_addr_t *addr, char *buffer, - int buffer_len); -static void net_sv_free_address(net_addr_t *addr); -static net_addr_t *net_sv_resolve_address(const char *address); - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -net_module_t net_loop_client_module = -{ - net_cl_init_client, net_cl_init_server, net_cl_send_packet, - net_cl_recv_packet, net_cl_addr_to_string, net_cl_free_address, - net_cl_resolve_address, -}; - -net_module_t net_loop_server_module = -{ - net_sv_init_client, net_sv_init_server, net_sv_send_packet, - net_sv_recv_packet, net_sv_addr_to_string, net_sv_free_address, - net_sv_resolve_address, -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static void queue_init(packet_queue_t *queue) -{ - queue->head = queue->tail = 0; -} - -static void queue_push(packet_queue_t *queue, net_packet_t *packet) -{ - int new_tail; - - new_tail = (queue->tail + 1) % MAX_QUEUE_SIZE; - - if (new_tail == queue->head) - { - /* queue is full */ - - return; - } - - queue->packets[queue->tail] = packet; - queue->tail = new_tail; -} - -static net_packet_t *queue_pop(packet_queue_t *queue) -{ - net_packet_t *packet; - - if (queue->tail == queue->head) - { - /* queue empty */ - - return NULL; - } - - packet = queue->packets[queue->head]; - queue->head = (queue->head + 1) % MAX_QUEUE_SIZE; - - return packet; -} - -/**************************************************************************** - * Client-end code - ****************************************************************************/ - -static boolean net_cl_init_client(void) -{ - queue_init(&client_queue); - - return true; -} - -static boolean net_cl_init_server(void) -{ - i_error("NET_CL_init_server: attempted to initialize client pipe end as a " - "server!"); - return false; -} - -static void net_cl_send_packet(net_addr_t *addr, net_packet_t *packet) -{ - queue_push(&server_queue, net_packet_dup(packet)); -} - -static boolean net_cl_recv_packet(net_addr_t **addr, net_packet_t **packet) -{ - net_packet_t *popped; - - popped = queue_pop(&client_queue); - - if (popped != NULL) - { - *packet = popped; - *addr = &client_addr; - client_addr.module = &net_loop_client_module; - - return true; - } - - return false; -} - -static void net_cl_addr_to_string(net_addr_t *addr, char *buffer, - int buffer_len) -{ - snprintf(buffer, buffer_len, "local server"); -} - -static void net_cl_free_address(net_addr_t *addr) -{ -} - -static net_addr_t *net_cl_resolve_address(const char *address) -{ - if (address == NULL) - { - client_addr.module = &net_loop_client_module; - - return &client_addr; - } - else - { - return NULL; - } -} - -/**************************************************************************** - * Server-end code - ****************************************************************************/ - -static boolean net_sv_init_client(void) -{ - i_error("net_sv_initClient: attempted to initialize server pipe end as a " - "client!"); - return false; -} - -static boolean net_sv_init_server(void) -{ - queue_init(&server_queue); - return true; -} - -static void net_sv_send_packet(net_addr_t *addr, net_packet_t *packet) -{ - queue_push(&client_queue, net_packet_dup(packet)); -} - -static boolean net_sv_recv_packet(net_addr_t **addr, net_packet_t **packet) -{ - net_packet_t *popped; - - popped = queue_pop(&server_queue); - - if (popped != NULL) - { - *packet = popped; - *addr = &server_addr; - server_addr.module = &net_loop_server_module; - - return true; - } - - return false; -} - -static void net_sv_addr_to_string(net_addr_t *addr, char *buffer, - int buffer_len) -{ - snprintf(buffer, buffer_len, "local client"); -} - -static void net_sv_free_address(net_addr_t *addr) -{ -} - -static net_addr_t *net_sv_resolve_address(const char *address) -{ - if (address == NULL) - { - server_addr.module = &net_loop_server_module; - return &server_addr; - } - else - { - return NULL; - } -} diff --git a/games/NXDoom/src/net_loop.h b/games/NXDoom/src/net_loop.h deleted file mode 100644 index 222660ffc..000000000 --- a/games/NXDoom/src/net_loop.h +++ /dev/null @@ -1,39 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/net_loop.h - * - * SPDX-License-Identifier: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Loopback network module for server compiled into the client - * - ****************************************************************************/ - -#ifndef NET_LOOP_H -#define NET_LOOP_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "net_defs.h" - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -extern net_module_t net_loop_client_module; -extern net_module_t net_loop_server_module; - -#endif /* NET_LOOP_H */ diff --git a/games/NXDoom/src/net_packet.c b/games/NXDoom/src/net_packet.c deleted file mode 100644 index d7a57e1e2..000000000 --- a/games/NXDoom/src/net_packet.c +++ /dev/null @@ -1,357 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/net_packet.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Network packet manipulation (net_packet_t) - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "net_packet.h" -#include "m_misc.h" -#include "z_zone.h" -#include -#include - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static int g_total_packet_memory = 0; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/* Dynamically increases the size of a packet */ - -static void net_increase_packet(net_packet_t *packet) -{ - byte *newdata; - - g_total_packet_memory -= packet->alloced; - - packet->alloced *= 2; - - newdata = z_malloc(packet->alloced, PU_STATIC, 0); - - memcpy(newdata, packet->data, packet->len); - - z_free(packet->data); - packet->data = newdata; - - g_total_packet_memory += packet->alloced; -} - -#if 0 /* Unused */ -static boolean net_read_sint32(net_packet_t *packet, signed int *data) -{ - if (net_read_int32(packet, (unsigned int *)data)) - { - if (*data & (1U << 31)) - { - *data &= ~(1U << 31); - *data -= (1U << 31); - } - - return true; - } - else - { - return false; - } -} -#endif - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -net_packet_t *net_new_packet(int initial_size) -{ - net_packet_t *packet; - - packet = (net_packet_t *)z_malloc(sizeof(net_packet_t), PU_STATIC, 0); - - if (initial_size == 0) initial_size = 256; - - packet->alloced = initial_size; - packet->data = z_malloc(initial_size, PU_STATIC, 0); - packet->len = 0; - packet->pos = 0; - - g_total_packet_memory += sizeof(net_packet_t) + initial_size; - - /* printf("total packet memory: %i bytes\n", total_packet_memory); - * printf("%p: allocated\n", packet); - */ - - return packet; -} - -/* duplicates an existing packet */ - -net_packet_t *net_packet_dup(net_packet_t *packet) -{ - net_packet_t *newpacket; - - newpacket = net_new_packet(packet->len); - memcpy(newpacket->data, packet->data, packet->len); - newpacket->len = packet->len; - - return newpacket; -} - -void net_free_packet(net_packet_t *packet) -{ - /* printf("%p: destroyed\n", packet); */ - - g_total_packet_memory -= sizeof(net_packet_t) + packet->alloced; - z_free(packet->data); - z_free(packet); -} - -/* Read a byte from the packet, returning true if read - * successfully - */ - -boolean net_read_int8(net_packet_t *packet, unsigned int *data) -{ - if (packet->pos + 1 > packet->len) return false; - - *data = packet->data[packet->pos]; - - packet->pos += 1; - - return true; -} - -/* Read a 16-bit integer from the packet, returning true if read - * successfully - */ - -boolean net_read_int16(net_packet_t *packet, unsigned int *data) -{ - byte *p; - - if (packet->pos + 2 > packet->len) return false; - - p = packet->data + packet->pos; - - *data = (p[0] << 8) | p[1]; - packet->pos += 2; - - return true; -} - -/* Read a 32-bit integer from the packet, returning true if read - * successfully - */ - -boolean net_read_int32(net_packet_t *packet, unsigned int *data) -{ - byte *p; - - if (packet->pos + 4 > packet->len) return false; - - p = packet->data + packet->pos; - - *data = (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]; - packet->pos += 4; - - return true; -} - -/* Signed read functions */ - -boolean net_read_sint8(net_packet_t *packet, signed int *data) -{ - if (net_read_int8(packet, (unsigned int *)data)) - { - if (*data & (1 << 7)) - { - *data &= ~(1 << 7); - *data -= (1 << 7); - } - - return true; - } - else - { - return false; - } -} - -boolean net_read_sint16(net_packet_t *packet, signed int *data) -{ - if (net_read_int16(packet, (unsigned int *)data)) - { - if (*data & (1 << 15)) - { - *data &= ~(1 << 15); - *data -= (1 << 15); - } - - return true; - } - else - { - return false; - } -} - -/* Read a string from the packet. Returns NULL if a terminating - * NUL character was not found before the end of the packet. - */ - -char *net_read_string(net_packet_t *packet) -{ - char *start; - - start = (char *)packet->data + packet->pos; - - /* Search forward for a NUL character */ - - while (packet->pos < packet->len && packet->data[packet->pos] != '\0') - { - ++packet->pos; - } - - if (packet->pos >= packet->len) - { - /* Reached the end of the packet */ - - return NULL; - } - - /* packet->data[packet->pos] == '\0': We have reached a terminating - * NULL. Skip past this NULL and continue reading immediately - * after it. - */ - - ++packet->pos; - - return start; -} - -/* Read a string from the packet, but (potentially) modify it to strip - * out any unprintable characters which could be malicious control codes. - * Note that this may modify the original packet contents. - */ - -char *net_read_safe_string(net_packet_t *packet) -{ - char *r; - char *w; - char *result; - - result = net_read_string(packet); - if (result == NULL) - { - return NULL; - } - - /* w is always <= r, so we never produce a longer string than the original. - */ - - w = result; - for (r = result; *r != '\0'; ++r) - { - /* TODO: This is a very naive way of producing a safe string; only - * ASCII characters are allowed. Probably this should really support - * UTF-8 characters as well. - */ - - if (isprint(*r) || *r == '\n') - { - *w = *r; - ++w; - } - } - - *w = '\0'; - - return result; -} - -/* Write a single byte to the packet */ - -void net_write_int8(net_packet_t *packet, unsigned int i) -{ - if (packet->len + 1 > packet->alloced) net_increase_packet(packet); - - packet->data[packet->len] = i; - packet->len += 1; -} - -/* Write a 16-bit integer to the packet */ - -void net_write_int16(net_packet_t *packet, unsigned int i) -{ - byte *p; - - if (packet->len + 2 > packet->alloced) net_increase_packet(packet); - - p = packet->data + packet->len; - - p[0] = (i >> 8) & 0xff; - p[1] = i & 0xff; - - packet->len += 2; -} - -/* Write a single byte to the packet */ - -void net_write_int32(net_packet_t *packet, unsigned int i) -{ - byte *p; - - if (packet->len + 4 > packet->alloced) net_increase_packet(packet); - - p = packet->data + packet->len; - - p[0] = (i >> 24) & 0xff; - p[1] = (i >> 16) & 0xff; - p[2] = (i >> 8) & 0xff; - p[3] = i & 0xff; - - packet->len += 4; -} - -void net_write_string(net_packet_t *packet, const char *string) -{ - byte *p; - size_t string_size; - - string_size = strlen(string) + 1; - - /* Increase the packet size until large enough to hold the string */ - - while (packet->len + string_size > packet->alloced) - { - net_increase_packet(packet); - } - - p = packet->data + packet->len; - - m_str_copy((char *)p, string, string_size); - - packet->len += string_size; -} diff --git a/games/NXDoom/src/net_packet.h b/games/NXDoom/src/net_packet.h deleted file mode 100644 index f2d412b95..000000000 --- a/games/NXDoom/src/net_packet.h +++ /dev/null @@ -1,56 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/net_packet.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Definitions for use in networking code. - * - ****************************************************************************/ - -#ifndef NET_PACKET_H -#define NET_PACKET_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "net_defs.h" - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -net_packet_t *net_new_packet(int initial_size); -net_packet_t *net_packet_dup(net_packet_t *packet); -void net_free_packet(net_packet_t *packet); - -boolean net_read_int8(net_packet_t *packet, unsigned int *data); -boolean net_read_int16(net_packet_t *packet, unsigned int *data); -boolean net_read_int32(net_packet_t *packet, unsigned int *data); - -boolean net_read_sint8(net_packet_t *packet, signed int *data); -boolean net_read_sint16(net_packet_t *packet, signed int *data); - -char *net_read_string(net_packet_t *packet); -char *net_read_safe_string(net_packet_t *packet); - -void net_write_int8(net_packet_t *packet, unsigned int i); -void net_write_int16(net_packet_t *packet, unsigned int i); -void net_write_int32(net_packet_t *packet, unsigned int i); - -void net_write_string(net_packet_t *packet, const char *string); - -#endif /* NET_PACKET_H */ diff --git a/games/NXDoom/src/net_query.c b/games/NXDoom/src/net_query.c deleted file mode 100644 index ea80d8ccd..000000000 --- a/games/NXDoom/src/net_query.c +++ /dev/null @@ -1,1063 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/net_query.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Querying servers to find their current status. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include -#include - -#include "i_system.h" -#include "i_timer.h" -#include "m_misc.h" - -#include "net_common.h" -#include "net_defs.h" -#include "net_io.h" -#include "net_packet.h" -#include "net_query.h" -#include "net_sdl.h" -#include "net_structrw.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* DNS address of the Internet master server. */ - -#define MASTER_SERVER_ADDRESS "master.chocolate-doom.org:2342" - -/* Time to wait for a response before declaring a timeout. */ - -#define QUERY_TIMEOUT_SECS 2 - -/* Time to wait for secure demo signatures before declaring a timeout. */ - -#define SIGNATURE_TIMEOUT_SECS 5 - -/* Number of query attempts to make before giving up on a server. */ - -#define QUERY_MAX_ATTEMPTS 3 - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -typedef enum -{ - QUERY_TARGET_SERVER, /* Normal server target. */ - QUERY_TARGET_MASTER, /* The master server. */ - QUERY_TARGET_BROADCAST /* Send a broadcast query */ -} query_target_type_t; - -typedef enum -{ - QUERY_TARGET_QUEUED, /* Query not yet sent */ - QUERY_TARGET_QUERIED, /* Query sent, waiting response */ - QUERY_TARGET_RESPONDED, /* Response received */ - QUERY_TARGET_NO_RESPONSE -} query_target_state_t; - -typedef struct -{ - query_target_type_t type; - query_target_state_t state; - net_addr_t *addr; - net_querydata_t data; - unsigned int ping_time; - unsigned int query_time; - unsigned int query_attempts; - boolean printed; -} query_target_t; - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static boolean g_registered_with_master = false; -static boolean g_got_master_response = false; - -static net_context_t *g_query_context; -static query_target_t *g_targets; -static int g_num_targets; - -static boolean g_query_loop_running = false; -static boolean g_printed_header = false; -static int g_last_query_time = 0; - -#if 0 -static char *g_securedemo_start_message = NULL; -#endif - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -static void formatted_printf(int wide, const char *s, ...) PRINTF_ATTR(2, 3); - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/* Send a query to the master server. */ - -static void net_query_send_master_query(net_addr_t *addr) -{ - net_packet_t *packet; - - packet = net_new_packet(4); - net_write_int16(packet, NET_MASTER_PACKET_TYPE_QUERY); - net_send_packet(addr, packet); - net_free_packet(packet); - - /* We also send a NAT_HOLE_PUNCH_ALL packet so that servers behind - * NAT gateways will open themselves up to us. - */ - - packet = net_new_packet(4); - net_write_int16(packet, NET_MASTER_PACKET_TYPE_NAT_HOLE_PUNCH_ALL); - net_send_packet(addr, packet); - net_free_packet(packet); -} - -/* Given the specified address, find the target associated. If no - * target is found, and 'create' is true, a new target is created. - */ - -static query_target_t *get_target_for_addr(net_addr_t *addr, boolean create) -{ - query_target_t *target; - int i; - - for (i = 0; i < g_num_targets; ++i) - { - if (g_targets[i].addr == addr) - { - return &g_targets[i]; - } - } - - if (!create) - { - return NULL; - } - - g_targets = - i_realloc(g_targets, sizeof(query_target_t) * (g_num_targets + 1)); - - target = &g_targets[g_num_targets]; - target->type = QUERY_TARGET_SERVER; - target->state = QUERY_TARGET_QUEUED; - target->printed = false; - target->query_attempts = 0; - target->addr = addr; - net_reference_address(addr); - ++g_num_targets; - - return target; -} - -static void free_targets(void) -{ - int i; - - for (i = 0; i < g_num_targets; ++i) - { - net_release_address(g_targets[i].addr); - } - - free(g_targets); - g_targets = NULL; - g_num_targets = 0; -} - -/* Transmit a query packet */ - -static void net_query_send_query(net_addr_t *addr) -{ - net_packet_t *request; - - request = net_new_packet(10); - net_write_int16(request, NET_PACKET_TYPE_QUERY); - - if (addr == NULL) - { - net_send_broadcast(g_query_context, request); - } - else - { - net_send_packet(addr, request); - } - - net_free_packet(request); -} - -static void net_query_parse_response(net_addr_t *addr, net_packet_t *packet, - net_query_callback_t callback, - void *user_data) -{ - unsigned int packet_type; - net_querydata_t querydata; - query_target_t *target; - - /* Read the header */ - - if (!net_read_int16(packet, &packet_type) || - packet_type != NET_PACKET_TYPE_QUERY_RESPONSE) - { - return; - } - - /* Read query data */ - - if (!net_read_query_data(packet, &querydata)) - { - return; - } - - /* Find the target that responded. */ - - target = get_target_for_addr(addr, false); - - /* If the target is not found, it may be because we are doing - * a LAN broadcast search, in which case we need to create a - * target for the new responder. - */ - - if (target == NULL) - { - query_target_t *broadcast_target; - - broadcast_target = get_target_for_addr(NULL, false); - - /* Not in broadcast mode, unexpected response that came out - * of nowhere. Ignore. - */ - - if (broadcast_target == NULL || - broadcast_target->state != QUERY_TARGET_QUERIED) - { - return; - } - - /* Create new target. */ - - target = get_target_for_addr(addr, true); - broadcast_target = get_target_for_addr(NULL, false); - target->state = QUERY_TARGET_QUERIED; - target->query_time = broadcast_target->query_time; - } - - if (target->state != QUERY_TARGET_RESPONDED) - { - target->state = QUERY_TARGET_RESPONDED; - memcpy(&target->data, &querydata, sizeof(net_querydata_t)); - - /* Calculate RTT. */ - - target->ping_time = i_get_time_ms() - target->query_time; - - /* Invoke callback to signal that we have a new address. */ - - callback(addr, &target->data, target->ping_time, user_data); - } -} - -/* Parse a response packet from the master server. */ - -static void net_query_parse_master_response(net_addr_t *master_addr, - net_packet_t *packet) -{ - unsigned int packet_type; - query_target_t *target; - char *addr_str; - net_addr_t *addr; - - /* Read the header. We are only interested in query responses. */ - - if (!net_read_int16(packet, &packet_type) || - packet_type != NET_MASTER_PACKET_TYPE_QUERY_RESPONSE) - { - return; - } - - /* Read a list of strings containing the addresses of servers - * that the master knows about. - */ - - for (; ; ) - { - addr_str = net_read_string(packet); - - if (addr_str == NULL) - { - break; - } - - /* Resolve address and add to targets list if it is not already - * there. - */ - - addr = net_resolve_address(g_query_context, addr_str); - if (addr != NULL) - { - get_target_for_addr(addr, true); - net_release_address(addr); - } - } - - /* Mark the master as having responded. */ - - target = get_target_for_addr(master_addr, true); - target->state = QUERY_TARGET_RESPONDED; -} - -static void net_query_parse_packet(net_addr_t *addr, net_packet_t *packet, - net_query_callback_t callback, - void *user_data) -{ - query_target_t *target; - - /* This might be the master server responding. */ - - target = get_target_for_addr(addr, false); - - if (target != NULL && target->type == QUERY_TARGET_MASTER) - { - net_query_parse_master_response(addr, packet); - } - else - { - net_query_parse_response(addr, packet, callback, user_data); - } -} - -static void net_query_get_response(net_query_callback_t callback, - void *user_data) -{ - net_addr_t *addr; - net_packet_t *packet; - - if (net_recv_packet(g_query_context, &addr, &packet)) - { - net_query_parse_packet(addr, packet, callback, user_data); - net_release_address(addr); - net_free_packet(packet); - } -} - -/* Find a target we have not yet queried and send a query. */ - -static void send_one_query(void) -{ - unsigned int now; - unsigned int i; - - now = i_get_time_ms(); - - /* Rate limit - only send one query every 50ms. */ - - if (now - g_last_query_time < 50) - { - return; - } - - for (i = 0; i < g_num_targets; ++i) - { - /* Not queried yet? - * Or last query timed out without a response? - */ - - if (g_targets[i].state == QUERY_TARGET_QUEUED || - (g_targets[i].state == QUERY_TARGET_QUERIED && - now - g_targets[i].query_time > QUERY_TIMEOUT_SECS * 1000)) - { - break; - } - } - - if (i >= g_num_targets) - { - return; - } - - /* Found a target to query. Send a query; how to do this depends on - * the target type. - */ - - switch (g_targets[i].type) - { - case QUERY_TARGET_SERVER: - net_query_send_query(g_targets[i].addr); - break; - - case QUERY_TARGET_BROADCAST: - net_query_send_query(NULL); - break; - - case QUERY_TARGET_MASTER: - net_query_send_master_query(g_targets[i].addr); - break; - } - - /* printf("Queried %s\n", net_addr_to_string(targets[i].addr)); */ - - g_targets[i].state = QUERY_TARGET_QUERIED; - g_targets[i].query_time = now; - ++g_targets[i].query_attempts; - - g_last_query_time = now; -} - -/* Time out servers that have been queried and not responded. */ - -static void check_target_timeouts(void) -{ - unsigned int i; - unsigned int now; - - now = i_get_time_ms(); - - for (i = 0; i < g_num_targets; ++i) - { - /* printf("target %i: state %i, queries %i, query time %i\n", - * i, targets[i].state, targets[i].query_attempts, - * now - targets[i].query_time); - */ - - /* We declare a target to be "no response" when we've sent - * multiple query packets to it (QUERY_MAX_ATTEMPTS) and - * received no response to any of them. - */ - - if (g_targets[i].state == QUERY_TARGET_QUERIED && - g_targets[i].query_attempts >= QUERY_MAX_ATTEMPTS && - now - g_targets[i].query_time > QUERY_TIMEOUT_SECS * 1000) - { - g_targets[i].state = QUERY_TARGET_NO_RESPONSE; - - if (g_targets[i].type == QUERY_TARGET_MASTER) - { - fprintf(stderr, "net_master_query: no response " - "from master server.\n"); - } - } - } -} - -/* If all targets have responded or timed out, returns true. */ - -static boolean all_targets_done(void) -{ - unsigned int i; - - for (i = 0; i < g_num_targets; ++i) - { - if (g_targets[i].state != QUERY_TARGET_RESPONDED && - g_targets[i].state != QUERY_TARGET_NO_RESPONSE) - { - return false; - } - } - - return true; -} - -/* Stop the query loop */ - -static void net_query_exit_loop(void) -{ - g_query_loop_running = false; -} - -/* Loop waiting for responses. - * The specified callback is invoked when a new server responds. - */ - -static void net_query_query_loop(net_query_callback_t callback, - void *user_data) -{ - g_query_loop_running = true; - - while (g_query_loop_running && net_query_poll(callback, user_data)) - { - /* Don't thrash the CPU */ - - usleep(1000); - } -} - -static void net_query_init(void) -{ - if (g_query_context == NULL) - { - g_query_context = net_new_context(); - net_add_module(g_query_context, &net_sdl_module); - net_sdl_module.init_client(); - } - - free(g_targets); - g_targets = NULL; - g_num_targets = 0; - - g_printed_header = false; -} - -/* Callback that exits the query loop when the first server is found. */ - -static void net_query_exit_callback(net_addr_t *addr, net_querydata_t *data, - unsigned int ping_time, void *user_data) -{ - net_query_exit_loop(); -} - -/* Search the targets list and find a target that has responded. - * If none have responded, returns NULL. - */ - -static query_target_t *find_first_responder(void) -{ - unsigned int i; - - for (i = 0; i < g_num_targets; ++i) - { - if (g_targets[i].type == QUERY_TARGET_SERVER && - g_targets[i].state == QUERY_TARGET_RESPONDED) - { - return &g_targets[i]; - } - } - - return NULL; -} - -/* Return a count of the number of responses. */ - -static int get_num_responses(void) -{ - unsigned int i; - int result; - - result = 0; - - for (i = 0; i < g_num_targets; ++i) - { - if (g_targets[i].type == QUERY_TARGET_SERVER && - g_targets[i].state == QUERY_TARGET_RESPONDED) - { - ++result; - } - } - - return result; -} - -static void formatted_printf(int wide, const char *s, ...) -{ - va_list args; - int i; - - va_start(args, s); - i = vprintf(s, args); - va_end(args); - - while (i < wide) - { - putchar(' '); - ++i; - } -} - -static const char *game_description(game_mode_t mode, gamemission_t mission) -{ - switch (mission) - { - case doom: - if (mode == shareware) - return "swdoom"; - else if (mode == registered) - return "regdoom"; - else if (mode == retail) - return "ultdoom"; - else - return "doom"; - case doom2: - return "doom2"; - case pack_tnt: - return "tnt"; - case pack_plut: - return "plutonia"; - case pack_chex: - return "chex"; - case pack_hacx: - return "hacx"; - case heretic: - return "heretic"; - case hexen: - return "hexen"; - case strife: - return "strife"; - default: - return "?"; - } -} - -static void print_header(void) -{ - int i; - - putchar('\n'); - formatted_printf(5, "Ping"); - formatted_printf(18, "Address"); - formatted_printf(8, "Players"); - puts("Description"); - - for (i = 0; i < 70; ++i) - putchar('='); - putchar('\n'); -} - -/* Callback function that just prints information in a table. */ - -static void net_query_print_callback(net_addr_t *addr, net_querydata_t *data, - unsigned int ping_time, void *user_data) -{ - /* If this is the first server, print the header. */ - - if (!g_printed_header) - { - print_header(); - g_printed_header = true; - } - - formatted_printf(5, "%4i", ping_time); - formatted_printf(22, "%s", net_addr_to_string(addr)); - formatted_printf(4, "%i/%i ", data->num_players, data->max_players); - - if (data->gamemode != indetermined) - { - printf("(%s) ", game_description(data->gamemode, data->gamemission)); - } - - if (data->server_state) - { - printf("(game running) "); - } - - printf("%s\n", data->description); -} - -#if 0 /* UNUSED */ - -/* Block until a packet of the given type is received from the given - * address. - */ - -static net_packet_t *block_for_packet(net_addr_t *addr, - unsigned int packet_type, - unsigned int timeout_ms) -{ - net_packet_t *packet; - net_addr_t *packet_src; - unsigned int read_packet_type; - unsigned int start_time; - - start_time = i_get_time_ms(); - - while (i_get_time_ms() < start_time + timeout_ms) - { - if (!net_recv_packet(g_query_context, &packet_src, &packet)) - { - usleep(20000); - continue; - } - - /* Caller doesn't need additional reference. */ - - net_release_address(packet_src); - - if (packet_src == addr && net_read_int16(packet, &read_packet_type) && - packet_type == read_packet_type) - { - return packet; - } - - net_free_packet(packet); - } - - /* Timeout - no response. */ - - return NULL; -} - -/* Query master server for secure demo start seed value. */ - -static boolean net_start_secure_demo(prng_seed_t seed) -{ - net_packet_t *request, *response; - net_addr_t *master_addr; - char *signature; - boolean result; - - net_query_init(); - master_addr = net_query_resolve_master(g_query_context); - - /* Send request packet to master server. */ - - request = net_new_packet(10); - net_write_int16(request, NET_MASTER_PACKET_TYPE_SIGN_START); - net_send_packet(master_addr, request); - net_free_packet(request); - - /* Block for response and read contents. - * The signed start message will be saved for later. - */ - - response = block_for_packet(master_addr, - NET_MASTER_PACKET_TYPE_SIGN_START_RESPONSE, - SIGNATURE_TIMEOUT_SECS * 1000); - - result = false; - - if (response != NULL) - { - if (net_read_prng_seed(response, seed)) - { - signature = net_read_string(response); - - if (signature != NULL) - { - g_securedemo_start_message = m_string_duplicate(signature); - result = true; - } - } - - net_free_packet(response); - } - - return result; -} - -/* Query master server for secure demo end signature. */ - -static char *net_end_secure_demo(sha1_digest_t demo_hash) -{ - net_packet_t *request, *response; - net_addr_t *master_addr; - char *signature; - - master_addr = net_query_resolve_master(g_query_context); - - /* Construct end request and send to master server. */ - - request = net_new_packet(10); - net_write_int16(request, NET_MASTER_PACKET_TYPE_SIGN_END); - net_write_sha1_sum(request, demo_hash); - net_write_string(request, g_securedemo_start_message); - net_send_packet(master_addr, request); - net_free_packet(request); - - /* Block for response. The response packet simply contains a string - * with the ASCII signature. - */ - - response = - block_for_packet(master_addr, NET_MASTER_PACKET_TYPE_SIGN_END_RESPONSE, - SIGNATURE_TIMEOUT_SECS * 1000); - - if (response == NULL) - { - return NULL; - } - - signature = net_read_string(response); - - net_free_packet(response); - - return signature; -} -#endif - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/* Resolve the master server address. */ - -net_addr_t *net_query_resolve_master(net_context_t *context) -{ - net_addr_t *addr; - - addr = net_resolve_address(context, MASTER_SERVER_ADDRESS); - - if (addr == NULL) - { - fprintf(stderr, - "Warning: Failed to resolve address " - "for master server: %s\n", - MASTER_SERVER_ADDRESS); - } - - return addr; -} - -/* Send a registration packet to the master server to register - * ourselves with the global list. - */ - -void net_query_add_to_master(net_addr_t *master_addr) -{ - net_packet_t *packet; - - packet = net_new_packet(10); - net_write_int16(packet, NET_MASTER_PACKET_TYPE_ADD); - net_send_packet(master_addr, packet); - net_free_packet(packet); -} - -/* Process a packet received from the master server. */ - -void net_query_add_response(net_packet_t *packet) -{ - unsigned int result; - - if (!net_read_int16(packet, &result)) - { - return; - } - - if (result != 0) - { - /* Only show the message once. */ - - if (!g_registered_with_master) - { - printf("Registered with master server at %s\n", - MASTER_SERVER_ADDRESS); - g_registered_with_master = true; - } - } - else - { - /* Always show rejections. */ - - printf("Failed to register with master server at %s\n", - MASTER_SERVER_ADDRESS); - } - - g_got_master_response = true; -} - -boolean net_query_check_added_to_master(boolean *result) -{ - /* Got response from master yet? */ - - if (!g_got_master_response) - { - return false; - } - - *result = g_registered_with_master; - return true; -} - -/* Send a hole punch request to the master server for the server at the - * given address. - */ - -void net_request_hole_punch(net_context_t *context, net_addr_t *addr) -{ - net_addr_t *master_addr; - net_packet_t *packet; - - master_addr = net_query_resolve_master(context); - if (master_addr == NULL) - { - return; - } - - packet = net_new_packet(32); - net_write_int16(packet, NET_MASTER_PACKET_TYPE_NAT_HOLE_PUNCH); - net_write_string(packet, net_addr_to_string(addr)); - net_send_packet(master_addr, packet); - - net_free_packet(packet); - net_release_address(master_addr); -} - -/* Polling function, invoked periodically to send queries and - * interpret new responses received from remote servers. - * Returns zero when the query sequence has completed and all targets - * have returned responses or timed out. - */ - -int net_query_poll(net_query_callback_t callback, void *user_data) -{ - check_target_timeouts(); - - /* Send a query. This will only send a single query at once. */ - - send_one_query(); - - /* Check for a response */ - - net_query_get_response(callback, user_data); - - return !all_targets_done(); -} - -int net_start_lan_query(void) -{ - query_target_t *target; - - net_query_init(); - - /* Add a broadcast target to the list. */ - - target = get_target_for_addr(NULL, true); - target->type = QUERY_TARGET_BROADCAST; - - return 1; -} - -int net_start_master_query(void) -{ - net_addr_t *master; - query_target_t *target; - - net_query_init(); - - /* Resolve master address and add to targets list. */ - - master = net_query_resolve_master(g_query_context); - - if (master == NULL) - { - return 0; - } - - target = get_target_for_addr(master, true); - target->type = QUERY_TARGET_MASTER; - net_release_address(master); - - return 1; -} - -void net_lan_query(void) -{ - if (net_start_lan_query()) - { - printf("\nSearching for servers on local LAN ...\n"); - - net_query_query_loop(net_query_print_callback, NULL); - - printf("\n%i server(s) found.\n", get_num_responses()); - free_targets(); - } -} - -void net_master_query(void) -{ - if (net_start_master_query()) - { - printf("\nSearching for servers on Internet ...\n"); - - net_query_query_loop(net_query_print_callback, NULL); - - printf("\n%i server(s) found.\n", get_num_responses()); - free_targets(); - } -} - -void net_query_address(const char *addr_str) -{ - net_addr_t *addr; - query_target_t *target; - - net_query_init(); - - addr = net_resolve_address(g_query_context, addr_str); - - if (addr == NULL) - { - i_error("net_query_address: Host '%s' not found!", addr_str); - } - - /* Add the address to the list of targets. */ - - target = get_target_for_addr(addr, true); - - printf("\nQuerying '%s'...\n", addr_str); - - /* Run query loop. */ - - net_query_query_loop(net_query_exit_callback, NULL); - - /* Check if the target responded. */ - - if (target->state == QUERY_TARGET_RESPONDED) - { - net_query_print_callback(addr, &target->data, target->ping_time, NULL); - net_release_address(addr); - free_targets(); - } - else - { - i_error("No response from '%s'", addr_str); - } -} - -net_addr_t *net_find_lan_server(void) -{ - query_target_t *target; - query_target_t *responder; - net_addr_t *result; - - net_query_init(); - - /* Add a broadcast target to the list. */ - - target = get_target_for_addr(NULL, true); - target->type = QUERY_TARGET_BROADCAST; - - /* Run the query loop, and stop at the first target found. */ - - net_query_query_loop(net_query_exit_callback, NULL); - - responder = find_first_responder(); - - if (responder != NULL) - { - result = responder->addr; - net_reference_address(result); - } - else - { - result = NULL; - } - - free_targets(); - return result; -} diff --git a/games/NXDoom/src/net_query.h b/games/NXDoom/src/net_query.h deleted file mode 100644 index 70dacfecd..000000000 --- a/games/NXDoom/src/net_query.h +++ /dev/null @@ -1,61 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/net_query.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Querying servers to find their current status. - * - ****************************************************************************/ - -#ifndef NET_QUERY_H -#define NET_QUERY_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "net_defs.h" - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -typedef void (*net_query_callback_t)(net_addr_t *addr, - net_querydata_t *querydata, - unsigned int ping_time, - void *user_data); - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -extern int net_start_lan_query(void); -extern int net_start_master_query(void); - -extern void net_lan_query(void); -extern void net_master_query(void); -extern void net_query_address(const char *addr); -extern net_addr_t *net_find_lan_server(void); - -extern int net_query_poll(net_query_callback_t callback, void *user_data); - -extern net_addr_t *net_query_resolve_master(net_context_t *context); -extern void net_query_add_to_master(net_addr_t *master_addr); -extern boolean net_query_check_added_to_master(boolean *result); -extern void net_query_add_response(net_packet_t *packet); -extern void net_request_hole_punch(net_context_t *context, net_addr_t *addr); - -#endif /* NET_QUERY_H */ diff --git a/games/NXDoom/src/net_sdl.c b/games/NXDoom/src/net_sdl.c deleted file mode 100644 index b57f4d206..000000000 --- a/games/NXDoom/src/net_sdl.c +++ /dev/null @@ -1,102 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/net_sdl.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Networking module which uses SDL_net - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include - -#include "doomtype.h" -#include "i_system.h" -#include "m_argv.h" -#include "m_misc.h" -#include "net_defs.h" -#include "net_io.h" -#include "net_packet.h" -#include "net_sdl.h" -#include "z_zone.h" - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -static boolean net_null_init_client(void); -static boolean net_null_init_server(void); -static void net_null_send_packet(net_addr_t *addr, net_packet_t *packet); -static boolean net_null_recv_packet(net_addr_t **addr, - net_packet_t **packet); -static void net_null_addr_to_string(net_addr_t *addr, char *buffer, - int buffer_len); -static void net_null_free_address(net_addr_t *addr); -static net_addr_t *net_null_resolve_address(const char *address); - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -net_module_t net_sdl_module = -{ - net_null_init_client, net_null_init_server, net_null_send_packet, - net_null_recv_packet, net_null_addr_to_string, net_null_free_address, - net_null_resolve_address, -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static net_addr_t *net_null_resolve_address(const char *address) -{ - return NULL; -} - -static boolean net_null_init_client(void) -{ - return false; -} - -static boolean net_null_init_server(void) -{ - return false; -} - -static void net_null_send_packet(net_addr_t *addr, net_packet_t *packet) -{ -} - -static boolean net_null_recv_packet(net_addr_t **addr, - net_packet_t **packet) -{ - return false; -} - -static void net_null_addr_to_string(net_addr_t *addr, char *buffer, - int buffer_len) -{ -} - -static void net_null_free_address(net_addr_t *addr) -{ -} diff --git a/games/NXDoom/src/net_sdl.h b/games/NXDoom/src/net_sdl.h deleted file mode 100644 index 6f972fd1d..000000000 --- a/games/NXDoom/src/net_sdl.h +++ /dev/null @@ -1,39 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/net_sdl.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Networking module which uses SDL_net - * - * - ****************************************************************************/ - -#ifndef NET_SDL_H -#define NET_SDL_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "net_defs.h" - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -extern net_module_t net_sdl_module; - -#endif /* NET_SDL_H */ diff --git a/games/NXDoom/src/net_server.c b/games/NXDoom/src/net_server.c deleted file mode 100644 index 61b5246f1..000000000 --- a/games/NXDoom/src/net_server.c +++ /dev/null @@ -1,2210 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/net_server.c - * - * SPDX-License-Identifier: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * Network server code - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include -#include - -#include "config.h" - -#include "d_mode.h" -#include "doomtype.h" -#include "i_system.h" -#include "i_timer.h" -#include "m_argv.h" -#include "m_misc.h" - -#include "net_client.h" -#include "net_common.h" -#include "net_defs.h" -#include "net_io.h" -#include "net_loop.h" -#include "net_packet.h" -#include "net_query.h" -#include "net_sdl.h" -#include "net_server.h" -#include "net_structrw.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* How often to refresh our registration with the master server. */ - -#define MASTER_REFRESH_PERIOD 30 /* twice per minute */ - -/* How often to re-resolve the address of the master server? */ - -#define MASTER_RESOLVE_PERIOD 8 * 60 * 60 /* 8 hours */ - -#define net_sv_expand_ticnum(b) net_expand_tic_num(recvwindow_start, (b)) - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -typedef enum -{ - /* waiting for the game to be "launched" (key player to press the start - * button) - */ - - SERVER_WAITING_LAUNCH, - - /* game has been launched, we are waiting for all players to be ready - * so the game can start. - */ - - SERVER_WAITING_START, - - /* in a game */ - - SERVER_IN_GAME, -} net_server_state_t; - -typedef struct -{ - boolean active; - int player_number; - net_addr_t *addr; - net_connection_t connection; - int last_send_time; - char *name; - - /* If true, the client has sent the NET_PACKET_TYPE_GAMESTART - * message indicating that it is ready for the game to start. - */ - - boolean ready; - - /* Time that this client connected to the server. - * This is used to determine the controller (oldest client). - */ - - unsigned int connect_time; - - /* Last time new gamedata was received from this client */ - - int last_gamedata_time; - - /* recording a demo without -longtics */ - - boolean recording_lowres; - - /* send queue: items to send to the client - * this is a circular buffer - */ - - int sendseq; - net_full_ticcmd_t sendqueue[CONFIG_GAMES_NXDOOM_NET_BACKUPTICS]; - - /* Latest acknowledged by the client */ - - unsigned int acknowledged; - - /* Value of max_players specified by the client on connect. */ - - int max_players; - - /* Observer: receives data but does not participate in the game. */ - - boolean drone; - - /* SHA1 hash sums of the client's WAD directory and dehacked data */ - - sha1_digest_t wad_sha1sum; - sha1_digest_t deh_sha1sum; - - /* Is this client is playing with the Freedoom IWAD? */ - - unsigned int is_freedoom; - - /* Player class (for Hexen) */ - - int player_class; -} net_client_t; - -/* structure used for the recv window */ - -typedef struct -{ - /* Whether this tic has been received yet */ - - boolean active; - - /* Latency value received from the client */ - - signed int latency; - - /* Last time we sent a resend request for this tic */ - - unsigned int resend_time; - - /* Tic data itself */ - - net_ticdiff_t diff; -} net_client_recv_t; - -typedef enum -{ - RANGE_LOCALHOST, /* Same process or 127.x */ - RANGE_PRIVATE, /* RFC 1918 */ - RANGE_PUBLIC, /* The public Internet */ -} ip_range_t; - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static net_server_state_t server_state; -static boolean server_initialized = false; -static net_client_t clients[MAXNETNODES]; -static net_client_t *sv_players[CONFIG_GAMES_NXDOOM_NET_MAXPLAYERS]; -static net_context_t *server_context; -static unsigned int sv_gamemode; -static unsigned int sv_gamemission; -static net_gamesettings_t sv_settings; - -/* For registration with master server: */ - -static net_addr_t *master_server = NULL; -static unsigned int master_refresh_time; -static unsigned int master_resolve_time; - -/* receive window */ - -static unsigned int recvwindow_start; -static net_client_recv_t recvwindow[CONFIG_GAMES_NXDOOM_NET_BACKUPTICS] - [CONFIG_GAMES_NXDOOM_NET_MAXPLAYERS]; - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -static void net_sv_send_console_message(net_client_t *client, const char *s, - ...) PRINTF_ATTR(2, 3); -static void net_sv_broadcast_message(const char *s, ...) PRINTF_ATTR(1, 2); - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static void net_sv_disconnect_client(net_client_t *client) -{ - if (client->active) - { - net_conn_disconnect(&client->connection); - } -} - -static boolean client_connected(net_client_t *client) -{ - /* Check that the client is properly connected: ie. not in the - * process of connecting or disconnecting - */ - - return client->active && - client->connection.state == NET_CONN_STATE_CONNECTED; -} - -/* Send a message to be displayed on a client's console */ - -static void net_sv_send_console_message(net_client_t *client, const char *s, - ...) -{ - char buf[1024]; - va_list args; - net_packet_t *packet; - - va_start(args, s); - vsnprintf(buf, sizeof(buf), s, args); - va_end(args); - - packet = net_conn_new_reliable(&client->connection, - NET_PACKET_TYPE_CONSOLE_MESSAGE); - - net_write_string(packet, buf); -} - -/* Send a message to all clients */ - -static void net_sv_broadcast_message(const char *s, ...) -{ - char buf[1024]; - va_list args; - int i; - - va_start(args, s); - vsnprintf(buf, sizeof(buf), s, args); - va_end(args); - - for (i = 0; i < MAXNETNODES; ++i) - { - if (client_connected(&clients[i])) - { - net_sv_send_console_message(&clients[i], "%s", buf); - } - } - - printf("%s\n", buf); -} - -/* Assign player numbers to connected clients */ - -static void net_sv_assign_players(void) -{ - int i; - int pl; - - pl = 0; - - for (i = 0; i < MAXNETNODES; ++i) - { - if (client_connected(&clients[i])) - { - if (!clients[i].drone) - { - sv_players[pl] = &clients[i]; - sv_players[pl]->player_number = pl; - ++pl; - } - else - { - clients[i].player_number = -1; - } - } - } - - for (; pl < CONFIG_GAMES_NXDOOM_NET_MAXPLAYERS; ++pl) - { - sv_players[pl] = NULL; - } -} - -/* Returns the number of players currently connected. */ - -static int net_sv_num_players(void) -{ - int i; - int result; - - result = 0; - - for (i = 0; i < CONFIG_GAMES_NXDOOM_NET_MAXPLAYERS; ++i) - { - if (sv_players[i] != NULL && client_connected(sv_players[i])) - { - result += 1; - } - } - - return result; -} - -/* Returns the number of players ready to start the game. */ - -static int net_sv_num_ready_players(void) -{ - int result = 0; - int i; - - for (i = 0; i < MAXNETNODES; ++i) - { - if (client_connected(&clients[i]) && !clients[i].drone && - clients[i].ready) - { - ++result; - } - } - - return result; -} - -/* Returns the maximum number of players that can play. */ - -static int net_sv_max_players(void) -{ - int i; - - for (i = 0; i < MAXNETNODES; ++i) - { - if (client_connected(&clients[i])) - { - return clients[i].max_players; - } - } - - return CONFIG_GAMES_NXDOOM_NET_MAXPLAYERS; -} - -/* Returns the number of drones currently connected. */ - -static int net_sv_num_drones(void) -{ - int i; - int result; - - result = 0; - - for (i = 0; i < MAXNETNODES; ++i) - { - if (client_connected(&clients[i]) && clients[i].drone) - { - result += 1; - } - } - - return result; -} - -/* returns the number of clients connected */ - -static int net_sv_num_clients(void) -{ - int count; - int i; - - count = 0; - - for (i = 0; i < MAXNETNODES; ++i) - { - if (client_connected(&clients[i])) - { - ++count; - } - } - - return count; -} - -/* returns a pointer to the client which controls the server */ - -static net_client_t *net_sv_controller(void) -{ - net_client_t *best; - int i; - - /* Find the oldest client (first to connect). */ - - best = NULL; - - for (i = 0; i < MAXNETNODES; ++i) - { - /* Can't be controller? */ - - if (!client_connected(&clients[i]) || clients[i].drone) - { - continue; - } - - if (best == NULL || clients[i].connect_time < best->connect_time) - { - best = &clients[i]; - } - } - - return best; -} - -static ip_range_t client_address_range(const char *addr) -{ - if (!strcmp(addr, "local client") || m_string_starts_with(addr, "127.")) - { - return RANGE_LOCALHOST; - } - - if (m_string_starts_with(addr, "10.") || - m_string_starts_with(addr, "192.168.")) - { - return RANGE_PRIVATE; - } - - return RANGE_PUBLIC; -} - -static void net_sv_send_waiting_data(net_client_t *client) -{ - net_waitdata_t wait_data; - net_packet_t *packet; - net_client_t *controller; - ip_range_t client_range, player_range; - const char *addr; - int i; - - net_sv_assign_players(); - - controller = net_sv_controller(); - - wait_data.num_players = net_sv_num_players(); - wait_data.num_drones = net_sv_num_drones(); - wait_data.ready_players = net_sv_num_ready_players(); - wait_data.max_players = net_sv_max_players(); - wait_data.is_controller = (client == controller); - wait_data.consoleplayer = client->player_number; - - /* Send the WAD and dehacked checksums of the controlling client. - * If no controller found (?), send the details that the client - * is expecting anyway. - */ - - if (controller == NULL) - { - controller = client; - } - - memcpy(&wait_data.wad_sha1sum, &controller->wad_sha1sum, - sizeof(sha1_digest_t)); - memcpy(&wait_data.deh_sha1sum, &controller->deh_sha1sum, - sizeof(sha1_digest_t)); - wait_data.is_freedoom = controller->is_freedoom; - - /* We only send IP addresses to locally-connected clients (including - * the 127.* loopback range): - */ - - addr = net_addr_to_string(client->connection.addr); - client_range = client_address_range(addr); - - /* set name and address of each player: */ - - for (i = 0; i < wait_data.num_players; ++i) - { - m_str_copy(wait_data.player_names[i], sv_players[i]->name, - CONFIG_GAMES_NXDOOM_NET_MAXPLAYERNAME); - - /* For privacy, only local clients or those on a LAN get to see - * addresses. Public clients only get to see their own address, - * though we do reveal localhost addresses since they're harmless, - * and we do reveal when a client is connected via LAN. - */ - - addr = net_addr_to_string(sv_players[i]->addr); - player_range = client_address_range(addr); - if (client_range == RANGE_LOCALHOST || client_range == RANGE_PRIVATE || - i == wait_data.consoleplayer || player_range == RANGE_LOCALHOST) - { - m_str_copy(wait_data.player_addrs[i], addr, - CONFIG_GAMES_NXDOOM_NET_MAXPLAYERNAME); - } - else if (player_range == RANGE_PRIVATE) - { - snprintf(wait_data.player_addrs[i], - CONFIG_GAMES_NXDOOM_NET_MAXPLAYERNAME, - "[LAN player]"); - } - else - { - snprintf(wait_data.player_addrs[i], - CONFIG_GAMES_NXDOOM_NET_MAXPLAYERNAME, - "[address hidden]"); - } - } - - /* Construct packet: */ - - packet = net_new_packet(10); - net_write_int16(packet, NET_PACKET_TYPE_WAITING_DATA); - net_write_wait_data(packet, &wait_data); - - /* Send packet to client and free */ - - net_conn_send_packet(&client->connection, packet); - net_free_packet(packet); -} - -/* Find the latest tic which has been acknowledged as received by - * all clients. - */ - -static unsigned int net_sv_latest_acknowledged(void) -{ - unsigned int lowtic = UINT_MAX; - int i; - - for (i = 0; i < MAXNETNODES; ++i) - { - if (client_connected(&clients[i])) - { - if (clients[i].acknowledged < lowtic) - { - lowtic = clients[i].acknowledged; - } - } - } - - return lowtic; -} - -/* Possibly advance the recv window if all connected clients have - * used the data in the window - */ - -static void net_sv_advance_window(void) -{ - unsigned int lowtic; - int i; - - if (net_sv_num_players() <= 0) - { - return; - } - - lowtic = net_sv_latest_acknowledged(); - - /* Advance the recv window until it catches up with lowtic */ - - while (recvwindow_start < lowtic) - { - boolean should_advance; - - /* Check we have tics from all players for first tic in - * the recv window - */ - - should_advance = true; - - for (i = 0; i < CONFIG_GAMES_NXDOOM_NET_MAXPLAYERS; ++i) - { - if (sv_players[i] == NULL || !client_connected(sv_players[i])) - { - continue; - } - - if (!recvwindow[0][i].active) - { - should_advance = false; - break; - } - } - - if (!should_advance) - { - /* The first tic is not complete: ie. we have not - * received tics from all connected players. This can - * happen if only one player is in the game. - */ - - break; - } - - /* Advance the window */ - - memmove(recvwindow, recvwindow + 1, - sizeof(*recvwindow) * - (CONFIG_GAMES_NXDOOM_NET_BACKUPTICS - 1)); - memset(&recvwindow[CONFIG_GAMES_NXDOOM_NET_BACKUPTICS - 1], - 0, sizeof(*recvwindow)); - ++recvwindow_start; - net_log_info("server: advanced receive window to %d", - recvwindow_start); - } -} - -/* Given an address, find the corresponding client */ - -static net_client_t *net_sv_find_client(net_addr_t *addr) -{ - int i; - - for (i = 0; i < MAXNETNODES; ++i) - { - if (clients[i].active && clients[i].addr == addr) - { - /* found the client */ - - return &clients[i]; - } - } - - return NULL; -} - -/* send a rejection packet to a client */ - -static void net_sv_send_reject(net_addr_t *addr, const char *msg) -{ - net_packet_t *packet; - - net_log_info("server: sending reject to %s", net_addr_to_string(addr)); - - packet = net_new_packet(10); - net_write_int16(packet, NET_PACKET_TYPE_REJECTED); - net_write_string(packet, msg); - net_send_packet(addr, packet); - net_free_packet(packet); -} - -static void net_sv_init_new_client(net_client_t *client, net_addr_t *addr, - net_protocol_t protocol) -{ - client->active = true; - client->connect_time = i_get_time_ms(); - net_conn_init_server(&client->connection, addr, protocol); - client->addr = addr; - net_reference_address(addr); - client->last_send_time = -1; - - /* init the ticcmd send queue */ - - client->sendseq = 0; - client->acknowledged = 0; - client->drone = false; - client->ready = false; - - client->last_gamedata_time = 0; - - memset(client->sendqueue, 0xff, sizeof(client->sendqueue)); - - net_log_info("server: initialized new client from %s", - net_addr_to_string(addr)); -} - -/* parse a SYN from a client(initiating a connection) */ - -static void net_sv_parse_syn(net_packet_t *packet, net_client_t *client, - net_addr_t *addr) -{ - unsigned int magic; - net_connect_data_t data; - net_packet_t *reply; - net_protocol_t protocol; - char *player_name; - char *client_version; - int num_players; - int i; - - net_log_info("server: processing SYN packet"); - - /* Read the magic number and check it is the expected one. */ - - if (!net_read_int32(packet, &magic)) - { - net_log_err("server: no magic number for SYN"); - return; - } - - switch (magic) - { - case NET_MAGIC_NUMBER: - break; - - case NET_OLD_MAGIC_NUMBER: - net_log_err("server: client using old magic number: %d", magic); - net_sv_send_reject( - addr, - "You are using an old client version that is not supported by " - "this server. This server is running " PACKAGE_STRING "."); - return; - - default: - net_log_err("server: wrong magic number: %d", magic); - return; - } - - /* Read the client version string. We actually now only use this when - * sending a reject message, as we only reject if we can't negotiate a - * common protocol (below). - */ - - client_version = net_read_string(packet); - if (client_version == NULL) - { - net_log_err("server: no version from client"); - return; - } - - /* Read the client's list of accepted protocols. Net play between forks - * of Chocolate Doom is accepted provided that they can negotiate a - * common accepted protocol. - */ - - protocol = net_read_protocol_list(packet); - if (protocol == NET_PROTOCOL_UNKNOWN) - { - char reject_msg[256]; - - snprintf(reject_msg, sizeof(reject_msg), - "Version mismatch: server version is: " PACKAGE_STRING "; " - "client is: %s. No common compatible protocol could be " - "negotiated.", - client_version); - net_sv_send_reject(addr, reject_msg); - net_log_err("server: no common protocol"); - return; - } - - /* Read connect data, and check that the game mode/mission are valid - * and the max_players value is in a sensible range. - */ - - if (!net_read_connect_data(packet, &data)) - { - net_log_err("server: failed to read connect data"); - return; - } - - if (!d_valid_game_mode(data.gamemission, data.gamemode) || - data.max_players > CONFIG_GAMES_NXDOOM_NET_MAXPLAYERS) - { - net_log_err("server: invalid connect data, max_players=%d, " - "gamemission=%d, gamemode=%d", - data.max_players, data.gamemission, data.gamemode); - return; - } - - /* Read the player's name */ - - player_name = net_read_string(packet); - if (player_name == NULL) - { - net_log_err("server: failed to read player name"); - return; - } - - /* At this point we have received a valid SYN. */ - - /* Not accepting new connections? */ - - if (server_state != SERVER_WAITING_LAUNCH) - { - net_log_err("server: not in waiting launch state, server_state=%d", - server_state); - net_sv_send_reject(addr, - "Server is not currently accepting connections"); - return; - } - - /* Before accepting a new client, check that there is a slot free. */ - - net_sv_assign_players(); - num_players = net_sv_num_players(); - - if ((!data.drone && num_players >= net_sv_max_players()) || - net_sv_num_clients() >= MAXNETNODES) - { - net_log_info("server: no more players, num_players=%d, max=%d", - num_players, net_sv_max_players()); - net_sv_send_reject(addr, "Server is full!"); - return; - } - - /* TODO: Add server option to allow rejecting clients which set - * lowres_turn. This is potentially desirable as the presence of such - * clients affects turning resolution. - */ - - /* Adopt the game mode and mission of the first connecting client: */ - - if (num_players == 0 && !data.drone) - { - sv_gamemode = data.gamemode; - sv_gamemission = data.gamemission; - net_log_info("server: new game, mode=%d, mission=%d", sv_gamemode, - sv_gamemission); - } - - /* Check the connecting client is playing the same game as all - * the other clients - */ - - if (data.gamemode != sv_gamemode || data.gamemission != sv_gamemission) - { - char msg[128]; - net_log_warn("server: wrong mode/mission, %d != %d || %d != %d", - data.gamemode, sv_gamemode, data.gamemission, - sv_gamemission); - snprintf(msg, sizeof(msg), - "Game mismatch: server is %s (%s), client is %s (%s)", - d_game_mission_string(sv_gamemission), - d_game_mode_string(sv_gamemode), - d_game_mission_string(data.gamemission), - d_game_mode_string(data.gamemode)); - - net_sv_send_reject(addr, msg); - return; - } - - /* Allocate a client slot if there isn't one already */ - - if (client == NULL) - { - /* find a slot, or return if none found */ - - for (i = 0; i < MAXNETNODES; ++i) - { - if (!clients[i].active) - { - client = &clients[i]; - break; - } - } - - if (client == NULL) - { - return; - } - } - else - { - /* If this is a recently-disconnected client, deactivate - * to allow immediate reconnection - */ - - if (client->connection.state == NET_CONN_STATE_DISCONNECTED) - { - client->active = false; - } - } - - /* Client already connected? */ - - if (client->active) - { - net_log_warn("server: client is already initialized (duplicate SYN?)"); - return; - } - - /* Activate, initialize connection */ - - net_sv_init_new_client(client, addr, protocol); - - /* Save the SHA1 checksums and other details. */ - - memcpy(client->wad_sha1sum, data.wad_sha1sum, sizeof(sha1_digest_t)); - memcpy(client->deh_sha1sum, data.deh_sha1sum, sizeof(sha1_digest_t)); - client->is_freedoom = data.is_freedoom; - client->max_players = data.max_players; - client->name = m_string_duplicate(player_name); - client->recording_lowres = data.lowres_turn; - client->drone = data.drone; - client->player_class = data.player_class; - - /* Send a reply back to the client, indicating a successful connection - * and specifying the protocol that will be used for communications. - */ - - reply = net_conn_new_reliable(&client->connection, NET_PACKET_TYPE_SYN); - net_write_string(reply, PACKAGE_STRING); - net_write_protocol(reply, protocol); -} - -/* Parse a launch packet. This is sent by the key player when the "start" - * button is pressed, and causes the startup process to continue. - */ - -static void net_sv_parse_launch(net_packet_t *packet, net_client_t *client) -{ - net_packet_t *launchpacket; - int num_players; - unsigned int i; - - net_log_info("server: processing launch packet"); - - /* Only the controller can launch the game. */ - - if (client != net_sv_controller()) - { - net_log_err("server: this client isn't the controller, %p != %p", - client, net_sv_controller()); - return; - } - - /* Can only launch when we are in the waiting state. */ - - if (server_state != SERVER_WAITING_LAUNCH) - { - net_log_err("server: not in waiting launch state, state=%d", - server_state); - return; - } - - /* Forward launch on to all clients. */ - - net_log_info("server: sending launch to all clients"); - net_sv_assign_players(); - num_players = net_sv_num_players(); - - for (i = 0; i < MAXNETNODES; ++i) - { - if (!client_connected(&clients[i])) continue; - - launchpacket = net_conn_new_reliable(&clients[i].connection, - NET_PACKET_TYPE_LAUNCH); - net_write_int8(launchpacket, num_players); - } - - /* Now in launch state. */ - - server_state = SERVER_WAITING_START; -} - -/* Transition to the in-game state and send all players the start game - * message. Invoked once all players have indicated they are ready to - * start the game. - */ - -static void start_game(void) -{ - net_packet_t *startpacket; - unsigned int i; - int nowtime; - - /* Assign player numbers */ - - net_sv_assign_players(); - - /* Check if anyone is recording a demo and set lowres_turn if so. */ - - sv_settings.lowres_turn = false; - - for (i = 0; i < CONFIG_GAMES_NXDOOM_NET_MAXPLAYERS; ++i) - { - if (sv_players[i] != NULL && sv_players[i]->recording_lowres) - { - sv_settings.lowres_turn = true; - } - } - - sv_settings.num_players = net_sv_num_players(); - - /* Copy player classes: */ - - for (i = 0; i < CONFIG_GAMES_NXDOOM_NET_MAXPLAYERS; ++i) - { - if (sv_players[i] != NULL) - { - sv_settings.player_classes[i] = sv_players[i]->player_class; - } - else - { - sv_settings.player_classes[i] = 0; - } - } - - nowtime = i_get_time_ms(); - - /* Send start packets to each connected node */ - - for (i = 0; i < MAXNETNODES; ++i) - { - if (!client_connected(&clients[i])) continue; - - clients[i].last_gamedata_time = nowtime; - - startpacket = net_conn_new_reliable(&clients[i].connection, - NET_PACKET_TYPE_GAMESTART); - - sv_settings.consoleplayer = clients[i].player_number; - - net_write_settings(startpacket, &sv_settings); - } - - /* Change server state */ - - net_log_info("server: beginning game state"); - server_state = SERVER_IN_GAME; - - memset(recvwindow, 0, sizeof(recvwindow)); - recvwindow_start = 0; -} - -/* Returns true when all nodes have indicated readiness to start the game. */ - -static boolean all_nodes_ready(void) -{ - unsigned int i; - - for (i = 0; i < MAXNETNODES; ++i) - { - if (client_connected(&clients[i]) && !clients[i].ready) - { - return false; - } - } - - return true; -} - -/* Check if the game should start, and if so, start it. */ - -static void check_start_game(void) -{ - if (!all_nodes_ready()) - { - net_log_warn("server: not all clients ready to start yet"); - return; - } - - net_log_info("server: all clients ready, starting game"); - start_game(); -} - -/* Send waiting data with current status to all nodes that are ready to - * start the game. - */ - -static void send_all_waiting_data(void) -{ - unsigned int i; - - for (i = 0; i < MAXNETNODES; ++i) - { - if (client_connected(&clients[i]) && clients[i].ready) - { - net_sv_send_waiting_data(&clients[i]); - } - } -} - -/* Parse a game start packet */ - -static void net_sv_parse_game_start(net_packet_t *packet, - net_client_t *client) -{ - net_gamesettings_t settings; - - net_log_info("server: processing game start packet"); - - /* Can only start a game if we are in the waiting start state. */ - - if (server_state != SERVER_WAITING_START) - { - net_log_info( - "server: error: not in waiting start state, server_state=%d", - server_state); - return; - } - - if (client == net_sv_controller()) - { - if (!net_read_settings(packet, &settings)) - { - /* Malformed packet */ - - net_log_err("server: no settings from controller"); - return; - } - - /* Check the game settings are valid */ - - if (!net_valid_game_settings(sv_gamemode, sv_gamemission, &settings)) - { - net_log_err("server: invalid game settings"); - return; - } - - sv_settings = settings; - } - - client->ready = true; - - check_start_game(); - - /* Update all ready clients with the current state (number of players - * ready, etc.). This is used by games that show startup progress - * (eg. Hexen's spinal loading) - */ - - send_all_waiting_data(); -} - -/* Send a resend request to a client */ - -static void net_sv_send_resend_request(net_client_t *client, int start, - int end) -{ - net_packet_t *packet; - net_client_recv_t *recvobj; - int i; - unsigned int nowtime; - int index; - - net_log_info("server: send resend to %s for tics %d-%d", - net_addr_to_string(client->addr), start, end); - - packet = net_new_packet(20); - - net_write_int16(packet, NET_PACKET_TYPE_GAMEDATA_RESEND); - net_write_int32(packet, start); - net_write_int8(packet, end - start + 1); - - net_conn_send_packet(&client->connection, packet); - net_free_packet(packet); - - /* Store the time we send the resend request */ - - nowtime = i_get_time_ms(); - - for (i = start; i <= end; ++i) - { - index = i - recvwindow_start; - - if (index >= CONFIG_GAMES_NXDOOM_NET_BACKUPTICS) - { - /* Outside the range */ - - continue; - } - - recvobj = &recvwindow[index][client->player_number]; - - recvobj->resend_time = nowtime; - } -} - -/* Check for expired resend requests */ - -static void net_sv_check_resends(net_client_t *client) -{ - int i; - int player; - int resend_start; - int resend_end; - unsigned int nowtime; - - nowtime = i_get_time_ms(); - - player = client->player_number; - resend_start = -1; - resend_end = -1; - - for (i = 0; i < CONFIG_GAMES_NXDOOM_NET_BACKUPTICS; ++i) - { - net_client_recv_t *recvobj; - boolean need_resend; - - recvobj = &recvwindow[i][player]; - - /* if need_resend is true, this tic needs another retransmit - * request (300ms timeout) - */ - - need_resend = !recvobj->active && recvobj->resend_time != 0 && - nowtime > recvobj->resend_time + 300; - - if (need_resend) - { - /* Start a new run of resend tics? */ - - if (resend_start < 0) - { - resend_start = i; - } - - resend_end = i; - } - else if (resend_start >= 0) - { - /* End of a run of resend tics */ - - net_log_warn( - "server: resend request to %s timed out for %d-%d (%p)", - net_addr_to_string(client->addr), - recvwindow_start + resend_start, - recvwindow_start + resend_end, - &recvwindow[resend_start][player].resend_time); - - net_sv_send_resend_request(client, recvwindow_start + resend_start, - recvwindow_start + resend_end); - - resend_start = -1; - } - } - - if (resend_start >= 0) - { - net_log_warn("server: resend request to %s timed out for %d-%d (%p)", - net_addr_to_string(client->addr), - recvwindow_start + resend_start, - recvwindow_start + resend_end, - &recvwindow[resend_start][player].resend_time); - net_sv_send_resend_request(client, recvwindow_start + resend_start, - recvwindow_start + resend_end); - } -} - -/* Process game data from a client */ - -static void net_sv_parse_game_data(net_packet_t *packet, - net_client_t *client) -{ - net_client_recv_t *recvobj; - unsigned int seq; - unsigned int ackseq; - unsigned int num_tics; - unsigned int nowtime; - size_t i; - int player; - int resend_start; - int resend_end; - int index; - - if (server_state != SERVER_IN_GAME) - { - net_log_err("server: not in game state: server_state=%d", - server_state); - return; - } - - if (client->drone) - { - /* Drones do not contribute any game data. */ - - net_log_err("server: game data from a drone?"); - return; - } - - player = client->player_number; - - /* Read header */ - - if (!net_read_int8(packet, &ackseq) || !net_read_int8(packet, &seq) || - !net_read_int8(packet, &num_tics)) - { - net_log_err("server: failed to read header"); - return; - } - - net_log_info("server: got game data, seq=%d, num_tics=%d, ackseq=%d", seq, - num_tics, ackseq); - - /* Get the current time */ - - nowtime = i_get_time_ms(); - - /* Expand 8-bit values to the full sequence number */ - - ackseq = net_sv_expand_ticnum(ackseq); - seq = net_sv_expand_ticnum(seq); - - /* Sanity checks */ - - for (i = 0; i < num_tics; ++i) - { - net_ticdiff_t diff; - signed int latency; - - if (!net_read_sint16(packet, &latency) || - !net_read_ticcmd_diff(packet, &diff, sv_settings.lowres_turn)) - { - return; - } - - index = seq + i - recvwindow_start; - - if (index < 0 || index >= CONFIG_GAMES_NXDOOM_NET_BACKUPTICS) - { - /* Not in range of the recv window */ - - continue; - } - - recvobj = &recvwindow[index][player]; - recvobj->active = true; - recvobj->diff = diff; - recvobj->latency = latency; - - client->last_gamedata_time = nowtime; - net_log_info("server: stored tic %zu for player %d", seq + i, player); - } - - /* Higher acknowledgement point? */ - - if (ackseq > client->acknowledged) - { - net_log_info("server: acknowledged up to %d", ackseq); - client->acknowledged = ackseq; - } - - /* Has this been received out of sequence, ie. have we not received - * all tics before the first tic in this packet? If so, send a - * resend request. - */ - - resend_end = seq - recvwindow_start; - - if (resend_end <= 0) return; - - if (resend_end >= CONFIG_GAMES_NXDOOM_NET_BACKUPTICS) - { - resend_end = CONFIG_GAMES_NXDOOM_NET_BACKUPTICS - 1; - } - - index = resend_end - 1; - resend_start = resend_end; - - while (index >= 0) - { - recvobj = &recvwindow[index][player]; - - if (recvobj->active) - { - /* ended our run of unreceived tics */ - - break; - } - - if (recvobj->resend_time != 0) - { - /* Already sent a resend request for this tic */ - - break; - } - - resend_start = index; - --index; - } - - /* Possibly send a resend request */ - - if (resend_start < resend_end) - { - net_log_info("server: request resend for %d-%d before %d", - recvwindow_start + resend_start, - recvwindow_start + resend_end - 1, seq); - net_sv_send_resend_request(client, recvwindow_start + resend_start, - recvwindow_start + resend_end - 1); - } -} - -static void net_sv_parse_game_data_ack(net_packet_t *packet, - net_client_t *client) -{ - unsigned int ackseq; - - net_log_info("server: processing game data ack packet"); - - if (server_state != SERVER_IN_GAME) - { - net_log_err("server: not in game state, server_state=%d", - server_state); - return; - } - - /* Read header */ - - if (!net_read_int8(packet, &ackseq)) - { - net_log_err("server: missing acknowledgement field"); - return; - } - - /* Expand 8-bit values to the full sequence number */ - - ackseq = net_sv_expand_ticnum(ackseq); - - /* Higher acknowledgement point than we already have? */ - - if (ackseq > client->acknowledged) - { - net_log_info("server: acknowledged up to %d", ackseq); - client->acknowledged = ackseq; - } -} - -static void net_sv_send_tics(net_client_t *client, unsigned int start, - unsigned int end) -{ - net_packet_t *packet; - unsigned int i; - - packet = net_new_packet(500); - - net_write_int16(packet, NET_PACKET_TYPE_GAMEDATA); - - /* Send the start tic and number of tics */ - - net_write_int8(packet, start & 0xff); - net_write_int8(packet, end - start + 1); - - /* Write the tics */ - - for (i = start; i <= end; ++i) - { - net_full_ticcmd_t *cmd; - - cmd = &client->sendqueue[i % CONFIG_GAMES_NXDOOM_NET_BACKUPTICS]; - - if (i != cmd->seq) - { - i_error("Wanted to send %i, but %i is in its place", i, cmd->seq); - } - - /* Add command */ - - net_write_full_ticcmd(packet, cmd, sv_settings.lowres_turn); - } - - /* Send packet */ - - net_conn_send_packet(&client->connection, packet); - - net_free_packet(packet); -} - -/* Parse a retransmission request from a client */ - -static void net_sv_parse_resend_request(net_packet_t *packet, - net_client_t *client) -{ - unsigned int start; - unsigned int last; - unsigned int num_tics; - unsigned int i; - - net_log_info("server: processing resend request"); - - /* Read the starting tic and number of tics */ - - if (!net_read_int32(packet, &start) || !net_read_int8(packet, &num_tics)) - { - net_log_err("server: missing fields for resend"); - return; - } - - /* Check we have all the requested tics */ - - last = start + num_tics - 1; - - for (i = start; i <= last; ++i) - { - net_full_ticcmd_t *cmd; - - cmd = &client->sendqueue[i % CONFIG_GAMES_NXDOOM_NET_BACKUPTICS]; - - if (i != cmd->seq) - { - /* We do not have the requested tic (any more) - * This is pretty fatal. We could disconnect the client, - * but then again this could be a spoofed packet. Just - * ignore it. - */ - - net_log_err("server: don't have tic %d any more, " - "can't resend", - i); - return; - } - } - - /* Resend those tics */ - - net_log_info("server: resending tics %d-%d", start, last); - net_sv_send_tics(client, start, last); -} - -static void net_sv_parse_hole_punch(net_packet_t *packet) -{ - const char *addr_string; - net_packet_t *sendpacket; - net_addr_t *addr; - - addr_string = net_read_string(packet); - if (addr_string == NULL) - { - net_log_err("server: hole punch request but no address provided"); - return; - } - - addr = net_resolve_address(server_context, addr_string); - if (addr == NULL) - { - net_log_err("server: failed to resolve address: %s", addr_string); - return; - } - - sendpacket = net_new_packet(16); - net_write_int16(sendpacket, NET_PACKET_TYPE_NAT_HOLE_PUNCH); - net_send_packet(addr, sendpacket); - net_free_packet(sendpacket); - net_release_address(addr); - net_log_info("server: sent hole punch to %s", addr_string); -} - -static void net_sv_master_packet(net_packet_t *packet) -{ - unsigned int packet_type; - - /* Read the packet type */ - - if (!net_read_int16(packet, &packet_type)) - { - net_log_err("server: no packet type in master server message"); - return; - } - - net_log_info("server: packet from master server; type %d", packet_type); - net_log_packet(packet); - - switch (packet_type) - { - case NET_MASTER_PACKET_TYPE_ADD_RESPONSE: - net_query_add_response(packet); - break; - - case NET_MASTER_PACKET_TYPE_NAT_HOLE_PUNCH: - net_sv_parse_hole_punch(packet); - break; - } -} - -/* Send a response back to the client */ - -static void net_sv_send_query_response(net_addr_t *addr) -{ - net_packet_t *reply; - net_querydata_t querydata; - int p; - - /* Version */ - - querydata.version = PACKAGE_STRING; - - /* Server state */ - - querydata.server_state = server_state; - - /* Number of players/maximum players */ - - querydata.num_players = net_sv_num_players(); - querydata.max_players = net_sv_max_players(); - - /* Game mode/mission */ - - querydata.gamemode = sv_gamemode; - querydata.gamemission = sv_gamemission; - - /* @category net - * @arg - * - * When starting a network server, specify a name for the server. - */ - - p = m_check_parm_with_args("-servername", 1); - - if (p > 0) - { - querydata.description = myargv[p + 1]; - } - else - { - querydata.description = "Unnamed server"; - } - - /* Send it and we're done. */ - - net_log_info("server: sending query response to %s", - net_addr_to_string(addr)); - reply = net_new_packet(64); - net_write_int16(reply, NET_PACKET_TYPE_QUERY_RESPONSE); - net_write_query_data(reply, &querydata); - net_send_packet(addr, reply); - net_free_packet(reply); -} - -/* Process a packet received by the server */ - -static void net_sv_packet(net_packet_t *packet, net_addr_t *addr) -{ - net_client_t *client; - unsigned int packet_type; - - /* Response from master server? */ - - if (addr != NULL && addr == master_server) - { - net_sv_master_packet(packet); - return; - } - - /* Find which client this packet came from */ - - client = net_sv_find_client(addr); - - /* Read the packet type */ - - if (!net_read_int16(packet, &packet_type)) - { - /* no packet type */ - - return; - } - - net_log_info("server: packet from %s; type %d", net_addr_to_string(addr), - packet_type & ~NET_RELIABLE_PACKET); - net_log_packet(packet); - - if (packet_type == NET_PACKET_TYPE_SYN) - { - net_sv_parse_syn(packet, client, addr); - } - else if (packet_type == NET_PACKET_TYPE_QUERY) - { - net_sv_send_query_response(addr); - } - else if (client == NULL) - { - /* Must come from a valid client; ignore otherwise */ - } - else if (net_conn_packet(&client->connection, packet, &packet_type)) - { - /* Packet was eaten by the common connection code */ - } - else - { - switch (packet_type) - { - case NET_PACKET_TYPE_GAMESTART: - net_sv_parse_game_start(packet, client); - break; - case NET_PACKET_TYPE_LAUNCH: - net_sv_parse_launch(packet, client); - break; - case NET_PACKET_TYPE_GAMEDATA: - net_sv_parse_game_data(packet, client); - break; - case NET_PACKET_TYPE_GAMEDATA_ACK: - net_sv_parse_game_data_ack(packet, client); - break; - case NET_PACKET_TYPE_GAMEDATA_RESEND: - net_sv_parse_resend_request(packet, client); - break; - default: - break; /* unknown packet type */ - } - } -} - -static void net_sv_pump_send_queue(net_client_t *client) -{ - net_full_ticcmd_t cmd; - int recv_index; - int num_players; - int i; - int starttic; - int endtic; - - /* If a client has not sent any acknowledgments for a while, - * wait until they catch up. - */ - - if (client->sendseq - net_sv_latest_acknowledged() > 40) - { - return; - } - - /* Work out the index into the receive window */ - - recv_index = client->sendseq - recvwindow_start; - - if (recv_index < 0 || recv_index >= CONFIG_GAMES_NXDOOM_NET_BACKUPTICS) - { - return; - } - - /* Check if we can generate a new entry for the send queue - * using the data in recvwindow. - */ - - num_players = 0; - - for (i = 0; i < CONFIG_GAMES_NXDOOM_NET_MAXPLAYERS; ++i) - { - if (sv_players[i] == client) - { - /* Client does not rely on itself for data */ - - continue; - } - - if (sv_players[i] == NULL || !client_connected(sv_players[i])) - { - continue; - } - - if (!recvwindow[recv_index][i].active) - { - /* We do not have this player's ticcmd, so we cannot generate a - * complete command yet. - */ - - return; - } - - ++num_players; - } - - /* If this is a game with only a single player in it, we might - * be sending a ticcmd set containing 0 ticcmds. This is fine; - * however, there's nothing to stop the game running on ahead - * and never stopping. Don't let the server get too far ahead - * of the client. - */ - - if (num_players == 0 && client->sendseq > recvwindow_start + 10) - { - return; - } - - /* We have all data we need to generate a command for this tic. */ - - cmd.seq = client->sendseq; - - /* Add ticcmds from all players */ - - cmd.latency = 0; - - for (i = 0; i < CONFIG_GAMES_NXDOOM_NET_MAXPLAYERS; ++i) - { - net_client_recv_t *recvobj; - - if (sv_players[i] == client) - { - /* Not the player we are sending to */ - - cmd.playeringame[i] = false; - continue; - } - - if (sv_players[i] == NULL || !recvwindow[recv_index][i].active) - { - cmd.playeringame[i] = false; - continue; - } - - cmd.playeringame[i] = true; - - recvobj = &recvwindow[recv_index][i]; - - cmd.cmds[i] = recvobj->diff; - - if (recvobj->latency > cmd.latency) cmd.latency = recvobj->latency; - } - - /* Add into the queue */ - - client->sendqueue[client->sendseq % - CONFIG_GAMES_NXDOOM_NET_BACKUPTICS] = cmd; - - /* Transmit the new tic to the client */ - - starttic = client->sendseq - sv_settings.extratics; - endtic = client->sendseq; - - if (starttic < 0) starttic = 0; - - net_log_info("server: send tics %d-%d to %s", starttic, endtic, - net_addr_to_string(client->addr)); - net_sv_send_tics(client, starttic, endtic); - - ++client->sendseq; -} - -/* Called when all players have disconnected. Return to listening for - * players to start a new game, and disconnect any drones still connected. - */ - -static void net_sv_game_ended(void) -{ - int i; - - server_state = SERVER_WAITING_LAUNCH; - sv_gamemode = indetermined; - - for (i = 0; i < MAXNETNODES; ++i) - { - if (clients[i].active) - { - net_sv_disconnect_client(&clients[i]); - } - } -} - -/* Prevent against deadlock: resend requests are usually only - * triggered if we miss a packet and receive the next one. - * If we miss a whole load of packets, we can end up in a - * deadlock situation where the client will not send any more. - * If we don't receive any game data in a while, trigger a resend - * request for the next tic we're expecting. - */ - -static void net_sv_check_deadlock(net_client_t *client) -{ - int nowtime; - int i; - - /* Don't expect game data from clients. */ - - if (client->drone) - { - return; - } - - nowtime = i_get_time_ms(); - - /* If we haven't received anything for a long time, it may be a deadlock. */ - - if (nowtime - client->last_gamedata_time > 1000) - { - net_log_warn("server: no gamedata from %s since %d - deadlock?", - net_addr_to_string(client->addr), - client->last_gamedata_time); - - /* Search the receive window for the first tic we are expecting - * from this player. - */ - - for (i = 0; i < CONFIG_GAMES_NXDOOM_NET_BACKUPTICS; ++i) - { - if (!recvwindow[i][client->player_number].active) - { - net_log_warn( - "server: deadlock: sending resend request for %d-%d", - recvwindow_start + i, recvwindow_start + i + 5); - - /* Found a tic we haven't received. Send a resend request. */ - - net_sv_send_resend_request(client, recvwindow_start + i, - recvwindow_start + i + 5); - - client->last_gamedata_time = nowtime; - break; - } - } - - /* If we sent a resend request to break the deadlock, also trigger a - * resend of any tics we have sitting in the send queue, in case the - * client is blocked waiting on tics from us that have been lost. - * This fixes deadlock with some older clients which do not send - * resends to break deadlock. - */ - - if (i < CONFIG_GAMES_NXDOOM_NET_BACKUPTICS && - client->sendseq > client->acknowledged) - { - net_log_warn("server: also resending tics %d-%d to break deadlock", - client->acknowledged, client->sendseq - 1); - net_sv_send_tics(client, client->acknowledged, - client->sendseq - 1); - } - } -} - -/* Perform any needed action on a client */ - -static void net_sv_run_client(net_client_t *client) -{ - /* Run common code */ - - net_conn_run(&client->connection); - - if (client->connection.state == NET_CONN_STATE_DISCONNECTED && - client->connection.disconnect_reason == NET_DISCONNECT_TIMEOUT) - { - net_log_warn("server: client at %s timed out", - net_addr_to_string(client->addr)); - net_sv_broadcast_message("Client '%s' timed out and disconnected", - client->name); - } - - /* Is this client disconnected? */ - - if (client->connection.state == NET_CONN_STATE_DISCONNECTED) - { - client->active = false; - - /* If we were about to start a game, any player disconnecting - * should cause an abort. - */ - - if (server_state == SERVER_WAITING_START && !client->drone) - { - net_sv_broadcast_message("Game startup aborted because " - "player '%s' disconnected.", - client->name); - net_sv_game_ended(); - } - - free(client->name); - net_release_address(client->addr); - - /* Are there any clients left connected? If not, return the - * server to the waiting-for-players state. - * - * Disconnect any drones still connected. - */ - - if (net_sv_num_players() <= 0) - { - net_log_info("server: no player clients left, game ended"); - net_sv_game_ended(); - } - } - - if (!client_connected(client)) - { - /* client has not yet finished connecting */ - - return; - } - - if (server_state == SERVER_WAITING_LAUNCH) - { - /* Waiting for the game to start */ - - /* Send information once every second */ - - if (client->last_send_time < 0 || - i_get_time_ms() - client->last_send_time > 1000) - { - net_sv_send_waiting_data(client); - client->last_send_time = i_get_time_ms(); - } - } - - if (server_state == SERVER_IN_GAME) - { - net_sv_pump_send_queue(client); - net_sv_check_deadlock(client); - } -} - -static void update_master_server(void) -{ - unsigned int now; - - now = i_get_time_ms(); - - /* The address of the master server can change. Periodically - * re-resolve the master server to update. - */ - - if (now - master_resolve_time > MASTER_RESOLVE_PERIOD * 1000) - { - net_addr_t *new_addr; - - new_addr = net_query_resolve_master(server_context); - net_release_address(master_server); - master_server = new_addr; - - master_resolve_time = now; - } - - /* Possibly refresh our registration with the master server. */ - - if (now - master_refresh_time > MASTER_REFRESH_PERIOD * 1000) - { - net_query_add_to_master(master_server); - master_refresh_time = now; - } -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/* Add a network module to the server context */ - -void net_sv_add_module(net_module_t *module) -{ - module->init_server(); - net_add_module(server_context, module); -} - -/* Initialize server and wait for connections */ - -void net_sv_init(void) -{ - int i; - - /* initialize send/receive context */ - - server_context = net_new_context(); - - /* no clients yet */ - - for (i = 0; i < MAXNETNODES; ++i) - { - clients[i].active = false; - } - - net_sv_assign_players(); - - server_state = SERVER_WAITING_LAUNCH; - sv_gamemode = indetermined; - server_initialized = true; -} - -void net_sv_register_with_master(void) -{ - /* @category net - * - * When running a server, don't register with the global master server. - * Implies -server. - */ - - if (!m_check_parm("-privateserver")) - { - master_server = net_query_resolve_master(server_context); - } - else - { - master_server = NULL; - } - - /* Send request. */ - - if (master_server != NULL) - { - net_query_add_to_master(master_server); - master_refresh_time = i_get_time_ms(); - master_resolve_time = master_refresh_time; - } -} - -/* Run server code to check for new packets/send packets as the server - * requires - */ - -void net_sv_run(void) -{ - net_addr_t *addr; - net_packet_t *packet; - int i; - - if (!server_initialized) - { - return; - } - - while (net_recv_packet(server_context, &addr, &packet)) - { - net_sv_packet(packet, addr); - net_free_packet(packet); - net_release_address(addr); - } - - if (master_server != NULL) - { - update_master_server(); - } - - /* "Run" any clients that may have things to do, independent of responses - * to received packets - */ - - for (i = 0; i < MAXNETNODES; ++i) - { - if (clients[i].active) - { - net_sv_run_client(&clients[i]); - } - } - - switch (server_state) - { - case SERVER_WAITING_LAUNCH: - break; - - case SERVER_WAITING_START: - check_start_game(); - break; - - case SERVER_IN_GAME: - net_sv_advance_window(); - - for (i = 0; i < CONFIG_GAMES_NXDOOM_NET_MAXPLAYERS; ++i) - { - if (sv_players[i] != NULL && client_connected(sv_players[i])) - { - net_sv_check_resends(sv_players[i]); - } - } - break; - } -} - -void net_sv_shutdown(void) -{ - int i; - boolean running; - int start_time; - - if (!server_initialized) - { - return; - } - - fprintf(stderr, "SV: Shutting down server...\n"); - - /* Disconnect all clients */ - - for (i = 0; i < MAXNETNODES; ++i) - { - if (clients[i].active) - { - net_sv_disconnect_client(&clients[i]); - } - } - - /* Wait for all clients to finish disconnecting */ - - start_time = i_get_time_ms(); - running = true; - - while (running) - { - /* Check if any clients are still not finished */ - - running = false; - - for (i = 0; i < MAXNETNODES; ++i) - { - if (clients[i].active) - { - running = true; - } - } - - /* Timed out? */ - - if (i_get_time_ms() - start_time > 5000) - { - running = false; - fprintf(stderr, - "SV: Timed out waiting for clients to disconnect.\n"); - } - - /* Run the client code in case this is a loopback client. */ - - net_cl_run(); - net_sv_run(); - - /* Don't hog the CPU */ - - usleep(1000); - } -} diff --git a/games/NXDoom/src/net_server.h b/games/NXDoom/src/net_server.h deleted file mode 100644 index 9d1db98b9..000000000 --- a/games/NXDoom/src/net_server.h +++ /dev/null @@ -1,51 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/net_server.h - * - * SPDX-License-Identifier: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * Network server code - * - ****************************************************************************/ - -#ifndef NET_SERVER_H -#define NET_SERVER_H - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/* initialize server and wait for connections */ - -void net_sv_init(void); - -/* run server: check for new packets received etc. */ - -void net_sv_run(void); - -/* Shut down the server - * Blocks until all clients disconnect, or until a 5 second timeout - */ - -void net_sv_shutdown(void); - -/* Add a network module to the context used by the server */ - -void net_sv_add_module(net_module_t *module); - -/* Register server with master server. */ - -void net_sv_register_with_master(void); - -#endif /* NET_SERVER_H */ diff --git a/games/NXDoom/src/net_structrw.c b/games/NXDoom/src/net_structrw.c deleted file mode 100644 index 371aa4f7a..000000000 --- a/games/NXDoom/src/net_structrw.c +++ /dev/null @@ -1,714 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/net_structrw.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * Reading and writing various structures into packets - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include - -#include "doomtype.h" -#include "i_system.h" -#include "m_misc.h" -#include "net_packet.h" -#include "net_structrw.h" - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -struct protocol_name -{ - net_protocol_t protocol; - const char *name; -}; - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/* String names for the enum values in net_protocol_t, which are what is - * sent over the wire. Every enum value must have an entry in this list. - */ - -static struct protocol_name g_protocol_names[] = -{ - {NET_PROTOCOL_CHOCOLATE_DOOM_0, "CHOCOLATE_DOOM_0"}, -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static boolean net_read_blob(net_packet_t *packet, uint8_t *buf, size_t len) -{ - unsigned int b; - int i; - - for (i = 0; i < len; ++i) - { - if (!net_read_int8(packet, &b)) - { - return false; - } - - buf[i] = b; - } - - return true; -} - -static void net_write_blob(net_packet_t *packet, uint8_t *buf, size_t len) -{ - int i; - - for (i = 0; i < len; ++i) - { - net_write_int8(packet, buf[i]); - } -} - -static net_protocol_t parse_protocol_name(const char *name) -{ - int i; - - for (i = 0; i < arrlen(g_protocol_names); ++i) - { - if (!strcmp(g_protocol_names[i].name, name)) - { - return g_protocol_names[i].protocol; - } - } - - return NET_PROTOCOL_UNKNOWN; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -void net_write_connect_data(net_packet_t *packet, net_connect_data_t *data) -{ - net_write_int8(packet, data->gamemode); - net_write_int8(packet, data->gamemission); - net_write_int8(packet, data->lowres_turn); - net_write_int8(packet, data->drone); - net_write_int8(packet, data->max_players); - net_write_int8(packet, data->is_freedoom); - net_write_sha1_sum(packet, data->wad_sha1sum); - net_write_sha1_sum(packet, data->deh_sha1sum); - net_write_int8(packet, data->player_class); -} - -boolean net_read_connect_data(net_packet_t *packet, net_connect_data_t *data) -{ - return net_read_int8(packet, (unsigned int *)&data->gamemode) && - net_read_int8(packet, (unsigned int *)&data->gamemission) && - net_read_int8(packet, (unsigned int *)&data->lowres_turn) && - net_read_int8(packet, (unsigned int *)&data->drone) && - net_read_int8(packet, (unsigned int *)&data->max_players) && - net_read_int8(packet, (unsigned int *)&data->is_freedoom) && - net_read_sha1_sum(packet, data->wad_sha1sum) && - net_read_sha1_sum(packet, data->deh_sha1sum) && - net_read_int8(packet, (unsigned int *)&data->player_class); -} - -void net_write_settings(net_packet_t *packet, net_gamesettings_t *settings) -{ - int i; - - net_write_int8(packet, settings->ticdup); - net_write_int8(packet, settings->extratics); - net_write_int8(packet, settings->deathmatch); - net_write_int8(packet, settings->nomonsters); - net_write_int8(packet, settings->fast_monsters); - net_write_int8(packet, settings->respawn_monsters); - net_write_int8(packet, settings->episode); - net_write_int8(packet, settings->map); - net_write_int8(packet, settings->skill); - net_write_int8(packet, settings->gameversion); - net_write_int8(packet, settings->lowres_turn); - net_write_int8(packet, settings->new_sync); - net_write_int32(packet, settings->timelimit); - net_write_int8(packet, settings->loadgame); - net_write_int8(packet, settings->random); - net_write_int8(packet, settings->num_players); - net_write_int8(packet, settings->consoleplayer); - - for (i = 0; i < settings->num_players; ++i) - { - net_write_int8(packet, settings->player_classes[i]); - } -} - -boolean net_read_settings(net_packet_t *packet, net_gamesettings_t *settings) -{ - boolean success; - int i; - - success = - net_read_int8(packet, (unsigned int *)&settings->ticdup) && - net_read_int8(packet, (unsigned int *)&settings->extratics) && - net_read_int8(packet, (unsigned int *)&settings->deathmatch) && - net_read_int8(packet, (unsigned int *)&settings->nomonsters) && - net_read_int8(packet, (unsigned int *)&settings->fast_monsters) && - net_read_int8(packet, (unsigned int *)&settings->respawn_monsters) && - net_read_int8(packet, (unsigned int *)&settings->episode) && - net_read_int8(packet, (unsigned int *)&settings->map) && - net_read_sint8(packet, &settings->skill) && - net_read_int8(packet, (unsigned int *)&settings->gameversion) && - net_read_int8(packet, (unsigned int *)&settings->lowres_turn) && - net_read_int8(packet, (unsigned int *)&settings->new_sync) && - net_read_int32(packet, (unsigned int *)&settings->timelimit) && - net_read_sint8(packet, (signed int *)&settings->loadgame) && - net_read_int8(packet, (unsigned int *)&settings->random) && - net_read_int8(packet, (unsigned int *)&settings->num_players) && - net_read_sint8(packet, (signed int *)&settings->consoleplayer); - - if (!success) - { - return false; - } - - for (i = 0; - i < settings->num_players && i < CONFIG_GAMES_NXDOOM_NET_MAXPLAYERS; - ++i) - { - if (!net_read_int8(packet, - (unsigned int *)&settings->player_classes[i])) - { - return false; - } - } - - return true; -} - -boolean net_read_query_data(net_packet_t *packet, net_querydata_t *query) -{ - boolean success; - - query->version = net_read_safe_string(packet); - - success = query->version != NULL && - net_read_int8(packet, (unsigned int *)&query->server_state) && - net_read_int8(packet, (unsigned int *)&query->num_players) && - net_read_int8(packet, (unsigned int *)&query->max_players) && - net_read_int8(packet, (unsigned int *)&query->gamemode) && - net_read_int8(packet, (unsigned int *)&query->gamemission); - - if (!success) - { - return false; - } - - query->description = net_read_safe_string(packet); - - /* We read the list of protocols supported by the server. However, - * old versions of Chocolate Doom do not support this field; it is - * okay if it cannot be successfully read. - */ - - query->protocol = net_read_protocol_list(packet); - - return query->description != NULL; -} - -void net_write_query_data(net_packet_t *packet, net_querydata_t *query) -{ - net_write_string(packet, query->version); - net_write_int8(packet, query->server_state); - net_write_int8(packet, query->num_players); - net_write_int8(packet, query->max_players); - net_write_int8(packet, query->gamemode); - net_write_int8(packet, query->gamemission); - net_write_string(packet, query->description); - - /* Write a list of all supported protocols. Note that the query->protocol - * field is ignored here; it is only used when receiving. - */ - - net_write_protocol_list(packet); -} - -void net_write_ticcmd_diff(net_packet_t *packet, net_ticdiff_t *diff, - boolean lowres_turn) -{ - /* Header */ - - net_write_int8(packet, diff->diff); - - /* Write the fields which are enabled: */ - - if (diff->diff & NET_TICDIFF_FORWARD) - net_write_int8(packet, diff->cmd.forwardmove); - if (diff->diff & NET_TICDIFF_SIDE) - net_write_int8(packet, diff->cmd.sidemove); - if (diff->diff & NET_TICDIFF_TURN) - { - if (lowres_turn) - { - net_write_int8(packet, diff->cmd.angleturn / 256); - } - else - { - net_write_int16(packet, diff->cmd.angleturn); - } - } - - if (diff->diff & NET_TICDIFF_BUTTONS) - net_write_int8(packet, diff->cmd.buttons); - if (diff->diff & NET_TICDIFF_CONSISTANCY) - net_write_int8(packet, diff->cmd.consistency); - if (diff->diff & NET_TICDIFF_CHATCHAR) - net_write_int8(packet, diff->cmd.chatchar); - if (diff->diff & NET_TICDIFF_RAVEN) - { - net_write_int8(packet, diff->cmd.lookfly); - net_write_int8(packet, diff->cmd.arti); - } - - if (diff->diff & NET_TICDIFF_STRIFE) - { - net_write_int8(packet, diff->cmd.buttons2); - net_write_int16(packet, diff->cmd.inventory); - } -} - -boolean net_read_ticcmd_diff(net_packet_t *packet, net_ticdiff_t *diff, - boolean lowres_turn) -{ - unsigned int val; - signed int sval; - - /* Read header */ - - if (!net_read_int8(packet, &diff->diff)) return false; - - /* Read fields */ - - if (diff->diff & NET_TICDIFF_FORWARD) - { - if (!net_read_sint8(packet, &sval)) return false; - diff->cmd.forwardmove = sval; - } - - if (diff->diff & NET_TICDIFF_SIDE) - { - if (!net_read_sint8(packet, &sval)) return false; - diff->cmd.sidemove = sval; - } - - if (diff->diff & NET_TICDIFF_TURN) - { - if (lowres_turn) - { - if (!net_read_sint8(packet, &sval)) return false; - diff->cmd.angleturn = sval * 256; - } - else - { - if (!net_read_sint16(packet, &sval)) return false; - diff->cmd.angleturn = sval; - } - } - - if (diff->diff & NET_TICDIFF_BUTTONS) - { - if (!net_read_int8(packet, &val)) return false; - diff->cmd.buttons = val; - } - - if (diff->diff & NET_TICDIFF_CONSISTANCY) - { - if (!net_read_int8(packet, &val)) return false; - diff->cmd.consistency = val; - } - - if (diff->diff & NET_TICDIFF_CHATCHAR) - { - if (!net_read_int8(packet, &val)) return false; - diff->cmd.chatchar = val; - } - - if (diff->diff & NET_TICDIFF_RAVEN) - { - if (!net_read_int8(packet, &val)) return false; - diff->cmd.lookfly = val; - - if (!net_read_int8(packet, &val)) return false; - diff->cmd.arti = val; - } - - if (diff->diff & NET_TICDIFF_STRIFE) - { - if (!net_read_int8(packet, &val)) return false; - diff->cmd.buttons2 = val; - - if (!net_read_int16(packet, &val)) return false; - diff->cmd.inventory = val; - } - - return true; -} - -void net_ticcmd_diff(ticcmd_t *tic1, ticcmd_t *tic2, net_ticdiff_t *diff) -{ - diff->diff = 0; - diff->cmd = *tic2; - - if (tic1->forwardmove != tic2->forwardmove) - diff->diff |= NET_TICDIFF_FORWARD; - if (tic1->sidemove != tic2->sidemove) diff->diff |= NET_TICDIFF_SIDE; - if (tic1->angleturn != tic2->angleturn) diff->diff |= NET_TICDIFF_TURN; - if (tic1->buttons != tic2->buttons) diff->diff |= NET_TICDIFF_BUTTONS; - if (tic1->consistency != tic2->consistency) - diff->diff |= NET_TICDIFF_CONSISTANCY; - if (tic2->chatchar != 0) diff->diff |= NET_TICDIFF_CHATCHAR; - - /* Heretic/Hexen-specific */ - - if (tic1->lookfly != tic2->lookfly || tic2->arti != 0) - diff->diff |= NET_TICDIFF_RAVEN; - - /* Strife-specific */ - - if (tic1->buttons2 != tic2->buttons2 || tic2->inventory != 0) - diff->diff |= NET_TICDIFF_STRIFE; -} - -void net_ticcmd_patch(ticcmd_t *src, net_ticdiff_t *diff, ticcmd_t *dest) -{ - memmove(dest, src, sizeof(ticcmd_t)); - - /* Apply the diff */ - - if (diff->diff & NET_TICDIFF_FORWARD) - dest->forwardmove = diff->cmd.forwardmove; - if (diff->diff & NET_TICDIFF_SIDE) dest->sidemove = diff->cmd.sidemove; - if (diff->diff & NET_TICDIFF_TURN) dest->angleturn = diff->cmd.angleturn; - if (diff->diff & NET_TICDIFF_BUTTONS) dest->buttons = diff->cmd.buttons; - if (diff->diff & NET_TICDIFF_CONSISTANCY) - dest->consistency = diff->cmd.consistency; - - if (diff->diff & NET_TICDIFF_CHATCHAR) - dest->chatchar = diff->cmd.chatchar; - else - dest->chatchar = 0; - - /* Heretic/Hexen specific: */ - - if (diff->diff & NET_TICDIFF_RAVEN) - { - dest->lookfly = diff->cmd.lookfly; - dest->arti = diff->cmd.arti; - } - else - { - dest->arti = 0; - } - - /* Strife-specific: */ - - if (diff->diff & NET_TICDIFF_STRIFE) - { - dest->buttons2 = diff->cmd.buttons2; - dest->inventory = diff->cmd.inventory; - } - else - { - dest->inventory = 0; - } -} - -/* net_full_ticcmd_t */ - -boolean net_read_full_ticcmd(net_packet_t *packet, net_full_ticcmd_t *cmd, - boolean lowres_turn) -{ - unsigned int bitfield; - int i; - - /* Latency */ - - if (!net_read_sint16(packet, &cmd->latency)) - { - return false; - } - - /* Regenerate playeringame from the "header" bitfield */ - - if (!net_read_int8(packet, &bitfield)) - { - return false; - } - - for (i = 0; i < CONFIG_GAMES_NXDOOM_NET_MAXPLAYERS; ++i) - { - cmd->playeringame[i] = (bitfield & (1 << i)) != 0; - } - - /* Read cmds */ - - for (i = 0; i < CONFIG_GAMES_NXDOOM_NET_MAXPLAYERS; ++i) - { - if (cmd->playeringame[i]) - { - if (!net_read_ticcmd_diff(packet, &cmd->cmds[i], lowres_turn)) - { - return false; - } - } - } - - return true; -} - -void net_write_full_ticcmd(net_packet_t *packet, net_full_ticcmd_t *cmd, - boolean lowres_turn) -{ - unsigned int bitfield; - int i; - - /* Write the latency */ - - net_write_int16(packet, cmd->latency); - - /* Write "header" byte indicating which players are active - * in this ticcmd - */ - - bitfield = 0; - - for (i = 0; i < CONFIG_GAMES_NXDOOM_NET_MAXPLAYERS; ++i) - { - if (cmd->playeringame[i]) - { - bitfield |= 1 << i; - } - } - - net_write_int8(packet, bitfield); - - /* Write player ticcmds */ - - for (i = 0; i < CONFIG_GAMES_NXDOOM_NET_MAXPLAYERS; ++i) - { - if (cmd->playeringame[i]) - { - net_write_ticcmd_diff(packet, &cmd->cmds[i], lowres_turn); - } - } -} - -void net_write_wait_data(net_packet_t *packet, net_waitdata_t *data) -{ - int i; - - net_write_int8(packet, data->num_players); - net_write_int8(packet, data->num_drones); - net_write_int8(packet, data->ready_players); - net_write_int8(packet, data->max_players); - net_write_int8(packet, data->is_controller); - net_write_int8(packet, data->consoleplayer); - - for (i = 0; - i < data->num_players && i < CONFIG_GAMES_NXDOOM_NET_MAXPLAYERS; - ++i) - { - net_write_string(packet, data->player_names[i]); - net_write_string(packet, data->player_addrs[i]); - } - - net_write_sha1_sum(packet, data->wad_sha1sum); - net_write_sha1_sum(packet, data->deh_sha1sum); - net_write_int8(packet, data->is_freedoom); -} - -boolean net_read_wait_data(net_packet_t *packet, net_waitdata_t *data) -{ - int i; - char *s; - - if (!net_read_int8(packet, (unsigned int *)&data->num_players) || - !net_read_int8(packet, (unsigned int *)&data->num_drones) || - !net_read_int8(packet, (unsigned int *)&data->ready_players) || - !net_read_int8(packet, (unsigned int *)&data->max_players) || - !net_read_int8(packet, (unsigned int *)&data->is_controller) || - !net_read_sint8(packet, &data->consoleplayer)) - { - return false; - } - - for (i = 0; - i < data->num_players && i < CONFIG_GAMES_NXDOOM_NET_MAXPLAYERS; - ++i) - { - s = net_read_string(packet); - - if (s == NULL || strlen(s) >= CONFIG_GAMES_NXDOOM_NET_MAXPLAYERNAME) - { - return false; - } - - m_str_copy(data->player_names[i], s, - CONFIG_GAMES_NXDOOM_NET_MAXPLAYERNAME); - - s = net_read_string(packet); - - if (s == NULL || strlen(s) >= CONFIG_GAMES_NXDOOM_NET_MAXPLAYERNAME) - { - return false; - } - - m_str_copy(data->player_addrs[i], s, - CONFIG_GAMES_NXDOOM_NET_MAXPLAYERNAME); - } - - return net_read_sha1_sum(packet, data->wad_sha1sum) && - net_read_sha1_sum(packet, data->deh_sha1sum) && - net_read_int8(packet, (unsigned int *)&data->is_freedoom); -} - -boolean net_read_sha1_sum(net_packet_t *packet, sha1_digest_t digest) -{ - return net_read_blob(packet, digest, sizeof(sha1_digest_t)); -} - -void net_write_sha1_sum(net_packet_t *packet, sha1_digest_t digest) -{ - net_write_blob(packet, digest, sizeof(sha1_digest_t)); -} - -boolean net_read_prng_seed(net_packet_t *packet, prng_seed_t seed) -{ - return net_read_blob(packet, seed, sizeof(prng_seed_t)); -} - -void net_write_prng_seed(net_packet_t *packet, prng_seed_t seed) -{ - net_write_blob(packet, seed, sizeof(prng_seed_t)); -} - -/* net_read_protocol reads a single string-format protocol name from the - * given packet, returning NET_PROTOCOL_UNKNOWN if the string describes an - * unknown protocol. - */ - -net_protocol_t net_read_protocol(net_packet_t *packet) -{ - const char *name; - - name = net_read_string(packet); - if (name == NULL) - { - return NET_PROTOCOL_UNKNOWN; - } - - return parse_protocol_name(name); -} - -/* net_write_protocol writes a single string-format protocol name to a - * packet. - */ - -void net_write_protocol(net_packet_t *packet, net_protocol_t protocol) -{ - int i; - - for (i = 0; i < arrlen(g_protocol_names); ++i) - { - if (g_protocol_names[i].protocol == protocol) - { - net_write_string(packet, g_protocol_names[i].name); - return; - } - } - - /* If you add an entry to the net_protocol_t enum, a corresponding entry - * must be added to the protocol_names list. - */ - - i_error("net_write_protocol: protocol %d missing from protocol_names " - "list; please add it.", - protocol); -} - -/* net_read_protocol_list reads a list of string-format protocol names from - * the given packet, returning a single protocol number. The protocol that is - * returned is the last protocol in the list that is a supported protocol. If - * no recognized protocols are read, NET_PROTOCOL_UNKNOWN is returned. - */ - -net_protocol_t net_read_protocol_list(net_packet_t *packet) -{ - net_protocol_t result; - unsigned int num_protocols; - int i; - - if (!net_read_int8(packet, &num_protocols)) - { - return NET_PROTOCOL_UNKNOWN; - } - - result = NET_PROTOCOL_UNKNOWN; - - for (i = 0; i < num_protocols; ++i) - { - net_protocol_t p; - const char *name; - - name = net_read_string(packet); - if (name == NULL) - { - return NET_PROTOCOL_UNKNOWN; - } - - p = parse_protocol_name(name); - if (p != NET_PROTOCOL_UNKNOWN) - { - result = p; - } - } - - return result; -} - -/* net_write_protocol_list writes a list of string-format protocol names into - * the given packet, all the supported protocols in the net_protocol_t enum. - * This is slightly different to other functions in this file, in that there - * is nothing the caller can "choose" to write; the built-in list of all - * protocols is always sent. - */ - -void net_write_protocol_list(net_packet_t *packet) -{ - int i; - - net_write_int8(packet, NET_NUM_PROTOCOLS); - - for (i = 0; i < NET_NUM_PROTOCOLS; ++i) - { - net_write_protocol(packet, i); - } -} diff --git a/games/NXDoom/src/net_structrw.h b/games/NXDoom/src/net_structrw.h deleted file mode 100644 index 2a924173c..000000000 --- a/games/NXDoom/src/net_structrw.h +++ /dev/null @@ -1,80 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/net_structrw.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - ****************************************************************************/ - -#ifndef NET_STRUCTRW_H -#define NET_STRUCTRW_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "aes_prng.h" -#include "net_defs.h" -#include "net_packet.h" -#include "sha1.h" - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -void net_write_connect_data(net_packet_t *packet, net_connect_data_t *data); -boolean net_read_connect_data(net_packet_t *packet, - net_connect_data_t *data); - -extern void net_write_settings(net_packet_t *packet, - net_gamesettings_t *settings); -extern boolean net_read_settings(net_packet_t *packet, - net_gamesettings_t *settings); - -extern void net_write_query_data(net_packet_t *packet, - net_querydata_t *querydata); -extern boolean net_read_query_data(net_packet_t *packet, - net_querydata_t *querydata); - -extern void net_write_ticcmd_diff(net_packet_t *packet, net_ticdiff_t *diff, - boolean lowres_turn); -extern boolean net_read_ticcmd_diff(net_packet_t *packet, - net_ticdiff_t *diff, boolean lowres_turn); -extern void net_ticcmd_diff(ticcmd_t *tic1, ticcmd_t *tic2, - net_ticdiff_t *diff); -extern void net_ticcmd_patch(ticcmd_t *src, net_ticdiff_t *diff, - ticcmd_t *dest); - -boolean net_read_full_ticcmd(net_packet_t *packet, net_full_ticcmd_t *cmd, - boolean lowres_turn); -void net_write_full_ticcmd(net_packet_t *packet, net_full_ticcmd_t *cmd, - boolean lowres_turn); - -boolean net_read_sha1_sum(net_packet_t *packet, sha1_digest_t digest); -void net_write_sha1_sum(net_packet_t *packet, sha1_digest_t digest); - -void net_write_wait_data(net_packet_t *packet, net_waitdata_t *data); -boolean net_read_wait_data(net_packet_t *packet, net_waitdata_t *data); - -boolean net_read_prng_seed(net_packet_t *packet, prng_seed_t seed); -void net_write_prng_seed(net_packet_t *packet, prng_seed_t seed); - -/* Protocol list exchange. */ - -net_protocol_t net_read_protocol(net_packet_t *packet); -void net_write_protocol(net_packet_t *packet, net_protocol_t protocol); -net_protocol_t net_read_protocol_list(net_packet_t *packet); -void net_write_protocol_list(net_packet_t *packet); - -#endif /* NET_STRUCTRW_H */ diff --git a/games/NXDoom/src/p_rejectpad.c b/games/NXDoom/src/p_rejectpad.c deleted file mode 100644 index 3099d59f9..000000000 --- a/games/NXDoom/src/p_rejectpad.c +++ /dev/null @@ -1,96 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/p_rejectpad.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Padding of Reject Lump - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -#include "m_argv.h" -#include "p_rejectpad.h" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/* Pad the REJECT lump with extra data when the lump is too small, - * to simulate a REJECT buffer overflow in Vanilla Doom. - */ - -void pad_reject_array(byte *array, unsigned int len, int totallines) -{ - unsigned int i; - unsigned int byte_num; - byte *dest; - unsigned int padvalue; - - /* Values to pad the REJECT array with: */ - - unsigned int rejectpad[4] = - { - 0, /* Size */ - 0, /* Part of z_zone block header */ - 50, /* PU_LEVEL */ - 0x1d4a11 /* DOOM_CONST_ZONEID */ - }; - - rejectpad[0] = ((totallines * 4 + 3) & ~3) + 24; - - /* Copy values from rejectpad into the destination array. */ - - dest = array; - - for (i = 0; i < len && i < sizeof(rejectpad); ++i) - { - byte_num = i % 4; - *dest = (rejectpad[i / 4] >> (byte_num * 8)) & 0xff; - ++dest; - } - - /* We only have a limited pad size. Print a warning if the - * REJECT lump is too small. - */ - - if (len > sizeof(rejectpad)) - { - fprintf(stderr, - "pad_reject_array: REJECT lump too short to pad! (%u > %i)\n", - len, (int)sizeof(rejectpad)); - - /* Pad remaining space with 0 (or 0xff, if specified on command line). - */ - - if (m_check_parm("-reject_pad_with_ff")) - { - padvalue = 0xff; - } - else - { - padvalue = 0x00; - } - - memset(array + sizeof(rejectpad), padvalue, len - sizeof(rejectpad)); - } -} diff --git a/games/NXDoom/src/p_rejectpad.h b/games/NXDoom/src/p_rejectpad.h deleted file mode 100644 index adb0372dd..000000000 --- a/games/NXDoom/src/p_rejectpad.h +++ /dev/null @@ -1,41 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/p_rejectpad.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Padding of Reject Lump - * - ****************************************************************************/ - -#ifndef __P_REJECTPAD__ -#define __P_REJECTPAD__ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "doomtype.h" - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/* Padding of Reject Lump */ - -void pad_reject_array(byte *array, unsigned int len, int totallines); - -#endif /* __P_REJECTPAD__ */ diff --git a/games/NXDoom/src/sha1.h b/games/NXDoom/src/sha1.h deleted file mode 100644 index eb0f7c360..000000000 --- a/games/NXDoom/src/sha1.h +++ /dev/null @@ -1,59 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/sha1.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * SHA-1 digest. - * - ****************************************************************************/ - -#ifndef __SHA1_H__ -#define __SHA1_H__ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include "doomtype.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define sha1_updatestring(ctx, str) \ - sha1update((ctx), (byte *)(str), strlen((str)) + 1) - -#define sha1_updateint32(ctx, val) \ - do \ - { \ - byte __sha1__tmp__buf[4]; \ - __sha1__tmp__buf[0] = ((val) >> 24) & 0xff; \ - __sha1__tmp__buf[1] = ((val) >> 16) & 0xff; \ - __sha1__tmp__buf[2] = ((val) >> 8) & 0xff; \ - __sha1__tmp__buf[3] = (val) & 0xff; \ - sha1update((ctx), __sha1__tmp__buf, 4); \ - } \ - while (0) - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -typedef byte sha1_digest_t[SHA1_DIGEST_LENGTH]; - -#endif /* __SHA1_H__ */ diff --git a/games/NXDoom/src/tables.c b/games/NXDoom/src/tables.c deleted file mode 100644 index 61f0198c3..000000000 --- a/games/NXDoom/src/tables.c +++ /dev/null @@ -1,2369 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/tables.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Lookup tables. - * Do not try to look them up :-). - * In the order of appearance: - * - * int finetangent[4096] - Tangens LUT. - * Should work with BAM fairly well (12 of 16bit, - * effectively, by shifting). - * - * int finesine[10240] - Sine lookup. - * Guess what, serves as cosine, too. - * Remarkable thing is, how to use BAMs with this? - * - * int tantoangle[2049] - ArcTan LUT, - * maps tan(angle) to angle fast. Gotta search. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "tables.h" - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -const fixed_t finetangent[4096] = -{ - -170910304, -56965752, -34178904, -24413316, -18988036, -15535599, - -13145455, -11392683, -10052327, -8994149, -8137527, -7429880, - -6835455, -6329090, -5892567, -5512368, -5178251, -4882318, - -4618375, -4381502, -4167737, -3973855, -3797206, -3635590, - -3487165, -3350381, -3223918, -3106651, -2997613, -2895966, - -2800983, -2712030, -2628549, -2550052, -2476104, -2406322, - -2340362, -2277919, -2218719, -2162516, -2109087, -2058233, - -2009771, -1963536, -1919378, -1877161, -1836758, -1798063, - -1760956, -1725348, -1691149, -1658278, -1626658, -1596220, - -1566898, -1538632, -1511367, -1485049, -1459630, -1435065, - -1411312, -1388330, -1366084, -1344537, -1323658, -1303416, - -1283783, -1264730, -1246234, -1228269, -1210813, -1193846, - -1177345, -1161294, -1145673, -1130465, -1115654, -1101225, - -1087164, -1073455, -1060087, -1047046, -1034322, -1021901, - -1009774, -997931, -986361, -975054, -964003, -953199, - -942633, -932298, -922186, -912289, -902602, -893117, - -883829, -874730, -865817, -857081, -848520, -840127, - -831898, -823827, -815910, -808143, -800521, -793041, - -785699, -778490, -771411, -764460, -757631, -750922, - -744331, -737853, -731486, -725227, -719074, -713023, - -707072, -701219, -695462, -689797, -684223, -678737, - -673338, -668024, -662792, -657640, -652568, -647572, - -642651, -637803, -633028, -628323, -623686, -619117, - -614613, -610174, -605798, -601483, -597229, -593033, - -588896, -584815, -580789, -576818, -572901, -569035, - -565221, -561456, -557741, -554074, -550455, -546881, - -543354, -539870, -536431, -533034, -529680, -526366, - -523094, -519861, -516667, -513512, -510394, -507313, - -504269, -501261, -498287, -495348, -492443, -489571, - -486732, -483925, -481150, -478406, -475692, -473009, - -470355, -467730, -465133, -462565, -460024, -457511, - -455024, -452564, -450129, -447720, -445337, -442978, - -440643, -438332, -436045, -433781, -431540, -429321, - -427125, -424951, -422798, -420666, -418555, -416465, - -414395, -412344, -410314, -408303, -406311, -404338, - -402384, -400448, -398530, -396630, -394747, -392882, - -391034, -389202, -387387, -385589, -383807, -382040, - -380290, -378555, -376835, -375130, -373440, -371765, - -370105, -368459, -366826, -365208, -363604, -362013, - -360436, -358872, -357321, -355783, -354257, -352744, - -351244, -349756, -348280, -346816, -345364, -343924, - -342495, -341078, -339671, -338276, -336892, -335519, - -334157, -332805, -331464, -330133, -328812, -327502, - -326201, -324910, -323629, -322358, -321097, -319844, - -318601, -317368, -316143, -314928, -313721, -312524, - -311335, -310154, -308983, -307819, -306664, -305517, - -304379, -303248, -302126, -301011, -299904, -298805, - -297714, -296630, -295554, -294485, -293423, -292369, - -291322, -290282, -289249, -288223, -287204, -286192, - -285186, -284188, -283195, -282210, -281231, -280258, - -279292, -278332, -277378, -276430, -275489, -274553, - -273624, -272700, -271782, -270871, -269965, -269064, - -268169, -267280, -266397, -265519, -264646, -263779, - -262917, -262060, -261209, -260363, -259522, -258686, - -257855, -257029, -256208, -255392, -254581, -253774, - -252973, -252176, -251384, -250596, -249813, -249035, - -248261, -247492, -246727, -245966, -245210, -244458, - -243711, -242967, -242228, -241493, -240763, -240036, - -239314, -238595, -237881, -237170, -236463, -235761, - -235062, -234367, -233676, -232988, -232304, -231624, - -230948, -230275, -229606, -228941, -228279, -227621, - -226966, -226314, -225666, -225022, -224381, -223743, - -223108, -222477, -221849, -221225, -220603, -219985, - -219370, -218758, -218149, -217544, -216941, -216341, - -215745, -215151, -214561, -213973, -213389, -212807, - -212228, -211652, -211079, -210509, -209941, -209376, - -208815, -208255, -207699, -207145, -206594, -206045, - -205500, -204956, -204416, -203878, -203342, -202809, - -202279, -201751, -201226, -200703, -200182, -199664, - -199149, -198636, -198125, -197616, -197110, -196606, - -196105, -195606, -195109, -194614, -194122, -193631, - -193143, -192658, -192174, -191693, -191213, -190736, - -190261, -189789, -189318, -188849, -188382, -187918, - -187455, -186995, -186536, -186080, -185625, -185173, - -184722, -184274, -183827, -183382, -182939, -182498, - -182059, -181622, -181186, -180753, -180321, -179891, - -179463, -179037, -178612, -178190, -177769, -177349, - -176932, -176516, -176102, -175690, -175279, -174870, - -174463, -174057, -173653, -173251, -172850, -172451, - -172053, -171657, -171263, -170870, -170479, -170089, - -169701, -169315, -168930, -168546, -168164, -167784, - -167405, -167027, -166651, -166277, -165904, -165532, - -165162, -164793, -164426, -164060, -163695, -163332, - -162970, -162610, -162251, -161893, -161537, -161182, - -160828, -160476, -160125, -159775, -159427, -159079, - -158734, -158389, -158046, -157704, -157363, -157024, - -156686, -156349, -156013, -155678, -155345, -155013, - -154682, -154352, -154024, -153697, -153370, -153045, - -152722, -152399, -152077, -151757, -151438, -151120, - -150803, -150487, -150172, -149859, -149546, -149235, - -148924, -148615, -148307, -148000, -147693, -147388, - -147084, -146782, -146480, -146179, -145879, -145580, - -145282, -144986, -144690, -144395, -144101, -143808, - -143517, -143226, -142936, -142647, -142359, -142072, - -141786, -141501, -141217, -140934, -140651, -140370, - -140090, -139810, -139532, -139254, -138977, -138701, - -138426, -138152, -137879, -137607, -137335, -137065, - -136795, -136526, -136258, -135991, -135725, -135459, - -135195, -134931, -134668, -134406, -134145, -133884, - -133625, -133366, -133108, -132851, -132594, -132339, - -132084, -131830, -131576, -131324, -131072, -130821, - -130571, -130322, -130073, -129825, -129578, -129332, - -129086, -128841, -128597, -128353, -128111, -127869, - -127627, -127387, -127147, -126908, -126669, -126432, - -126195, -125959, -125723, -125488, -125254, -125020, - -124787, -124555, -124324, -124093, -123863, -123633, - -123404, -123176, -122949, -122722, -122496, -122270, - -122045, -121821, -121597, -121374, -121152, -120930, - -120709, -120489, -120269, -120050, -119831, -119613, - -119396, -119179, -118963, -118747, -118532, -118318, - -118104, -117891, -117678, -117466, -117254, -117044, - -116833, -116623, -116414, -116206, -115998, -115790, - -115583, -115377, -115171, -114966, -114761, -114557, - -114354, -114151, -113948, -113746, -113545, -113344, - -113143, -112944, -112744, -112546, -112347, -112150, - -111952, -111756, -111560, -111364, -111169, -110974, - -110780, -110586, -110393, -110200, -110008, -109817, - -109626, -109435, -109245, -109055, -108866, -108677, - -108489, -108301, -108114, -107927, -107741, -107555, - -107369, -107184, -107000, -106816, -106632, -106449, - -106266, -106084, -105902, -105721, -105540, -105360, - -105180, -105000, -104821, -104643, -104465, -104287, - -104109, -103933, -103756, -103580, -103404, -103229, - -103054, -102880, -102706, -102533, -102360, -102187, - -102015, -101843, -101671, -101500, -101330, -101159, - -100990, -100820, -100651, -100482, -100314, -100146, - -99979, -99812, -99645, -99479, -99313, -99148, - -98982, -98818, -98653, -98489, -98326, -98163, - -98000, -97837, -97675, -97513, -97352, -97191, - -97030, -96870, -96710, -96551, -96391, -96233, - -96074, -95916, -95758, -95601, -95444, -95287, - -95131, -94975, -94819, -94664, -94509, -94354, - -94200, -94046, -93892, -93739, -93586, -93434, - -93281, -93129, -92978, -92826, -92675, -92525, - -92375, -92225, -92075, -91926, -91777, -91628, - -91480, -91332, -91184, -91036, -90889, -90742, - -90596, -90450, -90304, -90158, -90013, -89868, - -89724, -89579, -89435, -89292, -89148, -89005, - -88862, -88720, -88577, -88435, -88294, -88152, - -88011, -87871, -87730, -87590, -87450, -87310, - -87171, -87032, -86893, -86755, -86616, -86479, - -86341, -86204, -86066, -85930, -85793, -85657, - -85521, -85385, -85250, -85114, -84980, -84845, - -84710, -84576, -84443, -84309, -84176, -84043, - -83910, -83777, -83645, -83513, -83381, -83250, - -83118, -82987, -82857, -82726, -82596, -82466, - -82336, -82207, -82078, -81949, -81820, -81691, - -81563, -81435, -81307, -81180, -81053, -80925, - -80799, -80672, -80546, -80420, -80294, -80168, - -80043, -79918, -79793, -79668, -79544, -79420, - -79296, -79172, -79048, -78925, -78802, -78679, - -78557, -78434, -78312, -78190, -78068, -77947, - -77826, -77705, -77584, -77463, -77343, -77223, - -77103, -76983, -76864, -76744, -76625, -76506, - -76388, -76269, -76151, -76033, -75915, -75797, - -75680, -75563, -75446, -75329, -75213, -75096, - -74980, -74864, -74748, -74633, -74517, -74402, - -74287, -74172, -74058, -73944, -73829, -73715, - -73602, -73488, -73375, -73262, -73149, -73036, - -72923, -72811, -72699, -72587, -72475, -72363, - -72252, -72140, -72029, -71918, -71808, -71697, - -71587, -71477, -71367, -71257, -71147, -71038, - -70929, -70820, -70711, -70602, -70494, -70385, - -70277, -70169, -70061, -69954, -69846, -69739, - -69632, -69525, -69418, -69312, -69205, -69099, - -68993, -68887, -68781, -68676, -68570, -68465, - -68360, -68255, -68151, -68046, -67942, -67837, - -67733, -67629, -67526, -67422, -67319, -67216, - -67113, -67010, -66907, -66804, -66702, -66600, - -66498, -66396, -66294, -66192, -66091, -65989, - -65888, -65787, -65686, -65586, -65485, -65385, - -65285, -65185, -65085, -64985, -64885, -64786, - -64687, -64587, -64488, -64389, -64291, -64192, - -64094, -63996, -63897, -63799, -63702, -63604, - -63506, -63409, -63312, -63215, -63118, -63021, - -62924, -62828, -62731, -62635, -62539, -62443, - -62347, -62251, -62156, -62060, -61965, -61870, - -61775, -61680, -61585, -61491, -61396, -61302, - -61208, -61114, -61020, -60926, -60833, -60739, - -60646, -60552, -60459, -60366, -60273, -60181, - -60088, -59996, -59903, -59811, -59719, -59627, - -59535, -59444, -59352, -59261, -59169, -59078, - -58987, -58896, -58805, -58715, -58624, -58534, - -58443, -58353, -58263, -58173, -58083, -57994, - -57904, -57815, -57725, -57636, -57547, -57458, - -57369, -57281, -57192, -57104, -57015, -56927, - -56839, -56751, -56663, -56575, -56487, -56400, - -56312, -56225, -56138, -56051, -55964, -55877, - -55790, -55704, -55617, -55531, -55444, -55358, - -55272, -55186, -55100, -55015, -54929, -54843, - -54758, -54673, -54587, -54502, -54417, -54333, - -54248, -54163, -54079, -53994, -53910, -53826, - -53741, -53657, -53574, -53490, -53406, -53322, - -53239, -53156, -53072, -52989, -52906, -52823, - -52740, -52657, -52575, -52492, -52410, -52327, - -52245, -52163, -52081, -51999, -51917, -51835, - -51754, -51672, -51591, -51509, -51428, -51347, - -51266, -51185, -51104, -51023, -50942, -50862, - -50781, -50701, -50621, -50540, -50460, -50380, - -50300, -50221, -50141, -50061, -49982, -49902, - -49823, -49744, -49664, -49585, -49506, -49427, - -49349, -49270, -49191, -49113, -49034, -48956, - -48878, -48799, -48721, -48643, -48565, -48488, - -48410, -48332, -48255, -48177, -48100, -48022, - -47945, -47868, -47791, -47714, -47637, -47560, - -47484, -47407, -47331, -47254, -47178, -47102, - -47025, -46949, -46873, -46797, -46721, -46646, - -46570, -46494, -46419, -46343, -46268, -46193, - -46118, -46042, -45967, -45892, -45818, -45743, - -45668, -45593, -45519, -45444, -45370, -45296, - -45221, -45147, -45073, -44999, -44925, -44851, - -44778, -44704, -44630, -44557, -44483, -44410, - -44337, -44263, -44190, -44117, -44044, -43971, - -43898, -43826, -43753, -43680, -43608, -43535, - -43463, -43390, -43318, -43246, -43174, -43102, - -43030, -42958, -42886, -42814, -42743, -42671, - -42600, -42528, -42457, -42385, -42314, -42243, - -42172, -42101, -42030, -41959, -41888, -41817, - -41747, -41676, -41605, -41535, -41465, -41394, - -41324, -41254, -41184, -41113, -41043, -40973, - -40904, -40834, -40764, -40694, -40625, -40555, - -40486, -40416, -40347, -40278, -40208, -40139, - -40070, -40001, -39932, -39863, -39794, -39726, - -39657, -39588, -39520, -39451, -39383, -39314, - -39246, -39178, -39110, -39042, -38973, -38905, - -38837, -38770, -38702, -38634, -38566, -38499, - -38431, -38364, -38296, -38229, -38161, -38094, - -38027, -37960, -37893, -37826, -37759, -37692, - -37625, -37558, -37491, -37425, -37358, -37291, - -37225, -37158, -37092, -37026, -36959, -36893, - -36827, -36761, -36695, -36629, -36563, -36497, - -36431, -36365, -36300, -36234, -36168, -36103, - -36037, -35972, -35907, -35841, -35776, -35711, - -35646, -35580, -35515, -35450, -35385, -35321, - -35256, -35191, -35126, -35062, -34997, -34932, - -34868, -34803, -34739, -34675, -34610, -34546, - -34482, -34418, -34354, -34289, -34225, -34162, - -34098, -34034, -33970, -33906, -33843, -33779, - -33715, -33652, -33588, -33525, -33461, -33398, - -33335, -33272, -33208, -33145, -33082, -33019, - -32956, -32893, -32830, -32767, -32705, -32642, - -32579, -32516, -32454, -32391, -32329, -32266, - -32204, -32141, -32079, -32017, -31955, -31892, - -31830, -31768, -31706, -31644, -31582, -31520, - -31458, -31396, -31335, -31273, -31211, -31150, - -31088, -31026, -30965, -30904, -30842, -30781, - -30719, -30658, -30597, -30536, -30474, -30413, - -30352, -30291, -30230, -30169, -30108, -30048, - -29987, -29926, -29865, -29805, -29744, -29683, - -29623, -29562, -29502, -29441, -29381, -29321, - -29260, -29200, -29140, -29080, -29020, -28959, - -28899, -28839, -28779, -28719, -28660, -28600, - -28540, -28480, -28420, -28361, -28301, -28241, - -28182, -28122, -28063, -28003, -27944, -27884, - -27825, -27766, -27707, -27647, -27588, -27529, - -27470, -27411, -27352, -27293, -27234, -27175, - -27116, -27057, -26998, -26940, -26881, -26822, - -26763, -26705, -26646, -26588, -26529, -26471, - -26412, -26354, -26295, -26237, -26179, -26120, - -26062, -26004, -25946, -25888, -25830, -25772, - -25714, -25656, -25598, -25540, -25482, -25424, - -25366, -25308, -25251, -25193, -25135, -25078, - -25020, -24962, -24905, -24847, -24790, -24732, - -24675, -24618, -24560, -24503, -24446, -24389, - -24331, -24274, -24217, -24160, -24103, -24046, - -23989, -23932, -23875, -23818, -23761, -23704, - -23647, -23591, -23534, -23477, -23420, -23364, - -23307, -23250, -23194, -23137, -23081, -23024, - -22968, -22911, -22855, -22799, -22742, -22686, - -22630, -22573, -22517, -22461, -22405, -22349, - -22293, -22237, -22181, -22125, -22069, -22013, - -21957, -21901, -21845, -21789, -21733, -21678, - -21622, -21566, -21510, -21455, -21399, -21343, - -21288, -21232, -21177, -21121, -21066, -21010, - -20955, -20900, -20844, -20789, -20734, -20678, - -20623, -20568, -20513, -20457, -20402, -20347, - -20292, -20237, -20182, -20127, -20072, -20017, - -19962, -19907, -19852, -19797, -19742, -19688, - -19633, -19578, -19523, -19469, -19414, -19359, - -19305, -19250, -19195, -19141, -19086, -19032, - -18977, -18923, -18868, -18814, -18760, -18705, - -18651, -18597, -18542, -18488, -18434, -18380, - -18325, -18271, -18217, -18163, -18109, -18055, - -18001, -17946, -17892, -17838, -17784, -17731, - -17677, -17623, -17569, -17515, -17461, -17407, - -17353, -17300, -17246, -17192, -17138, -17085, - -17031, -16977, -16924, -16870, -16817, -16763, - -16710, -16656, -16603, -16549, -16496, -16442, - -16389, -16335, -16282, -16229, -16175, -16122, - -16069, -16015, -15962, -15909, -15856, -15802, - -15749, -15696, -15643, -15590, -15537, -15484, - -15431, -15378, -15325, -15272, -15219, -15166, - -15113, -15060, -15007, -14954, -14901, -14848, - -14795, -14743, -14690, -14637, -14584, -14531, - -14479, -14426, -14373, -14321, -14268, -14215, - -14163, -14110, -14057, -14005, -13952, -13900, - -13847, -13795, -13742, -13690, -13637, -13585, - -13533, -13480, -13428, -13375, -13323, -13271, - -13218, -13166, -13114, -13062, -13009, -12957, - -12905, -12853, -12800, -12748, -12696, -12644, - -12592, -12540, -12488, -12436, -12383, -12331, - -12279, -12227, -12175, -12123, -12071, -12019, - -11967, -11916, -11864, -11812, -11760, -11708, - -11656, -11604, -11552, -11501, -11449, -11397, - -11345, -11293, -11242, -11190, -11138, -11086, - -11035, -10983, -10931, -10880, -10828, -10777, - -10725, -10673, -10622, -10570, -10519, -10467, - -10415, -10364, -10312, -10261, -10209, -10158, - -10106, -10055, -10004, -9952, -9901, -9849, - -9798, -9747, -9695, -9644, -9592, -9541, - -9490, -9438, -9387, -9336, -9285, -9233, - -9182, -9131, -9080, -9028, -8977, -8926, - -8875, -8824, -8772, -8721, -8670, -8619, - -8568, -8517, -8466, -8414, -8363, -8312, - -8261, -8210, -8159, -8108, -8057, -8006, - -7955, -7904, -7853, -7802, -7751, -7700, - -7649, -7598, -7547, -7496, -7445, -7395, - -7344, -7293, -7242, -7191, -7140, -7089, - -7038, -6988, -6937, -6886, -6835, -6784, - -6733, -6683, -6632, -6581, -6530, -6480, - -6429, -6378, -6327, -6277, -6226, -6175, - -6124, -6074, -6023, -5972, -5922, -5871, - -5820, -5770, -5719, -5668, -5618, -5567, - -5517, -5466, -5415, -5365, -5314, -5264, - -5213, -5162, -5112, -5061, -5011, -4960, - -4910, -4859, -4808, -4758, -4707, -4657, - -4606, -4556, -4505, -4455, -4404, -4354, - -4303, -4253, -4202, -4152, -4101, -4051, - -4001, -3950, -3900, -3849, -3799, -3748, - -3698, -3648, -3597, -3547, -3496, -3446, - -3395, -3345, -3295, -3244, -3194, -3144, - -3093, -3043, -2992, -2942, -2892, -2841, - -2791, -2741, -2690, -2640, -2590, -2539, - -2489, -2439, -2388, -2338, -2288, -2237, - -2187, -2137, -2086, -2036, -1986, -1935, - -1885, -1835, -1784, -1734, -1684, -1633, - -1583, -1533, -1483, -1432, -1382, -1332, - -1281, -1231, -1181, -1131, -1080, -1030, - -980, -929, -879, -829, -779, -728, - -678, -628, -578, -527, -477, -427, - -376, -326, -276, -226, -175, -125, - -75, -25, 25, 75, 125, 175, - 226, 276, 326, 376, 427, 477, - 527, 578, 628, 678, 728, 779, - 829, 879, 929, 980, 1030, 1080, - 1131, 1181, 1231, 1281, 1332, 1382, - 1432, 1483, 1533, 1583, 1633, 1684, - 1734, 1784, 1835, 1885, 1935, 1986, - 2036, 2086, 2137, 2187, 2237, 2288, - 2338, 2388, 2439, 2489, 2539, 2590, - 2640, 2690, 2741, 2791, 2841, 2892, - 2942, 2992, 3043, 3093, 3144, 3194, - 3244, 3295, 3345, 3395, 3446, 3496, - 3547, 3597, 3648, 3698, 3748, 3799, - 3849, 3900, 3950, 4001, 4051, 4101, - 4152, 4202, 4253, 4303, 4354, 4404, - 4455, 4505, 4556, 4606, 4657, 4707, - 4758, 4808, 4859, 4910, 4960, 5011, - 5061, 5112, 5162, 5213, 5264, 5314, - 5365, 5415, 5466, 5517, 5567, 5618, - 5668, 5719, 5770, 5820, 5871, 5922, - 5972, 6023, 6074, 6124, 6175, 6226, - 6277, 6327, 6378, 6429, 6480, 6530, - 6581, 6632, 6683, 6733, 6784, 6835, - 6886, 6937, 6988, 7038, 7089, 7140, - 7191, 7242, 7293, 7344, 7395, 7445, - 7496, 7547, 7598, 7649, 7700, 7751, - 7802, 7853, 7904, 7955, 8006, 8057, - 8108, 8159, 8210, 8261, 8312, 8363, - 8414, 8466, 8517, 8568, 8619, 8670, - 8721, 8772, 8824, 8875, 8926, 8977, - 9028, 9080, 9131, 9182, 9233, 9285, - 9336, 9387, 9438, 9490, 9541, 9592, - 9644, 9695, 9747, 9798, 9849, 9901, - 9952, 10004, 10055, 10106, 10158, 10209, - 10261, 10312, 10364, 10415, 10467, 10519, - 10570, 10622, 10673, 10725, 10777, 10828, - 10880, 10931, 10983, 11035, 11086, 11138, - 11190, 11242, 11293, 11345, 11397, 11449, - 11501, 11552, 11604, 11656, 11708, 11760, - 11812, 11864, 11916, 11967, 12019, 12071, - 12123, 12175, 12227, 12279, 12331, 12383, - 12436, 12488, 12540, 12592, 12644, 12696, - 12748, 12800, 12853, 12905, 12957, 13009, - 13062, 13114, 13166, 13218, 13271, 13323, - 13375, 13428, 13480, 13533, 13585, 13637, - 13690, 13742, 13795, 13847, 13900, 13952, - 14005, 14057, 14110, 14163, 14215, 14268, - 14321, 14373, 14426, 14479, 14531, 14584, - 14637, 14690, 14743, 14795, 14848, 14901, - 14954, 15007, 15060, 15113, 15166, 15219, - 15272, 15325, 15378, 15431, 15484, 15537, - 15590, 15643, 15696, 15749, 15802, 15856, - 15909, 15962, 16015, 16069, 16122, 16175, - 16229, 16282, 16335, 16389, 16442, 16496, - 16549, 16603, 16656, 16710, 16763, 16817, - 16870, 16924, 16977, 17031, 17085, 17138, - 17192, 17246, 17300, 17353, 17407, 17461, - 17515, 17569, 17623, 17677, 17731, 17784, - 17838, 17892, 17946, 18001, 18055, 18109, - 18163, 18217, 18271, 18325, 18380, 18434, - 18488, 18542, 18597, 18651, 18705, 18760, - 18814, 18868, 18923, 18977, 19032, 19086, - 19141, 19195, 19250, 19305, 19359, 19414, - 19469, 19523, 19578, 19633, 19688, 19742, - 19797, 19852, 19907, 19962, 20017, 20072, - 20127, 20182, 20237, 20292, 20347, 20402, - 20457, 20513, 20568, 20623, 20678, 20734, - 20789, 20844, 20900, 20955, 21010, 21066, - 21121, 21177, 21232, 21288, 21343, 21399, - 21455, 21510, 21566, 21622, 21678, 21733, - 21789, 21845, 21901, 21957, 22013, 22069, - 22125, 22181, 22237, 22293, 22349, 22405, - 22461, 22517, 22573, 22630, 22686, 22742, - 22799, 22855, 22911, 22968, 23024, 23081, - 23137, 23194, 23250, 23307, 23364, 23420, - 23477, 23534, 23591, 23647, 23704, 23761, - 23818, 23875, 23932, 23989, 24046, 24103, - 24160, 24217, 24274, 24331, 24389, 24446, - 24503, 24560, 24618, 24675, 24732, 24790, - 24847, 24905, 24962, 25020, 25078, 25135, - 25193, 25251, 25308, 25366, 25424, 25482, - 25540, 25598, 25656, 25714, 25772, 25830, - 25888, 25946, 26004, 26062, 26120, 26179, - 26237, 26295, 26354, 26412, 26471, 26529, - 26588, 26646, 26705, 26763, 26822, 26881, - 26940, 26998, 27057, 27116, 27175, 27234, - 27293, 27352, 27411, 27470, 27529, 27588, - 27647, 27707, 27766, 27825, 27884, 27944, - 28003, 28063, 28122, 28182, 28241, 28301, - 28361, 28420, 28480, 28540, 28600, 28660, - 28719, 28779, 28839, 28899, 28959, 29020, - 29080, 29140, 29200, 29260, 29321, 29381, - 29441, 29502, 29562, 29623, 29683, 29744, - 29805, 29865, 29926, 29987, 30048, 30108, - 30169, 30230, 30291, 30352, 30413, 30474, - 30536, 30597, 30658, 30719, 30781, 30842, - 30904, 30965, 31026, 31088, 31150, 31211, - 31273, 31335, 31396, 31458, 31520, 31582, - 31644, 31706, 31768, 31830, 31892, 31955, - 32017, 32079, 32141, 32204, 32266, 32329, - 32391, 32454, 32516, 32579, 32642, 32705, - 32767, 32830, 32893, 32956, 33019, 33082, - 33145, 33208, 33272, 33335, 33398, 33461, - 33525, 33588, 33652, 33715, 33779, 33843, - 33906, 33970, 34034, 34098, 34162, 34225, - 34289, 34354, 34418, 34482, 34546, 34610, - 34675, 34739, 34803, 34868, 34932, 34997, - 35062, 35126, 35191, 35256, 35321, 35385, - 35450, 35515, 35580, 35646, 35711, 35776, - 35841, 35907, 35972, 36037, 36103, 36168, - 36234, 36300, 36365, 36431, 36497, 36563, - 36629, 36695, 36761, 36827, 36893, 36959, - 37026, 37092, 37158, 37225, 37291, 37358, - 37425, 37491, 37558, 37625, 37692, 37759, - 37826, 37893, 37960, 38027, 38094, 38161, - 38229, 38296, 38364, 38431, 38499, 38566, - 38634, 38702, 38770, 38837, 38905, 38973, - 39042, 39110, 39178, 39246, 39314, 39383, - 39451, 39520, 39588, 39657, 39726, 39794, - 39863, 39932, 40001, 40070, 40139, 40208, - 40278, 40347, 40416, 40486, 40555, 40625, - 40694, 40764, 40834, 40904, 40973, 41043, - 41113, 41184, 41254, 41324, 41394, 41465, - 41535, 41605, 41676, 41747, 41817, 41888, - 41959, 42030, 42101, 42172, 42243, 42314, - 42385, 42457, 42528, 42600, 42671, 42743, - 42814, 42886, 42958, 43030, 43102, 43174, - 43246, 43318, 43390, 43463, 43535, 43608, - 43680, 43753, 43826, 43898, 43971, 44044, - 44117, 44190, 44263, 44337, 44410, 44483, - 44557, 44630, 44704, 44778, 44851, 44925, - 44999, 45073, 45147, 45221, 45296, 45370, - 45444, 45519, 45593, 45668, 45743, 45818, - 45892, 45967, 46042, 46118, 46193, 46268, - 46343, 46419, 46494, 46570, 46646, 46721, - 46797, 46873, 46949, 47025, 47102, 47178, - 47254, 47331, 47407, 47484, 47560, 47637, - 47714, 47791, 47868, 47945, 48022, 48100, - 48177, 48255, 48332, 48410, 48488, 48565, - 48643, 48721, 48799, 48878, 48956, 49034, - 49113, 49191, 49270, 49349, 49427, 49506, - 49585, 49664, 49744, 49823, 49902, 49982, - 50061, 50141, 50221, 50300, 50380, 50460, - 50540, 50621, 50701, 50781, 50862, 50942, - 51023, 51104, 51185, 51266, 51347, 51428, - 51509, 51591, 51672, 51754, 51835, 51917, - 51999, 52081, 52163, 52245, 52327, 52410, - 52492, 52575, 52657, 52740, 52823, 52906, - 52989, 53072, 53156, 53239, 53322, 53406, - 53490, 53574, 53657, 53741, 53826, 53910, - 53994, 54079, 54163, 54248, 54333, 54417, - 54502, 54587, 54673, 54758, 54843, 54929, - 55015, 55100, 55186, 55272, 55358, 55444, - 55531, 55617, 55704, 55790, 55877, 55964, - 56051, 56138, 56225, 56312, 56400, 56487, - 56575, 56663, 56751, 56839, 56927, 57015, - 57104, 57192, 57281, 57369, 57458, 57547, - 57636, 57725, 57815, 57904, 57994, 58083, - 58173, 58263, 58353, 58443, 58534, 58624, - 58715, 58805, 58896, 58987, 59078, 59169, - 59261, 59352, 59444, 59535, 59627, 59719, - 59811, 59903, 59996, 60088, 60181, 60273, - 60366, 60459, 60552, 60646, 60739, 60833, - 60926, 61020, 61114, 61208, 61302, 61396, - 61491, 61585, 61680, 61775, 61870, 61965, - 62060, 62156, 62251, 62347, 62443, 62539, - 62635, 62731, 62828, 62924, 63021, 63118, - 63215, 63312, 63409, 63506, 63604, 63702, - 63799, 63897, 63996, 64094, 64192, 64291, - 64389, 64488, 64587, 64687, 64786, 64885, - 64985, 65085, 65185, 65285, 65385, 65485, - 65586, 65686, 65787, 65888, 65989, 66091, - 66192, 66294, 66396, 66498, 66600, 66702, - 66804, 66907, 67010, 67113, 67216, 67319, - 67422, 67526, 67629, 67733, 67837, 67942, - 68046, 68151, 68255, 68360, 68465, 68570, - 68676, 68781, 68887, 68993, 69099, 69205, - 69312, 69418, 69525, 69632, 69739, 69846, - 69954, 70061, 70169, 70277, 70385, 70494, - 70602, 70711, 70820, 70929, 71038, 71147, - 71257, 71367, 71477, 71587, 71697, 71808, - 71918, 72029, 72140, 72252, 72363, 72475, - 72587, 72699, 72811, 72923, 73036, 73149, - 73262, 73375, 73488, 73602, 73715, 73829, - 73944, 74058, 74172, 74287, 74402, 74517, - 74633, 74748, 74864, 74980, 75096, 75213, - 75329, 75446, 75563, 75680, 75797, 75915, - 76033, 76151, 76269, 76388, 76506, 76625, - 76744, 76864, 76983, 77103, 77223, 77343, - 77463, 77584, 77705, 77826, 77947, 78068, - 78190, 78312, 78434, 78557, 78679, 78802, - 78925, 79048, 79172, 79296, 79420, 79544, - 79668, 79793, 79918, 80043, 80168, 80294, - 80420, 80546, 80672, 80799, 80925, 81053, - 81180, 81307, 81435, 81563, 81691, 81820, - 81949, 82078, 82207, 82336, 82466, 82596, - 82726, 82857, 82987, 83118, 83250, 83381, - 83513, 83645, 83777, 83910, 84043, 84176, - 84309, 84443, 84576, 84710, 84845, 84980, - 85114, 85250, 85385, 85521, 85657, 85793, - 85930, 86066, 86204, 86341, 86479, 86616, - 86755, 86893, 87032, 87171, 87310, 87450, - 87590, 87730, 87871, 88011, 88152, 88294, - 88435, 88577, 88720, 88862, 89005, 89148, - 89292, 89435, 89579, 89724, 89868, 90013, - 90158, 90304, 90450, 90596, 90742, 90889, - 91036, 91184, 91332, 91480, 91628, 91777, - 91926, 92075, 92225, 92375, 92525, 92675, - 92826, 92978, 93129, 93281, 93434, 93586, - 93739, 93892, 94046, 94200, 94354, 94509, - 94664, 94819, 94975, 95131, 95287, 95444, - 95601, 95758, 95916, 96074, 96233, 96391, - 96551, 96710, 96870, 97030, 97191, 97352, - 97513, 97675, 97837, 98000, 98163, 98326, - 98489, 98653, 98818, 98982, 99148, 99313, - 99479, 99645, 99812, 99979, 100146, 100314, - 100482, 100651, 100820, 100990, 101159, 101330, - 101500, 101671, 101843, 102015, 102187, 102360, - 102533, 102706, 102880, 103054, 103229, 103404, - 103580, 103756, 103933, 104109, 104287, 104465, - 104643, 104821, 105000, 105180, 105360, 105540, - 105721, 105902, 106084, 106266, 106449, 106632, - 106816, 107000, 107184, 107369, 107555, 107741, - 107927, 108114, 108301, 108489, 108677, 108866, - 109055, 109245, 109435, 109626, 109817, 110008, - 110200, 110393, 110586, 110780, 110974, 111169, - 111364, 111560, 111756, 111952, 112150, 112347, - 112546, 112744, 112944, 113143, 113344, 113545, - 113746, 113948, 114151, 114354, 114557, 114761, - 114966, 115171, 115377, 115583, 115790, 115998, - 116206, 116414, 116623, 116833, 117044, 117254, - 117466, 117678, 117891, 118104, 118318, 118532, - 118747, 118963, 119179, 119396, 119613, 119831, - 120050, 120269, 120489, 120709, 120930, 121152, - 121374, 121597, 121821, 122045, 122270, 122496, - 122722, 122949, 123176, 123404, 123633, 123863, - 124093, 124324, 124555, 124787, 125020, 125254, - 125488, 125723, 125959, 126195, 126432, 126669, - 126908, 127147, 127387, 127627, 127869, 128111, - 128353, 128597, 128841, 129086, 129332, 129578, - 129825, 130073, 130322, 130571, 130821, 131072, - 131324, 131576, 131830, 132084, 132339, 132594, - 132851, 133108, 133366, 133625, 133884, 134145, - 134406, 134668, 134931, 135195, 135459, 135725, - 135991, 136258, 136526, 136795, 137065, 137335, - 137607, 137879, 138152, 138426, 138701, 138977, - 139254, 139532, 139810, 140090, 140370, 140651, - 140934, 141217, 141501, 141786, 142072, 142359, - 142647, 142936, 143226, 143517, 143808, 144101, - 144395, 144690, 144986, 145282, 145580, 145879, - 146179, 146480, 146782, 147084, 147388, 147693, - 148000, 148307, 148615, 148924, 149235, 149546, - 149859, 150172, 150487, 150803, 151120, 151438, - 151757, 152077, 152399, 152722, 153045, 153370, - 153697, 154024, 154352, 154682, 155013, 155345, - 155678, 156013, 156349, 156686, 157024, 157363, - 157704, 158046, 158389, 158734, 159079, 159427, - 159775, 160125, 160476, 160828, 161182, 161537, - 161893, 162251, 162610, 162970, 163332, 163695, - 164060, 164426, 164793, 165162, 165532, 165904, - 166277, 166651, 167027, 167405, 167784, 168164, - 168546, 168930, 169315, 169701, 170089, 170479, - 170870, 171263, 171657, 172053, 172451, 172850, - 173251, 173653, 174057, 174463, 174870, 175279, - 175690, 176102, 176516, 176932, 177349, 177769, - 178190, 178612, 179037, 179463, 179891, 180321, - 180753, 181186, 181622, 182059, 182498, 182939, - 183382, 183827, 184274, 184722, 185173, 185625, - 186080, 186536, 186995, 187455, 187918, 188382, - 188849, 189318, 189789, 190261, 190736, 191213, - 191693, 192174, 192658, 193143, 193631, 194122, - 194614, 195109, 195606, 196105, 196606, 197110, - 197616, 198125, 198636, 199149, 199664, 200182, - 200703, 201226, 201751, 202279, 202809, 203342, - 203878, 204416, 204956, 205500, 206045, 206594, - 207145, 207699, 208255, 208815, 209376, 209941, - 210509, 211079, 211652, 212228, 212807, 213389, - 213973, 214561, 215151, 215745, 216341, 216941, - 217544, 218149, 218758, 219370, 219985, 220603, - 221225, 221849, 222477, 223108, 223743, 224381, - 225022, 225666, 226314, 226966, 227621, 228279, - 228941, 229606, 230275, 230948, 231624, 232304, - 232988, 233676, 234367, 235062, 235761, 236463, - 237170, 237881, 238595, 239314, 240036, 240763, - 241493, 242228, 242967, 243711, 244458, 245210, - 245966, 246727, 247492, 248261, 249035, 249813, - 250596, 251384, 252176, 252973, 253774, 254581, - 255392, 256208, 257029, 257855, 258686, 259522, - 260363, 261209, 262060, 262917, 263779, 264646, - 265519, 266397, 267280, 268169, 269064, 269965, - 270871, 271782, 272700, 273624, 274553, 275489, - 276430, 277378, 278332, 279292, 280258, 281231, - 282210, 283195, 284188, 285186, 286192, 287204, - 288223, 289249, 290282, 291322, 292369, 293423, - 294485, 295554, 296630, 297714, 298805, 299904, - 301011, 302126, 303248, 304379, 305517, 306664, - 307819, 308983, 310154, 311335, 312524, 313721, - 314928, 316143, 317368, 318601, 319844, 321097, - 322358, 323629, 324910, 326201, 327502, 328812, - 330133, 331464, 332805, 334157, 335519, 336892, - 338276, 339671, 341078, 342495, 343924, 345364, - 346816, 348280, 349756, 351244, 352744, 354257, - 355783, 357321, 358872, 360436, 362013, 363604, - 365208, 366826, 368459, 370105, 371765, 373440, - 375130, 376835, 378555, 380290, 382040, 383807, - 385589, 387387, 389202, 391034, 392882, 394747, - 396630, 398530, 400448, 402384, 404338, 406311, - 408303, 410314, 412344, 414395, 416465, 418555, - 420666, 422798, 424951, 427125, 429321, 431540, - 433781, 436045, 438332, 440643, 442978, 445337, - 447720, 450129, 452564, 455024, 457511, 460024, - 462565, 465133, 467730, 470355, 473009, 475692, - 478406, 481150, 483925, 486732, 489571, 492443, - 495348, 498287, 501261, 504269, 507313, 510394, - 513512, 516667, 519861, 523094, 526366, 529680, - 533034, 536431, 539870, 543354, 546881, 550455, - 554074, 557741, 561456, 565221, 569035, 572901, - 576818, 580789, 584815, 588896, 593033, 597229, - 601483, 605798, 610174, 614613, 619117, 623686, - 628323, 633028, 637803, 642651, 647572, 652568, - 657640, 662792, 668024, 673338, 678737, 684223, - 689797, 695462, 701219, 707072, 713023, 719074, - 725227, 731486, 737853, 744331, 750922, 757631, - 764460, 771411, 778490, 785699, 793041, 800521, - 808143, 815910, 823827, 831898, 840127, 848520, - 857081, 865817, 874730, 883829, 893117, 902602, - 912289, 922186, 932298, 942633, 953199, 964003, - 975054, 986361, 997931, 1009774, 1021901, 1034322, - 1047046, 1060087, 1073455, 1087164, 1101225, 1115654, - 1130465, 1145673, 1161294, 1177345, 1193846, 1210813, - 1228269, 1246234, 1264730, 1283783, 1303416, 1323658, - 1344537, 1366084, 1388330, 1411312, 1435065, 1459630, - 1485049, 1511367, 1538632, 1566898, 1596220, 1626658, - 1658278, 1691149, 1725348, 1760956, 1798063, 1836758, - 1877161, 1919378, 1963536, 2009771, 2058233, 2109087, - 2162516, 2218719, 2277919, 2340362, 2406322, 2476104, - 2550052, 2628549, 2712030, 2800983, 2895966, 2997613, - 3106651, 3223918, 3350381, 3487165, 3635590, 3797206, - 3973855, 4167737, 4381502, 4618375, 4882318, 5178251, - 5512368, 5892567, 6329090, 6835455, 7429880, 8137527, - 8994149, 10052327, 11392683, 13145455, 15535599, 18988036, - 24413316, 34178904, 56965752, 170910304, -}; - -const fixed_t finesine[10240] = -{ - 25, 75, 125, 175, 226, 276, 326, 376, 427, - 477, 527, 578, 628, 678, 728, 779, 829, 879, - 929, 980, 1030, 1080, 1130, 1181, 1231, 1281, 1331, - 1382, 1432, 1482, 1532, 1583, 1633, 1683, 1733, 1784, - 1834, 1884, 1934, 1985, 2035, 2085, 2135, 2186, 2236, - 2286, 2336, 2387, 2437, 2487, 2537, 2587, 2638, 2688, - 2738, 2788, 2839, 2889, 2939, 2989, 3039, 3090, 3140, - 3190, 3240, 3291, 3341, 3391, 3441, 3491, 3541, 3592, - 3642, 3692, 3742, 3792, 3843, 3893, 3943, 3993, 4043, - 4093, 4144, 4194, 4244, 4294, 4344, 4394, 4445, 4495, - 4545, 4595, 4645, 4695, 4745, 4796, 4846, 4896, 4946, - 4996, 5046, 5096, 5146, 5197, 5247, 5297, 5347, 5397, - 5447, 5497, 5547, 5597, 5647, 5697, 5748, 5798, 5848, - 5898, 5948, 5998, 6048, 6098, 6148, 6198, 6248, 6298, - 6348, 6398, 6448, 6498, 6548, 6598, 6648, 6698, 6748, - 6798, 6848, 6898, 6948, 6998, 7048, 7098, 7148, 7198, - 7248, 7298, 7348, 7398, 7448, 7498, 7548, 7598, 7648, - 7697, 7747, 7797, 7847, 7897, 7947, 7997, 8047, 8097, - 8147, 8196, 8246, 8296, 8346, 8396, 8446, 8496, 8545, - 8595, 8645, 8695, 8745, 8794, 8844, 8894, 8944, 8994, - 9043, 9093, 9143, 9193, 9243, 9292, 9342, 9392, 9442, - 9491, 9541, 9591, 9640, 9690, 9740, 9790, 9839, 9889, - 9939, 9988, 10038, 10088, 10137, 10187, 10237, 10286, 10336, - 10386, 10435, 10485, 10534, 10584, 10634, 10683, 10733, 10782, - 10832, 10882, 10931, 10981, 11030, 11080, 11129, 11179, 11228, - 11278, 11327, 11377, 11426, 11476, 11525, 11575, 11624, 11674, - 11723, 11773, 11822, 11872, 11921, 11970, 12020, 12069, 12119, - 12168, 12218, 12267, 12316, 12366, 12415, 12464, 12514, 12563, - 12612, 12662, 12711, 12760, 12810, 12859, 12908, 12957, 13007, - 13056, 13105, 13154, 13204, 13253, 13302, 13351, 13401, 13450, - 13499, 13548, 13597, 13647, 13696, 13745, 13794, 13843, 13892, - 13941, 13990, 14040, 14089, 14138, 14187, 14236, 14285, 14334, - 14383, 14432, 14481, 14530, 14579, 14628, 14677, 14726, 14775, - 14824, 14873, 14922, 14971, 15020, 15069, 15118, 15167, 15215, - 15264, 15313, 15362, 15411, 15460, 15509, 15557, 15606, 15655, - 15704, 15753, 15802, 15850, 15899, 15948, 15997, 16045, 16094, - 16143, 16191, 16240, 16289, 16338, 16386, 16435, 16484, 16532, - 16581, 16629, 16678, 16727, 16775, 16824, 16872, 16921, 16970, - 17018, 17067, 17115, 17164, 17212, 17261, 17309, 17358, 17406, - 17455, 17503, 17551, 17600, 17648, 17697, 17745, 17793, 17842, - 17890, 17939, 17987, 18035, 18084, 18132, 18180, 18228, 18277, - 18325, 18373, 18421, 18470, 18518, 18566, 18614, 18663, 18711, - 18759, 18807, 18855, 18903, 18951, 19000, 19048, 19096, 19144, - 19192, 19240, 19288, 19336, 19384, 19432, 19480, 19528, 19576, - 19624, 19672, 19720, 19768, 19816, 19864, 19912, 19959, 20007, - 20055, 20103, 20151, 20199, 20246, 20294, 20342, 20390, 20438, - 20485, 20533, 20581, 20629, 20676, 20724, 20772, 20819, 20867, - 20915, 20962, 21010, 21057, 21105, 21153, 21200, 21248, 21295, - 21343, 21390, 21438, 21485, 21533, 21580, 21628, 21675, 21723, - 21770, 21817, 21865, 21912, 21960, 22007, 22054, 22102, 22149, - 22196, 22243, 22291, 22338, 22385, 22433, 22480, 22527, 22574, - 22621, 22668, 22716, 22763, 22810, 22857, 22904, 22951, 22998, - 23045, 23092, 23139, 23186, 23233, 23280, 23327, 23374, 23421, - 23468, 23515, 23562, 23609, 23656, 23703, 23750, 23796, 23843, - 23890, 23937, 23984, 24030, 24077, 24124, 24171, 24217, 24264, - 24311, 24357, 24404, 24451, 24497, 24544, 24591, 24637, 24684, - 24730, 24777, 24823, 24870, 24916, 24963, 25009, 25056, 25102, - 25149, 25195, 25241, 25288, 25334, 25381, 25427, 25473, 25520, - 25566, 25612, 25658, 25705, 25751, 25797, 25843, 25889, 25936, - 25982, 26028, 26074, 26120, 26166, 26212, 26258, 26304, 26350, - 26396, 26442, 26488, 26534, 26580, 26626, 26672, 26718, 26764, - 26810, 26856, 26902, 26947, 26993, 27039, 27085, 27131, 27176, - 27222, 27268, 27313, 27359, 27405, 27450, 27496, 27542, 27587, - 27633, 27678, 27724, 27770, 27815, 27861, 27906, 27952, 27997, - 28042, 28088, 28133, 28179, 28224, 28269, 28315, 28360, 28405, - 28451, 28496, 28541, 28586, 28632, 28677, 28722, 28767, 28812, - 28858, 28903, 28948, 28993, 29038, 29083, 29128, 29173, 29218, - 29263, 29308, 29353, 29398, 29443, 29488, 29533, 29577, 29622, - 29667, 29712, 29757, 29801, 29846, 29891, 29936, 29980, 30025, - 30070, 30114, 30159, 30204, 30248, 30293, 30337, 30382, 30426, - 30471, 30515, 30560, 30604, 30649, 30693, 30738, 30782, 30826, - 30871, 30915, 30959, 31004, 31048, 31092, 31136, 31181, 31225, - 31269, 31313, 31357, 31402, 31446, 31490, 31534, 31578, 31622, - 31666, 31710, 31754, 31798, 31842, 31886, 31930, 31974, 32017, - 32061, 32105, 32149, 32193, 32236, 32280, 32324, 32368, 32411, - 32455, 32499, 32542, 32586, 32630, 32673, 32717, 32760, 32804, - 32847, 32891, 32934, 32978, 33021, 33065, 33108, 33151, 33195, - 33238, 33281, 33325, 33368, 33411, 33454, 33498, 33541, 33584, - 33627, 33670, 33713, 33756, 33799, 33843, 33886, 33929, 33972, - 34015, 34057, 34100, 34143, 34186, 34229, 34272, 34315, 34358, - 34400, 34443, 34486, 34529, 34571, 34614, 34657, 34699, 34742, - 34785, 34827, 34870, 34912, 34955, 34997, 35040, 35082, 35125, - 35167, 35210, 35252, 35294, 35337, 35379, 35421, 35464, 35506, - 35548, 35590, 35633, 35675, 35717, 35759, 35801, 35843, 35885, - 35927, 35969, 36011, 36053, 36095, 36137, 36179, 36221, 36263, - 36305, 36347, 36388, 36430, 36472, 36514, 36555, 36597, 36639, - 36681, 36722, 36764, 36805, 36847, 36889, 36930, 36972, 37013, - 37055, 37096, 37137, 37179, 37220, 37262, 37303, 37344, 37386, - 37427, 37468, 37509, 37551, 37592, 37633, 37674, 37715, 37756, - 37797, 37838, 37879, 37920, 37961, 38002, 38043, 38084, 38125, - 38166, 38207, 38248, 38288, 38329, 38370, 38411, 38451, 38492, - 38533, 38573, 38614, 38655, 38695, 38736, 38776, 38817, 38857, - 38898, 38938, 38979, 39019, 39059, 39100, 39140, 39180, 39221, - 39261, 39301, 39341, 39382, 39422, 39462, 39502, 39542, 39582, - 39622, 39662, 39702, 39742, 39782, 39822, 39862, 39902, 39942, - 39982, 40021, 40061, 40101, 40141, 40180, 40220, 40260, 40300, - 40339, 40379, 40418, 40458, 40497, 40537, 40576, 40616, 40655, - 40695, 40734, 40773, 40813, 40852, 40891, 40931, 40970, 41009, - 41048, 41087, 41127, 41166, 41205, 41244, 41283, 41322, 41361, - 41400, 41439, 41478, 41517, 41556, 41595, 41633, 41672, 41711, - 41750, 41788, 41827, 41866, 41904, 41943, 41982, 42020, 42059, - 42097, 42136, 42174, 42213, 42251, 42290, 42328, 42366, 42405, - 42443, 42481, 42520, 42558, 42596, 42634, 42672, 42711, 42749, - 42787, 42825, 42863, 42901, 42939, 42977, 43015, 43053, 43091, - 43128, 43166, 43204, 43242, 43280, 43317, 43355, 43393, 43430, - 43468, 43506, 43543, 43581, 43618, 43656, 43693, 43731, 43768, - 43806, 43843, 43880, 43918, 43955, 43992, 44029, 44067, 44104, - 44141, 44178, 44215, 44252, 44289, 44326, 44363, 44400, 44437, - 44474, 44511, 44548, 44585, 44622, 44659, 44695, 44732, 44769, - 44806, 44842, 44879, 44915, 44952, 44989, 45025, 45062, 45098, - 45135, 45171, 45207, 45244, 45280, 45316, 45353, 45389, 45425, - 45462, 45498, 45534, 45570, 45606, 45642, 45678, 45714, 45750, - 45786, 45822, 45858, 45894, 45930, 45966, 46002, 46037, 46073, - 46109, 46145, 46180, 46216, 46252, 46287, 46323, 46358, 46394, - 46429, 46465, 46500, 46536, 46571, 46606, 46642, 46677, 46712, - 46747, 46783, 46818, 46853, 46888, 46923, 46958, 46993, 47028, - 47063, 47098, 47133, 47168, 47203, 47238, 47273, 47308, 47342, - 47377, 47412, 47446, 47481, 47516, 47550, 47585, 47619, 47654, - 47688, 47723, 47757, 47792, 47826, 47860, 47895, 47929, 47963, - 47998, 48032, 48066, 48100, 48134, 48168, 48202, 48237, 48271, - 48305, 48338, 48372, 48406, 48440, 48474, 48508, 48542, 48575, - 48609, 48643, 48676, 48710, 48744, 48777, 48811, 48844, 48878, - 48911, 48945, 48978, 49012, 49045, 49078, 49112, 49145, 49178, - 49211, 49244, 49278, 49311, 49344, 49377, 49410, 49443, 49476, - 49509, 49542, 49575, 49608, 49640, 49673, 49706, 49739, 49771, - 49804, 49837, 49869, 49902, 49935, 49967, 50000, 50032, 50065, - 50097, 50129, 50162, 50194, 50226, 50259, 50291, 50323, 50355, - 50387, 50420, 50452, 50484, 50516, 50548, 50580, 50612, 50644, - 50675, 50707, 50739, 50771, 50803, 50834, 50866, 50898, 50929, - 50961, 50993, 51024, 51056, 51087, 51119, 51150, 51182, 51213, - 51244, 51276, 51307, 51338, 51369, 51401, 51432, 51463, 51494, - 51525, 51556, 51587, 51618, 51649, 51680, 51711, 51742, 51773, - 51803, 51834, 51865, 51896, 51926, 51957, 51988, 52018, 52049, - 52079, 52110, 52140, 52171, 52201, 52231, 52262, 52292, 52322, - 52353, 52383, 52413, 52443, 52473, 52503, 52534, 52564, 52594, - 52624, 52653, 52683, 52713, 52743, 52773, 52803, 52832, 52862, - 52892, 52922, 52951, 52981, 53010, 53040, 53069, 53099, 53128, - 53158, 53187, 53216, 53246, 53275, 53304, 53334, 53363, 53392, - 53421, 53450, 53479, 53508, 53537, 53566, 53595, 53624, 53653, - 53682, 53711, 53739, 53768, 53797, 53826, 53854, 53883, 53911, - 53940, 53969, 53997, 54026, 54054, 54082, 54111, 54139, 54167, - 54196, 54224, 54252, 54280, 54308, 54337, 54365, 54393, 54421, - 54449, 54477, 54505, 54533, 54560, 54588, 54616, 54644, 54672, - 54699, 54727, 54755, 54782, 54810, 54837, 54865, 54892, 54920, - 54947, 54974, 55002, 55029, 55056, 55084, 55111, 55138, 55165, - 55192, 55219, 55246, 55274, 55300, 55327, 55354, 55381, 55408, - 55435, 55462, 55489, 55515, 55542, 55569, 55595, 55622, 55648, - 55675, 55701, 55728, 55754, 55781, 55807, 55833, 55860, 55886, - 55912, 55938, 55965, 55991, 56017, 56043, 56069, 56095, 56121, - 56147, 56173, 56199, 56225, 56250, 56276, 56302, 56328, 56353, - 56379, 56404, 56430, 56456, 56481, 56507, 56532, 56557, 56583, - 56608, 56633, 56659, 56684, 56709, 56734, 56760, 56785, 56810, - 56835, 56860, 56885, 56910, 56935, 56959, 56984, 57009, 57034, - 57059, 57083, 57108, 57133, 57157, 57182, 57206, 57231, 57255, - 57280, 57304, 57329, 57353, 57377, 57402, 57426, 57450, 57474, - 57498, 57522, 57546, 57570, 57594, 57618, 57642, 57666, 57690, - 57714, 57738, 57762, 57785, 57809, 57833, 57856, 57880, 57903, - 57927, 57950, 57974, 57997, 58021, 58044, 58067, 58091, 58114, - 58137, 58160, 58183, 58207, 58230, 58253, 58276, 58299, 58322, - 58345, 58367, 58390, 58413, 58436, 58459, 58481, 58504, 58527, - 58549, 58572, 58594, 58617, 58639, 58662, 58684, 58706, 58729, - 58751, 58773, 58795, 58818, 58840, 58862, 58884, 58906, 58928, - 58950, 58972, 58994, 59016, 59038, 59059, 59081, 59103, 59125, - 59146, 59168, 59190, 59211, 59233, 59254, 59276, 59297, 59318, - 59340, 59361, 59382, 59404, 59425, 59446, 59467, 59488, 59509, - 59530, 59551, 59572, 59593, 59614, 59635, 59656, 59677, 59697, - 59718, 59739, 59759, 59780, 59801, 59821, 59842, 59862, 59883, - 59903, 59923, 59944, 59964, 59984, 60004, 60025, 60045, 60065, - 60085, 60105, 60125, 60145, 60165, 60185, 60205, 60225, 60244, - 60264, 60284, 60304, 60323, 60343, 60363, 60382, 60402, 60421, - 60441, 60460, 60479, 60499, 60518, 60537, 60556, 60576, 60595, - 60614, 60633, 60652, 60671, 60690, 60709, 60728, 60747, 60766, - 60785, 60803, 60822, 60841, 60859, 60878, 60897, 60915, 60934, - 60952, 60971, 60989, 61007, 61026, 61044, 61062, 61081, 61099, - 61117, 61135, 61153, 61171, 61189, 61207, 61225, 61243, 61261, - 61279, 61297, 61314, 61332, 61350, 61367, 61385, 61403, 61420, - 61438, 61455, 61473, 61490, 61507, 61525, 61542, 61559, 61577, - 61594, 61611, 61628, 61645, 61662, 61679, 61696, 61713, 61730, - 61747, 61764, 61780, 61797, 61814, 61831, 61847, 61864, 61880, - 61897, 61913, 61930, 61946, 61963, 61979, 61995, 62012, 62028, - 62044, 62060, 62076, 62092, 62108, 62125, 62141, 62156, 62172, - 62188, 62204, 62220, 62236, 62251, 62267, 62283, 62298, 62314, - 62329, 62345, 62360, 62376, 62391, 62407, 62422, 62437, 62453, - 62468, 62483, 62498, 62513, 62528, 62543, 62558, 62573, 62588, - 62603, 62618, 62633, 62648, 62662, 62677, 62692, 62706, 62721, - 62735, 62750, 62764, 62779, 62793, 62808, 62822, 62836, 62850, - 62865, 62879, 62893, 62907, 62921, 62935, 62949, 62963, 62977, - 62991, 63005, 63019, 63032, 63046, 63060, 63074, 63087, 63101, - 63114, 63128, 63141, 63155, 63168, 63182, 63195, 63208, 63221, - 63235, 63248, 63261, 63274, 63287, 63300, 63313, 63326, 63339, - 63352, 63365, 63378, 63390, 63403, 63416, 63429, 63441, 63454, - 63466, 63479, 63491, 63504, 63516, 63528, 63541, 63553, 63565, - 63578, 63590, 63602, 63614, 63626, 63638, 63650, 63662, 63674, - 63686, 63698, 63709, 63721, 63733, 63745, 63756, 63768, 63779, - 63791, 63803, 63814, 63825, 63837, 63848, 63859, 63871, 63882, - 63893, 63904, 63915, 63927, 63938, 63949, 63960, 63971, 63981, - 63992, 64003, 64014, 64025, 64035, 64046, 64057, 64067, 64078, - 64088, 64099, 64109, 64120, 64130, 64140, 64151, 64161, 64171, - 64181, 64192, 64202, 64212, 64222, 64232, 64242, 64252, 64261, - 64271, 64281, 64291, 64301, 64310, 64320, 64330, 64339, 64349, - 64358, 64368, 64377, 64387, 64396, 64405, 64414, 64424, 64433, - 64442, 64451, 64460, 64469, 64478, 64487, 64496, 64505, 64514, - 64523, 64532, 64540, 64549, 64558, 64566, 64575, 64584, 64592, - 64601, 64609, 64617, 64626, 64634, 64642, 64651, 64659, 64667, - 64675, 64683, 64691, 64699, 64707, 64715, 64723, 64731, 64739, - 64747, 64754, 64762, 64770, 64777, 64785, 64793, 64800, 64808, - 64815, 64822, 64830, 64837, 64844, 64852, 64859, 64866, 64873, - 64880, 64887, 64895, 64902, 64908, 64915, 64922, 64929, 64936, - 64943, 64949, 64956, 64963, 64969, 64976, 64982, 64989, 64995, - 65002, 65008, 65015, 65021, 65027, 65033, 65040, 65046, 65052, - 65058, 65064, 65070, 65076, 65082, 65088, 65094, 65099, 65105, - 65111, 65117, 65122, 65128, 65133, 65139, 65144, 65150, 65155, - 65161, 65166, 65171, 65177, 65182, 65187, 65192, 65197, 65202, - 65207, 65212, 65217, 65222, 65227, 65232, 65237, 65242, 65246, - 65251, 65256, 65260, 65265, 65270, 65274, 65279, 65283, 65287, - 65292, 65296, 65300, 65305, 65309, 65313, 65317, 65321, 65325, - 65329, 65333, 65337, 65341, 65345, 65349, 65352, 65356, 65360, - 65363, 65367, 65371, 65374, 65378, 65381, 65385, 65388, 65391, - 65395, 65398, 65401, 65404, 65408, 65411, 65414, 65417, 65420, - 65423, 65426, 65429, 65431, 65434, 65437, 65440, 65442, 65445, - 65448, 65450, 65453, 65455, 65458, 65460, 65463, 65465, 65467, - 65470, 65472, 65474, 65476, 65478, 65480, 65482, 65484, 65486, - 65488, 65490, 65492, 65494, 65496, 65497, 65499, 65501, 65502, - 65504, 65505, 65507, 65508, 65510, 65511, 65513, 65514, 65515, - 65516, 65518, 65519, 65520, 65521, 65522, 65523, 65524, 65525, - 65526, 65527, 65527, 65528, 65529, 65530, 65530, 65531, 65531, - 65532, 65532, 65533, 65533, 65534, 65534, 65534, 65535, 65535, - 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, - 65535, 65535, 65535, 65534, 65534, 65534, 65533, 65533, 65532, - 65532, 65531, 65531, 65530, 65530, 65529, 65528, 65527, 65527, - 65526, 65525, 65524, 65523, 65522, 65521, 65520, 65519, 65518, - 65516, 65515, 65514, 65513, 65511, 65510, 65508, 65507, 65505, - 65504, 65502, 65501, 65499, 65497, 65496, 65494, 65492, 65490, - 65488, 65486, 65484, 65482, 65480, 65478, 65476, 65474, 65472, - 65470, 65467, 65465, 65463, 65460, 65458, 65455, 65453, 65450, - 65448, 65445, 65442, 65440, 65437, 65434, 65431, 65429, 65426, - 65423, 65420, 65417, 65414, 65411, 65408, 65404, 65401, 65398, - 65395, 65391, 65388, 65385, 65381, 65378, 65374, 65371, 65367, - 65363, 65360, 65356, 65352, 65349, 65345, 65341, 65337, 65333, - 65329, 65325, 65321, 65317, 65313, 65309, 65305, 65300, 65296, - 65292, 65287, 65283, 65279, 65274, 65270, 65265, 65260, 65256, - 65251, 65246, 65242, 65237, 65232, 65227, 65222, 65217, 65212, - 65207, 65202, 65197, 65192, 65187, 65182, 65177, 65171, 65166, - 65161, 65155, 65150, 65144, 65139, 65133, 65128, 65122, 65117, - 65111, 65105, 65099, 65094, 65088, 65082, 65076, 65070, 65064, - 65058, 65052, 65046, 65040, 65033, 65027, 65021, 65015, 65008, - 65002, 64995, 64989, 64982, 64976, 64969, 64963, 64956, 64949, - 64943, 64936, 64929, 64922, 64915, 64908, 64902, 64895, 64887, - 64880, 64873, 64866, 64859, 64852, 64844, 64837, 64830, 64822, - 64815, 64808, 64800, 64793, 64785, 64777, 64770, 64762, 64754, - 64747, 64739, 64731, 64723, 64715, 64707, 64699, 64691, 64683, - 64675, 64667, 64659, 64651, 64642, 64634, 64626, 64617, 64609, - 64600, 64592, 64584, 64575, 64566, 64558, 64549, 64540, 64532, - 64523, 64514, 64505, 64496, 64487, 64478, 64469, 64460, 64451, - 64442, 64433, 64424, 64414, 64405, 64396, 64387, 64377, 64368, - 64358, 64349, 64339, 64330, 64320, 64310, 64301, 64291, 64281, - 64271, 64261, 64252, 64242, 64232, 64222, 64212, 64202, 64192, - 64181, 64171, 64161, 64151, 64140, 64130, 64120, 64109, 64099, - 64088, 64078, 64067, 64057, 64046, 64035, 64025, 64014, 64003, - 63992, 63981, 63971, 63960, 63949, 63938, 63927, 63915, 63904, - 63893, 63882, 63871, 63859, 63848, 63837, 63825, 63814, 63803, - 63791, 63779, 63768, 63756, 63745, 63733, 63721, 63709, 63698, - 63686, 63674, 63662, 63650, 63638, 63626, 63614, 63602, 63590, - 63578, 63565, 63553, 63541, 63528, 63516, 63504, 63491, 63479, - 63466, 63454, 63441, 63429, 63416, 63403, 63390, 63378, 63365, - 63352, 63339, 63326, 63313, 63300, 63287, 63274, 63261, 63248, - 63235, 63221, 63208, 63195, 63182, 63168, 63155, 63141, 63128, - 63114, 63101, 63087, 63074, 63060, 63046, 63032, 63019, 63005, - 62991, 62977, 62963, 62949, 62935, 62921, 62907, 62893, 62879, - 62865, 62850, 62836, 62822, 62808, 62793, 62779, 62764, 62750, - 62735, 62721, 62706, 62692, 62677, 62662, 62648, 62633, 62618, - 62603, 62588, 62573, 62558, 62543, 62528, 62513, 62498, 62483, - 62468, 62453, 62437, 62422, 62407, 62391, 62376, 62360, 62345, - 62329, 62314, 62298, 62283, 62267, 62251, 62236, 62220, 62204, - 62188, 62172, 62156, 62141, 62125, 62108, 62092, 62076, 62060, - 62044, 62028, 62012, 61995, 61979, 61963, 61946, 61930, 61913, - 61897, 61880, 61864, 61847, 61831, 61814, 61797, 61780, 61764, - 61747, 61730, 61713, 61696, 61679, 61662, 61645, 61628, 61611, - 61594, 61577, 61559, 61542, 61525, 61507, 61490, 61473, 61455, - 61438, 61420, 61403, 61385, 61367, 61350, 61332, 61314, 61297, - 61279, 61261, 61243, 61225, 61207, 61189, 61171, 61153, 61135, - 61117, 61099, 61081, 61062, 61044, 61026, 61007, 60989, 60971, - 60952, 60934, 60915, 60897, 60878, 60859, 60841, 60822, 60803, - 60785, 60766, 60747, 60728, 60709, 60690, 60671, 60652, 60633, - 60614, 60595, 60576, 60556, 60537, 60518, 60499, 60479, 60460, - 60441, 60421, 60402, 60382, 60363, 60343, 60323, 60304, 60284, - 60264, 60244, 60225, 60205, 60185, 60165, 60145, 60125, 60105, - 60085, 60065, 60045, 60025, 60004, 59984, 59964, 59944, 59923, - 59903, 59883, 59862, 59842, 59821, 59801, 59780, 59759, 59739, - 59718, 59697, 59677, 59656, 59635, 59614, 59593, 59572, 59551, - 59530, 59509, 59488, 59467, 59446, 59425, 59404, 59382, 59361, - 59340, 59318, 59297, 59276, 59254, 59233, 59211, 59190, 59168, - 59146, 59125, 59103, 59081, 59059, 59038, 59016, 58994, 58972, - 58950, 58928, 58906, 58884, 58862, 58840, 58818, 58795, 58773, - 58751, 58729, 58706, 58684, 58662, 58639, 58617, 58594, 58572, - 58549, 58527, 58504, 58481, 58459, 58436, 58413, 58390, 58367, - 58345, 58322, 58299, 58276, 58253, 58230, 58207, 58183, 58160, - 58137, 58114, 58091, 58067, 58044, 58021, 57997, 57974, 57950, - 57927, 57903, 57880, 57856, 57833, 57809, 57785, 57762, 57738, - 57714, 57690, 57666, 57642, 57618, 57594, 57570, 57546, 57522, - 57498, 57474, 57450, 57426, 57402, 57377, 57353, 57329, 57304, - 57280, 57255, 57231, 57206, 57182, 57157, 57133, 57108, 57083, - 57059, 57034, 57009, 56984, 56959, 56935, 56910, 56885, 56860, - 56835, 56810, 56785, 56760, 56734, 56709, 56684, 56659, 56633, - 56608, 56583, 56557, 56532, 56507, 56481, 56456, 56430, 56404, - 56379, 56353, 56328, 56302, 56276, 56250, 56225, 56199, 56173, - 56147, 56121, 56095, 56069, 56043, 56017, 55991, 55965, 55938, - 55912, 55886, 55860, 55833, 55807, 55781, 55754, 55728, 55701, - 55675, 55648, 55622, 55595, 55569, 55542, 55515, 55489, 55462, - 55435, 55408, 55381, 55354, 55327, 55300, 55274, 55246, 55219, - 55192, 55165, 55138, 55111, 55084, 55056, 55029, 55002, 54974, - 54947, 54920, 54892, 54865, 54837, 54810, 54782, 54755, 54727, - 54699, 54672, 54644, 54616, 54588, 54560, 54533, 54505, 54477, - 54449, 54421, 54393, 54365, 54337, 54308, 54280, 54252, 54224, - 54196, 54167, 54139, 54111, 54082, 54054, 54026, 53997, 53969, - 53940, 53911, 53883, 53854, 53826, 53797, 53768, 53739, 53711, - 53682, 53653, 53624, 53595, 53566, 53537, 53508, 53479, 53450, - 53421, 53392, 53363, 53334, 53304, 53275, 53246, 53216, 53187, - 53158, 53128, 53099, 53069, 53040, 53010, 52981, 52951, 52922, - 52892, 52862, 52832, 52803, 52773, 52743, 52713, 52683, 52653, - 52624, 52594, 52564, 52534, 52503, 52473, 52443, 52413, 52383, - 52353, 52322, 52292, 52262, 52231, 52201, 52171, 52140, 52110, - 52079, 52049, 52018, 51988, 51957, 51926, 51896, 51865, 51834, - 51803, 51773, 51742, 51711, 51680, 51649, 51618, 51587, 51556, - 51525, 51494, 51463, 51432, 51401, 51369, 51338, 51307, 51276, - 51244, 51213, 51182, 51150, 51119, 51087, 51056, 51024, 50993, - 50961, 50929, 50898, 50866, 50834, 50803, 50771, 50739, 50707, - 50675, 50644, 50612, 50580, 50548, 50516, 50484, 50452, 50420, - 50387, 50355, 50323, 50291, 50259, 50226, 50194, 50162, 50129, - 50097, 50065, 50032, 50000, 49967, 49935, 49902, 49869, 49837, - 49804, 49771, 49739, 49706, 49673, 49640, 49608, 49575, 49542, - 49509, 49476, 49443, 49410, 49377, 49344, 49311, 49278, 49244, - 49211, 49178, 49145, 49112, 49078, 49045, 49012, 48978, 48945, - 48911, 48878, 48844, 48811, 48777, 48744, 48710, 48676, 48643, - 48609, 48575, 48542, 48508, 48474, 48440, 48406, 48372, 48338, - 48304, 48271, 48237, 48202, 48168, 48134, 48100, 48066, 48032, - 47998, 47963, 47929, 47895, 47860, 47826, 47792, 47757, 47723, - 47688, 47654, 47619, 47585, 47550, 47516, 47481, 47446, 47412, - 47377, 47342, 47308, 47273, 47238, 47203, 47168, 47133, 47098, - 47063, 47028, 46993, 46958, 46923, 46888, 46853, 46818, 46783, - 46747, 46712, 46677, 46642, 46606, 46571, 46536, 46500, 46465, - 46429, 46394, 46358, 46323, 46287, 46252, 46216, 46180, 46145, - 46109, 46073, 46037, 46002, 45966, 45930, 45894, 45858, 45822, - 45786, 45750, 45714, 45678, 45642, 45606, 45570, 45534, 45498, - 45462, 45425, 45389, 45353, 45316, 45280, 45244, 45207, 45171, - 45135, 45098, 45062, 45025, 44989, 44952, 44915, 44879, 44842, - 44806, 44769, 44732, 44695, 44659, 44622, 44585, 44548, 44511, - 44474, 44437, 44400, 44363, 44326, 44289, 44252, 44215, 44178, - 44141, 44104, 44067, 44029, 43992, 43955, 43918, 43880, 43843, - 43806, 43768, 43731, 43693, 43656, 43618, 43581, 43543, 43506, - 43468, 43430, 43393, 43355, 43317, 43280, 43242, 43204, 43166, - 43128, 43091, 43053, 43015, 42977, 42939, 42901, 42863, 42825, - 42787, 42749, 42711, 42672, 42634, 42596, 42558, 42520, 42481, - 42443, 42405, 42366, 42328, 42290, 42251, 42213, 42174, 42136, - 42097, 42059, 42020, 41982, 41943, 41904, 41866, 41827, 41788, - 41750, 41711, 41672, 41633, 41595, 41556, 41517, 41478, 41439, - 41400, 41361, 41322, 41283, 41244, 41205, 41166, 41127, 41088, - 41048, 41009, 40970, 40931, 40891, 40852, 40813, 40773, 40734, - 40695, 40655, 40616, 40576, 40537, 40497, 40458, 40418, 40379, - 40339, 40300, 40260, 40220, 40180, 40141, 40101, 40061, 40021, - 39982, 39942, 39902, 39862, 39822, 39782, 39742, 39702, 39662, - 39622, 39582, 39542, 39502, 39462, 39422, 39382, 39341, 39301, - 39261, 39221, 39180, 39140, 39100, 39059, 39019, 38979, 38938, - 38898, 38857, 38817, 38776, 38736, 38695, 38655, 38614, 38573, - 38533, 38492, 38451, 38411, 38370, 38329, 38288, 38248, 38207, - 38166, 38125, 38084, 38043, 38002, 37961, 37920, 37879, 37838, - 37797, 37756, 37715, 37674, 37633, 37592, 37551, 37509, 37468, - 37427, 37386, 37344, 37303, 37262, 37220, 37179, 37137, 37096, - 37055, 37013, 36972, 36930, 36889, 36847, 36805, 36764, 36722, - 36681, 36639, 36597, 36556, 36514, 36472, 36430, 36388, 36347, - 36305, 36263, 36221, 36179, 36137, 36095, 36053, 36011, 35969, - 35927, 35885, 35843, 35801, 35759, 35717, 35675, 35633, 35590, - 35548, 35506, 35464, 35421, 35379, 35337, 35294, 35252, 35210, - 35167, 35125, 35082, 35040, 34997, 34955, 34912, 34870, 34827, - 34785, 34742, 34699, 34657, 34614, 34571, 34529, 34486, 34443, - 34400, 34358, 34315, 34272, 34229, 34186, 34143, 34100, 34057, - 34015, 33972, 33929, 33886, 33843, 33799, 33756, 33713, 33670, - 33627, 33584, 33541, 33498, 33454, 33411, 33368, 33325, 33281, - 33238, 33195, 33151, 33108, 33065, 33021, 32978, 32934, 32891, - 32847, 32804, 32760, 32717, 32673, 32630, 32586, 32542, 32499, - 32455, 32411, 32368, 32324, 32280, 32236, 32193, 32149, 32105, - 32061, 32017, 31974, 31930, 31886, 31842, 31798, 31754, 31710, - 31666, 31622, 31578, 31534, 31490, 31446, 31402, 31357, 31313, - 31269, 31225, 31181, 31136, 31092, 31048, 31004, 30959, 30915, - 30871, 30826, 30782, 30738, 30693, 30649, 30604, 30560, 30515, - 30471, 30426, 30382, 30337, 30293, 30248, 30204, 30159, 30114, - 30070, 30025, 29980, 29936, 29891, 29846, 29801, 29757, 29712, - 29667, 29622, 29577, 29533, 29488, 29443, 29398, 29353, 29308, - 29263, 29218, 29173, 29128, 29083, 29038, 28993, 28948, 28903, - 28858, 28812, 28767, 28722, 28677, 28632, 28586, 28541, 28496, - 28451, 28405, 28360, 28315, 28269, 28224, 28179, 28133, 28088, - 28042, 27997, 27952, 27906, 27861, 27815, 27770, 27724, 27678, - 27633, 27587, 27542, 27496, 27450, 27405, 27359, 27313, 27268, - 27222, 27176, 27131, 27085, 27039, 26993, 26947, 26902, 26856, - 26810, 26764, 26718, 26672, 26626, 26580, 26534, 26488, 26442, - 26396, 26350, 26304, 26258, 26212, 26166, 26120, 26074, 26028, - 25982, 25936, 25889, 25843, 25797, 25751, 25705, 25658, 25612, - 25566, 25520, 25473, 25427, 25381, 25334, 25288, 25241, 25195, - 25149, 25102, 25056, 25009, 24963, 24916, 24870, 24823, 24777, - 24730, 24684, 24637, 24591, 24544, 24497, 24451, 24404, 24357, - 24311, 24264, 24217, 24171, 24124, 24077, 24030, 23984, 23937, - 23890, 23843, 23796, 23750, 23703, 23656, 23609, 23562, 23515, - 23468, 23421, 23374, 23327, 23280, 23233, 23186, 23139, 23092, - 23045, 22998, 22951, 22904, 22857, 22810, 22763, 22716, 22668, - 22621, 22574, 22527, 22480, 22433, 22385, 22338, 22291, 22243, - 22196, 22149, 22102, 22054, 22007, 21960, 21912, 21865, 21817, - 21770, 21723, 21675, 21628, 21580, 21533, 21485, 21438, 21390, - 21343, 21295, 21248, 21200, 21153, 21105, 21057, 21010, 20962, - 20915, 20867, 20819, 20772, 20724, 20676, 20629, 20581, 20533, - 20485, 20438, 20390, 20342, 20294, 20246, 20199, 20151, 20103, - 20055, 20007, 19959, 19912, 19864, 19816, 19768, 19720, 19672, - 19624, 19576, 19528, 19480, 19432, 19384, 19336, 19288, 19240, - 19192, 19144, 19096, 19048, 19000, 18951, 18903, 18855, 18807, - 18759, 18711, 18663, 18614, 18566, 18518, 18470, 18421, 18373, - 18325, 18277, 18228, 18180, 18132, 18084, 18035, 17987, 17939, - 17890, 17842, 17793, 17745, 17697, 17648, 17600, 17551, 17503, - 17455, 17406, 17358, 17309, 17261, 17212, 17164, 17115, 17067, - 17018, 16970, 16921, 16872, 16824, 16775, 16727, 16678, 16629, - 16581, 16532, 16484, 16435, 16386, 16338, 16289, 16240, 16191, - 16143, 16094, 16045, 15997, 15948, 15899, 15850, 15802, 15753, - 15704, 15655, 15606, 15557, 15509, 15460, 15411, 15362, 15313, - 15264, 15215, 15167, 15118, 15069, 15020, 14971, 14922, 14873, - 14824, 14775, 14726, 14677, 14628, 14579, 14530, 14481, 14432, - 14383, 14334, 14285, 14236, 14187, 14138, 14089, 14040, 13990, - 13941, 13892, 13843, 13794, 13745, 13696, 13646, 13597, 13548, - 13499, 13450, 13401, 13351, 13302, 13253, 13204, 13154, 13105, - 13056, 13007, 12957, 12908, 12859, 12810, 12760, 12711, 12662, - 12612, 12563, 12514, 12464, 12415, 12366, 12316, 12267, 12218, - 12168, 12119, 12069, 12020, 11970, 11921, 11872, 11822, 11773, - 11723, 11674, 11624, 11575, 11525, 11476, 11426, 11377, 11327, - 11278, 11228, 11179, 11129, 11080, 11030, 10981, 10931, 10882, - 10832, 10782, 10733, 10683, 10634, 10584, 10534, 10485, 10435, - 10386, 10336, 10286, 10237, 10187, 10137, 10088, 10038, 9988, - 9939, 9889, 9839, 9790, 9740, 9690, 9640, 9591, 9541, - 9491, 9442, 9392, 9342, 9292, 9243, 9193, 9143, 9093, - 9043, 8994, 8944, 8894, 8844, 8794, 8745, 8695, 8645, - 8595, 8545, 8496, 8446, 8396, 8346, 8296, 8246, 8196, - 8147, 8097, 8047, 7997, 7947, 7897, 7847, 7797, 7747, - 7697, 7648, 7598, 7548, 7498, 7448, 7398, 7348, 7298, - 7248, 7198, 7148, 7098, 7048, 6998, 6948, 6898, 6848, - 6798, 6748, 6698, 6648, 6598, 6548, 6498, 6448, 6398, - 6348, 6298, 6248, 6198, 6148, 6098, 6048, 5998, 5948, - 5898, 5848, 5798, 5748, 5697, 5647, 5597, 5547, 5497, - 5447, 5397, 5347, 5297, 5247, 5197, 5146, 5096, 5046, - 4996, 4946, 4896, 4846, 4796, 4745, 4695, 4645, 4595, - 4545, 4495, 4445, 4394, 4344, 4294, 4244, 4194, 4144, - 4093, 4043, 3993, 3943, 3893, 3843, 3792, 3742, 3692, - 3642, 3592, 3541, 3491, 3441, 3391, 3341, 3291, 3240, - 3190, 3140, 3090, 3039, 2989, 2939, 2889, 2839, 2788, - 2738, 2688, 2638, 2587, 2537, 2487, 2437, 2387, 2336, - 2286, 2236, 2186, 2135, 2085, 2035, 1985, 1934, 1884, - 1834, 1784, 1733, 1683, 1633, 1583, 1532, 1482, 1432, - 1382, 1331, 1281, 1231, 1181, 1130, 1080, 1030, 980, - 929, 879, 829, 779, 728, 678, 628, 578, 527, - 477, 427, 376, 326, 276, 226, 175, 125, 75, - 25, -25, -75, -125, -175, -226, -276, -326, -376, - -427, -477, -527, -578, -628, -678, -728, -779, -829, - -879, -929, -980, -1030, -1080, -1130, -1181, -1231, -1281, - -1331, -1382, -1432, -1482, -1532, -1583, -1633, -1683, -1733, - -1784, -1834, -1884, -1934, -1985, -2035, -2085, -2135, -2186, - -2236, -2286, -2336, -2387, -2437, -2487, -2537, -2588, -2638, - -2688, -2738, -2788, -2839, -2889, -2939, -2989, -3039, -3090, - -3140, -3190, -3240, -3291, -3341, -3391, -3441, -3491, -3541, - -3592, -3642, -3692, -3742, -3792, -3843, -3893, -3943, -3993, - -4043, -4093, -4144, -4194, -4244, -4294, -4344, -4394, -4445, - -4495, -4545, -4595, -4645, -4695, -4745, -4796, -4846, -4896, - -4946, -4996, -5046, -5096, -5146, -5197, -5247, -5297, -5347, - -5397, -5447, -5497, -5547, -5597, -5647, -5697, -5748, -5798, - -5848, -5898, -5948, -5998, -6048, -6098, -6148, -6198, -6248, - -6298, -6348, -6398, -6448, -6498, -6548, -6598, -6648, -6698, - -6748, -6798, -6848, -6898, -6948, -6998, -7048, -7098, -7148, - -7198, -7248, -7298, -7348, -7398, -7448, -7498, -7548, -7598, - -7648, -7697, -7747, -7797, -7847, -7897, -7947, -7997, -8047, - -8097, -8147, -8196, -8246, -8296, -8346, -8396, -8446, -8496, - -8545, -8595, -8645, -8695, -8745, -8794, -8844, -8894, -8944, - -8994, -9043, -9093, -9143, -9193, -9243, -9292, -9342, -9392, - -9442, -9491, -9541, -9591, -9640, -9690, -9740, -9790, -9839, - -9889, -9939, -9988, -10038, -10088, -10137, -10187, -10237, -10286, - -10336, -10386, -10435, -10485, -10534, -10584, -10634, -10683, -10733, - -10782, -10832, -10882, -10931, -10981, -11030, -11080, -11129, -11179, - -11228, -11278, -11327, -11377, -11426, -11476, -11525, -11575, -11624, - -11674, -11723, -11773, -11822, -11872, -11921, -11970, -12020, -12069, - -12119, -12168, -12218, -12267, -12316, -12366, -12415, -12464, -12514, - -12563, -12612, -12662, -12711, -12760, -12810, -12859, -12908, -12957, - -13007, -13056, -13105, -13154, -13204, -13253, -13302, -13351, -13401, - -13450, -13499, -13548, -13597, -13647, -13696, -13745, -13794, -13843, - -13892, -13941, -13990, -14040, -14089, -14138, -14187, -14236, -14285, - -14334, -14383, -14432, -14481, -14530, -14579, -14628, -14677, -14726, - -14775, -14824, -14873, -14922, -14971, -15020, -15069, -15118, -15167, - -15215, -15264, -15313, -15362, -15411, -15460, -15509, -15557, -15606, - -15655, -15704, -15753, -15802, -15850, -15899, -15948, -15997, -16045, - -16094, -16143, -16191, -16240, -16289, -16338, -16386, -16435, -16484, - -16532, -16581, -16629, -16678, -16727, -16775, -16824, -16872, -16921, - -16970, -17018, -17067, -17115, -17164, -17212, -17261, -17309, -17358, - -17406, -17455, -17503, -17551, -17600, -17648, -17697, -17745, -17793, - -17842, -17890, -17939, -17987, -18035, -18084, -18132, -18180, -18228, - -18277, -18325, -18373, -18421, -18470, -18518, -18566, -18614, -18663, - -18711, -18759, -18807, -18855, -18903, -18951, -19000, -19048, -19096, - -19144, -19192, -19240, -19288, -19336, -19384, -19432, -19480, -19528, - -19576, -19624, -19672, -19720, -19768, -19816, -19864, -19912, -19959, - -20007, -20055, -20103, -20151, -20199, -20246, -20294, -20342, -20390, - -20438, -20485, -20533, -20581, -20629, -20676, -20724, -20772, -20819, - -20867, -20915, -20962, -21010, -21057, -21105, -21153, -21200, -21248, - -21295, -21343, -21390, -21438, -21485, -21533, -21580, -21628, -21675, - -21723, -21770, -21817, -21865, -21912, -21960, -22007, -22054, -22102, - -22149, -22196, -22243, -22291, -22338, -22385, -22433, -22480, -22527, - -22574, -22621, -22668, -22716, -22763, -22810, -22857, -22904, -22951, - -22998, -23045, -23092, -23139, -23186, -23233, -23280, -23327, -23374, - -23421, -23468, -23515, -23562, -23609, -23656, -23703, -23750, -23796, - -23843, -23890, -23937, -23984, -24030, -24077, -24124, -24171, -24217, - -24264, -24311, -24357, -24404, -24451, -24497, -24544, -24591, -24637, - -24684, -24730, -24777, -24823, -24870, -24916, -24963, -25009, -25056, - -25102, -25149, -25195, -25241, -25288, -25334, -25381, -25427, -25473, - -25520, -25566, -25612, -25658, -25705, -25751, -25797, -25843, -25889, - -25936, -25982, -26028, -26074, -26120, -26166, -26212, -26258, -26304, - -26350, -26396, -26442, -26488, -26534, -26580, -26626, -26672, -26718, - -26764, -26810, -26856, -26902, -26947, -26993, -27039, -27085, -27131, - -27176, -27222, -27268, -27313, -27359, -27405, -27450, -27496, -27542, - -27587, -27633, -27678, -27724, -27770, -27815, -27861, -27906, -27952, - -27997, -28042, -28088, -28133, -28179, -28224, -28269, -28315, -28360, - -28405, -28451, -28496, -28541, -28586, -28632, -28677, -28722, -28767, - -28812, -28858, -28903, -28948, -28993, -29038, -29083, -29128, -29173, - -29218, -29263, -29308, -29353, -29398, -29443, -29488, -29533, -29577, - -29622, -29667, -29712, -29757, -29801, -29846, -29891, -29936, -29980, - -30025, -30070, -30114, -30159, -30204, -30248, -30293, -30337, -30382, - -30426, -30471, -30515, -30560, -30604, -30649, -30693, -30738, -30782, - -30826, -30871, -30915, -30959, -31004, -31048, -31092, -31136, -31181, - -31225, -31269, -31313, -31357, -31402, -31446, -31490, -31534, -31578, - -31622, -31666, -31710, -31754, -31798, -31842, -31886, -31930, -31974, - -32017, -32061, -32105, -32149, -32193, -32236, -32280, -32324, -32368, - -32411, -32455, -32499, -32542, -32586, -32630, -32673, -32717, -32760, - -32804, -32847, -32891, -32934, -32978, -33021, -33065, -33108, -33151, - -33195, -33238, -33281, -33325, -33368, -33411, -33454, -33498, -33541, - -33584, -33627, -33670, -33713, -33756, -33799, -33843, -33886, -33929, - -33972, -34015, -34057, -34100, -34143, -34186, -34229, -34272, -34315, - -34358, -34400, -34443, -34486, -34529, -34571, -34614, -34657, -34699, - -34742, -34785, -34827, -34870, -34912, -34955, -34997, -35040, -35082, - -35125, -35167, -35210, -35252, -35294, -35337, -35379, -35421, -35464, - -35506, -35548, -35590, -35633, -35675, -35717, -35759, -35801, -35843, - -35885, -35927, -35969, -36011, -36053, -36095, -36137, -36179, -36221, - -36263, -36305, -36347, -36388, -36430, -36472, -36514, -36555, -36597, - -36639, -36681, -36722, -36764, -36805, -36847, -36889, -36930, -36972, - -37013, -37055, -37096, -37137, -37179, -37220, -37262, -37303, -37344, - -37386, -37427, -37468, -37509, -37551, -37592, -37633, -37674, -37715, - -37756, -37797, -37838, -37879, -37920, -37961, -38002, -38043, -38084, - -38125, -38166, -38207, -38248, -38288, -38329, -38370, -38411, -38451, - -38492, -38533, -38573, -38614, -38655, -38695, -38736, -38776, -38817, - -38857, -38898, -38938, -38979, -39019, -39059, -39100, -39140, -39180, - -39221, -39261, -39301, -39341, -39382, -39422, -39462, -39502, -39542, - -39582, -39622, -39662, -39702, -39742, -39782, -39822, -39862, -39902, - -39942, -39982, -40021, -40061, -40101, -40141, -40180, -40220, -40260, - -40299, -40339, -40379, -40418, -40458, -40497, -40537, -40576, -40616, - -40655, -40695, -40734, -40773, -40813, -40852, -40891, -40931, -40970, - -41009, -41048, -41087, -41127, -41166, -41205, -41244, -41283, -41322, - -41361, -41400, -41439, -41478, -41517, -41556, -41595, -41633, -41672, - -41711, -41750, -41788, -41827, -41866, -41904, -41943, -41982, -42020, - -42059, -42097, -42136, -42174, -42213, -42251, -42290, -42328, -42366, - -42405, -42443, -42481, -42520, -42558, -42596, -42634, -42672, -42711, - -42749, -42787, -42825, -42863, -42901, -42939, -42977, -43015, -43053, - -43091, -43128, -43166, -43204, -43242, -43280, -43317, -43355, -43393, - -43430, -43468, -43506, -43543, -43581, -43618, -43656, -43693, -43731, - -43768, -43806, -43843, -43880, -43918, -43955, -43992, -44029, -44067, - -44104, -44141, -44178, -44215, -44252, -44289, -44326, -44363, -44400, - -44437, -44474, -44511, -44548, -44585, -44622, -44659, -44695, -44732, - -44769, -44806, -44842, -44879, -44915, -44952, -44989, -45025, -45062, - -45098, -45135, -45171, -45207, -45244, -45280, -45316, -45353, -45389, - -45425, -45462, -45498, -45534, -45570, -45606, -45642, -45678, -45714, - -45750, -45786, -45822, -45858, -45894, -45930, -45966, -46002, -46037, - -46073, -46109, -46145, -46180, -46216, -46252, -46287, -46323, -46358, - -46394, -46429, -46465, -46500, -46536, -46571, -46606, -46642, -46677, - -46712, -46747, -46783, -46818, -46853, -46888, -46923, -46958, -46993, - -47028, -47063, -47098, -47133, -47168, -47203, -47238, -47273, -47308, - -47342, -47377, -47412, -47446, -47481, -47516, -47550, -47585, -47619, - -47654, -47688, -47723, -47757, -47792, -47826, -47860, -47895, -47929, - -47963, -47998, -48032, -48066, -48100, -48134, -48168, -48202, -48236, - -48271, -48304, -48338, -48372, -48406, -48440, -48474, -48508, -48542, - -48575, -48609, -48643, -48676, -48710, -48744, -48777, -48811, -48844, - -48878, -48911, -48945, -48978, -49012, -49045, -49078, -49112, -49145, - -49178, -49211, -49244, -49278, -49311, -49344, -49377, -49410, -49443, - -49476, -49509, -49542, -49575, -49608, -49640, -49673, -49706, -49739, - -49771, -49804, -49837, -49869, -49902, -49935, -49967, -50000, -50032, - -50065, -50097, -50129, -50162, -50194, -50226, -50259, -50291, -50323, - -50355, -50387, -50420, -50452, -50484, -50516, -50548, -50580, -50612, - -50644, -50675, -50707, -50739, -50771, -50803, -50834, -50866, -50898, - -50929, -50961, -50993, -51024, -51056, -51087, -51119, -51150, -51182, - -51213, -51244, -51276, -51307, -51338, -51369, -51401, -51432, -51463, - -51494, -51525, -51556, -51587, -51618, -51649, -51680, -51711, -51742, - -51773, -51803, -51834, -51865, -51896, -51926, -51957, -51988, -52018, - -52049, -52079, -52110, -52140, -52171, -52201, -52231, -52262, -52292, - -52322, -52353, -52383, -52413, -52443, -52473, -52503, -52534, -52564, - -52594, -52624, -52653, -52683, -52713, -52743, -52773, -52803, -52832, - -52862, -52892, -52922, -52951, -52981, -53010, -53040, -53069, -53099, - -53128, -53158, -53187, -53216, -53246, -53275, -53304, -53334, -53363, - -53392, -53421, -53450, -53479, -53508, -53537, -53566, -53595, -53624, - -53653, -53682, -53711, -53739, -53768, -53797, -53826, -53854, -53883, - -53911, -53940, -53969, -53997, -54026, -54054, -54082, -54111, -54139, - -54167, -54196, -54224, -54252, -54280, -54308, -54337, -54365, -54393, - -54421, -54449, -54477, -54505, -54533, -54560, -54588, -54616, -54644, - -54672, -54699, -54727, -54755, -54782, -54810, -54837, -54865, -54892, - -54920, -54947, -54974, -55002, -55029, -55056, -55084, -55111, -55138, - -55165, -55192, -55219, -55246, -55274, -55300, -55327, -55354, -55381, - -55408, -55435, -55462, -55489, -55515, -55542, -55569, -55595, -55622, - -55648, -55675, -55701, -55728, -55754, -55781, -55807, -55833, -55860, - -55886, -55912, -55938, -55965, -55991, -56017, -56043, -56069, -56095, - -56121, -56147, -56173, -56199, -56225, -56250, -56276, -56302, -56328, - -56353, -56379, -56404, -56430, -56456, -56481, -56507, -56532, -56557, - -56583, -56608, -56633, -56659, -56684, -56709, -56734, -56760, -56785, - -56810, -56835, -56860, -56885, -56910, -56935, -56959, -56984, -57009, - -57034, -57059, -57083, -57108, -57133, -57157, -57182, -57206, -57231, - -57255, -57280, -57304, -57329, -57353, -57377, -57402, -57426, -57450, - -57474, -57498, -57522, -57546, -57570, -57594, -57618, -57642, -57666, - -57690, -57714, -57738, -57762, -57785, -57809, -57833, -57856, -57880, - -57903, -57927, -57950, -57974, -57997, -58021, -58044, -58067, -58091, - -58114, -58137, -58160, -58183, -58207, -58230, -58253, -58276, -58299, - -58322, -58345, -58367, -58390, -58413, -58436, -58459, -58481, -58504, - -58527, -58549, -58572, -58594, -58617, -58639, -58662, -58684, -58706, - -58729, -58751, -58773, -58795, -58818, -58840, -58862, -58884, -58906, - -58928, -58950, -58972, -58994, -59016, -59038, -59059, -59081, -59103, - -59125, -59146, -59168, -59190, -59211, -59233, -59254, -59276, -59297, - -59318, -59340, -59361, -59382, -59404, -59425, -59446, -59467, -59488, - -59509, -59530, -59551, -59572, -59593, -59614, -59635, -59656, -59677, - -59697, -59718, -59739, -59759, -59780, -59801, -59821, -59842, -59862, - -59883, -59903, -59923, -59944, -59964, -59984, -60004, -60025, -60045, - -60065, -60085, -60105, -60125, -60145, -60165, -60185, -60205, -60225, - -60244, -60264, -60284, -60304, -60323, -60343, -60363, -60382, -60402, - -60421, -60441, -60460, -60479, -60499, -60518, -60537, -60556, -60576, - -60595, -60614, -60633, -60652, -60671, -60690, -60709, -60728, -60747, - -60766, -60785, -60803, -60822, -60841, -60859, -60878, -60897, -60915, - -60934, -60952, -60971, -60989, -61007, -61026, -61044, -61062, -61081, - -61099, -61117, -61135, -61153, -61171, -61189, -61207, -61225, -61243, - -61261, -61279, -61297, -61314, -61332, -61350, -61367, -61385, -61403, - -61420, -61438, -61455, -61473, -61490, -61507, -61525, -61542, -61559, - -61577, -61594, -61611, -61628, -61645, -61662, -61679, -61696, -61713, - -61730, -61747, -61764, -61780, -61797, -61814, -61831, -61847, -61864, - -61880, -61897, -61913, -61930, -61946, -61963, -61979, -61995, -62012, - -62028, -62044, -62060, -62076, -62092, -62108, -62125, -62141, -62156, - -62172, -62188, -62204, -62220, -62236, -62251, -62267, -62283, -62298, - -62314, -62329, -62345, -62360, -62376, -62391, -62407, -62422, -62437, - -62453, -62468, -62483, -62498, -62513, -62528, -62543, -62558, -62573, - -62588, -62603, -62618, -62633, -62648, -62662, -62677, -62692, -62706, - -62721, -62735, -62750, -62764, -62779, -62793, -62808, -62822, -62836, - -62850, -62865, -62879, -62893, -62907, -62921, -62935, -62949, -62963, - -62977, -62991, -63005, -63019, -63032, -63046, -63060, -63074, -63087, - -63101, -63114, -63128, -63141, -63155, -63168, -63182, -63195, -63208, - -63221, -63235, -63248, -63261, -63274, -63287, -63300, -63313, -63326, - -63339, -63352, -63365, -63378, -63390, -63403, -63416, -63429, -63441, - -63454, -63466, -63479, -63491, -63504, -63516, -63528, -63541, -63553, - -63565, -63578, -63590, -63602, -63614, -63626, -63638, -63650, -63662, - -63674, -63686, -63698, -63709, -63721, -63733, -63745, -63756, -63768, - -63779, -63791, -63803, -63814, -63825, -63837, -63848, -63859, -63871, - -63882, -63893, -63904, -63915, -63927, -63938, -63949, -63960, -63971, - -63981, -63992, -64003, -64014, -64025, -64035, -64046, -64057, -64067, - -64078, -64088, -64099, -64109, -64120, -64130, -64140, -64151, -64161, - -64171, -64181, -64192, -64202, -64212, -64222, -64232, -64242, -64252, - -64261, -64271, -64281, -64291, -64301, -64310, -64320, -64330, -64339, - -64349, -64358, -64368, -64377, -64387, -64396, -64405, -64414, -64424, - -64433, -64442, -64451, -64460, -64469, -64478, -64487, -64496, -64505, - -64514, -64523, -64532, -64540, -64549, -64558, -64566, -64575, -64584, - -64592, -64601, -64609, -64617, -64626, -64634, -64642, -64651, -64659, - -64667, -64675, -64683, -64691, -64699, -64707, -64715, -64723, -64731, - -64739, -64747, -64754, -64762, -64770, -64777, -64785, -64793, -64800, - -64808, -64815, -64822, -64830, -64837, -64844, -64852, -64859, -64866, - -64873, -64880, -64887, -64895, -64902, -64908, -64915, -64922, -64929, - -64936, -64943, -64949, -64956, -64963, -64969, -64976, -64982, -64989, - -64995, -65002, -65008, -65015, -65021, -65027, -65033, -65040, -65046, - -65052, -65058, -65064, -65070, -65076, -65082, -65088, -65094, -65099, - -65105, -65111, -65117, -65122, -65128, -65133, -65139, -65144, -65150, - -65155, -65161, -65166, -65171, -65177, -65182, -65187, -65192, -65197, - -65202, -65207, -65212, -65217, -65222, -65227, -65232, -65237, -65242, - -65246, -65251, -65256, -65260, -65265, -65270, -65274, -65279, -65283, - -65287, -65292, -65296, -65300, -65305, -65309, -65313, -65317, -65321, - -65325, -65329, -65333, -65337, -65341, -65345, -65349, -65352, -65356, - -65360, -65363, -65367, -65371, -65374, -65378, -65381, -65385, -65388, - -65391, -65395, -65398, -65401, -65404, -65408, -65411, -65414, -65417, - -65420, -65423, -65426, -65429, -65431, -65434, -65437, -65440, -65442, - -65445, -65448, -65450, -65453, -65455, -65458, -65460, -65463, -65465, - -65467, -65470, -65472, -65474, -65476, -65478, -65480, -65482, -65484, - -65486, -65488, -65490, -65492, -65494, -65496, -65497, -65499, -65501, - -65502, -65504, -65505, -65507, -65508, -65510, -65511, -65513, -65514, - -65515, -65516, -65518, -65519, -65520, -65521, -65522, -65523, -65524, - -65525, -65526, -65527, -65527, -65528, -65529, -65530, -65530, -65531, - -65531, -65532, -65532, -65533, -65533, -65534, -65534, -65534, -65535, - -65535, -65535, -65535, -65535, -65535, -65535, -65535, -65535, -65535, - -65535, -65535, -65535, -65535, -65534, -65534, -65534, -65533, -65533, - -65532, -65532, -65531, -65531, -65530, -65530, -65529, -65528, -65527, - -65527, -65526, -65525, -65524, -65523, -65522, -65521, -65520, -65519, - -65518, -65516, -65515, -65514, -65513, -65511, -65510, -65508, -65507, - -65505, -65504, -65502, -65501, -65499, -65497, -65496, -65494, -65492, - -65490, -65488, -65486, -65484, -65482, -65480, -65478, -65476, -65474, - -65472, -65470, -65467, -65465, -65463, -65460, -65458, -65455, -65453, - -65450, -65448, -65445, -65442, -65440, -65437, -65434, -65431, -65429, - -65426, -65423, -65420, -65417, -65414, -65411, -65408, -65404, -65401, - -65398, -65395, -65391, -65388, -65385, -65381, -65378, -65374, -65371, - -65367, -65363, -65360, -65356, -65352, -65349, -65345, -65341, -65337, - -65333, -65329, -65325, -65321, -65317, -65313, -65309, -65305, -65300, - -65296, -65292, -65287, -65283, -65279, -65274, -65270, -65265, -65260, - -65256, -65251, -65246, -65242, -65237, -65232, -65227, -65222, -65217, - -65212, -65207, -65202, -65197, -65192, -65187, -65182, -65177, -65171, - -65166, -65161, -65155, -65150, -65144, -65139, -65133, -65128, -65122, - -65117, -65111, -65105, -65099, -65094, -65088, -65082, -65076, -65070, - -65064, -65058, -65052, -65046, -65040, -65033, -65027, -65021, -65015, - -65008, -65002, -64995, -64989, -64982, -64976, -64969, -64963, -64956, - -64949, -64943, -64936, -64929, -64922, -64915, -64908, -64902, -64895, - -64887, -64880, -64873, -64866, -64859, -64852, -64844, -64837, -64830, - -64822, -64815, -64808, -64800, -64793, -64785, -64777, -64770, -64762, - -64754, -64747, -64739, -64731, -64723, -64715, -64707, -64699, -64691, - -64683, -64675, -64667, -64659, -64651, -64642, -64634, -64626, -64617, - -64609, -64601, -64592, -64584, -64575, -64566, -64558, -64549, -64540, - -64532, -64523, -64514, -64505, -64496, -64487, -64478, -64469, -64460, - -64451, -64442, -64433, -64424, -64414, -64405, -64396, -64387, -64377, - -64368, -64358, -64349, -64339, -64330, -64320, -64310, -64301, -64291, - -64281, -64271, -64261, -64252, -64242, -64232, -64222, -64212, -64202, - -64192, -64181, -64171, -64161, -64151, -64140, -64130, -64120, -64109, - -64099, -64088, -64078, -64067, -64057, -64046, -64035, -64025, -64014, - -64003, -63992, -63981, -63971, -63960, -63949, -63938, -63927, -63915, - -63904, -63893, -63882, -63871, -63859, -63848, -63837, -63825, -63814, - -63803, -63791, -63779, -63768, -63756, -63745, -63733, -63721, -63709, - -63698, -63686, -63674, -63662, -63650, -63638, -63626, -63614, -63602, - -63590, -63578, -63565, -63553, -63541, -63528, -63516, -63504, -63491, - -63479, -63466, -63454, -63441, -63429, -63416, -63403, -63390, -63378, - -63365, -63352, -63339, -63326, -63313, -63300, -63287, -63274, -63261, - -63248, -63235, -63221, -63208, -63195, -63182, -63168, -63155, -63141, - -63128, -63114, -63101, -63087, -63074, -63060, -63046, -63032, -63019, - -63005, -62991, -62977, -62963, -62949, -62935, -62921, -62907, -62893, - -62879, -62865, -62850, -62836, -62822, -62808, -62793, -62779, -62764, - -62750, -62735, -62721, -62706, -62692, -62677, -62662, -62648, -62633, - -62618, -62603, -62588, -62573, -62558, -62543, -62528, -62513, -62498, - -62483, -62468, -62453, -62437, -62422, -62407, -62391, -62376, -62360, - -62345, -62329, -62314, -62298, -62283, -62267, -62251, -62236, -62220, - -62204, -62188, -62172, -62156, -62141, -62125, -62108, -62092, -62076, - -62060, -62044, -62028, -62012, -61995, -61979, -61963, -61946, -61930, - -61913, -61897, -61880, -61864, -61847, -61831, -61814, -61797, -61780, - -61764, -61747, -61730, -61713, -61696, -61679, -61662, -61645, -61628, - -61611, -61594, -61577, -61559, -61542, -61525, -61507, -61490, -61473, - -61455, -61438, -61420, -61403, -61385, -61367, -61350, -61332, -61314, - -61297, -61279, -61261, -61243, -61225, -61207, -61189, -61171, -61153, - -61135, -61117, -61099, -61081, -61062, -61044, -61026, -61007, -60989, - -60971, -60952, -60934, -60915, -60897, -60878, -60859, -60841, -60822, - -60803, -60785, -60766, -60747, -60728, -60709, -60690, -60671, -60652, - -60633, -60614, -60595, -60576, -60556, -60537, -60518, -60499, -60479, - -60460, -60441, -60421, -60402, -60382, -60363, -60343, -60323, -60304, - -60284, -60264, -60244, -60225, -60205, -60185, -60165, -60145, -60125, - -60105, -60085, -60065, -60045, -60025, -60004, -59984, -59964, -59944, - -59923, -59903, -59883, -59862, -59842, -59821, -59801, -59780, -59759, - -59739, -59718, -59697, -59677, -59656, -59635, -59614, -59593, -59572, - -59551, -59530, -59509, -59488, -59467, -59446, -59425, -59404, -59382, - -59361, -59340, -59318, -59297, -59276, -59254, -59233, -59211, -59189, - -59168, -59146, -59125, -59103, -59081, -59059, -59038, -59016, -58994, - -58972, -58950, -58928, -58906, -58884, -58862, -58840, -58818, -58795, - -58773, -58751, -58729, -58706, -58684, -58662, -58639, -58617, -58594, - -58572, -58549, -58527, -58504, -58481, -58459, -58436, -58413, -58390, - -58367, -58345, -58322, -58299, -58276, -58253, -58230, -58207, -58183, - -58160, -58137, -58114, -58091, -58067, -58044, -58021, -57997, -57974, - -57950, -57927, -57903, -57880, -57856, -57833, -57809, -57785, -57762, - -57738, -57714, -57690, -57666, -57642, -57618, -57594, -57570, -57546, - -57522, -57498, -57474, -57450, -57426, -57402, -57377, -57353, -57329, - -57304, -57280, -57255, -57231, -57206, -57182, -57157, -57133, -57108, - -57083, -57059, -57034, -57009, -56984, -56959, -56935, -56910, -56885, - -56860, -56835, -56810, -56785, -56760, -56734, -56709, -56684, -56659, - -56633, -56608, -56583, -56557, -56532, -56507, -56481, -56456, -56430, - -56404, -56379, -56353, -56328, -56302, -56276, -56250, -56225, -56199, - -56173, -56147, -56121, -56095, -56069, -56043, -56017, -55991, -55965, - -55938, -55912, -55886, -55860, -55833, -55807, -55781, -55754, -55728, - -55701, -55675, -55648, -55622, -55595, -55569, -55542, -55515, -55489, - -55462, -55435, -55408, -55381, -55354, -55327, -55300, -55274, -55246, - -55219, -55192, -55165, -55138, -55111, -55084, -55056, -55029, -55002, - -54974, -54947, -54920, -54892, -54865, -54837, -54810, -54782, -54755, - -54727, -54699, -54672, -54644, -54616, -54588, -54560, -54533, -54505, - -54477, -54449, -54421, -54393, -54365, -54337, -54308, -54280, -54252, - -54224, -54196, -54167, -54139, -54111, -54082, -54054, -54026, -53997, - -53969, -53940, -53911, -53883, -53854, -53826, -53797, -53768, -53739, - -53711, -53682, -53653, -53624, -53595, -53566, -53537, -53508, -53479, - -53450, -53421, -53392, -53363, -53334, -53304, -53275, -53246, -53216, - -53187, -53158, -53128, -53099, -53069, -53040, -53010, -52981, -52951, - -52922, -52892, -52862, -52832, -52803, -52773, -52743, -52713, -52683, - -52653, -52624, -52594, -52564, -52534, -52503, -52473, -52443, -52413, - -52383, -52353, -52322, -52292, -52262, -52231, -52201, -52171, -52140, - -52110, -52079, -52049, -52018, -51988, -51957, -51926, -51896, -51865, - -51834, -51803, -51773, -51742, -51711, -51680, -51649, -51618, -51587, - -51556, -51525, -51494, -51463, -51432, -51401, -51369, -51338, -51307, - -51276, -51244, -51213, -51182, -51150, -51119, -51087, -51056, -51024, - -50993, -50961, -50929, -50898, -50866, -50834, -50803, -50771, -50739, - -50707, -50675, -50644, -50612, -50580, -50548, -50516, -50484, -50452, - -50420, -50387, -50355, -50323, -50291, -50259, -50226, -50194, -50162, - -50129, -50097, -50065, -50032, -50000, -49967, -49935, -49902, -49869, - -49837, -49804, -49771, -49739, -49706, -49673, -49640, -49608, -49575, - -49542, -49509, -49476, -49443, -49410, -49377, -49344, -49311, -49278, - -49244, -49211, -49178, -49145, -49112, -49078, -49045, -49012, -48978, - -48945, -48911, -48878, -48844, -48811, -48777, -48744, -48710, -48676, - -48643, -48609, -48575, -48542, -48508, -48474, -48440, -48406, -48372, - -48338, -48305, -48271, -48237, -48202, -48168, -48134, -48100, -48066, - -48032, -47998, -47963, -47929, -47895, -47860, -47826, -47792, -47757, - -47723, -47688, -47654, -47619, -47585, -47550, -47516, -47481, -47446, - -47412, -47377, -47342, -47307, -47273, -47238, -47203, -47168, -47133, - -47098, -47063, -47028, -46993, -46958, -46923, -46888, -46853, -46818, - -46783, -46747, -46712, -46677, -46642, -46606, -46571, -46536, -46500, - -46465, -46429, -46394, -46358, -46323, -46287, -46251, -46216, -46180, - -46145, -46109, -46073, -46037, -46002, -45966, -45930, -45894, -45858, - -45822, -45786, -45750, -45714, -45678, -45642, -45606, -45570, -45534, - -45498, -45462, -45425, -45389, -45353, -45316, -45280, -45244, -45207, - -45171, -45135, -45098, -45062, -45025, -44989, -44952, -44915, -44879, - -44842, -44806, -44769, -44732, -44695, -44659, -44622, -44585, -44548, - -44511, -44474, -44437, -44400, -44363, -44326, -44289, -44252, -44215, - -44178, -44141, -44104, -44067, -44029, -43992, -43955, -43918, -43880, - -43843, -43806, -43768, -43731, -43693, -43656, -43618, -43581, -43543, - -43506, -43468, -43430, -43393, -43355, -43317, -43280, -43242, -43204, - -43166, -43128, -43091, -43053, -43015, -42977, -42939, -42901, -42863, - -42825, -42787, -42749, -42711, -42672, -42634, -42596, -42558, -42520, - -42481, -42443, -42405, -42366, -42328, -42290, -42251, -42213, -42174, - -42136, -42097, -42059, -42020, -41982, -41943, -41904, -41866, -41827, - -41788, -41750, -41711, -41672, -41633, -41595, -41556, -41517, -41478, - -41439, -41400, -41361, -41322, -41283, -41244, -41205, -41166, -41127, - -41087, -41048, -41009, -40970, -40931, -40891, -40852, -40813, -40773, - -40734, -40695, -40655, -40616, -40576, -40537, -40497, -40458, -40418, - -40379, -40339, -40299, -40260, -40220, -40180, -40141, -40101, -40061, - -40021, -39982, -39942, -39902, -39862, -39822, -39782, -39742, -39702, - -39662, -39622, -39582, -39542, -39502, -39462, -39422, -39382, -39341, - -39301, -39261, -39221, -39180, -39140, -39100, -39059, -39019, -38979, - -38938, -38898, -38857, -38817, -38776, -38736, -38695, -38655, -38614, - -38573, -38533, -38492, -38451, -38411, -38370, -38329, -38288, -38248, - -38207, -38166, -38125, -38084, -38043, -38002, -37961, -37920, -37879, - -37838, -37797, -37756, -37715, -37674, -37633, -37592, -37550, -37509, - -37468, -37427, -37386, -37344, -37303, -37262, -37220, -37179, -37137, - -37096, -37055, -37013, -36972, -36930, -36889, -36847, -36805, -36764, - -36722, -36681, -36639, -36597, -36556, -36514, -36472, -36430, -36388, - -36347, -36305, -36263, -36221, -36179, -36137, -36095, -36053, -36011, - -35969, -35927, -35885, -35843, -35801, -35759, -35717, -35675, -35633, - -35590, -35548, -35506, -35464, -35421, -35379, -35337, -35294, -35252, - -35210, -35167, -35125, -35082, -35040, -34997, -34955, -34912, -34870, - -34827, -34785, -34742, -34699, -34657, -34614, -34571, -34529, -34486, - -34443, -34400, -34358, -34315, -34272, -34229, -34186, -34143, -34100, - -34057, -34015, -33972, -33929, -33886, -33843, -33799, -33756, -33713, - -33670, -33627, -33584, -33541, -33498, -33454, -33411, -33368, -33325, - -33281, -33238, -33195, -33151, -33108, -33065, -33021, -32978, -32934, - -32891, -32847, -32804, -32760, -32717, -32673, -32630, -32586, -32542, - -32499, -32455, -32411, -32368, -32324, -32280, -32236, -32193, -32149, - -32105, -32061, -32017, -31974, -31930, -31886, -31842, -31798, -31754, - -31710, -31666, -31622, -31578, -31534, -31490, -31446, -31402, -31357, - -31313, -31269, -31225, -31181, -31136, -31092, -31048, -31004, -30959, - -30915, -30871, -30826, -30782, -30738, -30693, -30649, -30604, -30560, - -30515, -30471, -30426, -30382, -30337, -30293, -30248, -30204, -30159, - -30114, -30070, -30025, -29980, -29936, -29891, -29846, -29801, -29757, - -29712, -29667, -29622, -29577, -29533, -29488, -29443, -29398, -29353, - -29308, -29263, -29218, -29173, -29128, -29083, -29038, -28993, -28948, - -28903, -28858, -28812, -28767, -28722, -28677, -28632, -28586, -28541, - -28496, -28451, -28405, -28360, -28315, -28269, -28224, -28179, -28133, - -28088, -28042, -27997, -27952, -27906, -27861, -27815, -27770, -27724, - -27678, -27633, -27587, -27542, -27496, -27450, -27405, -27359, -27313, - -27268, -27222, -27176, -27131, -27085, -27039, -26993, -26947, -26902, - -26856, -26810, -26764, -26718, -26672, -26626, -26580, -26534, -26488, - -26442, -26396, -26350, -26304, -26258, -26212, -26166, -26120, -26074, - -26028, -25982, -25936, -25889, -25843, -25797, -25751, -25705, -25658, - -25612, -25566, -25520, -25473, -25427, -25381, -25334, -25288, -25241, - -25195, -25149, -25102, -25056, -25009, -24963, -24916, -24870, -24823, - -24777, -24730, -24684, -24637, -24591, -24544, -24497, -24451, -24404, - -24357, -24311, -24264, -24217, -24171, -24124, -24077, -24030, -23984, - -23937, -23890, -23843, -23796, -23750, -23703, -23656, -23609, -23562, - -23515, -23468, -23421, -23374, -23327, -23280, -23233, -23186, -23139, - -23092, -23045, -22998, -22951, -22904, -22857, -22810, -22763, -22716, - -22668, -22621, -22574, -22527, -22480, -22432, -22385, -22338, -22291, - -22243, -22196, -22149, -22102, -22054, -22007, -21960, -21912, -21865, - -21817, -21770, -21723, -21675, -21628, -21580, -21533, -21485, -21438, - -21390, -21343, -21295, -21248, -21200, -21153, -21105, -21057, -21010, - -20962, -20915, -20867, -20819, -20772, -20724, -20676, -20629, -20581, - -20533, -20485, -20438, -20390, -20342, -20294, -20246, -20199, -20151, - -20103, -20055, -20007, -19959, -19912, -19864, -19816, -19768, -19720, - -19672, -19624, -19576, -19528, -19480, -19432, -19384, -19336, -19288, - -19240, -19192, -19144, -19096, -19048, -19000, -18951, -18903, -18855, - -18807, -18759, -18711, -18663, -18614, -18566, -18518, -18470, -18421, - -18373, -18325, -18277, -18228, -18180, -18132, -18084, -18035, -17987, - -17939, -17890, -17842, -17793, -17745, -17697, -17648, -17600, -17551, - -17503, -17455, -17406, -17358, -17309, -17261, -17212, -17164, -17115, - -17067, -17018, -16970, -16921, -16872, -16824, -16775, -16727, -16678, - -16629, -16581, -16532, -16484, -16435, -16386, -16338, -16289, -16240, - -16191, -16143, -16094, -16045, -15997, -15948, -15899, -15850, -15802, - -15753, -15704, -15655, -15606, -15557, -15509, -15460, -15411, -15362, - -15313, -15264, -15215, -15167, -15118, -15069, -15020, -14971, -14922, - -14873, -14824, -14775, -14726, -14677, -14628, -14579, -14530, -14481, - -14432, -14383, -14334, -14285, -14236, -14187, -14138, -14089, -14040, - -13990, -13941, -13892, -13843, -13794, -13745, -13696, -13647, -13597, - -13548, -13499, -13450, -13401, -13351, -13302, -13253, -13204, -13154, - -13105, -13056, -13007, -12957, -12908, -12859, -12810, -12760, -12711, - -12662, -12612, -12563, -12514, -12464, -12415, -12366, -12316, -12267, - -12217, -12168, -12119, -12069, -12020, -11970, -11921, -11872, -11822, - -11773, -11723, -11674, -11624, -11575, -11525, -11476, -11426, -11377, - -11327, -11278, -11228, -11179, -11129, -11080, -11030, -10981, -10931, - -10882, -10832, -10782, -10733, -10683, -10634, -10584, -10534, -10485, - -10435, -10386, -10336, -10286, -10237, -10187, -10137, -10088, -10038, - -9988, -9939, -9889, -9839, -9790, -9740, -9690, -9640, -9591, - -9541, -9491, -9442, -9392, -9342, -9292, -9243, -9193, -9143, - -9093, -9043, -8994, -8944, -8894, -8844, -8794, -8745, -8695, - -8645, -8595, -8545, -8496, -8446, -8396, -8346, -8296, -8246, - -8196, -8147, -8097, -8047, -7997, -7947, -7897, -7847, -7797, - -7747, -7697, -7648, -7598, -7548, -7498, -7448, -7398, -7348, - -7298, -7248, -7198, -7148, -7098, -7048, -6998, -6948, -6898, - -6848, -6798, -6748, -6698, -6648, -6598, -6548, -6498, -6448, - -6398, -6348, -6298, -6248, -6198, -6148, -6098, -6048, -5998, - -5948, -5898, -5848, -5798, -5747, -5697, -5647, -5597, -5547, - -5497, -5447, -5397, -5347, -5297, -5247, -5197, -5146, -5096, - -5046, -4996, -4946, -4896, -4846, -4796, -4745, -4695, -4645, - -4595, -4545, -4495, -4445, -4394, -4344, -4294, -4244, -4194, - -4144, -4093, -4043, -3993, -3943, -3893, -3843, -3792, -3742, - -3692, -3642, -3592, -3541, -3491, -3441, -3391, -3341, -3291, - -3240, -3190, -3140, -3090, -3039, -2989, -2939, -2889, -2839, - -2788, -2738, -2688, -2638, -2588, -2537, -2487, -2437, -2387, - -2336, -2286, -2236, -2186, -2135, -2085, -2035, -1985, -1934, - -1884, -1834, -1784, -1733, -1683, -1633, -1583, -1532, -1482, - -1432, -1382, -1331, -1281, -1231, -1181, -1130, -1080, -1030, - -980, -929, -879, -829, -779, -728, -678, -628, -578, - -527, -477, -427, -376, -326, -276, -226, -175, -125, - -75, -25, 25, 75, 125, 175, 226, 276, 326, - 376, 427, 477, 527, 578, 628, 678, 728, 779, - 829, 879, 929, 980, 1030, 1080, 1130, 1181, 1231, - 1281, 1331, 1382, 1432, 1482, 1532, 1583, 1633, 1683, - 1733, 1784, 1834, 1884, 1934, 1985, 2035, 2085, 2135, - 2186, 2236, 2286, 2336, 2387, 2437, 2487, 2537, 2587, - 2638, 2688, 2738, 2788, 2839, 2889, 2939, 2989, 3039, - 3090, 3140, 3190, 3240, 3291, 3341, 3391, 3441, 3491, - 3542, 3592, 3642, 3692, 3742, 3792, 3843, 3893, 3943, - 3993, 4043, 4093, 4144, 4194, 4244, 4294, 4344, 4394, - 4445, 4495, 4545, 4595, 4645, 4695, 4745, 4796, 4846, - 4896, 4946, 4996, 5046, 5096, 5146, 5197, 5247, 5297, - 5347, 5397, 5447, 5497, 5547, 5597, 5647, 5697, 5747, - 5798, 5848, 5898, 5948, 5998, 6048, 6098, 6148, 6198, - 6248, 6298, 6348, 6398, 6448, 6498, 6548, 6598, 6648, - 6698, 6748, 6798, 6848, 6898, 6948, 6998, 7048, 7098, - 7148, 7198, 7248, 7298, 7348, 7398, 7448, 7498, 7548, - 7598, 7648, 7697, 7747, 7797, 7847, 7897, 7947, 7997, - 8047, 8097, 8147, 8196, 8246, 8296, 8346, 8396, 8446, - 8496, 8545, 8595, 8645, 8695, 8745, 8794, 8844, 8894, - 8944, 8994, 9043, 9093, 9143, 9193, 9243, 9292, 9342, - 9392, 9442, 9491, 9541, 9591, 9640, 9690, 9740, 9790, - 9839, 9889, 9939, 9988, 10038, 10088, 10137, 10187, 10237, - 10286, 10336, 10386, 10435, 10485, 10534, 10584, 10634, 10683, - 10733, 10782, 10832, 10882, 10931, 10981, 11030, 11080, 11129, - 11179, 11228, 11278, 11327, 11377, 11426, 11476, 11525, 11575, - 11624, 11674, 11723, 11773, 11822, 11872, 11921, 11970, 12020, - 12069, 12119, 12168, 12218, 12267, 12316, 12366, 12415, 12464, - 12514, 12563, 12612, 12662, 12711, 12760, 12810, 12859, 12908, - 12957, 13007, 13056, 13105, 13154, 13204, 13253, 13302, 13351, - 13401, 13450, 13499, 13548, 13597, 13647, 13696, 13745, 13794, - 13843, 13892, 13941, 13990, 14040, 14089, 14138, 14187, 14236, - 14285, 14334, 14383, 14432, 14481, 14530, 14579, 14628, 14677, - 14726, 14775, 14824, 14873, 14922, 14971, 15020, 15069, 15118, - 15167, 15215, 15264, 15313, 15362, 15411, 15460, 15509, 15557, - 15606, 15655, 15704, 15753, 15802, 15850, 15899, 15948, 15997, - 16045, 16094, 16143, 16191, 16240, 16289, 16338, 16386, 16435, - 16484, 16532, 16581, 16629, 16678, 16727, 16775, 16824, 16872, - 16921, 16970, 17018, 17067, 17115, 17164, 17212, 17261, 17309, - 17358, 17406, 17455, 17503, 17551, 17600, 17648, 17697, 17745, - 17793, 17842, 17890, 17939, 17987, 18035, 18084, 18132, 18180, - 18228, 18277, 18325, 18373, 18421, 18470, 18518, 18566, 18614, - 18663, 18711, 18759, 18807, 18855, 18903, 18951, 19000, 19048, - 19096, 19144, 19192, 19240, 19288, 19336, 19384, 19432, 19480, - 19528, 19576, 19624, 19672, 19720, 19768, 19816, 19864, 19912, - 19959, 20007, 20055, 20103, 20151, 20199, 20246, 20294, 20342, - 20390, 20438, 20485, 20533, 20581, 20629, 20676, 20724, 20772, - 20819, 20867, 20915, 20962, 21010, 21057, 21105, 21153, 21200, - 21248, 21295, 21343, 21390, 21438, 21485, 21533, 21580, 21628, - 21675, 21723, 21770, 21817, 21865, 21912, 21960, 22007, 22054, - 22102, 22149, 22196, 22243, 22291, 22338, 22385, 22432, 22480, - 22527, 22574, 22621, 22668, 22716, 22763, 22810, 22857, 22904, - 22951, 22998, 23045, 23092, 23139, 23186, 23233, 23280, 23327, - 23374, 23421, 23468, 23515, 23562, 23609, 23656, 23703, 23750, - 23796, 23843, 23890, 23937, 23984, 24030, 24077, 24124, 24171, - 24217, 24264, 24311, 24357, 24404, 24451, 24497, 24544, 24591, - 24637, 24684, 24730, 24777, 24823, 24870, 24916, 24963, 25009, - 25056, 25102, 25149, 25195, 25241, 25288, 25334, 25381, 25427, - 25473, 25520, 25566, 25612, 25658, 25705, 25751, 25797, 25843, - 25889, 25936, 25982, 26028, 26074, 26120, 26166, 26212, 26258, - 26304, 26350, 26396, 26442, 26488, 26534, 26580, 26626, 26672, - 26718, 26764, 26810, 26856, 26902, 26947, 26993, 27039, 27085, - 27131, 27176, 27222, 27268, 27313, 27359, 27405, 27450, 27496, - 27542, 27587, 27633, 27678, 27724, 27770, 27815, 27861, 27906, - 27952, 27997, 28042, 28088, 28133, 28179, 28224, 28269, 28315, - 28360, 28405, 28451, 28496, 28541, 28586, 28632, 28677, 28722, - 28767, 28812, 28858, 28903, 28948, 28993, 29038, 29083, 29128, - 29173, 29218, 29263, 29308, 29353, 29398, 29443, 29488, 29533, - 29577, 29622, 29667, 29712, 29757, 29801, 29846, 29891, 29936, - 29980, 30025, 30070, 30114, 30159, 30204, 30248, 30293, 30337, - 30382, 30427, 30471, 30516, 30560, 30604, 30649, 30693, 30738, - 30782, 30826, 30871, 30915, 30959, 31004, 31048, 31092, 31136, - 31181, 31225, 31269, 31313, 31357, 31402, 31446, 31490, 31534, - 31578, 31622, 31666, 31710, 31754, 31798, 31842, 31886, 31930, - 31974, 32017, 32061, 32105, 32149, 32193, 32236, 32280, 32324, - 32368, 32411, 32455, 32499, 32542, 32586, 32630, 32673, 32717, - 32760, 32804, 32847, 32891, 32934, 32978, 33021, 33065, 33108, - 33151, 33195, 33238, 33281, 33325, 33368, 33411, 33454, 33498, - 33541, 33584, 33627, 33670, 33713, 33756, 33799, 33843, 33886, - 33929, 33972, 34015, 34057, 34100, 34143, 34186, 34229, 34272, - 34315, 34358, 34400, 34443, 34486, 34529, 34571, 34614, 34657, - 34699, 34742, 34785, 34827, 34870, 34912, 34955, 34997, 35040, - 35082, 35125, 35167, 35210, 35252, 35294, 35337, 35379, 35421, - 35464, 35506, 35548, 35590, 35633, 35675, 35717, 35759, 35801, - 35843, 35885, 35927, 35969, 36011, 36053, 36095, 36137, 36179, - 36221, 36263, 36305, 36347, 36388, 36430, 36472, 36514, 36556, - 36597, 36639, 36681, 36722, 36764, 36805, 36847, 36889, 36930, - 36972, 37013, 37055, 37096, 37137, 37179, 37220, 37262, 37303, - 37344, 37386, 37427, 37468, 37509, 37551, 37592, 37633, 37674, - 37715, 37756, 37797, 37838, 37879, 37920, 37961, 38002, 38043, - 38084, 38125, 38166, 38207, 38248, 38288, 38329, 38370, 38411, - 38451, 38492, 38533, 38573, 38614, 38655, 38695, 38736, 38776, - 38817, 38857, 38898, 38938, 38979, 39019, 39059, 39100, 39140, - 39180, 39221, 39261, 39301, 39341, 39382, 39422, 39462, 39502, - 39542, 39582, 39622, 39662, 39702, 39742, 39782, 39822, 39862, - 39902, 39942, 39982, 40021, 40061, 40101, 40141, 40180, 40220, - 40260, 40299, 40339, 40379, 40418, 40458, 40497, 40537, 40576, - 40616, 40655, 40695, 40734, 40773, 40813, 40852, 40891, 40931, - 40970, 41009, 41048, 41087, 41127, 41166, 41205, 41244, 41283, - 41322, 41361, 41400, 41439, 41478, 41517, 41556, 41595, 41633, - 41672, 41711, 41750, 41788, 41827, 41866, 41904, 41943, 41982, - 42020, 42059, 42097, 42136, 42174, 42213, 42251, 42290, 42328, - 42366, 42405, 42443, 42481, 42520, 42558, 42596, 42634, 42672, - 42711, 42749, 42787, 42825, 42863, 42901, 42939, 42977, 43015, - 43053, 43091, 43128, 43166, 43204, 43242, 43280, 43317, 43355, - 43393, 43430, 43468, 43506, 43543, 43581, 43618, 43656, 43693, - 43731, 43768, 43806, 43843, 43880, 43918, 43955, 43992, 44029, - 44067, 44104, 44141, 44178, 44215, 44252, 44289, 44326, 44363, - 44400, 44437, 44474, 44511, 44548, 44585, 44622, 44659, 44695, - 44732, 44769, 44806, 44842, 44879, 44915, 44952, 44989, 45025, - 45062, 45098, 45135, 45171, 45207, 45244, 45280, 45316, 45353, - 45389, 45425, 45462, 45498, 45534, 45570, 45606, 45642, 45678, - 45714, 45750, 45786, 45822, 45858, 45894, 45930, 45966, 46002, - 46037, 46073, 46109, 46145, 46180, 46216, 46252, 46287, 46323, - 46358, 46394, 46429, 46465, 46500, 46536, 46571, 46606, 46642, - 46677, 46712, 46747, 46783, 46818, 46853, 46888, 46923, 46958, - 46993, 47028, 47063, 47098, 47133, 47168, 47203, 47238, 47273, - 47308, 47342, 47377, 47412, 47446, 47481, 47516, 47550, 47585, - 47619, 47654, 47688, 47723, 47757, 47792, 47826, 47861, 47895, - 47929, 47963, 47998, 48032, 48066, 48100, 48134, 48168, 48202, - 48237, 48271, 48305, 48338, 48372, 48406, 48440, 48474, 48508, - 48542, 48575, 48609, 48643, 48676, 48710, 48744, 48777, 48811, - 48844, 48878, 48911, 48945, 48978, 49012, 49045, 49078, 49112, - 49145, 49178, 49211, 49244, 49278, 49311, 49344, 49377, 49410, - 49443, 49476, 49509, 49542, 49575, 49608, 49640, 49673, 49706, - 49739, 49771, 49804, 49837, 49869, 49902, 49935, 49967, 50000, - 50032, 50064, 50097, 50129, 50162, 50194, 50226, 50259, 50291, - 50323, 50355, 50387, 50420, 50452, 50484, 50516, 50548, 50580, - 50612, 50644, 50675, 50707, 50739, 50771, 50803, 50834, 50866, - 50898, 50929, 50961, 50993, 51024, 51056, 51087, 51119, 51150, - 51182, 51213, 51244, 51276, 51307, 51338, 51369, 51401, 51432, - 51463, 51494, 51525, 51556, 51587, 51618, 51649, 51680, 51711, - 51742, 51773, 51803, 51834, 51865, 51896, 51926, 51957, 51988, - 52018, 52049, 52079, 52110, 52140, 52171, 52201, 52231, 52262, - 52292, 52322, 52353, 52383, 52413, 52443, 52473, 52503, 52534, - 52564, 52594, 52624, 52653, 52683, 52713, 52743, 52773, 52803, - 52832, 52862, 52892, 52922, 52951, 52981, 53010, 53040, 53069, - 53099, 53128, 53158, 53187, 53216, 53246, 53275, 53304, 53334, - 53363, 53392, 53421, 53450, 53479, 53508, 53537, 53566, 53595, - 53624, 53653, 53682, 53711, 53739, 53768, 53797, 53826, 53854, - 53883, 53912, 53940, 53969, 53997, 54026, 54054, 54082, 54111, - 54139, 54167, 54196, 54224, 54252, 54280, 54309, 54337, 54365, - 54393, 54421, 54449, 54477, 54505, 54533, 54560, 54588, 54616, - 54644, 54672, 54699, 54727, 54755, 54782, 54810, 54837, 54865, - 54892, 54920, 54947, 54974, 55002, 55029, 55056, 55084, 55111, - 55138, 55165, 55192, 55219, 55246, 55274, 55300, 55327, 55354, - 55381, 55408, 55435, 55462, 55489, 55515, 55542, 55569, 55595, - 55622, 55648, 55675, 55701, 55728, 55754, 55781, 55807, 55833, - 55860, 55886, 55912, 55938, 55965, 55991, 56017, 56043, 56069, - 56095, 56121, 56147, 56173, 56199, 56225, 56250, 56276, 56302, - 56328, 56353, 56379, 56404, 56430, 56456, 56481, 56507, 56532, - 56557, 56583, 56608, 56633, 56659, 56684, 56709, 56734, 56760, - 56785, 56810, 56835, 56860, 56885, 56910, 56935, 56959, 56984, - 57009, 57034, 57059, 57083, 57108, 57133, 57157, 57182, 57206, - 57231, 57255, 57280, 57304, 57329, 57353, 57377, 57402, 57426, - 57450, 57474, 57498, 57522, 57546, 57570, 57594, 57618, 57642, - 57666, 57690, 57714, 57738, 57762, 57785, 57809, 57833, 57856, - 57880, 57903, 57927, 57950, 57974, 57997, 58021, 58044, 58067, - 58091, 58114, 58137, 58160, 58183, 58207, 58230, 58253, 58276, - 58299, 58322, 58345, 58367, 58390, 58413, 58436, 58459, 58481, - 58504, 58527, 58549, 58572, 58594, 58617, 58639, 58662, 58684, - 58706, 58729, 58751, 58773, 58795, 58818, 58840, 58862, 58884, - 58906, 58928, 58950, 58972, 58994, 59016, 59038, 59059, 59081, - 59103, 59125, 59146, 59168, 59190, 59211, 59233, 59254, 59276, - 59297, 59318, 59340, 59361, 59382, 59404, 59425, 59446, 59467, - 59488, 59509, 59530, 59551, 59572, 59593, 59614, 59635, 59656, - 59677, 59697, 59718, 59739, 59759, 59780, 59801, 59821, 59842, - 59862, 59883, 59903, 59923, 59944, 59964, 59984, 60004, 60025, - 60045, 60065, 60085, 60105, 60125, 60145, 60165, 60185, 60205, - 60225, 60244, 60264, 60284, 60304, 60323, 60343, 60363, 60382, - 60402, 60421, 60441, 60460, 60479, 60499, 60518, 60537, 60556, - 60576, 60595, 60614, 60633, 60652, 60671, 60690, 60709, 60728, - 60747, 60766, 60785, 60803, 60822, 60841, 60859, 60878, 60897, - 60915, 60934, 60952, 60971, 60989, 61007, 61026, 61044, 61062, - 61081, 61099, 61117, 61135, 61153, 61171, 61189, 61207, 61225, - 61243, 61261, 61279, 61297, 61314, 61332, 61350, 61367, 61385, - 61403, 61420, 61438, 61455, 61473, 61490, 61507, 61525, 61542, - 61559, 61577, 61594, 61611, 61628, 61645, 61662, 61679, 61696, - 61713, 61730, 61747, 61764, 61780, 61797, 61814, 61831, 61847, - 61864, 61880, 61897, 61913, 61930, 61946, 61963, 61979, 61995, - 62012, 62028, 62044, 62060, 62076, 62092, 62108, 62125, 62141, - 62156, 62172, 62188, 62204, 62220, 62236, 62251, 62267, 62283, - 62298, 62314, 62329, 62345, 62360, 62376, 62391, 62407, 62422, - 62437, 62453, 62468, 62483, 62498, 62513, 62528, 62543, 62558, - 62573, 62588, 62603, 62618, 62633, 62648, 62662, 62677, 62692, - 62706, 62721, 62735, 62750, 62764, 62779, 62793, 62808, 62822, - 62836, 62850, 62865, 62879, 62893, 62907, 62921, 62935, 62949, - 62963, 62977, 62991, 63005, 63019, 63032, 63046, 63060, 63074, - 63087, 63101, 63114, 63128, 63141, 63155, 63168, 63182, 63195, - 63208, 63221, 63235, 63248, 63261, 63274, 63287, 63300, 63313, - 63326, 63339, 63352, 63365, 63378, 63390, 63403, 63416, 63429, - 63441, 63454, 63466, 63479, 63491, 63504, 63516, 63528, 63541, - 63553, 63565, 63578, 63590, 63602, 63614, 63626, 63638, 63650, - 63662, 63674, 63686, 63698, 63709, 63721, 63733, 63745, 63756, - 63768, 63779, 63791, 63803, 63814, 63825, 63837, 63848, 63859, - 63871, 63882, 63893, 63904, 63915, 63927, 63938, 63949, 63960, - 63971, 63981, 63992, 64003, 64014, 64025, 64035, 64046, 64057, - 64067, 64078, 64088, 64099, 64109, 64120, 64130, 64140, 64151, - 64161, 64171, 64181, 64192, 64202, 64212, 64222, 64232, 64242, - 64252, 64261, 64271, 64281, 64291, 64301, 64310, 64320, 64330, - 64339, 64349, 64358, 64368, 64377, 64387, 64396, 64405, 64414, - 64424, 64433, 64442, 64451, 64460, 64469, 64478, 64487, 64496, - 64505, 64514, 64523, 64532, 64540, 64549, 64558, 64566, 64575, - 64584, 64592, 64600, 64609, 64617, 64626, 64634, 64642, 64651, - 64659, 64667, 64675, 64683, 64691, 64699, 64707, 64715, 64723, - 64731, 64739, 64747, 64754, 64762, 64770, 64777, 64785, 64793, - 64800, 64808, 64815, 64822, 64830, 64837, 64844, 64852, 64859, - 64866, 64873, 64880, 64887, 64895, 64902, 64908, 64915, 64922, - 64929, 64936, 64943, 64949, 64956, 64963, 64969, 64976, 64982, - 64989, 64995, 65002, 65008, 65015, 65021, 65027, 65033, 65040, - 65046, 65052, 65058, 65064, 65070, 65076, 65082, 65088, 65094, - 65099, 65105, 65111, 65117, 65122, 65128, 65133, 65139, 65144, - 65150, 65155, 65161, 65166, 65171, 65177, 65182, 65187, 65192, - 65197, 65202, 65207, 65212, 65217, 65222, 65227, 65232, 65237, - 65242, 65246, 65251, 65256, 65260, 65265, 65270, 65274, 65279, - 65283, 65287, 65292, 65296, 65300, 65305, 65309, 65313, 65317, - 65321, 65325, 65329, 65333, 65337, 65341, 65345, 65349, 65352, - 65356, 65360, 65363, 65367, 65371, 65374, 65378, 65381, 65385, - 65388, 65391, 65395, 65398, 65401, 65404, 65408, 65411, 65414, - 65417, 65420, 65423, 65426, 65429, 65431, 65434, 65437, 65440, - 65442, 65445, 65448, 65450, 65453, 65455, 65458, 65460, 65463, - 65465, 65467, 65470, 65472, 65474, 65476, 65478, 65480, 65482, - 65484, 65486, 65488, 65490, 65492, 65494, 65496, 65497, 65499, - 65501, 65502, 65504, 65505, 65507, 65508, 65510, 65511, 65513, - 65514, 65515, 65516, 65518, 65519, 65520, 65521, 65522, 65523, - 65524, 65525, 65526, 65527, 65527, 65528, 65529, 65530, 65530, - 65531, 65531, 65532, 65532, 65533, 65533, 65534, 65534, 65534, - 65535, 65535, 65535, 65535, 65535, 65535, 65535, -}; - -const fixed_t *finecosine = &finesine[FINEANGLES / 4]; - -const angle_t tantoangle[2049] = -{ - 0, 333772, 667544, 1001315, 1335086, 1668857, - 2002626, 2336395, 2670163, 3003929, 3337694, 3671457, - 4005219, 4338979, 4672736, 5006492, 5340245, 5673995, - 6007743, 6341488, 6675230, 7008968, 7342704, 7676435, - 8010164, 8343888, 8677609, 9011325, 9345037, 9678744, - 10012447, 10346145, 10679838, 11013526, 11347209, 11680887, - 12014558, 12348225, 12681885, 13015539, 13349187, 13682829, - 14016464, 14350092, 14683714, 15017328, 15350936, 15684536, - 16018129, 16351714, 16685291, 17018860, 17352422, 17685974, - 18019518, 18353054, 18686582, 19020100, 19353610, 19687110, - 20020600, 20354080, 20687552, 21021014, 21354466, 21687906, - 22021338, 22354758, 22688168, 23021568, 23354956, 23688332, - 24021698, 24355052, 24688396, 25021726, 25355046, 25688352, - 26021648, 26354930, 26688200, 27021456, 27354702, 27687932, - 28021150, 28354356, 28687548, 29020724, 29353888, 29687038, - 30020174, 30353296, 30686404, 31019496, 31352574, 31685636, - 32018684, 32351718, 32684734, 33017736, 33350722, 33683692, - 34016648, 34349584, 34682508, 35015412, 35348300, 35681172, - 36014028, 36346868, 36679688, 37012492, 37345276, 37678044, - 38010792, 38343524, 38676240, 39008936, 39341612, 39674272, - 40006912, 40339532, 40672132, 41004716, 41337276, 41669820, - 42002344, 42334848, 42667332, 42999796, 43332236, 43664660, - 43997060, 44329444, 44661800, 44994140, 45326456, 45658752, - 45991028, 46323280, 46655512, 46987720, 47319908, 47652072, - 47984212, 48316332, 48648428, 48980500, 49312548, 49644576, - 49976580, 50308556, 50640512, 50972444, 51304352, 51636236, - 51968096, 52299928, 52631740, 52963524, 53295284, 53627020, - 53958728, 54290412, 54622068, 54953704, 55285308, 55616888, - 55948444, 56279972, 56611472, 56942948, 57274396, 57605816, - 57937212, 58268576, 58599916, 58931228, 59262512, 59593768, - 59924992, 60256192, 60587364, 60918508, 61249620, 61580704, - 61911760, 62242788, 62573788, 62904756, 63235692, 63566604, - 63897480, 64228332, 64559148, 64889940, 65220696, 65551424, - 65882120, 66212788, 66543420, 66874024, 67204600, 67535136, - 67865648, 68196120, 68526568, 68856984, 69187360, 69517712, - 69848024, 70178304, 70508560, 70838776, 71168960, 71499112, - 71829224, 72159312, 72489360, 72819376, 73149360, 73479304, - 73809216, 74139096, 74468936, 74798744, 75128520, 75458264, - 75787968, 76117632, 76447264, 76776864, 77106424, 77435952, - 77765440, 78094888, 78424304, 78753688, 79083032, 79412336, - 79741608, 80070840, 80400032, 80729192, 81058312, 81387392, - 81716432, 82045440, 82374408, 82703336, 83032224, 83361080, - 83689896, 84018664, 84347400, 84676096, 85004760, 85333376, - 85661952, 85990488, 86318984, 86647448, 86975864, 87304240, - 87632576, 87960872, 88289128, 88617344, 88945520, 89273648, - 89601736, 89929792, 90257792, 90585760, 90913688, 91241568, - 91569408, 91897200, 92224960, 92552672, 92880336, 93207968, - 93535552, 93863088, 94190584, 94518040, 94845448, 95172816, - 95500136, 95827416, 96154648, 96481832, 96808976, 97136080, - 97463136, 97790144, 98117112, 98444032, 98770904, 99097736, - 99424520, 99751256, 100077944, 100404592, 100731192, 101057744, - 101384248, 101710712, 102037128, 102363488, 102689808, 103016080, - 103342312, 103668488, 103994616, 104320696, 104646736, 104972720, - 105298656, 105624552, 105950392, 106276184, 106601928, 106927624, - 107253272, 107578872, 107904416, 108229920, 108555368, 108880768, - 109206120, 109531416, 109856664, 110181872, 110507016, 110832120, - 111157168, 111482168, 111807112, 112132008, 112456856, 112781648, - 113106392, 113431080, 113755720, 114080312, 114404848, 114729328, - 115053760, 115378136, 115702464, 116026744, 116350960, 116675128, - 116999248, 117323312, 117647320, 117971272, 118295176, 118619024, - 118942816, 119266560, 119590248, 119913880, 120237456, 120560984, - 120884456, 121207864, 121531224, 121854528, 122177784, 122500976, - 122824112, 123147200, 123470224, 123793200, 124116120, 124438976, - 124761784, 125084528, 125407224, 125729856, 126052432, 126374960, - 126697424, 127019832, 127342184, 127664472, 127986712, 128308888, - 128631008, 128953072, 129275080, 129597024, 129918912, 130240744, - 130562520, 130884232, 131205888, 131527480, 131849016, 132170496, - 132491912, 132813272, 133134576, 133455816, 133776992, 134098120, - 134419184, 134740176, 135061120, 135382000, 135702816, 136023584, - 136344272, 136664912, 136985488, 137306016, 137626464, 137946864, - 138267184, 138587456, 138907664, 139227808, 139547904, 139867920, - 140187888, 140507776, 140827616, 141147392, 141467104, 141786752, - 142106336, 142425856, 142745312, 143064720, 143384048, 143703312, - 144022512, 144341664, 144660736, 144979744, 145298704, 145617584, - 145936400, 146255168, 146573856, 146892480, 147211040, 147529536, - 147847968, 148166336, 148484640, 148802880, 149121056, 149439152, - 149757200, 150075168, 150393072, 150710912, 151028688, 151346400, - 151664048, 151981616, 152299136, 152616576, 152933952, 153251264, - 153568496, 153885680, 154202784, 154519824, 154836784, 155153696, - 155470528, 155787296, 156104000, 156420624, 156737200, 157053696, - 157370112, 157686480, 158002768, 158318976, 158635136, 158951216, - 159267232, 159583168, 159899040, 160214848, 160530592, 160846256, - 161161840, 161477376, 161792832, 162108208, 162423520, 162738768, - 163053952, 163369040, 163684080, 163999040, 164313936, 164628752, - 164943504, 165258176, 165572784, 165887312, 166201776, 166516160, - 166830480, 167144736, 167458912, 167773008, 168087040, 168400992, - 168714880, 169028688, 169342432, 169656096, 169969696, 170283216, - 170596672, 170910032, 171223344, 171536576, 171849728, 172162800, - 172475808, 172788736, 173101600, 173414384, 173727104, 174039728, - 174352288, 174664784, 174977200, 175289536, 175601792, 175913984, - 176226096, 176538144, 176850096, 177161984, 177473792, 177785536, - 178097200, 178408784, 178720288, 179031728, 179343088, 179654368, - 179965568, 180276704, 180587744, 180898720, 181209616, 181520448, - 181831184, 182141856, 182452448, 182762960, 183073408, 183383760, - 183694048, 184004240, 184314368, 184624416, 184934400, 185244288, - 185554096, 185863840, 186173504, 186483072, 186792576, 187102000, - 187411344, 187720608, 188029808, 188338912, 188647936, 188956896, - 189265760, 189574560, 189883264, 190191904, 190500448, 190808928, - 191117312, 191425632, 191733872, 192042016, 192350096, 192658096, - 192966000, 193273840, 193581584, 193889264, 194196848, 194504352, - 194811792, 195119136, 195426400, 195733584, 196040688, 196347712, - 196654656, 196961520, 197268304, 197574992, 197881616, 198188144, - 198494592, 198800960, 199107248, 199413456, 199719584, 200025616, - 200331584, 200637456, 200943248, 201248960, 201554576, 201860128, - 202165584, 202470960, 202776256, 203081456, 203386592, 203691632, - 203996592, 204301472, 204606256, 204910976, 205215600, 205520144, - 205824592, 206128960, 206433248, 206737456, 207041584, 207345616, - 207649568, 207953424, 208257216, 208560912, 208864512, 209168048, - 209471488, 209774832, 210078112, 210381296, 210684384, 210987408, - 211290336, 211593184, 211895936, 212198608, 212501184, 212803680, - 213106096, 213408432, 213710672, 214012816, 214314880, 214616864, - 214918768, 215220576, 215522288, 215823920, 216125472, 216426928, - 216728304, 217029584, 217330784, 217631904, 217932928, 218233856, - 218534704, 218835472, 219136144, 219436720, 219737216, 220037632, - 220337952, 220638192, 220938336, 221238384, 221538352, 221838240, - 222138032, 222437728, 222737344, 223036880, 223336304, 223635664, - 223934912, 224234096, 224533168, 224832160, 225131072, 225429872, - 225728608, 226027232, 226325776, 226624240, 226922608, 227220880, - 227519056, 227817152, 228115168, 228413088, 228710912, 229008640, - 229306288, 229603840, 229901312, 230198688, 230495968, 230793152, - 231090256, 231387280, 231684192, 231981024, 232277760, 232574416, - 232870960, 233167440, 233463808, 233760096, 234056288, 234352384, - 234648384, 234944304, 235240128, 235535872, 235831504, 236127056, - 236422512, 236717888, 237013152, 237308336, 237603424, 237898416, - 238193328, 238488144, 238782864, 239077488, 239372016, 239666464, - 239960816, 240255072, 240549232, 240843312, 241137280, 241431168, - 241724960, 242018656, 242312256, 242605776, 242899200, 243192512, - 243485744, 243778896, 244071936, 244364880, 244657744, 244950496, - 245243168, 245535744, 245828224, 246120608, 246412912, 246705104, - 246997216, 247289216, 247581136, 247872960, 248164688, 248456320, - 248747856, 249039296, 249330640, 249621904, 249913056, 250204128, - 250495088, 250785968, 251076736, 251367424, 251658016, 251948512, - 252238912, 252529200, 252819408, 253109520, 253399536, 253689456, - 253979280, 254269008, 254558640, 254848176, 255137632, 255426976, - 255716224, 256005376, 256294432, 256583392, 256872256, 257161024, - 257449696, 257738272, 258026752, 258315136, 258603424, 258891600, - 259179696, 259467696, 259755600, 260043392, 260331104, 260618704, - 260906224, 261193632, 261480960, 261768176, 262055296, 262342320, - 262629248, 262916080, 263202816, 263489456, 263776000, 264062432, - 264348784, 264635024, 264921168, 265207216, 265493168, 265779024, - 266064784, 266350448, 266636000, 266921472, 267206832, 267492096, - 267777264, 268062336, 268347312, 268632192, 268916960, 269201632, - 269486208, 269770688, 270055072, 270339360, 270623552, 270907616, - 271191616, 271475488, 271759296, 272042976, 272326560, 272610048, - 272893440, 273176736, 273459936, 273743040, 274026048, 274308928, - 274591744, 274874432, 275157024, 275439520, 275721920, 276004224, - 276286432, 276568512, 276850528, 277132416, 277414240, 277695936, - 277977536, 278259040, 278540448, 278821728, 279102944, 279384032, - 279665056, 279945952, 280226752, 280507456, 280788064, 281068544, - 281348960, 281629248, 281909472, 282189568, 282469568, 282749440, - 283029248, 283308960, 283588544, 283868032, 284147424, 284426720, - 284705920, 284985024, 285264000, 285542912, 285821696, 286100384, - 286378976, 286657440, 286935840, 287214112, 287492320, 287770400, - 288048384, 288326240, 288604032, 288881696, 289159264, 289436768, - 289714112, 289991392, 290268576, 290545632, 290822592, 291099456, - 291376224, 291652896, 291929440, 292205888, 292482272, 292758528, - 293034656, 293310720, 293586656, 293862496, 294138240, 294413888, - 294689440, 294964864, 295240192, 295515424, 295790560, 296065600, - 296340512, 296615360, 296890080, 297164704, 297439200, 297713632, - 297987936, 298262144, 298536256, 298810240, 299084160, 299357952, - 299631648, 299905248, 300178720, 300452128, 300725408, 300998592, - 301271680, 301544640, 301817536, 302090304, 302362976, 302635520, - 302908000, 303180352, 303452608, 303724768, 303996800, 304268768, - 304540608, 304812320, 305083968, 305355520, 305626944, 305898272, - 306169472, 306440608, 306711616, 306982528, 307253344, 307524064, - 307794656, 308065152, 308335552, 308605856, 308876032, 309146112, - 309416096, 309685984, 309955744, 310225408, 310494976, 310764448, - 311033824, 311303072, 311572224, 311841280, 312110208, 312379040, - 312647776, 312916416, 313184960, 313453376, 313721696, 313989920, - 314258016, 314526016, 314793920, 315061728, 315329408, 315597024, - 315864512, 316131872, 316399168, 316666336, 316933408, 317200384, - 317467232, 317733984, 318000640, 318267200, 318533632, 318799968, - 319066208, 319332352, 319598368, 319864288, 320130112, 320395808, - 320661408, 320926912, 321192320, 321457632, 321722816, 321987904, - 322252864, 322517760, 322782528, 323047200, 323311744, 323576192, - 323840544, 324104800, 324368928, 324632992, 324896928, 325160736, - 325424448, 325688096, 325951584, 326215008, 326478304, 326741504, - 327004608, 327267584, 327530464, 327793248, 328055904, 328318496, - 328580960, 328843296, 329105568, 329367712, 329629760, 329891680, - 330153536, 330415264, 330676864, 330938400, 331199808, 331461120, - 331722304, 331983392, 332244384, 332505280, 332766048, 333026752, - 333287296, 333547776, 333808128, 334068384, 334328544, 334588576, - 334848512, 335108352, 335368064, 335627712, 335887200, 336146624, - 336405920, 336665120, 336924224, 337183200, 337442112, 337700864, - 337959552, 338218112, 338476576, 338734944, 338993184, 339251328, - 339509376, 339767296, 340025120, 340282848, 340540480, 340797984, - 341055392, 341312704, 341569888, 341826976, 342083968, 342340832, - 342597600, 342854272, 343110848, 343367296, 343623648, 343879904, - 344136032, 344392064, 344648000, 344903808, 345159520, 345415136, - 345670656, 345926048, 346181344, 346436512, 346691616, 346946592, - 347201440, 347456224, 347710880, 347965440, 348219872, 348474208, - 348728448, 348982592, 349236608, 349490528, 349744320, 349998048, - 350251648, 350505152, 350758528, 351011808, 351264992, 351518048, - 351771040, 352023872, 352276640, 352529280, 352781824, 353034272, - 353286592, 353538816, 353790944, 354042944, 354294880, 354546656, - 354798368, 355049952, 355301440, 355552800, 355804096, 356055264, - 356306304, 356557280, 356808128, 357058848, 357309504, 357560032, - 357810464, 358060768, 358311008, 358561088, 358811104, 359060992, - 359310784, 359560480, 359810048, 360059520, 360308896, 360558144, - 360807296, 361056352, 361305312, 361554144, 361802880, 362051488, - 362300032, 362548448, 362796736, 363044960, 363293056, 363541024, - 363788928, 364036704, 364284384, 364531936, 364779392, 365026752, - 365274016, 365521152, 365768192, 366015136, 366261952, 366508672, - 366755296, 367001792, 367248192, 367494496, 367740704, 367986784, - 368232768, 368478656, 368724416, 368970080, 369215648, 369461088, - 369706432, 369951680, 370196800, 370441824, 370686752, 370931584, - 371176288, 371420896, 371665408, 371909792, 372154080, 372398272, - 372642336, 372886304, 373130176, 373373952, 373617600, 373861152, - 374104608, 374347936, 374591168, 374834304, 375077312, 375320224, - 375563040, 375805760, 376048352, 376290848, 376533248, 376775520, - 377017696, 377259776, 377501728, 377743584, 377985344, 378227008, - 378468544, 378709984, 378951328, 379192544, 379433664, 379674688, - 379915584, 380156416, 380397088, 380637696, 380878176, 381118560, - 381358848, 381599040, 381839104, 382079072, 382318912, 382558656, - 382798304, 383037856, 383277280, 383516640, 383755840, 383994976, - 384233984, 384472896, 384711712, 384950400, 385188992, 385427488, - 385665888, 385904160, 386142336, 386380384, 386618368, 386856224, - 387093984, 387331616, 387569152, 387806592, 388043936, 388281152, - 388518272, 388755296, 388992224, 389229024, 389465728, 389702336, - 389938816, 390175200, 390411488, 390647680, 390883744, 391119712, - 391355584, 391591328, 391826976, 392062528, 392297984, 392533312, - 392768544, 393003680, 393238720, 393473632, 393708448, 393943168, - 394177760, 394412256, 394646656, 394880960, 395115136, 395349216, - 395583200, 395817088, 396050848, 396284512, 396518080, 396751520, - 396984864, 397218112, 397451264, 397684288, 397917248, 398150080, - 398382784, 398615424, 398847936, 399080320, 399312640, 399544832, - 399776928, 400008928, 400240832, 400472608, 400704288, 400935872, - 401167328, 401398720, 401629984, 401861120, 402092192, 402323136, - 402553984, 402784736, 403015360, 403245888, 403476320, 403706656, - 403936896, 404167008, 404397024, 404626944, 404856736, 405086432, - 405316032, 405545536, 405774912, 406004224, 406233408, 406462464, - 406691456, 406920320, 407149088, 407377760, 407606336, 407834784, - 408063136, 408291392, 408519520, 408747584, 408975520, 409203360, - 409431072, 409658720, 409886240, 410113664, 410340992, 410568192, - 410795296, 411022304, 411249216, 411476032, 411702720, 411929312, - 412155808, 412382176, 412608480, 412834656, 413060736, 413286720, - 413512576, 413738336, 413964000, 414189568, 414415040, 414640384, - 414865632, 415090784, 415315840, 415540800, 415765632, 415990368, - 416215008, 416439552, 416663968, 416888288, 417112512, 417336640, - 417560672, 417784576, 418008384, 418232096, 418455712, 418679200, - 418902624, 419125920, 419349120, 419572192, 419795200, 420018080, - 420240864, 420463552, 420686144, 420908608, 421130976, 421353280, - 421575424, 421797504, 422019488, 422241344, 422463104, 422684768, - 422906336, 423127776, 423349120, 423570400, 423791520, 424012576, - 424233536, 424454368, 424675104, 424895744, 425116288, 425336736, - 425557056, 425777280, 425997408, 426217440, 426437376, 426657184, - 426876928, 427096544, 427316064, 427535488, 427754784, 427974016, - 428193120, 428412128, 428631040, 428849856, 429068544, 429287168, - 429505664, 429724064, 429942368, 430160576, 430378656, 430596672, - 430814560, 431032352, 431250048, 431467616, 431685120, 431902496, - 432119808, 432336992, 432554080, 432771040, 432987936, 433204736, - 433421408, 433637984, 433854464, 434070848, 434287104, 434503296, - 434719360, 434935360, 435151232, 435367008, 435582656, 435798240, - 436013696, 436229088, 436444352, 436659520, 436874592, 437089568, - 437304416, 437519200, 437733856, 437948416, 438162880, 438377248, - 438591520, 438805696, 439019744, 439233728, 439447584, 439661344, - 439875008, 440088576, 440302048, 440515392, 440728672, 440941824, - 441154880, 441367872, 441580736, 441793472, 442006144, 442218720, - 442431168, 442643552, 442855808, 443067968, 443280032, 443492000, - 443703872, 443915648, 444127296, 444338880, 444550336, 444761696, - 444972992, 445184160, 445395232, 445606176, 445817056, 446027840, - 446238496, 446449088, 446659552, 446869920, 447080192, 447290400, - 447500448, 447710432, 447920320, 448130112, 448339776, 448549376, - 448758848, 448968224, 449177536, 449386720, 449595808, 449804800, - 450013664, 450222464, 450431168, 450639776, 450848256, 451056640, - 451264960, 451473152, 451681248, 451889248, 452097152, 452304960, - 452512672, 452720288, 452927808, 453135232, 453342528, 453549760, - 453756864, 453963904, 454170816, 454377632, 454584384, 454791008, - 454997536, 455203968, 455410304, 455616544, 455822688, 456028704, - 456234656, 456440512, 456646240, 456851904, 457057472, 457262912, - 457468256, 457673536, 457878688, 458083744, 458288736, 458493600, - 458698368, 458903040, 459107616, 459312096, 459516480, 459720768, - 459924960, 460129056, 460333056, 460536960, 460740736, 460944448, - 461148064, 461351584, 461554976, 461758304, 461961536, 462164640, - 462367680, 462570592, 462773440, 462976160, 463178816, 463381344, - 463583776, 463786144, 463988384, 464190560, 464392608, 464594560, - 464796448, 464998208, 465199872, 465401472, 465602944, 465804320, - 466005600, 466206816, 466407904, 466608896, 466809824, 467010624, - 467211328, 467411936, 467612480, 467812896, 468013216, 468213440, - 468413600, 468613632, 468813568, 469013440, 469213184, 469412832, - 469612416, 469811872, 470011232, 470210528, 470409696, 470608800, - 470807776, 471006688, 471205472, 471404192, 471602784, 471801312, - 471999712, 472198048, 472396288, 472594400, 472792448, 472990400, - 473188256, 473385984, 473583648, 473781216, 473978688, 474176064, - 474373344, 474570528, 474767616, 474964608, 475161504, 475358336, - 475555040, 475751648, 475948192, 476144608, 476340928, 476537184, - 476733312, 476929376, 477125344, 477321184, 477516960, 477712640, - 477908224, 478103712, 478299104, 478494400, 478689600, 478884704, - 479079744, 479274656, 479469504, 479664224, 479858880, 480053408, - 480247872, 480442240, 480636512, 480830656, 481024736, 481218752, - 481412640, 481606432, 481800128, 481993760, 482187264, 482380704, - 482574016, 482767264, 482960416, 483153472, 483346432, 483539296, - 483732064, 483924768, 484117344, 484309856, 484502240, 484694560, - 484886784, 485078912, 485270944, 485462880, 485654720, 485846464, - 486038144, 486229696, 486421184, 486612576, 486803840, 486995040, - 487186176, 487377184, 487568096, 487758912, 487949664, 488140320, - 488330880, 488521312, 488711712, 488901984, 489092160, 489282240, - 489472256, 489662176, 489851968, 490041696, 490231328, 490420896, - 490610336, 490799712, 490988960, 491178144, 491367232, 491556224, - 491745120, 491933920, 492122656, 492311264, 492499808, 492688256, - 492876608, 493064864, 493253056, 493441120, 493629120, 493817024, - 494004832, 494192544, 494380160, 494567712, 494755136, 494942496, - 495129760, 495316928, 495504000, 495691008, 495877888, 496064704, - 496251424, 496438048, 496624608, 496811040, 496997408, 497183680, - 497369856, 497555936, 497741920, 497927840, 498113632, 498299360, - 498484992, 498670560, 498856000, 499041376, 499226656, 499411840, - 499596928, 499781920, 499966848, 500151680, 500336416, 500521056, - 500705600, 500890080, 501074464, 501258752, 501442944, 501627040, - 501811072, 501995008, 502178848, 502362592, 502546240, 502729824, - 502913312, 503096704, 503280000, 503463232, 503646368, 503829408, - 504012352, 504195200, 504377984, 504560672, 504743264, 504925760, - 505108192, 505290496, 505472736, 505654912, 505836960, 506018944, - 506200832, 506382624, 506564320, 506745952, 506927488, 507108928, - 507290272, 507471552, 507652736, 507833824, 508014816, 508195744, - 508376576, 508557312, 508737952, 508918528, 509099008, 509279392, - 509459680, 509639904, 509820032, 510000064, 510180000, 510359872, - 510539648, 510719328, 510898944, 511078432, 511257856, 511437216, - 511616448, 511795616, 511974688, 512153664, 512332576, 512511392, - 512690112, 512868768, 513047296, 513225792, 513404160, 513582432, - 513760640, 513938784, 514116800, 514294752, 514472608, 514650368, - 514828064, 515005664, 515183168, 515360608, 515537952, 515715200, - 515892352, 516069440, 516246432, 516423328, 516600160, 516776896, - 516953536, 517130112, 517306592, 517482976, 517659264, 517835488, - 518011616, 518187680, 518363648, 518539520, 518715296, 518891008, - 519066624, 519242144, 519417600, 519592960, 519768256, 519943424, - 520118528, 520293568, 520468480, 520643328, 520818112, 520992800, - 521167392, 521341888, 521516320, 521690656, 521864896, 522039072, - 522213152, 522387168, 522561056, 522734912, 522908640, 523082304, - 523255872, 523429376, 523602784, 523776096, 523949312, 524122464, - 524295552, 524468512, 524641440, 524814240, 524986976, 525159616, - 525332192, 525504640, 525677056, 525849344, 526021568, 526193728, - 526365792, 526537760, 526709632, 526881440, 527053152, 527224800, - 527396352, 527567840, 527739200, 527910528, 528081728, 528252864, - 528423936, 528594880, 528765760, 528936576, 529107296, 529277920, - 529448480, 529618944, 529789344, 529959648, 530129856, 530300000, - 530470048, 530640000, 530809888, 530979712, 531149440, 531319072, - 531488608, 531658080, 531827488, 531996800, 532166016, 532335168, - 532504224, 532673184, 532842080, 533010912, 533179616, 533348288, - 533516832, 533685312, 533853728, 534022048, 534190272, 534358432, - 534526496, 534694496, 534862400, 535030240, 535197984, 535365632, - 535533216, 535700704, 535868128, 536035456, 536202720, 536369888, - 536536992, 536704000, 536870912, -}; - -/* Now where did these came from? */ - -const byte gammatable[5][256] = -{ - {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, - 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, - 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, - 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, - 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, - 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, - 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, - 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, - 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, - 127, 128, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, - 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, - 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, - 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, - 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, - 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, - 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, - 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, - 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, - 252, 253, 254, 255}, - - { - 2, 4, 5, 7, 8, 10, 11, 12, 14, 15, 16, 18, 19, 20, - 21, 23, 24, 25, 26, 27, 29, 30, 31, 32, 33, 34, 36, 37, - 38, 39, 40, 41, 42, 44, 45, 46, 47, 48, 49, 50, 51, 52, - 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, - 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, - 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, - 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, - 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, - 125, 126, 127, 128, 129, 129, 130, 131, 132, 133, 134, 135, 136, 137, - 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 148, 149, 150, - 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 163, - 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 175, 176, - 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 186, 187, 188, 189, - 190, 191, 192, 193, 194, 195, 196, 196, 197, 198, 199, 200, 201, 202, - 203, 204, 205, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 214, - 215, 216, 217, 218, 219, 220, 221, 222, 222, 223, 224, 225, 226, 227, - 228, 229, 230, 230, 231, 232, 233, 234, 235, 236, 237, 237, 238, 239, - 240, 241, 242, 243, 244, 245, 245, 246, 247, 248, 249, 250, 251, 252, - 252, 253, 254, 255, - }, - - { - 4, 7, 9, 11, 13, 15, 17, 19, 21, 22, 24, 26, 27, 29, - 30, 32, 33, 35, 36, 38, 39, 40, 42, 43, 45, 46, 47, 48, - 50, 51, 52, 54, 55, 56, 57, 59, 60, 61, 62, 63, 65, 66, - 67, 68, 69, 70, 72, 73, 74, 75, 76, 77, 78, 79, 80, 82, - 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, - 97, 98, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, - 112, 113, 114, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, - 125, 126, 127, 128, 129, 130, 131, 132, 133, 133, 134, 135, 136, 137, - 138, 139, 140, 141, 142, 143, 144, 144, 145, 146, 147, 148, 149, 150, - 151, 152, 153, 153, 154, 155, 156, 157, 158, 159, 160, 160, 161, 162, - 163, 164, 165, 166, 166, 167, 168, 169, 170, 171, 172, 172, 173, 174, - 175, 176, 177, 178, 178, 179, 180, 181, 182, 183, 183, 184, 185, 186, - 187, 188, 188, 189, 190, 191, 192, 193, 193, 194, 195, 196, 197, 197, - 198, 199, 200, 201, 201, 202, 203, 204, 205, 206, 206, 207, 208, 209, - 210, 210, 211, 212, 213, 213, 214, 215, 216, 217, 217, 218, 219, 220, - 221, 221, 222, 223, 224, 224, 225, 226, 227, 228, 228, 229, 230, 231, - 231, 232, 233, 234, 235, 235, 236, 237, 238, 238, 239, 240, 241, 241, - 242, 243, 244, 244, 245, 246, 247, 247, 248, 249, 250, 251, 251, 252, - 253, 254, 254, 255, - }, - - { - 8, 12, 16, 19, 22, 24, 27, 29, 31, 34, 36, 38, 40, 41, - 43, 45, 47, 49, 50, 52, 53, 55, 57, 58, 60, 61, 63, 64, - 65, 67, 68, 70, 71, 72, 74, 75, 76, 77, 79, 80, 81, 82, - 84, 85, 86, 87, 88, 90, 91, 92, 93, 94, 95, 96, 98, 99, - 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, - 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, - 128, 129, 130, 131, 132, 133, 134, 135, 135, 136, 137, 138, 139, 140, - 141, 142, 143, 143, 144, 145, 146, 147, 148, 149, 150, 150, 151, 152, - 153, 154, 155, 155, 156, 157, 158, 159, 160, 160, 161, 162, 163, 164, - 165, 165, 166, 167, 168, 169, 169, 170, 171, 172, 173, 173, 174, 175, - 176, 176, 177, 178, 179, 180, 180, 181, 182, 183, 183, 184, 185, 186, - 186, 187, 188, 189, 189, 190, 191, 192, 192, 193, 194, 195, 195, 196, - 197, 197, 198, 199, 200, 200, 201, 202, 202, 203, 204, 205, 205, 206, - 207, 207, 208, 209, 210, 210, 211, 212, 212, 213, 214, 214, 215, 216, - 216, 217, 218, 219, 219, 220, 221, 221, 222, 223, 223, 224, 225, 225, - 226, 227, 227, 228, 229, 229, 230, 231, 231, 232, 233, 233, 234, 235, - 235, 236, 237, 237, 238, 238, 239, 240, 240, 241, 242, 242, 243, 244, - 244, 245, 246, 246, 247, 247, 248, 249, 249, 250, 251, 251, 252, 253, - 253, 254, 254, 255, - }, - - { - 16, 23, 28, 32, 36, 39, 42, 45, 48, 50, 53, 55, 57, 60, - 62, 64, 66, 68, 69, 71, 73, 75, 76, 78, 80, 81, 83, 84, - 86, 87, 89, 90, 92, 93, 94, 96, 97, 98, 100, 101, 102, 103, - 105, 106, 107, 108, 109, 110, 112, 113, 114, 115, 116, 117, 118, 119, - 120, 121, 122, 123, 124, 125, 126, 128, 128, 129, 130, 131, 132, 133, - 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 143, 144, 145, 146, - 147, 148, 149, 150, 150, 151, 152, 153, 154, 155, 155, 156, 157, 158, - 159, 159, 160, 161, 162, 163, 163, 164, 165, 166, 166, 167, 168, 169, - 169, 170, 171, 172, 172, 173, 174, 175, 175, 176, 177, 177, 178, 179, - 180, 180, 181, 182, 182, 183, 184, 184, 185, 186, 187, 187, 188, 189, - 189, 190, 191, 191, 192, 193, 193, 194, 195, 195, 196, 196, 197, 198, - 198, 199, 200, 200, 201, 202, 202, 203, 203, 204, 205, 205, 206, 207, - 207, 208, 208, 209, 210, 210, 211, 211, 212, 213, 213, 214, 214, 215, - 216, 216, 217, 217, 218, 219, 219, 220, 220, 221, 221, 222, 223, 223, - 224, 224, 225, 225, 226, 227, 227, 228, 228, 229, 229, 230, 230, 231, - 232, 232, 233, 233, 234, 234, 235, 235, 236, 236, 237, 237, 238, 239, - 239, 240, 240, 241, 241, 242, 242, 243, 243, 244, 244, 245, 245, 246, - 246, 247, 247, 248, 248, 249, 249, 250, 250, 251, 251, 252, 252, 253, - 254, 254, 255, 255, - }, -}; - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/* to get a global angle from cartesian coordinates, the coordinates are - * flipped until they are in the first octant of the coordinate system, then - * the y (<=x) is scaled and divided by x to get a tangent (slope) value - * which is looked up in the tantoangle[] table. The +1 size is to handle - * the case when x==y without additional checking. - */ - -int slope_div(unsigned int num, unsigned int den) -{ - unsigned answer; - - if (den < 512) - { - return SLOPERANGE; - } - else - { - answer = (num << 3) / (den >> 8); - - if (answer <= SLOPERANGE) - { - return answer; - } - else - { - return SLOPERANGE; - } - } -} diff --git a/games/NXDoom/src/tables.h b/games/NXDoom/src/tables.h deleted file mode 100644 index 1a30ee74e..000000000 --- a/games/NXDoom/src/tables.h +++ /dev/null @@ -1,125 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/tables.h - * - * SPDX-License-Identifier: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 1993-2008 Raven Software - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Lookup tables. - * Do not try to look them up :-). - * In the order of appearance: - * - * int finetangent[4096] - Tangens LUT. - * Should work with BAM fairly well (12 of 16bit, effectively, - * by shifting). - * - * int finesine[10240] - Sine lookup. - * Guess what, serves as cosine, too. - * Remarkable thing is, how to use BAMs with this? - * - * int tantoangle[2049] - ArcTan LUT, - * maps tan(angle) to angle fast. Gotta search. - * - * - * DESCRIPTION: - * System specific interface stuff. - * - ****************************************************************************/ - -#ifndef __TABLES__ -#define __TABLES__ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "doomtype.h" - -#include "m_fixed.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define FINEANGLES 8192 -#define FINEMASK (FINEANGLES - 1) - -/* 0x100000000 to 0x2000 */ - -#define ANGLETOFINESHIFT 19 - -/* Binary Angle Measurement, BAM. */ - -#define ANG45 0x20000000 -#define ANG90 0x40000000 -#define ANG180 0x80000000 -#define ANG270 0xc0000000 -#define ANG_MAX 0xffffffff - -#define ANG1 (ANG45 / 45) -#define ANG60 (ANG180 / 3) - -/* Heretic code uses this definition as though it represents one - * degree, but it is not! This is actually ~1.40 degrees. - */ - -#define ANG1_X 0x01000000 - -#define SLOPERANGE 2048 -#define SLOPEBITS 11 -#define DBITS (FRACBITS - SLOPEBITS) - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -typedef unsigned int angle_t; - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/* Effective size is 10240. */ - -extern const fixed_t finesine[5 * FINEANGLES / 4]; - -/* Reuse data, is just PI/2 pahse shift. */ - -extern const fixed_t *finecosine; - -/* Effective size is 4096. */ - -extern const fixed_t finetangent[FINEANGLES / 2]; - -/* Gamma correction tables. */ - -extern const byte gammatable[5][256]; - -/* Effective size is 2049; - * The +1 size is to handle the case when x==y without additional checking. - */ - -extern const angle_t tantoangle[SLOPERANGE + 1]; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/* Utility function, called by r_point_to_angle. */ - -int slope_div(unsigned int num, unsigned int den); - -#endif /* __TABLES__ */ diff --git a/games/NXDoom/src/v_diskicon.c b/games/NXDoom/src/v_diskicon.c deleted file mode 100644 index 755d281a9..000000000 --- a/games/NXDoom/src/v_diskicon.c +++ /dev/null @@ -1,185 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/v_diskicon.c - * - * SPDX-License-Identifier: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Disk load indicator. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "deh_str.h" -#include "doomtype.h" -#include "i_swap.h" -#include "i_video.h" -#include "m_argv.h" -#include "v_video.h" -#include "w_wad.h" -#include "z_zone.h" - -#include "v_diskicon.h" - -#include - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/* Only display the disk icon if more then this much bytes have been read - * during the previous tic. - */ - -static const int diskicon_threshold = 20 * 1024; - -/* Two buffers: disk_data contains the data representing the disk icon - * (raw, not a patch_t) while saved_background is an equivalently-sized - * buffer where we save the background data while the disk is on screen. - */ - -static pixel_t *disk_data; -static pixel_t *saved_background; - -static int loading_disk_xoffs = 0; -static int loading_disk_yoffs = 0; - -/* Number of bytes read since the last call to v_draw_disk_icon(). */ - -static size_t recent_bytes_read = 0; -static boolean disk_drawn; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static void copy_region(pixel_t *dest, int dest_pitch, pixel_t *src, - int src_pitch, int w, int h) -{ - pixel_t *s, *d; - int y; - - s = src; - d = dest; - for (y = 0; y < h; ++y) - { - memcpy(d, s, w * sizeof(*d)); - s += src_pitch; - d += dest_pitch; - } -} - -static void save_disk_data(const char *disk_lump, int xoffs, int yoffs) -{ - pixel_t *tmpscreen; - patch_t *disk; - - /* Allocate a complete temporary screen where we'll draw the patch. */ - - tmpscreen = z_malloc(SCREENWIDTH * SCREENHEIGHT * sizeof(*tmpscreen), - PU_STATIC, NULL); - memset(tmpscreen, 0, SCREENWIDTH * SCREENHEIGHT * sizeof(*tmpscreen)); - v_use_buffer(tmpscreen); - - /* Buffer where we'll save the disk data. */ - - if (disk_data != NULL) - { - z_free(disk_data); - disk_data = NULL; - } - - disk_data = z_malloc(LOADING_DISK_W * LOADING_DISK_H * sizeof(*disk_data), - PU_STATIC, NULL); - - /* Draw the patch and save the result to disk_data. */ - - disk = w_cache_lump_name(disk_lump, PU_STATIC); - v_draw_patch(loading_disk_xoffs, loading_disk_yoffs, disk); - copy_region(disk_data, LOADING_DISK_W, - tmpscreen + yoffs * SCREENWIDTH + xoffs, SCREENWIDTH, - LOADING_DISK_W, LOADING_DISK_H); - w_release_lump_name(disk_lump); - - v_restore_buffer(); - z_free(tmpscreen); -} - -static pixel_t *disk_region_pointer(void) -{ - return i_video_buffer + loading_disk_yoffs * SCREENWIDTH + - loading_disk_xoffs; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -void v_enable_loading_disk(const char *lump_name, int xoffs, int yoffs) -{ - loading_disk_xoffs = xoffs; - loading_disk_yoffs = yoffs; - - if (saved_background != NULL) - { - z_free(saved_background); - saved_background = NULL; - } - - saved_background = - z_malloc(LOADING_DISK_W * LOADING_DISK_H * sizeof(*saved_background), - PU_STATIC, NULL); - save_disk_data(lump_name, xoffs, yoffs); -} - -void v_begin_read(size_t nbytes) -{ - recent_bytes_read += nbytes; -} - -void v_draw_disk_icon(void) -{ - if (disk_data != NULL && recent_bytes_read > diskicon_threshold) - { - /* Save the background behind the disk before we draw it. */ - - copy_region(saved_background, LOADING_DISK_W, disk_region_pointer(), - SCREENWIDTH, LOADING_DISK_W, LOADING_DISK_H); - - /* Write the disk to the screen buffer. */ - - copy_region(disk_region_pointer(), SCREENWIDTH, disk_data, - LOADING_DISK_W, LOADING_DISK_W, LOADING_DISK_H); - disk_drawn = true; - } - - recent_bytes_read = 0; -} - -void v_restore_disk_background(void) -{ - if (disk_drawn) - { - /* Restore the background. */ - - copy_region(disk_region_pointer(), SCREENWIDTH, saved_background, - LOADING_DISK_W, LOADING_DISK_W, LOADING_DISK_H); - - disk_drawn = false; - } -} diff --git a/games/NXDoom/src/v_diskicon.h b/games/NXDoom/src/v_diskicon.h deleted file mode 100644 index 4bd9b54aa..000000000 --- a/games/NXDoom/src/v_diskicon.h +++ /dev/null @@ -1,46 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/v_diskicon.h - * - * SPDX-License-Identifier: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Disk load indicator. - * - ****************************************************************************/ - -#ifndef __V_DISKICON__ -#define __V_DISKICON__ - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* Dimensions of the flashing "loading" disk icon */ - -#define LOADING_DISK_W 16 -#define LOADING_DISK_H 16 - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -extern void v_enable_loading_disk(const char *lump_name, int xoffs, - int yoffs); -extern void v_begin_read(size_t nbytes); -extern void v_draw_disk_icon(void); -extern void v_restore_disk_background(void); - -#endif /* __V_DISKICON__ */ diff --git a/games/NXDoom/src/v_patch.h b/games/NXDoom/src/v_patch.h deleted file mode 100644 index 5bfac559c..000000000 --- a/games/NXDoom/src/v_patch.h +++ /dev/null @@ -1,70 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/v_patch.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Refresh/rendering module, shared data struct definitions. - * - ****************************************************************************/ - -#ifndef V_PATCH_H -#define V_PATCH_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -/* Patches. - * A patch holds one or more columns. - * Patches are used for sprites and all masked pictures, - * and we compose textures from the TEXTURE1/2 lists - * of patches. - */ - -begin_packed_struct struct patch_t -{ - short width; /* bounding box size */ - short height; - short leftoffset; /* pixels to the left of origin */ - short topoffset; /* pixels below the origin */ - int columnofs[8]; /* only [width] used the [0] is &columnofs[width] */ -} end_packed_struct; - -typedef struct patch_t patch_t; - -/* posts are runs of non masked source pixels */ - -begin_packed_struct struct post_t -{ - byte topdelta; /* -1 is the last post in a column */ - byte length; /* length data bytes follows */ -} end_packed_struct; - -typedef struct post_t post_t; - -/* column_t is a list of 0 or more post_t, (byte)-1 terminated */ - -typedef post_t column_t; - -#endif /* V_PATCH_H */ diff --git a/games/NXDoom/src/v_video.c b/games/NXDoom/src/v_video.c deleted file mode 100644 index 55f455cce..000000000 --- a/games/NXDoom/src/v_video.c +++ /dev/null @@ -1,881 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/v_video.c - * - * SPDX-License-Identifier: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 1993-2008 Raven Software - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Gamma correction LUT stuff. - * Functions to draw patches (by post) directly to screen. - * Functions to blit a block to the screen. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include -#include - -#include "i_system.h" - -#include "doomtype.h" - -#include "deh_str.h" -#include "i_input.h" -#include "i_swap.h" -#include "i_video.h" -#include "m_bbox.h" -#include "m_misc.h" -#include "v_video.h" -#include "w_wad.h" -#include "z_zone.h" - -#include "config.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define MOUSE_SPEED_BOX_WIDTH 120 -#define MOUSE_SPEED_BOX_HEIGHT 9 -#define MOUSE_SPEED_BOX_X (SCREENWIDTH - MOUSE_SPEED_BOX_WIDTH - 10) -#define MOUSE_SPEED_BOX_Y 15 - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/* SCREEN SHOTS */ - -begin_packed_struct struct pcx_t -{ - char manufacturer; - char version; - char encoding; - char bits_per_pixel; - - unsigned short xmin; - unsigned short ymin; - unsigned short xmax; - unsigned short ymax; - - unsigned short hres; - unsigned short vres; - - unsigned char palette[48]; - - char reserved; - char color_planes; - unsigned short bytes_per_line; - unsigned short palette_type; - - char filler[58]; - unsigned char data; /* unbounded */ -} end_packed_struct; - -typedef struct pcx_t pcx_t; - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/* The screen buffer that the v_video.c code draws to. */ - -static pixel_t *dest_screen = NULL; - -/* haleyjd 08/28/10: clipping callback function for patches. - * This is needed for Chocolate Strife, which clips patches to the screen. - */ - -static vpatchclipfunc_t patchclip_callback = NULL; - -/* Highest seen mouse turn speed. We scale the range of the thermometer - * according to this value, so that it never exceeds the range. Initially - * this is set to a 1:1 setting where 1 pixel = 1 unit of speed. - */ - -static int max_seen_speed = MOUSE_SPEED_BOX_WIDTH - 1; - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/* Blending table used for fuzzpatch, etc. Only used in Heretic/Hexen */ - -byte *tinttable = NULL; - -/* villsa [STRIFE] Blending table used for Strife */ - -byte *xlatab = NULL; - -int dirtybox[4]; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static void draw_accelerating_box(int speed) -{ - int red; - int white; - int yellow; - int original_speed; - int redline_x; - int linelen; - - red = i_get_palette_index(0xff, 0x00, 0x00); - white = i_get_palette_index(0xff, 0xff, 0xff); - yellow = i_get_palette_index(0xff, 0xff, 0x00); - - /* Calculate the position of the red threshold line when calibrating - * acceleration. This is 1/3 of the way along the box. - */ - - redline_x = MOUSE_SPEED_BOX_WIDTH / 3; - - if (speed >= mouse_threshold) - { - /* Undo acceleration and get back the original mouse speed */ - - original_speed = speed - mouse_threshold; - original_speed = (int)(original_speed / mouse_acceleration); - original_speed += mouse_threshold; - - linelen = (original_speed * redline_x) / mouse_threshold; - } - else - { - linelen = (speed * redline_x) / mouse_threshold; - } - - /* Horizontal "thermometer" */ - - if (linelen > MOUSE_SPEED_BOX_WIDTH - 1) - { - linelen = MOUSE_SPEED_BOX_WIDTH - 1; - } - - if (linelen < redline_x) - { - v_draw_horiz_line(MOUSE_SPEED_BOX_X + 1, - MOUSE_SPEED_BOX_Y + MOUSE_SPEED_BOX_HEIGHT / 2, - linelen, white); - } - else - { - v_draw_horiz_line(MOUSE_SPEED_BOX_X + 1, - MOUSE_SPEED_BOX_Y + MOUSE_SPEED_BOX_HEIGHT / 2, - redline_x, white); - v_draw_horiz_line(MOUSE_SPEED_BOX_X + redline_x, - MOUSE_SPEED_BOX_Y + MOUSE_SPEED_BOX_HEIGHT / 2, - linelen - redline_x, yellow); - } - - /* Draw acceleration threshold line */ - - v_draw_vert_line(MOUSE_SPEED_BOX_X + redline_x, MOUSE_SPEED_BOX_Y + 1, - MOUSE_SPEED_BOX_HEIGHT - 2, red); -} - -static void draw_non_accelerating_box(int speed) -{ - int white; - int linelen; - - white = i_get_palette_index(0xff, 0xff, 0xff); - - if (speed > max_seen_speed) - { - max_seen_speed = speed; - } - - /* Draw horizontal "thermometer": */ - - linelen = speed * (MOUSE_SPEED_BOX_WIDTH - 1) / max_seen_speed; - - v_draw_horiz_line(MOUSE_SPEED_BOX_X + 1, - MOUSE_SPEED_BOX_Y + MOUSE_SPEED_BOX_HEIGHT / 2, linelen, - white); -} - -static void write_pcx_file(char *filename, pixel_t *data, int width, - int height, byte *palette) -{ - int i; - int length; - pcx_t *pcx; - byte *pack; - - pcx = z_malloc(width * height * 2 + 1000, PU_STATIC, NULL); - - pcx->manufacturer = 0x0a; /* PCX id */ - pcx->version = 5; /* 256 color */ - pcx->encoding = 1; /* uncompressed */ - pcx->bits_per_pixel = 8; /* 256 color */ - pcx->xmin = 0; - pcx->ymin = 0; - pcx->xmax = SHORT(width - 1); - pcx->ymax = SHORT(height - 1); - pcx->hres = SHORT(1); - pcx->vres = SHORT(1); - memset(pcx->palette, 0, sizeof(pcx->palette)); - pcx->reserved = 0; /* PCX spec: reserved byte must be zero */ - pcx->color_planes = 1; /* chunky image */ - pcx->bytes_per_line = SHORT(width); - pcx->palette_type = SHORT(2); /* not a grey scale */ - memset(pcx->filler, 0, sizeof(pcx->filler)); - - /* pack the image */ - - pack = &pcx->data; - - for (i = 0; i < width * height; i++) - { - if ((*data & 0xc0) != 0xc0) - *pack++ = *data++; - else - { - *pack++ = 0xc1; - *pack++ = *data++; - } - } - - /* write the palette */ - - *pack++ = 0x0c; /* palette ID byte */ - for (i = 0; i < 768; i++) - *pack++ = *palette++; - - /* write output file */ - - length = pack - (byte *)pcx; - m_write_file(filename, pcx, length); - - z_free(pcx); -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -void v_mark_rect(int x, int y, int width, int height) -{ - /* If we are temporarily using an alternate screen, do not affect the - * update box. - */ - - if (dest_screen == i_video_buffer) - { - m_add_to_box(dirtybox, x, y); - m_add_to_box(dirtybox, x + width - 1, y + height - 1); - } -} - -void v_copy_rect(int srcx, int srcy, pixel_t *source, int width, int height, - int destx, int desty) -{ - pixel_t *src; - pixel_t *dest; - -#ifdef CONFIG_GAMES_NXDOOM_RANGECHECK - if (srcx < 0 || srcx + width > SCREENWIDTH || srcy < 0 || - srcy + height > SCREENHEIGHT || destx < 0 || - destx + width > SCREENWIDTH || desty < 0 || - desty + height > SCREENHEIGHT) - { - i_error("Bad v_copy_rect"); - } -#endif - - v_mark_rect(destx, desty, width, height); - - src = source + SCREENWIDTH * srcy + srcx; - dest = dest_screen + SCREENWIDTH * desty + destx; - - for (; height > 0; height--) - { - memcpy(dest, src, width * sizeof(*dest)); - src += SCREENWIDTH; - dest += SCREENWIDTH; - } -} - -/* v_set_patch_clip_callback - * - * haleyjd 08/28/10: Added for Strife support. - * By calling this function, you can setup runtime error checking for patch - * clipping. Strife never caused errors by drawing patches partway - * off-screen. - * - * Some versions of vanilla DOOM also behaved differently than the default - * implementation, so this could possibly be extended to those as well for - * accurate emulation. - */ - -void v_set_patch_clip_callback(vpatchclipfunc_t func) -{ - patchclip_callback = func; -} - -/* V_DrawPatch - * Masks a column based masked pic to the screen. - */ - -void v_draw_patch(int x, int y, patch_t *patch) -{ - int count; - int col; - column_t *column; - pixel_t *desttop; - pixel_t *dest; - byte *source; - int w; - - y -= SHORT(patch->topoffset); - x -= SHORT(patch->leftoffset); - - /* haleyjd 08/28/10: Strife needs silent error checking here. */ - - if (patchclip_callback) - { - if (!patchclip_callback(patch, x, y)) return; - } - -#ifdef CONFIG_GAMES_NXDOOM_RANGECHECK - if (x < 0 || x + SHORT(patch->width) > SCREENWIDTH || y < 0 || - y + SHORT(patch->height) > SCREENHEIGHT) - { - i_error("Bad V_DrawPatch"); - } -#endif - - v_mark_rect(x, y, SHORT(patch->width), SHORT(patch->height)); - - col = 0; - desttop = dest_screen + y * SCREENWIDTH + x; - - w = SHORT(patch->width); - - for (; col < w; x++, col++, desttop++) - { - column = (column_t *)((byte *)patch + LONG(patch->columnofs[col])); - - /* step through the posts in a column */ - - while (column->topdelta != 0xff) - { - source = (byte *)column + 3; - dest = desttop + column->topdelta * SCREENWIDTH; - count = column->length; - - while (count--) - { - *dest = *source++; - dest += SCREENWIDTH; - } - - column = (column_t *)((byte *)column + column->length + 4); - } - } -} - -/* v_draw_patch_flipped - * Masks a column based masked pic to the screen. - * Flips horizontally, e.g. to mirror face. - */ - -void v_draw_patch_flipped(int x, int y, patch_t *patch) -{ - int count; - int col; - column_t *column; - pixel_t *desttop; - pixel_t *dest; - byte *source; - int w; - - y -= SHORT(patch->topoffset); - x -= SHORT(patch->leftoffset); - - /* haleyjd 08/28/10: Strife needs silent error checking here. */ - - if (patchclip_callback) - { - if (!patchclip_callback(patch, x, y)) return; - } - -#ifdef CONFIG_GAMES_NXDOOM_RANGECHECK - if (x < 0 || x + SHORT(patch->width) > SCREENWIDTH || y < 0 || - y + SHORT(patch->height) > SCREENHEIGHT) - { - i_error("Bad v_draw_patch_flipped"); - } -#endif - - v_mark_rect(x, y, SHORT(patch->width), SHORT(patch->height)); - - col = 0; - desttop = dest_screen + y * SCREENWIDTH + x; - - w = SHORT(patch->width); - - for (; col < w; x++, col++, desttop++) - { - column = - (column_t *)((byte *)patch + LONG(patch->columnofs[w - 1 - col])); - - /* step through the posts in a column */ - - while (column->topdelta != 0xff) - { - source = (byte *)column + 3; - dest = desttop + column->topdelta * SCREENWIDTH; - count = column->length; - - while (count--) - { - *dest = *source++; - dest += SCREENWIDTH; - } - - column = (column_t *)((byte *)column + column->length + 4); - } - } -} - -/* v_draw_patch_direct - * Draws directly to the screen on the pc. - */ - -void v_draw_patch_direct(int x, int y, patch_t *patch) -{ - v_draw_patch(x, y, patch); -} - -/* v_draw_tl_patch - * Masks a column based translucent masked pic to the screen. - */ - -void v_draw_tl_patch(int x, int y, patch_t *patch) -{ - int count; - int col; - column_t *column; - pixel_t *desttop; - pixel_t *dest; - byte *source; - int w; - - y -= SHORT(patch->topoffset); - x -= SHORT(patch->leftoffset); - - if (x < 0 || x + SHORT(patch->width) > SCREENWIDTH || y < 0 || - y + SHORT(patch->height) > SCREENHEIGHT) - { - i_error("Bad v_draw_tl_patch"); - } - - col = 0; - desttop = dest_screen + y * SCREENWIDTH + x; - - w = SHORT(patch->width); - for (; col < w; x++, col++, desttop++) - { - column = (column_t *)((byte *)patch + LONG(patch->columnofs[col])); - - /* step through the posts in a column */ - - while (column->topdelta != 0xff) - { - source = (byte *)column + 3; - dest = desttop + column->topdelta * SCREENWIDTH; - count = column->length; - - while (count--) - { - *dest = tinttable[*dest + ((*source++) << 8)]; - dest += SCREENWIDTH; - } - - column = (column_t *)((byte *)column + column->length + 4); - } - } -} - -/* v_draw_xla_patch - * villsa [STRIFE] Masks a column based translucent masked pic to the screen. - */ - -void v_draw_xla_patch(int x, int y, patch_t *patch) -{ - int count; - int col; - column_t *column; - pixel_t *desttop, *dest; - byte *source; - int w; - - y -= SHORT(patch->topoffset); - x -= SHORT(patch->leftoffset); - - if (patchclip_callback) - { - if (!patchclip_callback(patch, x, y)) return; - } - - col = 0; - desttop = dest_screen + y * SCREENWIDTH + x; - - w = SHORT(patch->width); - for (; col < w; x++, col++, desttop++) - { - column = (column_t *)((byte *)patch + LONG(patch->columnofs[col])); - - /* step through the posts in a column */ - - while (column->topdelta != 0xff) - { - source = (byte *)column + 3; - dest = desttop + column->topdelta * SCREENWIDTH; - count = column->length; - - while (count--) - { - *dest = xlatab[*dest + ((*source) << 8)]; - source++; - dest += SCREENWIDTH; - } - - column = (column_t *)((byte *)column + column->length + 4); - } - } -} - -/* v_draw_alt_tl_patch - * Masks a column based translucent masked pic to the screen. - */ - -void v_draw_alt_tl_patch(int x, int y, patch_t *patch) -{ - int count; - int col; - column_t *column; - pixel_t *desttop; - pixel_t *dest; - byte *source; - int w; - - y -= SHORT(patch->topoffset); - x -= SHORT(patch->leftoffset); - - if (x < 0 || x + SHORT(patch->width) > SCREENWIDTH || y < 0 || - y + SHORT(patch->height) > SCREENHEIGHT) - { - i_error("Bad v_draw_alt_tl_patch"); - } - - col = 0; - desttop = dest_screen + y * SCREENWIDTH + x; - - w = SHORT(patch->width); - for (; col < w; x++, col++, desttop++) - { - column = (column_t *)((byte *)patch + LONG(patch->columnofs[col])); - - /* step through the posts in a column */ - - while (column->topdelta != 0xff) - { - source = (byte *)column + 3; - dest = desttop + column->topdelta * SCREENWIDTH; - count = column->length; - - while (count--) - { - *dest = tinttable[((*dest) << 8) + *source++]; - dest += SCREENWIDTH; - } - - column = (column_t *)((byte *)column + column->length + 4); - } - } -} - -/* v_draw_shadowed_patch - * Masks a column based masked pic to the screen. - */ - -void v_draw_shadowed_patch(int x, int y, patch_t *patch) -{ - int count; - int col; - column_t *column; - pixel_t *desttop; - pixel_t *dest; - byte *source; - pixel_t *desttop2; - pixel_t *dest2; - int w; - - y -= SHORT(patch->topoffset); - x -= SHORT(patch->leftoffset); - - if (x < 0 || x + SHORT(patch->width) > SCREENWIDTH || y < 0 || - y + SHORT(patch->height) > SCREENHEIGHT) - { - i_error("Bad v_draw_shadowed_patch"); - } - - col = 0; - desttop = dest_screen + y * SCREENWIDTH + x; - desttop2 = dest_screen + (y + 2) * SCREENWIDTH + x + 2; - - w = SHORT(patch->width); - for (; col < w; x++, col++, desttop++, desttop2++) - { - column = (column_t *)((byte *)patch + LONG(patch->columnofs[col])); - - /* step through the posts in a column */ - - while (column->topdelta != 0xff) - { - source = (byte *)column + 3; - dest = desttop + column->topdelta * SCREENWIDTH; - dest2 = desttop2 + column->topdelta * SCREENWIDTH; - count = column->length; - - while (count--) - { - *dest2 = tinttable[((*dest2) << 8)]; - dest2 += SCREENWIDTH; - *dest = *source++; - dest += SCREENWIDTH; - } - - column = (column_t *)((byte *)column + column->length + 4); - } - } -} - -/* Load tint table from TINTTAB lump. */ - -void v_load_tint_table(void) -{ - tinttable = w_cache_lump_name("TINTTAB", PU_STATIC); -} - -/* v_load_xla_table - * villsa [STRIFE] Load xla table from XLATAB lump. - */ - -void v_load_xla_table(void) -{ - xlatab = w_cache_lump_name("XLATAB", PU_STATIC); -} - -/* v_draw_block - * Draw a linear block of pixels into the view buffer. - */ - -void v_draw_block(int x, int y, int width, int height, pixel_t *src) -{ - pixel_t *dest; - -#ifdef CONFIG_GAMES_NXDOOM_RANGECHECK - if (x < 0 || x + width > SCREENWIDTH || y < 0 || y + height > SCREENHEIGHT) - { - i_error("Bad v_draw_block"); - } -#endif - - v_mark_rect(x, y, width, height); - - dest = dest_screen + y * SCREENWIDTH + x; - - while (height--) - { - memcpy(dest, src, width * sizeof(*dest)); - src += width; - dest += SCREENWIDTH; - } -} - -void v_draw_filled_box(int x, int y, int w, int h, int c) -{ - pixel_t *buf, *buf1; - int x1; - int y1; - - buf = i_video_buffer + SCREENWIDTH * y + x; - - for (y1 = 0; y1 < h; ++y1) - { - buf1 = buf; - - for (x1 = 0; x1 < w; ++x1) - { - *buf1++ = c; - } - - buf += SCREENWIDTH; - } -} - -void v_draw_horiz_line(int x, int y, int w, int c) -{ - pixel_t *buf; - int x1; - - buf = i_video_buffer + SCREENWIDTH * y + x; - - for (x1 = 0; x1 < w; ++x1) - { - *buf++ = c; - } -} - -void v_draw_vert_line(int x, int y, int h, int c) -{ - pixel_t *buf; - int y1; - - buf = i_video_buffer + SCREENWIDTH * y + x; - - for (y1 = 0; y1 < h; ++y1) - { - *buf = c; - buf += SCREENWIDTH; - } -} - -void v_draw_box(int x, int y, int w, int h, int c) -{ - v_draw_horiz_line(x, y, w, c); - v_draw_horiz_line(x, y + h - 1, w, c); - v_draw_vert_line(x, y, h, c); - v_draw_vert_line(x + w - 1, y, h, c); -} - -/* Draw a "raw" screen (lump containing raw data to blit directly - * to the screen) - */ - -void v_draw_raw_screen(pixel_t *raw) -{ - memcpy(dest_screen, raw, - SCREENWIDTH * SCREENHEIGHT * sizeof(*dest_screen)); -} - -void v_init(void) -{ - /* no-op! - * There used to be separate screens that could be drawn to; these are - * now handled in the upper layers. - */ -} - -/* Set the buffer that the code draws to. */ - -void v_use_buffer(pixel_t *buffer) -{ - dest_screen = buffer; -} - -/* Restore screen buffer to the i_video screen buffer. */ - -void v_restore_buffer(void) -{ - dest_screen = i_video_buffer; -} - -void v_screenshot(const char *format) -{ - int i; - char lbmname[16]; /* haleyjd 20110213: BUG FIX - 12 is too small! */ - const char *ext; - - /* find a file name to save it to */ - - ext = "pcx"; - - for (i = 0; i <= 99; i++) - { - snprintf(lbmname, sizeof(lbmname), format, i, ext); - - if (!m_file_exists(lbmname)) - { - break; /* file doesn't exist */ - } - } - - if (i == 100) - { - i_error("v_screenshot: Couldn't create a PCX"); - } - - /* save the pcx file */ - - write_pcx_file(lbmname, i_video_buffer, SCREENWIDTH, SCREENHEIGHT, - w_cache_lump_name(("PLAYPAL"), PU_CACHE)); -} - -void v_draw_mouse_speed_box(int speed) -{ - int bgcolor; - int bordercolor; - int black; - - /* If the mouse is turned off, don't draw the box at all. */ - - if (!usemouse) - { - return; - } - - /* Get palette indices for colors for widget. These depend on the - * palette of the game being played. - */ - - bgcolor = i_get_palette_index(0x77, 0x77, 0x77); - bordercolor = i_get_palette_index(0x55, 0x55, 0x55); - black = i_get_palette_index(0x00, 0x00, 0x00); - - /* Calculate box position */ - - v_draw_filled_box(MOUSE_SPEED_BOX_X, MOUSE_SPEED_BOX_Y, - MOUSE_SPEED_BOX_WIDTH, MOUSE_SPEED_BOX_HEIGHT, bgcolor); - v_draw_box(MOUSE_SPEED_BOX_X, MOUSE_SPEED_BOX_Y, MOUSE_SPEED_BOX_WIDTH, - MOUSE_SPEED_BOX_HEIGHT, bordercolor); - v_draw_horiz_line(MOUSE_SPEED_BOX_X + 1, MOUSE_SPEED_BOX_Y + 4, - MOUSE_SPEED_BOX_WIDTH - 2, black); - - /* If acceleration is used, draw a box that helps to calibrate the - * threshold point. - */ - - if (mouse_threshold > 0 && fabs(mouse_acceleration - 1) > 0.01) - { - draw_accelerating_box(speed); - } - else - { - draw_non_accelerating_box(speed); - } -} diff --git a/games/NXDoom/src/v_video.h b/games/NXDoom/src/v_video.h deleted file mode 100644 index 07ac56730..000000000 --- a/games/NXDoom/src/v_video.h +++ /dev/null @@ -1,181 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/v_video.h - * - * SPDX-License-Identifier: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Gamma correction LUT. - * Functions to draw patches (by post) directly to screen. - * Functions to blit a block to the screen. - * - ****************************************************************************/ - -#ifndef __V_VIDEO__ -#define __V_VIDEO__ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "doomtype.h" - -/* Needed because we are referring to patches. */ - -#include "v_patch.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define CENTERY (SCREENHEIGHT / 2) - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -extern int dirtybox[4]; - -extern byte *tinttable; - -/* haleyjd 08/28/10: implemented for Strife support - * haleyjd 08/28/10: Patch clipping callback, implemented to support Choco - * Strife. - */ - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -typedef boolean (*vpatchclipfunc_t)(patch_t *, int, int); - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -void v_set_patch_clip_callback(vpatchclipfunc_t func); - -/**************************************************************************** - * Name: v_init - * - * Description: - * Allocates buffer screens, call before r_init. - * - ****************************************************************************/ - -void v_init(void); - -/**************************************************************************** - * Name: v_copy_rect - * - * Description: - * Draw a block from the specified source screen to the screen. - * - ****************************************************************************/ - -void v_copy_rect(int srcx, int srcy, pixel_t *source, int width, int height, - int destx, int desty); - -void v_draw_patch(int x, int y, patch_t *patch); -void v_draw_patch_flipped(int x, int y, patch_t *patch); -void v_draw_tl_patch(int x, int y, patch_t *patch); -void v_draw_alt_tl_patch(int x, int y, patch_t *patch); -void v_draw_shadowed_patch(int x, int y, patch_t *patch); -void v_draw_xla_patch(int x, int y, patch_t *patch); /* villsa [STRIFE] */ -void v_draw_patch_direct(int x, int y, patch_t *patch); - -/**************************************************************************** - * Name: v_draw_block - * - * Description: - * Draw a linear block of pixels into the view buffer. - * - ****************************************************************************/ - -void v_draw_block(int x, int y, int width, int height, pixel_t *src); - -void v_mark_rect(int x, int y, int width, int height); - -void v_draw_filled_box(int x, int y, int w, int h, int c); -void v_draw_horiz_line(int x, int y, int w, int c); -void v_draw_vert_line(int x, int y, int h, int c); -void v_draw_box(int x, int y, int w, int h, int c); - -/**************************************************************************** - * Name: v_draw_raw_screen - * - * Description: - * Draw a raw screen lump - * - ****************************************************************************/ - -void v_draw_raw_screen(pixel_t *raw); - -/**************************************************************************** - * Name: v_use_buffer - * - * Description: - * Temporarily switch to using a different buffer to draw graphics, etc. - * - ****************************************************************************/ - -void v_use_buffer(pixel_t *buffer); - -/**************************************************************************** - * Name: v_restore_buffer - * - * Description: - * Return to using the normal screen buffer to draw graphics. - * - ****************************************************************************/ - -void v_restore_buffer(void); - -/**************************************************************************** - * Name: v_screenshot - * - * Description: - * Save a screenshot of the current screen to a file, named in the format - * described in the string passed to the function, eg. "DOOM%02i.pcx" - * - ****************************************************************************/ - -void v_screenshot(const char *format); - -/**************************************************************************** - * Name: v_load_tint_table - * - * Description: - * Load the lookup table for translucency calculations from the TINTTAB - * lump. - * - ****************************************************************************/ - -void v_load_tint_table(void); - -/**************************************************************************** - * Name: v_load_xla_table - * - * Description: - * villsa [STRIFE] - * Load the lookup table for translucency calculations from the XLATAB lump. - * - ****************************************************************************/ - -void v_load_xla_table(void); - -void v_draw_mouse_speed_box(int speed); - -#endif diff --git a/games/NXDoom/src/w_checksum.c b/games/NXDoom/src/w_checksum.c deleted file mode 100644 index 28dbf8d16..000000000 --- a/games/NXDoom/src/w_checksum.c +++ /dev/null @@ -1,113 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/w_checksum.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Generate a checksum of the WAD directory. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include - -#include "i_system.h" -#include "m_misc.h" -#include "sha1.h" -#include "w_checksum.h" -#include "w_wad.h" - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static wad_file_t **g_open_wadfiles = NULL; -static int g_num_open_wadfiles = 0; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static int get_file_number(wad_file_t *handle) -{ - int i; - int result; - - for (i = 0; i < g_num_open_wadfiles; ++i) - { - if (g_open_wadfiles[i] == handle) - { - return i; - } - } - - /* Not found in list. This is a new file we haven't seen yet. - * Allocate another slot for this file. - */ - - g_open_wadfiles = i_realloc(g_open_wadfiles, - sizeof(wad_file_t *) * (g_num_open_wadfiles + 1)); - g_open_wadfiles[g_num_open_wadfiles] = handle; - - result = g_num_open_wadfiles; - ++g_num_open_wadfiles; - - return result; -} - -static void checksum_add_lump(SHA1_CTX *sha1_context, lumpinfo_t *lump) -{ - char buf[9]; - int fileno; - - fileno = get_file_number(lump->wad_file); - - m_str_copy(buf, lump->name, sizeof(buf)); - sha1_updatestring(sha1_context, buf); - sha1_updateint32(sha1_context, fileno); - sha1_updateint32(sha1_context, lump->position); - sha1_updateint32(sha1_context, lump->size); -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -void w_checksum(sha1_digest_t digest) -{ - SHA1_CTX sha1_context; - unsigned int i; - - sha1init(&sha1_context); - - g_num_open_wadfiles = 0; - - /* Go through each entry in the WAD directory, adding information - * about each entry to the SHA1 hash. - */ - - for (i = 0; i < numlumps; ++i) - { - checksum_add_lump(&sha1_context, lumpinfo[i]); - } - - sha1final(digest, &sha1_context); -} diff --git a/games/NXDoom/src/w_checksum.h b/games/NXDoom/src/w_checksum.h deleted file mode 100644 index 316239b70..000000000 --- a/games/NXDoom/src/w_checksum.h +++ /dev/null @@ -1,39 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/w_checksum.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Generate a checksum of the WAD directory. - * - ****************************************************************************/ - -#ifndef W_CHECKSUM_H -#define W_CHECKSUM_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "doomtype.h" - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -extern void w_checksum(sha1_digest_t digest); - -#endif /* W_CHECKSUM_H */ diff --git a/games/NXDoom/src/w_file.c b/games/NXDoom/src/w_file.c deleted file mode 100644 index 38b4d9574..000000000 --- a/games/NXDoom/src/w_file.c +++ /dev/null @@ -1,92 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/w_file.c - * - * SPDX-License-Identifier: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * WAD I/O functions. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include "config.h" - -#include "doomtype.h" -#include "m_argv.h" - -#include "w_file.h" - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static wad_file_class_t *wad_file_classes[] = -{ - &stdc_wad_file, -}; - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -wad_file_t *w_open_file(const char *path) -{ - wad_file_t *result; - int i; - - /* @category obscure - * - * Use the OS's virtual memory subsystem to map WAD files - * directly into memory. - */ - - if (!m_check_parm("-mmap")) - { - return stdc_wad_file.open_file(path); - } - - /* Try all classes in order until we find one that works */ - - result = NULL; - - for (i = 0; i < arrlen(wad_file_classes); ++i) - { - result = wad_file_classes[i]->open_file(path); - - if (result != NULL) - { - break; - } - } - - return result; -} - -void w_close_file(wad_file_t *wad) -{ - wad->file_class->close_file(wad); -} - -size_t w_read(wad_file_t *wad, unsigned int offset, void *buffer, - size_t buffer_len) -{ - return wad->file_class->read(wad, offset, buffer, buffer_len); -} diff --git a/games/NXDoom/src/w_file.h b/games/NXDoom/src/w_file.h deleted file mode 100644 index 32ac34222..000000000 --- a/games/NXDoom/src/w_file.h +++ /dev/null @@ -1,111 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/w_file.h - * - * SPDX-License-Identifier: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * WAD I/O functions. - * - ****************************************************************************/ - -#ifndef __W_FILE__ -#define __W_FILE__ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "doomtype.h" -#include - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -typedef struct _wad_file_s wad_file_t; - -typedef struct -{ - /* Open a file for reading. */ - - wad_file_t *(*open_file)(const char *path); - - /* Close the specified file. */ - - void (*close_file)(wad_file_t *file); - - /* Read data from the specified position in the file into the provided - * buffer. Returns the number of bytes read. - */ - - size_t (*read)(wad_file_t *file, unsigned int offset, void *buffer, - size_t buffer_len); -} wad_file_class_t; - -struct _wad_file_s -{ - /* Class of this file. */ - - wad_file_class_t *file_class; - - /* If this is NULL, the file cannot be mapped into memory. If this is - * non-NULL, it is a pointer to the mapped file. - */ - - byte *mapped; - - /* Length of the file, in bytes. */ - - unsigned int length; - - /* File's location on disk. */ - - const char *path; -}; - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -extern wad_file_class_t stdc_wad_file; - -#ifdef HAVE_MMAP -extern wad_file_class_t posix_wad_file; -#endif - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/* Open the specified file. Returns a pointer to a new wad_file_t - * handle for the WAD file, or NULL if it could not be opened. - */ - -wad_file_t *w_open_file(const char *path); - -/* Close the specified WAD file. */ - -void w_close_file(wad_file_t *wad); - -/* Read data from the specified file into the provided buffer. The - * data is read from the specified offset from the start of the file. - * Returns the number of bytes read. - */ - -size_t w_read(wad_file_t *wad, unsigned int offset, void *buffer, - size_t buffer_len); - -#endif /* __W_FILE__ */ diff --git a/games/NXDoom/src/w_file_stdc.c b/games/NXDoom/src/w_file_stdc.c deleted file mode 100644 index 361bf2060..000000000 --- a/games/NXDoom/src/w_file_stdc.c +++ /dev/null @@ -1,123 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/w_file_stdc.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * WAD I/O functions. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include "m_misc.h" -#include "w_file.h" -#include "z_zone.h" - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -typedef struct -{ - wad_file_t wad; - FILE *fstream; -} stdc_wad_file_t; - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -static wad_file_t *w_stdc_openfile(const char *path); -static void w_stdc_closefile(wad_file_t *wad); -static size_t w_stdc_read(wad_file_t *wad, unsigned int offset, void *buffer, - size_t buffer_len); - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -wad_file_class_t stdc_wad_file = -{ - w_stdc_openfile, - w_stdc_closefile, - w_stdc_read, -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static wad_file_t *w_stdc_openfile(const char *path) -{ - stdc_wad_file_t *result; - FILE *fstream; - - fstream = fopen(path, "rb"); - - if (fstream == NULL) - { - return NULL; - } - - /* Create a new stdc_wad_file_t to hold the file handle. */ - - result = z_malloc(sizeof(stdc_wad_file_t), PU_STATIC, 0); - result->wad.file_class = &stdc_wad_file; - result->wad.mapped = NULL; - result->wad.length = m_file_length(fstream); - result->wad.path = m_string_duplicate(path); - result->fstream = fstream; - - return &result->wad; -} - -static void w_stdc_closefile(wad_file_t *wad) -{ - stdc_wad_file_t *stdc_wad; - - stdc_wad = (stdc_wad_file_t *)wad; - - fclose(stdc_wad->fstream); - z_free(stdc_wad); -} - -/* Read data from the specified position in the file into the - * provided buffer. Returns the number of bytes read. - */ - -static size_t w_stdc_read(wad_file_t *wad, unsigned int offset, void *buffer, - size_t buffer_len) -{ - stdc_wad_file_t *stdc_wad; - size_t result; - - stdc_wad = (stdc_wad_file_t *)wad; - - /* Jump to the specified position in the file. */ - - fseek(stdc_wad->fstream, offset, SEEK_SET); - - /* Read into the buffer. */ - - result = fread(buffer, 1, buffer_len, stdc_wad->fstream); - - return result; -} diff --git a/games/NXDoom/src/w_main.c b/games/NXDoom/src/w_main.c deleted file mode 100644 index ce1176547..000000000 --- a/games/NXDoom/src/w_main.c +++ /dev/null @@ -1,294 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/w_main.c - * - * SPDX-License-Identifier: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Common code to parse command line, identifying WAD files to load. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include "config.h" -#include "d_iwad.h" -#include "i_glob.h" -#include "i_system.h" -#include "m_argv.h" -#include "w_main.h" -#include "w_merge.h" -#include "w_wad.h" -#include "z_zone.h" - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -struct uniquelump -{ - gamemission_t mission; - const char *lumpname; -}; - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/* Lump names that are unique to particular game types. This lets us check - * the user is not trying to play with the wrong executable, eg. - * chocolate-doom -iwad hexen.wad. - */ - -static const struct uniquelump g_unique_lumps[] = -{ - {doom, "POSSA1"}, - {heretic, "IMPXA1"}, - {hexen, "ETTNA1"}, - {strife, "AGRDA1"}, -}; - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/* Parse the command line, merging WAD files that are sppecified. - * Returns true if at least one file was added. - */ - -boolean w_parse_command_line(void) -{ - boolean modifiedgame = false; - int p; - - /* Merged PWADs are loaded first, because they are supposed to be - * modified IWADs. - */ - - /* @arg - * @category mod - * - * Simulates the behavior of deutex's -merge option, merging a PWAD - * into the main IWAD. Multiple files may be specified. - */ - - p = m_check_parm_with_args("-merge", 1); - - if (p > 0) - { - for (p = p + 1; p < myargc && myargv[p][0] != '-'; ++p) - { - char *filename; - - modifiedgame = true; - - filename = d_try_find_wad_by_name(myargv[p]); - - printf(" merging %s\n", filename); - w_merge_file(filename); - free(filename); - } - } - - /* NWT-style merging: */ - - /* NWT's -merge option: */ - - /* @arg - * @category mod - * - * Simulates the behavior of NWT's -merge option. Multiple files - * may be specified. - */ - - p = m_check_parm_with_args("-nwtmerge", 1); - - if (p > 0) - { - for (p = p + 1; p < myargc && myargv[p][0] != '-'; ++p) - { - char *filename; - - modifiedgame = true; - - filename = d_try_find_wad_by_name(myargv[p]); - - printf(" performing NWT-style merge of %s\n", filename); - w_nwt_dash_merge(filename); - free(filename); - } - } - - /* Add flats */ - - /* @arg - * @category mod - * - * Simulates the behavior of NWT's -af option, merging flats into - * the main IWAD directory. Multiple files may be specified. - */ - - p = m_check_parm_with_args("-af", 1); - - if (p > 0) - { - for (p = p + 1; p < myargc && myargv[p][0] != '-'; ++p) - { - char *filename; - - modifiedgame = true; - - filename = d_try_find_wad_by_name(myargv[p]); - - printf(" merging flats from %s\n", filename); - w_nwt_merge_file(filename, W_NWT_MERGE_FLATS); - free(filename); - } - } - - /* @arg - * @category mod - * - * Simulates the behavior of NWT's -as option, merging sprites - * into the main IWAD directory. Multiple files may be specified. - */ - - p = m_check_parm_with_args("-as", 1); - - if (p > 0) - { - for (p = p + 1; p < myargc && myargv[p][0] != '-'; ++p) - { - char *filename; - - modifiedgame = true; - filename = d_try_find_wad_by_name(myargv[p]); - - printf(" merging sprites from %s\n", filename); - w_nwt_merge_file(filename, W_NWT_MERGE_SPRITES); - free(filename); - } - } - - /* @arg - * @category mod - * - * Equivalent to "-af -as ". - */ - - p = m_check_parm_with_args("-aa", 1); - - if (p > 0) - { - for (p = p + 1; p < myargc && myargv[p][0] != '-'; ++p) - { - char *filename; - - modifiedgame = true; - - filename = d_try_find_wad_by_name(myargv[p]); - - printf(" merging sprites and flats from %s\n", filename); - w_nwt_merge_file(filename, - W_NWT_MERGE_SPRITES | W_NWT_MERGE_FLATS); - free(filename); - } - } - - /* @arg - * @vanilla - * - * Load the specified PWAD files. Each succeeding argument is - * treated as a PWAD file name until one starts with a dash or the - * argument list is exhausted. - */ - - p = m_check_parm_with_args("-file", 1); - if (p) - { - /* the params after p are wadfile/lump names, - * until end of params or another - preceded param - */ - - modifiedgame = true; /* homebrew levels */ - while (++p != myargc && myargv[p][0] != '-') - { - char *filename; - - filename = d_try_find_wad_by_name(myargv[p]); - - printf(" adding %s\n", filename); - w_add_file(filename); - free(filename); - } - } - - return modifiedgame; -} - -/* Load all WAD files from the given directory. */ - -void w_auto_load_wads(const char *path) -{ - glob_t *glob; - const char *filename; - - glob = i_start_multi_glob(path, GLOB_FLAG_NOCASE | GLOB_FLAG_SORTED, - "*.wad", "*.lmp", NULL); - for (; ; ) - { - filename = i_next_glob(glob); - if (filename == NULL) - { - break; - } - - printf(" [autoload] merging %s\n", filename); - w_merge_file(filename); - } - - i_end_glob(glob); -} - -void w_check_correct_iwad(gamemission_t mission) -{ - int i; - lumpindex_t lumpnum; - - for (i = 0; i < arrlen(g_unique_lumps); ++i) - { - if (mission != g_unique_lumps[i].mission) - { - lumpnum = w_check_num_for_name(g_unique_lumps[i].lumpname); - - if (lumpnum >= 0) - { - i_error( - "\nYou are trying to use a %s IWAD file with " - "the %s%s binary.\nThis isn't going to work.\n" - "You probably want to use the %s%s binary.", - d_suggest_game_name( - g_unique_lumps[i].mission, indetermined), - PROGRAM_PREFIX, d_game_mission_string(mission), - PROGRAM_PREFIX, - d_game_mission_string(g_unique_lumps[i].mission)); - } - } - } -} diff --git a/games/NXDoom/src/w_main.h b/games/NXDoom/src/w_main.h deleted file mode 100644 index beab3f29b..000000000 --- a/games/NXDoom/src/w_main.h +++ /dev/null @@ -1,43 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/w_main.h - * - * SPDX-License-Identifier: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Common code to parse command line, identifying WAD files to load. - * - ****************************************************************************/ - -#ifndef W_MAIN_H -#define W_MAIN_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "d_mode.h" - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -boolean w_parse_command_line(void); -void w_check_correct_iwad(gamemission_t mission); - -/* Autoload all .wad files from the given directory: */ - -void w_auto_load_wads(const char *path); - -#endif /* W_MAIN_H */ diff --git a/games/NXDoom/src/w_merge.c b/games/NXDoom/src/w_merge.c deleted file mode 100644 index 88a05b4bd..000000000 --- a/games/NXDoom/src/w_merge.c +++ /dev/null @@ -1,764 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/w_merge.c - * - * SPDX-License-Identifier: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Handles merging of PWADs, similar to deutex's -merge option - * - * Ideally this should work exactly the same as in deutex, but trying to - * read the deutex source code made my brain hurt. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include -#include - -#include "doomtype.h" -#include "i_system.h" -#include "m_misc.h" -#include "w_merge.h" -#include "w_wad.h" -#include "z_zone.h" - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -typedef enum -{ - SECTION_NORMAL, - SECTION_FLATS, - SECTION_SPRITES, -} section_t; - -typedef struct -{ - lumpinfo_t **lumps; - int numlumps; -} searchlist_t; - -typedef struct -{ - char sprname[4]; - char frame; - lumpinfo_t *angle_lumps[8]; -} sprite_frame_t; - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static searchlist_t iwad; -static searchlist_t iwad_sprites; -static searchlist_t pwad; - -static searchlist_t iwad_flats; -static searchlist_t pwad_sprites; -static searchlist_t pwad_flats; - -/* lumps with these sprites must be replaced in the IWAD */ - -static sprite_frame_t *sprite_frames; -static int num_sprite_frames; -static int sprite_frames_alloced; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/* Search in a list to find a lump with a particular name - * Linear search (slow!) - * - * Returns -1 if not found - */ - -static int find_in_list(searchlist_t *list, const char *name) -{ - int i; - - for (i = 0; i < list->numlumps; ++i) - { - if (!strncasecmp(list->lumps[i]->name, name, 8)) return i; - } - - return -1; -} - -static boolean setup_list(searchlist_t *list, searchlist_t *src_list, - const char *startname, const char *endname, - const char *startname2, const char *endname2) -{ - int startlump; - int endlump; - - list->numlumps = 0; - startlump = find_in_list(src_list, startname); - - if (startname2 != NULL && startlump < 0) - { - startlump = find_in_list(src_list, startname2); - } - - if (startlump >= 0) - { - endlump = find_in_list(src_list, endname); - - if (endname2 != NULL && endlump < 0) - { - endlump = find_in_list(src_list, endname2); - } - - if (endlump > startlump) - { - list->lumps = src_list->lumps + startlump + 1; - list->numlumps = endlump - startlump - 1; - return true; - } - } - - return false; -} - -/* Sets up the sprite/flat search lists */ - -static void setup_lists(void) -{ - /* IWAD */ - - if (!setup_list(&iwad_flats, &iwad, "F_START", "F_END", NULL, NULL)) - { - i_error("Flats section not found in IWAD"); - } - - if (!setup_list(&iwad_sprites, &iwad, "S_START", "S_END", NULL, NULL)) - - { - i_error("Sprites section not found in IWAD"); - } - - /* PWAD */ - - setup_list(&pwad_flats, &pwad, "F_START", "F_END", "FF_START", "FF_END"); - setup_list(&pwad_sprites, &pwad, "S_START", "S_END", "SS_START", "SS_END"); -} - -/* Initialize the replace list */ - -static void init_sprite_list(void) -{ - if (sprite_frames == NULL) - { - sprite_frames_alloced = 128; - sprite_frames = z_malloc( - sizeof(*sprite_frames) * sprite_frames_alloced, - PU_STATIC, NULL - ); - } - - num_sprite_frames = 0; -} - -static boolean valid_sprite_lump_name(char *name) -{ - if (name[0] == '\0' || name[1] == '\0' || name[2] == '\0' || - name[3] == '\0') - { - return false; - } - - /* First frame: */ - - if (name[4] == '\0' || !isdigit(name[5])) - { - return false; - } - - /* Second frame (optional): */ - - if (name[6] != '\0' && !isdigit(name[7])) - { - return false; - } - - return true; -} - -static sprite_frame_t *find_sprite_frame(char *name, int frame) -{ - sprite_frame_t *result; - int i; - - /* Search the list and try to find the frame */ - - for (i = 0; i < num_sprite_frames; ++i) - { - sprite_frame_t *cur = &sprite_frames[i]; - - if (!strncasecmp(cur->sprname, name, 4) && cur->frame == frame) - { - return cur; - } - } - - /* Not found in list; Need to add to the list */ - - /* Grow list? */ - - if (num_sprite_frames >= sprite_frames_alloced) - { - sprite_frame_t *newframes; - - newframes = z_malloc( - sprite_frames_alloced * 2 * sizeof(*sprite_frames), - PU_STATIC, NULL - ); - memcpy(newframes, sprite_frames, - sprite_frames_alloced * sizeof(*sprite_frames)); - z_free(sprite_frames); - sprite_frames_alloced *= 2; - sprite_frames = newframes; - } - - /* Add to end of list */ - - result = &sprite_frames[num_sprite_frames]; - memcpy(result->sprname, name, 4); - result->frame = frame; - - for (i = 0; i < 8; ++i) - result->angle_lumps[i] = NULL; - - ++num_sprite_frames; - - return result; -} - -/* Check if sprite lump is needed in the new wad */ - -static boolean sprite_lump_needed(lumpinfo_t *lump) -{ - sprite_frame_t *sprite; - int angle_num; - int i; - - if (!valid_sprite_lump_name(lump->name)) - { - return true; - } - - /* check the first frame */ - - sprite = find_sprite_frame(lump->name, lump->name[4]); - angle_num = lump->name[5] - '0'; - - if (angle_num == 0) - { - /* must check all frames */ - - for (i = 0; i < 8; ++i) - { - if (sprite->angle_lumps[i] == lump) return true; - } - } - else - { - /* check if this lump is being used for this frame */ - - if (sprite->angle_lumps[angle_num - 1] == lump) return true; - } - - /* second frame if any */ - - /* no second frame? */ - - if (lump->name[6] == '\0') return false; - - sprite = find_sprite_frame(lump->name, lump->name[6]); - angle_num = lump->name[7] - '0'; - - if (angle_num == 0) - { - /* must check all frames */ - - for (i = 0; i < 8; ++i) - { - if (sprite->angle_lumps[i] == lump) return true; - } - } - else - { - /* check if this lump is being used for this frame */ - - if (sprite->angle_lumps[angle_num - 1] == lump) return true; - } - - return false; -} - -static void add_sprite_lump(lumpinfo_t *lump) -{ - sprite_frame_t *sprite; - int angle_num; - int i; - - if (!valid_sprite_lump_name(lump->name)) - { - return; - } - - /* first angle */ - - sprite = find_sprite_frame(lump->name, lump->name[4]); - angle_num = lump->name[5] - '0'; - - if (angle_num == 0) - { - for (i = 0; i < 8; ++i) - sprite->angle_lumps[i] = lump; - } - else - { - sprite->angle_lumps[angle_num - 1] = lump; - } - - /* second angle */ - - /* no second angle? */ - - if (lump->name[6] == '\0') return; - - sprite = find_sprite_frame(lump->name, lump->name[6]); - angle_num = lump->name[7] - '0'; - - if (angle_num == 0) - { - for (i = 0; i < 8; ++i) - sprite->angle_lumps[i] = lump; - } - else - { - sprite->angle_lumps[angle_num - 1] = lump; - } -} - -/* Generate the list. Run at the start, before merging */ - -static void generate_sprite_list(void) -{ - int i; - - init_sprite_list(); - - /* Add all sprites from the IWAD */ - - for (i = 0; i < iwad_sprites.numlumps; ++i) - { - add_sprite_lump(iwad_sprites.lumps[i]); - } - - /* Add all sprites from the PWAD - * (replaces IWAD sprites) - */ - - for (i = 0; i < pwad_sprites.numlumps; ++i) - { - add_sprite_lump(pwad_sprites.lumps[i]); - } -} - -/* Perform the merge. - * - * The merge code creates a new lumpinfo list, adding entries from the - * IWAD first followed by the PWAD. - * - * For the IWAD: - * * Flats are added. If a flat with the same name is in the PWAD, - * it is ignored(deleted). At the end of the section, all flats in the - * PWAD are inserted. This is consistent with the behavior of - * deutex/deusf. - * * Sprites are added. The "replace list" is generated before the merge - * from the list of sprites in the PWAD. Any sprites in the IWAD found - * to match the replace list are removed. At the end of the section, - * the sprites from the PWAD are inserted. - * - * For the PWAD: - * * All Sprites and Flats are ignored, with the assumption they have - * already been merged into the IWAD's sections. - */ - -static void do_merge(void) -{ - section_t current_section; - lumpinfo_t **newlumps; - int num_newlumps; - int lumpindex; - int i; - int n; - - /* Can't ever have more lumps than we already have */ - - newlumps = calloc(numlumps, sizeof(lumpinfo_t *)); - num_newlumps = 0; - - /* Add IWAD lumps */ - - current_section = SECTION_NORMAL; - - for (i = 0; i < iwad.numlumps; ++i) - { - lumpinfo_t *lump = iwad.lumps[i]; - - switch (current_section) - { - case SECTION_NORMAL: - if (!strncasecmp(lump->name, "F_START", 8)) - { - current_section = SECTION_FLATS; - } - else if (!strncasecmp(lump->name, "S_START", 8)) - { - current_section = SECTION_SPRITES; - } - - newlumps[num_newlumps++] = lump; - - break; - - case SECTION_FLATS: - - /* Have we reached the end of the section? */ - - if (!strncasecmp(lump->name, "F_END", 8)) - { - /* Add all new flats from the PWAD to the end - * of the section - */ - - for (n = 0; n < pwad_flats.numlumps; ++n) - { - newlumps[num_newlumps++] = pwad_flats.lumps[n]; - } - - newlumps[num_newlumps++] = lump; - - /* back to normal reading */ - - current_section = SECTION_NORMAL; - } - else - { - /* If there is a flat in the PWAD with the same name, - * do not add it now. All PWAD flats are added to the - * end of the section. Otherwise, if it is only in the - * IWAD, add it now - */ - - lumpindex = find_in_list(&pwad_flats, lump->name); - - if (lumpindex < 0) - { - newlumps[num_newlumps++] = lump; - } - } - - break; - - case SECTION_SPRITES: - - /* Have we reached the end of the section? */ - - if (!strncasecmp(lump->name, "S_END", 8)) - { - /* add all the PWAD sprites */ - - for (n = 0; n < pwad_sprites.numlumps; ++n) - { - if (sprite_lump_needed(pwad_sprites.lumps[n])) - { - newlumps[num_newlumps++] = pwad_sprites.lumps[n]; - } - } - - /* copy the ending */ - - newlumps[num_newlumps++] = lump; - - /* back to normal reading */ - - current_section = SECTION_NORMAL; - } - else - { - /* Is this lump holding a sprite to be replaced in the - * PWAD? If so, wait until the end to add it. - */ - - if (sprite_lump_needed(lump)) - { - newlumps[num_newlumps++] = lump; - } - } - - break; - } - } - - /* Add PWAD lumps */ - - current_section = SECTION_NORMAL; - - for (i = 0; i < pwad.numlumps; ++i) - { - lumpinfo_t *lump = pwad.lumps[i]; - - switch (current_section) - { - case SECTION_NORMAL: - if (!strncasecmp(lump->name, "F_START", 8) || - !strncasecmp(lump->name, "FF_START", 8)) - { - current_section = SECTION_FLATS; - } - else if (!strncasecmp(lump->name, "S_START", 8) || - !strncasecmp(lump->name, "SS_START", 8)) - { - current_section = SECTION_SPRITES; - } - else - { - /* Don't include the headers of sections */ - - newlumps[num_newlumps++] = lump; - } - break; - - case SECTION_FLATS: - - /* PWAD flats are ignored (already merged) */ - - if (!strncasecmp(lump->name, "FF_END", 8) || - !strncasecmp(lump->name, "F_END", 8)) - { - /* end of section */ - - current_section = SECTION_NORMAL; - } - break; - - case SECTION_SPRITES: - - /* PWAD sprites are ignored (already merged) */ - - if (!strncasecmp(lump->name, "SS_END", 8) || - !strncasecmp(lump->name, "S_END", 8)) - { - /* end of section */ - - current_section = SECTION_NORMAL; - } - break; - } - } - - /* Switch to the new lumpinfo, and free the old one */ - - free(lumpinfo); - lumpinfo = newlumps; - numlumps = num_newlumps; -} - -/* Replace lumps in the given list with lumps from the PWAD */ - -static void w_nwt_add_lumps(searchlist_t *list) -{ - int i; - - /* Go through the IWAD list given, replacing lumps with lumps of - * the same name from the PWAD - */ - - for (i = 0; i < list->numlumps; ++i) - { - int index; - - index = find_in_list(&pwad, list->lumps[i]->name); - - if (index > 0) - { - memcpy(list->lumps[i], pwad.lumps[index], sizeof(lumpinfo_t)); - } - } -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -void w_print_directory(void) -{ - unsigned int i; - unsigned int n; - - /* debug */ - - for (i = 0; i < numlumps; ++i) - { - for (n = 0; n < 8 && lumpinfo[i]->name[n] != '\0'; ++n) - putchar(lumpinfo[i]->name[n]); - putchar('\n'); - } -} - -/* Merge in a file by name */ - -void w_merge_file(const char *filename) -{ - int old_numlumps; - - old_numlumps = numlumps; - - /* Load PWAD */ - - if (w_add_file(filename) == NULL) return; - - /* IWAD is at the start, PWAD was appended to the end */ - - iwad.lumps = lumpinfo; - iwad.numlumps = old_numlumps; - - pwad.lumps = lumpinfo + old_numlumps; - pwad.numlumps = numlumps - old_numlumps; - - /* Setup sprite/flat lists */ - - setup_lists(); - - /* Generate list of sprites to be replaced by the PWAD */ - - generate_sprite_list(); - - /* Perform the merge */ - - do_merge(); -} - -/* Merge sprites and flats in the way NWT does with its -af and -as - * command-line options. - */ - -void w_nwt_merge_file(const char *filename, int flags) -{ - int old_numlumps; - - old_numlumps = numlumps; - - /* Load PWAD */ - - if (w_add_file(filename) == NULL) return; - - /* IWAD is at the start, PWAD was appended to the end */ - - iwad.lumps = lumpinfo; - iwad.numlumps = old_numlumps; - - pwad.lumps = lumpinfo + old_numlumps; - pwad.numlumps = numlumps - old_numlumps; - - /* Setup sprite/flat lists */ - - setup_lists(); - - /* Merge in flats? */ - - if (flags & W_NWT_MERGE_FLATS) - { - w_nwt_add_lumps(&iwad_flats); - } - - /* Sprites? */ - - if (flags & W_NWT_MERGE_SPRITES) - { - w_nwt_add_lumps(&iwad_sprites); - } - - /* Discard the PWAD */ - - numlumps = old_numlumps; -} - -/* Simulates the NWT -merge command line parameter. What this does is load - * a PWAD, then search the IWAD sprites, removing any sprite lumps that also - * exist in the PWAD. - */ - -void w_nwt_dash_merge(const char *filename) -{ - wad_file_t *wad_file; - int old_numlumps; - int i; - - old_numlumps = numlumps; - - /* Load PWAD */ - - wad_file = w_add_file(filename); - - if (wad_file == NULL) - { - return; - } - - /* IWAD is at the start, PWAD was appended to the end */ - - iwad.lumps = lumpinfo; - iwad.numlumps = old_numlumps; - - pwad.lumps = lumpinfo + old_numlumps; - pwad.numlumps = numlumps - old_numlumps; - - /* Setup sprite/flat lists */ - - setup_lists(); - - /* Search through the IWAD sprites list. */ - - for (i = 0; i < iwad_sprites.numlumps; ++i) - { - if (find_in_list(&pwad, iwad_sprites.lumps[i]->name) >= 0) - { - /* Replace this entry with an empty string. This is what - * nwt -merge does. - */ - - m_str_copy(iwad_sprites.lumps[i]->name, "", 8); - } - } - - /* Discard PWAD - * The PWAD must now be added in again with -file. - */ - - numlumps = old_numlumps; - - w_close_file(wad_file); -} diff --git a/games/NXDoom/src/w_merge.h b/games/NXDoom/src/w_merge.h deleted file mode 100644 index ce580afc5..000000000 --- a/games/NXDoom/src/w_merge.h +++ /dev/null @@ -1,56 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/w_merge.h - * - * SPDX-License-Identifier: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Handles merging of PWADs, similar to deutex's -merge option - * - * Ideally this should work exactly the same as in deutex, but trying to - * read the deutex source code made my brain hurt. - * - ****************************************************************************/ - -#ifndef W_MERGE_H -#define W_MERGE_H - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define W_NWT_MERGE_SPRITES 0x1 -#define W_NWT_MERGE_FLATS 0x2 - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/* Add a new WAD and merge it into the main directory */ - -void w_merge_file(const char *filename); - -/* NWT-style merging */ - -void w_nwt_merge_file(const char *filename, int flags); - -/* Acts the same as NWT's "-merge" option. */ - -void w_nwt_dash_merge(const char *filename); - -/* Debug function that prints the WAD directory. */ - -void w_print_directory(void); - -#endif /* W_MERGE_H */ diff --git a/games/NXDoom/src/w_wad.c b/games/NXDoom/src/w_wad.c deleted file mode 100644 index 88c75ada5..000000000 --- a/games/NXDoom/src/w_wad.c +++ /dev/null @@ -1,663 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/w_wad.c - * - * SPDX-License-Identifier: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Handles WAD file header, directory, lump I/O. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include -#include - -#include "doomtype.h" - -#include "i_swap.h" -#include "i_system.h" -#include "i_video.h" -#include "m_misc.h" -#include "v_diskicon.h" -#include "z_zone.h" - -#include "w_wad.h" - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -begin_packed_struct struct wadinfo_t -{ - /* Should be "IWAD" or "PWAD". */ - - char identification[4]; - int numlumps; - int infotableofs; -} end_packed_struct; - -typedef struct wadinfo_t wadinfo_t; - -begin_packed_struct struct filelump_t -{ - int filepos; - int size; - char name[8]; -} end_packed_struct; - -typedef struct filelump_t filelump_t; - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/* Hash table for fast lookups */ - -static lumpindex_t *lumphash; - -/* Variables for the reload hack: filename of the PWAD to reload, and the - * lumps from WADs before the reload file, so we can resent numlumps and - * load the file again. - */ - -static wad_file_t *reloadhandle = NULL; -static lumpinfo_t *reloadlumps = NULL; -static char *reloadname = NULL; -static int reloadlump = -1; - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/* Location of each lump on disk. */ - -lumpinfo_t **lumpinfo; -unsigned int numlumps = 0; - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/* Hash function used for lump names. */ - -unsigned int w_lump_name_hash(const char *s) -{ - /* This is the djb2 string hash function, modded to work on strings - * that have a maximum length of 8. - */ - - unsigned int result = 5381; - unsigned int i; - - for (i = 0; i < 8 && s[i] != '\0'; ++i) - { - result = ((result << 5) ^ result) ^ toupper(s[i]); - } - - return result; -} - -/* LUMP BASED ROUTINES. */ - -/* w_add_file - * - * All files are optional, but at least one file must be found (PWAD, if all - * required lumps are present). - * - * Files with a .wad extension are wadlink files with multiple lumps. - * - * Other files are single lumps with the base filename for the lump name. - */ - -wad_file_t *w_add_file(const char *filename) -{ - wadinfo_t header; - lumpindex_t i; - wad_file_t *wad_file; - int length; - int startlump; - filelump_t *fileinfo; - filelump_t *filerover; - lumpinfo_t *filelumps; - int numfilelumps; - - /* If the filename begins with a ~, it indicates that we should use the - * reload hack. - */ - - if (filename[0] == '~') - { - if (reloadname != NULL) - { - i_error("Prefixing a WAD filename with '~' indicates that the " - "WAD should be reloaded\n" - "on each level restart, for use by level authors for " - "rapid development. You\n" - "can only reload one WAD file, and it must be the last " - "file in the -file list."); - } - - reloadname = strdup(filename); - reloadlump = numlumps; - ++filename; - } - - /* Open the file and add to directory */ - - wad_file = w_open_file(filename); - - if (wad_file == NULL) - { - printf(" couldn't open %s\n", filename); - return NULL; - } - - if (strcasecmp(filename + strlen(filename) - 3, "wad")) - { - /* single lump file */ - - /* fraggle: Swap the filepos and size here. The WAD directory - * parsing code expects a little-endian directory, so will swap - * them back. Effectively we're constructing a "fake WAD directory" - * here, as it would appear on disk. - */ - - fileinfo = z_malloc(sizeof(filelump_t), PU_STATIC, 0); - fileinfo->filepos = LONG(0); - fileinfo->size = LONG(wad_file->length); - - /* Name the lump after the base of the filename (without the - * extension). - */ - - m_extract_file_base(filename, fileinfo->name); - numfilelumps = 1; - } - else - { - /* WAD file */ - - w_read(wad_file, 0, &header, sizeof(header)); - - if (strncmp(header.identification, "IWAD", 4)) - { - /* Homebrew levels? */ - - if (strncmp(header.identification, "PWAD", 4)) - { - w_close_file(wad_file); - i_error("Wad file %s doesn't have IWAD " - "or PWAD id\n", - filename); - } - - /* ???modifiedgame = true; */ - } - - header.numlumps = LONG(header.numlumps); - - /* Vanilla Doom doesn't like WADs with more than 4046 lumps - * https://www.doomworld.com/vb/post/1010985 - */ - - if (!strncmp(header.identification, "PWAD", 4) && - header.numlumps > 4046) - { - w_close_file(wad_file); - i_error("Error: Vanilla limit for lumps in a WAD is 4046, " - "PWAD %s has %d", - filename, header.numlumps); - } - - header.infotableofs = LONG(header.infotableofs); - length = header.numlumps * sizeof(filelump_t); - fileinfo = z_malloc(length, PU_STATIC, 0); - - w_read(wad_file, header.infotableofs, fileinfo, length); - numfilelumps = header.numlumps; - } - - /* Increase size of numlumps array to accommodate the new file. */ - - filelumps = calloc(numfilelumps, sizeof(lumpinfo_t)); - if (filelumps == NULL) - { - w_close_file(wad_file); - i_error("Failed to allocate array for lumps from new file."); - } - - startlump = numlumps; - numlumps += numfilelumps; - lumpinfo = i_realloc(lumpinfo, numlumps * sizeof(lumpinfo_t *)); - filerover = fileinfo; - - for (i = startlump; i < numlumps; ++i) - { - lumpinfo_t *lump_p = &filelumps[i - startlump]; - lump_p->wad_file = wad_file; - lump_p->position = LONG(filerover->filepos); - lump_p->size = LONG(filerover->size); - lump_p->cache = NULL; - strncpy(lump_p->name, filerover->name, 8); - lumpinfo[i] = lump_p; - - ++filerover; - } - - z_free(fileinfo); - - if (lumphash != NULL) - { - z_free(lumphash); - lumphash = NULL; - } - - /* If this is the reload file, we need to save some details about the - * file so that we can close it later on when we do a reload. - */ - - if (reloadname) - { - reloadhandle = wad_file; - reloadlumps = filelumps; - } - - return wad_file; -} - -/* w_check_num_for_name - * Returns -1 if name not found. - */ - -lumpindex_t w_check_num_for_name(const char *name) -{ - lumpindex_t i; - - /* Do we have a hash table yet? */ - - if (lumphash != NULL) - { - int hash; - - /* We do! Excellent. */ - - hash = w_lump_name_hash(name) % numlumps; - - for (i = lumphash[hash]; i != -1; i = lumpinfo[i]->next) - { - if (!strncasecmp(lumpinfo[i]->name, name, 8)) - { - return i; - } - } - } - else - { - /* We don't have a hash table generate yet. Linear search :-( - * - * scan backwards so patch lump files take precedence - */ - - for (i = numlumps - 1; i >= 0; --i) - { - if (!strncasecmp(lumpinfo[i]->name, name, 8)) - { - return i; - } - } - } - - /* TFB. Not found. */ - - return -1; -} - -/* w_get_num_for_name - * Calls w_check_num_for_name, but bombs out if not found. - */ - -lumpindex_t w_get_num_for_name(const char *name) -{ - lumpindex_t i; - - i = w_check_num_for_name(name); - - if (i < 0) - { - i_error("w_get_num_for_name: %s not found!", name); - } - - return i; -} - -/* w_lump_length - * Returns the buffer size needed to load the given lump. - */ - -int w_lump_length(lumpindex_t lump) -{ - if (lump >= numlumps) - { - i_error("w_lump_length: %i >= numlumps", lump); - } - - return lumpinfo[lump]->size; -} - -/* w_read_lump - * Loads the lump into the given buffer, - * which must be >= w_lump_length(). - */ - -void w_read_lump(lumpindex_t lump, void *dest) -{ - int c; - lumpinfo_t *l; - - if (lump >= numlumps) - { - i_error("w_read_lump: %i >= numlumps", lump); - } - - l = lumpinfo[lump]; - - v_begin_read(l->size); - - c = w_read(l->wad_file, l->position, dest, l->size); - - if (c < l->size) - { - i_error("w_read_lump: only read %i of %i on lump %i", - c, l->size, lump); - } -} - -/* w_cache_lump_num - * - * Load a lump into memory and return a pointer to a buffer containing - * the lump data. - * - * 'tag' is the type of zone memory buffer to allocate for the lump - * (usually PU_STATIC or PU_CACHE). If the lump is loaded as - * PU_STATIC, it should be released back using w_release_lump_num - * when no longer needed (do not use z_change_tag). - */ - -void *w_cache_lump_num(lumpindex_t lumpnum, int tag) -{ - byte *result; - lumpinfo_t *lump; - - if ((unsigned)lumpnum >= numlumps) - { - i_error("w_cache_lump_num: %i >= numlumps", lumpnum); - } - - lump = lumpinfo[lumpnum]; - - /* Get the pointer to return. If the lump is in a memory-mapped - * file, we can just return a pointer to within the memory-mapped - * region. If the lump is in an ordinary file, we may already - * have it cached; otherwise, load it into memory. - */ - - if (lump->wad_file->mapped != NULL) - { - /* Memory mapped file, return from the mmapped region. */ - - result = lump->wad_file->mapped + lump->position; - } - else if (lump->cache != NULL) - { - /* Already cached, so just switch the zone tag. */ - - result = lump->cache; - z_change_tag(lump->cache, tag); - } - else - { - /* Not yet loaded, so load it now */ - - lump->cache = z_malloc(w_lump_length(lumpnum), tag, &lump->cache); - w_read_lump(lumpnum, lump->cache); - result = lump->cache; - } - - return result; -} - -/* w_cache_lump_name */ - -void *w_cache_lump_name(const char *name, int tag) -{ - return w_cache_lump_num(w_get_num_for_name(name), tag); -} - -/* Release a lump back to the cache, so that it can be reused later - * without having to read from disk again, or alternatively, discarded - * if we run out of memory. - * - * Back in Vanilla Doom, this was just done using z_change_tag - * directly, but now that we have WAD mmap, things are a bit more - * complicated ... - */ - -void w_release_lump_num(lumpindex_t lumpnum) -{ - lumpinfo_t *lump; - - if ((unsigned)lumpnum >= numlumps) - { - i_error("w_release_lump_num: %i >= numlumps", lumpnum); - } - - lump = lumpinfo[lumpnum]; - - if (lump->wad_file->mapped != NULL) - { - /* Memory-mapped file, so nothing needs to be done here. */ - } - else - { - z_change_tag(lump->cache, PU_CACHE); - } -} - -void w_release_lump_name(const char *name) -{ - w_release_lump_num(w_get_num_for_name(name)); -} - -#if 0 - -/* w_profile */ - -int info[2500][10]; -int profilecount; - -void w_profile(void) -{ - int i; - memblock_t *block; - void *ptr; - char ch; - FILE *f; - int j; - char name[9]; - - for (i = 0; i < numlumps; i++) - { - ptr = lumpinfo[i].cache; - if (!ptr) - { - ch = ' '; - continue; - } - else - { - block = (memblock_t *)((byte *)ptr - sizeof(memblock_t)); - if (block->tag < PU_PURGELEVEL) - ch = 'S'; - else - ch = 'P'; - } - - info[i][profilecount] = ch; - } - - profilecount++; - - f = fopen("waddump.txt", "w"); - name[8] = 0; - - for (i = 0; i < numlumps; i++) - { - memcpy(name, lumpinfo[i].name, 8); - - for (j = 0; j < 8; j++) - { - if (!name[j]) - { - break; - } - } - - for (; j < 8; j++) - { - name[j] = ' '; - } - - fprintf(f, "%s ", name); - - for (j = 0; j < profilecount; j++) - { - fprintf(f, " %c", info[i][j]); - } - - fprintf(f, "\n"); - } - - fclose(f); -} -#endif - -/* Generate a hash table for fast lookups */ - -void w_generate_hash_table(void) -{ - lumpindex_t i; - - /* Free the old hash table, if there is one: */ - - if (lumphash != NULL) - { - z_free(lumphash); - } - - /* Generate hash table */ - - if (numlumps > 0) - { - lumphash = z_malloc(sizeof(lumpindex_t) * numlumps, PU_STATIC, NULL); - - for (i = 0; i < numlumps; ++i) - { - lumphash[i] = -1; - } - - for (i = 0; i < numlumps; ++i) - { - unsigned int hash; - - hash = w_lump_name_hash(lumpinfo[i]->name) % numlumps; - - /* Hook into the hash table */ - - lumpinfo[i]->next = lumphash[hash]; - lumphash[hash] = i; - } - } - - /* All done! */ -} - -/* The Doom reload hack. The idea here is that if you give a WAD file to - * -file prefixed with the ~ hack, that WAD file will be reloaded each time a - * new level is loaded. This lets you use a level editor in parallel and make - * incremental changes to the level you're working on without having to - * restart the game after every change. But: the reload feature is a fragile - * hack... - */ - -void w_reload(void) -{ - char *filename; - lumpindex_t i; - - if (reloadname == NULL) - { - return; - } - - /* We must free any lumps being cached from the PWAD we're about to reload: - */ - - for (i = reloadlump; i < numlumps; ++i) - { - if (lumpinfo[i]->cache != NULL) - { - z_free(lumpinfo[i]->cache); - } - } - - /* Reset numlumps to remove the reload WAD file: */ - - numlumps = reloadlump; - - /* Now reload the WAD file. */ - - filename = reloadname; - - w_close_file(reloadhandle); - free(reloadlumps); - - reloadname = NULL; - reloadlump = -1; - reloadhandle = NULL; - w_add_file(filename); - free(filename); - - /* The WAD directory has changed, so we have to regenerate the - * fast lookup hashtable: - */ - - w_generate_hash_table(); -} - -const char *w_wad_name_for_lump(const lumpinfo_t *lump) -{ - return m_base_name(lump->wad_file->path); -} - -boolean w_is_iwad_lump(const lumpinfo_t *lump) -{ - return lump->wad_file == lumpinfo[0]->wad_file; -} diff --git a/games/NXDoom/src/w_wad.h b/games/NXDoom/src/w_wad.h deleted file mode 100644 index 867ac5add..000000000 --- a/games/NXDoom/src/w_wad.h +++ /dev/null @@ -1,91 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/w_wad.h - * - * SPDX-License-Identifier: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * WAD I/O functions. - * - ****************************************************************************/ - -#ifndef __W_WAD__ -#define __W_WAD__ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include "doomtype.h" -#include "w_file.h" - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -/* WADFILE I/O related stuff. */ - -typedef struct lumpinfo_s lumpinfo_t; -typedef int lumpindex_t; - -struct lumpinfo_s -{ - char name[8]; - wad_file_t *wad_file; - int position; - int size; - void *cache; - - /* Used for hash table lookups */ - - lumpindex_t next; -}; - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -extern lumpinfo_t **lumpinfo; -extern unsigned int numlumps; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -wad_file_t *w_add_file(const char *filename); -void w_reload(void); - -lumpindex_t w_check_num_for_name(const char *name); -lumpindex_t w_get_num_for_name(const char *name); - -int w_lump_length(lumpindex_t lump); -void w_read_lump(lumpindex_t lump, void *dest); - -void *w_cache_lump_num(lumpindex_t lump, int tag); -void *w_cache_lump_name(const char *name, int tag); - -void w_generate_hash_table(void); - -extern unsigned int w_lump_name_hash(const char *s); - -void w_release_lump_num(lumpindex_t lump); -void w_release_lump_name(const char *name); - -const char *w_wad_name_for_lump(const lumpinfo_t *lump); -boolean w_is_iwad_lump(const lumpinfo_t *lump); - -#endif /* __W_WAD_H__ */ diff --git a/games/NXDoom/src/z_native.c b/games/NXDoom/src/z_native.c deleted file mode 100644 index 3d962bbd0..000000000 --- a/games/NXDoom/src/z_native.c +++ /dev/null @@ -1,556 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/z_native.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Zone Memory Allocation. Neat. - * - * This is an implementation of the zone memory API which - * uses native calls to malloc() and free(). - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -#include "doomtype.h" -#include "i_system.h" -#include "z_zone.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define ZONEID 0x1d4a11 - -#ifdef TESTING -#define malloc test_malloc -#define free test_free -#endif - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -typedef struct memblock_s memblock_t; - -struct memblock_s -{ - int id; /* = ZONEID */ - int tag; - int size; - void **user; - memblock_t *prev; - memblock_t *next; -}; - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/* Linked list of allocated blocks for each tag type */ - -static memblock_t *allocated_blocks[PU_NUM_TAGS]; - -#ifdef TESTING -static int test_malloced = 0; -#endif - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: z_insert_block - * - * Description: - * Add a block into the linked list for its type. - * - ****************************************************************************/ - -static void z_insert_block(memblock_t *block) -{ - block->prev = NULL; - block->next = allocated_blocks[block->tag]; - allocated_blocks[block->tag] = block; - - if (block->next != NULL) - { - block->next->prev = block; - } -} - -/**************************************************************************** - * Name: z_insert_block - * - * Description: - * Remove a block from its linked list. - * - ****************************************************************************/ - -static void z_remove_block(memblock_t *block) -{ - /* Unlink from list */ - - if (block->prev == NULL) - { - /* Start of list */ - - allocated_blocks[block->tag] = block->next; - } - else - { - if (block->prev->next != block) - { - i_error("Z_RemoveBlock: Doubly-linked list corrupted!"); - } - - block->prev->next = block->next; - } - - if (block->next != NULL) - { - if (block->next->prev != block) - { - i_error("Z_RemoveBlock: Doubly-linked list corrupted!"); - } - - block->next->prev = block->prev; - } -} - -/**************************************************************************** - * Name: clear_cache - * - * Description: - * Empty data from the cache list to allocate enough data of the size - * required. - * - * Return: - * Returns true if any blocks were freed. - * - ****************************************************************************/ - -static boolean clear_cache(int size) -{ - memblock_t *block; - memblock_t *next_block; - int remaining; - - block = allocated_blocks[PU_CACHE]; - - if (block == NULL) - { - /* Cache is already empty. */ - - return false; - } - - /* Search to the end of the PU_CACHE list. The blocks at the end - * of the list are the ones that have been free for longer and - * are more likely to be unneeded now. - */ - - while (block->next != NULL) - { - block = block->next; - } - - /* Search backwards through the list freeing blocks until we have - * freed the amount of memory required. - */ - - remaining = size; - - while (remaining > 0) - { - if (block == NULL) - { - break; /* No blocks left to free; we've done our best. */ - } - - next_block = block->prev; - - z_remove_block(block); - - remaining -= block->size; - - if (block->user) - { - *block->user = NULL; - } - - free(block); - - block = next_block; - } - - return true; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -#ifdef TESTING -void *test_malloc(size_t size) -{ - int *result; - - if (test_malloced + size > 2 * 1024 * 1024) - { - return NULL; - } - - test_malloced += size; - - result = malloc(size + sizeof(int)); - - *result = size; - - return result + 1; -} - -void test_free(void *data) -{ - int *i; - - i = ((int *)data) - 1; - - test_malloced -= *i; - - free(i); -} -#endif /* #ifdef TESTING */ - -/**************************************************************************** - * Name: z_init - ****************************************************************************/ - -void z_init(void) -{ - memset(allocated_blocks, 0, sizeof(allocated_blocks)); - printf("zone memory: Using native C allocator.\n"); -} - -/**************************************************************************** - * Name: z_free - ****************************************************************************/ - -void z_free(void *ptr) -{ - memblock_t *block; - - block = (memblock_t *)((byte *)ptr - sizeof(memblock_t)); - - if (block->id != ZONEID) - { - i_error("z_free: freed a pointer without ZONEID"); - } - - if (block->tag != PU_FREE && block->user != NULL) - { - /* clear the user's mark */ - - *block->user = NULL; - } - - z_remove_block(block); - - /* Free back to system */ - - free(block); -} - -/**************************************************************************** - * Name: z_malloc - * - * Description: - * You can pass a NULL user if the tag is < PU_PURGELEVEL. - * - * Return: - * The translated key code. - * - ****************************************************************************/ - -void *z_malloc(int size, int tag, void *user) -{ - memblock_t *newblock; - unsigned char *data; - void *result; - - if (tag < 0 || tag >= PU_NUM_TAGS || tag == PU_FREE) - { - i_error("z_malloc: attempted to allocate a block with an invalid " - "tag: %i", - tag); - } - - if (user == NULL && tag >= PU_PURGELEVEL) - { - i_error("z_malloc: an owner is required for purgeable blocks"); - } - - /* Malloc a block of the required size */ - - newblock = NULL; - - while (newblock == NULL) - { - newblock = (memblock_t *)malloc(sizeof(memblock_t) + size); - - if (newblock == NULL) - { - if (!clear_cache(sizeof(memblock_t) + size)) - { - i_error("z_malloc: failed on allocation of %i bytes", size); - } - } - } - - newblock->tag = tag; - - /* Hook into the linked list for this tag type */ - - newblock->id = ZONEID; - newblock->user = user; - newblock->size = size; - - z_insert_block(newblock); - - data = (unsigned char *)newblock; - result = data + sizeof(memblock_t); - - if (user != NULL) - { - *newblock->user = result; - } - - return result; -} - -/**************************************************************************** - * Name: z_free_tags - ****************************************************************************/ - -void z_free_tags(int lowtag, int hightag) -{ - int i; - - for (i = lowtag; i <= hightag; ++i) - { - memblock_t *block; - memblock_t *next; - - /* Free all in this chain */ - - for (block = allocated_blocks[i]; block != NULL; ) - { - next = block->next; - - /* Free this block */ - - if (block->user != NULL) - { - *block->user = NULL; - } - - free(block); - - /* Jump to the next in the chain */ - - block = next; - } - - /* This chain is empty now */ - - allocated_blocks[i] = NULL; - } -} - -/**************************************************************************** - * Name: z_dump_heap - ****************************************************************************/ - -void z_dump_heap(int lowtag, int hightag) -{ - /* WARN: broken */ - -#if 0 - memblock_t *block; - - printf("zone size: %i location: %p\n", mainzone->size, mainzone); - - printf("tag range: %i to %i\n", lowtag, hightag); - - for (block = mainzone->blocklist.next; ; block = block->next) - { - if (block->tag >= lowtag && block->tag <= hightag) - printf("block:%p size:%7i user:%p tag:%3i\n", block, - block->size, block->user, block->tag); - - if (block->next == &mainzone->blocklist) - { - /* all blocks have been hit */ - - break; - } - - if ((byte *)block + block->size != (byte *)block->next) - printf("ERROR: block size does not touch the next block\n"); - - if (block->next->prev != block) - printf("ERROR: next block doesn't have proper back link\n"); - - if (block->tag == PU_FREE && block->next->tag == PU_FREE) - printf("ERROR: two consecutive free blocks\n"); - } -#endif -} - -/**************************************************************************** - * Name: z_file_dump_heap - ****************************************************************************/ - -void z_file_dump_heap(FILE *f) -{ - /* WARN: broken */ -#if 0 - memblock_t *block; - - fprintf(f, "zone size: %i location: %p\n", mainzone->size, mainzone); - - for (block = mainzone->blocklist.next; ; block = block->next) - { - fprintf(f, "block:%p size:%7i user:%p tag:%3i\n", block, - block->size, block->user, block->tag); - - if (block->next == &mainzone->blocklist) - { - /* all blocks have been hit */ - - break; - } - - if ((byte *)block + block->size != (byte *)block->next) - fprintf(f, "ERROR: block size does not touch the next block\n"); - - if (block->next->prev != block) - fprintf(f, "ERROR: next block doesn't have proper back link\n"); - - if (block->tag == PU_FREE && block->next->tag == PU_FREE) - fprintf(f, "ERROR: two consecutive free blocks\n"); - } -#endif -} - -/**************************************************************************** - * Name: z_check_heap - ****************************************************************************/ - -void z_check_heap(void) -{ - memblock_t *block; - memblock_t *prev; - int i; - - /* Check all chains */ - - for (i = 0; i < PU_NUM_TAGS; ++i) - { - prev = NULL; - - for (block = allocated_blocks[i]; block != NULL; block = block->next) - { - if (block->id != ZONEID) - { - i_error("z_check_heap: Block without a ZONEID!"); - } - - if (block->prev != prev) - { - i_error("z_check_heap: Doubly-linked list corrupted!"); - } - - prev = block; - } - } -} - -/**************************************************************************** - * Name: z_change_tag2 - ****************************************************************************/ - -void z_change_tag2(void *ptr, int tag, const char *file, int line) -{ - memblock_t *block; - - block = (memblock_t *)((byte *)ptr - sizeof(memblock_t)); - - if (block->id != ZONEID) - i_error("%s:%i: z_change_tag: block without a ZONEID!", file, line); - - if (tag >= PU_PURGELEVEL && block->user == NULL) - i_error("%s:%i: z_change_tag: an owner is required " - "for purgeable blocks", - file, line); - - /* Remove the block from its current list, and rehook it into - * its new list. - */ - - z_remove_block(block); - block->tag = tag; - z_insert_block(block); -} - -void z_change_user(void *ptr, void **user) -{ - memblock_t *block; - - block = (memblock_t *)((byte *)ptr - sizeof(memblock_t)); - - if (block->id != ZONEID) - { - i_error("z_change_user: Tried to change user for invalid block!"); - } - - block->user = user; - *user = ptr; -} - -/**************************************************************************** - * Name: z_free_memory - ****************************************************************************/ - -int z_free_memory(void) -{ - return -1; /* Limited by the system?? */ -} - -/**************************************************************************** - * Name: z_zone_size - ****************************************************************************/ - -unsigned int z_zone_size(void) -{ - return 0; -} diff --git a/games/NXDoom/src/z_zone.c b/games/NXDoom/src/z_zone.c deleted file mode 100644 index f5274e334..000000000 --- a/games/NXDoom/src/z_zone.c +++ /dev/null @@ -1,557 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/z_zone.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Zone Memory Allocation. Neat. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include "doomtype.h" -#include "i_system.h" -#include "m_argv.h" - -#include "z_zone.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* ZONE MEMORY ALLOCATION - * - * There is never any space between memblocks, - * and there will never be two contiguous free memblocks. - * The rover can be left pointing at a non-empty block. - * - * It is of no value to free a cacheable block, - * because it will get overwritten automatically if needed. - */ - -#define MEM_ALIGN sizeof(void *) -#define ZONEID 0x1d4a11 - -#define MINFRAGMENT 64 - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -typedef struct memblock_s -{ - int size; /* including the header and possibly tiny fragments */ - void **user; - int tag; /* PU_FREE if this is free */ - int id; /* should be ZONEID */ - struct memblock_s *next; - struct memblock_s *prev; -} memblock_t; - -typedef struct -{ - /* total bytes malloced, including header */ - - int size; - - /* start / end cap for linked list */ - - memblock_t blocklist; - - memblock_t *rover; -} memzone_t; - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static memzone_t *mainzone; -static boolean zero_on_free; -static boolean scan_on_free; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: scan_for_block - * - * Description: - * Scan the zone heap for pointers within the specified range, and warn - * about any remaining pointers. - * - ****************************************************************************/ - -static void scan_for_block(void *start, void *end) -{ - memblock_t *block; - void **mem; - int i; - int len; - int tag; - - block = mainzone->blocklist.next; - - while (block->next != &mainzone->blocklist) - { - tag = block->tag; - - if (tag == PU_STATIC || tag == PU_LEVEL || tag == PU_LEVSPEC) - { - /* Scan for pointers on the assumption that pointers are aligned - * on word boundaries (word size depending on pointer size): - */ - - mem = (void **)((byte *)block + sizeof(memblock_t)); - len = (block->size - sizeof(memblock_t)) / sizeof(void *); - - for (i = 0; i < len; ++i) - { - if (start <= mem[i] && mem[i] <= end) - { - fprintf(stderr, - "%p has dangling pointer into freed block " - "%p (%p -> %p)\n", - mem, start, &mem[i], mem[i]); - } - } - } - - block = block->next; - } -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: z_init - ****************************************************************************/ - -void z_init(void) -{ - memblock_t *block; - int size; - - mainzone = (memzone_t *)i_zone_base(&size); - mainzone->size = size; - - /* set the entire zone to one free block */ - - mainzone->blocklist.next = mainzone->blocklist.prev = block = - (memblock_t *)((byte *)mainzone + sizeof(memzone_t)); - - mainzone->blocklist.user = (void *)mainzone; - mainzone->blocklist.tag = PU_STATIC; - mainzone->rover = block; - - block->prev = block->next = &mainzone->blocklist; - - block->tag = PU_FREE; /* free block */ - - block->size = mainzone->size - sizeof(memzone_t); - - /* [Deliberately undocumented] - * Zone memory debugging flag. If set, memory is zeroed after it is freed - * to deliberately break any code that attempts to use it after free. - */ - - zero_on_free = m_parm_exists("-zonezero"); - - /* [Deliberately undocumented] - * Zone memory debugging flag. If set, each time memory is freed, the zone - * heap is scanned to look for remaining pointers to the freed block. - */ - - scan_on_free = m_parm_exists("-zonescan"); -} - -/**************************************************************************** - * Name: z_free - ****************************************************************************/ - -void z_free(void *ptr) -{ - memblock_t *block; - memblock_t *other; - - block = (memblock_t *)((byte *)ptr - sizeof(memblock_t)); - - if (block->id != ZONEID) i_error("z_free: freed a pointer without ZONEID"); - - if (block->tag != PU_FREE && block->user != NULL) - { - *block->user = 0; /* clear the user's mark */ - } - - /* mark as free */ - - block->tag = PU_FREE; - block->user = NULL; - block->id = 0; - - /* If the -zonezero flag is provided, we zero out the block on free - * to break code that depends on reading freed memory. - */ - - if (zero_on_free) - { - memset(ptr, 0, block->size - sizeof(memblock_t)); - } - - if (scan_on_free) - { - scan_for_block(ptr, (byte *)ptr + block->size - sizeof(memblock_t)); - } - - other = block->prev; - - if (other->tag == PU_FREE) - { - /* merge with previous free block */ - - other->size += block->size; - other->next = block->next; - other->next->prev = other; - - if (block == mainzone->rover) mainzone->rover = other; - - block = other; - } - - other = block->next; - if (other->tag == PU_FREE) - { - /* merge with previous free block */ - - block->size += other->size; - block->next = other->next; - block->next->prev = block; - - if (other == mainzone->rover) mainzone->rover = block; - } -} - -/**************************************************************************** - * Name: z_malloc - * - * Description: - * You can pass a NULL user if the tag is < PU_PURGELEVEL. - * - ****************************************************************************/ - -void *z_malloc(int size, int tag, void *user) -{ - int extra; - memblock_t *start; - memblock_t *rover; - memblock_t *newblock; - memblock_t *base; - void *result; - - size = (size + MEM_ALIGN - 1) & ~(MEM_ALIGN - 1); - - /* scan through the block list, looking for the first free block of - * sufficient size, throwing out any purgeable blocks along the way. - */ - - /* account for size of block header */ - - size += sizeof(memblock_t); - - /* if there is a free block behind the rover, back up over them */ - - base = mainzone->rover; - - if (base->prev->tag == PU_FREE) base = base->prev; - - rover = base; - start = base->prev; - - do - { - if (rover == start) - { - /* scanned all the way around the list */ - - i_error("z_malloc: failed on allocation of %i bytes", size); - } - - if (rover->tag != PU_FREE) - { - if (rover->tag < PU_PURGELEVEL) - { - /* hit a block that can't be purged, so move base past it */ - - base = rover = rover->next; - } - else - { - /* free the rover block (adding the size to base) the rover can - * be the base block - */ - - base = base->prev; - z_free((byte *)rover + sizeof(memblock_t)); - base = base->next; - rover = base->next; - } - } - else - { - rover = rover->next; - } - } - while (base->tag != PU_FREE || base->size < size); - - /* found a block big enough */ - - extra = base->size - size; - - if (extra > MINFRAGMENT) - { - /* there will be a free fragment after the allocated block */ - - newblock = (memblock_t *)((byte *)base + size); - newblock->size = extra; - - newblock->tag = PU_FREE; - newblock->user = NULL; - newblock->prev = base; - newblock->next = base->next; - newblock->next->prev = newblock; - - base->next = newblock; - base->size = size; - } - - if (user == NULL && tag >= PU_PURGELEVEL) - i_error("z_malloc: an owner is required for purgeable blocks"); - - base->user = user; - base->tag = tag; - - result = (void *)((byte *)base + sizeof(memblock_t)); - - if (base->user) - { - *base->user = result; - } - - /* next allocation will start looking here */ - - mainzone->rover = base->next; - - base->id = ZONEID; - - return result; -} - -/**************************************************************************** - * Name: z_free_tags - ****************************************************************************/ - -void z_free_tags(int lowtag, int hightag) -{ - memblock_t *block; - memblock_t *next; - - for (block = mainzone->blocklist.next; block != &mainzone->blocklist; - block = next) - { - /* get link before freeing */ - - next = block->next; - - /* free block? */ - - if (block->tag == PU_FREE) continue; - - if (block->tag >= lowtag && block->tag <= hightag) - z_free((byte *)block + sizeof(memblock_t)); - } -} - -/**************************************************************************** - * Name: z_dump_heap - * - * Description: - * Note: TFileDumpHeap( stdout ) ? - * - ****************************************************************************/ - -void z_dump_heap(int lowtag, int hightag) -{ - memblock_t *block; - - printf("zone size: %i location: %p\n", mainzone->size, mainzone); - - printf("tag range: %i to %i\n", lowtag, hightag); - - for (block = mainzone->blocklist.next; ; block = block->next) - { - if (block->tag >= lowtag && block->tag <= hightag) - printf("block:%p size:%7i user:%p tag:%3i\n", block, - block->size, block->user, block->tag); - - if (block->next == &mainzone->blocklist) - { - break; /* all blocks have been hit */ - } - - if ((byte *)block + block->size != (byte *)block->next) - printf("ERROR: block size does not touch the next block\n"); - - if (block->next->prev != block) - printf("ERROR: next block doesn't have proper back link\n"); - - if (block->tag == PU_FREE && block->next->tag == PU_FREE) - printf("ERROR: two consecutive free blocks\n"); - } -} - -/**************************************************************************** - * Name: z_file_dump_heap - ****************************************************************************/ - -void z_file_dump_heap(FILE *f) -{ - memblock_t *block; - - fprintf(f, "zone size: %i location: %p\n", mainzone->size, mainzone); - - for (block = mainzone->blocklist.next; ; block = block->next) - { - fprintf(f, "block:%p size:%7i user:%p tag:%3i\n", block, - block->size, block->user, block->tag); - - if (block->next == &mainzone->blocklist) - { - break; /* all blocks have been hit */ - } - - if ((byte *)block + block->size != (byte *)block->next) - fprintf(f, "ERROR: block size does not touch the next block\n"); - - if (block->next->prev != block) - fprintf(f, "ERROR: next block doesn't have proper back link\n"); - - if (block->tag == PU_FREE && block->next->tag == PU_FREE) - fprintf(f, "ERROR: two consecutive free blocks\n"); - } -} - -/**************************************************************************** - * Name: z_check_heap - ****************************************************************************/ - -void z_check_heap(void) -{ - memblock_t *block; - - for (block = mainzone->blocklist.next; ; block = block->next) - { - if (block->next == &mainzone->blocklist) - { - break; /* all blocks have been hit */ - } - - if ((byte *)block + block->size != (byte *)block->next) - i_error("z_check_heap: block size does not touch the next block\n"); - - if (block->next->prev != block) - i_error("z_check_heap: next block doesn't have proper back link\n"); - - if (block->tag == PU_FREE && block->next->tag == PU_FREE) - i_error("z_check_heap: two consecutive free blocks\n"); - } -} - -/**************************************************************************** - * Name: z_change_tag2 - ****************************************************************************/ - -void z_change_tag2(void *ptr, int tag, const char *file, int line) -{ - memblock_t *block; - - block = (memblock_t *)((byte *)ptr - sizeof(memblock_t)); - - if (block->id != ZONEID) - i_error("%s:%i: z_change_tag: block without a ZONEID!", file, line); - - if (tag >= PU_PURGELEVEL && block->user == NULL) - i_error("%s:%i: z_change_tag: an owner is required " - "for purgeable blocks", - file, line); - - block->tag = tag; -} - -/**************************************************************************** - * Name: z_change_user - ****************************************************************************/ - -void z_change_user(void *ptr, void **user) -{ - memblock_t *block; - - block = (memblock_t *)((byte *)ptr - sizeof(memblock_t)); - - if (block->id != ZONEID) - { - i_error("z_change_user: Tried to change user for invalid block!"); - } - - block->user = user; - *user = ptr; -} - -/**************************************************************************** - * Name: z_free_memory - ****************************************************************************/ - -int z_free_memory(void) -{ - memblock_t *block; - int free; - - free = 0; - - for (block = mainzone->blocklist.next; block != &mainzone->blocklist; - block = block->next) - { - if (block->tag == PU_FREE || block->tag >= PU_PURGELEVEL) - free += block->size; - } - - return free; -} - -/**************************************************************************** - * Name: z_zone_size - ****************************************************************************/ - -unsigned int z_zone_size(void) -{ - return mainzone->size; -} diff --git a/games/NXDoom/src/z_zone.h b/games/NXDoom/src/z_zone.h deleted file mode 100644 index 4df6bb3fb..000000000 --- a/games/NXDoom/src/z_zone.h +++ /dev/null @@ -1,89 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/src/z_zone.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 1993-1996 Id Software, Inc. - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * DESCRIPTION: - * Zone Memory Allocation, perhaps NeXT ObjectiveC inspired. - * - * Remark: this was the only stuff that, according to John Carmack, might - * have been useful for Quake. - * - ****************************************************************************/ - -#ifndef __Z_ZONE__ -#define __Z_ZONE__ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* This is used to get the local FILE:LINE info from CPP prior to really call - * the function in question. - */ - -#define z_change_tag(p, t) z_change_tag2((p), (t), __FILE__, __LINE__) - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -/* ZONE MEMORY - * PU - purge tags. - */ - -enum -{ - PU_STATIC = 1, /* static entire execution time */ - PU_SOUND, /* static while playing */ - PU_MUSIC, /* static while playing */ - PU_FREE, /* a free block */ - PU_LEVEL, /* static until level exited */ - PU_LEVSPEC, /* a special thinker in a level */ - - /* Tags >= PU_PURGELEVEL are purgeable whenever needed. */ - - PU_PURGELEVEL, - PU_CACHE, - - /* Total number of different tag types */ - - PU_NUM_TAGS -}; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -void z_init(void); -void *z_malloc(int size, int tag, void *ptr); -void z_free(void *ptr); -void z_free_tags(int lowtag, int hightag); -void z_dump_heap(int lowtag, int hightag); -void z_file_dump_heap(FILE *f); -void z_check_heap(void); -void z_change_tag2(void *ptr, int tag, const char *file, int line); -void z_change_user(void *ptr, void **user); -int z_free_memory(void); -unsigned int z_zone_size(void); - -#endif /* __Z_ZONE__ */ diff --git a/games/NXDoom/textscreen/.gitignore b/games/NXDoom/textscreen/.gitignore deleted file mode 100644 index 3be8ec0c7..000000000 --- a/games/NXDoom/textscreen/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -Makefile -Makefile.in -.deps -*.a -tags -TAGS diff --git a/games/NXDoom/textscreen/fonts/README b/games/NXDoom/textscreen/fonts/README deleted file mode 100644 index a9b9b1b24..000000000 --- a/games/NXDoom/textscreen/fonts/README +++ /dev/null @@ -1,38 +0,0 @@ - -This directory contains the fonts used by libtextscreen: - - * normal.png is the standard DOS font, from the DOSbox project. - Copyright (C) 2002-2004 The DOSBox Team - - * small.png contains a miniature, half-size font for low-resolution - displays. This is based on the Atari-Small font by Tom Fine. The - original font was standard ASCII only; this has been extended to the - full Extended ASCII range with scaled-down versions of the full-size - DOS font. Original copyright notice: - - Copyright (c) 1999, Thomas A. Fine - - License to copy, modify, and distribute for both commercial and - non-commercial use is herby granted, provided this notice - is preserved. - - Email to my last name at head.cfa.harvard.edu - http://hea-www.harvard.edu/~fine/ - - * large.png is a scaled-up version of normal.png with extra detail - added; this is for use on modern high-resolution ("retina") displays. - -All modifications and enhancements to the above fonts are: - - Copyright (C) 2005-2016 Simon Howard - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - diff --git a/games/NXDoom/textscreen/fonts/codepage.h b/games/NXDoom/textscreen/fonts/codepage.h deleted file mode 100644 index f506c90e4..000000000 --- a/games/NXDoom/textscreen/fonts/codepage.h +++ /dev/null @@ -1,105 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/textscreen/fonts/codepage.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2017 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * This file contains a #define macro mapping from the characters - * in the CP437 code page to the equivalent Unicode characters. It - * therefore defines which Unicode characters can be represented on - * a text screen using such a code page. - * - * If you're changing the textscreen font to show a different code - * page, you should update the mapping in this file to match. The - * Wikipedia pages for DOS code pages are a good place to look for - * this information. - * - ****************************************************************************/ - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define CODE_PAGE_TO_UNICODE \ - { \ - /* CP437 control codes: */ \ - \ - 0x0000, 0x263a, 0x263b, 0x2665, /* 00 - 0f */ \ - 0x2666, 0x2663, 0x2660, 0x2022, 0x25d8, 0x25cb, 0x25d9, \ - 0x2642, 0x2640, 0x266a, 0x266b, 0x263c, \ - \ - 0x25ba, 0x25c4, 0x2195, 0x203c, /* 10 - 1f */ \ - 0x00b6, 0x00a7, 0x25ac, 0x21a8, 0x2191, 0x2193, 0x2192, \ - 0x2190, 0x221f, 0x2194, 0x25b2, 0x25bc, \ - \ - /* Standard ASCII range: */ \ - \ - 0x0020, 0x0021, 0x0022, 0x0023, /* 20 - 2f */ \ - 0x0024, 0x0025, 0x0026, 0x0027, 0x0028, 0x0029, 0x002a, \ - 0x002b, 0x002c, 0x002d, 0x002e, 0x002f, \ - \ - 0x0030, 0x0031, 0x0032, 0x0033, /* 30 - 3f */ \ - 0x0034, 0x0035, 0x0036, 0x0037, 0x0038, 0x0039, 0x003a, \ - 0x003b, 0x003c, 0x003d, 0x003e, 0x003f, \ - \ - 0x0040, 0x0041, 0x0042, 0x0043, /* 40 - 4f */ \ - 0x0044, 0x0045, 0x0046, 0x0047, 0x0048, 0x0049, 0x004a, \ - 0x004b, 0x004c, 0x004d, 0x004e, 0x004f, \ - \ - 0x0050, 0x0051, 0x0052, 0x0053, /* 50 - 5f */ \ - 0x0054, 0x0055, 0x0056, 0x0057, 0x0058, 0x0059, 0x005a, \ - 0x005b, 0x005c, 0x005d, 0x005e, 0x005f, \ - \ - 0x0060, 0x0061, 0x0062, 0x0063, /* 60 - 6f */ \ - 0x0064, 0x0065, 0x0066, 0x0067, 0x0068, 0x0069, 0x006a, \ - 0x006b, 0x006c, 0x006d, 0x006e, 0x006f, \ - \ - 0x0070, 0x0071, 0x0072, 0x0073, /* 70 - 7f */ \ - 0x0074, 0x0075, 0x0076, 0x0077, 0x0078, 0x0079, 0x007a, \ - 0x007b, 0x007c, 0x007d, 0x007e, 0x2302, \ - \ - /* CP437 Extended ASCII range: */ \ - \ - 0x00c7, 0x00fc, 0x00e9, 0x00e2, /* 80-8f */ \ - 0x00e4, 0x00e0, 0x00e5, 0x00e7, 0x00ea, 0x00eb, 0x00e8, \ - 0x00ef, 0x00ee, 0x00ec, 0x00c4, 0x00c5, \ - \ - 0x00c9, 0x00e6, 0x00c6, 0x00f4, /* 90-9f */ \ - 0x00f6, 0x00f2, 0x00fb, 0x00f9, 0x00ff, 0x00d6, 0x00dc, \ - 0x00a2, 0x00a3, 0x00a5, 0x20a7, 0x0192, \ - \ - 0x00e1, 0x00ed, 0x00f3, 0x00fa, /* a0-af */ \ - 0x00f1, 0x00d1, 0x00aa, 0x00ba, 0x00bf, 0x2310, 0x00ac, \ - 0x00bd, 0x00bc, 0x00a1, 0x00ab, 0x00bb, \ - \ - 0x2591, 0x2592, 0x2593, 0x2502, /* b0-bf */ \ - 0x2524, 0x2561, 0x2562, 0x2556, 0x2555, 0x2563, 0x2551, \ - 0x2557, 0x255d, 0x255c, 0x255b, 0x2510, \ - \ - 0x2514, 0x2534, 0x252c, 0x251c, /* c0-cf */ \ - 0x2500, 0x253c, 0x255e, 0x255f, 0x255a, 0x2554, 0x2569, \ - 0x2566, 0x2560, 0x2550, 0x256c, 0x2567, \ - \ - 0x2568, 0x2564, 0x2565, 0x2559, /* d0-df */ \ - 0x2558, 0x2552, 0x2553, 0x256b, 0x256a, 0x2518, 0x250c, \ - 0x2588, 0x2584, 0x258c, 0x2590, 0x2580, \ - \ - 0x03b1, 0x00df, 0x0393, 0x03c0, /* e0-ef */ \ - 0x03a3, 0x03c3, 0x00b5, 0x03c4, 0x03a6, 0x0398, 0x03a9, \ - 0x03b4, 0x221e, 0x03c6, 0x03b5, 0x2229, \ - \ - 0x2261, 0x00b1, 0x2265, 0x2264, /* f0-ff */ \ - 0x2320, 0x2321, 0x00f7, 0x2248, 0x00b0, 0x2219, 0x00b7, \ - 0x221a, 0x207f, 0x00b2, 0x25a0, 0x00a0, \ - } diff --git a/games/NXDoom/textscreen/fonts/convert-font b/games/NXDoom/textscreen/fonts/convert-font deleted file mode 100644 index b3d828cc5..000000000 --- a/games/NXDoom/textscreen/fonts/convert-font +++ /dev/null @@ -1,104 +0,0 @@ -#!/usr/bin/env python3 -# -# Copyright(C) 2016 Simon Howard -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# -# Converts images into libtextscreen fonts. -# - -import sys -import os -import re - -GRID_COLUMNS = 16 -GRID_ROWS = 16 - -try: - import Image -except ImportError: - try: - from PIL import Image - except ImportError: - print("WARNING: Could not update %s. " - "Please install the Python Imaging library or Pillow." - % sys.argv[3]) - sys.exit(0) - - -def generate_font_data(filename): - """Read font data from the given file. - - Args: - filename: Image file to read. - Returns: - Tuple containing: - (width, height) dimensions of each font character. - Array of byte data for font. - """ - im = Image.open(filename) - width, height = im.size - assert (width % GRID_COLUMNS) == 0 - assert (height % GRID_ROWS) == 0 - - char_w, char_h = width // GRID_COLUMNS, height // GRID_ROWS - font_data_len = (width * height) // 8 - font_data = [0] * font_data_len - - for y in range(height): - for x in range(width): - px = im.getpixel((x, y)) - if px > (127, 127, 127): - char_x, char_y = x // char_w, y // char_h - x1, y1 = x % char_w, y % char_h - bit_index = ( - (char_y * GRID_COLUMNS + char_x) * (char_w * char_h) + - (y1 * char_w) + x1) - font_data[bit_index // 8] |= 1 << (bit_index % 8) - - return (char_w, char_h), font_data - -def convert_image(font_prefix, filename, output_filename): - """Convert the given image to a text output file. - - Args: - font_prefix: Prefix string to attach to constants. - filename: Input image file to read. - output_filename: Header file to write. - """ - dimensions, data = generate_font_data(filename) - - with open(output_filename, "w") as outfile: - outfile.write("/* Font data generated from %s; do not edit.\n" - " Please see textscreen/fonts/README for copyright\n" - " information. */\n\n" % filename) - outfile.write("static const uint8_t %s_font_data[] =\n{\n" % - font_prefix) - for index, b in enumerate(data): - if (index % 8) == 0: - outfile.write(" ") - outfile.write("0x%02x," % b) - if ((index + 1) % 8) == 0: - outfile.write("\n") - else: - outfile.write(" ") - outfile.write("};\n") - - outfile.write("\n") - outfile.write("static const txt_font_t %s_font =\n{\n" % font_prefix) - outfile.write(" \"%s\", %s_font_data, %d, %d,\n" % ( - font_prefix, font_prefix, - dimensions[0], dimensions[1])) - outfile.write("};\n") - -convert_image(sys.argv[1], sys.argv[2], sys.argv[3]) - diff --git a/games/NXDoom/textscreen/fonts/large.h b/games/NXDoom/textscreen/fonts/large.h deleted file mode 100644 index a58692d91..000000000 --- a/games/NXDoom/textscreen/fonts/large.h +++ /dev/null @@ -1,1391 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/textscreen/fonts/large.h - * - * SPDX-License-Identifer: GPLv2 - * - * Font data generated from large.png; do not edit. Please see - * textscreen/fonts/README for copyright information. - * - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -static const uint8_t large_font_data[] = -{ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xfc, 0x3f, 0xfe, 0x7f, 0x07, 0xe0, 0x03, 0xc0, 0x33, 0xcc, 0x33, 0xcc, - 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0xf3, 0xcf, 0xf3, 0xcf, - 0xe3, 0xc7, 0xc3, 0xc3, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x07, 0xe0, - 0xfe, 0x7f, 0xfc, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xfc, 0x3f, 0xfe, 0x7f, 0xff, 0xff, 0xff, 0xff, - 0xcf, 0xf3, 0xcf, 0xf3, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0x0f, 0xf0, 0x0f, 0xf0, 0x1f, 0xf8, 0x3f, 0xfc, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xfe, 0x7f, 0xfc, 0x3f, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x1c, 0x0e, 0x3e, 0x1f, 0xff, 0x3f, 0xff, 0x3f, - 0xff, 0x3f, 0xff, 0x3f, 0xff, 0x3f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfc, 0x0f, - 0xfc, 0x0f, 0xf8, 0x07, 0xf0, 0x03, 0xe0, 0x01, 0xc0, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0xe0, 0x01, - 0xf0, 0x03, 0xf8, 0x07, 0xfc, 0x0f, 0xfe, 0x1f, 0xff, 0x3f, 0xff, 0x3f, - 0xfe, 0x1f, 0xfc, 0x0f, 0xf8, 0x07, 0xf0, 0x03, 0xe0, 0x01, 0xc0, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x03, 0xe0, 0x07, - 0xf0, 0x0f, 0xf0, 0x0f, 0xf0, 0x0f, 0xf0, 0x0f, 0x3e, 0x7c, 0x3f, 0xfc, - 0x3f, 0xfc, 0x3f, 0xfc, 0x3f, 0xfc, 0x3e, 0x7c, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xe0, 0x07, 0xf0, 0x0f, 0xf0, 0x0f, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xc0, 0x03, 0xe0, 0x07, 0xf0, 0x0f, 0xf8, 0x1f, 0xfc, 0x3f, 0xfe, 0x7f, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x7f, 0xdc, 0x3b, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xe0, 0x07, 0xf0, 0x0f, 0xf0, 0x0f, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xc0, 0x03, 0xe0, 0x07, 0xf0, 0x0f, 0xf0, 0x0f, - 0xf0, 0x0f, 0xf0, 0x0f, 0xe0, 0x07, 0xc0, 0x03, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xfc, 0x1f, 0xf8, - 0x0f, 0xf0, 0x0f, 0xf0, 0x0f, 0xf0, 0x0f, 0xf0, 0x1f, 0xf8, 0x3f, 0xfc, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x0f, 0xf8, 0x1f, - 0x3c, 0x3c, 0x1c, 0x38, 0x0c, 0x30, 0x0c, 0x30, 0x0c, 0x30, 0x0c, 0x30, - 0x1c, 0x38, 0x3c, 0x3c, 0xf8, 0x1f, 0xf0, 0x0f, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0x0f, 0xf0, 0x07, 0xe0, 0xc3, 0xc3, 0xe3, 0xc7, 0xf3, 0xcf, 0xf3, 0xcf, - 0xf3, 0xcf, 0xf3, 0xcf, 0xe3, 0xc7, 0xc3, 0xc3, 0x07, 0xe0, 0x0f, 0xf0, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xc0, 0x3f, 0xc0, 0x3f, 0x00, 0x3f, 0x00, 0x3f, - 0x80, 0x37, 0xc0, 0x33, 0xe0, 0x31, 0xf0, 0x30, 0xfc, 0x03, 0xfe, 0x07, - 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, - 0x0f, 0x0f, 0x0f, 0x0f, 0xfe, 0x07, 0xfc, 0x03, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x0f, 0xf8, 0x1f, - 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, - 0x3c, 0x3c, 0x3c, 0x3c, 0xf8, 0x1f, 0xf0, 0x0f, 0xc0, 0x03, 0xc0, 0x03, - 0xfc, 0x3f, 0xfc, 0x3f, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xf0, 0xff, 0xf0, 0xff, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xff, 0xf0, 0xff, - 0xf0, 0x00, 0xf0, 0x00, 0xf0, 0x00, 0xf0, 0x00, 0xf0, 0x00, 0xf0, 0x00, - 0xf0, 0x00, 0xf0, 0x00, 0xfc, 0x00, 0xfe, 0x00, 0xff, 0x00, 0xff, 0x00, - 0x7f, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff, 0xfc, 0xff, 0x3c, 0xf0, 0x3c, 0xf0, - 0xfc, 0xff, 0xfc, 0xff, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, - 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf8, 0x3c, 0xfc, - 0x3e, 0xfc, 0x3f, 0xfc, 0x3f, 0x7c, 0x3f, 0x38, 0x1f, 0x00, 0x0e, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc3, 0xc3, 0xcf, 0xf3, - 0xfc, 0x3f, 0xf0, 0x0f, 0x3f, 0xfc, 0x3f, 0xfc, 0xf0, 0x0f, 0xfc, 0x3f, - 0xcf, 0xf3, 0xc3, 0xc3, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x03, 0x00, - 0x07, 0x00, 0x0f, 0x00, 0x1f, 0x00, 0x3f, 0x00, 0x7f, 0x00, 0xff, 0x00, - 0xff, 0x01, 0xff, 0x03, 0xff, 0x07, 0xff, 0x07, 0xff, 0x03, 0xff, 0x01, - 0xff, 0x00, 0x7f, 0x00, 0x3f, 0x00, 0x1f, 0x00, 0x0f, 0x00, 0x07, 0x00, - 0x03, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x20, 0x00, 0x30, 0x00, 0x38, 0x00, 0x3c, 0x00, 0x3e, 0x00, 0x3f, - 0x80, 0x3f, 0xc0, 0x3f, 0xe0, 0x3f, 0xf0, 0x3f, 0xf8, 0x3f, 0xf8, 0x3f, - 0xf0, 0x3f, 0xe0, 0x3f, 0xc0, 0x3f, 0x80, 0x3f, 0x00, 0x3f, 0x00, 0x3e, - 0x00, 0x3c, 0x00, 0x38, 0x00, 0x30, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0xc0, 0x03, - 0xe0, 0x07, 0xf0, 0x0f, 0xf8, 0x1f, 0xfc, 0x3f, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xfc, 0x3f, 0xf8, 0x1f, - 0xf0, 0x0f, 0xe0, 0x07, 0xc0, 0x03, 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, - 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, - 0x3c, 0x3c, 0x3c, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x3c, 0x3c, - 0x3c, 0x3c, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff, 0xfe, 0xff, 0xc7, 0xf3, 0xc7, 0xf3, - 0xc7, 0xf3, 0xc7, 0xf3, 0xc7, 0xf3, 0xc7, 0xf3, 0xfe, 0xf3, 0xfc, 0xf3, - 0xc0, 0xf3, 0xc0, 0xf3, 0xc0, 0xf3, 0xc0, 0xf3, 0xc0, 0xf3, 0xc0, 0xf3, - 0xc0, 0xf3, 0xc0, 0xf3, 0xc0, 0xf3, 0xc0, 0xf3, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xfc, 0x0f, 0xfe, 0x1f, 0x0f, 0x3c, 0x0f, 0x38, - 0x3e, 0x00, 0xfc, 0x00, 0xf8, 0x03, 0xf0, 0x07, 0x38, 0x0f, 0x1c, 0x1e, - 0x0e, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x1c, 0x1e, 0x0e, 0x3c, 0x07, - 0xf8, 0x03, 0xf0, 0x03, 0xc0, 0x0f, 0x00, 0x1f, 0x07, 0x3e, 0x0f, 0x3c, - 0xfe, 0x1f, 0xfc, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xff, 0x3f, 0xff, 0x3f, 0xff, 0x3f, 0xff, 0x3f, 0xff, 0x3f, 0xff, 0x3f, - 0xff, 0x3f, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0xc0, 0x03, 0xe0, 0x07, 0xf0, 0x0f, - 0xf8, 0x1f, 0xfc, 0x3f, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xfc, 0x3f, 0xf8, 0x1f, 0xf0, 0x0f, 0xe0, 0x07, - 0xc0, 0x03, 0x80, 0x01, 0xfc, 0x3f, 0xfc, 0x3f, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0xc0, 0x03, - 0xe0, 0x07, 0xf0, 0x0f, 0xf8, 0x1f, 0xfc, 0x3f, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xfc, 0x3f, 0xf8, 0x1f, 0xf0, 0x0f, 0xe0, 0x07, - 0xc0, 0x03, 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xc0, 0x01, 0x80, 0x03, 0x00, 0x07, 0x00, 0x0e, - 0xff, 0x1f, 0xff, 0x1f, 0x00, 0x0e, 0x00, 0x07, 0x80, 0x03, 0xc0, 0x01, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x70, 0x00, - 0x38, 0x00, 0x1c, 0x00, 0xfe, 0x3f, 0xfe, 0x3f, 0x1c, 0x00, 0x38, 0x00, - 0x70, 0x00, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, - 0x0f, 0x00, 0x0f, 0x00, 0xff, 0x3f, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x20, 0x04, 0x30, 0x0c, 0x38, 0x1c, 0x3c, 0x3c, - 0xfe, 0x7f, 0xfe, 0x7f, 0x3c, 0x3c, 0x38, 0x1c, 0x30, 0x0c, 0x20, 0x04, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0xe0, 0x01, 0xe0, 0x01, - 0xf0, 0x03, 0xf0, 0x03, 0xf8, 0x07, 0xf8, 0x07, 0xfc, 0x0f, 0xfc, 0x0f, - 0xfe, 0x1f, 0xfe, 0x1f, 0xff, 0x3f, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x3f, 0xff, 0x3f, - 0xfe, 0x1f, 0xfe, 0x1f, 0xfc, 0x0f, 0xfc, 0x0f, 0xf8, 0x07, 0xf8, 0x07, - 0xf0, 0x03, 0xf0, 0x03, 0xe0, 0x01, 0xe0, 0x01, 0xc0, 0x00, 0xc0, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x03, 0xe0, 0x07, - 0xf0, 0x0f, 0xf0, 0x0f, 0xf0, 0x0f, 0xf0, 0x0f, 0xf0, 0x0f, 0xf0, 0x0f, - 0xe0, 0x07, 0xe0, 0x07, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0x00, 0x00, 0x00, 0x00, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x3c, 0x3c, 0x3c, - 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x38, 0x1c, 0x30, 0x0c, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x07, 0x38, 0x07, - 0x38, 0x07, 0x38, 0x07, 0xff, 0x3f, 0xff, 0x3f, 0x38, 0x07, 0x38, 0x07, - 0x38, 0x07, 0x38, 0x07, 0x38, 0x07, 0x38, 0x07, 0xff, 0x3f, 0xff, 0x3f, - 0x38, 0x07, 0x38, 0x07, 0x38, 0x07, 0x38, 0x07, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xfc, 0x0f, 0xfe, 0x1f, - 0x0f, 0x3c, 0x0f, 0x38, 0x0f, 0x30, 0x0f, 0x30, 0x0f, 0x00, 0x0f, 0x00, - 0xfe, 0x0f, 0xfc, 0x1f, 0x00, 0x3c, 0x00, 0x3c, 0x00, 0x3c, 0x00, 0x3c, - 0x03, 0x3c, 0x03, 0x3c, 0x07, 0x3c, 0x0f, 0x3c, 0xfe, 0x1f, 0xfc, 0x0f, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x30, 0x0f, 0x38, - 0x0f, 0x3c, 0x06, 0x1e, 0x00, 0x0f, 0x80, 0x07, 0xc0, 0x03, 0xe0, 0x01, - 0xf0, 0x00, 0x78, 0x00, 0x3c, 0x00, 0x1e, 0x00, 0x0f, 0x18, 0x07, 0x3c, - 0x03, 0x3c, 0x01, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xf0, 0x03, 0xf8, 0x07, 0x3c, 0x0f, 0x3c, 0x0f, - 0x3c, 0x0f, 0x38, 0x07, 0xf0, 0x03, 0xf0, 0x03, 0xfc, 0x30, 0xfe, 0x38, - 0xcf, 0x1f, 0xcf, 0x1f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, - 0x0f, 0x0f, 0x8f, 0x0f, 0xfe, 0x3f, 0xfc, 0x1c, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0xf0, 0x00, 0xf0, 0x00, 0xf0, 0x00, - 0xf0, 0x00, 0xf0, 0x00, 0x78, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x0f, 0x80, 0x0f, 0xc0, 0x03, 0xe0, 0x01, 0xe0, 0x00, 0xe0, 0x00, - 0xf0, 0x00, 0xf0, 0x00, 0xf0, 0x00, 0xf0, 0x00, 0xf0, 0x00, 0xf0, 0x00, - 0xf0, 0x00, 0xf0, 0x00, 0xe0, 0x00, 0xe0, 0x00, 0xe0, 0x01, 0xc0, 0x03, - 0x80, 0x0f, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xf0, 0x00, 0xf0, 0x01, 0xc0, 0x03, 0x80, 0x07, - 0x00, 0x07, 0x00, 0x07, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, - 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x07, 0x00, 0x07, - 0x80, 0x07, 0xc0, 0x03, 0xf0, 0x01, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x38, 0x3c, 0x3c, 0x78, 0x1e, - 0xf0, 0x0f, 0xf0, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x0f, 0xf0, 0x0f, - 0x78, 0x1e, 0x3c, 0x3c, 0x1c, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xfc, 0x3f, 0xfc, 0x3f, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xe0, 0x01, 0xf0, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xff, 0x3f, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x20, 0x00, 0x30, 0x00, 0x38, 0x00, 0x3c, 0x00, 0x1e, 0x00, 0x0f, - 0x80, 0x07, 0xc0, 0x03, 0xe0, 0x01, 0xf0, 0x00, 0x78, 0x00, 0x3c, 0x00, - 0x1e, 0x00, 0x0f, 0x00, 0x07, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x0f, 0xf8, 0x1f, - 0x3c, 0x3c, 0x1e, 0x78, 0x0f, 0xf0, 0x0f, 0xf0, 0x0f, 0xf0, 0x0f, 0xf0, - 0x8f, 0xf1, 0xcf, 0xf3, 0xcf, 0xf3, 0x8f, 0xf1, 0x0f, 0xf0, 0x0f, 0xf0, - 0x0f, 0xf0, 0x0f, 0xf0, 0x1e, 0x78, 0x3c, 0x3c, 0xf8, 0x1f, 0xf0, 0x0f, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x80, 0x03, 0xc0, 0x03, 0xe0, 0x03, 0xf0, 0x03, 0xf8, 0x03, 0xfc, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xfc, 0x3f, 0xfc, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xf0, 0x07, 0xfc, 0x0f, 0x0e, 0x1c, 0x07, 0x3c, - 0x00, 0x3c, 0x00, 0x1e, 0x00, 0x0f, 0x80, 0x07, 0xc0, 0x03, 0xe0, 0x01, - 0xf0, 0x00, 0x78, 0x00, 0x3c, 0x00, 0x1c, 0x00, 0x0e, 0x00, 0x0e, 0x00, - 0x0f, 0x30, 0x0f, 0x3c, 0xff, 0x3f, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x0f, 0xfe, 0x1f, - 0x1f, 0x3e, 0x0f, 0x3c, 0x00, 0x3c, 0x00, 0x3c, 0x00, 0x3c, 0x00, 0x3c, - 0xf0, 0x0f, 0xf0, 0x0f, 0x00, 0x3c, 0x00, 0x3c, 0x00, 0x3c, 0x00, 0x3c, - 0x00, 0x3c, 0x00, 0x3c, 0x0f, 0x3c, 0x1f, 0x3e, 0xfe, 0x1f, 0xfc, 0x0f, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x0e, 0x00, 0x0f, 0x80, 0x0f, 0xc0, 0x0f, 0xe0, 0x0f, 0xf0, 0x0f, - 0x78, 0x0f, 0x3c, 0x0f, 0x1e, 0x0f, 0x0f, 0x0f, 0xff, 0x3f, 0xff, 0x3f, - 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, - 0xc0, 0x3f, 0xc0, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xff, 0x3f, 0xff, 0x3f, 0x0f, 0x00, 0x0f, 0x00, - 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0xff, 0x0f, 0xff, 0x1f, - 0x00, 0x3c, 0x00, 0x3c, 0x00, 0x3c, 0x00, 0x3c, 0x00, 0x3c, 0x00, 0x3c, - 0x0f, 0x3c, 0x0f, 0x3c, 0xfe, 0x1f, 0xfc, 0x0f, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x03, 0xf8, 0x03, - 0x3c, 0x00, 0x1e, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, - 0xff, 0x0f, 0xff, 0x1f, 0x1f, 0x3e, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, - 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x1f, 0x3e, 0xfe, 0x1f, 0xfc, 0x0f, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xff, 0x3f, 0xff, 0x3f, 0x0f, 0x3c, 0x0f, 0x3c, 0x00, 0x3c, 0x00, 0x3c, - 0x00, 0x3c, 0x00, 0x3c, 0x00, 0x1e, 0x00, 0x0f, 0x80, 0x07, 0xc0, 0x03, - 0xe0, 0x01, 0xe0, 0x01, 0xf0, 0x00, 0xf0, 0x00, 0xf0, 0x00, 0xf0, 0x00, - 0xf0, 0x00, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xfc, 0x0f, 0xfe, 0x1f, 0x1f, 0x3e, 0x0f, 0x3c, - 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x1e, 0x1e, 0xfc, 0x0f, 0xfc, 0x0f, - 0x1e, 0x1e, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, - 0x0f, 0x3c, 0x1f, 0x3e, 0xfe, 0x1f, 0xfc, 0x0f, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x0f, 0xfe, 0x1f, - 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, - 0xfe, 0x3f, 0xfc, 0x3f, 0x00, 0x3c, 0x00, 0x3c, 0x00, 0x3c, 0x00, 0x3c, - 0x00, 0x3c, 0x00, 0x3c, 0x00, 0x1e, 0x00, 0x0f, 0xfc, 0x07, 0xfc, 0x03, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0xc0, 0x03, - 0xc0, 0x03, 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0xc0, 0x03, 0xc0, 0x03, 0x80, 0x01, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x80, 0x01, 0xc0, 0x03, 0xc0, 0x03, 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xe0, 0x01, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x3c, 0x00, 0x1e, 0x00, 0x0f, 0x80, 0x07, 0xc0, 0x03, 0xe0, 0x01, - 0xf0, 0x00, 0x78, 0x00, 0x3c, 0x00, 0x3c, 0x00, 0x78, 0x00, 0xf0, 0x00, - 0xe0, 0x01, 0xc0, 0x03, 0x80, 0x07, 0x00, 0x0f, 0x00, 0x1e, 0x00, 0x3c, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xfc, 0x3f, 0xfc, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xfc, 0x3f, 0xfc, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x78, 0x00, - 0xf0, 0x00, 0xe0, 0x01, 0xc0, 0x03, 0x80, 0x07, 0x00, 0x0f, 0x00, 0x1e, - 0x00, 0x3c, 0x00, 0x3c, 0x00, 0x1e, 0x00, 0x0f, 0x80, 0x07, 0xc0, 0x03, - 0xe0, 0x01, 0xf0, 0x00, 0x78, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x0f, 0xfe, 0x1f, - 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3e, 0x00, 0x1f, 0x80, 0x0f, - 0xc0, 0x07, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0x00, 0x00, 0x00, 0x00, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xfc, 0x0f, 0xfe, 0x1f, 0x0f, 0x3c, 0x0f, 0x3c, - 0x0f, 0x3c, 0x0f, 0x3c, 0x8f, 0x3f, 0xcf, 0x3f, 0xcf, 0x3f, 0xcf, 0x3f, - 0xcf, 0x3f, 0xcf, 0x3f, 0xcf, 0x1f, 0x8f, 0x0f, 0x0f, 0x00, 0x0f, 0x00, - 0xfe, 0x0f, 0xfc, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0xe0, 0x01, 0xf0, 0x03, 0xf8, 0x07, - 0x3c, 0x0f, 0x1e, 0x1e, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, - 0xff, 0x3f, 0xff, 0x3f, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, - 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x07, 0xff, 0x0f, - 0x3c, 0x1c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x1c, - 0xfc, 0x0f, 0xfc, 0x0f, 0x3c, 0x1c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, - 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x1c, 0xff, 0x0f, 0xff, 0x07, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xc0, 0x03, 0xf0, 0x0f, 0x78, 0x1e, 0x3c, 0x3c, 0x1e, 0x38, 0x1e, 0x30, - 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, - 0x0f, 0x00, 0x0f, 0x00, 0x1e, 0x30, 0x1e, 0x38, 0x3c, 0x3c, 0x78, 0x1e, - 0xf0, 0x0f, 0xc0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xff, 0x01, 0xff, 0x03, 0xbc, 0x07, 0x3c, 0x0f, - 0x3c, 0x1e, 0x3c, 0x1c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, - 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x1c, 0x3c, 0x1e, - 0x3c, 0x0f, 0xbc, 0x07, 0xff, 0x03, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x3f, 0xff, 0x3f, - 0x3c, 0x3c, 0x3c, 0x38, 0x3c, 0x30, 0x3c, 0x20, 0x3c, 0x03, 0x3c, 0x03, - 0xfc, 0x03, 0xfc, 0x03, 0x3c, 0x03, 0x3c, 0x03, 0x3c, 0x00, 0x3c, 0x00, - 0x3c, 0x20, 0x3c, 0x30, 0x3c, 0x38, 0x3c, 0x3c, 0xff, 0x3f, 0xff, 0x3f, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xff, 0x3f, 0xff, 0x3f, 0x3c, 0x3c, 0x3c, 0x38, 0x3c, 0x30, 0x3c, 0x20, - 0x3c, 0x03, 0x3c, 0x03, 0xfc, 0x03, 0xfc, 0x03, 0x3c, 0x03, 0x3c, 0x03, - 0x3c, 0x00, 0x3c, 0x00, 0x3c, 0x00, 0x3c, 0x00, 0x3c, 0x00, 0x3c, 0x00, - 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xe0, 0x07, 0xf0, 0x0f, 0x78, 0x1c, 0x3c, 0x38, - 0x1e, 0x30, 0x0e, 0x30, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, - 0xcf, 0x3f, 0xcf, 0x3f, 0x0f, 0x3c, 0x0f, 0x3c, 0x0e, 0x3c, 0x1e, 0x3c, - 0x3c, 0x3c, 0x78, 0x3e, 0xf0, 0x37, 0xe0, 0x33, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x3c, 0x0f, 0x3c, - 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, - 0xff, 0x3f, 0xff, 0x3f, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, - 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xf0, 0x0f, 0xf0, 0x0f, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xf0, 0x0f, 0xf0, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xc0, 0x3f, 0xc0, 0x3f, 0x00, 0x0f, 0x00, 0x0f, - 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, - 0x00, 0x0f, 0x00, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, - 0x0f, 0x0f, 0x0f, 0x0f, 0xfe, 0x07, 0xfc, 0x03, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x3c, 0x3f, 0x3c, - 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x1e, 0x3c, 0x0f, - 0xfc, 0x07, 0xfc, 0x03, 0xfc, 0x03, 0xfc, 0x07, 0x3c, 0x0f, 0x3c, 0x1e, - 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3f, 0x3c, 0x3f, 0x3c, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xff, 0x00, 0xff, 0x00, 0x3c, 0x00, 0x3c, 0x00, 0x3c, 0x00, 0x3c, 0x00, - 0x3c, 0x00, 0x3c, 0x00, 0x3c, 0x00, 0x3c, 0x00, 0x3c, 0x00, 0x3c, 0x00, - 0x3c, 0x00, 0x3c, 0x00, 0x3c, 0x20, 0x3c, 0x30, 0x3c, 0x38, 0x3c, 0x3c, - 0xff, 0x3f, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x07, 0xe0, 0x0f, 0xf0, 0x1f, 0xf8, 0x3f, 0xfc, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xcf, 0xf3, 0x8f, 0xf1, - 0x0f, 0xf0, 0x0f, 0xf0, 0x0f, 0xf0, 0x0f, 0xf0, 0x0f, 0xf0, 0x0f, 0xf0, - 0x0f, 0xf0, 0x0f, 0xf0, 0x0f, 0xf0, 0x0f, 0xf0, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x3c, 0x0f, 0x3c, - 0x1f, 0x3c, 0x3f, 0x3c, 0x7f, 0x3c, 0xff, 0x3c, 0xff, 0x3f, 0xff, 0x3f, - 0xcf, 0x3f, 0x8f, 0x3f, 0x0f, 0x3f, 0x0f, 0x3e, 0x0f, 0x3c, 0x0f, 0x3c, - 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xf8, 0x07, 0xfc, 0x0f, 0x1e, 0x1e, 0x1e, 0x1e, 0x0f, 0x3c, 0x0f, 0x3c, - 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, - 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x1e, 0x1e, 0x1e, 0x1e, - 0xfc, 0x0f, 0xf8, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xff, 0x07, 0xff, 0x0f, 0x3c, 0x1e, 0x3c, 0x3c, - 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x1e, 0xfc, 0x0f, 0xfc, 0x07, - 0x3c, 0x00, 0x3c, 0x00, 0x3c, 0x00, 0x3c, 0x00, 0x3c, 0x00, 0x3c, 0x00, - 0x3c, 0x00, 0x3c, 0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x0f, 0xfe, 0x1f, - 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, - 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, - 0xcf, 0x3c, 0xcf, 0x3c, 0xcf, 0x3f, 0xcf, 0x3f, 0xfe, 0x1f, 0xfc, 0x0f, - 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x3f, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xff, 0x07, 0xff, 0x0f, 0x3c, 0x1c, 0x3c, 0x38, 0x3c, 0x38, 0x3c, 0x38, - 0x3c, 0x3c, 0x3c, 0x1c, 0xfc, 0x0f, 0xfc, 0x07, 0x3c, 0x07, 0x3c, 0x0e, - 0x3c, 0x1c, 0x3c, 0x1c, 0x3c, 0x38, 0x3c, 0x38, 0x3c, 0x38, 0x3c, 0x38, - 0x3f, 0x38, 0x3f, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xfc, 0x0f, 0xfe, 0x1f, 0x0f, 0x3c, 0x0f, 0x3c, - 0x0f, 0x3c, 0x0f, 0x3c, 0x1e, 0x00, 0x3c, 0x00, 0xf8, 0x00, 0xf0, 0x03, - 0xc0, 0x0f, 0x00, 0x1f, 0x00, 0x3c, 0x00, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, - 0x0f, 0x3c, 0x1f, 0x3e, 0xfe, 0x1f, 0xfc, 0x0f, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, - 0xcf, 0xf3, 0xc7, 0xe3, 0xc3, 0xc3, 0xc1, 0x83, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xf0, 0x0f, 0xf0, 0x0f, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, - 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, - 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x1e, 0x1e, - 0xfc, 0x0f, 0xf8, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x0f, 0xf0, 0x0f, 0xf0, 0x0f, 0xf0, 0x0f, 0xf0, - 0x0f, 0xf0, 0x0f, 0xf0, 0x0f, 0xf0, 0x0f, 0xf0, 0x0f, 0xf0, 0x0f, 0xf0, - 0x0f, 0xf0, 0x0f, 0xf0, 0x0f, 0xf0, 0x0f, 0xf0, 0x1e, 0x78, 0x3c, 0x3c, - 0x78, 0x1e, 0xf0, 0x0f, 0xe0, 0x07, 0xc0, 0x03, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xf0, 0x0f, 0xf0, - 0x0f, 0xf0, 0x0f, 0xf0, 0x0f, 0xf0, 0x0f, 0xf0, 0x0f, 0xf0, 0x0f, 0xf0, - 0x0f, 0xf0, 0x0f, 0xf0, 0x8f, 0xf1, 0x8f, 0xf1, 0xcf, 0xf3, 0xcf, 0xf3, - 0xef, 0xf7, 0xef, 0xf7, 0x7e, 0x7e, 0x7e, 0x7e, 0x3c, 0x3c, 0x3c, 0x3c, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x0f, 0xf0, 0x0f, 0xf0, 0x0f, 0xf0, 0x0f, 0xf0, 0x1e, 0x78, 0x3c, 0x3c, - 0x78, 0x1e, 0xf0, 0x0f, 0xe0, 0x07, 0xc0, 0x03, 0xc0, 0x03, 0xe0, 0x07, - 0xf0, 0x0f, 0x78, 0x1e, 0x3c, 0x3c, 0x1e, 0x78, 0x0f, 0xf0, 0x0f, 0xf0, - 0x0f, 0xf0, 0x0f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x0f, 0xf0, 0x0f, 0xf0, 0x0f, 0xf0, 0x0f, 0xf0, - 0x0f, 0xf0, 0x1e, 0x78, 0x3c, 0x3c, 0x78, 0x1e, 0xf0, 0x0f, 0xe0, 0x07, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xf0, 0x0f, 0xf0, 0x0f, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, - 0x0f, 0xf0, 0x07, 0x78, 0x03, 0x3c, 0x01, 0x1e, 0x00, 0x0f, 0x80, 0x07, - 0xc0, 0x03, 0xe0, 0x01, 0xf0, 0x00, 0x78, 0x00, 0x3c, 0x00, 0x1e, 0x00, - 0x0f, 0x80, 0x0f, 0xc0, 0x0f, 0xe0, 0x0f, 0xf0, 0xff, 0xff, 0xff, 0xff, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xf0, 0x0f, 0xf0, 0x0f, 0xf0, 0x00, 0xf0, 0x00, 0xf0, 0x00, 0xf0, 0x00, - 0xf0, 0x00, 0xf0, 0x00, 0xf0, 0x00, 0xf0, 0x00, 0xf0, 0x00, 0xf0, 0x00, - 0xf0, 0x00, 0xf0, 0x00, 0xf0, 0x00, 0xf0, 0x00, 0xf0, 0x00, 0xf0, 0x00, - 0xf0, 0x0f, 0xf0, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x03, 0x00, - 0x0f, 0x00, 0x0f, 0x00, 0x3f, 0x00, 0x3f, 0x00, 0xfc, 0x00, 0xfc, 0x00, - 0xf0, 0x03, 0xf0, 0x03, 0xc0, 0x0f, 0xc0, 0x0f, 0x00, 0x3f, 0x00, 0x3f, - 0x00, 0x3c, 0x00, 0x3c, 0x00, 0x30, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x0f, 0xf0, 0x0f, - 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, - 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, - 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0xf0, 0x0f, 0xf0, 0x0f, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0xe0, 0x01, 0xf0, 0x03, - 0x38, 0x07, 0x1c, 0x0e, 0x0e, 0x1c, 0x07, 0x38, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x70, 0x00, 0x70, 0x00, 0x70, 0x00, 0xe0, 0x00, 0xc0, 0x03, 0x80, 0x03, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xfc, 0x01, 0xfc, 0x03, 0x00, 0x07, 0x00, 0x0f, 0xf8, 0x0f, 0xfc, 0x0f, - 0x1e, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x9e, 0x0f, - 0xfc, 0x3c, 0x78, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x3f, 0x00, 0x3c, 0x00, 0x3c, 0x00, - 0x3c, 0x00, 0x3c, 0x00, 0xfc, 0x01, 0xfc, 0x03, 0x3c, 0x07, 0x3c, 0x0e, - 0x3c, 0x1c, 0x3c, 0x1c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, - 0x3c, 0x1c, 0x3c, 0x1c, 0xfc, 0x0f, 0xfc, 0x07, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x07, 0xfc, 0x0f, - 0x1e, 0x1c, 0x0f, 0x3c, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, - 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x38, 0x1e, 0x1c, 0xfc, 0x0f, 0xf8, 0x07, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xc0, 0x0f, 0xc0, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, - 0xf0, 0x0f, 0xf8, 0x0f, 0x3c, 0x0f, 0x1e, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, - 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x1f, 0x0f, - 0xfe, 0x3d, 0xfc, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xfc, 0x0f, 0xfe, 0x1f, 0x0f, 0x3c, 0x0f, 0x3c, - 0xff, 0x3f, 0xff, 0x3f, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, - 0x0f, 0x38, 0x1f, 0x3c, 0xfe, 0x1f, 0xfc, 0x0f, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x01, 0xf0, 0x03, - 0x38, 0x07, 0x3c, 0x0e, 0x3c, 0x0c, 0x3c, 0x0c, 0x3c, 0x00, 0x3c, 0x00, - 0xff, 0x00, 0xff, 0x00, 0x3c, 0x00, 0x3c, 0x00, 0x3c, 0x00, 0x3c, 0x00, - 0x3c, 0x00, 0x3c, 0x00, 0x3c, 0x00, 0x3c, 0x00, 0xff, 0x00, 0xff, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xf8, 0x38, 0xfc, 0x3d, 0x0e, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, - 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0e, 0x0f, - 0xfc, 0x0f, 0xf8, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x07, 0x0f, 0x0e, 0x0f, - 0xfc, 0x03, 0xf8, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x3f, 0x00, 0x3c, 0x00, 0x3c, 0x00, - 0x3c, 0x00, 0x3c, 0x00, 0x3c, 0x0f, 0xbc, 0x1f, 0xfc, 0x3c, 0x7c, 0x3c, - 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, - 0x3c, 0x3c, 0x3c, 0x3c, 0x3f, 0x3c, 0x3f, 0x3c, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0xc0, 0x03, - 0xc0, 0x03, 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x03, 0xf0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xf0, 0x0f, 0xf0, 0x0f, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x18, 0x00, 0x3c, 0x00, 0x3c, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x3f, 0x00, 0x3f, 0x00, 0x3c, 0x00, 0x3c, 0x00, 0x3c, 0x00, 0x3c, - 0x00, 0x3c, 0x00, 0x3c, 0x00, 0x3c, 0x00, 0x3c, 0x00, 0x3c, 0x00, 0x3c, - 0x00, 0x3c, 0x00, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x38, 0x1c, - 0xf0, 0x0f, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x3f, 0x00, 0x3c, 0x00, 0x3c, 0x00, - 0x3c, 0x00, 0x3c, 0x00, 0x3c, 0x38, 0x3c, 0x1c, 0x3c, 0x0e, 0x3c, 0x07, - 0xbc, 0x03, 0xfc, 0x01, 0xfc, 0x01, 0xfc, 0x03, 0x3c, 0x07, 0x3c, 0x0e, - 0x3c, 0x1c, 0x3c, 0x38, 0x3f, 0x38, 0x3f, 0x38, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x03, 0xf0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xf0, 0x0f, 0xf0, 0x0f, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x3f, 0x3c, 0x7f, 0x7e, 0xff, 0xff, 0xff, 0xff, 0xcf, 0xf3, 0xcf, 0xf3, - 0xcf, 0xf3, 0xcf, 0xf3, 0xcf, 0xf3, 0xcf, 0xf3, 0xcf, 0xf3, 0xcf, 0xf3, - 0xcf, 0xf3, 0xcf, 0xf3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xc7, 0x07, 0xef, 0x0f, 0x3c, 0x1c, 0x3c, 0x3c, - 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, - 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x07, 0xfc, 0x0f, - 0x1e, 0x1e, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, - 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x1e, 0x1e, 0xfc, 0x0f, 0xf8, 0x07, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xc7, 0x07, 0xef, 0x0f, 0x7c, 0x1e, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, - 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x1e, - 0xfc, 0x0f, 0xfc, 0x07, 0x3c, 0x00, 0x3c, 0x00, 0x3c, 0x00, 0x3c, 0x00, - 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xf8, 0x38, 0xfc, 0x3d, 0x1e, 0x0f, 0x0f, 0x0f, - 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, - 0x0f, 0x0f, 0x1e, 0x0f, 0xfc, 0x0f, 0xf8, 0x0f, 0x00, 0x0f, 0x00, 0x0f, - 0x00, 0x0f, 0x00, 0x0f, 0xc0, 0x3f, 0xc0, 0x3f, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x87, 0x07, 0xcf, 0x0f, - 0xfc, 0x1c, 0x7c, 0x38, 0x3c, 0x38, 0x3c, 0x38, 0x3c, 0x00, 0x3c, 0x00, - 0x3c, 0x00, 0x3c, 0x00, 0x3c, 0x00, 0x3c, 0x00, 0xff, 0x00, 0xff, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xfc, 0x0f, 0xfe, 0x1f, 0x0f, 0x3c, 0x0f, 0x3c, 0x3e, 0x00, 0xfc, 0x00, - 0xf0, 0x03, 0xc0, 0x07, 0x00, 0x0f, 0x00, 0x1e, 0x0f, 0x3c, 0x0f, 0x3c, - 0xfe, 0x1f, 0xfc, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0xc0, 0x00, 0xe0, 0x00, 0xf0, 0x00, - 0xf0, 0x00, 0xf0, 0x00, 0xff, 0x0f, 0xff, 0x0f, 0xf0, 0x00, 0xf0, 0x00, - 0xf0, 0x00, 0xf0, 0x00, 0xf0, 0x00, 0xf0, 0x00, 0xf0, 0x00, 0xf0, 0x00, - 0xf0, 0x38, 0xe0, 0x3c, 0xc0, 0x0f, 0x80, 0x07, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x0f, 0x0f, 0x0f, - 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, - 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x8f, 0x0f, 0xfe, 0x3d, 0xfc, 0x38, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x0f, 0xf0, 0x0f, 0xf0, 0x0f, 0xf0, 0x0f, 0xf0, 0x0f, 0xf0, 0x0f, 0xf0, - 0x0f, 0xf0, 0x0f, 0xf0, 0x1e, 0x78, 0x3c, 0x3c, 0x78, 0x1e, 0xf0, 0x0f, - 0xe0, 0x07, 0xc0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x0f, 0xf0, 0x0f, 0xf0, 0x0f, 0xf0, 0x0f, 0xf0, - 0x0f, 0xf0, 0x0f, 0xf0, 0xcf, 0xf3, 0xcf, 0xf3, 0xcf, 0xf3, 0xcf, 0xf3, - 0xff, 0xff, 0xff, 0xff, 0x7e, 0x7e, 0x3c, 0x3c, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xf0, 0x1f, 0xf8, - 0x3c, 0x3c, 0x78, 0x1e, 0xf0, 0x0f, 0xe0, 0x07, 0xc0, 0x03, 0xe0, 0x07, - 0xf0, 0x0f, 0x78, 0x1e, 0x3c, 0x3c, 0x1e, 0x78, 0x0f, 0xf0, 0x07, 0xe0, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, - 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0e, 0x3c, - 0xfc, 0x3f, 0xf8, 0x3f, 0x00, 0x3c, 0x00, 0x1c, 0x00, 0x0e, 0x00, 0x07, - 0xff, 0x03, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xff, 0x3f, 0xff, 0x1f, 0x07, 0x0e, 0x03, 0x07, - 0x80, 0x03, 0xc0, 0x01, 0xe0, 0x00, 0x70, 0x00, 0x38, 0x00, 0x1c, 0x00, - 0x0e, 0x30, 0x07, 0x38, 0xff, 0x3f, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x3f, - 0x80, 0x03, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, - 0xfc, 0x00, 0xfc, 0x00, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, - 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x03, 0xc0, 0x03, 0x00, 0x3f, 0x00, 0x3f, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x7c, 0x00, 0xfc, 0x00, 0xc0, 0x01, 0x80, 0x03, - 0x80, 0x03, 0x80, 0x03, 0x80, 0x03, 0x80, 0x03, 0x00, 0x3f, 0x00, 0x3f, - 0x80, 0x03, 0x80, 0x03, 0x80, 0x03, 0x80, 0x03, 0x80, 0x03, 0x80, 0x03, - 0xc0, 0x03, 0xc0, 0x01, 0xfc, 0x00, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x38, 0xfc, 0x3c, - 0xce, 0x0f, 0x87, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, - 0xe0, 0x01, 0xf0, 0x03, 0x38, 0x07, 0x1c, 0x0e, 0x0e, 0x1c, 0x07, 0x38, - 0x07, 0x38, 0x07, 0x38, 0x07, 0x38, 0x07, 0x38, 0xff, 0x3f, 0xff, 0x3f, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xe0, 0x07, 0xf0, 0x0f, 0x38, 0x1c, 0x1c, 0x38, - 0x0e, 0x30, 0x0f, 0x30, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, - 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x30, 0x0e, 0x30, 0x1c, 0x38, 0x38, 0x1c, - 0xf0, 0x0f, 0xe0, 0x0f, 0x00, 0x0f, 0x00, 0x0e, 0x00, 0x1c, 0x00, 0x1c, - 0xfc, 0x0f, 0xfc, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x0f, 0x0f, 0x0f, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x0f, 0x0f, 0x0f, - 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, - 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x8f, 0x0f, 0xfe, 0x3d, 0xfc, 0x38, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x07, - 0x80, 0x03, 0xc0, 0x01, 0xe0, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xfc, 0x0f, 0xfe, 0x1f, 0x0f, 0x3c, 0x0f, 0x3c, 0xff, 0x3f, 0xff, 0x3f, - 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x38, 0x1f, 0x3c, - 0xfe, 0x1f, 0xfc, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0xc0, 0x00, 0xe0, 0x01, 0xf0, 0x03, 0x38, 0x07, 0x1c, 0x0e, - 0x00, 0x00, 0x00, 0x00, 0xfc, 0x01, 0xfc, 0x03, 0x00, 0x07, 0x00, 0x0f, - 0xf8, 0x0f, 0xfc, 0x0f, 0x1e, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, - 0x0f, 0x0f, 0x9e, 0x0f, 0xfc, 0x3c, 0x78, 0x38, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x0f, 0x0f, 0x0f, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x01, 0xfc, 0x03, - 0x00, 0x07, 0x00, 0x0f, 0xf8, 0x0f, 0xfc, 0x0f, 0x1e, 0x0f, 0x0f, 0x0f, - 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x9e, 0x0f, 0xfc, 0x3c, 0x78, 0x38, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x38, 0x00, - 0x70, 0x00, 0xe0, 0x00, 0xc0, 0x01, 0x80, 0x03, 0x00, 0x00, 0x00, 0x00, - 0xfc, 0x01, 0xfc, 0x03, 0x00, 0x07, 0x00, 0x0f, 0xf8, 0x0f, 0xfc, 0x0f, - 0x1e, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x9e, 0x0f, - 0xfc, 0x3c, 0x78, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xe0, 0x01, 0xf0, 0x03, 0x1c, 0x0e, 0x1c, 0x0e, 0xf0, 0x03, 0xe0, 0x01, - 0x00, 0x00, 0x00, 0x00, 0xfc, 0x01, 0xfc, 0x03, 0x00, 0x07, 0x00, 0x0f, - 0xf8, 0x0f, 0xfc, 0x0f, 0x1e, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, - 0x0f, 0x0f, 0x9e, 0x0f, 0xfc, 0x3c, 0x78, 0x38, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xe0, 0x07, 0xf0, 0x0f, 0x38, 0x1c, 0x3c, 0x38, - 0x3c, 0x00, 0x3c, 0x00, 0x3c, 0x00, 0x3c, 0x00, 0x3c, 0x38, 0x38, 0x1c, - 0xf0, 0x0f, 0xe0, 0x0f, 0x00, 0x0f, 0x00, 0x0e, 0x00, 0x1c, 0x00, 0x1c, - 0xf0, 0x0f, 0xf0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, - 0xe0, 0x01, 0xf0, 0x03, 0x38, 0x07, 0x1c, 0x0e, 0x00, 0x00, 0x00, 0x00, - 0xfc, 0x0f, 0xfe, 0x1f, 0x0f, 0x3c, 0x0f, 0x3c, 0xff, 0x3f, 0xff, 0x3f, - 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x38, 0x1f, 0x3c, - 0xfe, 0x1f, 0xfc, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x0f, 0x3c, 0x0f, 0x3c, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xfc, 0x0f, 0xfe, 0x1f, 0x0f, 0x3c, 0x0f, 0x3c, - 0xff, 0x3f, 0xff, 0x3f, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, - 0x0f, 0x38, 0x1f, 0x3c, 0xfe, 0x1f, 0xfc, 0x0f, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x38, 0x00, 0x70, 0x00, 0xe0, 0x00, - 0xc0, 0x01, 0x80, 0x03, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x0f, 0xfe, 0x1f, - 0x0f, 0x3c, 0x0f, 0x3c, 0xff, 0x3f, 0xff, 0x3f, 0x0f, 0x00, 0x0f, 0x00, - 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x38, 0x1f, 0x3c, 0xfe, 0x1f, 0xfc, 0x0f, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x3c, 0x3c, 0x3c, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xf0, 0x03, 0xf0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xf0, 0x0f, 0xf0, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x80, 0x01, 0xc0, 0x03, 0xe0, 0x07, 0x70, 0x0e, 0x38, 0x1c, 0x1c, 0x38, - 0x00, 0x00, 0x00, 0x00, 0xf0, 0x03, 0xf0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xf0, 0x0f, 0xf0, 0x0f, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x38, 0x00, 0x70, 0x00, 0xe0, 0x00, - 0xc0, 0x01, 0x80, 0x03, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x03, 0xf0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xf0, 0x0f, 0xf0, 0x0f, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x3c, 0x0f, 0x3c, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0xe0, 0x01, 0xf0, 0x03, - 0x38, 0x07, 0x1c, 0x0e, 0x0e, 0x1c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, - 0xff, 0x3f, 0xff, 0x3f, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, - 0x0f, 0x3c, 0x0f, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x01, 0xf0, 0x03, - 0x1c, 0x0e, 0x1c, 0x0e, 0xf0, 0x03, 0xe0, 0x01, 0x00, 0x00, 0xc0, 0x00, - 0xe0, 0x01, 0xf0, 0x03, 0x38, 0x07, 0x1c, 0x0e, 0x0e, 0x1c, 0x0f, 0x3c, - 0x0f, 0x3c, 0x0f, 0x3c, 0xff, 0x3f, 0xff, 0x3f, 0x0f, 0x3c, 0x0f, 0x3c, - 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x80, 0x03, 0xc0, 0x01, 0xe0, 0x00, 0x70, 0x00, 0x38, 0x00, 0x1c, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xff, 0x3f, 0xff, 0x3f, 0x3c, 0x38, 0x3c, 0x30, - 0x3c, 0x00, 0x3c, 0x00, 0xfc, 0x0f, 0xfc, 0x0f, 0x3c, 0x00, 0x3c, 0x00, - 0x3c, 0x00, 0x3c, 0x00, 0x3c, 0x30, 0x3c, 0x38, 0xff, 0x3f, 0xff, 0x3f, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x1c, 0x1e, 0x38, 0x3f, 0xf0, 0x73, 0xe0, 0xf3, 0xc0, 0xf3, 0xc0, 0x73, - 0xf8, 0x3f, 0xfc, 0x1f, 0xce, 0x03, 0xc7, 0x03, 0xc7, 0x07, 0xce, 0x1e, - 0xfc, 0xfc, 0x78, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xe0, 0x3f, 0xf0, 0x3f, 0x38, 0x0f, 0x1c, 0x0f, - 0x0e, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0xff, 0x3f, 0xff, 0x3f, - 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, - 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x3f, 0x0f, 0x3f, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0xe0, 0x01, 0xf0, 0x03, 0x38, 0x07, - 0x1c, 0x0e, 0x0e, 0x1c, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x07, 0xfc, 0x0f, - 0x1e, 0x1e, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, - 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x1e, 0x1e, 0xfc, 0x0f, 0xf8, 0x07, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x0f, 0x3c, 0x0f, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xf8, 0x07, 0xfc, 0x0f, 0x1e, 0x1e, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, - 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x1e, 0x1e, - 0xfc, 0x0f, 0xf8, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x1c, 0x00, 0x38, 0x00, 0x70, 0x00, 0xe0, 0x00, 0xc0, 0x01, 0x80, 0x03, - 0x00, 0x00, 0x00, 0x00, 0xf8, 0x07, 0xfc, 0x0f, 0x1e, 0x1e, 0x0f, 0x3c, - 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, - 0x0f, 0x3c, 0x1e, 0x1e, 0xfc, 0x0f, 0xf8, 0x07, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0xf0, 0x00, 0xf8, 0x01, 0x9c, 0x03, - 0x0e, 0x07, 0x07, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x0f, 0x0f, 0x0f, - 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, - 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x8f, 0x0f, 0xfe, 0x3d, 0xfc, 0x38, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x38, 0x00, - 0x70, 0x00, 0xe0, 0x00, 0xc0, 0x01, 0x80, 0x03, 0x00, 0x00, 0x00, 0x00, - 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, - 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x8f, 0x0f, - 0xfe, 0x3d, 0xfc, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x0f, 0x3c, 0x0f, 0x3c, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, - 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, - 0x0f, 0x3c, 0x0e, 0x3c, 0xfc, 0x3f, 0xf8, 0x3f, 0x00, 0x3c, 0x00, 0x1c, - 0x00, 0x0e, 0x00, 0x07, 0xfc, 0x03, 0xfc, 0x01, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x0f, 0x3c, 0x0f, 0x3c, 0x00, 0x00, 0x00, 0x00, - 0xf8, 0x07, 0xfc, 0x0f, 0x0e, 0x1c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, - 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, - 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0e, 0x1c, 0xfc, 0x0f, 0xf8, 0x07, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x3c, 0x0f, 0x3c, - 0x00, 0x00, 0x00, 0x00, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, - 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, - 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0e, 0x1c, - 0xfc, 0x0f, 0xf8, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xf8, 0x1f, 0xfc, 0x3f, - 0x0e, 0x70, 0x07, 0xe0, 0x07, 0x00, 0x07, 0x00, 0x07, 0x00, 0x07, 0x00, - 0x07, 0x00, 0x07, 0x00, 0x07, 0xe0, 0x0e, 0x70, 0xfc, 0x3f, 0xf8, 0x1f, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xe0, 0x01, 0xf0, 0x03, 0x38, 0x07, 0x3c, 0x0e, - 0x3c, 0x0c, 0x3c, 0x0c, 0x3c, 0x00, 0x3c, 0x00, 0xff, 0x00, 0xff, 0x00, - 0x3c, 0x00, 0x3c, 0x00, 0x3c, 0x00, 0x3c, 0x00, 0x3c, 0x00, 0x3c, 0x00, - 0x3c, 0x00, 0x3c, 0x00, 0x3f, 0x38, 0x3f, 0x1c, 0xff, 0x0f, 0xff, 0x03, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x07, 0xe0, 0x0e, 0x70, 0x1c, 0x38, 0x38, 0x1c, 0x70, 0x0e, 0xe0, 0x07, - 0xc0, 0x03, 0xc0, 0x03, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x03, 0xc0, 0x03, - 0xff, 0xff, 0xff, 0xff, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xff, 0x0f, 0xff, 0x1f, 0x3c, 0x3c, 0x3c, 0x38, 0x3c, 0x38, 0x3c, 0x3c, - 0xfc, 0x1f, 0xfc, 0x0f, 0x3c, 0x30, 0x3c, 0x38, 0x3c, 0x3c, 0x3c, 0x3c, - 0x3c, 0xff, 0x3c, 0xff, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, - 0x3c, 0x3c, 0x3c, 0x3c, 0xff, 0xf8, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x3f, 0x80, 0x77, 0xc0, 0xe3, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xfc, 0x3f, 0xfc, 0x3f, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc7, 0x03, 0xee, 0x01, 0xfc, 0x00, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x03, 0xc0, 0x01, - 0xe0, 0x00, 0x70, 0x00, 0x38, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xfc, 0x01, 0xfc, 0x03, 0x00, 0x07, 0x00, 0x0f, 0xf8, 0x0f, 0xfc, 0x0f, - 0x1e, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x9e, 0x0f, - 0xfc, 0x3c, 0x78, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x0e, 0x00, 0x07, 0x80, 0x03, 0xc0, 0x01, 0xe0, 0x00, 0x70, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xf0, 0x03, 0xf0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xf0, 0x0f, 0xf0, 0x0f, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x80, 0x03, 0xc0, 0x01, 0xe0, 0x00, 0x70, 0x00, - 0x38, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x07, 0xfc, 0x0f, - 0x1e, 0x1e, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, - 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x1e, 0x1e, 0xfc, 0x0f, 0xf8, 0x07, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x03, 0xc0, 0x01, - 0xe0, 0x00, 0x70, 0x00, 0x38, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, - 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x8f, 0x0f, - 0xfe, 0x3d, 0xfc, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x78, 0x38, 0xfc, 0x3c, 0xcf, 0x0f, 0x87, 0x07, - 0x00, 0x00, 0x00, 0x00, 0xc7, 0x07, 0xef, 0x0f, 0x3c, 0x3c, 0x3c, 0x3c, - 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, - 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x78, 0x38, 0xfc, 0x3c, 0xcf, 0x0f, 0x87, 0x07, 0x00, 0x00, 0x00, 0x00, - 0x07, 0x3c, 0x0f, 0x3c, 0x1f, 0x3c, 0x3f, 0x3c, 0x7f, 0x3c, 0xff, 0x3c, - 0xff, 0x3d, 0xef, 0x3f, 0xcf, 0x3f, 0x8f, 0x3f, 0x0f, 0x3f, 0x0f, 0x3e, - 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x0f, 0xf0, 0x0f, - 0x38, 0x0f, 0x1c, 0x0f, 0x1c, 0x0f, 0x38, 0x0f, 0xf0, 0x3f, 0xe0, 0x3f, - 0x00, 0x00, 0x00, 0x00, 0xfc, 0x3f, 0xfc, 0x3f, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xe0, 0x01, 0xf0, 0x03, 0x38, 0x07, 0x1c, 0x0e, 0x1c, 0x0e, 0x38, 0x07, - 0xf0, 0x03, 0xe0, 0x01, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x0f, 0xfc, 0x0f, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0xf0, 0x00, - 0xf0, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x00, 0xf0, 0x00, - 0xf0, 0x00, 0x78, 0x00, 0x3c, 0x00, 0x1e, 0x00, 0x0f, 0x00, 0x07, 0x00, - 0x07, 0x38, 0x07, 0x38, 0x07, 0x38, 0x0f, 0x3c, 0xfe, 0x1f, 0xfc, 0x0f, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xff, 0x3f, 0xff, 0x3f, 0x0f, 0x00, 0x0f, 0x00, - 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x3f, 0xff, 0x3f, - 0x00, 0x3c, 0x00, 0x3c, 0x00, 0x3c, 0x00, 0x3c, 0x00, 0x3c, 0x00, 0x3c, - 0x00, 0x3c, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, - 0x0f, 0x20, 0x0f, 0x30, 0x0f, 0x38, 0x0f, 0x1c, 0x0f, 0x0e, 0x0f, 0x07, - 0x80, 0x03, 0xc0, 0x01, 0xe0, 0x00, 0x70, 0x00, 0x38, 0x00, 0x1c, 0x00, - 0x0e, 0x3e, 0x07, 0x7f, 0x83, 0xf3, 0xc1, 0xf1, 0x00, 0x38, 0x00, 0x1c, - 0x00, 0x0e, 0x00, 0x07, 0x80, 0xff, 0xc0, 0xff, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x0f, 0x00, - 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x20, 0x0f, 0x30, 0x0f, 0x38, 0x0f, 0x1c, - 0x0f, 0x0e, 0x0f, 0x07, 0x80, 0x03, 0xc0, 0x01, 0xe0, 0x00, 0x70, 0x00, - 0x38, 0x3c, 0x1c, 0x3e, 0x0e, 0x3f, 0x87, 0x3d, 0xc3, 0x3c, 0x61, 0x3c, - 0xf0, 0x3f, 0xf0, 0x3f, 0x00, 0x3c, 0x00, 0x3c, 0x00, 0x3c, 0x00, 0x3c, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0x00, 0x00, 0x00, 0x00, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xe0, 0x07, 0xe0, 0x07, 0xf0, 0x0f, 0xf0, 0x0f, 0xf0, 0x0f, 0xf0, 0x0f, - 0xf0, 0x0f, 0xf0, 0x0f, 0xe0, 0x07, 0xc0, 0x03, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x3c, 0x78, 0x1e, - 0x3c, 0x0f, 0x9e, 0x07, 0xcf, 0x03, 0xcf, 0x03, 0x9e, 0x07, 0x3c, 0x0f, - 0x78, 0x1e, 0xf0, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xcf, 0x03, 0x9e, 0x07, 0x3c, 0x0f, 0x78, 0x1e, 0xf0, 0x3c, 0xf0, 0x3c, - 0x78, 0x1e, 0x3c, 0x0f, 0x9e, 0x07, 0xcf, 0x03, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xc0, 0xc0, 0xc0, - 0x0c, 0x0c, 0x0c, 0x0c, 0xc0, 0xc0, 0xc0, 0xc0, 0x0c, 0x0c, 0x0c, 0x0c, - 0xc0, 0xc0, 0xc0, 0xc0, 0x0c, 0x0c, 0x0c, 0x0c, 0xc0, 0xc0, 0xc0, 0xc0, - 0x0c, 0x0c, 0x0c, 0x0c, 0xc0, 0xc0, 0xc0, 0xc0, 0x0c, 0x0c, 0x0c, 0x0c, - 0xc0, 0xc0, 0xc0, 0xc0, 0x0c, 0x0c, 0x0c, 0x0c, 0xc0, 0xc0, 0xc0, 0xc0, - 0x0c, 0x0c, 0x0c, 0x0c, 0xc0, 0xc0, 0xc0, 0xc0, 0x0c, 0x0c, 0x0c, 0x0c, - 0xcc, 0xcc, 0xcc, 0xcc, 0x33, 0x33, 0x33, 0x33, 0xcc, 0xcc, 0xcc, 0xcc, - 0x33, 0x33, 0x33, 0x33, 0xcc, 0xcc, 0xcc, 0xcc, 0x33, 0x33, 0x33, 0x33, - 0xcc, 0xcc, 0xcc, 0xcc, 0x33, 0x33, 0x33, 0x33, 0xcc, 0xcc, 0xcc, 0xcc, - 0x33, 0x33, 0x33, 0x33, 0xcc, 0xcc, 0xcc, 0xcc, 0x33, 0x33, 0x33, 0x33, - 0xcc, 0xcc, 0xcc, 0xcc, 0x33, 0x33, 0x33, 0x33, 0xcc, 0xcc, 0xcc, 0xcc, - 0x33, 0x33, 0x33, 0x33, 0xcf, 0xcf, 0xcf, 0xcf, 0xfc, 0xfc, 0xfc, 0xfc, - 0xcf, 0xcf, 0xcf, 0xcf, 0xfc, 0xfc, 0xfc, 0xfc, 0xcf, 0xcf, 0xcf, 0xcf, - 0xfc, 0xfc, 0xfc, 0xfc, 0xcf, 0xcf, 0xcf, 0xcf, 0xfc, 0xfc, 0xfc, 0xfc, - 0xcf, 0xcf, 0xcf, 0xcf, 0xfc, 0xfc, 0xfc, 0xfc, 0xcf, 0xcf, 0xcf, 0xcf, - 0xfc, 0xfc, 0xfc, 0xfc, 0xcf, 0xcf, 0xcf, 0xcf, 0xfc, 0xfc, 0xfc, 0xfc, - 0xcf, 0xcf, 0xcf, 0xcf, 0xfc, 0xfc, 0xfc, 0xfc, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xff, 0x03, 0xff, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xff, 0x03, 0xff, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xff, 0x03, 0xff, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xf0, 0x3c, 0xf0, 0x3c, - 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, - 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, - 0xff, 0x3c, 0xff, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, - 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, - 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xff, 0x3f, 0xff, 0x3f, 0xf0, 0x3c, 0xf0, 0x3c, - 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, - 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, - 0xf0, 0x3c, 0xf0, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xff, 0x03, 0xff, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xff, 0x03, 0xff, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xf0, 0x3c, 0xf0, 0x3c, - 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, - 0xf0, 0x3c, 0xf0, 0x3c, 0xff, 0x3c, 0xff, 0x3c, 0x00, 0x3c, 0x00, 0x3c, - 0xff, 0x3c, 0xff, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, - 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, - 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, - 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, - 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, - 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, - 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, - 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, - 0xf0, 0x3c, 0xf0, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xff, 0x3f, 0xff, 0x3f, 0x00, 0x3c, 0x00, 0x3c, 0xff, 0x3c, 0xff, 0x3c, - 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, - 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, - 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, - 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, - 0xf0, 0x3c, 0xf0, 0x3c, 0xff, 0x3c, 0xff, 0x3c, 0x00, 0x3c, 0x00, 0x3c, - 0xff, 0x3f, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, - 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, - 0xf0, 0x3c, 0xf0, 0x3c, 0xff, 0x3f, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xff, 0x03, 0xff, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xff, 0x03, 0xff, 0x03, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xff, 0x03, 0xff, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0xff, 0xc0, 0xff, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xff, 0xff, 0xff, 0xff, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xff, 0xff, 0xff, 0xff, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0xff, 0xc0, 0xff, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xff, 0xff, 0xff, 0xff, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0xff, 0xc0, 0xff, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0xff, 0xc0, 0xff, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, - 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, - 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0xfc, 0xf0, 0xfc, - 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, - 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, - 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, - 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, - 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0xfc, 0xf0, 0xfc, 0xf0, 0x00, 0xf0, 0x00, - 0xf0, 0xff, 0xf0, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xff, 0xf0, 0xff, - 0xf0, 0x00, 0xf0, 0x00, 0xf0, 0xfc, 0xf0, 0xfc, 0xf0, 0x3c, 0xf0, 0x3c, - 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, - 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, - 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, - 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, - 0xff, 0xfc, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, - 0xff, 0xfc, 0xff, 0xfc, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, - 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, - 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, - 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, - 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0xfc, 0xf0, 0xfc, - 0xf0, 0x00, 0xf0, 0x00, 0xf0, 0xfc, 0xf0, 0xfc, 0xf0, 0x3c, 0xf0, 0x3c, - 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, - 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, - 0xf0, 0x3c, 0xf0, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x3c, 0xf0, 0x3c, - 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, - 0xf0, 0x3c, 0xf0, 0x3c, 0xff, 0xfc, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, - 0xff, 0xfc, 0xff, 0xfc, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, - 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, - 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xff, 0xff, 0xff, 0xff, - 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, - 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, - 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xff, 0xff, 0xff, 0xff, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, - 0xff, 0xff, 0xff, 0xff, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x3c, 0xf0, 0x3c, - 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, - 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, - 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, - 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, - 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0xff, 0xf0, 0xff, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0xff, 0xc0, 0xff, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0xff, 0xc0, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xc0, 0xff, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0xff, 0xc0, 0xff, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xff, 0xf0, 0xff, - 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, - 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, - 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, - 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, - 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, - 0xff, 0xff, 0xff, 0xff, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, - 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, - 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, 0xf0, 0x3c, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xff, 0xff, 0xff, 0xff, - 0xc0, 0x03, 0xc0, 0x03, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xff, 0x03, 0xff, 0x03, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xc0, 0xff, 0xc0, 0xff, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xff, 0x00, - 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, - 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, - 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, - 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, - 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, - 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, - 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, - 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, - 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, - 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, - 0x00, 0xff, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x7c, 0x3c, 0xfe, 0x3e, 0xcf, 0x1f, 0x87, 0x0f, - 0x87, 0x03, 0x87, 0x03, 0x87, 0x03, 0x87, 0x03, 0x87, 0x03, 0x87, 0x03, - 0x87, 0x0f, 0xcf, 0x1f, 0xfe, 0x3d, 0xfc, 0x38, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x01, 0xfc, 0x03, - 0x0e, 0x07, 0x0e, 0x07, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x07, 0x8f, 0x07, - 0xcf, 0x03, 0xcf, 0x03, 0x8f, 0x07, 0x0f, 0x0f, 0x0f, 0x0e, 0x0f, 0x1c, - 0x0f, 0x1c, 0x0f, 0x1c, 0x0f, 0x1c, 0x0f, 0x1e, 0x0f, 0x0f, 0x0f, 0x07, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xff, 0x3f, 0xff, 0x3f, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, - 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, - 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, - 0x0f, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xff, 0x3f, 0xff, 0x3f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, - 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, - 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xff, 0x3f, 0xff, 0x3f, 0x0f, 0x38, 0x1e, 0x30, 0x3c, 0x00, 0x78, 0x00, - 0xf0, 0x00, 0xe0, 0x01, 0xc0, 0x03, 0xc0, 0x03, 0xe0, 0x01, 0xf0, 0x00, - 0x78, 0x00, 0x3c, 0x00, 0x1e, 0x30, 0x0f, 0x38, 0xff, 0x3f, 0xff, 0x3f, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xf8, 0x3f, 0xfc, 0x3f, 0xce, 0x03, 0x87, 0x03, 0x87, 0x03, 0x87, 0x03, - 0x87, 0x03, 0x87, 0x03, 0x87, 0x03, 0x87, 0x03, 0x87, 0x03, 0xce, 0x01, - 0xfc, 0x00, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, - 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x1c, 0x3c, 0x1e, 0xfc, 0x0f, 0xfc, 0x07, - 0x3c, 0x00, 0x3c, 0x00, 0x3c, 0x00, 0x1c, 0x00, 0x0f, 0x00, 0x07, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x78, 0x38, 0xfc, 0x3c, 0xcf, 0x0f, 0xc7, 0x07, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xfc, 0x3f, 0xfc, 0x3f, 0xc0, 0x03, 0xc0, 0x03, - 0xe0, 0x07, 0xf0, 0x0f, 0x38, 0x1c, 0x1c, 0x38, 0x1c, 0x38, 0x1c, 0x38, - 0x1c, 0x38, 0x38, 0x1c, 0xf0, 0x0f, 0xe0, 0x07, 0xc0, 0x03, 0xc0, 0x03, - 0xfc, 0x3f, 0xfc, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x01, 0xf0, 0x03, - 0x38, 0x07, 0x1c, 0x0e, 0x0e, 0x1c, 0x0e, 0x1c, 0x07, 0x38, 0x07, 0x38, - 0xff, 0x3f, 0xff, 0x3f, 0x07, 0x38, 0x07, 0x38, 0x0e, 0x1c, 0x0e, 0x1c, - 0x1c, 0x0e, 0x38, 0x07, 0xf0, 0x03, 0xe0, 0x01, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x03, 0xf8, 0x07, - 0x3c, 0x0f, 0x1e, 0x1e, 0x0f, 0x3c, 0x07, 0x38, 0x07, 0x38, 0x07, 0x38, - 0x07, 0x38, 0x07, 0x38, 0x0e, 0x1c, 0x1e, 0x1e, 0x1c, 0x0e, 0x3c, 0x0f, - 0x38, 0x07, 0x38, 0x07, 0x38, 0x07, 0x38, 0x07, 0x3f, 0x3f, 0x3f, 0x3f, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x3f, 0xc0, 0x3f, 0xe0, 0x00, 0xe0, 0x00, 0xc0, 0x01, 0x80, 0x03, - 0x00, 0x07, 0x00, 0x0f, 0xe0, 0x1f, 0xf0, 0x3f, 0x38, 0x3c, 0x1c, 0x38, - 0x1c, 0x38, 0x1c, 0x38, 0x1c, 0x38, 0x1c, 0x38, 0x1c, 0x38, 0x38, 0x1c, - 0xf0, 0x0f, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xf8, 0x1f, 0xfc, 0x3f, 0xce, 0xf3, 0xcf, 0xf3, - 0xcf, 0xf3, 0xcf, 0xf3, 0xcf, 0xf3, 0xce, 0xf3, 0xfc, 0x3f, 0xf8, 0x1f, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0xe0, 0x00, 0x70, 0x00, 0x38, 0x00, 0x1c, 0xf8, 0x1f, 0xfc, 0x3f, - 0x0e, 0x77, 0x8f, 0xf3, 0xcf, 0xf3, 0xef, 0xf1, 0xff, 0xf0, 0xff, 0x70, - 0xfc, 0x3f, 0xfc, 0x1f, 0x1c, 0x00, 0x0c, 0x00, 0x0e, 0x00, 0x07, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x0f, 0xc0, 0x0f, 0xe0, 0x01, 0xf0, 0x00, 0x78, 0x00, 0x3c, 0x00, - 0x3c, 0x00, 0x3c, 0x00, 0xfc, 0x0f, 0xfc, 0x0f, 0x3c, 0x00, 0x3c, 0x00, - 0x3c, 0x00, 0x3c, 0x00, 0x3c, 0x00, 0x78, 0x00, 0xf0, 0x00, 0xe0, 0x01, - 0xc0, 0x0f, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x0f, 0xfe, 0x1f, - 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, - 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, - 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xff, 0x3f, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xff, 0x3f, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xff, 0x3f, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xfc, 0x3f, 0xfc, 0x3f, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0xf0, 0x00, - 0xe0, 0x01, 0xc0, 0x03, 0x80, 0x07, 0x00, 0x0f, 0x00, 0x1e, 0x00, 0x1e, - 0x00, 0x0f, 0x80, 0x07, 0xc0, 0x03, 0xe0, 0x01, 0xf0, 0x00, 0x70, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xfc, 0x3f, 0xfc, 0x3f, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x0e, 0x00, 0x0f, 0x80, 0x07, 0xc0, 0x03, 0xe0, 0x01, 0xf0, 0x00, - 0x78, 0x00, 0x78, 0x00, 0xf0, 0x00, 0xe0, 0x01, 0xc0, 0x03, 0x80, 0x07, - 0x00, 0x0f, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x3f, 0xfc, 0x3f, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x3f, 0x80, 0x7f, 0xc0, 0xf3, 0xc0, 0xf3, 0xc0, 0xf3, 0xc0, 0xf3, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xcf, 0x03, 0xcf, 0x03, 0xcf, 0x03, 0xcf, 0x03, - 0xcf, 0x03, 0xcf, 0x03, 0xfe, 0x01, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0xc0, 0x03, 0xc0, 0x03, 0x80, 0x01, - 0x00, 0x00, 0x00, 0x00, 0xfc, 0x3f, 0xfc, 0x3f, 0x00, 0x00, 0x00, 0x00, - 0x80, 0x01, 0xc0, 0x03, 0xc0, 0x03, 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x78, 0x38, 0xfc, 0x3c, 0xcf, 0x0f, 0x87, 0x07, 0x00, 0x00, 0x00, 0x00, - 0x78, 0x38, 0xfc, 0x3c, 0xcf, 0x0f, 0x87, 0x07, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xe0, 0x01, 0xf0, 0x03, 0x38, 0x07, 0x1c, 0x0e, 0x1c, 0x0e, 0x38, 0x07, - 0xf0, 0x03, 0xe0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xc0, 0x03, 0xc0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0xff, 0x00, 0xff, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, - 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, - 0x07, 0x0f, 0x0f, 0x0f, 0x1e, 0x0f, 0x3c, 0x0f, 0x78, 0x0f, 0xf0, 0x0f, - 0xe0, 0x0f, 0xc0, 0x0f, 0x80, 0x0f, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xcf, 0x03, 0xef, 0x07, 0x3c, 0x0f, 0x3c, 0x0f, - 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, 0x3c, 0x0f, - 0x3c, 0x0f, 0x3c, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x00, 0xfc, 0x00, - 0xce, 0x01, 0xc7, 0x03, 0xe0, 0x00, 0x70, 0x00, 0x38, 0x00, 0x1c, 0x00, - 0x0e, 0x03, 0x07, 0x03, 0xff, 0x03, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f, - 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f, - 0xfc, 0x0f, 0xfc, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, -}; - -static const txt_font_t large_font = -{ - "large", - large_font_data, - 16, - 32, -}; diff --git a/games/NXDoom/textscreen/fonts/large.png b/games/NXDoom/textscreen/fonts/large.png deleted file mode 100644 index 3827ab599..000000000 Binary files a/games/NXDoom/textscreen/fonts/large.png and /dev/null differ diff --git a/games/NXDoom/textscreen/fonts/normal.h b/games/NXDoom/textscreen/fonts/normal.h deleted file mode 100644 index 4ecaf3787..000000000 --- a/games/NXDoom/textscreen/fonts/normal.h +++ /dev/null @@ -1,367 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/textscreen/fonts/normal.h - * - * SPDX-License-Identifer: GPLv2 - * - * Font data generated from normal.png; do not edit. Please see - * textscreen/fonts/README for copyright information. - * - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -static const uint8_t normal_font_data[] = -{ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x81, 0xa5, 0x81, 0x81, 0xbd, - 0x99, 0x81, 0x81, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0xff, - 0xdb, 0xff, 0xff, 0xc3, 0xe7, 0xff, 0xff, 0x7e, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x36, 0x7f, 0x7f, 0x7f, 0x7f, 0x3e, 0x1c, 0x08, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x1c, 0x3e, 0x7f, - 0x3e, 0x1c, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, - 0x3c, 0x3c, 0xe7, 0xe7, 0xe7, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x18, 0x3c, 0x7e, 0xff, 0xff, 0x7e, 0x18, 0x18, 0x3c, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x3c, - 0x3c, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xe7, 0xc3, 0xc3, 0xe7, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x66, 0x42, 0x42, 0x66, 0x3c, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc3, 0x99, 0xbd, - 0xbd, 0x99, 0xc3, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x78, 0x70, - 0x58, 0x4c, 0x1e, 0x33, 0x33, 0x33, 0x33, 0x1e, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x3c, 0x66, 0x66, 0x66, 0x66, 0x3c, 0x18, 0x7e, 0x18, 0x18, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xcc, 0xfc, 0x0c, 0x0c, 0x0c, - 0x0c, 0x0e, 0x0f, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xc6, - 0xfe, 0xc6, 0xc6, 0xc6, 0xc6, 0xe6, 0xe7, 0x67, 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x18, 0x18, 0xdb, 0x3c, 0xe7, 0x3c, 0xdb, 0x18, 0x18, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x7f, 0x1f, - 0x0f, 0x07, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x60, 0x70, - 0x78, 0x7c, 0x7f, 0x7c, 0x78, 0x70, 0x60, 0x40, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x18, 0x3c, 0x7e, 0x18, 0x18, 0x18, 0x7e, 0x3c, 0x18, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, - 0x66, 0x00, 0x66, 0x66, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xdb, - 0xdb, 0xdb, 0xde, 0xd8, 0xd8, 0xd8, 0xd8, 0xd8, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x3e, 0x63, 0x06, 0x1c, 0x36, 0x63, 0x63, 0x36, 0x1c, 0x30, 0x63, - 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x7f, 0x7f, 0x7f, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x3c, - 0x7e, 0x18, 0x18, 0x18, 0x7e, 0x3c, 0x18, 0x7e, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x18, 0x3c, 0x7e, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, - 0x18, 0x7e, 0x3c, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x18, 0x30, 0x7f, 0x30, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x06, 0x7f, 0x06, 0x0c, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x03, - 0x03, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x24, 0x66, 0xff, 0x66, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x08, 0x1c, 0x1c, 0x3e, 0x3e, 0x7f, 0x7f, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x7f, 0x3e, 0x3e, - 0x1c, 0x1c, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x18, 0x3c, 0x3c, 0x3c, 0x18, 0x18, 0x18, 0x00, 0x18, 0x18, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x66, 0x66, 0x66, 0x24, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, - 0x36, 0x7f, 0x36, 0x36, 0x36, 0x7f, 0x36, 0x36, 0x00, 0x00, 0x00, 0x00, - 0x18, 0x18, 0x3e, 0x63, 0x43, 0x03, 0x3e, 0x60, 0x60, 0x61, 0x63, 0x3e, - 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x43, 0x63, 0x30, 0x18, - 0x0c, 0x06, 0x63, 0x61, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x36, - 0x36, 0x1c, 0x6e, 0x3b, 0x33, 0x33, 0x33, 0x6e, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x0c, 0x0c, 0x0c, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x18, 0x0c, 0x0c, 0x0c, 0x0c, - 0x0c, 0x0c, 0x18, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x18, - 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x18, 0x0c, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x66, 0x3c, 0xff, 0x3c, 0x66, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x7e, - 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x0c, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x40, 0x60, 0x30, 0x18, 0x0c, 0x06, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x3c, 0x66, 0xc3, 0xc3, 0xdb, 0xdb, 0xc3, 0xc3, 0x66, 0x3c, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x1c, 0x1e, 0x18, 0x18, 0x18, - 0x18, 0x18, 0x18, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x63, - 0x60, 0x30, 0x18, 0x0c, 0x06, 0x03, 0x63, 0x7f, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x3e, 0x63, 0x60, 0x60, 0x3c, 0x60, 0x60, 0x60, 0x63, 0x3e, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x38, 0x3c, 0x36, 0x33, 0x7f, - 0x30, 0x30, 0x30, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x03, - 0x03, 0x03, 0x3f, 0x60, 0x60, 0x60, 0x63, 0x3e, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x1c, 0x06, 0x03, 0x03, 0x3f, 0x63, 0x63, 0x63, 0x63, 0x3e, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x63, 0x60, 0x60, 0x30, 0x18, - 0x0c, 0x0c, 0x0c, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x63, - 0x63, 0x63, 0x3e, 0x63, 0x63, 0x63, 0x63, 0x3e, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x3e, 0x63, 0x63, 0x63, 0x7e, 0x60, 0x60, 0x60, 0x30, 0x1e, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, - 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x18, 0x18, 0x00, 0x00, 0x00, 0x18, 0x18, 0x0c, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x60, 0x30, 0x18, 0x0c, 0x06, 0x0c, 0x18, 0x30, 0x60, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x00, - 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, - 0x0c, 0x18, 0x30, 0x60, 0x30, 0x18, 0x0c, 0x06, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x3e, 0x63, 0x63, 0x30, 0x18, 0x18, 0x18, 0x00, 0x18, 0x18, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x63, 0x63, 0x7b, 0x7b, - 0x7b, 0x3b, 0x03, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x1c, - 0x36, 0x63, 0x63, 0x7f, 0x63, 0x63, 0x63, 0x63, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x3f, 0x66, 0x66, 0x66, 0x3e, 0x66, 0x66, 0x66, 0x66, 0x3f, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x66, 0x43, 0x03, 0x03, 0x03, - 0x03, 0x43, 0x66, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x36, - 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x36, 0x1f, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x7f, 0x66, 0x46, 0x16, 0x1e, 0x16, 0x06, 0x46, 0x66, 0x7f, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x66, 0x46, 0x16, 0x1e, 0x16, - 0x06, 0x06, 0x06, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x66, - 0x43, 0x03, 0x03, 0x7b, 0x63, 0x63, 0x66, 0x5c, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x63, 0x63, 0x63, 0x63, 0x7f, 0x63, 0x63, 0x63, 0x63, 0x63, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x18, 0x18, 0x18, 0x18, 0x18, - 0x18, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x30, - 0x30, 0x30, 0x30, 0x30, 0x33, 0x33, 0x33, 0x1e, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x67, 0x66, 0x66, 0x36, 0x1e, 0x1e, 0x36, 0x66, 0x66, 0x67, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x06, 0x06, 0x06, 0x06, 0x06, - 0x06, 0x46, 0x66, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc3, 0xe7, - 0xff, 0xff, 0xdb, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x63, 0x67, 0x6f, 0x7f, 0x7b, 0x73, 0x63, 0x63, 0x63, 0x63, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x63, 0x63, 0x63, 0x63, 0x63, - 0x63, 0x63, 0x63, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x66, - 0x66, 0x66, 0x3e, 0x06, 0x06, 0x06, 0x06, 0x0f, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x3e, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x6b, 0x7b, 0x3e, - 0x30, 0x70, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x66, 0x66, 0x66, 0x3e, 0x36, - 0x66, 0x66, 0x66, 0x67, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x63, - 0x63, 0x06, 0x1c, 0x30, 0x60, 0x63, 0x63, 0x3e, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0xff, 0xdb, 0x99, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, - 0x63, 0x63, 0x63, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc3, 0xc3, - 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0x66, 0x3c, 0x18, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xdb, 0xdb, 0xff, 0x66, 0x66, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc3, 0xc3, 0x66, 0x3c, 0x18, 0x18, - 0x3c, 0x66, 0xc3, 0xc3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc3, 0xc3, - 0xc3, 0x66, 0x3c, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0xff, 0xc3, 0x61, 0x30, 0x18, 0x0c, 0x06, 0x83, 0xc3, 0xff, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, - 0x0c, 0x0c, 0x0c, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, - 0x03, 0x07, 0x0e, 0x1c, 0x38, 0x70, 0x60, 0x40, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x3c, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x3c, - 0x00, 0x00, 0x00, 0x00, 0x08, 0x1c, 0x36, 0x63, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, - 0x0c, 0x0c, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x30, 0x3e, - 0x33, 0x33, 0x33, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x06, - 0x06, 0x1e, 0x36, 0x66, 0x66, 0x66, 0x66, 0x3e, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x63, 0x03, 0x03, 0x03, 0x63, 0x3e, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x30, 0x30, 0x3c, 0x36, 0x33, - 0x33, 0x33, 0x33, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x3e, 0x63, 0x7f, 0x03, 0x03, 0x63, 0x3e, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x1c, 0x36, 0x26, 0x06, 0x0f, 0x06, 0x06, 0x06, 0x06, 0x0f, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6e, 0x33, 0x33, - 0x33, 0x33, 0x33, 0x3e, 0x30, 0x33, 0x1e, 0x00, 0x00, 0x00, 0x07, 0x06, - 0x06, 0x36, 0x6e, 0x66, 0x66, 0x66, 0x66, 0x67, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x18, 0x18, 0x00, 0x1c, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x60, 0x00, 0x70, 0x60, 0x60, - 0x60, 0x60, 0x60, 0x60, 0x66, 0x66, 0x3c, 0x00, 0x00, 0x00, 0x07, 0x06, - 0x06, 0x66, 0x36, 0x1e, 0x1e, 0x36, 0x66, 0x67, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x1c, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x67, 0xff, 0xdb, - 0xdb, 0xdb, 0xdb, 0xdb, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x3b, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x63, 0x63, 0x63, 0x63, 0x63, 0x3e, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3b, 0x66, 0x66, - 0x66, 0x66, 0x66, 0x3e, 0x06, 0x06, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x6e, 0x33, 0x33, 0x33, 0x33, 0x33, 0x3e, 0x30, 0x30, 0x78, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x3b, 0x6e, 0x66, 0x06, 0x06, 0x06, 0x0f, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x63, 0x06, - 0x1c, 0x30, 0x63, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x0c, - 0x0c, 0x3f, 0x0c, 0x0c, 0x0c, 0x0c, 0x6c, 0x38, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x6e, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc3, 0xc3, 0xc3, - 0xc3, 0x66, 0x3c, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0xc3, 0xc3, 0xc3, 0xdb, 0xdb, 0xff, 0x66, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0xc3, 0x66, 0x3c, 0x18, 0x3c, 0x66, 0xc3, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x63, 0x63, 0x63, - 0x63, 0x63, 0x63, 0x7e, 0x60, 0x30, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x7f, 0x33, 0x18, 0x0c, 0x06, 0x63, 0x7f, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x70, 0x18, 0x18, 0x18, 0x0e, 0x18, 0x18, 0x18, 0x18, 0x70, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x00, 0x18, - 0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x18, - 0x18, 0x18, 0x70, 0x18, 0x18, 0x18, 0x18, 0x0e, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x6e, 0x3b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x1c, 0x36, 0x63, - 0x63, 0x63, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x66, - 0x43, 0x03, 0x03, 0x03, 0x43, 0x66, 0x3c, 0x30, 0x60, 0x3e, 0x00, 0x00, - 0x00, 0x00, 0x33, 0x00, 0x00, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x6e, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x18, 0x0c, 0x00, 0x3e, 0x63, 0x7f, - 0x03, 0x03, 0x63, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x1c, 0x36, - 0x00, 0x1e, 0x30, 0x3e, 0x33, 0x33, 0x33, 0x6e, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x33, 0x00, 0x00, 0x1e, 0x30, 0x3e, 0x33, 0x33, 0x33, 0x6e, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x0c, 0x18, 0x00, 0x1e, 0x30, 0x3e, - 0x33, 0x33, 0x33, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x36, 0x1c, - 0x00, 0x1e, 0x30, 0x3e, 0x33, 0x33, 0x33, 0x6e, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x3c, 0x66, 0x06, 0x06, 0x66, 0x3c, 0x30, 0x60, - 0x3c, 0x00, 0x00, 0x00, 0x00, 0x08, 0x1c, 0x36, 0x00, 0x3e, 0x63, 0x7f, - 0x03, 0x03, 0x63, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x63, 0x00, - 0x00, 0x3e, 0x63, 0x7f, 0x03, 0x03, 0x63, 0x3e, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x06, 0x0c, 0x18, 0x00, 0x3e, 0x63, 0x7f, 0x03, 0x03, 0x63, 0x3e, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x66, 0x00, 0x00, 0x1c, 0x18, 0x18, - 0x18, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x3c, 0x66, - 0x00, 0x1c, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x06, 0x0c, 0x18, 0x00, 0x1c, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x63, 0x00, 0x08, 0x1c, 0x36, 0x63, 0x63, - 0x7f, 0x63, 0x63, 0x63, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x36, 0x1c, 0x00, - 0x1c, 0x36, 0x63, 0x63, 0x7f, 0x63, 0x63, 0x63, 0x00, 0x00, 0x00, 0x00, - 0x18, 0x0c, 0x06, 0x00, 0x7f, 0x66, 0x06, 0x3e, 0x06, 0x06, 0x66, 0x7f, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x76, 0xdc, 0xd8, - 0x7e, 0x1b, 0x3b, 0xee, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0x36, - 0x33, 0x33, 0x7f, 0x33, 0x33, 0x33, 0x33, 0x73, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x08, 0x1c, 0x36, 0x00, 0x3e, 0x63, 0x63, 0x63, 0x63, 0x63, 0x3e, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x63, 0x00, 0x00, 0x3e, 0x63, 0x63, - 0x63, 0x63, 0x63, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x0c, 0x18, - 0x00, 0x3e, 0x63, 0x63, 0x63, 0x63, 0x63, 0x3e, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x0c, 0x1e, 0x33, 0x00, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x6e, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x0c, 0x18, 0x00, 0x33, 0x33, 0x33, - 0x33, 0x33, 0x33, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x63, 0x00, - 0x00, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x7e, 0x60, 0x30, 0x1e, 0x00, - 0x00, 0x63, 0x00, 0x3e, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x3e, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x63, 0x00, 0x63, 0x63, 0x63, 0x63, 0x63, - 0x63, 0x63, 0x63, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x7e, - 0xc3, 0x03, 0x03, 0x03, 0xc3, 0x7e, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x1c, 0x36, 0x26, 0x06, 0x0f, 0x06, 0x06, 0x06, 0x06, 0x67, 0x3f, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc3, 0x66, 0x3c, 0x18, 0xff, 0x18, - 0xff, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x66, 0x66, - 0x3e, 0x46, 0x66, 0xf6, 0x66, 0x66, 0x66, 0xcf, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x70, 0xd8, 0x18, 0x18, 0x18, 0x7e, 0x18, 0x18, 0x18, 0x18, 0x18, - 0x1b, 0x0e, 0x00, 0x00, 0x00, 0x18, 0x0c, 0x06, 0x00, 0x1e, 0x30, 0x3e, - 0x33, 0x33, 0x33, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x18, 0x0c, - 0x00, 0x1c, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x18, 0x0c, 0x06, 0x00, 0x3e, 0x63, 0x63, 0x63, 0x63, 0x63, 0x3e, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x0c, 0x06, 0x00, 0x33, 0x33, 0x33, - 0x33, 0x33, 0x33, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6e, 0x3b, - 0x00, 0x3b, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x00, 0x00, 0x00, 0x00, - 0x6e, 0x3b, 0x00, 0x63, 0x67, 0x6f, 0x7f, 0x7b, 0x73, 0x63, 0x63, 0x63, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x36, 0x36, 0x7c, 0x00, 0x7e, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x36, 0x36, - 0x1c, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x0c, 0x0c, 0x00, 0x0c, 0x0c, 0x06, 0x03, 0x63, 0x63, 0x3e, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x03, - 0x03, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x7f, 0x60, 0x60, 0x60, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x03, 0x03, 0x43, 0x63, 0x33, 0x18, 0x0c, 0x06, 0x73, 0xd9, 0x60, - 0x30, 0xf8, 0x00, 0x00, 0x00, 0x03, 0x03, 0x43, 0x63, 0x33, 0x18, 0x0c, - 0x66, 0x73, 0x69, 0x7c, 0x60, 0x60, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, - 0x00, 0x18, 0x18, 0x18, 0x3c, 0x3c, 0x3c, 0x18, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x6c, 0x36, 0x1b, 0x36, 0x6c, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1b, 0x36, 0x6c, - 0x36, 0x1b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x88, 0x22, 0x88, 0x22, - 0x88, 0x22, 0x88, 0x22, 0x88, 0x22, 0x88, 0x22, 0x88, 0x22, 0x88, 0x22, - 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, - 0xaa, 0x55, 0xaa, 0x55, 0xbb, 0xee, 0xbb, 0xee, 0xbb, 0xee, 0xbb, 0xee, - 0xbb, 0xee, 0xbb, 0xee, 0xbb, 0xee, 0xbb, 0xee, 0x18, 0x18, 0x18, 0x18, - 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, - 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x1f, 0x18, 0x18, 0x18, 0x18, - 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x1f, 0x18, 0x1f, - 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x6c, 0x6c, 0x6c, 0x6c, - 0x6c, 0x6c, 0x6c, 0x6f, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x6c, 0x6c, 0x6c, 0x6c, - 0x6c, 0x6c, 0x6c, 0x6c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x18, 0x1f, - 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x6c, 0x6c, 0x6c, 0x6c, - 0x6c, 0x6f, 0x60, 0x6f, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, - 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, - 0x6c, 0x6c, 0x6c, 0x6c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x60, 0x6f, - 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, - 0x6c, 0x6f, 0x60, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x7f, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x1f, 0x18, 0x1f, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x1f, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, - 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xf8, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xff, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0xff, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, - 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xf8, 0x18, 0x18, 0x18, 0x18, - 0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18, - 0x18, 0x18, 0x18, 0xff, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, - 0x18, 0x18, 0x18, 0x18, 0x18, 0xf8, 0x18, 0xf8, 0x18, 0x18, 0x18, 0x18, - 0x18, 0x18, 0x18, 0x18, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0xec, - 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, - 0x6c, 0xec, 0x0c, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x0c, 0xec, 0x6c, 0x6c, 0x6c, 0x6c, - 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0xef, 0x00, 0xff, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0xff, 0x00, 0xef, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, - 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0xec, 0x0c, 0xec, 0x6c, 0x6c, 0x6c, 0x6c, - 0x6c, 0x6c, 0x6c, 0x6c, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0xff, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6c, 0x6c, 0x6c, 0x6c, - 0x6c, 0xef, 0x00, 0xef, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, - 0x18, 0x18, 0x18, 0x18, 0x18, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0xff, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0xff, 0x00, 0xff, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x6c, 0x6c, 0x6c, 0x6c, - 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0xfc, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18, - 0x18, 0xf8, 0x18, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x18, 0xf8, 0x18, 0x18, 0x18, 0x18, - 0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, - 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, - 0x6c, 0x6c, 0x6c, 0xff, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, - 0x18, 0x18, 0x18, 0x18, 0x18, 0xff, 0x18, 0xff, 0x18, 0x18, 0x18, 0x18, - 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x1f, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0xf8, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0f, 0x0f, 0x0f, 0x0f, - 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, - 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, - 0xf0, 0xf0, 0xf0, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x6e, 0x3b, 0x1b, 0x1b, 0x1b, 0x3b, 0x6e, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x1e, 0x33, 0x33, 0x33, 0x1b, 0x33, 0x63, 0x63, 0x63, 0x33, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x63, 0x63, 0x03, 0x03, 0x03, - 0x03, 0x03, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x7f, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x7f, 0x63, 0x06, 0x0c, 0x18, 0x0c, 0x06, 0x63, 0x7f, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x1b, 0x1b, - 0x1b, 0x1b, 0x1b, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x66, 0x66, 0x66, 0x66, 0x66, 0x3e, 0x06, 0x06, 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x6e, 0x3b, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x18, 0x3c, 0x66, 0x66, - 0x66, 0x3c, 0x18, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, - 0x36, 0x63, 0x63, 0x7f, 0x63, 0x63, 0x36, 0x1c, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x1c, 0x36, 0x63, 0x63, 0x63, 0x36, 0x36, 0x36, 0x36, 0x77, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x0c, 0x18, 0x30, 0x7c, 0x66, - 0x66, 0x66, 0x66, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x7e, 0xdb, 0xdb, 0xdb, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0xc0, 0x60, 0x7e, 0xdb, 0xdb, 0xcf, 0x7e, 0x06, 0x03, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x0c, 0x06, 0x06, 0x3e, 0x06, - 0x06, 0x06, 0x0c, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, - 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x7f, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x7e, 0x18, - 0x18, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, - 0x18, 0x30, 0x60, 0x30, 0x18, 0x0c, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x30, 0x18, 0x0c, 0x06, 0x0c, 0x18, 0x30, 0x00, 0x7e, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0xd8, 0xd8, 0x18, 0x18, 0x18, - 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, - 0x18, 0x18, 0x18, 0x18, 0x1b, 0x1b, 0x1b, 0x0e, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x7e, 0x00, 0x18, 0x18, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6e, 0x3b, 0x00, - 0x6e, 0x3b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x36, 0x36, - 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x30, 0x30, - 0x30, 0x30, 0x30, 0x37, 0x36, 0x36, 0x3c, 0x38, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x1b, 0x36, 0x36, 0x36, 0x36, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x1b, 0x0c, 0x06, 0x13, 0x1f, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x3e, 0x3e, 0x3e, 0x3e, 0x3e, 0x3e, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, -}; - -static const txt_font_t normal_font = -{ - "normal", - normal_font_data, - 8, - 16, -}; diff --git a/games/NXDoom/textscreen/fonts/normal.png b/games/NXDoom/textscreen/fonts/normal.png deleted file mode 100644 index 884bb98d4..000000000 Binary files a/games/NXDoom/textscreen/fonts/normal.png and /dev/null differ diff --git a/games/NXDoom/textscreen/fonts/small.h b/games/NXDoom/textscreen/fonts/small.h deleted file mode 100644 index b7dd28d22..000000000 --- a/games/NXDoom/textscreen/fonts/small.h +++ /dev/null @@ -1,111 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/textscreen/fonts/small.h - * - * SPDX-License-Identifer: GPLv2 - * - * Font data generated from small.png; do not edit. Please see - * textscreen/fonts/README for copyright information. - * - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -static const uint8_t small_font_data[] = -{ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x4e, 0x00, 0xf6, 0xf5, 0xb1, 0x6f, - 0x00, 0xea, 0x04, 0x00, 0x00, 0xe4, 0x04, 0x00, 0x40, 0xaa, 0xe4, 0x00, - 0x40, 0xee, 0xe4, 0x00, 0x00, 0x60, 0x06, 0x00, 0xff, 0x9f, 0xf9, 0xff, - 0x00, 0x96, 0x69, 0x00, 0xff, 0x69, 0x96, 0xff, 0xe0, 0x74, 0x75, 0x00, - 0x60, 0x69, 0x6f, 0x06, 0xc0, 0x44, 0x74, 0x03, 0xe0, 0xaa, 0xba, 0x03, - 0x22, 0x27, 0x27, 0x22, 0x10, 0x73, 0x13, 0x00, 0x80, 0xec, 0x8c, 0x00, - 0x40, 0x4e, 0xe4, 0x04, 0xa0, 0xaa, 0xa0, 0x00, 0xf0, 0xb9, 0xaa, 0x00, - 0x16, 0x96, 0x86, 0x06, 0x00, 0x00, 0xff, 0x00, 0x40, 0x4e, 0xe4, 0xf4, - 0x40, 0x4e, 0x44, 0x04, 0x40, 0x44, 0xe4, 0x04, 0x20, 0xf4, 0x24, 0x00, - 0x40, 0xf2, 0x42, 0x00, 0x00, 0x10, 0x07, 0x00, 0x00, 0xf5, 0x05, 0x00, - 0x00, 0x72, 0x0f, 0x00, 0x00, 0x7f, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x20, 0x22, 0x02, 0x02, 0x50, 0x05, 0x00, 0x00, 0x50, 0x57, 0x75, 0x05, - 0x22, 0x25, 0x54, 0x22, 0x50, 0x24, 0x12, 0x05, 0x52, 0x52, 0x35, 0x06, - 0x20, 0x02, 0x00, 0x00, 0x40, 0x22, 0x22, 0x04, 0x10, 0x22, 0x22, 0x01, - 0x50, 0x72, 0x52, 0x00, 0x20, 0x72, 0x22, 0x00, 0x00, 0x00, 0x20, 0x12, - 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0x20, 0x02, 0x40, 0x24, 0x12, 0x01, - 0x20, 0x75, 0x55, 0x02, 0x20, 0x23, 0x22, 0x07, 0x20, 0x45, 0x12, 0x07, - 0x70, 0x24, 0x54, 0x02, 0x40, 0x56, 0x47, 0x04, 0x70, 0x31, 0x54, 0x02, - 0x60, 0x31, 0x55, 0x02, 0x70, 0x44, 0x22, 0x02, 0x20, 0x25, 0x55, 0x02, - 0x20, 0x55, 0x46, 0x03, 0x00, 0x02, 0x20, 0x00, 0x00, 0x02, 0x20, 0x01, - 0x00, 0x24, 0x21, 0x04, 0x00, 0x07, 0x07, 0x00, 0x00, 0x21, 0x24, 0x01, - 0x20, 0x45, 0x02, 0x02, 0x20, 0x55, 0x11, 0x06, 0x20, 0x55, 0x57, 0x05, - 0x30, 0x35, 0x55, 0x03, 0x20, 0x15, 0x51, 0x02, 0x30, 0x55, 0x55, 0x03, - 0x70, 0x71, 0x11, 0x07, 0x70, 0x71, 0x11, 0x01, 0x20, 0x15, 0x55, 0x02, - 0x50, 0x75, 0x55, 0x05, 0x70, 0x22, 0x22, 0x07, 0x40, 0x44, 0x54, 0x02, - 0x50, 0x35, 0x55, 0x05, 0x10, 0x11, 0x11, 0x07, 0x50, 0x57, 0x55, 0x05, - 0x40, 0x75, 0x57, 0x01, 0x20, 0x55, 0x55, 0x02, 0x30, 0x55, 0x13, 0x01, - 0x20, 0x55, 0x35, 0x06, 0x30, 0x55, 0x53, 0x05, 0x20, 0x25, 0x54, 0x02, - 0x70, 0x22, 0x22, 0x02, 0x50, 0x55, 0x55, 0x07, 0x50, 0x55, 0x55, 0x02, - 0x50, 0x55, 0x75, 0x05, 0x50, 0x25, 0x55, 0x05, 0x50, 0x25, 0x22, 0x02, - 0x70, 0x24, 0x12, 0x07, 0x60, 0x22, 0x22, 0x06, 0x10, 0x21, 0x42, 0x04, - 0x30, 0x22, 0x22, 0x03, 0x20, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, - 0x10, 0x02, 0x00, 0x00, 0x00, 0x43, 0x56, 0x06, 0x10, 0x31, 0x55, 0x03, - 0x00, 0x16, 0x11, 0x06, 0x40, 0x64, 0x55, 0x06, 0x00, 0x52, 0x17, 0x06, - 0x40, 0x72, 0x22, 0x02, 0x00, 0x56, 0x65, 0x34, 0x10, 0x31, 0x55, 0x05, - 0x20, 0x30, 0x22, 0x07, 0x40, 0x60, 0x44, 0x34, 0x10, 0x51, 0x53, 0x05, - 0x20, 0x22, 0x22, 0x02, 0x00, 0x75, 0x55, 0x05, 0x00, 0x53, 0x55, 0x05, - 0x00, 0x52, 0x55, 0x02, 0x00, 0x53, 0x35, 0x11, 0x00, 0x56, 0x65, 0x44, - 0x00, 0x16, 0x11, 0x01, 0x00, 0x16, 0x42, 0x03, 0x20, 0x72, 0x22, 0x02, - 0x00, 0x55, 0x55, 0x07, 0x00, 0x55, 0x55, 0x02, 0x00, 0x55, 0x75, 0x05, - 0x00, 0x55, 0x52, 0x05, 0x00, 0x55, 0x65, 0x34, 0x00, 0x47, 0x12, 0x07, - 0x24, 0x12, 0x22, 0x04, 0x22, 0x02, 0x22, 0x02, 0x21, 0x42, 0x22, 0x01, - 0xa0, 0x05, 0x00, 0x00, 0x20, 0x55, 0x75, 0x00, 0x20, 0x15, 0x51, 0x32, - 0x05, 0x55, 0x55, 0x07, 0x12, 0x52, 0x17, 0x06, 0xa4, 0x43, 0x56, 0x06, - 0x05, 0x43, 0x56, 0x06, 0x42, 0x43, 0x56, 0x06, 0x52, 0x42, 0x56, 0x06, - 0x00, 0x16, 0x11, 0x36, 0x52, 0x52, 0x17, 0x06, 0x05, 0x52, 0x17, 0x06, - 0x42, 0x52, 0x17, 0x06, 0x50, 0x30, 0x22, 0x07, 0x52, 0x30, 0x22, 0x07, - 0x42, 0x30, 0x22, 0x07, 0x05, 0x52, 0x57, 0x05, 0x52, 0x52, 0x57, 0x05, - 0x24, 0x17, 0x13, 0x07, 0x00, 0xad, 0x5e, 0x0e, 0xe0, 0xf5, 0x55, 0x0d, - 0x52, 0x20, 0x55, 0x02, 0x05, 0x52, 0x55, 0x02, 0x42, 0x52, 0x55, 0x02, - 0x52, 0x50, 0x55, 0x07, 0x42, 0x50, 0x55, 0x07, 0x05, 0x55, 0x65, 0x34, - 0x05, 0x52, 0x55, 0x02, 0x05, 0x55, 0x55, 0x07, 0x20, 0x16, 0x61, 0x02, - 0x2c, 0x72, 0x22, 0x0f, 0x50, 0x25, 0x27, 0x02, 0x30, 0x35, 0xd5, 0x05, - 0x48, 0xe4, 0x54, 0x02, 0x24, 0x43, 0x56, 0x06, 0x24, 0x30, 0x22, 0x07, - 0x12, 0x52, 0x55, 0x02, 0x24, 0x50, 0x55, 0x07, 0x5a, 0x30, 0x55, 0x05, - 0x5a, 0x90, 0xdb, 0x09, 0x56, 0x0e, 0x0f, 0x00, 0x52, 0x02, 0x07, 0x00, - 0x20, 0x20, 0x51, 0x02, 0x00, 0x70, 0x11, 0x00, 0x00, 0xe0, 0x88, 0x00, - 0x11, 0x25, 0x8d, 0xc4, 0x11, 0x25, 0xa1, 0x8e, 0x20, 0x20, 0x22, 0x02, - 0x00, 0xa0, 0xa5, 0x00, 0x00, 0x50, 0x5a, 0x00, 0x28, 0x28, 0x28, 0x28, - 0x5a, 0x5a, 0x5a, 0x5a, 0xeb, 0xeb, 0xeb, 0xeb, 0x44, 0x44, 0x44, 0x44, - 0x44, 0x74, 0x44, 0x44, 0x44, 0x47, 0x47, 0x44, 0xaa, 0xba, 0xaa, 0xaa, - 0x00, 0xf0, 0xaa, 0xaa, 0x00, 0x47, 0x47, 0x44, 0xaa, 0x8b, 0xab, 0xaa, - 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x8f, 0xab, 0xaa, 0xaa, 0x8b, 0x0f, 0x00, - 0xaa, 0xfa, 0x00, 0x00, 0x44, 0x47, 0x07, 0x00, 0x00, 0x70, 0x44, 0x44, - 0x44, 0xc4, 0x00, 0x00, 0x44, 0xf4, 0x00, 0x00, 0x00, 0xf0, 0x44, 0x44, - 0x44, 0xc4, 0x44, 0x44, 0x00, 0xf0, 0x00, 0x00, 0x44, 0xf4, 0x44, 0x44, - 0x44, 0x4c, 0x4c, 0x44, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0x2a, 0x0e, 0x00, - 0x00, 0x2e, 0xaa, 0xaa, 0xaa, 0x0b, 0x0f, 0x00, 0x00, 0x0f, 0xab, 0xaa, - 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x0f, 0x0f, 0x00, 0xaa, 0x0b, 0xab, 0xaa, - 0x44, 0x0f, 0x0f, 0x00, 0xaa, 0xfa, 0x00, 0x00, 0x00, 0x0f, 0x4f, 0x44, - 0x00, 0xf0, 0xaa, 0xaa, 0xaa, 0xea, 0x00, 0x00, 0x44, 0x4c, 0x0c, 0x00, - 0x00, 0x4c, 0x4c, 0x44, 0x00, 0xe0, 0xaa, 0xaa, 0xaa, 0xfa, 0xaa, 0xaa, - 0x44, 0x4f, 0x4f, 0x44, 0x44, 0x74, 0x00, 0x00, 0x00, 0xc0, 0x44, 0x44, - 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x33, 0x33, 0x33, 0x33, - 0xcc, 0xcc, 0xcc, 0xcc, 0xff, 0xff, 0x00, 0x00, 0x00, 0xa0, 0x55, 0x0a, - 0x30, 0x35, 0x95, 0x05, 0xf0, 0x19, 0x11, 0x01, 0x00, 0x5f, 0x55, 0x05, - 0x00, 0x17, 0x12, 0x07, 0x00, 0x5e, 0x55, 0x02, 0x00, 0xaa, 0x2e, 0x01, - 0x00, 0x5a, 0x44, 0x04, 0x70, 0x52, 0x25, 0x07, 0x20, 0x75, 0x55, 0x02, - 0x60, 0x99, 0x66, 0x0f, 0x60, 0x21, 0x55, 0x02, 0x00, 0xd6, 0x6b, 0x00, - 0x80, 0x9f, 0xf9, 0x01, 0x60, 0x71, 0x11, 0x06, 0x20, 0x55, 0x55, 0x05, - 0x70, 0x70, 0x70, 0x00, 0x20, 0x27, 0x70, 0x00, 0x10, 0x42, 0x12, 0x07, - 0x40, 0x12, 0x42, 0x07, 0x80, 0x44, 0x44, 0x44, 0x44, 0x44, 0x25, 0x00, - 0x00, 0x02, 0x07, 0x02, 0xa0, 0x05, 0x5a, 0x00, 0x52, 0x02, 0x00, 0x00, - 0x00, 0x60, 0x06, 0x00, 0x00, 0x00, 0x02, 0x00, 0x4c, 0x54, 0x46, 0x00, - 0x57, 0x55, 0x00, 0x00, 0x43, 0x72, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, - 0x00, 0x00, 0x00, 0x00, -}; - -static const txt_font_t small_font = -{ - "small", - small_font_data, - 4, - 8, -}; diff --git a/games/NXDoom/textscreen/fonts/small.png b/games/NXDoom/textscreen/fonts/small.png deleted file mode 100644 index 155797fe6..000000000 Binary files a/games/NXDoom/textscreen/fonts/small.png and /dev/null differ diff --git a/games/NXDoom/textscreen/textscreen.h b/games/NXDoom/textscreen/textscreen.h deleted file mode 100644 index 40824da68..000000000 --- a/games/NXDoom/textscreen/textscreen.h +++ /dev/null @@ -1,57 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/textscreen/textscreen.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - ****************************************************************************/ - -#ifndef TEXTSCREEN_H -#define TEXTSCREEN_H - -#ifdef __cplusplus -extern "C" -{ -#endif - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "../src/doomkeys.h" -#include "txt_main.h" - -#include "txt_button.h" -#include "txt_checkbox.h" -#include "txt_conditional.h" -#include "txt_desktop.h" -#include "txt_dropdown.h" -#include "txt_fileselect.h" -#include "txt_inputbox.h" -#include "txt_label.h" -#include "txt_radiobutton.h" -#include "txt_scrollpane.h" -#include "txt_separator.h" -#include "txt_spinctrl.h" -#include "txt_strut.h" -#include "txt_table.h" -#include "txt_widget.h" -#include "txt_window.h" -#include "txt_window_action.h" - -#ifdef __cplusplus -} -#endif - -#endif /* TEXTSCREEN_H */ diff --git a/games/NXDoom/textscreen/txt_button.c b/games/NXDoom/textscreen/txt_button.c deleted file mode 100644 index 0eadb71a4..000000000 --- a/games/NXDoom/textscreen/txt_button.c +++ /dev/null @@ -1,159 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/textscreen/txt_button.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -#include "doomkeys.h" - -#include "txt_button.h" -#include "txt_gui.h" -#include "txt_io.h" -#include "txt_main.h" -#include "txt_utf8.h" -#include "txt_window.h" - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -static void txt_button_size_calc(TXT_UNCAST_ARG(button)); -static void txt_button_drawer(TXT_UNCAST_ARG(button)); -static void txt_button_destructor(TXT_UNCAST_ARG(button)); -static int txt_button_keypress(TXT_UNCAST_ARG(button), int key); -static void txt_button_mousepress(TXT_UNCAST_ARG(button), int x, int y, - int b); - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -txt_widget_class_t txt_button_class = -{ - txt_always_selectable, - txt_button_size_calc, - txt_button_drawer, - txt_button_keypress, - txt_button_destructor, - txt_button_mousepress, - NULL, -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static void txt_button_size_calc(TXT_UNCAST_ARG(button)) -{ - TXT_CAST_ARG(txt_button_t, button); - - button->widget.w = txt_utf8_strlen(button->label); - button->widget.h = 1; -} - -static void txt_button_drawer(TXT_UNCAST_ARG(button)) -{ - TXT_CAST_ARG(txt_button_t, button); - int i; - int w; - - w = button->widget.w; - - txt_set_widget_bg(button); - - txt_draw_string(button->label); - - for (i = txt_utf8_strlen(button->label); i < w; ++i) - { - txt_draw_string(" "); - } -} - -static void txt_button_destructor(TXT_UNCAST_ARG(button)) -{ - TXT_CAST_ARG(txt_button_t, button); - - free(button->label); -} - -static int txt_button_keypress(TXT_UNCAST_ARG(button), int key) -{ - TXT_CAST_ARG(txt_button_t, button); - - if (key == KEY_ENTER) - { - txt_emit_signal(button, "pressed"); - return 1; - } - - return 0; -} - -static void txt_button_mousepress(TXT_UNCAST_ARG(button), int x, int y, - int b) -{ - TXT_CAST_ARG(txt_button_t, button); - - if (b == TXT_MOUSE_LEFT) - { - /* Equivalent to pressing enter */ - - txt_button_keypress(button, KEY_ENTER); - } -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -void txt_set_button_label(txt_button_t *button, const char *label) -{ - free(button->label); - button->label = strdup(label); -} - -txt_button_t *txt_new_button(const char *label) -{ - txt_button_t *button; - - button = malloc(sizeof(txt_button_t)); - - txt_init_widget(button, &txt_button_class); - button->label = strdup(label); - - return button; -} - -/* Button with a callback set automatically */ - -txt_button_t *txt_new_button2(const char *label, txt_widget_signal_f func, - void *user_data) -{ - txt_button_t *button; - - button = txt_new_button(label); - - txt_signal_connect(button, "pressed", func, user_data); - - return button; -} diff --git a/games/NXDoom/textscreen/txt_button.h b/games/NXDoom/textscreen/txt_button.h deleted file mode 100644 index 1982e894a..000000000 --- a/games/NXDoom/textscreen/txt_button.h +++ /dev/null @@ -1,80 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/textscreen/txt_button.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - ****************************************************************************/ - -#ifndef TXT_BUTTON_H -#define TXT_BUTTON_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "txt_widget.h" - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -/* Button widget. - * - * A button is a widget that can be selected to perform some action. - * When a button is pressed, it emits the "pressed" signal. - */ - -struct txt_button_s -{ - txt_widget_t widget; - char *label; -}; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/** - * Create a new button widget. - * - * @param label The label to use on the new button (UTF-8 format). - * @return Pointer to the new button widget. - */ - -txt_button_t *txt_new_button(const char *label); - -/** - * Create a new button widget, binding the "pressed" signal to a - * specified callback function. - * - * @param label The label to use on the new button (UTF-8 format). - * @param func The callback function to invoke. - * @param user_data User-specified pointer to pass to the callback. - * @return Pointer to the new button widget. - */ - -txt_button_t *txt_new_button2(const char *label, txt_widget_signal_f func, - void *user_data); - -/** - * Change the label used on a button. - * - * @param button The button. - * @param label The new label (UTF-8 format). - */ - -void txt_set_button_label(txt_button_t *button, const char *label); - -#endif /* TXT_BUTTON_H */ diff --git a/games/NXDoom/textscreen/txt_checkbox.c b/games/NXDoom/textscreen/txt_checkbox.c deleted file mode 100644 index cd467ff3b..000000000 --- a/games/NXDoom/textscreen/txt_checkbox.c +++ /dev/null @@ -1,174 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/textscreen/txt_checkbox.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -#include "doomkeys.h" - -#include "txt_checkbox.h" -#include "txt_gui.h" -#include "txt_io.h" -#include "txt_main.h" -#include "txt_utf8.h" -#include "txt_window.h" - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -static void txt_checkbox_size_calc(TXT_UNCAST_ARG(checkbox)); -static void txt_checkbox_drawer(TXT_UNCAST_ARG(checkbox)); -static void txt_checkbox_destructor(TXT_UNCAST_ARG(checkbox)); -static int txt_check_box_keypress(TXT_UNCAST_ARG(checkbox), int key); -static void txt_checkbox_mousepress(TXT_UNCAST_ARG(checkbox), int x, int y, - int b); - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -txt_widget_class_t txt_checkbox_class = -{ - txt_always_selectable, - txt_checkbox_size_calc, - txt_checkbox_drawer, - txt_check_box_keypress, - txt_checkbox_destructor, - txt_checkbox_mousepress, - NULL, -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static void txt_checkbox_size_calc(TXT_UNCAST_ARG(checkbox)) -{ - TXT_CAST_ARG(txt_checkbox_t, checkbox); - - /* Minimum width is the string length + right-side space for padding */ - - checkbox->widget.w = txt_utf8_strlen(checkbox->label) + 5; - checkbox->widget.h = 1; -} - -static void txt_checkbox_drawer(TXT_UNCAST_ARG(checkbox)) -{ - TXT_CAST_ARG(txt_checkbox_t, checkbox); - txt_saved_colors_t colors; - int i; - int w; - - w = checkbox->widget.w; - - txt_save_colours(&colors); - txt_fgcolour(TXT_COLOR_BRIGHT_CYAN); - txt_draw_string("("); - - txt_fgcolour(TXT_COLOR_BRIGHT_WHITE); - - if ((*checkbox->variable != 0) ^ checkbox->inverted) - { - txt_draw_code_page_string("\x07"); - } - else - { - txt_draw_string(" "); - } - - txt_fgcolour(TXT_COLOR_BRIGHT_CYAN); - - txt_draw_string(") "); - - txt_restore_colours(&colors); - txt_set_widget_bg(checkbox); - txt_draw_string(checkbox->label); - - for (i = txt_utf8_strlen(checkbox->label); i < w - 4; ++i) - { - txt_draw_string(" "); - } -} - -static void txt_checkbox_destructor(TXT_UNCAST_ARG(checkbox)) -{ - TXT_CAST_ARG(txt_checkbox_t, checkbox); - - free(checkbox->label); -} - -static int txt_check_box_keypress(TXT_UNCAST_ARG(checkbox), int key) -{ - TXT_CAST_ARG(txt_checkbox_t, checkbox); - - if (key == KEY_ENTER || key == ' ') - { - *checkbox->variable = !*checkbox->variable; - txt_emit_signal(checkbox, "changed"); - return 1; - } - - return 0; -} - -static void txt_checkbox_mousepress(TXT_UNCAST_ARG(checkbox), int x, int y, - int b) -{ - TXT_CAST_ARG(txt_checkbox_t, checkbox); - - if (b == TXT_MOUSE_LEFT) - { - /* Equivalent to pressing enter */ - - txt_check_box_keypress(checkbox, KEY_ENTER); - } -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -txt_checkbox_t *txt_new_check_box(const char *label, int *variable) -{ - txt_checkbox_t *checkbox; - - checkbox = malloc(sizeof(txt_checkbox_t)); - - txt_init_widget(checkbox, &txt_checkbox_class); - checkbox->label = strdup(label); - checkbox->variable = variable; - checkbox->inverted = 0; - - return checkbox; -} - -txt_checkbox_t *txt_new_inverted_checkbox(const char *label, int *variable) -{ - txt_checkbox_t *result; - - result = txt_new_check_box(label, variable); - result->inverted = 1; - - return result; -} diff --git a/games/NXDoom/textscreen/txt_checkbox.h b/games/NXDoom/textscreen/txt_checkbox.h deleted file mode 100644 index b988f2cf1..000000000 --- a/games/NXDoom/textscreen/txt_checkbox.h +++ /dev/null @@ -1,82 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/textscreen/txt_checkbox.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - ****************************************************************************/ - -#ifndef TXT_CHECKBOX_H -#define TXT_CHECKBOX_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "txt_widget.h" - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -/* Checkbox widget. - * - * A checkbox is used to control boolean values that may be either on - * or off. The widget has a label that is displayed to the right of - * the checkbox indicator. The widget tracks an integer variable; - * if the variable is non-zero, the checkbox is checked, while if it - * is zero, the checkbox is unchecked. It is also possible to - * create "inverted" checkboxes where this logic is reversed. - * - * When a checkbox is changed, it emits the "changed" signal. - */ - -struct txt_checkbox_s -{ - txt_widget_t widget; - char *label; - int *variable; - int inverted; -}; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/** - * Create a new checkbox. - * - * @param label The label for the new checkbox (UTF-8 format). - * @param variable Pointer to the variable containing this checkbox's - * value. - * @return Pointer to the new checkbox. - */ - -txt_checkbox_t *txt_new_check_box(const char *label, int *variable); - -/** - * Create a new inverted checkbox. - * - * An inverted checkbox displays the opposite of a normal checkbox; - * where it would be checked, it appears unchecked, and vice-versa. - * - * @param label The label for the new checkbox (UTF-8 format). - * @param variable Pointer to the variable containing this checkbox's - * value. - * @return Pointer to the new checkbox. - */ - -txt_checkbox_t *txt_new_inverted_checkbox(const char *label, int *variable); - -#endif /* TXT_CHECKBOX_H */ diff --git a/games/NXDoom/textscreen/txt_conditional.c b/games/NXDoom/textscreen/txt_conditional.c deleted file mode 100644 index 182711915..000000000 --- a/games/NXDoom/textscreen/txt_conditional.c +++ /dev/null @@ -1,189 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/textscreen/txt_conditional.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2016 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -#include "txt_conditional.h" -#include "txt_strut.h" - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -struct txt_conditional_s -{ - txt_widget_t widget; - int *var; - int expected_value; - txt_widget_t *child; -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static int condition_true(txt_conditional_t *conditional) -{ - return *conditional->var == conditional->expected_value; -} - -static int txt_cond_selectable(TXT_UNCAST_ARG(conditional)) -{ - TXT_CAST_ARG(txt_conditional_t, conditional); - return condition_true(conditional) && - txt_selectable_widget(conditional->child); -} - -static void txt_cond_size_calc(TXT_UNCAST_ARG(conditional)) -{ - TXT_CAST_ARG(txt_conditional_t, conditional); - - if (!condition_true(conditional)) - { - conditional->widget.w = 0; - conditional->widget.h = 0; - } - else - { - txt_calc_widget_size(conditional->child); - conditional->widget.w = conditional->child->w; - conditional->widget.h = conditional->child->h; - } -} - -static void txt_cond_layout(TXT_UNCAST_ARG(conditional)) -{ - TXT_CAST_ARG(txt_conditional_t, conditional); - - if (condition_true(conditional)) - { - conditional->child->x = conditional->widget.x; - conditional->child->y = conditional->widget.y; - txt_layout_widget(conditional->child); - } -} - -static void txt_cond_drawer(TXT_UNCAST_ARG(conditional)) -{ - TXT_CAST_ARG(txt_conditional_t, conditional); - - if (condition_true(conditional)) - { - txt_draw_widget(conditional->child); - } -} - -static void txt_cond_destructor(TXT_UNCAST_ARG(conditional)) -{ - TXT_CAST_ARG(txt_conditional_t, conditional); - txt_destroy_widget(conditional->child); -} - -static void txt_cond_focused(TXT_UNCAST_ARG(conditional), int focused) -{ - TXT_CAST_ARG(txt_conditional_t, conditional); - - if (condition_true(conditional)) - { - txt_set_widget_focus(conditional->child, focused); - } -} - -static int txt_cond_key_press(TXT_UNCAST_ARG(conditional), int key) -{ - TXT_CAST_ARG(txt_conditional_t, conditional); - - if (condition_true(conditional)) - { - return txt_widget_key_press(conditional->child, key); - } - - return 0; -} - -static void txt_cond_mouse_press(TXT_UNCAST_ARG(conditional), int x, int y, - int b) -{ - TXT_CAST_ARG(txt_conditional_t, conditional); - - if (condition_true(conditional)) - { - txt_widget_mouse_press(conditional->child, x, y, b); - } -} - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -txt_widget_class_t txt_conditional_class = -{ - txt_cond_selectable, txt_cond_size_calc, txt_cond_drawer, - txt_cond_key_press, txt_cond_destructor, txt_cond_mouse_press, - txt_cond_layout, txt_cond_focused, -}; - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -txt_conditional_t *txt_new_conidtional(int *var, int expected_value, - TXT_UNCAST_ARG(child)) -{ - TXT_CAST_ARG(txt_widget_t, child); - txt_conditional_t *conditional; - - conditional = malloc(sizeof(txt_conditional_t)); - - txt_init_widget(conditional, &txt_conditional_class); - conditional->var = var; - conditional->expected_value = expected_value; - conditional->child = child; - - child->parent = &conditional->widget; - - return conditional; -} - -/* "Static" conditional that returns an empty strut if the given static - * value is false. Kind of like a conditional but we only evaluate it at - * creation time. - */ - -txt_widget_t *txt_if(int conditional, TXT_UNCAST_ARG(child)) -{ - TXT_CAST_ARG(txt_widget_t, child); - - if (conditional) - { - return child; - } - else - { - txt_strut_t *nullwidget; - txt_destroy_widget(child); - nullwidget = txt_new_strut(0, 0); - return &nullwidget->widget; - } -} diff --git a/games/NXDoom/textscreen/txt_conditional.h b/games/NXDoom/textscreen/txt_conditional.h deleted file mode 100644 index 691c891e4..000000000 --- a/games/NXDoom/textscreen/txt_conditional.h +++ /dev/null @@ -1,79 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/textscreen/txt_conditional.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2016 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - ****************************************************************************/ - -#ifndef TXT_CONDITIONAL_H -#define TXT_CONDITIONAL_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -/** - * @file txt_conditional.h - * - * Conditional widget. - */ - -#include "txt_widget.h" - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -/** - * Conditional widget. - * - * A conditional widget contains another widget, and conditionally - * shows or hides it based on the value of a variable. - */ - -typedef struct txt_conditional_s txt_conditional_t; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/** - * Create a new conditional widget. - * - * @param var The variable to check. - * @param expected_value If the variable has this value, the widget is - * shown. - * @param child The inner widget to show or hide. - * @return Pointer to the new conditional widget. - */ - -txt_conditional_t *txt_new_conidtional(int *var, int expected_value, - TXT_UNCAST_ARG(child)); - -/** - * Return the given child widget if the given boolean condition is true. - * - * If the condition is not true, the child widget is destroyed and a dummy - * "null" widget is returned that shows nothing. - * - * @param condition Boolean condition - true or false value. - * @param child Widget to conditionally return. - * @return Either child (if condition is true) or a null - * widget. - */ - -txt_widget_t *txt_if(int condition, TXT_UNCAST_ARG(child)); - -#endif /* #ifndef TXT_CONDITIONAL_H */ diff --git a/games/NXDoom/textscreen/txt_desktop.c b/games/NXDoom/textscreen/txt_desktop.c deleted file mode 100644 index 3b45a0eb5..000000000 --- a/games/NXDoom/textscreen/txt_desktop.c +++ /dev/null @@ -1,420 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/textscreen/txt_desktop.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include - -#include "doomkeys.h" - -#include "txt_desktop.h" -#include "txt_gui.h" -#include "txt_io.h" -#include "txt_main.h" -#include "txt_separator.h" -#include "txt_window.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define HELP_KEY KEY_F1 -#define MAXWINDOWS 128 - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static char *g_desktop_title; -static txt_window_t *g_all_windows[MAXWINDOWS]; -static int g_num_windows = 0; -static int g_main_loop_running = 0; - -static txt_idle_callback_f g_periodic_callback = NULL; -static void *g_periodic_callback_data; -static unsigned int g_periodic_callback_period; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static void txt_exit_mainloop(void) -{ - g_main_loop_running = 0; -} - -#if 0 /* UNUSED */ -static int txt_raise_window(txt_window_t *window) -{ - int i; - - for (i = 0; i < g_num_windows - 1; ++i) - { - if (g_all_windows[i] == window) - { - g_all_windows[i] = g_all_windows[i + 1]; - g_all_windows[i + 1] = window; - - if (i == g_num_windows - 2) - { - txt_set_window_focus(g_all_windows[i], 0); - txt_set_window_focus(window, 1); - } - - return 1; - } - } - - /* Window not in the list, or at the end of the list (top) already. */ - - return 0; -} -#endif - -static void draw_desktop_background(const char *title) -{ - int i; - unsigned char *screendata; - unsigned char *p; - - screendata = txt_get_screen_data(); - - /* Fill the screen with gradient characters */ - - p = screendata; - - for (i = 0; i < TXT_SCREEN_W * TXT_SCREEN_H; ++i) - { - *p++ = 0xb1; - *p++ = TXT_COLOR_GREY | (TXT_COLOR_BLUE << 4); - } - - /* Draw the top and bottom banners */ - - p = screendata; - - for (i = 0; i < TXT_SCREEN_W; ++i) - { - *p++ = ' '; - *p++ = TXT_COLOR_BLACK | (TXT_COLOR_GREY << 4); - } - - p = screendata + (TXT_SCREEN_H - 1) * TXT_SCREEN_W * 2; - - for (i = 0; i < TXT_SCREEN_W; ++i) - { - *p++ = ' '; - *p++ = TXT_COLOR_BLACK | (TXT_COLOR_GREY << 4); - } - - /* Print the title */ - - txt_goto_xy(0, 0); - txt_fgcolour(TXT_COLOR_BLACK); - txt_bgcolour(TXT_COLOR_GREY, 0); - - txt_putchar(' '); - txt_puts(title); -} - -static void draw_help_indicator(void) -{ - char keybuf[10]; - int fgcolor; - int x; - int y; - - txt_get_key_description(HELP_KEY, keybuf, sizeof(keybuf)); - - txt_get_mouse_position(&x, &y); - - if (y == 0 && x >= TXT_SCREEN_W - 9) - { - fgcolor = TXT_COLOR_GREY; - txt_bgcolour(TXT_COLOR_BLACK, 0); - } - else - { - fgcolor = TXT_COLOR_BLACK; - txt_bgcolour(TXT_COLOR_GREY, 0); - } - - txt_goto_xy(TXT_SCREEN_W - 9, 0); - - txt_fgcolour(TXT_COLOR_BRIGHT_WHITE); - txt_draw_string(" "); - txt_draw_string(keybuf); - - txt_fgcolour(fgcolor); - txt_draw_string("=Help "); -} - -static void desktop_input_event(int c) -{ - txt_window_t *active_window; - int x; - int y; - - switch (c) - { - case TXT_MOUSE_LEFT: - txt_get_mouse_position(&x, &y); - - /* Clicking the top-right of the screen is equivalent - * to pressing the help key. - */ - - if (y == 0 && x >= TXT_SCREEN_W - 9) - { - desktop_input_event(HELP_KEY); - } - break; - - case HELP_KEY: - active_window = txt_get_active_window(); - if (active_window != NULL) - { - txt_open_window_help_url(active_window); - } - break; - - default: - break; - } -} - -#if 0 /* UNUSED */ -static void txt_draw_ascii_table(void) -{ - unsigned char *screendata; - char buf[10]; - int x; - int y; - int n; - - screendata = txt_get_screen_data(); - - txt_fgcolour(TXT_COLOR_BRIGHT_WHITE); - txt_bgcolour(TXT_COLOR_BLACK, 0); - - for (y = 0; y < 16; ++y) - { - for (x = 0; x < 16; ++x) - { - n = y * 16 + x; - - txt_goto_xy(x * 5, y); - txt_snprintf(buf, sizeof(buf), "%02x ", n); - txt_puts(buf); - - /* Write the character directly to the screen memory buffer: */ - - screendata[(y * TXT_SCREEN_W + x * 5 + 3) * 2] = n; - } - } - - txt_update_screen(); -} -#endif - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -void txt_add_desktop_window(txt_window_t *win) -{ - /* Previously-top window loses focus: */ - - if (g_num_windows > 0) - { - txt_set_window_focus(g_all_windows[g_num_windows - 1], 0); - } - - g_all_windows[g_num_windows] = win; - ++g_num_windows; - - /* New window gains focus: */ - - txt_set_window_focus(win, 1); -} - -void txt_remove_desktop_window(txt_window_t *win) -{ - int from; - int to; - - /* Window must lose focus if it's being removed: */ - - txt_set_window_focus(win, 0); - - for (from = 0, to = 0; from < g_num_windows; ++from) - { - if (g_all_windows[from] != win) - { - g_all_windows[to] = g_all_windows[from]; - ++to; - } - } - - g_num_windows = to; - - /* Top window gains focus: */ - - if (g_num_windows > 0) - { - txt_set_window_focus(g_all_windows[g_num_windows - 1], 1); - } -} - -txt_window_t *txt_get_active_window(void) -{ - if (g_num_windows == 0) - { - return NULL; - } - - return g_all_windows[g_num_windows - 1]; -} - -int txt_lower_window(txt_window_t *window) -{ - int i; - - for (i = 0; i < g_num_windows - 1; ++i) - { - if (g_all_windows[i + 1] == window) - { - g_all_windows[i + 1] = g_all_windows[i]; - g_all_windows[i] = window; - - if (i == g_num_windows - 2) - { - txt_set_window_focus(window, 0); - txt_set_window_focus(g_all_windows[i + 1], 1); - } - - return 1; - } - } - - /* Window not in the list, or at the start of the list (bottom) already. */ - - return 0; -} - -void txt_set_desktop_title(const char *title) -{ - free(g_desktop_title); - g_desktop_title = strdup(title); - txt_set_window_title(title); -} - -void txt_draw_desktop(void) -{ - txt_window_t *active_window; - const char *title; - int i; - - txt_init_clip_area(); - - if (g_desktop_title == NULL) - title = ""; - else - title = g_desktop_title; - - draw_desktop_background(title); - - active_window = txt_get_active_window(); - if (active_window != NULL && active_window->help_url != NULL) - { - draw_help_indicator(); - } - - for (i = 0; i < g_num_windows; ++i) - { - txt_draw_window(g_all_windows[i]); - } - - txt_update_screen(); -} - -/* Fallback function to handle key/mouse events that are not handled by - * the active window. - */ - -void txt_dispatch_events(void) -{ - txt_window_t *active_window; - int c; - - while ((c = txt_getchar()) > 0) - { - active_window = txt_get_active_window(); - - if (active_window != NULL && !txt_window_keypress(active_window, c)) - { - desktop_input_event(c); - } - } -} - -void txt_set_periodic_callback(txt_idle_callback_f callback, void *user_data, - unsigned int period) -{ - g_periodic_callback = callback; - g_periodic_callback_data = user_data; - g_periodic_callback_period = period; -} - -void txt_gui_mainloop(void) -{ - g_main_loop_running = 1; - - while (g_main_loop_running) - { - txt_dispatch_events(); - - /* After the last window is closed, exit the loop */ - - if (g_num_windows <= 0) - { - txt_exit_mainloop(); - continue; - } - - txt_draw_desktop(); - - /* TXT_DrawASCIITable(); */ - - if (g_periodic_callback == NULL) - { - txt_sleep(0); - } - else - { - txt_sleep(g_periodic_callback_period); - - g_periodic_callback(g_periodic_callback_data); - } - } -} diff --git a/games/NXDoom/textscreen/txt_desktop.h b/games/NXDoom/textscreen/txt_desktop.h deleted file mode 100644 index faae8c834..000000000 --- a/games/NXDoom/textscreen/txt_desktop.h +++ /dev/null @@ -1,99 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/textscreen/txt_desktop.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - ****************************************************************************/ - -#ifndef TXT_DESKTOP_H -#define TXT_DESKTOP_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "txt_window.h" - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -typedef void (*txt_idle_callback_f)(void *user_data); - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -void txt_add_desktop_window(txt_window_t *win); -void txt_remove_desktop_window(txt_window_t *win); -void txt_draw_desktop(void); -void txt_dispatch_events(void); -void txt_draw_window(txt_window_t *window); -void txt_set_window_focus(txt_window_t *window, int focused); -int txt_window_keypress(txt_window_t *window, int c); - -/** - * Set the title displayed at the top of the screen. - * - * @param title The title to display (UTF-8 format). - */ - -void txt_set_desktop_title(const char *title); - -/** - * Start the main event loop. At least one window must have been - * opened prior to running this function. When no windows are left - * open, the event loop exits. - * - * It is possible to trigger an exit from this function using the - * @ref TXT_ExitMainLoop function. - */ - -void txt_gui_mainloop(void); - -/** - * Get the top window on the desktop that is currently receiving - * inputs. - * - * @return The active window, or NULL if no windows are present. - */ - -txt_window_t *txt_get_active_window(void); - -/** - * Set a callback function to be invoked periodically by the main - * loop code. - * - * @param callback The callback to invoke, or NULL to cancel - * an existing callback. - * @param user_data Extra data to pass to the callback. - * @param period Maximum time between invoking each callback. - * eg. a value of 200 will cause the callback - * to be invoked at least once every 200ms. - */ - -void txt_set_periodic_callback(txt_idle_callback_f callback, void *user_data, - unsigned int period); -/** - * Lower the z-position of the given window relative to other windows. - * - * @param window The window to make inactive. - * @return Non-zero if the window was lowered successfully, - * or zero if the window could not be lowered further. - */ - -int txt_lower_window(txt_window_t *window); - -#endif /* TXT_DESKTOP_H */ diff --git a/games/NXDoom/textscreen/txt_dropdown.c b/games/NXDoom/textscreen/txt_dropdown.c deleted file mode 100644 index da19a8efd..000000000 --- a/games/NXDoom/textscreen/txt_dropdown.c +++ /dev/null @@ -1,343 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/textscreen/txt_dropdown.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -#include "doomkeys.h" - -#include "txt_button.h" -#include "txt_dropdown.h" -#include "txt_gui.h" -#include "txt_io.h" -#include "txt_main.h" -#include "txt_utf8.h" -#include "txt_window.h" - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -typedef struct -{ - txt_window_t *window; - txt_dropdown_list_t *list; - int item; -} callback_data_t; - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -static void txt_dropdown_list_size_calc(TXT_UNCAST_ARG(list)); -static void txt_dropdown_list_drawer(TXT_UNCAST_ARG(list)); -static void txt_dropdown_list_destructor(TXT_UNCAST_ARG(list)); -static int txt_dropdown_lis_keypress(TXT_UNCAST_ARG(list), int key); -static void txt_dropdown_list_mousepress(TXT_UNCAST_ARG(list), int x, int y, - int b); -/**************************************************************************** - * Public Data - ****************************************************************************/ - -txt_widget_class_t txt_dropdown_list_class = -{ - txt_always_selectable, - txt_dropdown_list_size_calc, - txt_dropdown_list_drawer, - txt_dropdown_lis_keypress, - txt_dropdown_list_destructor, - txt_dropdown_list_mousepress, - NULL, -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/* Check if the selected value for a list is valid */ - -static int valid_selection(txt_dropdown_list_t *list) -{ - return *list->variable >= 0 && *list->variable < list->num_values; -} - -/* Calculate the Y position for the selector window */ - -static int selector_window_y(txt_dropdown_list_t *list) -{ - int result; - - if (valid_selection(list)) - { - result = list->widget.y - 1 - *list->variable; - } - else - { - result = list->widget.y - 1 - (list->num_values / 2); - } - - /* Keep dropdown inside the screen. */ - - if (result < 1) - { - result = 1; - } - else if (result + list->num_values > (TXT_SCREEN_H - 3)) - { - result = TXT_SCREEN_H - list->num_values - 3; - } - - return result; -} - -/* Called when a button in the selector window is pressed */ - -static void item_selected(TXT_UNCAST_ARG(button), - TXT_UNCAST_ARG(callback_data)) -{ - TXT_CAST_ARG(callback_data_t, callback_data); - - /* Set the variable */ - - *callback_data->list->variable = callback_data->item; - - txt_emit_signal(callback_data->list, "changed"); - - /* Close the window */ - - txt_close_window(callback_data->window); -} - -/* Free callback data when the window is closed */ - -static void free_callback_data(TXT_UNCAST_ARG(list), - TXT_UNCAST_ARG(callback_data)) -{ - TXT_CAST_ARG(callback_data_t, callback_data); - free(callback_data); -} - -/* Catch presses of escape and close the window. */ - -static int selector_window_listener(txt_window_t *window, int key, - void *user_data) -{ - if (key == KEY_ESCAPE) - { - txt_close_window(window); - return 1; - } - - return 0; -} - -static int selector_mouse_listener(txt_window_t *window, int x, int y, int b, - void *unused) -{ - txt_widget_t *win; - - win = (txt_widget_t *)window; - - if (x < win->x || x > win->x + win->w || y < win->y || y > win->y + win->h) - { - txt_close_window(window); - return 1; - } - - return 0; -} - -/* Open the dropdown list window to select an item */ - -static void open_selector_window(txt_dropdown_list_t *list) -{ - txt_window_t *window; - int i; - - /* Open a simple window with no title bar or action buttons. */ - - window = txt_new_window(NULL); - - txt_set_window_action(window, TXT_HORIZ_LEFT, NULL); - txt_set_window_action(window, TXT_HORIZ_CENTER, NULL); - txt_set_window_action(window, TXT_HORIZ_RIGHT, NULL); - - /* Position the window so that the currently selected item appears - * over the top of the list widget. - */ - - txt_set_window_position(window, TXT_HORIZ_LEFT, TXT_VERT_TOP, - list->widget.x - 2, selector_window_y(list)); - - /* Add a button to the window for each option in the list. */ - - for (i = 0; i < list->num_values; ++i) - { - txt_button_t *button; - callback_data_t *data; - - button = txt_new_button(list->values[i]); - - txt_add_widget(window, button); - - /* Callback struct */ - - data = malloc(sizeof(callback_data_t)); - data->list = list; - data->window = window; - data->item = i; - - /* When the button is pressed, invoke the button press callback */ - - txt_signal_connect(button, "pressed", item_selected, data); - - /* When the window is closed, free back the callback struct */ - - txt_signal_connect(window, "closed", free_callback_data, data); - - /* Is this the currently-selected value? If so, select the button - * in the window as the default. - */ - - if (i == *list->variable) - { - txt_select_widget(window, button); - } - } - - /* Catch presses of escape in this window and close it. */ - - txt_set_key_listener(window, selector_window_listener, NULL); - txt_set_mouse_listener(window, selector_mouse_listener, NULL); -} - -static int dropdown_list_width(txt_dropdown_list_t *list) -{ - int i; - int result; - - /* Find the maximum string width */ - - result = 0; - - for (i = 0; i < list->num_values; ++i) - { - int w = txt_utf8_strlen(list->values[i]); - if (w > result) - { - result = w; - } - } - - return result; -} - -static void txt_dropdown_list_size_calc(TXT_UNCAST_ARG(list)) -{ - TXT_CAST_ARG(txt_dropdown_list_t, list); - - list->widget.w = dropdown_list_width(list); - list->widget.h = 1; -} - -static void txt_dropdown_list_drawer(TXT_UNCAST_ARG(list)) -{ - TXT_CAST_ARG(txt_dropdown_list_t, list); - unsigned int i; - const char *str; - - /* Set bg/fg text colors. */ - - txt_set_widget_bg(list); - - /* Select a string to draw from the list, if the current value is - * in range. Otherwise fall back to a default. - */ - - if (valid_selection(list)) - { - str = list->values[*list->variable]; - } - else - { - str = "???"; - } - - /* Draw the string and fill to the end with spaces */ - - txt_draw_string(str); - - for (i = txt_utf8_strlen(str); i < list->widget.w; ++i) - { - txt_draw_string(" "); - } -} - -static void txt_dropdown_list_destructor(TXT_UNCAST_ARG(list)) -{ -} - -static int txt_dropdown_lis_keypress(TXT_UNCAST_ARG(list), int key) -{ - TXT_CAST_ARG(txt_dropdown_list_t, list); - - if (key == KEY_ENTER) - { - open_selector_window(list); - return 1; - } - - return 0; -} - -static void txt_dropdown_list_mousepress(TXT_UNCAST_ARG(list), int x, int y, - int b) -{ - TXT_CAST_ARG(txt_dropdown_list_t, list); - - /* Left mouse click does the same as selecting and pressing enter */ - - if (b == TXT_MOUSE_LEFT) - { - txt_dropdown_lis_keypress(list, KEY_ENTER); - } -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -txt_dropdown_list_t *txt_new_dropdown_list(int *variable, - const char **values, int num_values) -{ - txt_dropdown_list_t *list; - - list = malloc(sizeof(txt_dropdown_list_t)); - - txt_init_widget(list, &txt_dropdown_list_class); - list->variable = variable; - list->values = values; - list->num_values = num_values; - - return list; -} diff --git a/games/NXDoom/textscreen/txt_dropdown.h b/games/NXDoom/textscreen/txt_dropdown.h deleted file mode 100644 index 08286325b..000000000 --- a/games/NXDoom/textscreen/txt_dropdown.h +++ /dev/null @@ -1,71 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/textscreen/txt_dropdown.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - ****************************************************************************/ - -#ifndef TXT_DROPDOWN_H -#define TXT_DROPDOWN_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "txt_widget.h" - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -/* Dropdown list widget. - * - * A dropdown list allows the user to select from a list of values, - * which appears when the list is selected. - * - * When the value of a dropdown list is changed, the "changed" signal - * is emitted. - */ - -struct txt_dropdown_list_s -{ - txt_widget_t widget; - int *variable; - const char **values; - int num_values; -}; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/** - * Create a new dropdown list widget. - * - * The parameters specify a list of string labels, and a pointer to an - * integer variable. The variable contains the current "value" of the - * list, as an index within the list of labels. - * - * @param variable Pointer to the variable containing the - * list's value. - * @param values Pointer to an array of strings containing - * the labels to use for the list (UTF-8 format). - * @param num_values The number of variables in the list. - */ - -txt_dropdown_list_t *txt_new_dropdown_list(int *variable, - const char **values, int num_values); - -#endif /* TXT_DROPDOWN_H */ diff --git a/games/NXDoom/textscreen/txt_fileselect.c b/games/NXDoom/textscreen/txt_fileselect.c deleted file mode 100644 index b6b6067cd..000000000 --- a/games/NXDoom/textscreen/txt_fileselect.c +++ /dev/null @@ -1,361 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/textscreen/txt_fileselect.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * Routines for selecting files. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "doomkeys.h" - -#include "txt_fileselect.h" -#include "txt_gui.h" -#include "txt_inputbox.h" -#include "txt_io.h" -#include "txt_main.h" -#include "txt_widget.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* Linux version: invoke the Zenity command line program to pop up a - * dialog box. This avoids adding Gtk+ as a compile dependency. - */ - -#define ZENITY_BINARY "/usr/bin/zenity" - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -struct txt_fileselect_s -{ - txt_widget_t widget; - txt_inputbox_t *inputbox; - int size; - const char *prompt; - const char **extensions; -}; - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -static void txt_file_select_size_calc(TXT_UNCAST_ARG(fileselect)); -static void txt_file_select_drawer(TXT_UNCAST_ARG(fileselect)); -static int txt_file_select_keypress(TXT_UNCAST_ARG(fileselect), int key); -static void txt_file_select_destructor(TXT_UNCAST_ARG(fileselect)); -static void txt_file_select_mousepress(TXT_UNCAST_ARG(fileselect), int x, - int y, int b); -static void txt_file_select_focused(TXT_UNCAST_ARG(fileselect), int focused); - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/* Dummy value to select a directory. */ - -const char *TXT_DIRECTORY[] = -{ - "__directory__", - NULL, -}; - -txt_widget_class_t txt_fileselect_class = -{ - txt_always_selectable, - txt_file_select_size_calc, - txt_file_select_drawer, - txt_file_select_keypress, - txt_file_select_destructor, - txt_file_select_mousepress, - NULL, - txt_file_select_focused, -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -#if 0 /* UNUSED */ -static char *exec_read_output(char **argv) -{ - char *result; - int completed; - int pid; - int status; - int result_len; - int pipefd[2]; - - if (pipe(pipefd) != 0) - { - return NULL; - } - - pid = fork(); - - if (pid == 0) - { - dup2(pipefd[1], fileno(stdout)); - execv(argv[0], argv); - exit(-1); - } - - fcntl(pipefd[0], F_SETFL, O_NONBLOCK); - - /* Read program output into 'result' string. - * Wait until the program has completed and (if it was successful) - * a full line has been read. - */ - - result = NULL; - result_len = 0; - completed = 0; - - while (!completed || - (status == 0 && (result == NULL || strchr(result, '\n') == NULL))) - { - char buf[64]; - int bytes; - - if (!completed && waitpid(pid, &status, WNOHANG) != 0) - { - completed = 1; - } - - bytes = read(pipefd[0], buf, sizeof(buf)); - - if (bytes < 0) - { - if (errno != EAGAIN && errno != EWOULDBLOCK) - { - status = -1; - break; - } - } - else - { - char *new_result = realloc(result, result_len + bytes + 1); - if (new_result == NULL) - { - break; - } - - result = new_result; - memcpy(result + result_len, buf, bytes); - result_len += bytes; - result[result_len] = '\0'; - } - - usleep(100 * 1000); - txt_sleep(1); - txt_update_screen(); - } - - close(pipefd[0]); - close(pipefd[1]); - - /* Must have a success exit code. */ - - if (WEXITSTATUS(status) != 0) - { - free(result); - result = NULL; - } - - /* Strip off newline from the end. */ - - if (result != NULL && result[result_len - 1] == '\n') - { - result[result_len - 1] = '\0'; - } - - return result; -} - -static unsigned int num_extensions(const char **extensions) -{ - unsigned int result = 0; - - if (extensions != NULL) - { - for (result = 0; extensions[result] != NULL; ++result) - ; - } - - return result; -} - -/* ExpandExtension - * given an extension (like wad) - * return a pointer to a string that is a case-insensitive - * pattern representation (like [Ww][Aa][Dd]) - */ - -static char *expand_extension(const char *orig) -{ - int oldlen; - int newlen; - int i; - char *c; - char *newext = NULL; - - oldlen = strlen(orig); - newlen = oldlen * 4; /* pathological case: 'w' => '[Ww]' */ - newext = malloc(newlen + 1); - - if (newext == NULL) - { - return NULL; - } - - c = newext; - - for (i = 0; i < oldlen; ++i) - { - if (isalpha(orig[i])) - { - *c++ = '['; - *c++ = tolower(orig[i]); - *c++ = toupper(orig[i]); - *c++ = ']'; - } - else - { - *c++ = orig[i]; - } - } - - *c = '\0'; - return newext; -} - -static char *txt_select_file(const char *window_title, - const char **extensions) -{ - return NULL; -} -#endif - -static void txt_file_select_size_calc(TXT_UNCAST_ARG(fileselect)) -{ - TXT_CAST_ARG(txt_fileselect_t, fileselect); - - /* Calculate widget size, but override the width to always - * be the configured size. - */ - - txt_calc_widget_size(fileselect->inputbox); - fileselect->widget.w = fileselect->size; - fileselect->widget.h = fileselect->inputbox->widget.h; -} - -static void txt_file_select_drawer(TXT_UNCAST_ARG(fileselect)) -{ - TXT_CAST_ARG(txt_fileselect_t, fileselect); - - /* Input box widget inherits all the properties of the - * file selector. - */ - - fileselect->inputbox->widget.x = fileselect->widget.x + 2; - fileselect->inputbox->widget.y = fileselect->widget.y; - fileselect->inputbox->widget.w = fileselect->widget.w - 2; - fileselect->inputbox->widget.h = fileselect->widget.h; - - /* Triple bar symbol gives a distinguishing look to the file selector. */ - - txt_draw_code_page_string("\xf0 "); - txt_bgcolour(TXT_COLOR_BLACK, 0); - txt_draw_widget(fileselect->inputbox); -} - -static void txt_file_select_destructor(TXT_UNCAST_ARG(fileselect)) -{ - TXT_CAST_ARG(txt_fileselect_t, fileselect); - - txt_destroy_widget(fileselect->inputbox); -} - -static int txt_file_select_keypress(TXT_UNCAST_ARG(fileselect), int key) -{ - TXT_CAST_ARG(txt_fileselect_t, fileselect); - return txt_widget_key_press(fileselect->inputbox, key); -} - -static void txt_file_select_mousepress(TXT_UNCAST_ARG(fileselect), int x, - int y, int b) -{ - TXT_CAST_ARG(txt_fileselect_t, fileselect); - txt_widget_mouse_press(fileselect->inputbox, x, y, b); -} - -static void txt_file_select_focused(TXT_UNCAST_ARG(fileselect), int focused) -{ - TXT_CAST_ARG(txt_fileselect_t, fileselect); - - txt_set_widget_focus(fileselect->inputbox, focused); -} - -/* If the (inner) inputbox widget is changed, emit a change to the - * outer (fileselect) widget. - */ - -static void input_box_changed(TXT_UNCAST_ARG(widget), - TXT_UNCAST_ARG(fileselect)) -{ - TXT_CAST_ARG(txt_fileselect_t, fileselect); - - txt_emit_signal(&fileselect->widget, "changed"); -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -txt_fileselect_t *txt_new_file_selector(char **variable, int size, - const char *prompt, - const char **extensions) -{ - txt_fileselect_t *fileselect; - - fileselect = malloc(sizeof(txt_fileselect_t)); - txt_init_widget(fileselect, &txt_fileselect_class); - fileselect->inputbox = txt_new_input_box(variable, 1024); - fileselect->inputbox->widget.parent = &fileselect->widget; - fileselect->size = size; - fileselect->prompt = prompt; - fileselect->extensions = extensions; - - txt_signal_connect(fileselect->inputbox, "changed", input_box_changed, - fileselect); - - return fileselect; -} diff --git a/games/NXDoom/textscreen/txt_fileselect.h b/games/NXDoom/textscreen/txt_fileselect.h deleted file mode 100644 index a8bc7eb5c..000000000 --- a/games/NXDoom/textscreen/txt_fileselect.h +++ /dev/null @@ -1,70 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/textscreen/txt_fileselect.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * Routines for selecting files, and the txt_fileselect_t widget. - * - ****************************************************************************/ - -#ifndef TXT_FILESELECT_H -#define TXT_FILESELECT_H - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -/** - * File selection widget. - * - * A file selection widget resembles an input box (@ref txt_inputbox_t) - * but opens a file selector dialog box when clicked. - */ - -typedef struct txt_fileselect_s txt_fileselect_t; - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/** - * Special value to use for 'extensions' that selects a directory - * instead of a file. - */ - -extern const char *TXT_DIRECTORY[]; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/** - * Create a new txt_fileselect_t widget. - * - * @param variable Pointer to a char * variable in which the selected - * file should be stored (UTF-8 format). - * @param size Width of the file selector widget in characters. - * @param prompt Pointer to a string containing a prompt to display - * in the file selection window. - * @param extensions NULL-terminated list of filename extensions that - * can be used for this widget, or @ref TXT_DIRECTORY - * to select directories. - */ - -txt_fileselect_t *txt_new_file_selector(char **variable, int size, - const char *prompt, - const char **extensions); - -#endif /* TXT_FILESELECT_H */ diff --git a/games/NXDoom/textscreen/txt_font.h b/games/NXDoom/textscreen/txt_font.h deleted file mode 100644 index 9815f8378..000000000 --- a/games/NXDoom/textscreen/txt_font.h +++ /dev/null @@ -1,29 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/textscreen/txt_font.h - * - * SPDX-License-Identifer: GPLv2 - * - ****************************************************************************/ - -#ifndef __TEXTSCREEN_FONT_H__ -#define __TEXTSCREEN_FONT_H__ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -typedef struct -{ - const char *name; - const uint8_t *data; - unsigned int w; - unsigned int h; -} txt_font_t; - -#endif /* __TEXTSCREEN_FONT_H__ */ diff --git a/games/NXDoom/textscreen/txt_gui.c b/games/NXDoom/textscreen/txt_gui.c deleted file mode 100644 index 9df99e62d..000000000 --- a/games/NXDoom/textscreen/txt_gui.c +++ /dev/null @@ -1,519 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/textscreen/txt_gui.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -#include "txt_gui.h" -#include "txt_io.h" -#include "txt_main.h" -#include "txt_utf8.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define VALID_X(x) ((x) >= g_cliparea->x1 && (x) < g_cliparea->x2) -#define VALID_Y(y) ((y) >= g_cliparea->y1 && (y) < g_cliparea->y2) - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -typedef struct txt_cliparea_s txt_cliparea_t; - -struct txt_cliparea_s -{ - int x1; - int x2; - int y1; - int y2; - txt_cliparea_t *next; -}; - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/* Array of border characters for drawing windows. The array looks like this: - * - * +-++ - * | || - * +-++ - * +-++ - */ - -static const int g_borders[4][4] = -{ - {0xda, 0xc4, 0xc2, 0xbf}, - {0xb3, ' ', 0xb3, 0xb3}, - {0xc3, 0xc4, 0xc5, 0xb4}, - {0xc0, 0xc4, 0xc1, 0xd9}, -}; - -static txt_cliparea_t *g_cliparea = NULL; - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -#if 0 /* UNUSED */ -static void txt_draw_desktop_background(const char *title) -{ - int i; - unsigned char *screendata; - unsigned char *p; - - screendata = txt_get_screen_data(); - - /* Fill the screen with gradient characters */ - - p = screendata; - - for (i = 0; i < TXT_SCREEN_W * TXT_SCREEN_H; ++i) - { - *p++ = 0xb1; - *p++ = TXT_COLOR_GREY | (TXT_COLOR_BLUE << 4); - } - - /* Draw the top and bottom banners */ - - p = screendata; - - for (i = 0; i < TXT_SCREEN_W; ++i) - { - *p++ = ' '; - *p++ = TXT_COLOR_BLACK | (TXT_COLOR_GREY << 4); - } - - p = screendata + (TXT_SCREEN_H - 1) * TXT_SCREEN_W * 2; - - for (i = 0; i < TXT_SCREEN_W; ++i) - { - *p++ = ' '; - *p++ = TXT_COLOR_BLACK | (TXT_COLOR_GREY << 4); - } - - /* Print the title */ - - txt_goto_xy(0, 0); - txt_fgcolour(TXT_COLOR_BLACK); - txt_bgcolour(TXT_COLOR_GREY, 0); - - txt_draw_string(" "); - txt_draw_string(title); -} -#endif - -static void txt_draw_shadow(int x, int y, int w, int h) -{ - unsigned char *screendata; - unsigned char *p; - int x1; - int y1; - - screendata = txt_get_screen_data(); - - for (y1 = y; y1 < y + h; ++y1) - { - p = screendata + (y1 * TXT_SCREEN_W + x) * 2; - - for (x1 = x; x1 < x + w; ++x1) - { - if (VALID_X(x1) && VALID_Y(y1)) - { - p[1] = TXT_COLOR_DARK_GREY; - } - - p += 2; - } - } -} - -static void put_unicode_char(unsigned int c) -{ - int d; - - /* Treat control characters specially. */ - - if (c == '\n' || c == '\b') - { - txt_putchar(c); - return; - } - - /* Map Unicode character into the symbol used to represent it in this - * code page. For unrepresentable characters, print a fallback instead. - * Note that we use txt_put_symbol() here because we just want to do a - * raw write into the screen buffer. - */ - - d = txt_unicode_character(c); - - if (d >= 0) - { - txt_put_symbol(d); - } - else - { - txt_put_symbol('\xa8'); - } -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -void txt_draw_window_frame(const char *title, int x, int y, int w, int h) -{ - txt_saved_colors_t colors; - int x1; - int y1; - int bx; - int by; - - txt_save_colours(&colors); - txt_fgcolour(TXT_COLOR_BRIGHT_CYAN); - - for (y1 = y; y1 < y + h; ++y1) - { - /* Select the appropriate row and column in the borders - * array to pick the appropriate character to draw at - * this location. - * - * Draw a horizontal line on the third line down, so we - * draw a box around the title. - */ - - by = y1 == y ? 0 - : y1 == y + 2 && title != NULL ? 2 - : y1 == y + h - 1 ? 3 - : 1; - - for (x1 = x; x1 < x + w; ++x1) - { - bx = x1 == x ? 0 : x1 == x + w - 1 ? 3 : 1; - - if (VALID_X(x1) && VALID_Y(y1)) - { - txt_goto_xy(x1, y1); - txt_putchar(g_borders[by][bx]); - } - } - } - - /* Draw the title */ - - if (title != NULL) - { - txt_goto_xy(x + 1, y + 1); - txt_bgcolour(TXT_COLOR_GREY, 0); - txt_fgcolour(TXT_COLOR_BLUE); - - for (x1 = 0; x1 < w - 2; ++x1) - { - txt_draw_string(" "); - } - - txt_goto_xy(x + (w - txt_utf8_strlen(title)) / 2, y + 1); - txt_draw_string(title); - } - - /* Draw the window's shadow. */ - - txt_draw_shadow(x + 2, y + h, w, 1); - txt_draw_shadow(x + w, y + 1, 2, h); - - txt_restore_colours(&colors); -} - -void txt_draw_separator(int x, int y, int w) -{ - txt_saved_colors_t colors; - unsigned char *data; - int x1; - int b; - - data = txt_get_screen_data(); - - txt_save_colours(&colors); - txt_fgcolour(TXT_COLOR_BRIGHT_CYAN); - - if (!VALID_Y(y)) - { - return; - } - - data += (y * TXT_SCREEN_W + x) * 2; - - for (x1 = x; x1 < x + w; ++x1) - { - txt_goto_xy(x1, y); - - b = x1 == x ? 0 : x1 == x + w - 1 ? 3 : 1; - - if (VALID_X(x1)) - { - /* Read the current value from the screen - * Check that it matches what the window should look like if - * there is no separator, then apply the separator - */ - - if (*data == g_borders[1][b]) - { - txt_putchar(g_borders[2][b]); - } - } - - data += 2; - } - - txt_restore_colours(&colors); -} - -/* Alternative to txt_draw_string() where the argument is a "code page - * string" - characters are in native code page format and not UTF-8. - */ - -void txt_draw_code_page_string(const char *s) -{ - int x; - int y; - int x1; - const char *p; - - txt_get_xy(&x, &y); - - if (VALID_Y(y)) - { - x1 = x; - - for (p = s; *p != '\0'; ++p) - { - if (VALID_X(x1)) - { - txt_goto_xy(x1, y); - txt_putchar(*p); - } - - x1 += 1; - } - } - - txt_goto_xy(x + strlen(s), y); -} - -void txt_draw_string(const char *s) -{ - int x; - int y; - int x1; - const char *p; - unsigned int c; - - txt_get_xy(&x, &y); - - if (VALID_Y(y)) - { - x1 = x; - - for (p = s; *p != '\0'; ) - { - c = txt_decode_utf8(&p); - - if (c == 0) - { - break; - } - - if (VALID_X(x1)) - { - txt_goto_xy(x1, y); - put_unicode_char(c); - } - - x1 += 1; - } - } - - txt_goto_xy(x + txt_utf8_strlen(s), y); -} - -void txt_draw_horiz_scrollbar(int x, int y, int w, int cursor, int range) -{ - txt_saved_colors_t colors; - int x1; - int cursor_x; - - if (!VALID_Y(y)) - { - return; - } - - txt_save_colours(&colors); - txt_fgcolour(TXT_COLOR_BLACK); - txt_bgcolour(TXT_COLOR_GREY, 0); - - txt_goto_xy(x, y); - txt_putchar('\x1b'); - - cursor_x = x + 1; - - if (range > 0) - { - cursor_x += (cursor * (w - 3)) / range; - } - - if (cursor_x > x + w - 2) - { - cursor_x = x + w - 2; - } - - for (x1 = x + 1; x1 < x + w - 1; ++x1) - { - if (VALID_X(x1)) - { - if (x1 == cursor_x) - { - txt_putchar('\xdb'); - } - else - { - txt_putchar('\xb1'); - } - } - } - - txt_putchar('\x1a'); - txt_restore_colours(&colors); -} - -void txt_draw_vert_scrollbar(int x, int y, int h, int cursor, int range) -{ - txt_saved_colors_t colors; - int y1; - int cursor_y; - - if (!VALID_X(x)) - { - return; - } - - txt_save_colours(&colors); - txt_fgcolour(TXT_COLOR_BLACK); - txt_bgcolour(TXT_COLOR_GREY, 0); - - txt_goto_xy(x, y); - txt_putchar('\x18'); - - cursor_y = y + 1; - - if (cursor_y > y + h - 2) - { - cursor_y = y + h - 2; - } - - if (range > 0) - { - cursor_y += (cursor * (h - 3)) / range; - } - - for (y1 = y + 1; y1 < y + h - 1; ++y1) - { - if (VALID_Y(y1)) - { - txt_goto_xy(x, y1); - - if (y1 == cursor_y) - { - txt_putchar('\xdb'); - } - else - { - txt_putchar('\xb1'); - } - } - } - - txt_goto_xy(x, y + h - 1); - txt_putchar('\x19'); - txt_restore_colours(&colors); -} - -void txt_init_clip_area(void) -{ - if (g_cliparea == NULL) - { - g_cliparea = malloc(sizeof(txt_cliparea_t)); - g_cliparea->x1 = 0; - g_cliparea->x2 = TXT_SCREEN_W; - g_cliparea->y1 = 0; - g_cliparea->y2 = TXT_SCREEN_H; - g_cliparea->next = NULL; - } -} - -void txt_push_clip_area(int x1, int x2, int y1, int y2) -{ - txt_cliparea_t *newarea; - - newarea = malloc(sizeof(txt_cliparea_t)); - - /* Set the new clip area to the intersection of the old - * area and the new one. - */ - - newarea->x1 = g_cliparea->x1; - newarea->x2 = g_cliparea->x2; - newarea->y1 = g_cliparea->y1; - newarea->y2 = g_cliparea->y2; - - if (x1 > newarea->x1) newarea->x1 = x1; - if (x2 < newarea->x2) newarea->x2 = x2; - if (y1 > newarea->y1) newarea->y1 = y1; - if (y2 < newarea->y2) newarea->y2 = y2; - -#if 0 - printf("New scrollable area: %i,%i-%i,%i\n", x1, y1, x2, y2); -#endif - - /* Hook into the list */ - - newarea->next = g_cliparea; - g_cliparea = newarea; -} - -void txt_pop_clip_area(void) -{ - txt_cliparea_t *next_cliparea; - - /* Never pop the last entry */ - - if (g_cliparea->next == NULL) return; - - /* Unlink the last entry and delete */ - - next_cliparea = g_cliparea->next; - free(g_cliparea); - g_cliparea = next_cliparea; -} diff --git a/games/NXDoom/textscreen/txt_gui.h b/games/NXDoom/textscreen/txt_gui.h deleted file mode 100644 index 3dfe0f59a..000000000 --- a/games/NXDoom/textscreen/txt_gui.h +++ /dev/null @@ -1,50 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/textscreen/txt_gui.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * - * Text mode emulation in SDL - * - ****************************************************************************/ - -#ifndef TXT_GUI_H -#define TXT_GUI_H - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define TXT_INACTIVE_WINDOW_BACKGROUND TXT_COLOR_BLACK -#define TXT_ACTIVE_WINDOW_BACKGROUND TXT_COLOR_BLUE -#define TXT_HOVER_BACKGROUND TXT_COLOR_CYAN - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -void txt_draw_window_frame(const char *title, int x, int y, int w, int h); -void txt_draw_separator(int x, int y, int w); -void txt_draw_code_page_string(const char *s); -void txt_draw_string(const char *s); - -void txt_draw_horiz_scrollbar(int x, int y, int w, int cursor, int range); -void txt_draw_vert_scrollbar(int x, int y, int h, int cursor, int range); - -void txt_init_clip_area(void); -void txt_push_clip_area(int x1, int x2, int y1, int y2); -void txt_pop_clip_area(void); - -#endif /* TXT_GUI_H */ diff --git a/games/NXDoom/textscreen/txt_inputbox.c b/games/NXDoom/textscreen/txt_inputbox.c deleted file mode 100644 index 17801687a..000000000 --- a/games/NXDoom/textscreen/txt_inputbox.c +++ /dev/null @@ -1,387 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/textscreen/txt_inputbox.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include -#include - -#include "doomkeys.h" - -#include "txt_gui.h" -#include "txt_inputbox.h" -#include "txt_io.h" -#include "txt_main.h" -#include "txt_utf8.h" -#include "txt_window.h" - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -static void txt_input_box_size_calc(TXT_UNCAST_ARG(inputbox)); -static void txt_input_box_drawer(TXT_UNCAST_ARG(inputbox)); -static int txt_input_box_keypress(TXT_UNCAST_ARG(inputbox), int key); -static void txt_input_box_destructor(TXT_UNCAST_ARG(inputbox)); -static void txt_input_box_mousepress(TXT_UNCAST_ARG(inputbox), int x, int y, - int b); -static void txt_input_box_focused(TXT_UNCAST_ARG(inputbox), int focused); - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -txt_widget_class_t txt_inputbox_class; -txt_widget_class_t txt_int_inputbox_class; - -txt_widget_class_t txt_inputbox_class = -{ - txt_always_selectable, - txt_input_box_size_calc, - txt_input_box_drawer, - txt_input_box_keypress, - txt_input_box_destructor, - txt_input_box_mousepress, - NULL, - txt_input_box_focused, -}; - -txt_widget_class_t txt_int_inputbox_class = -{ - txt_always_selectable, - txt_input_box_size_calc, - txt_input_box_drawer, - txt_input_box_keypress, - txt_input_box_destructor, - txt_input_box_mousepress, - NULL, - txt_input_box_focused, -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static void set_buffer_from_value(txt_inputbox_t *inputbox) -{ - if (inputbox->widget.widget_class == &txt_inputbox_class) - { - char **value = (char **)inputbox->value; - - if (*value != NULL) - { - txt_string_copy(inputbox->buffer, *value, - strnlen(*value, inputbox->buffer_len) + 1); - } - else - { - txt_string_copy(inputbox->buffer, "", inputbox->buffer_len); - } - } - else if (inputbox->widget.widget_class == &txt_int_inputbox_class) - { - int *value = (int *)inputbox->value; - txt_snprintf(inputbox->buffer, inputbox->buffer_len, "%i", *value); - } -} - -static void start_editing(txt_inputbox_t *inputbox) -{ - /* Integer input boxes start from an empty buffer: */ - - if (inputbox->widget.widget_class == &txt_int_inputbox_class) - { - txt_string_copy(inputbox->buffer, "", inputbox->buffer_len); - } - else - { - set_buffer_from_value(inputbox); - } - - /* Switch to text input mode so we get shifted input. */ - - txt_set_input_mode(TXT_INPUT_TEXT); - inputbox->editing = 1; -} - -static void stop_editing(txt_inputbox_t *inputbox) -{ - if (inputbox->editing) - { - /* Switch back to normal input mode. */ - - txt_set_input_mode(TXT_INPUT_NORMAL); - inputbox->editing = 0; - } -} - -static void finish_editing(txt_inputbox_t *inputbox) -{ - if (!inputbox->editing) - { - return; - } - - /* Save the new value back to the variable. */ - - if (inputbox->widget.widget_class == &txt_inputbox_class) - { - free(*((char **)inputbox->value)); - *((char **)inputbox->value) = strdup(inputbox->buffer); - } - else if (inputbox->widget.widget_class == &txt_int_inputbox_class) - { - *((int *)inputbox->value) = atoi(inputbox->buffer); - } - - txt_emit_signal(&inputbox->widget, "changed"); - - stop_editing(inputbox); -} - -static void txt_input_box_size_calc(TXT_UNCAST_ARG(inputbox)) -{ - TXT_CAST_ARG(txt_inputbox_t, inputbox); - - /* Enough space for the box + cursor */ - - inputbox->widget.w = inputbox->size + 1; - inputbox->widget.h = 1; -} - -static void txt_input_box_drawer(TXT_UNCAST_ARG(inputbox)) -{ - TXT_CAST_ARG(txt_inputbox_t, inputbox); - int focused; - int i; - int chars; - int w; - - focused = inputbox->widget.focused; - w = inputbox->widget.w; - - /* Select the background color based on whether we are currently - * editing, and if not, whether the widget is focused. - */ - - if (inputbox->editing && focused) - { - txt_bgcolour(TXT_COLOR_BLACK, 0); - } - else - { - txt_set_widget_bg(inputbox); - } - - if (!inputbox->editing) - { - /* If not editing, use the current value from inputbox->value. */ - - set_buffer_from_value(inputbox); - } - - /* If string size exceeds the widget's width, show only the end. */ - - if (txt_utf8_strlen(inputbox->buffer) > w - 1) - { - txt_draw_code_page_string("\xae"); - txt_draw_string(txt_utf8_skip_chars( - inputbox->buffer, txt_utf8_strlen(inputbox->buffer) - w + 2)); - chars = w - 1; - } - else - { - txt_draw_string(inputbox->buffer); - chars = txt_utf8_strlen(inputbox->buffer); - } - - if (chars < w && inputbox->editing && focused) - { - txt_bgcolour(TXT_COLOR_BLACK, 1); - txt_draw_string("_"); - ++chars; - } - - for (i = chars; i < w; ++i) - { - txt_draw_string(" "); - } -} - -static void txt_input_box_destructor(TXT_UNCAST_ARG(inputbox)) -{ - TXT_CAST_ARG(txt_inputbox_t, inputbox); - - stop_editing(inputbox); - free(inputbox->buffer); -} - -static void backspace(txt_inputbox_t *inputbox) -{ - unsigned int len; - char *p; - - len = txt_utf8_strlen(inputbox->buffer); - - if (len > 0) - { - p = txt_utf8_skip_chars(inputbox->buffer, len - 1); - *p = '\0'; - } -} - -static void add_character(txt_inputbox_t *inputbox, int key) -{ - char *end; - char *p; - - if (txt_utf8_strlen(inputbox->buffer) < inputbox->size) - { - /* Add character to the buffer */ - - end = inputbox->buffer + strlen(inputbox->buffer); - p = txt_encode_utf8(end, key); - *p = '\0'; - } -} - -static int txt_input_box_keypress(TXT_UNCAST_ARG(inputbox), int key) -{ - TXT_CAST_ARG(txt_inputbox_t, inputbox); - unsigned int c; - - if (!inputbox->editing) - { - if (key == KEY_ENTER) - { - start_editing(inputbox); - return 1; - } - - /* Backspace or delete erases the contents of the box. */ - - if ((key == KEY_DEL || key == KEY_BACKSPACE) && - inputbox->widget.widget_class == &txt_inputbox_class) - { - free(*((char **)inputbox->value)); - *((char **)inputbox->value) = strdup(""); - } - - return 0; - } - - if (key == KEY_ENTER) - { - finish_editing(inputbox); - } - - if (key == KEY_ESCAPE) - { - stop_editing(inputbox); - } - - if (key == KEY_BACKSPACE) - { - backspace(inputbox); - } - - c = TXT_KEY_TO_UNICODE(key); - - /* Add character to the buffer, but only if it's a printable character - * that we can represent on the screen. - */ - - if (isprint(c) || (c >= 128 && txt_unicode_character(c) >= 0)) - { - add_character(inputbox, c); - } - - return 1; -} - -static void txt_input_box_mousepress(TXT_UNCAST_ARG(inputbox), int x, int y, - int b) -{ - TXT_CAST_ARG(txt_inputbox_t, inputbox); - - if (b == TXT_MOUSE_LEFT) - { - /* Make mouse clicks start editing the box */ - - if (!inputbox->editing) - { - /* Send a simulated keypress to start editing */ - - txt_widget_key_press(inputbox, KEY_ENTER); - } - } -} - -static void txt_input_box_focused(TXT_UNCAST_ARG(inputbox), int focused) -{ - TXT_CAST_ARG(txt_inputbox_t, inputbox); - - /* Stop editing when we lose focus. */ - - if (inputbox->editing && !focused) - { - finish_editing(inputbox); - } -} - -static txt_inputbox_t *new_input_box(txt_widget_class_t *widget_class, - void *value, int size) -{ - txt_inputbox_t *inputbox; - - inputbox = malloc(sizeof(txt_inputbox_t)); - - txt_init_widget(inputbox, widget_class); - inputbox->value = value; - inputbox->size = size; - - /* 'size' is the maximum number of characters that can be entered, - * but for a UTF-8 string, each character can take up to four - * characters. - */ - - inputbox->buffer_len = size * 4 + 1; - inputbox->buffer = malloc(inputbox->buffer_len); - inputbox->editing = 0; - - return inputbox; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -txt_inputbox_t *txt_new_input_box(char **value, int size) -{ - return new_input_box(&txt_inputbox_class, value, size); -} - -txt_inputbox_t *txt_new_int_input_box(int *value, int size) -{ - return new_input_box(&txt_int_inputbox_class, value, size); -} diff --git a/games/NXDoom/textscreen/txt_inputbox.h b/games/NXDoom/textscreen/txt_inputbox.h deleted file mode 100644 index 077df013e..000000000 --- a/games/NXDoom/textscreen/txt_inputbox.h +++ /dev/null @@ -1,82 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/textscreen/txt_inputbox.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - ****************************************************************************/ - -#ifndef TXT_INPUTBOX_H -#define TXT_INPUTBOX_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "txt_widget.h" - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -/* Input box widget. - * - * An input box is a widget that displays a value, which can be - * selected to enter a new value. - * - * Input box widgets can be of an integer or string type. - */ - -struct txt_inputbox_s -{ - txt_widget_t widget; - char *buffer; - size_t buffer_len; - unsigned int size; - int editing; - void *value; -}; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/** - * Create a new input box widget for controlling a string value. - * - * @param value Pointer to a string variable that contains - * a pointer to the current value of the - * input box. The value should be allocated - * dynamically; when the string is changed it - * will be freed and the variable set to point - * to the new string value. String will be in - * UTF-8 format. - * @param size Width of the input box, in characters. - * @return Pointer to the new input box widget. - */ - -txt_inputbox_t *txt_new_input_box(char **value, int size); - -/** - * Create a new input box widget for controlling an integer value. - * - * @param value Pointer to an integer variable containing - * the value of the input box. - * @param size Width of the input box, in characters. - * @return Pointer to the new input box widget. - */ - -txt_inputbox_t *txt_new_int_input_box(int *value, int size); - -#endif /* TXT_INPUTBOX_H */ diff --git a/games/NXDoom/textscreen/txt_io.c b/games/NXDoom/textscreen/txt_io.c deleted file mode 100644 index f8127f17d..000000000 --- a/games/NXDoom/textscreen/txt_io.c +++ /dev/null @@ -1,197 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/textscreen/txt_io.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * - * Text mode I/O functions, similar to C stdio - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -#include "txt_io.h" -#include "txt_main.h" - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static int g_cur_x = 0; -static int g_cur_y = 0; -static txt_color_t g_fgcolour = TXT_COLOR_GREY; -static txt_color_t g_bgcolour = TXT_COLOR_BLACK; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -#if 0 /* UNUSED */ -static void txt_clear_screen(void) -{ - unsigned char *screen; - int i; - - screen = txt_get_screen_data(); - - for (i = 0; i < TXT_SCREEN_W * TXT_SCREEN_H; ++i) - { - screen[i * 2] = ' '; - screen[i * 2 + 1] = (bgcolor << 4) | fgcolor; - } - - cur_x = 0; - cur_y = 0; -} -#endif - -static void new_line(unsigned char *screendata) -{ - int i; - unsigned char *p; - - g_cur_x = 0; - ++g_cur_y; - - if (g_cur_y >= TXT_SCREEN_H) - { - /* Scroll the screen up */ - - g_cur_y = TXT_SCREEN_H - 1; - - memmove(screendata, screendata + TXT_SCREEN_W * 2, - TXT_SCREEN_W * 2 * (TXT_SCREEN_H - 1)); - - /* Clear the bottom line */ - - p = screendata + (TXT_SCREEN_H - 1) * 2 * TXT_SCREEN_W; - - for (i = 0; i < TXT_SCREEN_W; ++i) - { - *p++ = ' '; - *p++ = g_fgcolour | (g_bgcolour << 4); - } - } -} - -static void put_symbol(unsigned char *screendata, int c) -{ - unsigned char *p; - - p = screendata + g_cur_y * TXT_SCREEN_W * 2 + g_cur_x * 2; - - /* Add a new character to the buffer */ - - p[0] = c; - p[1] = g_fgcolour | (g_bgcolour << 4); - - ++g_cur_x; - - if (g_cur_x >= TXT_SCREEN_W) - { - new_line(screendata); - } -} - -static void put_char(unsigned char *screendata, int c) -{ - switch (c) - { - case '\n': - new_line(screendata); - break; - - case '\b': - - /* backspace */ - - --g_cur_x; - if (g_cur_x < 0) g_cur_x = 0; - break; - - default: - put_symbol(screendata, c); - break; - } -} - -/* "Blind" version of txt_putchar() below which doesn't do any interpretation - * of control signals. Just write a particular symbol to the screen buffer. - */ - -void txt_put_symbol(int c) -{ - put_symbol(txt_get_screen_data(), c); -} - -void txt_putchar(int c) -{ - put_char(txt_get_screen_data(), c); -} - -void txt_puts(const char *s) -{ - unsigned char *screen; - const char *p; - - screen = txt_get_screen_data(); - - for (p = s; *p != '\0'; ++p) - { - put_char(screen, *p); - } - - put_char(screen, '\n'); -} - -void txt_goto_xy(int x, int y) -{ - g_cur_x = x; - g_cur_y = y; -} - -void txt_get_xy(int *x, int *y) -{ - *x = g_cur_x; - *y = g_cur_y; -} - -void txt_fgcolour(txt_color_t color) -{ - g_fgcolour = color; -} - -void txt_bgcolour(int color, int blinking) -{ - g_bgcolour = color; - if (blinking) g_bgcolour |= TXT_COLOR_BLINKING; -} - -void txt_save_colours(txt_saved_colors_t *save) -{ - save->bgcolor = g_bgcolour; - save->fgcolor = g_fgcolour; -} - -void txt_restore_colours(txt_saved_colors_t *save) -{ - g_bgcolour = save->bgcolor; - g_fgcolour = save->fgcolor; -} diff --git a/games/NXDoom/textscreen/txt_io.h b/games/NXDoom/textscreen/txt_io.h deleted file mode 100644 index 7d91b885b..000000000 --- a/games/NXDoom/textscreen/txt_io.h +++ /dev/null @@ -1,55 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/textscreen/txt_io.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * Text mode emulation in SDL - * - ****************************************************************************/ - -#ifndef TXT_IO_H -#define TXT_IO_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "txt_main.h" - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -typedef struct -{ - int bgcolor; - int fgcolor; -} txt_saved_colors_t; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -void txt_put_symbol(int c); -void txt_putchar(int c); -void txt_puts(const char *s); -void txt_goto_xy(int x, int y); -void txt_get_xy(int *x, int *y); -void txt_fgcolour(txt_color_t color); -void txt_bgcolour(int color, int blinking); -void txt_save_colours(txt_saved_colors_t *save); -void txt_restore_colours(txt_saved_colors_t *save); - -#endif /* TXT_IO_H */ diff --git a/games/NXDoom/textscreen/txt_label.c b/games/NXDoom/textscreen/txt_label.c deleted file mode 100644 index c943b1b50..000000000 --- a/games/NXDoom/textscreen/txt_label.c +++ /dev/null @@ -1,234 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/textscreen/txt_label.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -#include "txt_gui.h" -#include "txt_io.h" -#include "txt_label.h" -#include "txt_main.h" -#include "txt_utf8.h" -#include "txt_window.h" - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -static void txt_label_size_calc(TXT_UNCAST_ARG(label)); -static void txt_label_drawer(TXT_UNCAST_ARG(label)); -static void txt_label_destructor(TXT_UNCAST_ARG(label)); - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -txt_widget_class_t txt_label_class = -{ - txt_never_selectable, - txt_label_size_calc, - txt_label_drawer, - NULL, - txt_label_destructor, - NULL, - NULL, -}; - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -static void txt_label_size_calc(TXT_UNCAST_ARG(label)) -{ - TXT_CAST_ARG(txt_label_t, label); - - label->widget.w = label->w; - label->widget.h = label->h; -} - -static void txt_label_drawer(TXT_UNCAST_ARG(label)) -{ - TXT_CAST_ARG(txt_label_t, label); - unsigned int x; - unsigned int y; - int origin_x; - int origin_y; - unsigned int align_indent = 0; - unsigned int w; - unsigned int sw; - - w = label->widget.w; - - if (label->bgcolor >= 0) - { - txt_bgcolour(label->bgcolor, 0); - } - if (label->fgcolor >= 0) - { - txt_fgcolour(label->fgcolor); - } - - txt_get_xy(&origin_x, &origin_y); - - for (y = 0; y < label->h; ++y) - { - /* Calculate the amount to indent this line due to the align - * setting - */ - - sw = txt_utf8_strlen(label->lines[y]); - switch (label->widget.align) - { - case TXT_HORIZ_LEFT: - align_indent = 0; - break; - case TXT_HORIZ_CENTER: - align_indent = (label->w - sw) / 2; - break; - case TXT_HORIZ_RIGHT: - align_indent = label->w - sw; - break; - } - - /* Draw this line */ - - txt_goto_xy(origin_x, origin_y + y); - - /* Gap at the start */ - - for (x = 0; x < align_indent; ++x) - { - txt_draw_string(" "); - } - - /* The string itself */ - - txt_draw_string(label->lines[y]); - x += sw; - - /* Gap at the end */ - - for (; x < w; ++x) - { - txt_draw_string(" "); - } - } -} - -static void txt_label_destructor(TXT_UNCAST_ARG(label)) -{ - TXT_CAST_ARG(txt_label_t, label); - - free(label->label); - free(label->lines); -} - -#if 0 /* UNUSED */ -static void txt_set_bg_colour(txt_label_t *label, txt_color_t color) -{ - label->bgcolor = color; -} -#endif - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -void txt_set_label(txt_label_t *label, const char *value) -{ - char *p; - unsigned int y; - - /* Free back the old label */ - - free(label->label); - free(label->lines); - - /* Set the new value */ - - label->label = strdup(value); - - /* Work out how many lines in this label */ - - label->h = 1; - - for (p = label->label; *p != '\0'; ++p) - { - if (*p == '\n') - { - ++label->h; - } - } - - /* Split into lines */ - - label->lines = malloc(sizeof(char *) * label->h); - label->lines[0] = label->label; - y = 1; - - for (p = label->label; *p != '\0'; ++p) - { - if (*p == '\n') - { - label->lines[y] = p + 1; - *p = '\0'; - ++y; - } - } - - label->w = 0; - - for (y = 0; y < label->h; ++y) - { - unsigned int line_len; - - line_len = txt_utf8_strlen(label->lines[y]); - - if (line_len > label->w) label->w = line_len; - } -} - -txt_label_t *txt_new_label(const char *text) -{ - txt_label_t *label; - - label = malloc(sizeof(txt_label_t)); - - txt_init_widget(label, &txt_label_class); - label->label = NULL; - label->lines = NULL; - - /* Default colors */ - - label->bgcolor = -1; - label->fgcolor = -1; - - txt_set_label(label, text); - - return label; -} - -void txt_set_fg_colour(txt_label_t *label, txt_color_t color) -{ - label->fgcolor = color; -} diff --git a/games/NXDoom/textscreen/txt_label.h b/games/NXDoom/textscreen/txt_label.h deleted file mode 100644 index f7f1b1033..000000000 --- a/games/NXDoom/textscreen/txt_label.h +++ /dev/null @@ -1,84 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/textscreen/txt_label.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - ****************************************************************************/ - -#ifndef TXT_LABEL_H -#define TXT_LABEL_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "txt_main.h" -#include "txt_widget.h" - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -/** - * Label widget. - * - * A label widget does nothing except show a text label. - */ - -typedef struct txt_label_s txt_label_t; - -struct txt_label_s -{ - txt_widget_t widget; - char *label; - char **lines; - unsigned int w; - unsigned int h; - int fgcolor; - int bgcolor; -}; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/** - * Create a new label widget. - * - * @param label String to display in the widget (UTF-8 format). - * @return Pointer to the new label widget. - */ - -txt_label_t *txt_new_label(const char *label); - -/** - * Set the string displayed in a label widget. - * - * @param label The widget. - * @param value The string to display (UTF-8 format). - */ - -void txt_set_label(txt_label_t *label, const char *value); - -/** - * Set the foreground color of a label widget. - * - * @param label The widget. - * @param color The foreground color to use. - */ - -void txt_set_fg_colour(txt_label_t *label, txt_color_t color); - -#endif /* TXT_LABEL_H */ diff --git a/games/NXDoom/textscreen/txt_main.h b/games/NXDoom/textscreen/txt_main.h deleted file mode 100644 index 34a92bde8..000000000 --- a/games/NXDoom/textscreen/txt_main.h +++ /dev/null @@ -1,255 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/textscreen/txt_main.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * - * Base interface that abstracts the text mode screen. - * - ****************************************************************************/ - -#ifndef TXT_MAIN_H -#define TXT_MAIN_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -/* For the moment, txt_sdl.c is the only implementation of the base - * text mode screen API: - */ - -#include "txt_sdl.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* textscreen key values: - * Key values are difficult because we have to support multiple conflicting - * address spaces. - * First, Doom's key constants use 0-127 as ASCII and extra values from - * 128-255 to represent special keys. Second, mouse buttons are represented - * as buttons. Finally, we want to be able to support Unicode. - * - * So we define different ranges: - * 0-255: Doom key constants, including ASCII. - * 256-511: Mouse buttons and other reserved. - * >=512: Unicode values greater than 127 are offset up into this range. - - * Special keypress values that correspond to mouse button clicks - */ - -#define TXT_MOUSE_BASE 256 -#define TXT_MOUSE_LEFT (TXT_MOUSE_BASE + 0) -#define TXT_MOUSE_RIGHT (TXT_MOUSE_BASE + 1) -#define TXT_MOUSE_MIDDLE (TXT_MOUSE_BASE + 2) -#define TXT_MOUSE_SCROLLUP (TXT_MOUSE_BASE + 3) -#define TXT_MOUSE_SCROLLDOWN (TXT_MOUSE_BASE + 4) -#define TXT_MOUSE_X1 (TXT_MOUSE_BASE + 5) -#define TXT_MOUSE_X2 (TXT_MOUSE_BASE + 6) -#define TXT_MAX_MOUSE_BUTTONS 16 - -#define TXT_KEY_TO_MOUSE_BUTTON(x) \ - ((x) >= TXT_MOUSE_BASE && (x) < TXT_MOUSE_BASE + TXT_MAX_MOUSE_BUTTONS \ - ? (x) - TXT_MOUSE_BASE \ - : -1) - -/* Unicode offset. Unicode values from 128 onwards are offset up into - * this range, so TXT_UNICODE_BASE = Unicode character #128, and so on. - */ - -#define TXT_UNICODE_BASE 512 - -/* Convert a key value to a Unicode character: */ - -#define TXT_KEY_TO_UNICODE(x) \ - ((x) < 128 ? (x) \ - : (x) >= TXT_UNICODE_BASE ? ((x) - TXT_UNICODE_BASE + 128) \ - : 0) - -/* Convert a Unicode character to a key value: */ - -#define TXT_UNICODE_TO_KEY(u) \ - ((u) < 128 ? (u) : ((u) - 128 + TXT_UNICODE_BASE)) - -/* Screen size */ - -#define TXT_SCREEN_W 80 -#define TXT_SCREEN_H 25 - -#define TXT_COLOR_BLINKING (1 << 3) - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -typedef enum -{ - TXT_COLOR_BLACK, - TXT_COLOR_BLUE, - TXT_COLOR_GREEN, - TXT_COLOR_CYAN, - TXT_COLOR_RED, - TXT_COLOR_MAGENTA, - TXT_COLOR_BROWN, - TXT_COLOR_GREY, - TXT_COLOR_DARK_GREY, - TXT_COLOR_BRIGHT_BLUE, - TXT_COLOR_BRIGHT_GREEN, - TXT_COLOR_BRIGHT_CYAN, - TXT_COLOR_BRIGHT_RED, - TXT_COLOR_BRIGHT_MAGENTA, - TXT_COLOR_YELLOW, - TXT_COLOR_BRIGHT_WHITE, -} txt_color_t; - -/* Modifier keys. */ - -typedef enum -{ - TXT_MOD_SHIFT, - TXT_MOD_CTRL, - TXT_MOD_ALT, - TXT_NUM_MODIFIERS -} txt_modifier_t; - -/* Due to the way the SDL API works, we provide different ways of configuring - * how we read input events, each of which is useful in different scenarios. - */ - -typedef enum -{ - /* "Localized" output that takes software keyboard layout into account, - * but key shifting has no effect. - */ - - TXT_INPUT_NORMAL, - - /* "Raw" input; the keys correspond to physical keyboard layout and - * software keyboard layout has no effect. - */ - - TXT_INPUT_RAW, - - /* Used for full text input. Events are fully shifted and localized. - * However, not all keyboard keys will generate input. - * Setting this mode may activate the on-screen keyboard, depending on - * device and OS. - */ - - TXT_INPUT_TEXT, -} txt_input_mode_t; - -#ifdef __GNUC__ - -#define PRINTF_ATTR(fmt, first) __attribute__((format(printf, fmt, first))) - -#else /* __GNUC__ */ - -#define PRINTF_ATTR(fmt, first) - -#endif /* __GNUC__ */ - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/* Initialize the screen - * Returns 1 if successful, 0 if failed. - */ - -int txt_init(void); - -/* Shut down text mode emulation */ - -void txt_shutdown(void); - -/* Get a pointer to the buffer containing the raw screen data. */ - -unsigned char *txt_get_screen_data(void); - -/* Update an area of the screen */ - -void txt_update_screen_area(int x, int y, int w, int h); - -/* Update the whole screen */ - -void txt_update_screen(void); - -/* Set the RGB value for a particular entry in the color palette: */ - -void txt_set_colour(txt_color_t color, int r, int g, int b); - -/* Read a character from the keyboard */ - -int txt_getchar(void); - -/* Given a Unicode character, get a character that can be used to represent - * it on the code page being displayed on the screen. If the character cannot - * be represented, this returns -1. - */ - -int txt_unicode_character(unsigned int c); - -/* Read the current state of modifier keys that are held down. */ - -int txt_get_modifier_state(txt_modifier_t mod); - -/* Provides a short description of a key code, placing into the provided - * buffer. Note that the key is assumed to represent a physical key on the - * keyboard (like that returned by TXT_INPUT_RAW), and the resulting string - * takes keyboard layout into consideration. For example, - * txt_get_key_description('q') on a French keyboard returns "A". - * The contents of the filled buffer will be in UTF-8 format, but will never - * contain characters which can't be shown on the screen. - */ - -void txt_get_key_description(int key, char *buf, size_t buf_len); - -/* Retrieve the current position of the mouse */ - -void txt_get_mouse_position(int *x, int *y); - -/* Sleep until an event is received or the screen needs updating - * Optional timeout in ms (timeout == 0 : sleep forever) - */ - -void txt_sleep(int timeout); - -/* Change mode for text input. */ - -void txt_set_input_mode(txt_input_mode_t mode); - -/* Set the window title of the window containing the text mode screen */ - -void txt_set_window_title(const char *title); - -/* Safe string copy. */ - -void txt_string_copy(char *dest, const char *src, size_t dest_len); - -/* Safe version of vsnprintf(). */ - -int txt_vsnprintf(char *buf, size_t buf_len, const char *s, va_list args); - -/* Safe version of snprintf(). */ - -int txt_snprintf(char *buf, size_t buf_len, const char *s, ...) - PRINTF_ATTR(3, 4); - -#endif /* TXT_MAIN_H */ diff --git a/games/NXDoom/textscreen/txt_radiobutton.c b/games/NXDoom/textscreen/txt_radiobutton.c deleted file mode 100644 index b13c617c9..000000000 --- a/games/NXDoom/textscreen/txt_radiobutton.c +++ /dev/null @@ -1,179 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/textscreen/txt_radiobutton.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -#include "doomkeys.h" - -#include "txt_gui.h" -#include "txt_io.h" -#include "txt_main.h" -#include "txt_radiobutton.h" -#include "txt_utf8.h" -#include "txt_window.h" - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -static void txt_radio_button_size_calc(TXT_UNCAST_ARG(radiobutton)); -static void txt_radio_button_drawer(TXT_UNCAST_ARG(radiobutton)); -static void txt_radio_button_destructor(TXT_UNCAST_ARG(radiobutton)); -static int txt_radio_button_keypress(TXT_UNCAST_ARG(radiobutton), int key); -static void txt_radio_button_mousepress(TXT_UNCAST_ARG(radiobutton), int x, - int y, int b); - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -txt_widget_class_t txt_radiobutton_class = -{ - txt_always_selectable, - txt_radio_button_size_calc, - txt_radio_button_drawer, - txt_radio_button_keypress, - txt_radio_button_destructor, - txt_radio_button_mousepress, - NULL, -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static void txt_radio_button_size_calc(TXT_UNCAST_ARG(radiobutton)) -{ - TXT_CAST_ARG(txt_radiobutton_t, radiobutton); - - /* Minimum width is the string length + right-side spaces for padding */ - - radiobutton->widget.w = txt_utf8_strlen(radiobutton->label) + 5; - radiobutton->widget.h = 1; -} - -static void txt_radio_button_drawer(TXT_UNCAST_ARG(radiobutton)) -{ - TXT_CAST_ARG(txt_radiobutton_t, radiobutton); - txt_saved_colors_t colors; - int i; - int w; - - w = radiobutton->widget.w; - - txt_save_colours(&colors); - txt_fgcolour(TXT_COLOR_BRIGHT_CYAN); - txt_draw_string("("); - - txt_fgcolour(TXT_COLOR_BRIGHT_WHITE); - - if (*radiobutton->variable == radiobutton->value) - { - txt_draw_code_page_string("\x07"); - } - else - { - txt_draw_string(" "); - } - - txt_fgcolour(TXT_COLOR_BRIGHT_CYAN); - - txt_draw_string(") "); - - txt_restore_colours(&colors); - txt_set_widget_bg(radiobutton); - - txt_draw_string(radiobutton->label); - - for (i = txt_utf8_strlen(radiobutton->label); i < w - 5; ++i) - { - txt_draw_string(" "); - } -} - -static void txt_radio_button_destructor(TXT_UNCAST_ARG(radiobutton)) -{ - TXT_CAST_ARG(txt_radiobutton_t, radiobutton); - - free(radiobutton->label); -} - -static int txt_radio_button_keypress(TXT_UNCAST_ARG(radiobutton), int key) -{ - TXT_CAST_ARG(txt_radiobutton_t, radiobutton); - - if (key == KEY_ENTER || key == ' ') - { - if (*radiobutton->variable != radiobutton->value) - { - *radiobutton->variable = radiobutton->value; - txt_emit_signal(radiobutton, "selected"); - } - - return 1; - } - - return 0; -} - -static void txt_radio_button_mousepress(TXT_UNCAST_ARG(radiobutton), int x, - int y, int b) -{ - TXT_CAST_ARG(txt_radiobutton_t, radiobutton); - - if (b == TXT_MOUSE_LEFT) - { - /* Equivalent to pressing enter */ - - txt_radio_button_keypress(radiobutton, KEY_ENTER); - } -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -txt_radiobutton_t *txt_new_radio_button(const char *label, int *variable, - int value) -{ - txt_radiobutton_t *radiobutton; - - radiobutton = malloc(sizeof(txt_radiobutton_t)); - - txt_init_widget(radiobutton, &txt_radiobutton_class); - radiobutton->label = strdup(label); - radiobutton->variable = variable; - radiobutton->value = value; - - return radiobutton; -} - -#if 0 /* UNUSED */ -static void txt_set_radio_button_label(txt_radiobutton_t *radiobutton, - const char *value) -{ - free(radiobutton->label); - radiobutton->label = strdup(value); -} -#endif diff --git a/games/NXDoom/textscreen/txt_radiobutton.h b/games/NXDoom/textscreen/txt_radiobutton.h deleted file mode 100644 index f5cafb6c8..000000000 --- a/games/NXDoom/textscreen/txt_radiobutton.h +++ /dev/null @@ -1,77 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/textscreen/txt_radiobutton.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - ****************************************************************************/ - -#ifndef TXT_RADIOBUTTON_H -#define TXT_RADIOBUTTON_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "txt_widget.h" - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -/* A radio button widget. - * - * Radio buttons are typically used in groups, to allow a value to be - * selected from a range of options. Each radio button corresponds - * to a particular option that may be selected. A radio button - * has an indicator to indicate whether it is the currently-selected - * value, and a text label. - * - * Internally, a radio button tracks an integer variable that may take - * a range of different values. Each radio button has a particular - * value associated with it; if the variable is equal to that value, - * the radio button appears selected. If a radio button is pressed - * by the user through the GUI, the variable is set to its value. - * - * When a radio button is selected, the "selected" signal is emitted. - */ - -struct txt_radiobutton_s -{ - txt_widget_t widget; - char *label; - int *variable; - int value; -}; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/** - * Create a new radio button widget. - * - * @param label The label to display next to the radio button - * (UTF-8 format). - * @param variable Pointer to the variable tracking whether this - * radio button is selected. - * @param value If the variable is equal to this value, the - * radio button appears selected. - * @return Pointer to the new radio button widget. - */ - -txt_radiobutton_t *txt_new_radio_button(const char *label, int *variable, - int value); - -#endif /* TXT_RADIOBUTTON_H */ diff --git a/games/NXDoom/textscreen/txt_scrollpane.c b/games/NXDoom/textscreen/txt_scrollpane.c deleted file mode 100644 index 4fa3b7184..000000000 --- a/games/NXDoom/textscreen/txt_scrollpane.c +++ /dev/null @@ -1,638 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/textscreen/txt_scrollpane.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include -#include -#include - -#include "txt_gui.h" -#include "txt_io.h" -#include "txt_main.h" -#include "txt_scrollpane.h" -#include "txt_table.h" - -#include "doomkeys.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define SCROLLBAR_VERTICAL (1 << 0) -#define SCROLLBAR_HORIZONTAL (1 << 1) - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -static int txt_scroll_pane_selectable(TXT_UNCAST_ARG(scrollpane)); -static void txt_scroll_pane_size_calc(TXT_UNCAST_ARG(scrollpane)); -static void txt_scroll_pane_drawer(TXT_UNCAST_ARG(scrollpane)); -static int txt_scroll_pane_keypress(TXT_UNCAST_ARG(scrollpane), int key); -static void txt_scroll_pane_destructor(TXT_UNCAST_ARG(scrollpane)); -static void txt_scroll_pane_mousepress(TXT_UNCAST_ARG(scrollpane), int x, - int y, int b); -static void txt_scroll_pane_layout(TXT_UNCAST_ARG(scrollpane)); -static void txt_scroll_pane_focus(TXT_UNCAST_ARG(scrollpane), int focused); - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -txt_widget_class_t txt_scrollpane_class = -{ - txt_scroll_pane_selectable, txt_scroll_pane_size_calc, - txt_scroll_pane_drawer, txt_scroll_pane_keypress, - txt_scroll_pane_destructor, txt_scroll_pane_mousepress, - txt_scroll_pane_layout, txt_scroll_pane_focus, -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static int full_width(txt_scrollpane_t *scrollpane) -{ - if (scrollpane->child != NULL) - { - return scrollpane->child->w; - } - else - { - return 0; - } -} - -static int full_height(txt_scrollpane_t *scrollpane) -{ - if (scrollpane->child != NULL) - { - return scrollpane->child->h; - } - else - { - return 0; - } -} - -/* Calculate which scroll bars the pane needs. */ - -static int needs_scroll_bars(txt_scrollpane_t *scrollpane) -{ - int result; - - result = 0; - - if (full_width(scrollpane) > scrollpane->w) - { - result |= SCROLLBAR_HORIZONTAL; - } - - if (full_height(scrollpane) > scrollpane->h) - { - result |= SCROLLBAR_VERTICAL; - } - - return result; -} - -/* If a scrollbar isn't needed, the scroll position is reset. */ - -static void sanity_check_scrollbars(txt_scrollpane_t *scrollpane) -{ - int scrollbars; - int max_x; - int max_y; - - scrollbars = needs_scroll_bars(scrollpane); - - if ((scrollbars & SCROLLBAR_HORIZONTAL) == 0) - { - scrollpane->x = 0; - } - - if ((scrollbars & SCROLLBAR_VERTICAL) == 0) - { - scrollpane->y = 0; - } - - max_x = full_width(scrollpane) - scrollpane->w; - max_y = full_height(scrollpane) - scrollpane->h; - - if (scrollpane->x < 0) - { - scrollpane->x = 0; - } - else if (scrollpane->x > max_x) - { - scrollpane->x = max_x; - } - - if (scrollpane->y < 0) - { - scrollpane->y = 0; - } - else if (scrollpane->y > max_y) - { - scrollpane->y = max_y; - } -} - -static void txt_scroll_pane_size_calc(TXT_UNCAST_ARG(scrollpane)) -{ - TXT_CAST_ARG(txt_scrollpane_t, scrollpane); - int scrollbars; - - if (scrollpane->child != NULL) - { - txt_calc_widget_size(scrollpane->child); - } - - /* Expand as necessary (to ensure that no scrollbars are needed)? */ - - if (scrollpane->expand_w) - { - scrollpane->w = full_width(scrollpane); - } - - if (scrollpane->expand_h) - { - scrollpane->h = full_height(scrollpane); - } - - scrollpane->widget.w = scrollpane->w; - scrollpane->widget.h = scrollpane->h; - - /* If we have scroll bars, we need to expand slightly to - * accommodate them. Eg. if we have a vertical scrollbar, we - * need to be an extra character wide. - */ - - scrollbars = needs_scroll_bars(scrollpane); - - if (scrollbars & SCROLLBAR_HORIZONTAL) - { - ++scrollpane->widget.h; - } - - if (scrollbars & SCROLLBAR_VERTICAL) - { - ++scrollpane->widget.w; - } - - if (scrollpane->child != NULL) - { - if (scrollpane->child->w < scrollpane->w) - { - scrollpane->child->w = scrollpane->w; - } - - if (scrollpane->child->h < scrollpane->h) - { - scrollpane->child->h = scrollpane->h; - } - } -} - -static void txt_scroll_pane_drawer(TXT_UNCAST_ARG(scrollpane)) -{ - TXT_CAST_ARG(txt_scrollpane_t, scrollpane); - int x1; - int y1; - int x2; - int y2; - int scrollbars; - - /* We set a clipping area of the scroll pane. */ - - x1 = scrollpane->widget.x; - y1 = scrollpane->widget.y; - x2 = x1 + scrollpane->w; - y2 = y1 + scrollpane->h; - - scrollbars = needs_scroll_bars(scrollpane); - - if (scrollbars & SCROLLBAR_HORIZONTAL) - { - txt_draw_horiz_scrollbar(x1, y1 + scrollpane->h, scrollpane->w, - scrollpane->x, - full_width(scrollpane) - scrollpane->w); - } - - if (scrollbars & SCROLLBAR_VERTICAL) - { - txt_draw_vert_scrollbar(x1 + scrollpane->w, y1, scrollpane->h, - scrollpane->y, - full_height(scrollpane) - scrollpane->h); - } - - txt_push_clip_area(x1, x2, y1, y2); - - /* Draw the child widget */ - - if (scrollpane->child != NULL) - { - txt_draw_widget(scrollpane->child); - } - - /* Restore old clipping area. */ - - txt_pop_clip_area(); -} - -static void txt_scroll_pane_destructor(TXT_UNCAST_ARG(scrollpane)) -{ - TXT_CAST_ARG(txt_scrollpane_t, scrollpane); - - if (scrollpane->child != NULL) - { - txt_destroy_widget(scrollpane->child); - } -} - -static void txt_scroll_pane_focus(TXT_UNCAST_ARG(scrollpane), int focused) -{ - TXT_CAST_ARG(txt_scrollpane_t, scrollpane); - - /* Whether the child is focused depends only on whether the scroll pane - * itself is focused. Pass through focus to the child. - */ - - if (scrollpane->child != NULL) - { - txt_set_widget_focus(scrollpane->child, focused); - } -} - -/* Hack for tables - when browsing a table inside a scroll pane, - * automatically scroll the window to show the newly-selected - * item. - */ - -static void show_selected_widget(txt_scrollpane_t *scrollpane) -{ - txt_widget_t *selected; - - selected = txt_get_selected_widget(scrollpane->child); - - /* Scroll up or down? */ - - if (selected->y <= scrollpane->widget.y) - { - scrollpane->y -= scrollpane->widget.y - selected->y; - } - else if ((signed)(selected->y + selected->h) > - (signed)(scrollpane->widget.y + scrollpane->h)) - { - scrollpane->y += (selected->y + selected->h) - - (scrollpane->widget.y + scrollpane->h); - } - - /* Scroll left or right? */ - - if (selected->x <= scrollpane->widget.x) - { - scrollpane->x -= scrollpane->widget.x - selected->x; - } - else if ((signed)(selected->x + selected->w) > - (signed)(scrollpane->widget.x + scrollpane->w)) - { - scrollpane->x += (selected->x + selected->w) - - (scrollpane->widget.x + scrollpane->w); - } -} - -/* Another hack for tables - when scrolling in 'pages', the normal key press - * event does not provide children with enough information to know how far - * to move their selection to reach a new page. This function does so. - * Note that it *only* affects scrolling in pages, not with arrows! - * A side-effect of this, rather than 'pulling' the selection to fit within - * the new page, is that we will jump straight over ranges of unselectable - * items longer than a page, but that is also true of arrow-key scrolling. - * The other unfortunate effect of doing things this way is that page keys - * have no effect on tables _not_ in scrollpanes: not even home/end. - */ - -static int page_selected_widget(txt_scrollpane_t *scrollpane, int key) -{ - int pagex = 0; /* No page left/right yet, but some keyboards have them */ - int pagey = 0; - - /* Subtract one from the absolute page distance as this is slightly more - * intuitive: a page down first jumps to the bottom of the current page, - * then proceeds to scroll onwards. - */ - - switch (key) - { - case KEY_PGUP: - pagey = 1 - scrollpane->h; - break; - - case KEY_PGDN: - pagey = scrollpane->h - 1; - break; - - default: /* We shouldn't even be in this function */ - return 0; - } - - if (scrollpane->child->widget_class == &txt_table_class) - { - return txt_page_table(scrollpane->child, pagex, pagey); - } - - return 0; -} - -/* Interpret arrow key presses as scroll commands */ - -static int interpret_scroll_key(txt_scrollpane_t *scrollpane, int key) -{ - int maxy; - - switch (key) - { - case KEY_UPARROW: - if (scrollpane->y > 0) - { - --scrollpane->y; - return 1; - } - break; - - case KEY_DOWNARROW: - if (scrollpane->y < full_height(scrollpane) - scrollpane->h) - { - ++scrollpane->y; - return 1; - } - break; - - case KEY_LEFTARROW: - if (scrollpane->x > 0) - { - --scrollpane->x; - return 1; - } - break; - - case KEY_RIGHTARROW: - if (scrollpane->x < full_width(scrollpane) - scrollpane->w) - { - ++scrollpane->x; - return 1; - } - break; - - case KEY_PGUP: - if (scrollpane->y > 0) - { - scrollpane->y -= scrollpane->h; - if (scrollpane->y < 0) - { - scrollpane->y = 0; - } - - return 1; - } - break; - - case KEY_PGDN: - maxy = full_height(scrollpane) - scrollpane->h; - if (scrollpane->y < maxy) - { - scrollpane->y += scrollpane->h; - if (scrollpane->y > maxy) - { - scrollpane->y = maxy; - } - - return 1; - } - break; - - default: - break; - } - - return 0; -} - -static int txt_scroll_pane_keypress(TXT_UNCAST_ARG(scrollpane), int key) -{ - TXT_CAST_ARG(txt_scrollpane_t, scrollpane); - int result; - - result = 0; - - if (scrollpane->child != NULL) - { - result = txt_widget_key_press(scrollpane->child, key); - - /* Gross hack - if we're scrolling in a menu with the keyboard, - * automatically move the scroll pane to show the new - * selected item. - */ - - if ((key == KEY_UPARROW || key == KEY_DOWNARROW || - key == KEY_LEFTARROW || key == KEY_RIGHTARROW || - key == KEY_PGUP || key == KEY_PGDN || key == KEY_TAB) && - scrollpane->child->widget_class == &txt_table_class) - { - if (page_selected_widget(scrollpane, key)) - { - result = 1; - } - - show_selected_widget(scrollpane); - } - - /* If the child widget didn't use the keypress, we can see - * if it can be interpreted as a scrolling command. - */ - - if (result == 0) - { - result = interpret_scroll_key(scrollpane, key); - } - } - - return result; -} - -static void txt_scroll_pane_mousepress(TXT_UNCAST_ARG(scrollpane), int x, - int y, int b) -{ - TXT_CAST_ARG(txt_scrollpane_t, scrollpane); - int scrollbars; - int rel_x; - int rel_y; - - scrollbars = needs_scroll_bars(scrollpane); - - if (b == TXT_MOUSE_SCROLLUP) - { - if (scrollbars & SCROLLBAR_VERTICAL) - { - scrollpane->y -= 3; - } - else if (scrollbars & SCROLLBAR_HORIZONTAL) - { - scrollpane->x -= 3; - } - - return; - } - else if (b == TXT_MOUSE_SCROLLDOWN) - { - if (scrollbars & SCROLLBAR_VERTICAL) - { - scrollpane->y += 3; - } - else if (scrollbars & SCROLLBAR_HORIZONTAL) - { - scrollpane->x += 3; - } - - return; - } - - rel_x = x - scrollpane->widget.x; - rel_y = y - scrollpane->widget.y; - - /* Click on the horizontal scrollbar? */ - - if ((scrollbars & SCROLLBAR_HORIZONTAL) && rel_y == scrollpane->h) - { - if (rel_x == 0) - { - --scrollpane->x; - } - else if (rel_x == scrollpane->w - 1) - { - ++scrollpane->x; - } - else - { - int range = full_width(scrollpane) - scrollpane->w; - int bar_max = scrollpane->w - 3; - - scrollpane->x = ((rel_x - 1) * range + bar_max - 1) / bar_max; - } - - return; - } - - /* Click on the vertical scrollbar? */ - - if ((scrollbars & SCROLLBAR_VERTICAL) && rel_x == scrollpane->w) - { - if (rel_y == 0) - { - --scrollpane->y; - } - else if (rel_y == scrollpane->h - 1) - { - ++scrollpane->y; - } - else - { - int range = full_height(scrollpane) - scrollpane->h; - int bar_max = scrollpane->h - 3; - - scrollpane->y = ((rel_y - 1) * range + bar_max - 1) / bar_max; - } - - return; - } - - if (scrollpane->child != NULL) - { - txt_widget_mouse_press(scrollpane->child, x, y, b); - } -} - -static void txt_scroll_pane_layout(TXT_UNCAST_ARG(scrollpane)) -{ - TXT_CAST_ARG(txt_scrollpane_t, scrollpane); - - sanity_check_scrollbars(scrollpane); - - /* The child widget takes the same position as the scroll pane - * itself, but is offset by the scroll position. - */ - - if (scrollpane->child != NULL) - { - scrollpane->child->x = scrollpane->widget.x - scrollpane->x; - scrollpane->child->y = scrollpane->widget.y - scrollpane->y; - - txt_layout_widget(scrollpane->child); - } -} - -static int txt_scroll_pane_selectable(TXT_UNCAST_ARG(scrollpane)) -{ - TXT_CAST_ARG(txt_scrollpane_t, scrollpane); - - /* If scroll bars are displayed, the scroll pane must be selectable - * so that we can use the arrow keys to scroll around. - */ - - if (needs_scroll_bars(scrollpane)) - { - return 1; - } - - /* Otherwise, whether this is selectable depends on the child widget. */ - - return txt_selectable_widget(scrollpane->child); -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -txt_scrollpane_t *txt_new_scrollpane(int w, int h, TXT_UNCAST_ARG(target)) -{ - TXT_CAST_ARG(txt_widget_t, target); - txt_scrollpane_t *scrollpane; - - scrollpane = malloc(sizeof(txt_scrollpane_t)); - txt_init_widget(scrollpane, &txt_scrollpane_class); - scrollpane->w = w; - scrollpane->h = h; - scrollpane->x = 0; - scrollpane->y = 0; - scrollpane->child = target; - scrollpane->expand_w = w <= 0; - scrollpane->expand_h = h <= 0; - - /* Set parent pointer for inner widget. */ - - target->parent = &scrollpane->widget; - - return scrollpane; -} diff --git a/games/NXDoom/textscreen/txt_scrollpane.h b/games/NXDoom/textscreen/txt_scrollpane.h deleted file mode 100644 index 831a014d9..000000000 --- a/games/NXDoom/textscreen/txt_scrollpane.h +++ /dev/null @@ -1,69 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/textscreen/txt_scrollpane.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * - ****************************************************************************/ - -#ifndef TXT_SCROLLPANE_H -#define TXT_SCROLLPANE_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "txt_widget.h" - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -/* Scrollable pane widget. - * - * A scrollable pane widget is a widget that contains another widget - * that is larger than it. Scroll bars appear on the side to allow - * different areas of the contained widget to be seen. - */ - -struct txt_scrollpane_s -{ - txt_widget_t widget; - int w; - int h; - int x; - int y; - int expand_w; - int expand_h; - txt_widget_t *child; -}; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/** - * Create a new scroll pane widget. - * - * @param w Width of the scroll pane, in characters. - * @param h Height of the scroll pane, in lines. - * @param target The target widget that the scroll pane will - * contain. - * @return Pointer to the new scroll pane widget. - */ - -txt_scrollpane_t *txt_new_scrollpane(int w, int h, TXT_UNCAST_ARG(target)); - -#endif /* TXT_SCROLLPANE_H */ diff --git a/games/NXDoom/textscreen/txt_sdl.c b/games/NXDoom/textscreen/txt_sdl.c deleted file mode 100644 index c531f6cbe..000000000 --- a/games/NXDoom/textscreen/txt_sdl.c +++ /dev/null @@ -1,264 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/textscreen/txt_sdl.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * - * Text mode emulation in SDL - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include -#include - -#include "doomkeys.h" - -#include "txt_main.h" -#include "txt_sdl.h" -#include "txt_utf8.h" - -/* Fonts: */ - -#include "txt_font.h" -#include "fonts/codepage.h" -#include "fonts/large.h" -#include "fonts/normal.h" -#include "fonts/small.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* Time between character blinks in ms */ - -#define BLINK_PERIOD 250 - -/* XXX: duplicate from doomtype.h */ - -#define arrlen(array) (sizeof(array) / sizeof(*array)) - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static unsigned char *screendata; - -/* Unicode key mapping; see codepage.h. */ - -static const short g_code_page_to_unicode[] = CODE_PAGE_TO_UNICODE; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/* Searches the desktop screen buffer to determine whether there are any - * blinking characters. - */ - -#if 0 /* UNUSED */ -static int txt_has_blinking_chars(void) -{ - int x; - int y; - unsigned char *p; - - /* Check all characters in screen buffer */ - - for (y = 0; y < TXT_SCREEN_H; ++y) - { - for (x = 0; x < TXT_SCREEN_W; ++x) - { - p = &screendata[(y * TXT_SCREEN_W + x) * 2]; - - if (p[1] & 0x80) - { - return 1; /* This character is blinking */ - } - } - } - - /* None found */ - - return 0; -} - -static void txt_string_concat(char *dest, const char *src, size_t dest_len) -{ - size_t offset; - - offset = strlen(dest); - if (offset > dest_len) - { - offset = dest_len; - } - - txt_string_copy(dest + offset, src, dest_len - offset); -} -#endif - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/* Initialize text mode screen - * - * Returns 1 if successful, 0 if an error occurred - */ - -int txt_init(void) -{ - return 1; -} - -void txt_shutdown(void) -{ -} - -void txt_set_colour(txt_color_t color, int r, int g, int b) -{ -} - -unsigned char *txt_get_screen_data(void) -{ - return screendata; -} - -void txt_update_screen_area(int x, int y, int w, int h) -{ -} - -void txt_update_screen(void) -{ - txt_update_screen_area(0, 0, TXT_SCREEN_W, TXT_SCREEN_H); -} - -void txt_get_mouse_position(int *x, int *y) -{ -} - -signed int txt_getchar(void) -{ - return -1; -} - -int txt_get_modifier_state(txt_modifier_t mod) -{ - return 0; -} - -int txt_unicode_character(unsigned int c) -{ - unsigned int i; - - /* Check the code page mapping to see if this character maps - * to anything. - */ - - for (i = 0; i < arrlen(g_code_page_to_unicode); ++i) - { - if (g_code_page_to_unicode[i] == c) - { - return i; - } - } - - return -1; -} - -void txt_get_key_description(int key, char *buf, size_t buf_len) -{ -} - -/* Sleeps until an event is received, the screen needs to be redrawn, - * or until timeout expires (if timeout != 0) - */ - -void txt_sleep(int timeout) -{ -} - -void txt_set_input_mode(txt_input_mode_t mode) -{ -} - -void txt_set_window_title(const char *title) -{ -} - -void txt_sdl_set_event_callback(void *user_data) -{ -} - -/* Safe string functions. */ - -void txt_string_copy(char *dest, const char *src, size_t dest_len) -{ - if (dest_len < 1) - { - return; - } - - dest[dest_len - 1] = '\0'; - strncpy(dest, src, dest_len - 1); -} - -/* Safe, portable vsnprintf(). */ - -int txt_vsnprintf(char *buf, size_t buf_len, const char *s, va_list args) -{ - int result; - - if (buf_len < 1) - { - return 0; - } - - /* Windows (and other OSes?) has a vsnprintf() that doesn't always - * append a trailing \0. So we must do it, and write into a buffer - * that is one byte shorter; otherwise this function is unsafe. - */ - - result = vsnprintf(buf, buf_len, s, args); - - /* If truncated, change the final char in the buffer to a \0. - * A negative result indicates a truncated buffer on Windows. - */ - - if (result < 0 || result >= buf_len) - { - buf[buf_len - 1] = '\0'; - result = buf_len - 1; - } - - return result; -} - -/* Safe, portable snprintf(). */ - -int txt_snprintf(char *buf, size_t buf_len, const char *s, ...) -{ - va_list args; - int result; - va_start(args, s); - result = txt_vsnprintf(buf, buf_len, s, args); - va_end(args); - return result; -} diff --git a/games/NXDoom/textscreen/txt_sdl.h b/games/NXDoom/textscreen/txt_sdl.h deleted file mode 100644 index 1de6af329..000000000 --- a/games/NXDoom/textscreen/txt_sdl.h +++ /dev/null @@ -1,41 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/textscreen/txt_sdl.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * Text mode emulation in SDL - * - ****************************************************************************/ - -#ifndef TXT_SDL_H -#define TXT_SDL_H - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/* Set a callback function to call in the SDL event loop. Useful for - * intercepting events. Pass callback=NULL to clear an existing - * callback function. - * user_data is a void pointer to be passed to the callback function. - */ - -void txt_sdl_set_event_callback(void *user_data); - -#endif /* TXT_SDL_H */ diff --git a/games/NXDoom/textscreen/txt_separator.c b/games/NXDoom/textscreen/txt_separator.c deleted file mode 100644 index fc0e1f6eb..000000000 --- a/games/NXDoom/textscreen/txt_separator.c +++ /dev/null @@ -1,145 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/textscreen/txt_separator.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -#include "txt_gui.h" -#include "txt_io.h" -#include "txt_main.h" -#include "txt_separator.h" -#include "txt_utf8.h" -#include "txt_window.h" - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -static void txt_separator_size_calc(TXT_UNCAST_ARG(separator)); -static void txt_separator_drawer(TXT_UNCAST_ARG(separator)); -static void txt_separator_destructor(TXT_UNCAST_ARG(separator)); - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -txt_widget_class_t txt_separator_class = -{ - txt_never_selectable, - txt_separator_size_calc, - txt_separator_drawer, - NULL, - txt_separator_destructor, - NULL, - NULL, -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static void txt_separator_size_calc(TXT_UNCAST_ARG(separator)) -{ - TXT_CAST_ARG(txt_separator_t, separator); - - if (separator->label != NULL) - { - /* Minimum width is the string length + two spaces for padding */ - - separator->widget.w = txt_utf8_strlen(separator->label) + 2; - } - else - { - separator->widget.w = 0; - } - - separator->widget.h = 1; -} - -static void txt_separator_drawer(TXT_UNCAST_ARG(separator)) -{ - TXT_CAST_ARG(txt_separator_t, separator); - int x; - int y; - int w; - - w = separator->widget.w; - - txt_get_xy(&x, &y); - - /* Draw separator. Go back one character and draw two extra - * to overlap the window borders. - */ - - txt_draw_separator(x - 2, y, w + 4); - - if (separator->label != NULL) - { - txt_goto_xy(x, y); - - txt_fgcolour(TXT_COLOR_BRIGHT_GREEN); - txt_draw_string(" "); - txt_draw_string(separator->label); - txt_draw_string(" "); - } -} - -static void txt_separator_destructor(TXT_UNCAST_ARG(separator)) -{ - TXT_CAST_ARG(txt_separator_t, separator); - - free(separator->label); -} - -static void txt_set_separator_label(txt_separator_t *separator, - const char *label) -{ - free(separator->label); - - if (label != NULL) - { - separator->label = strdup(label); - } - else - { - separator->label = NULL; - } -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -txt_separator_t *txt_new_separator(const char *label) -{ - txt_separator_t *separator; - - separator = malloc(sizeof(txt_separator_t)); - - txt_init_widget(separator, &txt_separator_class); - - separator->label = NULL; - txt_set_separator_label(separator, label); - - return separator; -} diff --git a/games/NXDoom/textscreen/txt_separator.h b/games/NXDoom/textscreen/txt_separator.h deleted file mode 100644 index 79be2f248..000000000 --- a/games/NXDoom/textscreen/txt_separator.h +++ /dev/null @@ -1,67 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/textscreen/txt_separator.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - ****************************************************************************/ - -#ifndef TXT_SEPARATOR_H -#define TXT_SEPARATOR_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "txt_widget.h" - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -/* Horizontal separator. - * - * A horizontal separator appears as a horizontal line divider across - * the length of the window in which it is added. An optional label - * allows the separator to be used as a section divider for grouping - * related controls. - */ - -struct txt_separator_s -{ - txt_widget_t widget; - char *label; -}; - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -extern txt_widget_class_t txt_separator_class; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/** - * Create a new horizontal separator widget. - * - * @param label Label to display on the separator (UTF-8 format). - * If this is set to NULL, no label is displayed. - * @return The new separator widget. - */ - -txt_separator_t *txt_new_separator(const char *label); - -#endif /* TXT_SEPARATOR_H */ diff --git a/games/NXDoom/textscreen/txt_spinctrl.c b/games/NXDoom/textscreen/txt_spinctrl.c deleted file mode 100644 index 2838cb49b..000000000 --- a/games/NXDoom/textscreen/txt_spinctrl.c +++ /dev/null @@ -1,460 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/textscreen/txt_spinctrl.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include -#include -#include - -#include "doomkeys.h" - -#include "txt_gui.h" -#include "txt_io.h" -#include "txt_main.h" -#include "txt_spinctrl.h" -#include "txt_utf8.h" -#include "txt_window.h" - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -static void txt_spin_control_size_calc(TXT_UNCAST_ARG(spincontrol)); -static void txt_spin_control_drawer(TXT_UNCAST_ARG(spincontrol)); -static int txt_spincontrol_keypress(TXT_UNCAST_ARG(spincontrol), int key); -static void txt_spin_control_destructor(TXT_UNCAST_ARG(spincontrol)); -static void txt_spincontrol_mousepress(TXT_UNCAST_ARG(spincontrol), int x, - int y, int b); -static void txt_spincontrol_focused(TXT_UNCAST_ARG(spincontrol), - int focused); - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -txt_widget_class_t txt_spincontrol_class = -{ - txt_always_selectable, - txt_spin_control_size_calc, - txt_spin_control_drawer, - txt_spincontrol_keypress, - txt_spin_control_destructor, - txt_spincontrol_mousepress, - NULL, - txt_spincontrol_focused, -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/* Generate the format string to be used for displaying floats */ - -static void float_format_string(float step, char *buf, size_t buf_len) -{ - int precision; - - precision = (int)ceil(-log(step) / log(10)); - - if (precision > 0) - { - txt_snprintf(buf, buf_len, "%%.%if", precision); - } - else - { - txt_string_copy(buf, "%.1f", buf_len); - } -} - -/* Number of characters needed to represent a character */ - -static unsigned int int_width(int val) -{ - char buf[25]; - - txt_snprintf(buf, sizeof(buf), "%i", val); - - return strlen(buf); -} - -static unsigned int float_width(float val, float step) -{ - unsigned int precision; - unsigned int result; - - /* Calculate the width of the int value */ - - result = int_width((int)val); - - /* Add a decimal part if the precision specifies it */ - - precision = (unsigned int)ceil(-log(step) / log(10)); - - if (precision > 0) - { - result += precision + 1; - } - - return result; -} - -/* Returns the minimum width of the input box */ - -static unsigned int spin_control_width(txt_spincontrol_t *spincontrol) -{ - unsigned int minw; - unsigned int maxw; - - switch (spincontrol->type) - { - case TXT_SPINCONTROL_FLOAT: - minw = float_width(spincontrol->min.f, spincontrol->step.f); - maxw = float_width(spincontrol->max.f, spincontrol->step.f); - break; - - default: - case TXT_SPINCONTROL_INT: - minw = int_width(spincontrol->min.i); - maxw = int_width(spincontrol->max.i); - break; - } - - /* Choose the wider of the two values. Add one so that there is always - * space for the cursor when editing. - */ - - if (minw > maxw) - { - return minw; - } - else - { - return maxw; - } -} - -static void txt_spin_control_size_calc(TXT_UNCAST_ARG(spincontrol)) -{ - TXT_CAST_ARG(txt_spincontrol_t, spincontrol); - - spincontrol->widget.w = spin_control_width(spincontrol) + 5; - spincontrol->widget.h = 1; -} - -static void set_buffer(txt_spincontrol_t *spincontrol) -{ - char format[25]; - - switch (spincontrol->type) - { - case TXT_SPINCONTROL_INT: - txt_snprintf(spincontrol->buffer, spincontrol->buffer_len, "%i", - spincontrol->value->i); - break; - - case TXT_SPINCONTROL_FLOAT: - float_format_string(spincontrol->step.f, format, sizeof(format)); - txt_snprintf(spincontrol->buffer, spincontrol->buffer_len, format, - spincontrol->value->f); - break; - } -} - -static void txt_spin_control_drawer(TXT_UNCAST_ARG(spincontrol)) -{ - TXT_CAST_ARG(txt_spincontrol_t, spincontrol); - unsigned int i; - unsigned int padding; - txt_saved_colors_t colors; - int bw; - int focused; - - focused = spincontrol->widget.focused; - - txt_save_colours(&colors); - - txt_fgcolour(TXT_COLOR_BRIGHT_CYAN); - txt_draw_code_page_string("\x1b "); - - txt_restore_colours(&colors); - - /* Choose background color */ - - if (focused && spincontrol->editing) - { - txt_bgcolour(TXT_COLOR_BLACK, 0); - } - else - { - txt_set_widget_bg(spincontrol); - } - - if (!spincontrol->editing) - { - set_buffer(spincontrol); - } - - i = 0; - - bw = txt_utf8_strlen(spincontrol->buffer); - padding = spincontrol->widget.w - bw - 4; - - while (i < padding) - { - txt_draw_string(" "); - ++i; - } - - txt_draw_string(spincontrol->buffer); - i += bw; - - while (i < spincontrol->widget.w - 4) - { - txt_draw_string(" "); - ++i; - } - - txt_restore_colours(&colors); - txt_fgcolour(TXT_COLOR_BRIGHT_CYAN); - txt_draw_code_page_string(" \x1a"); -} - -static void txt_spin_control_destructor(TXT_UNCAST_ARG(spincontrol)) -{ - TXT_CAST_ARG(txt_spincontrol_t, spincontrol); - - free(spincontrol->buffer); -} - -static void add_character(txt_spincontrol_t *spincontrol, int key) -{ - if (txt_utf8_strlen(spincontrol->buffer) < - spin_control_width(spincontrol) && - strlen(spincontrol->buffer) < spincontrol->buffer_len - 2) - { - spincontrol->buffer[strlen(spincontrol->buffer) + 1] = '\0'; - spincontrol->buffer[strlen(spincontrol->buffer)] = key; - } -} - -static void backspace(txt_spincontrol_t *spincontrol) -{ - if (txt_utf8_strlen(spincontrol->buffer) > 0) - { - spincontrol->buffer[strlen(spincontrol->buffer) - 1] = '\0'; - } -} - -static void enforce_limits(txt_spincontrol_t *spincontrol) -{ - switch (spincontrol->type) - { - case TXT_SPINCONTROL_INT: - if (spincontrol->value->i > spincontrol->max.i) - spincontrol->value->i = spincontrol->max.i; - else if (spincontrol->value->i < spincontrol->min.i) - spincontrol->value->i = spincontrol->min.i; - break; - - case TXT_SPINCONTROL_FLOAT: - if (spincontrol->value->f > spincontrol->max.f) - spincontrol->value->f = spincontrol->max.f; - else if (spincontrol->value->f < spincontrol->min.f) - spincontrol->value->f = spincontrol->min.f; - break; - } -} - -static void finish_editing(txt_spincontrol_t *spincontrol) -{ - switch (spincontrol->type) - { - case TXT_SPINCONTROL_INT: - spincontrol->value->i = atoi(spincontrol->buffer); - break; - - case TXT_SPINCONTROL_FLOAT: - spincontrol->value->f = (float)atof(spincontrol->buffer); - break; - } - - spincontrol->editing = 0; - enforce_limits(spincontrol); -} - -static int txt_spincontrol_keypress(TXT_UNCAST_ARG(spincontrol), int key) -{ - TXT_CAST_ARG(txt_spincontrol_t, spincontrol); - - /* Enter to enter edit mode */ - - if (spincontrol->editing) - { - if (key == KEY_ENTER) - { - finish_editing(spincontrol); - return 1; - } - - if (key == KEY_ESCAPE) - { - /* Abort without saving value */ - - spincontrol->editing = 0; - return 1; - } - - if (isdigit(key) || key == '-' || key == '.') - { - add_character(spincontrol, key); - return 1; - } - - if (key == KEY_BACKSPACE) - { - backspace(spincontrol); - return 1; - } - } - else - { - /* Non-editing mode */ - - if (key == KEY_ENTER) - { - spincontrol->editing = 1; - txt_string_copy(spincontrol->buffer, "", spincontrol->buffer_len); - return 1; - } - - if (key == KEY_LEFTARROW) - { - switch (spincontrol->type) - { - case TXT_SPINCONTROL_INT: - spincontrol->value->i -= spincontrol->step.i; - break; - - case TXT_SPINCONTROL_FLOAT: - spincontrol->value->f -= spincontrol->step.f; - break; - } - - enforce_limits(spincontrol); - - return 1; - } - - if (key == KEY_RIGHTARROW) - { - switch (spincontrol->type) - { - case TXT_SPINCONTROL_INT: - spincontrol->value->i += spincontrol->step.i; - break; - - case TXT_SPINCONTROL_FLOAT: - spincontrol->value->f += spincontrol->step.f; - break; - } - - enforce_limits(spincontrol); - - return 1; - } - } - - return 0; -} - -static void txt_spincontrol_mousepress(TXT_UNCAST_ARG(spincontrol), int x, - int y, int b) -{ - TXT_CAST_ARG(txt_spincontrol_t, spincontrol); - unsigned int rel_x; - - rel_x = x - spincontrol->widget.x; - - if (rel_x < 2) - { - txt_spincontrol_keypress(spincontrol, KEY_LEFTARROW); - } - else if (rel_x >= spincontrol->widget.w - 2) - { - txt_spincontrol_keypress(spincontrol, KEY_RIGHTARROW); - } -} - -static void txt_spincontrol_focused(TXT_UNCAST_ARG(spincontrol), int focused) -{ - TXT_CAST_ARG(txt_spincontrol_t, spincontrol); - - finish_editing(spincontrol); -} - -static txt_spincontrol_t *txt_base_spincontrol(void) -{ - txt_spincontrol_t *spincontrol; - - spincontrol = malloc(sizeof(txt_spincontrol_t)); - - txt_init_widget(spincontrol, &txt_spincontrol_class); - spincontrol->buffer_len = 25; - spincontrol->buffer = malloc(spincontrol->buffer_len); - txt_string_copy(spincontrol->buffer, "", spincontrol->buffer_len); - spincontrol->editing = 0; - - return spincontrol; -} - -txt_spincontrol_t *txt_newspin_control(int *value, int min, int max) -{ - txt_spincontrol_t *spincontrol; - - spincontrol = txt_base_spincontrol(); - spincontrol->type = TXT_SPINCONTROL_INT; - spincontrol->value = (void *)value; - spincontrol->min.i = min; - spincontrol->max.i = max; - spincontrol->step.i = 1; - set_buffer(spincontrol); - - return spincontrol; -} - -txt_spincontrol_t *txt_new_float_spincontrol(float *value, float min, - float max) -{ - txt_spincontrol_t *spincontrol; - - spincontrol = txt_base_spincontrol(); - spincontrol->type = TXT_SPINCONTROL_FLOAT; - spincontrol->value = (void *)value; - spincontrol->min.f = min; - spincontrol->max.f = max; - spincontrol->step.f = 0.1f; - set_buffer(spincontrol); - - return spincontrol; -} diff --git a/games/NXDoom/textscreen/txt_spinctrl.h b/games/NXDoom/textscreen/txt_spinctrl.h deleted file mode 100644 index d6f663ed0..000000000 --- a/games/NXDoom/textscreen/txt_spinctrl.h +++ /dev/null @@ -1,94 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/textscreen/txt_spinctrl.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - ****************************************************************************/ - -#ifndef TXT_SPINCONTROL_H -#define TXT_SPINCONTROL_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "txt_widget.h" - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -typedef enum -{ - TXT_SPINCONTROL_INT, - TXT_SPINCONTROL_FLOAT, -} txt_spincontrol_type_t; - -union _float_n_int -{ - float f; - int i; -}; - -/* Spin control widget. - * - * A spin control widget works as an input box that can be used to - * set numeric values, but also has buttons that allow its value - * to be increased or decreased. - */ - -struct txt_spincontrol_s -{ - txt_widget_t widget; - txt_spincontrol_type_t type; - union _float_n_int min; - union _float_n_int max; - union _float_n_int *value; - union _float_n_int step; - int editing; - char *buffer; - size_t buffer_len; -}; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/** - * Create a new spin control widget tracking an integer value. - * - * @param value Pointer to the variable containing the value - * displayed in the widget. - * @param min Minimum value that may be set. - * @param max Maximum value that may be set. - * @return Pointer to the new spin control widget. - */ - -txt_spincontrol_t *txt_newspin_control(int *value, int min, int max); - -/** - * Create a new spin control widget tracking a float value. - * - * @param value Pointer to the variable containing the value - * displayed in the widget. - * @param min Minimum value that may be set. - * @param max Maximum value that may be set. - * @return Pointer to the new spin control widget. - */ - -txt_spincontrol_t *txt_new_float_spincontrol(float *value, float min, - float max); - -#endif /* TXT_SPINCONTROL_H */ diff --git a/games/NXDoom/textscreen/txt_strut.c b/games/NXDoom/textscreen/txt_strut.c deleted file mode 100644 index e1da6647e..000000000 --- a/games/NXDoom/textscreen/txt_strut.c +++ /dev/null @@ -1,101 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/textscreen/txt_strut.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -#include "doomkeys.h" - -#include "txt_io.h" -#include "txt_main.h" -#include "txt_strut.h" -#include "txt_window.h" - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -static void txt_strut_size_calc(TXT_UNCAST_ARG(strut)); -static void txt_strut_drawer(TXT_UNCAST_ARG(strut)); -static void txt_strut_destructor(TXT_UNCAST_ARG(strut)); -static int txt_strut_keypress(TXT_UNCAST_ARG(strut), int key); - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -txt_widget_class_t txt_strut_class = -{ - txt_never_selectable, - txt_strut_size_calc, - txt_strut_drawer, - txt_strut_keypress, - txt_strut_destructor, - NULL, - NULL, -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static void txt_strut_size_calc(TXT_UNCAST_ARG(strut)) -{ - TXT_CAST_ARG(txt_strut_t, strut); - - /* Minimum width is the string length + two spaces for padding */ - - strut->widget.w = strut->width; - strut->widget.h = strut->height; -} - -static void txt_strut_drawer(TXT_UNCAST_ARG(strut)) -{ - /* Nothing is drawn for a strut. */ -} - -static void txt_strut_destructor(TXT_UNCAST_ARG(strut)) -{ -} - -static int txt_strut_keypress(TXT_UNCAST_ARG(strut), int key) -{ - return 0; -} - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -txt_strut_t *txt_new_strut(int width, int height) -{ - txt_strut_t *strut; - - strut = malloc(sizeof(txt_strut_t)); - - txt_init_widget(strut, &txt_strut_class); - strut->width = width; - strut->height = height; - - return strut; -} diff --git a/games/NXDoom/textscreen/txt_strut.h b/games/NXDoom/textscreen/txt_strut.h deleted file mode 100644 index 7d988fb03..000000000 --- a/games/NXDoom/textscreen/txt_strut.h +++ /dev/null @@ -1,60 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/textscreen/txt_strut.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - ****************************************************************************/ - -#ifndef TXT_STRUT_H -#define TXT_STRUT_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "txt_widget.h" - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -/* Strut widget. - * - * A strut is a widget that takes up a fixed amount of space. It can - * be visualised as a transparent box. Struts are used to provide - * spacing between widgets. - */ - -struct txt_strut_s -{ - txt_widget_t widget; - int width; - int height; -}; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/** - * Create a new strut. - * - * @param width Width of the strut, in characters. - * @param height Height of the strut, in characters. - */ - -txt_strut_t *txt_new_strut(int width, int height); - -#endif /* TXT_STRUT_H */ diff --git a/games/NXDoom/textscreen/txt_table.c b/games/NXDoom/textscreen/txt_table.c deleted file mode 100644 index 3d77e3731..000000000 --- a/games/NXDoom/textscreen/txt_table.c +++ /dev/null @@ -1,1330 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/textscreen/txt_table.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include - -#include "doomkeys.h" - -#include "txt_desktop.h" -#include "txt_gui.h" -#include "txt_io.h" -#include "txt_main.h" -#include "txt_separator.h" -#include "txt_strut.h" -#include "txt_table.h" - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -static int txt_table_selectable(TXT_UNCAST_ARG(table)); -static void txt_calc_table_size(TXT_UNCAST_ARG(table)); -static void txt_table_drawer(TXT_UNCAST_ARG(table)); -static int txt_table_keypress(TXT_UNCAST_ARG(table), int key); -static void txt_table_destructor(TXT_UNCAST_ARG(table)); -static void txt_table_mouse_press(TXT_UNCAST_ARG(table), int x, - int y, int b); -static void txt_table_layout(TXT_UNCAST_ARG(table)); -static void txt_table_focused(TXT_UNCAST_ARG(table), int focused); - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -txt_widget_t txt_table_overflow_right; -txt_widget_t txt_table_overflow_down; -txt_widget_t txt_table_eol; -txt_widget_t txt_table_empty; - -txt_widget_class_t txt_table_class = -{ - txt_table_selectable, txt_calc_table_size, txt_table_drawer, - txt_table_keypress, txt_table_destructor, txt_table_mouse_press, - txt_table_layout, txt_table_focused, -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/* Returns true if the given widget in the table's widgets[] array refers - * to an actual widget - not NULL, or one of the special overflow pointers. - */ - -static int is_actual_widget(txt_widget_t *widget) -{ - return widget != NULL && widget != &txt_table_overflow_right && - widget != &txt_table_overflow_down; -} - -static void txt_table_destructor(TXT_UNCAST_ARG(table)) -{ - TXT_CAST_ARG(txt_table_t, table); - - txt_clear_table(table); -} - -static int table_rows(txt_table_t *table) -{ - return (table->num_widgets + table->columns - 1) / table->columns; -} - -/* Most widgets occupy just one cell of a table, but if the special - * overflow constants are used, they can occupy multiple cells. - * This function figures out for a widget in a given cell, which - * cells it should actually occupy (always a rectangle). - */ - -static void cell_overflowed_size(txt_table_t *table, int x, int y, int *w, - int *h) -{ - txt_widget_t *widget; - int x1; - int y1; - - if (!is_actual_widget(table->widgets[y * table->columns + x])) - { - *w = 0; - *h = 0; - return; - } - - *w = table->columns - x; - *h = 0; - for (y1 = y; y1 < table_rows(table); ++y1) - { - /* Every overflow cell must point to either (x, y) or another - * overflow cell. This means the first in every row must be - * txt_table_overflow_down. - */ - - if (y1 * table->columns + x >= table->num_widgets) - { - break; - } - - widget = table->widgets[y1 * table->columns + x]; - - if (y1 != y && widget != &txt_table_overflow_down) - { - break; - } - - for (x1 = x + 1; x1 < x + *w; ++x1) - { - if (y1 * table->columns + x1 >= table->num_widgets) - { - break; - } - - /* Can be either type of overflow, except on the first row. - * Otherwise we impose a limit on the width. - */ - - widget = table->widgets[y1 * table->columns + x1]; - if (widget != &txt_table_overflow_right && - (widget != &txt_table_overflow_down || y1 == y)) - { - *w = x1 - x; - break; - } - } - - ++*h; - } -} - -static int is_overflowing_cell(txt_table_t *table, int x, int y) -{ - int w; - int h; - cell_overflowed_size(table, x, y, &w, &h); - return w > 1 || h > 1; -} - -/* Using the given column/row size tables, calculate the size of the given - * widget, storing the result in (w, h). - */ - -static void calculate_widget_dimensions(txt_table_t *table, int x, int y, - unsigned int *column_widths, - unsigned int *row_heights, - unsigned int *w, unsigned int *h) -{ - int cell_w; - int cell_h; - int x1; - int y1; - - /* Find which cells this widget occupies. */ - - cell_overflowed_size(table, x, y, &cell_w, &cell_h); - - /* Add up column / row widths / heights to get the actual dimensions. */ - - *w = 0; - for (x1 = x; x1 < x + cell_w; ++x1) - { - *w += column_widths[x1]; - } - - *h = 0; - for (y1 = y; y1 < y + cell_h; ++y1) - { - *h += row_heights[y1]; - } -} - -static void calc_row_col_sizes(txt_table_t *table, unsigned int *row_heights, - unsigned int *col_widths) -{ - int x; - int y; - int rows; - txt_widget_t *widget; - - rows = table_rows(table); - - memset(col_widths, 0, sizeof(int) * table->columns); - - for (y = 0; y < rows; ++y) - { - row_heights[y] = 0; - - for (x = 0; x < table->columns; ++x) - { - if (y * table->columns + x >= table->num_widgets) break; - - widget = table->widgets[y * table->columns + x]; - - if (is_actual_widget(widget)) - { - txt_calc_widget_size(widget); - } - - /* In the first pass we ignore overflowing cells. */ - - if (is_overflowing_cell(table, x, y)) - { - continue; - } - - /* NULL represents an empty spacer */ - - if (is_actual_widget(widget)) - { - if (widget->h > row_heights[y]) row_heights[y] = widget->h; - if (widget->w > col_widths[x]) col_widths[x] = widget->w; - } - } - } - - /* In the second pass, we go through again and process overflowing - * widgets, to ensure that they will fit. - */ - - for (y = 0; y < rows; ++y) - { - for (x = 0; x < table->columns; ++x) - { - unsigned int w; - unsigned int h; - - if (y * table->columns + x >= table->num_widgets) break; - - widget = table->widgets[y * table->columns + x]; - if (!is_actual_widget(widget)) - { - continue; - } - - /* Expand column width and row heights as needed. */ - - calculate_widget_dimensions(table, x, y, col_widths, row_heights, - &w, &h); - if (w < widget->w) - { - col_widths[x] += widget->w - w; - } - - if (h < widget->h) - { - row_heights[y] += widget->h - h; - } - } - } -} - -static void txt_calc_table_size(TXT_UNCAST_ARG(table)) -{ - TXT_CAST_ARG(txt_table_t, table); - unsigned int *column_widths; - unsigned int *row_heights; - int x; - int y; - int rows; - - rows = table_rows(table); - - row_heights = malloc(sizeof(int) * rows); - column_widths = malloc(sizeof(int) * table->columns); - - calc_row_col_sizes(table, row_heights, column_widths); - - table->widget.w = 0; - - for (x = 0; x < table->columns; ++x) - { - table->widget.w += column_widths[x]; - } - - table->widget.h = 0; - - for (y = 0; y < rows; ++y) - { - table->widget.h += row_heights[y]; - } - - free(row_heights); - free(column_widths); -} - -static void fill_row_to_end(txt_table_t *table) -{ - while ((table->num_widgets % table->columns) != 0) - { - txt_add_widget(table, &txt_table_overflow_right); - } -} - -static int selectable_cell(txt_table_t *table, int x, int y) -{ - txt_widget_t *widget; - int i; - - if (x < 0 || x >= table->columns) - { - return 0; - } - - i = y * table->columns + x; - - if (i >= 0 && i < table->num_widgets) - { - widget = table->widgets[i]; - return is_actual_widget(widget) && txt_selectable_widget(widget) && - widget->visible; - } - - return 0; -} - -/* Tries to locate a selectable widget in the given row, returning - * the column number of the first column available or -1 if none are - * available in the given row. - * - * Starts from start_col, then searches nearby columns. - */ - -static int find_selectable_column(txt_table_t *table, int row, int start_col) -{ - int x; - - for (x = 0; x < table->columns; ++x) - { - /* Search to the right */ - - if (selectable_cell(table, start_col + x, row)) - { - return start_col + x; - } - - /* Search to the left */ - - if (selectable_cell(table, start_col - x, row)) - { - return start_col - x; - } - } - - /* None available */ - - return -1; -} - -/* Change the selected widget. */ - -static void change_selection(txt_table_t *table, int x, int y) -{ - txt_widget_t *cur_widget; - txt_widget_t *new_widget; - int i; - - /* No change? */ - - if (x == table->selected_x && y == table->selected_y) - { - return; - } - - /* Unfocus current widget: */ - - i = table->selected_y * table->columns + table->selected_x; - - if (i < table->num_widgets) - { - cur_widget = table->widgets[i]; - - if (table->widget.focused && is_actual_widget(cur_widget)) - { - txt_set_widget_focus(cur_widget, 0); - } - } - - /* Focus new widget. */ - - new_widget = table->widgets[y * table->columns + x]; - - table->selected_x = x; - table->selected_y = y; - - if (table->widget.focused && new_widget != NULL) - { - txt_set_widget_focus(new_widget, 1); - } -} - -static int txt_table_keypress(TXT_UNCAST_ARG(table), int key) -{ - TXT_CAST_ARG(txt_table_t, table); - int selected; - int rows; - - rows = table_rows(table); - - /* Send to the currently selected widget first */ - - selected = table->selected_y * table->columns + table->selected_x; - - if (selected >= 0 && selected < table->num_widgets) - { - if (is_actual_widget(table->widgets[selected]) && - txt_selectable_widget(table->widgets[selected]) && - txt_widget_key_press(table->widgets[selected], key)) - { - return 1; - } - } - - if (key == KEY_TAB) - { - int dir; - int i; - - dir = txt_get_modifier_state(TXT_MOD_SHIFT) ? -1 : 1; - - /* Cycle through all widgets until we find one that can be selected. */ - - for (i = table->selected_y * table->columns + table->selected_x + dir; - i >= 0 && i < table->num_widgets; i += dir) - { - if (is_actual_widget(table->widgets[i]) && - txt_selectable_widget(table->widgets[i])) - { - change_selection(table, - i % table->columns, i / table->columns); - return 1; - } - } - - return 0; - } - - if (key == KEY_DOWNARROW) - { - int new_x; - int new_y; - - /* Move cursor down to the next selectable widget */ - - for (new_y = table->selected_y + 1; new_y < rows; ++new_y) - { - new_x = find_selectable_column(table, new_y, table->selected_x); - - if (new_x >= 0) - { - /* Found a selectable widget in this column! */ - - change_selection(table, new_x, new_y); - - return 1; - } - } - } - - if (key == KEY_UPARROW) - { - int new_x; - int new_y; - - /* Move cursor up to the next selectable widget */ - - for (new_y = table->selected_y - 1; new_y >= 0; --new_y) - { - new_x = find_selectable_column(table, new_y, table->selected_x); - - if (new_x >= 0) - { - /* Found a selectable widget in this column! */ - - change_selection(table, new_x, new_y); - - return 1; - } - } - } - - if (key == KEY_LEFTARROW) - { - int new_x; - - /* Move cursor left */ - - for (new_x = table->selected_x - 1; new_x >= 0; --new_x) - { - if (selectable_cell(table, new_x, table->selected_y)) - { - /* Found a selectable widget! */ - - change_selection(table, new_x, table->selected_y); - - return 1; - } - } - } - - if (key == KEY_RIGHTARROW) - { - int new_x; - - /* Move cursor left */ - - for (new_x = table->selected_x + 1; new_x < table->columns; ++new_x) - { - if (selectable_cell(table, new_x, table->selected_y)) - { - /* Found a selectable widget! */ - - change_selection(table, new_x, table->selected_y); - - return 1; - } - } - } - - return 0; -} - -/* Check the currently selected widget in the table is valid. */ - -static void check_valid_selection(txt_table_t *table) -{ - int rows; - int new_x; - int new_y; - - rows = table_rows(table); - - for (new_y = table->selected_y; new_y < rows; ++new_y) - { - new_x = find_selectable_column(table, new_y, table->selected_x); - - if (new_x >= 0) - { - /* Found a selectable column. */ - - change_selection(table, new_x, new_y); - - break; - } - } -} - -static void layout_cell(txt_table_t *table, int x, int y, int draw_x, - int draw_y) -{ - txt_widget_t *widget; - int col_width; - - widget = table->widgets[y * table->columns + x]; - - col_width = widget->w; - - /* Adjust x position based on alignment property */ - - switch (widget->align) - { - case TXT_HORIZ_LEFT: - widget->w = col_width; - break; - - case TXT_HORIZ_CENTER: - txt_calc_widget_size(widget); - - /* Separators are always drawn left-aligned. */ - - if (widget->widget_class != &txt_separator_class) - { - draw_x += (col_width - widget->w) / 2; - } - - break; - - case TXT_HORIZ_RIGHT: - txt_calc_widget_size(widget); - - if (widget->widget_class != &txt_separator_class) - { - draw_x += col_width - widget->w; - } - break; - } - - /* Set the position for this widget */ - - widget->x = draw_x; - widget->y = draw_y; - - /* Recursively lay out any widgets contained in the widget */ - - txt_layout_widget(widget); -} - -static void txt_table_layout(TXT_UNCAST_ARG(table)) -{ - TXT_CAST_ARG(txt_table_t, table); - unsigned int *column_widths; - unsigned int *row_heights; - txt_widget_t *widget; - int draw_x; - int draw_y; - int x; - int y; - int i; - int rows; - - /* Work out the column widths and row heights */ - - rows = table_rows(table); - - column_widths = malloc(sizeof(int) * table->columns); - row_heights = malloc(sizeof(int) * rows); - - calc_row_col_sizes(table, row_heights, column_widths); - - /* If this table only has one column, expand column size to fit - * the display width. Ensures that separators reach the window edges - * when drawing windows. - */ - - if (table->columns == 1) - { - column_widths[0] = table->widget.w; - } - - /* Draw all cells */ - - draw_y = table->widget.y; - - for (y = 0; y < rows; ++y) - { - draw_x = table->widget.x; - - for (x = 0; x < table->columns; ++x) - { - i = y * table->columns + x; - - if (i >= table->num_widgets) break; - - widget = table->widgets[i]; - - if (is_actual_widget(widget)) - { - calculate_widget_dimensions(table, x, y, column_widths, - row_heights, &widget->w, - &widget->h); - layout_cell(table, x, y, draw_x, draw_y); - } - - draw_x += column_widths[x]; - } - - draw_y += row_heights[y]; - } - - free(row_heights); - free(column_widths); -} - -static void txt_table_drawer(TXT_UNCAST_ARG(table)) -{ - TXT_CAST_ARG(txt_table_t, table); - txt_widget_t *widget; - int i; - - /* Check the table's current selection points at something valid before - * drawing. - */ - - check_valid_selection(table); - - /* Draw all cells */ - - for (i = 0; i < table->num_widgets; ++i) - { - widget = table->widgets[i]; - - if (is_actual_widget(widget)) - { - txt_goto_xy(widget->x, widget->y); - txt_draw_widget(widget); - } - } -} - -/* Responds to mouse presses */ - -static void txt_table_mouse_press(TXT_UNCAST_ARG(table), int x, int y, int b) -{ - TXT_CAST_ARG(txt_table_t, table); - txt_widget_t *widget; - int i; - - for (i = 0; i < table->num_widgets; ++i) - { - widget = table->widgets[i]; - - /* NULL widgets are spacers */ - - if (is_actual_widget(widget)) - { - if (x >= widget->x && x < (signed)(widget->x + widget->w) && - y >= widget->y && y < (signed)(widget->y + widget->h)) - { - /* This is the widget that was clicked! - * - * Select the cell if the widget is selectable - */ - - if (txt_selectable_widget(widget)) - { - change_selection(table, i % table->columns, - i / table->columns); - } - - /* Propagate click */ - - txt_widget_mouse_press(widget, x, y, b); - - break; - } - } - } -} - -/* Determine whether the table is selectable. */ - -static int txt_table_selectable(TXT_UNCAST_ARG(table)) -{ - TXT_CAST_ARG(txt_table_t, table); - int i; - - /* Is the currently-selected cell selectable? */ - - if (selectable_cell(table, table->selected_x, table->selected_y)) - { - return 1; - } - - /* Find the first selectable cell and set selected_x, selected_y. */ - - for (i = 0; i < table->num_widgets; ++i) - { - if (is_actual_widget(table->widgets[i]) && - txt_selectable_widget(table->widgets[i])) - { - change_selection(table, i % table->columns, i / table->columns); - return 1; - } - } - - /* No selectable widgets exist within the table. */ - - return 0; -} - -/* Need to pass through focus changes to the selected child widget. */ - -static void txt_table_focused(TXT_UNCAST_ARG(table), int focused) -{ - TXT_CAST_ARG(txt_table_t, table); - int i; - - i = table->selected_y * table->columns + table->selected_x; - - if (i < table->num_widgets) - { - if (is_actual_widget(table->widgets[i])) - { - txt_set_widget_focus(table->widgets[i], focused); - } - } -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/* Remove all entries from a table */ - -void txt_clear_table(TXT_UNCAST_ARG(table)) -{ - TXT_CAST_ARG(txt_table_t, table); - int i; - - /* Free all widgets - * Skip over the first (num_columns) widgets in the array, as these - * are the column struts used to control column width - */ - - for (i = table->columns; i < table->num_widgets; ++i) - { - if (is_actual_widget(table->widgets[i])) - { - txt_destroy_widget(table->widgets[i]); - } - } - - /* Shrink the table to just the column strut widgets */ - - table->num_widgets = table->columns; -} - -void txt_add_widget(TXT_UNCAST_ARG(table), TXT_UNCAST_ARG(widget)) -{ - TXT_CAST_ARG(txt_table_t, table); - TXT_CAST_ARG(txt_widget_t, widget); - int is_separator; - int i; - - /* Convenience alias for NULL: */ - - if (widget == &txt_table_empty) - { - widget = NULL; - } - else if (widget == &txt_table_eol) - { - fill_row_to_end(table); - return; - } - - /* We have special handling for the separator widget: */ - - is_separator = is_actual_widget(widget) && - widget->widget_class == &txt_separator_class; - - /* If we add two separators consecutively, the new separator replaces the - * first. This allows us to override the "implicit" separator that is - * added at the top of a window when it is created. - */ - - if (is_separator) - { - for (i = table->num_widgets - 1; i >= 0; --i) - { - txt_widget_t *last_widget; - last_widget = table->widgets[i]; - - if (is_actual_widget(last_widget) && - widget->widget_class == &txt_separator_class && - last_widget->widget_class == &txt_separator_class) - { - table->widgets[i] = widget; - txt_destroy_widget(last_widget); - return; - } - else if (last_widget != &txt_table_overflow_right) - { - break; - } - } - } - - /* Separators begin on a new line. */ - - if (is_separator) - { - fill_row_to_end(table); - } - - table->widgets = realloc( - table->widgets, - sizeof(txt_widget_t *) * (table->num_widgets + 1)); - table->widgets[table->num_widgets] = widget; - ++table->num_widgets; - - /* Maintain parent pointer. */ - - if (is_actual_widget(widget)) - { - widget->parent = &table->widget; - } - - /* Separators always take up the entire line. */ - - if (is_separator) - { - fill_row_to_end(table); - } -} - -/* Add multiple widgets to a table. */ - -void txt_add_widgets(TXT_UNCAST_ARG(table), ...) -{ - TXT_CAST_ARG(txt_table_t, table); - va_list args; - txt_widget_t *widget; - - va_start(args, TXT_UNCAST_ARG_NAME(table)); - - /* Keep adding widgets until a NULL is reached. */ - - for (; ; ) - { - widget = va_arg(args, txt_widget_t *); - - if (widget == NULL) - { - break; - } - - txt_add_widget(table, widget); - } - - va_end(args); -} - -void txt_init_table(txt_table_t *table, int columns) -{ - int i; - - txt_init_widget(table, &txt_table_class); - table->columns = columns; - table->widgets = NULL; - table->num_widgets = 0; - table->selected_x = 0; - table->selected_y = 0; - - /* Add a strut for each column at the start of the table. - * These are used by the txt_set_column_widths function below: - * the struts are created with widths of 0 each, but this - * function changes them. - */ - - for (i = 0; i < columns; ++i) - { - txt_add_widget(table, txt_new_strut(0, 0)); - } -} - -txt_table_t *txt_new_table(int columns) -{ - txt_table_t *table; - - table = malloc(sizeof(txt_table_t)); - - txt_init_table(table, columns); - - return table; -} - -/* Alternative to txt_new_table() that allows a list of widgets to be - * provided in its arguments. - */ - -txt_table_t *txt_make_table(int columns, ...) -{ - txt_table_t *table; - va_list args; - - table = txt_new_table(columns); - va_start(args, columns); - - for (; ; ) - { - txt_widget_t *widget; - widget = va_arg(args, txt_widget_t *); - - if (widget == NULL) - { - break; - } - - txt_add_widget(table, widget); - } - - va_end(args); - - return table; -} - -/* Create a horizontal table from a list of widgets. */ - -txt_table_t *txt_new_horiz_box(TXT_UNCAST_ARG(first_widget), ...) -{ - TXT_CAST_ARG(txt_widget_t, first_widget); - txt_table_t *result; - va_list args; - int num_args; - - /* First, find the number of arguments to determine the width of - * the box. - */ - - va_start(args, TXT_UNCAST_ARG_NAME(first_widget)); - - num_args = 1; - - for (; ; ) - { - txt_widget_t *widget; - - widget = va_arg(args, txt_widget_t *); - - if (widget == NULL) - { - /* End of list */ - - break; - } - else - { - ++num_args; - } - } - - va_end(args); - - /* Create the table. */ - - result = txt_new_table(num_args); - txt_add_widget(result, first_widget); - - /* Go through the list again and add each widget. */ - - va_start(args, TXT_UNCAST_ARG_NAME(first_widget)); - - for (; ; ) - { - txt_widget_t *widget; - - widget = va_arg(args, txt_widget_t *); - - if (widget == NULL) - { - /* End of list */ - - break; - } - else - { - txt_add_widget(result, widget); - } - } - - va_end(args); - - return result; -} - -/* Get the currently-selected widget in a table, recursively searching - * through sub-tables if necessary. - */ - -txt_widget_t *txt_get_selected_widget(TXT_UNCAST_ARG(table)) -{ - TXT_CAST_ARG(txt_table_t, table); - txt_widget_t *result; - int index; - - index = table->selected_y * table->columns + table->selected_x; - - result = NULL; - - if (index >= 0 && index < table->num_widgets) - { - result = table->widgets[index]; - - if (!is_actual_widget(result)) - { - result = NULL; - } - } - - if (result != NULL && result->widget_class == &txt_table_class) - { - result = txt_get_selected_widget(result); - } - - return result; -} - -/* Selects a given widget in a table, recursively searching any tables - * within this table. Returns 1 if successful, 0 if unsuccessful. - */ - -int txt_select_widget(TXT_UNCAST_ARG(table), TXT_UNCAST_ARG(widget)) -{ - TXT_CAST_ARG(txt_table_t, table); - TXT_CAST_ARG(txt_widget_t, widget); - int i; - - for (i = 0; i < table->num_widgets; ++i) - { - if (!is_actual_widget(table->widgets[i])) - { - continue; - } - - if (table->widgets[i] == widget) - { - /* Found the item! Select it and return. */ - - change_selection(table, i % table->columns, i / table->columns); - - return 1; - } - - if (table->widgets[i]->widget_class == &txt_table_class) - { - /* This item is a subtable. Recursively search this table. */ - - if (txt_select_widget(table->widgets[i], widget)) - { - /* Found it in the subtable. Select this subtable and return. - */ - - change_selection(table, i % table->columns, - i / table->columns); - - return 1; - } - } - } - - /* Not found. */ - - return 0; -} - -void txt_set_table_columns(TXT_UNCAST_ARG(table), int new_columns) -{ - TXT_CAST_ARG(txt_table_t, table); - txt_widget_t **new_widgets; - txt_widget_t *widget; - int new_num_widgets; - int i; - int j; - int x; - - /* We need as many full rows as are in the current list, plus the - * remainder from the last row. - */ - - new_num_widgets = (table->num_widgets / table->columns) * new_columns + - (table->num_widgets % table->columns); - new_widgets = calloc(new_num_widgets, sizeof(txt_widget_t *)); - - /* Reset and add one by one from the old table. */ - - new_num_widgets = 0; - - for (i = 0; i < table->num_widgets; ++i) - { - widget = table->widgets[i]; - x = i % table->columns; - - if (x < new_columns) - { - new_widgets[new_num_widgets] = widget; - ++new_num_widgets; - } - else if (is_actual_widget(widget)) - { - txt_destroy_widget(widget); - } - - /* When we reach the last column of a row, we must pad it out with - * extra widgets to reach the next row. - */ - - if (x == table->columns - 1) - { - for (j = table->columns; j < new_columns; ++j) - { - /* First row? We need to add struts that are used to apply - * the column widths. - */ - - if (i < table->columns) - { - widget = &txt_new_strut(0, 0)->widget; - } - else - { - widget = &txt_table_overflow_right; - } - - new_widgets[new_num_widgets] = widget; - ++new_num_widgets; - } - } - } - - free(table->widgets); - table->widgets = new_widgets; - table->num_widgets = new_num_widgets; - table->columns = new_columns; -} - -/* Sets the widths of columns in a table. */ - -void txt_set_column_widths(TXT_UNCAST_ARG(table), ...) -{ - TXT_CAST_ARG(txt_table_t, table); - va_list args; - txt_strut_t *strut; - int i; - int width; - - va_start(args, TXT_UNCAST_ARG_NAME(table)); - - for (i = 0; i < table->columns; ++i) - { - width = va_arg(args, int); - - strut = (txt_strut_t *)table->widgets[i]; - strut->width = width; - } - - va_end(args); -} - -/* Moves the select by at least the given number of characters. - * Currently quietly ignores pagex, as we don't use it. - */ - -int txt_page_table(TXT_UNCAST_ARG(table), int pagex, int pagey) -{ - TXT_CAST_ARG(txt_table_t, table); - unsigned int *column_widths; - unsigned int *row_heights; - int rows; - int changed = 0; - - rows = table_rows(table); - - row_heights = malloc(sizeof(int) * rows); - column_widths = malloc(sizeof(int) * table->columns); - - calc_row_col_sizes(table, row_heights, column_widths); - - if (pagex) - { - /* @todo Jump selection to the left or right as needed */ - } - - if (pagey) - { - int new_x; - int new_y; - int distance = 0; - int dir; - - /* What direction are we moving? */ - - if (pagey > 0) - { - dir = 1; - } - else - { - dir = -1; - } - - /* Move the cursor until the desired distance is reached. */ - - new_y = table->selected_y; - - while (new_y >= 0 && new_y < rows) - { - /* We are about to travel a distance equal to the height of the row - * we are about to leave. - */ - - distance += row_heights[new_y]; - - /* *Now* increment the loop. */ - - new_y += dir; - - new_x = find_selectable_column(table, new_y, table->selected_x); - - if (new_x >= 0) - { - /* Found a selectable widget in this column! - * Select it anyway in case we don't find something better. - */ - - change_selection(table, new_x, new_y); - changed = 1; - - /* ...but is it far enough away? */ - - if (distance >= abs(pagey)) - { - break; - } - } - } - } - - free(row_heights); - free(column_widths); - - return changed; -} diff --git a/games/NXDoom/textscreen/txt_table.h b/games/NXDoom/textscreen/txt_table.h deleted file mode 100644 index d1dffbeff..000000000 --- a/games/NXDoom/textscreen/txt_table.h +++ /dev/null @@ -1,265 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/textscreen/txt_table.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - ****************************************************************************/ - -#ifndef TXT_TABLE_H -#define TXT_TABLE_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "txt_widget.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/** - * Magic value that if used in a table, will indicate that the cell is - * empty and the widget in the cell to the left can overflow into it. - */ - -#define TXT_TABLE_OVERFLOW_RIGHT (&txt_table_overflow_right) - -/** - * Magic value that if used in a table, will indicate that the cell is - * empty and the widget in the cell above it can overflow down into it. - */ - -#define TXT_TABLE_OVERFLOW_DOWN (&txt_table_overflow_down) - -/** - * Magic value that if given to @ref txt_add_widget(), will pad out all - * columns until the end of line. - */ - -#define TXT_TABLE_EOL (&txt_table_eol) - -/** - * Indicates an empty space to @ref txt_add_widgets(). Equivalent to - * txt_add_widget(table, NULL), except that NULL is used by txt_add_widgets() - * to indicate the end of input. - */ - -#define TXT_TABLE_EMPTY (&txt_table_empty) - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -/* Table widget. - * - * A table is a widget that contains other widgets. It may have - * multiple columns, in which case the child widgets are laid out - * in a grid. Columns automatically grow as necessary, although - * minimum column widths can be set using @ref txt_set_column_widths. - * - * To create a new table, use @ref txt_new_table. It is also - * possible to use @ref txt_new_horiz_box to create a table, specifying - * widgets to place inside a horizontal list. A vertical list is - * possible simply by creating a table containing a single column. - */ - -struct txt_table_s -{ - txt_widget_t widget; - - /* Widgets in this table - * The widget at (x,y) in the table is widgets[columns * y + x] - */ - - txt_widget_t **widgets; - int num_widgets; - - /* Number of columns */ - - int columns; - - /* Currently selected: */ - - int selected_x; - int selected_y; -}; - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -extern txt_widget_class_t txt_table_class; -extern txt_widget_t txt_table_overflow_right; -extern txt_widget_t txt_table_overflow_down; -extern txt_widget_t txt_table_eol; -extern txt_widget_t txt_table_empty; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -void txt_init_table(txt_table_t *table, int columns); - -/** - * Create a new table. - * - * @param columns The number of columns in the new table. - * @return Pointer to the new table structure. - */ - -txt_table_t *txt_new_table(int columns); - -/** - * Create a new table and populate it with provided widgets. - * - * The arguments to this function are variable. Each argument must be a - * pointer to a widget, and the list is terminated with a NULL. - * - * @param columns The number of columns in the new table. - * @return Pointer to the new table structure. - */ - -txt_table_t *txt_make_table(int columns, ...); - -/** - * Create a table containing the specified widgets packed horizontally, - * from left to right. - * - * The arguments to this function are variable. Each argument must - * be a pointer to a widget, and the list is terminated with a - * NULL. - * - * @return Pointer to the new table structure. - */ - -txt_table_t *txt_new_horiz_box(TXT_UNCAST_ARG(first_widget), ...); - -/** - * Get the currently selected widget within a table. - * - * This function will recurse through subtables if necessary. - * - * @param table The table. - * @return Pointer to the widget that is currently selected. - */ - -txt_widget_t *txt_get_selected_widget(TXT_UNCAST_ARG(table)); - -/** - * Add a widget to a table. - * - * Widgets are added to tables horizontally, from left to right. - * For example, for a table with three columns, the first call - * to this function will add a widget to the first column, the second - * call to the second column, the third call to the third column, - * and the fourth will return to the first column, starting a new - * row. - * - * For adding many widgets, it may be easier to use - * @ref txt_add_widgets. - * - * @param table The table. - * @param widget The widget to add. - */ - -void txt_add_widget(TXT_UNCAST_ARG(table), TXT_UNCAST_ARG(widget)); - -/** - * Add multiple widgets to a table. - * - * Widgets are added as described in the documentation for the - * @ref txt_add_widget function. This function adds multiple - * widgets. The number of arguments is variable, and the argument - * list must be terminated by a NULL pointer. - * - * @param table The table. - */ - -void txt_add_widgets(TXT_UNCAST_ARG(table), ...); - -/** - * Select the given widget that is contained within the specified - * table. - * - * This function will recursively search through subtables if - * necessary. - * - * @param table The table. - * @param widget The widget to select. - * @return Non-zero (true) if it has been selected, - * or zero (false) if it was not found within - * this table. - */ - -int txt_select_widget(TXT_UNCAST_ARG(table), TXT_UNCAST_ARG(widget)); - -/** - * Change the number of columns in the table. - * - * Existing widgets in the table will be preserved, unless the change - * reduces the number of columns, in which case the widgets from the - * 'deleted' columns will be freed. - * - * This function can be useful for changing the number of columns in - * a window, which by default are tables containing a single column. - * - * @param table The table. - * @param new_columns The new number of columns. - */ - -void txt_set_table_columns(TXT_UNCAST_ARG(table), int new_columns); - -/** - * Set the widths of the columns of the table. - * - * The arguments to this function are variable, and correspond - * to the number of columns in the table. For example, if a table - * has five columns, the width of each of the five columns must be - * specified. - * - * The width values are in number of characters. - * - * Note that this function only sets the minimum widths for columns; - * if the columns contain widgets that are wider than the widths - * specified, they will be larger. - * - * @param table The table. - */ - -void txt_set_column_widths(TXT_UNCAST_ARG(table), ...); - -/** - * Remove all widgets from a table. - * - * @param table The table. - */ - -void txt_clear_table(TXT_UNCAST_ARG(table)); - -/** - * Hack to move the selection in a table by a 'page', triggered by the - * scrollpane. This acts as per the keyboard events for the arrows, but moves - * the selection by at least the specified number of characters. - * - * @param table The table. - * @param pagex Minimum distance to move the selection horizontally. - * @param pagey Minimum distance to move the selection vertically. - * @return Non-zero if the selection has been changed. - */ - -int txt_page_table(TXT_UNCAST_ARG(table), int pagex, int pagey); - -#endif /* #ifndef TXT_TABLE_T */ diff --git a/games/NXDoom/textscreen/txt_utf8.c b/games/NXDoom/textscreen/txt_utf8.c deleted file mode 100644 index 086025994..000000000 --- a/games/NXDoom/textscreen/txt_utf8.c +++ /dev/null @@ -1,159 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/textscreen/txt_utf8.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include - -#include "txt_utf8.h" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/* Encode a Unicode character as UTF-8, storing it in the buffer 'p' - * and returning the new, incremented position. - */ - -char *txt_encode_utf8(char *p, unsigned int c) -{ - if (c < 0x80) /* 1 character (ASCII): */ - { - p[0] = c; - return p + 1; - } - else if (c < 0x800) /* 2 character: */ - { - p[0] = 0xc0 | (c >> 6); - p[1] = 0x80 | (c & 0x3f); - return p + 2; - } - else if (c < 0x10000) /* 3 chacater: */ - { - p[0] = 0xe0 | (c >> 12); - p[1] = 0x80 | ((c >> 6) & 0x3f); - p[2] = 0x80 | (c & 0x3f); - return p + 3; - } - else if (c < 0x200000) /* 4 character: */ - { - p[0] = 0xf0 | (c >> 18); - p[1] = 0x80 | ((c >> 12) & 0x3f); - p[2] = 0x80 | ((c >> 6) & 0x3f); - p[3] = 0x80 | (c & 0x3f); - return p + 4; - } - else - { - return p; /* Too big! */ - } -} - -/* Decode UTF-8 character, incrementing *ptr over the decoded bytes. */ - -unsigned int txt_decode_utf8(const char **ptr) -{ - const char *p = *ptr; - unsigned int c; - - /* UTF-8 decode. */ - - if ((*p & 0x80) == 0) /* 1 character (ASCII): */ - { - c = *p; - *ptr += 1; - } - else if ((p[0] & 0xe0) == 0xc0 /* 2 character: */ - && (p[1] & 0xc0) == 0x80) - { - c = ((p[0] & 0x1f) << 6) | (p[1] & 0x3f); - *ptr += 2; - } - else if ((p[0] & 0xf0) == 0xe0 /* 3 character: */ - && (p[1] & 0xc0) == 0x80 && (p[2] & 0xc0) == 0x80) - { - c = ((p[0] & 0x0f) << 12) | ((p[1] & 0x3f) << 6) | (p[2] & 0x3f); - *ptr += 3; - } - else if ((p[0] & 0xf8) == 0xf0 /* 4 character: */ - && (p[1] & 0xc0) == 0x80 && (p[2] & 0xc0) == 0x80 && - (p[3] & 0xc0) == 0x80) - { - c = ((p[0] & 0x07) << 18) | ((p[1] & 0x3f) << 12) | - ((p[2] & 0x3f) << 6) | (p[3] & 0x3f); - *ptr += 4; - } - else - { - /* Decode failure. - * Don't bother with 5/6 byte sequences. - */ - - c = 0; - } - - return c; -} - -/* Count the number of characters in a UTF-8 string. */ - -unsigned int txt_utf8_strlen(const char *s) -{ - const char *p; - unsigned int result = 0; - unsigned int c; - - for (p = s; *p != '\0'; ) - { - c = txt_decode_utf8(&p); - - if (c == 0) - { - break; - } - - ++result; - } - - return result; -} - -/* Skip past the first n characters in a UTF-8 string. */ - -char *txt_utf8_skip_chars(const char *s, unsigned int n) -{ - unsigned int i; - const char *p; - - p = s; - - for (i = 0; i < n; ++i) - { - if (txt_decode_utf8(&p) == 0) - { - break; - } - } - - return (char *)p; -} diff --git a/games/NXDoom/textscreen/txt_utf8.h b/games/NXDoom/textscreen/txt_utf8.h deleted file mode 100644 index 0d2f98ef3..000000000 --- a/games/NXDoom/textscreen/txt_utf8.h +++ /dev/null @@ -1,38 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/textscreen/txt_utf8.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - ****************************************************************************/ - -#ifndef TXT_UTF8_H -#define TXT_UTF8_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -char *txt_encode_utf8(char *p, unsigned int c); -unsigned int txt_decode_utf8(const char **ptr); -unsigned int txt_utf8_strlen(const char *s); -char *txt_utf8_skip_chars(const char *s, unsigned int n); - -#endif /* TXT_UTF8_H */ diff --git a/games/NXDoom/textscreen/txt_widget.c b/games/NXDoom/textscreen/txt_widget.c deleted file mode 100644 index 01c44643c..000000000 --- a/games/NXDoom/textscreen/txt_widget.c +++ /dev/null @@ -1,350 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/textscreen/txt_widget.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -#include "txt_desktop.h" -#include "txt_gui.h" -#include "txt_io.h" -#include "txt_widget.h" - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -typedef struct -{ - char *signal_name; - txt_widget_signal_f func; - void *user_data; -} txt_callback_t; - -struct txt_callback_table_s -{ - int refcount; - txt_callback_t *callbacks; - int num_callbacks; -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static int txt_contains_widget(TXT_UNCAST_ARG(haystack), - TXT_UNCAST_ARG(needle)) -{ - TXT_CAST_ARG(txt_widget_t, haystack); - TXT_CAST_ARG(txt_widget_t, needle); - - while (needle != NULL) - { - if (needle == haystack) - { - return 1; - } - - needle = needle->parent; - } - - return 0; -} - -static txt_callback_table_t *txt_new_callback_table(void) -{ - txt_callback_table_t *table; - - table = malloc(sizeof(txt_callback_table_t)); - table->callbacks = NULL; - table->num_callbacks = 0; - table->refcount = 1; - - return table; -} - -static void txt_ref_callback_table(txt_callback_table_t *table) -{ - ++table->refcount; -} - -static void txt_unref_callback_table(txt_callback_table_t *table) -{ - int i; - - --table->refcount; - - if (table->refcount == 0) - { - /* No more references to this table */ - - for (i = 0; i < table->num_callbacks; ++i) - { - free(table->callbacks[i].signal_name); - } - - free(table->callbacks); - free(table); - } -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -void txt_init_widget(TXT_UNCAST_ARG(widget), - txt_widget_class_t *widget_class) -{ - TXT_CAST_ARG(txt_widget_t, widget); - - widget->widget_class = widget_class; - widget->callback_table = txt_new_callback_table(); - widget->parent = NULL; - - /* Not focused until we hear otherwise. */ - - widget->focused = 0; - - /* Visible by default. */ - - widget->visible = 1; - - /* Align left by default */ - - widget->align = TXT_HORIZ_LEFT; -} - -void txt_signal_connect(TXT_UNCAST_ARG(widget), const char *signal_name, - txt_widget_signal_f func, void *user_data) -{ - TXT_CAST_ARG(txt_widget_t, widget); - txt_callback_table_t *table; - txt_callback_t *callback; - - table = widget->callback_table; - - /* Add a new callback to the table */ - - table->callbacks = realloc( - table->callbacks, sizeof(txt_callback_t) * (table->num_callbacks + 1)); - callback = &table->callbacks[table->num_callbacks]; - ++table->num_callbacks; - - callback->signal_name = strdup(signal_name); - callback->func = func; - callback->user_data = user_data; -} - -void txt_emit_signal(TXT_UNCAST_ARG(widget), const char *signal_name) -{ - TXT_CAST_ARG(txt_widget_t, widget); - txt_callback_table_t *table; - int i; - - table = widget->callback_table; - - /* Don't destroy the table while we're searching through it - * (one of the callbacks may destroy this window) - */ - - txt_ref_callback_table(table); - - /* Search the table for all callbacks with this name and invoke - * the functions. - */ - - for (i = 0; i < table->num_callbacks; ++i) - { - if (!strcmp(table->callbacks[i].signal_name, signal_name)) - { - table->callbacks[i].func(widget, table->callbacks[i].user_data); - } - } - - /* Finished using the table */ - - txt_unref_callback_table(table); -} - -void txt_calc_widget_size(TXT_UNCAST_ARG(widget)) -{ - TXT_CAST_ARG(txt_widget_t, widget); - - widget->widget_class->size_calc(widget); -} - -void txt_draw_widget(TXT_UNCAST_ARG(widget)) -{ - TXT_CAST_ARG(txt_widget_t, widget); - txt_saved_colors_t colors; - - /* The drawing function might change the fg/bg colors, - * so make sure we restore them after it's done. - */ - - txt_save_colours(&colors); - - /* For convenience... */ - - txt_goto_xy(widget->x, widget->y); - - /* Call drawer method */ - - widget->widget_class->drawer(widget); - - txt_restore_colours(&colors); -} - -void txt_destroy_widget(TXT_UNCAST_ARG(widget)) -{ - TXT_CAST_ARG(txt_widget_t, widget); - - widget->widget_class->destructor(widget); - txt_unref_callback_table(widget->callback_table); - free(widget); -} - -int txt_widget_key_press(TXT_UNCAST_ARG(widget), int key) -{ - TXT_CAST_ARG(txt_widget_t, widget); - - if (widget->widget_class->key_press != NULL) - { - return widget->widget_class->key_press(widget, key); - } - - return 0; -} - -void txt_set_widget_focus(TXT_UNCAST_ARG(widget), int focused) -{ - TXT_CAST_ARG(txt_widget_t, widget); - - if (widget == NULL) - { - return; - } - - if (widget->focused != focused) - { - widget->focused = focused; - - if (widget->widget_class->focus_change != NULL) - { - widget->widget_class->focus_change(widget, focused); - } - } -} - -void txt_set_widget_align(TXT_UNCAST_ARG(widget), - txt_horiz_align_t horiz_align) -{ - TXT_CAST_ARG(txt_widget_t, widget); - - widget->align = horiz_align; -} - -void txt_widget_mouse_press(TXT_UNCAST_ARG(widget), int x, int y, int b) -{ - TXT_CAST_ARG(txt_widget_t, widget); - - if (widget->widget_class->mouse_press != NULL) - { - widget->widget_class->mouse_press(widget, x, y, b); - } -} - -void txt_layout_widget(TXT_UNCAST_ARG(widget)) -{ - TXT_CAST_ARG(txt_widget_t, widget); - - if (widget->widget_class->layout != NULL) - { - widget->widget_class->layout(widget); - } -} - -int txt_always_selectable(TXT_UNCAST_ARG(widget)) -{ - return 1; -} - -int txt_never_selectable(TXT_UNCAST_ARG(widget)) -{ - return 0; -} - -int txt_selectable_widget(TXT_UNCAST_ARG(widget)) -{ - TXT_CAST_ARG(txt_widget_t, widget); - - if (widget->widget_class->selectable != NULL) - { - return widget->widget_class->selectable(widget); - } - else - { - return 0; - } -} - -int txt_hovering_over_widget(TXT_UNCAST_ARG(widget)) -{ - TXT_CAST_ARG(txt_widget_t, widget); - txt_window_t *active_window; - int x; - int y; - - /* We can only be hovering over widgets in the active window. */ - - active_window = txt_get_active_window(); - - if (active_window == NULL || !txt_contains_widget(active_window, widget)) - { - return 0; - } - - /* Is the mouse cursor within the bounds of the widget? */ - - txt_get_mouse_position(&x, &y); - - return (x >= widget->x && x < widget->x + widget->w && y >= widget->y && - y < widget->y + widget->h); -} - -void txt_set_widget_bg(TXT_UNCAST_ARG(widget)) -{ - TXT_CAST_ARG(txt_widget_t, widget); - - if (widget->focused) - { - txt_bgcolour(TXT_COLOR_GREY, 0); - } - else if (txt_hovering_over_widget(widget)) - { - txt_bgcolour(TXT_HOVER_BACKGROUND, 0); - } - else - { - /* Use normal window background. */ - } -} diff --git a/games/NXDoom/textscreen/txt_widget.h b/games/NXDoom/textscreen/txt_widget.h deleted file mode 100644 index 109be5e9c..000000000 --- a/games/NXDoom/textscreen/txt_widget.h +++ /dev/null @@ -1,190 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/textscreen/txt_widget.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - ****************************************************************************/ - -#ifndef TXT_WIDGET_H -#define TXT_WIDGET_H - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define TXT_UNCAST_ARG_NAME(name) uncast_##name -#define TXT_UNCAST_ARG(name) void *TXT_UNCAST_ARG_NAME(name) -#define TXT_CAST_ARG(type, name) type *name = (type *)uncast_##name - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -/* Forward definitions */ - -typedef struct txt_table_s txt_table_t; -typedef struct txt_strut_s txt_strut_t; -typedef struct txt_spincontrol_s txt_spincontrol_t; -typedef struct txt_separator_s txt_separator_t; -typedef struct txt_scrollpane_s txt_scrollpane_t; -typedef struct txt_radiobutton_s txt_radiobutton_t; -typedef struct txt_inputbox_s txt_inputbox_t; -typedef struct txt_dropdown_list_s txt_dropdown_list_t; -typedef struct txt_checkbox_s txt_checkbox_t; -typedef struct txt_button_s txt_button_t; - -typedef enum -{ - TXT_VERT_TOP, - TXT_VERT_CENTER, - TXT_VERT_BOTTOM, -} txt_vert_align_t; - -typedef enum -{ - TXT_HORIZ_LEFT, - TXT_HORIZ_CENTER, - TXT_HORIZ_RIGHT, -} txt_horiz_align_t; - -/* A GUI widget. - * - * A widget is an individual component of a GUI. Various different widget - * types exist. - * - * Widgets may emit signals. The types of signal emitted by a widget - * depend on the type of the widget. It is possible to be notified - * when a signal occurs using the @ref txt_signal_connect function. - */ - -typedef struct txt_widget_s txt_widget_t; - -typedef struct txt_widget_class_s txt_widget_class_t; -typedef struct txt_callback_table_s txt_callback_table_t; - -typedef void (*txt_widget_size_calc_f)(TXT_UNCAST_ARG(widget)); -typedef void (*txt_widget_drawer_f)(TXT_UNCAST_ARG(widget)); -typedef void (*txt_widget_destroy_f)(TXT_UNCAST_ARG(widget)); -typedef int (*txt_widget_keypress_f)(TXT_UNCAST_ARG(widget), int key); -typedef void (*txt_widget_signal_f)(TXT_UNCAST_ARG(widget), void *user_data); -typedef void (*txt_mouse_press_f)(TXT_UNCAST_ARG(widget), int x, int y, - int b); -typedef void (*txt_widget_layout_f)(TXT_UNCAST_ARG(widget)); -typedef int (*txt_widget_selectable_f)(TXT_UNCAST_ARG(widget)); -typedef void (*txt_widget_focus_f)(TXT_UNCAST_ARG(widget), int focused); - -struct txt_widget_class_s -{ - txt_widget_selectable_f selectable; - txt_widget_size_calc_f size_calc; - txt_widget_drawer_f drawer; - txt_widget_keypress_f key_press; - txt_widget_destroy_f destructor; - txt_mouse_press_f mouse_press; - txt_widget_layout_f layout; - txt_widget_focus_f focus_change; -}; - -struct txt_widget_s -{ - txt_widget_class_t *widget_class; - txt_callback_table_t *callback_table; - int visible; - txt_horiz_align_t align; - int focused; - - /* These are set automatically when the window is drawn and should - * not be set manually. - */ - - int x; - int y; - unsigned int w; - unsigned int h; - - /* Pointer up to parent widget that contains this widget. */ - - txt_widget_t *parent; -}; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -void txt_init_widget(TXT_UNCAST_ARG(widget), - txt_widget_class_t *widget_class); -void txt_calc_widget_size(TXT_UNCAST_ARG(widget)); -void txt_draw_widget(TXT_UNCAST_ARG(widget)); -void txt_emit_signal(TXT_UNCAST_ARG(widget), const char *signal_name); -int txt_widget_key_press(TXT_UNCAST_ARG(widget), int key); -void txt_widget_mouse_press(TXT_UNCAST_ARG(widget), int x, int y, int b); -void txt_destroy_widget(TXT_UNCAST_ARG(widget)); -void txt_layout_widget(TXT_UNCAST_ARG(widget)); -int txt_always_selectable(TXT_UNCAST_ARG(widget)); -int txt_never_selectable(TXT_UNCAST_ARG(widget)); -void txt_set_widget_focus(TXT_UNCAST_ARG(widget), int focused); - -/** - * Set a callback function to be invoked when a signal occurs. - * - * @param widget The widget to watch. - * @param signal_name The signal to watch. - * @param func The callback function to invoke. - * @param user_data User-specified pointer to pass to the callback - * function. - */ - -void txt_signal_connect(TXT_UNCAST_ARG(widget), const char *signal_name, - txt_widget_signal_f func, void *user_data); - -/** - * Set the policy for how a widget should be aligned within a table. - * By default, widgets are aligned to the left of the column. - * - * @param widget The widget. - * @param horiz_align The alignment to use. - */ - -void txt_set_widget_align(TXT_UNCAST_ARG(widget), - txt_horiz_align_t horiz_align); - -/** - * Query whether a widget is selectable with the cursor. - * - * @param widget The widget. - * @return Non-zero if the widget is selectable. - */ - -int txt_selectable_widget(TXT_UNCAST_ARG(widget)); - -/** - * Query whether the mouse is hovering over the specified widget. - * - * @param widget The widget. - * @return Non-zero if the mouse cursor is over the widget. - */ - -int txt_hovering_over_widget(TXT_UNCAST_ARG(widget)); - -/** - * Set the background to draw the specified widget, depending on - * whether it is selected and the mouse is hovering over it. - * - * @param widget The widget. - */ - -void txt_set_widget_bg(TXT_UNCAST_ARG(widget)); - -#endif /* TXT_WIDGET_H */ diff --git a/games/NXDoom/textscreen/txt_window.c b/games/NXDoom/textscreen/txt_window.c deleted file mode 100644 index 1f48eac5a..000000000 --- a/games/NXDoom/textscreen/txt_window.c +++ /dev/null @@ -1,609 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/textscreen/txt_window.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include -#include - -#include "doomkeys.h" - -#include "txt_desktop.h" -#include "txt_gui.h" -#include "txt_io.h" -#include "txt_label.h" -#include "txt_main.h" -#include "txt_separator.h" -#include "txt_window.h" - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static void calc_window_position(txt_window_t *window) -{ - switch (window->horiz_align) - { - case TXT_HORIZ_LEFT: - window->window_x = window->x; - break; - case TXT_HORIZ_CENTER: - window->window_x = window->x - (window->window_w / 2); - break; - case TXT_HORIZ_RIGHT: - window->window_x = window->x - (window->window_w - 1); - break; - } - - switch (window->vert_align) - { - case TXT_VERT_TOP: - window->window_y = window->y; - break; - case TXT_VERT_CENTER: - window->window_y = window->y - (window->window_h / 2); - break; - case TXT_VERT_BOTTOM: - window->window_y = window->y - (window->window_h - 1); - break; - } -} - -static void layout_action_area(txt_window_t *window) -{ - txt_widget_t *widget; - int space_available; - int space_left_offset; - - /* We need to calculate the available horizontal space for the center - * action widget, so that we can center it within it. - * To start with, we have the entire action area available. - */ - - space_available = window->window_w; - space_left_offset = 0; - - /* Left action */ - - if (window->actions[TXT_HORIZ_LEFT] != NULL) - { - widget = window->actions[TXT_HORIZ_LEFT]; - - txt_calc_widget_size(widget); - - widget->x = window->window_x + 1; - widget->y = window->window_y + window->window_h - widget->h - 1; - - /* Adjust available space: */ - - space_available -= widget->w; - space_left_offset += widget->w; - - txt_layout_widget(widget); - } - - /* Draw the right action */ - - if (window->actions[TXT_HORIZ_RIGHT] != NULL) - { - widget = window->actions[TXT_HORIZ_RIGHT]; - - txt_calc_widget_size(widget); - - widget->x = window->window_x + window->window_w - 1 - widget->w; - widget->y = window->window_y + window->window_h - widget->h - 1; - - /* Adjust available space: */ - - space_available -= widget->w; - - txt_layout_widget(widget); - } - - /* Draw the center action */ - - if (window->actions[TXT_HORIZ_CENTER] != NULL) - { - widget = window->actions[TXT_HORIZ_CENTER]; - - txt_calc_widget_size(widget); - - /* The left and right widgets have left a space sandwiched between - * them. Center this widget within that space. - */ - - widget->x = window->window_x + space_left_offset + - (space_available - widget->w) / 2; - widget->y = window->window_y + window->window_h - widget->h - 1; - - txt_layout_widget(widget); - } -} - -static void draw_action_area(txt_window_t *window) -{ - int i; - - for (i = 0; i < 3; ++i) - { - if (window->actions[i] != NULL) - { - txt_draw_widget(window->actions[i]); - } - } -} - -static void calc_action_area_size(txt_window_t *window, unsigned int *w, - unsigned int *h) -{ - txt_widget_t *widget; - int i; - - *w = 0; - *h = 0; - - /* Calculate the width of all the action widgets and use this - * to create an overall min. width of the action area - */ - - for (i = 0; i < 3; ++i) - { - widget = (txt_widget_t *)window->actions[i]; - - if (widget != NULL) - { - txt_calc_widget_size(widget); - *w += widget->w; - - if (widget->h > *h) - { - *h = widget->h; - } - } - } -} - -/* Sets size and position of all widgets in a window */ - -static void txt_layout_window(txt_window_t *window) -{ - txt_widget_t *widgets = (txt_widget_t *)window; - unsigned int widgets_w; - unsigned int actionarea_w; - unsigned int actionarea_h; - - /* Calculate size of table */ - - txt_calc_widget_size(window); - - /* Widgets area: add one character of padding on each side */ - - widgets_w = widgets->w + 2; - - /* Calculate the size of the action area - * Make window wide enough to action area - */ - - calc_action_area_size(window, &actionarea_w, &actionarea_h); - - if (actionarea_w > widgets_w) widgets_w = actionarea_w; - - /* Set the window size based on widgets_w */ - - window->window_w = widgets_w + 2; - window->window_h = widgets->h + 1; - - /* If the window has a title, add an extra two lines */ - - if (window->title != NULL) - { - window->window_h += 2; - } - - /* If the window has an action area, add extra lines */ - - if (actionarea_h > 0) - { - window->window_h += actionarea_h + 1; - } - - /* Use the x,y position as the centerpoint and find the location to - * draw the window. - */ - - calc_window_position(window); - - /* Set the table size and position */ - - widgets->w = widgets_w - 2; - - /* widgets->h (already set) */ - - widgets->x = window->window_x + 2; - widgets->y = window->window_y; - - if (window->title != NULL) - { - widgets->y += 2; - } - - /* Layout the table and action area */ - - layout_action_area(window); - txt_layout_widget(widgets); -} - -static void txt_open_url(const char *url) -{ -#if 0 - char *cmd; - size_t cmd_len; - int retval; - - cmd_len = strlen(url) + 30; - cmd = malloc(cmd_len); - - /* The Unix situation sucks as usual, but the closest thing to a - * standard that exists is the xdg-utils package. - */ - - if (system("xdg-open --version 2>/dev/null") != 0) - { - fprintf(stderr, - "xdg-utils is not installed. Can't open this URL:\n%s\n", url); - free(cmd); - return; - } - - txt_snprintf(cmd, cmd_len, "xdg-open \"%s\"", url); - - retval = system(cmd); - if (retval != 0) - { - fprintf(stderr, "txt_open_url: error executing '%s'; return code %d\n", - cmd, retval); - } - - free(cmd); -#endif -} - -static int mouse_button_press(txt_window_t *window, int b) -{ - int x; - int y; - int i; - txt_widget_t *widgets; - txt_widget_t *widget; - - /* Lay out the window, set positions and sizes of all widgets */ - - txt_layout_window(window); - - /* Get the current mouse position */ - - txt_get_mouse_position(&x, &y); - - /* Try the mouse button listener - * This happens whether it is in the window range or not - */ - - if (window->mouse_listener != NULL) - { - /* Mouse listener can eat button presses */ - - if (window->mouse_listener(window, x, y, b, - window->mouse_listener_data)) - { - return 1; - } - } - - /* Is it within the table range? */ - - widgets = (txt_widget_t *)window; - - if (x >= widgets->x && x < (signed)(widgets->x + widgets->w) && - y >= widgets->y && y < (signed)(widgets->y + widgets->h)) - { - txt_widget_mouse_press(window, x, y, b); - return 1; - } - - /* Was one of the action area buttons pressed? */ - - for (i = 0; i < 3; ++i) - { - widget = window->actions[i]; - - if (widget != NULL && x >= widget->x && - x < (signed)(widget->x + widget->w) && y >= widget->y && - y < (signed)(widget->y + widget->h)) - { - int was_focused; - - /* Main table temporarily loses focus when action area button - * is clicked. This way, any active input boxes that depend - * on having focus will save their values before the - * action is performed. - */ - - was_focused = window->table.widget.focused; - txt_set_widget_focus(window, 0); - txt_set_widget_focus(window, was_focused); - - /* Pass through mouse press. */ - - txt_widget_mouse_press(widget, x, y, b); - return 1; - } - } - - return 0; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -void txt_set_window_action(txt_window_t *window, txt_horiz_align_t position, - TXT_UNCAST_ARG(action)) -{ - TXT_CAST_ARG(txt_widget_t, action); - - if (window->actions[position] != NULL) - { - txt_destroy_widget(window->actions[position]); - } - - window->actions[position] = action; - - /* Maintain parent pointer. */ - - if (action != NULL) - { - action->parent = &window->table.widget; - } -} - -txt_window_t *txt_new_window(const char *title) -{ - int i; - - txt_window_t *win; - - win = malloc(sizeof(txt_window_t)); - - txt_init_table(&win->table, 1); - - if (title == NULL) - { - win->title = NULL; - } - else - { - win->title = strdup(title); - } - - win->x = TXT_SCREEN_W / 2; - win->y = TXT_SCREEN_H / 2; - win->horiz_align = TXT_HORIZ_CENTER; - win->vert_align = TXT_VERT_CENTER; - win->key_listener = NULL; - win->mouse_listener = NULL; - win->help_url = NULL; - - txt_add_widget(win, txt_new_separator(NULL)); - - for (i = 0; i < 3; ++i) - { - win->actions[i] = NULL; - } - - txt_add_desktop_window(win); - - /* Default actions */ - - txt_set_window_action(win, TXT_HORIZ_LEFT, - txt_new_window_escape_action(win)); - txt_set_window_action(win, TXT_HORIZ_RIGHT, - txt_new_window_select_action(win)); - - return win; -} - -void txt_close_window(txt_window_t *window) -{ - int i; - - txt_emit_signal(window, "closed"); - txt_remove_desktop_window(window); - - free(window->title); - - /* Destroy all actions */ - - for (i = 0; i < 3; ++i) - { - if (window->actions[i] != NULL) - { - txt_destroy_widget(window->actions[i]); - } - } - - /* Destroy table and window */ - - txt_destroy_widget(window); -} - -void txt_draw_window(txt_window_t *window) -{ - txt_widget_t *widgets; - - txt_layout_window(window); - - if (window->table.widget.focused) - { - txt_bgcolour(TXT_ACTIVE_WINDOW_BACKGROUND, 0); - } - else - { - txt_bgcolour(TXT_INACTIVE_WINDOW_BACKGROUND, 0); - } - - txt_fgcolour(TXT_COLOR_BRIGHT_WHITE); - - /* Draw the window */ - - txt_draw_window_frame(window->title, window->window_x, window->window_y, - window->window_w, window->window_h); - - /* Draw all widgets */ - - txt_draw_widget(window); - - /* Draw an action area, if we have one */ - - widgets = (txt_widget_t *)window; - - if (widgets->y + widgets->h < window->window_y + window->window_h - 1) - { - /* Separator for action area */ - - txt_draw_separator(window->window_x, widgets->y + widgets->h, - window->window_w); - - /* Action area at the window bottom */ - - draw_action_area(window); - } -} - -void txt_set_window_position(txt_window_t *window, - txt_horiz_align_t horiz_align, - txt_vert_align_t vert_align, int x, int y) -{ - window->vert_align = vert_align; - window->horiz_align = horiz_align; - window->x = x; - window->y = y; -} - -int txt_window_keypress(txt_window_t *window, int c) -{ - int i; - - /* Is this a mouse button ? */ - - if (c >= TXT_MOUSE_BASE && c < TXT_MOUSE_BASE + TXT_MAX_MOUSE_BUTTONS) - { - return mouse_button_press(window, c); - } - - /* Try the window key spy */ - - if (window->key_listener != NULL) - { - /* key listener can eat keys */ - - if (window->key_listener(window, c, window->key_listener_data)) - { - return 1; - } - } - - /* Send to the currently selected widget: */ - - if (txt_widget_key_press(window, c)) - { - return 1; - } - - /* Try all of the action buttons */ - - for (i = 0; i < 3; ++i) - { - if (window->actions[i] != NULL && - txt_widget_key_press(window->actions[i], c)) - { - return 1; - } - } - - return 0; -} - -void txt_set_key_listener(txt_window_t *window, - txt_window_keypress_t key_listener, - void *user_data) -{ - window->key_listener = key_listener; - window->key_listener_data = user_data; -} - -void txt_set_mouse_listener(txt_window_t *window, - txt_window_mouse_press_t mouse_listener, - void *user_data) -{ - window->mouse_listener = mouse_listener; - window->mouse_listener_data = user_data; -} - -void txt_set_window_focus(txt_window_t *window, int focused) -{ - txt_set_widget_focus(window, focused); -} - -void txt_set_window_help_url(txt_window_t *window, const char *help_url) -{ - window->help_url = help_url; -} - -void txt_open_window_help_url(txt_window_t *window) -{ - if (window->help_url != NULL) - { - txt_open_url(window->help_url); - } -} - -txt_window_t *txt_message_box(const char *title, const char *message, ...) -{ - txt_window_t *window; - char buf[256]; - va_list args; - - va_start(args, message); - txt_vsnprintf(buf, sizeof(buf), message, args); - va_end(args); - - window = txt_new_window(title); - txt_add_widget(window, txt_new_label(buf)); - - txt_set_window_action(window, TXT_HORIZ_LEFT, NULL); - txt_set_window_action(window, TXT_HORIZ_CENTER, - txt_new_window_escape_action(window)); - txt_set_window_action(window, TXT_HORIZ_RIGHT, NULL); - - return window; -} diff --git a/games/NXDoom/textscreen/txt_window.h b/games/NXDoom/textscreen/txt_window.h deleted file mode 100644 index b2803ce56..000000000 --- a/games/NXDoom/textscreen/txt_window.h +++ /dev/null @@ -1,215 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/textscreen/txt_window.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - ****************************************************************************/ - -#ifndef TXT_WINDOW_H -#define TXT_WINDOW_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "txt_table.h" -#include "txt_widget.h" - -#include "txt_window_action.h" - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -/* Callback function for window key presses */ - -typedef int (*txt_window_keypress_t)(txt_window_t *window, int key, - void *user_data); -typedef int (*txt_window_mouse_press_t)(txt_window_t *window, int x, int y, - int b, void *user_data); - -struct txt_window_s -{ - /* Base class: all windows are tables with one column. */ - - txt_table_t table; - - /* Window title */ - - char *title; - - /* Screen coordinates of the window */ - - txt_vert_align_t vert_align; - txt_horiz_align_t horiz_align; - int x; - int y; - - /* Actions that appear in the box at the bottom of the window */ - - txt_widget_t *actions[3]; - - /* Callback functions to invoke when keys/mouse buttons are pressed */ - - txt_window_keypress_t key_listener; - void *key_listener_data; - txt_window_mouse_press_t mouse_listener; - void *mouse_listener_data; - - /* These are set automatically when the window is drawn */ - - int window_x; - int window_y; - unsigned int window_w; - unsigned int window_h; - - /* URL of a webpage with help about this window. If set, a help key - * indicator is shown while this window is active. - */ - - const char *help_url; -}; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/** - * Open a new window. - * - * @param title Title to display in the titlebar of the new window - * (UTF-8 format). - * @return Pointer to a new @ref txt_window_t structure - * representing the new window. - */ - -txt_window_t *txt_new_window(const char *title); - -/** - * Close a window. - * - * @param window Tine window to close. - */ - -void txt_close_window(txt_window_t *window); - -/** - * Set the position of a window on the screen. - * - * The position is specified as a pair of x, y, coordinates on the - * screen. These specify the position of a particular point on the - * window. The following are some examples: - * - * - * // Centered on the screen: - * - * txt_set_window_position(window, TXT_HORIZ_CENTER, TXT_VERT_CENTER, - * TXT_SCREEN_W / 2, TXT_SCREEN_H / 2); - * - * // Horizontally centered, with top of the window on line 6: - * - * txt_set_window_position(window, TXT_HORIZ_CENTER, TXT_VERT_TOP, - * TXT_SCREEN_W / 2, 6); - * - * // Top-left of window at 20, 6: - * - * txt_set_window_position(window, TXT_HORIZ_LEFT, TXT_VERT_TOP, 20, 6); - * - * - * @param window The window. - * @param horiz_align Horizontal location on the window for the X - * position. - * @param vert_align Vertical location on the window for the Y position. - * @param x X coordinate (horizontal axis) for window position. - * @param y Y coordinate (vertical axis) for window position. - */ - -void txt_set_window_position(txt_window_t *window, - txt_horiz_align_t horiz_align, - txt_vert_align_t vert_align, int x, int y); - -/** - * Set a window action for a given window. - * - * Each window can have up to three window actions, which provide - * keyboard shortcuts that can be used within a given window. - * - * @param window The window. - * @param position The window action slot to set (left, center or right). - * @param action The window action widget. If this is NULL, any - * current window action in the given slot is removed. - */ - -void txt_set_window_action(txt_window_t *window, txt_horiz_align_t position, - TXT_UNCAST_ARG(action)); - -/** - * Set a callback function to be invoked whenever a key is pressed within - * a window. - * - * @param window The window. - * @param key_listener Callback function. - * @param user_data User-specified pointer to pass to the callback - * function. - */ - -void txt_set_key_listener(txt_window_t *window, - txt_window_keypress_t key_listener, - void *user_data); - -/** - * Set a callback function to be invoked whenever a mouse button is pressed - * within a window. - * - * @param window The window. - * @param mouse_listener Callback function. - * @param user_data User-specified pointer to pass to the callback - * function. - */ - -void txt_set_mouse_listener(txt_window_t *window, - txt_window_mouse_press_t mouse_listener, - void *user_data); - -/** - * Open a window displaying a message. - * - * @param title Title of the window (UTF-8 format). - * @param message The message to display in the window - * (UTF-8 format). - * @return The new window. - */ - -txt_window_t *txt_message_box(const char *title, const char *message, ...); - -/** - * Set the help URL for the given window. - * - * @param window The window. - * @param help_url String containing URL of the help page for this - * window, or NULL to set no help for this window. - */ - -void txt_set_window_help_url(txt_window_t *window, const char *help_url); - -/** - * Open the help URL for the given window, if one is set. - * - * @param window The window. - */ - -void txt_open_window_help_url(txt_window_t *window); - -#endif /* TXT_WINDOW_H */ diff --git a/games/NXDoom/textscreen/txt_window_action.c b/games/NXDoom/textscreen/txt_window_action.c deleted file mode 100644 index d14f41d66..000000000 --- a/games/NXDoom/textscreen/txt_window_action.c +++ /dev/null @@ -1,203 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/textscreen/txt_window_action.c - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include - -#include "doomkeys.h" - -#include "txt_gui.h" -#include "txt_io.h" -#include "txt_main.h" -#include "txt_utf8.h" -#include "txt_window.h" -#include "txt_window_action.h" - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -static void txt_window_action_size_calc(TXT_UNCAST_ARG(action)); -static void txt_window_action_drawer(TXT_UNCAST_ARG(action)); -static void txt_window_action_destructor(TXT_UNCAST_ARG(action)); -static int txt_window_action_key_press(TXT_UNCAST_ARG(action), int key); -static void txt_window_action_mouse_press(TXT_UNCAST_ARG(action), int x, - int y, int b); - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -txt_widget_class_t txt_window_action_class = -{ - txt_always_selectable, - txt_window_action_size_calc, - txt_window_action_drawer, - txt_window_action_key_press, - txt_window_action_destructor, - txt_window_action_mouse_press, - NULL, -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static void txt_window_action_size_calc(TXT_UNCAST_ARG(action)) -{ - TXT_CAST_ARG(txt_window_action_t, action); - char buf[10]; - - txt_get_key_description(action->key, buf, sizeof(buf)); - - /* Width is label length, plus key description length, plus '=' - * and two surrounding spaces. - */ - - action->widget.w = - txt_utf8_strlen(action->label) + txt_utf8_strlen(buf) + 3; - action->widget.h = 1; -} - -static void txt_window_action_drawer(TXT_UNCAST_ARG(action)) -{ - TXT_CAST_ARG(txt_window_action_t, action); - int hovering; - char buf[10]; - - txt_get_key_description(action->key, buf, sizeof(buf)); - - hovering = txt_hovering_over_widget(action); - txt_set_widget_bg(action); - - txt_draw_string(" "); - txt_fgcolour(hovering ? TXT_COLOR_BRIGHT_WHITE : TXT_COLOR_BRIGHT_GREEN); - txt_draw_string(buf); - txt_fgcolour(TXT_COLOR_BRIGHT_CYAN); - txt_draw_string("="); - - txt_fgcolour(TXT_COLOR_BRIGHT_WHITE); - txt_draw_string(action->label); - txt_draw_string(" "); -} - -static void txt_window_action_destructor(TXT_UNCAST_ARG(action)) -{ - TXT_CAST_ARG(txt_window_action_t, action); - - free(action->label); -} - -static int txt_window_action_key_press(TXT_UNCAST_ARG(action), int key) -{ - TXT_CAST_ARG(txt_window_action_t, action); - - if (tolower(key) == tolower(action->key)) - { - txt_emit_signal(action, "pressed"); - return 1; - } - - return 0; -} - -static void txt_window_action_mouse_press(TXT_UNCAST_ARG(action), int x, - int y, int b) -{ - TXT_CAST_ARG(txt_window_action_t, action); - - /* Simulate a press of the key */ - - if (b == TXT_MOUSE_LEFT) - { - txt_window_action_key_press(action, action->key); - } -} - -static void window_close_callback(TXT_UNCAST_ARG(widget), - TXT_UNCAST_ARG(window)) -{ - TXT_CAST_ARG(txt_window_t, window); - - txt_close_window(window); -} - -static void window_select_callback(TXT_UNCAST_ARG(widget), - TXT_UNCAST_ARG(window)) -{ - TXT_CAST_ARG(txt_window_t, window); - - txt_widget_key_press(window, KEY_ENTER); -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -txt_window_action_t *txt_new_window_action(int key, const char *label) -{ - txt_window_action_t *action; - - action = malloc(sizeof(txt_window_action_t)); - - txt_init_widget(action, &txt_window_action_class); - action->key = key; - action->label = strdup(label); - - return action; -} - -/* An action with the name "close" the closes the window */ - -txt_window_action_t *txt_new_window_escape_action(txt_window_t *window) -{ - txt_window_action_t *action; - - action = txt_new_window_action(KEY_ESCAPE, "Close"); - txt_signal_connect(action, "pressed", window_close_callback, window); - - return action; -} - -/* Exactly the same as the above, but the button is named "abort" */ - -txt_window_action_t *txt_new_window_abort_action(txt_window_t *window) -{ - txt_window_action_t *action; - - action = txt_new_window_action(KEY_ESCAPE, "Abort"); - txt_signal_connect(action, "pressed", window_close_callback, window); - - return action; -} - -txt_window_action_t *txt_new_window_select_action(txt_window_t *window) -{ - txt_window_action_t *action; - - action = txt_new_window_action(KEY_ENTER, "Select"); - txt_signal_connect(action, "pressed", window_select_callback, window); - - return action; -} diff --git a/games/NXDoom/textscreen/txt_window_action.h b/games/NXDoom/textscreen/txt_window_action.h deleted file mode 100644 index c76c6ecae..000000000 --- a/games/NXDoom/textscreen/txt_window_action.h +++ /dev/null @@ -1,125 +0,0 @@ -/**************************************************************************** - * apps/games/NXDoom/textscreen/txt_window_action.h - * - * SPDX-License-Identifer: GPLv2 - * - * Copyright(C) 2005-2014 Simon Howard - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - ****************************************************************************/ - -#ifndef TXT_WINDOW_ACTION_H -#define TXT_WINDOW_ACTION_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "txt_widget.h" -#include "txt_window.h" - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -/** - * @file txt_window_action.h - * - * Window action widget. - */ - -/** - * Window action widget. - * - * A window action is attached to a window and corresponds to a - * keyboard shortcut that is active within that window. When the - * key is pressed, the action is triggered. - * - * When a window action is triggered, the "pressed" signal is emitted. - */ - -typedef struct txt_window_action_s txt_window_action_t; - -struct txt_window_action_s -{ - txt_widget_t widget; - char *label; - int key; -}; - -/* A window. - * - * A window contains widgets, and may also be treated as a table - * (@ref txt_table_t) containing a single column. - * - * Windows can be created using @ref txt_new_window and closed using - * @ref txt_close_window. When a window is closed, it emits the - * "closed" signal. - * - * In addition to the widgets within a window, windows also have - * a "tray" area at their bottom containing window action widgets. - * These widgets allow keyboard shortcuts to trigger common actions. - * Each window has three slots for keyboard shortcuts. By default, - * the left slot contains an action to close the window when the - * escape button is pressed, while the right slot contains an - * action to activate the currently-selected widget. - */ - -typedef struct txt_window_s txt_window_t; /* Forward definition */ - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/** - * Create a new window action. - * - * @param key The keyboard key that triggers this action. - * @param label Label to display for this action in the tray - * at the bottom of the window (UTF-8 format). - * @return Pointer to the new window action widget. - */ - -txt_window_action_t *txt_new_window_action(int key, const char *label); - -/** - * Create a new window action that closes the window when the - * escape key is pressed. The label "Close" is used. - * - * @param window The window to close. - * @return Pointer to the new window action widget. - */ - -txt_window_action_t *txt_new_window_escape_action(txt_window_t *window); - -/** - * Create a new window action that closes the window when the - * escape key is pressed. The label "Abort" is used. - * - * @param window The window to close. - * @return Pointer to the new window action widget. - */ - -txt_window_action_t *txt_new_window_abort_action(txt_window_t *window); - -/** - * Create a new "select" window action. This does not really do - * anything, but reminds the user that "enter" can be pressed to - * activate the currently-selected widget. - * - * @param window The window. - * @return Pointer to the new window action widget. - */ - -txt_window_action_t *txt_new_window_select_action(txt_window_t *window); - -#endif /* TXT_WINDOW_ACTION_H */ diff --git a/games/brickmatch/Kconfig b/games/brickmatch/Kconfig deleted file mode 100644 index 1567a4ebc..000000000 --- a/games/brickmatch/Kconfig +++ /dev/null @@ -1,121 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config GAMES_BRICKMATCH - bool "Brickmatch Game" - default n - ---help--- - Enable Brickmatch games. Brickmatch is like a mix - between Tetris and Crush Candy. The inspiration came - from a Shift game that was available for Android in the - F-Droid store. The original game source code still here: - https://github.com/boombuler/Shift/ but the game only works - for old Android versions (4.x). - NOTE: The source code here is not based on that code from - above github. - -if GAMES_BRICKMATCH - -config GAMES_BRICKMATCH_PROGNAME - string "Program name" - default "brick" - ---help--- - This is the name of the program that will be used when the NSH ELF - program is installed. - -config GAMES_BRICKMATCH_PRIORITY - int "Brickmatch Game task priority" - default 100 - -config GAMES_BRICKMATCH_STACKSIZE - int "Brickmatch Game stack size" - default DEFAULT_TASK_STACKSIZE - -# -# Output Device Selection -# - -choice - prompt "Output Device (LED Matrix, LCD Screen, etc)" - default GAMES_BRICKMATCH_USE_LCD_SCREEN - -config GAMES_BRICKMATCH_USE_LCD_SCREEN - bool "LCD Screen as Output (Also APA102 Matrix as LCD Interface)" - -config GAMES_BRICKMATCH_USE_LED_MATRIX - bool "LED Matrix as Output" -endchoice - -if GAMES_BRICKMATCH_USE_LED_MATRIX - -config GAMES_BRICKMATCH_LED_MATRIX_PATH - string "LED matrix path" - default "/dev/leds0" - ---help--- - Path of the led matrix - -config GAMES_BRICKMATCH_LED_MATRIX_ROWS - int "LED Matrix row count" - default 8 - -config GAMES_BRICKMATCH_LED_MATRIX_COLS - int "LED Matrix column count" - default 8 - -endif #GAMES_BRICKMATCH_LED_MATRIX_PATH - -# -# Input Device Selection -# - -choice - prompt "Input Device (Joystick, Gesture Sensor, etc)" - default GAMES_BRICKMATCH_USE_CONSOLEKEY - -config GAMES_BRICKMATCH_USE_CONSOLEKEY - bool "Serial Console as Input" - depends on !INPUT_DJOYSTICK && !SENSORS_APDS9960 - -config GAMES_BRICKMATCH_USE_DJOYSTICK - bool "Discrete Joystick as Input" - depends on INPUT_DJOYSTICK - -config GAMES_BRICKMATCH_USE_GESTURE - bool "Gesture Sensor APDS-9960 as Input" - depends on SENSORS_APDS9960 - -config GAMES_BRICKMATCH_USE_GPIO - bool "GPIO pins as Input" -endchoice - -if GAMES_BRICKMATCH_USE_GPIO - -config GAMES_BRICKMATCH_UP_KEY_PATH - string "Up key path" - default "/dev/gpio0" - ---help--- - Path of the up key to read - -config GAMES_BRICKMATCH_DOWN_KEY_PATH - string "Down key path" - default "/dev/gpio1" - ---help--- - Path of the down key to read - -config GAMES_BRICKMATCH_LEFT_KEY_PATH - string "Left key path" - default "/dev/gpio2" - ---help--- - Path of the left key to read - -config GAMES_BRICKMATCH_RIGHT_KEY_PATH - string "Right key path" - default "/dev/gpio3" - ---help--- - Path of the right key to read - -endif #GAMES_BRICKMATCH_USE_GPIO - -endif diff --git a/games/brickmatch/Make.defs b/games/brickmatch/Make.defs deleted file mode 100644 index 274ee477d..000000000 --- a/games/brickmatch/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/games/brickmatch/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_GAMES_BRICKMATCH),) -CONFIGURED_APPS += $(APPDIR)/games/brickmatch -endif diff --git a/games/brickmatch/Makefile b/games/brickmatch/Makefile deleted file mode 100644 index 2d228b5fc..000000000 --- a/games/brickmatch/Makefile +++ /dev/null @@ -1,36 +0,0 @@ -############################################################################ -# apps/games/brickmatch/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -# Brickmatch game info - -PROGNAME = $(CONFIG_GAMES_BRICKMATCH_PROGNAME) -PRIORITY = $(CONFIG_GAMES_BRICKMATCH_PRIORITY) -STACKSIZE = $(CONFIG_GAMES_BRICKMATCH_STACKSIZE) -MODULE = $(CONFIG_GAMES_BRICKMATCH) - -# Brickmatch game application - -MAINSRC = bm_main.c - -include $(APPDIR)/Application.mk diff --git a/games/brickmatch/bm_input_console.h b/games/brickmatch/bm_input_console.h deleted file mode 100644 index 1d638f874..000000000 --- a/games/brickmatch/bm_input_console.h +++ /dev/null @@ -1,135 +0,0 @@ -/**************************************************************************** - * apps/games/brickmatch/bm_input_console.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -#include "bm_inputs.h" - -/**************************************************************************** - * Preprocessor Definitions - ****************************************************************************/ - -/* Termios functions to have getch on Linux/NuttX */ - -static struct termios g_old; -static struct termios g_new; - -/* Initialize g_new terminal I/O settings */ - -void init_termios(int echo) -{ - tcgetattr(0, &g_old); /* grab old terminal i/o settings */ - g_new = g_old; /* use old settings as starting */ - g_new.c_lflag &= ~ICANON; /* disable buffered I/O */ - g_new.c_lflag &= ~ECHO; /* disable ECHO bit */ - g_new.c_lflag |= echo ? ECHO : 0; /* set echo mode if requested */ - tcsetattr(0, TCSANOW, &g_new); /* apply terminal I/O settings */ -} - -/* Restore g_old terminal i/o settings */ - -void reset_termios(void) -{ - tcsetattr(0, TCSANOW, &g_old); -} - -/* Read 1 character - echo defines echo mode */ - -char getch_(int echo) -{ - char ch; - - init_termios(echo); - ch = getchar(); - reset_termios(); - - return ch; -} - -/* Read 1 character without echo getch() function definition. */ - -char getch(void) -{ - return getch_(0); -} - -/**************************************************************************** - * dev_input_init - ****************************************************************************/ - -int dev_input_init(FAR struct input_state_s *dev) -{ - init_termios(0); - - return OK; -} - -/**************************************************************************** - * dev_read_input - ****************************************************************************/ - -int dev_read_input(FAR struct input_state_s *dev) -{ - char ch; - - /* Arrows keys return three bytes: 27 91 [65-68] */ - - if ((ch = getch()) == 27) - { - if ((ch = getch()) == 91) - { - ch = getch(); - if (ch == 65) - { - dev->dir = DIR_UP; - } - else if (ch == 66) - { - dev->dir = DIR_DOWN; - } - else if (ch == 67) - { - dev->dir = DIR_RIGHT; - } - else if (ch == 68) - { - dev->dir = DIR_LEFT; - } - } - else - { - dev->dir = DIR_NONE; - } - } - else - { - dev->dir = DIR_NONE; - } - - return OK; -} - diff --git a/games/brickmatch/bm_input_gesture.h b/games/brickmatch/bm_input_gesture.h deleted file mode 100644 index 4ae8ef9f0..000000000 --- a/games/brickmatch/bm_input_gesture.h +++ /dev/null @@ -1,80 +0,0 @@ -/**************************************************************************** - * apps/games/brickmatch/bm_input_gesture.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include - -#include "bm_inputs.h" - -/**************************************************************************** - * Preprocessor Definitions - ****************************************************************************/ - -#define APDS9960_DEVNAME "/dev/gest0" - -/**************************************************************************** - * dev_input_init - ****************************************************************************/ - -int dev_input_init(FAR struct input_state_s *dev) -{ - /* Open the gesture sensor APDS9960 */ - - dev->fd_gest = open(APDS9960_DEVNAME, O_RDONLY | O_NONBLOCK); - if (dev->fd_gest < 0) - { - int errcode = errno; - printf("ERROR: Failed to open %s: %d\n", APDS9960_DEVNAME, errcode); - return -ENODEV; - } - - return OK; -} - -/**************************************************************************** - * dev_read_input - ****************************************************************************/ - -int dev_read_input(FAR struct input_state_s *dev) -{ - int nbytes; - uint8_t gest; - - nbytes = read(dev->fd_gest, &gest, sizeof(gest)); - if (nbytes == sizeof(gest)) - { - dev->dir = gest; - } - else - { - dev->dir = DIR_NONE; - return -EINVAL; - } - - return OK; -} - diff --git a/games/brickmatch/bm_input_gpio.h b/games/brickmatch/bm_input_gpio.h deleted file mode 100644 index 27428d35d..000000000 --- a/games/brickmatch/bm_input_gpio.h +++ /dev/null @@ -1,202 +0,0 @@ -/**************************************************************************** - * apps/games/brickmatch/bm_input_gpio.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "bm_inputs.h" - -/**************************************************************************** - * Preprocessor Definitions - ****************************************************************************/ - -struct gpio_struct_fd_s -{ - int fd_up; /* File descriptor value to read up arrow key */ - int fd_down; /* File descriptor value to read down arrow key */ - int fd_left; /* File descriptor value to read left arrow key */ - int fd_right; /* File descriptor value to read right arrow key */ -}; - -struct gpio_struct_fd_s fd_list; - -/**************************************************************************** - * Name: dev_input_init - * - * Description: - * Initialize input method. - * - * Parameters: - * dev - Input state data - * - * Returned Value: - * Zero (OK) is returned on success. A negated errno value is returned on - * failure. - * - ****************************************************************************/ - -int dev_input_init(FAR struct input_state_s *dev) -{ - /* Open the up key gpio device */ - - fd_list.fd_up = open(CONFIG_GAMES_BRICKMATCH_UP_KEY_PATH, O_RDONLY); - if (fd_list.fd_up < 0) - { - fprintf(stderr, "ERROR: Failed to open %s: %d\n", - CONFIG_GAMES_BRICKMATCH_UP_KEY_PATH, errno); - return -ENODEV; - } - - /* Open the down key gpio device */ - - fd_list.fd_down = open(CONFIG_GAMES_BRICKMATCH_DOWN_KEY_PATH, O_RDONLY); - if (fd_list.fd_down < 0) - { - fprintf(stderr, "ERROR: Failed to open %s: %d\n", - CONFIG_GAMES_BRICKMATCH_DOWN_KEY_PATH, errno); - return -ENODEV; - } - - /* Open the left key gpio device */ - - fd_list.fd_left = open(CONFIG_GAMES_BRICKMATCH_LEFT_KEY_PATH, O_RDONLY); - if (fd_list.fd_down < 0) - { - fprintf(stderr, "ERROR: Failed to open %s: %d\n", - CONFIG_GAMES_BRICKMATCH_LEFT_KEY_PATH, errno); - return -ENODEV; - } - - /* Open the right key gpio device */ - - fd_list.fd_right = open(CONFIG_GAMES_BRICKMATCH_RIGHT_KEY_PATH, O_RDONLY); - if (fd_list.fd_down < 0) - { - fprintf(stderr, "ERROR: Failed to open %s: %d\n", - CONFIG_GAMES_BRICKMATCH_RIGHT_KEY_PATH, errno); - return -ENODEV; - } - - dev->fd_gpio = (int)&fd_list; - - return OK; -} - -/**************************************************************************** - * Name: dev_read_input - * - * Description: - * Read inputs and returns result in input state data. - * - * Parameters: - * dev - Input state data - * - * Returned Value: - * Zero (OK) - * - ****************************************************************************/ - -int dev_read_input(FAR struct input_state_s *dev) -{ - struct gpio_struct_fd_s *fd = (struct gpio_struct_fd_s *)dev->fd_gpio; - int invalue = 0; - int ret; - - ret = ioctl(fd->fd_up, GPIOC_READ, (unsigned long)((uintptr_t)&invalue)); - if (ret < 0) - { - int errcode = errno; - fprintf(stderr, "ERROR: Failed to read value from %s: %d\n", - CONFIG_GAMES_BRICKMATCH_UP_KEY_PATH, errcode); - } - else - { - if (invalue != 0) - { - dev->dir = DIR_UP; - } - } - - ret = ioctl(fd->fd_down, GPIOC_READ, (unsigned long)((uintptr_t)&invalue)); - if (ret < 0) - { - int errcode = errno; - fprintf(stderr, "ERROR: Failed to read value from %s: %d\n", - CONFIG_GAMES_BRICKMATCH_DOWN_KEY_PATH, errcode); - } - else - { - if (invalue != 0) - { - dev->dir = DIR_DOWN; - } - } - - ret = ioctl(fd->fd_left, GPIOC_READ, (unsigned long)((uintptr_t)&invalue)); - if (ret < 0) - { - int errcode = errno; - fprintf(stderr, "ERROR: Failed to read value from %s: %d\n", - CONFIG_GAMES_BRICKMATCH_LEFT_KEY_PATH, errcode); - } - else - { - if (invalue != 0) - { - dev->dir = DIR_LEFT; - } - } - - ret = ioctl(fd->fd_right, GPIOC_READ, - (unsigned long)((uintptr_t)&invalue)); - if (ret < 0) - { - int errcode = errno; - fprintf(stderr, "ERROR: Failed to read value from %s: %d\n", - CONFIG_GAMES_BRICKMATCH_RIGHT_KEY_PATH, errcode); - } - else - { - if (invalue != 0) - { - dev->dir = DIR_RIGHT; - } - } - - return OK; -} - diff --git a/games/brickmatch/bm_input_joystick.h b/games/brickmatch/bm_input_joystick.h deleted file mode 100644 index 890fd3e41..000000000 --- a/games/brickmatch/bm_input_joystick.h +++ /dev/null @@ -1,168 +0,0 @@ -/**************************************************************************** - * apps/games/brickmatch/bm_input_joystick.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include - -#include "bm_inputs.h" - -/**************************************************************************** - * Preprocessor Definitions - ****************************************************************************/ - -#define DJOYSTICK_DEVNAME "/dev/djoy0" -#define DJOYSTICK_SIGNO 32 - -/* The set of supported joystick discretes */ - -static djoy_buttonset_t g_djoysupported; - -/* Last sampled discrete set */ - -static djoy_buttonset_t g_djoylast; - -struct djoy_notify_s notify; - -/**************************************************************************** - * dev_input_init - ****************************************************************************/ - -int dev_input_init(FAR struct input_state_s *dev) -{ - int tmp; - int ret; - - /* Open the djoystick device */ - - dev->fd_joy = open(DJOYSTICK_DEVNAME, O_RDONLY); - if (dev->fd_joy < 0) - { - fprintf(stderr, "ERROR: Failed to open %s: %d\n", - DJOYSTICK_DEVNAME, errno); - return -ENODEV; - } - - /* Get the set of supported discretes */ - - ret = ioctl(dev->fd_joy, DJOYIOC_SUPPORTED, - (unsigned long)((uintptr_t)&tmp)); - if (ret < 0) - { - fprintf(stderr, "ERROR: ioctl(DJOYIOC_SUPPORTED) failed: %d\n", errno); - goto errout_with_fd; - } - - g_djoysupported = (djoy_buttonset_t)tmp; - - /* Register to receive a signal on any change in the joystick discretes. */ - - notify.dn_press = g_djoysupported; - notify.dn_release = g_djoysupported; - - notify.dn_event.sigev_notify = SIGEV_SIGNAL; - notify.dn_event.sigev_signo = DJOYSTICK_SIGNO; - - ret = ioctl(dev->fd_joy, DJOYIOC_REGISTER, - (unsigned long)((uintptr_t)¬ify)); - if (ret < 0) - { - fprintf(stderr, "ERROR: ioctl(DJOYIOC_REGISTER) failed: %d\n", errno); - goto errout_with_fd; - } - - /* Ignore the default signal action */ - - signal(DJOYSTICK_SIGNO, SIG_IGN); - - return OK; - -errout_with_fd: - close(dev->fd_joy); - return -ENODEV; -} - -/**************************************************************************** - * dev_read_input - ****************************************************************************/ - -int dev_read_input(FAR struct input_state_s *dev) -{ - struct siginfo value; - sigset_t set; - djoy_buttonset_t newset; - ssize_t nread; - int ret; - - /* Wait for a signal */ - - sigemptyset(&set); - sigaddset(&set, DJOYSTICK_SIGNO); - ret = sigwaitinfo(&set, &value); - if (ret < 0) - { - fprintf(stderr, "ERROR: sigwaitinfo() failed: %d\n", errno); - } - - newset = (djoy_buttonset_t)value.si_value.sival_int; - - g_djoylast = newset; - - /* Read the signal set and compare */ - - nread = read(dev->fd_joy, &newset, sizeof(djoy_buttonset_t)); - if (nread < 0) - { - fprintf(stderr, "ERROR: read() failed: %d\n", errno); - } - else if (nread != sizeof(djoy_buttonset_t)) - { - fprintf(stderr, "ERROR: read() unexpected size: %ld vs %d\n", - (long)nread, sizeof(djoy_buttonset_t)); - } - - g_djoylast = newset; - - switch (newset) - { - case DJOY_UP_BIT: - dev->dir = DIR_UP; - break; - case DJOY_DOWN_BIT: - dev->dir = DIR_DOWN; - break; - case DJOY_LEFT_BIT: - dev->dir = DIR_LEFT; - break; - case DJOY_RIGHT_BIT: - dev->dir = DIR_RIGHT; - break; - default: - dev->dir = DIR_NONE; - } - - return OK; -} diff --git a/games/brickmatch/bm_inputs.h b/games/brickmatch/bm_inputs.h deleted file mode 100644 index 9497b3135..000000000 --- a/games/brickmatch/bm_inputs.h +++ /dev/null @@ -1,70 +0,0 @@ -/**************************************************************************** - * apps/games/brickmatch/bm_inputs.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -/**************************************************************************** - * Preprocessor Definitions - ****************************************************************************/ - -#ifndef DIR_NONE -# define DIR_NONE 0 -#endif - -#ifndef DIR_LEFT -# define DIR_LEFT 1 -#endif - -#ifndef DIR_RIGHT -# define DIR_RIGHT 2 -#endif - -#ifndef DIR_UP -# define DIR_UP 3 -#endif - -#ifndef DIR_DOWN -# define DIR_DOWN 4 -#endif - -struct input_state_s -{ -#ifdef CONFIG_GAMES_BRICKMATCH_USE_CONSOLEKEY - int fd_con; -#endif -#ifdef CONFIG_GAMES_BRICKMATCH_USE_DJOYSTICK - int fd_joy; -#endif -#ifdef CONFIG_GAMES_BRICKMATCH_USE_GESTURE - int fd_gest; -#endif -#ifdef CONFIG_GAMES_BRICKMATCH_USE_GPIO - int fd_gpio; -#endif - - int dir; /* Direction to move the blocks */ -}; - diff --git a/games/brickmatch/bm_main.c b/games/brickmatch/bm_main.c deleted file mode 100644 index b9e63ca5d..000000000 --- a/games/brickmatch/bm_main.c +++ /dev/null @@ -1,1172 +0,0 @@ -/**************************************************************************** - * apps/games/brickmatch/bm_main.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#ifdef CONFIG_GAMES_BRICKMATCH_USE_LED_MATRIX -#include -#endif - -#ifdef CONFIG_GAMES_BRICKMATCH_USE_CONSOLEKEY -#include "bm_input_console.h" -#endif - -#ifdef CONFIG_GAMES_BRICKMATCH_USE_DJOYSTICK -#include "bm_input_joystick.h" -#endif - -#ifdef CONFIG_GAMES_BRICKMATCH_USE_GESTURE -#include "bm_input_gesture.h" -#endif - -#ifdef CONFIG_GAMES_BRICKMATCH_USE_GPIO -#include "bm_input_gpio.h" -#endif - -/**************************************************************************** - * Preprocessor Definitions - ****************************************************************************/ - -#ifndef CONFIG_GAMES_BRICKMATCH_USE_LED_MATRIX -#define BOARDX_SIZE 6 -#define BOARDY_SIZE 6 -#else -#define BOARDX_SIZE CONFIG_GAMES_BRICKMATCH_LED_MATRIX_ROWS -#define BOARDY_SIZE CONFIG_GAMES_BRICKMATCH_LED_MATRIX_COLS -#define N_LEDS BOARDX_SIZE * BOARDY_SIZE -#endif - -#define ROW BOARDX_SIZE + 2 -#define COL BOARDY_SIZE + 2 - -/* Difficult mode: 4, 5, 6 */ - -#define GAMEMODE 6 - -#define NCOLORS GAMEMODE - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -struct screen_state_s -{ - int fd_fb; - struct fb_videoinfo_s vinfo; - struct fb_planeinfo_s pinfo; -#ifdef CONFIG_FB_OVERLAY - struct fb_overlayinfo_s oinfo; -#endif - FAR void *fbmem; -}; - -struct game_screen_s -{ - int xres; /* X display resolution */ - int yres; /* Y display resolution */ - int xoff; /* X offset to start drawing */ - int yoff; /* Y offset to start drawing */ - int ncolors; /* Supported number of colors */ - int blklen; /* Size of side of the blocks */ - int steps; /* Steps to slide a block for a now position */ - int stepinc; /* Step increment during the sliding */ - int dir; /* Direction to move the blocks */ -}; - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -#ifndef CONFIG_GAMES_BRICKMATCH_USE_LED_MATRIX -static const char g_default_fbdev[] = "/dev/fb0"; -#else -static const char g_default_fbdev[] = - CONFIG_GAMES_BRICKMATCH_LED_MATRIX_PATH; -#endif - -/* The edge of the board is invisible to user */ - -int board[ROW][COL] = -{ - 0 -}; - -int prev_board[ROW][COL] = -{ - 0 -}; - -/* Colors used in the game plus Black */ - -static const uint16_t pallete[NCOLORS + 1] = -{ - RGB16_BLACK, - RGB16_BLUE, - RGB16_GREEN, - RGB16_RED, - RGB16_CYAN, - RGB16_WHITE, - RGB16_GOLD, -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -#ifndef CONFIG_GAMES_BRICKMATCH_USE_LED_MATRIX -/**************************************************************************** - * Name: draw_rect - * - * Description: - * Draw a rectangular. - * - * Parameters: - * state - Reference to the game screen state structure - * area - Reference to the valid area structure - * color - Color of the rectangular - * - * Returned Value: - * None. - * - ****************************************************************************/ - -static void draw_rect(FAR struct screen_state_s *state, - FAR struct fb_area_s *area, int color) -{ - FAR uint16_t *dest; - FAR uint8_t *row; - int x; - int y; - - row = (FAR uint8_t *)state->fbmem + state->pinfo.stride * area->y; - for (y = 0; y < area->h; y++) - { - dest = ((FAR uint16_t *)row) + area->x; - for (x = 0; x < area->w; x++) - { - *dest++ = pallete[color]; - } - - row += state->pinfo.stride; - } -} - -/**************************************************************************** - * Name: update_screen - * - * Description: - * Refresh screen. - * - * Parameters: - * state - Reference to the game screen state structure - * area - Reference to the valid area structure - * - * Returned Value: - * None. - * - ****************************************************************************/ - -void update_screen(FAR struct screen_state_s *state, - FAR struct fb_area_s *area) -{ - int ret; - -#ifdef CONFIG_FB_UPDATE - ret = ioctl(state->fd_fb, FBIO_UPDATE, - (unsigned long)((uintptr_t)area)); - if (ret < 0) - { - int errcode = errno; - fprintf(stderr, "ERROR: ioctl(FBIO_UPDATE) failed: %d\n", - errcode); - } -#endif -} - -/**************************************************************************** - * Name: draw_board - * - * Description: - * Draw the user board without the edges. - * - * Parameters: - * state - Reference to the game screen state structure - * area - Reference to the valid area structure - * screen - Reference to the information structure of game screen - * - * Returned Value: - * None. - * - ****************************************************************************/ - -void draw_board(FAR struct screen_state_s *state, - FAR struct fb_area_s *area, - FAR struct game_screen_s *screen) -{ - int row; - int col; - int x; - int y; - int i; - int color; - - /* Clear the framebuffer, but don't update yet */ - - area->x = 0; - area->y = 0; - area->w = screen->xres; - area->h = screen->yres; - - draw_rect(state, area, 0); - - for (i = screen->steps; i > 0; i--) - { - for (row = 1; row <= BOARDX_SIZE; row++) - { - for (col = 1; col <= BOARDY_SIZE; col++) - { - color = board[row][col]; - - x = (col - 1) * screen->blklen + screen->xoff; - y = (row - 1) * screen->blklen + screen->yoff; - - /* Get original width and height of blocks */ - - area->w = screen->blklen; - area->h = screen->blklen; - - /* Only do the sliding for blocks that changed */ - - if (prev_board[row][col] != board[row][col]) - { - if (screen->dir == DIR_NONE) - { - area->x = x; - area->y = y; - } - - if (screen->dir == DIR_UP) - { - area->x = x; - area->y = y + ((i - 1) * screen->stepinc); - } - - if (screen->dir == DIR_DOWN) - { - area->x = x; - area->y = y - ((i - 1) * screen->stepinc); - } - - if (screen->dir == DIR_LEFT) - { - area->x = x + ((i - 1) * screen->stepinc); - area->y = y; - } - - if (screen->dir == DIR_RIGHT) - { - area->x = x - ((i - 1) * screen->stepinc); - area->y = y; - } - } - else - { - area->x = x; - area->y = y; - } - - /* Drawn only part of block if above margin */ - - if (area->x > (screen->xres - 2 * screen->xoff)) - { - area->x = (screen->xres - 2 * screen->xoff) + 1; - area->w = 1; - } - - if (area->x < screen->xoff) - { - area->x = screen->xoff; - } - - if (area->y > (screen->yres - 2 * screen->yoff)) - { - area->y = (screen->yres - 2 * screen->yoff) + 1; - area->h = 1; - } - - if (area->y < screen->yoff) - { - area->y = screen->yoff; - } - - draw_rect(state, area, color); - } - } - - area->x = 0; - area->y = 0; - area->w = screen->xres; - area->h = screen->yres; - - update_screen(state, area); - usleep(100000); - } -} -#else - -/**************************************************************************** - * Name: dim_color - * - * Description: - * Dim led color to handle brightness. - * - * Parameters: - * val - RGB24 value of the led - * dim - Percentage of brightness - * - * Returned Value: - * Dimmed RGB24 value. - * - ****************************************************************************/ - -uint32_t dim_color(uint32_t val, float dim) -{ - uint16_t r = RGB24RED(val); - uint16_t g = RGB24GREEN(val); - uint16_t b = RGB24BLUE(val); - - float sat = dim; - - r *= sat; - g *= sat; - b *= sat; - - return RGBTO24(r, g, b); -} - -/**************************************************************************** - * Name: draw_board - * - * Description: - * Draw the user board without the edges. - * - * Parameters: - * state - Reference to the game screen state structure - * area - Reference to the valid area structure - * screen - Reference to the information structure of game screen - * - * Returned Value: - * None. - * - ****************************************************************************/ - -void draw_board(FAR struct screen_state_s *state, - FAR struct fb_area_s *area, - FAR struct game_screen_s *screen) -{ - int result; - uint32_t *bp = state->fbmem; - int x; - int y; - int rgb_val; - int tmp; - - for (x = 1; x <= BOARDX_SIZE; x++) - { - for (y = 1; y <= BOARDY_SIZE; y++) - { - rgb_val = RGB16TO24(pallete[board[x][y]]); - tmp = dim_color(rgb_val, 0.15); - *bp++ = ws2812_gamma_correct(tmp); - } - } - - lseek(state->fd_fb, 0, SEEK_SET); - - result = write(state->fd_fb, state->fbmem, 4 * N_LEDS); - if (result != 4 * N_LEDS) - { - fprintf(stderr, - "ws2812_main: write failed: %d %d\n", - result, - errno); - } -} -#endif /* CONFIG_GAMES_BRICKMATCH_USE_LED_MATRIX */ - -/**************************************************************************** - * Name: print_board - * - * Description: - * Draw the board including the user non-visible border for debugging. - * - * Parameters: - * None - * - * Returned Value: - * None. - * - ****************************************************************************/ - -#ifdef DEBUG_BRICKMATCH_GAME -void print_board(void) -{ - int row; - int col; - int tmp; - - for (row = 0; row < ROW; row++) - { - for (tmp = 0; tmp < COL; tmp++) - { - printf("+---"); - } - - printf("+\n"); - for (col = 0; col < COL; col++) - { - if (row == 0 || col == 0 || row == ROW - 1 || col == COL - 1) - { - printf("|>%c<", board[row][col] + 48); - } - else - { - printf("| %c ", board[row][col] + 48); - } - } - - printf("|\n"); - } - - for (tmp = 0; tmp < COL; tmp++) - { - printf("+---"); - } - - printf("+\n\n\n"); -} -#endif - -/**************************************************************************** - * Name: move_board - * - * Description: - * Move the blocks (represented by numbers) to 'dir' direction (L,R,U,D). - * - * Parameters: - * dir - Direction to move - * - * Returned Value: - * None. - * - ****************************************************************************/ - -void move_board(int dir) -{ - int row = 0; - int row_ini = 0; - int col = 0; - int col_ini = 0; - int row_dir = 0; - int row_pos = 0; - int col_dir = 0; - int col_pos = 0; - int row_lim = 0; - int col_lim = 0; - - if (dir == DIR_UP) - { - row_ini = 0; - row_dir = 1; - row_pos = 1; - row_lim = BOARDY_SIZE + 1; - - col_ini = 0; - col_dir = 1; - col_pos = 0; - col_lim = BOARDX_SIZE + 1; - } - - if (dir == DIR_DOWN) - { - row_ini = BOARDY_SIZE + 1; - row_dir = -1; - row_pos = -1; - row_lim = 0; - - col_ini = 0; - col_dir = 1; - col_pos = 0; - col_lim = BOARDX_SIZE + 1; - } - - if (dir == DIR_RIGHT) - { - row_ini = 0; - row_dir = 1; - row_pos = 0; - row_lim = BOARDY_SIZE + 1; - - col_ini = BOARDX_SIZE + 1; - col_dir = -1; - col_pos = -1; - col_lim = 0; - } - - if (dir == DIR_LEFT) - { - row_ini = 0; - row_dir = 1; - row_pos = 0; - row_lim = BOARDY_SIZE + 1; - - col_ini = 0; - col_dir = 1; - col_pos = 1; - col_lim = BOARDX_SIZE + 1; - } - - for (row = row_ini; row != row_lim; row += row_dir) - { - for (col = col_ini; col != col_lim; col += col_dir) - { - /* Never move item if we are in the cache border */ - - if ((row != 0 && col != 0) && - (row != 0 && col != BOARDX_SIZE + 1) && - (row != BOARDY_SIZE + 1 && col != 0) && - (row != BOARDY_SIZE + 1 && col != BOARDX_SIZE + 1)) - { - if (board[row][col] == 0) - { - board[row][col] = board[row + row_pos][col + col_pos]; - board[row + row_pos][col + col_pos] = 0; - } - } - } - } -} - -/**************************************************************************** - * Name: init_board - * - * Description: - * Initialize board to start the game properly - * - * Parameters: - * None - * - * Returned Value: - * None. - * - ****************************************************************************/ - -void init_board(void) -{ - int i; - int j; - - for (i = 0; i < ROW; i++) - { - for (j = 0; j < COL; j++) - { - if (i == 0 || i == ROW - 1 || j == 0 || j == COL - 1) - { - board[i][j] = 1; - prev_board[i][j] = 1; - } - else - { - board[i][j] = 0; - prev_board[i][j] = 0; - } - } - } -} - -/**************************************************************************** - * Name: fill_edge - * - * Description: - * Fill the invisible border with "colored" blocks - * - * Parameters: - * None - * - * Returned Value: - * None. - * - ****************************************************************************/ - -void fill_edge(void) -{ - int i; - - for (i = 0; i <= BOARDX_SIZE + 1; i++) - { - board[0][i] = (random() % GAMEMODE) + 1; - board[BOARDY_SIZE + 1][i] = (random() % GAMEMODE) + 1; - } - - for (i = 0; i <= BOARDY_SIZE + 1; i++) - { - board[i][0] = (random() % GAMEMODE) + 1; - board[i][BOARDY_SIZE + 1] = (random() % GAMEMODE) + 1; - } -} - -/**************************************************************************** - * Name: fill_border - * - * Description: - * Fill the visible border with "colored" blocks - * - * Parameters: - * None - * - * Returned Value: - * None. - * - ****************************************************************************/ - -void fill_border(void) -{ - int i; - - for (i = 1; i < BOARDX_SIZE + 1; i++) - { - board[1][i] = (random() % GAMEMODE) + 1; - board[BOARDY_SIZE][i] = (random() % GAMEMODE) + 1; - } - - for (i = 1; i < BOARDY_SIZE + 1; i++) - { - board[i][1] = (random() % GAMEMODE) + 1; - board[i][BOARDY_SIZE] = (random() % GAMEMODE) + 1; - } -} - -/**************************************************************************** - * Name: search_board_squares - * - * Description: - * Search for squares or triples of same colors. - * - * Parameters: - * None - * - * Returned Value: - * True(1) if there are squares or triples, False(0) if not. - * - ****************************************************************************/ - -int search_board_squares(void) -{ - int row; - int col; - int found = 0; - - for (row = 1; row < BOARDY_SIZE; row++) - { - for (col = 1; col < BOARDX_SIZE; col++) - { - if (board[row][col] != 0) - { - if (fabs(board[row][col]) == fabs(board[row][col + 1])) - { - /* Square */ - - if (fabs(board[row][col]) == fabs(board[row + 1][col]) && - fabs(board[row][col + 1]) == - fabs(board[row + 1][col + 1])) - { - found = 1; - board[row][col] = board[row][col] > 0 ? - -board[row][col] : board[row][col]; - board[row][col + 1] = board[row][col + 1] > 0 ? - -board[row][col + 1] : - board[row][col + 1]; - board[row + 1][col] = board[row + 1][col] > 0 ? - -board[row + 1][col] : - board[row + 1][col]; - board[row + 1][col + 1] = board[row + 1][col + 1] > 0 ? - -board[row + 1][col + 1] : - board[row + 1][col + 1]; - } - - /* |- */ - - if (fabs(board[row][col]) == fabs(board[row + 1][col])) - { - found = 1; - board[row][col] = board[row][col] > 0 ? - -board[row][col] : - board[row][col]; - board[row][col + 1] = board[row][col + 1] > 0 ? - -board[row][col + 1] : - board[row][col + 1]; - board[row + 1][col] = board[row + 1][col] > 0 ? - -board[row + 1][col] : - board[row + 1][col]; - } - - /* -| */ - - if (fabs(board[row][col + 1]) == - fabs(board[row + 1][col + 1])) - { - found = 1; - board[row][col] = board[row][col] > 0 ? - -board[row][col] : board[row][col]; - board[row][col + 1] = board[row][col + 1] > 0 ? - -board[row][col + 1] : - board[row][col + 1]; - board[row + 1][col + 1] = board[row + 1][col + 1] > 0 ? - -board[row + 1][col + 1] : - board[row + 1][col + 1]; - } - } - - if (fabs(board[row][col]) == fabs(board[row + 1][col])) - { - /* |_ */ - - if (fabs(board[row + 1][col]) == - fabs(board[row + 1][col + 1])) - { - found = 1; - board[row][col] = board[row][col] > 0 ? - -board[row][col] : board[row][col]; - board[row + 1][col] = board[row + 1][col] > 0 ? - -board[row + 1][col] : - board[row + 1][col]; - board[row + 1][col + 1] = board[row + 1][col + 1] > 0 ? - -board[row + 1][col + 1] : - board[row + 1][col + 1]; - } - } - } - - if (board[row + 1][col] != 0) - { - /* _| */ - - if (fabs(board[row + 1][col]) == fabs(board[row + 1][col + 1])) - { - if (fabs(board[row + 1][col + 1]) == - fabs(board[row][col + 1])) - { - found = 1; - board[row][col + 1] = board[row][col + 1] > 0 ? - -board[row][col + 1] : - board[row][col + 1]; - board[row + 1][col] = board[row + 1][col] > 0 ? - -board[row + 1][col] : - board[row + 1][col]; - board[row + 1][col + 1] = board[row + 1][col + 1] > 0 ? - -board[row + 1][col + 1] : - board[row + 1][col + 1]; - } - } - } - } - } - - return found; -} - -/**************************************************************************** - * Name: search_board_lines - * - * Description: - * Search for vertical/horizontal lines of same colours. - * - * Parameters: - * None - * - * Returned Value: - * True(1) if there are same colours, False(0) if not. - * - ****************************************************************************/ - -int search_board_lines(void) -{ - int row; - int col; - int h = 0; - int hpos = 0; - int hfound = 0; - int v = 0; - int vpos = 0; - int vfound = 0; - int found = 0; - int prev_sym = 0; - - /* Search horizontal lines */ - - for (row = 1; row < BOARDY_SIZE + 1; row++) - { - prev_sym = board[row][1]; - - for (col = 1; col < BOARDX_SIZE; col++) - { - if (board[row][col] != 0) - { - if (fabs(board[row][col]) == fabs(board[row][col + 1])) - { - if (!hfound) - { - hpos = col; - hfound = 1; - prev_sym = board[row][col]; - } - - if (fabs(board[row][col]) == fabs(prev_sym)) - { - h++; - } - } - else if (h < 2) - { - h = 0; - hpos = 1; - hfound = 0; - } - } - } - - if (h >= 2) - { - for (int i = hpos; i <= hpos + h; i++) - { - board[row][i] = board[row][i] > 0 ? - -board[row][i] : board[row][i]; - found = 1; - } - } - - h = 0; - hpos = 1; - hfound = 0; - } - - /* Search vertical lines */ - - for (col = 1; col < BOARDX_SIZE + 1; col++) - { - prev_sym = board[1][col]; - - for (row = 1; row < BOARDY_SIZE; row++) - { - if (board[row][col] != 0) - { - if (fabs(board[row][col]) == fabs(board[row + 1][col])) - { - if (!vfound) - { - vpos = row; - vfound = 1; - prev_sym = board[row][col]; - } - - if (fabs(board[row][col]) == fabs(prev_sym)) - { - v++; - } - } - else if (v < 2) - { - v = 0; - vpos = 1; - vfound = 0; - } - } - } - - if (v >= 2) - { - for (int i = vpos; i <= vpos + v; i++) - { - board[i][col] = board[i][col] > 0 ? - -board[i][col] : board[i][col]; - found = 1; - } - } - - v = 0; - vpos = 1; - vfound = 0; - } - - return found; -} - -/**************************************************************************** - * Name: check_board - * - * Description: - * Verify if there are match lines/squares and remove them - * - * Parameters: - * None - * - * Returned Value: - * True(1) if there is a match, False(0) if not. - * - ****************************************************************************/ - -int check_board(void) -{ - int found = 0; - int row; - int col; - - found = search_board_lines(); - found |= search_board_squares(); - - /* Remove all negative values */ - - for (row = 0; row < ROW; row++) - { - for (col = 0; col < COL; col++) - { - if (board[row][col] < 0) - { - board[row][col] = 0; - } - } - } - - return found; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * brick_main - ****************************************************************************/ - -int main(int argc, FAR char *argv[]) -{ - FAR const char *fbdev = g_default_fbdev; - struct game_screen_s screen; - struct input_state_s input; - struct screen_state_s state; - struct fb_area_s area; - int ret; - - init_board(); - - /* Open the framebuffer driver */ - - state.fd_fb = open(fbdev, O_RDWR); - if (state.fd_fb < 0) - { - int errcode = errno; - fprintf(stderr, "ERROR: Failed to open %s: %d\n", fbdev, errcode); - return EXIT_FAILURE; - } - -#ifndef CONFIG_GAMES_BRICKMATCH_USE_LED_MATRIX - /* Get the characteristics of the framebuffer */ - - ret = ioctl(state.fd_fb, FBIOGET_VIDEOINFO, - (unsigned long)((uintptr_t)&state.vinfo)); - if (ret < 0) - { - int errcode = errno; - fprintf(stderr, "ERROR: ioctl(FBIOGET_VIDEOINFO) failed: %d\n", - errcode); - close(state.fd_fb); - return EXIT_FAILURE; - } - - printf("VideoInfo:\n"); - printf(" fmt: %u\n", state.vinfo.fmt); - printf(" xres: %u\n", state.vinfo.xres); - printf(" yres: %u\n", state.vinfo.yres); - printf(" nplanes: %u\n", state.vinfo.nplanes); - - /* Setup the screen information */ - - screen.xres = state.vinfo.xres > state.vinfo.yres ? - state.vinfo.yres : state.vinfo.xres; - screen.yres = state.vinfo.yres > state.vinfo.xres ? - state.vinfo.xres : state.vinfo.yres; - screen.xoff = (screen.xres % NCOLORS) / 2; - screen.yoff = (screen.yres % NCOLORS) / 2; - screen.steps = 2; - screen.stepinc = 1; - screen.blklen = (screen.xres / NCOLORS); - screen.ncolors = NCOLORS; - - /* Get the display planeinfo */ - - ret = ioctl(state.fd_fb, FBIOGET_PLANEINFO, - (unsigned long)((uintptr_t)&state.pinfo)); - if (ret < 0) - { - int errcode = errno; - fprintf(stderr, "ERROR: ioctl(FBIOGET_PLANEINFO) failed: %d\n", - errcode); - close(state.fd_fb); - return EXIT_FAILURE; - } - - printf("PlaneInfo (plane 0):\n"); - printf(" fbmem: %p\n", state.pinfo.fbmem); - printf(" fblen: %lu\n", (unsigned long)state.pinfo.fblen); - printf(" stride: %u\n", state.pinfo.stride); - printf(" display: %u\n", state.pinfo.display); - printf(" bpp: %u\n", state.pinfo.bpp); - - state.fbmem = mmap(NULL, state.pinfo.fblen, PROT_READ | PROT_WRITE, - MAP_SHARED | MAP_FILE, state.fd_fb, 0); - if (state.fbmem == MAP_FAILED) - { - int errcode = errno; - fprintf(stderr, "ERROR: ioctl(FBIOGET_PLANEINFO) failed: %d\n", - errcode); - close(state.fd_fb); - return EXIT_FAILURE; - } - - printf("Mapped FB: %p\n", state.fbmem); -#else - state.fbmem = calloc(4, N_LEDS); - - if (state.fbmem == NULL) - { - fprintf(stderr, "ws2812_main: buffer allocation failed: %d\n", errno); - return ERROR; - } -#endif /* CONFIG_GAMES_BRICKMATCH_USE_LED_MATRIX */ - - /* Fill the edge with random values */ - - fill_edge(); - fill_border(); - - /* Draw the empty board to user */ - - draw_board(&state, &area, &screen); - - dev_input_init(&input); - - input.dir = DIR_NONE; - - while (1) - { - while (input.dir == DIR_NONE) - { - ret = dev_read_input(&input); - } - - screen.dir = input.dir; - -#ifdef DEBUG_BRICKMATCH_GAME - printf("Before moving:\n"); - print_board(); - usleep(2000000); -#endif - - /* Save a copy of the board before moving to new position */ - - memcpy(prev_board, board, (sizeof(int) * ROW * COL)); - - move_board(screen.dir); - - draw_board(&state, &area, &screen); - -#ifdef DEBUG_BRICKMATCH_GAME - printf("After moving:\n"); - print_board(); - usleep(1000000); -#endif - - /* Save a copy of the board after moving the pieces */ - - memcpy(prev_board, board, (sizeof(int) * ROW * COL)); - - screen.dir = DIR_NONE; - input.dir = DIR_NONE; - - /* If we found bricks with same colors */ - - if (check_board() == 1) - { - int i; - - /* Lets do a blinking effect */ - - for (i = 0; i < 3; i++) - { - /* Draw the board with the pieces */ - - memcpy(board, prev_board, (sizeof(int) * ROW * COL)); - - draw_board(&state, &area, &screen); - usleep(100000); - - /* Draw the board without the pieces */ - - check_board(); - draw_board(&state, &area, &screen); - usleep(100000); - } - - usleep(500000); - } - -#ifdef DEBUG_BRICKMATCH_GAME - printf("After checking:\n"); - print_board(); - usleep(1000000); -#endif - - usleep(1000); - - /* Add random pieces in the not visible border */ - - fill_edge(); - } - - return 0; -} diff --git a/games/cgol/CMakeLists.txt b/games/cgol/CMakeLists.txt deleted file mode 100644 index b496011a4..000000000 --- a/games/cgol/CMakeLists.txt +++ /dev/null @@ -1,37 +0,0 @@ -# ############################################################################## -# apps/games/cgol/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -# CGOL game info - -if(CONFIG_GAMES_CGOL) - nuttx_add_application( - NAME - ${CONFIG_GAMES_CGOL_PROGNAME} - PRIORITY - ${CONFIG_GAMES_CGOL_PRIORITY} - STACKSIZE - ${CONFIG_GAMES_CGOL_STACKSIZE} - MODULE - ${CONFIG_GAMES_CGOL} - SRCS - cgol_main.c) -endif() diff --git a/games/cgol/Kconfig b/games/cgol/Kconfig deleted file mode 100644 index d07a71251..000000000 --- a/games/cgol/Kconfig +++ /dev/null @@ -1,80 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config GAMES_CGOL - bool "Conway's Game of Life" - depends on VIDEO_FB - default n - ---help--- - Enable Conway's Game of Life. - -if GAMES_CGOL - -config GAMES_CGOL_PROGNAME - string "Program name" - default "cgol" - ---help--- - This is the name of the program that will be used when the NSH ELF - program is installed. - -config GAMES_CGOL_PRIORITY - int "CGOL task priority" - default 100 - -config GAMES_CGOL_STACKSIZE - int "CGOL stack size" - default DEFAULT_TASK_STACKSIZE - -config GAMES_CGOL_FBDEV - string "CGOL frame buffer device path" - default "/dev/fb0" - ---help--- - The frame buffer device path that will be used by default for rendering. - Device path can still be selected from first command line argument. - -config GAMES_CGOL_DBLBUF - bool "CGOL double buffered" - default n - ---help--- - If enabled, CGOL will allocate enough RAM for a 'second frame buffer'. - Rendering will be done to this buffer and copied to the real frame - buffer once complete. This is necessary for some devices, but requires - a lot more memory. - -config GAMES_CGOL_MAPWIDTH - int "Map width" - range 1 500000 - default 256 - ---help--- - This is the width of the game map. It must be greater than or equal to - the width of the frame buffer. It must also be a multiple of the target - device's `sizeof(unsigned int) * 8`. - -config GAMES_CGOL_MAPHEIGHT - int "Map height" - range 1 500000 - default 256 - ---help--- - This is the height of the game map. It must be greater than or equal to - the height of the frame buffer. - -config GAMES_CGOL_FRAMEDELAY - int "Microseconds between frames" - range 0 10000000 - default 0 - ---help--- - This adds a delay between frames in microseconds. If the render is too - fast for you to "enjoy", then you can slow it down with this. - -config GAMES_CGOL_DENSITY - int "Cell density" - range 1 10000 - default 6 - ---help--- - The initial cell density to populate the map with. The map will be - randomly initialized with `TOTAL_CELLS * (1 / density)` cells, not - accounting for overlap. - -endif diff --git a/games/cgol/Make.defs b/games/cgol/Make.defs deleted file mode 100644 index a41a0c995..000000000 --- a/games/cgol/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/games/cgol/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_GAMES_CGOL),) -CONFIGURED_APPS += $(APPDIR)/games/cgol -endif diff --git a/games/cgol/Makefile b/games/cgol/Makefile deleted file mode 100644 index 5659a2908..000000000 --- a/games/cgol/Makefile +++ /dev/null @@ -1,36 +0,0 @@ -############################################################################ -# apps/games/cgol/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -# CGOL game info - -PROGNAME = $(CONFIG_GAMES_CGOL_PROGNAME) -PRIORITY = $(CONFIG_GAMES_CGOL_PRIORITY) -STACKSIZE = $(CONFIG_GAMES_CGOL_STACKSIZE) -MODULE = $(CONFIG_GAMES_CGOL) - -# CGOL application - -MAINSRC = cgol_main.c - -include $(APPDIR)/Application.mk diff --git a/games/cgol/cgol_main.c b/games/cgol/cgol_main.c deleted file mode 100644 index 88e26d2f7..000000000 --- a/games/cgol/cgol_main.c +++ /dev/null @@ -1,1057 +0,0 @@ -/**************************************************************************** - * apps/games/cgol/cgol_main.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Author's note: - * - * There are several approaches that can be taken to make a CGOL - * implementation efficient for a resource-constrained device, such as the - * ones that Nuttx (impressively) can run on. - * - * I can make each of the cells a single bit, 1 for alive and 0 for dead, and - * pack a large game state into a single array of bit fields. I can take - * advantage of the game's "sparse" nature and only store the living cells as - * x, y coordinates. - * - * In terms of memory usage: - * A decently sized map of 100 x 100 cells with a single bit per cell would - * require a little over 1KB of memory. On the other hand, each living cell - * could be represented with 2 bytes (x, y), which allows 625 living cells in - * the same space (much less). - * - * As it turns out, people smarter than me have determined in the "still-Life - * Conjecture" that a still life cannot have a density greater than 1/2. [1] - * Although this doesn't tell me anything about the maximum living cells at - * any moment in time, it would be fair to say that on _average_ a 100 x 100 - * map is upper-bounded by some 5000 living cells. That is a lot more than - * the 625 which can be implemented using 1250 bytes of memory. - * - * On the other hand, we also want to balance CPU usage. Nobody should be - * using this alongside important tasks, as it is just a curiosity/demo. - * However, lower CPU usage allows us to render frames more quickly and get - * a nicer video output. - * - * This implementation will restrict the size of the CGOL world to be less - * than or equal to the size of the frame buffer (i.e. minimum resolution of - * one pixel per cell). With this cap on the world size, it will likely - * always be more memory efficient to use full world map with 1 bit per cell - * than to represent living cells as (x, y) pairs. - * - * The implementation in [2] gives a fast method for computing CGOL with - * bit-fields in `uint64_t` types. However, that won't work as efficiently - * on machines with smaller word sizes. I want to use a bit-field that works - * well on all machines. - * - * In order to keep calculations of next states fast, this program enforces - * the map width to be a multiple of the machine word size. - * - * [1] Elkies, Noam D, โ€œThe still-Life density problem and its - * generalizations,โ€ arXiv.org, 1999. https://arxiv.org/abs/math/9905194 - * (accessed Nov. 10, 2025). - * - * [2] https://binary-banter.github.io/game-of-life/ - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -/**************************************************************************** - * Preprocessor Definitions - ****************************************************************************/ - -/* Foreground and background colours for all pixel sizes */ - -#define ARGB_FULL_ALPHA (0xff << 24) - -#define BG32 (RGB24_BLACK | ARGB_FULL_ALPHA) -#define FG32 (RGB24_WHITE | ARGB_FULL_ALPHA) - -#define BG24 RGB24_BLACK -#define FG24 RGB24_WHITE - -#define BG16 RGB16_BLACK -#define FG16 RGB16_WHITE - -#define BG8 RGB8_BLACK -#define FG8 RGB8_WHITE - -/* Total cells in the map */ - -#define TOTAL_CELLS (CONFIG_GAMES_CGOL_MAPWIDTH * CONFIG_GAMES_CGOL_MAPHEIGHT) - -/* The number of bits in one "natural" word on our machine */ - -#ifdef UINT_WIDTH -#define WORD_BITS UINT_WIDTH -#else -#define WORD_BITS ((uint8_t)(sizeof(unsigned int) * 8)) -#endif - -/* The number of words required to represent the map. This will always be a - * multiple of the word size since that is a restriction we put on MAPWIDTH. - */ - -#define WORD_COUNT (TOTAL_CELLS / WORD_BITS) - -/* Map width in words */ - -#define MAPWIDTH_WORDS (CONFIG_GAMES_CGOL_MAPWIDTH / WORD_BITS) - -/* Last bit of a word mask. Important for calculating next state */ - -#define LAST_BIT_MASK (1 << (WORD_BITS - 1)) - -/* Returns 1 if bit `n` is set, 0 if not. */ - -#define BIT_N_ISSET(word, n) (((word) & (1 << (n))) >> (n)) - -/* The map width must be a multiple of the word size in bits, otherwise - * the calculation of next states becomes much slower (not good on - * low-resource devices). - * - * We can only compile-time check this if the compiler includes a macro for - * the size of an unsigned int. Otherwise, we have to perform a run-time - * check. - */ - -#ifdef UINT_WIDTH -#if CONFIG_GAMES_CGOL_MAPWIDTH % WORD_BITS != 0 -#error "Please choose a map width which is a multiple of sizeof(unsigned int)" -#endif -#endif - -/* Short-hand for accessing the render buffer */ - -#ifdef CONFIG_GAMES_CGOL_DBLBUF -#define render_buf(state) ((state)->rambuf) -#else -#define render_buf(state) ((state)->fb) -#endif - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -struct fb_state_s -{ - struct fb_videoinfo_s vinfo; - struct fb_planeinfo_s pinfo; - unsigned int scale; - int fd; - void *fb; /* Real frame buffer */ -#ifdef CONFIG_GAMES_CGOL_DBLBUF - void *rambuf; /* RAM double buffer */ -#endif -}; - -/* Function which renders a single cell at `x`, `y` */ - -typedef void (*cell_render_f)(const struct fb_state_s *, uint32_t x, - uint32_t y); - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: cgol_init - * - * Description: - * Initializes the CGOL game with some random living cells. These are - * chosen using `rand()` and are approximately uniformly distributed. - * Overlap can happen and is not specially handled. - * - * Parameters: - * map - The map to initialize with random living cells. - * density - The map is initialized with `(1 / density) * TOTAL_CELLS` live - * cells, not accounting for overlap. - * - * Returned Value: - * None - * - ****************************************************************************/ - -static void cgol_init(unsigned int *map, unsigned int density) -{ - unsigned int idx; - uint8_t offset; - - /* Wipe the map to all dead initially */ - - memset(map, 0, WORD_COUNT * sizeof(unsigned int)); - - /* Approximately half the total cells should start alive. */ - - for (unsigned int i = 0; i < TOTAL_CELLS / density; i++) - { - /* Choose a random word, and within that word, choose a random bit to - * start as a live cell. - */ - - idx = rand() % WORD_COUNT; - offset = rand() % WORD_BITS; - map[idx] |= (1 << offset); - } - - return; -} - -/**************************************************************************** - * Name: cell_lives - * - * Description: - * Calculates if a cell lives or dies in the next generation according to - * the rules of CGOL. - * - * Rules of cells in CGOL: - * - Any live cell with < 2 neighbour dies by underpopulation - * - Any live cell with 2-3 live neighbours lives - * - Any live cell with > 3 live neighbours dies by overpopulation - * - Any dead cell with exactly 3 live neighbours becomes alive - * - * Parameters: - * alive - True if the cell is alive, false if the cell is dead - * count - The cell's neighbour count - * - * Returned Value: - * Returns 1 if the cell lives, 0 if the cell doesn't. - * - ****************************************************************************/ - -static unsigned int cell_lives(unsigned int alive, uint8_t count) -{ - if (alive) - { - if (count < 2) - { - return 0; - } - else if (count > 3) - { - return 0; - } - else - { - return 1; - } - } - - /* Cell is dead */ - - return count == 3 ? 1 : 0; -} - -/**************************************************************************** - * Name: cgol_advance - * - * Description: - * Advances the state of the game to the next time step. The next state - * overwrites the current one in `map`. - * - * NOTE: This function expects both maps to have the same dimensions. - * - * Parameters: - * map - A bit-field map representing all of the cells in the map - * - * Returned Value: - * The pointer of the most updated map. - * - ****************************************************************************/ - -static void cgol_advance(unsigned int *map) -{ - unsigned int *above; - unsigned int *cur; - unsigned int *below; - unsigned int prev_idx; - unsigned int next_idx; - unsigned int zerobuf[MAPWIDTH_WORDS]; - uint8_t count; - - unsigned int buffer[2][MAPWIDTH_WORDS]; - unsigned int *readybuf = buffer[0]; - unsigned int *workbuf = buffer[1]; - unsigned int *temp; - - /* We start with `cur` as row 1 of the map. Any part of our row scanner - * (which is three rows in height) that exceeds the map's y limits - * is made to point to a row of dead cells. This will prevent us from - * having to handle more special cases in the logic below. - */ - - memset(zerobuf, 0, sizeof(zerobuf)); - - above = zerobuf; - cur = map; - below = map + MAPWIDTH_WORDS; - - /* For each row of the map (i.e. while the `cur` pointer hasn't looped back - * to the start of the map): - */ - - do - { - /* Working buffer starts zeroed so we don't need to explicitly do bit - * operations on dead cells. - */ - - memset(workbuf, 0, MAPWIDTH_WORDS * sizeof(unsigned int)); - - /* Iterate through each word in the rows. */ - - for (unsigned int i = 0; i < MAPWIDTH_WORDS; i++) - { - /* Get the previous and next indexes (considering wrap-around), - * since they will be useful later - */ - - if (i == 0) - { - prev_idx = MAPWIDTH_WORDS - 1; - } - else - { - prev_idx = i - 1; - } - - if (i + 1 == MAPWIDTH_WORDS) - { - next_idx = 0; - } - else - { - next_idx = i + 1; - } - - /* Iterate through each cell (bit) in the word */ - - for (uint8_t b = 0; b < WORD_BITS; b++) - { - count = 0; - - /* Count the three '1' bits above and below our cell in the - * neighbourhood. - */ - - if (b == 0) - { - /* Bit 0 also needs to check the last bit of the next word - * above, below and immediately left. - */ - - count += popcount(above[i] & 0x3); - count += popcount(below[i] & 0x3); - count += BIT_N_ISSET(above[prev_idx], WORD_BITS - 1); - count += BIT_N_ISSET(below[prev_idx], WORD_BITS - 1); - count += BIT_N_ISSET(cur[prev_idx], WORD_BITS - 1); - } - else - { - /* For all bits that aren't bit 0, we need to check the - * left-hand side of the neighbourhood. We check top-left - * and bottom-left for free already with above and below - * words, so just check current left explicitly. - */ - - count += popcount(above[i] & (0x7 << (b - 1))); - count += popcount(below[i] & (0x7 << (b - 1))); - count += BIT_N_ISSET(cur[i], b - 1); - } - - /* For all cases except the last bit, we can easily check the - * right-most neighbours. - */ - - if (b == WORD_BITS - 1) - { - /* We need to fetch the next words and check if their - * first bits are set. - */ - - count += BIT_N_ISSET(cur[next_idx], 0); - count += BIT_N_ISSET(above[next_idx], 0); - count += BIT_N_ISSET(below[next_idx], 0); - } - else - { - /* We already checked top-right and bottom-right before, - * check the current right only. - */ - - count += BIT_N_ISSET(cur[i], b + 1); - } - - /* Now, we should have the complete neighbourhood count for the - * cell at word `i` and bit `b`. - * - * We always put the next state of neighbours into the last row - * of the buffer. Then, we shift up the rows by one index. Once - * a row has bubbled to the top of the buffer, it is used to - * overwrite the corresponding row of the map. - */ - - DEBUGASSERT(count <= 8); /* Only 8 neighbours to this cell */ - workbuf[i] |= (cell_lives(cur[i] & (1 << b), count) << b); - } - } - - if (cur - map >= MAPWIDTH_WORDS) - { - /* We can copy the portion of the next state that is ready to the - * `above` row. Once we hit the next iteration, the `above` row - * isn't used for calculation ever again. Since it will no longer - * have any impact on the following neighbourhoods, it's safe to - * overwrite in the map. - * - * NOTE: We only does this when `cur` is row 1 onward, since - * otherwise `readybuf` is uninitialized. - * - * NOTE: This is the clever trick that allows us to have only 2 - * rows of buffer for the next state calculation, regardless of - * the map size. This is very advantageous for embedded contexts. - * Row buffers are even better because each word in the buffer is - * `WORD_BITS` cells, opposed to column buffering which would take - * as many words as the map height (a factor of `WORD_BITS` worse - * than row buffering). - */ - - memcpy(above, readybuf, MAPWIDTH_WORDS * sizeof(unsigned int)); - } - - /* Swap work buffer and temporary buffer */ - - temp = workbuf; - workbuf = readybuf; - readybuf = temp; - - /* Now all the updating and whatnot is done for this row. Increment the - * row pointers to the next rows and continue! - */ - - above = cur; - cur = below; - below += MAPWIDTH_WORDS; - - /* If we exceed the bottom of the map, the 'below' pointer gets to be - * the zero buffer. - */ - - if (below >= map + WORD_COUNT) - { - below = zerobuf; - } - } - - /* Since we move up the pointers for `above`, `cur` and `below`, the `cur` - * pointer will be moved to the `zerobuf` once we hit the bottom of the - * map. This is the reason for this condition. - */ - - while (cur != zerobuf); - - /* We perform one last copy from the `readybuf` at this stage, since the - * `above` row will never reach the bottom row during the regular loop - * iterations. - */ - - memcpy(above, readybuf, MAPWIDTH_WORDS * sizeof(unsigned int)); -} - -/**************************************************************************** - * Name: cgol_render_update - * - * Description: - * Updates the frame buffer with the current render. - * - * Parameters: - * state - The frame buffer state information to use for rendering - * - * Returned Value: - * None - * - ****************************************************************************/ - -static void cgol_render_update(const struct fb_state_s *state) -{ -#ifdef CONFIG_FB_UPDATE - struct fb_area_s *full_screen; - - /* Create an area with the dimensions of the full screen for updating the - * frame buffer after render operations are complete. - */ - - full_screen.x = 0; - full_screen.y = 0; - full_screen.w = fb_state.vinfo.xres; - full_screen.h = fb_state.vinfo.yres; -#endif - - /* If double buffering, copy the RAM buffer to the frame buffer */ - -#ifdef CONFIG_GAMES_CGOL_DBLBUF - memcpy(state->fb, state->rambuf, state->pinfo.fblen); -#endif - - /* If the frame buffer on this device needs explicit updates, do that */ - -#ifdef CONFIG_FB_UPDATE - err = ioctl(fb_state.fd, FBIO_UPDATE, (uintptr_t)&full_screen); - if (err < 0) - { - fprintf(stderr, "Couldn't update screen: %d\n", errno); - } -#endif -} - -/**************************************************************************** - * Name: cgol_render_clear - * - * Description: - * Wipes the frame buffer clean to the background colour. - * - * Parameters: - * state - The frame buffer state information to use for rendering - * - * Returned Value: - * None - * - ****************************************************************************/ - -static void cgol_render_clear(const struct fb_state_s *state) -{ - /* TODO: we can do this more efficiently if we just blot out the pixels - * used for live cells last frame. - */ - - switch (state->pinfo.bpp) - { - case 32: - for (uint32_t y = 0; y < state->pinfo.yres_virtual; y++) - { - uint8_t *row = render_buf(state) + state->pinfo.stride * y; - for (uint32_t x = 0; x < state->pinfo.xres_virtual; x++) - { - ((uint32_t *)(row))[x] = BG32; - } - } - break; - - case 24: - for (uint32_t y = 0; y < state->pinfo.yres_virtual; y++) - { - uint8_t *row = render_buf(state) + state->pinfo.stride * y; - for (uint32_t x = 0; x < state->pinfo.xres_virtual; x++) - { - *row++ = RGB24BLUE(BG24); - *row++ = RGB24GREEN(BG24); - *row++ = RGB24RED(BG24); - } - } - break; - - case 16: - { - for (uint32_t y = 0; y < state->pinfo.yres_virtual; y++) - { - uint8_t *row = render_buf(state) + state->pinfo.stride * y; - for (uint32_t x = 0; x < state->pinfo.xres_virtual; x++) - { - ((uint16_t *)(row))[x] = BG16; - } - } - } - break; - - case 8: - memset(render_buf(state), BG8, state->pinfo.fblen); - break; - } -} - -/**************************************************************************** - * Name: cgol_render_cell8 - * - * Description: - * Renders living cell with 8bpp. - * - * Parameters: - * state - The frame buffer state information to use for rendering - * - * Returned Value: - * None - * - ****************************************************************************/ - -static void cgol_render_cell8(const struct fb_state_s *state, uint32_t x, - uint32_t y) -{ - uint8_t *row; - - /* Scale the (x, y) coordinates */ - - x *= state->scale; - y *= state->scale; - - /* Starting at the (x, y) pair, we draw `scale` cells in each direction */ - - for (uint8_t yy = 0; yy < state->scale; yy++) - { - row = ((uint8_t *)render_buf(state)) + state->pinfo.stride * y; - for (uint8_t xx = 0; xx < state->scale; xx++) - { - row[x + xx] = FG8; - } - - y++; - } -} - -/**************************************************************************** - * Name: cgol_render_cell16 - * - * Description: - * Renders living cell with 16bpp. - * - * Parameters: - * state - The frame buffer state information to use for rendering - * - * Returned Value: - * None - * - ****************************************************************************/ - -static void cgol_render_cell16(const struct fb_state_s *state, uint32_t x, - uint32_t y) -{ - uint8_t *row; - - /* Scale the (x, y) coordinates */ - - x *= state->scale; - y *= state->scale; - - /* Starting at the (x, y) pair, we draw `scale` cells in each direction */ - - for (uint8_t yy = 0; yy < state->scale; yy++) - { - row = ((uint8_t *)render_buf(state)) + state->pinfo.stride * y; - for (uint8_t xx = 0; xx < state->scale; xx++) - { - ((uint16_t *)(row))[x + xx] = FG16; - } - - y++; - } -} - -/**************************************************************************** - * Name: cgol_render_cell24 - * - * Description: - * Renders living cell with 24bpp. - * - * Parameters: - * state - The frame buffer state information to use for rendering - * - * Returned Value: - * None - * - ****************************************************************************/ - -static void cgol_render_cell24(const struct fb_state_s *state, uint32_t x, - uint32_t y) -{ - uint8_t *row; - - /* Scale the (x, y) coordinates */ - - x *= state->scale; - y *= state->scale; - - /* Starting at the (x, y) pair, we draw `scale` cells in each direction */ - - for (uint8_t yy = 0; yy < state->scale; yy++) - { - row = ((uint8_t *)render_buf(state)) + state->pinfo.stride * y; - for (uint8_t xx = 0; xx < state->scale; xx++) - { - row[x + xx + 0] = RGB24BLUE(BG24); - row[x + xx + 1] = RGB24GREEN(BG24); - row[x + xx + 2] = RGB24RED(BG24); - } - - y++; - } -} - -/**************************************************************************** - * Name: cgol_render_cell32 - * - * Description: - * Renders living cell with 32bpp. - * - * Parameters: - * state - The frame buffer state information to use for rendering - * - * Returned Value: - * None - * - ****************************************************************************/ - -static void cgol_render_cell32(const struct fb_state_s *state, uint32_t x, - uint32_t y) -{ - uint8_t *row; - - /* Scale the (x, y) coordinates */ - - x *= state->scale; - y *= state->scale; - - /* Starting at the (x, y) pair, we draw `scale` cells in each direction */ - - for (uint8_t yy = 0; yy < state->scale; yy++) - { - row = ((uint8_t *)render_buf(state)) + state->pinfo.stride * y; - for (uint8_t xx = 0; xx < state->scale; xx++) - { - ((uint32_t *)(row))[x + xx] = FG32; - } - - y++; - } -} - -/**************************************************************************** - * Name: cgol_render_alive - * - * Description: - * Renders living cells to the frame buffer. - * - * Parameters: - * state - The frame buffer state information to use for rendering - * map - The bit-field map where 1 represents living cells, 0 for dead - * cells - * - * Returned Value: - * None - * - ****************************************************************************/ - -static void cgol_render_alive(const struct fb_state_s *state, - const unsigned int *map) -{ - cell_render_f render_cell = NULL; - uint32_t x; - uint32_t y; - uint32_t bit_index; - unsigned int word; - const unsigned int *start; - const unsigned int *end; - - switch (state->pinfo.bpp) - { - case 32: - render_cell = cgol_render_cell32; - break; - case 24: - render_cell = cgol_render_cell24; - break; - case 16: - render_cell = cgol_render_cell16; - break; - case 8: - render_cell = cgol_render_cell8; - break; - } - - DEBUGASSERT(render_cell != NULL); - - /* Render only the living cells. */ - - start = map; - end = &map[WORD_COUNT]; - - for (; map < end; map++) - { - word = *map; /* Current word */ - - /* Determine where we are in the map in terms of (x, y) coords. - */ - - bit_index = (map - start) * WORD_BITS; - y = (bit_index) / CONFIG_GAMES_CGOL_MAPWIDTH; - x = (bit_index) % CONFIG_GAMES_CGOL_MAPWIDTH; - - /* Stop trying to render cells if there are no more living cells in - * this word. - */ - - while (word) - { - /* Get the index of the first bit in the word. - * - * NOTE: reusing the bit_index variable here since it's no longer - * needed. - */ - - bit_index = ffs(word); - DEBUGASSERT(bit_index > 0); - - /* Advance the word past the set bit so that next iteration we'll - * be looking for a new bit. - * - * NOTE: if the bit index is the same as the word size in bits, - * the C standard says that left-shift behaviour is undefined. - * For this case, we just set the word to 0 manually. - */ - - if (bit_index == WORD_BITS) - { - word = 0; - } - else - { - word = word >> bit_index; - } - - /* Calculate the x, y coordinates of the bit we found that was set. - * - * NOTE: We can safely perform `- 1` since there is no way we would - * be here if there isn't a '1' bit in the word. - * - * NOTE: Since we're operating within a single word, there is no - * way that the x index can ever exceed the end of the word, and - * therefore no way that it can ever cross to another row. - */ - - x += (bit_index - 1); - DEBUGASSERT(x < CONFIG_GAMES_CGOL_MAPWIDTH); - - /* Since we've rounded the map length to the nearest word, we - * may have up to WORD_BITS extra bits at the end of our map. - * These bits have invalid (x, y) coordinates. Since the end of - * our map always lands on the end of a row, this will manifest - * with a `y` coordinate that is greater than or equal to the - * map height. In this case, we skip rendering the cell. We've - * also reached the end of the map so it's safe to break out of - * the rendering loop. - */ - - if (y >= CONFIG_GAMES_CGOL_MAPHEIGHT) - { - break; - } - - /* Render the cell at x, y */ - - render_cell(state, x, y); - - /* Since our bit-index increase to x (`x += (bit_index - 1)`) - * doesn't account for the additional left-shift of the word, we - * have to increase x by one here. - */ - - x++; - } - } -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * cgol_main - ****************************************************************************/ - -int main(int argc, FAR char *argv[]) -{ - int err; - char *fbdev = CONFIG_GAMES_CGOL_FBDEV; - struct fb_state_s fb_state; - unsigned int map[WORD_COUNT]; - unsigned int yscale; - unsigned int xscale; - - if (argc == 2) - { - fbdev = argv[1]; - } - - /* Access the frame buffer */ - - fb_state.fd = open(fbdev, O_RDWR); - if (fb_state.fd < 0) - { - fprintf(stderr, "Failed to open %s: %d\n", fbdev, errno); - return EXIT_FAILURE; - } - - /* Get information about the frame buffer for rendering */ - - err = ioctl(fb_state.fd, FBIOGET_VIDEOINFO, (uintptr_t)&fb_state.vinfo); - if (err < 0) - { - fprintf(stderr, "Couldn't get frame buffer video information: %d\n", - errno); - close(fb_state.fd); - return EXIT_FAILURE; - } - - err = ioctl(fb_state.fd, FBIOGET_PLANEINFO, (uintptr_t)&fb_state.pinfo); - if (err < 0) - { - fprintf(stderr, "Couldn't get frame buffer plane information: %d\n", - errno); - close(fb_state.fd); - return EXIT_FAILURE; - } - - /* If the frame buffer resolution is too small to support our game at its - * lowest resolution (one pixel per cell), we can't play :( - */ - - if (fb_state.vinfo.xres < CONFIG_GAMES_CGOL_MAPWIDTH || - fb_state.vinfo.yres < CONFIG_GAMES_CGOL_MAPHEIGHT) - { - fprintf(stderr, - "Needed at least %u x %u px resolution, but got %u x %u", - CONFIG_GAMES_CGOL_MAPWIDTH, CONFIG_GAMES_CGOL_MAPHEIGHT, - fb_state.vinfo.xres, fb_state.vinfo.yres); - close(fb_state.fd); - return EXIT_FAILURE; - } - -#ifndef UINT_WIDTH - - /* If we haven't performed a compile-time check to guarantee that the map - * width is a multiple of the word size, we need to run-time check it. - */ - - if (CONFIG_GAMES_CGOL_MAPWIDTH % WORD_BITS != 0) - { - fprintf( - stderr, - "Map width of %u cells is not a multiple of %u bits (word size)\n", - CONFIG_GAMES_CGOL_MAPWIDTH, WORD_BITS); - close(fb_state.fd); - return EXIT_FAILURE; - } -#endif - - /* Get access to the frame buffer memory */ - - fb_state.fb = mmap(NULL, fb_state.pinfo.fblen, PROT_READ | PROT_WRITE, - MAP_SHARED | MAP_FILE, fb_state.fd, 0); - - if (fb_state.fb == MAP_FAILED) - { - fprintf(stderr, "Failed to map frame buffer memory: %d\n", errno); - close(fb_state.fd); - return EXIT_FAILURE; - } - -#ifdef CONFIG_GAMES_CGOL_DBLBUF - - /* If double buffering, allocate the RAM buffer */ - - fb_state.rambuf = malloc(fb_state.pinfo.fblen); - if (fb_state.rambuf == NULL) - { - fprintf(stderr, "Couldn't allocate double buffer: %d\n", errno); - close(fb_state.fd); - return EXIT_FAILURE; - } -#endif - - /* Determine the ratio of the map size to the frame buffer size. If we can, - * use a scale factor greater than 1 so that the image is rendered larger. - * - * This is selected by picking the minimum of the scale options. - */ - - xscale = fb_state.pinfo.xres_virtual / CONFIG_GAMES_CGOL_MAPWIDTH; - yscale = fb_state.pinfo.yres_virtual / CONFIG_GAMES_CGOL_MAPHEIGHT; - fb_state.scale = xscale < yscale ? xscale : yscale; - - /* Now we can seed the game with some random starting cells */ - - cgol_init(map, CONFIG_GAMES_CGOL_DENSITY); - - /* Initially clear the game backdrop */ - - cgol_render_clear(&fb_state); - - /* Loop the game forever */ - - for (; ; ) - { - /* Render the freshly calculated cells */ - - cgol_render_alive(&fb_state, map); - -#if CONFIG_GAMES_CGOL_FRAMEDELAY > 0 - usleep(CONFIG_GAMES_CGOL_FRAMEDELAY); -#endif - - /* Update the render with the new image */ - - cgol_render_update(&fb_state); - - /* Calculate next state of the cells */ - - cgol_advance(map); - - /* Clear the render in preparation for new cells to be rendered */ - - cgol_render_clear(&fb_state); - } - -#ifdef CONFIG_GAMES_CGOL_DBLBUF - free(fb_state.rambuf); -#endif - close(fb_state.fd); - return EXIT_SUCCESS; -} diff --git a/games/match4/Kconfig b/games/match4/Kconfig deleted file mode 100644 index cd916fd45..000000000 --- a/games/match4/Kconfig +++ /dev/null @@ -1,84 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config GAMES_MATCH4 - bool "Match 4 Game" - default n - ---help--- - Enable Match 4 game. - -if GAMES_MATCH4 - -config GAMES_MATCH4_PROGNAME - string "Program name" - default "match" - ---help--- - This is the name of the program that will be used when the NSH ELF - program is installed. - -config GAMES_MATCH4_PRIORITY - int "Match 4 Game task priority" - default 100 - -config GAMES_MATCH4_STACKSIZE - int "Match 4 Game stack size" - default DEFAULT_TASK_STACKSIZE - -config MATCH4_GAME_DEBUG - bool "Print board status to the serial console for debugging" - default n - -config GAMES_MATCH4_LED_MATRIX_PATH - string "LED matrix path" - default "/dev/leds0" - ---help--- - Path of the led matrix - -config GAMES_MATCH4_LED_MATRIX_ROWS - int "LED Matrix row count" - default 8 - -config GAMES_MATCH4_LED_MATRIX_COLS - int "LED Matrix column count" - default 8 - -# -# Input Device Selection -# - -choice - prompt "Input Device (Serial Console, GPIO, etc)" - default GAMES_MATCH4_USE_CONSOLEKEY - -config GAMES_MATCH4_USE_CONSOLEKEY - bool "Serial Console as Input" - -config GAMES_MATCH4_USE_GPIO - bool "GPIO pins as Input" -endchoice - -if GAMES_MATCH4_USE_GPIO - -config GAMES_MATCH4_DOWN_KEY_PATH - string "Down key path" - default "/dev/gpio1" - ---help--- - Path of the down key to read - -config GAMES_MATCH4_LEFT_KEY_PATH - string "Left key path" - default "/dev/gpio2" - ---help--- - Path of the left key to read - -config GAMES_MATCH4_RIGHT_KEY_PATH - string "Right key path" - default "/dev/gpio3" - ---help--- - Path of the right key to read - -endif #GAMES_MATCH4_USE_GPIO - -endif diff --git a/games/match4/Make.defs b/games/match4/Make.defs deleted file mode 100644 index 27b4f1352..000000000 --- a/games/match4/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/games/match4/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_GAMES_MATCH4),) -CONFIGURED_APPS += $(APPDIR)/games/match4 -endif diff --git a/games/match4/Makefile b/games/match4/Makefile deleted file mode 100644 index 53bc65186..000000000 --- a/games/match4/Makefile +++ /dev/null @@ -1,36 +0,0 @@ -############################################################################ -# apps/games/match4/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -# Match4 game info - -PROGNAME = $(CONFIG_GAMES_MATCH4_PROGNAME) -PRIORITY = $(CONFIG_GAMES_MATCH4_PRIORITY) -STACKSIZE = $(CONFIG_GAMES_MATCH4_STACKSIZE) -MODULE = $(CONFIG_GAMES_MATCH4) - -# Match4 game application - -MAINSRC = match4_main.c - -include $(APPDIR)/Application.mk diff --git a/games/match4/match4_input_console.h b/games/match4/match4_input_console.h deleted file mode 100644 index 3e7f0522e..000000000 --- a/games/match4/match4_input_console.h +++ /dev/null @@ -1,239 +0,0 @@ -/**************************************************************************** - * apps/games/match4/match4_input_console.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include - -#include "match4_inputs.h" - -/**************************************************************************** - * Preprocessor Definitions - ****************************************************************************/ - -/* Termios functions to have getch on Linux/NuttX */ - -static struct termios g_old; -static struct termios g_new; - -/**************************************************************************** - * Name: init_termios - * - * Description: - * Initialize g_new terminal I/O settings. - * - * Parameters: - * echo - Enable echo flag - * - * Returned Value: - * None. - * - ****************************************************************************/ - -void init_termios(int echo) -{ - tcgetattr(0, &g_old); /* grab old terminal i/o settings */ - g_new = g_old; /* use old settings as starting */ - g_new.c_lflag &= ~ICANON; /* disable buffered I/O */ - g_new.c_lflag &= ~ECHO; /* disable ECHO bit */ - g_new.c_lflag |= echo ? ECHO : 0; /* set echo mode if requested */ - tcsetattr(0, TCSANOW, &g_new); /* apply terminal I/O settings */ -} - -/**************************************************************************** - * Name: deinit_termios - * - * Description: - * Restore back g_old terminal I/O settings. - * - * Parameters: - * None - * - * Returned Value: - * None. - * - ****************************************************************************/ - -void deinit_termios(void) -{ - tcsetattr(0, TCSANOW, &g_old); /* restore old terminal i/o settings */ -} - -/**************************************************************************** - * Name: reset_termios - * - * Description: - * Restore g_old terminal i/o settings. - * - * Parameters: - * None - * - * Returned Value: - * None. - * - ****************************************************************************/ - -void reset_termios(void) -{ - tcsetattr(0, TCSANOW, &g_old); -} - -/**************************************************************************** - * Name: getch_ - * - * Description: - * Read 1 character. - * - * Parameters: - * echo - Enable echo mode flag - * - * Returned Value: - * Read character. - * - ****************************************************************************/ - -char getch_(int echo) -{ - char ch; - - init_termios(echo); - ch = getchar(); - reset_termios(); - - return ch; -} - -/**************************************************************************** - * Name: getch - * - * Description: - * Read 1 character without echo. - * - * Parameters: - * None - * - * Returned Value: - * Read character. - * - ****************************************************************************/ - -char getch(void) -{ - return getch_(0); -} - -/**************************************************************************** - * Name: dev_input_init - * - * Description: - * Initialize input method. - * - * Parameters: - * dev - Input state data - * - * Returned Value: - * Zero (OK) - * - ****************************************************************************/ - -int dev_input_init(FAR struct input_state_s *dev) -{ - init_termios(0); - - return OK; -} - -/**************************************************************************** - * Name: dev_input_deinit - * - * Description: - * Deinitialize input method. - * - * Parameters: - * None - * - * Returned Value: - * Zero (OK) - * - ****************************************************************************/ - -int dev_input_deinit(void) -{ - deinit_termios(); - - return OK; -} - -/**************************************************************************** - * Name: dev_read_input - * - * Description: - * Read inputs and returns result in input state data. - * - * Parameters: - * dev - Input state data - * - * Returned Value: - * Zero (OK) - * - ****************************************************************************/ - -int dev_read_input(FAR struct input_state_s *dev) -{ - char ch; - - /* Arrows keys return three bytes: 27 91 [65-68] */ - - if ((ch = getch()) == ASCII_ESC) - { - if ((ch = getch()) == ASCII_LBRACKET) - { - ch = getch(); - if (ch == ASCII_B) - { - dev->dir = DIR_DOWN; - } - else if (ch == ASCII_C) - { - dev->dir = DIR_RIGHT; - } - else if (ch == ASCII_D) - { - dev->dir = DIR_LEFT; - } - } - else - { - dev->dir = DIR_NONE; - } - } - else - { - dev->dir = DIR_NONE; - } - - return OK; -} diff --git a/games/match4/match4_input_gpio.h b/games/match4/match4_input_gpio.h deleted file mode 100644 index a25ab3930..000000000 --- a/games/match4/match4_input_gpio.h +++ /dev/null @@ -1,194 +0,0 @@ -/**************************************************************************** - * apps/games/match4/match4_input_gpio.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "match4_inputs.h" - -/**************************************************************************** - * Preprocessor Definitions - ****************************************************************************/ - -struct gpio_struct_fd_s -{ - int fd_down; /* File descriptor value to read down arrow key */ - int fd_left; /* File descriptor value to read left arrow key */ - int fd_right; /* File descriptor value to read right arrow key */ -}; - -struct gpio_struct_fd_s fd_list; - -/**************************************************************************** - * Name: dev_input_init - * - * Description: - * Initialize input method. - * - * Parameters: - * dev - Input state data - * - * Returned Value: - * Zero (OK) is returned on success. A negated errno value is returned on - * failure. - * - ****************************************************************************/ - -int dev_input_init(FAR struct input_state_s *dev) -{ - /* Open the down key gpio device */ - - fd_list.fd_down = open(CONFIG_GAMES_MATCH4_DOWN_KEY_PATH, O_RDONLY); - if (fd_list.fd_down < 0) - { - fprintf(stderr, "ERROR: Failed to open %s: %d\n", - CONFIG_GAMES_MATCH4_DOWN_KEY_PATH, errno); - return -ENODEV; - } - - /* Open the left key gpio device */ - - fd_list.fd_left = open(CONFIG_GAMES_MATCH4_LEFT_KEY_PATH, O_RDONLY); - if (fd_list.fd_down < 0) - { - fprintf(stderr, "ERROR: Failed to open %s: %d\n", - CONFIG_GAMES_MATCH4_LEFT_KEY_PATH, errno); - return -ENODEV; - } - - /* Open the right key gpio device */ - - fd_list.fd_right = open(CONFIG_GAMES_MATCH4_RIGHT_KEY_PATH, O_RDONLY); - if (fd_list.fd_down < 0) - { - fprintf(stderr, "ERROR: Failed to open %s: %d\n", - CONFIG_GAMES_MATCH4_RIGHT_KEY_PATH, errno); - return -ENODEV; - } - - dev->fd_gpio = (int)&fd_list; - - return OK; -} - -/**************************************************************************** - * Name: dev_input_deinit - * - * Description: - * Deinitialize input method. - * - * Parameters: - * None - * - * Returned Value: - * Zero (OK) - * - ****************************************************************************/ - -int dev_input_deinit(void) -{ - return OK; -} - -/**************************************************************************** - * Name: dev_read_input - * - * Description: - * Read inputs and returns result in input state data. - * - * Parameters: - * dev - Input state data - * - * Returned Value: - * Zero (OK) - * - ****************************************************************************/ - -int dev_read_input(FAR struct input_state_s *dev) -{ - struct gpio_struct_fd_s *fd = (struct gpio_struct_fd_s *)dev->fd_gpio; - int invalue = 0; - int ret; - - ret = ioctl(fd->fd_down, GPIOC_READ, (unsigned long)((uintptr_t)&invalue)); - if (ret < 0) - { - int errcode = errno; - fprintf(stderr, "ERROR: Failed to read value from %s: %d\n", - CONFIG_GAMES_MATCH4_DOWN_KEY_PATH, errcode); - } - else - { - if (invalue != 0) - { - dev->dir = DIR_DOWN; - } - } - - ret = ioctl(fd->fd_left, GPIOC_READ, (unsigned long)((uintptr_t)&invalue)); - if (ret < 0) - { - int errcode = errno; - fprintf(stderr, "ERROR: Failed to read value from %s: %d\n", - CONFIG_GAMES_MATCH4_LEFT_KEY_PATH, errcode); - } - else - { - if (invalue != 0) - { - dev->dir = DIR_LEFT; - } - } - - ret = ioctl(fd->fd_right, GPIOC_READ, - (unsigned long)((uintptr_t)&invalue)); - if (ret < 0) - { - int errcode = errno; - fprintf(stderr, "ERROR: Failed to read value from %s: %d\n", - CONFIG_GAMES_MATCH4_RIGHT_KEY_PATH, errcode); - } - else - { - if (invalue != 0) - { - dev->dir = DIR_RIGHT; - } - } - - return OK; -} diff --git a/games/match4/match4_inputs.h b/games/match4/match4_inputs.h deleted file mode 100644 index e48c1847f..000000000 --- a/games/match4/match4_inputs.h +++ /dev/null @@ -1,60 +0,0 @@ -/**************************************************************************** - * apps/games/match4/match4_inputs.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -/**************************************************************************** - * Preprocessor Definitions - ****************************************************************************/ - -#ifndef DIR_NONE -# define DIR_NONE 0 -#endif - -#ifndef DIR_LEFT -# define DIR_LEFT 1 -#endif - -#ifndef DIR_RIGHT -# define DIR_RIGHT 2 -#endif - -#ifndef DIR_DOWN -# define DIR_DOWN 4 -#endif - -struct input_state_s -{ -#ifdef CONFIG_GAMES_MATCH4_USE_CONSOLEKEY - int fd_con; -#endif -#ifdef CONFIG_GAMES_MATCH4_USE_GPIO - int fd_gpio; -#endif - - int dir; /* Direction to move the blocks */ -}; - diff --git a/games/match4/match4_main.c b/games/match4/match4_main.c deleted file mode 100644 index d60e1dbc6..000000000 --- a/games/match4/match4_main.c +++ /dev/null @@ -1,1024 +0,0 @@ -/**************************************************************************** - * apps/games/match4/match4_main.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include - -#ifdef CONFIG_GAMES_MATCH4_USE_CONSOLEKEY -#include "match4_input_console.h" -#endif - -#ifdef CONFIG_GAMES_MATCH4_USE_GPIO -#include "match4_input_gpio.h" -#endif - -/**************************************************************************** - * Preprocessor Definitions - ****************************************************************************/ - -#ifdef CONFIG_MATCH4_GAME_DEBUG -# define DEBUG_MATCH4_GAME 1 -#endif - -#define BOARDX_SIZE CONFIG_GAMES_MATCH4_LED_MATRIX_ROWS -#define BOARDY_SIZE CONFIG_GAMES_MATCH4_LED_MATRIX_COLS - -#define N_LEDS BOARDX_SIZE * BOARDY_SIZE - -#define P1_COLOUR RGB24_YELLOW -#define P1_SELECT_COLOUR RGB24_GOLD -#define P2_COLOUR RGB24_BLUE -#define P2_SELECT_COLOUR RGB24_CYAN -#define BLUE_COLOR RGB24_BLUE -#define RED_COLOR RGB24_RED -#define WHITE_COLOR RGB24_WHITE - -/* ID numbers of game items */ - -#define BLANK_PLACE 0 -#define P1_PREVIEW 1 -#define P1_SELECT 2 -#define P2_PREVIEW 3 -#define P2_SELECT 4 -#define BLUE_INDEX 5 -#define RED_INDEX 6 -#define WHITE_INDEX 7 -#define PALETTE_MAX 8 - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static const char g_board_path[] = - CONFIG_GAMES_MATCH4_LED_MATRIX_PATH; - -/* Game board to show */ - -uint32_t board[BOARDX_SIZE][BOARDY_SIZE] = -{ - 0 -}; - -/* Player colours */ - -uint32_t players[2] = -{ - P1_SELECT, - P2_SELECT, -}; - -/* Player move preview colour */ - -uint32_t players_select[2] = -{ - P1_PREVIEW, - P2_PREVIEW, -}; - -/* Colors used in the game */ - -static const uint32_t palette[] = -{ - RGB24_BLACK, - P1_COLOUR, - P1_SELECT_COLOUR, - P2_COLOUR, - P2_SELECT_COLOUR, - BLUE_COLOR, - RED_COLOR, - WHITE_COLOR, -}; - -/* Game entrance screen that shows one player mode */ - -uint32_t one_player_scr[BOARDX_SIZE][BOARDY_SIZE] = -{ - { - BLUE_INDEX, WHITE_INDEX, WHITE_INDEX, WHITE_INDEX, - BLUE_INDEX, WHITE_INDEX, WHITE_INDEX, WHITE_INDEX - }, - { - WHITE_INDEX, BLUE_INDEX, WHITE_INDEX, BLUE_INDEX, - WHITE_INDEX, WHITE_INDEX, WHITE_INDEX, WHITE_INDEX - }, - { - WHITE_INDEX, WHITE_INDEX, BLUE_INDEX, WHITE_INDEX, - WHITE_INDEX, WHITE_INDEX, WHITE_INDEX, WHITE_INDEX - }, - { - WHITE_INDEX, WHITE_INDEX, RED_INDEX, WHITE_INDEX, - RED_INDEX, RED_INDEX, RED_INDEX, WHITE_INDEX - }, - { - WHITE_INDEX, RED_INDEX, RED_INDEX, WHITE_INDEX, - WHITE_INDEX, WHITE_INDEX, RED_INDEX, WHITE_INDEX - }, - { - WHITE_INDEX, WHITE_INDEX, RED_INDEX, WHITE_INDEX, - RED_INDEX, RED_INDEX, RED_INDEX, WHITE_INDEX - }, - { - WHITE_INDEX, WHITE_INDEX, RED_INDEX, WHITE_INDEX, - RED_INDEX, WHITE_INDEX, WHITE_INDEX, WHITE_INDEX - }, - { - WHITE_INDEX, WHITE_INDEX, RED_INDEX, WHITE_INDEX, - RED_INDEX, RED_INDEX, RED_INDEX, WHITE_INDEX - } -}; - -/* Game entrance screen that shows two players mode */ - -uint32_t two_player_scr[BOARDX_SIZE][BOARDY_SIZE] = -{ - { - WHITE_INDEX, WHITE_INDEX, WHITE_INDEX, BLUE_INDEX, - WHITE_INDEX, WHITE_INDEX, WHITE_INDEX, BLUE_INDEX - }, - { - WHITE_INDEX, WHITE_INDEX, WHITE_INDEX, WHITE_INDEX, - BLUE_INDEX, WHITE_INDEX, BLUE_INDEX, WHITE_INDEX - }, - { - WHITE_INDEX, WHITE_INDEX, WHITE_INDEX, WHITE_INDEX, - WHITE_INDEX, BLUE_INDEX, WHITE_INDEX, WHITE_INDEX - }, - { - WHITE_INDEX, WHITE_INDEX, RED_INDEX, WHITE_INDEX, - RED_INDEX, RED_INDEX, RED_INDEX, WHITE_INDEX - }, - { - WHITE_INDEX, RED_INDEX, RED_INDEX, WHITE_INDEX, - WHITE_INDEX, WHITE_INDEX, RED_INDEX, WHITE_INDEX - }, - { - WHITE_INDEX, WHITE_INDEX, RED_INDEX, WHITE_INDEX, - RED_INDEX, RED_INDEX, RED_INDEX, WHITE_INDEX - }, - { - WHITE_INDEX, WHITE_INDEX, RED_INDEX, WHITE_INDEX, - RED_INDEX, WHITE_INDEX, WHITE_INDEX, WHITE_INDEX - }, - { - WHITE_INDEX, WHITE_INDEX, RED_INDEX, WHITE_INDEX, - RED_INDEX, RED_INDEX, RED_INDEX, WHITE_INDEX - } -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -#ifdef DEBUG_MATCH4_GAME -/**************************************************************************** - * Name: print_board - * - * Description: - * Draw the board for debugging. - * - * Parameters: - * None - * - * Returned Value: - * None. - * - ****************************************************************************/ - -static void print_board(void) -{ - const char board_icons[] = - { - ' ', 'x', 'X', 'o', 'O', '-', '#', ' ', ' ' - }; - - int row; - int col; - int tmp; - - /* Clear screen */ - - printf("\e[1;1H\e[2J"); - - /* Print board */ - - for (int i = 0; i < BOARDY_SIZE; i++) - { - printf(" %d", i); - } - - printf("\n"); - - for (row = 0; row < BOARDY_SIZE; row++) - { - for (col = 0; col < BOARDX_SIZE; col++) - { - printf("|%c", board_icons[board[row][col]]); - } - - printf("|\n"); - } - - for (tmp = 0; tmp < BOARDX_SIZE * 2 + 1; tmp++) - { - printf("-"); - } - - printf("\n"); -} -#endif /* DEBUG_MATCH4_GAME */ - -/**************************************************************************** - * Name: dim_color - * - * Description: - * Dim led color to handle brightness. - * - * Parameters: - * val - RGB24 value of the led - * dim - Percentage of brightness - * - * Returned Value: - * Dimmed RGB24 value. - * - ****************************************************************************/ - -static uint32_t dim_color(uint32_t val, float dim) -{ - uint16_t r = RGB24RED(val); - uint16_t g = RGB24GREEN(val); - uint16_t b = RGB24BLUE(val); - - float sat = dim; - - r *= sat; - g *= sat; - b *= sat; - - return RGBTO24(r, g, b); -} - -/**************************************************************************** - * Name: draw_board - * - * Description: - * Draw the user board. - * - * Parameters: - * fd - File descriptor for screen - * - * Returned Value: - * None. - * - ****************************************************************************/ - -static void draw_board(int fd) -{ - uint32_t buffer[N_LEDS] = - { - 0 - }; - - int result; - uint32_t *bp = buffer; - int x; - int y; - int rgb_val; - int tmp; - -#ifdef DEBUG_MATCH4_GAME - print_board(); -#endif - - for (x = 0; x < BOARDX_SIZE; x++) - { - for (y = 0; y < BOARDY_SIZE; y++) - { - rgb_val = palette[board[x][y]]; - tmp = dim_color(rgb_val, 0.15); - *bp++ = ws2812_gamma_correct(tmp); - } - } - - lseek(fd, 0, SEEK_SET); - - usleep(200); - result = write(fd, buffer, 4 * N_LEDS); - if (result != 4 * N_LEDS) - { - fprintf(stderr, - "ws2812_main: write failed: %d %d\n", - result, - errno); - } -} - -/**************************************************************************** - * Name: fill_board - * - * Description: - * Fill board with given value - * - * Parameters: - * val - Value to fill the board - * - * Returned Value: - * None. - * - ****************************************************************************/ - -static void fill_board(int val) -{ - int i; - int j; - - for (i = 0; i < BOARDX_SIZE; i++) - { - for (j = 0; j < BOARDY_SIZE; j++) - { - board[i][j] = val; - } - } -} - -/**************************************************************************** - * Name: put_mark - * - * Description: - * Drop a piece on the selected column - * - * Parameters: - * col - Column number - * piece - Piece to drop - * - * Returned Value: - * OK on success, ERROR if not. - * - ****************************************************************************/ - -int put_mark(int col, uint32_t piece) -{ - int i = 0; - if (col < 0 || col >= BOARDY_SIZE) - { - return OK; - } - - for (i = BOARDX_SIZE - 1; i >= 0; i--) - { - if (board[i][col] == BLANK_PLACE) - { - board[i][col] = piece; - return OK; - } - } - - return ERROR; -} - -/**************************************************************************** - * Name: check_winner - * - * Description: - * Check for 4 in a row in any direction - * - * Parameters: - * piece - Mark number depends on turn - * blink - Flag to blink - * - * Returned Value: - * OK on success, ERROR if not. - * - ****************************************************************************/ - -int check_winner(uint32_t piece, bool blink, int fd) -{ - int i = 0; - int j = 0; - int k = 0; - - /* Horizontal 4 piece check */ - - for (i = 0; i < BOARDX_SIZE; i++) - { - for (j = 0; j <= BOARDY_SIZE - 4; j++) - { - if (board[i][j] == piece && - board[i][j + 1] == piece && - board[i][j + 2] == piece && - board[i][j + 3] == piece) - { - if (blink) - { - for (k = 0; k < 3; k++) - { - board[i][j] = WHITE_INDEX; - board[i][j + 1] = WHITE_INDEX; - board[i][j + 2] = WHITE_INDEX; - board[i][j + 3] = WHITE_INDEX; - draw_board(fd); - usleep(300000); - - board[i][j] = piece; - board[i][j + 1] = piece; - board[i][j + 2] = piece; - board[i][j + 3] = piece; - draw_board(fd); - usleep(300000); - } - } - - return OK; - } - } - } - - /* Vertical 4 piece check */ - - for (i = 0; i <= BOARDX_SIZE - 4; i++) - { - for (j = 0; j < BOARDY_SIZE; j++) - { - if (board[i][j] == piece && - board[i + 1][j] == piece && - board[i + 2][j] == piece && - board[i + 3][j] == piece) - { - if (blink) - { - for (k = 0; k < 3; k++) - { - board[i][j] = WHITE_INDEX; - board[i + 1][j] = WHITE_INDEX; - board[i + 2][j] = WHITE_INDEX; - board[i + 3][j] = WHITE_INDEX; - draw_board(fd); - usleep(300000); - - board[i][j] = piece; - board[i + 1][j] = piece; - board[i + 2][j] = piece; - board[i + 3][j] = piece; - draw_board(fd); - usleep(300000); - } - } - - return OK; - } - } - } - - /* Diagonal down-right 4 piece check */ - - for (i = 0; i <= BOARDX_SIZE - 4; i++) - { - for (j = 0; j <= BOARDY_SIZE - 4; j++) - { - if (board[i][j] == piece && - board[i + 1][j + 1] == piece && - board[i + 2][j + 2] == piece && - board[i + 3][j + 3] == piece) - { - if (blink) - { - for (k = 0; k < 3; k++) - { - board[i][j] = WHITE_INDEX; - board[i + 1][j + 1] = WHITE_INDEX; - board[i + 2][j + 2] = WHITE_INDEX; - board[i + 3][j + 3] = WHITE_INDEX; - draw_board(fd); - usleep(300000); - - board[i][j] = piece; - board[i + 1][j + 1] = piece; - board[i + 2][j + 2] = piece; - board[i + 3][j + 3] = piece; - draw_board(fd); - usleep(300000); - } - } - - return OK; - } - } - } - - /* Diagonal up-right 4 piece check */ - - for (i = 3; i < BOARDX_SIZE; i++) - { - for (j = 0; j <= BOARDY_SIZE - 4; j++) - { - if (board[i][j] == piece && - board[i - 1][j + 1] == piece && - board[i - 2][j + 2] == piece && - board[i - 3][j + 3] == piece) - { - if (blink) - { - for (k = 0; k < 3; k++) - { - board[i][j] = WHITE_INDEX; - board[i - 1][j + 1] = WHITE_INDEX; - board[i - 2][j + 2] = WHITE_INDEX; - board[i - 3][j + 3] = WHITE_INDEX; - draw_board(fd); - usleep(300000); - - board[i][j] = piece; - board[i - 1][j + 1] = piece; - board[i - 2][j + 2] = piece; - board[i - 3][j + 3] = piece; - draw_board(fd); - usleep(300000); - } - } - - return OK; - } - } - } - - return ERROR; -} - -/**************************************************************************** - * Name: is_board_empty - * - * Description: - * Check if the board is full to decide there is a draw - * - * Parameters: - * None. - * - * Returned Value: - * OK if there is a BLANK_PLACE space, ERROR if not. - * - ****************************************************************************/ - -static int is_board_empty(void) -{ - for (int j = 0; j < BOARDY_SIZE; j++) - { - if (board[0][j] == BLANK_PLACE) - { - return OK; - } - } - - return ERROR; -} - -/**************************************************************************** - * Name: ai_move - * - * Description: - * Finds first empty column to fill - * - * Parameters: - * piece - AI (CPU) piece value - * opponent_piece - Opponent piece value - * - * Returned Value: - * Column number if there is valid move, ERROR if not. - * - ****************************************************************************/ - -int ai_move(uint32_t piece, uint32_t opponent_piece) -{ - int row = 0; - int col = 0; - int valid_boardy_size[BOARDY_SIZE]; - int count = 0; - - /* Trying to find winner move */ - - for (col = 0; col < BOARDY_SIZE; col++) - { - for (row = BOARDX_SIZE - 1; row >= 0; row--) - { - if (board[row][col] == BLANK_PLACE) - { - board[row][col] = piece; - if (check_winner(piece, false, 0) == OK) - { - board[row][col] = 0; - return col; - } - - board[row][col] = 0; - break; - } - } - } - - /* Trying to block opponent let to win */ - - for (col = 0; col < BOARDY_SIZE; col++) - { - for (row = BOARDX_SIZE - 1; row >= 0; row--) - { - if (board[row][col] == BLANK_PLACE) - { - board[row][col] = opponent_piece; - if (check_winner(opponent_piece, false, 0) == OK) - { - board[row][col] = 0; - return col; - } - - board[row][col] = 0; - break; - } - } - } - - /* Choose random column */ - - for (col = 0; col < BOARDY_SIZE; col++) - { - if (board[0][col] == BLANK_PLACE) - { - valid_boardy_size[count++] = col; - } - } - - if (count > 0) - { - return valid_boardy_size[rand() % count]; - } - - /* Return ERROR if no valid move */ - - return ERROR; -} - -/**************************************************************************** - * Name: find_empty_col - * - * Description: - * Finds first empty column to fill - * - * Parameters: - * col - Column number to start - * dir - Direction from that column - * - * Returned Value: - * First empty column to fill. - * - ****************************************************************************/ - -static int find_empty_col(int col, int dir) -{ - int i = 0; - while (i < BOARDY_SIZE) - { - if ((col == 7) && (dir == 1)) - { - col = 0; - } - else if ((col == BLANK_PLACE) && (dir == -1)) - { - col = 7; - } - else - { - col = col + dir; - } - - if (board[0][col] == BLANK_PLACE) - { - break; - } - - i++; - } - - return col; -} - -/**************************************************************************** - * Name: init_game - * - * Description: - * Initializes game to start properly - * - * Parameters: - * None - * - * Returned Value: - * None. - * - ****************************************************************************/ - -static void init_game(void) -{ - fill_board(BLANK_PLACE); -} - -/**************************************************************************** - * Name: get_col_input - * - * Description: - * Gets column number to put mark into board. - * - * Parameters: - * input_st - Input struct pointer to get input - * turn - Turn number - * col - Column number pointer to return - * fd - File descriptor to print - * - * Returned Value: - * None. - * - ****************************************************************************/ - -static void get_col_input(struct input_state_s *input_st, - int turn, int *col, int fd) -{ - int ret = ERROR; - uint8_t column = find_empty_col(-1, 1); - bool refresh_board = true; - - printf("Player %d, choose column (0-%d): \n", turn + 1, BOARDX_SIZE - 1); - while (input_st->dir != DIR_DOWN) - { - if (refresh_board) - { - refresh_board = false; - put_mark(column, players_select[turn]); - draw_board(fd); - int j = 0; - while (board[j][column] != players_select[turn]) - { - j++; - } - - board[j][column] = 0; - } - - while (ret == ERROR || input_st->dir == DIR_NONE) - { - ret = dev_read_input(input_st); - } - - if (input_st->dir == DIR_RIGHT) - { - column = find_empty_col(column, 1); - refresh_board = true; - input_st->dir = DIR_NONE; - printf("right button pressed: %d\n", column); - usleep(7000); - } - else if (input_st->dir == DIR_LEFT) - { - column = find_empty_col(column, -1); - refresh_board = true; - input_st->dir = DIR_NONE; - printf("left button pressed: %d\n", column); - usleep(7000); - } - - usleep(15000); - } - - usleep(15000); - input_st->dir = DIR_NONE; - *col = column; -} - -/**************************************************************************** - * Name: draw_led_matrix - * - * Description: - * Fills board premade picture - * - * Parameters: - * img - Image to show - * fd - File descriptor to print - * - * Returned Value: - * None. - * - ****************************************************************************/ - -static void draw_led_matrix(uint32_t img[][BOARDY_SIZE], int fd) -{ - int i = 0; - int j = 0; - for (i = 0; i < BOARDX_SIZE; i++) - { - for (j = 0; j < BOARDX_SIZE; j++) - { - board[i][j] = img[i][j]; - } - } - - draw_board(fd); -} - -/**************************************************************************** - * Name: game_entrance - * - * Description: - * Screen that handles entrance screen to select game mode (1-2 player) - * - * Parameters: - * input_st - Input struct pointer to get input - * fd - File descriptor to print - * - * Returned Value: - * True if one player mode, false if two player mode. - * - ****************************************************************************/ - -static bool game_entrance(struct input_state_s *input_st, int fd) -{ - int ret = ERROR; - bool game_mode_one = true; - - draw_led_matrix(one_player_scr, fd); - while (input_st->dir != DIR_DOWN) - { - while (ret == ERROR || input_st->dir == DIR_NONE) - { - ret = dev_read_input(input_st); - } - - if (input_st->dir == DIR_LEFT || input_st->dir == DIR_RIGHT) - { - game_mode_one = !game_mode_one; - if (game_mode_one) - { - draw_led_matrix(one_player_scr, fd); - } - else - { - draw_led_matrix(two_player_scr, fd); - } - - input_st->dir = DIR_NONE; - } - - usleep(15000); - } - - usleep(15000); - input_st->dir = DIR_NONE; - return game_mode_one; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * match4_main - ****************************************************************************/ - -int main(int argc, FAR char *argv[]) -{ - int col = 0; - int turn = 0; - bool one_player_mode = true; - int ret = ERROR; - int board_fd = -1; - bool game_over = false; - struct input_state_s input_st; - char player_symbol[2] = - { - 'X', 'O' - }; - - srand(time(NULL)); - - /* Open the output device driver */ - - board_fd = open(g_board_path, O_RDWR); - if (board_fd < 0) - { - int errcode = errno; - fprintf(stderr, "ERROR: Failed to open %s: %d\n", - g_board_path, errcode); - return EXIT_FAILURE; - } - - dev_input_init(&input_st); - -restart: - ret = 0; - turn = 0; - col = 0; - one_player_mode = true; - input_st.dir = DIR_NONE; - game_over = false; - - one_player_mode = game_entrance(&input_st, board_fd); - init_game(); - while (!game_over) - { - draw_board(board_fd); - if ((one_player_mode && turn == 0) || !one_player_mode) - { - get_col_input(&input_st, turn, &col, board_fd); - } - else - { - col = ai_move(players[turn], players[(turn + 1) % 2]); - printf("AI chooses column %d\n", col); - } - - ret = put_mark(col, players[turn]); - if (ret != 0) - { - printf("Column full or invalid. Try again.\n"); - continue; - } - - if (check_winner(players[turn], true, board_fd) == OK) - { - if ((one_player_mode && turn == 0) || !one_player_mode) - { - printf("\nPlayer %d (%c) wins!\n", - turn + 1, player_symbol[turn]); - } - else - { - printf("\nAI (%c) wins!\n", player_symbol[turn]); - } - - fill_board(players[turn]); - draw_board(board_fd); - usleep(85000); - break; - } - - if (is_board_empty() != OK) - { - printf("It's a draw!\n"); - break; - } - - turn = (turn + 1) % 2; - usleep(85000); - } - - printf("Please press left key to exit or other keys to restart\n"); - usleep(2000000); - - input_st.dir = DIR_NONE; - ret = ERROR; - while (ret == ERROR && input_st.dir == DIR_NONE) - { - ret = dev_read_input(&input_st); - } - - if (input_st.dir != DIR_LEFT) - { - goto restart; - } - - input_st.dir = DIR_NONE; - dev_input_deinit(); - return 0; -} diff --git a/games/snake/Kconfig b/games/snake/Kconfig deleted file mode 100644 index 35be60035..000000000 --- a/games/snake/Kconfig +++ /dev/null @@ -1,90 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config GAMES_SNAKE - bool "Snake Game" - default n - ---help--- - Enable Snake game. - -if GAMES_SNAKE - -config GAMES_SNAKE_PROGNAME - string "Program name" - default "snake" - ---help--- - This is the name of the program that will be used when the NSH ELF - program is installed. - -config GAMES_SNAKE_PRIORITY - int "Snake Game task priority" - default 100 - -config GAMES_SNAKE_STACKSIZE - int "Snake Game stack size" - default DEFAULT_TASK_STACKSIZE - -config DEBUG_SNAKE_GAME - bool "Print board status to the serial console for debugging" - default n - -config GAMES_SNAKE_LED_MATRIX_PATH - string "LED matrix path" - default "/dev/leds0" - ---help--- - Path of the led matrix - -config GAMES_SNAKE_LED_MATRIX_ROWS - int "LED Matrix row count" - default 8 - -config GAMES_SNAKE_LED_MATRIX_COLS - int "LED Matrix column count" - default 8 - -# -# Input Device Selection -# - -choice INPUT_METHOD - prompt "Input Device (Serial Console, GPIO, etc)" - default GAMES_SNAKE_USE_CONSOLEKEY - -config GAMES_SNAKE_USE_CONSOLEKEY - bool "Serial Console as Input" - -config GAMES_SNAKE_USE_GPIO - bool "GPIO pins as Input" -endchoice - -if GAMES_SNAKE_USE_GPIO - -config GAMES_SNAKE_UP_KEY_PATH - string "Up key path" - default "/dev/gpio0" - ---help--- - Path of the up key to read - -config GAMES_SNAKE_DOWN_KEY_PATH - string "Down key path" - default "/dev/gpio1" - ---help--- - Path of the down key to read - -config GAMES_SNAKE_LEFT_KEY_PATH - string "Left key path" - default "/dev/gpio2" - ---help--- - Path of the left key to read - -config GAMES_SNAKE_RIGHT_KEY_PATH - string "Right key path" - default "/dev/gpio3" - ---help--- - Path of the right key to read - -endif #GAMES_SNAKE_USE_GPIO - -endif diff --git a/games/snake/Make.defs b/games/snake/Make.defs deleted file mode 100644 index 8656d46ca..000000000 --- a/games/snake/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/games/snake/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_GAMES_SNAKE),) -CONFIGURED_APPS += $(APPDIR)/games/snake -endif diff --git a/games/snake/Makefile b/games/snake/Makefile deleted file mode 100644 index fcdfd15d3..000000000 --- a/games/snake/Makefile +++ /dev/null @@ -1,36 +0,0 @@ -############################################################################ -# apps/games/snake/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -# Snake game info - -PROGNAME = $(CONFIG_GAMES_SNAKE_PROGNAME) -PRIORITY = $(CONFIG_GAMES_SNAKE_PRIORITY) -STACKSIZE = $(CONFIG_GAMES_SNAKE_STACKSIZE) -MODULE = $(CONFIG_GAMES_SNAKE) - -# Snake game application - -MAINSRC = snake_main.c - -include $(APPDIR)/Application.mk diff --git a/games/snake/snake_input_console.h b/games/snake/snake_input_console.h deleted file mode 100644 index 03254f5d5..000000000 --- a/games/snake/snake_input_console.h +++ /dev/null @@ -1,225 +0,0 @@ -/**************************************************************************** - * apps/games/snake/snake_input_console.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include - -#include "snake_inputs.h" - -/**************************************************************************** - * Preprocessor Definitions - ****************************************************************************/ - -/* Termios functions to have getch on Linux/NuttX */ - -static struct termios g_old; -static struct termios g_new; - -/**************************************************************************** - * Name: init_termios - * - * Description: - * Initialize g_new terminal I/O settings. - * - * Parameters: - * echo - Enable echo flag - * - * Returned Value: - * None. - * - ****************************************************************************/ - -void init_termios(int echo) -{ - tcgetattr(0, &g_old); /* grab old terminal i/o settings */ - g_new = g_old; /* use old settings as starting */ - g_new.c_lflag &= ~ICANON; /* disable buffered I/O */ - g_new.c_lflag &= ~ECHO; /* disable ECHO bit */ - g_new.c_lflag |= echo ? ECHO : 0; /* set echo mode if requested */ - tcsetattr(0, TCSANOW, &g_new); /* apply terminal I/O settings */ - fcntl(STDIN_FILENO, F_SETFL, O_NONBLOCK); /* set non-blocking mode */ -} - -/**************************************************************************** - * Name: reset_termios - * - * Description: - * Restore g_old terminal i/o settings. - * - * Parameters: - * None - * - * Returned Value: - * None. - * - ****************************************************************************/ - -void reset_termios(void) -{ - tcsetattr(0, TCSANOW, &g_old); -} - -/**************************************************************************** - * Name: getch_ - * - * Description: - * Read 1 character. - * - * Parameters: - * echo - Enable echo mode flag - * - * Returned Value: - * Read character. - * - ****************************************************************************/ - -char getch_(int echo) -{ - char ch; - - init_termios(echo); - ch = getchar(); - reset_termios(); - - return ch; -} - -/**************************************************************************** - * Name: getch - * - * Description: - * Read 1 character without echo. - * - * Parameters: - * None - * - * Returned Value: - * Read character. - * - ****************************************************************************/ - -char getch(void) -{ - return getch_(0); -} - -/**************************************************************************** - * Name: dev_input_init - * - * Description: - * Initialize input method. - * - * Parameters: - * dev - Input state data - * - * Returned Value: - * Zero (OK) - * - ****************************************************************************/ - -int dev_input_init(FAR struct input_state_s *dev) -{ - init_termios(0); - - return OK; -} - -/**************************************************************************** - * Name: dev_input_deinit - * - * Description: - * Deinitialize input method. - * - * Parameters: - * None - * - * Returned Value: - * Zero (OK) - * - ****************************************************************************/ - -int dev_input_deinit(void) -{ - reset_termios(); - - return OK; -} - -/**************************************************************************** - * Name: dev_read_input - * - * Description: - * Read inputs and returns result in input state data. - * - * Parameters: - * dev - Input state data - * - * Returned Value: - * Zero (OK) - * - ****************************************************************************/ - -int dev_read_input(FAR struct input_state_s *dev) -{ - char ch; - - /* Arrows keys return three bytes: 27 91 [65-68] */ - - if ((ch = getch()) == ASCII_ESC) - { - if ((ch = getch()) == ASCII_LBRACKET) - { - ch = getch(); - if (ch == ASCII_A) - { - dev->dir = DIR_UP; - } - else if (ch == ASCII_B) - { - dev->dir = DIR_DOWN; - } - else if (ch == ASCII_C) - { - dev->dir = DIR_RIGHT; - } - else if (ch == ASCII_D) - { - dev->dir = DIR_LEFT; - } - } - else - { - dev->dir = DIR_NONE; - } - } - else - { - dev->dir = DIR_NONE; - } - - return OK; -} diff --git a/games/snake/snake_input_gpio.h b/games/snake/snake_input_gpio.h deleted file mode 100644 index 2a487d331..000000000 --- a/games/snake/snake_input_gpio.h +++ /dev/null @@ -1,220 +0,0 @@ -/**************************************************************************** - * apps/games/snake/snake_input_gpio.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "snake_inputs.h" - -/**************************************************************************** - * Preprocessor Definitions - ****************************************************************************/ - -struct gpio_struct_fd_s -{ - int fd_up; /* File descriptor value to read up arrow key */ - int fd_down; /* File descriptor value to read down arrow key */ - int fd_left; /* File descriptor value to read left arrow key */ - int fd_right; /* File descriptor value to read right arrow key */ -}; - -struct gpio_struct_fd_s fd_list; - -/**************************************************************************** - * Name: dev_input_init - * - * Description: - * Initialize input method. - * - * Parameters: - * dev - Input state data - * - * Returned Value: - * Zero (OK) is returned on success. A negated errno value is returned on - * failure. - * - ****************************************************************************/ - -int dev_input_init(FAR struct input_state_s *dev) -{ - /* Open the up key gpio device */ - - fd_list.fd_up = open(CONFIG_GAMES_SNAKE_UP_KEY_PATH, O_RDONLY); - if (fd_list.fd_up < 0) - { - fprintf(stderr, "ERROR: Failed to open %s: %d\n", - CONFIG_GAMES_SNAKE_UP_KEY_PATH, errno); - return -ENODEV; - } - - /* Open the down key gpio device */ - - fd_list.fd_down = open(CONFIG_GAMES_SNAKE_DOWN_KEY_PATH, O_RDONLY); - if (fd_list.fd_down < 0) - { - fprintf(stderr, "ERROR: Failed to open %s: %d\n", - CONFIG_GAMES_SNAKE_DOWN_KEY_PATH, errno); - return -ENODEV; - } - - /* Open the left key gpio device */ - - fd_list.fd_left = open(CONFIG_GAMES_SNAKE_LEFT_KEY_PATH, O_RDONLY); - if (fd_list.fd_down < 0) - { - fprintf(stderr, "ERROR: Failed to open %s: %d\n", - CONFIG_GAMES_SNAKE_LEFT_KEY_PATH, errno); - return -ENODEV; - } - - /* Open the right key gpio device */ - - fd_list.fd_right = open(CONFIG_GAMES_SNAKE_RIGHT_KEY_PATH, O_RDONLY); - if (fd_list.fd_down < 0) - { - fprintf(stderr, "ERROR: Failed to open %s: %d\n", - CONFIG_GAMES_SNAKE_RIGHT_KEY_PATH, errno); - return -ENODEV; - } - - dev->fd_gpio = (int)&fd_list; - - return OK; -} - -/**************************************************************************** - * Name: dev_input_deinit - * - * Description: - * Deinitialize input method. - * - * Parameters: - * None - * - * Returned Value: - * Zero (OK) - * - ****************************************************************************/ - -int dev_input_deinit(void) -{ - return OK; -} - -/**************************************************************************** - * Name: dev_read_input - * - * Description: - * Read inputs and returns result in input state data. - * - * Parameters: - * dev - Input state data - * - * Returned Value: - * Zero (OK) - * - ****************************************************************************/ - -int dev_read_input(FAR struct input_state_s *dev) -{ - struct gpio_struct_fd_s *fd = (struct gpio_struct_fd_s *)dev->fd_gpio; - int invalue = 0; - int ret; - - ret = ioctl(fd->fd_up, GPIOC_READ, (unsigned long)((uintptr_t)&invalue)); - if (ret < 0) - { - int errcode = errno; - fprintf(stderr, "ERROR: Failed to read value from %s: %d\n", - CONFIG_GAMES_SNAKE_UP_KEY_PATH, errcode); - } - else - { - if (invalue != 0) - { - dev->dir = DIR_UP; - } - } - - ret = ioctl(fd->fd_down, GPIOC_READ, (unsigned long)((uintptr_t)&invalue)); - if (ret < 0) - { - int errcode = errno; - fprintf(stderr, "ERROR: Failed to read value from %s: %d\n", - CONFIG_GAMES_SNAKE_DOWN_KEY_PATH, errcode); - } - else - { - if (invalue != 0) - { - dev->dir = DIR_DOWN; - } - } - - ret = ioctl(fd->fd_left, GPIOC_READ, (unsigned long)((uintptr_t)&invalue)); - if (ret < 0) - { - int errcode = errno; - fprintf(stderr, "ERROR: Failed to read value from %s: %d\n", - CONFIG_GAMES_SNAKE_LEFT_KEY_PATH, errcode); - } - else - { - if (invalue != 0) - { - dev->dir = DIR_LEFT; - } - } - - ret = ioctl(fd->fd_right, GPIOC_READ, - (unsigned long)((uintptr_t)&invalue)); - if (ret < 0) - { - int errcode = errno; - fprintf(stderr, "ERROR: Failed to read value from %s: %d\n", - CONFIG_GAMES_SNAKE_RIGHT_KEY_PATH, errcode); - } - else - { - if (invalue != 0) - { - dev->dir = DIR_RIGHT; - } - } - - return OK; -} diff --git a/games/snake/snake_inputs.h b/games/snake/snake_inputs.h deleted file mode 100644 index 630349459..000000000 --- a/games/snake/snake_inputs.h +++ /dev/null @@ -1,64 +0,0 @@ -/**************************************************************************** - * apps/games/snake/snake_inputs.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -/**************************************************************************** - * Preprocessor Definitions - ****************************************************************************/ - -#ifndef DIR_NONE -# define DIR_NONE 0 -#endif - -#ifndef DIR_LEFT -# define DIR_LEFT 1 -#endif - -#ifndef DIR_RIGHT -# define DIR_RIGHT 2 -#endif - -#ifndef DIR_UP -# define DIR_UP 3 -#endif - -#ifndef DIR_DOWN -# define DIR_DOWN 4 -#endif - -struct input_state_s -{ -#ifdef CONFIG_GAMES_SNAKE_USE_CONSOLEKEY - int fd_con; -#endif -#ifdef CONFIG_GAMES_SNAKE_USE_GPIO - int fd_gpio; -#endif - - int dir; /* Direction to move the blocks */ -}; - diff --git a/games/snake/snake_main.c b/games/snake/snake_main.c deleted file mode 100644 index a49357c7c..000000000 --- a/games/snake/snake_main.c +++ /dev/null @@ -1,742 +0,0 @@ -/**************************************************************************** - * apps/games/snake/snake_main.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include - -#ifdef CONFIG_GAMES_SNAKE_USE_CONSOLEKEY -#include "snake_input_console.h" -#endif - -#ifdef CONFIG_GAMES_SNAKE_USE_GPIO -#include "snake_input_gpio.h" -#endif - -/**************************************************************************** - * Preprocessor Definitions - ****************************************************************************/ - -#ifdef CONFIG_DEBUG_SNAKE_GAME -# define DEBUG_SNAKE_GAME 1 -#endif - -#define BOARDX_SIZE CONFIG_GAMES_SNAKE_LED_MATRIX_ROWS -#define BOARDY_SIZE CONFIG_GAMES_SNAKE_LED_MATRIX_COLS - -#define N_LEDS BOARDX_SIZE * BOARDY_SIZE - -/* ID numbers of game items */ - -#define BLANK_PLACE 0 -#define SNAKE_TAIL 1 -#define SNAKE_HEAD 2 -#define FOOD 3 -#define BLINK 4 -#define HIGH_SCORE 5 - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/* Game item struct to represent in board */ - -struct game_item -{ - int pos_x; - int pos_y; -}; - -/* Snake item struct to represent in board */ - -struct snake_item -{ - struct game_item tail[BOARDX_SIZE * BOARDY_SIZE]; - int tail_len; -}; - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static const char g_board_path[] = - CONFIG_GAMES_SNAKE_LED_MATRIX_PATH; - -struct snake_item snake = -{ - 0 -}; - -struct game_item food = -{ - 0 -}; - -/* Game board to show */ - -uint32_t board[BOARDX_SIZE][BOARDY_SIZE] = -{ - 0 -}; - -/* Reached highest score */ - -uint32_t high_score = 0; - -/* Colors used in the game plus Black */ - -static const uint32_t palette[] = -{ - RGB24_BLACK, - RGB24_BLUE, - RGB24_CYAN, - RGB24_RED, - RGB24_WHITE, - RGB24_GREENYELLOW, -}; - -/* Second block of score value to print (.e.g 1x) */ - -const uint64_t second_score_block[] = -{ - 0x0007050505070000, - 0x0004040404040000, - 0x0007010704070000, - 0x0007040704070000, - 0x0004040705050000, - 0x0007040701070000, - 0x0007050701070000 -}; - -/* First block of score value to print (.e.g x1) */ - -const uint64_t first_score_block[] = -{ - 0x0070505050700000, - 0x0040404040400000, - 0x0070107040700000, - 0x0070407040700000, - 0x0040407050500000, - 0x0070407010700000, - 0x0070507010700000, - 0x0040404040700000, - 0x0070507050700000, - 0x0070407050700000 -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: dim_color - * - * Description: - * Dim led color to handle brightness. - * - * Parameters: - * val - RGB24 value of the led - * dim - Percentage of brightness - * - * Returned Value: - * Dimmed RGB24 value. - * - ****************************************************************************/ - -static uint32_t dim_color(uint32_t val, float dim) -{ - uint16_t r = RGB24RED(val); - uint16_t g = RGB24GREEN(val); - uint16_t b = RGB24BLUE(val); - - float sat = dim; - - r *= sat; - g *= sat; - b *= sat; - - return RGBTO24(r, g, b); -} - -/**************************************************************************** - * Name: draw_board - * - * Description: - * Draw the user board. - * - * Parameters: - * fd - File descriptor for screen - * - * Returned Value: - * None. - * - ****************************************************************************/ - -static void draw_board(int fd) -{ - uint32_t buffer[N_LEDS] = - { - 0 - }; - - int result; - uint32_t *bp = buffer; - int x; - int y; - int rgb_val; - int tmp; - - for (x = 0; x < BOARDX_SIZE; x++) - { - for (y = 0; y < BOARDY_SIZE; y++) - { - rgb_val = palette[board[x][y]]; - tmp = dim_color(rgb_val, 0.15); - *bp++ = ws2812_gamma_correct(tmp); - } - } - - lseek(fd, 0, SEEK_SET); - - result = write(fd, buffer, 4 * N_LEDS); - if (result != 4 * N_LEDS) - { - fprintf(stderr, - "ws2812_main: write failed: %d %d\n", - result, - errno); - } -} - -/**************************************************************************** - * Name: print_board - * - * Description: - * Draw the board for debugging. - * - * Parameters: - * None - * - * Returned Value: - * None. - * - ****************************************************************************/ - -#ifdef DEBUG_SNAKE_GAME -static void print_board(void) -{ - const char board_icons[] = - { - ' ', - 'o', - 'O', - 'X' - }; - - int row; - int col; - int tmp; - int tmp_idx; - - /* Clear screen */ - - printf("\e[1;1H\e[2J"); - - /* Print board */ - - for (row = 0; row < BOARDY_SIZE; row++) - { - for (tmp = 0; tmp < BOARDX_SIZE; tmp++) - { - printf("+--"); - } - - printf("-+\n"); - printf("|"); - for (col = 0; col < BOARDX_SIZE; col++) - { - tmp_idx = board[row][col]; - printf(" %c ", board_icons[tmp_idx]); - } - - printf("|\n"); - } - - for (tmp = 0; tmp < BOARDX_SIZE; tmp++) - { - printf("+--"); - } - - printf("-+\n\n\n"); -} -#endif - -/**************************************************************************** - * Name: move_snake - * - * Description: - * Move the snake to 'dir' direction (L,R,U,D). - * - * Parameters: - * dir - Direction to move - * - * Returned Value: - * None. - * - ****************************************************************************/ - -static void move_snake(int dir) -{ - int prev_x = snake.tail[0].pos_x; - int prev_y = snake.tail[0].pos_y; - int prev_2x; - int prev_2y; - int i; - - board[prev_x][prev_y] = SNAKE_TAIL; - for (i = 1; i < snake.tail_len; i++) - { - prev_2x = snake.tail[i].pos_x; - prev_2y = snake.tail[i].pos_y; - snake.tail[i].pos_x = prev_x; - snake.tail[i].pos_y = prev_y; - prev_x = prev_2x; - prev_y = prev_2y; - } - - board[prev_x][prev_y] = 0; - - if (dir == DIR_LEFT) - { - snake.tail[0].pos_y--; - } - - if (dir == DIR_RIGHT) - { - snake.tail[0].pos_y++; - } - - if (dir == DIR_UP) - { - snake.tail[0].pos_x--; - } - - if (dir == DIR_DOWN) - { - snake.tail[0].pos_x++; - } - - /* Wrap around screen borders */ - - if (snake.tail[0].pos_x >= BOARDX_SIZE) - { - snake.tail[0].pos_x = 0; - } - - if (snake.tail[0].pos_x < 0) - { - snake.tail[0].pos_x = BOARDX_SIZE - 1; - } - - if (snake.tail[0].pos_y >= BOARDY_SIZE) - { - snake.tail[0].pos_y = 0; - } - - if (snake.tail[0].pos_y < 0) - { - snake.tail[0].pos_y = BOARDY_SIZE - 1; - } - - board[snake.tail[0].pos_x][snake.tail[0].pos_y] = SNAKE_HEAD; -} - -/**************************************************************************** - * Name: fill_board_with_score - * - * Description: - * Fills board with score value to print - * - * Parameters: - * val - Value that includes with tiles should light up - * - * Returned Value: - * None. - * - ****************************************************************************/ - -static void fill_board_with_score(uint64_t val) -{ - int i = 0; - int j = 0; - for (i = 0; i < BOARDX_SIZE; i++) - { - for (j = 0; j < BOARDX_SIZE; j++) - { - if (val % 2 == 0) - { - board[i][j] = BLANK_PLACE; - } - else - { - board[i][j] = FOOD; - } - - val = val >> 1; - } - } -} - -/**************************************************************************** - * Name: print_score - * - * Description: - * Prints score to the screen - * - * Parameters: - * score - Score that reached in game - * fd - File descriptor for screen - * - * Returned Value: - * None. - * - ****************************************************************************/ - -static void print_score(int score, int fd) -{ - int second_idx = (int) score / 10; - int first_idx = score % 10; - uint64_t val = second_score_block[second_idx] | - first_score_block[first_idx]; - fill_board_with_score(val); - draw_board(fd); -} - -/**************************************************************************** - * Name: fill_board - * - * Description: - * Fill board with given value - * - * Parameters: - * val - Value to fill the board - * - * Returned Value: - * None. - * - ****************************************************************************/ - -static void fill_board(int val) -{ - int i; - int j; - - for (i = 0; i < BOARDX_SIZE; i++) - { - for (j = 0; j < BOARDY_SIZE; j++) - { - board[i][j] = val; - } - } -} - -/**************************************************************************** - * Name: init_game - * - * Description: - * Initializes game to start properly - * - * Parameters: - * None - * - * Returned Value: - * None. - * - ****************************************************************************/ - -static void init_game(void) -{ - snake.tail_len = 1; - snake.tail[0].pos_x = BOARDX_SIZE / 2; - snake.tail[0].pos_y = BOARDY_SIZE / 2; - food.pos_x = rand() % BOARDX_SIZE; - food.pos_y = rand() % BOARDY_SIZE; - fill_board(BLANK_PLACE); - - board[BOARDX_SIZE / 2][BOARDY_SIZE / 2] = SNAKE_HEAD; -} - -/**************************************************************************** - * Name: check_food_snake_collision - * - * Description: - * Check if there is any collision between food or snake - * - * Parameters: - * None - * - * Returned Value: - * True(1) if there is collision, False(0) if not. - * - ****************************************************************************/ - -static bool check_food_snake_collision(void) -{ - int i = 0; - - for (i = 0; i < snake.tail_len; i++) - { - if (snake.tail[i].pos_x == food.pos_x && - snake.tail[i].pos_y == food.pos_y) - { - return true; - } - } - - return false; -} - -/**************************************************************************** - * Name: check_collisions - * - * Description: - * Check if there is any collision between food or snake itself - * - * Parameters: - * None - * - * Returned Value: - * True(1) if there is collision itself, False(0) if not. - * - ****************************************************************************/ - -static int check_collisions(void) -{ - int i = 0; - bool end_game = false; - bool food_col = false; - - /* Collision with itself (game over) */ - - for (i = 1; i < snake.tail_len; i++) - { - if (snake.tail[i].pos_x == snake.tail[0].pos_x && - snake.tail[i].pos_y == snake.tail[0].pos_y) - { - end_game = true; - } - } - - /* Collision with food (eating food) */ - - food_col = check_food_snake_collision(); - if (food_col) - { - snake.tail_len++; - - while (food_col) - { - food.pos_x = rand() % BOARDX_SIZE; - food.pos_y = rand() % BOARDY_SIZE; - food_col = check_food_snake_collision(); - } - } - - board[food.pos_x][food.pos_y] = FOOD; - return end_game; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * snake_main - ****************************************************************************/ - -int main(int argc, FAR char *argv[]) -{ - bool game_over; - struct input_state_s input_st; - int board_fd = -1; - int last_dir = DIR_NONE; - int ret = ERROR; - int i; - int idx; - int board_x; - int board_y; - struct snake_item prev_snake = - { - 0 - }; - - srand(time(NULL)); - - /* Open the output device driver */ - - board_fd = open(g_board_path, O_RDWR); - if (board_fd < 0) - { - int errcode = errno; - fprintf(stderr, "ERROR: Failed to open %s: %d\n", - g_board_path, errcode); - return EXIT_FAILURE; - } - - dev_input_init(&input_st); - - /* Draw the empty board to user */ - -restart: - init_game(); - draw_board(board_fd); - - input_st.dir = DIR_NONE; - game_over = false; - - while (!game_over) - { -#ifdef DEBUG_SNAKE_GAME - print_board(); -#endif - draw_board(board_fd); - - last_dir = input_st.dir; - ret = ERROR; - - while (ret == ERROR) - { - ret = dev_read_input(&input_st); - } - - /* Check if input creates collision */ - - if ((last_dir == DIR_LEFT && input_st.dir == DIR_RIGHT) || - (last_dir == DIR_RIGHT && input_st.dir == DIR_LEFT) || - (last_dir == DIR_UP && input_st.dir == DIR_DOWN) || - (last_dir == DIR_DOWN && input_st.dir == DIR_UP)) - { - input_st.dir = last_dir; - } - - if (input_st.dir == DIR_NONE) - { - input_st.dir = last_dir; - } - - memcpy(&prev_snake, &snake, sizeof(struct snake_item)); - - move_snake(input_st.dir); - - game_over = check_collisions(); - - if (game_over) - { - /* Lets do a blinking effect */ - - for (i = 0; i < 3; i++) - { - /* Draw the board with the pieces */ - - for (idx = 0; idx < prev_snake.tail_len; idx++) - { - board_x = prev_snake.tail[idx].pos_x; - board_y = prev_snake.tail[idx].pos_y; - board[board_x][board_y] = BLINK; - } - - draw_board(board_fd); - usleep(100000); - - /* Draw the board without the pieces */ - - board[prev_snake.tail[0].pos_x][prev_snake.tail[0].pos_y] = - SNAKE_HEAD; - for (idx = 1; idx < snake.tail_len; idx++) - { - board_x = prev_snake.tail[idx].pos_x; - board_y = prev_snake.tail[idx].pos_y; - board[board_x][board_y] = SNAKE_TAIL; - } - - draw_board(board_fd); - usleep(100000); - } - - usleep(500000); - } - - usleep(85000); - } - - printf("Game Over! Score: %d\n", snake.tail_len); - if (high_score < snake.tail_len) - { - printf("Congrats! New High Score\n"); - high_score = snake.tail_len; - for (i = 0; i < 3; i++) - { - fill_board(HIGH_SCORE); - draw_board(board_fd); - usleep(200000); - - fill_board(BLANK_PLACE); - draw_board(board_fd); - usleep(200000); - } - } - - print_score(snake.tail_len, board_fd); - - printf("Please press left key to exit or other keys to restart\n"); - usleep(2000000); - - input_st.dir = DIR_NONE; - ret = ERROR; - while (ret == ERROR && input_st.dir == DIR_NONE) - { - ret = dev_read_input(&input_st); - } - - if (input_st.dir != DIR_LEFT) - { - goto restart; - } - - dev_input_deinit(); - return 0; -} diff --git a/audioutils/.gitignore b/gpsutils/.gitignore similarity index 100% rename from audioutils/.gitignore rename to gpsutils/.gitignore diff --git a/tee/Make.defs b/gpsutils/Make.defs similarity index 92% rename from tee/Make.defs rename to gpsutils/Make.defs index 11499d5ed..2cc53fa1f 100644 --- a/tee/Make.defs +++ b/gpsutils/Make.defs @@ -1,5 +1,5 @@ ############################################################################ -# apps/tee/Make.defs +# apps/gpsutils/Make.defs # # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with @@ -18,4 +18,4 @@ # ############################################################################ -include $(wildcard $(APPDIR)/tee/*/Make.defs) +include $(wildcard $(APPDIR)/gpsutils/*/Make.defs) diff --git a/tee/Makefile b/gpsutils/Makefile similarity index 94% rename from tee/Makefile rename to gpsutils/Makefile index 1e41bb1e3..63dbee918 100644 --- a/tee/Makefile +++ b/gpsutils/Makefile @@ -1,5 +1,5 @@ ############################################################################ -# apps/tee/Makefile +# apps/gpsutils/Makefile # # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with @@ -18,6 +18,6 @@ # ############################################################################ -MENUDESC = "TEE Libraries Support" +MENUDESC = "GPS Utilities" include $(APPDIR)/Directory.mk diff --git a/gpsutils/README.md b/gpsutils/README.md new file mode 100644 index 000000000..e05d9a1ea --- /dev/null +++ b/gpsutils/README.md @@ -0,0 +1,10 @@ +# `gpsutils` GPS Utilities + +The `gpsutils` directory is used to include libraries from external projects +that are not part of NuttX Applications, but are useful for NuttX developers and +users. + +## `minmea` GPS NMEA 0183 parser + +MINMEA is a NMEA parser developed by Kosma Moczek. Kosma is also a NuttX +contributor. diff --git a/gpsutils/minmea/Kconfig b/gpsutils/minmea/Kconfig new file mode 100644 index 000000000..c762f8ebd --- /dev/null +++ b/gpsutils/minmea/Kconfig @@ -0,0 +1,17 @@ +# +# For a description of the syntax of this configuration file, +# see the file kconfig-language.txt in the NuttX tools repository. +# + +config GPSUTILS_MINMEA_LIB + bool "MINMEA NMEA Library" + default n + ---help--- + Enable support for the MINMEA NMEA library. + + NOTE: This library depends on having some version of math.h + at include/nuttx. There are some different ways to accomplish + this. See the discussion in the top-level nuttx/README.txt file. + +if GPSUTILS_MINMEA_LIB +endif diff --git a/gpsutils/minmea/Make.defs b/gpsutils/minmea/Make.defs new file mode 100644 index 000000000..efaa939b2 --- /dev/null +++ b/gpsutils/minmea/Make.defs @@ -0,0 +1,23 @@ +############################################################################ +# apps/gpsutils/minmea/Make.defs +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. The +# ASF licenses this file to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance with the +# License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +############################################################################ + +ifeq ($(CONFIG_GPSUTILS_MINMEA_LIB),y) +CONFIGURED_APPS += $(APPDIR)/gpsutils/minmea +endif diff --git a/netutils/iptables/Makefile b/gpsutils/minmea/Makefile similarity index 91% rename from netutils/iptables/Makefile rename to gpsutils/minmea/Makefile index 4b0fe6ee7..a8b59b4ab 100644 --- a/netutils/iptables/Makefile +++ b/gpsutils/minmea/Makefile @@ -1,7 +1,5 @@ ############################################################################ -# apps/netutils/iptables/Makefile -# -# SPDX-License-Identifier: Apache-2.0 +# apps/gpsutils/minmea/Makefile # # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with @@ -22,6 +20,9 @@ include $(APPDIR)/Make.defs -CSRCS += xtables.c +# NSH Library + +CSRCS = minmea.c +CFLAGS += -std=c99 include $(APPDIR)/Application.mk diff --git a/gpsutils/minmea/README.md b/gpsutils/minmea/README.md new file mode 100644 index 000000000..c8ac5b583 --- /dev/null +++ b/gpsutils/minmea/README.md @@ -0,0 +1,152 @@ +# GPS Utilities / `minmea` GPS NMEA 0183 parser + +A lightweight GPS NMEA 0183 parser library + +[![Build Status](https://travis-ci.org/cloudyourcar/minmea.svg?branch=master)](https://travis-ci.org/cloudyourcar/minmea) + +Minmea is a minimalistic GPS parser library written in pure C intended for +resource-constrained platforms, especially microcontrollers and other embedded +systems. + +## Features + +* Written in ISO C99. +* No dynamic memory allocation. +* No floating point usage in the core library. +* Supports both fixed and floating point values. +* One source file and one header - can't get any simpler. +* Easily extendable to support new sentences. +* Complete with a test suite and static analysis. + +## Supported sentences + +* ``RMC`` (Recommended Minimum: position, velocity, time) +* ``GGA`` (Fix Data) +* ``GSA`` (DOP and active satellites) +* ``GLL`` (Geographic Position: Latitude/Longitude) +* ``GST`` (Pseudorange Noise Statistics) +* ``GSV`` (Satellites in view) + +Adding support for more sentences is trivial; see ``minmea.c`` source. + +## Fractional number format + +Internally, minmea stores fractional numbers as pairs of two integers: ``{value, +scale}``. For example, a value of ``"-123.456"`` would be parsed as ``{-123456, +1000}``. As this format is quite unwieldy, minmea provides the following +convenience functions for converting to either fixed-point or floating-point +format: + +* ``minmea_rescale({-123456, 1000}, 10) => -1235`` +* ``minmea_float({-123456, 1000}) => -123.456`` + +The compound type ``struct minmea_float`` uses ``int_least32_t`` internally. +Therefore, the coordinate precision is guaranteed to be at least +``[+-]DDDMM.MMMMM`` (five decimal digits) or ยฑ20cm LSB at the equator. + +## Coordinate format + +NMEA uses the clunky ``DDMM.MMMM`` format which, honestly, is not good in the +internet era. Internally, minmea stores it as a fractional number (see above); +for practical uses, the value should be probably converted to the DD.DDDDD +floating point format using the following function: + +* ``minmea_tocoord({-375165, 100}) => -37.860832`` + +The library doesn't perform this conversion automatically for the following +reasons: + +* The conversion is not reversible. +* It requires floating point hardware. +* The user might want to perform this conversion later on or retain the original + values. + +## Example + +```c +char line[MINMEA_MAX_LENGTH]; +while (fgets(line, sizeof(line), stdin) != NULL) { + switch (minmea_sentence_id(line)) { + case MINMEA_SENTENCE_RMC: { + struct minmea_sentence_rmc frame; + if (minmea_parse_rmc(&frame, line)) { + printf("$RMC: raw coordinates and speed: (%d/%d,%d/%d) %d/%d\n", + frame.latitude.value, frame.latitude.scale, + frame.longitude.value, frame.longitude.scale, + frame.speed.value, frame.speed.scale); + printf("$RMC fixed-point coordinates and speed scaled to three decimal places: (%d,%d) %d\n", + minmea_rescale(&frame.latitude, 1000), + minmea_rescale(&frame.longitude, 1000), + minmea_rescale(&frame.speed, 1000)); + printf("$RMC floating point degree coordinates and speed: (%f,%f) %f\n", + minmea_tocoord(&frame.latitude), + minmea_tocoord(&frame.longitude), + minmea_tofloat(&frame.speed)); + } + } break; + + case MINMEA_SENTENCE_GGA: { + struct minmea_sentence_gga frame; + if (minmea_parse_gga(&frame, line)) { + printf("$GGA: fix quality: %d\n", frame.fix_quality); + } + } break; + + case MINMEA_SENTENCE_GSV: { + struct minmea_sentence_gsv frame; + if (minmea_parse_gsv(&frame, line)) { + printf("$GSV: message %d of %d\n", frame.msg_nr, frame.total_msgs); + printf("$GSV: satellites in view: %d\n", frame.total_sats); + for (int i = 0; i < 4; i++) + printf("$GSV: sat nr %d, elevation: %d, azimuth: %d, snr: %d dbm\n", + frame.sats[i].nr, + frame.sats[i].elevation, + frame.sats[i].azimuth, + frame.sats[i].snr); + } + } break; + } +} +``` + +## Integration with your project + +Simply add ``minmea.[ch]`` to your project, ``#include "minmea.h"`` and you're +good to go. + +## Running unit tests + +Building and running the tests requires the following: + +* Check Framework (http://check.sourceforge.net/). +* Clang Static Analyzer (http://clang-analyzer.llvm.org/). + +If you have both in your ``$PATH``, running the tests should be as simple as +typing ``make``. + +## Limitations + +* Only a handful of frames is supported right now. +* There's no support for omitting parts of the library from building. As a + workaround, use the ``-ffunction-sections -Wl,--gc-sections`` linker flags (or + equivalent) to remove the unused functions (parsers) from the final image. +* Some systems lack ``timegm``. On these systems, the recommended course of + action is to build with ``-Dtimegm=mktime`` which will work correctly as long + the system runs in the default ``UTC`` timezone. Native Windows builds should + use ``-Dtimegm=_mkgmtime`` instead which will work correctly in all timezones. + +## Bugs + +There are plenty. Report them on GitHub, or - even better - open a pull request. +Please write unit tests for any new functions you add - it's fun! + +## Licensing + +Minmea is open source software; see ``COPYING`` for amusement. Email me if the +license bothers you and I'll happily re-license under anything else under the +sun. + +## Author + +Minmea was written by Kosma Moczek <kosma@cloudyourcar.com> at Cloud Your +Car. diff --git a/gpsutils/minmea/minmea.c b/gpsutils/minmea/minmea.c new file mode 100644 index 000000000..5bb41b8da --- /dev/null +++ b/gpsutils/minmea/minmea.c @@ -0,0 +1,879 @@ +/**************************************************************************** + * apps/gpsutils/minmea/minmea.c + * + * Copyright ยฉ 2014 Kosma Moczek + * + * Released under the NuttX BSD license with permission from the author: + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include +#include +#include +#include + +#include "gpsutils/minmea.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define boolstr(s) ((s) ? "true" : "false") + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +static int hex2int(char c) +{ + if (c >= '0' && c <= '9') + { + return c - '0'; + } + + if (c >= 'A' && c <= 'F') + { + return c - 'A' + 10; + } + + if (c >= 'a' && c <= 'f') + { + return c - 'a' + 10; + } + + return -1; +} + +static inline bool minmea_isfield(char c) +{ + return isprint((unsigned char) c) && c != ',' && c != '*'; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +uint8_t minmea_checksum(FAR const char *sentence) +{ + uint8_t checksum = 0x00; + + /* Support sentences with or without the starting dollar sign. */ + + if (*sentence == '$') + { + sentence++; + } + + /* The optional checksum is an XOR of all bytes between "$" and "*". */ + + while (*sentence && *sentence != '*') + { + checksum ^= *sentence++; + } + + return checksum; +} + +bool minmea_check(FAR const char *sentence, bool strict) +{ + uint8_t checksum = 0x00; + + /* Sequence length is limited. */ + + if (strlen(sentence) > MINMEA_MAX_LENGTH + 3) + { + return false; + } + + /* A valid sentence starts with "$". */ + + if (*sentence++ != '$') + { + return false; + } + + /* The optional checksum is an XOR of all bytes between "$" and "*". */ + + while (*sentence && *sentence != '*' && + isprint((unsigned char) *sentence)) + { + checksum ^= *sentence++; + } + + /* If checksum is present... */ + + if (*sentence == '*') + { + int upper; + int lower; + int expected; + + /* Extract checksum. */ + + sentence++; + upper = hex2int(*sentence++); + + if (upper == -1) + { + return false; + } + + lower = hex2int(*sentence++); + if (lower == -1) + { + return false; + } + + expected = upper << 4 | lower; + + /* Check for checksum mismatch. */ + + if (checksum != expected) + { + return false; + } + } + else if (strict) + { + /* Discard non-checksummed frames in strict mode. */ + + return false; + } + + /* The only stuff allowed at this point is a newline. */ + + if (*sentence && strcmp(sentence, "\n") && + strcmp(sentence, "\r\n")) + { + return false; + } + + return true; +} + +bool minmea_scan(FAR const char *sentence, FAR const char *format, ...) +{ + bool result = false; + bool optional = false; + va_list ap; + va_start(ap, format); + + const char *field = sentence; +#define next_field() \ + do \ + { \ + /* Progress to the next field. */ \ + while (minmea_isfield(*sentence)) \ + { \ + sentence++; \ + } \ + /* Make sure there is a field there. */ \ + if (*sentence == ',') \ + { \ + sentence++; \ + field = sentence; \ + } \ + else \ + { \ + field = NULL; \ + } \ + } \ + while (0) + + while (*format) + { + char type = *format++; + + if (type == ';') + { + /* All further fields are optional. */ + + optional = true; + continue; + } + + if (!field && !optional) + { + /* Field requested but we ran out if input. Bail out. */ + + goto parse_error; + } + + switch (type) + { + /* Single character field (char). */ + + case 'c': + { + char value = '\0'; + + if (field && minmea_isfield(*field)) + { + value = *field; + } + + *va_arg(ap, char *) = value; + } + break; + + /* Single character direction field (int). */ + + case 'd': + { + int value = 0; + + if (field && minmea_isfield(*field)) + { + switch (*field) + { + case 'N': + case 'E': + value = 1; + break; + + case 'S': + case 'W': + value = -1; + break; + + default: + goto parse_error; + } + } + + *va_arg(ap, int *) = value; + } + break; + + /* Fractional value with scale (struct minmea_float). */ + + case 'f': + { + int sign = 0; + int_least32_t value = -1; + int_least32_t scale = 0; + + if (field) + { + while (minmea_isfield(*field)) + { + if (*field == '+' && !sign && value == -1) + { + sign = 1; + } + else if (*field == '-' && !sign && value == -1) + { + sign = -1; + } + else if (isdigit((unsigned char) *field)) + { + int digit = *field - '0'; + + if (value == -1) + { + value = 0; + } + + if (value > (INT_LEAST32_MAX-digit) / 10) + { + /* we ran out of bits, what do we do? */ + + if (scale) + { + /* truncate extra precision */ + + break; + } + else + { + /* integer overflow. bail out. */ + + goto parse_error; + } + } + + value = (10 * value) + digit; + if (scale) + { + scale *= 10; + } + } + else if (*field == '.' && scale == 0) + { + scale = 1; + } + else if (*field == ' ') + { + /* Allow spaces at the start of the field. Not NMEA + * conformant, but some modules do this. + */ + + if (sign != 0 || value != -1 || scale != 0) + { + goto parse_error; + } + } + else + { + goto parse_error; + } + + field++; + } + } + + if ((sign || scale) && value == -1) + { + goto parse_error; + } + + if (value == -1) + { + /* No digits were scanned. */ + + value = 0; + scale = 0; + } + else if (scale == 0) + { + /* No decimal point. */ + + scale = 1; + } + + if (sign) + { + value *= sign; + } + + *va_arg(ap, struct minmea_float *) = + (struct minmea_float) {value, scale}; + } + break; + + /* Integer value, default 0 (int). */ + + case 'i': + { + int value = 0; + + if (field) + { + FAR char *endptr; + + value = strtol(field, &endptr, 10); + if (minmea_isfield(*endptr)) + { + goto parse_error; + } + } + + *va_arg(ap, int *) = value; + } + break; + + /* String value (char *). */ + + case 's': + { + char *buf = va_arg(ap, char *); + + if (field) + { + while (minmea_isfield(*field)) + { + *buf++ = *field++; + } + } + + *buf = '\0'; + } + break; + + /* NMEA talker+sentence identifier (char *). */ + + case 't': + { + char *buf; + int f; + + /* This field is always mandatory. */ + + if (!field) + { + goto parse_error; + } + + if (field[0] != '$') + { + goto parse_error; + } + + for (f = 0; f < 5; f++) + { + if (!minmea_isfield(field[1+f])) + { + goto parse_error; + } + } + + buf = va_arg(ap, char *); + memcpy(buf, field+1, 5); + buf[5] = '\0'; + } + break; + + /* Date (int, int, int), -1 if empty. */ + + case 'D': + { + struct minmea_date *date = va_arg(ap, struct minmea_date *); + int d = -1; + int m = -1; + int y = -1; + int f; + + if (field && minmea_isfield(*field)) + { + /* Always six digits. */ + + for (f = 0; f < 6; f++) + { + if (!isdigit((unsigned char) field[f])) + { + goto parse_error; + } + } + + d = strtol((char[]) {field[0], field[1], '\0'}, NULL, 10); + m = strtol((char[]) {field[2], field[3], '\0'}, NULL, 10); + y = strtol((char[]) {field[4], field[5], '\0'}, NULL, 10); + } + + date->day = d; + date->month = m; + date->year = y; + } + break; + + /* Time (int, int, int, int), -1 if empty. */ + + case 'T': + { + struct minmea_time *time_ = va_arg(ap, struct minmea_time *); + int h = -1; + int i = -1; + int s = -1; + int u = -1; + int f; + + if (field && minmea_isfield(*field)) + { + /* Minimum required: integer time. */ + + for (f = 0; f < 6; f++) + { + if (!isdigit((unsigned char) field[f])) + { + goto parse_error; + } + } + + h = strtol((char[]) {field[0], field[1], '\0'}, NULL, 10); + i = strtol((char[]) {field[2], field[3], '\0'}, NULL, 10); + s = strtol((char[]) {field[4], field[5], '\0'}, NULL, 10); + field += 6; + + /* Extra: fractional time. Saved as microseconds. */ + + if (*field++ == '.') + { + int value = 0; + int scale = 1000000; + + while (isdigit((unsigned char) *field) && scale > 1) + { + value = (value * 10) + (*field++ - '0'); + scale /= 10; + } + + u = value * scale; + } + else + { + u = 0; + } + } + + time_->hours = h; + time_->minutes = i; + time_->seconds = s; + time_->microseconds = u; + } + break; + + /* Ignore the field. */ + + case '_': + { + } + break; + + default: + { + goto parse_error; + } + break; + } + + next_field(); + } + + result = true; + +parse_error: + va_end(ap); + return result; +} + +bool minmea_talker_id(char talker[3], FAR const char *sentence) +{ + char type[6]; + + if (!minmea_scan(sentence, "t", type)) + { + return false; + } + + talker[0] = type[0]; + talker[1] = type[1]; + talker[2] = '\0'; + + return true; +} + +enum minmea_sentence_id minmea_sentence_id(FAR const char *sentence, + bool strict) +{ + if (!minmea_check(sentence, strict)) + return MINMEA_INVALID; + + char type[6]; + if (!minmea_scan(sentence, "t", type)) + { + return MINMEA_INVALID; + } + + if (!strcmp(type+2, "RMC")) + { + return MINMEA_SENTENCE_RMC; + } + + if (!strcmp(type+2, "GGA")) + { + return MINMEA_SENTENCE_GGA; + } + + if (!strcmp(type+2, "GSA")) + { + return MINMEA_SENTENCE_GSA; + } + + if (!strcmp(type+2, "GLL")) + { + return MINMEA_SENTENCE_GLL; + } + + if (!strcmp(type+2, "GST")) + { + return MINMEA_SENTENCE_GST; + } + + if (!strcmp(type+2, "GSV")) + { + return MINMEA_SENTENCE_GSV; + } + + return MINMEA_UNKNOWN; +} + +bool minmea_parse_rmc(FAR struct minmea_sentence_rmc *frame, + FAR const char *sentence) +{ + /* $GPRMC,081836,A,3751.65,S,14507.36,E,000.0,360.0,130998,011.3,E*62 */ + + char type[6]; + char validity; + int latitude_direction; + int longitude_direction; + int variation_direction; + + if (!minmea_scan(sentence, "tTcfdfdffDfd", + type, + &frame->time, + &validity, + &frame->latitude, &latitude_direction, + &frame->longitude, &longitude_direction, + &frame->speed, + &frame->course, + &frame->date, + &frame->variation, &variation_direction)) + { + return false; + } + + if (strcmp(type+2, "RMC")) + { + return false; + } + + frame->valid = (validity == 'A'); + frame->latitude.value *= latitude_direction; + frame->longitude.value *= longitude_direction; + frame->variation.value *= variation_direction; + + return true; +} + +bool minmea_parse_gga(FAR struct minmea_sentence_gga *frame, + FAR const char *sentence) +{ + /* $GPGGA,123519,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,*47 */ + + char type[6]; + int latitude_direction; + int longitude_direction; + + if (!minmea_scan(sentence, "tTfdfdiiffcfci_", + type, + &frame->time, + &frame->latitude, &latitude_direction, + &frame->longitude, &longitude_direction, + &frame->fix_quality, + &frame->satellites_tracked, + &frame->hdop, + &frame->altitude, &frame->altitude_units, + &frame->height, &frame->height_units, + &frame->dgps_age)) + { + return false; + } + + if (strcmp(type+2, "GGA")) + { + return false; + } + + frame->latitude.value *= latitude_direction; + frame->longitude.value *= longitude_direction; + + return true; +} + +bool minmea_parse_gsa(FAR struct minmea_sentence_gsa *frame, + FAR const char *sentence) +{ + /* $GPGSA,A,3,04,05,,09,12,,,24,,,,,2.5,1.3,2.1*39 */ + + char type[6]; + + if (!minmea_scan(sentence, "tciiiiiiiiiiiiifff", + type, + &frame->mode, + &frame->fix_type, + &frame->sats[0], + &frame->sats[1], + &frame->sats[2], + &frame->sats[3], + &frame->sats[4], + &frame->sats[5], + &frame->sats[6], + &frame->sats[7], + &frame->sats[8], + &frame->sats[9], + &frame->sats[10], + &frame->sats[11], + &frame->pdop, + &frame->hdop, + &frame->vdop)) + { + return false; + } + + if (strcmp(type+2, "GSA")) + { + return false; + } + + return true; +} + +bool minmea_parse_gll(FAR struct minmea_sentence_gll *frame, + FAR const char *sentence) +{ + /* $GPGLL,3723.2475,N,12158.3416,W,161229.487,A,A*41$; */ + + char type[6]; + int latitude_direction; + int longitude_direction; + + if (!minmea_scan(sentence, "tfdfdTc;c", + type, + &frame->latitude, &latitude_direction, + &frame->longitude, &longitude_direction, + &frame->time, + &frame->status, + &frame->mode)) + { + return false; + } + + if (strcmp(type+2, "GLL")) + { + return false; + } + + frame->latitude.value *= latitude_direction; + frame->longitude.value *= longitude_direction; + + return true; +} + +bool minmea_parse_gst(FAR struct minmea_sentence_gst *frame, + FAR const char *sentence) +{ + /* $GPGST,024603.00,3.2,6.6,4.7,47.3,5.8,5.6,22.0*58 */ + + char type[6]; + + if (!minmea_scan(sentence, "tTfffffff", + type, + &frame->time, + &frame->rms_deviation, + &frame->semi_major_deviation, + &frame->semi_minor_deviation, + &frame->semi_major_orientation, + &frame->latitude_error_deviation, + &frame->longitude_error_deviation, + &frame->altitude_error_deviation)) + { + return false; + } + + if (strcmp(type+2, "GST")) + { + return false; + } + + return true; +} + +bool minmea_parse_gsv(FAR struct minmea_sentence_gsv *frame, + FAR const char *sentence) +{ + /* $GPGSV,3,1,11,03,03,111,00,04,15,270,00,06,01,010,00,13,06,292,00*74 + * $GPGSV,3,3,11,22,42,067,42,24,14,311,43,27,05,244,00,,,,*4D + * $GPGSV,4,2,11,08,51,203,30,09,45,215,28*75 + * $GPGSV,4,4,13,39,31,170,27*40 + * $GPGSV,4,4,13*7B */ + + char type[6]; + + if (!minmea_scan(sentence, "tiii;iiiiiiiiiiiiiiii", + type, + &frame->total_msgs, + &frame->msg_nr, + &frame->total_sats, + &frame->sats[0].nr, + &frame->sats[0].elevation, + &frame->sats[0].azimuth, + &frame->sats[0].snr, + &frame->sats[1].nr, + &frame->sats[1].elevation, + &frame->sats[1].azimuth, + &frame->sats[1].snr, + &frame->sats[2].nr, + &frame->sats[2].elevation, + &frame->sats[2].azimuth, + &frame->sats[2].snr, + &frame->sats[3].nr, + &frame->sats[3].elevation, + &frame->sats[3].azimuth, + &frame->sats[3].snr)) + { + return false; + } + + if (strcmp(type+2, "GSV")) + { + return false; + } + + return true; +} + +int minmea_gettime(FAR struct timespec *ts, + FAR const struct minmea_date *date, + FAR const struct minmea_time *time_) +{ + struct tm tm; + + if (date->year == -1 || time_->hours == -1) + { + return -1; + } + + memset(&tm, 0, sizeof(tm)); + tm.tm_year = 2000 + date->year - 1900; + tm.tm_mon = date->month - 1; + tm.tm_mday = date->day; + tm.tm_hour = time_->hours; + tm.tm_min = time_->minutes; + tm.tm_sec = time_->seconds; + + /* See README.md if your system lacks timegm(). */ + + time_t timestamp = mktime(&tm); + if (timestamp != -1) + { + ts->tv_sec = timestamp; + ts->tv_nsec = time_->microseconds * 1000; + return 0; + } + else + { + return -1; + } +} diff --git a/graphics/CMakeLists.txt b/graphics/CMakeLists.txt deleted file mode 100644 index 15e14c695..000000000 --- a/graphics/CMakeLists.txt +++ /dev/null @@ -1,24 +0,0 @@ -# ############################################################################## -# apps/graphics/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## -nuttx_add_subdirectory() - -nuttx_generate_kconfig(MENUDESC "Graphics Support") diff --git a/graphics/Make.defs b/graphics/Make.defs index 43d73c068..2630b6d7c 100644 --- a/graphics/Make.defs +++ b/graphics/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/graphics/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/graphics/Makefile b/graphics/Makefile index 0e11d2d83..f9b719cf6 100644 --- a/graphics/Makefile +++ b/graphics/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/graphics/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/graphics/ft80x/Make.defs b/graphics/ft80x/Make.defs index 3c78e6a11..d78d1e366 100644 --- a/graphics/ft80x/Make.defs +++ b/graphics/ft80x/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/graphics/ft80x/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -20,6 +18,6 @@ # ############################################################################ -ifneq ($(CONFIG_GRAPHICS_FT80X),) +ifeq ($(CONFIG_GRAPHICS_FT80X),y) CONFIGURED_APPS += $(APPDIR)/graphics/ft80x endif diff --git a/graphics/ft80x/Makefile b/graphics/ft80x/Makefile index c0a5622f2..6da02b4de 100644 --- a/graphics/ft80x/Makefile +++ b/graphics/ft80x/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/graphics/ft80x/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/graphics/ft80x/ft80x.h b/graphics/ft80x/ft80x.h index 64254691c..d29978f94 100644 --- a/graphics/ft80x/ft80x.h +++ b/graphics/ft80x/ft80x.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/ft80x/ft80x.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -32,7 +30,7 @@ #include #include -#include +#include #ifdef CONFIG_GRAPHICS_FT80X diff --git a/graphics/ft80x/ft80x_audio.c b/graphics/ft80x/ft80x_audio.c index 455cc13f5..2cb342793 100644 --- a/graphics/ft80x/ft80x_audio.c +++ b/graphics/ft80x/ft80x_audio.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/ft80x/ft80x_audio.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/ft80x/ft80x_backlight.c b/graphics/ft80x/ft80x_backlight.c index c2f07196a..973f159ca 100644 --- a/graphics/ft80x/ft80x_backlight.c +++ b/graphics/ft80x/ft80x_backlight.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/ft80x/ft80x_backlight.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/ft80x/ft80x_coproc.c b/graphics/ft80x/ft80x_coproc.c index cde264331..8958eb08c 100644 --- a/graphics/ft80x/ft80x_coproc.c +++ b/graphics/ft80x/ft80x_coproc.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/ft80x/ft80x_coproc.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/ft80x/ft80x_dl.c b/graphics/ft80x/ft80x_dl.c index 60624b4ca..146f86e5b 100644 --- a/graphics/ft80x/ft80x_dl.c +++ b/graphics/ft80x/ft80x_dl.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/ft80x/ft80x_dl.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -359,8 +357,7 @@ int ft80x_dl_data(int fd, FAR struct ft80x_dlbuffer_s *buffer, size_t padlen; int ret; - ft80x_info("fd=%d buffer=%p data=%p datlen=%u\n", - fd, buffer, data, datlen); + ft80x_info("fd=%d buffer=%p data=%p datlen=%u\n", fd, buffer, data, datlen); DEBUGASSERT(fd >= 0 && buffer != NULL && data != NULL && datlen > 0); if (datlen > 0) @@ -444,7 +441,7 @@ int ft80x_dl_data(int fd, FAR struct ft80x_dlbuffer_s *buffer, bufptr += datlen; buffer->dloffset += datlen; - /* Then append zero bytes as necessary to achieve alignment */ + /* Then append zero bytes as necessary to achieve alignment */ while (datlen < padlen) { @@ -576,8 +573,7 @@ int ft80x_dl_string(int fd, FAR struct ft80x_dlbuffer_s *buffer, bufptr = (FAR uint8_t *)buffer->dlbuffer; bufptr += buffer->dloffset; - strlcpy((FAR char *)bufptr, str, - sizeof(buffer->dlbuffer) - buffer->dloffset); + strcpy((FAR char *)bufptr, str); /* NOTE: that strcpy will copy the NUL terminator too */ @@ -609,8 +605,8 @@ int ft80x_dl_string(int fd, FAR struct ft80x_dlbuffer_s *buffer, * hardware and reset the local display list buffer offset to zero. * * Input Parameters: - * fd - The file descriptor of the FT80x device. Opened by the caller - * with write access. + * fd - The file descriptor of the FT80x device. Opened by the caller with + * write access. * buffer - An instance of struct ft80x_dlbuffer_s allocated by the caller. * wait - True: wait until data has been consumed by the co-processor * (only for co-processor destination); false: Send to hardware diff --git a/graphics/ft80x/ft80x_gpio.c b/graphics/ft80x/ft80x_gpio.c index de5a6bbbf..ca5cfd099 100644 --- a/graphics/ft80x/ft80x_gpio.c +++ b/graphics/ft80x/ft80x_gpio.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/ft80x/ft80x_gpio.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -96,6 +94,7 @@ int ft80x_gpio_configure(int fd, uint8_t gpio, uint8_t dir, uint8_t drive, /* Set the pin direction */ + ret = ft80x_getreg8(fd, FT80X_REG_GPIO_DIR, ®val8); if (ret < 0) { diff --git a/graphics/ft80x/ft80x_ramcmd.c b/graphics/ft80x/ft80x_ramcmd.c index 69c13f7e3..cdfb77324 100644 --- a/graphics/ft80x/ft80x_ramcmd.c +++ b/graphics/ft80x/ft80x_ramcmd.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/ft80x/ft80x_ramcmd.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -32,7 +30,6 @@ #include #include #include -#include #include @@ -217,13 +214,10 @@ uint16_t ft80x_ramcmd_freespace(int fd, FAR uint16_t *offset, return ret; } - /* Return the free space in the FIFO. NOTE that 4 bytes are not - * available - */ + /* Return the free space in the FIFO. NOTE that 4 bytes are not available */ *offset = regs[1] & FT80X_CMDFIFO_MASK; - *avail = (FT80X_CMDFIFO_SIZE - 4) - - ((regs[1] - regs[0]) & FT80X_CMDFIFO_MASK); + *avail = (FT80X_CMDFIFO_SIZE - 4) - ((regs[1] - regs[0]) & FT80X_CMDFIFO_MASK); return OK; } @@ -276,9 +270,7 @@ int ft80x_ramcmd_waitfifoempty(int fd) for (; ; ) { - /* Read both the FT80X_REG_CMD_WRITE and FT80X_REG_CMD_READ - * registers. - */ + /* Read both the FT80X_REG_CMD_WRITE and FT80X_REG_CMD_READ registers. */ ret = ft80x_getregs(fd, FT80X_REG_CMD_READ, 2, regs); if (ret < 0) @@ -331,9 +323,7 @@ int ft80x_ramcmd_waitfifoempty(int fd) ioctl(fd, FT80X_IOC_EVENTNOTIFY, (unsigned long)((uintptr_t)¬ify)); - /* Check if the signal was received correctly or if the timeout - * occurred. - */ + /* Check if the signal was received correctly or if the timeout occurred. */ if (ret < 0) { diff --git a/graphics/ft80x/ft80x_ramdl.c b/graphics/ft80x/ft80x_ramdl.c index c2fc201b4..5d10550f6 100644 --- a/graphics/ft80x/ft80x_ramdl.c +++ b/graphics/ft80x/ft80x_ramdl.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/ft80x/ft80x_ramdl.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/ft80x/ft80x_ramg.c b/graphics/ft80x/ft80x_ramg.c index 3505c8eb0..891c40b14 100644 --- a/graphics/ft80x/ft80x_ramg.c +++ b/graphics/ft80x/ft80x_ramg.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/ft80x/ft80x_ramg.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/ft80x/ft80x_regs.c b/graphics/ft80x/ft80x_regs.c index bb3f68fa0..a811ae812 100644 --- a/graphics/ft80x/ft80x_regs.c +++ b/graphics/ft80x/ft80x_regs.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/ft80x/ft80x_regs.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -45,7 +43,7 @@ #define DLSWAP_DELAY_USEC (10 * 1000) -/* But timeout after 5 seconds (5 * 100 * 10 MS = 5 S) */ +/* But timeout after 5 seconds ( 5 * 100 * 10 MS = 5 S) */ #define DLSWAP_TIMEOUT_CSEC (5 * 100) diff --git a/graphics/ft80x/ft80x_touch.c b/graphics/ft80x/ft80x_touch.c index fac5d2013..0c497d772 100644 --- a/graphics/ft80x/ft80x_touch.c +++ b/graphics/ft80x/ft80x_touch.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/ft80x/ft80x_touch.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -31,7 +29,6 @@ #include #include #include -#include #include @@ -97,8 +94,7 @@ int ft80x_touch_gettransform(int fd, FAR uint32_t matrix[6]) * * Returned Value: * A value of 1-255 is returned if a graphics object is touched. Zero is - * returned if no graphics object is touched. A negated errno value on - * failure. + * returned if no graphics object is touched. A negated errno value on failure. * ****************************************************************************/ @@ -142,8 +138,7 @@ int ft80x_touch_tag(int fd) * * Returned Value: * A value of 1-255 is returned if a graphics object is touched. Zero is - * returned if no graphics object is touched. A negated errno value on - * failure. + * returned if no graphics object is touched. A negated errno value on failure. * ****************************************************************************/ @@ -229,9 +224,7 @@ int ft80x_touch_waittag(int fd, uint8_t oldtag) ioctl(fd, FT80X_IOC_EVENTNOTIFY, (unsigned long)((uintptr_t)¬ify)); - /* Check if the signal was received correctly or if the timeout - * occurred. - */ + /* Check if the signal was received correctly or if the timeout occurred. */ if (ret < 0) { @@ -268,8 +261,7 @@ int ft80x_touch_waittag(int fd, uint8_t oldtag) * * Returned Value: * A value of 1-255 is returned if a graphics object is touched. Zero is - * returned if no graphics object is touched. A negated errno value on - * failure. + * returned if no graphics object is touched. A negated errno value on failure. * ****************************************************************************/ diff --git a/graphics/input/CMakeLists.txt b/graphics/input/CMakeLists.txt deleted file mode 100644 index 8213d364a..000000000 --- a/graphics/input/CMakeLists.txt +++ /dev/null @@ -1,78 +0,0 @@ -# ############################################################################## -# apps/graphics/input/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_GRAPHICS_INPUT_GENERATOR) - nuttx_add_library(input_generator) - file(GLOB CSRCS generator/*.c) - list(REMOVE_ITEM CSRCS ${CMAKE_CURRENT_SOURCE_DIR}/generator/input.c) - target_sources(input_generator PRIVATE ${CSRCS}) -endif() - -if(CONFIG_GRAPHICS_INPUT_MONKEY) - file(GLOB MONKEY_SRCS monkey/*.c) - list(REMOVE_ITEM MONKEY_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/monkey/monkey_main.c) - set(SRCS monkey/monkey_main.c ${MONKEY_SRCS}) - - nuttx_add_application( - NAME - monkey - PRIORITY - ${CONFIG_GRAPHICS_INPUT_MONKEY_PRIORITY} - STACKSIZE - ${CONFIG_GRAPHICS_INPUT_MONKEY_STACKSIZE} - MODULE - ${CONFIG_GRAPHICS_INPUT_MONKEY} - DEPENDS - input_generator - SRCS - ${SRCS}) -endif() - -if(CONFIG_GRAPHICS_INPUT_TOOL) - nuttx_add_application( - MODULE - ${CONFIG_GRAPHICS_INPUT_TOOL} - NAME - input - STACKSIZE - ${CONFIG_GRAPHICS_INPUT_TOOL_STACKSIZE} - PRIORITY - ${CONFIG_GRAPHICS_INPUT_TOOL_PRIORITY} - DEPENDS - input_generator - SRCS - generator/input.c) -endif() - -if(CONFIG_GRAPHICS_INPUT_GETEVENT) - nuttx_add_application( - MODULE - ${CONFIG_GRAPHICS_INPUT_GETEVENT} - NAME - getevent - STACKSIZE - ${CONFIG_GRAPHICS_INPUT_GETEVENT_STACKSIZE} - PRIORITY - ${CONFIG_GRAPHICS_INPUT_GETEVENT_PRIORITY} - SRCS - getevent/getevent.c) -endif() diff --git a/graphics/input/Kconfig b/graphics/input/Kconfig deleted file mode 100644 index 7cda0c370..000000000 --- a/graphics/input/Kconfig +++ /dev/null @@ -1,97 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config GRAPHICS_INPUT_GENERATOR - bool - default n - ---help--- - This is a simple input generator library that can be used to - generate input events for testing graphics applications. - -menuconfig GRAPHICS_INPUT_MONKEY - tristate "Monkey test" - select UINPUT_TOUCH - select UINPUT_BUTTONS - select GRAPHICS_INPUT_GENERATOR - select LIBC_PRINT_EXTENSION - default n - -if GRAPHICS_INPUT_MONKEY - -config GRAPHICS_INPUT_MONKEY_PRIORITY - int "Task priority" - default 110 - -config GRAPHICS_INPUT_MONKEY_STACKSIZE - int "Stack size" - default 4096 - -config GRAPHICS_INPUT_MONKEY_REC_DIR_PATH - string "Recorder directory path" - default "/data/monkey" - -endif - -menuconfig GRAPHICS_INPUT_TOOL - tristate "Enable input tool" - default n - select UINPUT_TOUCH - select UINPUT_BUTTONS - select UINPUT_MOUSE - select GRAPHICS_INPUT_GENERATOR - ---help--- - Enable support for a command line input tool. - -if GRAPHICS_INPUT_TOOL - -config GRAPHICS_INPUT_TOOL_STACKSIZE - int "input stack size" - default DEFAULT_TASK_STACKSIZE - ---help--- - The size of stack allocated for the input task. - -config GRAPHICS_INPUT_TOOL_PRIORITY - int "input priority" - default 110 - ---help--- - The priority of the input task. - -endif # GRAPHICS_INPUT_TOOL - -menuconfig GRAPHICS_INPUT_GETEVENT - tristate "Enable getevent tool" - default n - ---help--- - The getevent is a command-line input event monitor. It - captures and displays real-time events from mouse, - touchscreen, and keyboard devices via the input subsystem. - - Use getevent to debug and verify input drivers, inspect - raw event data during device bring-up, or diagnose - input issues on a running system. It supports automatic - device detection in /dev as well as manual device path - specification. - -if GRAPHICS_INPUT_GETEVENT - -config GRAPHICS_INPUT_GETEVENT_STACKSIZE - int "getevent stack size" - default DEFAULT_TASK_STACKSIZE - ---help--- - The size of stack allocated for the getevent task. - -config GRAPHICS_INPUT_GETEVENT_PRIORITY - int "getevent priority" - default 100 - ---help--- - The priority of the getevent task. - -config GRAPHICS_INPUT_GETEVENT_DETAIL_INFO - bool "getevent detail info" - default n - ---help--- - Enable detailed information in getevent output. - -endif # GRAPHICS_INPUT_GETEVENT diff --git a/graphics/input/Make.defs b/graphics/input/Make.defs deleted file mode 100644 index 5931c7950..000000000 --- a/graphics/input/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/graphics/input/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_GRAPHICS_INPUT_GENERATOR)$(CONFIG_GRAPHICS_INPUT_GETEVENT),) -CONFIGURED_APPS += $(APPDIR)/graphics/input -endif diff --git a/graphics/input/Makefile b/graphics/input/Makefile deleted file mode 100644 index e0a974b51..000000000 --- a/graphics/input/Makefile +++ /dev/null @@ -1,65 +0,0 @@ -############################################################################ -# apps/graphics/input/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -ifneq ($(CONFIG_GRAPHICS_INPUT_GENERATOR),) -CSRCS = $(filter-out generator/input.c, $(wildcard generator/*.c)) -endif - -# Monkey test - -ifneq ($(CONFIG_GRAPHICS_INPUT_MONKEY),) -PROGNAME += monkey -PRIORITY += $(CONFIG_GRAPHICS_INPUT_MONKEY_PRIORITY) -STACKSIZE += $(CONFIG_GRAPHICS_INPUT_MONKEY_STACKSIZE) -MODULE += $(CONFIG_GRAPHICS_INPUT_MONKEY) - -MAINSRC += monkey/monkey_main.c - -CSRCS += $(filter-out monkey/monkey_main.c, $(wildcard monkey/*.c)) -endif - -# Input tool - -ifneq ($(CONFIG_GRAPHICS_INPUT_TOOL),) -PROGNAME += input -PRIORITY += $(CONFIG_GRAPHICS_INPUT_TOOL_PRIORITY) -STACKSIZE += $(CONFIG_GRAPHICS_INPUT_TOOL_STACKSIZE) -MODULE += $(CONFIG_GRAPHICS_INPUT_TOOL) - -MAINSRC += generator/input.c -endif - -# getevent tool - -ifneq ($(CONFIG_GRAPHICS_INPUT_GETEVENT),) -PROGNAME += getevent -PRIORITY += $(CONFIG_GRAPHICS_INPUT_GETEVENT_PRIORITY) -STACKSIZE += $(CONFIG_GRAPHICS_INPUT_GETEVENT_STACKSIZE) -MODULE += $(CONFIG_GRAPHICS_INPUT_GETEVENT) - -MAINSRC += getevent/getevent.c -CFLAGS += -Wno-discarded-qualifiers -endif - -include $(APPDIR)/Application.mk diff --git a/graphics/input/generator/input.c b/graphics/input/generator/input.c deleted file mode 100644 index a501acfdc..000000000 --- a/graphics/input/generator/input.c +++ /dev/null @@ -1,358 +0,0 @@ -/**************************************************************************** - * apps/graphics/input/generator/input.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define SWIPE_DEFAULT_DURATION 300 -#define DRAG_DEFAULT_DURATION 500 -#define BUTTON_LONGPRESS_DEFAULT_DURATION 1000 - -#define DELAY_MS(ms) usleep((ms) * 1000) -#define ABS(a) ((a) > 0 ? (a) : -(a)) - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -struct input_cmd_s -{ - /* Command name */ - - const char *cmd; - - /* Function corresponding to command */ - - int (*func)(input_gen_ctx_t ctx, int argc, char **argv); -}; - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -static int input_button(input_gen_ctx_t ctx, int argc, char **argv); -static int input_help(input_gen_ctx_t ctx, int argc, char **argv); -static int input_sleep(input_gen_ctx_t ctx, int argc, char **argv); -static int input_utouch_tap(input_gen_ctx_t ctx, int argc, char **argv); -static int input_utouch_swipe(input_gen_ctx_t ctx, int argc, char **argv); -static int input_wheel(input_gen_ctx_t ctx, int argc, char **argv); - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static const struct input_cmd_s g_input_cmd_list[] = -{ - {"help", input_help }, - {"sleep", input_sleep }, - {"tap", input_utouch_tap }, - {"swipe", input_utouch_swipe}, - {"drag", input_utouch_swipe}, - {"draganddrop", input_utouch_swipe}, - {"button", input_button }, - {"wheel", input_wheel }, - {NULL, NULL } -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: parse_arg_to_int16 - ****************************************************************************/ - -static int parse_arg_to_int16(const char *arg, int16_t *result) -{ - char *endptr; - long val; - - if (!arg || arg[0] == '\0') - { - return 1; - } - - errno = 0; - val = strtol(arg, &endptr, 10); - - if (errno != 0 || *endptr != '\0' || arg == endptr || - val < -32768 || val > 32767) - { - return 1; - } - - *result = (int16_t)val; - return 0; -} - -/**************************************************************************** - * Name: parse_arg_to_uint32 - ****************************************************************************/ - -static int parse_arg_to_uint32(const char *arg, uint32_t *result) -{ - char *endptr; - uintmax_t val; - - if (!arg || arg[0] == '\0') - { - return 1; - } - - errno = 0; - val = strtoumax(arg, &endptr, 0); - - if (errno != 0 || *endptr != '\0' || arg == endptr || val > UINT32_MAX) - { - return 1; - } - - *result = (uint32_t)val; - return 0; -} - -/**************************************************************************** - * Name: input_sleep - ****************************************************************************/ - -static int input_sleep(input_gen_ctx_t ctx, int argc, char **argv) -{ - if (argc != 2) - { - return -EINVAL; - } - - DELAY_MS(atoi(argv[1])); - return 0; -} - -/**************************************************************************** - * Name: input_utouch_tap - ****************************************************************************/ - -static int input_utouch_tap(input_gen_ctx_t ctx, int argc, char **argv) -{ - int16_t x; - int16_t y; - - if (argc != 3) - { - return -EINVAL; - } - - if (parse_arg_to_int16(argv[1], &x) || parse_arg_to_int16(argv[2], &y)) - { - return -EINVAL; - } - - return input_gen_tap(ctx, x, y); -} - -/**************************************************************************** - * Name: input_utouch_swipe - ****************************************************************************/ - -static int input_utouch_swipe(input_gen_ctx_t ctx, int argc, char **argv) -{ - int16_t x1; - int16_t x2; - int16_t y1; - int16_t y2; - bool is_swipe = strcmp(argv[0], "swipe") == 0; - uint32_t duration = is_swipe ? SWIPE_DEFAULT_DURATION - : DRAG_DEFAULT_DURATION; - - if (argc < 5 || argc > 6) - { - return -EINVAL; - } - - if (parse_arg_to_int16(argv[1], &x1) || parse_arg_to_int16(argv[3], &x2) || - parse_arg_to_int16(argv[2], &y1) || parse_arg_to_int16(argv[4], &y2)) - { - return -EINVAL; - } - - /* Number of times to calculate reports */ - - if (argc > 5) - { - if (parse_arg_to_uint32(argv[5], &duration)) - { - return -EINVAL; - } - } - - return is_swipe ? input_gen_swipe(ctx, x1, y1, x2, y2, duration) - : input_gen_drag(ctx, x1, y1, x2, y2, duration); -} - -/**************************************************************************** - * Name: input_button - ****************************************************************************/ - -static int input_button(input_gen_ctx_t ctx, int argc, char **argv) -{ - btn_buttonset_t button; - uint32_t duration = 0; - int result = -EINVAL; - - if (argc < 2 || argc > 3) - { - return result; - } - - if (parse_arg_to_uint32(argv[1], &button)) - { - return result; - } - - if (argc == 3) - { - if (parse_arg_to_uint32(argv[2], &duration)) - { - return -EINVAL; - } - } - - if (duration) - { - result = input_gen_button_longpress(ctx, button, duration); - } - else - { - result = input_gen_button_click(ctx, button); - } - - return result; -} - -/**************************************************************************** - * Name: input_wheel - ****************************************************************************/ - -static int input_wheel(input_gen_ctx_t ctx, int argc, char **argv) -{ - int16_t wheel; - - if (argc != 2) - { - return -EINVAL; - } - - if (parse_arg_to_int16(argv[1], &wheel)) - { - return -EINVAL; - } - - return input_gen_mouse_wheel(ctx, wheel); -} - -/**************************************************************************** - * Name: intput_help - ****************************************************************************/ - -static int input_help(input_gen_ctx_t ctx, int argc, char **argv) -{ - printf("Usage: input [...]\n"); - printf("The commands are:\n" - "\thelp\n" - "\tsleep \n" - "\ttap \n" - "\tswipe [duration(ms)]\n" - "\tdrag | draganddrop [duration(ms)]\n" - "\tbutton [duration(ms)]\n" - "\twheel \n" - "\tduration: Duration of sliding\n" - "\tbuttonvalue: button value in hex format\n" - ); - - return 0; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: input_main - * - * Description: - * Main entry point for the serial terminal example. - * - ****************************************************************************/ - -int main(int argc, char **argv) -{ - int i; - int ret = -EINVAL; - input_gen_ctx_t input_gen_ctx; - - if (argv[1] == NULL) - { - goto errout; - } - - if (input_gen_create(&input_gen_ctx, INPUT_GEN_DEV_ALL) < 0) - { - printf("Failed to create input generator\n"); - return EXIT_FAILURE; - } - - for (i = 0; g_input_cmd_list[i].cmd != NULL; i++) - { - /* Matching the function corresponding to the command */ - - if (strcmp(g_input_cmd_list[i].cmd, argv[1]) == 0) - { - ret = g_input_cmd_list[i].func(input_gen_ctx, argc - 1, &argv[1]); - break; - } - } - - if (input_gen_destroy(input_gen_ctx) < 0) - { - return EXIT_FAILURE; - } - -errout: - if (ret != 0) - { - input_help(NULL, argc, argv); - return EXIT_FAILURE; - } - - return EXIT_SUCCESS; -} diff --git a/graphics/input/generator/input_gen_ctx.c b/graphics/input/generator/input_gen_ctx.c deleted file mode 100644 index ea415e020..000000000 --- a/graphics/input/generator/input_gen_ctx.c +++ /dev/null @@ -1,304 +0,0 @@ -/**************************************************************************** - * apps/graphics/input/generator/input_gen_ctx.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include -#include -#include -#include - -#include "input_gen_internal.h" - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -struct input_gen_ctx_s -{ - struct input_gen_dev_s devs[INPUT_GEN_DEV_NUM]; -}; - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: input_gen_create - * - * Description: - * Create an input generator context. - * - * Input Parameters: - * ctx - A pointer to the input generator context, or NULL if the - * context failed to be created. - * devices - Device types to be opened. - * - * Returned Value: - * Success device count. On failure, a negated errno value is returned. - * - ****************************************************************************/ - -int input_gen_create(FAR input_gen_ctx_t *ctx, uint32_t devices) -{ - int success = 0; - int i; - - if (ctx == NULL || devices & ~INPUT_GEN_DEV_ALL) - { - gerr("ERROR: Invalid parameter: ctx=%p, devices=0x%08" PRIX32 "\n", - ctx, devices); - return -EINVAL; - } - - *ctx = (input_gen_ctx_t)zalloc(sizeof(struct input_gen_ctx_s)); - if (*ctx == NULL) - { - return -ENOMEM; - } - - /* Initialize the device context */ - - for (i = 0; i < INPUT_GEN_DEV_NUM; i++) - { - FAR struct input_gen_dev_s *dev = &(*ctx)->devs[i]; - input_gen_dev_t current = (1 << i); - - if (devices & current) - { - dev->fd = open(input_gen_dev2path(current), - O_WRONLY | O_NONBLOCK); - if (dev->fd < 0) - { - dev->device = INPUT_GEN_DEV_NONE; - gerr("ERROR: Open %s failed: %d\n", - input_gen_dev2path(current), errno); - continue; - } - - ginfo("Opened %s, fd = %d\n", - input_gen_dev2path(current), dev->fd); - dev->device = current; - success++; - } - else - { - dev->fd = -1; - dev->device = INPUT_GEN_DEV_NONE; - } - } - - ginfo("%d devices opened\n", success); - - if (success == 0) - { - free(*ctx); - *ctx = NULL; - return -ENODEV; - } - - return success; -} - -/**************************************************************************** - * Name: input_gen_destroy - * - * Description: - * Destroy an input generator context. - * - * Input Parameters: - * ctx - The input generator context to destroy. - * - * Returned Value: - * Zero (OK) is returned on success. On failure, a negated errno value is - * returned. - * - ****************************************************************************/ - -int input_gen_destroy(input_gen_ctx_t ctx) -{ - int i; - - if (ctx == NULL) - { - return -EINVAL; - } - - for (i = 0; i < INPUT_GEN_DEV_NUM; i++) - { - if (ctx->devs[i].fd >= 0) - { - ginfo("Closing %s, fd = %d\n", - input_gen_dev2path(ctx->devs[i].device), ctx->devs[i].fd); - close(ctx->devs[i].fd); - } - } - - free(ctx); - return OK; -} - -/**************************************************************************** - * Name: input_gen_search_dev - * - * Description: - * Get the input generator device by type. - * - * Input Parameters: - * ctx - The input generator context. - * device - The device type. - * - * Returned Value: - * A pointer to the input generator device structure, or NULL if not found. - * - ****************************************************************************/ - -FAR struct input_gen_dev_s *input_gen_search_dev(input_gen_ctx_t ctx, - input_gen_dev_t device) -{ - int i; - - if (ctx == NULL || device > INPUT_GEN_DEV_ALL) - { - return NULL; - } - - for (i = 0; i < INPUT_GEN_DEV_NUM; i++) - { - if (ctx->devs[i].device & device) - { - return &ctx->devs[i]; - } - } - - nwarn("WARNING: Device with type %d not found\n", device); - return NULL; -} - -/**************************************************************************** - * Name: input_gen_query_device - * - * Description: - * Query whether the device with the specified type is opened. - * - * Input Parameters: - * ctx - The input generator context. - * device - The device type. - * - * Returned Value: - * True if the device is opened, false otherwise. - * - ****************************************************************************/ - -bool input_gen_query_device(input_gen_ctx_t ctx, input_gen_dev_t device) -{ - return input_gen_search_dev(ctx, device) != NULL; -} - -/**************************************************************************** - * Name: input_gen_reset_devices - * - * Description: - * Reset the device state with the specified type. - * - * Input Parameters: - * ctx - The input generator context. - * devices - The device types to reset state. - * - * Returned Value: - * Zero (OK) is returned on success. On failure, a negated errno value is - * returned. - * - ****************************************************************************/ - -int input_gen_reset_devices(input_gen_ctx_t ctx, uint32_t devices) -{ - int ret; - - if (ctx == NULL) - { - return -EINVAL; - } - - /* Use actions with duration 0 to reset the device state */ - - if (devices & INPUT_GEN_DEV_UTOUCH) - { - ret = input_gen_swipe(ctx, 0, 0, 0, 0, 0); - if (ret < 0 && ret != -ENODEV) - { - return ret; - } - } - - if (devices & INPUT_GEN_DEV_UBUTTON) - { - ret = input_gen_button_longpress(ctx, 0, 0); - if (ret < 0 && ret != -ENODEV) - { - return ret; - } - } - - /* TODO: Reset keyboard when we support it. */ - - return OK; -} - -/**************************************************************************** - * Name: input_gen_write_raw - * - * Description: - * Write raw data to the device. - * - * Input Parameters: - * ctx - The input generator context. - * device - The device type. - * buf - The buffer to write. - * nbytes - The number of bytes to write. - * - * Returned Value: - * The number of bytes written, or a negated errno value on failure. - * - ****************************************************************************/ - -ssize_t input_gen_write_raw(input_gen_ctx_t ctx, input_gen_dev_t device, - FAR const void *buf, size_t nbytes) -{ - FAR struct input_gen_dev_s *dev = input_gen_search_dev(ctx, device); - ssize_t ret; - - if (dev == NULL) - { - gerr("ERROR: Device with type %d not found\n", device); - return -ENODEV; - } - - ret = write(dev->fd, buf, nbytes); - return ret < 0 ? -errno : ret; -} diff --git a/graphics/input/generator/input_gen_dev.c b/graphics/input/generator/input_gen_dev.c deleted file mode 100644 index 9c921107c..000000000 --- a/graphics/input/generator/input_gen_dev.c +++ /dev/null @@ -1,228 +0,0 @@ -/**************************************************************************** - * apps/graphics/input/generator/input_gen_dev.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include - -#include - -#include "input_gen_internal.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define INPUT_GEN_DEV_PATH_UTOUCH "/dev/utouch" -#define INPUT_GEN_DEV_PATH_UBUTTON "/dev/ubutton" -#define INPUT_GEN_DEV_PATH_UMOUSE "/dev/umouse" -#define INPUT_GEN_DEV_PATH_UKEYBOARD "/dev/ukeyboard" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: input_gen_dev2path - * - * Description: - * Convert device type to device path. - * - * Input Parameters: - * device - Device type - * - * Returned Value: - * Device path string. - * - ****************************************************************************/ - -FAR const char *input_gen_dev2path(input_gen_dev_t device) -{ - switch (device) - { - case INPUT_GEN_DEV_UTOUCH: - return INPUT_GEN_DEV_PATH_UTOUCH; - case INPUT_GEN_DEV_UBUTTON: - return INPUT_GEN_DEV_PATH_UBUTTON; - case INPUT_GEN_DEV_UMOUSE: - return INPUT_GEN_DEV_PATH_UMOUSE; - case INPUT_GEN_DEV_UKEYBOARD: - return INPUT_GEN_DEV_PATH_UKEYBOARD; - default: - gerr("ERROR: Invalid device type: %d\n", device); - return ""; - } -} - -/**************************************************************************** - * Name: input_gen_utouch_write - * - * Description: - * Write touch sample to the device. - * - * Input Parameters: - * fd - File descriptor of the device - * sample - Pointer to the touch sample structure - * - * Returned Value: - * Zero (OK) is returned on success. On failure, a negated errno value is - * returned. - * - ****************************************************************************/ - -int input_gen_utouch_write(int fd, FAR const struct touch_sample_s *sample) -{ - size_t nbytes = SIZEOF_TOUCH_SAMPLE_S(sample->npoints); - ssize_t ret = write(fd, sample, nbytes); - - if (ret != nbytes) - { - gerr("ERROR: utouch_write failed: nbytes = %zu, ret = %zd, error = %d," - " data = %d points, first at x = %d, y = %d, pressure = %u\n", - nbytes, ret, errno, sample->npoints, sample->point[0].x, - sample->point[0].y, sample->point[0].pressure); - return ret < 0 ? -errno : -EIO; - } - - ginfo("utouch_write: %d points, first at x = %d, y = %d, pressure = %u\n", - sample->npoints, sample->point[0].x, sample->point[0].y, - sample->point[0].pressure); - return OK; -} - -/**************************************************************************** - * Name: input_gen_ubutton_write - * - * Description: - * Write button state to the device. - * - * Input Parameters: - * fd - File descriptor of the device - * mask - Button mask - * - * Returned Value: - * Zero (OK) is returned on success. On failure, a negated errno value is - * returned. - * - ****************************************************************************/ - -int input_gen_ubutton_write(int fd, btn_buttonset_t mask) -{ - ssize_t ret = write(fd, &mask, sizeof(mask)); - - if (ret != sizeof(mask)) - { - gerr("ERROR: ubutton_write failed: %zd, error = %d\n", ret, errno); - return ret < 0 ? -errno : -EIO; - } - - ginfo("ubutton_write: mask = 0x%08" PRIX32 "\n", mask); - return OK; -} - -/**************************************************************************** - * Name: input_gen_umouse_write - * - * Description: - * Write mouse wheel state to the device. - * - * Input Parameters: - * fd - File descriptor of the device - * wheel - Mouse wheel value - * - * Returned Value: - * Zero (OK) is returned on success. On failure, a negated errno value is - * returned. - * - ****************************************************************************/ - -#ifdef CONFIG_INPUT_MOUSE_WHEEL -int input_gen_umouse_write(int fd, int16_t wheel) -{ - struct mouse_report_s sample; - ssize_t ret; - - memset(&sample, 0, sizeof(sample)); - sample.wheel = wheel; - - ret = write(fd, &sample, sizeof(sample)); - if (ret != sizeof(sample)) - { - gerr("ERROR: umouse_write failed: %zd, error = %d\n", ret, errno); - return ret < 0 ? -errno : -EIO; - } - - ginfo("umouse_write: wheel = %d\n", wheel); - return OK; -} -#endif - -/**************************************************************************** - * Name: input_gen_grab / input_gen_ungrab - * - * Description: - * Grab or ungrab the input device. - * - * Input Parameters: - * dev - The input generator device. - * - * Returned Value: - * Zero (OK) is returned on success. On failure, a negated errno value is - * returned. - * - ****************************************************************************/ - -int input_gen_grab(FAR struct input_gen_dev_s *dev) -{ -/* Note: We use flock instead of GRAB ioctl because GRAB will block user - * programs like LVGL from receiving events from the device. - */ - -#if CONFIG_FS_LOCK_BUCKET_SIZE > 0 - if (flock(dev->fd, LOCK_EX | LOCK_NB) < 0) - { - gerr("ERROR: input_gen_grab failed: %d\n", errno); - return -errno; - } -#endif - - return OK; -} - -int input_gen_ungrab(FAR struct input_gen_dev_s *dev) -{ -#if CONFIG_FS_LOCK_BUCKET_SIZE > 0 - if (flock(dev->fd, LOCK_UN) < 0) - { - gerr("ERROR: input_gen_ungrab failed: %d\n", errno); - return -errno; - } -#endif - - return OK; -} diff --git a/graphics/input/generator/input_gen_event.c b/graphics/input/generator/input_gen_event.c deleted file mode 100644 index 51219d51b..000000000 --- a/graphics/input/generator/input_gen_event.c +++ /dev/null @@ -1,578 +0,0 @@ -/**************************************************************************** - * apps/graphics/input/generator/input_gen_event.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include - -#include "input_gen_internal.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define INPUT_GEN_DEFAULT_PRESSURE 42 - -#define INPUT_GEN_DEFAULT_PRESS_DURATION 50 /* ms */ -#define INPUT_GEN_DEFAULT_HOLD_DURATION 5 /* ms */ - -#define INPUT_GEN_DEFAULT_CLICK_DURATION 100 /* ms */ - -#define INPUT_GEN_MAX_FINGERS 2 - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/* Structure to hold parameters for single finger operations, we can support - * multiple fingers by using multiple instances of this structure. - */ - -struct input_gen_single_finger_s -{ - int16_t x1; - int16_t y1; - int16_t x2; - int16_t y2; - uint32_t press_duration; - uint32_t move_duration; - uint32_t hold_duration; -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: input_gen_tick_get - * - * Description: - * Get the current tick count in milliseconds. - * - * Returned Value: - * The current tick count in milliseconds. - * - ****************************************************************************/ - -static uint32_t input_gen_tick_get(void) -{ - struct timespec ts; - uint32_t ms; - - clock_gettime(CLOCK_MONOTONIC, &ts); - ms = ts.tv_sec * 1000 + ts.tv_nsec / 1000000; - - return ms; -} - -/**************************************************************************** - * Name: input_gen_tick_elapsed - * - * Description: - * Calculate the elapsed time in milliseconds since the last tick. - * - * Input Parameters: - * act_time - The current tick count. - * prev_tick - The previous tick count. - * - * Returned Value: - * The elapsed time in milliseconds. - * - ****************************************************************************/ - -static uint32_t input_gen_tick_elapsed(uint32_t act_time, uint32_t prev_tick) -{ - /* If there is no overflow in sys_time simple subtract */ - - if (act_time >= prev_tick) - { - prev_tick = act_time - prev_tick; - } - else - { - prev_tick = UINT32_MAX - prev_tick + 1; - prev_tick += act_time; - } - - return prev_tick; -} - -/**************************************************************************** - * Name: input_gen_single_finger - * - * Description: - * Calculate the position of a single finger based on the elapsed time and - * the parameters. - * - * Input Parameters: - * point - The touch point structure to fill in. - * finger - The parameters for the single finger operation. - * elapsed - The elapsed time since the start of the operation. - * - * Returned Value: - * True if the operation is finished, false otherwise. - * - ****************************************************************************/ - -static bool -input_gen_single_finger(FAR struct touch_point_s *point, - FAR const struct input_gen_single_finger_s *finger, - uint32_t elapsed) -{ - if (elapsed < finger->press_duration) - { - /* Press */ - - input_gen_fill_point(point, finger->x1, finger->y1, TOUCH_DOWN); - return false; - } - - elapsed -= finger->press_duration; - if (elapsed < finger->move_duration) - { - int16_t x = ((int64_t)(finger->x2 - finger->x1) * elapsed) / - finger->move_duration + finger->x1; - int16_t y = ((int64_t)(finger->y2 - finger->y1) * elapsed) / - finger->move_duration + finger->y1; - input_gen_fill_point(point, x, y, TOUCH_MOVE); - - return false; - } - - elapsed -= finger->move_duration; - if (elapsed < finger->hold_duration) - { - /* Hold */ - - input_gen_fill_point(point, finger->x2, finger->y2, TOUCH_DOWN); - return false; - } - - /* Release */ - - input_gen_fill_point(point, finger->x2, finger->y2, TOUCH_UP); - return true; -} - -/**************************************************************************** - * Name: input_gen_write_motion - * - * Description: - * Write a motion event to the device. - * - * Input Parameters: - * fd - The file descriptor of the device. - * fingers - The parameters for the motion operation. - * nfingers - The number of fingers. - * elapsed - The elapsed time since the start of the operation. - * - * Returned Value: - * Zero (OK) is returned on success. On failure, a negated errno value is - * returned. - * - ****************************************************************************/ - -static int input_gen_write_motion(int fd, - FAR const struct input_gen_single_finger_s *fingers, - size_t nfingers, uint32_t elapsed) -{ - size_t finished = 0; - size_t i; - int ret; - union /* A union with enough space to make compiler / checker happy. */ - { - struct touch_sample_s sample; - struct - { - uint8_t placeholder[offsetof(struct touch_sample_s, point)]; - struct touch_point_s point[INPUT_GEN_MAX_FINGERS]; - } points; - } buffer; - - /* Check the number of fingers */ - - if (nfingers < 1 || nfingers > INPUT_GEN_MAX_FINGERS) - { - return -EINVAL; - } - - /* Fill the touch sample structure */ - - buffer.sample.npoints = nfingers; - - for (i = 0; i < nfingers; i++) - { - FAR struct touch_point_s *point = &buffer.points.point[i]; - - point->id = i; - if (input_gen_single_finger(point, &fingers[i], elapsed)) - { - finished++; - } - - ginfo("Finger %zu: x = %d, y = %d, flags = %02X\n", - i, point->x, point->y, point->flags); - } - - /* Write the sample to the device */ - - ret = input_gen_utouch_write(fd, &buffer.sample); - if (ret < 0) - { - return ret; - } - - return finished == nfingers ? OK : -EAGAIN; -} - -/**************************************************************************** - * Name: input_gen_motion - * - * Description: - * Perform a motion operation. - * - * Input Parameters: - * ctx - The input generator context. - * fingers - The parameters for the motion operation. - * nfingers - The number of fingers. - * - * Returned Value: - * Zero (OK) is returned on success. On failure, a negated errno value is - * returned. - * - ****************************************************************************/ - -static int input_gen_motion(input_gen_ctx_t ctx, - FAR const struct input_gen_single_finger_s *fingers, - size_t nfingers) -{ - FAR struct input_gen_dev_s *dev; - uint32_t start; - int ret; - - dev = input_gen_search_dev(ctx, INPUT_GEN_DEV_UTOUCH); - if (dev == NULL) - { - return -ENODEV; - } - - ret = input_gen_grab(dev); - if (ret < 0) - { - return ret; - } - - start = input_gen_tick_get(); - - do - { - uint32_t elapsed = input_gen_tick_elapsed(input_gen_tick_get(), start); - ret = input_gen_write_motion(dev->fd, fingers, nfingers, elapsed); - if (ret == -EAGAIN && usleep(8 * 1000) < 0) - { - nwarn("WARNING: Maybe interrupted by signal\n"); - input_gen_ungrab(dev); - return -errno; - } - } - while (ret == -EAGAIN); - - input_gen_ungrab(dev); - return ret; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: input_gen_tap - * - * Description: - * Perform a tap operation. - * - * Input Parameters: - * ctx - The input generator context. - * x - The x coordinate. - * y - The y coordinate. - * - * Returned Value: - * Zero (OK) is returned on success. On failure, a negated errno value is - * returned. - * - ****************************************************************************/ - -int input_gen_tap(input_gen_ctx_t ctx, int16_t x, int16_t y) -{ - struct input_gen_single_finger_s finger = - { - .x1 = x, - .y1 = y, - .x2 = x, - .y2 = y, - .press_duration = INPUT_GEN_DEFAULT_PRESS_DURATION, - .move_duration = 0, - .hold_duration = 0, - }; - - return input_gen_motion(ctx, &finger, 1); -} - -/**************************************************************************** - * Name: input_gen_drag / input_gen_swipe - * - * Description: - * Perform a drag or swipe operation. - * - * Input Parameters: - * ctx - The input generator context. - * x1 - The start x coordinate. - * y1 - The start y coordinate. - * x2 - The end x coordinate. - * y2 - The end y coordinate. - * duration - The duration of the operation. - * - * Returned Value: - * Zero (OK) is returned on success. On failure, a negated errno value is - * returned. - * - ****************************************************************************/ - -int input_gen_drag(input_gen_ctx_t ctx, int16_t x1, int16_t y1, - int16_t x2, int16_t y2, uint32_t duration) -{ - struct input_gen_single_finger_s finger = - { - .x1 = x1, - .y1 = y1, - .x2 = x2, - .y2 = y2, - .press_duration = INPUT_GEN_DEFAULT_PRESS_DURATION, - .move_duration = duration, - .hold_duration = INPUT_GEN_DEFAULT_HOLD_DURATION, - }; - - return input_gen_motion(ctx, &finger, 1); -} - -int input_gen_swipe(input_gen_ctx_t ctx, int16_t x1, int16_t y1, - int16_t x2, int16_t y2, uint32_t duration) -{ - struct input_gen_single_finger_s finger = - { - .x1 = x1, - .y1 = y1, - .x2 = x2, - .y2 = y2, - .press_duration = 0, - .move_duration = duration, - .hold_duration = 0, - }; - - return input_gen_motion(ctx, &finger, 1); -} - -/**************************************************************************** - * Name: input_gen_pinch - * - * Description: - * Perform a pinch operation. - * - * Input Parameters: - * ctx - The input generator context. - * x1_start - The start x coordinate of the first finger. - * y1_start - The start y coordinate of the first finger. - * x2_start - The start x coordinate of the second finger. - * y2_start - The start y coordinate of the second finger. - * x1_end - The end x coordinate of the first finger. - * y1_end - The end y coordinate of the first finger. - * x2_end - The end x coordinate of the second finger. - * y2_end - The end y coordinate of the second finger. - * duration - The duration of the operation. - * - * Returned Value: - * Zero (OK) is returned on success. On failure, a negated errno value is - * returned. - * - ****************************************************************************/ - -int input_gen_pinch(input_gen_ctx_t ctx, int16_t x1_start, int16_t y1_start, - int16_t x2_start, int16_t y2_start, int16_t x1_end, - int16_t y1_end, int16_t x2_end, int16_t y2_end, - uint32_t duration) -{ - struct input_gen_single_finger_s fingers[2] = - { - { - .x1 = x1_start, - .y1 = y1_start, - .x2 = x1_end, - .y2 = y1_end, - .press_duration = INPUT_GEN_DEFAULT_PRESS_DURATION, - .move_duration = duration, - .hold_duration = INPUT_GEN_DEFAULT_HOLD_DURATION, - }, - { - .x1 = x2_start, - .y1 = y2_start, - .x2 = x2_end, - .y2 = y2_end, - .press_duration = INPUT_GEN_DEFAULT_PRESS_DURATION, - .move_duration = duration, - .hold_duration = INPUT_GEN_DEFAULT_HOLD_DURATION, - }, - }; - - return input_gen_motion(ctx, fingers, 2); -} - -/**************************************************************************** - * Name: input_gen_button_click / input_gen_button_longpress - * - * Description: - * Perform a button click or long press operation. - * - * Input Parameters: - * ctx - The input generator context. - * mask - The button mask. - * duration - The duration of the operation. - * - * Returned Value: - * Zero (OK) is returned on success. On failure, a negated errno value is - * returned. - * - ****************************************************************************/ - -int input_gen_button_click(input_gen_ctx_t ctx, btn_buttonset_t mask) -{ - return input_gen_button_longpress(ctx, mask, - INPUT_GEN_DEFAULT_CLICK_DURATION); -} - -int input_gen_button_longpress(input_gen_ctx_t ctx, btn_buttonset_t mask, - uint32_t duration) -{ - FAR struct input_gen_dev_s *dev; - int ret; - - dev = input_gen_search_dev(ctx, INPUT_GEN_DEV_UBUTTON); - if (dev == NULL) - { - return -ENODEV; - } - - ret = input_gen_grab(dev); - if (ret < 0) - { - return ret; - } - - ret = input_gen_ubutton_write(dev->fd, mask); - if (ret < 0) - { - goto out; - } - - usleep(duration * 1000); - - ret = input_gen_ubutton_write(dev->fd, 0); - if (ret < 0) - { - goto out; - } - -out: - input_gen_ungrab(dev); - return ret; -} - -/**************************************************************************** - * Name: input_gen_mouse_wheel - * - * Description: - * Perform a mouse wheel operation. - * - * Input Parameters: - * ctx - The input generator context. - * wheel - The wheel value. - * - * Returned Value: - * Zero (OK) is returned on success. On failure, a negated errno value is - * returned. - * - ****************************************************************************/ - -#ifdef CONFIG_INPUT_MOUSE_WHEEL -int input_gen_mouse_wheel(input_gen_ctx_t ctx, int16_t wheel) -{ - FAR struct input_gen_dev_s *dev; - - dev = input_gen_search_dev(ctx, INPUT_GEN_DEV_UMOUSE); - if (dev == NULL) - { - return -ENODEV; - } - - return input_gen_umouse_write(dev->fd, wheel); -} -#endif - -/**************************************************************************** - * Name: input_gen_fill_point - * - * Description: - * Fill the touch point structure. - * - * Input Parameters: - * point - The touch point structure. - * x - The x coordinate. - * y - The y coordinate. - * flags - The TOUCH_DOWN, TOUCH_MOVE, TOUCH_UP flag. - * - ****************************************************************************/ - -void input_gen_fill_point(FAR struct touch_point_s *point, - int16_t x, int16_t y, uint8_t flags) -{ - point->x = x; - point->y = y; - point->h = 1; - point->w = 1; - - if (flags & TOUCH_UP) - { - point->pressure = 0; - point->flags = flags | TOUCH_ID_VALID; - } - else - { - point->pressure = INPUT_GEN_DEFAULT_PRESSURE; - point->flags = flags | TOUCH_ID_VALID | TOUCH_POS_VALID | - TOUCH_PRESSURE_VALID; - } -} diff --git a/graphics/input/generator/input_gen_internal.h b/graphics/input/generator/input_gen_internal.h deleted file mode 100644 index 8fadec865..000000000 --- a/graphics/input/generator/input_gen_internal.h +++ /dev/null @@ -1,174 +0,0 @@ -/**************************************************************************** - * apps/graphics/input/generator/input_gen_internal.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __APPS_GRAPHICS_INPUT_GENERATOR_INPUT_GEN_INTERNAL_H -#define __APPS_GRAPHICS_INPUT_GENERATOR_INPUT_GEN_INTERNAL_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -struct input_gen_dev_s -{ - int fd; - input_gen_dev_t device; -}; - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -#undef EXTERN -#if defined(__cplusplus) -#define EXTERN extern "C" -extern "C" -{ -#else -#define EXTERN extern -#endif - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Name: input_gen_search_dev - * - * Description: - * Get the input generator device by type. - * - * Input Parameters: - * ctx - The input generator context. - * device - The device type. - * - * Returned Value: - * A pointer to the input generator device structure, or NULL if not found. - * - ****************************************************************************/ - -FAR struct input_gen_dev_s *input_gen_search_dev(input_gen_ctx_t ctx, - input_gen_dev_t device); - -/**************************************************************************** - * Name: input_gen_dev2path - * - * Description: - * Convert device type to device path. - * - * Input Parameters: - * device - Device type - * - * Returned Value: - * Device path string. - * - ****************************************************************************/ - -FAR const char *input_gen_dev2path(input_gen_dev_t device); - -/**************************************************************************** - * Name: input_gen_utouch_write - * - * Description: - * Write touch sample to the device. - * - * Input Parameters: - * fd - File descriptor of the device - * sample - Pointer to the touch sample structure - * - * Returned Value: - * Zero (OK) is returned on success. On failure, a negated errno value is - * returned. - * - ****************************************************************************/ - -int input_gen_utouch_write(int fd, FAR const struct touch_sample_s *sample); - -/**************************************************************************** - * Name: input_gen_ubutton_write - * - * Description: - * Write button state to the device. - * - * Input Parameters: - * fd - File descriptor of the device - * mask - Button mask - * - * Returned Value: - * Zero (OK) is returned on success. On failure, a negated errno value is - * returned. - * - ****************************************************************************/ - -int input_gen_ubutton_write(int fd, btn_buttonset_t mask); - -/**************************************************************************** - * Name: input_gen_umouse_write - * - * Description: - * Write mouse wheel state to the device. - * - * Input Parameters: - * fd - File descriptor of the device - * wheel - Mouse wheel value - * - * Returned Value: - * Zero (OK) is returned on success. On failure, a negated errno value is - * returned. - * - ****************************************************************************/ - -#ifdef CONFIG_INPUT_MOUSE_WHEEL -int input_gen_umouse_write(int fd, int16_t wheel); -#endif - -/**************************************************************************** - * Name: input_gen_grab / input_gen_ungrab - * - * Description: - * Grab or ungrab the input device. - * - * Input Parameters: - * dev - The input generator device. - * - * Returned Value: - * Zero (OK) is returned on success. On failure, a negated errno value is - * returned. - * - ****************************************************************************/ - -int input_gen_grab(FAR struct input_gen_dev_s *dev); -int input_gen_ungrab(FAR struct input_gen_dev_s *dev); - -#undef EXTERN -#if defined(__cplusplus) -} -#endif - -#endif /* __APPS_GRAPHICS_INPUT_GENERATOR_INPUT_GEN_INTERNAL_H */ diff --git a/graphics/input/getevent/getevent.c b/graphics/input/getevent/getevent.c deleted file mode 100644 index c70f90d47..000000000 --- a/graphics/input/getevent/getevent.c +++ /dev/null @@ -1,562 +0,0 @@ -/**************************************************************************** - * apps/graphics/input/getevent/getevent.c - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define GETEVENT_INFO(format, ...) \ - printf("[getevent]: " format, ##__VA_ARGS__) - -#define GETEVENT_ERR(format, ...) \ - fprintf(stderr, "[getevent]: " format, ##__VA_ARGS__) - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -struct input_device_s; - -typedef CODE int (*input_init_cb)(FAR struct input_device_s *); -typedef CODE void (*input_read_cb)(FAR struct input_device_s *); - -struct touch_priv_s -{ - uint8_t maxpoint; - struct touch_sample_s sample[]; -}; - -struct input_device_s -{ - int fd; - input_init_cb init_cb; - input_read_cb read_cb; - FAR void *priv; - FAR struct input_device_s *next; - char path[]; -}; - -struct input_devices_ctx_s -{ - FAR struct input_device_s *head; -}; - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: open_device - ****************************************************************************/ - -static int open_device(FAR struct input_device_s *dev) -{ - GETEVENT_INFO("opening %s\n", dev->path); - dev->fd = open(dev->path, O_RDONLY | O_NONBLOCK | O_CLOEXEC); - - if (dev->fd < 0) - { - GETEVENT_ERR("open %s failed, errno: %d\n", dev->path, errno); - return -errno; - } - - if (dev->init_cb) - { - return dev->init_cb(dev); - } - - return 0; -} - -/**************************************************************************** - * Name: touch_init - ****************************************************************************/ - -static int touch_init(FAR struct input_device_s *dev) -{ - FAR struct touch_priv_s *priv; - uint8_t maxpoint; - int ret; - - ret = ioctl(dev->fd, TSIOC_GETMAXPOINTS, &maxpoint); - if (ret < 0) - { - GETEVENT_ERR("ioctl GETMAXPOINTS failed: %d, " - "errno: %d\n", ret, errno); - return -errno; - } - - priv = calloc(1, sizeof(struct touch_priv_s) + - SIZEOF_TOUCH_SAMPLE_S(maxpoint)); - if (!priv) - { - GETEVENT_ERR("Memory allocation failed for touch_priv_s\n"); - return -ENOMEM; - } - - priv->maxpoint = maxpoint; - dev->priv = priv; - GETEVENT_INFO("ioctl TSIOC_GETMAXPOINTS: %d\n", maxpoint); - return ret; -} - -/**************************************************************************** - * Name: read_mouse_event - ****************************************************************************/ - -static void read_mouse_event(FAR struct input_device_s *dev) -{ - struct mouse_report_s sample; - ssize_t nbytes; - - /* Read one sample */ - - nbytes = read(dev->fd, &sample, sizeof(struct mouse_report_s)); - - /* Print the sample data on successful return */ - - if (nbytes == sizeof(struct mouse_report_s)) - { - GETEVENT_INFO("mouse event: %s\n", dev->path); - GETEVENT_INFO(" buttons : %02" PRIx8 "\n", sample.buttons); - GETEVENT_INFO(" x : %d\n", sample.x); - GETEVENT_INFO(" y : %d\n", sample.y); -#ifdef CONFIG_INPUT_MOUSE_WHEEL - GETEVENT_INFO(" wheel : %d\n", sample.wheel); -#endif - } -} - -/**************************************************************************** - * Name: read_touch_event - ****************************************************************************/ - -static void read_touch_event(FAR struct input_device_s *dev) -{ - FAR struct touch_priv_s *priv = (FAR struct touch_priv_s *)dev->priv; - ssize_t nbytes; - size_t i; - - /* Read one sample */ - - nbytes = read(dev->fd, priv->sample, - SIZEOF_TOUCH_SAMPLE_S(priv->maxpoint)); - - /* Print the sample data on successful return */ - - if (nbytes == SIZEOF_TOUCH_SAMPLE_S(priv->maxpoint)) - { - GETEVENT_INFO("touch event: %s\n", dev->path); - GETEVENT_INFO(" npoints : %" PRId32 "\n", priv->sample->npoints); - for (i = 0; i < priv->maxpoint; i++) - { - if (priv->sample->point[i].flags == 0) - { - break; - } - - GETEVENT_INFO("Point : %d\n", priv->sample->point[i].id); - GETEVENT_INFO(" flags : %02x\n", priv->sample->point[i].flags); - GETEVENT_INFO(" x : %d\n", priv->sample->point[i].x); - GETEVENT_INFO(" y : %d\n", priv->sample->point[i].y); -#ifdef CONFIG_GRAPHICS_INPUT_GETEVENT_DETAIL_INFO - GETEVENT_INFO(" h : %d\n", priv->sample->point[i].h); - GETEVENT_INFO(" w : %d\n", priv->sample->point[i].w); - GETEVENT_INFO(" pressure : %d\n", - priv->sample->point[i].pressure); -#endif - GETEVENT_INFO(" timestamp : %" PRIu64"\n", - priv->sample->point[i].timestamp); - } - } -} - -/**************************************************************************** - * Name: read_keyboard_event - ****************************************************************************/ - -static void read_keyboard_event(FAR struct input_device_s *dev) -{ - struct keyboard_event_s sample; - ssize_t nbytes; - - /* Read one sample */ - - nbytes = read(dev->fd, &sample, sizeof(struct keyboard_event_s)); - - /* Print the sample data on successful return */ - - if (nbytes == sizeof(struct keyboard_event_s)) - { - GETEVENT_INFO("keyboard event: %s\n", dev->path); - GETEVENT_INFO(" type : %" PRIu32 "\n", sample.type); - GETEVENT_INFO(" code : %" PRIu32 "\n", sample.code); - } -} - -/**************************************************************************** - * Name: cleanup_input_devices - ****************************************************************************/ - -static void cleanup_input_devices(FAR struct input_devices_ctx_s *ctx) -{ - FAR struct input_device_s *dev = ctx->head; - FAR struct input_device_s *next; - - while (dev) - { - next = dev->next; - if (dev->fd >= 0) - { - close(dev->fd); - } - - free(dev->priv); - free(dev); - dev = next; - } - - ctx->head = NULL; -} - -/**************************************************************************** - * Name: signal_handler - ****************************************************************************/ - -static void -signal_handler(int signum, FAR siginfo_t *info, FAR void *context) -{ - FAR volatile sig_atomic_t *running = info->si_user; - *running = 0; -} - -/**************************************************************************** - * Name: run_event_loop - ****************************************************************************/ - -static void run_event_loop(FAR struct input_devices_ctx_s *ctx) -{ - FAR struct input_device_s *dev; - FAR struct pollfd *fds = NULL; - volatile sig_atomic_t running = 1; - struct sigaction sa; - int fd_count = 0; - int timeout = 500; - int i = 0; - int ret; - - sa.sa_flags = SA_SIGINFO; - sa.sa_sigaction = signal_handler; - sigemptyset(&sa.sa_mask); - sa.sa_user = (FAR void *)&running; - sigaction(SIGINT, &sa, NULL); - - for (dev = ctx->head; dev; dev = dev->next) - { - if (dev->fd >= 0) - { - fd_count++; - } - } - - fds = calloc(fd_count, sizeof(struct pollfd)); - - if (!fds) - { - GETEVENT_ERR("Memory allocation failed for fds\n"); - return; - } - - for (dev = ctx->head; dev; dev = dev->next) - { - if (dev->fd >= 0) - { - fds[i].fd = dev->fd; - fds[i].events = POLLIN; - fds[i].revents = 0; - i++; - } - } - - while (running) - { - ret = poll(fds, fd_count, timeout); - if (ret < 0 && errno != EINTR) - { - GETEVENT_ERR("poll error: %d\n", errno); - break; - } - - for (i = 0; i < fd_count; i++) - { - if (!(fds[i].revents & POLLIN)) - { - continue; - } - - for (dev = ctx->head; dev; dev = dev->next) - { - if (dev->fd == fds[i].fd) - { - dev->read_cb(dev); - break; - } - } - } - } - - free(fds); -} - -/**************************************************************************** - * Name: show_usage - ****************************************************************************/ - -static void show_usage(void) -{ - printf("Usage: getevent [OPTIONS]\n"); - printf("Options:\n"); - printf(" -h Show this help message\n"); - printf(" -m /dev/mouse -- mouse device path\n"); - printf(" -t /dev/input -- touch device path\n"); - printf(" -k /dev/keyboard -- keyboard device path\n"); - printf("No options: Auto detect devices in /dev\n"); -} - -/**************************************************************************** - * Name: alloc_input_device - ****************************************************************************/ - -static FAR struct input_device_s * -alloc_input_device(FAR struct input_devices_ctx_s *ctx, - FAR const char *path) -{ - FAR struct input_device_s *dev; - FAR struct input_device_s *cur; - size_t path_len = strlen(path) + 1; - - dev = calloc(1, sizeof(struct input_device_s) + path_len); - if (!dev) - { - GETEVENT_ERR("Memory allocation failed for device\n"); - return NULL; - } - - memcpy(dev->path, path, path_len); - - if (!ctx->head) - { - ctx->head = dev; - } - else - { - cur = ctx->head; - while (cur->next) - { - cur = cur->next; - } - - cur->next = dev; - } - - return dev; -} - -/**************************************************************************** - * Name: add_input_device - ****************************************************************************/ - -static int add_input_device(FAR struct input_devices_ctx_s *ctx, - input_init_cb init_cb, - input_read_cb read_cb, - FAR const char *path) -{ - FAR struct input_device_s *dev = alloc_input_device(ctx, path); - - if (!dev) - { - return -ENOMEM; - } - - dev->fd = -1; - dev->init_cb = init_cb; - dev->read_cb = read_cb; - - return open_device(dev); -} - -/**************************************************************************** - * Name: detect_devices - ****************************************************************************/ - -static int detect_devices(FAR struct input_devices_ctx_s *ctx) -{ - FAR struct dirent *entry; - char path[PATH_MAX]; - FAR DIR *dir; - int ret = 0; - - dir = opendir("/dev"); - if (!dir) - { - GETEVENT_ERR("Failed to open /dev directory, errno: %d\n", errno); - return -errno; - } - - while ((entry = readdir(dir))) - { - if (entry->d_type == DT_CHR) - { - if (snprintf(path, sizeof(path), "/dev/%s", entry->d_name) < 0) - { - GETEVENT_ERR("Memory allocation failed for path\n"); - continue; - } - - if (strncmp(entry->d_name, "mouse", 5) == 0) - { - ret = add_input_device(ctx, NULL, read_mouse_event, path); - } - else if (strncmp(entry->d_name, "input", 5) == 0) - { - ret = add_input_device(ctx, touch_init, read_touch_event, - path); - } - else if (strncmp(entry->d_name, "kbd", 3) == 0) - { - ret = add_input_device(ctx, NULL, read_keyboard_event, path); - } - - if (ret < 0) - { - break; - } - } - } - - closedir(dir); - return ret; -} - -/**************************************************************************** - * Name: parse_commandline - ****************************************************************************/ - -static int parse_commandline(FAR struct input_devices_ctx_s *ctx, - int argc, FAR char **argv) -{ - int ret = -EINVAL; - int ch; - - if (argc == 1) - { - return detect_devices(ctx); - } - - while ((ch = getopt(argc, argv, "hn:m:t:k:")) != -1) - { - switch (ch) - { - case 'm': - ret = add_input_device(ctx, NULL, read_mouse_event, optarg); - break; - case 't': - ret = add_input_device(ctx, touch_init, read_touch_event, optarg); - break; - case 'k': - ret = add_input_device(ctx, NULL, read_keyboard_event, optarg); - break; - case '?': - case 'h': - default: - show_usage(); - break; - } - - if (ret < 0) - { - break; - } - } - - return ret; -} - -/**************************************************************************** - * Name: main - ****************************************************************************/ - -int main(int argc, FAR char *argv[]) -{ - struct input_devices_ctx_s ctx; - int ret; - - memset(&ctx, 0, sizeof(ctx)); - - /* Parse the command line arguments */ - - ret = parse_commandline(&ctx, argc, argv); - if (ret < 0) - { - goto cleanup; - } - - /* Start event loop for input processing */ - - run_event_loop(&ctx); - - /* Clean up resources */ - -cleanup: - cleanup_input_devices(&ctx); - - GETEVENT_INFO("Terminating!\n"); - - return ret < 0 ? EXIT_FAILURE : EXIT_SUCCESS; -} diff --git a/graphics/input/monkey/monkey.c b/graphics/input/monkey/monkey.c deleted file mode 100644 index 3ba0d10b3..000000000 --- a/graphics/input/monkey/monkey.c +++ /dev/null @@ -1,230 +0,0 @@ -/**************************************************************************** - * apps/graphics/input/monkey/monkey.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include -#include -#include -#include "monkey.h" -#include "monkey_recorder.h" -#include "monkey_assert.h" -#include "monkey_log.h" -#include "monkey_dev.h" -#include "monkey_utils.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define MONKEY_DEV_PATH_TOUCH "/dev/input0" -#define MONKEY_DEV_PATH_BUTTON "/dev/buttons" - -#define MONKEY_DEV_CREATE_MATCH(monkey, type_mask, type) \ -do { \ - if (((type_mask) & MONKEY_DEV_TYPE_##type) == MONKEY_DEV_TYPE_##type) \ - { \ - FAR struct monkey_dev_s *dev; \ - dev = monkey_dev_create(MONKEY_DEV_PATH_##type, \ - MONKEY_DEV_TYPE_##type); \ - if (!dev) \ - { \ - goto failed; \ - } \ - (monkey)->devs[(monkey)->dev_num] = dev; \ - (monkey)->dev_num++; \ - } \ -} while (0) - -#define MONKEY_DEV_CREATE_UINPUT(monkey, _type) \ -do { \ - if (input_gen_query_device(monkey->input_gen_ctx, INPUT_GEN_DEV_##_type)) \ - { \ - FAR struct monkey_dev_s *dev = calloc(1, sizeof(struct monkey_dev_s)); \ - if (!dev) \ - { \ - MONKEY_LOG_ERROR("Failed to create virtual device"); \ - goto failed; \ - } \ - dev->type = MONKEY_DEV_TYPE_##_type; \ - dev->is_available = true; \ - (monkey)->devs[(monkey)->dev_num] = dev; \ - (monkey)->dev_num++; \ - } \ -} while (0) - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: monkey_create - ****************************************************************************/ - -FAR struct monkey_s *monkey_create(int dev_type_mask) -{ - FAR struct monkey_s *monkey = calloc(1, sizeof(struct monkey_s)); - MONKEY_ASSERT_NULL(monkey); - - if (MONKEY_IS_UINPUT_TYPE(dev_type_mask)) - { - if (input_gen_create(&monkey->input_gen_ctx, - MONKEY_GET_DEV_TYPE(dev_type_mask)) < 0) - { - MONKEY_LOG_ERROR("input generator create failed"); - goto failed; - } - - MONKEY_DEV_CREATE_UINPUT(monkey, UTOUCH); - MONKEY_DEV_CREATE_UINPUT(monkey, UBUTTON); - } - else - { - MONKEY_DEV_CREATE_MATCH(monkey, dev_type_mask, TOUCH); - MONKEY_DEV_CREATE_MATCH(monkey, dev_type_mask, BUTTON); - } - - if (monkey->dev_num == 0) - { - MONKEY_LOG_ERROR("NO enabled device detected"); - goto failed; - } - - MONKEY_ASSERT(monkey->dev_num <= MONKEY_DEV_MAX_NUM); - - MONKEY_LOG_NOTICE("OK"); - - return monkey; - -failed: - monkey_delete(monkey); - return NULL; -} - -/**************************************************************************** - * Name: monkey_delete - ****************************************************************************/ - -void monkey_delete(FAR struct monkey_s *monkey) -{ - int i; - MONKEY_ASSERT_NULL(monkey); - - if (monkey->input_gen_ctx) - { - input_gen_reset_devices(monkey->input_gen_ctx, INPUT_GEN_DEV_ALL); - input_gen_destroy(monkey->input_gen_ctx); - } - - for (i = 0; i < monkey->dev_num; i++) - { - monkey_dev_delete(monkey->devs[i]); - } - - if (monkey->recorder) - { - monkey_recorder_delete(monkey->recorder); - monkey->recorder = NULL; - } - - free(monkey); - MONKEY_LOG_NOTICE("OK"); -} - -/**************************************************************************** - * Name: monkey_config_default_init - ****************************************************************************/ - -void monkey_config_default_init(FAR struct monkey_config_s *config) -{ - MONKEY_ASSERT_NULL(config); - memset(config, 0, sizeof(struct monkey_config_s)); - config->screen.hor_res = 480; - config->screen.ver_res = 480; - config->period.min = 100; - config->period.max = 500; -} - -/**************************************************************************** - * Name: monkey_set_config - ****************************************************************************/ - -void monkey_set_config(FAR struct monkey_s *monkey, - FAR const struct monkey_config_s *config) -{ - MONKEY_ASSERT_NULL(monkey); - MONKEY_ASSERT_NULL(config); - monkey->config = *config; -} - -/**************************************************************************** - * Name: monkey_set_mode - ****************************************************************************/ - -void monkey_set_mode(FAR struct monkey_s *monkey, - enum monkey_mode_e mode) -{ - MONKEY_ASSERT_NULL(monkey); - monkey->mode = mode; -} - -/**************************************************************************** - * Name: monkey_set_period - ****************************************************************************/ - -void monkey_set_period(FAR struct monkey_s *monkey, uint32_t period) -{ - MONKEY_ASSERT_NULL(monkey); - monkey->config.period.min = period; - monkey->config.period.max = period; -} - -/**************************************************************************** - * Name: monkey_set_recorder_path - ****************************************************************************/ - -bool monkey_set_recorder_path(FAR struct monkey_s *monkey, - FAR const char *path) -{ - MONKEY_ASSERT_NULL(monkey); - - if (monkey->mode == MONKEY_MODE_RECORD) - { - monkey->recorder = monkey_recorder_create(path, - MONKEY_RECORDER_MODE_RECORD); - } - else if (monkey->mode == MONKEY_MODE_PLAYBACK) - { - monkey->recorder = monkey_recorder_create(path, - MONKEY_RECORDER_MODE_PLAYBACK); - } - else - { - MONKEY_LOG_WARN("mismatched mode: %d", monkey->mode); - } - - return (monkey->recorder != NULL); -} diff --git a/graphics/input/monkey/monkey.h b/graphics/input/monkey/monkey.h deleted file mode 100644 index ef3be8d90..000000000 --- a/graphics/input/monkey/monkey.h +++ /dev/null @@ -1,100 +0,0 @@ -/**************************************************************************** - * apps/graphics/input/monkey/monkey.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __APPS_GRAPHICS_INPUT_MONKEY_MONKEY_H -#define __APPS_GRAPHICS_INPUT_MONKEY_MONKEY_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include "monkey_type.h" - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -#ifdef __cplusplus -#define EXTERN extern "C" -extern "C" -{ -#else -#define EXTERN extern -#endif - -/**************************************************************************** - * Name: monkey_create - ****************************************************************************/ - -FAR struct monkey_s *monkey_create(int dev_type_mask); - -/**************************************************************************** - * Name: monkey_update - ****************************************************************************/ - -int monkey_update(FAR struct monkey_s *monkey); - -/**************************************************************************** - * Name: monkey_delete - ****************************************************************************/ - -void monkey_delete(FAR struct monkey_s *monkey); - -/**************************************************************************** - * Name: monkey_config_default_init - ****************************************************************************/ - -void monkey_config_default_init(FAR struct monkey_config_s *config); - -/**************************************************************************** - * Name: monkey_set_config - ****************************************************************************/ - -void monkey_set_config(FAR struct monkey_s *monkey, - FAR const struct monkey_config_s *config); - -/**************************************************************************** - * Name: monkey_set_mode - ****************************************************************************/ - -void monkey_set_mode(FAR struct monkey_s *monkey, enum monkey_mode_e mode); - -/**************************************************************************** - * Name: monkey_set_period - ****************************************************************************/ - -void monkey_set_period(FAR struct monkey_s *monkey, uint32_t period); - -/**************************************************************************** - * Name: monkey_set_recorder_path - ****************************************************************************/ - -bool monkey_set_recorder_path(FAR struct monkey_s *monkey, - FAR const char *path); - -#undef EXTERN -#ifdef __cplusplus -} -#endif - -#endif /* __APPS_GRAPHICS_INPUT_MONKEY_MONKEY_H */ diff --git a/graphics/input/monkey/monkey_assert.h b/graphics/input/monkey/monkey_assert.h deleted file mode 100644 index 8ff474c28..000000000 --- a/graphics/input/monkey/monkey_assert.h +++ /dev/null @@ -1,39 +0,0 @@ -/**************************************************************************** - * apps/graphics/input/monkey/monkey_assert.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __APPS_GRAPHICS_INPUT_MONKEY_MONKEY_ASSERT_H -#define __APPS_GRAPHICS_INPUT_MONKEY_MONKEY_ASSERT_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define MONKEY_ASSERT(expr) DEBUGASSERT(expr) -#define MONKEY_ASSERT_NULL(ptr) MONKEY_ASSERT(ptr != NULL) - -#endif /* __APPS_GRAPHICS_INPUT_MONKEY_MONKEY_ASSERT_H */ diff --git a/graphics/input/monkey/monkey_dev.c b/graphics/input/monkey/monkey_dev.c deleted file mode 100644 index ec63d8d79..000000000 --- a/graphics/input/monkey/monkey_dev.c +++ /dev/null @@ -1,318 +0,0 @@ -/**************************************************************************** - * apps/graphics/input/monkey/monkey_dev.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "monkey_assert.h" -#include "monkey_log.h" -#include "monkey_dev.h" -#include "monkey_utils.h" - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: utouch_write - ****************************************************************************/ - -static void utouch_write(input_gen_ctx_t input_gen_ctx, - FAR const struct monkey_dev_state_s *state) -{ - struct touch_sample_s sample; - sample.npoints = 1; - input_gen_fill_point(sample.point, state->data.touch.x, - state->data.touch.y, - state->data.touch.is_pressed ? TOUCH_DOWN : TOUCH_UP); - - if (input_gen_write_raw(input_gen_ctx, INPUT_GEN_DEV_UTOUCH, &sample, - sizeof(struct touch_sample_s)) < 0) - { - MONKEY_LOG_WARN("unsupported device type: %d", INPUT_GEN_DEV_UTOUCH); - return; - } - - MONKEY_LOG_INFO("%s at x = %d, y = %d", - state->data.touch.is_pressed ? "PRESS" : "RELEASE", - state->data.touch.x, state->data.touch.y); -} - -/**************************************************************************** - * Name: ubutton_write - ****************************************************************************/ - -static void ubutton_write(input_gen_ctx_t input_gen_ctx, - FAR const struct monkey_dev_state_s *state) -{ - btn_buttonset_t buttonset = state->data.button.value; - if (input_gen_write_raw(input_gen_ctx, INPUT_GEN_DEV_UBUTTON, &buttonset, - sizeof(buttonset)) < 0) - { - MONKEY_LOG_WARN("unsupported device type: %d", INPUT_GEN_DEV_UBUTTON); - return; - } - - MONKEY_LOG_INFO("btn = 0x%08X", state->data.button.value); -} - -/**************************************************************************** - * Name: touch_read - ****************************************************************************/ - -static bool touch_read(int fd, FAR int *x, FAR int *y, FAR int *touch_down) -{ - bool retval = false; - struct touch_sample_s sample; - - int nbytes = read(fd, &sample, sizeof(sample)); - - if (nbytes == sizeof(sample)) - { - retval = true; - uint8_t touch_flags = sample.point[0].flags; - - if (touch_flags & TOUCH_DOWN || touch_flags & TOUCH_MOVE) - { - *x = sample.point[0].x; - *y = sample.point[0].y; - *touch_down = true; - } - else if (touch_flags & TOUCH_UP) - { - *x = 0; - *y = 0; - *touch_down = false; - } - } - - return retval; -} - -/**************************************************************************** - * Name: button_read - ****************************************************************************/ - -static bool button_read(int fd, FAR uint32_t *value) -{ - btn_buttonset_t buttonset; - - int nbytes = read(fd, &buttonset, sizeof(buttonset)); - if (nbytes != sizeof(buttonset)) - { - return false; - } - - *value = buttonset; - return true; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: monkey_dev_create - ****************************************************************************/ - -FAR struct monkey_dev_s *monkey_dev_create(FAR const char *dev_path, - enum monkey_dev_type_e type) -{ - FAR struct monkey_dev_s *dev; - int oflag; - int fd; - - MONKEY_ASSERT_NULL(dev_path); - MONKEY_ASSERT(!MONKEY_IS_UINPUT_TYPE(type)); - - dev = calloc(1, sizeof(struct monkey_dev_s)); - MONKEY_ASSERT_NULL(dev); - - oflag = O_RDONLY | O_NONBLOCK; - - fd = open(dev_path, oflag); - if (fd < 0) - { - MONKEY_LOG_ERROR("open %s failed: %d", dev_path, errno); - goto failed; - } - - dev->type = type; - dev->fd = fd; - - MONKEY_LOG_NOTICE("open %s success, fd = %d, type: %s", - dev_path, fd, monkey_dev_type2name(type)); - - return dev; - -failed: - if (fd > 0) - { - close(fd); - } - - if (dev) - { - free(dev); - } - - return NULL; -} - -/**************************************************************************** - * Name: monkey_dev_delete - ****************************************************************************/ - -void monkey_dev_delete(FAR struct monkey_dev_s *dev) -{ - MONKEY_ASSERT_NULL(dev); - - if (dev->fd > 0) - { - MONKEY_LOG_NOTICE("close fd: %d", dev->fd); - close(dev->fd); - } - - free(dev); -} - -/**************************************************************************** - * Name: monkey_dev_set_state - ****************************************************************************/ - -void monkey_dev_set_state(input_gen_ctx_t input_gen_ctx, - FAR const struct monkey_dev_state_s *state) -{ - MONKEY_ASSERT_NULL(input_gen_ctx); - - switch (MONKEY_GET_DEV_TYPE(state->type)) - { - case MONKEY_DEV_TYPE_TOUCH: - { - utouch_write(input_gen_ctx, state); - break; - } - - case MONKEY_DEV_TYPE_BUTTON: - { - ubutton_write(input_gen_ctx, state); - break; - } - - default: - break; - } -} - -/**************************************************************************** - * Name: monkey_dev_get_state - ****************************************************************************/ - -bool monkey_dev_get_state(FAR struct monkey_dev_s *dev, - FAR struct monkey_dev_state_s *state) -{ - bool retval; - MONKEY_ASSERT_NULL(dev); - - retval = false; - - state->type = dev->type; - - switch (dev->type) - { - case MONKEY_DEV_TYPE_TOUCH: - retval = touch_read(dev->fd, - &state->data.touch.x, - &state->data.touch.y, - &state->data.touch.is_pressed); - break; - - case MONKEY_DEV_TYPE_BUTTON: - retval = button_read(dev->fd, &state->data.button.value); - break; - - default: - break; - } - - return retval; -} - -/**************************************************************************** - * Name: monkey_dev_get_type - ****************************************************************************/ - -enum monkey_dev_type_e monkey_dev_get_type( - FAR struct monkey_dev_s *dev) -{ - MONKEY_ASSERT_NULL(dev); - return dev->type; -} - -/**************************************************************************** - * Name: monkey_dev_get_available - ****************************************************************************/ - -int monkey_dev_get_available(FAR struct monkey_dev_s *devs[], int dev_num) -{ - int i; - int available = 0; - struct pollfd fds[MONKEY_DEV_MAX_NUM]; - memset(fds, 0, sizeof(fds)); - - for (i = 0; i < dev_num; i++) - { - devs[i]->is_available = false; - fds[i].fd = devs[i]->fd; - fds[i].events = POLLIN | POLLPRI; - } - - if (poll(fds, dev_num, -1) < 0) - { - MONKEY_LOG_WARN("stop: %d", errno); - return -1; - } - - for (i = 0; i < dev_num; i++) - { - if (fds[i].revents & (POLLIN | POLLPRI)) - { - devs[i]->is_available = true; - available++; - } - } - - return available; -} diff --git a/graphics/input/monkey/monkey_dev.h b/graphics/input/monkey/monkey_dev.h deleted file mode 100644 index 48a76f36e..000000000 --- a/graphics/input/monkey/monkey_dev.h +++ /dev/null @@ -1,99 +0,0 @@ -/**************************************************************************** - * apps/graphics/input/monkey/monkey_dev.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __APPS_GRAPHICS_INPUT_MONKEY_MONKEY_DEV_H -#define __APPS_GRAPHICS_INPUT_MONKEY_MONKEY_DEV_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "monkey_type.h" - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -struct monkey_dev_s -{ - int fd; - enum monkey_dev_type_e type; - bool is_available; -}; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -#ifdef __cplusplus -#define EXTERN extern "C" -extern "C" -{ -#else -#define EXTERN extern -#endif - -/**************************************************************************** - * Name: monkey_dev_create - ****************************************************************************/ - -FAR struct monkey_dev_s *monkey_dev_create(FAR const char *dev_path, - enum monkey_dev_type_e type); - -/**************************************************************************** - * Name: monkey_dev_delete - ****************************************************************************/ - -void monkey_dev_delete(FAR struct monkey_dev_s *dev); - -/**************************************************************************** - * Name: monkey_dev_set_state - ****************************************************************************/ - -void monkey_dev_set_state(input_gen_ctx_t input_gen_ctx, - FAR const struct monkey_dev_state_s *state); - -/**************************************************************************** - * Name: monkey_dev_get_state - ****************************************************************************/ - -bool monkey_dev_get_state(FAR struct monkey_dev_s *dev, - FAR struct monkey_dev_state_s *state); - -/**************************************************************************** - * Name: monkey_dev_get_type - ****************************************************************************/ - -enum monkey_dev_type_e monkey_dev_get_type(FAR struct monkey_dev_s *dev); - -/**************************************************************************** - * Name: monkey_dev_get_available - ****************************************************************************/ - -int monkey_dev_get_available(FAR struct monkey_dev_s *devs[], int dev_num); - -#undef EXTERN -#ifdef __cplusplus -} -#endif - -#endif /* __APPS_GRAPHICS_INPUT_MONKEY_MONKEY_DEV_H */ diff --git a/graphics/input/monkey/monkey_event.c b/graphics/input/monkey/monkey_event.c deleted file mode 100644 index a8fac696c..000000000 --- a/graphics/input/monkey/monkey_event.c +++ /dev/null @@ -1,154 +0,0 @@ -/**************************************************************************** - * apps/graphics/input/monkey/monkey_event.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include -#include "monkey_dev.h" -#include "monkey_event.h" -#include "monkey_log.h" -#include "monkey_utils.h" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: monkey_event_gen - ****************************************************************************/ - -void monkey_event_gen(FAR struct monkey_s *monkey, - FAR struct monkey_event_param_s *param) -{ - int weight = 0; - int total = 0; - int i; - int rnd; - int duration_min; - int duration_max; - int x_offset; - int y_offset; - - memset(param, 0, sizeof(struct monkey_event_param_s)); - - /* Calculate total weight */ - - for (i = 0; i < MONKEY_EVENT_LAST; i++) - { - total += monkey->config.event[i].weight; - } - - rnd = monkey_random(0, total); - - /* Select random events based on weight */ - - for (i = 0; i < MONKEY_EVENT_LAST; i++) - { - weight += monkey->config.event[i].weight; - - if (rnd < weight) - { - param->event = i; - break; - } - } - - duration_min = monkey->config.event[param->event].duration_min; - duration_max = monkey->config.event[param->event].duration_max; - x_offset = monkey->config.screen.x_offset; - y_offset = monkey->config.screen.y_offset; - - param->duration = monkey_random(duration_min, duration_max); - param->x1 = monkey_random(x_offset, - x_offset + monkey->config.screen.hor_res - 1); - param->y1 = monkey_random(y_offset, - y_offset + monkey->config.screen.ver_res - 1); - param->x2 = monkey_random(x_offset, - x_offset + monkey->config.screen.hor_res - 1); - param->y2 = monkey_random(y_offset, - y_offset + monkey->config.screen.ver_res - 1); - - MONKEY_LOG_INFO("event=%d(%s) duration=%d x1=%d y1=%d x2=%d y2=%d", - param->event, - monkey_event_type2name(param->event), - param->duration, - param->x1, param->y1, - param->x2, param->y2); -} - -/**************************************************************************** - * Name: monkey_event_exec - ****************************************************************************/ - -bool monkey_event_exec(FAR struct monkey_s *monkey, - FAR struct monkey_dev_s *dev, - FAR const struct monkey_event_param_s *param) -{ - bool retval = false; - enum monkey_dev_type_e dev_type = monkey_dev_get_type(dev); - MONKEY_LOG_INFO("dev=0x%x event=%d(%s) duration=%d" - " x1=%d y1=%d x2=%d y2=%d", - dev_type, - param->event, - monkey_event_type2name(param->event), - param->duration, - param->x1, param->y1, - param->x2, param->y2); - - if (dev_type & MONKEY_DEV_TYPE_TOUCH) - { - if (param->event == MONKEY_EVENT_DRAG) - { - retval = !input_gen_drag(monkey->input_gen_ctx, - param->x1, param->y1, - param->x2, param->y2, - param->duration); - } - else - { - /* Use swipe with same start and end point to simulate click or - * longpress. - */ - - retval = !input_gen_swipe(monkey->input_gen_ctx, - param->x1, param->y1, - param->x1, param->y1, - param->duration); - } - } - else if (dev_type & MONKEY_DEV_TYPE_BUTTON) - { - retval = !input_gen_button_longpress(monkey->input_gen_ctx, - 1 << monkey->config.btn_bit, - param->duration); - } - else - { - MONKEY_LOG_WARN("unsupported device type: %d", dev_type); - } - - return retval; -} diff --git a/graphics/input/monkey/monkey_event.h b/graphics/input/monkey/monkey_event.h deleted file mode 100644 index f1dc29724..000000000 --- a/graphics/input/monkey/monkey_event.h +++ /dev/null @@ -1,79 +0,0 @@ -/**************************************************************************** - * apps/graphics/input/monkey/monkey_event.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __APPS_GRAPHICS_INPUT_MONKEY_MONKEY_EVENT_H -#define __APPS_GRAPHICS_INPUT_MONKEY_MONKEY_EVENT_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include "monkey_type.h" - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -struct monkey_event_param_s -{ - enum monkey_event_e event; - int duration; - int x1; - int y1; - int x2; - int y2; -}; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -#ifdef __cplusplus -#define EXTERN extern "C" -extern "C" -{ -#else -#define EXTERN extern -#endif - -/**************************************************************************** - * Name: monkey_event_gen - ****************************************************************************/ - -void monkey_event_gen(FAR struct monkey_s *monkey, - FAR struct monkey_event_param_s *param); - -/**************************************************************************** - * Name: monkey_event_exec - ****************************************************************************/ - -bool monkey_event_exec(FAR struct monkey_s *monkey, - FAR struct monkey_dev_s *dev, - FAR const struct monkey_event_param_s *param); - -#undef EXTERN -#ifdef __cplusplus -} -#endif - -#endif /* __APPS_GRAPHICS_INPUT_MONKEY_MONKEY_EVENT_H */ diff --git a/graphics/input/monkey/monkey_log.c b/graphics/input/monkey/monkey_log.c deleted file mode 100644 index 473570578..000000000 --- a/graphics/input/monkey/monkey_log.c +++ /dev/null @@ -1,97 +0,0 @@ -/**************************************************************************** - * apps/graphics/input/monkey/monkey_log.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include -#include "monkey_log.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static enum monkey_log_level_type_e g_log_level = MONKEY_LOG_LEVEL_NOTICE; - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: monkey_log_printf - ****************************************************************************/ - -void monkey_log_printf(enum monkey_log_level_type_e level, - FAR const char *func, - FAR const char *fmt, - ...) -{ - struct va_format vaf; - va_list ap; - - static const int priority[MONKEY_LOG_LEVEL_LAST] = - { - LOG_INFO, LOG_NOTICE, LOG_WARNING, LOG_ERR - }; - - if (level < g_log_level) - { - return; - } - - va_start(ap, fmt); - vaf.fmt = fmt; - vaf.va = ≈ - syslog(priority[level], "[monkey] %s: %pV\n", func, &vaf); - va_end(ap); -} - -/**************************************************************************** - * Name: monkey_log_set_level - ****************************************************************************/ - -void monkey_log_set_level(enum monkey_log_level_type_e level) -{ - if (level >= MONKEY_LOG_LEVEL_LAST) - { - MONKEY_LOG_WARN("error level: %d", level); - return; - } - - g_log_level = level; -} - -/**************************************************************************** - * Name: monkey_log_get_level - ****************************************************************************/ - -enum monkey_log_level_type_e monkey_log_get_level(void) -{ - return g_log_level; -} diff --git a/graphics/input/monkey/monkey_log.h b/graphics/input/monkey/monkey_log.h deleted file mode 100644 index 30a8c18e0..000000000 --- a/graphics/input/monkey/monkey_log.h +++ /dev/null @@ -1,108 +0,0 @@ -/**************************************************************************** - * apps/graphics/input/monkey/monkey_log.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __APPS_GRAPHICS_INPUT_MONKEY_MONKEY_LOG_H -#define __APPS_GRAPHICS_INPUT_MONKEY_MONKEY_LOG_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define MONKEY_LOG_INFO(format, ...) \ - monkey_log_printf(MONKEY_LOG_LEVEL_INFO, \ - __func__, \ - format, \ - ##__VA_ARGS__) -#define MONKEY_LOG_NOTICE(format, ...) \ - monkey_log_printf(MONKEY_LOG_LEVEL_NOTICE, \ - __func__, \ - format, \ - ##__VA_ARGS__) -#define MONKEY_LOG_WARN(format, ...) \ - monkey_log_printf(MONKEY_LOG_LEVEL_WARN, \ - __func__, \ - format, \ - ##__VA_ARGS__) -#define MONKEY_LOG_ERROR(format, ...) \ - monkey_log_printf(MONKEY_LOG_LEVEL_ERROR, \ - __func__, \ - format, \ - ##__VA_ARGS__) - -#ifdef __cplusplus -#define EXTERN extern "C" -extern "C" -{ -#else -#define EXTERN extern -#endif - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -enum monkey_log_level_type_e -{ - MONKEY_LOG_LEVEL_INFO, - MONKEY_LOG_LEVEL_NOTICE, - MONKEY_LOG_LEVEL_WARN, - MONKEY_LOG_LEVEL_ERROR, - MONKEY_LOG_LEVEL_LAST -}; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Name: monkey_log_printf - ****************************************************************************/ - -void monkey_log_printf(enum monkey_log_level_type_e level, - FAR const char *func, - FAR const char *fmt, - ...); - -/**************************************************************************** - * Name: monkey_log_set_level - ****************************************************************************/ - -void monkey_log_set_level(enum monkey_log_level_type_e level); - -/**************************************************************************** - * Name: monkey_log_get_level - ****************************************************************************/ - -enum monkey_log_level_type_e monkey_log_get_level(void); - -#undef EXTERN -#ifdef __cplusplus -} -#endif - -#endif /* __APPS_GRAPHICS_INPUT_MONKEY_MONKEY_LOG_H */ diff --git a/graphics/input/monkey/monkey_main.c b/graphics/input/monkey/monkey_main.c deleted file mode 100644 index 43b0561c0..000000000 --- a/graphics/input/monkey/monkey_main.c +++ /dev/null @@ -1,631 +0,0 @@ -/**************************************************************************** - * apps/graphics/input/monkey/monkey_main.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "monkey.h" -#include "monkey_utils.h" -#include "monkey_log.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define MONKEY_PREFIX "monkey" - -#define CONSTRAIN(x, low, high) \ - ((x) < (low) ? (low) : ((x) > (high) ? (high) : (x))) - -#define OPTARG_TO_VALUE(value, type, base) \ - do \ - { \ - FAR char *ptr; \ - (value) = (type)strtoul(optarg, &ptr, (base)); \ - if (*ptr != '\0') \ - { \ - MONKEY_LOG_ERROR("Parameter error: -%c %s", ch, optarg); \ - show_usage(argv[0], EXIT_FAILURE); \ - } \ - } while (0) - -#define OPTARG_TO_RANGE(value_1, value_2, delimiter) \ - do \ - { \ - int converted; \ - int v1; \ - int v2; \ - converted = sscanf(optarg, "%d" delimiter "%d", &v1, &v2); \ - if (converted == 2 && v1 >= 0 && v2 >= 0) \ - { \ - value_1 = v1; \ - value_2 = v2; \ - } \ - else \ - { \ - MONKEY_LOG_ERROR("Error range: %s", optarg); \ - show_usage(argv[0], EXIT_FAILURE); \ - } \ - } while (0) - -/* Default parameters */ - -#if defined(CONFIG_VIDEO_FB) -# define MONKEY_SCREEN_DEV "/dev/fb0" -# define MONKEY_SCREEN_GETVIDEOINFO FBIOGET_VIDEOINFO -#elif defined(CONFIG_LCD) -# define MONKEY_SCREEN_DEV "/dev/lcd0" -# define MONKEY_SCREEN_GETVIDEOINFO LCDDEVIO_GETVIDEOINFO -#endif - -#define MONKEY_RUNNING_MINUTES_MAX (UINT32_MAX / 60 / 1000) - -#define MONKEY_SCREEN_HOR_RES_DEFAULT 480 -#define MONKEY_SCREEN_VER_RES_DEFAULT 480 - -#define MONKEY_PERIOD_MIN_DEFAULT 100 -#define MONKEY_PERIOD_MAX_DEFAULT 500 -#define MONKEY_BUTTON_BIT_DEFAULT 0 - -#define MONKEY_EVENT_CLICK_WEIGHT_DEFAULT 70 -#define MONKEY_EVENT_LONG_PRESS_WEIGHT_DEFAULT 10 -#define MONKEY_EVENT_DRAG_WEIGHT_DEFAULT 20 - -#define MONKEY_EVENT_CLICK_DURATION_MIN_DEFAULT 50 -#define MONKEY_EVENT_CLICK_DURATION_MAX_DEFAULT 200 -#define MONKEY_EVENT_LONG_PRESS_DURATION_MIN_DEFAULT 400 -#define MONKEY_EVENT_LONG_PRESS_DURATION_MAX_DEFAULT 600 -#define MONKEY_EVENT_DRAG_DURATION_MIN_DEFAULT 100 -#define MONKEY_EVENT_DRAG_DURATION_MAX_DEFAULT 400 - -#define MONKEY_EVENT_PARAM_INIT(name) \ - do \ - { \ - param->event[MONKEY_EVENT_##name].weight = \ - MONKEY_EVENT_##name##_WEIGHT_DEFAULT; \ - param->event[MONKEY_EVENT_##name].duration_min = \ - MONKEY_EVENT_##name##_DURATION_MIN_DEFAULT; \ - param->event[MONKEY_EVENT_##name].duration_max = \ - MONKEY_EVENT_##name##_DURATION_MAX_DEFAULT; \ - } while (0) - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -struct monkey_param_s -{ - int dev_type_mask; - FAR const char *file_path; - int x_offset; - int y_offset; - int hor_res; - int ver_res; - int period_min; - int period_max; - int btn_bit; - int log_level; - struct monkey_event_config_s event[MONKEY_EVENT_LAST]; - uint32_t running_minutes; -}; - -enum monkey_wait_res_e -{ - MONKEY_WAIT_RES_AGAIN, - MONKEY_WAIT_RES_PAUSE, - MONKEY_WAIT_RES_STOP, - MONKEY_WAIT_RES_ERROR, -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: show_usage - ****************************************************************************/ - -static void show_usage(FAR const char *progname, int exitcode) -{ - printf("\nUsage: %s" - " -t " - " -f " - " -p " - " -s " - " -b " - " -l \n" - " --weight-click " - " --weight-longpress " - " --weight-drag \n" - " --duration-click " - " --duration-longpress " - " --duration-drag \n" - " --screen-offset \n" - " --running-minutes \n", - progname); - - printf("\nWhere:\n"); - - printf(" -t Device type mask: uinput = 0x%02X;" - " touch = 0x%02X; button = 0x%02X.\n", - MONKEY_UINPUT_TYPE_MASK, - MONKEY_DEV_TYPE_TOUCH, - MONKEY_DEV_TYPE_BUTTON); - printf(" -f Recorder playback file path.\n"); - printf(" -p Period(ms) range: " - "-\n"); - printf(" -s Screen resolution: " - "x\n"); - printf(" -b Button bit: 0 ~ 31\n"); - printf(" -l Log level: 0 ~ 3\n"); - - printf(" --weight-click Click event weight.\n"); - printf(" --weight-longpress Long press event weight.\n"); - printf(" --weight-drag Drag event weight.\n"); - - printf(" --duration-click Click duration(ms) range: " - "-.\n"); - printf(" --duration-longpress Long press duration(ms) range: " - "-.\n"); - printf(" --duration-drag Drag duration(ms) range: " - "-.\n"); - printf(" --screen-offset Screen offset: " - ",\n"); - printf(" --running-minutes Running minutes.\n"); - - exit(exitcode); -} - -/**************************************************************************** - * Name: monkey_get_screen_resolution - ****************************************************************************/ - -static int monkey_get_screen_resolution(FAR int *hor_res, FAR int *ver_res) -{ -#ifdef MONKEY_SCREEN_DEV - struct fb_videoinfo_s vinfo; - int fd; - int ret; - FAR const char *dev_path = MONKEY_SCREEN_DEV; - *hor_res = MONKEY_SCREEN_HOR_RES_DEFAULT; - *ver_res = MONKEY_SCREEN_VER_RES_DEFAULT; - fd = open(dev_path, 0); - - if (fd < 0) - { - MONKEY_LOG_ERROR("screen dev %s open failed: %d", dev_path, errno); - return ERROR; - } - - ret = ioctl(fd, MONKEY_SCREEN_GETVIDEOINFO, - (unsigned long)((uintptr_t)&vinfo)); - - if (ret < 0) - { - MONKEY_LOG_ERROR("get video info failed: %d", errno); - } - else - { - *hor_res = vinfo.xres; - *ver_res = vinfo.yres; - } - - close(fd); - return ret; -#else - *hor_res = MONKEY_SCREEN_HOR_RES_DEFAULT; - *ver_res = MONKEY_SCREEN_VER_RES_DEFAULT; - return OK; -#endif /* MONKEY_SCREEN_DEV */ -} - -/**************************************************************************** - * Name: monkey_init - ****************************************************************************/ - -static FAR struct monkey_s *monkey_init( - FAR const struct monkey_param_s *param) -{ - FAR struct monkey_s *monkey; - struct monkey_config_s config; - int i; - - if (!param->dev_type_mask) - { - show_usage(MONKEY_PREFIX, EXIT_FAILURE); - } - - monkey = monkey_create(param->dev_type_mask); - - if (!monkey) - { - goto failed; - } - - monkey_config_default_init(&config); - config.screen.x_offset = param->x_offset; - config.screen.y_offset = param->y_offset; - config.screen.hor_res = param->hor_res; - config.screen.ver_res = param->ver_res; - config.period.min = param->period_min; - config.period.max = param->period_max; - config.btn_bit = param->btn_bit; - memcpy(config.event, param->event, sizeof(config.event)); - monkey_set_config(monkey, &config); - monkey_log_set_level(param->log_level); - - MONKEY_LOG_NOTICE("Screen: %dx%d, offset: %d,%d", - config.screen.hor_res, - config.screen.ver_res, - config.screen.x_offset, - config.screen.y_offset); - MONKEY_LOG_NOTICE("Period: %" PRIu32 " ~ %" PRIu32 "ms", - config.period.min, - config.period.max); - MONKEY_LOG_NOTICE("Button bit: %d", config.btn_bit); - MONKEY_LOG_NOTICE("Log level: %d", monkey_log_get_level()); - - for (i = 0; i < MONKEY_EVENT_LAST; i++) - { - MONKEY_LOG_NOTICE("Event %d(%s): weight=%d" - " duration %d ~ %dms", - i, - monkey_event_type2name(i), - config.event[i].weight, - config.event[i].duration_min, - config.event[i].duration_max); - } - - MONKEY_LOG_NOTICE("Running minutes: %" PRIu32, param->running_minutes); - - if (MONKEY_IS_UINPUT_TYPE(param->dev_type_mask)) - { - if (param->file_path) - { - monkey_set_mode(monkey, MONKEY_MODE_PLAYBACK); - if (!monkey_set_recorder_path(monkey, param->file_path)) - { - goto failed; - } - } - else - { - monkey_set_mode(monkey, MONKEY_MODE_RANDOM); - } - } - else - { - monkey_set_mode(monkey, MONKEY_MODE_RECORD); - if (!monkey_set_recorder_path(monkey, - CONFIG_GRAPHICS_INPUT_MONKEY_REC_DIR_PATH)) - { - goto failed; - } - - monkey_set_period(monkey, config.period.min); - } - - return monkey; - -failed: - if (monkey) - { - monkey_delete(monkey); - } - - return NULL; -} - -/**************************************************************************** - * Name: parse_long_commandline - ****************************************************************************/ - -static void parse_long_commandline(int argc, FAR char **argv, - int ch, - FAR const struct option *longopts, - int longindex, - FAR struct monkey_param_s *param) -{ - int event_index; - switch (longindex) - { - case 0: - case 1: - case 2: - event_index = longindex; - OPTARG_TO_VALUE(param->event[event_index].weight, uint8_t, 10); - break; - - case 3: - case 4: - case 5: - event_index = longindex - 3; - OPTARG_TO_RANGE(param->event[event_index].duration_min, - param->event[event_index].duration_max, - "-"); - break; - - case 6: - OPTARG_TO_RANGE(param->x_offset, - param->y_offset, - ","); - break; - - case 7: - OPTARG_TO_VALUE(param->running_minutes, uint32_t, 10); - - if (param->running_minutes > MONKEY_RUNNING_MINUTES_MAX) - { - MONKEY_LOG_WARN("Running minutes must be less than %d", - MONKEY_RUNNING_MINUTES_MAX); - param->running_minutes = MONKEY_RUNNING_MINUTES_MAX; - } - break; - - default: - MONKEY_LOG_WARN("Unknown longindex: %d", longindex); - show_usage(argv[0], EXIT_FAILURE); - break; - } -} - -/**************************************************************************** - * Name: parse_commandline - ****************************************************************************/ - -static void parse_commandline(int argc, FAR char **argv, - FAR struct monkey_param_s *param) -{ - int ch; - int longindex = 0; - FAR const char *optstring = "t:f:p:s:b:l:"; - const struct option longopts[] = - { - {"weight-click", required_argument, NULL, 0 }, - {"weight-longpress", required_argument, NULL, 0 }, - {"weight-drag", required_argument, NULL, 0 }, - {"duration-click", required_argument, NULL, 0 }, - {"duration-longpress", required_argument, NULL, 0 }, - {"duration-drag", required_argument, NULL, 0 }, - {"screen-offset", required_argument, NULL, 0 }, - {"running-minutes", required_argument, NULL, 0 }, - {0, 0, NULL, 0 } - }; - - memset(param, 0, sizeof(struct monkey_param_s)); - monkey_get_screen_resolution(¶m->hor_res, ¶m->ver_res); - param->period_min = MONKEY_PERIOD_MIN_DEFAULT; - param->period_max = MONKEY_PERIOD_MAX_DEFAULT; - param->btn_bit = MONKEY_BUTTON_BIT_DEFAULT; - param->log_level = MONKEY_LOG_LEVEL_NOTICE; - MONKEY_EVENT_PARAM_INIT(CLICK); - MONKEY_EVENT_PARAM_INIT(LONG_PRESS); - MONKEY_EVENT_PARAM_INIT(DRAG); - - while ((ch = getopt_long(argc, argv, - optstring, longopts, &longindex)) != ERROR) - { - switch (ch) - { - case 0: - parse_long_commandline(argc, argv, ch, - longopts, longindex, param); - break; - - case 't': - OPTARG_TO_VALUE(param->dev_type_mask, int, 16); - break; - - case 'f': - param->file_path = optarg; - break; - - case 'p': - OPTARG_TO_RANGE(param->period_min, param->period_max, "-"); - break; - - case 's': - OPTARG_TO_RANGE(param->hor_res, param->ver_res, "x"); - break; - - case 'b': - OPTARG_TO_VALUE(param->btn_bit, int, 10); - param->btn_bit = CONSTRAIN(param->btn_bit, 0, 31); - break; - - case 'l': - OPTARG_TO_VALUE(param->log_level, int, 10); - param->log_level = CONSTRAIN(param->log_level, 0, - MONKEY_LOG_LEVEL_LAST - 1); - break; - - case '?': - MONKEY_LOG_WARN("Unknown option: %c", optopt); - show_usage(argv[0], EXIT_FAILURE); - break; - } - } -} - -/**************************************************************************** - * Name: monkey_pause - ****************************************************************************/ - -static int monkey_pause(void) -{ - sigset_t set; - - sigemptyset(&set); - sigaddset(&set, SIGCONT); - - return sigwaitinfo(&set, NULL); -} - -/**************************************************************************** - * Name: monkey_wait - ****************************************************************************/ - -static enum monkey_wait_res_e monkey_wait(uint32_t ms) -{ - sigset_t set; - struct timespec timeout; - int ret; - - enum monkey_wait_res_e res = MONKEY_WAIT_RES_ERROR; - - if (ms == 0) - { - return MONKEY_WAIT_RES_AGAIN; - } - - timeout.tv_sec = ms / 1000; - timeout.tv_nsec = (ms % 1000) * 1000000; - - sigemptyset(&set); - sigaddset(&set, SIGTSTP); - - ret = sigtimedwait(&set, NULL, &timeout); - - if (ret < 0) - { - int errcode = errno; - if (errcode == EINTR) - { - res = MONKEY_WAIT_RES_STOP; - } - else if(errcode == EAGAIN) - { - res = MONKEY_WAIT_RES_AGAIN; - } - else - { - MONKEY_LOG_ERROR("Unknown error: %d", errcode); - } - } - else if (ret == SIGTSTP) - { - res = MONKEY_WAIT_RES_PAUSE; - } - - return res; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: monkey_main - * - * Description: - * - * Input Parameters: - * Standard argc and argv - * - * Returned Value: - * Zero on success; a positive, non-zero value on failure. - * - ****************************************************************************/ - -int main(int argc, FAR char *argv[]) -{ - struct monkey_param_s param; - FAR struct monkey_s *monkey; - uint32_t start_tick; - parse_commandline(argc, argv, ¶m); - - monkey = monkey_init(¶m); - - if (!monkey) - { - return ERROR; - } - - start_tick = monkey_tick_get(); - - while (1) - { - enum monkey_wait_res_e res; - int sleep_ms; - - if (param.running_minutes > 0) - { - uint32_t elaps = monkey_tick_elaps(monkey_tick_get(), start_tick); - - if (elaps > param.running_minutes * 60 * 1000) - { - MONKEY_LOG_WARN("Running time is over: %" PRIu32 - " minutes, exit...", - param.running_minutes); - break; - } - } - - sleep_ms = monkey_update(monkey); - - if (sleep_ms < 0) - { - break; - } - - res = monkey_wait(sleep_ms); - - if (res == MONKEY_WAIT_RES_AGAIN) - { - continue; - } - else if (res == MONKEY_WAIT_RES_PAUSE) - { - MONKEY_LOG_NOTICE("pause"); - if (monkey_pause() < 0) - { - break; - } - - MONKEY_LOG_NOTICE("continue..."); - } - else - { - /* STOP or ERROR */ - - break; - } - } - - monkey_delete(monkey); - - return OK; -} diff --git a/graphics/input/monkey/monkey_proc.c b/graphics/input/monkey/monkey_proc.c deleted file mode 100644 index fb09b074d..000000000 --- a/graphics/input/monkey/monkey_proc.c +++ /dev/null @@ -1,291 +0,0 @@ -/**************************************************************************** - * apps/graphics/input/monkey/monkey_proc.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include -#include -#include "monkey.h" -#include "monkey_assert.h" -#include "monkey_dev.h" -#include "monkey_event.h" -#include "monkey_log.h" -#include "monkey_recorder.h" -#include "monkey_utils.h" - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: monkey_update_uinput_random - ****************************************************************************/ - -static bool monkey_update_uinput_random(FAR struct monkey_s *monkey) -{ - int i; - bool retval = false; - - for (i = 0; i < monkey->dev_num; i++) - { - FAR struct monkey_dev_s *dev = monkey->devs[i]; - struct monkey_event_param_s param; - monkey_event_gen(monkey, ¶m); - retval = monkey_event_exec(monkey, dev, ¶m); - - if (!retval) - { - break; - } - } - - return retval; -} - -/**************************************************************************** - * Name: monkey_recorder_get_next - * - * Description: - * Gets the next recorder state - * - * Returned Value: - * 0 on error, 1 on end of file, 2 on success. - * - ****************************************************************************/ - -static int monkey_recorder_get_next(FAR struct monkey_s *monkey, - FAR uint32_t *cur_time_stamp_p, - FAR struct monkey_dev_state_s *cur_state_p, - FAR uint32_t *next_time_stamp_p, - FAR struct monkey_dev_state_s *next_state_p) -{ - enum monkey_recorder_res_e res; - - if (monkey->playback_ctx.time_stamp == 0) - { - res = monkey_recorder_read(monkey->recorder, - cur_state_p, - cur_time_stamp_p); - - if (res != MONKEY_RECORDER_RES_OK) - { - MONKEY_LOG_ERROR("read first line failed: %d", res); - return 0; - } - } - else - { - *cur_time_stamp_p = monkey->playback_ctx.time_stamp; - *cur_state_p = monkey->playback_ctx.state; - } - - res = monkey_recorder_read(monkey->recorder, - next_state_p, - next_time_stamp_p); - - if (res != MONKEY_RECORDER_RES_OK) - { - if (res == MONKEY_RECORDER_RES_END_OF_FILE) - { - MONKEY_LOG_WARN("end of file"); - return 1; - } - - MONKEY_LOG_ERROR("read error: %d", res); - return 0; - } - - monkey->playback_ctx.time_stamp = *next_time_stamp_p; - monkey->playback_ctx.state = *next_state_p; - return 2; -} - -/**************************************************************************** - * Name: monkey_update_uinput_playback - ****************************************************************************/ - -static bool monkey_update_uinput_playback(FAR struct monkey_s *monkey) -{ - FAR uint32_t cur_time_stamp; - struct monkey_dev_state_s cur_state; - FAR uint32_t next_time_stamp; - struct monkey_dev_state_s next_state; - - uint32_t tick_elaps; - - int num_of_get; - - MONKEY_ASSERT_NULL(monkey->recorder); - - num_of_get = monkey_recorder_get_next(monkey, - &cur_time_stamp, - &cur_state, - &next_time_stamp, - &next_state); - - switch (num_of_get) - { - case 1: - next_time_stamp = cur_time_stamp; - memset(&monkey->playback_ctx, 0, sizeof(monkey->playback_ctx)); - monkey_recorder_reset(monkey->recorder); - case 2: - monkey_dev_set_state(monkey->input_gen_ctx, &cur_state); - tick_elaps = monkey_tick_elaps(next_time_stamp, cur_time_stamp); - monkey_set_period(monkey, tick_elaps); - break; - - default: - MONKEY_LOG_ERROR("error num_of_get = %d", num_of_get); - return false; - } - - return true; -} - -/**************************************************************************** - * Name: monkey_update_uinput - ****************************************************************************/ - -static bool monkey_update_uinput(FAR struct monkey_s *monkey) -{ - bool retval = false; - MONKEY_ASSERT_NULL(monkey); - - if (monkey->mode == MONKEY_MODE_RANDOM) - { - retval = monkey_update_uinput_random(monkey); - } - else if(monkey->mode == MONKEY_MODE_PLAYBACK) - { - retval = monkey_update_uinput_playback(monkey); - } - else - { - MONKEY_LOG_ERROR("error mode: %d", monkey->mode); - } - - return retval; -} - -/**************************************************************************** - * Name: monkey_update_input - ****************************************************************************/ - -static bool monkey_update_input(FAR struct monkey_s *monkey) -{ - struct monkey_dev_state_s state; - int available; - int i; - - MONKEY_ASSERT_NULL(monkey); - - available = monkey_dev_get_available(monkey->devs, monkey->dev_num); - - if (available <= 0) - { - MONKEY_LOG_WARN("no available device"); - return false; - } - - for (i = 0; i < monkey->dev_num; i++) - { - FAR struct monkey_dev_s *dev = monkey->devs[i]; - if (dev->is_available) - { - /* try to get device state */ - - if (!monkey_dev_get_state(dev, &state)) - { - MONKEY_LOG_ERROR("can't get state"); - return false; - } - - if (dev->type == MONKEY_DEV_TYPE_TOUCH) - { - MONKEY_LOG_INFO("touch %s at x = %d, y = %d", - state.data.touch.is_pressed - ? "PRESS " : "RELEASE", - state.data.touch.x, state.data.touch.y); - } - else if (dev->type == MONKEY_DEV_TYPE_BUTTON) - { - MONKEY_LOG_INFO("btn = 0x%08X", state.data.button.value); - } - - /* record state */ - - if (monkey->recorder) - { - monkey_recorder_write(monkey->recorder, &state); - } - } - } - - return true; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: monkey_update - ****************************************************************************/ - -int monkey_update(FAR struct monkey_s *monkey) -{ - int wait_time; - MONKEY_ASSERT_NULL(monkey); - - srand(monkey_tick_get()); - - if (monkey->mode == MONKEY_MODE_RECORD) - { - if (monkey_update_input(monkey)) - { - /* no need for sleep */ - - return 0; - } - else - { - return -1; - } - } - else - { - if (!monkey_update_uinput(monkey)) - { - return -1; - } - } - - wait_time = monkey_random(monkey->config.period.min, - monkey->config.period.max); - - return wait_time; -} diff --git a/graphics/input/monkey/monkey_recorder.c b/graphics/input/monkey/monkey_recorder.c deleted file mode 100644 index 13a41d8ff..000000000 --- a/graphics/input/monkey/monkey_recorder.c +++ /dev/null @@ -1,348 +0,0 @@ -/**************************************************************************** - * apps/graphics/input/monkey/monkey_recorder.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "monkey_assert.h" -#include "monkey_log.h" -#include "monkey_dev.h" -#include "monkey_recorder.h" -#include "monkey_utils.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define MONKEY_REC_HEAD_FMT "T%" PRIu32 ",D%X," -#define MONKEY_REC_TOUCH_FMT MONKEY_REC_HEAD_FMT "X%d,Y%d,PR%d\n" -#define MONKEY_REC_BTN_FMT MONKEY_REC_HEAD_FMT "V%" PRIu32 "\n" -#define MONKEY_REC_FILE_EXT ".csv" -#define MONKEY_REC_FILE_HEAD "rec_" - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: monkey_recorder_gen_file_path - ****************************************************************************/ - -static void monkey_recorder_gen_file_path(FAR char *path_buf, - size_t buf_size, - FAR const char *dir_path) -{ - char localtime_str_buf[64]; - - monkey_get_localtime_str(localtime_str_buf, sizeof(localtime_str_buf)); - - snprintf(path_buf, buf_size, - "%s/" MONKEY_REC_FILE_HEAD "%s" MONKEY_REC_FILE_EXT, - dir_path, - localtime_str_buf); -} - -/**************************************************************************** - * Name: monkey_readline - ****************************************************************************/ - -static int monkey_readline(int fd, FAR char *ptr, int maxlen) -{ - int n; - int rc; - char c; - for (n = 1; n < maxlen; n++) - { - if ((rc = read(fd, &c, 1)) == 1) - { - *ptr++ = c; - if (c == '\n') - { - break; - } - } - else if (rc == 0) - { - if (n == 1) - { - /* EOF no data read */ - - return 0; - } - else - { - /* EOF, some data read */ - - break; - } - } - else - { - /* error */ - - return -1; - } - } - - *ptr = 0; - return n; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: monkey_recorder_create - ****************************************************************************/ - -FAR struct monkey_recorder_s *monkey_recorder_create(FAR const char *path, - enum monkey_recorder_mode_e mode) -{ - char file_path[PATH_MAX]; - FAR const char *path_ptr; - int oflag; - int fd; - FAR struct monkey_recorder_s *recorder; - - MONKEY_ASSERT_NULL(path); - - recorder = calloc(1, sizeof(struct monkey_recorder_s)); - MONKEY_ASSERT_NULL(recorder); - - if (mode == MONKEY_RECORDER_MODE_RECORD) - { - if (!monkey_dir_check(path)) - { - goto failed; - } - - monkey_recorder_gen_file_path(file_path, - sizeof(file_path), - path); - path_ptr = file_path; - oflag = O_WRONLY | O_CREAT; - } - else - { - path_ptr = path; - oflag = O_RDONLY; - } - - fd = open(path_ptr, oflag, 0666); - if (fd < 0) - { - MONKEY_LOG_ERROR("open %s failed: %d", path_ptr, errno); - goto failed; - } - - recorder->fd = fd; - recorder->mode = mode; - - MONKEY_LOG_NOTICE("open %s success, fd = %d, mode = %d", - path_ptr, fd, mode); - - return recorder; - -failed: - if (fd > 0) - { - close(fd); - } - - if (recorder) - { - free(recorder); - } - - return NULL; -} - -/**************************************************************************** - * Name: monkey_recorder_delete - ****************************************************************************/ - -void monkey_recorder_delete(FAR struct monkey_recorder_s *recorder) -{ - MONKEY_ASSERT_NULL(recorder); - if (recorder->fd > 0) - { - MONKEY_LOG_NOTICE("close fd: %d", recorder->fd); - close(recorder->fd); - } - - free(recorder); -} - -/**************************************************************************** - * Name: monkey_recorder_write - ****************************************************************************/ - -enum monkey_recorder_res_e monkey_recorder_write( - FAR struct monkey_recorder_s *recorder, - FAR const struct monkey_dev_state_s *state) -{ - char buffer[128]; - int len = -1; - int ret; - uint32_t cur_tick; - - MONKEY_ASSERT_NULL(recorder); - MONKEY_ASSERT(recorder->mode == MONKEY_RECORDER_MODE_RECORD); - - cur_tick = monkey_tick_get(); - - switch (MONKEY_GET_DEV_TYPE(state->type)) - { - case MONKEY_DEV_TYPE_TOUCH: - len = snprintf(buffer, sizeof(buffer), MONKEY_REC_TOUCH_FMT, - cur_tick, - state->type, - state->data.touch.x, - state->data.touch.y, - state->data.touch.is_pressed); - break; - - case MONKEY_DEV_TYPE_BUTTON: - len = snprintf(buffer, sizeof(buffer), MONKEY_REC_BTN_FMT, - cur_tick, - state->type, - state->data.button.value); - break; - - default: - return MONKEY_RECORDER_RES_DEV_TYPE_ERROR; - } - - if (len <= 0) - { - return MONKEY_RECORDER_RES_PARSER_ERROR; - } - - ret = write(recorder->fd, buffer, len); - if (ret < 0) - { - return MONKEY_RECORDER_RES_WRITE_ERROR; - } - - return MONKEY_RECORDER_RES_OK; -} - -/**************************************************************************** - * Name: monkey_recorder_read - ****************************************************************************/ - -enum monkey_recorder_res_e monkey_recorder_read( - FAR struct monkey_recorder_s *recorder, - FAR struct monkey_dev_state_s *state, - FAR uint32_t *time_stamp) -{ - char buffer[128]; - int dev_type; - int converted; - int ret; - - MONKEY_ASSERT_NULL(recorder); - MONKEY_ASSERT(recorder->mode == MONKEY_RECORDER_MODE_PLAYBACK); - - ret = monkey_readline(recorder->fd, buffer, sizeof(buffer)); - - if (ret < 0) - { - return MONKEY_RECORDER_RES_READ_ERROR; - } - - if (ret == 0) - { - return MONKEY_RECORDER_RES_END_OF_FILE; - } - - /* Read head to get device type */ - - converted = sscanf(buffer, MONKEY_REC_HEAD_FMT, time_stamp, &dev_type); - - if (converted != 2) - { - return MONKEY_RECORDER_RES_PARSER_ERROR; - } - - state->type = dev_type; - - /* Get data */ - - switch (MONKEY_GET_DEV_TYPE(state->type)) - { - case MONKEY_DEV_TYPE_TOUCH: - converted = sscanf(buffer, - MONKEY_REC_TOUCH_FMT, - time_stamp, - &dev_type, - &state->data.touch.x, - &state->data.touch.y, - &state->data.touch.is_pressed); - if (converted != 5) - { - return MONKEY_RECORDER_RES_PARSER_ERROR; - } - break; - - case MONKEY_DEV_TYPE_BUTTON: - converted = sscanf(buffer, - MONKEY_REC_BTN_FMT, - time_stamp, - &dev_type, - &state->data.button.value); - if (converted != 3) - { - return MONKEY_RECORDER_RES_PARSER_ERROR; - } - break; - - default: - return MONKEY_RECORDER_RES_DEV_TYPE_ERROR; - } - - return MONKEY_RECORDER_RES_OK; -} - -/**************************************************************************** - * Name: monkey_recorder_reset - ****************************************************************************/ - -enum monkey_recorder_res_e monkey_recorder_reset( - FAR struct monkey_recorder_s *recorder) -{ - MONKEY_ASSERT_NULL(recorder); - lseek(recorder->fd, 0, SEEK_SET); - return MONKEY_RECORDER_RES_OK; -} diff --git a/graphics/input/monkey/monkey_recorder.h b/graphics/input/monkey/monkey_recorder.h deleted file mode 100644 index 7dee8ae56..000000000 --- a/graphics/input/monkey/monkey_recorder.h +++ /dev/null @@ -1,112 +0,0 @@ -/**************************************************************************** - * apps/graphics/input/monkey/monkey_recorder.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __APPS_GRAPHICS_INPUT_MONKEY_MONKEY_RECORDER_H -#define __APPS_GRAPHICS_INPUT_MONKEY_MONKEY_RECORDER_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "monkey_type.h" - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -enum monkey_recorder_mode_e -{ - MONKEY_RECORDER_MODE_RECORD, - MONKEY_RECORDER_MODE_PLAYBACK -}; - -struct monkey_recorder_s -{ - int fd; - enum monkey_recorder_mode_e mode; -}; - -enum monkey_recorder_res_e -{ - MONKEY_RECORDER_RES_OK, - MONKEY_RECORDER_RES_END_OF_FILE, - MONKEY_RECORDER_RES_DEV_TYPE_ERROR, - MONKEY_RECORDER_RES_WRITE_ERROR, - MONKEY_RECORDER_RES_READ_ERROR, - MONKEY_RECORDER_RES_PARSER_ERROR -}; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -#ifdef __cplusplus -#define EXTERN extern "C" -extern "C" -{ -#else -#define EXTERN extern -#endif - -/**************************************************************************** - * Name: monkey_recorder_create - ****************************************************************************/ - -FAR struct monkey_recorder_s *monkey_recorder_create(FAR const char *path, - enum monkey_recorder_mode_e mode); - -/**************************************************************************** - * Name: monkey_recorder_delete - ****************************************************************************/ - -void monkey_recorder_delete(FAR struct monkey_recorder_s *recorder); - -/**************************************************************************** - * Name: monkey_recorder_write - ****************************************************************************/ - -enum monkey_recorder_res_e monkey_recorder_write( - FAR struct monkey_recorder_s *recorder, - FAR const struct monkey_dev_state_s *state); - -/**************************************************************************** - * Name: monkey_recorder_read - ****************************************************************************/ - -enum monkey_recorder_res_e monkey_recorder_read( - FAR struct monkey_recorder_s *recorder, - FAR struct monkey_dev_state_s *state, - FAR uint32_t *time_stamp); - -/**************************************************************************** - * Name: monkey_recorder_reset - ****************************************************************************/ - -enum monkey_recorder_res_e monkey_recorder_reset( - FAR struct monkey_recorder_s *recorder); - -#undef EXTERN -#ifdef __cplusplus -} -#endif - -#endif /* __APPS_GRAPHICS_INPUT_MONKEY_MONKEY_RECORDER_H */ diff --git a/graphics/input/monkey/monkey_type.h b/graphics/input/monkey/monkey_type.h deleted file mode 100644 index 90fe442b7..000000000 --- a/graphics/input/monkey/monkey_type.h +++ /dev/null @@ -1,136 +0,0 @@ -/**************************************************************************** - * apps/graphics/input/monkey/monkey_type.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __APPS_GRAPHICS_INPUT_MONKEY_MONKEY_TYPE_H -#define __APPS_GRAPHICS_INPUT_MONKEY_MONKEY_TYPE_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define MONKEY_UINPUT_TYPE_MASK (0x10) -#define MONKEY_IS_UINPUT_TYPE(type) (!!((type) & MONKEY_UINPUT_TYPE_MASK)) -#define MONKEY_GET_DEV_TYPE(type) ((type) & ~MONKEY_UINPUT_TYPE_MASK) -#define MONKEY_DEV_MAX_NUM 2 - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -struct monkey_dev_s; -struct monkey_recorder_s; - -enum monkey_mode_e -{ - MONKEY_MODE_RANDOM, - MONKEY_MODE_RECORD, - MONKEY_MODE_PLAYBACK, -}; - -enum monkey_dev_type_e -{ - MONKEY_DEV_TYPE_UNKNOW = 0x00, - MONKEY_DEV_TYPE_TOUCH = 0x01, - MONKEY_DEV_TYPE_BUTTON = 0x02, - MONKEY_DEV_TYPE_UTOUCH = MONKEY_UINPUT_TYPE_MASK | MONKEY_DEV_TYPE_TOUCH, - MONKEY_DEV_TYPE_UBUTTON = MONKEY_UINPUT_TYPE_MASK | MONKEY_DEV_TYPE_BUTTON, -}; - -enum monkey_event_e -{ - MONKEY_EVENT_CLICK, - MONKEY_EVENT_LONG_PRESS, - MONKEY_EVENT_DRAG, - MONKEY_EVENT_LAST -}; - -struct monkey_dev_state_s -{ - enum monkey_dev_type_e type; - union - { - struct - { - int x; - int y; - int is_pressed; - } touch; - - struct - { - uint32_t value; - } button; - } data; -}; - -struct monkey_event_config_s -{ - int weight; - int duration_min; - int duration_max; -}; - -struct monkey_config_s -{ - struct - { - int x_offset; - int y_offset; - int hor_res; - int ver_res; - } screen; - - struct - { - uint32_t min; - uint32_t max; - } period; - - uint8_t btn_bit; - - struct monkey_event_config_s event[MONKEY_EVENT_LAST]; -}; - -struct monkey_s -{ - struct monkey_config_s config; - enum monkey_mode_e mode; - FAR struct monkey_dev_s *devs[MONKEY_DEV_MAX_NUM]; - int dev_num; - FAR struct monkey_recorder_s *recorder; - input_gen_ctx_t input_gen_ctx; - struct - { - struct monkey_dev_state_s state; - uint32_t time_stamp; - } playback_ctx; -}; - -#endif /* __APPS_GRAPHICS_INPUT_MONKEY_MONKEY_TYPE_H */ diff --git a/graphics/input/monkey/monkey_utils.c b/graphics/input/monkey/monkey_utils.c deleted file mode 100644 index 57c6c4fac..000000000 --- a/graphics/input/monkey/monkey_utils.c +++ /dev/null @@ -1,220 +0,0 @@ -/**************************************************************************** - * apps/graphics/input/monkey/monkey_utils.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include -#include -#include -#include -#include -#include "monkey_log.h" -#include "monkey_utils.h" - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -struct monkey_port_dev_type_name_s -{ - enum monkey_dev_type_e type; - FAR const char *name; -}; - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static const struct monkey_port_dev_type_name_s g_type_name_grp[] = -{ - { MONKEY_DEV_TYPE_TOUCH, "touch" }, - { MONKEY_DEV_TYPE_BUTTON, "button" }, - { MONKEY_DEV_TYPE_UTOUCH, "utouch" }, - { MONKEY_DEV_TYPE_UBUTTON, "ubutton" } -}; - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: monkey_random - ****************************************************************************/ - -int monkey_random(int min, int max) -{ - if (min >= max) - { - return min; - } - - long diff = max - min + 1; - return rand() % diff + min; -} - -/**************************************************************************** - * Name: monkey_tick_get - ****************************************************************************/ - -uint32_t monkey_tick_get(void) -{ - struct timespec ts; - uint32_t ms; - clock_gettime(CLOCK_MONOTONIC, &ts); - ms = ts.tv_sec * 1000 + ts.tv_nsec / 1000000; - return ms; -} - -/**************************************************************************** - * Name: monkey_tick_elaps - ****************************************************************************/ - -uint32_t monkey_tick_elaps(uint32_t act_time, uint32_t prev_tick) -{ - /* If there is no overflow in sys_time simple subtract */ - - if (act_time >= prev_tick) - { - prev_tick = act_time - prev_tick; - } - else - { - prev_tick = UINT32_MAX - prev_tick + 1; - prev_tick += act_time; - } - - return prev_tick; -} - -/**************************************************************************** - * Name: monkey_get_localtime_str - ****************************************************************************/ - -void monkey_get_localtime_str(FAR char *str_buf, size_t buf_size) -{ - time_t rawtime; - FAR struct tm *timeinfo; - - time(&rawtime); - timeinfo = localtime(&rawtime); - snprintf(str_buf, buf_size, "%04d%02d%02d_%02d%02d%02d", - 1900 + timeinfo->tm_year, - timeinfo->tm_mon, timeinfo->tm_mday, timeinfo->tm_hour, - timeinfo->tm_min, timeinfo->tm_sec); -} - -/**************************************************************************** - * Name: monkey_dir_check - ****************************************************************************/ - -bool monkey_dir_check(FAR const char *dir_path) -{ - bool retval = false; - if (access(dir_path, F_OK) == 0) - { - MONKEY_LOG_NOTICE("directory: %s already exists", dir_path); - retval = true; - } - else - { - MONKEY_LOG_WARN("can't access directory: %s, creating...", dir_path); - if (mkdir(dir_path, 0777) == 0) - { - MONKEY_LOG_NOTICE("OK"); - retval = true; - } - else - { - MONKEY_LOG_ERROR("create directory: %s failed", dir_path); - } - } - - return retval; -} - -/**************************************************************************** - * Name: monkey_dev_type2name - ****************************************************************************/ - -FAR const char *monkey_dev_type2name(enum monkey_dev_type_e type) -{ - int i; - const int grp_len = sizeof(g_type_name_grp) - / sizeof(struct monkey_port_dev_type_name_s); - for (i = 0; i < grp_len; i++) - { - if (type == g_type_name_grp[i].type) - { - return g_type_name_grp[i].name; - } - } - - return "unknown"; -} - -/**************************************************************************** - * Name: monkey_dev_name2type - ****************************************************************************/ - -enum monkey_dev_type_e monkey_dev_name2type(FAR const char *name) -{ - int i; - const int grp_len = sizeof(g_type_name_grp) - / sizeof(struct monkey_port_dev_type_name_s); - if (name) - { - for (i = 0; i < grp_len; i++) - { - if (strcmp(name, g_type_name_grp[i].name) == 0) - { - return g_type_name_grp[i].type; - } - } - } - - return MONKEY_DEV_TYPE_UNKNOW; -} - -/**************************************************************************** - * Name: monkey_event_type2name - ****************************************************************************/ - -FAR const char *monkey_event_type2name(enum monkey_event_e event) -{ - switch (event) - { - case MONKEY_EVENT_CLICK: - return "click"; - case MONKEY_EVENT_LONG_PRESS: - return "long-press"; - case MONKEY_EVENT_DRAG: - return "drag"; - default: - break; - } - - return "unknown"; -} diff --git a/graphics/input/monkey/monkey_utils.h b/graphics/input/monkey/monkey_utils.h deleted file mode 100644 index 3577390e3..000000000 --- a/graphics/input/monkey/monkey_utils.h +++ /dev/null @@ -1,102 +0,0 @@ -/**************************************************************************** - * apps/graphics/input/monkey/monkey_utils.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __APPS_GRAPHICS_INPUT_MONKEY_MONKEY_UTILS_H -#define __APPS_GRAPHICS_INPUT_MONKEY_MONKEY_UTILS_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include "monkey_type.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#ifdef __cplusplus -#define EXTERN extern "C" -extern "C" -{ -#else -#define EXTERN extern -#endif - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Name: monkey_random - ****************************************************************************/ - -int monkey_random(int min, int max); - -/**************************************************************************** - * Name: monkey_tick_get - ****************************************************************************/ - -uint32_t monkey_tick_get(void); - -/**************************************************************************** - * Name: monkey_tick_elaps - ****************************************************************************/ - -uint32_t monkey_tick_elaps(uint32_t act_time, uint32_t prev_tick); - -/**************************************************************************** - * Name: monkey_get_localtime_str - ****************************************************************************/ - -void monkey_get_localtime_str(FAR char *str_buf, size_t buf_size); - -/**************************************************************************** - * Name: monkey_dir_check - ****************************************************************************/ - -bool monkey_dir_check(FAR const char *dir_path); - -/**************************************************************************** - * Name: monkey_dev_type2name - ****************************************************************************/ - -FAR const char *monkey_dev_type2name(enum monkey_dev_type_e type); - -/**************************************************************************** - * Name: monkey_dev_name2type - ****************************************************************************/ - -enum monkey_dev_type_e monkey_dev_name2type(FAR const char *name); - -/**************************************************************************** - * Name: monkey_event_type2name - ****************************************************************************/ - -FAR const char *monkey_event_type2name(enum monkey_event_e event); - -#undef EXTERN -#ifdef __cplusplus -} -#endif - -#endif /* __APPS_GRAPHICS_INPUT_MONKEY_MONKEY_UTILS_H */ diff --git a/graphics/jpgresizetool/CMakeLists.txt b/graphics/jpgresizetool/CMakeLists.txt deleted file mode 100644 index 3afa2ce75..000000000 --- a/graphics/jpgresizetool/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# ############################################################################## -# apps/graphics/jpgresizetool/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_GRAPHICS_JPGRESIZETOOL) - nuttx_add_application( - NAME - jpgresize - STACKSIZE - 4096 - MODULE - ${CONFIG_GRAPHICS_JPGRESIZETOOL} - SRCS - resize.c) -endif() diff --git a/graphics/jpgresizetool/Kconfig b/graphics/jpgresizetool/Kconfig deleted file mode 100644 index a1ff56f5d..000000000 --- a/graphics/jpgresizetool/Kconfig +++ /dev/null @@ -1,11 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config GRAPHICS_JPGRESIZETOOL - bool "JPGResizeTool" - default n - depends on libjpeg - ---help--- - Libjpeg JPEG resizer diff --git a/graphics/jpgresizetool/Make.defs b/graphics/jpgresizetool/Make.defs deleted file mode 100644 index 1409a3ffb..000000000 --- a/graphics/jpgresizetool/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/graphics/jpgresizetool/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_GRAPHICS_JPGRESIZETOOL),) -CONFIGURED_APPS += $(APPDIR)/graphics/jpgresizetool -endif diff --git a/graphics/jpgresizetool/resize.c b/graphics/jpgresizetool/resize.c deleted file mode 100644 index 93caaf7f9..000000000 --- a/graphics/jpgresizetool/resize.c +++ /dev/null @@ -1,200 +0,0 @@ -/**************************************************************************** - * apps/graphics/jpgresizetool/resize.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/* Every N line, report resizing progress */ -#define JPEGRESIZE_PROGRESS_INTERVAL 40 - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/* Usage: jpgresize input.jpg output.jpg scale_denom quality% - * scale_denom: 1, 2, 4, 8. Shrinks image by scale_denom times. - * quality: 1% to 100%. 20% heavy compression, 80% nearly original. - * thumbnail example: - * jpgresize /sd/IMAGES/000000a1.jpg /sd/TEMP/THUMBS/000000a1.jpg 8 20 - */ - -int main(int argc, char *argv[]) -{ - struct jpeg_compress_struct cinfo_out; - struct jpeg_decompress_struct cinfo; - struct jpeg_error_mgr jerr_out; - struct jpeg_error_mgr jerr; - const char *output_filename; - const char *input_filename; - uint8_t togglechar; - JSAMPARRAY buffer; - FILE *outfile; - FILE *infile; - int scale_denom; - int pixel_size; - int quality; - int height; - int width; - - /* Take arguments */ - - if (argc != 5) - { - fprintf(stderr, - "Usage: %s input.jpg output.jpg scale_denom(1, 2, 4, 8) quality%%\n", - argv[0]); - return -1; - } - - scale_denom = atoi(argv[3]); - if (scale_denom != 1 && scale_denom != 2 && scale_denom != 4 && - scale_denom != 8 && scale_denom != 16) - { - fprintf(stderr, "scale_denom must be 1, 2, 4 or 8\n"); - return -1; - } - - input_filename = argv[1]; - output_filename = argv[2]; - quality = atoi(argv[4]); - - /* Opening input */ - - infile = fopen(input_filename, "rb"); - if (!infile) - { - perror("fopen input"); - return -1; - } - - /* Configuring decompressor */ - - cinfo.err = jpeg_std_error(&jerr); - jpeg_create_decompress(&cinfo); - jpeg_stdio_src(&cinfo, infile); - jpeg_read_header(&cinfo, TRUE); - - cinfo.scale_num = 1; - cinfo.scale_denom = scale_denom; - jpeg_start_decompress(&cinfo); - - width = cinfo.output_width; - height = cinfo.output_height; - pixel_size = cinfo.output_components; - - /* Opening output */ - - outfile = fopen(output_filename, "wb"); - if (!outfile) - { - perror("fopen output"); - jpeg_destroy_decompress(&cinfo); - fclose(infile); - return -1; - } - - /* Configuring compressor */ - - cinfo_out.err = jpeg_std_error(&jerr_out); - jpeg_create_compress(&cinfo_out); - jpeg_stdio_dest(&cinfo_out, outfile); - - cinfo_out.image_width = width; - cinfo_out.image_height = height; - cinfo_out.input_components = pixel_size; - cinfo_out.in_color_space = cinfo.out_color_space; - jpeg_set_defaults(&cinfo_out); - jpeg_set_quality(&cinfo_out, quality, TRUE); - jpeg_start_compress(&cinfo_out, TRUE); - - /* Allocating memory by using JPEG their own allocator. Do not use malloc */ - - printf("Allocating... \r"); - buffer = (*cinfo.mem->alloc_sarray) - ((j_common_ptr)&cinfo, JPOOL_IMAGE, width * pixel_size, 1); - - /* Start the job */ - - printf("Resizing... \n"); - togglechar = 0; - while (cinfo.output_scanline < cinfo.output_height) - { - /* Pretty loading bar... */ - - if (cinfo.output_scanline % JPEGRESIZE_PROGRESS_INTERVAL == 1) - { - printf("\r[%u%%]", - (unsigned)(((float)cinfo.output_scanline - / cinfo.output_height) - * 100)); - togglechar = !togglechar; - } - - if (togglechar) - { - printf("-"); - } - else - { - printf("#"); - } - - fflush(stdout); - - /* Actual work */ - - jpeg_read_scanlines(&cinfo, buffer, 1); - jpeg_write_scanlines(&cinfo_out, buffer, 1); - } - - /* Erase progress bar */ - - printf("\r "); - for (size_t i = 0; i < JPEGRESIZE_PROGRESS_INTERVAL; i++) - { - printf(" "); - } - - /* All done */ - - printf("\rDone\n"); - - jpeg_finish_compress(&cinfo_out); - jpeg_destroy_compress(&cinfo_out); - fclose(outfile); - - jpeg_finish_decompress(&cinfo); - jpeg_destroy_decompress(&cinfo); - fclose(infile); - - printf("Resized JPEG written to %s\n", output_filename); - return 0; -} diff --git a/graphics/libjpeg/0001-libjpeg-add-preconfigured-jconfig.h.patch b/graphics/libjpeg/0001-libjpeg-add-preconfigured-jconfig.h.patch deleted file mode 100644 index 0e7cbd7e9..000000000 --- a/graphics/libjpeg/0001-libjpeg-add-preconfigured-jconfig.h.patch +++ /dev/null @@ -1,82 +0,0 @@ -From a6220cb02fdab278588dad24ec55aef28de8f005 Mon Sep 17 00:00:00 2001 -From: Alin Jerpelea -Date: Tue, 18 Oct 2022 12:18:59 +0200 -Subject: [PATCH] libjpeg: add preconfigured jconfig.h - -Add a generated header with configuration for libjpeg. - -Signed-off-by: Alin Jerpelea ---- - libjpeg/jconfig.h | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ - 1 file changed, 60 insertions(+) - create mode 100644 jconfig.h - -diff --git a/libjpeg/jconfig.h b/libjpeg/jconfig.h -new file mode 100644 -index 0000000..2d05a3b ---- /dev/null -+++ b/libjpeg/jconfig.h -@@ -0,0 +1,60 @@ -+/* jconfig.h. Generated from jconfig.cfg by configure. */ -+/* jconfig.cfg --- source file edited by configure script */ -+/* see jconfig.txt for explanations */ -+ -+#define HAVE_PROTOTYPES 1 -+#define HAVE_UNSIGNED_CHAR 1 -+#define HAVE_UNSIGNED_SHORT 1 -+/* #undef void */ -+/* #undef const */ -+/* #undef CHAR_IS_UNSIGNED */ -+#define HAVE_STDDEF_H 1 -+#define HAVE_STDLIB_H 1 -+#define HAVE_LOCALE_H 1 -+/* #undef NEED_BSD_STRINGS */ -+/* #undef NEED_SYS_TYPES_H */ -+/* #undef NEED_FAR_POINTERS */ -+/* #undef NEED_SHORT_EXTERNAL_NAMES */ -+/* Define this if you get warnings about undefined structures. */ -+/* #undef INCOMPLETE_TYPES_BROKEN */ -+ -+/* Define "boolean" as unsigned char, not enum, on Windows systems. */ -+#ifdef _WIN32 -+#ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */ -+typedef unsigned char boolean; -+#endif -+#ifndef FALSE /* in case these macros already exist */ -+#define FALSE 0 /* values of boolean */ -+#endif -+#ifndef TRUE -+#define TRUE 1 -+#endif -+#define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */ -+#endif -+ -+#ifdef JPEG_INTERNALS -+ -+/* #undef RIGHT_SHIFT_IS_UNSIGNED */ -+#define INLINE __inline__ -+/* These are for configuring the JPEG memory manager. */ -+/* #undef DEFAULT_MAX_MEM */ -+/* #undef NO_MKTEMP */ -+ -+#endif /* JPEG_INTERNALS */ -+ -+#ifdef JPEG_CJPEG_DJPEG -+ -+#define BMP_SUPPORTED /* BMP image file format */ -+#define GIF_SUPPORTED /* GIF image file format */ -+#define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */ -+/* #undef RLE_SUPPORTED */ -+#define TARGA_SUPPORTED /* Targa image file format */ -+ -+/* #undef TWO_FILE_COMMANDLINE */ -+/* #undef NEED_SIGNAL_CATCHER */ -+/* #undef DONT_USE_B_MODE */ -+ -+/* Define this if you want percent-done progress reports from cjpeg/djpeg. */ -+/* #undef PROGRESS_REPORT */ -+ -+#endif /* JPEG_CJPEG_DJPEG */ --- -2.37.1 - diff --git a/graphics/libjpeg/Kconfig b/graphics/libjpeg/Kconfig deleted file mode 100644 index 2f2e714f0..000000000 --- a/graphics/libjpeg/Kconfig +++ /dev/null @@ -1,34 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config LIBJPEG - bool "libjpeg" - default n - ---help--- - Enable libjpeg. - This package contains C software to implement JPEG image encoding, decoding, - and transcoding. JPEG is a standardized compression method for full-color - and grayscale images. - The distributed programs provide conversion between JPEG JFIF format and - image files in PBMPLUS PPM/PGM, GIF, BMP, and Targa file formats. The - core compression and decompression library can easily be reused in other - programs, such as image viewers. The package is highly portable C code; - we have tested it on many machines ranging from PCs to Crays. - libjpeg is provided from http://www.ijg.org/ - -if LIBJPEG - -config LIBJPEG_VER - string "libjpeg version" - default "9c" - -config LIBJPEG_TEMP_DIR - string "Temporary directory" - default "/mnt/spif/" - ---help--- - This is the directory path including the trailing slash '/' - to store the temporary files created by libjpeg. - -endif # LIBJPEG diff --git a/graphics/libjpeg/Make.defs b/graphics/libjpeg/Make.defs deleted file mode 100644 index 57ac03076..000000000 --- a/graphics/libjpeg/Make.defs +++ /dev/null @@ -1,28 +0,0 @@ -############################################################################ -# apps/graphics/libjpeg/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_LIBJPEG),) -CONFIGURED_APPS += $(APPDIR)/graphics/libjpeg - -CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/graphics/libjpeg/libjpeg -CXXFLAGS += ${INCDIR_PREFIX}$(APPDIR)/graphics/libjpeg/libjpeg -endif diff --git a/graphics/libjpeg/Makefile b/graphics/libjpeg/Makefile deleted file mode 100644 index 5e94447b0..000000000 --- a/graphics/libjpeg/Makefile +++ /dev/null @@ -1,101 +0,0 @@ -############################################################################ -# apps/graphics/libjpeg/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -SRC = libjpeg - -# Decompressor - -CSRCS += $(SRC)/jaricom.c -CSRCS += $(SRC)/jcomapi.c -CSRCS += $(SRC)/jdapimin.c -CSRCS += $(SRC)/jdapistd.c -CSRCS += $(SRC)/jdarith.c -CSRCS += $(SRC)/jdatasrc.c -CSRCS += $(SRC)/jdcoefct.c -CSRCS += $(SRC)/jdcolor.c -CSRCS += $(SRC)/jddctmgr.c -CSRCS += $(SRC)/jdhuff.c -CSRCS += $(SRC)/jdinput.c -CSRCS += $(SRC)/jdmainct.c -CSRCS += $(SRC)/jdmarker.c -CSRCS += $(SRC)/jdmaster.c -CSRCS += $(SRC)/jdmerge.c -CSRCS += $(SRC)/jdpostct.c -CSRCS += $(SRC)/jdsample.c -CSRCS += $(SRC)/jdtrans.c -CSRCS += $(SRC)/jerror.c -CSRCS += $(SRC)/jidctflt.c -CSRCS += $(SRC)/jidctfst.c -CSRCS += $(SRC)/jidctint.c -CSRCS += $(SRC)/jquant1.c -CSRCS += $(SRC)/jquant2.c -CSRCS += $(SRC)/jutils.c -CSRCS += $(SRC)/jmemmgr.c -CSRCS += $(SRC)/jmemname.c - -# Compressor - -CSRCS += $(SRC)/jcapimin.c -CSRCS += $(SRC)/jcapistd.c -CSRCS += $(SRC)/jcarith.c -CSRCS += $(SRC)/jccoefct.c -CSRCS += $(SRC)/jccolor.c -CSRCS += $(SRC)/jcdctmgr.c -CSRCS += $(SRC)/jchuff.c -CSRCS += $(SRC)/jcinit.c -CSRCS += $(SRC)/jcmainct.c -CSRCS += $(SRC)/jcmarker.c -CSRCS += $(SRC)/jcmaster.c -CSRCS += $(SRC)/jcparam.c -CSRCS += $(SRC)/jcprepct.c -CSRCS += $(SRC)/jcsample.c -CSRCS += $(SRC)/jctrans.c - -CSRCS += $(SRC)/jdatadst.c -CSRCS += $(SRC)/jfdctint.c -CSRCS += $(SRC)/jfdctfst.c -CSRCS += $(SRC)/jfdctflt.c - -CFLAGS += -DTEMP_DIRECTORY=\"$(CONFIG_EXTERNALS_LIBJPEG_TEMP_DIR)\" - -CFLAGS += -Wno-shadow -Wno-strict-prototypes -Wno-unknown-pragmas - -MODULE = $(CONFIG_LIBJPEG) - -libjpeg.tar.gz: - $(Q) curl -L http://www.ijg.org/files/jpegsrc.v$(CONFIG_LIBJPEG_VER).tar.gz -o libjpeg.tar.gz - $(Q) tar xf libjpeg.tar.gz - $(Q) mv jpeg-$(CONFIG_LIBJPEG_VER) libjpeg - $(Q) patch -Np1 <0001-libjpeg-add-preconfigured-jconfig.h.patch - -# Download and unpack tarball if no git repo found -ifeq ($(wildcard libjpeg/libjpeg),) -context:: libjpeg.tar.gz - -distclean:: - $(call DELDIR, libjpeg) - $(call DELFILE, libjpeg.tar.gz) -endif - -include $(APPDIR)/Application.mk diff --git a/graphics/libyuv/.gitignore b/graphics/libyuv/.gitignore deleted file mode 100644 index 23b19093e..000000000 --- a/graphics/libyuv/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -libyuv -*.tar.gz diff --git a/graphics/libyuv/0001-include-libyuv-fix-strict-prototype-warning.patch b/graphics/libyuv/0001-include-libyuv-fix-strict-prototype-warning.patch deleted file mode 100644 index 6fdacd5f3..000000000 --- a/graphics/libyuv/0001-include-libyuv-fix-strict-prototype-warning.patch +++ /dev/null @@ -1,26 +0,0 @@ -From d498349aeb061ab92e6f5eba2538d9f35206697c Mon Sep 17 00:00:00 2001 -From: Peter Bee -Date: Fri, 9 Dec 2022 13:36:33 +0800 -Subject: [PATCH] include/libyuv: fix strict-prototype warning - -Signed-off-by: Peter Bee ---- - include/libyuv/planar_functions.h | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/include/libyuv/planar_functions.h libyuv/include/libyuv/planar_functions.h -index fdecdee..3ae8896 100644 ---- a/include/libyuv/planar_functions.h -+++ libyuv/include/libyuv/planar_functions.h -@@ -744,7 +744,7 @@ typedef void (*ARGBBlendRow)(const uint8_t* src_argb0, - - // Get function to Alpha Blend ARGB pixels and store to destination. - LIBYUV_API --ARGBBlendRow GetARGBBlend(); -+ARGBBlendRow GetARGBBlend(void); - - // Alpha Blend ARGB images and store to destination. - // Source is pre-multiplied by alpha using ARGBAttenuate. --- -2.38.1 - diff --git a/graphics/libyuv/CMakeLists.txt b/graphics/libyuv/CMakeLists.txt deleted file mode 100644 index c792f090f..000000000 --- a/graphics/libyuv/CMakeLists.txt +++ /dev/null @@ -1,58 +0,0 @@ -# ############################################################################## -# apps/graphics/libyuv/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_LIBYUV) - - set(LIBYUV_DIR ${CMAKE_CURRENT_LIST_DIR}/libyuv) - - if(NOT EXISTS ${LIBYUV_DIR}) - FetchContent_Declare( - libyuv_fetch - URL https://chromium.googlesource.com/libyuv/libyuv/+archive/refs/heads/${CONFIG_LIBYUV_BRANCH}.tar.gz - SOURCE_DIR - ${CMAKE_CURRENT_LIST_DIR}/libyuv - BINARY_DIR - ${CMAKE_BINARY_DIR}/apps/graphics/libyuv/libyuv - PATCH_COMMAND - patch -p0 -d ${CMAKE_CURRENT_LIST_DIR} < - ${CMAKE_CURRENT_LIST_DIR}/0001-include-libyuv-fix-strict-prototype-warning.patch - DOWNLOAD_NO_PROGRESS true - TIMEOUT 30) - - FetchContent_GetProperties(libyuv_fetch) - - if(NOT libyuv_fetch_POPULATED) - FetchContent_Populate(libyuv_fetch) - endif() - endif() - - nuttx_add_library(libyuv STATIC) - file(GLOB SRCS ${LIBYUV_DIR}/source/*.cc) - target_sources(libyuv PRIVATE ${SRCS}) - target_compile_options(libyuv PRIVATE -Wno-shadow -Wno-undef) - - set_property( - TARGET nuttx - APPEND - PROPERTY NUTTX_INCLUDE_DIRECTORIES - ${CMAKE_CURRENT_SOURCE_DIR}/libyuv/include) -endif() diff --git a/graphics/libyuv/Kconfig b/graphics/libyuv/Kconfig deleted file mode 100644 index 8d6b7cb7c..000000000 --- a/graphics/libyuv/Kconfig +++ /dev/null @@ -1,18 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config LIBYUV - bool "libyuv" - default n - ---help--- - Enable libyuv. - -if LIBYUV - -config LIBYUV_BRANCH - string "libyuv branch (main/stable)" - default "stable" - -endif # LIBYUV diff --git a/graphics/libyuv/Make.defs b/graphics/libyuv/Make.defs deleted file mode 100644 index 37bacb443..000000000 --- a/graphics/libyuv/Make.defs +++ /dev/null @@ -1,28 +0,0 @@ -############################################################################ -# apps/graphics/libyuv/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_LIBYUV),) -CONFIGURED_APPS += $(APPDIR)/graphics/libyuv - -CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/graphics/libyuv/libyuv/include -CXXFLAGS += ${INCDIR_PREFIX}$(APPDIR)/graphics/libyuv/libyuv/include -endif diff --git a/graphics/libyuv/Makefile b/graphics/libyuv/Makefile deleted file mode 100644 index e4421ee1d..000000000 --- a/graphics/libyuv/Makefile +++ /dev/null @@ -1,48 +0,0 @@ -############################################################################ -# apps/graphics/libyuv/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -SRCDIR = libyuv - -CXXEXT := .cc -CXXFLAGS += -Wno-shadow -Wno-undef -CXXSRCS = $(wildcard $(SRCDIR)/source/*.cc) - -libyuv.tar.gz: - $(Q) curl -L https://github.com/NuttX/nuttx/releases/download/libyuv/libyuv-refs_heads_$(CONFIG_LIBYUV_BRANCH).tar.gz -o libyuv.tar.gz - $(Q) mkdir -p $(SRCDIR) - $(Q) tar zxf libyuv.tar.gz --directory $(SRCDIR) -ifeq ($(CONFIG_LIBYUV_BRANCH),"stable") - $(Q) patch -p0 < 0001-include-libyuv-fix-strict-prototype-warning.patch -endif - -# Download and unpack tarball if no git repo found -ifeq ($(wildcard libyuv/.git),) -context:: libyuv.tar.gz - -distclean:: - $(call DELDIR, libyuv) - $(call DELFILE, libyuv.tar.gz) -endif - -include $(APPDIR)/Application.mk diff --git a/graphics/lvgl/CMakeLists.txt b/graphics/lvgl/CMakeLists.txt deleted file mode 100644 index ba5af28e2..000000000 --- a/graphics/lvgl/CMakeLists.txt +++ /dev/null @@ -1,133 +0,0 @@ -# ############################################################################## -# apps/graphics/lvgl/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_GRAPHICS_LVGL) - - # ############################################################################ - # Config and Fetch lvgl - # ############################################################################ - set(LVGL_DIR ${CMAKE_CURRENT_LIST_DIR}/lvgl) - - set(LVGL_VERSION - "${CONFIG_LVGL_VERSION_MAJOR}.${CONFIG_LVGL_VERSION_MINOR}.${CONFIG_LVGL_VERSION_PATCH}" - ) - - if(NOT EXISTS ${LVGL_DIR}) - set(LVGL_URL - "https://github.com/lvgl/lvgl/archive/refs/tags/v${LVGL_VERSION}.zip") - FetchContent_Declare( - lvgl_fetch - URL ${LVGL_URL} - DOWNLOAD_DIR - ${CMAKE_CURRENT_LIST_DIR} - SOURCE_DIR - ${CMAKE_CURRENT_LIST_DIR}/lvgl - BINARY_DIR - ${CMAKE_BINARY_DIR}/apps/graphics/lvgl/lvgl - DOWNLOAD_NO_PROGRESS true - TIMEOUT 120) - - FetchContent_GetProperties(lvgl_fetch) - - if(NOT lvgl_fetch_POPULATED) - FetchContent_Populate(lvgl_fetch) - endif() - endif() - - # ############################################################################ - # Flags and Sources - # ############################################################################ - - # ############################################################################ - # Library Configuration - # ############################################################################ - - file( - GLOB_RECURSE - SRCS - "${LVGL_DIR}/src/*.S" - "${LVGL_DIR}/src/*.c" - "${LVGL_DIR}/src/*.cpp" - "${LVGL_DIR}/demos/*.c" - "${LVGL_DIR}/examples/*.c") - nuttx_add_library(lvgl) - - target_sources(lvgl PRIVATE ${SRCS}) - target_include_directories(lvgl PRIVATE ${LVGL_DIR}) - target_compile_options(lvgl PRIVATE -Wno-shadow) - - if(NOT CONFIG_LV_ASSERT_HANDLER_INCLUDE STREQUAL "") - target_compile_definitions(lvgl PRIVATE "LV_ASSERT_HANDLER=ASSERT(0)\;") - endif() - - if(CONFIG_LV_USE_FREETYPE) - if(NOT CONFIG_LIB_FREETYPE) - message(WARNING "LIB_FREETYPE is not enabled") - endif() - nuttx_add_dependencies(TARGET lvgl DEPENDS freetype) - endif() - - if(CONFIG_LV_USE_LIBPNG) - if(NOT CONFIG_LIB_PNG) - message(WARNING "LIB_PNG is not enabled") - endif() - nuttx_add_dependencies(TARGET lvgl DEPENDS png_static) - endif() - - if(CONFIG_LV_USE_LIBWEBP) - if(NOT CONFIG_LIB_WEBP) - message(WARNING "LIB_WEBP is not enabled") - endif() - nuttx_add_dependencies(TARGET lvgl DEPENDS webpdecoder) - endif() - - if(CONFIG_LV_USE_FFMPEG) - message(FATAL_ERROR "FFMPEG is not supported yet") - endif() - - if(CONFIG_LV_USE_RLOTTIE) - message(FATAL_ERROR "RLOTTIE is not supported yet") - endif() - - if(CONFIG_LV_USE_LIBJPEG_TURBO) - if(NOT CONFIG_LIB_JPEG_TURBO) - message(WARNING "LIB_JPEG_TURBO is not enabled") - endif() - nuttx_add_dependencies(TARGET lvgl DEPENDS turbojpeg-static) - endif() - - if(NOT ${CONFIG_LV_OPTLEVEL} STREQUAL "") - add_compile_options(${CONFIG_LV_OPTLEVEL}) - endif() - - set_property( - TARGET nuttx - APPEND - PROPERTY NUTTX_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_LIST_DIR} - ${CMAKE_CURRENT_LIST_DIR}/lvgl) - - set_property( - TARGET nuttx - APPEND - PROPERTY NUTTX_COMPILE_OPTIONS -DLV_USE_DEV_VERSION=1) - -endif() diff --git a/graphics/lvgl/Kconfig b/graphics/lvgl/Kconfig index 2d9ad2f8e..3162c9c41 100644 --- a/graphics/lvgl/Kconfig +++ b/graphics/lvgl/Kconfig @@ -11,1883 +11,483 @@ menuconfig GRAPHICS_LVGL if GRAPHICS_LVGL -# Kconfig file for LVGL v9.2.2 - -menu "LVGL configuration" - - # Define CONFIG_LV_CONF_SKIP so we can use LVGL - # without lv_conf.h file, the lv_conf_internal.h and - # lv_conf_kconfig.h files are used instead. - config LV_CONF_SKIP - bool "Check this to not use custom lv_conf.h" - default y - - config LV_CONF_MINIMAL - bool "LVGL minimal configuration" - - menu "Color Settings" - choice LV_COLOR_DEPTH - prompt "Color depth" - default LV_COLOR_DEPTH_16 - help - Color depth to be used. - - config LV_COLOR_DEPTH_32 - bool "32: XRGB8888" - config LV_COLOR_DEPTH_24 - bool "24: RGB888" - config LV_COLOR_DEPTH_16 - bool "16: RGB565" - config LV_COLOR_DEPTH_8 - bool "8: RGB232" - config LV_COLOR_DEPTH_1 - bool "1: 1 byte per pixel" - endchoice - - config LV_COLOR_DEPTH - int - default 1 if LV_COLOR_DEPTH_1 - default 8 if LV_COLOR_DEPTH_8 - default 16 if LV_COLOR_DEPTH_16 - default 24 if LV_COLOR_DEPTH_24 - default 32 if LV_COLOR_DEPTH_32 - endmenu - - menu "Memory Settings" - choice - prompt "Malloc functions source" - default LV_USE_BUILTIN_MALLOC - - config LV_USE_BUILTIN_MALLOC - bool "LVGL's built in implementation" - - config LV_USE_CLIB_MALLOC - bool "Standard C functions malloc/realloc/free" - - config LV_USE_MICROPYTHON_MALLOC - bool "MicroPython functions malloc/realloc/free" - - config LV_USE_RTTHREAD_MALLOC - bool "RTThread functions malloc/realloc/free" - - config LV_USE_CUSTOM_MALLOC - bool "Implement the functions externally" - - endchoice # "Malloc functions" - - choice - prompt "String functions source" - default LV_USE_BUILTIN_STRING - - config LV_USE_BUILTIN_STRING - bool "LVGL's built in implementation" - - config LV_USE_CLIB_STRING - bool "Standard C functions memcpy/memset/strlen/strcpy" - - config LV_USE_CUSTOM_STRING - bool "Implement the functions externally" - - endchoice # "String functions" - - choice - prompt "Sprintf functions source" - default LV_USE_BUILTIN_SPRINTF - - config LV_USE_BUILTIN_SPRINTF - bool "LVGL's built in implementation" - - config LV_USE_CLIB_SPRINTF - bool "Standard C functions vsnprintf" - - config LV_USE_CUSTOM_SPRINTF - bool "Implement the functions externally" - - endchoice # "Sprintf functions" - - config LV_MEM_SIZE_KILOBYTES - int "Size of the memory used by `lv_malloc()` in kilobytes (>= 2kB)" - default 64 - depends on LV_USE_BUILTIN_MALLOC - - config LV_MEM_POOL_EXPAND_SIZE_KILOBYTES - int "Size of the memory expand for `lv_malloc()` in kilobytes" - default 0 - depends on LV_USE_BUILTIN_MALLOC - - config LV_MEM_ADR - hex "Address for the memory pool instead of allocating it as a normal array" - default 0x0 - depends on LV_USE_BUILTIN_MALLOC - - endmenu - - menu "HAL Settings" - config LV_DEF_REFR_PERIOD - int "Default refresh period (ms)" - default 33 - help - Default display refresh, input device read and animation step period. - - config LV_DPI_DEF - int "Default Dots Per Inch (in px/inch)" - default 130 - help - Used to initialize default sizes such as widgets sized, style paddings. - (Not so important, you can adjust it to modify default sizes and spaces) - endmenu - - menu "Operating System (OS)" - choice LV_USE_OS - prompt "Default operating system to use" - default LV_OS_NONE - - config LV_OS_NONE - bool "0: NONE" - config LV_OS_PTHREAD - bool "1: PTHREAD" - config LV_OS_FREERTOS - bool "2: FREERTOS" - config LV_OS_CMSIS_RTOS2 - bool "3: CMSIS_RTOS2" - config LV_OS_RTTHREAD - bool "4: RTTHREAD" - config LV_OS_WINDOWS - bool "5: WINDOWS" - config LV_OS_MQX - bool "6: MQX" - config LV_OS_CUSTOM - bool "255: CUSTOM" - endchoice - - config LV_USE_OS - int - default 0 if LV_OS_NONE - default 1 if LV_OS_PTHREAD - default 2 if LV_OS_FREERTOS - default 3 if LV_OS_CMSIS_RTOS2 - default 4 if LV_OS_RTTHREAD - default 5 if LV_OS_WINDOWS - default 6 if LV_OS_MQX - default 255 if LV_OS_CUSTOM - - config LV_OS_CUSTOM_INCLUDE - string "Custom OS include header" - default "stdint.h" - depends on LV_OS_CUSTOM - - config LV_USE_FREERTOS_TASK_NOTIFY - bool "Use RTOS task with a direct notification for synchronization" - default y - depends on LV_OS_FREERTOS - help - Unblocking an RTOS task with a direct notification is 45% faster and uses less RAM - than unblocking a task using an intermediary object such as a binary semaphore. - RTOS task notifications can only be used when there is only one task that can be the recipient of the event. - endmenu - - menu "Rendering Configuration" - config LV_DRAW_BUF_STRIDE_ALIGN - int "Buffer stride alignment" - default 1 - help - Align the stride of all layers and images to this bytes. - - config LV_DRAW_BUF_ALIGN - int "Buffer address alignment" - default 4 - help - Align the start address of draw_buf addresses to this bytes. - - config LV_DRAW_TRANSFORM_USE_MATRIX - bool "Using matrix for transformations" - default n - depends on LV_USE_MATRIX - help - Requirements: The rendering engine needs to support 3x3 matrix transformations. - - config LV_DRAW_LAYER_SIMPLE_BUF_SIZE - int "Optimal size to buffer the widget with opacity" - default 24576 - depends on LV_USE_DRAW_SW - help - If a widget has `style_opa < 255` (not `bg_opa`, `text_opa` etc) or not NORMAL blend mode - it is buffered into a "simple" layer before rendering. The widget can be buffered in smaller chunks. - "Transformed layers" (if `transform_angle/zoom` are set) use larger buffers and can't be drawn in chunks. - - config LV_DRAW_THREAD_STACK_SIZE - int "Stack size of draw thread in bytes" - default 8192 - depends on LV_USE_OS > 0 - help - If FreeType or ThorVG is enabled, it is recommended to set it to 32KB or more. - - config LV_USE_DRAW_SW - bool "Enable software rendering" - default y - help - Required to draw anything on the screen. - - config LV_DRAW_SW_SUPPORT_RGB565 - bool "Enable support for RGB565 color format" - default y - depends on LV_USE_DRAW_SW - - config LV_DRAW_SW_SUPPORT_RGB565A8 - bool "Enable support for RGB565A8 color format" - default y - depends on LV_USE_DRAW_SW - - config LV_DRAW_SW_SUPPORT_RGB888 - bool "Enable support for RGB888 color format" - default y - depends on LV_USE_DRAW_SW - - config LV_DRAW_SW_SUPPORT_XRGB8888 - bool "Enable support for XRGB8888 color format" - default y - depends on LV_USE_DRAW_SW - - config LV_DRAW_SW_SUPPORT_ARGB8888 - bool "Enable support for ARGB8888 color format" - default y - depends on LV_USE_DRAW_SW - - config LV_DRAW_SW_SUPPORT_L8 - bool "Enable support for L8 color format" - default y - depends on LV_USE_DRAW_SW - - config LV_DRAW_SW_SUPPORT_AL88 - bool "Enable support for AL88 color format" - default y - depends on LV_USE_DRAW_SW - - config LV_DRAW_SW_SUPPORT_A8 - bool "Enable support for A8 color format" - default y - depends on LV_USE_DRAW_SW - - config LV_DRAW_SW_SUPPORT_I1 - bool "Enable support for I1 color format" - default y - depends on LV_USE_DRAW_SW - - config LV_DRAW_SW_DRAW_UNIT_CNT - int "Number of draw units" - default 1 - depends on LV_USE_DRAW_SW - help - > 1 requires an operating system enabled in `LV_USE_OS` - > 1 means multiply threads will render the screen in parallel - - config LV_USE_DRAW_ARM2D_SYNC - bool "Enable Arm's 2D image processing library (Arm-2D) for all Cortex-M processors" - default n - depends on LV_USE_DRAW_SW - help - Must deploy arm-2d library to your project and add include PATH for "arm_2d.h". - - config LV_USE_NATIVE_HELIUM_ASM - bool "Enable native helium assembly" - default n - depends on LV_USE_DRAW_SW - help - Disabling this allows arm2d to work on its own (for testing only) - - config LV_DRAW_SW_COMPLEX - bool "Enable complex draw engine" - default y - depends on LV_USE_DRAW_SW - help - 0: use a simple renderer capable of drawing only simple rectangles with gradient, images, texts, and straight lines only, - 1: use a complex renderer capable of drawing rounded corners, shadow, skew lines, and arcs too. - - config LV_USE_DRAW_SW_COMPLEX_GRADIENTS - bool "Enable drawing complex gradients in software" - default n - depends on LV_USE_DRAW_SW - help - 0: do not enable complex gradients - 1: enable complex gradients (linear at an angle, radial or conical) - - config LV_DRAW_SW_SHADOW_CACHE_SIZE - int "Allow buffering some shadow calculation" - depends on LV_DRAW_SW_COMPLEX - default 0 - help - LV_DRAW_SW_SHADOW_CACHE_SIZE is the max shadow size to buffer, where - shadow size is `shadow_width + radius`. - Caching has LV_DRAW_SW_SHADOW_CACHE_SIZE^2 RAM cost. - - config LV_DRAW_SW_CIRCLE_CACHE_SIZE - int "Set number of maximally cached circle data" - depends on LV_DRAW_SW_COMPLEX - default 4 - help - The circumference of 1/4 circle are saved for anti-aliasing - radius * 4 bytes are used per circle (the most often used - radiuses are saved). - Set to 0 to disable caching. - - choice LV_USE_DRAW_SW_ASM - prompt "Asm mode in sw draw" - default LV_DRAW_SW_ASM_NONE - depends on LV_USE_DRAW_SW - help - ASM mode to be used - - config LV_DRAW_SW_ASM_NONE - bool "0: NONE" - config LV_DRAW_SW_ASM_NEON - bool "1: NEON" - config LV_DRAW_SW_ASM_HELIUM - bool "2: HELIUM" - config LV_DRAW_SW_ASM_CUSTOM - bool "255: CUSTOM" - endchoice - - config LV_USE_DRAW_SW_ASM - int - default 0 if LV_DRAW_SW_ASM_NONE - default 1 if LV_DRAW_SW_ASM_NEON - default 2 if LV_DRAW_SW_ASM_HELIUM - default 255 if LV_DRAW_SW_ASM_CUSTOM - - config LV_DRAW_SW_ASM_CUSTOM_INCLUDE - string "Set the custom asm include file" - default "" - depends on LV_DRAW_SW_ASM_CUSTOM - - config LV_USE_DRAW_VGLITE - bool "Use NXP's VG-Lite GPU on iMX RTxxx platforms" - default n - - config LV_USE_VGLITE_BLIT_SPLIT - bool "Enable blit quality degradation workaround recommended for screen's dimension > 352 pixels" - depends on LV_USE_DRAW_VGLITE - default n - - config LV_USE_VGLITE_DRAW_THREAD - bool "Use additional draw thread for VG-Lite processing" - depends on LV_USE_DRAW_VGLITE && LV_USE_OS > 0 - default y - - config LV_USE_VGLITE_DRAW_ASYNC - bool "Enable VGLite draw async" - depends on LV_USE_VGLITE_DRAW_THREAD - default y - help - Queue multiple tasks and flash them once to the GPU. The task ready state will be send asynchronous to dispatcher. - - config LV_USE_VGLITE_ASSERT - bool "Enable VGLite asserts" - depends on LV_USE_DRAW_VGLITE - default n - - config LV_USE_DRAW_PXP - bool "Use NXP's PXP on iMX RTxxx platforms" - default n - - config LV_USE_PXP_DRAW_THREAD - bool "Use additional draw thread for PXP processing" - depends on LV_USE_DRAW_PXP && LV_USE_OS > 0 - default y - - config LV_USE_PXP_ASSERT - bool "Enable PXP asserts" - depends on LV_USE_DRAW_PXP - default n - - config LV_USE_DRAW_DAVE2D - bool "Use Renesas Dave2D on RA platforms" - default n - - config LV_USE_DRAW_SDL - bool "Draw using cached SDL textures" - default n - help - Uses SDL renderer API - - config LV_USE_DRAW_VG_LITE - bool "Use VG-Lite GPU" - default n - select LV_USE_MATRIX - - config LV_VG_LITE_USE_GPU_INIT - bool "Enable VG-Lite custom external 'gpu_init()' function" - default n - depends on LV_USE_DRAW_VG_LITE - - config LV_VG_LITE_USE_ASSERT - bool "Enable VG-Lite assert" - default n - depends on LV_USE_DRAW_VG_LITE - - config LV_VG_LITE_FLUSH_MAX_COUNT - int "VG-Lite flush commit trigger threshold" - default 8 - depends on LV_USE_DRAW_VG_LITE - help - GPU will try to batch these many draw tasks - - config LV_VG_LITE_USE_BOX_SHADOW - bool "Enable border to simulate shadow" - default n - depends on LV_USE_DRAW_VG_LITE - help - which usually improves performance, - but does not guarantee the same rendering quality as the software. - - config LV_VG_LITE_GRAD_CACHE_CNT - int "VG-Lite gradient maximum cache number." - default 32 - depends on LV_USE_DRAW_VG_LITE - help - The memory usage of a single gradient: - linear: 4K bytes. - radial: radius * 4K bytes. - - config LV_VG_LITE_STROKE_CACHE_CNT - int "VG-Lite stroke maximum cache number." - default 32 - depends on LV_USE_DRAW_VG_LITE - - config LV_USE_VECTOR_GRAPHIC - bool "Use Vector Graphic APIs" - default n - select LV_USE_MATRIX - help - Enable drawing support vector graphic APIs. - endmenu - - menu "Feature Configuration" - menu "Logging" - config LV_USE_LOG - bool "Enable the log module" - - choice - bool "Default log verbosity" if LV_USE_LOG - default LV_LOG_LEVEL_WARN - help - Specify how important log should be added. - - config LV_LOG_LEVEL_TRACE - bool "A lot of logs to give detailed information" - config LV_LOG_LEVEL_INFO - bool "Log important events" - config LV_LOG_LEVEL_WARN - bool "Log if something unwanted happened but didn't cause a problem" - config LV_LOG_LEVEL_ERROR - bool "Only critical issues, when the system may fail" - config LV_LOG_LEVEL_USER - bool "Only logs added by the user" - config LV_LOG_LEVEL_NONE - bool "Do not log anything" - endchoice - - config LV_LOG_LEVEL - int - default 0 if LV_LOG_LEVEL_TRACE - default 1 if LV_LOG_LEVEL_INFO - default 2 if LV_LOG_LEVEL_WARN - default 3 if LV_LOG_LEVEL_ERROR - default 4 if LV_LOG_LEVEL_USER - default 5 if LV_LOG_LEVEL_NONE - - config LV_LOG_PRINTF - bool "Print the log with 'printf'" if LV_USE_LOG - help - Use printf for log output. - If not set the user needs to register a callback with `lv_log_register_print_cb`. - - config LV_LOG_USE_TIMESTAMP - bool "Enable print timestamp" - default y - depends on LV_USE_LOG - - config LV_LOG_USE_FILE_LINE - bool "Enable print file and line number" - default y - depends on LV_USE_LOG - - config LV_LOG_TRACE_MEM - bool "Enable/Disable LV_LOG_TRACE in mem module" - default y - depends on LV_USE_LOG - - config LV_LOG_TRACE_TIMER - bool "Enable/Disable LV_LOG_TRACE in timer module" - default y - depends on LV_USE_LOG - - config LV_LOG_TRACE_INDEV - bool "Enable/Disable LV_LOG_TRACE in indev module" - default y - depends on LV_USE_LOG - - config LV_LOG_TRACE_DISP_REFR - bool "Enable/Disable LV_LOG_TRACE in disp refr module" - default y - depends on LV_USE_LOG - - config LV_LOG_TRACE_EVENT - bool "Enable/Disable LV_LOG_TRACE in event module" - default y - depends on LV_USE_LOG - - config LV_LOG_TRACE_OBJ_CREATE - bool "Enable/Disable LV_LOG_TRACE in obj create module" - default y - depends on LV_USE_LOG - - config LV_LOG_TRACE_LAYOUT - bool "Enable/Disable LV_LOG_TRACE in layout module" - default y - depends on LV_USE_LOG - - config LV_LOG_TRACE_ANIM - bool "Enable/Disable LV_LOG_TRACE in anim module" - default y - depends on LV_USE_LOG - - config LV_LOG_TRACE_CACHE - bool "Enable/Disable LV_LOG_TRACE in cache module" - default y - depends on LV_USE_LOG - endmenu - - menu "Asserts" - config LV_USE_ASSERT_NULL - bool "Check if the parameter is NULL. (Very fast, recommended)" - default y if !LV_CONF_MINIMAL - - config LV_USE_ASSERT_MALLOC - bool "Checks if the memory is successfully allocated or no. (Very fast, recommended)" - default y if !LV_CONF_MINIMAL - - config LV_USE_ASSERT_STYLE - bool "Check if the styles are properly initialized. (Very fast, recommended)" - - config LV_USE_ASSERT_MEM_INTEGRITY - bool "Check the integrity of `lv_mem` after critical operations. (Slow)" - - config LV_USE_ASSERT_OBJ - bool "Check NULL, the object's type and existence (e.g. not deleted). (Slow)" - - config LV_ASSERT_HANDLER_INCLUDE - string "Header to include for the custom assert function" - default "assert.h" - help - Add a custom handler when assert happens e.g. to restart the MCU - endmenu - - menu "Debug" - config LV_USE_REFR_DEBUG - bool "Draw random colored rectangles over the redrawn areas" - - config LV_USE_LAYER_DEBUG - bool "Draw a red overlay for ARGB layers and a green overlay for RGB layers" - - config LV_USE_PARALLEL_DRAW_DEBUG - bool "Draw overlays with different colors for each draw_unit's tasks" - help - Also add the index number of the draw unit on white background. - For layers add the index number of the draw unit on black background. - endmenu - - menu "Others" - config LV_ENABLE_GLOBAL_CUSTOM - bool "Enable 'lv_global' customization" - - config LV_GLOBAL_CUSTOM_INCLUDE - string "Header to include for the custom 'lv_global' function" - depends on LV_ENABLE_GLOBAL_CUSTOM - default "lv_global.h" - - config LV_CACHE_DEF_SIZE - int "Default image cache size. 0 to disable caching" - default 0 - depends on LV_USE_DRAW_SW - help - If only the built-in image formats are used there is no real advantage of caching. - (I.e. no new image decoder is added). - - With complex image decoders (e.g. PNG or JPG) caching can - save the continuous open/decode of images. - However the opened images might consume additional RAM. - - config LV_IMAGE_HEADER_CACHE_DEF_CNT - int "Default image header cache count. 0 to disable caching" - default 0 - depends on LV_USE_DRAW_SW - help - If only the built-in image formats are used there is no real advantage of caching. - (I.e. no new image decoder is added). - - With complex image decoders (e.g. PNG or JPG) caching can - save the continuous getting header information of images. - However the records of opened images headers might consume additional RAM. - - config LV_GRADIENT_MAX_STOPS - int "Number of stops allowed per gradient" - default 2 - depends on LV_USE_DRAW_SW - help - Increase this to allow more stops. - This adds (sizeof(lv_color_t) + 1) bytes per additional stop - - config LV_COLOR_MIX_ROUND_OFS - int "Adjust color mix functions rounding" - default 128 if !LV_COLOR_DEPTH_32 - default 0 if LV_COLOR_DEPTH_32 - range 0 254 - help - 0: no adjustment, get the integer part of the result (round down) - 64: round up from x.75 - 128: round up from half - 192: round up from x.25 - 254: round up - - config LV_OBJ_STYLE_CACHE - bool "Use cache to speed up getting object style properties" - default n - help - Add 2 x 32 bit variables to each lv_obj_t to speed up getting style properties - - config LV_USE_OBJ_ID - bool "Add id field to obj" - default n - - config LV_OBJ_ID_AUTO_ASSIGN - bool "Automatically assign an ID when obj is created" - default y - depends on LV_USE_OBJ_ID - - config LV_USE_OBJ_ID_BUILTIN - bool "Use builtin method to deal with obj ID" - default n - depends on LV_USE_OBJ_ID - - config LV_USE_OBJ_PROPERTY - bool "Use obj property set/get API" - default n - - config LV_USE_OBJ_PROPERTY_NAME - bool "Use name to access property" - default n - depends on LV_USE_OBJ_PROPERTY - help - Add a name table to every widget class, so the property can be accessed by name. - Note, the const table will increase flash usage. - - config LV_USE_VG_LITE_THORVG - bool "VG-Lite Simulator" - default n - depends on LV_USE_THORVG - help - Use thorvg to simulate VG-Lite hardware behavior, it's useful - for debugging and testing on PC simulator. Enable LV_USE_THORVG, - Either internal ThorVG or external ThorVG library is required. - - config LV_VG_LITE_THORVG_LVGL_BLEND_SUPPORT - bool "Enable LVGL blend mode support" - default n - depends on LV_USE_VG_LITE_THORVG - - config LV_VG_LITE_THORVG_YUV_SUPPORT - bool "Enable YUV color format support" - default n - depends on LV_USE_VG_LITE_THORVG - - config LV_VG_LITE_THORVG_LINEAR_GRADIENT_EXT_SUPPORT - bool "Enable linear gradient extension support" - default n - depends on LV_USE_VG_LITE_THORVG - - config LV_VG_LITE_THORVG_16PIXELS_ALIGN - bool "Enable 16 pixels alignment" - default y - depends on LV_USE_VG_LITE_THORVG - - config LV_VG_LITE_THORVG_BUF_ADDR_ALIGN - int "Buffer address alignment" - default 64 - depends on LV_USE_VG_LITE_THORVG - - config LV_VG_LITE_THORVG_THREAD_RENDER - bool "Enable multi-thread render" - default n - depends on LV_USE_VG_LITE_THORVG - endmenu - endmenu - - menu "Compiler Settings" - config LV_BIG_ENDIAN_SYSTEM - bool "For big endian systems set to 1" - - config LV_ATTRIBUTE_MEM_ALIGN_SIZE - int "Required alignment size for buffers" - default 1 - - config LV_ATTRIBUTE_FAST_MEM_USE_IRAM - bool "Set IRAM as LV_ATTRIBUTE_FAST_MEM" - help - Set this option to configure IRAM as LV_ATTRIBUTE_FAST_MEM - - config LV_USE_FLOAT - bool "Use float as lv_value_precise_t" - default n - - config LV_USE_MATRIX - bool "Enable matrix support" - default n - select LV_USE_FLOAT - - config LV_USE_PRIVATE_API - bool "Include `lvgl_private.h` in `lvgl.h` to access internal data and functions by default" - default n - endmenu - - menu "Font Usage" - menu "Enable built-in fonts" - config LV_FONT_MONTSERRAT_8 - bool "Enable Montserrat 8" - config LV_FONT_MONTSERRAT_10 - bool "Enable Montserrat 10" - config LV_FONT_MONTSERRAT_12 - bool "Enable Montserrat 12" - config LV_FONT_MONTSERRAT_14 - bool "Enable Montserrat 14" - default y if !LV_CONF_MINIMAL - config LV_FONT_MONTSERRAT_16 - bool "Enable Montserrat 16" - config LV_FONT_MONTSERRAT_18 - bool "Enable Montserrat 18" - config LV_FONT_MONTSERRAT_20 - bool "Enable Montserrat 20" - config LV_FONT_MONTSERRAT_22 - bool "Enable Montserrat 22" - config LV_FONT_MONTSERRAT_24 - bool "Enable Montserrat 24" - config LV_FONT_MONTSERRAT_26 - bool "Enable Montserrat 26" - config LV_FONT_MONTSERRAT_28 - bool "Enable Montserrat 28" - config LV_FONT_MONTSERRAT_30 - bool "Enable Montserrat 30" - config LV_FONT_MONTSERRAT_32 - bool "Enable Montserrat 32" - config LV_FONT_MONTSERRAT_34 - bool "Enable Montserrat 34" - config LV_FONT_MONTSERRAT_36 - bool "Enable Montserrat 36" - config LV_FONT_MONTSERRAT_38 - bool "Enable Montserrat 38" - config LV_FONT_MONTSERRAT_40 - bool "Enable Montserrat 40" - config LV_FONT_MONTSERRAT_42 - bool "Enable Montserrat 42" - config LV_FONT_MONTSERRAT_44 - bool "Enable Montserrat 44" - config LV_FONT_MONTSERRAT_46 - bool "Enable Montserrat 46" - config LV_FONT_MONTSERRAT_48 - bool "Enable Montserrat 48" - - config LV_FONT_MONTSERRAT_28_COMPRESSED - bool "Enable Montserrat 28 compressed" - config LV_FONT_DEJAVU_16_PERSIAN_HEBREW - bool "Enable Dejavu 16 Persian, Hebrew, Arabic letters" - config LV_FONT_SIMSUN_14_CJK - bool "Enable Simsun 14 CJK" - config LV_FONT_SIMSUN_16_CJK - bool "Enable Simsun 16 CJK" - - config LV_FONT_UNSCII_8 - bool "Enable UNSCII 8 (Perfect monospace font)" - default y if LV_CONF_MINIMAL - config LV_FONT_UNSCII_16 - bool "Enable UNSCII 16 (Perfect monospace font)" - endmenu - - choice LV_FONT_DEFAULT - prompt "Select theme default title font" - default LV_FONT_DEFAULT_MONTSERRAT_14 if !LV_CONF_MINIMAL - default LV_FONT_DEFAULT_UNSCII_8 if LV_CONF_MINIMAL - help - Select theme default title font - - config LV_FONT_DEFAULT_MONTSERRAT_8 - bool "Montserrat 8" - select LV_FONT_MONTSERRAT_8 - config LV_FONT_DEFAULT_MONTSERRAT_10 - bool "Montserrat 10" - select LV_FONT_MONTSERRAT_10 - config LV_FONT_DEFAULT_MONTSERRAT_12 - bool "Montserrat 12" - select LV_FONT_MONTSERRAT_12 - config LV_FONT_DEFAULT_MONTSERRAT_14 - bool "Montserrat 14" - select LV_FONT_MONTSERRAT_14 - config LV_FONT_DEFAULT_MONTSERRAT_16 - bool "Montserrat 16" - select LV_FONT_MONTSERRAT_16 - config LV_FONT_DEFAULT_MONTSERRAT_18 - bool "Montserrat 18" - select LV_FONT_MONTSERRAT_18 - config LV_FONT_DEFAULT_MONTSERRAT_20 - bool "Montserrat 20" - select LV_FONT_MONTSERRAT_20 - config LV_FONT_DEFAULT_MONTSERRAT_22 - bool "Montserrat 22" - select LV_FONT_MONTSERRAT_22 - config LV_FONT_DEFAULT_MONTSERRAT_24 - bool "Montserrat 24" - select LV_FONT_MONTSERRAT_24 - config LV_FONT_DEFAULT_MONTSERRAT_26 - bool "Montserrat 26" - select LV_FONT_MONTSERRAT_26 - config LV_FONT_DEFAULT_MONTSERRAT_28 - bool "Montserrat 28" - select LV_FONT_MONTSERRAT_28 - config LV_FONT_DEFAULT_MONTSERRAT_30 - bool "Montserrat 30" - select LV_FONT_MONTSERRAT_30 - config LV_FONT_DEFAULT_MONTSERRAT_32 - bool "Montserrat 32" - select LV_FONT_MONTSERRAT_32 - config LV_FONT_DEFAULT_MONTSERRAT_34 - bool "Montserrat 34" - select LV_FONT_MONTSERRAT_34 - config LV_FONT_DEFAULT_MONTSERRAT_36 - bool "Montserrat 36" - select LV_FONT_MONTSERRAT_36 - config LV_FONT_DEFAULT_MONTSERRAT_38 - bool "Montserrat 38" - select LV_FONT_MONTSERRAT_38 - config LV_FONT_DEFAULT_MONTSERRAT_40 - bool "Montserrat 40" - select LV_FONT_MONTSERRAT_40 - config LV_FONT_DEFAULT_MONTSERRAT_42 - bool "Montserrat 42" - select LV_FONT_MONTSERRAT_42 - config LV_FONT_DEFAULT_MONTSERRAT_44 - bool "Montserrat 44" - select LV_FONT_MONTSERRAT_44 - config LV_FONT_DEFAULT_MONTSERRAT_46 - bool "Montserrat 46" - select LV_FONT_MONTSERRAT_46 - config LV_FONT_DEFAULT_MONTSERRAT_48 - bool "Montserrat 48" - select LV_FONT_MONTSERRAT_48 - config LV_FONT_DEFAULT_MONTSERRAT_28_COMPRESSED - bool "Montserrat 28 compressed" - select LV_FONT_MONTSERRAT_28_COMPRESSED - config LV_FONT_DEFAULT_DEJAVU_16_PERSIAN_HEBREW - bool "Dejavu 16 Persian, Hebrew, Arabic letters" - select LV_FONT_DEJAVU_16_PERSIAN_HEBREW - config LV_FONT_DEFAULT_SIMSUN_14_CJK - bool "Simsun 14 CJK" - select LV_FONT_SIMSUN_14_CJK - config LV_FONT_DEFAULT_SIMSUN_16_CJK - bool "Simsun 16 CJK" - select LV_FONT_SIMSUN_16_CJK - config LV_FONT_DEFAULT_UNSCII_8 - bool "UNSCII 8 (Perfect monospace font)" - select LV_FONT_UNSCII_8 - config LV_FONT_DEFAULT_UNSCII_16 - bool "UNSCII 16 (Perfect monospace font)" - select LV_FONT_UNSCII_16 - endchoice - - config LV_FONT_FMT_TXT_LARGE - bool "Enable it if you have fonts with a lot of characters" - help - The limit depends on the font size, font face and format - but with > 10,000 characters if you see issues probably you - need to enable it. - - config LV_USE_FONT_COMPRESSED - bool "Sets support for compressed fonts" - - config LV_USE_FONT_PLACEHOLDER - bool "Enable drawing placeholders when glyph dsc is not found" - default y - endmenu - - menu "Text Settings" - choice LV_TXT_ENC - prompt "Select a character encoding for strings" - help - Select a character encoding for strings. Your IDE or editor should have the same character encoding. - default LV_TXT_ENC_UTF8 if !LV_CONF_MINIMAL - default LV_TXT_ENC_ASCII if LV_CONF_MINIMAL - - config LV_TXT_ENC_UTF8 - bool "UTF8" - config LV_TXT_ENC_ASCII - bool "ASCII" - endchoice - - config LV_TXT_BREAK_CHARS - string "Can break (wrap) texts on these chars" - default " ,.;:-_)}" - - config LV_TXT_LINE_BREAK_LONG_LEN - int "Line break long length" - default 0 - help - If a word is at least this long, will break wherever 'prettiest'. - To disable, set to a value <= 0. - - config LV_TXT_LINE_BREAK_LONG_PRE_MIN_LEN - int "Min num chars before break" - default 3 - depends on LV_TXT_LINE_BREAK_LONG_LEN > 0 - help - Minimum number of characters in a long word to put on a line before a break. - - config LV_TXT_LINE_BREAK_LONG_POST_MIN_LEN - int "Min num chars after break" - default 3 - depends on LV_TXT_LINE_BREAK_LONG_LEN > 0 - help - Minimum number of characters in a long word to put on a line after a break - - config LV_USE_BIDI - bool "Support bidirectional texts" - help - Allows mixing Left-to-Right and Right-to-Left texts. - The direction will be processed according to the Unicode Bidirectional Algorithm: - https://www.w3.org/International/articles/inline-bidi-markup/uba-basics - - choice - prompt "Set the default BIDI direction" - default LV_BIDI_DIR_AUTO - depends on LV_USE_BIDI - - config LV_BIDI_DIR_LTR - bool "Left-to-Right" - config LV_BIDI_DIR_RTL - bool "Right-to-Left" - config LV_BIDI_DIR_AUTO - bool "Detect texts base direction" - endchoice - - config LV_USE_ARABIC_PERSIAN_CHARS - bool "Enable Arabic/Persian processing" - help - In these languages characters should be replaced with - another form based on their position in the text. - endmenu - - menu "Widget Usage" - config LV_WIDGETS_HAS_DEFAULT_VALUE - bool "Widgets has default value" - default y if !LV_CONF_MINIMAL - config LV_USE_ANIMIMG - bool "Anim image" - default y if !LV_CONF_MINIMAL - config LV_USE_ARC - bool "Arc" - default y if !LV_CONF_MINIMAL - config LV_USE_BAR - bool "Bar" - default y if !LV_CONF_MINIMAL - config LV_USE_BUTTON - bool "Button" - default y if !LV_CONF_MINIMAL - config LV_USE_BUTTONMATRIX - bool "Button matrix" - default y if !LV_CONF_MINIMAL - config LV_USE_CALENDAR - bool "Calendar" - default y if !LV_CONF_MINIMAL - config LV_CALENDAR_WEEK_STARTS_MONDAY - bool "Calendar week starts monday" - depends on LV_USE_CALENDAR - config LV_USE_CALENDAR_HEADER_ARROW - bool "Use calendar header arrow" - depends on LV_USE_CALENDAR - default y - config LV_USE_CALENDAR_HEADER_DROPDOWN - bool "Use calendar header dropdown" - depends on LV_USE_CALENDAR - default y - config LV_USE_CALENDAR_CHINESE - bool "Use chinese calendar" - depends on LV_USE_CALENDAR - config LV_USE_CANVAS - bool "Canvas. Requires: lv_image" - imply LV_USE_IMAGE - default y if !LV_CONF_MINIMAL - config LV_USE_CHART - bool "Chart" - default y if !LV_CONF_MINIMAL - config LV_USE_CHECKBOX - bool "Check Box" - default y if !LV_CONF_MINIMAL - config LV_USE_DROPDOWN - bool "Drop down list. Requires: lv_label" - imply LV_USE_LABEL - default y if !LV_CONF_MINIMAL - config LV_USE_IMAGE - bool "Image. Requires: lv_label" - imply LV_USE_LABEL - default y if !LV_CONF_MINIMAL - config LV_USE_IMAGEBUTTON - bool "ImageButton" - default y if !LV_CONF_MINIMAL - config LV_USE_KEYBOARD - bool "Keyboard" - default y if !LV_CONF_MINIMAL - config LV_USE_LABEL - bool "Label" - default y if !LV_CONF_MINIMAL - config LV_LABEL_TEXT_SELECTION - bool "Enable selecting text of the label" - depends on LV_USE_LABEL - default y - config LV_LABEL_LONG_TXT_HINT - bool "Store extra some info in labels (12 bytes) to speed up drawing of very long texts" - depends on LV_USE_LABEL - default y - config LV_LABEL_WAIT_CHAR_COUNT - int "The count of wait chart" - depends on LV_USE_LABEL - default 3 - config LV_USE_LED - bool "LED" - default y if !LV_CONF_MINIMAL - config LV_USE_LINE - bool "Line" - default y if !LV_CONF_MINIMAL - config LV_USE_LIST - bool "List" - default y if !LV_CONF_MINIMAL - config LV_USE_LOTTIE - bool "Lottie" - default n - depends on LV_USE_VECTOR_GRAPHIC && (LV_USE_THORVG_INTERNAL || LV_USE_THORVG_EXTERNAL) - help - Enable Lottie animations. Requires LV_USE_VECTOR_GRAPHIC and LV_USE_THORVG_INTERNAL or LV_USE_THORVG_EXTERNAL. - config LV_USE_MENU - bool "Menu" - default y if !LV_CONF_MINIMAL - config LV_USE_MSGBOX - bool "Msgbox" - default y if !LV_CONF_MINIMAL - config LV_USE_ROLLER - bool "Roller. Requires: lv_label" - imply LV_USE_LABEL - default y if !LV_CONF_MINIMAL - config LV_USE_SCALE - bool "Scale" - default y if !LV_CONF_MINIMAL - config LV_USE_SLIDER - bool "Slider. Requires: lv_bar" - imply LV_USE_BAR - default y if !LV_CONF_MINIMAL - config LV_USE_SPAN - bool "Span" - default y if !LV_CONF_MINIMAL - config LV_SPAN_SNIPPET_STACK_SIZE - int "Maximum number of span descriptor" - default 64 - depends on LV_USE_SPAN - config LV_USE_SPINBOX - bool "Spinbox" - default y if !LV_CONF_MINIMAL - config LV_USE_SPINNER - bool "Spinner" - default y if !LV_CONF_MINIMAL - config LV_USE_SWITCH - bool "Switch" - default y if !LV_CONF_MINIMAL - config LV_USE_TEXTAREA - bool "Text area. Requires: lv_label" - select LV_USE_LABEL - default y if !LV_CONF_MINIMAL - config LV_TEXTAREA_DEF_PWD_SHOW_TIME - int "Text area def. pwd show time [ms]" - default 1500 - depends on LV_USE_TEXTAREA - config LV_USE_TABLE - bool "Table" - default y if !LV_CONF_MINIMAL - config LV_USE_TABVIEW - bool "Tabview" - default y if !LV_CONF_MINIMAL - config LV_USE_TILEVIEW - bool "Tileview" - default y if !LV_CONF_MINIMAL - config LV_USE_WIN - bool "Win" - default y if !LV_CONF_MINIMAL - endmenu - - menu "Themes" - config LV_USE_THEME_DEFAULT - bool "A simple, impressive and very complete theme" - default y if !LV_COLOR_DEPTH_1 && !LV_CONF_MINIMAL - config LV_THEME_DEFAULT_DARK - bool "Yes to set dark mode, No to set light mode" - depends on LV_USE_THEME_DEFAULT - config LV_THEME_DEFAULT_GROW - bool "Enable grow on press" - default y - depends on LV_USE_THEME_DEFAULT - config LV_THEME_DEFAULT_TRANSITION_TIME - int "Default transition time in [ms]" - default 80 - depends on LV_USE_THEME_DEFAULT - config LV_USE_THEME_SIMPLE - bool "A very simple theme that is a good starting point for a custom theme" - default y if !LV_COLOR_DEPTH_1 && !LV_CONF_MINIMAL - config LV_USE_THEME_MONO - bool "Monochrome theme, suitable for some E-paper & dot matrix displays" - default y if LV_COLOR_DEPTH_1 && !LV_CONF_MINIMAL - endmenu - - menu "Layouts" - config LV_USE_FLEX - bool "A layout similar to Flexbox in CSS" - default y if !LV_CONF_MINIMAL - config LV_USE_GRID - bool "A layout similar to Grid in CSS" - default y if !LV_CONF_MINIMAL - endmenu - - menu "3rd Party Libraries" - config LV_FS_DEFAULT_DRIVE_LETTER - int "Default drive letter (e.g. 65 for 'A')" - default 0 - help - Setting a default drive letter allows skipping the driver prefix in filepaths - - config LV_USE_FS_STDIO - bool "File system on top of stdio API" - config LV_FS_STDIO_LETTER - int "Set an upper cased letter on which the drive will accessible (e.g. 65 for 'A')" - default 0 - depends on LV_USE_FS_STDIO - config LV_FS_STDIO_PATH - string "Set the working directory" - depends on LV_USE_FS_STDIO - config LV_FS_STDIO_CACHE_SIZE - int ">0 to cache this number of bytes in lv_fs_read()" - default 0 - depends on LV_USE_FS_STDIO - - config LV_USE_FS_POSIX - bool "File system on top of posix API" - config LV_FS_POSIX_LETTER - int "Set an upper cased letter on which the drive will accessible (e.g. 65 for 'A')" - default 0 - depends on LV_USE_FS_POSIX - config LV_FS_POSIX_PATH - string "Set the working directory" - depends on LV_USE_FS_POSIX - config LV_FS_POSIX_CACHE_SIZE - int ">0 to cache this number of bytes in lv_fs_read()" - default 0 - depends on LV_USE_FS_POSIX - - config LV_USE_FS_WIN32 - bool "File system on top of Win32 API" - config LV_FS_WIN32_LETTER - int "Set an upper cased letter on which the drive will accessible (e.g. 65 for 'A')" - default 0 - depends on LV_USE_FS_WIN32 - config LV_FS_WIN32_PATH - string "Set the working directory" - depends on LV_USE_FS_WIN32 - config LV_FS_WIN32_CACHE_SIZE - int ">0 to cache this number of bytes in lv_fs_read()" - default 0 - depends on LV_USE_FS_WIN32 - - config LV_USE_FS_FATFS - bool "File system on top of FatFS" - config LV_FS_FATFS_LETTER - int "Set an upper cased letter on which the drive will accessible (e.g. 65 for 'A')" - default 0 - depends on LV_USE_FS_FATFS - config LV_FS_FATFS_CACHE_SIZE - int ">0 to cache this number of bytes in lv_fs_read()" - default 0 - depends on LV_USE_FS_FATFS - - config LV_USE_FS_MEMFS - bool "File system on top of memory-mapped API" - config LV_FS_MEMFS_LETTER - int "Set an upper cased letter on which the drive will accessible (e.g. 65 for 'A')" - default 0 - depends on LV_USE_FS_MEMFS - - config LV_USE_FS_LITTLEFS - bool "File system on top of littlefs API" - config LV_FS_LITTLEFS_LETTER - int "Set an upper cased letter on which the drive will accessible (e.g. 65 for 'A')" - default 0 - depends on LV_USE_FS_LITTLEFS - - config LV_USE_FS_ARDUINO_ESP_LITTLEFS - bool "File system on top of Arduino ESP littlefs API" - config LV_FS_ARDUINO_ESP_LITTLEFS_LETTER - int "Set an upper cased letter on which the drive will accessible (e.g. 65 for 'A')" - default 0 - depends on LV_USE_FS_ARDUINO_ESP_LITTLEFS - - config LV_USE_FS_ARDUINO_SD - bool "File system on top of Arduino SD API" - config LV_FS_ARDUINO_SD_LETTER - int "Set an upper cased letter on which the drive will accessible (e.g. 65 for 'A')" - default 0 - depends on LV_USE_FS_ARDUINO_SD - - config LV_USE_LODEPNG - bool "PNG decoder library" - - config LV_USE_LIBPNG - bool "PNG decoder(libpng) library" - - config LV_USE_BMP - bool "BMP decoder library" - - config LV_USE_TJPGD - bool "TJPGD decoder library" - - config LV_USE_LIBJPEG_TURBO - bool "libjpeg-turbo decoder library" - - config LV_USE_GIF - bool "GIF decoder library" - - config LV_GIF_CACHE_DECODE_DATA - bool "Use extra 16KB RAM to cache decoded data to accelerate" - depends on LV_USE_GIF - - config LV_BIN_DECODER_RAM_LOAD - bool "Decode whole image to RAM for bin decoder" - default n - - config LV_USE_RLE - bool "LVGL's version of RLE compression method" - - config LV_USE_QRCODE - bool "QR code library" - - config LV_USE_BARCODE - bool "Barcode library" - - config LV_USE_FREETYPE - bool "FreeType library" - config LV_FREETYPE_USE_LVGL_PORT - bool "Let FreeType to use LVGL memory and file porting" - default n - depends on LV_USE_FREETYPE - config LV_FREETYPE_CACHE_FT_GLYPH_CNT - int "The maximum number of Glyph in count" - default 256 - depends on LV_USE_FREETYPE - - config LV_USE_TINY_TTF - bool "Enable Tiny TTF decoder" - default n - config LV_TINY_TTF_FILE_SUPPORT - bool "Enable loading Tiny TTF data from files" - default n - depends on LV_USE_TINY_TTF - config LV_TINY_TTF_CACHE_GLYPH_CNT - bool "Tiny ttf cache entries count" - default 256 - depends on LV_USE_TINY_TTF - - config LV_USE_RLOTTIE - bool "Lottie library" - - config LV_USE_THORVG - bool "ThorVG library" - choice - prompt "Use ThorVG config" - depends on LV_USE_THORVG - default LV_USE_THORVG_INTERNAL - config LV_USE_THORVG_INTERNAL - bool "Use ThorVG internal" - config LV_USE_THORVG_EXTERNAL - bool "Use ThorVG external" - endchoice - - config LV_USE_LZ4 - bool "Enable LZ4 compress/decompress lib" - choice - prompt "Choose lvgl built-in LZ4 lib or external lib" - depends on LV_USE_LZ4 - default LV_USE_LZ4_INTERNAL - config LV_USE_LZ4_INTERNAL - bool "Use lvgl built-in LZ4 lib" - config LV_USE_LZ4_EXTERNAL - bool "Use external LZ4 library" - endchoice - - config LV_USE_FFMPEG - bool "FFmpeg library" - config LV_FFMPEG_DUMP_FORMAT - bool "Dump format" - depends on LV_USE_FFMPEG - default n - endmenu - - menu "Others" - config LV_USE_SNAPSHOT - bool "Enable API to take snapshot" - default n if !LV_CONF_MINIMAL - - config LV_USE_SYSMON - bool "Enable system monitor component" - default n - - config LV_USE_PERF_MONITOR - bool "Show CPU usage and FPS count" - depends on LV_USE_SYSMON - - choice - prompt "Performance monitor position" - depends on LV_USE_PERF_MONITOR - default LV_PERF_MONITOR_ALIGN_BOTTOM_RIGHT - - config LV_PERF_MONITOR_ALIGN_TOP_LEFT - bool "Top left" - config LV_PERF_MONITOR_ALIGN_TOP_MID - bool "Top middle" - config LV_PERF_MONITOR_ALIGN_TOP_RIGHT - bool "Top right" - config LV_PERF_MONITOR_ALIGN_BOTTOM_LEFT - bool "Bottom left" - config LV_PERF_MONITOR_ALIGN_BOTTOM_MID - bool "Bottom middle" - config LV_PERF_MONITOR_ALIGN_BOTTOM_RIGHT - bool "Bottom right" - config LV_PERF_MONITOR_ALIGN_LEFT_MID - bool "Left middle" - config LV_PERF_MONITOR_ALIGN_RIGHT_MID - bool "Right middle" - config LV_PERF_MONITOR_ALIGN_CENTER - bool "Center" - endchoice - - config LV_USE_PERF_MONITOR_LOG_MODE - bool "Prints performance data using log" - depends on LV_USE_PERF_MONITOR - default n - - config LV_USE_MEM_MONITOR - bool "Show the used memory and the memory fragmentation" - default n - depends on LV_USE_BUILTIN_MALLOC && LV_USE_SYSMON - - choice - prompt "Memory monitor position" - depends on LV_USE_MEM_MONITOR - default LV_MEM_MONITOR_ALIGN_BOTTOM_LEFT - - config LV_MEM_MONITOR_ALIGN_TOP_LEFT - bool "Top left" - config LV_MEM_MONITOR_ALIGN_TOP_MID - bool "Top middle" - config LV_MEM_MONITOR_ALIGN_TOP_RIGHT - bool "Top right" - config LV_MEM_MONITOR_ALIGN_BOTTOM_LEFT - bool "Bottom left" - config LV_MEM_MONITOR_ALIGN_BOTTOM_MID - bool "Bottom middle" - config LV_MEM_MONITOR_ALIGN_BOTTOM_RIGHT - bool "Bottom right" - config LV_MEM_MONITOR_ALIGN_LEFT_MID - bool "Left middle" - config LV_MEM_MONITOR_ALIGN_RIGHT_MID - bool "Right middle" - config LV_MEM_MONITOR_ALIGN_CENTER - bool "Center" - endchoice - - config LV_USE_PROFILER - bool "Runtime performance profiler" - config LV_USE_PROFILER_BUILTIN - bool "Enable the built-in profiler" - depends on LV_USE_PROFILER - default y - config LV_PROFILER_BUILTIN_BUF_SIZE - int "Default profiler trace buffer size in bytes" - depends on LV_USE_PROFILER_BUILTIN - default 16384 - config LV_PROFILER_INCLUDE - string "Header to include for the profiler" - depends on LV_USE_PROFILER - default "lvgl/src/misc/lv_profiler_builtin.h" - - config LV_USE_MONKEY - bool "Enable Monkey test" - default n - - config LV_USE_GRIDNAV - bool "Enable grid navigation" - default n - - config LV_USE_FRAGMENT - bool "Enable lv_obj fragment" - default n - - config LV_USE_IMGFONT - bool "Support using images as font in label or span widgets" - default n - - config LV_USE_OBSERVER - bool "Observer" - default y - - config LV_USE_IME_PINYIN - bool "Enable Pinyin input method" - default n - config LV_IME_PINYIN_USE_K9_MODE - bool "Enable Pinyin input method 9 key input mode" - depends on LV_USE_IME_PINYIN - default n - config LV_IME_PINYIN_K9_CAND_TEXT_NUM - int "Maximum number of candidate panels for 9-key input mode" - depends on LV_IME_PINYIN_USE_K9_MODE - default 3 - config LV_IME_PINYIN_USE_DEFAULT_DICT - bool "Use built-in Thesaurus" - depends on LV_USE_IME_PINYIN - default y - help - If you do not use the default thesaurus, be sure to use lv_ime_pinyin after setting the thesaurus - config LV_IME_PINYIN_CAND_TEXT_NUM - int "Maximum number of candidate panels" - depends on LV_USE_IME_PINYIN - default 6 - help - Set the maximum number of candidate panels that can be displayed. - This needs to be adjusted according to the size of the screen. - - config LV_USE_FILE_EXPLORER - bool "Enable file explorer" - default n - config LV_FILE_EXPLORER_PATH_MAX_LEN - int "Maximum length of path" - depends on LV_USE_FILE_EXPLORER - default 128 - config LV_FILE_EXPLORER_QUICK_ACCESS - bool "Enable quick access bar" - depends on LV_USE_FILE_EXPLORER - default y - help - This can save some memory, but not much. After the quick access bar is created, it can be hidden by clicking the button at the top left corner of the browsing area, which is very useful for small screen devices. - - config LVGL_VERSION_MAJOR - int - default 9 # LVGL_VERSION_MAJOR - config LVGL_VERSION_MINOR - int - default 2 # LVGL_VERSION_MINOR - config LVGL_VERSION_PATCH - int - default 2 # LVGL_VERSION_PATCH - endmenu - - menu "Devices" - config LV_USE_SDL - bool "Use SDL to open window on PC and handle mouse and keyboard" - default n - config LV_SDL_INCLUDE_PATH - string "SDL include path" - depends on LV_USE_SDL - default "SDL2/SDL.h" - - choice - prompt "SDL rendering mode" - depends on LV_USE_SDL - default LV_SDL_RENDER_MODE_DIRECT - help - LV_DISPLAY_RENDER_MODE_DIRECT is recommended for best performance - - config LV_SDL_RENDER_MODE_PARTIAL - bool "Use the buffer(s) to render the screen is smaller parts" - - config LV_SDL_RENDER_MODE_DIRECT - bool "Only the changed areas will be updated with 2 screen sized buffers" - - config LV_SDL_RENDER_MODE_FULL - bool "Always redraw the whole screen even if only one pixel has been changed with 2 screen sized buffers" - endchoice - - choice - prompt "SDL buffer size" - depends on LV_USE_SDL - default LV_SDL_SINGLE_BUFFER - - config LV_SDL_SINGLE_BUFFER - bool "One screen-sized buffer" - - config LV_SDL_DOUBLE_BUFFER - bool "Two screen-sized buffer" - depends on !LV_SDL_RENDER_MODE_PARTIAL - - config LV_SDL_CUSTOM_BUFFER - bool "Custom-sized buffer" - depends on LV_SDL_RENDER_MODE_PARTIAL - endchoice - - config LV_SDL_BUFFER_COUNT - int - depends on LV_USE_SDL - default 0 if LV_SDL_CUSTOM_BUFFER - default 1 if LV_SDL_SINGLE_BUFFER - default 2 if LV_SDL_DOUBLE_BUFFER - - config LV_SDL_ACCELERATED - bool "Use hardware acceleration" - depends on LV_USE_SDL - default y - - config LV_SDL_FULLSCREEN - bool "SDL fullscreen" - depends on LV_USE_SDL - default n - - config LV_SDL_DIRECT_EXIT - bool "Exit the application when all SDL windows are closed" - depends on LV_USE_SDL - default y - - choice - prompt "SDL mousewheel mode" - depends on LV_USE_SDL - default LV_SDL_MOUSEWHEEL_MODE_ENCODER - - config LV_SDL_MOUSEWHEEL_MODE_ENCODER - bool "The mousewheel emulates an encoder input device" - - config LV_SDL_MOUSEWHEEL_MODE_CROWN - bool "The mousewheel emulates a smart watch crown" - endchoice - - config LV_SDL_MOUSEWHEEL_MODE - int - depends on LV_USE_SDL - default 0 if LV_SDL_MOUSEWHEEL_MODE_ENCODER - default 1 if LV_SDL_MOUSEWHEEL_MODE_CROWN - - config LV_USE_X11 - bool "Use X11 window manager to open window on Linux PC and handle mouse and keyboard" - default n - config LV_X11_DOUBLE_BUFFER - bool "Use double buffers for lvgl rendering" - depends on LV_USE_X11 - default y - config LV_X11_DIRECT_EXIT - bool "Exit the application when all X11 windows have been closed" - depends on LV_USE_X11 - default y - choice - prompt "X11 device render mode" - depends on LV_USE_X11 - default LV_X11_RENDER_MODE_PARTIAL - - config LV_X11_RENDER_MODE_PARTIAL - bool "Partial render mode (preferred)" - help - Use the buffer(s) to render the screen is smaller parts. This way the buffers can be smaller then the display to save RAM. - Appr. 1/10 screen size buffer(s) are used. - config LV_X11_RENDER_MODE_DIRECT - bool "Direct render mode" - help - The buffer(s) has to be screen sized and LVGL will render into the correct location of the buffer. This way the buffer always contain the whole image. Only the changed ares will be updated. - With 2 buffers the buffers' content are kept in sync automatically and in flush_cb only address change is required. - config LV_X11_RENDER_MODE_FULL - bool "Full render mode" - help - Always redraw the whole screen even if only one pixel has been changed. - With 2 buffers in flush_cb only and address change is required. - endchoice - - config LV_USE_WAYLAND - bool "Use the wayland client to open a window and handle inputs on Linux or BSD" - default n - config LV_WAYLAND_WINDOW_DECORATIONS - bool "Draw client side window decorations, only necessary on Mutter (GNOME)" - depends on LV_USE_WAYLAND - default n - config LV_WAYLAND_WL_SHELL - bool "Support the legacy wl_shell instead of the default XDG Shell protocol" - depends on LV_USE_WAYLAND - default n - - config LV_USE_LINUX_FBDEV - bool "Use Linux framebuffer device" - default n - config LV_LINUX_FBDEV_BSD - bool "Use BSD flavored framebuffer device" - depends on LV_USE_LINUX_FBDEV - default n - - choice - prompt "Framebuffer device render mode" - depends on LV_USE_LINUX_FBDEV - default LV_LINUX_FBDEV_RENDER_MODE_PARTIAL - - config LV_LINUX_FBDEV_RENDER_MODE_PARTIAL - bool "Partial mode" - help - Use the buffer(s) to render the screen is smaller parts. This way the buffers can be smaller then the display to save RAM. At least 1/10 screen size buffer(s) are recommended. - - config LV_LINUX_FBDEV_RENDER_MODE_DIRECT - bool "Direct mode" - help - The buffer(s) has to be screen sized and LVGL will render into the correct location of the buffer. This way the buffer always contain the whole image. Only the changed ares will be updated. With 2 buffers the buffers' content are kept in sync automatically and in flush_cb only address change is required. - - config LV_LINUX_FBDEV_RENDER_MODE_FULL - bool "Full mode" - help - Always redraw the whole screen even if only one pixel has been changed. With 2 buffers in flush_cb only and address change is required. - - endchoice - - choice - prompt "Framebuffer size" - depends on LV_USE_LINUX_FBDEV - default LV_LINUX_FBDEV_SINGLE_BUFFER - - config LV_LINUX_FBDEV_SINGLE_BUFFER - bool "One screen-sized buffer" - - config LV_LINUX_FBDEV_DOUBLE_BUFFER - bool "Two screen-sized buffer" - depends on !LV_LINUX_FBDEV_RENDER_MODE_PARTIAL - - config LV_LINUX_FBDEV_CUSTOM_BUFFER - bool "Custom-sized buffer" - depends on LV_LINUX_FBDEV_RENDER_MODE_PARTIAL - - endchoice - - config LV_LINUX_FBDEV_BUFFER_COUNT - int - depends on LV_USE_LINUX_FBDEV - default 0 if LV_LINUX_FBDEV_CUSTOM_BUFFER - default 1 if LV_LINUX_FBDEV_SINGLE_BUFFER - default 2 if LV_LINUX_FBDEV_DOUBLE_BUFFER - - config LV_LINUX_FBDEV_BUFFER_SIZE - int "Custom partial buffer size (in number of rows)" - depends on LV_USE_LINUX_FBDEV && LV_LINUX_FBDEV_CUSTOM_BUFFER - default 60 - - config LV_USE_NUTTX - bool "Use Nuttx to open window and handle touchscreen" - default n - - config LV_USE_NUTTX_LIBUV - bool "Use uv loop to replace default timer loop and other fb/indev timers" - depends on LV_USE_NUTTX - default n - - config LV_USE_NUTTX_CUSTOM_INIT - bool "Use Custom Nuttx init API to open window and handle touchscreen" - depends on LV_USE_NUTTX - default n - - config LV_USE_NUTTX_LCD - bool "Use NuttX LCD device" - depends on LV_USE_NUTTX - default n - - choice - prompt "NuttX LCD buffer size" - depends on LV_USE_NUTTX_LCD - default LV_NUTTX_LCD_SINGLE_BUFFER - - config LV_NUTTX_LCD_SINGLE_BUFFER - bool "One screen-sized buffer" - - config LV_NUTTX_LCD_DOUBLE_BUFFER - bool "Two screen-sized buffer" - - config LV_NUTTX_LCD_CUSTOM_BUFFER - bool "Custom-sized buffer" - - endchoice - - config LV_NUTTX_LCD_BUFFER_COUNT - int - depends on LV_USE_NUTTX_LCD - default 0 if LV_NUTTX_LCD_CUSTOM_BUFFER - default 1 if LV_NUTTX_LCD_SINGLE_BUFFER - default 2 if LV_NUTTX_LCD_DOUBLE_BUFFER - - config LV_NUTTX_LCD_BUFFER_SIZE - int "Custom partial buffer size (in number of rows)" - depends on LV_USE_NUTTX_LCD && LV_NUTTX_LCD_CUSTOM_BUFFER - default 60 - - config LV_USE_NUTTX_TOUCHSCREEN - bool "Use NuttX touchscreen driver" - depends on LV_USE_NUTTX - default n - - config LV_USE_LINUX_DRM - bool "Use Linux DRM device" - default n - - config LV_USE_TFT_ESPI - bool "Use TFT_eSPI driver" - default n - - config LV_USE_EVDEV - bool "Use evdev input driver" - default n - - config LV_USE_LIBINPUT - bool "Use libinput input driver" - default n - - config LV_LIBINPUT_BSD - bool "Use the BSD variant of the libinput input driver" - depends on LV_USE_LIBINPUT - default n - - config LV_LIBINPUT_XKB - bool "Enable full keyboard support via XKB" - depends on LV_USE_LIBINPUT - default n - - config LV_USE_ST7735 - bool "Use ST7735 LCD driver" - default n - - config LV_USE_ST7789 - bool "Use ST7789 LCD driver" - default n - - config LV_USE_ST7796 - bool "Use ST7796 LCD driver" - default n - - config LV_USE_ILI9341 - bool "Use ILI9341 LCD driver" - default n - - config LV_USE_GENERIC_MIPI - bool "Generic MIPI driver" - default y if LV_USE_ST7735 || LV_USE_ST7789 || LV_USE_ST7796 || LV_USE_ILI9341 - - config LV_USE_RENESAS_GLCDC - bool "Use Renesas GLCDC driver" - default n - - config LV_USE_WINDOWS - bool "Use LVGL Windows backend" - depends on LV_OS_WINDOWS - default n - - config LV_USE_OPENGLES - bool "Use GLFW and OpenGL to open window on PC and handle mouse and keyboard" - default n - - config LV_USE_OPENGLES_DEBUG - bool "Enable debug mode for OpenGL" - depends on LV_USE_OPENGLES - default n - - config LV_USE_QNX - bool "Use a QNX Screen window as a display" - default n - - config LV_QNX_BUF_COUNT - int - depends on LV_USE_QNX - default 1 - endmenu - - menu "Examples" - config LV_BUILD_EXAMPLES - bool "Enable the examples to be built" - default y if !LV_CONF_MINIMAL - endmenu - - menu "Demos" - config LV_USE_DEMO_WIDGETS - bool "Show some widget" - default n - - config LV_USE_DEMO_KEYPAD_AND_ENCODER - bool "Demonstrate the usage of encoder and keyboard" - default n - - config LV_USE_DEMO_BENCHMARK - bool "Benchmark your system" - default n - depends on LV_FONT_MONTSERRAT_14 && LV_FONT_MONTSERRAT_24 && LV_USE_DEMO_WIDGETS - config LV_USE_DEMO_RENDER - bool "Render test for each primitives. Requires at least 480x272 display" - default n - - config LV_USE_DEMO_SCROLL - bool "Scroll settings test for LVGL" - default n - - config LV_USE_DEMO_STRESS - bool "Stress test for LVGL" - default n - - config LV_USE_DEMO_TRANSFORM - bool "Transform test for LVGL" - default n - depends on LV_FONT_MONTSERRAT_18 - - config LV_USE_DEMO_MUSIC - bool "Music player demo" - default n - config LV_DEMO_MUSIC_SQUARE - bool "Enable Square" - depends on LV_USE_DEMO_MUSIC - default n - config LV_DEMO_MUSIC_LANDSCAPE - bool "Enable Landscape" - depends on LV_USE_DEMO_MUSIC - default n - config LV_DEMO_MUSIC_ROUND - bool "Enable Round" - depends on LV_USE_DEMO_MUSIC - default n - config LV_DEMO_MUSIC_LARGE - bool "Enable Large" - depends on LV_USE_DEMO_MUSIC - default n - config LV_DEMO_MUSIC_AUTO_PLAY - bool "Enable Auto play" - depends on LV_USE_DEMO_MUSIC - default n - - config LV_USE_DEMO_FLEX_LAYOUT - bool "Flex layout previewer" - default n - config LV_USE_DEMO_MULTILANG - bool "multi-language demo" - default n - config LV_USE_DEMO_VECTOR_GRAPHIC - bool "vector graphic demo" - default n - depends on LV_USE_VECTOR_GRAPHIC - endmenu +config LVGL_VERSION + string "LVGL Version" + default "7.3.0" + +config LV_MEM_SIZE + int "Heap size of the graphics library" + default 32768 + ---help--- + The size of a memory pool where the grapohisc library + dynamically allocates data + +config LV_USE_USER_DATA + bool "Use user data in driver and objects" + default n + ---help--- + Add a `user_data` to drivers and objects + +config LV_USE_PERF_MONITOR + bool "Show CPU usage and FPS count" + default n + ---help--- + Show CPU usage and FPS count in the right bottom corner + +menu "Graphics settings" + +config LV_HOR_RES + int "Horizontal resolution." + default 320 + ---help--- + Number of pixels in horizontally. + +config LV_VER_RES + int "Vertical resolution." + default 240 + ---help--- + Number of pixels vertically. Double it if anti aliasing is used + +config LV_DPI + int "DPI (px/inch)" + default 100 + ---help--- + Number of pixels in 1 inch + +config LV_ANTIALIAS + bool "Anti aliasing of the screen" + default n + +config LV_DISP_DEF_REFR_PERIOD + int "Default refresh period in milliseconds" + default 30 + ---help--- + The graphics library will check for invalid areas an refresh + them with this period time + +config LV_INV_FIFO_SIZE + int "Average number of object on the screen" + default 32 + ---help--- + If too much area is invalidated (greater then this number) then + the whole screen will be refreshed endmenu -config LV_OPTLEVEL - string "Customize compilation optimization level" - default "" +menu "Input device settings" + +config LV_INDEV_DEF_READ_PERIOD + int "Input device default read period in milliseconds" + default 30 + +config LV_INDEV_POINT_MARKER + int "Mark the pressed points on the screen" + default 0 + +config LV_INDEV_DEF_DRAG_LIMIT + int "Default drag limit in pixels" + default 10 + +config LV_INDEV_DEF_DRAG_THROW + int "Default slow down ration when throwing on object by drag [%]" + default 20 + +config LV_INDEV_DEF_LONG_PRESS_TIME + int "Default long press time [ms]" + default 400 + +config LV_INDEV_DEF_LONG_PRESS_REP_TIME + int "Default repeated trigger period in long press [ms]" + default 100 + +config LV_INDEV_DEF_GESTURE_LIMIT + int "Gesture threshold in pixels" + default 50 + +config LV_INDEV_DEF_GESTURE_MIN_VELOCITY + int "Gesture min velocity at release before swipe (pixels)" + default 3 + +endmenu + +menu "Color settings" + +config LV_COLOR_DEPTH + int "Color depth (8/16/32)" + default 16 + +config LV_COLOR_16_SWAP + bool "Swap the 2 bytes of RGB565 color" + depends on LV_COLOR_DEPTH = 16 + default 0 + +config LV_COLOR_SCREEN_TRANSP + bool "Enable screen transparency.(If disabled, 32-bit color depth fall to 24-bit)" + default 0 + +config LV_COLOR_TRANSP + hex "Chroma key color (pixels with this color will be transparent on images)" + default 0x00ff00 + +endmenu + +menu "Text (font) settings" + +config LV_TXT_UTF8 + bool "Unicode support" + default n + +config LV_TXT_BREAK_CHARS + string "Characters where the words/line cab be wrapped" + default " ,.;:-_" + +endmenu + +menu "Feature usage" +config USE_LV_ANIMATION + bool "Enable animations" + default y + +config USE_LV_SHADOW + bool "Enable shadows" + default y + +config USE_LV_GROUP + bool "Enable object groups (for keyboard)" + default y + +config USE_LV_GPU + bool "Enable GPU (hardware acceleration) API" + default y + +config USE_LV_REAL_DRAW + bool "Enable function which draws directly to the frame buffer instead of VDB" + default y + +config USE_LV_FILESYSTEM + bool "Enable filesystem (required for images, lv_img)" + default y + +if USE_LV_FILESYSTEM + +config LV_FILESYSTEM_MOUNTPOINT + string "File system mount point" + default "/data" + +endif + +config USE_LV_MULTI_LANG + int "Number of languages for labels to store (0 to disable)" + default 0 + +endmenu + +menu "Log usage" + +config LV_USE_LOG + bool "Enable/disable the log module" + default n + +choice + prompt "Log level" + depends on LV_USE_LOG + default LV_LOG_LEVEL_WARN + +config LV_LOG_LEVEL_TRACE + bool "Trace" + +config LV_LOG_LEVEL_INFO + bool "Info" + +config LV_LOG_LEVEL_WARN + bool "Warn" + +config LV_LOG_LEVEL_ERROR + bool "Error" + +endchoice + +config LV_LOG_PRINTF + bool "Use printf() for logging" + depends on LV_USE_LOG + default y + +endmenu + +menu "Debug usage" + +config LV_USE_DEBUG + bool "Enable/disable the debug module" + default n + +config LV_USE_ASSERT_NULL + bool "Check if the parameter is NULL" + depends on LV_USE_DEBUG + default n + +config LV_USE_ASSERT_MEM + bool "Checks is the memory is successfully allocated or no" + depends on LV_USE_DEBUG + default n + +config LV_USE_ASSERT_STR + bool "Check the strings" + depends on LV_USE_DEBUG + default n + +config LV_USE_ASSERT_OBJ + bool "Check object's type and existence" + depends on LV_USE_DEBUG + default n + +config LV_USE_ASSERT_STYLE + bool "Check if the styles are properly initialized" + depends on LV_USE_DEBUG + default n + +endmenu + +menu "Theme usage" + +config LV_USE_THEME_TEMPL + bool "Use Template theme: just for test" + default n + +config LV_USE_THEME_MONO + bool "Use Mono theme: mono color theme" + default n + +config LV_USE_THEME_MATERIAL + bool "Use Material theme: material theme with bold colors" + default n + +endmenu + +menu "Base object settings" + +config LV_OBJ_REALIGN + bool "Enable `lv_obj_realaign()` based on `lv_obj_align()` parameters" + default y + +endmenu + +menu "Object type usage settings" + +config USE_LV_LABEL + bool "Label usage" + default y + +config LV_LABEL_SCROLL_SPEED + int "Hor, or ver. scroll speed [px/sec] in 'LV_LABEL_LONG_SCROLL/ROLL' mode" + depends on USE_LV_LABEL + default 25 + +config USE_LV_IMG + bool "Image usage" + default y + +config LV_IMG_CF_INDEXED + bool "Enable indexed (palette) images" + depends on USE_LV_IMG + default y + +config LV_IMG_CF_ALPHA + bool "Enable alpha indexed images" + depends on USE_LV_IMG + default y + +config USE_LV_LINE + bool "Line usage" + default y + +config USE_LV_ARC + bool "Arc usage" + default y + +config USE_LV_CONT + bool "Container usage" + default y + +config USE_LV_PAGE + depends on USE_LV_CONT + bool "Page usage" + default y + +config USE_LV_WIN + depends on USE_LV_PAGE && USE_LV_LABEL && USE_LV_IMG && USE_LV_BTN + bool "Window usage" + default y + +config USE_LV_TABVIEW + depends on USE_LV_PAGE && USE_LV_BTNM + bool "Tabview usage" + default y + +config LV_TABVIEW_ANIM_TIME + int "Time of slide animation [ms] (0: no animation)" + depends on USE_LV_TABVIEW + default 300 + +config USE_LV_TILEVIEW + depends on USE_LV_CONT && USE_LV_PAGE + bool "Tileview usage" + default y + +config LV_TILEVIEW_ANIM_TIME + int "Time of slide animation [ms] (0: no animation)" + depends on USE_LV_TILEVIEW + default 300 + +config USE_LV_BAR + bool "Bar usage" + default y + +config USE_LV_LMETER + depends on USE_LV_BAR + bool "Line meter usage" + default y + +config USE_LV_GAUGE + depends on USE_LV_BAR && USE_LV_LMETER + bool "Gauge usage" + default y + +config USE_LV_CHART + bool "Chart usage" + default y + +config LV_CHART_AXIS_TICK_LABEL_MAX_LEN + depends on USE_LV_CHART + int "Chart axis tick label max length" + default 20 + +config USE_LV_TABLE + bool "Table usage" + depends on USE_LV_LABEL + default y + +config LV_TABLE_COL_MAX + int "Maximum number of table columns" + depends on USE_LV_TABLE + default 12 + +config USE_LV_LED + bool "LED usage" + default y + +config USE_LV_MBOX + bool "Messagebox usage" + depends on USE_LV_BTNM && USE_LV_LABEL + default y + +config USE_LV_TA + bool "Text area usage" + depends on USE_LV_LABEL && USE_LV_PAGE + default y + +config USE_LV_SPINBOX + bool "Spinbox usage" + depends on USE_LV_TA + default y + +config USE_LV_CALENDAR + bool "Calendar usage" + default y + +config USE_LV_PRELOAD + bool "Preload usage" + depends on USE_LV_ARC + default y + +config LV_PRELOAD_DEF_ARC_LENGTH + int "Degrees of arc length (default)" + range 0 360 + depends on USE_LV_PRELOAD + default 60 + +config LV_PRELOAD_DEF_SPIN_TIME + int "Time (ms) preload spins (default)" + depends on USE_LV_PRELOAD + default 1000 + +choice + prompt "Default preload animation" + depends on USE_LV_PRELOAD + default LV_PRELOAD_DEF_ANIM_SPINNING_ARC + +config LV_PRELOAD_DEF_ANIM_SPINNING_ARC + bool "Spinning Arc" + +config LV_PRELOAD_DEF_ANIM_FILLSPIN_ARC + bool "Fillspin Arc" + +endchoice + +config USE_LV_CANVAS + bool "Canvas usage" + depends on USE_LV_IMG + default n + +config USE_LV_BTN + bool "Button usage" + depends on USE_LV_CONT + default y + +config LV_BTN_INK_EFFECT + bool "Enable button-state animations" + depends on USE_LV_BTN && USE_LV_ANIMATION + default y + +config USE_LV_IMGBTN + depends on USE_LV_BTN + bool "Image button usage" + default y + +config LV_IMGBTN_TILED + bool "Tiled image button" + depends on USE_LV_IMGBTN + ---help--- + The imgbtn requires left, mid and right parts and the width can be set freely + +config USE_LV_BTNM + bool "Button matrix usage" + default y + +config USE_LV_KB + bool "Keyboard" + depends on USE_LV_BTNM + default y + +config USE_LV_CB + bool "Chekbox usage" + depends on USE_LV_BTN + default y + +config USE_LV_SW + bool "Switch usage" + depends on USE_LV_BTN + default y + +config USE_LV_LIST + bool "List usage" + depends on USE_LV_BTN && USE_LV_PAGE + default y + +config USE_LV_DDLIST + bool "Drop down list usage" + depends on USE_LV_PAGE && USE_LV_LABEL + default y + +config USE_LV_ROLLER + bool "Roller usage" + depends on USE_LV_DDLIST + default y + +config USE_LV_SLIDER + bool "Slider usage" + depends on USE_LV_BAR + default y + +endmenu endif # GRAPHICS_LVGL diff --git a/graphics/lvgl/Make.defs b/graphics/lvgl/Make.defs index 041bcf61e..627ad303f 100644 --- a/graphics/lvgl/Make.defs +++ b/graphics/lvgl/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/graphics/lvgl/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -20,12 +18,16 @@ # ############################################################################ -ifneq ($(CONFIG_GRAPHICS_LVGL),) +ifeq ($(CONFIG_GRAPHICS_LVGL),y) CONFIGURED_APPS += $(APPDIR)/graphics/lvgl # It allows `` import. -CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/graphics/lvgl -CXXFLAGS += ${INCDIR_PREFIX}$(APPDIR)/graphics/lvgl +CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(APPDIR)/graphics/lvgl} +CXXFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(APPDIR)/graphics/lvgl} +# It allows `` import. + +CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(APPDIR)/graphics/lvgl/lvgl} +CXXFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(APPDIR)/graphics/lvgl/lvgl} endif diff --git a/graphics/lvgl/Makefile b/graphics/lvgl/Makefile index ce9ad6b7f..ff66ae4df 100644 --- a/graphics/lvgl/Makefile +++ b/graphics/lvgl/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/graphics/lvgl/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -27,70 +25,55 @@ include $(APPDIR)/Make.defs LVGL_DIR = . LVGL_DIR_NAME = lvgl --include ./lvgl/lvgl.mk +# Relax format check for LVGL to avoid errors on prinf() use -ifneq ($(CONFIG_LV_ASSERT_HANDLER_INCLUDE), "") -CFLAGS += "-DLV_ASSERT_HANDLER=ASSERT(0);" -endif +CFLAGS += -Wno-format -ifeq ($(and $(CONFIG_LV_USE_PERF_MONITOR),$(CONFIG_SCHED_CPULOAD)),y) -CFLAGS += "-DLV_SYSMON_GET_IDLE=lv_nuttx_get_idle" -endif +# LVGL Libraries -ifeq ($(and $(CONFIG_SCHED_INSTRUMENTATION),$(CONFIG_LV_USE_PROFILER)),y) -CFLAGS += "-DLV_PROFILER_BEGIN=sched_note_beginex(NOTE_TAG_GRAPHICS, __func__)" -CFLAGS += "-DLV_PROFILER_END=sched_note_endex(NOTE_TAG_GRAPHICS, __func__)" +-include ./lvgl/src/lv_core/lv_core.mk +-include ./lvgl/src/lv_hal/lv_hal.mk +-include ./lvgl/src/lv_widgets/lv_widgets.mk +-include ./lvgl/src/lv_font/lv_font.mk +-include ./lvgl/src/lv_misc/lv_misc.mk +-include ./lvgl/src/lv_themes/lv_themes.mk +-include ./lvgl/src/lv_draw/lv_draw.mk +-include ./lvgl/src/lv_gpu/lv_gpu.mk -CFLAGS += "-DLV_PROFILER_BEGIN_TAG(str)=sched_note_beginex(NOTE_TAG_GRAPHICS, str)" -CFLAGS += "-DLV_PROFILER_END_TAG(str)=sched_note_endex(NOTE_TAG_GRAPHICS, str)" -endif +CSRCS += lv_tick_interface.c -ifneq ($(CONFIG_LV_OPTLEVEL), "") -# Since multiple options need to be supported, subst needs to be used here to remove -# the redundant double quotes, otherwise it will cause command parsing errors. -CFLAGS += $(subst ",, $(CONFIG_LV_OPTLEVEL)) -CXXFLAGS += $(subst ",, $(CONFIG_LV_OPTLEVEL)) +ifneq ($(CONFIG_USE_LV_FILESYSTEM),) +CSRCS += lv_fs_interface.c endif # Set up build configuration and environment WD := ${shell echo $(CURDIR) | sed -e 's/ /\\ /g'} -CONFIG_GRAPH_LVGL_URL ?= "https://github.com/lvgl/lvgl/archive/refs/tags" +CONFIG_GRAPH_LVGL_URL ?= "https://github.com/lvgl/lvgl/archive" -_MAJ := $(CONFIG_LVGL_VERSION_MAJOR) -_MIN := $(CONFIG_LVGL_VERSION_MINOR) -_PAT := $(CONFIG_LVGL_VERSION_PATCH) -LVGL_VERSION := $(_MAJ).$(_MIN).$(_PAT) -LVGL_TARBALL := v$(LVGL_VERSION).zip +LVGL_VERSION = $(patsubst "%",%,$(strip $(CONFIG_LVGL_VERSION))) +LVGL_TARBALL = v$(LVGL_VERSION).zip LVGL_UNPACKNAME = lvgl -UNPACK ?= unzip -o $(if $(V),,-q) -CURL ?= curl -L -O $(if $(V),,-Ss) +UNPACK ?= unzip -o LVGL_UNPACKDIR = $(WD)/$(LVGL_UNPACKNAME) $(LVGL_TARBALL): - $(ECHO_BEGIN)"Downloading: $(LVGL_TARBALL)" - $(Q) $(CURL) $(CONFIG_GRAPH_LVGL_URL)/$(LVGL_TARBALL) - $(ECHO_END) + $(Q) echo "Downloading: $(LVGL_TARBALL)" + $(Q) curl -O -L $(CONFIG_GRAPH_LVGL_URL)/$(LVGL_TARBALL) $(LVGL_UNPACKNAME): $(LVGL_TARBALL) - $(ECHO_BEGIN)"Unpacking: $(LVGL_TARBALL) -> $(LVGL_UNPACKNAME)" + $(Q) echo "Unpacking: $(LVGL_TARBALL) -> $(LVGL_UNPACKNAME)" $(Q) $(UNPACK) $(LVGL_TARBALL) $(Q) mv lvgl-$(LVGL_VERSION) $(LVGL_UNPACKNAME) $(Q) touch $(LVGL_UNPACKNAME) - $(ECHO_END) -# Download and unpack tarball if no git repo found -ifeq ($(wildcard $(LVGL_UNPACKNAME)/.git),) context:: $(LVGL_UNPACKNAME) -endif -include $(APPDIR)/Application.mk - -ifeq ($(wildcard $(LVGL_UNPACKNAME)/.git),) distclean:: $(call DELDIR, $(LVGL_UNPACKNAME)) $(call DELFILE, $(LVGL_TARBALL)) -endif + +include $(APPDIR)/Application.mk diff --git a/graphics/lvgl/README.md b/graphics/lvgl/README.md new file mode 100644 index 000000000..a3c846a8d --- /dev/null +++ b/graphics/lvgl/README.md @@ -0,0 +1,23 @@ +# Graphics / `lvgl` LVGL + +## Usage + +Import with `#include ` or `#include `. + +Upstream example ported to NuttX is present at `examples/lvgldemo`. + +LVGL can be used with framebuffer device. To find example boards with this +preconfigured, search for `CONFIG_GRAPHICS_LVGL=y` in `defconfig` files. All of +them have also `CONFIG_VIDEO_FB=y` present. + +As a second option, LVGL can talk to a display driver and explicitly draw line +by line. For this case, there is no preconfigured board present. Go to _Porting_ +section of upstream documentation for more hints. + +## Resources + +- [API documentation with examples](https://docs.lvgl.io/latest/en/html/index.html) +- [GitHub / LVGL / LVGL library](https://github.com/lvgl/lvgl) +- [GitHub / LVGL / Examples, tutorials, applications](https://github.com/lvgl/lv_examples) +- [GitHub / LVGL / Desktop simulator](https://github.com/lvgl/lv_sim_eclipse_sdl) +- [GitHub / LVGL / Web simulator](https://github.com/lvgl/lv_sim_emscripten) diff --git a/graphics/lvgl/lv_conf.h b/graphics/lvgl/lv_conf.h new file mode 100644 index 000000000..53ac9959d --- /dev/null +++ b/graphics/lvgl/lv_conf.h @@ -0,0 +1,1052 @@ +/**************************************************************************** + * apps/graphics/lvgl/lv_conf.h + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __APPS_GRAPHICS_LVGL_LV_CONF_H +#define __APPS_GRAPHICS_LVGL_LV_CONF_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +/* Type of coordinates. Should be `int16_t` + * (or `int32_t` for extreme cases) + */ + +typedef int16_t lv_coord_t; + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Graphical settings + ****************************************************************************/ + +/* Maximal horizontal and vertical resolution to support by the library. */ + +#define LV_HOR_RES_MAX CONFIG_LV_HOR_RES +#define LV_VER_RES_MAX CONFIG_LV_VER_RES + +/* Color depth: + * - 1: 1 byte per pixel + * - 8: RGB233 + * - 16: RGB565 + * - 32: ARGB8888 + */ + +#define LV_COLOR_DEPTH CONFIG_LV_COLOR_DEPTH + +/* Swap the 2 bytes of RGB565 color. + * Useful if the display has a 8 bit interface (e.g. SPI) + */ + +#ifdef CONFIG_LV_COLOR_16_SWAP +#define LV_COLOR_16_SWAP CONFIG_LV_COLOR_16_SWAP +#else +#define LV_COLOR_16_SWAP 0 +#endif + +/* 1: Enable screen transparency. + * Useful for OSD or other overlapping GUIs. + * Requires `LV_COLOR_DEPTH = 32` colors and the screen's style + * should be modified: `style.body.opa = ...` + */ + +#ifdef CONFIG_LV_COLOR_SCREEN_TRANSP +#define LV_COLOR_SCREEN_TRANSP CONFIG_LV_COLOR_SCREEN_TRANSP +#else +#define LV_COLOR_SCREEN_TRANSP 0 +#endif + +/* Images pixels with this color will not be drawn (with chroma keying) */ + +/* LV_COLOR_LIME: pure green */ + +#define LV_COLOR_TRANSP ((lv_color_t){.full = (CONFIG_LV_COLOR_TRANSP)}) + +/* Enable chroma keying for indexed images. */ + +#define LV_INDEXED_CHROMA 1 + +/* Enable anti-aliasing (lines, and radiuses will be smoothed) */ + +#ifdef CONFIG_LV_ANTIALIAS +#define LV_ANTIALIAS CONFIG_LV_ANTIALIAS +#else +#define LV_ANTIALIAS 0 +#endif + +/* Default display refresh period. + * Can be changed in the display driver (`lv_disp_drv_t`). + */ + +#define LV_DISP_DEF_REFR_PERIOD CONFIG_LV_DISP_DEF_REFR_PERIOD /* [ms] */ + +/* Dot Per Inch: used to initialize default sizes. + * E.g. a button with width = LV_DPI / 2 -> half inch wide + * (Not so important, you can adjust it to modify default sizes and spaces) + */ + +#define LV_DPI CONFIG_LV_DPI /* [px] */ + +/* The the real width of the display changes some default values: + * default object sizes, layout of examples, etc. + * According to the width of the display (hor. res. / dpi) + * the displays fall in 4 categories. + * The 4th is extra large which has no upper limit so not listed here + * The upper limit of the categories are set below in 0.1 inch unit. + */ + +#define LV_DISP_SMALL_LIMIT 30 +#define LV_DISP_MEDIUM_LIMIT 50 +#define LV_DISP_LARGE_LIMIT 70 + +/**************************************************************************** + * Memory manager settings + ****************************************************************************/ + +/* LittelvGL's internal memory manager's settings. + * The graphical objects and other related data are stored here. + */ + +/* 1: use custom malloc/free, 0: use the built-in + * `lv_mem_alloc` and `lv_mem_free` + */ + +#define LV_MEM_CUSTOM 1 +#if LV_MEM_CUSTOM == 0 + +/* Size of the memory used by `lv_mem_alloc` in bytes (>= 2kB) */ + +# define LV_MEM_SIZE CONFIG_LV_MEM_SIZE + +/* Compiler prefix for a big array declaration */ + +# define LV_MEM_ATTR + +/* Set an address for the memory pool instead of allocating it as an array. + * Can be in external SRAM too. + */ + +# define LV_MEM_ADR 0 + +/* Automatically defrag. on free. Defrag. means + * joining the adjacent free cells. + */ + +# define LV_MEM_AUTO_DEFRAG 1 +#else /* LV_MEM_CUSTOM */ +# define LV_MEM_CUSTOM_INCLUDE /* Header for the dynamic memory function */ +# define LV_MEM_CUSTOM_ALLOC malloc /* Wrapper to malloc */ +# define LV_MEM_CUSTOM_FREE free /* Wrapper to free */ +#endif /* LV_MEM_CUSTOM */ + +/* Garbage Collector settings + * Used if lvgl is binded to higher level language and the memory is + * managed by that language + */ + +#define LV_ENABLE_GC 0 +#if LV_ENABLE_GC != 0 +# define LV_GC_INCLUDE "gc.h" /* Include Garbage Collector related things */ +# define LV_MEM_CUSTOM_REALLOC your_realloc /* Wrapper to realloc */ +# define LV_MEM_CUSTOM_GET_SIZE your_mem_get_size /* Wrapper to lv_mem_get_size */ +#endif /* LV_ENABLE_GC */ + +/**************************************************************************** + * Input device settings + ****************************************************************************/ + +/* Input device default settings. + * Can be changed in the Input device driver (`lv_indev_drv_t`) + */ + +/* Input device read period in milliseconds */ + +#define LV_INDEV_DEF_READ_PERIOD CONFIG_LV_INDEV_DEF_READ_PERIOD + +/* Drag threshold in pixels */ + +#define LV_INDEV_DEF_DRAG_LIMIT CONFIG_LV_INDEV_DEF_DRAG_LIMIT + +/* Drag throw slow-down in [%]. Greater value -> faster slow-down */ + +#define LV_INDEV_DEF_DRAG_THROW CONFIG_LV_INDEV_DEF_DRAG_THROW + +/* Long press time in milliseconds. + * Time to send `LV_EVENT_LONG_PRESSSED`) + */ + +#define LV_INDEV_DEF_LONG_PRESS_TIME CONFIG_LV_INDEV_DEF_LONG_PRESS_TIME + +/* Repeated trigger period in long press [ms] + * Time between `LV_EVENT_LONG_PRESSED_REPEAT + */ + +#define LV_INDEV_DEF_LONG_PRESS_REP_TIME \ + CONFIG_LV_INDEV_DEF_LONG_PRESS_REP_TIME + +/* Gesture threshold in pixels */ + +#define LV_INDEV_DEF_GESTURE_LIMIT CONFIG_LV_INDEV_DEF_GESTURE_LIMIT + +/* Gesture min velocity at release before swipe (pixels) */ + +#define LV_INDEV_DEF_GESTURE_MIN_VELOCITY \ + CONFIG_LV_INDEV_DEF_GESTURE_MIN_VELOCITY + +/**************************************************************************** + * Feature usage + ****************************************************************************/ + +/* 1: Enable the Animations */ + +#ifdef CONFIG_USE_LV_ANIMATION +#define LV_USE_ANIMATION CONFIG_USE_LV_ANIMATION +#else +#define LV_USE_ANIMATION 0 +#endif + +#if LV_USE_ANIMATION + +/* Declare the type of the user data of animations + * (can be e.g. `void *`, `int`, `struct`) + */ + +typedef void * lv_anim_user_data_t; + +#endif + +/* 1: Enable shadow drawing */ + +#ifdef CONFIG_USE_LV_SHADOW +#define LV_USE_SHADOW CONFIG_USE_LV_SHADOW +#else +#define LV_USE_SHADOW 0 +#endif + +#if LV_USE_SHADOW +/* Allow buffering some shadow calculation + * LV_SHADOW_CACHE_SIZE is the max. shadow size to buffer, + * where shadow size is `shadow_width + radius` + * Caching has LV_SHADOW_CACHE_SIZE^2 RAM cost + */ + +# define LV_SHADOW_CACHE_SIZE 0 +#endif + +/* 1: Use other blend modes than normal (`LV_BLEND_MODE_...`) */ + +#define LV_USE_BLEND_MODES 1 + +/* 1: Use the `opa_scale` style property to set the opacity + * of an object and its children at once + */ + +#define LV_USE_OPA_SCALE 1 + +/* 1: Use image zoom and rotation */ + +#define LV_USE_IMG_TRANSFORM 1 + +/* 1: Enable object groups (for keyboard/encoder navigation) */ + +#ifdef CONFIG_USE_LV_GROUP +#define LV_USE_GROUP CONFIG_USE_LV_GROUP +#else +#define LV_USE_GROUP 0 +#endif +#if LV_USE_GROUP +typedef void * lv_group_user_data_t; +#endif /* LV_USE_GROUP */ + +/* 1: Enable GPU interface */ + +#ifdef CONFIG_USE_LV_GPU +#define LV_USE_GPU CONFIG_USE_LV_GPU +#else +#define LV_USE_GPU 0 +#endif + +/* 1: Enable file system (might be required for images */ + +#ifdef CONFIG_USE_LV_FILESYSTEM +#define LV_USE_FILESYSTEM CONFIG_USE_LV_FILESYSTEM +#else +#define LV_USE_FILESYSTEM 0 +#endif + +#if LV_USE_FILESYSTEM +/* Declare the type of the user data of file system drivers + * (can be e.g. `void *`, `int`, `struct`) + */ + +typedef void * lv_fs_drv_user_data_t; +#endif + +/* 1: Add a `user_data` to drivers and objects */ + +#ifdef CONFIG_LV_USE_USER_DATA +#define LV_USE_USER_DATA CONFIG_LV_USE_USER_DATA +#else +#define LV_USE_USER_DATA 0 +#endif + +/* 1: Show CPU usage and FPS count in the right bottom corner */ + +#ifdef CONFIG_LV_USE_PERF_MONITOR +#define LV_USE_PERF_MONITOR CONFIG_LV_USE_PERF_MONITOR +#else +#define LV_USE_PERF_MONITOR 0 +#endif + +/* 1: Use the functions and types from the older API if possible */ + +#define LV_USE_API_EXTENSION_V6 1 + +/**************************************************************************** + * Image decoder and cache + ****************************************************************************/ + +/* 1: Enable indexed (palette) images */ + +#ifdef CONFIG_LV_IMG_CF_INDEXED +#define LV_IMG_CF_INDEXED CONFIG_LV_IMG_CF_INDEXED +#else +#define LV_IMG_CF_INDEXED 0 +#endif + +/* 1: Enable alpha indexed images */ + +#ifdef CONFIG_LV_IMG_CF_ALPHA +#define LV_IMG_CF_ALPHA CONFIG_LV_IMG_CF_ALPHA +#else +#define LV_IMG_CF_ALPHA 0 +#endif + +/* Default image cache size. Image caching keeps the images opened. + * If only the built-in image formats are used there is + * no real advantage of caching. + * (I.e. no new image decoder is added) + * With complex image decoders (e.g. PNG or JPG) caching can + * save the continuous open/decode of images. + * However the opened images might consume additional RAM. + * LV_IMG_CACHE_DEF_SIZE must be >= 1 + */ + +#define LV_IMG_CACHE_DEF_SIZE 1 + +/* Declare the type of the user data of image decoder + * (can be e.g. `void *`, `int`, `struct`) + */ + +typedef void * lv_img_decoder_user_data_t; + +/**************************************************************************** + * Compiler settings + ****************************************************************************/ + +/* Define a custom attribute to `lv_tick_inc` function */ + +#define LV_ATTRIBUTE_TICK_INC + +/* Define a custom attribute to `lv_task_handler` function */ + +#define LV_ATTRIBUTE_TASK_HANDLER + +/* With size optimization (-Os) the compiler might not align data to + * 4 or 8 byte boundary. This alignment will be explicitly applied + * where needed. + * E.g. __attribute__((aligned(4))) + */ + +#define LV_ATTRIBUTE_MEM_ALIGN + +/* Attribute to mark large constant arrays for example + * font's bitmaps + */ + +#define LV_ATTRIBUTE_LARGE_CONST + +/* Prefix performance critical functions to place them into a + * faster memory (e.g RAM). Uses 15-20 kB extra memory + */ + +#define LV_ATTRIBUTE_FAST_MEM + +/* Export integer constant to binding. + * This macro is used with constants in the form of LV_ that + * should also appear on lvgl binding API such as Micropython + * + * The default value just prevents a GCC warning. + */ + +#define LV_EXPORT_CONST_INT(int_value) struct _silence_gcc_warning + +/**************************************************************************** + * HAL settings + ****************************************************************************/ + +/* 1: use a custom tick source. + * It removes the need to manually update the tick with `lv_tick_inc`) + */ + +#define LV_TICK_CUSTOM 1 +#if LV_TICK_CUSTOM == 1 +#define LV_TICK_CUSTOM_INCLUDE "lv_tick_interface.h" /* Header for the sys time function */ +#define LV_TICK_CUSTOM_SYS_TIME_EXPR (lv_tick_interface()) /* Expression evaluating to current systime in ms */ +#endif /* LV_TICK_CUSTOM */ + +typedef void * lv_disp_drv_user_data_t; /* Type of user data in the display driver */ +typedef void * lv_indev_drv_user_data_t; /* Type of user data in the input device driver */ + +/**************************************************************************** + * Log settings + ****************************************************************************/ + +/* 1: Enable the log module */ + +#ifdef CONFIG_LV_USE_LOG +#define LV_USE_LOG CONFIG_LV_USE_LOG +#else +#define LV_USE_LOG 0 +#endif + +#if LV_USE_LOG +/* How important log should be added: + * LV_LOG_LEVEL_TRACE - A lot of logs to give detailed information + * LV_LOG_LEVEL_INFO - Log important events + * LV_LOG_LEVEL_WARN - Log if something happened but didn't cause a crash + * LV_LOG_LEVEL_ERROR - Only critical issue, when the system may fail + * LV_LOG_LEVEL_NONE - Do not log anything + */ + +#ifdef CONFIG_LV_LOG_LEVEL_TRACE +# define LV_LOG_LEVEL LV_LOG_LEVEL_TRACE +#endif + +#ifdef CONFIG_LV_LOG_LEVEL_INFO +# define LV_LOG_LEVEL LV_LOG_LEVEL_INFO +#endif + +#ifdef CONFIG_LV_LOG_LEVEL_WARN +# define LV_LOG_LEVEL LV_LOG_LEVEL_WARN +#endif + +#ifdef CONFIG_LV_LOG_LEVEL_ERROR +# define LV_LOG_LEVEL LV_LOG_LEVEL_ERROR +#endif + +#ifdef CONFIG_LV_LOG_LEVEL_NONE +# define LV_LOG_LEVEL LV_LOG_LEVEL_NONE +#endif + +/* 1: Print the log with 'printf'; + * 0: user need to register a callback with `lv_log_register_print_cb` + */ + +#ifdef CONFIG_LV_LOG_PRINTF +# define LV_LOG_PRINTF CONFIG_LV_LOG_PRINTF +#else +# define LV_LOG_PRINTF 0 +#endif +#endif /* LV_USE_LOG */ + +/**************************************************************************** + * Debug settings + ****************************************************************************/ + +/* If Debug is enabled LittelvGL validates the parameters of the functions. + * If an invalid parameter is found an error log message is printed and + * the MCU halts at the error. (`LV_USE_LOG` should be enabled) + * If you are debugging the MCU you can pause + * the debugger to see exactly where the issue is. + * + * The behavior of asserts can be overwritten by redefining them here. + * E.g. #define LV_ASSERT_MEM(p) + */ + +#ifndef CONFIG_LV_USE_DEBUG +#define CONFIG_LV_USE_DEBUG 0 +#endif + +#define LV_USE_DEBUG CONFIG_LV_USE_DEBUG + +/* Check if the parameter is NULL. (Quite fast) */ + +#ifdef CONFIG_LV_USE_ASSERT_NULL +#define LV_USE_ASSERT_NULL CONFIG_LV_USE_ASSERT_NULL +#else +#define LV_USE_ASSERT_NULL 0 +#endif + +/* Checks is the memory is successfully allocated or no. (Quite fast) */ + +#ifdef CONFIG_LV_USE_ASSERT_MEM +#define LV_USE_ASSERT_MEM CONFIG_LV_USE_ASSERT_MEM +#else +#define LV_USE_ASSERT_MEM 0 +#endif + +/* Check the integrity of `lv_mem` after critical operations. (Slow) */ + +#define LV_USE_ASSERT_MEM_INTEGRITY 0 + +/* Check the strings. + * Search for NULL, very long strings, invalid characters, + * and unnatural repetitions. (Slow) + * If disabled `LV_USE_ASSERT_NULL` will be performed instead + * (if it's enabled) + */ +#ifdef CONFIG_LV_USE_ASSERT_STR +#define LV_USE_ASSERT_STR CONFIG_LV_USE_ASSERT_STR +#else +#define LV_USE_ASSERT_STR 0 +#endif + +/* Check NULL, the object's type and existence + * (e.g. not deleted). (Quite slow) + * If disabled `LV_USE_ASSERT_NULL` will be + * performed instead (if it's enabled) + */ + +#ifdef CONFIG_LV_USE_ASSERT_OBJ +#define LV_USE_ASSERT_OBJ CONFIG_LV_USE_ASSERT_OBJ +#else +#define LV_USE_ASSERT_OBJ 0 +#endif + +/* Check if the styles are properly initialized. (Fast) */ + +#ifdef CONFIG_LV_USE_ASSERT_STYLE +#define LV_USE_ASSERT_STYLE CONFIG_LV_USE_ASSERT_STYLE +#else +#define LV_USE_ASSERT_STYLE 0 +#endif + +/**************************************************************************** + * THEME USAGE + ****************************************************************************/ + +/* Always enable at least on theme */ + +/* No theme, you can apply your styles as you need + * No flags. Set LV_THEME_DEFAULT_FLAG 0 + */ + +#define LV_USE_THEME_EMPTY 1 + +/* Simple to the create your theme based on it + * No flags. Set LV_THEME_DEFAULT_FLAG 0 + */ + +#define LV_USE_THEME_TEMPLATE 1 + +/* A fast and impressive theme. + * Flags: + * LV_THEME_MATERIAL_FLAG_LIGHT: light theme + * LV_THEME_MATERIAL_FLAG_DARK: dark theme + */ + +#define LV_USE_THEME_MATERIAL 1 + +/* Mono-color theme for monochrome displays. + * If LV_THEME_DEFAULT_COLOR_PRIMARY is LV_COLOR_BLACK the + * texts and borders will be black and the background will be + * white. Else the colors are inverted. + * No flags. Set LV_THEME_DEFAULT_FLAG 0 + */ + +#define LV_USE_THEME_MONO 1 + +#define LV_THEME_DEFAULT_INCLUDE /* Include a header for the init. function */ +#define LV_THEME_DEFAULT_INIT lv_theme_material_init +#define LV_THEME_DEFAULT_COLOR_PRIMARY LV_COLOR_RED +#define LV_THEME_DEFAULT_COLOR_SECONDARY LV_COLOR_BLUE +#define LV_THEME_DEFAULT_FLAG LV_THEME_MATERIAL_FLAG_LIGHT +#define LV_THEME_DEFAULT_FONT_SMALL &lv_font_montserrat_16 +#define LV_THEME_DEFAULT_FONT_NORMAL &lv_font_montserrat_16 +#define LV_THEME_DEFAULT_FONT_SUBTITLE &lv_font_montserrat_16 +#define LV_THEME_DEFAULT_FONT_TITLE &lv_font_montserrat_16 + +/**************************************************************************** + * FONT USAGE + ****************************************************************************/ + +/* The built-in fonts contains the ASCII range and some Symbols + * with 4 bit-per-pixel. + * The symbols are available via `LV_SYMBOL_...` defines + * More info about fonts: https://docs.lvgl.io/v7/en/html/overview/font.html + * To create a new font go to: https://lvgl.com/ttf-font-to-c-array + */ + +/* Montserrat fonts with bpp = 4 + * https://fonts.google.com/specimen/Montserrat + */ + +/* They only take up storage space after being used, + * so we can enable them all by default + */ + +#define LV_FONT_MONTSERRAT_12 1 +#define LV_FONT_MONTSERRAT_14 1 +#define LV_FONT_MONTSERRAT_16 1 +#define LV_FONT_MONTSERRAT_18 1 +#define LV_FONT_MONTSERRAT_20 1 +#define LV_FONT_MONTSERRAT_22 1 +#define LV_FONT_MONTSERRAT_24 1 +#define LV_FONT_MONTSERRAT_26 1 +#define LV_FONT_MONTSERRAT_28 1 +#define LV_FONT_MONTSERRAT_30 1 +#define LV_FONT_MONTSERRAT_32 1 +#define LV_FONT_MONTSERRAT_34 1 +#define LV_FONT_MONTSERRAT_36 1 +#define LV_FONT_MONTSERRAT_38 1 +#define LV_FONT_MONTSERRAT_40 1 +#define LV_FONT_MONTSERRAT_42 1 +#define LV_FONT_MONTSERRAT_44 1 +#define LV_FONT_MONTSERRAT_46 1 +#define LV_FONT_MONTSERRAT_48 1 + +/* Demonstrate special features */ +#define LV_FONT_MONTSERRAT_12_SUBPX 0 +#define LV_FONT_MONTSERRAT_28_COMPRESSED 0 /* bpp = 3 */ +#define LV_FONT_DEJAVU_16_PERSIAN_HEBREW 0 /* Hebrew, Arabic, PErisan letters and all their forms */ +#define LV_FONT_SIMSUN_16_CJK 0 /* 1000 most common CJK radicals */ + +/* Pixel perfect monospace font + * http://pelulamu.net/unscii/ + */ + +#ifdef CONFIG_USE_LV_FONT_UNSCII_8 +#define LV_FONT_UNSCII_8 CONFIG_USE_LV_FONT_UNSCII_8 +#else +#define LV_FONT_UNSCII_8 0 +#endif + +/* Optionally declare your custom fonts here. + * You can use these fonts as default font too + * and they will be available globally. E.g. + * #define LV_FONT_CUSTOM_DECLARE LV_FONT_DECLARE(my_font_1) \ + * LV_FONT_DECLARE(my_font_2) + */ + +#define LV_FONT_CUSTOM_DECLARE + +/* Enable it if you have fonts with a lot of characters. + * The limit depends on the font size, font face and bpp + * but with > 10,000 characters if you see issues probably you need + * to enable it. + */ + +#define LV_FONT_FMT_TXT_LARGE 0 + +/* Set the pixel order of the display. + * Important only if "subpx fonts" are used. + * With "normal" font it doesn't matter. + */ + +#define LV_FONT_SUBPX_BGR 0 + +/* Declare the type of the user data of fonts + * (can be e.g. `void *`, `int`, `struct`) + */ + +typedef void * lv_font_user_data_t; + +/**************************************************************************** + * Text settings + ****************************************************************************/ + +/* Select a character encoding for strings. + * Your IDE or editor should have the same character encoding + * - LV_TXT_ENC_UTF8 + * - LV_TXT_ENC_ASCII + */ + +#define LV_TXT_ENC LV_TXT_ENC_UTF8 + +/* Can break (wrap) texts on these chars */ + +#define LV_TXT_BREAK_CHARS CONFIG_LV_TXT_BREAK_CHARS + +/* If a word is at least this long, will break wherever "prettiest" + * To disable, set to a value <= 0 + */ + +#define LV_TXT_LINE_BREAK_LONG_LEN 0 + +/* Minimum number of characters in a long word to put + * on a line before a break. + * Depends on LV_TXT_LINE_BREAK_LONG_LEN. + */ + +#define LV_TXT_LINE_BREAK_LONG_PRE_MIN_LEN 3 + +/* Minimum number of characters in a long word to put on a + * line after a break. + * Depends on LV_TXT_LINE_BREAK_LONG_LEN. + */ + +#define LV_TXT_LINE_BREAK_LONG_POST_MIN_LEN 3 + +/* The control character to use for signalling text recoloring. */ + +#define LV_TXT_COLOR_CMD "#" + +/* Support bidirectional texts. + * Allows mixing Left-to-Right and Right-to-Left texts. + * The direction will be processed according to the + * Unicode Bidirectioanl Algorithm: + * https://www.w3.org/International/articles/inline-bidi-markup/uba-basics + */ + +#define LV_USE_BIDI 0 +#if LV_USE_BIDI +/* Set the default direction. Supported values: + * `LV_BIDI_DIR_LTR` Left-to-Right + * `LV_BIDI_DIR_RTL` Right-to-Left + * `LV_BIDI_DIR_AUTO` detect texts base direction + */ + +#define LV_BIDI_BASE_DIR_DEF LV_BIDI_DIR_AUTO +#endif + +/* Enable Arabic/Persian processing + * In these languages characters should be replaced with + * an other form based on their position in the text + */ + +#define LV_USE_ARABIC_PERSIAN_CHARS 0 + +/* Change the built in (v)snprintf functions */ + +#define LV_SPRINTF_CUSTOM 1 +#if LV_SPRINTF_CUSTOM +# define LV_SPRINTF_INCLUDE +# define lv_snprintf snprintf +# define lv_vsnprintf vsnprintf +#endif /* LV_SPRINTF_CUSTOM */ + +/**************************************************************************** + * LV_OBJ SETTINGS + ****************************************************************************/ + +/* Declare the type of the user data of object + * (can be e.g. `void *`, `int`, `struct`) + */ + +typedef void * lv_obj_user_data_t; + +/* 1: enable `lv_obj_realaign()` based on `lv_obj_align()` parameters */ + +#ifdef CONFIG_LV_OBJ_REALIGN +#define LV_USE_OBJ_REALIGN CONFIG_LV_OBJ_REALIGN +#else +#define LV_USE_OBJ_REALIGN 0 +#endif + +/* Enable to make the object clickable on a larger area. + * LV_EXT_CLICK_AREA_OFF or 0: Disable this feature + * LV_EXT_CLICK_AREA_TINY: The extra area can be adjusted + * horizontally and vertically (0..255 px) + * LV_EXT_CLICK_AREA_FULL: The extra area can be adjusted + * in all 4 directions (-32k..+32k px) + */ + +#define LV_USE_EXT_CLICK_AREA LV_EXT_CLICK_AREA_TINY + +/**************************************************************************** + * LV OBJ X USAGE + ****************************************************************************/ + +/* Documentation of the object types: + * https://docs.littlevgl.com/#Object-types + */ + +/* Arc (dependencies: -) */ + +#ifdef CONFIG_USE_LV_ARC +#define LV_USE_ARC CONFIG_USE_LV_ARC +#else +#define LV_USE_ARC 0 +#endif + +/* Bar (dependencies: -) */ + +#ifdef CONFIG_USE_LV_BAR +#define LV_USE_BAR CONFIG_USE_LV_BAR +#else +#define LV_USE_BAR 0 +#endif + +/* Button (dependencies: lv_cont) */ + +#ifdef CONFIG_USE_LV_BTN +#define LV_USE_BTN CONFIG_USE_LV_BTN +#else +#define LV_USE_BTN 0 +#endif + +#if LV_USE_BTN != 0 + +/* Enable button-state animations - draw a + * circle on click (dependencies: LV_USE_ANIMATION) + */ + +#ifdef CONFIG_LV_BTN_INK_EFFECT +#define LV_BTN_INK_EFFECT CONFIG_LV_BTN_INK_EFFECT +#else +#define LV_BTN_INK_EFFECT 0 +#endif + +#endif + +/* Button matrix (dependencies: -) */ + +#ifdef CONFIG_USE_LV_BTNM +#define LV_USE_BTNM CONFIG_USE_LV_BTNM +#else +#define LV_USE_BTNM 0 +#endif + +/* Calendar (dependencies: -) */ + +#ifdef CONFIG_USE_LV_CALENDAR +#define LV_USE_CALENDAR CONFIG_USE_LV_CALENDAR +#else +#define LV_USE_CALENDAR 0 +#endif + +/* Canvas (dependencies: lv_img) */ + +#ifdef CONFIG_USE_LV_CANVAS +#define LV_USE_CANVAS CONFIG_USE_LV_CANVAS +#else +#define LV_USE_CANVAS 0 +#endif + +/* Check box (dependencies: lv_btn, lv_label) */ + +#ifdef CONFIG_USE_LV_CB +#define LV_USE_CB CONFIG_USE_LV_CB +#else +#define LV_USE_CB 0 +#endif + +/* Chart (dependencies: -) */ + +#ifdef CONFIG_USE_LV_CHART +#define LV_USE_CHART CONFIG_USE_LV_CHART +#else +#define LV_USE_CHART 0 +#endif + +#if LV_USE_CHART +# define LV_CHART_AXIS_TICK_LABEL_MAX_LEN CONFIG_LV_CHART_AXIS_TICK_LABEL_MAX_LEN +#endif + +/* Container (dependencies: -) */ + +#define LV_USE_CONT 1 + +/* Color picker (dependencies: -) */ + +#define LV_USE_CPICKER 1 + +/* Drop down list (dependencies: lv_page, lv_label, lv_symbol_def.h) */ + +#define LV_USE_DDLIST 1 +#if LV_USE_DDLIST != 0 +/* Open and close default animation time [ms] (0: no animation) */ + +# define LV_DDLIST_DEF_ANIM_TIME 200 +#endif + +/* Gauge (dependencies:lv_bar, lv_lmeter) */ + +#define LV_USE_GAUGE 1 + +/* Image (dependencies: lv_label) */ + +#define LV_USE_IMG 1 + +/* Image Button (dependencies: lv_btn) */ + +#define LV_USE_IMGBTN 1 +#if LV_USE_IMGBTN +/* 1: The imgbtn requires left, mid and right + * parts and the width can be set freely + */ + +# define LV_IMGBTN_TILED 0 +#endif + +/* Keyboard (dependencies: lv_btnm) */ + +#define LV_USE_KB 1 + +/* Label (dependencies: -) */ + +#define LV_USE_LABEL 1 +#if LV_USE_LABEL != 0 +/* Hor, or ver. scroll speed [px/sec] in + * 'LV_LABEL_LONG_ROLL/ROLL_CIRC' mode + */ + +# define LV_LABEL_DEF_SCROLL_SPEED 25 + +/* Waiting period at beginning/end of animation cycle */ + +# define LV_LABEL_WAIT_CHAR_COUNT 3 + +/* Enable selecting text of the label */ + +# define LV_LABEL_TEXT_SEL 0 + +/* Store extra some info in labels (12 bytes) + * to speed up drawing of very long texts + */ + +# define LV_LABEL_LONG_TXT_HINT 0 +#endif + +/* LED (dependencies: -) */ + +#define LV_USE_LED 1 + +/* Line (dependencies: -) */ + +#define LV_USE_LINE 1 + +/* List (dependencies: lv_page, lv_btn, lv_label, + * (lv_img optionally for icons)) + */ + +#define LV_USE_LIST 1 +#if LV_USE_LIST != 0 +/* Default animation time of focusing to a + * list element [ms] (0: no animation) + */ + +# define LV_LIST_DEF_ANIM_TIME 100 +#endif + +/* Line meter (dependencies: *) */ + +#define LV_USE_LMETER 1 + +/* Message box (dependencies: lv_rect, lv_btnm, lv_label) */ + +#define LV_USE_MBOX 1 + +/* Page (dependencies: lv_cont) */ + +#define LV_USE_PAGE 1 +#if LV_USE_PAGE != 0 +/* Focus default animation time [ms] (0: no animation) */ + +# define LV_PAGE_DEF_ANIM_TIME 400 +#endif + +/* Preload (dependencies: lv_arc, lv_anim) */ + +#define LV_USE_PRELOAD 1 +#if LV_USE_PRELOAD != 0 +# define LV_PRELOAD_DEF_ARC_LENGTH 60 /* [deg] */ +# define LV_PRELOAD_DEF_SPIN_TIME 1000 /* [ms] */ +# define LV_PRELOAD_DEF_ANIM LV_PRELOAD_TYPE_SPINNING_ARC +#endif + +/* Roller (dependencies: lv_ddlist) */ + +#define LV_USE_ROLLER 1 +#if LV_USE_ROLLER != 0 +/* Focus animation time [ms] (0: no animation) */ + +# define LV_ROLLER_DEF_ANIM_TIME 200 + +/* Number of extra "pages" when the roller is infinite */ + +# define LV_ROLLER_INF_PAGES 7 +#endif + +/* Slider (dependencies: lv_bar) */ + +#define LV_USE_SLIDER 1 + +/* Spinbox (dependencies: lv_ta) */ + +#define LV_USE_SPINBOX 1 + +/* Switch (dependencies: lv_slider) */ + +#define LV_USE_SW 1 + +/* Text area (dependencies: lv_label, lv_page) */ + +#define LV_USE_TA 1 +#if LV_USE_TA != 0 +# define LV_TA_DEF_CURSOR_BLINK_TIME 400 /* ms */ +# define LV_TA_DEF_PWD_SHOW_TIME 1500 /* ms */ +#endif + +/* Table (dependencies: lv_label) */ + +#define LV_USE_TABLE 1 +#if LV_USE_TABLE +# define LV_TABLE_COL_MAX 12 +#endif + +/* Tab (dependencies: lv_page, lv_btnm) */ + +#define LV_USE_TABVIEW 1 +# if LV_USE_TABVIEW != 0 +/* Time of slide animation [ms] (0: no animation) */ + +# define LV_TABVIEW_DEF_ANIM_TIME 300 +#endif + +/* Tileview (dependencies: lv_page) */ + +#define LV_USE_TILEVIEW 1 +#if LV_USE_TILEVIEW +/* Time of slide animation [ms] (0: no animation) */ + +# define LV_TILEVIEW_DEF_ANIM_TIME 300 +#endif + +/* Window (dependencies: lv_cont, lv_btn, lv_label, lv_img, lv_page) */ + +#define LV_USE_WIN 1 + +/**************************************************************************** + * Non-user section + ****************************************************************************/ + +#if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS) /* Disable warnings for Visual Studio*/ +# define _CRT_SECURE_NO_WARNINGS +#endif + +#endif /* __APPS_GRAPHICS_LVGL_LV_CONF_H */ diff --git a/graphics/lvgl/lv_fs_interface.c b/graphics/lvgl/lv_fs_interface.c new file mode 100644 index 000000000..b75c2bf0d --- /dev/null +++ b/graphics/lvgl/lv_fs_interface.c @@ -0,0 +1,575 @@ +/**************************************************************************** + * apps/graphics/lvgl/lv_fs_interface.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include "lv_fs_interface.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define LV_FS_LETTER '/' + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +/* Create a type to store the required data about your file. */ + +typedef int file_t; + +/* Similarly to `file_t` create a type for directory reading too */ + +typedef DIR *dir_t; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +static lv_fs_res_t fs_open(lv_fs_drv_t *drv, void *file_p, + const char *path, lv_fs_mode_t mode); +static lv_fs_res_t fs_close(lv_fs_drv_t *drv, void *file_p); +static lv_fs_res_t fs_read(lv_fs_drv_t *drv, void *file_p, + void *buf, uint32_t btr, uint32_t *br); +static lv_fs_res_t fs_write(lv_fs_drv_t *drv, void *file_p, + const void *buf, uint32_t btw, uint32_t *bw); +static lv_fs_res_t fs_seek(lv_fs_drv_t *drv, void *file_p, + uint32_t pos); +static lv_fs_res_t fs_size(lv_fs_drv_t *drv, void *file_p, + uint32_t *size_p); +static lv_fs_res_t fs_tell(lv_fs_drv_t *drv, void *file_p, + uint32_t *pos_p); +static lv_fs_res_t fs_remove(lv_fs_drv_t *drv, const char *path); +static lv_fs_res_t fs_trunc(lv_fs_drv_t *drv, void *file_p); +static lv_fs_res_t fs_rename(lv_fs_drv_t *drv, const char *oldname, + const char *newname); +static lv_fs_res_t fs_free(lv_fs_drv_t *drv, uint32_t *total_p, + uint32_t *free_p); +static lv_fs_res_t fs_dir_open(lv_fs_drv_t *drv, void *dir_p, + const char *path); +static lv_fs_res_t fs_dir_read(lv_fs_drv_t *drv, void *dir_p, char *fn); +static lv_fs_res_t fs_dir_close(lv_fs_drv_t *drv, void *dir_p); + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: fs_open + * + * Description: + * Open a file. + * + * Input Parameters: + * drv - pointer to a driver where this function belongs. + * file_p - pointer to a file_t variable. + * path - path to the file beginning with the driver letter. + * (e.g. /folder/file.txt) + * mode - read: FS_MODE_RD, write: FS_MODE_WR, + * both: FS_MODE_RD | FS_MODE_WR + * + * Returned Value: + * LV_FS_RES_OK or any error from lv_fs_res_t enum. + * + ****************************************************************************/ + +static lv_fs_res_t fs_open(lv_fs_drv_t *drv, void *file_p, + const char *path, lv_fs_mode_t mode) +{ + uint32_t flags = 0; + if (mode == LV_FS_MODE_WR) + { + flags = O_WRONLY | O_CREAT; + } + else if (mode == LV_FS_MODE_RD) + { + flags = O_RDONLY; + } + else if (mode == (LV_FS_MODE_WR | LV_FS_MODE_RD)) + { + flags = O_RDWR | O_CREAT; + } + else + { + return LV_FS_RES_UNKNOWN; + } + + file_t f = open(--path, flags); + if (f < 0) + { + return LV_FS_RES_FS_ERR; + } + + /* 'file_p' is pointer to a file descriptor and + * we need to store our file descriptor here + */ + + file_t *fp = file_p; /* Just avoid the confusing casings */ + *fp = f; + + return LV_FS_RES_OK; +} + +/**************************************************************************** + * Name: fs_close + * + * Description: + * Close an opened file. + * + * Input Parameters: + * drv - pointer to a driver where this function belongs. + * file_p - pointer to a file_t variable. + * + * Returned Value: + * LV_FS_RES_OK: no error, the file is read + * any error from lv_fs_res_t enum. + * + ****************************************************************************/ + +static lv_fs_res_t fs_close(lv_fs_drv_t *drv, void *file_p) +{ + /* Just avoid the confusing casings */ + + file_t *fp = file_p; + + return close(*fp) < 0 ? LV_FS_RES_FS_ERR : LV_FS_RES_OK; +} + +/**************************************************************************** + * Name: fs_read + * + * Description: + * Read data from an opened file. + * + * Input Parameters: + * drv - pointer to a driver where this function belongs. + * file_p - pointer to a file_t variable. + * buf - pointer to a memory block where to store the read data. + * btr - number of Bytes To Read. + * br - the real number of read bytes (Byte Read). + * + * Returned Value: + * LV_FS_RES_OK: no error, the file is read + * any error from lv_fs_res_t enum. + * + ****************************************************************************/ + +static lv_fs_res_t fs_read(lv_fs_drv_t *drv, void *file_p, + void *buf, uint32_t btr, uint32_t *br) +{ + /* Just avoid the confusing casings */ + + file_t *fp = file_p; + + *br = read(*fp, buf, btr); + + return (int32_t)*br < 0 ? LV_FS_RES_FS_ERR : LV_FS_RES_OK; +} + +/**************************************************************************** + * Name: fs_write + * + * Description: + * Write into a file. + * + * Input Parameters: + * drv - pointer to a driver where this function belongs. + * file_p - pointer to a file_t variable. + * buf - pointer to a buffer with the bytes to write. + * btw - Bytes To Write. + * bw - the number of real written bytes (Bytes Written). + * NULL if unused. + * + * Returned Value: + * LV_FS_RES_OK or any error from lv_fs_res_t enum. + * + ****************************************************************************/ + +static lv_fs_res_t fs_write(lv_fs_drv_t *drv, void *file_p, + const void *buf, uint32_t btw, uint32_t *bw) +{ + /* Just avoid the confusing casings */ + + file_t *fp = file_p; + + *bw = write(*fp, buf, btw); + + return (int32_t)*bw < 0 ? LV_FS_RES_FS_ERR : LV_FS_RES_OK; +} + +/**************************************************************************** + * Name: fs_seek + * + * Description: + * Set the read write pointer. Also expand the file size if necessary. + * + * Input Parameters: + * drv - pointer to a driver where this function belongs. + * file_p - pointer to a file_t variable. + * pos - the new position of read write pointer. + * + * Returned Value: + * LV_FS_RES_OK: no error, the file is read + * any error from lv_fs_res_t enum. + * + ****************************************************************************/ + +static lv_fs_res_t fs_seek(lv_fs_drv_t *drv, void *file_p, uint32_t pos) +{ + /* Just avoid the confusing casings */ + + file_t *fp = file_p; + + off_t offset = lseek(*fp, pos, SEEK_SET); + + return offset < 0 ? LV_FS_RES_FS_ERR : LV_FS_RES_OK; +} + +/**************************************************************************** + * Name: fs_size + * + * Description: + * Give the size of a file bytes. + * + * Input Parameters: + * drv - pointer to a driver where this function belongs. + * file_p - pointer to a file_t variable. + * size - pointer to a variable to store the size. + * + * Returned Value: + * LV_FS_RES_OK or any error from lv_fs_res_t enum. + * + ****************************************************************************/ + +static lv_fs_res_t fs_size(lv_fs_drv_t *drv, void *file_p, + uint32_t *size_p) +{ + /* Just avoid the confusing casings */ + + file_t *fp = file_p; + + off_t cur = lseek(*fp, 0, SEEK_CUR); + + *size_p = lseek(*fp, 0L, SEEK_END); + + /* Restore file pointer */ + + lseek(*fp, cur, SEEK_SET); + + return (int32_t)*size_p < 0 ? LV_FS_RES_FS_ERR : LV_FS_RES_OK; +} + +/**************************************************************************** + * Name: fs_tell + * + * Description: + * Give the position of the read write pointer. + * + * Input Parameters: + * drv - pointer to a driver where this function belongs. + * file_p - pointer to a file_t variable. + * pos_p - pointer to to store the result. + * + * Returned Value: + * LV_FS_RES_OK: no error, the file is read + * any error from lv_fs_res_t enum. + * + ****************************************************************************/ + +static lv_fs_res_t fs_tell(lv_fs_drv_t *drv, void *file_p, + uint32_t *pos_p) +{ + /* Just avoid the confusing casings */ + + file_t *fp = file_p; + + *pos_p = lseek(*fp, 0, SEEK_CUR); + + return (int32_t)*pos_p < 0 ? LV_FS_RES_FS_ERR : LV_FS_RES_OK; +} + +/**************************************************************************** + * Name: fs_remove + * + * Description: + * Delete a file. + * + * Input Parameters: + * drv - pointer to a driver where this function belongs. + * path - path of the file to delete. + * + * Returned Value: + * LV_FS_RES_OK or any error from lv_fs_res_t enum. + * + ****************************************************************************/ + +static lv_fs_res_t fs_remove(lv_fs_drv_t *drv, const char *path) +{ + return remove(--path) < 0 ? LV_FS_RES_FS_ERR : LV_FS_RES_OK; +} + +/**************************************************************************** + * Name: fs_trunc + * + * Description: + * Truncate the file size to the current position of + * the read write pointer. + * + * Input Parameters: + * drv - pointer to a driver where this function belongs. + * file_p - pointer to a file_t variable. + * + * Returned Value: + * LV_FS_RES_OK or any error from lv_fs_res_t enum. + * + ****************************************************************************/ + +static lv_fs_res_t fs_trunc(lv_fs_drv_t *drv, void *file_p) +{ + /* Just avoid the confusing casings */ + + file_t *fp = file_p; + + off_t p = lseek(*fp, 0, SEEK_CUR); + + return ftruncate(*fp, p) < 0 ? LV_FS_RES_FS_ERR : LV_FS_RES_OK; +} + +/**************************************************************************** + * Name: fs_rename + * + * Description: + * Rename a file. + * + * Input Parameters: + * drv - pointer to a driver where this function belongs. + * oldname - path to the file. + * newname - path with the new name + * + * Returned Value: + * LV_FS_RES_OK or any error from lv_fs_res_t enum. + * + ****************************************************************************/ + +static lv_fs_res_t fs_rename(lv_fs_drv_t *drv, const char *oldname, + const char *newname) +{ + return rename(--oldname, --newname) < 0 ? LV_FS_RES_FS_ERR : LV_FS_RES_OK; +} + +/**************************************************************************** + * Name: fs_free + * + * Description: + * Get the free and total size of a driver in kB. + * + * Input Parameters: + * drv - pointer to a driver where this function belongs. + * total_p - pointer to store the total size [kB]. + * free_p - pointer to store the free size [kB] + * + * Returned Value: + * LV_FS_RES_OK or any error from lv_fs_res_t enum. + * + ****************************************************************************/ + +static lv_fs_res_t fs_free(lv_fs_drv_t *drv, uint32_t *total_p, + uint32_t *free_p) +{ + struct statfs sfs; + + if (statfs(CONFIG_LV_FILESYSTEM_MOUNTPOINT, &sfs) < 0) + { + return LV_FS_RES_FS_ERR; + } + else + { + *total_p = sfs.f_blocks * sfs.f_bsize / 1024; + *free_p = sfs.f_bfree * sfs.f_bsize / 1024; + return LV_FS_RES_OK; + } +} + +/**************************************************************************** + * Name: fs_dir_open + * + * Description: + * Initialize a 'fs_read_dir_t' variable for directory reading. + * + * Input Parameters: + * drv - pointer to a driver where this function belongs. + * dir_p - pointer to a 'fs_read_dir_t' variable. + * path - path to a directory. + * + * Returned Value: + * LV_FS_RES_OK or any error from lv_fs_res_t enum. + * + ****************************************************************************/ + +static lv_fs_res_t fs_dir_open(lv_fs_drv_t *drv, void *dir_p, + const char *path) +{ + dir_t d; + + /* Make the path relative to the current directory + * (the projects root folder) + */ + + if ((d = opendir(--path)) == NULL) + { + return LV_FS_RES_FS_ERR; + } + else + { + /* 'dir_p' is pointer to a file descriptor and + * we need to store our file descriptor here + */ + + /* Just avoid the confusing casings */ + + dir_t *dp = dir_p; + *dp = d; + } + + return LV_FS_RES_OK; +} + +/**************************************************************************** + * Name: fs_dir_read + * + * Description: + * Read the next filename form a directory. + * The name of the directories will begin with '/'. + * + * Input Parameters: + * drv - pointer to a driver where this function belongs. + * dir_p - pointer to an initialized 'fs_read_dir_t' variable. + * fn - pointer to a buffer to store the filename. + * + * Returned Value: + * LV_FS_RES_OK or any error from lv_fs_res_t enum. + * + ****************************************************************************/ + +static lv_fs_res_t fs_dir_read(lv_fs_drv_t *drv, void *dir_p, char *fn) +{ + /* Just avoid the confusing casings */ + + dir_t *dp = dir_p; + + do + { + struct dirent *entry = readdir(*dp); + + if (entry) + { + if (entry->d_type == DT_DIR) + { + sprintf(fn, "/%s", entry->d_name); + } + else + { + strcpy(fn, entry->d_name); + } + } + else + { + strcpy(fn, ""); + } + } + while (strcmp(fn, "/.") == 0 || strcmp(fn, "/..") == 0); + + return LV_FS_RES_OK; +} + +/**************************************************************************** + * Name: fs_dir_read + * + * Description: + * Close the directory reading. + * + * Input Parameters: + * drv - pointer to a driver where this function belongs. + * dir_p - pointer to an initialized 'fs_read_dir_t' variable. + * + * Returned Value: + * LV_FS_RES_OK or any error from lv_fs_res_t enum. + * + ****************************************************************************/ + +static lv_fs_res_t fs_dir_close(lv_fs_drv_t *drv, void *dir_p) +{ + dir_t *dp = dir_p; + + return closedir(*dp) < 0 ? LV_FS_RES_FS_ERR : LV_FS_RES_OK; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: lv_fs_interface_init + * + * Description: + * Register a driver for the File system interface. + * + ****************************************************************************/ + +void lv_fs_interface_init(void) +{ + /* Add a simple drive to open images */ + + lv_fs_drv_t fs_drv; /* A driver descriptor */ + + lv_fs_drv_init(&fs_drv); + + /* Set up fields... */ + + fs_drv.file_size = sizeof(file_t); + fs_drv.letter = LV_FS_LETTER; + fs_drv.open_cb = fs_open; + fs_drv.close_cb = fs_close; + fs_drv.read_cb = fs_read; + fs_drv.write_cb = fs_write; + fs_drv.seek_cb = fs_seek; + fs_drv.tell_cb = fs_tell; + fs_drv.free_space_cb = fs_free; + fs_drv.size_cb = fs_size; + fs_drv.remove_cb = fs_remove; + fs_drv.rename_cb = fs_rename; + fs_drv.trunc_cb = fs_trunc; + + fs_drv.rddir_size = sizeof(dir_t); + fs_drv.dir_close_cb = fs_dir_close; + fs_drv.dir_open_cb = fs_dir_open; + fs_drv.dir_read_cb = fs_dir_read; + + lv_fs_drv_register(&fs_drv); +} diff --git a/system/settings/storage.h b/graphics/lvgl/lv_fs_interface.h similarity index 80% rename from system/settings/storage.h rename to graphics/lvgl/lv_fs_interface.h index 1190d2939..a02558ef7 100644 --- a/system/settings/storage.h +++ b/graphics/lvgl/lv_fs_interface.h @@ -1,7 +1,5 @@ /**************************************************************************** - * apps/system/settings/storage.h - * - * SPDX-License-Identifier: Apache-2.0 + * apps/graphics/lvgl/lv_fs_interface.h * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -20,46 +18,49 @@ * ****************************************************************************/ -#ifndef SETTINGS_STORAGE_H_ -#define SETTINGS_STORAGE_H_ +#ifndef __APPS_GRAPHICS_LVGL_LV_FS_INTERFACE_H +#define __APPS_GRAPHICS_LVGL_LV_FS_INTERFACE_H /**************************************************************************** * Included Files ****************************************************************************/ #include -#include "system/settings.h" +#include /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ +#if LV_USE_FILESYSTEM + /**************************************************************************** - * Public Types + * Type Definitions ****************************************************************************/ /**************************************************************************** * Public Data ****************************************************************************/ +#ifdef __cplusplus +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + /**************************************************************************** * Public Function Prototypes ****************************************************************************/ -/* Text storage. */ +void lv_fs_interface_init(void); -int load_text(FAR char *file); -int save_text(FAR char *file); +#undef EXTERN +#ifdef __cplusplus +} +#endif -/* Binary storage. */ - -int load_bin(FAR char *file); -int save_bin(FAR char *file); - -/* EEPROM storage. */ - -int load_eeprom(FAR char *file); -int save_eeprom(FAR char *file); - -#endif /* SETTINGS_STORAGE_H_*/ +#endif /* LV_USE_FILESYSTEM */ +#endif /* __APPS_GRAPHICS_LVGL_LV_FS_INTERFACE_H */ diff --git a/examples/lua_module/luamod_hello.c b/graphics/lvgl/lv_tick_interface.c similarity index 79% rename from examples/lua_module/luamod_hello.c rename to graphics/lvgl/lv_tick_interface.c index 22f13c2fb..d0757d4db 100644 --- a/examples/lua_module/luamod_hello.c +++ b/graphics/lvgl/lv_tick_interface.c @@ -1,7 +1,5 @@ /**************************************************************************** - * apps/examples/lua_module/luamod_hello.c - * - * SPDX-License-Identifier: Apache-2.0 + * apps/graphics/lvgl/lv_tick_interface.c * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -24,55 +22,52 @@ * Included Files ****************************************************************************/ -#include -#include +#include +#include +#include "lv_tick_interface.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ /**************************************************************************** * Private Function Prototypes ****************************************************************************/ -static int say_hello(lua_State *L); - /**************************************************************************** * Private Data ****************************************************************************/ -static const struct luaL_Reg g_hello[] = -{ - {"say_hello", say_hello}, - {NULL, NULL}, -}; - /**************************************************************************** * Private Functions ****************************************************************************/ -/**************************************************************************** - * Name: say_hello - * - * Push a "Hello World!" string to the Lua interpreter. - * - ****************************************************************************/ - -static int say_hello(lua_State *L) -{ - lua_pushstring(L, "Hello World!"); - return 1; -} - /**************************************************************************** * Public Functions ****************************************************************************/ -/**************************************************************************** - * Name: luaopen_hello - * - * Open the "hello" Lua module. - * - ****************************************************************************/ - -int luaopen_hello(lua_State *L) +uint32_t lv_tick_interface(void) { - luaL_newlib(L, g_hello); - return 1; + static bool first_time = true; + static struct timeval t0; + + if (first_time) + { + gettimeofday(&t0, NULL); + first_time = false; + return 0; + } + else + { + struct timeval t; + struct timeval delta; + + gettimeofday(&t, NULL); + timersub(&t, &t0, &delta); + return delta.tv_sec * 1000 + delta.tv_usec / 1000; + } } diff --git a/include/netutils/mdnsd.h b/graphics/lvgl/lv_tick_interface.h similarity index 80% rename from include/netutils/mdnsd.h rename to graphics/lvgl/lv_tick_interface.h index 1900fb9db..2a9546553 100644 --- a/include/netutils/mdnsd.h +++ b/graphics/lvgl/lv_tick_interface.h @@ -1,7 +1,5 @@ /**************************************************************************** - * apps/netutils/mdnsd.h - * - * SPDX-License-Identifier: Apache-2.0 + * apps/graphics/lvgl/lv_tick_interface.h * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -20,23 +18,26 @@ * ****************************************************************************/ -#ifndef __APPS_INCLUDE_NETUTILS_MDNSD_H -#define __APPS_INCLUDE_NETUTILS_MDNSD_H +#ifndef __APPS_GRAPHICS_LV_TICK_INTERFACE_H +#define __APPS_GRAPHICS_LV_TICK_INTERFACE_H /**************************************************************************** * Included Files ****************************************************************************/ +#include +#include + /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ /**************************************************************************** - * Public Types + * Type Definitions ****************************************************************************/ /**************************************************************************** - * Public Function Prototypes + * Public Data ****************************************************************************/ #ifdef __cplusplus @@ -47,12 +48,15 @@ extern "C" #define EXTERN extern #endif -int mdnsd_start(FAR char *service_name, FAR char *service_port); -int mdnsd_stop(void); +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +uint32_t lv_tick_interface(void); #undef EXTERN #ifdef __cplusplus } #endif -#endif /* __APPS_INCLUDE_NETUTILS_MDNSD_H */ +#endif // __APPS_GRAPHICS_LV_TICK_INTERFACE_H diff --git a/graphics/microwindows/.gitignore b/graphics/microwindows/.gitignore deleted file mode 100644 index 0cb9c8404..000000000 --- a/graphics/microwindows/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/microwindows -/*.zip diff --git a/graphics/microwindows/Kconfig b/graphics/microwindows/Kconfig deleted file mode 100644 index 8463d791f..000000000 --- a/graphics/microwindows/Kconfig +++ /dev/null @@ -1,131 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -menuconfig GRAPHICS_MICROWINDOWS - bool "Microwindows or the Nano-X Window System" - default n - depends on VIDEO_FB - ---help--- - Enable Microwindows or the Nano-X Window System - -if GRAPHICS_MICROWINDOWS - -config MICROWINDOWS_FB_PATH - string "Framebuffer device path" - default "/dev/fb0" - ---help--- - Path to the NuttX framebuffer device. - -choice - prompt "Keyboard driver" - default MICROWINDOWS_KBD_EVENT - ---help--- - Select the keyboard input driver for Microwindows. - -config MICROWINDOWS_KBD_EVENT - bool "Event-mode keyboard driver" - ---help--- - Reads keyboard_event_s events from a NuttX keyboard device - (e.g., /dev/kbd). Supports key press/release tracking and - modifier keys (Shift, Ctrl, Alt). - -config MICROWINDOWS_KBD_RAW - bool "Raw-mode keyboard driver" - depends on LIBC_KBDCODEC - ---help--- - Reads raw byte stream from a character device (e.g., /dev/kbda) - and decodes escape sequences via the kbd_codec library. Suitable - for USB HID keyboards on QEMU. - -config MICROWINDOWS_KBD_NONE - bool "No keyboard driver" - ---help--- - No keyboard driver is compiled. Microwindows will use a null - keyboard driver that never produces input. Suitable for - display-only applications. - -config MICROWINDOWS_KBD_CUSTOM - bool "Custom keyboard driver" - ---help--- - No built-in keyboard driver is compiled. The application or BSP - must provide its own kbddev symbol and KBDDEVICE implementation, - and add the source file to the build (e.g., via CSRCS in its - Makefile). See the Microwindows documentation for details. - -endchoice - -config MICROWINDOWS_KBD_EVENT_PATH - string "Event keyboard device path" - default "/dev/kbd" - depends on MICROWINDOWS_KBD_EVENT - ---help--- - Device path for the event-mode keyboard driver. - -config MICROWINDOWS_KBD_RAW_PATH - string "Raw keyboard device path" - default "/dev/kbda" - depends on MICROWINDOWS_KBD_RAW - ---help--- - Device path for the raw-mode keyboard driver. - -choice - prompt "Mouse/touchscreen driver" - default MICROWINDOWS_MOUSE_RELATIVE - ---help--- - Select the pointing device driver for Microwindows. - -config MICROWINDOWS_MOUSE_RELATIVE - bool "Relative mouse driver" - ---help--- - Reads mouse_report_s events from a NuttX mouse device - (e.g., /dev/mouse0). Supports three buttons and scroll wheel. - -config MICROWINDOWS_MOUSE_TS - bool "Touchscreen driver" - ---help--- - Reads touch_sample_s events from a NuttX touchscreen device - (e.g., /dev/input0). Supports absolute positioning. - -config MICROWINDOWS_MOUSE_NONE - bool "No mouse/touchscreen driver" - ---help--- - No pointing device driver is compiled. Microwindows will use a - null mouse driver that never produces input and hides the cursor. - Suitable for display-only applications. - -config MICROWINDOWS_MOUSE_CUSTOM - bool "Custom mouse/touchscreen driver" - ---help--- - No built-in pointing device driver is compiled. The application - or BSP must provide its own mousedev symbol and MOUSEDEVICE - implementation, and add the source file to the build (e.g., via - CSRCS in its Makefile). See the Microwindows documentation for - details. - -endchoice - -config MICROWINDOWS_MOUSE_PATH - string "Mouse device path" - default "/dev/mouse0" - depends on MICROWINDOWS_MOUSE_RELATIVE - ---help--- - Device path for the relative mouse driver. - -config MICROWINDOWS_TS_PATH - string "Touchscreen device path" - default "/dev/input0" - depends on MICROWINDOWS_MOUSE_TS - ---help--- - Device path for the touchscreen driver. - -config MICROWINDOWS_MWIN - bool "Win32 API (mwin) support" - default n - ---help--- - Build the Microwindows Win32 (mwin) API library. This provides - a high-level windowing API similar to the Microsoft Windows API - with window management, controls, and standard dialogs. - -endif # GRAPHICS_MICROWINDOWS diff --git a/graphics/microwindows/Make.defs b/graphics/microwindows/Make.defs deleted file mode 100644 index 935abf66b..000000000 --- a/graphics/microwindows/Make.defs +++ /dev/null @@ -1,33 +0,0 @@ -############################################################################ -# apps/graphics/microwindows/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_GRAPHICS_MICROWINDOWS),) -CONFIGURED_APPS += $(APPDIR)/graphics/microwindows - -# It allows `microwindows/src/include` import. - -CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/graphics/microwindows/microwindows/src/include -CXXFLAGS += ${INCDIR_PREFIX}$(APPDIR)/graphics/microwindows/microwindows/src/include - -CFLAGS += -DMWCONFIG_FILE='"mwconfig.nuttx"' - -endif diff --git a/graphics/microwindows/Makefile b/graphics/microwindows/Makefile deleted file mode 100644 index 2ea7e4c1a..000000000 --- a/graphics/microwindows/Makefile +++ /dev/null @@ -1,156 +0,0 @@ -############################################################################ -# apps/graphics/microwindows/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -# Microwindows graphic library - -MICROWINDOWS_DIR = . -MICROWINDOWS_DIR_NAME = microwindows - -# Set up build configuration and environment - -WD := ${shell echo $(CURDIR) | sed -e 's/ /\\ /g'} - -MICROWINDOWS_COMMIT_HASH := 1f269127b991d01dea5784eacee321a23e34d3d5 - -CONFIG_GRAPH_MICROWINDOWS_URL ?= https://codeload.github.com/ghaerr/microwindows/zip/$(MICROWINDOWS_COMMIT_HASH) - -MICROWINDOWS_TARBALL := microwindows-$(MICROWINDOWS_COMMIT_HASH).zip - -MICROWINDOWS_UNPACKNAME = microwindows -UNPACK ?= unzip -o $(if $(V),,-q) -CURL ?= curl -L $(if $(V),,-Ss) - -MICROWINDOWS_UNPACKDIR = $(WD)/$(MICROWINDOWS_UNPACKNAME) - -$(MICROWINDOWS_TARBALL): - $(ECHO_BEGIN)"Downloading: $(MICROWINDOWS_TARBALL)" - $(Q) $(CURL) -o $(MICROWINDOWS_TARBALL) $(CONFIG_GRAPH_MICROWINDOWS_URL) - $(ECHO_END) - -$(MICROWINDOWS_UNPACKNAME): $(MICROWINDOWS_TARBALL) - $(ECHO_BEGIN)"Unpacking: $(MICROWINDOWS_TARBALL) -> $(MICROWINDOWS_UNPACKNAME)" - $(Q) $(UNPACK) $(MICROWINDOWS_TARBALL) - $(Q) mv microwindows-$(MICROWINDOWS_COMMIT_HASH) $(MICROWINDOWS_UNPACKNAME) - $(Q) touch $(MICROWINDOWS_UNPACKNAME) - $(ECHO_END) - -# Download and unpack tarball if no git repo found -ifeq ($(wildcard $(MICROWINDOWS_UNPACKNAME)/.git),) -context:: $(MICROWINDOWS_UNPACKNAME) - -distclean:: - $(call DELDIR, $(MICROWINDOWS_UNPACKNAME)) - $(call DELFILE, $(MICROWINDOWS_TARBALL)) -endif - -CFLAGS += -Wno-undef -CFLAGS += -Wno-shadow - -CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/graphics/microwindows/microwindows/src/drivers - -CFLAGS += -DNUTTX_FB_PATH=\"$(CONFIG_MICROWINDOWS_FB_PATH)\" -ifdef CONFIG_MICROWINDOWS_KBD_EVENT_PATH -CFLAGS += -DNUTTX_KBD_EVENT_PATH=\"$(CONFIG_MICROWINDOWS_KBD_EVENT_PATH)\" -endif -ifdef CONFIG_MICROWINDOWS_KBD_RAW_PATH -CFLAGS += -DNUTTX_KBD_RAW_PATH=\"$(CONFIG_MICROWINDOWS_KBD_RAW_PATH)\" -endif -ifdef CONFIG_MICROWINDOWS_MOUSE_PATH -CFLAGS += -DNUTTX_MOUSE_PATH=\"$(CONFIG_MICROWINDOWS_MOUSE_PATH)\" -endif -ifdef CONFIG_MICROWINDOWS_TS_PATH -CFLAGS += -DNUTTX_TOUCHSCREEN_PATH=\"$(CONFIG_MICROWINDOWS_TS_PATH)\" -endif - -MW_DIR_OBJ = $(WD)/$(MICROWINDOWS_DIR_NAME)/src - -# Select NuttX drivers via Microwindows Objects.rules -ARCH = NUTTX - -ifeq ($(CONFIG_MICROWINDOWS_KBD_EVENT),y) -KEYBOARD = NUTTXKBD -else ifeq ($(CONFIG_MICROWINDOWS_KBD_RAW),y) -KEYBOARD = NUTTXRAWKBD -else ifeq ($(CONFIG_MICROWINDOWS_KBD_NONE),y) -KEYBOARD = NOKBD -else ifeq ($(CONFIG_MICROWINDOWS_KBD_CUSTOM),y) -KEYBOARD = CUSTOM -endif - -ifeq ($(CONFIG_MICROWINDOWS_MOUSE_RELATIVE),y) -MOUSE = NUTTXMOUSE -else ifeq ($(CONFIG_MICROWINDOWS_MOUSE_TS),y) -MOUSE = NUTTXTOUCH -else ifeq ($(CONFIG_MICROWINDOWS_MOUSE_NONE),y) -MOUSE = NOMOUSE -else ifeq ($(CONFIG_MICROWINDOWS_MOUSE_CUSTOM),y) -MOUSE = CUSTOM -endif - -HAVE_FNT_SUPPORT = Y - --include microwindows/src/engine/Objects.rules --include microwindows/src/drivers/Objects.rules --include microwindows/src/fonts/Objects.rules - -CSRCS += $(MW_CORE_OBJS:%.o=%.c) - -ifneq ($(CONFIG_MICROWINDOWS_MWIN),) - -# Win32 API -MWIN_CORE_SRCS = microwindows/src/mwin/winmain.c -MWIN_CORE_SRCS += microwindows/src/mwin/winuser.c -MWIN_CORE_SRCS += microwindows/src/mwin/wingdi.c -MWIN_CORE_SRCS += microwindows/src/mwin/winexpos.c -MWIN_CORE_SRCS += microwindows/src/mwin/winclip.c -MWIN_CORE_SRCS += microwindows/src/mwin/winevent.c -MWIN_CORE_SRCS += microwindows/src/mwin/windefw.c -MWIN_CORE_SRCS += microwindows/src/mwin/winrgn.c -MWIN_CORE_SRCS += microwindows/src/mwin/winfont.c -MWIN_CORE_SRCS += microwindows/src/mwin/winsbar.c -MWIN_CORE_SRCS += microwindows/src/mwin/winres.c - -# mwin winlib -WINLIB_SRCS = microwindows/src/mwin/winlib/draw3d.c -WINLIB_SRCS += microwindows/src/mwin/winlib/fastfill.c -WINLIB_SRCS += microwindows/src/mwin/winlib/windlg.c -WINLIB_SRCS += microwindows/src/mwin/winlib/graph3d.c -WINLIB_SRCS += microwindows/src/mwin/winlib/caret.c -WINLIB_SRCS += microwindows/src/mwin/winlib/static.c -WINLIB_SRCS += microwindows/src/mwin/winlib/button.c -WINLIB_SRCS += microwindows/src/mwin/winlib/newedit.c -WINLIB_SRCS += microwindows/src/mwin/winlib/newlistbox.c -WINLIB_SRCS += microwindows/src/mwin/winlib/combobox.c -WINLIB_SRCS += microwindows/src/mwin/winlib/progbar.c -WINLIB_SRCS += microwindows/src/mwin/winlib/scrlbar.c -WINLIB_SRCS += microwindows/src/mwin/winlib/medit.c -WINLIB_SRCS += microwindows/src/mwin/winlib/ptinsid.c -WINLIB_SRCS += microwindows/src/mwin/winlib/insetr.c - -CSRCS += $(MWIN_CORE_SRCS) $(WINLIB_SRCS) -CFLAGS += -DNOGDI - -endif - -include $(APPDIR)/Application.mk diff --git a/graphics/nxglyphs/Make.defs b/graphics/nxglyphs/Make.defs index 12404e5c6..cc813f834 100644 --- a/graphics/nxglyphs/Make.defs +++ b/graphics/nxglyphs/Make.defs @@ -1,7 +1,5 @@ ############################################################################ -# apps/graphics/nxglyphs/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 +# apps/graphics/tiff/Make.defs # # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with @@ -20,6 +18,6 @@ # ############################################################################ -ifneq ($(CONFIG_NXWIDGETS),) +ifeq ($(CONFIG_NXWIDGETS),y) CONFIGURED_APPS += $(APPDIR)/graphics/nxglyphs endif diff --git a/graphics/nxglyphs/Makefile b/graphics/nxglyphs/Makefile index 7b0d5e688..48b2314b8 100644 --- a/graphics/nxglyphs/Makefile +++ b/graphics/nxglyphs/Makefile @@ -1,7 +1,5 @@ ############################################################################ -# apps/graphics/nxglyphs/Makefile -# -# SPDX-License-Identifier: Apache-2.0 +# apps/graphics/tiff/Makefile # # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with diff --git a/graphics/nxglyphs/include/cursor-arrow1-16x16.h b/graphics/nxglyphs/include/cursor-arrow1-16x16.h index 5cffe5e7b..480cb971c 100644 --- a/graphics/nxglyphs/include/cursor-arrow1-16x16.h +++ b/graphics/nxglyphs/include/cursor-arrow1-16x16.h @@ -1,8 +1,6 @@ /*************************************************************************** * apps/graphics/nxglyphs/include/cursor-arrow1-16x16.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxglyphs/include/cursor-arrow1-30x30.h b/graphics/nxglyphs/include/cursor-arrow1-30x30.h index 4de8ba1dd..65f2e6df0 100644 --- a/graphics/nxglyphs/include/cursor-arrow1-30x30.h +++ b/graphics/nxglyphs/include/cursor-arrow1-30x30.h @@ -1,8 +1,6 @@ /*************************************************************************** * apps/graphics/nxglyphs/include/cursor-arrow1-30x30.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxglyphs/include/cursor-arrow2-16x16.h b/graphics/nxglyphs/include/cursor-arrow2-16x16.h index 25f157486..773cc2938 100644 --- a/graphics/nxglyphs/include/cursor-arrow2-16x16.h +++ b/graphics/nxglyphs/include/cursor-arrow2-16x16.h @@ -1,8 +1,6 @@ /*************************************************************************** * apps/graphics/nxglyphs/include/cursor-arrow2-16x16.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxglyphs/include/cursor-arrow2-30x30.h b/graphics/nxglyphs/include/cursor-arrow2-30x30.h index 94057fb45..7cbf62371 100644 --- a/graphics/nxglyphs/include/cursor-arrow2-30x30.h +++ b/graphics/nxglyphs/include/cursor-arrow2-30x30.h @@ -1,8 +1,6 @@ /*************************************************************************** * apps/graphics/nxglyphs/include/cursor-arrow2-30x30.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxglyphs/include/cursor-grab-14x16.h b/graphics/nxglyphs/include/cursor-grab-14x16.h index cf588bb5c..e3dc2e216 100644 --- a/graphics/nxglyphs/include/cursor-grab-14x16.h +++ b/graphics/nxglyphs/include/cursor-grab-14x16.h @@ -1,8 +1,6 @@ /*************************************************************************** * apps/graphics/nxglyphs/include/cursor-grab-14x16.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxglyphs/include/cursor-grab-25x30.h b/graphics/nxglyphs/include/cursor-grab-25x30.h index 944b8a0f5..6c7e41402 100644 --- a/graphics/nxglyphs/include/cursor-grab-25x30.h +++ b/graphics/nxglyphs/include/cursor-grab-25x30.h @@ -1,8 +1,6 @@ /*************************************************************************** * apps/graphics/nxglyphs/include/cursor-grab-25x30.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxglyphs/include/cursor-resize-16x16.h b/graphics/nxglyphs/include/cursor-resize-16x16.h index 1acf8e187..54b8e750e 100644 --- a/graphics/nxglyphs/include/cursor-resize-16x16.h +++ b/graphics/nxglyphs/include/cursor-resize-16x16.h @@ -1,8 +1,6 @@ /*************************************************************************** * apps/graphics/nxglyphs/include/cursor-resize-16x16.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxglyphs/include/cursor-resize-30x30.h b/graphics/nxglyphs/include/cursor-resize-30x30.h index 5a214cd5e..4795bffd8 100644 --- a/graphics/nxglyphs/include/cursor-resize-30x30.h +++ b/graphics/nxglyphs/include/cursor-resize-30x30.h @@ -1,8 +1,6 @@ /*************************************************************************** * apps/graphics/nxglyphs/include/cursor-resize-30x30.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxglyphs/include/cursor-resize-61x62.h b/graphics/nxglyphs/include/cursor-resize-61x62.h index e78dbfc95..048c05339 100644 --- a/graphics/nxglyphs/include/cursor-resize-61x62.h +++ b/graphics/nxglyphs/include/cursor-resize-61x62.h @@ -1,8 +1,6 @@ /*************************************************************************** * apps/graphics/nxglyphs/include/cursor-resize-61x62.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxglyphs/include/cursor-wait-13x16.h b/graphics/nxglyphs/include/cursor-wait-13x16.h index 062d278d4..bafdf8ec9 100644 --- a/graphics/nxglyphs/include/cursor-wait-13x16.h +++ b/graphics/nxglyphs/include/cursor-wait-13x16.h @@ -1,8 +1,6 @@ /*************************************************************************** * apps/graphics/nxglyphs/include/cursor-wait-13x16.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxglyphs/include/cursor-wait-23x30.h b/graphics/nxglyphs/include/cursor-wait-23x30.h index fcf1f3081..f705dcdfa 100644 --- a/graphics/nxglyphs/include/cursor-wait-23x30.h +++ b/graphics/nxglyphs/include/cursor-wait-23x30.h @@ -1,8 +1,6 @@ /*************************************************************************** * apps/graphics/nxglyphs/include/cursor-wait-23x30.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxglyphs/include/cursor-zoomin-16x16.h b/graphics/nxglyphs/include/cursor-zoomin-16x16.h index ec3fa8a31..ca3e02826 100644 --- a/graphics/nxglyphs/include/cursor-zoomin-16x16.h +++ b/graphics/nxglyphs/include/cursor-zoomin-16x16.h @@ -1,8 +1,6 @@ /*************************************************************************** * apps/graphics/nxglyphs/include/cursor-zoomin-16x16.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxglyphs/include/cursor-zoomin-30x30.h b/graphics/nxglyphs/include/cursor-zoomin-30x30.h index c92e3c265..d4bc25c92 100644 --- a/graphics/nxglyphs/include/cursor-zoomin-30x30.h +++ b/graphics/nxglyphs/include/cursor-zoomin-30x30.h @@ -1,8 +1,6 @@ /*************************************************************************** * apps/graphics/nxglyphs/include/cursor-zoomin-30x30.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxglyphs/include/cursor-zoomout-16x16.h b/graphics/nxglyphs/include/cursor-zoomout-16x16.h index 97fb72dae..d75709c87 100644 --- a/graphics/nxglyphs/include/cursor-zoomout-16x16.h +++ b/graphics/nxglyphs/include/cursor-zoomout-16x16.h @@ -1,8 +1,6 @@ /*************************************************************************** * apps/graphics/nxglyphs/include/cursor-zoomout-16x16.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxglyphs/include/cursor-zoomout-30x30.h b/graphics/nxglyphs/include/cursor-zoomout-30x30.h index 9a21f61ab..6217946df 100644 --- a/graphics/nxglyphs/include/cursor-zoomout-30x30.h +++ b/graphics/nxglyphs/include/cursor-zoomout-30x30.h @@ -1,8 +1,6 @@ /*************************************************************************** * apps/graphics/nxglyphs/include/cursor-zoomout-30x30.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxglyphs/include/mkcursor.c b/graphics/nxglyphs/include/mkcursor.c index b7d8fa8f0..4e8b3b105 100644 --- a/graphics/nxglyphs/include/mkcursor.c +++ b/graphics/nxglyphs/include/mkcursor.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxglyphs/include/mkcursor.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxglyphs/include/mkcursor.sh b/graphics/nxglyphs/include/mkcursor.sh index cb7594a59..277855d0e 100644 --- a/graphics/nxglyphs/include/mkcursor.sh +++ b/graphics/nxglyphs/include/mkcursor.sh @@ -1,8 +1,6 @@ #!/usr/bin/env bash # apps/graphics/nxglyphs/inlclude/mkcursor.sh # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/graphics/nxglyphs/src/glpyh_menu2-21x21.cxx b/graphics/nxglyphs/src/glpyh_menu2-21x21.cxx index 6adf09c3f..2ea077a5a 100644 --- a/graphics/nxglyphs/src/glpyh_menu2-21x21.cxx +++ b/graphics/nxglyphs/src/glpyh_menu2-21x21.cxx @@ -1,8 +1,6 @@ /******************************************************************************************** * apps/graphics/nxglyphs/src/glyph_xxxxxx.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxglyphs/src/glpyh_menu2-42x42.cxx b/graphics/nxglyphs/src/glpyh_menu2-42x42.cxx index 947bef692..fa57ab1cb 100644 --- a/graphics/nxglyphs/src/glpyh_menu2-42x42.cxx +++ b/graphics/nxglyphs/src/glpyh_menu2-42x42.cxx @@ -1,8 +1,6 @@ /******************************************************************************************** * apps/graphics/nxglyphs/src/glyph_xxxxxx.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxglyphs/src/glpyh_minimize2-21x21.cxx b/graphics/nxglyphs/src/glpyh_minimize2-21x21.cxx index 7f891c913..36f2b0d11 100644 --- a/graphics/nxglyphs/src/glpyh_minimize2-21x21.cxx +++ b/graphics/nxglyphs/src/glpyh_minimize2-21x21.cxx @@ -1,8 +1,6 @@ /******************************************************************************************** * apps/graphics/nxglyphs/src/glyph_xxxxxx.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxglyphs/src/glpyh_minimize2-42x42.cxx b/graphics/nxglyphs/src/glpyh_minimize2-42x42.cxx index 582d86fd4..1f729cc01 100644 --- a/graphics/nxglyphs/src/glpyh_minimize2-42x42.cxx +++ b/graphics/nxglyphs/src/glpyh_minimize2-42x42.cxx @@ -1,8 +1,6 @@ /******************************************************************************************** * apps/graphics/nxglyphs/src/glyph_xxxxxx.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxglyphs/src/glpyh_resize2-21x21.cxx b/graphics/nxglyphs/src/glpyh_resize2-21x21.cxx index 1e05ce18d..3d32b4464 100644 --- a/graphics/nxglyphs/src/glpyh_resize2-21x21.cxx +++ b/graphics/nxglyphs/src/glpyh_resize2-21x21.cxx @@ -1,8 +1,6 @@ /******************************************************************************************** * apps/graphics/nxglyphs/src/glyph_xxxxxx.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxglyphs/src/glpyh_resize2-42x42.cxx b/graphics/nxglyphs/src/glpyh_resize2-42x42.cxx index c733a08ba..e138226dc 100644 --- a/graphics/nxglyphs/src/glpyh_resize2-42x42.cxx +++ b/graphics/nxglyphs/src/glpyh_resize2-42x42.cxx @@ -1,8 +1,6 @@ /******************************************************************************************** * apps/graphics/nxglyphs/src/glyph_xxxxxx.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxglyphs/src/glpyh_stop2-21x21.cxx b/graphics/nxglyphs/src/glpyh_stop2-21x21.cxx index d1da539dc..511c750f1 100644 --- a/graphics/nxglyphs/src/glpyh_stop2-21x21.cxx +++ b/graphics/nxglyphs/src/glpyh_stop2-21x21.cxx @@ -1,8 +1,6 @@ /******************************************************************************************** * apps/graphics/nxglyphs/src/glyph_xxxxxx.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxglyphs/src/glyph_arrowdown.cxx b/graphics/nxglyphs/src/glyph_arrowdown.cxx index 84bdf55aa..71745731e 100644 --- a/graphics/nxglyphs/src/glyph_arrowdown.cxx +++ b/graphics/nxglyphs/src/glyph_arrowdown.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxglyphs/src/glyph_arrowdown.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxglyphs/src/glyph_arrowleft.cxx b/graphics/nxglyphs/src/glyph_arrowleft.cxx index a493713cd..3cc0067a0 100644 --- a/graphics/nxglyphs/src/glyph_arrowleft.cxx +++ b/graphics/nxglyphs/src/glyph_arrowleft.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxglyphs/src/glyph_glypharrowleft.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxglyphs/src/glyph_arrowright.cxx b/graphics/nxglyphs/src/glyph_arrowright.cxx index f7bacc7d2..6662af8e1 100644 --- a/graphics/nxglyphs/src/glyph_arrowright.cxx +++ b/graphics/nxglyphs/src/glyph_arrowright.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxglyphs/src/glyph_arrowright.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxglyphs/src/glyph_arrowup.cxx b/graphics/nxglyphs/src/glyph_arrowup.cxx index 75455b88d..9d367dec1 100644 --- a/graphics/nxglyphs/src/glyph_arrowup.cxx +++ b/graphics/nxglyphs/src/glyph_arrowup.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxglyphs/src/glyph_arrowup.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxglyphs/src/glyph_backspace.cxx b/graphics/nxglyphs/src/glyph_backspace.cxx index 66acf1d78..5512008fa 100644 --- a/graphics/nxglyphs/src/glyph_backspace.cxx +++ b/graphics/nxglyphs/src/glyph_backspace.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxglyphs/src/glyph_backspace.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxglyphs/src/glyph_calculator24x25.cxx b/graphics/nxglyphs/src/glyph_calculator24x25.cxx index 640e63092..105f9ae7c 100644 --- a/graphics/nxglyphs/src/glyph_calculator24x25.cxx +++ b/graphics/nxglyphs/src/glyph_calculator24x25.cxx @@ -1,8 +1,6 @@ /******************************************************************************************** * apps/graphics/nxglyphs/src/glyph_calculator24x25.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxglyphs/src/glyph_calculator47x49.cxx b/graphics/nxglyphs/src/glyph_calculator47x49.cxx index ddafba86d..6ea5fb550 100644 --- a/graphics/nxglyphs/src/glyph_calculator47x49.cxx +++ b/graphics/nxglyphs/src/glyph_calculator47x49.cxx @@ -1,8 +1,6 @@ /******************************************************************************************** * apps/graphics/nxglyphs/src/glyph_calculator47x47.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxglyphs/src/glyph_calibration24x21.cxx b/graphics/nxglyphs/src/glyph_calibration24x21.cxx index 4f3bbad00..cc510d4f3 100644 --- a/graphics/nxglyphs/src/glyph_calibration24x21.cxx +++ b/graphics/nxglyphs/src/glyph_calibration24x21.cxx @@ -1,8 +1,6 @@ /******************************************************************************************** * apps/graphics/nxglyphs/src/glyph_calibration24x21.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxglyphs/src/glyph_calibration48x42.cxx b/graphics/nxglyphs/src/glyph_calibration48x42.cxx index a7518c187..10af4f128 100644 --- a/graphics/nxglyphs/src/glyph_calibration48x42.cxx +++ b/graphics/nxglyphs/src/glyph_calibration48x42.cxx @@ -1,8 +1,6 @@ /******************************************************************************************** * apps/graphics/nxglyphs/src/glyph_calibration48x42.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxglyphs/src/glyph_capslock.cxx b/graphics/nxglyphs/src/glyph_capslock.cxx index fcb55123b..c62bfa435 100644 --- a/graphics/nxglyphs/src/glyph_capslock.cxx +++ b/graphics/nxglyphs/src/glyph_capslock.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxglyphs/src/glyph_capslock.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxglyphs/src/glyph_checkboxmu.cxx b/graphics/nxglyphs/src/glyph_checkboxmu.cxx index 50aeb0cb6..33bf8020c 100644 --- a/graphics/nxglyphs/src/glyph_checkboxmu.cxx +++ b/graphics/nxglyphs/src/glyph_checkboxmu.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxglyphs/src/glyph_checkboxmu.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxglyphs/src/glyph_checkboxoff.cxx b/graphics/nxglyphs/src/glyph_checkboxoff.cxx index 6f6525fbc..c3d223f4f 100644 --- a/graphics/nxglyphs/src/glyph_checkboxoff.cxx +++ b/graphics/nxglyphs/src/glyph_checkboxoff.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxglyphs/src/glyph_checkboxoff.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -102,7 +100,7 @@ const struct SBitmap NXWidgets::g_checkBoxOff = 0, // width - Width in pixels 0, // height - Height in rows (0*CONFIG_NXWIDGETS_BPP + 7) / 8, // stride - Width in bytes - NULL // data - Pointer to the beginning of pixel data + (const nxgl_mxpixel_t*)NULL // data - Pointer to the beginning of pixel data }; #endif // CONFIG_NXWIDGETS_BPP != 8 diff --git a/graphics/nxglyphs/src/glyph_checkboxon.cxx b/graphics/nxglyphs/src/glyph_checkboxon.cxx index 444ea5926..18d87c083 100644 --- a/graphics/nxglyphs/src/glyph_checkboxon.cxx +++ b/graphics/nxglyphs/src/glyph_checkboxon.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxglyphs/src/glyph_checkboxon.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxglyphs/src/glyph_cmd25x22.cxx b/graphics/nxglyphs/src/glyph_cmd25x22.cxx index 7f676f5fa..8e75c8893 100644 --- a/graphics/nxglyphs/src/glyph_cmd25x22.cxx +++ b/graphics/nxglyphs/src/glyph_cmd25x22.cxx @@ -1,8 +1,6 @@ /******************************************************************************************** * apps/graphics/nxglyphs/src/glyph_cmd24x22.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxglyphs/src/glyph_cmd49x43.cxx b/graphics/nxglyphs/src/glyph_cmd49x43.cxx index 62c1a038a..25a5049e9 100644 --- a/graphics/nxglyphs/src/glyph_cmd49x43.cxx +++ b/graphics/nxglyphs/src/glyph_cmd49x43.cxx @@ -1,8 +1,6 @@ /******************************************************************************************** * apps/graphics/nxglyphs/src/glyph_cmd49x43.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxglyphs/src/glyph_control.cxx b/graphics/nxglyphs/src/glyph_control.cxx index 53ce66707..7abb17c1f 100644 --- a/graphics/nxglyphs/src/glyph_control.cxx +++ b/graphics/nxglyphs/src/glyph_control.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxglyphs/src/glyph_control.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxglyphs/src/glyph_cycle.cxx b/graphics/nxglyphs/src/glyph_cycle.cxx index fe861d591..ef93caebf 100644 --- a/graphics/nxglyphs/src/glyph_cycle.cxx +++ b/graphics/nxglyphs/src/glyph_cycle.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxglyphs/src/glyph_cycle.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxglyphs/src/glyph_lcdclock102x48.cxx b/graphics/nxglyphs/src/glyph_lcdclock102x48.cxx index 02557fe83..d3a05ee4a 100644 --- a/graphics/nxglyphs/src/glyph_lcdclock102x48.cxx +++ b/graphics/nxglyphs/src/glyph_lcdclock102x48.cxx @@ -1,8 +1,6 @@ /******************************************************************************************** * apps/graphics/nxglyphs/src/glyph_lcdclock102x48.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxglyphs/src/glyph_lcdclock136x64.cxx b/graphics/nxglyphs/src/glyph_lcdclock136x64.cxx index 9aa371329..dd5a90801 100644 --- a/graphics/nxglyphs/src/glyph_lcdclock136x64.cxx +++ b/graphics/nxglyphs/src/glyph_lcdclock136x64.cxx @@ -1,8 +1,6 @@ /******************************************************************************************** * apps/graphics/nxglyphs/src/glyph_lcdclock136x64.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxglyphs/src/glyph_lcdclock51x24.cxx b/graphics/nxglyphs/src/glyph_lcdclock51x24.cxx index aac6c329a..673bf5cc0 100644 --- a/graphics/nxglyphs/src/glyph_lcdclock51x24.cxx +++ b/graphics/nxglyphs/src/glyph_lcdclock51x24.cxx @@ -1,8 +1,6 @@ /******************************************************************************************** * apps/graphics/nxglyphs/src/glyph_lcdclock51x24.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxglyphs/src/glyph_mediagrip60x30.cxx b/graphics/nxglyphs/src/glyph_mediagrip60x30.cxx index 8ba1d5c7e..feb051412 100644 --- a/graphics/nxglyphs/src/glyph_mediagrip60x30.cxx +++ b/graphics/nxglyphs/src/glyph_mediagrip60x30.cxx @@ -1,8 +1,6 @@ /******************************************************************************************** * apps/graphics/nxglyphs/src/mediagrip60x30.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxglyphs/src/glyph_mediaplayer24x24.cxx b/graphics/nxglyphs/src/glyph_mediaplayer24x24.cxx index aa2ed236a..eb76a4095 100644 --- a/graphics/nxglyphs/src/glyph_mediaplayer24x24.cxx +++ b/graphics/nxglyphs/src/glyph_mediaplayer24x24.cxx @@ -1,8 +1,6 @@ /******************************************************************************************** * apps/graphics/nxglyphs/src/glyph_mediaplayer24x24.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxglyphs/src/glyph_mediaplayer44x50.cxx b/graphics/nxglyphs/src/glyph_mediaplayer44x50.cxx index d5784d342..52a705b14 100644 --- a/graphics/nxglyphs/src/glyph_mediaplayer44x50.cxx +++ b/graphics/nxglyphs/src/glyph_mediaplayer44x50.cxx @@ -1,8 +1,6 @@ /******************************************************************************************** * apps/graphics/nxglyphs/src/glyph_mediaplayer44x50.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxglyphs/src/glyph_menu21x21.cxx b/graphics/nxglyphs/src/glyph_menu21x21.cxx index 0e8d99b2a..4141387b3 100644 --- a/graphics/nxglyphs/src/glyph_menu21x21.cxx +++ b/graphics/nxglyphs/src/glyph_menu21x21.cxx @@ -1,8 +1,6 @@ /******************************************************************************************** * apps/graphics/nxglyphs/src/glyph_menu21x21.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxglyphs/src/glyph_menu42x42.cxx b/graphics/nxglyphs/src/glyph_menu42x42.cxx index 314229519..0371c7ba2 100644 --- a/graphics/nxglyphs/src/glyph_menu42x42.cxx +++ b/graphics/nxglyphs/src/glyph_menu42x42.cxx @@ -1,8 +1,6 @@ /******************************************************************************************** * apps/graphics/nxglyphs/src/glyph_men42x42.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxglyphs/src/glyph_minimize21x21.cxx b/graphics/nxglyphs/src/glyph_minimize21x21.cxx index 534fd4096..18e3b27da 100644 --- a/graphics/nxglyphs/src/glyph_minimize21x21.cxx +++ b/graphics/nxglyphs/src/glyph_minimize21x21.cxx @@ -1,8 +1,6 @@ /******************************************************************************************** * apps/graphics/nxglyphs/src/glyph_minimize21x21.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxglyphs/src/glyph_minimize42x42.cxx b/graphics/nxglyphs/src/glyph_minimize42x42.cxx index d0d9065ff..454266364 100644 --- a/graphics/nxglyphs/src/glyph_minimize42x42.cxx +++ b/graphics/nxglyphs/src/glyph_minimize42x42.cxx @@ -1,8 +1,6 @@ /******************************************************************************************** * apps/graphics/nxglyphs/src/glyph_minimize42x42.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxglyphs/src/glyph_mplayer_controls32x32.cxx b/graphics/nxglyphs/src/glyph_mplayer_controls32x32.cxx index 1c4cb7479..12c9b4476 100644 --- a/graphics/nxglyphs/src/glyph_mplayer_controls32x32.cxx +++ b/graphics/nxglyphs/src/glyph_mplayer_controls32x32.cxx @@ -1,8 +1,6 @@ /******************************************************************************************** * apps/graphics/nxglyphs/src/glyph_mediaplayer32x32.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxglyphs/src/glyph_mplayer_controls43x41.cxx b/graphics/nxglyphs/src/glyph_mplayer_controls43x41.cxx index b37283404..256415d69 100644 --- a/graphics/nxglyphs/src/glyph_mplayer_controls43x41.cxx +++ b/graphics/nxglyphs/src/glyph_mplayer_controls43x41.cxx @@ -1,8 +1,6 @@ /******************************************************************************************** * apps/graphics/nxglyphs/src/glyph_mediaplayer43x41.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxglyphs/src/glyph_nxicon21x21.cxx b/graphics/nxglyphs/src/glyph_nxicon21x21.cxx index 721d03bdb..605ee81ee 100644 --- a/graphics/nxglyphs/src/glyph_nxicon21x21.cxx +++ b/graphics/nxglyphs/src/glyph_nxicon21x21.cxx @@ -1,8 +1,6 @@ /******************************************************************************************** * apps/graphics/nxglyphs/src/glyph_nxicon21x21.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxglyphs/src/glyph_nxicon42x42.cxx b/graphics/nxglyphs/src/glyph_nxicon42x42.cxx index e36e0650d..0b0f9589e 100644 --- a/graphics/nxglyphs/src/glyph_nxicon42x42.cxx +++ b/graphics/nxglyphs/src/glyph_nxicon42x42.cxx @@ -1,8 +1,6 @@ /******************************************************************************************** * apps/graphics/nxglyphs/src/glyph_nxicon42x42.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxglyphs/src/glyph_nxlogo160x160.cxx b/graphics/nxglyphs/src/glyph_nxlogo160x160.cxx index f2b2f94ab..2f67d2f2c 100644 --- a/graphics/nxglyphs/src/glyph_nxlogo160x160.cxx +++ b/graphics/nxglyphs/src/glyph_nxlogo160x160.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxglyphs/src/glyph_nxlogo160x160.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxglyphs/src/glyph_nxlogo320x320.cxx b/graphics/nxglyphs/src/glyph_nxlogo320x320.cxx index 8d13da52f..95e335943 100644 --- a/graphics/nxglyphs/src/glyph_nxlogo320x320.cxx +++ b/graphics/nxglyphs/src/glyph_nxlogo320x320.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxglyphs/src/glyph_nxlogo320x320.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxglyphs/src/glyph_play24x24.cxx b/graphics/nxglyphs/src/glyph_play24x24.cxx index 406f619a2..37f74e937 100644 --- a/graphics/nxglyphs/src/glyph_play24x24.cxx +++ b/graphics/nxglyphs/src/glyph_play24x24.cxx @@ -1,8 +1,6 @@ /******************************************************************************************** * apps/graphics/nxglyphs/src/glyph_play24x24.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxglyphs/src/glyph_play48x48.cxx b/graphics/nxglyphs/src/glyph_play48x48.cxx index 13edfe0be..45d7bdf09 100644 --- a/graphics/nxglyphs/src/glyph_play48x48.cxx +++ b/graphics/nxglyphs/src/glyph_play48x48.cxx @@ -1,8 +1,6 @@ /******************************************************************************************** * apps/graphics/nxglyphs/src/glyph_play24x24.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxglyphs/src/glyph_radiobuttonmu.cxx b/graphics/nxglyphs/src/glyph_radiobuttonmu.cxx index beb97dc6c..ac0230af9 100644 --- a/graphics/nxglyphs/src/glyph_radiobuttonmu.cxx +++ b/graphics/nxglyphs/src/glyph_radiobuttonmu.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxglyphs/src/glyph_radiobuttonmu.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxglyphs/src/glyph_radiobuttonoff.cxx b/graphics/nxglyphs/src/glyph_radiobuttonoff.cxx index ef523b7d7..aaa761a0c 100644 --- a/graphics/nxglyphs/src/glyph_radiobuttonoff.cxx +++ b/graphics/nxglyphs/src/glyph_radiobuttonoff.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxglyphs/src/glyph_radiobuttonoff.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxglyphs/src/glyph_radiobuttonon.cxx b/graphics/nxglyphs/src/glyph_radiobuttonon.cxx index 3e16968e5..5d5a68b7e 100644 --- a/graphics/nxglyphs/src/glyph_radiobuttonon.cxx +++ b/graphics/nxglyphs/src/glyph_radiobuttonon.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxglyphs/src/glyph_radiobuttonon.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxglyphs/src/glyph_resize21x21.cxx b/graphics/nxglyphs/src/glyph_resize21x21.cxx index ac36adf04..72def4dcf 100644 --- a/graphics/nxglyphs/src/glyph_resize21x21.cxx +++ b/graphics/nxglyphs/src/glyph_resize21x21.cxx @@ -1,8 +1,6 @@ /******************************************************************************************** * apps/graphics/nxglyphs/src/glyph_resize21x21.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxglyphs/src/glyph_resize42x42.cxx b/graphics/nxglyphs/src/glyph_resize42x42.cxx index e040eaf49..1984993a3 100644 --- a/graphics/nxglyphs/src/glyph_resize42x42.cxx +++ b/graphics/nxglyphs/src/glyph_resize42x42.cxx @@ -1,8 +1,6 @@ /******************************************************************************************** * apps/graphics/nxglyphs/src/glyph_resize42x42.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxglyphs/src/glyph_return.cxx b/graphics/nxglyphs/src/glyph_return.cxx index ce3da683e..7021fccc5 100644 --- a/graphics/nxglyphs/src/glyph_return.cxx +++ b/graphics/nxglyphs/src/glyph_return.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxglyphs/src/glyph_return.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxglyphs/src/glyph_screendepthdown.cxx b/graphics/nxglyphs/src/glyph_screendepthdown.cxx index f945a6887..566ec4800 100644 --- a/graphics/nxglyphs/src/glyph_screendepthdown.cxx +++ b/graphics/nxglyphs/src/glyph_screendepthdown.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxglyphs/src/glyph_screendepthdown.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxglyphs/src/glyph_screendepthup.cxx b/graphics/nxglyphs/src/glyph_screendepthup.cxx index b4c1c0055..a07fb7ba8 100644 --- a/graphics/nxglyphs/src/glyph_screendepthup.cxx +++ b/graphics/nxglyphs/src/glyph_screendepthup.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxglyphs/src/glyph_screendepthup.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxglyphs/src/glyph_screenflipdown.cxx b/graphics/nxglyphs/src/glyph_screenflipdown.cxx index db8913fe1..5efa1e234 100644 --- a/graphics/nxglyphs/src/glyph_screenflipdown.cxx +++ b/graphics/nxglyphs/src/glyph_screenflipdown.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxglyphs/src/glyph_screenflipdown.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxglyphs/src/glyph_screenflipup.cxx b/graphics/nxglyphs/src/glyph_screenflipup.cxx index 7e7d05375..00b1dc159 100644 --- a/graphics/nxglyphs/src/glyph_screenflipup.cxx +++ b/graphics/nxglyphs/src/glyph_screenflipup.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxglyphs/src/glyph_screenflipup.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxglyphs/src/glyph_shift.cxx b/graphics/nxglyphs/src/glyph_shift.cxx index 2ac26cbec..3dae7ba81 100644 --- a/graphics/nxglyphs/src/glyph_shift.cxx +++ b/graphics/nxglyphs/src/glyph_shift.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxglyphs/src/glyph_shift.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxglyphs/src/glyph_stop2-42x42.cxx b/graphics/nxglyphs/src/glyph_stop2-42x42.cxx index bca0789fa..540cea78f 100644 --- a/graphics/nxglyphs/src/glyph_stop2-42x42.cxx +++ b/graphics/nxglyphs/src/glyph_stop2-42x42.cxx @@ -1,8 +1,6 @@ /******************************************************************************************** * apps/graphics/nxglyphs/src/glyph_xxxxxx.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxglyphs/src/glyph_stop21x21.cxx b/graphics/nxglyphs/src/glyph_stop21x21.cxx index 24253f741..459ab9fe6 100644 --- a/graphics/nxglyphs/src/glyph_stop21x21.cxx +++ b/graphics/nxglyphs/src/glyph_stop21x21.cxx @@ -1,8 +1,6 @@ /******************************************************************************************** * apps/graphics/nxglyphs/src/glyph_stop21x21.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxglyphs/src/glyph_stop42x42.cxx b/graphics/nxglyphs/src/glyph_stop42x42.cxx index df00f324e..39ea5b959 100644 --- a/graphics/nxglyphs/src/glyph_stop42x42.cxx +++ b/graphics/nxglyphs/src/glyph_stop42x42.cxx @@ -1,8 +1,6 @@ /******************************************************************************************** * apps/graphics/nxglyphs/src/glyph_stop42x42.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxglyphs/src/glyph_windowclose.cxx b/graphics/nxglyphs/src/glyph_windowclose.cxx index ed5aae68a..a15a86dbc 100644 --- a/graphics/nxglyphs/src/glyph_windowclose.cxx +++ b/graphics/nxglyphs/src/glyph_windowclose.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxglyphs/src/glyph_windowclose.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxglyphs/src/glyph_windowdepthdown.cxx b/graphics/nxglyphs/src/glyph_windowdepthdown.cxx index 57a7fa0b5..3caab7a28 100644 --- a/graphics/nxglyphs/src/glyph_windowdepthdown.cxx +++ b/graphics/nxglyphs/src/glyph_windowdepthdown.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxglyphs/src/glyph_windowdepthdown.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxglyphs/src/glyph_windowdepthup.cxx b/graphics/nxglyphs/src/glyph_windowdepthup.cxx index 85982122c..0da66903e 100644 --- a/graphics/nxglyphs/src/glyph_windowdepthup.cxx +++ b/graphics/nxglyphs/src/glyph_windowdepthup.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxglyphs/src/glyph_windowdepthup.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxglyphs/src/mksrle.c b/graphics/nxglyphs/src/mksrle.c index 7c3cc849e..14000fdbd 100644 --- a/graphics/nxglyphs/src/mksrle.c +++ b/graphics/nxglyphs/src/mksrle.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxglyphs/src/mksrle.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxglyphs/src/mksrle.sh b/graphics/nxglyphs/src/mksrle.sh index 0394a7421..e0f5abd57 100644 --- a/graphics/nxglyphs/src/mksrle.sh +++ b/graphics/nxglyphs/src/mksrle.sh @@ -1,8 +1,6 @@ #!/usr/bin/env bash # apps/graphics/nxglyphs/src/mksrle.sh # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwidgets/Doxygen/Doxyfile b/graphics/nxwidgets/Doxygen/Doxyfile index b80c12a02..45ab1094e 100644 --- a/graphics/nxwidgets/Doxygen/Doxyfile +++ b/graphics/nxwidgets/Doxygen/Doxyfile @@ -63,7 +63,7 @@ CREATE_SUBDIRS = NO OUTPUT_LANGUAGE = English # If the BRIEF_MEMBER_DESC tag is set to YES (the default) Doxygen will -# include brief member descriptions after the members that are listed in +# include brief member descriptions after the members that are listed in # the file and class documentation (similar to JavaDoc). # Set to NO to disable this. @@ -1084,7 +1084,7 @@ USE_PDFLATEX = YES LATEX_BATCHMODE = NO # If LATEX_HIDE_INDICES is set to YES then doxygen will not -# include the index chapters (such as File Index, Compound Index, etc.) +# include the index chapters (such as File Index, Compound Index, etc.) # in the output. LATEX_HIDE_INDICES = NO diff --git a/graphics/nxwidgets/Doxygen/README.md b/graphics/nxwidgets/Doxygen/README.md new file mode 100644 index 000000000..dc38ed5da --- /dev/null +++ b/graphics/nxwidgets/Doxygen/README.md @@ -0,0 +1,68 @@ +# Graphics / `nxwidgets` NXWidgets / Doxygen + +This directory contains the documentation automatically generated by Doxygen. + +## Contents + +- Installing the necessary packages in Ubuntu +- Generating documentation +- References + +## Installing the Necessary Packages in Ubuntu + +1. Install the following packages. + + ```bash + $ sudo aptitude install doxygen doxygen-doc doxygen-gui dot2tex graphviz + ``` + +2. (Optional) Install Doxygen from the latest sourcode. + + The Ubuntu package is outdated. The newer the version of Doxygen, the better + the documentation looks. + + Place yourself in some temporary folder where you can download the source, + and run [1]: + + ```bash + $ svn co https://doxygen.svn.sourceforge.net/svnroot/doxygen/trunk doxygen-svn + $ cd doxygen-svn + $ ./configure + $ make + $ make install + ``` + +## Generating Documentation + +Two ways described here: + +1. Use the provided `gendoc.sh` script. + + ```bash + trunk/NXWidgets/Doxygen/gendoc.sh + ``` + + The script only needs the argument to the absolute path where to place the + generated documentation. I.e.: + + ```bash + $ cd /path/to/nuttx/trunk/NXWidgets/Doxygen/ + $ mkdir doc + $ ./gendoc.sh $PWD/doc + ``` + +2. Using the `Doxyfile` directly: + + The file `Doxyfile` contains the configuration of the Doxygen settings for + the run, edit only if necessary. + + To generate the documentation type: + + ```bash + $ cd /path/to/nuttx/trunk/NXWidgets/Doxygen/ + $ doxygen Doxyfile + ``` + +## References + +[1] http://www.stack.nl/~dimitri/doxygen/download.html diff --git a/graphics/nxwidgets/Doxygen/gendoc.sh b/graphics/nxwidgets/Doxygen/gendoc.sh index 915833650..b52649943 100755 --- a/graphics/nxwidgets/Doxygen/gendoc.sh +++ b/graphics/nxwidgets/Doxygen/gendoc.sh @@ -2,8 +2,6 @@ ################################################################################# # apps/graphics/nxwidgets/Doxygen/gendoc.sh # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwidgets/Kconfig b/graphics/nxwidgets/Kconfig index 2de028f7f..cfaefa7df 100644 --- a/graphics/nxwidgets/Kconfig +++ b/graphics/nxwidgets/Kconfig @@ -18,7 +18,8 @@ menu "NX Server/Device Configuration" config NXWIDGETS_FLICKERFREE bool "Enable Flicker Reduction Logic" - default NX_LCDDRIVER + default y if NX_LCDDRIVER + default n if !NX_LCDDRIVER ---help--- Because of their performance an in the manner in which they are updated, LCDs may be prone to "flicker" in the displays when Widgets diff --git a/graphics/nxwidgets/Make.defs b/graphics/nxwidgets/Make.defs index 68977c4e2..049c7c272 100644 --- a/graphics/nxwidgets/Make.defs +++ b/graphics/nxwidgets/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/graphics/nxwidgets/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -20,6 +18,6 @@ # ############################################################################ -ifneq ($(CONFIG_NXWIDGETS),) +ifeq ($(CONFIG_NXWIDGETS),y) CONFIGURED_APPS += $(APPDIR)/graphics/nxwidgets endif diff --git a/graphics/nxwidgets/Makefile b/graphics/nxwidgets/Makefile index 26ab16c42..809096cac 100644 --- a/graphics/nxwidgets/Makefile +++ b/graphics/nxwidgets/Makefile @@ -1,7 +1,5 @@ ################################################################################# -# apps/graphics/nxwidgets/Makefile -# -# SPDX-License-Identifier: Apache-2.0 +# appx/graphics/nxwidgets/Makefile # # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with diff --git a/graphics/nxwidgets/README.md b/graphics/nxwidgets/README.md new file mode 100644 index 000000000..5fc93f371 --- /dev/null +++ b/graphics/nxwidgets/README.md @@ -0,0 +1,68 @@ +# Graphics / `nxwidgets` NXWidgets + +In order to better support NuttX based platforms, a special graphical user +interface has been created called NXWidgets. NXWidgets is written in C++ and +integrates seamlessly with the NuttX NX graphics subsystem in order to provide +graphic objects, or _widgets_, in the NX Graphics Subsystem + +Some of the features of NXWidgets include: + +- Conservative C++ + + NXWidgets is written entirely in C++ but using only selected _embedded + friendly_ C++ constructs that are fully supported under NuttX. No additional + C++ support libraries are required. + +- NX Integration + + NXWidgets integrate seamlessly with the NX graphics system. Think of the X + server under Linux โ€“ the NX graphics system is like a tiny X server that + provides windowing under NuttX. By adding NXWidgets, you can support graphics + objects like buttons and text boxes in the NX windows and toolbars. + +- Small Footprint + + NXWidgets is tailored for use MCUs in embedded applications. It is ideally + suited for mid- and upper-range of most MCU families. A complete NXWidgets is + possible in as little as 40Kb of FLASH and maybe 4Kb of SRAM. + +- Output Devices + + NXWidgets will work on the high-end frame buffer devices as well as on LCDs + connected via serial or parallel ports to a small MCU. + +- Input Devices + + NXWidgets will accept position and selection inputs from a mouse or a + touchscreen. It will also support character input from a keyboard such as a + USB keyboard. NXWidgets supports on very special widget called `CKeypad` that + will provide keyboard input via an on-screen keypad that can be operated via + mouse or touchscreen inputs. + +- Many Graphic Objects + + Some of the graphic objects supported by NXWidgets include labels, buttons, + text boxes, button arrays, check boxes, cycle buttons, images, sliders, + scrollable list boxes, progress bars, and more. + +**Note**: Many of the fundamental classed in NxWidgets derive from the Antony +Dzeryn's _Woopsi_ project: http://woopsi.org/ which also has a BSD style +license. See the `COPYING` file for details. + +## Directory Structure + +- `Kconfig` + + This is a `Kconfig` file that should be provided at `apps/NxWidgets/Kconfig`. + When copied to that location, it will be used by the NuttX configuration + systems to configure settings for NxWidgets and NxWM + +- `nxwidgets` + + The source code, header files, and build environment for NxWidgets is provided + in this directory. + +- `UnitTests` + + Provides a collection of unit-level tests for many of the individual widgets + provided by `nxwidgets`. diff --git a/graphics/nxwidgets/UnitTests/CButton/Make.defs b/graphics/nxwidgets/UnitTests/CButton/Make.defs index 1c2885584..a3dfda908 100644 --- a/graphics/nxwidgets/UnitTests/CButton/Make.defs +++ b/graphics/nxwidgets/UnitTests/CButton/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/graphics/nxwidgets/UnitTests/CButton/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwidgets/UnitTests/CButton/Makefile b/graphics/nxwidgets/UnitTests/CButton/Makefile index 6db8eb923..cfefa0906 100644 --- a/graphics/nxwidgets/UnitTests/CButton/Makefile +++ b/graphics/nxwidgets/UnitTests/CButton/Makefile @@ -1,7 +1,5 @@ ################################################################################# -# apps/graphics/nxwidgets/UnitTests/CButton/Makefile -# -# SPDX-License-Identifier: Apache-2.0 +# apps/graphics/nxwidgets/Unitests/CButton/Makefile # # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with diff --git a/graphics/nxwidgets/UnitTests/CButton/cbutton_main.cxx b/graphics/nxwidgets/UnitTests/CButton/cbutton_main.cxx index 663048593..cf14ec969 100644 --- a/graphics/nxwidgets/UnitTests/CButton/cbutton_main.cxx +++ b/graphics/nxwidgets/UnitTests/CButton/cbutton_main.cxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/graphics/nxwidgets/UnitTests/CButton/cbutton_main.cxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -29,7 +27,7 @@ #include #include #include -#include +#include #include diff --git a/graphics/nxwidgets/UnitTests/CButton/cbuttontest.cxx b/graphics/nxwidgets/UnitTests/CButton/cbuttontest.cxx index c7628b41a..e53a62d9b 100644 --- a/graphics/nxwidgets/UnitTests/CButton/cbuttontest.cxx +++ b/graphics/nxwidgets/UnitTests/CButton/cbuttontest.cxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/graphics/nxwidgets/UnitTests/CButton/cbuttontest.cxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -29,7 +27,7 @@ #include #include #include -#include +#include #include #include @@ -66,9 +64,9 @@ CButtonTest::CButtonTest() { - m_bgWindow = NULL; - m_nxFont = NULL; - m_text = NULL; + m_bgWindow = (CBgWindow *)NULL; + m_nxFont = (CNxFont *)NULL; + m_text = (CNxString *)NULL; } // CButtonTest Descriptor @@ -124,7 +122,7 @@ void CButtonTest::disconnect(void) if (m_text) { delete m_text; - m_text = NULL; + m_text = (CNxString *)NULL; } // Free the default font @@ -132,7 +130,7 @@ void CButtonTest::disconnect(void) if (m_nxFont) { delete m_nxFont; - m_nxFont = NULL; + m_nxFont = (CNxFont *)NULL; } // And disconnect from the server @@ -156,7 +154,7 @@ bool CButtonTest::createWindow(void) { // Initialize the widget control using the default style - m_widgetControl = new CWidgetControl(NULL); + m_widgetControl = new CWidgetControl((CWidgetStyle *)NULL); // Get an (uninitialized) instance of the background window as a class // that derives from INxWindow. @@ -193,7 +191,7 @@ CButton *CButtonTest::createButton(FAR const char *text) if (!m_bgWindow->getSize(&windowSize)) { printf("CButtonTest::createGraphics: Failed to get window size\n"); - return NULL; + return (CButton *)NULL; } // Create a CNxString instance to contain the C string diff --git a/graphics/nxwidgets/UnitTests/CButton/cbuttontest.hxx b/graphics/nxwidgets/UnitTests/CButton/cbuttontest.hxx index 608e77929..214274df2 100644 --- a/graphics/nxwidgets/UnitTests/CButton/cbuttontest.hxx +++ b/graphics/nxwidgets/UnitTests/CButton/cbuttontest.hxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/graphics/nxwidgets/UnitTests/CButton/cbuttontest.hxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -32,7 +30,7 @@ #include #include #include -#include +#include #include diff --git a/graphics/nxwidgets/UnitTests/CButtonArray/Make.defs b/graphics/nxwidgets/UnitTests/CButtonArray/Make.defs index a08aa2842..c1d6130ae 100644 --- a/graphics/nxwidgets/UnitTests/CButtonArray/Make.defs +++ b/graphics/nxwidgets/UnitTests/CButtonArray/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/graphics/nxwidgets/UnitTests/CButtonArray/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwidgets/UnitTests/CButtonArray/Makefile b/graphics/nxwidgets/UnitTests/CButtonArray/Makefile index b8870c51f..1fe25c656 100644 --- a/graphics/nxwidgets/UnitTests/CButtonArray/Makefile +++ b/graphics/nxwidgets/UnitTests/CButtonArray/Makefile @@ -1,8 +1,6 @@ ################################################################################# # apps/graphics/nxwidgets/UnitTests/CButtonArray/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwidgets/UnitTests/CButtonArray/cbuttonarray_main.cxx b/graphics/nxwidgets/UnitTests/CButtonArray/cbuttonarray_main.cxx index 51a09a16c..13692fa70 100644 --- a/graphics/nxwidgets/UnitTests/CButtonArray/cbuttonarray_main.cxx +++ b/graphics/nxwidgets/UnitTests/CButtonArray/cbuttonarray_main.cxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/graphics/nxwidgets/UnitTests/CButtonArray/cbuttonarray_main.cxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -31,7 +29,7 @@ #include #include #include -#include +#include #include diff --git a/graphics/nxwidgets/UnitTests/CButtonArray/cbuttonarraytest.cxx b/graphics/nxwidgets/UnitTests/CButtonArray/cbuttonarraytest.cxx index e84caf02f..d2a661f08 100644 --- a/graphics/nxwidgets/UnitTests/CButtonArray/cbuttonarraytest.cxx +++ b/graphics/nxwidgets/UnitTests/CButtonArray/cbuttonarraytest.cxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/graphics/nxwidgets/UnitTests/CButtonArray/cbuttonarraytest.cxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -29,7 +27,7 @@ #include #include #include -#include +#include #include #include @@ -66,8 +64,8 @@ CButtonArrayTest::CButtonArrayTest() { - m_widgetControl = NULL; - m_bgWindow = NULL; + m_widgetControl = (CWidgetControl *)NULL; + m_bgWindow = (CBgWindow *)NULL; } // CButtonArrayTest Descriptor @@ -136,7 +134,7 @@ bool CButtonArrayTest::createWindow(void) { // Initialize the widget control using the default style - m_widgetControl = new CWidgetControl(NULL); + m_widgetControl = new CWidgetControl((CWidgetStyle *)NULL); // Get an (uninitialized) instance of the background window as a class // that derives from INxWindow. @@ -173,7 +171,7 @@ CButtonArray *CButtonArrayTest::createButtonArray(void) if (!m_bgWindow->getSize(&windowSize)) { printf("CButtonArrayTest::createGraphics: Failed to get window size\n"); - return NULL; + return (CButtonArray *)NULL; } // Pick an X/Y position such that the button array will be centered in the display diff --git a/graphics/nxwidgets/UnitTests/CButtonArray/cbuttonarraytest.hxx b/graphics/nxwidgets/UnitTests/CButtonArray/cbuttonarraytest.hxx index 0d69a2838..ccd027755 100644 --- a/graphics/nxwidgets/UnitTests/CButtonArray/cbuttonarraytest.hxx +++ b/graphics/nxwidgets/UnitTests/CButtonArray/cbuttonarraytest.hxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/graphics/nxwidgets/UnitTests/CButtonArray/cbuttonarraytest.hxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -32,7 +30,7 @@ #include #include #include -#include +#include #include diff --git a/graphics/nxwidgets/UnitTests/CCheckBox/Make.defs b/graphics/nxwidgets/UnitTests/CCheckBox/Make.defs index be552f0a7..f79a8e198 100644 --- a/graphics/nxwidgets/UnitTests/CCheckBox/Make.defs +++ b/graphics/nxwidgets/UnitTests/CCheckBox/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/graphics/nxwidgets/UnitTests/CCheckBox/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwidgets/UnitTests/CCheckBox/Makefile b/graphics/nxwidgets/UnitTests/CCheckBox/Makefile index bbc55255e..0c244e7be 100644 --- a/graphics/nxwidgets/UnitTests/CCheckBox/Makefile +++ b/graphics/nxwidgets/UnitTests/CCheckBox/Makefile @@ -1,8 +1,6 @@ ################################################################################# # apps/graphics/nxwidgets/UnitTests/CCheckBox/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwidgets/UnitTests/CCheckBox/ccheckbox_main.cxx b/graphics/nxwidgets/UnitTests/CCheckBox/ccheckbox_main.cxx index 087e31499..a4dd417c4 100644 --- a/graphics/nxwidgets/UnitTests/CCheckBox/ccheckbox_main.cxx +++ b/graphics/nxwidgets/UnitTests/CCheckBox/ccheckbox_main.cxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/graphics/nxwidgets/UnitTests/CCheckBox/ccheckbox_main.cxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -32,7 +30,7 @@ #include #include #include -#include +#include #include diff --git a/graphics/nxwidgets/UnitTests/CCheckBox/ccheckboxtest.cxx b/graphics/nxwidgets/UnitTests/CCheckBox/ccheckboxtest.cxx index 8f8398324..cc89ba3cd 100644 --- a/graphics/nxwidgets/UnitTests/CCheckBox/ccheckboxtest.cxx +++ b/graphics/nxwidgets/UnitTests/CCheckBox/ccheckboxtest.cxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/graphics/nxwidgets/UnitTests/CCheckBox/ccheckboxtest.cxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -29,7 +27,7 @@ #include #include #include -#include +#include #include #include @@ -70,9 +68,9 @@ CCheckBoxTest::CCheckBoxTest() { // Initialize state data - m_widgetControl = NULL; - m_bgWindow = NULL; - m_checkBox = NULL; + m_widgetControl = (CWidgetControl *)NULL; + m_bgWindow = (CBgWindow *)NULL; + m_checkBox = (CCheckBox *)NULL; } // CCheckBoxTest Descriptor @@ -111,7 +109,7 @@ void CCheckBoxTest::disconnect(void) if (m_checkBox) { delete m_checkBox; - m_checkBox = NULL; + m_checkBox = (CCheckBox *)NULL; } // Close the window @@ -119,7 +117,7 @@ void CCheckBoxTest::disconnect(void) if (m_bgWindow) { delete m_bgWindow; - m_bgWindow = NULL; + m_bgWindow = (CBgWindow *)NULL; } // Free the widget control instance @@ -127,7 +125,7 @@ void CCheckBoxTest::disconnect(void) if (m_widgetControl) { delete m_widgetControl; - m_widgetControl = NULL; + m_widgetControl = (CWidgetControl *)NULL; } // And disconnect from the server @@ -151,7 +149,7 @@ bool CCheckBoxTest::createWindow(void) { // Initialize the widget control using the default style - m_widgetControl = new CWidgetControl(NULL); + m_widgetControl = new CWidgetControl((CWidgetStyle *)NULL); // Get an (uninitialized) instance of the background window as a class // that derives from INxWindow. @@ -195,7 +193,7 @@ bool CCheckBoxTest::createWindow(void) // Create the checkbox m_checkBox = new CCheckBox(m_widgetControl, checkboxX, checkboxY, - width, height, NULL); + width, height, (CWidgetStyle *)NULL); if (!m_checkBox) { printf("CCheckBoxTest::createWindow: Failed to create CCheckBox\n"); diff --git a/graphics/nxwidgets/UnitTests/CCheckBox/ccheckboxtest.hxx b/graphics/nxwidgets/UnitTests/CCheckBox/ccheckboxtest.hxx index 205884f47..eb708b372 100644 --- a/graphics/nxwidgets/UnitTests/CCheckBox/ccheckboxtest.hxx +++ b/graphics/nxwidgets/UnitTests/CCheckBox/ccheckboxtest.hxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/graphics/nxwidgets/UnitTests/CCheckBox/ccheckboxtest.hxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -32,7 +30,7 @@ #include #include #include -#include +#include #include diff --git a/graphics/nxwidgets/UnitTests/CGlyphButton/Make.defs b/graphics/nxwidgets/UnitTests/CGlyphButton/Make.defs index bbc695233..09d2c8583 100644 --- a/graphics/nxwidgets/UnitTests/CGlyphButton/Make.defs +++ b/graphics/nxwidgets/UnitTests/CGlyphButton/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/graphics/nxwidgets/UnitTests/CGlyphButton/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwidgets/UnitTests/CGlyphButton/Makefile b/graphics/nxwidgets/UnitTests/CGlyphButton/Makefile index 409fdff79..d1668f163 100644 --- a/graphics/nxwidgets/UnitTests/CGlyphButton/Makefile +++ b/graphics/nxwidgets/UnitTests/CGlyphButton/Makefile @@ -1,8 +1,6 @@ ################################################################################# # apps/graphics/nxwidgets/UnitTests/CGlyphButton/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwidgets/UnitTests/CGlyphButton/cglyphbutton_main.cxx b/graphics/nxwidgets/UnitTests/CGlyphButton/cglyphbutton_main.cxx index 01081b38e..f08da13e0 100644 --- a/graphics/nxwidgets/UnitTests/CGlyphButton/cglyphbutton_main.cxx +++ b/graphics/nxwidgets/UnitTests/CGlyphButton/cglyphbutton_main.cxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/graphics/nxwidgets/UnitTests/CGlyphButton/cglyphbutton_main.cxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -32,7 +30,7 @@ #include #include #include -#include +#include #include diff --git a/graphics/nxwidgets/UnitTests/CGlyphButton/cglyphbuttontest.cxx b/graphics/nxwidgets/UnitTests/CGlyphButton/cglyphbuttontest.cxx index acee748fa..738964ace 100644 --- a/graphics/nxwidgets/UnitTests/CGlyphButton/cglyphbuttontest.cxx +++ b/graphics/nxwidgets/UnitTests/CGlyphButton/cglyphbuttontest.cxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/graphics/nxwidgets/UnitTests/CGlyphButton/cglyphbuttontest.cxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -29,7 +27,7 @@ #include #include #include -#include +#include #include #include @@ -66,8 +64,8 @@ CGlyphButtonTest::CGlyphButtonTest() { - m_widgetControl = NULL; - m_bgWindow = NULL; + m_widgetControl = (CWidgetControl *)NULL; + m_bgWindow = (CBgWindow *)NULL; m_center.x = 0; m_center.y = 0; } @@ -138,7 +136,7 @@ bool CGlyphButtonTest::createWindow(void) { // Initialize the widget control using the default style - m_widgetControl = new CWidgetControl(NULL); + m_widgetControl = new CWidgetControl((CWidgetStyle *)NULL); // Get an (uninitialized) instance of the background window as a class // that derives from INxWindow. @@ -176,7 +174,7 @@ CGlyphButton *CGlyphButtonTest::createButton(FAR const struct SBitmap *clickGlyp if (!m_bgWindow->getSize(&windowSize)) { printf("CGlyphButtonTest::createGraphics: Failed to get window size\n"); - return NULL; + return (CGlyphButton *)NULL; } // Get the height and width of the glyph display area diff --git a/graphics/nxwidgets/UnitTests/CGlyphButton/cglyphbuttontest.hxx b/graphics/nxwidgets/UnitTests/CGlyphButton/cglyphbuttontest.hxx index 89884872f..3686b9810 100644 --- a/graphics/nxwidgets/UnitTests/CGlyphButton/cglyphbuttontest.hxx +++ b/graphics/nxwidgets/UnitTests/CGlyphButton/cglyphbuttontest.hxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/graphics/nxwidgets/UnitTests/CGlyphButton/cglyphbuttontest.hxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -32,8 +30,7 @@ #include #include #include -#include -#include +#include #include @@ -64,6 +61,12 @@ # define CONFIG_CGLYPHBUTTONTEST_FONTCOLOR CONFIG_NXWIDGETS_DEFAULT_FONTCOLOR #endif +// Helper macros + +#ifndef MAX +# define MAX(a,b) ((a) > (b) ? (a) : (b)) +#endif + ///////////////////////////////////////////////////////////////////////////// // Public Classes ///////////////////////////////////////////////////////////////////////////// diff --git a/graphics/nxwidgets/UnitTests/CGlyphSliderHorizontal/Make.defs b/graphics/nxwidgets/UnitTests/CGlyphSliderHorizontal/Make.defs index 36bdeb7b2..a9bf1b3e9 100644 --- a/graphics/nxwidgets/UnitTests/CGlyphSliderHorizontal/Make.defs +++ b/graphics/nxwidgets/UnitTests/CGlyphSliderHorizontal/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/graphics/nxwidgets/UnitTests/CGlyphSliderHorizontal/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwidgets/UnitTests/CGlyphSliderHorizontal/Makefile b/graphics/nxwidgets/UnitTests/CGlyphSliderHorizontal/Makefile index 19426bb02..349e18d5d 100644 --- a/graphics/nxwidgets/UnitTests/CGlyphSliderHorizontal/Makefile +++ b/graphics/nxwidgets/UnitTests/CGlyphSliderHorizontal/Makefile @@ -1,8 +1,6 @@ ################################################################################# # apps/graphics/nxwidgets/UnitTests/CGlyphSliderHorizontal/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwidgets/UnitTests/CGlyphSliderHorizontal/cglyphsliderhorizontal_main.cxx b/graphics/nxwidgets/UnitTests/CGlyphSliderHorizontal/cglyphsliderhorizontal_main.cxx index 59546fa73..c3bfa04c9 100644 --- a/graphics/nxwidgets/UnitTests/CGlyphSliderHorizontal/cglyphsliderhorizontal_main.cxx +++ b/graphics/nxwidgets/UnitTests/CGlyphSliderHorizontal/cglyphsliderhorizontal_main.cxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/graphics/nxwidgets/UnitTests/CGlyphSliderHorizontal/cglyphsliderhorizontal_main.cxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -32,7 +30,7 @@ #include #include #include -#include +#include #include diff --git a/graphics/nxwidgets/UnitTests/CGlyphSliderHorizontal/cglyphsliderhorizontaltest.cxx b/graphics/nxwidgets/UnitTests/CGlyphSliderHorizontal/cglyphsliderhorizontaltest.cxx index a9e38f00a..60f53ee3b 100644 --- a/graphics/nxwidgets/UnitTests/CGlyphSliderHorizontal/cglyphsliderhorizontaltest.cxx +++ b/graphics/nxwidgets/UnitTests/CGlyphSliderHorizontal/cglyphsliderhorizontaltest.cxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/graphics/nxwidgets/UnitTests/CGlyphSliderHorizontal/cglyphsliderhorizontaltest.cxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -29,7 +27,7 @@ #include #include #include -#include +#include #include #include @@ -114,8 +112,8 @@ CGlyphSliderHorizontalTest::CGlyphSliderHorizontalTest() { // Initialize state data - m_widgetControl = NULL; - m_bgWindow = NULL; + m_widgetControl = (CWidgetControl *)NULL; + m_bgWindow = (CBgWindow *)NULL; } // CGlyphSliderHorizontalTest Descriptor @@ -154,7 +152,7 @@ void CGlyphSliderHorizontalTest::disconnect(void) if (m_bgWindow) { delete m_bgWindow; - m_bgWindow = NULL; + m_bgWindow = (CBgWindow *)NULL; } // Free the widget control instance @@ -162,7 +160,7 @@ void CGlyphSliderHorizontalTest::disconnect(void) if (m_widgetControl) { delete m_widgetControl; - m_widgetControl = NULL; + m_widgetControl = (CWidgetControl *)NULL; } // And disconnect from the server @@ -186,7 +184,7 @@ bool CGlyphSliderHorizontalTest::createWindow(void) { // Initialize the widget control using the default style - m_widgetControl = new CWidgetControl(NULL); + m_widgetControl = new CWidgetControl((CWidgetStyle *)NULL); // Get an (uninitialized) instance of the background window as a class // that derives from INxWindow. diff --git a/graphics/nxwidgets/UnitTests/CGlyphSliderHorizontal/cglyphsliderhorizontaltest.hxx b/graphics/nxwidgets/UnitTests/CGlyphSliderHorizontal/cglyphsliderhorizontaltest.hxx index 0d563eecb..30e1afb49 100644 --- a/graphics/nxwidgets/UnitTests/CGlyphSliderHorizontal/cglyphsliderhorizontaltest.hxx +++ b/graphics/nxwidgets/UnitTests/CGlyphSliderHorizontal/cglyphsliderhorizontaltest.hxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/graphics/nxwidgets/UnitTests/CGlyphSliderHorizontal/cglyphsliderhorizontaltest.hxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -32,7 +30,7 @@ #include #include #include -#include +#include #include diff --git a/graphics/nxwidgets/UnitTests/CImage/Make.defs b/graphics/nxwidgets/UnitTests/CImage/Make.defs index a17112fab..44488e48f 100644 --- a/graphics/nxwidgets/UnitTests/CImage/Make.defs +++ b/graphics/nxwidgets/UnitTests/CImage/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/graphics/nxwidgets/UnitTests/CImage/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwidgets/UnitTests/CImage/Makefile b/graphics/nxwidgets/UnitTests/CImage/Makefile index af2250543..2f4ee9fe7 100644 --- a/graphics/nxwidgets/UnitTests/CImage/Makefile +++ b/graphics/nxwidgets/UnitTests/CImage/Makefile @@ -1,8 +1,6 @@ ################################################################################# # apps/graphics/nxwidgets/UnitTests/CImage/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwidgets/UnitTests/CImage/cimage_main.cxx b/graphics/nxwidgets/UnitTests/CImage/cimage_main.cxx index 339627a74..fc5e29b15 100644 --- a/graphics/nxwidgets/UnitTests/CImage/cimage_main.cxx +++ b/graphics/nxwidgets/UnitTests/CImage/cimage_main.cxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/graphics/nxwidgets/UnitTests/CImage/cimage_main.cxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -32,7 +30,7 @@ #include #include #include -#include +#include #include diff --git a/graphics/nxwidgets/UnitTests/CImage/cimagetest.cxx b/graphics/nxwidgets/UnitTests/CImage/cimagetest.cxx index 9eedd8aa4..a41ca14d3 100644 --- a/graphics/nxwidgets/UnitTests/CImage/cimagetest.cxx +++ b/graphics/nxwidgets/UnitTests/CImage/cimagetest.cxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/graphics/nxwidgets/UnitTests/CImage/cimagetest.cxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -29,7 +27,7 @@ #include #include #include -#include +#include #include #include @@ -67,8 +65,8 @@ CImageTest::CImageTest() { - m_widgetControl = NULL; - m_bgWindow = NULL; + m_widgetControl = (CWidgetControl *)NULL; + m_bgWindow = (CBgWindow *)NULL; } // CImageTest Descriptor @@ -137,7 +135,7 @@ bool CImageTest::createWindow(void) { // Initialize the widget control using the default style - m_widgetControl = new CWidgetControl(NULL); + m_widgetControl = new CWidgetControl((CWidgetStyle *)NULL); // Get an (uninitialized) instance of the background window as a class // that derives from INxWindow. @@ -174,7 +172,7 @@ CImage *CImageTest::createImage(IBitmap *bitmap) if (!m_bgWindow->getSize(&windowSize)) { printf("CImageTest::createGraphics: Failed to get window size\n"); - return NULL; + return (CImage *)NULL; } // Get the height and width of the image diff --git a/graphics/nxwidgets/UnitTests/CImage/cimagetest.hxx b/graphics/nxwidgets/UnitTests/CImage/cimagetest.hxx index 99970b6f1..d76abe4a9 100644 --- a/graphics/nxwidgets/UnitTests/CImage/cimagetest.hxx +++ b/graphics/nxwidgets/UnitTests/CImage/cimagetest.hxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/graphics/nxwidgets/UnitTests/CImage/cimagetest.hxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -32,7 +30,7 @@ #include #include #include -#include +#include #include diff --git a/graphics/nxwidgets/UnitTests/CKeypad/Make.defs b/graphics/nxwidgets/UnitTests/CKeypad/Make.defs index fa0175319..3896547c6 100644 --- a/graphics/nxwidgets/UnitTests/CKeypad/Make.defs +++ b/graphics/nxwidgets/UnitTests/CKeypad/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/graphics/nxwidgets/UnitTests/CKeypad/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwidgets/UnitTests/CKeypad/Makefile b/graphics/nxwidgets/UnitTests/CKeypad/Makefile index 44796a4c3..4dab8d6f5 100644 --- a/graphics/nxwidgets/UnitTests/CKeypad/Makefile +++ b/graphics/nxwidgets/UnitTests/CKeypad/Makefile @@ -1,7 +1,5 @@ ################################################################################# -# apps/graphics/nxwidgets/UnitTests/CKeypad/Makefile -# -# SPDX-License-Identifier: Apache-2.0 +# apps/graphics/nxwidgets/UnitTests/CKeyPad/Makefile # # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with diff --git a/graphics/nxwidgets/UnitTests/CKeypad/ckeypad_main.cxx b/graphics/nxwidgets/UnitTests/CKeypad/ckeypad_main.cxx index 9e9d4b269..a20fca694 100644 --- a/graphics/nxwidgets/UnitTests/CKeypad/ckeypad_main.cxx +++ b/graphics/nxwidgets/UnitTests/CKeypad/ckeypad_main.cxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/graphics/nxwidgets/UnitTests/CKeypad/ckeypad_main.cxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -31,7 +29,7 @@ #include #include #include -#include +#include #include diff --git a/graphics/nxwidgets/UnitTests/CKeypad/ckeypadtest.cxx b/graphics/nxwidgets/UnitTests/CKeypad/ckeypadtest.cxx index a51555e44..70abea0cc 100644 --- a/graphics/nxwidgets/UnitTests/CKeypad/ckeypadtest.cxx +++ b/graphics/nxwidgets/UnitTests/CKeypad/ckeypadtest.cxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/graphics/nxwidgets/UnitTests/CKeypad/ckeypadtest.cxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -29,7 +27,7 @@ #include #include #include -#include +#include #include #include @@ -69,8 +67,8 @@ CKeypadTest::CKeypadTest() { - m_widgetControl = NULL; - m_bgWindow = NULL; + m_widgetControl = (CWidgetControl *)NULL; + m_bgWindow = (CBgWindow *)NULL; m_buttonWidth = 0; m_buttonHeight = 0; m_displayHeight = 0; @@ -149,7 +147,7 @@ bool CKeypadTest::createWindow(void) { // Initialize the widget control using the default style - m_widgetControl = new CWidgetControl(NULL); + m_widgetControl = new CWidgetControl((CWidgetStyle *)NULL); // Get an (uninitialized) instance of the background window as a class // that derives from INxWindow. @@ -236,7 +234,7 @@ CKeypad *CKeypadTest::createKeypad(void) if (!m_bgWindow->getSize(&windowSize)) { printf("CKeypadTest::createGraphics: Failed to get window size\n"); - return NULL; + return (CKeypad *)NULL; } // Pick a height and width. Here we use inside information that the number @@ -264,7 +262,7 @@ CKeypad *CKeypadTest::createKeypad(void) if (!m_textbox) { delete keypad; - keypad = NULL; + keypad = (CKeypad *)NULL; } else { @@ -296,7 +294,7 @@ CTextBox *CKeypadTest::createTextBox(void) if (!m_bgWindow->getSize(&windowSize)) { printf("CKeypadTest::createGraphics: Failed to get window size\n"); - return NULL; + return (CTextBox *)NULL; } // Pick a height and width. Here we use inside information that the number diff --git a/graphics/nxwidgets/UnitTests/CKeypad/ckeypadtest.hxx b/graphics/nxwidgets/UnitTests/CKeypad/ckeypadtest.hxx index 783fb0b52..97504a59e 100644 --- a/graphics/nxwidgets/UnitTests/CKeypad/ckeypadtest.hxx +++ b/graphics/nxwidgets/UnitTests/CKeypad/ckeypadtest.hxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/graphics/nxwidgets/UnitTests/CKeypad/ckeypadtest.hxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -32,7 +30,7 @@ #include #include #include -#include +#include #include diff --git a/graphics/nxwidgets/UnitTests/CLabel/Make.defs b/graphics/nxwidgets/UnitTests/CLabel/Make.defs index be0a9e9c6..e0c348020 100644 --- a/graphics/nxwidgets/UnitTests/CLabel/Make.defs +++ b/graphics/nxwidgets/UnitTests/CLabel/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/graphics/nxwidgets/UnitTests/CLabel/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwidgets/UnitTests/CLabel/Makefile b/graphics/nxwidgets/UnitTests/CLabel/Makefile index 3e9dd9111..377744eaa 100644 --- a/graphics/nxwidgets/UnitTests/CLabel/Makefile +++ b/graphics/nxwidgets/UnitTests/CLabel/Makefile @@ -1,8 +1,6 @@ ################################################################################# # apps/graphics/nxwidgets/UnitTests/CLabel/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwidgets/UnitTests/CLabel/clabel_main.cxx b/graphics/nxwidgets/UnitTests/CLabel/clabel_main.cxx index c822abf1a..833eae154 100644 --- a/graphics/nxwidgets/UnitTests/CLabel/clabel_main.cxx +++ b/graphics/nxwidgets/UnitTests/CLabel/clabel_main.cxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/graphics/nxwidgets/UnitTests/CLabel/clabel_main.cxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -29,7 +27,7 @@ #include #include #include -#include +#include #include diff --git a/graphics/nxwidgets/UnitTests/CLabel/clabeltest.cxx b/graphics/nxwidgets/UnitTests/CLabel/clabeltest.cxx index 1b439125f..068b3b2a2 100644 --- a/graphics/nxwidgets/UnitTests/CLabel/clabeltest.cxx +++ b/graphics/nxwidgets/UnitTests/CLabel/clabeltest.cxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/graphics/nxwidgets/UnitTests/CLabel/clabeltest.cxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -29,7 +27,7 @@ #include #include #include -#include +#include #include #include @@ -66,9 +64,9 @@ CLabelTest::CLabelTest() { - m_bgWindow = NULL; - m_nxFont = NULL; - m_text = NULL; + m_bgWindow = (CBgWindow *)NULL; + m_nxFont = (CNxFont *)NULL; + m_text = (CNxString *)NULL; } // CLabelTest Descriptor @@ -124,7 +122,7 @@ void CLabelTest::disconnect(void) if (m_text) { delete m_text; - m_text = NULL; + m_text = (CNxString *)NULL; } // Free the default font @@ -132,7 +130,7 @@ void CLabelTest::disconnect(void) if (m_nxFont) { delete m_nxFont; - m_nxFont = NULL; + m_nxFont = (CNxFont *)NULL; } // And disconnect from the server @@ -156,7 +154,7 @@ bool CLabelTest::createWindow(void) { // Initialize the widget control using the default style - m_widgetControl = new CWidgetControl(NULL); + m_widgetControl = new CWidgetControl((CWidgetStyle *)NULL); // Get an (uninitialized) instance of the background window as a class // that derives from INxWindow. @@ -193,7 +191,7 @@ CLabel *CLabelTest::createLabel(FAR const char *text) if (!m_bgWindow->getSize(&windowSize)) { printf("CLabelTest::createGraphics: Failed to get window size\n"); - return NULL; + return (CLabel *)NULL; } // Create a CNxString instance to contain the C string diff --git a/graphics/nxwidgets/UnitTests/CLabel/clabeltest.hxx b/graphics/nxwidgets/UnitTests/CLabel/clabeltest.hxx index 317a08bec..9d4b55d76 100644 --- a/graphics/nxwidgets/UnitTests/CLabel/clabeltest.hxx +++ b/graphics/nxwidgets/UnitTests/CLabel/clabeltest.hxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/graphics/nxwidgets/UnitTests/CLabel/clabeltest.hxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -32,7 +30,7 @@ #include #include #include -#include +#include #include diff --git a/graphics/nxwidgets/UnitTests/CLatchButton/Make.defs b/graphics/nxwidgets/UnitTests/CLatchButton/Make.defs index a7a894228..727e09575 100644 --- a/graphics/nxwidgets/UnitTests/CLatchButton/Make.defs +++ b/graphics/nxwidgets/UnitTests/CLatchButton/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/graphics/nxwidgets/UnitTests/CLatchButton/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwidgets/UnitTests/CLatchButton/Makefile b/graphics/nxwidgets/UnitTests/CLatchButton/Makefile index be605df19..1022ce33b 100644 --- a/graphics/nxwidgets/UnitTests/CLatchButton/Makefile +++ b/graphics/nxwidgets/UnitTests/CLatchButton/Makefile @@ -1,8 +1,6 @@ ################################################################################# # apps/graphics/nxwidgets/UnitTests/CLatchButton/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwidgets/UnitTests/CLatchButton/clatchbutton_main.cxx b/graphics/nxwidgets/UnitTests/CLatchButton/clatchbutton_main.cxx index 0663f74c3..80401c6dc 100644 --- a/graphics/nxwidgets/UnitTests/CLatchButton/clatchbutton_main.cxx +++ b/graphics/nxwidgets/UnitTests/CLatchButton/clatchbutton_main.cxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/graphics/nxwidgets/UnitTests/CLatchButton/clatchbutton_main.cxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -29,7 +27,7 @@ #include #include #include -#include +#include #include diff --git a/graphics/nxwidgets/UnitTests/CLatchButton/clatchbuttontest.cxx b/graphics/nxwidgets/UnitTests/CLatchButton/clatchbuttontest.cxx index a8dbe2603..e1b4ecf4f 100644 --- a/graphics/nxwidgets/UnitTests/CLatchButton/clatchbuttontest.cxx +++ b/graphics/nxwidgets/UnitTests/CLatchButton/clatchbuttontest.cxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/graphics/nxwidgets/UnitTests/CLatchButton/clatchbuttontest.cxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -29,7 +27,7 @@ #include #include #include -#include +#include #include #include @@ -66,9 +64,9 @@ CLatchButtonTest::CLatchButtonTest() { - m_bgWindow = NULL; - m_nxFont = NULL; - m_text = NULL; + m_bgWindow = (CBgWindow *)NULL; + m_nxFont = (CNxFont *)NULL; + m_text = (CNxString *)NULL; } // CLatchButtonTest Descriptor @@ -124,7 +122,7 @@ void CLatchButtonTest::disconnect(void) if (m_text) { delete m_text; - m_text = NULL; + m_text = (CNxString *)NULL; } // Free the default font @@ -132,7 +130,7 @@ void CLatchButtonTest::disconnect(void) if (m_nxFont) { delete m_nxFont; - m_nxFont = NULL; + m_nxFont = (CNxFont *)NULL; } // And disconnect from the server @@ -156,7 +154,7 @@ bool CLatchButtonTest::createWindow(void) { // Initialize the widget control using the default style - m_widgetControl = new CWidgetControl(NULL); + m_widgetControl = new CWidgetControl((CWidgetStyle *)NULL); // Get an (uninitialized) instance of the background window as a class // that derives from INxWindow. @@ -193,7 +191,7 @@ CLatchButton *CLatchButtonTest::createButton(FAR const char *text) if (!m_bgWindow->getSize(&windowSize)) { printf("CLatchButtonTest::createGraphics: Failed to get window size\n"); - return NULL; + return (CLatchButton *)NULL; } // Create a CNxString instance to contain the C string diff --git a/graphics/nxwidgets/UnitTests/CLatchButton/clatchbuttontest.hxx b/graphics/nxwidgets/UnitTests/CLatchButton/clatchbuttontest.hxx index 641ccb9ec..5faac6afe 100644 --- a/graphics/nxwidgets/UnitTests/CLatchButton/clatchbuttontest.hxx +++ b/graphics/nxwidgets/UnitTests/CLatchButton/clatchbuttontest.hxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/graphics/nxwidgets/UnitTests/CLatchButton/clatchbuttontest.hxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -32,7 +30,7 @@ #include #include #include -#include +#include #include diff --git a/graphics/nxwidgets/UnitTests/CLatchButtonArray/Make.defs b/graphics/nxwidgets/UnitTests/CLatchButtonArray/Make.defs index 7e6705dc2..9fdb923f6 100644 --- a/graphics/nxwidgets/UnitTests/CLatchButtonArray/Make.defs +++ b/graphics/nxwidgets/UnitTests/CLatchButtonArray/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/graphics/nxwidgets/UnitTests/CLatchButtonArray/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwidgets/UnitTests/CLatchButtonArray/Makefile b/graphics/nxwidgets/UnitTests/CLatchButtonArray/Makefile index 2909a9e2a..12b896268 100644 --- a/graphics/nxwidgets/UnitTests/CLatchButtonArray/Makefile +++ b/graphics/nxwidgets/UnitTests/CLatchButtonArray/Makefile @@ -1,8 +1,6 @@ ################################################################################# # apps/graphics/nxwidgets/UnitTests/CLatchButtonArray/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwidgets/UnitTests/CLatchButtonArray/clatchbuttonarray_main.cxx b/graphics/nxwidgets/UnitTests/CLatchButtonArray/clatchbuttonarray_main.cxx index a1e713660..209b6cd09 100644 --- a/graphics/nxwidgets/UnitTests/CLatchButtonArray/clatchbuttonarray_main.cxx +++ b/graphics/nxwidgets/UnitTests/CLatchButtonArray/clatchbuttonarray_main.cxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/graphics/nxwidgets/UnitTests/CLatchButtonArray/clatchbuttonarry_main.cxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -31,7 +29,7 @@ #include #include #include -#include +#include #include diff --git a/graphics/nxwidgets/UnitTests/CLatchButtonArray/clatchbuttonarraytest.cxx b/graphics/nxwidgets/UnitTests/CLatchButtonArray/clatchbuttonarraytest.cxx index 146f9172a..35b7c8c36 100644 --- a/graphics/nxwidgets/UnitTests/CLatchButtonArray/clatchbuttonarraytest.cxx +++ b/graphics/nxwidgets/UnitTests/CLatchButtonArray/clatchbuttonarraytest.cxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/graphics/nxwidgets/UnitTests/CLatchButtonArray/clatchbuttonarraytest.cxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -29,7 +27,7 @@ #include #include #include -#include +#include #include #include @@ -66,8 +64,8 @@ CLatchButtonArrayTest::CLatchButtonArrayTest() { - m_widgetControl = NULL; - m_bgWindow = NULL; + m_widgetControl = (CWidgetControl *)NULL; + m_bgWindow = (CBgWindow *)NULL; } // CLatchButtonArrayTest Descriptor @@ -136,7 +134,7 @@ bool CLatchButtonArrayTest::createWindow(void) { // Initialize the widget control using the default style - m_widgetControl = new CWidgetControl(NULL); + m_widgetControl = new CWidgetControl((CWidgetStyle *)NULL); // Get an (uninitialized) instance of the background window as a class // that derives from INxWindow. @@ -173,7 +171,7 @@ CLatchButtonArray *CLatchButtonArrayTest::createButtonArray(void) if (!m_bgWindow->getSize(&windowSize)) { printf("CLatchButtonArrayTest::createGraphics: Failed to get window size\n"); - return NULL; + return (CLatchButtonArray *)NULL; } // Pick an X/Y position such that the button array will be centered in the display diff --git a/graphics/nxwidgets/UnitTests/CLatchButtonArray/clatchbuttonarraytest.hxx b/graphics/nxwidgets/UnitTests/CLatchButtonArray/clatchbuttonarraytest.hxx index 9ebfed210..e142769e1 100644 --- a/graphics/nxwidgets/UnitTests/CLatchButtonArray/clatchbuttonarraytest.hxx +++ b/graphics/nxwidgets/UnitTests/CLatchButtonArray/clatchbuttonarraytest.hxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/graphics/nxwidgets/UnitTests/CLatchButtonArray/clatchbuttonarraytest.hxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -32,7 +30,7 @@ #include #include #include -#include +#include #include diff --git a/graphics/nxwidgets/UnitTests/CListBox/Make.defs b/graphics/nxwidgets/UnitTests/CListBox/Make.defs index d17218d00..7288cc08a 100644 --- a/graphics/nxwidgets/UnitTests/CListBox/Make.defs +++ b/graphics/nxwidgets/UnitTests/CListBox/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/graphics/nxwidgets/UnitTests/CListBox/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwidgets/UnitTests/CListBox/Makefile b/graphics/nxwidgets/UnitTests/CListBox/Makefile index 961ec066e..56e5e0ea0 100644 --- a/graphics/nxwidgets/UnitTests/CListBox/Makefile +++ b/graphics/nxwidgets/UnitTests/CListBox/Makefile @@ -1,8 +1,6 @@ ################################################################################# # apps/graphics/nxwidgets/UnitTests/CListBox/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwidgets/UnitTests/CListBox/clistbox_main.cxx b/graphics/nxwidgets/UnitTests/CListBox/clistbox_main.cxx index c9bb459ed..07a67312a 100644 --- a/graphics/nxwidgets/UnitTests/CListBox/clistbox_main.cxx +++ b/graphics/nxwidgets/UnitTests/CListBox/clistbox_main.cxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/graphics/nxwidgets/UnitTests/CListBox/clistbox_main.cxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -32,7 +30,7 @@ #include #include #include -#include +#include #include diff --git a/graphics/nxwidgets/UnitTests/CListBox/clistboxtest.cxx b/graphics/nxwidgets/UnitTests/CListBox/clistboxtest.cxx index b81fff628..e2ea577cc 100644 --- a/graphics/nxwidgets/UnitTests/CListBox/clistboxtest.cxx +++ b/graphics/nxwidgets/UnitTests/CListBox/clistboxtest.cxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/graphics/nxwidgets/UnitTests/CListBox/clistboxtest.cxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -29,7 +27,7 @@ #include #include #include -#include +#include #include #include @@ -68,8 +66,8 @@ CListBoxTest::CListBoxTest() { // Initialize state data - m_widgetControl = NULL; - m_bgWindow = NULL; + m_widgetControl = (CWidgetControl *)NULL; + m_bgWindow = (CBgWindow *)NULL; } // CListBoxTest Descriptor @@ -108,7 +106,7 @@ void CListBoxTest::disconnect(void) if (m_bgWindow) { delete m_bgWindow; - m_bgWindow = NULL; + m_bgWindow = (CBgWindow *)NULL; } // Free the widget control instance @@ -116,7 +114,7 @@ void CListBoxTest::disconnect(void) if (m_widgetControl) { delete m_widgetControl; - m_widgetControl = NULL; + m_widgetControl = (CWidgetControl *)NULL; } // And disconnect from the server @@ -140,7 +138,7 @@ bool CListBoxTest::createWindow(void) { // Initialize the widget control using the default style - m_widgetControl = new CWidgetControl(NULL); + m_widgetControl = new CWidgetControl((CWidgetStyle *)NULL); // Get an (uninitialized) instance of the background window as a class // that derives from INxWindow. diff --git a/graphics/nxwidgets/UnitTests/CListBox/clistboxtest.hxx b/graphics/nxwidgets/UnitTests/CListBox/clistboxtest.hxx index 7171c26cd..8f7e11349 100644 --- a/graphics/nxwidgets/UnitTests/CListBox/clistboxtest.hxx +++ b/graphics/nxwidgets/UnitTests/CListBox/clistboxtest.hxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/graphics/nxwidgets/UnitTests/CListBox/clistboxtest.hxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -32,7 +30,7 @@ #include #include #include -#include +#include #include diff --git a/graphics/nxwidgets/UnitTests/CProgressBar/Make.defs b/graphics/nxwidgets/UnitTests/CProgressBar/Make.defs index e77ec2ceb..1b15c62d5 100644 --- a/graphics/nxwidgets/UnitTests/CProgressBar/Make.defs +++ b/graphics/nxwidgets/UnitTests/CProgressBar/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/graphics/nxwidgets/UnitTests/CProgressBar/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwidgets/UnitTests/CProgressBar/Makefile b/graphics/nxwidgets/UnitTests/CProgressBar/Makefile index 3697e365f..21cd0199a 100644 --- a/graphics/nxwidgets/UnitTests/CProgressBar/Makefile +++ b/graphics/nxwidgets/UnitTests/CProgressBar/Makefile @@ -1,8 +1,6 @@ ################################################################################# # apps/graphics/nxwidgets/UnitTests/CProgressBar/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwidgets/UnitTests/CProgressBar/cprogressbar_main.cxx b/graphics/nxwidgets/UnitTests/CProgressBar/cprogressbar_main.cxx index 3df02715f..74ab8b91c 100644 --- a/graphics/nxwidgets/UnitTests/CProgressBar/cprogressbar_main.cxx +++ b/graphics/nxwidgets/UnitTests/CProgressBar/cprogressbar_main.cxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/graphics/nxwidgets/UnitTests/CProgressBar/cprogressbar_main.cxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -32,7 +30,7 @@ #include #include #include -#include +#include #include diff --git a/graphics/nxwidgets/UnitTests/CProgressBar/cprogressbartest.cxx b/graphics/nxwidgets/UnitTests/CProgressBar/cprogressbartest.cxx index 537774ea8..8c8f83aa5 100644 --- a/graphics/nxwidgets/UnitTests/CProgressBar/cprogressbartest.cxx +++ b/graphics/nxwidgets/UnitTests/CProgressBar/cprogressbartest.cxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/graphics/nxwidgets/UnitTests/ProgressBar/cprogressbartest.cxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -29,7 +27,7 @@ #include #include #include -#include +#include #include #include @@ -68,8 +66,8 @@ CProgressBarTest::CProgressBarTest() { // Initialize state data - m_widgetControl = NULL; - m_bgWindow = NULL; + m_widgetControl = (CWidgetControl *)NULL; + m_bgWindow = (CBgWindow *)NULL; } // CProgressBarTest Descriptor @@ -108,7 +106,7 @@ void CProgressBarTest::disconnect(void) if (m_bgWindow) { delete m_bgWindow; - m_bgWindow = NULL; + m_bgWindow = (CBgWindow *)NULL; } // Free the widget control instance @@ -116,7 +114,7 @@ void CProgressBarTest::disconnect(void) if (m_widgetControl) { delete m_widgetControl; - m_widgetControl = NULL; + m_widgetControl = (CWidgetControl *)NULL; } // And disconnect from the server @@ -140,7 +138,7 @@ bool CProgressBarTest::createWindow(void) { // Initialize the widget control using the default style - m_widgetControl = new CWidgetControl(NULL); + m_widgetControl = new CWidgetControl((CWidgetStyle *)NULL); // Get an (uninitialized) instance of the background window as a class // that derives from INxWindow. diff --git a/graphics/nxwidgets/UnitTests/CProgressBar/cprogressbartest.hxx b/graphics/nxwidgets/UnitTests/CProgressBar/cprogressbartest.hxx index 657da3d8e..2cc0f4571 100644 --- a/graphics/nxwidgets/UnitTests/CProgressBar/cprogressbartest.hxx +++ b/graphics/nxwidgets/UnitTests/CProgressBar/cprogressbartest.hxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/graphics/nxwidgets/UnitTests/CProgressBar/cprogressbartest.hxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -32,7 +30,7 @@ #include #include #include -#include +#include #include diff --git a/graphics/nxwidgets/UnitTests/CRadioButton/Make.defs b/graphics/nxwidgets/UnitTests/CRadioButton/Make.defs index dbcd4e559..b98084d70 100644 --- a/graphics/nxwidgets/UnitTests/CRadioButton/Make.defs +++ b/graphics/nxwidgets/UnitTests/CRadioButton/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/graphics/nxwidgets/UnitTests/CRadioButton/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwidgets/UnitTests/CRadioButton/Makefile b/graphics/nxwidgets/UnitTests/CRadioButton/Makefile index af324f188..683c940b8 100644 --- a/graphics/nxwidgets/UnitTests/CRadioButton/Makefile +++ b/graphics/nxwidgets/UnitTests/CRadioButton/Makefile @@ -1,8 +1,6 @@ ################################################################################# # apps/graphics/nxwidgets/UnitTests/CRadioButton/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwidgets/UnitTests/CRadioButton/cradiobutton_main.cxx b/graphics/nxwidgets/UnitTests/CRadioButton/cradiobutton_main.cxx index b093382a1..0953e3441 100644 --- a/graphics/nxwidgets/UnitTests/CRadioButton/cradiobutton_main.cxx +++ b/graphics/nxwidgets/UnitTests/CRadioButton/cradiobutton_main.cxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/graphics/nxwidgets/UnitTests/CRadioButton/cradiobutton_main.cxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -32,7 +30,7 @@ #include #include #include -#include +#include #include diff --git a/graphics/nxwidgets/UnitTests/CRadioButton/cradiobuttontest.cxx b/graphics/nxwidgets/UnitTests/CRadioButton/cradiobuttontest.cxx index 5d0be7bb5..0b3600bf6 100644 --- a/graphics/nxwidgets/UnitTests/CRadioButton/cradiobuttontest.cxx +++ b/graphics/nxwidgets/UnitTests/CRadioButton/cradiobuttontest.cxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/graphics/nxwidgets/UnitTests/CRadioButton/cradiobuttontest.cxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -29,7 +27,7 @@ #include #include #include -#include +#include #include #include @@ -70,8 +68,8 @@ CRadioButtonTest::CRadioButtonTest() { // Initialize state data - m_widgetControl = NULL; - m_bgWindow = NULL; + m_widgetControl = (CWidgetControl *)NULL; + m_bgWindow = (CBgWindow *)NULL; // Peek at the radio button glyph to get a good estimate of the size @@ -115,7 +113,7 @@ void CRadioButtonTest::disconnect(void) if (m_radioButtonGroup) { delete m_radioButtonGroup; - m_radioButtonGroup = NULL; + m_radioButtonGroup = (CRadioButtonGroup *)NULL; } // Close the window @@ -153,7 +151,7 @@ bool CRadioButtonTest::createWindow(void) { // Initialize the widget control using the default style - m_widgetControl = new CWidgetControl(NULL); + m_widgetControl = new CWidgetControl((CWidgetStyle *)NULL); // Get an (uninitialized) instance of the background window as a class // that derives from INxWindow. @@ -190,7 +188,7 @@ CRadioButton *CRadioButtonTest::newRadioButton(void) if (!m_bgWindow->getSize(&windowSize)) { printf("CRadioButtonTest::newRadioButton: Failed to get window size\n"); - return NULL; + return (CRadioButton *)NULL; } // Create the radio button group, if we have not already done so @@ -207,7 +205,7 @@ CRadioButton *CRadioButtonTest::newRadioButton(void) if (!m_radioButtonGroup) { printf("CRadioButtonTest::newRadioButton: Failed to create the radio button group\n"); - return NULL; + return (CRadioButton *)NULL; } } diff --git a/graphics/nxwidgets/UnitTests/CRadioButton/cradiobuttontest.hxx b/graphics/nxwidgets/UnitTests/CRadioButton/cradiobuttontest.hxx index 8a5c1f0df..577b8a1e7 100644 --- a/graphics/nxwidgets/UnitTests/CRadioButton/cradiobuttontest.hxx +++ b/graphics/nxwidgets/UnitTests/CRadioButton/cradiobuttontest.hxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/graphics/nxwidgets/UnitTests/CRadioButton/cradiobuttontest.hxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -32,7 +30,7 @@ #include #include #include -#include +#include #include diff --git a/graphics/nxwidgets/UnitTests/CScrollbarHorizontal/Make.defs b/graphics/nxwidgets/UnitTests/CScrollbarHorizontal/Make.defs index 68fb2e45d..0fca7b68a 100644 --- a/graphics/nxwidgets/UnitTests/CScrollbarHorizontal/Make.defs +++ b/graphics/nxwidgets/UnitTests/CScrollbarHorizontal/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/graphics/nxwidgets/UnitTests/CScrollbarHorizontal/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwidgets/UnitTests/CScrollbarHorizontal/Makefile b/graphics/nxwidgets/UnitTests/CScrollbarHorizontal/Makefile index 8a1b989b1..03bb81490 100644 --- a/graphics/nxwidgets/UnitTests/CScrollbarHorizontal/Makefile +++ b/graphics/nxwidgets/UnitTests/CScrollbarHorizontal/Makefile @@ -1,8 +1,6 @@ ################################################################################# # apps/graphics/nxwidgets/UnitTests/CScrollbarHorizontal/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwidgets/UnitTests/CScrollbarHorizontal/cscrollbarhorizontal_main.cxx b/graphics/nxwidgets/UnitTests/CScrollbarHorizontal/cscrollbarhorizontal_main.cxx index 2429a75d1..344e84cca 100644 --- a/graphics/nxwidgets/UnitTests/CScrollbarHorizontal/cscrollbarhorizontal_main.cxx +++ b/graphics/nxwidgets/UnitTests/CScrollbarHorizontal/cscrollbarhorizontal_main.cxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/graphics/nxwidgets/UnitTests/CScrollbarHorizontal/cscrollbarhorizontal_main.cxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -32,7 +30,7 @@ #include #include #include -#include +#include #include diff --git a/graphics/nxwidgets/UnitTests/CScrollbarHorizontal/cscrollbarhorizontaltest.cxx b/graphics/nxwidgets/UnitTests/CScrollbarHorizontal/cscrollbarhorizontaltest.cxx index 21501c125..4532222da 100644 --- a/graphics/nxwidgets/UnitTests/CScrollbarHorizontal/cscrollbarhorizontaltest.cxx +++ b/graphics/nxwidgets/UnitTests/CScrollbarHorizontal/cscrollbarhorizontaltest.cxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/graphics/nxwidgets/UnitTests/CScrollbarHorizontal/cscrollbarhorizontaltest.cxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -29,7 +27,7 @@ #include #include #include -#include +#include #include #include @@ -68,8 +66,8 @@ CScrollbarHorizontalTest::CScrollbarHorizontalTest() { // Initialize state data - m_widgetControl = NULL; - m_bgWindow = NULL; + m_widgetControl = (CWidgetControl *)NULL; + m_bgWindow = (CBgWindow *)NULL; } // CScrollbarHorizontalTest Descriptor @@ -108,7 +106,7 @@ void CScrollbarHorizontalTest::disconnect(void) if (m_bgWindow) { delete m_bgWindow; - m_bgWindow = NULL; + m_bgWindow = (CBgWindow *)NULL; } // Free the widget control instance @@ -116,7 +114,7 @@ void CScrollbarHorizontalTest::disconnect(void) if (m_widgetControl) { delete m_widgetControl; - m_widgetControl = NULL; + m_widgetControl = (CWidgetControl *)NULL; } // And disconnect from the server @@ -140,7 +138,7 @@ bool CScrollbarHorizontalTest::createWindow(void) { // Initialize the widget control using the default style - m_widgetControl = new CWidgetControl(NULL); + m_widgetControl = new CWidgetControl((CWidgetStyle *)NULL); // Get an (uninitialized) instance of the background window as a class // that derives from INxWindow. diff --git a/graphics/nxwidgets/UnitTests/CScrollbarHorizontal/cscrollbarhorizontaltest.hxx b/graphics/nxwidgets/UnitTests/CScrollbarHorizontal/cscrollbarhorizontaltest.hxx index b53d318d5..190d6243c 100644 --- a/graphics/nxwidgets/UnitTests/CScrollbarHorizontal/cscrollbarhorizontaltest.hxx +++ b/graphics/nxwidgets/UnitTests/CScrollbarHorizontal/cscrollbarhorizontaltest.hxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/graphics/nxwidgets/UnitTests/CScrollbarHorizontal/cscrollbarhorizontaltest.hxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -32,7 +30,7 @@ #include #include #include -#include +#include #include diff --git a/graphics/nxwidgets/UnitTests/CScrollbarVertical/Make.defs b/graphics/nxwidgets/UnitTests/CScrollbarVertical/Make.defs index f5c251149..051a7d49b 100644 --- a/graphics/nxwidgets/UnitTests/CScrollbarVertical/Make.defs +++ b/graphics/nxwidgets/UnitTests/CScrollbarVertical/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/graphics/nxwidgets/UnitTests/CScrollbarVertical/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwidgets/UnitTests/CScrollbarVertical/Makefile b/graphics/nxwidgets/UnitTests/CScrollbarVertical/Makefile index 439675520..fb63717ae 100644 --- a/graphics/nxwidgets/UnitTests/CScrollbarVertical/Makefile +++ b/graphics/nxwidgets/UnitTests/CScrollbarVertical/Makefile @@ -1,8 +1,6 @@ ################################################################################# # apps/graphics/nxwidgets/UnitTests/CScrollbarVertical/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwidgets/UnitTests/CScrollbarVertical/cscrollbarvertical_main.cxx b/graphics/nxwidgets/UnitTests/CScrollbarVertical/cscrollbarvertical_main.cxx index 9497febe5..01b957a20 100644 --- a/graphics/nxwidgets/UnitTests/CScrollbarVertical/cscrollbarvertical_main.cxx +++ b/graphics/nxwidgets/UnitTests/CScrollbarVertical/cscrollbarvertical_main.cxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/graphics/nxwidgets/UnitTests/CScrollbarVertical/cscrollbarvertical_main.cxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -32,7 +30,7 @@ #include #include #include -#include +#include #include diff --git a/graphics/nxwidgets/UnitTests/CScrollbarVertical/cscrollbarverticaltest.cxx b/graphics/nxwidgets/UnitTests/CScrollbarVertical/cscrollbarverticaltest.cxx index 8770f5df4..e01201585 100644 --- a/graphics/nxwidgets/UnitTests/CScrollbarVertical/cscrollbarverticaltest.cxx +++ b/graphics/nxwidgets/UnitTests/CScrollbarVertical/cscrollbarverticaltest.cxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/graphics/nxwidgets/UnitTests/CScrollbarVertical/cscrollbarverticaltest.cxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -29,7 +27,7 @@ #include #include #include -#include +#include #include #include @@ -68,8 +66,8 @@ CScrollbarVerticalTest::CScrollbarVerticalTest() { // Initialize state data - m_widgetControl = NULL; - m_bgWindow = NULL; + m_widgetControl = (CWidgetControl *)NULL; + m_bgWindow = (CBgWindow *)NULL; } // CScrollbarVerticalTest Descriptor @@ -108,7 +106,7 @@ void CScrollbarVerticalTest::disconnect(void) if (m_bgWindow) { delete m_bgWindow; - m_bgWindow = NULL; + m_bgWindow = (CBgWindow *)NULL; } // Free the widget control instance @@ -116,7 +114,7 @@ void CScrollbarVerticalTest::disconnect(void) if (m_widgetControl) { delete m_widgetControl; - m_widgetControl = NULL; + m_widgetControl = (CWidgetControl *)NULL; } // And disconnect from the server @@ -140,7 +138,7 @@ bool CScrollbarVerticalTest::createWindow(void) { // Initialize the widget control using the default style - m_widgetControl = new CWidgetControl(NULL); + m_widgetControl = new CWidgetControl((CWidgetStyle *)NULL); // Get an (uninitialized) instance of the background window as a class // that derives from INxWindow. diff --git a/graphics/nxwidgets/UnitTests/CScrollbarVertical/cscrollbarverticaltest.hxx b/graphics/nxwidgets/UnitTests/CScrollbarVertical/cscrollbarverticaltest.hxx index fc062fed2..78dca2edb 100644 --- a/graphics/nxwidgets/UnitTests/CScrollbarVertical/cscrollbarverticaltest.hxx +++ b/graphics/nxwidgets/UnitTests/CScrollbarVertical/cscrollbarverticaltest.hxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/graphics/nxwidgets/UnitTests/CScrollbarVertical/cscrollbarverticaltest.hxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -32,7 +30,7 @@ #include #include #include -#include +#include #include diff --git a/graphics/nxwidgets/UnitTests/CSliderHorizonal/Make.defs b/graphics/nxwidgets/UnitTests/CSliderHorizonal/Make.defs index 1a5144f3c..a7c3afe42 100644 --- a/graphics/nxwidgets/UnitTests/CSliderHorizonal/Make.defs +++ b/graphics/nxwidgets/UnitTests/CSliderHorizonal/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/graphics/nxwidgets/UnitTests/CSliderHorizonal/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwidgets/UnitTests/CSliderHorizonal/Makefile b/graphics/nxwidgets/UnitTests/CSliderHorizonal/Makefile index 893f1942c..6d5ba91e4 100644 --- a/graphics/nxwidgets/UnitTests/CSliderHorizonal/Makefile +++ b/graphics/nxwidgets/UnitTests/CSliderHorizonal/Makefile @@ -1,8 +1,6 @@ ################################################################################# # apps/graphics/nxwidgets/UnitTests/CSliderHorizontal/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwidgets/UnitTests/CSliderHorizonal/csliderhorizontal_main.cxx b/graphics/nxwidgets/UnitTests/CSliderHorizonal/csliderhorizontal_main.cxx index 6c122a20b..33c19c668 100644 --- a/graphics/nxwidgets/UnitTests/CSliderHorizonal/csliderhorizontal_main.cxx +++ b/graphics/nxwidgets/UnitTests/CSliderHorizonal/csliderhorizontal_main.cxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/graphics/nxwidgets/UnitTests/CSliderHorizontal/csliderhorizontal_main.cxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -32,7 +30,7 @@ #include #include #include -#include +#include #include diff --git a/graphics/nxwidgets/UnitTests/CSliderHorizonal/csliderhorizontaltest.cxx b/graphics/nxwidgets/UnitTests/CSliderHorizonal/csliderhorizontaltest.cxx index 5dd3880f7..fa42fdf55 100644 --- a/graphics/nxwidgets/UnitTests/CSliderHorizonal/csliderhorizontaltest.cxx +++ b/graphics/nxwidgets/UnitTests/CSliderHorizonal/csliderhorizontaltest.cxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/graphics/nxwidgets/UnitTests/CSliderHorizontal/csliderhorizontaltest.cxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -29,7 +27,7 @@ #include #include #include -#include +#include #include #include @@ -68,8 +66,8 @@ CSliderHorizontalTest::CSliderHorizontalTest() { // Initialize state data - m_widgetControl = NULL; - m_bgWindow = NULL; + m_widgetControl = (CWidgetControl *)NULL; + m_bgWindow = (CBgWindow *)NULL; } // CSliderHorizontalTest Descriptor @@ -108,7 +106,7 @@ void CSliderHorizontalTest::disconnect(void) if (m_bgWindow) { delete m_bgWindow; - m_bgWindow = NULL; + m_bgWindow = (CBgWindow *)NULL; } // Free the widget control instance @@ -116,7 +114,7 @@ void CSliderHorizontalTest::disconnect(void) if (m_widgetControl) { delete m_widgetControl; - m_widgetControl = NULL; + m_widgetControl = (CWidgetControl *)NULL; } // And disconnect from the server @@ -140,7 +138,7 @@ bool CSliderHorizontalTest::createWindow(void) { // Initialize the widget control using the default style - m_widgetControl = new CWidgetControl(NULL); + m_widgetControl = new CWidgetControl((CWidgetStyle *)NULL); // Get an (uninitialized) instance of the background window as a class // that derives from INxWindow. diff --git a/graphics/nxwidgets/UnitTests/CSliderHorizonal/csliderhorizontaltest.hxx b/graphics/nxwidgets/UnitTests/CSliderHorizonal/csliderhorizontaltest.hxx index 9f9297399..3eb6ee7ff 100644 --- a/graphics/nxwidgets/UnitTests/CSliderHorizonal/csliderhorizontaltest.hxx +++ b/graphics/nxwidgets/UnitTests/CSliderHorizonal/csliderhorizontaltest.hxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/graphics/nxwidgets/UnitTests/CSliderHorizontal/csliderhorizontaltest.hxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -32,7 +30,7 @@ #include #include #include -#include +#include #include diff --git a/graphics/nxwidgets/UnitTests/CSliderVertical/Make.defs b/graphics/nxwidgets/UnitTests/CSliderVertical/Make.defs index ef0a92bcc..7cd8c5fb0 100644 --- a/graphics/nxwidgets/UnitTests/CSliderVertical/Make.defs +++ b/graphics/nxwidgets/UnitTests/CSliderVertical/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/graphics/nxwidgets/UnitTests/CSliderVertical/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwidgets/UnitTests/CSliderVertical/Makefile b/graphics/nxwidgets/UnitTests/CSliderVertical/Makefile index d4a972525..d989b56c2 100644 --- a/graphics/nxwidgets/UnitTests/CSliderVertical/Makefile +++ b/graphics/nxwidgets/UnitTests/CSliderVertical/Makefile @@ -1,8 +1,6 @@ ################################################################################# # apps/graphics/nxwidgets/UnitTests/CSliderVertical/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwidgets/UnitTests/CSliderVertical/cslidervertical_main.cxx b/graphics/nxwidgets/UnitTests/CSliderVertical/cslidervertical_main.cxx index 2d109b35a..621c30739 100644 --- a/graphics/nxwidgets/UnitTests/CSliderVertical/cslidervertical_main.cxx +++ b/graphics/nxwidgets/UnitTests/CSliderVertical/cslidervertical_main.cxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/graphics/nxwidgets/UnitTests/CSliderVertical/cslidervertical_main.cxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -32,7 +30,7 @@ #include #include #include -#include +#include #include diff --git a/graphics/nxwidgets/UnitTests/CSliderVertical/csliderverticaltest.cxx b/graphics/nxwidgets/UnitTests/CSliderVertical/csliderverticaltest.cxx index aa2241764..211942185 100644 --- a/graphics/nxwidgets/UnitTests/CSliderVertical/csliderverticaltest.cxx +++ b/graphics/nxwidgets/UnitTests/CSliderVertical/csliderverticaltest.cxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/graphics/nxwidgets/UnitTests/CSliderVertical/csliderverticaltest.cxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -29,7 +27,7 @@ #include #include #include -#include +#include #include #include @@ -68,8 +66,8 @@ CSliderVerticalTest::CSliderVerticalTest() { // Initialize state data - m_widgetControl = NULL; - m_bgWindow = NULL; + m_widgetControl = (CWidgetControl *)NULL; + m_bgWindow = (CBgWindow *)NULL; } // CSliderVerticalTest Descriptor @@ -108,7 +106,7 @@ void CSliderVerticalTest::disconnect(void) if (m_bgWindow) { delete m_bgWindow; - m_bgWindow = NULL; + m_bgWindow = (CBgWindow *)NULL; } // Free the widget control instance @@ -116,7 +114,7 @@ void CSliderVerticalTest::disconnect(void) if (m_widgetControl) { delete m_widgetControl; - m_widgetControl = NULL; + m_widgetControl = (CWidgetControl *)NULL; } // And disconnect from the server @@ -140,7 +138,7 @@ bool CSliderVerticalTest::createWindow(void) { // Initialize the widget control using the default style - m_widgetControl = new CWidgetControl(NULL); + m_widgetControl = new CWidgetControl((CWidgetStyle *)NULL); // Get an (uninitialized) instance of the background window as a class // that derives from INxWindow. diff --git a/graphics/nxwidgets/UnitTests/CSliderVertical/csliderverticaltest.hxx b/graphics/nxwidgets/UnitTests/CSliderVertical/csliderverticaltest.hxx index 0bac9b3d6..cc2bc5d8f 100644 --- a/graphics/nxwidgets/UnitTests/CSliderVertical/csliderverticaltest.hxx +++ b/graphics/nxwidgets/UnitTests/CSliderVertical/csliderverticaltest.hxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/graphics/nxwidgets/UnitTests/CSliderVertical/csliderverticaltest.hxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -32,7 +30,7 @@ #include #include #include -#include +#include #include diff --git a/graphics/nxwidgets/UnitTests/CTextBox/Make.defs b/graphics/nxwidgets/UnitTests/CTextBox/Make.defs index e98f713ff..9f262f68e 100644 --- a/graphics/nxwidgets/UnitTests/CTextBox/Make.defs +++ b/graphics/nxwidgets/UnitTests/CTextBox/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/graphics/nxwidgets/UnitTests/CTextBox/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwidgets/UnitTests/CTextBox/Makefile b/graphics/nxwidgets/UnitTests/CTextBox/Makefile index 9144e1bd4..acdc88def 100644 --- a/graphics/nxwidgets/UnitTests/CTextBox/Makefile +++ b/graphics/nxwidgets/UnitTests/CTextBox/Makefile @@ -1,8 +1,6 @@ ################################################################################# # apps/graphics/nxwidgets/UnitTests/CTextBox/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwidgets/UnitTests/CTextBox/ctextbox_main.cxx b/graphics/nxwidgets/UnitTests/CTextBox/ctextbox_main.cxx index ef9a5e362..33a8d48e1 100644 --- a/graphics/nxwidgets/UnitTests/CTextBox/ctextbox_main.cxx +++ b/graphics/nxwidgets/UnitTests/CTextBox/ctextbox_main.cxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/graphics/nxwidgets/UnitTests/CTextBox/ctextbox_main.cxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -29,7 +27,7 @@ #include #include #include -#include +#include #include diff --git a/graphics/nxwidgets/UnitTests/CTextBox/ctextboxtest.cxx b/graphics/nxwidgets/UnitTests/CTextBox/ctextboxtest.cxx index d34d937b9..b34cd724c 100644 --- a/graphics/nxwidgets/UnitTests/CTextBox/ctextboxtest.cxx +++ b/graphics/nxwidgets/UnitTests/CTextBox/ctextboxtest.cxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/graphics/nxwidgets/UnitTests/CTextBox/ctextboxtest.cxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -30,7 +28,7 @@ #include #include #include -#include +#include #include #include @@ -67,9 +65,9 @@ CTextBoxTest::CTextBoxTest() { - m_bgWindow = NULL; - m_nxFont = NULL; - m_text = NULL; + m_bgWindow = (CBgWindow *)NULL; + m_nxFont = (CNxFont *)NULL; + m_text = (CNxString *)NULL; } // CTextBoxTest Descriptor @@ -125,7 +123,7 @@ void CTextBoxTest::disconnect(void) if (m_text) { delete m_text; - m_text = NULL; + m_text = (CNxString *)NULL; } // Free the default font @@ -133,7 +131,7 @@ void CTextBoxTest::disconnect(void) if (m_nxFont) { delete m_nxFont; - m_nxFont = NULL; + m_nxFont = (CNxFont *)NULL; } // And disconnect from the server @@ -157,7 +155,7 @@ bool CTextBoxTest::createWindow(void) { // Initialize the widget control using the default style - m_widgetControl = new CWidgetControl(NULL); + m_widgetControl = new CWidgetControl((CWidgetStyle *)NULL); // Get an (uninitialized) instance of the background window as a class // that derives from INxWindow. @@ -194,7 +192,7 @@ CTextBox *CTextBoxTest::createTextBox(void) if (!m_bgWindow->getSize(&windowSize)) { printf("CTextBoxTest::createGraphics: Failed to get window size\n"); - return NULL; + return (CTextBox *)NULL; } // Create an empty CNxString instance to contain the C string diff --git a/graphics/nxwidgets/UnitTests/CTextBox/ctextboxtest.hxx b/graphics/nxwidgets/UnitTests/CTextBox/ctextboxtest.hxx index 21e994d74..4dd0cbac1 100644 --- a/graphics/nxwidgets/UnitTests/CTextBox/ctextboxtest.hxx +++ b/graphics/nxwidgets/UnitTests/CTextBox/ctextboxtest.hxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/graphics/nxwidgets/UnitTests/CTextBox/ctextboxtest.hxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -32,7 +30,7 @@ #include #include #include -#include +#include #include diff --git a/graphics/nxwidgets/UnitTests/Make.defs b/graphics/nxwidgets/UnitTests/Make.defs index 9eaef1369..bbb563433 100644 --- a/graphics/nxwidgets/UnitTests/Make.defs +++ b/graphics/nxwidgets/UnitTests/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/graphics/nxwidgets/UnitTests/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwidgets/UnitTests/Makefile b/graphics/nxwidgets/UnitTests/Makefile index 1a2d49f26..85e6e2e82 100644 --- a/graphics/nxwidgets/UnitTests/Makefile +++ b/graphics/nxwidgets/UnitTests/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/graphics/nxwidgets/UnitTests/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwidgets/UnitTests/README.md b/graphics/nxwidgets/UnitTests/README.md new file mode 100644 index 000000000..1793cd58e --- /dev/null +++ b/graphics/nxwidgets/UnitTests/README.md @@ -0,0 +1,259 @@ +# Graphics / NXWidgets / Unit Tests + +This directory contains a collection of Unit Tests that can be used to verify +NXWidgets.: + +## Contents + +**Installing and Building the Unit Tests** + +1. Setup NuttX + 1. Configure NuttX + 2. Enable C++ Support + 3. Enable Debug Options + 4. Special configuration requirements for the nxwm unit test + 5. Other `.config` file changes โ€“ NSH configurations only + 6. Other `.config` file changes โ€“ NON-NSH configurations only +2. Adjust the Stack Size +3. Build NuttX including the unit test and the NXWidgets library + +**Work-Arounds** + +1. Build Issues + +**Unit Test Directories** + +## Installing and Building the Unit Tests + +1. Setup NuttX + + 1. Configure NuttX + + Configure NuttX to run one of the target configurations. For example, + let's assume that you are using the `sim/nsh2` configuration. The + `sim/nsh2` configuration was specially created for use NXWidgets on the + simulation platform. A similar, special configuration `stm3210e-eval/nsh2` + is also for the `STM3210E-EVAL` available. However, the unit test can be + run on other configurations (see steps d and e below). + + **Note**: There are some other special configurationsrecommended for + unit-leveling testing of NxWM because the configuration is more complex in + that case. These are: + + 1) `sim/nxwmm`, or the simulated platform (no touchscreen), and + 2) `stm3240g-evel`, for the `STM3240G-EVAL` board (with the STMPE11 + touchscreen) + + We will assume the `sim/nsh2` configuration in this discussion. The + `sim/nsh2` configuration is installed as follows: + + ```bash + cd + make distclean + tools/configure.sh sim:nsh2 + ``` + + Where: + + `` is the full, absolute path to the NuttX build + directory + + If you are using the `sim/nsh2` or `stm3210e-eval` configurations, then + skip to step 2 (Hmmm.. better check 1d) too). + + There may be certain requirements for the configuration that you select... + for example, certain widget tests may require touchscreen support or + special font selections. These test-specific requirements are addressed + below under _Unit Test Directories_ + + 2. Enable C++ Support + + If you are not using the `sim/nsh2` or `stm3210e-eval`, you will need to + add the following definitions to the NuttX configuration at + `nuttx/.config` to enable C++ support: + + ```conf + CONFIG_HAVE_CXX=y + ``` + + Check first, some configurations already have C++ support enabled (As of + this writing **ONLY** the `sim/nsh2` and `stm321-e-eval` configurations + have C++ support pre-enabled). + + 3. Enable Debug Options + + If you are running on a simulated target, then you might also want to + enable debug symbols: + + ```conf + CONFIG_DEBUG_SYMBOLS=y + ``` + + Then you can run the simulation using GDB or DDD which is a very powerful + debugging environment! + + 4. Special configuration requirements for the nxwm unit test. + + ```conf + CONFIG_NXTERM=y + ``` + + 5. Other `.config` file changes โ€“ NSH configurations only. + + If the configuration that you are using supports NSH and NSH built-in + tasks then all is well. If it is an NSH configuration, then you will have + to define the following in your `nuttx/.config` file as well (if it is not + already defined): + + ```conf + CONFIG_NSH_BUILTIN_APPS=y + ``` + + `sim/nsh2` and `stm3210e-eval/nsh2` already has this setting. You do not + need to change anything further in the `nuttx/.config` file if you are + using either of these configurations. + + 6. Other `.config` file changes โ€“ NON-NSH configurations only. + + Entry Point. You will need to set the entry point in the .config file. For + NSH configurations, the entry point will always be `nsh_main` and you will + see that setting like: + + ```conf + CONFIG_INIT_ENTRYPOINT="nsh_main" + ``` + + If you are not using in NSH, then each unit test has a unique entry point. + That entry point is the name of the unit test directory in all lower case + plus the suffix `_main`. So, for example, the correct entry for the + `UnitTests/CButton` would be: + + ```conf + CONFIG_INIT_ENTRYPOINT="cbutton_main" + ``` + + And the correct entry point for `UnitTests/nxwm` would be: + + ```conf + CONFIG_INIT_ENTRYPOINT="nxwm_main" + ``` + + etc. + + For non-NSH configurations (such as the `sim/touchscreen`) you will have + to remove the configuration setting that provided the `main` function so + that you use the `main` in the unit test code instead. So, for example, + with the `sim/touchscreen` configuration you need to remove the following + from the NuttX configuration file (`.config`): + + ```conf + CONFIG_EXAMPLES_TOUSCHCREEN=y ## REMOVE (provided "tc_main") + ``` + +2. Adjust the Stack Size + + If using an simulation configuration (like `sim/nsh2`) and your unit test + uses X11 as its display device, then you would have to increase the size of + unit test stack as described below under _Stack Size Issues with the X11 + Simulation_. + +3. Build NuttX including the unit test and the NXWidgets library + + ```bash + cd + . ./setenv.sh + make + ``` + +## Work-Arounds + +### Build Issues + +1. I have seen this error on Cygwin building C++ code: + + ``` + LD: nuttx.rel + ld: skipping incompatible /home/patacongo/projects/nuttx/nuttx/trunk/nuttx/libxx//liblibxx.a when searching for -llibxx + ld: cannot find -llibxx + ``` + + The problem seems to be caused because `gcc` build code for 32-bit mode and + `g++` builds code for 64-bit mode. Add the `-m32` option to the `g++` command + line seems to fix the problem. In `Make.defs`: + + ```makefile + CXXFLAGS = -m32 $(ARCHWARNINGSXX) $(ARCHOPTIMIZATION) \ + $(ARCHCXXFLAGS) $(ARCHINCLUDESXX) $(ARCHDEFINES) $(EXTRADEFINES) -pipe + ``` + +2. Stack Size Issues with the X11 Simulation + + When you run the NuttX simulation, it uses stacks allocated by NuttX from the + NuttX heap. The memory management model is exactly the same in the simulation + as it is real, target system. This is good because this produces a higher + fidelity simulation. + + However, when the simulation calls into Linux/Cygwin libraries, it will still + use these small simulation stacks. This happens, for example, when you call + into the system to get and put characters to the console window or when you + make x11 calls into the system. The programming model within those libraries + will assume a Linux/Cygwin environment where the stack size grows dynamically + + As a consequence, those system libraries may allocate large data structures + on the stack and overflow the small NuttX stacks. X11, in particular, + requires large stacks. If you are using X11 in the simulation, make sure that + you set aside a "lot" of stack for the X11 system calls (maybe 8 or 16Kb). + The stack size for the thread that begins with user start is controlled by + the configuration setting `CONFIG_USERMAIN_STACKSIZE`; you may need to + increase this value to larger number to survive the X11 system calls. + + If you are running X11 applications as NSH add-on programs, then the stack + size of the add-on program is controlled in another way. Here are the steps + for increasing the stack size in that case: + + ```bash + cd ../apps/namedapps # Go to the namedapps directory + vi namedapps_list.h # Edit this file and increase the stack size of the add-on + rm .built *.o # This will force the namedapps logic to rebuild + ``` + +## Unit Tests + +The following provide simple unit tests for each of the NXWidgets. In addition, +these unit tests provide examples for the use of each widget type. + +- `CButton` + - Exercises the `CButton` widget. + - Depends on `CLabel`. +- `CButtonArray` + - Exercises the `CButtonArray` widget. +- `CCheckBox` + - Exercises the `CCheckBox` widget. + - Depends on `CLabel` and `CButton`. +- `CGlyphButton` + - Exercises the `CGlyphButton` widget. + - Depends on `CLabel` and `CButton`. +- `CImage` + - Exercises the `CImage` widget. +- `CLabel` + - Exercises the `CLabel` widget. +- `CProgressBar` + - Exercises the `CProgressBar` widget. +- `CRadioButton` + - Exercises the `CRadioButton` and `CRadioButtonGroup` widgets. + - Depends on `CLabel` and `CButton`. +- `CScrollBarHorizontal` + - Exercises the `ScrollbarHorizontal`. + - Depends on `CSliderHorizontal` and `CGlyphButton`. +- `CScrollBarVertical` + - Exercises the `ScrollbarHorizontal`. + - Depends on `CSliderVertical` and `CGlyphButton`. +- `CSliderHorizontal` + - Exercises the `CSliderHorizontal`. + - Depends on `CSliderHorizontalGrip`. +- `CSliderVertical` + - Exercises the `CSliderVertical`. + - Depends on `CSliderVerticalGrip`. +- `CTextBox` + - Exercises the `CTextBox` widget. + - Depends on `CLabel`. diff --git a/graphics/nxwidgets/src/cbgwindow.cxx b/graphics/nxwidgets/src/cbgwindow.cxx index a18dfa2b2..90da9cf6e 100644 --- a/graphics/nxwidgets/src/cbgwindow.cxx +++ b/graphics/nxwidgets/src/cbgwindow.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxwidgets/src/cbgwindow.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwidgets/src/cbitmap.cxx b/graphics/nxwidgets/src/cbitmap.cxx index 542e505b9..f8178f711 100644 --- a/graphics/nxwidgets/src/cbitmap.cxx +++ b/graphics/nxwidgets/src/cbitmap.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxwidgets/src/cbitmap.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwidgets/src/cbutton.cxx b/graphics/nxwidgets/src/cbutton.cxx index 4c3f1e842..192cc5fed 100644 --- a/graphics/nxwidgets/src/cbutton.cxx +++ b/graphics/nxwidgets/src/cbutton.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxwidgets/src/cbutton.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwidgets/src/cbuttonarray.cxx b/graphics/nxwidgets/src/cbuttonarray.cxx index 3de7bf165..c5072efc0 100644 --- a/graphics/nxwidgets/src/cbuttonarray.cxx +++ b/graphics/nxwidgets/src/cbuttonarray.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxwidgets/include/cbuttonarray.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwidgets/src/ccallback.cxx b/graphics/nxwidgets/src/ccallback.cxx index f07deaf93..21989d243 100644 --- a/graphics/nxwidgets/src/ccallback.cxx +++ b/graphics/nxwidgets/src/ccallback.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxwidgets/src/ccallback.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -34,7 +32,7 @@ #include #include #include -#include +#include #include #include @@ -85,6 +83,7 @@ CCallback::CCallback(CWidgetControl *widgetControl) m_synchronized = false; sem_init(&m_semevent, 0, 0); + sem_setprotocol(&m_semevent, SEM_PRIO_NONE); #ifdef CONFIG_NXTERM_NXKBDIN // Keyboard input is initially directed to the widgets within the window @@ -308,7 +307,7 @@ void CCallback::newKeyboardEvent(NXHANDLE hwnd, uint8_t nCh, * NXEVENT_SYCNCHED - Synchronization handshake * * This completes the handshake started by nx_synch(). nx_synch() - * sends a synchronization message to the NX server which responds + * sends a syncrhonization messages to the NX server which responds * with this event. The sleeping client is awakened and continues * graphics processing, completing the handshake. * diff --git a/graphics/nxwidgets/src/ccheckbox.cxx b/graphics/nxwidgets/src/ccheckbox.cxx index ada8430da..3e4bb298d 100644 --- a/graphics/nxwidgets/src/ccheckbox.cxx +++ b/graphics/nxwidgets/src/ccheckbox.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxwidgets/src/ccheckbox.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwidgets/src/ccyclebutton.cxx b/graphics/nxwidgets/src/ccyclebutton.cxx index 15f139c55..ac47ce234 100644 --- a/graphics/nxwidgets/src/ccyclebutton.cxx +++ b/graphics/nxwidgets/src/ccyclebutton.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxwidgets/src/ccyclebutton.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwidgets/src/cglyphbutton.cxx b/graphics/nxwidgets/src/cglyphbutton.cxx index 4d1107a4e..9cda22933 100644 --- a/graphics/nxwidgets/src/cglyphbutton.cxx +++ b/graphics/nxwidgets/src/cglyphbutton.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxwidgets/src/cglyphbutton.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwidgets/src/cglyphsliderhorizontal.cxx b/graphics/nxwidgets/src/cglyphsliderhorizontal.cxx index d6d2567e3..ff60f01e6 100644 --- a/graphics/nxwidgets/src/cglyphsliderhorizontal.cxx +++ b/graphics/nxwidgets/src/cglyphsliderhorizontal.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxwidgets/src/cglyphsliderhorizontal.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwidgets/src/cglyphsliderhorizontalgrip.cxx b/graphics/nxwidgets/src/cglyphsliderhorizontalgrip.cxx index 11540c654..2be7e6d71 100644 --- a/graphics/nxwidgets/src/cglyphsliderhorizontalgrip.cxx +++ b/graphics/nxwidgets/src/cglyphsliderhorizontalgrip.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxwidgets/src/cglyphsliderhorizontalgrip.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwidgets/src/cgraphicsport.cxx b/graphics/nxwidgets/src/cgraphicsport.cxx index ffe56033e..cac72d395 100644 --- a/graphics/nxwidgets/src/cgraphicsport.cxx +++ b/graphics/nxwidgets/src/cgraphicsport.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxwidgets/src/cgraphicsport.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -64,7 +62,7 @@ #include #include #include -#include +#include #include #include @@ -581,7 +579,7 @@ void CGraphicsPort::drawBitmapGreyScale(nxgl_coord_t x, nxgl_coord_t y, src += bitmap->stride; } - delete[] run; + delete run; } /** @@ -826,7 +824,7 @@ void CGraphicsPort::_drawText(struct nxgl_point_s *pos, CRect *bound, pos->x += fontWidth; } - delete[] glyph; + delete glyph; } /** @@ -964,7 +962,7 @@ void CGraphicsPort::greyScale(nxgl_coord_t x, nxgl_coord_t y, &origin, rowBitmap.stride) ; } - delete[] rowBuffer; + delete rowBuffer; } /** @@ -1040,5 +1038,5 @@ void CGraphicsPort::invert(nxgl_coord_t x, nxgl_coord_t y, &origin, rowBitmap.stride) ; } - delete[] rowBuffer; + delete rowBuffer; }; diff --git a/graphics/nxwidgets/src/cimage.cxx b/graphics/nxwidgets/src/cimage.cxx index 337b7fea4..da33a690e 100644 --- a/graphics/nxwidgets/src/cimage.cxx +++ b/graphics/nxwidgets/src/cimage.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxwidgets/include/cimage.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -62,7 +60,7 @@ #include #include -#include +#include #include @@ -256,7 +254,7 @@ void CImage::drawContents(CGraphicsPort *port, bool selected) if (!m_bitmap->getRun(0, srcRow, nLeftPixels, &buffer[m_origin.x])) { ginfo("IBitmap::getRun failed at image row %d\n", srcRow); - delete[] buffer; + delete buffer; return; } @@ -327,7 +325,7 @@ void CImage::drawContents(CGraphicsPort *port, bool selected) } } - delete[] buffer; + delete buffer; } /** diff --git a/graphics/nxwidgets/src/ckeypad.cxx b/graphics/nxwidgets/src/ckeypad.cxx index 460c9540b..5b9a3ab8e 100644 --- a/graphics/nxwidgets/src/ckeypad.cxx +++ b/graphics/nxwidgets/src/ckeypad.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxwidgets/src/ckeypad.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwidgets/src/clabel.cxx b/graphics/nxwidgets/src/clabel.cxx index 88fbba917..2523e1084 100644 --- a/graphics/nxwidgets/src/clabel.cxx +++ b/graphics/nxwidgets/src/clabel.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxwidgets/src/clabel.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -181,7 +179,7 @@ void CLabel::appendText(const CNxString &text) * @param index Index at which to insert the text. */ -void CLabel::insertText(const CNxString &text, const unsigned int index) +void CLabel::insertText(const CNxString &text, const int index) { m_text.insert(text, index); onTextChange(); diff --git a/graphics/nxwidgets/src/clabelgrid.cxx b/graphics/nxwidgets/src/clabelgrid.cxx index 175535bba..efd19e71e 100644 --- a/graphics/nxwidgets/src/clabelgrid.cxx +++ b/graphics/nxwidgets/src/clabelgrid.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/NxWkidgets/nwidgets/src/clabelgrid.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -59,7 +57,7 @@ ****************************************************************************/ #include -#include +#include #include "graphics/nxwidgets/clabelgrid.hxx" #include "graphics/nxwidgets/clabel.hxx" diff --git a/graphics/nxwidgets/src/clatchbutton.cxx b/graphics/nxwidgets/src/clatchbutton.cxx index 37dc6b035..d9fa235df 100644 --- a/graphics/nxwidgets/src/clatchbutton.cxx +++ b/graphics/nxwidgets/src/clatchbutton.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxwidgets/src/clatchbutton.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwidgets/src/clatchbuttonarray.cxx b/graphics/nxwidgets/src/clatchbuttonarray.cxx index 7de83e2a8..02ae3c84d 100644 --- a/graphics/nxwidgets/src/clatchbuttonarray.cxx +++ b/graphics/nxwidgets/src/clatchbuttonarray.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxwidgets/src/clatchbuttonarray.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwidgets/src/clistbox.cxx b/graphics/nxwidgets/src/clistbox.cxx index 8647d4aa9..cf39b1c14 100644 --- a/graphics/nxwidgets/src/clistbox.cxx +++ b/graphics/nxwidgets/src/clistbox.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxwidgets/src/clistbox.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -483,7 +481,7 @@ void CListBox::drawContents(CGraphicsPort *port) int y = m_canvasY + (topOption * optionHeight); int i = topOption; - const CListBoxDataItem *item = NULL; + const CListBoxDataItem *item = (CListBoxDataItem *)NULL; // Loop through all options drawing each ones diff --git a/graphics/nxwidgets/src/clistboxdataitem.cxx b/graphics/nxwidgets/src/clistboxdataitem.cxx index 571ad507e..6f65e0d0e 100644 --- a/graphics/nxwidgets/src/clistboxdataitem.cxx +++ b/graphics/nxwidgets/src/clistboxdataitem.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxwidgets/src/clistboxdataitem.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwidgets/src/clistdata.cxx b/graphics/nxwidgets/src/clistdata.cxx index 272b20eb2..331d42321 100644 --- a/graphics/nxwidgets/src/clistdata.cxx +++ b/graphics/nxwidgets/src/clistdata.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxwidgets/src/clistdata.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -248,7 +246,7 @@ const CListDataItem *CListData::getSelectedItem(void) const { return m_items[index]; } - return NULL; + return (CListDataItem *)NULL; } /** diff --git a/graphics/nxwidgets/src/clistdataitem.cxx b/graphics/nxwidgets/src/clistdataitem.cxx index bfe19682d..9cca7c6f7 100644 --- a/graphics/nxwidgets/src/clistdataitem.cxx +++ b/graphics/nxwidgets/src/clistdataitem.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxwidgets/src/clistdataitem.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwidgets/src/cmultilinetextbox.cxx b/graphics/nxwidgets/src/cmultilinetextbox.cxx index 3253db274..c655ff1e5 100644 --- a/graphics/nxwidgets/src/cmultilinetextbox.cxx +++ b/graphics/nxwidgets/src/cmultilinetextbox.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxwidgets/src/cmultilinetextbox.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -1227,7 +1225,7 @@ void CMultiLineTextBox::drawCursor(CGraphicsPort *port) // Draw cursor port->invert(cursorX, cursorY, - m_text->getFont()->getCharWidth(getCursorChar()), + m_text->getFont()->getCharWidth( getCursorChar()), m_text->getFont()->getHeight()); } } diff --git a/graphics/nxwidgets/src/cnumericedit.cxx b/graphics/nxwidgets/src/cnumericedit.cxx index 22556c7d8..2fedf32d1 100644 --- a/graphics/nxwidgets/src/cnumericedit.cxx +++ b/graphics/nxwidgets/src/cnumericedit.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxwidgets/include/cnumericedit.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -66,7 +64,7 @@ #include #include -#include +#include #include "graphics/nxwidgets/cnumericedit.hxx" #include "graphics/nxwidgets/cbutton.hxx" @@ -90,7 +88,7 @@ class CDraggableLabel: public CLabel public: CDraggableLabel(CWidgetControl *pWidgetControl, nxgl_coord_t x, nxgl_coord_t y, nxgl_coord_t width, nxgl_coord_t height, const CNxString &text, - CWidgetStyle *style = NULL): + CWidgetStyle *style = (CWidgetStyle *)NULL): CLabel(pWidgetControl, x, y, width, height, text, style) { setDraggable(true); diff --git a/graphics/nxwidgets/src/cnxfont.cxx b/graphics/nxwidgets/src/cnxfont.cxx index 639de608f..d7a122676 100644 --- a/graphics/nxwidgets/src/cnxfont.cxx +++ b/graphics/nxwidgets/src/cnxfont.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxwidgets/src/cnxfont.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwidgets/src/cnxserver.cxx b/graphics/nxwidgets/src/cnxserver.cxx index 60f841833..bda5d0d1b 100644 --- a/graphics/nxwidgets/src/cnxserver.cxx +++ b/graphics/nxwidgets/src/cnxserver.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxwidgets/src/cnxserver.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -37,7 +35,7 @@ #include #include #include -#include +#include #include @@ -65,8 +63,8 @@ CNxServer::CNxServer(void) { // Initialize server instance state data - m_hDevice = NULL; // LCD/Framebuffer device handle - m_hNxServer = NULL; // NX server handle + m_hDevice = (FAR NX_DRIVERTYPE *)NULL; // LCD/Framebuffer device handle + m_hNxServer = (NXHANDLE)NULL; // NX server handle m_connected = false; // True: Connected to the server sem_init(&m_connsem, 0, 0); // Wait for server connection diff --git a/graphics/nxwidgets/src/cnxstring.cxx b/graphics/nxwidgets/src/cnxstring.cxx index 6cd7ac13e..7274391fd 100644 --- a/graphics/nxwidgets/src/cnxstring.cxx +++ b/graphics/nxwidgets/src/cnxstring.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxwidgets/src/cnxstring.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -82,7 +80,7 @@ using namespace NXWidgets; CNxString::CNxString() { - m_text = NULL; + m_text = (FAR nxwidget_char_t *)NULL; m_stringLength = 0; m_allocatedSize = 0; m_growAmount = 16; @@ -97,7 +95,7 @@ CNxString::CNxString() CNxString::CNxString(FAR const char *text) { - m_text = NULL; + m_text = (FAR nxwidget_char_t *)NULL; m_stringLength = 0; m_allocatedSize = 0; m_growAmount = 16; @@ -112,7 +110,7 @@ CNxString::CNxString(FAR const char *text) CNxString::CNxString(const nxwidget_char_t text) { - m_text = NULL; + m_text = (FAR nxwidget_char_t *)NULL; m_stringLength = 0; m_allocatedSize = 0; m_growAmount = 16; @@ -122,7 +120,7 @@ CNxString::CNxString(const nxwidget_char_t text) CNxString::CNxString(const CNxString &string) { - m_text = NULL; + m_text = (FAR nxwidget_char_t *)NULL; m_stringLength = 0; m_allocatedSize = 0; m_growAmount = 16; @@ -785,14 +783,14 @@ FAR nxwidget_char_t *CNxString::getCharPointer(const int index) const if (!hasData()) { - return NULL; + return (FAR nxwidget_char_t*)NULL; } // Early exit if the index is greater than the length of the string if (index >= m_stringLength) { - return NULL; + return (FAR nxwidget_char_t*)NULL; } return &m_text[index]; diff --git a/graphics/nxwidgets/src/cnxtimer.cxx b/graphics/nxwidgets/src/cnxtimer.cxx index dd6be5101..d826e3ebe 100644 --- a/graphics/nxwidgets/src/cnxtimer.cxx +++ b/graphics/nxwidgets/src/cnxtimer.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxwidgets/src/cnxtimer.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -64,7 +62,7 @@ #include #include #include -#include +#include #include #include diff --git a/graphics/nxwidgets/src/cnxtkwindow.cxx b/graphics/nxwidgets/src/cnxtkwindow.cxx index 5f56f07af..6b819f3f0 100644 --- a/graphics/nxwidgets/src/cnxtkwindow.cxx +++ b/graphics/nxwidgets/src/cnxtkwindow.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxwidgets/src/cnxtkwindow.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwidgets/src/cnxtoolbar.cxx b/graphics/nxwidgets/src/cnxtoolbar.cxx index 8ae26490d..dc876032f 100644 --- a/graphics/nxwidgets/src/cnxtoolbar.cxx +++ b/graphics/nxwidgets/src/cnxtoolbar.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxwidgets/src/cnxtoolbar.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwidgets/src/cnxwidget.cxx b/graphics/nxwidgets/src/cnxwidget.cxx index e6b93863c..62230365d 100644 --- a/graphics/nxwidgets/src/cnxwidget.cxx +++ b/graphics/nxwidgets/src/cnxwidget.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxwidgets/src/cnxwidget.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -118,7 +116,7 @@ CNxWidget::CNxWidget(CWidgetControl *pWidgetControl, // Do we need to fetch the default style? - if (style == NULL) + if (style == (CWidgetStyle *)NULL) { // Get the style from the controlling widget. This allows different // widgets within a window to have the same style, unique to the window. @@ -163,8 +161,8 @@ CNxWidget::CNxWidget(CWidgetControl *pWidgetControl, // Set hierarchy pointers - m_parent = NULL; - m_focusedChild = NULL; + m_parent = (CNxWidget *)NULL; + m_focusedChild = (CNxWidget *)NULL; // Double-click @@ -197,11 +195,11 @@ CNxWidget::~CNxWidget(void) if (m_widgetControl->getClickedWidget() == this) { - m_widgetControl->setClickedWidget(NULL); + m_widgetControl->setClickedWidget((CNxWidget *)NULL); } } - if (m_parent != NULL) + if (m_parent != (CNxWidget *)NULL) { m_parent->removeChild(this); } @@ -231,7 +229,7 @@ CNxWidget::~CNxWidget(void) nxgl_coord_t CNxWidget::getX(void) const { - if (m_parent != NULL) + if (m_parent != (CNxWidget *)NULL) { return m_parent->getX() + m_rect.getX(); } @@ -247,7 +245,7 @@ nxgl_coord_t CNxWidget::getX(void) const nxgl_coord_t CNxWidget::getY(void) const { - if (m_parent != NULL) + if (m_parent != (CNxWidget *)NULL) { return m_parent->getY() + m_rect.getY(); } @@ -290,7 +288,7 @@ nxgl_coord_t CNxWidget::getRelativeY(void) const bool CNxWidget::isDeleted(void) const { - if (m_parent != NULL) + if (m_parent != (CNxWidget *)NULL) { if (m_parent->isDeleted()) { @@ -311,7 +309,7 @@ bool CNxWidget::isDeleted(void) const bool CNxWidget::isDrawingEnabled(void) const { - if (m_parent != NULL) + if (m_parent != (CNxWidget *)NULL) { if (m_parent->isDrawingEnabled()) { @@ -340,7 +338,7 @@ bool CNxWidget::isDrawingEnabled(void) const bool CNxWidget::isHidden(void) const { - if (m_parent != NULL) + if (m_parent != (CNxWidget *)NULL) { if (!m_parent->isHidden()) { @@ -367,7 +365,7 @@ bool CNxWidget::isHidden(void) const bool CNxWidget::isEnabled() const { - if (m_parent != NULL) + if (m_parent != (CNxWidget *)NULL) { if (m_parent->isEnabled()) { @@ -554,7 +552,7 @@ void CNxWidget::close(void) release(clickedWidget->getX(), clickedWidget->getY()); } - if (m_parent != NULL) + if (m_parent != (CNxWidget *)NULL) { m_parent->closeChild(this); } @@ -650,7 +648,7 @@ bool CNxWidget::click(nxgl_coord_t x, nxgl_coord_t y) // Take focus away from child widgets - setFocusedWidget(NULL); + setFocusedWidget((CNxWidget *)NULL); // Tell controlling widget that the clicked widget has changed @@ -733,7 +731,7 @@ bool CNxWidget::doubleClick(nxgl_coord_t x, nxgl_coord_t y) // Take focus away from child widgets - setFocusedWidget(NULL); + setFocusedWidget((CNxWidget *)NULL); // Tell controlling widget that the clicked widget has changed @@ -778,7 +776,7 @@ bool CNxWidget::release(nxgl_coord_t x, nxgl_coord_t y) if (m_widgetControl->getClickedWidget() == this) { - m_widgetControl->setClickedWidget(NULL); + m_widgetControl->setClickedWidget((CNxWidget *)NULL); } // Determine which release event to fire @@ -911,7 +909,7 @@ bool CNxWidget::focus(void) // Notify parent that this widget has focus - if (m_parent != NULL) + if (m_parent != (CNxWidget *)NULL) { m_parent->setFocusedWidget(this); } @@ -945,10 +943,10 @@ bool CNxWidget::blur(void) // Take focus away from child widgets - if (m_focusedChild != NULL) + if (m_focusedChild != (CNxWidget *)NULL) { m_focusedChild->blur(); - m_focusedChild = NULL; + m_focusedChild = (CNxWidget *)NULL; m_widgetControl->clearFocusedWidget(this); } @@ -978,7 +976,7 @@ bool CNxWidget::moveTo(nxgl_coord_t x, nxgl_coord_t y) { // Enforce widget to stay within parent confines if necessary - if (m_parent != NULL) + if (m_parent != (FAR CNxWidget *)NULL) { if (!m_parent->isPermeable()) { @@ -1066,7 +1064,7 @@ bool CNxWidget::resize(nxgl_coord_t width, nxgl_coord_t height) { // Enforce widget to stay within parent confines if necessary - if (m_parent != NULL) + if (m_parent != (CNxWidget *)NULL) { if (!m_parent->isPermeable()) { @@ -1326,7 +1324,7 @@ void CNxWidget::insertWidget(CNxWidget *widget) bool CNxWidget::remove(void) { - if (m_parent != NULL) + if (m_parent != (CNxWidget *)NULL) { return m_parent->removeChild(this); } @@ -1350,7 +1348,7 @@ bool CNxWidget::removeChild(CNxWidget *widget) if (m_focusedChild == widget) { - m_focusedChild = NULL; + m_focusedChild = (CNxWidget *)NULL; m_widgetControl->clearFocusedWidget(this); } @@ -1364,7 +1362,7 @@ bool CNxWidget::removeChild(CNxWidget *widget) // Divorce child from parent - widget->setParent(NULL); + widget->setParent((CNxWidget *)NULL); widget->disableDrawing(); // Locate widget in main vector @@ -1397,7 +1395,7 @@ const CNxWidget *CNxWidget::getChild(int index) const return m_children[index]; } - return NULL; + return (CNxWidget *)NULL; } /** @@ -1481,7 +1479,7 @@ void CNxWidget::closeChild(CNxWidget *widget) if (m_focusedChild == widget) { - m_focusedChild = NULL; + m_focusedChild = (CNxWidget *)NULL; m_widgetControl->clearFocusedWidget(this); // Try to choose highest widget @@ -1510,7 +1508,7 @@ void CNxWidget::closeChild(CNxWidget *widget) { // Give focus to this - setFocusedWidget(NULL); + setFocusedWidget((CNxWidget *)NULL); } } diff --git a/graphics/nxwidgets/src/cnxwindow.cxx b/graphics/nxwidgets/src/cnxwindow.cxx index cceef5794..ee7d40e91 100644 --- a/graphics/nxwidgets/src/cnxwindow.cxx +++ b/graphics/nxwidgets/src/cnxwindow.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxwidgets/src/cnxwindow.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwidgets/src/cprogressbar.cxx b/graphics/nxwidgets/src/cprogressbar.cxx index 88543daee..740793663 100644 --- a/graphics/nxwidgets/src/cprogressbar.cxx +++ b/graphics/nxwidgets/src/cprogressbar.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxwidgets/src/cprogressbar.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwidgets/src/cradiobutton.cxx b/graphics/nxwidgets/src/cradiobutton.cxx index 8fde8c58f..c41cc6e2f 100644 --- a/graphics/nxwidgets/src/cradiobutton.cxx +++ b/graphics/nxwidgets/src/cradiobutton.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxwidgets/src/cradiobutton.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwidgets/src/cradiobuttongroup.cxx b/graphics/nxwidgets/src/cradiobuttongroup.cxx index 72b024bd3..81bbd6151 100644 --- a/graphics/nxwidgets/src/cradiobuttongroup.cxx +++ b/graphics/nxwidgets/src/cradiobuttongroup.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxwidgets/src/cradiobutton.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -98,7 +96,7 @@ CRadioButtonGroup::CRadioButtonGroup(CWidgetControl *pWidgetControl, : CNxWidget(pWidgetControl, x, y, 0, 0, WIDGET_BORDERLESS, style) { m_widgetControl = pWidgetControl; - m_selectedWidget = NULL; + m_selectedWidget = (CRadioButton *)NULL; } /** diff --git a/graphics/nxwidgets/src/crect.cxx b/graphics/nxwidgets/src/crect.cxx index 2883dda30..afd64311f 100644 --- a/graphics/nxwidgets/src/crect.cxx +++ b/graphics/nxwidgets/src/crect.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxwidgets/src/cbgwindow.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwidgets/src/crlepalettebitmap.cxx b/graphics/nxwidgets/src/crlepalettebitmap.cxx index 752faf011..4e4aee3cd 100644 --- a/graphics/nxwidgets/src/crlepalettebitmap.cxx +++ b/graphics/nxwidgets/src/crlepalettebitmap.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxwidgets/src/crlepalettebitmap.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwidgets/src/cscaledbitmap.cxx b/graphics/nxwidgets/src/cscaledbitmap.cxx index 65f1a372f..063e0e3eb 100644 --- a/graphics/nxwidgets/src/cscaledbitmap.cxx +++ b/graphics/nxwidgets/src/cscaledbitmap.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxwidgets/src/cscaledbitmap.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -29,7 +27,7 @@ #include #include #include -#include +#include #include @@ -64,7 +62,7 @@ CScaledBitmap::CScaledBitmap(IBitmap *bitmap, struct nxgl_size_s &newSize) m_xScale = itob16((uint32_t)m_bitmap->getWidth()) / newSize.w; // Similarly, yScale will be used to convert a request Y position to a Y - // position in the contained bitmap: + // positionin the contained bitmap: // // yImage = yRequested * oldHeight / newHeight // = yRequested * yScale @@ -435,7 +433,7 @@ bool CScaledBitmap::scaleColor(FAR const struct rgbcolor_s &incolor1, FAR const struct rgbcolor_s &incolor2, b16_t fraction, FAR struct rgbcolor_s &outcolor) { - uint32_t component; + uint8_t component; b16_t red; b16_t green; b16_t blue; diff --git a/graphics/nxwidgets/src/cscrollbarhorizontal.cxx b/graphics/nxwidgets/src/cscrollbarhorizontal.cxx index 0a546af46..05cf642a9 100644 --- a/graphics/nxwidgets/src/cscrollbarhorizontal.cxx +++ b/graphics/nxwidgets/src/cscrollbarhorizontal.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxwidgets/include/cscrollbarhorizontal.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwidgets/src/cscrollbarpanel.cxx b/graphics/nxwidgets/src/cscrollbarpanel.cxx index b90d55cbf..bef923f27 100644 --- a/graphics/nxwidgets/src/cscrollbarpanel.cxx +++ b/graphics/nxwidgets/src/cscrollbarpanel.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxwidgets/src/cscrollbarpanel.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -109,9 +107,9 @@ CScrollbarPanel::CScrollbarPanel(CWidgetControl *pWidgetControl, m_flags.borderless = true; m_widgetControl = pWidgetControl; - m_panel = NULL; - m_scrollbarVertical = NULL; - m_scrollbarHorizontal = NULL; + m_panel = (CScrollingPanel *)NULL; + m_scrollbarVertical = (CScrollbarVertical *)NULL; + m_scrollbarHorizontal = (CScrollbarHorizontal *)NULL; buildUI(); } diff --git a/graphics/nxwidgets/src/cscrollbarvertical.cxx b/graphics/nxwidgets/src/cscrollbarvertical.cxx index 5b6670ba7..0ff40ad0b 100644 --- a/graphics/nxwidgets/src/cscrollbarvertical.cxx +++ b/graphics/nxwidgets/src/cscrollbarvertical.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxwidgets/include/cscrollbarhorizontal.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwidgets/src/cscrollinglistbox.cxx b/graphics/nxwidgets/src/cscrollinglistbox.cxx index 2667b8fc9..710dbb286 100644 --- a/graphics/nxwidgets/src/cscrollinglistbox.cxx +++ b/graphics/nxwidgets/src/cscrollinglistbox.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxwidgets/src/cscrollinglistbox.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwidgets/src/cscrollingpanel.cxx b/graphics/nxwidgets/src/cscrollingpanel.cxx index 80f51c87c..5f68abd57 100644 --- a/graphics/nxwidgets/src/cscrollingpanel.cxx +++ b/graphics/nxwidgets/src/cscrollingpanel.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxwidgets/src/cscrollingpanel.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -62,7 +60,7 @@ #include #include -#include +#include #include "graphics/nxwidgets/cwidgetcontrol.hxx" #include "graphics/nxwidgets/cscrollingpanel.hxx" @@ -360,7 +358,7 @@ void CScrollingPanel::scrollChildren(int32_t dx, int32_t dy, bool do_redraw) nxgl_coord_t widgetY = 0; nxgl_coord_t thisX = getX(); nxgl_coord_t thisY = getY(); - CNxWidget *widget = NULL; + CNxWidget *widget = (CNxWidget *)NULL; for (int32_t i = 0; i < m_children.size(); i++) { diff --git a/graphics/nxwidgets/src/cscrollingtextbox.cxx b/graphics/nxwidgets/src/cscrollingtextbox.cxx index 3ea6a51d4..658831b16 100644 --- a/graphics/nxwidgets/src/cscrollingtextbox.cxx +++ b/graphics/nxwidgets/src/cscrollingtextbox.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxwidgets/src/cscrollingtextbox.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwidgets/src/csliderhorizontal.cxx b/graphics/nxwidgets/src/csliderhorizontal.cxx index f2072493a..377887088 100644 --- a/graphics/nxwidgets/src/csliderhorizontal.cxx +++ b/graphics/nxwidgets/src/csliderhorizontal.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxwidgets/src/csliderhorizontal.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwidgets/src/csliderhorizontalgrip.cxx b/graphics/nxwidgets/src/csliderhorizontalgrip.cxx index 28fd1276a..4bfa8f4bc 100644 --- a/graphics/nxwidgets/src/csliderhorizontalgrip.cxx +++ b/graphics/nxwidgets/src/csliderhorizontalgrip.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxwidgets/src/csliderhorizontalgrip.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwidgets/src/cslidervertical.cxx b/graphics/nxwidgets/src/cslidervertical.cxx index 4dee4274b..c3666fc53 100644 --- a/graphics/nxwidgets/src/cslidervertical.cxx +++ b/graphics/nxwidgets/src/cslidervertical.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxwidgets/src/cslidervertical.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwidgets/src/csliderverticalgrip.cxx b/graphics/nxwidgets/src/csliderverticalgrip.cxx index 6fda9d8fd..11967d76b 100644 --- a/graphics/nxwidgets/src/csliderverticalgrip.cxx +++ b/graphics/nxwidgets/src/csliderverticalgrip.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxwidgets/src/cslidervertical.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwidgets/src/cstickybutton.cxx b/graphics/nxwidgets/src/cstickybutton.cxx index 2509c1db8..5a96690b0 100644 --- a/graphics/nxwidgets/src/cstickybutton.cxx +++ b/graphics/nxwidgets/src/cstickybutton.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxwidgets/src/cstickybutton.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwidgets/src/cstickybuttonarray.cxx b/graphics/nxwidgets/src/cstickybuttonarray.cxx index b52c2bf94..1799153fd 100644 --- a/graphics/nxwidgets/src/cstickybuttonarray.cxx +++ b/graphics/nxwidgets/src/cstickybuttonarray.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxwidgets/include/cstickybuttonarray.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwidgets/src/cstickyimage.cxx b/graphics/nxwidgets/src/cstickyimage.cxx index 346694c8c..b1edb59d7 100644 --- a/graphics/nxwidgets/src/cstickyimage.cxx +++ b/graphics/nxwidgets/src/cstickyimage.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxwidgets/src/cstickyimage.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwidgets/src/cstringiterator.cxx b/graphics/nxwidgets/src/cstringiterator.cxx index 301b3966d..98831419b 100644 --- a/graphics/nxwidgets/src/cstringiterator.cxx +++ b/graphics/nxwidgets/src/cstringiterator.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxwidgets/src/cgraphicsport.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwidgets/src/ctabpanel.cxx b/graphics/nxwidgets/src/ctabpanel.cxx index ea0b943a0..5c698425e 100644 --- a/graphics/nxwidgets/src/ctabpanel.cxx +++ b/graphics/nxwidgets/src/ctabpanel.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxwidgets/src/ctabpanel.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwidgets/src/ctext.cxx b/graphics/nxwidgets/src/ctext.cxx index 0da00793d..e68e9da21 100644 --- a/graphics/nxwidgets/src/ctext.cxx +++ b/graphics/nxwidgets/src/ctext.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxwidgets/src/ctext.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwidgets/src/ctextbox.cxx b/graphics/nxwidgets/src/ctextbox.cxx index 9e04650cc..a8ede069a 100644 --- a/graphics/nxwidgets/src/ctextbox.cxx +++ b/graphics/nxwidgets/src/ctextbox.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxwidgets/src/ctextbox.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwidgets/src/cwidgetcontrol.cxx b/graphics/nxwidgets/src/cwidgetcontrol.cxx index 3107d7729..eeb5e4180 100644 --- a/graphics/nxwidgets/src/cwidgetcontrol.cxx +++ b/graphics/nxwidgets/src/cwidgetcontrol.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxwidgets/src/cwidgetcontrol.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -29,10 +27,9 @@ #include #include #include +#include #include - -#include -#include +#include #include "graphics/nxwidgets/nxconfig.hxx" #include "graphics/nxwidgets/cnxserver.hxx" @@ -71,10 +68,10 @@ CWidgetControl::CWidgetControl(FAR const CWidgetStyle *style) { // Initialize state - m_port = NULL; + m_port = (CGraphicsPort *)NULL; m_haveGeometry = false; - m_clickedWidget = NULL; - m_focusedWidget = NULL; + m_clickedWidget = (CNxWidget *)NULL; + m_focusedWidget = (CNxWidget *)NULL; // Initialize data that we will get from the position callback @@ -112,7 +109,7 @@ CWidgetControl::CWidgetControl(FAR const CWidgetStyle *style) // Do we need to fetch the default style? - if (style == NULL) + if (style == (CWidgetStyle *)NULL) { // Get the style from the controlling widget @@ -314,7 +311,7 @@ void CWidgetControl::setClickedWidget(CNxWidget *widget) { // Do we have a clicked widget already? - if (m_clickedWidget != NULL) + if (m_clickedWidget != (CNxWidget *)NULL) { // Ensure that the existing clicked widget is released *outside* its bounds @@ -647,7 +644,7 @@ bool CWidgetControl::createGraphicsPort(INxWindow *window) #else m_port = new CGraphicsPort(window); #endif - return m_port != NULL; + return m_port != (CGraphicsPort *)NULL; } /** @@ -734,7 +731,7 @@ bool CWidgetControl::handleLeftClick(nxgl_coord_t x, nxgl_coord_t y, { // Working with a specific widget or the whole structure? - if (widget == NULL) + if (widget == (CNxWidget *)NULL) { // All widgets @@ -803,7 +800,7 @@ bool CWidgetControl::pollMouseEvents(CNxWidget *widget) { // The left button is still being held down - if (m_clickedWidget != NULL) + if (m_clickedWidget != (CNxWidget *)NULL) { // Handle a mouse drag event @@ -816,7 +813,7 @@ bool CWidgetControl::pollMouseEvents(CNxWidget *widget) // Check for release event on the clicked widget - if (!mouseEvent && m_clickedWidget != NULL) + if (!mouseEvent && m_clickedWidget != (CNxWidget *)NULL) { // Mouse left button release event @@ -851,7 +848,7 @@ bool CWidgetControl::pollKeyboardEvents(void) // Keyboard presses with no focused widget is not an interesting // event - if (m_focusedWidget != NULL) + if (m_focusedWidget != (CNxWidget *)NULL) { // Forward each character to the widget with the focus @@ -881,7 +878,7 @@ bool CWidgetControl::pollCursorControlEvents(void) // Cursor controls with no focused widget is not an interesting // event - if (m_focusedWidget != NULL) + if (m_focusedWidget != (CNxWidget *)NULL) { // Forward each cursor control to the widget with the focus diff --git a/graphics/nxwidgets/src/cwidgeteventhandlerlist.cxx b/graphics/nxwidgets/src/cwidgeteventhandlerlist.cxx index c96d7d28f..293872c55 100644 --- a/graphics/nxwidgets/src/cwidgeteventhandlerlist.cxx +++ b/graphics/nxwidgets/src/cwidgeteventhandlerlist.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxwidgets/src/cwidgeteventhandlerlist.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwidgets/src/cwindoweventhandlerlist.cxx b/graphics/nxwidgets/src/cwindoweventhandlerlist.cxx index 253f08f3a..80fd051b2 100644 --- a/graphics/nxwidgets/src/cwindoweventhandlerlist.cxx +++ b/graphics/nxwidgets/src/cwindoweventhandlerlist.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxwidgets/src/cwindoweventhandlerlist.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -145,8 +143,8 @@ void CWindowEventHandlerList::raiseKeyboardEvent(void) { m_eventHandlers.at(i)->handleKeyboardEvent(); } -} #endif +} /** * Raise an NX window blocked event. diff --git a/graphics/nxwidgets/src/singletons.cxx b/graphics/nxwidgets/src/singletons.cxx index a6e44797c..6dcf24e26 100644 --- a/graphics/nxwidgets/src/singletons.cxx +++ b/graphics/nxwidgets/src/singletons.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxwidgets/src/singletons.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -64,7 +62,7 @@ #include #include #include -#include +#include #include "graphics/nxwidgets/nxconfig.hxx" #include "graphics/nxwidgets/cnxserver.hxx" @@ -161,7 +159,7 @@ void NXWidgets::freeSingletons(void) if (g_nullString) { delete g_nullString; - g_nullString = NULL; + g_nullString = (CNxString *)NULL; } // Delete the default widget style singleton @@ -174,7 +172,7 @@ void NXWidgets::freeSingletons(void) } delete g_defaultWidgetStyle; - g_defaultWidgetStyle = NULL; + g_defaultWidgetStyle = (CWidgetStyle *)NULL; } // Free the timer list @@ -182,7 +180,7 @@ void NXWidgets::freeSingletons(void) if (g_nxTimers) { delete g_nxTimers; - g_nxTimers = NULL; + g_nxTimers = (TNxArray *)NULL; } } diff --git a/graphics/nxwm/Doxygen/Doxyfile b/graphics/nxwm/Doxygen/Doxyfile index b80c12a02..45ab1094e 100644 --- a/graphics/nxwm/Doxygen/Doxyfile +++ b/graphics/nxwm/Doxygen/Doxyfile @@ -63,7 +63,7 @@ CREATE_SUBDIRS = NO OUTPUT_LANGUAGE = English # If the BRIEF_MEMBER_DESC tag is set to YES (the default) Doxygen will -# include brief member descriptions after the members that are listed in +# include brief member descriptions after the members that are listed in # the file and class documentation (similar to JavaDoc). # Set to NO to disable this. @@ -1084,7 +1084,7 @@ USE_PDFLATEX = YES LATEX_BATCHMODE = NO # If LATEX_HIDE_INDICES is set to YES then doxygen will not -# include the index chapters (such as File Index, Compound Index, etc.) +# include the index chapters (such as File Index, Compound Index, etc.) # in the output. LATEX_HIDE_INDICES = NO diff --git a/graphics/nxwm/Doxygen/README.md b/graphics/nxwm/Doxygen/README.md new file mode 100644 index 000000000..cf4436347 --- /dev/null +++ b/graphics/nxwm/Doxygen/README.md @@ -0,0 +1,68 @@ +# Graphics / `nxwm` NxWM / Doxygen + +This directory contains the documentation automatically generated by Doxygen. + +## Contents + +- Installing the necessary packages in Ubuntu +- Generating documentation +- References + +## Installing the necessary packages in Ubuntu + +1. Install the following packages. + + ```bash + $ sudo aptitude install doxygen doxygen-doc doxygen-gui dot2tex graphviz + ``` + +2. (Optional) Install Doxygen from the latest sourcode. + + The Ubuntu package is outdated. The newer the version of Doxygen, the better + the documentation looks. + + Place yourself in some temporary folder where you can download the source, + and run [1]: + + ```bash + $ svn co https://doxygen.svn.sourceforge.net/svnroot/doxygen/trunk doxygen-svn + $ cd doxygen-svn + $ ./configure + $ make + $ make install + ``` + +## Generating documentation + +Two ways described here: + +1. Use the provided `gendoc.sh` script. + + ```bash + trunk/NXWidgets/Doxygen/gendoc.sh + ``` + + The script only needs the argument to the absolute path where to place the + generated documentation. I.e.: + + ```bash + $ cd /path/to/nuttx/trunk/NXWidgets/Doxygen/ + $ mkdir doc + $ ./gendoc.sh $PWD/doc + ``` + +2. Using the `Doxyfile` directly: + + The file `Doxyfile` contains the configuration of the Doxygen settings for + the run, edit only if necessary. + + To generate the documentation type: + + ```bash + $ cd /path/to/nuttx/trunk/NXWidgets/Doxygen/ + $ doxygen Doxyfile + ``` + +## References + +[1] http://www.stack.nl/~dimitri/doxygen/download.html diff --git a/graphics/nxwm/Doxygen/gendoc.sh b/graphics/nxwm/Doxygen/gendoc.sh index 5fe931e91..e3dcdb7e8 100644 --- a/graphics/nxwm/Doxygen/gendoc.sh +++ b/graphics/nxwm/Doxygen/gendoc.sh @@ -2,8 +2,6 @@ ################################################################################# # apps/graphics/nxwm/Doxygen/gendoc.sh # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwm/Kconfig b/graphics/nxwm/Kconfig index ab0fe9209..ab1018ce3 100644 --- a/graphics/nxwm/Kconfig +++ b/graphics/nxwm/Kconfig @@ -124,7 +124,8 @@ comment "Background Image" config NXWM_DISABLE_BACKGROUND_IMAGE bool "Disable Background Image" - default NXWM_DISABLE_MINIMIZE + default n if !NXWM_DISABLE_MINIMIZE + default y if NXWM_DISABLE_MINIMIZE ---help--- Disable support for the "Desktop" background image. @@ -464,7 +465,8 @@ menu "NxWM Touchscreen Configuration" config NXWM_TOUCHSCREEN bool "Touchscreen Support" - default INPUT + default y if INPUT + default n if !INPUT ---help--- Define to build in touchscreen support. @@ -487,10 +489,10 @@ config NXWM_TOUCHSCREEN_DEVPATH config NXWM_TOUCHSCREEN_SIGNO int "Touchscreen Signal Number" - default 32 + default 5 ---help--- The realtime signal used to wake up the touchscreen listener - thread. Default: 32 + thread. Default: 5 config NXWM_TOUCHSCREEN_LISTENERPRIO int "Touchscreen Listener Task Priority" @@ -550,10 +552,10 @@ config NXWM_KEYBOARD_USBHOST config NXWM_KEYBOARD_SIGNO int "Keyboard Task Signal Number" - default 33 + default 6 ---help--- The realtime signal used to wake up the keyboard listener thread. - Default: 33 + Default: 6 config NXWM_KEYBOARD_BUFSIZE int "Keyboard Buffer Size" @@ -727,10 +729,10 @@ endif # NXWM_CUSTOM_CALIBRATION_ICON config NXWM_CALIBRATION_SIGNO int "Calibration Signal Number" - default 32 + default 5 ---help--- The realtime signal used to wake up the touchscreen calibration - thread. Default: 32 + thread. Default: 5 config NXWM_CALIBRATION_LISTENERPRIO int "Calibration Task Priority" @@ -920,7 +922,7 @@ config NXWM_MEDIAPLAYER_CUSTOM_COLORS if NXWM_MEDIAPLAYER_CUSTOM_COLORS -config NXWM_MEDIAPLAYER_VOLUMECOLOR + config NXWM_MEDIAPLAYER_VOLUMECOLOR hex "Media Volume Slide Color" default 0x0 diff --git a/graphics/nxwm/Make.defs b/graphics/nxwm/Make.defs index 6161418d0..68e492a23 100644 --- a/graphics/nxwm/Make.defs +++ b/graphics/nxwm/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/graphics/nxwm/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwm/Makefile b/graphics/nxwm/Makefile index 4b1028c2e..b643ee02a 100644 --- a/graphics/nxwm/Makefile +++ b/graphics/nxwm/Makefile @@ -1,8 +1,6 @@ ################################################################################# # apps/graphics/nxwm/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwm/README.md b/graphics/nxwm/README.md new file mode 100644 index 000000000..2578a46f2 --- /dev/null +++ b/graphics/nxwm/README.md @@ -0,0 +1,27 @@ +# Graphics / `nxwm` NxWM + +This directory holds a tiny desktop for small embedded devices with a +touchscreen,. NxWM. NxWM is true multiple window manager but only one window is +displayed at a time. This simplification helps performance on LCD based products +(in the same way that a tiled window manager helps) and also makes the best use +of small displays. It is awkward from a human factors point-of-view trying to +manage multiple windows on a small display. + +The window manager consists of a task bar with icons representing the running +tasks. If you touch the task's icon, it comes to the top. Each window has a +toolbar with (1) a title, (2) a minimize button, and (3) a stop application +button using the standard icons for these things. + +There is always a start window that is available in the task bar. When you touch +the start window icon, it brings up the start window containing icons +representing all of the available applications. If you touch an icon in the +start window, it will be started and added to the task bar. + +There is a base class that defines an add-on application and an interface that +supports incorporation of new application. The only application that is provided +is NxTerm. This is an NSH session running in a window. You should be able to +select the NX icon in the start menu and create as many NSH sessions in windows +as you want. (keybard input still comes through serial). + +Note 1: NwWM requires `NuttX-7.19` or above to work with the current +`NxWidgets-1.18` release. diff --git a/graphics/nxwm/src/capplicationwindow.cxx b/graphics/nxwm/src/capplicationwindow.cxx index 659db97ad..d3b5ba131 100644 --- a/graphics/nxwm/src/capplicationwindow.cxx +++ b/graphics/nxwm/src/capplicationwindow.cxx @@ -1,8 +1,6 @@ /******************************************************************************************** * apps/graphics/nxwm/src/capplicationwindow.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwm/src/ccalibration.cxx b/graphics/nxwm/src/ccalibration.cxx index 262a9d567..e13bdb52b 100644 --- a/graphics/nxwm/src/ccalibration.cxx +++ b/graphics/nxwm/src/ccalibration.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nxwm/src/ccalibration.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -25,13 +23,13 @@ ****************************************************************************/ #include +#include #include #include #include #include -#include -#include +#include #ifdef CONFIG_NXWM_TOUCHSCREEN_CONFIGDATA # include "platform/configdata.h" @@ -630,7 +628,7 @@ FAR void *CCalibration::calibration(FAR void *arg) { // Sleep for a while (or until we receive a signal) - usleep(500*1000); + std::usleep(500*1000); } else { diff --git a/graphics/nxwm/src/cfullscreenwindow.cxx b/graphics/nxwm/src/cfullscreenwindow.cxx index ccaf6300d..4873d633f 100644 --- a/graphics/nxwm/src/cfullscreenwindow.cxx +++ b/graphics/nxwm/src/cfullscreenwindow.cxx @@ -1,8 +1,6 @@ /******************************************************************************************** * apps/graphics/nxwm/src/cfullscreenwindow.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/nxwm/src/chexcalculator.cxx b/graphics/nxwm/src/chexcalculator.cxx index 3ba68eac3..ed4105991 100644 --- a/graphics/nxwm/src/chexcalculator.cxx +++ b/graphics/nxwm/src/chexcalculator.cxx @@ -1,8 +1,6 @@ /******************************************************************************************** * apps/graphics/nxwm/src/chexcalculator.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -27,7 +25,7 @@ #include #include -#include +#include #include "graphics/nxwidgets/cwidgetcontrol.hxx" @@ -734,7 +732,7 @@ void CHexCalculator::handleActionEvent(const NXWidgets::CWidgetEventArgs &e) if (m_result) { - m_accum = g_keyDesc[index].value; + m_accum = (uint64_t)g_keyDesc[index].value; } // Otherwise, add the new value to the accumulator. The way @@ -743,12 +741,12 @@ void CHexCalculator::handleActionEvent(const NXWidgets::CWidgetEventArgs &e) else if (m_hexMode) { m_accum <<= 4; - m_accum |= g_keyDesc[index].value; + m_accum |= (uint64_t)g_keyDesc[index].value; } else { m_accum *= 10; - m_accum += g_keyDesc[index].value; + m_accum += (uint64_t)g_keyDesc[index].value; } updateText(); } diff --git a/graphics/nxwm/src/ckeyboard.cxx b/graphics/nxwm/src/ckeyboard.cxx index 7afb0b0ae..73cde0258 100644 --- a/graphics/nxwm/src/ckeyboard.cxx +++ b/graphics/nxwm/src/ckeyboard.cxx @@ -1,8 +1,6 @@ /******************************************************************************************** * apps/graphics/nxwm/src/ckeyboard.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -26,14 +24,14 @@ #include +#include #include +#include -#include #include #include #include -#include -#include +#include #include "graphics/nxwm/nxwmconfig.hxx" #include "graphics/nxwm/ckeyboard.hxx" @@ -86,7 +84,7 @@ CKeyboard::~CKeyboard(void) if (m_kbdFd >= 0) { - close(m_kbdFd); + std::close(m_kbdFd); } } @@ -169,7 +167,7 @@ int CKeyboard::open(void) { // Try to open the keyboard device - fd = ::open(CONFIG_NXWM_KEYBOARD_DEVPATH, O_RDONLY); + fd = std::open(CONFIG_NXWM_KEYBOARD_DEVPATH, O_RDONLY); if (fd < 0) { int errcode = errno; @@ -188,14 +186,14 @@ int CKeyboard::open(void) if (errcode == ENOENT || errcode == ENODEV) { - // REVISIT: Can we inject a constant string here to let the + // REVIST: Can we inject a constant string here to let the // user know that we are waiting for a USB keyboard to be // connected? // Sleep a bit and try again ginfo("WAITING for a USB device\n"); - sleep(2); + std::sleep(2); } // Anything else would be really bad. @@ -368,7 +366,7 @@ FAR void *CKeyboard::listener(FAR void *arg) // Close the keyboard device - close(This->m_kbdFd); + std::close(This->m_kbdFd); This->m_kbdFd = -1; } diff --git a/graphics/nxwm/src/cmediaplayer.cxx b/graphics/nxwm/src/cmediaplayer.cxx index 8561eb469..72c1895cc 100644 --- a/graphics/nxwm/src/cmediaplayer.cxx +++ b/graphics/nxwm/src/cmediaplayer.cxx @@ -1,8 +1,6 @@ /******************************************************************************************** * apps/graphics/nxwm/src/cmediaplayer.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -33,7 +31,7 @@ #include #include #include -#include +#include #include "system/nxplayer.h" #include diff --git a/graphics/nxwm/src/cnxterm.cxx b/graphics/nxwm/src/cnxterm.cxx index 40bc5997b..c2391bdd2 100644 --- a/graphics/nxwm/src/cnxterm.cxx +++ b/graphics/nxwm/src/cnxterm.cxx @@ -1,8 +1,6 @@ /******************************************************************************************** * apps/graphics/nxwm/src/cnxterm.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -28,6 +26,7 @@ #include #include +#include #include #include @@ -35,8 +34,7 @@ #include #include #include -#include -#include +#include #include "nshlib/nshlib.h" @@ -333,7 +331,7 @@ void CNxTerm::stop(void) // Construct the driver name using this minor number char devname[32]; - snprintf(devname, sizeof(devname), "/dev/nxterm%d", m_minor); + snprintf(devname, 32, "/dev/nxterm%d", m_minor); unlink(devname); m_nxterm = 0; @@ -462,7 +460,7 @@ int CNxTerm::nxterm(int argc, char *argv[]) // Construct the driver name using this minor number char devname[32]; - snprintf(devname, sizeof(devname), "/dev/nxterm%d", g_nxtermvars.minor); + snprintf(devname, 32, "/dev/nxterm%d", g_nxtermvars.minor); // Increment the minor number while it is protect by the semaphore @@ -491,16 +489,16 @@ int CNxTerm::nxterm(int argc, char *argv[]) std::fflush(stderr); #ifdef CONFIG_NXTERM_NXKBDIN - dup2(fd, 0); + std::dup2(fd, 0); #endif - dup2(fd, 1); - dup2(fd, 2); + std::dup2(fd, 1); + std::dup2(fd, 2); // And we can close our original driver file descriptor if (fd > 2) { - ::close(fd); + std::close(fd); } // Inform the parent thread that we successfully initialized @@ -655,5 +653,19 @@ bool NxWM::nshlibInitialize(void) // Initialize the NSH library nsh_initialize(); + + // If the Telnet console is selected as a front-end, then start the + // Telnet daemon. + +#ifdef CONFIG_NSH_TELNET + int ret = nsh_telnetstart(AF_UNSPEC); + if (ret < 0) + { + // The daemon is NOT running! + + return false; + } +#endif + return true; } diff --git a/graphics/nxwm/src/cstartwindow.cxx b/graphics/nxwm/src/cstartwindow.cxx index 8ee409e27..c4fa30e27 100644 --- a/graphics/nxwm/src/cstartwindow.cxx +++ b/graphics/nxwm/src/cstartwindow.cxx @@ -1,8 +1,6 @@ /******************************************************************************************** * apps/graphics/nxwm/src/cstartwindow.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -27,11 +25,10 @@ #include #include +#include +#include #include -#include -#include - #include "graphics/nxwidgets/cwidgetcontrol.hxx" #include "graphics/nxwm/nxwmconfig.hxx" diff --git a/graphics/nxwm/src/ctaskbar.cxx b/graphics/nxwm/src/ctaskbar.cxx index 7160b93d9..ede31776e 100644 --- a/graphics/nxwm/src/ctaskbar.cxx +++ b/graphics/nxwm/src/ctaskbar.cxx @@ -1,8 +1,6 @@ /******************************************************************************************** * apps/graphics/nxwm/src/ctaskbar.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -26,7 +24,7 @@ #include -#include +#include #include @@ -617,7 +615,7 @@ bool CTaskbar::maximizeApplication(IApplication *app) /** * Minimize an application by moving its window to the bottom of the and - * redrawing the next visible application. + * redrawing the next visible appliation. * * @param app. The new application to add to the task bar * @return true on success @@ -755,7 +753,7 @@ NXWidgets::CNxWindow *CTaskbar::openRawWindow(void) { // Create the widget control (with the window messenger) using the default style - CWindowMessenger *control = new CWindowMessenger(NULL); + CWindowMessenger *control = new CWindowMessenger((NXWidgets::CWidgetStyle *)NULL); // Get an (uninitialized) instance of the background window as a class // that derives from INxWindow. @@ -792,7 +790,7 @@ NXWidgets::CNxTkWindow *CTaskbar::openFramedWindow(void) { // Create the widget control (with the window messenger) using the default style - CWindowMessenger *control = new CWindowMessenger(NULL); + CWindowMessenger *control = new CWindowMessenger((NXWidgets::CWidgetStyle *)NULL); // Get an (uninitialized) instance of the framed window as a class // that derives from INxWindow. @@ -959,7 +957,7 @@ bool CTaskbar::createTaskbarWindow(void) bool CTaskbar::createBackgroundWindow(void) { - CWindowMessenger *control = new CWindowMessenger(NULL); + CWindowMessenger *control = new CWindowMessenger((NXWidgets::CWidgetStyle *)NULL); // Create a raw window to present the background image diff --git a/graphics/nxwm/src/ctouchscreen.cxx b/graphics/nxwm/src/ctouchscreen.cxx index b7807c710..d4e10052a 100644 --- a/graphics/nxwm/src/ctouchscreen.cxx +++ b/graphics/nxwm/src/ctouchscreen.cxx @@ -1,8 +1,6 @@ /******************************************************************************************** * apps/graphics/nxwm/src/ctouchscreen.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -27,15 +25,16 @@ #include #include +#include #include +#include #include -#include + #include #include #include -#include -#include +#include #include @@ -104,7 +103,7 @@ CTouchscreen::~CTouchscreen(void) if (m_touchFd >= 0) { - close(m_touchFd); + std::close(m_touchFd); } // Destroy the semaphores that we created. @@ -181,7 +180,7 @@ void CTouchscreen::setCalibrationData(const struct SCalibrationData &caldata) m_calibData = caldata; // Note that we have calibration data. Data will now be scaled and forwarded - // to NX (unless we are still in capture mode) + // to NX (unless we are still in cpature mode) m_calibrated = true; @@ -205,7 +204,7 @@ bool CTouchscreen::waitRawTouchData(struct touch_sample_s *touch) { _info("Capturing touch input\n"); - // Setup to capture raw data into the user provided buffer + // Setup to cpature raw data into the user provided buffer sched_lock(); m_touch = touch; @@ -254,7 +253,7 @@ FAR void *CTouchscreen::listener(FAR void *arg) // Open the touchscreen device that we just created. - This->m_touchFd = open(CONFIG_NXWM_TOUCHSCREEN_DEVPATH, O_RDONLY); + This->m_touchFd = std::open(CONFIG_NXWM_TOUCHSCREEN_DEVPATH, O_RDONLY); if (This->m_touchFd < 0) { gerr("ERROR Failed to open %s for reading: %d\n", diff --git a/graphics/nxwm/src/cwindowmessenger.cxx b/graphics/nxwm/src/cwindowmessenger.cxx index 92a2ba91a..7262ff745 100644 --- a/graphics/nxwm/src/cwindowmessenger.cxx +++ b/graphics/nxwm/src/cwindowmessenger.cxx @@ -1,8 +1,6 @@ /******************************************************************************************** * apps/graphics/nxwm/src/cwindowmessenger.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -26,10 +24,10 @@ #include +#include #include -#include -#include +#include #include "graphics/nxwm/nxwmconfig.hxx" #include "graphics/nxwm/cstartwindow.hxx" diff --git a/graphics/nxwm/src/nxwm_main.cxx b/graphics/nxwm/src/nxwm_main.cxx index 6b6a3ca1d..7365ea92c 100644 --- a/graphics/nxwm/src/nxwm_main.cxx +++ b/graphics/nxwm/src/nxwm_main.cxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/graphics/nxwm/src/nxwm_main.cxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -28,8 +26,8 @@ #include #include +#include -#include #include #ifdef CONFIG_NXWM_TOUCHSCREEN_CONFIGDATA @@ -485,6 +483,16 @@ static bool createMediaPlayer(void) int main(int argc, char *argv[]) { +#if defined(CONFIG_BOARDCTL) && !defined(CONFIG_BOARD_LATE_INITIALIZE) + // Should we perform board-specific initialization? There are two ways + // that board initialization can occur: 1) automatically via + // board_late_initialize() during bootup if CONFIG_BOARD_LATE_INITIALIZE, or + // 2) here via a call to boardctl() if the interface is enabled + // (CONFIG_BOARDCTL=y). + + boardctl(BOARDIOC_INIT, 0); +#endif + #ifdef CONFIG_NXWM_NXTERM // Initialize the NSH library @@ -596,7 +604,7 @@ int main(int argc, char *argv[]) printf("nxwm_main: Waiting for touchscreen calibration\n"); while (!g_nxwmtest.touchscreen->isCalibrated()) { - sleep(2); + std::sleep(2); } // This is how we would then recover the calibration data. After the diff --git a/graphics/pdcurs34/Make.defs b/graphics/pdcurs34/Make.defs index 6db199357..13a8520a7 100644 --- a/graphics/pdcurs34/Make.defs +++ b/graphics/pdcurs34/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/graphics/pdcurs34/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -20,6 +18,6 @@ # ############################################################################ -ifneq ($(CONFIG_GRAPHICS_PDCURSES),) +ifeq ($(CONFIG_GRAPHICS_PDCURSES),y) CONFIGURED_APPS += $(APPDIR)/graphics/pdcurs34 endif diff --git a/graphics/pdcurs34/Makefile b/graphics/pdcurs34/Makefile index e07f2fc1e..56d3c9bb8 100644 --- a/graphics/pdcurs34/Makefile +++ b/graphics/pdcurs34/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/graphics/pdcurs34/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -26,6 +24,6 @@ include $(APPDIR)/Make.defs include pdcurses/Make.defs include nuttx/Make.defs -CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/graphics/pdcurs34/include +CFLAGS += ${shell $(INCDIR) "$(CC)" $(APPDIR)/graphics/pdcurs34/include} include $(APPDIR)/Application.mk diff --git a/graphics/pdcurs34/include/curspriv.h b/graphics/pdcurs34/include/curspriv.h index 68e702bf4..c921f5129 100644 --- a/graphics/pdcurs34/include/curspriv.h +++ b/graphics/pdcurs34/include/curspriv.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/pdcurses/curspriv.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -63,10 +61,10 @@ /* Internal macros for attributes */ #ifndef max -# define max(a,b) (((a) > (b)) ? (a) : (b)) +# define max(a,b) (((a) > (b)) ? (a) : (b)) #endif #ifndef min -# define min(a,b) (((a) < (b)) ? (a) : (b)) +# define min(a,b) (((a) < (b)) ? (a) : (b)) #endif #define DIVROUND(num, divisor) ((num) + ((divisor) >> 1)) / (divisor) diff --git a/graphics/pdcurs34/include/term.h b/graphics/pdcurs34/include/term.h index 06230d368..2298f1def 100644 --- a/graphics/pdcurs34/include/term.h +++ b/graphics/pdcurs34/include/term.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/pdcurses/term.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/pdcurs34/nuttx/Make.defs b/graphics/pdcurs34/nuttx/Make.defs index 5ed3728be..d6e691a00 100644 --- a/graphics/pdcurs34/nuttx/Make.defs +++ b/graphics/pdcurs34/nuttx/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/graphics/pdcurs34/nuttx/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -29,4 +27,4 @@ endif DEPPATH += --dep-path nuttx VPATH += :nuttx -CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/graphics/pdcurs34/nuttx +CFLAGS += ${shell $(INCDIR) "$(CC)" $(APPDIR)/graphics/pdcurs34/nuttx} diff --git a/graphics/pdcurs34/nuttx/pdcclip.c b/graphics/pdcurs34/nuttx/pdcclip.c index a938d7c63..476db525d 100644 --- a/graphics/pdcurs34/nuttx/pdcclip.c +++ b/graphics/pdcurs34/nuttx/pdcclip.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nuttx/pdclip.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/pdcurs34/nuttx/pdcdisp.c b/graphics/pdcurs34/nuttx/pdcdisp.c index 428d24b70..35ea45dba 100644 --- a/graphics/pdcurs34/nuttx/pdcdisp.c +++ b/graphics/pdcurs34/nuttx/pdcdisp.c @@ -1,7 +1,5 @@ /**************************************************************************** - * apps/graphics/pdcurs34/nuttx/pdcdisp.c - * - * SPDX-License-Identifier: Apache-2.0 + * apps/graphics/nuttx/pdcdisp.c * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -27,7 +25,6 @@ #include #include #include -#include #ifdef CONFIG_SYSTEM_TERMCURSES #include @@ -59,7 +56,7 @@ #ifdef CONFIG_PDCURSES_CHTYPE_LONG -# define A(x) ((chtype)x | A_ALTCHARSET) +# define A(x) ((chtype)x | A_ALTCHARSET) chtype acs_map[128] = { diff --git a/graphics/pdcurs34/nuttx/pdcgetsc.c b/graphics/pdcurs34/nuttx/pdcgetsc.c index 8bbda5885..ce7ad1d88 100644 --- a/graphics/pdcurs34/nuttx/pdcgetsc.c +++ b/graphics/pdcurs34/nuttx/pdcgetsc.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nuttx/pdcgetsc.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/pdcurs34/nuttx/pdckbd.c b/graphics/pdcurs34/nuttx/pdckbd.c index eeac7245f..f11280fe0 100644 --- a/graphics/pdcurs34/nuttx/pdckbd.c +++ b/graphics/pdcurs34/nuttx/pdckbd.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nuttx/pdckbd.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/pdcurs34/nuttx/pdcnuttx.h b/graphics/pdcurs34/nuttx/pdcnuttx.h index 40c085848..00760278e 100644 --- a/graphics/pdcurs34/nuttx/pdcnuttx.h +++ b/graphics/pdcurs34/nuttx/pdcnuttx.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nuttx/pdcnuttx.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/pdcurs34/nuttx/pdcscrn.c b/graphics/pdcurs34/nuttx/pdcscrn.c index 762041243..fccc3f166 100644 --- a/graphics/pdcurs34/nuttx/pdcscrn.c +++ b/graphics/pdcurs34/nuttx/pdcscrn.c @@ -1,7 +1,5 @@ /**************************************************************************** - * apps/graphics/pdcurs34/nuttx/pdcscrn.c - * - * SPDX-License-Identifier: Apache-2.0 + * apps/graphics/nuttx/pdcscrn.c * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -33,7 +31,6 @@ #include #include #include -#include #include #include "pdcnuttx.h" @@ -64,8 +61,7 @@ bool graphic_screen = false; #ifdef CONFIG_SYSTEM_TERMCURSES static void PDC_scr_free_term(FAR SCREEN *sp) { - FAR struct pdc_termscreen_s *termscreen = - (FAR struct pdc_termscreen_s *)sp; + FAR struct pdc_termscreen_s *termscreen = (FAR struct pdc_termscreen_s *)sp; FAR struct pdc_termstate_s *termstate = &termscreen->termstate; /* Deinitialize termcurses */ @@ -149,8 +145,7 @@ static int PDC_scr_open_term(int argc, char **argv) ret = termcurses_getwinsize(termstate->tcurs, &winsz); if (ret != OK) { - PDC_LOG(("ERROR: Terminal termcurses driver doesn't support size " - "reporting\n")); + PDC_LOG(("ERROR: Terminal termcurses driver doesn't support size reporting\n")); free(termscreen); return ERR; } @@ -161,8 +156,8 @@ static int PDC_scr_open_term(int argc, char **argv) SP->cols = winsz.ws_col; termscreen->termstate.out_fd = 1; termscreen->termstate.in_fd = 0; - termscreen->termstate.fg_red = 0xfffe; - termscreen->termstate.bg_red = 0xfffe; + termscreen->termstate.fg_red = 0xFFFE; + termscreen->termstate.bg_red = 0xFFFE; termstate = &termscreen->termstate; /* Setup initial RGB colors */ @@ -177,7 +172,7 @@ static int PDC_scr_open_term(int argc, char **argv) greylevel += (i & COLOR_BLUE) ? 0x40 : 0; termstate->greylevel[i] = greylevel; - termstate->greylevel[i + 8] = greylevel | 0x3f; + termstate->greylevel[i+8] = greylevel | 0x3f; #else termstate->rgbcolor[i].red = (i & COLOR_RED) ? 0xc0 : 0; termstate->rgbcolor[i].green = (i & COLOR_GREEN) ? 0xc0 : 0; @@ -212,20 +207,18 @@ static int PDC_scr_open_term(int argc, char **argv) * Name: PDC_init_pair_term * * Description: - * The core of init_pair(). This does all the work of that function, - * except checking for values out of range. The values passed to this - * function should be returned by a call to PDC_pair_content() with the - * same pair number. PDC_transform_line() should use the specified colors - * when rendering a chtype with the given pair number. + * The core of init_pair(). This does all the work of that function, except + * checking for values out of range. The values passed to this function + * should be returned by a call to PDC_pair_content() with the same pair + * number. PDC_transform_line() should use the specified colors when + * rendering a chtype with the given pair number. * ****************************************************************************/ #ifdef CONFIG_SYSTEM_TERMCURSES -static void PDC_init_pair_term(FAR SCREEN *sp, short pair, - short fg, short bg) +static void PDC_init_pair_term(FAR SCREEN *sp, short pair, short fg, short bg) { - FAR struct pdc_termscreen_s *termscreen = - (FAR struct pdc_termscreen_s *)sp; + FAR struct pdc_termscreen_s *termscreen = (FAR struct pdc_termscreen_s *)sp; termscreen->termstate.colorpair[pair].fg = fg; termscreen->termstate.colorpair[pair].bg = bg; @@ -245,8 +238,7 @@ static void PDC_init_pair_term(FAR SCREEN *sp, short pair, int PDC_init_color_term(FAR SCREEN *sp, short color, short red, short green, short blue) { - FAR struct pdc_termscreen_s *termscreen = - (FAR struct pdc_termscreen_s *)sp; + FAR struct pdc_termscreen_s *termscreen = (FAR struct pdc_termscreen_s *)sp; FAR struct pdc_termstate_s *termstate; DEBUGASSERT(termscreen != NULL); @@ -280,8 +272,7 @@ int PDC_init_color_term(FAR SCREEN *sp, short color, short red, short green, int PDC_color_content_term(FAR SCREEN *sp, short color, FAR short *red, FAR short *green, FAR short *blue) { - FAR struct pdc_termscreen_s *termscreen = - (FAR struct pdc_termscreen_s *)sp; + FAR struct pdc_termscreen_s *termscreen = (FAR struct pdc_termscreen_s *)sp; FAR struct pdc_termstate_s *termstate; DEBUGASSERT(termscreen != NULL); @@ -312,11 +303,9 @@ int PDC_color_content_term(FAR SCREEN *sp, short color, ****************************************************************************/ #ifdef CONFIG_SYSTEM_TERMCURSES -static int PDC_pair_content_term(FAR SCREEN *sp, short pair, - FAR short *fg, FAR short *bg) +static int PDC_pair_content_term(FAR SCREEN *sp, short pair, short *fg, short *bg) { - FAR struct pdc_termscreen_s *termscreen = - (FAR struct pdc_termscreen_s *)sp; + FAR struct pdc_termscreen_s *termscreen = (FAR struct pdc_termscreen_s *)sp; *fg = termscreen->termstate.colorpair[pair].fg; *bg = termscreen->termstate.colorpair[pair].bg; @@ -453,8 +442,7 @@ int PDC_scr_open(int argc, char **argv) /* Allocate the global instance of SP */ - fbscreen = - (FAR struct pdc_fbscreen_s *)zalloc(sizeof(struct pdc_fbscreen_s)); + fbscreen = (FAR struct pdc_fbscreen_s *)zalloc(sizeof(struct pdc_fbscreen_s)); if (fbscreen == NULL) { PDC_LOG(("ERROR: Failed to allocate SP\n")); @@ -485,7 +473,7 @@ int PDC_scr_open(int argc, char **argv) greylevel += (i & COLOR_BLUE) ? 0x40 : 0; fbstate->greylevel[i] = greylevel; - fbstate->greylevel[i + 8] = greylevel | 0x3f; + fbstate->greylevel[i+8] = greylevel | 0x3f; #else fbstate->rgbcolor[i].red = (i & COLOR_RED) ? 0xc0 : 0; fbstate->rgbcolor[i].green = (i & COLOR_GREEN) ? 0xc0 : 0; @@ -576,8 +564,8 @@ int PDC_scr_open(int argc, char **argv) * address mapping to make the memory accessible to the application. */ - fbstate->fbmem = mmap(NULL, pinfo.fblen, PROT_READ | PROT_WRITE, - MAP_SHARED | MAP_FILE, fbstate->fbfd, 0); + fbstate->fbmem = mmap(NULL, pinfo.fblen, PROT_READ|PROT_WRITE, + MAP_SHARED|MAP_FILE, fbstate->fbfd, 0); if (fbstate->fbmem == MAP_FAILED) { PDC_LOG(("ERROR: ioctl(FBIOGET_PLANEINFO) failed: %d\n", errno)); @@ -716,9 +704,9 @@ int PDC_resize_screen(int nlines, int ncols) * * Description: * The non-portable functionality of reset_prog_mode() is handled here -- - * whatever's not done in _restore_mode(). In current ports: In OS/2, - * this sets the keyboard to binary mode; in Win32, it enables or disables - * the mouse pointer to match the saved mode; in others it does nothing. + * whatever's not done in _restore_mode(). In current ports: In OS/2, this + * sets the keyboard to binary mode; in Win32, it enables or disables the + * mouse pointer to match the saved mode; in others it does nothing. * ****************************************************************************/ @@ -775,11 +763,11 @@ void PDC_save_screen_mode(int i) * Name: PDC_init_pair * * Description: - * The core of init_pair(). This does all the work of that function, - * except checking for values out of range. The values passed to this - * function should be returned by a call to PDC_pair_content() with the - * same pair number. PDC_transform_line() should use the specified colors - * when rendering a chtype with the given pair number. + * The core of init_pair(). This does all the work of that function, except + * checking for values out of range. The values passed to this function + * should be returned by a call to PDC_pair_content() with the same pair + * number. PDC_transform_line() should use the specified colors when + * rendering a chtype with the given pair number. * ****************************************************************************/ diff --git a/graphics/pdcurs34/nuttx/pdcsetsc.c b/graphics/pdcurs34/nuttx/pdcsetsc.c index af413f32c..3e5cd99cb 100644 --- a/graphics/pdcurs34/nuttx/pdcsetsc.c +++ b/graphics/pdcurs34/nuttx/pdcsetsc.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nuttx/pdcsetsc.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/pdcurs34/nuttx/pdcthread.c b/graphics/pdcurs34/nuttx/pdcthread.c index ca19d7f76..4568e886d 100644 --- a/graphics/pdcurs34/nuttx/pdcthread.c +++ b/graphics/pdcurs34/nuttx/pdcthread.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/pdcurs34/nuttx/pdcthread.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -118,9 +116,9 @@ static FAR struct pdc_context_s *PDC_ctx_new(void) ctx->panel_ctx = pdc_alloc_panel_ctx(); ctx->term_ctx = pdc_alloc_term_ctx(); - /* Get our TID */ + /* Get our PID */ - pid = gettid(); + pid = getpid(); #ifdef CONFIG_PDCURSES_MULTITHREAD_HASH @@ -179,9 +177,9 @@ FAR struct pdc_context_s * PDC_ctx(void) PDC_ctx_initialize(); } - /* Get our TID */ + /* Get our PID */ - pid = gettid(); + pid = getpid(); #ifdef CONFIG_PDCURSES_MULTITHREAD_HASH @@ -264,9 +262,9 @@ void PDC_ctx_free(void) #ifdef CONFIG_PDCURSES_MULTITHREAD_HASH int pid; - /* Get a unique hash key from the TID */ + /* Get a unique hash key from the PID */ - pid = PIDHASH(gettid()); + pid = PIDHASH(getpid()); ctx = g_pdc_ctx_per_pid[pid]; /* Free the context memory */ diff --git a/graphics/pdcurs34/nuttx/pdcutil.c b/graphics/pdcurs34/nuttx/pdcutil.c index c22b88ad9..21957eb62 100644 --- a/graphics/pdcurs34/nuttx/pdcutil.c +++ b/graphics/pdcurs34/nuttx/pdcutil.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/nuttx/pdcutil.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/pdcurs34/pdcurses/Make.defs b/graphics/pdcurs34/pdcurses/Make.defs index 0632a550f..d8ebe865b 100644 --- a/graphics/pdcurs34/pdcurses/Make.defs +++ b/graphics/pdcurs34/pdcurses/Make.defs @@ -1,7 +1,5 @@ ############################################################################ -# apps/graphics/pdcurs34/pdcurses/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 +# apps/graphics/pdcurs34/Make.defs # # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with diff --git a/graphics/pdcurs34/pdcurses/pdc_addch.c b/graphics/pdcurs34/pdcurses/pdc_addch.c index b070b15ed..dc0e332ce 100644 --- a/graphics/pdcurs34/pdcurses/pdc_addch.c +++ b/graphics/pdcurs34/pdcurses/pdc_addch.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/pdcurses/pdc_addch.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/pdcurs34/pdcurses/pdc_addchstr.c b/graphics/pdcurs34/pdcurses/pdc_addchstr.c index 9287d7cc5..90cb59174 100644 --- a/graphics/pdcurs34/pdcurses/pdc_addchstr.c +++ b/graphics/pdcurs34/pdcurses/pdc_addchstr.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/pdcurses/pdc_addchstr.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/pdcurs34/pdcurses/pdc_addstr.c b/graphics/pdcurs34/pdcurses/pdc_addstr.c index 458e8a3c9..2073427c7 100644 --- a/graphics/pdcurs34/pdcurses/pdc_addstr.c +++ b/graphics/pdcurs34/pdcurses/pdc_addstr.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/pdcurses/pdc_addstr.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/pdcurs34/pdcurses/pdc_attr.c b/graphics/pdcurs34/pdcurses/pdc_attr.c index 87256b00c..efbd7aaab 100644 --- a/graphics/pdcurs34/pdcurses/pdc_attr.c +++ b/graphics/pdcurs34/pdcurses/pdc_attr.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/pdcurses/pdc_attr.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/pdcurs34/pdcurses/pdc_beep.c b/graphics/pdcurs34/pdcurses/pdc_beep.c index a318d0d82..787db6840 100644 --- a/graphics/pdcurs34/pdcurses/pdc_beep.c +++ b/graphics/pdcurs34/pdcurses/pdc_beep.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/pdcurses/pdc_beep.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/pdcurs34/pdcurses/pdc_bkgd.c b/graphics/pdcurs34/pdcurses/pdc_bkgd.c index 48bc8b415..89cfc25b5 100644 --- a/graphics/pdcurs34/pdcurses/pdc_bkgd.c +++ b/graphics/pdcurs34/pdcurses/pdc_bkgd.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/pdcurses/pdc_bkgd.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/pdcurs34/pdcurses/pdc_border.c b/graphics/pdcurs34/pdcurses/pdc_border.c index 5bb5462ff..50b02cc82 100644 --- a/graphics/pdcurs34/pdcurses/pdc_border.c +++ b/graphics/pdcurs34/pdcurses/pdc_border.c @@ -1,7 +1,5 @@ /**************************************************************************** - * apps/graphics/pdcurs34/pdcurses/pdc_border.c - * - * SPDX-License-Identifier: Apache-2.0 + * apps/graphics/pdcurses/pdc_border.c * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -49,18 +47,15 @@ * const cchar_t *ts, const cchar_t *bs, * const cchar_t *tl, const cchar_t *tr, * const cchar_t *bl, const cchar_t *br); - * int box_set(WINDOW *win, const cchar_t *verch, - * const cchar_t *horch); + * int box_set(WINDOW *win, const cchar_t *verch, const cchar_t *horch); * int hline_set(const cchar_t *wch, int n); * int vline_set(const cchar_t *wch, int n); * int whline_set(WINDOW *win, const cchar_t *wch, int n); * int wvline_set(WINDOW *win, const cchar_t *wch, int n); * int mvhline_set(int y, int x, const cchar_t *wch, int n); * int mvvline_set(int y, int x, const cchar_t *wch, int n); - * int mvwhline_set(WINDOW *win, int y, int x, - * const cchar_t *wch, int n); - * int mvwvline_set(WINDOW *win, int y, int x, - * const cchar_t *wch, int n); + * int mvwhline_set(WINDOW *win, int y, int x, const cchar_t *wch, int n); + * int mvwvline_set(WINDOW *win, int y, int x, const cchar_t *wch, int n); * * Description: * border(), wborder(), and box() draw a border around the edge of @@ -148,7 +143,7 @@ static chtype _attr_passthru(WINDOW *win, chtype ch) } /* wrs (4/10/93) -- Apply the same sort of logic for the window background, - * in that it only takes precedence if other color attributes aren't there. + * in that it only takes precedence if other color attributes are not there. */ if (!(attr & A_COLOR)) @@ -244,8 +239,7 @@ int box(WINDOW *win, chtype verch, chtype horch) int whline(WINDOW *win, chtype ch, int n) { chtype *dest; - int startpos; - int endpos; + int startpos, endpos; PDC_LOG(("whline() - called\n")); @@ -421,7 +415,8 @@ int box_set(WINDOW *win, const cchar_t *verch, const cchar_t *horch) PDC_LOG(("box_set() - called\n")); return wborder_set(win, verch, verch, horch, horch, - NULL, NULL, NULL, NULL); + (const cchar_t *)NULL, (const cchar_t *)NULL, + (const cchar_t *)NULL, (const cchar_t *)NULL); } int whline_set(WINDOW *win, const cchar_t *wch, int n) diff --git a/graphics/pdcurs34/pdcurses/pdc_clear.c b/graphics/pdcurs34/pdcurses/pdc_clear.c index ff8ff04c0..2ac20b6b0 100644 --- a/graphics/pdcurs34/pdcurses/pdc_clear.c +++ b/graphics/pdcurs34/pdcurses/pdc_clear.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/pdcurses/pdc_clear.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/pdcurs34/pdcurses/pdc_color.c b/graphics/pdcurs34/pdcurses/pdc_color.c index bebb19f7f..fc9ddf59c 100644 --- a/graphics/pdcurs34/pdcurses/pdc_color.c +++ b/graphics/pdcurs34/pdcurses/pdc_color.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/pdcurses/pdc_color.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/pdcurs34/pdcurses/pdc_debug.c b/graphics/pdcurs34/pdcurses/pdc_debug.c index e7431c25e..08edd540f 100644 --- a/graphics/pdcurs34/pdcurses/pdc_debug.c +++ b/graphics/pdcurs34/pdcurses/pdc_debug.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/pdcurses/pdc_debug.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/pdcurs34/pdcurses/pdc_delch.c b/graphics/pdcurs34/pdcurses/pdc_delch.c index d9969d313..63aa82b76 100644 --- a/graphics/pdcurs34/pdcurses/pdc_delch.c +++ b/graphics/pdcurs34/pdcurses/pdc_delch.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/pdcurses/pdc_delch.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/pdcurs34/pdcurses/pdc_deleteln.c b/graphics/pdcurs34/pdcurses/pdc_deleteln.c index 7af909f24..962a01c59 100644 --- a/graphics/pdcurs34/pdcurses/pdc_deleteln.c +++ b/graphics/pdcurs34/pdcurses/pdc_deleteln.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/pdcurses/pdc_deleteln.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/pdcurs34/pdcurses/pdc_getch.c b/graphics/pdcurs34/pdcurses/pdc_getch.c index f787e14f6..bfdb6aaad 100644 --- a/graphics/pdcurs34/pdcurses/pdc_getch.c +++ b/graphics/pdcurs34/pdcurses/pdc_getch.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/pdcurses/pdc_getch.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/pdcurs34/pdcurses/pdc_getstr.c b/graphics/pdcurs34/pdcurses/pdc_getstr.c index 17bed774b..8cd24178e 100644 --- a/graphics/pdcurs34/pdcurses/pdc_getstr.c +++ b/graphics/pdcurs34/pdcurses/pdc_getstr.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/pdcurses/pdc_getstr.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/pdcurs34/pdcurses/pdc_getyx.c b/graphics/pdcurs34/pdcurses/pdc_getyx.c index b205984f4..d6c5358ad 100644 --- a/graphics/pdcurs34/pdcurses/pdc_getyx.c +++ b/graphics/pdcurs34/pdcurses/pdc_getyx.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/pdcurses/pdc_getyx.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/pdcurs34/pdcurses/pdc_inch.c b/graphics/pdcurs34/pdcurses/pdc_inch.c index 29e00ae91..cda749729 100644 --- a/graphics/pdcurs34/pdcurses/pdc_inch.c +++ b/graphics/pdcurs34/pdcurses/pdc_inch.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/pdcurses/pdc_inch.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/pdcurs34/pdcurses/pdc_inchstr.c b/graphics/pdcurs34/pdcurses/pdc_inchstr.c index 8c7620394..9bc595a36 100644 --- a/graphics/pdcurs34/pdcurses/pdc_inchstr.c +++ b/graphics/pdcurs34/pdcurses/pdc_inchstr.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/pdcurses/pdc_inchstr.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/pdcurs34/pdcurses/pdc_initscr.c b/graphics/pdcurs34/pdcurses/pdc_initscr.c index f643526ff..2401903cb 100644 --- a/graphics/pdcurs34/pdcurses/pdc_initscr.c +++ b/graphics/pdcurs34/pdcurses/pdc_initscr.c @@ -1,7 +1,5 @@ /**************************************************************************** - * apps/graphics/pdcurs34/pdcurses/pdc_initscr.c - * - * SPDX-License-Identifier: Apache-2.0 + * apps/graphics/pdcurses/pdc_initscr.c * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -123,13 +121,13 @@ const char *_curses_notice = "PDCurses 3.4 - Public Domain 2008"; char ttytype[128]; -SCREEN *SP = NULL; /* curses variables */ -WINDOW *curscr = NULL; /* the current screen image */ -WINDOW *stdscr = NULL; /* the default screen window */ -WINDOW *pdc_lastscr = NULL; /* the last screen image */ +SCREEN *SP = (SCREEN *) NULL; /* curses variables */ +WINDOW *curscr = (WINDOW *) NULL; /* the current screen image */ +WINDOW *stdscr = (WINDOW *) NULL; /* the default screen window */ +WINDOW *pdc_lastscr = (WINDOW *) NULL; /* the last screen image */ -int LINES = 0; /* current terminal height */ -int COLS = 0; /* current terminal width */ +int LINES = 0; /* current terminal height */ +int COLS = 0; /* current terminal width */ int TABSIZE = 8; MOUSE_STATUS Mouse_status, pdc_mouse_status; @@ -190,13 +188,13 @@ WINDOW *Xinitscr(int argc, char *argv[]) exit(4); } - if ((curscr = newwin(LINES, COLS, 0, 0)) == NULL) + if ((curscr = newwin(LINES, COLS, 0, 0)) == (WINDOW *)NULL) { fprintf(stderr, "initscr(): Unable to create curscr.\n"); exit(2); } - if ((pdc_lastscr = newwin(LINES, COLS, 0, 0)) == NULL) + if ((pdc_lastscr = newwin(LINES, COLS, 0, 0)) == (WINDOW *)NULL) { fprintf(stderr, "initscr(): Unable to create pdc_lastscr.\n"); exit(2); @@ -209,8 +207,7 @@ WINDOW *Xinitscr(int argc, char *argv[]) LINES -= SP->slklines; /* We have to sort out ripped off lines here, and reduce the height of - * stdscr by the number of lines ripped off - */ + * stdscr by the number of lines ripped off */ for (i = 0; i < linesrippedoff; i++) { @@ -264,8 +261,7 @@ WINDOW *Xinitscr(int argc, char *argv[]) def_shell_mode(); - snprintf(ttytype, sizeof(ttytype), - "pdcurses|PDCurses for %s", PDC_sysname()); + sprintf(ttytype, "pdcurses|PDCurses for %s", PDC_sysname()); return stdscr; } @@ -343,15 +339,15 @@ void delscreen(SCREEN *sp) delwin(stdscr); delwin(curscr); delwin(pdc_lastscr); - stdscr = NULL; - curscr = NULL; - pdc_lastscr = NULL; + stdscr = (WINDOW *) NULL; + curscr = (WINDOW *) NULL; + pdc_lastscr = (WINDOW *) NULL; SP->alive = false; PDC_scr_free(); /* Free SP and pdc_atrtab */ - SP = NULL; + SP = (SCREEN *)NULL; #ifdef CONFIG_PDCURSES_MULTITHREAD diff --git a/graphics/pdcurs34/pdcurses/pdc_inopts.c b/graphics/pdcurs34/pdcurses/pdc_inopts.c index 089100c80..d4fd5a5ad 100644 --- a/graphics/pdcurs34/pdcurses/pdc_inopts.c +++ b/graphics/pdcurs34/pdcurses/pdc_inopts.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/pdcurses/pdc_inopts.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/pdcurs34/pdcurses/pdc_insch.c b/graphics/pdcurs34/pdcurses/pdc_insch.c index cc351edde..deb9f74c2 100644 --- a/graphics/pdcurs34/pdcurses/pdc_insch.c +++ b/graphics/pdcurs34/pdcurses/pdc_insch.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/pdcurses/pdc_insch.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/pdcurs34/pdcurses/pdc_insstr.c b/graphics/pdcurs34/pdcurses/pdc_insstr.c index d945226e5..c62e50781 100644 --- a/graphics/pdcurs34/pdcurses/pdc_insstr.c +++ b/graphics/pdcurs34/pdcurses/pdc_insstr.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/pdcurses/pdc_insstr.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/pdcurs34/pdcurses/pdc_instr.c b/graphics/pdcurs34/pdcurses/pdc_instr.c index a32e48013..ac5b0a18b 100644 --- a/graphics/pdcurs34/pdcurses/pdc_instr.c +++ b/graphics/pdcurs34/pdcurses/pdc_instr.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/pdcurses/pdc_instr.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/pdcurs34/pdcurses/pdc_kernel.c b/graphics/pdcurs34/pdcurses/pdc_kernel.c index 0e3bf42ef..ec706e865 100644 --- a/graphics/pdcurs34/pdcurses/pdc_kernel.c +++ b/graphics/pdcurs34/pdcurses/pdc_kernel.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/pdcurses/pdc_kernel.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/pdcurs34/pdcurses/pdc_keyname.c b/graphics/pdcurs34/pdcurses/pdc_keyname.c index 8a23ddb46..15d6d046f 100644 --- a/graphics/pdcurs34/pdcurses/pdc_keyname.c +++ b/graphics/pdcurs34/pdcurses/pdc_keyname.c @@ -1,7 +1,5 @@ /**************************************************************************** - * apps/graphics/pdcurs34/pdcurses/pdc_keyname.c - * - * SPDX-License-Identifier: Apache-2.0 + * apps/graphics/pdcurses/pdc_keyname.c * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with diff --git a/graphics/pdcurs34/pdcurses/pdc_mouse.c b/graphics/pdcurs34/pdcurses/pdc_mouse.c index 62f47dc2d..54bdc66c7 100644 --- a/graphics/pdcurs34/pdcurses/pdc_mouse.c +++ b/graphics/pdcurs34/pdcurses/pdc_mouse.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/pdcurses/pdc_mouse.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/pdcurs34/pdcurses/pdc_move.c b/graphics/pdcurs34/pdcurses/pdc_move.c index 87268fd2a..f1729ed29 100644 --- a/graphics/pdcurs34/pdcurses/pdc_move.c +++ b/graphics/pdcurs34/pdcurses/pdc_move.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/pdcurses/pdc_move.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/pdcurs34/pdcurses/pdc_outopts.c b/graphics/pdcurs34/pdcurses/pdc_outopts.c index 0f9808952..81c1eaf9f 100644 --- a/graphics/pdcurs34/pdcurses/pdc_outopts.c +++ b/graphics/pdcurs34/pdcurses/pdc_outopts.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/pdcurses/pdc_outopts.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/pdcurs34/pdcurses/pdc_overlay.c b/graphics/pdcurs34/pdcurses/pdc_overlay.c index e5fea025c..d692851df 100644 --- a/graphics/pdcurs34/pdcurses/pdc_overlay.c +++ b/graphics/pdcurs34/pdcurses/pdc_overlay.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/pdcurses/pdc_overlay.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/pdcurs34/pdcurses/pdc_pad.c b/graphics/pdcurs34/pdcurses/pdc_pad.c index 6d250829f..8cb0daff1 100644 --- a/graphics/pdcurs34/pdcurses/pdc_pad.c +++ b/graphics/pdcurs34/pdcurses/pdc_pad.c @@ -1,7 +1,5 @@ /**************************************************************************** - * apps/graphics/pdcurs34/pdcurses/pdc_pad.c - * - * SPDX-License-Identifier: Apache-2.0 + * apps/graphics/pdcurses/pdc_pad.c * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -122,15 +120,13 @@ WINDOW *newpad(int nlines, int ncols) if (!(win = PDC_makenew(nlines, ncols, -1, -1)) || !(win = PDC_makelines(win))) { - return NULL; + return (WINDOW *) NULL; } werase(win); win->_flags = _PAD; - /* save default values in case pechochar() is the first call to - * prefresh(). - */ + /* save default values in case pechochar() is the first call to prefresh(). */ save_pminrow = 0; save_pmincol = 0; @@ -157,7 +153,7 @@ WINDOW *subpad(WINDOW *orig, int nlines, int ncols, int begy, int begx) if (!orig || !(orig->_flags & _PAD)) { - return NULL; + return (WINDOW *) NULL; } /* Make sure window fits inside the original one */ @@ -166,7 +162,7 @@ WINDOW *subpad(WINDOW *orig, int nlines, int ncols, int begy, int begx) (begy + nlines) > (orig->_begy + orig->_maxy) || (begx + ncols) > (orig->_begx + orig->_maxx)) { - return NULL; + return (WINDOW *) NULL; } if (!nlines) @@ -181,7 +177,7 @@ WINDOW *subpad(WINDOW *orig, int nlines, int ncols, int begy, int begx) if (!(win = PDC_makenew(nlines, ncols, begy, begx))) { - return NULL; + return (WINDOW *) NULL; } /* Initialize window variables */ @@ -240,7 +236,7 @@ int pnoutrefresh(WINDOW *w, int py, int px, int sy1, int sx1, int sy2, PDC_LOG(("pnoutrefresh() - called\n")); - if (!w || !(w->_flags & (_PAD | _SUBPAD)) || sy2 >= LINES || sy2 >= COLS) + if (!w || !(w->_flags & (_PAD | _SUBPAD)) || (sy2 >= LINES) || (sy2 >= COLS)) { return ERR; } diff --git a/graphics/pdcurs34/pdcurses/pdc_panel.c b/graphics/pdcurs34/pdcurses/pdc_panel.c index 28f191765..59ec33e01 100644 --- a/graphics/pdcurs34/pdcurses/pdc_panel.c +++ b/graphics/pdcurs34/pdcurses/pdc_panel.c @@ -1,7 +1,5 @@ /**************************************************************************** - * apps/graphics/pdcurs34/pdcurses/pdc_panel.c - * - * SPDX-License-Identifier: Apache-2.0 + * apps/graphics/pdcurses/pdc_panel.c * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -151,12 +149,9 @@ ****************************************************************************/ #ifndef CONFIG_PDCURSES_MULTITHREAD -PANEL *_bottom_panel = (PANEL *)0; -PANEL *_top_panel = (PANEL *)0; -PANEL _stdscr_pseudo_panel = -{ - (WINDOW *)0 -}; +PANEL *_bottom_panel = (PANEL *) 0; +PANEL *_top_panel = (PANEL *) 0; +PANEL _stdscr_pseudo_panel = { (WINDOW *) 0 }; #else typedef struct panel_ctx_s { @@ -169,7 +164,7 @@ typedef struct panel_ctx_s #ifdef CONFIG_PDCURSES_MULTITHREAD void *pdc_alloc_panel_ctx() { - return zalloc(sizeof(struct panel_ctx_s)); + return (void *) zalloc(sizeof(struct panel_ctx_s)); } #endif @@ -182,15 +177,14 @@ static void dpanel(char *text, PANEL *pan) { PDC_LOG(("%s id=%s b=%s a=%s y=%d x=%d", text, pan->user, pan->below ? pan->below->user : "--", - pan->above ? pan->above->user : "--", - pan->wstarty, pan->wstartx)); + pan->above ? pan->above->user : "--", pan->wstarty, pan->wstartx)); } static void dstack(char *fmt, int num, PANEL *pan) { char s80[80]; - snprintf(s80, sizeof(s80), fmt, num, pan); + sprintf(s80, fmt, num, pan); PDC_LOG(("%s b=%s t=%s", s80, _bottom_panel ? _bottom_panel->user : "--", _top_panel ? _top_panel->user : "--")); @@ -226,7 +220,7 @@ static void dtouchline(PANEL *pan, int start, int count) { char s80[80]; - snprintf(s80, sizeof(s80), "dtouchline s=%d c=%d", start, count); + sprintf(s80, "dtouchline s=%d c=%d", start, count); dpanel(s80, pan); touchline(pan->win, start, count); } @@ -692,8 +686,7 @@ WINDOW *panel_window(const PANEL *pan) int replace_panel(PANEL *pan, WINDOW *win) { - int maxy; - int maxx; + int maxy, maxx; if (!pan) { diff --git a/graphics/pdcurs34/pdcurses/pdc_printw.c b/graphics/pdcurs34/pdcurses/pdc_printw.c index 6864ddbab..09ccacdf7 100644 --- a/graphics/pdcurs34/pdcurses/pdc_printw.c +++ b/graphics/pdcurs34/pdcurses/pdc_printw.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/pdcurses/pdc_printw.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/pdcurs34/pdcurses/pdc_refresh.c b/graphics/pdcurs34/pdcurses/pdc_refresh.c index 33a82d256..dc69552c7 100644 --- a/graphics/pdcurs34/pdcurses/pdc_refresh.c +++ b/graphics/pdcurs34/pdcurses/pdc_refresh.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/pdcurses/pdc_refresh.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/pdcurs34/pdcurses/pdc_scanw.c b/graphics/pdcurs34/pdcurses/pdc_scanw.c index 0f9e94652..5a6e6c6d9 100644 --- a/graphics/pdcurs34/pdcurses/pdc_scanw.c +++ b/graphics/pdcurs34/pdcurses/pdc_scanw.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/pdcurses/pdc_scanw.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/pdcurs34/pdcurses/pdc_scrdump.c b/graphics/pdcurs34/pdcurses/pdc_scrdump.c index e06b3c463..dd342490b 100644 --- a/graphics/pdcurs34/pdcurses/pdc_scrdump.c +++ b/graphics/pdcurs34/pdcurses/pdc_scrdump.c @@ -1,7 +1,5 @@ /**************************************************************************** - * apps/graphics/pdcurs34/pdcurses/pdc_scrdump.c - * - * SPDX-License-Identifier: Apache-2.0 + * apps/graphics/pdcurses/pdc_scrdump.c * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -136,7 +134,7 @@ WINDOW *getwin(FILE *filep) if (!(win = malloc(sizeof(WINDOW)))) { - return NULL; + return (WINDOW *)NULL; } /* Check for the marker, and load the WINDOW struct */ @@ -145,7 +143,7 @@ WINDOW *getwin(FILE *filep) marker[3] != DUMPVER || !fread(win, sizeof(WINDOW), 1, filep)) { free(win); - return NULL; + return (WINDOW *)NULL; } nlines = win->_maxy; @@ -156,7 +154,7 @@ WINDOW *getwin(FILE *filep) if (!(win->_y = malloc(nlines * sizeof(chtype *)))) { free(win); - return NULL; + return (WINDOW *)NULL; } /* allocate the minchng and maxchng arrays */ @@ -165,7 +163,7 @@ WINDOW *getwin(FILE *filep) { free(win->_y); free(win); - return NULL; + return (WINDOW *)NULL; } if (!(win->_lastch = malloc(nlines * sizeof(int)))) @@ -173,15 +171,13 @@ WINDOW *getwin(FILE *filep) free(win->_firstch); free(win->_y); free(win); - return NULL; + return (WINDOW *) NULL; } /* allocate the lines */ if (!(win = PDC_makelines(win))) - { - return NULL; - } + return (WINDOW *) NULL; /* read them */ @@ -190,7 +186,7 @@ WINDOW *getwin(FILE *filep) if (!fread(win->_y[i], ncols * sizeof(chtype), 1, filep)) { delwin(win); - return NULL; + return (WINDOW *) NULL; } } diff --git a/graphics/pdcurs34/pdcurses/pdc_scroll.c b/graphics/pdcurs34/pdcurses/pdc_scroll.c index 1b87471e1..835fd7463 100644 --- a/graphics/pdcurs34/pdcurses/pdc_scroll.c +++ b/graphics/pdcurs34/pdcurses/pdc_scroll.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/pdcurses/pdc_scroll.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/pdcurs34/pdcurses/pdc_slk.c b/graphics/pdcurs34/pdcurses/pdc_slk.c index b53d530e1..fa3b1409d 100644 --- a/graphics/pdcurs34/pdcurses/pdc_slk.c +++ b/graphics/pdcurs34/pdcurses/pdc_slk.c @@ -1,7 +1,5 @@ /**************************************************************************** - * apps/graphics/pdcurs34/pdcurses/pdc_slk.c - * - * SPDX-License-Identifier: Apache-2.0 + * apps/graphics/pdcurses/pdc_slk.c * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -126,7 +124,7 @@ static int label_fmt = 0; static int label_line = 0; static bool hidden = false; -static struct SLK *slk = NULL; +static struct SLK *slk = (struct SLK *)NULL; #endif /**************************************************************************** @@ -498,9 +496,7 @@ int slk_attr_set(const attr_t attrs, short color_pair, void *opts) static void _slk_calc(void) { - int i; - int center; - int col = 0; + int i, center, col = 0; #ifdef CONFIG_PDCURSES_MULTITHREAD FAR struct pdc_context_s *ctx = PDC_ctx(); #endif @@ -659,11 +655,11 @@ void PDC_slk_free(void) if (SP->slk_winptr) { delwin(SP->slk_winptr); - SP->slk_winptr = NULL; + SP->slk_winptr = (WINDOW *) NULL; } free(slk); - slk = NULL; + slk = (struct SLK *)NULL; label_length = 0; labels = 0; @@ -728,8 +724,7 @@ int slk_wset(int labnum, const wchar_t *label, int justify) } else { - int i; - int j = 0; + int i, j = 0; /* Skip leading spaces */ diff --git a/graphics/pdcurs34/pdcurses/pdc_termattr.c b/graphics/pdcurs34/pdcurses/pdc_termattr.c index 9c25f7b3b..a95e8b75b 100644 --- a/graphics/pdcurs34/pdcurses/pdc_termattr.c +++ b/graphics/pdcurs34/pdcurses/pdc_termattr.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/pdcurses/pdc_termattr.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/pdcurs34/pdcurses/pdc_terminfo.c b/graphics/pdcurs34/pdcurses/pdc_terminfo.c index e65112604..87e1c787e 100644 --- a/graphics/pdcurs34/pdcurses/pdc_terminfo.c +++ b/graphics/pdcurs34/pdcurses/pdc_terminfo.c @@ -1,7 +1,5 @@ /**************************************************************************** - * apps/graphics/pdcurs34/pdcurses/pdc_terminfo.c - * - * SPDX-License-Identifier: Apache-2.0 + * apps/graphics/pdcurses/pdc_terminfo.c * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -86,7 +84,7 @@ TERMINAL *cur_term = NULL; #ifdef CONFIG_PDCURSES_MULTITHREAD void *pdc_alloc_term_ctx(void) { - return zalloc(sizeof(TERMINAL)); + return (void *) zalloc(sizeof(TERMINAL)); } #endif @@ -167,7 +165,7 @@ TERMINAL *set_curterm(TERMINAL * nterm) { PDC_LOG(("set_curterm() - called\n")); - return NULL; + return (TERMINAL *) NULL; } int setterm(const char *term) @@ -218,14 +216,14 @@ char *tgetstr(const char *id, char **area) { PDC_LOG(("tgetstr() - called: id %s\n", id)); - return NULL; + return (char *)NULL; } char *tgoto(const char *cap, int col, int row) { PDC_LOG(("tgoto() - called\n")); - return NULL; + return (char *)NULL; } int tigetflag(const char *capname) @@ -246,7 +244,7 @@ char *tigetstr(const char *capname) { PDC_LOG(("tigetstr() - called: capname %s\n", capname)); - return NULL; + return (char *)(-1); } char *tparm(const char *cap, long p1, long p2, long p3, long p4, @@ -254,7 +252,7 @@ char *tparm(const char *cap, long p1, long p2, long p3, long p4, { PDC_LOG(("tparm() - called: cap %s\n", cap)); - return NULL; + return (char *)NULL; } int tputs(const char *str, int affcnt, int (*putfunc) (int)) diff --git a/graphics/pdcurs34/pdcurses/pdc_touch.c b/graphics/pdcurs34/pdcurses/pdc_touch.c index 5562df1a6..3c4a2c7c5 100644 --- a/graphics/pdcurs34/pdcurses/pdc_touch.c +++ b/graphics/pdcurs34/pdcurses/pdc_touch.c @@ -1,7 +1,5 @@ /**************************************************************************** - * apps/graphics/pdcurs34/pdcurses/pdc_touch.c - * - * SPDX-License-Identifier: Apache-2.0 + * apps/graphics/pdcurses/pdc_touch.c * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with diff --git a/graphics/pdcurs34/pdcurses/pdc_util.c b/graphics/pdcurs34/pdcurses/pdc_util.c index 979543efd..4b4b369f8 100644 --- a/graphics/pdcurs34/pdcurses/pdc_util.c +++ b/graphics/pdcurs34/pdcurses/pdc_util.c @@ -1,8 +1,7 @@ + /**************************************************************************** * apps/graphics/pdcurses/util.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/pdcurs34/pdcurses/pdc_window.c b/graphics/pdcurs34/pdcurses/pdc_window.c index 0a0ef7e7e..783b49b22 100644 --- a/graphics/pdcurs34/pdcurses/pdc_window.c +++ b/graphics/pdcurs34/pdcurses/pdc_window.c @@ -1,7 +1,5 @@ /**************************************************************************** - * apps/graphics/pdcurs34/pdcurses/pdc_window.c - * - * SPDX-License-Identifier: Apache-2.0 + * apps/graphics/pdcurses/pdc_window.c * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -156,7 +154,7 @@ #include "curspriv.h" /**************************************************************************** - * Public Functions + * Public functions ****************************************************************************/ WINDOW *PDC_makenew(int nlines, int ncols, int begy, int begx) @@ -171,7 +169,7 @@ WINDOW *PDC_makenew(int nlines, int ncols, int begy, int begx) /* Allocate the window structure itself */ - if ((win = calloc(1, sizeof(WINDOW))) == NULL) + if ((win = calloc(1, sizeof(WINDOW))) == (WINDOW *) NULL) { return win; } @@ -181,7 +179,7 @@ WINDOW *PDC_makenew(int nlines, int ncols, int begy, int begx) if ((win->_y = malloc(nlines * sizeof(chtype *))) == NULL) { free(win); - return NULL; + return (WINDOW *)NULL; } /* allocate the minchng and maxchng arrays */ @@ -190,7 +188,7 @@ WINDOW *PDC_makenew(int nlines, int ncols, int begy, int begx) { free(win->_y); free(win); - return NULL; + return (WINDOW *)NULL; } if ((win->_lastch = malloc(nlines * sizeof(int))) == NULL) @@ -198,7 +196,7 @@ WINDOW *PDC_makenew(int nlines, int ncols, int begy, int begx) free(win->_firstch); free(win->_y); free(win); - return NULL; + return (WINDOW *)NULL; } /* Initialize window variables */ @@ -230,7 +228,7 @@ WINDOW *PDC_makelines(WINDOW *win) if (!win) { - return NULL; + return (WINDOW *)NULL; } nlines = win->_maxy; @@ -252,7 +250,7 @@ WINDOW *PDC_makelines(WINDOW *win) free(win->_y); free(win); - return NULL; + return (WINDOW *)NULL; } } @@ -298,7 +296,7 @@ WINDOW *newwin(int nlines, int ncols, int begy, int begx) !(win = PDC_makenew(nlines, ncols, begy, begx)) || !(win = PDC_makelines(win))) { - return NULL; + return (WINDOW *)NULL; } werase(win); @@ -371,7 +369,7 @@ WINDOW *subwin(WINDOW *orig, int nlines, int ncols, int begy, int begx) (begy + nlines) > (orig->_begy + orig->_maxy) || (begx + ncols) > (orig->_begx + orig->_maxx)) { - return NULL; + return (WINDOW *)NULL; } if (!nlines) @@ -386,7 +384,7 @@ WINDOW *subwin(WINDOW *orig, int nlines, int ncols, int begy, int begx) if (!(win = PDC_makenew(nlines, ncols, begy, begx))) { - return NULL; + return (WINDOW *)NULL; } /* Initialize window variables */ @@ -419,8 +417,7 @@ WINDOW *derwin(WINDOW *orig, int nlines, int ncols, int begy, int begx) int mvderwin(WINDOW *win, int pary, int parx) { - int i; - int j; + int i, j; WINDOW *mypar; if (!win || !(win->_parent)) @@ -461,7 +458,7 @@ WINDOW *dupwin(WINDOW *win) if (!win) { - return NULL; + return (WINDOW *) NULL; } nlines = win->_maxy; @@ -472,7 +469,7 @@ WINDOW *dupwin(WINDOW *win) if (!(new = PDC_makenew(nlines, ncols, begy, begx)) || !(new = PDC_makelines(new))) { - return NULL; + return (WINDOW *) NULL; } /* copy the contents of win into new */ @@ -529,23 +526,21 @@ WINDOW *resize_window(WINDOW *win, int nlines, int ncols) if (!win) { - return NULL; + return (WINDOW *)NULL; } if (win->_flags & _SUBPAD) { - if (!(new = subpad(win->_parent, nlines, ncols, - win->_begy, win->_begx))) + if (!(new = subpad(win->_parent, nlines, ncols, win->_begy, win->_begx))) { - return NULL; + return (WINDOW *)NULL; } } else if (win->_flags & _SUBWIN) { - if (!(new = subwin(win->_parent, nlines, ncols, - win->_begy, win->_begx))) + if (!(new = subwin(win->_parent, nlines, ncols, win->_begy, win->_begx))) { - return NULL; + return (WINDOW *)NULL; } } else @@ -563,7 +558,7 @@ WINDOW *resize_window(WINDOW *win, int nlines, int ncols) if (!(new = PDC_makenew(nlines, ncols, new_begy, new_begx))) { - return NULL; + return (WINDOW *)NULL; } } @@ -574,7 +569,7 @@ WINDOW *resize_window(WINDOW *win, int nlines, int ncols) { if (!(new = PDC_makelines(new))) { - return NULL; + return (WINDOW *) NULL; } werase(new); diff --git a/graphics/screenshot/Make.defs b/graphics/screenshot/Make.defs index 28f0d1fa1..5901dcc4a 100644 --- a/graphics/screenshot/Make.defs +++ b/graphics/screenshot/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/graphics/screenshot/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/graphics/screenshot/Makefile b/graphics/screenshot/Makefile index 0a315fc56..5e8cfae58 100644 --- a/graphics/screenshot/Makefile +++ b/graphics/screenshot/Makefile @@ -1,7 +1,5 @@ ############################################################################ -# apps/graphics/screenshot/Makefile -# -# SPDX-License-Identifier: Apache-2.0 +# apps/examples/screenshot/Makefile # # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with diff --git a/graphics/screenshot/screenshot_main.c b/graphics/screenshot/screenshot_main.c index 5025c67d8..944a7af7f 100644 --- a/graphics/screenshot/screenshot_main.c +++ b/graphics/screenshot/screenshot_main.c @@ -1,7 +1,5 @@ /**************************************************************************** - * apps/graphics/screenshot/screenshot_main.c - * - * SPDX-License-Identifier: Apache-2.0 + * apps/examples/screenshot/screenshot_main.c * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -71,8 +69,7 @@ * Private Functions ****************************************************************************/ -static void replace_extension(FAR const char *filename, - FAR const char *newext, +static void replace_extension(FAR const char *filename, FAR const char *newext, FAR char *dest, size_t size) { FAR char *p = strrchr(filename, '.'); @@ -88,8 +85,8 @@ static void replace_extension(FAR const char *filename, len = size - strlen(newext); } - strlcpy(dest, filename, size); - strlcpy(dest + len, newext, size - len); + strncpy(dest, filename, size); + strncpy(dest + len, newext, size - len); } /**************************************************************************** @@ -107,15 +104,8 @@ static void replace_extension(FAR const char *filename, int save_screenshot(FAR const char *filename) { struct tiff_info_s info; - struct nx_callback_s cb = - { - }; - - struct nxgl_size_s size = - { - CONFIG_SCREENSHOT_WIDTH, CONFIG_SCREENSHOT_HEIGHT - }; - + struct nx_callback_s cb = {}; + struct nxgl_size_s size = {CONFIG_SCREENSHOT_WIDTH, CONFIG_SCREENSHOT_HEIGHT}; #ifdef CONFIG_VNCSERVER struct boardioc_vncstart_s vnc; #endif @@ -140,18 +130,18 @@ int save_screenshot(FAR const char *filename) } #ifdef CONFIG_VNCSERVER - /* Setup the VNC server to support keyboard/mouse inputs */ + /* Setup the VNC server to support keyboard/mouse inputs */ - vnc.display = 0; - vnc.handle = server; + vnc.display = 0; + vnc.handle = server; - ret = boardctl(BOARDIOC_VNC_START, (uintptr_t)&vnc); - if (ret < 0) - { - printf("boardctl(BOARDIOC_VNC_START) failed: %d\n", ret); - nx_disconnect(server); - return 1; - } + ret = boardctl(BOARDIOC_VNC_START, (uintptr_t)&vnc); + if (ret < 0) + { + printf("boardctl(BOARDIOC_VNC_START) failed: %d\n", ret); + nx_disconnect(server); + return 1; + } #endif /* Wait for "connected" event */ @@ -167,11 +157,11 @@ int save_screenshot(FAR const char *filename) window = nx_openwindow(server, 0, &cb, NULL); if (!window) - { - perror("nx_openwindow"); - nx_disconnect(server); - return 1; - } + { + perror("nx_openwindow"); + nx_disconnect(server); + return 1; + } nx_setsize(window, &size); @@ -202,26 +192,17 @@ int save_screenshot(FAR const char *filename) strip = malloc(size.w * 3); for (row = 0; row < size.h; row++) - { - struct nxgl_rect_s rect = + { + struct nxgl_rect_s rect = {{0, row}, {size.w - 1, row}}; + nx_getrectangle(window, &rect, 0, strip, 0); + + ret = tiff_addstrip(&info, strip); + if (ret < 0) { - { - 0, row - }, - { - size.w - 1, row - } - }; - - nx_getrectangle(window, &rect, 0, strip, 0); - - ret = tiff_addstrip(&info, strip); - if (ret < 0) - { - printf("tiff_addstrip() #%d failed: %d\n", row, ret); - break; - } - } + printf("tiff_addstrip() #%d failed: %d\n", row, ret); + break; + } + } free(strip); diff --git a/graphics/slcd/Make.defs b/graphics/slcd/Make.defs index 4378ff132..31bbb20ea 100644 --- a/graphics/slcd/Make.defs +++ b/graphics/slcd/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/graphics/slcd/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -20,6 +18,6 @@ # ############################################################################ -ifneq ($(CONFIG_GRAPHICS_SLCD),) +ifeq ($(CONFIG_GRAPHICS_SLCD),y) CONFIGURED_APPS += $(APPDIR)/graphics/slcd endif diff --git a/graphics/slcd/Makefile b/graphics/slcd/Makefile index bc1c151e3..d45edf7e5 100644 --- a/graphics/slcd/Makefile +++ b/graphics/slcd/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/graphics/slcd/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/graphics/slcd/cslcd.cxx b/graphics/slcd/cslcd.cxx index f732b8e42..bba30faf5 100644 --- a/graphics/slcd/cslcd.cxx +++ b/graphics/slcd/cslcd.cxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/graphics/slcd/cslcd.cxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -25,7 +23,7 @@ ///////////////////////////////////////////////////////////////////////////// #include -#include +#include #include diff --git a/graphics/slcd/slcd.hxx b/graphics/slcd/slcd.hxx index a28279440..97619f8ab 100644 --- a/graphics/slcd/slcd.hxx +++ b/graphics/slcd/slcd.hxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/graphics/slcd/slcd.hxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The diff --git a/graphics/slcd/slcd_mapping.cxx b/graphics/slcd/slcd_mapping.cxx index 086145f7e..b5d7315e4 100644 --- a/graphics/slcd/slcd_mapping.cxx +++ b/graphics/slcd/slcd_mapping.cxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/graphics/slcd/slcd_mapping.cxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The diff --git a/graphics/slcd/slcd_trapezoids.cxx b/graphics/slcd/slcd_trapezoids.cxx index 5c9689e4a..c4c6a2f9e 100644 --- a/graphics/slcd/slcd_trapezoids.cxx +++ b/graphics/slcd/slcd_trapezoids.cxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/graphics/slcd/slcd_trapezoids.cxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -37,21 +35,25 @@ namespace SLcd const struct SLcdTrapezoidRun GTop_Runs[NTOP_TRAPEZOIDS + 1] = { + [0] = { .leftx = 11703, .rightx = 31208, .y = 0 }, + [1] = { .leftx = 8972, .rightx = 27323, .y = 780 }, + [2] = { .leftx = 9655, .rightx = 34328, .y = 1560 }, + [3] = { .leftx = 14434, .rightx = 28867, @@ -63,31 +65,37 @@ namespace SLcd const struct SLcdTrapezoidRun GTopLeft_Runs[NTOPLEFT_TRAPEZOIDS + 1] = { + [0] = { .leftx = 7022, .rightx = 7022, .y = 2341 }, + [1] = { .leftx = 5461, .rightx = 9362, .y = 4681 }, + [2] = { .leftx = 5098, .rightx = 12873, .y = 8192 }, + [3] = { .leftx = 3193, .rightx = 10923, .y = 26526 }, + [4] = { .leftx = 3121, .rightx = 9986, .y = 27307 }, + [5] = { .leftx = 6242, .rightx = 6242, @@ -99,31 +107,37 @@ namespace SLcd const struct SLcdTrapezoidRun GTopRight_Runs[NTOPRIGHT_TRAPEZOIDS + 1] = { + [0] = { .leftx = 37059, .rightx = 37059, .y = 3901 }, + [1] = { .leftx = 33997, .rightx = 37839, .y = 6242 }, + [2] = { .leftx = 30427, .rightx = 37591, .y = 8972 }, + [3] = { .leftx = 28477, .rightx = 35924, .y = 27307 }, + [4] = { .leftx = 28518, .rightx = 35889, .y = 27697 }, + [5] = { .leftx = 32378, .rightx = 32378, @@ -135,16 +149,19 @@ namespace SLcd const struct SLcdTrapezoidRun GMiddle_Runs[NMIDDLE_TRAPEZOIDS + 1] = { + [0] = { .leftx = 12483, .rightx = 27307, .y = 28867 }, + [1] = { .leftx = 8192, .rightx = 30427, .y = 32378 }, + [2] = { .leftx = 11703, .rightx = 25746, @@ -156,27 +173,32 @@ namespace SLcd const struct SLcdTrapezoidRun GBottomLeft_Runs[NBOTTOMLEFT_TRAPEZOIDS + 1] = { + [0] = { .leftx = 5851, .rightx = 5851, .y = 33938 , }, + [1] = { .leftx = 1950, .rightx = 9752, .y = 37449 }, + [2] = { .leftx = 370, .rightx = 8192, .y = 55784 }, + [3] = { .leftx = 0, .rightx = 3364, .y = 60075 }, + [4] = { .leftx = 1170, .rightx = 1170, @@ -188,31 +210,37 @@ namespace SLcd const struct SLcdTrapezoidRun GBottomRight_Runs[NBOTTOMRIGHT_TRAPEZOIDS + 1] = { + [0] = { .leftx = 31988, .rightx = 31988, .y = 34328 }, + [1] = { .leftx = 28769, .rightx = 35109, .y = 37059 }, + [2] = { .leftx = 27307, .rightx = 34996, .y = 38229 }, + [3] = { .leftx = 25746, .rightx = 33183, .y = 56954 }, + [4] = { .leftx = 30324, .rightx = 32768, .y = 61245 }, + [5] = { .leftx = 31988, .rightx = 31988, @@ -224,16 +252,19 @@ namespace SLcd const struct SLcdTrapezoidRun GBottom_Runs[NBOTTOM_TRAPEZOIDS + 1] = { + [0] = { .leftx = 9362, .rightx = 24576, .y = 58124 }, + [1] = { .leftx = 2731, .rightx = 31988, .y = 63976 }, + [2] = { .leftx = 4681, .rightx = 28477, diff --git a/graphics/tiff/Make.defs b/graphics/tiff/Make.defs index a376e36a9..c3ff46103 100644 --- a/graphics/tiff/Make.defs +++ b/graphics/tiff/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/graphics/tiff/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -20,6 +18,6 @@ # ############################################################################ -ifneq ($(CONFIG_TIFF),) +ifeq ($(CONFIG_TIFF),y) CONFIGURED_APPS += $(APPDIR)/graphics/tiff endif diff --git a/graphics/tiff/Makefile b/graphics/tiff/Makefile index 10c51fc88..542376749 100644 --- a/graphics/tiff/Makefile +++ b/graphics/tiff/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/graphics/tiff/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/graphics/tiff/README.md b/graphics/tiff/README.md new file mode 100644 index 000000000..dd4620715 --- /dev/null +++ b/graphics/tiff/README.md @@ -0,0 +1,12 @@ +# Graphics / `tiff` TIFF Creation Library + +This directory contains a library that can be used to create TIFF image files. +This file was created for the purpose of supporting screen dumps from an LCD. +Howeve, the logic is general and could be used for most any purpose. + +The only usage documentation is in the (rather extensive) comments in the file +`apps/include/tiff.h`. + +## Unit Test + +See `apps/examples/tiff`. diff --git a/graphics/tiff/tiff_addstrip.c b/graphics/tiff/tiff_addstrip.c index 965152eac..e0a4bdfe0 100644 --- a/graphics/tiff/tiff_addstrip.c +++ b/graphics/tiff/tiff_addstrip.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/tiff/tiff_addstrip.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -28,7 +26,7 @@ #include #include -#include +#include #include "graphics/tiff.h" @@ -65,15 +63,13 @@ * tiff_initialize(). * * Input Parameters: - * info - A pointer to the caller allocated parameter passing/TIFF - * state instance. + * info - A pointer to the caller allocated parameter passing/TIFF state instance. * buffer - A buffer containing a single row of data. * * Returned Value: * Zero (OK) on success. A negated errno value on failure. * ****************************************************************************/ - int tiff_convstrip(FAR struct tiff_info_s *info, FAR const uint8_t *strip) { #ifdef CONFIG_DEBUG_GRAPHICS @@ -102,9 +98,9 @@ int tiff_convstrip(FAR struct tiff_info_s *info, FAR const uint8_t *strip) /* Convert RGB565 to RGB888 */ rgb565 = *src++; - *dest++ = (rgb565 >> (11 - 3)) & 0xf8; /* Move bits 11-15 to 3-7 */ - *dest++ = (rgb565 >> (5 - 2)) & 0xfc; /* Move bits 5-10 to 2-7 */ - *dest++ = (rgb565 << 3) & 0xf8; /* Move bits 0- 4 to 3-7 */ + *dest++ = (rgb565 >> (11-3)) & 0xf8; /* Move bits 11-15 to 3-7 */ + *dest++ = (rgb565 >> ( 5-2)) & 0xfc; /* Move bits 5-10 to 2-7 */ + *dest++ = (rgb565 << ( 3)) & 0xf8; /* Move bits 0- 4 to 3-7 */ /* Update the byte count */ @@ -115,7 +111,7 @@ int tiff_convstrip(FAR struct tiff_info_s *info, FAR const uint8_t *strip) /* Flush the conversion buffer to tmpfile2 when it becomes full */ - if (nbytes > (info->iosize - 3)) + if (nbytes > (info->iosize-3)) { ret = tiff_write(info->tmp2fd, info->iobuffer, nbytes); if (ret < 0) @@ -136,7 +132,6 @@ int tiff_convstrip(FAR struct tiff_info_s *info, FAR const uint8_t *strip) #ifdef CONFIG_DEBUG_GRAPHICS DEBUGASSERT(ntotal == info->bps); #endif - return ret; } @@ -153,8 +148,7 @@ int tiff_convstrip(FAR struct tiff_info_s *info, FAR const uint8_t *strip) * tiff_initialize(). * * Input Parameters: - * info - A pointer to the caller allocated parameter passing/TIFF - * state instance. + * info - A pointer to the caller allocated parameter passing/TIFF state instance. * buffer - A buffer containing a single row of data. * * Returned Value: @@ -176,9 +170,7 @@ int tiff_addstrip(FAR struct tiff_info_s *info, FAR const uint8_t *strip) ret = tiff_convstrip(info, strip); } - /* For other formats, it is a simple write using the number of bytes per - * strip. - */ + /* For other formats, it is a simple write using the number of bytes per strip */ else { @@ -197,7 +189,6 @@ int tiff_addstrip(FAR struct tiff_info_s *info, FAR const uint8_t *strip) { goto errout; } - info->outsize += 4; ret = tiff_putint32(info->tmp1fd, info->tmp2size); @@ -205,7 +196,6 @@ int tiff_addstrip(FAR struct tiff_info_s *info, FAR const uint8_t *strip) { goto errout; } - info->tmp1size += 4; /* Increment the size of tmp2file. */ @@ -220,17 +210,14 @@ int tiff_addstrip(FAR struct tiff_info_s *info, FAR const uint8_t *strip) ret = (int)newsize; goto errout; } - info->tmp2size = (size_t)newsize; /* Increment the number of strips in the TIFF file */ info->nstrips++; - return OK; errout: - tiff_abort(info); return ret; } diff --git a/graphics/tiff/tiff_finalize.c b/graphics/tiff/tiff_finalize.c index da49343c9..11409e785 100644 --- a/graphics/tiff/tiff_finalize.c +++ b/graphics/tiff/tiff_finalize.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/tiff/tiff_finalize.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -29,7 +27,7 @@ #include #include #include -#include +#include #include "graphics/tiff.h" @@ -124,7 +122,7 @@ static int tiff_writeifdentry(int fd, off_t offset, /* Then write the IFD entry */ - return tiff_write(fd, ifdentry, SIZEOF_IFD_ENTRY); + return tiff_write(fd, ifdentry, SIZEOF_IFD_ENTRY); } /**************************************************************************** @@ -150,21 +148,18 @@ static void tiff_cleanup(FAR struct tiff_info_s *info) { close(info->outfd); } - info->outfd = -1; if (info->tmp1fd >= 0) { close(info->tmp1fd); } - info->tmp1fd = -1; if (info->tmp2fd >= 0) { close(info->tmp2fd); } - info->tmp2fd = -1; /* And remove the temporary files */ @@ -205,21 +200,20 @@ int tiff_finalize(FAR struct tiff_info_s *info) int i; int j; - /* Put all of the pieces together to create the final output file. - * There are three pieces: + /* Put all of the pieces together to create the final output file. There + * are three pieces: * * 1) outfile: The partial output file containing the header, IFD and strip * counts. This includes the StripOffsets and StripByteCounts that need * to be updated. Size=outsize; - * 2) tmpfile1: This contains the offsets into tmpfile3 for each strip. - * The size of this file is tmp1size. These offsets are relative to the + * 2) tmpfile1: This contains the offsets into tmpfile3 for each strip. The + * size of this file is tmp1size. These offsets are relative to the * beginning of tmpfile3 and need to be offset by outsize+tmp1size. * 3) tmpfile3: The strip data. Size is tmp2size. This is raw image data; * no fixups are required. */ - DEBUGASSERT(info && info->outfd >= 0 && - info->tmp1fd >= 0 && info->tmp2fd >= 0); + DEBUGASSERT(info && info->outfd >= 0 && info->tmp1fd >= 0 && info->tmp2fd >= 0); DEBUGASSERT((info->outsize & 3) == 0 && (info->tmp1size & 3) == 0); /* Fix-up the count value in the StripByteCounts IFD entry in the outfile. @@ -227,8 +221,7 @@ int tiff_finalize(FAR struct tiff_info_s *info) * was written. */ - ret = tiff_readifdentry(info->outfd, info->filefmt->sbcifdoffset, - &ifdentry); + ret = tiff_readifdentry(info->outfd, info->filefmt->sbcifdoffset, &ifdentry); if (ret < 0) { goto errout; @@ -236,8 +229,7 @@ int tiff_finalize(FAR struct tiff_info_s *info) tiff_put32(ifdentry.count, info->nstrips); - ret = tiff_writeifdentry(info->outfd, info->filefmt->sbcifdoffset, - &ifdentry); + ret = tiff_writeifdentry(info->outfd, info->filefmt->sbcifdoffset, &ifdentry); if (ret < 0) { goto errout; @@ -248,8 +240,7 @@ int tiff_finalize(FAR struct tiff_info_s *info) * outfile, hence, the correct offset is outsize. */ - ret = tiff_readifdentry(info->outfd, info->filefmt->soifdoffset, - &ifdentry); + ret = tiff_readifdentry(info->outfd, info->filefmt->soifdoffset, &ifdentry); if (ret < 0) { goto errout; @@ -258,8 +249,7 @@ int tiff_finalize(FAR struct tiff_info_s *info) tiff_put32(ifdentry.count, info->nstrips); tiff_put32(ifdentry.offset, info->outsize); - ret = tiff_writeifdentry(info->outfd, info->filefmt->soifdoffset, - &ifdentry); + ret = tiff_writeifdentry(info->outfd, info->filefmt->soifdoffset, &ifdentry); if (ret < 0) { goto errout; @@ -343,7 +333,6 @@ int tiff_finalize(FAR struct tiff_info_s *info) total += nbytes; #endif } - #ifdef CONFIG_DEBUG_GRAPHICS DEBUGASSERT(total == info->tmp1size); #endif @@ -362,7 +351,7 @@ int tiff_finalize(FAR struct tiff_info_s *info) #ifdef CONFIG_DEBUG_GRAPHICS total = 0; #endif - for (; ; ) + for (;;) { ssize_t nbytes; @@ -394,7 +383,6 @@ int tiff_finalize(FAR struct tiff_info_s *info) total += nbytes; #endif } - #ifdef CONFIG_DEBUG_GRAPHICS DEBUGASSERT(total == info->tmp2size); #endif @@ -409,20 +397,19 @@ errout: return ret; } -/**************************************************************************** +/************************************************************************************ * Name: tiff_abort * * Description: * Abort the TIFF file creation and create-up resources. * * Input Parameters: - * info - A pointer to the caller allocated parameter passing/TIFF state - * instance. + * info - A pointer to the caller allocated parameter passing/TIFF state instance. * * Returned Value: * None * - ****************************************************************************/ + ************************************************************************************/ void tiff_abort(FAR struct tiff_info_s *info) { diff --git a/graphics/tiff/tiff_initialize.c b/graphics/tiff/tiff_initialize.c index 5ce27cac4..8198333ef 100644 --- a/graphics/tiff/tiff_initialize.c +++ b/graphics/tiff/tiff_initialize.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/tiff/tiff_initialize.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -32,7 +30,7 @@ #include #include #include -#include +#include #include "graphics/tiff.h" @@ -41,7 +39,6 @@ /**************************************************************************** * Pre-Processor Definitions ****************************************************************************/ - /* Bi-level Images * * Offset Description Contents/Notes @@ -51,18 +48,13 @@ * 8 [2 bytes padding] * IFD: 10 Number of Directory Entries 13 * 12 NewSubfileType - * 24 ImageWidth Number of columns is a user - * parameter - * 36 ImageLength Number of rows is a user - * parameter - * 48 Compression Hard-coded no compression - * (for now) + * 24 ImageWidth Number of columns is a user parameter + * 36 ImageLength Number of rows is a user parameter + * 48 Compression Hard-coded no compression (for now) * 60 PhotometricInterpretation Value is a user parameter - * 72 StripOffsets Offset and count determined - * as strips added + * 72 StripOffsets Offset and count determined as strips added * 84 RowsPerStrip Value is a user parameter - * 96 StripByteCounts Offset and count determined - * as strips added + * 96 StripByteCounts Offset and count determined as strips added * 108 XResolution Value is a user parameter * 120 YResolution Value is a user parameter * 132 Resolution Unit Hard-coded to "inches" @@ -73,10 +65,8 @@ * Values: * 172 XResolution Hard-coded to 300/1 * 180 YResolution Hard-coded to 300/1 - * 188 "NuttX" Length = 6 (including NUL - * terminator) - * 194 "YYYY:MM:DD HH:MM:SS" Length = 20 (including NUL - * terminator) + * 188 "NuttX" Length = 6 (including NUL terminator) + * 194 "YYYY:MM:DD HH:MM:SS" Length = 20 (ncluding NUL terminator) * 214 [2 bytes padding] * 216 StripByteCounts Beginning of strip byte counts * xxx StripOffsets Beginning of strip offsets @@ -84,7 +74,7 @@ * xxx Data for strips Beginning of strip data */ -#define TIFF_IFD_OFFSET (SIZEOF_TIFF_HEADER + 2) +#define TIFF_IFD_OFFSET (SIZEOF_TIFF_HEADER+2) #define TIFF_BILEV_NIFDENTRIES 13 #define TIFF_BILEV_STRIPIFDOFFS 72 @@ -110,19 +100,14 @@ * 8 [2 bytes padding] * IFD: 10 Number of Directory Entries 14 * 12 NewSubfileType - * 24 ImageWidth Number of columns is a user - * parameter - * 36 ImageLength Number of rows is a user - * parameter + * 24 ImageWidth Number of columns is a user parameter + * 36 ImageLength Number of rows is a user parameter * 48 BitsPerSample - * 60 Compression Hard-coded no compression - * (for now) + * 60 Compression Hard-coded no compression (for now) * 72 PhotometricInterpretation Value is a user parameter - * 84 StripOffsets Offset and count determined - * as strips added + * 84 StripOffsets Offset and count determined as strips added * 96 RowsPerStrip Value is a user parameter - * 108 StripByteCounts Offset and count determined - * as strips added + * 108 StripByteCounts Offset and count determined as strips added * 120 XResolution Value is a user parameter * 132 YResolution Value is a user parameter * 144 Resolution Unit Hard-coded to "inches" @@ -133,10 +118,8 @@ * Values: * 184 XResolution Hard-coded to 300/1 * 192 YResolution Hard-coded to 300/1 - * 200 "NuttX" Length = 6 (including NUL - * terminator) - * 206 "YYYY:MM:DD HH:MM:SS" Length = 20 (including NUL - * terminator) + * 200 "NuttX" Length = 6 (including NUL terminator) + * 206 "YYYY:MM:DD HH:MM:SS" Length = 20 (ncluding NUL terminator) * 226 [2 bytes padding] * 228 StripByteCounts Beginning of strip byte counts * xxx StripOffsets Beginning of strip offsets @@ -163,20 +146,15 @@ * 8 [2 bytes padding] * IFD: 10 Number of Directory Entries 15 * 12 NewSubfileType - * 24 ImageWidth Number of columns is a user - * parameter - * 36 ImageLength Number of rows is a user - * parameter + * 24 ImageWidth Number of columns is a user parameter + * 36 ImageLength Number of rows is a user parameter * 48 BitsPerSample 8, 8, 8 - * 60 Compression Hard-coded no compression - * (for now) + * 60 Compression Hard-coded no compression (for now) * 72 PhotometricInterpretation Value is a user parameter - * 84 StripOffsets Offset and count determined - * as strips added + * 84 StripOffsets Offset and count determined as strips added * 96 SamplesPerPixel Hard-coded to 3 * 108 RowsPerStrip Value is a user parameter - * 120 StripByteCounts Offset and count determined - * as strips added + * 120 StripByteCounts Offset and count determined as strips added * 132 XResolution Value is a user parameter * 144 YResolution Value is a user parameter * 156 Resolution Unit Hard-coded to "inches" @@ -189,10 +167,8 @@ * 204 YResolution Hard-coded to 300/1 * 212 BitsPerSample 8, 8, 8 * 218 [2 bytes padding] - * 220 "NuttX" Length = 6 (including NUL - * terminator) - * 226 "YYYY:MM:DD HH:MM:SS" Length = 20 (including NUL - * terminator) + * 220 "NuttX" Length = 6 (including NUL terminator) + * 226 "YYYY:MM:DD HH:MM:SS" Length = 20 (ncluding NUL terminator) * 246 [2 bytes padding] * 248 StripByteCounts Beginning of strip byte counts * xxx StripOffsets Beginning of strip offsets @@ -211,12 +187,8 @@ #define TIFF_RGB_DATEOFFSET 226 #define TIFF_RGB_STRIPBCOFFSET 248 -/**************************************************************************** - * Debug - ****************************************************************************/ - -/* CONFIG_DEBUG_TIFFOFFSETS may be defined (along with CONFIG_DEBUG_FEATURES - * and +/* Debug *******************************************************************/ +/* CONFIG_DEBUG_TIFFOFFSETS may be defined (along with CONFIG_DEBUG_FEATURES and * CONFIG_DEBUG_GRAPHICS) in order to verify the pre-determined TIFF file * offsets. */ @@ -226,11 +198,11 @@ #endif #ifdef CONFIG_DEBUG_TIFFOFFSETS -# define tiff_offset(o, l) (o) += (l) -# define tiff_checkoffs(o, x) DEBUGASSERT((o) == (x)) +# define tiff_offset(o,l) (o) += (l) +# define tiff_checkoffs(o,x) DEBUGASSERT((o) == (x)) #else -# define tiff_offset(o, l) -# define tiff_checkoffs(o, x) +# define tiff_offset(o,l) +# define tiff_checkoffs(o,x) #endif /**************************************************************************** @@ -434,9 +406,9 @@ static int tiff_datetime(FAR char *timbuf, unsigned int buflen) /* Break the current time up into the format needed by strftime */ - gmtime_r(&ts.tv_sec, &tm); + gmtime_r((FAR const time_t*)&ts.tv_sec, &tm); - /* Convert the current time to TIFF format */ + /* Comvert the current time in the TIFF format */ strftime(timbuf, buflen, TIFF_DATETIME_FORMAT, &tm); return OK; @@ -453,8 +425,7 @@ static int tiff_datetime(FAR char *timbuf, unsigned int buflen) * Setup to create a new TIFF file. * * Input Parameters: - * info - A pointer to the caller allocated parameter passing/TIFF state - * instance. + * info - A pointer to the caller allocated parameter passing/TIFF state instance. * * Returned Value: * Zero (OK) on success. A negated errno value on failure. @@ -474,7 +445,7 @@ int tiff_initialize(FAR struct tiff_info_s *info) /* Open all output files */ - info->outfd = open(info->outfile, O_RDWR | O_CREAT | O_TRUNC, 0666); + info->outfd = open(info->outfile, O_RDWR|O_CREAT|O_TRUNC, 0666); if (info->outfd < 0) { gerr("ERROR: Failed to open %s for reading/writing: %d\n", @@ -482,7 +453,7 @@ int tiff_initialize(FAR struct tiff_info_s *info) goto errout; } - info->tmp1fd = open(info->tmpfile1, O_RDWR | O_CREAT | O_TRUNC, 0666); + info->tmp1fd = open(info->tmpfile1, O_RDWR|O_CREAT|O_TRUNC, 0666); if (info->tmp1fd < 0) { gerr("ERROR: Failed to open %s for reading/writing: %d\n", @@ -490,7 +461,7 @@ int tiff_initialize(FAR struct tiff_info_s *info) goto errout; } - info->tmp2fd = open(info->tmpfile2, O_RDWR | O_CREAT | O_TRUNC, 0666); + info->tmp2fd = open(info->tmpfile2, O_RDWR|O_CREAT|O_TRUNC, 0666); if (info->tmp2fd < 0) { gerr("ERROR: Failed to open %s for reading/writing: %d\n", @@ -532,7 +503,7 @@ int tiff_initialize(FAR struct tiff_info_s *info) case FB_FMT_RGB24: /* BPP=24 R=8, G=8, B=8 */ info->filefmt = &g_rgbinfo; /* RGB file image file info */ info->imgflags = IMGFLAGS_FMT_RGB24; /* Bit encoded image characteristics */ - info->bps = 3 * info->pps; /* Bytes per strip */ + info->bps = 3 *info->pps; /* Bytes per strip */ break; default: @@ -553,7 +524,6 @@ int tiff_initialize(FAR struct tiff_info_s *info) { goto errout; } - tiff_offset(offset, TIFF_IFD_OFFSET); /* Write the Number of directory entries @@ -566,7 +536,6 @@ int tiff_initialize(FAR struct tiff_info_s *info) { goto errout; } - tiff_offset(offset, 2); /* Write the NewSubfileType IFD entry @@ -574,13 +543,11 @@ int tiff_initialize(FAR struct tiff_info_s *info) * All formats: Offset 12 NewSubfileType */ - ret = tiff_putifdentry16(info, IFD_TAG_NEWSUBFILETYPE, - IFD_FIELD_LONG, 1, 0); + ret = tiff_putifdentry16(info, IFD_TAG_NEWSUBFILETYPE, IFD_FIELD_LONG, 1, 0); if (ret < 0) { goto errout; } - tiff_offset(offset, SIZEOF_IFD_ENTRY); /* Write ImageWidth and ImageLength @@ -589,20 +556,17 @@ int tiff_initialize(FAR struct tiff_info_s *info) * 36 ImageLength Number of rows is a user parameter */ - ret = tiff_putifdentry16(info, IFD_TAG_IMAGEWIDTH, - IFD_FIELD_SHORT, 1, info->imgwidth); + ret = tiff_putifdentry16(info, IFD_TAG_IMAGEWIDTH, IFD_FIELD_SHORT, 1, info->imgwidth); if (ret == OK) { - ret = tiff_putifdentry16(info, IFD_TAG_IMAGELENGTH, - IFD_FIELD_SHORT, 1, info->imgheight); + ret= tiff_putifdentry16(info, IFD_TAG_IMAGELENGTH, IFD_FIELD_SHORT, 1, info->imgheight); } if (ret < 0) { goto errout; } - - tiff_offset(offset, 2 * SIZEOF_IFD_ENTRY); + tiff_offset(offset, 2*SIZEOF_IFD_ENTRY); /* Write BitsPerSample * @@ -623,24 +587,20 @@ int tiff_initialize(FAR struct tiff_info_s *info) val16 = 4; } - ret = tiff_putifdentry16(info, IFD_TAG_BITSPERSAMPLE, - IFD_FIELD_SHORT, 1, val16); + ret = tiff_putifdentry16(info, IFD_TAG_BITSPERSAMPLE, IFD_FIELD_SHORT, 1, val16); if (ret < 0) { goto errout; } - tiff_offset(offset, SIZEOF_IFD_ENTRY); } else if (IMGFLAGS_ISRGB(info->imgflags)) { - ret = tiff_putifdentry(info, IFD_TAG_BITSPERSAMPLE, - IFD_FIELD_SHORT, 3, TIFF_RGB_BPSOFFSET); + ret = tiff_putifdentry(info, IFD_TAG_BITSPERSAMPLE, IFD_FIELD_SHORT, 3, TIFF_RGB_BPSOFFSET); if (ret < 0) { goto errout; } - tiff_offset(offset, SIZEOF_IFD_ENTRY); } @@ -651,13 +611,11 @@ int tiff_initialize(FAR struct tiff_info_s *info) * RGB: Offset 60 " " " " "" " " " " " " */ - ret = tiff_putifdentry16(info, IFD_TAG_COMPRESSION, - IFD_FIELD_SHORT, 1, TAG_COMP_NONE); + ret = tiff_putifdentry16(info, IFD_TAG_COMPRESSION, IFD_FIELD_SHORT, 1, TAG_COMP_NONE); if (ret < 0) { goto errout; } - tiff_offset(offset, SIZEOF_IFD_ENTRY); /* Write PhotometricInterpretation: @@ -681,7 +639,6 @@ int tiff_initialize(FAR struct tiff_info_s *info) { goto errout; } - tiff_offset(offset, SIZEOF_IFD_ENTRY); /* Write StripOffsets: @@ -697,7 +654,6 @@ int tiff_initialize(FAR struct tiff_info_s *info) { goto errout; } - tiff_offset(offset, SIZEOF_IFD_ENTRY); /* Write SamplesPerPixel @@ -709,13 +665,11 @@ int tiff_initialize(FAR struct tiff_info_s *info) if (IMGFLAGS_ISRGB(info->imgflags)) { - ret = tiff_putifdentry16(info, IFD_TAG_SAMPLESPERPIXEL, - IFD_FIELD_SHORT, 1, 3); + ret = tiff_putifdentry16(info, IFD_TAG_SAMPLESPERPIXEL, IFD_FIELD_SHORT, 1, 3); if (ret < 0) { goto errout; } - tiff_offset(offset, SIZEOF_IFD_ENTRY); } @@ -726,33 +680,26 @@ int tiff_initialize(FAR struct tiff_info_s *info) * RGB: Offset 108 Value is a user parameter */ - ret = tiff_putifdentry16(info, IFD_TAG_ROWSPERSTRIP, - IFD_FIELD_SHORT, 1, info->rps); + ret = tiff_putifdentry16(info, IFD_TAG_ROWSPERSTRIP, IFD_FIELD_SHORT, 1, info->rps); if (ret < 0) { goto errout; } - tiff_offset(offset, SIZEOF_IFD_ENTRY); /* Write StripByteCounts: * - * Bi-level Images: Offset 96 Count determined as strips added, Value - * offset = 216 - * Greyscale: Offset 108 Count determined as strips added, Value - * offset = 228 - * RGB: Offset 120 Count determined as strips added, Value - * offset = 248 + * Bi-level Images: Offset 96 Count determined as strips added, Value offset = 216 + * Greyscale: Offset 108 Count determined as strips added, Value offset = 228 + * RGB: Offset 120 Count determined as strips added, Value offset = 248 */ tiff_checkoffs(offset, info->filefmt->sbcifdoffset); - ret = tiff_putifdentry(info, IFD_TAG_STRIPCOUNTS, - IFD_FIELD_LONG, 0, info->filefmt->sbcoffset); + ret = tiff_putifdentry(info, IFD_TAG_STRIPCOUNTS, IFD_FIELD_LONG, 0, info->filefmt->sbcoffset); if (ret < 0) { goto errout; } - tiff_offset(offset, SIZEOF_IFD_ENTRY); /* Write XResolution and YResolution: @@ -762,22 +709,17 @@ int tiff_initialize(FAR struct tiff_info_s *info) * RGB: Offset 132 and 144, Values are a user parameters */ - ret = tiff_putifdentry(info, IFD_TAG_XRESOLUTION, - IFD_FIELD_RATIONAL, 1, - info->filefmt->xresoffset); + ret = tiff_putifdentry(info, IFD_TAG_XRESOLUTION, IFD_FIELD_RATIONAL, 1, info->filefmt->xresoffset); if (ret == OK) { - ret = tiff_putifdentry(info, IFD_TAG_YRESOLUTION, - IFD_FIELD_RATIONAL, 1, - info->filefmt->yresoffset); + ret = tiff_putifdentry(info, IFD_TAG_YRESOLUTION, IFD_FIELD_RATIONAL, 1, info->filefmt->yresoffset); } if (ret < 0) { goto errout; } - - tiff_offset(offset, 2 * SIZEOF_IFD_ENTRY); + tiff_offset(offset, 2*SIZEOF_IFD_ENTRY); /* Write ResolutionUnit: * @@ -786,13 +728,11 @@ int tiff_initialize(FAR struct tiff_info_s *info) * RGB: Offset 156, Hard-coded to "inches" */ - ret = tiff_putifdentry16(info, IFD_TAG_RESUNIT, - IFD_FIELD_SHORT, 1, TAG_RESUNIT_INCH); + ret = tiff_putifdentry16(info, IFD_TAG_RESUNIT, IFD_FIELD_SHORT, 1, TAG_RESUNIT_INCH); if (ret < 0) { goto errout; } - tiff_offset(offset, SIZEOF_IFD_ENTRY); /* Write Software: @@ -802,14 +742,11 @@ int tiff_initialize(FAR struct tiff_info_s *info) * RGB: Offset 168 Count, Hard-coded "NuttX" */ - ret = tiff_putifdentry(info, IFD_TAG_SOFTWARE, - IFD_FIELD_ASCII, TIFF_SOFTWARE_STRLEN, - info->filefmt->swoffset); + ret = tiff_putifdentry(info, IFD_TAG_SOFTWARE, IFD_FIELD_ASCII, TIFF_SOFTWARE_STRLEN, info->filefmt->swoffset); if (ret < 0) { goto errout; } - tiff_offset(offset, SIZEOF_IFD_ENTRY); /* Write DateTime: @@ -819,14 +756,11 @@ int tiff_initialize(FAR struct tiff_info_s *info) * RGB: Offset 180 Count, Format "YYYY:MM:DD HH:MM:SS" */ - ret = tiff_putifdentry(info, IFD_TAG_DATETIME, - IFD_FIELD_ASCII, TIFF_DATETIME_STRLEN, - info->filefmt->dateoffset); + ret = tiff_putifdentry(info, IFD_TAG_DATETIME, IFD_FIELD_ASCII, TIFF_DATETIME_STRLEN, info->filefmt->dateoffset); if (ret < 0) { goto errout; } - tiff_offset(offset, SIZEOF_IFD_ENTRY); /* Write Next IFD Offset and 2 bytes of padding: @@ -844,7 +778,6 @@ int tiff_initialize(FAR struct tiff_info_s *info) { goto errout; } - tiff_offset(offset, 4); /* Now we begin the value section of the file */ @@ -872,7 +805,6 @@ int tiff_initialize(FAR struct tiff_info_s *info) { goto errout; } - tiff_offset(offset, 8); tiff_checkoffs(offset, info->filefmt->yresoffset); @@ -886,7 +818,6 @@ int tiff_initialize(FAR struct tiff_info_s *info) { goto errout; } - tiff_offset(offset, 8); /* Write RGB BitsPerSample Data: @@ -904,7 +835,6 @@ int tiff_initialize(FAR struct tiff_info_s *info) tiff_putint16(info->outfd, 8); tiff_putint16(info->outfd, 8); tiff_putint16(info->outfd, 0); - tiff_offset(offset, 8); } @@ -917,13 +847,11 @@ int tiff_initialize(FAR struct tiff_info_s *info) */ tiff_checkoffs(offset, info->filefmt->swoffset); - ret = tiff_putstring(info->outfd, TIFF_SOFTWARE_STRING, - TIFF_SOFTWARE_STRLEN); + ret = tiff_putstring(info->outfd, TIFF_SOFTWARE_STRING, TIFF_SOFTWARE_STRLEN); if (ret < 0) { goto errout; } - tiff_offset(offset, TIFF_SOFTWARE_STRLEN); /* Write the DateTime string: @@ -946,7 +874,6 @@ int tiff_initialize(FAR struct tiff_info_s *info) { goto errout; } - tiff_offset(offset, TIFF_DATETIME_STRLEN); /* Add two bytes of padding */ @@ -956,7 +883,6 @@ int tiff_initialize(FAR struct tiff_info_s *info) { goto errout; } - tiff_offset(offset, 2); /* And that should do it! */ diff --git a/graphics/tiff/tiff_internal.h b/graphics/tiff/tiff_internal.h index b76615145..00bc6515b 100644 --- a/graphics/tiff/tiff_internal.h +++ b/graphics/tiff/tiff_internal.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/tiff/tiff_internal.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/graphics/tiff/tiff_utils.c b/graphics/tiff/tiff_utils.c index 12aa4bb8e..70de92925 100644 --- a/graphics/tiff/tiff_utils.c +++ b/graphics/tiff/tiff_utils.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/tiff/tiff_utils.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -30,7 +28,7 @@ #include #include #include -#include +#include #include "graphics/tiff.h" @@ -93,10 +91,10 @@ void tiff_put32(FAR uint8_t *dest, uint32_t value) { #ifdef CONFIG_ENDIAN_BIG tiff_put16(dest, (uint16_t)(value >> 16)); - tiff_put16(dest + 2, (uint16_t)(value & 0xffff)); + tiff_put16(dest+2, (uint16_t)(value & 0xffff)); #else tiff_put16(dest, (uint16_t)(value & 0xffff)); - tiff_put16(dest + 2, (uint16_t)(value >> 16)); + tiff_put16(dest+2, (uint16_t)(value >> 16)); #endif } @@ -112,10 +110,11 @@ uint16_t tiff_get16(FAR uint8_t *src) uint32_t tiff_get32(FAR uint8_t *src) { #ifdef CONFIG_ENDIAN_BIG - return (uint32_t)tiff_get16(src) << 16 | (uint32_t)tiff_get16(src + 2); + return (uint32_t)tiff_get16(src) << 16 | (uint32_t)tiff_get16(src+2); #else - return (uint32_t)tiff_get16(src + 2) << 16 | (uint32_t)tiff_get16(src); + return (uint32_t)tiff_get16(src+2) << 16 | (uint32_t)tiff_get16(src); #endif + } /**************************************************************************** @@ -152,7 +151,7 @@ ssize_t tiff_read(int fd, FAR void *buffer, size_t count) * (ntotal). */ - nbytes = read(fd, buffer, count - ntotal); + nbytes = read(fd, buffer, count-ntotal); /* Check for an error */ @@ -165,26 +164,22 @@ ssize_t tiff_read(int fd, FAR void *buffer, size_t count) errval = errno; if (errval != EINTR) { - /* Other errors are bad news and we will break out with an - * error. - */ + /* Other errors are bad news and we will break out with an error */ return -errval; } } - /* Zero is a special case and means that the end of file was - * encountered. - */ + /* Zero is a special case and means that the end of file was encountered. */ else if (nbytes == 0) { break; } - /* What if read returns some number of bytes other than the requested - * number? This probably means that the end-of-file will be - * encountered the next time that we call read(). + /* What if read returns some number of bytes other than the requested number? + * This probably means that the end-of-file will be encountered the next time + * that we call read(). */ else @@ -239,17 +234,13 @@ int tiff_write(int fd, FAR const void *buffer, size_t count) errval = errno; if (errval != EINTR) { - /* Other errors are bad news and we will break out with an - * error. - */ + /* Other errors are bad news and we will break out with an error */ return -errval; } } - /* What if write returns some number of bytes other than the requested - * number? - */ + /* What if write returns some number of bytes other than the requested number? */ else { @@ -333,7 +324,7 @@ int tiff_putstring(int fd, FAR const char *string, int len) #ifdef CONFIG_DEBUG_GRAPHICS int actual = strlen(string); - DEBUGASSERT(len == actual + 1); + DEBUGASSERT(len = actual+1); #endif return tiff_write(fd, string, len); } @@ -342,7 +333,7 @@ int tiff_putstring(int fd, FAR const char *string, int len) * Name: tiff_wordalign * * Description: - * Pad a file with zeros as necessary to achieve word alignment. + * Pad a file with zeros as necessary to achieve word alignament. * * Input Parameters: * fd - File descriptor to be used. @@ -369,9 +360,7 @@ ssize_t tiff_wordalign(int fd, size_t size) { return (ssize_t)ret; } - size += nbytes; } - return size; } diff --git a/graphics/twm4nx/Kconfig b/graphics/twm4nx/Kconfig index 3b114df88..9e1322dd0 100644 --- a/graphics/twm4nx/Kconfig +++ b/graphics/twm4nx/Kconfig @@ -42,6 +42,17 @@ config TWM4NX_REVMINOR string "Twm4Nx minor version number" default "0" +config TWM4NX_ARCHINIT + bool "Have architecture-specific initialization" + default n + select BOARDCTL + depends on !NSH_ARCHINIT + ---help--- + Set if your board provides architecture specific initialization + via the board-interface function boardctl(). The boardctl() + function will be called early in Twm4Nx initialization to allow + board logic to do such things as configure MMC/SD slots. + config TWM4NX_NETINIT bool "Network initialization" default y @@ -86,7 +97,7 @@ choice config TWM4NX_MOUSE bool "Mouse" - depends on NX_SWCURSOR + select NX_SWCURSOR config TWM4NX_TOUCHSCREEN bool "Touchscreen" diff --git a/graphics/twm4nx/Make.defs b/graphics/twm4nx/Make.defs index 6d992ec5f..e724004e7 100644 --- a/graphics/twm4nx/Make.defs +++ b/graphics/twm4nx/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/graphics/twm4nx/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/graphics/twm4nx/Makefile b/graphics/twm4nx/Makefile index 6156b2da2..f6de5385a 100644 --- a/graphics/twm4nx/Makefile +++ b/graphics/twm4nx/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/graphics/twm4nx/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -24,7 +22,7 @@ include $(APPDIR)/Make.defs # Add path to cursor images to CXXFLAGS -CXXFLAGS += ${INCDIR_PREFIX}"$(APPDIR)/graphics/nxglyphs/include" +CXXFLAGS += ${shell $(INCDIR) "$(CC)" "$(APPDIR)/graphics/nxglyphs/include"} # Twm4Nx built-in application info diff --git a/graphics/twm4nx/README.md b/graphics/twm4nx/README.md new file mode 100644 index 000000000..5c594b94d --- /dev/null +++ b/graphics/twm4nx/README.md @@ -0,0 +1,386 @@ +# Graphics / `twm4nx` Tab Window Manager (TWM) + +Twm4Nx is a port of twm, Tab Window Manager (or Tom's Window Manager) version +`1.0.10` to NuttX NX windows server. No, a port is not the right word. It is a +re-design of TWM from the inside out to work with the NuttX NX server. The name +Twm4Nx reflects this legacy. But Twm4Nx is more a homage to TWM than a port of +TWM. + +The original TWM was based on X11 which provides a rich set of features. TWM +provided titlebars, shaped windows, several forms of icon management, +user-defined macro functions, click-to-type and pointer-driven keyboard focus, +graphic contexts, and user-specified key and pointer button bindings, etc. + +Twm4Nx, on the other hand is based on the NuttX NX server which provides +comparatively minimal support. Additional drawing support comes from the NuttX +NxWidgets library (which necessitated the change to C++). + +Twm4Nx is greatly stripped down and targeted on small embedded systems with +minimal resources. For example, no assumption is made about the availability of +a file system; no `.twmrc` file is used. Bitmaps are not used (other than for +fonts). + +The TWM license is, I believe compatible with the BSD license used by NuttX. The +origin TWM license required notice of copyrights within each file and a full +copy of the original license which you can find in the `COPYING` file. within +this directory. + +## Status + +### Progress + +- `2019-04-28` This port was brutal. Much TWM logic was removed because it + depended on X11 features (or just because I could not understand how to use + it). The replacement logic is only mostly in place but more needs to be done + to have a complete system (hence, it is marked `EXPERIMENTAL`). The kinds of + things that need to done are: + + 1. Right click should bring up a window list (like the icon manager???) + 2. For TWM-like behavior, a window frame and toolbar should be highlighted + when the window has focus. + 3. A right click on the toolbar should bring up a window-specific menu. + +- `2019-05-02` Some testing progress. The system comes up, connects to and + initializes the VNC window. For some reason, the VNC client breaks the + connection. The server is no longer connected so Twm4Nx constipates and and + eventually hangs. + +- `2019-05-08` I abandoned the VNC interface and found that things are much + better using a direct, hardware framebuffer. The background comes up properly + and the Icon Manager appears properly in the upper right hand corner. The Icon + Manager Window can be iconified or de-iconified. The Icon Manager window can + be grabbed by the toolbar title and moved about on the window (the movement is + not very smooth on the particular hardware that I am working with). + +- `2019-05-10` A left click on the background brings up the main menu. At + present there are only two options: _Desktop_ which will iconify all windows + and _Twm4Nx Icon Manager_ which will de-iconify and/or raise the Icon Manager + window to the top of the hierarchy. That latter option is only meaningful when + the desktop is very crowded. + +- `2019-05-13` Added the NxTerm application. If enabled via + `CONFIG_TWM4XN_NXTERM`, there will now be a _NuttShell_ entry in the Main + Menu. When pressed, this will bring up an NSH session in a Twm4Nx window. + +- `2019-05-14` We can now move an icon on the desktop. Includes logic to avoid + collisions with other icons and with the background image. That later is an + issue. The background image image widget needs to be removed; it can occlude a + desktop icon. We need to paint the image directly on the background without + the use of a widget. + +- `2019-05-15` Resizing now seems to work correctly in Twm4Nx. + +- `2019-05-20` Calibration screen is now in place. + +- `2019-05-21` A `CONTEMPORARY` theme was added. Still has a few glitches. + +- `2019-06-01` A retro, emulated segment LCD clock is now in place. + +## How To + +### Icon Manager + +- At start up, only the Icon Manager window is shown. The Icon Manager is a TWM + alternative to more common desktop icons. Currently Twm4Nx supports both + desktop icons and the Icon Manager. + + Whenever a new application is started from the Main Menu, its name shows up in + the Icon Manager. Selecting the name will either de-iconify the window, or + just raise it to the top of the display. + +### Main Menu: + +- A touch/click at any open location on the background (except the image at the + center or on another icon) will bring up the Main Menu. Options: + - Desktop. Iconify all windows and show the desktop + - Twm4Nx Icom Manager. De-iconify and/or raise the Icon Manager to the top of + the display. + - Calibration. Perform touchscreen re-calibration. + - Clock. Start and instance of clock in the window. The uses the the retro, + LCD emulation of `apps/graphics/slcd`. + - NuttShell. Start and instance of NSH running in an NxTerm. +- All windows close after the terminal menu option is selected. + +### Window Toolbar + +- Most windows have a toolbar at the top. It is optional but used in most + windows. +- The toolbar contains window title and from zero to 4 buttons: + - Right side: A menu button may be presented. The menu button is not used by + anything in the current implementation and is always suppressed + - Left side: The far left is (1) the terminate button (if present). If + present, it will close window when selected. Not all windows can be closed. + You can't close the Icon Manager or menu windows, for example. Then (2) a + resize button. If presented and is selected, then the resize sequence + described below it started. This may the be preceded by a minimize button + that iconifies the window. + +### Moving a Window: + +- Grab the title in the toolbar and move the window to the desired position. + +### Resizing a Window: + +- A window must have the green resize button with the square or it cannot be + resized. +- Press resize button. A small window should pop-up in the upper left hand + corner showing the current window size. +- Touch anywhere in window (not the toolbar) and slide your finger. The resize + window will show the new size but there will be no other update to the + display. It is thought that continuous size updates would overwhelm lower end + MCUs. Movements support include: + - Move toward the right increases the width of the window + - Move toward the left decreases the width of the window + - Move toward the bottom increases the height of the window + - Move toward the top decreases the height of the Window + - Other moves will affect both the height and width of the window. +- **Note**: While resizing, non-critical events from all other windows are + ignored. + +### Themes + +- There are two themes support by the configuration system: + - `CONFIG_TWM4NX_CLASSIC` โ€“ Strong bordered windows with dark primary colors. + Reminiscent of Windows 98. + - `CONFIG_TWM4NX_CONTEMPORARY` โ€“ Border-less windows in pastel shades for a + more contemporary look. + +## Issues: + +`2019-05-16` Twm4Nx is in a very complete state but only at perhaps _alpha_ in +its maturity. You should expect to see some undocumented problems. If you see +such problems and can describe a sequence to actions to reproduce the problem, +let me know and I will try to resolve the problems. + +Here are all known issues and features that are missing: + +TWM Compatibilities Issues: +1. Resizing works a little differently in Twm4Nx. +2. Right click should bring up a window list +3. For TWM-like behavior, a window frame and toolbar should be highlighted when + the window has focus. +4. A right click on the toolbar should bring up a window-specific menu. + +There are no near-term plans to address these compatibility issues. + +Other issues/bugs. All-in-all, I would say that Twm4Nx is maturing well and is +attaining stability. That being said, there are some issues and untested +functionality that should be addressed: + +1. Icon drag movement includes logic to avoid collisions with other icons and + with the background image. That later is an issue. We need to paint the image + directly on the background without the use of a widget. +2. There are a few color artifacts in the toolbar of the `CONTEMPORARY` theme. + These look like borders are being drawn around the toolbar widgets (even + though the are configured to be borderless). +3. Most Twm4Nx configuration settings are hard-coded in `*_config.hxx` header + files. These all need to be brought out and made accessible via Kconfig files +4. I have seen some odd behavior when many NxTerm windows have been opened + (around 15). Specifically, I see failures to start NSH in the windows so they + come up blank. All other behaviors seem normal. Most likely, some NxTerm + resource allocation is failing silently and leaving things in an unusable + state. The board I am using has 128Mb of SDRAM so I can't believe that memory + is the limiting factor. These are, however, RAM-backed windows and will use + significant amounts of memory. The primary issue is that the number of + windows should probably be managed in some way to assure that the end-user + does not experience odd behaviors when resource usage is high. +5. Menus with sub-menus have not been verified. There is no use of sub- menus in + the current code base so I expect that there are issues when, for example, + and item from a sub-menu item: That menu and all of its antecedent menus + should be closed. +6. There is an optional MENU button that may appear at the far left on the + toolbar. It is not used by any window in the current code base and, hence, is + unverified. I would expect some issues with generating and routing the MENU + button events to applications. There are likely other unverified features. +7. X/Y input may be either via a touchscreen or a mouse. Only touchscreen input + has been verified. There is, however, very little difference. The primary + issue is in cursor support: Cursors are needed with a mouse. Cursor images + also change depending on the state (like grabbing and dragging or resizing). + There is also a possibility of using auto-raise with a mouse as well. All of + this logic is in place, but none has been verified. +8. NxTerm windows really need to be scrollable. They are difficult to use with + only a few lines on a small display. A related usability issue is the font + height: The fonts report a maximum font height that results in a large line + spacing on the display and, hence, fewer lines visible in the small window. + This is latter issues is a problem with the fonts not Twm4Nx, however. +9. There is a trivial rounding error in the calculation of the LCD width in + `SLcd::CSLcd::getWidth()`. It currently truncates down. It needs to round up. + This sometimes leaves a small, one-pixel- wide sliver on the clock display. + This display always recovers and this only cosmetic. + +## Adding Twm4Nx Applications + +### Application Factories and the Main Menu + +The original TWM supported a .twmrc in which you could describe application +programs supported on the desktop. Currently no such start-up file is available +for Twm4Nx. Rather, all applications must be added via run-time interfaces. And +overview of these interfaces is provided in this paragraph. + +Currently, there are only two applications developed for Twm4Nx: (1) An NxTerm +hosting NSH that is analogous to an XTerm hosting the Bash shell in a Unix +environment, and (2) a touchscreen calibration application. Let's focus instead +on the NxTerm application as an example because the touchscreen calibration is a +rather unusual beast. + +These example applications can be found at: `apps/graphics/twm4nx/apps` and +`apps/include/graphics/twm4nx/apps` + +In short, adding an application involves a _Factory Object_ that is hooked into +the Main Menu. A Factory Object is an object that is used to create other object +instances. The way in which the Factory Object is represented is purely a +decision of the application developer. One option, however, is to use the pure +virtual base class `IApplicationFactory` as defined in +`apps/include/graphics/twm4nx/iapplication.hxx`. This base class provides only a +single method: + +```cpp +bool initialize(FAR CTwm4Nx *twm4nx); +``` + +where CTwm4Nx is the Twm4NX session instance that allows the class +implementation to interact with session specific resources. Multiple sessions +would be required, for example, if the platform supported multiple displays. + +In practice, the application factory implementation class inherits from the +following base classes: + +1. `IApplicationFactory`. Provides the common `initialize()` method. +2. `IApplication`. Provides the information for the application's entry in the + Main Menu +3. `CTwm4NxEvent`. Hooks the application factory into the Twm4Nx event + notification system. + +Initialization consists of instantiating the application factory instance and +calling its `IApplicationFactory::initialize()` method. The application factory +instance is a singleton that must persist for the life of the session. For the +NxTerm application factory, this is done in +`apps/graphics/twm4nx/src/twm4nx_main.c` like: + +```cpp +CNxTermFactory nxtermFactory; +success = nxtermFactory.initialize(twm4nx); +``` + +In addition to general initialization, the `IApplicationFactory::initialize()` +method must register a new entry with the main menu. You can see an example of +this in `apps/graphics/twm4nx/apps/cnxterm.c`: + +```cpp +FAR CMainMenu *cmain = twm4nx->getMainMenu(); +return cmain->addApplication(this); +``` + +The argument to the `CMainMenu::addApplication()` method is of type +`IApplication *`. Remember, however, that our application implementation `class` +inherited from `IApplication`. + +The IApplication pure virtual base class is also defined in +`apps/include/graphics/twm4nx/iapplication.hxx`. It essentially describes what +the Main Menu logic should do when the menu item is selected. It includes these +methods: + +1. `getName()`. Provides the name string that will be shown in the Main Menu for + this selection. +2. `getSubMenu()`. One possibility is that selecting the Main Menu item is that + it may bring up yet another sub-menu of options. +3. `getEventHandler()`. Returns an instance of `CTwm4NxEvent` that is used to + route menu selection events. Remember that our application factory inherits + from `CTwm4NxEvent` so this function only needs to return the 'this' + pointer. +4. `getEvent()`. Provides the event ID that will be used in the event + notification. The returned value must conform to the description in + `apps/include/graphics/twm4nx/twm4nx_events.hxx`. In particular, the + recipient of the event must be `EVENT_RECIPIENT_APP`. + +The Twm4Nx application is then started when the application factory's +`CTwm4NxEvent::event()` method is called with the specified event. + +### Application Windows + +How the application factory starts an application instance is purely up to the +application designer. Typically this would include starting a new application +task. General characteristics of an application include: + +1. It probably should inherit from `CTwm4NxEvent` so that it can receive events + from the system. +2. To create the window, it must instantiate and initialize an instance of + `CWindow`. +3. It must configure application events to receive notifications from Twm4Nx. + +To create an application window, the application must call the +`CWindowFactory::createWindow()` method. For the NxTerm example, this looks +like: + +```cpp +NXWidgets::CNxString name("NuttShell"); + +uint8_t wflags = (WFLAGS_NO_MENU_BUTTON | WFLAGS_HIDDEN); + +FAR CWindowFactory *factory = m_twm4nx->getWindowFactory(); +m_nxtermWindow = factory->createWindow(name, &CONFIG_TWM4NX_NXTERM_ICON, + (FAR CIconMgr *)0, wflags); +``` + +The window factory is another factory that creates and manages window instance. +The `createWindow()` method requires four parameters: + +1. The name of the window. This is the name that is show in the window toolbar + and may be the same name as was used in the Main Menu entry. +2. A reference to the the Icon image associated with the window. This is the + image that is show on the desktop when the window is iconified. It is of + type `NXWidgets::SRlePaletteBitmap`. +3. A pointer to the Icon Manager instance that this window belongs with. This + can be NULL to use the default Twm4Nx Icon Manager. +4. A set of flags that describe properties of the windows. + + The flag values are defined byte `WFLAGS_*` definitions provided in + `apps/include/graphics/twm4nx/cwindow.hxx`: + + - `WFLAGS_NO_MENU_BUTTON` โ€“ Omit the menu button from the toolbar. + - `WFLAGS_NO_DELETE_BUTTON` โ€“ Omit the delete button from the toolbar. + - `WFLAGS_NO_RESIZE_BUTTON` โ€“ Omit the resize button from the toolbar. + - `WFLAGS_NO_MINIMIZE_BUTTON` โ€“ Omit the minimize button from the toolbar. + - `WFLAGS_NO_TOOLBAR` โ€“ Omit the toolbar altogether. + - `WFLAGS_ICONMGR` โ€“ This window is an icon manager. + - `WFLAGS_MENU` โ€“ This window is a menu window. + - `WFLAGS_HIDDEN` โ€“ Start with the window hidden. + +Once the `CWindow` is instantiated, events needed by the application can be +configured as is done in the NxTerm application: + +```cpp +struct SAppEvents events; +events.eventObj = (FAR void *)this; +events.redrawEvent = EVENT_NXTERM_REDRAW; +events.resizeEvent = EVENT_NXTERM_RESIZE; +events.mouseEvent = EVENT_NXTERM_XYINPUT; +events.kbdEvent = EVENT_NXTERM_KBDINPUT; +events.closeEvent = EVENT_NXTERM_CLOSE; +events.deleteEvent = EVENT_NXTERM_DELETE; + +bool success = m_nxtermWindow->configureEvents(events); +``` + +Again, recall that the application inherits from `CTwm4NxEvent`. So passing +`this` as the event object above assures that the specific events are routed to +the application instance. + +Drawing in the application window can be performed using that facilities of +NXWidgets using the `NXWidgets::CGraphicsPort` associated with the window. The +NxTerm application does not perform any drawing, however; that drawing is +performed by the NxTerm driver. + +The `NXWidgets::CGraphicsPort` can be obtained from a `CWindow` instance, say +`m_window`, like: + +```cpp +FAR NXWidgets::CWidgetControl *control = m_window->getWidgetControl(); +NXWidgets::CGraphicsPort *port = control->getGraphicsPort(); +``` + +That `CGraphicsPort` is then passed to the widget constructor, binding the +widget to that window and forcing all widget drawing to occur within the window. + +Obviously, a lot more could be written about drawing, much more than can be +addressed in this README file. diff --git a/graphics/twm4nx/apps/ccalibration.cxx b/graphics/twm4nx/apps/ccalibration.cxx index 40317cdb6..cd505a927 100644 --- a/graphics/twm4nx/apps/ccalibration.cxx +++ b/graphics/twm4nx/apps/ccalibration.cxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/graphics/twm4nx/src/ccalibration.cxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -27,14 +25,14 @@ #include #include +#include +#include #include #include #include #include -#include -#include -#include +#include #include #include @@ -128,6 +126,7 @@ CCalibration::CCalibration(FAR CTwm4Nx *twm4nx) sem_init(&m_exclSem, 0, 1); sem_init(&m_synchSem, 0, 0); + sem_setprotocol(&m_synchSem, SEM_PRIO_NONE); } /** diff --git a/graphics/twm4nx/apps/cclock.cxx b/graphics/twm4nx/apps/cclock.cxx index e9d3b55bd..fcf3e876b 100644 --- a/graphics/twm4nx/apps/cclock.cxx +++ b/graphics/twm4nx/apps/cclock.cxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/graphics/twm4nx/src/cnxterm.cxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -28,12 +26,12 @@ #include #include +#include #include +#include #include -#include -#include -#include +#include #include @@ -299,6 +297,7 @@ bool CClock::run(void) // start the new Clock task sem_init(&GClockVars.waitSem, 0, 0); + sem_setprotocol(&GClockVars.waitSem, SEM_PRIO_NONE); GClockVars.that = this; GClockVars.success = false; @@ -362,7 +361,7 @@ void CClock::stop(void) // Then delete the NSH task, possibly stranding resources - task_delete(pid); + std::task_delete(pid); } } diff --git a/graphics/twm4nx/apps/cnxterm.cxx b/graphics/twm4nx/apps/cnxterm.cxx index a36edc4db..957b96c9d 100644 --- a/graphics/twm4nx/apps/cnxterm.cxx +++ b/graphics/twm4nx/apps/cnxterm.cxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/graphics/twm4nx/src/cnxterm.cxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -28,14 +26,14 @@ #include #include +#include +#include #include #include #include #include -#include -#include -#include +#include #include "nshlib/nshlib.h" @@ -332,7 +330,7 @@ void CNxTerm::stop(void) // Construct the driver name using this minor number char devname[32]; - snprintf(devname, sizeof(devname), "/dev/nxterm%d", m_minor); + snprintf(devname, 32, "/dev/nxterm%d", m_minor); unlink(devname); m_NxTerm = 0; @@ -375,7 +373,7 @@ int CNxTerm::nxterm(int argc, char *argv[]) // Construct the driver name using this minor number char devname[32]; - snprintf(devname, sizeof(devname), "/dev/nxterm%d", GNxTermVars.minor); + snprintf(devname, 32, "/dev/nxterm%d", GNxTermVars.minor); // Increment the minor number while it is protect by the semaphore @@ -404,16 +402,16 @@ int CNxTerm::nxterm(int argc, char *argv[]) std::fflush(stderr); #ifdef CONFIG_NXTERM_NXKBDIN - dup2(fd, 0); + std::dup2(fd, 0); #endif - dup2(fd, 1); - dup2(fd, 2); + std::dup2(fd, 1); + std::dup2(fd, 2); // And we can close our original driver file descriptor if (fd > 2) { - close(fd); + std::close(fd); } // Inform the parent thread that we successfully initialized @@ -576,6 +574,20 @@ bool CNxTermFactory::nshlibInitialize(void) // Initialize the NSH library nsh_initialize(); + + // If the Telnet console is selected as a front-end, then start the + // Telnet daemon. + +#ifdef CONFIG_NSH_TELNET + int ret = nsh_telnetstart(AF_UNSPEC); + if (ret < 0) + { + // The daemon is NOT running! + + return false; + } +#endif + return true; } diff --git a/graphics/twm4nx/src/cbackground.cxx b/graphics/twm4nx/src/cbackground.cxx index 664913e00..8ff48f5d9 100644 --- a/graphics/twm4nx/src/cbackground.cxx +++ b/graphics/twm4nx/src/cbackground.cxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/graphics/twm4nx/include/cbackground.cxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -26,10 +24,9 @@ #include +#include #include -#include - #include #include "graphics/nxwidgets/cscaledbitmap.hxx" diff --git a/graphics/twm4nx/src/cfonts.cxx b/graphics/twm4nx/src/cfonts.cxx index 03fcbee57..b46baafbd 100644 --- a/graphics/twm4nx/src/cfonts.cxx +++ b/graphics/twm4nx/src/cfonts.cxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/graphics/twm4nx/src/cfonts.cxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The diff --git a/graphics/twm4nx/src/ciconmgr.cxx b/graphics/twm4nx/src/ciconmgr.cxx index 24150a701..5cffa328f 100644 --- a/graphics/twm4nx/src/ciconmgr.cxx +++ b/graphics/twm4nx/src/ciconmgr.cxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/graphics/twm4nx/src/ciconmgr.cxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -732,7 +730,7 @@ void CIconMgr::insertEntry(FAR struct SWindowEntry *wentry, // Insert the new window mid-list, in name order NXWidgets::CNxString windowName = cwin->getWindowName(); - if (windowName.compareTo(tmpwin->cwin->getWindowName()) > 0) + if (windowName.compareTo( tmpwin->cwin->getWindowName()) > 0) { wentry->flink = tmpwin; wentry->blink = tmpwin->blink; diff --git a/graphics/twm4nx/src/ciconwidget.cxx b/graphics/twm4nx/src/ciconwidget.cxx index 0f2153030..46f43ac2d 100644 --- a/graphics/twm4nx/src/ciconwidget.cxx +++ b/graphics/twm4nx/src/ciconwidget.cxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/graphics/twm4nx/src/ciconwidget.cxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -26,12 +24,11 @@ #include +#include #include #include +#include #include - -#include -#include #include #include diff --git a/graphics/twm4nx/src/cinput.cxx b/graphics/twm4nx/src/cinput.cxx index a6486de07..291234fa0 100644 --- a/graphics/twm4nx/src/cinput.cxx +++ b/graphics/twm4nx/src/cinput.cxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/graphics/NxWidgets/nxwm/src/cinput.cxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -26,14 +24,14 @@ #include +#include #include +#include -#include #include #include #include #include -#include #include #include @@ -99,6 +97,7 @@ CInput::CInput(CTwm4Nx *twm4nx) // Initialize the semaphore used to synchronize with the listener thread sem_init(&m_waitSem, 0, 0); + sem_setprotocol(&m_waitSem, SEM_PRIO_NONE); #ifdef CONFIG_TWM4NX_TOUCHSCREEN // Calibration @@ -128,7 +127,7 @@ CInput::~CInput(void) if (m_kbdFd >= 0) { - close(m_kbdFd); + std::close(m_kbdFd); } #endif @@ -137,7 +136,7 @@ CInput::~CInput(void) if (m_mouseFd >= 0) { - close(m_mouseFd); + std::close(m_mouseFd); } #endif } @@ -221,7 +220,7 @@ int CInput::keyboardOpen(void) { // Try to open the keyboard device non-blocking. - fd = open(CONFIG_TWM4NX_KEYBOARD_DEVPATH, O_RDONLY | O_NONBLOCK); + fd = std::open(CONFIG_TWM4NX_KEYBOARD_DEVPATH, O_RDONLY | O_NONBLOCK); if (fd < 0) { int errcode = errno; @@ -247,7 +246,7 @@ int CInput::keyboardOpen(void) // Sleep a bit and try again twminfo("WAITING for a USB keyboard\n"); - sleep(2); + std::sleep(2); } // Anything else would be really bad. @@ -297,7 +296,7 @@ inline int CInput::mouseOpen(void) { // Try to open the mouse device non-blocking - fd = open(CONFIG_TWM4NX_MOUSE_DEVPATH, O_RDONLY | O_NONBLOCK); + fd = std::open(CONFIG_TWM4NX_MOUSE_DEVPATH, O_RDONLY | O_NONBLOCK); if (fd < 0) { int errcode = errno; @@ -323,7 +322,7 @@ inline int CInput::mouseOpen(void) // Sleep a bit and try again twminfo("WAITING for a USB mouse\n"); - sleep(2); + std::sleep(2); } // Anything else would be really bad. @@ -786,12 +785,12 @@ int CInput::session(void) struct pollfd pfd[NINPUT_DEVICES]; #ifndef CONFIG_TWM4NX_NOKEYBOARD pfd[KBD_INDEX].fd = m_kbdFd; - pfd[KBD_INDEX].events = POLLIN; + pfd[KBD_INDEX].events = POLLIN | POLLERR | POLLHUP; pfd[KBD_INDEX].revents = 0; #endif #ifndef CONFIG_TWM4NX_NOMOUSE pfd[MOUSE_INDEX].fd = m_mouseFd; - pfd[MOUSE_INDEX].events = POLLIN; + pfd[MOUSE_INDEX].events = POLLIN | POLLERR | POLLHUP; pfd[MOUSE_INDEX].revents = 0; #endif @@ -818,7 +817,7 @@ int CInput::session(void) if ((pfd[KBD_INDEX].revents & (POLLERR | POLLHUP)) != 0) { - twmerr("ERROR: keyboard poll() failed. revents=%08" PRIx32 "\n", + twmerr("ERROR: keyboard poll() failed. revents=%04x\n", pfd[KBD_INDEX].revents); ret = -EIO; break; @@ -840,7 +839,7 @@ int CInput::session(void) if ((pfd[MOUSE_INDEX].revents & (POLLERR | POLLHUP)) != 0) { - twmerr("ERROR: Mouse poll() failed. revents=%08" PRIx32 "\n", + twmerr("ERROR: Mouse poll() failed. revents=%04x\n", pfd[MOUSE_INDEX].revents); ret = -EIO; break; @@ -957,14 +956,14 @@ FAR void *CInput::listener(FAR void *arg) #ifndef CONFIG_TWM4NX_NOKEYBOARD // Close the keyboard device - close(This->m_kbdFd); + std::close(This->m_kbdFd); This->m_kbdFd = -1; #endif #ifndef CONFIG_TWM4NX_NOMOUSE // Close the mouse device - close(This->m_mouseFd); + std::close(This->m_mouseFd); This->m_mouseFd = -1; #endif } diff --git a/graphics/twm4nx/src/cmainmenu.cxx b/graphics/twm4nx/src/cmainmenu.cxx index e2b9c1992..4e47fcde8 100644 --- a/graphics/twm4nx/src/cmainmenu.cxx +++ b/graphics/twm4nx/src/cmainmenu.cxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/graphics/twm4nx/include/cmainmenu.cxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -26,8 +24,8 @@ #include -#include -#include +#include +#include #include diff --git a/graphics/twm4nx/src/cmenus.cxx b/graphics/twm4nx/src/cmenus.cxx index 701fc1a79..9c6d1f3bd 100644 --- a/graphics/twm4nx/src/cmenus.cxx +++ b/graphics/twm4nx/src/cmenus.cxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/graphics/twm4nx/src/cmenus.cxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The diff --git a/graphics/twm4nx/src/cresize.cxx b/graphics/twm4nx/src/cresize.cxx index 0e39cea53..fd65f80c6 100644 --- a/graphics/twm4nx/src/cresize.cxx +++ b/graphics/twm4nx/src/cresize.cxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/graphics/twm4nx/src/cresize.cxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -39,7 +37,6 @@ #include #include -#include #include @@ -65,7 +62,11 @@ #define MINHEIGHT 0 // had been 32 #define MINWIDTH 0 // had been 60 -#define makemult(a,b) ((b == 1) ? (a) : (((int)((a) / (b))) * (b))) +#define makemult(a,b) ((b==1) ? (a) : (((int)((a) / (b))) * (b))) + +#ifndef MIN +# define MIN(a,b) (((a) < (b)) ? (a) : (b)) +#endif ///////////////////////////////////////////////////////////////////////////// // Class Implementations @@ -415,8 +416,6 @@ bool CResize::setWindowSize(FAR struct nxgl_size_s *size) void CResize::updateSizeLabel(FAR struct nxgl_size_s &windowSize) { - int ret; - // Do nothing if the size has not changed struct nxgl_size_s labelSize; @@ -428,8 +427,8 @@ void CResize::updateSizeLabel(FAR struct nxgl_size_s &windowSize) } FAR char *str; - ret = asprintf(&str, " %4d x %-4d ", windowSize.w, windowSize.h); - if (ret < 0) + asprintf(&str, " %4d x %-4d ", windowSize.w, windowSize.h); + if (str == (FAR char *)0) { twmerr("ERROR: Failed to get size string\n"); return; diff --git a/graphics/twm4nx/src/ctwm4nx.cxx b/graphics/twm4nx/src/ctwm4nx.cxx index eaa07bc1a..b0391eeb7 100644 --- a/graphics/twm4nx/src/ctwm4nx.cxx +++ b/graphics/twm4nx/src/ctwm4nx.cxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/graphics/twm4nx/src/ctwm4nx.cxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -43,11 +41,11 @@ #include #include #include +#include #include #include #include -#include #include #include @@ -384,10 +382,7 @@ void CTwm4Nx::genMqName(void) unsigned long randvalue = (unsigned long)std::random() & 0x00fffffful; - if (std::asprintf(&m_queueName, "Twm4Nx%06lu", randvalue) < 0) - { - m_queueName = NULL; - } + std::asprintf(&m_queueName, "Twm4Nx%06lu", randvalue); } /** diff --git a/graphics/twm4nx/src/cwindow.cxx b/graphics/twm4nx/src/cwindow.cxx index 5d71d7990..cdf22577e 100644 --- a/graphics/twm4nx/src/cwindow.cxx +++ b/graphics/twm4nx/src/cwindow.cxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/graphics/twm4nx/src/cwindow.cxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -39,11 +37,11 @@ #include +#include #include #include #include -#include #include #include @@ -96,15 +94,19 @@ struct SToolbarInfo struct SToolbarInfo GToolBarInfo[NTOOLBAR_BUTTONS] = { + [MENU_BUTTON] = { &CONFIG_TWM4NX_MENU_IMAGE, false, EVENT_TOOLBAR_MENU }, + [DELETE_BUTTON] = { &CONFIG_TWM4NX_TERMINATE_IMAGE, true, EVENT_TOOLBAR_TERMINATE }, + [RESIZE_BUTTON] = { &CONFIG_TWM4NX_RESIZE_IMAGE, true, EVENT_RESIZE_BUTTON }, + [MINIMIZE_BUTTON] = { &CONFIG_TWM4NX_MINIMIZE_IMAGE, true, EVENT_TOOLBAR_MINIMIZE } diff --git a/graphics/twm4nx/src/cwindowevent.cxx b/graphics/twm4nx/src/cwindowevent.cxx index b29268b84..b329423ec 100644 --- a/graphics/twm4nx/src/cwindowevent.cxx +++ b/graphics/twm4nx/src/cwindowevent.cxx @@ -1,7 +1,5 @@ // apps/graphics/twm4nx/src/cwindowevent.cxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -57,9 +55,9 @@ #include +#include #include -#include #include #include diff --git a/graphics/twm4nx/src/cwindowfactory.cxx b/graphics/twm4nx/src/cwindowfactory.cxx index bfda3f2c6..35a7373e1 100644 --- a/graphics/twm4nx/src/cwindowfactory.cxx +++ b/graphics/twm4nx/src/cwindowfactory.cxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/graphics/twm4nx/src/cwindowfactory.cxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The diff --git a/graphics/twm4nx/src/twm4nx_cursor.cxx b/graphics/twm4nx/src/twm4nx_cursor.cxx index f9778d06e..efea39c47 100644 --- a/graphics/twm4nx/src/twm4nx_cursor.cxx +++ b/graphics/twm4nx/src/twm4nx_cursor.cxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/graphics/twm4nx/src/twm4nx_cursor.cxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The diff --git a/graphics/twm4nx/src/twm4nx_main.cxx b/graphics/twm4nx/src/twm4nx_main.cxx index 3cfb3a6b5..c3de5e23a 100644 --- a/graphics/twm4nx/src/twm4nx_main.cxx +++ b/graphics/twm4nx/src/twm4nx_main.cxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/graphics/twm4nx/src/twm4nx_main.cxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -98,6 +96,23 @@ int main(int argc, FAR char *argv[]) int ret; +#if defined(CONFIG_TWM4NX_ARCHINIT) && defined(CONFIG_BOARDCTL) && \ + !defined(CONFIG_BOARD_LATE_INITIALIZE) + // Should we perform board-specific initialization? There are two ways + // that board initialization can occur: 1) automatically via + // board_late_initialize() during bootup if CONFIG_BOARD_LATE_INITIALIZE, or + // 2) here via a call to boardctl() if the interface is enabled + // (CONFIG_BOARDCTL=y). board_early_initialize() is also possibility, + // although less likely. + + ret = boardctl(BOARDIOC_INIT, 0); + if (ret < 0) + { + twmerr("ERROR: boardctl(BOARDIOC_INIT) failed: %d\n", errno); + return EXIT_FAILURE; + } +#endif + #ifdef CONFIG_TWM4NX_NETINIT /* Bring up the network */ diff --git a/import/Make.defs b/import/Make.defs index 2b8236d25..e5b0ed16f 100644 --- a/import/Make.defs +++ b/import/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/import/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -29,13 +27,13 @@ include $(TOPDIR)/scripts/Make.defs # Compiler ARCHCRT0OBJ = $(call CONVERT_PATH,$(TOPDIR)$(DELIM)startup$(DELIM)crt0$(OBJEXT)) -ARCHINCLUDES += ${INCSYSDIR_PREFIX}$(TOPDIR)$(DELIM)include +ARCHINCLUDES += ${shell $(INCDIR) -s "$(CC)" $(TOPDIR)$(DELIM)include} -ARCHXXINCLUDES += ${INCSYSDIR_PREFIX}$(TOPDIR)$(DELIM)include -ARCHXXINCLUDES += ${INCSYSDIR_PREFIX}$(TOPDIR)$(DELIM)include$(DELIM)cxx +ARCHXXINCLUDES += ${shell $(INCDIR) -s "$(CC)" $(TOPDIR)$(DELIM)include} +ARCHXXINCLUDES += ${shell $(INCDIR) -s "$(CC)" $(TOPDIR)$(DELIM)include$(DELIM)cxx} ARCHCFLAGS += -fno-common -pipe -ARCHCXXFLAGS += -fno-common -nostdinc++ -pipe +ARCHCXXFLAGS += -fno-common -pipe CFLAGS = $(ARCHCFLAGS) $(ARCHWARNINGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRADEFINES) CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS) @@ -68,18 +66,16 @@ LDLIBPATH = $(addprefix -L,$(call CONVERT_PATH,$(TOPDIR)$(DELIM)libs)) # Link with user libraries ifeq ($(CONFIG_BUILD_KERNEL),y) - LDLIBS += -lmm -lc -lproxies + LDLIBS = -lapps -lmm -lc -lproxies ifeq ($(CONFIG_HAVE_CXX),y) LDLIBS += -lxx endif -ifeq ($(CONFIG_LIBM_TOOLCHAIN),y) +ifneq ($(CONFIG_LIBM),y) LIBM = ${shell "$(CC)" $(ARCHCPUFLAGS) --print-file-name=libm.a} ifneq ($(LIBM),".") LDLIBPATH += -L "${shell dirname $(LIBM)}" LDLIBS += -lm endif -else ifneq ($(CONFIG_LIBM_NONE),) - LDLIBS += -lm endif endif @@ -94,13 +90,5 @@ endif # ELF module definitions -ifeq ($(CONFIG_BINFMT_ELF_RELOCATABLE),y) - LDELFFLAGS += -r -endif -LDELFFLAGS += -e _start -Bstatic - -# Remove other ld scripts, just use import ld scripts -# -LDFILE := $(filter -T %.ld, $(LDELFFLAGS)) -LDELFFLAGS := $(filter-out $(LDFILE), $(LDELFFLAGS)) +LDELFFLAGS = -r -e _start -Bstatic LDELFFLAGS += $(addprefix -T,$(call CONVERT_PATH,$(TOPDIR)/scripts/gnu-elf.ld)) diff --git a/import/Makefile b/import/Makefile index 577708cac..be5c4dc8e 100644 --- a/import/Makefile +++ b/import/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/import/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/include/.gitignore b/include/.gitignore index b237d4f3c..9d6149edc 100644 --- a/include/.gitignore +++ b/include/.gitignore @@ -1,4 +1,2 @@ /netutils/cJSON.h /netutils/cJSON_Utils.h -/audioutils/rtttl.h -/audioutils/morsey.h diff --git a/include/audioutils/fmsynth.h b/include/audioutils/fmsynth.h deleted file mode 100644 index f38bc1cc6..000000000 --- a/include/audioutils/fmsynth.h +++ /dev/null @@ -1,86 +0,0 @@ -/**************************************************************************** - * apps/include/audioutils/fmsynth.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __INCLUDE_AUDIOUTILS_FMSYNTH_H -#define __INCLUDE_AUDIOUTILS_FMSYNTH_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -#include -#include - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define FMSYNTH_MAX_VOLUME (SHRT_MAX) - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -typedef struct fmsynth_sound_s -{ - int own_allocate; - int phase_time; - int max_phase_time; - int volume; - FAR fmsynth_op_t *operators; - - FAR struct fmsynth_sound_s *next_sound; -} fmsynth_sound_t; - -typedef CODE void (*fmsynth_tickcb_t)(unsigned long cbarg); - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -#ifdef __cplusplus -extern "C" -{ -#endif - -int fmsynth_initialize(int fs); -FAR fmsynth_sound_t *fmsynthsnd_create(void); -FAR fmsynth_sound_t *create_fmsynthsnd(FAR fmsynth_sound_t *); -void fmsynthsnd_stop(FAR fmsynth_sound_t *snd); -void fmsynthsnd_delete(FAR fmsynth_sound_t *snd); -int fmsynthsnd_set_operator(FAR fmsynth_sound_t *snd, FAR fmsynth_op_t *op); -void fmsynthsnd_set_soundfreq(FAR fmsynth_sound_t *snd, float freq); -void fmsynthsnd_set_volume(FAR fmsynth_sound_t *snd, float vol); -int fmsynthsnd_add_subsound(FAR fmsynth_sound_t *top, - FAR fmsynth_sound_t *sub); -int fmsynth_rendering(FAR fmsynth_sound_t *snd, - FAR int16_t *sample, int sample_num, int chnum, - fmsynth_tickcb_t cb, unsigned long cbarg); - -#ifdef __cplusplus -} -#endif - -#endif /* __INCLUDE_AUDIOUTILS_FMSYNTH_H */ diff --git a/include/audioutils/fmsynth_eg.h b/include/audioutils/fmsynth_eg.h deleted file mode 100644 index 9d21c688d..000000000 --- a/include/audioutils/fmsynth_eg.h +++ /dev/null @@ -1,103 +0,0 @@ -/**************************************************************************** - * apps/include/audioutils/fmsynth_eg.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __APPS_INCLUDE_AUDIOUTILS_FMSYNTH_EG_H -#define __APPS_INCLUDE_AUDIOUTILS_FMSYNTH_EG_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define FMSYNTH_MAX_EGLEVEL (SHRT_MAX / 8) - -#define EGSTATE_ATTACK (0) -#define EGSTATE_DECAYBREAK (1) -#define EGSTATE_DECAY (2) -#define EGSTATE_SUSTAIN (3) -#define EGSTATE_RELEASE (4) -#define EGSTATE_RELEASED (5) -#define EGSTATE_MAX (6) - -#define EGSTATE_NUM EGSTATE_RELEASED - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -struct fmsynth_eglevel_s -{ - float level; - int period_ms; -}; - -typedef struct fmsynth_eglevels_s -{ - struct fmsynth_eglevel_s attack; - struct fmsynth_eglevel_s decaybrk; - struct fmsynth_eglevel_s decay; - struct fmsynth_eglevel_s sustain; - struct fmsynth_eglevel_s release; -} fmsynth_eglevels_t; - -typedef struct fmsynth_egparam_s -{ - int initval; - int period; - int diff2next; -} fmsynth_egparam_t; - -typedef struct fmsynth_eg_s -{ - int state; - int state_counter; - fmsynth_egparam_t state_params[EGSTATE_MAX]; -} fmsynth_eg_t; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -#ifdef __cplusplus -extern "C" -{ -#endif - -FAR fmsynth_eg_t *create_fmsyntheg(fmsynth_eg_t *eg); -FAR fmsynth_eg_t *fmsyntheg_create(void); -void fmsyntheg_delete(FAR fmsynth_eg_t *eg); -int fmsyntheg_set_param(FAR fmsynth_eg_t *eg, - int fs, FAR fmsynth_eglevels_t *levels); -void fmsyntheg_start(FAR fmsynth_eg_t *eg); -void fmsyntheg_stop(FAR fmsynth_eg_t *eg); -int fmsyntheg_operate(FAR fmsynth_eg_t *eg); - -#ifdef __cplusplus -} -#endif - -#endif /* __APPS_INCLUDE_AUDIOUTILS_FMSYNTH_EG_H */ diff --git a/include/audioutils/fmsynth_op.h b/include/audioutils/fmsynth_op.h deleted file mode 100644 index 38a24172d..000000000 --- a/include/audioutils/fmsynth_op.h +++ /dev/null @@ -1,104 +0,0 @@ -/**************************************************************************** - * apps/include/audioutils/fmsynth_op.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __APPS_INCLUDE_AUDIOUTILS_FMSYNTH_OP_H -#define __APPS_INCLUDE_AUDIOUTILS_FMSYNTH_OP_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define FMSYNTH_PI (0x10000) - -#define FMSYNTH_OPFUNC_SIN (0) -#define FMSYNTH_OPFUNC_TRIANGLE (1) -#define FMSYNTH_OPFUNC_SAWTOOTH (2) -#define FMSYNTH_OPFUNC_SQUARE (3) -#define FMSYNTH_OPFUNC_NUM (4) - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -typedef CODE int (*opfunc_t)(int theta); - -typedef struct fmsynth_op_s -{ - FAR fmsynth_eg_t *eg; - opfunc_t wavegen; - struct fmsynth_op_s *cascadeop; - struct fmsynth_op_s *parallelop; - - int own_allocate; - FAR int *feedback_ref; - int feedback_val; - int feedbackrate; - int last_sigval; - - float freq_rate; - float sound_freq; - float delta_phase; - float current_phase; -} fmsynth_op_t; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -#ifdef __cplusplus -extern "C" -{ -#endif - -int fmsynthop_set_samplerate(int fs); - -FAR fmsynth_op_t *fmsynthop_create(void); -FAR fmsynth_op_t *create_fmsynthop(FAR fmsynth_op_t *op, - FAR fmsynth_eg_t *eg); -void fmsynthop_delete(FAR fmsynth_op_t *op); -int fmsynthop_select_opfunc(FAR fmsynth_op_t *op, int type); -int fmsynthop_set_envelope(FAR fmsynth_op_t *op, - FAR fmsynth_eglevels_t *levels); -int fmsynthop_cascade_subop(FAR fmsynth_op_t *op, - FAR fmsynth_op_t *subop); -int fmsynthop_parallel_subop(FAR fmsynth_op_t *op, - FAR fmsynth_op_t *subop); -int fmsynthop_bind_feedback(FAR fmsynth_op_t *op, - FAR fmsynth_op_t *subop, float ratio); -int fmsynthop_update_feedback(FAR fmsynth_op_t *op); -void fmsynthop_set_soundfreq(FAR fmsynth_op_t *op, float freq); -void fmsynthop_set_soundfreqrate(FAR fmsynth_op_t *op, float rate); -void fmsynthop_start(FAR fmsynth_op_t *op); -void fmsynthop_stop(FAR fmsynth_op_t *op); -int fmsynthop_operate(FAR fmsynth_op_t *op, int phase_time); - -#ifdef __cplusplus -} -#endif - -#endif /* __APPS_INCLUDE_AUDIOUTILS_FMSYNTH_OP_H */ diff --git a/include/audioutils/mml_parser.h b/include/audioutils/mml_parser.h deleted file mode 100644 index ac9496f72..000000000 --- a/include/audioutils/mml_parser.h +++ /dev/null @@ -1,104 +0,0 @@ -/**************************************************************************** - * apps/include/audioutils/mml_parser.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __APPS_INCLUDE_AUDIOUTILS_MML_PARSER_MML_PARSER_H -#define __APPS_INCLUDE_AUDIOUTILS_MML_PARSER_MML_PARSER_H - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define MML_TYPE_EOF (0) -#define MML_TYPE_NOTE (1) -#define MML_TYPE_REST (2) -#define MML_TYPE_TEMPO (3) -#define MML_TYPE_LENGTH (4) -#define MML_TYPE_OCTAVE (5) -#define MML_TYPE_TUPLETSTART (6) -#define MML_TYPE_TUPLETDONE (7) -#define MML_TYPE_VOLUME (8) -#define MML_TYPE_TONE (9) -#define MML_TYPE_CHORD (10) - -#define MML_TYPE_NOTE_ERROR (-MML_TYPE_NOTE) -#define MML_TYPE_REST_ERROR (-MML_TYPE_REST) -#define MML_TYPE_TEMPO_ERROR (-MML_TYPE_TEMPO) -#define MML_TYPE_LENGTH_ERROR (-MML_TYPE_LENGTH) -#define MML_TYPE_OCTAVE_ERROR (-MML_TYPE_OCTAVE) -#define MML_TYPE_VOLUME_ERROR (-MML_TYPE_VOLUME) -#define MML_TYPE_TUPLET_ERROR (-MML_TYPE_TUPLETSTART) -#define MML_TYPE_TONE_ERROR (-MML_TYPE_TONE) -#define MML_TYPE_CHORD_ERROR (-MML_TYPE_CHORD) - -#define MML_TYPE_ILLIGAL_COMPOSITION (-100) -#define MML_TYPE_ILLIGAL_TOOMANY_NOTES (-101) -#define MML_TYPE_ILLIGAL_TOOFEW_NOTES (-102) -#define MML_TYPE_ILLIGAL_DOUBLE_TUPLET (-103) - -#define MML_STATE_NORMAL (0) -#define MML_STATE_TUPLET (1) - -#define MAX_CHORD_NOTES (5) - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -struct music_macro_lang_s -{ - int cur_tempo; - int cur_octave; - int def_length; - int fs; - - int state; - int cur_tuplet; - int tuplet_notes; - int tuplet_length; -}; - -struct mml_result_s -{ - int note_idx[MAX_CHORD_NOTES]; - int length; - int chord_notes; -}; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -#ifdef __cplusplus -extern "C" -{ -#endif - -int init_mml(FAR struct music_macro_lang_s *mml, - int fs, int tempo, int octave, int length); -int parse_mml(FAR struct music_macro_lang_s *mml, - FAR char **score, FAR struct mml_result_s *result); - -#ifdef __cplusplus -} -#endif - -#endif /* __APPS_INCLUDE_AUDIOUTILS_MML_PARSER_MML_PARSER_H */ diff --git a/include/audioutils/nxaudio.h b/include/audioutils/nxaudio.h deleted file mode 100644 index eec0ea486..000000000 --- a/include/audioutils/nxaudio.h +++ /dev/null @@ -1,86 +0,0 @@ -/**************************************************************************** - * apps/include/audioutils/nxaudio.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __APPS_INCLUDE_AUDIOUTILS_NXAUDIO_H -#define __APPS_INCLUDE_AUDIOUTILS_NXAUDIO_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include - -/**************************************************************************** - * Public Data Types - ****************************************************************************/ - -struct nxaudio_s -{ - int fd; - - int abufnum; - FAR struct ap_buffer_s **abufs; - mqd_t mq; - - int chnum; -}; - -struct nxaudio_callbacks_s -{ - void CODE (*dequeue)(unsigned long arg, FAR struct ap_buffer_s *apb); - void CODE (*complete)(unsigned long arg); - void CODE (*user)(unsigned long arg, FAR struct audio_msg_s *msg, - FAR bool *running); -}; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -#ifdef __cplusplus -extern "C" -{ -#endif - -int init_nxaudio(FAR struct nxaudio_s *nxaudio, - int fs, int bps, int chnum); -int init_nxaudio_devname(FAR struct nxaudio_s *nxaudio, - int fs, int bps, int chnum, - const char *devname, const char *mqname); -void fin_nxaudio(FAR struct nxaudio_s *nxaudio); -int nxaudio_enqbuffer(FAR struct nxaudio_s *nxaudio, - FAR struct ap_buffer_s *apb); -int nxaudio_pause(FAR struct nxaudio_s *nxaudio); -int nxaudio_resume(FAR struct nxaudio_s *nxaudio); -int nxaudio_setvolume(FAR struct nxaudio_s *nxaudio, uint16_t vol); -int nxaudio_start(FAR struct nxaudio_s *nxaudio); -int nxaudio_msgloop(FAR struct nxaudio_s *nxaudio, - FAR struct nxaudio_callbacks_s *cbs, unsigned long arg); -int nxaudio_stop(FAR struct nxaudio_s *nxaudio); - -#ifdef __cplusplus -} -#endif - -#endif /* __APPS_INCLUDE_AUDIOUTILS_NXAUDIO_H */ diff --git a/include/builtin/builtin.h b/include/builtin/builtin.h index b0e0f4866..e6662127f 100644 --- a/include/builtin/builtin.h +++ b/include/builtin/builtin.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/builtin/builtin.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -32,7 +30,6 @@ #include #include -#include /**************************************************************************** * Pre-processor Definitions @@ -67,9 +64,13 @@ extern "C" * New application is run in a separate task context (and thread). * * Input Parameter: - * filename - Name of the linked-in binary to be started. - * argv - Argument list - * param - Parameters for execute. + * filename - Name of the linked-in binary to be started. + * argv - Argument list + * redirfile - If output is redirected, this parameter will be non-NULL + * and will provide the full path to the file. + * oflags - If output is redirected, this parameter will provide the + * open flags to use. This will support file replacement + * of appending to an existing file. * * Returned Value: * This is an end-user function, so it follows the normal convention: @@ -79,7 +80,7 @@ extern "C" ****************************************************************************/ int exec_builtin(FAR const char *appname, FAR char * const *argv, - FAR const struct nsh_param_s *param); + FAR const char *redirfile, int oflags); #undef EXTERN #if defined(__cplusplus) diff --git a/include/canutils/.gitignore b/include/canutils/.gitignore index cd3875f43..4396c63a2 100644 --- a/include/canutils/.gitignore +++ b/include/canutils/.gitignore @@ -1,4 +1,2 @@ /canard.h /canard_nuttx.h -/canard_dsdl.h -/o1heap.h diff --git a/include/canutils/canlib.h b/include/canutils/canlib.h index 4f280549d..75521b295 100644 --- a/include/canutils/canlib.h +++ b/include/canutils/canlib.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/canutils/canlib.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -109,8 +107,6 @@ int canlib_getbaud(int fd, FAR int *bauds); * ****************************************************************************/ -int canlib_setloopback(int fd, bool loop); - /**************************************************************************** * Name: canlib_getloopback * @@ -128,6 +124,8 @@ int canlib_setloopback(int fd, bool loop); * ****************************************************************************/ +int canlib_setloopback(int fd, bool loop); + int canlib_getloopback(int fd, FAR bool *loop); /**************************************************************************** @@ -138,8 +136,8 @@ int canlib_getloopback(int fd, FAR bool *loop); * peripheral never transmits on the bus, but receives all bus traffic. * * Input Parameter: - * fd - file descriptor of an opened can device - * silent - whether to use silent mode. + * fd - file descriptor of an opened can device + * loopback - whether to use loopback mode. * * Returned Value: * Zero (OK) is returned on success. Otherwise -1 (ERROR) @@ -157,8 +155,8 @@ int canlib_setsilent(int fd, bool silent); * Wrapper for CANIOC_GET_CONNMODES. * * Input Parameter: - * fd - file descriptor of an opened can device - * silent - pointer to a buffer to store the current silent mode state. + * fd - file descriptor of an opened can device + * loopback - pointer to a buffer to store the current silent mode state. * * Returned Value: * Zero (OK) is returned on success. Otherwise -1 (ERROR) diff --git a/include/canutils/lely/config.h b/include/canutils/lely/config.h deleted file mode 100644 index 9e9d82d6d..000000000 --- a/include/canutils/lely/config.h +++ /dev/null @@ -1,280 +0,0 @@ -/**************************************************************************** - * apps/include/canutils/lely/config.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __APPS_INCLUDE_CANUTILS_LELY_CONFIG_H -#define __APPS_INCLUDE_CANUTILS_LELY_CONFIG_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* General NuttX port configuration */ - -#define _WIN32 0 -#define _WIN64 0 -#define LELY_NO_ERRNO 0 -#define LELY_NO_MALLOC 0 -#define LELY_NO_THREADS 0 -#define LELY_NO_STDIO 0 -#define LELY_NO_ATOMICS 0 -#define HAVE_SYS_IOCTL_H 1 -#define LELY_HAVE_ITIMERSPEC 1 -#define LELY_HAVE_SYS_TYPES_H 1 -#define LELY_HAVE_STRINGS_H 1 -#define LELY_HAVE_UCHAR_H 0 -#define _POSIX_C_SOURCE 200112L - -/* --disable-daemon */ - -#define LELY_NO_DAEMON 1 - -/* --disable-cxx */ - -#ifdef CONFIG_HAVE_CXX -# define LELY_NO_CXX 0 -#else -# define LELY_NO_CXX 1 -#endif - -/* SocketCAN support */ - -#ifdef CONFIG_NET_CAN -# define LELY_HAVE_SOCKET_CAN 1 -#else -# define LELY_HAVE_SOCKET_CAN 0 -#endif - -/* --disable-canfd */ - -#ifdef CONFIG_CANUTILS_LELYCANOPEN_CANFD -# define LELY_NO_CANFD 1 -#else -# define LELY_NO_CANFD 0 -#endif - -/* --disable-diag */ - -#ifdef CONFIG_CANUTILS_LELYCANOPEN_DIAG -# define LELY_NO_DIAG 0 -#else -# define LELY_NO_DIAG 1 -#endif - -/* --disable-dcf */ - -#ifdef CONFIG_CANUTILS_LELYCANOPEN_DCF -# define LELY_NO_CO_DCF 0 -#else -# define LELY_NO_CO_DCF 1 -#endif - -/* --disable-obj-default */ - -#ifdef CONFIG_CANUTILS_LELYCANOPEN_OBJDEFAULT -# define LELY_NO_CO_OBJ_DEFAULT 0 -#else -# define LELY_NO_CO_OBJ_DEFAULT 1 -#endif - -/* --disable-obj-file */ - -#ifdef CONFIG_CANUTILS_LELYCANOPEN_OBJFILE -# define LELY_NO_CO_OBJ_FILE 0 -#else -# define LELY_NO_CO_OBJ_FILE 1 -#endif - -/* --disable-obj-limits */ - -#ifdef CONFIG_CANUTILS_LELYCANOPEN_OBJLIMITS -# define LELY_NO_CO_OBJ_LIMITS 0 -#else -# define LELY_NO_CO_OBJ_LIMITS 1 -#endif - -/* --disable-obj-name */ - -#ifdef CONFIG_CANUTILS_LELYCANOPEN_OBJNAME -# define LELY_NO_CO_OBJ_NAME 0 -#else -# define LELY_NO_CO_OBJ_NAME 1 -#endif - -/* --disable-obj-upload */ - -#ifdef CONFIG_CANUTILS_LELYCANOPEN_OBJUPLOAD -# define LELY_NO_CO_OBJ_UPLOAD 0 -#else -# define LELY_NO_CO_OBJ_UPLOAD 1 -#endif - -/* --disable-sdev */ - -#ifdef CONFIG_CANUTILS_LELYCANOPEN_SDEV -# define LELY_NO_CO_SDEV 0 -#else -# define LELY_NO_CO_SDEV 1 -#endif - -/* --disable-csdo */ - -#ifdef CONFIG_CANUTILS_LELYCANOPEN_CSDO -# define LELY_NO_CO_CSDO 0 -#else -# define LELY_NO_CO_CSDO 1 -#endif - -/* --disable-rpdo */ - -#ifdef CONFIG_CANUTILS_LELYCANOPEN_RPDO -# define LELY_NO_CO_RPDO 0 -#else -# define LELY_NO_CO_RPDO 1 -#endif - -/* --disable-tpdo */ - -#ifdef CONFIG_CANUTILS_LELYCANOPEN_TPDO -# define LELY_NO_CO_TPDO 0 -#else -# define LELY_NO_CO_TPDO 1 -#endif - -/* --disable-mpdo */ - -#ifdef CONFIG_CANUTILS_LELYCANOPEN_MPDO -# define LELY_NO_CO_MPDO 0 -#else -# define LELY_NO_CO_MPDO 1 -#endif - -/* --disable-sync */ - -#ifdef CONFIG_CANUTILS_LELYCANOPEN_SYNC -# define LELY_NO_CO_SYNC 0 -#else -# define LELY_NO_CO_SYNC 1 -#endif - -/* --disable-time */ - -#ifdef CONFIG_CANUTILS_LELYCANOPEN_TIME -# define LELY_NO_CO_TIME 0 -#else -# define LELY_NO_CO_TIME 1 -#endif - -/* --disable-emcy */ - -#ifdef CONFIG_CANUTILS_LELYCANOPEN_EMCY -# define LELY_NO_CO_EMCY 0 -#else -# define LELY_NO_CO_EMCY 1 -#endif - -/* --disable-lss */ - -#ifdef CONFIG_CANUTILS_LELYCANOPEN_LSS -# define LELY_NO_CO_LSS 0 -#else -# define LELY_NO_CO_LSS 1 -#endif - -/* --disable-wtm */ - -#ifdef CONFIG_CANUTILS_LELYCANOPEN_WTM -# define LELY_NO_CO_WTM 0 -#else -# define LELY_NO_CO_WTM 1 -#endif - -/* --disable-master */ - -#ifdef CONFIG_CANUTILS_LELYCANOPEN_MASTER -# define LELY_NO_CO_MASTER 0 -#else -# define LELY_NO_CO_MASTER 1 -#endif - -/* --disable-ng */ - -#ifdef CONFIG_CANUTILS_LELYCANOPEN_NG -# define LELY_NO_CO_NG 0 -#else -# define LELY_NO_CO_NG 1 -#endif - -/* --disable-nmt-boot */ - -#ifdef CONFIG_CANUTILS_LELYCANOPEN_NMTBOOT -# define LELY_NO_CO_NMT_BOOT 0 -#else -# define LELY_NO_CO_NMT_BOOT 1 -#endif - -/* --disable-nmt-cfg */ - -#ifdef CONFIG_CANUTILS_LELYCANOPEN_NMTCFG -# define LELY_NO_CO_NMT_CFG 0 -#else -# define LELY_NO_CO_NMT_CFG 1 -#endif - -/* --disable-gw */ - -#ifdef CONFIG_CANUTILS_LELYCANOPEN_GW -# define LELY_NO_CO_GW 0 -#else -# define LELY_NO_CO_GW 1 -#endif - -/* --disable-gw-txt */ - -#ifdef CONFIG_CANUTILS_LELYCANOPEN_GW_TXT -# define LELY_NO_CO_GW_TXT 0 -#else -# define LELY_NO_CO_GW_TXT 1 -#endif - -/* --disable-coapp-master */ - -#ifdef CONFIG_CANUTILS_LELYCANOPEN_COAPP_MASTER -# define LELY_NO_CO_COAPP_MASTER 0 -#else -# define LELY_NO_CO_COAPP_MASTER 1 -#endif - -/* --disable-coapp-slave */ - -#ifdef CONFIG_CANUTILS_LELYCANOPEN_COAPP_SLAVE -# define LELY_NO_CO_COAPP_SLAVE 0 -#else -# define LELY_NO_CO_COAPP_SLAVE 1 -#endif - -#endif /* __APPS_INCLUDE_CANUTILS_LELY_CONFIG_H */ diff --git a/include/canutils/obd.h b/include/canutils/obd.h index c49b2a152..6d9b294d8 100644 --- a/include/canutils/obd.h +++ b/include/canutils/obd.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/canutils/obd.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -96,13 +94,13 @@ int obd_send_request(FAR struct obd_dev_s *dev, uint8_t opmode, uint8_t pid); * Wait for a message from ECUs with requested PID that was sent using * obd_send_request(). * - * It will return an error case it doesn't receive the msg after the - * elapsed "timeout" time. + * It will return an error case it doesn't receive the msg after the elapsed + * "timeout" time. * ****************************************************************************/ -int obd_wait_response(FAR struct obd_dev_s *dev, uint8_t opmode, - uint8_t pid, int timeout); +int obd_wait_response(FAR struct obd_dev_s *dev, uint8_t opmode, uint8_t pid, + int timeout); /**************************************************************************** * Name: obd_decode_pid @@ -116,4 +114,4 @@ int obd_wait_response(FAR struct obd_dev_s *dev, uint8_t opmode, FAR char *obd_decode_pid(FAR struct obd_dev_s *dev, uint8_t pid); -#endif /* __APPS_INCLUDE_CANUTILS_OBD_H */ +#endif /*__APPS_INCLUDE_CANUTILS_OBD_H */ diff --git a/include/canutils/obd_frame.h b/include/canutils/obd_frame.h index 0d54a50b7..6e06b6bc3 100644 --- a/include/canutils/obd_frame.h +++ b/include/canutils/obd_frame.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/canutils/obd_frame.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/canutils/obd_pid.h b/include/canutils/obd_pid.h index dfd46c0bf..2a0095111 100644 --- a/include/canutils/obd_pid.h +++ b/include/canutils/obd_pid.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/canutils/obd_pid.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/crypto/controlse/ccertificate.hxx b/include/crypto/controlse/ccertificate.hxx deleted file mode 100644 index 332fd0303..000000000 --- a/include/crypto/controlse/ccertificate.hxx +++ /dev/null @@ -1,123 +0,0 @@ -//*************************************************************************** -// apps/include/crypto/controlse/ccertificate.hxx -// -// SPDX-License-Identifier: Apache-2.0 -// SPDX-FileCopyrightText: 2024 NXP -// -// Licensed to the Apache Software Foundation (ASF) under one or more -// contributor license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright ownership. The -// ASF licenses this file to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance with the -// License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -// License for the specific language governing permissions and limitations -// under the License. -// -//*************************************************************************** - -#pragma once - -//*************************************************************************** -// Included Files -//*************************************************************************** - -#include "crypto/controlse/isecure_element_object.hxx" -#include - -//*************************************************************************** -// Class definitions -//*************************************************************************** - -namespace Controlse -{ -class ISecureElement; -class CPublicKey; -class CSerialNumber; - -class CCertificate : public ISecureElementObject -{ -public: - CCertificate(const ISecureElement &se, uint32_t keystore_id); - CCertificate(const uint8_t *crt_der_or_pem, size_t crt_size); - CCertificate(const ISecureElement &se, const uint8_t *csr_der_or_pem, - size_t csr_size, uint32_t keystore_id); - - // from_datetime and to_datetime need to have format: YYYYMMDDHHMMSSZ - CCertificate(const ISecureElement &se, const uint8_t *csr_der_or_pem, - size_t csr_size, uint32_t keystore_id, - const char *from_datetime, const char *to_datetime); - CCertificate(const CCertificate &) = delete; - CCertificate(CCertificate &&) = default; - ~CCertificate(); - - CCertificate &operator=(const CCertificate &other) = delete; - - bool IsLoaded() const; - bool StoreOnSecureElement(const ISecureElement &se, - uint32_t keystore_id) const; - bool LoadFromSecureElement(const ISecureElement &se, uint32_t keystore_id); - bool LoadFromDerOrPem(const uint8_t *crt_der_or_pem, size_t crt_size); - bool LoadFromCsrDerOrPem(const ISecureElement &se, - const uint8_t *csr_der_or_pem, size_t csr_size, - uint32_t keystore_id, const char *from_datetime, - const char *to_datetime); - - bool VerifyAgainst(const ISecureElement &se, - uint32_t verify_against_id) const; - - // Test time range is valid - // returns 0 if valid - // -1 when expired - // 1 when not yet valid - int TestValidTimerange(time_t now) const; - - // Get public key from certificate - // returns pointer to public key when successful otherwise NULL - // note: must be deleted by caller when not NULL - CPublicKey *GetPublicKey() const; - - // Get oid from certificate if available - // oid must be one of MBEDTLS_OID_AT* from mbedtls/oid.h - // - // returns zero terminated text string when successful otherwise NULL - // note: must be deleted by caller when not NULL - char *GetOid(const char *oid) const; - - // Get serial number from from certificate - // returns pointer to CSerialNumber when successful otherwise NULL - // note: must be deleted by caller when not NULL - CSerialNumber *GetSerialNumber() const; - - size_t GetNumberOfSubjectAlternativeNames() const; - - // Get SAN from from certificate - // returns pointer to array when successful otherwise NULL - // note: must be deleted by caller when not NULL - char *GetSubjectAlternativeName(int item) const; - - // Get certificate in DER format - // returns size of the der array otherwise 0 - // note: der must be deleted by caller when not NULL - size_t GetDer(uint8_t **der) const; - - // Get certificate in PEM format - // returns pointer to pem string when successful otherwise NULL - // note: must be deleted by caller when not NULL - char *GetPem() const; - - bool ContainsSan(const char *name, size_t size) const; - - static constexpr char TAG_ID_SIZE = 18; - -private: - bool is_loaded = false; - - mbedtls_x509_crt crt; -}; -} // namespace Controlse diff --git a/include/crypto/controlse/ccsr.hxx b/include/crypto/controlse/ccsr.hxx deleted file mode 100644 index fd3eb38bd..000000000 --- a/include/crypto/controlse/ccsr.hxx +++ /dev/null @@ -1,93 +0,0 @@ -//*************************************************************************** -// apps/include/crypto/controlse/ccsr.hxx -// -// SPDX-License-Identifier: Apache-2.0 -// SPDX-FileCopyrightText: 2024 NXP -// -// Licensed to the Apache Software Foundation (ASF) under one or more -// contributor license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright ownership. The -// ASF licenses this file to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance with the -// License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -// License for the specific language governing permissions and limitations -// under the License. -// -//************************************************************************** - -#pragma once - -//*************************************************************************** -// Included Files -//*************************************************************************** - -#include "crypto/controlse/isecure_element_object.hxx" -#include "mbedtls/x509_csr.h" - -namespace Controlse -{ - -//*************************************************************************** -// Class definitions -//*************************************************************************** - -class CCsr : public ISecureElementObject -{ -public: - class CsrBuilder; - class CsrBuilder - { - public: - CsrBuilder(ISecureElement &se, const char *subject, uint32_t key_slot_id); - CsrBuilder(const CsrBuilder &) = delete; - CsrBuilder(CsrBuilder &&) = default; - - CsrBuilder &operator=(const CsrBuilder &other) = delete; - - CsrBuilder *AddExtension(const char *oid, size_t oid_size, - const uint8_t *value, size_t value_size); - - // result: pointer to dynamically allocated Csr (to be deleted) or nullptr - // if error - CCsr *Build(); - - private: - mbedtls_x509write_csr csr_w; - mbedtls_pk_context key; - bool ready; - }; - - CCsr(const ISecureElement &se, uint32_t keystore_id); - CCsr(const uint8_t *der_or_pem, size_t size); - CCsr(const CCsr &) = delete; - CCsr(CCsr &&) = default; - ~CCsr(); - - CCsr &operator=(const CCsr &other) = delete; - - bool IsLoaded() const; - bool StoreOnSecureElement(const ISecureElement &se, - uint32_t keystore_id) const; - bool LoadFromSecureElement(const ISecureElement &se, uint32_t keystore_id); - - // Get CSR in DER format - // returns size of the der array otherwise 0 - // note: der must be deleted by caller when not NULL - size_t GetDer(uint8_t **der) const; - - // Get certificate in PEM format - // returns pointer to pem string when successful otherwise NULL - // note: must be deleted by caller when not NULL - char *GetPem() const; - -private: - mbedtls_x509_csr csr; - bool is_loaded = false; -}; -} // namespace Controlse diff --git a/include/crypto/controlse/chex_util.hxx b/include/crypto/controlse/chex_util.hxx deleted file mode 100644 index c40f23227..000000000 --- a/include/crypto/controlse/chex_util.hxx +++ /dev/null @@ -1,63 +0,0 @@ -//*************************************************************************** -// apps/include/crypto/controlse/chex_util.hxx -// -// SPDX-License-Identifier: Apache-2.0 -// SPDX-FileCopyrightText: 2024 NXP -// -// Licensed to the Apache Software Foundation (ASF) under one or more -// contributor license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright ownership. The -// ASF licenses this file to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance with the -// License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -// License for the specific language governing permissions and limitations -// under the License. -// -//************************************************************************** - -#pragma once - -//*************************************************************************** -// Included Files -//*************************************************************************** - -#include -#include - -namespace Controlse -{ - -//*************************************************************************** -// Class definitions -//*************************************************************************** - -class CHexUtil -{ -public: - static size_t GetByteArraySizeFromHexString(const char *hex_buffer); - static size_t GetByteArraySizeFromHexStringSize(size_t hex_buffer_size); - static size_t GetHexStringSizeFromByteArraySize(size_t byte_array_size); - - // result contains allocated pointer to byte array (delete[] afterwards) if - // successfull otherwise nullptr - static uint8_t *ConvertHexStringToByteArray(const char *hex_buffer); - - // result contains allocated pointer to byte array (delete[] afterwards) if - // successfull otherwise nullptr - static uint8_t *ConvertHexStringToByteArray(const char *hex_buffer, - size_t hex_buffer_size); - - // result contains allocated pointer to hex string (delete[] afterwards) if - // successfull otherwise nullptr - static char *ByteArrayToHexString(const uint8_t bytearray[], size_t size); - -private: - static constexpr size_t AMOUNT_OF_HEXDIGITS_PER_BYTE = 2; -}; -} // namespace Controlse diff --git a/include/crypto/controlse/cpublic_key.hxx b/include/crypto/controlse/cpublic_key.hxx deleted file mode 100644 index c0678b274..000000000 --- a/include/crypto/controlse/cpublic_key.hxx +++ /dev/null @@ -1,83 +0,0 @@ -//*************************************************************************** -// apps/include/crypto/controlse/cpublic_key.hxx -// -// SPDX-License-Identifier: Apache-2.0 -// SPDX-FileCopyrightText: 2024 NXP -// -// Licensed to the Apache Software Foundation (ASF) under one or more -// contributor license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright ownership. The -// ASF licenses this file to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance with the -// License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -// License for the specific language governing permissions and limitations -// under the License. -// -//************************************************************************** - -#pragma once - -//*************************************************************************** -// Included Files -//*************************************************************************** - -#include "crypto/controlse/isecure_element_object.hxx" -#include - -struct mbedtls_x509_crt; - -namespace Controlse -{ - -//*************************************************************************** -// Class definitions -//*************************************************************************** - -class ISecureElement; - -class CPublicKey : public ISecureElementObject -{ -public: - CPublicKey(const ISecureElement &se, uint32_t keystore_id); - CPublicKey(const uint8_t *buffer, size_t buffer_size); - CPublicKey(const char *pem); - CPublicKey(const CPublicKey &p1); - ~CPublicKey(); - - CPublicKey &operator=(const CPublicKey &other); - - bool IsLoaded() const; - bool StoreOnSecureElement(const ISecureElement &se, - uint32_t keystore_id) const; - bool LoadFromSecureElement(const ISecureElement &se, uint32_t keystore_id); - bool operator==(const CPublicKey &a) const; - bool operator!=(const CPublicKey &a) const; - - size_t GetRawSize() const; - void GetRaw(uint8_t *raw_buffer) const; - - // Get public key in PEM format - // returns pointer to pem string when successful otherwise NULL - // note: must be deleted by caller when not NULL - char *GetPem() const; - -private: - void Unload(); - static int convert_public_key_raw_to_pem(char *pem_buf, size_t pem_buf_size, - const uint8_t *key_buf, - size_t key_buf_size); - static int convert_public_key_pem_to_raw(uint8_t *key_buf, - size_t key_buf_size, - size_t *key_size, - const char *pem_buf); - - uint8_t *m_key = nullptr; - size_t m_size = 0; -}; -} // namespace Controlse diff --git a/include/crypto/controlse/csan_builder.hxx b/include/crypto/controlse/csan_builder.hxx deleted file mode 100644 index b6b05cd03..000000000 --- a/include/crypto/controlse/csan_builder.hxx +++ /dev/null @@ -1,70 +0,0 @@ -//*************************************************************************** -// apps/include/crypto/controlse/csan_builder.hxx -// -// SPDX-License-Identifier: Apache-2.0 -// SPDX-FileCopyrightText: 2024 NXP -// -// Licensed to the Apache Software Foundation (ASF) under one or more -// contributor license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright ownership. The -// ASF licenses this file to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance with the -// License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -// License for the specific language governing permissions and limitations -// under the License. -// -//************************************************************************** - -#pragma once - -//*************************************************************************** -// Included Files -//*************************************************************************** - -#include -#include - -namespace Controlse -{ - -//*************************************************************************** -// Class definitions -//*************************************************************************** - -class CSanBuilder; -class CSanBuilder -{ -public: - CSanBuilder() = default; - CSanBuilder(const CSanBuilder &) = delete; - CSanBuilder(CSanBuilder &&) = default; - ~CSanBuilder(); - - CSanBuilder &operator=(const CSanBuilder &other) = delete; - - CSanBuilder *AddSan(uint8_t type, const char *value, size_t value_size); - - // result: pointer to dynamically allocated san (to be deleted with delete[]) - // or error when size == 0 - size_t Build(uint8_t **san); - - uint32_t GetNumberOfSan(); - -private: - struct List - { - char *p; - size_t size; - uint8_t type; - List *next; - }; - size_t total_size = 0; - List *entry = nullptr; -}; -} // namespace Controlse diff --git a/include/crypto/controlse/csecure_element.hxx b/include/crypto/controlse/csecure_element.hxx deleted file mode 100644 index 5632b3ca2..000000000 --- a/include/crypto/controlse/csecure_element.hxx +++ /dev/null @@ -1,74 +0,0 @@ -//*************************************************************************** -// apps/include/crypto/controlse/csecure_element.hxx -// -// SPDX-License-Identifier: Apache-2.0 -// SPDX-FileCopyrightText: 2024 NXP -// -// Licensed to the Apache Software Foundation (ASF) under one or more -// contributor license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright ownership. The -// ASF licenses this file to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance with the -// License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -// License for the specific language governing permissions and limitations -// under the License. -// -//************************************************************************** - -#pragma once - -//*************************************************************************** -// Included Files -//*************************************************************************** - -#include "crypto/controlse/isecure_element.hxx" - -namespace Controlse -{ - -//*************************************************************************** -// Class definitions -//*************************************************************************** - -class CCertificate; -class CertificateCatalog; -class CPublicKey; - -class CSecureElement : public ISecureElement -{ -public: - explicit CSecureElement(const char *se05x_device); - explicit CSecureElement(int fd); - CSecureElement(const CSecureElement &) = delete; - CSecureElement(CSecureElement &&) = default; - ~CSecureElement(); - - CSecureElement &operator=(const CSecureElement &other) = delete; - - bool IsReady() const; - bool GenerateKey(struct se05x_generate_keypair_s &args) const; - bool SetKey(struct se05x_key_transmission_s &args) const; - bool GetKey(struct se05x_key_transmission_s &args) const; - bool DeleteKey(uint32_t id) const; - bool SetData(struct se05x_key_transmission_s &args) const; - bool GetData(struct se05x_key_transmission_s &args) const; - bool CreateSignature(struct se05x_signature_s &args) const; - bool Verify(struct se05x_signature_s &args) const; - bool DeriveSymmetricalKey(struct se05x_derive_key_s &args) const; - bool GetUid(struct se05x_uid_s &args) const; - bool GetInfo(struct se05x_info_s &args) const; - - CCertificate *GetCertificate(uint32_t keystore_id); - CPublicKey *GetPublicKey(uint32_t keystore_id); - -private: - const int se05x_fd; - const bool close_device_at_destructor; -}; -} // namespace Controlse diff --git a/include/crypto/controlse/cserial_number.hxx b/include/crypto/controlse/cserial_number.hxx deleted file mode 100644 index 0cdeb459e..000000000 --- a/include/crypto/controlse/cserial_number.hxx +++ /dev/null @@ -1,63 +0,0 @@ -//*************************************************************************** -// apps/include/crypto/controlse/cserial_number.hxx -// -// SPDX-License-Identifier: Apache-2.0 -// SPDX-FileCopyrightText: 2024 NXP -// -// Licensed to the Apache Software Foundation (ASF) under one or more -// contributor license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright ownership. The -// ASF licenses this file to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance with the -// License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -// License for the specific language governing permissions and limitations -// under the License. -// -//************************************************************************** - -#pragma once - -//*************************************************************************** -// Included Files -//*************************************************************************** - -#include "crypto/controlse/isecure_element_object.hxx" -#include - -namespace Controlse -{ - -//*************************************************************************** -// Class definitions -//*************************************************************************** - -class CSerialNumber : ISecureElementObject -{ -public: - static constexpr size_t SERIAL_NUMBER_SIZE = 20; - CSerialNumber(const ISecureElement &se, uint32_t keystore_id); - CSerialNumber(uint8_t const *serial_number_byte_array); - - bool operator==(CSerialNumber &a) const; - bool operator!=(CSerialNumber &a) const; - bool operator<(const CSerialNumber &a) const; - - bool IsLoaded() const; - bool StoreOnSecureElement(const ISecureElement &se, - uint32_t keystore_id) const; - bool LoadFromSecureElement(const ISecureElement &se, uint32_t keystore_id); - - bool - GetSerialNumber(uint8_t serial_number_destination[SERIAL_NUMBER_SIZE]) const; - -private: - bool is_loaded = false; - uint8_t serial_number[SERIAL_NUMBER_SIZE]; -}; -} // namespace Controlse diff --git a/include/crypto/controlse/cstring.hxx b/include/crypto/controlse/cstring.hxx deleted file mode 100644 index 7ae868cb3..000000000 --- a/include/crypto/controlse/cstring.hxx +++ /dev/null @@ -1,65 +0,0 @@ -//*************************************************************************** -// apps/include/crypto/controlse/cstring.hxx -// -// SPDX-License-Identifier: Apache-2.0 -// SPDX-FileCopyrightText: 2024 NXP -// -// Licensed to the Apache Software Foundation (ASF) under one or more -// contributor license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright ownership. The -// ASF licenses this file to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance with the -// License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -// License for the specific language governing permissions and limitations -// under the License. -// -//************************************************************************** - -#pragma once - -//*************************************************************************** -// Included Files -//*************************************************************************** - -#include "crypto/controlse/isecure_element_object.hxx" -#include - -namespace Controlse -{ - -//*************************************************************************** -// Class definitions -//*************************************************************************** - -class CString : public ISecureElementObject -{ -public: - CString(const ISecureElement &se, uint32_t keystore_id); - CString(char *string, size_t size); - CString(const CString &p1); - ~CString(); - - CString &operator=(const CString &other); - bool operator==(CString &a) const; - bool operator!=(CString &a) const; - - // return value is string otherwise nullptr - // NOTE: need to delete[] return value - char *c_str(void) const; - - bool IsLoaded() const; - bool StoreOnSecureElement(const ISecureElement &se, - uint32_t keystore_id) const; - bool LoadFromSecureElement(const ISecureElement &se, uint32_t keystore_id); - -private: - size_t m_size = 0; - char *m_string = nullptr; -}; -} // namespace Controlse diff --git a/include/crypto/controlse/isecure_element.hxx b/include/crypto/controlse/isecure_element.hxx deleted file mode 100644 index dc957bdf4..000000000 --- a/include/crypto/controlse/isecure_element.hxx +++ /dev/null @@ -1,72 +0,0 @@ -//*************************************************************************** -// apps/include/crypto/controlse/isecure_element.hxx -// -// SPDX-License-Identifier: Apache-2.0 -// SPDX-FileCopyrightText: 2024 NXP -// -// Licensed to the Apache Software Foundation (ASF) under one or more -// contributor license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright ownership. The -// ASF licenses this file to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance with the -// License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -// License for the specific language governing permissions and limitations -// under the License. -// -//************************************************************************** - -//*************************************************************************** -// Included Files -//*************************************************************************** - -#pragma once - -#include "crypto/controlse/isecure_element_object.hxx" -#include -#include - -struct se05x_key_transmission_s; -struct se05x_signature_s; -struct se05x_uid_s; -struct se05x_info_s; -struct se05x_generate_keypair_s; -struct se05x_derive_key_s; - -namespace Controlse -{ - -//*************************************************************************** -// Class definitions -//*************************************************************************** - -class ISecureElement -{ -public: - virtual ~ISecureElement() = default; - - virtual bool IsReady() const = 0; - virtual bool GenerateKey(struct se05x_generate_keypair_s &args) const = 0; - virtual bool SetKey(struct se05x_key_transmission_s &args) const = 0; - virtual bool GetKey(struct se05x_key_transmission_s &args) const = 0; - virtual bool DeleteKey(uint32_t id) const = 0; - virtual bool SetData(struct se05x_key_transmission_s &args) const = 0; - virtual bool GetData(struct se05x_key_transmission_s &args) const = 0; - virtual bool CreateSignature(struct se05x_signature_s &args) const = 0; - virtual bool Verify(struct se05x_signature_s &args) const = 0; - virtual bool DeriveSymmetricalKey(struct se05x_derive_key_s &args) const = 0; - virtual bool GetUid(struct se05x_uid_s &args) const = 0; - virtual bool GetInfo(struct se05x_info_s &args) const = 0; - - virtual bool Set(uint32_t keystore_id, - const ISecureElementObject &object) const - { - return object.StoreOnSecureElement(*this, keystore_id); - } -}; -} // namespace Controlse diff --git a/include/crypto/controlse/isecure_element_object.hxx b/include/crypto/controlse/isecure_element_object.hxx deleted file mode 100644 index f73a262ff..000000000 --- a/include/crypto/controlse/isecure_element_object.hxx +++ /dev/null @@ -1,52 +0,0 @@ -//*************************************************************************** -// apps/include/crypto/controlse/isecure_element_object.hxx -// -// SPDX-License-Identifier: Apache-2.0 -// SPDX-FileCopyrightText: 2024 NXP -// -// Licensed to the Apache Software Foundation (ASF) under one or more -// contributor license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright ownership. The -// ASF licenses this file to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance with the -// License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -// License for the specific language governing permissions and limitations -// under the License. -// -//************************************************************************** - -#pragma once - -//*************************************************************************** -// Included Files -//*************************************************************************** - -#include - -namespace Controlse -{ - -//*************************************************************************** -// Class definitions -//*************************************************************************** - -class ISecureElement; - -class ISecureElementObject -{ -public: - virtual ~ISecureElementObject() = default; - virtual bool IsLoaded() const = 0; - virtual bool StoreOnSecureElement(const ISecureElement &se, - uint32_t keystore_id) const = 0; - virtual bool LoadFromSecureElement(const ISecureElement &se, - uint32_t keystore_id) - = 0; -}; -} // namespace Controlse diff --git a/testing/testsuites/kernel/mutex/include/MutexTest.h b/include/crypto/mbedtls_config.h similarity index 54% rename from testing/testsuites/kernel/mutex/include/MutexTest.h rename to include/crypto/mbedtls_config.h index 44e9dbb0b..46d51cdff 100644 --- a/testing/testsuites/kernel/mutex/include/MutexTest.h +++ b/include/crypto/mbedtls_config.h @@ -1,7 +1,5 @@ /**************************************************************************** - * apps/testing/testsuites/kernel/mutex/include/MutexTest.h - * - * SPDX-License-Identifier: Apache-2.0 + * apps/include/crypto/mbedtls_config.h * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -20,50 +18,65 @@ * ****************************************************************************/ -#ifndef PTHREAD_TEST_H -#define PTHREAD_TEST_H +#ifndef __APPS_INCLUDE_CRYPTO_MBEDTLS_CONFIG_H +#define __APPS_INCLUDE_CRYPTO_MBEDTLS_CONFIG_H /**************************************************************************** * Included Files ****************************************************************************/ + #include -#include -#include -#include -#include -#include -#include -#include -#include -#include "sched.h" -#include "semaphore.h" -#include "unistd.h" /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ -#define MUTEX_TEST_NUM 100 -#define ENOERR 0 -typedef unsigned int UINT32; -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ +/* System support */ +#define MBEDTLS_HAVE_TIME -/* test case function */ +/* Debug */ +#define MBEDTLS_SELF_TEST +#define MBEDTLS_TIMING_C -/* cases/posix_mutex_test_001.c - * ************************************************/ +/* Feature support */ +#define MBEDTLS_CIPHER_MODE_CBC +#define MBEDTLS_PKCS1_V15 +#define MBEDTLS_KEY_EXCHANGE_RSA_ENABLED +#define MBEDTLS_SSL_PROTO_TLS1_2 -void test_nuttx_mutex_test01(FAR void **state); +/* Modules */ +#define MBEDTLS_AES_C +#define MBEDTLS_ASN1_PARSE_C +#define MBEDTLS_ASN1_WRITE_C +#define MBEDTLS_BIGNUM_C +#define MBEDTLS_CIPHER_C +#define MBEDTLS_CTR_DRBG_C +#define MBEDTLS_DES_C +#define MBEDTLS_ENTROPY_C +#define MBEDTLS_MD_C +#define MBEDTLS_MD5_C -/* cases/posix_mutex_test_019.c - * ************************************************/ - -void test_nuttx_mutex_test19(FAR void **state); - -/* cases/posix_mutex_test_020.c - * ************************************************/ - -void test_nuttx_mutex_test20(FAR void **state); +#ifdef CONFIG_NET +#define MBEDTLS_NET_C #endif + +#define MBEDTLS_OID_C +#define MBEDTLS_PK_C +#define MBEDTLS_PK_PARSE_C +#define MBEDTLS_RSA_C +#define MBEDTLS_SHA1_C +#define MBEDTLS_SHA224_C +#define MBEDTLS_SHA256_C +#define MBEDTLS_SSL_CLI_C +#define MBEDTLS_SSL_SRV_C +#define MBEDTLS_SSL_TLS_C +#define MBEDTLS_X509_CRT_PARSE_C +#define MBEDTLS_X509_USE_C + +#define MBEDTLS_BASE64_C +#define MBEDTLS_CERTS_C +#define MBEDTLS_PEM_PARSE_C + +#define MBEDTLS_FS_IO + +#endif /* __APPS_INCLUDE_CRYPTO_MBEDTLS_CONFIG_H */ diff --git a/include/fsutils/flash_eraseall.h b/include/fsutils/flash_eraseall.h index d3fb47c73..d02baaef7 100644 --- a/include/fsutils/flash_eraseall.h +++ b/include/fsutils/flash_eraseall.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/fsutils/flash_eraseall.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/fsutils/inifile.h b/include/fsutils/inifile.h index ad9a7ffdf..d943887fc 100644 --- a/include/fsutils/inifile.h +++ b/include/fsutils/inifile.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/fsutils/inifile.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/fsutils/ipcfg.h b/include/fsutils/ipcfg.h index a2aa11531..344b240ae 100644 --- a/include/fsutils/ipcfg.h +++ b/include/fsutils/ipcfg.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/fsutils/ipcfg.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/fsutils/mkfatfs.h b/include/fsutils/mkfatfs.h index f2bc4ff9e..09334b9e6 100644 --- a/include/fsutils/mkfatfs.h +++ b/include/fsutils/mkfatfs.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/fsutils/mkfatfs.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/fsutils/mksmartfs.h b/include/fsutils/mksmartfs.h index 38c6dea64..4929598b4 100644 --- a/include/fsutils/mksmartfs.h +++ b/include/fsutils/mksmartfs.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/fsutils/mksmartfs.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/fsutils/passwd.h b/include/fsutils/passwd.h index 93fed255d..b8eac9fb4 100644 --- a/include/fsutils/passwd.h +++ b/include/fsutils/passwd.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/fsutils/passwd.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -36,9 +34,9 @@ /* passwd_verify() return value tests */ -#define PASSWORD_VERIFY_MATCH(ret) ((ret) == 0) -#define PASSWORD_VERIFY_NOMATCH(ret) ((ret) == -1) -#define PASSWORD_VERIFY_ERROR(ret) ((ret) < -1) +#define PASSWORD_VERIFY_MATCH(ret) (ret == 1) +#define PASSWORD_VERIFY_NOMATCH(ret) (ret == 0) +#define PASSWORD_VERIFY_ERROR(ret) (ret < 0) /**************************************************************************** * Public Function Prototypes @@ -61,7 +59,7 @@ * ****************************************************************************/ -#if !defined(CONFIG_FSUTILS_PASSWD_READONLY) +#if defined(CONFIG_FSUTILS_PASSWD_READONLY) int passwd_adduser(FAR const char *username, FAR const char *password); /**************************************************************************** @@ -115,8 +113,9 @@ int passwd_update(FAR const char *username, FAR const char *password); * password - The password to be verified * * Returned Value: - * Zero (0) is returned on a successful match, -1 on mismatch or invalid - * hash format; a negated errno value is returned on other failures. + * One (1) is returned on success match, Zero (OK) is returned on an + * unsuccessful match; a negated errno value is returned on any other + * failure. * ****************************************************************************/ diff --git a/include/gpsutils/minmea.h b/include/gpsutils/minmea.h new file mode 100644 index 000000000..c3b8e533f --- /dev/null +++ b/include/gpsutils/minmea.h @@ -0,0 +1,309 @@ +/**************************************************************************** + * apps/include/gpsutils/minmea.h + * + * Copyright ยฉ 2014 Kosma Moczek + * + * Released under the NuttX BSD license with permission from the author: + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __APPS_INCLUDE_GPSUTILS_MINMEA_H +#define __APPS_INCLUDE_GPSUTILS_MINMEA_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include +#include +#include +#include +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define MINMEA_MAX_LENGTH 80 + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +enum minmea_sentence_id +{ + MINMEA_INVALID = -1, + MINMEA_UNKNOWN = 0, + MINMEA_SENTENCE_RMC, + MINMEA_SENTENCE_GGA, + MINMEA_SENTENCE_GSA, + MINMEA_SENTENCE_GLL, + MINMEA_SENTENCE_GST, + MINMEA_SENTENCE_GSV, +}; + +struct minmea_float +{ + int_least32_t value; + int_least32_t scale; +}; + +struct minmea_date +{ + int day; + int month; + int year; +}; + +struct minmea_time +{ + int hours; + int minutes; + int seconds; + int microseconds; +}; + +struct minmea_sentence_rmc +{ + struct minmea_time time; + bool valid; + struct minmea_float latitude; + struct minmea_float longitude; + struct minmea_float speed; + struct minmea_float course; + struct minmea_date date; + struct minmea_float variation; +}; + +struct minmea_sentence_gga +{ + struct minmea_time time; + struct minmea_float latitude; + struct minmea_float longitude; + int fix_quality; + int satellites_tracked; + struct minmea_float hdop; + struct minmea_float altitude; + char altitude_units; + struct minmea_float height; + char height_units; + int dgps_age; +}; + +enum minmea_gll_status +{ + MINMEA_GLL_STATUS_DATA_VALID = 'A', + MINMEA_GLL_STATUS_DATA_NOT_VALID = 'V', +}; + +enum minmea_gll_mode +{ + MINMEA_GLL_MODE_AUTONOMOUS = 'A', + MINMEA_GLL_MODE_DPGS = 'D', + MINMEA_GLL_MODE_DR = 'E', +}; + +struct minmea_sentence_gll +{ + struct minmea_float latitude; + struct minmea_float longitude; + struct minmea_time time; + char status; + char mode; +}; + +struct minmea_sentence_gst +{ + struct minmea_time time; + struct minmea_float rms_deviation; + struct minmea_float semi_major_deviation; + struct minmea_float semi_minor_deviation; + struct minmea_float semi_major_orientation; + struct minmea_float latitude_error_deviation; + struct minmea_float longitude_error_deviation; + struct minmea_float altitude_error_deviation; +}; + +enum minmea_gsa_mode +{ + MINMEA_GPGSA_MODE_AUTO = 'A', + MINMEA_GPGSA_MODE_FORCED = 'M', +}; + +enum minmea_gsa_fix_type +{ + MINMEA_GPGSA_FIX_NONE = 1, + MINMEA_GPGSA_FIX_2D = 2, + MINMEA_GPGSA_FIX_3D = 3, +}; + +struct minmea_sentence_gsa +{ + char mode; + int fix_type; + int sats[12]; + struct minmea_float pdop; + struct minmea_float hdop; + struct minmea_float vdop; +}; + +struct minmea_sat_info +{ + int nr; + int elevation; + int azimuth; + int snr; +}; + +struct minmea_sentence_gsv +{ + int total_msgs; + int msg_nr; + int total_sats; + struct minmea_sat_info sats[4]; +}; + +#ifdef __cplusplus +extern "C" +{ +#endif + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/* Calculate raw sentence checksum. Does not check sentence integrity. */ + +uint8_t minmea_checksum(FAR const char *sentence); + +/* Check sentence validity and checksum. Returns true for valid sentences. */ + +bool minmea_check(FAR const char *sentence, bool strict); + +/* Determine talker identifier. */ + +bool minmea_talker_id(char talker[3], FAR const char *sentence); + +/* Determine sentence identifier. */ + +enum minmea_sentence_id minmea_sentence_id(FAR const char *sentence, + bool strict); + +/* Scanf-like processor for NMEA sentences. Supports the following formats: + * c - single character (char *) + * d - direction, returned as 1/-1, default 0 (int *) + * f - fractional, returned as value + scale (int *, int *) + * i - decimal, default zero (int *) + * s - string (char *) + * t - talker identifier and type (char *) + * T - date/time stamp (int *, int *, int *) + * Returns true on success. See library source code for details. + */ + +bool minmea_scan(const char *sentence, const char *format, ...); + +/* Parse a specific type of sentence. Return true on success. */ + +bool minmea_parse_rmc(struct minmea_sentence_rmc *frame, const char *sentence); +bool minmea_parse_gga(struct minmea_sentence_gga *frame, const char *sentence); +bool minmea_parse_gsa(struct minmea_sentence_gsa *frame, const char *sentence); +bool minmea_parse_gll(struct minmea_sentence_gll *frame, const char *sentence); +bool minmea_parse_gst(struct minmea_sentence_gst *frame, const char *sentence); +bool minmea_parse_gsv(struct minmea_sentence_gsv *frame, const char *sentence); + +/* Convert GPS UTC date/time representation to a UNIX timestamp. */ + +int minmea_gettime(FAR struct timespec *ts, + FAR const struct minmea_date *date, + FAR const struct minmea_time *time_); + +/* Rescale a fixed-point value to a different scale. Rounds towards zero. */ + +static inline int_least32_t minmea_rescale(FAR struct minmea_float *f, + int_least32_t new_scale) +{ + if (f->scale == 0) + { + return 0; + } + + if (f->scale == new_scale) + { + return f->value; + } + + if (f->scale > new_scale) + { + return (f->value + ((f->value > 0) - (f->value < 0)) * f->scale / + new_scale / 2) / (f->scale / new_scale); + } + else + { + return f->value * (new_scale / f->scale); + } +} + +/* Convert a fixed-point value to a floating-point value. + * Returns NaN for "unknown" values. + */ + +static inline float minmea_tofloat(FAR struct minmea_float *f) +{ + if (f->scale == 0) + { + return NAN; + } + + return (float) f->value / (float) f->scale; +} + +/* Convert a raw coordinate to a floating point DD.DDD... value. + * Returns NaN for "unknown" values. + */ + +static inline float minmea_tocoord(FAR struct minmea_float *f) +{ + if (f->scale == 0) + { + return NAN; + } + + int_least32_t degrees = f->value / (f->scale * 100); + int_least32_t minutes = f->value % (f->scale * 100); + + return (float) degrees + (float) minutes / (60 * f->scale); +} + +#ifdef __cplusplus +} +#endif + +#endif /* __APPS_INCLUDE_GPSUTILS_MINMEA_H */ diff --git a/include/graphics/curses.h b/include/graphics/curses.h index d66e19ce9..acba716bd 100644 --- a/include/graphics/curses.h +++ b/include/graphics/curses.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/curses.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -47,7 +45,7 @@ #define PDC_RGB 1 #ifdef CONFIG_PDCURSES_WIDE -# include +# include #endif /**************************************************************************** @@ -69,9 +67,9 @@ #endif #ifdef CONFIG_PDCURSES_CHTYPE_LONG -# define PDC_COLOR_PAIRS 256 +# define PDC_COLOR_PAIRS 256 #else -# define PDC_COLOR_PAIRS 32 +# define PDC_COLOR_PAIRS 32 #endif #define BUTTON_RELEASED 0x0000 @@ -91,7 +89,8 @@ #define MOUSE_X_POS (Mouse_status.x) #define MOUSE_Y_POS (Mouse_status.y) -/* Bits associated with the .changes field: +/* + * Bits associated with the .changes field: * 3 2 1 0 * 210987654321098765432109876543210 * 1 <- button 1 has changed @@ -140,9 +139,8 @@ #define BUTTON3_MOVED 0x00004000L /* PDCurses */ /* For the ncurses-compatible functions only, BUTTON4_PRESSED and - * BUTTON5_PRESSED are returned for mouse scroll wheel up and down; - * otherwise PDCurses doesn't support buttons 4 and 5 - */ + BUTTON5_PRESSED are returned for mouse scroll wheel up and down; + otherwise PDCurses doesn't support buttons 4 and 5 */ #define BUTTON4_RELEASED 0x00008000L #define BUTTON4_PRESSED 0x00010000L @@ -165,14 +163,14 @@ #define REPORT_MOUSE_POSITION 0x20000000L #ifdef NCURSES_MOUSE_VERSION -# define BUTTON_SHIFT BUTTON_MODIFIER_SHIFT -# define BUTTON_CONTROL BUTTON_MODIFIER_CONTROL -# define BUTTON_CTRL BUTTON_MODIFIER_CONTROL -# define BUTTON_ALT BUTTON_MODIFIER_ALT +# define BUTTON_SHIFT BUTTON_MODIFIER_SHIFT +# define BUTTON_CONTROL BUTTON_MODIFIER_CONTROL +# define BUTTON_CTRL BUTTON_MODIFIER_CONTROL +# define BUTTON_ALT BUTTON_MODIFIER_ALT #else -# define BUTTON_SHIFT PDC_BUTTON_SHIFT -# define BUTTON_CONTROL PDC_BUTTON_CONTROL -# define BUTTON_ALT PDC_BUTTON_ALT +# define BUTTON_SHIFT PDC_BUTTON_SHIFT +# define BUTTON_CONTROL PDC_BUTTON_CONTROL +# define BUTTON_ALT PDC_BUTTON_ALT #endif /* PDCurses Text Attributes @@ -202,9 +200,9 @@ * * long form: * - * ------------------------------------------------------------------------- - * |31|30|29|28|27|26|25|24|23|22|21|20|19|18|17|16|15|14|13|..| 3| 2| 1| 0| - * ------------------------------------------------------------------------- + * ---------------------------------------------------------------------------- + * |31|30|29|28|27|26|25|24|23|22|21|20|19|18|17|16|15|14|13|12|..| 3| 2| 1| 0| + * ---------------------------------------------------------------------------- * color number | modifiers | character eg 'a' * * The available non-color attributes are bold, underline, invisible, @@ -347,7 +345,8 @@ #define ACS_LANTERN ACS_PICK('i', '*') #define ACS_BLOCK ACS_PICK('0', '#') -/* That goes double for these -- undocumented SysV symbols. Don't use them. */ +/* That goes double for these -- undocumented SysV symbols. Don't use + them. */ #define ACS_S3 ACS_PICK('p', '-') #define ACS_S7 ACS_PICK('r', '-') @@ -800,12 +799,9 @@ typedef unsigned long mmask_t; typedef struct { short id; /* unused, always 0 */ - int x; /* x, y same as MOUSE_STATUS; z unused */ - int y; - int z; + int x, y, z; /* x, y same as MOUSE_STATUS; z unused */ mmask_t bstate; /* equivalent to changes + button[], but - * in the same format as used for mousemask() - */ + * in the same format as used for mousemask() */ } MEVENT; /* PDCurses Structure Definitions */ @@ -834,8 +830,7 @@ typedef struct _win /* definition of a window */ int _tmarg; /* top of scrolling region */ int _bmarg; /* bottom of scrolling region */ int _delayms; /* milliseconds of delay for getch() */ - int _parx; /* coords relative to parent (0,0) */ - int _pary; + int _parx, _pary; /* coords relative to parent (0,0) */ struct _win *_parent; /* subwin's pointer to parent win */ } WINDOW; @@ -863,7 +858,6 @@ typedef struct int orig_cursor; /* original cursor size */ int lines; /* new value for LINES */ int cols; /* new value for COLS */ - unsigned long _trap_mbe; /* trap these mouse button events */ unsigned long _map_mbe_to_key; /* map mouse buttons to slk */ int mouse_wait; /* time to wait (in ms) for a @@ -948,9 +942,9 @@ struct pdc_context_s short COLOR_PAIRS; short TABSIZE; short first_col; - short c_pindex; /* putter index */ - short c_gindex; /* getter index */ - short c_ungind; /* ungetch() push index */ + short c_pindex; /* putter index */ + short c_gindex; /* getter index */ + short c_ungind; /* ungetch() push index */ short c_ungch[NUNGETCH]; /* array of ungotten chars */ short c_buffer[_INBUFSIZ]; /* character buffer */ RIPPEDOFFLINE linesripped[5]; @@ -1032,8 +1026,8 @@ void PDC_ctx_free(void); #define graphic_screen ctx->graphic_screen #endif -void *pdc_alloc_panel_ctx(void); -void *pdc_alloc_term_ctx(void); +void* pdc_alloc_panel_ctx(void); +void* pdc_alloc_term_ctx(void); #else @@ -1078,8 +1072,7 @@ int baudrate(void); int beep(void); int bkgd(chtype); void bkgdset(chtype); -int border(chtype, chtype, chtype, chtype, - chtype, chtype, chtype, chtype); +int border(chtype, chtype, chtype, chtype, chtype, chtype, chtype, chtype); int box(WINDOW *, chtype, chtype); bool can_change_color(void); int cbreak(void); @@ -1167,8 +1160,8 @@ int mvinsch(int, int, chtype); int mvinsnstr(int, int, const char *, int); int mvinsstr(int, int, const char *); int mvinstr(int, int, char *); -int mvprintw(int, int, const char *, ...) printf_like(3, 4); -int mvscanw(int, int, const char *, ...) scanf_like(3, 4); +int mvprintw(int, int, const char *, ...); +int mvscanw(int, int, const char *, ...); int mvvline(int, int, chtype, int); int mvwaddchnstr(WINDOW *, int, int, const chtype *, int); int mvwaddchstr(WINDOW *, int, int, const chtype *); @@ -1190,8 +1183,8 @@ int mvwinsnstr(WINDOW *, int, int, const char *, int); int mvwinsstr(WINDOW *, int, int, const char *); int mvwinstr(WINDOW *, int, int, char *); int mvwin(WINDOW *, int, int); -int mvwprintw(WINDOW *, int, int, const char *, ...) printf_like(4, 5); -int mvwscanw(WINDOW *, int, int, const char *, ...) scanf_like(4, 5); +int mvwprintw(WINDOW *, int, int, const char *, ...); +int mvwscanw(WINDOW *, int, int, const char *, ...); int mvwvline(WINDOW *, int, int, chtype, int); int napms(int); WINDOW *newpad(int, int); @@ -1211,7 +1204,7 @@ int pair_content(short, short *, short *); int pechochar(WINDOW *, chtype); int pnoutrefresh(WINDOW *, int, int, int, int, int, int); int prefresh(WINDOW *, int, int, int, int, int, int); -int printw(const char *, ...) printf_like(1, 2); +int printw(const char *, ...); int putwin(WINDOW *, FILE *); void qiflush(void); int raw(void); @@ -1222,7 +1215,7 @@ int reset_shell_mode(void); int resetty(void); int ripoffline(int, int (*)(WINDOW *, int)); int savetty(void); -int scanw(const char *, ...) scanf_like(1, 2); +int scanw(const char *, ...); int scr_dump(const char *); int scr_init(const char *); int scr_restore(const char *); @@ -1267,10 +1260,10 @@ int vid_attr(attr_t, short, void *); int vidputs(chtype, int (*)(int)); int vid_puts(attr_t, short, void *, int (*)(int)); int vline(chtype, int); -int vw_printw(WINDOW *, const char *, va_list) printf_like(2, 0); -int vwprintw(WINDOW *, const char *, va_list) printf_like(2, 0); -int vw_scanw(WINDOW *, const char *, va_list) scanf_like(2, 0); -int vwscanw(WINDOW *, const char *, va_list) scanf_like(2, 0); +int vw_printw(WINDOW *, const char *, va_list); +int vwprintw(WINDOW *, const char *, va_list); +int vw_scanw(WINDOW *, const char *, va_list); +int vwscanw(WINDOW *, const char *, va_list); int waddchnstr(WINDOW *, const chtype *, int); int waddchstr(WINDOW *, const chtype *); int waddch(WINDOW *, const chtype); @@ -1313,10 +1306,10 @@ int winsstr(WINDOW *, const char *); int winstr(WINDOW *, char *); int wmove(WINDOW *, int, int); int wnoutrefresh(WINDOW *); -int wprintw(WINDOW *, const char *, ...) printf_like(2, 3); +int wprintw(WINDOW *, const char *, ...); int wredrawln(WINDOW *, int, int); int wrefresh(WINDOW *); -int wscanw(WINDOW *, const char *, ...) scanf_like(2, 3); +int wscanw(WINDOW *, const char *, ...); int wscrl(WINDOW *, int); int wsetscrreg(WINDOW *, int, int); int wstandend(WINDOW *); @@ -1393,9 +1386,8 @@ int mvwin_wchnstr(WINDOW *, int, int, cchar_t *, int); int mvwin_wchstr(WINDOW *, int, int, cchar_t *); int mvwinwstr(WINDOW *, int, int, wchar_t *); int mvwvline_set(WINDOW *, int, int, const cchar_t *, int); -int pecho_wchar(WINDOW *, const cchar_t *); -int setcchar(cchar_t *, const wchar_t *, const attr_t, - short, const void *); +int pecho_wchar(WINDOW *, const cchar_t*); +int setcchar(cchar_t*, const wchar_t*, const attr_t, short, const void*); int slk_wset(int, const wchar_t *, int); int unget_wch(const wchar_t); int vline_set(const cchar_t *, int); @@ -1499,7 +1491,7 @@ char wordchar(void); wchar_t *slk_wlabel(int); #endif -void PDC_debug(const char *, ...) printf_like(1, 2); +void PDC_debug(const char *, ...); int PDC_ungetch(int); int PDC_set_blink(bool); int PDC_set_line_color(short); diff --git a/include/graphics/ft80x.h b/include/graphics/ft80x.h index 20da36b44..27b81b240 100644 --- a/include/graphics/ft80x.h +++ b/include/graphics/ft80x.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/ft80x.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/graphics/input_gen.h b/include/graphics/input_gen.h deleted file mode 100644 index b69f4d69a..000000000 --- a/include/graphics/input_gen.h +++ /dev/null @@ -1,304 +0,0 @@ -/**************************************************************************** - * apps/include/graphics/input_gen.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __APPS_INCLUDE_GRAPHICS_INPUT_GEN_H -#define __APPS_INCLUDE_GRAPHICS_INPUT_GEN_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include - -#include -#include - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define INPUT_GEN_DEV_NUM 4 - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -/* Device types */ - -typedef enum -{ - INPUT_GEN_DEV_NONE = 0x00, - INPUT_GEN_DEV_UTOUCH = 0x01, /* Touchscreen */ - INPUT_GEN_DEV_UBUTTON = 0x02, /* Button */ - INPUT_GEN_DEV_UMOUSE = 0x04, /* Mouse */ - INPUT_GEN_DEV_UKEYBOARD = 0x08, /* Keyboard */ - INPUT_GEN_DEV_ALL = INPUT_GEN_DEV_UTOUCH | INPUT_GEN_DEV_UBUTTON | - INPUT_GEN_DEV_UMOUSE | INPUT_GEN_DEV_UKEYBOARD -} input_gen_dev_t; - -/* Input generator context */ - -typedef FAR struct input_gen_ctx_s *input_gen_ctx_t; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -#ifdef __cplusplus -#define EXTERN extern "C" -extern "C" -{ -#else -#define EXTERN extern -#endif - -/**************************************************************************** - * Name: input_gen_create - * - * Description: - * Create an input generator context. - * - * Input Parameters: - * ctx - A pointer to the input generator context, or NULL if the - * context failed to be created. - * devices - Device types to be opened. - * - * Returned Value: - * Success device count. On failure, a negated errno value is returned. - * - ****************************************************************************/ - -int input_gen_create(FAR input_gen_ctx_t *ctx, uint32_t devices); - -/**************************************************************************** - * Name: input_gen_destroy - * - * Description: - * Destroy an input generator context. - * - * Input Parameters: - * ctx - The input generator context to destroy. - * - * Returned Value: - * Zero (OK) is returned on success. On failure, a negated errno value is - * returned. - * - ****************************************************************************/ - -int input_gen_destroy(input_gen_ctx_t ctx); - -/**************************************************************************** - * Name: input_gen_query_device - * - * Description: - * Query whether the device with the specified type is opened. - * - * Input Parameters: - * ctx - The input generator context. - * device - The device type. - * - * Returned Value: - * True if the device is opened, false otherwise. - * - ****************************************************************************/ - -bool input_gen_query_device(input_gen_ctx_t ctx, input_gen_dev_t device); - -/**************************************************************************** - * Name: input_gen_reset_devices - * - * Description: - * Reset the device state with the specified type. - * - * Input Parameters: - * ctx - The input generator context. - * devices - The device types to reset state. - * - * Returned Value: - * Zero (OK) is returned on success. On failure, a negated errno value is - * returned. - * - ****************************************************************************/ - -int input_gen_reset_devices(input_gen_ctx_t ctx, uint32_t devices); - -/**************************************************************************** - * Name: input_gen_tap - * - * Description: - * Perform a tap operation. - * - * Input Parameters: - * ctx - The input generator context. - * x - The x coordinate. - * y - The y coordinate. - * - * Returned Value: - * Zero (OK) is returned on success. On failure, a negated errno value is - * returned. - * - ****************************************************************************/ - -int input_gen_tap(input_gen_ctx_t ctx, int16_t x, int16_t y); - -/**************************************************************************** - * Name: input_gen_drag / input_gen_swipe - * - * Description: - * Perform a drag or swipe operation. - * - * Input Parameters: - * ctx - The input generator context. - * x1 - The start x coordinate. - * y1 - The start y coordinate. - * x2 - The end x coordinate. - * y2 - The end y coordinate. - * duration - The duration of the operation. - * - * Returned Value: - * Zero (OK) is returned on success. On failure, a negated errno value is - * returned. - * - ****************************************************************************/ - -int input_gen_drag(input_gen_ctx_t ctx, int16_t x1, int16_t y1, - int16_t x2, int16_t y2, uint32_t duration); -int input_gen_swipe(input_gen_ctx_t ctx, int16_t x1, int16_t y1, - int16_t x2, int16_t y2, uint32_t duration); - -/**************************************************************************** - * Name: input_gen_pinch - * - * Description: - * Perform a pinch operation. - * - * Input Parameters: - * ctx - The input generator context. - * x1_start - The start x coordinate of the first finger. - * y1_start - The start y coordinate of the first finger. - * x2_start - The start x coordinate of the second finger. - * y2_start - The start y coordinate of the second finger. - * x1_end - The end x coordinate of the first finger. - * y1_end - The end y coordinate of the first finger. - * x2_end - The end x coordinate of the second finger. - * y2_end - The end y coordinate of the second finger. - * duration - The duration of the operation. - * - * Returned Value: - * Zero (OK) is returned on success. On failure, a negated errno value is - * returned. - * - ****************************************************************************/ - -int input_gen_pinch(input_gen_ctx_t ctx, int16_t x1_start, int16_t y1_start, - int16_t x2_start, int16_t y2_start, int16_t x1_end, - int16_t y1_end, int16_t x2_end, int16_t y2_end, - uint32_t duration); - -/**************************************************************************** - * Name: input_gen_button_click / input_gen_button_longpress - * - * Description: - * Perform a button click or long press operation. - * - * Input Parameters: - * ctx - The input generator context. - * mask - The button mask. - * duration - The duration of the operation. - * - * Returned Value: - * Zero (OK) is returned on success. On failure, a negated errno value is - * returned. - * - ****************************************************************************/ - -int input_gen_button_click(input_gen_ctx_t ctx, btn_buttonset_t mask); -int input_gen_button_longpress(input_gen_ctx_t ctx, btn_buttonset_t mask, - uint32_t duration); - -/**************************************************************************** - * Name: input_gen_mouse_wheel - * - * Description: - * Perform a mouse wheel operation. - * - * Input Parameters: - * ctx - The input generator context. - * wheel - The wheel value. - * - * Returned Value: - * Zero (OK) is returned on success. On failure, a negated errno value is - * returned. - * - ****************************************************************************/ - -#ifdef CONFIG_INPUT_MOUSE_WHEEL -int input_gen_mouse_wheel(input_gen_ctx_t ctx, int16_t wheel); -#else -#define input_gen_mouse_wheel(ctx, wheel) (-ENODEV) -#endif - -/**************************************************************************** - * Name: input_gen_fill_point - * - * Description: - * Fill the touch point structure. - * - * Input Parameters: - * point - The touch point structure. - * x - The x coordinate. - * y - The y coordinate. - * flags - The TOUCH_DOWN, TOUCH_MOVE, TOUCH_UP flag. - * - ****************************************************************************/ - -void input_gen_fill_point(FAR struct touch_point_s *point, - int16_t x, int16_t y, uint8_t flags); - -/**************************************************************************** - * Name: input_gen_write_raw - * - * Description: - * Write raw data to the device. - * - * Input Parameters: - * ctx - The input generator context. - * device - The device type. - * buf - The buffer to write. - * nbytes - The number of bytes to write. - * - * Returned Value: - * The number of bytes written, or a negated errno value on failure. - * - ****************************************************************************/ - -ssize_t input_gen_write_raw(input_gen_ctx_t ctx, input_gen_dev_t device, - FAR const void *buf, size_t nbytes); - -#undef EXTERN -#ifdef __cplusplus -} -#endif - -#endif /* __APPS_INCLUDE_GRAPHICS_INPUT_GEN_H */ diff --git a/include/graphics/nxglyphs.hxx b/include/graphics/nxglyphs.hxx index 807817f97..73fcf2f85 100644 --- a/include/graphics/nxglyphs.hxx +++ b/include/graphics/nxglyphs.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwidgets/nxglyphs.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/graphics/nxwidgets/cbgwindow.hxx b/include/graphics/nxwidgets/cbgwindow.hxx index d79d15f65..c0e1e5c21 100644 --- a/include/graphics/nxwidgets/cbgwindow.hxx +++ b/include/graphics/nxwidgets/cbgwindow.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwidgets/cbgwindow.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/graphics/nxwidgets/cbitmap.hxx b/include/graphics/nxwidgets/cbitmap.hxx index 01f5196f7..4d29d4985 100644 --- a/include/graphics/nxwidgets/cbitmap.hxx +++ b/include/graphics/nxwidgets/cbitmap.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwidgets/cbitmap.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/graphics/nxwidgets/cbutton.hxx b/include/graphics/nxwidgets/cbutton.hxx index ad64d1bc1..78419157c 100644 --- a/include/graphics/nxwidgets/cbutton.hxx +++ b/include/graphics/nxwidgets/cbutton.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwidgets/cbutton.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -217,7 +215,7 @@ namespace NXWidgets CButton(CWidgetControl *pWidgetControl, nxgl_coord_t x, nxgl_coord_t y, nxgl_coord_t width, nxgl_coord_t height, const CNxString &text, - CWidgetStyle *style = NULL); + CWidgetStyle *style = (CWidgetStyle *)NULL); /** * CButton Destructor. diff --git a/include/graphics/nxwidgets/cbuttonarray.hxx b/include/graphics/nxwidgets/cbuttonarray.hxx index 8c4798f32..429e8245f 100644 --- a/include/graphics/nxwidgets/cbuttonarray.hxx +++ b/include/graphics/nxwidgets/cbuttonarray.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwidgets/cbuttonarray.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -193,7 +191,7 @@ namespace NXWidgets nxgl_coord_t x, nxgl_coord_t y, uint8_t buttonColumns, uint8_t buttonRows, nxgl_coord_t buttonWidth, nxgl_coord_t buttonHeight, - CWidgetStyle *style = NULL); + CWidgetStyle *style = (CWidgetStyle *)NULL); /** * CButtonArray Destructor. diff --git a/include/graphics/nxwidgets/ccallback.hxx b/include/graphics/nxwidgets/ccallback.hxx index 96e5ca893..b0cadbb54 100644 --- a/include/graphics/nxwidgets/ccallback.hxx +++ b/include/graphics/nxwidgets/ccallback.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwidgets/ccallback.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/graphics/nxwidgets/ccheckbox.hxx b/include/graphics/nxwidgets/ccheckbox.hxx index e97b62fe0..20fc3133e 100644 --- a/include/graphics/nxwidgets/ccheckbox.hxx +++ b/include/graphics/nxwidgets/ccheckbox.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwidgets/ccheckbox.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -164,7 +162,7 @@ namespace NXWidgets CCheckBox(CWidgetControl *pWidgetControl, nxgl_coord_t x, nxgl_coord_t y, nxgl_coord_t width, nxgl_coord_t height, - CWidgetStyle *style = NULL); + CWidgetStyle *style = (CWidgetStyle *)NULL); /** * Destructor. diff --git a/include/graphics/nxwidgets/ccyclebutton.hxx b/include/graphics/nxwidgets/ccyclebutton.hxx index 441b4bb0e..e5bfeb593 100644 --- a/include/graphics/nxwidgets/ccyclebutton.hxx +++ b/include/graphics/nxwidgets/ccyclebutton.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwidgets/ccyclebutton.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -193,7 +191,7 @@ namespace NXWidgets CCycleButton(CWidgetControl *pWidgetControl, nxgl_coord_t x, nxgl_coord_t y, nxgl_coord_t width, nxgl_coord_t height, - CWidgetStyle *style = NULL); + CWidgetStyle *style = (CWidgetStyle *)NULL); /** * Destructor. diff --git a/include/graphics/nxwidgets/cglyphbutton.hxx b/include/graphics/nxwidgets/cglyphbutton.hxx index c0c759924..d764afc6a 100644 --- a/include/graphics/nxwidgets/cglyphbutton.hxx +++ b/include/graphics/nxwidgets/cglyphbutton.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwidgets/cbutton.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -203,7 +201,7 @@ namespace NXWidgets nxgl_coord_t bitmapX, nxgl_coord_t bitmapY, FAR const struct SBitmap *normalGlyph, FAR const struct SBitmap *clickedGlyph, - CWidgetStyle *style = NULL); + CWidgetStyle *style = (CWidgetStyle *)NULL); /** * Destructor. diff --git a/include/graphics/nxwidgets/cglyphsliderhorizontal.hxx b/include/graphics/nxwidgets/cglyphsliderhorizontal.hxx index 8d1cacafc..daf6bb971 100644 --- a/include/graphics/nxwidgets/cglyphsliderhorizontal.hxx +++ b/include/graphics/nxwidgets/cglyphsliderhorizontal.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwidgets/cglyphsliderhorizontal.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/graphics/nxwidgets/cglyphsliderhorizontalgrip.hxx b/include/graphics/nxwidgets/cglyphsliderhorizontalgrip.hxx index b3e4b8b9c..e4f61401c 100644 --- a/include/graphics/nxwidgets/cglyphsliderhorizontalgrip.hxx +++ b/include/graphics/nxwidgets/cglyphsliderhorizontalgrip.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwidgets/cglyphsliderhorizontalgrip.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/graphics/nxwidgets/cgraphicsport.hxx b/include/graphics/nxwidgets/cgraphicsport.hxx index e715e2014..c5a052995 100644 --- a/include/graphics/nxwidgets/cgraphicsport.hxx +++ b/include/graphics/nxwidgets/cgraphicsport.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwidgets/cgraphicsport.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/graphics/nxwidgets/cimage.hxx b/include/graphics/nxwidgets/cimage.hxx index 1698c5511..cdf453f5c 100644 --- a/include/graphics/nxwidgets/cimage.hxx +++ b/include/graphics/nxwidgets/cimage.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwidgets/cimage.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -203,7 +201,7 @@ namespace NXWidgets CImage(CWidgetControl *pWidgetControl, nxgl_coord_t x, nxgl_coord_t y, nxgl_coord_t width, nxgl_coord_t height, FAR IBitmap *bitmap, - CWidgetStyle *style = NULL); + CWidgetStyle *style = (CWidgetStyle *)NULL); /** * Destructor. diff --git a/include/graphics/nxwidgets/ckeypad.hxx b/include/graphics/nxwidgets/ckeypad.hxx index c3ecaae53..ba7db526f 100644 --- a/include/graphics/nxwidgets/ckeypad.hxx +++ b/include/graphics/nxwidgets/ckeypad.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwidgets/ckeypad.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -96,7 +94,7 @@ namespace NXWidgets CKeypad(CWidgetControl *pWidgetControl, NXHANDLE hNxServer, nxgl_coord_t x, nxgl_coord_t y, nxgl_coord_t width, nxgl_coord_t height, - CWidgetStyle *style = NULL); + CWidgetStyle *style = (CWidgetStyle *)NULL); /** * CKeypad Destructor. diff --git a/include/graphics/nxwidgets/clabel.hxx b/include/graphics/nxwidgets/clabel.hxx index a94907869..37c4fc7ae 100644 --- a/include/graphics/nxwidgets/clabel.hxx +++ b/include/graphics/nxwidgets/clabel.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwidgets/clabel.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -206,7 +204,7 @@ namespace NXWidgets CLabel(CWidgetControl *pWidgetControl, nxgl_coord_t x, nxgl_coord_t y, nxgl_coord_t width, nxgl_coord_t height, const CNxString &text, - CWidgetStyle *style = NULL); + CWidgetStyle *style = (CWidgetStyle *)NULL); /** * Destructor. @@ -287,7 +285,7 @@ namespace NXWidgets * @param index Index at which to insert the text. */ - virtual void insertText(const CNxString &text, const unsigned int index); + virtual void insertText(const CNxString &text, const int index); /** * Control the highlight state. diff --git a/include/graphics/nxwidgets/clabelgrid.hxx b/include/graphics/nxwidgets/clabelgrid.hxx index da518f9bc..fe6f521f2 100644 --- a/include/graphics/nxwidgets/clabelgrid.hxx +++ b/include/graphics/nxwidgets/clabelgrid.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/nxwidgets/include/clabelgrid.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/graphics/nxwidgets/clatchbutton.hxx b/include/graphics/nxwidgets/clatchbutton.hxx index c6f3b4ed9..fb63a6eb5 100644 --- a/include/graphics/nxwidgets/clatchbutton.hxx +++ b/include/graphics/nxwidgets/clatchbutton.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwidgets/clatchbutton.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -136,7 +134,7 @@ namespace NXWidgets nxgl_coord_t x, nxgl_coord_t y, nxgl_coord_t width, nxgl_coord_t height, const CNxString &text, - CWidgetStyle *style = NULL); + CWidgetStyle *style = (CWidgetStyle *)NULL); /** * Destructor. diff --git a/include/graphics/nxwidgets/clatchbuttonarray.hxx b/include/graphics/nxwidgets/clatchbuttonarray.hxx index 10c48ca81..e2c34f205 100644 --- a/include/graphics/nxwidgets/clatchbuttonarray.hxx +++ b/include/graphics/nxwidgets/clatchbuttonarray.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/clatchbuttonarray.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -112,7 +110,7 @@ namespace NXWidgets nxgl_coord_t x, nxgl_coord_t y, uint8_t buttonColumns, uint8_t buttonRows, nxgl_coord_t buttonWidth, nxgl_coord_t buttonHeight, - CWidgetStyle *style = NULL); + CWidgetStyle *style = (CWidgetStyle *)NULL); /** * CLatchButtonArray Destructor. diff --git a/include/graphics/nxwidgets/clistbox.hxx b/include/graphics/nxwidgets/clistbox.hxx index 0f1a7c8e5..8777943e6 100644 --- a/include/graphics/nxwidgets/clistbox.hxx +++ b/include/graphics/nxwidgets/clistbox.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwidgets/clistbox.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -182,7 +180,7 @@ namespace NXWidgets CListBox(CWidgetControl *pWidgetControl, nxgl_coord_t x, nxgl_coord_t y, nxgl_coord_t width, nxgl_coord_t height, - CWidgetStyle *style = NULL); + CWidgetStyle *style = (CWidgetStyle *)NULL); /** * Destructor. diff --git a/include/graphics/nxwidgets/clistboxdataitem.hxx b/include/graphics/nxwidgets/clistboxdataitem.hxx index 33ff88399..4d88c1345 100644 --- a/include/graphics/nxwidgets/clistboxdataitem.hxx +++ b/include/graphics/nxwidgets/clistboxdataitem.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/clistboxdataitem.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/graphics/nxwidgets/clistdata.hxx b/include/graphics/nxwidgets/clistdata.hxx index 32317da0b..e9fc290c4 100644 --- a/include/graphics/nxwidgets/clistdata.hxx +++ b/include/graphics/nxwidgets/clistdata.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwidgets/clistdata.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/graphics/nxwidgets/clistdataeventargs.hxx b/include/graphics/nxwidgets/clistdataeventargs.hxx index 3d48cbefb..18649d9ad 100644 --- a/include/graphics/nxwidgets/clistdataeventargs.hxx +++ b/include/graphics/nxwidgets/clistdataeventargs.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwidgets/clistdataeventargs.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/graphics/nxwidgets/clistdataitem.hxx b/include/graphics/nxwidgets/clistdataitem.hxx index 43b68d2cc..9eb48bcd6 100644 --- a/include/graphics/nxwidgets/clistdataitem.hxx +++ b/include/graphics/nxwidgets/clistdataitem.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwidgets/clistdataitem.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/graphics/nxwidgets/cmultilinetextbox.hxx b/include/graphics/nxwidgets/cmultilinetextbox.hxx index f98a405ea..eb153cf88 100644 --- a/include/graphics/nxwidgets/cmultilinetextbox.hxx +++ b/include/graphics/nxwidgets/cmultilinetextbox.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwidgets/cmultilinetextbox.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -386,7 +384,7 @@ namespace NXWidgets inline virtual ~CMultiLineTextBox(void) { delete m_text; - m_text = NULL; + m_text = (CText *)NULL; } /** @@ -424,7 +422,7 @@ namespace NXWidgets nxgl_coord_t width, nxgl_coord_t height, const CNxString &text, uint32_t flags, nxgl_coord_t maxRows = 0, - CWidgetStyle *style = NULL); + CWidgetStyle *style = (CWidgetStyle *)NULL); /** * Set the horizontal alignment of text within the textbox. diff --git a/include/graphics/nxwidgets/cnumericedit.hxx b/include/graphics/nxwidgets/cnumericedit.hxx index 18bc2b5cd..6dddbdbdd 100644 --- a/include/graphics/nxwidgets/cnumericedit.hxx +++ b/include/graphics/nxwidgets/cnumericedit.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwidgets/cnumericedit.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -158,7 +156,7 @@ namespace NXWidgets CNumericEdit(CWidgetControl *pWidgetControl, nxgl_coord_t x, nxgl_coord_t y, nxgl_coord_t width, nxgl_coord_t height, - CWidgetStyle *style = NULL); + CWidgetStyle *style = (CWidgetStyle *)NULL); /** * Destructor. diff --git a/include/graphics/nxwidgets/cnxfont.hxx b/include/graphics/nxwidgets/cnxfont.hxx index a894e1e51..873430e43 100644 --- a/include/graphics/nxwidgets/cnxfont.hxx +++ b/include/graphics/nxwidgets/cnxfont.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwidgets/cnxfont.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/graphics/nxwidgets/cnxserver.hxx b/include/graphics/nxwidgets/cnxserver.hxx index 55b730a3d..5683506eb 100644 --- a/include/graphics/nxwidgets/cnxserver.hxx +++ b/include/graphics/nxwidgets/cnxserver.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwidgets/cnxserver.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/graphics/nxwidgets/cnxstring.hxx b/include/graphics/nxwidgets/cnxstring.hxx index 6f5d8198e..525b98e3a 100644 --- a/include/graphics/nxwidgets/cnxstring.hxx +++ b/include/graphics/nxwidgets/cnxstring.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/cnxtring.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -211,7 +209,7 @@ namespace NXWidgets virtual inline ~CNxString() { delete[] m_text; - m_text = NULL; + m_text = (FAR nxwidget_char_t *)NULL; }; /** @@ -512,7 +510,7 @@ namespace NXWidgets * @return New CNxString instance. */ - static CNxString format(const char *fmt, ...) printf_like(1, 2); + static CNxString format(const char *fmt, ...); }; } diff --git a/include/graphics/nxwidgets/cnxtimer.hxx b/include/graphics/nxwidgets/cnxtimer.hxx index f17f74fd3..1ee40371e 100644 --- a/include/graphics/nxwidgets/cnxtimer.hxx +++ b/include/graphics/nxwidgets/cnxtimer.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwidgets/cnxtimer.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/graphics/nxwidgets/cnxtkwindow.hxx b/include/graphics/nxwidgets/cnxtkwindow.hxx index b8b4fa999..db08cb3db 100644 --- a/include/graphics/nxwidgets/cnxtkwindow.hxx +++ b/include/graphics/nxwidgets/cnxtkwindow.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwidgets/cnxtkwindow.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -164,7 +162,7 @@ namespace NXWidgets inline void detachToolbar(void) { - m_toolbar = NULL; + m_toolbar = (CNxToolbar *)NULL; m_toolbarHeight = 0; } diff --git a/include/graphics/nxwidgets/cnxtoolbar.hxx b/include/graphics/nxwidgets/cnxtoolbar.hxx index a70014bda..8bfdd64ad 100644 --- a/include/graphics/nxwidgets/cnxtoolbar.hxx +++ b/include/graphics/nxwidgets/cnxtoolbar.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwidgets/cnxtoolbar.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/graphics/nxwidgets/cnxwidget.hxx b/include/graphics/nxwidgets/cnxwidget.hxx index eb1414dc8..b1b6219ed 100644 --- a/include/graphics/nxwidgets/cnxwidget.hxx +++ b/include/graphics/nxwidgets/cnxwidget.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/cnxwidget.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -399,7 +397,7 @@ namespace NXWidgets nxgl_coord_t x, nxgl_coord_t y, nxgl_coord_t width, nxgl_coord_t height, uint32_t flags, - FAR const CWidgetStyle *style = NULL); + FAR const CWidgetStyle *style = (FAR const CWidgetStyle *)NULL); /** * Destructor. diff --git a/include/graphics/nxwidgets/cnxwindow.hxx b/include/graphics/nxwidgets/cnxwindow.hxx index c75145a64..c8b5535be 100644 --- a/include/graphics/nxwidgets/cnxwindow.hxx +++ b/include/graphics/nxwidgets/cnxwindow.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwidgets/cnxwindow.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/graphics/nxwidgets/cprogressbar.hxx b/include/graphics/nxwidgets/cprogressbar.hxx index a4f2162a3..6a33a67ec 100644 --- a/include/graphics/nxwidgets/cprogressbar.hxx +++ b/include/graphics/nxwidgets/cprogressbar.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwidgets/cprogressbar.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/graphics/nxwidgets/cradiobutton.hxx b/include/graphics/nxwidgets/cradiobutton.hxx index b293d6b2d..10935c4cf 100644 --- a/include/graphics/nxwidgets/cradiobutton.hxx +++ b/include/graphics/nxwidgets/cradiobutton.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwidgets/cradiobutton.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -168,7 +166,7 @@ namespace NXWidgets CRadioButton(CWidgetControl *pWidgetControl, nxgl_coord_t x, nxgl_coord_t y, nxgl_coord_t width, nxgl_coord_t height, - CWidgetStyle *style = NULL); + CWidgetStyle *style = (CWidgetStyle *)NULL); /** * Get the current state of the radio button. diff --git a/include/graphics/nxwidgets/cradiobuttongroup.hxx b/include/graphics/nxwidgets/cradiobuttongroup.hxx index 427dfdfbb..16413126d 100644 --- a/include/graphics/nxwidgets/cradiobuttongroup.hxx +++ b/include/graphics/nxwidgets/cradiobuttongroup.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwidgets/cradiobuttongroup.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -135,7 +133,7 @@ namespace NXWidgets CRadioButtonGroup(CWidgetControl *pWidgetControl, nxgl_coord_t x, nxgl_coord_t y, - CWidgetStyle *style = NULL); + CWidgetStyle *style = (CWidgetStyle *)NULL); /** * Destructor. diff --git a/include/graphics/nxwidgets/crect.hxx b/include/graphics/nxwidgets/crect.hxx index 864a46be4..02a8874ae 100644 --- a/include/graphics/nxwidgets/crect.hxx +++ b/include/graphics/nxwidgets/crect.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwidgets/cbgwindow.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/graphics/nxwidgets/crlepalettebitmap.hxx b/include/graphics/nxwidgets/crlepalettebitmap.hxx index 395c8c4d7..d14ba4cc0 100644 --- a/include/graphics/nxwidgets/crlepalettebitmap.hxx +++ b/include/graphics/nxwidgets/crlepalettebitmap.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwidgets/crlepalettebitmap.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -65,12 +63,12 @@ namespace NXWidgets struct SRlePaletteBitmap { - uint8_t bpp; /**< Bits per pixel */ - uint8_t fmt; /**< Color format */ - uint8_t nlut; /**< Number of colors in the Look-Up Table (LUT) */ - nxgl_coord_t width; /**< Width in pixels */ - nxgl_coord_t height; /**< Height in rows */ - FAR const void *lut[2]; /**< Pointers to the beginning of the Look-Up Tables (LUTs) */ + uint8_t bpp; /**< Bits per pixel */ + uint8_t fmt; /**< Color format */ + uint8_t nlut; /**< Number of colors in the Look-Up Table (LUT) */ + nxgl_coord_t width; /**< Width in pixels */ + nxgl_coord_t height; /**< Height in rows */ + FAR const void *lut[2]; /**< Pointers to the beginning of the Look-Up Tables (LUTs) */ /** * The pointer to the beginning of the RLE data diff --git a/include/graphics/nxwidgets/cscaledbitmap.hxx b/include/graphics/nxwidgets/cscaledbitmap.hxx index f175dd6ee..7fc3538d6 100644 --- a/include/graphics/nxwidgets/cscaledbitmap.hxx +++ b/include/graphics/nxwidgets/cscaledbitmap.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwidgets/cscaledbitmap.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -32,7 +30,7 @@ #include #include #include -#include +#include #include #include diff --git a/include/graphics/nxwidgets/cscrollbarhorizontal.hxx b/include/graphics/nxwidgets/cscrollbarhorizontal.hxx index 0280516b4..7f9853fef 100644 --- a/include/graphics/nxwidgets/cscrollbarhorizontal.hxx +++ b/include/graphics/nxwidgets/cscrollbarhorizontal.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwidgets/cscrollbarhorizontal.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -146,7 +144,7 @@ namespace NXWidgets CScrollbarHorizontal(CWidgetControl *pWidgetControl, nxgl_coord_t x, nxgl_coord_t y, nxgl_coord_t width, nxgl_coord_t height, - CWidgetStyle *style = NULL); + CWidgetStyle *style = (CWidgetStyle *)NULL); /** * Destructor. diff --git a/include/graphics/nxwidgets/cscrollbarpanel.hxx b/include/graphics/nxwidgets/cscrollbarpanel.hxx index 0f1fcaa07..4236a7ef5 100644 --- a/include/graphics/nxwidgets/cscrollbarpanel.hxx +++ b/include/graphics/nxwidgets/cscrollbarpanel.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwidgets/cscrollbarpanel.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -162,7 +160,7 @@ namespace NXWidgets nxgl_coord_t x, nxgl_coord_t y, nxgl_coord_t width, nxgl_coord_t height, uint32_t flags, - CWidgetStyle *style = NULL); + CWidgetStyle *style = (CWidgetStyle *)NULL); /** * Scroll the panel by the specified amounts. diff --git a/include/graphics/nxwidgets/cscrollbarvertical.hxx b/include/graphics/nxwidgets/cscrollbarvertical.hxx index e6d13796c..630329bf9 100644 --- a/include/graphics/nxwidgets/cscrollbarvertical.hxx +++ b/include/graphics/nxwidgets/cscrollbarvertical.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwidgets/cscrollbarvertical.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -145,7 +143,7 @@ namespace NXWidgets CScrollbarVertical(CWidgetControl *pWidgetControl, nxgl_coord_t x, nxgl_coord_t y, nxgl_coord_t width, nxgl_coord_t height, - CWidgetStyle *style = NULL); + CWidgetStyle *style = (CWidgetStyle *)NULL); /** * Destructor. diff --git a/include/graphics/nxwidgets/cscrollinglistbox.hxx b/include/graphics/nxwidgets/cscrollinglistbox.hxx index 662682dbc..659239961 100644 --- a/include/graphics/nxwidgets/cscrollinglistbox.hxx +++ b/include/graphics/nxwidgets/cscrollinglistbox.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwidgets/cscrollinglistbox.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -158,7 +156,7 @@ namespace NXWidgets CScrollingListBox(CWidgetControl *pWidgetControl, nxgl_coord_t x, nxgl_coord_t y, nxgl_coord_t width, nxgl_coord_t height, - CWidgetStyle *style = NULL); + CWidgetStyle *style = (CWidgetStyle *)NULL); /** * Add a new option to the widget using default colors. diff --git a/include/graphics/nxwidgets/cscrollingpanel.hxx b/include/graphics/nxwidgets/cscrollingpanel.hxx index 17e48f108..b9e34b69c 100644 --- a/include/graphics/nxwidgets/cscrollingpanel.hxx +++ b/include/graphics/nxwidgets/cscrollingpanel.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwidgets/cscrollingpanel.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -196,7 +194,7 @@ namespace NXWidgets nxgl_coord_t x, nxgl_coord_t y, nxgl_coord_t width, nxgl_coord_t height, uint32_t flags, - CWidgetStyle *style = NULL); + CWidgetStyle *style = (CWidgetStyle *)NULL); /** * Scroll the panel by the specified amounts. diff --git a/include/graphics/nxwidgets/cscrollingtextbox.hxx b/include/graphics/nxwidgets/cscrollingtextbox.hxx index 65bc47570..30d591fe7 100644 --- a/include/graphics/nxwidgets/cscrollingtextbox.hxx +++ b/include/graphics/nxwidgets/cscrollingtextbox.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwidgets/cscrollingtextbox.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -165,7 +163,7 @@ namespace NXWidgets nxgl_coord_t width, nxgl_coord_t height, const CNxString &text, uint32_t flags, nxgl_coord_t maxRows = 0, - CWidgetStyle *style = NULL); + CWidgetStyle *style = (CWidgetStyle *)NULL); /** * Set the horizontal alignment of text within the textbox. diff --git a/include/graphics/nxwidgets/csliderhorizontal.hxx b/include/graphics/nxwidgets/csliderhorizontal.hxx index ea797eaaf..f87f52ac0 100644 --- a/include/graphics/nxwidgets/csliderhorizontal.hxx +++ b/include/graphics/nxwidgets/csliderhorizontal.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwidgets/csliderhorizontal.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/graphics/nxwidgets/csliderhorizontalgrip.hxx b/include/graphics/nxwidgets/csliderhorizontalgrip.hxx index 5b18d916a..e45fcb204 100644 --- a/include/graphics/nxwidgets/csliderhorizontalgrip.hxx +++ b/include/graphics/nxwidgets/csliderhorizontalgrip.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwidgets/csliderhorizontalgrip.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/graphics/nxwidgets/cslidervertical.hxx b/include/graphics/nxwidgets/cslidervertical.hxx index 7a2ca5c64..8f6f3dd3d 100644 --- a/include/graphics/nxwidgets/cslidervertical.hxx +++ b/include/graphics/nxwidgets/cslidervertical.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwidgets/cslidervertical.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/graphics/nxwidgets/csliderverticalgrip.hxx b/include/graphics/nxwidgets/csliderverticalgrip.hxx index c3ccb13b7..eca56a6da 100644 --- a/include/graphics/nxwidgets/csliderverticalgrip.hxx +++ b/include/graphics/nxwidgets/csliderverticalgrip.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwidgets/cslidervertical.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/graphics/nxwidgets/cstickybutton.hxx b/include/graphics/nxwidgets/cstickybutton.hxx index 279fad095..8aecef7d8 100644 --- a/include/graphics/nxwidgets/cstickybutton.hxx +++ b/include/graphics/nxwidgets/cstickybutton.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwidgets/cstickybutton.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -181,7 +179,7 @@ namespace NXWidgets nxgl_coord_t x, nxgl_coord_t y, nxgl_coord_t width, nxgl_coord_t height, const CNxString &text, - CWidgetStyle *style = NULL); + CWidgetStyle *style = (CWidgetStyle *)NULL); /** * Destructor. diff --git a/include/graphics/nxwidgets/cstickybuttonarray.hxx b/include/graphics/nxwidgets/cstickybuttonarray.hxx index 4d6bb7afe..c84312503 100644 --- a/include/graphics/nxwidgets/cstickybuttonarray.hxx +++ b/include/graphics/nxwidgets/cstickybuttonarray.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwidgets/cstickybuttonarray.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -106,7 +104,7 @@ namespace NXWidgets nxgl_coord_t x, nxgl_coord_t y, uint8_t buttonColumns, uint8_t buttonRows, nxgl_coord_t buttonWidth, nxgl_coord_t buttonHeight, - CWidgetStyle *style = NULL); + CWidgetStyle *style = (CWidgetStyle *)NULL); /** * CStickyButtonArray Destructor. diff --git a/include/graphics/nxwidgets/cstickyimage.hxx b/include/graphics/nxwidgets/cstickyimage.hxx index 4ca29e6db..38b226b00 100644 --- a/include/graphics/nxwidgets/cstickyimage.hxx +++ b/include/graphics/nxwidgets/cstickyimage.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwidgets/cstickyimage.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -134,7 +132,7 @@ namespace NXWidgets CStickyImage(CWidgetControl *pWidgetControl, nxgl_coord_t x, nxgl_coord_t y, nxgl_coord_t width, nxgl_coord_t height, FAR IBitmap *bitmap, - CWidgetStyle *style = NULL); + CWidgetStyle *style = (CWidgetStyle *)NULL); /** * Destructor. diff --git a/include/graphics/nxwidgets/cstringiterator.hxx b/include/graphics/nxwidgets/cstringiterator.hxx index 09c883243..e20b1ec13 100644 --- a/include/graphics/nxwidgets/cstringiterator.hxx +++ b/include/graphics/nxwidgets/cstringiterator.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwidgets/cstringiterator.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/graphics/nxwidgets/ctabpanel.hxx b/include/graphics/nxwidgets/ctabpanel.hxx index 75937628f..4a52a7607 100644 --- a/include/graphics/nxwidgets/ctabpanel.hxx +++ b/include/graphics/nxwidgets/ctabpanel.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwidgets/ctabpanel.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -80,7 +78,7 @@ namespace NXWidgets nxgl_coord_t x, nxgl_coord_t y, nxgl_coord_t width, nxgl_coord_t height, nxgl_coord_t buttonHeight, - FAR const CWidgetStyle *style = NULL + FAR const CWidgetStyle *style = (FAR const CWidgetStyle *)NULL ); inline CNxWidget &page(uint8_t index) { return *m_tabpages.at(index); } diff --git a/include/graphics/nxwidgets/ctext.hxx b/include/graphics/nxwidgets/ctext.hxx index b5ce62157..19aa01d09 100644 --- a/include/graphics/nxwidgets/ctext.hxx +++ b/include/graphics/nxwidgets/ctext.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwidgets/ctext.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/graphics/nxwidgets/ctextbox.hxx b/include/graphics/nxwidgets/ctextbox.hxx index ffc6d8d1e..4bc25edc7 100644 --- a/include/graphics/nxwidgets/ctextbox.hxx +++ b/include/graphics/nxwidgets/ctextbox.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwidgets/ctextbox.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -228,7 +226,7 @@ namespace NXWidgets CTextBox(CWidgetControl *pWidgetControl, nxgl_coord_t x, nxgl_coord_t y, nxgl_coord_t width, nxgl_coord_t height, const CNxString &text, - CWidgetStyle *style = NULL); + CWidgetStyle *style = (CWidgetStyle *)NULL); /** * Sets the cursor display mode. diff --git a/include/graphics/nxwidgets/cwidgetcontrol.hxx b/include/graphics/nxwidgets/cwidgetcontrol.hxx index 504aab616..31dff8a7a 100644 --- a/include/graphics/nxwidgets/cwidgetcontrol.hxx +++ b/include/graphics/nxwidgets/cwidgetcontrol.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwidgets/cwidgetcontrol.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -354,7 +352,7 @@ namespace NXWidgets * values stored in the defaultCWidgetStyle object. */ - CWidgetControl(FAR const CWidgetStyle *style = NULL); + CWidgetControl(FAR const CWidgetStyle *style = (const CWidgetStyle *)NULL); /** * Destructor. @@ -422,7 +420,7 @@ namespace NXWidgets * @return True means some interesting event occurred */ - bool pollEvents(CNxWidget *widget = NULL); + bool pollEvents(CNxWidget *widget = (CNxWidget *)NULL); /** * Swaps the depth of the supplied widget. @@ -511,7 +509,7 @@ namespace NXWidgets { if (widget == m_focusedWidget) { - m_focusedWidget = NULL; + m_focusedWidget = (CNxWidget *)NULL; } } diff --git a/include/graphics/nxwidgets/cwidgeteventargs.hxx b/include/graphics/nxwidgets/cwidgeteventargs.hxx index 42ea5ed5f..143f3b02f 100644 --- a/include/graphics/nxwidgets/cwidgeteventargs.hxx +++ b/include/graphics/nxwidgets/cwidgeteventargs.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwidgets/cwidgeteventargs.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/graphics/nxwidgets/cwidgeteventhandler.hxx b/include/graphics/nxwidgets/cwidgeteventhandler.hxx index 823dac9d0..3df10531c 100644 --- a/include/graphics/nxwidgets/cwidgeteventhandler.hxx +++ b/include/graphics/nxwidgets/cwidgeteventhandler.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwidgets/cwidgeteventhandler.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/graphics/nxwidgets/cwidgeteventhandlerlist.hxx b/include/graphics/nxwidgets/cwidgeteventhandlerlist.hxx index 24b11ce80..846f76505 100644 --- a/include/graphics/nxwidgets/cwidgeteventhandlerlist.hxx +++ b/include/graphics/nxwidgets/cwidgeteventhandlerlist.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwidgets/cwidgeteventhandlerlist.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/graphics/nxwidgets/cwidgetstyle.hxx b/include/graphics/nxwidgets/cwidgetstyle.hxx index 01e333ea1..b1d25aeac 100644 --- a/include/graphics/nxwidgets/cwidgetstyle.hxx +++ b/include/graphics/nxwidgets/cwidgetstyle.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwidgets/cwidgetstyle.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/graphics/nxwidgets/cwindoweventhandler.hxx b/include/graphics/nxwidgets/cwindoweventhandler.hxx index 5979c254e..c4729e128 100644 --- a/include/graphics/nxwidgets/cwindoweventhandler.hxx +++ b/include/graphics/nxwidgets/cwindoweventhandler.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwidgets/cwindoweventhandler.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/graphics/nxwidgets/cwindoweventhandlerlist.hxx b/include/graphics/nxwidgets/cwindoweventhandlerlist.hxx index f59af9c5d..be494c879 100644 --- a/include/graphics/nxwidgets/cwindoweventhandlerlist.hxx +++ b/include/graphics/nxwidgets/cwindoweventhandlerlist.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwidgets/cwindoweventhandlerlist.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/graphics/nxwidgets/ibitmap.hxx b/include/graphics/nxwidgets/ibitmap.hxx index 208e91bf7..d2abbb964 100644 --- a/include/graphics/nxwidgets/ibitmap.hxx +++ b/include/graphics/nxwidgets/ibitmap.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwidgets/ibitmap.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/graphics/nxwidgets/ilistbox.hxx b/include/graphics/nxwidgets/ilistbox.hxx index 32a77bec8..89003b70b 100644 --- a/include/graphics/nxwidgets/ilistbox.hxx +++ b/include/graphics/nxwidgets/ilistbox.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwidgets/ilistbox.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/graphics/nxwidgets/ilistdataeventhandler.hxx b/include/graphics/nxwidgets/ilistdataeventhandler.hxx index 2ca274d43..6aa2cd484 100644 --- a/include/graphics/nxwidgets/ilistdataeventhandler.hxx +++ b/include/graphics/nxwidgets/ilistdataeventhandler.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwidgets/ilistdataeventhandler.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/graphics/nxwidgets/inxwindow.hxx b/include/graphics/nxwidgets/inxwindow.hxx index 0236192ef..28aabd0a6 100644 --- a/include/graphics/nxwidgets/inxwindow.hxx +++ b/include/graphics/nxwidgets/inxwindow.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwidgets/inxwindow.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/graphics/nxwidgets/iscrollable.hxx b/include/graphics/nxwidgets/iscrollable.hxx index 53fdcecdd..baaf2e465 100644 --- a/include/graphics/nxwidgets/iscrollable.hxx +++ b/include/graphics/nxwidgets/iscrollable.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwidgets/iscrollable.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/graphics/nxwidgets/islider.hxx b/include/graphics/nxwidgets/islider.hxx index d50e60dc3..4c5b787dd 100644 --- a/include/graphics/nxwidgets/islider.hxx +++ b/include/graphics/nxwidgets/islider.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwidgets/islider.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/graphics/nxwidgets/itextbox.hxx b/include/graphics/nxwidgets/itextbox.hxx index 006ade8a5..99216f19c 100644 --- a/include/graphics/nxwidgets/itextbox.hxx +++ b/include/graphics/nxwidgets/itextbox.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwidgets/itextbox.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/graphics/nxwidgets/nxconfig.hxx b/include/graphics/nxwidgets/nxconfig.hxx index 4a8e1ebf7..097af19e0 100644 --- a/include/graphics/nxwidgets/nxconfig.hxx +++ b/include/graphics/nxwidgets/nxconfig.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwidgets/nxconfig.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/graphics/nxwidgets/singletons.hxx b/include/graphics/nxwidgets/singletons.hxx index 588af5560..d3ef88c72 100644 --- a/include/graphics/nxwidgets/singletons.hxx +++ b/include/graphics/nxwidgets/singletons.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwidgets/singletons.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/graphics/nxwidgets/teventargs.hxx b/include/graphics/nxwidgets/teventargs.hxx index 15df705d4..c7d78429f 100644 --- a/include/graphics/nxwidgets/teventargs.hxx +++ b/include/graphics/nxwidgets/teventargs.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwidgets/teventargs.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/graphics/nxwidgets/tnxarray.hxx b/include/graphics/nxwidgets/tnxarray.hxx index 9c28c9211..e27f25b8f 100644 --- a/include/graphics/nxwidgets/tnxarray.hxx +++ b/include/graphics/nxwidgets/tnxarray.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwidgets/tnxarray.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/graphics/nxwm/capplicationwindow.hxx b/include/graphics/nxwm/capplicationwindow.hxx index 51365d1b2..5362a3fe9 100644 --- a/include/graphics/nxwm/capplicationwindow.hxx +++ b/include/graphics/nxwm/capplicationwindow.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwm/capplicationwindow.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/graphics/nxwm/ccalibration.hxx b/include/graphics/nxwm/ccalibration.hxx index e80354149..8ee66f2c8 100644 --- a/include/graphics/nxwm/ccalibration.hxx +++ b/include/graphics/nxwm/ccalibration.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwm/ccalibration.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -66,7 +64,7 @@ namespace NxWM * Forward references */ - class CTouchscreen; + struct CTouchscreen; /** * Touchscreen calibration data @@ -166,6 +164,7 @@ namespace NxWM struct nxgl_point_s m_touchPos; /**< This is the last touch position */ volatile uint8_t m_calthread; /**< Current calibration display state (See ECalibThreadState)*/ uint8_t m_calphase; /**< Current calibration display state (See ECalibrationPhase)*/ + bool m_stop; /**< True: We have been asked to stop the calibration */ bool m_touched; /**< True: The screen is touched */ uint8_t m_touchId; /**< The ID of the touch */ #ifdef CONFIG_NXWM_CALIBRATION_AVERAGE @@ -397,8 +396,8 @@ namespace NxWM class CCalibrationFactory : public IApplicationFactory { private: - CTaskbar *m_taskbar; /**< The taskbar */ - CTouchscreen *m_touchscreen; /**< The touchscreen device */ + CTaskbar *m_taskbar; /**< The taskbar */ + CTouchscreen *m_touchscreen; /**< The touchscreen device */ public: /** diff --git a/include/graphics/nxwm/cfullscreenwindow.hxx b/include/graphics/nxwm/cfullscreenwindow.hxx index 3054e6f8e..b03798482 100644 --- a/include/graphics/nxwm/cfullscreenwindow.hxx +++ b/include/graphics/nxwm/cfullscreenwindow.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwm/cfullscreenwindow.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/graphics/nxwm/chexcalculator.hxx b/include/graphics/nxwm/chexcalculator.hxx index 2780a1047..146c8810b 100644 --- a/include/graphics/nxwm/chexcalculator.hxx +++ b/include/graphics/nxwm/chexcalculator.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwm/chexcalculator.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/graphics/nxwm/ckeyboard.hxx b/include/graphics/nxwm/ckeyboard.hxx index 64535dafb..f810f6a97 100644 --- a/include/graphics/nxwm/ckeyboard.hxx +++ b/include/graphics/nxwm/ckeyboard.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwm/keyboard.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/graphics/nxwm/cmediaplayer.hxx b/include/graphics/nxwm/cmediaplayer.hxx index fd1745dc5..20e454ca2 100644 --- a/include/graphics/nxwm/cmediaplayer.hxx +++ b/include/graphics/nxwm/cmediaplayer.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwm/cmediaplayer.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/graphics/nxwm/cnxterm.hxx b/include/graphics/nxwm/cnxterm.hxx index 5afbac76c..fb4acfbcb 100644 --- a/include/graphics/nxwm/cnxterm.hxx +++ b/include/graphics/nxwm/cnxterm.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwm/cnxterm.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -65,11 +63,11 @@ namespace NxWM class CNxTerm : public IApplication, private IApplicationCallback { private: - CTaskbar *m_taskbar; /**< Reference to the "parent" taskbar */ - CApplicationWindow *m_window; /**< Reference to the application window */ - NXTERM m_nxterm; /**< NxTerm handle */ - pid_t m_pid; /**< Task ID of the NxTerm thread */ - int m_minor; /**< Terminal device minor number */ + CTaskbar *m_taskbar; /**< Reference to the "parent" taskbar */ + CApplicationWindow *m_window; /**< Reference to the application window */ + NXTERM m_nxterm; /**< NxTerm handle */ + pid_t m_pid; /**< Task ID of the NxTerm thread */ + int m_minor; /**< Terminal device minor number */ /** * This is the NxTerm task. This function first redirects output to the diff --git a/include/graphics/nxwm/cstartwindow.hxx b/include/graphics/nxwm/cstartwindow.hxx index 2c1d0178a..a3a6c87ff 100644 --- a/include/graphics/nxwm/cstartwindow.hxx +++ b/include/graphics/nxwm/cstartwindow.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwm/cnxstart.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -29,7 +27,7 @@ #include -#include +#include #include "graphics/nxwidgets/tnxarray.hxx" diff --git a/include/graphics/nxwm/ctaskbar.hxx b/include/graphics/nxwm/ctaskbar.hxx index fd312b3f1..295a173ae 100644 --- a/include/graphics/nxwm/ctaskbar.hxx +++ b/include/graphics/nxwm/ctaskbar.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwm/cnxtaskbar.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/graphics/nxwm/ctouchscreen.hxx b/include/graphics/nxwm/ctouchscreen.hxx index 7808f21ba..0e215b7a0 100644 --- a/include/graphics/nxwm/ctouchscreen.hxx +++ b/include/graphics/nxwm/ctouchscreen.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwm/ctouchscreen.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/graphics/nxwm/cwindowmessenger.hxx b/include/graphics/nxwm/cwindowmessenger.hxx index 535b7aeb5..0917f5b19 100644 --- a/include/graphics/nxwm/cwindowmessenger.hxx +++ b/include/graphics/nxwm/cwindowmessenger.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwm/cwindowmessenger.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -120,7 +118,8 @@ namespace NxWM * values stored in the defaultCWidgetStyle object. */ - CWindowMessenger(FAR const NXWidgets::CWidgetStyle *style = NULL); + CWindowMessenger(FAR const NXWidgets::CWidgetStyle *style = + (const NXWidgets::CWidgetStyle *)NULL); /** * CWindowMessenger Destructor. diff --git a/include/graphics/nxwm/iapplication.hxx b/include/graphics/nxwm/iapplication.hxx index 26b3ff694..e671304ed 100644 --- a/include/graphics/nxwm/iapplication.hxx +++ b/include/graphics/nxwm/iapplication.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwm/iapplication.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/graphics/nxwm/iapplicationwindow.hxx b/include/graphics/nxwm/iapplicationwindow.hxx index 72addbcd6..d702869b5 100644 --- a/include/graphics/nxwm/iapplicationwindow.hxx +++ b/include/graphics/nxwm/iapplicationwindow.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwm/iapplicationwindow.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/graphics/nxwm/nxwmconfig.hxx b/include/graphics/nxwm/nxwmconfig.hxx index 06eb68530..ac67a2407 100644 --- a/include/graphics/nxwm/nxwmconfig.hxx +++ b/include/graphics/nxwm/nxwmconfig.hxx @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/nxwm/nxwmconfig.hxx * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -81,8 +79,8 @@ * exit. */ -#if CONFIG_LIBC_MAX_EXITFUNS == 0 -# warning "on_exit() support may be needed (CONFIG_LIBC_MAX_EXITFUNS)" +#ifndef CONFIG_SCHED_ONEXIT +# warning "on_exit() support may be needed (CONFIG_SCHED_ONEXIT)" #endif /** @@ -425,7 +423,7 @@ #endif #ifndef CONFIG_NXWM_TOUCHSCREEN_SIGNO -# define CONFIG_NXWM_TOUCHSCREEN_SIGNO 32 +# define CONFIG_NXWM_TOUCHSCREEN_SIGNO 5 #endif #ifndef CONFIG_NXWM_TOUCHSCREEN_LISTENERPRIO @@ -461,7 +459,7 @@ #endif #ifndef CONFIG_NXWM_KEYBOARD_SIGNO -# define CONFIG_NXWM_KEYBOARD_SIGNO 33 +# define CONFIG_NXWM_KEYBOARD_SIGNO 6 #endif #ifndef CONFIG_NXWM_KEYBOARD_BUFSIZE @@ -534,7 +532,7 @@ #endif #ifndef CONFIG_NXWM_CALIBRATION_SIGNO -# define CONFIG_NXWM_CALIBRATION_SIGNO 32 +# define CONFIG_NXWM_CALIBRATION_SIGNO 5 #endif #ifndef CONFIG_NXWM_CALIBRATION_LISTENERPRIO diff --git a/include/graphics/panel.h b/include/graphics/panel.h index 22a25f212..9eb9daefd 100644 --- a/include/graphics/panel.h +++ b/include/graphics/panel.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/graphics/panel.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/graphics/slcd.hxx b/include/graphics/slcd.hxx index 23d940844..e1b1bb749 100644 --- a/include/graphics/slcd.hxx +++ b/include/graphics/slcd.hxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/include/graphics/slcd.hxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The diff --git a/include/graphics/tiff.h b/include/graphics/tiff.h index 2239ead28..d233c511e 100644 --- a/include/graphics/tiff.h +++ b/include/graphics/tiff.h @@ -1,8 +1,6 @@ -/**************************************************************************** +/************************************************************************************ * apps/include/graphics/tiff.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -18,7 +16,7 @@ * License for the specific language governing permissions and limitations * under the License. * - ****************************************************************************/ + ************************************************************************************/ /* Reference: * "TIFF, Revision 6.0, Final," June 3, 1992, Adobe Developers Association. @@ -27,22 +25,20 @@ #ifndef __APPS_INCLUDE_GRAPHICS_TIFF_H #define __APPS_INCLUDE_GRAPHICS_TIFF_H -/**************************************************************************** +/************************************************************************************ * Included Files - ****************************************************************************/ + ************************************************************************************/ #include #include #include -/**************************************************************************** +/************************************************************************************ * Pre-processor Definitions - ****************************************************************************/ - -/* Configuration ************************************************************/ - -/* TIFF File Format Definitions *********************************************/ + ************************************************************************************/ +/* Configuration ********************************************************************/ +/* TIFF File Format Definitions *****************************************************/ /* Values for the IFD field type */ #define IFD_FIELD_BYTE 1 /* 8-bit unsigned integer */ @@ -60,7 +56,7 @@ * integer */ #define IFD_FIELD_SLONG 9 /* A 32-bit (4-byte) signed (twos-complement) * integer */ -#define IFD_FIELD_SRATIONAL 10 /* Two SLONG's: the first represents the +#define IFD_FIELD_SRATIONAL 10 /* Two SLONG’s: the first represents the * numerator of a fraction, the second the * denominator */ #define IFD_FIELD_FLOAT 11 /* Single precision (4-byte) IEEE format */ @@ -68,11 +64,10 @@ /* Values for the IFD tag type */ -#define IFD_TAG_NEWSUBFILETYPE 254 /* NewSubfileType, LONG */ +#define IFD_TAG_NEWSUBFILETYPE 254 /* NewSubfileType, LONG */ # define TAG_NEWSUBFILETYPE_REDUCED (1 << 0) /* Bit 0: Reduced resolution version of image */ # define TAG_NEWSUBFILETYPE_SINGLE (1 << 1) /* Bit 1: Single page of a multi-page image */ # define TAG_NEWSUBFILETYPE_TRANSP (1 << 2) /* Bit 2: Defines a transparency mask for image */ - #define IFD_TAG_SUBFILETYPE 255 /* SubfileType, SHORT */ # define TAG_SUBFILETYPE_FULL 1 /* Full-resolution image data */ # define TAG_SUBFILETYPE_REDUCED 2 /* Reduced-resolution image data */ @@ -148,11 +143,11 @@ # define TAG_GRAYRESPUNIT_100KTHS 5 /* Number represents hundred-thousandths of a unit */ #define IFD_TAG_GRAYRESPONSECURVE 291 /* GrayResponseCurve, SHORT */ #define IFD_TAG_T4OPTIONS 292 /* T4Options, LONG */ -# define TAG_T4OPTIONS_2D (1 << 0) /* 2-dimensional coding */ -# define TAG_T4OPTIONS_NONE (1 << 1) /* Uncompressed mode */ -# define TAG_T4OPTIONS_FILL (1 << 2) /* Fill bits have been added */ +# define TAG_T4OPTIONS_2D (1 << 0) /* 2-dimensional coding */ +# define TAG_T4OPTIONS_NONE (1 << 1) /* Uncompressed mode */ +# define TAG_T4OPTIONS_FILL (1 << 2) /* Fill bits have been added */ #define IFD_TAG_T6OPTIONS 293 /* T6Options, LONG */ -# define TAG_T6OPTIONS_NONE (1 << 1) /* Uncompressed mode allowed */ +# define TAG_T6OPTIONS_NONE (1 << 1) /* Uncompressed mode allowed */ #define IFD_TAG_RESUNIT 296 /* ResolutionUnit, SHORT (Required) */ # define TAG_RESUNIT_NONE 1 /* No absolute unit of measurement */ # define TAG_RESUNIT_INCH 2 /* Inch (default) */ @@ -188,7 +183,7 @@ # define TAG_EXTSAMP_UNASSALPHA 2 /* Unassociated alpha data */ #define IFD_TAG_SAMPLEFORMAT 339 /* SampleFormat, SHORT */ # define TAG_SAMPLEFMT_UNSIGED 1 /* Unsigned integer data */ -# define TAG_SAMPLEFMT_SIGNED 2 /* Two's complement signed integer data */ +# define TAG_SAMPLEFMT_SIGNED 2 /* Two’s complement signed integer data */ # define TAG_SAMPLEFMT_FLOAT 3 /* IEEE floating point data */ # define TAG_SAMPLEFMT_UNDEFINED 4 /* Undefined data format */ #define IFD_TAG_SMINSAMPLEVALUE 340 /* SMinSampleValue, type matches sample data */ @@ -209,12 +204,10 @@ #define IFD_TAG_REFERENCEBW 532 /* ReferenceBlackWhite, RATIONAL */ #define IFD_TAG_COPYRIGHT 33432 /* Copyright, ASCII */ -/**************************************************************************** +/************************************************************************************ * Public Types - ****************************************************************************/ - -/* TIFF File Format Structure ***********************************************/ - + ************************************************************************************/ +/* TIFF File Format Structure *******************************************************/ /* "A TIFF file begins with an 8-byte image file header that points to an * image file directory (IFD). An image file directory contains information * about the image, as well as pointers to the actual image data." @@ -245,10 +238,9 @@ struct tiff_ifdentry_s }; #define SIZEOF_IFD_ENTRY 12 -/****************************************************************************/ - -/* Structures needed to interface with the TIFF file creation library) and - * also structures used only internally by the TIFF file creation library). +/************************************************************************************/ +/* Structures needed to interface with the TIFF file creation library )and also + * structures used only internally by the TIFF file creation library). */ /* This structure describes on strip in tmpfile2 */ @@ -259,8 +251,8 @@ struct tiff_strip_s uint32_t count; /* Count of pixels in the strip */ }; -/* This structure is used only internally by the TIFF file creation library - * to manage file offsets. +/* This structure is used only internally by the TIFF file creation library to + * manage file offsets. */ struct tiff_filefmt_s @@ -292,8 +284,8 @@ struct tiff_info_s * * colorfmt - Specifies the form of the color data that will be provided * in the strip data. These are the FB_FMT_* definitions - * provided in include/nuttx/video/fb.h. Only the following - * values are supported: + * provided in include/nuttx/video/fb.h. Only the following values + * are supported: * * FB_FMT_Y1 BPP=1, monochrome, 0=black * FB_FMT_Y4 BPP=4, 4-bit greyscale, 0=black @@ -347,9 +339,9 @@ struct tiff_info_s FAR const struct tiff_filefmt_s *filefmt; }; -/**************************************************************************** +/************************************************************************************ * Public Function Prototypes - ****************************************************************************/ + ************************************************************************************/ #ifdef __cplusplus #define EXTERN extern "C" @@ -359,12 +351,12 @@ extern "C" #define EXTERN extern #endif -/**************************************************************************** +/************************************************************************************ * Name: tiff_initialize * * Description: - * Setup to create a new TIFF file. The overall steps to creating a - * TIFF file are as follows: + * Setup to create a new TIFF file. The overall steps to creating a TIFF file are + * as follows: * * 1) Create an initialize a struct tiff_info_s instance * 2) Call tiff_initialize() to setup the file creation @@ -372,76 +364,70 @@ extern "C" * 4) Call tiff_finalize() to complete the file creation. * * Input Parameters: - * info - A pointer to the caller allocated parameter passing/TIFF state - * instance. + * info - A pointer to the caller allocated parameter passing/TIFF state instance. * * Returned Value: * Zero (OK) on success. A negated errno value on failure. * - ****************************************************************************/ + ************************************************************************************/ int tiff_initialize(FAR struct tiff_info_s *info); -/**************************************************************************** +/************************************************************************************ * Name: tiff_addstrip * * Description: - * Add an image data strip. The size of the strip in pixels - * must be equal to the RowsPerStrip x ImageWidth values - * that were provided to tiff_initialize(). + * Add an image data strip. The size of the strip in pixels must be equal to + * the RowsPerStrip x ImageWidth values that were provided to tiff_initialize(). * * Input Parameters: - * info - A pointer to the caller allocated parameter passing/TIFF state - * instance. + * info - A pointer to the caller allocated parameter passing/TIFF state instance. * buffer - A buffer containing a single row of data. * * Returned Value: * Zero (OK) on success. A negated errno value on failure. * - ****************************************************************************/ + ************************************************************************************/ int tiff_addstrip(FAR struct tiff_info_s *info, FAR const uint8_t *strip); -/**************************************************************************** +/************************************************************************************ * Name: tiff_finalize * * Description: * Finalize the TIFF output file, completing the TIFF file creation steps. * * Input Parameters: - * info - A pointer to the caller allocated parameter passing/TIFF state - * instance. + * info - A pointer to the caller allocated parameter passing/TIFF state instance. * * Returned Value: * Zero (OK) on success. A negated errno value on failure. * - ****************************************************************************/ + ************************************************************************************/ int tiff_finalize(FAR struct tiff_info_s *info); -/**************************************************************************** +/************************************************************************************ * Name: tiff_abort * * Description: * Abort the TIFF file creation and create-up resources. * * Input Parameters: - * info - A pointer to the caller allocated parameter passing/TIFF state - * instance. + * info - A pointer to the caller allocated parameter passing/TIFF state instance. * * Returned Value: * None * - ****************************************************************************/ + ************************************************************************************/ void tiff_abort(FAR struct tiff_info_s *info); -/**************************************************************************** +/************************************************************************************ * Name: tiff_put/get16/32 * * Description: - * Put and get 16 and 32 values in the correct byte order at the specified - * position. + * Put and get 16 and 32 values in the correct byte order at the specified position. * * Input Parameters: * dest - The location to store the multi-byte data (put only) @@ -451,7 +437,7 @@ void tiff_abort(FAR struct tiff_info_s *info); * None (put) * The extracted value (get) * - ****************************************************************************/ + ************************************************************************************/ void tiff_put16(FAR uint8_t *dest, uint16_t value); void tiff_put32(FAR uint8_t *dest, uint32_t value); diff --git a/include/graphics/twm4nx/apps/calib_config.hxx b/include/graphics/twm4nx/apps/calib_config.hxx index ffcdfc6a7..d8d82eb9d 100644 --- a/include/graphics/twm4nx/apps/calib_config.hxx +++ b/include/graphics/twm4nx/apps/calib_config.hxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/include/graphics/twm4nx/apps/calib_config.hxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -28,7 +26,7 @@ ///////////////////////////////////////////////////////////////////////////// #include -#include +#include #include "graphics/nxwidgets/nxconfig.hxx" #include "graphics/twm4nx/twm4nx_config.hxx" @@ -116,7 +114,7 @@ #endif #ifndef CONFIG_TWM4NX_CALIBRATION_SIGNO -# define CONFIG_TWM4NX_CALIBRATION_SIGNO 32 +# define CONFIG_TWM4NX_CALIBRATION_SIGNO 5 #endif #ifndef CONFIG_TWM4NX_CALIBRATION_LISTENERPRIO diff --git a/include/graphics/twm4nx/apps/ccalibration.hxx b/include/graphics/twm4nx/apps/ccalibration.hxx index 39b60b0cf..9de0e8f21 100644 --- a/include/graphics/twm4nx/apps/ccalibration.hxx +++ b/include/graphics/twm4nx/apps/ccalibration.hxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/include/graphics/twm4nx/apps/ccalibration.hxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -148,6 +146,7 @@ namespace Twm4Nx struct nxgl_point_s m_touchPos; /**< This is the last touch position */ volatile uint8_t m_calthread; /**< Current calibration display state (See ECalibThreadState)*/ uint8_t m_calphase; /**< Current calibration display state (See ECalibrationPhase)*/ + bool m_stop; /**< True: We have been asked to stop the calibration */ bool m_touched; /**< True: The screen is touched */ struct STouchSample m_sample; /**< Catches new touch samples */ #ifdef CONFIG_TWM4NX_CALIBRATION_AVERAGE diff --git a/include/graphics/twm4nx/apps/cclock.hxx b/include/graphics/twm4nx/apps/cclock.hxx index 351381a69..c03de3336 100644 --- a/include/graphics/twm4nx/apps/cclock.hxx +++ b/include/graphics/twm4nx/apps/cclock.hxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/include/graphics/twm4nx/apps/cclock.hxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The diff --git a/include/graphics/twm4nx/apps/clock_config.hxx b/include/graphics/twm4nx/apps/clock_config.hxx index 2e2db213c..fa5584f1a 100644 --- a/include/graphics/twm4nx/apps/clock_config.hxx +++ b/include/graphics/twm4nx/apps/clock_config.hxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/include/graphics/twm4nx/apps/clock_config.hxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -28,7 +26,7 @@ ///////////////////////////////////////////////////////////////////////////// #include -#include +#include #include "graphics/nxglyphs.hxx" #include "graphics/nxwidgets/crlepalettebitmap.hxx" diff --git a/include/graphics/twm4nx/apps/cnxterm.hxx b/include/graphics/twm4nx/apps/cnxterm.hxx index e7bfcecc2..d697f72f9 100644 --- a/include/graphics/twm4nx/apps/cnxterm.hxx +++ b/include/graphics/twm4nx/apps/cnxterm.hxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/include/graphics/twm4nx/apps/cnxterm.hxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The diff --git a/include/graphics/twm4nx/apps/nxterm_config.hxx b/include/graphics/twm4nx/apps/nxterm_config.hxx index 2d0661e9e..88d4b10c8 100644 --- a/include/graphics/twm4nx/apps/nxterm_config.hxx +++ b/include/graphics/twm4nx/apps/nxterm_config.hxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/include/graphics/twm4nx/apps/nxterm_config.hxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -28,7 +26,7 @@ ///////////////////////////////////////////////////////////////////////////// #include -#include +#include #include "graphics/nxglyphs.hxx" #include "graphics/nxwidgets/crlepalettebitmap.hxx" diff --git a/include/graphics/twm4nx/cbackground.hxx b/include/graphics/twm4nx/cbackground.hxx index bca793029..75e985f4e 100644 --- a/include/graphics/twm4nx/cbackground.hxx +++ b/include/graphics/twm4nx/cbackground.hxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/include/graphics/twm4nx/cbackground.hxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The diff --git a/include/graphics/twm4nx/cfonts.hxx b/include/graphics/twm4nx/cfonts.hxx index 479eaa727..532e37b39 100644 --- a/include/graphics/twm4nx/cfonts.hxx +++ b/include/graphics/twm4nx/cfonts.hxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/include/graphics/twm4nx/cfonts.hxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The diff --git a/include/graphics/twm4nx/ciconmgr.hxx b/include/graphics/twm4nx/ciconmgr.hxx index 4b2104b07..82203b187 100644 --- a/include/graphics/twm4nx/ciconmgr.hxx +++ b/include/graphics/twm4nx/ciconmgr.hxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/include/graphics/twm4nx/ciconmgr.hxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -79,7 +77,7 @@ namespace Twm4Nx NXWidgets::CNxString m_name; /**< The Icon Manager name */ FAR struct SWindowEntry *m_head; /**< Head of the window list */ FAR struct SWindowEntry *m_tail; /**< Tail of the window list */ - FAR CWindow *m_window; /**< Parent window */ + FAR struct CWindow *m_window; /**< Parent window */ FAR NXWidgets::CButtonArray *m_buttons; /**< The contained button array */ uint16_t m_nWindows; /**< The number of windows in the icon mgr. */ uint8_t m_nColumns; /**< Fixed number of columns per row */ diff --git a/include/graphics/twm4nx/ciconwidget.hxx b/include/graphics/twm4nx/ciconwidget.hxx index e9152fc19..f76082869 100644 --- a/include/graphics/twm4nx/ciconwidget.hxx +++ b/include/graphics/twm4nx/ciconwidget.hxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/include/graphics/twm4nx/ciconwidget.hxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -32,7 +30,7 @@ #include #include #include -#include +#include #include #include diff --git a/include/graphics/twm4nx/cinput.hxx b/include/graphics/twm4nx/cinput.hxx index eb576dd55..c7ee7da6e 100644 --- a/include/graphics/twm4nx/cinput.hxx +++ b/include/graphics/twm4nx/cinput.hxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/include/graphics/twm4nx/cinput.hxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The diff --git a/include/graphics/twm4nx/cmainmenu.hxx b/include/graphics/twm4nx/cmainmenu.hxx index f88af86e1..6fe1f72da 100644 --- a/include/graphics/twm4nx/cmainmenu.hxx +++ b/include/graphics/twm4nx/cmainmenu.hxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/include/graphics/twm4nx/cmainmenu.hxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The diff --git a/include/graphics/twm4nx/cmenus.hxx b/include/graphics/twm4nx/cmenus.hxx index e7abee1ab..ecbda5907 100644 --- a/include/graphics/twm4nx/cmenus.hxx +++ b/include/graphics/twm4nx/cmenus.hxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/include/graphics/twm4nx/Cmenus.hxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The diff --git a/include/graphics/twm4nx/cresize.hxx b/include/graphics/twm4nx/cresize.hxx index 0c6a52733..fd4b503b1 100644 --- a/include/graphics/twm4nx/cresize.hxx +++ b/include/graphics/twm4nx/cresize.hxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/include/graphics/twm4nx/cresize.hxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The diff --git a/include/graphics/twm4nx/ctwm4nx.hxx b/include/graphics/twm4nx/ctwm4nx.hxx index 655bb9214..8f3cc5b42 100644 --- a/include/graphics/twm4nx/ctwm4nx.hxx +++ b/include/graphics/twm4nx/ctwm4nx.hxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/include/graphics/twm4nx/ctwm4nx.hxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The diff --git a/include/graphics/twm4nx/ctwm4nxevent.hxx b/include/graphics/twm4nx/ctwm4nxevent.hxx index 8d0d3b9cc..fef008216 100644 --- a/include/graphics/twm4nx/ctwm4nxevent.hxx +++ b/include/graphics/twm4nx/ctwm4nxevent.hxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/include/graphics/twm4nx/ctwmnxevent.hxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The diff --git a/include/graphics/twm4nx/cwindow.hxx b/include/graphics/twm4nx/cwindow.hxx index 2b0508593..c85f6bbc4 100644 --- a/include/graphics/twm4nx/cwindow.hxx +++ b/include/graphics/twm4nx/cwindow.hxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/include/graphics/twm4nx/cwindow.hxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -144,6 +142,7 @@ namespace Twm4Nx NXWidgets::CNxString m_name; /**< Name of the window */ FAR NXWidgets::CNxTkWindow *m_nxWin; /**< The contained NX primary window */ FAR CWindowEvent *m_windowEvent; /**< Cached window event reference */ + FAR void *m_eventObj; /**< Object reference that accompanies events */ nxgl_coord_t m_minWidth; /**< The minimum width of the window */ struct SAppEvents m_appEvents; /**< Application event information */ bool m_modal; /**< Window is in modal state */ diff --git a/include/graphics/twm4nx/cwindowevent.hxx b/include/graphics/twm4nx/cwindowevent.hxx index 86755790b..f0e2c09a0 100644 --- a/include/graphics/twm4nx/cwindowevent.hxx +++ b/include/graphics/twm4nx/cwindowevent.hxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/graphics/twm4nx/src/cwindowevent.hxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -217,7 +215,8 @@ namespace Twm4Nx CWindowEvent(FAR CTwm4Nx *twm4nx, FAR void *client, FAR const struct SAppEvents &events, - FAR const NXWidgets::CWidgetStyle *style = NULL); + FAR const NXWidgets::CWidgetStyle *style = + (const NXWidgets::CWidgetStyle *)NULL); /** * CWindowEvent Destructor. diff --git a/include/graphics/twm4nx/cwindowfactory.hxx b/include/graphics/twm4nx/cwindowfactory.hxx index c59fe710f..1ae7be4eb 100644 --- a/include/graphics/twm4nx/cwindowfactory.hxx +++ b/include/graphics/twm4nx/cwindowfactory.hxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/include/graphics/twm4nx/cwindowfactory.hxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The diff --git a/include/graphics/twm4nx/iapplication.hxx b/include/graphics/twm4nx/iapplication.hxx index 5a71013bd..b3962e0cb 100644 --- a/include/graphics/twm4nx/iapplication.hxx +++ b/include/graphics/twm4nx/iapplication.hxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/include/graphics/twm4nx/iapplication.hxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The diff --git a/include/graphics/twm4nx/twm4nx_config.hxx b/include/graphics/twm4nx/twm4nx_config.hxx index 60b34d09d..7d113e68d 100644 --- a/include/graphics/twm4nx/twm4nx_config.hxx +++ b/include/graphics/twm4nx/twm4nx_config.hxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/include/graphics/twm4nx/twm4nx_config.hxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The @@ -28,7 +26,7 @@ ///////////////////////////////////////////////////////////////////////////// #include -#include +#include #include "graphics/nxglyphs.hxx" #include "graphics/nxwidgets/nxconfig.hxx" @@ -450,7 +448,7 @@ */ #ifndef CONFIG_TWM4NX_INPUT_SIGNO -# define CONFIG_TWM4NX_INPUT_SIGNO 33 +# define CONFIG_TWM4NX_INPUT_SIGNO 6 #endif #ifndef CONFIG_TWM4NX_INPUT_LISTENERPRIO diff --git a/include/graphics/twm4nx/twm4nx_cursor.hxx b/include/graphics/twm4nx/twm4nx_cursor.hxx index f6761e342..9f86a5b0a 100644 --- a/include/graphics/twm4nx/twm4nx_cursor.hxx +++ b/include/graphics/twm4nx/twm4nx_cursor.hxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/include/graphics/twm4nx/twm4nx_cursor.hxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The diff --git a/include/graphics/twm4nx/twm4nx_events.hxx b/include/graphics/twm4nx/twm4nx_events.hxx index 64a2ea5da..9058d40ec 100644 --- a/include/graphics/twm4nx/twm4nx_events.hxx +++ b/include/graphics/twm4nx/twm4nx_events.hxx @@ -1,8 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // apps/include/graphics/twm4nx/twm4nx_events.hxx // -// SPDX-License-Identifier: Apache-2.0 -// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. The diff --git a/include/industry/abnt_codi.h b/include/industry/abnt_codi.h index e1dbeb494..c84aee45f 100644 --- a/include/industry/abnt_codi.h +++ b/include/industry/abnt_codi.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/industry/abnt_codi.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -104,8 +102,7 @@ uint8_t abnt_codi_checksum(FAR const uint8_t *data); /* Parse a specific ABNT CODI sequence. */ -bool abnt_codi_parse(FAR const uint8_t *data, - FAR struct abnt_codi_proto_s *proto); +bool abnt_codi_parse(FAR const uint8_t *data, FAR struct abnt_codi_proto_s *proto); #ifdef __cplusplus } diff --git a/include/industry/foc/fixed16/foc_align.h b/include/industry/foc/fixed16/foc_align.h index 9a840799b..27403df57 100644 --- a/include/industry/foc/fixed16/foc_align.h +++ b/include/industry/foc/fixed16/foc_align.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/industry/foc/fixed16/foc_align.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/industry/foc/fixed16/foc_angle.h b/include/industry/foc/fixed16/foc_angle.h index 1834ec6f8..ba6cd22ff 100644 --- a/include/industry/foc/fixed16/foc_angle.h +++ b/include/industry/foc/fixed16/foc_angle.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/industry/foc/fixed16/foc_angle.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/industry/foc/fixed16/foc_cordic.h b/include/industry/foc/fixed16/foc_cordic.h index 94bd09564..81dd52ddc 100644 --- a/include/industry/foc/fixed16/foc_cordic.h +++ b/include/industry/foc/fixed16/foc_cordic.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/industry/foc/fixed16/foc_cordic.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/industry/foc/fixed16/foc_feedforward.h b/include/industry/foc/fixed16/foc_feedforward.h deleted file mode 100644 index f84430ca4..000000000 --- a/include/industry/foc/fixed16/foc_feedforward.h +++ /dev/null @@ -1,47 +0,0 @@ -/**************************************************************************** - * apps/include/industry/foc/fixed16/foc_feedforward.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __INDUSTRY_FOC_FIXED16_FOC_FEEDFORWARD_H -#define __INDUSTRY_FOC_FIXED16_FOC_FEEDFORWARD_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include - -/**************************************************************************** - * Public Type Definition - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -int foc_feedforward_pmsm_b16(FAR struct motor_phy_params_b16_s *phy, - FAR dq_frame_b16_t *idq, - b16_t vel_now, - FAR dq_frame_b16_t *vdq_comp); - -#endif /* __INDUSTRY_FOC_FIXED16_FOC_FEEDFORWARD_H */ diff --git a/include/industry/foc/fixed16/foc_handler.h b/include/industry/foc/fixed16/foc_handler.h index 718713fc1..793aeafa8 100644 --- a/include/industry/foc/fixed16/foc_handler.h +++ b/include/industry/foc/fixed16/foc_handler.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/industry/foc/fixed16/foc_handler.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -106,11 +104,6 @@ struct foc_modulation_ops_b16_s CODE void (*run)(FAR foc_handler_b16_t *h, FAR ab_frame_b16_t *v_ab_mod, FAR b16_t *duty); - - /* Get modulation state */ - - CODE void (*state_get)(FAR foc_handler_b16_t *h, - FAR void *state); }; /* Current/voltage controller operations */ @@ -242,8 +235,7 @@ void foc_handler_cfg_b16(FAR foc_handler_b16_t *h, ****************************************************************************/ void foc_handler_state_b16(FAR foc_handler_b16_t *h, - FAR struct foc_state_b16_s *state, - FAR void *mod_state); + FAR struct foc_state_b16_s *state); #ifdef CONFIG_INDUSTRY_FOC_HANDLER_PRINT /**************************************************************************** diff --git a/include/industry/foc/fixed16/foc_ident.h b/include/industry/foc/fixed16/foc_ident.h index 74e97f081..276fa631e 100644 --- a/include/industry/foc/fixed16/foc_ident.h +++ b/include/industry/foc/fixed16/foc_ident.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/industry/foc/fixed16/foc_ident.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -43,7 +41,6 @@ struct foc_routine_ident_cfg_b16_s { b16_t per; /* Routine period in sec */ b16_t res_current; /* Resistance measurement current */ - b16_t res_ki; /* Resistance measurement Ki */ b16_t ind_volt; /* Inductance measurement current */ int res_steps; /* Resistance measurement steps */ int ind_steps; /* Inductance measurement steps */ diff --git a/include/industry/foc/fixed16/foc_model.h b/include/industry/foc/fixed16/foc_model.h index 7afe2129c..ce0c8c8e4 100644 --- a/include/industry/foc/fixed16/foc_model.h +++ b/include/industry/foc/fixed16/foc_model.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/industry/foc/fixed16/foc_model.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/industry/foc/fixed16/foc_ramp.h b/include/industry/foc/fixed16/foc_ramp.h index 5577f427a..1c2a1547a 100644 --- a/include/industry/foc/fixed16/foc_ramp.h +++ b/include/industry/foc/fixed16/foc_ramp.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/industry/foc/fixed16/foc_ramp.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/industry/foc/fixed16/foc_routine.h b/include/industry/foc/fixed16/foc_routine.h index 8dae9639b..320d8a8f0 100644 --- a/include/industry/foc/fixed16/foc_routine.h +++ b/include/industry/foc/fixed16/foc_routine.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/industry/foc/fixed16/foc_routine.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/industry/foc/fixed16/foc_velocity.h b/include/industry/foc/fixed16/foc_velocity.h index eef5c73ce..14119e968 100644 --- a/include/industry/foc/fixed16/foc_velocity.h +++ b/include/industry/foc/fixed16/foc_velocity.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/industry/foc/fixed16/foc_velocity.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/industry/foc/float/foc_align.h b/include/industry/foc/float/foc_align.h index 31bce11c8..f0e3035eb 100644 --- a/include/industry/foc/float/foc_align.h +++ b/include/industry/foc/float/foc_align.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/industry/foc/float/foc_align.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/industry/foc/float/foc_angle.h b/include/industry/foc/float/foc_angle.h index 420098463..b258b46b8 100644 --- a/include/industry/foc/float/foc_angle.h +++ b/include/industry/foc/float/foc_angle.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/industry/foc/float/foc_angle.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/industry/foc/float/foc_cordic.h b/include/industry/foc/float/foc_cordic.h index 77620d653..f68fbec9b 100644 --- a/include/industry/foc/float/foc_cordic.h +++ b/include/industry/foc/float/foc_cordic.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/industry/foc/float/foc_cordic.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/industry/foc/float/foc_feedforward.h b/include/industry/foc/float/foc_feedforward.h deleted file mode 100644 index 96b33dbf8..000000000 --- a/include/industry/foc/float/foc_feedforward.h +++ /dev/null @@ -1,47 +0,0 @@ -/**************************************************************************** - * apps/include/industry/foc/float/foc_feedforward.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __INDUSTRY_FOC_FLOAT_FOC_FEEDFORWARD_H -#define __INDUSTRY_FOC_FLOAT_FOC_FEEDFORWARD_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include - -/**************************************************************************** - * Public Type Definition - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -int foc_feedforward_pmsm_f32(FAR struct motor_phy_params_f32_s *phy, - FAR dq_frame_f32_t *idq, - float vel_now, - FAR dq_frame_f32_t *vdq_comp); - -#endif /* __INDUSTRY_FOC_FLOAT_FOC_FEEDFORWARD_H */ diff --git a/include/industry/foc/float/foc_handler.h b/include/industry/foc/float/foc_handler.h index 09e38e98a..ada230692 100644 --- a/include/industry/foc/float/foc_handler.h +++ b/include/industry/foc/float/foc_handler.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/industry/foc/float/foc_handler.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -106,11 +104,6 @@ struct foc_modulation_ops_f32_s CODE void (*run)(FAR foc_handler_f32_t *h, FAR ab_frame_f32_t *v_ab_mod, FAR float *duty); - - /* Get modulation state */ - - CODE void (*state_get)(FAR foc_handler_f32_t *h, - FAR void *state); }; /* Current/voltage controller operations */ @@ -243,8 +236,7 @@ void foc_handler_cfg_f32(FAR foc_handler_f32_t *h, ****************************************************************************/ void foc_handler_state_f32(FAR foc_handler_f32_t *h, - FAR struct foc_state_f32_s *state, - FAR void *mod_state); + FAR struct foc_state_f32_s *state); #ifdef CONFIG_INDUSTRY_FOC_HANDLER_PRINT /**************************************************************************** diff --git a/include/industry/foc/float/foc_ident.h b/include/industry/foc/float/foc_ident.h index fcbb94b6d..d7172f89a 100644 --- a/include/industry/foc/float/foc_ident.h +++ b/include/industry/foc/float/foc_ident.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/industry/foc/float/foc_ident.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -37,56 +35,13 @@ * Public Type Definition ****************************************************************************/ -#ifdef CONFIG_INDUSTRY_FOC_IDENT_FLUX -/* Identification routine callbacks */ - -struct foc_routine_ident_cb_f32_s -{ - /* Private data for angle callbacks */ - - FAR void *priv_angle; - - /* Private data for speed callbacks */ - - FAR void *priv_speed; - - /* Private data for kpki callbacks */ - - FAR void *priv_kpki; - - /* Openloop angle zero callback */ - - CODE int (*zero)(FAR void *priv); - - /* Identification openloop angle callback */ - - CODE float (*angle)(FAR void *priv, float speed, float dir); - - /* Identification openloop speed callback */ - - CODE float (*speed)(FAR void *priv, float des, float now); - - /* Identification calculate kp and ki callback */ - - CODE int (*kpki)(FAR void *priv, float res, float ind, float per); -}; -#endif - /* Identification routine configuration */ struct foc_routine_ident_cfg_f32_s { -#ifdef CONFIG_INDUSTRY_FOC_IDENT_FLUX - struct foc_routine_ident_cb_f32_s cb; /* Identification routine callbacks */ - - float flux_vel; /* Flux linkage measurement velocity */ - float flux_curr; /* Flux linkage measurement current */ - int flux_steps; /* Flux linkage measurement steps */ -#endif float per; /* Routine period in sec */ float res_current; /* Resistance measurement current */ - float res_ki; /* Resistance measurement Ki */ - float ind_volt; /* Inductance measurement voltage */ + float ind_volt; /* Inductance measurement current */ int res_steps; /* Resistance measurement steps */ int ind_steps; /* Inductance measurement steps */ int idle_steps; /* IDLE steps */ @@ -99,9 +54,6 @@ struct foc_routine_ident_final_f32_s bool ready; /* Result ready */ float res; /* Phase resistance */ float ind; /* Phase inductance */ -#ifdef CONFIG_INDUSTRY_FOC_IDENT_FLUX - float flux; /* Motor flux linkage */ -#endif }; /**************************************************************************** diff --git a/include/industry/foc/float/foc_model.h b/include/industry/foc/float/foc_model.h index 95a7ed1b3..da26eec0c 100644 --- a/include/industry/foc/float/foc_model.h +++ b/include/industry/foc/float/foc_model.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/industry/foc/float/foc_model.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/industry/foc/float/foc_ramp.h b/include/industry/foc/float/foc_ramp.h index ca41eef37..ea75700b0 100644 --- a/include/industry/foc/float/foc_ramp.h +++ b/include/industry/foc/float/foc_ramp.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/industry/foc/float/foc_ramp.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/industry/foc/float/foc_routine.h b/include/industry/foc/float/foc_routine.h index bcfe3e1b9..fc3d68640 100644 --- a/include/industry/foc/float/foc_routine.h +++ b/include/industry/foc/float/foc_routine.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/industry/foc/float/foc_routine.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/industry/foc/float/foc_velocity.h b/include/industry/foc/float/foc_velocity.h index 309a4512a..971a9e9ab 100644 --- a/include/industry/foc/float/foc_velocity.h +++ b/include/industry/foc/float/foc_velocity.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/industry/foc/float/foc_velocity.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/industry/foc/foc_common.h b/include/industry/foc/foc_common.h index 6993a6a37..fa50f5dab 100644 --- a/include/industry/foc/foc_common.h +++ b/include/industry/foc/foc_common.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/industry/foc/foc_common.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -82,15 +80,6 @@ enum foc_angle_type_e FOC_ANGLE_TYPE_MECH = 2, /* Mechanical angle */ }; -/* Open-loop stage */ - -enum foc_openloop_stage_e -{ - FOC_OPENLOOP_ENABLED = 1, /* Open-loop enabled */ - FOC_OPENLOOP_TRANSITION = 2, /* Open-loop to closed-loop transition */ - FOC_OPENLOOP_DISABLED = 3, /* Open-loop disabled */ -}; - /**************************************************************************** * Public Function Prototypes ****************************************************************************/ diff --git a/include/industry/foc/foc_log.h b/include/industry/foc/foc_log.h index 62a9950bb..0634d4924 100644 --- a/include/industry/foc/foc_log.h +++ b/include/industry/foc/foc_log.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/industry/foc/foc_log.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -37,22 +35,8 @@ * Pre-processor Definitions ****************************************************************************/ -#ifdef CONFIG_INDUSTRY_FOC_DEBUG -# define FOCLIBLOG(format, ...) printf(format, ##__VA_ARGS__) -#else -# define FOCLIBLOG(format, ...) -#endif - -#ifdef CONFIG_INDUSTRY_FOC_ERROR -# define FOCLIBERR(format, ...) printf(format, ##__VA_ARGS__) -#else -# define FOCLIBERR(format, ...) -#endif - -#ifdef CONFIG_INDUSTRY_FOC_WARN -# define FOCLIBWARN(format, ...) printf(format, ##__VA_ARGS__) -#else -# define FOCLIBWARN(format, ...) -#endif +#define FOCLIBLOG(format, ...) printf(format, ##__VA_ARGS__) +#define FOCLIBERR(format, ...) printf(format, ##__VA_ARGS__) +#define FOCLIBWARN(format, ...) printf(format, ##__VA_ARGS__) #endif /* __APPS_INCLUDE_INDUSTRY_FOC_FOC_LOG_H */ diff --git a/include/industry/foc/foc_utils.h b/include/industry/foc/foc_utils.h index b76931846..65406ce7d 100644 --- a/include/industry/foc/foc_utils.h +++ b/include/industry/foc/foc_utils.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/industry/foc/foc_utils.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/interpreters/minibasic.h b/include/interpreters/minibasic.h index b315445b0..083911c14 100644 --- a/include/interpreters/minibasic.h +++ b/include/interpreters/minibasic.h @@ -1,30 +1,41 @@ /**************************************************************************** - * apps/include/interpreters/minibasic.h + * apps/interpreters/minibasic/basic.c * - * SPDX-License-Identifier: Apache-2.0 + * Copyright (C) 2016 Gregory Nutt. All rights reserved. * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/* This file was taken from Mini Basic, versino 1.0 developed by Malcolm + * This file was taken from Mini Basic, versino 1.0 developed by Malcolm * McLean, Leeds University. Mini Basic version 1.0 was released the * Creative Commons Attribution license which, from my reading, appears to * be compatible with the NuttX BSD-style license: - */ + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ #ifndef __APPS_INCLUDE_INTERPRETERS_MINIBASIC_H #define __APPS_INCLUDE_INTERPRETERS_MINIBASIC_H diff --git a/include/logging/nxscope/nxscope.h b/include/logging/nxscope/nxscope.h deleted file mode 100644 index 79d8c59fc..000000000 --- a/include/logging/nxscope/nxscope.h +++ /dev/null @@ -1,504 +0,0 @@ -/**************************************************************************** - * apps/include/logging/nxscope/nxscope.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __APPS_INCLUDE_LOGGING_NXSCOPE_NXSCOPE_H -#define __APPS_INCLUDE_LOGGING_NXSCOPE_NXSCOPE_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -#include -#include - -#include -#include -#include - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define NXSCOPE_ENABLE_LEN (sizeof(struct nxscope_enable_data_s)) -#define NXSCOPE_DIV_LEN (sizeof(struct nxscope_div_data_s)) -#define NXSCOPE_START_LEN (sizeof(struct nxscope_start_data_s)) - -/* MSB bit in the channel type means a critical channel */ - -#define NXSCOPE_IS_CRICHAN(chtype) (chtype & 0x80) - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -#ifdef __cplusplus -#define EXTERN extern "C" -extern "C" -{ -#else -#define EXTERN extern -#endif - -/* Nxscope header ID */ - -enum nxscope_hdr_id_e -{ - NXSCOPE_HDRID_UNDEF = 0, /* Reserved */ - - /* Stream frames */ - - NXSCOPE_HDRID_STREAM = 1, /* Stream data */ - - /* Get frames */ - - NXSCOPE_HDRID_CMNINFO = 2, /* Get nxscope common info */ - NXSCOPE_HDRID_CHINFO = 3, /* Get nxscope channel info */ - - /* Special frames */ - - NXSCOPE_HDRID_ACK = 4, /* ACK/NACK */ - - /* Set frames. - * - * If CONFIG_LOGGING_NXSCOPE_ACKFRAMES=y this requests must - * be confirmed with ACK frames to report success or failure. - */ - - NXSCOPE_HDRID_START = 5, /* Start/stop stream. - * NOTE: this frame do not follow - * 'struct nxscope_set_frame_s' format - */ - NXSCOPE_HDRID_ENABLE = 6, /* Snable/disable channels */ - NXSCOPE_HDRID_DIV = 7, /* Channels divider */ - - /* User defined frames. - * Must be alway the last element. - */ - - NXSCOPE_HDRID_USER = 8 -}; - -/* Nxscope flags */ - -enum nxscope_info_flags_e -{ - NXSCOPE_FLAGS_DIVIDER_SUPPORT = (1 << 0), - NXSCOPE_FLAGS_ACK_SUPPORT = (1 << 1), - NXSCOPE_FLAGS_RES2 = (1 << 2), - NXSCOPE_FLAGS_RES3 = (1 << 3), - NXSCOPE_FLAGS_RES4 = (1 << 4), - NXSCOPE_FLAGS_RES5 = (1 << 5), - NXSCOPE_FLAGS_RES6 = (1 << 6), - NXSCOPE_FLAGS_RES7 = (1 << 7), -}; - -/* Nxscope stream flags */ - -enum nxscope_stream_flags_s -{ - NXSCOPE_STREAM_FLAGS_OVERFLOW = (1 << 0) -}; - -/* Nxscope start frame data */ - -begin_packed_struct struct nxscope_start_data_s -{ - uint8_t start; /* Start/stop flag */ -} end_packed_struct; - -/* Nxscope enable channel data */ - -begin_packed_struct struct nxscope_enable_ch_data_s -{ - uint8_t en; /* Channel enable */ -} end_packed_struct; - -/* Nxscope divider channel data */ - -begin_packed_struct struct nxscope_div_ch_data_s -{ - uint8_t div; /* Channel divider - starts from 0 */ -} end_packed_struct; - -/* Nxscope enable frame data */ - -begin_packed_struct struct nxscope_enable_data_s -{ - struct nxscope_enable_ch_data_s ch[1]; /* Chmax elements */ -} end_packed_struct; - -/* Nxscope divider frame data */ - -begin_packed_struct struct nxscope_div_data_s -{ - struct nxscope_div_ch_data_s ch[1]; /* Chmax elements */ -} end_packed_struct; - -/* Set channel frame */ - -enum nxscope_set_frame_req_s -{ - NXSCOPE_SET_REQ_SINGLE = 0, /* Single channel request */ - NXSCOPE_SET_REQ_BULK = 1, /* Set different values for all channels */ - NXSCOPE_SET_REQ_ALL = 2 /* Set one value for all channles */ -}; - -/* Set frame common data */ - -begin_packed_struct struct nxscope_set_frame_s -{ - uint8_t req; /* Request type */ - uint8_t chan; /* Channel id */ - uint8_t data[1]; /* n bytes data - depends on the request type */ -} end_packed_struct; - -/* Chanel type */ - -begin_packed_struct struct nxscope_chinfo_type_s -{ - uint8_t dtype:5; /* Data type */ - uint8_t _res:2; /* Reserved for future use */ - uint8_t cri:1; /* Criticial channel - no buffering */ -} end_packed_struct; - -/* Chanel type union */ - -union nxscope_chinfo_type_u -{ - struct nxscope_chinfo_type_s s; - uint8_t u8; -}; - -/* Nxscope channel info */ - -begin_packed_struct struct nxscope_chinfo_s -{ - uint8_t enable; /* Enable flag */ - union nxscope_chinfo_type_u type; /* Channel data type */ - uint8_t vdim; /* Vector dimention */ - uint8_t div; /* Divider - starts from 0 */ - uint8_t mlen; /* Metadata size */ - FAR char *name; /* Chanel name */ -} end_packed_struct; - -/* Nxscope info common */ - -begin_packed_struct struct nxscope_info_cmn_s -{ - uint8_t chmax; /* Supported channels */ - uint8_t flags; /* Flags (enum nxscope_info_flags_e) */ - uint8_t rx_padding; /* RX padding (>0 if used) */ -} end_packed_struct; - -/* Nxscope sample hdr: - * - * +----------+-------------+----------+ - * | channel | sample data | metadata | - * +----------+-------------+----------+ - * | 1B | n bytes [1] | m bytes | - * +----------+-------------+----------+ - * - * [1] - sizeof(channel_type) * channel_vdim - * NOTE: sample data always little-endian ! - * - */ - -struct nxscope_sample_s -{ - uint8_t chan; /* 1 byte: Channel id - starts from 0 */ - /* n bytes: Data */ - /* m bytes: Metadata */ -}; - -/* Nxscope stream data: - * - * +----------+--------------+ - * | flags | samples data | - * +----------+--------------+ - * | 1B | n bytes | - * +----------+--------------+ - * - */ - -struct nxscope_stream_s -{ - uint8_t flags; /* stream flags */ - struct nxscope_sample_s samples[1]; /* stream samples */ -}; - -/* Nxscope callbacks */ - -struct nxscope_callbacks_s -{ - /* User-defined id callback */ - - FAR void *userid_priv; - CODE int (*userid)(FAR void *priv, uint8_t id, FAR uint8_t *buff); - - /* Start request callback */ - - FAR void *start_priv; - CODE int (*start)(FAR void *priv, bool start); -}; - -/* Nxscope general configuration */ - -struct nxscope_cfg_s -{ - /* NOTE: It is possible to configure separate interface - * and protocol for control commands and data stream. - */ - - /* Interface implementation for commands */ - - FAR struct nxscope_intf_s *intf_cmd; - - /* Interface implementation for stream data */ - - FAR struct nxscope_intf_s *intf_stream; - - /* Protocol implementation for commands */ - - FAR struct nxscope_proto_s *proto_cmd; - - /* Protocol implementation for stream data */ - - FAR struct nxscope_proto_s *proto_stream; - - /* Callbacks */ - - FAR struct nxscope_callbacks_s *callbacks; - - /* Number of suppoted channels */ - - uint8_t channels; - - /* Stream buffer len */ - - size_t streambuf_len; - - /* RX buffer len */ - - size_t rxbuf_len; - -#ifdef CONFIG_LOGGING_NXSCOPE_CRICHANNELS - /* Critical buffer len. - * - * It's the user's responsibility to correctly choose this value. - * The minimal buffer size for critical channels can be calculate - * with this formula: - * buff_size = max(proto_stream->hdrlen + 1 + type_size * vdim + - * meta_len + proto_stream->footlen) - * - * where max() means the maximum value from all initialized critical - * channels. - * - * When CONFIG_DEBUG_FEATURES is enabled the correct buffer size is - * verified in run-time. - */ - - size_t cribuf_len; -#endif - - /* RX padding. - * - * This option will be provided for client in common info data - * and can be useful if we use DMA for receiving frames - */ - - uint8_t rx_padding; -}; - -/* Nxscope data */ - -struct nxscope_s -{ - /* Nxscope interface handlers */ - - FAR struct nxscope_intf_s *intf_cmd; - FAR struct nxscope_intf_s *intf_stream; - - /* Nxscope protocol handlers */ - - FAR struct nxscope_proto_s *proto_cmd; - FAR struct nxscope_proto_s *proto_stream; - - /* Callbacks */ - - FAR struct nxscope_callbacks_s *callbacks; - - /* Nxscope common info */ - - struct nxscope_info_cmn_s cmninfo; - - /* Channels info, chmax elements */ - - FAR struct nxscope_chinfo_s *chinfo; - size_t chinfo_size; - - /* Nxscope data */ - -#ifdef CONFIG_LOGGING_NXSCOPE_DIVIDER - FAR uint32_t *cntr; -#endif - uint8_t start; - - /* Stream data */ - - FAR uint8_t *streambuf; - size_t streambuf_len; - size_t stream_i; - bool stream_retry; - -#ifdef CONFIG_LOGGING_NXSCOPE_CRICHANNELS - /* Critical buffer data */ - - FAR uint8_t *cribuf; - size_t cribuf_len; -#endif - - /* RX data buffer */ - - FAR uint8_t *rxbuf; - size_t rxbuf_len; - size_t rxbuf_i; - - /* TX data buffer */ - - FAR uint8_t *txbuf; - size_t txbuf_len; - - /* Exclusive access */ - - pthread_mutex_t lock; -}; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Name: nxscope_init - * - * Description: - * Initialize a nxscope instance - * - * Input Parameters: - * s - a pointer to a nxscope instance - * cfg - a pointer to a nxscope configuration data - * - ****************************************************************************/ - -int nxscope_init(FAR struct nxscope_s *s, FAR struct nxscope_cfg_s *cfg); - -/**************************************************************************** - * Name: nxscope_deinit - * - * Description: - * De-initialize a nxscope instance - * - * Input Parameters: - * s - a pointer to a nxscope instance - * - ****************************************************************************/ - -void nxscope_deinit(FAR struct nxscope_s *s); - -/**************************************************************************** - * Name: nxscope_lock - * - * Description: - * Lock a nxscope instance - * - * Input Parameters: - * s - a pointer to a nxscope instance - * - ****************************************************************************/ - -void nxscope_lock(FAR struct nxscope_s *s); - -/**************************************************************************** - * Name: nxscope_unlock - * - * Description: - * Unlock a nxscope instance - * - * Input Parameters: - * s - a pointer to a nxscope instance - * - ****************************************************************************/ - -void nxscope_unlock(FAR struct nxscope_s *s); - -/**************************************************************************** - * Name: nxscope_stream - * - * Description: - * Send nxscope stream data. - * - * NOTE: It's the user's responsibility to periodically call this function. - * - * Input Parameters: - * s - a pointer to a nxscope instance - * - ****************************************************************************/ - -int nxscope_stream(FAR struct nxscope_s *s); - -/**************************************************************************** - * Name: nxscope_recv - * - * Description: - * Receive and handle nxscope protocol data. - * - * NOTE: It's the user's responsibility to periodically call this function. - * - * Input Parameters: - * s - a pointer to a nxscope instance - * - ****************************************************************************/ - -int nxscope_recv(FAR struct nxscope_s *s); - -/**************************************************************************** - * Name: nxscope_stream_start - * - * Description: - * Start/stop data stream - * - * Input Parameters: - * s - a pointer to a nxscope instance - * start - start/stop - * - ****************************************************************************/ - -int nxscope_stream_start(FAR struct nxscope_s *s, bool start); - -#undef EXTERN -#ifdef __cplusplus -} -#endif - -#endif /* __APPS_INCLUDE_LOGGING_NXSCOPE_NXSCOPE_H */ diff --git a/include/logging/nxscope/nxscope_chan.h b/include/logging/nxscope/nxscope_chan.h deleted file mode 100644 index 8c7fb9087..000000000 --- a/include/logging/nxscope/nxscope_chan.h +++ /dev/null @@ -1,414 +0,0 @@ -/**************************************************************************** - * apps/include/logging/nxscope/nxscope_chan.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __APPS_INCLUDE_LOGGING_NXSCOPE_NXSCOPE_CHAN_H -#define __APPS_INCLUDE_LOGGING_NXSCOPE_NXSCOPE_CHAN_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -#ifdef __cplusplus -#define EXTERN extern "C" -extern "C" -{ -#else -#define EXTERN extern -#endif - -/* Nxscope sample type */ - -enum nxscope_sample_dtype_e -{ - /* Default numerical types */ - - NXSCOPE_TYPE_UNDEF = 0, - NXSCOPE_TYPE_NONE = 1, - NXSCOPE_TYPE_UINT8 = 2, - NXSCOPE_TYPE_INT8 = 3, - NXSCOPE_TYPE_UINT16 = 4, - NXSCOPE_TYPE_INT16 = 5, - NXSCOPE_TYPE_UINT32 = 6, - NXSCOPE_TYPE_INT32 = 7, - NXSCOPE_TYPE_UINT64 = 8, - NXSCOPE_TYPE_INT64 = 9, - NXSCOPE_TYPE_FLOAT = 10, - NXSCOPE_TYPE_DOUBLE = 11, - NXSCOPE_TYPE_UB8 = 12, - NXSCOPE_TYPE_B8 = 13, - NXSCOPE_TYPE_UB16 = 14, - NXSCOPE_TYPE_B16 = 15, - NXSCOPE_TYPE_UB32 = 16, - NXSCOPE_TYPE_B32 = 17, - - /* Char/string data */ - - NXSCOPE_TYPE_CHAR = 18, - -#if 0 - /* Reserved for future use */ - - NXSCOPE_TYPE_WCHAR = 19, -#endif - -#ifdef CONFIG_LOGGING_NXSCOPE_USERTYPES - /* User defined types starts from here. - * NXSCOPE_TYPE_USER must be always the last element. - * - * Type of size 1B. Together with channel.vdim this - * can be used to send custom protocol data. - */ - - NXSCOPE_TYPE_USER = 20, -#endif - - /* 5 bits reserved for data type */ - - NXSCOPE_TYPE_LAST = 31, -}; - -/* Forward declaration */ - -struct nxscope_s; - -/**************************************************************************** - * Public Function Puttypes - ****************************************************************************/ - -/**************************************************************************** - * Name: nxscope_chan_init - * - * Description: - * Initialize nxscope channel - * - * Input Parameters: - * s - a pointer to a nxscope instance - * ch - a channel id - * name - a channel name - * type - a channel data type (union nxscope_chinfo_type_u) - * vdim - a vector data dimension (vdim=1 for a point) - * mlen - a length of metadata - * - ****************************************************************************/ - -int nxscope_chan_init(FAR struct nxscope_s *s, uint8_t ch, - FAR char *name, uint8_t type, uint8_t vdim, - uint8_t mlen); - -/**************************************************************************** - * Name: nxscope_chan_en - * - * Description: - * Enable/disable a given channel - * - * Input Parameters: - * s - a pointer to a nxscope instance - * ch - a channel id - * en - enable/disable - * - ****************************************************************************/ - -int nxscope_chan_en(FAR struct nxscope_s *s, uint8_t chan, bool en); - -#ifdef CONFIG_LOGGING_NXSCOPE_DIVIDER -/**************************************************************************** - * Name: nxscope_chan_div - * - * Description: - * Configure divider for a given channel - * - * Input Parameters: - * s - a pointer to a nxscope instance - * ch - a channel id - * div - divider value - starts from 0 - * - ****************************************************************************/ - -int nxscope_chan_div(FAR struct nxscope_s *s, uint8_t chan, uint8_t div); -#endif - -/**************************************************************************** - * Name: nxscope_chan_all_en - * - * Description: - * Enable/disable all channels - * - * Input Parameters: - * s - a pointer to a nxscope instance - * en - enable/disable - * - ****************************************************************************/ - -int nxscope_chan_all_en(FAR struct nxscope_s *s, bool en); - -/**************************************************************************** - * Name: nxscope_put_vXXXX_m - * - * Description: - * Put a vector with metadata on the stream buffer - * - * Input Parameters: - * s - a pointer to a nxscope instance - * ch - a channel id - * val - a pointer to a sample data vector - * d - a dimmention of sample data vector - * meta - a pointer to metadata - * mlen - a length of metadata - * - ****************************************************************************/ - -int nxscope_put_vuint8_m(FAR struct nxscope_s *s, uint8_t ch, - FAR uint8_t *val, uint8_t d, - FAR uint8_t *meta, uint8_t mlen); -int nxscope_put_vint8_m(FAR struct nxscope_s *s, uint8_t ch, - FAR int8_t *val, uint8_t d, - FAR uint8_t *meta, uint8_t mlen); -int nxscope_put_vuint16_m(FAR struct nxscope_s *s, uint8_t ch, - FAR uint16_t *val, uint8_t d, - FAR uint8_t *meta, uint8_t mlen); -int nxscope_put_vint16_m(FAR struct nxscope_s *s, uint8_t ch, - FAR int16_t *val, uint8_t d, - FAR uint8_t *meta, uint8_t mlen); -int nxscope_put_vuint32_m(FAR struct nxscope_s *s, uint8_t ch, - FAR uint32_t *val, uint8_t d, - FAR uint8_t *meta, uint8_t mlen); -int nxscope_put_vint32_m(FAR struct nxscope_s *s, uint8_t ch, - FAR int32_t *val, uint8_t d, - FAR uint8_t *meta, uint8_t mlen); -int nxscope_put_vuint64_m(FAR struct nxscope_s *s, uint8_t ch, - FAR uint64_t *val, uint8_t d, - FAR uint8_t *meta, uint8_t mlen); -int nxscope_put_vint64_m(FAR struct nxscope_s *s, uint8_t ch, - FAR int64_t *val, uint8_t d, - FAR uint8_t *meta, uint8_t mlen); -int nxscope_put_vfloat_m(FAR struct nxscope_s *s, uint8_t ch, - FAR float *val, uint8_t d, - FAR uint8_t *meta, uint8_t mlen); -int nxscope_put_vdouble_m(FAR struct nxscope_s *s, uint8_t ch, - FAR double *val, uint8_t d, - FAR uint8_t *meta, uint8_t mlen); -int nxscope_put_vub8_m(FAR struct nxscope_s *s, uint8_t ch, - FAR ub8_t *val, uint8_t d, - FAR uint8_t *meta, uint8_t mlen); -int nxscope_put_vb8_m(FAR struct nxscope_s *s, uint8_t ch, - FAR b8_t *val, uint8_t d, - FAR uint8_t *meta, uint8_t mlen); -int nxscope_put_vub16_m(FAR struct nxscope_s *s, uint8_t ch, - FAR ub16_t *val, uint8_t d, - FAR uint8_t *meta, uint8_t mlen); -int nxscope_put_vb16_m(FAR struct nxscope_s *s, uint8_t ch, - FAR b16_t *val, uint8_t d, - FAR uint8_t *meta, uint8_t mlen); -int nxscope_put_vub32_m(FAR struct nxscope_s *s, uint8_t ch, - FAR ub32_t *val, uint8_t d, - FAR uint8_t *meta, uint8_t mlen); -int nxscope_put_vb32_m(FAR struct nxscope_s *s, uint8_t ch, - FAR b32_t *val, uint8_t d, - FAR uint8_t *meta, uint8_t mlen); -int nxscope_put_vchar_m(FAR struct nxscope_s *s, uint8_t ch, - FAR char *val, uint8_t d, - FAR uint8_t *meta, uint8_t mlen); - -/**************************************************************************** - * Name: nxscope_put_vXXXX - * - * Description: - * Put a vector on the stream buffer - * - * Input Parameters: - * s - a pointer to a nxscope instance - * ch - a channel id - * val - a pointer to a sample data vector - * d - a dimmention of sample data vector - * - ****************************************************************************/ - -int nxscope_put_vuint8(FAR struct nxscope_s *s, uint8_t ch, - FAR uint8_t *val, uint8_t d); -int nxscope_put_vint8(FAR struct nxscope_s *s, uint8_t ch, - FAR int8_t *val, uint8_t d); -int nxscope_put_vuint16(FAR struct nxscope_s *s, uint8_t ch, - FAR uint16_t *val, uint8_t d); -int nxscope_put_vint16(FAR struct nxscope_s *s, uint8_t ch, - FAR int16_t *val, uint8_t d); -int nxscope_put_vuint32(FAR struct nxscope_s *s, uint8_t ch, - FAR uint32_t *val, uint8_t d); -int nxscope_put_vint32(FAR struct nxscope_s *s, uint8_t ch, - FAR int32_t *val, uint8_t d); -int nxscope_put_vuint64(FAR struct nxscope_s *s, uint8_t ch, - FAR uint64_t *val, uint8_t d); -int nxscope_put_vint64(FAR struct nxscope_s *s, uint8_t ch, - FAR int64_t *val, uint8_t d); -int nxscope_put_vfloat(FAR struct nxscope_s *s, uint8_t ch, - FAR float *val, uint8_t d); -int nxscope_put_vdouble(FAR struct nxscope_s *s, uint8_t ch, - FAR double *val, uint8_t d); -int nxscope_put_vub8(FAR struct nxscope_s *s, uint8_t ch, - FAR ub8_t *val, uint8_t d); -int nxscope_put_vb8(FAR struct nxscope_s *s, uint8_t ch, - FAR b8_t *val, uint8_t d); -int nxscope_put_vub16(FAR struct nxscope_s *s, uint8_t ch, - FAR ub16_t *val, uint8_t d); -int nxscope_put_vb16(FAR struct nxscope_s *s, uint8_t ch, - FAR b16_t *val, uint8_t d); -int nxscope_put_vub32(FAR struct nxscope_s *s, uint8_t ch, - FAR ub32_t *val, uint8_t d); -int nxscope_put_vb32(FAR struct nxscope_s *s, uint8_t ch, - FAR b32_t *val, uint8_t d); -int nxscope_put_vchar(FAR struct nxscope_s *s, uint8_t ch, - FAR char *val, uint8_t d); - -/**************************************************************************** - * Name: nxscope_put_XXXX_m - * - * Description: - * Put a point with metadata on the stream buffer - * - * Input Parameters: - * s - a pointer to a nxscope instance - * ch - a channel id - * val - sample data - * meta - a pointer to metadata - * mlen - a length of metadata - * - ****************************************************************************/ - -int nxscope_put_uint8_m(FAR struct nxscope_s *s, uint8_t ch, uint8_t val, - FAR uint8_t *meta, uint8_t mlen); -int nxscope_put_int8_m(FAR struct nxscope_s *s, uint8_t ch, int8_t val, - FAR uint8_t *meta, uint8_t mlen); -int nxscope_put_uint16_m(FAR struct nxscope_s *s, uint8_t ch, uint16_t val, - FAR uint8_t *meta, uint8_t mlen); -int nxscope_put_int16_m(FAR struct nxscope_s *s, uint8_t ch, int16_t val, - FAR uint8_t *meta, uint8_t mlen); -int nxscope_put_uint32_m(FAR struct nxscope_s *s, uint8_t ch, uint32_t val, - FAR uint8_t *meta, uint8_t mlen); -int nxscope_put_int32_m(FAR struct nxscope_s *s, uint8_t ch, int32_t val, - FAR uint8_t *meta, uint8_t mlen); -int nxscope_put_uint64_m(FAR struct nxscope_s *s, uint8_t ch, uint64_t val, - FAR uint8_t *meta, uint8_t mlen); -int nxscope_put_int64_m(FAR struct nxscope_s *s, uint8_t ch, int64_t val, - FAR uint8_t *meta, uint8_t mlen); -int nxscope_put_float_m(FAR struct nxscope_s *s, uint8_t ch, float val, - FAR uint8_t *meta, uint8_t mlen); -int nxscope_put_double_m(FAR struct nxscope_s *s, uint8_t ch, double val, - FAR uint8_t *meta, uint8_t mlen); -int nxscope_put_ub8_m(FAR struct nxscope_s *s, uint8_t ch, ub8_t val, - FAR uint8_t *meta, uint8_t mlen); -int nxscope_put_b8_m(FAR struct nxscope_s *s, uint8_t ch, b8_t val, - FAR uint8_t *meta, uint8_t mlen); -int nxscope_put_ub16_m(FAR struct nxscope_s *s, uint8_t ch, ub16_t val, - FAR uint8_t *meta, uint8_t mlen); -int nxscope_put_b16_m(FAR struct nxscope_s *s, uint8_t ch, b16_t val, - FAR uint8_t *meta, uint8_t mlen); -int nxscope_put_ub32_m(FAR struct nxscope_s *s, uint8_t ch, ub32_t val, - FAR uint8_t *meta, uint8_t mlen); -int nxscope_put_b32_m(FAR struct nxscope_s *s, uint8_t ch, b32_t val, - FAR uint8_t *meta, uint8_t mlen); -int nxscope_put_char_m(FAR struct nxscope_s *s, uint8_t ch, char val, - FAR uint8_t *meta, uint8_t mlen); - -/**************************************************************************** - * Name: nxscope_put_none_m - * - * Description: - * Put metadata only on the stream buffer - * - * Input Parameters: - * s - a pointer to a nxscope instance - * ch - a channel id - * meta - a pointer to metadata - * mlen - a length of metadata - * - ****************************************************************************/ - -int nxscope_put_none_m(FAR struct nxscope_s *s, uint8_t ch, - FAR uint8_t *meta, uint8_t mlen); - -#ifdef CONFIG_LOGGING_NXSCOPE_USERTYPES -/**************************************************************************** - * Name: nxscope_put_user_m - * - * Description: - * Put a user specific data on the stream buffer - * - * Input Parameters: - * s - a pointer to a nxscope instance - * type - a channel type (starts from NXSCOPE_TYPE_USER) - * ch - a channel id - * val - a pointer to a sample data vector - * d - a dimmention of sample data vector - * meta - a pointer to metadata - * mlen - a length of metadata - * - ****************************************************************************/ - -int nxscope_put_user_m(FAR struct nxscope_s *s, uint8_t ch, uint8_t type, - FAR uint8_t *val, uint8_t d, - FAR uint8_t *meta, uint8_t mlen); -#endif - -/**************************************************************************** - * Name: nxscope_put_user_m - * - * Description: - * Put a point on the stream buffer - * - * Input Parameters: - * s - a pointer to a nxscope instance - * ch - a channel id - * val - sample data - * - ****************************************************************************/ - -int nxscope_put_uint8(FAR struct nxscope_s *s, uint8_t ch, uint8_t val); -int nxscope_put_int8(FAR struct nxscope_s *s, uint8_t ch, int8_t val); -int nxscope_put_uint16(FAR struct nxscope_s *s, uint8_t ch, uint16_t val); -int nxscope_put_int16(FAR struct nxscope_s *s, uint8_t ch, int16_t val); -int nxscope_put_uint32(FAR struct nxscope_s *s, uint8_t ch, uint32_t val); -int nxscope_put_int32(FAR struct nxscope_s *s, uint8_t ch, int32_t val); -int nxscope_put_uint64(FAR struct nxscope_s *s, uint8_t ch, uint64_t val); -int nxscope_put_int64(FAR struct nxscope_s *s, uint8_t ch, int64_t val); -int nxscope_put_float(FAR struct nxscope_s *s, uint8_t ch, float val); -int nxscope_put_double(FAR struct nxscope_s *s, uint8_t ch, double val); -int nxscope_put_ub8(FAR struct nxscope_s *s, uint8_t ch, ub8_t val); -int nxscope_put_b8(FAR struct nxscope_s *s, uint8_t ch, b8_t val); -int nxscope_put_ub16(FAR struct nxscope_s *s, uint8_t ch, ub16_t val); -int nxscope_put_b16(FAR struct nxscope_s *s, uint8_t ch, b16_t val); -int nxscope_put_ub32(FAR struct nxscope_s *s, uint8_t ch, ub32_t val); -int nxscope_put_b32(FAR struct nxscope_s *s, uint8_t ch, b32_t val); -int nxscope_put_char(FAR struct nxscope_s *s, uint8_t ch, char val); - -#undef EXTERN -#ifdef __cplusplus -} -#endif - -#endif /* __APPS_INCLUDE_LOGGING_NXSCOPE_NXSCOPE_CHAN_H */ diff --git a/include/logging/nxscope/nxscope_intf.h b/include/logging/nxscope/nxscope_intf.h deleted file mode 100644 index 937619f3a..000000000 --- a/include/logging/nxscope/nxscope_intf.h +++ /dev/null @@ -1,166 +0,0 @@ -/**************************************************************************** - * apps/include/logging/nxscope/nxscope_intf.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __APPS_INCLUDE_LOGGING_NXSCOPE_NXSCOPE_INTF_H -#define __APPS_INCLUDE_LOGGING_NXSCOPE_NXSCOPE_INTF_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#ifdef CONFIG_LOGGING_NXSCOPE_INTF_SERIAL -# include -#endif - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -#ifdef __cplusplus -#define EXTERN extern "C" -extern "C" -{ -#else -#define EXTERN extern -#endif - -/* Forward declaration */ - -struct nxscope_intf_s; - -/* Nxscope interface ops */ - -struct nxscope_intf_ops_s -{ - /* Send data */ - - CODE int (*send)(FAR struct nxscope_intf_s *s, FAR uint8_t *buff, int len); - - /* Receive data */ - - CODE int (*recv)(FAR struct nxscope_intf_s *s, FAR uint8_t *buff, int len); -}; - -/* Nxscope interface */ - -struct nxscope_intf_s -{ - /* Initialized flag */ - - bool initialized; - - /* Nxscope interface private data */ - - FAR void *priv; - - /* Nxscope interface ops */ - - FAR struct nxscope_intf_ops_s *ops; -}; - -#ifdef CONFIG_LOGGING_NXSCOPE_INTF_DUMMY -/* Nxscope dummy interface configuration */ - -struct nxscope_dummy_cfg_s -{ - int res; /* Reserved */ -}; -#endif - -#ifdef CONFIG_LOGGING_NXSCOPE_INTF_SERIAL -/* Nxscope serial interface configuration */ - -struct nxscope_ser_cfg_s -{ - FAR char *path; /* Device path */ - bool nonblock; /* Nonblocking operation */ - speed_t baud; /* Baud rate. Ignored if set to 0 */ -}; -#endif - -#ifdef CONFIG_LOGGING_NXSCOPE_INTF_UDP -/* Nxscope UDP interface configuration */ - -struct nxscope_udp_cfg_s -{ - uint16_t port; /* Local UDP port */ - bool nonblock; /* Nonblocking operation */ -}; -#endif - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -#ifdef CONFIG_LOGGING_NXSCOPE_INTF_DUMMY -/**************************************************************************** - * Name: nxscope_dummy_init - ****************************************************************************/ - -int nxscope_dummy_init(FAR struct nxscope_intf_s *intf, - FAR struct nxscope_dummy_cfg_s *cfg); - -/**************************************************************************** - * Name: nxscope_dummy_deinit - ****************************************************************************/ - -void nxscope_dummy_deinit(FAR struct nxscope_intf_s *intf); -#endif - -#ifdef CONFIG_LOGGING_NXSCOPE_INTF_SERIAL -/**************************************************************************** - * Name: nxscope_ser_init - ****************************************************************************/ - -int nxscope_ser_init(FAR struct nxscope_intf_s *intf, - FAR struct nxscope_ser_cfg_s *cfg); - -/**************************************************************************** - * Name: nxscope_ser_deinit - ****************************************************************************/ - -void nxscope_ser_deinit(FAR struct nxscope_intf_s *intf); -#endif - -#ifdef CONFIG_LOGGING_NXSCOPE_INTF_UDP -/**************************************************************************** - * Name: nxscope_udp_init - ****************************************************************************/ - -int nxscope_udp_init(FAR struct nxscope_intf_s *intf, - FAR struct nxscope_udp_cfg_s *cfg); - -/**************************************************************************** - * Name: nxscope_udp_deinit - ****************************************************************************/ - -void nxscope_udp_deinit(FAR struct nxscope_intf_s *intf); -#endif - -#undef EXTERN -#ifdef __cplusplus -} -#endif - -#endif /* __APPS_INCLUDE_LOGGING_NXSCOPE_NXSCOPE_INTF_H */ diff --git a/include/logging/nxscope/nxscope_proto.h b/include/logging/nxscope/nxscope_proto.h deleted file mode 100644 index 109aa91c0..000000000 --- a/include/logging/nxscope/nxscope_proto.h +++ /dev/null @@ -1,120 +0,0 @@ -/**************************************************************************** - * apps/include/logging/nxscope/nxscope_proto.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __APPS_INCLUDE_LOGGING_NXSCOPE_NXSCOPE_PROTO_H -#define __APPS_INCLUDE_LOGGING_NXSCOPE_NXSCOPE_PROTO_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -#ifdef __cplusplus -#define EXTERN extern "C" -extern "C" -{ -#else -#define EXTERN extern -#endif - -/* Nxscope frame handler */ - -struct nxscope_frame_s -{ - uint8_t id; /* Frame id */ - size_t drop; /* Data to be droped from recv buffer */ - size_t dlen; /* Data len (without header and footer) */ - FAR uint8_t *data; /* A pointer to a frame data */ -}; - -/* Forward declaration */ - -struct nxscope_proto_s; - -/* Nxscope protocol ops */ - -struct nxscope_proto_ops_s -{ - /* Get a frame from a buffer */ - - CODE int (*frame_get)(FAR struct nxscope_proto_s *p, - FAR uint8_t *buff, size_t len, - FAR struct nxscope_frame_s *frame); - - /* Finalize a frame in a given buffer */ - - CODE int (*frame_final)(FAR struct nxscope_proto_s *p, - uint8_t id, - FAR uint8_t *buff, FAR size_t *len); -}; - -/* Nxscope protocol handler */ - -struct nxscope_proto_s -{ - /* Initialized flag */ - - bool initialized; - - /* Nxscope protocol private data */ - - FAR void *priv; - - /* Nxscope protocol ops */ - - FAR struct nxscope_proto_ops_s *ops; - - /* Header and foot size */ - - size_t hdrlen; - size_t footlen; -}; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -#ifdef CONFIG_LOGGING_NXSCOPE_PROTO_SER -/**************************************************************************** - * Name: nxscope_proto_ser_init - ****************************************************************************/ - -int nxscope_proto_ser_init(FAR struct nxscope_proto_s *proto, FAR void *cfg); - -/**************************************************************************** - * Name: nxscope_proto_ser_deinit - ****************************************************************************/ - -void nxscope_proto_ser_deinit(FAR struct nxscope_proto_s *proto); -#endif - -#undef EXTERN -#ifdef __cplusplus -} -#endif - -#endif /* __APPS_INCLUDE_LOGGING_NXSCOPE_NXSCOPE_PROTO_H */ diff --git a/include/lte/lte_api.h b/include/lte/lte_api.h deleted file mode 100644 index f7c17c5d5..000000000 --- a/include/lte/lte_api.h +++ /dev/null @@ -1,1582 +0,0 @@ -/**************************************************************************** - * apps/include/lte/lte_api.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __APPS_INCLUDE_LTE_LTE_API_H -#define __APPS_INCLUDE_LTE_LTE_API_H - -/* - Abbreviations and terms - * - PDN : Packet Data Network - * - * Route for transferring packets between the terminal and LTE networks. - * - * - APN : Access Point Name - * - * Settings required when connecting to an LTE network. - * - * - IMSI : International Mobile Subscriber Identity - * - * International subscriber identification number recorded - * on the SIM card. - * - * - IMEI : International Mobile Equipment Identifier - * - * International identification number assigned to - * data communication terminals - * - * - PIN : Personal Identification Number - * - * - MCC : Mobile Country Code - * - * The mobile country code consists of three decimal digits. - * - * - MNC : Mobile Network Code - * - * The mobile network code consists of two or three decimal digits. - * - * - eDRX : extended Discontinuous Reception - * - * Communication technology that reduces power consumption - * by increasing the reception interval of various signals transmitted - * from LTE networks. - * - * - PSM : Power Saving Mode - * - * Communication technology that reduces power consumption - * by not communicating with the LTE network - * for a certain period of time. - * - * - CE : Coverage Enhancement - * - * Communication technology that attempts to resend data and eventually - * restores the original data even if the data is corrupted - * due to weak electric field communication. - * - * - RAT : Radio Access Technology - * - * Physical connection method for a radio based communication network. - * - * - LTE API system - * - Network connection API - * - * Radio ON / OFF, PDN connection establishment / destruction. - * - * - Communication quality and communication state API - * - * Acquisition of radio status, communication status, and local time. - * - * - SIM card control API - * - * Get phone number / IMSI, set the PIN, get SIM status. - * - * - Modem setting API - * - * Get modem firmware version and IMEI. Update communication settings. - * - * - API call type - * - * There are two types of LTE API: synchronous and asynchronous. - * - * - Synchronous API - * - Notifies the processing result as a return value. - * - * - Blocks the task that called the API until - * processing is completed on the modem. - * - * - If the return value is -EPROTO, you can get the error code - * with lte_get_errinfo. - * - * - If the argument attribute is out, the argument must be allocated - * by the caller. - * - * - Asynchronous API - * - The processing result is notified by callback. - * The callback is invoked in the task context. - * - * - Blocks the task that called the API until it requests - * processing from the modem. - * - * - Notifies the processing request result as a return value. - * - * - The callback is registered with the argument of each API. - * Registration is canceled when the processing result is notified. - * - * - The same API cannot be called until the processing result is notified - * by the callback.(-EINPROGRESS is notified with a return value.) - * - * - If the callback reports an error (LTE_RESULT_ERROR), - * detailed error information can be acquired with lte_get_errinfo. - * - * For some APIs, both synchronous and asynchronous APIs are available. - * The correspondence table of API is as follows. - * - * - * | Synchronous API | Asynchronous API | - * | ---------------------------- | --------------------------------- | - * | lte_initialize | | - * | lte_finalize | | - * | lte_set_report_restart | | - * | lte_power_on | | - * | lte_power_off | | - * | lte_set_report_netinfo | | - * | lte_set_report_simstat | | - * | lte_set_report_localtime | | - * | lte_set_report_quality | | - * | lte_set_report_cellinfo | | - * | lte_get_errinfo | | - * | lte_activate_pdn_cancel | | - * | lte_radio_on_sync | lte_radio_on (deprecated) | - * | lte_radio_off_sync | lte_radio_off (deprecated) | - * | lte_activate_pdn_sync | lte_activate_pdn | - * | lte_deactivate_pdn_sync | lte_deactivate_pdn (deprecated) | - * | lte_data_allow_sync | lte_data_allow (deprecated) | - * | lte_get_netinfo_sync | lte_get_netinfo (deprecated) | - * | lte_get_imscap_sync | lte_get_imscap (deprecated) | - * | lte_get_version_sync | lte_get_version (deprecated) | - * | lte_get_phoneno_sync | lte_get_phoneno (deprecated) | - * | lte_get_imsi_sync | lte_get_imsi (deprecated) | - * | lte_get_imei_sync | lte_get_imei (deprecated) | - * | lte_get_pinset_sync | lte_get_pinset (deprecated) | - * | lte_set_pinenable_sync | lte_set_pinenable (deprecated) | - * | lte_change_pin_sync | lte_change_pin (deprecated) | - * | lte_enter_pin_sync | lte_enter_pin (deprecated) | - * | lte_get_localtime_sync | lte_get_localtime (deprecated) | - * | lte_get_operator_sync | lte_get_operator (deprecated) | - * | lte_get_edrx_sync | lte_get_edrx (deprecated) | - * | lte_set_edrx_sync | lte_set_edrx (deprecated) | - * | lte_get_psm_sync | lte_get_psm (deprecated) | - * | lte_set_psm_sync | lte_set_psm (deprecated) | - * | lte_get_ce_sync | lte_get_ce (deprecated) | - * | lte_set_ce_sync | lte_set_ce (deprecated) | - * | lte_get_siminfo_sync | lte_get_siminfo (deprecated) | - * | lte_get_current_edrx_sync | lte_get_current_edrx (deprecated) | - * | lte_get_current_psm_sync | lte_get_current_psm (deprecated) | - * | lte_get_quality_sync | lte_get_quality (deprecated) | - * | lte_get_cellinfo_sync | | - * | lte_get_rat_sync | | - * | lte_set_rat_sync | | - * | lte_get_ratinfo_sync | | - * | lte_acquire_wakelock | | - * | lte_release_wakelock | | - * | lte_send_atcmd_sync | | - * | lte_factory_reset_sync | | - * | lte_set_context_save_cb | | - * | lte_hibernation_resume | | - */ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include - -#ifdef __cplusplus -#define EXTERN extern "C" -extern "C" -{ -#else -#define EXTERN extern -#endif - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/* Initialize resources used in LTE API. - * - * On success, 0 is returned. On failure, - * negative value is returned according to . - */ - -int lte_initialize(void); - -/* Release resources used in LTE API. - * - * return On success, 0 is returned. On failure, - * negative value is returned according to . - */ - -int lte_finalize(void); - -/* Register the callback to notify that the modem has started up. - * - * The callback will be invoked if the modem starts successfully - * after calling lte_power_on. Some APIs have to wait until - * this callback is invoked. If no wait, those API return - * with an error. (-ENETDOWN) - * - * The callback is also invoked when the modem is restarted. - * The cause of the restart can be obtained from the callback argument. - * - * This function must be called after lte_initialize. - * - * Attention to the following - * when LTE_RESTART_MODEM_INITIATED is set. - * - Asynchronous API callbacks for which results have not been - * notified are canceled and becomes available. - * - * - The processing result of the synchronous API - * being called results in an error. (Return value is -ENETDOWN) - * The errno is ENETDOWN for the socket API. - * - * - It should close the socket by user application. - * - * [in] restart_callback: Callback function to notify that - * modem restarted. - * - * On success, 0 is returned. On failure, - * negative value is returned according to . - */ - -int lte_set_report_restart(restart_report_cb_t restart_callback); - -/* Power on the modem. - * - * The callback which registered by lte_set_report_restart - * will be invoked if the modem starts successfully. - * - * This function must be called after lte_set_report_restart. - * - * On success, 0 is returned. On failure, - * negative value is returned according to . - */ - -int lte_power_on(void); - -/* Power off the modem - * - * Attention to the following when this API calling. - * - For asynchronous API - * - callback is canceled. - * - * - For synchronous API - * - API returns with an error. - * - The return value is -ENETDOWN for the LTE API. - * - The errno is ENETDOWN for the socket API. - * - * On success, 0 is returned. On failure, - * negative value is returned according to . - */ - -int lte_power_off(void); - -/* With the radio on, to start the LTE network search. - * - * Attention to the following when this API calling. - * - If SIM is PIN locked, the result will be an error. - * - * On success, 0 is returned. On failure, - * negative value is returned according to . - */ - -int lte_radio_on_sync(void); - -#ifdef CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API - -/* With the radio on, to start the LTE network search. - * The use of this API is deprecated. - * Use lte_radio_on_sync() instead. - * - * Attention to the following when this API calling. - * - If SIM is PIN locked, the result will be an error. - * - * [in] callback: Callback function to notify that - * radio on is completed. - * - * On success, 0 is returned. On failure, - * negative value is returned according to . - */ - -int lte_radio_on(radio_on_cb_t callback); - -#endif /* CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API */ - -/* Exit LTE network searches with the radio off. - * - * If this function is called when a PDN has already been constructed, - * the PDN is discarded. - * - * On success, 0 is returned. On failure, - * negative value is returned according to . - */ - -int lte_radio_off_sync(void); - -#ifdef CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API - -/* Exit LTE network searches with the radio off. - * The use of this API is deprecated. - * Use lte_radio_off_sync() instead. - * - * If this function is called when a PDN has already been constructed, - * the PDN is discarded. - * - * [in] callback: Callback function to notify that - * radio off is completed. - * - * On success, 0 is returned. On failure, - * negative value is returned according to . - */ - -int lte_radio_off(radio_off_cb_t callback); - -#endif /* CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API */ - -/* Get LTE network information. - * - * The maximum number of PDNs status areas must be allocated - * before calls this API. - * - * [in] pdn_num: Number of pdn_stat allocated by the user. - * The range is from LTE_PDN_SESSIONID_MIN to - * LTE_PDN_SESSIONID_MAX. - * - * [out] info: The LTE network information. - * See lte_netinfo_t - * - * attention Immediately after successful PDN construction - * using lte_activate_pdn_sync() or lte_activate_pdn(), - * session information such as IP address - * may not be acquired correctly. - * If you want to use this API after successfully construction - * the PDN, wait at least 1 second before executing it. - * - * On success, 0 is returned. On failure, - * negative value is returned according to . - */ - -int lte_get_netinfo_sync(uint8_t pdn_num, FAR lte_netinfo_t *info); - -#ifdef CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API - -/* Get LTE network information. - * The use of this API is deprecated. - * Use lte_get_netinfo_sync() instead. - * - * [in] callback: Callback function to notify that - * get network information completed. - * - * attention Immediately after successful PDN construction - * using lte_activate_pdn_sync() or lte_activate_pdn(), - * session information such as IP address - * may not be acquired correctly. - * If you want to use this API after successfully construction - * the PDN, wait at least 1 second before executing it. - * - * On success, 0 is returned. On failure, - * negative value is returned according to . - */ - -int lte_get_netinfo(get_netinfo_cb_t callback); - -#endif /* CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API */ - -/* Constructs a PDN with the specified APN settings. - * - * When constructs the initial PDN, - * LTE_APN_TYPE_IA must be set to the APN type. - * - * When PDN construction is successful, - * an IP address is given from the LTE network. - * - * attention Attention to the following when this API calling. - * - The initial PDN construction may take a few minutes - * depending on radio conditions. - * - * - If API is not returned, please check if the APN settings are correct. - * - * [in] apn: The pointer of the apn setting. - * See lte_apn_setting_t for valid parameters. - * - * [out] pdn: The construction PDN information. - * See lte_pdn_t. - * - * On success, 0 is returned. On failure, - * negative value is returned according to . - * If canceling, -ECANCELED is returned. - */ - -int lte_activate_pdn_sync(FAR lte_apn_setting_t *apn, FAR lte_pdn_t *pdn); - -/* Constructs a PDN with the specified APN settings. - * - * When constructs the initial PDN, - * LTE_APN_TYPE_IA must be set to the APN type. - * - * When PDN construction is successful, - * an IP address is given from the LTE network. - * - * attention Attention to the following when this API calling. - * - The initial PDN construction may take a few minutes - * depending on radio conditions. - * - * - If the callback is not notified, please check - * if the APN settings are correct. - * - * [in] apn: The pointer of the apn setting. - * See lte_apn_setting_t for valid parameters. - * - * [in] callback: Callback function to notify that - * PDN activation completed. - * - * On success, 0 is returned. On failure, - * negative value is returned according to . - */ - -int lte_activate_pdn(FAR lte_apn_setting_t *apn, activate_pdn_cb_t callback); - -/* Cancel PDN construction. - * - * On success, 0 is returned. On failure, - * negative value is returned according to . - */ - -int lte_activate_pdn_cancel(void); - -/* Discard the constructed PDN. - * - * Discards the PDN corresponding to the session ID - * obtained by lte_activate_pdn. - * - * When the discard process is successful, the IP address assigned to - * the modem is released to the LTE network. - * - * [in] session_id: The numeric value of the session ID. - * Use the value obtained by the lte_activate_pdn. - * - * On success, 0 is returned. On failure, - * negative value is returned according to . - */ - -int lte_deactivate_pdn_sync(uint8_t session_id); - -#ifdef CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API - -/* Discard the constructed PDN. - * The use of this API is deprecated. - * Use lte_deactivate_pdn_sync() instead. - * - * Discards the PDN corresponding to the session ID - * obtained by lte_activate_pdn. - * - * When the discard process is successful, the IP address assigned to - * the modem is released to the LTE network. - * - * [in] session_id: The numeric value of the session ID. - * Use the value obtained by the lte_activate_pdn. - * - * [in] callback: Callback function to notify that - * LTE PDN deactivation completed. - * - * On success, 0 is returned. On failure, - * negative value is returned according to . - */ - -int lte_deactivate_pdn(uint8_t session_id, deactivate_pdn_cb_t callback); - -#endif /* CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API */ - -/* Allow or disallow to data communication for specified PDN. - * - * attention This function is not supported. - * - * [in] session_id: The numeric value of the session ID. - * Use the value obtained by the lte_activate_pdn. - * - * [in] allow: Allow or disallow to data communication for - * all network. Definition is as below. - * - LTE_DATA_ALLOW - * - LTE_DATA_DISALLOW - * - * [in] roaming_allow: Allow or disallow to data communication for - * roaming network. Definition is as below. - * - LTE_DATA_ALLOW - * - LTE_DATA_DISALLOW - * - * -EOPNOTSUPP is returned. - */ - -int lte_data_allow_sync(uint8_t session_id, uint8_t allow, - uint8_t roaming_allow); - -#ifdef CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API - -/* Allow or disallow to data communication for specified PDN. - * The use of this API is deprecated. - * - * attention This function is not supported. - * - * [in] session_id: The numeric value of the session ID. - * Use the value obtained by the lte_activate_pdn. - * - * [in] allow: Allow or disallow to data communication for - * all network. Definition is as below. - * - LTE_DATA_ALLOW - * - LTE_DATA_DISALLOW - * - * [in] roaming_allow: Allow or disallow to data communication for - * roaming network. Definition is as below. - * - LTE_DATA_ALLOW - * - LTE_DATA_DISALLOW - * - * [in] callback: Callback function to notify that - * configuration has changed. - * - * -EOPNOTSUPP is returned. - */ - -int lte_data_allow(uint8_t session_id, uint8_t allow, - uint8_t roaming_allow, data_allow_cb_t callback); - -#endif /* CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API */ - -/* Get whether the modem supports IMS or not. - * - * [out] imscap: The IMS capability. - * As below value stored. - * - LTE_ENABLE - * - LTE_DISABLE - * - * On success, 0 is returned. On failure, - * negative value is returned according to . - */ - -int lte_get_imscap_sync(FAR bool *imscap); - -#ifdef CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API - -/* Get whether the modem supports IMS or not. - * The use of this API is deprecated. - * Use lte_get_imscap_sync() instead. - * - * [in] callback: Callback function to notify when - * getting IMS capability is completed. - * - * On success, 0 is returned. On failure, - * negative value is returned according to . - */ - -int lte_get_imscap(get_imscap_cb_t callback); - -#endif /* CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API */ - -/* Acquires the FW version information of the modem. - * - * [out] version: The version information of the modem. - * See lte_version_t - * - * On success, 0 is returned. On failure, - * negative value is returned according to . - */ - -int lte_get_version_sync(FAR lte_version_t *version); - -#ifdef CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API - -/* Acquires the FW version information of the modem. - * The use of this API is deprecated. - * Use lte_get_version_sync() instead. - * - * [in] callback: Callback function to notify when - * getting the version is completed. - * - * On success, 0 is returned. On failure, - * negative value is returned according to . - */ - -int lte_get_version(get_ver_cb_t callback); - -#endif /* CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API */ - -/* Get phone number from SIM. - * - * [out] phoneno: A character string indicating phone number. - * It is terminated with '\0'. - * The maximum number of phone number areas - * must be allocated. See LTE_PHONENO_LEN. - * [in] len: Length of the buffer for storing phone number. - * - * On success, 0 is returned. On failure, - * negative value is returned according to . - */ - -#ifdef CONFIG_LTE_LAPI_KEEP_COMPATIBILITY -int lte_get_phoneno_sync(FAR char *phoneno); -#else -int lte_get_phoneno_sync(FAR char *phoneno, size_t len); -#endif - -#ifdef CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API - -/* Get phone number from SIM. - * The use of this API is deprecated. - * Use lte_get_phoneno_sync() instead. - * - * [in] callback: Callback function to notify when - * getting the phone number is completed. - * - * On success, 0 is returned. On failure, - * negative value is returned according to . - */ - -int lte_get_phoneno(get_phoneno_cb_t callback); - -#endif /* CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API */ - -/* Get International Mobile Subscriber Identity from SIM. - * - * [out] imsi: A character string indicating IMSI. - * It is terminated with '\0'. - * The maximum number of IMSI areas - * must be allocated. See LTE_IMSI_LEN. - * [in] len: Length of the buffer for storing IMSI. - * - * On success, 0 is returned. On failure, - * negative value is returned according to . - */ - -#ifdef CONFIG_LTE_LAPI_KEEP_COMPATIBILITY -int lte_get_imsi_sync(FAR char *imsi); -#else -int lte_get_imsi_sync(FAR char *imsi, size_t len); -#endif - -#ifdef CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API - -/* Get International Mobile Subscriber Identity from SIM. - * The use of this API is deprecated. - * Use lte_get_imsi_sync() instead. - * - * [in] callback: Callback function to notify when - * getting IMSI is completed. - * - * On success, 0 is returned. On failure, - * negative value is returned according to . - */ - -int lte_get_imsi(get_imsi_cb_t callback); - -#endif /* CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API */ - -/* Get International Mobile Equipment Identifier from the modem. - * - * [out] imei: A character string indicating IMEI. - * It is terminated with '\0'. - * The maximum number of IMEI areas - * must be allocated. See LTE_IMEI_LEN. - * [in] len: Length of the buffer for storing IMEI. - * - * On success, 0 is returned. On failure, - * negative value is returned according to . - */ - -#ifdef CONFIG_LTE_LAPI_KEEP_COMPATIBILITY -int lte_get_imei_sync(FAR char *imei); -#else -int lte_get_imei_sync(FAR char *imei, size_t len); -#endif - -#ifdef CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API - -/* Get International Mobile Equipment Identifier from the modem. - * The use of this API is deprecated. - * Use lte_get_imei_sync() instead. - * - * [in] callback: Callback function to notify when - * getting IMEI is completed - * - * On success, 0 is returned. On failure, - * negative value is returned according to . - */ - -int lte_get_imei(get_imei_cb_t callback); - -#endif /* CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API */ - -/* Get Personal Identification Number settings. - * - * [out] pinset: PIN settings information. - * See lte_getpin_t. - * - * On success, 0 is returned. On failure, - * negative value is returned according to . - */ - -int lte_get_pinset_sync(FAR lte_getpin_t *pinset); - -#ifdef CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API - -/* Get Personal Identification Number settings. - * The use of this API is deprecated. - * Use lte_get_pinset_sync() instead. - * - * [in] callback: Callback function to notify when - * getting the PIN setting is completed. - * - * On success, 0 is returned. On failure, - * negative value is returned according to . - */ - -int lte_get_pinset(get_pinset_cb_t callback); - -#endif /* CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API */ - -/* Set Personal Identification Number enable. - * - * [in] enable: "Enable" or "Disable". - * Definition is as below. - * - LTE_ENABLE - * - LTE_DISABLE - * - * [in] pincode: Current PIN code. Minimum number of digits is 4. - * Maximum number of digits is 8, end with '\0'. - * (i.e. Max 9 byte) - * - * [out] attemptsleft: Number of attempts left. - * Set only if failed. - * - * On success, 0 is returned. On failure, - * negative value is returned according to . - */ - -int lte_set_pinenable_sync(bool enable, FAR char *pincode, - FAR uint8_t *attemptsleft); - -#ifdef CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API - -/* Set Personal Identification Number enable. - * The use of this API is deprecated. - * Use lte_set_pinenable_sync() instead. - * - * [in] enable: "Enable" or "Disable". - * Definition is as below. - * - LTE_ENABLE - * - LTE_DISABLE - * - * [in] pincode: Current PIN code. Minimum number of digits is 4. - * Maximum number of digits is 8, end with '\0'. - * (i.e. Max 9 byte) - * - * [in] callback: Callback function to notify that - * setting of PIN enables/disables is completed. - * - * On success, 0 is returned. On failure, - * negative value is returned according to . - */ - -int lte_set_pinenable(bool enable, FAR char *pincode, - set_pinenable_cb_t callback); - -#endif /* CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API */ - -/* Change Personal Identification Number. - * - * It can be changed only when PIN is enable. - * - * [in] target_pin: Target of change PIN. - * Definition is as below. - * - LTE_TARGET_PIN - * - LTE_TARGET_PIN2 - * - * [in] pincode: Current PIN code. Minimum number of digits is 4. - * Maximum number of digits is 8, end with '\0'. - * (i.e. Max 9 byte) - * - * [in] new_pincode: New PIN code. Minimum number of digits is 4. - * Maximum number of digits is 8, end with '\0'. - * (i.e. Max 9 byte) - * - * [out] attemptsleft: Number of attempts left. - * Set only if failed. - * - * On success, 0 is returned. On failure, - * negative value is returned according to . - */ - -int lte_change_pin_sync(int8_t target_pin, FAR char *pincode, - FAR char *new_pincode, FAR uint8_t *attemptsleft); - -#ifdef CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API - -/* Change Personal Identification Number. - * The use of this API is deprecated. - * Use lte_change_pin_sync() instead. - * - * It can be changed only when PIN is enable. - * - * [in] target_pin: Target of change PIN. - * Definition is as below. - * - LTE_TARGET_PIN - * - LTE_TARGET_PIN2 - * - * [in] pincode: Current PIN code. Minimum number of digits is 4. - * Maximum number of digits is 8, end with '\0'. - * (i.e. Max 9 byte) - * - * [in] new_pincode: New PIN code. Minimum number of digits is 4. - * Maximum number of digits is 8, end with '\0'. - * (i.e. Max 9 byte) - * - * [in] callback: Callback function to notify that - * change of PIN is completed. - * - * On success, 0 is returned. On failure, - * negative value is returned according to . - */ - -int lte_change_pin(int8_t target_pin, FAR char *pincode, - FAR char *new_pincode, change_pin_cb_t callback); - -#endif /* CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API */ - -/* Enter Personal Identification Number. - * - * [in] pincode: Current PIN code. Minimum number of digits is 4. - * Maximum number of digits is 8, end with '\0'. - * (i.e. Max 9 byte) - * - * [in] new_pincode: Always set NULL. - * This parameter is not currently used. - * If this parameter has a value in it, - * this API will error. - * - * [out] simstat: State after PIN enter. - * As below value stored. - * - LTE_PINSTAT_READY - * - LTE_PINSTAT_SIM_PIN - * - LTE_PINSTAT_SIM_PUK - * - LTE_PINSTAT_PH_SIM_PIN - * - LTE_PINSTAT_PH_FSIM_PIN - * - LTE_PINSTAT_PH_FSIM_PUK - * - LTE_PINSTAT_SIM_PIN2 - * - LTE_PINSTAT_SIM_PUK2 - * - LTE_PINSTAT_PH_NET_PIN - * - LTE_PINSTAT_PH_NET_PUK - * - LTE_PINSTAT_PH_NETSUB_PIN - * - LTE_PINSTAT_PH_NETSUB_PUK - * - LTE_PINSTAT_PH_SP_PIN - * - LTE_PINSTAT_PH_SP_PUK - * - LTE_PINSTAT_PH_CORP_PIN - * - LTE_PINSTAT_PH_CORP_PUK - * - * [out] attemptsleft: Number of attempts left. - * Set only if failed. - * If simstat is other than PIN, PUK, PIN2, PUK2, - * set the number of PIN. - * - * note Running this API when the SIM state is - * other than LTE_PINSTAT_SIM_PIN will return an error. - * - * On success, 0 is returned. On failure, - * negative value is returned according to . - * - * deprecated This API will be removed in a future version - */ - -int lte_enter_pin_sync(FAR char *pincode, FAR char *new_pincode, - FAR uint8_t *simstat, FAR uint8_t *attemptsleft); - -#ifdef CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API - -/* Enter Personal Identification Number. - * The use of this API is deprecated. - * Use lte_enter_pin_sync() instead. - * - * [in] pincode: Current PIN code. Minimum number of digits is 4. - * Maximum number of digits is 8, end with '\0'. - * (i.e. Max 9 byte) - * - * [in] new_pincode: Always set NULL. - * This parameter is not currently used. - * If this parameter has a value in it, - * this API will error. - * - * [in] callback: Callback function to notify that - * PIN enter is completed. - * - * note Running this API when the SIM state is - * other than LTE_PINSTAT_SIM_PIN will return an error. - * - * On success, 0 is returned. On failure, - * negative value is returned according to . - * - * deprecated This API will be removed in a future version - */ - -int lte_enter_pin(FAR char *pincode, FAR char *new_pincode, - enter_pin_cb_t callback); - -#endif /* CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API */ - -/* Get local time. - * - * [out] localtime: Local time. See lte_localtime_t. - * - * On success, 0 is returned. On failure, - * negative value is returned according to . - */ - -int lte_get_localtime_sync(FAR lte_localtime_t *localtime); - -#ifdef CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API - -/* Get local time. - * The use of this API is deprecated. - * Use lte_get_localtime_sync() instead. - * - * [in] callback: Callback function to notify when - * getting local time is completed. - * - * On success, 0 is returned. On failure, - * negative value is returned according to . - */ - -int lte_get_localtime(get_localtime_cb_t callback); - -#endif /* CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API */ - -/* Get connected network operator information. - * - * [out] oper: A character string indicating network operator. - * It is terminated with '\0' If it is not connected, - * the first character is '\0'. - * The maximum number of network operator areas - * must be allocated. See LTE_OPERATOR_LEN. - * [in] len: Length of the buffer for storing network operator. - * - * On success, 0 is returned. On failure, - * negative value is returned according to . - */ - -#ifdef CONFIG_LTE_LAPI_KEEP_COMPATIBILITY -int lte_get_operator_sync(FAR char *oper); -#else -int lte_get_operator_sync(FAR char *oper, size_t len); -#endif - -#ifdef CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API - -/* Get connected network operator information. - * The use of this API is deprecated. - * Use lte_get_operator_sync() instead. - * - * [in] callback: Callback function to notify when - * getting network operator information is completed. - * - * On success, 0 is returned. On failure, - * negative value is returned according to . - */ - -int lte_get_operator(get_operator_cb_t callback); - -#endif /* CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API */ - -/* Get eDRX settings. - * - * [out] settings: eDRX settings. See lte_edrx_setting_t. - * - * On success, 0 is returned. On failure, - * negative value is returned according to . - */ - -int lte_get_edrx_sync(FAR lte_edrx_setting_t *settings); - -#ifdef CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API - -/* Get eDRX settings. - * The use of this API is deprecated. - * Use lte_get_edrx_sync() instead. - * - * [in] callback: Callback function to notify when - * getting eDRX settings are completed. - * - * On success, 0 is returned. On failure, - * negative value is returned according to . - */ - -int lte_get_edrx(get_edrx_cb_t callback); - -#endif /* CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API */ - -/* Set eDRX settings. - * - * [in] settings: eDRX settings. - * - * On success, 0 is returned. On failure, - * negative value is returned according to . - */ - -int lte_set_edrx_sync(FAR lte_edrx_setting_t *settings); - -#ifdef CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API - -/* Set eDRX settings. - * The use of this API is deprecated. - * Use lte_set_edrx_sync() instead. - * - * [in] settings: eDRX settings. - * - * [in] callback: Callback function to notify that - * eDRX settings are completed. - * - * On success, 0 is returned. On failure, - * negative value is returned according to . - */ - -int lte_set_edrx(FAR lte_edrx_setting_t *settings, set_edrx_cb_t callback); - -#endif /* CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API */ - -/* Get PSM settings. - * - * [out] settings: PSM settings. See lte_psm_setting_t. - * - * On success, 0 is returned. On failure, - * negative value is returned according to . - */ - -int lte_get_psm_sync(FAR lte_psm_setting_t *settings); - -#ifdef CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API - -/* Get PSM settings. - * The use of this API is deprecated. - * Use lte_get_psm_sync() instead. - * - * [in] callback: Callback function to notify when - * getting PSM settings are completed. - * - * On success, 0 is returned. On failure, - * negative value is returned according to . - */ - -int lte_get_psm(get_psm_cb_t callback); - -#endif /* CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API */ - -/* Set PSM settings. - * - * [in] settings: PSM settings. - * - * On success, 0 is returned. On failure, - * negative value is returned according to . - */ - -int lte_set_psm_sync(FAR lte_psm_setting_t *settings); - -#ifdef CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API - -/* Set PSM settings. - * The use of this API is deprecated. - * Use lte_set_psm_sync() instead. - * - * [in] settings: PSM settings. - * - * [in] callback: Callback function to notify that - * PSM settings are completed. - * - * On success, 0 is returned. On failure, - * negative value is returned according to . - */ - -int lte_set_psm(FAR lte_psm_setting_t *settings, set_psm_cb_t callback); - -#endif /* CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API */ - -/* Get CE settings. - * - * [out] settings: CE settings. See lte_ce_setting_t. - * - * On success, 0 is returned. On failure, - * negative value is returned according to . - */ - -int lte_get_ce_sync(FAR lte_ce_setting_t *settings); - -#ifdef CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API - -/* Get CE settings. - * The use of this API is deprecated. - * Use lte_get_ce_sync() instead. - * - * [in] callback: Callback function to notify when - * getting CE settings are completed. - * - * On success, 0 is returned. On failure, - * negative value is returned according to . - */ - -int lte_get_ce(get_ce_cb_t callback); - -#endif /* CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API */ - -/* Set CE settings. - * - * [in] settings: CE settings - * - * On success, 0 is returned. On failure, - * negative value is returned according to . - */ - -int lte_set_ce_sync(FAR lte_ce_setting_t *settings); - -#ifdef CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API - -/* Set CE settings. - * The use of this API is deprecated. - * Use lte_set_ce_sync() instead. - * - * [in] settings: CE settings - * - * [in] callback: Callback function to notify that - * CE settings are completed. - * - * On success, 0 is returned. On failure, - * negative value is returned according to . - */ - -int lte_set_ce(FAR lte_ce_setting_t *settings, set_ce_cb_t callback); - -#endif /* CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API */ - -/* Notifies the SIM status to the application. - * - * The default report setting is disable. - * - * [in] simstat_callback: Callback function to notify that SIM state. - * If NULL is set, - * the report setting is disabled. - * - * On success, 0 is returned. On failure, - * negative value is returned according to . - */ - -int lte_set_report_simstat(simstat_report_cb_t simstat_callback); - -/* Notifies the Local time to the application. - * - * The default report setting is disable. - * - * [in] localtime_callback: Callback function to notify that - * local time. If NULL is set, - * the report setting is disabled. - * - * On success, 0 is returned. On failure, - * negative value is returned according to . - */ - -int lte_set_report_localtime(localtime_report_cb_t localtime_callback); - -/* Notifies the communication quality information to the application. - * - * Invoke the callback at the specified report interval. - * - * The default report setting is disable. - * - * attention When changing the notification cycle, stop and start again. - * - * [in] quality_callback: Callback function to notify that - * quality information. If NULL is set, - * the report setting is disabled. - * - * [in] period: Reporting cycle in sec (1-4233600) - * - * On success, 0 is returned. On failure, - * negative value is returned according to . - */ - -int lte_set_report_quality(quality_report_cb_t quality_callback, - uint32_t period); - -/* Notifies the LTE network cell information to the application. - * - * Invoke the callback at the specified report interval. - * - * The default report setting is disable. - * - * attention When changing the notification cycle, stop and start again. - * - * [in] cellinfo_callback: Callback function to notify that - * cell information. If NULL is set, - * the report setting is disabled. - * - * [in] period: Reporting cycle in sec (1-4233600) - * - * On success, 0 is returned. On failure, - * negative value is returned according to . - */ - -int lte_set_report_cellinfo(cellinfo_report_cb_t cellinfo_callback, - uint32_t period); - -/* Notifies the LTE network status to the application. - * - * The default report setting is disable. - * - * [in] netinfo_callback: Callback function to notify that - * cell information. If NULL is set, - * the report setting is disabled. - * - * On success, 0 is returned. On failure, - * negative value is returned according to . - */ - -int lte_set_report_netinfo(netinfo_report_cb_t netinfo_callback); - -/* Get LTE API last error information. - * - * Call this function when LTE_RESULT_ERROR is returned by - * callback function. The detailed error information can be obtained. - * - * [in] info: Pointer of error information. - * - * On success, 0 is returned. On failure, - * negative value is returned according to . - */ - -int lte_get_errinfo(FAR lte_errinfo_t *info); - -/* Get SIM information such as Mobile Country Code/Mobile Network Code. - * - * [in] option: Indicates which parameter to get. - * Bit setting definition is as below. - * - LTE_SIMINFO_GETOPT_MCCMNC - * - LTE_SIMINFO_GETOPT_SPN - * - LTE_SIMINFO_GETOPT_ICCID - * - LTE_SIMINFO_GETOPT_IMSI - * - LTE_SIMINFO_GETOPT_GID1 - * - LTE_SIMINFO_GETOPT_GID2 - * - * [out] siminfo: SIM information. See lte_siminfo_t. - * - * On success, 0 is returned. On failure, - * negative value is returned according to . - */ - -int lte_get_siminfo_sync(uint32_t option, FAR lte_siminfo_t *siminfo); - -#ifdef CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API - -/* Get SIM information such as Mobile Country Code/Mobile Network Code. - * The use of this API is deprecated. - * Use lte_get_siminfo_sync() instead. - * - * [in] option: Indicates which parameter to get. - * Bit setting definition is as below. - * - LTE_SIMINFO_GETOPT_MCCMNC - * - LTE_SIMINFO_GETOPT_SPN - * - LTE_SIMINFO_GETOPT_ICCID - * - LTE_SIMINFO_GETOPT_IMSI - * - LTE_SIMINFO_GETOPT_GID1 - * - LTE_SIMINFO_GETOPT_GID2 - * - * [in] callback: Callback function to notify that - * get of SIM information is completed. - * - * On success, 0 is returned. On failure, - * negative value is returned according to . - */ - -int lte_get_siminfo(uint32_t option, get_siminfo_cb_t callback); - -/* Get eDRX dynamic parameter. - * - * deprecated Use lte_get_current_edrx instead. - * - * This API can be issued after connect to the LTE network - * with lte_activate_pdn(). - * - * [in] callback: Callback function to notify when - * getting eDRX dynamic parameter is completed. - * - * On success, 0 is returned. On failure, - * negative value is returned according to . - */ - -int lte_get_dynamic_edrx_param(get_dynamic_edrx_param_cb_t callback); - -#endif /* CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API */ - -/* Get current eDRX settings. - * - * This API can be issued after connect to the LTE network - * with lte_activate_pdn(). - * - * Get the settings negotiated between the modem and the network. - * - * [out] settings: Current eDRX settings. - * See lte_edrx_setting_t. - * - * On success, 0 is returned. On failure, - * negative value is returned according to . - */ - -int lte_get_current_edrx_sync(FAR lte_edrx_setting_t *settings); - -#ifdef CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API - -/* Get current eDRX settings. - * The use of this API is deprecated. - * Use lte_get_current_edrx_sync() instead. - * - * This API can be issued after connect to the LTE network - * with lte_activate_pdn(). - * - * Get the settings negotiated between the modem and the network. - * - * [in] callback: Callback function to notify when - * getting current eDRX settings is completed. - * - * On success, 0 is returned. On failure, - * negative value is returned according to . - */ - -int lte_get_current_edrx(get_current_edrx_cb_t callback); - -/* Get PSM dynamic parameter. - * - * deprecated Use lte_get_current_psm instead. - * - * This API can be issued after connect to the LTE network - * with lte_activate_pdn(). - * - * [in] callback: Callback function to notify when - * getting PSM dynamic parameter is completed. - * - * On success, 0 is returned. On failure, - * negative value is returned according to . - */ - -int lte_get_dynamic_psm_param(get_dynamic_psm_param_cb_t callback); - -#endif /* CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API */ - -/* Get current PSM settings. - * - * This API can be issued after connect to the LTE network - * with lte_activate_pdn(). - * - * Get the settings negotiated between the modem and the network. - * - * [OUT] settings: Current PSM settings. - * See lte_psm_setting_t. - * - * On success, 0 is returned. On failure, - * negative value is returned according to . - */ - -int lte_get_current_psm_sync(FAR lte_psm_setting_t *settings); - -#ifdef CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API - -/* Get current PSM settings. - * The use of this API is deprecated. - * Use lte_get_current_psm_sync() instead. - * - * This API can be issued after connect to the LTE network - * with lte_activate_pdn(). - * - * Get the settings negotiated between the modem and the network. - * - * [in] callback: Callback function to notify when - * getting current PSM settings is completed. - * - * On success, 0 is returned. On failure, - * negative value is returned according to . - */ - -int lte_get_current_psm(get_current_psm_cb_t callback); - -#endif /* CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API */ - -/* Get communication quality information. - * - * [out] quality: Quality information. See lte_quality_t - * - * On success, 0 is returned. On failure, - * negative value is returned according to . - */ - -int lte_get_quality_sync(FAR lte_quality_t *quality); - -#ifdef CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API - -/* Get communication quality information. - * The use of this API is deprecated. - * Use lte_get_quality_sync() instead. - * - * [in] callback: Callback function to notify when - * getting quality information is completed. - * - * On success, 0 is returned. On failure, - * negative value is returned according to . - */ - -int lte_get_quality(get_quality_cb_t callback); - -#endif /* CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API */ - -/* Get LTE network cell information. - * - * attention This function is not supported yet. - * - * [out] cellinfo: LTE network cell information. - * See lte_cellinfo_t - * - * On success, 0 is returned. On failure, - * negative value is returned according to . - */ - -int lte_get_cellinfo_sync(FAR lte_cellinfo_t *cellinfo); - -/* Get RAT type - * - * On success, RAT type shown below is returned. - * - LTE_RAT_CATM - * - LTE_RAT_NBIOT - * On failure, negative value is returned according to . - */ - -int lte_get_rat_sync(void); - -/* Set RAT setting - * - * [in] rat: RAT type. Definition is as below. - * - LTE_RAT_CATM - * - LTE_RAT_NBIOT - * [in] persistent: Flag to keep RAT settings - * after power off the modem. - * Definition is as below. - * - LTE_ENABLE - * - LTE_DISABLE - * - * On success, 0 is returned. On failure, - * negative value is returned according to . - */ - -int lte_set_rat_sync(uint8_t rat, bool persistent); - -/* Get RAT information - * - * [out] info: Pointer to the structure that - * stores RAT information - * See lte_ratinfo_t. - * - * On success, 0 is returned. On failure, - * negative value is returned according to . - */ - -int lte_get_ratinfo_sync(FAR lte_ratinfo_t *info); - -/* Acquire the modem wakelock. If any wakelock is acquired, modem can't - * enter to the sleep state. - * Please call this API after calling lte_initialize(). - * Otherwise this API will result in an error. - * Before calling lte_finalize(), must release all wakelocks - * acquired by this API. - * - * On success, return the count of the current modem wakelock. On failure, - * negative value is returned according to . - */ - -int lte_acquire_wakelock(void); - -/* Release the modem wakelock. If all of the wakelock are released, - * modem can enter to the sleep state. - * Please call this API after calling lte_initialize(). - * Otherwise this API will result in an error. - * - * On success, return the count of the current modem wakelock. On failure, - * negative value is returned according to . - */ - -int lte_release_wakelock(void); - -/* Get the number of wakelock counts acquired. - * Please call this API after calling lte_initialize(). - * Otherwise this API will result in an error. - * - * On success, return the count of the current modem wakelock. On failure, - * negative value is returned according to . - */ - -int lte_get_wakelock_count(void); - -/* Send AT command to the modem. - * - * [in] cmd: The AT command data. - * Maximum length is LTE_AT_COMMAND_MAX_LEN. - * AT command is shall begin with "AT" and end with '\r'. - * [in] cmdlen: Length of the AT command data. - * [in] respbuff: The area to store the AT command response. - * [in] respbufflen: Length of the AT command response buffer. - * [in] resplen: The pointer to the area store - * the length of AT command response. - * - * On success, 0 is returned. On failure, - * negative value is returned according to . - */ - -int lte_send_atcmd_sync(FAR const char *cmd, int cmdlen, - FAR char *respbuff, int respbufflen, - FAR int *resplen); - -/* Run factory reset on the modem. - * - * On success, 0 is returned. On failure, - * negative value is returned according to . - */ - -int lte_factory_reset_sync(void); - -/* Set callback function for context save. - * - * [in] callback: Callback function to notify a context data - * when modem entering hibernation mode. - * - * On success, 0 is returned. On failure, - * negative value is returned according to . - */ - -int lte_set_context_save_cb(context_save_cb_t callback); - -/* Resume LTE status from hibernation mode. - * - * [in] res_ctx: Context data for resume daemon. - * - * [in] len : Context data size. - * - * On success, 0 is returned. On failure, - * negative value is returned according to . - */ - -int lte_hibernation_resume(FAR const uint8_t *res_ctx, int len); - -#undef EXTERN -#ifdef __cplusplus -} -#endif - -#endif /* __APPS_INCLUDE_LTE_LTE_API_H */ diff --git a/include/lte/lte_fw_def.h b/include/lte/lte_fw_def.h deleted file mode 100644 index 4b7a78734..000000000 --- a/include/lte/lte_fw_def.h +++ /dev/null @@ -1,32 +0,0 @@ -/**************************************************************************** - * apps/include/lte/lte_fw_def.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __APPS_INCLUDE_LTE_LTE_FW_DEF_H -#define __APPS_INCLUDE_LTE_LTE_FW_DEF_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#endif /* __APPS_INCLUDE_LTE_LTE_FW_DEF_H */ diff --git a/include/lte/lte_fwupdate.h b/include/lte/lte_fwupdate.h deleted file mode 100644 index eff749909..000000000 --- a/include/lte/lte_fwupdate.h +++ /dev/null @@ -1,157 +0,0 @@ -/**************************************************************************** - * apps/include/lte/lte_fwupdate.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __APPS_INCLUDE_LTE_LTE_FWUPDATE_H -#define __APPS_INCLUDE_LTE_LTE_FWUPDATE_H - -/* API call type - * - * | Sync API | - * | ----------------------------- | - * | ltefwupdate_initialize | - * | ltefwupdate_injectrest | - * | ltefwupdate_injected_datasize | - * | ltefwupdate_execute | - * | ltefwupdate_result | - * - * attention - * This API notifies the progress of the update by the callback set by - * lte_set_report_restart(). You must call lte_set_report_restart() - * before lte_power_on(). - */ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -#include "lte_fw_def.h" - -#ifdef __cplusplus -#define EXTERN extern "C" -extern "C" -{ -#else -#define EXTERN extern -#endif - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/* Initialze injection delta image to LTE modem. - * - * Initialize LTE modem delta image injection with some data of top of delta - * image. - * - * [in] initial_data: Pointer to top data of update image. - * [in] len: Size of initial_data. - * - * Return value : Positive value is the injected length. Negative value is - * any error. In error case, the value can be below values. - * - * - LTEFW_RESULT_NOT_ENOUGH_INJECTSTORAGE - * - LTEFW_RESULT_DELTAIMAGE_HDR_CRC_ERROR - * - LTEFW_RESULT_DELTAIMAGE_HDR_UNSUPPORTED - * - EINVAL - * - ENODATA - * - */ - -int ltefwupdate_initialize(FAR const char *initial_data, int len); - -/* Inject rest delta image to LTE modem. - * - * Inject the rest of the delta image following the data injected - * by the ltefwupdate_initialize() and ltefwupdate_injectrest() functions. - * - * [in] rest_data: Pointer to top data of update image. - * [in] len: Size of initial_data. - * - * Return value : Positive value is the injected length. Negative value is - * any error. In error case, the value can be below values. - * - * - LTEFW_RESULT_NOT_ENOUGH_INJECTSTORAGE - * - LTEFW_RESULT_DELTAIMAGE_HDR_CRC_ERROR - * - LTEFW_RESULT_DELTAIMAGE_HDR_UNSUPPORTED - * - EINVAL - * - ENODATA - * - */ - -int ltefwupdate_injectrest(FAR const char *rest_data, int len); - -/* Get length of injected delta image file. - * - * On success, The length of injected data to the modem is returned. - * On failure, a negative value is returned according to . - */ - -int ltefwupdate_injected_datasize(void); - -/* Execute delta update. - * attention When this function is executed, the modem is automatically - * rebooted multiple times. The progress of the update can be checked by - * the callback set by lte_set_report_restart(). - * Before executing this function, the modem must be woken up using - * lte_acquire_wakelock() to safely update the modem. Then - * lte_release_wakelock() is executed when the callback set by - * lte_set_report_restart() is called. - * - * On success, 0 is returned. On failure, - * negative value is returned as below values. - * - * - LTEFW_RESULT_PRECHK_SET_DELTAIMAGE_FAILED - * - LTEFW_RESULT_PRECHK_DELTAIMAGE_MISSING - * - LTEFW_RESULT_PRECHK_OOM - * - LTEFW_RESULT_PRECHK_SIZE_ERROR - * - LTEFW_RESULT_PRECHK_PKG_ERROR - * - LTEFW_RESULT_PRECHK_CRC_ERROR - * - -EPERM - * - */ - -int ltefwupdate_execute(void); - -/* Get the result of delta update. - * Execute this function after LTE_RESTART_MODEM_UPDATED is - * notified to the callback set by lte_set_report_restart(). - * - * On success, 0 is returned. On failure, - * negative value is returned as below values. - - * - LTEFW_RESULT_OK - * - LTEFW_RESULT_DELTAUPDATE_FAILED - * - LTEFW_RESULT_DELTAUPDATE_NORESULT - * - */ - -int ltefwupdate_result(void); - -#undef EXTERN -#ifdef __cplusplus -} -#endif - -#endif /* __APPS_INCLUDE_LTE_LTE_FWUPDATE_H */ diff --git a/include/lte/lte_log.h b/include/lte/lte_log.h deleted file mode 100644 index 41ce2b950..000000000 --- a/include/lte/lte_log.h +++ /dev/null @@ -1,189 +0,0 @@ -/**************************************************************************** - * apps/include/lte/lte_log.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __APPS_INCLUDE_LTE_LTE_LOG_H -#define __APPS_INCLUDE_LTE_LTE_LOG_H - -/* API call type - * - * | Sync API | - * | --------------- | - * | lte_log_collect | - * | lte_log_getlist | - * | lte_log_open | - * | lte_log_close | - * | lte_log_read | - * | lte_log_remove | - * | lte_log_lseek | - */ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -#ifdef __cplusplus -#define EXTERN extern "C" -extern "C" -{ -#else -#define EXTERN extern -#endif - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/* Collect LTE modem FW logs and store them in the LTE modem storage. - * - * [out] output_fname: Buffer to store the name of the saved file. - * If the saved file name is not needed, set it to NULL. - * [in] len: Buffer length for output_fname. Sets LTE_LOG_NAME_LEN, - * except when the saved file name is not needed. - * - * Return value : Returns 0 on success. On error, a negative value is - * returned. The following values may be returned - * in error cases. - * - * - ENOBUFS - * - ENOTSUP - * - */ - -int lte_log_collect(FAR char *output_fname, size_t len); - -/* Get a list of logs stored in the LTE modem storage. - * - * [in] listsize: Number of arrays in which to store file names. The maximum - * number of arrays is LTE_LOG_LIST_SIZE. - * [in] fnamelen: Buffer length for list. Sets LTE_LOG_NAME_LEN. - * [in] list: Buffer to store the list of saved file names. - * - * Return value : Returns the number of stored file names on success. - * On error, a negative value is returned. The following - * values may be returned in error cases. - * - * - EINVAL - * - ENOBUFS - * - ENOTSUP - * - */ - -int lte_log_getlist(size_t listsize, size_t fnamelen, - char list[listsize][fnamelen]); - -#ifdef CONFIG_LTE_LAPI_LOG_ACCESS - -/* Open a log file on LTE modem. - * - * [in] filename: Log file name to open. - * - * Return value : Returns the file descriptor on success. - * On error, a negative value is returned. The following - * values may be returned in error cases. - * - * - EINVAL - * - ENAMETOOLONG - * - ENOTSUP - * - */ - -int lte_log_open(FAR const char *filename); - -/* Close a log file descriptor. - * - * [in] fd: File descriptor. - * - * Return value : Returns the 0 on success. - * On error, a negative value is returned. The following - * values may be returned in error cases. - * - * - EINVAL - * - ENOTSUP - * - */ - -int lte_log_close(int fd); - -/* Read data from log file on LTE modem. - * - * [in] fd: File descriptor. - * [out] buf: Buffer to read. - * [in] len: Read length. - * - * Return value : Returns the number of bytes read on success. - * On error, a negative value is returned. The following - * values may be returned in error cases. - * - * - EINVAL - * - ENOTSUP - * - */ - -ssize_t lte_log_read(int fd, FAR void *buf, size_t len); - -/* Remove a file on LTE modem. - * - * [in] filename: Log file name to remove. - * - * Return value : Returns the 0 on success. - * On error, a negative value is returned. The following - * values may be returned in error cases. - * - * - ENAMETOOLONG - * - ENOTSUP - * - */ - -int lte_log_remove(FAR const char *filename); - -/* Set the file read offset. - * - * [in] fd: File descriptor. - * [in] offset: The number of offset bytes. - * [in] whence: Reference point of offset. - * Available @a whence are as follows. - * - SEEK_SET - * - SEEK_CUR - * - SEEK_END - * - * Return value : Returns the offset from the beginning of the file on - * success. On error, a negative value is returned. - * The following values may be returned in error cases. - * - * - EINVAL - * - ENOTSUP - * - */ - -int lte_log_lseek(int fd, off_t offset, int whence); - -#endif /* CONFIG_LTE_LAPI_LOG_ACCESS */ - -#undef EXTERN -#ifdef __cplusplus -} -#endif - -#endif /* __APPS_INCLUDE_LTE_LTE_LOG_H */ diff --git a/include/lte/lte_lwm2m.h b/include/lte/lte_lwm2m.h deleted file mode 100644 index b9e1abd06..000000000 --- a/include/lte/lte_lwm2m.h +++ /dev/null @@ -1,327 +0,0 @@ -/**************************************************************************** - * apps/include/lte/lte_lwm2m.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __APPS_INCLUDE_LTE_LTE_LWM2M_H -#define __APPS_INCLUDE_LTE_LTE_LWM2M_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include - -#define LWM2MSTUB_RESOURCE_HANDLENOCARE (0) -#define LWM2MSTUB_RESOURCE_HANDLEHOST (1) -#define LWM2MSTUB_RESOURCE_HANDLEMODEMH (2) - -#define LWM2MSTUB_MAX_WRITE_SIZE (1500) -#define LWM2MSTUB_MAX_TOKEN_SIZE (8 * 2 + 1) - -#define LWM2MSTUB_MAX_SERVER_NAME (256) -#define LWM2MSTUB_MAX_DEVID (256) -#define LWM2MSTUB_MAX_SEQKEY (256) - -#define LWM2MSTUB_CONDVALID_MINPERIOD (1<<0) -#define LWM2MSTUB_CONDVALID_MAXPERIOD (1<<1) -#define LWM2MSTUB_CONDVALID_GRATERTHAN (1<<2) -#define LWM2MSTUB_CONDVALID_LESSTHAN (1<<3) -#define LWM2MSTUB_CONDVALID_STEP (1<<4) - -#define LWM2MSTUB_FWUP_PEND_DL (0) -#define LWM2MSTUB_FWUP_PEND_UPD (1) -#define LWM2MSTUB_FWUP_COMP_DL (2) -#define LWM2MSTUB_FWUP_FAIL_DL (3) -#define LWM2MSTUB_FWUP_CANCELED (4) - -#define LWM2MSTUB_CMD_REGISTER (0) -#define LWM2MSTUB_CMD_DEREGISTER (1) -#define LWM2MSTUB_CMD_UPDATERESIGER (2) - -#define LWM2MSTUB_STATE_NOTREGISTERD (0) -#define LWM2MSTUB_STATE_REGISTPENDING (1) -#define LWM2MSTUB_STATE_REGISTERD (2) -#define LWM2MSTUB_STATE_REGISTERFAILED (3) -#define LWM2MSTUB_STATE_UPDATEPENDING (4) -#define LWM2MSTUB_STATE_DEREGISTPENDING (5) -#define LWM2MSTUB_STATE_BSHOLDOFF (6) -#define LWM2MSTUB_STATE_BSREQUESTED (7) -#define LWM2MSTUB_STATE_BSONGOING (8) -#define LWM2MSTUB_STATE_BSDONE (9) -#define LWM2MSTUB_STATE_BSFAILED (10) - -#define LWM2MSTUB_RESOP_READ (0) -#define LWM2MSTUB_RESOP_WRITE (1) -#define LWM2MSTUB_RESOP_RW (2) -#define LWM2MSTUB_RESOP_EXEC (3) - -#define LWM2MSTUB_RESINST_SINGLE (0) -#define LWM2MSTUB_RESINST_MULTI (1) - -#define LWM2MSTUB_RESDATA_NONE (0) -#define LWM2MSTUB_RESDATA_STRING (1) -#define LWM2MSTUB_RESDATA_INT (2) -#define LWM2MSTUB_RESDATA_UNSIGNED (3) -#define LWM2MSTUB_RESDATA_FLOAT (4) -#define LWM2MSTUB_RESDATA_BOOL (5) -#define LWM2MSTUB_RESDATA_OPAQUE (6) -#define LWM2MSTUB_RESDATA_TIME (7) -#define LWM2MSTUB_RESDATA_OBJLINK (8) - -#define LWM2MSTUB_SECUREMODE_PSK (0) -#define LWM2MSTUB_SECUREMODE_RPK (1) -#define LWM2MSTUB_SECUREMODE_CERT (2) -#define LWM2MSTUB_SECUREMODE_NOSEC (3) -#define LWM2MSTUB_SECUREMODE_CERTEST (4) - -#define LWM2MSTUB_CONNECT_REGISTER (0) -#define LWM2MSTUB_CONNECT_DEREGISTER (1) -#define LWM2MSTUB_CONNECT_REREGISTER (2) -#define LWM2MSTUB_CONNECT_BOOTSTRAP (3) - -#define LWM2MSTUB_RESP_CHANGED (0) -#define LWM2MSTUB_RESP_CONTENT (1) -#define LWM2MSTUB_RESP_BADREQ (2) -#define LWM2MSTUB_RESP_UNAUTH (3) -#define LWM2MSTUB_RESP_NOURI (4) -#define LWM2MSTUB_RESP_NOTALLOW (5) -#define LWM2MSTUB_RESP_NOTACCEPT (6) -#define LWM2MSTUB_RESP_UNSUPPORT (7) -#define LWM2MSTUB_RESP_INTERNALERROR (8) - -/* Client received "Write" operation */ - -#define LWM2MSTUB_OP_WRITE (0) - -/* Client received "Execute" operation */ - -#define LWM2MSTUB_OP_EXEC (1) - -/* Client received "Write Attributes" operation */ - -#define LWM2MSTUB_OP_WATTR (4) - -/* Client received "Discover" operation */ - -#define LWM2MSTUB_OP_DISCOVER (5) - -/* Client received "Read" operation */ - -#define LWM2MSTUB_OP_READ (6) - -/* Client received "Observe" operation */ - -#define LWM2MSTUB_OP_OBSERVE (7) - -/* Client received "Cancel observation" operation */ - -#define LWM2MSTUB_OP_CANCELOBS (8) - -/* Client is offline now. */ - -#define LWM2MSTUB_OP_OFFLINE (9) - -/* Client is online now. */ - -#define LWM2MSTUB_OP_ONLINE (10) - -/* Client sent observation notification to a server. */ - -#define LWM2MSTUB_OP_SENDNOTICE (11) - -/* Client received wakeup SMS. */ - -#define LWM2MSTUB_OP_RCVWUP (12) - -/* Client received notification acknowledge. */ - -#define LWM2MSTUB_OP_RCVOBSACK (13) - -/* Client ON: LMM2M client exits Client OFF state - * and tries to re-connect server due to explicitly - * AT Command registration request. - */ - -#define LWM2MSTUB_OP_CLIENTON (14) - -/* Client OFF: LWM2M client has exhausted server connection retries. */ - -#define LWM2MSTUB_OP_CLIENTOFF (15) - -/* Confirmable NOTIFY failed. */ - -#define LWM2MSTUB_OP_FAILNOTIFY (16) - -/* Bootstrap finished and completed successfully. */ - -#define LWM2MSTUB_OP_BSFINISH (20) - -/* Registration finished and completed successfully. - * all server observation requests are cleaned, - * the host should clean host objects observation rules too. - */ - -#define LWM2MSTUB_OP_REGSUCCESS (21) - -/* Register update finished and completed successfully. */ - -#define LWM2MSTUB_OP_REGUPDATED (22) - -/* De-register finished and completed successfully. */ - -#define LWM2MSTUB_OP_DEREGSUCCESS (23) - -/* Notification was not saved and not sent to server */ - -#define LWM2MSTUB_OP_NOSENDNOTICE (24) - -struct lwm2mstub_resource_s -{ - int res_id; - int operation; - int inst_type; - int data_type; - int handl; -}; - -struct lwm2mstub_instance_s -{ - int object_id; - int object_inst; - int res_id; - int res_inst; -}; - -struct lwm2mstub_ovcondition_s -{ - uint8_t valid_mask; - unsigned int min_period; - unsigned int max_period; - double gt_cond; - double lt_cond; - double step_val; -}; - -struct lwm2mstub_serverinfo_s -{ - int object_inst; - int state; - bool bootstrap; - bool nonip; - int security_mode; - uint32_t lifetime; - char server_uri[LWM2MSTUB_MAX_SERVER_NAME]; - char device_id[LWM2MSTUB_MAX_DEVID]; - char security_key[LWM2MSTUB_MAX_SEQKEY]; -}; - -typedef CODE void (*lwm2mstub_write_cb_t)(int seq_no, int srv_id, - FAR struct lwm2mstub_instance_s *inst, FAR char *value, - int len); - -typedef CODE void (*lwm2mstub_read_cb_t)(int seq_no, int srv_id, - FAR struct lwm2mstub_instance_s *inst); - -typedef CODE void (*lwm2mstub_exec_cb_t)(int seq_no, int srv_id, - FAR struct lwm2mstub_instance_s *inst); - -typedef CODE void (*lwm2mstub_ovstart_cb_t)(int seq_no, int srv_id, - FAR struct lwm2mstub_instance_s *inst, FAR char *token, - FAR struct lwm2mstub_ovcondition_s *cond); - -typedef CODE void (*lwm2mstub_ovstop_cb_t)(int seq_no, int srv_id, - FAR struct lwm2mstub_instance_s *inst, FAR char *token); - -typedef CODE void (*lwm2mstub_operation_cb_t)(int event, int srv_id, - FAR struct lwm2mstub_instance_s *inst); - -typedef CODE void (*lwm2mstub_fwupstate_cb_t)(int event); - -#ifdef __cplusplus -#define EXTERN extern "C" -extern "C" -{ -#else -#define EXTERN extern -#endif - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/* On powe on state */ - -int lte_setm2m_endpointname(FAR char *name); -int lte_getm2m_endpointname(FAR char *name, int len); - -int lte_getm2m_servernum(void); -int lte_setm2m_serverinfo(FAR struct lwm2mstub_serverinfo_s *info, int id); -int lte_getm2m_serverinfo(FAR struct lwm2mstub_serverinfo_s *info, int id); - -int lte_getm2m_enabled_objectnum(void); -int lte_getm2m_enabled_objects(FAR uint16_t *objids, int objnum); -int lte_enablem2m_objects(FAR uint16_t *objids, int objnum); - -int lte_getm2m_objresourcenum(uint16_t objid); -int lte_getm2m_objresourceinfo(uint16_t objids, int res_num, - FAR struct lwm2mstub_resource_s *reses); -int lte_setm2m_objectdefinition(uint16_t objids, int res_num, - FAR struct lwm2mstub_resource_s *reses); -bool lte_getm2m_qmode(void); -int lte_setm2m_qmode(bool en); - -int lte_apply_m2msetting(void); - -/* After attached */ - -int lte_m2m_connection(int cmd); - -int lte_set_report_m2mwrite(lwm2mstub_write_cb_t cb); -int lte_set_report_m2mread(lwm2mstub_read_cb_t cb); -int lte_set_report_m2mexec(lwm2mstub_exec_cb_t cb); -int lte_set_report_m2movstart(lwm2mstub_ovstart_cb_t cb); -int lte_set_report_m2movstop(lwm2mstub_ovstop_cb_t cb); -int lte_set_report_m2moperation(lwm2mstub_operation_cb_t cb); -int lte_set_report_m2mfwupdate(lwm2mstub_fwupstate_cb_t cb); - -int lte_m2m_readresponse(int seq_no, - FAR struct lwm2mstub_instance_s *inst, - int resp, FAR char *readvalue, int len); -int lte_m2m_writeresponse(int seq_no, - FAR struct lwm2mstub_instance_s *inst, - int resp); -int lte_m2m_executeresp(int seq_no, - FAR struct lwm2mstub_instance_s *inst, - int resp); -int lte_m2m_observeresp(int seq_no, int resp); - -int lte_m2m_observeupdate(FAR char *token, - FAR struct lwm2mstub_instance_s *inst, - FAR char *value, int len); - -#undef EXTERN -#ifdef __cplusplus -} -#endif - -#endif /* __APPS_INCLUDE_LTE_LTE_LWM2M_H */ diff --git a/include/modbus/mb.h b/include/modbus/mb.h index bbbf26b6c..617f33c59 100644 --- a/include/modbus/mb.h +++ b/include/modbus/mb.h @@ -1,8 +1,9 @@ /**************************************************************************** * apps/include/modbus/mb.h * - * SPDX-License-Identifier: BSD-3-Clause - * SPDX-FileCopyrightText: 2006 Christian Walter + * FreeModbus Library: A portable Modbus implementation for Modbus ASCII/RTU. + * Copyright (c) 2006 Christian Walter + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/include/modbus/mb_m.h b/include/modbus/mb_m.h index 03ffe07d2..7390320a2 100644 --- a/include/modbus/mb_m.h +++ b/include/modbus/mb_m.h @@ -1,8 +1,9 @@ /**************************************************************************** * apps/include/modbus/mb_m.h * - * SPDX-License-Identifier: BSD-3-Clause - * SPDX-FileCopyrightText: 2013 Armink + * FreeModbus Library: A portable Modbus implementation for Modbus ASCII/RTU. + * Copyright (C) 2013 Armink + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/include/modbus/mbframe.h b/include/modbus/mbframe.h index 999fdc4e3..40312ff51 100644 --- a/include/modbus/mbframe.h +++ b/include/modbus/mbframe.h @@ -1,8 +1,9 @@ /**************************************************************************** * apps/include/modbus/mbframe.h * - * SPDX-License-Identifier: BSD-3-Clause - * SPDX-FileCopyrightText: 2006 Christian Walter + * FreeModbus Library: A portable Modbus implementation for Modbus ASCII/RTU. + * Copyright (c) 2006 Christian Walter + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/include/modbus/mbfunc.h b/include/modbus/mbfunc.h index d61fed4b6..82f4ee8cc 100644 --- a/include/modbus/mbfunc.h +++ b/include/modbus/mbfunc.h @@ -1,8 +1,9 @@ /**************************************************************************** * apps/include/modbus/mbfunc.h * - * SPDX-License-Identifier: BSD-3-Clause - * SPDX-FileCopyrightText: 2006 Christian Walter + * FreeModbus Library: A portable Modbus implementation for Modbus ASCII/RTU. + * Copyright (c) 2006 Christian Walter + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/include/modbus/mbport.h b/include/modbus/mbport.h index 45019dfee..ab4a374f9 100644 --- a/include/modbus/mbport.h +++ b/include/modbus/mbport.h @@ -1,8 +1,9 @@ /**************************************************************************** * apps/include/modbus/mbport.h * - * SPDX-License-Identifier: BSD-3-Clause - * SPDX-FileCopyrightText: 2006 Christian Walter + * FreeModbus Library: A portable Modbus implementation for Modbus ASCII/RTU. + * Copyright (c) 2006 Christian Walter + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -125,7 +126,7 @@ bool xMBPortEventGet(eMBEventType *eEvent); bool xMBMasterPortEventInit(void); bool xMBMasterPortEventPost(eMBMasterEventType eEvent); -bool xMBMasterPortEventGet(eMBMasterEventType *eEvent); +bool xMBMasterPortEventGet(eMBMasterEventType * eEvent); void vMBMasterOsResInit(void); bool xMBMasterRunResTake(int32_t time); void vMBMasterRunResRelease(void); @@ -137,7 +138,7 @@ bool xMBPortSerialInit(uint8_t ucPort, speed_t ulBaudRate, void vMBPortClose(void); void xMBPortSerialClose(void); void vMBPortSerialEnable(bool xRxEnable, bool xTxEnable); -bool xMBPortSerialGetByte(int8_t *pucByte); +bool xMBPortSerialGetByte(int8_t * pucByte); bool xMBPortSerialPutByte(int8_t ucByte); bool xMBMasterPortSerialInit(uint8_t ucPort, speed_t ulBaudRate, @@ -145,7 +146,7 @@ bool xMBMasterPortSerialInit(uint8_t ucPort, speed_t ulBaudRate, void vMBMasterPortClose(void); void xMBMasterPortSerialClose(void); void vMBMasterPortSerialEnable(bool xRxEnable, bool xTxEnable); -bool xMBMasterPortSerialGetByte(int8_t *pucByte); +bool xMBMasterPortSerialGetByte(int8_t * pucByte); bool xMBMasterPortSerialPutByte(int8_t ucByte); /* Timers functions */ diff --git a/include/modbus/mbproto.h b/include/modbus/mbproto.h index dded90df0..e42e7a284 100644 --- a/include/modbus/mbproto.h +++ b/include/modbus/mbproto.h @@ -1,8 +1,9 @@ /**************************************************************************** * apps/include/modbus/mbproto.h * - * SPDX-License-Identifier: BSD-3-Clause - * SPDX-FileCopyrightText: 2006 Christian Walter + * FreeModbus Library: A portable Modbus implementation for Modbus ASCII/RTU. + * Copyright (c) 2006 Christian Walter + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/include/modbus/mbutils.h b/include/modbus/mbutils.h index 0da543437..1bb33c53c 100644 --- a/include/modbus/mbutils.h +++ b/include/modbus/mbutils.h @@ -1,8 +1,9 @@ /**************************************************************************** * apps/include/modbus/mbutils.h * - * SPDX-License-Identifier: BSD-3-Clause - * SPDX-FileCopyrightText: 2006 Christian Walter + * FreeModbus Library: A portable Modbus implementation for Modbus ASCII/RTU. + * Copyright (c) 2006 Christian Walter + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/include/netutils/base64.h b/include/netutils/base64.h index 5f146d7e8..d44600333 100644 --- a/include/netutils/base64.h +++ b/include/netutils/base64.h @@ -1,10 +1,15 @@ /**************************************************************************** * apps/include/netutils/base64.h * - * SPDX-License-Identifier: BSD-3-Clause - * SPDX-FileCopyrightText: 2012 Gregory Nutt - * SPDX-FileCopyrightText: 2005 Jouni Malinen - * SPDX-FileContributor: Darcy Gong + * This file is part of the NuttX RTOS: + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Darcy Gong + * + * Reference: + * + * Base64 encoding/decoding (RFC1341) + * Copyright (c) 2005, Jouni Malinen * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as @@ -30,17 +35,17 @@ * may be used to endorse or promote products derived from this software * without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. * ****************************************************************************/ @@ -73,10 +78,6 @@ FAR void *base64w_encode(FAR const void *src, size_t len, FAR void *dst, FAR size_t *out_len); FAR void *base64w_decode(FAR const void *src, size_t len, FAR void *dst, FAR size_t *out_len); -int base64url_encode(FAR const void *src, size_t len, FAR char *dst, - size_t dstlen); -int base64url_decode(FAR const char *src, FAR void *dst, size_t dstmax, - FAR size_t *out_len); #endif /* CONFIG_CODECS_BASE64 */ #ifdef __cplusplus diff --git a/include/netutils/chat.h b/include/netutils/chat.h index fabd3f8cd..b1ff0a5c3 100644 --- a/include/netutils/chat.h +++ b/include/netutils/chat.h @@ -1,9 +1,8 @@ /**************************************************************************** * apps/include/netutils/chat.h * - * SPDX-License-Identifier: BSD-3-Clause - * SPDX-FileCopyrightText: 2016 Vladimir Komendantskiy. All rights reserved. - * SPDX-FileContributor: Vladimir Komendantskiy + * Copyright (C) 2016 Vladimir Komendantskiy. All rights reserved. + * Author: Vladimir Komendantskiy * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/include/netutils/cmux.h b/include/netutils/cmux.h deleted file mode 100644 index 8bbf2e1f0..000000000 --- a/include/netutils/cmux.h +++ /dev/null @@ -1,66 +0,0 @@ -/**************************************************************************** - * apps/include/netutils/cmux.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __APPS_INCLUDE_NETUTILS_CMUX_H -#define __APPS_INCLUDE_NETUTILS_CMUX_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include -#include - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -struct cmux_settings_s -{ - FAR const char *tty_name; - FAR const char *script; - int total_channels; -}; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -#undef EXTERN -#if defined(__cplusplus) -#define EXTERN extern "C" -extern "C" -{ -#else -#define EXTERN extern -#endif - -int cmux_create(struct cmux_settings_s *settings); - -#undef EXTERN -#ifdef __cplusplus -} -#endif - -#endif /* __APPS_INCLUDE_NETUTILS_CMUX_H */ \ No newline at end of file diff --git a/include/netutils/curl4nx.h b/include/netutils/curl4nx.h index 8e10144b3..cb5d25e32 100644 --- a/include/netutils/curl4nx.h +++ b/include/netutils/curl4nx.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/netutils/curl4nx.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/netutils/dhcp6c.h b/include/netutils/dhcp6c.h deleted file mode 100644 index 4d184417e..000000000 --- a/include/netutils/dhcp6c.h +++ /dev/null @@ -1,78 +0,0 @@ -/**************************************************************************** - * apps/include/netutils/dhcp6c.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __APPS_INCLUDE_NETUTILS_DHCP6C_H -#define __APPS_INCLUDE_NETUTILS_DHCP6C_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -struct dhcp6c_state -{ - struct in6_addr addr; - struct in6_addr pd; /* prefix address */ - struct in6_addr dns; - struct in6_addr netmask; - uint8_t pl; /* prefix len */ - uint32_t t1; - uint32_t t2; -}; - -typedef void (*dhcp6c_callback_t)(FAR struct dhcp6c_state *presult); - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -#ifdef __cplusplus -#define EXTERN extern "C" -extern "C" -{ -#else -#define EXTERN extern -#endif - -FAR void *dhcp6c_open(FAR const char *interface); -int dhcp6c_request(FAR void *handle, FAR struct dhcp6c_state *presult); -int dhcp6c_request_async(FAR void *handle, dhcp6c_callback_t callback); -void dhcp6c_cancel(FAR void *handle); -void dhcp6c_close(FAR void *handle); - -#undef EXTERN -#ifdef __cplusplus -} -#endif - -#endif /* __APPS_INCLUDE_NETUTILS_DHCP6C_H */ diff --git a/include/netutils/dhcpc.h b/include/netutils/dhcpc.h index b17d6f368..8ec670723 100644 --- a/include/netutils/dhcpc.h +++ b/include/netutils/dhcpc.h @@ -1,10 +1,13 @@ /**************************************************************************** * apps/include/netutils/dhcpc.h * - * SPDX-License-Identifier: BSD-3-Clause - * SPDX-FileCopyrightText: 2007, 2009-2011, 2015 Gregory Nutt - * SPDX-FileCopyrightText: 2005 Swedish Institute of Computer Science - * SPDX-FileContributor: Gregory Nutt + * Copyright (C) 2007, 2009-2011, 2015 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * This logic was leveraged from uIP which also has a BSD-style license: + * + * Copyright (c) 2005, Swedish Institute of Computer Science + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -39,7 +42,6 @@ * Included Files ****************************************************************************/ -#include #include #include @@ -47,18 +49,6 @@ * Pre-processor Definitions ****************************************************************************/ -/* Provide a default value for CONFIG_NETDB_DNSSERVER_NAMESERVERS if - * CONFIG_NETDB_DNSCLIENT is not enabled. - */ - -#if !defined(CONFIG_NETDB_DNSSERVER_NAMESERVERS) -# define CONFIG_NETDB_DNSSERVER_NAMESERVERS 1 -#endif - -#if !defined(CONFIG_NETUTILS_DHCPC_NTP_SERVERS) -# define CONFIG_NETUTILS_DHCPC_NTP_SERVERS 1 -#endif - /**************************************************************************** * Public Types ****************************************************************************/ @@ -68,14 +58,9 @@ struct dhcpc_state struct in_addr serverid; struct in_addr ipaddr; struct in_addr netmask; - struct in_addr dnsaddr[CONFIG_NETDB_DNSSERVER_NAMESERVERS]; - uint8_t num_dnsaddr; /* Number of DNS addresses received */ - struct in_addr ntpaddr[CONFIG_NETUTILS_DHCPC_NTP_SERVERS]; - uint8_t num_ntpaddr; /* Number of NTP addresses received */ + struct in_addr dnsaddr; struct in_addr default_router; uint32_t lease_time; /* Lease expires in this number of seconds */ - uint32_t renewal_time; /* Seconds to transition to RENEW state(T1) */ - uint32_t rebinding_time; /* Seconds to transition to REBIND state(T2) */ }; typedef void (*dhcpc_callback_t)(FAR struct dhcpc_state *presult); @@ -96,7 +81,6 @@ FAR void *dhcpc_open(FAR const char *interface, FAR const void *mac_addr, int mac_len); int dhcpc_request(FAR void *handle, FAR struct dhcpc_state *presult); int dhcpc_request_async(FAR void *handle, dhcpc_callback_t callback); -int dhcpc_release(FAR void *handle, FAR struct dhcpc_state *presult); void dhcpc_cancel(FAR void *handle); void dhcpc_close(FAR void *handle); diff --git a/include/netutils/dhcpd.h b/include/netutils/dhcpd.h index b1061b8a4..5c8209c18 100644 --- a/include/netutils/dhcpd.h +++ b/include/netutils/dhcpd.h @@ -1,10 +1,13 @@ /**************************************************************************** * apps/include/netutils/dhcpd.h * - * SPDX-License-Identifier: BSD-3-Clause - * SPDX-FileCopyrightText: 2007, 2009-2011, 2015 Gregory Nutt - * SPDX-FileCopyrightText: 2005 Swedish Institute of Computer Science - * SPDX-FileContributor: Gregory Nutt + * Copyright (C) 2007, 2009, 2011, 2015 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * This logic was leveraged from uIP which also has a BSD-style license: + * + * Copyright (c) 2005, Swedish Institute of Computer Science + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -39,8 +42,6 @@ * Included Files ****************************************************************************/ -#include - /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ @@ -64,10 +65,6 @@ extern "C" int dhcpd_run(FAR const char *interface); int dhcpd_start(FAR const char *interface); int dhcpd_stop(void); -int dhcpd_set_startip(in_addr_t startip); -int dhcpd_set_routerip(in_addr_t routerip); -int dhcpd_set_netmask(in_addr_t netmask); -int dhcpd_set_dnsip(in_addr_t dnsip); #undef EXTERN #ifdef __cplusplus diff --git a/include/netutils/discover.h b/include/netutils/discover.h index b7423197d..535ba8101 100644 --- a/include/netutils/discover.h +++ b/include/netutils/discover.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/netutils/discover.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/netutils/esp8266.h b/include/netutils/esp8266.h index d36bd73c8..c6d2c2c42 100644 --- a/include/netutils/esp8266.h +++ b/include/netutils/esp8266.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/netutils/esp8266.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -37,8 +35,8 @@ * Pre-processor Definitions ****************************************************************************/ -#define LESP_SSID_SIZE 32 /* Number of character max of SSID (null char not included) */ -#define LESP_BSSID_SIZE 6 +#define lespSSID_SIZE 32 /* Number of character max of SSID (null char not included) */ +#define lespBSSID_SIZE 6 #define lespIP(x1,x2,x3,x4) ((x1) << 24 | (x2) << 16 | (x3) << 8 | (x4) << 0) @@ -48,26 +46,26 @@ typedef enum { - LESP_MODE_AP = 0, - LESP_MODE_STATION = 1, - LESP_MODE_BOTH = 2 + lesp_eMODE_AP = 0, + lesp_eMODE_STATION = 1, + lesp_eMODE_BOTH = 2 } lesp_mode_t; typedef enum { - LESP_SECURITY_NONE = 0, - LESP_SECURITY_WEP, - LESP_SECURITY_WPA_PSK, - LESP_SECURITY_WPA2_PSK, - LESP_SECURITY_WPA_WPA2_PSK, - LESP_SECURITY_NBR + lesp_eSECURITY_NONE = 0, + lesp_eSECURITY_WEP, + lesp_eSECURITY_WPA_PSK, + lesp_eSECURITY_WPA2_PSK, + lesp_eSECURITY_WPA_WPA2_PSK, + lesp_eSECURITY_NBR } lesp_security_t; typedef struct { lesp_security_t security; - char ssid[LESP_SSID_SIZE + 1]; /* +1 for null char */ - uint8_t bssid[LESP_BSSID_SIZE]; + char ssid[lespSSID_SIZE + 1]; /* +1 for null char */ + uint8_t bssid[lespBSSID_SIZE]; int rssi; int channel; } lesp_ap_t; @@ -77,7 +75,6 @@ typedef struct ****************************************************************************/ int lesp_initialize(void); -int lesp_finalize(void); int lesp_soft_reset(void); const char *lesp_security_to_str(lesp_security_t security); diff --git a/include/netutils/ftpc.h b/include/netutils/ftpc.h index 0216b5faf..fe1be978d 100644 --- a/include/netutils/ftpc.h +++ b/include/netutils/ftpc.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/netutils/ftpc.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/netutils/ftpd.h b/include/netutils/ftpd.h index 30f18cd32..91bcb371a 100644 --- a/include/netutils/ftpd.h +++ b/include/netutils/ftpd.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/netutils/ftpd.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -29,8 +27,6 @@ #include -#include - #include /**************************************************************************** @@ -121,7 +117,6 @@ extern "C" * used to run the server. * * Input Parameters: - * port - The port that the server will listen to. * family - The type of INET family to use when opening the socket. * AF_INET and AF_INET6 are supported. * @@ -131,7 +126,7 @@ extern "C" * ****************************************************************************/ -FTPD_SESSION ftpd_open(int port, sa_family_t family); +FTPD_SESSION ftpd_open(sa_family_t family); /**************************************************************************** * Name: ftpd_adduser diff --git a/include/netutils/httpd.h b/include/netutils/httpd.h index e9dc61f75..2a3f261a4 100644 --- a/include/netutils/httpd.h +++ b/include/netutils/httpd.h @@ -1,11 +1,15 @@ /**************************************************************************** * apps/include/netutils/httpd.h * - * SPDX-License-Identifier: BSD-3-Clause - * SPDX-FileCopyrightText: 2007, 2009-2011, 2014, 2018 Gregory Nutt - * SPDX-FileCopyrightText: 2001-2005, Adam Dunkels. - * SPDX-FileContributor: Gregory Nutt - * SPDX-FileContributor: Adam Dunkels + * Copyright (C) 2007, 2009, 2011-2012, 2014, 2018 Gregory Nutt. All + * rights reserved. + * Author: Gregory Nutt + * + * Based on uIP which also has a BSD style license: + * + * Author: Adam Dunkels + * Copyright (c) 2001-2005, Adam Dunkels. + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -68,10 +72,6 @@ * MSS value. Here we arbitrarily select the minimum MSS for that case. */ -#ifndef MIN_TCP_MSS -# error "You need to enable TCP/IP (i.e. CONFIG_NET_TCP) to use HTTPD" -#endif - #define HTTPD_IOBUFFER_SIZE (3*MIN_TCP_MSS) /* This is the maximum size of a file path */ @@ -96,7 +96,7 @@ struct httpd_fs_file { - FAR char *data; + char *data; int len; #if defined(CONFIG_NETUTILS_HTTPD_MMAP) || \ defined(CONFIG_NETUTILS_HTTPD_SENDFILE) @@ -109,17 +109,17 @@ struct httpd_fs_file struct httpd_state { - char ht_buffer[HTTPD_IOBUFFER_SIZE]; /* recv() buffer */ - char ht_filename[HTTPD_MAX_FILENAME]; /* filename from GET command */ + char ht_buffer[HTTPD_IOBUFFER_SIZE]; /* recv() buffer */ + char ht_filename[HTTPD_MAX_FILENAME]; /* filename from GET command */ #ifndef CONFIG_NETUTILS_HTTPD_KEEPALIVE_DISABLE - bool ht_keepalive; /* Connection: keep-alive */ + bool ht_keepalive; /* Connection: keep-alive */ #endif #if defined(CONFIG_NETUTILS_HTTPD_ENABLE_CHUNKED_ENCODING) - bool ht_chunked; /* Server uses chunked encoding for tx */ + bool ht_chunked; /* Server uses chunked encoding for tx */ #endif - struct httpd_fs_file ht_file; /* Fake file data to send */ - int ht_sockfd; /* The socket descriptor from accept() */ - FAR char *ht_scriptptr; + struct httpd_fs_file ht_file; /* Fake file data to send */ + int ht_sockfd; /* The socket descriptor from accept() */ + char *ht_scriptptr; uint16_t ht_scriptlen; uint16_t ht_sndlen; }; @@ -146,12 +146,12 @@ struct httpd_fsdata_file_noconst #endif }; -typedef void CODE (*httpd_cgifunction)(FAR struct httpd_state *, FAR char *); +typedef void (*httpd_cgifunction)(struct httpd_state *, char *); struct httpd_cgi_call { - FAR struct httpd_cgi_call *next; - FAR const char *name; + struct httpd_cgi_call *next; + const char *name; httpd_cgifunction function; }; @@ -222,7 +222,7 @@ int httpd_listen(void); * ****************************************************************************/ -void httpd_cgi_register(FAR struct httpd_cgi_call *cgi_call); +void httpd_cgi_register(struct httpd_cgi_call *cgi_call); /**************************************************************************** * Name: httpd_send_datachunk @@ -244,7 +244,7 @@ void httpd_cgi_register(FAR struct httpd_cgi_call *cgi_call); * ****************************************************************************/ -int httpd_send_datachunk(int sockfd, FAR void *data, int len, bool chunked); +int httpd_send_datachunk(int sockfd, void *data, int len, bool chunked); /**************************************************************************** * Name: httpd_send_headers @@ -263,10 +263,10 @@ int httpd_send_datachunk(int sockfd, FAR void *data, int len, bool chunked); * ****************************************************************************/ -int httpd_send_headers(FAR struct httpd_state *pstate, int status, int len); +int httpd_send_headers(struct httpd_state *pstate, int status, int len); #ifdef CONFIG_NETUTILS_HTTPDFSSTATS -uint16_t httpd_fs_count(FAR char *name); +uint16_t httpd_fs_count(char *name); #endif #ifdef CONFIG_NETUTILS_HTTPD_DIRLIST diff --git a/include/netutils/icmp_ping.h b/include/netutils/icmp_ping.h index d9164afc1..93652c883 100644 --- a/include/netutils/icmp_ping.h +++ b/include/netutils/icmp_ping.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/netutils/icmp_ping.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -50,8 +48,6 @@ #define ICMP_E_POLL -11 /* extra: error code */ #define ICMP_E_RECVFROM -13 /* extra: error code */ #define ICMP_E_RECVSMALL -15 /* extra: recv bytes */ -#define ICMP_E_BINDDEV -17 /* extra: error bind */ -#define ICMP_E_FILTER -19 /* extra: error filter */ /* Negative even number represent warning(recoverable) */ @@ -72,9 +68,6 @@ struct ping_result_s; struct ping_info_s { FAR const char *hostname; /* Host name to ping */ -#ifdef CONFIG_NET_BINDTODEVICE - FAR const char *devname; /* Device name to bind */ -#endif uint16_t count; /* Number of pings requested */ uint16_t datalen; /* Number of bytes to be sent */ uint16_t delay; /* Deciseconds to delay between pings */ @@ -86,7 +79,7 @@ struct ping_info_s struct ping_result_s { int code; /* Notice code ICMP_I/E/W_XXX */ - long extra; /* Extra information for code */ + int extra; /* Extra information for code */ struct in_addr dest; /* Target address to ping */ uint16_t nrequests; /* Number of ICMP ECHO requests sent */ uint16_t nreplies; /* Number of matching ICMP ECHO replies received */ diff --git a/include/netutils/icmpv6_ping.h b/include/netutils/icmpv6_ping.h index 33db0fc6f..e3014d8bb 100644 --- a/include/netutils/icmpv6_ping.h +++ b/include/netutils/icmpv6_ping.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/netutils/icmpv6_ping.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -50,7 +48,6 @@ #define ICMPv6_E_POLL -11 /* extra: error code */ #define ICMPv6_E_RECVFROM -13 /* extra: error code */ #define ICMPv6_E_RECVSMALL -15 /* extra: recv bytes */ -#define ICMPV6_E_BINDDEV -17 /* extra: error bind */ /* Negative even number represent warning(recoverable) */ @@ -71,9 +68,6 @@ struct ping6_result_s; struct ping6_info_s { FAR const char *hostname; /* Host name to ping */ -#ifdef CONFIG_NET_BINDTODEVICE - FAR const char *devname; /* Device name to bind */ -#endif uint16_t count; /* Number of pings requested */ uint16_t datalen; /* Number of bytes to be sent */ uint16_t delay; /* Deciseconds to delay between pings */ @@ -85,7 +79,7 @@ struct ping6_info_s struct ping6_result_s { int code; /* Notice code ICMPv6_I/E/W_XXX */ - long extra; /* Extra information for code */ + int extra; /* Extra information for code */ struct in6_addr dest; /* Target address to ping */ uint16_t nrequests; /* Number of ICMP ECHO requests sent */ uint16_t nreplies; /* Number of matching ICMP ECHO replies received */ diff --git a/include/netutils/ipmsfilter.h b/include/netutils/ipmsfilter.h index edab65fe2..a96c7f0f6 100644 --- a/include/netutils/ipmsfilter.h +++ b/include/netutils/ipmsfilter.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/netutils/ipmsfilter.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/netutils/md5.h b/include/netutils/md5.h index f64173bfa..ff10c4e2d 100644 --- a/include/netutils/md5.h +++ b/include/netutils/md5.h @@ -1,34 +1,57 @@ /**************************************************************************** * apps/include/netutils/md5.h * - * SPDX-License-Identifier: BSD-3-Clause - * SPDX-FileCopyrightText: 2012 Gregory Nutt - * SPDX-FileContributor: Darcy Gong + * This file is part of the NuttX RTOS: * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Darcy Gong * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the Institute nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * Reference: * - * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. + * This code implements the MD5 message-digest algorithm. + * The algorithm is due to Ron Rivest. This code was + * written by Colin Plumb in 1993, no copyright is claimed. + * + * This code is in the public domain; do with it what you wish. + * + * Equivalent code is available from RSA Data Security, Inc. + * This code has been tested against that, and is equivalent, + * except that you don't need to include two pages of legalese + * with every copy. + * + * To compute the message digest of a chunk of bytes, declare an + * md5_context_s structure, pass it to md5_init, call md5_update as + * needed on buffers full of bytes, and then call md5_final, which + * will fill a supplied 16-byte array with the digest. + * + * See README and COPYING for more details. + * + * And is re-released under the NuttX modified BSD license: + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. * ****************************************************************************/ @@ -72,7 +95,6 @@ void md5_final(unsigned char digest[16], struct md5_context_s *context); void md5_transform(uint32_t buf[4], uint32_t const in[16]); void md5_sum(const uint8_t *addr, const size_t len, uint8_t *mac); -int md5_file(const char *path, uint8_t *mac); char *md5_hash(const uint8_t *addr, const size_t len); #ifdef __cplusplus diff --git a/include/netutils/netinit.h b/include/netutils/netinit.h index 320fa1498..adb5ba256 100644 --- a/include/netutils/netinit.h +++ b/include/netutils/netinit.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/netutils/netinit.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -57,6 +55,10 @@ # define CONFIG_NETINIT_DNSIPADDR CONFIG_NETINIT_DRIPADDR #endif +#ifndef CONFIG_NETINIT_MACADDR +# define CONFIG_NETINIT_MACADDR 0x00e0deadbeef +#endif + #if !defined(CONFIG_NETINIT_THREAD) || !defined(CONFIG_ARCH_PHY_INTERRUPT) || \ !defined(CONFIG_NETDEV_PHY_IOCTL) || !defined(CONFIG_NET_UDP) # undef CONFIG_NETINIT_MONITOR @@ -67,7 +69,7 @@ #endif #ifndef CONFIG_NETINIT_SIGNO -# define CONFIG_NETINIT_SIGNO 32 +# define CONFIG_NETINIT_SIGNO 18 #endif #ifndef CONFIG_NETINIT_THREAD_STACKSIZE diff --git a/include/netutils/netlib.h b/include/netutils/netlib.h index d76c93e96..8b18af6cc 100644 --- a/include/netutils/netlib.h +++ b/include/netutils/netlib.h @@ -1,11 +1,17 @@ /**************************************************************************** * apps/include/netutils/netlib.h + * Various non-standard APIs to support netutils. All non-standard and + * intended only for internal use. * - * SPDX-License-Identifier: BSD-3-Clause - * SPDX-FileCopyrightText: 2007, 2009, 2011, 2015, 2017 Gregory Nutt. - * SPDX-FileCopyrightText: 2002 Adam Dunkels. - * SPDX-FileContributor: Gregory Nutt - * SPDX-FileContributor: Adam Dunkels + * Copyright (C) 2007, 2009, 2011, 2015, 2017 Gregory Nutt. All rights + * reserved. + * Author: Gregory Nutt + * + * Some of these APIs derive from uIP. uIP also has a BSD style license: + * + * Author: Adam Dunkels + * Copyright (c) 2002, Adam Dunkels. + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -52,15 +58,8 @@ #include #include -#include -#include #include -#ifdef CONFIG_NET_IPTABLES -# include -# include -#endif - /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ @@ -124,60 +123,6 @@ struct netlib_device_s }; #endif /* CONFIG_NETLINK_ROUTE*/ -#ifdef CONFIG_NETLINK_NETFILTER -/* Describes one connection returned by netlib_get_conntrack() */ - -union netlib_conntrack_addr_u -{ -#ifdef CONFIG_NET_IPv4 - struct in_addr ipv4; -#endif -#ifdef CONFIG_NET_IPv6 - struct in6_addr ipv6; -#endif -}; - -struct netlib_conntrack_tuple_s -{ - union netlib_conntrack_addr_u src; - union netlib_conntrack_addr_u dst; - - union - { - struct - { - uint16_t sport; - uint16_t dport; - } tcp; /* and udp */ - - struct - { - uint16_t id; - uint8_t type; - uint8_t code; - } icmp; /* and icmp6 */ - } l4; - - uint8_t l4proto; -}; - -struct netlib_conntrack_s -{ - struct netlib_conntrack_tuple_s orig; - struct netlib_conntrack_tuple_s reply; - - sa_family_t family; /* AF_INET or AF_INET6 */ - uint8_t type; /* IPCTNL_MSG_CT_* */ -}; - -/* There might be many conntrack entries, so we don't use array of data, but - * use callback instead. - */ - -typedef CODE int (*netlib_conntrack_cb_t)(FAR struct netlib_conntrack_s *ct); - -#endif /* CONFIG_NETLINK_NETFILTER */ - #ifdef CONFIG_NETUTILS_NETLIB_GENERICURLPARSER struct url_s { @@ -203,11 +148,6 @@ struct url_s }; #endif -#ifdef CONFIG_NETUTILS_DHCPC -typedef CODE void (*netlib_dhcp_ntp_callback_t) - (FAR const char *ntp_server_list, FAR void *arg); -#endif - /**************************************************************************** * Public Data ****************************************************************************/ @@ -252,44 +192,6 @@ ssize_t netlib_get_devices(FAR struct netlib_device_s *devlist, bool netlib_ipv4addrconv(FAR const char *addrstr, FAR uint8_t *addr); bool netlib_ethaddrconv(FAR const char *hwstr, FAR uint8_t *hw); -#ifdef CONFIG_NETUTILS_DHCPC -/**************************************************************************** - * Name: netlib_set_ntp_servers_from_dhcp - * - * Description: - * Update the currently active DHCP option 42 NTP server list. The list - * contains semicolon-separated hostnames or addresses. Passing NULL or - * an empty string clears the DHCP-provided list. - * - ****************************************************************************/ - -int netlib_set_ntp_servers_from_dhcp(FAR const char *ntp_server_list); - -/**************************************************************************** - * Name: netlib_register_dhcp_ntp_callback - * - * Description: - * Register a callback to receive DHCP option 42 NTP server list updates. - * The current list, if any, is replayed immediately after registration. - * Only one callback may be registered at a time. - * - ****************************************************************************/ - -int netlib_register_dhcp_ntp_callback(netlib_dhcp_ntp_callback_t callback, - FAR void *arg); - -/**************************************************************************** - * Name: netlib_unregister_dhcp_ntp_callback - * - * Description: - * Unregister a previously registered DHCP option 42 NTP update callback. - * - ****************************************************************************/ - -int netlib_unregister_dhcp_ntp_callback(netlib_dhcp_ntp_callback_t callback, - FAR void *arg); -#endif - #ifdef CONFIG_NET_ETHERNET /* Get and set IP/MAC addresses (Ethernet L2 only) */ @@ -337,21 +239,7 @@ int netlib_get_ipv4netmask(FAR const char *ifname, FAR struct in_addr *addr); int netlib_ipv4adaptor(in_addr_t destipaddr, FAR in_addr_t *srcipaddr); #endif -/* We support multiple IPv6 addresses on a single interface. - * Recommend to use netlib_add/del_ipv6addr to manage them, by which you - * don't need to care about the slot it stored. - * - * Previous interfaces can still work, the ifname can be :, - * e.g. eth0:0 stands for managing the secondary address on eth0 - */ - #ifdef CONFIG_NET_IPv6 -# ifdef CONFIG_NETDEV_MULTIPLE_IPv6 -int netlib_add_ipv6addr(FAR const char *ifname, - FAR const struct in6_addr *addr, uint8_t preflen); -int netlib_del_ipv6addr(FAR const char *ifname, - FAR const struct in6_addr *addr, uint8_t preflen); -# endif int netlib_get_ipv6addr(FAR const char *ifname, FAR struct in6_addr *addr); int netlib_set_ipv6addr(FAR const char *ifname, FAR const struct in6_addr *addr); @@ -377,24 +265,17 @@ int netlib_getessid(FAR const char *ifname, FAR char *essid, size_t idlen); int netlib_setessid(FAR const char *ifname, FAR const char *essid); #endif -#ifdef CONFIG_NET_VLAN -int netlib_add_vlan(FAR const char *ifname, int vlanid, int prio); -int netlib_del_vlan(FAR const char *vlanif); -#endif - #ifdef CONFIG_NET_ARP /* ARP Table Support */ -int netlib_del_arpmapping(FAR const struct sockaddr_in *inaddr, - FAR const char *ifname); +int netlib_del_arpmapping(FAR const struct sockaddr_in *inaddr); int netlib_get_arpmapping(FAR const struct sockaddr_in *inaddr, - FAR uint8_t *macaddr, FAR const char *ifname); + FAR uint8_t *macaddr); int netlib_set_arpmapping(FAR const struct sockaddr_in *inaddr, - FAR const uint8_t *macaddr, - FAR const char *ifname); + FAR const uint8_t *macaddr); #ifdef CONFIG_NETLINK_ROUTE -struct arpreq; -ssize_t netlib_get_arptable(FAR struct arpreq *arptab, +struct arp_entry_s; +ssize_t netlib_get_arptable(FAR struct arp_entry_s *arptab, unsigned int nentries); #endif #endif @@ -424,99 +305,17 @@ ssize_t netlib_get_route(FAR struct rtentry *rtelist, unsigned int nentries, sa_family_t family); #endif -#if defined(CONFIG_NET_IPv4) && defined(CONFIG_NETUTILS_DHCPC) -/* DHCP */ - -int netlib_obtain_ipv4addr(FAR const char *ifname); -#endif - #ifdef CONFIG_NET_ICMPv6_AUTOCONF /* ICMPv6 Autoconfiguration */ int netlib_icmpv6_autoconfiguration(FAR const char *ifname); - -/* DHCPv6 */ - -int netlib_obtain_ipv6addr(FAR const char *ifname); -#endif - -#ifdef CONFIG_NET_IPTABLES -/* iptables interface support */ - -struct ipt_replace; /* Forward reference */ -struct ipt_entry; /* Forward reference */ -struct ip6t_replace; /* Forward reference */ -struct ip6t_entry; /* Forward reference */ -enum nf_inet_hooks; /* Forward reference */ - -# ifdef CONFIG_NET_IPv4 -FAR struct ipt_replace *netlib_ipt_prepare(FAR const char *table); -int netlib_ipt_commit(FAR const struct ipt_replace *repl); -int netlib_ipt_flush(FAR const char *table, enum nf_inet_hooks hook); -int netlib_ipt_policy(FAR const char *table, enum nf_inet_hooks hook, - int verdict); -int netlib_ipt_append(FAR struct ipt_replace **repl, - FAR const struct ipt_entry *entry, - enum nf_inet_hooks hook); -int netlib_ipt_insert(FAR struct ipt_replace **repl, - FAR const struct ipt_entry *entry, - enum nf_inet_hooks hook, int rulenum); -int netlib_ipt_delete(FAR struct ipt_replace *repl, - FAR const struct ipt_entry *entry, - enum nf_inet_hooks hook, int rulenum); -int netlib_ipt_fillifname(FAR struct ipt_entry *entry, - FAR const char *inifname, - FAR const char *outifname); -# ifdef CONFIG_NET_NAT -FAR struct ipt_entry *netlib_ipt_masquerade_entry(FAR const char *ifname); -# endif -# ifdef CONFIG_NET_IPFILTER -FAR struct ipt_entry *netlib_ipt_filter_entry(FAR const char *target, - int verdict, - uint8_t match_proto); -# endif -# endif /* CONFIG_NET_IPv4 */ -# ifdef CONFIG_NET_IPv6 -FAR struct ip6t_replace *netlib_ip6t_prepare(FAR const char *table); -int netlib_ip6t_commit(FAR const struct ip6t_replace *repl); -int netlib_ip6t_flush(FAR const char *table, enum nf_inet_hooks hook); -int netlib_ip6t_policy(FAR const char *table, enum nf_inet_hooks hook, - int verdict); -int netlib_ip6t_append(FAR struct ip6t_replace **repl, - FAR const struct ip6t_entry *entry, - enum nf_inet_hooks hook); -int netlib_ip6t_insert(FAR struct ip6t_replace **repl, - FAR const struct ip6t_entry *entry, - enum nf_inet_hooks hook, int rulenum); -int netlib_ip6t_delete(FAR struct ip6t_replace *repl, - FAR const struct ip6t_entry *entry, - enum nf_inet_hooks hook, int rulenum); -int netlib_ip6t_fillifname(FAR struct ip6t_entry *entry, - FAR const char *inifname, - FAR const char *outifname); -# ifdef CONFIG_NET_IPFILTER -FAR struct ip6t_entry *netlib_ip6t_filter_entry(FAR const char *target, - int verdict, - uint8_t match_proto); -# endif -# endif /* CONFIG_NET_IPv6 */ -#endif /* CONFIG_NET_IPTABLES */ - -#ifdef CONFIG_NETLINK_NETFILTER -/* Netfilter connection tracking support */ - -struct nlmsghdr; /* Forward reference */ - -int netlib_parse_conntrack(FAR const struct nlmsghdr *nlh, size_t len, - FAR struct netlib_conntrack_s *ct); -int netlib_get_conntrack(sa_family_t family, netlib_conntrack_cb_t cb); #endif /* HTTP support */ -int netlib_parsehttpurl(FAR const char *url, uint16_t *port, - FAR char *hostname, int hostlen, - FAR char *filename, int namelen); +int netlib_parsehttpurl(FAR const char *url, uint16_t *port, + FAR char *hostname, int hostlen, + FAR char *filename, int namelen); #ifdef CONFIG_NETUTILS_NETLIB_GENERICURLPARSER int netlib_parseurl(FAR const char *str, FAR struct url_s *url); @@ -526,95 +325,18 @@ int netlib_parseurl(FAR const char *str, FAR struct url_s *url); int netlib_listenon(uint16_t portno); void netlib_server(uint16_t portno, pthread_startroutine_t handler, - int stacksize); + int stacksize); int netlib_getifstatus(FAR const char *ifname, FAR uint8_t *flags); int netlib_ifup(FAR const char *ifname); int netlib_ifdown(FAR const char *ifname); -int netlib_ifarp(const char *ifname); -int netlib_ifnoarp(const char *ifname); /* DNS server addressing */ #if defined(CONFIG_NET_IPv4) && defined(CONFIG_NETDB_DNSCLIENT) int netlib_set_ipv4dnsaddr(FAR const struct in_addr *inaddr); -int netlib_del_ipv4dnsaddr(FAR const struct in_addr *inaddr); -int netlib_del_ipv4dnsaddr_by_index(int index); #endif -#if defined(CONFIG_NET_IPv6) && defined(CONFIG_NETDB_DNSCLIENT) -int netlib_set_ipv6dnsaddr(FAR const struct in6_addr *inaddr); -int netlib_del_ipv6dnsaddr(FAR const struct in6_addr *inaddr); -int netlib_del_ipv6dnsaddr_by_index(int index); -#endif - -int netlib_set_mtu(FAR const char *ifname, int mtu); - -#if defined(CONFIG_NETDEV_STATISTICS) -int netlib_getifstatistics(FAR const char *ifname, - FAR struct netdev_statistics_s *stat); -#endif - -/* Network check support */ - -#ifdef CONFIG_NET_ARP_ACD -int netlib_check_ifconflict(FAR const char *ifname); -#endif - -/**************************************************************************** - * Name: netlib_check_ipconnectivity - * - * Description: - * Check network connectivity by pinging a remote IP address. - * If ip is NULL, ping the gateway of each network interface, - * and optionally the routers from the routing table. If ping - * is disabled, just check the status of the IP network card. - * - * Parameters: - * ip The ipv4 address to check, or NULL to ping gateways - * timeout The max timeout of each ping - * retry The retry times of ping - * - * Return: - * nums of remote reply of ping; a negative or ZERO on failure - * - ****************************************************************************/ - -int netlib_check_ipconnectivity(FAR const char *ip, int timeout, int retry); - -#ifdef CONFIG_NETUTILS_PING - -/**************************************************************************** - * Name: netlib_check_ifconnectivity - * - * Description: - * Check network connectivity by pinging the default gateway - * of the specified network interface. - * - * Parameters: - * ifname The name of the interface to use - * timeout The timeout of ping - * retry The retry times of ping - * - * Return: - * nums of gateway reply of ping; a negative on failure. - * - ****************************************************************************/ - -int netlib_check_ifconnectivity(FAR const char *ifname, - int timeout, int retry); -#else -#define netlib_check_ifconnectivity(i, t, r) 1 -#endif - -#ifdef CONFIG_MM_IOB -int netlib_get_iobinfo(FAR struct iob_stats_s *iob); -#endif - -int netlib_check_httpconnectivity(FAR const char *host, - FAR const char *getmsg, - int port, int expect_code); - #undef EXTERN #ifdef __cplusplus } diff --git a/include/netutils/ntpclient.h b/include/netutils/ntpclient.h index 78045f5ee..b330dfec7 100644 --- a/include/netutils/ntpclient.h +++ b/include/netutils/ntpclient.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/netutils/ntpclient.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/netutils/pppd.h b/include/netutils/pppd.h index 690f10b0b..4e24e3f94 100644 --- a/include/netutils/pppd.h +++ b/include/netutils/pppd.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/netutils/pppd.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/netutils/ptpd.h b/include/netutils/ptpd.h deleted file mode 100644 index 1d455c6be..000000000 --- a/include/netutils/ptpd.h +++ /dev/null @@ -1,189 +0,0 @@ -/**************************************************************************** - * apps/include/netutils/ptpd.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __APPS_INCLUDE_NETUTILS_PTPD_H -#define __APPS_INCLUDE_NETUTILS_PTPD_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -struct ptpd_config_s -{ - FAR const char *interface; - FAR const char *clock; - bool client_only; - bool hardware_ts; - bool delay_e2e; - bool bmca; - sa_family_t af; -}; - -/* PTPD status information structure */ - -struct ptpd_status_s -{ - /* Is there a valid remote clock source active? */ - - bool clock_source_valid; - - /* Information about selected best clock source */ - - struct - { - uint8_t id[8]; /* Clock identity */ - int utcoffset; /* Offset between clock time and UTC time (seconds) */ - int priority1; /* Main priority field */ - int clockclass; /* Clock class (IEEE-1588, lower is better) */ - int accuracy; /* Clock accuracy (IEEE-1588, lower is better) */ - int variance; /* Clock variance (IEEE-1588, lower is better) */ - int priority2; /* Secondary priority field */ - uint8_t gm_id[8]; /* Grandmaster clock identity */ - int stepsremoved; /* How many steps from grandmaster clock */ - int timesource; /* Type of time source (IEEE-1588) */ - } clock_source_info; - - /* When was clock last updated or adjusted (CLOCK_REALTIME). - * Matches last_received_sync but in different clock. - */ - - struct timespec last_clock_update; - - /* Details of clock adjustment made at last_clock_update */ - - int64_t last_delta_ns; /* Latest measured clock error */ - int64_t last_adjtime_ns; /* Previously applied adjtime() offset */ - - /* Averaged clock drift estimate (parts per billion). - * Positive means remote clock runs faster than local clock before - * adjustment. - */ - - long drift_ppb; - - /* Averaged path delay */ - - long path_delay_ns; - - /* Timestamps of latest received packets (CLOCK_MONOTONIC) */ - - struct timespec last_received_multicast; /* Any multicast packet */ - struct timespec last_received_announce; /* Announce from any server */ - struct timespec last_received_sync; /* Sync from selected source */ - - /* Timestamps of latest transmitted packets (CLOCK_MONOTONIC) */ - - struct timespec last_transmitted_sync; - struct timespec last_transmitted_announce; - struct timespec last_transmitted_delayresp; - struct timespec last_transmitted_delayreq; -}; - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -#ifdef __cplusplus -#define EXTERN extern "C" -extern "C" -{ -#else -#define EXTERN extern -#endif - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Name: ptpd_start - * - * Description: - * Start the PTP daemon and bind it to specified config. - * - * Input Parameters: - * config - The configs of PTP daemon, includes interface, af and clock... - * - * Returned Value: - * On success, the non-negative task ID of the PTP daemon is returned; - * On failure, a negated errno value is returned. - * - ****************************************************************************/ - -int ptpd_start(FAR const struct ptpd_config_s *config); - -/**************************************************************************** - * Name: ptpd_status - * - * Description: - * Query status from a running PTP daemon. - * - * Input Parameters: - * pid - Process ID previously returned by ptpd_start() - * status - Pointer to storage for status information. - * - * Returned Value: - * On success, returns OK. - * On failure, a negated errno value is returned. - * - * Assumptions/Limitations: - * Multiple threads with priority less than CONFIG_NETUTILS_PTPD_SERVERPRIO - * can request status simultaneously. If higher priority threads request - * status simultaneously, some of the requests may timeout. - * - ****************************************************************************/ - -int ptpd_status(int pid, FAR struct ptpd_status_s *status); - -/**************************************************************************** - * Name: ptpd_stop - * - * Description: - * Stop PTP daemon - * - * Input Parameters: - * pid - Process ID previously returned by ptpd_start() - * - * Returned Value: - * On success, returns OK. - * On failure, a negated errno value is returned. - * - ****************************************************************************/ - -int ptpd_stop(int pid); - -#undef EXTERN -#ifdef __cplusplus -} -#endif - -#endif /* __APPS_INCLUDE_NETUTILS_PTPD_H */ diff --git a/include/netutils/smtp.h b/include/netutils/smtp.h index e278d1a17..5d4c612ae 100644 --- a/include/netutils/smtp.h +++ b/include/netutils/smtp.h @@ -1,11 +1,15 @@ /**************************************************************************** * apps/include/netutils/smtp.h + * SMTP header file * - * SPDX-License-Identifier: BSD-3-Clause - * SPDX-FileCopyrightText: 2007, 2009, 2011, 2015 Gregory Nutt. - * SPDX-FileCopyrightText: 2002 Adam Dunkels. - * SPDX-FileContributor: Gregory Nutt - * SPDX-FileContributor: Adam Dunkels + * Copyright (C) 2007, 2009, 2011, 2015 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Heavily leveraged from uIP 1.0 which also has a BSD-like license: + * + * Author: Adam Dunkels + * Copyright (c) 2002, Adam Dunkels. + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/include/netutils/telnetc.h b/include/netutils/telnetc.h index 85d653d80..163efdc86 100644 --- a/include/netutils/telnetc.h +++ b/include/netutils/telnetc.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/netutils/telnetc.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -588,8 +586,7 @@ void telnet_begin_compress2(struct telnet_s *telnet); * ****************************************************************************/ -int telnet_printf(struct telnet_s *telnet, const char *fmt, ...) - printf_like(2, 3); +int telnet_printf(struct telnet_s *telnet, const char *fmt, ...); /**************************************************************************** * Name: telnet_vprintf @@ -601,8 +598,7 @@ int telnet_printf(struct telnet_s *telnet, const char *fmt, ...) * ****************************************************************************/ -int telnet_vprintf(struct telnet_s *telnet, const char *fmt, va_list va) - printf_like(2, 0); +int telnet_vprintf(struct telnet_s *telnet, const char *fmt, va_list va); /**************************************************************************** * Name: telnet_raw_printf @@ -623,8 +619,7 @@ int telnet_vprintf(struct telnet_s *telnet, const char *fmt, va_list va) * ****************************************************************************/ -int telnet_raw_printf(struct telnet_s *telnet, const char *fmt, ...) - printf_like(2, 3); +int telnet_raw_printf(struct telnet_s *telnet, const char *fmt, ...); /**************************************************************************** * Name: telnet_raw_vprintf @@ -636,8 +631,7 @@ int telnet_raw_printf(struct telnet_s *telnet, const char *fmt, ...) * ****************************************************************************/ -int telnet_raw_vprintf(struct telnet_s *telnet, const char *fmt, va_list va) - printf_like(2, 0); +int telnet_raw_vprintf(struct telnet_s *telnet, const char *fmt, va_list va); /**************************************************************************** * Name: telnet_begin_newenviron @@ -707,7 +701,7 @@ void telnet_newenviron_value(struct telnet_s *telnet, unsigned char type, * ****************************************************************************/ -void telnet_ttype_send(struct telnet_s *telnet); +void telnet_ttype_send(struct telnet_s * telnet); /**************************************************************************** * Name: telnet_ttype_is @@ -745,7 +739,7 @@ void telnet_ttype_send(struct telnet_s *telnet); * ****************************************************************************/ -void telnet_ttype_is(struct telnet_s *telnet, const char *ttype); +void telnet_ttype_is(struct telnet_s * telnet, const char *ttype); /**************************************************************************** * Name: telnet_send_zmp @@ -760,8 +754,8 @@ void telnet_ttype_is(struct telnet_s *telnet, const char *ttype); * ****************************************************************************/ -void telnet_send_zmp(struct telnet_s *telnet, size_t argc, - const char **argv); +void telnet_send_zmp(struct telnet_s * telnet, size_t argc, + const char **argv); /**************************************************************************** * Name: telnet_send_zmpv @@ -777,7 +771,7 @@ void telnet_send_zmp(struct telnet_s *telnet, size_t argc, * ****************************************************************************/ -void telnet_send_zmpv(struct telnet_s *telnet, ...); +void telnet_send_zmpv(struct telnet_s * telnet, ...); /**************************************************************************** * Name: telnet_send_vzmpv @@ -789,7 +783,7 @@ void telnet_send_zmpv(struct telnet_s *telnet, ...); * ****************************************************************************/ -void telnet_send_vzmpv(struct telnet_s *telnet, va_list va); +void telnet_send_vzmpv(struct telnet_s * telnet, va_list va); /**************************************************************************** * Name: telnet_begin_zmp @@ -803,7 +797,7 @@ void telnet_send_vzmpv(struct telnet_s *telnet, va_list va); * ****************************************************************************/ -void telnet_begin_zmp(struct telnet_s *telnet, const char *cmd); +void telnet_begin_zmp(struct telnet_s * telnet, const char *cmd); /**************************************************************************** * Name: telnet_zmp_arg @@ -817,7 +811,7 @@ void telnet_begin_zmp(struct telnet_s *telnet, const char *cmd); * ****************************************************************************/ -void telnet_zmp_arg(struct telnet_s *telnet, const char *arg); +void telnet_zmp_arg(struct telnet_s * telnet, const char *arg); /**************************************************************************** * Name: telnet_finish_zmp diff --git a/include/netutils/telnetd.h b/include/netutils/telnetd.h index f428e937d..11fb39f58 100644 --- a/include/netutils/telnetd.h +++ b/include/netutils/telnetd.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/netutils/telnetd.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -27,38 +25,44 @@ * Included Files ****************************************************************************/ -#include +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* CONFIG_TELNETD_CONSOLE - Use the first Telnet session as the default + * console. + */ /**************************************************************************** * Public Types ****************************************************************************/ /* An instance of the struct telnetd_config_s structure must be passed to - * telnetd_daemon in order to configure the new Telnet daemon. + * telnetd_start in order to configure the new Telnet daemon. */ struct telnetd_config_s { + /* These fields describe the telnet daemon */ + + uint8_t d_priority; /* The execution priority of the Telnet daemon task */ + size_t d_stacksize; /* The stack size needed by the Telnet daemon task */ + /* These fields describe the network connection */ - uint16_t d_port; /* The port to listen on (in network byte order) */ - sa_family_t d_family; /* Address family */ + uint16_t d_port; /* The port to listen on (in network byte order) */ + sa_family_t d_family; /* Address family */ - /* These fields describe the priority of each task created by the Telnet + /* These fields describe the priority of each thread created by the Telnet * daemon. */ - uint8_t t_priority; /* The execution priority of the spawned task, */ - size_t t_stacksize; /* The stack size needed by the spawned task */ -#ifndef CONFIG_BUILD_KERNEL - main_t t_entry; /* The entrypoint of the task to spawn when a new - * connection is accepted. */ -#endif -#ifdef CONFIG_LIBC_EXECFUNCS - FAR const char *t_path; /* The binary path of the task to spawn when a new - * connection is accepted. */ -#endif - FAR char * const *t_argv; /* The argument pass to the spawned task */ + uint8_t t_priority; /* The execution priority of the spawned task, */ + size_t t_stacksize; /* The stack size needed by the spawned task */ + main_t t_entry; /* The entrypoint of the task to spawn when a new + * connection is accepted. */ }; /**************************************************************************** @@ -74,10 +78,10 @@ extern "C" #endif /**************************************************************************** - * Name: telnetd_daemon + * Name: telnetd_start * * Description: - * Run the Telnet daemon loop. + * Start the Telnet daemon. * * Parameters: * config A pointer to a configuration structure that characterizes the @@ -86,11 +90,13 @@ extern "C" * daemon. * * Return: - * A negated errno is returned if the daemon was not successfully started. + * The process ID (pid) of the new Telnet daemon is returned on + * success; A negated errno is returned if the daemon was not successfully + * started. * ****************************************************************************/ -int telnetd_daemon(FAR const struct telnetd_config_s *config); +int telnetd_start(FAR struct telnetd_config_s *config); #undef EXTERN #ifdef __cplusplus diff --git a/include/netutils/tftp.h b/include/netutils/tftp.h index ad0432c45..ae2eee8cb 100644 --- a/include/netutils/tftp.h +++ b/include/netutils/tftp.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/netutils/tftp.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/netutils/thttpd.h b/include/netutils/thttpd.h index a0df9e0b7..1f34764e6 100644 --- a/include/netutils/thttpd.h +++ b/include/netutils/thttpd.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/netutils/thttpd.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/netutils/urldecode.h b/include/netutils/urldecode.h index 07a4c39db..60b098add 100644 --- a/include/netutils/urldecode.h +++ b/include/netutils/urldecode.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/netutils/urldecode.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/netutils/webclient.h b/include/netutils/webclient.h index 58188c941..e352d44ea 100644 --- a/include/netutils/webclient.h +++ b/include/netutils/webclient.h @@ -1,11 +1,15 @@ /**************************************************************************** * apps/include/netutils/webclient.h + * Header file for the HTTP client * - * SPDX-License-Identifier: BSD-3-Clause - * SPDX-FileCopyrightText: 2007, 2009, 2011, 2015 Gregory Nutt. - * SPDX-FileCopyrightText: 2002 Adam Dunkels. - * SPDX-FileContributor: Gregory Nutt - * SPDX-FileContributor: Adam Dunkels + * Copyright (C) 2007, 2009, 2011, 2015 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Based remotely on the uIP webclient which also has a BSD style license: + * + * Author: Adam Dunkels + * Copyright (c) 2002, Adam Dunkels. + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -45,7 +49,6 @@ #include #include -#include #include /**************************************************************************** @@ -98,30 +101,14 @@ * the name resolution in a blocking manner. */ -#define WEBCLIENT_FLAG_NON_BLOCKING 1U - -/* WEBCLIENT_FLAG_TUNNEL: Establish a tunnel - * - * If WEBCLIENT_FLAG_TUNNEL is set, ctx->url is ignored and - * tunnel_target_host and tunnel_target_port members are used instead. - * - * Once a tunnel is established, webclient_perform returns success, - * keeping the tunneled connection open. - * - * After the successful (0-returning) call of webclient_perform, - * the user can use webclient_get_tunnel only once. - * webclient_get_tunnel effectively detaches the returned - * webclient_conn_s from the context. It's users' responsibility - * to dispose the connection. - */ -#define WEBCLIENT_FLAG_TUNNEL 2U +#define WEBCLIENT_FLAG_NON_BLOCKING 1U /* The following WEBCLIENT_FLAG_xxx constants are for * webclient_poll_info::flags. */ -#define WEBCLIENT_POLL_INFO_WANT_READ 1U -#define WEBCLIENT_POLL_INFO_WANT_WRITE 2U +#define WEBCLIENT_POLL_INFO_WANT_READ 1U +#define WEBCLIENT_POLL_INFO_WANT_WRITE 2U /**************************************************************************** * Public types @@ -231,7 +218,6 @@ typedef CODE int (*webclient_body_callback_t)( struct webclient_tls_connection; struct webclient_poll_info; -struct webclient_conn_s; struct webclient_tls_ops { @@ -250,25 +236,6 @@ struct webclient_tls_ops CODE int (*get_poll_info)(FAR void *ctx, FAR struct webclient_tls_connection *conn, FAR struct webclient_poll_info *info); - - /* init_connection: Initialize TLS over an existing connection - * - * This method is used for https proxy, which is essentially - * tunnelling over http. - * - * hostname parameter is supposed to be used for server certificate - * validation. - * - * This method can be NULL. - * In that case, webclient_perform fails with -ENOTSUP - * when it turns out that tunnelling is necessary. - */ - - CODE int (*init_connection)(FAR void *ctx, - FAR struct webclient_conn_s *conn, - FAR const char *hostname, - unsigned int timeout_second, - FAR struct webclient_tls_connection **connp); }; /* Note on webclient_client lifetime @@ -291,27 +258,13 @@ struct webclient_tls_ops * | | * webclient_perform * | - * | - * +-- non-blocking mode, returns -EAGAIN ---> IN-PROGRESS - * | - * +-- returns -errno ---> DONE - * | - * returns 0 - * | - * +-- !WEBCLIENT_FLAG_TUNNEL --> DONE - * | - * +-- WEBCLIENT_FLAG_TUNNEL, http_status 2xx -----> TUNNEL_ESTABLISHED - * | - * +-- WEBCLIENT_FLAG_TUNNEL, http_status others --> DONE - * - * - * TUNNEL_ESTABLISHED - * | - * webclient_get_tunnel - * | - * v - * DONE - * + * +---------------+ + * | | + * | non-blocking mode, + * | returns -EAGAIN + * | | + * v v + * DONE IN-PROGRESS * * (uninitialized): * After the memory for webclient_context is allocated, @@ -351,10 +304,6 @@ struct webclient_tls_ops * * If the application wants to reuse the context for another request, * it should initialize it with webclient_set_defaults() again. - * - * TUNNEL_ESTABLISHED - * webclient_get_tunnel() should be called exactly once to return - * the established tunnel. */ struct webclient_context @@ -367,17 +316,9 @@ struct webclient_context * url - A pointer to a string containing the full URL. * (e.g., http://www.nutt.org/index.html, or * http://192.168.23.1:80/index.html) - * proxy - A pointer to a string containing the proxy string. - * (e.g., http://myproxy:1080) - * NULL means no proxy. This is the default. - * Only http:// protocol is implemented. * unix_socket_path - If not NULL, the path to an AF_LOCAL socket. * headers - An array of pointers to the extra headers. * nheaders - The number of elements in the "headers" array. - * proxy_headers - An array of pointers to the extra headers for - * the proxy connection. - * proxy_nheaders - The number of elements in the "headers" array for - * the proxy connection. * bodylen - The size of the request body. * timeout_sec - The timeout in second. * This is not meant to cover the entire transaction. @@ -396,24 +337,14 @@ struct webclient_context FAR const char *method; FAR const char *url; - FAR const char *proxy; #if defined(CONFIG_WEBCLIENT_NET_LOCAL) FAR const char *unix_socket_path; #endif FAR const char * FAR const *headers; unsigned int nheaders; - - FAR const char * FAR const *proxy_headers; - unsigned int proxy_nheaders; - size_t bodylen; unsigned int timeout_sec; - /* Parameters for WEBCLIENT_FLAG_TUNNEL */ - - FAR const char *tunnel_target_host; - uint16_t tunnel_target_port; - /* other parameters * * buffer - A user provided buffer to receive the file data @@ -472,7 +403,6 @@ struct webclient_context WEBCLIENT_CONTEXT_STATE_IN_PROGRESS, WEBCLIENT_CONTEXT_STATE_ABORTED, WEBCLIENT_CONTEXT_STATE_DONE, - WEBCLIENT_CONTEXT_STATE_TUNNEL_ESTABLISHED, } state; #endif }; @@ -485,25 +415,6 @@ struct webclient_poll_info unsigned int flags; /* OR'ed WEBCLIENT_POLL_INFO_xxx flags */ }; -struct webclient_conn_s -{ - bool tls; - - /* for !tls */ - - int sockfd; - unsigned int flags; - - /* for tls */ - - FAR struct webclient_tls_connection *tls_conn; - - /* for tls, same as webclient_context */ - - FAR const struct webclient_tls_ops *tls_ops; - FAR void *tls_ctx; -}; - /**************************************************************************** * Public Function Prototypes ****************************************************************************/ @@ -562,15 +473,6 @@ void webclient_set_static_body(FAR struct webclient_context *ctx, size_t bodylen); int webclient_get_poll_info(FAR struct webclient_context *ctx, FAR struct webclient_poll_info *info); -void webclient_get_tunnel(FAR struct webclient_context *ctx, - FAR struct webclient_conn_s **connp); - -ssize_t webclient_conn_send(FAR struct webclient_conn_s *conn, - FAR const void *buffer, size_t len); -ssize_t webclient_conn_recv(FAR struct webclient_conn_s *conn, - FAR void *buffer, size_t len); -void webclient_conn_close(FAR struct webclient_conn_s *conn); -void webclient_conn_free(FAR struct webclient_conn_s *conn); #undef EXTERN #ifdef __cplusplus diff --git a/include/netutils/xmlrpc.h b/include/netutils/xmlrpc.h index 53ee6f919..067c04373 100644 --- a/include/netutils/xmlrpc.h +++ b/include/netutils/xmlrpc.h @@ -1,10 +1,14 @@ /**************************************************************************** * apps/include/netutils/xmlrpc.h * - * SPDX-License-Identifier: BSD-3-Clause - * SPDX-FileCopyrightText: 2012 Max Holtzberg. All rights reserved. - * SPDX-FileCopyrightText: 2002 Cogito LLC. All rights reserved. - * SPDX-FileContributor: Max Holtzberg + * Copyright (C) 2012 Max Holtzberg. All rights reserved. + * Author: Max Holtzberg + * + * Based on the embeddable lightweight XML-RPC server code discussed + * in the article at: http://www.drdobbs.com/web-development/\ + * an-embeddable-lightweight-xml-rpc-server/184405364 + * + * Copyright (c) 2002 Cogito LLC. All rights reserved. * * Redistribution and use in source and binary forms, with or * without modification, is hereby granted without fee provided @@ -37,14 +41,10 @@ ****************************************************************************/ /* - * Based on the embeddable lightweight XML-RPC server code discussed - * in the article at: http://www.drdobbs.com/web-development/\ - * an-embeddable-lightweight-xml-rpc-server/184405364 - */ - -/* Lightweight Embedded XML-RPC Server Types and Definitions + * Lightweight Embedded XML-RPC Server Types and Definitions + * + * mtj@cogitollc.com * - * mtj@cogitollc.com */ #ifndef __APPS_INCLUDE_NETUTILS_XMLRPC_H @@ -86,13 +86,13 @@ struct xmlrpc_arg_s int i; char boolean; double d; - char string[CONFIG_XMLRPC_STRINGSIZE + 1]; + char string[CONFIG_XMLRPC_STRINGSIZE+1]; } u; }; struct xmlrpc_s { - char name[CONFIG_XMLRPC_STRINGSIZE + 1]; + char name[CONFIG_XMLRPC_STRINGSIZE+1]; struct xmlrpc_arg_s arguments[MAX_ARGS]; char args[MAX_ARGS]; int argsize; @@ -104,7 +104,7 @@ struct xmlrpc_s struct xmlrpc_entry_s { struct xmlrpc_entry_s *next; - int (*func)(struct xmlrpc_s *); + int (*func)(struct xmlrpc_s*); char *name; }; diff --git a/include/netutils/xtables.h b/include/netutils/xtables.h deleted file mode 100644 index 12c116b53..000000000 --- a/include/netutils/xtables.h +++ /dev/null @@ -1,505 +0,0 @@ -/**************************************************************************** - * apps/include/netutils/xtables.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __APPS_INCLUDE_NETUTILS_XTABLES_H -#define __APPS_INCLUDE_NETUTILS_XTABLES_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include - -#include - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define XTABLES_VERSION_CODE 12 - -/* Select the format the input has to conform to, as well as the target type - * (area pointed to with XTOPT_POINTER). Note that the storing is not always - * uniform. cb->val will be populated with as much as there is space, i.e. - * exactly 2 items for ranges, but the target area can receive more values - * (e.g. in case of ranges), or less values (e.g. XTTYPE_HOSTMASK). - * - * XTTYPE_NONE: option takes no argument - * XTTYPE_UINT*: standard integer - * XTTYPE_UINT*RC: colon-separated range of standard integers - * XTTYPE_DOUBLE: double-precision floating point number - * XTTYPE_STRING: arbitrary string - * XTTYPE_TOSMASK: 8-bit TOS value with optional mask - * XTTYPE_MARKMASK32: 32-bit mark with optional mask - * XTTYPE_SYSLOGLEVEL: syslog level by name or number - * XTTYPE_HOST: one host or address (ptr: union nf_inet_addr) - * XTTYPE_HOSTMASK: one host or address, with an optional prefix length - * ptr: union nf_inet_addr; only host portion is stored - * XTTYPE_PROTOCOL: protocol number/name from /etc/protocols ptr: uint8_t - * XTTYPE_PORT: 16-bit port name or number (supports XTOPT_NBO) - * XTTYPE_PORTRC: colon-separated port range (names acceptable), - * (supports XTOPT_NBO) - * XTTYPE_PLEN: prefix length - * XTTYPE_PLENMASK: prefix length (ptr: union nf_inet_addr) - * XTTYPE_ETHERMAC: Ethernet MAC address in hex form - */ - -enum xt_option_type -{ - XTTYPE_NONE, - XTTYPE_UINT8, - XTTYPE_UINT16, - XTTYPE_UINT32, - XTTYPE_UINT64, - XTTYPE_UINT8RC, - XTTYPE_UINT16RC, - XTTYPE_UINT32RC, - XTTYPE_UINT64RC, - XTTYPE_DOUBLE, - XTTYPE_STRING, - XTTYPE_TOSMASK, - XTTYPE_MARKMASK32, - XTTYPE_SYSLOGLEVEL, - XTTYPE_HOST, - XTTYPE_HOSTMASK, - XTTYPE_PROTOCOL, - XTTYPE_PORT, - XTTYPE_PORTRC, - XTTYPE_PLEN, - XTTYPE_PLENMASK, - XTTYPE_ETHERMAC, -}; - -enum xtables_tryload -{ - XTF_DONT_LOAD, - XTF_DURING_LOAD, - XTF_TRY_LOAD, - XTF_LOAD_MUST_SUCCEED, -}; - -enum xtables_exittype -{ - OTHER_PROBLEM = 1, - PARAMETER_PROBLEM, - VERSION_PROBLEM, - RESOURCE_PROBLEM, - XTF_ONLY_ONCE, - XTF_NO_INVERT, - XTF_BAD_VALUE, - XTF_ONE_ACTION, -}; - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -struct xtables_globals -{ - unsigned int option_offset; - FAR const char *program_name; - FAR const char *program_version; - FAR struct option *orig_opts; - FAR struct option *opts; - noreturn_function void (*exit_err)(enum xtables_exittype status, - FAR const char *msg, ...) - printf_like(2, 3); - int (*compat_rev)(FAR const char *name, uint8_t rev, int opt); -}; - -/* name: name of option - * type: type of input and validation method, see XTTYPE_* - * id: unique number (within extension) for option, 0-31 - * excl: bitmask of flags that cannot be used with this option - * also: bitmask of flags that must be used with this option - * flags: bitmask of option flags, see XTOPT_* - * ptroff: offset into private structure for member - * size: size of the item pointed to by ptroff; this is a safeguard - * min: lowest allowed value (for singular integral types) - * max: highest allowed value (for singular integral types) - */ - -struct xt_option_entry -{ - FAR const char *name; - enum xt_option_type type; - unsigned int id; - unsigned int excl; - unsigned int also; - unsigned int flags; - unsigned int ptroff; - size_t size; - unsigned int min; - unsigned int max; -}; - -struct xt_xlate; -struct xt_xlate_tg_params -{ - FAR const void *ip; - FAR const struct xt_entry_target *target; - int numeric; - bool escape_quotes; -}; - -/* ext_name: name of extension currently being processed - * data: per-extension (kernel) data block - * udata: per-extension private scratch area - * (cf. xtables_{match,target}->udata_size) - * xflags: options of the extension that have been used - */ - -struct xt_fcheck_call -{ - FAR const char *ext_name; - FAR void *data; - FAR void *udata; - unsigned int xflags; -}; - -struct xt_xlate_mt_params -{ - FAR const void *ip; - FAR const struct xt_entry_match *match; - int numeric; - bool escape_quotes; -}; - -/* arg: input from command line - * ext_name: name of extension currently being processed - * entry: current option being processed - * data: per-extension kernel data block - * xflags: options of the extension that have been used - * invert: whether option was used with ! - * nvals: number of results in uXX_multi - * val: parsed result - * udata: per-extension private scratch area - * (cf. xtables_{match,target}->udata_size) - */ - -struct xt_option_call -{ - FAR const char *arg; - FAR const char *ext_name; - FAR const struct xt_option_entry *entry; - FAR void *data; - unsigned int xflags; - bool invert; - uint8_t nvals; - union - { - uint8_t u8; - uint8_t u8_range[2]; - uint8_t syslog_level; - uint8_t protocol; - uint16_t u16; - uint16_t u16_range[2]; - uint16_t port; - uint16_t port_range[2]; - uint32_t u32; - uint32_t u32_range[2]; - uint64_t u64; - uint64_t u64_range[2]; - double dbl; - struct - { - union nf_inet_addr haddr; - union nf_inet_addr hmask; - uint8_t hlen; - }; - struct - { - uint8_t tos_value; - uint8_t tos_mask; - }; - struct - { - uint32_t mark; - uint32_t mask; - }; - uint8_t ethermac[6]; - } val; - - /* Wished for a world where the ones below were gone: */ - - union - { - FAR struct xt_entry_match **match; - FAR struct xt_entry_target **target; - }; - - FAR void *xt_entry; - FAR void *udata; -}; - -/* Include file for additions: new matches and targets. */ - -struct xtables_match -{ - /* ABI/API version this module requires. Must be first member, - * as the rest of this struct may be subject to ABI changes. - */ - - FAR const char *version; - FAR struct xtables_match *next; - FAR const char *name; - FAR const char *real_name; - - /* Revision of match (0 by default). */ - - uint8_t revision; - - /* Extension flags */ - - uint8_t ext_flags; - uint16_t family; - - /* Size of match data. */ - - size_t size; - - /* Size of match data relevant for userspace comparison purposes */ - - size_t userspacesize; - - /* Function which prints out usage message. */ - - void (*help)(void); - - /* Initialize the match. */ - - void (*init)(FAR struct xt_entry_match *m); - - /* Function which parses command options; returns true if it - * ate an option - */ - - /* entry is struct ipt_entry for example */ - - int (*parse)(int c, FAR char **argv, int invert, FAR unsigned int *flags, - FAR const void *entry, FAR struct xt_entry_match **match); - - /* Final check; exit if not ok. */ - - void (*final_check)(unsigned int flags); - - /* Prints out the match iff non-NULL: put space at end */ - - /* ip is struct ipt_ip * for example */ - - void (*print)(FAR const void *ip, - FAR const struct xt_entry_match *match, int numeric); - - /* Saves the match info in parsable form to stdout. */ - - /* ip is struct ipt_ip * for example */ - - void (*save)(FAR const void *ip, FAR const struct xt_entry_match *match); - - /* Print match name or alias */ - - FAR const char *(*alias)(FAR const struct xt_entry_match *match); - - /* Pointer to list of extra command-line options */ - - FAR const struct option *extra_opts; - - /* New parser */ - - void (*x6_parse)(FAR struct xt_option_call *); - void (*x6_fcheck)(FAR struct xt_fcheck_call *); - FAR const struct xt_option_entry *x6_options; - - /* Translate iptables to nft */ - - int (*xlate)(FAR struct xt_xlate *xl, - FAR const struct xt_xlate_mt_params *params); - - /* Size of per-extension instance extra "global" scratch space */ - - size_t udata_size; - - /* Ignore these men behind the curtain: */ - - FAR void *udata; - unsigned int option_offset; - FAR struct xt_entry_match *m; - unsigned int mflags; - unsigned int loaded; /* simulate loading so options are merged properly */ -}; - -struct xtables_target -{ - /* ABI/API version this module requires. Must be first member, - * as the rest of this struct may be subject to ABI changes. - */ - - FAR const char *version; - FAR struct xtables_target *next; - FAR const char *name; - - /* Real target behind this, if any. */ - - FAR const char *real_name; - - /* Revision of target (0 by default). */ - - uint8_t revision; - - /* Extension flags */ - - uint8_t ext_flags; - uint16_t family; - - /* Size of target data. */ - - size_t size; - - /* Size of target data relevant for userspace comparison purposes */ - - size_t userspacesize; - - /* Function which prints out usage message. */ - - void (*help)(void); - - /* Initialize the target. */ - - FAR void (*init)(struct xt_entry_target *t); - - /* Function which parses command options; returns true if it - * ate an option - */ - - /* entry is struct ipt_entry for example */ - - int (*parse)(int c, FAR char **argv, int invert, FAR unsigned int *flags, - FAR const void *entry, - FAR struct xt_entry_target **targetinfo); - - /* Final check; exit if not ok. */ - - void (*final_check)(unsigned int flags); - - /* Prints out the target iff non-NULL: put space at end */ - - void (*print)(FAR const void *ip, - FAR const struct xt_entry_target *target, int numeric); - - /* Saves the targinfo in parsable form to stdout. */ - - void (*save)(FAR const void *ip, - FAR const struct xt_entry_target *target); - - /* Print target name or alias */ - - FAR const char *(*alias)(FAR const struct xt_entry_target *target); - - /* Pointer to list of extra command-line options */ - - FAR const struct option *extra_opts; - - /* New parser */ - - void (*x6_parse)(FAR struct xt_option_call *); - void (*x6_fcheck)(FAR struct xt_fcheck_call *); - FAR const struct xt_option_entry *x6_options; - - /* Translate iptables to nft */ - - int (*xlate)(FAR struct xt_xlate *xl, - FAR const struct xt_xlate_tg_params *params); - size_t udata_size; - - /* Ignore these men behind the curtain: */ - - FAR void *udata; - unsigned int option_offset; - FAR struct xt_entry_target *t; - unsigned int tflags; - unsigned int used; - unsigned int loaded; /* simulate loading so options are merged properly */ -}; - -struct xtables_rule_match -{ - FAR struct xtables_rule_match *next; - FAR struct xtables_match *match; - - /* Multiple matches of the same type: the ones before - * the current one are completed from parsing point of view - */ - - bool completed; -}; - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -#ifdef __cplusplus -#define EXTERN extern "C" -extern "C" -{ -#else -#define EXTERN extern -#endif - -EXTERN FAR struct xtables_match *xtables_matches; -EXTERN FAR struct xtables_target *xtables_targets; -EXTERN FAR struct xtables_globals *xt_params; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -int xtables_insmod(FAR const char *, FAR const char *, bool); -int xtables_init_all(FAR struct xtables_globals *xtp, - uint8_t nfproto); -uint16_t xtables_parse_protocol(FAR const char *s); -void xtables_option_tpcall(unsigned int, FAR char **, bool, - FAR struct xtables_target *, FAR void *); -void xtables_option_mpcall(unsigned int, FAR char **, bool, - FAR struct xtables_match *, FAR void *); -void xtables_option_tfcall(FAR struct xtables_target *); -void xtables_option_mfcall(FAR struct xtables_match *); -FAR struct option *xtables_options_xfrm(FAR struct option *, - FAR struct option *, - FAR const struct xt_option_entry *, - FAR unsigned int *); -FAR struct option *xtables_merge_options(FAR struct option *origopts, -FAR struct option *oldopts, FAR const struct option *newopts, -FAR unsigned int *option_offset); -FAR struct xtables_match *xtables_find_match(FAR const char *name, - enum xtables_tryload, FAR struct xtables_rule_match **match); -FAR struct xtables_target *xtables_find_target(FAR const char *name, - enum xtables_tryload); -int xtables_compatible_revision(FAR const char *name, - uint8_t revision, int opt); - -#ifdef __cplusplus -} -#endif - -#endif /* __APPS_INCLUDE_NETUTILS_XTABLES_H */ diff --git a/include/nshlib/nshlib.h b/include/nshlib/nshlib.h index f2153fed0..894e736bd 100644 --- a/include/nshlib/nshlib.h +++ b/include/nshlib/nshlib.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/nshlib/nshlib.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -62,33 +60,11 @@ #endif #if CONFIG_RR_INTERVAL > 0 -# define SCHED_NSH SCHED_RR +# define SCHED_NSH SCHED_RR #else -# define SCHED_NSH SCHED_FIFO +# define SCHED_NSH SCHED_FIFO #endif -struct nsh_param_s -{ - /* Redirect input/output/error through `fd` OR `path_name` - * - * Select one: - * 1. Using fd_in/fd_out/fd_err as oldfd for dup2() if greater than -1. - * 2. Using file_in/file_out/file_err as full path to the file if it is - * not NULL, and oflags_in/oflags_out/oflags_err as flags for open(). - */ - - int fd_in; - int fd_out; - int fd_err; - - int oflags_in; - int oflags_out; - int oflags_err; - FAR const char *file_in; - FAR const char *file_out; - FAR const char *file_err; -}; - /**************************************************************************** * Public Data ****************************************************************************/ @@ -150,27 +126,6 @@ void nsh_initialize(void); int nsh_consolemain(int argc, FAR char *argv[]); -/**************************************************************************** - * Name: nsh_telnetmain - * - * Description: - * This interface may be called or started with task_start to start a - * single NSH instance that operates on stdin and stdout for telnet daemon. - * This function does not return. - * - * Input Parameters: - * Standard task start-up arguments. These are not used. argc may be - * zero and argv may be NULL. - * - * Returned Values: - * This function does not normally return. exit() is usually called to - * terminate the NSH session. This function will return in the event of - * an error. In that case, a non-zero value is returned (EXIT_FAILURE=1). - - ****************************************************************************/ - -int nsh_telnetmain(int argc, FAR char *argv[]); - /**************************************************************************** * Name: nsh_telnetstart * @@ -216,46 +171,6 @@ int nsh_telnetstart(sa_family_t family); void platform_motd(FAR char *buffer, size_t buflen); #endif -/**************************************************************************** - * Name: platform_skip_login - * - * Description: - * If CONFIG_NSH_PLATFORM_SKIP_LOGIN is defined, then platform-specific - * logic must provide this function in order to skip login. - * - * Input Parameters: - * None - * - * Returned value: - * OK - need to skip login - * else - no need to skip login - * - ****************************************************************************/ - -#ifdef CONFIG_NSH_PLATFORM_SKIP_LOGIN -int platform_skip_login(void); -#endif - -/**************************************************************************** - * Name: platform_challenge - * - * Description: - * If CONFIG_NSH_PLATFORM_CHALLENGE is defined, then platform-specific - * logic must provide this function in order get the challenge. - * - * Input Parameters: - * buffer - A caller allocated buffer in which to receive the challenge - * buflen - The length in bytes of the caller allocated buffer - * - * Returned value: - * None - * - ****************************************************************************/ - -#ifdef CONFIG_NSH_PLATFORM_CHALLENGE -void platform_challenge(FAR char *buffer, size_t buflen); -#endif - /**************************************************************************** * Name: platform_user_verify * @@ -275,13 +190,8 @@ void platform_challenge(FAR char *buffer, size_t buflen); ****************************************************************************/ #ifdef CONFIG_NSH_LOGIN_PLATFORM -#ifdef CONFIG_NSH_PLATFORM_CHALLENGE -int platform_user_verify(FAR const char *username, FAR const char *challenge, - FAR const char *password); -#else int platform_user_verify(FAR const char *username, FAR const char *password); #endif -#endif /**************************************************************************** * Name: nsh_system @@ -304,27 +214,6 @@ int platform_user_verify(FAR const char *username, FAR const char *password); int nsh_system(int argc, FAR char *argv[]); -/**************************************************************************** - * Name: nsh_system_ctty - * - * Description: - * This is the NSH-specific implementation of the standard system() - * command. - * - * NOTE: - * This difference with nsh_system: newconsole set isctty true - * - * Input Parameters: - * Standard task start-up arguments. Expects argc == 2 with argv[1] being - * the command to execute - * - * Returned Values: - * EXIT_SUCCESS or EXIT_FAILURE - * - ****************************************************************************/ - -int nsh_system_ctty(int argc, FAR char *argv[]); - #undef EXTERN #ifdef __cplusplus } diff --git a/include/nxmodbus/nxmb_client.h b/include/nxmodbus/nxmb_client.h deleted file mode 100644 index 49c10e542..000000000 --- a/include/nxmodbus/nxmb_client.h +++ /dev/null @@ -1,261 +0,0 @@ -/**************************************************************************** - * apps/include/nxmodbus/nxmb_client.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __APPS_INCLUDE_NXMODBUS_NXMB_CLIENT_H -#define __APPS_INCLUDE_NXMODBUS_NXMB_CLIENT_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -#include -#include - -#include - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -#ifdef __cplusplus -extern "C" -{ -#endif - -/**************************************************************************** - * Name: nxmb_read_coils - * - * Description: - * Read coil values from a remote unit. - * - * Input Parameters: - * h - The NxModbus client instance. - * uid - The remote unit identifier. - * addr - The first coil address to read. - * count - The number of coils to read. - * buf - The destination buffer for the returned coil values. - * - * Returned Value: - * Zero on success; a negated errno value on failure. - * - ****************************************************************************/ - -int nxmb_read_coils(nxmb_handle_t h, uint8_t uid, uint16_t addr, - uint16_t count, FAR uint8_t *buf); - -/**************************************************************************** - * Name: nxmb_read_discrete - * - * Description: - * Read discrete input values from a remote unit. - * - * Input Parameters: - * h - The NxModbus client instance. - * uid - The remote unit identifier. - * addr - The first discrete input address to read. - * count - The number of discrete inputs to read. - * buf - The destination buffer for the returned values. - * - * Returned Value: - * Zero on success; a negated errno value on failure. - * - ****************************************************************************/ - -int nxmb_read_discrete(nxmb_handle_t h, uint8_t uid, uint16_t addr, - uint16_t count, FAR uint8_t *buf); - -/**************************************************************************** - * Name: nxmb_read_input - * - * Description: - * Read input registers from a remote unit. - * - * Input Parameters: - * h - The NxModbus client instance. - * uid - The remote unit identifier. - * addr - The first input register address to read. - * count - The number of registers to read. - * buf - The destination buffer for the returned register values. - * - * Returned Value: - * Zero on success; a negated errno value on failure. - * - ****************************************************************************/ - -int nxmb_read_input(nxmb_handle_t h, uint8_t uid, uint16_t addr, - uint16_t count, FAR uint16_t *buf); - -/**************************************************************************** - * Name: nxmb_read_holding - * - * Description: - * Read holding registers from a remote unit. - * - * Input Parameters: - * h - The NxModbus client instance. - * uid - The remote unit identifier. - * addr - The first holding register address to read. - * count - The number of registers to read. - * buf - The destination buffer for the returned register values. - * - * Returned Value: - * Zero on success; a negated errno value on failure. - * - ****************************************************************************/ - -int nxmb_read_holding(nxmb_handle_t h, uint8_t uid, uint16_t addr, - uint16_t count, FAR uint16_t *buf); - -/**************************************************************************** - * Name: nxmb_write_coil - * - * Description: - * Write a single coil on a remote unit. - * - * Input Parameters: - * h - The NxModbus client instance. - * uid - The remote unit identifier. - * addr - The coil address to update. - * value - The coil state to write. - * - * Returned Value: - * Zero on success; a negated errno value on failure. - * - ****************************************************************************/ - -int nxmb_write_coil(nxmb_handle_t h, uint8_t uid, uint16_t addr, bool value); - -/**************************************************************************** - * Name: nxmb_write_holding - * - * Description: - * Write a single holding register on a remote unit. - * - * Input Parameters: - * h - The NxModbus client instance. - * uid - The remote unit identifier. - * addr - The holding register address to update. - * value - The register value to write. - * - * Returned Value: - * Zero on success; a negated errno value on failure. - * - ****************************************************************************/ - -int nxmb_write_holding(nxmb_handle_t h, uint8_t uid, uint16_t addr, - uint16_t value); - -/**************************************************************************** - * Name: nxmb_write_coils - * - * Description: - * Write multiple coils on a remote unit. - * - * Input Parameters: - * h - The NxModbus client instance. - * uid - The remote unit identifier. - * addr - The first coil address to update. - * count - The number of coils to write. - * buf - The source buffer containing coil values. - * - * Returned Value: - * Zero on success; a negated errno value on failure. - * - ****************************************************************************/ - -int nxmb_write_coils(nxmb_handle_t h, uint8_t uid, uint16_t addr, - uint16_t count, FAR const uint8_t *buf); - -/**************************************************************************** - * Name: nxmb_write_holdings - * - * Description: - * Write multiple holding registers on a remote unit. - * - * Input Parameters: - * h - The NxModbus client instance. - * uid - The remote unit identifier. - * addr - The first holding register address to update. - * count - The number of registers to write. - * buf - The source buffer containing register values. - * - * Returned Value: - * Zero on success; a negated errno value on failure. - * - ****************************************************************************/ - -int nxmb_write_holdings(nxmb_handle_t h, uint8_t uid, uint16_t addr, - uint16_t count, FAR const uint16_t *buf); - -/**************************************************************************** - * Name: nxmb_readwrite_holdings - * - * Description: - * Perform a combined read/write of holding registers on a remote unit - * using FC23 (0x17). The write is performed before the read on the - * server side. - * - * Input Parameters: - * h - The NxModbus client instance. - * uid - The remote unit identifier. - * rd_addr - The first holding register address to read. - * rd_count - The number of registers to read (1-125). - * rd_buf - The destination buffer for the returned register values. - * wr_addr - The first holding register address to write. - * wr_count - The number of registers to write (1-121). - * wr_buf - The source buffer containing register values to write. - * - * Returned Value: - * Zero on success; a negated errno value on failure. - * - ****************************************************************************/ - -int nxmb_readwrite_holdings(nxmb_handle_t h, uint8_t uid, uint16_t rd_addr, - uint16_t rd_count, FAR uint16_t *rd_buf, - uint16_t wr_addr, uint16_t wr_count, - FAR const uint16_t *wr_buf); - -/**************************************************************************** - * Name: nxmb_set_timeout - * - * Description: - * Set the client-side response timeout. - * - * Input Parameters: - * h - The NxModbus client instance. - * timeout_ms - The timeout in milliseconds. - * - * Returned Value: - * Zero on success; a negated errno value on failure. - * - ****************************************************************************/ - -int nxmb_set_timeout(nxmb_handle_t h, uint32_t timeout_ms); - -#ifdef __cplusplus -} -#endif - -#endif /* __APPS_INCLUDE_NXMODBUS_NXMB_CLIENT_H */ diff --git a/include/nxmodbus/nxmb_raw.h b/include/nxmodbus/nxmb_raw.h deleted file mode 100644 index e01f42598..000000000 --- a/include/nxmodbus/nxmb_raw.h +++ /dev/null @@ -1,108 +0,0 @@ -/**************************************************************************** - * apps/include/nxmodbus/nxmb_raw.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __APPS_INCLUDE_NXMODBUS_NXMB_RAW_H -#define __APPS_INCLUDE_NXMODBUS_NXMB_RAW_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -#include -#include - -#include - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define NXMB_RAW_HDR_SIZE 8 - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -#ifdef __cplusplus -extern "C" -{ -#endif - -/**************************************************************************** - * Name: nxmb_raw_submit_rx - * - * Description: - * Submit a received raw ADU into the NxModbus protocol core. - * - * Input Parameters: - * h - The NxModbus instance receiving the frame. - * adu - The received raw ADU container. - * - * Returned Value: - * Zero on success; a negated errno value on failure. - * - ****************************************************************************/ - -int nxmb_raw_submit_rx(nxmb_handle_t h, FAR const struct nxmb_adu_s *adu); - -/**************************************************************************** - * Name: nxmb_raw_put_header - * - * Description: - * Serialize the 8-byte MBAP+FC header for an ADU. - * - * Input Parameters: - * adu - The ADU providing the header fields. - * hdr - The destination buffer for the serialized header. - * - * Returned Value: - * None. - * - ****************************************************************************/ - -void nxmb_raw_put_header(FAR const struct nxmb_adu_s *adu, FAR uint8_t *hdr); - -/**************************************************************************** - * Name: nxmb_raw_get_header - * - * Description: - * Parse the 8-byte MBAP+FC header into an ADU structure. - * - * Input Parameters: - * adu - The destination ADU structure. - * hdr - The source buffer containing the serialized header. - * - * Returned Value: - * None. - * - ****************************************************************************/ - -void nxmb_raw_get_header(FAR struct nxmb_adu_s *adu, FAR const uint8_t *hdr); - -#ifdef __cplusplus -} -#endif - -#endif /* __APPS_INCLUDE_NXMODBUS_NXMB_RAW_H */ diff --git a/include/nxmodbus/nxmodbus.h b/include/nxmodbus/nxmodbus.h deleted file mode 100644 index f5307989b..000000000 --- a/include/nxmodbus/nxmodbus.h +++ /dev/null @@ -1,378 +0,0 @@ -/**************************************************************************** - * apps/include/nxmodbus/nxmodbus.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __APPS_INCLUDE_NXMODBUS_NXMODBUS_H -#define __APPS_INCLUDE_NXMODBUS_NXMODBUS_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -#include -#include - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define NXMB_TCP_PORT_DEFAULT 502 - -/* Maximum number of PDU data bytes (everything after the FC byte). - * Configured via Kconfig (CONFIG_NXMODBUS_ADU_DATA_MAX). - */ - -#define NXMB_ADU_DATA_MAX CONFIG_NXMODBUS_ADU_DATA_MAX - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -/* Opaque handle to an NxModbus instance. */ - -typedef FAR struct nxmb_context_s *nxmb_handle_t; - -/* Custom frame handler */ - -typedef CODE int (*nxmb_custom_fc_handler_t)(nxmb_handle_t ctx); - -/* Modbus Application Data Unit container. - * - * Single canonical ADU representation shared by the protocol core and all - * transports. Transports parse incoming wire frames into this struct and - * serialize this struct back out on transmit. - * - * trans_id, proto_id, length - MBAP header fields (TCP-only). - * unit_id - Modbus address byte. - * fc - Modbus function code byte. - * data[] - PDU payload after the function code. - * crc - RTU/ASCII checksum (serial-only). - * - * The MBAP `length` field counts the bytes following it: unit_id + fc + - * data_count. Transports that don't carry MBAP still populate this field - * with the same value so that consumers can derive data_count uniformly: - * data_count = adu.length - 2 - */ - -struct nxmb_adu_s -{ - uint16_t trans_id; - uint16_t proto_id; - uint16_t length; - uint8_t unit_id; - uint8_t fc; - uint8_t data[NXMB_ADU_DATA_MAX]; - uint16_t crc; -}; - -/* Callback used by raw ADU mode to emit a fully-formed frame. */ - -typedef int (*nxmb_raw_tx_cb_t)(FAR const struct nxmb_adu_s *adu, - FAR void *user_data); - -/* Supported transport modes. */ - -enum nxmb_mode_e -{ - NXMB_MODE_INVAL = 0, - NXMB_MODE_RTU, /* Modbus RTU */ - NXMB_MODE_ASCII, /* Modbus ASCII */ - NXMB_MODE_TCP, /* Modbus TCP */ - NXMB_MODE_RAW /* Custom ADU transport */ -}; - -/* Serial parity configuration. */ - -enum nxmb_parity_e -{ - NXMB_PAR_NONE = 0, - NXMB_PAR_EVEN, - NXMB_PAR_ODD -}; - -/* Register access direction passed to callbacks. */ - -enum nxmb_regmode_e -{ - NXMB_REG_READ = 0, - NXMB_REG_WRITE -}; - -/* Standard Modbus exception codes. */ - -enum nxmb_exception_e -{ - NXMB_EX_NONE = 0x00, - NXMB_EX_ILLEGAL_FUNCTION = 0x01, - NXMB_EX_ILLEGAL_DATA_ADDRESS = 0x02, - NXMB_EX_ILLEGAL_DATA_VALUE = 0x03, - NXMB_EX_DEVICE_FAILURE = 0x04, - NXMB_EX_ACKNOWLEDGE = 0x05, - NXMB_EX_DEVICE_BUSY = 0x06, - NXMB_EX_MEMORY_PARITY_ERROR = 0x08, - NXMB_EX_GATEWAY_PATH_FAILED = 0x0a, - NXMB_EX_GATEWAY_TGT_FAILED = 0x0b -}; - -/* Serial transport configuration. */ - -struct nxmb_serial_config_s -{ - FAR const char *devpath; - enum nxmb_parity_e parity; - uint32_t baudrate; -}; - -/* TCP transport configuration. - * - * For slave mode, bindaddr selects the local address and port selects the - * listening port. For client mode, host selects the remote endpoint and - * port selects the remote port. - */ - -struct nxmb_tcp_config_s -{ - FAR const char *host; - FAR const char *bindaddr; - uint16_t port; -}; - -/* Raw ADU transport configuration. */ - -struct nxmb_raw_config_s -{ - FAR void *user_data; - nxmb_raw_tx_cb_t tx_cb; -}; - -union nxmb_transport_config_u -{ - struct nxmb_serial_config_s serial; - struct nxmb_tcp_config_s tcp; - struct nxmb_raw_config_s raw; -}; - -/* Generic NxModbus instance configuration. */ - -struct nxmb_config_s -{ - union nxmb_transport_config_u transport; - enum nxmb_mode_e mode; - uint8_t unit_id; - bool is_client; -}; - -/* Application callback table for Modbus data model access. - * - * The protocol stack passes buffers covering a contiguous address range and - * the application fills or consumes them depending on the register mode. - */ - -struct nxmb_callbacks_s -{ - CODE int (*coil_cb)(FAR uint8_t *buf, uint16_t addr, uint16_t ncoils, - enum nxmb_regmode_e mode, FAR void *priv); - CODE int (*discrete_cb)(FAR uint8_t *buf, uint16_t addr, - uint16_t ndiscrete, FAR void *priv); - CODE int (*input_cb)(FAR uint8_t *buf, uint16_t addr, uint16_t nregs, - FAR void *priv); - CODE int (*holding_cb)(FAR uint8_t *buf, uint16_t addr, uint16_t nregs, - enum nxmb_regmode_e mode, FAR void *priv); - FAR void *priv; -}; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -#ifdef __cplusplus -extern "C" -{ -#endif - -/**************************************************************************** - * Name: nxmb_create - * - * Description: - * Create and initialize an NxModbus instance. This function allocates one - * entry from the static NxModbus instance pool and initializes it for the - * selected transport mode. - * - * Input Parameters: - * handle - A location to receive the opaque NxModbus handle. - * config - The transport and role configuration for the new instance. - * - * Returned Value: - * Zero on success; a negated errno value on failure. - * - ****************************************************************************/ - -int nxmb_create(FAR nxmb_handle_t *handle, - FAR const struct nxmb_config_s *config); - -/**************************************************************************** - * Name: nxmb_destroy - * - * Description: - * Destroy a previously created NxModbus instance. This function releases - * a handle previously obtained from nxmb_create(). - * - * Input Parameters: - * handle - The NxModbus instance to destroy. - * - * Returned Value: - * Zero on success; a negated errno value on failure. - * - ****************************************************************************/ - -int nxmb_destroy(nxmb_handle_t handle); - -/**************************************************************************** - * Name: nxmb_set_callbacks - * - * Description: - * Register the application callback table for an instance. The registered - * callback table defines how the application exposes coils, discrete - * inputs, input registers, and holding registers to the protocol stack. - * - * Input Parameters: - * handle - The NxModbus instance to update. - * cbs - The callback table to associate with the instance. - * - * Returned Value: - * Zero on success; a negated errno value on failure. - * - ****************************************************************************/ - -int nxmb_set_callbacks(nxmb_handle_t handle, - FAR const struct nxmb_callbacks_s *cbs); - -/**************************************************************************** - * Name: nxmb_enable - * - * Description: - * Enable the configured transport and protocol handling. This function - * prepares the configured transport backend so the instance can start - * sending or receiving Modbus ADUs. - * - * Input Parameters: - * handle - The NxModbus instance to enable. - * - * Returned Value: - * Zero on success; a negated errno value on failure. - * - ****************************************************************************/ - -int nxmb_enable(nxmb_handle_t handle); - -/**************************************************************************** - * Name: nxmb_disable - * - * Description: - * Disable an active NxModbus instance. This function stops frame - * processing and releases any transport state held by an enabled instance. - * - * Input Parameters: - * handle - The NxModbus instance to disable. - * - * Returned Value: - * Zero on success; a negated errno value on failure. - * - ****************************************************************************/ - -int nxmb_disable(nxmb_handle_t handle); - -/**************************************************************************** - * Name: nxmb_poll - * - * Description: - * Execute one server-side polling iteration. This function performs a - * single poll of the transport backend and processes one server-side - * Modbus transaction when data is available. - * - * Input Parameters: - * handle - The NxModbus instance to poll. - * - * Returned Value: - * Zero on success; a negated errno value on failure. - * - ****************************************************************************/ - -int nxmb_poll(nxmb_handle_t handle); - -/**************************************************************************** - * Name: nxmb_set_server_id - * - * Description: - * Configure the data returned by FC17 (Report Server ID). The response - * contains the server ID byte, a run indicator, and optional additional - * data supplied by the application. - * - * Input Parameters: - * handle - The NxModbus instance to update. - * id - The server ID byte. - * is_running - True if the device is in a running state. - * additional - Optional additional data bytes (may be NULL). - * addlen - Length of additional data. - * - * Returned Value: - * Zero on success; a negated errno value on failure. - * - ****************************************************************************/ - -int nxmb_set_server_id(nxmb_handle_t handle, uint8_t id, bool is_running, - FAR const uint8_t *additional, uint16_t addlen); - -#ifdef CONFIG_NXMODBUS_CUSTOM_FC -/**************************************************************************** - * Name: nxmb_register_custom_fc - * - * Description: - * Register a custom Modbus function code handler for an instance. - * Custom handlers are checked after standard handlers, so standard - * function codes cannot be overridden. - * - * Input Parameters: - * h - The NxModbus instance handle. - * fc - The custom function code to register. - * handler - The handler function. Receives the instance handle and - * operates on ctx->adu in place: the request fields - * (adu.fc, adu.data[], adu.length) are overwritten with the - * response. Returns zero on success or a negated errno value - * on failure. - * - * Returned Value: - * Zero on success; a negated errno value on failure. - * - ****************************************************************************/ - -int nxmb_register_custom_fc(nxmb_handle_t h, uint8_t fc, - nxmb_custom_fc_handler_t handler); -#endif - -#ifdef __cplusplus -} -#endif - -#endif /* __APPS_INCLUDE_NXMODBUS_NXMODBUS_H */ diff --git a/include/platform/configdata.h b/include/platform/configdata.h index 94df86821..98ea14c61 100644 --- a/include/platform/configdata.h +++ b/include/platform/configdata.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/platform/configdata.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/system/cle.h b/include/system/cle.h index c1204864f..3e3163522 100644 --- a/include/system/cle.h +++ b/include/system/cle.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/system/cle.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/system/microros_transport.h b/include/system/microros_transport.h deleted file mode 100644 index fc89bde3c..000000000 --- a/include/system/microros_transport.h +++ /dev/null @@ -1,50 +0,0 @@ -/**************************************************************************** - * apps/include/system/microros_transport.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __APPS_INCLUDE_SYSTEM_MICROROS_TRANSPORT_H -#define __APPS_INCLUDE_SYSTEM_MICROROS_TRANSPORT_H - -#ifdef __cplusplus -extern "C" -{ -#endif - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/* microros_transport_init - * - * Register the NuttX-native transport (UDP or Serial, selected by Kconfig) - * with the rmw_microxrcedds layer. Must be called once before - * rclc_support_init(). - * - * Returns 0 on success, negated errno on failure. - */ - -int microros_transport_init(void); - -#ifdef __cplusplus -} -#endif - -#endif /* __APPS_INCLUDE_SYSTEM_MICROROS_TRANSPORT_H */ diff --git a/include/system/nxcamera.h b/include/system/nxcamera.h deleted file mode 100644 index 6c4707e42..000000000 --- a/include/system/nxcamera.h +++ /dev/null @@ -1,257 +0,0 @@ -/**************************************************************************** - * apps/include/system/nxcamera.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __APPS_INCLUDE_SYSTEM_NXCAMERA_H -#define __APPS_INCLUDE_SYSTEM_NXCAMERA_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include -#include - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* Standard Video Message Queue message IDs */ - -#define VIDEO_MSG_NONE 0 -#define VIDEO_MSG_STOP 1 - -/**************************************************************************** - * Public Type Declarations - ****************************************************************************/ - -/* This structure describes the internal state of the nxcamera */ - -struct nxcamera_s -{ - int loopstate; /* Current looper test state */ - int capture_fd; /* File descriptor of active - * capture device */ - char capturedev[CONFIG_NAME_MAX]; /* Preferred capture device */ - int display_fd; /* File descriptor of active - * display device */ - char displaydev[CONFIG_NAME_MAX]; /* Display framebuffer device */ - struct fb_planeinfo_s display_pinfo; /* Display plane info */ - struct fb_videoinfo_s display_vinfo; /* Display video controller info */ - char videopath[CONFIG_NAME_MAX]; /* Output video file path */ - char imagepath[CONFIG_NAME_MAX]; /* Output image file path */ - int crefs; /* Number of references */ - pthread_mutex_t mutex; /* Thread sync mutex */ - char mqname[14]; /* Name of display message queue */ - mqd_t mq; /* Message queue for the - * loopthread */ - pthread_t loop_id; /* Thread ID of the loopthread */ - v4l2_format_t fmt; /* Buffer format */ - size_t nbuffers; /* Number of buffers */ - FAR size_t *buf_sizes; /* Buffer lengths */ - FAR uint8_t **bufs; /* Buffer pointers */ -}; - -struct video_msg_s -{ - uint16_t msg_id; /* Message ID */ - union - { - FAR void *ptr; /* Buffer being dequeued */ - uint32_t data; /* Message data */ - } u; -}; - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -#ifdef __cplusplus -#define EXTERN extern "C" -extern "C" -{ -#else -#define EXTERN extern -#endif - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Name: nxcamera_create - * - * Allocates and Initializes a nxcamera context that is passed to all - * nxcamera routines. The looper MUST be destroyed using the - * nxcamera_destroy() routine since the context is reference counted. - * The context can be used in a mode where the caller creates the - * context, starts a looping, and then forgets about the context - * and it will self free. This is because the nxcamera_stream - * will also create a reference to the context, so the client calling - * nxcamera_destroy() won't actually de-allocate anything. The freeing - * will occur after the loopthread has completed. - * - * Alternately, the caller can create the object and hold on to it, then - * the context will persist until the original creator destroys it. - * - * Input Parameters: None - * - * Returned Value: - * Pointer to created nxcamera context or NULL if error. - ****************************************************************************/ - -FAR struct nxcamera_s *nxcamera_create(void); - -/**************************************************************************** - * Name: nxcamera_release - * - * Reduces the reference count to the looper and if it reaches zero, - * frees all memory used by the context. - * - * Input Parameters: - * pcam Pointer to the nxcamera context - * - * Returned Value: - * None - * - ****************************************************************************/ - -void nxcamera_release(FAR struct nxcamera_s *pcam); - -/**************************************************************************** - * Name: nxcamera_reference - * - * Increments the reference count to the looper. - * - * Input Parameters: - * pcam Pointer to the nxcamera context - * - * Returned Value: - * None - * - ****************************************************************************/ - -void nxcamera_reference(FAR struct nxcamera_s *pcam); - -/**************************************************************************** - * Name: nxcamera_stream - * - * nxcamera_stream() tries to capture and then display the raw data using - * the Video system. If a capture device is specified, it will try to use - * that device. - * - * Input: - * pcam Pointer to the initialized Looper context - * width Capture frame width - * height Capture frame height - * framerate Capture frame rate - * format Capture frame pixel format - * - * Returns: - * OK Video is being streamed - * -EBUSY Capture device is busy - * -ENOSYS No supported video format found - * -ENODEV No video capture or framebuffer device suitable - * - ****************************************************************************/ - -int nxcamera_stream(FAR struct nxcamera_s *pcam, - uint16_t width, uint16_t height, - uint32_t framerate, uint32_t format); - -/**************************************************************************** - * Name: nxcamera_stop - * - * Stops current loopback. - * - * Input Parameters: - * pcam - Pointer to the context to initialize - * - * Returned Value: - * OK if file found, device found, and loopback started. - * - ****************************************************************************/ - -int nxcamera_stop(FAR struct nxcamera_s *pcam); - -/**************************************************************************** - * Name: nxcamera_setdevice - * - * Sets the preferred video device to use with the instance of the - * nxcamera. - * - * Input Parameters: - * pcam - Pointer to the context to initialize - * device - Pointer to pathname of the preferred device - * - * Returned Value: - * OK if context initialized successfully, error code otherwise. - * - ****************************************************************************/ - -int nxcamera_setdevice(FAR struct nxcamera_s *pcam, - FAR const char *device); - -/**************************************************************************** - * Name: nxcamera_setfb - * - * Sets the output framebuffer device to use with the - * provided nxcamera context. - * - * Input Parameters: - * pcam - Pointer to the context to initialize - * device - Pointer to pathname of the preferred framebuffer device - * - * Returned Value: - * OK if context initialized successfully, error code otherwise. - * - ****************************************************************************/ - -int nxcamera_setfb(FAR struct nxcamera_s *pcam, FAR const char *device); - -/**************************************************************************** - * Name: nxcamera_setfile - * - * Sets the output file path to use with the provided nxcamera context. - * - * Input Parameters: - * pcam - Pointer to the context to initialize - * file - Pointer to pathname of the preferred output file - * isimage - The path is for image file or not - * - * Returned Value: - * OK if file found, device found, and loopback started. - * - ****************************************************************************/ - -int nxcamera_setfile(FAR struct nxcamera_s *pcam, FAR const char *pfile, - bool isimage); - -#undef EXTERN -#ifdef __cplusplus -} -#endif - -#endif /* __APPS_INCLUDE_SYSTEM_NXCAMERA_H */ diff --git a/include/system/nxlooper.h b/include/system/nxlooper.h index 7218b0f20..51f45c758 100644 --- a/include/system/nxlooper.h +++ b/include/system/nxlooper.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/system/nxlooper.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -31,6 +29,7 @@ #include #include +#include /**************************************************************************** * Pre-processor Definitions @@ -44,30 +43,30 @@ struct nxlooper_s { - int loopstate; /* Current looper test state */ - int recorddev_fd; /* File descriptor of active - * record device */ - char recorddev[CONFIG_NAME_MAX]; /* Preferred record device */ - int playdev_fd; /* File descriptor of active - * play device */ - char playdev[CONFIG_NAME_MAX]; /* Preferred loopback device */ - int crefs; /* Number of references */ - pthread_mutex_t mutex; /* Thread sync mutex */ - char mqname[32]; /* Name of play message queue */ - mqd_t mq; /* Message queue for the - * loopthread */ - pthread_t loop_id; /* Thread ID of the loopthread */ + int loopstate; /* Current looper test state */ + int recorddev_fd; /* File descriptor of active + * record device */ + char recorddev[CONFIG_NAME_MAX]; /* Preferred record device */ + int playdev_fd; /* File descriptor of active + * play device */ + char playdev[CONFIG_NAME_MAX]; /* Preferred loopback device */ + int crefs; /* Number of references */ + sem_t sem; /* Thread sync semaphore */ + char mqname[16]; /* Name of play message queue */ + mqd_t mq; /* Message queue for the + * loopthread */ + pthread_t loop_id; /* Thread ID of the loopthread */ #ifdef CONFIG_AUDIO_MULTI_SESSION - FAR void *pplayses; /* Session assignment from device */ + FAR void *pplayses; /* Session assignment from device */ #endif #ifdef CONFIG_AUDIO_MULTI_SESSION - FAR void *precordses; /* Session assignment from device */ + FAR void *precordses; /* Session assignment from device */ #endif #ifndef CONFIG_AUDIO_EXCLUDE_VOLUME - uint16_t volume; /* Volume as a whole percentage (0-100) */ + uint16_t volume; /* Volume as a whole percentage (0-100) */ #endif }; @@ -163,9 +162,9 @@ int nxlooper_setdevice(FAR struct nxlooper_s *plooper, FAR const char *device); /**************************************************************************** - * Name: nxlooper_loopback + * Name: nxlooper_loopraw * - * nxlooper_loopback() tries to record and then play the raw data using the + * nxlooper_loopraw() tries to record and then play the raw data using the * Audio system. If a device is specified, it will try to use that * device. * @@ -185,9 +184,9 @@ int nxlooper_setdevice(FAR struct nxlooper_s *plooper, * ****************************************************************************/ -int nxlooper_loopback(FAR struct nxlooper_s *plooper, int format, - uint8_t nchannels, uint8_t bpsamp, - uint32_t samprate, uint8_t chmap); +int nxlooper_loopraw(FAR struct nxlooper_s *plooper, + uint8_t nchannels, uint8_t bpsamp, + uint32_t samprate, uint8_t chmap); /**************************************************************************** * Name: nxlooper_stop diff --git a/include/system/nxplayer.h b/include/system/nxplayer.h index f70a9d55c..19e154594 100644 --- a/include/system/nxplayer.h +++ b/include/system/nxplayer.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/system/nxplayer.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -31,6 +29,7 @@ #include #include +#include /**************************************************************************** * Pre-processor Definitions @@ -40,49 +39,39 @@ * Public Type Declarations ****************************************************************************/ -struct nxplayer_dec_ops_s -{ - int format; - CODE int (*pre_parse)(int fd, FAR uint32_t *samplerate, - FAR uint8_t *chans, FAR uint8_t *bps); - CODE int (*fill_data)(int fd, FAR struct ap_buffer_s *apb); -}; - /* This structure describes the internal state of the NxPlayer */ struct nxplayer_s { - int state; /* Current player state */ - int dev_fd; /* File descriptor of active device */ - mqd_t mq; /* Message queue for the playthread */ - char mqname[32]; /* Name of our message queue */ - pthread_t play_id; /* Thread ID of the playthread */ - int crefs; /* Number of references to the player */ - pthread_mutex_t mutex; /* Thread sync mutex */ - int fd; /* File descriptor of open file */ + int state; /* Current player state */ + int dev_fd; /* File descriptor of active device */ + mqd_t mq; /* Message queue for the playthread */ + char mqname[16]; /* Name of our message queue */ + pthread_t play_id; /* Thread ID of the playthread */ + int crefs; /* Number of references to the player */ + sem_t sem; /* Thread sync semaphore */ + int fd; /* File descriptor of open file */ #ifdef CONFIG_NXPLAYER_INCLUDE_PREFERRED_DEVICE - char prefdevice[CONFIG_NAME_MAX]; /* Preferred audio device */ - int prefformat; /* Formats supported by preferred device */ - int preftype; /* Types supported by preferred device */ + char prefdevice[CONFIG_NAME_MAX]; /* Preferred audio device */ + int prefformat; /* Formats supported by preferred device */ + int preftype; /* Types supported by preferred device */ #endif #ifdef CONFIG_NXPLAYER_INCLUDE_MEDIADIR - char mediadir[CONFIG_NAME_MAX]; /* Root media directory where media is located */ + char mediadir[CONFIG_NAME_MAX]; /* Root media directory where media is located */ #endif #ifdef CONFIG_AUDIO_MULTI_SESSION - FAR void *session; /* Session assignment from device */ + FAR void *session; /* Session assignment from device */ #endif #ifndef CONFIG_AUDIO_EXCLUDE_VOLUME - uint16_t volume; /* Volume as a whole percentage (0-100) */ + uint16_t volume; /* Volume as a whole percentage (0-100) */ #ifndef CONFIG_AUDIO_EXCLUDE_BALANCE - uint16_t balance; /* Balance as a whole % (0=left off, 100=right off) */ + uint16_t balance; /* Balance as a whole % (0=left off, 100=right off) */ #endif #endif #ifndef CONFIG_AUDIO_EXCLUDE_TONE - uint16_t treble; /* Treble as a whole % */ - uint16_t bass; /* Bass as a whole % */ + uint16_t treble; /* Treble as a whole % */ + uint16_t bass; /* Bass as a whole % */ #endif - - FAR const struct nxplayer_dec_ops_s *ops; }; typedef int (*nxplayer_func)(FAR struct nxplayer_s *pplayer, char *pargs); @@ -491,70 +480,6 @@ int nxplayer_settreble(FAR struct nxplayer_s *pplayer, uint8_t treble); int nxplayer_systemreset(FAR struct nxplayer_s *pplayer); #endif -/**************************************************************************** - * Name: nxplayer_parse_mp3 - * - * Performs pre-process when play mp3 file. - * Parse samplerate, channels, bps. - * - * Input Parameters: - * pplayer - Pointer to the context to initialize - * - * Returned Value: - * OK if file parsed successfully. - * - ****************************************************************************/ - -int nxplayer_parse_mp3(int fd, FAR uint32_t *samplerate, - FAR uint8_t *chans, FAR uint8_t *bps); - -/**************************************************************************** - * Name: nxplayer_parse_sbc - * - * Performs pre-process when play sbc file. - * Parse samplerate, channels, bps. - * - * Input Parameters: - * pplayer - Pointer to the context to initialize - * - * Returned Value: - * OK if file parsed successfully. - * - ****************************************************************************/ - -int nxplayer_parse_sbc(int fd, FAR uint32_t *samplerate, - FAR uint8_t *chans, FAR uint8_t *bps); - -/**************************************************************************** - * Name: nxplayer_fill_mp3 - * - * Performs read mp3 frame to apb buffer - * - * Input Parameters: - * pplayer - Pointer to the context to initialize - * - * Returned Value: - * OK if file read successfully. - * - ****************************************************************************/ - -int nxplayer_fill_mp3(int fd, FAR struct ap_buffer_s *apb); - -/**************************************************************************** - * Name: nxplayer_fill_common - * - * Performs common function to read data to apb buffer - * - * Input Parameters: - * pplayer - Pointer to the context to initialize - * - * Returned Value: - * OK if file read successfully. - * - ****************************************************************************/ - -int nxplayer_fill_common(int fd, FAR struct ap_buffer_s *apb); - #undef EXTERN #ifdef __cplusplus } diff --git a/include/system/nxrecorder.h b/include/system/nxrecorder.h index c80d2ee15..b632c4a2d 100644 --- a/include/system/nxrecorder.h +++ b/include/system/nxrecorder.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/system/nxrecorder.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -31,6 +29,7 @@ #include #include +#include /**************************************************************************** * Pre-processor Definitions @@ -40,32 +39,22 @@ * Public Type Declarations ****************************************************************************/ -struct nxrecorder_enc_ops_s -{ - int format; - CODE int (*pre_write)(int fd, uint32_t samplerate, - uint8_t chans, uint8_t bps); - CODE int (*write_data)(int fd, struct ap_buffer_s *apb); -}; - /* This structure describes the internal state of the NxRecorder */ struct nxrecorder_s { - int state; /* Current recorder state */ - int dev_fd; /* File descriptor of active device */ - mqd_t mq; /* Message queue for the recordthread */ - char mqname[32]; /* Name of our message queue */ - pthread_t record_id; /* Thread ID of the recordthread */ - int crefs; /* Number of references to the recorder */ - pthread_mutex_t mutex; /* Thread sync mutex */ - int fd; /* File descriptor of open file */ - char device[CONFIG_NAME_MAX]; /* Preferred audio device */ + int state; /* Current recorder state */ + int dev_fd; /* File descriptor of active device */ + mqd_t mq; /* Message queue for the recordthread */ + char mqname[16]; /* Name of our message queue */ + pthread_t record_id; /* Thread ID of the recordthread */ + int crefs; /* Number of references to the recorder */ + sem_t sem; /* Thread sync semaphore */ + int fd; /* File descriptor of open file */ + char device[CONFIG_NAME_MAX]; /* Preferred audio device */ #ifdef CONFIG_AUDIO_MULTI_SESSION - FAR void *session; /* Session assignment from device */ + FAR void *session; /* Session assignment from device */ #endif - - FAR const struct nxrecorder_enc_ops_s *ops; }; typedef int (*nxrecorder_func)(FAR struct nxrecorder_s *precorder, @@ -165,7 +154,7 @@ int nxrecorder_setdevice(FAR struct nxrecorder_s *precorder, FAR const char *device); /**************************************************************************** - * Name: nxrecorder_recordinternal + * Name: nxrecorder_recordraw * * Plays the specified media file (from the filesystem) using the * Audio system. If a preferred device has been set, that device @@ -185,10 +174,9 @@ int nxrecorder_setdevice(FAR struct nxrecorder_s *precorder, * ****************************************************************************/ -int nxrecorder_recordinternal(FAR struct nxrecorder_s *precorder, - FAR const char *filename, int filefmt, - uint8_t nchannels, uint8_t bpsamp, - uint32_t samprate, uint8_t chmap); +int nxrecorder_recordraw(FAR struct nxrecorder_s *precorder, + FAR const char *filename, uint8_t nchannels, + uint8_t bpsamp, uint32_t samprate, uint8_t chmap); /**************************************************************************** * Name: nxrecorder_stop @@ -241,41 +229,6 @@ int nxrecorder_pause(FAR struct nxrecorder_s *precorder); int nxrecorder_resume(FAR struct nxrecorder_s *precorder); #endif -/**************************************************************************** - * Name: nxrecorder_write_amr - * - * Performs pre-process when record amr file. - * - * Input Parameters: - * fd - recording file descriptor - * samplerate - sample rate - * chans - channels num - * bps - bit width - * - * Returned Value: - * OK if file writed successfully. - * - ****************************************************************************/ - -int nxrecorder_write_amr(int fd, uint32_t samplerate, - uint8_t chans, uint8_t bps); - -/**************************************************************************** - * Name: nxrecorder_write_common - * - * Performs common function to write apb buffer to FILE - * - * Input Parameters: - * fd - recording file descriptor - * apb - apb buffer - * - * Returned Value: - * OK if apb buffer write successfully. - * - ****************************************************************************/ - -int nxrecorder_write_common(int fd, FAR struct ap_buffer_s *apb); - #undef EXTERN #ifdef __cplusplus } diff --git a/include/system/readline.h b/include/system/readline.h index 8f40c92c1..7db0f89eb 100644 --- a/include/system/readline.h +++ b/include/system/readline.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/system/readline.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -88,9 +86,8 @@ extern "C" * * If a prompt string is used by the application, then the application * must provide the prompt string to readline() by calling this function. - * This is needed for tab completion, and for line editing's full-line - * redraws (Home, End, history recall, ...), in cases where it is - * necessary to reprint the prompt string. + * This is needed only for tab completion in cases where is it necessary + * to reprint the prompt string. * * Input Parameters: * prompt - The prompt string. This function may then be @@ -109,7 +106,7 @@ extern "C" * ****************************************************************************/ -#if defined(CONFIG_READLINE_TABCOMPLETION) || defined(CONFIG_READLINE_EDIT) +#ifdef CONFIG_READLINE_TABCOMPLETION FAR const char *readline_prompt(FAR const char *prompt); #else # define readline_prompt(p) @@ -177,31 +174,17 @@ FAR const struct extmatch_vtable_s * ssize_t readline_fd(FAR char *buf, int buflen, int infd, int outfd); /**************************************************************************** - * Name: readline_stream + * Name: readline * - * readline_stream() is same to readline_fd() but accept a file stream - * instead of a file handle. + * readline() is same to readline_fd() but accept a file stream instead + * of a file handle. * ****************************************************************************/ #ifdef CONFIG_FILE_STREAM -ssize_t readline_stream(FAR char *buf, int buflen, - FAR FILE *instream, FAR FILE *outstream); +ssize_t readline(FAR char *buf, int buflen, FILE *instream, FILE *outstream); #endif -/**************************************************************************** - * Name: readline - * - * readline will read a line from the terminal and return it, using - * prompt as a prompt. If prompt is NULL or the empty string, no prompt - * is issued. The line returned is allocated with malloc(3); - * the caller must free it when finished. The line reโ€turned has the - * final newline removed, so only the text of the line remains. - * - ****************************************************************************/ - -FAR char *readline(FAR const char *prompt); - /**************************************************************************** * Name: std_readline * @@ -229,7 +212,7 @@ FAR char *readline(FAR const char *prompt); * ****************************************************************************/ -#define std_readline(b,s) readline_stream(b,s,stdin,stdout) +#define std_readline(b,s) readline(b,s,stdin,stdout) #undef EXTERN #ifdef __cplusplus diff --git a/include/system/settings.h b/include/system/settings.h deleted file mode 100644 index 943be7add..000000000 --- a/include/system/settings.h +++ /dev/null @@ -1,308 +0,0 @@ -/**************************************************************************** - * apps/include/system/settings.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef UTILS_SETTINGS_H_ -#define UTILS_SETTINGS_H_ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include -#include -#include -#include - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define VALID 0x600d /* "Magic" number to confirm storage is OK */ - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -enum settings_type_e -{ - SETTING_EMPTY = 0, - SETTING_INT, /* INT32 */ - SETTING_BOOL, - SETTING_FLOAT, - SETTING_STRING, - SETTING_IP_ADDR, -}; - -typedef struct -{ - char key[CONFIG_SYSTEM_SETTINGS_KEY_SIZE]; - enum settings_type_e type; - union - { - int i; - double f; - char s[CONFIG_SYSTEM_SETTINGS_VALUE_SIZE]; - struct in_addr ip; - } val; -} setting_t; - -typedef struct -{ - char file[CONFIG_SYSTEM_SETTINGS_MAX_FILENAME]; - - int (*load_fn)(FAR char *file); - int (*save_fn)(FAR char *file); -} storage_t; - -struct notify_s -{ - pid_t pid; - uint8_t signo; -}; - -enum storage_type_e -{ - STORAGE_BINARY = 0, - STORAGE_TEXT, -}; - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Name: settings_init - * - * Description: - * Initializes the settings storage. - * - * Input Parameters: none - * - * Returned Value: none - * - ****************************************************************************/ - -void settings_init(void); - -/**************************************************************************** - * Name: settings_setstorage - * - * Description: - * Sets a file to be used as a settings storage. - * Except from the first file, if loading the file causes any changes - * to the settings, then the new map will be dumped to all files - * (effectively it syncs all storages). - * - * Input Parameters: - * file - the filename of the storage to use - * type - the type of the storage (BINARY or TEXT) - * - * Returned Value: - * Success or negated failure code - * - ****************************************************************************/ - -int settings_setstorage(FAR char *file, enum storage_type_e type); - -/**************************************************************************** - * Name: settings_sync - * - * Description: - * Synchronizes the storage. - * - * wait_dump - if cached saves are enabled, this determines whether - * the function will wait until the save is actually - * completed or just schedule a new save - * - * Returned Value: - * Success or negated failure code - * - ****************************************************************************/ - -int settings_sync(bool wait_dump); - -/**************************************************************************** - * Name: settings_notify - * - * Description: - * Registers a task to be notified on any change of the settings. - * Whenever any value is changed, a signal will be sent to all - * registered threads. Signals are NOT sent when new settings are - * created or when the whole storage is cleared. - * - * Input Parameters: - * none - * - * Returned Value: - * Success or negated failure code - * - ****************************************************************************/ - -int settings_notify(void); - -/**************************************************************************** - * Name: settings_hash - * - * Description: - * Gets the hash of the settings storage. - * - * This hash represents the internal state of the settings map. A - * unique number is calculated based on the contents of the whole map. - * - * This hash can be used to check the settings for any alterations, i.e. - * any setting that may had its value changed since last check. - * - * Input Parameters: - * none - * - * Returned Value: - * Success or negated failure code - * - ****************************************************************************/ - -int settings_hash(FAR uint32_t *h); - -/**************************************************************************** - * Name: settings_clear - * - * Description: - * Clears all settings. - * Data in all storages are purged. - * - * Note that if the settings are cleared during the application run-time - * (i.e. not during initialization), every access to the settings storage - * will fail. - * - * All settings must be created again. This can be done either by calling - * Settings_create() again, or by restarting the application. - * - * Input Parameters: - * none - * - * Returned Value: - * Success or negated failure code - * - ****************************************************************************/ - -int settings_clear(void); - -/**************************************************************************** - * Name: settings_create - * - * Description: - * Creates a new setting. - * - * If the setting is found to exist in any of the storages, it will - * be loaded. Else, it will be created and the default value will be - * assigned. - * - * Input Parameters: - * key - the key of the setting. - * type - the type of the setting. - * ... - the default value of the setting. - * - * Returned Value: - * Success or negated failure code - * - ****************************************************************************/ - -int settings_create(FAR char *key, enum settings_type_e type, ...); - -/**************************************************************************** - * Name: settings_type - * - * Description: - * Gets the type of a setting. - * - * Input Parameters: - * key - the key of the setting. - * type = pointer to int for the returned setting type - * - * Returned Value: - * Success or negated failure code - * - ****************************************************************************/ - -int settings_type(FAR char *key, FAR enum settings_type_e *stype); - -/**************************************************************************** - * Name: settings_get - * - * Description: - * Gets the value of a setting. - * - * Input Parameters: - * key - the key of the setting. - * type - the type of the setting - * ... - pointer to store the setting value. - * - * Returned Value: - * Success or negated failure code - * - ****************************************************************************/ - -int settings_get(FAR char *key, FAR enum settings_type_e type, ...); - -/**************************************************************************** - * Name: settings_set - * - * Description: - * Sets the value of a setting. - * - * Input Parameters: - * key - the key of the setting. - * type - the type of the setting - * ... - the new value of the setting. - * - * Returned Value: - * Success or negated failure code - * - ****************************************************************************/ - -int settings_set(FAR char *key, FAR enum settings_type_e type, ...); - -/**************************************************************************** - * Name: settings_iterate - * - * Description: - * Gets a copy of a setting at the specified position. It can be used to - * iterate over the settings map, by using successive values of idx. - * - * Input Parameters: - * idx - the iteration index for the setting. - * setting - pointer to return the setting value - * - * Returned Value: - * Success or negated failure code - * - ****************************************************************************/ - -int settings_iterate(int idx, FAR setting_t *setting); - -#endif /* UTILS_SETTINGS_H_ */ - diff --git a/include/system/smf.h b/include/system/smf.h deleted file mode 100644 index edb1bf81b..000000000 --- a/include/system/smf.h +++ /dev/null @@ -1,267 +0,0 @@ -/**************************************************************************** - * apps/include/system/smf.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __APPS_INCLUDE_SYSTEM_SMF_H -#define __APPS_INCLUDE_SYSTEM_SMF_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -#include -#include - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#ifdef CONFIG_SYSTEM_SMF_ANCESTOR_SUPPORT -# ifdef CONFIG_SYSTEM_SMF_INITIAL_TRANSITION -# define SMF_CREATE_STATE(_entry, _run, _exit, _parent, _initial) \ - { \ - .entry = (_entry), \ - .run = (_run), \ - .exit = (_exit), \ - .parent = (_parent), \ - .initial = (_initial), \ - } -# else -# define SMF_CREATE_STATE(_entry, _run, _exit, _parent, _initial) \ - { \ - .entry = (_entry), \ - .run = (_run), \ - .exit = (_exit), \ - .parent = (_parent), \ - } -# endif -#else -# define SMF_CREATE_STATE(_entry, _run, _exit, _parent, _initial) \ - { \ - .entry = (_entry), \ - .run = (_run), \ - .exit = (_exit), \ - } -#endif - -#define SMF_CTX(o) ((struct smf_ctx *)(o)) - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -enum smf_state_result -{ - SMF_EVENT_HANDLED, - SMF_EVENT_PROPAGATE -}; - -typedef void (*state_method)(void *obj); - -typedef enum smf_state_result (*state_execution)(void *obj); - -struct smf_state -{ - /* Optional method that will be run when this state is entered. */ - - state_method entry; - - /* Optional method that will be run repeatedly during the state machine - * loop. - */ - - state_execution run; - - /* Optional method that will be run when this state exits. */ - - state_method exit; - -#ifdef CONFIG_SYSTEM_SMF_ANCESTOR_SUPPORT - /* Optional parent state that contains common entry/run/exit - * implementation among various child states. - * entry: Parent function executes BEFORE child function. - * run: Parent function executes AFTER child function. - * exit: Parent function executes AFTER child function. - * Note: When transitioning between two child states with a shared - * parent, that parent's exit and entry functions do not execute. - */ - - const struct smf_state *parent; - -# ifdef CONFIG_SYSTEM_SMF_INITIAL_TRANSITION - /* Optional initial transition state. NULL for leaf states. */ - - const struct smf_state *initial; -# endif /* CONFIG_SYSTEM_SMF_INITIAL_TRANSITION */ -#endif /* CONFIG_SYSTEM_SMF_ANCESTOR_SUPPORT */ -}; - -struct smf_ctx -{ - /* Current state the state machine is executing. */ - - const struct smf_state *current; - - /* Previous state the state machine executed. */ - - const struct smf_state *previous; - -#ifdef CONFIG_SYSTEM_SMF_ANCESTOR_SUPPORT - /* Currently executing state (which may be a parent). */ - - const struct smf_state *executing; -#endif /* CONFIG_SYSTEM_SMF_ANCESTOR_SUPPORT */ - - /* This value is set by the set_terminate function and should - * terminate the state machine when its set to a value other than - * zero when it's returned by the run_state function. - */ - - int32_t terminate_val; - - /* The state machine casts this to a "struct internal_ctx" and it's - * used to track state machine context. - */ - - uint32_t internal; -}; - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -#undef EXTERN -#if defined(__cplusplus) -#define EXTERN extern "C" -extern "C" -{ -#else -#define EXTERN extern -#endif - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Name: smf_set_initial - * - * Description: - * Initialize the state machine and set its initial state. - * - * Input Parameters: - * ctx - State machine context - * init_state - Initial state the state machine starts in - * - ****************************************************************************/ - -void smf_set_initial(struct smf_ctx *ctx, - const struct smf_state *init_state); - -/**************************************************************************** - * Name: smf_set_state - * - * Description: - * Change the state machine state. This handles exiting the previous state - * and entering the target state. For HSMs the entry and exit actions of - * the Least Common Ancestor are not run. - * - * Input Parameters: - * ctx - State machine context - * new_state - State to transition to - * - ****************************************************************************/ - -void smf_set_state(struct smf_ctx *ctx, const struct smf_state *new_state); - -/**************************************************************************** - * Name: smf_set_terminate - * - * Description: - * Terminate a state machine. - * - * Input Parameters: - * ctx - State machine context - * val - Non-zero termination value returned by smf_run_state - * - ****************************************************************************/ - -void smf_set_terminate(struct smf_ctx *ctx, int32_t val); - -/**************************************************************************** - * Name: smf_run_state - * - * Description: - * Run one iteration of a state machine (including any parent states). - * - * Input Parameters: - * ctx - State machine context - * - * Returned Value: - * A non-zero value terminates the state machine. This non-zero value may - * represent a terminal state being reached or detection of an error. - * - ****************************************************************************/ - -int32_t smf_run_state(struct smf_ctx *ctx); - -/**************************************************************************** - * Name: smf_get_current_leaf_state - * - * Description: - * Get the current leaf state. This may be a parent state if the HSM is - * malformed (initial transitions are not set up correctly). - * - ****************************************************************************/ - -static inline const struct smf_state * -smf_get_current_leaf_state(const struct smf_ctx *ctx) -{ - return ctx->current; -} - -/**************************************************************************** - * Name: smf_get_current_executing_state - * - * Description: - * Get the state that is currently executing. This may be a parent state. - * - ****************************************************************************/ - -static inline const struct smf_state * -smf_get_current_executing_state(const struct smf_ctx *ctx) -{ -#ifdef CONFIG_SYSTEM_SMF_ANCESTOR_SUPPORT - return ctx->executing; -#else - return ctx->current; -#endif /* CONFIG_SYSTEM_SMF_ANCESTOR_SUPPORT */ -} - -#undef EXTERN -#if defined(__cplusplus) -} -#endif - -#endif /* __APPS_INCLUDE_SYSTEM_SMF_H */ diff --git a/include/system/termcurses.h b/include/system/termcurses.h index 458526102..852258de7 100644 --- a/include/system/termcurses.h +++ b/include/system/termcurses.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/system/termcurses.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/system/zmodem.h b/include/system/zmodem.h index 3a7eddea9..1c13742bc 100644 --- a/include/system/zmodem.h +++ b/include/system/zmodem.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/system/zmodem.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/include/testing/unity_config.h b/include/testing/unity_config.h index adee96f8e..4cfe157ac 100644 --- a/include/testing/unity_config.h +++ b/include/testing/unity_config.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/testing/unity_config.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -47,10 +45,4 @@ # define UNITY_OUTPUT_COLOR 1 #endif -/* Enable Unity TEST_PRINTF */ - -#ifdef CONFIG_TESTING_UNITY_PRINT_FORMATTED -# define UNITY_INCLUDE_PRINT_FORMATTED 1 -#endif - #endif /* UNITY_CONFIG_H */ diff --git a/include/wasm/math.h b/include/wasm/math.h deleted file mode 100644 index bd0b887fe..000000000 --- a/include/wasm/math.h +++ /dev/null @@ -1,34 +0,0 @@ -/**************************************************************************** - * apps/include/wasm/math.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __INCLUDE_WASM_MATH_H -#define __INCLUDE_WASM_MATH_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -/* Forwards math.h to nuttx/include/nuttx/lib/math.h */ - -#include - -#endif /* __INCLUDE_WASM_MATH_H */ diff --git a/include/wireless/ieee802154.h b/include/wireless/ieee802154.h index 95e854376..383aa3fcb 100644 --- a/include/wireless/ieee802154.h +++ b/include/wireless/ieee802154.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/wireless/ieee802154.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -122,7 +120,7 @@ int sixlowpan_assoc_resp(int sock, FAR const char *ifname, int sixlowpan_disassoc_req(int sock, FAR const char *ifname, FAR const struct ieee802154_disassoc_req_s *req); int sixlowpan_get_req(int sock, FAR const char *ifname, - FAR struct ieee802154_get_req_s *req); + FAR const struct ieee802154_get_req_s *req); int sixlowpan_gts_req(int sock, FAR const char *ifname, FAR const struct ieee802154_gts_req_s *req); int sixlowpan_orphan_resp(int sock, FAR const char *ifname, diff --git a/include/wireless/iwpan.h b/include/wireless/iwpan.h index 3e0efc350..84df05419 100644 --- a/include/wireless/iwpan.h +++ b/include/wireless/iwpan.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/include/wireless/iwpan.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -39,7 +37,7 @@ * Public Data ****************************************************************************/ -#ifdef __cplusplus + #ifdef __cplusplus #define EXTERN extern "C" extern "C" { diff --git a/include/wireless/wapi.h b/include/wireless/wapi.h index 8663b338b..062291dcf 100644 --- a/include/wireless/wapi.h +++ b/include/wireless/wapi.h @@ -1,12 +1,21 @@ /**************************************************************************** * apps/include/wireless/wapi.h * - * SPDX-License-Identifier: BSD-3-Clause - * SPDX-FileCopyrightText: 2017,2019 Gregory Nutt - * SPDX-FileCopyrightText: 2010, Volkan YAZICI - * SPDX-FileCopyrightText: 2003-2005, Jouni Malinen - * SPDX-FileContributor: Gregory Nutt - * SPDX-FileContributor: Simon Piriou + * Copyright (C) 2017, 2019 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Adapted for NuttX from WAPI: + * + * Copyright (c) 2010, Volkan YAZICI + * All rights reserved. + * + * And includes WPA supplicant logic contributed by: + * + * Author: Simon Piriou + * + * Which was adapted to NuttX from driver_ext.h + * + * Copyright (c) 2003-2005, Jouni Malinen * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -44,7 +53,6 @@ * Included Files ****************************************************************************/ -#include #include #include #include @@ -139,21 +147,6 @@ enum wapi_mode_e WAPI_MODE_MESH = IW_MODE_MESH /* Mesh (IEEE 802.11s) network */ }; -/* Flags for encoding */ - -enum wapi_encode_e -{ - WAPI_ENCODE_INDEX = IW_ENCODE_INDEX, /* Token index (if needed) */ - WAPI_ENCODE_FLAGS = IW_ENCODE_FLAGS, /* Flags defined below */ - WAPI_ENCODE_MODE = IW_ENCODE_MODE, /* Modes defined below */ - WAPI_ENCODE_DISABLED = IW_ENCODE_DISABLED, /* Encoding disabled */ - WAPI_ENCODE_ENABLED = IW_ENCODE_ENABLED, /* Encoding enabled */ - WAPI_ENCODE_RESTRICTED = IW_ENCODE_RESTRICTED, /* Refuse non-encoded packets */ - WAPI_ENCODE_OPEN = IW_ENCODE_OPEN, /* Accept non-encoded packets */ - WAPI_ENCODE_NOKEY = IW_ENCODE_NOKEY, /* Key is write only, so not present */ - WAPI_ENCODE_TEMP = IW_ENCODE_TEMP /* Temporary key */ -}; - /* Bitrate flags. * * At the moment, unicast (IW_BITRATE_UNICAST) and broadcast @@ -200,8 +193,6 @@ struct wapi_scan_info_s int bitrate; int has_rssi; int rssi; - int has_encode; - int encode; }; /* Linked list container for routing table rows. */ @@ -257,27 +248,19 @@ enum wpa_alg_e WPA_ALG_BIP_CMAC_256 }; -enum wpa_ver_e -{ - WPA_VER_NONE = 0, - WPA_VER_1, - WPA_VER_2, - WPA_VER_3 -}; - /* This structure provides the wireless configuration to * wpa_driver_wext_associate(). */ struct wpa_wconfig_s { - enum wapi_mode_e sta_mode; /* Mode of operation, e.g. IW_MODE_INFRA */ + uint8_t sta_mode; /* Mode of operation, e.g. IW_MODE_INFRA */ uint8_t auth_wpa; /* IW_AUTH_WPA_VERSION values, e.g. * IW_AUTH_WPA_VERSION_WPA2 */ uint8_t cipher_mode; /* IW_AUTH_PAIRWISE_CIPHER and * IW_AUTH_GROUP_CIPHER values, e.g., * IW_AUTH_CIPHER_CCMP */ - enum wpa_alg_e alg; /* See enum wpa_alg_e above, e.g. + uint8_t alg; /* See enum wpa_alg_e above, e.g. * WPA_ALG_CCMP */ double freq; /* Channel frequency */ enum wapi_freq_flag_e flag; /* Channel frequency flag */ @@ -289,22 +272,11 @@ struct wpa_wconfig_s FAR const char *passphrase; /* E.g., "mySSIDpassphrase" */ }; -/* COEX *********************************************************************/ - -enum wapi_pta_prio_e -{ - WAPI_PTA_PRIORITY_COEX_MAXIMIZED = IW_PTA_PRIORITY_COEX_MAXIMIZED, - WAPI_PTA_PRIORITY_COEX_HIGH = IW_PTA_PRIORITY_COEX_HIGH, - WAPI_PTA_PRIORITY_BALANCED = IW_PTA_PRIORITY_BALANCED, - WAPI_PTA_PRIORITY_WLAN_HIGHD = IW_PTA_PRIORITY_WLAN_HIGH, - WAPI_PTA_PRIORITY_WLAN_MAXIMIZED = IW_PTA_PRIORITY_WLAN_MAXIMIZED -}; - /**************************************************************************** * Public Data ****************************************************************************/ -#ifdef __cplusplus + #ifdef __cplusplus #define EXTERN extern "C" extern "C" { @@ -324,10 +296,6 @@ EXTERN FAR const char *g_wapi_essid_flags[]; EXTERN FAR const char *g_wapi_alg_flags[]; -/* Passphrase WPA Version flag names. */ - -EXTERN FAR const char *g_wapi_wpa_ver_flags[]; - /* Supported operation mode names. */ EXTERN FAR const char *g_wapi_modes[]; @@ -340,10 +308,6 @@ EXTERN FAR const char *g_wapi_bitrate_flags[]; EXTERN FAR const char *g_wapi_txpower_flags[]; -/* PTA priority flag names. */ - -EXTERN FAR const char *g_wapi_pta_prio_flags[]; - /**************************************************************************** * Public Function Prototyppes ****************************************************************************/ @@ -699,31 +663,6 @@ int wapi_scan_channel_init(int sock, FAR const char *ifname, FAR const char *essid, uint8_t *channels, int num_channels); -/**************************************************************************** - * Name: wapi_escan_init - * - * Description: - * Starts a extended scan on the given interface, you can specify the scan - * type. Root privileges are required to start a scan. - * - ****************************************************************************/ - -int wapi_escan_init(int sock, FAR const char *ifname, - uint8_t scan_type, FAR const char *essid); - -/**************************************************************************** - * Name: wapi_escan_channel_init - * - * Description: - * Starts a scan on the given interface. Root privileges are required to - * start a scan with specified channels. - * - ****************************************************************************/ - -int wapi_escan_channel_init(int sock, FAR const char *ifname, - uint8_t scan_type, FAR const char *essid, - uint8_t *channels, int num_channels); - /**************************************************************************** * Name: wapi_scan_stat * @@ -775,17 +714,6 @@ void wapi_scan_coll_free(FAR struct wapi_list_s *aps); int wapi_set_country(int sock, FAR const char *ifname, FAR const char *country); -/**************************************************************************** - * Name: wapi_get_country - * - * Description: - * Get the country code - * - ****************************************************************************/ - -int wapi_get_country(int sock, FAR const char *ifname, - FAR char *country); - /**************************************************************************** * Name: wapi_get_sensitivity * @@ -933,80 +861,6 @@ int wpa_driver_wext_get_auth_param(int sockfd, FAR const char *ifname, void wpa_driver_wext_disconnect(int sockfd, FAR const char *ifname); -/**************************************************************************** - * Name: wapi_set_pta_prio - * - * Description: - * Sets the pta priority of the device. - * - ****************************************************************************/ - -int wapi_set_pta_prio(int sock, FAR const char *ifname, - enum wapi_pta_prio_e pta_prio); - -/**************************************************************************** - * Name: wapi_get_pta_prio - * - * Description: - * Gets the pta priority of the device. - * - ****************************************************************************/ - -int wapi_get_pta_prio(int sock, FAR const char *ifname, - enum wapi_pta_prio_e *pta_prio); - -/**************************************************************************** - * Name: wapi_set_pmksa - * - * Description: - * Set the wlan pmksa. - * - ****************************************************************************/ - -int wapi_set_pmksa(int sock, FAR const char *ifname, - FAR const uint8_t *pmk, int len); - -/**************************************************************************** - * Name: wapi_get_pmksa - * - * Description: - * Get the wlan pmksa. - * - ****************************************************************************/ - -int wapi_get_pmksa(int sock, FAR const char *ifname, - FAR uint8_t *pmk, int len); - -/**************************************************************************** - * Name: wapi_extend_params - * - * Description: - * wapi extension interface for privatization method. - * - ****************************************************************************/ - -int wapi_extend_params(int sock, int cmd, FAR struct iwreq *wrq); - -/**************************************************************************** - * Name: wapi_set_power_save - * - * Description: - * Set power save status of wifi. - * - ****************************************************************************/ - -int wapi_set_power_save(int sock, FAR const char *ifname, bool on); - -/**************************************************************************** - * Name: wapi_get_power_save - * - * Description: - * Get power save status of wifi. - * - ****************************************************************************/ - -int wapi_get_power_save(int sock, FAR const char *ifname, bool *on); - #undef EXTERN #ifdef __cplusplus } diff --git a/industry/CMakeLists.txt b/industry/CMakeLists.txt deleted file mode 100644 index 0869d77d9..000000000 --- a/industry/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -# ############################################################################## -# apps/industry/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -nuttx_add_subdirectory() - -nuttx_generate_kconfig(MENUDESC "Industrial Applications") diff --git a/industry/Make.defs b/industry/Make.defs index 5d2de7618..5b68b9ef8 100644 --- a/industry/Make.defs +++ b/industry/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/industry/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/industry/Makefile b/industry/Makefile index 42ed16d6b..9f4937e18 100644 --- a/industry/Makefile +++ b/industry/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/industry/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/industry/abnt_codi/Make.defs b/industry/abnt_codi/Make.defs index b220cf63c..c8ba7ec1c 100644 --- a/industry/abnt_codi/Make.defs +++ b/industry/abnt_codi/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/industry/abnt_codi/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -20,6 +18,6 @@ # ############################################################################ -ifneq ($(CONFIG_INDUSTRY_ABNT_CODI_LIB),) +ifeq ($(CONFIG_INDUSTRY_ABNT_CODI_LIB),y) CONFIGURED_APPS += $(APPDIR)/industry/abnt_codi endif diff --git a/industry/abnt_codi/Makefile b/industry/abnt_codi/Makefile index f3b9ee9d9..037a87de0 100644 --- a/industry/abnt_codi/Makefile +++ b/industry/abnt_codi/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/industry/abnt_codi/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/industry/abnt_codi/README.md b/industry/abnt_codi/README.md new file mode 100644 index 000000000..849e2dc96 --- /dev/null +++ b/industry/abnt_codi/README.md @@ -0,0 +1,27 @@ +# Industry / `abnt_codi` ABNT CODI + +The ABNT CODI is an old energy meter standard used in Brazil. + +This code interprets the end user serial output existent in the energy meter. +That output externalizes its data blinking an LED as a serial protocol at the +baudrate of `110 BPS` and uses `8` octects: + +| Octet | Bits | Description +|:-----:|------:|------------- +| `001` | `0-7` | Number of seconds to the end of current active demand (`LSB`) +| `002` | `0-3` | Number of seconds to the end of current active demand (`MSB`) +| | `4` | Bill indicator. It is inverted at each demand replenishment +| | `5` | Reactive Interval Indicator. Inverted at end react interval +| | `6` | If `1` means the reactive-capacitive is used to calculate `UFER` +| | `7` | If `1` means the reactive-inductive is used to calculate `UFER` +| `003` | `0-3` | Current seasonal segment:
`0001` โ€“ tip
`0010` โ€“ out of tip
`1000` โ€“ reserved +| | `4-5` | Type of charging indicator (flag):
`00` โ€“ Blue
`01` โ€“ Green
`10` โ€“ Irrigators
`11` โ€“ Other +| | `6` | Not used +| | `7` | If equal `1` means reactive rate is enabled +| `004` | `0-7` | Number of pulses for active energy of cur dem interv (`LSB`) +| `005` | `0-6` | Number of pulses for active energy of cur dem interv (`MSB`) +| | `7` | Not used +| `006` | `0-7` | Number of pulses for reactive energy of cur dem interv (`LSB`) +| `007` | `0-6` | Number of pulses for reactive energy of cur dem interv (`MSB`) +| | `7` | Not used +| `008` | `0-7` | Inverted bits of _xor_ from previous octects diff --git a/industry/abnt_codi/abnt_codi.c b/industry/abnt_codi/abnt_codi.c index 911d8ae29..260b08e82 100644 --- a/industry/abnt_codi/abnt_codi.c +++ b/industry/abnt_codi/abnt_codi.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/industry/abnt_codi/abnt_codi.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/industry/foc/CMakeLists.txt b/industry/foc/CMakeLists.txt deleted file mode 100644 index 7331644cd..000000000 --- a/industry/foc/CMakeLists.txt +++ /dev/null @@ -1,170 +0,0 @@ -# ############################################################################## -# apps/industry/foc/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_INDUSTRY_FOC) - - set(CSRCS foc_utils.c) - - if(CONFIG_INDUSTRY_FOC_FLOAT) - list( - APPEND - CSRCS - float/foc_ramp.c - float/foc_handler.c - float/foc_angle.c - float/foc_velocity.c - float/foc_routine.c) - - if(CONFIG_INDUSTRY_FOC_ANGLE_OPENLOOP) - list(APPEND CSRCS float/foc_ang_openloop.c) - endif() - - if(CONFIG_INDUSTRY_FOC_ANGLE_ONFO) - list(APPEND CSRCS float/foc_ang_onfo.c) - endif() - - if(CONFIG_INDUSTRY_FOC_ANGLE_OSMO) - list(APPEND CSRCS float/foc_ang_osmo.c) - endif() - - if(CONFIG_INDUSTRY_FOC_ANGLE_QENCO) - list(APPEND CSRCS float/foc_ang_qenco.c) - endif() - - if(CONFIG_INDUSTRY_FOC_ANGLE_HALL) - list(APPEND CSRCS float/foc_ang_hall.c) - endif() - - if(CONFIG_INDUSTRY_FOC_CORDIC) - list(APPEND CSRCS float/foc_cordic.c) - endif() - - if(CONFIG_INDUSTRY_FOC_CONTROL_PI) - list(APPEND CSRCS float/foc_picontrol.c) - endif() - - if(CONFIG_INDUSTRY_FOC_MODULATION_SVM3) - list(APPEND CSRCS float/foc_svm3.c) - endif() - - if(CONFIG_INDUSTRY_FOC_HAVE_MODEL) - list(APPEND CSRCS float/foc_model.c) - endif() - - if(CONFIG_INDUSTRY_FOC_MODEL_PMSM) - list(APPEND CSRCS float/foc_model_pmsm.c) - endif() - - if(CONFIG_INDUSTRY_FOC_ALIGN) - list(APPEND CSRCS float/foc_align.c) - endif() - - if(CONFIG_INDUSTRY_FOC_IDENT) - list(APPEND CSRCS float/foc_ident.c) - endif() - - if(CONFIG_INDUSTRY_FOC_VELOCITY_ODIV) - list(APPEND CSRCS float/foc_vel_odiv.c) - endif() - - if(CONFIG_INDUSTRY_FOC_VELOCITY_OPLL) - list(APPEND CSRCS float/foc_vel_opll.c) - endif() - - if(CONFIG_INDUSTRY_FOC_FEEDFORWARD) - list(APPEND CSRCS float/foc_feedforward.c) - endif() - endif() - - if(CONFIG_INDUSTRY_FOC_FIXED16) - list( - APPEND - CSRCS - fixed16/foc_ramp.c - fixed16/foc_handler.c - fixed16/foc_angle.c - fixed16/foc_velocity.c - fixed16/foc_routine.c) - - if(CONFIG_INDUSTRY_FOC_ANGLE_OPENLOOP) - list(APPEND CSRCS fixed16/foc_ang_openloop.c) - endif() - - if(CONFIG_INDUSTRY_FOC_ANGLE_ONFO) - list(APPEND CSRCS fixed16/foc_ang_onfo.c) - endif() - - if(CONFIG_INDUSTRY_FOC_ANGLE_OSMO) - list(APPEND CSRCS fixed16/foc_ang_osmo.c) - endif() - - if(CONFIG_INDUSTRY_FOC_ANGLE_QENCO) - list(APPEND CSRCS fixed16/foc_ang_qenco.c) - endif() - - if(CONFIG_INDUSTRY_FOC_ANGLE_HALL) - list(APPEND CSRCS fixed16/foc_ang_hall.c) - endif() - - if(CONFIG_INDUSTRY_FOC_CORDIC) - list(APPEND CSRCS fixed16/foc_cordic.c) - endif() - - if(CONFIG_INDUSTRY_FOC_CONTROL_PI) - list(APPEND CSRCS fixed16/foc_picontrol.c) - endif() - - if(CONFIG_INDUSTRY_FOC_MODULATION_SVM3) - list(APPEND CSRCS fixed16/foc_svm3.c) - endif() - - if(CONFIG_INDUSTRY_FOC_HAVE_MODEL) - list(APPEND CSRCS fixed16/foc_model.c) - endif() - - if(CONFIG_INDUSTRY_FOC_MODEL_PMSM) - list(APPEND CSRCS fixed16/foc_model_pmsm.c) - endif() - - if(CONFIG_INDUSTRY_FOC_ALIGN) - list(APPEND CSRCS fixed16/foc_align.c) - endif() - - if(CONFIG_INDUSTRY_FOC_IDENT) - list(APPEND CSRCS fixed16/foc_ident.c) - endif() - - if(CONFIG_INDUSTRY_FOC_VELOCITY_ODIV) - list(APPEND CSRCS fixed16/foc_vel_odiv.c) - endif() - - if(CONFIG_INDUSTRY_FOC_VELOCITY_OPLL) - list(APPEND CSRCS fixed16/foc_vel_opll.c) - endif() - - if(CONFIG_INDUSTRY_FOC_FEEDFORWARD) - list(APPEND CSRCS fixed16/foc_feedforward.c) - endif() - endif() - - target_sources(apps PRIVATE ${CSRCS}) -endif() diff --git a/industry/foc/Kconfig b/industry/foc/Kconfig index 1bbe71ad0..a6e55c169 100644 --- a/industry/foc/Kconfig +++ b/industry/foc/Kconfig @@ -7,28 +7,14 @@ config INDUSTRY_FOC bool "FOC Library" default n select LIBDSP - depends on MOTOR_FOC ---help--- Enable or disable the FOC Library if INDUSTRY_FOC -config INDUSTRY_FOC_DEBUG - bool "Enable FOCLIB debug log" - default n - -config INDUSTRY_FOC_ERROR - bool "Enable FOCLIB error log" - default n - -config INDUSTRY_FOC_WARN - bool "Enable FOCLIB warn log" - default n - config INDUSTRY_FOC_CORDIC bool "Enable CORDIC support" default n - depends on MATH_CORDIC ---help--- Enable support for CORDIC hardware acceleration @@ -130,12 +116,6 @@ config INDUSTRY_FOC_MODULATION_SVM3 ---help--- Enable support for FOC 3-phase space vector modulation -config INDUSTRY_FOC_FEEDFORWARD - bool "FOC current controller feedforward compensation" - default n - ---help--- - Enable support for current controller feed forward compensation - config INDUSTRY_FOC_MODEL_PMSM bool "FOC PMSM model support" select INDUSTRY_FOC_HAVE_MODEL @@ -155,12 +135,6 @@ config INDUSTRY_FOC_ALIGN if INDUSTRY_FOC_ALIGN -config INDUSTRY_FOC_ALIGN_DIR - bool "FOC alignment direction support" - default n - ---help--- - Enable support for sensor direction alignment - config INDUSTRY_FOC_ALIGN_INDEX bool "FOC alignment index search support" default n @@ -175,16 +149,6 @@ config INDUSTRY_FOC_IDENT ---help--- Enable support for motor identification routine (phase resistance and phase inductance) -if INDUSTRY_FOC_IDENT - -config INDUSTRY_FOC_IDENT_FLUX - bool "FOC flux linkage identification support" - default n - ---help--- - Enable support for flux linkage identification - -endif # INDUSTRY_FOC_IDENT - config INDUSTRY_FOC_VELOCITY_ODIV bool "FOC velocity DIV observer" default n diff --git a/industry/foc/Make.defs b/industry/foc/Make.defs index ed25e84f4..f5a84f083 100644 --- a/industry/foc/Make.defs +++ b/industry/foc/Make.defs @@ -1,7 +1,6 @@ ############################################################################ # apps/industry/foc/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 +# Adds selected applications to apps/ build # # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with @@ -20,6 +19,6 @@ # ############################################################################ -ifneq ($(CONFIG_INDUSTRY_FOC),) +ifeq ($(CONFIG_INDUSTRY_FOC),y) CONFIGURED_APPS += $(APPDIR)/industry/foc endif diff --git a/industry/foc/Makefile b/industry/foc/Makefile index 1c3375435..4923de19c 100644 --- a/industry/foc/Makefile +++ b/industry/foc/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/industry/foc/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -77,9 +75,6 @@ endif ifeq ($(CONFIG_INDUSTRY_FOC_VELOCITY_OPLL),y) CSRCS += float/foc_vel_opll.c endif -ifeq ($(CONFIG_INDUSTRY_FOC_FEEDFORWARD),y) -CSRCS += float/foc_feedforward.c -endif endif @@ -134,9 +129,6 @@ endif ifeq ($(CONFIG_INDUSTRY_FOC_VELOCITY_OPLL),y) CSRCS += fixed16/foc_vel_opll.c endif -ifeq ($(CONFIG_INDUSTRY_FOC_FEEDFORWARD),y) -CSRCS += fixed16/foc_feedforward.c -endif endif diff --git a/industry/foc/fixed16/foc_align.c b/industry/foc/fixed16/foc_align.c index d0ad6f8e7..0f0ecbee5 100644 --- a/industry/foc/fixed16/foc_align.c +++ b/industry/foc/fixed16/foc_align.c @@ -1,7 +1,6 @@ /**************************************************************************** * apps/industry/foc/fixed16/foc_align.c - * - * SPDX-License-Identifier: Apache-2.0 + * This file implements angle sensor alignment routine for fixed16 * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -76,9 +75,7 @@ enum foc_align_run_stage_e FOC_ALIGN_RUN_INDEX, #endif FOC_ALIGN_RUN_OFFSET, -#ifdef CONFIG_INDUSTRY_FOC_ALIGN_DIR FOC_ALIGN_RUN_DIR, -#endif FOC_ALIGN_RUN_IDLE, FOC_ALIGN_RUN_DONE }; @@ -350,7 +347,6 @@ errout: return ret; } -#ifdef CONFIG_INDUSTRY_FOC_ALIGN_DIR /**************************************************************************** * Name: foc_align_dir_move_b16 ****************************************************************************/ @@ -403,8 +399,6 @@ static void foc_align_dir_move_b16(FAR struct foc_align_b16_s *align, static void foc_align_dir_hold_b16(FAR struct foc_align_b16_s *align, b16_t dir, bool last, bool diff) { - b16_t tmp = 0; - DEBUGASSERT(align); /* Lock angle */ @@ -425,16 +419,13 @@ static void foc_align_dir_hold_b16(FAR struct foc_align_b16_s *align, if (diff == true) { - tmp = align->angle_now - align->angle_last; - angle_norm_2pi_b16(&tmp, -b16PI, b16PI); - if (dir == DIR_CW_B16) { - align->diff_cw += tmp; + align->diff_cw += (align->angle_now - align->angle_last); } else if (dir == DIR_CCW_B16) { - align->diff_ccw += tmp; + align->diff_ccw += (align->angle_now - align->angle_last); } else { @@ -672,7 +663,6 @@ errout: return ret; } -#endif /**************************************************************************** * Name: foc_align_idle_run_b16 @@ -920,7 +910,6 @@ int foc_routine_align_run_b16(FAR foc_routine_b16_t *r, break; } -#ifdef CONFIG_INDUSTRY_FOC_ALIGN_DIR case FOC_ALIGN_RUN_DIR: { /* Align direction procedure */ @@ -941,7 +930,6 @@ int foc_routine_align_run_b16(FAR foc_routine_b16_t *r, break; } -#endif case FOC_ALIGN_RUN_IDLE: { @@ -1011,12 +999,5 @@ int foc_routine_align_final_b16(FAR foc_routine_b16_t *r, FAR void *data) memcpy(data, &a->final, sizeof(struct foc_routine_aling_final_b16_s)); - /* Reset data but leave configuration */ - - memset(&a->final, - 0, - (sizeof(struct foc_align_b16_s) - - sizeof(struct foc_routine_align_cfg_b16_s))); - return OK; } diff --git a/industry/foc/fixed16/foc_ang_hall.c b/industry/foc/fixed16/foc_ang_hall.c index 0e2eae9bf..905e0f724 100644 --- a/industry/foc/fixed16/foc_ang_hall.c +++ b/industry/foc/fixed16/foc_ang_hall.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/industry/foc/fixed16/foc_ang_hall.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -32,7 +30,6 @@ #include #include #include -#include #include diff --git a/industry/foc/fixed16/foc_ang_onfo.c b/industry/foc/fixed16/foc_ang_onfo.c index 139684671..35fbe63f1 100644 --- a/industry/foc/fixed16/foc_ang_onfo.c +++ b/industry/foc/fixed16/foc_ang_onfo.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/industry/foc/fixed16/foc_ang_onfo.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -37,10 +35,16 @@ * Pre-processor Definitions ****************************************************************************/ +#define SIGN(x) ((x > 0) ? b16ONE : -b16ONE) + #define LINEAR_MAP(x, in_min, in_max, out_min, out_max) \ (b16divb16(b16mulb16((x - in_min), (out_max - out_min)), \ (in_max - in_min)) + out_min) +#ifndef ABS +# define ABS(a) (a < 0 ? -a : a) +#endif + /**************************************************************************** * Private Data Types ****************************************************************************/ @@ -281,15 +285,6 @@ static int foc_angle_onfo_run_b16(FAR foc_angle_b16_t *h, DEBUGASSERT(h->data); ob = h->data; - if (in->vel == 0) - { - /* Do nothing if motor stopped */ - - out->type = FOC_ANGLE_TYPE_ELE; - out->angle = 0; - return OK; - } - /* Normalize the d-q voltage to get the d-q modulation * voltage */ @@ -299,12 +294,12 @@ static int foc_angle_onfo_run_b16(FAR foc_angle_b16_t *h, /* Update duty cycle now */ - duty_now = b16mulb16(b16sign(in->state->vdq.q), + duty_now = b16mulb16(SIGN(in->state->vdq.q), vector2d_mag_b16(v_dq_mod.d, v_dq_mod.q)); /* Update and the observer gain. */ - dyn_gain = b16mulb16(LINEAR_MAP(b16abs(duty_now), + dyn_gain = b16mulb16(LINEAR_MAP(ABS(duty_now), 0, b16ONE, b16mulb16(ob->cfg.gain, ob->cfg.gain_slow), diff --git a/industry/foc/fixed16/foc_ang_openloop.c b/industry/foc/fixed16/foc_ang_openloop.c index 9cbb59466..d428c84e9 100644 --- a/industry/foc/fixed16/foc_ang_openloop.c +++ b/industry/foc/fixed16/foc_ang_openloop.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/industry/foc/fixed16/foc_ang_openloop.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -29,7 +27,6 @@ #include #include #include -#include #include "industry/foc/foc_log.h" #include "industry/foc/fixed16/foc_angle.h" @@ -260,11 +257,9 @@ static int foc_angle_ol_run_b16(FAR foc_angle_b16_t *h, DEBUGASSERT(h->data); ol = h->data; - /* Update open-loop. - * NOTE: we don't use dir argument here, instead we use signed velocity. - */ + /* Update open-loop */ - motor_openloop_b16(&ol->data, in->vel, 1); + motor_openloop_b16(&ol->data, in->vel, in->dir); tmp = motor_openloop_angle_get_b16(&ol->data); diff --git a/industry/foc/fixed16/foc_ang_osmo.c b/industry/foc/fixed16/foc_ang_osmo.c index 3a48beb6c..90acd2a86 100644 --- a/industry/foc/fixed16/foc_ang_osmo.c +++ b/industry/foc/fixed16/foc_ang_osmo.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/industry/foc/fixed16/foc_ang_osmo.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -270,15 +268,6 @@ static int foc_angle_osmo_run_b16(FAR foc_angle_b16_t *h, DEBUGASSERT(h->data); ob = h->data; - if (in->vel == 0) - { - /* Do nothing if motor stopped */ - - out->type = FOC_ANGLE_TYPE_ELE; - out->angle = 0; - return OK; - } - /* Update observer */ motor_aobserver_smo_b16(&ob->o, &in->state->iab, &in->state->vab, diff --git a/industry/foc/fixed16/foc_ang_qenco.c b/industry/foc/fixed16/foc_ang_qenco.c index bb53a8c42..af5b9074a 100644 --- a/industry/foc/fixed16/foc_ang_qenco.c +++ b/industry/foc/fixed16/foc_ang_qenco.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/industry/foc/fixed16/foc_ang_qenco.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -32,7 +30,6 @@ #include #include #include -#include #include diff --git a/industry/foc/fixed16/foc_angle.c b/industry/foc/fixed16/foc_angle.c index 0820d47d0..ee5ad8e03 100644 --- a/industry/foc/fixed16/foc_angle.c +++ b/industry/foc/fixed16/foc_angle.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/industry/foc/fixed16/foc_angle.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -28,7 +26,6 @@ #include #include -#include #include "industry/foc/foc_log.h" #include "industry/foc/fixed16/foc_angle.h" diff --git a/industry/foc/fixed16/foc_cordic.c b/industry/foc/fixed16/foc_cordic.c index 22af88a46..4c08e8212 100644 --- a/industry/foc/fixed16/foc_cordic.c +++ b/industry/foc/fixed16/foc_cordic.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/industry/foc/fixed16/foc_cordic.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -30,7 +28,7 @@ #include #include -#include +#include #include #include diff --git a/industry/foc/fixed16/foc_feedforward.c b/industry/foc/fixed16/foc_feedforward.c deleted file mode 100644 index 97c1b6699..000000000 --- a/industry/foc/fixed16/foc_feedforward.c +++ /dev/null @@ -1,70 +0,0 @@ -/**************************************************************************** - * apps/industry/foc/fixed16/foc_feedforward.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include - -#include "industry/foc/fixed16/foc_feedforward.h" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: foc_feedforward_pmsm_b16 - * - * Description: - * Feed forward compensation for PMSM (fixed16) - * - * Input Parameter: - * phy - motor physical parameters - * idq - iqd frame - * vel_now - electrical velocity - * vdq_comp - compensation vdq frame - * - ****************************************************************************/ - -int foc_feedforward_pmsm_b16(FAR struct motor_phy_params_b16_s *phy, - FAR dq_frame_b16_t *idq, - b16_t vel_now, - FAR dq_frame_b16_t *vdq_comp) -{ - DEBUGASSERT(phy); - DEBUGASSERT(idq); - DEBUGASSERT(vdq_comp); - - /* NOTE: vdq_comp is substracted from vdq_ref in foc_current_control() - * so vq compensation must be negative here. - */ - - vdq_comp->q = -b16mulb16(vel_now, - (phy->flux_link + b16mulb16(phy->ind, - idq->d))); - vdq_comp->d = b16mulb16(b16mulb16(vel_now, phy->ind), idq->q); - - return OK; -} diff --git a/industry/foc/fixed16/foc_handler.c b/industry/foc/fixed16/foc_handler.c index 12ef7aa5b..5cc95d23f 100644 --- a/industry/foc/fixed16/foc_handler.c +++ b/industry/foc/fixed16/foc_handler.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/industry/foc/fixed16/foc_handler.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -29,8 +27,6 @@ #include #include #include -#include -#include #include "industry/foc/foc_log.h" #include "industry/foc/foc_common.h" @@ -302,6 +298,7 @@ errout: /* Set duty to zeros */ memset(out->duty, 0, sizeof(b16_t) * CONFIG_MOTOR_FOC_PHASES); + return ret; } @@ -312,25 +309,18 @@ errout: * Get FOC handler state (fixed16) * * Input Parameter: - * h - pointer to FOC handler - * state - pointer to FOC state data - * mod_state - pointer to modulation state data (optional) + * h - pointer to FOC handler + * state - pointer to FOC state data * ****************************************************************************/ void foc_handler_state_b16(FAR foc_handler_b16_t *h, - FAR struct foc_state_b16_s *state, - FAR void *mod_state) + FAR struct foc_state_b16_s *state) { DEBUGASSERT(h); DEBUGASSERT(state); h->ops.ctrl->state_get(h, state); - - if (mod_state) - { - h->ops.mod->state_get(h, mod_state); - } } #ifdef CONFIG_INDUSTRY_FOC_HANDLER_PRINT diff --git a/industry/foc/fixed16/foc_ident.c b/industry/foc/fixed16/foc_ident.c index a7b2098a2..65dab3535 100644 --- a/industry/foc/fixed16/foc_ident.c +++ b/industry/foc/fixed16/foc_ident.c @@ -1,7 +1,6 @@ /**************************************************************************** * apps/industry/foc/fixed16/foc_ident.c - * - * SPDX-License-Identifier: Apache-2.0 + * This file implements motor ident routine for fixed16 * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -40,7 +39,7 @@ ****************************************************************************/ #define IDENT_PI_KP (ftob16(0.0f)) -#define B16UPPERLIMIT (0x7e000000) +#define IDENT_PI_KI (ftob16(0.05f)) /**************************************************************************** * Private Data Types @@ -68,17 +67,6 @@ struct foc_ident_b16_s pid_controller_b16_t pi; /* PI controller for res */ int cntr; /* Helper counter */ int stage; /* Ident stage */ - - /* global data in resistance identification */ - - b16_t curr_sum; - b16_t volt_sum; - - /* global data in inductance identification */ - - b16_t sign; - b16_t curr1_sum; - b16_t curr2_sum; }; /**************************************************************************** @@ -181,8 +169,7 @@ int foc_ident_res_run_b16(FAR struct foc_ident_b16_s *ident, if (ident->cntr == 0) { - DEBUGASSERT(ident->cfg.res_ki > 0); - pi_controller_init_b16(&ident->pi, IDENT_PI_KP, ident->cfg.res_ki); + pi_controller_init_b16(&ident->pi, IDENT_PI_KP, IDENT_PI_KI); } /* PI saturation */ @@ -206,30 +193,12 @@ int foc_ident_res_run_b16(FAR struct foc_ident_b16_s *ident, /* Increase counter */ ident->cntr += 1; - if (ident->cntr > (ident->cfg.res_steps / 3)) - { - ident->volt_sum += vector2d_mag_b16(in->foc_state->vdq.q, - in->foc_state->vdq.d); - ident->curr_sum += vector2d_mag_b16(in->foc_state->idq.q, - in->foc_state->idq.d); - } - - /* Overflow protection */ - - if (ident->volt_sum > B16UPPERLIMIT || ident->curr_sum > B16UPPERLIMIT) - { - ret = -EOVERFLOW; - goto errout; - } if (ident->cntr > ident->cfg.res_steps) { /* Get resistance */ - ident->final.res = b16divb16(b16mulb16( - ftob16(2.0f / 3.0f), - ident->volt_sum), - ident->curr_sum); + ident->final.res = b16divb16(vref, ident->cfg.res_current); /* Force IDLE state */ @@ -247,14 +216,8 @@ int foc_ident_res_run_b16(FAR struct foc_ident_b16_s *ident, /* Reset counter */ ident->cntr = 0; - - /* Reset static curr_sum and volt_sum */ - - ident->curr_sum = 0; - ident->volt_sum = 0; } -errout: return ret; } @@ -280,6 +243,9 @@ int foc_ident_ind_run_b16(FAR struct foc_ident_b16_s *ident, b16_t curr1_avg = 0; b16_t curr2_avg = 0; b16_t delta_curr = 0; + static b16_t sign = b16ONE; + static b16_t curr1_sum = 0; + static b16_t curr2_sum = 0; b16_t tmp1 = 0; b16_t tmp2 = 0; b16_t tmp3 = 0; @@ -288,31 +254,23 @@ int foc_ident_ind_run_b16(FAR struct foc_ident_b16_s *ident, * if previous sing was +1 then we have bottom current. */ - if (ident->sign > 0) + if (sign > 0) { /* Average bottm current */ - ident->curr1_sum += in->foc_state->idq.d; + curr1_sum += in->foc_state->idq.d; } else { /* Average top current */ - ident->curr2_sum += in->foc_state->idq.d; - } - - /* Overflow protection */ - - if (ident->curr1_sum > B16UPPERLIMIT || ident->curr2_sum > B16UPPERLIMIT) - { - ret = -EOVERFLOW; - goto errout; + curr2_sum += in->foc_state->idq.d; } /* Invert voltage to generate square wave D voltage */ - ident->sign = -ident->sign; - vref = b16mulb16(ident->sign, ident->cfg.ind_volt); + sign = -sign; + vref = b16mulb16(sign, ident->cfg.ind_volt); /* Force alpha voltage = vref */ @@ -331,11 +289,11 @@ int foc_ident_ind_run_b16(FAR struct foc_ident_b16_s *ident, { /* Half samples from curr1, other half from curr2 */ - tmp1 = b16muli(ident->curr1_sum, 2); - tmp2 = b16muli(ident->curr2_sum, 2); + tmp1 = b16muli(curr1_sum, 2); + tmp2 = b16muli(curr2_sum, 2); - curr1_avg = b16divi(tmp1, ident->cntr); - curr2_avg = b16divi(tmp2, ident->cntr); + curr1_avg = b16divb16(tmp1, ident->cntr); + curr2_avg = b16divb16(tmp2, ident->cntr); /* Average delta current */ @@ -372,12 +330,11 @@ int foc_ident_ind_run_b16(FAR struct foc_ident_b16_s *ident, /* Reset static data */ - ident->sign = b16ONE; - ident->curr1_sum = 0; - ident->curr2_sum = 0; + sign = b16ONE; + curr1_sum = 0; + curr2_sum = 0; } -errout: return ret; } @@ -394,7 +351,6 @@ errout: int foc_routine_ident_init_b16(FAR foc_routine_b16_t *r) { - FAR struct foc_ident_b16_s *i = NULL; int ret = OK; DEBUGASSERT(r); @@ -408,9 +364,6 @@ int foc_routine_ident_init_b16(FAR foc_routine_b16_t *r) goto errout; } - i = r->data; - i->sign = b16ONE; - errout: return ret; } @@ -474,12 +427,6 @@ int foc_routine_ident_cfg_b16(FAR foc_routine_b16_t *r, FAR void *cfg) goto errout; } - if (i->cfg.res_ki <= 0) - { - ret = -EINVAL; - goto errout; - } - if (i->cfg.res_current <= 0 || i->cfg.ind_volt <= 0) { ret = -EINVAL; @@ -613,7 +560,6 @@ int foc_routine_ident_run_b16(FAR foc_routine_b16_t *r, case FOC_IDENT_RUN_DONE: { ret = FOC_ROUTINE_RUN_DONE; - i->stage = FOC_IDENT_RUN_INIT; break; } diff --git a/industry/foc/fixed16/foc_model.c b/industry/foc/fixed16/foc_model.c index 6ed52f2b1..8540dee6a 100644 --- a/industry/foc/fixed16/foc_model.c +++ b/industry/foc/fixed16/foc_model.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/industry/foc/fixed16/foc_model.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -28,7 +26,6 @@ #include #include -#include #include "industry/foc/foc_log.h" #include "industry/foc/foc_common.h" diff --git a/industry/foc/fixed16/foc_model_pmsm.c b/industry/foc/fixed16/foc_model_pmsm.c index 0c4c80036..403093e99 100644 --- a/industry/foc/fixed16/foc_model_pmsm.c +++ b/industry/foc/fixed16/foc_model_pmsm.c @@ -1,7 +1,6 @@ /**************************************************************************** * apps/industry/foc/fixed16/foc_model_pmsm.c - * - * SPDX-License-Identifier: Apache-2.0 + * This file implements PMSM model for fixed16 * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with diff --git a/industry/foc/fixed16/foc_picontrol.c b/industry/foc/fixed16/foc_picontrol.c index 97d1c7f3d..66ee26524 100644 --- a/industry/foc/fixed16/foc_picontrol.c +++ b/industry/foc/fixed16/foc_picontrol.c @@ -1,7 +1,6 @@ /**************************************************************************** * apps/industry/foc/fixed16/foc_picontrol.c - * - * SPDX-License-Identifier: Apache-2.0 + * This file implements classical FOC PI current controller for fixed16 * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with diff --git a/industry/foc/fixed16/foc_ramp.c b/industry/foc/fixed16/foc_ramp.c index 282c051a0..237ebd3b8 100644 --- a/industry/foc/fixed16/foc_ramp.c +++ b/industry/foc/fixed16/foc_ramp.c @@ -1,7 +1,6 @@ /**************************************************************************** * apps/industry/foc/fixed16/foc_ramp.c - * - * SPDX-License-Identifier: Apache-2.0 + * This file implements ramp for fixed16 * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -86,8 +85,6 @@ int foc_ramp_init_b16(FAR struct foc_ramp_b16_s *ramp, b16_t per, int foc_ramp_run_b16(FAR struct foc_ramp_b16_s *ramp, b16_t des, b16_t now, FAR b16_t *set) { - b16_t sign = b16ONE; - DEBUGASSERT(ramp); /* Check if we require soft start/stop operation. @@ -98,42 +95,14 @@ int foc_ramp_run_b16(FAR struct foc_ramp_b16_s *ramp, b16_t des, { ramp->diff = des - *set; - /* If we change direction then the first vel target is 0 */ - - if (des * (*set) < 0) + if (ramp->diff >= ramp->ramp_thr) { - ramp->diff = -now; - des = 0; - } - - if (now >= 0 && ramp->diff >= ramp->ramp_thr) - { - /* Soft start in CW direction */ - - sign = b16ONE; ramp->ramp_mode = RAMP_MODE_SOFTSTART; } - else if (now >= 0 && ramp->diff <= -ramp->ramp_thr) + else if (ramp->diff <= -ramp->ramp_thr) { - /* Soft stop in CW direction */ - - sign = -b16ONE; ramp->ramp_mode = RAMP_MODE_SOFTSTOP; } - else if (now < 0 && ramp->diff >= ramp->ramp_thr) - { - /* Soft stop in CCW direction */ - - sign = b16ONE; - ramp->ramp_mode = RAMP_MODE_SOFTSTOP; - } - else if (now < 0 && ramp->diff <= -ramp->ramp_thr) - { - /* Soft start in CCW direction */ - - sign = -b16ONE; - ramp->ramp_mode = RAMP_MODE_SOFTSTART; - } else { /* Just set new setpoint */ @@ -160,18 +129,38 @@ int foc_ramp_run_b16(FAR struct foc_ramp_b16_s *ramp, b16_t des, case RAMP_MODE_SOFTSTART: { - /* Increase setpoint with ramp */ + if (des - *set >= ramp->ramp_thr) + { + /* Increase setpoint with ramp */ - *set = now + b16mulb16(sign, ramp->ramp_acc_per); + *set = now + ramp->ramp_acc_per; + } + else + { + /* Set final setpoint and exit soft start */ + + *set = des; + ramp->ramp_mode = RAMP_MODE_NORMAL; + } break; } case RAMP_MODE_SOFTSTOP: { - /* Stop motor with ramp */ + if (des - *set <= -ramp->ramp_thr) + { + /* Stop motor with ramp */ - *set = now + b16mulb16(sign, ramp->ramp_dec_per); + *set = now - ramp->ramp_dec_per; + } + else + { + /* Set final setpoint and exit soft stop */ + + *set = des; + ramp->ramp_mode = RAMP_MODE_NORMAL; + } break; } diff --git a/industry/foc/fixed16/foc_routine.c b/industry/foc/fixed16/foc_routine.c index faa57fb69..bba1e614e 100644 --- a/industry/foc/fixed16/foc_routine.c +++ b/industry/foc/fixed16/foc_routine.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/industry/foc/fixed16/foc_routine.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -28,7 +26,6 @@ #include #include -#include #include "industry/foc/foc_log.h" #include "industry/foc/fixed16/foc_routine.h" diff --git a/industry/foc/fixed16/foc_svm3.c b/industry/foc/fixed16/foc_svm3.c index 1521b30a8..bfc3ab072 100644 --- a/industry/foc/fixed16/foc_svm3.c +++ b/industry/foc/fixed16/foc_svm3.c @@ -1,7 +1,6 @@ /**************************************************************************** * apps/industry/foc/fixed16/foc_svm3.c - * - * SPDX-License-Identifier: Apache-2.0 + * This file implements 3-phase space vector modulation for fixed16 * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -74,8 +73,6 @@ static void foc_modulation_vbase_get_b16(FAR foc_handler_b16_t *h, static void foc_modulation_run_b16(FAR foc_handler_b16_t *h, FAR ab_frame_b16_t *v_ab_mod, FAR b16_t *duty); -static void foc_modulation_state_b16(FAR foc_handler_b16_t *h, - FAR void *v_priv); /**************************************************************************** * Public Data @@ -91,7 +88,6 @@ struct foc_modulation_ops_b16_s g_foc_mod_svm3_b16 = .current = foc_modulation_current_b16, .vbase_get = foc_modulation_vbase_get_b16, .run = foc_modulation_run_b16, - .state_get = foc_modulation_state_b16, }; /**************************************************************************** @@ -124,7 +120,7 @@ static int foc_modulation_init_b16(FAR foc_handler_b16_t *h) goto errout; } -errout: + errout: return ret; } @@ -247,7 +243,7 @@ static void foc_modulation_current_b16(FAR foc_handler_b16_t *h, } /**************************************************************************** - * Name: foc_modulation_run_b16 + * Name: foc_modulation_b16 * * Description: * Handle the SVM3 modulation (fixed16) @@ -290,33 +286,3 @@ static void foc_modulation_run_b16(FAR foc_handler_b16_t *h, f_saturate_b16(&duty[1], 0, svm->cfg.pwm_duty_max); f_saturate_b16(&duty[2], 0, svm->cfg.pwm_duty_max); } - -/**************************************************************************** - * Name: foc_modulation_state_b16 - * - * Description: - * Get the SVM3 modulation state (fixed16) - * - * Input Parameter: - * h - pointer to FOC handler - * state - pointer to modulation specific data - * - ****************************************************************************/ - -static void foc_modulation_state_b16(FAR foc_handler_b16_t *h, - FAR void *state) -{ - FAR struct foc_svm3mod_b16_s *svm = NULL; - - DEBUGASSERT(h); - DEBUGASSERT(state); - - /* Get modulation data */ - - DEBUGASSERT(h->modulation); - svm = h->modulation; - - /* Copy data */ - - memcpy(state, &svm->state, sizeof(struct svm3_state_b16_s)); -} diff --git a/industry/foc/fixed16/foc_vel_odiv.c b/industry/foc/fixed16/foc_vel_odiv.c index 4cdf13d55..5df851893 100644 --- a/industry/foc/fixed16/foc_vel_odiv.c +++ b/industry/foc/fixed16/foc_vel_odiv.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/industry/foc/fixed16/foc_vel_odiv.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -216,8 +214,6 @@ static int foc_velocity_div_zero_b16(FAR foc_velocity_b16_t *h) div->cfg.filter, div->cfg.per); - div->o.speed = 0; - return ret; } diff --git a/industry/foc/fixed16/foc_vel_opll.c b/industry/foc/fixed16/foc_vel_opll.c index eecbe40d8..b16cbee1d 100644 --- a/industry/foc/fixed16/foc_vel_opll.c +++ b/industry/foc/fixed16/foc_vel_opll.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/industry/foc/fixed16/foc_vel_opll.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -214,8 +212,6 @@ static int foc_velocity_pll_zero_b16(FAR foc_velocity_b16_t *h) pll->cfg.kp, pll->cfg.ki); - pll->o.speed = 0; - return ret; } diff --git a/industry/foc/fixed16/foc_velocity.c b/industry/foc/fixed16/foc_velocity.c index c6f4af8a2..59b0679ba 100644 --- a/industry/foc/fixed16/foc_velocity.c +++ b/industry/foc/fixed16/foc_velocity.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/industry/foc/fixed16/foc_velocity.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -28,7 +26,6 @@ #include #include -#include #include "industry/foc/foc_log.h" #include "industry/foc/fixed16/foc_velocity.h" diff --git a/industry/foc/float/foc_align.c b/industry/foc/float/foc_align.c index 957e0083f..a7ff85aec 100644 --- a/industry/foc/float/foc_align.c +++ b/industry/foc/float/foc_align.c @@ -1,7 +1,6 @@ /**************************************************************************** * apps/industry/foc/float/foc_align.c - * - * SPDX-License-Identifier: Apache-2.0 + * This file implements angle sensor alignment routine for float32 * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -76,10 +75,8 @@ enum foc_align_run_stage_e FOC_ALIGN_RUN_INDEX, #endif FOC_ALIGN_RUN_OFFSET, -#ifdef CONFIG_INDUSTRY_FOC_ALIGN_DIR FOC_ALIGN_RUN_DIR, FOC_ALIGN_RUN_IDLE, -#endif FOC_ALIGN_RUN_DONE }; @@ -350,7 +347,6 @@ errout: return ret; } -#ifdef CONFIG_INDUSTRY_FOC_ALIGN_DIR /**************************************************************************** * Name: foc_align_dir_move_f32 ****************************************************************************/ @@ -403,8 +399,6 @@ static void foc_align_dir_move_f32(FAR struct foc_align_f32_s *align, static void foc_align_dir_hold_f32(FAR struct foc_align_f32_s *align, float dir, bool last, bool diff) { - float tmp = 0.0f; - DEBUGASSERT(align); /* Lock angle */ @@ -425,16 +419,13 @@ static void foc_align_dir_hold_f32(FAR struct foc_align_f32_s *align, if (diff == true) { - tmp = align->angle_now - align->angle_last; - angle_norm_2pi(&tmp, -M_PI_F, M_PI_F); - if (dir == DIR_CW) { - align->diff_cw += tmp; + align->diff_cw += (align->angle_now - align->angle_last); } else if (dir == DIR_CCW) { - align->diff_ccw += tmp; + align->diff_ccw += (align->angle_now - align->angle_last); } else { @@ -718,7 +709,6 @@ static int foc_align_idle_run_f32(FAR struct foc_align_f32_s *align, return ret; } -#endif /**************************************************************************** * Name: foc_routine_align_init_f32 @@ -920,7 +910,6 @@ int foc_routine_align_run_f32(FAR foc_routine_f32_t *r, break; } -#ifdef CONFIG_INDUSTRY_FOC_ALIGN_DIR case FOC_ALIGN_RUN_DIR: { /* Align direction procedure */ @@ -962,7 +951,6 @@ int foc_routine_align_run_f32(FAR foc_routine_f32_t *r, break; } -#endif case FOC_ALIGN_RUN_DONE: { @@ -1011,12 +999,5 @@ int foc_routine_align_final_f32(FAR foc_routine_f32_t *r, FAR void *data) memcpy(data, &a->final, sizeof(struct foc_routine_aling_final_f32_s)); - /* Reset data but leave configuration */ - - memset(&a->final, - 0, - (sizeof(struct foc_align_f32_s) - - sizeof(struct foc_routine_align_cfg_f32_s))); - return OK; } diff --git a/industry/foc/float/foc_ang_hall.c b/industry/foc/float/foc_ang_hall.c index 130a77f95..f3c0e7366 100644 --- a/industry/foc/float/foc_ang_hall.c +++ b/industry/foc/float/foc_ang_hall.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/industry/foc/float/foc_ang_hall.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -32,7 +30,6 @@ #include #include #include -#include #include diff --git a/industry/foc/float/foc_ang_onfo.c b/industry/foc/float/foc_ang_onfo.c index c00c826f6..2acb6ce9c 100644 --- a/industry/foc/float/foc_ang_onfo.c +++ b/industry/foc/float/foc_ang_onfo.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/industry/foc/float/foc_ang_onfo.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -37,7 +35,7 @@ * Pre-processor Definitions ****************************************************************************/ -#define SIGN(x) ((x > 0.0f) ? 1.0f : -1.0f) +#define SIGN(x) ((x > 0.0f) ? 1.0f : -1.0f) #define LINEAR_MAP(x, in_min, in_max, out_min, out_max) \ ((x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min) @@ -282,16 +280,9 @@ static int foc_angle_onfo_run_f32(FAR foc_angle_f32_t *h, DEBUGASSERT(h->data); ob = h->data; - if (in->vel == 0.0f) - { - /* Do nothing if motor stopped */ - - out->type = FOC_ANGLE_TYPE_ELE; - out->angle = 0.0f; - return OK; - } - - /* Normalize the d-q voltage to get the d-q modulation voltage */ + /* Normalize the d-q voltage to get the d-q modulation + * voltage + */ v_dq_mod.d = in->state->vdq.d * in->state->mod_scale; v_dq_mod.q = in->state->vdq.q * in->state->mod_scale; @@ -302,8 +293,8 @@ static int foc_angle_onfo_run_f32(FAR foc_angle_f32_t *h, /* Update and the observer gain. */ - dyn_gain = LINEAR_MAP(fabsf(duty_now), 0.0f, 1.0f, - ob->cfg.gain * ob->cfg.gain_slow, ob->cfg.gain) * 0.5f; + dyn_gain = LINEAR_MAP(fabsf(duty_now), 0.0, 1.0, + ob->cfg.gain * ob->cfg.gain_slow, ob->cfg.gain) * 0.5; /* Update observer */ diff --git a/industry/foc/float/foc_ang_openloop.c b/industry/foc/float/foc_ang_openloop.c index a8815319c..fe75dbf9a 100644 --- a/industry/foc/float/foc_ang_openloop.c +++ b/industry/foc/float/foc_ang_openloop.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/industry/foc/float/foc_ang_openloop.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -29,7 +27,6 @@ #include #include #include -#include #include "industry/foc/foc_log.h" #include "industry/foc/float/foc_angle.h" @@ -261,11 +258,9 @@ static int foc_angle_ol_run_f32(FAR foc_angle_f32_t *h, DEBUGASSERT(h->data); ol = h->data; - /* Update open-loop. - * NOTE: we don't use dir argument here, instead we use signed velocity. - */ + /* Update open-loop */ - motor_openloop(&ol->data, in->vel, 1.0f); + motor_openloop(&ol->data, in->vel, in->dir); /* Get open-loop angle */ diff --git a/industry/foc/float/foc_ang_osmo.c b/industry/foc/float/foc_ang_osmo.c index e509c12e9..ce693f3b7 100644 --- a/industry/foc/float/foc_ang_osmo.c +++ b/industry/foc/float/foc_ang_osmo.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/industry/foc/float/foc_ang_osmo.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -270,15 +268,6 @@ static int foc_angle_osmo_run_f32(FAR foc_angle_f32_t *h, DEBUGASSERT(h->data); ob = h->data; - if (in->vel == 0.0f) - { - /* Do nothing if motor stopped */ - - out->type = FOC_ANGLE_TYPE_ELE; - out->angle = 0.0f; - return OK; - } - /* Update observer */ motor_aobserver_smo(&ob->o, &in->state->iab, &in->state->vab, diff --git a/industry/foc/float/foc_ang_qenco.c b/industry/foc/float/foc_ang_qenco.c index 44395dfd2..aaa36f5a8 100644 --- a/industry/foc/float/foc_ang_qenco.c +++ b/industry/foc/float/foc_ang_qenco.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/industry/foc/float/foc_ang_qenco.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -32,7 +30,6 @@ #include #include #include -#include #include diff --git a/industry/foc/float/foc_angle.c b/industry/foc/float/foc_angle.c index 78bde639a..bbc0bd643 100644 --- a/industry/foc/float/foc_angle.c +++ b/industry/foc/float/foc_angle.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/industry/foc/float/foc_angle.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -28,7 +26,6 @@ #include #include -#include #include "industry/foc/foc_log.h" #include "industry/foc/float/foc_angle.h" diff --git a/industry/foc/float/foc_cordic.c b/industry/foc/float/foc_cordic.c index d4fe510ff..d66e6bc7b 100644 --- a/industry/foc/float/foc_cordic.c +++ b/industry/foc/float/foc_cordic.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/industry/foc/float/foc_cordic.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -30,7 +28,7 @@ #include #include -#include +#include #include #include diff --git a/industry/foc/float/foc_feedforward.c b/industry/foc/float/foc_feedforward.c deleted file mode 100644 index f9d3c3324..000000000 --- a/industry/foc/float/foc_feedforward.c +++ /dev/null @@ -1,68 +0,0 @@ -/**************************************************************************** - * apps/industry/foc/float/foc_feedforward.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include - -#include "industry/foc/float/foc_feedforward.h" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: foc_feedforward_pmsm_f32 - * - * Description: - * Feed forward compensation for PMSM (float32) - * - * Input Parameter: - * phy - motor physical parameters - * idq - iqd frame - * vel_now - electrical velocity - * vdq_comp - compensation vdq frame - * - ****************************************************************************/ - -int foc_feedforward_pmsm_f32(FAR struct motor_phy_params_f32_s *phy, - FAR dq_frame_f32_t *idq, - float vel_now, - FAR dq_frame_f32_t *vdq_comp) -{ - DEBUGASSERT(phy); - DEBUGASSERT(idq); - DEBUGASSERT(vdq_comp); - - /* NOTE: vdq_comp is substracted from vdq_ref in foc_current_control() - * so vq compensation must be negative here. - */ - - vdq_comp->q = -vel_now * (phy->flux_link + phy->ind * idq->d); - vdq_comp->d = vel_now * phy->ind * idq->q; - - return OK; -} diff --git a/industry/foc/float/foc_handler.c b/industry/foc/float/foc_handler.c index c44969439..e436e5ece 100644 --- a/industry/foc/float/foc_handler.c +++ b/industry/foc/float/foc_handler.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/industry/foc/float/foc_handler.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -29,8 +27,6 @@ #include #include #include -#include -#include #include "industry/foc/foc_log.h" #include "industry/foc/foc_common.h" @@ -302,6 +298,7 @@ errout: /* Set duty to zeros */ memset(out->duty, 0, sizeof(float) * CONFIG_MOTOR_FOC_PHASES); + return ret; } @@ -312,25 +309,18 @@ errout: * Get FOC handler state (float32) * * Input Parameter: - * h - pointer to FOC handler - * state - pointer to FOC state data - * mod_state - pointer to modulation state data (optional) + * h - pointer to FOC handler + * state - pointer to FOC state data * ****************************************************************************/ void foc_handler_state_f32(FAR foc_handler_f32_t *h, - FAR struct foc_state_f32_s *state, - FAR void *mod_state) + FAR struct foc_state_f32_s *state) { DEBUGASSERT(h); DEBUGASSERT(state); h->ops.ctrl->state_get(h, state); - - if (mod_state) - { - h->ops.mod->state_get(h, mod_state); - } } #ifdef CONFIG_INDUSTRY_FOC_HANDLER_PRINT diff --git a/industry/foc/float/foc_ident.c b/industry/foc/float/foc_ident.c index 3713e8d44..f0a61170c 100644 --- a/industry/foc/float/foc_ident.c +++ b/industry/foc/float/foc_ident.c @@ -1,7 +1,6 @@ /**************************************************************************** * apps/industry/foc/float/foc_ident.c - * - * SPDX-License-Identifier: Apache-2.0 + * This file implements motor ident routine for float32 * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -40,6 +39,7 @@ ****************************************************************************/ #define IDENT_PI_KP (0.0f) +#define IDENT_PI_KI (0.05f) /**************************************************************************** * Private Data Types @@ -55,10 +55,6 @@ enum foc_ident_run_stage_e FOC_IDENT_RUN_IDLE2, FOC_IDENT_RUN_IND, FOC_IDENT_RUN_IDLE3, -#ifdef CONFIG_INDUSTRY_FOC_IDENT_FLUX - FOC_IDENT_RUN_FLU, - FOC_IDENT_RUN_IDLE4, -#endif FOC_IDENT_RUN_DONE }; @@ -71,28 +67,6 @@ struct foc_ident_f32_s pid_controller_f32_t pi; /* PI controller for res */ int cntr; /* Helper counter */ int stage; /* Ident stage */ - - /* global data in resistance identification */ - - float curr_sum; - float volt_sum; - - /* global data in inductance identification */ - - float sign; - float curr1_sum; - float curr2_sum; - -#ifdef CONFIG_INDUSTRY_FOC_IDENT_FLUX - /* global data in flux linkage identification */ - - float vq_sum; - float vd_sum; - float iq_sum; - float id_sum; - float vel; - int aveg_sum; -#endif }; /**************************************************************************** @@ -195,8 +169,7 @@ int foc_ident_res_run_f32(FAR struct foc_ident_f32_s *ident, if (ident->cntr == 0) { - DEBUGASSERT(ident->cfg.res_ki > 0.0f); - pi_controller_init(&ident->pi, IDENT_PI_KP, ident->cfg.res_ki); + pi_controller_init(&ident->pi, IDENT_PI_KP, IDENT_PI_KI); } /* PI saturation */ @@ -220,19 +193,12 @@ int foc_ident_res_run_f32(FAR struct foc_ident_f32_s *ident, /* Increase counter */ ident->cntr += 1; - if (ident->cntr > (ident->cfg.res_steps / 3)) - { - ident->volt_sum += vector2d_mag(in->foc_state->vdq.q, - in->foc_state->vdq.d); - ident->curr_sum += vector2d_mag(in->foc_state->idq.q, - in->foc_state->idq.d); - } if (ident->cntr > ident->cfg.res_steps) { /* Get resistance */ - ident->final.res = (2.0f / 3.0f) * ident->volt_sum / ident->curr_sum; + ident->final.res = vref / ident->cfg.res_current; /* Force IDLE state */ @@ -250,11 +216,6 @@ int foc_ident_res_run_f32(FAR struct foc_ident_f32_s *ident, /* Reset counter */ ident->cntr = 0; - - /* Reset static curr_sum and volt_sum */ - - ident->curr_sum = 0.0f; - ident->volt_sum = 0.0f; } return ret; @@ -282,28 +243,31 @@ int foc_ident_ind_run_f32(FAR struct foc_ident_f32_s *ident, float curr1_avg = 0.0f; float curr2_avg = 0.0f; float delta_curr = 0.0f; + static float sign = 1.0f; + static float curr1_sum = 0.0f; + static float curr2_sum = 0.0f; /* If previous sign was -1 then we have top current, * if previous sing was +1 then we have bottom current. */ - if (ident->sign > 0) + if (sign > 0) { /* Average bottm current */ - ident->curr1_sum += in->foc_state->idq.d; + curr1_sum += in->foc_state->idq.d; } else { /* Average top current */ - ident->curr2_sum += in->foc_state->idq.d; + curr2_sum += in->foc_state->idq.d; } /* Invert voltage to generate square wave D voltage */ - ident->sign = -ident->sign; - vref = ident->sign * ident->cfg.ind_volt; + sign = -sign; + vref = sign * ident->cfg.ind_volt; /* Force alpha voltage = vref */ @@ -322,8 +286,8 @@ int foc_ident_ind_run_f32(FAR struct foc_ident_f32_s *ident, { /* Half samples from curr1, other half from curr2 */ - curr1_avg = 2 * ident->curr1_sum / ident->cntr; - curr2_avg = 2 * ident->curr2_sum / ident->cntr; + curr1_avg = 2 * curr1_sum / ident->cntr; + curr2_avg = 2 * curr2_sum / ident->cntr; /* Average delta current */ @@ -357,134 +321,16 @@ int foc_ident_ind_run_f32(FAR struct foc_ident_f32_s *ident, ident->cntr = 0; - /* Reset curr1_sum curr2_sum and sign */ + /* Reset static data */ - ident->sign = 1.0f; - ident->curr1_sum = 0.0f; - ident->curr2_sum = 0.0f; + sign = 1.0f; + curr1_sum = 0.0f; + curr2_sum = 0.0f; } return ret; } -#ifdef CONFIG_INDUSTRY_FOC_IDENT_FLUX -/**************************************************************************** - * Name: foc_ident_fluxlink_run_f32 - * - * Description: - * Run flux linkage identification routine - * - * Input Parameter: - * ident - pointer to FOC ident routine - * in - pointer to FOC routine input data - * out - pointer to FOC routine output data - * - ****************************************************************************/ - -int foc_ident_fluxlink_run_f32(FAR struct foc_ident_f32_s *ident, - FAR struct foc_routine_in_f32_s *in, - FAR struct foc_routine_out_f32_s *out) -{ - int ret = FOC_ROUTINE_RUN_NOTDONE; - float curr_avg = 0.0f; - float volt_avg = 0.0f; - - DEBUGASSERT(ident->cfg.cb.zero != NULL); - DEBUGASSERT(ident->cfg.cb.angle != NULL); - DEBUGASSERT(ident->cfg.cb.speed != NULL); - - if (ident->cfg.cb.angle != NULL) - { - /* Update openloop angle by angle callbacks */ - - out->angle = ident->cfg.cb.angle(ident->cfg.cb.priv_angle, - ident->vel, DIR_CW); - } - - if (ident->cfg.cb.speed != NULL) - { - /* Update openloop speed by speed callbacks */ - - ident->vel = ident->cfg.cb.speed(ident->cfg.cb.priv_speed, - ident->cfg.flux_vel, ident->vel); - } - - /* Force q axis current = ident->cfg.flux_curr */ - - out->dq_ref.q = ident->cfg.flux_curr; - out->dq_ref.d = 0.0f; - out->vdq_comp.q = 0.0f; - out->vdq_comp.d = 0.0f; - out->foc_mode = FOC_HANDLER_MODE_CURRENT; - - /* Increase counter */ - - ident->cntr += 1; - if (ident->vel >= ident->cfg.flux_vel) - { - ident->vq_sum += in->foc_state->vdq.q; - ident->vd_sum += in->foc_state->vdq.d; - ident->iq_sum += in->foc_state->idq.q; - ident->id_sum += in->foc_state->idq.d; - ident->aveg_sum++; - } - - if (ident->cntr > ident->cfg.flux_steps) - { - volt_avg = vector2d_mag(ident->vq_sum / ident->aveg_sum, - ident->vd_sum / ident->aveg_sum); - curr_avg = vector2d_mag(ident->iq_sum / ident->aveg_sum, - ident->id_sum / ident->aveg_sum); - - /* Get flux linkage */ - - ident->final.flux = (volt_avg - ident->final.res * curr_avg) / - ident->vel - ident->final.ind * curr_avg; - - /* Force IDLE state */ - - out->dq_ref.q = 0.0f; - out->dq_ref.d = 0.0f; - out->vdq_comp.q = 0.0f; - out->vdq_comp.d = 0.0f; - out->angle = 0.0f; - out->foc_mode = FOC_HANDLER_MODE_IDLE; - - /* Reset global value of open loop angle */ - - if (ident->cfg.cb.zero != NULL) - { - ret = ident->cfg.cb.zero(ident->cfg.cb.priv_angle); - if (ret < 0) - { - FOCLIBERR("ERROR: ident zero callback failed %d!\n", ret); - goto errout; - } - } - - /* Flux linkage identification done */ - - ret = FOC_ROUTINE_RUN_DONE; - - /* Reset counter */ - - ident->cntr = 0; - - /* Reset global data */ - - ident->vq_sum = 0.0f; - ident->vd_sum = 0.0f; - ident->iq_sum = 0.0f; - ident->id_sum = 0.0f; - ident->vel = 0.0f; - ident->aveg_sum = 0; - } - -errout: - return ret; -} -#endif - /**************************************************************************** * Name: foc_routine_ident_init_f32 * @@ -498,7 +344,6 @@ errout: int foc_routine_ident_init_f32(FAR foc_routine_f32_t *r) { - FAR struct foc_ident_f32_s *i = NULL; int ret = OK; DEBUGASSERT(r); @@ -512,9 +357,6 @@ int foc_routine_ident_init_f32(FAR foc_routine_f32_t *r) goto errout; } - i = r->data; - i->sign = 1.0f; - errout: return ret; } @@ -578,26 +420,13 @@ int foc_routine_ident_cfg_f32(FAR foc_routine_f32_t *r, FAR void *cfg) goto errout; } - if (i->cfg.res_ki <= 0.0f) - { - ret = -EINVAL; - goto errout; - } - - if (i->cfg.res_current <= 0.0f || i->cfg.ind_volt <= 0.0f -#ifdef CONFIG_INDUSTRY_FOC_IDENT_FLUX - || i->cfg.flux_curr <= 0.0f -#endif - ) + if (i->cfg.res_current <= 0.0f || i->cfg.ind_volt <= 0.0f) { ret = -EINVAL; goto errout; } if (i->cfg.res_steps <= 0 || i->cfg.ind_steps <= 0 || -#ifdef CONFIG_INDUSTRY_FOC_IDENT_FLUX - i->cfg.flux_steps <= 0 || -#endif i->cfg.idle_steps <= 0) { ret = -EINVAL; @@ -636,9 +465,6 @@ int foc_routine_ident_run_f32(FAR foc_routine_f32_t *r, DEBUGASSERT(r->data); i = r->data; -#ifdef CONFIG_INDUSTRY_FOC_IDENT_FLUX - DEBUGASSERT(i->cfg.cb.kpki != NULL); -#endif /* Force IDLE state at default */ @@ -661,23 +487,9 @@ int foc_routine_ident_run_f32(FAR foc_routine_f32_t *r, break; } - case FOC_IDENT_RUN_IDLE3: -#ifdef CONFIG_INDUSTRY_FOC_IDENT_FLUX - if (i->cntr == 0) - { - ret = i->cfg.cb.kpki(i->cfg.cb.priv_kpki, i->final.res, - i->final.ind, i->cfg.per); - if (ret < 0) - { - FOCLIBERR("ERROR: ident kpki callback failed %d!\n", ret); - goto errout; - } - } - - case FOC_IDENT_RUN_IDLE4: -#endif case FOC_IDENT_RUN_IDLE1: case FOC_IDENT_RUN_IDLE2: + case FOC_IDENT_RUN_IDLE3: { /* De-energetize motor */ @@ -738,33 +550,9 @@ int foc_routine_ident_run_f32(FAR foc_routine_f32_t *r, break; } -#ifdef CONFIG_INDUSTRY_FOC_IDENT_FLUX - case FOC_IDENT_RUN_FLU: - { - /* Flux linkage */ - - ret = foc_ident_fluxlink_run_f32(i, in, out); - if (ret < 0) - { - goto errout; - } - - if (ret == FOC_ROUTINE_RUN_DONE) - { - FOCLIBLOG("IDENT FLU done!\n"); - - i->stage += 1; - ret = FOC_ROUTINE_RUN_NOTDONE; - } - - break; - } - -#endif case FOC_IDENT_RUN_DONE: { ret = FOC_ROUTINE_RUN_DONE; - i->stage = FOC_IDENT_RUN_INIT; break; } diff --git a/industry/foc/float/foc_model.c b/industry/foc/float/foc_model.c index 3587b9699..d46e0b474 100644 --- a/industry/foc/float/foc_model.c +++ b/industry/foc/float/foc_model.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/industry/foc/float/foc_model.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -28,7 +26,6 @@ #include #include -#include #include "industry/foc/foc_log.h" #include "industry/foc/foc_common.h" diff --git a/industry/foc/float/foc_model_pmsm.c b/industry/foc/float/foc_model_pmsm.c index a4eee5377..072180da5 100644 --- a/industry/foc/float/foc_model_pmsm.c +++ b/industry/foc/float/foc_model_pmsm.c @@ -1,7 +1,6 @@ /**************************************************************************** * apps/industry/foc/float/foc_model_pmsm.c - * - * SPDX-License-Identifier: Apache-2.0 + * This file implements PMSM model for fixed16 * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with diff --git a/industry/foc/float/foc_picontrol.c b/industry/foc/float/foc_picontrol.c index ee7964654..b99a8e741 100644 --- a/industry/foc/float/foc_picontrol.c +++ b/industry/foc/float/foc_picontrol.c @@ -1,7 +1,6 @@ /**************************************************************************** * apps/industry/foc/float/foc_picontrol.c - * - * SPDX-License-Identifier: Apache-2.0 + * This file implements classical FOC PI current controller for float32 * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with diff --git a/industry/foc/float/foc_ramp.c b/industry/foc/float/foc_ramp.c index e65d06963..566ee1144 100644 --- a/industry/foc/float/foc_ramp.c +++ b/industry/foc/float/foc_ramp.c @@ -1,7 +1,6 @@ /**************************************************************************** * apps/industry/foc/float/foc_ramp.c - * - * SPDX-License-Identifier: Apache-2.0 + * This file implements ramp for float32 * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -86,8 +85,6 @@ int foc_ramp_init_f32(FAR struct foc_ramp_f32_s *ramp, float per, int foc_ramp_run_f32(FAR struct foc_ramp_f32_s *ramp, float des, float now, FAR float *set) { - float sign = 1.0f; - DEBUGASSERT(ramp); /* Check if we require soft start/stop operation. @@ -98,42 +95,14 @@ int foc_ramp_run_f32(FAR struct foc_ramp_f32_s *ramp, float des, { ramp->diff = des - *set; - /* If we change direction then the first vel target is 0 */ - - if (des * (*set) < 0.0f) + if (ramp->diff >= ramp->ramp_thr) { - ramp->diff = -now; - des = 0.0f; - } - - if (now >= 0.0f && ramp->diff >= ramp->ramp_thr) - { - /* Soft start in CW direction */ - - sign = 1.0f; ramp->ramp_mode = RAMP_MODE_SOFTSTART; } - else if (now >= 0.0f && ramp->diff <= -ramp->ramp_thr) + else if (ramp->diff <= -ramp->ramp_thr) { - /* Soft stop in CW direction */ - - sign = -1.0f; ramp->ramp_mode = RAMP_MODE_SOFTSTOP; } - else if (now < 0.0f && ramp->diff >= ramp->ramp_thr) - { - /* Soft stop in CCW direction */ - - sign = 1.0f; - ramp->ramp_mode = RAMP_MODE_SOFTSTOP; - } - else if (now < 0.0f && ramp->diff <= -ramp->ramp_thr) - { - /* Soft start in CCW direction */ - - sign = -1.0f; - ramp->ramp_mode = RAMP_MODE_SOFTSTART; - } else { /* Just set new setpoint */ @@ -160,18 +129,38 @@ int foc_ramp_run_f32(FAR struct foc_ramp_f32_s *ramp, float des, case RAMP_MODE_SOFTSTART: { - /* Increase setpoin with ramp */ + if (des - *set >= ramp->ramp_thr) + { + /* Increase setpoin with ramp */ - *set = now + sign * ramp->ramp_acc_per; + *set = now + ramp->ramp_acc_per; + } + else + { + /* Set final setpoint and exit soft start */ + + *set = des; + ramp->ramp_mode = RAMP_MODE_NORMAL; + } break; } case RAMP_MODE_SOFTSTOP: { - /* Stop motor with ramp */ + if (des - *set <= -ramp->ramp_thr) + { + /* Stop motor with ramp */ - *set = now + sign * ramp->ramp_dec_per; + *set = now - ramp->ramp_dec_per; + } + else + { + /* Set final setpint and exit soft stop */ + + *set = des; + ramp->ramp_mode = RAMP_MODE_NORMAL; + } break; } diff --git a/industry/foc/float/foc_routine.c b/industry/foc/float/foc_routine.c index 0f604e4fd..767fb1873 100644 --- a/industry/foc/float/foc_routine.c +++ b/industry/foc/float/foc_routine.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/industry/foc/float/foc_routine.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -28,7 +26,6 @@ #include #include -#include #include "industry/foc/foc_log.h" #include "industry/foc/float/foc_routine.h" diff --git a/industry/foc/float/foc_svm3.c b/industry/foc/float/foc_svm3.c index 5ba841166..36babe7f0 100644 --- a/industry/foc/float/foc_svm3.c +++ b/industry/foc/float/foc_svm3.c @@ -1,7 +1,6 @@ /**************************************************************************** * apps/industry/foc/float/foc_svm3.c - * - * SPDX-License-Identifier: Apache-2.0 + * This file implements 3-phase space vector modulation for float32 * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -74,8 +73,6 @@ static void foc_modulation_vbase_get_f32(FAR foc_handler_f32_t *h, static void foc_modulation_run_f32(FAR foc_handler_f32_t *h, FAR ab_frame_f32_t *v_ab_mod, FAR float *duty); -static void foc_modulation_state_f32(FAR foc_handler_f32_t *h, - FAR void *v_priv); /**************************************************************************** * Public Data @@ -91,7 +88,6 @@ struct foc_modulation_ops_f32_s g_foc_mod_svm3_f32 = .current = foc_modulation_current_f32, .vbase_get = foc_modulation_vbase_get_f32, .run = foc_modulation_run_f32, - .state_get = foc_modulation_state_f32, }; /**************************************************************************** @@ -247,7 +243,7 @@ static void foc_modulation_current_f32(FAR foc_handler_f32_t *h, } /**************************************************************************** - * Name: foc_modulation_run_f32 + * Name: foc_modulation_f32 * * Description: * Handle the SVM3 modulation (float32) @@ -290,33 +286,3 @@ static void foc_modulation_run_f32(FAR foc_handler_f32_t *h, f_saturate(&duty[1], 0.0f, svm->cfg.pwm_duty_max); f_saturate(&duty[2], 0.0f, svm->cfg.pwm_duty_max); } - -/**************************************************************************** - * Name: foc_modulation_state_f32 - * - * Description: - * Get the SVM3 modulation state (float32) - * - * Input Parameter: - * h - pointer to FOC handler - * state - pointer to modulation specific data - * - ****************************************************************************/ - -static void foc_modulation_state_f32(FAR foc_handler_f32_t *h, - FAR void *state) -{ - FAR struct foc_svm3mod_f32_s *svm = NULL; - - DEBUGASSERT(h); - DEBUGASSERT(state); - - /* Get modulation data */ - - DEBUGASSERT(h->modulation); - svm = h->modulation; - - /* Copy data */ - - memcpy(state, &svm->state, sizeof(struct svm3_state_f32_s)); -} diff --git a/industry/foc/float/foc_vel_odiv.c b/industry/foc/float/foc_vel_odiv.c index 3ba70cbf1..43491b5a5 100644 --- a/industry/foc/float/foc_vel_odiv.c +++ b/industry/foc/float/foc_vel_odiv.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/industry/foc/float/foc_vel_odiv.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -216,8 +214,6 @@ static int foc_velocity_div_zero_f32(FAR foc_velocity_f32_t *h) div->cfg.filter, div->cfg.per); - div->o.speed = 0.0f; - return ret; } diff --git a/industry/foc/float/foc_vel_opll.c b/industry/foc/float/foc_vel_opll.c index b15ffcb35..0e554848a 100644 --- a/industry/foc/float/foc_vel_opll.c +++ b/industry/foc/float/foc_vel_opll.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/industry/foc/float/foc_vel_opll.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -214,8 +212,6 @@ static int foc_velocity_pll_zero_f32(FAR foc_velocity_f32_t *h) pll->cfg.kp, pll->cfg.ki); - pll->o.speed = 0.0f; - return ret; } diff --git a/industry/foc/float/foc_velocity.c b/industry/foc/float/foc_velocity.c index ba81a5e8a..4a5b7ca86 100644 --- a/industry/foc/float/foc_velocity.c +++ b/industry/foc/float/foc_velocity.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/industry/foc/float/foc_velocity.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -28,7 +26,6 @@ #include #include -#include #include "industry/foc/foc_log.h" #include "industry/foc/float/foc_velocity.h" diff --git a/industry/foc/foc_utils.c b/industry/foc/foc_utils.c index 7e650577a..27838f8e6 100644 --- a/industry/foc/foc_utils.c +++ b/industry/foc/foc_utils.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/industry/foc/foc_utils.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/industry/modbus/.gitignore b/industry/modbus/.gitignore deleted file mode 100644 index 9e1d2593e..000000000 --- a/industry/modbus/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/Kconfig diff --git a/industry/modbus/CMakeLists.txt b/industry/modbus/CMakeLists.txt deleted file mode 100644 index 89038a9a7..000000000 --- a/industry/modbus/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -# ############################################################################## -# apps/industry/modbus/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -nuttx_add_subdirectory() - -nuttx_generate_kconfig(MENUDESC "Modbus") diff --git a/industry/modbus/Make.defs b/industry/modbus/Make.defs deleted file mode 100644 index b358e9be4..000000000 --- a/industry/modbus/Make.defs +++ /dev/null @@ -1,23 +0,0 @@ -############################################################################ -# apps/industry/modbus/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(wildcard $(APPDIR)/industry/modbus/*/Make.defs) diff --git a/industry/modbus/Makefile b/industry/modbus/Makefile deleted file mode 100644 index 320c97faf..000000000 --- a/industry/modbus/Makefile +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/industry/modbus/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -MENUDESC = "Modbus" - -include $(APPDIR)/Directory.mk diff --git a/industry/modbus/freemodbus/CMakeLists.txt b/industry/modbus/freemodbus/CMakeLists.txt deleted file mode 100644 index d49e6c069..000000000 --- a/industry/modbus/freemodbus/CMakeLists.txt +++ /dev/null @@ -1,101 +0,0 @@ -# ############################################################################## -# apps/industry/modbus/freemodbus/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_INDUSTRY_MODBUS) - - set(CSRCS) - - if(CONFIG_INDUSTRY_MODBUS_SLAVE) - list(APPEND CSRCS mb.c) - endif() - - if(CONFIG_MB_RTU_MASTER) - list(APPEND CSRCS mb_m.c) - endif() - - # ascii/Make.defs - - if(CONFIG_MB_ASCII_ENABLED) - list(APPEND CSRCS ascii/mbascii.c) - endif() - - # functions/Make.defs - - list( - APPEND - CSRCS - functions/mbfunccoils.c - functions/mbfuncdiag.c - functions/mbfuncdisc.c - functions/mbfuncholding.c - functions/mbfuncinput.c - functions/mbfuncother.c - functions/mbutils.c) - - if(CONFIG_MB_ASCII_MASTER) - list(APPEND CSRCS functions/mbfunccoils_m.c functions/mbfuncdisc_m.c - functions/mbfuncholding_m.c functions/mbfuncinput_m.c) - elseif(CONFIG_MB_RTU_MASTER) - list(APPEND CSRCS functions/mbfunccoils_m.c functions/mbfuncdisc_m.c - functions/mbfuncholding_m.c functions/mbfuncinput_m.c) - endif() - - # nuttx/Make.defs - - list(APPEND CSRCS nuttx/portother.c) - - if(CONFIG_INDUSTRY_MODBUS_SLAVE) - list(APPEND CSRCS nuttx/portevent.c nuttx/portserial.c nuttx/porttimer.c) - endif() - - if(CONFIG_MB_RTU_MASTER) - list(APPEND CSRCS nuttx/portother_m.c nuttx/portserial_m.c - nuttx/porttimer_m.c nuttx/portevent_m.c) - endif() - - # rtu/Make.defs - - if(CONFIG_MB_RTU_ENABLED OR CONFIG_MB_RTU_MASTER) - list(APPEND CSRCS rtu/mbcrc.c) - if(CONFIG_MB_RTU_ENABLED) - list(APPEND CSRCS rtu/mbrtu.c) - endif() - - if(CONFIG_MB_RTU_MASTER) - list(APPEND CSRCS rtu/mbrtu_m.c) - endif() - endif() - - # tcp/Make.defs - - if(CONFIG_MB_TCP_ENABLED) - list(APPEND CSRCS tcp/mbtcp.c) - endif() - - # include private headers - - target_include_directories(apps PRIVATE nuttx) - target_include_directories(apps PRIVATE rtu) - - target_sources(apps PRIVATE ${CSRCS}) - -endif() diff --git a/industry/modbus/freemodbus/Make.defs b/industry/modbus/freemodbus/Make.defs deleted file mode 100644 index 7d867a0aa..000000000 --- a/industry/modbus/freemodbus/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/industry/modbus/freemodbus/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_INDUSTRY_MODBUS),) -CONFIGURED_APPS += $(APPDIR)/industry/modbus/freemodbus -endif diff --git a/industry/nxmodbus/CMakeLists.txt b/industry/nxmodbus/CMakeLists.txt deleted file mode 100644 index 35be513e4..000000000 --- a/industry/nxmodbus/CMakeLists.txt +++ /dev/null @@ -1,68 +0,0 @@ -# ############################################################################## -# apps/industry/nxmodbus/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_INDUSTRY_NXMODBUS) - - set(CSRCS) - - # Core sources - list(APPEND CSRCS core/nxmb_context.c core/nxmb_utils.c) - - if(CONFIG_NXMODBUS_SERVER) - list(APPEND CSRCS core/nxmb_server.c) - list(APPEND CSRCS core/nxmb_func.c) - list(APPEND CSRCS core/nxmb_func_coils.c core/nxmb_func_discrete.c) - list(APPEND CSRCS core/nxmb_func_holding.c core/nxmb_func_input.c) - list(APPEND CSRCS core/nxmb_func_diag.c core/nxmb_func_other.c) - endif() - - if(CONFIG_NXMODBUS_CLIENT) - list(APPEND CSRCS core/nxmb_client.c) - endif() - - # Transport layer sources - if(CONFIG_NXMODBUS_RTU OR CONFIG_NXMODBUS_ASCII) - list(APPEND CSRCS transport/nxmb_serial_common.c) - endif() - - if(CONFIG_NXMODBUS_RTU) - list(APPEND CSRCS transport/nxmb_crc.c transport/nxmb_serial.c) - endif() - - if(CONFIG_NXMODBUS_ASCII) - list(APPEND CSRCS transport/nxmb_lrc.c transport/nxmb_ascii.c) - endif() - - if(CONFIG_NXMODBUS_RAW_ADU) - list(APPEND CSRCS transport/nxmb_raw.c) - endif() - - if(CONFIG_NXMODBUS_TCP) - list(APPEND CSRCS transport/nxmb_tcp.c) - endif() - - if(CSRCS) - target_include_directories(apps PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) - target_sources(apps PRIVATE ${CSRCS}) - endif() - -endif() diff --git a/industry/nxmodbus/Kconfig b/industry/nxmodbus/Kconfig deleted file mode 100644 index 31f555fe7..000000000 --- a/industry/nxmodbus/Kconfig +++ /dev/null @@ -1,245 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -menuconfig INDUSTRY_NXMODBUS - bool "NxModbus - New Modbus Stack" - default n - ---help--- - NxModbus is a modern Modbus stack for NuttX with multi-instance - support, per-instance register callbacks, and pluggable transport - backends (RTU, ASCII, TCP, Raw ADU). - - This implementation follows NuttX coding standards and is - designed for upstream contribution to nuttx-apps. - -if INDUSTRY_NXMODBUS - -config NXMODBUS_SERVER - bool "Server (slave) support" - default y - ---help--- - Enable Modbus server (slave) support. The server processes - incoming Modbus requests and calls registered register - callbacks. - -config NXMODBUS_CLIENT - bool "Client (master) support" - default n - ---help--- - Enable Modbus client (master) support. The client sends - Modbus requests to a server and receives responses. - -config NXMODBUS_RTU - bool "Modbus RTU mode" - default y - ---help--- - Enable Modbus RTU (Remote Terminal Unit) serial transmission - mode. Uses binary encoding with CRC16 error checking. - -config NXMODBUS_ASCII - bool "Modbus ASCII mode" - default n - ---help--- - Enable Modbus ASCII serial transmission mode. Uses - hex-encoded text with LRC error checking. Slower but - more human-readable than RTU. - -config NXMODBUS_TCP - bool "Modbus TCP mode" - default n - depends on NET_TCP - ---help--- - Enable Modbus TCP support. Modbus frames are encapsulated - in TCP/IP using the MBAP header format. Requires network - stack with TCP support. - -config NXMODBUS_RAW_ADU - bool "Raw ADU transport support" - default n - ---help--- - Enable raw ADU (Application Data Unit) transport mode. - The application provides callbacks for transmitting and - receiving raw Modbus frames. This enables custom transports - such as TLS, CAN, BLE, or MQTT. - -config NXMODBUS_MAX_INSTANCES - int "Maximum number of NxModbus instances" - default 1 - range 1 16 - ---help--- - Maximum number of simultaneous NxModbus instances. Each - instance can use a different transport (RTU, TCP, etc.) - and configuration. Instances are allocated from a static - pool at compile time. - -config NXMODBUS_ADU_DATA_MAX - int "ADU data buffer size in bytes" - default 252 - range 4 252 - ---help--- - Size of the data[] payload in struct nxmb_adu_s, in bytes. - This is the PDU body after the function code. The Modbus - specification allows up to 252 data bytes (1 fc + 252 data = - 253-byte PDU max). Reduce this value to save RAM on - resource-constrained systems. - -config NXMODBUS_REP_SERVER_ID_BUF - int "Report Server ID buffer size" - default 32 - range 4 253 - ---help--- - Size of the buffer used by FC17 (Report Server ID). - This buffer holds the server ID byte, run indicator, and - optional additional data configured via nxmb_set_server_id(). - -config NXMODBUS_ASCII_TIMEOUT_SEC - int "ASCII character timeout (seconds)" - default 1 - range 1 60 - depends on NXMODBUS_ASCII - ---help--- - Character timeout for Modbus ASCII mode in seconds. If no - character is received within this period, the current frame - is discarded. Default is 1 second per the Modbus specification. - -config NXMODBUS_CLIENT_TIMEOUT_MS - int "Client default response timeout (ms)" - default 1000 - range 100 60000 - depends on NXMODBUS_CLIENT - ---help--- - Default response timeout for client (master) mode in - milliseconds. If no response is received from the server - within this period, the request fails with ETIMEDOUT. - Can be overridden at runtime via nxmb_set_timeout(). - -config NXMODBUS_TCP_MAX_CLIENTS - int "Maximum simultaneous TCP client connections" - default 1 - range 1 8 - depends on NXMODBUS_TCP - ---help--- - Maximum number of simultaneous TCP client connections - accepted by a Modbus TCP server instance. Each connection - uses one file descriptor. Set to 1 for minimal resource - usage. - -config NXMODBUS_TCP_TIMEOUT_SEC - int "TCP idle connection timeout (seconds)" - default 60 - range 1 3600 - depends on NXMODBUS_TCP - ---help--- - Idle timeout for TCP connections in seconds. If no data is - received on a client connection within this period, the - connection is closed. Set to a higher value for slow networks. - -config NXMODBUS_RTU_IDLE_TIMEOUT_MS - int "RTU inter-frame idle timeout (ms)" - default 50 - range 1 1000 - depends on NXMODBUS_RTU - ---help--- - Fallback idle timeout in milliseconds used by the RTU - transport when waiting for a new frame via select(). This - is the maximum time to block waiting for data when no - frame is in progress. The T3.5 character timing is still - used for frame delimiting within an active reception. - -menu "Function Code Selection" - -config NXMODBUS_FUNC_READ_COILS - bool "FC01 Read Coils" - default y - depends on NXMODBUS_SERVER - ---help--- - Enable FC01 Read Coils function code handler. - -config NXMODBUS_FUNC_READ_DISCRETE - bool "FC02 Read Discrete Inputs" - default y - depends on NXMODBUS_SERVER - ---help--- - Enable FC02 Read Discrete Inputs function code handler. - -config NXMODBUS_FUNC_READ_HOLDING - bool "FC03 Read Holding Registers" - default y - depends on NXMODBUS_SERVER - ---help--- - Enable FC03 Read Holding Registers function code handler. - -config NXMODBUS_FUNC_READ_INPUT - bool "FC04 Read Input Registers" - default y - depends on NXMODBUS_SERVER - ---help--- - Enable FC04 Read Input Registers function code handler. - -config NXMODBUS_FUNC_WRITE_COIL - bool "FC05 Write Single Coil" - default y - depends on NXMODBUS_SERVER - ---help--- - Enable FC05 Write Single Coil function code handler. - -config NXMODBUS_FUNC_WRITE_HOLDING - bool "FC06 Write Single Holding Register" - default y - depends on NXMODBUS_SERVER - ---help--- - Enable FC06 Write Single Holding Register function - code handler. - -config NXMODBUS_FUNC_DIAGNOSTICS - bool "FC08 Diagnostics" - default y - depends on NXMODBUS_SERVER - ---help--- - Enable FC08 Diagnostics function code handler. - Only sub-function 0x0000 (Return Query Data) is supported. - -config NXMODBUS_FUNC_WRITE_COILS - bool "FC15 Write Multiple Coils" - default y - depends on NXMODBUS_SERVER - ---help--- - Enable FC15 Write Multiple Coils function code handler. - -config NXMODBUS_FUNC_WRITE_HOLDINGS - bool "FC16 Write Multiple Holding Registers" - default y - depends on NXMODBUS_SERVER - ---help--- - Enable FC16 Write Multiple Holding Registers function - code handler. - -config NXMODBUS_FUNC_REPORT_SERVER_ID - bool "FC17 Report Server ID" - default y - depends on NXMODBUS_SERVER - ---help--- - Enable FC17 Report Server ID function code handler. - -config NXMODBUS_FUNC_READWRITE_HOLDINGS - bool "FC23 Read/Write Multiple Holding Registers" - default y - depends on NXMODBUS_SERVER - ---help--- - Enable FC23 Read/Write Multiple Holding Registers - function code handler. - -endmenu # Function Code Selection - -config NXMODBUS_CUSTOM_FC - bool "Custom function code extension support" - default y - depends on NXMODBUS - ---help--- - Enable support for registering custom Modbus function - code handlers. Applications can extend the Modbus - function code set via nxmb_register_custom_fc(). - -endif # INDUSTRY_NXMODBUS diff --git a/industry/nxmodbus/Make.defs b/industry/nxmodbus/Make.defs deleted file mode 100644 index 539b48d64..000000000 --- a/industry/nxmodbus/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/modbus/nxmodbus/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_INDUSTRY_NXMODBUS),) -CONFIGURED_APPS += $(APPDIR)/industry/nxmodbus -endif diff --git a/industry/nxmodbus/Makefile b/industry/nxmodbus/Makefile deleted file mode 100644 index 64caacdba..000000000 --- a/industry/nxmodbus/Makefile +++ /dev/null @@ -1,76 +0,0 @@ -############################################################################ -# apps/industry/nxmodbus/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -# NxModbus Library - -ifeq ($(CONFIG_INDUSTRY_NXMODBUS),y) - -# Core sources -CSRCS := core/nxmb_context.c -CSRCS += core/nxmb_utils.c - -ifeq ($(CONFIG_NXMODBUS_SERVER),y) -CSRCS += core/nxmb_server.c -CSRCS += core/nxmb_func.c -CSRCS += core/nxmb_func_coils.c -CSRCS += core/nxmb_func_discrete.c -CSRCS += core/nxmb_func_holding.c -CSRCS += core/nxmb_func_input.c -CSRCS += core/nxmb_func_diag.c -CSRCS += core/nxmb_func_other.c -endif - -ifeq ($(CONFIG_NXMODBUS_CLIENT),y) -CSRCS += core/nxmb_client.c -endif - -# Transport layer sources -ifneq (,$(filter y,$(CONFIG_NXMODBUS_RTU) $(CONFIG_NXMODBUS_ASCII))) -CSRCS += transport/nxmb_serial_common.c -endif - -ifeq ($(CONFIG_NXMODBUS_RTU),y) -CSRCS += transport/nxmb_crc.c -CSRCS += transport/nxmb_serial.c -endif - -ifeq ($(CONFIG_NXMODBUS_ASCII),y) -CSRCS += transport/nxmb_lrc.c -CSRCS += transport/nxmb_ascii.c -endif - -ifeq ($(CONFIG_NXMODBUS_RAW_ADU),y) -CSRCS += transport/nxmb_raw.c -endif - -ifeq ($(CONFIG_NXMODBUS_TCP),y) -CSRCS += transport/nxmb_tcp.c -endif - -# Include private headers -CFLAGS += ${INCDIR_PREFIX}$(CURDIR) - -endif - -include $(APPDIR)/Application.mk diff --git a/industry/nxmodbus/core/nxmb_client.c b/industry/nxmodbus/core/nxmb_client.c deleted file mode 100644 index 24b264f92..000000000 --- a/industry/nxmodbus/core/nxmb_client.c +++ /dev/null @@ -1,739 +0,0 @@ -/**************************************************************************** - * apps/industry/nxmodbus/core/nxmb_client.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include -#include -#include - -#include -#include - -#include "nxmb_internal.h" - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -struct nxmb_client_state_s -{ - uint32_t timeout_ms; -}; - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -static int nxmb_client_tx_wait_rx(nxmb_handle_t ctx, - uint8_t expected_uid, uint8_t expected_fc); -static int nxmb_client_validate_response(nxmb_handle_t ctx, - uint8_t expected_uid, - uint8_t expected_fc); - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: nxmb_exception_to_errno - ****************************************************************************/ - -static int nxmb_exception_to_errno(uint8_t exception) -{ - switch (exception) - { - case NXMB_EX_ILLEGAL_FUNCTION: - return -ENXIO; - - case NXMB_EX_ILLEGAL_DATA_ADDRESS: - return -EFAULT; - - case NXMB_EX_ILLEGAL_DATA_VALUE: - return -EINVAL; - - case NXMB_EX_DEVICE_FAILURE: - return -EIO; - - case NXMB_EX_ACKNOWLEDGE: - return -EBUSY; - - case NXMB_EX_DEVICE_BUSY: - return -EBUSY; - - default: - return -EPROTO; - } -} - -/**************************************************************************** - * Name: nxmb_client_validate_response - ****************************************************************************/ - -static int nxmb_client_validate_response(nxmb_handle_t ctx, - uint8_t expected_uid, - uint8_t expected_fc) -{ - uint8_t rx_uid; - uint8_t rx_fc; - - if (ctx->adu.length < 2) - { - return -EPROTO; - } - - rx_uid = ctx->adu.unit_id; - rx_fc = ctx->adu.fc; - - if (rx_uid != expected_uid) - { - return -EPROTO; - } - - if (rx_fc == (expected_fc | 0x80)) - { - if (ctx->adu.length < 3) - { - return -EPROTO; - } - - return nxmb_exception_to_errno(ctx->adu.data[0]); - } - - if (rx_fc != expected_fc) - { - return -EPROTO; - } - - return OK; -} - -/**************************************************************************** - * Name: nxmb_client_tx_wait_rx - ****************************************************************************/ - -static int nxmb_client_tx_wait_rx(nxmb_handle_t ctx, uint8_t expected_uid, - uint8_t expected_fc) -{ - FAR struct nxmb_client_state_s *state; - uint64_t deadline; - int ret; - - if (ctx == NULL || ctx->client_state == NULL) - { - return -EINVAL; - } - - state = (FAR struct nxmb_client_state_s *)ctx->client_state; - - ret = ctx->transport_ops->send(ctx); - if (ret < 0) - { - return ret; - } - - /* Broadcast frames do not receive a response */ - - if (expected_uid == NXMB_ADDRESS_BROADCAST) - { - return OK; - } - - deadline = nxmb_util_clock_ms() + state->timeout_ms; - - for (; ; ) - { - if (nxmb_util_clock_ms() >= deadline) - { - return -ETIMEDOUT; - } - - ret = ctx->transport_ops->receive(ctx); - if (ret > 0) - { - return nxmb_client_validate_response(ctx, expected_uid, - expected_fc); - } - else if (ret < 0 && ret != -EAGAIN) - { - return ret; - } - } -} - -/**************************************************************************** - * Name: nxmb_client_read_bits - * - * Description: - * Common helper for FC01 (Read Coils) and FC02 (Read Discrete Inputs). - * - ****************************************************************************/ - -static int nxmb_client_read_bits(nxmb_handle_t ctx, uint8_t uid, uint8_t fc, - uint16_t addr, uint16_t count, - FAR uint8_t *buf) -{ - uint16_t nbytes; - int ret; - - nbytes = (count + 7) / 8; - - pthread_mutex_lock(&ctx->lock); - - ctx->adu.unit_id = uid; - ctx->adu.fc = fc; - nxmb_util_put_u16_be(&ctx->adu.data[0], addr); - nxmb_util_put_u16_be(&ctx->adu.data[2], count); - ctx->adu.length = 6; - - ret = nxmb_client_tx_wait_rx(ctx, uid, fc); - if (ret < 0) - { - pthread_mutex_unlock(&ctx->lock); - return ret; - } - - if (ctx->adu.length < (3 + nbytes) || ctx->adu.data[0] != nbytes) - { - pthread_mutex_unlock(&ctx->lock); - return -EPROTO; - } - - memcpy(buf, &ctx->adu.data[1], nbytes); - - pthread_mutex_unlock(&ctx->lock); - - return OK; -} - -/**************************************************************************** - * Name: nxmb_client_read_regs - * - * Description: - * Common helper for FC03 (Read Holding) and FC04 (Read Input) registers. - * - ****************************************************************************/ - -static int nxmb_client_read_regs(nxmb_handle_t ctx, uint8_t uid, uint8_t fc, - uint16_t addr, uint16_t count, - FAR uint16_t *buf) -{ - uint16_t nbytes; - int ret; - int i; - - nbytes = count * 2; - - pthread_mutex_lock(&ctx->lock); - - ctx->adu.unit_id = uid; - ctx->adu.fc = fc; - nxmb_util_put_u16_be(&ctx->adu.data[0], addr); - nxmb_util_put_u16_be(&ctx->adu.data[2], count); - ctx->adu.length = 6; - - ret = nxmb_client_tx_wait_rx(ctx, uid, fc); - if (ret < 0) - { - pthread_mutex_unlock(&ctx->lock); - return ret; - } - - if (ctx->adu.length < (3 + nbytes) || ctx->adu.data[0] != nbytes) - { - pthread_mutex_unlock(&ctx->lock); - return -EPROTO; - } - - for (i = 0; i < count; i++) - { - buf[i] = nxmb_util_get_u16_be(&ctx->adu.data[1 + i * 2]); - } - - pthread_mutex_unlock(&ctx->lock); - - return OK; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: nxmb_read_coils - ****************************************************************************/ - -int nxmb_read_coils(nxmb_handle_t ctx, uint8_t uid, uint16_t addr, - uint16_t count, FAR uint8_t *buf) -{ - DEBUGASSERT(ctx && buf); - - if (uid == NXMB_ADDRESS_BROADCAST || count == 0 || count > 2000) - { - return -EINVAL; - } - - if (!ctx->is_client) - { - return -ENOTSUP; - } - - return nxmb_client_read_bits(ctx, uid, NXMB_FC_READ_COILS, addr, - count, buf); -} - -/**************************************************************************** - * Name: nxmb_read_discrete - ****************************************************************************/ - -int nxmb_read_discrete(nxmb_handle_t ctx, uint8_t uid, uint16_t addr, - uint16_t count, FAR uint8_t *buf) -{ - DEBUGASSERT(ctx && buf); - - if (uid == NXMB_ADDRESS_BROADCAST || count == 0 || count > 2000) - { - return -EINVAL; - } - - if (!ctx->is_client) - { - return -ENOTSUP; - } - - return nxmb_client_read_bits(ctx, uid, NXMB_FC_READ_DISCRETE, addr, - count, buf); -} - -/**************************************************************************** - * Name: nxmb_read_input - ****************************************************************************/ - -int nxmb_read_input(nxmb_handle_t ctx, uint8_t uid, uint16_t addr, - uint16_t count, FAR uint16_t *buf) -{ - DEBUGASSERT(ctx && buf); - - if (uid == NXMB_ADDRESS_BROADCAST || count == 0 || count > 125) - { - return -EINVAL; - } - - if (!ctx->is_client) - { - return -ENOTSUP; - } - - return nxmb_client_read_regs(ctx, uid, NXMB_FC_READ_INPUT, addr, - count, buf); -} - -/**************************************************************************** - * Name: nxmb_read_holding - ****************************************************************************/ - -int nxmb_read_holding(nxmb_handle_t ctx, uint8_t uid, uint16_t addr, - uint16_t count, FAR uint16_t *buf) -{ - DEBUGASSERT(ctx && buf); - - if (uid == NXMB_ADDRESS_BROADCAST || count == 0 || count > 125) - { - return -EINVAL; - } - - if (!ctx->is_client) - { - return -ENOTSUP; - } - - return nxmb_client_read_regs(ctx, uid, NXMB_FC_READ_HOLDING, addr, - count, buf); -} - -/**************************************************************************** - * Name: nxmb_write_coil - ****************************************************************************/ - -int nxmb_write_coil(nxmb_handle_t ctx, uint8_t uid, uint16_t addr, - bool value) -{ - uint16_t coil_value; - int ret; - - DEBUGASSERT(ctx); - - if (!ctx->is_client) - { - return -ENOTSUP; - } - - coil_value = value ? 0xff00 : 0x0000; - - pthread_mutex_lock(&ctx->lock); - - ctx->adu.unit_id = uid; - ctx->adu.fc = NXMB_FC_WRITE_COIL; - nxmb_util_put_u16_be(&ctx->adu.data[0], addr); - nxmb_util_put_u16_be(&ctx->adu.data[2], coil_value); - ctx->adu.length = 6; - - ret = nxmb_client_tx_wait_rx(ctx, uid, NXMB_FC_WRITE_COIL); - if (ret < 0) - { - pthread_mutex_unlock(&ctx->lock); - return ret; - } - - if (uid != NXMB_ADDRESS_BROADCAST && ctx->adu.length < 6) - { - pthread_mutex_unlock(&ctx->lock); - return -EPROTO; - } - - pthread_mutex_unlock(&ctx->lock); - - return OK; -} - -/**************************************************************************** - * Name: nxmb_write_holding - ****************************************************************************/ - -int nxmb_write_holding(nxmb_handle_t ctx, uint8_t uid, uint16_t addr, - uint16_t value) -{ - int ret; - - DEBUGASSERT(ctx); - - if (!ctx->is_client) - { - return -ENOTSUP; - } - - pthread_mutex_lock(&ctx->lock); - - ctx->adu.unit_id = uid; - ctx->adu.fc = NXMB_FC_WRITE_HOLDING; - nxmb_util_put_u16_be(&ctx->adu.data[0], addr); - nxmb_util_put_u16_be(&ctx->adu.data[2], value); - ctx->adu.length = 6; - - ret = nxmb_client_tx_wait_rx(ctx, uid, NXMB_FC_WRITE_HOLDING); - if (ret < 0) - { - pthread_mutex_unlock(&ctx->lock); - return ret; - } - - if (uid != NXMB_ADDRESS_BROADCAST && ctx->adu.length < 6) - { - pthread_mutex_unlock(&ctx->lock); - return -EPROTO; - } - - pthread_mutex_unlock(&ctx->lock); - - return OK; -} - -/**************************************************************************** - * Name: nxmb_write_coils - ****************************************************************************/ - -int nxmb_write_coils(nxmb_handle_t ctx, uint8_t uid, uint16_t addr, - uint16_t count, FAR const uint8_t *buf) -{ - uint16_t nbytes; - int ret; - - DEBUGASSERT(ctx && buf); - - if (count == 0 || count > 1968) - { - return -EINVAL; - } - - if (!ctx->is_client) - { - return -ENOTSUP; - } - - nbytes = (count + 7) / 8; - - /* Request layout in adu.data[]: addr(2) + count(2) + bcnt(1) + nbytes */ - - if (5 + nbytes > NXMB_ADU_DATA_MAX) - { - return -EMSGSIZE; - } - - pthread_mutex_lock(&ctx->lock); - - ctx->adu.unit_id = uid; - ctx->adu.fc = NXMB_FC_WRITE_COILS; - nxmb_util_put_u16_be(&ctx->adu.data[0], addr); - nxmb_util_put_u16_be(&ctx->adu.data[2], count); - ctx->adu.data[4] = nbytes; - memcpy(&ctx->adu.data[5], buf, nbytes); - ctx->adu.length = 7 + nbytes; - - ret = nxmb_client_tx_wait_rx(ctx, uid, NXMB_FC_WRITE_COILS); - if (ret < 0) - { - pthread_mutex_unlock(&ctx->lock); - return ret; - } - - if (uid != NXMB_ADDRESS_BROADCAST && ctx->adu.length < 6) - { - pthread_mutex_unlock(&ctx->lock); - return -EPROTO; - } - - pthread_mutex_unlock(&ctx->lock); - - return OK; -} - -/**************************************************************************** - * Name: nxmb_write_holdings - ****************************************************************************/ - -int nxmb_write_holdings(nxmb_handle_t ctx, uint8_t uid, uint16_t addr, - uint16_t count, FAR const uint16_t *buf) -{ - uint16_t nbytes; - int ret; - int i; - - DEBUGASSERT(ctx && buf); - - if (count == 0 || count > 123) - { - return -EINVAL; - } - - if (!ctx->is_client) - { - return -ENOTSUP; - } - - nbytes = count * 2; - - /* Request layout in adu.data[]: addr(2) + count(2) + bcnt(1) + nbytes */ - - if (5 + nbytes > NXMB_ADU_DATA_MAX) - { - return -EMSGSIZE; - } - - pthread_mutex_lock(&ctx->lock); - - ctx->adu.unit_id = uid; - ctx->adu.fc = NXMB_FC_WRITE_HOLDINGS; - nxmb_util_put_u16_be(&ctx->adu.data[0], addr); - nxmb_util_put_u16_be(&ctx->adu.data[2], count); - ctx->adu.data[4] = nbytes; - - for (i = 0; i < count; i++) - { - nxmb_util_put_u16_be(&ctx->adu.data[5 + i * 2], buf[i]); - } - - ctx->adu.length = 7 + nbytes; - - ret = nxmb_client_tx_wait_rx(ctx, uid, NXMB_FC_WRITE_HOLDINGS); - if (ret < 0) - { - pthread_mutex_unlock(&ctx->lock); - return ret; - } - - if (uid != NXMB_ADDRESS_BROADCAST && ctx->adu.length < 6) - { - pthread_mutex_unlock(&ctx->lock); - return -EPROTO; - } - - pthread_mutex_unlock(&ctx->lock); - - return OK; -} - -/**************************************************************************** - * Name: nxmb_readwrite_holdings - ****************************************************************************/ - -int nxmb_readwrite_holdings(nxmb_handle_t ctx, uint8_t uid, uint16_t rd_addr, - uint16_t rd_count, FAR uint16_t *rd_buf, - uint16_t wr_addr, uint16_t wr_count, - FAR const uint16_t *wr_buf) -{ - uint16_t rd_nbytes; - uint16_t wr_nbytes; - int ret; - int i; - - DEBUGASSERT(ctx && rd_buf && wr_buf); - - if (uid == NXMB_ADDRESS_BROADCAST || rd_count == 0 || rd_count > 125 || - wr_count == 0 || wr_count > 121) - { - return -EINVAL; - } - - if (!ctx->is_client) - { - return -ENOTSUP; - } - - rd_nbytes = rd_count * 2; - wr_nbytes = wr_count * 2; - - /* Request layout: rd_addr(2) + rd_qty(2) + wr_addr(2) + wr_qty(2) + - * wr_bcnt(1) + wr_nbytes - */ - - if (9 + wr_nbytes > NXMB_ADU_DATA_MAX) - { - return -EMSGSIZE; - } - - pthread_mutex_lock(&ctx->lock); - - ctx->adu.unit_id = uid; - ctx->adu.fc = NXMB_FC_READWRITE_HOLDINGS; - nxmb_util_put_u16_be(&ctx->adu.data[0], rd_addr); - nxmb_util_put_u16_be(&ctx->adu.data[2], rd_count); - nxmb_util_put_u16_be(&ctx->adu.data[4], wr_addr); - nxmb_util_put_u16_be(&ctx->adu.data[6], wr_count); - ctx->adu.data[8] = (uint8_t)wr_nbytes; - - for (i = 0; i < wr_count; i++) - { - nxmb_util_put_u16_be(&ctx->adu.data[9 + i * 2], wr_buf[i]); - } - - ctx->adu.length = 11 + wr_nbytes; - - ret = nxmb_client_tx_wait_rx(ctx, uid, NXMB_FC_READWRITE_HOLDINGS); - if (ret < 0) - { - pthread_mutex_unlock(&ctx->lock); - return ret; - } - - if (ctx->adu.length < (3 + rd_nbytes)) - { - pthread_mutex_unlock(&ctx->lock); - return -EPROTO; - } - - if (ctx->adu.data[0] != rd_nbytes) - { - pthread_mutex_unlock(&ctx->lock); - return -EPROTO; - } - - for (i = 0; i < rd_count; i++) - { - rd_buf[i] = nxmb_util_get_u16_be(&ctx->adu.data[1 + i * 2]); - } - - pthread_mutex_unlock(&ctx->lock); - - return OK; -} - -/**************************************************************************** - * Name: nxmb_set_timeout - ****************************************************************************/ - -int nxmb_set_timeout(nxmb_handle_t ctx, uint32_t timeout_ms) -{ - FAR struct nxmb_client_state_s *state; - - DEBUGASSERT(ctx && ctx->client_state); - - if (!ctx->is_client) - { - return -ENOTSUP; - } - - state = (FAR struct nxmb_client_state_s *)ctx->client_state; - - pthread_mutex_lock(&ctx->lock); - state->timeout_ms = timeout_ms; - pthread_mutex_unlock(&ctx->lock); - - return OK; -} - -/**************************************************************************** - * Name: nxmb_client_init - ****************************************************************************/ - -int nxmb_client_init(nxmb_handle_t ctx) -{ - FAR struct nxmb_client_state_s *state; - - DEBUGASSERT(ctx && ctx->is_client); - - state = calloc(1, sizeof(struct nxmb_client_state_s)); - if (state == NULL) - { - return -ENOMEM; - } - - state->timeout_ms = CONFIG_NXMODBUS_CLIENT_TIMEOUT_MS; - - ctx->client_state = state; - - return OK; -} - -/**************************************************************************** - * Name: nxmb_client_deinit - ****************************************************************************/ - -int nxmb_client_deinit(nxmb_handle_t ctx) -{ - FAR struct nxmb_client_state_s *state; - - DEBUGASSERT(ctx && ctx->client_state); - - state = (FAR struct nxmb_client_state_s *)ctx->client_state; - - free(state); - - ctx->client_state = NULL; - - return OK; -} diff --git a/industry/nxmodbus/core/nxmb_context.c b/industry/nxmodbus/core/nxmb_context.c deleted file mode 100644 index e6a76c581..000000000 --- a/industry/nxmodbus/core/nxmb_context.c +++ /dev/null @@ -1,392 +0,0 @@ -/**************************************************************************** - * apps/industry/nxmodbus/core/nxmb_context.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include - -#include -#include -#include -#include -#include -#include - -#include - -#include "nxmb_internal.h" - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static struct nxmb_context_s g_nxmb_pool[CONFIG_NXMODBUS_MAX_INSTANCES]; -static pthread_mutex_t g_pool_lock = PTHREAD_MUTEX_INITIALIZER; - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: nxmb_create - * - * Description: - * Create a new NxModbus instance. - * - * Input Parameters: - * handle - Pointer to receive the instance handle - * config - Instance configuration - * - * Returned Value: - * 0 on success, negative errno on failure - * - ****************************************************************************/ - -int nxmb_create(FAR nxmb_handle_t *handle, - FAR const struct nxmb_config_s *config) -{ - nxmb_handle_t ctx = NULL; - int ret = -ENOMEM; - int i; - - DEBUGASSERT(handle && config); - -#ifndef CONFIG_NXMODBUS_CLIENT - if (config->is_client) - { - /* Master not supported */ - - return -EINVAL; - } -#endif - - pthread_mutex_lock(&g_pool_lock); - - for (i = 0; i < CONFIG_NXMODBUS_MAX_INSTANCES; i++) - { - if (g_nxmb_pool[i].mode == NXMB_MODE_INVAL) - { - ctx = &g_nxmb_pool[i]; - break; - } - } - - if (ctx != NULL) - { - memset(ctx, 0, sizeof(struct nxmb_context_s)); - - ret = pthread_mutex_init(&ctx->lock, NULL); - if (ret == 0) - { - ctx->mode = config->mode; - ctx->unit_id = config->unit_id; - ctx->is_client = config->is_client; - - switch (config->mode) - { -#ifdef CONFIG_NXMODBUS_RTU - case NXMB_MODE_RTU: - ctx->transport_cfg.serial = config->transport.serial; - ctx->transport_ops = &g_nxmb_serial_ops; - break; -#endif - -#ifdef CONFIG_NXMODBUS_ASCII - case NXMB_MODE_ASCII: - ctx->transport_cfg.serial = config->transport.serial; - ctx->transport_ops = &g_nxmb_ascii_ops; - break; -#endif - -#ifdef CONFIG_NXMODBUS_TCP - case NXMB_MODE_TCP: - ctx->transport_cfg.tcp = config->transport.tcp; - ctx->transport_ops = &g_nxmb_tcp_ops; - break; -#endif - -#ifdef CONFIG_NXMODBUS_RAW_ADU - case NXMB_MODE_RAW: - ctx->transport_cfg.raw = config->transport.raw; - ctx->transport_ops = &g_nxmb_raw_ops; - break; -#endif - - default: - pthread_mutex_destroy(&ctx->lock); - memset(ctx, 0, sizeof(struct nxmb_context_s)); - ret = -EINVAL; - goto out; - } - - *handle = ctx; - ret = 0; - } - else - { - memset(ctx, 0, sizeof(struct nxmb_context_s)); - ret = -ret; - } - } - -out: - pthread_mutex_unlock(&g_pool_lock); - return ret; -} - -/**************************************************************************** - * Name: nxmb_destroy - * - * Description: - * Destroy an NxModbus instance. - * - * Input Parameters: - * handle - Instance handle - * - * Returned Value: - * 0 on success, negative errno on failure - * - ****************************************************************************/ - -int nxmb_destroy(nxmb_handle_t ctx) -{ -#ifdef CONFIG_NXMODBUS_CUSTOM_FC - FAR struct nxmb_custom_fc_s *entry; - FAR struct nxmb_custom_fc_s *next; -#endif - - DEBUGASSERT(ctx); - - pthread_mutex_lock(&g_pool_lock); - pthread_mutex_lock(&ctx->lock); - - if (ctx->enabled) - { - pthread_mutex_unlock(&ctx->lock); - pthread_mutex_unlock(&g_pool_lock); - return -EBUSY; - } - - pthread_mutex_unlock(&ctx->lock); - pthread_mutex_destroy(&ctx->lock); - -#ifdef CONFIG_NXMODBUS_CUSTOM_FC - entry = ctx->custom_fc_list; - while (entry != NULL) - { - next = entry->next; - free(entry); - entry = next; - } -#endif - - memset(ctx, 0, sizeof(struct nxmb_context_s)); - pthread_mutex_unlock(&g_pool_lock); - - return 0; -} - -/**************************************************************************** - * Name: nxmb_set_callbacks - * - * Description: - * Set application callbacks for register access. - * - * Input Parameters: - * handle - Instance handle - * callbacks - Pointer to callback structure - * - * Returned Value: - * 0 on success, negative errno on failure - * - ****************************************************************************/ - -int nxmb_set_callbacks(nxmb_handle_t ctx, - FAR const struct nxmb_callbacks_s *callbacks) -{ - DEBUGASSERT(ctx); - - pthread_mutex_lock(&ctx->lock); - ctx->callbacks = callbacks; - pthread_mutex_unlock(&ctx->lock); - - return 0; -} - -/**************************************************************************** - * Name: nxmb_enable - * - * Description: - * Enable an NxModbus instance and initialize transport. - * - * Input Parameters: - * handle - Instance handle - * - * Returned Value: - * 0 on success, negative errno on failure - * - ****************************************************************************/ - -int nxmb_enable(nxmb_handle_t ctx) -{ - int ret; - - DEBUGASSERT(ctx && ctx->transport_ops && ctx->transport_ops->init); - - pthread_mutex_lock(&ctx->lock); - - if (ctx->enabled) - { - pthread_mutex_unlock(&ctx->lock); - return -EBUSY; - } - -#ifdef CONFIG_NXMODBUS_CLIENT - if (ctx->is_client) - { - ret = nxmb_client_init(ctx); - if (ret < 0) - { - pthread_mutex_unlock(&ctx->lock); - return ret; - } - } -#endif - - /* Initialize transport */ - - ret = ctx->transport_ops->init(ctx); - if (ret < 0) - { -#ifdef CONFIG_NXMODBUS_CLIENT - if (ctx->is_client) - { - nxmb_client_deinit(ctx); - } -#endif - - pthread_mutex_unlock(&ctx->lock); - return ret; - } - - ctx->enabled = true; - pthread_mutex_unlock(&ctx->lock); - - return 0; -} - -/**************************************************************************** - * Name: nxmb_set_server_id - * - * Description: - * Configure the data returned by FC17 (Report Server ID). - * - * Input Parameters: - * handle - Instance handle - * id - Server ID byte - * is_running - True if device is running - * additional - Optional additional data (may be NULL) - * addlen - Length of additional data - * - * Returned Value: - * 0 on success, negative errno on failure - * - ****************************************************************************/ - -int nxmb_set_server_id(nxmb_handle_t ctx, uint8_t id, bool is_running, - FAR const uint8_t *additional, uint16_t addlen) -{ - DEBUGASSERT(ctx); - - /* The first two bytes are server ID and run indicator. - * The rest is optional additional data. - */ - - if (addlen + 2 > CONFIG_NXMODBUS_REP_SERVER_ID_BUF) - { - return -ENOMEM; - } - - pthread_mutex_lock(&ctx->lock); - - ctx->server_id_len = 0; - ctx->server_id_buf[ctx->server_id_len++] = id; - ctx->server_id_buf[ctx->server_id_len++] = - (uint8_t)(is_running ? 0xff : 0x00); - - if (addlen > 0 && additional != NULL) - { - memcpy(&ctx->server_id_buf[ctx->server_id_len], additional, - (size_t)addlen); - ctx->server_id_len += addlen; - } - - pthread_mutex_unlock(&ctx->lock); - - return 0; -} - -/**************************************************************************** - * Name: nxmb_disable - * - * Description: - * Disable an NxModbus instance and deinitialize transport. - * - * Input Parameters: - * handle - Instance handle - * - * Returned Value: - * 0 on success, negative errno on failure - * - ****************************************************************************/ - -int nxmb_disable(nxmb_handle_t ctx) -{ - DEBUGASSERT(ctx && ctx->transport_ops && ctx->transport_ops->deinit); - - pthread_mutex_lock(&ctx->lock); - - if (!ctx->enabled) - { - pthread_mutex_unlock(&ctx->lock); - return 0; - } - - ctx->transport_ops->deinit(ctx); - -#ifdef CONFIG_NXMODBUS_CLIENT - if (ctx->is_client) - { - nxmb_client_deinit(ctx); - } -#endif - - ctx->enabled = false; - pthread_mutex_unlock(&ctx->lock); - - return 0; -} diff --git a/industry/nxmodbus/core/nxmb_func.c b/industry/nxmodbus/core/nxmb_func.c deleted file mode 100644 index 13b595b4f..000000000 --- a/industry/nxmodbus/core/nxmb_func.c +++ /dev/null @@ -1,354 +0,0 @@ -/**************************************************************************** - * apps/industry/nxmodbus/core/nxmb_func.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include - -#include -#include -#include -#include - -#include - -#include "nxmb_internal.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define NXMB_EXCEPTION_FLAG 0x80 - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/* Function code handler signature */ - -typedef enum nxmb_exception_e (*nxmb_fc_handler_t)(nxmb_handle_t ctx); - -/* Dispatch table entry */ - -struct nxmb_fc_entry_s -{ - uint8_t fc; - nxmb_fc_handler_t handler; -}; - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/* Standard function code dispatch table */ - -static const struct nxmb_fc_entry_s g_nxmb_fc_table[] = -{ -#ifdef CONFIG_NXMODBUS_FUNC_READ_COILS - { NXMB_FC_READ_COILS, nxmb_fc01_read_coils }, -#endif -#ifdef CONFIG_NXMODBUS_FUNC_READ_DISCRETE - { NXMB_FC_READ_DISCRETE, nxmb_fc02_read_discrete }, -#endif -#ifdef CONFIG_NXMODBUS_FUNC_READ_HOLDING - { NXMB_FC_READ_HOLDING, nxmb_fc03_read_holding }, -#endif -#ifdef CONFIG_NXMODBUS_FUNC_READ_INPUT - { NXMB_FC_READ_INPUT, nxmb_fc04_read_input }, -#endif -#ifdef CONFIG_NXMODBUS_FUNC_WRITE_COIL - { NXMB_FC_WRITE_COIL, nxmb_fc05_write_coil }, -#endif -#ifdef CONFIG_NXMODBUS_FUNC_WRITE_HOLDING - { NXMB_FC_WRITE_HOLDING, nxmb_fc06_write_holding }, -#endif -#ifdef CONFIG_NXMODBUS_FUNC_DIAGNOSTICS - { NXMB_FC_DIAGNOSTICS, nxmb_fc08_diagnostics }, -#endif -#ifdef CONFIG_NXMODBUS_FUNC_WRITE_COILS - { NXMB_FC_WRITE_COILS, nxmb_fc15_write_coils }, -#endif -#ifdef CONFIG_NXMODBUS_FUNC_WRITE_HOLDINGS - { NXMB_FC_WRITE_HOLDINGS, nxmb_fc16_write_holdings }, -#endif -#ifdef CONFIG_NXMODBUS_FUNC_REPORT_SERVER_ID - { NXMB_FC_REPORT_SERVER_ID, nxmb_fc17_report_server_id }, -#endif -#ifdef CONFIG_NXMODBUS_FUNC_READWRITE_HOLDINGS - { NXMB_FC_READWRITE_HOLDINGS, nxmb_fc23_readwrite_holding } -#endif -}; - -#define NXMB_FC_TABLE_SIZE \ - (sizeof(g_nxmb_fc_table) / sizeof(g_nxmb_fc_table[0])) - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: nxmb_build_exception - * - * Description: - * Build a Modbus exception response in ctx->adu in place. - * - * Input Parameters: - * ctx - Instance context - * fc - Function code - * exception - NxModbus exception code - * - ****************************************************************************/ - -static void nxmb_build_exception(nxmb_handle_t ctx, uint8_t fc, - enum nxmb_exception_e exception) -{ - ctx->adu.fc = fc | NXMB_EXCEPTION_FLAG; - ctx->adu.data[0] = (uint8_t)exception; - - /* unit_id + fc + 1 exception byte */ - - ctx->adu.length = 3; -} - -/**************************************************************************** - * Name: nxmb_lookup_standard_fc - * - * Description: - * Look up a standard function code handler in the dispatch table. - * - * Input Parameters: - * fc - Function code to look up - * - * Returned Value: - * Handler function pointer, or NULL if not found - * - ****************************************************************************/ - -static nxmb_fc_handler_t nxmb_lookup_standard_fc(uint8_t fc) -{ - int i; - - for (i = 0; i < NXMB_FC_TABLE_SIZE; i++) - { - if (g_nxmb_fc_table[i].fc == fc) - { - return g_nxmb_fc_table[i].handler; - } - } - - return NULL; -} - -#ifdef CONFIG_NXMODBUS_CUSTOM_FC - -/**************************************************************************** - * Name: nxmb_lookup_custom_fc - * - * Description: - * Look up a custom function code handler in the instance list. - * - * Input Parameters: - * ctx - Instance context - * fc - Function code to look up - * - * Returned Value: - * Handler function pointer, or NULL if not found - * - ****************************************************************************/ - -static nxmb_custom_fc_handler_t nxmb_lookup_custom_fc( - nxmb_handle_t ctx, uint8_t fc) -{ - FAR struct nxmb_custom_fc_s *entry; - - for (entry = ctx->custom_fc_list; entry != NULL; entry = entry->next) - { - if (entry->fc == fc) - { - return entry->handler; - } - } - - return NULL; -} - -#endif /* CONFIG_NXMODBUS_CUSTOM_FC */ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: nxmb_dispatch_function - * - * Description: - * Dispatch a Modbus function code to the appropriate handler. Operates in - * place on ctx->adu. Checks standard handlers first, then custom handlers - * if enabled. Builds an exception response if no handler is found or the - * handler fails. - * - * Input Parameters: - * ctx - Instance context - * - * Returned Value: - * Zero on success; a negated errno value on failure - * - ****************************************************************************/ - -int nxmb_dispatch_function(nxmb_handle_t ctx) -{ - nxmb_fc_handler_t handler; - enum nxmb_exception_e exception; - uint8_t fc; -#ifdef CONFIG_NXMODBUS_CUSTOM_FC - nxmb_custom_fc_handler_t custom_handler; - int ret; -#endif - - DEBUGASSERT(ctx); - - if (ctx->adu.length < 2) - { - return -EINVAL; - } - - fc = ctx->adu.fc; - - /* Look up standard handler first */ - - handler = nxmb_lookup_standard_fc(fc); - -#ifdef CONFIG_NXMODBUS_CUSTOM_FC - - /* If not found, check custom handlers */ - - if (handler == NULL) - { - custom_handler = nxmb_lookup_custom_fc(ctx, fc); - if (custom_handler != NULL) - { - ret = custom_handler(ctx); - if (ret < 0) - { - nxmb_build_exception(ctx, fc, NXMB_EX_DEVICE_FAILURE); - } - - return 0; - } - } -#endif - - /* If no handler found, return illegal function exception */ - - if (handler == NULL) - { - nxmb_build_exception(ctx, fc, NXMB_EX_ILLEGAL_FUNCTION); - return 0; - } - - /* Call the handler */ - - exception = handler(ctx); - - /* If handler returned exception, build exception response */ - - if (exception != NXMB_EX_NONE) - { - nxmb_build_exception(ctx, fc, exception); - } - - return 0; -} - -#ifdef CONFIG_NXMODBUS_CUSTOM_FC -/**************************************************************************** - * Name: nxmb_register_custom_fc - * - * Description: - * Register a custom Modbus function code handler for an instance. - * - * Custom handlers are checked after standard handlers, so standard - * function codes (FC01-FC16) cannot be overridden. - * - * Input Parameters: - * h - The NxModbus instance handle - * fc - The custom function code to register - * handler - The handler function - * - * Returned Value: - * Zero on success; a negated errno value on failure - * - ****************************************************************************/ - -int nxmb_register_custom_fc(nxmb_handle_t ctx, uint8_t fc, - nxmb_custom_fc_handler_t handler) -{ - FAR struct nxmb_custom_fc_s *entry; - FAR struct nxmb_custom_fc_s *new_entry; - - DEBUGASSERT(ctx && handler); - - /* Check if FC is already a standard handler */ - - if (nxmb_lookup_standard_fc(fc) != NULL) - { - return -EEXIST; - } - - pthread_mutex_lock(&ctx->lock); - - /* Check if FC is already registered as custom */ - - for (entry = ctx->custom_fc_list; entry != NULL; entry = entry->next) - { - if (entry->fc == fc) - { - pthread_mutex_unlock(&ctx->lock); - return -EEXIST; - } - } - - /* Allocate new entry */ - - new_entry = malloc(sizeof(struct nxmb_custom_fc_s)); - if (new_entry == NULL) - { - pthread_mutex_unlock(&ctx->lock); - return -ENOMEM; - } - - /* Initialize and prepend to list */ - - new_entry->fc = fc; - new_entry->handler = handler; - new_entry->next = ctx->custom_fc_list; - ctx->custom_fc_list = new_entry; - - pthread_mutex_unlock(&ctx->lock); - return 0; -} - -#endif /* CONFIG_NXMODBUS_CUSTOM_FC */ diff --git a/industry/nxmodbus/core/nxmb_func_coils.c b/industry/nxmodbus/core/nxmb_func_coils.c deleted file mode 100644 index 3235fcc9e..000000000 --- a/industry/nxmodbus/core/nxmb_func_coils.c +++ /dev/null @@ -1,259 +0,0 @@ -/**************************************************************************** - * apps/industry/nxmodbus/core/nxmb_func_coils.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include - -#include -#include - -#include - -#include "nxmb_internal.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* Offsets are in adu.data[]; lengths refer to data only. */ - -/* FC01 Read Coils */ - -#define NXMB_FC01_ADDR_OFF 0 -#define NXMB_FC01_QTY_OFF 2 -#define NXMB_FC01_REQ_DATA_LEN 4 - -/* FC05 Write Single Coil */ - -#define NXMB_FC05_ADDR_OFF 0 -#define NXMB_FC05_VALUE_OFF 2 -#define NXMB_FC05_REQ_DATA_LEN 4 - -/* FC15 Write Multiple Coils */ - -#define NXMB_FC15_ADDR_OFF 0 -#define NXMB_FC15_QTY_OFF 2 -#define NXMB_FC15_BCNT_OFF 4 -#define NXMB_FC15_DATA_OFF 5 -#define NXMB_FC15_RESP_DATA_LEN 4 - -/* Maximum coil quantity per Modbus specification. - * FC01/FC02 read max is 2000 (0x07D0). - * FC15 write max is 1968 (0x07B0). - */ - -#define NXMB_COIL_READ_QTY_MAX 2000 -#define NXMB_COIL_WRITE_QTY_MAX 1968 - -/* Coil ON/OFF wire values for FC05 */ - -#define NXMB_COIL_ON 0xff00 -#define NXMB_COIL_OFF 0x0000 - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: nxmb_fc01_read_coils - ****************************************************************************/ - -enum nxmb_exception_e nxmb_fc01_read_coils(nxmb_handle_t ctx) -{ - uint16_t data_len = ctx->adu.length - 2; - uint16_t addr; - uint16_t qty; - uint8_t nbytes; - int ret; - - if (data_len != NXMB_FC01_REQ_DATA_LEN) - { - return NXMB_EX_ILLEGAL_DATA_VALUE; - } - - if (ctx->callbacks == NULL || ctx->callbacks->coil_cb == NULL) - { - return NXMB_EX_ILLEGAL_FUNCTION; - } - - addr = nxmb_util_get_u16_be(&ctx->adu.data[NXMB_FC01_ADDR_OFF]); - qty = nxmb_util_get_u16_be(&ctx->adu.data[NXMB_FC01_QTY_OFF]); - - if (qty < 1 || qty > NXMB_COIL_READ_QTY_MAX) - { - return NXMB_EX_ILLEGAL_DATA_VALUE; - } - - if ((uint32_t)addr + qty > 0xffffu) - { - return NXMB_EX_ILLEGAL_DATA_ADDRESS; - } - - nbytes = (uint8_t)((qty + 7) / 8); - - /* Response is byte_count + coil data */ - - if (1 + nbytes > NXMB_ADU_DATA_MAX) - { - return NXMB_EX_ILLEGAL_DATA_VALUE; - } - - /* Build response: byte_count + coil data */ - - ctx->adu.fc = NXMB_FC_READ_COILS; - ctx->adu.data[0] = nbytes; - - /* Zero data area so unused trailing bits are clear */ - - memset(&ctx->adu.data[1], 0, nbytes); - - ret = ctx->callbacks->coil_cb(&ctx->adu.data[1], addr, qty, NXMB_REG_READ, - ctx->callbacks->priv); - if (ret != 0) - { - return nxmb_cb_ret_to_exception(ret); - } - - ctx->adu.length = (uint16_t)(2 + 1 + nbytes); - return NXMB_EX_NONE; -} - -/**************************************************************************** - * Name: nxmb_fc05_write_coil - ****************************************************************************/ - -enum nxmb_exception_e nxmb_fc05_write_coil(nxmb_handle_t ctx) -{ - uint16_t data_len = ctx->adu.length - 2; - uint16_t addr; - uint16_t value; - uint8_t coil_buf[2]; - int ret; - - if (data_len != NXMB_FC05_REQ_DATA_LEN) - { - return NXMB_EX_ILLEGAL_DATA_VALUE; - } - - if (ctx->callbacks == NULL || ctx->callbacks->coil_cb == NULL) - { - return NXMB_EX_ILLEGAL_FUNCTION; - } - - addr = nxmb_util_get_u16_be(&ctx->adu.data[NXMB_FC05_ADDR_OFF]); - value = nxmb_util_get_u16_be(&ctx->adu.data[NXMB_FC05_VALUE_OFF]); - - if (addr == 0xffffu) - { - return NXMB_EX_ILLEGAL_DATA_ADDRESS; - } - - if (value != NXMB_COIL_ON && value != NXMB_COIL_OFF) - { - return NXMB_EX_ILLEGAL_DATA_VALUE; - } - - /* Convert wire value to single-bit buffer for callback */ - - coil_buf[0] = (value == NXMB_COIL_ON) ? 1 : 0; - coil_buf[1] = 0; - - ret = ctx->callbacks->coil_cb(coil_buf, addr, 1, NXMB_REG_WRITE, - ctx->callbacks->priv); - if (ret != 0) - { - return nxmb_cb_ret_to_exception(ret); - } - - /* Response echoes the request โ€” adu.length is already correct */ - - return NXMB_EX_NONE; -} - -/**************************************************************************** - * Name: nxmb_fc15_write_coils - ****************************************************************************/ - -enum nxmb_exception_e nxmb_fc15_write_coils(nxmb_handle_t ctx) -{ - uint16_t data_len = ctx->adu.length - 2; - uint16_t addr; - uint16_t qty; - uint8_t byte_count; - uint8_t byte_count_exp; - int ret; - - if (data_len < NXMB_FC15_DATA_OFF) - { - return NXMB_EX_ILLEGAL_DATA_VALUE; - } - - if (ctx->callbacks == NULL || ctx->callbacks->coil_cb == NULL) - { - return NXMB_EX_ILLEGAL_FUNCTION; - } - - addr = nxmb_util_get_u16_be(&ctx->adu.data[NXMB_FC15_ADDR_OFF]); - qty = nxmb_util_get_u16_be(&ctx->adu.data[NXMB_FC15_QTY_OFF]); - byte_count = ctx->adu.data[NXMB_FC15_BCNT_OFF]; - - if (qty < 1 || qty > NXMB_COIL_WRITE_QTY_MAX) - { - return NXMB_EX_ILLEGAL_DATA_VALUE; - } - - if ((uint32_t)addr + qty > 0xffffu) - { - return NXMB_EX_ILLEGAL_DATA_ADDRESS; - } - - byte_count_exp = (uint8_t)((qty + 7) / 8); - - if (byte_count != byte_count_exp) - { - return NXMB_EX_ILLEGAL_DATA_VALUE; - } - - /* Verify total data length matches header + payload */ - - if (data_len != (uint16_t)(NXMB_FC15_DATA_OFF + byte_count)) - { - return NXMB_EX_ILLEGAL_DATA_VALUE; - } - - ret = ctx->callbacks->coil_cb(&ctx->adu.data[NXMB_FC15_DATA_OFF], addr, - qty, NXMB_REG_WRITE, ctx->callbacks->priv); - if (ret != 0) - { - return nxmb_cb_ret_to_exception(ret); - } - - /* Response: addr(2) + qty(2) โ€” already in data[0..3] from request */ - - ctx->adu.length = (uint16_t)(2 + NXMB_FC15_RESP_DATA_LEN); - return NXMB_EX_NONE; -} diff --git a/industry/nxmodbus/core/nxmb_func_diag.c b/industry/nxmodbus/core/nxmb_func_diag.c deleted file mode 100644 index 8575c610d..000000000 --- a/industry/nxmodbus/core/nxmb_func_diag.c +++ /dev/null @@ -1,83 +0,0 @@ -/**************************************************************************** - * apps/industry/nxmodbus/core/nxmb_func_diag.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include - -#include - -#include - -#include "nxmb_internal.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define NXMB_DIAG_SUBFUNC_OFF 0 -#define NXMB_DIAG_DATA_OFF 2 -#define NXMB_DIAG_REQ_MIN_DATA_LEN 4 - -/* Sub-function codes */ - -#define NXMB_DIAG_RETURN_QUERY 0x0000 - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: nxmb_fc08_diagnostics - ****************************************************************************/ - -enum nxmb_exception_e nxmb_fc08_diagnostics(nxmb_handle_t ctx) -{ - uint16_t data_len = ctx->adu.length - 2; - uint16_t subfunc; - - if (data_len < NXMB_DIAG_REQ_MIN_DATA_LEN) - { - return NXMB_EX_ILLEGAL_DATA_VALUE; - } - - subfunc = nxmb_util_get_u16_be(&ctx->adu.data[NXMB_DIAG_SUBFUNC_OFF]); - - switch (subfunc) - { - case NXMB_DIAG_RETURN_QUERY: - { - /* Response echoes the request โ€” adu is already correct */ - - return NXMB_EX_NONE; - } - - default: - { - return NXMB_EX_ILLEGAL_FUNCTION; - } - } -} diff --git a/industry/nxmodbus/core/nxmb_func_discrete.c b/industry/nxmodbus/core/nxmb_func_discrete.c deleted file mode 100644 index b30a0a720..000000000 --- a/industry/nxmodbus/core/nxmb_func_discrete.c +++ /dev/null @@ -1,110 +0,0 @@ -/**************************************************************************** - * apps/industry/nxmodbus/core/nxmb_func_discrete.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include - -#include -#include - -#include - -#include "nxmb_internal.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define NXMB_FC02_ADDR_OFF 0 -#define NXMB_FC02_QTY_OFF 2 -#define NXMB_FC02_REQ_DATA_LEN 4 - -#define NXMB_DISCRETE_QTY_MAX 2000 - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: nxmb_fc02_read_discrete - ****************************************************************************/ - -enum nxmb_exception_e nxmb_fc02_read_discrete(nxmb_handle_t ctx) -{ - uint16_t data_len = ctx->adu.length - 2; - uint16_t addr; - uint16_t qty; - uint8_t nbytes; - int ret; - - if (data_len != NXMB_FC02_REQ_DATA_LEN) - { - return NXMB_EX_ILLEGAL_DATA_VALUE; - } - - if (ctx->callbacks == NULL || ctx->callbacks->discrete_cb == NULL) - { - return NXMB_EX_ILLEGAL_FUNCTION; - } - - addr = nxmb_util_get_u16_be(&ctx->adu.data[NXMB_FC02_ADDR_OFF]); - qty = nxmb_util_get_u16_be(&ctx->adu.data[NXMB_FC02_QTY_OFF]); - - if (qty < 1 || qty > NXMB_DISCRETE_QTY_MAX) - { - return NXMB_EX_ILLEGAL_DATA_VALUE; - } - - if ((uint32_t)addr + qty > 0xffffu) - { - return NXMB_EX_ILLEGAL_DATA_ADDRESS; - } - - nbytes = (uint8_t)((qty + 7) / 8); - - /* Response is byte_count + discrete data */ - - if (1 + nbytes > NXMB_ADU_DATA_MAX) - { - return NXMB_EX_ILLEGAL_DATA_VALUE; - } - - ctx->adu.fc = NXMB_FC_READ_DISCRETE; - ctx->adu.data[0] = nbytes; - - memset(&ctx->adu.data[1], 0, nbytes); - - ret = ctx->callbacks->discrete_cb(&ctx->adu.data[1], addr, qty, - ctx->callbacks->priv); - if (ret != 0) - { - return nxmb_cb_ret_to_exception(ret); - } - - ctx->adu.length = (uint16_t)(2 + 1 + nbytes); - return NXMB_EX_NONE; -} diff --git a/industry/nxmodbus/core/nxmb_func_holding.c b/industry/nxmodbus/core/nxmb_func_holding.c deleted file mode 100644 index a4fe74cc5..000000000 --- a/industry/nxmodbus/core/nxmb_func_holding.c +++ /dev/null @@ -1,331 +0,0 @@ -/**************************************************************************** - * apps/industry/nxmodbus/core/nxmb_func_holding.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include - -#include - -#include - -#include "nxmb_internal.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* PDU data offsets are relative to ctx->adu.data[] (after unit_id + fc). - * Lengths refer to the data payload only โ€” adu.length = 2 + data_len. - */ - -/* FC03 Read Holding Registers */ - -#define NXMB_FC03_ADDR_OFF 0 -#define NXMB_FC03_QTY_OFF 2 -#define NXMB_FC03_REQ_DATA_LEN 4 - -/* FC06 Write Single Holding Register */ - -#define NXMB_FC06_ADDR_OFF 0 -#define NXMB_FC06_VALUE_OFF 2 -#define NXMB_FC06_REQ_DATA_LEN 4 - -/* FC16 Write Multiple Holding Registers */ - -#define NXMB_FC16_ADDR_OFF 0 -#define NXMB_FC16_QTY_OFF 2 -#define NXMB_FC16_BCNT_OFF 4 -#define NXMB_FC16_DATA_OFF 5 -#define NXMB_FC16_RESP_DATA_LEN 4 - -/* FC23 Read/Write Multiple Holding Registers */ - -#define NXMB_FC23_RD_ADDR_OFF 0 -#define NXMB_FC23_RD_QTY_OFF 2 -#define NXMB_FC23_WR_ADDR_OFF 4 -#define NXMB_FC23_WR_QTY_OFF 6 -#define NXMB_FC23_WR_BCNT_OFF 8 -#define NXMB_FC23_WR_DATA_OFF 9 -#define NXMB_FC23_REQ_MIN_DATA_LEN 9 - -/* Quantity limits per Modbus Application Protocol Specification */ - -#define NXMB_REG_READ_QTY_MAX 125 /* 0x007D */ -#define NXMB_REG_WRITE_MUL_QTY_MAX 123 /* 0x007B */ -#define NXMB_REG_READWRITE_RD_QTY_MAX 125 /* 0x007D */ -#define NXMB_REG_READWRITE_WR_QTY_MAX 121 /* 0x0079 */ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: nxmb_fc03_read_holding - ****************************************************************************/ - -enum nxmb_exception_e nxmb_fc03_read_holding(nxmb_handle_t ctx) -{ - uint16_t data_len = ctx->adu.length - 2; - uint16_t addr; - uint16_t qty; - uint8_t nbytes; - int ret; - - if (data_len != NXMB_FC03_REQ_DATA_LEN) - { - return NXMB_EX_ILLEGAL_DATA_VALUE; - } - - if (ctx->callbacks == NULL || ctx->callbacks->holding_cb == NULL) - { - return NXMB_EX_ILLEGAL_FUNCTION; - } - - addr = nxmb_util_get_u16_be(&ctx->adu.data[NXMB_FC03_ADDR_OFF]); - qty = nxmb_util_get_u16_be(&ctx->adu.data[NXMB_FC03_QTY_OFF]); - - if (qty < 1 || qty > NXMB_REG_READ_QTY_MAX) - { - return NXMB_EX_ILLEGAL_DATA_VALUE; - } - - if ((uint32_t)addr + qty > 0xffffu) - { - return NXMB_EX_ILLEGAL_DATA_ADDRESS; - } - - nbytes = (uint8_t)(qty * 2); - - /* Response is byte_count + register data */ - - if (1 + nbytes > NXMB_ADU_DATA_MAX) - { - return NXMB_EX_ILLEGAL_DATA_VALUE; - } - - /* Build response: byte_count + register data (big-endian) */ - - ctx->adu.fc = NXMB_FC_READ_HOLDING; - ctx->adu.data[0] = nbytes; - - ret = ctx->callbacks->holding_cb(&ctx->adu.data[1], addr, qty, - NXMB_REG_READ, ctx->callbacks->priv); - if (ret != 0) - { - return nxmb_cb_ret_to_exception(ret); - } - - ctx->adu.length = (uint16_t)(2 + 1 + nbytes); - return NXMB_EX_NONE; -} - -/**************************************************************************** - * Name: nxmb_fc06_write_holding - ****************************************************************************/ - -enum nxmb_exception_e nxmb_fc06_write_holding(nxmb_handle_t ctx) -{ - uint16_t data_len = ctx->adu.length - 2; - uint16_t addr; - int ret; - - if (data_len != NXMB_FC06_REQ_DATA_LEN) - { - return NXMB_EX_ILLEGAL_DATA_VALUE; - } - - if (ctx->callbacks == NULL || ctx->callbacks->holding_cb == NULL) - { - return NXMB_EX_ILLEGAL_FUNCTION; - } - - addr = nxmb_util_get_u16_be(&ctx->adu.data[NXMB_FC06_ADDR_OFF]); - - if (addr == 0xffffu) - { - return NXMB_EX_ILLEGAL_DATA_ADDRESS; - } - - ret = ctx->callbacks->holding_cb(&ctx->adu.data[NXMB_FC06_VALUE_OFF], addr, - 1, NXMB_REG_WRITE, ctx->callbacks->priv); - if (ret != 0) - { - return nxmb_cb_ret_to_exception(ret); - } - - /* Response echoes the request โ€” adu.length is already correct */ - - return NXMB_EX_NONE; -} - -/**************************************************************************** - * Name: nxmb_fc16_write_holdings - ****************************************************************************/ - -enum nxmb_exception_e nxmb_fc16_write_holdings(nxmb_handle_t ctx) -{ - uint16_t data_len = ctx->adu.length - 2; - uint16_t addr; - uint16_t qty; - uint8_t byte_count; - int ret; - - if (data_len < NXMB_FC16_DATA_OFF) - { - return NXMB_EX_ILLEGAL_DATA_VALUE; - } - - if (ctx->callbacks == NULL || ctx->callbacks->holding_cb == NULL) - { - return NXMB_EX_ILLEGAL_FUNCTION; - } - - addr = nxmb_util_get_u16_be(&ctx->adu.data[NXMB_FC16_ADDR_OFF]); - qty = nxmb_util_get_u16_be(&ctx->adu.data[NXMB_FC16_QTY_OFF]); - byte_count = ctx->adu.data[NXMB_FC16_BCNT_OFF]; - - if (qty < 1 || qty > NXMB_REG_WRITE_MUL_QTY_MAX) - { - return NXMB_EX_ILLEGAL_DATA_VALUE; - } - - if ((uint32_t)addr + qty > 0xffffu) - { - return NXMB_EX_ILLEGAL_DATA_ADDRESS; - } - - if (byte_count != (uint8_t)(qty * 2)) - { - return NXMB_EX_ILLEGAL_DATA_VALUE; - } - - /* Verify total data length matches header + payload */ - - if (data_len != (uint16_t)(NXMB_FC16_DATA_OFF + byte_count)) - { - return NXMB_EX_ILLEGAL_DATA_VALUE; - } - - ret = ctx->callbacks->holding_cb(&ctx->adu.data[NXMB_FC16_DATA_OFF], addr, - qty, NXMB_REG_WRITE, - ctx->callbacks->priv); - if (ret != 0) - { - return nxmb_cb_ret_to_exception(ret); - } - - /* Response: addr(2) + qty(2) โ€” already in data[0..3] from request */ - - ctx->adu.length = (uint16_t)(2 + NXMB_FC16_RESP_DATA_LEN); - return NXMB_EX_NONE; -} - -/**************************************************************************** - * Name: nxmb_fc23_readwrite_holding - ****************************************************************************/ - -enum nxmb_exception_e nxmb_fc23_readwrite_holding(nxmb_handle_t ctx) -{ - uint16_t data_len = ctx->adu.length - 2; - uint16_t rd_addr; - uint16_t rd_qty; - uint16_t wr_addr; - uint16_t wr_qty; - uint8_t wr_bcnt; - uint16_t rd_bcnt; - int ret; - - if (data_len < NXMB_FC23_REQ_MIN_DATA_LEN) - { - return NXMB_EX_ILLEGAL_DATA_VALUE; - } - - if (ctx->callbacks == NULL || ctx->callbacks->holding_cb == NULL) - { - return NXMB_EX_ILLEGAL_FUNCTION; - } - - rd_addr = nxmb_util_get_u16_be(&ctx->adu.data[NXMB_FC23_RD_ADDR_OFF]); - rd_qty = nxmb_util_get_u16_be(&ctx->adu.data[NXMB_FC23_RD_QTY_OFF]); - wr_addr = nxmb_util_get_u16_be(&ctx->adu.data[NXMB_FC23_WR_ADDR_OFF]); - wr_qty = nxmb_util_get_u16_be(&ctx->adu.data[NXMB_FC23_WR_QTY_OFF]); - wr_bcnt = ctx->adu.data[NXMB_FC23_WR_BCNT_OFF]; - - if (rd_qty < 1 || rd_qty > NXMB_REG_READWRITE_RD_QTY_MAX || wr_qty < 1 || - wr_qty > NXMB_REG_READWRITE_WR_QTY_MAX || wr_bcnt != (wr_qty * 2)) - { - return NXMB_EX_ILLEGAL_DATA_VALUE; - } - - if ((uint32_t)rd_addr + rd_qty > 0xffffu) - { - return NXMB_EX_ILLEGAL_DATA_ADDRESS; - } - - if ((uint32_t)wr_addr + wr_qty > 0xffffu) - { - return NXMB_EX_ILLEGAL_DATA_ADDRESS; - } - - /* Verify total request data length matches header + write payload */ - - if (data_len != (uint16_t)(NXMB_FC23_WR_DATA_OFF + wr_bcnt)) - { - return NXMB_EX_ILLEGAL_DATA_VALUE; - } - - /* Response is byte_count + read register data โ€” must fit in adu.data[] */ - - if (1 + rd_qty * 2 > NXMB_ADU_DATA_MAX) - { - return NXMB_EX_ILLEGAL_DATA_VALUE; - } - - ret = ctx->callbacks->holding_cb(&ctx->adu.data[NXMB_FC23_WR_DATA_OFF], - wr_addr, wr_qty, NXMB_REG_WRITE, - ctx->callbacks->priv); - if (ret != 0) - { - return nxmb_cb_ret_to_exception(ret); - } - - /* Build response: byte_count + read register data, overwriting request */ - - ctx->adu.fc = NXMB_FC_READWRITE_HOLDINGS; - rd_bcnt = rd_qty * 2; - ctx->adu.data[0] = (uint8_t)rd_bcnt; - - ret = ctx->callbacks->holding_cb(&ctx->adu.data[1], rd_addr, rd_qty, - NXMB_REG_READ, ctx->callbacks->priv); - if (ret != 0) - { - return nxmb_cb_ret_to_exception(ret); - } - - ctx->adu.length = (uint16_t)(2 + 1 + rd_bcnt); - return NXMB_EX_NONE; -} diff --git a/industry/nxmodbus/core/nxmb_func_input.c b/industry/nxmodbus/core/nxmb_func_input.c deleted file mode 100644 index 151d2510b..000000000 --- a/industry/nxmodbus/core/nxmb_func_input.c +++ /dev/null @@ -1,115 +0,0 @@ -/**************************************************************************** - * apps/industry/nxmodbus/core/nxmb_func_input.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include - -#include - -#include - -#include "nxmb_internal.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* FC04 Read Input Registers โ€” offsets in adu.data[], lengths are data - * only - */ - -#define NXMB_FC04_ADDR_OFF 0 -#define NXMB_FC04_QTY_OFF 2 -#define NXMB_FC04_REQ_DATA_LEN 4 - -/* Maximum register quantity per Modbus specification */ - -#define NXMB_REG_READ_QTY_MAX 125 /* 0x007D */ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: nxmb_fc04_read_input - ****************************************************************************/ - -enum nxmb_exception_e nxmb_fc04_read_input(nxmb_handle_t ctx) -{ - uint16_t data_len = ctx->adu.length - 2; - uint16_t addr; - uint16_t qty; - uint8_t nbytes; - int ret; - - if (data_len != NXMB_FC04_REQ_DATA_LEN) - { - return NXMB_EX_ILLEGAL_DATA_VALUE; - } - - if (ctx->callbacks == NULL || ctx->callbacks->input_cb == NULL) - { - return NXMB_EX_ILLEGAL_FUNCTION; - } - - addr = nxmb_util_get_u16_be(&ctx->adu.data[NXMB_FC04_ADDR_OFF]); - qty = nxmb_util_get_u16_be(&ctx->adu.data[NXMB_FC04_QTY_OFF]); - - if (qty < 1 || qty > NXMB_REG_READ_QTY_MAX) - { - return NXMB_EX_ILLEGAL_DATA_VALUE; - } - - if ((uint32_t)addr + qty > 0xffffu) - { - return NXMB_EX_ILLEGAL_DATA_ADDRESS; - } - - nbytes = (uint8_t)(qty * 2); - - /* Response is byte_count + register data */ - - if (1 + nbytes > NXMB_ADU_DATA_MAX) - { - return NXMB_EX_ILLEGAL_DATA_VALUE; - } - - /* Build response: byte_count + register data (big-endian) */ - - ctx->adu.fc = NXMB_FC_READ_INPUT; - ctx->adu.data[0] = nbytes; - - ret = ctx->callbacks->input_cb(&ctx->adu.data[1], addr, qty, - ctx->callbacks->priv); - if (ret != 0) - { - return nxmb_cb_ret_to_exception(ret); - } - - ctx->adu.length = (uint16_t)(2 + 1 + nbytes); - return NXMB_EX_NONE; -} diff --git a/industry/nxmodbus/core/nxmb_func_other.c b/industry/nxmodbus/core/nxmb_func_other.c deleted file mode 100644 index 5827026df..000000000 --- a/industry/nxmodbus/core/nxmb_func_other.c +++ /dev/null @@ -1,99 +0,0 @@ -/**************************************************************************** - * apps/industry/nxmodbus/core/nxmb_func_other.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include - -#include -#include - -#include - -#include "nxmb_internal.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define NXMB_REPORT_ID_REQ_DATA_LEN 0 - -/* Run indicator status */ - -#define NXMB_RUN_STATUS_ON 0xff -#define NXMB_RUN_STATUS_OFF 0x00 - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: nxmb_fc17_report_server_id - * - * Description: - * Handle FC17 (0x11) Report Server ID request. Returns the configured - * unit ID and a run indicator byte (0xFF = ON). - * - ****************************************************************************/ - -enum nxmb_exception_e nxmb_fc17_report_server_id(nxmb_handle_t ctx) -{ - uint16_t data_len = ctx->adu.length - 2; - - if (data_len != NXMB_REPORT_ID_REQ_DATA_LEN) - { - return NXMB_EX_ILLEGAL_DATA_VALUE; - } - - /* If the application configured server ID data via nxmb_set_server_id(), - * use that; otherwise fall back to unit_id + run status ON. - */ - - ctx->adu.fc = NXMB_FC_REPORT_SERVER_ID; - - if (ctx->server_id_len > 0) - { - /* Response is byte_count + server_id_buf */ - - if (1 + ctx->server_id_len > NXMB_ADU_DATA_MAX) - { - return NXMB_EX_DEVICE_FAILURE; - } - - ctx->adu.data[0] = (uint8_t)ctx->server_id_len; - memcpy(&ctx->adu.data[1], ctx->server_id_buf, ctx->server_id_len); - ctx->adu.length = (uint16_t)(2 + 1 + ctx->server_id_len); - } - else - { - ctx->adu.data[0] = 2; /* byte count */ - ctx->adu.data[1] = ctx->unit_id; /* server ID */ - ctx->adu.data[2] = NXMB_RUN_STATUS_ON; /* run indicator */ - ctx->adu.length = (uint16_t)(2 + 3); - } - - return NXMB_EX_NONE; -} diff --git a/industry/nxmodbus/core/nxmb_server.c b/industry/nxmodbus/core/nxmb_server.c deleted file mode 100644 index 4168b53f2..000000000 --- a/industry/nxmodbus/core/nxmb_server.c +++ /dev/null @@ -1,121 +0,0 @@ -/**************************************************************************** - * apps/industry/nxmodbus/core/nxmb_server.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include - -#include -#include -#include -#include - -#include - -#include "nxmb_internal.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define NXMB_FUNC_ERROR 0x80 - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: nxmb_poll - * - * Description: - * Poll for Modbus events and process received frames. - * - * Input Parameters: - * handle - Instance handle - * - * Returned Value: - * 0 on success, negative errno on failure - * - ****************************************************************************/ - -int nxmb_poll(nxmb_handle_t ctx) -{ - uint8_t rcv_address; - int ret; - - DEBUGASSERT(ctx && ctx->transport_ops && ctx->transport_ops->receive); - - pthread_mutex_lock(&ctx->lock); - - if (!ctx->enabled) - { - pthread_mutex_unlock(&ctx->lock); - return -EAGAIN; - } - - ret = ctx->transport_ops->receive(ctx); - if (ret < 0) - { - pthread_mutex_unlock(&ctx->lock); - return ret; - } - - if (ret == 0 || ctx->adu.length == 0) - { - pthread_mutex_unlock(&ctx->lock); - return 0; - } - - rcv_address = ctx->adu.unit_id; - - if (rcv_address != NXMB_ADDRESS_BROADCAST && rcv_address != ctx->unit_id) - { - pthread_mutex_unlock(&ctx->lock); - return 0; - } - - /* Dispatch to function code handler. Handlers mutate ctx->adu in place, - * turning the request into the response. - */ - - ret = nxmb_dispatch_function(ctx); - - if (rcv_address != NXMB_ADDRESS_BROADCAST) - { - if (ctx->transport_ops->send != NULL) - { - ret = ctx->transport_ops->send(ctx); - if (ret < 0) - { - pthread_mutex_unlock(&ctx->lock); - return ret; - } - } - } - - pthread_mutex_unlock(&ctx->lock); - return 0; -} diff --git a/industry/nxmodbus/core/nxmb_utils.c b/industry/nxmodbus/core/nxmb_utils.c deleted file mode 100644 index 016d370c5..000000000 --- a/industry/nxmodbus/core/nxmb_utils.c +++ /dev/null @@ -1,127 +0,0 @@ -/**************************************************************************** - * apps/industry/nxmodbus/core/nxmb_utils.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include - -#include - -#include "nxmb_internal.h" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: nxmb_util_set_bits - * - * Description: - * Set bits in a byte buffer. - * - * Input Parameters: - * buf - Byte buffer - * bit_offset - Bit offset from start of buffer - * nbits - Number of bits to set (max 8) - * value - Value to set - * - * Returned Value: - * None - * - ****************************************************************************/ - -void nxmb_util_set_bits(FAR uint8_t *buf, uint16_t bit_offset, uint8_t nbits, - uint8_t value) -{ - uint16_t word_buf; - uint16_t mask; - uint16_t byte_offset; - uint16_t pre_bits; - uint16_t val = value; - - byte_offset = bit_offset / 8; - pre_bits = bit_offset - (byte_offset * 8); - - val <<= pre_bits; - mask = (uint16_t)((1 << nbits) - 1); - mask <<= pre_bits; - - word_buf = buf[byte_offset]; - if (pre_bits + nbits > 8) - { - word_buf |= buf[byte_offset + 1] << 8; - } - - word_buf = (word_buf & (~mask)) | val; - - buf[byte_offset] = (uint8_t)(word_buf & 0xff); - if (pre_bits + nbits > 8) - { - buf[byte_offset + 1] = (uint8_t)(word_buf >> 8); - } -} - -/**************************************************************************** - * Name: nxmb_util_get_bits - * - * Description: - * Get bits from a byte buffer. - * - * Input Parameters: - * buf - Byte buffer - * bit_offset - Bit offset from start of buffer - * nbits - Number of bits to get (max 8) - * - * Returned Value: - * Bit value - * - ****************************************************************************/ - -uint8_t nxmb_util_get_bits(FAR const uint8_t *buf, uint16_t bit_offset, - uint8_t nbits) -{ - uint16_t word_buf; - uint16_t mask; - uint16_t byte_offset; - uint16_t pre_bits; - - byte_offset = bit_offset / 8; - pre_bits = bit_offset - (byte_offset * 8); - - mask = (uint16_t)((1 << nbits) - 1); - - word_buf = buf[byte_offset]; - if (pre_bits + nbits > 8) - { - word_buf |= buf[byte_offset + 1] << 8; - } - - word_buf >>= pre_bits; - word_buf &= mask; - - return (uint8_t)word_buf; -} - diff --git a/industry/nxmodbus/nxmb_internal.h b/industry/nxmodbus/nxmb_internal.h deleted file mode 100644 index 6e781bd04..000000000 --- a/industry/nxmodbus/nxmb_internal.h +++ /dev/null @@ -1,379 +0,0 @@ -/**************************************************************************** - * apps/industry/nxmodbus/nxmb_internal.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __APPS_INDUSTRY_NXMODBUS_NXMB_INTERNAL_H -#define __APPS_INDUSTRY_NXMODBUS_NXMB_INTERNAL_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -#include -#include -#include -#include -#include - -#include - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -/* Pre-processor Definitions */ - -#define NXMB_ADDRESS_BROADCAST 0 - -/* Modbus function codes */ - -#define NXMB_FC_READ_COILS 0x01 -#define NXMB_FC_READ_DISCRETE 0x02 -#define NXMB_FC_READ_HOLDING 0x03 -#define NXMB_FC_READ_INPUT 0x04 -#define NXMB_FC_WRITE_COIL 0x05 -#define NXMB_FC_WRITE_HOLDING 0x06 -#define NXMB_FC_DIAGNOSTICS 0x08 -#define NXMB_FC_WRITE_COILS 0x0f -#define NXMB_FC_WRITE_HOLDINGS 0x10 -#define NXMB_FC_REPORT_SERVER_ID 0x11 -#define NXMB_FC_READWRITE_HOLDINGS 0x17 - -/* Transport operations interface. - * - * receive() must not block indefinitely. Implementations should use an - * internal timeout (e.g. select()) and return 0 or -EAGAIN when no - * complete frame is available yet. The client polling loop relies on - * this to enforce its own response timeout. - */ - -struct nxmb_transport_ops_s -{ - CODE int (*init)(nxmb_handle_t ctx); - CODE int (*deinit)(nxmb_handle_t ctx); - CODE int (*send)(nxmb_handle_t ctx); - CODE int (*receive)(nxmb_handle_t ctx); -}; - -/* Custom function code handler */ - -struct nxmb_custom_fc_s -{ - FAR struct nxmb_custom_fc_s *next; - nxmb_custom_fc_handler_t handler; - uint8_t fc; -}; - -/* NxModbus instance context */ - -struct nxmb_context_s -{ - FAR const struct nxmb_callbacks_s *callbacks; - FAR const struct nxmb_transport_ops_s *transport_ops; - enum nxmb_mode_e mode; - pthread_mutex_t lock; - uint8_t unit_id; - bool is_client; - bool enabled; - - /* Transport configuration */ - - union nxmb_transport_config_u transport_cfg; - - /* Single ADU container reused for both RX and TX. Modbus is half-duplex, - * so request and response never coexist: handlers mutate the request - * in place to form the response. - */ - - struct nxmb_adu_s adu; - - /* Report Server ID (FC17) data */ - - uint8_t server_id_buf[CONFIG_NXMODBUS_REP_SERVER_ID_BUF]; - uint16_t server_id_len; - - /* Custom handlers */ - - FAR struct nxmb_custom_fc_s *custom_fc_list; - FAR void *transport_state; - FAR void *client_state; -}; - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -#ifdef CONFIG_NXMODBUS_RTU -extern const struct nxmb_transport_ops_s g_nxmb_serial_ops; -#endif - -#ifdef CONFIG_NXMODBUS_ASCII -extern const struct nxmb_transport_ops_s g_nxmb_ascii_ops; -#endif - -#ifdef CONFIG_NXMODBUS_RAW_ADU -extern const struct nxmb_transport_ops_s g_nxmb_raw_ops; -#endif - -#ifdef CONFIG_NXMODBUS_TCP -extern const struct nxmb_transport_ops_s g_nxmb_tcp_ops; -#endif - -/**************************************************************************** - * Inline Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: nxmb_cb_ret_to_exception - * - * Description: - * Map a callback return value to a Modbus exception code. - * - * -ENOENT -> address not supported by the application - * anything else -> generic device failure - * - ****************************************************************************/ - -static inline enum nxmb_exception_e nxmb_cb_ret_to_exception(int ret) -{ - if (ret == -ENOENT) - { - return NXMB_EX_ILLEGAL_DATA_ADDRESS; - } - - return NXMB_EX_DEVICE_FAILURE; -} - -/**************************************************************************** - * Name: nxmb_util_get_u16_be - * - * Description: - * Extract a big-endian 16-bit value from a buffer. - * - ****************************************************************************/ - -static inline uint16_t nxmb_util_get_u16_be(FAR const uint8_t *buf) -{ - return (uint16_t)((buf[0] << 8) | buf[1]); -} - -/**************************************************************************** - * Name: nxmb_util_put_u16_be - * - * Description: - * Store a 16-bit value as big-endian in a buffer. - * - ****************************************************************************/ - -static inline void nxmb_util_put_u16_be(FAR uint8_t *buf, uint16_t value) -{ - buf[0] = (uint8_t)(value >> 8); - buf[1] = (uint8_t)(value & 0xff); -} - -/**************************************************************************** - * Name: nxmb_util_clock_ms - * - * Description: - * Return the current monotonic clock value in milliseconds. - * - ****************************************************************************/ - -static inline uint64_t nxmb_util_clock_ms(void) -{ - struct timespec ts; - - clock_gettime(CLOCK_MONOTONIC, &ts); - return ts.tv_sec * 1000 + ts.tv_nsec / 1000000; -} - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -#ifdef CONFIG_SERIAL_TERMIOS -/**************************************************************************** - * Name: nxmb_serial_configure - * - * Description: - * Configure serial port with termios settings for Modbus communication. - * Shared by RTU and ASCII transports. - * - * Input Parameters: - * fd - File descriptor - * baudrate - Baud rate - * parity - Parity setting - * - * Returned Value: - * Zero on success; a negated errno value on failure - * - ****************************************************************************/ - -int nxmb_serial_configure(int fd, uint32_t baudrate, - enum nxmb_parity_e parity); -#endif - -/**************************************************************************** - * Name: nxmb_util_set_bits - * - * Description: - * Set up to 8 bits in a byte buffer at the given bit offset. - * - * Input Parameters: - * buf - Byte buffer - * bit_offset - Bit offset from start of buffer - * nbits - Number of bits to set (max 8) - * value - Bit values to write - * - ****************************************************************************/ - -void nxmb_util_set_bits(FAR uint8_t *buf, uint16_t bit_offset, uint8_t nbits, - uint8_t value); - -/**************************************************************************** - * Name: nxmb_util_get_bits - * - * Description: - * Extract up to 8 bits from a byte buffer at the given bit offset. - * - * Input Parameters: - * buf - Byte buffer - * bit_offset - Bit offset from start of buffer - * nbits - Number of bits to extract (max 8) - * - * Returned Value: - * Extracted bit values - * - ****************************************************************************/ - -uint8_t nxmb_util_get_bits(FAR const uint8_t *buf, uint16_t bit_offset, - uint8_t nbits); - -#ifdef CONFIG_NXMODBUS_RTU -/**************************************************************************** - * Name: nxmb_crc16 - * - * Description: - * Calculate Modbus RTU CRC16 checksum. - * - * Input Parameters: - * buf - Pointer to data buffer - * len - Length of data in bytes - * - * Returned Value: - * CRC16 value - * - ****************************************************************************/ - -uint16_t nxmb_crc16(FAR const uint8_t *buf, uint16_t len); -#endif - -#ifdef CONFIG_NXMODBUS_ASCII -/**************************************************************************** - * Name: nxmb_lrc - * - * Description: - * Calculate Modbus ASCII LRC checksum. - * - * Input Parameters: - * buf - Pointer to data buffer - * len - Length of data in bytes - * - * Returned Value: - * LRC value (8-bit) - * - ****************************************************************************/ - -uint8_t nxmb_lrc(FAR const uint8_t *buf, uint16_t len); -#endif - -#ifdef CONFIG_NXMODBUS_CLIENT -/**************************************************************************** - * Name: nxmb_client_init - * - * Description: - * Initialize client state for master mode. - * - * Input Parameters: - * ctx - Instance context - * - * Returned Value: - * Zero on success; a negated errno value on failure - * - ****************************************************************************/ - -int nxmb_client_init(nxmb_handle_t ctx); - -/**************************************************************************** - * Name: nxmb_client_deinit - * - * Description: - * Deinitialize client state. - * - * Input Parameters: - * ctx - Instance context - * - * Returned Value: - * Zero on success; a negated errno value on failure - * - ****************************************************************************/ - -int nxmb_client_deinit(nxmb_handle_t ctx); -#endif - -/**************************************************************************** - * Name: nxmb_dispatch_function - * - * Description: - * Dispatch a Modbus function code to the appropriate handler. Operates - * in place on ctx->adu. - * - * Input Parameters: - * ctx - Instance context - * - * Returned Value: - * Zero on success; a negated errno value on failure - * - ****************************************************************************/ - -int nxmb_dispatch_function(nxmb_handle_t ctx); - -/* Function-code handlers operate on ctx->adu in place: they read the - * request from adu.fc/adu.data[]/adu.length and overwrite those fields - * with the response. - */ - -enum nxmb_exception_e nxmb_fc01_read_coils(nxmb_handle_t ctx); -enum nxmb_exception_e nxmb_fc02_read_discrete(nxmb_handle_t ctx); -enum nxmb_exception_e nxmb_fc05_write_coil(nxmb_handle_t ctx); -enum nxmb_exception_e nxmb_fc15_write_coils(nxmb_handle_t ctx); -enum nxmb_exception_e nxmb_fc03_read_holding(nxmb_handle_t ctx); -enum nxmb_exception_e nxmb_fc04_read_input(nxmb_handle_t ctx); -enum nxmb_exception_e nxmb_fc06_write_holding(nxmb_handle_t ctx); -enum nxmb_exception_e nxmb_fc16_write_holdings(nxmb_handle_t ctx); -enum nxmb_exception_e nxmb_fc23_readwrite_holding(nxmb_handle_t ctx); -enum nxmb_exception_e nxmb_fc08_diagnostics(nxmb_handle_t ctx); -enum nxmb_exception_e nxmb_fc17_report_server_id(nxmb_handle_t ctx); - -#endif /* __APPS_INDUSTRY_NXMODBUS_NXMB_INTERNAL_H */ diff --git a/industry/nxmodbus/transport/nxmb_ascii.c b/industry/nxmodbus/transport/nxmb_ascii.c deleted file mode 100644 index 668a89821..000000000 --- a/industry/nxmodbus/transport/nxmb_ascii.c +++ /dev/null @@ -1,550 +0,0 @@ -/**************************************************************************** - * apps/industry/nxmodbus/transport/nxmb_ascii.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#ifdef CONFIG_SERIAL_TERMIOS -# include -#endif - -#include - -#include "nxmb_internal.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define NXMB_ASCII_START_CHAR ':' -#define NXMB_ASCII_CR '\r' -#define NXMB_ASCII_LF '\n' - -/* Serialized binary frame: unit_id(1) + fc(1) + data + LRC(1) */ - -#define NXMB_ASCII_BIN_MAX (NXMB_ADU_DATA_MAX + 3) - -/* Hex-encoded ASCII frame: ':' + 2*bin + CR + LF */ - -#define NXMB_ASCII_BUFLEN (NXMB_ASCII_BIN_MAX * 2 + 4) - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -struct nxmb_ascii_state_s -{ - int fd; - uint8_t rx_buf[NXMB_ASCII_BUFLEN]; - uint16_t rx_pos; - bool in_frame; -#ifdef CONFIG_SERIAL_TERMIOS - struct termios old_tio; -#endif -}; - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -static int nxmb_ascii_char_to_hex(char c); -static char nxmb_ascii_hex_to_char(uint8_t nibble); -static uint16_t nxmb_ascii_encode(FAR const uint8_t *bin, uint16_t bin_len, - FAR char *ascii); -static int nxmb_ascii_decode(FAR const char *ascii, uint16_t ascii_len, - FAR uint8_t *bin); -static int nxmb_ascii_init(nxmb_handle_t ctx); -static int nxmb_ascii_deinit(nxmb_handle_t ctx); -static int nxmb_ascii_send(nxmb_handle_t ctx); -static int nxmb_ascii_receive(nxmb_handle_t ctx); - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -const struct nxmb_transport_ops_s g_nxmb_ascii_ops = -{ - .init = nxmb_ascii_init, - .deinit = nxmb_ascii_deinit, - .send = nxmb_ascii_send, - .receive = nxmb_ascii_receive -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: nxmb_ascii_char_to_hex - * - * Description: - * Convert ASCII hex character to binary nibble. - * - * Input Parameters: - * c - ASCII hex character - * - * Returned Value: - * Binary value 0-15, or -1 on error - * - ****************************************************************************/ - -static int nxmb_ascii_char_to_hex(char c) -{ - if (c >= '0' && c <= '9') - { - return c - '0'; - } - else if (c >= 'A' && c <= 'F') - { - return c - 'A' + 10; - } - else if (c >= 'a' && c <= 'f') - { - return c - 'a' + 10; - } - - return -1; -} - -/**************************************************************************** - * Name: nxmb_ascii_hex_to_char - * - * Description: - * Convert binary nibble to ASCII hex character. - * - * Input Parameters: - * nibble - Binary value 0-15 - * - * Returned Value: - * ASCII hex character - * - ****************************************************************************/ - -static char nxmb_ascii_hex_to_char(uint8_t nibble) -{ - if (nibble < 10) - { - return '0' + nibble; - } - else - { - return 'A' + (nibble - 10); - } -} - -/**************************************************************************** - * Name: nxmb_ascii_encode - * - * Description: - * Encode binary data to ASCII hex string. - * - * Input Parameters: - * bin - Binary data - * bin_len - Binary data length - * ascii - Output ASCII buffer - * - * Returned Value: - * ASCII string length - * - ****************************************************************************/ - -static uint16_t nxmb_ascii_encode(FAR const uint8_t *bin, uint16_t bin_len, - FAR char *ascii) -{ - uint16_t pos = 0; - uint16_t i; - - for (i = 0; i < bin_len; i++) - { - ascii[pos++] = nxmb_ascii_hex_to_char(bin[i] >> 4); - ascii[pos++] = nxmb_ascii_hex_to_char(bin[i] & 0x0f); - } - - return pos; -} - -/**************************************************************************** - * Name: nxmb_ascii_decode - * - * Description: - * Decode ASCII hex string to binary data. - * - * Input Parameters: - * ascii - ASCII hex string - * ascii_len - ASCII string length (must be even) - * bin - Output binary buffer - * - * Returned Value: - * Binary data length, or negative errno on error - * - ****************************************************************************/ - -static int nxmb_ascii_decode(FAR const char *ascii, uint16_t ascii_len, - FAR uint8_t *bin) -{ - uint16_t i; - int high; - int low; - - if (ascii_len % 2 != 0) - { - return -EINVAL; - } - - for (i = 0; i < ascii_len; i += 2) - { - high = nxmb_ascii_char_to_hex(ascii[i]); - low = nxmb_ascii_char_to_hex(ascii[i + 1]); - - if (high < 0 || low < 0) - { - return -EINVAL; - } - - bin[i / 2] = (high << 4) | low; - } - - return ascii_len / 2; -} - -/**************************************************************************** - * Name: nxmb_ascii_init - * - * Description: - * Initialize serial ASCII transport. - * - * Input Parameters: - * ctx - Instance context - * - * Returned Value: - * Zero on success; a negated errno value on failure - * - ****************************************************************************/ - -static int nxmb_ascii_init(nxmb_handle_t ctx) -{ - FAR struct nxmb_ascii_state_s *state; - FAR const struct nxmb_serial_config_s *cfg; - int ret; - - DEBUGASSERT(ctx); - - cfg = &ctx->transport_cfg.serial; - - if (cfg->devpath == NULL) - { - return -EINVAL; - } - - state = calloc(1, sizeof(struct nxmb_ascii_state_s)); - if (state == NULL) - { - return -ENOMEM; - } - - state->fd = open(cfg->devpath, O_RDWR | O_NOCTTY); - if (state->fd < 0) - { - ret = -errno; - free(state); - return ret; - } - -#ifdef CONFIG_SERIAL_TERMIOS - if (tcgetattr(state->fd, &state->old_tio) < 0) - { - ret = -errno; - close(state->fd); - free(state); - return ret; - } - - ret = nxmb_serial_configure(state->fd, cfg->baudrate, cfg->parity); - if (ret < 0) - { - close(state->fd); - free(state); - return ret; - } -#endif - - state->rx_pos = 0; - state->in_frame = false; - - ctx->transport_state = state; - - return 0; -} - -/**************************************************************************** - * Name: nxmb_ascii_deinit - * - * Description: - * Deinitialize serial ASCII transport. - * - * Input Parameters: - * ctx - Instance context - * - * Returned Value: - * Zero on success; a negated errno value on failure - * - ****************************************************************************/ - -static int nxmb_ascii_deinit(nxmb_handle_t ctx) -{ - FAR struct nxmb_ascii_state_s *state; - - DEBUGASSERT(ctx && ctx->transport_state); - - state = ctx->transport_state; - -#ifdef CONFIG_SERIAL_TERMIOS - tcsetattr(state->fd, TCSANOW, &state->old_tio); -#endif - close(state->fd); - free(state); - - ctx->transport_state = NULL; - - return 0; -} - -/**************************************************************************** - * Name: nxmb_ascii_send - * - * Description: - * Send ASCII frame over serial port. - * - * Input Parameters: - * ctx - Instance context - * - * Returned Value: - * Zero on success; a negated errno value on failure - * - ****************************************************************************/ - -static int nxmb_ascii_send(nxmb_handle_t ctx) -{ - FAR struct nxmb_ascii_state_s *state; - uint8_t bin[NXMB_ASCII_BIN_MAX]; - char tx_buf[NXMB_ASCII_BUFLEN]; - uint16_t data_len; - uint16_t pos = 0; - uint8_t lrc; - ssize_t written; - - DEBUGASSERT(ctx && ctx->transport_state); - - state = ctx->transport_state; - - if (ctx->adu.length < 2) - { - return -EINVAL; - } - - data_len = ctx->adu.length - 2; - - /* Linearize the ADU into the wire byte order: unit_id, fc, data... */ - - bin[0] = ctx->adu.unit_id; - bin[1] = ctx->adu.fc; - memcpy(&bin[2], ctx->adu.data, data_len); - - lrc = nxmb_lrc(bin, ctx->adu.length); - ctx->adu.crc = lrc; - - tx_buf[pos++] = NXMB_ASCII_START_CHAR; - pos += nxmb_ascii_encode(bin, ctx->adu.length, &tx_buf[pos]); - tx_buf[pos++] = nxmb_ascii_hex_to_char(lrc >> 4); - tx_buf[pos++] = nxmb_ascii_hex_to_char(lrc & 0x0f); - tx_buf[pos++] = NXMB_ASCII_CR; - tx_buf[pos++] = NXMB_ASCII_LF; - - written = write(state->fd, tx_buf, pos); - - if (written < 0) - { - return -errno; - } - - if (written != pos) - { - return -EIO; - } - - return 0; -} - -/**************************************************************************** - * Name: nxmb_ascii_receive - * - * Description: - * Receive ASCII frame from serial port. - * - * Input Parameters: - * ctx - Instance context - * - * Returned Value: - * Zero on success; a negated errno value on failure - * - ****************************************************************************/ - -static int nxmb_ascii_receive(nxmb_handle_t ctx) -{ - FAR struct nxmb_ascii_state_s *state; - uint8_t bin[NXMB_ASCII_BIN_MAX]; - struct timeval timeout; - fd_set readfds; - ssize_t nread; - uint8_t c; - uint8_t lrc_calc; - uint8_t lrc_recv; - int ret; - int bin_len; - - DEBUGASSERT(ctx && ctx->transport_state); - - state = ctx->transport_state; - - FD_ZERO(&readfds); - FD_SET(state->fd, &readfds); - - timeout.tv_sec = CONFIG_NXMODBUS_ASCII_TIMEOUT_SEC; - timeout.tv_usec = 0; - - ret = select(state->fd + 1, &readfds, NULL, NULL, &timeout); - - if (ret < 0) - { - return -errno; - } - - if (ret == 0) - { - return 0; - } - - if (!FD_ISSET(state->fd, &readfds)) - { - return 0; - } - - nread = read(state->fd, &c, 1); - if (nread < 0) - { - return -errno; - } - - if (nread == 0) - { - return 0; - } - - if (c == NXMB_ASCII_START_CHAR) - { - state->rx_pos = 0; - state->in_frame = true; - return 0; - } - - if (!state->in_frame) - { - return 0; - } - - if (c == NXMB_ASCII_LF) - { - state->in_frame = false; - - /* Minimum valid frame: addr(2) + func(2) + lrc(2) + CR = 7 chars. - * Maximum valid frame: NXMB_ASCII_BIN_MAX hex pairs + CR. Reject - * anything larger so the decoded length fits bin[]. - */ - - if (state->rx_pos < 7 || - state->rx_pos > NXMB_ASCII_BIN_MAX * 2 + 1 || - state->rx_buf[state->rx_pos - 1] != NXMB_ASCII_CR) - { - state->rx_pos = 0; - return 0; - } - - /* Decode all hex chars (exclude CR) into a temp binary buffer. - * Layout: unit_id + fc + data... + LRC. - */ - - bin_len = nxmb_ascii_decode((FAR const char *)state->rx_buf, - state->rx_pos - 1, bin); - - if (bin_len < 3) - { - state->rx_pos = 0; - return 0; - } - - lrc_calc = nxmb_lrc(bin, bin_len - 1); - lrc_recv = bin[bin_len - 1]; - - if (lrc_calc != lrc_recv) - { - state->rx_pos = 0; - return 0; - } - - /* Unpack into ctx->adu. Length excludes LRC. */ - - ctx->adu.unit_id = bin[0]; - ctx->adu.fc = bin[1]; - memcpy(ctx->adu.data, &bin[2], (bin_len - 3)); - ctx->adu.crc = lrc_recv; - ctx->adu.length = (bin_len - 1); - - state->rx_pos = 0; - - return 1; - } - - if (state->rx_pos < sizeof(state->rx_buf)) - { - state->rx_buf[state->rx_pos++] = c; - } - else - { - state->in_frame = false; - state->rx_pos = 0; - } - - return 0; -} diff --git a/industry/nxmodbus/transport/nxmb_crc.c b/industry/nxmodbus/transport/nxmb_crc.c deleted file mode 100644 index abfffffb4..000000000 --- a/industry/nxmodbus/transport/nxmb_crc.c +++ /dev/null @@ -1,108 +0,0 @@ -/**************************************************************************** - * apps/industry/nxmodbus/transport/nxmb_crc.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include - -#include - -#include "nxmb_internal.h" - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static const uint16_t g_crc16_table[256] = -{ - 0x0000, 0xc0c1, 0xc181, 0x0140, 0xc301, 0x03c0, 0x0280, 0xc241, 0xc601, - 0x06c0, 0x0780, 0xc741, 0x0500, 0xc5c1, 0xc481, 0x0440, 0xcc01, 0x0cc0, - 0x0d80, 0xcd41, 0x0f00, 0xcfc1, 0xce81, 0x0e40, 0x0a00, 0xcac1, 0xcb81, - 0x0b40, 0xc901, 0x09c0, 0x0880, 0xc841, 0xd801, 0x18c0, 0x1980, 0xd941, - 0x1b00, 0xdbc1, 0xda81, 0x1a40, 0x1e00, 0xdec1, 0xdf81, 0x1f40, 0xdd01, - 0x1dc0, 0x1c80, 0xdc41, 0x1400, 0xd4c1, 0xd581, 0x1540, 0xd701, 0x17c0, - 0x1680, 0xd641, 0xd201, 0x12c0, 0x1380, 0xd341, 0x1100, 0xd1c1, 0xd081, - 0x1040, 0xf001, 0x30c0, 0x3180, 0xf141, 0x3300, 0xf3c1, 0xf281, 0x3240, - 0x3600, 0xf6c1, 0xf781, 0x3740, 0xf501, 0x35c0, 0x3480, 0xf441, 0x3c00, - 0xfcc1, 0xfd81, 0x3d40, 0xff01, 0x3fc0, 0x3e80, 0xfe41, 0xfa01, 0x3ac0, - 0x3b80, 0xfb41, 0x3900, 0xf9c1, 0xf881, 0x3840, 0x2800, 0xe8c1, 0xe981, - 0x2940, 0xeb01, 0x2bc0, 0x2a80, 0xea41, 0xee01, 0x2ec0, 0x2f80, 0xef41, - 0x2d00, 0xedc1, 0xec81, 0x2c40, 0xe401, 0x24c0, 0x2580, 0xe541, 0x2700, - 0xe7c1, 0xe681, 0x2640, 0x2200, 0xe2c1, 0xe381, 0x2340, 0xe101, 0x21c0, - 0x2080, 0xe041, 0xa001, 0x60c0, 0x6180, 0xa141, 0x6300, 0xa3c1, 0xa281, - 0x6240, 0x6600, 0xa6c1, 0xa781, 0x6740, 0xa501, 0x65c0, 0x6480, 0xa441, - 0x6c00, 0xacc1, 0xad81, 0x6d40, 0xaf01, 0x6fc0, 0x6e80, 0xae41, 0xaa01, - 0x6ac0, 0x6b80, 0xab41, 0x6900, 0xa9c1, 0xa881, 0x6840, 0x7800, 0xb8c1, - 0xb981, 0x7940, 0xbb01, 0x7bc0, 0x7a80, 0xba41, 0xbe01, 0x7ec0, 0x7f80, - 0xbf41, 0x7d00, 0xbdc1, 0xbc81, 0x7c40, 0xb401, 0x74c0, 0x7580, 0xb541, - 0x7700, 0xb7c1, 0xb681, 0x7640, 0x7200, 0xb2c1, 0xb381, 0x7340, 0xb101, - 0x71c0, 0x7080, 0xb041, 0x5000, 0x90c1, 0x9181, 0x5140, 0x9301, 0x53c0, - 0x5280, 0x9241, 0x9601, 0x56c0, 0x5780, 0x9741, 0x5500, 0x95c1, 0x9481, - 0x5440, 0x9c01, 0x5cc0, 0x5d80, 0x9d41, 0x5f00, 0x9fc1, 0x9e81, 0x5e40, - 0x5a00, 0x9ac1, 0x9b81, 0x5b40, 0x9901, 0x59c0, 0x5880, 0x9841, 0x8801, - 0x48c0, 0x4980, 0x8941, 0x4b00, 0x8bc1, 0x8a81, 0x4a40, 0x4e00, 0x8ec1, - 0x8f81, 0x4f40, 0x8d01, 0x4dc0, 0x4c80, 0x8c41, 0x4400, 0x84c1, 0x8581, - 0x4540, 0x8701, 0x47c0, 0x4680, 0x8641, 0x8201, 0x42c0, 0x4380, 0x8341, - 0x4100, 0x81c1, 0x8081, 0x4040 -}; - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: nxmb_crc16 - * - * Description: - * Calculate Modbus RTU CRC16 checksum. - * - * Input Parameters: - * buf - Pointer to data buffer - * len - Length of data in bytes - * - * Returned Value: - * CRC16 value - * - ****************************************************************************/ - -uint16_t nxmb_crc16(FAR const uint8_t *buf, uint16_t len) -{ - uint16_t crc = 0xffff; - uint8_t index; - - if (buf == NULL || len == 0) - { - return crc; - } - - while (len--) - { - index = (crc ^ *buf++); - crc = (crc >> 8) ^ g_crc16_table[index]; - } - - return crc; -} diff --git a/industry/nxmodbus/transport/nxmb_lrc.c b/industry/nxmodbus/transport/nxmb_lrc.c deleted file mode 100644 index 7768c9cb5..000000000 --- a/industry/nxmodbus/transport/nxmb_lrc.c +++ /dev/null @@ -1,70 +0,0 @@ -/**************************************************************************** - * apps/industry/nxmodbus/transport/nxmb_lrc.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include - -#include - -#include "nxmb_internal.h" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: nxmb_lrc - * - * Description: - * Calculate Modbus ASCII LRC checksum. - * - * Input Parameters: - * buf - Pointer to data buffer - * len - Length of data in bytes - * - * Returned Value: - * LRC value (8-bit) - * - ****************************************************************************/ - -uint8_t nxmb_lrc(FAR const uint8_t *buf, uint16_t len) -{ - uint8_t lrc = 0; - uint16_t i; - - if (buf == NULL || len == 0) - { - return lrc; - } - - for (i = 0; i < len; i++) - { - lrc += buf[i]; - } - - return (uint8_t)(-((int8_t)lrc)); -} diff --git a/industry/nxmodbus/transport/nxmb_raw.c b/industry/nxmodbus/transport/nxmb_raw.c deleted file mode 100644 index 8352581fe..000000000 --- a/industry/nxmodbus/transport/nxmb_raw.c +++ /dev/null @@ -1,303 +0,0 @@ -/**************************************************************************** - * apps/industry/nxmodbus/transport/nxmb_raw.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include -#include -#include - -#include -#include - -#include "nxmb_internal.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define MBAP_PROTO_ID 0x0000 - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/* Raw ADU transport state */ - -struct nxmb_raw_state_s -{ - FAR void *user_data; - nxmb_raw_tx_cb_t tx_callback; -}; - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -static int nxmb_raw_init(nxmb_handle_t ctx); -static int nxmb_raw_deinit(nxmb_handle_t ctx); -static int nxmb_raw_send(nxmb_handle_t ctx); -static int nxmb_raw_receive(nxmb_handle_t ctx); - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -const struct nxmb_transport_ops_s g_nxmb_raw_ops = -{ - .init = nxmb_raw_init, - .deinit = nxmb_raw_deinit, - .send = nxmb_raw_send, - .receive = nxmb_raw_receive, -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: nxmb_raw_init - * - * Description: - * Initialize raw ADU transport. - * - * Input Parameters: - * ctx - Instance context - * - * Returned Value: - * Zero on success; a negated errno value on failure - * - ****************************************************************************/ - -static int nxmb_raw_init(nxmb_handle_t ctx) -{ - FAR const struct nxmb_raw_config_s *cfg; - FAR struct nxmb_raw_state_s *state; - - DEBUGASSERT(ctx); - - cfg = &ctx->transport_cfg.raw; - - if (cfg->tx_cb == NULL) - { - return -EINVAL; - } - - state = malloc(sizeof(struct nxmb_raw_state_s)); - if (state == NULL) - { - return -ENOMEM; - } - - state->tx_callback = cfg->tx_cb; - state->user_data = cfg->user_data; - - ctx->transport_state = state; - - return OK; -} - -/**************************************************************************** - * Name: nxmb_raw_deinit - * - * Description: - * Deinitialize raw ADU transport. - * - * Input Parameters: - * ctx - Instance context - * - * Returned Value: - * Zero on success; a negated errno value on failure - * - ****************************************************************************/ - -static int nxmb_raw_deinit(nxmb_handle_t ctx) -{ - DEBUGASSERT(ctx && ctx->transport_state); - - free(ctx->transport_state); - ctx->transport_state = NULL; - - return OK; -} - -/**************************************************************************** - * Name: nxmb_raw_send - * - * Description: - * Send raw ADU via user callback. - * - * Input Parameters: - * ctx - Instance context - * - * Returned Value: - * Zero on success; a negated errno value on failure - * - ****************************************************************************/ - -static int nxmb_raw_send(nxmb_handle_t ctx) -{ - FAR struct nxmb_raw_state_s *state; - int ret; - - DEBUGASSERT(ctx && ctx->transport_state); - - state = ctx->transport_state; - - if (state->tx_callback == NULL) - { - return -EINVAL; - } - - ctx->adu.proto_id = MBAP_PROTO_ID; - - ret = state->tx_callback(&ctx->adu, state->user_data); - if (ret < 0) - { - return ret; - } - - return OK; -} - -/**************************************************************************** - * Name: nxmb_raw_receive - * - * Description: - * Receive raw ADU (not used in raw mode, frames are submitted via - * nxmb_raw_submit_rx). - * - * Input Parameters: - * ctx - Instance context - * - * Returned Value: - * -ENOTSUP (raw mode uses submit pattern, not polling) - * - ****************************************************************************/ - -static int nxmb_raw_receive(nxmb_handle_t ctx) -{ - return -ENOTSUP; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: nxmb_raw_submit_rx - * - * Description: - * Submit a received raw ADU into the NxModbus protocol core. - * - * Input Parameters: - * h - The NxModbus instance receiving the frame - * adu - The received raw ADU container - * - * Returned Value: - * Zero on success; a negated errno value on failure - * - ****************************************************************************/ - -int nxmb_raw_submit_rx(nxmb_handle_t ctx, FAR const struct nxmb_adu_s *adu) -{ - DEBUGASSERT(ctx && adu); - - if (adu->proto_id != MBAP_PROTO_ID) - { - return -EPROTO; - } - - if (adu->length < 2) - { - return -EINVAL; - } - - if ((adu->length - 2) > NXMB_ADU_DATA_MAX) - { - return -EMSGSIZE; - } - - pthread_mutex_lock(&ctx->lock); - ctx->adu = *adu; - pthread_mutex_unlock(&ctx->lock); - - return OK; -} - -/**************************************************************************** - * Name: nxmb_raw_put_header - * - * Description: - * Serialize the 8-byte MBAP+FC header for an ADU. - * - * Input Parameters: - * adu - The ADU providing the header fields - * hdr - The destination buffer for the serialized header - * - * Returned Value: - * None - * - ****************************************************************************/ - -void nxmb_raw_put_header(FAR const struct nxmb_adu_s *adu, FAR uint8_t *hdr) -{ - DEBUGASSERT(adu && hdr); - - nxmb_util_put_u16_be(&hdr[0], adu->trans_id); - nxmb_util_put_u16_be(&hdr[2], adu->proto_id); - nxmb_util_put_u16_be(&hdr[4], adu->length); - hdr[6] = adu->unit_id; - hdr[7] = adu->fc; -} - -/**************************************************************************** - * Name: nxmb_raw_get_header - * - * Description: - * Parse the 8-byte MBAP+FC header into an ADU structure. - * - * Input Parameters: - * adu - The destination ADU structure - * hdr - The source buffer containing the serialized header - * - * Returned Value: - * None - * - ****************************************************************************/ - -void nxmb_raw_get_header(FAR struct nxmb_adu_s *adu, FAR const uint8_t *hdr) -{ - DEBUGASSERT(adu && hdr); - - adu->trans_id = nxmb_util_get_u16_be(&hdr[0]); - adu->proto_id = nxmb_util_get_u16_be(&hdr[2]); - adu->length = nxmb_util_get_u16_be(&hdr[4]); - adu->unit_id = hdr[6]; - adu->fc = hdr[7]; -} diff --git a/industry/nxmodbus/transport/nxmb_serial.c b/industry/nxmodbus/transport/nxmb_serial.c deleted file mode 100644 index 679e0d597..000000000 --- a/industry/nxmodbus/transport/nxmb_serial.c +++ /dev/null @@ -1,423 +0,0 @@ -/**************************************************************************** - * apps/industry/nxmodbus/transport/nxmb_serial.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include - -#include -#include -#include -#include -#include -#include -#include - -#ifdef CONFIG_SERIAL_TERMIOS -# include -#endif - -#include - -#include "nxmb_internal.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define NXMB_RTU_MIN_FRAME_SIZE 5 - -/* Wire frame: unit_id + fc + data + 2 CRC bytes */ - -#define NXMB_RTU_FRAME_MAX (NXMB_ADU_DATA_MAX + 4) - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -struct nxmb_serial_state_s -{ - int fd; - uint32_t t35_usec; - bool rx_frame_now; - uint16_t rx_pos; - uint8_t rx_buf[NXMB_RTU_FRAME_MAX]; -#ifdef CONFIG_SERIAL_TERMIOS - struct termios old_tio; -#endif -}; - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -static uint32_t nxmb_serial_calculate_t35(uint32_t baudrate); -static int nxmb_serial_init(nxmb_handle_t ctx); -static int nxmb_serial_deinit(nxmb_handle_t ctx); -static int nxmb_serial_send(nxmb_handle_t ctx); -static int nxmb_serial_receive(nxmb_handle_t ctx); - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -const struct nxmb_transport_ops_s g_nxmb_serial_ops = -{ - .init = nxmb_serial_init, - .deinit = nxmb_serial_deinit, - .send = nxmb_serial_send, - .receive = nxmb_serial_receive -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: nxmb_serial_calculate_t35 - * - * Description: - * Calculate T3.5 character timeout in microseconds based on baud rate. - * - * Input Parameters: - * baudrate - Serial baud rate - * - * Returned Value: - * T3.5 timeout in microseconds - * - ****************************************************************************/ - -static uint32_t nxmb_serial_calculate_t35(uint32_t baudrate) -{ - if (baudrate <= 19200) - { - /* T3.5 = 3.5 * 11 bits/char * 1e6 us/s / baudrate - * = 38500000 / baudrate (in microseconds). - * Use integer arithmetic to avoid floating-point, which may - * require FPU context save/restore on embedded targets. - */ - - return 38500000u / baudrate; - } - else - { - /* Per Modbus spec, fixed 1750 us for baud rates above 19200 */ - - return 1750; - } -} - -/**************************************************************************** - * Name: nxmb_serial_init - * - * Description: - * Initialize serial RTU transport. - * - * Input Parameters: - * ctx - Instance context - * - * Returned Value: - * Zero on success; a negated errno value on failure - * - ****************************************************************************/ - -static int nxmb_serial_init(nxmb_handle_t ctx) -{ - FAR struct nxmb_serial_state_s *state; - FAR const struct nxmb_serial_config_s *cfg; - int ret; - - DEBUGASSERT(ctx); - - cfg = &ctx->transport_cfg.serial; - - if (cfg->devpath == NULL) - { - return -EINVAL; - } - - state = calloc(1, sizeof(struct nxmb_serial_state_s)); - if (state == NULL) - { - return -ENOMEM; - } - - state->fd = open(cfg->devpath, O_RDWR | O_NOCTTY); - if (state->fd < 0) - { - ret = -errno; - free(state); - return ret; - } - -#ifdef CONFIG_SERIAL_TERMIOS - if (tcgetattr(state->fd, &state->old_tio) < 0) - { - ret = -errno; - close(state->fd); - free(state); - return ret; - } - - ret = nxmb_serial_configure(state->fd, cfg->baudrate, cfg->parity); - - if (ret < 0) - { - close(state->fd); - free(state); - return ret; - } - - tcflush(state->fd, TCIOFLUSH); -#endif - - state->t35_usec = nxmb_serial_calculate_t35(cfg->baudrate); - state->rx_frame_now = false; - - ctx->transport_state = state; - - return 0; -} - -/**************************************************************************** - * Name: nxmb_serial_deinit - * - * Description: - * Deinitialize serial RTU transport. - * - * Input Parameters: - * ctx - Instance context - * - * Returned Value: - * Zero on success; a negated errno value on failure - * - ****************************************************************************/ - -static int nxmb_serial_deinit(nxmb_handle_t ctx) -{ - FAR struct nxmb_serial_state_s *state; - - DEBUGASSERT(ctx && ctx->transport_state); - - state = ctx->transport_state; - -#ifdef CONFIG_SERIAL_TERMIOS - tcsetattr(state->fd, TCSANOW, &state->old_tio); -#endif - close(state->fd); - free(state); - - ctx->transport_state = NULL; - - return 0; -} - -/**************************************************************************** - * Name: nxmb_serial_send - * - * Description: - * Send RTU frame over serial port. - * - * Input Parameters: - * ctx - Instance context - * - * Returned Value: - * Zero on success; a negated errno value on failure - * - ****************************************************************************/ - -static int nxmb_serial_send(nxmb_handle_t ctx) -{ - FAR struct nxmb_serial_state_s *state; - uint8_t frame[NXMB_RTU_FRAME_MAX]; - uint16_t data_len; - uint16_t total; - uint16_t crc; - ssize_t written; - - DEBUGASSERT(ctx && ctx->transport_state); - - state = ctx->transport_state; - - if (ctx->adu.length < 2) - { - return -EINVAL; - } - - data_len = ctx->adu.length - 2; - - /* Linearize the ADU and append CRC: unit_id, fc, data..., crc_lo, crc_hi */ - - frame[0] = ctx->adu.unit_id; - frame[1] = ctx->adu.fc; - memcpy(&frame[2], ctx->adu.data, data_len); - - crc = nxmb_crc16(frame, ctx->adu.length); - - frame[ctx->adu.length] = (crc & 0xff); - frame[ctx->adu.length + 1] = (crc >> 8); - - ctx->adu.crc = crc; - - total = ctx->adu.length + 2; - written = write(state->fd, frame, total); - - if (written < 0) - { - return -errno; - } - - if (written != total) - { - return -EIO; - } - - return 0; -} - -/**************************************************************************** - * Name: nxmb_serial_receive - * - * Description: - * Receive RTU frame from serial port with dynamic timeout. - * - * Input Parameters: - * ctx - Instance context - * - * Returned Value: - * Zero on success; a negated errno value on failure - * - ****************************************************************************/ - -static int nxmb_serial_receive(nxmb_handle_t ctx) -{ - FAR struct nxmb_serial_state_s *state; - struct timeval timeout; - fd_set readfds; - ssize_t nread; - uint16_t crc_calc; - uint16_t crc_recv; - uint16_t data_len; - int ret; - - DEBUGASSERT(ctx && ctx->transport_state); - - state = ctx->transport_state; - - FD_ZERO(&readfds); - FD_SET(state->fd, &readfds); - - if (state->rx_frame_now) - { - timeout.tv_sec = 0; - timeout.tv_usec = state->t35_usec; - } - else - { - timeout.tv_sec = 0; - timeout.tv_usec = CONFIG_NXMODBUS_RTU_IDLE_TIMEOUT_MS * 1000; - } - - ret = select(state->fd + 1, &readfds, NULL, NULL, &timeout); - - if (ret < 0) - { - return -errno; - } - - if (ret == 0) - { - if (state->rx_frame_now) - { - state->rx_frame_now = false; - - if (state->rx_pos < NXMB_RTU_MIN_FRAME_SIZE) - { - state->rx_pos = 0; - return 0; - } - - crc_calc = nxmb_crc16(state->rx_buf, state->rx_pos - 2); - crc_recv = state->rx_buf[state->rx_pos - 2] | - (state->rx_buf[state->rx_pos - 1] << 8); - - if (crc_calc != crc_recv) - { - state->rx_pos = 0; - return 0; - } - - /* Unpack frame into ctx->adu (excluding the trailing CRC). */ - - data_len = (state->rx_pos - 4); - ctx->adu.unit_id = state->rx_buf[0]; - ctx->adu.fc = state->rx_buf[1]; - memcpy(ctx->adu.data, &state->rx_buf[2], data_len); - ctx->adu.crc = crc_recv; - ctx->adu.length = (state->rx_pos - 2); - - state->rx_pos = 0; - return 1; - } - - return 0; - } - - if (!FD_ISSET(state->fd, &readfds)) - { - return 0; - } - - if (!state->rx_frame_now) - { - state->rx_pos = 0; - state->rx_frame_now = true; - } - - nread = read(state->fd, - &state->rx_buf[state->rx_pos], - sizeof(state->rx_buf) - state->rx_pos); - if (nread < 0) - { - return -errno; - } - - if (nread == 0) - { - return 0; - } - - state->rx_pos += nread; - - if (state->rx_pos >= sizeof(state->rx_buf)) - { - state->rx_pos = 0; - state->rx_frame_now = false; - return 0; - } - - return 0; -} diff --git a/industry/nxmodbus/transport/nxmb_serial_common.c b/industry/nxmodbus/transport/nxmb_serial_common.c deleted file mode 100644 index 72b2d1a87..000000000 --- a/industry/nxmodbus/transport/nxmb_serial_common.c +++ /dev/null @@ -1,138 +0,0 @@ -/**************************************************************************** - * apps/industry/nxmodbus/transport/nxmb_serial_common.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include - -#include -#include - -#ifdef CONFIG_SERIAL_TERMIOS -# include -#endif - -#include - -#include "nxmb_internal.h" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -#ifdef CONFIG_SERIAL_TERMIOS - -/**************************************************************************** - * Name: nxmb_serial_configure - * - * Description: - * Configure serial port with termios settings for Modbus communication. - * - * Input Parameters: - * fd - File descriptor - * baudrate - Baud rate - * parity - Parity setting - * - * Returned Value: - * Zero on success; a negated errno value on failure - * - ****************************************************************************/ - -int nxmb_serial_configure(int fd, uint32_t baudrate, - enum nxmb_parity_e parity) -{ - struct termios tio; - speed_t speed; - - if (tcgetattr(fd, &tio) < 0) - { - return -errno; - } - - switch (baudrate) - { - case 9600: - speed = B9600; - break; - case 19200: - speed = B19200; - break; - case 38400: - speed = B38400; - break; - case 57600: - speed = B57600; - break; - case 115200: - speed = B115200; - break; - default: - return -EINVAL; - } - - cfsetispeed(&tio, speed); - cfsetospeed(&tio, speed); - - tio.c_cflag &= ~(CSIZE | PARENB | PARODD | CSTOPB); - tio.c_cflag |= CS8 | CLOCAL | CREAD; - - switch (parity) - { - case NXMB_PAR_NONE: - - /* Modbus spec: no parity requires 2 stop bits so the - * character frame remains 11 bits. - */ - - tio.c_cflag |= CSTOPB; - break; - case NXMB_PAR_EVEN: - tio.c_cflag |= PARENB; - break; - case NXMB_PAR_ODD: - tio.c_cflag |= PARENB | PARODD; - break; - default: - return -EINVAL; - } - - tio.c_iflag &= - ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON); - tio.c_oflag &= ~OPOST; - tio.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN); - - tio.c_cc[VMIN] = 0; - tio.c_cc[VTIME] = 0; - - if (tcsetattr(fd, TCSANOW, &tio) < 0) - { - return -errno; - } - - return 0; -} - -#endif /* CONFIG_SERIAL_TERMIOS */ diff --git a/industry/nxmodbus/transport/nxmb_tcp.c b/industry/nxmodbus/transport/nxmb_tcp.c deleted file mode 100644 index f4b2dc940..000000000 --- a/industry/nxmodbus/transport/nxmb_tcp.c +++ /dev/null @@ -1,684 +0,0 @@ -/**************************************************************************** - * apps/industry/nxmodbus/transport/nxmb_tcp.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include "nxmb_internal.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define MBAP_HEADER_SIZE 7 -#define MBAP_FC_SIZE 8 -#define NXMB_TCP_RECV_MS 1000 - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -struct nxmb_tcp_client_s -{ - int fd; - uint16_t trans_id; - time_t last_activity; -}; - -struct nxmb_tcp_state_s -{ - struct nxmb_tcp_client_s clients[CONFIG_NXMODBUS_TCP_MAX_CLIENTS]; - int listen_fd; - int active_idx; -}; - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -static int nxmb_tcp_init(nxmb_handle_t ctx); -static int nxmb_tcp_deinit(nxmb_handle_t ctx); -static int nxmb_tcp_send(nxmb_handle_t ctx); -static int nxmb_tcp_receive(nxmb_handle_t ctx); - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -const struct nxmb_transport_ops_s g_nxmb_tcp_ops = -{ - .init = nxmb_tcp_init, - .deinit = nxmb_tcp_deinit, - .send = nxmb_tcp_send, - .receive = nxmb_tcp_receive, -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: nxmb_tcp_put_header - ****************************************************************************/ - -static void nxmb_tcp_put_header(FAR const struct nxmb_adu_s *adu, - FAR uint8_t *hdr) -{ - nxmb_util_put_u16_be(&hdr[0], adu->trans_id); - nxmb_util_put_u16_be(&hdr[2], adu->proto_id); - nxmb_util_put_u16_be(&hdr[4], adu->length); - hdr[6] = adu->unit_id; - hdr[7] = adu->fc; -} - -/**************************************************************************** - * Name: nxmb_tcp_get_header - ****************************************************************************/ - -static void nxmb_tcp_get_header(FAR struct nxmb_adu_s *adu, - FAR const uint8_t *hdr) -{ - adu->trans_id = nxmb_util_get_u16_be(&hdr[0]); - adu->proto_id = nxmb_util_get_u16_be(&hdr[2]); - adu->length = nxmb_util_get_u16_be(&hdr[4]); - adu->unit_id = hdr[6]; - adu->fc = hdr[7]; -} - -/**************************************************************************** - * Name: nxmb_tcp_create_server - ****************************************************************************/ - -static int nxmb_tcp_create_server(FAR const struct nxmb_tcp_config_s *cfg) -{ - struct sockaddr_in addr; - int listen_fd; - int ret; -#ifdef CONFIG_NET_SOCKOPTS - int opt = 1; -#endif - - listen_fd = socket(AF_INET, SOCK_STREAM, 0); - if (listen_fd < 0) - { - return -errno; - } - -#ifdef CONFIG_NET_SOCKOPTS - setsockopt(listen_fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)); -#endif - - memset(&addr, 0, sizeof(addr)); - addr.sin_family = AF_INET; - addr.sin_port = htons(cfg->port); - - if (cfg->bindaddr != NULL) - { - ret = inet_pton(AF_INET, cfg->bindaddr, &addr.sin_addr); - if (ret != 1) - { - close(listen_fd); - return -EINVAL; - } - } - else - { - addr.sin_addr.s_addr = htonl(INADDR_ANY); - } - - ret = bind(listen_fd, (FAR struct sockaddr *)&addr, sizeof(addr)); - if (ret < 0) - { - close(listen_fd); - return -errno; - } - - ret = listen(listen_fd, CONFIG_NXMODBUS_TCP_MAX_CLIENTS); - if (ret < 0) - { - close(listen_fd); - return -errno; - } - - return listen_fd; -} - -/**************************************************************************** - * Name: nxmb_tcp_connect_client - ****************************************************************************/ - -static int nxmb_tcp_connect_client(FAR const struct nxmb_tcp_config_s *cfg) -{ - struct sockaddr_in addr; - int client_fd; - int ret; - - if (cfg->host == NULL) - { - return -EINVAL; - } - - client_fd = socket(AF_INET, SOCK_STREAM, 0); - if (client_fd < 0) - { - return -errno; - } - - memset(&addr, 0, sizeof(addr)); - addr.sin_family = AF_INET; - addr.sin_port = htons(cfg->port); - - ret = inet_pton(AF_INET, cfg->host, &addr.sin_addr); - if (ret != 1) - { - close(client_fd); - return -EINVAL; - } - - ret = connect(client_fd, (FAR struct sockaddr *)&addr, sizeof(addr)); - if (ret < 0) - { - close(client_fd); - return -errno; - } - - return client_fd; -} - -/**************************************************************************** - * Name: nxmb_tcp_recv_full - ****************************************************************************/ - -static int nxmb_tcp_recv_full(int fd, FAR uint8_t *buf, size_t len, - int timeout_ms) -{ - struct timeval tv; - fd_set readfds; - size_t received; - int ret; - - received = 0; - - while (received < len) - { - FD_ZERO(&readfds); - FD_SET(fd, &readfds); - - tv.tv_sec = timeout_ms / 1000; - tv.tv_usec = (timeout_ms % 1000) * 1000; - - ret = select(fd + 1, &readfds, NULL, NULL, &tv); - if (ret < 0) - { - return -errno; - } - else if (ret == 0) - { - return -ETIMEDOUT; - } - - ret = recv(fd, &buf[received], len - received, 0); - if (ret < 0) - { - if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR) - { - continue; - } - - return -errno; - } - else if (ret == 0) - { - return -ECONNRESET; - } - - received += ret; - } - - return received; -} - -/**************************************************************************** - * Name: nxmb_tcp_init - ****************************************************************************/ - -static int nxmb_tcp_init(nxmb_handle_t ctx) -{ - FAR const struct nxmb_tcp_config_s *cfg; - FAR struct nxmb_tcp_state_s *state; - int fd; - int i; - - DEBUGASSERT(ctx); - - cfg = &ctx->transport_cfg.tcp; - - state = calloc(1, sizeof(struct nxmb_tcp_state_s)); - if (state == NULL) - { - return -ENOMEM; - } - - state->listen_fd = -1; - state->active_idx = -1; - - for (i = 0; i < CONFIG_NXMODBUS_TCP_MAX_CLIENTS; i++) - { - state->clients[i].fd = -1; - } - - if (ctx->is_client) - { - fd = nxmb_tcp_connect_client(cfg); - if (fd < 0) - { - free(state); - return fd; - } - - state->clients[0].fd = fd; - state->clients[0].last_activity = time(NULL); - } - else - { - fd = nxmb_tcp_create_server(cfg); - if (fd < 0) - { - free(state); - return fd; - } - - state->listen_fd = fd; - } - - ctx->transport_state = state; - - return OK; -} - -/**************************************************************************** - * Name: nxmb_tcp_deinit - ****************************************************************************/ - -static int nxmb_tcp_deinit(nxmb_handle_t ctx) -{ - FAR struct nxmb_tcp_state_s *state; - int i; - - DEBUGASSERT(ctx && ctx->transport_state); - - state = ctx->transport_state; - - for (i = 0; i < CONFIG_NXMODBUS_TCP_MAX_CLIENTS; i++) - { - if (state->clients[i].fd >= 0) - { - close(state->clients[i].fd); - } - } - - if (state->listen_fd >= 0) - { - close(state->listen_fd); - } - - free(state); - ctx->transport_state = NULL; - - return OK; -} - -/**************************************************************************** - * Name: nxmb_tcp_send - ****************************************************************************/ - -static int nxmb_tcp_send(nxmb_handle_t ctx) -{ - FAR struct nxmb_tcp_state_s *state; - FAR struct nxmb_tcp_client_s *client; - uint8_t header[MBAP_FC_SIZE]; - struct iovec iov[2]; - uint16_t data_len; - uint16_t total; - ssize_t sent; - int fd; - - DEBUGASSERT(ctx && ctx->transport_state); - - state = ctx->transport_state; - - /* For server mode, respond to the client that sent the request. - * For client mode, use the single connection (index 0). - */ - - if (ctx->is_client) - { - client = &state->clients[0]; - } - else - { - if (state->active_idx < 0) - { - return -ENOTCONN; - } - - client = &state->clients[state->active_idx]; - } - - fd = client->fd; - if (fd < 0) - { - return -ENOTCONN; - } - - if (ctx->adu.length < 2) - { - return -EINVAL; - } - - /* Populate the MBAP fields before serializing the header */ - - ctx->adu.trans_id = client->trans_id; - ctx->adu.proto_id = 0x0000; - - data_len = ctx->adu.length - 2; - - /* Emit MBAP header + PDU data via writev() to avoid a stack-side - * copy. The kernel gathers both iovecs into a single TCP segment. - */ - - nxmb_tcp_put_header(&ctx->adu, header); - - iov[0].iov_base = header; - iov[0].iov_len = MBAP_FC_SIZE; - iov[1].iov_base = ctx->adu.data; - iov[1].iov_len = data_len; - - total = MBAP_FC_SIZE + data_len; - sent = writev(fd, iov, (data_len > 0) ? 2 : 1); - if (sent != total) - { - return (sent < 0) ? -errno : -EIO; - } - - client->last_activity = time(NULL); - - return OK; -} - -/**************************************************************************** - * Name: nxmb_tcp_evict_idle - * - * Description: - * Close idle client connections that exceed the configured timeout. - * - ****************************************************************************/ - -static void nxmb_tcp_evict_idle(FAR struct nxmb_tcp_state_s *state, - time_t now) -{ - int i; - - for (i = 0; i < CONFIG_NXMODBUS_TCP_MAX_CLIENTS; i++) - { - if (state->clients[i].fd >= 0 && - (now - state->clients[i].last_activity) > - CONFIG_NXMODBUS_TCP_TIMEOUT_SEC) - { - close(state->clients[i].fd); - state->clients[i].fd = -1; - } - } -} - -/**************************************************************************** - * Name: nxmb_tcp_accept_new - * - * Description: - * Accept a pending connection into the first free client slot. - * - ****************************************************************************/ - -static void nxmb_tcp_accept_new(FAR struct nxmb_tcp_state_s *state) -{ - int fd; - int i; - - fd = accept(state->listen_fd, NULL, NULL); - if (fd < 0) - { - return; - } - - for (i = 0; i < CONFIG_NXMODBUS_TCP_MAX_CLIENTS; i++) - { - if (state->clients[i].fd < 0) - { - state->clients[i].fd = fd; - state->clients[i].last_activity = time(NULL); - return; - } - } - - /* No free slot -- reject the connection */ - - close(fd); -} - -/**************************************************************************** - * Name: nxmb_tcp_read_frame - * - * Description: - * Read a complete Modbus TCP frame from a client connection. - * On error (except timeout), the connection is closed. - * - ****************************************************************************/ - -static int nxmb_tcp_read_frame(nxmb_handle_t ctx, - FAR struct nxmb_tcp_client_s *client) -{ - uint8_t header[MBAP_FC_SIZE]; - uint16_t data_len; - int ret; - - ret = nxmb_tcp_recv_full(client->fd, header, MBAP_FC_SIZE, - NXMB_TCP_RECV_MS); - if (ret < 0) - { - if (ret == -ETIMEDOUT || ret == -EAGAIN) - { - return -EAGAIN; - } - - close(client->fd); - client->fd = -1; - return ret; - } - - nxmb_tcp_get_header(&ctx->adu, header); - - if (ctx->adu.proto_id != 0x0000) - { - close(client->fd); - client->fd = -1; - return -EPROTO; - } - - if (ctx->adu.length < 2) - { - close(client->fd); - client->fd = -1; - return -EINVAL; - } - - data_len = ctx->adu.length - 2; - - if (data_len > NXMB_ADU_DATA_MAX) - { - close(client->fd); - client->fd = -1; - return -EMSGSIZE; - } - - if (data_len > 0) - { - ret = nxmb_tcp_recv_full(client->fd, ctx->adu.data, data_len, - NXMB_TCP_RECV_MS); - if (ret < 0) - { - close(client->fd); - client->fd = -1; - return ret; - } - } - - client->trans_id = ctx->adu.trans_id; - client->last_activity = time(NULL); - - return ctx->adu.length; -} - -static int nxmb_tcp_receive(nxmb_handle_t ctx) -{ - FAR struct nxmb_tcp_state_s *state; - struct timeval tv; - fd_set readfds; - time_t now; - int maxfd; - int ret; - int i; - - DEBUGASSERT(ctx && ctx->transport_state); - - state = ctx->transport_state; - state->active_idx = -1; - - /* Client mode: single connection, read directly */ - - if (ctx->is_client) - { - if (state->clients[0].fd < 0) - { - return -ENOTCONN; - } - - state->active_idx = 0; - return nxmb_tcp_read_frame(ctx, &state->clients[0]); - } - - /* Server mode: multiplex listen socket + all client connections */ - - now = time(NULL); - nxmb_tcp_evict_idle(state, now); - - FD_ZERO(&readfds); - maxfd = -1; - - if (state->listen_fd >= 0) - { - FD_SET(state->listen_fd, &readfds); - maxfd = state->listen_fd; - } - - for (i = 0; i < CONFIG_NXMODBUS_TCP_MAX_CLIENTS; i++) - { - if (state->clients[i].fd >= 0) - { - FD_SET(state->clients[i].fd, &readfds); - if (state->clients[i].fd > maxfd) - { - maxfd = state->clients[i].fd; - } - } - } - - if (maxfd < 0) - { - return -EAGAIN; - } - - tv.tv_sec = 0; - tv.tv_usec = 50000; - - ret = select(maxfd + 1, &readfds, NULL, NULL, &tv); - if (ret < 0) - { - return -errno; - } - - if (ret == 0) - { - return -EAGAIN; - } - - /* Accept new connections if listen socket is ready */ - - if (state->listen_fd >= 0 && FD_ISSET(state->listen_fd, &readfds)) - { - nxmb_tcp_accept_new(state); - } - - /* Check each client for incoming data (first ready wins). - * In server mode, a per-client read failure (disconnect, protocol - * error, etc.) must not be fatal - nxmb_tcp_read_frame has already - * closed the offending fd, and the listen socket remains open for new - * connections. Translate any such error to -EAGAIN so the caller - * keeps polling. - */ - - for (i = 0; i < CONFIG_NXMODBUS_TCP_MAX_CLIENTS; i++) - { - if (state->clients[i].fd >= 0 && - FD_ISSET(state->clients[i].fd, &readfds)) - { - state->active_idx = i; - ret = nxmb_tcp_read_frame(ctx, &state->clients[i]); - if (ret < 0 && ret != -EAGAIN) - { - state->active_idx = -1; - return -EAGAIN; - } - - return ret; - } - } - - return -EAGAIN; -} diff --git a/industry/scpi/.gitignore b/industry/scpi/.gitignore deleted file mode 100644 index 17ba1ae81..000000000 --- a/industry/scpi/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -/*.tar.gz -/scpi-parser - diff --git a/industry/scpi/Kconfig b/industry/scpi/Kconfig deleted file mode 100644 index 6797051e6..000000000 --- a/industry/scpi/Kconfig +++ /dev/null @@ -1,88 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config SCPI_PARSER - tristate "SCPI instrument side parser" - default n - -if SCPI_PARSER - -menu "SCPI parser unit support" - -config SCPI_PARSER_UNITS_IMPERIAL - bool "Imperial units" - default n - -config SCPI_PARSER_UNITS_ANGLE - bool "Angle units" - default n - -config SCPI_PARSER_UNITS_PARTICLES - bool "Particle units" - default n - -config SCPI_PARSER_UNITS_DISTANCE - bool "Distance units" - default n - -config SCPI_PARSER_UNITS_MAGNETIC - bool "Magnetic units" - default n - -config SCPI_PARSER_UNITS_LIGHT - bool "Light units" - default n - -config SCPI_PARSER_UNITS_ENERGY_FORCE_MASS - bool "Energy, force, and mass units" - default n - -config SCPI_PARSER_UNITS_TIME - bool "Time units" - default n - -config SCPI_PARSER_UNITS_TEMPERATURE - bool "Temperature units" - default n - -config SCPI_PARSER_UNITS_RATIO - bool "Ratio units" - default n - -config SCPI_PARSER_UNITS_POWER - bool "Power units" - default y - -config SCPI_PARSER_UNITS_FREQUENCY - bool "Frequency units" - default y - -config SCPI_PARSER_UNITS_ELECTRIC - bool "Electric units" - default y - -config SCPI_PARSER_UNITS_ELECTRIC_CHARGE_CONDUCTANCE - bool "Electric charge and conductance units" - default n - -endmenu - -config SCPI_PARSER_DEMO - bool "Enable the SCPI parser library demo" - default n - -if SCPI_PARSER_DEMO - -config SCPI_PARSER_DEMO_PRIORITY - int "SCPI demo program priority" - default 100 - -config SCPI_PARSER_DEMO_STACKSIZE - int "SCPI demo program stack size" - default DEFAULT_TASK_STACKSIZE - -endif - -endif diff --git a/industry/scpi/Make.defs b/industry/scpi/Make.defs deleted file mode 100644 index f7e67a846..000000000 --- a/industry/scpi/Make.defs +++ /dev/null @@ -1,32 +0,0 @@ -############################################################################ -# apps/industry/scpi/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_SCPI_PARSER),) - -CONFIGURED_APPS += $(APPDIR)/industry/scpi - -# Allows `.h>` import. - -CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/industry/scpi/scpi-parser/libscpi/inc -CXXFLAGS += ${INCDIR_PREFIX}$(APPDIR)/industry/scpi/scpi-parser/libscpi/inc - -endif diff --git a/industry/scpi/Makefile b/industry/scpi/Makefile deleted file mode 100644 index 515011129..000000000 --- a/industry/scpi/Makefile +++ /dev/null @@ -1,89 +0,0 @@ -############################################################################ -# apps/industry/scpi/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -SCPI_VERSION = 2.2 -SCPI_UNPACK = scpi-parser -SCPI_TARBALL = v$(SCPI_VERSION).tar.gz -SCPI_URL_BASE = https://github.com/j123b567/scpi-parser/archive/refs/tags -SCPI_URL = $(SCPI_URL_BASE)/$(SCPI_TARBALL) - -CSRCS += error.c fifo.c ieee488.c -CSRCS += minimal.c parser.c units.c utils.c -CSRCS += lexer.c expression.c - -VPATH += $(SCPI_UNPACK)/libscpi/src - -CFLAGS += -DHAVE_STRNLEN -CFLAGS += -DHAVE_SNPRINTF -CFLAGS += -DHAVE_STRNDUP -CFLAGS += -DHAVE_STRNCASECMP - -SCPI_UNIT = $(if $(filter y,$(CONFIG_SCPI_PARSER_UNITS_$(1))),1,0) -SCPI_UECC = $(call SCPI_UNIT,ELECTRIC_CHARGE_CONDUCTANCE) - -CFLAGS += -DUSE_UNITS_IMPERIAL=$(call SCPI_UNIT,IMPERIAL) -CFLAGS += -DUSE_UNITS_ANGLE=$(call SCPI_UNIT,ANGLE) -CFLAGS += -DUSE_UNITS_PARTICLES=$(call SCPI_UNIT,PARTICLES) -CFLAGS += -DUSE_UNITS_DISTANCE=$(call SCPI_UNIT,DISTANCE) -CFLAGS += -DUSE_UNITS_MAGNETIC=$(call SCPI_UNIT,MAGNETIC) -CFLAGS += -DUSE_UNITS_LIGHT=$(call SCPI_UNIT,LIGHT) -CFLAGS += -DUSE_UNITS_ENERGY_FORCE_MASS=$(call SCPI_UNIT,ENERGY_FORCE_MASS) -CFLAGS += -DUSE_UNITS_TIME=$(call SCPI_UNIT,TIME) -CFLAGS += -DUSE_UNITS_TEMPERATURE=$(call SCPI_UNIT,TEMPERATURE) -CFLAGS += -DUSE_UNITS_RATIO=$(call SCPI_UNIT,RATIO) -CFLAGS += -DUSE_UNITS_POWER=$(call SCPI_UNIT,POWER) -CFLAGS += -DUSE_UNITS_FREQUENCY=$(call SCPI_UNIT,FREQUENCY) -CFLAGS += -DUSE_UNITS_ELECTRIC=$(call SCPI_UNIT,ELECTRIC) -CFLAGS += -DUSE_UNITS_ELECTRIC_CHARGE_CONDUCTANCE=$(SCPI_UECC) - -ifneq ($(CONFIG_SCPI_PARSER_DEMO),) -MAINSRC = $(SCPI_UNPACK)/examples/test-interactive/main.c -CSRCS += scpi-def.c - -PROGNAME = scpidemo -PRIORITY = $(CONFIG_SCPI_PARSER_DEMO_PRIORITY) -STACKSIZE = $(CONFIG_SCPI_PARSER_DEMO_STACKSIZE) -MODULE = $(CONFIG_SCPI_PARSER) - -VPATH += $(SCPI_UNPACK)/examples -VPATH += $(SCPI_UNPACK)/examples/common -endif # CONFIG_SCPI_PARSER_DEMO - -$(SCPI_TARBALL): - $(Q) echo "Downloading $(SCPI_TARBALL)" - $(Q) curl -O -L $(SCPI_URL) - $(Q) echo "Unpacking $(SCPI_TARBALL) to $(SCPI_UNPACK)" - $(Q) tar xzvf $(SCPI_TARBALL) - $(Q) mv scpi-parser-$(SCPI_VERSION) $(SCPI_UNPACK) - -# Download and unpack tarball if no git repo found -ifeq ($(wildcard $(SCPI_UNPACK)/.git),) -context:: $(SCPI_TARBALL) - -distclean:: - $(call DELDIR, $(SCPI_UNPACK)) - $(call DELFILE, $(SCPI_TARBALL)) -endif - -include $(APPDIR)/Application.mk diff --git a/inertial/.gitignore b/inertial/.gitignore deleted file mode 100644 index 9e1d2593e..000000000 --- a/inertial/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/Kconfig diff --git a/inertial/CMakeLists.txt b/inertial/CMakeLists.txt deleted file mode 100644 index e3324c5cc..000000000 --- a/inertial/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -# ############################################################################## -# apps/inertial/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -nuttx_add_subdirectory() - -nuttx_generate_kconfig(MENUDESC "Inertial Libraries Support") diff --git a/inertial/Make.defs b/inertial/Make.defs deleted file mode 100644 index d5c8f4ca5..000000000 --- a/inertial/Make.defs +++ /dev/null @@ -1,23 +0,0 @@ -############################################################################ -# apps/inertial/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(wildcard $(APPDIR)/inertial/*/Make.defs) diff --git a/inertial/Makefile b/inertial/Makefile deleted file mode 100644 index 1d48a1ae3..000000000 --- a/inertial/Makefile +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/inertial/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -MENUDESC = "Inertial Libraries Support" - -include $(APPDIR)/Directory.mk diff --git a/inertial/madgwick/.gitignore b/inertial/madgwick/.gitignore deleted file mode 100644 index 53b249722..000000000 --- a/inertial/madgwick/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/fusion -/libmadgwick.tar.gz diff --git a/inertial/madgwick/CMakeLists.txt b/inertial/madgwick/CMakeLists.txt deleted file mode 100644 index df20b7129..000000000 --- a/inertial/madgwick/CMakeLists.txt +++ /dev/null @@ -1,58 +0,0 @@ -# ############################################################################## -# apps/inertial/madgwick/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_LIB_MADGWICK) - - set(MADGWICK_DIR ${CMAKE_CURRENT_LIST_DIR}/fusion) - - if(NOT EXISTS ${MADGWICK_DIR}) - FetchContent_Declare( - madgwick_fetch - DOWNLOAD_NAME "libmadgwick.tar.gz" - DOWNLOAD_DIR ${CMAKE_CURRENT_LIST_DIR} - URL "https://github.com/xioTechnologies/Fusion/archive/refs/tags/v${CONFIG_LIB_MADGWICK_VER}.tar.gz" - SOURCE_DIR - ${MADGWICK_DIR} - BINARY_DIR - ${CMAKE_BINARY_DIR}/apps/inertial/madgwick/fusion - DOWNLOAD_NO_PROGRESS true - TIMEOUT 30) - - FetchContent_GetProperties(madgwick_fetch) - - if(NOT madgwick_fetch_POPULATED) - FetchContent_Populate(madgwick_fetch) - endif() - endif() - - set(CSRCS - ${MADGWICK_DIR}/Fusion/FusionAhrs.c - ${MADGWICK_DIR}/Fusion/FusionCompass.c - ${MADGWICK_DIR}/Fusion/FusionOffset.c) - - nuttx_add_library(madgwick STATIC) - target_sources(madgwick PRIVATE ${CSRCS}) - target_include_directories(madgwick PUBLIC ${MADGWICK_DIR}) - target_compile_options(madgwick PRIVATE -Wno-shadow -Wno-strict-prototypes - -Wno-unknown-pragmas) - -endif() diff --git a/inertial/madgwick/Kconfig b/inertial/madgwick/Kconfig deleted file mode 100644 index 98d0e1db0..000000000 --- a/inertial/madgwick/Kconfig +++ /dev/null @@ -1,21 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config LIB_MADGWICK - bool "Madgwick Fusion Algorithm" - default n - depends on ALLOW_MIT_COMPONENTS - ---help--- - Enable madgwick fusion algorithm. - Madgwick is a quick fusion algorithm use integrate - accelerometer, gyroscope and magnotomer (compass). - -if LIB_MADGWICK - -config LIB_MADGWICK_VER - string "Lib Madgwick version" - default "1.2.1" - -endif # LIB_MADGWICK diff --git a/inertial/madgwick/Make.defs b/inertial/madgwick/Make.defs deleted file mode 100644 index bb48895dc..000000000 --- a/inertial/madgwick/Make.defs +++ /dev/null @@ -1,28 +0,0 @@ -############################################################################ -# apps/inertial/madgwick/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_LIB_MADGWICK),) -CONFIGURED_APPS += $(APPDIR)/inertial/madgwick - -CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/inertial/madgwick/fusion -CXXFLAGS += ${INCDIR_PREFIX}$(APPDIR)/inertial/madgwick/fusion -endif diff --git a/inertial/madgwick/Makefile b/inertial/madgwick/Makefile deleted file mode 100644 index 909d67b97..000000000 --- a/inertial/madgwick/Makefile +++ /dev/null @@ -1,49 +0,0 @@ -############################################################################ -# apps/inertial/madgwick/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -SRC = fusion/Fusion - -CSRCS += $(SRC)/FusionAhrs.c -CSRCS += $(SRC)/FusionCompass.c -CSRCS += $(SRC)/FusionOffset.c - -CFLAGS += -Wno-shadow -Wno-strict-prototypes -Wno-unknown-pragmas - -MODULE = $(CONFIG_LIB_MADGWICK) - -libmadgwick.tar.gz: - $(Q) curl -L https://github.com/xioTechnologies/Fusion/archive/refs/tags/v$(CONFIG_LIB_MADGWICK_VER).tar.gz -o libmadgwick.tar.gz - $(Q) tar xf libmadgwick.tar.gz - $(Q) mv Fusion-$(CONFIG_LIB_MADGWICK_VER) fusion - -# Download and unpack tarball if no git repo found -ifeq ($(wildcard madgwick/fusion),) -context:: libmadgwick.tar.gz - -distclean:: - $(call DELDIR, fusion) - $(call DELFILE, libmadgwick.tar.gz) -endif - -include $(APPDIR)/Application.mk diff --git a/interpreters/CMakeLists.txt b/interpreters/CMakeLists.txt deleted file mode 100644 index 94592ab05..000000000 --- a/interpreters/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -# ############################################################################## -# apps/interpreters/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -nuttx_add_subdirectory() - -nuttx_generate_kconfig(MENUDESC "Interpreters") diff --git a/interpreters/Make.defs b/interpreters/Make.defs index 64c220bbd..0ead58c3b 100644 --- a/interpreters/Make.defs +++ b/interpreters/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/interpreters/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/interpreters/Makefile b/interpreters/Makefile index 63f027808..ec2e50c1c 100644 --- a/interpreters/Makefile +++ b/interpreters/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/interpreters/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/interpreters/README.md b/interpreters/README.md new file mode 100644 index 000000000..0379e1eee --- /dev/null +++ b/interpreters/README.md @@ -0,0 +1,21 @@ +# Interpreters + +This `apps/` directory is set aside to hold interpreters that may be +incorporated into NuttX. + +## Ficl + +This is DIY port of Ficl (the _Forth Inspired Command Language_). See +http://ficl.sourceforge.net/. It is a _DIY_ port because the Ficl source is not +in that directory, only an environment and instructions that will let you build +Ficl under NuttX. The rest is up to you. + +## Mini Basic + +The Mini Basic implementation at `apps/interpreters` derives from version `1.0` +by Malcolm McLean, Leeds University, and was released under the Creative Commons +Attibution license. I am not legal expert, but this license appears to be +compatible with the NuttX BSD license see: +https://creativecommons.org/licenses/. I, however, cannot take responsibility +for any actions that you might take based on my understanding. Please use your +own legal judgement. diff --git a/interpreters/bas/CMakeLists.txt b/interpreters/bas/CMakeLists.txt deleted file mode 100644 index 527353d7c..000000000 --- a/interpreters/bas/CMakeLists.txt +++ /dev/null @@ -1,51 +0,0 @@ -# ############################################################################## -# apps/interpreters/bas/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_INTERPRETERS_BAS) - nuttx_add_application( - NAME - bas - SRCS - bas_main.c - STACKSIZE - ${CONFIG_INTERPRETERS_BAS_STACKSIZE} - PRIORITY - ${CONFIG_INTERPRETERS_BAS_PRIORITY}) - - set(CSRCS - bas_str.c - bas_token.c - bas_value.c - bas_var.c - bas.c - bas_auto.c - bas_fs.c - bas_global.c - bas_program.c) - - if(CONFIG_INTERPRETERS_BAS_VT100) - list(APPEND CSRCS bas_vt100.c) - endif() - - target_sources(apps PRIVATE ${CSRCS}) - -endif() diff --git a/interpreters/bas/Kconfig b/interpreters/bas/Kconfig index 39b502902..074fa477b 100644 --- a/interpreters/bas/Kconfig +++ b/interpreters/bas/Kconfig @@ -33,37 +33,37 @@ config INTERPRETERS_BAS if INTERPRETERS_BAS -config INTERPRETERS_BAS_VERSION +config INTERPRETER_BAS_VERSION string "Version number" default "2.4" -config INTERPRETERS_BAS_PRIORITY +config INTERPRETER_BAS_PRIORITY int "Basic interpreter priority" default 100 ---help--- Task priority of the Basic interpreter main task -config INTERPRETERS_BAS_STACKSIZE +config INTERPRETER_BAS_STACKSIZE int "Basic interpreter stack size" default 4096 ---help--- Size of the stack allocated for the Basic interpreter main task -config INTERPRETERS_BAS_VT100 +config INTERPRETER_BAS_VT100 bool "VT100 terminal support" default y -config INTERPRETERS_BAS_USE_LR0 +config INTERPRETER_BAS_USE_LR0 bool "LR0 parser" default n ---help--- Select if you want LR0 parser. -config INTERPRETERS_BAS_USE_SELECT +config INTERPRETER_BAS_USE_SELECT bool "Use select()" default n -config INTERPRETERS_BAS_HAVE_FTRUNCATE +config INTERPRETER_BAS_HAVE_FTRUNCATE bool default n ---help--- @@ -72,7 +72,7 @@ config INTERPRETERS_BAS_HAVE_FTRUNCATE config EXAMPLES_BAS_SHELL bool "Shell support" default n - depends on ARCH_HAVE_FORK && EXPERIMENTAL + depends on ARCH_HAVE_VFORK && EXPERIMENTAL select LIBC_EXECFUNCS select SCHED_WAITPID ---help--- diff --git a/interpreters/bas/Make.defs b/interpreters/bas/Make.defs index e17fec9a6..0494eff25 100644 --- a/interpreters/bas/Make.defs +++ b/interpreters/bas/Make.defs @@ -1,25 +1,3 @@ -############################################################################ -# apps/interpreters/bas/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - ifneq ($(CONFIG_INTERPRETERS_BAS),) CONFIGURED_APPS += $(APPDIR)/interpreters/bas endif diff --git a/interpreters/bas/Makefile b/interpreters/bas/Makefile index 532c74043..a3afaf278 100644 --- a/interpreters/bas/Makefile +++ b/interpreters/bas/Makefile @@ -1,7 +1,5 @@ ############################################################################ -# apps/interpreters/bas/Makefile -# -# SPDX-License-Identifier: Apache-2.0 +# apps/bas/Makefile # # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with @@ -27,7 +25,7 @@ include $(APPDIR)/Make.defs CSRCS = bas.c bas_auto.c bas_fs.c bas_global.c bas_program.c CSRCS += bas_str.c bas_token.c bas_value.c bas_var.c -ifeq ($(CONFIG_INTERPRETERS_BAS_VT100),y) +ifeq ($(CONFIG_INTERPRETER_BAS_VT100),y) CSRCS += bas_vt100.c endif @@ -36,8 +34,8 @@ MAINSRC = bas_main.c # BAS built-in application info PROGNAME = bas -PRIORITY = $(CONFIG_INTERPRETERS_BAS_PRIORITY) -STACKSIZE = $(CONFIG_INTERPRETERS_BAS_STACKSIZE) +PRIORITY = $(CONFIG_INTERPRETER_BAS_PRIORITY) +STACKSIZE = $(CONFIG_INTERPRETER_BAS_STACKSIZE) MODULE = $(CONFIG_INTERPRETERS_BAS) include $(APPDIR)/Application.mk diff --git a/interpreters/bas/README.md b/interpreters/bas/README.md new file mode 100644 index 000000000..be3f431eb --- /dev/null +++ b/interpreters/bas/README.md @@ -0,0 +1,59 @@ +# Interpreters / `bas` Bas BASIC + +## Introduction + +Bas is an interpreter for the classic dialect of the programming language BASIC. +It is pretty compatible to typical BASIC interpreters of the 1980s, unlike some +other UNIX BASIC interpreters, that implement a different syntax, breaking +compatibility to existing programs. Bas offers many ANSI BASIC statements for +structured programming, such as procedures, local variables and various loop +types. Further there are matrix operations, automatic LIST indentation and many +statements and functions found in specific classic dialects. Line numbers are +not required. + +The interpreter tokenises the source and resolves references to variables and +jump targets before running the program. This compilation pass increases +efficiency and catches syntax errors, type errors and references to variables +that are never initialised. Bas is written in ANSI C for UNIX systems. + +## License + +BAS 2.4 is released as part of NuttX under the standard 3-clause BSD license use +by all components of NuttX. This is not incompatible with the original BAS 2.4 +licensing + +Copyright (c) 1999-2014 Michael Haardt + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +## Bas 2.4 Release Notes + +Changes compared to version `2.3` + +- Matrix inversion on integer arrays with option base 1 fixed. +- `PRINT USING` behaviour for `!` fixed. +- `PRINT`, separator should advance to the next zone, even if the current + position is at the start of a zone. +- Added `ip()`, `frac()`, `fp()`, `log10()`, `log2()`, `min()` and `max()`. +- Fixed `NEXT` checking the variable case sensitive. +- Use `terminfo` capability cr to make use of its padding. +- `LET` segmentation fault fixed. +- `PRINT` now uses print items. +- `-r` for restricted operation. +- `MAT INPUT` does not drop excess arguments, but uses them for the next row. +- License changed to MIT. diff --git a/interpreters/bas/bas.c b/interpreters/bas/bas.c index 18b08876f..46a5c85df 100644 --- a/interpreters/bas/bas.c +++ b/interpreters/bas/bas.c @@ -1,8 +1,7 @@ /**************************************************************************** * apps/interpreters/bas/bas.c * - * SPDX-License-Identifier: MIT - * SPDX-FileCopyrightText: 1999-2014 Michael Haardt + * Copyright (c) 1999-2014 Michael Haardt * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -614,7 +613,7 @@ static struct Value *func(struct Value *value) return value; } -#ifdef CONFIG_INTERPRETERS_BAS_USE_LR0 +#ifdef CONFIG_INTERPRETER_BAS_USE_LR0 /* Grammar with LR(0) sets */ @@ -2368,7 +2367,7 @@ void bas_interpreter(void) { if (FS_istty(STDCHANNEL)) { - FS_putChars(STDCHANNEL, "bas " CONFIG_INTERPRETERS_BAS_VERSION "\n"); + FS_putChars(STDCHANNEL, "bas " CONFIG_INTERPRETER_BAS_VERSION "\n"); FS_putChars(STDCHANNEL, "Copyright 1999-2014 Michael Haardt.\n"); FS_putChars(STDCHANNEL, "This is free software with ABSOLUTELY NO WARRANTY.\n"); diff --git a/interpreters/bas/bas.h b/interpreters/bas/bas.h index eb4890d50..4373ad7ad 100644 --- a/interpreters/bas/bas.h +++ b/interpreters/bas/bas.h @@ -1,8 +1,7 @@ /**************************************************************************** * apps/interpreters/bas/bas.h * - * SPDX-License-Identifier: MIT - * SPDX-FileCopyrightText: 1999-2014 Michael Haardt + * Copyright (c) 1999-2014 Michael Haardt * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), diff --git a/interpreters/bas/bas_auto.c b/interpreters/bas/bas_auto.c index 25d14a6cd..92ff57340 100644 --- a/interpreters/bas/bas_auto.c +++ b/interpreters/bas/bas_auto.c @@ -1,8 +1,8 @@ /**************************************************************************** * apps/interpreters/bas/bas_auto.c + * BASIC file system interface. * - * SPDX-License-Identifier: MIT - * SPDX-FileCopyrightText: 1999-2014 Michael Haardt + * Copyright (c) 1999-2014 Michael Haardt * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -14,8 +14,8 @@ * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING @@ -50,34 +50,34 @@ /* interpretation methods */ -struct Auto *Auto_new(struct Auto *self) +struct Auto *Auto_new(struct Auto *this) { - self->stackPointer = 0; - self->stackCapacity = 0; - self->framePointer = 0; - self->frameSize = 0; - self->onerror.line = -1; - self->erl = 0; - Value_new_NIL(&self->err); - Value_new_NIL(&self->lastdet); - self->begindata.line = -1; - self->slot = (union AutoSlot *)0; - self->cur = self->all = (struct Symbol *)0; - return self; + this->stackPointer = 0; + this->stackCapacity = 0; + this->framePointer = 0; + this->frameSize = 0; + this->onerror.line = -1; + this->erl = 0; + Value_new_NIL(&this->err); + Value_new_NIL(&this->lastdet); + this->begindata.line = -1; + this->slot = (union AutoSlot *)0; + this->cur = this->all = (struct Symbol *)0; + return this; } -void Auto_destroy(struct Auto *self) +void Auto_destroy(struct Auto *this) { struct Symbol *l; - Value_destroy(&self->err); - Value_destroy(&self->lastdet); - if (self->stackCapacity) + Value_destroy(&this->err); + Value_destroy(&this->lastdet); + if (this->stackCapacity) { - free(self->slot); + free(this->slot); } - for (l = self->all; l != (struct Symbol *)0; ) + for (l = this->all; l != (struct Symbol *)0;) { struct Symbol *f; @@ -88,135 +88,134 @@ void Auto_destroy(struct Auto *self) } } -struct Var *Auto_pushArg(struct Auto *self) +struct Var *Auto_pushArg(struct Auto *this) { - if ((self->stackPointer + 1) >= self->stackCapacity) + if ((this->stackPointer + 1) >= this->stackCapacity) { - self->slot = - realloc(self->slot, - sizeof(self->slot[0]) * - (self-> - stackCapacity ? (self->stackCapacity = - self->stackPointer + - INCREASE_STACK) : (self->stackCapacity = + this->slot = + realloc(this->slot, + sizeof(this->slot[0]) * + (this-> + stackCapacity ? (this->stackCapacity = + this->stackPointer + + INCREASE_STACK) : (this->stackCapacity = INCREASE_STACK))); } - return &self->slot[self->stackPointer++].var; + return &this->slot[this->stackPointer++].var; } -void Auto_pushFuncRet(struct Auto *self, int firstarg, struct Pc *pc) +void Auto_pushFuncRet(struct Auto *this, int firstarg, struct Pc *pc) { - if (self->stackPointer + 2 >= self->stackCapacity) + if (this->stackPointer + 2 >= this->stackCapacity) { - self->slot = - realloc(self->slot, - sizeof(self->slot[0]) * - (self-> - stackCapacity ? (self->stackCapacity = - self->stackCapacity + - INCREASE_STACK) : (self->stackCapacity = + this->slot = + realloc(this->slot, + sizeof(this->slot[0]) * + (this-> + stackCapacity ? (this->stackCapacity = + this->stackCapacity + + INCREASE_STACK) : (this->stackCapacity = INCREASE_STACK))); } - self->slot[self->stackPointer].retException.onerror = self->onerror; - self->slot[self->stackPointer].retException.resumeable = self->resumeable; - ++self->stackPointer; - self->slot[self->stackPointer].retFrame.pc = *pc; - self->slot[self->stackPointer].retFrame.framePointer = self->framePointer; - self->slot[self->stackPointer].retFrame.frameSize = self->frameSize; - ++self->stackPointer; - self->framePointer = firstarg; - self->frameSize = self->stackPointer - firstarg; - self->onerror.line = -1; + this->slot[this->stackPointer].retException.onerror = this->onerror; + this->slot[this->stackPointer].retException.resumeable = this->resumeable; + ++this->stackPointer; + this->slot[this->stackPointer].retFrame.pc = *pc; + this->slot[this->stackPointer].retFrame.framePointer = this->framePointer; + this->slot[this->stackPointer].retFrame.frameSize = this->frameSize; + ++this->stackPointer; + this->framePointer = firstarg; + this->frameSize = this->stackPointer - firstarg; + this->onerror.line = -1; } -void Auto_pushGosubRet(struct Auto *self, struct Pc *pc) +void Auto_pushGosubRet(struct Auto *this, struct Pc *pc) { - if ((self->stackPointer + 1) >= self->stackCapacity) + if ((this->stackPointer + 1) >= this->stackCapacity) { - self->slot = - realloc(self->slot, - sizeof(self->slot[0]) * - (self-> - stackCapacity ? (self->stackCapacity = - self->stackPointer + - INCREASE_STACK) : (self->stackCapacity = + this->slot = + realloc(this->slot, + sizeof(this->slot[0]) * + (this-> + stackCapacity ? (this->stackCapacity = + this->stackPointer + + INCREASE_STACK) : (this->stackCapacity = INCREASE_STACK))); } - self->slot[self->stackPointer].retFrame.pc = *pc; - ++self->stackPointer; + this->slot[this->stackPointer].retFrame.pc = *pc; + ++this->stackPointer; } -struct Var *Auto_local(struct Auto *self, int l) +struct Var *Auto_local(struct Auto *this, int l) { - assert(self->frameSize > (l + 2)); - return &(self->slot[self->framePointer + l].var); + assert(this->frameSize > (l + 2)); + return &(this->slot[this->framePointer + l].var); } -int Auto_funcReturn(struct Auto *self, struct Pc *pc) +int Auto_funcReturn(struct Auto *this, struct Pc *pc) { int retException; int retFrame; int i; - if (self->stackPointer == 0) + if (this->stackPointer == 0) { return 0; } - assert(self->frameSize); - retFrame = self->framePointer + self->frameSize - 1; - retException = self->framePointer + self->frameSize - 2; - assert(retException >= 0 && retFrame < self->stackPointer); - for (i = 0; i < self->frameSize - 2; ++i) + assert(this->frameSize); + retFrame = this->framePointer + this->frameSize - 1; + retException = this->framePointer + this->frameSize - 2; + assert(retException >= 0 && retFrame < this->stackPointer); + for (i = 0; i < this->frameSize - 2; ++i) { - Var_destroy(&self->slot[self->framePointer + i].var); + Var_destroy(&this->slot[this->framePointer + i].var); } - self->stackPointer = self->framePointer; + this->stackPointer = this->framePointer; if (pc != (struct Pc *)0) { - *pc = self->slot[retFrame].retFrame.pc; + *pc = this->slot[retFrame].retFrame.pc; } - self->frameSize = self->slot[retFrame].retFrame.frameSize; - self->framePointer = self->slot[retFrame].retFrame.framePointer; - self->onerror = self->slot[retException].retException.onerror; + this->frameSize = this->slot[retFrame].retFrame.frameSize; + this->framePointer = this->slot[retFrame].retFrame.framePointer; + this->onerror = this->slot[retException].retException.onerror; return 1; } -int Auto_gosubReturn(struct Auto *self, struct Pc *pc) +int Auto_gosubReturn(struct Auto *this, struct Pc *pc) { - if (self->stackPointer <= self->framePointer + self->frameSize) + if (this->stackPointer <= this->framePointer + this->frameSize) { return 0; } - --self->stackPointer; + --this->stackPointer; if (pc) { - *pc = self->slot[self->stackPointer].retFrame.pc; + *pc = this->slot[this->stackPointer].retFrame.pc; } return 1; } -void Auto_frameToError(struct Auto *self, - struct Program *program, struct Value *v) +void Auto_frameToError(struct Auto *this, struct Program *program, struct Value *v) { struct Pc p; int framePointer; int frameSize; int retFrame; - int i = self->stackPointer; + int i = this->stackPointer; - framePointer = self->framePointer; - frameSize = self->frameSize; + framePointer = this->framePointer; + frameSize = this->frameSize; while (i > framePointer + frameSize) { - p = self->slot[--i].retFrame.pc; + p = this->slot[--i].retFrame.pc; Value_errorSuffix(v, _("Called")); Program_PCtoError(program, &p, v); } @@ -224,28 +223,26 @@ void Auto_frameToError(struct Auto *self, if (i) { retFrame = framePointer + frameSize - 1; - p = self->slot[retFrame].retFrame.pc; + p = this->slot[retFrame].retFrame.pc; Value_errorSuffix(v, _("Proc Called")); Program_PCtoError(program, &p, v); } } -void Auto_setError(struct Auto *self, long int line, - struct Pc *pc, struct Value *v) +void Auto_setError(struct Auto *this, long int line, struct Pc *pc, struct Value *v) { - self->erpc = *pc; - self->erl = line; - Value_destroy(&self->err); - Value_clone(&self->err, v); + this->erpc = *pc; + this->erl = line; + Value_destroy(&this->err); + Value_clone(&this->err, v); } /* compilation methods */ - -int Auto_find(struct Auto *self, struct Identifier *ident) +int Auto_find(struct Auto *this, struct Identifier *ident) { struct Symbol *find; - for (find = self->cur; find != (struct Symbol *)0; find = find->next) + for (find = this->cur; find != (struct Symbol *)0; find = find->next) { const char *s = ident->name; const char *r = find->name; @@ -266,12 +263,12 @@ int Auto_find(struct Auto *self, struct Identifier *ident) return 0; } -int Auto_variable(struct Auto *self, const struct Identifier *ident) +int Auto_variable(struct Auto *this, const struct Identifier *ident) { struct Symbol **tail; int offset; - for (offset = 0, tail = &self->cur; + for (offset = 0, tail = &this->cur; *tail != (struct Symbol *)0; tail = &(*tail)->next, ++offset) { @@ -292,31 +289,28 @@ int Auto_variable(struct Auto *self, const struct Identifier *ident) (*tail) = malloc(sizeof(struct Symbol)); (*tail)->next = (struct Symbol *)0; - (*tail)->name = strdup(ident->name); + (*tail)->name = strcpy(malloc(strlen(ident->name) + 1), ident->name); (*tail)->type = LOCALVAR; (*tail)->u.local.type = ident->defaultType; - /* the offset -1 of the V_VOID procedure return symbol is ok, - * it is not used - */ + /* the offset -1 of the V_VOID procedure return symbol is ok, it is not used */ (*tail)->u.local.offset = - offset - (self->cur->u.local.type == V_VOID ? 1 : 0); + offset - (this->cur->u.local.type == V_VOID ? 1 : 0); return 1; } -enum ValueType Auto_argType(const struct Auto *self, int l) +enum ValueType Auto_argType(const struct Auto *this, int l) { struct Symbol *find; int offset; - if (self->cur->u.local.type == V_VOID) + if (this->cur->u.local.type == V_VOID) { ++l; } - for (offset = 0, find = self->cur; l != offset; - find = find->next, ++offset) + for (offset = 0, find = this->cur; l != offset; find = find->next, ++offset) { assert(find != (struct Symbol *)0); } @@ -325,11 +319,11 @@ enum ValueType Auto_argType(const struct Auto *self, int l) return find->u.local.type; } -enum ValueType Auto_varType(const struct Auto *self, struct Symbol *sym) +enum ValueType Auto_varType(const struct Auto *this, struct Symbol *sym) { struct Symbol *find; - for (find = self->cur; + for (find = this->cur; find->u.local.offset != sym->u.local.offset; find = find->next) { @@ -340,11 +334,11 @@ enum ValueType Auto_varType(const struct Auto *self, struct Symbol *sym) return find->u.local.type; } -void Auto_funcEnd(struct Auto *self) +void Auto_funcEnd(struct Auto *this) { struct Symbol **tail; - for (tail = &self->all; *tail != NULL; tail = &(*tail)->next); - *tail = self->cur; - self->cur = (struct Symbol *)0; + for (tail = &this->all; *tail != (struct Symbol *)0; tail = &(*tail)->next); + *tail = this->cur; + this->cur = (struct Symbol *)0; } diff --git a/interpreters/bas/bas_auto.h b/interpreters/bas/bas_auto.h index 4aaa6878b..d48511ffb 100644 --- a/interpreters/bas/bas_auto.h +++ b/interpreters/bas/bas_auto.h @@ -1,8 +1,7 @@ /**************************************************************************** * apps/interpreters/bas/bas_auto.h * - * SPDX-License-Identifier: MIT - * SPDX-FileCopyrightText: 1999-2014 Michael Haardt + * Copyright (c) 1999-2014 Michael Haardt * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -81,21 +80,21 @@ union AutoSlot * Public Function Prototypes ****************************************************************************/ -struct Auto *Auto_new(struct Auto *self); -void Auto_destroy(struct Auto *self); -struct Var *Auto_pushArg(struct Auto *self); -void Auto_pushFuncRet(struct Auto *self, int firstarg, struct Pc *pc); -void Auto_pushGosubRet(struct Auto *self, struct Pc *pc); -struct Var *Auto_local(struct Auto *self, int l); -int Auto_funcReturn(struct Auto *self, struct Pc *pc); -int Auto_gosubReturn(struct Auto *self, struct Pc *pc); -void Auto_frameToError(struct Auto *self, struct Program *program, struct Value *v); -void Auto_setError(struct Auto *self, long int line, struct Pc *pc, struct Value *v); +struct Auto *Auto_new(struct Auto *this); +void Auto_destroy(struct Auto *this); +struct Var *Auto_pushArg(struct Auto *this); +void Auto_pushFuncRet(struct Auto *this, int firstarg, struct Pc *pc); +void Auto_pushGosubRet(struct Auto *this, struct Pc *pc); +struct Var *Auto_local(struct Auto *this, int l); +int Auto_funcReturn(struct Auto *this, struct Pc *pc); +int Auto_gosubReturn(struct Auto *this, struct Pc *pc); +void Auto_frameToError(struct Auto *this, struct Program *program, struct Value *v); +void Auto_setError(struct Auto *this, long int line, struct Pc *pc, struct Value *v); -int Auto_find(struct Auto *self, struct Identifier *ident); -int Auto_variable(struct Auto *self, const struct Identifier *ident); -enum ValueType Auto_argType(const struct Auto *self, int l); -enum ValueType Auto_varType(const struct Auto *self, struct Symbol *sym); -void Auto_funcEnd(struct Auto *self); +int Auto_find(struct Auto *this, struct Identifier *ident); +int Auto_variable(struct Auto *this, const struct Identifier *ident); +enum ValueType Auto_argType(const struct Auto *this, int l); +enum ValueType Auto_varType(const struct Auto *this, struct Symbol *sym); +void Auto_funcEnd(struct Auto *this); #endif /* __APPS_EXAMPLES_BAS_BAS_AUTO_H */ diff --git a/interpreters/bas/bas_autotypes.h b/interpreters/bas/bas_autotypes.h index b1dd547b9..ac08d144f 100644 --- a/interpreters/bas/bas_autotypes.h +++ b/interpreters/bas/bas_autotypes.h @@ -1,8 +1,7 @@ /**************************************************************************** * apps/interpreters/bas/bas_autotypes.h * - * SPDX-License-Identifier: MIT - * SPDX-FileCopyrightText: 1999-2014 Michael Haardt + * Copyright (c) 1999-2014 Michael Haardt * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), diff --git a/interpreters/bas/bas_error.h b/interpreters/bas/bas_error.h index 58fe4dd2d..d0f50a035 100644 --- a/interpreters/bas/bas_error.h +++ b/interpreters/bas/bas_error.h @@ -1,8 +1,7 @@ /**************************************************************************** * apps/interpreters/bas/bas_error.h * - * SPDX-License-Identifier: MIT - * SPDX-FileCopyrightText: 1999-2014 Michael Haardt + * Copyright (c) 1999-2014 Michael Haardt * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -84,7 +83,7 @@ #define STRAYELSE2 STATIC+46, _("`else' without `end if'") #define STRAYENDIF STATIC+47, _("`end if' without multiline `if' or `else'") #define STRAYSUBEND STATIC+49, _("`subend', `end sub' or `endproc' without `sub' or `def proc' inside %s") -#define STRAYSUBEXIT STATIC+50, _("`subexit' without `sub' inside") +#define STRAYSUBEXIT STATIC+50, _("`subexit' without `sub' inside %s") #define STRAYENDSELECT STATIC+51, _("`end select' without `select case'") #define STRAYENDFN STATIC+52, _("`end function' without `def fn' or `function'") #define STRAYENDEQ STATIC+53, _("`=' returning from function without `def fn'") diff --git a/interpreters/bas/bas_fs.c b/interpreters/bas/bas_fs.c index ad708a912..a959c407c 100644 --- a/interpreters/bas/bas_fs.c +++ b/interpreters/bas/bas_fs.c @@ -1,8 +1,8 @@ /**************************************************************************** * apps/interpreters/bas/bas_fs.c + * BASIC file system interface. * - * SPDX-License-Identifier: MIT - * SPDX-FileCopyrightText: 1999-2014 Michael Haardt + * Copyright (c) 1999-2014 Michael Haardt * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -270,7 +270,7 @@ static int edit(int chn, int nl) { if (f->inCapacity) { -#ifdef CONFIG_INTERPRETERS_BAS_VT100 +#ifdef CONFIG_INTERPRETER_BAS_VT100 /* Could use vt100_clrtoeol */ #endif /* Is the previous char in buffer 2 char escape sequence? */ @@ -294,22 +294,64 @@ static int edit(int chn, int nl) } else if ((f->inCapacity + 1) < sizeof(f->inBuf)) { - /* Is this a new line character */ +#ifdef CONFIG_EOL_IS_BOTH_CRLF + /* Ignore carriage returns that may accompany a CRLF sequence. */ - if (ch != '\n') + if (ch != '\r') +#endif { - /* No.. escape control characters other than newline and - * carriage return - */ + /* Is this a new line character */ - if (ch >= '\0' && ch < ' ') +#ifdef CONFIG_EOL_IS_CR + if (ch != '\r') +#elif defined(CONFIG_EOL_IS_LF) + if (ch != '\n') +#elif defined(CONFIG_EOL_IS_EITHER_CRLF) + if (ch != '\n' && ch != '\r') +#endif { - FS_putChar(chn, '^'); - FS_putChar(chn, ch ? (ch + 'a' - 1) : '@'); - } - } + /* No.. escape control characters other than newline and + * carriage return + */ - f->inBuf[f->inCapacity++] = ch; + if (ch >= '\0' && ch < ' ') + { + FS_putChar(chn, '^'); + FS_putChar(chn, ch ? (ch + 'a' - 1) : '@'); + } + + /* Output normal, printable characters */ + + else + { + FS_putChar(chn, ch); + } + } + + /* It is a newline */ + + else + { + /* Echo the newline (or not). We always use newline + * termination when talking to the host. + */ + + if (nl) + { + FS_putChar(chn, '\n'); + } + +#if defined(CONFIG_EOL_IS_CR) || defined(CONFIG_EOL_IS_EITHER_CRLF) + /* If the host is talking to us with CR line terminations, + * switch to use LF internally. + */ + + ch = '\n'; +#endif + } + + f->inBuf[f->inCapacity++] = ch; + } } } while (ch != '\n'); @@ -319,7 +361,7 @@ static int edit(int chn, int nl) static int cls(int chn) { -#ifdef CONFIG_INTERPRETERS_BAS_VT100 +#ifdef CONFIG_INTERPRETER_BAS_VT100 vt100_clrscreen(chn); vt100_cursorhome(chn); return 0; @@ -331,7 +373,7 @@ static int cls(int chn) static int locate(int chn, int line, int column) { -#ifdef CONFIG_INTERPRETERS_BAS_VT100 +#ifdef CONFIG_INTERPRETER_BAS_VT100 vt100_setcursor(chn, line, column); return 0; #else @@ -342,7 +384,7 @@ static int locate(int chn, int line, int column) static int colour(int chn, int foreground, int background) { -#ifdef CONFIG_INTERPRETERS_BAS_VT100 +#ifdef CONFIG_INTERPRETER_BAS_VT100 if (foreground >= 0) { vt100_foreground_color(chn, foreground); @@ -362,7 +404,7 @@ static int colour(int chn, int foreground, int background) static int resetcolour(int chn) { -#ifdef CONFIG_INTERPRETERS_BAS_VT100 +#ifdef CONFIG_INTERPRETER_BAS_VT100 vt100_foreground_color(chn, VT100_DEFAULT); vt100_background_color(chn, VT100_DEFAULT); #endif @@ -388,7 +430,11 @@ int FS_opendev(int chn, int infd, int outfd) g_file[chn] = malloc(sizeof(struct FileStream)); g_file[chn]->dev = 1; +#ifdef CONFIG_SERIAL_TERMIOS g_file[chn]->tty = (infd == 0 ? isatty(infd) && isatty(outfd) : 0); +#else + g_file[chn]->tty = 1; +#endif g_file[chn]->recLength = 1; g_file[chn]->infd = infd; g_file[chn]->inSize = 0; @@ -410,12 +456,9 @@ int FS_opendev(int chn, int infd, int outfd) int FS_openin(const char *name) { - int chn; - int fd; + int chn, fd; - fd = open(name, O_RDONLY); - - if (fd < 0) + if ((fd = open(name, O_RDONLY)) == -1) { FS_errmsg = strerror(errno); return -1; @@ -504,12 +547,9 @@ int FS_openinChn(int chn, const char *name, int mode) int FS_openout(const char *name) { - int chn; - int fd; + int chn, fd; - fd = open(name, O_WRONLY | O_TRUNC | O_CREAT, 0666); - - if (fd < 0) + if ((fd = open(name, O_WRONLY | O_TRUNC | O_CREAT, 0666)) == -1) { FS_errmsg = strerror(errno); return -1; @@ -777,10 +817,12 @@ int FS_close(int dev) return 0; } +#ifdef CONFIG_SERIAL_TERMIOS int FS_istty(int chn) { return (g_file[chn] && g_file[chn]->tty); } +#endif int FS_lock(int chn, off_t offset, off_t length, int mode, int w) { @@ -837,7 +879,7 @@ int FS_lock(int chn, off_t offset, off_t length, int mode, int w) int FS_truncate(int chn) { -#ifdef CONFIG_INTERPRETERS_BAS_HAVE_FTRUNCATE +#ifdef CONFIG_INTERPRETER_BAS_HAVE_FTRUNCATE int fd; off_t o; @@ -890,8 +932,7 @@ void FS_xonxoff(int chn, int on) int FS_put(int chn) { - ssize_t offset; - size_t written; + ssize_t offset, written; if (opened(chn, 2) == -1) { @@ -1377,8 +1418,7 @@ int FS_getChar(int dev) int FS_get(int chn) { - ssize_t offset; - size_t rd; + ssize_t offset, rd; if (opened(chn, 2) == -1) { @@ -1411,7 +1451,7 @@ int FS_inkeyChar(int dev, int ms) struct FileStream *f; char c; ssize_t len; -#ifdef CONFIG_INTERPRETERS_BAS_USE_SELECT +#ifdef CONFIG_INTERPRETER_BAS_USE_SELECT fd_set just_infd; struct timeval timeout; #endif @@ -1427,7 +1467,7 @@ int FS_inkeyChar(int dev, int ms) return f->inBuf[f->inSize++]; } -#ifdef CONFIG_INTERPRETERS_BAS_USE_SELECT +#ifdef CONFIG_INTERPRETER_BAS_USE_SELECT FD_ZERO(&just_infd); FD_SET(f->infd, &just_infd); timeout.tv_sec = ms / 1000; @@ -1504,8 +1544,7 @@ int FS_eof(int chn) long int FS_loc(int chn) { int fd; - off_t cur; - off_t offset = 0; + off_t cur, offset = 0; if (opened(chn, -1) == -1) { @@ -1755,11 +1794,9 @@ int FS_charpos(int chn) int FS_copy(const char *from, const char *to) { - int infd; - int outfd; + int infd, outfd; char buf[4096]; - ssize_t inlen; - ssize_t outlen = -1; + ssize_t inlen, outlen = -1; if ((infd = open(from, O_RDONLY)) == -1) { diff --git a/interpreters/bas/bas_fs.h b/interpreters/bas/bas_fs.h index 38ddb1553..781c4dbd0 100644 --- a/interpreters/bas/bas_fs.h +++ b/interpreters/bas/bas_fs.h @@ -1,8 +1,7 @@ /**************************************************************************** * apps/interpreters/bas/bas_fs.h * - * SPDX-License-Identifier: MIT - * SPDX-FileCopyrightText: 1999-2014 Michael Haardt + * Copyright (c) 1999-2014 Michael Haardt * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -14,8 +13,8 @@ * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING @@ -70,24 +69,20 @@ struct FileStream { - int dev; - int tty; + int dev,tty; int recLength; int infd; char inBuf[1024]; - size_t inSize; - size_t inCapacity; + size_t inSize,inCapacity; int outfd; int outPos; int outLineWidth; int outColWidth; char outBuf[1024]; - size_t outSize; - size_t outCapacity; - int outforeground; - int outbackground; + size_t outSize,outCapacity; + int outforeground,outbackground; int randomfd; int recPos; @@ -117,7 +112,13 @@ int FS_openbinaryChn(int chn, const char *name, int mode); int FS_freechn(void); int FS_flush(int dev); int FS_close(int dev); + +#ifdef CONFIG_SERIAL_TERMIOS int FS_istty(int chn); +#else +# define FS_istty(chn) (1) +#endif + int FS_lock(int chn, off_t offset, off_t length, int mode, int w); int FS_truncate(int chn); void FS_shellmode(int chn); diff --git a/interpreters/bas/bas_global.c b/interpreters/bas/bas_global.c index 480ac47db..78515c653 100644 --- a/interpreters/bas/bas_global.c +++ b/interpreters/bas/bas_global.c @@ -1,8 +1,8 @@ /**************************************************************************** * apps/interpreters/bas/bas_global.c + * Global variables and functions. * - * SPDX-License-Identifier: MIT - * SPDX-FileCopyrightText: 1999-2014 Michael Haardt + * Copyright (c) 1999-2014 Michael Haardt * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -14,8 +14,8 @@ * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING @@ -179,7 +179,7 @@ static struct Value *hex(struct Value *v, long int value, long int digits) { char buf[sizeof(long int) * 2 + 1]; - snprintf(buf, sizeof(buf), "%0*lx", (int)digits, value); + sprintf(buf, "%0*lx", (int)digits, value); Value_new_STRING(v); String_appendChars(&v->u.string, buf); return v; @@ -188,8 +188,7 @@ static struct Value *hex(struct Value *v, long int value, long int digits) static struct Value *find(struct Value *v, struct String *pattern, long int occurrence) { - struct String dirname; - struct String basename; + struct String dirname, basename; char *slash; DIR *dir; struct dirent *ent; @@ -323,8 +322,8 @@ static struct Value *string(struct Value *v, long int len, int c) return v; } -static struct Value *mid(struct Value *v, struct String *s, - long int position, long int length) +static struct Value *mid(struct Value *v, struct String *s, long int position, + long int length) { --position; if (position < 0) @@ -521,8 +520,7 @@ static struct Value *fn_binid(struct Value *v, struct Auto *stack) static struct Value *fn_bindd(struct Value *v, struct Auto *stack) { int overflow; - long int n; - long int digits; + long int n, digits; n = Value_toi(realValue(stack, 0), &overflow); if (overflow) @@ -686,16 +684,14 @@ static struct Value *fn_date(struct Value *v, struct Auto *stack) String_size(&v->u.string, 10); time(&t); now = localtime(&t); - snprintf(v->u.string.character, v->u.string.length + 1, - "%02d-%02d-%04d", now->tm_mon + 1, - now->tm_mday, now->tm_year + 1900); + sprintf(v->u.string.character, "%02d-%02d-%04d", now->tm_mon + 1, + now->tm_mday, now->tm_year + 1900); return v; } static struct Value *fn_dec(struct Value *v, struct Auto *stack) { - struct Value value; - struct Value *arg; + struct Value value, *arg; size_t using; Value_new_STRING(v); @@ -722,10 +718,7 @@ static struct Value *fn_det(struct Value *v, struct Auto *stack) static struct Value *fn_edit(struct Value *v, struct Auto *stack) { int code; - char *begin; - char *end; - char *rd; - char *wr; + char *begin, *end, *rd, *wr; char quote; code = intValue(stack, 1); @@ -762,12 +755,11 @@ static struct Value *fn_edit(struct Value *v, struct Auto *stack) } /* 4 - Discard all carriage returns, line feeds, form feeds, deletes, - * escapes, and nulls - */ + * escapes, and nulls */ if ((code & 4) && - (*rd == '\r' || *rd == '\n' || *rd == '\f' || *rd == 127 || - *rd == 27 || *rd == '\0')) + (*rd == '\r' || *rd == '\n' || *rd == '\f' || *rd == 127 || *rd == 27 + || *rd == '\0')) { ++rd; continue; @@ -965,7 +957,7 @@ static struct Value *fn_hexi(struct Value *v, struct Auto *stack) { char buf[sizeof(long int) * 2 + 1]; - snprintf(buf, sizeof(buf), "%lx", intValue(stack, 0)); + sprintf(buf, "%lx", intValue(stack, 0)); Value_new_STRING(v); String_appendChars(&v->u.string, buf); return v; @@ -983,7 +975,7 @@ static struct Value *fn_hexd(struct Value *v, struct Auto *stack) return Value_new_ERROR(v, OUTOFRANGE, _("number")); } - snprintf(buf, sizeof(buf), "%lx", n); + sprintf(buf, "%lx", n); Value_new_STRING(v); String_appendChars(&v->u.string, buf); return v; @@ -1004,7 +996,6 @@ static struct Value *fn_hexdi(struct Value *v, struct Auto *stack) { return Value_new_ERROR(v, OUTOFRANGE, _("number")); } - return hex(v, n, intValue(stack, 1)); } @@ -1210,8 +1201,8 @@ static struct Value *fn_instr3ssd(struct Value *v, struct Auto *stack) static struct Value *fn_instr4ii(struct Value *v, struct Auto *stack) { - return instr(v, intValue(stack, 2), intValue(stack, 3), - stringValue(stack, 0), stringValue(stack, 1)); + return instr(v, intValue(stack, 2), intValue(stack, 3), stringValue(stack, 0), + stringValue(stack, 1)); } static struct Value *fn_instr4id(struct Value *v, struct Auto *stack) @@ -1511,8 +1502,7 @@ static struct Value *fn_mid2d(struct Value *v, struct Auto *stack) static struct Value *fn_mid3ii(struct Value *v, struct Auto *stack) { - return mid(v, stringValue(stack, 0), - intValue(stack, 1), intValue(stack, 2)); + return mid(v, stringValue(stack, 0), intValue(stack, 1), intValue(stack, 2)); } static struct Value *fn_mid3id(struct Value *v, struct Auto *stack) @@ -1640,7 +1630,7 @@ static struct Value *fn_oct(struct Value *v, struct Auto *stack) { char buf[sizeof(long int) * 3 + 1]; - snprintf(buf, sizeof(buf), "%lo", intValue(stack, 0)); + sprintf(buf, "%lo", intValue(stack, 0)); Value_new_STRING(v); String_appendChars(&v->u.string, buf); return v; @@ -1911,9 +1901,8 @@ static struct Value *fn_times(struct Value *v, struct Auto *stack) String_size(&v->u.string, 8); time(&t); now = localtime(&t); - snprintf(v->u.string.character, v->u.string.length + 1, - "%02d:%02d:%02d", now->tm_hour, now->tm_min, - now->tm_sec); + sprintf(v->u.string.character, "%02d:%02d:%02d", now->tm_hour, now->tm_min, + now->tm_sec); return v; } @@ -1942,7 +1931,6 @@ static struct Value *fn_tl(struct Value *v, struct Auto *stack) memcpy(v->u.string.character, s->character + 1, tail); } } - return v; } @@ -1978,7 +1966,7 @@ static struct Value *fn_val(struct Value *v, struct Auto *stack) } else { - return Value_new_REAL(v, Value_vald(s->character, NULL, &overflow)); + return Value_new_REAL(v, Value_vald(s->character, (char **)0, &overflow)); } } @@ -1995,25 +1983,24 @@ static unsigned int hash(const char *s) return h % GLOBAL_HASHSIZE; } -static void builtin(struct Global *self, - const char *ident, enum ValueType type, +static void builtin(struct Global *this, const char *ident, enum ValueType type, struct Value *(*func) (struct Value * value, - struct Auto * stack), - int argLength, ...) + struct Auto * stack), int argLength, + ...) { struct Symbol **r; struct Symbol *s, **sptr; int i; va_list ap; - for (r = &self->table[hash(ident)]; + for (r = &this->table[hash(ident)]; *r != (struct Symbol *)0 && cistrcmp((*r)->name, ident); r = &((*r)->next)); if (*r == (struct Symbol *)0) { *r = malloc(sizeof(struct Symbol)); - (*r)->name = strdup(ident); + (*r)->name = strcpy(malloc(strlen(ident) + 1), ident); (*r)->next = (struct Symbol *)0; s = (*r); } @@ -2046,192 +2033,168 @@ static void builtin(struct Global *self, * Public Functions ****************************************************************************/ -struct Global *Global_new(struct Global *self) +struct Global *Global_new(struct Global *this) { - builtin(self, "abs", V_REAL, fn_abs, 1, (int)V_REAL); - builtin(self, "asc", V_INTEGER, fn_asc, 1, (int)V_STRING); - builtin(self, "atn", V_REAL, fn_atn, 1, (int)V_REAL); - builtin(self, "bin$", V_STRING, fn_bini, 1, (int)V_INTEGER); - builtin(self, "bin$", V_STRING, fn_bind, 1, (int)V_REAL); - builtin(self, "bin$", V_STRING, fn_binii, 2, + builtin(this, "abs", V_REAL, fn_abs, 1, (int)V_REAL); + builtin(this, "asc", V_INTEGER, fn_asc, 1, (int)V_STRING); + builtin(this, "atn", V_REAL, fn_atn, 1, (int)V_REAL); + builtin(this, "bin$", V_STRING, fn_bini, 1, (int)V_INTEGER); + builtin(this, "bin$", V_STRING, fn_bind, 1, (int)V_REAL); + builtin(this, "bin$", V_STRING, fn_binii, 2, (int)V_INTEGER, (int)V_INTEGER); + builtin(this, "bin$", V_STRING, fn_bindi, 2, (int)V_REAL, (int)V_INTEGER); + builtin(this, "bin$", V_STRING, fn_binid, 2, (int)V_INTEGER, (int)V_REAL); + builtin(this, "bin$", V_STRING, fn_bindd, 2, (int)V_REAL, (int)V_REAL); + builtin(this, "chr$", V_STRING, fn_chr, 1, (int)V_INTEGER); + builtin(this, "cint", V_REAL, fn_cint, 1, (int)V_REAL); + builtin(this, "code", V_INTEGER, fn_asc, 1, (int)V_STRING); + builtin(this, "command$", V_STRING, fn_command, 0); + builtin(this, "command$", V_STRING, fn_commandi, 1, (int)V_INTEGER); + builtin(this, "command$", V_STRING, fn_commandd, 1, (int)V_REAL); + builtin(this, "cos", V_REAL, fn_cos, 1, (int)V_REAL); + builtin(this, "cvi", V_INTEGER, fn_cvi, 1, (int)V_STRING); + builtin(this, "cvs", V_REAL, fn_cvs, 1, (int)V_STRING); + builtin(this, "cvd", V_REAL, fn_cvd, 1, (int)V_STRING); + builtin(this, "date$", V_STRING, fn_date, 0); + builtin(this, "dec$", V_STRING, fn_dec, 2, (int)V_REAL, (int)V_STRING); + builtin(this, "dec$", V_STRING, fn_dec, 2, (int)V_INTEGER, (int)V_STRING); + builtin(this, "dec$", V_STRING, fn_dec, 2, (int)V_STRING, (int)V_STRING); + builtin(this, "deg", V_REAL, fn_deg, 1, (int)V_REAL); + builtin(this, "det", V_REAL, fn_det, 0); + builtin(this, "edit$", V_STRING, fn_edit, 2, (int)V_STRING, (int)V_INTEGER); + builtin(this, "environ$", V_STRING, fn_environi, 1, (int)V_INTEGER); + builtin(this, "environ$", V_STRING, fn_environd, 1, (int)V_REAL); + builtin(this, "environ$", V_STRING, fn_environs, 1, (int)V_STRING); + builtin(this, "eof", V_INTEGER, fn_eof, 1, (int)V_INTEGER); + builtin(this, "erl", V_INTEGER, fn_erl, 0); + builtin(this, "err", V_INTEGER, fn_err, 0); + builtin(this, "exp", V_REAL, fn_exp, 1, (int)V_REAL); + builtin(this, "false", V_INTEGER, fn_false, 0); + builtin(this, "find$", V_STRING, fn_find, 1, (int)V_STRING); + builtin(this, "find$", V_STRING, fn_findi, 2, (int)V_STRING, (int)V_INTEGER); + builtin(this, "find$", V_STRING, fn_findd, 2, (int)V_STRING, (int)V_REAL); + builtin(this, "fix", V_REAL, fn_fix, 1, (int)V_REAL); + builtin(this, "frac", V_REAL, fn_frac, 1, (int)V_REAL); + builtin(this, "freefile", V_INTEGER, fn_freefile, 0); + builtin(this, "fp", V_REAL, fn_frac, 1, (int)V_REAL); + builtin(this, "hex$", V_STRING, fn_hexi, 1, (int)V_INTEGER); + builtin(this, "hex$", V_STRING, fn_hexd, 1, (int)V_REAL); + builtin(this, "hex$", V_STRING, fn_hexii, 2, (int)V_INTEGER, (int)V_INTEGER); + builtin(this, "hex$", V_STRING, fn_hexdi, 2, (int)V_REAL, (int)V_INTEGER); + builtin(this, "hex$", V_STRING, fn_hexid, 2, (int)V_INTEGER, (int)V_REAL); + builtin(this, "hex$", V_STRING, fn_hexdd, 2, (int)V_REAL, (int)V_REAL); + builtin(this, "inkey$", V_STRING, fn_inkey, 0); + builtin(this, "inkey$", V_STRING, fn_inkeyi, 1, (int)V_INTEGER); + builtin(this, "inkey$", V_STRING, fn_inkeyd, 1, (int)V_REAL); + builtin(this, "inkey$", V_STRING, fn_inkeyii, 2, (int)V_INTEGER, (int)V_INTEGER); + builtin(this, "inkey$", V_STRING, fn_inkeyid, 2, (int)V_INTEGER, (int)V_REAL); + builtin(this, "inkey$", V_STRING, fn_inkeydi, 2, (int)V_REAL, (int)V_INTEGER); + builtin(this, "inkey$", V_STRING, fn_inkeydd, 2, (int)V_REAL, (int)V_REAL); + builtin(this, "inp", V_INTEGER, fn_inp, 1, (int)V_INTEGER); + builtin(this, "input$", V_STRING, fn_input1, 1, (int)V_INTEGER); + builtin(this, "input$", V_STRING, fn_input2, 2, (int)V_INTEGER, (int)V_INTEGER); + builtin(this, "instr", V_INTEGER, fn_instr2, 2, (int)V_STRING, (int)V_STRING); + builtin(this, "instr", V_INTEGER, fn_instr3iss, 3, (int)V_INTEGER, (int)V_STRING, + V_STRING); + builtin(this, "instr", V_INTEGER, fn_instr3ssi, 3, (int)V_STRING, (int)V_STRING, + V_INTEGER); + builtin(this, "instr", V_INTEGER, fn_instr3dss, 3, (int)V_REAL, (int)V_STRING, + V_STRING); + builtin(this, "instr", V_INTEGER, fn_instr3ssd, 3, (int)V_STRING, (int)V_STRING, + V_REAL); + builtin(this, "instr", V_INTEGER, fn_instr4ii, 4, (int)V_STRING, (int)V_STRING, (int)V_INTEGER, (int)V_INTEGER); - builtin(self, "bin$", V_STRING, fn_bindi, 2, (int)V_REAL, (int)V_INTEGER); - builtin(self, "bin$", V_STRING, fn_binid, 2, (int)V_INTEGER, (int)V_REAL); - builtin(self, "bin$", V_STRING, fn_bindd, 2, (int)V_REAL, (int)V_REAL); - builtin(self, "chr$", V_STRING, fn_chr, 1, (int)V_INTEGER); - builtin(self, "cint", V_REAL, fn_cint, 1, (int)V_REAL); - builtin(self, "code", V_INTEGER, fn_asc, 1, (int)V_STRING); - builtin(self, "command$", V_STRING, fn_command, 0); - builtin(self, "command$", V_STRING, fn_commandi, 1, (int)V_INTEGER); - builtin(self, "command$", V_STRING, fn_commandd, 1, (int)V_REAL); - builtin(self, "cos", V_REAL, fn_cos, 1, (int)V_REAL); - builtin(self, "cvi", V_INTEGER, fn_cvi, 1, (int)V_STRING); - builtin(self, "cvs", V_REAL, fn_cvs, 1, (int)V_STRING); - builtin(self, "cvd", V_REAL, fn_cvd, 1, (int)V_STRING); - builtin(self, "date$", V_STRING, fn_date, 0); - builtin(self, "dec$", V_STRING, fn_dec, 2, (int)V_REAL, (int)V_STRING); - builtin(self, "dec$", V_STRING, fn_dec, 2, (int)V_INTEGER, (int)V_STRING); - builtin(self, "dec$", V_STRING, fn_dec, 2, (int)V_STRING, (int)V_STRING); - builtin(self, "deg", V_REAL, fn_deg, 1, (int)V_REAL); - builtin(self, "det", V_REAL, fn_det, 0); - builtin(self, "edit$", V_STRING, fn_edit, 2, - (int)V_STRING, (int)V_INTEGER); - builtin(self, "environ$", V_STRING, fn_environi, 1, (int)V_INTEGER); - builtin(self, "environ$", V_STRING, fn_environd, 1, (int)V_REAL); - builtin(self, "environ$", V_STRING, fn_environs, 1, (int)V_STRING); - builtin(self, "eof", V_INTEGER, fn_eof, 1, (int)V_INTEGER); - builtin(self, "erl", V_INTEGER, fn_erl, 0); - builtin(self, "err", V_INTEGER, fn_err, 0); - builtin(self, "exp", V_REAL, fn_exp, 1, (int)V_REAL); - builtin(self, "false", V_INTEGER, fn_false, 0); - builtin(self, "find$", V_STRING, fn_find, 1, (int)V_STRING); - builtin(self, "find$", V_STRING, fn_findi, 2, - (int)V_STRING, (int)V_INTEGER); - builtin(self, "find$", V_STRING, fn_findd, 2, (int)V_STRING, (int)V_REAL); - builtin(self, "fix", V_REAL, fn_fix, 1, (int)V_REAL); - builtin(self, "frac", V_REAL, fn_frac, 1, (int)V_REAL); - builtin(self, "freefile", V_INTEGER, fn_freefile, 0); - builtin(self, "fp", V_REAL, fn_frac, 1, (int)V_REAL); - builtin(self, "hex$", V_STRING, fn_hexi, 1, (int)V_INTEGER); - builtin(self, "hex$", V_STRING, fn_hexd, 1, (int)V_REAL); - builtin(self, "hex$", V_STRING, fn_hexii, 2, - (int)V_INTEGER, (int)V_INTEGER); - builtin(self, "hex$", V_STRING, fn_hexdi, 2, (int)V_REAL, (int)V_INTEGER); - builtin(self, "hex$", V_STRING, fn_hexid, 2, (int)V_INTEGER, (int)V_REAL); - builtin(self, "hex$", V_STRING, fn_hexdd, 2, (int)V_REAL, (int)V_REAL); - builtin(self, "inkey$", V_STRING, fn_inkey, 0); - builtin(self, "inkey$", V_STRING, fn_inkeyi, 1, (int)V_INTEGER); - builtin(self, "inkey$", V_STRING, fn_inkeyd, 1, (int)V_REAL); - builtin(self, "inkey$", V_STRING, fn_inkeyii, 2, - (int)V_INTEGER, (int)V_INTEGER); - builtin(self, "inkey$", V_STRING, fn_inkeyid, 2, + builtin(this, "instr", V_INTEGER, fn_instr4id, 4, (int)V_STRING, (int)V_STRING, (int)V_INTEGER, (int)V_REAL); - builtin(self, "inkey$", V_STRING, fn_inkeydi, 2, + builtin(this, "instr", V_INTEGER, fn_instr4di, 4, (int)V_STRING, (int)V_STRING, (int)V_REAL, (int)V_INTEGER); - builtin(self, "inkey$", V_STRING, fn_inkeydd, 2, + builtin(this, "instr", V_INTEGER, fn_instr4dd, 4, (int)V_STRING, (int)V_STRING, (int)V_REAL, (int)V_REAL); - builtin(self, "inp", V_INTEGER, fn_inp, 1, (int)V_INTEGER); - builtin(self, "input$", V_STRING, fn_input1, 1, (int)V_INTEGER); - builtin(self, "input$", V_STRING, fn_input2, 2, - (int)V_INTEGER, (int)V_INTEGER); - builtin(self, "instr", V_INTEGER, fn_instr2, 2, - (int)V_STRING, (int)V_STRING); - builtin(self, "instr", V_INTEGER, fn_instr3iss, 3, - (int)V_INTEGER, (int)V_STRING, (int)V_STRING); - builtin(self, "instr", V_INTEGER, fn_instr3ssi, 3, - (int)V_STRING, (int)V_STRING, (int)V_INTEGER); - builtin(self, "instr", V_INTEGER, fn_instr3dss, 3, - (int)V_REAL, (int)V_STRING, (int)V_STRING); - builtin(self, "instr", V_INTEGER, fn_instr3ssd, 3, - (int)V_STRING, (int)V_STRING, (int)V_REAL); - builtin(self, "instr", V_INTEGER, fn_instr4ii, 4, - (int)V_STRING, (int)V_STRING, (int)V_INTEGER, (int)V_INTEGER); - builtin(self, "instr", V_INTEGER, fn_instr4id, 4, - (int)V_STRING, (int)V_STRING, (int)V_INTEGER, (int)V_REAL); - builtin(self, "instr", V_INTEGER, fn_instr4di, 4, - (int)V_STRING, (int)V_STRING, (int)V_REAL, (int)V_INTEGER); - builtin(self, "instr", V_INTEGER, fn_instr4dd, 4, - (int)V_STRING, (int)V_STRING, (int)V_REAL, (int)V_REAL); - builtin(self, "int", V_REAL, fn_int, 1, (int)V_REAL); - builtin(self, "int%", V_INTEGER, fn_intp, 1, (int)V_REAL); - builtin(self, "ip", V_REAL, fn_fix, 1, (int)V_REAL); - builtin(self, "lcase$", V_STRING, fn_lcase, 1, (int)V_STRING); - builtin(self, "lower$", V_STRING, fn_lcase, 1, (int)V_STRING); - builtin(self, "left$", V_STRING, fn_left, 2, - (int)V_STRING, (int)V_INTEGER); - builtin(self, "len", V_INTEGER, fn_len, 1, (int)V_STRING); - builtin(self, "loc", V_INTEGER, fn_loc, 1, (int)V_INTEGER); - builtin(self, "lof", V_INTEGER, fn_lof, 1, (int)V_INTEGER); - builtin(self, "log", V_REAL, fn_log, 1, (int)V_REAL); - builtin(self, "log10", V_REAL, fn_log10, 1, (int)V_REAL); - builtin(self, "log2", V_REAL, fn_log2, 1, (int)V_REAL); - builtin(self, "ltrim$", V_STRING, fn_ltrim, 1, (int)V_STRING); - builtin(self, "match", V_INTEGER, fn_match, 3, - (int)V_STRING, (int)V_STRING, (int)V_INTEGER); - builtin(self, "max", V_INTEGER, fn_maxii, 2, - (int)V_INTEGER, (int)V_INTEGER); - builtin(self, "max", V_REAL, fn_maxdi, 2, (int)V_REAL, (int)V_INTEGER); - builtin(self, "max", V_REAL, fn_maxid, 2, (int)V_INTEGER, (int)V_REAL); - builtin(self, "max", V_REAL, fn_maxdd, 2, (int)V_REAL, (int)V_REAL); - builtin(self, "mid$", V_STRING, fn_mid2i, 2, - (int)V_STRING, (int)V_INTEGER); - builtin(self, "mid$", V_STRING, fn_mid2d, 2, (int)V_STRING, (int)V_REAL); - builtin(self, "mid$", V_STRING, fn_mid3ii, 3, - (int)V_STRING, (int)V_INTEGER, (int)V_INTEGER); - builtin(self, "mid$", V_STRING, fn_mid3id, 3, - (int)V_STRING, (int)V_INTEGER, (int)V_REAL); - builtin(self, "mid$", V_STRING, fn_mid3di, 3, - (int)V_STRING, (int)V_REAL, (int)V_INTEGER); - builtin(self, "mid$", V_STRING, fn_mid3dd, 3, - (int)V_STRING, (int)V_REAL, (int)V_REAL); - builtin(self, "min", V_INTEGER, fn_minii, 2, - (int)V_INTEGER, (int)V_INTEGER); - builtin(self, "min", V_REAL, fn_mindi, 2, (int)V_REAL, (int)V_INTEGER); - builtin(self, "min", V_REAL, fn_minid, 2, (int)V_INTEGER, (int)V_REAL); - builtin(self, "min", V_REAL, fn_mindd, 2, (int)V_REAL, (int)V_REAL); - builtin(self, "mki$", V_STRING, fn_mki, 1, (int)V_INTEGER); - builtin(self, "mks$", V_STRING, fn_mks, 1, (int)V_REAL); - builtin(self, "mkd$", V_STRING, fn_mkd, 1, (int)V_REAL); - builtin(self, "oct$", V_STRING, fn_oct, 1, (int)V_INTEGER); - builtin(self, "peek", V_INTEGER, fn_peek, 1, (int)V_INTEGER); - builtin(self, "pi", V_REAL, fn_pi, 0); - builtin(self, "pos", V_INTEGER, fn_pos, 1, (int)V_INTEGER); - builtin(self, "pos", V_INTEGER, fn_pos, 1, (int)V_REAL); - builtin(self, "pos", V_INTEGER, fn_instr3ssi, 3, - (int)V_STRING, (int)V_STRING, (int)V_INTEGER); - builtin(self, "pos", V_INTEGER, fn_instr3ssd, 3, - (int)V_STRING, (int)V_STRING, (int)V_REAL); - builtin(self, "rad", V_REAL, fn_rad, 1, (int)V_REAL); - builtin(self, "right$", V_STRING, fn_right, 2, - (int)V_STRING, (int)V_INTEGER); - builtin(self, "rnd", V_INTEGER, fn_rnd, 0); - builtin(self, "rnd", V_INTEGER, fn_rndd, 1, (int)V_REAL); - builtin(self, "rnd", V_INTEGER, fn_rndi, 1, (int)V_INTEGER); - builtin(self, "rtrim$", V_STRING, fn_rtrim, 1, (int)V_STRING); - builtin(self, "seg$", V_STRING, fn_mid3ii, 3, - (int)V_STRING, (int)V_INTEGER, (int)V_INTEGER); - builtin(self, "seg$", V_STRING, fn_mid3id, 3, - (int)V_STRING, (int)V_INTEGER, (int)V_REAL); - builtin(self, "seg$", V_STRING, fn_mid3di, 3, (int)V_STRING, (int)V_REAL, + builtin(this, "int", V_REAL, fn_int, 1, (int)V_REAL); + builtin(this, "int%", V_INTEGER, fn_intp, 1, (int)V_REAL); + builtin(this, "ip", V_REAL, fn_fix, 1, (int)V_REAL); + builtin(this, "lcase$", V_STRING, fn_lcase, 1, (int)V_STRING); + builtin(this, "lower$", V_STRING, fn_lcase, 1, (int)V_STRING); + builtin(this, "left$", V_STRING, fn_left, 2, (int)V_STRING, (int)V_INTEGER); + builtin(this, "len", V_INTEGER, fn_len, 1, (int)V_STRING); + builtin(this, "loc", V_INTEGER, fn_loc, 1, (int)V_INTEGER); + builtin(this, "lof", V_INTEGER, fn_lof, 1, (int)V_INTEGER); + builtin(this, "log", V_REAL, fn_log, 1, (int)V_REAL); + builtin(this, "log10", V_REAL, fn_log10, 1, (int)V_REAL); + builtin(this, "log2", V_REAL, fn_log2, 1, (int)V_REAL); + builtin(this, "ltrim$", V_STRING, fn_ltrim, 1, (int)V_STRING); + builtin(this, "match", V_INTEGER, fn_match, 3, (int)V_STRING, (int)V_STRING, (int)V_INTEGER); - builtin(self, "seg$", V_STRING, fn_mid3dd, 3, (int)V_STRING, (int)V_REAL, + builtin(this, "max", V_INTEGER, fn_maxii, 2, (int)V_INTEGER, (int)V_INTEGER); + builtin(this, "max", V_REAL, fn_maxdi, 2, (int)V_REAL, (int)V_INTEGER); + builtin(this, "max", V_REAL, fn_maxid, 2, (int)V_INTEGER, (int)V_REAL); + builtin(this, "max", V_REAL, fn_maxdd, 2, (int)V_REAL, (int)V_REAL); + builtin(this, "mid$", V_STRING, fn_mid2i, 2, (int)V_STRING, (int)V_INTEGER); + builtin(this, "mid$", V_STRING, fn_mid2d, 2, (int)V_STRING, (int)V_REAL); + builtin(this, "mid$", V_STRING, fn_mid3ii, 3, (int)V_STRING, (int)V_INTEGER, + V_INTEGER); + builtin(this, "mid$", V_STRING, fn_mid3id, 3, (int)V_STRING, (int)V_INTEGER, (int)V_REAL); + builtin(this, "mid$", V_STRING, fn_mid3di, 3, (int)V_STRING, (int)V_REAL, (int)V_INTEGER); + builtin(this, "mid$", V_STRING, fn_mid3dd, 3, (int)V_STRING, (int)V_REAL, (int)V_REAL); + builtin(this, "min", V_INTEGER, fn_minii, 2, (int)V_INTEGER, (int)V_INTEGER); + builtin(this, "min", V_REAL, fn_mindi, 2, (int)V_REAL, (int)V_INTEGER); + builtin(this, "min", V_REAL, fn_minid, 2, (int)V_INTEGER, (int)V_REAL); + builtin(this, "min", V_REAL, fn_mindd, 2, (int)V_REAL, (int)V_REAL); + builtin(this, "mki$", V_STRING, fn_mki, 1, (int)V_INTEGER); + builtin(this, "mks$", V_STRING, fn_mks, 1, (int)V_REAL); + builtin(this, "mkd$", V_STRING, fn_mkd, 1, (int)V_REAL); + builtin(this, "oct$", V_STRING, fn_oct, 1, (int)V_INTEGER); + builtin(this, "peek", V_INTEGER, fn_peek, 1, (int)V_INTEGER); + builtin(this, "pi", V_REAL, fn_pi, 0); + builtin(this, "pos", V_INTEGER, fn_pos, 1, (int)V_INTEGER); + builtin(this, "pos", V_INTEGER, fn_pos, 1, (int)V_REAL); + builtin(this, "pos", V_INTEGER, fn_instr3ssi, 3, (int)V_STRING, (int)V_STRING, + (int)V_INTEGER); + builtin(this, "pos", V_INTEGER, fn_instr3ssd, 3, (int)V_STRING, (int)V_STRING, (int)V_REAL); - builtin(self, "sgn", V_INTEGER, fn_sgn, 1, (int)V_REAL); - builtin(self, "sin", V_REAL, fn_sin, 1, (int)V_REAL); - builtin(self, "space$", V_STRING, fn_space, 1, (int)V_INTEGER); - builtin(self, "sqr", V_REAL, fn_sqr, 1, (int)V_REAL); - builtin(self, "str$", V_STRING, fn_str, 1, (int)V_REAL); - builtin(self, "str$", V_STRING, fn_str, 1, (int)V_INTEGER); - builtin(self, "string$", V_STRING, fn_stringii, 2, - (int)V_INTEGER, (int)V_INTEGER); - builtin(self, "string$", V_STRING, fn_stringid, 2, - (int)V_INTEGER, (int)V_REAL); - builtin(self, "string$", V_STRING, fn_stringdi, 2, - (int)V_REAL, (int)V_INTEGER); - builtin(self, "string$", V_STRING, fn_stringdd, 2, - (int)V_REAL, (int)V_REAL); - builtin(self, "string$", V_STRING, fn_stringis, 2, - (int)V_INTEGER, (int)V_STRING); - builtin(self, "string$", V_STRING, fn_stringds, 2, - (int)V_REAL, (int)V_STRING); - builtin(self, "strip$", V_STRING, fn_strip, 1, (int)V_STRING); - builtin(self, "tan", V_REAL, fn_tan, 1, (int)V_REAL); - builtin(self, "time", V_INTEGER, fn_timei, 0); - builtin(self, "time$", V_STRING, fn_times, 0); - builtin(self, "timer", V_REAL, fn_timer, 0); - builtin(self, "tl$", V_STRING, fn_tl, 1, (int)V_STRING); - builtin(self, "true", V_INTEGER, fn_true, 0); - builtin(self, "ucase$", V_STRING, fn_ucase, 1, (int)V_STRING); - builtin(self, "upper$", V_STRING, fn_ucase, 1, (int)V_STRING); - builtin(self, "val", V_REAL, fn_val, 1, (int)V_STRING); - return self; + builtin(this, "rad", V_REAL, fn_rad, 1, (int)V_REAL); + builtin(this, "right$", V_STRING, fn_right, 2, (int)V_STRING, (int)V_INTEGER); + builtin(this, "rnd", V_INTEGER, fn_rnd, 0); + builtin(this, "rnd", V_INTEGER, fn_rndd, 1, (int)V_REAL); + builtin(this, "rnd", V_INTEGER, fn_rndi, 1, (int)V_INTEGER); + builtin(this, "rtrim$", V_STRING, fn_rtrim, 1, (int)V_STRING); + builtin(this, "seg$", V_STRING, fn_mid3ii, 3, (int)V_STRING, (int)V_INTEGER, + (int)V_INTEGER); + builtin(this, "seg$", V_STRING, fn_mid3id, 3, (int)V_STRING, (int)V_INTEGER, + (int)V_REAL); + builtin(this, "seg$", V_STRING, fn_mid3di, 3, (int)V_STRING, (int)V_REAL, + (int)V_INTEGER); + builtin(this, "seg$", V_STRING, fn_mid3dd, 3, (int)V_STRING, (int)V_REAL, + (int)V_REAL); + builtin(this, "sgn", V_INTEGER, fn_sgn, 1, (int)V_REAL); + builtin(this, "sin", V_REAL, fn_sin, 1, (int)V_REAL); + builtin(this, "space$", V_STRING, fn_space, 1, (int)V_INTEGER); + builtin(this, "sqr", V_REAL, fn_sqr, 1, (int)V_REAL); + builtin(this, "str$", V_STRING, fn_str, 1, (int)V_REAL); + builtin(this, "str$", V_STRING, fn_str, 1, (int)V_INTEGER); + builtin(this, "string$", V_STRING, fn_stringii, 2, (int)V_INTEGER, (int)V_INTEGER); + builtin(this, "string$", V_STRING, fn_stringid, 2, (int)V_INTEGER, (int)V_REAL); + builtin(this, "string$", V_STRING, fn_stringdi, 2, (int)V_REAL, (int)V_INTEGER); + builtin(this, "string$", V_STRING, fn_stringdd, 2, (int)V_REAL, (int)V_REAL); + builtin(this, "string$", V_STRING, fn_stringis, 2, (int)V_INTEGER, (int)V_STRING); + builtin(this, "string$", V_STRING, fn_stringds, 2, (int)V_REAL, (int)V_STRING); + builtin(this, "strip$", V_STRING, fn_strip, 1, (int)V_STRING); + builtin(this, "tan", V_REAL, fn_tan, 1, (int)V_REAL); + builtin(this, "time", V_INTEGER, fn_timei, 0); + builtin(this, "time$", V_STRING, fn_times, 0); + builtin(this, "timer", V_REAL, fn_timer, 0); + builtin(this, "tl$", V_STRING, fn_tl, 1, (int)V_STRING); + builtin(this, "true", V_INTEGER, fn_true, 0); + builtin(this, "ucase$", V_STRING, fn_ucase, 1, (int)V_STRING); + builtin(this, "upper$", V_STRING, fn_ucase, 1, (int)V_STRING); + builtin(this, "val", V_REAL, fn_val, 1, (int)V_STRING); + return this; } -int Global_find(struct Global *self, struct Identifier *ident, int oparen) +int Global_find(struct Global *this, struct Identifier *ident, int oparen) { struct Symbol **r; - for (r = &self->table[hash(ident->name)]; + for (r = &this->table[hash(ident->name)]; *r != (struct Symbol *)0 && ((((*r)->type == GLOBALVAR && oparen) || ((*r)->type == GLOBALARRAY && !oparen)) || @@ -2246,13 +2209,13 @@ int Global_find(struct Global *self, struct Identifier *ident, int oparen) return 1; } -int Global_variable(struct Global *self, struct Identifier *ident, +int Global_variable(struct Global *this, struct Identifier *ident, enum ValueType type, enum SymbolType symbolType, int redeclare) { struct Symbol **r; - for (r = &self->table[hash(ident->name)]; + for (r = &this->table[hash(ident->name)]; *r != (struct Symbol *)0 && ((*r)->type != symbolType || cistrcmp((*r)->name, ident->name)); r = &((*r)->next)); @@ -2260,7 +2223,7 @@ int Global_variable(struct Global *self, struct Identifier *ident, if (*r == (struct Symbol *)0) { *r = malloc(sizeof(struct Symbol)); - (*r)->name = strdup(ident->name); + (*r)->name = strcpy(malloc(strlen(ident->name) + 1), ident->name); (*r)->next = (struct Symbol *)0; (*r)->type = symbolType; Var_new(&((*r)->u.var), type, 0, (unsigned int *)0, 0); @@ -2296,13 +2259,13 @@ int Global_variable(struct Global *self, struct Identifier *ident, return 1; } -int Global_function(struct Global *self, struct Identifier *ident, +int Global_function(struct Global *this, struct Identifier *ident, enum ValueType type, struct Pc *deffn, struct Pc *begin, int argLength, enum ValueType *argTypes) { struct Symbol **r; - for (r = &self->table[hash(ident->name)]; + for (r = &this->table[hash(ident->name)]; *r != (struct Symbol *)0 && cistrcmp((*r)->name, ident->name); r = &((*r)->next)); @@ -2312,7 +2275,7 @@ int Global_function(struct Global *self, struct Identifier *ident, } *r = malloc(sizeof(struct Symbol)); - (*r)->name = strdup(ident->name); + (*r)->name = strcpy(malloc(strlen(ident->name) + 1), ident->name); (*r)->next = (struct Symbol *)0; (*r)->type = USERFUNCTION; (*r)->u.sub.u.def.scope.start = *deffn; @@ -2326,12 +2289,12 @@ int Global_function(struct Global *self, struct Identifier *ident, return 1; } -void Global_endfunction(struct Global *self, struct Identifier *ident, +void Global_endfunction(struct Global *this, struct Identifier *ident, struct Pc *end) { struct Symbol **r; - for (r = &self->table[hash(ident->name)]; + for (r = &this->table[hash(ident->name)]; *r != (struct Symbol *)0 && cistrcmp((*r)->name, ident->name); r = &((*r)->next)); @@ -2339,7 +2302,7 @@ void Global_endfunction(struct Global *self, struct Identifier *ident, (*r)->u.sub.u.def.scope.end = *end; } -void Global_clear(struct Global *self) +void Global_clear(struct Global *this) { int i; @@ -2347,7 +2310,7 @@ void Global_clear(struct Global *self) { struct Symbol *v; - for (v = self->table[i]; v; v = v->next) + for (v = this->table[i]; v; v = v->next) { if (v->type == GLOBALVAR || v->type == GLOBALARRAY) { @@ -2357,13 +2320,13 @@ void Global_clear(struct Global *self) } } -void Global_clearFunctions(struct Global *self) +void Global_clearFunctions(struct Global *this) { int i; for (i = 0; i < GLOBAL_HASHSIZE; ++i) { - struct Symbol **v = &self->table[i], *w; + struct Symbol **v = &this->table[i], *w; struct Symbol *sym; while (*v) @@ -2394,13 +2357,13 @@ void Global_clearFunctions(struct Global *self) } } -void Global_destroy(struct Global *self) +void Global_destroy(struct Global *this) { int i; for (i = 0; i < GLOBAL_HASHSIZE; ++i) { - struct Symbol *v = self->table[i], *w; + struct Symbol *v = this->table[i], *w; struct Symbol *sym; while (v) @@ -2466,6 +2429,6 @@ void Global_destroy(struct Global *self) v = w; } - self->table[i] = (struct Symbol *)0; + this->table[i] = (struct Symbol *)0; } } diff --git a/interpreters/bas/bas_global.h b/interpreters/bas/bas_global.h index f51aae78d..b2d9544d3 100644 --- a/interpreters/bas/bas_global.h +++ b/interpreters/bas/bas_global.h @@ -1,8 +1,7 @@ /**************************************************************************** * apps/interpreters/bas/bas_global.h * - * SPDX-License-Identifier: MIT - * SPDX-FileCopyrightText: 1999-2014 Michael Haardt + * Copyright (c) 1999-2014 Michael Haardt * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -62,17 +61,17 @@ struct Global * Public Function Prototypes ****************************************************************************/ -struct Global *Global_new(struct Global *self); -void Global_destroy(struct Global *self); -void Global_clear(struct Global *self); -void Global_clearFunctions(struct Global *self); -int Global_find(struct Global *self, struct Identifier *ident, int oparen); -int Global_function(struct Global *self, struct Identifier *ident, +struct Global *Global_new(struct Global *this); +void Global_destroy(struct Global *this); +void Global_clear(struct Global *this); +void Global_clearFunctions(struct Global *this); +int Global_find(struct Global *this, struct Identifier *ident, int oparen); +int Global_function(struct Global *this, struct Identifier *ident, enum ValueType type, struct Pc *deffn, struct Pc *begin, int argTypesLength, enum ValueType *argTypes); -void Global_endfunction(struct Global *self, struct Identifier *ident, +void Global_endfunction(struct Global *this, struct Identifier *ident, struct Pc *end); -int Global_variable(struct Global *self, struct Identifier *ident, +int Global_variable(struct Global *this, struct Identifier *ident, enum ValueType type, enum SymbolType symbolType, int redeclare); diff --git a/interpreters/bas/bas_main.c b/interpreters/bas/bas_main.c index c6c9a70ec..986ac1d2f 100644 --- a/interpreters/bas/bas_main.c +++ b/interpreters/bas/bas_main.c @@ -1,8 +1,7 @@ /**************************************************************************** * apps/interpreters/bas/bas_main.c * - * SPDX-License-Identifier: MIT - * SPDX-FileCopyrightText: 1999-2014 Michael Haardt + * Copyright (c) 1999-2014 Michael Haardt * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -84,7 +83,7 @@ int main(int argc, FAR char *argv[]) break; case 'V': - printf("bas %s\n", CONFIG_INTERPRETERS_BAS_VERSION); + printf("bas %s\n", CONFIG_INTERPRETER_BAS_VERSION); exit(0); break; @@ -129,7 +128,7 @@ int main(int argc, FAR char *argv[]) fputs(_("-u Output all tokens in uppercase\n"), stdout); fputs(_("-h Display this help and exit\n"), stdout); - fputs(_("-V Output version information and exit\n"), + fputs(_("-V Ooutput version information and exit\n"), stdout); exit(0); } diff --git a/interpreters/bas/bas_program.c b/interpreters/bas/bas_program.c index 4d281da63..358d560cf 100644 --- a/interpreters/bas/bas_program.c +++ b/interpreters/bas/bas_program.c @@ -1,8 +1,8 @@ /**************************************************************************** * apps/interpreters/bas/bas_program.c + * Program storage. * - * SPDX-License-Identifier: MIT - * SPDX-FileCopyrightText: 1999-2014 Michael Haardt + * Copyright (c) 1999-2014 Michael Haardt * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -67,8 +67,7 @@ struct Xref { struct Pc line; struct LineNumber *next; - } - *lines; + } *lines; struct Xref *l; struct Xref *r; }; @@ -163,8 +162,7 @@ static void Xref_print(struct Xref *root, FS_putChars(chn, "\n "); } - snprintf(buf, sizeof(buf), " %ld", - Program_lineNumber(p, &cur->line)); + sprintf(buf, " %ld", Program_lineNumber(p, &cur->line)); FS_putChars(chn, buf); } while (cur != tail); @@ -176,8 +174,8 @@ static void Xref_print(struct Xref *root, static int cmpLine(const void *a, const void *b) { - const register struct Pc *pcA = (const struct Pc *)a; - const register struct Pc *pcB = (const struct Pc *)b; + const register struct Pc *pcA = (const struct Pc *)a, *pcB = + (const struct Pc *)b; return pcA->line - pcB->line; } @@ -186,15 +184,13 @@ static void printLine(const void *k, struct Program *p, int chn) { char buf[80]; - snprintf(buf, sizeof(buf), "%8ld", - Program_lineNumber(p, (const struct Pc *)k)); + sprintf(buf, "%8ld", Program_lineNumber(p, (const struct Pc *)k)); FS_putChars(chn, buf); } static int cmpName(const void *a, const void *b) { - const register char *funcA = (const char *)a; - const register char *funcB = (const char *)b; + const register char *funcA = (const char *)a, *funcB = (const char *)b; return strcmp(funcA, funcB); } @@ -214,153 +210,151 @@ static void printName(const void *k, struct Program *p, int chn) * Public Functions ****************************************************************************/ -struct Program *Program_new(struct Program *self) +struct Program *Program_new(struct Program *this) { - self->trace = 0; - self->size = 0; - self->numbered = 1; - self->capacity = 0; - self->runnable = 0; - self->unsaved = 0; - self->code = (struct Token **)0; - self->scope = (struct Scope *)0; - String_new(&self->name); - return self; + this->trace = 0; + this->size = 0; + this->numbered = 1; + this->capacity = 0; + this->runnable = 0; + this->unsaved = 0; + this->code = (struct Token **)0; + this->scope = (struct Scope *)0; + String_new(&this->name); + return this; } -void Program_destroy(struct Program *self) +void Program_destroy(struct Program *this) { - while (self->size) + while (this->size) { - Token_destroy(self->code[--self->size]); + Token_destroy(this->code[--this->size]); } - if (self->capacity) + if (this->capacity) { - free(self->code); + free(this->code); } - self->code = (struct Token **)0; - self->scope = (struct Scope *)0; - String_destroy(&self->name); + this->code = (struct Token **)0; + this->scope = (struct Scope *)0; + String_destroy(&this->name); } -void Program_norun(struct Program *self) +void Program_norun(struct Program *this) { - self->runnable = 0; - self->scope = (struct Scope *)0; + this->runnable = 0; + this->scope = (struct Scope *)0; } -void Program_store(struct Program *self, struct Token *line, long int where) +void Program_store(struct Program *this, struct Token *line, long int where) { int i; assert(line->type == T_INTEGER || line->type == T_UNNUMBERED); - self->runnable = 0; - self->unsaved = 1; + this->runnable = 0; + this->unsaved = 1; if (line->type == T_UNNUMBERED) { - self->numbered = 0; + this->numbered = 0; } if (where) { int last = -1; - for (i = 0; i < self->size; ++i) + for (i = 0; i < this->size; ++i) { - assert(self->code[i]->type == T_INTEGER || - self->code[i]->type == T_UNNUMBERED); - if (where > last && where < self->code[i]->u.integer) + assert(this->code[i]->type == T_INTEGER || + this->code[i]->type == T_UNNUMBERED); + if (where > last && where < this->code[i]->u.integer) { - if ((self->size + 1) >= self->capacity) + if ((this->size + 1) >= this->capacity) { - self->code = - realloc(self->code, + this->code = + realloc(this->code, sizeof(struct Token *) * - (self->capacity ? (self->capacity *= - 2) : (self->capacity = 256))); + (this->capacity ? (this->capacity *= + 2) : (this->capacity = 256))); } - memmove(&self->code[i + 1], &self->code[i], - (self->size - i) * sizeof(struct Token *)); - self->code[i] = line; - ++self->size; + memmove(&this->code[i + 1], &this->code[i], + (this->size - i) * sizeof(struct Token *)); + this->code[i] = line; + ++this->size; return; } - else if (where == self->code[i]->u.integer) + else if (where == this->code[i]->u.integer) { - Token_destroy(self->code[i]); - self->code[i] = line; + Token_destroy(this->code[i]); + this->code[i] = line; return; } - last = self->code[i]->u.integer; + last = this->code[i]->u.integer; } } else { - i = self->size; + i = this->size; } - if ((self->size + 1) >= self->capacity) + if ((this->size + 1) >= this->capacity) { - self->code = - realloc(self->code, + this->code = + realloc(this->code, sizeof(struct Token *) * - (self->capacity ? (self->capacity *= 2) - : (self->capacity = 256))); + (this->capacity ? (this->capacity *= 2) + : (this->capacity = 256))); } - self->code[i] = line; - ++self->size; + this->code[i] = line; + ++this->size; } -void Program_delete(struct Program *self, const struct Pc *from, +void Program_delete(struct Program *this, const struct Pc *from, const struct Pc *to) { - int i; - int first; - int last; + int i, first, last; - self->runnable = 0; - self->unsaved = 1; + this->runnable = 0; + this->unsaved = 1; first = from ? from->line : 0; - last = to ? to->line : self->size - 1; + last = to ? to->line : this->size - 1; for (i = first; i <= last; ++i) { - Token_destroy(self->code[i]); + Token_destroy(this->code[i]); } - if ((last + 1) != self->size) + if ((last + 1) != this->size) { - memmove(&self->code[first], &self->code[last + 1], - (self->size - last + 1) * sizeof(struct Token *)); + memmove(&this->code[first], &this->code[last + 1], + (this->size - last + 1) * sizeof(struct Token *)); } - self->size -= (last - first + 1); + this->size -= (last - first + 1); } -void Program_addScope(struct Program *self, struct Scope *scope) +void Program_addScope(struct Program *this, struct Scope *scope) { struct Scope *s; - s = self->scope; - self->scope = scope; + s = this->scope; + this->scope = scope; scope->next = s; } -struct Pc *Program_goLine(struct Program *self, long int line, struct Pc *pc) +struct Pc *Program_goLine(struct Program *this, long int line, struct Pc *pc) { int i; - for (i = 0; i < self->size; ++i) + for (i = 0; i < this->size; ++i) { - if (self->code[i]->type == T_INTEGER && - line == self->code[i]->u.integer) + if (this->code[i]->type == T_INTEGER && + line == this->code[i]->u.integer) { pc->line = i; - pc->token = self->code[i] + 1; + pc->token = this->code[i] + 1; return pc; } } @@ -368,18 +362,18 @@ struct Pc *Program_goLine(struct Program *self, long int line, struct Pc *pc) return (struct Pc *)0; } -struct Pc *Program_fromLine(struct Program *self, long int line, +struct Pc *Program_fromLine(struct Program *this, long int line, struct Pc *pc) { int i; - for (i = 0; i < self->size; ++i) + for (i = 0; i < this->size; ++i) { - if (self->code[i]->type == T_INTEGER && - self->code[i]->u.integer >= line) + if (this->code[i]->type == T_INTEGER && + this->code[i]->u.integer >= line) { pc->line = i; - pc->token = self->code[i] + 1; + pc->token = this->code[i] + 1; return pc; } } @@ -387,17 +381,17 @@ struct Pc *Program_fromLine(struct Program *self, long int line, return (struct Pc *)0; } -struct Pc *Program_toLine(struct Program *self, long int line, struct Pc *pc) +struct Pc *Program_toLine(struct Program *this, long int line, struct Pc *pc) { int i; - for (i = self->size - 1; i >= 0; --i) + for (i = this->size - 1; i >= 0; --i) { - if (self->code[i]->type == T_INTEGER && - self->code[i]->u.integer <= line) + if (this->code[i]->type == T_INTEGER && + this->code[i]->u.integer <= line) { pc->line = i; - pc->token = self->code[i] + 1; + pc->token = this->code[i] + 1; return pc; } } @@ -405,13 +399,13 @@ struct Pc *Program_toLine(struct Program *self, long int line, struct Pc *pc) return (struct Pc *)0; } -int Program_scopeCheck(struct Program *self, struct Pc *pc, struct Pc *fn) +int Program_scopeCheck(struct Program *this, struct Pc *pc, struct Pc *fn) { struct Scope *scope; if (fn == (struct Pc *)0) /* jump from global block must go to global pc */ { - for (scope = self->scope; scope; scope = scope->next) + for (scope = this->scope; scope; scope = scope->next) { if (pc->line < scope->begin.line) { @@ -467,10 +461,10 @@ int Program_scopeCheck(struct Program *self, struct Pc *pc, struct Pc *fn) return 0; } -struct Pc *Program_dataLine(struct Program *self, long int line, +struct Pc *Program_dataLine(struct Program *this, long int line, struct Pc *pc) { - if ((pc = Program_goLine(self, line, pc)) == (struct Pc *)0) + if ((pc = Program_goLine(this, line, pc)) == (struct Pc *)0) { return (struct Pc *)0; } @@ -490,10 +484,10 @@ struct Pc *Program_dataLine(struct Program *self, long int line, return pc; } -struct Pc *Program_imageLine(struct Program *self, long int line, +struct Pc *Program_imageLine(struct Program *this, long int line, struct Pc *pc) { - if ((pc = Program_goLine(self, line, pc)) == (struct Pc *)0) + if ((pc = Program_goLine(this, line, pc)) == (struct Pc *)0) { return (struct Pc *)0; } @@ -519,16 +513,16 @@ struct Pc *Program_imageLine(struct Program *self, long int line, return pc; } -long int Program_lineNumber(const struct Program *self, const struct Pc *pc) +long int Program_lineNumber(const struct Program *this, const struct Pc *pc) { if (pc->line == -1) { return 0; } - if (self->numbered) + if (this->numbered) { - return (self->code[pc->line]->u.integer); + return (this->code[pc->line]->u.integer); } else { @@ -536,30 +530,30 @@ long int Program_lineNumber(const struct Program *self, const struct Pc *pc) } } -struct Pc *Program_beginning(struct Program *self, struct Pc *pc) +struct Pc *Program_beginning(struct Program *this, struct Pc *pc) { - if (self->size == 0) + if (this->size == 0) { return (struct Pc *)0; } else { pc->line = 0; - pc->token = self->code[0] + 1; + pc->token = this->code[0] + 1; return pc; } } -struct Pc *Program_end(struct Program *self, struct Pc *pc) +struct Pc *Program_end(struct Program *this, struct Pc *pc) { - if (self->size == 0) + if (this->size == 0) { return (struct Pc *)0; } else { - pc->line = self->size - 1; - pc->token = self->code[self->size - 1]; + pc->line = this->size - 1; + pc->token = this->code[this->size - 1]; while (pc->token->type != T_EOL) { ++pc->token; @@ -569,31 +563,31 @@ struct Pc *Program_end(struct Program *self, struct Pc *pc) } } -struct Pc *Program_nextLine(struct Program *self, struct Pc *pc) +struct Pc *Program_nextLine(struct Program *this, struct Pc *pc) { - if (pc->line + 1 == self->size) + if (pc->line + 1 == this->size) { return (struct Pc *)0; } else { - pc->token = self->code[++pc->line] + 1; + pc->token = this->code[++pc->line] + 1; return pc; } } -int Program_skipEOL(struct Program *self, struct Pc *pc, int dev, int tr) +int Program_skipEOL(struct Program *this, struct Pc *pc, int dev, int tr) { if (pc->token->type == T_EOL) { - if (pc->line == -1 || pc->line + 1 == self->size) + if (pc->line == -1 || pc->line + 1 == this->size) { return 0; } else { - pc->token = self->code[++pc->line] + 1; - Program_trace(self, pc, dev, tr); + pc->token = this->code[++pc->line] + 1; + Program_trace(this, pc, dev, tr); return 1; } } @@ -603,32 +597,31 @@ int Program_skipEOL(struct Program *self, struct Pc *pc, int dev, int tr) } } -void Program_trace(struct Program *self, struct Pc *pc, int dev, int tr) +void Program_trace(struct Program *this, struct Pc *pc, int dev, int tr) { - if (tr && self->trace && pc->line != -1) + if (tr && this->trace && pc->line != -1) { char buf[40]; - snprintf(buf, sizeof(buf), "<%ld>\n", - self->code[pc->line]->u.integer); + sprintf(buf, "<%ld>\n", this->code[pc->line]->u.integer); FS_putChars(dev, buf); } } -void Program_PCtoError(struct Program *self, struct Pc *pc, struct Value *v) +void Program_PCtoError(struct Program *this, struct Pc *pc, struct Value *v) { struct String s; String_new(&s); if (pc->line >= 0) { - if (pc->line < (self->size - 1) || pc->token->type != T_EOL) + if (pc->line < (this->size - 1) || pc->token->type != T_EOL) { String_appendPrintf(&s, _(" in line %ld at:\n"), - Program_lineNumber(self, pc)); - Token_toString(self->code[pc->line], (struct Token *)0, &s, + Program_lineNumber(this, pc)); + Token_toString(this->code[pc->line], (struct Token *)0, &s, (int *)0, -1); - Token_toString(self->code[pc->line], pc->token, &s, (int *)0, -1); + Token_toString(this->code[pc->line], pc->token, &s, (int *)0, -1); String_appendPrintf(&s, "^\n"); } else @@ -653,7 +646,7 @@ void Program_PCtoError(struct Program *self, struct Pc *pc, struct Value *v) String_destroy(&s); } -struct Value *Program_merge(struct Program *self, int dev, +struct Value *Program_merge(struct Program *this, int dev, struct Value *value) { struct String s; @@ -672,12 +665,12 @@ struct Value *Program_merge(struct Program *self, int dev, line = Token_newCode(s.character); if (line->type == T_INTEGER && line->u.integer > 0) { - Program_store(self, line, - self->numbered ? line->u.integer : 0); + Program_store(this, line, + this->numbered ? line->u.integer : 0); } else if (line->type == T_UNNUMBERED) { - Program_store(self, line, 0); + Program_store(this, line, 0); } else { @@ -698,19 +691,16 @@ struct Value *Program_merge(struct Program *self, int dev, return (struct Value *)0; } -int Program_lineNumberWidth(struct Program *self) +int Program_lineNumberWidth(struct Program *this) { - int i; - int w = 0; + int i, w = 0; - for (i = 0; i < self->size; ++i) + for (i = 0; i < this->size; ++i) { - if (self->code[i]->type == T_INTEGER) + if (this->code[i]->type == T_INTEGER) { - int nw; - int ln; - - for (ln = self->code[i]->u.integer, nw = 1; ln /= 10; ++nw); + int nw, ln; + for (ln = this->code[i]->u.integer, nw = 1; ln /= 10; ++nw); if (nw > w) { w = nw; @@ -721,20 +711,19 @@ int Program_lineNumberWidth(struct Program *self) return w; } -struct Value *Program_list(struct Program *self, int dev, int watchIntr, +struct Value *Program_list(struct Program *this, int dev, int watchIntr, struct Pc *from, struct Pc *to, struct Value *value) { - int i; - int w; + int i, w; int indent = 0; struct String s; - w = Program_lineNumberWidth(self); - for (i = 0; i < self->size; ++i) + w = Program_lineNumberWidth(this); + for (i = 0; i < this->size; ++i) { String_new(&s); - Token_toString(self->code[i], (struct Token *)0, &s, &indent, w); + Token_toString(this->code[i], (struct Token *)0, &s, &indent, w); if ((from == (struct Pc *)0 || from->line <= i) && (to == (struct Pc *)0 || to->line >= i)) { @@ -750,14 +739,14 @@ struct Value *Program_list(struct Program *self, int dev, int watchIntr, return (struct Value *)0; } -struct Value *Program_analyse(struct Program *self, struct Pc *pc, +struct Value *Program_analyse(struct Program *this, struct Pc *pc, struct Value *value) { int i; - for (i = 0; i < self->size; ++i) + for (i = 0; i < this->size; ++i) { - pc->token = self->code[i]; + pc->token = this->code[i]; pc->line = i; if (pc->token->type == T_INTEGER || pc->token->type == T_UNNUMBERED) { @@ -819,14 +808,14 @@ struct Value *Program_analyse(struct Program *self, struct Pc *pc, return (struct Value *)0; } -void Program_renum(struct Program *self, int first, int inc) +void Program_renum(struct Program *this, int first, int inc) { int i; struct Token *token; - for (i = 0; i < self->size; ++i) + for (i = 0; i < this->size; ++i) { - for (token = self->code[i]; token->type != T_EOL; ) + for (token = this->code[i]; token->type != T_EOL; ) { if (token->type == T_GOTO || token->type == T_GOSUB || token->type == T_RESTORE || token->type == T_RESUME || @@ -837,7 +826,7 @@ void Program_renum(struct Program *self, int first, int inc) { struct Pc dst; - if (Program_goLine(self, token->u.integer, &dst)) + if (Program_goLine(this, token->u.integer, &dst)) { token->u.integer = first + dst.line * inc; } @@ -860,30 +849,30 @@ void Program_renum(struct Program *self, int first, int inc) } } - for (i = 0; i < self->size; ++i) + for (i = 0; i < this->size; ++i) { - assert(self->code[i]->type == T_INTEGER || - self->code[i]->type == T_UNNUMBERED); - self->code[i]->type = T_INTEGER; - self->code[i]->u.integer = first + i * inc; + assert(this->code[i]->type == T_INTEGER || + this->code[i]->type == T_UNNUMBERED); + this->code[i]->type = T_INTEGER; + this->code[i]->u.integer = first + i * inc; } - self->numbered = 1; - self->runnable = 0; - self->unsaved = 1; + this->numbered = 1; + this->runnable = 0; + this->unsaved = 1; } -void Program_unnum(struct Program *self) +void Program_unnum(struct Program *this) { char *ref; int i; struct Token *token; - ref = malloc(self->size); - memset(ref, 0, self->size); - for (i = 0; i < self->size; ++i) + ref = malloc(this->size); + memset(ref, 0, this->size); + for (i = 0; i < this->size; ++i) { - for (token = self->code[i]; token->type != T_EOL; ++token) + for (token = this->code[i]; token->type != T_EOL; ++token) { if (token->type == T_GOTO || token->type == T_GOSUB || token->type == T_RESTORE || token->type == T_RESUME) @@ -893,7 +882,7 @@ void Program_unnum(struct Program *self) { struct Pc dst; - if (Program_goLine(self, token->u.integer, &dst)) + if (Program_goLine(this, token->u.integer, &dst)) { ref[dst.line] = 1; } @@ -912,32 +901,32 @@ void Program_unnum(struct Program *self) } } - for (i = 0; i < self->size; ++i) + for (i = 0; i < this->size; ++i) { - assert(self->code[i]->type == T_INTEGER || - self->code[i]->type == T_UNNUMBERED); + assert(this->code[i]->type == T_INTEGER || + this->code[i]->type == T_UNNUMBERED); if (!ref[i]) { - self->code[i]->type = T_UNNUMBERED; - self->numbered = 0; + this->code[i]->type = T_UNNUMBERED; + this->numbered = 0; } } free(ref); - self->runnable = 0; - self->unsaved = 1; + this->runnable = 0; + this->unsaved = 1; } -int Program_setname(struct Program *self, const char *filename) +int Program_setname(struct Program *this, const char *filename) { - if (self->name.length) + if (this->name.length) { - String_delete(&self->name, 0, self->name.length); + String_delete(&this->name, 0, this->name.length); } if (filename) { - return String_appendChars(&self->name, filename); + return String_appendChars(&this->name, filename); } else { @@ -945,26 +934,23 @@ int Program_setname(struct Program *self, const char *filename) } } -void Program_xref(struct Program *self, int chn) +void Program_xref(struct Program *this, int chn) { struct Pc pc; - struct Xref *func; - struct Xref *var; - struct Xref *gosub; - struct Xref *goto_; + struct Xref *func, *var, *gosub, *goto_; int nl = 0; - assert(self->runnable); + assert(this->runnable); func = (struct Xref *)0; var = (struct Xref *)0; gosub = (struct Xref *)0; goto_ = (struct Xref *)0; - for (pc.line = 0; pc.line < self->size; ++pc.line) + for (pc.line = 0; pc.line < this->size; ++pc.line) { struct On *on; - for (on = (struct On *)0, pc.token = self->code[pc.line]; + for (on = (struct On *)0, pc.token = this->code[pc.line]; pc.token->type != T_EOL; ++pc.token) { switch (pc.token->type) @@ -1021,9 +1007,9 @@ void Program_xref(struct Program *self, int chn) } } - for (pc.line = 0; pc.line < self->size; ++pc.line) + for (pc.line = 0; pc.line < this->size; ++pc.line) { - for (pc.token = self->code[pc.line]; pc.token->type != T_EOL; + for (pc.token = this->code[pc.line]; pc.token->type != T_EOL; ++pc.token) { switch (pc.token->type) @@ -1075,7 +1061,7 @@ void Program_xref(struct Program *self, int chn) if (func) { FS_putChars(chn, _("Function Referenced in line\n")); - Xref_print(func, printName, self, chn); + Xref_print(func, printName, this, chn); Xref_destroy(func); nl = 1; } @@ -1088,7 +1074,7 @@ void Program_xref(struct Program *self, int chn) } FS_putChars(chn, _("Variable Referenced in line\n")); - Xref_print(var, printName, self, chn); + Xref_print(var, printName, this, chn); Xref_destroy(func); nl = 1; } @@ -1101,7 +1087,7 @@ void Program_xref(struct Program *self, int chn) } FS_putChars(chn, _("Gosub Referenced in line\n")); - Xref_print(gosub, printLine, self, chn); + Xref_print(gosub, printLine, this, chn); Xref_destroy(gosub); nl = 1; } @@ -1114,7 +1100,7 @@ void Program_xref(struct Program *self, int chn) } FS_putChars(chn, _("Goto Referenced in line\n")); - Xref_print(goto_, printLine, self, chn); + Xref_print(goto_, printLine, this, chn); Xref_destroy(goto_); } } diff --git a/interpreters/bas/bas_program.h b/interpreters/bas/bas_program.h index 712918af9..af540f24a 100644 --- a/interpreters/bas/bas_program.h +++ b/interpreters/bas/bas_program.h @@ -1,8 +1,7 @@ /**************************************************************************** * apps/interpreters/bas/bas_program.h * - * SPDX-License-Identifier: MIT - * SPDX-FileCopyrightText: 1999-2014 Michael Haardt + * Copyright (c) 1999-2014 Michael Haardt * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -38,45 +37,45 @@ * Public Function Prototypes ****************************************************************************/ -struct Program *Program_new(struct Program *self); -void Program_destroy(struct Program *self); -void Program_norun(struct Program *self); -void Program_store(struct Program *self, struct Token *line, +struct Program *Program_new(struct Program *this); +void Program_destroy(struct Program *this); +void Program_norun(struct Program *this); +void Program_store(struct Program *this, struct Token *line, long int where); -void Program_delete(struct Program *self, const struct Pc *from, +void Program_delete(struct Program *this, const struct Pc *from, const struct Pc *to); -void Program_addScope(struct Program *self, struct Scope *scope); -struct Pc *Program_goLine(struct Program *self, long int line, +void Program_addScope(struct Program *this, struct Scope *scope); +struct Pc *Program_goLine(struct Program *this, long int line, struct Pc *pc); -struct Pc *Program_fromLine(struct Program *self, long int line, +struct Pc *Program_fromLine(struct Program *this, long int line, struct Pc *pc); -struct Pc *Program_toLine(struct Program *self, long int line, +struct Pc *Program_toLine(struct Program *this, long int line, struct Pc *pc); -int Program_scopeCheck(struct Program *self, struct Pc *pc, struct Pc *fn); -struct Pc *Program_dataLine(struct Program *self, long int line, +int Program_scopeCheck(struct Program *this, struct Pc *pc, struct Pc *fn); +struct Pc *Program_dataLine(struct Program *this, long int line, struct Pc *pc); -struct Pc *Program_imageLine(struct Program *self, long int line, +struct Pc *Program_imageLine(struct Program *this, long int line, struct Pc *pc); -long int Program_lineNumber(const struct Program *self, +long int Program_lineNumber(const struct Program *this, const struct Pc *pc); -struct Pc *Program_beginning(struct Program *self, struct Pc *pc); -struct Pc *Program_end(struct Program *self, struct Pc *pc); -struct Pc *Program_nextLine(struct Program *self, struct Pc *pc); -int Program_skipEOL(struct Program *self, struct Pc *pc, int dev, int tr); -void Program_trace(struct Program *self, struct Pc *pc, int dev, int tr); -void Program_PCtoError(struct Program *self, struct Pc *pc, +struct Pc *Program_beginning(struct Program *this, struct Pc *pc); +struct Pc *Program_end(struct Program *this, struct Pc *pc); +struct Pc *Program_nextLine(struct Program *this, struct Pc *pc); +int Program_skipEOL(struct Program *this, struct Pc *pc, int dev, int tr); +void Program_trace(struct Program *this, struct Pc *pc, int dev, int tr); +void Program_PCtoError(struct Program *this, struct Pc *pc, struct Value *v); -struct Value *Program_merge(struct Program *self, int dev, +struct Value *Program_merge(struct Program *this, int dev, struct Value *value); -int Program_lineNumberWidth(struct Program *self); -struct Value *Program_list(struct Program *self, int dev, int watchIntr, +int Program_lineNumberWidth(struct Program *this); +struct Value *Program_list(struct Program *this, int dev, int watchIntr, struct Pc *from, struct Pc *to, struct Value *value); -struct Value *Program_analyse(struct Program *self, struct Pc *pc, +struct Value *Program_analyse(struct Program *this, struct Pc *pc, struct Value *value); -void Program_renum(struct Program *self, int first, int inc); -void Program_unnum(struct Program *self); -int Program_setname(struct Program *self, const char *filename); -void Program_xref(struct Program *self, int chn); +void Program_renum(struct Program *this, int first, int inc); +void Program_unnum(struct Program *this); +int Program_setname(struct Program *this, const char *filename); +void Program_xref(struct Program *this, int chn); #endif /* __APPS_EXAMPLES_BAS_BAS_PROGRAM_H */ diff --git a/interpreters/bas/bas_programtypes.h b/interpreters/bas/bas_programtypes.h index d328f5819..9174f6595 100644 --- a/interpreters/bas/bas_programtypes.h +++ b/interpreters/bas/bas_programtypes.h @@ -1,8 +1,7 @@ /**************************************************************************** * apps/interpreters/bas/bas_programtypes.h * - * SPDX-License-Identifier: MIT - * SPDX-FileCopyrightText: 1999-2014 Michael Haardt + * Copyright (c) 1999-2014 Michael Haardt * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), diff --git a/interpreters/bas/bas_statement.c b/interpreters/bas/bas_statement.c index b95a38a3c..9638b6cf9 100644 --- a/interpreters/bas/bas_statement.c +++ b/interpreters/bas/bas_statement.c @@ -1,8 +1,7 @@ /**************************************************************************** * apps/interpreters/bas/bas_statement.c * - * SPDX-License-Identifier: MIT - * SPDX-FileCopyrightText: 1999-2014 Michael Haardt + * Copyright (c) 1999-2014 Michael Haardt * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -33,7 +32,6 @@ #include #include #include -#include #include "bas_statement.h" @@ -1052,7 +1050,7 @@ struct Value *stmt_DOcondition(struct Value *value) struct Value *stmt_EDIT(struct Value *value) { -#if defined(CONFIG_EXAMPLES_BAS_EDITOR) && defined(CONFIG_EXAMPLES_BAS_SHELL) && defined(CONFIG_ARCH_HAVE_FORK) +#if defined(CONFIG_EXAMPLES_BAS_EDITOR) && defined(CONFIG_EXAMPLES_BAS_SHELL) && defined(CONFIG_ARCH_HAVE_VFORK) long int line; struct Pc statementpc = g_pc; int status; @@ -1183,7 +1181,7 @@ struct Value *stmt_EDIT(struct Value *value) String_new(&cmd); String_appendChars(&cmd, visual); String_appendChar(&cmd, ' '); - for (i = 0; i < nitems(gotoLine); ++i) + for (i = 0; i < sizeof(gotoLine) / sizeof(gotoLine[0]); ++i) { if (strcmp(basename, gotoLine[i].editor) == 0) { @@ -1243,7 +1241,7 @@ struct Value *stmt_EDIT(struct Value *value) return (struct Value *)0; #else - return Value_new_ERROR(value, NOTAVAILABLE); + return Value_new_ERROR(value, NOTAVAILABLE, strerror(ENOSYS)); #endif } @@ -3528,7 +3526,7 @@ struct Value *stmt_MATINPUT(struct Value *value) if (var->dim != 1 && var->dim != 2) { - return Value_new_ERROR(value, DIMENSION); + return Value_new_ERROR(value, NOMATRIX, var->dim); } columns = var->dim == 1 ? 0 : var->geometry[1]; @@ -5675,7 +5673,7 @@ struct Value *stmt_SELECTCASE(struct Value *value) struct Value *stmt_SHELL(struct Value *value) { -#if defined(CONFIG_EXAMPLES_BAS_SHELL) && defined(CONFIG_ARCH_HAVE_FORK) +#if defined(CONFIG_EXAMPLES_BAS_SHELL) && defined(CONFIG_ARCH_HAVE_VFORK) pid_t pid; int status; @@ -5774,7 +5772,7 @@ struct Value *stmt_SHELL(struct Value *value) return (struct Value *)0; #else - return Value_new_ERROR(value, NOTAVAILABLE); + return Value_new_ERROR(value, NOTAVAILABLE, strerror(ENOSYS)); #endif } diff --git a/interpreters/bas/bas_statement.h b/interpreters/bas/bas_statement.h index 5b1fe9fcd..3421aab14 100644 --- a/interpreters/bas/bas_statement.h +++ b/interpreters/bas/bas_statement.h @@ -1,8 +1,7 @@ /**************************************************************************** * apps/interpreters/bas/statement.h * - * SPDX-License-Identifier: MIT - * SPDX-FileCopyrightText: 1999-2014 Michael Haardt + * Copyright (c) 1999-2014 Michael Haardt * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), diff --git a/interpreters/bas/bas_str.c b/interpreters/bas/bas_str.c index 1c68982dd..f804cbc15 100644 --- a/interpreters/bas/bas_str.c +++ b/interpreters/bas/bas_str.c @@ -1,8 +1,8 @@ /**************************************************************************** * apps/interpreters/bas/bas_str.c + * Dynamic strings. * - * SPDX-License-Identifier: MIT - * SPDX-FileCopyrightText: 1999-2014 Michael Haardt + * Copyright (c) 1999-2014 Michael Haardt * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -57,41 +57,41 @@ int cistrcmp(const char *s, const char *r) return ((tolower(*s) - tolower(*r))); } -struct String *String_new(struct String *self) +struct String *String_new(struct String *this) { - assert(self != (struct String *)0); - self->length = 0; - self->character = (char *)0; - self->field = (struct StringField *)0; - return self; + assert(this != (struct String *)0); + this->length = 0; + this->character = (char *)0; + this->field = (struct StringField *)0; + return this; } -void String_destroy(struct String *self) +void String_destroy(struct String *this) { - assert(self != (struct String *)0); - if (self->field) + assert(this != (struct String *)0); + if (this->field) { - String_leaveField(self); + String_leaveField(this); } - if (self->length) + if (this->length) { - free(self->character); + free(this->character); } } -int String_joinField(struct String *self, struct StringField *field, +int String_joinField(struct String *this, struct StringField *field, char *character, size_t length) { struct String **n; - assert(self != (struct String *)0); - if (self->field) + assert(this != (struct String *)0); + if (this->field) { - String_leaveField(self); + String_leaveField(this); } - self->field = field; + this->field = field; if ((n = (struct String **)realloc(field->refStrings, sizeof(struct String *) * (field->refCount + @@ -102,30 +102,30 @@ int String_joinField(struct String *self, struct StringField *field, } field->refStrings = n; - field->refStrings[field->refCount] = self; + field->refStrings[field->refCount] = this; ++field->refCount; - if (self->length) + if (this->length) { - free(self->character); + free(this->character); } - self->character = character; - self->length = length; + this->character = character; + this->length = length; return 0; } -void String_leaveField(struct String *self) +void String_leaveField(struct String *this) { struct StringField *field; int i; struct String **ref; - assert(self != (struct String *)0); - field = self->field; + assert(this != (struct String *)0); + field = this->field; assert(field != (struct StringField *)0); for (i = 0, ref = field->refStrings; i < field->refCount; ++i, ++ref) { - if (*ref == self) + if (*ref == this) { int further = --field->refCount - i; @@ -134,9 +134,9 @@ void String_leaveField(struct String *self) memmove(ref, ref + 1, further * sizeof(struct String **)); } - self->character = (char *)0; - self->length = 0; - self->field = (struct StringField *)0; + this->character = (char *)0; + this->length = 0; + this->field = (struct StringField *)0; return; } } @@ -144,59 +144,59 @@ void String_leaveField(struct String *self) assert(0); } -struct String *String_clone(struct String *self, const struct String *original) +struct String *String_clone(struct String *this, const struct String *original) { - assert(self != (struct String *)0); - String_new(self); - String_appendString(self, original); - return self; + assert(this != (struct String *)0); + String_new(this); + String_appendString(this, original); + return this; } -int String_size(struct String *self, size_t length) +int String_size(struct String *this, size_t length) { char *n; - assert(self != (struct String *)0); - if (self->field) + assert(this != (struct String *)0); + if (this->field) { - String_leaveField(self); + String_leaveField(this); } if (length) { - if (length > self->length) + if (length > this->length) { - if ((n = realloc(self->character, length + 1)) == (char *)0) + if ((n = realloc(this->character, length + 1)) == (char *)0) { return -1; } - self->character = n; + this->character = n; } - self->character[length] = '\0'; + this->character[length] = '\0'; } else { - if (self->length) + if (this->length) { - free(self->character); + free(this->character); } - self->character = (char *)0; + this->character = (char *)0; } - self->length = length; + this->length = length; return 0; } -int String_appendString(struct String *self, const struct String *app) +int String_appendString(struct String *this, const struct String *app) { - size_t oldlength = self->length; + size_t oldlength = this->length; - if (self->field) + if (this->field) { - String_leaveField(self); + String_leaveField(this); } if (app->length == 0) @@ -204,146 +204,146 @@ int String_appendString(struct String *self, const struct String *app) return 0; } - if (String_size(self, self->length + app->length) == -1) + if (String_size(this, this->length + app->length) == -1) { return -1; } - memcpy(self->character + oldlength, app->character, app->length); + memcpy(this->character + oldlength, app->character, app->length); return 0; } -int String_appendChar(struct String *self, char ch) +int String_appendChar(struct String *this, char ch) { - size_t oldlength = self->length; + size_t oldlength = this->length; - if (self->field) + if (this->field) { - String_leaveField(self); + String_leaveField(this); } - if (String_size(self, self->length + 1) == -1) + if (String_size(this, this->length + 1) == -1) { return -1; } - self->character[oldlength] = ch; + this->character[oldlength] = ch; return 0; } -int String_appendChars(struct String *self, const char *ch) +int String_appendChars(struct String *this, const char *ch) { - size_t oldlength = self->length; + size_t oldlength = this->length; size_t chlen = strlen(ch); - if (self->field) + if (this->field) { - String_leaveField(self); + String_leaveField(this); } - if (String_size(self, self->length + chlen) == -1) + if (String_size(this, this->length + chlen) == -1) { return -1; } - memcpy(self->character + oldlength, ch, chlen); + memcpy(this->character + oldlength, ch, chlen); return 0; } -int String_appendPrintf(struct String *self, const char *fmt, ...) +int String_appendPrintf(struct String *this, const char *fmt, ...) { char buf[1024]; size_t l, j; va_list ap; - if (self->field) + if (this->field) { - String_leaveField(self); + String_leaveField(this); } va_start(ap, fmt); l = vsprintf(buf, fmt, ap); va_end(ap); - j = self->length; - if (String_size(self, j + l) == -1) + j = this->length; + if (String_size(this, j + l) == -1) { return -1; } - memcpy(self->character + j, buf, l); + memcpy(this->character + j, buf, l); return 0; } -int String_insertChar(struct String *self, size_t where, char ch) +int String_insertChar(struct String *this, size_t where, char ch) { - size_t oldlength = self->length; + size_t oldlength = this->length; - if (self->field) + if (this->field) { - String_leaveField(self); + String_leaveField(this); } assert(where < oldlength); - if (String_size(self, self->length + 1) == -1) + if (String_size(this, this->length + 1) == -1) { return -1; } - memmove(self->character + where + 1, self->character + where, + memmove(this->character + where + 1, this->character + where, oldlength - where); - self->character[where] = ch; + this->character[where] = ch; return 0; } -int String_delete(struct String *self, size_t where, size_t len) +int String_delete(struct String *this, size_t where, size_t len) { - size_t oldlength = self->length; + size_t oldlength = this->length; - if (self->field) + if (this->field) { - String_leaveField(self); + String_leaveField(this); } assert(where < oldlength); assert(len > 0); if ((where + len) < oldlength) { - memmove(self->character + where, self->character + where + len, + memmove(this->character + where, this->character + where + len, oldlength - where - len); } - self->character[self->length -= len] = '\0'; + this->character[this->length -= len] = '\0'; return 0; } -void String_ucase(struct String *self) +void String_ucase(struct String *this) { size_t i; - for (i = 0; i < self->length; ++i) + for (i = 0; i < this->length; ++i) { - self->character[i] = toupper(self->character[i]); + this->character[i] = toupper(this->character[i]); } } -void String_lcase(struct String *self) +void String_lcase(struct String *this) { size_t i; - for (i = 0; i < self->length; ++i) + for (i = 0; i < this->length; ++i) { - self->character[i] = tolower(self->character[i]); + this->character[i] = tolower(this->character[i]); } } -int String_cmp(const struct String *self, const struct String *s) +int String_cmp(const struct String *this, const struct String *s) { size_t pos; int res; const char *thisch, *sch; - for (pos = 0, thisch = self->character, sch = s->character; - pos < self->length && pos < s->length; ++pos, ++thisch, ++sch) + for (pos = 0, thisch = this->character, sch = s->character; + pos < this->length && pos < s->length; ++pos, ++thisch, ++sch) { if ((res = (*thisch - *sch))) { @@ -351,74 +351,74 @@ int String_cmp(const struct String *self, const struct String *s) } } - return (self->length - s->length); + return (this->length - s->length); } -void String_lset(struct String *self, const struct String *s) +void String_lset(struct String *this, const struct String *s) { size_t copy; - copy = (self->length < s->length ? self->length : s->length); + copy = (this->length < s->length ? this->length : s->length); if (copy) { - memcpy(self->character, s->character, copy); + memcpy(this->character, s->character, copy); } - if (copy < self->length) + if (copy < this->length) { - memset(self->character + copy, ' ', self->length - copy); + memset(this->character + copy, ' ', this->length - copy); } } -void String_rset(struct String *self, const struct String *s) +void String_rset(struct String *this, const struct String *s) { size_t copy; - copy = (self->length < s->length ? self->length : s->length); + copy = (this->length < s->length ? this->length : s->length); if (copy) { - memcpy(self->character + self->length - copy, s->character, copy); + memcpy(this->character + this->length - copy, s->character, copy); } - if (copy < self->length) + if (copy < this->length) { - memset(self->character, ' ', self->length - copy); + memset(this->character, ' ', this->length - copy); } } -void String_set(struct String *self, size_t pos, const struct String *s, +void String_set(struct String *this, size_t pos, const struct String *s, size_t length) { - if (self->length >= pos) + if (this->length >= pos) { - if (self->length < (pos + length)) + if (this->length < (pos + length)) { - length = self->length - pos; + length = this->length - pos; } if (length) { - memcpy(self->character + pos, s->character, length); + memcpy(this->character + pos, s->character, length); } } } -struct StringField *StringField_new(struct StringField *self) +struct StringField *StringField_new(struct StringField *this) { - self->refStrings = (struct String **)0; - self->refCount = 0; - return self; + this->refStrings = (struct String **)0; + this->refCount = 0; + return this; } -void StringField_destroy(struct StringField *self) +void StringField_destroy(struct StringField *this) { int i; - for (i = self->refCount; i > 0;) + for (i = this->refCount; i > 0;) { - String_leaveField(self->refStrings[--i]); + String_leaveField(this->refStrings[--i]); } - self->refCount = -1; - free(self->refStrings); + this->refCount = -1; + free(this->refStrings); } diff --git a/interpreters/bas/bas_str.h b/interpreters/bas/bas_str.h index e70fe8711..5c7d02796 100644 --- a/interpreters/bas/bas_str.h +++ b/interpreters/bas/bas_str.h @@ -1,8 +1,7 @@ /**************************************************************************** * apps/interpreters/bas/bas_str.h * - * SPDX-License-Identifier: MIT - * SPDX-FileCopyrightText: 1999-2014 Michael Haardt + * Copyright (c) 1999-2014 Michael Haardt * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -15,7 +14,7 @@ * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING @@ -56,29 +55,28 @@ struct StringField int cistrcmp(const char *s, const char *r); -struct String *String_new(struct String *self); -void String_destroy(struct String *self); -int String_joinField(struct String *self, struct StringField *field, +struct String *String_new(struct String *this); +void String_destroy(struct String *this); +int String_joinField(struct String *this, struct StringField *field, char *character, size_t length); -void String_leaveField(struct String *self); -struct String *String_clone(struct String *self, const struct String *clon); -int String_appendString(struct String *self, const struct String *app); -int String_appendChar(struct String *self, char ch); -int String_appendChars(struct String *self, const char *ch); -int String_appendPrintf(struct String *self, const char *fmt, ...) - printf_like(2, 3); -int String_insertChar(struct String *self, size_t where, char ch); -int String_delete(struct String *self, size_t where, size_t len); -void String_ucase(struct String *self); -void String_lcase(struct String *self); -int String_size(struct String *self, size_t length); -int String_cmp(const struct String *self, const struct String *s); -void String_lset(struct String *self, const struct String *s); -void String_rset(struct String *self, const struct String *s); -void String_set(struct String *self, size_t pos, const struct String *s, +void String_leaveField(struct String *this); +struct String *String_clone(struct String *this, const struct String *clon); +int String_appendString(struct String *this, const struct String *app); +int String_appendChar(struct String *this, char ch); +int String_appendChars(struct String *this, const char *ch); +int String_appendPrintf(struct String *this, const char *fmt, ...); +int String_insertChar(struct String *this, size_t where, char ch); +int String_delete(struct String *this, size_t where, size_t len); +void String_ucase(struct String *this); +void String_lcase(struct String *this); +int String_size(struct String *this, size_t length); +int String_cmp(const struct String *this, const struct String *s); +void String_lset(struct String *this, const struct String *s); +void String_rset(struct String *this, const struct String *s); +void String_set(struct String *this, size_t pos, const struct String *s, size_t length); -struct StringField *StringField_new(struct StringField *self); -void StringField_destroy(struct StringField *self); +struct StringField *StringField_new(struct StringField *this); +void StringField_destroy(struct StringField *this); #endif /* __APPS_EXAMPLES_BAS_BAS_STR_H */ diff --git a/interpreters/bas/bas_token.c b/interpreters/bas/bas_token.c index f4c2fbd26..8e57d0dc7 100644 --- a/interpreters/bas/bas_token.c +++ b/interpreters/bas/bas_token.c @@ -1,24 +1,3 @@ -/**************************************************************************** - * apps/interpreters/bas/bas_token.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ #line 3 "" @@ -4184,7 +4163,11 @@ static void yy_init_buffer (YY_BUFFER_STATE b, FILE * file) b->yy_bs_column = 0; } +#ifdef CONFIG_SERIAL_TERMIOS b->yy_is_interactive = file ? (isatty(fileno(file)) > 0) : 0; +#else + b->yy_is_interactive = 1; +#endif errno = oerrno; } diff --git a/interpreters/bas/bas_token.h b/interpreters/bas/bas_token.h index 7cb15d3a3..bf4b03784 100644 --- a/interpreters/bas/bas_token.h +++ b/interpreters/bas/bas_token.h @@ -1,8 +1,7 @@ /**************************************************************************** * apps/interpreters/bas/bas_token.h * - * SPDX-License-Identifier: MIT - * SPDX-FileCopyrightText: 1999-2014 Michael Haardt + * Copyright (c) 1999-2014 Michael Haardt * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -101,7 +100,7 @@ struct Identifier { struct Symbol *sym; enum ValueType defaultType; - char name[0]; + char name[2/* ... */]; }; struct Next diff --git a/interpreters/bas/bas_token.l b/interpreters/bas/bas_token.l index 131544262..d68fb900a 100644 --- a/interpreters/bas/bas_token.l +++ b/interpreters/bas/bas_token.l @@ -1,25 +1,3 @@ -/**************************************************************************** - * apps/interpreters/bas/bas_token.l - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - /* Tokens and token sequence arrays. */ %{ #include diff --git a/interpreters/bas/bas_value.c b/interpreters/bas/bas_value.c index 3c99281d0..3ecf92a5e 100644 --- a/interpreters/bas/bas_value.c +++ b/interpreters/bas/bas_value.c @@ -1,8 +1,7 @@ /**************************************************************************** * apps/interpreters/bas/bas_value.c * - * SPDX-License-Identifier: MIT - * SPDX-FileCopyrightText: 1999-2014 Michael Haardt + * Copyright (c) 1999-2014 Michael Haardt * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -14,8 +13,8 @@ * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING @@ -137,9 +136,7 @@ static void format_double(struct String *buf, double value, int width, else /* print decimal numbers or integers, if * possible */ { - int o; - int n; - int p = 6; + int o, n, p = 6; while (x >= 10.0 && p > 0) { @@ -156,7 +153,6 @@ static void format_double(struct String *buf, double value, int width, { --buf->length; } - if (buf->character[buf->length - 1] == '.') { --buf->length; @@ -219,89 +215,89 @@ double Value_vald(const char *s, char **end, int *overflow) return d; } -struct Value *Value_new_NIL(struct Value *self) +struct Value *Value_new_NIL(struct Value *this) { - assert(self != (struct Value *)0); - self->type = V_NIL; - return self; + assert(this != (struct Value *)0); + this->type = V_NIL; + return this; } -struct Value *Value_new_ERROR(struct Value *self, int code, - const char *error, ...) +struct Value *Value_new_ERROR(struct Value *this, int code, const char *error, + ...) { va_list ap; char buf[128]; - assert(self != (struct Value *)0); + assert(this != (struct Value *)0); va_start(ap, error); vsprintf(buf, error, ap); va_end(ap); - self->type = V_ERROR; - self->u.error.code = code; - self->u.error.msg = strdup(buf); - return self; + this->type = V_ERROR; + this->u.error.code = code; + this->u.error.msg = strcpy(malloc(strlen(buf) + 1), buf); + return this; } -struct Value *Value_new_INTEGER(struct Value *self, int n) +struct Value *Value_new_INTEGER(struct Value *this, int n) { - assert(self != (struct Value *)0); - self->type = V_INTEGER; - self->u.integer = n; - return self; + assert(this != (struct Value *)0); + this->type = V_INTEGER; + this->u.integer = n; + return this; } -struct Value *Value_new_REAL(struct Value *self, double n) +struct Value *Value_new_REAL(struct Value *this, double n) { - assert(self != (struct Value *)0); - self->type = V_REAL; - self->u.real = n; - return self; + assert(this != (struct Value *)0); + this->type = V_REAL; + this->u.real = n; + return this; } -struct Value *Value_new_STRING(struct Value *self) +struct Value *Value_new_STRING(struct Value *this) { - assert(self != (struct Value *)0); - self->type = V_STRING; - String_new(&self->u.string); - return self; + assert(this != (struct Value *)0); + this->type = V_STRING; + String_new(&this->u.string); + return this; } -struct Value *Value_new_VOID(struct Value *self) +struct Value *Value_new_VOID(struct Value *this) { - assert(self != (struct Value *)0); - self->type = V_VOID; - return self; + assert(this != (struct Value *)0); + this->type = V_VOID; + return this; } -struct Value *Value_new_null(struct Value *self, enum ValueType type) +struct Value *Value_new_null(struct Value *this, enum ValueType type) { - assert(self != (struct Value *)0); + assert(this != (struct Value *)0); switch (type) { case V_INTEGER: { - self->type = V_INTEGER; - self->u.integer = 0; + this->type = V_INTEGER; + this->u.integer = 0; break; } case V_REAL: { - self->type = V_REAL; - self->u.real = 0.0; + this->type = V_REAL; + this->u.real = 0.0; break; } case V_STRING: { - self->type = V_STRING; - String_new(&self->u.string); + this->type = V_STRING; + String_new(&this->u.string); break; } case V_VOID: { - self->type = V_VOID; + this->type = V_VOID; break; } @@ -309,21 +305,21 @@ struct Value *Value_new_null(struct Value *self, enum ValueType type) assert(0); } - return self; + return this; } -int Value_isNull(const struct Value *self) +int Value_isNull(const struct Value *this) { - switch (self->type) + switch (this->type) { case V_INTEGER: - return (self->u.integer == 0); + return (this->u.integer == 0); case V_REAL: - return (self->u.real == 0.0); + return (this->u.real == 0.0); case V_STRING: - return (self->u.string.length == 0); + return (this->u.string.length == 0); default: assert(0); @@ -332,13 +328,13 @@ int Value_isNull(const struct Value *self) return -1; } -void Value_destroy(struct Value *self) +void Value_destroy(struct Value *this) { - assert(self != (struct Value *)0); - switch (self->type) + assert(this != (struct Value *)0); + switch (this->type) { case V_ERROR: - free(self->u.error.msg); + free(this->u.error.msg); break; case V_INTEGER: @@ -351,7 +347,7 @@ void Value_destroy(struct Value *self) break; case V_STRING: - String_destroy(&self->u.string); + String_destroy(&this->u.string); break; case V_VOID: @@ -361,49 +357,50 @@ void Value_destroy(struct Value *self) assert(0); } - self->type = 0; + this->type = 0; } -struct Value *Value_clone(struct Value *self, const struct Value *original) +struct Value *Value_clone(struct Value *this, const struct Value *original) { - assert(self != (struct Value *)0); + assert(this != (struct Value *)0); assert(original != (struct Value *)0); - switch (original->type) { case V_ERROR: { - self->u.error.msg = strdup(original->u.error.msg); - self->u.error.code = original->u.error.code; + strcpy(this->u.error.msg = + malloc(strlen(original->u.error.msg) + 1), + original->u.error.msg); + this->u.error.code = original->u.error.code; break; } case V_INTEGER: - self->u.integer = original->u.integer; + this->u.integer = original->u.integer; break; case V_NIL: break; case V_REAL: - self->u.real = original->u.real; + this->u.real = original->u.real; break; case V_STRING: - String_clone(&self->u.string, &original->u.string); + String_clone(&this->u.string, &original->u.string); break; default: assert(0); } - self->type = original->type; - return self; + this->type = original->type; + return this; } -struct Value *Value_uplus(struct Value *self, int calc) +struct Value *Value_uplus(struct Value *this, int calc) { - switch (self->type) + switch (this->type) { case V_INTEGER: case V_REAL: @@ -413,8 +410,8 @@ struct Value *Value_uplus(struct Value *self, int calc) case V_STRING: { - Value_destroy(self); - Value_new_ERROR(self, INVALIDUOPERAND); + Value_destroy(this); + Value_new_ERROR(this, INVALIDUOPERAND); break; } @@ -422,18 +419,18 @@ struct Value *Value_uplus(struct Value *self, int calc) assert(0); } - return self; + return this; } -struct Value *Value_uneg(struct Value *self, int calc) +struct Value *Value_uneg(struct Value *this, int calc) { - switch (self->type) + switch (this->type) { case V_INTEGER: { if (calc) { - self->u.integer = -self->u.integer; + this->u.integer = -this->u.integer; } break; } @@ -442,15 +439,15 @@ struct Value *Value_uneg(struct Value *self, int calc) { if (calc) { - self->u.real = -self->u.real; + this->u.real = -this->u.real; } break; } case V_STRING: { - Value_destroy(self); - Value_new_ERROR(self, INVALIDUOPERAND); + Value_destroy(this); + Value_new_ERROR(this, INVALIDUOPERAND); break; } @@ -458,36 +455,36 @@ struct Value *Value_uneg(struct Value *self, int calc) assert(0); } - return self; + return this; } -struct Value *Value_unot(struct Value *self, int calc) +struct Value *Value_unot(struct Value *this, int calc) { - switch (self->type) + switch (this->type) { case V_INTEGER: { if (calc) { - self->u.integer = ~self->u.integer; + this->u.integer = ~this->u.integer; } break; } case V_REAL: { - Value_retype(self, V_INTEGER); + Value_retype(this, V_INTEGER); if (calc) { - self->u.integer = ~self->u.integer; + this->u.integer = ~this->u.integer; } break; } case V_STRING: { - Value_destroy(self); - Value_new_ERROR(self, INVALIDUOPERAND); + Value_destroy(this); + Value_new_ERROR(this, INVALIDUOPERAND); break; } @@ -495,31 +492,31 @@ struct Value *Value_unot(struct Value *self, int calc) assert(0); } - return self; + return this; } -struct Value *Value_add(struct Value *self, struct Value *x, int calc) +struct Value *Value_add(struct Value *this, struct Value *x, int calc) { - switch (Value_commonType[self->type][x->type]) + switch (Value_commonType[this->type][x->type]) { case V_INTEGER: { - VALUE_RETYPE(self, V_INTEGER); + VALUE_RETYPE(this, V_INTEGER); VALUE_RETYPE(x, V_INTEGER); if (calc) { - self->u.integer += x->u.integer; + this->u.integer += x->u.integer; } break; } case V_REAL: { - VALUE_RETYPE(self, V_REAL); + VALUE_RETYPE(this, V_REAL); VALUE_RETYPE(x, V_REAL); if (calc) { - self->u.real += x->u.real; + this->u.real += x->u.real; } break; } @@ -528,7 +525,7 @@ struct Value *Value_add(struct Value *self, struct Value *x, int calc) { if (calc) { - String_appendString(&self->u.string, &x->u.string); + String_appendString(&this->u.string, &x->u.string); } break; } @@ -537,39 +534,39 @@ struct Value *Value_add(struct Value *self, struct Value *x, int calc) assert(0); } - return self; + return this; } -struct Value *Value_sub(struct Value *self, struct Value *x, int calc) +struct Value *Value_sub(struct Value *this, struct Value *x, int calc) { - switch (Value_commonType[self->type][x->type]) + switch (Value_commonType[this->type][x->type]) { case V_INTEGER: { - VALUE_RETYPE(self, V_INTEGER); + VALUE_RETYPE(this, V_INTEGER); VALUE_RETYPE(x, V_INTEGER); if (calc) { - self->u.integer -= x->u.integer; + this->u.integer -= x->u.integer; } break; } case V_REAL: { - VALUE_RETYPE(self, V_REAL); + VALUE_RETYPE(this, V_REAL); VALUE_RETYPE(x, V_REAL); if (calc) { - self->u.real -= x->u.real; + this->u.real -= x->u.real; } break; } case V_STRING: { - Value_destroy(self); - Value_new_ERROR(self, INVALIDOPERAND); + Value_destroy(this); + Value_new_ERROR(this, INVALIDOPERAND); break; } @@ -577,20 +574,20 @@ struct Value *Value_sub(struct Value *self, struct Value *x, int calc) assert(0); } - return self; + return this; } -struct Value *Value_mult(struct Value *self, struct Value *x, int calc) +struct Value *Value_mult(struct Value *this, struct Value *x, int calc) { - switch (Value_commonType[self->type][x->type]) + switch (Value_commonType[this->type][x->type]) { case V_INTEGER: { - VALUE_RETYPE(self, V_INTEGER); + VALUE_RETYPE(this, V_INTEGER); VALUE_RETYPE(x, V_INTEGER); if (calc) { - self->u.integer *= x->u.integer; + this->u.integer *= x->u.integer; } break; @@ -598,19 +595,19 @@ struct Value *Value_mult(struct Value *self, struct Value *x, int calc) case V_REAL: { - VALUE_RETYPE(self, V_REAL); + VALUE_RETYPE(this, V_REAL); VALUE_RETYPE(x, V_REAL); if (calc) { - self->u.real *= x->u.real; + this->u.real *= x->u.real; } break; } case V_STRING: { - Value_destroy(self); - Value_new_ERROR(self, INVALIDOPERAND); + Value_destroy(this); + Value_new_ERROR(this, INVALIDOPERAND); break; } @@ -618,27 +615,27 @@ struct Value *Value_mult(struct Value *self, struct Value *x, int calc) assert(0); } - return self; + return this; } -struct Value *Value_div(struct Value *self, struct Value *x, int calc) +struct Value *Value_div(struct Value *this, struct Value *x, int calc) { - switch (Value_commonType[self->type][x->type]) + switch (Value_commonType[this->type][x->type]) { case V_INTEGER: { - VALUE_RETYPE(self, V_REAL); + VALUE_RETYPE(this, V_REAL); VALUE_RETYPE(x, V_REAL); if (calc) { if (x->u.real == 0) { - Value_destroy(self); - Value_new_ERROR(self, UNDEFINED, "Division by zero"); + Value_destroy(this); + Value_new_ERROR(this, UNDEFINED, "Division by zero"); } else { - self->u.real /= x->u.real; + this->u.real /= x->u.real; } } break; @@ -646,18 +643,18 @@ struct Value *Value_div(struct Value *self, struct Value *x, int calc) case V_REAL: { - VALUE_RETYPE(self, V_REAL); + VALUE_RETYPE(this, V_REAL); VALUE_RETYPE(x, V_REAL); if (calc) { if (x->u.real == 0.0) { - Value_destroy(self); - Value_new_ERROR(self, UNDEFINED, "Division by zero"); + Value_destroy(this); + Value_new_ERROR(this, UNDEFINED, "Division by zero"); } else { - self->u.real /= x->u.real; + this->u.real /= x->u.real; } } break; @@ -665,8 +662,8 @@ struct Value *Value_div(struct Value *self, struct Value *x, int calc) case V_STRING: { - Value_destroy(self); - Value_new_ERROR(self, INVALIDOPERAND); + Value_destroy(this); + Value_new_ERROR(this, INVALIDOPERAND); break; } @@ -674,27 +671,27 @@ struct Value *Value_div(struct Value *self, struct Value *x, int calc) assert(0); } - return self; + return this; } -struct Value *Value_idiv(struct Value *self, struct Value *x, int calc) +struct Value *Value_idiv(struct Value *this, struct Value *x, int calc) { - switch (Value_commonType[self->type][x->type]) + switch (Value_commonType[this->type][x->type]) { case V_INTEGER: { - VALUE_RETYPE(self, V_INTEGER); + VALUE_RETYPE(this, V_INTEGER); VALUE_RETYPE(x, V_INTEGER); if (calc) { if (x->u.integer == 0) { - Value_destroy(self); - Value_new_ERROR(self, UNDEFINED, "Division by zero"); + Value_destroy(this); + Value_new_ERROR(this, UNDEFINED, "Division by zero"); } else { - self->u.integer /= x->u.integer; + this->u.integer /= x->u.integer; } } break; @@ -702,18 +699,18 @@ struct Value *Value_idiv(struct Value *self, struct Value *x, int calc) case V_REAL: { - VALUE_RETYPE(self, V_REAL); + VALUE_RETYPE(this, V_REAL); VALUE_RETYPE(x, V_REAL); if (calc) { if (x->u.real == 0.0) { - Value_destroy(self); - Value_new_ERROR(self, UNDEFINED, "Division by zero"); + Value_destroy(this); + Value_new_ERROR(this, UNDEFINED, "Division by zero"); } else { - self->u.real = Value_trunc(self->u.real / x->u.real); + this->u.real = Value_trunc(this->u.real / x->u.real); } } break; @@ -721,8 +718,8 @@ struct Value *Value_idiv(struct Value *self, struct Value *x, int calc) case V_STRING: { - Value_destroy(self); - Value_new_ERROR(self, INVALIDOPERAND); + Value_destroy(this); + Value_new_ERROR(this, INVALIDOPERAND); break; } @@ -730,27 +727,27 @@ struct Value *Value_idiv(struct Value *self, struct Value *x, int calc) assert(0); } - return self; + return this; } -struct Value *Value_mod(struct Value *self, struct Value *x, int calc) +struct Value *Value_mod(struct Value *this, struct Value *x, int calc) { - switch (Value_commonType[self->type][x->type]) + switch (Value_commonType[this->type][x->type]) { case V_INTEGER: { - VALUE_RETYPE(self, V_INTEGER); + VALUE_RETYPE(this, V_INTEGER); VALUE_RETYPE(x, V_INTEGER); if (calc) { if (x->u.integer == 0) { - Value_destroy(self); - Value_new_ERROR(self, UNDEFINED, "Modulo by zero"); + Value_destroy(this); + Value_new_ERROR(this, UNDEFINED, "Modulo by zero"); } else { - self->u.integer %= x->u.integer; + this->u.integer %= x->u.integer; } } break; @@ -758,18 +755,18 @@ struct Value *Value_mod(struct Value *self, struct Value *x, int calc) case V_REAL: { - VALUE_RETYPE(self, V_REAL); + VALUE_RETYPE(this, V_REAL); VALUE_RETYPE(x, V_REAL); if (calc) { if (x->u.real == 0.0) { - Value_destroy(self); - Value_new_ERROR(self, UNDEFINED, "Modulo by zero"); + Value_destroy(this); + Value_new_ERROR(this, UNDEFINED, "Modulo by zero"); } else { - self->u.real = fmod(self->u.real, x->u.real); + this->u.real = fmod(this->u.real, x->u.real); } } break; @@ -777,8 +774,8 @@ struct Value *Value_mod(struct Value *self, struct Value *x, int calc) case V_STRING: { - Value_destroy(self); - Value_new_ERROR(self, INVALIDOPERAND); + Value_destroy(this); + Value_new_ERROR(this, INVALIDOPERAND); break; } @@ -786,33 +783,33 @@ struct Value *Value_mod(struct Value *self, struct Value *x, int calc) assert(0); } - return self; + return this; } -struct Value *Value_pow(struct Value *self, struct Value *x, int calc) +struct Value *Value_pow(struct Value *this, struct Value *x, int calc) { - switch (Value_commonType[self->type][x->type]) + switch (Value_commonType[this->type][x->type]) { case V_INTEGER: { - VALUE_RETYPE(self, V_INTEGER); + VALUE_RETYPE(this, V_INTEGER); VALUE_RETYPE(x, V_INTEGER); if (calc) { - if (self->u.integer == 0 && x->u.integer == 0) + if (this->u.integer == 0 && x->u.integer == 0) { - Value_destroy(self); - Value_new_ERROR(self, UNDEFINED, "0^0"); + Value_destroy(this); + Value_new_ERROR(this, UNDEFINED, "0^0"); } else if (x->u.integer > 0) { - self->u.integer = pow(self->u.integer, x->u.integer); + this->u.integer = pow(this->u.integer, x->u.integer); } else { - long int thisi = self->u.integer; - Value_destroy(self); - Value_new_REAL(self, pow(thisi, x->u.integer)); + long int thisi = this->u.integer; + Value_destroy(this); + Value_new_REAL(this, pow(thisi, x->u.integer)); } } break; @@ -820,18 +817,18 @@ struct Value *Value_pow(struct Value *self, struct Value *x, int calc) case V_REAL: { - VALUE_RETYPE(self, V_REAL); + VALUE_RETYPE(this, V_REAL); VALUE_RETYPE(x, V_REAL); if (calc) { - if (self->u.real == 0.0 && x->u.real == 0.0) + if (this->u.real == 0.0 && x->u.real == 0.0) { - Value_destroy(self); - Value_new_ERROR(self, UNDEFINED, "0^0"); + Value_destroy(this); + Value_new_ERROR(this, UNDEFINED, "0^0"); } else { - self->u.real = pow(self->u.real, x->u.real); + this->u.real = pow(this->u.real, x->u.real); } } break; @@ -839,8 +836,8 @@ struct Value *Value_pow(struct Value *self, struct Value *x, int calc) case V_STRING: { - Value_destroy(self); - Value_new_ERROR(self, INVALIDOPERAND); + Value_destroy(this); + Value_new_ERROR(this, INVALIDOPERAND); break; } @@ -848,29 +845,29 @@ struct Value *Value_pow(struct Value *self, struct Value *x, int calc) assert(0); } - return self; + return this; } -struct Value *Value_and(struct Value *self, struct Value *x, int calc) +struct Value *Value_and(struct Value *this, struct Value *x, int calc) { - switch (Value_commonType[self->type][x->type]) + switch (Value_commonType[this->type][x->type]) { case V_INTEGER: case V_REAL: { - VALUE_RETYPE(self, V_INTEGER); + VALUE_RETYPE(this, V_INTEGER); VALUE_RETYPE(x, V_INTEGER); if (calc) { - self->u.integer &= x->u.integer; + this->u.integer &= x->u.integer; } break; } case V_STRING: { - Value_destroy(self); - Value_new_ERROR(self, INVALIDOPERAND); + Value_destroy(this); + Value_new_ERROR(this, INVALIDOPERAND); break; } @@ -878,29 +875,29 @@ struct Value *Value_and(struct Value *self, struct Value *x, int calc) assert(0); } - return self; + return this; } -struct Value *Value_or(struct Value *self, struct Value *x, int calc) +struct Value *Value_or(struct Value *this, struct Value *x, int calc) { - switch (Value_commonType[self->type][x->type]) + switch (Value_commonType[this->type][x->type]) { case V_INTEGER: case V_REAL: { - VALUE_RETYPE(self, V_INTEGER); + VALUE_RETYPE(this, V_INTEGER); VALUE_RETYPE(x, V_INTEGER); if (calc) { - self->u.integer |= x->u.integer; + this->u.integer |= x->u.integer; } break; } case V_STRING: { - Value_destroy(self); - Value_new_ERROR(self, INVALIDOPERAND); + Value_destroy(this); + Value_new_ERROR(this, INVALIDOPERAND); break; } @@ -908,29 +905,29 @@ struct Value *Value_or(struct Value *self, struct Value *x, int calc) assert(0); } - return self; + return this; } -struct Value *Value_xor(struct Value *self, struct Value *x, int calc) +struct Value *Value_xor(struct Value *this, struct Value *x, int calc) { - switch (Value_commonType[self->type][x->type]) + switch (Value_commonType[this->type][x->type]) { case V_INTEGER: case V_REAL: { - VALUE_RETYPE(self, V_INTEGER); + VALUE_RETYPE(this, V_INTEGER); VALUE_RETYPE(x, V_INTEGER); if (calc) { - self->u.integer ^= x->u.integer; + this->u.integer ^= x->u.integer; } break; } case V_STRING: { - Value_destroy(self); - Value_new_ERROR(self, INVALIDOPERAND); + Value_destroy(this); + Value_new_ERROR(this, INVALIDOPERAND); break; } @@ -938,29 +935,29 @@ struct Value *Value_xor(struct Value *self, struct Value *x, int calc) assert(0); } - return self; + return this; } -struct Value *Value_eqv(struct Value *self, struct Value *x, int calc) +struct Value *Value_eqv(struct Value *this, struct Value *x, int calc) { - switch (Value_commonType[self->type][x->type]) + switch (Value_commonType[this->type][x->type]) { case V_INTEGER: case V_REAL: { - VALUE_RETYPE(self, V_INTEGER); + VALUE_RETYPE(this, V_INTEGER); VALUE_RETYPE(x, V_INTEGER); if (calc) { - self->u.integer = ~(self->u.integer ^ x->u.integer); + this->u.integer = ~(this->u.integer ^ x->u.integer); } break; } case V_STRING: { - Value_destroy(self); - Value_new_ERROR(self, INVALIDOPERAND); + Value_destroy(this); + Value_new_ERROR(this, INVALIDOPERAND); break; } @@ -968,29 +965,29 @@ struct Value *Value_eqv(struct Value *self, struct Value *x, int calc) assert(0); } - return self; + return this; } -struct Value *Value_imp(struct Value *self, struct Value *x, int calc) +struct Value *Value_imp(struct Value *this, struct Value *x, int calc) { - switch (Value_commonType[self->type][x->type]) + switch (Value_commonType[this->type][x->type]) { case V_INTEGER: case V_REAL: { - VALUE_RETYPE(self, V_INTEGER); + VALUE_RETYPE(this, V_INTEGER); VALUE_RETYPE(x, V_INTEGER); if (calc) { - self->u.integer = (~self->u.integer) | x->u.integer; + this->u.integer = (~this->u.integer) | x->u.integer; } break; } case V_STRING: { - Value_destroy(self); - Value_new_ERROR(self, INVALIDOPERAND); + Value_destroy(this); + Value_new_ERROR(this, INVALIDOPERAND); break; } @@ -998,20 +995,20 @@ struct Value *Value_imp(struct Value *self, struct Value *x, int calc) assert(0); } - return self; + return this; } -struct Value *Value_lt(struct Value *self, struct Value *x, int calc) +struct Value *Value_lt(struct Value *this, struct Value *x, int calc) { - switch (Value_commonType[self->type][x->type]) + switch (Value_commonType[this->type][x->type]) { case V_INTEGER: { - VALUE_RETYPE(self, V_INTEGER); + VALUE_RETYPE(this, V_INTEGER); VALUE_RETYPE(x, V_INTEGER); if (calc) { - self->u.integer = (self->u.integer < x->u.integer) ? -1 : 0; + this->u.integer = (this->u.integer < x->u.integer) ? -1 : 0; } break; } @@ -1020,19 +1017,19 @@ struct Value *Value_lt(struct Value *self, struct Value *x, int calc) { int v; - VALUE_RETYPE(self, V_REAL); + VALUE_RETYPE(this, V_REAL); VALUE_RETYPE(x, V_REAL); if (calc) { - v = (self->u.real < x->u.real) ? -1 : 0; + v = (this->u.real < x->u.real) ? -1 : 0; } else { v = 0; } - Value_destroy(self); - Value_new_INTEGER(self, v); + Value_destroy(this); + Value_new_INTEGER(this, v); break; } @@ -1042,15 +1039,15 @@ struct Value *Value_lt(struct Value *self, struct Value *x, int calc) if (calc) { - v = (String_cmp(&self->u.string, &x->u.string) < 0) ? -1 : 0; + v = (String_cmp(&this->u.string, &x->u.string) < 0) ? -1 : 0; } else { v = 0; } - Value_destroy(self); - Value_new_INTEGER(self, v); + Value_destroy(this); + Value_new_INTEGER(this, v); break; } @@ -1058,20 +1055,20 @@ struct Value *Value_lt(struct Value *self, struct Value *x, int calc) assert(0); } - return self; + return this; } -struct Value *Value_le(struct Value *self, struct Value *x, int calc) +struct Value *Value_le(struct Value *this, struct Value *x, int calc) { - switch (Value_commonType[self->type][x->type]) + switch (Value_commonType[this->type][x->type]) { case V_INTEGER: { - VALUE_RETYPE(self, V_INTEGER); + VALUE_RETYPE(this, V_INTEGER); VALUE_RETYPE(x, V_INTEGER); if (calc) { - self->u.integer = (self->u.integer <= x->u.integer) ? -1 : 0; + this->u.integer = (this->u.integer <= x->u.integer) ? -1 : 0; } break; } @@ -1080,19 +1077,19 @@ struct Value *Value_le(struct Value *self, struct Value *x, int calc) { int v; - VALUE_RETYPE(self, V_REAL); + VALUE_RETYPE(this, V_REAL); VALUE_RETYPE(x, V_REAL); if (calc) { - v = (self->u.real <= x->u.real) ? -1 : 0; + v = (this->u.real <= x->u.real) ? -1 : 0; } else { v = 0; } - Value_destroy(self); - Value_new_INTEGER(self, v); + Value_destroy(this); + Value_new_INTEGER(this, v); break; } @@ -1102,15 +1099,15 @@ struct Value *Value_le(struct Value *self, struct Value *x, int calc) if (calc) { - v = (String_cmp(&self->u.string, &x->u.string) <= 0) ? -1 : 0; + v = (String_cmp(&this->u.string, &x->u.string) <= 0) ? -1 : 0; } else { v = 0; } - Value_destroy(self); - Value_new_INTEGER(self, v); + Value_destroy(this); + Value_new_INTEGER(this, v); break; } @@ -1118,20 +1115,20 @@ struct Value *Value_le(struct Value *self, struct Value *x, int calc) assert(0); } - return self; + return this; } -struct Value *Value_eq(struct Value *self, struct Value *x, int calc) +struct Value *Value_eq(struct Value *this, struct Value *x, int calc) { - switch (Value_commonType[self->type][x->type]) + switch (Value_commonType[this->type][x->type]) { case V_INTEGER: { - VALUE_RETYPE(self, V_INTEGER); + VALUE_RETYPE(this, V_INTEGER); VALUE_RETYPE(x, V_INTEGER); if (calc) { - self->u.integer = (self->u.integer == x->u.integer) ? -1 : 0; + this->u.integer = (this->u.integer == x->u.integer) ? -1 : 0; } break; } @@ -1140,37 +1137,36 @@ struct Value *Value_eq(struct Value *self, struct Value *x, int calc) { int v; - VALUE_RETYPE(self, V_REAL); + VALUE_RETYPE(this, V_REAL); VALUE_RETYPE(x, V_REAL); if (calc) { - v = (self->u.real == x->u.real) ? -1 : 0; + v = (this->u.real == x->u.real) ? -1 : 0; } else { v = 0; } - Value_destroy(self); - Value_new_INTEGER(self, v); + Value_destroy(this); + Value_new_INTEGER(this, v); break; } - case V_STRING: { int v; if (calc) { - v = (String_cmp(&self->u.string, &x->u.string) == 0) ? -1 : 0; + v = (String_cmp(&this->u.string, &x->u.string) == 0) ? -1 : 0; } else { v = 0; } - Value_destroy(self); - Value_new_INTEGER(self, v); + Value_destroy(this); + Value_new_INTEGER(this, v); break; } @@ -1178,20 +1174,20 @@ struct Value *Value_eq(struct Value *self, struct Value *x, int calc) assert(0); } - return self; + return this; } -struct Value *Value_ge(struct Value *self, struct Value *x, int calc) +struct Value *Value_ge(struct Value *this, struct Value *x, int calc) { - switch (Value_commonType[self->type][x->type]) + switch (Value_commonType[this->type][x->type]) { case V_INTEGER: { - VALUE_RETYPE(self, V_INTEGER); + VALUE_RETYPE(this, V_INTEGER); VALUE_RETYPE(x, V_INTEGER); if (calc) { - self->u.integer = (self->u.integer >= x->u.integer) ? -1 : 0; + this->u.integer = (this->u.integer >= x->u.integer) ? -1 : 0; } break; } @@ -1200,19 +1196,19 @@ struct Value *Value_ge(struct Value *self, struct Value *x, int calc) { int v; - VALUE_RETYPE(self, V_REAL); + VALUE_RETYPE(this, V_REAL); VALUE_RETYPE(x, V_REAL); if (calc) { - v = (self->u.real >= x->u.real) ? -1 : 0; + v = (this->u.real >= x->u.real) ? -1 : 0; } else { v = 0; } - Value_destroy(self); - Value_new_INTEGER(self, v); + Value_destroy(this); + Value_new_INTEGER(this, v); break; } @@ -1222,15 +1218,15 @@ struct Value *Value_ge(struct Value *self, struct Value *x, int calc) if (calc) { - v = (String_cmp(&self->u.string, &x->u.string) >= 0) ? -1 : 0; + v = (String_cmp(&this->u.string, &x->u.string) >= 0) ? -1 : 0; } else { v = 0; } - Value_destroy(self); - Value_new_INTEGER(self, v); + Value_destroy(this); + Value_new_INTEGER(this, v); break; } @@ -1238,20 +1234,20 @@ struct Value *Value_ge(struct Value *self, struct Value *x, int calc) assert(0); } - return self; + return this; } -struct Value *Value_gt(struct Value *self, struct Value *x, int calc) +struct Value *Value_gt(struct Value *this, struct Value *x, int calc) { - switch (Value_commonType[self->type][x->type]) + switch (Value_commonType[this->type][x->type]) { case V_INTEGER: { - VALUE_RETYPE(self, V_INTEGER); + VALUE_RETYPE(this, V_INTEGER); VALUE_RETYPE(x, V_INTEGER); if (calc) { - self->u.integer = (self->u.integer > x->u.integer) ? -1 : 0; + this->u.integer = (this->u.integer > x->u.integer) ? -1 : 0; } break; } @@ -1260,19 +1256,19 @@ struct Value *Value_gt(struct Value *self, struct Value *x, int calc) { int v; - VALUE_RETYPE(self, V_REAL); + VALUE_RETYPE(this, V_REAL); VALUE_RETYPE(x, V_REAL); if (calc) { - v = (self->u.real > x->u.real) ? -1 : 0; + v = (this->u.real > x->u.real) ? -1 : 0; } else { v = 0; } - Value_destroy(self); - Value_new_INTEGER(self, v); + Value_destroy(this); + Value_new_INTEGER(this, v); break; } @@ -1282,15 +1278,15 @@ struct Value *Value_gt(struct Value *self, struct Value *x, int calc) if (calc) { - v = (String_cmp(&self->u.string, &x->u.string) > 0) ? -1 : 0; + v = (String_cmp(&this->u.string, &x->u.string) > 0) ? -1 : 0; } else { v = 0; } - Value_destroy(self); - Value_new_INTEGER(self, v); + Value_destroy(this); + Value_new_INTEGER(this, v); break; } @@ -1298,20 +1294,20 @@ struct Value *Value_gt(struct Value *self, struct Value *x, int calc) assert(0); } - return self; + return this; } -struct Value *Value_ne(struct Value *self, struct Value *x, int calc) +struct Value *Value_ne(struct Value *this, struct Value *x, int calc) { - switch (Value_commonType[self->type][x->type]) + switch (Value_commonType[this->type][x->type]) { case V_INTEGER: { - VALUE_RETYPE(self, V_INTEGER); + VALUE_RETYPE(this, V_INTEGER); VALUE_RETYPE(x, V_INTEGER); if (calc) { - self->u.integer = (self->u.integer != x->u.integer) ? -1 : 0; + this->u.integer = (this->u.integer != x->u.integer) ? -1 : 0; } break; } @@ -1320,19 +1316,19 @@ struct Value *Value_ne(struct Value *self, struct Value *x, int calc) { int v; - VALUE_RETYPE(self, V_REAL); + VALUE_RETYPE(this, V_REAL); VALUE_RETYPE(x, V_REAL); if (calc) { - v = (self->u.real != x->u.real) ? -1 : 0; + v = (this->u.real != x->u.real) ? -1 : 0; } else { v = 0; } - Value_destroy(self); - Value_new_INTEGER(self, v); + Value_destroy(this); + Value_new_INTEGER(this, v); break; } @@ -1342,15 +1338,15 @@ struct Value *Value_ne(struct Value *self, struct Value *x, int calc) if (calc) { - v = String_cmp(&self->u.string, &x->u.string) ? -1 : 0; + v = String_cmp(&this->u.string, &x->u.string) ? -1 : 0; } else { v = 0; } - Value_destroy(self); - Value_new_INTEGER(self, v); + Value_destroy(this); + Value_new_INTEGER(this, v); break; } @@ -1358,27 +1354,26 @@ struct Value *Value_ne(struct Value *self, struct Value *x, int calc) assert(0); } - return self; + return this; } -int Value_exitFor(struct Value *self, - struct Value *limit, struct Value *step) +int Value_exitFor(struct Value *this, struct Value *limit, struct Value *step) { - switch (self->type) + switch (this->type) { case V_INTEGER: return (step->u.integer < 0 - ? (self->u.integer < limit->u.integer) - : (self->u.integer > limit->u.integer)); + ? (this->u.integer < limit->u.integer) + : (this->u.integer > limit->u.integer)); case V_REAL: return (step->u.real < 0.0 - ? (self->u.real < limit->u.real) : (self->u.real > limit->u.real)); + ? (this->u.real < limit->u.real) : (this->u.real > limit->u.real)); case V_STRING: - return (String_cmp(&self->u.string, &limit->u.string) > 0); + return (String_cmp(&this->u.string, &limit->u.string) > 0); default: assert(0); @@ -1387,53 +1382,50 @@ int Value_exitFor(struct Value *self, return -1; } -void Value_errorPrefix(struct Value *self, const char *prefix) +void Value_errorPrefix(struct Value *this, const char *prefix) { - size_t prefixlen; - size_t msglen; + size_t prefixlen, msglen; - assert(self->type == V_ERROR); + assert(this->type == V_ERROR); prefixlen = strlen(prefix); - msglen = strlen(self->u.error.msg); - self->u.error.msg = realloc(self->u.error.msg, prefixlen + msglen + 1); - memmove(self->u.error.msg + prefixlen, self->u.error.msg, msglen); - memcpy(self->u.error.msg, prefix, prefixlen); + msglen = strlen(this->u.error.msg); + this->u.error.msg = realloc(this->u.error.msg, prefixlen + msglen + 1); + memmove(this->u.error.msg + prefixlen, this->u.error.msg, msglen); + memcpy(this->u.error.msg, prefix, prefixlen); } -void Value_errorSuffix(struct Value *self, const char *suffix) +void Value_errorSuffix(struct Value *this, const char *suffix) { - size_t suffixlen; - size_t msglen; + size_t suffixlen, msglen; - assert(self->type == V_ERROR); + assert(this->type == V_ERROR); suffixlen = strlen(suffix); - msglen = strlen(self->u.error.msg); - self->u.error.msg = realloc(self->u.error.msg, suffixlen + msglen + 1); - memcpy(self->u.error.msg + msglen, suffix, suffixlen + 1); + msglen = strlen(this->u.error.msg); + this->u.error.msg = realloc(this->u.error.msg, suffixlen + msglen + 1); + memcpy(this->u.error.msg + msglen, suffix, suffixlen + 1); } -struct Value *Value_new_typeError(struct Value *self, enum ValueType t1, +struct Value *Value_new_typeError(struct Value *this, enum ValueType t1, enum ValueType t2) { assert(typestr[t1]); assert(typestr[t2]); - return Value_new_ERROR(self, TYPEMISMATCH1, - _(typestr[t1]), _(typestr[t2])); + return Value_new_ERROR(this, TYPEMISMATCH1, _(typestr[t1]), _(typestr[t2])); } -static void retypeError(struct Value *self, enum ValueType to) +static void retypeError(struct Value *this, enum ValueType to) { - enum ValueType thisType = self->type; + enum ValueType thisType = this->type; assert(typestr[thisType]); assert(typestr[to]); - Value_destroy(self); - Value_new_ERROR(self, TYPEMISMATCH1, _(typestr[thisType]), _(typestr[to])); + Value_destroy(this); + Value_new_ERROR(this, TYPEMISMATCH1, _(typestr[thisType]), _(typestr[to])); } -struct Value *Value_retype(struct Value *self, enum ValueType type) +struct Value *Value_retype(struct Value *this, enum ValueType type) { - switch (self->type) + switch (this->type) { case V_INTEGER: { @@ -1443,17 +1435,17 @@ struct Value *Value_retype(struct Value *self, enum ValueType type) break; case V_REAL: - self->u.real = self->u.integer; - self->type = type; + this->u.real = this->u.integer; + this->type = type; break; case V_VOID: - Value_destroy(self); - Value_new_VOID(self); + Value_destroy(this); + Value_new_VOID(this); break; default: - retypeError(self, type); + retypeError(this, type); break; } break; @@ -1467,12 +1459,12 @@ struct Value *Value_retype(struct Value *self, enum ValueType type) { case V_INTEGER: { - self->u.integer = Value_toi(self->u.real, &overflow); - self->type = V_INTEGER; + this->u.integer = Value_toi(this->u.real, &overflow); + this->type = V_INTEGER; if (overflow) { - Value_destroy(self); - Value_new_ERROR(self, OUTOFRANGE, typestr[V_INTEGER]); + Value_destroy(this); + Value_new_ERROR(this, OUTOFRANGE, typestr[V_INTEGER]); } break; } @@ -1481,12 +1473,12 @@ struct Value *Value_retype(struct Value *self, enum ValueType type) break; case V_VOID: - Value_destroy(self); - Value_new_VOID(self); + Value_destroy(this); + Value_new_VOID(this); break; default: - retypeError(self, type); + retypeError(this, type); break; } break; @@ -1500,12 +1492,12 @@ struct Value *Value_retype(struct Value *self, enum ValueType type) break; case V_VOID: - Value_destroy(self); - Value_new_VOID(self); + Value_destroy(this); + Value_new_VOID(this); break; default: - retypeError(self, type); + retypeError(this, type); break; } break; @@ -1519,7 +1511,7 @@ struct Value *Value_retype(struct Value *self, enum ValueType type) break; default: - retypeError(self, type); + retypeError(this, type); } break; } @@ -1531,20 +1523,20 @@ struct Value *Value_retype(struct Value *self, enum ValueType type) assert(0); } - return self; + return this; } -struct String *Value_toString(struct Value *self, struct String *s, char pad, +struct String *Value_toString(struct Value *this, struct String *s, char pad, int headingsign, size_t width, int commas, int dollar, int dollarleft, int precision, int exponent, int trailingsign) { size_t oldlength = s->length; - switch (self->type) + switch (this->type) { case V_ERROR: - String_appendChars(s, self->u.error.msg); + String_appendChars(s, this->u.error.msg); break; case V_REAL: @@ -1555,14 +1547,14 @@ struct String *Value_toString(struct Value *self, struct String *s, char pad, size_t totalwidth = width; String_new(&buf); - if (self->type == V_INTEGER) + if (this->type == V_INTEGER) { - if (self->u.integer < 0) + if (this->u.integer < 0) { sign = -1; - self->u.integer = -self->u.integer; + this->u.integer = -this->u.integer; } - else if (self->u.integer == 0) + else if (this->u.integer == 0) { sign = 0; } @@ -1573,12 +1565,12 @@ struct String *Value_toString(struct Value *self, struct String *s, char pad, } else { - if (self->u.real < 0.0) + if (this->u.real < 0.0) { sign = -1; - self->u.real = -self->u.real; + this->u.real = -this->u.real; } - else if (self->u.real == 0.0) + else if (this->u.real == 0.0) { sign = 0; } @@ -1621,25 +1613,25 @@ struct String *Value_toString(struct Value *self, struct String *s, char pad, } totalwidth += exponent; - if (self->type == V_INTEGER) + if (this->type == V_INTEGER) { if (precision > 0 || exponent) { - format_double(&buf, (double)self->u.integer, width, - precision, exponent); + format_double(&buf, (double)this->u.integer, width, precision, + exponent); } else if (precision == 0) { - String_appendPrintf(&buf, "%lu.", self->u.integer); + String_appendPrintf(&buf, "%lu.", this->u.integer); } else { - String_appendPrintf(&buf, "%lu", self->u.integer); + String_appendPrintf(&buf, "%lu", this->u.integer); } } else { - format_double(&buf, self->u.real, width, precision, exponent); + format_double(&buf, this->u.real, width, precision, exponent); } if (commas) @@ -1704,21 +1696,21 @@ struct String *Value_toString(struct Value *self, struct String *s, char pad, if (width > 0) { size_t blanks = - (self->u.string.length < - width ? (width - self->u.string.length) : 0); + (this->u.string.length < + width ? (width - this->u.string.length) : 0); String_size(s, oldlength + width); - memcpy(s->character + oldlength, self->u.string.character, - blanks ? self->u.string.length : width); + memcpy(s->character + oldlength, this->u.string.character, + blanks ? this->u.string.length : width); if (blanks) { - memset(s->character + oldlength + self->u.string.length, ' ', + memset(s->character + oldlength + this->u.string.length, ' ', blanks); } } else { - String_appendString(s, &self->u.string); + String_appendString(s, &this->u.string); } break; } @@ -1731,7 +1723,7 @@ struct String *Value_toString(struct Value *self, struct String *s, char pad, return s; } -struct Value *Value_toStringUsing(struct Value *self, struct String *s, +struct Value *Value_toStringUsing(struct Value *this, struct String *s, struct String *using, size_t * usingpos) { char pad = ' '; @@ -1763,8 +1755,8 @@ struct Value *Value_toStringUsing(struct Value *self, struct String *s, } else { - Value_destroy(self); - return Value_new_ERROR(self, MISSINGCHARACTER); + Value_destroy(this); + return Value_new_ERROR(this, MISSINGCHARACTER); } break; @@ -1797,21 +1789,19 @@ struct Value *Value_toStringUsing(struct Value *self, struct String *s, } else { - Value_destroy(self); - return Value_new_ERROR(self, IOERROR, + Value_destroy(this); + return Value_new_ERROR(this, IOERROR, _("unpaired \\ in format")); } break; } - case '&': /* output string */ { width = 0; ++(*usingpos); goto work; } - case '*': case '$': case '0': @@ -1860,12 +1850,10 @@ struct Value *Value_toStringUsing(struct Value *self, struct String *s, default: ++width; } - ++(*usingpos); } - if (*usingpos < using->length && - using->character[*usingpos] == '.') + if (*usingpos < using->length && using->character[*usingpos] == '.') { ++(*usingpos); ++width; @@ -1880,20 +1868,18 @@ struct Value *Value_toStringUsing(struct Value *self, struct String *s, if (width == 1 && precision == 0) { - Value_destroy(self); - return Value_new_ERROR(self, BADFORMAT); + Value_destroy(this); + return Value_new_ERROR(this, BADFORMAT); } } - if (*usingpos < using->length && - using->character[*usingpos] == '-') + if (*usingpos < using->length && using->character[*usingpos] == '-') { ++(*usingpos); if (headingsign == 0) { headingsign = 2; } - trailingsign = -1; } else if (*usingpos < using->length && @@ -1904,7 +1890,6 @@ struct Value *Value_toStringUsing(struct Value *self, struct String *s, { headingsign = 2; } - trailingsign = 1; } @@ -1926,9 +1911,9 @@ struct Value *Value_toStringUsing(struct Value *self, struct String *s, } work: - Value_toString(self, s, pad, headingsign, width, commas, dollar, - dollarleft, precision, exponent, trailingsign); - if ((self->type == V_INTEGER || self->type == V_REAL) && width == 0 && + Value_toString(this, s, pad, headingsign, width, commas, dollar, dollarleft, + precision, exponent, trailingsign); + if ((this->type == V_INTEGER || this->type == V_REAL) && width == 0 && precision == -1) { String_appendChar(s, ' '); @@ -1947,8 +1932,8 @@ work: } else { - Value_destroy(self); - return Value_new_ERROR(self, MISSINGCHARACTER); + Value_destroy(this); + return Value_new_ERROR(this, MISSINGCHARACTER); } break; } @@ -1961,7 +1946,7 @@ work: case '+': case '#': case '.': - return self; + return this; default: { @@ -1970,25 +1955,24 @@ work: } } - return self; + return this; } -struct String *Value_toWrite(struct Value *self, struct String *s) +struct String *Value_toWrite(struct Value *this, struct String *s) { - switch (self->type) + switch (this->type) { case V_INTEGER: - String_appendPrintf(s, "%ld", self->u.integer); + String_appendPrintf(s, "%ld", this->u.integer); break; case V_REAL: { double x; int p = DBL_DIG; - int n; - int o; + int n, o; - x = (self->u.real < 0.0 ? -self->u.real : self->u.real); + x = (this->u.real < 0.0 ? -this->u.real : this->u.real); while (x > 1.0 && p > 0) { x /= 10.0; @@ -1996,7 +1980,7 @@ struct String *Value_toWrite(struct Value *self, struct String *s) } o = s->length; - String_appendPrintf(s, "%.*f", p, self->u.real); + String_appendPrintf(s, "%.*f", p, this->u.real); n = s->length; if (memchr(s->character + o, '.', n - o)) { @@ -2015,8 +1999,8 @@ struct String *Value_toWrite(struct Value *self, struct String *s) case V_STRING: { - size_t l = self->u.string.length; - char *data = self->u.string.character; + size_t l = this->u.string.length; + char *data = this->u.string.character; String_appendChar(s, '"'); while (l--) @@ -2043,21 +2027,10 @@ struct String *Value_toWrite(struct Value *self, struct String *s) struct Value *Value_nullValue(enum ValueType type) { - static struct Value integer = - { - V_INTEGER - }; - - static struct Value real = - { - V_REAL - }; - - static struct Value string = - { - V_STRING - }; - + static struct Value integer = { V_INTEGER }; + static struct Value real = { V_REAL }; + static struct Value string = { V_STRING }; + static char n[] = ""; static int init = 0; if (!init) @@ -2065,8 +2038,7 @@ struct Value *Value_nullValue(enum ValueType type) integer.u.integer = 0; real.u.real = 0.0; string.u.string.length = 0; - string.u.string.character = ""; - init = 1; + string.u.string.character = n; } switch (type) diff --git a/interpreters/bas/bas_value.h b/interpreters/bas/bas_value.h index 5a428bd5d..e364dba54 100644 --- a/interpreters/bas/bas_value.h +++ b/interpreters/bas/bas_value.h @@ -1,8 +1,7 @@ /**************************************************************************** * apps/interpreters/bas/bas_value.h * - * SPDX-License-Identifier: MIT - * SPDX-FileCopyrightText: 1999-2014 Michael Haardt + * Copyright (c) 1999-2014 Michael Haardt * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -15,7 +14,7 @@ * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING @@ -59,7 +58,7 @@ enum ValueType { - V_ERROR = 1, + V_ERROR=1, V_INTEGER, V_NIL, V_REAL, @@ -72,16 +71,12 @@ struct Value enum ValueType type; union { - struct /* V_ERROR */ - { - char *msg; - long int code; - } error; - long int integer; /* V_INTEGER */ - /* V_NIL */ - double real; /* V_REAL */ - struct String string; /* V_STRING */ - /* V_VOID */ + /* V_ERROR */ struct { char *msg; long int code; } error; + /* V_INTEGER */ long int integer; + /* V_NIL */ + /* V_REAL */ double real; + /* V_STRING */ struct String string; + /* V_VOID */ } u; }; @@ -89,7 +84,7 @@ struct Value * Public Data ****************************************************************************/ -extern const enum ValueType Value_commonType[V_VOID + 1][V_VOID + 1]; +extern const enum ValueType Value_commonType[V_VOID+1][V_VOID+1]; /**************************************************************************** * Public Function Prototypes @@ -102,53 +97,53 @@ long int Value_toi(double d, int *overflow); long int Value_vali(const char *s, char **end, int *overflow); double Value_vald(const char *s, char **end, int *overflow); -struct Value *Value_new_NIL(struct Value *self); -struct Value *Value_new_ERROR(struct Value *self, int code, - const char *error, ...) printf_like(3, 4); -struct Value *Value_new_INTEGER(struct Value *self, int n); -struct Value *Value_new_REAL(struct Value *self, double n); -struct Value *Value_new_STRING(struct Value *self); -struct Value *Value_new_VOID(struct Value *self); -struct Value *Value_new_null(struct Value *self, enum ValueType type); -int Value_isNull(const struct Value *self); -void Value_destroy(struct Value *self); -void Value_errorPrefix(struct Value *self, const char *prefix); -void Value_errorSuffix(struct Value *self, const char *suffix); -struct Value *Value_new_typeError(struct Value *self, enum ValueType t1, +struct Value *Value_new_NIL(struct Value *this); +struct Value *Value_new_ERROR(struct Value *this, int code, + const char *error, ...); +struct Value *Value_new_INTEGER(struct Value *this, int n); +struct Value *Value_new_REAL(struct Value *this, double n); +struct Value *Value_new_STRING(struct Value *this); +struct Value *Value_new_VOID(struct Value *this); +struct Value *Value_new_null(struct Value *this, enum ValueType type); +int Value_isNull(const struct Value *this); +void Value_destroy(struct Value *this); +void Value_errorPrefix(struct Value *this, const char *prefix); +void Value_errorSuffix(struct Value *this, const char *suffix); +struct Value *Value_new_typeError(struct Value *this, enum ValueType t1, enum ValueType t2); -struct Value *Value_retype(struct Value *self, enum ValueType type); -struct Value *Value_clone(struct Value *self, const struct Value *original); -struct Value *Value_uplus(struct Value *self, int calc); -struct Value *Value_uneg(struct Value *self, int calc); -struct Value *Value_unot(struct Value *self, int calc); -struct Value *Value_add(struct Value *self, struct Value *x, int calc); -struct Value *Value_sub(struct Value *self, struct Value *x, int calc); -struct Value *Value_mult(struct Value *self, struct Value *x, int calc); -struct Value *Value_div(struct Value *self, struct Value *x, int calc); -struct Value *Value_idiv(struct Value *self, struct Value *x, int calc); -struct Value *Value_mod(struct Value *self, struct Value *x, int calc); -struct Value *Value_pow(struct Value *self, struct Value *x, int calc); -struct Value *Value_and(struct Value *self, struct Value *x, int calc); -struct Value *Value_or(struct Value *self, struct Value *x, int calc); -struct Value *Value_xor(struct Value *self, struct Value *x, int calc); -struct Value *Value_eqv(struct Value *self, struct Value *x, int calc); -struct Value *Value_imp(struct Value *self, struct Value *x, int calc); -struct Value *Value_lt(struct Value *self, struct Value *x, int calc); -struct Value *Value_le(struct Value *self, struct Value *x, int calc); -struct Value *Value_eq(struct Value *self, struct Value *s, int calc); -struct Value *Value_ge(struct Value *self, struct Value *x, int calc); -struct Value *Value_gt(struct Value *self, struct Value *x, int calc); -struct Value *Value_ne(struct Value *self, struct Value *x, int calc); -int Value_exitFor(struct Value *self, struct Value *limit, +struct Value *Value_retype(struct Value *this, enum ValueType type); +struct Value *Value_clone(struct Value *this, const struct Value *original); +struct Value *Value_uplus(struct Value *this, int calc); +struct Value *Value_uneg(struct Value *this, int calc); +struct Value *Value_unot(struct Value *this, int calc); +struct Value *Value_add(struct Value *this, struct Value *x, int calc); +struct Value *Value_sub(struct Value *this, struct Value *x, int calc); +struct Value *Value_mult(struct Value *this, struct Value *x, int calc); +struct Value *Value_div(struct Value *this, struct Value *x, int calc); +struct Value *Value_idiv(struct Value *this, struct Value *x, int calc); +struct Value *Value_mod(struct Value *this, struct Value *x, int calc); +struct Value *Value_pow(struct Value *this, struct Value *x, int calc); +struct Value *Value_and(struct Value *this, struct Value *x, int calc); +struct Value *Value_or(struct Value *this, struct Value *x, int calc); +struct Value *Value_xor(struct Value *this, struct Value *x, int calc); +struct Value *Value_eqv(struct Value *this, struct Value *x, int calc); +struct Value *Value_imp(struct Value *this, struct Value *x, int calc); +struct Value *Value_lt(struct Value *this, struct Value *x, int calc); +struct Value *Value_le(struct Value *this, struct Value *x, int calc); +struct Value *Value_eq(struct Value *this, struct Value *s, int calc); +struct Value *Value_ge(struct Value *this, struct Value *x, int calc); +struct Value *Value_gt(struct Value *this, struct Value *x, int calc); +struct Value *Value_ne(struct Value *this, struct Value *x, int calc); +int Value_exitFor(struct Value *this, struct Value *limit, struct Value *step); -struct String *Value_toString(struct Value *self, struct String *s, +struct String *Value_toString(struct Value *this, struct String *s, char pad, int headingsign, size_t width, int commas, int dollar, int dollarleft, int precision, int exponent, int trailingsign); -struct Value *Value_toStringUsing(struct Value *self, struct String *s, +struct Value *Value_toStringUsing(struct Value *this, struct String *s, struct String *using, size_t *usingpos); -struct String *Value_toWrite(struct Value *self, struct String *s); +struct String *Value_toWrite(struct Value *this, struct String *s); struct Value *Value_nullValue(enum ValueType type); #endif /* __APPS_EXAMPLES_BAS_BAS_VALUE_H */ diff --git a/interpreters/bas/bas_var.c b/interpreters/bas/bas_var.c index 1e26dca22..e31adde58 100644 --- a/interpreters/bas/bas_var.c +++ b/interpreters/bas/bas_var.c @@ -1,8 +1,7 @@ /**************************************************************************** * apps/interpreters/bas/bas_var.c * - * SPDX-License-Identifier: MIT - * SPDX-FileCopyrightText: 1999-2014 Michael Haardt + * Copyright (c) 1999-2014 Michael Haardt * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -47,141 +46,141 @@ * Public Functions ****************************************************************************/ -struct Var *Var_new(struct Var *self, enum ValueType type, unsigned int dim, +struct Var *Var_new(struct Var *this, enum ValueType type, unsigned int dim, const unsigned int *geometry, int base) { unsigned int i; size_t newsize; - self->type = type; - self->dim = dim; - self->base = base; - for (newsize = self->size = 1, dim = 0; dim < self->dim; ++dim) + this->type = type; + this->dim = dim; + this->base = base; + for (newsize = this->size = 1, dim = 0; dim < this->dim; ++dim) { - if ((newsize *= geometry[dim]) < self->size) + if ((newsize *= geometry[dim]) < this->size) return (struct Var *)0; - self->size = newsize; + this->size = newsize; } - if ((newsize *= sizeof(struct Value)) < self->size) + if ((newsize *= sizeof(struct Value)) < this->size) { return (struct Var *)0; } - if ((self->value = malloc(newsize)) == (struct Value *)0) + if ((this->value = malloc(newsize)) == (struct Value *)0) { return (struct Var *)0; } if (dim) { - self->geometry = malloc(sizeof(unsigned int) * dim); + this->geometry = malloc(sizeof(unsigned int) * dim); for (i = 0; i < dim; ++i) { - self->geometry[i] = geometry[i]; + this->geometry[i] = geometry[i]; } } else { - self->geometry = (unsigned int *)0; + this->geometry = (unsigned int *)0; } - for (i = 0; i < self->size; ++i) + for (i = 0; i < this->size; ++i) { - Value_new_null(&(self->value[i]), type); + Value_new_null(&(this->value[i]), type); } - return self; + return this; } -struct Var *Var_new_scalar(struct Var *self) +struct Var *Var_new_scalar(struct Var *this) { - self->dim = 0; - self->size = 1; - self->geometry = (unsigned int *)0; - self->value = malloc(sizeof(struct Value)); - return self; + this->dim = 0; + this->size = 1; + this->geometry = (unsigned int *)0; + this->value = malloc(sizeof(struct Value)); + return this; } -void Var_destroy(struct Var *self) +void Var_destroy(struct Var *this) { - while (self->size--) + while (this->size--) { - Value_destroy(&(self->value[self->size])); + Value_destroy(&(this->value[this->size])); } - free(self->value); - self->value = (struct Value *)0; - self->size = 0; - self->dim = 0; - if (self->geometry) + free(this->value); + this->value = (struct Value *)0; + this->size = 0; + this->dim = 0; + if (this->geometry) { - free(self->geometry); - self->geometry = (unsigned int *)0; + free(this->geometry); + this->geometry = (unsigned int *)0; } } -void Var_retype(struct Var *self, enum ValueType type) +void Var_retype(struct Var *this, enum ValueType type) { unsigned int i; - for (i = 0; i < self->size; ++i) + for (i = 0; i < this->size; ++i) { - Value_destroy(&(self->value[i])); - Value_new_null(&(self->value[i]), type); + Value_destroy(&(this->value[i])); + Value_new_null(&(this->value[i]), type); } } -struct Value *Var_value(struct Var *self, unsigned int dim, int idx[], +struct Value *Var_value(struct Var *this, unsigned int dim, int idx[], struct Value *value) { unsigned int offset; unsigned int i; - assert(self->value); - if (dim != self->dim) + assert(this->value); + if (dim != this->dim) { return Value_new_ERROR(value, DIMENSION); } for (offset = 0, i = 0; i < dim; ++i) { - if (idx[i] < self->base || (idx[i] - self->base) >= self->geometry[i]) + if (idx[i] < this->base || (idx[i] - this->base) >= this->geometry[i]) { return Value_new_ERROR(value, OUTOFRANGE, _("array index")); } - offset = offset * self->geometry[i] + (idx[i] - self->base); + offset = offset * this->geometry[i] + (idx[i] - this->base); } - assert(offset < self->size); - return self->value + offset; + assert(offset < this->size); + return this->value + offset; } -void Var_clear(struct Var *self) +void Var_clear(struct Var *this) { size_t i; - for (i = 0; i < self->size; ++i) + for (i = 0; i < this->size; ++i) { - Value_destroy(&(self->value[i])); + Value_destroy(&(this->value[i])); } - if (self->geometry) + if (this->geometry) { - free(self->geometry); - self->geometry = (unsigned int *)0; - self->size = 1; - self->dim = 0; + free(this->geometry); + this->geometry = (unsigned int *)0; + this->size = 1; + this->dim = 0; } - Value_new_null(&(self->value[0]), self->type); + Value_new_null(&(this->value[0]), this->type); } -struct Value *Var_mat_assign(struct Var *self, struct Var *x, struct Value *err, +struct Value *Var_mat_assign(struct Var *this, struct Var *x, struct Value *err, int work) { - enum ValueType thisType = self->type; + enum ValueType thisType = this->type; if (work) { @@ -191,13 +190,13 @@ struct Value *Var_mat_assign(struct Var *self, struct Var *x, struct Value *err, assert(x->base == 0 || x->base == 1); assert(x->dim == 1 || x->dim == 2); - if (self == x) + if (this == x) { return (struct Value *)0; } - Var_destroy(self); - Var_new(self, thisType, x->dim, x->geometry, x->base); + Var_destroy(this); + Var_new(this, thisType, x->dim, x->geometry, x->base); g0 = x->geometry[0]; g1 = x->dim == 1 ? unused + 1 : x->geometry[1]; for (i = unused; i < g0; ++i) @@ -206,27 +205,27 @@ struct Value *Var_mat_assign(struct Var *self, struct Var *x, struct Value *err, { unsigned int element = x->dim == 1 ? i : i * g1 + j; - Value_destroy(&(self->value[element])); - Value_clone(&(self->value[element]), &(x->value[element])); - Value_retype(&(self->value[element]), thisType); + Value_destroy(&(this->value[element])); + Value_clone(&(this->value[element]), &(x->value[element])); + Value_retype(&(this->value[element]), thisType); } } } else { - if (Value_commonType[self->type][x->type] == V_ERROR) + if (Value_commonType[this->type][x->type] == V_ERROR) { - return Value_new_typeError(err, self->type, x->type); + return Value_new_typeError(err, this->type, x->type); } } return (struct Value *)0; } -struct Value *Var_mat_addsub(struct Var *self, struct Var *x, struct Var *y, +struct Value *Var_mat_addsub(struct Var *this, struct Var *x, struct Var *y, int add, struct Value *err, int work) { - enum ValueType thisType = self->type; + enum ValueType thisType = this->type; struct Value foo, bar; if (work) @@ -244,10 +243,10 @@ struct Value *Var_mat_addsub(struct Var *self, struct Var *x, struct Var *y, return Value_new_ERROR(err, DIMENSION); } - if (self != x && self != y) + if (this != x && this != y) { - Var_destroy(self); - Var_new(self, thisType, x->dim, x->geometry, x->base); + Var_destroy(this); + Var_new(this, thisType, x->dim, x->geometry, x->base); } g0 = x->geometry[0]; @@ -277,8 +276,8 @@ struct Value *Var_mat_addsub(struct Var *self, struct Var *x, struct Var *y, } Value_destroy(&bar); - Value_destroy(&(self->value[element])); - self->value[element] = *Value_retype(&foo, thisType); + Value_destroy(&(this->value[element])); + this->value[element] = *Value_retype(&foo, thisType); } } } @@ -305,10 +304,10 @@ struct Value *Var_mat_addsub(struct Var *self, struct Var *x, struct Var *y, return (struct Value *)0; } -struct Value *Var_mat_mult(struct Var *self, struct Var *x, struct Var *y, +struct Value *Var_mat_mult(struct Var *this, struct Var *x, struct Var *y, struct Value *err, int work) { - enum ValueType thisType = self->type; + enum ValueType thisType = this->type; struct Var foo; if (work) @@ -355,8 +354,8 @@ struct Value *Var_mat_mult(struct Var *self, struct Var *x, struct Var *y, } } - Var_destroy(self); - *self = foo; + Var_destroy(this); + *this = foo; } else { @@ -373,10 +372,10 @@ struct Value *Var_mat_mult(struct Var *self, struct Var *x, struct Var *y, return (struct Value *)0; } -struct Value *Var_mat_scalarMult(struct Var *self, struct Value *factor, +struct Value *Var_mat_scalarMult(struct Var *this, struct Value *factor, struct Var *x, int work) { - enum ValueType thisType = self->type; + enum ValueType thisType = this->type; if (work) { @@ -386,10 +385,10 @@ struct Value *Var_mat_scalarMult(struct Var *self, struct Value *factor, assert(x->base == 0 || x->base == 1); assert(x->dim == 1 || x->dim == 2); - if (self != x) + if (this != x) { - Var_destroy(self); - Var_new(self, thisType, x->dim, x->geometry, 0); + Var_destroy(this); + Var_new(this, thisType, x->dim, x->geometry, 0); } g0 = x->geometry[0]; @@ -410,14 +409,14 @@ struct Value *Var_mat_scalarMult(struct Var *self, struct Value *factor, return factor; } - Value_destroy(&(self->value[element])); - self->value[element] = *Value_retype(&foo, thisType); + Value_destroy(&(this->value[element])); + this->value[element] = *Value_retype(&foo, thisType); } } } else { - if (Value_mult(factor, self->value, 0)->type == V_ERROR) + if (Value_mult(factor, this->value, 0)->type == V_ERROR) { return factor; } @@ -426,10 +425,10 @@ struct Value *Var_mat_scalarMult(struct Var *self, struct Value *factor, return (struct Value *)0; } -void Var_mat_transpose(struct Var *self, struct Var *x) +void Var_mat_transpose(struct Var *this, struct Var *x) { unsigned int geometry[2]; - enum ValueType thisType = self->type; + enum ValueType thisType = this->type; unsigned int i, j; struct Var foo; @@ -447,14 +446,14 @@ void Var_mat_transpose(struct Var *self, struct Var *x) } } - Var_destroy(self); - *self = foo; + Var_destroy(this); + *this = foo; } -struct Value *Var_mat_invert(struct Var *self, struct Var *x, struct Value *det, +struct Value *Var_mat_invert(struct Var *this, struct Var *x, struct Value *det, struct Value *err) { - enum ValueType thisType = self->type; + enum ValueType thisType = this->type; int n, i, j, k, max; double t, *a, *u, d; int unused = 1 - x->base; @@ -582,26 +581,26 @@ struct Value *Var_mat_invert(struct Var *self, struct Var *x, struct Value *det, } free(a); - if (self != x) + if (this != x) { - Var_destroy(self); - Var_new(self, thisType, 2, x->geometry, x->base); + Var_destroy(this); + Var_new(this, thisType, 2, x->geometry, x->base); } for (i = 0; i < n; ++i) { for (j = 0; j < n; ++j) { - Value_destroy(&self->value[(i + unused) * (n + unused) + j + unused]); + Value_destroy(&this->value[(i + unused) * (n + unused) + j + unused]); if (thisType == V_INTEGER) { - Value_new_INTEGER(&self->value + Value_new_INTEGER(&this->value [(i + unused) * (n + unused) + j + unused], u[i * n + j]); } else { - Value_new_REAL(&self-> + Value_new_REAL(&this-> value[(i + unused) * (n + unused) + j + unused], u[i * n + j]); } @@ -622,15 +621,15 @@ struct Value *Var_mat_invert(struct Var *self, struct Var *x, struct Value *det, return (struct Value *)0; } -struct Value *Var_mat_redim(struct Var *self, unsigned int dim, +struct Value *Var_mat_redim(struct Var *this, unsigned int dim, const unsigned int *geometry, struct Value *err) { unsigned int i, j, size; struct Value *value; - int unused = 1 - self->base; + int unused = 1 - this->base; int g0, g1; - if (self->dim > 0 && self->dim != dim) + if (this->dim > 0 && this->dim != dim) { return Value_new_ERROR(err, DIMENSION); } @@ -647,39 +646,39 @@ struct Value *Var_mat_redim(struct Var *self, unsigned int dim, { for (j = 0; j < g1; ++j) { - if (self->dim == 0 || i < unused || (dim == 2 && j < unused) || - i >= self->geometry[0] || (self->dim == 2 && - j >= self->geometry[1])) + if (this->dim == 0 || i < unused || (dim == 2 && j < unused) || + i >= this->geometry[0] || (this->dim == 2 && + j >= this->geometry[1])) { - Value_new_null(&(value[i * g1 + j]), self->type); + Value_new_null(&(value[i * g1 + j]), this->type); } else { Value_clone(&value[dim == 1 ? i : i * g1 + j], - &self->value[dim == - 1 ? i : i * self->geometry[1] + j]); + &this->value[dim == + 1 ? i : i * this->geometry[1] + j]); } } } - for (i = 0; i < self->size; ++i) + for (i = 0; i < this->size; ++i) { - Value_destroy(&self->value[i]); + Value_destroy(&this->value[i]); } - free(self->value); - if (self->geometry == (unsigned int *)0) + free(this->value); + if (this->geometry == (unsigned int *)0) { - self->geometry = malloc(sizeof(unsigned int) * dim); + this->geometry = malloc(sizeof(unsigned int) * dim); } for (i = 0; i < dim; ++i) { - self->geometry[i] = geometry[i]; + this->geometry[i] = geometry[i]; } - self->dim = dim; - self->size = size; - self->value = value; + this->dim = dim; + this->size = size; + this->value = value; return (struct Value *)0; } diff --git a/interpreters/bas/bas_var.h b/interpreters/bas/bas_var.h index 1f5f0444b..14b24195c 100644 --- a/interpreters/bas/bas_var.h +++ b/interpreters/bas/bas_var.h @@ -1,8 +1,7 @@ /**************************************************************************** * apps/interpreters/bas/bas_var.h * - * SPDX-License-Identifier: MIT - * SPDX-FileCopyrightText: 1999-2014 Michael Haardt + * Copyright (c) 1999-2014 Michael Haardt * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -37,7 +36,7 @@ * Pre-processor Definitions ****************************************************************************/ -#define VAR_SCALAR_VALUE(self) ((self)->value) +#define VAR_SCALAR_VALUE(this) ((this)->value) /**************************************************************************** * Public Types @@ -57,26 +56,26 @@ struct Var * Public Function Prototypes ****************************************************************************/ -struct Var *Var_new(struct Var *self, enum ValueType type, unsigned int dim, +struct Var *Var_new(struct Var *this, enum ValueType type, unsigned int dim, const unsigned int *geometry, int base); -struct Var *Var_new_scalar(struct Var *self); -void Var_destroy(struct Var *self); -void Var_retype(struct Var *self, enum ValueType type); -struct Value *Var_value(struct Var *self, unsigned int dim, int idx[], +struct Var *Var_new_scalar(struct Var *this); +void Var_destroy(struct Var *this); +void Var_retype(struct Var *this, enum ValueType type); +struct Value *Var_value(struct Var *this, unsigned int dim, int idx[], struct Value *value); -void Var_clear(struct Var *self); -struct Value *Var_mat_assign(struct Var *self, struct Var *x, +void Var_clear(struct Var *this); +struct Value *Var_mat_assign(struct Var *this, struct Var *x, struct Value *err, int work); -struct Value *Var_mat_addsub(struct Var *self, struct Var *x, struct Var *y, +struct Value *Var_mat_addsub(struct Var *this, struct Var *x, struct Var *y, int add, struct Value *err, int work); -struct Value *Var_mat_mult(struct Var *self, struct Var *x, struct Var *y, +struct Value *Var_mat_mult(struct Var *this, struct Var *x, struct Var *y, struct Value *err, int work); -struct Value *Var_mat_scalarMult(struct Var *self, struct Value *factor, +struct Value *Var_mat_scalarMult(struct Var *this, struct Value *factor, struct Var *x, int work); -void Var_mat_transpose(struct Var *self, struct Var *x); -struct Value *Var_mat_invert(struct Var *self, struct Var *x, +void Var_mat_transpose(struct Var *this, struct Var *x); +struct Value *Var_mat_invert(struct Var *this, struct Var *x, struct Value *det, struct Value *err); -struct Value *Var_mat_redim(struct Var *self, unsigned int dim, +struct Value *Var_mat_redim(struct Var *this, unsigned int dim, const unsigned int *geometry, struct Value *err); diff --git a/interpreters/bas/bas_vt100.c b/interpreters/bas/bas_vt100.c index 84410232d..7d04ad8a1 100644 --- a/interpreters/bas/bas_vt100.c +++ b/interpreters/bas/bas_vt100.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/interpreters/bas/bas_vt100.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -226,8 +224,7 @@ void vt100_setcursor(int chn, uint16_t row, uint16_t column) /* Format the cursor position command. The origin is (1,1). */ - len = snprintf(buffer, sizeof(buffer), g_fmt_cursorpos, - row + 1, column + 1); + len = snprintf(buffer, 16, g_fmt_cursorpos, row + 1, column + 1); /* Send the VT100 CURSORPOS command */ @@ -327,7 +324,7 @@ void vt100_foreground_color(int chn, uint8_t color) /* Format the foreground color command. */ DEBUGASSERT(color < 10); - len = snprintf(buffer, sizeof(buffer), g_fmt_forecolor, color); + len = snprintf(buffer, 16, g_fmt_forecolor, color); /* Send the VT100 foreground color command */ @@ -350,7 +347,7 @@ void vt100_background_color(int chn, uint8_t color) /* Format the background color command. */ DEBUGASSERT(color < 10); - len = snprintf(buffer, sizeof(buffer), g_fmt_backcolor, color); + len = snprintf(buffer, 16, g_fmt_backcolor, color); /* Send the VT100 background color command */ diff --git a/interpreters/bas/bas_vt100.h b/interpreters/bas/bas_vt100.h index fc7b5d2c5..45ade3d26 100644 --- a/interpreters/bas/bas_vt100.h +++ b/interpreters/bas/bas_vt100.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/interpreters/bas/bas_vt100.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/interpreters/berry/.gitattributes b/interpreters/berry/.gitattributes deleted file mode 100644 index 0a83e0afa..000000000 --- a/interpreters/berry/.gitattributes +++ /dev/null @@ -1 +0,0 @@ -0001-Fix-Berry-default-port-for-NuttX.patch whitespace=cr-at-eol,-blank-at-eol diff --git a/interpreters/berry/0001-Fix-Berry-default-port-for-NuttX.patch b/interpreters/berry/0001-Fix-Berry-default-port-for-NuttX.patch deleted file mode 100644 index 5e720d07d..000000000 --- a/interpreters/berry/0001-Fix-Berry-default-port-for-NuttX.patch +++ /dev/null @@ -1,57 +0,0 @@ -diff --git a/default/berry.c b/default/berry.c -index 203773f..0df2a99 100644 ---- a/default/berry.c -+++ b/default/berry.c -@@ -19,7 +19,9 @@ - #endif - - /* detect operating system name */ --#if defined(__linux) -+#if defined(__NuttX__) -+ #define OS_NAME "NuttX" -+#elif defined(__linux) - #define OS_NAME "Linux" - #elif defined(__unix) - #define OS_NAME "Unix" -@@ -98,7 +100,7 @@ - struct arg_opts { - int idx; - const char *pattern; -- const char *optarg; -+ const char *optvalue; - const char *errarg; - const char *src; - const char *dst; -@@ -143,10 +145,10 @@ static int arg_getopt(struct arg_opts *opt, int argc, char *argv[]) - /* the '?' indicates an optional argument after the option */ - if (++opt->idx < argc && res != NULL - && res[1] == '?' && *argv[opt->idx] != '-') { -- opt->optarg = argv[opt->idx++]; /* save the argument */ -+ opt->optvalue = argv[opt->idx++]; /* save the argument */ - return *res; - } -- opt->optarg = NULL; -+ opt->optvalue = NULL; - opt->errarg = arg; - return res != NULL ? *res : '?'; - } -@@ -267,16 +269,16 @@ static int parse_arg(struct arg_opts *opt, int argc, char *argv[]) - case 's': args |= arg_s; break; - case 'm': - args |= arg_m; -- opt->modulepath = opt->optarg; -+ opt->modulepath = opt->optvalue; - break; - case '?': return args | arg_err; - case 'c': - args |= arg_c; -- opt->src = opt->optarg; -+ opt->src = opt->optvalue; - break; - case 'o': - args |= arg_o; -- opt->dst = opt->optarg; -+ opt->dst = opt->optvalue; - break; - default: - break; diff --git a/interpreters/berry/CMakeLists.txt b/interpreters/berry/CMakeLists.txt deleted file mode 100644 index d4749851b..000000000 --- a/interpreters/berry/CMakeLists.txt +++ /dev/null @@ -1,148 +0,0 @@ -# ############################################################################## -# apps/interpreters/berry/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_INTERPRETERS_BERRY) - set(BERRY_COMMIT_ID 4db341475df9e9ad18e6741ef978b4c467690e09) - set(BERRY_DIR ${CMAKE_CURRENT_LIST_DIR}/berry) - - if(NOT EXISTS ${BERRY_DIR}) - set(BERRY_URL_BASE https://github.com/berry-lang/berry/archive/) - - FetchContent_Declare( - berry_fetch - URL ${BERRY_URL_BASE}/${BERRY_COMMIT_ID}.zip SOURCE_DIR - ${CMAKE_CURRENT_LIST_DIR}/berry BINARY_DIR - ${CMAKE_BINARY_DIR}/apps/interpreters/berry/berry - PATCH_COMMAND - patch -l -p1 -d ${CMAKE_CURRENT_LIST_DIR}/berry -i - ${CMAKE_CURRENT_LIST_DIR}/0001-Fix-Berry-default-port-for-NuttX.patch - DOWNLOAD_NO_PROGRESS true - TIMEOUT 30) - - FetchContent_GetProperties(berry_fetch) - - if(NOT berry_fetch_POPULATED) - FetchContent_Populate(berry_fetch) - endif() - endif() - - find_package( - Python3 - COMPONENTS Interpreter - REQUIRED) - - set(BERRY_CONFIG_DIR ${CMAKE_CURRENT_LIST_DIR}/include) - set(BERRY_CONFIG ${BERRY_CONFIG_DIR}/berry_conf.h) - set(BERRY_GENERATE ${BERRY_DIR}/generate) - set(BERRY_GEN_STAMP ${BERRY_GENERATE}/.generated) - set(BERRY_FLAGS -Wno-unused-but-set-variable -Wno-shadow) - set(BERRY_INCDIR ${BERRY_CONFIG_DIR} ${BERRY_DIR}/src ${BERRY_DIR}/default) - - set(BERRY_CSRCS - ${BERRY_DIR}/src/be_api.c - ${BERRY_DIR}/src/be_baselib.c - ${BERRY_DIR}/src/be_bytecode.c - ${BERRY_DIR}/src/be_byteslib.c - ${BERRY_DIR}/src/be_class.c - ${BERRY_DIR}/src/be_code.c - ${BERRY_DIR}/src/be_debug.c - ${BERRY_DIR}/src/be_debuglib.c - ${BERRY_DIR}/src/be_exec.c - ${BERRY_DIR}/src/be_filelib.c - ${BERRY_DIR}/src/be_func.c - ${BERRY_DIR}/src/be_gc.c - ${BERRY_DIR}/src/be_gclib.c - ${BERRY_DIR}/src/be_globallib.c - ${BERRY_DIR}/src/be_introspectlib.c - ${BERRY_DIR}/src/be_jsonlib.c - ${BERRY_DIR}/src/be_lexer.c - ${BERRY_DIR}/src/be_libs.c - ${BERRY_DIR}/src/be_list.c - ${BERRY_DIR}/src/be_listlib.c - ${BERRY_DIR}/src/be_map.c - ${BERRY_DIR}/src/be_maplib.c - ${BERRY_DIR}/src/be_mathlib.c - ${BERRY_DIR}/src/be_mem.c - ${BERRY_DIR}/src/be_module.c - ${BERRY_DIR}/src/be_object.c - ${BERRY_DIR}/src/be_oslib.c - ${BERRY_DIR}/src/be_parser.c - ${BERRY_DIR}/src/be_rangelib.c - ${BERRY_DIR}/src/be_repl.c - ${BERRY_DIR}/src/be_solidifylib.c - ${BERRY_DIR}/src/be_strictlib.c - ${BERRY_DIR}/src/be_string.c - ${BERRY_DIR}/src/be_strlib.c - ${BERRY_DIR}/src/be_syslib.c - ${BERRY_DIR}/src/be_timelib.c - ${BERRY_DIR}/src/be_undefinedlib.c - ${BERRY_DIR}/src/be_var.c - ${BERRY_DIR}/src/be_vector.c - ${BERRY_DIR}/src/be_vm.c - ${BERRY_DIR}/default/be_modtab.c - ${BERRY_DIR}/default/be_port.c) - - add_custom_command( - OUTPUT ${BERRY_GEN_STAMP} - COMMAND ${CMAKE_COMMAND} -E make_directory ${BERRY_GENERATE} - COMMAND - ${Python3_EXECUTABLE} ${BERRY_DIR}/tools/coc/coc -o ${BERRY_GENERATE} - ${BERRY_DIR}/src ${BERRY_DIR}/default -c ${BERRY_CONFIG} - COMMAND ${CMAKE_COMMAND} -E touch ${BERRY_GEN_STAMP} - DEPENDS ${BERRY_CSRCS} ${BERRY_CONFIG} - WORKING_DIRECTORY ${BERRY_DIR} - COMMENT "Generating Berry constant objects") - - add_custom_target(berry_coc DEPENDS ${BERRY_GEN_STAMP}) - - nuttx_add_library(libberry) - target_sources(libberry PRIVATE ${BERRY_CSRCS}) - target_include_directories(libberry PRIVATE ${BERRY_INCDIR}) - target_compile_options(libberry PRIVATE ${BERRY_FLAGS}) - add_dependencies(libberry berry_coc) - nuttx_export_header(TARGET libberry INCLUDE_DIRECTORIES ${BERRY_DIR}/src) - - set_property( - TARGET nuttx - APPEND - PROPERTY NUTTX_INCLUDE_DIRECTORIES ${BERRY_DIR}/src) - - nuttx_add_application( - MODULE - ${CONFIG_INTERPRETERS_BERRY} - NAME - ${CONFIG_INTERPRETERS_BERRY_PROGNAME} - STACKSIZE - ${CONFIG_INTERPRETERS_BERRY_STACKSIZE} - PRIORITY - ${CONFIG_INTERPRETERS_BERRY_PRIORITY} - SRCS - ${BERRY_DIR}/default/berry.c - INCLUDE_DIRECTORIES - ${BERRY_INCDIR} - COMPILE_FLAGS - ${BERRY_FLAGS} - DEPENDS - libberry - berry_coc) - -endif() diff --git a/interpreters/berry/Kconfig b/interpreters/berry/Kconfig deleted file mode 100644 index 805c61866..000000000 --- a/interpreters/berry/Kconfig +++ /dev/null @@ -1,43 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config INTERPRETERS_BERRY - tristate "Berry scripting language" - default n - depends on ARCH_SETJMP_H - depends on LIBC_FLOATINGPOINT - depends on SYSTEM_SYSTEM - ---help--- - Enable the Berry embedded scripting language as an NSH built-in - command. Berry provides a small ANSI C99 compiler, register-based - virtual machine, garbage collector, file I/O, bytecode loading and - saving, and built-in modules. - - The default NuttX configuration keeps Berry shared-library loading - disabled so boards do not need CONFIG_LIBC_DLFCN. The math module - is enabled, so select a NuttX math library or provide one from the - toolchain. - -if INTERPRETERS_BERRY - -config INTERPRETERS_BERRY_PROGNAME - string "Berry program name" - default "berry" - ---help--- - The command name used to start the Berry interpreter. - -config INTERPRETERS_BERRY_PRIORITY - int "Berry interpreter priority" - default 100 - ---help--- - Task priority of the Berry interpreter main task. - -config INTERPRETERS_BERRY_STACKSIZE - int "Berry interpreter stack size" - default 12288 - ---help--- - Size of the stack allocated for the Berry interpreter main task. - -endif # INTERPRETERS_BERRY diff --git a/interpreters/berry/Make.defs b/interpreters/berry/Make.defs deleted file mode 100644 index 48a5e64ef..000000000 --- a/interpreters/berry/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/interpreters/berry/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_INTERPRETERS_BERRY),) -CONFIGURED_APPS += $(APPDIR)/interpreters/berry -endif diff --git a/interpreters/berry/Makefile b/interpreters/berry/Makefile deleted file mode 100644 index 510a5e86a..000000000 --- a/interpreters/berry/Makefile +++ /dev/null @@ -1,98 +0,0 @@ -############################################################################ -# apps/interpreters/berry/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -BERRY_COMMIT_ID = 4db341475df9e9ad18e6741ef978b4c467690e09 -BERRY_UNPACK = berry -BERRY_ARCHIVE = berry-$(BERRY_COMMIT_ID).zip -BERRY_URL_BASE = https://github.com/berry-lang/berry/archive/ -BERRY_URL = $(BERRY_URL_BASE)/$(BERRY_COMMIT_ID).zip -BERRY_CONFIG = include$(DELIM)berry_conf.h -BERRY_COC = $(BERRY_UNPACK)$(DELIM)tools$(DELIM)coc$(DELIM)coc -BERRY_GENERATE = $(BERRY_UNPACK)$(DELIM)generate -BERRY_GEN_STAMP = $(BERRY_GENERATE)$(DELIM).generated - -BERRY_SRCS = be_api.c be_baselib.c be_bytecode.c be_byteslib.c -BERRY_SRCS += be_class.c be_code.c be_debug.c be_debuglib.c be_exec.c -BERRY_SRCS += be_filelib.c be_func.c be_gc.c be_gclib.c be_globallib.c -BERRY_SRCS += be_introspectlib.c be_jsonlib.c be_lexer.c be_libs.c -BERRY_SRCS += be_list.c be_listlib.c be_map.c be_maplib.c be_mathlib.c -BERRY_SRCS += be_mem.c be_module.c be_object.c be_oslib.c be_parser.c -BERRY_SRCS += be_rangelib.c be_repl.c be_solidifylib.c be_strictlib.c -BERRY_SRCS += be_string.c be_strlib.c be_syslib.c be_timelib.c -BERRY_SRCS += be_undefinedlib.c be_var.c be_vector.c be_vm.c - -CSRCS = $(BERRY_SRCS) -CSRCS += be_modtab.c be_port.c - -MAINSRC = berry.c - -VPATH += $(BERRY_UNPACK)$(DELIM)src -VPATH += $(BERRY_UNPACK)$(DELIM)default -DEPPATH += --dep-path $(BERRY_UNPACK)$(DELIM)src -DEPPATH += --dep-path $(BERRY_UNPACK)$(DELIM)default - -CFLAGS += ${INCDIR_PREFIX}$(APPDIR)$(DELIM)interpreters$(DELIM)berry$(DELIM)include -CFLAGS += ${INCDIR_PREFIX}$(APPDIR)$(DELIM)interpreters$(DELIM)berry$(DELIM)$(BERRY_UNPACK)$(DELIM)src -CFLAGS += ${INCDIR_PREFIX}$(APPDIR)$(DELIM)interpreters$(DELIM)berry$(DELIM)$(BERRY_UNPACK)$(DELIM)default -CFLAGS += -Wno-unused-but-set-variable -CFLAGS += -Wno-shadow - -PROGNAME = $(CONFIG_INTERPRETERS_BERRY_PROGNAME) -PRIORITY = $(CONFIG_INTERPRETERS_BERRY_PRIORITY) -STACKSIZE = $(CONFIG_INTERPRETERS_BERRY_STACKSIZE) -MODULE = $(CONFIG_INTERPRETERS_BERRY) - -$(BERRY_ARCHIVE): - $(Q) echo "Downloading $(BERRY_ARCHIVE)" - $(Q) curl -L $(BERRY_URL) -o $(BERRY_ARCHIVE) - -$(BERRY_UNPACK): $(BERRY_ARCHIVE) - $(Q) echo "Unpacking $(BERRY_ARCHIVE) to $(BERRY_UNPACK)" - $(Q) unzip -q -o $(BERRY_ARCHIVE) - $(call DELDIR, $(BERRY_UNPACK)) - $(Q) mv berry-$(BERRY_COMMIT_ID) $(BERRY_UNPACK) - $(Q) patch -l -d $(BERRY_UNPACK) -p1 < 0001-Fix-Berry-default-port-for-NuttX.patch - -$(BERRY_GEN_STAMP): $(BERRY_UNPACK) $(BERRY_CONFIG) - $(Q) echo "Generating Berry constant objects" - $(Q) mkdir -p $(BERRY_GENERATE) - $(Q) python3 $(BERRY_COC) -o $(BERRY_GENERATE) \ - $(BERRY_UNPACK)$(DELIM)src \ - $(BERRY_UNPACK)$(DELIM)default \ - -c $(BERRY_CONFIG) - $(Q) touch $(BERRY_GEN_STAMP) - -ifeq ($(wildcard $(BERRY_UNPACK)/.git),) -context:: $(BERRY_GEN_STAMP) -endif - -depend:: $(BERRY_GEN_STAMP) - -distclean:: -ifeq ($(wildcard $(BERRY_UNPACK)/.git),) - $(call DELDIR, $(BERRY_UNPACK)) - $(call DELFILE, $(BERRY_ARCHIVE)) -endif - -include $(APPDIR)/Application.mk diff --git a/interpreters/berry/include/berry_conf.h b/interpreters/berry/include/berry_conf.h deleted file mode 100644 index 633d9cdc9..000000000 --- a/interpreters/berry/include/berry_conf.h +++ /dev/null @@ -1,86 +0,0 @@ -/**************************************************************************** - * apps/interpreters/berry/include/berry_conf.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __APPS_INTERPRETERS_BERRY_INCLUDE_BERRY_CONF_H -#define __APPS_INTERPRETERS_BERRY_INCLUDE_BERRY_CONF_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define BE_DEBUG 0 -#define BE_INTGER_TYPE 2 -#define BE_USE_SINGLE_FLOAT 0 -#define BE_BYTES_MAX_SIZE (32 * 1024) -#define BE_USE_PRECOMPILED_OBJECT 1 -#define BE_DEBUG_SOURCE_FILE 1 -#define BE_DEBUG_RUNTIME_INFO 1 -#define BE_DEBUG_VAR_INFO 1 -#define BE_USE_PERF_COUNTERS 1 -#define BE_VM_OBSERVABILITY_SAMPLING 20 -#define BE_STACK_TOTAL_MAX 20000 -#define BE_STACK_FREE_MIN 10 -#define BE_STACK_START 50 -#define BE_CONST_SEARCH_SIZE 50 -#define BE_USE_STR_HASH_CACHE 0 -#define BE_USE_FILE_SYSTEM 1 -#define BE_USE_SCRIPT_COMPILER 1 -#define BE_USE_BYTECODE_SAVER 1 -#define BE_USE_BYTECODE_LOADER 1 -#define BE_USE_SHARED_LIB 0 -#define BE_USE_OVERLOAD_HASH 1 -#define BE_USE_DEBUG_HOOK 0 -#define BE_USE_DEBUG_GC 0 -#define BE_USE_DEBUG_STACK 0 -#define BE_USE_MEM_ALIGNED 0 - -#define BE_USE_STRING_MODULE 1 -#define BE_USE_JSON_MODULE 1 -#define BE_USE_MATH_MODULE 1 -#define BE_USE_TIME_MODULE 1 -#define BE_USE_OS_MODULE 1 -#define BE_USE_GLOBAL_MODULE 1 -#define BE_USE_SYS_MODULE 1 -#define BE_USE_DEBUG_MODULE 1 -#define BE_USE_GC_MODULE 1 -#define BE_USE_SOLIDIFY_MODULE 1 -#define BE_USE_INTROSPECT_MODULE 1 -#define BE_USE_STRICT_MODULE 1 - -#define BE_EXPLICIT_ABORT abort -#define BE_EXPLICIT_EXIT exit -#define BE_EXPLICIT_MALLOC malloc -#define BE_EXPLICIT_FREE free -#define BE_EXPLICIT_REALLOC realloc - -#define be_assert(expr) assert(expr) - -#endif /* __APPS_INTERPRETERS_BERRY_INCLUDE_BERRY_CONF_H */ diff --git a/interpreters/duktape/Make.defs b/interpreters/duktape/Make.defs index e0627acf7..5c2b45f8f 100644 --- a/interpreters/duktape/Make.defs +++ b/interpreters/duktape/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/interpreters/duktape/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -24,7 +22,9 @@ ifneq ($(CONFIG_INTERPRETERS_DUKTAPE),) CONFIGURED_APPS += $(APPDIR)/interpreters/duktape # It allows `` import. -CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/interpreters/duktape/duktape/src-noline -CXXFLAGS += ${INCDIR_PREFIX}$(APPDIR)/interpreters/duktape/duktape/src-noline +CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" \ + $(APPDIR)/interpreters/duktape/duktape/src-noline} +CXXFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" \ + $(APPDIR)/interpreters/duktape/duktape/src-noline} endif diff --git a/interpreters/duktape/Makefile b/interpreters/duktape/Makefile index c6a0a621e..93f61ee56 100644 --- a/interpreters/duktape/Makefile +++ b/interpreters/duktape/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/interpreters/duktape/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -49,7 +47,6 @@ CFLAGS += -I$(DUKTAPE_UNPACK)/extras/console CFLAGS += -I$(DUKTAPE_UNPACK)/extras/print-alert CFLAGS += -DDUK_CMDLINE_CONSOLE_SUPPORT CFLAGS += -DDUK_CMDLINE_PRINTALERT_SUPPORT -CFLAGS += -Wno-unused-but-set-variable $(DUKTAPE_TARBALL): $(Q) echo "Downloading $(DUKTAPE_TARBALL)" @@ -65,13 +62,10 @@ $(DUKTAPE_UNPACK): $(DUKTAPE_TARBALL) $(DUKTAPE_UNPACK)/.patch: $(DUKTAPE_UNPACK) $(Q) touch $(DUKTAPE_UNPACK)/.patch -# Download and unpack tarball if no git repo found -ifeq ($(wildcard $(DUKTAPE_UNPACK)/.git),) context:: $(DUKTAPE_UNPACK)/.patch distclean:: $(call DELDIR, $(DUKTAPE_UNPACK)) $(call DELFILE, $(DUKTAPE_TARBALL)) -endif include $(APPDIR)/Application.mk diff --git a/interpreters/ficl/Make.defs b/interpreters/ficl/Make.defs index 95cbe50b9..0bc6d335a 100644 --- a/interpreters/ficl/Make.defs +++ b/interpreters/ficl/Make.defs @@ -1,25 +1,3 @@ -############################################################################ -# apps/interpreters/ficl/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_INTERPRETERS_FICL),) +ifeq ($(CONFIG_INTERPRETERS_FICL),y) CONFIGURED_APPS += $(APPDIR)/interpreters/ficl endif diff --git a/interpreters/ficl/Makefile b/interpreters/ficl/Makefile index 46d058e13..c478b10d4 100644 --- a/interpreters/ficl/Makefile +++ b/interpreters/ficl/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/interpreters/ficl/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -32,7 +30,7 @@ include $(APPDIR)/Make.defs # Include paths -CFLAGS += ${INCDIR_PREFIX}$(BUILDDIR)/$(FICL_SUBDIR) $(BUILDDIR)/src +CFLAGS += ${shell $(INCDIR) "$(CC)" $(BUILDDIR)/$(FICL_SUBDIR) $(BUILDDIR)/src} # Source Files diff --git a/interpreters/ficl/README.md b/interpreters/ficl/README.md new file mode 100644 index 000000000..743a1ee63 --- /dev/null +++ b/interpreters/ficl/README.md @@ -0,0 +1,39 @@ +# Interpreters / `ficl` Ficl + +Ficl is a programming language interpreter designed to be embedded into other +systems as a command, macro, and development prototyping language. Ficl is an +acronym for _Forth Inspired Command Language_. See http://ficl.sourceforge.net/ + +## Build Instructions + +Disclaimer: This installation steps have only been exercised using Ficl 4.1.0. +With new versions you will likely have to make some adjustments to this +instructtions or to the files within this directory. Think of this information +as _recommendations_ - not necessarily proven instructions. + +1. `cd` to `interpreters/ficl` + +2. Download Ficl: http://sourceforge.net/projects/ficl/files/ + +3. Uznip the Ficl compressed file. + + For example, `unzip ficl-4.1.0.zip` will leave the file + `interpreters/ficl/ficl-4.1.0`. + +4. Configure to build Ficl in the `interpreters/ficl` directory using the + `configure.sh` script. + + For example, `./configure.sh ficl-4.1.0` will leave the Makefile fragment + `Make.srcs` in the ficl build directory. + +5. Create your NuttX configuration. Using the `make menuconfig`, you should + select: + + ```conf + CONFIG_INTERPRETERS_FICL=y + ``` + +6. Configure and build NuttX. On successful completion, the Ficl objects will be + available in `apps/libapps.a` and that NuttX binary will be linked against + that file. Of course, Ficl will do nothing unless you have written some + application code that uses it! diff --git a/interpreters/ficl/configure.sh b/interpreters/ficl/configure.sh index d7e232d3a..d84e0d4fc 100755 --- a/interpreters/ficl/configure.sh +++ b/interpreters/ficl/configure.sh @@ -1,26 +1,4 @@ #!/usr/bin/env bash -############################################################################ -# apps/interpreters/ficl/configure.sh -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - USAGE="$0 " diff --git a/interpreters/ficl/src/nuttx.c b/interpreters/ficl/src/nuttx.c index 86cc1712b..0aacffc15 100644 --- a/interpreters/ficl/src/nuttx.c +++ b/interpreters/ficl/src/nuttx.c @@ -1,31 +1,39 @@ /**************************************************************************** - * apps/interpreters/ficl/src/nuttx.c + * apps/interpreters/minibasic/basic.c * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ***************************************************************************/ - -/**************************************************************************** + * Copyright (C) 2016 Gregory Nutt. All rights reserved. * * This file was taken from Mini Basic, versino 1.0 developed by Malcolm * McLean, Leeds University. Mini Basic version 1.0 was released the * Creative Commons Attribution license which, from my reading, appears to - * be compatible with the NuttX license. + * be compatible with the NuttX BSD-style license: + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. * ****************************************************************************/ @@ -105,4 +113,5 @@ long ficlFileSize(ficlFile *ff) void ficlSystemCompilePlatform(ficlSystem *system) { + return; } diff --git a/interpreters/ficl/src/nuttx.h b/interpreters/ficl/src/nuttx.h index d1b94a170..d6f9be32d 100644 --- a/interpreters/ficl/src/nuttx.h +++ b/interpreters/ficl/src/nuttx.h @@ -1,8 +1,6 @@ /*************************************************************************** * apps/interpreters/ficl/src/nuttx.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -20,9 +18,6 @@ * ***************************************************************************/ -#ifndef __APPS_INTERPRETERS_FICL_SRC_NUTTX_H -#define __APPS_INTERPRETERS_FICL_SRC_NUTTX_H - /*************************************************************************** * Included Files ***************************************************************************/ @@ -46,5 +41,3 @@ typedef float ficlFloat; #define FICL_PLATFORM_OS "ansi" #define FICL_PLATFORM_ARCHITECTURE "unknown" - -#endif /* __APPS_INTERPRETERS_FICL_SRC_NUTTX_H */ diff --git a/interpreters/jimtcl/CMakeLists.txt b/interpreters/jimtcl/CMakeLists.txt deleted file mode 100644 index ba3b64697..000000000 --- a/interpreters/jimtcl/CMakeLists.txt +++ /dev/null @@ -1,48 +0,0 @@ -if(CONFIG_INTERPRETERS_JIMTCL) - set(JIMTCL_VERSION 0.83) - set(JIMTCL_TARBALL ${JIMTCL_VERSION}.tar.gz) - set(JIMTCL_UNPACK jimtcl) - set(JIMTCL_URL_BASE https://github.com/msteveb/jimtcl/archive/refs/tags) - set(JIMTCL_URL ${JIMTCL_URL_BASE}/${JIMTCL_TARBALL}) - set(JIMTCL_SRC ${CMAKE_CURRENT_BINARY_DIR}/${JIMTCL_UNPACK}) - - # We need the source available before declaring the application, because - # jimsh.c is added as an application source, so we can not integrate download - # into the external project. - FetchContent_Declare(jimtcl_fetch URL ${JIMTCL_URL} SOURCE_DIR - ${JIMTCL_UNPACK}) - - FetchContent_MakeAvailable(jimtcl_fetch) - - ExternalProject_Add( - jimtcl_build - SOURCE_DIR ${JIMTCL_SRC} - PATCH_COMMAND sed -i -e "/^void Jim_SetEnviron/,/^/{s/^/\\/* /}" -e - "/^void Jim_SetEnviron/,/^/{s/\$/ *\\//}" jim.c - CONFIGURE_COMMAND - ./configure --host=${CMAKE_C_COMPILER_TARGET} - "CFLAGS=$, > -D$, -D> -I$, -I> -isystem ${CMAKE_SOURCE_DIR}/include -isystem ${CMAKE_BINARY_DIR}/include" - BUILD_COMMAND make libjim.a initjimsh.o - INSTALL_COMMAND "" - BUILD_IN_SOURCE TRUE - BUILD_BYPRODUCTS ${JIMTCL_SRC}/libjim.a ${JIMTCL_SRC}/_initjimsh.c) - - nuttx_add_application( - NAME - jimsh - PRIORITY - 100 - STACKSIZE - 8192 - INCLUDE_DIRECTORIES - ${JIMTCL_SRC} - DEPENDS - jimtcl_build - SRCS - ${JIMTCL_SRC}/jimsh.c - ${JIMTCL_SRC}/_initjimsh.c) - - set_property(GLOBAL APPEND PROPERTY NUTTX_EXTRA_LIBRARIES - ${JIMTCL_SRC}/libjim.a) - -endif() diff --git a/interpreters/jimtcl/Kconfig b/interpreters/jimtcl/Kconfig deleted file mode 100644 index 16a70db70..000000000 --- a/interpreters/jimtcl/Kconfig +++ /dev/null @@ -1,12 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config INTERPRETERS_JIMTCL - bool "The Jim (TCL) Interpreter" - default n - ---help--- - Enable support for The Jim interpreter. - Jim is an opensource small-footprint implementation of the - Tcl programming language. \ No newline at end of file diff --git a/interpreters/jimtcl/Make.defs b/interpreters/jimtcl/Make.defs deleted file mode 100644 index eb5a44b0c..000000000 --- a/interpreters/jimtcl/Make.defs +++ /dev/null @@ -1,3 +0,0 @@ -ifneq ($(CONFIG_INTERPRETERS_JIMTCL),) -CONFIGURED_APPS += $(APPDIR)/interpreters/jimtcl -endif \ No newline at end of file diff --git a/interpreters/jimtcl/Makefile b/interpreters/jimtcl/Makefile deleted file mode 100644 index f470167f2..000000000 --- a/interpreters/jimtcl/Makefile +++ /dev/null @@ -1,64 +0,0 @@ -include $(APPDIR)/Make.defs - -PROGNAME = jimsh -PRIORITY = 100 -STACKSIZE = 8192 - -JIMTCL_VERSION = 0.83 -JIMTCL_TARBALL = $(JIMTCL_VERSION).tar.gz -JIMTCL_UNPACK = jimtcl -JIMTCL_URL_BASE = https://github.com/msteveb/jimtcl/archive/refs/tags -JIMTCL_URL = $(JIMTCL_URL_BASE)/$(JIMTCL_TARBALL) -JIMTCL_SRC = $(JIMTCL_UNPACK) - -MAINSRC = $(JIMTCL_SRC)$(DELIM)jimsh.c - -# Obtain object list from jimtcl Makefile -JIMTCL_OBJS := $(shell test -f $(JIMTCL_SRC)$(DELIM)Makefile \ - && ( cat $(JIMTCL_SRC)$(DELIM)Makefile; \ - printf 'print-%%:\n\techo $$($$*)' ) \ - | $(MAKE) -f - -s print-OBJS) initjimsh.o - -EXTOBJS = $(addprefix $(JIMTCL_SRC)$(DELIM), $(JIMTCL_OBJS)) - -CFLAGS += -I$(JIMTCL_SRC) - -$(JIMTCL_SRC)$(DELIM)%.o: $(JIMTCL_SRC)$(DELIM)Makefile - $(Q) $(MAKE) -C $(JIMTCL_SRC) $*.o - -$(JIMTCL_SRC)$(DELIM)jimsh.c: $(JIMTCL_SRC)$(DELIM)Makefile - -$(JIMTCL_SRC)$(DELIM)_initjimsh.c: $(JIMTCL_SRC)$(DELIM)Makefile - $(Q) $(MAKE) -C $(JIMTCL_SRC) $(notdir $@) - -$(JIMTCL_SRC)$(DELIM)Makefile: - $(Q) cd $(dir $@) \ - && ./configure --host=$(patsubst %-,%,$(CROSSDEV)) \ - CFLAGS="$(CFLAGS)" - -# Get the source code and apply a small patch because environ is -# not settable in Nuttx. This is not required for basic jimtcl -# but build would fail without commenting it out. -$(JIMTCL_TARBALL): - $(Q) echo "Downloading $(JIMTCL_TARBALL)" - $(Q) curl -O -L $(JIMTCL_URL) - $(Q) echo "Unpacking $(JIMTCL_TARBALL) to $(JIMTCL_UNPACK)" - $(Q) tar -xvzf $(JIMTCL_TARBALL) - $(Q) mv jimtcl-$(JIMTCL_VERSION) $(JIMTCL_UNPACK) - $(Q) sed -i '/^void Jim_SetEnviron/,/^}/{s/^/\/* /;s/$$/ *\//}' \ - $(JIMTCL_SRC)$(DELIM)jim.c - -# Download and unpack tarball if no git repo found -ifeq ($(wildcard $(JIMTCL_UNPACK)/.git),) -context:: $(JIMTCL_TARBALL) -endif - -clean:: - $(Q) test -f $(JIMTCL_SRC)$(DELIM)Makefile \ - && $(MAKE) -C $(JIMTCL_SRC) clean - -distclean:: clean - $(call DELDIR, $(JIMTCL_UNPACK)) - $(call DELFILE, $(JIMTCL_TARBALL)) - -include $(APPDIR)/Application.mk diff --git a/interpreters/lua/.gitignore b/interpreters/lua/.gitignore deleted file mode 100644 index b66b519c8..000000000 --- a/interpreters/lua/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -*.tar.gz -lua/ -/luamod_list.h -/luamod_proto.h diff --git a/interpreters/lua/CMakeLists.txt b/interpreters/lua/CMakeLists.txt deleted file mode 100644 index 863c63514..000000000 --- a/interpreters/lua/CMakeLists.txt +++ /dev/null @@ -1,149 +0,0 @@ -# ############################################################################## -# apps/interpreters/lua/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_INTERPRETERS_LUA) - - # ############################################################################ - # Config and Fetch lua - # ############################################################################ - - set(LUA_DIR ${CMAKE_CURRENT_LIST_DIR}/lua) - - if(NOT EXISTS ${LUA_DIR}) - set(LUA_URL https://github.com/lua/lua/archive/refs/tags/) - FetchContent_Declare( - lua_fetch - URL ${LUA_URL}/v${CONFIG_INTERPRETERS_LUA_VERSION}.tar.gz SOURCE_DIR - ${CMAKE_CURRENT_LIST_DIR}/lua BINARY_DIR - ${CMAKE_BINARY_DIR}/apps/interpreters/lua/lua - DOWNLOAD_NO_PROGRESS true - TIMEOUT 30) - - FetchContent_GetProperties(lua_fetch) - - if(NOT lua_fetch_POPULATED) - FetchContent_Populate(lua_fetch) - endif() - endif() - - # ############################################################################ - # Flags - # ############################################################################ - - set(CFLAGS -DLUA_MAXINPUT=${CONFIG_INTERPRETERS_LUA_IOBUFSIZE} - -DLUA_PROGNAME=\"lua\") - if(CONFIG_INTERPRETERS_LUA_32BITS) - list(APPEND CFLAGS -DLUA_32BITS) - endif() - if(NOT "${CONFIG_INTERPRETERS_LUA_PATH}" STREQUAL "") - list(APPEND CFLAGS -DLUA_PATH_DEFAULT=\"${CONFIG_INTERPRETERS_LUA_PATH}\") - endif() - - if(NOT "${CONFIG_INTERPRETERS_LUA_CPATH}" STREQUAL "") - list(APPEND CFLAGS -DLUA_CPATH_DEFAULT=\"${CONFIG_INTERPRETERS_LUA_CPATH}\") - endif() - - if(CONFIG_SYSTEM_READLINE) - set(LUA_SYSTEM_READLINE_DEF - [=[ - #define lua_initreadline(L) ((void)L) - #define lua_readline(L,b,p) ((void)L,fputs(p,stdout),fflush(stdout),readline_stream(b,LUA_MAXINPUT,stdin,stdout)) - #define lua_saveline(L,line) {(void)L;(void)line;} - #define lua_freeline(L,line) {(void)L;(void)b;} - ]=]) - - file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/def_lua_readline.h - "${LUA_SYSTEM_READLINE_DEF}") - list(APPEND CFLAGS "SHELL:-include \"system/readline.h\"") - list(APPEND CFLAGS - "SHELL:-include ${CMAKE_CURRENT_BINARY_DIR}/def_lua_readline.h") - - endif() - - # ############################################################################ - # Sources - # ############################################################################ - - file(GLOB CORELIBS_SRCS ${LUA_DIR}/*lib.c) - list(REMOVE_ITEM CORELIBS_SRCS ${LUA_DIR}/lauxlib.c) - file(GLOB CSRCS ${LUA_DIR}/*.c) - list( - REMOVE_ITEM - CSRCS - ${LUA_DIR}/onelua.c - ${LUA_DIR}/luac.c - ${LUA_DIR}/linit.c - ${LUA_DIR}/lua.c - ${CORELIBS_SRCS}) - list(APPEND CSRCS nuttx_linit.c) - - if(CONFIG_INTERPRETERS_LUA_CORELIBS) - list(APPEND CSRCS ${CORELIBS_SRCS}) - - set(LUA_LIB_H_PATH ${LUA_DIR}/lualib.h) - file(READ "${LUA_LIB_H_PATH}" FILE_CONTENTS) - string(REGEX MATCHALL "#define[ \t]+LUA_[A-Z]+LIBNAME[ \t]+\"[^\"]+\"" - LIB_DEFINITIONS "${FILE_CONTENTS}") - foreach(DEFINITION IN LISTS LIB_DEFINITIONS) - string(REGEX REPLACE ".*\"([^\"]+)\"" "\\1" LIB_NAME "${DEFINITION}") - # register lua core mod - nuttx_add_luamod(MODS ${LIB_NAME}) - endforeach() - endif() - - # ############################################################################ - # Include Directory - # ############################################################################ - - set(INCDIR ${LUAMOD_DIR}) - - # ############################################################################ - # Library Configuration - # ############################################################################ - - set_property( - TARGET nuttx - APPEND - PROPERTY NUTTX_INCLUDE_DIRECTORIES ${LUA_DIR}) - - # ############################################################################ - # Applications Configuration - # ############################################################################ - - nuttx_add_application( - MODULE - ${CONFIG_INTERPRETERS_LUA} - NAME - lua - STACKSIZE - ${CONFIG_INTERPRETERS_LUA_STACKSIZE} - PRIORITY - ${CONFIG_INTERPRETERS_LUA_PRIORITY} - SRCS - ${LUA_DIR}/lua.c - ${CSRCS} - INCLUDE_DIRECTORIES - ${INCDIR} - COMPILE_FLAGS - ${CFLAGS}) - -endif() diff --git a/interpreters/lua/Kconfig b/interpreters/lua/Kconfig deleted file mode 100644 index 418cf8472..000000000 --- a/interpreters/lua/Kconfig +++ /dev/null @@ -1,67 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -menuconfig INTERPRETERS_LUA - bool "Lua interpreter support" - default n - select ARCH_SETJMP_H - select LIBC_LOCALE - ---help--- - Embed Lua language interpreter. - Select the Lua version with the INTERPRETERS_LUA_VERSION config. - A math library is required. Use the LIBM config or a toolchain library. - It's suggested to enable the SYSTEM_READLINE and LIBC_FLOATINGPOINT configs. - -if INTERPRETERS_LUA - -config INTERPRETERS_LUA_VERSION - string "Lua interpreter version" - default "5.4.0" - ---help--- - Lua release version to fetch and build. - Versions 5.2.0 and up are supported. - -config INTERPRETERS_LUA_CORELIBS - bool "Load core Lua modules" - default y - select SYSTEM_SYSTEM - ---help--- - Load core Lua modules like "os", "string", and "table". - -config INTERPRETERS_LUA_PATH - string "Lua modules search path" - ---help--- - Override default package.path search path for Lua modules. - -config INTERPRETERS_LUA_CPATH - string "Lua C modules search path" - ---help--- - Override default package.cpath search path for C modules. - -config INTERPRETERS_LUA_32BIT - bool "Use 32-bit integers and floats" - default y - ---help--- - "Use int and float instead of long and double for Lua numbers." - -config INTERPRETERS_LUA_PRIORITY - int "Lua interpreter priority" - default 100 - ---help--- - Task priority of the Lua interpreter main task. - -config INTERPRETERS_LUA_STACKSIZE - int "Lua interpreter stack size" - default 32768 - ---help--- - Size of the stack allocated for the Lua interpreter main task. - -config INTERPRETERS_LUA_IOBUFSIZE - int "I/O buffer size" - default 1024 - ---help--- - Size of the statically allocated I/O buffer. - -endif # INTERPRETERS_LUA diff --git a/interpreters/lua/Make.defs b/interpreters/lua/Make.defs deleted file mode 100644 index a0cf323ab..000000000 --- a/interpreters/lua/Make.defs +++ /dev/null @@ -1,33 +0,0 @@ -############################################################################ -# apps/interpreters/lua/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_INTERPRETERS_LUA),) -CONFIGURED_APPS += $(APPDIR)/interpreters/lua - -# Enable and includes. - -CFLAGS += ${INCDIR_PREFIX}\ - $(APPDIR)/interpreters/lua/lua -CXXFLAGS += ${INCDIR_PREFIX}\ - $(APPDIR)/interpreters/lua/lua - -endif diff --git a/interpreters/lua/Makefile b/interpreters/lua/Makefile deleted file mode 100644 index 40daf76ed..000000000 --- a/interpreters/lua/Makefile +++ /dev/null @@ -1,141 +0,0 @@ -############################################################################ -# apps/interpreters/lua/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -# Lua built-in application info - -PROGNAME = lua -PRIORITY = $(CONFIG_INTERPRETERS_LUA_PRIORITY) -STACKSIZE = $(CONFIG_INTERPRETERS_LUA_STACKSIZE) -MODULE = $(CONFIG_INTERPRETERS_LUA) - -# Lua library - -LUA_VERSION = $(patsubst "%",%,$(strip $(CONFIG_INTERPRETERS_LUA_VERSION))) -LUA_TARBALL = v$(LUA_VERSION).tar.gz -LUA_UNPACK = lua -LUA_URL_BASE = https://github.com/lua/lua/archive/refs/tags/ -LUA_URL = $(LUA_URL_BASE)/$(LUA_TARBALL) -LUA_SRC = $(LUA_UNPACK) - -MAINSRC = $(LUA_SRC)$(DELIM)lua.c -CORELIBS_SRCS = $(filter-out $(LUA_SRC)$(DELIM)lauxlib.c,$(wildcard $(LUA_SRC)$(DELIM)*lib.c)) -EXCLUDE_SRCS = $(MAINSRC) $(CORELIBS_SRCS) $(LUA_SRC)$(DELIM)onelua.c $(LUA_SRC)$(DELIM)luac.c $(LUA_SRC)$(DELIM)linit.c -CSRCS = $(filter-out $(EXCLUDE_SRCS),$(wildcard $(LUA_SRC)$(DELIM)*.c)) -CSRCS += nuttx_linit.c - -CFLAGS += -DLUA_MAXINPUT=$(CONFIG_INTERPRETERS_LUA_IOBUFSIZE) -CFLAGS += -DLUA_PROGNAME=\"$(PROGNAME)\" - -ifeq ($(CONFIG_INTERPRETERS_LUA_32BITS),y) -CFLAGS += -DLUA_32BITS -endif - -ifneq ($(CONFIG_INTERPRETERS_LUA_PATH),"") -CFLAGS += -DLUA_PATH_DEFAULT=\"$(CONFIG_INTERPRETERS_LUA_PATH)\" -endif - -ifneq ($(CONFIG_INTERPRETERS_LUA_CPATH),"") -CFLAGS += -DLUA_CPATH_DEFAULT=\"$(CONFIG_INTERPRETERS_LUA_CPATH)\" -endif - -ifeq ($(CONFIG_SYSTEM_READLINE),y) -CFLAGS += -include "system/readline.h" -CFLAGS += -D'lua_initreadline(L)=((void)L)' -CFLAGS += -D'lua_readline(L,b,p)=((void)L,fputs(p,stdout),fflush(stdout),readline_stream(b,LUA_MAXINPUT,stdin,stdout))' -CFLAGS += -D'lua_saveline(L,line)={(void)L;(void)line;}' -CFLAGS += -D'lua_freeline(L,line)={(void)L;(void)b;}' -endif - -# Lua download and unpack - -$(LUA_TARBALL): - $(Q) echo "Downloading $(LUA_TARBALL)" - $(Q) curl -O -L $(LUA_URL) - $(Q) echo "Unpacking $(LUA_TARBALL) to $(LUA_UNPACK)" - $(Q) tar -xvzf $(LUA_TARBALL) - $(Q) mv lua-$(LUA_VERSION) $(LUA_UNPACK) - -# Download and unpack tarball if no git repo found -ifeq ($(wildcard $(LUA_UNPACK)/.git),) -context:: $(LUA_TARBALL) -endif - -# Register core modules - -ifeq ($(CONFIG_INTERPRETERS_LUA_CORELIBS),y) -CSRCS += $(CORELIBS_SRCS) - -register:: - # collect core module names from defines in lualib.h - $(Q) while read -r line; do \ - name=$$(expr "$$line" : '#define LUA_[[:upper:]]\+LIBNAME[[:space:]]\+"\([[:lower:]]\+\)"'); \ - if [ ! -z $$name ]; then \ - printf '{ "%s", luaopen_%s },\n' $$name $$name > registry$(DELIM)$$name.bdat; \ - fi done < $(LUA_SRC)$(DELIM)lualib.h -endif - -# Lua builtin module registry - -PDATLIST = $(strip $(call RWILDCARD, registry, *.pdat)) -BDATLIST = $(strip $(call RWILDCARD, registry, *.bdat)) - -lua_main.c: luamod_list.h luamod_proto.h - -registry$(DELIM).updated: - $(Q) touch registry$(DELIM).updated - -luamod_list.h: registry$(DELIM).updated -ifeq ($(BDATLIST),) - $(call DELFILE, luamod_list.h) - $(Q) touch luamod_list.h -else - $(call CATFILE, luamod_list.h, $(BDATLIST)) -endif - -luamod_proto.h: registry$(DELIM).updated -ifeq ($(PDATLIST),) - $(call DELFILE, luamod_proto.h) - $(Q) touch luamod_proto.h -else - $(call CATFILE, luamod_proto.h, $(PDATLIST)) -endif - -depend:: luamod_list.h luamod_proto.h - -clean:: - $(call DELFILE, luamod_list.h) - $(call DELFILE, luamod_proto.h) - -clean_context:: - $(call DELFILE, $(PDATLIST)) - $(call DELFILE, $(BDATLIST)) - -distclean:: clean_context clean - $(call DELFILE, registry$(DELIM).updated) -ifeq ($(wildcard $(LUA_UNPACK)/.git),) - $(call DELDIR, $(LUA_UNPACK)) - $(call DELFILE, $(LUA_TARBALL)) -endif - -include $(APPDIR)/Application.mk diff --git a/interpreters/lua/Module.mk b/interpreters/lua/Module.mk deleted file mode 100644 index 52e9023c0..000000000 --- a/interpreters/lua/Module.mk +++ /dev/null @@ -1,39 +0,0 @@ -############################################################################ -# apps/interpreters/lua/Module.mk -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -LUAMOD_REGISTRY = $(APPDIR)$(DELIM)interpreters$(DELIM)lua$(DELIM)registry - -define LUAMOD_REGISTER - $(Q) echo Register Lua Module: $1 - $(Q) echo { \"$1\", $2 }, > "$(LUAMOD_REGISTRY)$(DELIM)$1.bdat" - $(Q) echo "int $2(lua_State *L);" > "$(LUAMOD_REGISTRY)$(DELIM)$1.pdat" - $(Q) touch "$(LUAMOD_REGISTRY)$(DELIM).updated" -endef - -ifneq ($(LUAMODNAME),) -LUAMODLIST := $(addprefix $(LUAMOD_REGISTRY)$(DELIM),$(addsuffix .bdat,$(LUAMODNAME))) -$(LUAMODLIST): $(DEPCONFIG) Makefile - $(call LUAMOD_REGISTER,$(firstword $(LUAMODNAME)),$(firstword luaopen_$(LUAMODNAME))) - $(eval LUAMODNAME=$(filter-out $(firstword $(LUAMODNAME)),$(LUAMODNAME))) - -register:: $(LUAMODLIST) -endif diff --git a/interpreters/lua/nuttx_linit.c b/interpreters/lua/nuttx_linit.c deleted file mode 100644 index 904eb9f81..000000000 --- a/interpreters/lua/nuttx_linit.c +++ /dev/null @@ -1,78 +0,0 @@ -/**************************************************************************** - * apps/interpreters/lua/nuttx_linit.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include - -#include - -#include "luamod_proto.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#ifndef LUA_GNAME -# define LUA_GNAME "_G" -#endif - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static const luaL_Reg g_loadedlibs[] = -{ -#ifdef CONFIG_INTERPRETERS_LUA_CORELIBS - {LUA_GNAME, luaopen_base}, -#endif -#include "luamod_list.h" - {NULL, NULL}, -}; - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: luaL_openlibs - * - * Make core and user-defined modules available to the Lua interpreter. - * This function is called from lua.c during interpreter initialization. - * - ****************************************************************************/ - -void luaL_openlibs(lua_State *L) -{ - const luaL_Reg *lib; - for (lib = g_loadedlibs; lib->func; lib++) - { - luaL_requiref(L, lib->name, lib->func, 1); - lua_pop(L, 1); - } -} diff --git a/interpreters/lua/registry/.gitignore b/interpreters/lua/registry/.gitignore deleted file mode 100644 index 3fd3b08fc..000000000 --- a/interpreters/lua/registry/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -.updated -*.pdat -*.bdat diff --git a/interpreters/luajit/.gitignore b/interpreters/luajit/.gitignore deleted file mode 100644 index 335ec9573..000000000 --- a/interpreters/luajit/.gitignore +++ /dev/null @@ -1 +0,0 @@ -*.tar.gz diff --git a/interpreters/luajit/0001-luajit-armv7m-nuttx.patch b/interpreters/luajit/0001-luajit-armv7m-nuttx.patch deleted file mode 100644 index d6c20879e..000000000 --- a/interpreters/luajit/0001-luajit-armv7m-nuttx.patch +++ /dev/null @@ -1,10330 +0,0 @@ -diff --git a/Makefile b/Makefile -index b0288b4d..f387077c 100644 ---- a/Makefile -+++ b/Makefile -@@ -90,7 +90,7 @@ FILE_MAN= luajit.1 - FILE_PC= luajit.pc - FILES_INC= lua.h lualib.h lauxlib.h luaconf.h lua.hpp luajit.h - FILES_JITLIB= bc.lua bcsave.lua dump.lua p.lua v.lua zone.lua \ -- dis_x86.lua dis_x64.lua dis_arm.lua dis_arm64.lua \ -+ dis_x86.lua dis_x64.lua dis_arm.lua dis_armv7m.lua dis_arm64.lua \ - dis_arm64be.lua dis_ppc.lua dis_mips.lua dis_mipsel.lua \ - dis_mips64.lua dis_mips64el.lua vmdef.lua - -diff --git a/dynasm/dasm_armv7m.h b/dynasm/dasm_armv7m.h -new file mode 100644 -index 00000000..8f94ba40 ---- /dev/null -+++ b/dynasm/dasm_armv7m.h -@@ -0,0 +1,563 @@ -+/* -+** SPDX-License-Identifier: MIT -+** SPDX-FileCopyrightText: 2018 Jernej Turnsek. All rights reserved. -+** SPDX-FileCopyrightText: 2005-2017 Mike Pall. All rights reserved. -+** Released under the MIT license. See dynasm.lua for full copyright notice. -+*/ -+ -+#include -+#include -+#include -+#include -+ -+#define DASM_ARCH "armv7m" -+ -+#ifndef DASM_EXTERN -+#define DASM_EXTERN(a,b,c,d) 0 -+#endif -+ -+/* Action definitions. */ -+enum { -+ DASM_STOP, -+ DASM_SECTION, -+ DASM_ESC, -+ DASM_REL_EXT, -+ /* The following actions need a buffer position. */ -+ DASM_ALIGN, -+ DASM_REL_LG, -+ DASM_LABEL_LG, -+ /* The following actions also have an argument. */ -+ DASM_REL_PC, -+ DASM_LABEL_PC, -+ DASM_IMM, -+ DASM_IMM12, -+ DASM_IMM16, -+ DASM_IMML8, -+ DASM_IMML12, -+ DASM_IMMV8, -+ DASM__MAX -+}; -+ -+/* Maximum number of section buffer positions for a single dasm_put() call. */ -+#define DASM_MAXSECPOS 25 -+ -+/* DynASM encoder status codes. Action list offset or number are or'ed in. */ -+#define DASM_S_OK 0x00000000 -+#define DASM_S_NOMEM 0x01000000 -+#define DASM_S_PHASE 0x02000000 -+#define DASM_S_MATCH_SEC 0x03000000 -+#define DASM_S_RANGE_I 0x11000000 -+#define DASM_S_RANGE_SEC 0x12000000 -+#define DASM_S_RANGE_LG 0x13000000 -+#define DASM_S_RANGE_PC 0x14000000 -+#define DASM_S_RANGE_REL 0x15000000 -+#define DASM_S_UNDEF_LG 0x21000000 -+#define DASM_S_UNDEF_PC 0x22000000 -+ -+/* Macros to convert positions (8 bit section + 24 bit index). */ -+#define DASM_POS2IDX(pos) ((pos)&0x00ffffff) -+#define DASM_POS2BIAS(pos) ((pos)&0xff000000) -+#define DASM_SEC2POS(sec) ((sec)<<24) -+#define DASM_POS2SEC(pos) ((pos)>>24) -+#define DASM_POS2PTR(D, pos) (D->sections[DASM_POS2SEC(pos)].rbuf + (pos)) -+ -+/* Action list type. */ -+typedef const unsigned int *dasm_ActList; -+ -+/* Per-section structure. */ -+typedef struct dasm_Section { -+ int *rbuf; /* Biased buffer pointer (negative section bias). */ -+ int *buf; /* True buffer pointer. */ -+ size_t bsize; /* Buffer size in bytes. */ -+ int pos; /* Biased buffer position. */ -+ int epos; /* End of biased buffer position - max single put. */ -+ int ofs; /* Byte offset into section. */ -+} dasm_Section; -+ -+/* Core structure holding the DynASM encoding state. */ -+struct dasm_State { -+ size_t psize; /* Allocated size of this structure. */ -+ dasm_ActList actionlist; /* Current actionlist pointer. */ -+ int *lglabels; /* Local/global chain/pos ptrs. */ -+ size_t lgsize; -+ int *pclabels; /* PC label chains/pos ptrs. */ -+ size_t pcsize; -+ void **globals; /* Array of globals (bias -10). */ -+ dasm_Section *section; /* Pointer to active section. */ -+ size_t codesize; /* Total size of all code sections. */ -+ int maxsection; /* 0 <= sectionidx < maxsection. */ -+ int status; /* Status code. */ -+ dasm_Section sections[1]; /* All sections. Alloc-extended. */ -+}; -+ -+/* The size of the core structure depends on the max. number of sections. */ -+#define DASM_PSZ(ms) (sizeof(dasm_State)+(ms-1)*sizeof(dasm_Section)) -+ -+ -+/* Initialize DynASM state. */ -+void dasm_init(Dst_DECL, int maxsection) -+{ -+ dasm_State *D; -+ size_t psz = 0; -+ int i; -+ Dst_REF = NULL; -+ DASM_M_GROW(Dst, struct dasm_State, Dst_REF, psz, DASM_PSZ(maxsection)); -+ D = Dst_REF; -+ D->psize = psz; -+ D->lglabels = NULL; -+ D->lgsize = 0; -+ D->pclabels = NULL; -+ D->pcsize = 0; -+ D->globals = NULL; -+ D->maxsection = maxsection; -+ for (i = 0; i < maxsection; i++) { -+ D->sections[i].buf = NULL; /* Need this for pass3. */ -+ D->sections[i].rbuf = D->sections[i].buf - DASM_SEC2POS(i); -+ D->sections[i].bsize = 0; -+ D->sections[i].epos = 0; /* Wrong, but is recalculated after resize. */ -+ } -+} -+ -+/* Free DynASM state. */ -+void dasm_free(Dst_DECL) -+{ -+ dasm_State *D = Dst_REF; -+ int i; -+ for (i = 0; i < D->maxsection; i++) -+ if (D->sections[i].buf) -+ DASM_M_FREE(Dst, D->sections[i].buf, D->sections[i].bsize); -+ if (D->pclabels) DASM_M_FREE(Dst, D->pclabels, D->pcsize); -+ if (D->lglabels) DASM_M_FREE(Dst, D->lglabels, D->lgsize); -+ DASM_M_FREE(Dst, D, D->psize); -+} -+ -+/* Setup global label array. Must be called before dasm_setup(). */ -+void dasm_setupglobal(Dst_DECL, void **gl, unsigned int maxgl) -+{ -+ dasm_State *D = Dst_REF; -+ D->globals = gl - 10; /* Negative bias to compensate for locals. */ -+ DASM_M_GROW(Dst, int, D->lglabels, D->lgsize, (10 + maxgl)*sizeof(int)); -+} -+ -+/* Grow PC label array. Can be called after dasm_setup(), too. */ -+void dasm_growpc(Dst_DECL, unsigned int maxpc) -+{ -+ dasm_State *D = Dst_REF; -+ size_t osz = D->pcsize; -+ DASM_M_GROW(Dst, int, D->pclabels, D->pcsize, maxpc*sizeof(int)); -+ memset((void *)(((unsigned char *)D->pclabels) + osz), 0, D->pcsize - osz); -+} -+ -+/* Setup encoder. */ -+void dasm_setup(Dst_DECL, const void *actionlist) -+{ -+ dasm_State *D = Dst_REF; -+ int i; -+ D->actionlist = (dasm_ActList)actionlist; -+ D->status = DASM_S_OK; -+ D->section = &D->sections[0]; -+ memset((void *)D->lglabels, 0, D->lgsize); -+ if (D->pclabels) memset((void *)D->pclabels, 0, D->pcsize); -+ for (i = 0; i < D->maxsection; i++) { -+ D->sections[i].pos = DASM_SEC2POS(i); -+ D->sections[i].ofs = 0; -+ } -+} -+ -+ -+#ifdef DASM_CHECKS -+#define CK(x, st) \ -+ do { if (!(x)) { \ -+ D->status = DASM_S_##st|(p-D->actionlist-1); return; } } while (0) -+#define CKPL(kind, st) \ -+ do { if ((size_t)((char *)pl-(char *)D->kind##labels) >= D->kind##size) { \ -+ D->status = DASM_S_RANGE_##st|(p-D->actionlist-1); return; } } while (0) -+#else -+#define CK(x, st) ((void)0) -+#define CKPL(kind, st) ((void)0) -+#endif -+ -+static int dasm_imm12(unsigned int n) -+{ -+ int i; -+ unsigned int m = n; -+ -+ if (m <= 255) { -+ /* i:imm3 = 0000 */ -+ return ((((m) & 0xff) << 16) | (((m) & 0x700) << 20) | (((m) & 0x800) >> 1)); -+ } -+ else if (!(m & 0xff00ff00) && !(((m >> 16 & 0xff) ^ m) & 0xff)) { -+ /* i:imm3 = 0001 */ -+ return ((((0x100 | (m & 0xff)) & 0xff) << 16) | (((0x100 | (m & 0xff)) & 0x700) << 20) | (((0x100 | (m & 0xff)) & 0x800) >> 1)); -+ } -+ else if (!(m & 0x00ff00ff) && !(((m >> 16 & 0xff00) ^ m) & 0xff00)) { -+ /* i:imm3 = 0010 */ -+ return ((((0x200 | (m >> 8 & 0xff)) & 0xff) << 16) | (((0x200 | (m >> 8 & 0xff)) & 0x700) << 20) | (((0x200 | (m >> 8 & 0xff)) & 0x800) >> 1)); -+ } -+ else if (!(((m >> 16 & 0xffff) ^ m) & 0xffff) && !(((m >> 8 & 0xff) ^ m) & 0xff)) { -+ /* i:imm3 = 0011 */ -+ return ((((0x300 | (m & 0xff)) & 0xff) << 16) | (((0x300 | (m & 0xff)) & 0x700) << 20) | (((0x300 | (m & 0xff)) & 0x800) >> 1)); -+ } -+ else { -+ for (i = 0; i < 4096; i += 128, m = ((m << 1) | (m >> (-(unsigned int)(1)&(8*sizeof(m) - 1))))) { -+ if (m <= 255) { -+ if ((m & 0x80) && (i >= 128 * 8)) -+ return ((((i | (m & 0x7f)) & 0xff) << 16) | (((i | (m & 0x7f)) & 0x700) << 20) | (((i | (m & 0x7f)) & 0x800) >> 1)); -+ else -+ continue; -+ } -+ } -+ } -+ if (n < 4096) { -+ return -2; /* Used for additional encoding of add/sub TODO: better solution! */ -+ } -+ return -1; -+} -+ -+/* Pass 1: Store actions and args, link branches/labels, estimate offsets. */ -+void dasm_put(Dst_DECL, int start, ...) -+{ -+ va_list ap; -+ dasm_State *D = Dst_REF; -+ dasm_ActList p = D->actionlist + start; -+ dasm_Section *sec = D->section; -+ int pos = sec->pos, ofs = sec->ofs; -+ int *b; -+ -+ if (pos >= sec->epos) { -+ DASM_M_GROW(Dst, -+ int, -+ sec->buf, -+ sec->bsize, -+ sec->bsize + 2*DASM_MAXSECPOS*sizeof(int)); -+ sec->rbuf = sec->buf - DASM_POS2BIAS(pos); -+ sec->epos = (int)sec->bsize / sizeof(int) - DASM_MAXSECPOS + DASM_POS2BIAS(pos); -+ } -+ -+ b = sec->rbuf; -+ b[pos++] = start; -+ -+ va_start(ap, start); -+ while (1) { -+ unsigned int ins = *p++; -+ unsigned int action = (ins >> 16); -+ if (action >= DASM__MAX) { -+ ofs += 4; -+ } -+ else { -+ int *pl, n = action >= DASM_REL_PC ? va_arg(ap, int) : 0; -+ switch (action) { -+ case DASM_STOP: goto stop; -+ case DASM_SECTION: -+ n = (ins & 255); CK(n < D->maxsection, RANGE_SEC); -+ D->section = &D->sections[n]; goto stop; -+ case DASM_ESC: p++; ofs += 4; break; -+ case DASM_REL_EXT: break; -+ case DASM_ALIGN: ofs += (ins & 255); b[pos++] = ofs; break; -+ case DASM_REL_LG: -+ n = (ins & 2047) - 10; pl = D->lglabels + n; -+ /* Bkwd rel or global. */ -+ if (n >= 0) { CK(n >= 10 || *pl < 0, RANGE_LG); CKPL(lg, LG); goto putrel; } -+ pl += 10; n = *pl; -+ if (n < 0) n = 0; /* Start new chain for fwd rel if label exists. */ -+ goto linkrel; -+ case DASM_REL_PC: -+ pl = D->pclabels + n; CKPL(pc, PC); -+putrel: -+ n = *pl; -+ if (n < 0) { -+ /* Label exists. Get label pos and store it. */ -+ b[pos] = -n; -+ } -+ else { -+linkrel: -+ b[pos] = n; /* Else link to rel chain, anchored at label. */ -+ *pl = pos; -+ } -+ pos++; -+ break; -+ case DASM_LABEL_LG: -+ pl = D->lglabels + (ins & 2047) - 10; CKPL(lg, LG); goto putlabel; -+ case DASM_LABEL_PC: -+ pl = D->pclabels + n; CKPL(pc, PC); -+putlabel: -+ n = *pl; /* n > 0: Collapse rel chain and replace with label pos. */ -+ while (n > 0) { int *pb = DASM_POS2PTR(D, n); n = *pb; *pb = pos; } -+ *pl = -pos; /* Label exists now. */ -+ b[pos++] = ofs; /* Store pass1 offset estimate. */ -+ break; -+ case DASM_IMM: -+ case DASM_IMM16: -+#ifdef DASM_CHECKS -+ CK((n & ((1 << ((ins >> 10) & 31)) - 1)) == 0, RANGE_I); -+ if ((ins & 0x8000)) -+ CK(((n + (1 << (((ins >> 5) & 31) - 1))) >> ((ins >> 5) & 31)) == 0, RANGE_I); -+ else -+ CK((n >> ((ins >> 5) & 31)) == 0, RANGE_I); -+#endif -+ b[pos++] = n; -+ break; -+ case DASM_IMMV8: -+ CK((n & 3) == 0, RANGE_I); -+ n >>= 2; -+ /* fallthrough */ -+ case DASM_IMML8: -+ case DASM_IMML12: -+ CK(n >= 0 ? ((n >> ((ins >> 5) & 31)) == 0) : -+ (((-n) >> ((ins >> 5) & 31)) == 0), -+ RANGE_I); -+ b[pos++] = n; -+ break; -+ case DASM_IMM12: -+ CK(dasm_imm12((unsigned int)n) != -1, RANGE_I); -+ b[pos++] = n; -+ break; -+ } -+ } -+ } -+stop: -+ va_end(ap); -+ sec->pos = pos; -+ sec->ofs = ofs; -+} -+#undef CK -+ -+/* Pass 2: Link sections, shrink aligns, fix label offsets. */ -+int dasm_link(Dst_DECL, size_t *szp) -+{ -+ dasm_State *D = Dst_REF; -+ int secnum; -+ int ofs = 0; -+ -+#ifdef DASM_CHECKS -+ *szp = 0; -+ if (D->status != DASM_S_OK) return D->status; -+ { -+ int pc; -+ for (pc = 0; pc*sizeof(int) < D->pcsize; pc++) -+ if (D->pclabels[pc] > 0) return DASM_S_UNDEF_PC | pc; -+ } -+#endif -+ -+ { -+ /* Handle globals not defined in this translation unit. */ -+ int idx; -+ for (idx = 20; idx*sizeof(int) < D->lgsize; idx++) { -+ int n = D->lglabels[idx]; -+ /* Undefined label: Collapse rel chain and replace with marker (< 0). */ -+ while (n > 0) { int *pb = DASM_POS2PTR(D, n); n = *pb; *pb = -idx; } -+ } -+ } -+ -+ /* Combine all code sections. No support for data sections (yet). */ -+ for (secnum = 0; secnum < D->maxsection; secnum++) { -+ dasm_Section *sec = D->sections + secnum; -+ int *b = sec->rbuf; -+ int pos = DASM_SEC2POS(secnum); -+ int lastpos = sec->pos; -+ -+ while (pos != lastpos) { -+ dasm_ActList p = D->actionlist + b[pos++]; -+ while (1) { -+ unsigned int ins = *p++; -+ unsigned int action = (ins >> 16); -+ switch (action) { -+ case DASM_STOP: case DASM_SECTION: goto stop; -+ case DASM_ESC: p++; break; -+ case DASM_REL_EXT: break; -+ case DASM_ALIGN: ofs -= (b[pos++] + ofs) & (ins & 255); break; -+ case DASM_REL_LG: case DASM_REL_PC: pos++; break; -+ case DASM_LABEL_LG: case DASM_LABEL_PC: b[pos++] += ofs; break; -+ case DASM_IMM: case DASM_IMM12: case DASM_IMM16: -+ case DASM_IMML8: case DASM_IMML12: case DASM_IMMV8: pos++; break; -+ } -+ } -+stop: (void)0; -+ } -+ ofs += sec->ofs; /* Next section starts right after current section. */ -+ } -+ -+ D->codesize = ofs; /* Total size of all code sections */ -+ *szp = ofs; -+ return DASM_S_OK; -+} -+ -+#ifdef DASM_CHECKS -+#define CK(x, st) \ -+ do { if (!(x)) return DASM_S_##st|(p-D->actionlist-1); } while (0) -+#else -+#define CK(x, st) ((void)0) -+#endif -+ -+/* Pass 3: Encode sections. */ -+int dasm_encode(Dst_DECL, void *buffer) -+{ -+ dasm_State *D = Dst_REF; -+ char *base = (char *)buffer; -+ unsigned int *cp = (unsigned int *)buffer; -+ int secnum; -+ -+ /* Encode all code sections. No support for data sections (yet). */ -+ for (secnum = 0; secnum < D->maxsection; secnum++) { -+ dasm_Section *sec = D->sections + secnum; -+ int *b = sec->buf; -+ int *endb = sec->rbuf + sec->pos; -+ -+ while (b != endb) { -+ dasm_ActList p = D->actionlist + *b++; -+ while (1) { -+ unsigned int ins = *p++; -+ unsigned int action = (ins >> 16); -+ int n = (action >= DASM_ALIGN && action < DASM__MAX) ? *b++ : 0; -+ switch (action) { -+ case DASM_STOP: -+ case DASM_SECTION: -+ goto stop; -+ case DASM_ESC: -+ //*cp++ = *p++; //jturnsek: do I need to swap this also? -+ *cp++ = ((*p >> 16) & 0x0000ffff) | ((*p << 16) & 0xffff0000); /* jturnsek: swap of half-words!!! */ -+ p++; -+ break; -+ case DASM_REL_EXT: -+ n = DASM_EXTERN(Dst, (unsigned char *)cp, (ins & 2047), !(ins & 2048)); -+ goto patchrel; -+ case DASM_ALIGN: -+ ins &= 255; while ((((char *)cp - base) & ins)) *cp++ = 0x8000f3af; /* jturnsek: NOP.W */ -+ break; -+ case DASM_REL_LG: -+ CK(n >= 0, UNDEF_LG); -+ /* fallthrough */ -+ case DASM_REL_PC: -+ CK(n >= 0, UNDEF_PC); -+ n = *DASM_POS2PTR(D, n) - (int)((char *)cp - base); -+patchrel: -+ if ((ins & 0x800) == 0) { -+ /* jturnsek: B or BL */ -+ if (cp[-1] & 0x10000000) { -+ /* BL */ -+ CK((n & 1) == 0 && ((n + 0x01000000) >> 25) == 0, RANGE_REL); -+ cp[-1] |= ((((n & 0x1000000) >> 24) & 0x1) << 10) | -+ (((~((n & 0x800000) >> 23) & 0x1) ^ (((n & 0x1000000) >> 24) & 0x1)) << 29) | -+ (((~((n & 0x400000) >> 22) & 0x1) ^ (((n & 0x1000000) >> 24) & 0x1)) << 27) | -+ ((n >> 12) & 0x3ff) | -+ (((n >> 1) & 0x7ff) << 16); -+ } -+ else { -+ /* B (T3) */ -+ CK((n & 1) == 0 && ((n + 0x00100000) >> 21) == 0, RANGE_REL); -+ cp[-1] |= ((((n & 0x100000) >> 20) & 0x1) << 10) | -+ ((((n & 0x80000) >> 19) & 0x1) << 27) | -+ ((((n & 0x40000) >> 18) & 0x1) << 29) | -+ ((n >> 12) & 0x3f) | -+ (((n >> 1) & 0x7ff) << 16); -+ } -+ } -+ else if ((ins & 0x1000)) { -+ CK((n & 3) == 0 && -256 <= n && n <= 256, RANGE_REL); -+ goto patchimml8; -+ } -+ else if ((ins & 0x2000) == 0) { -+ CK((n & 3) == 0 && -4096 <= n && n <= 4096, RANGE_REL); -+ goto patchimml; -+ } -+ else { -+ CK((n & 3) == 0 && -1020 <= n && n <= 1020, RANGE_REL); -+ n >>= 2; -+ goto patchimmv; -+ } -+ break; -+ case DASM_LABEL_LG: -+ ins &= 2047; if (ins >= 20) D->globals[ins - 10] = (void *)(base + n); -+ break; -+ case DASM_LABEL_PC: -+ break; -+ case DASM_IMM: -+ if (((ins >> 5) & 31) == 2) { -+ /* 2 bit shift for load/store lsl */ -+ cp[-1] |= ((n & 0x3) << 20); -+ } -+ else { -+ /* 5 bit shift */ -+ cp[-1] |= ((n & 0x3) << 22) | ((n & 0x1c) << 26); -+ } -+ //cp[-1] |= ((n >> ((ins >> 10) & 31)) & ((1 << ((ins >> 5) & 31)) - 1)) << (ins & 31); -+ break; -+ case DASM_IMM12: -+ if (dasm_imm12((unsigned int)n) == -2) { -+ cp[-1] ^= 0x00000300; -+ cp[-1] &= ~0x00000010; -+ cp[-1] |= ((((n) & 0xff) << 16) | (((n) & 0x700) << 20) | (((n) & 0x800) >> 1)); -+ } -+ else { -+ cp[-1] |= dasm_imm12((unsigned int)n); -+ } -+ break; -+ case DASM_IMM16: -+ cp[-1] |= ((n & 0xf000) >> 12) | -+ ((n & 0x0800) >> 1) | -+ ((n & 0x0700) << 20) | -+ ((n & 0x00ff) << 16); -+ break; -+ case DASM_IMML8: -+patchimml8: -+ cp[-1] |= n >= 0 ? (0x02000000 | ((n & 0xff) << 16)) : ((-n & 0xff) << 16); -+ break; -+ case DASM_IMML12: -+patchimml: -+ cp[-1] |= n >= 0 ? (0x00000080 | ((n & 0xfff) << 16)) : ((-n & 0xfff) << 16); -+ if (((cp[-1] & 0x0000000f) != 0x0000000f) && (n < 0)) { -+ CK(-255 <= n && n < 0, RANGE_I); -+ cp[-1] &= ~0x03000000; -+ cp[-1] |= 0x0c000000; -+ } -+ break; -+ case DASM_IMMV8: -+patchimmv: -+ cp[-1] |= n >= 0 ? (0x00000080 | ((n & 0xff) << 16)) : ((-n & 0xff) << 16); -+ break; -+ default: -+ *cp++ = ((ins >> 16) & 0x0000ffff) | ((ins << 16) & 0xffff0000); /* jturnsek: swap of half-words!!! */ -+ break; -+ } -+ } -+stop: (void)0; -+ } -+ } -+ -+ if (base + D->codesize != (char *)cp) /* Check for phase errors. */ -+ return DASM_S_PHASE; -+ return DASM_S_OK; -+} -+#undef CK -+ -+/* Get PC label offset. */ -+int dasm_getpclabel(Dst_DECL, unsigned int pc) -+{ -+ dasm_State *D = Dst_REF; -+ if (pc*sizeof(int) < D->pcsize) { -+ int pos = D->pclabels[pc]; -+ if (pos < 0) return *DASM_POS2PTR(D, -pos); -+ if (pos > 0) return -1; /* Undefined. */ -+ } -+ return -2; /* Unused or out of range. */ -+} -+ -+#ifdef DASM_CHECKS -+/* Optional sanity checker to call between isolated encoding steps. */ -+int dasm_checkstep(Dst_DECL, int secmatch) -+{ -+ dasm_State *D = Dst_REF; -+ if (D->status == DASM_S_OK) { -+ int i; -+ for (i = 1; i <= 9; i++) { -+ if (D->lglabels[i] > 0) { D->status = DASM_S_UNDEF_LG | i; break; } -+ D->lglabels[i] = 0; -+ } -+ } -+ if (D->status == DASM_S_OK && secmatch >= 0 && -+ D->section != &D->sections[secmatch]) -+ D->status = DASM_S_MATCH_SEC | (D->section - D->sections); -+ return D->status; -+} -+#endif -+ -diff --git a/dynasm/dasm_armv7m.lua b/dynasm/dasm_armv7m.lua -new file mode 100644 -index 00000000..8e877d26 ---- /dev/null -+++ b/dynasm/dasm_armv7m.lua -@@ -0,0 +1,1010 @@ -+------------------------------------------------------------------------------ -+-- DynASM ARMV7M module. -+-- -+-- Copyright (C) 2018 Jernej Turnsek. All rights reserved. -+-- Copyright (C) 2005-2017 Mike Pall. All rights reserved. -+-- See dynasm.lua for full copyright notice. -+------------------------------------------------------------------------------ -+ -+-- Module information: -+local _info = { -+ arch = "armv7m", -+ description = "DynASM ARMV7M module", -+ version = "1.4.0", -+ vernum = 10400, -+ release = "2018-12-07", -+ author = "Jernej Turnsek", -+ license = "MIT", -+} -+ -+-- Exported glue functions for the arch-specific module. -+local _M = { _info = _info } -+ -+-- Cache library functions. -+local type, tonumber, pairs, ipairs = type, tonumber, pairs, ipairs -+local assert, setmetatable, rawget = assert, setmetatable, rawget -+local _s = string -+local sub, format, byte, char = _s.sub, _s.format, _s.byte, _s.char -+local match, gmatch, gsub = _s.match, _s.gmatch, _s.gsub -+local concat, sort, insert = table.concat, table.sort, table.insert -+local bit = bit or require("bit") -+local band, shl, shr, sar = bit.band, bit.lshift, bit.rshift, bit.arshift -+local ror, tohex = bit.ror, bit.tohex -+local bxor = bit.bxor -+ -+-- Inherited tables and callbacks. -+local g_opt, g_arch -+local wline, werror, wfatal, wwarn -+ -+-- Action name list. -+-- CHECK: Keep this in sync with the C code! -+local action_names = { -+ "STOP", "SECTION", "ESC", "REL_EXT", -+ "ALIGN", "REL_LG", "LABEL_LG", -+ "REL_PC", "LABEL_PC", "IMM", "IMM12", "IMM16", "IMML8", "IMML12", "IMMV8", -+} -+ -+-- Maximum number of section buffer positions for dasm_put(). -+-- CHECK: Keep this in sync with the C code! -+local maxsecpos = 25 -- Keep this low, to avoid excessively long C lines. -+ -+-- Action name -> action number. -+local map_action = {} -+for n,name in ipairs(action_names) do -+ map_action[name] = n-1 -+end -+ -+-- Action list buffer. -+local actlist = {} -+ -+-- Argument list for next dasm_put(). Start with offset 0 into action list. -+local actargs = { 0 } -+ -+-- Current number of section buffer positions for dasm_put(). -+local secpos = 1 -+ -+------------------------------------------------------------------------------ -+ -+-- Dump action names and numbers. -+local function dumpactions(out) -+ out:write("DynASM encoding engine action codes:\n") -+ for n,name in ipairs(action_names) do -+ local num = map_action[name] -+ out:write(format(" %-10s %02X %d\n", name, num, num)) -+ end -+ out:write("\n") -+end -+ -+-- Write action list buffer as a huge static C array. -+local function writeactions(out, name) -+ local nn = #actlist -+ if nn == 0 then nn = 1; actlist[0] = map_action.STOP end -+ out:write("static const unsigned int ", name, "[", nn, "] = {\n") -+ for i = 1,nn-1 do -+ assert(out:write("0x", tohex(actlist[i]), ",\n")) -+ end -+ assert(out:write("0x", tohex(actlist[nn]), "\n};\n\n")) -+end -+ -+------------------------------------------------------------------------------ -+ -+-- Add word to action list. -+local function wputxw(n) -+ assert(n >= 0 and n <= 0xffffffff and n % 1 == 0, "word out of range") -+ actlist[#actlist+1] = n -+end -+ -+-- Add action to list with optional arg. Advance buffer pos, too. -+local function waction(action, val, a, num) -+ local w = assert(map_action[action], "bad action name `"..action.."'") -+ wputxw(w * 0x10000 + (val or 0)) -+ if a then actargs[#actargs+1] = a end -+ if a or num then secpos = secpos + (num or 1) end -+end -+ -+-- Flush action list (intervening C code or buffer pos overflow). -+local function wflush(term) -+ if #actlist == actargs[1] then return end -- Nothing to flush. -+ if not term then waction("STOP") end -- Terminate action list. -+ wline(format("dasm_put(Dst, %s);", concat(actargs, ", ")), true) -+ actargs = { #actlist } -- Actionlist offset is 1st arg to next dasm_put(). -+ secpos = 1 -- The actionlist offset occupies a buffer position, too. -+end -+ -+-- Put escaped word. -+local function wputw(n) -+ if n <= 0x000fffff then waction("ESC") end -+ wputxw(n) -+end -+ -+-- Reserve position for word. -+local function wpos() -+ local pos = #actlist+1 -+ actlist[pos] = "" -+ return pos -+end -+ -+-- Store word to reserved position. -+local function wputpos(pos, n) -+ assert(n >= 0 and n <= 0xffffffff and n % 1 == 0, "word out of range") -+ if n <= 0x000fffff then -+ insert(actlist, pos+1, n) -+ n = map_action.ESC * 0x10000 -+ end -+ actlist[pos] = n -+end -+ -+------------------------------------------------------------------------------ -+ -+-- Global label name -> global label number. With auto assignment on 1st use. -+local next_global = 20 -+local map_global = setmetatable({}, { __index = function(t, name) -+ if not match(name, "^[%a_][%w_]*$") then werror("bad global label") end -+ local n = next_global -+ if n > 2047 then werror("too many global labels") end -+ next_global = n + 1 -+ t[name] = n -+ return n -+end}) -+ -+-- Dump global labels. -+local function dumpglobals(out, lvl) -+ local t = {} -+ for name, n in pairs(map_global) do t[n] = name end -+ out:write("Global labels:\n") -+ for i=20,next_global-1 do -+ out:write(format(" %s\n", t[i])) -+ end -+ out:write("\n") -+end -+ -+-- Write global label enum. -+local function writeglobals(out, prefix) -+ local t = {} -+ for name, n in pairs(map_global) do t[n] = name end -+ out:write("enum {\n") -+ for i=20,next_global-1 do -+ out:write(" ", prefix, t[i], ",\n") -+ end -+ out:write(" ", prefix, "_MAX\n};\n") -+end -+ -+-- Write global label names. -+local function writeglobalnames(out, name) -+ local t = {} -+ for name, n in pairs(map_global) do t[n] = name end -+ out:write("static const char *const ", name, "[] = {\n") -+ for i=20,next_global-1 do -+ out:write(" \"", t[i], "\",\n") -+ end -+ out:write(" (const char *)0\n};\n") -+end -+ -+------------------------------------------------------------------------------ -+ -+-- Extern label name -> extern label number. With auto assignment on 1st use. -+local next_extern = 0 -+local map_extern_ = {} -+local map_extern = setmetatable({}, { __index = function(t, name) -+ -- No restrictions on the name for now. -+ local n = next_extern -+ if n > 2047 then werror("too many extern labels") end -+ next_extern = n + 1 -+ t[name] = n -+ map_extern_[n] = name -+ return n -+end}) -+ -+-- Dump extern labels. -+local function dumpexterns(out, lvl) -+ out:write("Extern labels:\n") -+ for i=0,next_extern-1 do -+ out:write(format(" %s\n", map_extern_[i])) -+ end -+ out:write("\n") -+end -+ -+-- Write extern label names. -+local function writeexternnames(out, name) -+ out:write("static const char *const ", name, "[] = {\n") -+ for i=0,next_extern-1 do -+ out:write(" \"", map_extern_[i], "\",\n") -+ end -+ out:write(" (const char *)0\n};\n") -+end -+ -+------------------------------------------------------------------------------ -+ -+-- Arch-specific maps. -+ -+-- Ext. register name -> int. name. -+local map_archdef = { sp = "r13", lr = "r14", pc = "r15", } -+ -+-- Int. register name -> ext. name. -+local map_reg_rev = { r13 = "sp", r14 = "lr", r15 = "pc", } -+ -+local map_type = {} -- Type name -> { ctype, reg } -+local ctypenum = 0 -- Type number (for Dt... macros). -+ -+-- Reverse defines for registers. -+function _M.revdef(s) -+ return map_reg_rev[s] or s -+end -+ -+local map_shift = { lsl = 0, lsr = 1, asr = 2, ror = 3, } -+ -+local map_cond = { -+ eq = 0, ne = 1, cs = 2, cc = 3, mi = 4, pl = 5, vs = 6, vc = 7, -+ hi = 8, ls = 9, ge = 10, lt = 11, gt = 12, le = 13, al = 14, -+ hs = 2, lo = 3, -+} -+ -+------------------------------------------------------------------------------ -+ -+-- Template strings for ARM instructions. -+-- jturnsek: dasm_encode will do the swap of half-words!!! -+local map_op = { -+ and_3 = "ea000000DNPs", -+ eor_3 = "ea800000DNPs", -+ sub_3 = "eba00000DNPs", -+ rsb_3 = "ebc00000DNPs", -+ add_3 = "eb000000DNPs", -+ sbc_3 = "eb600000DNPs", -+ tst_2 = "ea100f00NP", -+ cmp_2 = "ebb00f00NP", -+ cmn_2 = "eb100f00NP", -+ orr_3 = "ea400000DNPs", -+ mov_2 = "ea4f0000DPs", -+ bic_3 = "ea200000DNPs", -+ mvn_2 = "ea6f0000DPs", -+ -+ and_4 = "ea000000DNMps", -+ eor_4 = "ea800000DNMps", -+ sub_4 = "eba00000DNMps", -+ rsb_4 = "ebc00000DNMps", -+ add_4 = "eb000000DNMps", -+ sbc_4 = "eb600000DNMps", -+ tst_3 = "ea100f00NMp", -+ cmp_3 = "ebb00f00NMp", -+ cmn_3 = "eb100f00NMp", -+ orr_4 = "ea400000DNMps", -+ mov_3 = "ea4f0000DMps", -+ bic_4 = "ea200000DNMps", -+ mvn_3 = "ea6f0000DMps", -+ -+ lsl_3 = "ea400000DNws", -+ lsr_3 = "ea400010DNws", -+ asr_3 = "ea400020DNws", -+ ror_3 = "ea400030DNws", -+ -+ smull_4 = "fb800000SDNM", -+ -+ clz_2 = "fab0f080Da", -- a is used for Consistent(M) -+ rbit_2 = "fa90f0a0Da", -- a is used for Consistent(M) -+ -+ str_2 = "f8400000SL", str_3 = "f8400000SL", str_4 = "f8400000SL", -+ strb_2 = "f8000000SL", strb_3 = "f8000000SL", strb_4 = "f8000000SL", -+ ldr_2 = "f8500000SL", ldr_3 = "f8500000SL", ldr_4 = "f8500000SL", -+ ldrb_2 = "f8100000SL", ldrb_3 = "f8100000SL", ldrb_4 = "f8100000SL", -+ strh_2 = "f8200000SL", strh_3 = "f8200000SL", -+ ldrh_2 = "f8300000SL", ldrh_3 = "f8300000SL", -+ ldrd_3 = "e8500000SDL", ldrd_4 = "e8500000SDL", -+ strd_3 = "e8400000SDL", strd_4 = "e8400000SDL", -+ -+ ldm_2 = "e8900000oR", -+ pop_1 = "e8bd0000R", -+ push_1 = "e92d0000R", -+ -+ b_1 = "f0009000B", -+ bl_1 = "f000d000B", -+ bx_1 = "bf004700C", -+ blx_1 = "bf004780C", -+ -+ nop_0 = "f3af8000", -+ bkpt_1 = "bf00be00K", -+ -+ ["vadd.f64_3"] = "ee300b00Gdnm", -+ ["vsub.f64_3"] = "ee300b40Gdnm", -+ ["vmul.f64_3"] = "ee200b00Gdnm", -+ ["vdiv.f64_3"] = "ee800b00Gdnm", -+ ["vcmp.f64_2"] = "eeb40b40Gdm", -+ ["vcvt.f64.s32_2"] = "eeb80bc0GdFm", -+ ["vsqrt.f64_2"] = "eeb10bc0Gdm", -+ -+ vldr_2 = "ed100a00dl|ed100b00Gdl", -+ vstr_2 = "ed000a00dl|ed000b00Gdl", -+ vldm_2 = "ec900a00or", -+ vpop_1 = "ecbd0a00r", -+ vstmdb_2 = "ed000a00or", -+ vpush_1 = "ed2d0a00r", -+ -+ ["vmov.f64_2"] = "eeb00b40Gdm|eeb00b00GdY", -+ vmov_2 = "ee100a10Sn|ee000a10nS", -+ vmov_3 = "ec500a10SNm|ec400a10mSN|ec500b10GSNm|ec400b10GmSN", -+ vmrs_0 = "eef1fa10", -+ -+ it_1 = "bf00bf08c", -+ ite_1 = "bf00bf04c", -+ itt_1 = "bf00bf04c", -+ ittt_1 = "bf00bf02c", -+ itttt_1 = "bf00bf01c", -+ iteee_1 = "bf00bf01c", -+} -+ -+-- Add mnemonics for "s" variants. -+do -+ local t = {} -+ for k,v in pairs(map_op) do -+ if sub(v, -1) == "s" then -+ local v2 = sub(v, 1, 2)..char(byte(v, 3)+1)..sub(v, 4, -2) -+ t[sub(k, 1, -3).."s"..sub(k, -2)] = v2 -+ end -+ end -+ for k,v in pairs(t) do -+ map_op[k] = v -+ end -+end -+ -+------------------------------------------------------------------------------ -+ -+local function parse_gpr(expr) -+ local tname, ovreg = match(expr, "^([%w_]+):(r1?[0-9])$") -+ local tp = map_type[tname or expr] -+ if tp then -+ local reg = ovreg or tp.reg -+ if not reg then -+ werror("type `"..(tname or expr).."' needs a register override") -+ end -+ expr = reg -+ end -+ local r = match(expr, "^r(1?[0-9])$") -+ if r then -+ r = tonumber(r) -+ if r <= 15 then return r, tp end -+ end -+ werror("bad register name `"..expr.."'") -+end -+ -+local function parse_gpr_pm(expr) -+ local pm, expr2 = match(expr, "^([+-]?)(.*)$") -+ return parse_gpr(expr2), (pm == "-") -+end -+ -+local function parse_vr(expr, tp) -+ local t, r = match(expr, "^([sd])([0-9]+)$") -+ if t == tp then -+ r = tonumber(r) -+ if r <= 31 then -+ if t == "s" then return shr(r, 1), band(r, 1) end -+ return band(r, 15), shr(r, 4) -+ end -+ end -+ werror("bad register name `"..expr.."'") -+end -+ -+local function parse_reglist(reglist) -+ reglist = match(reglist, "^{%s*([^}]*)}$") -+ if not reglist then werror("register list expected") end -+ local rr = 0 -+ for p in gmatch(reglist..",", "%s*([^,]*),") do -+ local rbit = shl(1, parse_gpr(gsub(p, "%s+$", ""))) -+ if band(rr, rbit) ~= 0 then -+ werror("duplicate register `"..p.."'") -+ end -+ rr = rr + rbit -+ end -+ return rr -+end -+ -+local function parse_vrlist(reglist) -+ local ta, ra, tb, rb = match(reglist, -+ "^{%s*([sd])([0-9]+)%s*%-%s*([sd])([0-9]+)%s*}$") -+ ra, rb = tonumber(ra), tonumber(rb) -+ if ta and ta == tb and ra and rb and ra <= 31 and rb <= 31 and ra <= rb then -+ local nr = rb + 1 - ra -+ if ta == "s" then -+ return shl(shr(ra, 1), 12) + shl(band(ra, 1), 22) + nr -+ else -+ return shl(band(ra, 15), 12) + shl(shr(ra, 4), 22) + nr * 2 + 0x100 -+ end -+ end -+ werror("register list expected") -+end -+ -+local function parse_imm(imm, bits, shift, scale, signed) -+ imm = match(imm, "^#(.*)$") -+ if not imm then werror("expected immediate operand") end -+ local n = tonumber(imm) -+ if n then -+ local m = sar(n, scale) -+ if shl(m, scale) == n then -+ if signed then -+ local s = sar(m, bits-1) -+ if s == 0 then return shl(m, shift) -+ elseif s == -1 then return shl(m + shl(1, bits), shift) end -+ else -+ if sar(m, bits) == 0 then return shl(m, shift) end -+ end -+ end -+ werror("out of range immediate `"..imm.."'") -+ else -+ waction("IMM", (signed and 32768 or 0)+scale*1024+bits*32+shift, imm) -+ return 0 -+ end -+end -+ -+local function parse_imm12(imm) -+ local n = tonumber(imm) -+ if n then -+ if n <= 255 then -+ return band(n, 0xff) -+ elseif band(n, 0xff00ff00) == 0 and band(shr(n, 16), 0xff) == band(n, 0xff) then -+ return band(n, 0xff) + shl(1, 12) -+ elseif band(n, 0x00ff00ff) == 0 and band(shr(n, 16), 0xff00) == band(n, 0xff00) then -+ return band(shr(n, 8), 0xff) + shl(2, 12) -+ elseif band(shr(n, 24), 0xff) == band(n, 0xff) and -+ band(shr(n, 16), 0xff) == band(n, 0xff) and -+ band(shr(n, 8), 0xff) == band(n, 0xff) then -+ return band(n, 0xff) + shl(3, 12) -+ else -+ for i=31, 8, -1 do -+ n = ror(n, 1) -+ if n >= 128 and n <= 255 then -+ return shl(band(i, 0x10), 22) + shl(band(i, 0x0e), 11) + shl(band(i, 0x01), 7) + band(n, 0x7f) -+ end -+ end -+ end -+ werror("out of range immediate `"..imm.."'") -+ else -+ waction("IMM12", 0, imm) -+ return 0 -+ end -+end -+ -+local function parse_imm16(imm) -+ imm = match(imm, "^#(.*)$") -+ if not imm then werror("expected immediate operand") end -+ local n = tonumber(imm) -+ if n then -+ if shr(n, 16) == 0 then -+ return band(n, 0x00ff) + shl(band(n, 0x0700), 4) + shl(band(n, 0x0800), 15) + shl(band(n, 0xf000), 4) -+ end -+ werror("out of range immediate `"..imm.."'") -+ else -+ waction("IMM16", 32*16, imm) -+ return 0 -+ end -+end -+ -+local function parse_imm_load(imm, ext, flags) -+ local n = tonumber(imm) -+ local p, w = match(flags, "P"), match(flags, "W") -+ if n then -+ if ext then -+ if n >= -1020 and n <= 1020 then -+ local up = 0x00800000 -+ if n < 0 then n = -n; up = 0 end -+ return n/4 + up + (p and 0x01000000 or 0) + (w and 0x00200000 or 0) -+ end -+ else -+ if w then -+ if n >= -255 and n <= 255 then -+ if n >= 0 then -+ return n + 0x00000a00 + (p and 0x00000400 or 0) + (w and 0x00000100 or 0) -+ else -+ return -n + 0x00000800 + (p and 0x00000400 or 0) + (w and 0x00000100 or 0) -+ end -+ end -+ else -+ if n >= 0 and n <= 4095 then -+ return n + 0x00800000 -+ elseif n >= -255 and n < 0 then -+ return -n + 0x00000800 + (p and 0x00000400 or 0) -+ end -+ end -+ end -+ werror("out of range immediate `"..imm.."'") -+ else -+ waction(ext and "IMMV8" or "IMML12", 32768 + (ext and 32*8 or 32*12), imm) -+ local pw = 0 -+ if p then pw = (ext and 0x01000000 or 0) end -+ if w then pw = (ext and 0x00200000 or 0) end -+ return pw -+ end -+end -+ -+local function parse_shift(shift) -+ if shift == "rrx" then -+ return 3 * 16 -+ else -+ local s, s2 = match(shift, "^(%S+)%s*(.*)$") -+ s = map_shift[s] -+ if not s then werror("expected shift operand") end -+ if sub(s2, 1, 1) == "#" then -+ local imm = parse_imm(s2, 5, 0, 0, false) -+ return shl(band(imm, 0x1c), 10) + shl(band(imm, 0x03), 6) + shl(s, 4) -+ else -+ werror("expected immediate shift operand") -+ end -+ end -+end -+ -+local function parse_shift_load(shift) -+ if not match(shift, "lsl", 1) then -+ werror("expected lsl shift operand") -+ else -+ local s, s2 = match(shift, "^(%S+)%s*(.*)$") -+ if not s then werror("expected shift operand") end -+ if sub(s2, 1, 1) == "#" then -+ return parse_imm(s2, 2, 4, 0, false) -+ else -+ werror("expected immediate shift operand") -+ end -+ end -+end -+ -+local function parse_label(label, def) -+ local prefix = sub(label, 1, 2) -+ -- =>label (pc label reference) -+ if prefix == "=>" then -+ return "PC", 0, sub(label, 3) -+ end -+ -- ->name (global label reference) -+ if prefix == "->" then -+ return "LG", map_global[sub(label, 3)] -+ end -+ if def then -+ -- [1-9] (local label definition) -+ if match(label, "^[1-9]$") then -+ return "LG", 10+tonumber(label) -+ end -+ else -+ -- [<>][1-9] (local label reference) -+ local dir, lnum = match(label, "^([<>])([1-9])$") -+ if dir then -- Fwd: 1-9, Bkwd: 11-19. -+ return "LG", lnum + (dir == ">" and 0 or 10) -+ end -+ -- extern label (extern label reference) -+ local extname = match(label, "^extern%s+(%S+)$") -+ if extname then -+ return "EXT", map_extern[extname] -+ end -+ end -+ werror("bad label `"..label.."'") -+end -+ -+local function parse_load(params, nparams, n, op) -+ local ext = (band(op, 0x10000000) == 0) -+ local pn = params[n] -+ local p1, wb = match(pn, "^%[%s*(.-)%s*%](!?)$") -+ local p2 = params[n+1] -+ if not p1 then -+ if not p2 then -+ if match(pn, "^[<>=%-]") or match(pn, "^extern%s+") then -+ local mode, n, s = parse_label(pn, false) -+ waction("REL_"..mode, n + (ext and 0x2800 or 0x0800), s, 1) -+ return op + 15 * 65536 + (ext and 0x01000000 or 0) --set P if ext==true -+ end -+ local reg, tailr = match(pn, "^([%w_:]+)%s*(.*)$") -+ if reg and tailr ~= "" then -+ local d, tp = parse_gpr(reg) -+ if tp then -+ waction(ext and "IMMV8" or "IMML12", 32768 + (ext and 32*8 or 32*12), -+ format(tp.ctypefmt, tailr)) -+ return op + shl(d, 16) + (ext and 0x01000000 or 0) --set P if ext==true, using imm12 if ext==false -+ end -+ end -+ end -+ werror("expected address operand") -+ end -+ if p2 then -+ if wb == "!" then werror("bad use of '!'") end -+ local p3 = params[n+2] -+ op = op + shl(parse_gpr(p1), 16) -+ local imm = match(p2, "^#(.*)$") -+ if imm then -+ if p3 then werror("too many parameters") end -+ op = op + parse_imm_load(imm, ext, "W") --always imm8, set W -+ else -+ if ext then werror("not in ARMV7M") end -+ op = op + parse_gpr(p2) -+ if p3 then op = op + parse_shift_load(p3) end -+ end -+ else -+ local p1a, p2 = match(p1, "^([^,%s]*)%s*(.*)$") -+ op = op + shl(parse_gpr(p1a), 16) -+ if p2 ~= "" then -+ local imm = match(p2, "^,%s*#(.*)$") -+ if imm then -+ op = op + parse_imm_load(imm, ext, (wb == "!" and "PW" or "P")) --set P (and W) -+ else -+ local p2a, p3 = match(p2, "^,%s*([^,%s]*)%s*,?%s*(.*)$") -+ if ext then werror("not in ARMV7M") end -+ op = op + parse_gpr(p2a) -+ if p3 ~= "" then -+ op = op + parse_shift_load(p3) -+ end -+ end -+ else -+ if wb == "!" then werror("bad use of '!'") end -+ op = op + (ext and 0x01000000 or 0) + 0x00800000 --no imm, thus using imm12 if ext==false, set U -+ end -+ end -+ return op -+end -+ -+local function parse_vload(q) -+ local reg, imm = match(q, "^%[%s*([^,%s]*)%s*(.*)%]$") -+ if reg then -+ local d = shl(parse_gpr(reg), 16) -+ if imm == "" then return d end -+ imm = match(imm, "^,%s*#(.*)$") -+ if imm then -+ local n = tonumber(imm) -+ if n then -+ if n >= -1020 and n <= 1020 and n%4 == 0 then -+ return d + (n >= 0 and n/4+0x00800000 or -n/4) -+ end -+ werror("out of range immediate `"..imm.."'") -+ else -+ waction("IMMV8", 32768 + 32*8, imm) -+ return d -+ end -+ end -+ else -+ if match(q, "^[<>=%-]") or match(q, "^extern%s+") then -+ local mode, n, s = parse_label(q, false) -+ waction("REL_"..mode, n + 0x2800, s, 1) -+ return 15 * 65536 -+ end -+ local reg, tailr = match(q, "^([%w_:]+)%s*(.*)$") -+ if reg and tailr ~= "" then -+ local d, tp = parse_gpr(reg) -+ if tp then -+ waction("IMMV8", 32768 + 32*8, format(tp.ctypefmt, tailr)) -+ return shl(d, 16) -+ end -+ end -+ end -+ werror("expected address operand") -+end -+ -+local function parse_it(name, cond) -+ local mask, it = 0, match(name, "it", 1) -+ if not it then -+ werror("not IT instruction") -+ end -+ local it2 = sub(name, 3, -1) -+ if not it2 then -+ return shl(map_cond[cond], 4) -+ end -+ local shift = 3 -+ for p in gmatch(it2, "[te]") do -+ if p == "t" then -+ mask = mask + shl(band(map_cond[cond], 1), shift) -+ elseif p == "e" then -+ mask = mask + shl(band(bxor(map_cond[cond], 15), 1), shift) -+ else -+ werror("wrong syntax") -+ end -+ if shift ~= 0 then shift = shift - 1 end -+ end -+ return shl(map_cond[cond], 4) + mask -+end -+ -+ -+------------------------------------------------------------------------------ -+ -+-- Handle opcodes defined with template strings. -+local function parse_template(params, template, nparams, pos) -+ local op = tonumber(sub(template, 1, 8), 16) -+ local n = 1 -+ local vr = "s" -+ -+ -- Process each character. -+ for p in gmatch(sub(template, 9), ".") do -+ local q = params[n] -+ if p == "D" then -+ op = op + shl(parse_gpr(q), 8); n = n + 1 -+ elseif p == "N" then -+ op = op + shl(parse_gpr(q), 16); n = n + 1 -+ elseif p == "S" then -+ op = op + shl(parse_gpr(q), 12); n = n + 1 -+ elseif p == "M" then -+ op = op + parse_gpr(q); n = n + 1 -+ elseif p == "a" then -+ local m = parse_gpr(q) -+ op = op + m + shl(m, 16); n = n + 1 -+ elseif p == "d" then -+ local r,h = parse_vr(q, vr); op = op + shl(r, 12) + shl(h, 22); n = n + 1 -+ elseif p == "n" then -+ local r,h = parse_vr(q, vr); op = op + shl(r, 16) + shl(h, 7); n = n + 1 -+ elseif p == "m" then -+ local r,h = parse_vr(q, vr); op = op + r + shl(h, 5); n = n + 1 -+ elseif p == "P" then -+ local imm = match(q, "^#(.*)$") -+ if imm then -+ op = op + 0x6000000 + parse_imm12(imm) -+ else -+ op = op + parse_gpr(q) -+ end -+ n = n + 1 -+ elseif p == "p" then -+ op = op + parse_shift(q); n = n + 1 -+ elseif p == "L" then -+ op = parse_load(params, nparams, n, op) -+ elseif p == "l" then -+ op = op + parse_vload(q) -+ elseif p == "B" then -+ local mode, n, s = parse_label(q, false) -+ waction("REL_"..mode, n, s, 1) -+ elseif p == "C" then -- blx gpr only -+ if match(q, "^([%w_]+):(r1?[0-9])$") or match(q, "^r(1?[0-9])$") then -+ local r = parse_gpr(q) -+ op = op + shl(r, 3) -+ else -+ werror("not supported") -+ end -+ elseif p == "c" then -+ op = op + parse_it(params.op, q) -+ elseif p == "F" then -+ vr = "s" -+ elseif p == "G" then -+ vr = "d" -+ elseif p == "o" then -+ local r, wb = match(q, "^([^!]*)(!?)$") -+ op = op + shl(parse_gpr(r), 16) + (wb == "!" and 0x00200000 or 0) -+ n = n + 1 -+ elseif p == "R" then -+ if params[1] == "{r15}" and params.op == "pop" then -+ op = 0xf85dfb04; -- pop {pc} coded as T3 -+ elseif params[1] == "{r12}" and params.op == "pop" then -+ op = 0xf85dcb04; -- pop {r12} coded as T3 -+ elseif params[1] == "{r12}" and params.op == "push" then -+ op = 0xf84dcd04; -- push {r12} coded as T3 -+ else -+ op = op + parse_reglist(q) -+ end -+ n = n + 1 -+ elseif p == "r" then -+ op = op + parse_vrlist(q); n = n + 1 -+ elseif p == "w" then -+ local imm = match(q, "^#(.*)$") -+ if imm then -+ local imm5 = parse_imm(q, 5, 0, 0, false) -+ local m = band(op, 0x000f0000) -+ op = op - m + 0x000f0000 + shr(m, 16) + shl(band(imm5, 0x1c), 10) + shl(band(imm5, 0x03), 6); n = n + 1 -+ else -+ local type = band(op, 0x00000030) -+ op = op - 0xea400000 + 0xfa00f000 - type + shl(type, 17) + parse_gpr(q) -+ end -+ elseif p == "Y" then -+ local imm = tonumber(match(q, "^#(.*)$")); n = n + 1 -+ if not imm or shr(imm, 8) ~= 0 then -+ werror("bad immediate operand") -+ end -+ op = op + shl(band(imm, 0xf0), 12) + band(imm, 0x0f) -+ elseif p == "K" then -+ local imm = tonumber(match(q, "^#(.*)$")); n = n + 1 -+ if not imm or shr(imm, 8) ~= 0 then -+ werror("bad immediate operand") -+ end -+ op = op + band(imm, 0x00ff) -+ elseif p == "s" then -+ -- Ignored. -+ else -+ assert(false) -+ end -+ end -+ wputpos(pos, op) -+end -+ -+map_op[".template__"] = function(params, template, nparams) -+ if not params then return template:gsub("%x%x%x%x%x%x%x%x", "") end -+ -+ -- Limit number of section buffer positions used by a single dasm_put(). -+ -- A single opcode needs a maximum of 3 positions. -+ if secpos+3 > maxsecpos then wflush() end -+ local pos = wpos() -+ local lpos, apos, spos = #actlist, #actargs, secpos -+ -+ local ok, err -+ for t in gmatch(template, "[^|]+") do -+ ok, err = pcall(parse_template, params, t, nparams, pos) -+ if ok then return end -+ secpos = spos -+ actlist[lpos+1] = nil -+ actlist[lpos+2] = nil -+ actlist[lpos+3] = nil -+ actargs[apos+1] = nil -+ actargs[apos+2] = nil -+ actargs[apos+3] = nil -+ end -+ error(err, 0) -+end -+ -+------------------------------------------------------------------------------ -+ -+-- Pseudo-opcode to mark the position where the action list is to be emitted. -+map_op[".actionlist_1"] = function(params) -+ if not params then return "cvar" end -+ local name = params[1] -- No syntax check. You get to keep the pieces. -+ wline(function(out) writeactions(out, name) end) -+end -+ -+-- Pseudo-opcode to mark the position where the global enum is to be emitted. -+map_op[".globals_1"] = function(params) -+ if not params then return "prefix" end -+ local prefix = params[1] -- No syntax check. You get to keep the pieces. -+ wline(function(out) writeglobals(out, prefix) end) -+end -+ -+-- Pseudo-opcode to mark the position where the global names are to be emitted. -+map_op[".globalnames_1"] = function(params) -+ if not params then return "cvar" end -+ local name = params[1] -- No syntax check. You get to keep the pieces. -+ wline(function(out) writeglobalnames(out, name) end) -+end -+ -+-- Pseudo-opcode to mark the position where the extern names are to be emitted. -+map_op[".externnames_1"] = function(params) -+ if not params then return "cvar" end -+ local name = params[1] -- No syntax check. You get to keep the pieces. -+ wline(function(out) writeexternnames(out, name) end) -+end -+ -+------------------------------------------------------------------------------ -+ -+-- Label pseudo-opcode (converted from trailing colon form). -+map_op[".label_1"] = function(params) -+ if not params then return "[1-9] | ->global | =>pcexpr" end -+ if secpos+1 > maxsecpos then wflush() end -+ local mode, n, s = parse_label(params[1], true) -+ if mode == "EXT" then werror("bad label definition") end -+ waction("LABEL_"..mode, n, s, 1) -+end -+ -+------------------------------------------------------------------------------ -+ -+-- Pseudo-opcodes for data storage. -+map_op[".long_*"] = function(params) -+ if not params then return "imm..." end -+ for _,p in ipairs(params) do -+ local n = tonumber(p) -+ if not n then werror("bad immediate `"..p.."'") end -+ if n < 0 then n = n + 2^32 end -+ wputw(n) -+ if secpos+2 > maxsecpos then wflush() end -+ end -+end -+ -+-- Alignment pseudo-opcode. -+map_op[".align_1"] = function(params) -+ if not params then return "numpow2" end -+ if secpos+1 > maxsecpos then wflush() end -+ local align = tonumber(params[1]) -+ if align then -+ local x = align -+ -- Must be a power of 2 in the range (2 ... 256). -+ for i=1,8 do -+ x = x / 2 -+ if x == 1 then -+ waction("ALIGN", align-1, nil, 1) -- Action byte is 2**n-1. -+ return -+ end -+ end -+ end -+ werror("bad alignment") -+end -+ -+------------------------------------------------------------------------------ -+ -+-- Pseudo-opcode for (primitive) type definitions (map to C types). -+map_op[".type_3"] = function(params, nparams) -+ if not params then -+ return nparams == 2 and "name, ctype" or "name, ctype, reg" -+ end -+ local name, ctype, reg = params[1], params[2], params[3] -+ if not match(name, "^[%a_][%w_]*$") then -+ werror("bad type name `"..name.."'") -+ end -+ local tp = map_type[name] -+ if tp then -+ werror("duplicate type `"..name.."'") -+ end -+ -- Add #type to defines. A bit unclean to put it in map_archdef. -+ map_archdef["#"..name] = "sizeof("..ctype..")" -+ -- Add new type and emit shortcut define. -+ local num = ctypenum + 1 -+ map_type[name] = { -+ ctype = ctype, -+ ctypefmt = format("Dt%X(%%s)", num), -+ reg = reg, -+ } -+ wline(format("#define Dt%X(_V) (int)(ptrdiff_t)&(((%s *)0)_V)", num, ctype)) -+ ctypenum = num -+end -+map_op[".type_2"] = map_op[".type_3"] -+ -+-- Dump type definitions. -+local function dumptypes(out, lvl) -+ local t = {} -+ for name in pairs(map_type) do t[#t+1] = name end -+ sort(t) -+ out:write("Type definitions:\n") -+ for _,name in ipairs(t) do -+ local tp = map_type[name] -+ local reg = tp.reg or "" -+ out:write(format(" %-20s %-20s %s\n", name, tp.ctype, reg)) -+ end -+ out:write("\n") -+end -+ -+------------------------------------------------------------------------------ -+ -+-- Set the current section. -+function _M.section(num) -+ waction("SECTION", num) -+ wflush(true) -- SECTION is a terminal action. -+end -+ -+------------------------------------------------------------------------------ -+ -+-- Dump architecture description. -+function _M.dumparch(out) -+ out:write(format("DynASM %s version %s, released %s\n\n", -+ _info.arch, _info.version, _info.release)) -+ dumpactions(out) -+end -+ -+-- Dump all user defined elements. -+function _M.dumpdef(out, lvl) -+ dumptypes(out, lvl) -+ dumpglobals(out, lvl) -+ dumpexterns(out, lvl) -+end -+ -+------------------------------------------------------------------------------ -+ -+-- Pass callbacks from/to the DynASM core. -+function _M.passcb(wl, we, wf, ww) -+ wline, werror, wfatal, wwarn = wl, we, wf, ww -+ return wflush -+end -+ -+-- Setup the arch-specific module. -+function _M.setup(arch, opt) -+ g_arch, g_opt = arch, opt -+end -+ -+local map_cond_b = { -+ eq = "f0008000B", ne = "f0408000B", cs = "f0808000B", cc = "f0c08000B", mi = "f1008000B", pl = "f1408000B", vs = "f1808000B", vc = "f1c08000B", -+ hi = "f2008000B", ls = "f2408000B", ge = "f2808000B", lt = "f2c08000B", gt = "f3008000B", le = "f3408000B", al = "f3808000B", -+ hs = "f0808000B", lo = "f0c08000B", -+} -+ -+-- Merge the core maps and the arch-specific maps. -+function _M.mergemaps(map_coreop, map_def) -+ setmetatable(map_op, { __index = function(t, k) -+ local v = map_coreop[k] -+ if v then return v end -+ local k1, cc, k2 = match(k, "^(.-)(..)([._].*)$") -+ local cv = map_cond[cc] -+ if cv then -+ local v = rawget(t, k1..k2) -+ if type(v) == "string" and k1 == "b" then -+ local scv = map_cond_b[cc] -+ return scv -+ elseif type(v) == "string" then -+ return v -+ end -+ end -+ end }) -+ setmetatable(map_def, { __index = map_archdef }) -+ return map_op, map_def -+end -+ -+return _M -+ -+------------------------------------------------------------------------------ -+ -diff --git a/src/Makefile b/src/Makefile -old mode 100644 -new mode 100755 -index 30d64be2..83d592f3 ---- a/src/Makefile -+++ b/src/Makefile -@@ -36,7 +36,8 @@ CC= $(DEFAULT_CC) - # to slow down the C part by not omitting it. Debugging, tracebacks and - # unwinding are not affected -- the assembler part has frame unwind - # information and GCC emits it where needed (x64) or with -g (see CCDEBUG). --CCOPT= -O2 -fomit-frame-pointer -+#CCOPT= -O2 -fomit-frame-pointer -+CCOPT= -O2 -fomit-frame-pointer -D__ARM_ARCH_7M__ -DLUAJIT_NO_UNWIND -DLUAJIT_DISABLE_PROFILE - # Use this if you want to generate a smaller binary (but it's slower): - #CCOPT= -Os -fomit-frame-pointer - # Note: it's no longer recommended to use -O3 with GCC 4.x. -@@ -49,7 +50,7 @@ CCOPT= -O2 -fomit-frame-pointer - # - CCOPT_x86= -march=i686 -msse -msse2 -mfpmath=sse - CCOPT_x64= --CCOPT_arm= -+CCOPT_arm= -mthumb -march=armv7e-m -mfloat-abi=hard -mfpu=fpv5-d16 - CCOPT_arm64= - CCOPT_ppc= - CCOPT_mips= -@@ -71,7 +72,7 @@ CCWARN= -Wall - # as dynamic mode. - # - # Mixed mode creates a static + dynamic library and a statically linked luajit. --BUILDMODE= mixed -+BUILDMODE= static - # - # Static mode creates a static library and a statically linked luajit. - #BUILDMODE= static -@@ -242,6 +243,9 @@ ifneq (,$(findstring LJ_TARGET_X86 ,$(TARGET_TESTARCH))) - TARGET_LJARCH= x86 - else - ifneq (,$(findstring LJ_TARGET_ARM ,$(TARGET_TESTARCH))) -+ ifneq (,$(findstring __ARM_ARCH_7M__ ,$(TARGET_TESTARCH))) -+ TARGET_ARCH= -D__ARM_ARCH_7M__=1 -+ endif - TARGET_LJARCH= arm - else - ifneq (,$(findstring LJ_TARGET_ARM64 ,$(TARGET_TESTARCH))) -@@ -443,6 +447,9 @@ ifeq (x64,$(TARGET_LJARCH)) - endif - else - ifeq (arm,$(TARGET_LJARCH)) -+ ifneq (,$(findstring __ARM_ARCH_7M__ ,$(TARGET_TESTARCH))) -+ DASM_ARCH= armv7m -+ endif - ifeq (iOS,$(TARGET_SYS)) - DASM_AFLAGS+= -D IOS - endif -diff --git a/src/host/buildvm.c b/src/host/buildvm.c -index 9ee47ada..ca0ee47e 100644 ---- a/src/host/buildvm.c -+++ b/src/host/buildvm.c -@@ -60,7 +60,11 @@ static int collect_reloc(BuildCtx *ctx, uint8_t *addr, int idx, int type); - #if LJ_TARGET_X86ORX64 - #include "../dynasm/dasm_x86.h" - #elif LJ_TARGET_ARM -+#if defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__) -+#include "../dynasm/dasm_armv7m.h" -+#else - #include "../dynasm/dasm_arm.h" -+#endif - #elif LJ_TARGET_ARM64 - #include "../dynasm/dasm_arm64.h" - #elif LJ_TARGET_PPC -diff --git a/src/host/buildvm_asm.c b/src/host/buildvm_asm.c -index 7baa011f..1fc72a9d 100644 ---- a/src/host/buildvm_asm.c -+++ b/src/host/buildvm_asm.c -@@ -114,6 +114,20 @@ static void emit_asm_wordreloc(BuildCtx *ctx, uint8_t *p, int n, - emit_asm_words(ctx, p, n-4); - ins = *(uint32_t *)(p+n-4); - #if LJ_TARGET_ARM -+#if defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__) -+ if ((ins & 0xd000f800) == 0xd000f000) { -+ fprintf(ctx->fp, "\tbl %s\n", sym); -+ } -+ else if ((ins & 0xd000f800) == 0x9000f000) { -+ fprintf(ctx->fp, "\tb %s\n", sym); -+ } -+ else { -+ fprintf(stderr, -+ "Error: unsupported opcode %08x for %s symbol relocation.\n", -+ ins, sym); -+ exit(1); -+ } -+#else - if ((ins & 0xff000000u) == 0xfa000000u) { - fprintf(ctx->fp, "\tblx %s\n", sym); - } else if ((ins & 0x0e000000u) == 0x0a000000u) { -@@ -125,6 +139,7 @@ static void emit_asm_wordreloc(BuildCtx *ctx, uint8_t *p, int n, - ins, sym); - exit(1); - } -+#endif - #elif LJ_TARGET_ARM64 - if ((ins >> 26) == 0x25u) { - fprintf(ctx->fp, "\tbl %s\n", sym); -@@ -193,6 +208,16 @@ static void emit_asm_label(BuildCtx *ctx, const char *name, int size, int isfunc - break; - } - #endif -+#if defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__) -+ fprintf(ctx->fp, -+ "\n\t.globl %s\n" -+ "\t.thumb_func\n" -+ "\t.hidden %s\n" -+ "\t.type %s, " ELFASM_PX "%s\n" -+ "\t.size %s, %d\n" -+ "%s:\n", -+ name,name,name,isfunc ? "function" : "object",name,size,name); -+#else - fprintf(ctx->fp, - "\n\t.globl %s\n" - "\t.hidden %s\n" -@@ -200,6 +225,7 @@ static void emit_asm_label(BuildCtx *ctx, const char *name, int size, int isfunc - "\t.size %s, %d\n" - "%s:\n", - name, name, name, isfunc ? "function" : "object", name, size, name); -+#endif - break; - case BUILD_coffasm: - fprintf(ctx->fp, "\n\t.globl %s\n", name); -@@ -242,8 +268,16 @@ void emit_asm(BuildCtx *ctx) - int i, rel; - - fprintf(ctx->fp, "\t.file \"buildvm_%s.dasc\"\n", ctx->dasm_arch); -+#if defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__) -+ fprintf(ctx->fp, "\t.syntax unified\n"); -+ fprintf(ctx->fp, "\t.thumb\n"); -+#endif - fprintf(ctx->fp, "\t.text\n"); -+#if defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__) -+ emit_asm_align(ctx, 2); -+#else - emit_asm_align(ctx, 4); -+#endif - - #if LJ_TARGET_PS3 - emit_asm_label(ctx, ctx->beginsym, ctx->codesz, 0); -diff --git a/src/lj_alloc.c b/src/lj_alloc.c -index 20e60493..4cadd673 100644 ---- a/src/lj_alloc.c -+++ b/src/lj_alloc.c -@@ -38,10 +38,17 @@ - #define MAX_SIZE_T (~(size_t)0) - #define MALLOC_ALIGNMENT ((size_t)8U) - -+#if LJ_TARGET_NUTTX -+#define DEFAULT_GRANULARITY ((size_t)32U * (size_t)1024U) -+#define DEFAULT_TRIM_THRESHOLD ((size_t)512U * (size_t)1024U) -+#define DEFAULT_MMAP_THRESHOLD ((size_t)32U * (size_t)1024U) -+#define MAX_RELEASE_CHECK_RATE 255 -+#else - #define DEFAULT_GRANULARITY ((size_t)128U * (size_t)1024U) - #define DEFAULT_TRIM_THRESHOLD ((size_t)2U * (size_t)1024U * (size_t)1024U) - #define DEFAULT_MMAP_THRESHOLD ((size_t)128U * (size_t)1024U) - #define MAX_RELEASE_CHECK_RATE 255 -+#endif - - /* ------------------- size_t and alignment properties -------------------- */ - -@@ -90,9 +97,36 @@ - - #include - /* If this include fails, then rebuild with: -DLUAJIT_USE_SYSMALLOC */ -+#if LJ_TARGET_NUTTX -+#include -+#include -+ -+static struct mm_heap_s *g_alloc_heap; -+ -+static void init_mmap(void) -+{ -+ static uint8_t buffer[CONFIG_LUAJIT_ALLOC_SIZE] -+ locate_data(CONFIG_LUAJIT_ALLOC_SECTION_NAME); -+ g_alloc_heap = mm_initialize("alloc", -+ (void *)buffer, -+ CONFIG_LUAJIT_ALLOC_SIZE); -+} -+#define INIT_MMAP() init_mmap() -+ -+#define CALL_MMAP(prng, size) mm_malloc(g_alloc_heap, (size_t)size) -+#define DIRECT_MMAP(prng, s) CALL_MMAP(prng, s) -+ -+static int CALL_MUNMAP(void *ptr, size_t size) -+{ -+ if (ptr == NULL) return -1; -+ mm_free(g_alloc_heap, ptr); -+ return 0; -+} -+#else - #include - - #define LJ_ALLOC_MMAP 1 -+#endif - - #if LJ_64 - -diff --git a/src/lj_arch.h b/src/lj_arch.h -index 882c99cb..92fbae5e 100644 ---- a/src/lj_arch.h -+++ b/src/lj_arch.h -@@ -39,6 +39,7 @@ - #define LUAJIT_OS_OSX 3 - #define LUAJIT_OS_BSD 4 - #define LUAJIT_OS_POSIX 5 -+#define LUAJIT_OS_NUTTX 6 - - /* Number mode. */ - #define LJ_NUMMODE_SINGLE 0 /* Single-number mode only. */ -@@ -110,6 +111,8 @@ - #define LJ_OS_NAME "BSD" - #elif LUAJIT_OS == LUAJIT_OS_POSIX - #define LJ_OS_NAME "POSIX" -+#elif LUAJIT_OS == LUAJIT_OS_NUTTX -+#define LJ_OS_NAME "NUTTX" - #else - #define LJ_OS_NAME "Other" - #endif -@@ -119,6 +122,7 @@ - #define LJ_TARGET_OSX (LUAJIT_OS == LUAJIT_OS_OSX) - #define LJ_TARGET_BSD (LUAJIT_OS == LUAJIT_OS_BSD) - #define LJ_TARGET_POSIX (LUAJIT_OS > LUAJIT_OS_WINDOWS) -+#define LJ_TARGET_NUTTX (LUAJIT_OS == LUAJIT_OS_NUTTX) - #define LJ_TARGET_DLOPEN LJ_TARGET_POSIX - - #if TARGET_OS_IPHONE -@@ -214,8 +218,11 @@ - #endif - - #elif LUAJIT_TARGET == LUAJIT_ARCH_ARM -- -+#if defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__) -+#define LJ_ARCH_NAME "armv7m" -+#else - #define LJ_ARCH_NAME "arm" -+#endif - #define LJ_ARCH_BITS 32 - #define LJ_ARCH_ENDIAN LUAJIT_LE - #if !defined(LJ_ARCH_HASFPU) && __SOFTFP__ -@@ -227,8 +234,12 @@ - #define LJ_ABI_EABI 1 - #define LJ_TARGET_ARM 1 - #define LJ_TARGET_EHRETREG 0 --#define LJ_TARGET_EHRAREG 14 -+#if defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__) -+/* No need to test jump address range, because we use veeners. */ -+//#define LJ_TARGET_JUMPRANGE 24 /* +-2^24 = +-16MB */ -+#else - #define LJ_TARGET_JUMPRANGE 25 /* +-2^25 = +-32MB */ -+#endif - #define LJ_TARGET_MASKSHIFT 0 - #define LJ_TARGET_MASKROT 1 - #define LJ_TARGET_UNIFYROT 2 /* Want only IR_BROR. */ -@@ -236,7 +247,7 @@ - - #if __ARM_ARCH == 8 || __ARM_ARCH_8__ || __ARM_ARCH_8A__ - #define LJ_ARCH_VERSION 80 --#elif __ARM_ARCH == 7 || __ARM_ARCH_7__ || __ARM_ARCH_7A__ || __ARM_ARCH_7R__ || __ARM_ARCH_7S__ || __ARM_ARCH_7VE__ -+#elif __ARM_ARCH == 7 || __ARM_ARCH_7__ || __ARM_ARCH_7A__ || __ARM_ARCH_7R__ || __ARM_ARCH_7S__ || __ARM_ARCH_7VE__ || __ARM_ARCH_7M__ || __ARM_ARCH_7EM__ - #define LJ_ARCH_VERSION 70 - #elif __ARM_ARCH_6T2__ - #define LJ_ARCH_VERSION 61 -@@ -479,7 +490,7 @@ - #if defined(__ARMEB__) - #error "No support for big-endian ARM" - #endif --#if __ARM_ARCH_6M__ || __ARM_ARCH_7M__ || __ARM_ARCH_7EM__ -+#if __ARM_ARCH_6M__ /*|| __ARM_ARCH_7M__ || __ARM_ARCH_7EM__*/ - #error "No support for Cortex-M CPUs" - #endif - #if !(__ARM_EABI__ || LJ_TARGET_IOS) -diff --git a/src/lj_asm.c b/src/lj_asm.c -index 6f5e0c45..429aa161 100644 ---- a/src/lj_asm.c -+++ b/src/lj_asm.c -@@ -178,7 +178,11 @@ IRFLDEF(FLOFS) - #if LJ_TARGET_X86ORX64 - #include "lj_emit_x86.h" - #elif LJ_TARGET_ARM -+#if defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__) -+#include "lj_emit_armv7m.h" -+#else - #include "lj_emit_arm.h" -+#endif - #elif LJ_TARGET_ARM64 - #include "lj_emit_arm64.h" - #elif LJ_TARGET_PPC -@@ -1655,7 +1659,11 @@ static void asm_loop(ASMState *as) - #if LJ_TARGET_X86ORX64 - #include "lj_asm_x86.h" - #elif LJ_TARGET_ARM -+#if defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__) -+#include "lj_asm_armv7m.h" -+#else - #include "lj_asm_arm.h" -+#endif - #elif LJ_TARGET_ARM64 - #include "lj_asm_arm64.h" - #elif LJ_TARGET_PPC -diff --git a/src/lj_asm_armv7m.h b/src/lj_asm_armv7m.h -new file mode 100644 -index 00000000..1bdd4a8a ---- /dev/null -+++ b/src/lj_asm_armv7m.h -@@ -0,0 +1,2520 @@ -+/* -+** ARM IR assembler (SSA IR -> machine code). -+** Copyright (C) 2018 Jernej Turnsek. See Copyright Notice in luajit.h -+** Copyright (C) 2005-2020 Mike Pall. See Copyright Notice in luajit.h -+*/ -+ -+/* -- Register allocator extensions --------------------------------------- */ -+ -+/* Allocate a register with a hint. */ -+static Reg ra_hintalloc(ASMState *as, IRRef ref, Reg hint, RegSet allow) -+{ -+ Reg r = IR(ref)->r; -+ if (ra_noreg(r)) { -+ if (!ra_hashint(r) && !iscrossref(as, ref)) -+ ra_sethint(IR(ref)->r, hint); /* Propagate register hint. */ -+ r = ra_allocref(as, ref, allow); -+ } -+ ra_noweak(as, r); -+ return r; -+} -+ -+/* Allocate a scratch register pair. */ -+static Reg ra_scratchpair(ASMState *as, RegSet allow) -+{ -+ RegSet pick1 = as->freeset & allow; -+ RegSet pick2 = pick1 & (pick1 >> 1) & RSET_GPREVEN; -+ Reg r; -+ if (pick2) { -+ r = rset_picktop(pick2); -+ } -+ else { -+ RegSet pick = pick1 & (allow >> 1) & RSET_GPREVEN; -+ if (pick) { -+ r = rset_picktop(pick); -+ ra_restore(as, regcost_ref(as->cost[r + 1])); -+ } -+ else { -+ pick = pick1 & (allow << 1) & RSET_GPRODD; -+ if (pick) { -+ r = ra_restore(as, regcost_ref(as->cost[rset_picktop(pick) - 1])); -+ } -+ else { -+ r = ra_evict(as, allow & (allow >> 1) & RSET_GPREVEN); -+ ra_restore(as, regcost_ref(as->cost[r + 1])); -+ } -+ } -+ } -+ lj_assertA(rset_test(RSET_GPREVEN, r), "odd reg %d", r); -+ ra_modified(as, r); -+ ra_modified(as, r + 1); -+ RA_DBGX((as, "scratchpair $r $r", r, r + 1)); -+ return r; -+} -+ -+#if !LJ_SOFTFP -+/* Allocate two source registers for three-operand instructions. */ -+static Reg ra_alloc2(ASMState *as, IRIns *ir, RegSet allow) -+{ -+ IRIns *irl = IR(ir->op1), *irr = IR(ir->op2); -+ Reg left = irl->r, right = irr->r; -+ if (ra_hasreg(left)) { -+ ra_noweak(as, left); -+ if (ra_noreg(right)) -+ right = ra_allocref(as, ir->op2, rset_exclude(allow, left)); -+ else -+ ra_noweak(as, right); -+ } -+ else if (ra_hasreg(right)) { -+ ra_noweak(as, right); -+ left = ra_allocref(as, ir->op1, rset_exclude(allow, right)); -+ } -+ else if (ra_hashint(right)) { -+ right = ra_allocref(as, ir->op2, allow); -+ left = ra_alloc1(as, ir->op1, rset_exclude(allow, right)); -+ } -+ else { -+ left = ra_allocref(as, ir->op1, allow); -+ right = ra_alloc1(as, ir->op2, rset_exclude(allow, left)); -+ } -+ return left | (right << 8); -+} -+#endif -+ -+/* -- Guard handling ------------------------------------------------------ */ -+ -+/* Generate an exit stub group at the bottom of the reserved MCode memory. */ -+static MCode *asm_exitstub_gen(ASMState *as, ExitNo group) -+{ -+ MCode *mxp = as->mcbot; -+ int i; -+ if (mxp + 8 * 4 + 4*EXITSTUBS_PER_GROUP >= as->mctop) -+ asm_mclimit(as); -+ /* lj_vm_exit_interp_veneer */ -+ *mxp++ = ARMI_LDR | ARMF_N(RID_PC) | ARMF_T(RID_PC); /* LDR.W PC, [PC, #-0] */ -+ *mxp++ = (MCode)lj_vm_exit_interp; -+ /* lj_vm_exit_handler_veneer */ -+ *mxp++ = ARMI_LDR | ARMF_N(RID_PC) | ARMF_T(RID_PC); /* LDR.W PC, [PC, #-0] */ -+ *mxp++ = (MCode)lj_vm_exit_handler; -+ /* str lr, [sp]; bl ->vm_exit_handler; .long DISPATCH_address, group. */ -+ *mxp++ = ARMI_STR | ARMI_LSX_U | ARMF_T(RID_LR) | ARMF_N(RID_SP); -+ *mxp = ARMI_BL | ARMC_BL((-4) << 1); /* lj_vm_exit_handler_veneer */ -+ mxp++; -+ *mxp++ = (MCode)i32ptr(J2GG(as->J)->dispatch); /* DISPATCH address */ -+ *mxp++ = group*EXITSTUBS_PER_GROUP; -+ for (i = 0; i < EXITSTUBS_PER_GROUP; i++) -+ *mxp++ = ARMI_B_T4 | ARMC_BL((-5 - i) << 1); -+ lj_mcode_sync(as->mcbot, mxp); -+ lj_mcode_commitbot(as->J, mxp); -+ as->mcbot = mxp; -+ as->mclim = as->mcbot + MCLIM_REDZONE; -+ return mxp - EXITSTUBS_PER_GROUP; -+} -+ -+/* Setup all needed exit stubs. */ -+static void asm_exitstub_setup(ASMState *as, ExitNo nexits) -+{ -+ ExitNo i; -+ if (nexits >= EXITSTUBS_PER_GROUP*LJ_MAX_EXITSTUBGR) -+ lj_trace_err(as->J, LJ_TRERR_SNAPOV); -+ for (i = 0; i < (nexits + EXITSTUBS_PER_GROUP - 1) / EXITSTUBS_PER_GROUP; i++) -+ if (as->J->exitstubgroup[i] == NULL) -+ as->J->exitstubgroup[i] = asm_exitstub_gen(as, i); -+} -+ -+/* Emit conditional branch to exit for guard. */ -+static void asm_guardcc(ASMState *as, ARMCC cc) -+{ -+ MCode *target = exitstub_addr(as->J, as->snapno); -+ MCode *p = as->mcp; -+ if (LJ_UNLIKELY(p == as->invmcp)) { -+ as->loopinv = 1; -+ *p = ARMI_BL | ARMC_BL((target - p - 1) << 1); -+ emit_branch(as, ARMF_CC(ARMI_B, cc ^ 1), p); -+ return; -+ } -+ emit_branchlink(as, ARMI_BL, target); -+ ARMI_IT(cc); -+} -+ -+/* -- Operand fusion ------------------------------------------------------ */ -+ -+/* Limit linear search to this distance. Avoids O(n^2) behavior. */ -+#define CONFLICT_SEARCH_LIM 31 -+ -+/* Check if there's no conflicting instruction between curins and ref. */ -+static int noconflict(ASMState *as, IRRef ref, IROp conflict) -+{ -+ IRIns *ir = as->ir; -+ IRRef i = as->curins; -+ if (i > ref + CONFLICT_SEARCH_LIM) -+ return 0; /* Give up, ref is too far away. */ -+ while (--i > ref) -+ if (ir[i].o == conflict) -+ return 0; /* Conflict found. */ -+ return 1; /* Ok, no conflict. */ -+} -+ -+/* Fuse the array base of colocated arrays. */ -+static int32_t asm_fuseabase(ASMState *as, IRRef ref) -+{ -+ IRIns *ir = IR(ref); -+ if (ir->o == IR_TNEW && ir->op1 <= LJ_MAX_COLOSIZE && -+ !neverfuse(as) && noconflict(as, ref, IR_NEWREF)) -+ return (int32_t)sizeof(GCtab); -+ return 0; -+} -+ -+/* Fuse array/hash/upvalue reference into register+offset operand. */ -+static Reg asm_fuseahuref(ASMState *as, IRRef ref, int32_t *ofsp, RegSet allow, int lim) -+{ -+ IRIns *ir = IR(ref); -+ if (ra_noreg(ir->r)) { -+ if (ir->o == IR_AREF) { -+ if (mayfuse(as, ref)) { -+ if (irref_isk(ir->op2)) { -+ IRRef tab = IR(ir->op1)->op1; -+ int32_t ofs = asm_fuseabase(as, tab); -+ IRRef refa = ofs ? tab : ir->op1; -+ ofs += 8*IR(ir->op2)->i; -+ if (ofs > -lim && ofs < lim) { -+ *ofsp = ofs; -+ return ra_alloc1(as, refa, allow); -+ } -+ } -+ } -+ } -+ else if (ir->o == IR_HREFK) { -+ if (mayfuse(as, ref)) { -+ int32_t ofs = (int32_t)(IR(ir->op2)->op2 * sizeof(Node)); -+ if (ofs < lim) { -+ *ofsp = ofs; -+ return ra_alloc1(as, ir->op1, allow); -+ } -+ } -+ } -+ else if (ir->o == IR_UREFC) { -+ if (irref_isk(ir->op1)) { -+ GCfunc *fn = ir_kfunc(IR(ir->op1)); -+ int32_t ofs = i32ptr(&gcref(fn->l.uvptr[(ir->op2 >> 8)])->uv.tv); -+ *ofsp = (ofs & 255); /* Mask out less bits to allow LDRD. */ -+ return ra_allock(as, (ofs & ~255), allow); -+ } -+ } else if (ir->o == IR_TMPREF) { -+ *ofsp = 0; -+ return RID_SP; -+ } -+ } -+ *ofsp = 0; -+ return ra_alloc1(as, ref, allow); -+} -+ -+/* Fuse m operand into arithmetic/logic instructions. */ -+static uint32_t asm_fuseopm(ASMState *as, ARMIns ai, IRRef ref, RegSet allow, uint32_t *rs) -+{ -+ IRIns *ir = IR(ref); -+ if (ra_hasreg(ir->r)) { -+ ra_noweak(as, ir->r); -+ return ARMF_M(ir->r); -+ } -+ else if (irref_isk(ref)) { -+ uint32_t k = emit_isk12(ai, ir->i); -+ if (k) -+ return k; -+ } -+ else if (mayfuse(as, ref)) { -+ if (ir->o >= IR_BSHL && ir->o <= IR_BROR) { -+ Reg m = ra_alloc1(as, ir->op1, allow); -+ ARMShift sh = ir->o == IR_BSHL ? ARMSH_LSL : -+ ir->o == IR_BSHR ? ARMSH_LSR : -+ ir->o == IR_BSAR ? ARMSH_ASR : ARMSH_ROR; -+ if (irref_isk(ir->op2)) { -+ return ARMF_M(m) | ARMF_SH(sh, (IR(ir->op2)->i & 31)); -+ } -+ else { -+ Reg s = ra_alloc1(as, ir->op2, rset_exclude(allow, m)); -+ *rs = ARMF_RSH(sh, s); -+ return ARMF_M(m); -+ } -+ } -+ else if (ir->o == IR_ADD && ir->op1 == ir->op2) { -+ Reg m = ra_alloc1(as, ir->op1, allow); -+ return ARMF_M(m) | ARMF_SH(ARMSH_LSL, 1); -+ } -+ } -+ return ARMF_M(ra_allocref(as, ref, allow)); -+} -+ -+/* Fuse shifts into loads/stores. Only bother with BSHL 2 => lsl #2. */ -+static IRRef asm_fuselsl2(ASMState *as, IRRef ref) -+{ -+ IRIns *ir = IR(ref); -+ if (ra_noreg(ir->r) && mayfuse(as, ref) && ir->o == IR_BSHL && -+ irref_isk(ir->op2) && IR(ir->op2)->i == 2) -+ return ir->op1; -+ return 0; /* No fusion. */ -+} -+ -+/* Fuse XLOAD/XSTORE reference into load/store operand. */ -+static void asm_fusexref(ASMState *as, -+ ARMIns ai, -+ Reg rd, -+ IRRef ref, -+ RegSet allow, -+ int32_t ofs) -+{ -+ IRIns *ir = IR(ref); -+ Reg base; -+ if (ra_noreg(ir->r) && canfuse(as, ir)) { -+ int32_t lim = (!LJ_SOFTFP && ((ai & 0x0000ff00) == 0x0000ed00)) ? 1024 : -+ (ai & 0x00000080) ? 4096 : 256; -+ if (ir->o == IR_ADD) { -+ int32_t ofs2; -+ if (irref_isk(ir->op2) && -+ (ofs2 = ofs + IR(ir->op2)->i) > -lim && ofs2 < lim && -+ (!(!LJ_SOFTFP && ((ai & 0x0000ff00) == 0x0000ed00)) || !(ofs2 & 3))) { -+ ofs = ofs2; -+ ref = ir->op1; -+ } -+ else if (ofs == 0 && !(!LJ_SOFTFP && ((ai & 0x0000ff00) == 0x0000ed00))) { -+ IRRef lref = ir->op1, rref = ir->op2; -+ Reg rn, rm; -+ IRRef sref = asm_fuselsl2(as, rref); -+ if (sref) { -+ rref = sref; -+ ai |= ARMF_LSL(2); -+ } -+ else if ((sref = asm_fuselsl2(as, lref)) != 0) { -+ lref = rref; -+ rref = sref; -+ ai |= ARMF_LSL(2); -+ } -+ rn = ra_alloc1(as, lref, allow); -+ rm = ra_alloc1(as, rref, rset_exclude(allow, rn)); -+ emit_tnm(as, ai, rd, rn, rm); -+ return; -+ } -+ } -+ else if (ir->o == IR_STRREF && !(!LJ_SOFTFP && ((ai & 0x0000ff00) == 0x0000ed00))) { -+ lj_assertA(ofs == 0, "bad usage"); -+ ofs = (int32_t)sizeof(GCstr); -+ if (irref_isk(ir->op2)) { -+ ofs += IR(ir->op2)->i; -+ ref = ir->op1; -+ } -+ else if (irref_isk(ir->op1)) { -+ ofs += IR(ir->op1)->i; -+ ref = ir->op2; -+ } -+ else { -+ /* NYI: Fuse ADD with constant. */ -+ Reg rn = ra_alloc1(as, ir->op1, allow); -+ uint32_t rs = 0; -+ uint32_t m = asm_fuseopm(as, 0, ir->op2, rset_exclude(allow, rn), &rs); -+ if ((ai & 0x0000fe00) == 0x0000f800) -+ emit_lso(as, ai, rd, rd, ofs); -+ else -+ emit_lsox(as, ai, rd, rd, ofs); -+ emit_dn(as, ARMI_ADD ^ m, rd, rn); -+ if (rs) -+ emit_dn(as, (ARMI_MOV ^ 0x0000104f) | rs, (m >> 16), (m >> 16)); -+ return; -+ } -+ if (ofs <= -lim || ofs >= lim) { -+ Reg rn = ra_alloc1(as, ref, allow); -+ Reg rm = ra_allock(as, ofs, rset_exclude(allow, rn)); -+ emit_tnm(as, ai, rd, rn, rm); -+ return; -+ } -+ } -+ } -+ base = ra_alloc1(as, ref, allow); -+#if !LJ_SOFTFP -+ if ((ai & 0x0000ff00) == 0x0000ed00) -+ emit_vlso(as, ai, rd, base, ofs); -+ else -+#endif -+ if ((ai & 0x0000fe00) == 0x0000f800) -+ emit_lso(as, ai, rd, base, ofs); -+ else -+ emit_lsox(as, ai, rd, base, ofs); -+} -+ -+#if !LJ_SOFTFP -+/* Fuse to multiply-add/sub instruction. */ -+static int asm_fusemadd(ASMState *as, IRIns *ir, ARMIns ai, ARMIns air) -+{ -+ IRRef lref = ir->op1, rref = ir->op2; -+ IRIns *irm; -+ if (lref != rref && -+ ((mayfuse(as, lref) && (irm = IR(lref), irm->o == IR_MUL) && -+ ra_noreg(irm->r)) || -+ (mayfuse(as, rref) && (irm = IR(rref), irm->o == IR_MUL) && -+ (rref = lref, ai = air, ra_noreg(irm->r))))) { -+ Reg dest = ra_dest(as, ir, RSET_FPR); -+ Reg add = ra_hintalloc(as, rref, dest, RSET_FPR); -+ Reg right, left = ra_alloc2(as, -+ irm, -+ rset_exclude(rset_exclude(RSET_FPR, dest), add)); -+ right = (left >> 8); left &= 255; -+ emit_tnm(as, ai, (dest & 15), (left & 15), (right & 15)); -+ if (dest != add) emit_tm(as, ARMI_VMOV_D, (dest & 15), (add & 15)); -+ return 1; -+ } -+ return 0; -+} -+#endif -+ -+/* -- Calls --------------------------------------------------------------- */ -+ -+/* Generate a call to a C function. */ -+static void asm_gencall(ASMState *as, const CCallInfo *ci, IRRef *args) -+{ -+ uint32_t n, nargs = CCI_XNARGS(ci); -+ int32_t ofs = 0; -+#if LJ_SOFTFP -+ Reg gpr = REGARG_FIRSTGPR; -+#else -+ Reg gpr, fpr = REGARG_FIRSTFPR, fprodd = 0; -+#endif -+ if ((void *)ci->func) -+ emit_call(as, (void *)ci->func); -+#if !LJ_SOFTFP -+ for (gpr = REGARG_FIRSTGPR; gpr <= REGARG_LASTGPR; gpr++) -+ as->cost[gpr] = REGCOST(~0u, ASMREF_L); -+ gpr = REGARG_FIRSTGPR; -+#endif -+ for (n = 0; n < nargs; n++) { -+ /* Setup args. */ -+ IRRef ref = args[n]; -+ IRIns *ir = IR(ref); -+#if !LJ_SOFTFP -+ if (ref && irt_isfp(ir->t)) { -+ RegSet of = as->freeset; -+ Reg src; -+ if (!LJ_ABI_SOFTFP && !(ci->flags & CCI_VARARG)) { -+ if (irt_isnum(ir->t)) { -+ if (fpr <= REGARG_LASTFPR) { -+ ra_leftov(as, fpr, ref); -+ fpr++; -+ continue; -+ } -+ } -+ else if (fprodd) { -+ /* Ick. */ -+ src = ra_alloc1(as, ref, RSET_FPR); -+ emit_tm(as, ARMI_VMOV_S, (fprodd & 15), (src & 15) | 0x00000040); -+ fprodd = 0; -+ continue; -+ } -+ else if (fpr <= REGARG_LASTFPR) { -+ ra_leftov(as, fpr, ref); -+ fprodd = fpr++; -+ continue; -+ } -+ /* Workaround to protect argument GPRs from being used for remat. */ -+ as->freeset &= ~RSET_RANGE(REGARG_FIRSTGPR, REGARG_LASTGPR + 1); -+ src = ra_alloc1(as, ref, RSET_FPR); /* May alloc GPR to remat FPR. */ -+ as->freeset |= (of & RSET_RANGE(REGARG_FIRSTGPR, REGARG_LASTGPR + 1)); -+ fprodd = 0; -+ goto stackfp; -+ } -+ /* Workaround to protect argument GPRs from being used for remat. */ -+ as->freeset &= ~RSET_RANGE(REGARG_FIRSTGPR, REGARG_LASTGPR + 1); -+ src = ra_alloc1(as, ref, RSET_FPR); /* May alloc GPR to remat FPR. */ -+ as->freeset |= (of & RSET_RANGE(REGARG_FIRSTGPR, REGARG_LASTGPR + 1)); -+ if (irt_isnum(ir->t)) gpr = (gpr + 1) & ~1u; -+ if (gpr <= REGARG_LASTGPR) { -+ lj_assertA(rset_test(as->freeset, gpr), -+ "reg %d not free", gpr); /* Must have been evicted. */ -+ if (irt_isnum(ir->t)) { -+ lj_assertA(rset_test(as->freeset, gpr+1), -+ "reg %d not free", gpr+1); /* Ditto. */ -+ emit_tnm(as, ARMI_VMOV_RR_D, gpr, gpr + 1, (src & 15)); -+ gpr += 2; -+ } -+ else { -+ emit_tn(as, ARMI_VMOV_R_S, gpr, (src & 15)); -+ gpr++; -+ } -+ } -+ else { -+stackfp: -+ if (irt_isnum(ir->t)) ofs = (ofs + 4) & ~4; -+ emit_spstore(as, ir, src, ofs); -+ ofs += irt_isnum(ir->t) ? 8 : 4; -+ } -+ } -+ else -+#endif -+ { -+ if (gpr <= REGARG_LASTGPR) { -+ lj_assertA(rset_test(as->freeset, gpr), -+ "reg %d not free", gpr); /* Must have been evicted. */ -+ if (ref) ra_leftov(as, gpr, ref); -+ gpr++; -+ } -+ else { -+ if (ref) { -+ Reg r = ra_alloc1(as, ref, RSET_GPR); -+ emit_spstore(as, ir, r, ofs); -+ } -+ ofs += 4; -+ } -+ } -+ } -+} -+ -+/* Setup result reg/sp for call. Evict scratch regs. */ -+static void asm_setupresult(ASMState *as, IRIns *ir, const CCallInfo *ci) -+{ -+ RegSet drop = RSET_SCRATCH; -+ int hiop = ((ir + 1)->o == IR_HIOP && !irt_isnil((ir + 1)->t)); -+ if (ra_hasreg(ir->r)) -+ rset_clear(drop, ir->r); /* Dest reg handled below. */ -+ if (hiop && ra_hasreg((ir + 1)->r)) -+ rset_clear(drop, (ir + 1)->r); /* Dest reg handled below. */ -+ ra_evictset(as, drop); /* Evictions must be performed first. */ -+ if (ra_used(ir)) { -+ lj_assertA(!irt_ispri(ir->t), "PRI dest"); -+ if (!LJ_SOFTFP && irt_isfp(ir->t)) { -+ if (LJ_ABI_SOFTFP || (ci->flags & (CCI_CASTU64 | CCI_VARARG))) { -+ Reg dest = (ra_dest(as, ir, RSET_FPR) & 15); -+ if (irt_isnum(ir->t)) -+ emit_tnm(as, ARMI_VMOV_D_RR, RID_RETLO, RID_RETHI, dest); -+ else -+ emit_tn(as, ARMI_VMOV_S_R, RID_RET, dest); -+ } -+ else { -+ ra_destreg(as, ir, RID_FPRET); -+ } -+ } -+ else if (hiop) { -+ ra_destpair(as, ir); -+ } -+ else { -+ ra_destreg(as, ir, RID_RET); -+ } -+ } -+ UNUSED(ci); -+} -+ -+static void asm_callx(ASMState *as, IRIns *ir) -+{ -+ IRRef args[CCI_NARGS_MAX * 2]; -+ CCallInfo ci; -+ IRRef func; -+ IRIns *irf; -+ ci.flags = asm_callx_flags(as, ir); -+ asm_collectargs(as, ir, &ci, args); -+ asm_setupresult(as, ir, &ci); -+ func = ir->op2; irf = IR(func); -+ if (irf->o == IR_CARG) { func = irf->op1; irf = IR(func); } -+ if (irref_isk(func)) { -+ /* Call to constant address. */ -+ ci.func = (ASMFunction)(void *)(irf->i); -+ } -+ else { -+ /* Need a non-argument register for indirect calls. */ -+ Reg freg = ra_alloc1(as, func, RSET_RANGE(RID_R4, RID_R12 + 1)); -+ emit_m(as, ARMI_BLXr, freg); -+ ci.func = (ASMFunction)(void *)0; -+ } -+ asm_gencall(as, &ci, args); -+} -+ -+/* -- Returns ------------------------------------------------------------- */ -+ -+/* Return to lower frame. Guard that it goes to the right spot. */ -+static void asm_retf(ASMState *as, IRIns *ir) -+{ -+ Reg base = ra_alloc1(as, REF_BASE, RSET_GPR); -+ void *pc = ir_kptr(IR(ir->op2)); -+ int32_t delta = 1 + LJ_FR2 + bc_a(*((const BCIns *)pc - 1)); -+ as->topslot -= (BCReg)delta; -+ if ((int32_t)as->topslot < 0) as->topslot = 0; -+ irt_setmark(IR(REF_BASE)->t); /* Children must not coalesce with BASE reg. */ -+ /* Need to force a spill on REF_BASE now to update the stack slot. */ -+ emit_lso(as, ARMI_STR, base, RID_SP, ra_spill(as, IR(REF_BASE))); -+ emit_setgl(as, base, jit_base); -+ emit_addptr(as, base, -8*delta); -+ asm_guardcc(as, CC_NE); -+ emit_nm(as, -+ ARMI_CMP, -+ RID_TMP, -+ ra_allock(as, i32ptr(pc), rset_exclude(RSET_GPR, base))); -+ emit_lso(as, ARMI_LDR, RID_TMP, base, -4); -+} -+ -+/* -- Buffer operations --------------------------------------------------- */ -+ -+#if LJ_HASBUFFER -+static void asm_bufhdr_write(ASMState *as, Reg sb) -+{ -+ Reg tmp = ra_scratch(as, rset_exclude(RSET_GPR, sb)); -+ IRIns irgc; -+ int32_t addr = i32ptr((void *)&J2G(as->J)->cur_L); -+ irgc.ot = IRT(0, IRT_PGC); /* GC type. */ -+ emit_storeofs(as, &irgc, RID_TMP, sb, offsetof(SBuf, L)); -+ //if ((as->flags & JIT_F_ARMV6T2)) { //jturnsek!!! -+ // emit_dnm(as, ARMI_BFI, RID_TMP, lj_fls(SBUF_MASK_FLAG), tmp); -+ //} else { -+ emit_dnm(as, ARMI_ORR, RID_TMP, RID_TMP, tmp); -+ emit_dn(as, ARMC_K12(ARMI_AND, 255), tmp, tmp); -+ //} -+ emit_lso(as, ARMI_LDR, RID_TMP, -+ ra_allock(as, (addr & ~4095), -+ rset_exclude(rset_exclude(RSET_GPR, sb), tmp)), -+ (addr & 4095)); -+ emit_loadofs(as, &irgc, tmp, sb, offsetof(SBuf, L)); -+} -+#endif -+ -+/* -- Type conversions ---------------------------------------------------- */ -+ -+#if !LJ_SOFTFP -+static void asm_tointg(ASMState *as, IRIns *ir, Reg left) -+{ -+ Reg tmp = ra_scratch(as, rset_exclude(RSET_FPR, left)); -+ Reg dest = ra_dest(as, ir, RSET_GPR); -+ asm_guardcc(as, CC_NE); -+ emit_t(as, ARMI_VMRS, 0); -+ emit_tm(as, ARMI_VCMP_D, (tmp & 15), (left & 15)); -+ emit_tm(as, ARMI_VCVT_F64_S32, (tmp & 15), (tmp & 15)); -+ emit_tn(as, ARMI_VMOV_R_S, dest, (tmp & 15)); -+ emit_tm(as, ARMI_VCVT_S32_F64, (tmp & 15), (left & 15)); -+} -+ -+static void asm_tobit(ASMState *as, IRIns *ir) -+{ -+ RegSet allow = RSET_FPR; -+ Reg left = ra_alloc1(as, ir->op1, allow); -+ Reg right = ra_alloc1(as, ir->op2, rset_clear(allow, left)); -+ Reg tmp = ra_scratch(as, rset_clear(allow, right)); -+ Reg dest = ra_dest(as, ir, RSET_GPR); -+ emit_tn(as, ARMI_VMOV_R_S, dest, (tmp & 15)); -+ emit_tnm(as, ARMI_VADD_D, (tmp & 15), (left & 15), (right & 15)); -+} -+#endif -+ -+static void asm_conv(ASMState *as, IRIns *ir) -+{ -+ IRType st = (IRType)(ir->op2 & IRCONV_SRCMASK); -+#if !LJ_SOFTFP -+ int stfp = (st == IRT_NUM || st == IRT_FLOAT); -+#endif -+ IRRef lref = ir->op1; -+ /* 64 bit integer conversions are handled by SPLIT. */ -+ lj_assertA(!irt_isint64(ir->t) && !(st == IRT_I64 || st == IRT_U64), -+ "IR %04d has unsplit 64 bit type", -+ (int)(ir - as->ir) - REF_BIAS); -+#if LJ_SOFTFP -+ /* FP conversions are handled by SPLIT. */ -+ lj_assertA(!irt_isfp(ir->t) && !(st == IRT_NUM || st == IRT_FLOAT), -+ "IR %04d has FP type", -+ (int)(ir - as->ir) - REF_BIAS); -+ /* Can't check for same types: SPLIT uses CONV int.int + BXOR for sfp NEG. */ -+#else -+ lj_assertA(irt_type(ir->t) != st, "inconsistent types for CONV"); -+ if (irt_isfp(ir->t)) { -+ Reg dest = ra_dest(as, ir, RSET_FPR); -+ if (stfp) { -+ /* FP to FP conversion. */ -+ emit_tm(as, -+ st == IRT_NUM ? ARMI_VCVT_F32_F64 : ARMI_VCVT_F64_F32, -+ (dest & 15), -+ (ra_alloc1(as, lref, RSET_FPR) & 15)); -+ } -+ else { -+ /* Integer to FP conversion. */ -+ Reg left = ra_alloc1(as, lref, RSET_GPR); -+ ARMIns ai = irt_isfloat(ir->t) ? -+ (st == IRT_INT ? ARMI_VCVT_F32_S32 : ARMI_VCVT_F32_U32) : -+ (st == IRT_INT ? ARMI_VCVT_F64_S32 : ARMI_VCVT_F64_U32); -+ emit_tm(as, ai, (dest & 15), (dest & 15)); -+ emit_tn(as, ARMI_VMOV_S_R, left, (dest & 15)); -+ } -+ } -+ else if (stfp) { -+ /* FP to integer conversion. */ -+ if (irt_isguard(ir->t)) { -+ /* Checked conversions are only supported from number to int. */ -+ lj_assertA(irt_isint(ir->t) && st == IRT_NUM, -+ "bad type for checked CONV"); -+ asm_tointg(as, ir, ra_alloc1(as, lref, RSET_FPR)); -+ } -+ else { -+ Reg left = ra_alloc1(as, lref, RSET_FPR); -+ Reg tmp = ra_scratch(as, rset_exclude(RSET_FPR, left)); -+ Reg dest = ra_dest(as, ir, RSET_GPR); -+ ARMIns ai; -+ emit_tn(as, ARMI_VMOV_R_S, dest, (tmp & 15)); -+ ai = irt_isint(ir->t) ? -+ (st == IRT_NUM ? ARMI_VCVT_S32_F64 : ARMI_VCVT_S32_F32) : -+ (st == IRT_NUM ? ARMI_VCVT_U32_F64 : ARMI_VCVT_U32_F32); -+ emit_tm(as, ai, (tmp & 15), (left & 15)); -+ } -+ } -+ else -+#endif -+ { -+ Reg dest = ra_dest(as, ir, RSET_GPR); -+ if (st >= IRT_I8 && st <= IRT_U16) { -+ /* Extend to 32 bit integer. */ -+ Reg left = ra_alloc1(as, lref, RSET_GPR); -+ lj_assertA(irt_isint(ir->t) || irt_isu32(ir->t), "bad type for CONV EXT"); -+ if ((as->flags & JIT_F_ARMV6)) { -+ ARMIns ai = st == IRT_I8 ? ARMI_SXTB : -+ st == IRT_U8 ? ARMI_UXTB : -+ st == IRT_I16 ? ARMI_SXTH : ARMI_UXTH; -+ emit_dm(as, ai, dest, left); -+ } -+ else if (st == IRT_U8) { -+ emit_dn(as, ARMC_K12(ARMI_AND, 255), dest, left); -+ } -+ else { -+ uint32_t shift = st == IRT_I8 ? 24 : 16; -+ ARMShift sh = st == IRT_U16 ? ARMSH_LSR : ARMSH_ASR; -+ emit_dm(as, ARMI_MOV | ARMF_SH(sh, shift), dest, RID_TMP); -+ emit_dm(as, ARMI_MOV | ARMF_SH(ARMSH_LSL, shift), RID_TMP, left); -+ } -+ } -+ else { -+ /* Handle 32/32 bit no-op (cast). */ -+ ra_leftov(as, dest, lref); /* Do nothing, but may need to move regs. */ -+ } -+ } -+} -+ -+static void asm_strto(ASMState *as, IRIns *ir) -+{ -+ const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_strscan_num]; -+ IRRef args[2]; -+ Reg rlo = 0, rhi = 0, tmp; -+ int destused = ra_used(ir); -+ int32_t ofs = 0; -+ ra_evictset(as, RSET_SCRATCH); -+#if LJ_SOFTFP -+ if (destused) { -+ if (ra_hasspill(ir->s) && ra_hasspill((ir + 1)->s) && -+ (ir->s & 1) == 0 && ir->s + 1 == (ir + 1)->s) { -+ int i; -+ for (i = 0; i < 2; i++) { -+ Reg r = (ir + i)->r; -+ if (ra_hasreg(r)) { -+ ra_free(as, r); -+ ra_modified(as, r); -+ emit_spload(as, ir + i, r, sps_scale((ir + i)->s)); -+ } -+ } -+ ofs = sps_scale(ir->s); -+ destused = 0; -+ } -+ else { -+ rhi = ra_dest(as, ir + 1, RSET_GPR); -+ rlo = ra_dest(as, ir, rset_exclude(RSET_GPR, rhi)); -+ } -+ } -+ asm_guardcc(as, CC_EQ); -+ if (destused) { -+ emit_lso(as, ARMI_LDR, rhi, RID_SP, 4); -+ emit_lso(as, ARMI_LDR, rlo, RID_SP, 0); -+ } -+#else -+ UNUSED(rhi); -+ if (destused) { -+ if (ra_hasspill(ir->s)) { -+ ofs = sps_scale(ir->s); -+ destused = 0; -+ if (ra_hasreg(ir->r)) { -+ ra_free(as, ir->r); -+ ra_modified(as, ir->r); -+ emit_spload(as, ir, ir->r, ofs); -+ } -+ } -+ else { -+ rlo = ra_dest(as, ir, RSET_FPR); -+ } -+ } -+ asm_guardcc(as, CC_EQ); -+ if (destused) -+ emit_vlso(as, ARMI_VLDR_D, rlo, RID_SP, 0); -+#endif -+ emit_n(as, ARMC_K12(ARMI_CMP, 0), RID_RET); /* Test return status. */ -+ args[0] = ir->op1; /* GCstr *str */ -+ args[1] = ASMREF_TMP1; /* TValue *n */ -+ asm_gencall(as, ci, args); -+ tmp = ra_releasetmp(as, ASMREF_TMP1); -+ if (ofs == 0) -+ emit_dm(as, ARMI_MOV, tmp, RID_SP); -+ else -+ emit_opk(as, ARMI_ADD, tmp, RID_SP, ofs, RSET_GPR); -+} -+ -+/* -- Memory references --------------------------------------------------- */ -+ -+/* Get pointer to TValue. */ -+static void asm_tvptr(ASMState *as, Reg dest, IRRef ref, MSize mode) -+{ -+ if ((mode & IRTMPREF_IN1)) { -+ IRIns *ir = IR(ref); -+ if (irt_isnum(ir->t)) { -+ if ((mode & IRTMPREF_OUT1)) { -+#if LJ_SOFTFP -+ lj_assertA(irref_isk(ref), "unsplit FP op"); -+ emit_dm(as, ARMI_MOV, dest, RID_SP); -+ emit_lso(as, ARMI_STR, -+ ra_allock(as, (int32_t)ir_knum(ir)->u32.lo, RSET_GPR), -+ RID_SP, 0); -+ emit_lso(as, ARMI_STR, -+ ra_allock(as, (int32_t)ir_knum(ir)->u32.hi, RSET_GPR), -+ RID_SP, 4); -+#else -+ Reg src = ra_alloc1(as, ref, RSET_FPR); -+ emit_dm(as, ARMI_MOV, dest, RID_SP); -+ emit_vlso(as, ARMI_VSTR_D, src, RID_SP, 0); -+#endif -+ } else if (irref_isk(ref)) { -+ /* Use the number constant itself as a TValue. */ -+ ra_allockreg(as, i32ptr(ir_knum(ir)), dest); -+ } else { -+#if LJ_SOFTFP -+ lj_assertA(0, "unsplit FP op"); -+#else -+ /* Otherwise force a spill and use the spill slot. */ -+ emit_opk(as, ARMI_ADD, dest, RID_SP, ra_spill(as, ir), RSET_GPR); -+#endif -+ } -+ } else { -+ /* Otherwise use [sp] and [sp+4] to hold the TValue. -+ ** This assumes the following call has max. 4 args. -+ */ -+ Reg type; -+ emit_dm(as, ARMI_MOV, dest, RID_SP); -+ if (!irt_ispri(ir->t)) { -+ Reg src = ra_alloc1(as, ref, RSET_GPR); -+ emit_lso(as, ARMI_STR, src, RID_SP, 0); -+ } -+ if (LJ_SOFTFP && (ir+1)->o == IR_HIOP && !irt_isnil((ir+1)->t)) -+ type = ra_alloc1(as, ref+1, RSET_GPR); -+ else -+ type = ra_allock(as, irt_toitype(ir->t), RSET_GPR); -+ emit_lso(as, ARMI_STR, type, RID_SP, 4); -+ } -+ } -+ else { -+ emit_dm(as, ARMI_MOV, dest, RID_SP); -+ } -+} -+ -+static void asm_aref(ASMState *as, IRIns *ir) -+{ -+ Reg dest = ra_dest(as, ir, RSET_GPR); -+ Reg idx, base; -+ if (irref_isk(ir->op2)) { -+ IRRef tab = IR(ir->op1)->op1; -+ int32_t ofs = asm_fuseabase(as, tab); -+ IRRef refa = ofs ? tab : ir->op1; -+ uint32_t k = emit_isk12(ARMI_ADD, ofs + 8*IR(ir->op2)->i); -+ if (k) { -+ base = ra_alloc1(as, refa, RSET_GPR); -+ emit_dn(as, ARMI_ADD ^ k, dest, base); -+ return; -+ } -+ } -+ base = ra_alloc1(as, ir->op1, RSET_GPR); -+ idx = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, base)); -+ emit_dnm(as, ARMI_ADD | ARMF_SH(ARMSH_LSL, 3), dest, base, idx); -+} -+ -+/* Inlined hash lookup. Specialized for key type and for const keys. -+** The equivalent C code is: -+** Node *n = hashkey(t, key); -+** do { -+** if (lj_obj_equal(&n->key, key)) return &n->val; -+** } while ((n = nextnode(n))); -+** return niltv(L); -+*/ -+static void asm_href(ASMState *as, IRIns *ir, IROp merge) -+{ -+ RegSet allow = RSET_GPR; -+ int destused = ra_used(ir); -+ Reg dest = ra_dest(as, ir, allow); -+ Reg tab = ra_alloc1(as, ir->op1, rset_clear(allow, dest)); -+ Reg key = 0, keyhi = 0, keynumhi = RID_NONE, tmp = RID_TMP; -+ IRRef refkey = ir->op2; -+ IRIns *irkey = IR(refkey); -+ IRType1 kt = irkey->t; -+ int32_t k = 0, khi = emit_isk12(ARMI_CMP, irt_toitype(kt)); -+ uint32_t khash; -+ MCLabel l_end, l_loop; -+ rset_clear(allow, tab); -+ if (!irref_isk(refkey) || irt_isstr(kt)) { -+#if LJ_SOFTFP -+ key = ra_alloc1(as, refkey, allow); -+ rset_clear(allow, key); -+ if (irkey[1].o == IR_HIOP) { -+ if (ra_hasreg((irkey + 1)->r)) { -+ keynumhi = (irkey + 1)->r; -+ keyhi = RID_TMP; -+ ra_noweak(as, keynumhi); -+ } -+ else { -+ keyhi = keynumhi = ra_allocref(as, refkey + 1, allow); -+ } -+ rset_clear(allow, keynumhi); -+ khi = 0; -+ } -+#else -+ if (irt_isnum(kt)) { -+ key = ra_scratch(as, allow); -+ rset_clear(allow, key); -+ keyhi = keynumhi = ra_scratch(as, allow); -+ rset_clear(allow, keyhi); -+ khi = 0; -+ } -+ else { -+ key = ra_alloc1(as, refkey, allow); -+ rset_clear(allow, key); -+ } -+#endif -+ } -+ else if (irt_isnum(kt)) { -+ int32_t val = (int32_t)ir_knum(irkey)->u32.lo; -+ k = emit_isk12(ARMI_CMP, val); -+ if (!k) { -+ key = ra_allock(as, val, allow); -+ rset_clear(allow, key); -+ } -+ val = (int32_t)ir_knum(irkey)->u32.hi; -+ khi = emit_isk12(ARMI_CMP, val); -+ if (!khi) { -+ keyhi = ra_allock(as, val, allow); -+ rset_clear(allow, keyhi); -+ } -+ } -+ else if (!irt_ispri(kt)) { -+ k = emit_isk12(ARMI_CMP, irkey->i); -+ if (!k) { -+ key = ra_alloc1(as, refkey, allow); -+ rset_clear(allow, key); -+ } -+ } -+ if (!irt_ispri(kt)) -+ tmp = ra_scratchpair(as, allow); -+ -+ /* Key not found in chain: jump to exit (if merged) or load niltv. */ -+ l_end = emit_label(as); -+ as->invmcp = NULL; -+ if (merge == IR_NE) -+ asm_guardcc(as, CC_AL); -+ else if (destused) -+ emit_loada(as, dest, niltvg(J2G(as->J))); -+ -+ /* Follow hash chain until the end. */ -+ l_loop = --as->mcp; -+ emit_n(as, ARMC_K12(ARMI_CMP, 0), dest); -+ emit_lso(as, ARMI_LDR, dest, dest, (int32_t)offsetof(Node, next)); -+ -+ /* Type and value comparison. */ -+ if (merge == IR_EQ) -+ asm_guardcc(as, CC_EQ); -+ else { -+ emit_branch(as, ARMF_CC(ARMI_B, CC_EQ), l_end); -+ } -+ if (!irt_ispri(kt)) { -+ emit_nm(as, ARMI_CMP ^ k, tmp, key); -+ ARMI_IT(CC_EQ); -+ emit_nm(as, ARMI_CMP ^ khi, tmp + 1, keyhi); -+ emit_lsox(as, ARMI_LDRD, tmp, dest, (int32_t)offsetof(Node, key)); -+ } -+ else { -+ emit_n(as, ARMI_CMP ^ khi, tmp); -+ emit_lso(as, ARMI_LDR, tmp, dest, (int32_t)offsetof(Node, key.it)); -+ } -+ *l_loop = ARMF_CC(ARMI_B, CC_NE) | ARMC_B((as->mcp - l_loop - 1) << 1); -+ -+ /* Load main position relative to tab->node into dest. */ -+ khash = irref_isk(refkey) ? ir_khash(as, irkey) : 1; -+ if (khash == 0) { -+ emit_lso(as, ARMI_LDR, dest, tab, (int32_t)offsetof(GCtab, node)); -+ } -+ else { -+ emit_dnm(as, ARMI_ADD | ARMF_SH(ARMSH_LSL, 3), dest, dest, tmp); -+ emit_dnm(as, ARMI_ADD | ARMF_SH(ARMSH_LSL, 1), tmp, tmp, tmp); -+ if (irt_isstr(kt)) { -+ /* Fetch of str->sid is cheaper than ra_allock. */ -+ emit_dnm(as, ARMI_AND, tmp, tmp + 1, RID_TMP); -+ emit_lso(as, ARMI_LDR, dest, tab, (int32_t)offsetof(GCtab, node)); -+ emit_lso(as, ARMI_LDR, tmp + 1, key, (int32_t)offsetof(GCstr, sid)); -+ emit_lso(as, ARMI_LDR, RID_TMP, tab, (int32_t)offsetof(GCtab, hmask)); -+ } -+ else if (irref_isk(refkey)) { -+ emit_opk(as, -+ ARMI_AND, -+ tmp, -+ RID_TMP, -+ (int32_t)khash, -+ rset_exclude(rset_exclude(RSET_GPR, tab), dest)); -+ emit_lso(as, ARMI_LDR, dest, tab, (int32_t)offsetof(GCtab, node)); -+ emit_lso(as, ARMI_LDR, RID_TMP, tab, (int32_t)offsetof(GCtab, hmask)); -+ } -+ else { -+ /* Must match with hash*() in lj_tab.c. */ -+ if (ra_hasreg(keynumhi)) { -+ /* Canonicalize +-0.0 to 0.0. */ -+ if (keyhi == RID_TMP) { -+ emit_dm(as, ARMI_MOV, keyhi, keynumhi); -+ ARMI_IT(CC_NE); -+ } -+ emit_d(as, ARMC_K12(ARMI_MOV, 0), keyhi); -+ ARMI_IT(CC_EQ); -+ } -+ emit_dnm(as, ARMI_AND, tmp, tmp, RID_TMP); -+ emit_dnm(as, ARMI_SUB | ARMF_SH(ARMSH_ROR, 32 - HASH_ROT3), tmp, tmp, tmp + 1); -+ emit_lso(as, ARMI_LDR, dest, tab, (int32_t)offsetof(GCtab, node)); -+ emit_dnm(as, -+ ARMI_EOR|ARMF_SH(ARMSH_ROR, 32 - ((HASH_ROT2 + HASH_ROT1) & 31)), -+ tmp, -+ tmp+1, -+ tmp); -+ emit_lso(as, ARMI_LDR, RID_TMP, tab, (int32_t)offsetof(GCtab, hmask)); -+ emit_dnm(as, ARMI_SUB | ARMF_SH(ARMSH_ROR, 32 - HASH_ROT1), tmp + 1, tmp + 1, tmp); -+ if (ra_hasreg(keynumhi)) { -+ emit_dnm(as, ARMI_EOR, tmp + 1, tmp, key); -+ emit_dnm(as, ARMI_ORR | ARMI_S, RID_TMP, tmp, key); /* Test for +-0.0. */ -+ emit_dnm(as, ARMI_ADD, tmp, keynumhi, keynumhi); -+#if !LJ_SOFTFP -+ emit_tnm(as, -+ ARMI_VMOV_RR_D, -+ key, -+ keynumhi, -+ (ra_alloc1(as, refkey, RSET_FPR) & 15)); -+#endif -+ } -+ else { -+ emit_dnm(as, ARMI_EOR, tmp + 1, tmp, key); -+ emit_opk(as, -+ ARMI_ADD, -+ tmp, -+ key, -+ (int32_t)HASH_BIAS, -+ rset_exclude(rset_exclude(RSET_GPR, tab), key)); -+ } -+ } -+ } -+} -+ -+static void asm_hrefk(ASMState *as, IRIns *ir) -+{ -+ IRIns *kslot = IR(ir->op2); -+ IRIns *irkey = IR(kslot->op1); -+ int32_t ofs = (int32_t)(kslot->op2 * sizeof(Node)); -+ int32_t kofs = ofs + (int32_t)offsetof(Node, key); -+ Reg dest = (ra_used(ir) || ofs > 4095) ? ra_dest(as, ir, RSET_GPR) : RID_NONE; -+ Reg node = ra_alloc1(as, ir->op1, RSET_GPR); -+ Reg key = RID_NONE, type = RID_TMP, idx = node; -+ RegSet allow = rset_exclude(RSET_GPR, node); -+ lj_assertA(ofs % sizeof(Node) == 0, "unaligned HREFK slot"); -+ if (ofs > 4095) { -+ idx = dest; -+ rset_clear(allow, dest); -+ kofs = (int32_t)offsetof(Node, key); -+ } -+ else if (ra_hasreg(dest)) { -+ emit_opk(as, ARMI_ADD, dest, node, ofs, allow); -+ } -+ asm_guardcc(as, CC_NE); -+ if (!irt_ispri(irkey->t)) { -+ RegSet even = (as->freeset & allow); -+ even = even & (even >> 1) & RSET_GPREVEN; -+ if (even) { -+ key = ra_scratch(as, even); -+ if (rset_test(as->freeset, key + 1)) { -+ type = key + 1; -+ ra_modified(as, type); -+ } -+ } -+ else { -+ key = ra_scratch(as, allow); -+ } -+ rset_clear(allow, key); -+ } -+ rset_clear(allow, type); -+ if (irt_isnum(irkey->t)) { -+ emit_opk(as, -+ ARMI_CMP, -+ 0, -+ type, -+ (int32_t)ir_knum(irkey)->u32.hi, -+ allow); -+ ARMI_IT(CC_EQ); -+ emit_opk(as, -+ ARMI_CMP, -+ 0, -+ key, -+ (int32_t)ir_knum(irkey)->u32.lo, -+ allow); -+ } -+ else { -+ if (ra_hasreg(key)) { -+ emit_opk(as, ARMI_CMP, 0, key, irkey->i, allow); -+ ARMI_IT(CC_EQ); -+ } -+ emit_n(as, ARMC_K12(ARMI_CMN, -irt_toitype(irkey->t)), type); -+ } -+ emit_lso(as, ARMI_LDR, type, idx, kofs + 4); -+ if (ra_hasreg(key)) emit_lso(as, ARMI_LDR, key, idx, kofs); -+ if (ofs > 4095) -+ emit_opk(as, ARMI_ADD, dest, node, ofs, RSET_GPR); -+} -+ -+static void asm_uref(ASMState *as, IRIns *ir) -+{ -+ Reg dest = ra_dest(as, ir, RSET_GPR); -+ if (irref_isk(ir->op1)) { -+ GCfunc *fn = ir_kfunc(IR(ir->op1)); -+ MRef *v = &gcref(fn->l.uvptr[(ir->op2 >> 8)])->uv.v; -+ emit_lsptr(as, ARMI_LDR, dest, v); -+ } -+ else { -+ Reg uv = ra_scratch(as, RSET_GPR); -+ Reg func = ra_alloc1(as, ir->op1, RSET_GPR); -+ if (ir->o == IR_UREFC) { -+ asm_guardcc(as, CC_NE); -+ emit_n(as, ARMC_K12(ARMI_CMP, 1), RID_TMP); -+ emit_opk(as, -+ ARMI_ADD, -+ dest, -+ uv, -+ (int32_t)offsetof(GCupval, tv), -+ RSET_GPR); -+ emit_lso(as, ARMI_LDRB, RID_TMP, uv, (int32_t)offsetof(GCupval, closed)); -+ } -+ else { -+ emit_lso(as, ARMI_LDR, dest, uv, (int32_t)offsetof(GCupval, v)); -+ } -+ emit_lso(as, -+ ARMI_LDR, -+ uv, -+ func, -+ (int32_t)offsetof(GCfuncL, uvptr) + 4*(int32_t)(ir->op2 >> 8)); -+ } -+} -+ -+static void asm_fref(ASMState *as, IRIns *ir) -+{ -+ UNUSED(as); UNUSED(ir); -+ lj_assertA(!ra_used(ir), "unfused FREF"); -+} -+ -+static void asm_strref(ASMState *as, IRIns *ir) -+{ -+ Reg dest = ra_dest(as, ir, RSET_GPR); -+ IRRef ref = ir->op2, refk = ir->op1; -+ Reg r; -+ if (irref_isk(ref)) { -+ IRRef tmp = refk; refk = ref; ref = tmp; -+ } -+ else if (!irref_isk(refk)) { -+ uint32_t k, m = ARMC_K12(0, sizeof(GCstr)); -+ Reg right, left = ra_alloc1(as, ir->op1, RSET_GPR); -+ IRIns *irr = IR(ir->op2); -+ if (ra_hasreg(irr->r)) { -+ ra_noweak(as, irr->r); -+ right = irr->r; -+ } -+ else if (mayfuse(as, irr->op2) && -+ irr->o == IR_ADD && irref_isk(irr->op2) && -+ (k = emit_isk12(ARMI_ADD, -+ (int32_t)sizeof(GCstr) + IR(irr->op2)->i))) { -+ m = k; -+ right = ra_alloc1(as, irr->op1, rset_exclude(RSET_GPR, left)); -+ } -+ else { -+ right = ra_allocref(as, ir->op2, rset_exclude(RSET_GPR, left)); -+ } -+ emit_dn(as, ARMI_ADD ^ m, dest, dest); -+ emit_dnm(as, ARMI_ADD, dest, left, right); -+ return; -+ } -+ r = ra_alloc1(as, ref, RSET_GPR); -+ emit_opk(as, -+ ARMI_ADD, -+ dest, -+ r, -+ sizeof(GCstr) + IR(refk)->i, -+ rset_exclude(RSET_GPR, r)); -+} -+ -+/* -- Loads and stores ---------------------------------------------------- */ -+ -+static ARMIns asm_fxloadins(ASMState *as, IRIns *ir) -+{ -+ UNUSED(as); -+ switch (irt_type(ir->t)) { -+ case IRT_I8: return ARMI_LDRSB; -+ case IRT_U8: return ARMI_LDRB; -+ case IRT_I16: return ARMI_LDRSH; -+ case IRT_U16: return ARMI_LDRH; -+ case IRT_NUM: lj_assertA(!LJ_SOFTFP, "unsplit FP op"); return ARMI_VLDR_D; -+ case IRT_FLOAT: if (!LJ_SOFTFP) return ARMI_VLDR_S; /* fallthrough */ -+ default: return ARMI_LDR; -+ } -+} -+ -+static ARMIns asm_fxstoreins(ASMState *as, IRIns *ir) -+{ -+ UNUSED(as); -+ switch (irt_type(ir->t)) { -+ case IRT_I8: case IRT_U8: return ARMI_STRB; -+ case IRT_I16: case IRT_U16: return ARMI_STRH; -+ case IRT_NUM: lj_assertA(!LJ_SOFTFP, "unsplit FP op"); return ARMI_VSTR_D; -+ case IRT_FLOAT: if (!LJ_SOFTFP) return ARMI_VSTR_S; /* fallthrough */ -+ default: return ARMI_STR; -+ } -+} -+ -+static void asm_fload(ASMState *as, IRIns *ir) -+{ -+ Reg dest = ra_dest(as, ir, RSET_GPR); -+ ARMIns ai = asm_fxloadins(as, ir); -+ Reg idx; -+ int32_t ofs; -+ if (ir->op1 == REF_NIL) { /* FLOAD from GG_State with offset. */ -+ idx = ra_allock(as, (int32_t)(ir->op2<<2) + (int32_t)J2GG(as->J), RSET_GPR); -+ ofs = 0; -+ } else { -+ idx = ra_alloc1(as, ir->op1, RSET_GPR); -+ if (ir->op2 == IRFL_TAB_ARRAY) { -+ ofs = asm_fuseabase(as, ir->op1); -+ if (ofs) { -+ /* Turn the t->array load into an add for colocated arrays. */ -+ emit_dn(as, ARMC_K12(ARMI_ADD, ofs), dest, idx); -+ return; -+ } -+ } -+ ofs = field_ofs[ir->op2]; -+ } -+ emit_lso(as, ai, dest, idx, ofs); -+} -+ -+static void asm_fstore(ASMState *as, IRIns *ir) -+{ -+ if (ir->r != RID_SINK) { -+ Reg src = ra_alloc1(as, ir->op2, RSET_GPR); -+ IRIns *irf = IR(ir->op1); -+ Reg idx = ra_alloc1(as, irf->op1, rset_exclude(RSET_GPR, src)); -+ int32_t ofs = field_ofs[irf->op2]; -+ ARMIns ai = asm_fxstoreins(as, ir); -+ emit_lso(as, ai, src, idx, ofs); -+ } -+} -+ -+static void asm_xload(ASMState *as, IRIns *ir) -+{ -+ Reg dest = ra_dest(as, -+ ir, -+ (!LJ_SOFTFP && irt_isfp(ir->t)) ? RSET_FPR : RSET_GPR); -+ lj_assertA(!(ir->op2 & IRXLOAD_UNALIGNED), "unaligned XLOAD"); -+ asm_fusexref(as, asm_fxloadins(as, ir), dest, ir->op1, RSET_GPR, 0); -+} -+ -+static void asm_xstore_(ASMState *as, IRIns *ir, int32_t ofs) -+{ -+ if (ir->r != RID_SINK) { -+ Reg src = ra_alloc1(as, -+ ir->op2, -+ (!LJ_SOFTFP && irt_isfp(ir->t)) ? RSET_FPR : RSET_GPR); -+ asm_fusexref(as, -+ asm_fxstoreins(as, ir), -+ src, -+ ir->op1, -+ rset_exclude(RSET_GPR, src), -+ ofs); -+ } -+} -+ -+#define asm_xstore(as, ir) asm_xstore_(as, ir, 0) -+ -+static void asm_ahuvload(ASMState *as, IRIns *ir) -+{ -+ int hiop = (LJ_SOFTFP && (ir + 1)->o == IR_HIOP); -+ IRType t = hiop ? IRT_NUM : irt_type(ir->t); -+ Reg dest = RID_NONE, type = RID_NONE, idx; -+ RegSet allow = RSET_GPR; -+ int32_t ofs = 0; -+ if (hiop && ra_used(ir + 1)) { -+ type = ra_dest(as, ir + 1, allow); -+ rset_clear(allow, type); -+ } -+ if (ra_used(ir)) { -+ lj_assertA((LJ_SOFTFP ? 0 : irt_isnum(ir->t)) || -+ irt_isint(ir->t) || irt_isaddr(ir->t), -+ "bad load type %d", irt_type(ir->t)); -+ dest = ra_dest(as, ir, (!LJ_SOFTFP && t == IRT_NUM) ? RSET_FPR : allow); -+ rset_clear(allow, dest); -+ } -+ idx = asm_fuseahuref(as, -+ ir->op1, -+ &ofs, -+ allow, -+ (!LJ_SOFTFP && t == IRT_NUM) ? 1024 : 4096); -+ if (ir->o == IR_VLOAD) ofs += 8 * ir->op2; -+ if (!hiop || type == RID_NONE) { -+ rset_clear(allow, idx); -+ if (ofs < 256 && ra_hasreg(dest) && (dest & 1) == 0 && -+ rset_test((as->freeset & allow), dest + 1)) { -+ type = dest + 1; -+ ra_modified(as, type); -+ } -+ else { -+ type = RID_TMP; -+ } -+ } -+ asm_guardcc(as, t == IRT_NUM ? CC_HS : CC_NE); -+ emit_n(as, ARMC_K12(ARMI_CMN, -irt_toitype_(t)), type); -+ if (ra_hasreg(dest)) { -+#if !LJ_SOFTFP -+ if (t == IRT_NUM) -+ emit_vlso(as, ARMI_VLDR_D, dest, idx, ofs); -+ else -+#endif -+ emit_lso(as, ARMI_LDR, dest, idx, ofs); -+ } -+ emit_lso(as, ARMI_LDR, type, idx, ofs + 4); -+} -+ -+static void asm_ahustore(ASMState *as, IRIns *ir) -+{ -+ if (ir->r != RID_SINK) { -+ RegSet allow = RSET_GPR; -+ Reg idx, src = RID_NONE, type = RID_NONE; -+ int32_t ofs = 0; -+#if !LJ_SOFTFP -+ if (irt_isnum(ir->t)) { -+ src = ra_alloc1(as, ir->op2, RSET_FPR); -+ idx = asm_fuseahuref(as, ir->op1, &ofs, allow, 1024); -+ emit_vlso(as, ARMI_VSTR_D, src, idx, ofs); -+ } -+ else -+#endif -+ { -+ int hiop = (LJ_SOFTFP && (ir + 1)->o == IR_HIOP); -+ if (!irt_ispri(ir->t)) { -+ src = ra_alloc1(as, ir->op2, allow); -+ rset_clear(allow, src); -+ } -+ if (hiop) -+ type = ra_alloc1(as, (ir + 1)->op2, allow); -+ else -+ type = ra_allock(as, (int32_t)irt_toitype(ir->t), allow); -+ idx = asm_fuseahuref(as, ir->op1, &ofs, rset_exclude(allow, type), 4096); -+ if (ra_hasreg(src)) emit_lso(as, ARMI_STR, src, idx, ofs); -+ emit_lso(as, ARMI_STR, type, idx, ofs + 4); -+ } -+ } -+} -+ -+static void asm_sload(ASMState *as, IRIns *ir) -+{ -+ int32_t ofs = 8*((int32_t)ir->op1 - 1) + ((ir->op2 & IRSLOAD_FRAME) ? 4 : 0); -+ int hiop = (LJ_SOFTFP && (ir + 1)->o == IR_HIOP); -+ IRType t = hiop ? IRT_NUM : irt_type(ir->t); -+ Reg dest = RID_NONE, type = RID_NONE, base; -+ RegSet allow = RSET_GPR; -+ lj_assertA(!(ir->op2 & IRSLOAD_PARENT), -+ "bad parent SLOAD"); /* Handled by asm_head_side(). */ -+ lj_assertA(irt_isguard(ir->t) || !(ir->op2 & IRSLOAD_TYPECHECK), -+ "inconsistent SLOAD variant"); -+#if LJ_SOFTFP -+ lj_assertA(!(ir->op2 & IRSLOAD_CONVERT), -+ "unsplit SLOAD convert"); /* Handled by LJ_SOFTFP SPLIT. */ -+ if (hiop && ra_used(ir + 1)) { -+ type = ra_dest(as, ir + 1, allow); -+ rset_clear(allow, type); -+ } -+#else -+ if ((ir->op2 & IRSLOAD_CONVERT) && irt_isguard(ir->t) && t == IRT_INT) { -+ dest = ra_scratch(as, RSET_FPR); -+ asm_tointg(as, ir, dest); -+ t = IRT_NUM; /* Continue with a regular number type check. */ -+ } -+ else -+#endif -+ if (ra_used(ir)) { -+ Reg tmp = RID_NONE; -+ if ((ir->op2 & IRSLOAD_CONVERT)) -+ tmp = ra_scratch(as, t == IRT_INT ? RSET_FPR : RSET_GPR); -+ lj_assertA((LJ_SOFTFP ? 0 : irt_isnum(ir->t)) || -+ irt_isint(ir->t) || irt_isaddr(ir->t), -+ "bad SLOAD type %d", irt_type(ir->t)); -+ dest = ra_dest(as, ir, (!LJ_SOFTFP && t == IRT_NUM) ? RSET_FPR : allow); -+ rset_clear(allow, dest); -+ base = ra_alloc1(as, REF_BASE, allow); -+ if ((ir->op2 & IRSLOAD_CONVERT)) { -+ if (t == IRT_INT) { -+ emit_tn(as, ARMI_VMOV_R_S, dest, (tmp & 15)); -+ emit_tm(as, ARMI_VCVT_S32_F64, (tmp & 15), (tmp & 15)); -+ t = IRT_NUM; /* Check for original type. */ -+ } -+ else { -+ emit_tm(as, ARMI_VCVT_F64_S32, (dest & 15), (dest & 15)); -+ emit_tn(as, ARMI_VMOV_S_R, tmp, (dest & 15)); -+ t = IRT_INT; /* Check for original type. */ -+ } -+ dest = tmp; -+ } -+ goto dotypecheck; -+ } -+ base = ra_alloc1(as, REF_BASE, allow); -+dotypecheck: -+ rset_clear(allow, base); -+ if ((ir->op2 & IRSLOAD_TYPECHECK)) { -+ if (ra_noreg(type)) { -+ if (ofs < 256 && ra_hasreg(dest) && (dest & 1) == 0 && -+ rset_test((as->freeset & allow), dest + 1)) { -+ type = dest + 1; -+ ra_modified(as, type); -+ } -+ else { -+ type = RID_TMP; -+ } -+ } -+ asm_guardcc(as, t == IRT_NUM ? CC_HS : CC_NE); -+ if ((ir->op2 & IRSLOAD_KEYINDEX)) { -+ emit_n(as, ARMC_K12(ARMI_CMN, 1), type); -+ emit_dn(as, ARMI_EOR^emit_isk12(ARMI_EOR, ~LJ_KEYINDEX), type, type); -+ } else { -+ emit_n(as, ARMC_K12(ARMI_CMN, -irt_toitype_(t)), type); -+ } -+ } -+ if (ra_hasreg(dest)) { -+#if !LJ_SOFTFP -+ if (t == IRT_NUM) { -+ if (ofs < 1024) { -+ emit_vlso(as, ARMI_VLDR_D, dest, base, ofs); -+ } -+ else { -+ if (ra_hasreg(type)) emit_lso(as, ARMI_LDR, type, base, ofs + 4); -+ emit_vlso(as, ARMI_VLDR_D, dest, RID_TMP, 0); -+ emit_opk(as, ARMI_ADD, RID_TMP, base, ofs, allow); -+ return; -+ } -+ } -+ else -+#endif -+ emit_lso(as, ARMI_LDR, dest, base, ofs); -+ } -+ if (ra_hasreg(type)) emit_lso(as, ARMI_LDR, type, base, ofs + 4); -+} -+ -+/* -- Allocations --------------------------------------------------------- */ -+ -+#if LJ_HASFFI -+static void asm_cnew(ASMState *as, IRIns *ir) -+{ -+ CTState *cts = ctype_ctsG(J2G(as->J)); -+ CTypeID id = (CTypeID)IR(ir->op1)->i; -+ CTSize sz; -+ CTInfo info = lj_ctype_info(cts, id, &sz); -+ const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_mem_newgco]; -+ IRRef args[4]; -+ RegSet allow = (RSET_GPR & ~RSET_SCRATCH); -+ RegSet drop = RSET_SCRATCH; -+ lj_assertA(sz != CTSIZE_INVALID || (ir->o == IR_CNEW && ir->op2 != REF_NIL), -+ "bad CNEW/CNEWI operands"); -+ -+ as->gcsteps++; -+ if (ra_hasreg(ir->r)) -+ rset_clear(drop, ir->r); /* Dest reg handled below. */ -+ ra_evictset(as, drop); -+ if (ra_used(ir)) -+ ra_destreg(as, ir, RID_RET); /* GCcdata * */ -+ -+ /* Initialize immutable cdata object. */ -+ if (ir->o == IR_CNEWI) { -+ int32_t ofs = sizeof(GCcdata); -+ lj_assertA(sz == 4 || sz == 8, "bad CNEWI size %d", sz); -+ if (sz == 8) { -+ ofs += 4; ir++; -+ lj_assertA(ir->o == IR_HIOP, "expected HIOP for CNEWI"); -+ } -+ for (;;) { -+ Reg r = ra_alloc1(as, ir->op2, allow); -+ emit_lso(as, ARMI_STR, r, RID_RET, ofs); -+ rset_clear(allow, r); -+ if (ofs == sizeof(GCcdata)) break; -+ ofs -= 4; ir--; -+ } -+ } -+ else if (ir->op2 != REF_NIL) { -+ /* Create VLA/VLS/aligned cdata. */ -+ ci = &lj_ir_callinfo[IRCALL_lj_cdata_newv]; -+ args[0] = ASMREF_L; /* lua_State *L */ -+ args[1] = ir->op1; /* CTypeID id */ -+ args[2] = ir->op2; /* CTSize sz */ -+ args[3] = ASMREF_TMP1; /* CTSize align */ -+ asm_gencall(as, ci, args); -+ emit_loadi(as, ra_releasetmp(as, ASMREF_TMP1), (int32_t)ctype_align(info)); -+ return; -+ } -+ -+ /* Initialize gct and ctypeid. lj_mem_newgco() already sets marked. */ -+ { -+ uint32_t k = emit_isk12(ARMI_MOV, id); -+ Reg r = k ? RID_R1 : ra_allock(as, id, allow); -+ emit_lso(as, ARMI_STRB, RID_TMP, RID_RET, offsetof(GCcdata, gct)); -+ emit_lso(as, ARMI_STRH, r, RID_RET, offsetof(GCcdata, ctypeid)); -+ emit_d(as, ARMC_K12(ARMI_MOV, ~LJ_TCDATA), RID_TMP); -+ if (k) emit_d(as, ARMI_MOV ^ k, RID_R1); -+ } -+ args[0] = ASMREF_L; /* lua_State *L */ -+ args[1] = ASMREF_TMP1; /* MSize size */ -+ asm_gencall(as, ci, args); -+ ra_allockreg(as, -+ (int32_t)(sz + sizeof(GCcdata)), -+ ra_releasetmp(as, ASMREF_TMP1)); -+} -+#endif -+ -+/* -- Write barriers ------------------------------------------------------ */ -+ -+static void asm_tbar(ASMState *as, IRIns *ir) -+{ -+ Reg tab = ra_alloc1(as, ir->op1, RSET_GPR); -+ Reg link = ra_scratch(as, rset_exclude(RSET_GPR, tab)); -+ Reg gr = ra_allock(as, -+ i32ptr(J2G(as->J)), -+ rset_exclude(rset_exclude(RSET_GPR, tab), link)); -+ Reg mark = RID_TMP; -+ MCLabel l_end = emit_label(as); -+ emit_lso(as, ARMI_STR, link, tab, (int32_t)offsetof(GCtab, gclist)); -+ emit_lso(as, ARMI_STRB, mark, tab, (int32_t)offsetof(GCtab, marked)); -+ emit_lso(as, -+ ARMI_STR, -+ tab, -+ gr, -+ (int32_t)offsetof(global_State, gc.grayagain)); -+ emit_dn(as, ARMC_K12(ARMI_BIC, LJ_GC_BLACK), mark, mark); -+ emit_lso(as, -+ ARMI_LDR, -+ link, -+ gr, -+ (int32_t)offsetof(global_State, gc.grayagain)); -+ emit_branch(as, ARMF_CC(ARMI_B, CC_EQ), l_end); -+ emit_n(as, ARMC_K12(ARMI_TST, LJ_GC_BLACK), mark); -+ emit_lso(as, ARMI_LDRB, mark, tab, (int32_t)offsetof(GCtab, marked)); -+} -+ -+static void asm_obar(ASMState *as, IRIns *ir) -+{ -+ const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_gc_barrieruv]; -+ IRRef args[2]; -+ MCLabel l_end; -+ Reg obj, val, tmp; -+ /* No need for other object barriers (yet). */ -+ lj_assertA(IR(ir->op1)->o == IR_UREFC, "bad OBAR type"); -+ ra_evictset(as, RSET_SCRATCH); -+ l_end = emit_label(as); -+ args[0] = ASMREF_TMP1; /* global_State *g */ -+ args[1] = ir->op1; /* TValue *tv */ -+ asm_gencall(as, ci, args); -+ //if ((l_end[-1] >> 28) == CC_AL) jturnsek!!! -+ // l_end[-1] = ARMF_CC(l_end[-1], CC_NE); -+ //else { -+ emit_branch(as, ARMF_CC(ARMI_B, CC_EQ), l_end); -+ //} -+ ra_allockreg(as, i32ptr(J2G(as->J)), ra_releasetmp(as, ASMREF_TMP1)); -+ obj = IR(ir->op1)->r; -+ tmp = ra_scratch(as, rset_exclude(RSET_GPR, obj)); -+ emit_n(as, ARMC_K12(ARMI_TST, LJ_GC_BLACK), tmp); -+ ARMI_IT(CC_NE); -+ emit_n(as, ARMC_K12(ARMI_TST, LJ_GC_WHITES), RID_TMP); -+ val = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, obj)); -+ emit_lso(as, -+ ARMI_LDRB, -+ tmp, -+ obj, -+ (int32_t)offsetof(GCupval, marked)-(int32_t)offsetof(GCupval, tv)); -+ emit_lso(as, ARMI_LDRB, RID_TMP, val, (int32_t)offsetof(GChead, marked)); -+} -+ -+/* -- Arithmetic and logic operations ------------------------------------- */ -+ -+#if !LJ_SOFTFP -+static void asm_fparith(ASMState *as, IRIns *ir, ARMIns ai) -+{ -+ Reg dest = ra_dest(as, ir, RSET_FPR); -+ Reg right, left = ra_alloc2(as, ir, RSET_FPR); -+ right = (left >> 8); left &= 255; -+ emit_tnm(as, ai, (dest & 15), (left & 15), (right & 15)); -+} -+ -+static void asm_fpunary(ASMState *as, IRIns *ir, ARMIns ai) -+{ -+ Reg dest = ra_dest(as, ir, RSET_FPR); -+ Reg left = ra_hintalloc(as, ir->op1, dest, RSET_FPR); -+ emit_tm(as, ai, (dest & 15), (left & 15)); -+} -+ -+static void asm_callround(ASMState *as, IRIns *ir, int id) -+{ -+ /* The modified regs must match with the *.dasc implementation. */ -+ RegSet drop = RID2RSET(RID_R0) | RID2RSET(RID_R1) | RID2RSET(RID_R2) | -+ RID2RSET(RID_R3) | RID2RSET(RID_R12); -+ RegSet of; -+ Reg dest, src; -+ ra_evictset(as, drop); -+ dest = ra_dest(as, ir, RSET_FPR); -+ emit_tnm(as, ARMI_VMOV_D_RR, RID_RETLO, RID_RETHI, (dest & 15)); -+ emit_call(as, -+ id == IRFPM_FLOOR ? (void *)lj_vm_floor_sf : -+ id == IRFPM_CEIL ? (void *)lj_vm_ceil_sf : -+ (void *)lj_vm_trunc_sf); -+ /* Workaround to protect argument GPRs from being used for remat. */ -+ of = as->freeset; -+ as->freeset &= ~RSET_RANGE(RID_R0, RID_R1 + 1); -+ as->cost[RID_R0] = as->cost[RID_R1] = REGCOST(~0u, ASMREF_L); -+ src = ra_alloc1(as, ir->op1, RSET_FPR); /* May alloc GPR to remat FPR. */ -+ as->freeset |= (of & RSET_RANGE(RID_R0, RID_R1 + 1)); -+ emit_tnm(as, ARMI_VMOV_RR_D, RID_R0, RID_R1, (src & 15)); -+} -+ -+static void asm_fpmath(ASMState *as, IRIns *ir) -+{ -+ if (ir->op2 <= IRFPM_TRUNC) -+ asm_callround(as, ir, ir->op2); -+ else if (ir->op2 == IRFPM_SQRT) -+ asm_fpunary(as, ir, ARMI_VSQRT_D); -+ else -+ asm_callid(as, ir, IRCALL_lj_vm_floor + ir->op2); -+} -+#endif -+ -+static int asm_swapops(ASMState *as, IRRef lref, IRRef rref) -+{ -+ IRIns *ir; -+ if (irref_isk(rref)) -+ return 0; /* Don't swap constants to the left. */ -+ if (irref_isk(lref)) -+ return 1; /* But swap constants to the right. */ -+ ir = IR(rref); -+ if ((ir->o >= IR_BSHL && ir->o <= IR_BROR) || -+ (ir->o == IR_ADD && ir->op1 == ir->op2)) -+ return 0; /* Don't swap fusable operands to the left. */ -+ ir = IR(lref); -+ if ((ir->o >= IR_BSHL && ir->o <= IR_BROR) || -+ (ir->o == IR_ADD && ir->op1 == ir->op2)) -+ return 1; /* But swap fusable operands to the right. */ -+ return 0; /* Otherwise don't swap. */ -+} -+ -+static void asm_intop(ASMState *as, IRIns *ir, ARMIns ai) -+{ -+ IRRef lref = ir->op1, rref = ir->op2; -+ Reg left, dest = ra_dest(as, ir, RSET_GPR); -+ uint32_t m, rs = 0; -+ if (asm_swapops(as, lref, rref)) { -+ IRRef tmp = lref; lref = rref; rref = tmp; -+ if ((ai & ~ARMI_S) == ARMI_SUB || (ai & ~ARMI_S) == ARMI_SBC) -+ ai ^= (ARMI_SUB ^ ARMI_RSB); -+ } -+ left = ra_hintalloc(as, lref, dest, RSET_GPR); -+ m = asm_fuseopm(as, ai, rref, rset_exclude(RSET_GPR, left), &rs); -+ if (irt_isguard(ir->t)) { -+ /* For IR_ADDOV etc. */ -+ asm_guardcc(as, CC_VS); -+ ai |= ARMI_S; -+ } -+ emit_dn(as, ai ^ m, dest, left); -+ if (rs) -+ emit_dn(as, (ARMI_MOV ^ 0x0000104f) | rs, (m >> 16), (m >> 16)); -+} -+ -+/* Try to drop cmp r, #0. */ -+static ARMIns asm_drop_cmp0(ASMState *as, ARMIns ai) //jturnsek!!! -+{ -+ if (as->flagmcp == as->mcp) { -+ uint32_t cc = ((as->mcp[1] >> 20) & 0xf); -+ as->flagmcp = NULL; -+ if (cc <= CC_NE) { -+ as->mcp++; -+ ai |= ARMI_S; -+ } -+ else if (cc == CC_GE) { -+ * ++as->mcp ^= ((CC_GE ^ CC_PL) << 20); -+ ai |= ARMI_S; -+ } -+ else if (cc == CC_LT) { -+ * ++as->mcp ^= ((CC_LT ^ CC_MI) << 20); -+ ai |= ARMI_S; -+ } /* else: other conds don't work in general. */ -+ } -+ return ai; -+} -+ -+static void asm_intop_s(ASMState *as, IRIns *ir, ARMIns ai) -+{ -+ asm_intop(as, ir, asm_drop_cmp0(as, ai)); -+} -+ -+static void asm_intneg(ASMState *as, IRIns *ir, ARMIns ai) -+{ -+ Reg dest = ra_dest(as, ir, RSET_GPR); -+ Reg left = ra_hintalloc(as, ir->op1, dest, RSET_GPR); -+ emit_dn(as, ARMC_K12(ai, 0), dest, left); -+} -+ -+/* NYI: use add/shift for MUL(OV) with constants. FOLD only does 2^k. */ -+static void asm_intmul(ASMState *as, IRIns *ir) -+{ -+ Reg dest = ra_dest(as, ir, RSET_GPR); -+ Reg left = ra_alloc1(as, ir->op1, rset_exclude(RSET_GPR, dest)); -+ Reg right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left)); -+ Reg tmp = RID_NONE; -+ /* ARMv5 restriction: dest != left and dest_hi != left. */ -+ if (dest == left && left != right) { left = right; right = dest; } -+ if (irt_isguard(ir->t)) { -+ /* IR_MULOV */ -+ if (!(as->flags & JIT_F_ARMV6) && dest == left) -+ tmp = left = ra_scratch(as, rset_exclude(RSET_GPR, left)); -+ asm_guardcc(as, CC_NE); -+ emit_nm(as, ARMI_TEQ | ARMF_SH(ARMSH_ASR, 31), RID_TMP, dest); -+ emit_dnm(as, ARMI_SMULL | ARMF_T(dest), RID_TMP, left, right); -+ } -+ else { -+ if (!(as->flags & JIT_F_ARMV6) && dest == left) tmp = left = RID_TMP; -+ emit_dnm(as, ARMI_MUL, dest, left, right); -+ } -+ /* Only need this for the dest == left == right case. */ -+ if (ra_hasreg(tmp)) emit_dm(as, ARMI_MOV, tmp, right); -+} -+ -+static void asm_add(ASMState *as, IRIns *ir) -+{ -+#if !LJ_SOFTFP -+ if (irt_isnum(ir->t)) { -+ if (!asm_fusemadd(as, ir, ARMI_VMLA_D, ARMI_VMLA_D)) -+ asm_fparith(as, ir, ARMI_VADD_D); -+ return; -+ } -+#endif -+ asm_intop_s(as, ir, ARMI_ADD); -+} -+ -+static void asm_sub(ASMState *as, IRIns *ir) -+{ -+#if !LJ_SOFTFP -+ if (irt_isnum(ir->t)) { -+ if (!asm_fusemadd(as, ir, ARMI_VNMLS_D, ARMI_VMLS_D)) -+ asm_fparith(as, ir, ARMI_VSUB_D); -+ return; -+ } -+#endif -+ asm_intop_s(as, ir, ARMI_SUB); -+} -+ -+static void asm_mul(ASMState *as, IRIns *ir) -+{ -+#if !LJ_SOFTFP -+ if (irt_isnum(ir->t)) { -+ asm_fparith(as, ir, ARMI_VMUL_D); -+ return; -+ } -+#endif -+ asm_intmul(as, ir); -+} -+ -+#define asm_addov(as, ir) asm_add(as, ir) -+#define asm_subov(as, ir) asm_sub(as, ir) -+#define asm_mulov(as, ir) asm_mul(as, ir) -+ -+#if !LJ_SOFTFP -+#define asm_fpdiv(as, ir) asm_fparith(as, ir, ARMI_VDIV_D) -+#define asm_abs(as, ir) asm_fpunary(as, ir, ARMI_VABS_D) -+#endif -+ -+static void asm_neg(ASMState *as, IRIns *ir) -+{ -+#if !LJ_SOFTFP -+ if (irt_isnum(ir->t)) { -+ asm_fpunary(as, ir, ARMI_VNEG_D); -+ return; -+ } -+#endif -+ asm_intneg(as, ir, ARMI_RSB); -+} -+ -+static void asm_bitop(ASMState *as, IRIns *ir, ARMIns ai) -+{ -+ ai = asm_drop_cmp0(as, ai); -+ if (ir->op2 == 0) { -+ Reg dest = ra_dest(as, ir, RSET_GPR); -+ uint32_t rs = 0; -+ uint32_t m = asm_fuseopm(as, ai, ir->op1, RSET_GPR, &rs); -+ emit_d(as, ai ^ m, dest); -+ if (rs) -+ emit_dn(as, (ARMI_MOV ^ 0x0000104f) | rs, (m >> 16), (m >> 16)); -+ } -+ else { -+ /* NYI: Turn BAND !k12 into uxtb, uxth or bfc or shl+shr. */ -+ asm_intop(as, ir, ai); -+ } -+} -+ -+#define asm_bnot(as, ir) asm_bitop(as, ir, ARMI_MVN) -+ -+static void asm_bswap(ASMState *as, IRIns *ir) -+{ -+ Reg dest = ra_dest(as, ir, RSET_GPR); -+ Reg left = ra_alloc1(as, ir->op1, RSET_GPR); -+ if ((as->flags & JIT_F_ARMV6)) { -+ emit_dnm(as, ARMI_REV, dest, left, left); -+ } -+ else { -+ Reg tmp2 = dest; -+ if (tmp2 == left) -+ tmp2 = ra_scratch(as, rset_exclude(rset_exclude(RSET_GPR, dest), left)); -+ emit_dnm(as, ARMI_EOR | ARMF_SH(ARMSH_LSR, 8), dest, tmp2, RID_TMP); -+ emit_dm(as, ARMI_MOV | ARMF_SH(ARMSH_ROR, 8), tmp2, left); -+ emit_dn(as, ARMC_K12(ARMI_BIC, 256 * 8 | 127), RID_TMP, RID_TMP); -+ emit_dnm(as, ARMI_EOR | ARMF_SH(ARMSH_ROR, 16), RID_TMP, left, left); -+ } -+} -+ -+#define asm_band(as, ir) asm_bitop(as, ir, ARMI_AND) -+#define asm_bor(as, ir) asm_bitop(as, ir, ARMI_ORR) -+#define asm_bxor(as, ir) asm_bitop(as, ir, ARMI_EOR) -+ -+static void asm_bitshift(ASMState *as, IRIns *ir, ARMShift sh) -+{ -+ if (irref_isk(ir->op2)) { -+ /* Constant shifts. */ -+ /* NYI: Turn SHL+SHR or BAND+SHR into uxtb, uxth or ubfx. */ -+ /* NYI: Turn SHL+ASR into sxtb, sxth or sbfx. */ -+ Reg dest = ra_dest(as, ir, RSET_GPR); -+ Reg left = ra_alloc1(as, ir->op1, RSET_GPR); -+ int32_t shift = (IR(ir->op2)->i & 31); -+ emit_dm(as, ARMI_MOV | ARMF_SH(sh, shift), dest, left); -+ } -+ else { -+ Reg dest = ra_dest(as, ir, RSET_GPR); -+ Reg left = ra_alloc1(as, ir->op1, RSET_GPR); -+ Reg right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left)); -+ emit_dn(as, (ARMI_MOV ^ 0x0000104f) | ARMF_RSH(sh, right), dest, left); -+ } -+} -+ -+#define asm_bshl(as, ir) asm_bitshift(as, ir, ARMSH_LSL) -+#define asm_bshr(as, ir) asm_bitshift(as, ir, ARMSH_LSR) -+#define asm_bsar(as, ir) asm_bitshift(as, ir, ARMSH_ASR) -+#define asm_bror(as, ir) asm_bitshift(as, ir, ARMSH_ROR) -+#define asm_brol(as, ir) lj_assertA(0, "unexpected BROL") -+ -+static void asm_intmin_max(ASMState *as, IRIns *ir, int cc) -+{ -+ uint32_t kcmp = 0, kmov = 0; -+ Reg dest = ra_dest(as, ir, RSET_GPR); -+ Reg left = ra_hintalloc(as, ir->op1, dest, RSET_GPR); -+ Reg right = 0; -+ if (irref_isk(ir->op2)) { -+ kcmp = emit_isk12(ARMI_CMP, IR(ir->op2)->i); -+ if (kcmp) kmov = emit_isk12(ARMI_MOV, IR(ir->op2)->i); -+ } -+ if (!kmov) { -+ kcmp = 0; -+ right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left)); -+ } -+ if (kmov || dest != right) { -+ emit_dm(as, ARMI_MOV ^ kmov, dest, right); -+ ARMI_IT(cc); -+ cc ^= 1; /* Must use opposite conditions for paired moves. */ -+ } -+ else { -+ cc ^= (CC_LT ^ CC_GT); /* Otherwise may swap CC_LT <-> CC_GT. */ -+ } -+ if (dest != left) { -+ emit_dm(as, ARMI_MOV, dest, left); -+ ARMI_IT(cc); -+ } -+ emit_nm(as, ARMI_CMP ^ kcmp, left, right); -+} -+ -+#if LJ_SOFTFP -+static void asm_sfpmin_max(ASMState *as, IRIns *ir, int cc) -+{ -+ const CCallInfo *ci = &lj_ir_callinfo[IRCALL_softfp_cmp]; -+ RegSet drop = RSET_SCRATCH; -+ Reg r; -+ IRRef args[4]; -+ args[0] = ir->op1; args[1] = (ir + 1)->op1; -+ args[2] = ir->op2; args[3] = (ir + 1)->op2; -+ /* __aeabi_cdcmple preserves r0-r3. */ -+ if (ra_hasreg(ir->r)) rset_clear(drop, ir->r); -+ if (ra_hasreg((ir + 1)->r)) rset_clear(drop, (ir + 1)->r); -+ if (!rset_test(as->freeset, RID_R2) && -+ regcost_ref(as->cost[RID_R2]) == args[2]) rset_clear(drop, RID_R2); -+ if (!rset_test(as->freeset, RID_R3) && -+ regcost_ref(as->cost[RID_R3]) == args[3]) rset_clear(drop, RID_R3); -+ ra_evictset(as, drop); -+ ra_destpair(as, ir); -+ emit_dm(as, ARMI_MOV, RID_RETHI, RID_R3); -+ ARMI_IT(cc); -+ emit_dm(as, ARMI_MOV, RID_RETLO, RID_R2); -+ ARMI_IT(cc); -+ emit_call(as, (void *)ci->func); -+ for (r = RID_R0; r <= RID_R3; r++) -+ ra_leftov(as, r, args[r - RID_R0]); -+} -+#else -+static void asm_fpmin_max(ASMState *as, IRIns *ir, int cc) -+{ -+ Reg dest = (ra_dest(as, ir, RSET_FPR) & 15); -+ Reg right, left = ra_alloc2(as, ir, RSET_FPR); -+ right = ((left >> 8) & 15); left &= 15; -+ if (dest != left) { -+ emit_tm(as, ARMI_VMOV_D, dest, left); -+ ARMI_IT(cc ^ 1); -+ } -+ if (dest != right) { -+ emit_tm(as, ARMI_VMOV_D, dest, right); -+ ARMI_IT(cc); -+ } -+ emit_t(as, ARMI_VMRS, 0); -+ emit_tm(as, ARMI_VCMP_D, left, right); -+} -+#endif -+ -+static void asm_min_max(ASMState *as, IRIns *ir, int cc, int fcc) -+{ -+#if LJ_SOFTFP -+ UNUSED(fcc); -+#else -+ if (irt_isnum(ir->t)) -+ asm_fpmin_max(as, ir, fcc); -+ else -+#endif -+ asm_intmin_max(as, ir, cc); -+} -+ -+#define asm_min(as, ir) asm_min_max(as, ir, CC_GT, CC_PL) -+#define asm_max(as, ir) asm_min_max(as, ir, CC_LT, CC_LE) -+ -+/* -- Comparisons --------------------------------------------------------- */ -+ -+/* Map of comparisons to flags. ORDER IR. */ -+static const uint8_t asm_compmap[IR_ABC + 1] = { -+ /* op FP swp int cc FP cc */ -+ /* LT */ CC_GE + (CC_HS << 4), -+ /* GE x */ CC_LT + (CC_HI << 4), -+ /* LE */ CC_GT + (CC_HI << 4), -+ /* GT x */ CC_LE + (CC_HS << 4), -+ /* ULT x */ CC_HS + (CC_LS << 4), -+ /* UGE */ CC_LO + (CC_LO << 4), -+ /* ULE x */ CC_HI + (CC_LO << 4), -+ /* UGT */ CC_LS + (CC_LS << 4), -+ /* EQ */ CC_NE + (CC_NE << 4), -+ /* NE */ CC_EQ + (CC_EQ << 4), -+ /* ABC */ CC_LS + (CC_LS << 4) /* Same as UGT. */ -+}; -+ -+#if LJ_SOFTFP -+/* FP comparisons. */ -+static void asm_sfpcomp(ASMState *as, IRIns *ir) -+{ -+ const CCallInfo *ci = &lj_ir_callinfo[IRCALL_softfp_cmp]; -+ RegSet drop = RSET_SCRATCH; -+ Reg r; -+ IRRef args[4]; -+ int swp = (((ir->o ^ (ir->o >> 2)) & ~(ir->o >> 3) & 1) << 1); -+ args[swp ^ 0] = ir->op1; args[swp ^ 1] = (ir + 1)->op1; -+ args[swp ^ 2] = ir->op2; args[swp ^ 3] = (ir + 1)->op2; -+ /* __aeabi_cdcmple preserves r0-r3. This helps to reduce spills. */ -+ for (r = RID_R0; r <= RID_R3; r++) -+ if (!rset_test(as->freeset, r) && -+ regcost_ref(as->cost[r]) == args[r - RID_R0]) rset_clear(drop, r); -+ ra_evictset(as, drop); -+ asm_guardcc(as, (asm_compmap[ir->o] >> 4)); -+ emit_call(as, (void *)ci->func); -+ for (r = RID_R0; r <= RID_R3; r++) -+ ra_leftov(as, r, args[r - RID_R0]); -+} -+#else -+/* FP comparisons. */ -+static void asm_fpcomp(ASMState *as, IRIns *ir) -+{ -+ Reg left, right; -+ ARMIns ai; -+ int swp = ((ir->o ^ (ir->o >> 2)) & ~(ir->o >> 3) & 1); -+ if (!swp && irref_isk(ir->op2) && ir_knum(IR(ir->op2))->u64 == 0) { -+ left = (ra_alloc1(as, ir->op1, RSET_FPR) & 15); -+ right = 0; -+ ai = ARMI_VCMPZ_D; -+ } -+ else { -+ left = ra_alloc2(as, ir, RSET_FPR); -+ if (swp) { -+ right = (left & 15); left = ((left >> 8) & 15); -+ } -+ else { -+ right = ((left >> 8) & 15); left &= 15; -+ } -+ ai = ARMI_VCMP_D; -+ } -+ asm_guardcc(as, (asm_compmap[ir->o] >> 4)); -+ emit_t(as, ARMI_VMRS, 0); -+ emit_tm(as, ai, left, right); -+} -+#endif -+ -+/* Integer comparisons. */ -+static void asm_intcomp(ASMState *as, IRIns *ir) -+{ -+ ARMCC cc = (asm_compmap[ir->o] & 15); -+ IRRef lref = ir->op1, rref = ir->op2; -+ Reg left; -+ uint32_t m, rs = 0; -+ int cmpprev0 = 0; -+ lj_assertA(irt_isint(ir->t) || irt_isu32(ir->t) || irt_isaddr(ir->t), -+ "bad comparison data type %d", irt_type(ir->t)); -+ if (asm_swapops(as, lref, rref)) { -+ Reg tmp = lref; lref = rref; rref = tmp; -+ if (cc >= CC_GE) cc ^= 7; /* LT <-> GT, LE <-> GE */ -+ else if(cc > CC_NE) cc ^= 11; /* LO <-> HI, LS <-> HS */ -+ } -+ if (irref_isk(rref) && IR(rref)->i == 0) { -+ IRIns *irl = IR(lref); -+ cmpprev0 = (irl + 1 == ir); -+ /* Combine comp(BAND(left, right), 0) into tst left, right. */ -+ if (cmpprev0 && irl->o == IR_BAND && !ra_used(irl)) { -+ IRRef blref = irl->op1, brref = irl->op2; -+ uint32_t m2 = 0; -+ Reg bleft; -+ if (asm_swapops(as, blref, brref)) { -+ Reg tmp = blref; blref = brref; brref = tmp; -+ } -+ if (irref_isk(brref)) { -+ m2 = emit_isk12(ARMI_AND, IR(brref)->i); -+ if ((m2 & (ARMI_AND ^ ARMI_BIC))) -+ goto notst; /* Not beneficial if we miss a constant operand. */ -+ } -+ if (cc == CC_GE) cc = CC_PL; -+ else if (cc == CC_LT) cc = CC_MI; -+ else if (cc > CC_NE) goto notst; /* Other conds don't work with tst. */ -+ bleft = ra_alloc1(as, blref, RSET_GPR); -+ if (!m2) m2 = asm_fuseopm(as, 0, brref, rset_exclude(RSET_GPR, bleft), &rs); -+ asm_guardcc(as, cc); -+ emit_n(as, ARMI_TST ^ m2, bleft); -+ if (rs) -+ emit_dn(as, (ARMI_MOV ^ 0x0000104f) | rs, (m2 >> 16), (m2 >> 16)); -+ return; -+ } -+ } -+notst: -+ left = ra_alloc1(as, lref, RSET_GPR); -+ m = asm_fuseopm(as, ARMI_CMP, rref, rset_exclude(RSET_GPR, left), &rs); -+ asm_guardcc(as, cc); -+ emit_n(as, ARMI_CMP ^ m, left); -+ if (rs) -+ emit_dn(as, (ARMI_MOV ^ 0x0000104f) | rs, (m >> 16), (m >> 16)); -+ /* Signed comparison with zero and referencing previous ins? */ -+ if (cmpprev0 && (cc <= CC_NE || cc >= CC_GE)) -+ as->flagmcp = as->mcp; /* Allow elimination of the compare. */ -+} -+ -+static void asm_comp(ASMState *as, IRIns *ir) -+{ -+#if !LJ_SOFTFP -+ if (irt_isnum(ir->t)) -+ asm_fpcomp(as, ir); -+ else -+#endif -+ asm_intcomp(as, ir); -+} -+ -+#define asm_equal(as, ir) asm_comp(as, ir) -+ -+#if LJ_HASFFI -+/* 64 bit integer comparisons. */ -+static void asm_int64comp(ASMState *as, IRIns *ir) -+{ -+ int signedcomp = (ir->o <= IR_GT); -+ ARMCC cclo, cchi; -+ Reg leftlo, lefthi; -+ uint32_t mlo, mhi, rslo = 0, rshi = 0; -+ RegSet allow = RSET_GPR, oldfree; -+ -+ /* Always use unsigned comparison for loword. */ -+ cclo = asm_compmap[ir->o + (signedcomp ? 4 : 0)] & 15; -+ leftlo = ra_alloc1(as, ir->op1, allow); -+ oldfree = as->freeset; -+ mlo = asm_fuseopm(as, ARMI_CMP, ir->op2, rset_clear(allow, leftlo), &rslo); -+ allow &= ~(oldfree & ~as->freeset); /* Update for allocs of asm_fuseopm. */ -+ -+ /* Use signed or unsigned comparison for hiword. */ -+ cchi = asm_compmap[ir->o] & 15; -+ lefthi = ra_alloc1(as, (ir + 1)->op1, allow); -+ mhi = asm_fuseopm(as, ARMI_CMP, (ir + 1)->op2, rset_clear(allow, lefthi), &rshi); -+ -+ /* All register allocations must be performed _before_ this point. */ -+ if (signedcomp) { -+ MCLabel l_around = emit_label(as); -+ asm_guardcc(as, cclo); -+ emit_n(as, ARMI_CMP ^ mlo, leftlo); -+ if (rslo) -+ emit_dn(as, (ARMI_MOV ^ 0x0000104f) | rslo, (mlo >> 16), (mlo >> 16)); -+ emit_branch(as, ARMF_CC(ARMI_B, CC_NE), l_around); -+ if (cchi == CC_GE || cchi == CC_LE) cchi ^= 6; /* GE -> GT, LE -> LT */ -+ asm_guardcc(as, cchi); -+ } -+ else { -+ asm_guardcc(as, cclo); -+ emit_n(as, ARMI_CMP ^ mlo, leftlo); -+ if (rslo) -+ emit_dn(as, (ARMI_MOV ^ 0x0000104f) | rslo, (mlo >> 16), (mlo >> 16)); -+ ARMI_IT(CC_EQ); -+ } -+ emit_n(as, ARMI_CMP ^ mhi, lefthi); -+ if (rshi) -+ emit_dn(as, (ARMI_MOV ^ 0x0000104f) | rshi, (mhi >> 16), (mhi >> 16)); -+} -+#endif -+ -+/* -- Split register ops -------------------------------------------------- */ -+ -+/* Hiword op of a split 32/32 bit op. Previous op is the loword op. */ -+static void asm_hiop(ASMState *as, IRIns *ir) -+{ -+ /* HIOP is marked as a store because it needs its own DCE logic. */ -+ int uselo = ra_used(ir - 1), usehi = ra_used(ir); /* Loword/hiword used? */ -+ if (LJ_UNLIKELY(!(as->flags & JIT_F_OPT_DCE))) uselo = usehi = 1; -+#if LJ_HASFFI || LJ_SOFTFP -+ if ((ir - 1)->o <= IR_NE) { -+ /* 64 bit integer or FP comparisons. ORDER IR. */ -+ as->curins--; /* Always skip the loword comparison. */ -+#if LJ_SOFTFP -+ if (!irt_isint(ir->t)) { -+ asm_sfpcomp(as, ir - 1); -+ return; -+ } -+#endif -+#if LJ_HASFFI -+ asm_int64comp(as, ir - 1); -+#endif -+ return; -+#if LJ_SOFTFP -+ } -+ else if ((ir - 1)->o == IR_MIN || (ir - 1)->o == IR_MAX) { -+ as->curins--; /* Always skip the loword min/max. */ -+ if (uselo || usehi) -+ asm_sfpmin_max(as, ir - 1, (ir - 1)->o == IR_MIN ? CC_PL : CC_LE); -+ return; -+#elif LJ_HASFFI -+ } -+ else if ((ir - 1)->o == IR_CONV) { -+ as->curins--; /* Always skip the CONV. */ -+ if (usehi || uselo) -+ asm_conv64(as, ir); -+ return; -+#endif -+ } -+ else if ((ir - 1)->o == IR_XSTORE) { -+ if ((ir - 1)->r != RID_SINK) -+ asm_xstore_(as, ir, 4); -+ return; -+ } -+#endif -+ if (!usehi) return; /* Skip unused hiword op for all remaining ops. */ -+ switch ((ir - 1)->o) { -+#if LJ_HASFFI -+ case IR_ADD: -+ as->curins--; -+ asm_intop(as, ir, ARMI_ADC); -+ asm_intop(as, ir - 1, ARMI_ADD | ARMI_S); -+ break; -+ case IR_SUB: -+ as->curins--; -+ asm_intop(as, ir, ARMI_SBC); -+ asm_intop(as, ir - 1, ARMI_SUB | ARMI_S); -+ break; -+ case IR_NEG: -+ as->curins--; -+ { -+ /* asm_intnegr */ -+ Reg dest = ra_dest(as, ir, RSET_GPR); -+ Reg left = ra_hintalloc(as, ir->op1, dest, RSET_GPR); -+ emit_dn(as, ARMC_K12(ARMI_SBC, 0), left, dest); -+ } -+ asm_intneg(as, ir - 1, ARMI_RSB | ARMI_S); -+ break; -+ case IR_CNEWI: -+ /* Nothing to do here. Handled by lo op itself. */ -+ break; -+#endif -+#if LJ_SOFTFP -+ case IR_SLOAD: case IR_ALOAD: case IR_HLOAD: case IR_ULOAD: case IR_VLOAD: -+ case IR_STRTO: -+ if (!uselo) -+ ra_allocref(as, ir->op1, RSET_GPR); /* Mark lo op as used. */ -+ break; -+ case IR_ASTORE: case IR_HSTORE: case IR_USTORE: case IR_TOSTR: case IR_TMPREF: -+ /* Nothing to do here. Handled by lo op itself. */ -+ break; -+#endif -+ case IR_CALLN: case IR_CALLL: case IR_CALLS: case IR_CALLXS: -+ if (!uselo) -+ ra_allocref(as, ir->op1, RID2RSET(RID_RETLO)); /* Mark lo op as used. */ -+ break; -+ default: lj_assertA(0, "bad HIOP for op %d", (ir-1)->o); break; -+ } -+} -+ -+/* -- Profiling ----------------------------------------------------------- */ -+ -+static void asm_prof(ASMState *as, IRIns *ir) -+{ -+ UNUSED(ir); -+ asm_guardcc(as, CC_NE); -+ emit_n(as, ARMC_K12(ARMI_TST, HOOK_PROFILE), RID_TMP); -+ emit_lsptr(as, ARMI_LDRB, RID_TMP, (void *)&J2G(as->J)->hookmask); -+} -+ -+/* -- Stack handling ------------------------------------------------------ */ -+ -+/* Check Lua stack size for overflow. Use exit handler as fallback. */ -+static void asm_stack_check(ASMState *as, -+ BCReg topslot, -+ IRIns *irp, -+ RegSet allow, -+ ExitNo exitno) -+{ -+ Reg pbase; -+ uint32_t k; -+ if (irp) { -+ if (!ra_hasspill(irp->s)) { -+ pbase = irp->r; -+ lj_assertA(ra_hasreg(pbase), "base reg lost"); -+ } -+ else if (allow) { -+ pbase = rset_pickbot(allow); -+ } -+ else { -+ pbase = RID_RET; -+ emit_lso(as, ARMI_LDR, RID_RET, RID_SP, 0); /* Restore temp. register. */ -+ } -+ } -+ else { -+ pbase = RID_BASE; -+ } -+ emit_branchlink(as, ARMI_BL, exitstub_addr(as->J, exitno)); -+ ARMI_IT(CC_LS); -+ k = emit_isk12(0, (int32_t)(8*topslot)); -+ lj_assertA(k, "slot offset %d does not fit in K12", 8*topslot); -+ emit_n(as, ARMI_CMP ^ k, RID_TMP); -+ emit_dnm(as, ARMI_SUB, RID_TMP, RID_TMP, pbase); -+ emit_lso(as, -+ ARMI_LDR, -+ RID_TMP, -+ RID_TMP, -+ (int32_t)offsetof(lua_State, maxstack)); -+ if (irp) { -+ /* Must not spill arbitrary registers in head of side trace. */ -+ int32_t i = i32ptr(&J2G(as->J)->cur_L); -+ if (ra_hasspill(irp->s)) -+ emit_lso(as, ARMI_LDR, pbase, RID_SP, sps_scale(irp->s)); -+ emit_lso(as, ARMI_LDR, RID_TMP, RID_TMP, (i & 4095)); -+ if (ra_hasspill(irp->s) && !allow) -+ emit_lso(as, ARMI_STR, RID_RET, RID_SP, 0); /* Save temp. register. */ -+ emit_loadi(as, RID_TMP, (i & ~4095)); -+ } -+ else { -+ emit_getgl(as, RID_TMP, cur_L); -+ } -+} -+ -+/* Restore Lua stack from on-trace state. */ -+static void asm_stack_restore(ASMState *as, SnapShot *snap) -+{ -+ SnapEntry *map = &as->T->snapmap[snap->mapofs]; -+ SnapEntry *flinks = &as->T->snapmap[snap_nextofs(as->T, snap) - 1]; -+ MSize n, nent = snap->nent; -+ /* Store the value of all modified slots to the Lua stack. */ -+ for (n = 0; n < nent; n++) { -+ SnapEntry sn = map[n]; -+ BCReg s = snap_slot(sn); -+ int32_t ofs = 8*((int32_t)s - 1); -+ IRRef ref = snap_ref(sn); -+ IRIns *ir = IR(ref); -+ if ((sn & SNAP_NORESTORE)) -+ continue; -+ if (irt_isnum(ir->t)) { -+#if LJ_SOFTFP -+ RegSet odd = rset_exclude(RSET_GPRODD, RID_BASE); -+ Reg tmp; -+ /* LJ_SOFTFP: must be a number constant. */ -+ lj_assertA(irref_isk(ref), "unsplit FP op"); -+ tmp = ra_allock(as, -+ (int32_t)ir_knum(ir)->u32.lo, -+ rset_exclude(RSET_GPREVEN, RID_BASE)); -+ emit_lso(as, ARMI_STR, tmp, RID_BASE, ofs); -+ if (rset_test(as->freeset, tmp + 1)) odd = RID2RSET(tmp + 1); -+ tmp = ra_allock(as, (int32_t)ir_knum(ir)->u32.hi, odd); -+ emit_lso(as, ARMI_STR, tmp, RID_BASE, ofs + 4); -+#else -+ Reg src = ra_alloc1(as, ref, RSET_FPR); -+ emit_vlso(as, ARMI_VSTR_D, src, RID_BASE, ofs); -+#endif -+ } -+ else { -+ RegSet odd = rset_exclude(RSET_GPRODD, RID_BASE); -+ Reg type; -+ lj_assertA(irt_ispri(ir->t) || irt_isaddr(ir->t) || irt_isinteger(ir->t), -+ "restore of IR type %d", irt_type(ir->t)); -+ if (!irt_ispri(ir->t)) { -+ Reg src = ra_alloc1(as, ref, rset_exclude(RSET_GPREVEN, RID_BASE)); -+ emit_lso(as, ARMI_STR, src, RID_BASE, ofs); -+ if (rset_test(as->freeset, src + 1)) odd = RID2RSET(src + 1); -+ } -+ if ((sn & (SNAP_CONT | SNAP_FRAME))) { -+ if (s == 0) continue; /* Do not overwrite link to previous frame. */ -+ type = ra_allock(as, (int32_t)(*flinks--), odd); -+#if LJ_SOFTFP -+ } -+ else if ((sn & SNAP_SOFTFPNUM)) { -+ type = ra_alloc1(as, ref + 1, rset_exclude(RSET_GPRODD, RID_BASE)); -+#endif -+ } else if ((sn & SNAP_KEYINDEX)) { -+ type = ra_allock(as, (int32_t)LJ_KEYINDEX, odd); -+ } -+ else { -+ type = ra_allock(as, (int32_t)irt_toitype(ir->t), odd); -+ } -+ emit_lso(as, ARMI_STR, type, RID_BASE, ofs + 4); -+ } -+ checkmclim(as); -+ } -+ lj_assertA(map + nent == flinks, "inconsistent frames in snapshot"); -+} -+ -+/* -- GC handling --------------------------------------------------------- */ -+ -+/* Marker to prevent patching the GC check exit. */ -+#define ARM_NOPATCH_GC_CHECK (ARMC_K12(ARMI_BIC, 0)) -+ -+/* Check GC threshold and do one or more GC steps. */ -+static void asm_gc_check(ASMState *as) -+{ -+ const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_gc_step_jit]; -+ IRRef args[2]; -+ MCLabel l_end; -+ Reg tmp1, tmp2; -+ ra_evictset(as, RSET_SCRATCH); -+ l_end = emit_label(as); -+ /* Exit trace if in GCSatomic or GCSfinalize. Avoids syncing GC objects. */ -+ asm_guardcc(as, CC_NE); /* Assumes asm_snap_prep() already done. */ -+ * --as->mcp = ARM_NOPATCH_GC_CHECK; -+ emit_n(as, ARMC_K12(ARMI_CMP, 0), RID_RET); -+ args[0] = ASMREF_TMP1; /* global_State *g */ -+ args[1] = ASMREF_TMP2; /* MSize steps */ -+ asm_gencall(as, ci, args); -+ tmp1 = ra_releasetmp(as, ASMREF_TMP1); -+ tmp2 = ra_releasetmp(as, ASMREF_TMP2); -+ emit_loadi(as, tmp2, as->gcsteps); -+ /* Jump around GC step if GC total < GC threshold. */ -+ emit_branch(as, ARMF_CC(ARMI_B, CC_LS), l_end); -+ emit_nm(as, ARMI_CMP, RID_TMP, tmp2); -+ emit_lso(as, -+ ARMI_LDR, -+ tmp2, -+ tmp1, -+ (int32_t)offsetof(global_State, gc.threshold)); -+ emit_lso(as, -+ ARMI_LDR, -+ RID_TMP, -+ tmp1, -+ (int32_t)offsetof(global_State, gc.total)); -+ ra_allockreg(as, i32ptr(J2G(as->J)), tmp1); -+ as->gcsteps = 0; -+ checkmclim(as); -+} -+ -+/* -- Loop handling ------------------------------------------------------- */ -+ -+/* Fixup the loop branch. */ -+static void asm_loop_fixup(ASMState *as) -+{ -+ MCode *p = as->mctop; -+ MCode *target = as->mcp; -+ if (as->loopinv) { -+ /* Inverted loop branch? */ -+ /* asm_guardcc already inverted the bcc and patched the final bl. */ -+ p[-2] |= ARMC_B((uint32_t)((target - p + 1) << 1)); -+ } -+ else { -+ p[-1] = ARMI_B_T4 | ARMC_BL((uint32_t)((target - p) << 1)); -+ } -+} -+ -+/* Fixup the tail of the loop. */ -+static void asm_loop_tail_fixup(ASMState *as) -+{ -+ UNUSED(as); /* Nothing to do. */ -+} -+ -+/* -- Head of trace ------------------------------------------------------- */ -+ -+/* Reload L register from g->cur_L. */ -+static void asm_head_lreg(ASMState *as) -+{ -+ IRIns *ir = IR(ASMREF_L); -+ if (ra_used(ir)) { -+ Reg r = ra_dest(as, ir, RSET_GPR); -+ emit_getgl(as, r, cur_L); -+ ra_evictk(as); -+ } -+} -+ -+/* Coalesce BASE register for a root trace. */ -+static void asm_head_root_base(ASMState *as) -+{ -+ IRIns *ir; -+ asm_head_lreg(as); -+ ir = IR(REF_BASE); -+ if (ra_hasreg(ir->r) && (rset_test(as->modset, ir->r) || irt_ismarked(ir->t))) -+ ra_spill(as, ir); -+ ra_destreg(as, ir, RID_BASE); -+} -+ -+/* Coalesce BASE register for a side trace. */ -+static RegSet asm_head_side_base(ASMState *as, IRIns *irp, RegSet allow) -+{ -+ IRIns *ir; -+ asm_head_lreg(as); -+ ir = IR(REF_BASE); -+ if (ra_hasreg(ir->r) && (rset_test(as->modset, ir->r) || irt_ismarked(ir->t))) -+ ra_spill(as, ir); -+ if (ra_hasspill(irp->s)) { -+ rset_clear(allow, ra_dest(as, ir, allow)); -+ } -+ else { -+ Reg r = irp->r; -+ lj_assertA(ra_hasreg(r), "base reg lost"); -+ rset_clear(allow, r); -+ if (r != ir->r && !rset_test(as->freeset, r)) -+ ra_restore(as, regcost_ref(as->cost[r])); -+ ra_destreg(as, ir, r); -+ } -+ return allow; -+} -+ -+/* -- Tail of trace ------------------------------------------------------- */ -+ -+/* Fixup the tail code. */ -+static void asm_tail_fixup(ASMState *as, TraceNo lnk) -+{ -+ MCode *p = as->mctop; -+ MCode *target; -+ int32_t spadj = as->T->spadjust; -+ if (spadj == 0) { -+ as->mctop = --p; -+ } -+ else { -+ /* Patch stack adjustment. */ -+ uint32_t k = emit_isk12(ARMI_ADD, spadj); -+ lj_assertA(k, "stack adjustment %d does not fit in K12", spadj); -+ p[-2] = (ARMI_ADD ^ k) | ARMF_D(RID_SP) | ARMF_N(RID_SP); -+ } -+ /* Patch exit branch. */ -+ target = lnk ? traceref(as->J, lnk)->mcode : (MCode *)as->J->exitstubgroup[0] - 8;//lj_vm_exit_interp; -+ p[-1] = ARMI_B_T4 | ARMC_BL((target - p) << 1); -+} -+ -+/* Prepare tail of code. */ -+static void asm_tail_prep(ASMState *as) -+{ -+ MCode *p = as->mctop - 1; /* Leave room for exit branch. */ -+ if (as->loopref) { -+ as->invmcp = as->mcp = p; -+ } -+ else { -+ as->mcp = p - 1; /* Leave room for stack pointer adjustment. */ -+ as->invmcp = NULL; -+ } -+ *p = 0; /* Prevent load/store merging. */ -+} -+ -+/* -- Trace setup --------------------------------------------------------- */ -+ -+/* Ensure there are enough stack slots for call arguments. */ -+static Reg asm_setup_call_slots(ASMState *as, IRIns *ir, const CCallInfo *ci) -+{ -+ IRRef args[CCI_NARGS_MAX * 2]; -+ uint32_t i, nargs = CCI_XNARGS(ci); -+ int nslots = 0, ngpr = REGARG_NUMGPR, nfpr = REGARG_NUMFPR, fprodd = 0; -+ asm_collectargs(as, ir, ci, args); -+ for (i = 0; i < nargs; i++) { -+ if (!LJ_SOFTFP && args[i] && irt_isfp(IR(args[i])->t)) { -+ if (!LJ_ABI_SOFTFP && !(ci->flags & CCI_VARARG)) { -+ if (irt_isnum(IR(args[i])->t)) { -+ if (nfpr > 0) nfpr--; -+ else fprodd = 0, nslots = (nslots + 3) & ~1; -+ } -+ else { -+ if (fprodd) fprodd--; -+ else if (nfpr > 0) fprodd = 1, nfpr--; -+ else nslots++; -+ } -+ } -+ else if (irt_isnum(IR(args[i])->t)) { -+ ngpr &= ~1; -+ if (ngpr > 0) ngpr -= 2; -+ else nslots += 2; -+ } -+ else { -+ if (ngpr > 0) ngpr--; -+ else nslots++; -+ } -+ } -+ else { -+ if (ngpr > 0) ngpr--; -+ else nslots++; -+ } -+ } -+ if (nslots > as->evenspill) /* Leave room for args in stack slots. */ -+ as->evenspill = nslots; -+ return REGSP_HINT(RID_RET); -+} -+ -+static void asm_setup_target(ASMState *as) -+{ -+ /* May need extra exit for asm_stack_check on side traces. */ -+ asm_exitstub_setup(as, as->T->nsnap + (as->parent ? 1 : 0)); -+} -+ -+/* -- Trace patching ------------------------------------------------------ */ -+ -+/* Patch exit jumps of existing machine code to a new target. */ -+void lj_asm_patchexit(jit_State *J, GCtrace *T, ExitNo exitno, MCode *target) -+{ -+ MCode *p = T->mcode; -+ MCode *pe = (MCode *)((char *)p + T->szmcode); -+ MCode *cstart = NULL, *cend = p; -+ MCode *mcarea = lj_mcode_patch(J, p, 0); -+ MCode *px = exitstub_addr(J, exitno) - 1; -+ for (; p < pe; p++) { -+ /* Look for bl_cc exitstub, replace with b_cc target. */ -+ uint32_t ins = *p; -+ if ((ins & 0xd000f800u) == 0xd000f000u && -+ (((ARMC_BL_READ(ins) >> 1) ^ (px - p)) & 0x007fffffu) == 0 && -+ p[-1] != ARM_NOPATCH_GC_CHECK) { -+ *p = ARMI_B_T4 | ARMC_BL((uint32_t)(((target - p) - 1) << 1)); -+ cend = p + 1; -+ if (!cstart) cstart = p; -+ } -+ } -+ lj_assertJ(cstart != NULL, "exit stub %d not found", exitno); -+ lj_mcode_sync(cstart, cend); -+ lj_mcode_patch(J, mcarea, 1); -+} -+ -diff --git a/src/lj_ccallback.c b/src/lj_ccallback.c -index 43e44305..2e6b6fd4 100644 ---- a/src/lj_ccallback.c -+++ b/src/lj_ccallback.c -@@ -151,7 +151,7 @@ static void *callback_mcode_init(global_State *g, uint32_t *page) - uint32_t *p = page; - void *target = (void *)lj_vm_ffi_callback; - MSize slot; -- /* This must match with the saveregs macro in buildvm_arm.dasc. */ -+ /* This must match with the saveregs macro in buildvm_arm.dasc. */ //jturnsek!!! - *p++ = ARMI_SUB|ARMF_D(RID_R12)|ARMF_N(RID_R12)|ARMF_M(RID_PC); - *p++ = ARMI_PUSH|ARMF_N(RID_SP)|RSET_RANGE(RID_R4,RID_R11+1)|RID2RSET(RID_LR); - *p++ = ARMI_SUB|ARMI_K12|ARMF_D(RID_R12)|ARMF_N(RID_R12)|CALLBACK_MCODE_HEAD; -@@ -295,7 +295,7 @@ static void callback_mcode_new(CTState *cts) - DWORD oprot; - LJ_WIN_VPROTECT(p, sz, PAGE_EXECUTE_READ, &oprot); - } --#elif LJ_TARGET_POSIX -+#elif LJ_TARGET_POSIX && !LJ_TARGET_NUTTX - mprotect(p, sz, (PROT_READ|PROT_EXEC)); - #endif - } -diff --git a/src/lj_clib.c b/src/lj_clib.c -index f0ef6edd..0fc6419b 100644 ---- a/src/lj_clib.c -+++ b/src/lj_clib.c -@@ -50,6 +50,8 @@ LJ_NORET LJ_NOINLINE static void clib_error_(lua_State *L) - #define CLIB_SOEXT "%s.dylib" - #elif LJ_TARGET_CYGWIN - #define CLIB_SOEXT "%s.dll" -+#elif LJ_TARGET_NUTTX -+#define CLIB_SOEXT "%s" - #else - #define CLIB_SOEXT "%s.so" - #endif -@@ -428,7 +430,11 @@ void lj_clib_unload(CLibrary *cl) - void lj_clib_default(lua_State *L, GCtab *mt) - { - CLibrary *cl = clib_new(L, mt); -+#if LJ_TARGET_NUTTX -+ cl->handle = clib_loadlib(L, "c", 0); -+#else - cl->handle = CLIB_DEFHANDLE; -+#endif - } - - #endif -diff --git a/src/lj_def.h b/src/lj_def.h -index b61297aa..03f60c3f 100644 ---- a/src/lj_def.h -+++ b/src/lj_def.h -@@ -87,6 +87,7 @@ typedef unsigned int uintptr_t; - #define LJ_MAX_EXITSTUBGR 16 /* Max. # of exit stub groups. */ - - /* Various macros. */ -+#undef UNUSED /* NuttX UNUSED macro is giving us problems. Use our own. */ - #ifndef UNUSED - #define UNUSED(x) ((void)(x)) /* to avoid warnings */ - #endif -diff --git a/src/lj_dispatch.h b/src/lj_dispatch.h -index 52762eea..909d4d5a 100644 ---- a/src/lj_dispatch.h -+++ b/src/lj_dispatch.h -@@ -87,25 +87,23 @@ typedef uint16_t HotCount; - - /* Global state, main thread and extra fields are allocated together. */ - typedef struct GG_State { -- lua_State L; /* Main thread. */ -- global_State g; /* Global state. */ --#if LJ_TARGET_ARM && !LJ_TARGET_NX -- /* Make g reachable via K12 encoded DISPATCH-relative addressing. */ -- uint8_t align1[(16-sizeof(global_State))&15]; --#endif -+ lua_State L; /* Main thread. */ - #if LJ_TARGET_MIPS -- ASMFunction got[LJ_GOT__MAX]; /* Global offset table. */ -+ ASMFunction got[LJ_GOT__MAX]; /* Global offset table. */ - #endif - #if LJ_HASJIT -- jit_State J; /* JIT state. */ -- HotCount hotcount[HOTCOUNT_SIZE]; /* Hot counters. */ -+ jit_State J; /* JIT state. */ -+ HotCount hotcount[HOTCOUNT_SIZE]; /* Hot counters. */ - #if LJ_TARGET_ARM && !LJ_TARGET_NX - /* Ditto for J. */ -- uint8_t align2[(16-sizeof(jit_State)-sizeof(HotCount)*HOTCOUNT_SIZE)&15]; -+ uint8_t align1[(16-sizeof(jit_State)-sizeof(HotCount)*HOTCOUNT_SIZE)&15]; - #endif - #endif -- ASMFunction dispatch[GG_LEN_DISP]; /* Instruction dispatch tables. */ -- BCIns bcff[GG_NUM_ASMFF]; /* Bytecode for ASM fast functions. */ -+ global_State g; /* Global state. */ /* jturnsek: moved here in order to avoid excessive negative offsets when LJ_HASJIT */ -+ /* Make g reachable via K12 encoded DISPATCH-relative addressing. */ -+ uint8_t align2[(16-sizeof(global_State))&15]; -+ ASMFunction dispatch[GG_LEN_DISP]; /* Instruction dispatch tables. */ -+ BCIns bcff[GG_NUM_ASMFF]; /* Bytecode for ASM fast functions. */ - } GG_State; - - #define GG_OFS(field) ((int)offsetof(GG_State, field)) -diff --git a/src/lj_emit_armv7m.h b/src/lj_emit_armv7m.h -new file mode 100644 -index 00000000..5381df8b ---- /dev/null -+++ b/src/lj_emit_armv7m.h -@@ -0,0 +1,474 @@ -+/* -+** ARMv7-M instruction emitter. -+** Copyright (C) 2018 Jernej Turnsek. See Copyright Notice in luajit.h -+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h -+*/ -+ -+/* -- Constant encoding --------------------------------------------------- */ -+ -+#define INVAI_MASK 0xfbe0 -+ -+static uint32_t emit_invai[16] = { -+ /* AND, TST */ ((ARMI_AND ^ 0x1a00) ^ (ARMI_BIC ^ 0x1a00)) & INVAI_MASK, -+ /* BIC */ ((ARMI_BIC ^ 0x1a00) ^ (ARMI_AND ^ 0x1a00)) & INVAI_MASK, -+ /* MOV, ORR */ ((ARMI_MOV ^ 0x1a00) ^ (ARMI_MVN ^ 0x1a00)) & INVAI_MASK, -+ /* MVN, ORN */ ((ARMI_MVN ^ 0x1a00) ^ (ARMI_MOV ^ 0x1a00)) & INVAI_MASK, -+ /* EOR, TEQ */ 0, -+ 0, -+ 0, -+ 0, -+ /* ADD, CMN */ ((ARMI_ADD ^ 0x1a00) ^ (ARMI_SUB ^ 0x1a00)) & INVAI_MASK, -+ 0, -+ /* ADC */ ((ARMI_ADC ^ 0x1a00) ^ (ARMI_SBC ^ 0x1a00)) & INVAI_MASK, -+ /* SBC */ ((ARMI_SBC ^ 0x1a00) ^ (ARMI_ADC ^ 0x1a00)) & INVAI_MASK, -+ 0, -+ /* SUB, CMP */ ((ARMI_SUB ^ 0x1a00) ^ (ARMI_ADD ^ 0x1a00)) & INVAI_MASK, -+ /* RSB */ 0, -+ 0 -+}; -+ -+/* Encode constant in K12 format for data processing instructions. */ -+static unsigned int emit_isk12(ARMIns ai, signed int n) -+{ -+ unsigned int invai, i, m = (unsigned int)n; -+ /* K12: 1bcdefgh value, rotated in steps of one bit. */ -+ if (m <= 255) { -+ /* i:imm3 = 0000 */ -+ return ARMC_K12(0, m); -+ } -+ else if (!(m & 0xff00ff00) && !(((m >> 16 & 0xff) ^ m) & 0xff)) { -+ /* i:imm3 = 0001 */ -+ return ARMC_K12(0, 0x100 | (m & 0xff)); -+ } -+ else if (!(m & 0x00ff00ff) && !(((m >> 16 & 0xff00) ^ m) & 0xff00)) { -+ /* i:imm3 = 0010 */ -+ return ARMC_K12(0, 0x200 | (m >> 8 & 0xff)); -+ } -+ else if (!(((m >> 16 & 0xffff) ^ m) & 0xffff) && !(((m >> 8 & 0xff) ^ m) & 0xff)) { -+ /* i:imm3 = 0011 */ -+ return ARMC_K12(0, 0x300 | (m & 0xff)); -+ } -+ else { -+ for (i = 0; i < 4096; i += 128, m = lj_rol(m, 1)) { -+ if (m <= 255) { -+ if ((m & 0x80) && (i >= 128 * 8)) -+ return ARMC_K12(0, i | (m & 0x7f)); -+ else -+ continue; -+ } -+ } -+ } -+ -+ /* Otherwise try negation/complement with the inverse instruction. */ -+ invai = emit_invai[(ai >> 5) & 0xf]; -+ if (!invai) return 0; /* Failed. No inverse instruction. */ -+ m = ~(unsigned int)n; -+ if (invai == (((ARMI_SUB ^ 0x1a00) ^ (ARMI_ADD ^ 0x1a00)) & INVAI_MASK) || -+ invai == (((ARMI_CMP ^ 0x1a00) ^ (ARMI_CMN ^ 0x1a00)) & INVAI_MASK)) m++; -+ if (m <= 255) { -+ /* i:imm3 = 0000 */ -+ return ARMC_K12(invai, m); -+ } -+ else if (!(m & 0xff00ff00) && !(((m >> 16 & 0xff) ^ m) & 0xff)) { -+ /* i:imm3 = 0001 */ -+ return ARMC_K12(invai, 0x100 | (m & 0xff)); -+ } -+ else if (!(m & 0x00ff00ff) && !(((m >> 16 & 0xff00) ^ m) & 0xff00)) { -+ /* i:imm3 = 0010 */ -+ return ARMC_K12(invai, 0x200 | (m >> 8 & 0xff)); -+ } -+ else if (!(((m >> 16 & 0xffff) ^ m) & 0xffff) && !(((m >> 8 & 0xff) ^ m) & 0xff)) { -+ /* i:imm3 = 0011 */ -+ return ARMC_K12(invai, 0x300 | (m & 0xff)); -+ } -+ else { -+ for (i = 0; i < 4096; i += 128, m = lj_rol(m, 1)) { -+ if (m <= 255) { -+ if ((m & 0x80) && (i >= 128 * 8)) -+ return ARMC_K12(invai, i | (m & 0x7f)); -+ else -+ continue; -+ } -+ } -+ } -+ -+ return 0; -+} -+ -+/* -- Emit basic instructions --------------------------------------------- */ -+ -+static void emit_dnm(ASMState *as, ARMIns ai, Reg rd, Reg rn, Reg rm) -+{ -+ * --as->mcp = ai | ARMF_D(rd) | ARMF_N(rn) | ARMF_M(rm); -+} -+ -+static void emit_tnm(ASMState *as, ARMIns ai, Reg rd, Reg rn, Reg rm) -+{ -+ * --as->mcp = ai | ARMF_T(rd) | ARMF_N(rn) | ARMF_M(rm); -+} -+ -+static void emit_dm(ASMState *as, ARMIns ai, Reg rd, Reg rm) -+{ -+ * --as->mcp = ai | ARMF_D(rd) | ARMF_M(rm); -+} -+ -+static void emit_tm(ASMState *as, ARMIns ai, Reg rd, Reg rm) -+{ -+ * --as->mcp = ai | ARMF_T(rd) | ARMF_M(rm); -+} -+ -+static void emit_dn(ASMState *as, ARMIns ai, Reg rd, Reg rn) -+{ -+ * --as->mcp = ai | ARMF_D(rd) | ARMF_N(rn); -+} -+ -+static void emit_tn(ASMState *as, ARMIns ai, Reg rd, Reg rn) -+{ -+ * --as->mcp = ai | ARMF_T(rd) | ARMF_N(rn); -+} -+ -+static void emit_nm(ASMState *as, ARMIns ai, Reg rn, Reg rm) -+{ -+ * --as->mcp = ai | ARMF_N(rn) | ARMF_M(rm); -+} -+ -+static void emit_d(ASMState *as, ARMIns ai, Reg rd) -+{ -+ * --as->mcp = ai | ARMF_D(rd); -+} -+ -+static void emit_t(ASMState *as, ARMIns ai, Reg rd) -+{ -+ * --as->mcp = ai | ARMF_T(rd); -+} -+ -+static void emit_n(ASMState *as, ARMIns ai, Reg rn) -+{ -+ * --as->mcp = ai | ARMF_N(rn); -+} -+ -+static void emit_m(ASMState *as, ARMIns ai, Reg rm) -+{ -+ * --as->mcp = ai | ARMF_M(rm); -+} -+ -+static void emit_lsox(ASMState *as, ARMIns ai, Reg rd, Reg rn, int32_t ofs) -+{ -+ lj_assertA(ofs >= -1020 && ofs <= 1020, -+ "load/store offset %d out of range", ofs); -+ if (ofs < 0) ofs = -ofs; -+ else ai |= ARMI_LSX_U; -+ * --as->mcp = ai | ARMI_LSX_P | ARMF_T(rd) | ARMF_D(rd + 1) | ARMF_N(rn) | -+ (((ofs >> 2) & 0xff) << 16); /* imm multiples of 4 */ -+} -+ -+static void emit_lso(ASMState *as, ARMIns ai, Reg rd, Reg rn, int32_t ofs) -+{ -+ lj_assertA(ofs >= -255 && ofs <= 4095, -+ "load/store offset %d out of range", ofs); -+ /* Combine LDR/STR pairs to LDRD/STRD. */ -+ if (*as->mcp == (ai | ARMI_LS_1 | ARMI_LS_P | ARMI_LS_U | ARMF_T(rd ^ 1) | ARMF_N(rn) | (ofs ^ 4)) && -+ (ai & ~(ARMI_LDR ^ ARMI_STR)) == ARMI_STR && rd != rn && -+ (uint32_t)ofs <= 252 && !(ofs & 3) && !((rd ^ (ofs >> 2)) & 1) && -+ as->mcp != as->mcloop) { -+ as->mcp++; -+ emit_lsox(as, ai == ARMI_LDR ? ARMI_LDRD : ARMI_STRD, rd & ~1, rn, ofs & ~4); -+ return; -+ } -+ if (ofs > 255) { -+ * --as->mcp = ai | ARMI_LS_I | ARMF_T(rd) | ARMF_N(rn) | ((ofs & 0xfff) << 16); -+ return; -+ } -+ if (ofs < 0) ofs = -ofs; -+ else ai |= ARMI_LS_U; -+ * --as->mcp = ai | ARMI_LS_1 | ARMI_LS_P | ARMF_T(rd) | ARMF_N(rn) | ((ofs & 0xff) << 16); -+} -+ -+#if !LJ_SOFTFP -+static void emit_vlso(ASMState *as, ARMIns ai, Reg rd, Reg rn, int32_t ofs) -+{ -+ lj_assertA(ofs >= -1020 && ofs <= 1020 && (ofs & 3) == 0, -+ "load/store offset %d out of range", ofs); -+ if (ofs < 0) ofs = -ofs; -+ else ai |= ARMI_LSX_U; -+ * --as->mcp = ai | ARMF_T(rd & 15) | ARMF_N(rn) | ((ofs >> 2) << 16); -+} -+#endif -+ -+/* -- Emit loads/stores --------------------------------------------------- */ -+ -+/* Prefer spills of BASE/L. */ -+#define emit_canremat(ref) ((ref) < ASMREF_L) -+ -+/* Try to find a one step delta relative to another constant. */ -+static int emit_kdelta1(ASMState *as, Reg d, int32_t i) -+{ -+ RegSet work = ~as->freeset & RSET_GPR; -+ while (work) { -+ Reg r = rset_picktop(work); -+ IRRef ref = regcost_ref(as->cost[r]); -+ lj_assertA(r != d, "dest reg not free"); -+ if (emit_canremat(ref)) { -+ int32_t delta = i - (ra_iskref(ref) ? ra_krefk(as, ref) : IR(ref)->i); -+ uint32_t k = emit_isk12(ARMI_ADD, delta); -+ if (k) { -+ if (k == ARMI_K12) -+ emit_dm(as, ARMI_MOV, d, r); -+ else -+ emit_dn(as, ARMI_ADD ^ k, d, r); -+ return 1; -+ } -+ } -+ rset_clear(work, r); -+ } -+ return 0; /* Failed. */ -+} -+ -+/* Try to find a two step delta relative to another constant. */ -+static int emit_kdelta2(ASMState *as, Reg rd, int32_t i) -+{ -+ RegSet work = ~as->freeset & RSET_GPR; -+ while (work) { -+ Reg r = rset_picktop(work); -+ IRRef ref = regcost_ref(as->cost[r]); -+ lj_assertA(r != rd, "dest reg %d not free", rd); -+ if (emit_canremat(ref)) { -+ int32_t other = ra_iskref(ref) ? ra_krefk(as, ref) : IR(ref)->i; -+ if (other) { -+ int32_t delta = i - other; -+ uint32_t sh, inv = 0, k2, k; -+ if (delta < 0) { delta = -delta; inv = (ARMI_ADD ^ 0x1a00) ^ (ARMI_SUB ^ 0x1a00); } -+ sh = lj_ffs(delta) & ~1; -+ k2 = emit_isk12(0, delta & (255 << sh)); -+ k = emit_isk12(0, delta & ~(255 << sh)); -+ if (k) { -+ emit_dn(as, ARMI_ADD ^ k2 ^ inv, rd, rd); -+ emit_dn(as, ARMI_ADD ^ k ^ inv, rd, r); -+ return 1; -+ } -+ } -+ } -+ rset_clear(work, r); -+ } -+ return 0; /* Failed. */ -+} -+ -+/* Load a 32 bit constant into a GPR. */ -+static void emit_loadi(ASMState *as, Reg rd, int32_t i) -+{ -+ uint32_t k = emit_isk12(ARMI_MOV, i); -+ lj_assertA(rset_test(as->freeset, rd) || rd == RID_TMP, -+ "dest reg %d not free", rd); -+ if (k) { -+ /* Standard K12 constant. */ -+ emit_d(as, ARMI_MOV ^ k, rd); -+ } -+ else if ((as->flags & JIT_F_ARMV6T2) && (uint32_t)i < 0x00010000u) { -+ /* 16 bit loword constant for ARMv6T2. */ -+ emit_d(as, ARMI_MOVW | ((i & 0xff) << 16) | ((i & 0x700) << 20) | ((i & 0x800) >> 1) | ((i & 0xf000) >> 12), rd); -+ } -+ else if (emit_kdelta1(as, rd, i)) { -+ /* One step delta relative to another constant. */ -+ } -+ else if ((as->flags & JIT_F_ARMV6T2)) { -+ /* 32 bit hiword/loword constant for ARMv6T2. */ -+ emit_d(as, ARMI_MOVT | (((i >> 16) & 0xff) << 16) | (((i >> 16) & 0x700) << 20) | (((i >> 16) & 0x800) >> 1) | (((i >> 16) & 0xf000) >> 12), rd); -+ emit_d(as, ARMI_MOVW | ((i & 0xff) << 16) | ((i & 0x700) << 20) | ((i & 0x800) >> 1) | ((i & 0xf000) >> 12), rd); -+ } -+ else if (emit_kdelta2(as, rd, i)) { -+ /* Two step delta relative to another constant. */ -+ } -+ else { -+ /* Otherwise construct the constant with up to 4 instructions. */ -+ /* NYI: use mvn+bic, use pc-relative loads. */ -+ for (;;) { -+ uint32_t sh = lj_ffs(i) & ~1; -+ int32_t m = i & (255 << sh); -+ i &= ~(255 << sh); -+ if (i == 0) { -+ emit_d(as, ARMI_MOV ^ emit_isk12(0, m), rd); -+ break; -+ } -+ emit_dn(as, ARMI_ORR ^ emit_isk12(0, m), rd, rd); -+ } -+ } -+} -+ -+#define emit_loada(as, rd, addr) emit_loadi(as, (rd), i32ptr((addr))) -+ -+static Reg ra_allock(ASMState *as, intptr_t k, RegSet allow); -+ -+/* Get/set from constant pointer. */ -+static void emit_lsptr(ASMState *as, ARMIns ai, Reg r, void *p) -+{ -+ int32_t i = i32ptr(p); -+ emit_lso(as, -+ ai, -+ r, -+ ra_allock(as, (i & ~4095), rset_exclude(RSET_GPR, r)), -+ (i & 4095)); -+} -+ -+#if !LJ_SOFTFP -+/* Load a number constant into an FPR. */ -+static void emit_loadk64(ASMState *as, Reg r, IRIns *ir) -+{ -+ cTValue *tv = ir_knum(ir); -+ int32_t i; -+ if ((as->flags & JIT_F_VFPV3) && !tv->u32.lo) { -+ uint32_t hi = tv->u32.hi; -+ uint32_t b = ((hi >> 22) & 0x1ff); -+ if (!(hi & 0xffff) && (b == 0x100 || b == 0x0ff)) { -+ * --as->mcp = ARMI_VMOVI_D | ARMF_T(r & 15) | -+ ((((tv->u32.hi >> 12) & 0x00080000) | -+ ((tv->u32.hi >> 4) & 0x00070000)) >> 16) | -+ (((tv->u32.hi >> 16) & 0x0000000f) << 16); -+ return; -+ } -+ } -+ i = i32ptr(tv); -+ emit_vlso(as, -+ ARMI_VLDR_D, -+ r, -+ ra_allock(as, (i & ~1020), RSET_GPR), -+ (i & 1020)); -+} -+#endif -+ -+/* Get/set global_State fields. */ -+#define emit_getgl(as, r, field) \ -+ emit_lsptr(as, ARMI_LDR, (r), (void *)&J2G(as->J)->field) -+#define emit_setgl(as, r, field) \ -+ emit_lsptr(as, ARMI_STR, (r), (void *)&J2G(as->J)->field) -+ -+/* Trace number is determined from pc of exit instruction. */ -+#define emit_setvmstate(as, i) UNUSED(i) -+ -+/* -- Emit control-flow instructions -------------------------------------- */ -+ -+/* Label for internal jumps. */ -+typedef MCode *MCLabel; -+ -+/* Return label pointing to current PC. */ -+#define emit_label(as) ((as)->mcp) -+ -+static void emit_branch(ASMState *as, ARMIns ai, MCode *target) -+{ -+ MCode *p = as->mcp; -+ ptrdiff_t delta = (target - p) << 1; -+ lj_assertA(((delta + 0x0080000) >> 20) == 0, "branch target out of range"); -+ * --p = ai | ARMC_B((uint32_t)delta & 0x00fffffu); -+ as->mcp = p; -+} -+ -+static void emit_branchlink(ASMState *as, ARMIns ai, MCode *target) -+{ -+ MCode *p = as->mcp; -+ ptrdiff_t delta = (target - p) << 1; -+ * --p = ai | ARMC_BL((uint32_t)delta & 0x0ffffffu); -+ as->mcp = p; -+} -+ -+static void emit_jmp(ASMState *as, MCode *target) -+{ -+ MCode *p = as->mcp; -+ ptrdiff_t delta = (target - p) << 1; -+ lj_assertA(((delta + 0x0800000) >> 24) == 0, "jump target out of range"); -+ * --p = ARMI_B_T4 | ARMC_BL((uint32_t)delta & 0x00ffffffu); -+ as->mcp = p; -+} -+ -+static void emit_call(ASMState *as, void *target) -+{ -+ MCode *p = --as->mcp; -+ ptrdiff_t delta = ((char *)target - (char *)p) - 4; -+ if ((((delta >> 1) + 0x00100000) >> 21) == 0) { -+ /* Only Thumb code is allowed */ -+ *p = ARMI_BL | ARMC_BL((uint32_t)(delta >> 1)); -+ } -+ else { -+ /* Target out of range: need indirect call. But don't use R0-R3. */ -+ Reg r = ra_allock(as, i32ptr(target), RSET_RANGE(RID_R4, RID_R12 + 1)); -+ *p = ARMI_BLXr | ARMF_M2(r); -+ } -+} -+ -+/* -- Emit generic operations --------------------------------------------- */ -+ -+/* Generic move between two regs. */ -+static void emit_movrr(ASMState *as, IRIns *ir, Reg dst, Reg src) -+{ -+#if LJ_SOFTFP -+ lj_assertA(!irt_isnum(ir->t), "unexpected FP op"); UNUSED(ir); -+#else -+ if (dst >= RID_MAX_GPR) { -+ emit_tm(as, -+ irt_isnum(ir->t) ? ARMI_VMOV_D : ARMI_VMOV_S, -+ (dst & 15), -+ (src & 15)); -+ return; -+ } -+#endif -+ if (as->mcp != as->mcloop) { -+ /* Swap early registers for loads/stores. */ -+ MCode ins = *as->mcp, swp = (src ^ dst); -+ if ((ins & 0x0fc0ff80) == 0x0000f800) { -+ if (!((ins ^ dst) & 0x0000000f)) -+ *as->mcp = ins ^ swp; /* Swap N in load/store. */ -+ if (!(ins & 0x00000010) && !((ins ^ (dst << 28)) & 0xf0000000)) -+ *as->mcp = ins ^ (swp << 28); /* Swap D in store. */ -+ } -+ } -+ emit_dm(as, ARMI_MOV, dst, src); -+} -+ -+/* Generic load of register with base and (small) offset address. */ -+static void emit_loadofs(ASMState *as, IRIns *ir, Reg r, Reg base, int32_t ofs) -+{ -+#if LJ_SOFTFP -+ lj_assertA(!irt_isnum(ir->t), "unexpected FP op"); UNUSED(ir); -+#else -+ if (r >= RID_MAX_GPR) -+ emit_vlso(as, irt_isnum(ir->t) ? ARMI_VLDR_D : ARMI_VLDR_S, r, base, ofs); -+ else -+#endif -+ emit_lso(as, ARMI_LDR, r, base, ofs); -+} -+ -+/* Generic store of register with base and (small) offset address. */ -+static void emit_storeofs(ASMState *as, IRIns *ir, Reg r, Reg base, int32_t ofs) -+{ -+#if LJ_SOFTFP -+ lj_assertA(!irt_isnum(ir->t), "unexpected FP op"); UNUSED(ir); -+#else -+ if (r >= RID_MAX_GPR) -+ emit_vlso(as, irt_isnum(ir->t) ? ARMI_VSTR_D : ARMI_VSTR_S, r, base, ofs); -+ else -+#endif -+ emit_lso(as, ARMI_STR, r, base, ofs); -+} -+ -+/* Emit an arithmetic/logic operation with a constant operand. */ -+static void emit_opk(ASMState *as, -+ ARMIns ai, -+ Reg dest, -+ Reg src, -+ int32_t i, -+ RegSet allow) -+{ -+ uint32_t k = emit_isk12(ai, i); -+ if (k) -+ emit_dn(as, ai ^ k, dest, src); -+ else -+ emit_dnm(as, ai, dest, src, ra_allock(as, i, allow)); -+} -+ -+/* Add offset to pointer. */ -+static void emit_addptr(ASMState *as, Reg r, int32_t ofs) -+{ -+ if (ofs) -+ emit_opk(as, ARMI_ADD, r, r, ofs, rset_exclude(RSET_GPR, r)); -+} -+ -+#define emit_spsub(as, ofs) emit_addptr(as, RID_SP, -(ofs)) -+ -diff --git a/src/lj_jit.h b/src/lj_jit.h -index 32b3861a..10644724 100644 ---- a/src/lj_jit.h -+++ b/src/lj_jit.h -@@ -107,7 +107,7 @@ - #define JIT_P_sizemcode_DEFAULT 64 - #else - /* Could go as low as 4K, but the mmap() overhead would be rather high. */ --#define JIT_P_sizemcode_DEFAULT 32 -+#define JIT_P_sizemcode_DEFAULT 8 - #endif - - /* Optimization parameters and their defaults. Length is a char in octal! */ -diff --git a/src/lj_mcode.c b/src/lj_mcode.c -index 163aada4..7ea1fe2f 100644 ---- a/src/lj_mcode.c -+++ b/src/lj_mcode.c -@@ -45,6 +45,8 @@ void lj_mcode_sync(void *start, void *end) - sys_icache_invalidate(start, (char *)end-(char *)start); - #elif LJ_TARGET_PPC - lj_vm_cachesync(start, end); -+#elif LJ_TARGET_NUTTX -+ up_invalidate_icache_all(); - #elif defined(__GNUC__) || defined(__clang__) - __clear_cache(start, end); - #else -@@ -86,6 +88,50 @@ static int mcode_setprot(void *p, size_t sz, DWORD prot) - return !LJ_WIN_VPROTECT(p, sz, prot, &oprot); - } - -+#elif LJ_TARGET_NUTTX -+ -+#include -+#include -+ -+static bool initialized = false; -+static struct mm_heap_s *g_mcode_heap; -+ -+#define MCPROT_RW 0 -+#define MCPROT_RX 0 -+#define MCPROT_RWX 0 -+ -+static void *mcode_alloc_at(jit_State *J, uintptr_t hint, size_t sz, int prot) -+{ -+ UNUSED(J); UNUSED(prot); -+ -+ if (!initialized) { -+ static uint8_t buffer[CONFIG_LUAJIT_MCODE_SIZE] -+ locate_data(CONFIG_LUAJIT_MCODE_SECTION_NAME); -+ g_mcode_heap = mm_initialize("mcode", -+ (void *)buffer, -+ CONFIG_LUAJIT_MCODE_SIZE); -+ initialized = true; -+ } -+ -+ void *p = mm_malloc(g_mcode_heap, sz); -+ if (p == NULL) { -+ if (!hint) lj_trace_err(J, LJ_TRERR_MCODEAL); -+ } -+ return p; -+} -+ -+static void mcode_free(jit_State *J, void *p, size_t sz) -+{ -+ UNUSED(J); UNUSED(sz); -+ mm_free(g_mcode_heap, p); -+} -+ -+static int mcode_setprot(void *p, size_t sz, int prot) -+{ -+ UNUSED(p); UNUSED(sz); UNUSED(prot); -+ return 0; -+} -+ - #elif LJ_TARGET_POSIX - - #include -diff --git a/src/lj_target.h b/src/lj_target.h -index 19716928..8cee29ea 100644 ---- a/src/lj_target.h -+++ b/src/lj_target.h -@@ -137,7 +137,11 @@ typedef uint32_t RegCost; - #if LJ_TARGET_X86ORX64 - #include "lj_target_x86.h" - #elif LJ_TARGET_ARM -+#if defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__) -+#include "lj_target_armv7m.h" -+#else - #include "lj_target_arm.h" -+#endif - #elif LJ_TARGET_ARM64 - #include "lj_target_arm64.h" - #elif LJ_TARGET_PPC -diff --git a/src/lj_target_armv7m.h b/src/lj_target_armv7m.h -new file mode 100755 -index 00000000..5dc6d488 ---- /dev/null -+++ b/src/lj_target_armv7m.h -@@ -0,0 +1,315 @@ -+/* -+** Definitions for ARMv7-M CPUs. -+** Copyright (C) 2018 Jernej Turnsek. See Copyright Notice in luajit.h -+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h -+*/ -+ -+#ifndef _LJ_TARGET_ARMV7M_H -+#define _LJ_TARGET_ARMV7M_H -+ -+/* -- Registers IDs ------------------------------------------------------- */ -+ -+#define GPRDEF(_) \ -+ _(R0) _(R1) _(R2) _(R3) _(R4) _(R5) _(R6) _(R7) \ -+ _(R8) _(R9) _(R10) _(R11) _(R12) _(SP) _(LR) _(PC) -+#if LJ_SOFTFP -+#define FPRDEF(_) -+#else -+#define FPRDEF(_) \ -+ _(D0) _(D1) _(D2) _(D3) _(D4) _(D5) _(D6) _(D7) \ -+ _(D8) _(D9) _(D10) _(D11) _(D12) _(D13) _(D14) _(D15) -+#endif -+#define VRIDDEF(_) -+ -+#define RIDENUM(name) RID_##name, -+ -+enum { -+ GPRDEF(RIDENUM) /* General-purpose registers (GPRs). */ -+ FPRDEF(RIDENUM) /* Floating-point registers (FPRs). */ -+ RID_MAX, -+ RID_TMP = RID_LR, -+ -+ /* Calling conventions. */ -+ RID_RET = RID_R0, -+ RID_RETLO = RID_R0, -+ RID_RETHI = RID_R1, -+#if LJ_SOFTFP -+ RID_FPRET = RID_R0, -+#else -+ RID_FPRET = RID_D0, -+#endif -+ -+ /* These definitions must match with the *.dasc file(s): */ -+ RID_BASE = RID_R9, /* Interpreter BASE. */ -+ RID_LPC = RID_R6, /* Interpreter PC. */ -+ RID_DISPATCH = RID_R7, /* Interpreter DISPATCH table. */ -+ RID_LREG = RID_R8, /* Interpreter L. */ -+ -+ /* Register ranges [min, max) and number of registers. */ -+ RID_MIN_GPR = RID_R0, -+ RID_MAX_GPR = RID_PC + 1, -+ RID_MIN_FPR = RID_MAX_GPR, -+#if LJ_SOFTFP -+ RID_MAX_FPR = RID_MIN_FPR, -+#else -+ RID_MAX_FPR = RID_D15 + 1, -+#endif -+ RID_NUM_GPR = RID_MAX_GPR - RID_MIN_GPR, -+ RID_NUM_FPR = RID_MAX_FPR - RID_MIN_FPR -+}; -+ -+#define RID_NUM_KREF RID_NUM_GPR -+#define RID_MIN_KREF RID_R0 -+ -+/* -- Register sets ------------------------------------------------------- */ -+ -+/* Make use of all registers, except sp, lr and pc. */ -+#define RSET_GPR (RSET_RANGE(RID_MIN_GPR, RID_R12+1)) -+#define RSET_GPREVEN \ -+ (RID2RSET(RID_R0)|RID2RSET(RID_R2)|RID2RSET(RID_R4)|RID2RSET(RID_R6)| \ -+ RID2RSET(RID_R8)|RID2RSET(RID_R10)) -+#define RSET_GPRODD \ -+ (RID2RSET(RID_R1)|RID2RSET(RID_R3)|RID2RSET(RID_R5)|RID2RSET(RID_R7)| \ -+ RID2RSET(RID_R9)|RID2RSET(RID_R11)) -+#if LJ_SOFTFP -+#define RSET_FPR 0 -+#else -+#define RSET_FPR (RSET_RANGE(RID_MIN_FPR, RID_MAX_FPR)) -+#endif -+#define RSET_ALL (RSET_GPR|RSET_FPR) -+#define RSET_INIT RSET_ALL -+ -+/* ABI-specific register sets. lr is an implicit scratch register. */ -+#define RSET_SCRATCH_GPR_ (RSET_RANGE(RID_R0, RID_R3+1)|RID2RSET(RID_R12)) -+#ifdef __APPLE__ -+#define RSET_SCRATCH_GPR (RSET_SCRATCH_GPR_|RID2RSET(RID_R9)) -+#else -+#define RSET_SCRATCH_GPR RSET_SCRATCH_GPR_ -+#endif -+#if LJ_SOFTFP -+#define RSET_SCRATCH_FPR 0 -+#else -+#define RSET_SCRATCH_FPR (RSET_RANGE(RID_D0, RID_D7+1)) -+#endif -+#define RSET_SCRATCH (RSET_SCRATCH_GPR|RSET_SCRATCH_FPR) -+#define REGARG_FIRSTGPR RID_R0 -+#define REGARG_LASTGPR RID_R3 -+#define REGARG_NUMGPR 4 -+#if LJ_ABI_SOFTFP -+#define REGARG_FIRSTFPR 0 -+#define REGARG_LASTFPR 0 -+#define REGARG_NUMFPR 0 -+#else -+#define REGARG_FIRSTFPR RID_D0 -+#define REGARG_LASTFPR RID_D7 -+#define REGARG_NUMFPR 8 -+#endif -+ -+/* -- Spill slots --------------------------------------------------------- */ -+ -+/* Spill slots are 32 bit wide. An even/odd pair is used for FPRs. -+** -+** SPS_FIXED: Available fixed spill slots in interpreter frame. -+** This definition must match with the *.dasc file(s). -+** -+** SPS_FIRST: First spill slot for general use. Reserve min. two 32 bit slots. -+*/ -+#define SPS_FIXED 2 -+#define SPS_FIRST 2 -+ -+#define SPOFS_TMP 0 -+ -+#define sps_scale(slot) (4 * (int32_t)(slot)) -+#define sps_align(slot) (((slot) - SPS_FIXED + 1) & ~1) -+ -+/* -- Exit state ---------------------------------------------------------- */ -+ -+/* This definition must match with the *.dasc file(s). */ -+typedef struct { -+#if !LJ_SOFTFP -+ lua_Number fpr[RID_NUM_FPR]; /* Floating-point registers. */ -+#endif -+ int32_t gpr[RID_NUM_GPR]; /* General-purpose registers. */ -+ int32_t spill[256]; /* Spill slots. */ -+} ExitState; -+ -+/* PC after instruction that caused an exit. Used to find the trace number. */ -+#define EXITSTATE_PCREG RID_PC -+/* Highest exit + 1 indicates stack check. */ -+#define EXITSTATE_CHECKEXIT 1 -+ -+#define EXITSTUB_SPACING 4 -+#define EXITSTUBS_PER_GROUP 32 -+ -+/* -- Instructions -------------------------------------------------------- */ -+ -+/* Instruction fields. */ -+#define ARMF_CC(ai, cc) ((ai) | ((cc) << 6)) -+#define ARMF_N(r) ((r)<<0) -+#define ARMF_T(r) ((r)<<28) -+#define ARMF_D(r) ((r)<<24) -+#define ARMF_M(r) ((r)<<16) -+#define ARMF_M2(r) ((r)<<19) // BLXr -+#define ARMF_SH(sh, n) (((sh)<<20)|(((n)&0x3)<<22)|((((n)>>2)&0x7)<<28)) -+#define ARMF_LSL(n) ((n&0x3)<<20) -+#define ARMF_RSH(sh, r) (0xf0000000|((sh)<<5)|ARMF_M(r)) -+ -+/* Instruction compositing */ -+#define ARMC_K12(arg1, arg2) (((arg1)^ARMI_K12)| \ -+ (((arg2)&0xff)<<16)| \ -+ (((arg2)&0x700)<<20)| \ -+ (((arg2)&0x800)>>1)) -+#define ARMC_B(arg) ((((arg)&0x7ff)<<16)| \ -+ (((arg)&0x1f800)>>11)| \ -+ (((arg)&0x20000)<<12)| \ -+ (((arg)&0x40000)<<9)| \ -+ (((arg)&0x80000)>>9)) -+#define ARMC_BL(arg) ((((arg)&0x7ff)<<16)| \ -+ (((arg)&0x1ff800)>>11)| \ -+ (((~(((arg)&0x200000)>>21)&0x1)^((((arg)&0x800000)>>23)&0x1))<<27)| \ -+ (((~(((arg)&0x400000)>>22)&0x1)^((((arg)&0x800000)>>23)&0x1))<<29)| \ -+ (((((arg)&0x800000)>>23)&0x1)<<10)) -+#define ARMC_BL_READ(ins) (((((ins)&0x07ff0000u)>>16))| \ -+ (((ins)&0x000003ffu)<<11)| \ -+ (((~((((ins)&0x08000000u)>>27)^(((ins)&0x00000400u)>>10)))&0x1)<<21)| \ -+ (((~((((ins)&0x20000000u)>>29)^(((ins)&0x00000400u)>>10)))&0x1)<<22)| \ -+ ((((ins)&0x00000400u)>>10)<<23)) -+#define ARMI_IT(cc) *--as->mcp = (0xbf08bf00u|(((cc)&0xf)<<20)) -+ -+ -+typedef enum ARMIns { -+ ARMI_CCAL = 0x000003c0, -+ ARMI_S = 0x00000010, -+ ARMI_K12 = 0x00001a00, -+ -+ ARMI_LS_W = 0x01000000, -+ ARMI_LS_U = 0x02000000, -+ ARMI_LS_P = 0x04000000, -+ ARMI_LS_1 = 0x08000000, -+ ARMI_LS_I = 0x00000080, -+ ARMI_LSX_W = 0x00000020, -+ ARMI_LSX_U = 0x00000080, -+ ARMI_LSX_P = 0x00000100, -+ -+ ARMI_AND = 0x0000ea00, -+ ARMI_EOR = 0x0000ea80, -+ ARMI_SUB = 0x0000eba0, -+ ARMI_RSB = 0x0000ebc0, -+ ARMI_ADD = 0x0000eb00, -+ ARMI_ADC = 0x0000eb40, -+ ARMI_SBC = 0x0000eb60, -+ // ARMI_RSC = 0xe0e00000, -+ ARMI_TST = 0x0f00ea10, -+ ARMI_TEQ = 0x0f00ea90, -+ ARMI_CMP = 0x0f00ebb0, -+ ARMI_CMN = 0x0f00eb10, -+ ARMI_ORR = 0x0000ea40, -+ ARMI_MOV = 0x0000ea4f, -+ ARMI_BIC = 0x0000ea20, -+ ARMI_MVN = 0x0000ea6f, -+ ARMI_NOP = 0xbf00bf00, -+ -+ ARMI_MUL = 0xf000fb00, -+ ARMI_SMULL = 0x0000fb80, -+ -+ ARMI_LDR = 0x0000f850, -+ ARMI_LDRB = 0x0000f810, -+ ARMI_LDRH = 0x0000f830, -+ ARMI_LDRSB = 0x0000f910, -+ ARMI_LDRSH = 0x0000f930, -+ ARMI_LDRD = 0x0000e850, -+ ARMI_STR = 0x0000f840, -+ ARMI_STRB = 0x0000f800, -+ ARMI_STRH = 0x0000f820, -+ ARMI_STRD = 0x0000e840, -+ ARMI_PUSH = 0x0000e92d, -+ -+ ARMI_B = 0x8000f000, -+ ARMI_B_T4 = 0x9000f000, -+ ARMI_BL = 0xd000f000, -+ ARMI_BLXr = 0x4780bf00, -+ -+ /* ARMv6 */ -+ ARMI_REV = 0xf080fa90, -+ ARMI_SXTB = 0xf080fa4f, -+ ARMI_SXTH = 0xf080fa0f, -+ ARMI_UXTB = 0xf080fa5f, -+ ARMI_UXTH = 0xf080fa1f, -+ -+ /* ARMv6T2 */ -+ ARMI_MOVW = 0x0000f240, -+ ARMI_MOVT = 0x0000f2c0, -+ -+ /* VFP */ -+ ARMI_VMOV_D = 0x0b40eeb0, -+ ARMI_VMOV_S = 0x0a40eeb0, -+ ARMI_VMOVI_D = 0x0b00eeb0, -+ -+ ARMI_VMOV_R_S = 0x0a10ee10, -+ ARMI_VMOV_S_R = 0x0a10ee00, -+ ARMI_VMOV_RR_D = 0x0b10ec50, -+ ARMI_VMOV_D_RR = 0x0b10ec40, -+ -+ ARMI_VADD_D = 0x0b00ee30, -+ ARMI_VSUB_D = 0x0b40ee30, -+ ARMI_VMUL_D = 0x0b00ee20, -+ ARMI_VMLA_D = 0x0b00ee00, -+ ARMI_VMLS_D = 0x0b40ee00, -+ ARMI_VNMLS_D = 0x0b00ee10, -+ ARMI_VDIV_D = 0x0b00ee80, -+ -+ ARMI_VABS_D = 0x0bc0eeb0, -+ ARMI_VNEG_D = 0x0b40eeb1, -+ ARMI_VSQRT_D = 0x0bc0eeb1, -+ -+ ARMI_VCMP_D = 0x0b40eeb4, -+ ARMI_VCMPZ_D = 0x0b40eeb5, -+ -+ ARMI_VMRS = 0xfa10eef1, -+ -+ ARMI_VCVT_S32_F32 = 0x0ac0eebd, -+ ARMI_VCVT_S32_F64 = 0x0bc0eebd, -+ ARMI_VCVT_U32_F32 = 0x0ac0eebc, -+ ARMI_VCVT_U32_F64 = 0x0bc0eebc, -+ ARMI_VCVT_F32_S32 = 0x0ac0eeb8, -+ ARMI_VCVT_F64_S32 = 0x0bc0eeb8, -+ ARMI_VCVT_F32_U32 = 0x0a40eeb8, -+ ARMI_VCVT_F64_U32 = 0x0b40eeb8, -+ ARMI_VCVT_F32_F64 = 0x0bc0eeb7, -+ ARMI_VCVT_F64_F32 = 0x0ac0eeb7, -+ -+ ARMI_VLDR_S = 0x0a00ed10, -+ ARMI_VLDR_D = 0x0b00ed10, -+ ARMI_VSTR_S = 0x0a00ed00, -+ ARMI_VSTR_D = 0x0b00ed00, -+} ARMIns; -+ -+typedef enum ARMShift { -+ ARMSH_LSL, -+ ARMSH_LSR, -+ ARMSH_ASR, -+ ARMSH_ROR -+} ARMShift; -+ -+/* ARM condition codes. */ -+typedef enum ARMCC { -+ CC_EQ, -+ CC_NE, -+ CC_CS, -+ CC_CC, -+ CC_MI, -+ CC_PL, -+ CC_VS, -+ CC_VC, -+ CC_HI, -+ CC_LS, -+ CC_GE, -+ CC_LT, -+ CC_GT, -+ CC_LE, -+ CC_AL, -+ CC_HS = CC_CS, -+ CC_LO = CC_CC -+} ARMCC; -+ -+#endif -diff --git a/src/vm_armv7m.dasc b/src/vm_armv7m.dasc -new file mode 100755 -index 00000000..13266007 ---- /dev/null -+++ b/src/vm_armv7m.dasc -@@ -0,0 +1,4901 @@ -+|// Low-level VM code for ARMV7M CPUs. -+|// Bytecode interpreter, fast functions and helper functions. -+|// Copyright (C) 2018 Jernej Turnsek. See Copyright Notice in luajit.h -+|// Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h -+| -+|.arch armv7m -+|.section code_op, code_sub -+| -+|.actionlist build_actionlist -+|.globals GLOB_ -+|.globalnames globnames -+|.externnames extnames -+| -+|// Note: The ragged indentation of the instructions is intentional. -+|// The starting columns indicate data dependencies. -+| -+|//----------------------------------------------------------------------- -+| -+|.macro ldrd_i, rt, rt2, rn, rm -+| add rt, rn, rm -+| ldm rt, {rt, rt2} -+|.endmacro -+|.macro ldrd_iw, rt, rt2, rn, rm -+| add rn, rn, rm -+| ldrd rt, rt2, [rn] -+|.endmacro -+| -+|.macro ldrdlo_i, rt, rt2, rn, rm -+| itt lo -+| addlo rt, rn, rm -+| ldmlo rt, {rt, rt2} -+|.endmacro -+|.macro ldrdlo_iw, rt, rt2, rn, rm -+| itt lo -+| addlo rn, rn, rm -+| ldrdlo rt, rt2, [rn] -+|.endmacro -+| -+|.macro strd_i, rt, rt2, rn, rm -+| add rn, rn, rm -+| strd rt, rt2, [rn] -+| sub rn, rn, rm -+|.endmacro -+| -+|.macro strdne_i, rt, rt2, rn, rm -+| ittt ne -+| addne rn, rn, rm -+| strdne rt, rt2, [rn] -+| subne rn, rn, rm -+|.endmacro -+|.macro strdls_i, rt, rt2, rn, rm -+| ittt ls -+| addls rn, rn, rm -+| strdls rt, rt2, [rn] -+| subls rn, rn, rm -+|.endmacro -+|.macro strdhi_i, rt, rt2, rn, rm -+| ittt hi -+| addhi rn, rn, rm -+| strdhi rt, rt2, [rn] -+| subhi rn, rn, rm -+|.endmacro -+| -+|// Fixed register assignments for the interpreter. -+| -+|// The following must be C callee-save. -+|.define MASKR8, r4 // 255*8 constant for fast bytecode decoding. -+|.define KBASE, r5 // Constants of current Lua function. -+|.define PC, r6 // Next PC. -+|.define DISPATCH,r7 // Opcode dispatch table. -+|.define LREG, r8 // Register holding lua_State (also in SAVE_L). -+| -+|// C callee-save in EABI, but often refetched. Temporary in iOS 3.0+. -+|.define BASE, r9 // Base of current Lua stack frame. -+| -+|// The following temporaries are not saved across C calls, except for RA/RC. -+|.define RA, r10 // Callee-save. -+|.define RC, r11 // Callee-save. -+|.define RB, r12 -+|.define OP, r12 // Overlaps RB, must not be lr. -+|.define INS, lr -+| -+|// Calling conventions. Also used as temporaries. -+|.define CARG1, r0 -+|.define CARG2, r1 -+|.define CARG3, r2 -+|.define CARG4, r3 -+| -+|.define CRET1, r0 -+|.define CRET2, r1 -+| -+|// Stack layout while in interpreter. Must match with lj_frame.h. -+|.define SAVE_R4, [sp, #28] -+|.define CFRAME_SPACE, #28 -+|.define SAVE_ERRF, [sp, #24] -+|.define SAVE_NRES, [sp, #20] -+|.define SAVE_CFRAME, [sp, #16] -+|.define SAVE_L, [sp, #12] -+|.define SAVE_PC, [sp, #8] -+|.define SAVE_MULTRES, [sp, #4] -+|.define ARG5, [sp] -+| -+|.define TMPDhi, [sp, #4] -+|.define TMPDlo, [sp] -+|.define TMPD, [sp] -+|.define TMPDp, sp -+| -+|.if FPU -+|.macro saveregs -+| push {r5, r6, r7, r8, r9, r10, r11, lr} -+| vpush {d8-d15} -+| sub sp, sp, CFRAME_SPACE+4 -+| str r4, SAVE_R4 -+|.endmacro -+|.macro restoreregs_ret -+| ldr r4, SAVE_R4 -+| add sp, sp, CFRAME_SPACE+4 -+| vpop {d8-d15} -+| pop {r5, r6, r7, r8, r9, r10, r11, pc} -+|.endmacro -+|.else -+|.macro saveregs -+| push {r4, r5, r6, r7, r8, r9, r10, r11, lr} -+| sub sp, sp, CFRAME_SPACE -+|.endmacro -+|.macro restoreregs_ret -+| add sp, sp, CFRAME_SPACE -+| pop {r4, r5, r6, r7, r8, r9, r10, r11, pc} -+|.endmacro -+|.endif -+| -+|// Type definitions. Some of these are only used for documentation. -+|.type L, lua_State, LREG -+|.type GL, global_State -+|.type TVALUE, TValue -+|.type GCOBJ, GCobj -+|.type STR, GCstr -+|.type TAB, GCtab -+|.type LFUNC, GCfuncL -+|.type CFUNC, GCfuncC -+|.type PROTO, GCproto -+|.type UPVAL, GCupval -+|.type NODE, Node -+|.type NARGS8, int -+|.type TRACE, GCtrace -+|.type SBUF, SBuf -+| -+|//----------------------------------------------------------------------- -+| -+|// Trap for not-yet-implemented parts. -+|.macro NYI; bkpt #0; .endmacro -+| -+|//----------------------------------------------------------------------- -+| -+|// Access to frame relative to BASE. -+|.define FRAME_FUNC, #-8 -+|.define FRAME_PC, #-4 -+| -+|.macro decode_RA8, dst, ins; and dst, MASKR8, ins, lsr #5; .endmacro -+|.macro decode_RB8, dst, ins; and dst, MASKR8, ins, lsr #21; .endmacro -+|.macro decode_RC8, dst, ins; and dst, MASKR8, ins, lsr #13; .endmacro -+|.macro decode_RD, dst, ins; lsr dst, ins, #16; .endmacro -+|.macro decode_OP, dst, ins; and dst, ins, #255; .endmacro -+| -+|// Instruction fetch. -+|.macro ins_NEXT1 -+| ldrb OP, [PC] -+|.endmacro -+|.macro ins_NEXT2 -+| ldr INS, [PC], #4 -+|.endmacro -+|// Instruction decode+dispatch. -+|.macro ins_NEXT3 -+| ldr OP, [DISPATCH, OP, lsl #2] -+| decode_RA8 RA, INS -+| decode_RD RC, INS -+| bx OP -+|.endmacro -+|.macro ins_NEXT -+| ins_NEXT1 -+| ins_NEXT2 -+| ins_NEXT3 -+|.endmacro -+| -+|// Instruction footer. -+|.if 1 -+| // Replicated dispatch. Less unpredictable branches, but higher I-Cache use. -+| .define ins_next, ins_NEXT -+| .define ins_next_, ins_NEXT -+| .define ins_next1, ins_NEXT1 -+| .define ins_next2, ins_NEXT2 -+| .define ins_next3, ins_NEXT3 -+|.else -+| // Common dispatch. Lower I-Cache use, only one (very) unpredictable branch. -+| // Affects only certain kinds of benchmarks (and only with -j off). -+| .macro ins_next -+| b ->ins_next -+| .endmacro -+| .macro ins_next1 -+| .endmacro -+| .macro ins_next2 -+| .endmacro -+| .macro ins_next3 -+| b ->ins_next -+| .endmacro -+| .macro ins_next_ -+| ->ins_next: -+| ins_NEXT -+| .endmacro -+|.endif -+| -+|// Avoid register name substitution for field name. -+#define field_pc pc -+| -+|// Call decode and dispatch. -+|.macro ins_callt -+| // BASE = new base, CARG3 = LFUNC/CFUNC, RC = nargs*8, FRAME_PC(BASE) = PC -+| ldr PC, LFUNC:CARG3->field_pc -+| ldrb OP, [PC] // STALL: load PC. early PC. -+| ldr INS, [PC], #4 -+| ldr OP, [DISPATCH, OP, lsl #2] // STALL: load OP. early OP. -+| decode_RA8 RA, INS -+| add RA, RA, BASE -+| bx OP -+|.endmacro -+| -+|.macro ins_call -+| // BASE = new base, CARG3 = LFUNC/CFUNC, RC = nargs*8, PC = caller PC -+| str PC, [BASE, FRAME_PC] -+| ins_callt // STALL: locked PC. -+|.endmacro -+| -+|//----------------------------------------------------------------------- -+| -+|// Macros to test operand types. -+|.macro checktp, reg, tp; cmn reg, #-tp; .endmacro -+|.macro checktpeq, reg, tp; it eq; cmneq reg, #-tp; .endmacro -+|.macro checktpne, reg, tp; it ne; cmnne reg, #-tp; .endmacro -+|.macro checkstr, reg, target; checktp reg, LJ_TSTR; bne target; .endmacro -+|.macro checktab, reg, target; checktp reg, LJ_TTAB; bne target; .endmacro -+|.macro checkfunc, reg, target; checktp reg, LJ_TFUNC; bne target; .endmacro -+| -+|// Assumes DISPATCH is relative to GL. -+#define DISPATCH_GL(field) (GG_DISP2G + (int)offsetof(global_State, field)) -+#define DISPATCH_J(field) (GG_DISP2J + (int)offsetof(jit_State, field)) -+| -+#define PC2PROTO(field) ((int)offsetof(GCproto, field)-(int)sizeof(GCproto)) -+| -+|.macro hotcheck, delta -+| lsr CARG1, PC, #1 -+| and CARG1, CARG1, #126 -+| sub CARG1, CARG1, #-GG_DISP2HOT -+| ldrh CARG2, [DISPATCH, CARG1] -+| subs CARG2, CARG2, #delta -+| strh CARG2, [DISPATCH, CARG1] -+|.endmacro -+| -+|.macro hotloop -+| hotcheck HOTCOUNT_LOOP -+| blo ->vm_hotloop -+|.endmacro -+| -+|.macro hotcall -+| hotcheck HOTCOUNT_CALL -+| blo ->vm_hotcall -+|.endmacro -+| -+|// Set current VM state. -+|.macro mv_vmstate, reg, st; mvn reg, #LJ_VMST_..st; .endmacro -+|.macro st_vmstate, reg; push {r12}; sub r12, DISPATCH, #-DISPATCH_GL(vmstate); str reg, [r12]; pop {r12}; .endmacro -+| -+|// Move table write barrier back. Overwrites mark and tmp. -+|.macro barrierback, tab, mark, tmp -+| sub tmp, DISPATCH, #-DISPATCH_GL(gc.grayagain) -+| ldr tmp, [tmp] -+| str tmp, tab->gclist -+| sub tmp, DISPATCH, #-DISPATCH_GL(gc.grayagain) -+| bic mark, mark, #LJ_GC_BLACK // black2gray(tab) -+| str tab, [tmp] -+| strb mark, tab->marked -+|.endmacro -+| -+|.macro .IOS, a, b -+|.if IOS -+| a, b -+|.endif -+|.endmacro -+| -+|//----------------------------------------------------------------------- -+ -+#if !LJ_DUALNUM -+#error "Only dual-number mode supported for ARM target" -+#endif -+ -+/* Generate subroutines used by opcodes and other parts of the VM. */ -+/* The .code_sub section should be last to help static branch prediction. */ -+static void build_subroutines(BuildCtx *ctx) -+{ -+ |.code_sub -+ | -+ |//----------------------------------------------------------------------- -+ |//-- Return handling ---------------------------------------------------- -+ |//----------------------------------------------------------------------- -+ | -+ |->vm_returnp: -+ | // See vm_return. Also: RB = previous base. -+ | tst PC, #FRAME_P -+ | beq ->cont_dispatch -+ | -+ | // Return from pcall or xpcall fast func. -+ | ldr PC, [RB, FRAME_PC] // Fetch PC of previous frame. -+ | mvn CARG2, #~LJ_TTRUE -+ | mov BASE, RB -+ | // Prepending may overwrite the pcall frame, so do it at the end. -+ | str CARG2, [RA, FRAME_PC] // Prepend true to results. -+ | sub RA, RA, #8 -+ | -+ |->vm_returnc: -+ | adds RC, RC, #8 // RC = (nresults+1)*8. -+ | mov CRET1, #LUA_YIELD -+ | beq ->vm_unwind_c_eh -+ | str RC, SAVE_MULTRES -+ | ands CARG1, PC, #FRAME_TYPE -+ | beq ->BC_RET_Z // Handle regular return to Lua. -+ | -+ |->vm_return: -+ | // BASE = base, RA = resultptr, RC/MULTRES = (nresults+1)*8, PC = return -+ | // CARG1 = PC & FRAME_TYPE -+ | bic RB, PC, #FRAME_TYPEP -+ | cmp CARG1, #FRAME_C -+ | sub RB, BASE, RB // RB = previous base. -+ | bne ->vm_returnp -+ | -+ | str RB, L->base -+ | ldr KBASE, SAVE_NRES -+ | mv_vmstate CARG4, C -+ | sub BASE, BASE, #8 -+ | subs CARG3, RC, #8 -+ | lsl KBASE, KBASE, #3 // KBASE = (nresults_wanted+1)*8 -+ | st_vmstate CARG4 -+ | beq >2 -+ |1: -+ | subs CARG3, CARG3, #8 -+ | ldrd CARG1, CARG2, [RA], #8 -+ | strd CARG1, CARG2, [BASE], #8 -+ | bne <1 -+ |2: -+ | cmp KBASE, RC // More/less results wanted? -+ | bne >6 -+ |3: -+ | str BASE, L->top // Store new top. -+ | -+ |->vm_leave_cp: -+ | ldr RC, SAVE_CFRAME // Restore previous C frame. -+ | mov CRET1, #0 // Ok return status for vm_pcall. -+ | str RC, L->cframe -+ | -+ |->vm_leave_unw: -+ | restoreregs_ret -+ | -+ |6: -+ | blt >7 // Less results wanted? -+ | // More results wanted. Check stack size and fill up results with nil. -+ | ldr CARG3, L->maxstack -+ | mvn CARG2, #~LJ_TNIL -+ | cmp BASE, CARG3 -+ | bhs >8 -+ | str CARG2, [BASE, #4] -+ | add RC, RC, #8 -+ | add BASE, BASE, #8 -+ | b <2 -+ | -+ |7: // Less results wanted. -+ | sub CARG1, RC, KBASE -+ | cmp KBASE, #0 // LUA_MULTRET+1 case? -+ | it ne -+ | subne BASE, BASE, CARG1 // Either keep top or shrink it. -+ | b <3 -+ | -+ |8: // Corner case: need to grow stack for filling up results. -+ | // This can happen if: -+ | // - A C function grows the stack (a lot). -+ | // - The GC shrinks the stack in between. -+ | // - A return back from a lua_call() with (high) nresults adjustment. -+ | str BASE, L->top // Save current top held in BASE (yes). -+ | lsr CARG2, KBASE, #3 -+ | mov CARG1, L -+ | bl extern lj_state_growstack // (lua_State *L, int n) -+ | ldr BASE, L->top // Need the (realloced) L->top in BASE. -+ | b <2 -+ | -+ |->vm_unwind_c: // Unwind C stack, return from vm_pcall. -+ | // (void *cframe, int errcode) -+ | mov sp, CARG1 -+ | mov CRET1, CARG2 -+ |->vm_unwind_c_eh: // Landing pad for external unwinder. -+ | ldr L, SAVE_L -+ | mv_vmstate CARG4, C -+ | ldr GL:CARG3, L->glref -+ | str CARG4, GL:CARG3->vmstate -+ | b ->vm_leave_unw -+ | -+ |->vm_unwind_ff: // Unwind C stack, return from ff pcall. -+ | // (void *cframe) -+ | bic CARG1, CARG1, #~CFRAME_RAWMASK // Use two steps: bic sp is deprecated. -+ | mov sp, CARG1 -+ |->vm_unwind_ff_eh: // Landing pad for external unwinder. -+ | ldr L, SAVE_L -+ | mov MASKR8, #255 -+ | mov RC, #16 // 2 results: false + error message. -+ | lsl MASKR8, MASKR8, #3 // MASKR8 = 255*8. -+ | ldr BASE, L->base -+ | ldr DISPATCH, L->glref // Setup pointer to dispatch table. -+ | mvn CARG1, #~LJ_TFALSE -+ | sub RA, BASE, #8 // Results start at BASE-8. -+ | ldr PC, [BASE, FRAME_PC] // Fetch PC of previous frame. -+ | add DISPATCH, DISPATCH, #GG_G2DISP -+ | mv_vmstate CARG2, INTERP -+ | str CARG1, [BASE, #-4] // Prepend false to error message. -+ | st_vmstate CARG2 -+ | b ->vm_returnc -+ | -+ |->vm_unwind_ext: // Complete external unwind. -+#if !LJ_NO_UNWIND -+ | push {r0, r1, r2, lr} -+ | bl extern _Unwind_Complete -+ | ldr r0, [sp] -+ | bl extern _Unwind_DeleteException -+ | pop {r0, r1, r2, lr} -+ | mov r0, r1 -+ | bx r2 -+#endif -+ | -+ |//----------------------------------------------------------------------- -+ |//-- Grow stack for calls ----------------------------------------------- -+ |//----------------------------------------------------------------------- -+ | -+ |->vm_growstack_c: // Grow stack for C function. -+ | // CARG1 = L -+ | mov CARG2, #LUA_MINSTACK -+ | b >2 -+ | -+ |->vm_growstack_l: // Grow stack for Lua function. -+ | // BASE = new base, RA = BASE+framesize*8, RC = nargs*8, PC = first PC -+ | add RC, BASE, RC -+ | sub RA, RA, BASE -+ | mov CARG1, L -+ | str BASE, L->base -+ | add PC, PC, #4 // Must point after first instruction. -+ | str RC, L->top -+ | lsr CARG2, RA, #3 -+ |2: -+ | // L->base = new base, L->top = top -+ | str PC, SAVE_PC -+ | bl extern lj_state_growstack // (lua_State *L, int n) -+ | ldr BASE, L->base -+ | ldr RC, L->top -+ | ldr LFUNC:CARG3, [BASE, FRAME_FUNC] -+ | sub NARGS8:RC, RC, BASE -+ | // BASE = new base, RB = LFUNC/CFUNC, RC = nargs*8, FRAME_PC(BASE) = PC -+ | ins_callt // Just retry the call. -+ | -+ |//----------------------------------------------------------------------- -+ |//-- Entry points into the assembler VM --------------------------------- -+ |//----------------------------------------------------------------------- -+ | -+ |->vm_resume: // Setup C frame and resume thread. -+ | // (lua_State *L, TValue *base, int nres1 = 0, ptrdiff_t ef = 0) -+ | saveregs -+ | mov L, CARG1 -+ | ldr DISPATCH, L:CARG1->glref // Setup pointer to dispatch table. -+ | mov BASE, CARG2 -+ | add DISPATCH, DISPATCH, #GG_G2DISP -+ | str L, SAVE_L -+ | mov PC, #FRAME_CP -+ | str CARG3, SAVE_NRES -+ | add CARG2, sp, #CFRAME_RESUME -+ | ldrb CARG1, L->status -+ | str CARG3, SAVE_ERRF -+ | str L, SAVE_PC // Any value outside of bytecode is ok. -+ | str CARG3, SAVE_CFRAME -+ | cmp CARG1, #0 -+ | str CARG2, L->cframe -+ | beq >3 -+ | -+ | // Resume after yield (like a return). -+ | str L, [DISPATCH, #DISPATCH_GL(cur_L)] -+ | mov RA, BASE -+ | ldr BASE, L->base -+ | ldr CARG1, L->top -+ | mov MASKR8, #255 -+ | strb CARG3, L->status -+ | sub RC, CARG1, BASE -+ | ldr PC, [BASE, FRAME_PC] -+ | lsl MASKR8, MASKR8, #3 // MASKR8 = 255*8. -+ | mv_vmstate CARG2, INTERP -+ | add RC, RC, #8 -+ | ands CARG1, PC, #FRAME_TYPE -+ | st_vmstate CARG2 -+ | str RC, SAVE_MULTRES -+ | beq ->BC_RET_Z -+ | b ->vm_return -+ | -+ |->vm_pcall: // Setup protected C frame and enter VM. -+ | // (lua_State *L, TValue *base, int nres1, ptrdiff_t ef) -+ | saveregs -+ | mov PC, #FRAME_CP -+ | str CARG4, SAVE_ERRF -+ | b >1 -+ | -+ |->vm_call: // Setup C frame and enter VM. -+ | // (lua_State *L, TValue *base, int nres1) -+ | saveregs -+ | mov PC, #FRAME_C -+ | -+ |1: // Entry point for vm_pcall above (PC = ftype). -+ | ldr RC, L:CARG1->cframe -+ | str CARG3, SAVE_NRES -+ | mov L, CARG1 -+ | str CARG1, SAVE_L -+ | ldr DISPATCH, L->glref // Setup pointer to dispatch table. -+ | mov BASE, CARG2 -+ | str CARG1, SAVE_PC // Any value outside of bytecode is ok. -+ | str RC, SAVE_CFRAME -+ | add DISPATCH, DISPATCH, #GG_G2DISP -+ | str sp, L->cframe // Add our C frame to cframe chain. -+ | -+ |3: // Entry point for vm_cpcall/vm_resume (BASE = base, PC = ftype). -+ | str L, [DISPATCH, #DISPATCH_GL(cur_L)] -+ | ldr RB, L->base // RB = old base (for vmeta_call). -+ | ldr CARG1, L->top -+ | mov MASKR8, #255 -+ | add PC, PC, BASE -+ | lsl MASKR8, MASKR8, #3 // MASKR8 = 255*8. -+ | sub PC, PC, RB // PC = frame delta + frame type -+ | mv_vmstate CARG2, INTERP -+ | sub NARGS8:RC, CARG1, BASE -+ | st_vmstate CARG2 -+ | -+ |->vm_call_dispatch: -+ | // RB = old base, BASE = new base, RC = nargs*8, PC = caller PC -+ | ldrd CARG3, CARG4, [BASE, FRAME_FUNC] -+ | checkfunc CARG4, ->vmeta_call -+ | -+ |->vm_call_dispatch_f: -+ | ins_call -+ | // BASE = new base, CARG3 = func, RC = nargs*8, PC = caller PC -+ | -+ |->vm_cpcall: // Setup protected C frame, call C. -+ | // (lua_State *L, lua_CFunction func, void *ud, lua_CPFunction cp) -+ | saveregs -+ | mov L, CARG1 -+ | ldr RA, L:CARG1->stack -+ | str CARG1, SAVE_L -+ | ldr DISPATCH, L->glref // Setup pointer to dispatch table. -+ | ldr RB, L->top -+ | str CARG1, SAVE_PC // Any value outside of bytecode is ok. -+ | ldr RC, L->cframe -+ | add DISPATCH, DISPATCH, #GG_G2DISP -+ | sub RA, RA, RB // Compute -savestack(L, L->top). -+ | mov RB, #0 -+ | str RA, SAVE_NRES // Neg. delta means cframe w/o frame. -+ | str RB, SAVE_ERRF // No error function. -+ | str RC, SAVE_CFRAME -+ | str sp, L->cframe // Add our C frame to cframe chain. -+ | str L, [DISPATCH, #DISPATCH_GL(cur_L)] -+ | blx CARG4 // (lua_State *L, lua_CFunction func, void *ud) -+ | movs BASE, CRET1 -+ | mov PC, #FRAME_CP -+ | bne <3 // Else continue with the call. -+ | b ->vm_leave_cp // No base? Just remove C frame. -+ | -+ |//----------------------------------------------------------------------- -+ |//-- Metamethod handling ------------------------------------------------ -+ |//----------------------------------------------------------------------- -+ | -+ |//-- Continuation dispatch ---------------------------------------------- -+ | -+ |->cont_dispatch: -+ | // BASE = meta base, RA = resultptr, RC = (nresults+1)*8 -+ | ldr LFUNC:CARG3, [RB, FRAME_FUNC] -+ | ldr CARG1, [BASE, #-16] // Get continuation. -+ | mov CARG4, BASE -+ | mov BASE, RB // Restore caller BASE. -+ |.if FFI -+ | cmp CARG1, #1 -+ |.endif -+ | ldr PC, [CARG4, #-12] // Restore PC from [cont|PC]. -+ | mvn INS, #~LJ_TNIL -+ | add CARG2, RA, RC -+ | str INS, [CARG2, #-4] // Ensure one valid arg. -+ |.if FFI -+ | bls >1 -+ |.endif -+ | ldr CARG3, LFUNC:CARG3->field_pc -+ | ldr KBASE, [CARG3, #PC2PROTO(k)] -+ | // BASE = base, RA = resultptr, CARG4 = meta base -+ | bx CARG1 -+ | -+ |.if FFI -+ |1: -+ | beq ->cont_ffi_callback // cont = 1: return from FFI callback. -+ | // cont = 0: tailcall from C function. -+ | sub CARG4, CARG4, #16 -+ | sub RC, CARG4, BASE -+ | b ->vm_call_tail -+ |.endif -+ | -+ |->cont_cat: // RA = resultptr, CARG4 = meta base -+ | ldr INS, [PC, #-4] -+ | sub CARG2, CARG4, #16 -+ | ldrd CARG3, CARG4, [RA] -+ | str BASE, L->base -+ | decode_RB8 RC, INS -+ | decode_RA8 RA, INS -+ | add CARG1, BASE, RC -+ | subs CARG1, CARG2, CARG1 -+ | itt ne -+ | strdne CARG3, CARG4, [CARG2] -+ | movne CARG3, CARG1 -+ | bne ->BC_CAT_Z -+ | strd_i CARG3, CARG4, BASE, RA -+ | b ->cont_nop -+ | -+ |//-- Table indexing metamethods ----------------------------------------- -+ | -+ |->vmeta_tgets1: -+ | add CARG2, BASE, RB -+ | b >2 -+ | -+ |->vmeta_tgets: -+ | sub CARG2, DISPATCH, #-DISPATCH_GL(tmptv) -+ | mvn CARG4, #~LJ_TTAB -+ | str TAB:RB, [CARG2] -+ | str CARG4, [CARG2, #4] -+ |2: -+ | mvn CARG4, #~LJ_TSTR -+ | str STR:RC, TMPDlo -+ | str CARG4, TMPDhi -+ | mov CARG3, TMPDp -+ | b >1 -+ | -+ |->vmeta_tgetb: // RC = index -+ | decode_RB8 RB, INS -+ | str RC, TMPDlo -+ | mvn CARG4, #~LJ_TISNUM -+ | add CARG2, BASE, RB -+ | str CARG4, TMPDhi -+ | mov CARG3, TMPDp -+ | b >1 -+ | -+ |->vmeta_tgetv: -+ | add CARG2, BASE, RB -+ | add CARG3, BASE, RC -+ |1: -+ | str BASE, L->base -+ | mov CARG1, L -+ | str PC, SAVE_PC -+ | bl extern lj_meta_tget // (lua_State *L, TValue *o, TValue *k) -+ | // Returns TValue * (finished) or NULL (metamethod). -+ | .IOS ldr BASE, L->base -+ | cmp CRET1, #0 -+ | beq >3 -+ | ldrd CARG3, CARG4, [CRET1] -+ | ins_next1 -+ | ins_next2 -+ | strd_i CARG3, CARG4, BASE, RA -+ | ins_next3 -+ | -+ |3: // Call __index metamethod. -+ | // BASE = base, L->top = new base, stack = cont/func/t/k -+ | rsb CARG1, BASE, #FRAME_CONT -+ | ldr BASE, L->top -+ | mov NARGS8:RC, #16 // 2 args for func(t, k). -+ | str PC, [BASE, #-12] // [cont|PC] -+ | add PC, CARG1, BASE -+ | ldr LFUNC:CARG3, [BASE, FRAME_FUNC] // Guaranteed to be a function here. -+ | b ->vm_call_dispatch_f -+ | -+ |->vmeta_tgetr: -+ | .IOS mov RC, BASE -+ | bl extern lj_tab_getinth // (GCtab *t, int32_t key) -+ | // Returns cTValue * or NULL. -+ | .IOS mov BASE, RC -+ | cmp CRET1, #0 -+ | ite ne -+ | ldrdne CARG1, CARG2, [CRET1] -+ | mvneq CARG2, #~LJ_TNIL -+ | b ->BC_TGETR_Z -+ | -+ |//----------------------------------------------------------------------- -+ | -+ |->vmeta_tsets1: -+ | add CARG2, BASE, RB -+ | b >2 -+ | -+ |->vmeta_tsets: -+ | sub CARG2, DISPATCH, #-DISPATCH_GL(tmptv) -+ | mvn CARG4, #~LJ_TTAB -+ | str TAB:RB, [CARG2] -+ | str CARG4, [CARG2, #4] -+ |2: -+ | mvn CARG4, #~LJ_TSTR -+ | str STR:RC, TMPDlo -+ | str CARG4, TMPDhi -+ | mov CARG3, TMPDp -+ | b >1 -+ | -+ |->vmeta_tsetb: // RC = index -+ | decode_RB8 RB, INS -+ | str RC, TMPDlo -+ | mvn CARG4, #~LJ_TISNUM -+ | add CARG2, BASE, RB -+ | str CARG4, TMPDhi -+ | mov CARG3, TMPDp -+ | b >1 -+ | -+ |->vmeta_tsetv: -+ | add CARG2, BASE, RB -+ | add CARG3, BASE, RC -+ |1: -+ | str BASE, L->base -+ | mov CARG1, L -+ | str PC, SAVE_PC -+ | bl extern lj_meta_tset // (lua_State *L, TValue *o, TValue *k) -+ | // Returns TValue * (finished) or NULL (metamethod). -+ | .IOS ldr BASE, L->base -+ | cmp CRET1, #0 -+ | ldrd_i CARG3, CARG4, BASE, RA -+ | beq >3 -+ | ins_next1 -+ | // NOBARRIER: lj_meta_tset ensures the table is not black. -+ | strd CARG3, CARG4, [CRET1] -+ | ins_next2 -+ | ins_next3 -+ | -+ |3: // Call __newindex metamethod. -+ | // BASE = base, L->top = new base, stack = cont/func/t/k/(v) -+ | rsb CARG1, BASE, #FRAME_CONT -+ | ldr BASE, L->top -+ | mov NARGS8:RC, #24 // 3 args for func(t, k, v). -+ | strd CARG3, CARG4, [BASE, #16] // Copy value to third argument. -+ | str PC, [BASE, #-12] // [cont|PC] -+ | add PC, CARG1, BASE -+ | ldr LFUNC:CARG3, [BASE, FRAME_FUNC] // Guaranteed to be a function here. -+ | b ->vm_call_dispatch_f -+ | -+ |->vmeta_tsetr: -+ | str BASE, L->base -+ | .IOS mov RC, BASE -+ | mov CARG1, L -+ | str PC, SAVE_PC -+ | bl extern lj_tab_setinth // (lua_State *L, GCtab *t, int32_t key) -+ | // Returns TValue *. -+ | .IOS mov BASE, RC -+ | b ->BC_TSETR_Z -+ | -+ |//-- Comparison metamethods --------------------------------------------- -+ | -+ |->vmeta_comp: -+ | mov CARG1, L -+ | sub PC, PC, #4 -+ | mov CARG2, RA -+ | str BASE, L->base -+ | mov CARG3, RC -+ | str PC, SAVE_PC -+ | decode_OP CARG4, INS -+ | bl extern lj_meta_comp // (lua_State *L, TValue *o1, *o2, int op) -+ | // Returns 0/1 or TValue * (metamethod). -+ |3: -+ | .IOS ldr BASE, L->base -+ | cmp CRET1, #1 -+ | bhi ->vmeta_binop -+ |4: -+ | ldrh RB, [PC, #2] -+ | add PC, PC, #4 -+ | add RB, PC, RB, lsl #2 -+ | it hs -+ | subhs PC, RB, #0x20000 -+ |->cont_nop: -+ | ins_next -+ | -+ |->cont_ra: // RA = resultptr -+ | ldr INS, [PC, #-4] -+ | ldrd CARG1, CARG2, [RA] -+ | decode_RA8 CARG3, INS -+ | strd_i CARG1, CARG2, BASE, CARG3 -+ | b ->cont_nop -+ | -+ |->cont_condt: // RA = resultptr -+ | ldr CARG2, [RA, #4] -+ | mvn CARG1, #~LJ_TTRUE -+ | cmp CARG1, CARG2 // Branch if result is true. -+ | b <4 -+ | -+ |->cont_condf: // RA = resultptr -+ | ldr CARG2, [RA, #4] -+ | checktp CARG2, LJ_TFALSE // Branch if result is false. -+ | b <4 -+ | -+ |->vmeta_equal: -+ | // CARG2, CARG3, CARG4 are already set by BC_ISEQV/BC_ISNEV. -+ | sub PC, PC, #4 -+ | str BASE, L->base -+ | mov CARG1, L -+ | str PC, SAVE_PC -+ | bl extern lj_meta_equal // (lua_State *L, GCobj *o1, *o2, int ne) -+ | // Returns 0/1 or TValue * (metamethod). -+ | b <3 -+ | -+ |->vmeta_equal_cd: -+ |.if FFI -+ | sub PC, PC, #4 -+ | str BASE, L->base -+ | mov CARG1, L -+ | mov CARG2, INS -+ | str PC, SAVE_PC -+ | bl extern lj_meta_equal_cd // (lua_State *L, BCIns op) -+ | // Returns 0/1 or TValue * (metamethod). -+ | b <3 -+ |.endif -+ | -+ |->vmeta_istype: -+ | sub PC, PC, #4 -+ | str BASE, L->base -+ | mov CARG1, L -+ | lsr CARG2, RA, #3 -+ | mov CARG3, RC -+ | str PC, SAVE_PC -+ | bl extern lj_meta_istype // (lua_State *L, BCReg ra, BCReg tp) -+ | .IOS ldr BASE, L->base -+ | b ->cont_nop -+ | -+ |//-- Arithmetic metamethods --------------------------------------------- -+ | -+ |->vmeta_arith_vn: -+ | decode_RB8 RB, INS -+ | decode_RC8 RC, INS -+ | add CARG3, BASE, RB -+ | add CARG4, KBASE, RC -+ | b >1 -+ | -+ |->vmeta_arith_nv: -+ | decode_RB8 RB, INS -+ | decode_RC8 RC, INS -+ | add CARG4, BASE, RB -+ | add CARG3, KBASE, RC -+ | b >1 -+ | -+ |->vmeta_unm: -+ | ldr INS, [PC, #-8] -+ | sub PC, PC, #4 -+ | add CARG3, BASE, RC -+ | add CARG4, BASE, RC -+ | b >1 -+ | -+ |->vmeta_arith_vv: -+ | decode_RB8 RB, INS -+ | decode_RC8 RC, INS -+ | add CARG3, BASE, RB -+ | add CARG4, BASE, RC -+ |1: -+ | decode_OP OP, INS -+ | add CARG2, BASE, RA -+ | str BASE, L->base -+ | mov CARG1, L -+ | str PC, SAVE_PC -+ | str OP, ARG5 -+ | bl extern lj_meta_arith // (lua_State *L, TValue *ra,*rb,*rc, BCReg op) -+ | // Returns NULL (finished) or TValue * (metamethod). -+ | .IOS ldr BASE, L->base -+ | cmp CRET1, #0 -+ | beq ->cont_nop -+ | -+ | // Call metamethod for binary op. -+ |->vmeta_binop: -+ | // BASE = old base, CRET1 = new base, stack = cont/func/o1/o2 -+ | sub CARG2, CRET1, BASE -+ | str PC, [CRET1, #-12] // [cont|PC] -+ | add PC, CARG2, #FRAME_CONT -+ | mov BASE, CRET1 -+ | mov NARGS8:RC, #16 // 2 args for func(o1, o2). -+ | b ->vm_call_dispatch -+ | -+ |->vmeta_len: -+ | add CARG2, BASE, RC -+ | str BASE, L->base -+ | mov CARG1, L -+ | str PC, SAVE_PC -+ | bl extern lj_meta_len // (lua_State *L, TValue *o) -+ | // Returns NULL (retry) or TValue * (metamethod base). -+ | .IOS ldr BASE, L->base -+#if LJ_52 -+ | cmp CRET1, #0 -+ | bne ->vmeta_binop // Binop call for compatibility. -+ | ldr TAB:CARG1, [BASE, RC] -+ | b ->BC_LEN_Z -+#else -+ | b ->vmeta_binop // Binop call for compatibility. -+#endif -+ | -+ |//-- Call metamethod ---------------------------------------------------- -+ | -+ |->vmeta_call: // Resolve and call __call metamethod. -+ | // RB = old base, BASE = new base, RC = nargs*8 -+ | mov CARG1, L -+ | str RB, L->base // This is the callers base! -+ | sub CARG2, BASE, #8 -+ | str PC, SAVE_PC -+ | add CARG3, BASE, NARGS8:RC -+ | .IOS mov RA, BASE -+ | bl extern lj_meta_call // (lua_State *L, TValue *func, TValue *top) -+ | .IOS mov BASE, RA -+ | ldr LFUNC:CARG3, [BASE, FRAME_FUNC] // Guaranteed to be a function here. -+ | add NARGS8:RC, NARGS8:RC, #8 // Got one more argument now. -+ | ins_call -+ | -+ |->vmeta_callt: // Resolve __call for BC_CALLT. -+ | // BASE = old base, RA = new base, RC = nargs*8 -+ | mov CARG1, L -+ | str BASE, L->base -+ | sub CARG2, RA, #8 -+ | str PC, SAVE_PC -+ | add CARG3, RA, NARGS8:RC -+ | bl extern lj_meta_call // (lua_State *L, TValue *func, TValue *top) -+ | .IOS ldr BASE, L->base -+ | ldr LFUNC:CARG3, [RA, FRAME_FUNC] // Guaranteed to be a function here. -+ | ldr PC, [BASE, FRAME_PC] -+ | add NARGS8:RC, NARGS8:RC, #8 // Got one more argument now. -+ | b ->BC_CALLT2_Z -+ | -+ |//-- Argument coercion for 'for' statement ------------------------------ -+ | -+ |->vmeta_for: -+ | mov CARG1, L -+ | str BASE, L->base -+ | mov CARG2, RA -+ | str PC, SAVE_PC -+ | bl extern lj_meta_for // (lua_State *L, TValue *base) -+ | .IOS ldr BASE, L->base -+ |.if JIT -+ | ldrb OP, [PC, #-4] -+ |.endif -+ | ldr INS, [PC, #-4] -+ |.if JIT -+ | cmp OP, #BC_JFORI -+ |.endif -+ | decode_RA8 RA, INS -+ | decode_RD RC, INS -+ |.if JIT -+ | beq =>BC_JFORI -+ |.endif -+ | b =>BC_FORI -+ | -+ |//----------------------------------------------------------------------- -+ |//-- Fast functions ----------------------------------------------------- -+ |//----------------------------------------------------------------------- -+ | -+ |.macro .ffunc, name -+ |->ff_ .. name: -+ |.endmacro -+ | -+ |.macro .ffunc_1, name -+ |->ff_ .. name: -+ | ldrd CARG1, CARG2, [BASE] -+ | cmp NARGS8:RC, #8 -+ | blo ->fff_fallback -+ |.endmacro -+ | -+ |.macro .ffunc_2, name -+ |->ff_ .. name: -+ | ldrd CARG1, CARG2, [BASE] -+ | ldrd CARG3, CARG4, [BASE, #8] -+ | cmp NARGS8:RC, #16 -+ | blo ->fff_fallback -+ |.endmacro -+ | -+ |.macro .ffunc_n, name -+ | .ffunc_1 name -+ | checktp CARG2, LJ_TISNUM -+ | bhs ->fff_fallback -+ |.endmacro -+ | -+ |.macro .ffunc_nn, name -+ | .ffunc_2 name -+ | checktp CARG2, LJ_TISNUM -+ | it lo -+ | cmnlo CARG4, #-LJ_TISNUM -+ | bhs ->fff_fallback -+ |.endmacro -+ | -+ |.macro .ffunc_d, name -+ | .ffunc name -+ | ldr CARG2, [BASE, #4] -+ | cmp NARGS8:RC, #8 -+ | vldr d0, [BASE] -+ | blo ->fff_fallback -+ | checktp CARG2, LJ_TISNUM -+ | bhs ->fff_fallback -+ |.endmacro -+ | -+ |.macro .ffunc_dd, name -+ | .ffunc name -+ | ldr CARG2, [BASE, #4] -+ | ldr CARG4, [BASE, #12] -+ | cmp NARGS8:RC, #16 -+ | vldr d0, [BASE] -+ | vldr d1, [BASE, #8] -+ | blo ->fff_fallback -+ | checktp CARG2, LJ_TISNUM -+ | it lo -+ | cmnlo CARG4, #-LJ_TISNUM -+ | bhs ->fff_fallback -+ |.endmacro -+ | -+ |// Inlined GC threshold check. Caveat: uses CARG1 and CARG2. -+ |.macro ffgccheck -+ | sub CARG1, DISPATCH, #-DISPATCH_GL(gc.total) -+ | ldr CARG1, [CARG1] -+ | sub CARG2, DISPATCH, #-DISPATCH_GL(gc.threshold) -+ | ldr CARG2, [CARG2] -+ | cmp CARG1, CARG2 -+ | it ge -+ | blge ->fff_gcstep -+ |.endmacro -+ | -+ |//-- Base library: checks ----------------------------------------------- -+ | -+ |.ffunc_1 assert -+ | checktp CARG2, LJ_TTRUE -+ | bhi ->fff_fallback -+ | ldr PC, [BASE, FRAME_PC] -+ | strd CARG1, CARG2, [BASE, #-8] -+ | mov RB, BASE -+ | subs RA, NARGS8:RC, #8 -+ | add RC, NARGS8:RC, #8 // Compute (nresults+1)*8. -+ | beq ->fff_res // Done if exactly 1 argument. -+ |1: -+ | ldrd CARG1, CARG2, [RB, #8] -+ | subs RA, RA, #8 -+ | strd CARG1, CARG2, [RB], #8 -+ | bne <1 -+ | b ->fff_res -+ | -+ |.ffunc type -+ | ldr CARG2, [BASE, #4] -+ | cmp NARGS8:RC, #8 -+ | blo ->fff_fallback -+ | checktp CARG2, LJ_TISNUM -+ | it lo -+ | mvnlo CARG2, #~LJ_TISNUM -+ | rsb CARG4, CARG2, #(int)(offsetof(GCfuncC, upvalue)>>3)-1 -+ | lsl CARG4, CARG4, #3 -+ | ldrd_i CARG1, CARG2, CFUNC:CARG3, CARG4 -+ | b ->fff_restv -+ | -+ |//-- Base library: getters and setters --------------------------------- -+ | -+ |.ffunc_1 getmetatable -+ | checktp CARG2, LJ_TTAB -+ | it ne -+ | cmnne CARG2, #-LJ_TUDATA -+ | bne >6 -+ |1: // Field metatable must be at same offset for GCtab and GCudata! -+ | ldr TAB:RB, TAB:CARG1->metatable -+ |2: -+ | mvn CARG2, #~LJ_TNIL -+ | ldr STR:RC, [DISPATCH, #DISPATCH_GL(gcroot[GCROOT_MMNAME+MM_metatable])] -+ | cmp TAB:RB, #0 -+ | beq ->fff_restv -+ | ldr CARG3, TAB:RB->hmask -+ | ldr CARG4, STR:RC->sid -+ | ldr NODE:INS, TAB:RB->node -+ | and CARG3, CARG3, CARG4 // idx = str->sid & tab->hmask -+ | add CARG3, CARG3, CARG3, lsl #1 -+ | add NODE:INS, NODE:INS, CARG3, lsl #3 // node = tab->node + idx*3*8 -+ |3: // Rearranged logic, because we expect _not_ to find the key. -+ | ldrd CARG3, CARG4, NODE:INS->key // STALL: early NODE:INS. -+ | ldrd CARG1, CARG2, NODE:INS->val -+ | ldr NODE:INS, NODE:INS->next -+ | checktp CARG4, LJ_TSTR -+ | it eq -+ | cmpeq CARG3, STR:RC -+ | beq >5 -+ | cmp NODE:INS, #0 -+ | bne <3 -+ |4: -+ | mov CARG1, RB // Use metatable as default result. -+ | mvn CARG2, #~LJ_TTAB -+ | b ->fff_restv -+ |5: -+ | checktp CARG2, LJ_TNIL -+ | bne ->fff_restv -+ | b <4 -+ | -+ |6: -+ | checktp CARG2, LJ_TISNUM -+ | ite hs -+ | mvnhs CARG2, CARG2 -+ | movlo CARG2, #~LJ_TISNUM -+ | add CARG4, DISPATCH, CARG2, lsl #2 -+ | ldr TAB:RB, [CARG4, #DISPATCH_GL(gcroot[GCROOT_BASEMT])] -+ | b <2 -+ | -+ |.ffunc_2 setmetatable -+ | // Fast path: no mt for table yet and not clearing the mt. -+ | checktp CARG2, LJ_TTAB -+ | it eq -+ | ldreq TAB:RB, TAB:CARG1->metatable -+ | checktpeq CARG4, LJ_TTAB -+ | it eq -+ | ldrbeq CARG4, TAB:CARG1->marked -+ | it eq -+ | cmpeq TAB:RB, #0 -+ | bne ->fff_fallback -+ | tst CARG4, #LJ_GC_BLACK // isblack(table) -+ | str TAB:CARG3, TAB:CARG1->metatable -+ | beq ->fff_restv -+ | barrierback TAB:CARG1, CARG4, CARG3 -+ | b ->fff_restv -+ | -+ |.ffunc rawget -+ | ldrd CARG3, CARG4, [BASE] -+ | cmp NARGS8:RC, #16 -+ | blo ->fff_fallback -+ | mov CARG2, CARG3 -+ | checktab CARG4, ->fff_fallback -+ | mov CARG1, L -+ | add CARG3, BASE, #8 -+ | .IOS mov RA, BASE -+ | bl extern lj_tab_get // (lua_State *L, GCtab *t, cTValue *key) -+ | // Returns cTValue *. -+ | .IOS mov BASE, RA -+ | ldrd CARG1, CARG2, [CRET1] -+ | b ->fff_restv -+ | -+ |//-- Base library: conversions ------------------------------------------ -+ | -+ |.ffunc tonumber -+ | // Only handles the number case inline (without a base argument). -+ | ldrd CARG1, CARG2, [BASE] -+ | cmp NARGS8:RC, #8 -+ | bne ->fff_fallback -+ | checktp CARG2, LJ_TISNUM -+ | bls ->fff_restv -+ | b ->fff_fallback -+ | -+ |.ffunc_1 tostring -+ | // Only handles the string or number case inline. -+ | checktp CARG2, LJ_TSTR -+ | // A __tostring method in the string base metatable is ignored. -+ | beq ->fff_restv -+ | // Handle numbers inline, unless a number base metatable is present. -+ | ldr CARG4, [DISPATCH, #DISPATCH_GL(gcroot[GCROOT_BASEMT_NUM])] -+ | str BASE, L->base -+ | checktp CARG2, LJ_TISNUM -+ | it ls -+ | cmpls CARG4, #0 -+ | str PC, SAVE_PC // Redundant (but a defined value). -+ | bhi ->fff_fallback -+ | ffgccheck -+ | mov CARG1, L -+ | mov CARG2, BASE -+ | bl extern lj_strfmt_number // (lua_State *L, cTValue *o) -+ | // Returns GCstr *. -+ | ldr BASE, L->base -+ | mvn CARG2, #~LJ_TSTR -+ | b ->fff_restv -+ | -+ |//-- Base library: iterators ------------------------------------------- -+ | -+ |.ffunc_1 next -+ | mvn CARG4, #~LJ_TNIL -+ | checktab CARG2, ->fff_fallback -+ | strd_i CARG3, CARG4, BASE, NARGS8:RC // Set missing 2nd arg to nil. -+ | ldr PC, [BASE, FRAME_PC] -+ | add CARG2, BASE, #8 -+ | sub CARG3, BASE, #8 -+ | bl extern lj_tab_next // (GCtab *t, cTValue *key, TValue *o) -+ | // Returns 1=found, 0=end, -1=error. -+ | .IOS ldr BASE, L->base -+ | cmp CRET1, #0 -+ | mov RC, #(2+1)*8 -+ | bgt ->fff_res // Found key/value. -+ | bmi ->fff_fallback // Invalid key. -+ | // End of traversal: return nil. -+ | mvn CRET2, #~LJ_TNIL -+ | b ->fff_restv -+ | -+ |.ffunc_1 pairs -+ | checktab CARG2, ->fff_fallback -+#if LJ_52 -+ | ldr TAB:RB, TAB:CARG1->metatable -+#endif -+ | ldrd CFUNC:CARG3, CFUNC:CARG4, CFUNC:CARG3->upvalue[0] -+ | ldr PC, [BASE, FRAME_PC] -+#if LJ_52 -+ | cmp TAB:RB, #0 -+ | bne ->fff_fallback -+#endif -+ | mvn CARG2, #~LJ_TNIL -+ | mov RC, #(3+1)*8 -+ | strd CFUNC:CARG3, CFUNC:CARG4, [BASE, #-8] -+ | str CARG2, [BASE, #12] -+ | b ->fff_res -+ | -+ |.ffunc_2 ipairs_aux -+ | checktp CARG2, LJ_TTAB -+ | checktpeq CARG4, LJ_TISNUM -+ | bne ->fff_fallback -+ | ldr RB, TAB:CARG1->asize -+ | ldr RC, TAB:CARG1->array -+ | add CARG3, CARG3, #1 -+ | ldr PC, [BASE, FRAME_PC] -+ | cmp CARG3, RB -+ | add RC, RC, CARG3, lsl #3 -+ | strd CARG3, CARG4, [BASE, #-8] -+ | it lo -+ | ldrdlo CARG1, CARG2, [RC] -+ | mov RC, #(0+1)*8 -+ | bhs >2 // Not in array part? -+ |1: -+ | checktp CARG2, LJ_TNIL -+ | itt ne -+ | movne RC, #(2+1)*8 -+ | strdne CARG1, CARG2, [BASE] -+ | b ->fff_res -+ |2: // Check for empty hash part first. Otherwise call C function. -+ | ldr RB, TAB:CARG1->hmask -+ | mov CARG2, CARG3 -+ | cmp RB, #0 -+ | beq ->fff_res -+ | .IOS mov RA, BASE -+ | bl extern lj_tab_getinth // (GCtab *t, int32_t key) -+ | // Returns cTValue * or NULL. -+ | .IOS mov BASE, RA -+ | cmp CRET1, #0 -+ | beq ->fff_res -+ | ldrd CARG1, CARG2, [CRET1] -+ | b <1 -+ | -+ |.ffunc_1 ipairs -+ | checktab CARG2, ->fff_fallback -+#if LJ_52 -+ | ldr TAB:RB, TAB:CARG1->metatable -+#endif -+ | ldrd CFUNC:CARG3, CFUNC:CARG4, CFUNC:CARG3->upvalue[0] -+ | ldr PC, [BASE, FRAME_PC] -+#if LJ_52 -+ | cmp TAB:RB, #0 -+ | bne ->fff_fallback -+#endif -+ | mov CARG1, #0 -+ | mvn CARG2, #~LJ_TISNUM -+ | mov RC, #(3+1)*8 -+ | strd CFUNC:CARG3, CFUNC:CARG4, [BASE, #-8] -+ | strd CARG1, CARG2, [BASE, #8] -+ | b ->fff_res -+ | -+ |//-- Base library: catch errors ---------------------------------------- -+ | -+ |.ffunc pcall -+ | sub RA, DISPATCH, #-DISPATCH_GL(hookmask) -+ | ldrb RA, [RA] -+ | cmp NARGS8:RC, #8 -+ | blo ->fff_fallback -+ | tst RA, #HOOK_ACTIVE // Remember active hook before pcall. -+ | mov RB, BASE -+ | add BASE, BASE, #8 -+ | ite eq -+ | moveq PC, #8+FRAME_PCALL -+ | movne PC, #8+FRAME_PCALLH -+ | sub NARGS8:RC, NARGS8:RC, #8 -+ | b ->vm_call_dispatch -+ | -+ |.ffunc_2 xpcall -+ | sub RA, DISPATCH, #-DISPATCH_GL(hookmask) -+ | ldrb RA, [RA] -+ | checkfunc CARG4, ->fff_fallback // Traceback must be a function. -+ | mov RB, BASE -+ | strd CARG1, CARG2, [BASE, #8] // Swap function and traceback. -+ | strd CARG3, CARG4, [BASE] -+ | tst RA, #HOOK_ACTIVE // Remember active hook before pcall. -+ | add BASE, BASE, #16 -+ | ite eq -+ | moveq PC, #16+FRAME_PCALL -+ | movne PC, #16+FRAME_PCALLH -+ | sub NARGS8:RC, NARGS8:RC, #16 -+ | b ->vm_call_dispatch -+ | -+ |//-- Coroutine library -------------------------------------------------- -+ | -+ |.macro coroutine_resume_wrap, resume -+ |.if resume -+ |.ffunc_1 coroutine_resume -+ | checktp CARG2, LJ_TTHREAD -+ | bne ->fff_fallback -+ |.else -+ |.ffunc coroutine_wrap_aux -+ | ldr L:CARG1, CFUNC:CARG3->upvalue[0].gcr -+ |.endif -+ | ldr PC, [BASE, FRAME_PC] -+ | str BASE, L->base -+ | ldr CARG2, L:CARG1->top -+ | ldrb RA, L:CARG1->status -+ | ldr RB, L:CARG1->base -+ | add CARG3, CARG2, NARGS8:RC -+ | add CARG4, CARG2, RA -+ | str PC, SAVE_PC -+ | cmp CARG4, RB -+ | beq ->fff_fallback -+ | ldr CARG4, L:CARG1->maxstack -+ | ldr RB, L:CARG1->cframe -+ | cmp RA, #LUA_YIELD -+ | it ls -+ | cmpls CARG3, CARG4 -+ | it ls -+ | cmpls RB, #0 -+ | bhi ->fff_fallback -+ |1: -+ |.if resume -+ | sub CARG3, CARG3, #8 // Keep resumed thread in stack for GC. -+ | add BASE, BASE, #8 -+ | sub NARGS8:RC, NARGS8:RC, #8 -+ |.endif -+ | str CARG3, L:CARG1->top -+ | str BASE, L->top -+ |2: // Move args to coroutine. -+ | ldrd_i CARG3, CARG4, BASE, RB -+ | cmp RB, NARGS8:RC -+ | strdne_i CARG3, CARG4, CARG2, RB -+ | add RB, RB, #8 -+ | bne <2 -+ | -+ | mov CARG3, #0 -+ | mov L:RA, L:CARG1 -+ | mov CARG4, #0 -+ | bl ->vm_resume // (lua_State *L, TValue *base, 0, 0) -+ | // Returns thread status. -+ |4: -+ | ldr CARG3, L:RA->base -+ | mv_vmstate CARG2, INTERP -+ | ldr CARG4, L:RA->top -+ | cmp CRET1, #LUA_YIELD -+ | ldr BASE, L->base -+ | str L, [DISPATCH, #DISPATCH_GL(cur_L)] -+ | st_vmstate CARG2 -+ | bhi >8 -+ | subs RC, CARG4, CARG3 -+ | ldr CARG1, L->maxstack -+ | add CARG2, BASE, RC -+ | beq >6 // No results? -+ | cmp CARG2, CARG1 -+ | mov RB, #0 -+ | bhi >9 // Need to grow stack? -+ | -+ | sub CARG4, RC, #8 -+ | str CARG3, L:RA->top // Clear coroutine stack. -+ |5: // Move results from coroutine. -+ | ldrd_i CARG1, CARG2, CARG3, RB -+ | cmp RB, CARG4 -+ | strd_i CARG1, CARG2, BASE, RB -+ | add RB, RB, #8 -+ | bne <5 -+ |6: -+ |.if resume -+ | mvn CARG3, #~LJ_TTRUE -+ | add RC, RC, #16 -+ |7: -+ | str CARG3, [BASE, #-4] // Prepend true/false to results. -+ | sub RA, BASE, #8 -+ |.else -+ | mov RA, BASE -+ | add RC, RC, #8 -+ |.endif -+ | ands CARG1, PC, #FRAME_TYPE -+ | str PC, SAVE_PC -+ | str RC, SAVE_MULTRES -+ | beq ->BC_RET_Z -+ | b ->vm_return -+ | -+ |8: // Coroutine returned with error (at co->top-1). -+ |.if resume -+ | ldrd CARG1, CARG2, [CARG4, #-8]! -+ | mvn CARG3, #~LJ_TFALSE -+ | mov RC, #(2+1)*8 -+ | str CARG4, L:RA->top // Remove error from coroutine stack. -+ | strd CARG1, CARG2, [BASE] // Copy error message. -+ | b <7 -+ |.else -+ | mov CARG1, L -+ | mov CARG2, L:RA -+ | bl extern lj_ffh_coroutine_wrap_err // (lua_State *L, lua_State *co) -+ | // Never returns. -+ |.endif -+ | -+ |9: // Handle stack expansion on return from yield. -+ | mov CARG1, L -+ | lsr CARG2, RC, #3 -+ | bl extern lj_state_growstack // (lua_State *L, int n) -+ | mov CRET1, #0 -+ | b <4 -+ |.endmacro -+ | -+ | coroutine_resume_wrap 1 // coroutine.resume -+ | coroutine_resume_wrap 0 // coroutine.wrap -+ | -+ |.ffunc coroutine_yield -+ | ldr CARG1, L->cframe -+ | add CARG2, BASE, NARGS8:RC -+ | str BASE, L->base -+ | tst CARG1, #CFRAME_RESUME -+ | str CARG2, L->top -+ | mov CRET1, #LUA_YIELD -+ | mov CARG3, #0 -+ | beq ->fff_fallback -+ | str CARG3, L->cframe -+ | strb CRET1, L->status -+ | b ->vm_leave_unw -+ | -+ |//-- Math library ------------------------------------------------------- -+ | -+ |.macro math_round, func -+ | .ffunc_1 math_ .. func -+ | checktp CARG2, LJ_TISNUM -+ | beq ->fff_restv -+ | bhi ->fff_fallback -+ | // Round FP value and normalize result. -+ | lsl CARG3, CARG2, #1 -+ | adds RB, CARG3, #0x00200000 -+ | bpl >2 // |x| < 1? -+ | mvn CARG4, #0x3e0 -+ | subs RB, CARG4, RB, asr #21 -+ | lsl CARG4, CARG2, #11 -+ | lsl CARG3, CARG1, #11 -+ | orr CARG4, CARG4, #0x80000000 -+ | rsb INS, RB, #32 -+ | orr CARG4, CARG4, CARG1, lsr #21 -+ | bls >3 // |x| >= 2^31? -+ | lsl CARG1, CARG4, INS -+ | orr CARG3, CARG3, CARG1 -+ | lsr CARG1, CARG4, RB -+ |.if "func" == "floor" -+ | tst CARG3, CARG2, asr #31 -+ | it ne -+ | addne CARG1, CARG1, #1 -+ |.else -+ | bics CARG3, CARG3, CARG2, asr #31 -+ | it ne -+ | addsne CARG1, CARG1, #1 -+ | it vs -+ | ldrdvs CARG1, CARG2, >9 -+ | bvs ->fff_restv -+ |.endif -+ | cmp CARG2, #0 -+ | it lt -+ | rsblt CARG1, CARG1, #0 -+ |1: -+ | mvn CARG2, #~LJ_TISNUM -+ | b ->fff_restv -+ | -+ |2: // |x| < 1 -+ | bcs ->fff_restv // |x| is not finite. -+ | orr CARG3, CARG3, CARG1 // ztest = abs(hi) | lo -+ |.if "func" == "floor" -+ | tst CARG3, CARG2, asr #31 // return (ztest & sign) == 0 ? 0 : -1 -+ | ite eq -+ | moveq CARG1, #0 -+ | mvnne CARG1, #0 -+ |.else -+ | bics CARG3, CARG3, CARG2, asr #31 // return (ztest & ~sign) == 0 ? 0 : 1 -+ | ite eq -+ | moveq CARG1, #0 -+ | movne CARG1, #1 -+ |.endif -+ | mvn CARG2, #~LJ_TISNUM -+ | b ->fff_restv -+ | -+ |3: // |x| >= 2^31. Check for x == -(2^31). -+ | it eq -+ | cmpeq CARG4, #0x80000000 -+ |.if "func" == "floor" -+ | it eq -+ | cmpeq CARG3, #0 -+ |.endif -+ | bne >4 -+ | cmp CARG2, #0 -+ | it mi -+ | movmi CARG1, #0x80000000 -+ | bmi <1 -+ |4: -+ | bl ->vm_..func.._sf -+ | b ->fff_restv -+ |.endmacro -+ | -+ | math_round floor -+ | math_round ceil -+ | -+ |.align 8 -+ |9: -+ | .long 0x00000000, 0x000041e0 // 2^31. jturnsek: swaped halfwords!!! -+ | -+ |.ffunc_1 math_abs -+ | checktp CARG2, LJ_TISNUM -+ | bhi ->fff_fallback -+ | it ne -+ | bicne CARG2, CARG2, #0x80000000 -+ | bne ->fff_restv -+ | cmp CARG1, #0 -+ | it lt -+ | rsbslt CARG1, CARG1, #0 -+ | it vs -+ | ldrdvs CARG1, CARG2, <9 -+ | // Fallthrough. -+ | -+ |->fff_restv: -+ | // CARG1, CARG2 = TValue result. -+ | ldr PC, [BASE, FRAME_PC] -+ | strd CARG1, CARG2, [BASE, #-8] -+ |->fff_res1: -+ | // PC = return. -+ | mov RC, #(1+1)*8 -+ |->fff_res: -+ | // RC = (nresults+1)*8, PC = return. -+ | ands CARG1, PC, #FRAME_TYPE -+ | it eq -+ | ldreq INS, [PC, #-4] -+ | str RC, SAVE_MULTRES -+ | sub RA, BASE, #8 -+ | bne ->vm_return -+ | decode_RB8 RB, INS -+ |5: -+ | cmp RB, RC // More results expected? -+ | bhi >6 -+ | decode_RA8 CARG1, INS -+ | ins_next1 -+ | ins_next2 -+ | // Adjust BASE. KBASE is assumed to be set for the calling frame. -+ | sub BASE, RA, CARG1 -+ | ins_next3 -+ | -+ |6: // Fill up results with nil. -+ | add CARG2, RA, RC -+ | mvn CARG1, #~LJ_TNIL -+ | add RC, RC, #8 -+ | str CARG1, [CARG2, #-4] -+ | b <5 -+ | -+ |.macro math_extern, func -+ |.if HFABI -+ | .ffunc_d math_ .. func -+ |.else -+ | .ffunc_n math_ .. func -+ |.endif -+ | .IOS mov RA, BASE -+ | bl extern func -+ | .IOS mov BASE, RA -+ |.if HFABI -+ | b ->fff_resd -+ |.else -+ | b ->fff_restv -+ |.endif -+ |.endmacro -+ | -+ |.macro math_extern2, func -+ |.if HFABI -+ | .ffunc_dd math_ .. func -+ |.else -+ | .ffunc_nn math_ .. func -+ |.endif -+ | .IOS mov RA, BASE -+ | bl extern func -+ | .IOS mov BASE, RA -+ |.if HFABI -+ | b ->fff_resd -+ |.else -+ | b ->fff_restv -+ |.endif -+ |.endmacro -+ | -+ |.if FPU -+ | .ffunc_d math_sqrt -+ | vsqrt.f64 d0, d0 -+ |->fff_resd: -+ | ldr PC, [BASE, FRAME_PC] -+ | vstr d0, [BASE, #-8] -+ | b ->fff_res1 -+ |.else -+ | math_extern sqrt -+ |.endif -+ | -+ |.ffunc math_log -+ |.if HFABI -+ | ldr CARG2, [BASE, #4] -+ | cmp NARGS8:RC, #8 // Need exactly 1 argument. -+ | vldr d0, [BASE] -+ | bne ->fff_fallback -+ |.else -+ | ldrd CARG1, CARG2, [BASE] -+ | cmp NARGS8:RC, #8 // Need exactly 1 argument. -+ | bne ->fff_fallback -+ |.endif -+ | checktp CARG2, LJ_TISNUM -+ | bhs ->fff_fallback -+ | .IOS mov RA, BASE -+ | bl extern log -+ | .IOS mov BASE, RA -+ |.if HFABI -+ | b ->fff_resd -+ |.else -+ | b ->fff_restv -+ |.endif -+ | -+ | math_extern log10 -+ | math_extern exp -+ | math_extern sin -+ | math_extern cos -+ | math_extern tan -+ | math_extern asin -+ | math_extern acos -+ | math_extern atan -+ | math_extern sinh -+ | math_extern cosh -+ | math_extern tanh -+ | math_extern2 pow -+ | math_extern2 atan2 -+ | math_extern2 fmod -+ | -+ |.if HFABI -+ | .ffunc math_ldexp -+ | ldr CARG4, [BASE, #4] -+ | ldrd CARG1, CARG2, [BASE, #8] -+ | cmp NARGS8:RC, #16 -+ | blo ->fff_fallback -+ | vldr d0, [BASE] -+ | checktp CARG4, LJ_TISNUM -+ | bhs ->fff_fallback -+ | checktp CARG2, LJ_TISNUM -+ | bne ->fff_fallback -+ | .IOS mov RA, BASE -+ | bl extern ldexp // (double x, int exp) -+ | .IOS mov BASE, RA -+ | b ->fff_resd -+ |.else -+ |.ffunc_2 math_ldexp -+ | checktp CARG2, LJ_TISNUM -+ | bhs ->fff_fallback -+ | checktp CARG4, LJ_TISNUM -+ | bne ->fff_fallback -+ | .IOS mov RA, BASE -+ | bl extern ldexp // (double x, int exp) -+ | .IOS mov BASE, RA -+ | b ->fff_restv -+ |.endif -+ | -+ |.if HFABI -+ |.ffunc_d math_frexp -+ | mov CARG1, sp -+ | .IOS mov RA, BASE -+ | bl extern frexp -+ | .IOS mov BASE, RA -+ | ldr CARG3, [sp] -+ | mvn CARG4, #~LJ_TISNUM -+ | ldr PC, [BASE, FRAME_PC] -+ | vstr d0, [BASE, #-8] -+ | mov RC, #(2+1)*8 -+ | strd CARG3, CARG4, [BASE] -+ | b ->fff_res -+ |.else -+ |.ffunc_n math_frexp -+ | mov CARG3, sp -+ | .IOS mov RA, BASE -+ | bl extern frexp -+ | .IOS mov BASE, RA -+ | ldr CARG3, [sp] -+ | mvn CARG4, #~LJ_TISNUM -+ | ldr PC, [BASE, FRAME_PC] -+ | strd CARG1, CARG2, [BASE, #-8] -+ | mov RC, #(2+1)*8 -+ | strd CARG3, CARG4, [BASE] -+ | b ->fff_res -+ |.endif -+ | -+ |.if HFABI -+ |.ffunc_d math_modf -+ | sub CARG1, BASE, #8 -+ | ldr PC, [BASE, FRAME_PC] -+ | .IOS mov RA, BASE -+ | bl extern modf -+ | .IOS mov BASE, RA -+ | mov RC, #(2+1)*8 -+ | vstr d0, [BASE] -+ | b ->fff_res -+ |.else -+ |.ffunc_n math_modf -+ | sub CARG3, BASE, #8 -+ | ldr PC, [BASE, FRAME_PC] -+ | .IOS mov RA, BASE -+ | bl extern modf -+ | .IOS mov BASE, RA -+ | mov RC, #(2+1)*8 -+ | strd CARG1, CARG2, [BASE] -+ | b ->fff_res -+ |.endif -+ | -+ |.macro math_minmax, name, cond, fcond -+ |.if FPU -+ | .ffunc_1 name -+ | add RB, BASE, RC -+ | checktp CARG2, LJ_TISNUM -+ | add RA, BASE, #8 -+ | bne >4 -+ |1: // Handle integers. -+ | ldrd CARG3, CARG4, [RA] -+ | cmp RA, RB -+ | bhs ->fff_restv -+ | checktp CARG4, LJ_TISNUM -+ | bne >3 -+ | cmp CARG1, CARG3 -+ | add RA, RA, #8 -+ | it cond -+ | mov..cond CARG1, CARG3 -+ | b <1 -+ |3: // Convert intermediate result to number and continue below. -+ | vmov s4, CARG1 -+ | bhi ->fff_fallback -+ | vldr d1, [RA] -+ | vcvt.f64.s32 d0, s4 -+ | b >6 -+ | -+ |4: -+ | vldr d0, [BASE] -+ | bhi ->fff_fallback -+ |5: // Handle numbers. -+ | ldrd CARG3, CARG4, [RA] -+ | vldr d1, [RA] -+ | cmp RA, RB -+ | bhs ->fff_resd -+ | checktp CARG4, LJ_TISNUM -+ | bhs >7 -+ |6: -+ | vcmp.f64 d0, d1 -+ | vmrs -+ | add RA, RA, #8 -+ | it fcond -+ | vmov..fcond.f64 d0, d1 -+ | b <5 -+ |7: // Convert integer to number and continue above. -+ | vmov s4, CARG3 -+ | bhi ->fff_fallback -+ | vcvt.f64.s32 d1, s4 -+ | b <6 -+ | -+ |.else -+ | -+ | .ffunc_1 name -+ | checktp CARG2, LJ_TISNUM -+ | mov RA, #8 -+ | bne >4 -+ |1: // Handle integers. -+ | ldrd_i CARG3, CARG4, BASE, RA -+ | cmp RA, RC -+ | bhs ->fff_restv -+ | checktp CARG4, LJ_TISNUM -+ | bne >3 -+ | cmp CARG1, CARG3 -+ | add RA, RA, #8 -+ | it cond -+ | mov..cond CARG1, CARG3 -+ | b <1 -+ |3: // Convert intermediate result to number and continue below. -+ | bhi ->fff_fallback -+ | bl extern __aeabi_i2d -+ | ldrd_i CARG3, CARG4, BASE, RA -+ | b >6 -+ | -+ |4: -+ | bhi ->fff_fallback -+ |5: // Handle numbers. -+ | ldrd_i CARG3, CARG4, BASE, RA -+ | cmp RA, RC -+ | bhs ->fff_restv -+ | checktp CARG4, LJ_TISNUM -+ | bhs >7 -+ |6: -+ | bl extern __aeabi_cdcmple -+ | add RA, RA, #8 -+ | mov..fcond CARG1, CARG3 -+ | mov..fcond CARG2, CARG4 -+ | b <5 -+ |7: // Convert integer to number and continue above. -+ | bhi ->fff_fallback -+ | strd CARG1, CARG2, TMPD -+ | mov CARG1, CARG3 -+ | bl extern __aeabi_i2d -+ | ldrd CARG3, CARG4, TMPD -+ | b <6 -+ |.endif -+ |.endmacro -+ | -+ | math_minmax math_min, gt, pl -+ | math_minmax math_max, lt, le -+ | -+ |//-- String library ----------------------------------------------------- -+ | -+ |.ffunc string_byte // Only handle the 1-arg case here. -+ | ldrd CARG1, CARG2, [BASE] -+ | ldr PC, [BASE, FRAME_PC] -+ | cmp NARGS8:RC, #8 -+ | checktpeq CARG2, LJ_TSTR // Need exactly 1 argument. -+ | bne ->fff_fallback -+ | ldr CARG3, STR:CARG1->len -+ | ldrb CARG1, STR:CARG1[1] // Access is always ok (NUL at end). -+ | mvn CARG2, #~LJ_TISNUM -+ | cmp CARG3, #0 -+ | ite eq -+ | moveq RC, #(0+1)*8 -+ | movne RC, #(1+1)*8 -+ | strd CARG1, CARG2, [BASE, #-8] -+ | b ->fff_res -+ | -+ |.ffunc string_char // Only handle the 1-arg case here. -+ | ffgccheck -+ | ldrd CARG1, CARG2, [BASE] -+ | ldr PC, [BASE, FRAME_PC] -+ | cmp NARGS8:RC, #8 // Need exactly 1 argument. -+ | checktpeq CARG2, LJ_TISNUM -+ | it eq -+ | bicseq CARG4, CARG1, #255 -+ | mov CARG3, #1 -+ | bne ->fff_fallback -+ | str CARG1, TMPD -+ | mov CARG2, TMPDp // Points to stack. Little-endian. -+ |->fff_newstr: -+ | // CARG2 = str, CARG3 = len. -+ | str BASE, L->base -+ | mov CARG1, L -+ | str PC, SAVE_PC -+ | bl extern lj_str_new // (lua_State *L, char *str, size_t l) -+ |->fff_resstr: -+ | // Returns GCstr *. -+ | ldr BASE, L->base -+ | mvn CARG2, #~LJ_TSTR -+ | b ->fff_restv -+ | -+ |.ffunc string_sub -+ | ffgccheck -+ | ldrd CARG1, CARG2, [BASE] -+ | ldrd CARG3, CARG4, [BASE, #16] -+ | cmp NARGS8:RC, #16 -+ | mvn RB, #0 -+ | beq >1 -+ | blo ->fff_fallback -+ | checktp CARG4, LJ_TISNUM -+ | mov RB, CARG3 -+ | bne ->fff_fallback -+ |1: -+ | ldrd CARG3, CARG4, [BASE, #8] -+ | checktp CARG2, LJ_TSTR -+ | it eq -+ | ldreq CARG2, STR:CARG1->len -+ | checktpeq CARG4, LJ_TISNUM -+ | bne ->fff_fallback -+ | // CARG1 = str, CARG2 = str->len, CARG3 = start, RB = end -+ | add CARG4, CARG2, #1 -+ | cmp CARG3, #0 // if (start < 0) start += len+1 -+ | it lt -+ | addlt CARG3, CARG3, CARG4 -+ | cmp CARG3, #1 // if (start < 1) start = 1 -+ | it lt -+ | movlt CARG3, #1 -+ | cmp RB, #0 // if (end < 0) end += len+1 -+ | it lt -+ | addlt RB, RB, CARG4 -+ | bic RB, RB, RB, asr #31 // if (end < 0) end = 0 -+ | cmp RB, CARG2 // if (end > len) end = len -+ | add CARG1, STR:CARG1, #sizeof(GCstr)-1 -+ | it gt -+ | movgt RB, CARG2 -+ | add CARG2, CARG1, CARG3 -+ | subs CARG3, RB, CARG3 // len = end - start -+ | add CARG3, CARG3, #1 // len += 1 -+ | bge ->fff_newstr -+ |->fff_emptystr: -+ | sub STR:CARG1, DISPATCH, #-DISPATCH_GL(strempty) -+ | mvn CARG2, #~LJ_TSTR -+ | b ->fff_restv -+ | -+ |.macro ffstring_op, name -+ | .ffunc string_ .. name -+ | ffgccheck -+ | ldr CARG3, [BASE, #4] -+ | cmp NARGS8:RC, #8 -+ | ldr STR:CARG2, [BASE] -+ | blo ->fff_fallback -+ | sub SBUF:CARG1, DISPATCH, #-DISPATCH_GL(tmpbuf) -+ | checkstr CARG3, ->fff_fallback -+ | ldr CARG4, SBUF:CARG1->b -+ | str BASE, L->base -+ | str PC, SAVE_PC -+ | str L, SBUF:CARG1->L -+ | str CARG4, SBUF:CARG1->w -+ | bl extern lj_buf_putstr_ .. name -+ | bl extern lj_buf_tostr -+ | b ->fff_resstr -+ |.endmacro -+ | -+ |ffstring_op reverse -+ |ffstring_op lower -+ |ffstring_op upper -+ | -+ |//-- Bit library -------------------------------------------------------- -+ | -+ |// FP number to bit conversion for soft-float. Clobbers r0-r3. -+ |->vm_tobit_fb: -+ | bhi ->fff_fallback -+ |->vm_tobit: -+ | lsl RB, CARG2, #1 -+ | adds RB, RB, #0x00200000 -+ | ittt pl -+ | movpl CARG1, #0 // |x| < 1? -+ | bxpl lr -+ | mvn CARG4, #0x3e0 -+ | subs RB, CARG4, RB, asr #21 -+ | bmi >1 // |x| >= 2^32? -+ | lsl CARG4, CARG2, #11 -+ | orr CARG4, CARG4, #0x80000000 -+ | orr CARG4, CARG4, CARG1, lsr #21 -+ | cmp CARG2, #0 -+ | lsr CARG1, CARG4, RB -+ | it lt -+ | rsblt CARG1, CARG1, #0 -+ | bx lr -+ |1: -+ | add RB, RB, #21 -+ | lsr CARG4, CARG1, RB -+ | rsb RB, RB, #20 -+ | lsl CARG1, CARG2, #12 -+ | cmp CARG2, #0 -+ | lsl CARG1, CARG1, RB -+ | orr CARG1, CARG4, CARG1 -+ | it lt -+ | rsblt CARG1, CARG1, #0 -+ | bx lr -+ | -+ |.macro .ffunc_bit, name -+ | .ffunc_1 bit_..name -+ | checktp CARG2, LJ_TISNUM -+ | it ne -+ | blne ->vm_tobit_fb -+ |.endmacro -+ | -+ |.ffunc_bit tobit -+ | mvn CARG2, #~LJ_TISNUM -+ | b ->fff_restv -+ | -+ |.macro .ffunc_bit_op, name, ins -+ | .ffunc_bit name -+ | mov CARG3, CARG1 -+ | mov RA, #8 -+ |1: -+ | ldrd_i CARG1, CARG2, BASE, RA -+ | cmp RA, NARGS8:RC -+ | add RA, RA, #8 -+ | bge >2 -+ | checktp CARG2, LJ_TISNUM -+ | it ne -+ | blne ->vm_tobit_fb -+ | ins CARG3, CARG3, CARG1 -+ | b <1 -+ |.endmacro -+ | -+ |.ffunc_bit_op band, and -+ |.ffunc_bit_op bor, orr -+ |.ffunc_bit_op bxor, eor -+ | -+ |2: -+ | mvn CARG4, #~LJ_TISNUM -+ | ldr PC, [BASE, FRAME_PC] -+ | strd CARG3, CARG4, [BASE, #-8] -+ | b ->fff_res1 -+ | -+ |.ffunc_bit bswap -+ | eor CARG3, CARG1, CARG1, ror #16 -+ | bic CARG3, CARG3, #0x00ff0000 -+ | ror CARG1, CARG1, #8 -+ | mvn CARG2, #~LJ_TISNUM -+ | eor CARG1, CARG1, CARG3, lsr #8 -+ | b ->fff_restv -+ | -+ |.ffunc_bit bnot -+ | mvn CARG1, CARG1 -+ | mvn CARG2, #~LJ_TISNUM -+ | b ->fff_restv -+ | -+ |.macro .ffunc_bit_sh, name, ins, shmod -+ | .ffunc bit_..name -+ | ldrd CARG1, CARG2, [BASE, #8] -+ | cmp NARGS8:RC, #16 -+ | blo ->fff_fallback -+ | checktp CARG2, LJ_TISNUM -+ | it ne -+ | blne ->vm_tobit_fb -+ |.if shmod == 0 -+ | and RA, CARG1, #31 -+ |.else -+ | rsb RA, CARG1, #0 -+ |.endif -+ | ldrd CARG1, CARG2, [BASE] -+ | checktp CARG2, LJ_TISNUM -+ | it ne -+ | blne ->vm_tobit_fb -+ | ins CARG1, CARG1, RA -+ | mvn CARG2, #~LJ_TISNUM -+ | b ->fff_restv -+ |.endmacro -+ | -+ |.ffunc_bit_sh lshift, lsl, 0 -+ |.ffunc_bit_sh rshift, lsr, 0 -+ |.ffunc_bit_sh arshift, asr, 0 -+ |.ffunc_bit_sh rol, ror, 1 -+ |.ffunc_bit_sh ror, ror, 0 -+ | -+ |//----------------------------------------------------------------------- -+ | -+ |->fff_fallback: // Call fast function fallback handler. -+ | // BASE = new base, RC = nargs*8 -+ | ldr CARG3, [BASE, FRAME_FUNC] -+ | ldr CARG2, L->maxstack -+ | add CARG1, BASE, NARGS8:RC -+ | ldr PC, [BASE, FRAME_PC] // Fallback may overwrite PC. -+ | str CARG1, L->top -+ | ldr CARG3, CFUNC:CARG3->f -+ | str BASE, L->base -+ | add CARG1, CARG1, #8*LUA_MINSTACK -+ | str PC, SAVE_PC // Redundant (but a defined value). -+ | cmp CARG1, CARG2 -+ | mov CARG1, L -+ | bhi >5 // Need to grow stack. -+ | blx CARG3 // (lua_State *L) -+ | // Either throws an error, or recovers and returns -1, 0 or nresults+1. -+ | ldr BASE, L->base -+ | cmp CRET1, #0 -+ | lsl RC, CRET1, #3 -+ | sub RA, BASE, #8 -+ | bgt ->fff_res // Returned nresults+1? -+ |1: // Returned 0 or -1: retry fast path. -+ | ldr CARG1, L->top -+ | ldr LFUNC:CARG3, [BASE, FRAME_FUNC] -+ | sub NARGS8:RC, CARG1, BASE -+ | bne ->vm_call_tail // Returned -1? -+ | ins_callt // Returned 0: retry fast path. -+ | -+ |// Reconstruct previous base for vmeta_call during tailcall. -+ |->vm_call_tail: -+ | ands CARG1, PC, #FRAME_TYPE -+ | bic CARG2, PC, #FRAME_TYPEP -+ | ittt eq -+ | ldreq INS, [PC, #-4] -+ | andeq CARG2, MASKR8, INS, lsr #5 // Conditional decode_RA8. -+ | addeq CARG2, CARG2, #8 -+ | sub RB, BASE, CARG2 -+ | b ->vm_call_dispatch // Resolve again for tailcall. -+ | -+ |5: // Grow stack for fallback handler. -+ | mov CARG2, #LUA_MINSTACK -+ | bl extern lj_state_growstack // (lua_State *L, int n) -+ | ldr BASE, L->base -+ | cmp CARG1, CARG1 // Set zero-flag to force retry. -+ | b <1 -+ | -+ |->fff_gcstep: // Call GC step function. -+ | // BASE = new base, RC = nargs*8 -+ | mov RA, lr -+ | str BASE, L->base -+ | add CARG2, BASE, NARGS8:RC -+ | str PC, SAVE_PC // Redundant (but a defined value). -+ | str CARG2, L->top -+ | mov CARG1, L -+ | bl extern lj_gc_step // (lua_State *L) -+ | ldr BASE, L->base -+ | mov lr, RA // Help return address predictor. -+ | ldr CFUNC:CARG3, [BASE, FRAME_FUNC] -+ | bx lr -+ | -+ |//----------------------------------------------------------------------- -+ |//-- Special dispatch targets ------------------------------------------- -+ |//----------------------------------------------------------------------- -+ | -+ |->vm_record: // Dispatch target for recording phase. -+ |.if JIT -+ | sub CARG1, DISPATCH, #-DISPATCH_GL(hookmask) -+ | ldrb CARG1, [CARG1] -+ | tst CARG1, #HOOK_VMEVENT // No recording while in vmevent. -+ | bne >5 -+ | // Decrement the hookcount for consistency, but always do the call. -+ | sub CARG2, DISPATCH, #-DISPATCH_GL(hookcount) -+ | ldr CARG2, [CARG2] -+ | tst CARG1, #HOOK_ACTIVE -+ | bne >1 -+ | sub CARG2, CARG2, #1 -+ | tst CARG1, #LUA_MASKLINE|LUA_MASKCOUNT -+ | sub CARG1, DISPATCH, #-DISPATCH_GL(hookcount) -+ | it ne -+ | strne CARG2, [CARG1] -+ | b >1 -+ |.endif -+ | -+ |->vm_rethook: // Dispatch target for return hooks. -+ | sub CARG1, DISPATCH, #-DISPATCH_GL(hookmask) -+ | ldrb CARG1, [CARG1] -+ | tst CARG1, #HOOK_ACTIVE // Hook already active? -+ | beq >1 -+ |5: // Re-dispatch to static ins. -+ | decode_OP OP, INS -+ | add OP, DISPATCH, OP, lsl #2 -+ | ldr pc, [OP, #GG_DISP2STATIC] -+ | -+ |->vm_inshook: // Dispatch target for instr/line hooks. -+ | sub CARG1, DISPATCH, #-DISPATCH_GL(hookmask) -+ | ldrb CARG1, [CARG1] -+ | sub CARG2, DISPATCH, #-DISPATCH_GL(hookcount) -+ | ldr CARG2, [CARG2] -+ | tst CARG1, #HOOK_ACTIVE // Hook already active? -+ | bne <5 -+ | tst CARG1, #LUA_MASKLINE|LUA_MASKCOUNT -+ | beq <5 -+ | subs CARG2, CARG2, #1 -+ | sub CARG3, DISPATCH, #-DISPATCH_GL(hookcount) -+ | str CARG2, [CARG3] -+ | beq >1 -+ | tst CARG1, #LUA_MASKLINE -+ | beq <5 -+ |1: -+ | mov CARG1, L -+ | str BASE, L->base -+ | mov CARG2, PC -+ | // SAVE_PC must hold the _previous_ PC. The callee updates it with PC. -+ | bl extern lj_dispatch_ins // (lua_State *L, const BCIns *pc) -+ |3: -+ | ldr BASE, L->base -+ |4: // Re-dispatch to static ins. -+ | ldrb OP, [PC, #-4] -+ | ldr INS, [PC, #-4] -+ | add OP, DISPATCH, OP, lsl #2 -+ | ldr OP, [OP, #GG_DISP2STATIC] -+ | decode_RA8 RA, INS -+ | decode_RD RC, INS -+ | bx OP -+ | -+ |->cont_hook: // Continue from hook yield. -+ | ldr CARG1, [CARG4, #-24] -+ | add PC, PC, #4 -+ | str CARG1, SAVE_MULTRES // Restore MULTRES for *M ins. -+ | b <4 -+ | -+ |->vm_hotloop: // Hot loop counter underflow. -+ |.if JIT -+ | ldr LFUNC:CARG3, [BASE, FRAME_FUNC] // Same as curr_topL(L). -+ | sub CARG1, DISPATCH, #-GG_DISP2J -+ | str PC, SAVE_PC -+ | ldr CARG3, LFUNC:CARG3->field_pc -+ | mov CARG2, PC -+ | sub RB, DISPATCH, #-DISPATCH_J(L) -+ | str L, [RB] -+ | ldrb CARG3, [CARG3, #PC2PROTO(framesize)] -+ | str BASE, L->base -+ | add CARG3, BASE, CARG3, lsl #3 -+ | str CARG3, L->top -+ | bl extern lj_trace_hot // (jit_State *J, const BCIns *pc) -+ | b <3 -+ |.endif -+ | -+ |->vm_callhook: // Dispatch target for call hooks. -+ | mov CARG2, PC -+ |.if JIT -+ | b >1 -+ |.endif -+ | -+ |->vm_hotcall: // Hot call counter underflow. -+ |.if JIT -+ | orr CARG2, PC, #1 -+ |1: -+ |.endif -+ | add CARG4, BASE, RC -+ | str PC, SAVE_PC -+ | mov CARG1, L -+ | str BASE, L->base -+ | sub RA, RA, BASE -+ | str CARG4, L->top -+ | bl extern lj_dispatch_call // (lua_State *L, const BCIns *pc) -+ | // Returns ASMFunction. -+ | ldr BASE, L->base -+ | ldr CARG4, L->top -+ | mov CARG2, #0 -+ | add RA, BASE, RA -+ | sub NARGS8:RC, CARG4, BASE -+ | str CARG2, SAVE_PC // Invalidate for subsequent line hook. -+ | ldr LFUNC:CARG3, [BASE, FRAME_FUNC] -+ | ldr INS, [PC, #-4] -+ | bx CRET1 -+ | -+ |->cont_stitch: // Trace stitching. -+ |.if JIT -+ | // RA = resultptr, CARG4 = meta base -+ | ldr RB, SAVE_MULTRES -+ | ldr INS, [PC, #-4] -+ | ldr TRACE:CARG3, [CARG4, #-24] // Save previous trace. -+ | subs RB, RB, #8 -+ | decode_RA8 RC, INS // Call base. -+ | beq >2 -+ |1: // Move results down. -+ | ldrd CARG1, CARG2, [RA] -+ | add RA, RA, #8 -+ | subs RB, RB, #8 -+ | strd_i CARG1, CARG2, BASE, RC -+ | add RC, RC, #8 -+ | bne <1 -+ |2: -+ | decode_RA8 RA, INS -+ | decode_RB8 RB, INS -+ | add RA, RA, RB -+ |3: -+ | cmp RA, RC -+ | mvn CARG2, #~LJ_TNIL -+ | bhi >9 // More results wanted? -+ | -+ | ldrh RA, TRACE:CARG3->traceno -+ | ldrh RC, TRACE:CARG3->link -+ | cmp RC, RA -+ | beq ->cont_nop // Blacklisted. -+ | cmp RC, #0 -+ | bne =>BC_JLOOP // Jump to stitched trace. -+ | -+ | // Stitch a new trace to the previous trace. -+ | sub RB, DISPATCH, #-DISPATCH_J(exitno) -+ | str RA, [RB] -+ | sub RB, DISPATCH, #-DISPATCH_J(L) -+ | str L, [RB] -+ | str BASE, L->base -+ | sub CARG1, DISPATCH, #-GG_DISP2J -+ | mov CARG2, PC -+ | bl extern lj_dispatch_stitch // (jit_State *J, const BCIns *pc) -+ | ldr BASE, L->base -+ | b ->cont_nop -+ | -+ |9: // Fill up results with nil. -+ | strd_i CARG1, CARG2, BASE, RC -+ | add RC, RC, #8 -+ | b <3 -+ |.endif -+ | -+ |->vm_profhook: // Dispatch target for profiler hook. -+#if LJ_HASPROFILE -+ | mov CARG1, L -+ | str BASE, L->base -+ | mov CARG2, PC -+ | bl extern lj_dispatch_profile // (lua_State *L, const BCIns *pc) -+ | // HOOK_PROFILE is off again, so re-dispatch to dynamic instruction. -+ | ldr BASE, L->base -+ | sub PC, PC, #4 -+ | b ->cont_nop -+#endif -+ | -+ |//----------------------------------------------------------------------- -+ |//-- Trace exit handler ------------------------------------------------- -+ |//----------------------------------------------------------------------- -+ | -+ |->vm_exit_handler: -+ |.if JIT -+ | sub sp, sp, #12 -+ | push {r0,r1,r2,r3,r4,r5,r6,r7,r8,r9,r10,r11,r12} -+ | ldr CARG1, [sp, #64] // Load original value of lr. -+ | ldr DISPATCH, [lr, #-1] // Load DISPATCH. -+ | add CARG3, sp, #64 // Recompute original value of sp. -+ | mv_vmstate CARG4, EXIT -+ | str CARG3, [sp, #52] // Store sp in RID_SP -+ | st_vmstate CARG4 -+ | ldr CARG4, [CARG1, #-5]! // Get exit instruction. -+ | str CARG1, [sp, #56] // Store exit pc in RID_LR and RID_PC. -+ | str CARG1, [sp, #60] -+ |.if FPU -+ | vpush {d0-d15} -+ |.endif -+ | .long 0xf3432180 //SBFX CARG2, CARG4, #10, #1 -+ | .long 0xf36321d4 //BFI CARG2, CARG4, #11, #10 -+ | lsr CARG4, CARG4, #16 -+ | .long 0xf363010a //BFI CARG2, CARG4, #0, #11 -+ | add CARG1, CARG1, CARG2, lsl #1 -+ | ldr CARG2, [lr, #3] // Load exit stub group offset. -+ | sub CARG1, CARG1, lr -+ | ldr L, [DISPATCH, #DISPATCH_GL(cur_L)] -+ | add CARG1, CARG2, CARG1, lsr #2 // Compute exit number. -+ | ldr BASE, [DISPATCH, #DISPATCH_GL(jit_base)] -+ | sub RB, DISPATCH, #-DISPATCH_J(exitno) -+ | str CARG1, [RB] -+ | mov CARG4, #0 -+ | str BASE, L->base -+ | sub RB, DISPATCH, #-DISPATCH_J(L) -+ | str L, [RB] -+ | str CARG4, [DISPATCH, #DISPATCH_GL(jit_base)] -+ | sub CARG1, DISPATCH, #-GG_DISP2J -+ | mov CARG2, sp -+ | bl extern lj_trace_exit // (jit_State *J, ExitState *ex) -+ | // Returns MULTRES (unscaled) or negated error code. -+ | ldr CARG2, L->cframe -+ | ldr BASE, L->base -+ | bic CARG2, CARG2, #~CFRAME_RAWMASK // Use two steps: bic sp is deprecated. -+ | mov sp, CARG2 -+ | ldr PC, SAVE_PC // Get SAVE_PC. -+ | str L, SAVE_L // Set SAVE_L (on-trace resume/yield). -+ | b >1 -+ |.endif -+ |->vm_exit_interp: -+ | // CARG1 = MULTRES or negated error code, BASE, PC and DISPATCH set. -+ |.if JIT -+ | ldr L, SAVE_L -+ |1: -+ | cmp CARG1, #0 -+ | blt >9 // Check for error from exit. -+ | lsl RC, CARG1, #3 -+ | ldr LFUNC:CARG2, [BASE, FRAME_FUNC] -+ | str RC, SAVE_MULTRES -+ | mov CARG3, #0 -+ | str BASE, L->base -+ | ldr CARG2, LFUNC:CARG2->field_pc -+ | str CARG3, [DISPATCH, #DISPATCH_GL(jit_base)] -+ | mv_vmstate CARG4, INTERP -+ | ldr KBASE, [CARG2, #PC2PROTO(k)] -+ | // Modified copy of ins_next which handles function header dispatch, too. -+ | ldrb OP, [PC] -+ | mov MASKR8, #255 -+ | ldr INS, [PC], #4 -+ | lsl MASKR8, MASKR8, #3 // MASKR8 = 255*8. -+ | st_vmstate CARG4 -+ | cmp OP, #BC_FUNCC+2 // Fast function? -+ | bhs >4 -+ |2: -+ | cmp OP, #BC_FUNCF // Function header? -+ | ldr OP, [DISPATCH, OP, lsl #2] -+ | decode_RA8 RA, INS -+ | iteee lo -+ | lsrlo RC, INS, #16 // No: Decode operands A*8 and D. -+ | subhs RC, RC, #8 -+ | addhs RA, RA, BASE // Yes: RA = BASE+framesize*8, RC = nargs*8 -+ | ldrhs CARG3, [BASE, FRAME_FUNC] -+ | bx OP -+ | -+ |4: // Check frame below fast function. -+ | ldr CARG1, [BASE, FRAME_PC] -+ | ands CARG2, CARG1, #FRAME_TYPE -+ | bne <2 // Trace stitching continuation? -+ | // Otherwise set KBASE for Lua function below fast function. -+ | ldr CARG3, [CARG1, #-4] -+ | decode_RA8 CARG1, CARG3 -+ | sub CARG2, BASE, CARG1 -+ | ldr LFUNC:CARG3, [CARG2, #-16] -+ | ldr CARG3, LFUNC:CARG3->field_pc -+ | ldr KBASE, [CARG3, #PC2PROTO(k)] -+ | b <2 -+ | -+ |9: // Rethrow error from the right C frame. -+ | mov CARG1, L -+ | bl extern lj_err_run // (lua_State *L) -+ |.endif -+ | -+ |//----------------------------------------------------------------------- -+ |//-- Math helper functions ---------------------------------------------- -+ |//----------------------------------------------------------------------- -+ | -+ |// FP value rounding. Called from JIT code. -+ |// -+ |// double lj_vm_floor/ceil/trunc(double x); -+ |.macro vm_round, func, hf -+ |.if hf == 1 -+ | vmov CARG1, CARG2, d0 -+ |.endif -+ | lsl CARG3, CARG2, #1 -+ | adds RB, CARG3, #0x00200000 -+ | bpl >2 // |x| < 1? -+ | mvn CARG4, #0x3cc -+ | subs RB, CARG4, RB, asr #21 // 2^0: RB = 51, 2^51: RB = 0. -+ | itt lo -+ | bxlo lr // |x| >= 2^52: done. -+ | mvn CARG4, #1 -+ | lsl CARG4, CARG4, RB -+ | bic CARG3, CARG1, CARG4 // ztest = lo & ~lomask -+ | and CARG1, CARG1, CARG4 // lo &= lomask -+ | subs RB, RB, #32 -+ | mvn CARG4, #1 -+ | itttt pl -+ | lslpl CARG4, CARG4, RB -+ | bicpl CARG4, CARG2, CARG4 // |x| <= 2^20: ztest |= hi & ~himask -+ | orrpl CARG3, CARG3, CARG4 -+ | mvnpl CARG4, #1 -+ | itt pl -+ | lslpl CARG4, CARG4, RB -+ | andpl CARG2, CARG2, CARG4 // |x| <= 2^20: hi &= himask -+ | mvn CARG4, #1 -+ |.if "func" == "floor" -+ | tst CARG3, CARG2, asr #31 // iszero = ((ztest & signmask) == 0) -+ |.else -+ | bics CARG3, CARG3, CARG2, asr #31 // iszero = ((ztest & ~signmask) == 0) -+ |.endif -+ |.if hf == 1 -+ | it eq -+ | vmoveq d0, CARG1, CARG2 -+ |.endif -+ | itt eq -+ | bxeq lr // iszero: done. -+ | mvn CARG4, #1 -+ | cmp RB, #0 -+ | ite pl -+ | lslpl CARG3, CARG4, RB -+ | mvnmi CARG3, #0 -+ | add RB, RB, #32 -+ | lsl CARG4, CARG4, RB -+ | subs CARG1, CARG1, CARG4 // lo = lo-lomask -+ | mvn CARG4, #1 -+ | sbc CARG2, CARG2, CARG3 // hi = hi-himask+carry -+ |.if hf == 1 -+ | vmov d0, CARG1, CARG2 -+ |.endif -+ | bx lr -+ | -+ |2: // |x| < 1: -+ | itt cs -+ | bxcs lr // |x| is not finite. -+ | orr CARG3, CARG3, CARG1 // ztest = (2*hi) | lo -+ |.if "func" == "floor" -+ | tst CARG3, CARG2, asr #31 // iszero = ((ztest & signmask) == 0) -+ |.else -+ | bics CARG3, CARG3, CARG2, asr #31 // iszero = ((ztest & ~signmask) == 0) -+ |.endif -+ | mov CARG1, #0 // lo = 0 -+ | and CARG2, CARG2, #0x80000000 -+ | itt ne -+ | ldrne CARG4, <9 // hi = sign(x) | (iszero ? 0.0 : 1.0) -+ | orrne CARG2, CARG2, CARG4 -+ |.if hf == 1 -+ | vmov d0, CARG1, CARG2 -+ |.endif -+ | bx lr -+ |.endmacro -+ | -+ |9: -+ | .long 0x00003ff0 // hiword(+1.0) jturnsek: swaped halfwords!!! -+ | -+ |->vm_floor: -+ |.if HFABI -+ | vm_round floor, 1 -+ |.endif -+ |->vm_floor_sf: -+ | vm_round floor, 0 -+ | -+ |->vm_ceil: -+ |.if HFABI -+ | vm_round ceil, 1 -+ |.endif -+ |->vm_ceil_sf: -+ | vm_round ceil, 0 -+ | -+ |.macro vm_trunc, hf -+ |.if JIT -+ |.if hf == 1 -+ | vmov CARG1, CARG2, d0 -+ |.endif -+ | lsl CARG3, CARG2, #1 -+ | adds RB, CARG3, #0x00200000 -+ | itt pl -+ | andpl CARG2, CARG2, #0x80000000 // |x| < 1? hi = sign(x), lo = 0. -+ | movpl CARG1, #0 -+ |.if hf == 1 -+ | it pl -+ | vmovpl d0, CARG1, CARG2 -+ |.endif -+ | itt pl -+ | bxpl lr -+ | mvn CARG4, #0x3cc -+ | subs RB, CARG4, RB, asr #21 // 2^0: RB = 51, 2^51: RB = 0. -+ | itt lo -+ | bxlo lr // |x| >= 2^52: already done. -+ | mvn CARG4, #1 -+ | lsl CARG4, CARG4, RB -+ | and CARG1, CARG1, CARG4 // lo &= lomask -+ | subs RB, RB, #32 -+ | mvn CARG4, #1 -+ | itt pl -+ | lsl CARG4, CARG4, RB -+ | andpl CARG2, CARG2, CARG4 // |x| <= 2^20: hi &= himask -+ |.if hf == 1 -+ | vmov d0, CARG1, CARG2 -+ |.endif -+ | bx lr -+ |.endif -+ |.endmacro -+ | -+ |->vm_trunc: -+ |.if HFABI -+ | vm_trunc 1 -+ |.endif -+ |->vm_trunc_sf: -+ | vm_trunc 0 -+ | -+ | // double lj_vm_mod(double dividend, double divisor); -+ |->vm_mod: -+ |.if FPU -+ | // Special calling convention. Also, RC (r11) is not preserved. -+ | vdiv.f64 d0, d6, d7 -+ | mov RC, lr -+ | vmov CARG1, CARG2, d0 -+ | bl ->vm_floor_sf -+ | vmov d0, CARG1, CARG2 -+ | vmul.f64 d0, d0, d7 -+ | mov lr, RC -+ | vsub.f64 d6, d6, d0 -+ | bx lr -+ |.else -+ | push {r0, r1, r2, r3, r4, lr} -+ | bl extern __aeabi_ddiv -+ | bl ->vm_floor_sf -+ | ldrd CARG3, CARG4, [sp, #8] -+ | bl extern __aeabi_dmul -+ | ldrd CARG3, CARG4, [sp] -+ | eor CARG2, CARG2, #0x80000000 -+ | bl extern __aeabi_dadd -+ | add sp, sp, #20 -+ | pop {pc} -+ |.endif -+ | -+ | // int lj_vm_modi(int dividend, int divisor); -+ |->vm_modi: -+ | ands RB, CARG1, #0x80000000 -+ | it mi -+ | rsbmi CARG1, CARG1, #0 // a = |dividend| -+ | eor RB, RB, CARG2, asr #1 // Keep signdiff and sign(divisor). -+ | cmp CARG2, #0 -+ | it mi -+ | rsbmi CARG2, CARG2, #0 // b = |divisor| -+ | subs CARG4, CARG2, #1 -+ | ite ne -+ | cmpne CARG1, CARG2 -+ | moveq CARG1, #0 // if (b == 1 || a == b) a = 0 -+ | it hi -+ | tsthi CARG2, CARG4 -+ | it eq -+ | andeq CARG1, CARG1, CARG4 // else if ((b & (b-1)) == 0) a &= b-1 -+ | bls >1 -+ | // Use repeated subtraction to get the remainder. -+ | clz CARG3, CARG1 -+ | clz CARG4, CARG2 -+ | sub CARG4, CARG4, CARG3 -+ | rsbs CARG3, CARG4, #31 // entry = (31-(clz(b)-clz(a)))*12 -+ | it ne -+ | .long 0xe8dff002 // tbbne [pc, CARG3] // Duff's device. -+ | .long 0xb8bec4ca, 0xa0a6acb2, 0x888e949a, 0x70767c82 // TBB table (part1) -+ | .long 0x585e646a, 0x40464c52, 0x282e343a, 0x10161c22 // TBB table (part2) -+ { -+ int i; -+ for (i = 31; i >= 0; i--) { -+ | cmp CARG1, CARG2, lsl #i -+ | it hs -+ | subhs CARG1, CARG1, CARG2, lsl #i -+ } -+ } -+ |1: -+ | cmp CARG1, #0 -+ | it ne -+ | cmpne RB, #0 -+ | it mi -+ | submi CARG1, CARG1, CARG2 // if (y != 0 && signdiff) y = y - b -+ | eors CARG2, CARG1, RB, lsl #1 -+ | it mi -+ | rsbmi CARG1, CARG1, #0 // if (sign(divisor) != sign(y)) y = -y -+ | bx lr -+ | -+ |//----------------------------------------------------------------------- -+ |//-- Miscellaneous functions -------------------------------------------- -+ |//----------------------------------------------------------------------- -+ | -+ |.define NEXT_TAB, TAB:CARG1 -+ |.define NEXT_RES, CARG1 -+ |.define NEXT_IDX, CARG2 -+ |.define NEXT_TMP0, CARG3 -+ |.define NEXT_TMP1, CARG4 -+ |.define NEXT_LIM, r12 -+ |.define NEXT_RES_PTR, sp -+ |.define NEXT_RES_VAL, [sp] -+ |.define NEXT_RES_KEY_I, [sp, #8] -+ |.define NEXT_RES_KEY_IT, [sp, #12] -+ | -+ |// TValue *lj_vm_next(GCtab *t, uint32_t idx) -+ |// Next idx returned in CRET2. -+ |->vm_next: -+ |.if JIT -+ | ldr NEXT_TMP0, NEXT_TAB->array -+ | ldr NEXT_LIM, NEXT_TAB->asize -+ | add NEXT_TMP0, NEXT_TMP0, NEXT_IDX, lsl #3 -+ |1: // Traverse array part. -+ | subs NEXT_TMP1, NEXT_IDX, NEXT_LIM -+ | bhs >5 -+ | ldr NEXT_TMP1, [NEXT_TMP0, #4] -+ | str NEXT_IDX, NEXT_RES_KEY_I -+ | add NEXT_TMP0, NEXT_TMP0, #8 -+ | add NEXT_IDX, NEXT_IDX, #1 -+ | checktp NEXT_TMP1, LJ_TNIL -+ | beq <1 // Skip holes in array part. -+ | ldr NEXT_TMP0, [NEXT_TMP0, #-8] -+ | mov NEXT_RES, NEXT_RES_PTR -+ | strd NEXT_TMP0, NEXT_TMP1, NEXT_RES_VAL -+ | mvn NEXT_TMP0, #~LJ_TISNUM -+ | str NEXT_TMP0, NEXT_RES_KEY_IT -+ | bx lr -+ | -+ |5: // Traverse hash part. -+ | ldr NEXT_TMP0, NEXT_TAB->hmask -+ | ldr NODE:NEXT_RES, NEXT_TAB->node -+ | add NEXT_TMP1, NEXT_TMP1, NEXT_TMP1, lsl #1 -+ | add NEXT_LIM, NEXT_LIM, NEXT_TMP0 -+ | add NODE:NEXT_RES, NODE:NEXT_RES, NEXT_TMP1, lsl #3 -+ |6: -+ | cmp NEXT_IDX, NEXT_LIM -+ | bhi >9 -+ | ldr NEXT_TMP1, NODE:NEXT_RES->val.it -+ | checktp NEXT_TMP1, LJ_TNIL -+ | add NEXT_IDX, NEXT_IDX, #1 -+ | itt ne -+ | bxne lr -+ | // Skip holes in hash part. -+ | add NEXT_RES, NEXT_RES, #sizeof(Node) -+ | b <6 -+ | -+ |9: // End of iteration. Set the key to nil (not the value). -+ | mvn NEXT_TMP0, #0 -+ | mov NEXT_RES, NEXT_RES_PTR -+ | str NEXT_TMP0, NEXT_RES_KEY_IT -+ | bx lr -+ |.endif -+ | -+ |//----------------------------------------------------------------------- -+ |//-- FFI helper functions ----------------------------------------------- -+ |//----------------------------------------------------------------------- -+ | -+ |// Handler for callback functions. -+ |// Saveregs already performed. Callback slot number in [sp], g in r12. -+ |->vm_ffi_callback: -+ |.if FFI -+ |.type CTSTATE, CTState, PC -+ | ldr CTSTATE, GL:r12->ctype_state -+ | add DISPATCH, r12, #GG_G2DISP -+ |.if FPU -+ | str r4, SAVE_R4 -+ | add r4, sp, CFRAME_SPACE+4+8*8 -+ | vstmdb r4!, {d8-d15} -+ |.endif -+ |.if HFABI -+ | add r12, CTSTATE, #offsetof(CTState, cb.fpr[8]) -+ |.endif -+ | strd CARG3, CARG4, CTSTATE->cb.gpr[2] -+ | strd CARG1, CARG2, CTSTATE->cb.gpr[0] -+ |.if HFABI -+ | vstmdb r12!, {d0-d7} -+ |.endif -+ | ldr CARG4, [sp] -+ | add CARG3, sp, #CFRAME_SIZE -+ | mov CARG1, CTSTATE -+ | lsr CARG4, CARG4, #3 -+ | str CARG3, CTSTATE->cb.stack -+ | mov CARG2, sp -+ | str CARG4, CTSTATE->cb.slot -+ | str CTSTATE, SAVE_PC // Any value outside of bytecode is ok. -+ | bl extern lj_ccallback_enter // (CTState *cts, void *cf) -+ | // Returns lua_State *. -+ | ldr BASE, L:CRET1->base -+ | mv_vmstate CARG2, INTERP -+ | ldr RC, L:CRET1->top -+ | mov MASKR8, #255 -+ | ldr LFUNC:CARG3, [BASE, FRAME_FUNC] -+ | mov L, CRET1 -+ | sub RC, RC, BASE -+ | lsl MASKR8, MASKR8, #3 // MASKR8 = 255*8. -+ | st_vmstate CARG2 -+ | ins_callt -+ |.endif -+ | -+ |->cont_ffi_callback: // Return from FFI callback. -+ |.if FFI -+ | ldr CTSTATE, [DISPATCH, #DISPATCH_GL(ctype_state)] -+ | str BASE, L->base -+ | str CARG4, L->top -+ | str L, CTSTATE->L -+ | mov CARG1, CTSTATE -+ | mov CARG2, RA -+ | bl extern lj_ccallback_leave // (CTState *cts, TValue *o) -+ | ldrd CARG1, CARG2, CTSTATE->cb.gpr[0] -+ |.if HFABI -+ | vldr d0, CTSTATE->cb.fpr[0] -+ |.endif -+ | b ->vm_leave_unw -+ |.endif -+ | -+ |->vm_ffi_call: // Call C function via FFI. -+ | // Caveat: needs special frame unwinding, see below. -+ |.if FFI -+ | .type CCSTATE, CCallState, r4 -+ | push {CCSTATE, r5, r11, lr} -+ | mov CCSTATE, CARG1 -+ | ldr CARG1, CCSTATE:CARG1->spadj -+ | ldrb CARG2, CCSTATE->nsp -+ | add CARG3, CCSTATE, #offsetof(CCallState, stack) -+ |.if HFABI -+ | add RB, CCSTATE, #offsetof(CCallState, fpr[0]) -+ |.endif -+ | mov r11, sp -+ | sub sp, sp, CARG1 // Readjust stack. -+ | subs CARG2, CARG2, #1 -+ |.if HFABI -+ | vldm RB, {d0-d7} -+ |.endif -+ | ldr RB, CCSTATE->func -+ | bmi >2 -+ |1: // Copy stack slots. -+ | ldr CARG4, [CARG3, CARG2, lsl #2] -+ | str CARG4, [sp, CARG2, lsl #2] -+ | subs CARG2, CARG2, #1 -+ | bpl <1 -+ |2: -+ | ldrd CARG1, CARG2, CCSTATE->gpr[0] -+ | ldrd CARG3, CARG4, CCSTATE->gpr[2] -+ | blx RB -+ | mov sp, r11 -+ |.if HFABI -+ | add r12, CCSTATE, #offsetof(CCallState, fpr[4]) -+ |.endif -+ | strd CRET1, CRET2, CCSTATE->gpr[0] -+ |.if HFABI -+ | vstmdb r12!, {d0-d3} -+ |.endif -+ | pop {CCSTATE, r5, r11, pc} -+ |.endif -+ |// Note: vm_ffi_call must be the last function in this object file! -+ | -+ |//----------------------------------------------------------------------- -+} -+ -+/* Generate the code for a single instruction. */ -+static void build_ins(BuildCtx *ctx, BCOp op, int defop) -+{ -+ int vk = 0; -+ |=>defop: -+ -+ switch (op) { -+ -+ /* -- Comparison ops ---------------------------------------------------- */ -+ -+ /* Remember: all ops branch for a true comparison, fall through otherwise. */ -+ -+ case BC_ISLT: case BC_ISGE: case BC_ISLE: case BC_ISGT: -+ | // RA = src1*8, RC = src2, JMP with RC = target -+ | lsl RC, RC, #3 -+ | ldrd_iw CARG1, CARG2, RA, BASE -+ | ldrh RB, [PC, #2] -+ | ldrd_iw CARG3, CARG4, RC, BASE -+ | add PC, PC, #4 -+ | add RB, PC, RB, lsl #2 -+ | checktp CARG2, LJ_TISNUM -+ | bne >3 -+ | checktp CARG4, LJ_TISNUM -+ | bne >4 -+ | cmp CARG1, CARG3 -+ if (op == BC_ISLT) { -+ | it lt -+ | sublt PC, RB, #0x20000 -+ } else if (op == BC_ISGE) { -+ | it ge -+ | subge PC, RB, #0x20000 -+ } else if (op == BC_ISLE) { -+ | it le -+ | suble PC, RB, #0x20000 -+ } else { -+ | it gt -+ | subgt PC, RB, #0x20000 -+ } -+ |1: -+ | ins_next -+ | -+ |3: // CARG1, CARG2 is not an integer. -+ |.if FPU -+ | vldr d0, [RA] -+ | bhi ->vmeta_comp -+ | // d0 is a number. -+ | checktp CARG4, LJ_TISNUM -+ | vldr d1, [RC] -+ | blo >5 -+ | bhi ->vmeta_comp -+ | // d0 is a number, CARG3 is an integer. -+ | vmov s4, CARG3 -+ | vcvt.f64.s32 d1, s4 -+ | b >5 -+ |4: // CARG1 is an integer, CARG3, CARG4 is not an integer. -+ | vldr d1, [RC] -+ | bhi ->vmeta_comp -+ | // CARG1 is an integer, d1 is a number. -+ | vmov s4, CARG1 -+ | vcvt.f64.s32 d0, s4 -+ |5: // d0 and d1 are numbers. -+ | vcmp.f64 d0, d1 -+ | vmrs -+ | // To preserve NaN semantics GE/GT branch on unordered, but LT/LE don't. -+ if (op == BC_ISLT) { -+ | it lo -+ | sublo PC, RB, #0x20000 -+ } else if (op == BC_ISGE) { -+ | it hs -+ | subhs PC, RB, #0x20000 -+ } else if (op == BC_ISLE) { -+ | it ls -+ | subls PC, RB, #0x20000 -+ } else { -+ | it hi -+ | subhi PC, RB, #0x20000 -+ } -+ | b <1 -+ |.else -+ | bhi ->vmeta_comp -+ | // CARG1, CARG2 is a number. -+ | checktp CARG4, LJ_TISNUM -+ | it lo -+ | movlo RA, RB // Save RB. -+ | blo >5 -+ | bhi ->vmeta_comp -+ | // CARG1, CARG2 is a number, CARG3 is an integer. -+ | mov CARG1, CARG3 -+ | mov RC, RA -+ | mov RA, RB // Save RB. -+ | bl extern __aeabi_i2d -+ | mov CARG3, CARG1 -+ | mov CARG4, CARG2 -+ | ldrd CARG1, CARG2, [RC] // Restore first operand. -+ | b >5 -+ |4: // CARG1 is an integer, CARG3, CARG4 is not an integer. -+ | bhi ->vmeta_comp -+ | // CARG1 is an integer, CARG3, CARG4 is a number. -+ | mov RA, RB // Save RB. -+ | bl extern __aeabi_i2d -+ | ldrd CARG3, CARG4, [RC] // Restore second operand. -+ |5: // CARG1, CARG2 and CARG3, CARG4 are numbers. -+ | bl extern __aeabi_cdcmple -+ | // To preserve NaN semantics GE/GT branch on unordered, but LT/LE don't. -+ if (op == BC_ISLT) { -+ | it lo -+ | sublo PC, RA, #0x20000 -+ } else if (op == BC_ISGE) { -+ | it hs -+ | subhs PC, RA, #0x20000 -+ } else if (op == BC_ISLE) { -+ | it ls -+ | subls PC, RA, #0x20000 -+ } else { -+ | it hi -+ | subhi PC, RA, #0x20000 -+ } -+ | b <1 -+ |.endif -+ break; -+ -+ case BC_ISEQV: case BC_ISNEV: -+ vk = op == BC_ISEQV; -+ | // RA = src1*8, RC = src2, JMP with RC = target -+ | lsl RC, RC, #3 -+ | ldrd_iw CARG1, CARG2, RA, BASE -+ | ldrh RB, [PC, #2] -+ | ldrd_iw CARG3, CARG4, RC, BASE -+ | add PC, PC, #4 -+ | add RB, PC, RB, lsl #2 -+ | checktp CARG2, LJ_TISNUM -+ | it ls -+ | cmnls CARG4, #-LJ_TISNUM -+ if (vk) { -+ | bls ->BC_ISEQN_Z -+ } else { -+ | bls ->BC_ISNEN_Z -+ } -+ | // Either or both types are not numbers. -+ |.if FFI -+ | checktp CARG2, LJ_TCDATA -+ | checktpne CARG4, LJ_TCDATA -+ | beq ->vmeta_equal_cd -+ |.endif -+ | cmp CARG2, CARG4 // Compare types. -+ | bne >2 // Not the same type? -+ | checktp CARG2, LJ_TISPRI -+ | bhs >1 // Same type and primitive type? -+ | -+ | // Same types and not a primitive type. Compare GCobj or pvalue. -+ | cmp CARG1, CARG3 -+ if (vk) { -+ | bne >3 // Different GCobjs or pvalues? -+ |1: // Branch if same. -+ | sub PC, RB, #0x20000 -+ |2: // Different. -+ | ins_next -+ |3: -+ | checktp CARG2, LJ_TISTABUD -+ | bhi <2 // Different objects and not table/ud? -+ } else { -+ | beq >1 // Same GCobjs or pvalues? -+ | checktp CARG2, LJ_TISTABUD -+ | bhi >2 // Different objects and not table/ud? -+ } -+ | // Different tables or userdatas. Need to check __eq metamethod. -+ | // Field metatable must be at same offset for GCtab and GCudata! -+ | ldr TAB:RA, TAB:CARG1->metatable -+ | cmp TAB:RA, #0 -+ if (vk) { -+ | beq <2 // No metatable? -+ } else { -+ | beq >2 // No metatable? -+ } -+ | ldrb RA, TAB:RA->nomm -+ | mov CARG4, #1-vk // ne = 0 or 1. -+ | mov CARG2, CARG1 -+ | tst RA, #1<vmeta_equal // 'no __eq' flag not set? -+ if (vk) { -+ | b <2 -+ } else { -+ |2: // Branch if different. -+ | sub PC, RB, #0x20000 -+ |1: // Same. -+ | ins_next -+ } -+ break; -+ -+ case BC_ISEQS: case BC_ISNES: -+ vk = op == BC_ISEQS; -+ | // RA = src*8, RC = str_const (~), JMP with RC = target -+ | mvn RC, RC -+ | ldrd_i CARG1, CARG2, BASE, RA -+ | ldrh RB, [PC, #2] -+ | ldr STR:CARG3, [KBASE, RC, lsl #2] -+ | add PC, PC, #4 -+ | add RB, PC, RB, lsl #2 -+ | checktp CARG2, LJ_TSTR -+ |.if FFI -+ | bne >7 -+ | cmp CARG1, CARG3 -+ |.else -+ | it eq -+ | cmpeq CARG1, CARG3 -+ |.endif -+ if (vk) { -+ | it eq -+ | subeq PC, RB, #0x20000 -+ |1: -+ } else { -+ |1: -+ | it ne -+ | subne PC, RB, #0x20000 -+ } -+ | ins_next -+ | -+ |.if FFI -+ |7: -+ | checktp CARG2, LJ_TCDATA -+ | bne <1 -+ | b ->vmeta_equal_cd -+ |.endif -+ break; -+ -+ case BC_ISEQN: case BC_ISNEN: -+ vk = op == BC_ISEQN; -+ | // RA = src*8, RC = num_const (~), JMP with RC = target -+ | lsl RC, RC, #3 -+ | ldrd_iw CARG1, CARG2, RA, BASE -+ | ldrh RB, [PC, #2] -+ | ldrd_iw CARG3, CARG4, RC, KBASE -+ | add PC, PC, #4 -+ | add RB, PC, RB, lsl #2 -+ if (vk) { -+ |->BC_ISEQN_Z: -+ } else { -+ |->BC_ISNEN_Z: -+ } -+ | checktp CARG2, LJ_TISNUM -+ | bne >3 -+ | checktp CARG4, LJ_TISNUM -+ | bne >4 -+ | cmp CARG1, CARG3 -+ if (vk) { -+ | it eq -+ | subeq PC, RB, #0x20000 -+ |1: -+ } else { -+ |1: -+ | it ne -+ | subne PC, RB, #0x20000 -+ } -+ |2: -+ | ins_next -+ | -+ |3: // CARG1, CARG2 is not an integer. -+ |.if FFI -+ | bhi >7 -+ |.else -+ if (!vk) { -+ | it hi -+ | subhi PC, RB, #0x20000 -+ } -+ | bhi <2 -+ |.endif -+ |.if FPU -+ | checktp CARG4, LJ_TISNUM -+ | vmov s4, CARG3 -+ | vldr d0, [RA] -+ | ite lo -+ | vldrlo d1, [RC] -+ | vcvths.f64.s32 d1, s4 -+ | b >5 -+ |4: // CARG1 is an integer, d1 is a number. -+ | vmov s4, CARG1 -+ | vldr d1, [RC] -+ | vcvt.f64.s32 d0, s4 -+ |5: // d0 and d1 are numbers. -+ | vcmp.f64 d0, d1 -+ | vmrs -+ if (vk) { -+ | it eq -+ | subeq PC, RB, #0x20000 -+ } else { -+ | it ne -+ | subne PC, RB, #0x20000 -+ } -+ | b <2 -+ |.else -+ | // CARG1, CARG2 is a number. -+ | checktp CARG4, LJ_TISNUM -+ | it lo -+ | movlo RA, RB // Save RB. -+ | blo >5 -+ | // CARG1, CARG2 is a number, CARG3 is an integer. -+ | mov CARG1, CARG3 -+ | mov RC, RA -+ |4: // CARG1 is an integer, CARG3, CARG4 is a number. -+ | mov RA, RB // Save RB. -+ | bl extern __aeabi_i2d -+ | ldrd CARG3, CARG4, [RC] // Restore other operand. -+ |5: // CARG1, CARG2 and CARG3, CARG4 are numbers. -+ | bl extern __aeabi_cdcmpeq -+ if (vk) { -+ | it eq -+ | subeq PC, RA, #0x20000 -+ } else { -+ | it ne -+ | subne PC, RA, #0x20000 -+ } -+ | b <2 -+ |.endif -+ | -+ |.if FFI -+ |7: -+ | checktp CARG2, LJ_TCDATA -+ | bne <1 -+ | b ->vmeta_equal_cd -+ |.endif -+ break; -+ -+ case BC_ISEQP: case BC_ISNEP: -+ vk = op == BC_ISEQP; -+ | // RA = src*8, RC = primitive_type (~), JMP with RC = target -+ | ldrd_i CARG1, CARG2, BASE, RA -+ | ldrh RB, [PC, #2] -+ | add PC, PC, #4 -+ | mvn RC, RC -+ | add RB, PC, RB, lsl #2 -+ |.if FFI -+ | checktp CARG2, LJ_TCDATA -+ | beq ->vmeta_equal_cd -+ |.endif -+ | cmp CARG2, RC -+ if (vk) { -+ | it eq -+ | subeq PC, RB, #0x20000 -+ } else { -+ | it ne -+ | subne PC, RB, #0x20000 -+ } -+ | ins_next -+ break; -+ -+ /* -- Unary test and copy ops ------------------------------------------- */ -+ -+ case BC_ISTC: case BC_ISFC: case BC_IST: case BC_ISF: -+ | // RA = dst*8 or unused, RC = src, JMP with RC = target -+ | add RC, BASE, RC, lsl #3 -+ | ldrh RB, [PC, #2] -+ | ldrd CARG1, CARG2, [RC] -+ | add PC, PC, #4 -+ | add RB, PC, RB, lsl #2 -+ | checktp CARG2, LJ_TTRUE -+ if (op == BC_ISTC || op == BC_IST) { -+ | it ls -+ | subls PC, RB, #0x20000 -+ if (op == BC_ISTC) { -+ | it ls -+ | strdls_i CARG1, CARG2, BASE, RA -+ } -+ } else { -+ | it hi -+ | subhi PC, RB, #0x20000 -+ if (op == BC_ISFC) { -+ | it hi -+ | strdhi_i CARG1, CARG2, BASE, RA -+ } -+ } -+ | ins_next -+ break; -+ -+ case BC_ISTYPE: -+ | // RA = src*8, RC = -type -+ | ldrd_i CARG1, CARG2, BASE, RA -+ | ins_next1 -+ | cmn CARG2, RC -+ | ins_next2 -+ | bne ->vmeta_istype -+ | ins_next3 -+ break; -+ case BC_ISNUM: -+ | // RA = src*8, RC = -(TISNUM-1) -+ | ldrd_i CARG1, CARG2, BASE, RA -+ | ins_next1 -+ | checktp CARG2, LJ_TISNUM -+ | ins_next2 -+ | bhs ->vmeta_istype -+ | ins_next3 -+ break; -+ -+ /* -- Unary ops --------------------------------------------------------- */ -+ -+ case BC_MOV: -+ | // RA = dst*8, RC = src -+ | lsl RC, RC, #3 -+ | ins_next1 -+ | ldrd_i CARG1, CARG2, BASE, RC -+ | ins_next2 -+ | strd_i CARG1, CARG2, BASE, RA -+ | ins_next3 -+ break; -+ case BC_NOT: -+ | // RA = dst*8, RC = src -+ | add RC, BASE, RC, lsl #3 -+ | ins_next1 -+ | ldr CARG1, [RC, #4] -+ | add RA, BASE, RA -+ | ins_next2 -+ | checktp CARG1, LJ_TTRUE -+ | ite ls -+ | mvnls CARG2, #~LJ_TFALSE -+ | mvnhi CARG2, #~LJ_TTRUE -+ | str CARG2, [RA, #4] -+ | ins_next3 -+ break; -+ case BC_UNM: -+ | // RA = dst*8, RC = src -+ | lsl RC, RC, #3 -+ | ldrd_i CARG1, CARG2, BASE, RC -+ | ins_next1 -+ | ins_next2 -+ | checktp CARG2, LJ_TISNUM -+ | bhi ->vmeta_unm -+ | it ne -+ | eorne CARG2, CARG2, #0x80000000 -+ | bne >5 -+ | it eq -+ | rsbseq CARG1, CARG1, #0 -+ | it vs -+ | ldrdvs CARG1, CARG2, >9 -+ |5: -+ | strd_i CARG1, CARG2, BASE, RA -+ | ins_next3 -+ | -+ |.align 8 -+ |9: -+ | .long 0x00000000, 0x000041e0 // 2^31. jturnsek: swaped halfwords!!! -+ break; -+ case BC_LEN: -+ | // RA = dst*8, RC = src -+ | lsl RC, RC, #3 -+ | ldrd_i CARG1, CARG2, BASE, RC -+ | checkstr CARG2, >2 -+ | ldr CARG1, STR:CARG1->len -+ |1: -+ | mvn CARG2, #~LJ_TISNUM -+ | ins_next1 -+ | ins_next2 -+ | strd_i CARG1, CARG2, BASE, RA -+ | ins_next3 -+ |2: -+ | checktab CARG2, ->vmeta_len -+#if LJ_52 -+ | ldr TAB:CARG3, TAB:CARG1->metatable -+ | cmp TAB:CARG3, #0 -+ | bne >9 -+ |3: -+#endif -+ |->BC_LEN_Z: -+ | .IOS mov RC, BASE -+ | bl extern lj_tab_len // (GCtab *t) -+ | // Returns uint32_t (but less than 2^31). -+ | .IOS mov BASE, RC -+ | b <1 -+#if LJ_52 -+ |9: -+ | ldrb CARG4, TAB:CARG3->nomm -+ | tst CARG4, #1<vmeta_len -+#endif -+ break; -+ -+ /* -- Binary ops -------------------------------------------------------- */ -+ -+ |.macro ins_arithcheck, cond, ncond, target -+ ||if (vk == 1) { -+ | cmn CARG4, #-LJ_TISNUM -+ | it cond -+ | cmn..cond CARG2, #-LJ_TISNUM -+ ||} else { -+ | cmn CARG2, #-LJ_TISNUM -+ | it cond -+ | cmn..cond CARG4, #-LJ_TISNUM -+ ||} -+ | b..ncond target -+ |.endmacro -+ |.macro ins_arithcheck_int, target -+ | ins_arithcheck eq, ne, target -+ |.endmacro -+ |.macro ins_arithcheck_num, target -+ | ins_arithcheck lo, hs, target -+ |.endmacro -+ | -+ |.macro ins_arithpre -+ | decode_RB8 RB, INS -+ | decode_RC8 RC, INS -+ | // RA = dst*8, RB = src1*8, RC = src2*8 | num_const*8 -+ ||vk = ((int)op - BC_ADDVN) / (BC_ADDNV-BC_ADDVN); -+ ||switch (vk) { -+ ||case 0: -+ | .if FPU -+ | ldrd_iw CARG1, CARG2, RB, BASE -+ | ldrd_iw CARG3, CARG4, RC, KBASE -+ | .else -+ | ldrd_i CARG1, CARG2, BASE, RB -+ | ldrd_i CARG3, CARG4, KBASE, RC -+ | .endif -+ || break; -+ ||case 1: -+ | .if FPU -+ | ldrd_iw CARG3, CARG4, RB, BASE -+ | ldrd_iw CARG1, CARG2, RC, KBASE -+ | .else -+ | ldrd_i CARG3, CARG4, BASE, RB -+ | ldrd_i CARG1, CARG2, KBASE, RC -+ | .endif -+ || break; -+ ||default: -+ | .if FPU -+ | ldrd_iw CARG1, CARG2, RB, BASE -+ | ldrd_iw CARG3, CARG4, RC, BASE -+ | .else -+ | ldrd_i CARG1, CARG2, BASE, RB -+ | ldrd_i CARG3, CARG4, BASE, RC -+ | .endif -+ || break; -+ ||} -+ |.endmacro -+ | -+ |.macro ins_arithpre_fpu, reg1, reg2 -+ |.if FPU -+ ||if (vk == 1) { -+ | vldr reg2, [RB] -+ | vldr reg1, [RC] -+ ||} else { -+ | vldr reg1, [RB] -+ | vldr reg2, [RC] -+ ||} -+ |.endif -+ |.endmacro -+ | -+ |.macro ins_arithpost_fpu, reg -+ | ins_next1 -+ | add RA, BASE, RA -+ | ins_next2 -+ | vstr reg, [RA] -+ | ins_next3 -+ |.endmacro -+ | -+ |.macro ins_arithfallback, ins -+ ||switch (vk) { -+ ||case 0: -+ | ins ->vmeta_arith_vn -+ || break; -+ ||case 1: -+ | ins ->vmeta_arith_nv -+ || break; -+ ||default: -+ | ins ->vmeta_arith_vv -+ || break; -+ ||} -+ |.endmacro -+ | -+ |.macro ins_arithdn, intins, fpins, fpcall -+ | ins_arithpre -+ |.if "intins" ~= "vm_modi" and not FPU -+ | ins_next1 -+ |.endif -+ | ins_arithcheck_int >5 -+ |.if "intins" == "smull" -+ | smull CARG1, RC, CARG3, CARG1 -+ | cmp RC, CARG1, asr #31 -+ | ins_arithfallback bne -+ |.elif "intins" == "vm_modi" -+ | movs CARG2, CARG3 -+ | ins_arithfallback beq -+ | bl ->vm_modi -+ | mvn CARG2, #~LJ_TISNUM -+ |.else -+ | intins CARG1, CARG1, CARG3 -+ | ins_arithfallback bvs -+ |.endif -+ |4: -+ |.if "intins" == "vm_modi" or FPU -+ | ins_next1 -+ |.endif -+ | ins_next2 -+ | strd_i CARG1, CARG2, BASE, RA -+ | ins_next3 -+ |5: // FP variant. -+ | ins_arithpre_fpu d6, d7 -+ | ins_arithfallback ins_arithcheck_num -+ |.if FPU -+ |.if "intins" == "vm_modi" -+ | bl fpcall -+ |.else -+ | fpins d6, d6, d7 -+ |.endif -+ | ins_arithpost_fpu d6 -+ |.else -+ | bl fpcall -+ |.if "intins" ~= "vm_modi" -+ | ins_next1 -+ |.endif -+ | b <4 -+ |.endif -+ |.endmacro -+ | -+ |.macro ins_arithfp, fpins, fpcall -+ | ins_arithpre -+ |.if "fpins" ~= "extern" or HFABI -+ | ins_arithpre_fpu d0, d1 -+ |.endif -+ | ins_arithfallback ins_arithcheck_num -+ |.if "fpins" == "extern" -+ | .IOS mov RC, BASE -+ | bl fpcall -+ | .IOS mov BASE, RC -+ |.elif FPU -+ | fpins d0, d0, d1 -+ |.else -+ | bl fpcall -+ |.endif -+ |.if ("fpins" ~= "extern" or HFABI) and FPU -+ | ins_arithpost_fpu d0 -+ |.else -+ | ins_next1 -+ | ins_next2 -+ | strd_i CARG1, CARG2, BASE, RA -+ | ins_next3 -+ |.endif -+ |.endmacro -+ -+ case BC_ADDVN: case BC_ADDNV: case BC_ADDVV: -+ | ins_arithdn adds, vadd.f64, extern __aeabi_dadd -+ break; -+ case BC_SUBVN: case BC_SUBNV: case BC_SUBVV: -+ | ins_arithdn subs, vsub.f64, extern __aeabi_dsub -+ break; -+ case BC_MULVN: case BC_MULNV: case BC_MULVV: -+ | ins_arithdn smull, vmul.f64, extern __aeabi_dmul -+ break; -+ case BC_DIVVN: case BC_DIVNV: case BC_DIVVV: -+ | ins_arithfp vdiv.f64, extern __aeabi_ddiv -+ break; -+ case BC_MODVN: case BC_MODNV: case BC_MODVV: -+ | ins_arithdn vm_modi, vm_mod, ->vm_mod -+ break; -+ case BC_POW: -+ | // NYI: (partial) integer arithmetic. -+ | ins_arithfp extern, extern pow -+ break; -+ -+ case BC_CAT: -+ | decode_RB8 RC, INS -+ | decode_RC8 RB, INS -+ | // RA = dst*8, RC = src_start*8, RB = src_end*8 (note: RB/RC swapped!) -+ | sub CARG3, RB, RC -+ | str BASE, L->base -+ | add CARG2, BASE, RB -+ |->BC_CAT_Z: -+ | // RA = dst*8, RC = src_start*8, CARG2 = top-1 -+ | mov CARG1, L -+ | str PC, SAVE_PC -+ | lsr CARG3, CARG3, #3 -+ | bl extern lj_meta_cat // (lua_State *L, TValue *top, int left) -+ | // Returns NULL (finished) or TValue * (metamethod). -+ | ldr BASE, L->base -+ | cmp CRET1, #0 -+ | bne ->vmeta_binop -+ | ldrd_i CARG3, CARG4, BASE, RC -+ | ins_next1 -+ | ins_next2 -+ | strd_i CARG3, CARG4, BASE, RA // Copy result to RA. -+ | ins_next3 -+ break; -+ -+ /* -- Constant ops ------------------------------------------------------ */ -+ -+ case BC_KSTR: -+ | // RA = dst*8, RC = str_const (~) -+ | mvn RC, RC -+ | ins_next1 -+ | ldr CARG1, [KBASE, RC, lsl #2] -+ | mvn CARG2, #~LJ_TSTR -+ | ins_next2 -+ | strd_i CARG1, CARG2, BASE, RA -+ | ins_next3 -+ break; -+ case BC_KCDATA: -+ |.if FFI -+ | // RA = dst*8, RC = cdata_const (~) -+ | mvn RC, RC -+ | ins_next1 -+ | ldr CARG1, [KBASE, RC, lsl #2] -+ | mvn CARG2, #~LJ_TCDATA -+ | ins_next2 -+ | strd_i CARG1, CARG2, BASE, RA -+ | ins_next3 -+ |.endif -+ break; -+ case BC_KSHORT: -+ | // RA = dst*8, (RC = int16_literal) -+ | mov CARG1, INS, asr #16 // Refetch sign-extended reg. -+ | mvn CARG2, #~LJ_TISNUM -+ | ins_next1 -+ | ins_next2 -+ | strd_i CARG1, CARG2, BASE, RA -+ | ins_next3 -+ break; -+ case BC_KNUM: -+ | // RA = dst*8, RC = num_const -+ | lsl RC, RC, #3 -+ | ins_next1 -+ | ldrd_i CARG1, CARG2, KBASE, RC -+ | ins_next2 -+ | strd_i CARG1, CARG2, BASE, RA -+ | ins_next3 -+ break; -+ case BC_KPRI: -+ | // RA = dst*8, RC = primitive_type (~) -+ | add RA, BASE, RA -+ | mvn RC, RC -+ | ins_next1 -+ | ins_next2 -+ | str RC, [RA, #4] -+ | ins_next3 -+ break; -+ case BC_KNIL: -+ | // RA = base*8, RC = end -+ | add RA, BASE, RA -+ | add RC, BASE, RC, lsl #3 -+ | mvn CARG1, #~LJ_TNIL -+ | str CARG1, [RA, #4] -+ | add RA, RA, #8 -+ |1: -+ | str CARG1, [RA, #4] -+ | cmp RA, RC -+ | add RA, RA, #8 -+ | blt <1 -+ | ins_next_ -+ break; -+ -+ /* -- Upvalue and function ops ------------------------------------------ */ -+ -+ case BC_UGET: -+ | // RA = dst*8, RC = uvnum -+ | ldr LFUNC:CARG2, [BASE, FRAME_FUNC] -+ | lsl RC, RC, #2 -+ | add RC, RC, #offsetof(GCfuncL, uvptr) -+ | ldr UPVAL:CARG2, [LFUNC:CARG2, RC] -+ | ldr CARG2, UPVAL:CARG2->v -+ | ldrd CARG3, CARG4, [CARG2] -+ | ins_next1 -+ | ins_next2 -+ | strd_i CARG3, CARG4, BASE, RA -+ | ins_next3 -+ break; -+ case BC_USETV: -+ | // RA = uvnum*8, RC = src -+ | ldr LFUNC:CARG2, [BASE, FRAME_FUNC] -+ | lsr RA, RA, #1 -+ | add RA, RA, #offsetof(GCfuncL, uvptr) -+ | lsl RC, RC, #3 -+ | ldr UPVAL:CARG2, [LFUNC:CARG2, RA] -+ | ldrd_i CARG3, CARG4, BASE, RC -+ | ldrb RB, UPVAL:CARG2->marked -+ | ldrb RC, UPVAL:CARG2->closed -+ | ldr CARG2, UPVAL:CARG2->v -+ | tst RB, #LJ_GC_BLACK // isblack(uv) -+ | add RB, CARG4, #-LJ_TISGCV -+ | it ne -+ | cmpne RC, #0 -+ | strd CARG3, CARG4, [CARG2] -+ | bne >2 // Upvalue is closed and black? -+ |1: -+ | ins_next -+ | -+ |2: // Check if new value is collectable. -+ | cmn RB, #-(LJ_TNUMX - LJ_TISGCV) -+ | it hi -+ | ldrbhi RC, GCOBJ:CARG3->gch.marked -+ | bls <1 // tvisgcv(v) -+ | sub CARG1, DISPATCH, #-GG_DISP2G -+ | tst RC, #LJ_GC_WHITES -+ | // Crossed a write barrier. Move the barrier forward. -+ |.if IOS -+ | beq <1 -+ | mov RC, BASE -+ | bl extern lj_gc_barrieruv // (global_State *g, TValue *tv) -+ | mov BASE, RC -+ |.else -+ | it ne -+ | blne extern lj_gc_barrieruv // (global_State *g, TValue *tv) -+ |.endif -+ | b <1 -+ break; -+ case BC_USETS: -+ | // RA = uvnum*8, RC = str_const (~) -+ | ldr LFUNC:CARG2, [BASE, FRAME_FUNC] -+ | lsr RA, RA, #1 -+ | add RA, RA, #offsetof(GCfuncL, uvptr) -+ | mvn RC, RC -+ | ldr UPVAL:CARG2, [LFUNC:CARG2, RA] -+ | ldr STR:CARG3, [KBASE, RC, lsl #2] -+ | ldrb RB, UPVAL:CARG2->marked -+ | ldrb RC, UPVAL:CARG2->closed -+ | ldr CARG2, UPVAL:CARG2->v -+ | mvn CARG4, #~LJ_TSTR -+ | tst RB, #LJ_GC_BLACK // isblack(uv) -+ | ldrb RB, STR:CARG3->marked -+ | strd CARG3, CARG4, [CARG2] -+ | bne >2 -+ |1: -+ | ins_next -+ | -+ |2: // Check if string is white and ensure upvalue is closed. -+ | tst RB, #LJ_GC_WHITES // iswhite(str) -+ | it ne -+ | cmpne RC, #0 -+ | sub CARG1, DISPATCH, #-GG_DISP2G -+ | // Crossed a write barrier. Move the barrier forward. -+ |.if IOS -+ | beq <1 -+ | mov RC, BASE -+ | bl extern lj_gc_barrieruv // (global_State *g, TValue *tv) -+ | mov BASE, RC -+ |.else -+ | it ne -+ | blne extern lj_gc_barrieruv // (global_State *g, TValue *tv) -+ |.endif -+ | b <1 -+ break; -+ case BC_USETN: -+ | // RA = uvnum*8, RC = num_const -+ | ldr LFUNC:CARG2, [BASE, FRAME_FUNC] -+ | lsr RA, RA, #1 -+ | add RA, RA, #offsetof(GCfuncL, uvptr) -+ | lsl RC, RC, #3 -+ | ldr UPVAL:CARG2, [LFUNC:CARG2, RA] -+ | ldrd_i CARG3, CARG4, KBASE, RC -+ | ldr CARG2, UPVAL:CARG2->v -+ | ins_next1 -+ | ins_next2 -+ | strd CARG3, CARG4, [CARG2] -+ | ins_next3 -+ break; -+ case BC_USETP: -+ | // RA = uvnum*8, RC = primitive_type (~) -+ | ldr LFUNC:CARG2, [BASE, FRAME_FUNC] -+ | lsr RA, RA, #1 -+ | add RA, RA, #offsetof(GCfuncL, uvptr) -+ | ldr UPVAL:CARG2, [LFUNC:CARG2, RA] -+ | mvn RC, RC -+ | ldr CARG2, UPVAL:CARG2->v -+ | ins_next1 -+ | ins_next2 -+ | str RC, [CARG2, #4] -+ | ins_next3 -+ break; -+ -+ case BC_UCLO: -+ | // RA = level*8, RC = target -+ | ldr CARG3, L->openupval -+ | add RC, PC, RC, lsl #2 -+ | str BASE, L->base -+ | cmp CARG3, #0 -+ | sub PC, RC, #0x20000 -+ | beq >1 -+ | mov CARG1, L -+ | add CARG2, BASE, RA -+ | bl extern lj_func_closeuv // (lua_State *L, TValue *level) -+ | ldr BASE, L->base -+ |1: -+ | ins_next -+ break; -+ -+ case BC_FNEW: -+ | // RA = dst*8, RC = proto_const (~) (holding function prototype) -+ | mvn RC, RC -+ | str BASE, L->base -+ | ldr CARG2, [KBASE, RC, lsl #2] -+ | str PC, SAVE_PC -+ | ldr CARG3, [BASE, FRAME_FUNC] -+ | mov CARG1, L -+ | // (lua_State *L, GCproto *pt, GCfuncL *parent) -+ | bl extern lj_func_newL_gc -+ | // Returns GCfuncL *. -+ | ldr BASE, L->base -+ | mvn CARG2, #~LJ_TFUNC -+ | ins_next1 -+ | ins_next2 -+ | strd_i CARG1, CARG2, BASE, RA -+ | ins_next3 -+ break; -+ -+ /* -- Table ops --------------------------------------------------------- */ -+ -+ case BC_TNEW: -+ case BC_TDUP: -+ | // RA = dst*8, RC = (hbits|asize) | tab_const (~) -+ if (op == BC_TDUP) { -+ | mvn RC, RC -+ } -+ | sub CARG1, DISPATCH, #-DISPATCH_GL(gc.total) -+ | ldr CARG3, [CARG1] -+ | sub CARG1, DISPATCH, #-DISPATCH_GL(gc.threshold) -+ | ldr CARG4, [CARG1] -+ | str BASE, L->base -+ | str PC, SAVE_PC -+ | cmp CARG3, CARG4 -+ | mov CARG1, L -+ | bhs >5 -+ |1: -+ if (op == BC_TNEW) { -+ | lsl CARG2, RC, #21 -+ | lsr CARG3, RC, #11 -+ | asr RC, CARG2, #21 -+ | lsr CARG2, CARG2, #21 -+ | cmn RC, #1 -+ | it eq -+ | addeq CARG2, CARG2, #2 -+ | bl extern lj_tab_new // (lua_State *L, int32_t asize, uint32_t hbits) -+ | // Returns GCtab *. -+ } else { -+ | ldr CARG2, [KBASE, RC, lsl #2] -+ | bl extern lj_tab_dup // (lua_State *L, Table *kt) -+ | // Returns GCtab *. -+ } -+ | ldr BASE, L->base -+ | mvn CARG2, #~LJ_TTAB -+ | ins_next1 -+ | ins_next2 -+ | strd_i CARG1, CARG2, BASE, RA -+ | ins_next3 -+ |5: -+ | bl extern lj_gc_step_fixtop // (lua_State *L) -+ | mov CARG1, L -+ | b <1 -+ break; -+ -+ case BC_GGET: -+ | // RA = dst*8, RC = str_const (~) -+ case BC_GSET: -+ | // RA = dst*8, RC = str_const (~) -+ | ldr LFUNC:CARG2, [BASE, FRAME_FUNC] -+ | mvn RC, RC -+ | ldr TAB:CARG1, LFUNC:CARG2->env -+ | ldr STR:RC, [KBASE, RC, lsl #2] -+ if (op == BC_GGET) { -+ | b ->BC_TGETS_Z -+ } else { -+ | b ->BC_TSETS_Z -+ } -+ break; -+ -+ case BC_TGETV: -+ | decode_RB8 RB, INS -+ | decode_RC8 RC, INS -+ | // RA = dst*8, RB = table*8, RC = key*8 -+ | ldrd_i TAB:CARG1, CARG2, BASE, RB -+ | ldrd_i CARG3, CARG4, BASE, RC -+ | checktab CARG2, ->vmeta_tgetv // STALL: load CARG1, CARG2. -+ | checktp CARG4, LJ_TISNUM // Integer key? -+ | it eq -+ | ldreq CARG4, TAB:CARG1->array -+ | it eq -+ | ldreq CARG2, TAB:CARG1->asize -+ | bne >9 -+ | -+ | add CARG4, CARG4, CARG3, lsl #3 -+ | cmp CARG3, CARG2 // In array part? -+ | it lo -+ | ldrdlo CARG3, CARG4, [CARG4] -+ | bhs ->vmeta_tgetv -+ | ins_next1 // Overwrites RB! -+ | checktp CARG4, LJ_TNIL -+ | beq >5 -+ |1: -+ | ins_next2 -+ | strd_i CARG3, CARG4, BASE, RA -+ | ins_next3 -+ | -+ |5: // Check for __index if table value is nil. -+ | ldr TAB:CARG2, TAB:CARG1->metatable -+ | cmp TAB:CARG2, #0 -+ | beq <1 // No metatable: done. -+ | ldrb CARG2, TAB:CARG2->nomm -+ | tst CARG2, #1<vmeta_tgetv -+ | -+ |9: -+ | checktp CARG4, LJ_TSTR // String key? -+ | it eq -+ | moveq STR:RC, CARG3 -+ | beq ->BC_TGETS_Z -+ | b ->vmeta_tgetv -+ break; -+ case BC_TGETS: -+ | decode_RB8 RB, INS -+ | and RC, RC, #255 -+ | // RA = dst*8, RB = table*8, RC = str_const (~) -+ | ldrd_i CARG1, CARG2, BASE, RB -+ | mvn RC, RC -+ | ldr STR:RC, [KBASE, RC, lsl #2] // STALL: early RC. -+ | checktab CARG2, ->vmeta_tgets1 -+ |->BC_TGETS_Z: -+ | // (TAB:RB =) TAB:CARG1 = GCtab *, STR:RC = GCstr *, RA = dst*8 -+ | ldr CARG3, TAB:CARG1->hmask -+ | ldr CARG4, STR:RC->sid -+ | ldr NODE:INS, TAB:CARG1->node -+ | mov TAB:RB, TAB:CARG1 -+ | and CARG3, CARG3, CARG4 // idx = str->sid & tab->hmask -+ | add CARG3, CARG3, CARG3, lsl #1 -+ | add NODE:INS, NODE:INS, CARG3, lsl #3 // node = tab->node + idx*3*8 -+ |1: -+ | ldrd CARG1, CARG2, NODE:INS->key // STALL: early NODE:INS. -+ | ldrd CARG3, CARG4, NODE:INS->val -+ | ldr NODE:INS, NODE:INS->next -+ | checktp CARG2, LJ_TSTR -+ | it eq -+ | cmpeq CARG1, STR:RC -+ | bne >4 -+ | checktp CARG4, LJ_TNIL -+ | beq >5 -+ |3: -+ | ins_next1 -+ | ins_next2 -+ | strd_i CARG3, CARG4, BASE, RA -+ | ins_next3 -+ | -+ |4: // Follow hash chain. -+ | cmp NODE:INS, #0 -+ | bne <1 -+ | // End of hash chain: key not found, nil result. -+ | -+ |5: // Check for __index if table value is nil. -+ | ldr TAB:CARG1, TAB:RB->metatable -+ | mov CARG3, #0 // Optional clear of undef. value (during load stall). -+ | mvn CARG4, #~LJ_TNIL -+ | cmp TAB:CARG1, #0 -+ | beq <3 // No metatable: done. -+ | ldrb CARG2, TAB:CARG1->nomm -+ | tst CARG2, #1<vmeta_tgets -+ break; -+ case BC_TGETB: -+ | decode_RB8 RB, INS -+ | and RC, RC, #255 -+ | // RA = dst*8, RB = table*8, RC = index -+ | ldrd_i CARG1, CARG2, BASE, RB -+ | checktab CARG2, ->vmeta_tgetb // STALL: load CARG1, CARG2. -+ | ldr CARG3, TAB:CARG1->asize -+ | ldr CARG4, TAB:CARG1->array -+ | lsl CARG2, RC, #3 -+ | cmp RC, CARG3 -+ | ldrdlo_i CARG3, CARG4, CARG4, CARG2 -+ | bhs ->vmeta_tgetb -+ | ins_next1 // Overwrites RB! -+ | checktp CARG4, LJ_TNIL -+ | beq >5 -+ |1: -+ | ins_next2 -+ | strd_i CARG3, CARG4, BASE, RA -+ | ins_next3 -+ | -+ |5: // Check for __index if table value is nil. -+ | ldr TAB:CARG2, TAB:CARG1->metatable -+ | cmp TAB:CARG2, #0 -+ | beq <1 // No metatable: done. -+ | ldrb CARG2, TAB:CARG2->nomm -+ | tst CARG2, #1<vmeta_tgetb -+ break; -+ case BC_TGETR: -+ | decode_RB8 RB, INS -+ | decode_RC8 RC, INS -+ | // RA = dst*8, RB = table*8, RC = key*8 -+ | ldr TAB:CARG1, [BASE, RB] -+ | ldr CARG2, [BASE, RC] -+ | ldr CARG4, TAB:CARG1->array -+ | ldr CARG3, TAB:CARG1->asize -+ | add CARG4, CARG4, CARG2, lsl #3 -+ | cmp CARG2, CARG3 // In array part? -+ | bhs ->vmeta_tgetr -+ | ldrd CARG1, CARG2, [CARG4] -+ |->BC_TGETR_Z: -+ | ins_next1 -+ | ins_next2 -+ | strd_i CARG1, CARG2, BASE, RA -+ | ins_next3 -+ break; -+ -+ case BC_TSETV: -+ | decode_RB8 RB, INS -+ | decode_RC8 RC, INS -+ | // RA = src*8, RB = table*8, RC = key*8 -+ | ldrd_i TAB:CARG1, CARG2, BASE, RB -+ | ldrd_i CARG3, CARG4, BASE, RC -+ | checktab CARG2, ->vmeta_tsetv // STALL: load CARG1, CARG2. -+ | checktp CARG4, LJ_TISNUM // Integer key? -+ | it eq -+ | ldreq CARG2, TAB:CARG1->array -+ | it eq -+ | ldreq CARG4, TAB:CARG1->asize -+ | bne >9 -+ | -+ | add CARG2, CARG2, CARG3, lsl #3 -+ | cmp CARG3, CARG4 // In array part? -+ | it lo -+ | ldrlo INS, [CARG2, #4] -+ | bhs ->vmeta_tsetv -+ | ins_next1 // Overwrites RB! -+ | checktp INS, LJ_TNIL -+ | ldrb INS, TAB:CARG1->marked -+ | ldrd_i CARG3, CARG4, BASE, RA -+ | beq >5 -+ |1: -+ | tst INS, #LJ_GC_BLACK // isblack(table) -+ | strd CARG3, CARG4, [CARG2] -+ | bne >7 -+ |2: -+ | ins_next2 -+ | ins_next3 -+ | -+ |5: // Check for __newindex if previous value is nil. -+ | ldr TAB:RA, TAB:CARG1->metatable -+ | cmp TAB:RA, #0 -+ | beq <1 // No metatable: done. -+ | ldrb RA, TAB:RA->nomm -+ | tst RA, #1<vmeta_tsetv -+ | -+ |7: // Possible table write barrier for the value. Skip valiswhite check. -+ | barrierback TAB:CARG1, INS, CARG3 -+ | b <2 -+ | -+ |9: -+ | checktp CARG4, LJ_TSTR // String key? -+ | it eq -+ | moveq STR:RC, CARG3 -+ | beq ->BC_TSETS_Z -+ | b ->vmeta_tsetv -+ break; -+ case BC_TSETS: -+ | decode_RB8 RB, INS -+ | and RC, RC, #255 -+ | // RA = src*8, RB = table*8, RC = str_const (~) -+ | ldrd_i CARG1, CARG2, BASE, RB -+ | mvn RC, RC -+ | ldr STR:RC, [KBASE, RC, lsl #2] // STALL: early RC. -+ | checktab CARG2, ->vmeta_tsets1 -+ |->BC_TSETS_Z: -+ | // (TAB:RB =) TAB:CARG1 = GCtab *, STR:RC = GCstr *, RA = dst*8 -+ | ldr CARG3, TAB:CARG1->hmask -+ | ldr CARG4, STR:RC->sid -+ | ldr NODE:INS, TAB:CARG1->node -+ | mov TAB:RB, TAB:CARG1 -+ | and CARG3, CARG3, CARG4 // idx = str->sid & tab->hmask -+ | add CARG3, CARG3, CARG3, lsl #1 -+ | mov CARG4, #0 -+ | add NODE:INS, NODE:INS, CARG3, lsl #3 // node = tab->node + idx*3*8 -+ | strb CARG4, TAB:RB->nomm // Clear metamethod cache. -+ |1: -+ | ldrd CARG1, CARG2, NODE:INS->key -+ | ldr CARG4, NODE:INS->val.it -+ | ldr NODE:CARG3, NODE:INS->next -+ | checktp CARG2, LJ_TSTR -+ | it eq -+ | cmpeq CARG1, STR:RC -+ | bne >5 -+ | ldrb CARG2, TAB:RB->marked -+ | checktp CARG4, LJ_TNIL // Key found, but nil value? -+ | ldrd_i CARG3, CARG4, BASE, RA -+ | beq >4 -+ |2: -+ | tst CARG2, #LJ_GC_BLACK // isblack(table) -+ | strd CARG3, CARG4, NODE:INS->val -+ | bne >7 -+ |3: -+ | ins_next -+ | -+ |4: // Check for __newindex if previous value is nil. -+ | ldr TAB:CARG1, TAB:RB->metatable -+ | cmp TAB:CARG1, #0 -+ | beq <2 // No metatable: done. -+ | ldrb CARG1, TAB:CARG1->nomm -+ | tst CARG1, #1<vmeta_tsets -+ | -+ |5: // Follow hash chain. -+ | movs NODE:INS, NODE:CARG3 -+ | bne <1 -+ | // End of hash chain: key not found, add a new one. -+ | -+ | // But check for __newindex first. -+ | ldr TAB:CARG1, TAB:RB->metatable -+ | mov CARG3, TMPDp -+ | str PC, SAVE_PC -+ | cmp TAB:CARG1, #0 // No metatable: continue. -+ | str BASE, L->base -+ | it ne -+ | ldrbne CARG2, TAB:CARG1->nomm -+ | mov CARG1, L -+ | beq >6 -+ | tst CARG2, #1<vmeta_tsets // 'no __newindex' flag NOT set: check. -+ |6: -+ | mvn CARG4, #~LJ_TSTR -+ | str STR:RC, TMPDlo -+ | mov CARG2, TAB:RB -+ | str CARG4, TMPDhi -+ | bl extern lj_tab_newkey // (lua_State *L, GCtab *t, TValue *k) -+ | // Returns TValue *. -+ | ldr BASE, L->base -+ | ldrd_i CARG3, CARG4, BASE, RA -+ | strd CARG3, CARG4, [CRET1] -+ | b <3 // No 2nd write barrier needed. -+ | -+ |7: // Possible table write barrier for the value. Skip valiswhite check. -+ | barrierback TAB:RB, CARG2, CARG3 -+ | b <3 -+ break; -+ case BC_TSETB: -+ | decode_RB8 RB, INS -+ | and RC, RC, #255 -+ | // RA = src*8, RB = table*8, RC = index -+ | ldrd_i CARG1, CARG2, BASE, RB -+ | checktab CARG2, ->vmeta_tsetb // STALL: load CARG1, CARG2. -+ | ldr CARG3, TAB:CARG1->asize -+ | ldr RB, TAB:CARG1->array -+ | lsl CARG2, RC, #3 -+ | cmp RC, CARG3 -+ | ldrdlo_iw CARG3, CARG4, CARG2, RB -+ | bhs ->vmeta_tsetb -+ | ins_next1 // Overwrites RB! -+ | checktp CARG4, LJ_TNIL -+ | ldrb INS, TAB:CARG1->marked -+ | ldrd_i CARG3, CARG4, BASE, RA -+ | beq >5 -+ |1: -+ | tst INS, #LJ_GC_BLACK // isblack(table) -+ | strd CARG3, CARG4, [CARG2] -+ | bne >7 -+ |2: -+ | ins_next2 -+ | ins_next3 -+ | -+ |5: // Check for __newindex if previous value is nil. -+ | ldr TAB:RA, TAB:CARG1->metatable -+ | cmp TAB:RA, #0 -+ | beq <1 // No metatable: done. -+ | ldrb RA, TAB:RA->nomm -+ | tst RA, #1<vmeta_tsetb -+ | -+ |7: // Possible table write barrier for the value. Skip valiswhite check. -+ | barrierback TAB:CARG1, INS, CARG3 -+ | b <2 -+ break; -+ case BC_TSETR: -+ | decode_RB8 RB, INS -+ | decode_RC8 RC, INS -+ | // RA = src*8, RB = table*8, RC = key*8 -+ | ldr TAB:CARG2, [BASE, RB] -+ | ldr CARG3, [BASE, RC] -+ | ldrb INS, TAB:CARG2->marked -+ | ldr CARG1, TAB:CARG2->array -+ | ldr CARG4, TAB:CARG2->asize -+ | tst INS, #LJ_GC_BLACK // isblack(table) -+ | add CARG1, CARG1, CARG3, lsl #3 -+ | bne >7 -+ |2: -+ | cmp CARG3, CARG4 // In array part? -+ | bhs ->vmeta_tsetr -+ |->BC_TSETR_Z: -+ | ldrd_i CARG3, CARG4, BASE, RA -+ | ins_next1 -+ | ins_next2 -+ | strd CARG3, CARG4, [CARG1] -+ | ins_next3 -+ | -+ |7: // Possible table write barrier for the value. Skip valiswhite check. -+ | barrierback TAB:CARG2, INS, RB -+ | b <2 -+ break; -+ -+ case BC_TSETM: -+ | // RA = base*8 (table at base-1), RC = num_const (start index) -+ | add RA, BASE, RA -+ |1: -+ | ldr RB, SAVE_MULTRES -+ | ldr TAB:CARG2, [RA, #-8] // Guaranteed to be a table. -+ | ldr CARG1, [KBASE, RC, lsl #3] // Integer constant is in lo-word. -+ | subs RB, RB, #8 -+ | ldr CARG4, TAB:CARG2->asize -+ | beq >4 // Nothing to copy? -+ | add CARG3, CARG1, RB, lsr #3 -+ | cmp CARG3, CARG4 -+ | ldr CARG4, TAB:CARG2->array -+ | add RB, RA, RB -+ | bhi >5 -+ | add INS, CARG4, CARG1, lsl #3 -+ | ldrb CARG1, TAB:CARG2->marked -+ |3: // Copy result slots to table. -+ | ldrd CARG3, CARG4, [RA], #8 -+ | strd CARG3, CARG4, [INS], #8 -+ | cmp RA, RB -+ | blo <3 -+ | tst CARG1, #LJ_GC_BLACK // isblack(table) -+ | bne >7 -+ |4: -+ | ins_next -+ | -+ |5: // Need to resize array part. -+ | str BASE, L->base -+ | mov CARG1, L -+ | str PC, SAVE_PC -+ | bl extern lj_tab_reasize // (lua_State *L, GCtab *t, int nasize) -+ | // Must not reallocate the stack. -+ | .IOS ldr BASE, L->base -+ | b <1 -+ | -+ |7: // Possible table write barrier for any value. Skip valiswhite check. -+ | barrierback TAB:CARG2, CARG1, CARG3 -+ | b <4 -+ break; -+ -+ /* -- Calls and vararg handling ----------------------------------------- */ -+ -+ case BC_CALLM: -+ | // RA = base*8, (RB = nresults+1,) RC = extra_nargs -+ | ldr CARG1, SAVE_MULTRES -+ | decode_RC8 NARGS8:RC, INS -+ | add NARGS8:RC, NARGS8:RC, CARG1 -+ | b ->BC_CALL_Z -+ break; -+ case BC_CALL: -+ | decode_RC8 NARGS8:RC, INS -+ | // RA = base*8, (RB = nresults+1,) RC = (nargs+1)*8 -+ |->BC_CALL_Z: -+ | mov RB, BASE // Save old BASE for vmeta_call. -+ | ldrd_iw CARG3, CARG4, BASE, RA -+ | sub NARGS8:RC, NARGS8:RC, #8 -+ | add BASE, BASE, #8 -+ | checkfunc CARG4, ->vmeta_call -+ | ins_call -+ break; -+ -+ case BC_CALLMT: -+ | // RA = base*8, (RB = 0,) RC = extra_nargs -+ | ldr CARG1, SAVE_MULTRES -+ | add NARGS8:RC, CARG1, RC, lsl #3 -+ | b ->BC_CALLT1_Z -+ break; -+ case BC_CALLT: -+ | lsl NARGS8:RC, RC, #3 -+ | // RA = base*8, (RB = 0,) RC = (nargs+1)*8 -+ |->BC_CALLT1_Z: -+ | ldrd_iw LFUNC:CARG3, CARG4, RA, BASE -+ | sub NARGS8:RC, NARGS8:RC, #8 -+ | add RA, RA, #8 -+ | checkfunc CARG4, ->vmeta_callt -+ | ldr PC, [BASE, FRAME_PC] -+ |->BC_CALLT2_Z: -+ | mov RB, #0 -+ | ldrb CARG4, LFUNC:CARG3->ffid -+ | tst PC, #FRAME_TYPE -+ | bne >7 -+ |1: -+ | str LFUNC:CARG3, [BASE, FRAME_FUNC] // Copy function down, but keep PC. -+ | cmp NARGS8:RC, #0 -+ | beq >3 -+ |2: -+ | ldrd_i CARG1, CARG2, RA, RB -+ | add INS, RB, #8 -+ | cmp INS, NARGS8:RC -+ | strd_i CARG1, CARG2, BASE, RB -+ | mov RB, INS -+ | bne <2 -+ |3: -+ | cmp CARG4, #1 // (> FF_C) Calling a fast function? -+ | bhi >5 -+ |4: -+ | ins_callt -+ | -+ |5: // Tailcall to a fast function with a Lua frame below. -+ | ldr INS, [PC, #-4] -+ | decode_RA8 RA, INS -+ | sub CARG1, BASE, RA -+ | ldr LFUNC:CARG1, [CARG1, #-16] -+ | ldr CARG1, LFUNC:CARG1->field_pc -+ | ldr KBASE, [CARG1, #PC2PROTO(k)] -+ | b <4 -+ | -+ |7: // Tailcall from a vararg function. -+ | eor PC, PC, #FRAME_VARG -+ | tst PC, #FRAME_TYPEP // Vararg frame below? -+ | it ne -+ | movne CARG4, #0 // Clear ffid if no Lua function below. -+ | bne <1 -+ | sub BASE, BASE, PC -+ | ldr PC, [BASE, FRAME_PC] -+ | tst PC, #FRAME_TYPE -+ | it ne -+ | movne CARG4, #0 // Clear ffid if no Lua function below. -+ | b <1 -+ break; -+ -+ case BC_ITERC: -+ | // RA = base*8, (RB = nresults+1, RC = nargs+1 (2+1)) -+ | add RA, BASE, RA -+ | mov RB, BASE // Save old BASE for vmeta_call. -+ | ldrd CARG3, CARG4, [RA, #-16] -+ | ldrd CARG1, CARG2, [RA, #-8] -+ | add BASE, RA, #8 -+ | strd CARG3, CARG4, [RA, #8] // Copy state. -+ | strd CARG1, CARG2, [RA, #16] // Copy control var. -+ | // STALL: locked CARG3, CARG4. -+ | ldrd LFUNC:CARG3, CARG4, [RA, #-24] -+ | mov NARGS8:RC, #16 // Iterators get 2 arguments. -+ | // STALL: load CARG3, CARG4. -+ | strd LFUNC:CARG3, CARG4, [RA] // Copy callable. -+ | checkfunc CARG4, ->vmeta_call -+ | ins_call -+ break; -+ -+ case BC_ITERN: -+ |.if JIT -+ | hotloop -+ |.endif -+ |->vm_IITERN: -+ | // RA = base*8, (RB = nresults+1, RC = nargs+1 (2+1)) -+ | add RA, BASE, RA -+ | ldr TAB:RB, [RA, #-16] -+ | ldr CARG1, [RA, #-8] // Get index from control var. -+ | ldr INS, TAB:RB->asize -+ | ldr CARG2, TAB:RB->array -+ | add PC, PC, #4 -+ |1: // Traverse array part. -+ | subs RC, CARG1, INS -+ | add CARG3, CARG2, CARG1, lsl #3 -+ | bhs >5 // Index points after array part? -+ | ldrd CARG3, CARG4, [CARG3] -+ | checktp CARG4, LJ_TNIL -+ | it eq -+ | addeq CARG1, CARG1, #1 // Skip holes in array part. -+ | beq <1 -+ | ldrh RC, [PC, #-2] -+ | mvn CARG2, #~LJ_TISNUM -+ | strd CARG3, CARG4, [RA, #8] -+ | add RC, PC, RC, lsl #2 -+ | add RB, CARG1, #1 -+ | strd CARG1, CARG2, [RA] -+ | sub PC, RC, #0x20000 -+ | str RB, [RA, #-8] // Update control var. -+ |3: -+ | ins_next -+ | -+ |5: // Traverse hash part. -+ | ldr CARG4, TAB:RB->hmask -+ | ldr NODE:RB, TAB:RB->node -+ |6: -+ | add CARG1, RC, RC, lsl #1 -+ | cmp RC, CARG4 // End of iteration? Branch to ITERL+1. -+ | add NODE:CARG3, NODE:RB, CARG1, lsl #3 // node = tab->node + idx*3*8 -+ | bhi <3 -+ | ldrd CARG1, CARG2, NODE:CARG3->val -+ | checktp CARG2, LJ_TNIL -+ | add RC, RC, #1 -+ | beq <6 // Skip holes in hash part. -+ | ldrh RB, [PC, #-2] -+ | add RC, RC, INS -+ | ldrd CARG3, CARG4, NODE:CARG3->key -+ | str RC, [RA, #-8] // Update control var. -+ | strd CARG1, CARG2, [RA, #8] -+ | add RC, PC, RB, lsl #2 -+ | sub PC, RC, #0x20000 -+ | strd CARG3, CARG4, [RA] -+ | b <3 -+ break; -+ -+ case BC_ISNEXT: -+ | // RA = base*8, RC = target (points to ITERN) -+ | add RA, BASE, RA -+ | add RC, PC, RC, lsl #2 -+ | ldrd CFUNC:CARG1, CFUNC:CARG2, [RA, #-24] -+ | ldr CARG3, [RA, #-12] -+ | ldr CARG4, [RA, #-4] -+ | checktp CARG2, LJ_TFUNC -+ | it eq -+ | ldrbeq CARG1, CFUNC:CARG1->ffid -+ | checktpeq CARG3, LJ_TTAB -+ | checktpeq CARG4, LJ_TNIL -+ | it eq -+ | cmpeq CARG1, #FF_next_N -+ | it eq -+ | subeq PC, RC, #0x20000 -+ | bne >5 -+ | ins_next1 -+ | ins_next2 -+ | mov CARG1, #0 -+ | mvn CARG2, #~LJ_KEYINDEX -+ | strd CARG1, CARG2, [RA, #-8] // Initialize control var. -+ |1: -+ | ins_next3 -+ |5: // Despecialize bytecode if any of the checks fail. -+ | mov CARG1, #BC_JMP -+ | mov OP, #BC_ITERC -+ | strb CARG1, [PC, #-4] -+ | sub PC, RC, #0x20000 -+ |.if JIT -+ | ldrb CARG1, [PC] -+ | cmp CARG1, #BC_ITERN -+ | bne >6 -+ |.endif -+ | strb OP, [PC] // Subsumes ins_next1. -+ | ins_next2 -+ | b <1 -+ |.if JIT -+ |6: // Unpatch JLOOP. -+ | sub CARG2, DISPATCH, #-DISPATCH_J(trace) -+ | ldr CARG1, [CARG2] -+ | ldrh CARG2, [PC, #2] -+ | ldr TRACE:CARG1, [CARG1, CARG2, lsl #2] -+ | // Subsumes ins_next1 and ins_next2. -+ | ldr INS, TRACE:CARG1->startins -+ | .long 0xf36c0e07 //BFI INS, OP, #0, #8 -+ | str INS, [PC], #4 -+ | b <1 -+ |.endif -+ break; -+ -+ case BC_VARG: -+ | decode_RB8 RB, INS -+ | decode_RC8 RC, INS -+ | // RA = base*8, RB = (nresults+1)*8, RC = numparams*8 -+ | ldr CARG1, [BASE, FRAME_PC] -+ | add RC, BASE, RC -+ | add RA, BASE, RA -+ | add RC, RC, #FRAME_VARG -+ | add CARG4, RA, RB -+ | sub CARG3, BASE, #8 // CARG3 = vtop -+ | sub RC, RC, CARG1 // RC = vbase -+ | // Note: RC may now be even _above_ BASE if nargs was < numparams. -+ | cmp RB, #0 -+ | sub CARG1, CARG3, RC -+ | beq >5 // Copy all varargs? -+ | sub CARG4, CARG4, #16 -+ |1: // Copy vararg slots to destination slots. -+ | cmp RC, CARG3 -+ | ite lo -+ | ldrdlo CARG1, CARG2, [RC], #8 -+ | mvnhs CARG2, #~LJ_TNIL -+ | cmp RA, CARG4 -+ | strd CARG1, CARG2, [RA], #8 -+ | blo <1 -+ |2: -+ | ins_next -+ | -+ |5: // Copy all varargs. -+ | ldr CARG4, L->maxstack -+ | cmp CARG1, #0 -+ | ite le -+ | movle RB, #8 // MULTRES = (0+1)*8 -+ | addgt RB, CARG1, #8 -+ | add CARG2, RA, CARG1 -+ | str RB, SAVE_MULTRES -+ | ble <2 -+ | cmp CARG2, CARG4 -+ | bhi >7 -+ |6: -+ | ldrd CARG1, CARG2, [RC], #8 -+ | strd CARG1, CARG2, [RA], #8 -+ | cmp RC, CARG3 -+ | blo <6 -+ | b <2 -+ | -+ |7: // Grow stack for varargs. -+ | lsr CARG2, CARG1, #3 -+ | str RA, L->top -+ | mov CARG1, L -+ | str BASE, L->base -+ | sub RC, RC, BASE // Need delta, because BASE may change. -+ | str PC, SAVE_PC -+ | sub RA, RA, BASE -+ | bl extern lj_state_growstack // (lua_State *L, int n) -+ | ldr BASE, L->base -+ | add RA, BASE, RA -+ | add RC, BASE, RC -+ | sub CARG3, BASE, #8 -+ | b <6 -+ break; -+ -+ /* -- Returns ----------------------------------------------------------- */ -+ -+ case BC_RETM: -+ | // RA = results*8, RC = extra results -+ | ldr CARG1, SAVE_MULTRES -+ | ldr PC, [BASE, FRAME_PC] -+ | add RA, BASE, RA -+ | add RC, CARG1, RC, lsl #3 -+ | b ->BC_RETM_Z -+ break; -+ -+ case BC_RET: -+ | // RA = results*8, RC = nresults+1 -+ | ldr PC, [BASE, FRAME_PC] -+ | lsl RC, RC, #3 -+ | add RA, BASE, RA -+ |->BC_RETM_Z: -+ | str RC, SAVE_MULTRES -+ |1: -+ | ands CARG1, PC, #FRAME_TYPE -+ | eor CARG2, PC, #FRAME_VARG -+ | bne ->BC_RETV2_Z -+ | -+ |->BC_RET_Z: -+ | // BASE = base, RA = resultptr, RC = (nresults+1)*8, PC = return -+ | ldr INS, [PC, #-4] -+ | subs CARG4, RC, #8 -+ | sub CARG3, BASE, #8 -+ | beq >3 -+ |2: -+ | ldrd CARG1, CARG2, [RA], #8 -+ | add BASE, BASE, #8 -+ | subs CARG4, CARG4, #8 -+ | strd CARG1, CARG2, [BASE, #-16] -+ | bne <2 -+ |3: -+ | decode_RA8 RA, INS -+ | sub CARG4, CARG3, RA -+ | decode_RB8 RB, INS -+ | ldr LFUNC:CARG1, [CARG4, FRAME_FUNC] -+ |5: -+ | cmp RB, RC // More results expected? -+ | bhi >6 -+ | mov BASE, CARG4 -+ | ldr CARG2, LFUNC:CARG1->field_pc -+ | ins_next1 -+ | ins_next2 -+ | ldr KBASE, [CARG2, #PC2PROTO(k)] -+ | ins_next3 -+ | -+ |6: // Fill up results with nil. -+ | mvn CARG2, #~LJ_TNIL -+ | add BASE, BASE, #8 -+ | add RC, RC, #8 -+ | str CARG2, [BASE, #-12] -+ | b <5 -+ | -+ |->BC_RETV1_Z: // Non-standard return case. -+ | add RA, BASE, RA -+ |->BC_RETV2_Z: -+ | tst CARG2, #FRAME_TYPEP -+ | bne ->vm_return -+ | // Return from vararg function: relocate BASE down. -+ | sub BASE, BASE, CARG2 -+ | ldr PC, [BASE, FRAME_PC] -+ | b <1 -+ break; -+ -+ case BC_RET0: case BC_RET1: -+ | // RA = results*8, RC = nresults+1 -+ | ldr PC, [BASE, FRAME_PC] -+ | lsl RC, RC, #3 -+ | str RC, SAVE_MULTRES -+ | ands CARG1, PC, #FRAME_TYPE -+ | eor CARG2, PC, #FRAME_VARG -+ | it eq -+ | ldreq INS, [PC, #-4] -+ | bne ->BC_RETV1_Z -+ if (op == BC_RET1) { -+ | ldrd_i CARG1, CARG2, BASE, RA -+ } -+ | sub CARG4, BASE, #8 -+ | decode_RA8 RA, INS -+ if (op == BC_RET1) { -+ | strd CARG1, CARG2, [CARG4] -+ } -+ | sub BASE, CARG4, RA -+ | decode_RB8 RB, INS -+ | ldr LFUNC:CARG1, [BASE, FRAME_FUNC] -+ |5: -+ | cmp RB, RC -+ | bhi >6 -+ | ldr CARG2, LFUNC:CARG1->field_pc -+ | ins_next1 -+ | ins_next2 -+ | ldr KBASE, [CARG2, #PC2PROTO(k)] -+ | ins_next3 -+ | -+ |6: // Fill up results with nil. -+ | sub CARG2, CARG4, #4 -+ | mvn CARG3, #~LJ_TNIL -+ | str CARG3, [CARG2, RC] -+ | add RC, RC, #8 -+ | b <5 -+ break; -+ -+ /* -- Loops and branches ------------------------------------------------ */ -+ -+ |.define FOR_IDX, [RA]; .define FOR_TIDX, [RA, #4] -+ |.define FOR_STOP, [RA, #8]; .define FOR_TSTOP, [RA, #12] -+ |.define FOR_STEP, [RA, #16]; .define FOR_TSTEP, [RA, #20] -+ |.define FOR_EXT, [RA, #24]; .define FOR_TEXT, [RA, #28] -+ -+ case BC_FORL: -+ |.if JIT -+ | hotloop -+ |.endif -+ | // Fall through. Assumes BC_IFORL follows. -+ break; -+ -+ case BC_JFORI: -+ case BC_JFORL: -+#if !LJ_HASJIT -+ break; -+#endif -+ case BC_FORI: -+ case BC_IFORL: -+ | // RA = base*8, RC = target (after end of loop or start of loop) -+ vk = (op == BC_IFORL || op == BC_JFORL); -+ | ldrd_iw CARG1, CARG2, RA, BASE -+ if (op != BC_JFORL) { -+ | add RC, PC, RC, lsl #2 -+ } -+ if (!vk) { -+ | ldrd CARG3, CARG4, FOR_STOP -+ | checktp CARG2, LJ_TISNUM -+ | ldr RB, FOR_TSTEP -+ | bne >5 -+ | checktp CARG4, LJ_TISNUM -+ | ldr CARG4, FOR_STEP -+ | checktpeq RB, LJ_TISNUM -+ | bne ->vmeta_for -+ | cmp CARG4, #0 -+ | blt >4 -+ | cmp CARG1, CARG3 -+ } else { -+ | ldrd CARG3, CARG4, FOR_STEP -+ | checktp CARG2, LJ_TISNUM -+ | bne >5 -+ | adds CARG1, CARG1, CARG3 -+ | ldr CARG4, FOR_STOP -+ if (op == BC_IFORL) { -+ | it vs -+ | addvs RC, PC, #0x20000 // Overflow: prevent branch. -+ } else { -+ | bvs >2 // Overflow: do not enter mcode. -+ } -+ | cmp CARG3, #0 -+ | blt >4 -+ | cmp CARG1, CARG4 -+ } -+ |1: -+ if (op == BC_FORI) { -+ | it gt -+ | subgt PC, RC, #0x20000 -+ } else if (op == BC_JFORI) { -+ | sub PC, RC, #0x20000 -+ | it le -+ | ldrhle RC, [PC, #-2] -+ } else if (op == BC_IFORL) { -+ | it le -+ | suble PC, RC, #0x20000 -+ } -+ if (vk) { -+ | strd CARG1, CARG2, FOR_IDX -+ } -+ |2: -+ | ins_next1 -+ | ins_next2 -+ | strd CARG1, CARG2, FOR_EXT -+ if (op == BC_JFORI || op == BC_JFORL) { -+ | ble =>BC_JLOOP -+ } -+ |3: -+ | ins_next3 -+ | -+ |4: // Invert check for negative step. -+ if (!vk) { -+ | cmp CARG3, CARG1 -+ } else { -+ | cmp CARG4, CARG1 -+ } -+ | b <1 -+ | -+ |5: // FP loop. -+ if (!vk) { -+ | itt lo -+ | cmnlo CARG4, #-LJ_TISNUM -+ | cmnlo RB, #-LJ_TISNUM -+ | bhs ->vmeta_for -+ |.if FPU -+ | vldr d0, FOR_IDX -+ | vldr d1, FOR_STOP -+ | cmp RB, #0 -+ | vstr d0, FOR_EXT -+ |.else -+ | cmp RB, #0 -+ | strd CARG1, CARG2, FOR_EXT -+ | blt >8 -+ |.endif -+ } else { -+ |.if FPU -+ | vldr d0, FOR_IDX -+ | vldr d2, FOR_STEP -+ | vldr d1, FOR_STOP -+ | cmp CARG4, #0 -+ | vadd.f64 d0, d0, d2 -+ |.else -+ | cmp CARG4, #0 -+ | blt >8 -+ | bl extern __aeabi_dadd -+ | strd CARG1, CARG2, FOR_IDX -+ | ldrd CARG3, CARG4, FOR_STOP -+ | strd CARG1, CARG2, FOR_EXT -+ |.endif -+ } -+ |6: -+ |.if FPU -+ | ite ge -+ | vcmpge.f64 d0, d1 -+ | vcmplt.f64 d1, d0 -+ | vmrs -+ |.else -+ | bl extern __aeabi_cdcmple -+ |.endif -+ if (vk) { -+ |.if FPU -+ | vstr d0, FOR_IDX -+ | vstr d0, FOR_EXT -+ |.endif -+ } -+ if (op == BC_FORI) { -+ | it hi -+ | subhi PC, RC, #0x20000 -+ } else if (op == BC_JFORI) { -+ | sub PC, RC, #0x20000 -+ | it ls -+ | ldrhls RC, [PC, #-2] -+ | bls =>BC_JLOOP -+ } else if (op == BC_IFORL) { -+ | it ls -+ | subls PC, RC, #0x20000 -+ } else { -+ | bls =>BC_JLOOP -+ } -+ | ins_next1 -+ | ins_next2 -+ | b <3 -+ | -+ |.if not FPU -+ |8: // Invert check for negative step. -+ if (vk) { -+ | bl extern __aeabi_dadd -+ | strd CARG1, CARG2, FOR_IDX -+ | strd CARG1, CARG2, FOR_EXT -+ } -+ | mov CARG3, CARG1 -+ | mov CARG4, CARG2 -+ | ldrd CARG1, CARG2, FOR_STOP -+ | b <6 -+ |.endif -+ break; -+ -+ case BC_ITERL: -+ |.if JIT -+ | hotloop -+ |.endif -+ | // Fall through. Assumes BC_IITERL follows. -+ break; -+ -+ case BC_JITERL: -+#if !LJ_HASJIT -+ break; -+#endif -+ case BC_IITERL: -+ | // RA = base*8, RC = target -+ | ldrd_iw CARG1, CARG2, RA, BASE -+ if (op == BC_JITERL) { -+ | cmn CARG2, #-LJ_TNIL // Stop if iterator returned nil. -+ | it ne -+ | strdne CARG1, CARG2, [RA, #-8] -+ | bne =>BC_JLOOP -+ } else { -+ | add RC, PC, RC, lsl #2 -+ | // STALL: load CARG1, CARG2. -+ | cmn CARG2, #-LJ_TNIL // Stop if iterator returned nil. -+ | itt ne -+ | subne PC, RC, #0x20000 // Otherwise save control var + branch. -+ | strdne CARG1, CARG2, [RA, #-8] -+ } -+ | ins_next -+ break; -+ -+ case BC_LOOP: -+ | // RA = base*8, RC = target (loop extent) -+ | // Note: RA/RC is only used by trace recorder to determine scope/extent -+ | // This opcode does NOT jump, it's only purpose is to detect a hot loop. -+ |.if JIT -+ | hotloop -+ |.endif -+ | // Fall through. Assumes BC_ILOOP follows. -+ break; -+ -+ case BC_ILOOP: -+ | // RA = base*8, RC = target (loop extent) -+ | ins_next -+ break; -+ -+ case BC_JLOOP: -+ |.if JIT -+ | // RA = base (ignored), RC = traceno -+ | sub RB, DISPATCH, #-DISPATCH_J(trace) -+ | ldr CARG1, [RB] -+ | mov CARG2, #0 // Traces on ARM don't store the trace number, so use 0. -+ | ldr TRACE:RC, [CARG1, RC, lsl #2] -+ | st_vmstate CARG2 -+ | ldr RA, TRACE:RC->mcode -+ | str BASE, [DISPATCH, #DISPATCH_GL(jit_base)] -+ | sub RB, DISPATCH, #-DISPATCH_GL(tmpbuf.L) -+ | str L, [RB] -+ | add RA, RA, #1 -+ | bx RA -+ |.endif -+ break; -+ -+ case BC_JMP: -+ | // RA = base*8 (only used by trace recorder), RC = target -+ | add RC, PC, RC, lsl #2 -+ | sub PC, RC, #0x20000 -+ | ins_next -+ break; -+ -+ /* -- Function headers -------------------------------------------------- */ -+ -+ case BC_FUNCF: -+ |.if JIT -+ | hotcall -+ |.endif -+ case BC_FUNCV: /* NYI: compiled vararg functions. */ -+ | // Fall through. Assumes BC_IFUNCF/BC_IFUNCV follow. -+ break; -+ -+ case BC_JFUNCF: -+#if !LJ_HASJIT -+ break; -+#endif -+ case BC_IFUNCF: -+ | // BASE = new base, RA = BASE+framesize*8, CARG3 = LFUNC, RC = nargs*8 -+ | ldr CARG1, L->maxstack -+ | ldrb CARG2, [PC, #-4+PC2PROTO(numparams)] -+ | ldr KBASE, [PC, #-4+PC2PROTO(k)] -+ | cmp RA, CARG1 -+ | bhi ->vm_growstack_l -+ if (op != BC_JFUNCF) { -+ | ins_next1 -+ | ins_next2 -+ } -+ |2: -+ | cmp NARGS8:RC, CARG2, lsl #3 // Check for missing parameters. -+ | mvn CARG4, #~LJ_TNIL -+ | blo >3 -+ if (op == BC_JFUNCF) { -+ | decode_RD RC, INS -+ | b =>BC_JLOOP -+ } else { -+ | ins_next3 -+ } -+ | -+ |3: // Clear missing parameters. -+ | strd_i CARG3, CARG4, BASE, NARGS8:RC -+ | add NARGS8:RC, NARGS8:RC, #8 -+ | b <2 -+ break; -+ -+ case BC_JFUNCV: -+#if !LJ_HASJIT -+ break; -+#endif -+ | NYI // NYI: compiled vararg functions -+ break; /* NYI: compiled vararg functions. */ -+ -+ case BC_IFUNCV: -+ | // BASE = new base, RA = BASE+framesize*8, CARG3 = LFUNC, RC = nargs*8 -+ | ldr CARG1, L->maxstack -+ | add CARG4, BASE, RC -+ | add RA, RA, RC -+ | str LFUNC:CARG3, [CARG4] // Store copy of LFUNC. -+ | add CARG2, RC, #8+FRAME_VARG -+ | ldr KBASE, [PC, #-4+PC2PROTO(k)] -+ | cmp RA, CARG1 -+ | str CARG2, [CARG4, #4] // Store delta + FRAME_VARG. -+ | bhs ->vm_growstack_l -+ | ldrb RB, [PC, #-4+PC2PROTO(numparams)] -+ | mov RA, BASE -+ | mov RC, CARG4 -+ | cmp RB, #0 -+ | add BASE, CARG4, #8 -+ | beq >3 -+ | mvn CARG3, #~LJ_TNIL -+ |1: -+ | cmp RA, RC // Less args than parameters? -+ | ite lo -+ | ldrdlo CARG1, CARG2, [RA], #8 -+ | movhs CARG2, CARG3 -+ | it lo -+ | strlo CARG3, [RA, #-4] // Clear old fixarg slot (help the GC). -+ |2: -+ | subs RB, RB, #1 -+ | strd CARG1, CARG2, [CARG4, #8]! -+ | bne <1 -+ |3: -+ | ins_next -+ break; -+ -+ case BC_FUNCC: -+ case BC_FUNCCW: -+ | // BASE = new base, RA = BASE+framesize*8, CARG3 = CFUNC, RC = nargs*8 -+ if (op == BC_FUNCC) { -+ | ldr CARG4, CFUNC:CARG3->f -+ } else { -+ | ldr CARG4, [DISPATCH, #DISPATCH_GL(wrapf)] -+ } -+ | add CARG2, RA, NARGS8:RC -+ | ldr CARG1, L->maxstack -+ | add RC, BASE, NARGS8:RC -+ | str BASE, L->base -+ | cmp CARG2, CARG1 -+ | str RC, L->top -+ if (op == BC_FUNCCW) { -+ | ldr CARG2, CFUNC:CARG3->f -+ } -+ | mv_vmstate CARG3, C -+ | mov CARG1, L -+ | bhi ->vm_growstack_c // Need to grow stack. -+ | st_vmstate CARG3 -+ | blx CARG4 // (lua_State *L [, lua_CFunction f]) -+ | // Returns nresults. -+ | ldr BASE, L->base -+ | mv_vmstate CARG3, INTERP -+ | ldr CRET2, L->top -+ | str L, [DISPATCH, #DISPATCH_GL(cur_L)] -+ | lsl RC, CRET1, #3 -+ | st_vmstate CARG3 -+ | ldr PC, [BASE, FRAME_PC] -+ | sub RA, CRET2, RC // RA = L->top - nresults*8 -+ | b ->vm_returnc -+ break; -+ -+ /* ---------------------------------------------------------------------- */ -+ -+ default: -+ fprintf(stderr, "Error: undefined opcode BC_%s\n", bc_names[op]); -+ exit(2); -+ break; -+ } -+} -+ -+static int build_backend(BuildCtx *ctx) -+{ -+ int op; -+ -+ dasm_growpc(Dst, BC__MAX); -+ -+ build_subroutines(ctx); -+ -+ |.code_op -+ for (op = 0; op < BC__MAX; op++) -+ build_ins(ctx, (BCOp)op, op); -+ -+ return BC__MAX; -+} -+ -+/* Emit pseudo frame-info for all assembler functions. */ -+static void emit_asm_debug(BuildCtx *ctx) -+{ -+ int fcofs = (int)((uint8_t *)ctx->glob[GLOB_vm_ffi_call] - ctx->code); -+ int i; -+ switch (ctx->mode) { -+ case BUILD_elfasm: -+ fprintf(ctx->fp, "\t.section .debug_frame,\"\",%%progbits\n"); -+ fprintf(ctx->fp, -+ ".Lframe0:\n" -+ "\t.long .LECIE0-.LSCIE0\n" -+ ".LSCIE0:\n" -+ "\t.long 0xffffffff\n" -+ "\t.byte 0x1\n" -+ "\t.string \"\"\n" -+ "\t.uleb128 0x1\n" -+ "\t.sleb128 -4\n" -+ "\t.byte 0xe\n" /* Return address is in lr. */ -+ "\t.byte 0xc\n\t.uleb128 0xd\n\t.uleb128 0\n" /* def_cfa sp */ -+ "\t.align 2\n" -+ ".LECIE0:\n\n"); -+ fprintf(ctx->fp, -+ ".LSFDE0:\n" -+ "\t.long .LEFDE0-.LASFDE0\n" -+ ".LASFDE0:\n" -+ "\t.long .Lframe0\n" -+ "\t.long .Lbegin\n" -+ "\t.long %d\n" -+ "\t.byte 0xe\n\t.uleb128 %d\n" /* def_cfa_offset */ -+ "\t.byte 0x8e\n\t.uleb128 1\n", /* offset lr */ -+ fcofs, CFRAME_SIZE); -+ for (i = 11; i >= (LJ_ARCH_HASFPU ? 5 : 4); i--) /* offset r4-r11 */ -+ fprintf(ctx->fp, "\t.byte %d\n\t.uleb128 %d\n", 0x80+i, 2+(11-i)); -+#if LJ_ARCH_HASFPU -+ for (i = 15; i >= 8; i--) /* offset d8-d15 */ -+ fprintf(ctx->fp, "\t.byte 5\n\t.uleb128 %d, %d\n", -+ 64+2*i, 10+2*(15-i)); -+ fprintf(ctx->fp, "\t.byte 0x84\n\t.uleb128 %d\n", 25); /* offset r4 */ -+#endif -+ fprintf(ctx->fp, -+ "\t.align 2\n" -+ ".LEFDE0:\n\n"); -+#if LJ_HASFFI -+ fprintf(ctx->fp, -+ ".LSFDE1:\n" -+ "\t.long .LEFDE1-.LASFDE1\n" -+ ".LASFDE1:\n" -+ "\t.long .Lframe0\n" -+ "\t.long lj_vm_ffi_call\n" -+ "\t.long %d\n" -+ "\t.byte 0xe\n\t.uleb128 16\n" /* def_cfa_offset */ -+ "\t.byte 0x8e\n\t.uleb128 1\n" /* offset lr */ -+ "\t.byte 0x8b\n\t.uleb128 2\n" /* offset r11 */ -+ "\t.byte 0x85\n\t.uleb128 3\n" /* offset r5 */ -+ "\t.byte 0x84\n\t.uleb128 4\n" /* offset r4 */ -+ "\t.byte 0xd\n\t.uleb128 0xb\n" /* def_cfa_register r11 */ -+ "\t.align 2\n" -+ ".LEFDE1:\n\n", (int)ctx->codesz - fcofs); -+#endif -+ break; -+ default: -+ break; -+ } -+} -+ diff --git a/interpreters/luajit/Kconfig b/interpreters/luajit/Kconfig deleted file mode 100644 index bfe8215e9..000000000 --- a/interpreters/luajit/Kconfig +++ /dev/null @@ -1,48 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config INTERPRETERS_LUAJIT - tristate "LuaJIT" - default n - -if INTERPRETERS_LUAJIT - -config LUAJIT_VERSION - string "LuaJIT version" - default "03080b795aa3496ed62d4a0697c9f4767e7ca7e5" - -config LUAJIT_PRIORITY - int "LuaJIT REPL priority" - default 100 - -config LUAJIT_STACKSIZE - int "LuaJIT REPL stack size" - default 16384 - -config LUAJIT_ALLOC_SECTION_NAME - string "Section name for Alloc heap" - default ".luajitalloc" - ---help--- - Allocation heap address for Lua objects. - -config LUAJIT_ALLOC_SIZE - hex "Alloc heap size" - default 0x80000 - ---help--- - Allocation heap size for Lua objects. - -config LUAJIT_MCODE_SECTION_NAME - string "Section name for MCode heap" - default ".luajitmcode" - ---help--- - Allocation heap address for JIT MCode traces. - -config LUAJIT_MCODE_SIZE - hex "MCode heap size" - default 0x1e000 - ---help--- - Allocation heap size for JIT MCode traces. - -endif diff --git a/interpreters/luajit/Make.defs b/interpreters/luajit/Make.defs deleted file mode 100644 index c9957001c..000000000 --- a/interpreters/luajit/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/interpreters/luajit/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_INTERPRETERS_LUAJIT),) -CONFIGURED_APPS += $(APPDIR)/interpreters/luajit -endif diff --git a/interpreters/luajit/Makefile b/interpreters/luajit/Makefile deleted file mode 100644 index 1d7f2dfb4..000000000 --- a/interpreters/luajit/Makefile +++ /dev/null @@ -1,274 +0,0 @@ -############################################################################ -# apps/interpreters/luajit/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -LUAJIT_PATCHS ?= $(sort $(wildcard 000*.patch)) - -LUAJIT_VERSION := $(patsubst "%",%,$(CONFIG_LUAJIT_VERSION)) -LUAJIT_UNPACK = LuaJIT -LUAJIT_TARBALL = $(LUAJIT_VERSION).tar.gz -LUAJIT_URL_BASE = https://github.com/LuaJIT/LuaJIT/archive -LUAJIT_URL = $(LUAJIT_URL_BASE)/$(LUAJIT_TARBALL) - -MAINSRC = luajit.c - -CSRCS += lib_aux.c -CSRCS += lib_base.c -CSRCS += lib_bit.c -CSRCS += lib_buffer.c -CSRCS += lib_debug.c -CSRCS += lib_ffi.c -CSRCS += lib_init.c -CSRCS += lib_io.c -CSRCS += lib_jit.c -CSRCS += lib_math.c -CSRCS += lib_os.c -CSRCS += lib_package.c -CSRCS += lib_string.c -CSRCS += lib_table.c -CSRCS += lj_alloc.c -CSRCS += lj_api.c -CSRCS += lj_asm.c -CSRCS += lj_assert.c -CSRCS += lj_bc.c -CSRCS += lj_bcread.c -CSRCS += lj_bcwrite.c -CSRCS += lj_buf.c -CSRCS += lj_carith.c -CSRCS += lj_ccall.c -CSRCS += lj_ccallback.c -CSRCS += lj_cconv.c -CSRCS += lj_cdata.c -CSRCS += lj_char.c -CSRCS += lj_clib.c -CSRCS += lj_cparse.c -CSRCS += lj_crecord.c -CSRCS += lj_ctype.c -CSRCS += lj_debug.c -CSRCS += lj_dispatch.c -CSRCS += lj_err.c -CSRCS += lj_ffrecord.c -CSRCS += lj_func.c -CSRCS += lj_gc.c -CSRCS += lj_gdbjit.c -CSRCS += lj_ir.c -CSRCS += lj_lex.c -CSRCS += lj_lib.c -CSRCS += lj_load.c -CSRCS += lj_mcode.c -CSRCS += lj_meta.c -CSRCS += lj_obj.c -CSRCS += lj_opt_dce.c -CSRCS += lj_opt_fold.c -CSRCS += lj_opt_loop.c -CSRCS += lj_opt_mem.c -CSRCS += lj_opt_narrow.c -CSRCS += lj_opt_sink.c -CSRCS += lj_opt_split.c -CSRCS += lj_parse.c -CSRCS += lj_prng.c -CSRCS += lj_profile.c -CSRCS += lj_record.c -CSRCS += lj_serialize.c -CSRCS += lj_snap.c -CSRCS += lj_state.c -CSRCS += lj_str.c -CSRCS += lj_strfmt.c -CSRCS += lj_strfmt_num.c -CSRCS += lj_strscan.c -CSRCS += lj_tab.c -CSRCS += lj_trace.c -CSRCS += lj_udata.c -CSRCS += lj_vmevent.c -CSRCS += lj_vmmath.c - -ASRCS += lj_vm.S - -VPATH += $(LUAJIT_UNPACK)/dynasm -VPATH += $(LUAJIT_UNPACK)/src -VPATH += $(LUAJIT_UNPACK)/src/host - -CFLAGS += -fomit-frame-pointer -CFLAGS += -fno-short-enums -CFLAGS += -D__ARM_ARCH_7M__ -CFLAGS += -DLUAJIT_DISABLE_PROFILE -CFLAGS += -DLUAJIT_NO_UNWIND -CFLAGS += -DLUAJIT_OS=LUAJIT_OS_NUTTX -CFLAGS += -DLUAJIT_SECURITY_MCODE=0 -CFLAGS += -DLUAJIT_SECURITY_PRNG=0 -CFLAGS += -DLUA_ROOT=CONFIG_LIBC_HOMEDIR - -PROGNAME = luajit -PRIORITY = $(CONFIG_LUAJIT_PRIORITY) -STACKSIZE = $(CONFIG_LUAJIT_STACKSIZE) -MODULE = $(CONFIG_INTERPRETERS_LUAJIT) - -$(LUAJIT_TARBALL): - $(call DOWNLOAD,$(LUAJIT_URL_BASE),$(LUAJIT_TARBALL),$(LUAJIT_TARBALL)) - -$(LUAJIT_UNPACK): $(LUAJIT_TARBALL) - $(ECHO_BEGIN) "Unpacking $(LUAJIT_TARBALL) to $(LUAJIT_UNPACK)" - $(Q) tar xzvf $(LUAJIT_TARBALL) - $(Q) mv LuaJIT-$(LUAJIT_VERSION) $(LUAJIT_UNPACK) - $(Q) cat $(LUAJIT_PATCHS) | \ - patch -s -N -d $(LUAJIT_UNPACK) -p1 - $(ECHO_END) - -$(LUAJIT_UNPACK)/.patch: $(LUAJIT_UNPACK) - $(Q) touch $(LUAJIT_UNPACK)/.patch - -DASM_ARCH = armv7m - -DASM_DASC = $(LUAJIT_UNPACK)/src/vm_armv7m.dasc - -DASM_FLAGS += -D ENDIAN_LE -DASM_FLAGS += -D JIT -DASM_FLAGS += -D FFI -DASM_FLAGS += -D DUALNUM -DASM_FLAGS += -D FPU -DASM_FLAGS += -D HFABI -DASM_FLAGS += -D NO_UNWIND -DASM_FLAGS += -D VER=70 - -MINILUA_O = $(LUAJIT_UNPACK)/src/host/minilua.o - -BUILDVM_O = $(LUAJIT_UNPACK)/src/host/buildvm.o \ - $(LUAJIT_UNPACK)/src/host/buildvm_asm.o \ - $(LUAJIT_UNPACK)/src/host/buildvm_fold.o \ - $(LUAJIT_UNPACK)/src/host/buildvm_lib.o \ - $(LUAJIT_UNPACK)/src/host/buildvm_peobj.o - -HOSTCFLAGS += -D__ARM_ARCH_7M__=1 -HOSTCFLAGS += -DLJ_ABI_SOFTFP=0 -HOSTCFLAGS += -DLJ_ARCH_HASFPU=1 -HOSTCFLAGS += -DLUAJIT_DISABLE_PROFILE -HOSTCFLAGS += -DLUAJIT_NO_UNWIND -HOSTCFLAGS += -DLUAJIT_TARGET=LUAJIT_ARCH_ARM -HOSTCFLAGS += -I$(LUAJIT_UNPACK)/src -HOSTCFLAGS += -I$(LUAJIT_UNPACK)/src/host - -HOSTLDFLAGS += -lm - -BUILDVM_BIN = $(LUAJIT_UNPACK)/src/host/buildvm - -MINILUA_BIN = $(LUAJIT_UNPACK)/src/host/minilua - -LJVM_S = $(LUAJIT_UNPACK)/src/lj_vm.S - -LIB_VMDEF = $(LUAJIT_UNPACK)/src/jit/vmdef.lua - -LIB_VMDEFP = $(LIB_VMDEF) - -ALL_T = $(MINILUA_BIN) - -ALL_HDRGEN = $(LUAJIT_UNPACK)/src/lj_bcdef.h -ALL_HDRGEN += $(LUAJIT_UNPACK)/src/lj_ffdef.h -ALL_HDRGEN += $(LUAJIT_UNPACK)/src/lj_folddef.h -ALL_HDRGEN += $(LUAJIT_UNPACK)/src/lj_libdef.h -ALL_HDRGEN += $(LUAJIT_UNPACK)/src/lj_recdef.h - -ALL_GEN = $(LJVM_S) $(ALL_HDRGEN) $(LIB_VMDEFP) - -HOST_OBJS = $(MINILUA_O) $(BUILDVM_O) - -LJLIB_O = $(LUAJIT_UNPACK)/src/lib_base.o -LJLIB_O += $(LUAJIT_UNPACK)/src/lib_bit.o -LJLIB_O += $(LUAJIT_UNPACK)/src/lib_buffer.o -LJLIB_O += $(LUAJIT_UNPACK)/src/lib_debug.o -LJLIB_O += $(LUAJIT_UNPACK)/src/lib_ffi.o -LJLIB_O += $(LUAJIT_UNPACK)/src/lib_io.o -LJLIB_O += $(LUAJIT_UNPACK)/src/lib_jit.o -LJLIB_O += $(LUAJIT_UNPACK)/src/lib_math.o -LJLIB_O += $(LUAJIT_UNPACK)/src/lib_os.o -LJLIB_O += $(LUAJIT_UNPACK)/src/lib_package.o -LJLIB_O += $(LUAJIT_UNPACK)/src/lib_string.o -LJLIB_O += $(LUAJIT_UNPACK)/src/lib_table.o - -LJLIB_C = $(LJLIB_O:.o=.c) - -.NOTPARALLEL: - -$(MINILUA_BIN): $(MINILUA_O) - $(ECHO_BEGIN) "HOSTLINK $@" - $(Q) $(HOSTCC) -m32 -o $@ $(MINILUA_O) $(HOSTLDFLAGS) - $(ECHO_END) - -$(LUAJIT_UNPACK)/src/host/buildvm_arch.h: $(DASM_DASC) $(MINILUA_BIN) $(LUAJIT_UNPACK)/src/lj_arch.h $(LUAJIT_UNPACK)/src/lua.h $(LUAJIT_UNPACK)/src/luaconf.h - $(ECHO_BEGIN) "DYNASM $@" - $(Q)$(MINILUA_BIN) $(LUAJIT_UNPACK)/dynasm/dynasm.lua $(DASM_FLAGS) -o $@ $(DASM_DASC) - $(ECHO_END) - -$(BUILDVM_BIN): $(BUILDVM_O) - $(ECHO_BEGIN) "HOSTLINK $@" - $(Q)$(HOSTCC) -m32 -o $@ $(BUILDVM_O) - $(ECHO_END) - -$(LJVM_S): $(BUILDVM_BIN) - $(ECHO_BEGIN) "BUILDVM $@" - $(Q)$(BUILDVM_BIN) -m elfasm -o $@ - $(ECHO_END) - -$(LUAJIT_UNPACK)/src/lj_bcdef.h: $(BUILDVM_BIN) $(LJLIB_C) - $(ECHO_BEGIN) "BUILDVM $@" - $(Q)$(BUILDVM_BIN) -m bcdef -o $@ $(LJLIB_C) - $(ECHO_END) - -$(LUAJIT_UNPACK)/src/lj_ffdef.h: $(BUILDVM_BIN) $(LJLIB_C) - $(ECHO_BEGIN) "BUILDVM $@" - $(Q)$(BUILDVM_BIN) -m ffdef -o $@ $(LJLIB_C) - $(ECHO_END) - -$(LUAJIT_UNPACK)/src/lj_libdef.h: $(BUILDVM_BIN) $(LJLIB_C) - $(ECHO_BEGIN) "BUILDVM $@" - $(Q)$(BUILDVM_BIN) -m libdef -o $@ $(LJLIB_C) - $(ECHO_END) - -$(LUAJIT_UNPACK)/src/lj_recdef.h: $(BUILDVM_BIN) $(LJLIB_C) - $(ECHO_BEGIN) "BUILDVM $@" - $(Q)$(BUILDVM_BIN) -m recdef -o $@ $(LJLIB_C) - $(ECHO_END) - -$(LIB_VMDEF): $(BUILDVM_BIN) $(LJLIB_C) - $(ECHO_BEGIN) "BUILDVM $@" - $(Q)$(BUILDVM_BIN) -m vmdef -o $(LIB_VMDEFP) $(LJLIB_C) - $(ECHO_END) - -$(LUAJIT_UNPACK)/src/lj_folddef.h: $(BUILDVM_BIN) $(LUAJIT_UNPACK)/src/lj_opt_fold.c - $(ECHO_BEGIN) "BUILDVM $@" - $(Q)$(BUILDVM_BIN) -m folddef -o $@ $(LUAJIT_UNPACK)/src/lj_opt_fold.c - $(ECHO_END) - -$(HOST_OBJS): %.o: %.c - $(ECHO_BEGIN) "CC: $<" - $(Q) $(HOSTCC) -m32 -c $(HOSTCFLAGS) $< -o $@ - $(ECHO_END) - -ifeq ($(wildcard $(LUAJIT_UNPACK)/.git),) -context:: $(LUAJIT_UNPACK)/.patch $(LUAJIT_UNPACK)/src/host/buildvm_arch.h $(ALL_GEN) - -distclean:: - $(call DELDIR, $(LUAJIT_UNPACK)) - $(call DELFILE, $(LUAJIT_TARBALL)) -endif - -include $(APPDIR)/Application.mk diff --git a/interpreters/luamodules/.gitignore b/interpreters/luamodules/.gitignore deleted file mode 100644 index 9e1d2593e..000000000 --- a/interpreters/luamodules/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/Kconfig diff --git a/interpreters/luamodules/CMakeLists.txt b/interpreters/luamodules/CMakeLists.txt deleted file mode 100644 index 9ac42149c..000000000 --- a/interpreters/luamodules/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -# ############################################################################## -# apps/interpreters/luamodules/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -nuttx_add_subdirectory() - -nuttx_generate_kconfig(MENUDESC "LUA Modules") diff --git a/interpreters/luamodules/Make.defs b/interpreters/luamodules/Make.defs deleted file mode 100644 index 1dd614d13..000000000 --- a/interpreters/luamodules/Make.defs +++ /dev/null @@ -1,23 +0,0 @@ -############################################################################ -# apps/interpreters/luamodules/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(wildcard $(APPDIR)/interpreters/luamodules/*/Make.defs) diff --git a/interpreters/luamodules/Makefile b/interpreters/luamodules/Makefile deleted file mode 100644 index b18df0fb3..000000000 --- a/interpreters/luamodules/Makefile +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/interpreters/luamodules/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -MENUDESC = "LUA Modules" - -include $(APPDIR)/Directory.mk diff --git a/interpreters/luamodules/cjson/.gitignore b/interpreters/luamodules/cjson/.gitignore deleted file mode 100644 index 2df1be299..000000000 --- a/interpreters/luamodules/cjson/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -lua-cjson/ -*.tar.gz diff --git a/interpreters/luamodules/cjson/0001-fix-compile-warnings.patch b/interpreters/luamodules/cjson/0001-fix-compile-warnings.patch deleted file mode 100644 index fefcbdcd2..000000000 --- a/interpreters/luamodules/cjson/0001-fix-compile-warnings.patch +++ /dev/null @@ -1,55 +0,0 @@ -From 68d772a032f5cb12526ad6c7769c0b3a671fcfa9 Mon Sep 17 00:00:00 2001 -From: Xuxingliang -Date: Thu, 22 Dec 2022 11:01:01 +0800 -Subject: [PATCH] fix compile warnings - -Signed-off-by: Xuxingliang ---- - fpconv.c | 4 ++-- - fpconv.h | 4 ++-- - 2 files changed, 4 insertions(+), 4 deletions(-) - -diff --git a/fpconv.c b/fpconv.c -index 3e480ec..0ef7f18 100644 ---- a/fpconv.c -+++ b/fpconv.c -@@ -55,7 +55,7 @@ static char locale_decimal_point = '.'; - * localconv() may not be thread safe (=>crash), and nl_langinfo() is - * not supported on some platforms. Use sprintf() instead - if the - * locale does change, at least Lua CJSON won't crash. */ --static void fpconv_update_locale() -+static void fpconv_update_locale(void) - { - char buf[8]; - -@@ -202,7 +202,7 @@ int fpconv_g_fmt(char *str, double num, int precision) - return len; - } - --void fpconv_init() -+void fpconv_init(void) - { - fpconv_update_locale(); - } -diff --git a/fpconv.h b/fpconv.h -index 7b0d0ee..59e0867 100644 ---- a/fpconv.h -+++ b/fpconv.h -@@ -7,12 +7,12 @@ - # define FPCONV_G_FMT_BUFSIZE 32 - - #ifdef USE_INTERNAL_FPCONV --static inline void fpconv_init() -+static inline void fpconv_init(void) - { - /* Do nothing - not required */ - } - #else --extern void fpconv_init(); -+extern void fpconv_init(void); - #endif - - extern int fpconv_g_fmt(char*, double, int); --- -2.25.1 - diff --git a/interpreters/luamodules/cjson/0002-bugfix-Fix-implicit-declaration-warning-for-strncase.patch b/interpreters/luamodules/cjson/0002-bugfix-Fix-implicit-declaration-warning-for-strncase.patch deleted file mode 100644 index 6beef060b..000000000 --- a/interpreters/luamodules/cjson/0002-bugfix-Fix-implicit-declaration-warning-for-strncase.patch +++ /dev/null @@ -1,26 +0,0 @@ -From e6e8fbe68a95bf6fca463781dbc22e631c4b7b7a Mon Sep 17 00:00:00 2001 -From: Gustavo Henrique Nihei -Date: Wed, 8 Mar 2023 17:18:02 -0300 -Subject: [PATCH] bugfix: Fix implicit declaration warning for strncasecmp - function - -Signed-off-by: Gustavo Henrique Nihei ---- - lua_cjson.c | 1 + - 1 file changed, 1 insertion(+) - -diff --git a/lua_cjson.c b/lua_cjson.c -index 42672de..f443626 100644 ---- a/lua_cjson.c -+++ b/lua_cjson.c -@@ -39,6 +39,7 @@ - #include - #include - #include -+#include - #include - #include - #include --- -2.37.2 - diff --git a/interpreters/luamodules/cjson/Kconfig b/interpreters/luamodules/cjson/Kconfig deleted file mode 100644 index 308bac7c3..000000000 --- a/interpreters/luamodules/cjson/Kconfig +++ /dev/null @@ -1,21 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config LUA_CJSON_MODULE - bool "Lua cjson module" - default n - depends on INTERPRETERS_LUA - ---help--- - LUA cjson module - -if LUA_CJSON_MODULE - -config LUA_CJSON_VERSION - string "lua csjon version" - default "2.1.0.9" - ---help--- - Lua cjson module from luarocks. - -endif # LUA_CJSON_MODULE diff --git a/interpreters/luamodules/cjson/Make.defs b/interpreters/luamodules/cjson/Make.defs deleted file mode 100644 index 863ba0ba4..000000000 --- a/interpreters/luamodules/cjson/Make.defs +++ /dev/null @@ -1,27 +0,0 @@ -############################################################################ -# apps/interpreters/luamodules/cjson/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_LUA_CJSON_MODULE),) - -CONFIGURED_APPS += $(APPDIR)/interpreters/luamodules/cjson - -endif diff --git a/interpreters/luamodules/cjson/Makefile b/interpreters/luamodules/cjson/Makefile deleted file mode 100644 index f9986df4d..000000000 --- a/interpreters/luamodules/cjson/Makefile +++ /dev/null @@ -1,66 +0,0 @@ -############################################################################ -# apps/interpreters/luamodules/cjson/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -LUACJSON_VERSION = $(patsubst "%",%,$(strip $(CONFIG_LUA_CJSON_VERSION))) -LUACJSON_TARBALL = $(LUACJSON_VERSION).tar.gz -LUACJSON_UNPACK = lua-cjson -LUACJSON_URL_BASE = https://github.com/openresty/lua-cjson/archive/refs/tags -LUACJSON_URL = $(LUACJSON_URL_BASE)/$(LUACJSON_TARBALL) -LUACJSON_SRC = $(LUACJSON_UNPACK) - -VPATH += lua-cjson -CSRCS = lua_cjson.c strbuf.c fpconv.c - -$(LUACJSON_TARBALL): - $(Q) echo "Downloading $(LUACJSON_TARBALL) from $(LUACJSON_URL)" - $(Q) curl -O -L $(LUACJSON_URL) - -$(LUACJSON_UNPACK): $(LUACJSON_TARBALL) - $(Q) echo "Unpacking $(LUACJSON_TARBALL) to $(LUACJSON_UNPACK)" - $(Q) tar -xvzf $(LUACJSON_TARBALL) - $(Q) mv lua-cjson-$(LUACJSON_VERSION) $(LUACJSON_UNPACK) - $(Q) patch -d $(LUACJSON_UNPACK) -p1 < 0001-fix-compile-warnings.patch - $(Q) patch -d $(LUACJSON_UNPACK) -p1 < 0002-bugfix-Fix-implicit-declaration-warning-for-strncase.patch - -$(LUACJSON_UNPACK)/.patch: $(LUACJSON_UNPACK) - touch $(LUACJSON_UNPACK)/.patch - -# Download and unpack tarball if no git repo found -ifeq ($(wildcard $(LUACJSON_UNPACK)/.git),) -distclean:: - $(call DELDIR, $(LUACJSON_UNPACK)) - $(call DELFILE, $(LUACJSON_TARBALL)) - -context:: $(LUACJSON_UNPACK)/.patch -endif - -# Set LUAMODNAME and include Module.mk to add this module to the list of -# builtin modules for the Lua interpreter. LUAMODNAME should match the -# module's luaopen function. - -LUAMODNAME = cjson - -include $(APPDIR)/interpreters/lua/Module.mk - -include $(APPDIR)/Application.mk diff --git a/interpreters/luamodules/lfs/.gitignore b/interpreters/luamodules/lfs/.gitignore deleted file mode 100644 index 7369b456f..000000000 --- a/interpreters/luamodules/lfs/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -lfs/ -*.tar.gz diff --git a/interpreters/luamodules/lfs/0001-call-symlink-or-link-directly.patch b/interpreters/luamodules/lfs/0001-call-symlink-or-link-directly.patch deleted file mode 100644 index d4838f643..000000000 --- a/interpreters/luamodules/lfs/0001-call-symlink-or-link-directly.patch +++ /dev/null @@ -1,30 +0,0 @@ -From f84640912e5c3ff37a2b2b4aab011a3e6cfde6a8 Mon Sep 17 00:00:00 2001 -From: Xu Xingliang -Date: Mon, 5 Dec 2022 18:58:40 +0800 -Subject: [PATCH] call symlink or link directly. - -Signed-off-by: Xu Xingliang ---- - src/lfs.c | 6 ++---- - 1 file changed, 2 insertions(+), 4 deletions(-) - -diff --git a/src/lfs.c b/src/lfs.c -index e5e5ee4..db6ae18 100644 ---- a/src/lfs.c -+++ b/src/lfs.c -@@ -566,10 +566,8 @@ static int make_link(lua_State * L) - const char *oldpath = luaL_checkstring(L, 1); - const char *newpath = luaL_checkstring(L, 2); - #ifndef _WIN32 -- return pushresult(L, -- (lua_toboolean(L, 3) ? symlink : link) (oldpath, -- newpath), -- NULL); -+ return pushresult(L, (lua_toboolean(L, 3) ? symlink(oldpath, newpath)\ -+ : link(oldpath, newpath)), NULL); - #else - int symbolic = lua_toboolean(L, 3); - STAT_STRUCT oldpathinfo; --- -2.25.1 - diff --git a/interpreters/luamodules/lfs/Kconfig b/interpreters/luamodules/lfs/Kconfig deleted file mode 100644 index 6fb013228..000000000 --- a/interpreters/luamodules/lfs/Kconfig +++ /dev/null @@ -1,21 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config LUA_LFS_MODULE - bool "Lua file system module" - default n - depends on INTERPRETERS_LUA - ---help--- - LUA file system module - -if LUA_LFS_MODULE - -config LUA_LFS_VERSION - string "LFS version" - default "1_8_0" - ---help--- - Luv release version to fetch and build. - -endif # LUA_LFS_MODULE diff --git a/interpreters/luamodules/lfs/Make.defs b/interpreters/luamodules/lfs/Make.defs deleted file mode 100644 index 0ce0cadff..000000000 --- a/interpreters/luamodules/lfs/Make.defs +++ /dev/null @@ -1,26 +0,0 @@ -############################################################################ -# apps/interpreters/luamodules/lfs/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_LUA_LFS_MODULE),) -CONFIGURED_APPS += $(APPDIR)/interpreters/luamodules/lfs - -endif diff --git a/interpreters/luamodules/lfs/Makefile b/interpreters/luamodules/lfs/Makefile deleted file mode 100644 index f41313aac..000000000 --- a/interpreters/luamodules/lfs/Makefile +++ /dev/null @@ -1,65 +0,0 @@ -############################################################################ -# apps/interpreters/luamodules/lfs/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -LFS_VERSION = $(patsubst "%",%,$(strip $(CONFIG_LUA_LFS_VERSION))) -LFS_TARBALL = v$(LFS_VERSION).tar.gz -LFS_UNPACK = lfs -LFS_URL_BASE = https://github.com/lunarmodules/luafilesystem/archive/refs/tags -LFS_URL = $(LFS_URL_BASE)/$(LFS_TARBALL) -LFS_SRC = $(LFS_UNPACK)$(DELIM)src - -VPATH += $(LFS_SRC) -CSRCS = lfs.c - -$(LFS_TARBALL): - $(Q) echo "Downloading $(LFS_TARBALL) from $(LFS_URL)" - $(Q) curl -O -L $(LFS_URL) - -$(LFS_UNPACK): $(LFS_TARBALL) - $(Q) echo "Unpacking $(LFS_TARBALL) to $(LFS_UNPACK)" - $(Q) tar -xvzf $(LFS_TARBALL) - $(Q) mv luafilesystem-$(LFS_VERSION) $(LFS_UNPACK) - $(Q) patch -d $(LFS_UNPACK) -p1 < 0001-call-symlink-or-link-directly.patch - -$(LFS_UNPACK)/.patch: $(LFS_UNPACK) - touch $(LFS_UNPACK)/.patch - -# Download and unpack tarball if no git repo found -ifeq ($(wildcard $(LFS_UNPACK)/.git),) -distclean:: - $(call DELDIR, $(LFS_UNPACK)) - $(call DELFILE, $(LFS_TARBALL)) - -context:: $(LFS_UNPACK)/.patch -endif - -# Set LUAMODNAME and include Module.mk to add this module to the list of -# builtin modules for the Lua interpreter. LUAMODNAME should match the -# module's luaopen function. - -LUAMODNAME = lfs - -include $(APPDIR)/interpreters/lua/Module.mk - -include $(APPDIR)/Application.mk diff --git a/interpreters/luamodules/luasyslog/.gitignore b/interpreters/luamodules/luasyslog/.gitignore deleted file mode 100644 index f422926ff..000000000 --- a/interpreters/luamodules/luasyslog/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -lsyslog/ -*.tar.gz diff --git a/interpreters/luamodules/luasyslog/CMakeLists.txt b/interpreters/luamodules/luasyslog/CMakeLists.txt deleted file mode 100644 index 6f1fc2e11..000000000 --- a/interpreters/luamodules/luasyslog/CMakeLists.txt +++ /dev/null @@ -1,79 +0,0 @@ -# ############################################################################## -# apps/interpreters/luamodules/luasyslog/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_LUA_LSYSLOG_MODULE) - - # ############################################################################ - # Config and Fetch luasyslog - # ############################################################################ - - set(SRC_DIR ${CMAKE_CURRENT_LIST_DIR}/lsyslog) - - if(NOT EXISTS ${SRC_DIR}) - set(LSYSLOG_URL https://github.com/lunarmodules/luasyslog/archive/refs/tags) - FetchContent_Declare( - lsyslog_fetch - URL ${LSYSLOG_URL}/${CONFIG_LUA_LSYSLOG_VERSION}.tar.gz SOURCE_DIR - ${SRC_DIR} - DOWNLOAD_NO_PROGRESS true - TIMEOUT 30) - - FetchContent_GetProperties(lsyslog_fetch) - - if(NOT lua_fetch_POPULATED) - FetchContent_Populate(lsyslog_fetch) - endif() - endif() - - # ############################################################################ - # Flags - # ############################################################################ - set(LUA_SYSTEM_READLINE_DEF - [=[ -#define openlog(a,b,c) {(void)a; (void)c;} -#define closelog() {} -]=]) - - file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/def_lua_readline.h - "${LUA_SYSTEM_READLINE_DEF}") - list(APPEND CFLAGS - "SHELL:-include ${CMAKE_CURRENT_BINARY_DIR}/def_lua_readline.h") - - # ############################################################################ - # Sources - # ############################################################################ - - set(CSRCS ${SRC_DIR}/lsyslog.c) - - # ############################################################################ - # Include Directory - # ############################################################################ - - # ############################################################################ - # Library Configuration - # ############################################################################ - - target_sources(apps PRIVATE ${CSRCS}) - - # register lua mod - nuttx_add_luamod(MODS lsyslog) -endif() diff --git a/interpreters/luamodules/luasyslog/Kconfig b/interpreters/luamodules/luasyslog/Kconfig deleted file mode 100644 index 418ce3496..000000000 --- a/interpreters/luamodules/luasyslog/Kconfig +++ /dev/null @@ -1,21 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config LUA_LSYSLOG_MODULE - bool "Lua syslog module" - default n - depends on INTERPRETERS_LUA - ---help--- - LUA syslog module - -if LUA_LSYSLOG_MODULE - -config LUA_LSYSLOG_VERSION - string "lsyslog version" - default "2.0.1" - ---help--- - Lua lsyslog module release version to fetch and build. - -endif # LUA_LSYSLOG_MODULE diff --git a/interpreters/luamodules/luasyslog/Make.defs b/interpreters/luamodules/luasyslog/Make.defs deleted file mode 100644 index 7861da2e2..000000000 --- a/interpreters/luamodules/luasyslog/Make.defs +++ /dev/null @@ -1,26 +0,0 @@ -############################################################################ -# apps/interpreters/luamodules/luasyslog/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_LUA_LSYSLOG_MODULE),) -CONFIGURED_APPS += $(APPDIR)/interpreters/luamodules/luasyslog - -endif diff --git a/interpreters/luamodules/luasyslog/Makefile b/interpreters/luamodules/luasyslog/Makefile deleted file mode 100644 index 2421472f8..000000000 --- a/interpreters/luamodules/luasyslog/Makefile +++ /dev/null @@ -1,67 +0,0 @@ -############################################################################ -# apps/interpreters/luamodules/luasyslog/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -LSYSLOG_VERSION = $(patsubst "%",%,$(strip $(CONFIG_LUA_LSYSLOG_VERSION))) -LSYSLOG_TARBALL = $(LSYSLOG_VERSION).tar.gz -LSYSLOG_UNPACK = lsyslog -LSYSLOG_URL_BASE = https://github.com/lunarmodules/luasyslog/archive/refs/tags -LSYSLOG_URL = $(LSYSLOG_URL_BASE)/$(LSYSLOG_TARBALL) -LSYSLOG_SRC = $(LSYSLOG_UNPACK) - -VPATH += $(LSYSLOG_SRC) -CSRCS = lsyslog.c - -CFLAGS += -D'openlog(a,b,c)={(void)a; (void)c;}' -CFLAGS += -D'closelog()={}' - -$(LSYSLOG_TARBALL): - $(Q) echo "Downloading $(LSYSLOG_TARBALL) from $(LSYSLOG_URL)" - $(Q) curl -O -L $(LSYSLOG_URL) - -$(LSYSLOG_UNPACK): $(LSYSLOG_TARBALL) - $(Q) echo "Unpacking $(LSYSLOG_TARBALL) to $(LSYSLOG_UNPACK)" - $(Q) tar -xvzf $(LSYSLOG_TARBALL) - $(Q) mv luasyslog-$(LSYSLOG_VERSION) $(LSYSLOG_UNPACK) - -$(LSYSLOG_UNPACK)/.patch: $(LSYSLOG_UNPACK) - touch $(LSYSLOG_UNPACK)/.patch - -# Download and unpack tarball if no git repo found -ifeq ($(wildcard $(LSYSLOG_UNPACK)/.git),) -distclean:: - $(call DELDIR, $(LSYSLOG_UNPACK)) - $(call DELFILE, $(LSYSLOG_TARBALL)) - -context:: $(LSYSLOG_UNPACK)/.patch -endif - -# Set LUAMODNAME and include Module.mk to add this module to the list of -# builtin modules for the Lua interpreter. LUAMODNAME should match the -# module's luaopen function. - -LUAMODNAME = lsyslog - -include $(APPDIR)/interpreters/lua/Module.mk - -include $(APPDIR)/Application.mk diff --git a/interpreters/luamodules/luv/.gitignore b/interpreters/luamodules/luv/.gitignore deleted file mode 100644 index 8974fb2c0..000000000 --- a/interpreters/luamodules/luv/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -luv/ -*.tar.gz diff --git a/interpreters/luamodules/luv/0001-fix-compile-warnings.patch b/interpreters/luamodules/luv/0001-fix-compile-warnings.patch deleted file mode 100644 index e0f47b804..000000000 --- a/interpreters/luamodules/luv/0001-fix-compile-warnings.patch +++ /dev/null @@ -1,144 +0,0 @@ -From 5ead8fc3a68738c1569ec635f898f50f9476bf4a Mon Sep 17 00:00:00 2001 -From: Xu Xingliang -Date: Mon, 12 Dec 2022 11:56:58 +0800 -Subject: [PATCH] fix compile warnings - -Signed-off-by: Xu Xingliang ---- - src/fs.c | 14 +++++++------- - src/luv.h | 2 +- - src/private.h | 2 +- - src/thread.c | 4 ++-- - src/work.c | 6 +++--- - 5 files changed, 14 insertions(+), 14 deletions(-) - -diff --git a/src/fs.c b/src/fs.c -index 344d602..ea2a80a 100644 ---- a/src/fs.c -+++ b/src/fs.c -@@ -428,14 +428,14 @@ static void luv_fs_cb(uv_fs_t* req) { - // variable 'nargs' to the number of return values - #define FS_CALL_NORETURN(func, req, ...) { \ - int ret, sync; \ -- luv_req_t* data = (luv_req_t*)req->data; \ -- sync = data->callback_ref == LUA_NOREF; \ -- ret = uv_fs_##func(data->ctx->loop, req, __VA_ARGS__, \ -+ luv_req_t* lreq = (luv_req_t*)req->data; \ -+ sync = lreq->callback_ref == LUA_NOREF; \ -+ ret = uv_fs_##func(lreq->ctx->loop, req, __VA_ARGS__, \ - sync ? NULL : luv_fs_cb); \ - if (req->fs_type != UV_FS_ACCESS && ret < 0) { \ - lua_pushnil(L); \ - if (fs_req_has_dest_path(req)) { \ -- lua_rawgeti(L, LUA_REGISTRYINDEX, data->data_ref); \ -+ lua_rawgeti(L, LUA_REGISTRYINDEX, lreq->data_ref); \ - const char* dest_path = lua_tostring(L, -1); \ - lua_pop(L, 1); \ - lua_pushfstring(L, "%s: %s: %s -> %s", \ -@@ -455,7 +455,7 @@ static void luv_fs_cb(uv_fs_t* req) { - } \ - lua_pushstring(L, uv_err_name(req->result)); \ - if(req->fs_type != UV_FS_SCANDIR) { \ -- luv_cleanup_req(L, data); \ -+ luv_cleanup_req(L, lreq); \ - req->data = NULL; \ - uv_fs_req_cleanup(req); \ - } \ -@@ -464,13 +464,13 @@ static void luv_fs_cb(uv_fs_t* req) { - else if (sync) { \ - nargs = push_fs_result(L, req); \ - if(req->fs_type != UV_FS_SCANDIR) { \ -- luv_cleanup_req(L, data); \ -+ luv_cleanup_req(L, lreq); \ - req->data = NULL; \ - uv_fs_req_cleanup(req); \ - } \ - } \ - else { \ -- lua_rawgeti(L, LUA_REGISTRYINDEX, data->req_ref); \ -+ lua_rawgeti(L, LUA_REGISTRYINDEX, lreq->req_ref); \ - nargs = 1; \ - } \ - } -diff --git a/src/luv.h b/src/luv.h -index 5921e15..ad02329 100644 ---- a/src/luv.h -+++ b/src/luv.h -@@ -147,7 +147,7 @@ LUALIB_API void luv_set_cthread(lua_State* L, luv_CFcpcall cpcall); - */ - LUALIB_API int luaopen_luv (lua_State *L); - --typedef lua_State* (*luv_acquire_vm)(); -+typedef lua_State* (*luv_acquire_vm)(void); - typedef void (*luv_release_vm)(lua_State* L); - LUALIB_API void luv_set_thread_cb(luv_acquire_vm acquire, luv_release_vm release); - -diff --git a/src/private.h b/src/private.h -index 1e921a4..b4ea7fb 100644 ---- a/src/private.h -+++ b/src/private.h -@@ -111,7 +111,7 @@ static int luv_arg_type_error(lua_State* L, int index, const char* fmt); - static int luv_optboolean(lua_State*L, int idx, int defaultval); - - /* From thread.c */ --static lua_State* luv_thread_acquire_vm(); -+static lua_State* luv_thread_acquire_vm(void); - - /* From process.c */ - static int luv_parse_signal(lua_State* L, int slot); -diff --git a/src/thread.c b/src/thread.c -index 36041af..93427d4 100644 ---- a/src/thread.c -+++ b/src/thread.c -@@ -24,7 +24,7 @@ typedef struct { - luv_thread_arg_t args; - } luv_thread_t; - --static lua_State* luv_thread_acquire_vm() { -+static lua_State* luv_thread_acquire_vm(void) { - lua_State* L = luaL_newstate(); - - // Add in the lua standard libraries -@@ -262,7 +262,7 @@ static int luv_thread_gc(lua_State* L) { - static int luv_thread_tostring(lua_State* L) - { - luv_thread_t* thd = luv_check_thread(L, 1); -- lua_pushfstring(L, "uv_thread_t: %p", (void*)thd->handle); -+ lua_pushfstring(L, "uv_thread_t: %p", (void*)(uintptr_t)thd->handle); - return 1; - } - -diff --git a/src/work.c b/src/work.c -index b6b7561..52d8004 100644 ---- a/src/work.c -+++ b/src/work.c -@@ -127,7 +127,7 @@ static int luv_work_cb(lua_State* L) { - return LUA_OK; - } - --static lua_State* luv_work_acquire_vm() -+static lua_State* luv_work_acquire_vm(void) - { - lua_State* L = uv_key_get(&tls_vmkey); - if (L == NULL) -@@ -247,7 +247,7 @@ static const luaL_Reg luv_work_ctx_methods[] = { - {NULL, NULL} - }; - --static void luv_key_init_once() -+static void luv_key_init_once(void) - { - const char* val; - int status = uv_key_create(&tls_vmkey); -@@ -289,7 +289,7 @@ static void luv_key_init_once() - idx_vms = 0; - } - --static void luv_work_cleanup() -+static void luv_work_cleanup(void) - { - unsigned int i; - --- -2.25.1 - diff --git a/interpreters/luamodules/luv/Kconfig b/interpreters/luamodules/luv/Kconfig deleted file mode 100644 index 490f83adf..000000000 --- a/interpreters/luamodules/luv/Kconfig +++ /dev/null @@ -1,30 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config LUA_LUV_MODULE - bool "Lua Luv module" - default n - depends on INTERPRETERS_LUA && LIBUV - depends on LIBC_EXECFUNCS - depends on LIBC_NETDB - depends on NET - depends on NETDEV_IFINDEX - depends on NET_SOCKOPTS - depends on NET_TCP - depends on NET_UDP - depends on PSEUDOFS_SOFTLINKS - depends on SCHED_HAVE_PARENT - ---help--- - Bare libuv bindings for Lua - -if LUA_LUV_MODULE - -config LUA_LUV_VERSION - string "Luv version" - default "1.44.2-1" - ---help--- - Luv release version to fetch and build. - -endif # LUA_LUV_MODULE diff --git a/interpreters/luamodules/luv/Make.defs b/interpreters/luamodules/luv/Make.defs deleted file mode 100644 index 2f1a4ae50..000000000 --- a/interpreters/luamodules/luv/Make.defs +++ /dev/null @@ -1,26 +0,0 @@ -############################################################################ -# apps/interpreters/luamodules/luv/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_LUA_LUV_MODULE),) -CONFIGURED_APPS += $(APPDIR)/interpreters/luamodules/luv - -endif diff --git a/interpreters/luamodules/luv/Makefile b/interpreters/luamodules/luv/Makefile deleted file mode 100644 index 8f4c25357..000000000 --- a/interpreters/luamodules/luv/Makefile +++ /dev/null @@ -1,69 +0,0 @@ -############################################################################ -# apps/interpreters/luamodules/luv/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -# Luv library - -LUV_VERSION = $(patsubst "%",%,$(strip $(CONFIG_LUA_LUV_VERSION))) -LUV_TARBALL = luv-$(LUV_VERSION).tar.gz -LUV_UNPACK = luv -LUV_URL_BASE = https://github.com/luvit/luv/releases/download/ -LUV_URL = $(LUV_URL_BASE)/$(LUV_VERSION)/$(LUV_TARBALL) -LUV_SRC = $(LUV_UNPACK)$(DELIM)src - -VPATH += $(LUV_SRC) -CSRCS = luv.c - -# Luv download and unpack - -$(LUV_TARBALL): - $(Q) echo "Downloading $(LUV_TARBALL)" - $(Q) curl -O -L $(LUV_URL) - -$(LUV_UNPACK): $(LUV_TARBALL) - $(Q) echo "Unpacking $(LUV_TARBALL) to $(LUV_UNPACK)" - $(Q) tar -xvzf $(LUV_TARBALL) - $(Q) mv luv-$(LUV_VERSION) $(LUV_UNPACK) - $(Q) patch -d $(LUV_UNPACK) -p1 < 0001-fix-compile-warnings.patch - -$(LUV_UNPACK)/.patch: $(LUV_UNPACK) - touch $(LUV_UNPACK)/.patch - -# Download and unpack tarball if no git repo found -ifeq ($(wildcard $(LUV_UNPACK)/.git),) -distclean:: - $(call DELDIR, $(LUV_UNPACK)) - $(call DELFILE, $(LUV_TARBALL)) - -context:: $(LUV_UNPACK)/.patch -endif - -# Set LUAMODNAME and include Module.mk to add this module to the list of -# builtin modules for the Lua interpreter. LUAMODNAME should match the -# module's luaopen function. - -LUAMODNAME = luv - -include $(APPDIR)/interpreters/lua/Module.mk - -include $(APPDIR)/Application.mk diff --git a/interpreters/minibasic/CMakeLists.txt b/interpreters/minibasic/CMakeLists.txt deleted file mode 100644 index c13cef5b1..000000000 --- a/interpreters/minibasic/CMakeLists.txt +++ /dev/null @@ -1,34 +0,0 @@ -# ############################################################################## -# apps/interpreters/minibasic/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_INTERPRETERS_MINIBASIC) - nuttx_add_application( - NAME - basic - SRCS - script.c - basic.c - STACKSIZE - ${CONFIG_INTERPRETERS_MINIBASIC_STACKSIZE} - PRIORITY - ${CONFIG_INTERPRETERS_MINIBASIC_PRIORITY}) -endif() diff --git a/interpreters/minibasic/Kconfig b/interpreters/minibasic/Kconfig index 0d54790b5..bab275fc0 100644 --- a/interpreters/minibasic/Kconfig +++ b/interpreters/minibasic/Kconfig @@ -33,25 +33,25 @@ config INTERPRETERS_MINIBASIC if INTERPRETERS_MINIBASIC -config INTERPRETERS_MINIBASIC_PRIORITY +config INTERPRETER_MINIBASIC_PRIORITY int "Basic interpreter priority" default 100 ---help--- Task priority of the Basic interpreter main task -config INTERPRETERS_MINIBASIC_STACKSIZE +config INTERPRETER_MINIBASIC_STACKSIZE int "Basic interpreter stack size" default 4096 ---help--- Size of the stack allocated for the Basic interpreter main task -config INTERPRETERS_MINIBASIC_IOBUFSIZE +config INTERPRETER_MINIBASIC_IOBUFSIZE int "I/O buffer size" default 1024 ---help--- Size of the statically allocated I/O buffer. -config INTERPRETERS_MINIBASIC_TESTSCRIPT +config INTERPRETER_MINIBASIC_TESTSCRIPT bool "Test script" default n ---help--- diff --git a/interpreters/minibasic/Make.defs b/interpreters/minibasic/Make.defs index 518bfb561..da9cb2bfe 100644 --- a/interpreters/minibasic/Make.defs +++ b/interpreters/minibasic/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/interpreters/minibasic/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/interpreters/minibasic/Makefile b/interpreters/minibasic/Makefile index 61a439873..ced37e100 100644 --- a/interpreters/minibasic/Makefile +++ b/interpreters/minibasic/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/interpreters/minibasic/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -31,8 +29,8 @@ MAINSRC = script.c # Mini Basic built-in application info PROGNAME = basic -PRIORITY = $(CONFIG_INTERPRETERS_MINIBASIC_PRIORITY) -STACKSIZE = $(CONFIG_INTERPRETERS_MINIBASIC_STACKSIZE) +PRIORITY = $(CONFIG_INTERPRETER_MINIBASIC_PRIORITY) +STACKSIZE = $(CONFIG_INTERPRETER_MINIBASIC_STACKSIZE) MODULE = $(CONFIG_INTERPRETERS_MINIBASIC) include $(APPDIR)/Application.mk diff --git a/interpreters/minibasic/basic.c b/interpreters/minibasic/basic.c index 2547f963e..b9dabe6d5 100644 --- a/interpreters/minibasic/basic.c +++ b/interpreters/minibasic/basic.c @@ -1,31 +1,39 @@ /**************************************************************************** * apps/interpreters/minibasic/basic.c * - * SPDX-License-Identifier: Apache-2.0 + * Copyright (C) 2016 Gregory Nutt. All rights reserved. * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * - * This file was taken from Mini Basic, version 1.0 developed by Malcolm + * This file was taken from Mini Basic, versino 1.0 developed by Malcolm * McLean, Leeds University. Mini Basic version 1.0 was released the * Creative Commons Attribution license which, from my reading, appears to - * be compatible with the NuttX license: + * be compatible with the NuttX BSD-style license: + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. * ****************************************************************************/ @@ -45,14 +53,13 @@ /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ - /* Configuration */ -#ifndef CONFIG_INTERPRETERS_MINIBASIC_IOBUFSIZE -# define CONFIG_INTERPRETERS_MINIBASIC_IOBUFSIZE 1024 +#ifndef CONFIG_INTERPRETER_MINIBASIC_IOBUFSIZE +# define CONFIG_INTERPRETER_MINIBASIC_IOBUFSIZE 1024 #endif -#define IOBUFSIZE CONFIG_INTERPRETERS_MINIBASIC_IOBUFSIZE +#define IOBUFSIZE CONFIG_INTERPRETER_MINIBASIC_IOBUFSIZE /* Tokens defined */ @@ -368,19 +375,17 @@ static int setup(FAR const char *script) } for (i = 1; i < nlines; i++) - { - if (g_lines[i].no <= g_lines[i - 1].no) - { - if (g_fperr) - { - fprintf(g_fperr, "program lines %d and %d not in order\n", - g_lines[i - 1].no, g_lines[i].no); - } + if (g_lines[i].no <= g_lines[i - 1].no) + { + if (g_fperr) + { + fprintf(g_fperr, "program lines %d and %d not in order\n", + g_lines[i - 1].no, g_lines[i].no); + } - free(g_lines); - return -1; - } - } + free(g_lines); + return -1; + } g_nvariables = 0; g_variables = 0; @@ -446,6 +451,7 @@ static void cleanup(void) } else if (g_dimvariables[i].dval) { + free(g_dimvariables[i].dval); } } @@ -695,7 +701,6 @@ static int line(void) if (g_token != EOS) { /* match(VALUE); */ - /* check for a newline */ str = g_string; @@ -869,8 +874,7 @@ static void dodim(void) break; case 3: - dimvar = dimension(name, 3, (int)dims[0], - (int)dims[1], (int)dims[2]); + dimvar = dimension(name, 3, (int)dims[0], (int)dims[1], (int)dims[2]); break; case 4: @@ -990,7 +994,7 @@ static int doif(void) * Name: dogoto * * Description: - * The GOTO statement + * The GOTO satement * Returns new line number * ****************************************************************************/ @@ -1088,7 +1092,7 @@ static int dofor(void) } else { - strlcpy(g_forstack[nfors].id, id, sizeof(g_forstack[nfors].id)); + strcpy(g_forstack[nfors].id, id); g_forstack[nfors].nextline = getnextline(g_string); g_forstack[nfors].step = stepval; g_forstack[nfors].toval = toval; @@ -1173,7 +1177,7 @@ static void doinput(void) * or comma is detected. */ - for (nch = 0, ptr = g_iobuffer; nch < (IOBUFSIZE - 1); nch++) + for (nch = 0, ptr = g_iobuffer; nch < (IOBUFSIZE-1); nch++) { int ch = fgetc(g_fpin); if (ch == EOF) @@ -1252,6 +1256,7 @@ static void doinput(void) static void dorem(void) { match(REM); + return; } /**************************************************************************** @@ -1367,8 +1372,7 @@ static void lvalue(FAR struct mb_lvalue_s *lv) index[2] = integer(expr()); if (g_errorflag == 0) { - valptr = getdimvar(dimvar, index[0], - index[1], index[2]); + valptr = getdimvar(dimvar, index[0], index[1], index[2]); } } break; @@ -1384,8 +1388,8 @@ static void lvalue(FAR struct mb_lvalue_s *lv) index[3] = integer(expr()); if (g_errorflag == 0) { - valptr = getdimvar(dimvar, index[0], - index[1], index[2], index[3]); + valptr = + getdimvar(dimvar, index[0], index[1], index[2], index[3]); } } break; @@ -1403,8 +1407,8 @@ static void lvalue(FAR struct mb_lvalue_s *lv) index[4] = integer(expr()); if (g_errorflag == 0) { - valptr = getdimvar(dimvar, index[0], - index[1], index[2], index[3]); + valptr = + getdimvar(dimvar, index[0], index[1], index[2], index[3]); } } break; @@ -1526,7 +1530,6 @@ static int boolfactor(void) return 0; } - cmp = strcmp(strleft, strright); switch (op) { @@ -1957,7 +1960,6 @@ static double factor(void) { srand((unsigned)-answer); } - answer = 0; } break; @@ -2177,8 +2179,8 @@ static double dimvariable(void) index[3] = integer(expr()); match(COMMA); index[4] = integer(expr()); - answer = getdimvar(dimvar, index[0], index[1], - index[2], index[3], index[4]); + answer = + getdimvar(dimvar, index[0], index[1], index[2], index[3], index[4]); break; } @@ -2499,8 +2501,7 @@ static FAR struct mb_variable_s *addfloat(FAR const char *id) if (vars) { g_variables = vars; - strlcpy(g_variables[g_nvariables].id, id, - sizeof(g_variables[g_nvariables].id)); + strcpy(g_variables[g_nvariables].id, id); g_variables[g_nvariables].dval = 0.0; g_variables[g_nvariables].sval = NULL; g_nvariables++; @@ -2533,8 +2534,7 @@ static FAR struct mb_variable_s *addstring(FAR const char *id) if (vars) { g_variables = vars; - strlcpy(g_variables[g_nvariables].id, id, - sizeof(g_variables[g_nvariables].id)); + strcpy(g_variables[g_nvariables].id, id); g_variables[g_nvariables].sval = NULL; g_variables[g_nvariables].dval = 0.0; g_nvariables++; @@ -2562,17 +2562,16 @@ static FAR struct mb_dimvar_s *adddimvar(FAR const char *id) { FAR struct mb_dimvar_s *vars; - vars = realloc(g_dimvariables, - (g_ndimvariables + 1) * sizeof(struct mb_dimvar_s)); + vars = + realloc(g_dimvariables, (g_ndimvariables + 1) * sizeof(struct mb_dimvar_s)); if (vars) { g_dimvariables = vars; - strlcpy(g_dimvariables[g_ndimvariables].id, id, - sizeof(g_dimvariables[g_ndimvariables].id)); + strcpy(g_dimvariables[g_ndimvariables].id, id); g_dimvariables[g_ndimvariables].dval = NULL; g_dimvariables[g_ndimvariables].str = NULL; g_dimvariables[g_ndimvariables].ndims = 0; - g_dimvariables[g_ndimvariables].type = strchr(id, '$') ? STRID : FLTID; + g_dimvariables[g_ndimvariables].type = strchr(id, '$') ? STRID : FLTID; g_ndimvariables++; return &g_dimvariables[g_ndimvariables - 1]; } @@ -2738,7 +2737,7 @@ static FAR char *strstring(void) x = expr(); match(CPAREN); - snprintf(g_iobuffer, sizeof(g_iobuffer), "%g", x); + sprintf(g_iobuffer, "%g", x); answer = mystrdup(g_iobuffer); if (!answer) { @@ -2905,7 +2904,8 @@ static FAR char *midstring(void) return str; } - strlcpy(answer, temp, len + 1); + strncpy(answer, temp, len); + answer[len] = 0; free(str); return answer; } @@ -2964,7 +2964,7 @@ static FAR char *stringstring(void) for (i = 0; i < N; i++) { - strlcpy(answer + len * i, str, (N - i) * len + 1); + strcpy(answer + len * i, str); } free(str); @@ -3039,8 +3039,7 @@ static FAR char *stringdimvar(void) match(COMMA); index[4] = integer(expr()); answer = - getdimvar(dimvar, index[0], index[1], - index[2], index[3], index[4]); + getdimvar(dimvar, index[0], index[1], index[2], index[3], index[4]); break; } @@ -3190,7 +3189,7 @@ static int integer(double x) * Name: match * * Description: - * Check that we have a token of the passed type (if not set g_errorflag) + * Check that we have a token of the passed type (if not set the g_errorflag) * Move parser on to next token. Sets token and string. * ****************************************************************************/ @@ -3804,7 +3803,7 @@ static int isstring(int tokenid) * Description: * Get a numerical value from the parse string * Params: str - the string to search - * len - return pointer for no chars read + * len - return pinter for no chars read * Returns: the value of the string. * ****************************************************************************/ @@ -3945,10 +3944,7 @@ static FAR char *mystrend(FAR const char *str, char quote) while (*str != quote) { if (*str == '\n' || *str == 0) - { - return 0; - } - + return 0; str++; } @@ -4003,7 +3999,15 @@ static int mystrcount(FAR const char *str, char ch) static FAR char *mystrdup(FAR const char *str) { - return strdup(str); + FAR char *answer; + + answer = malloc(strlen(str) + 1); + if (answer) + { + strcpy(answer, str); + } + + return answer; } /**************************************************************************** @@ -4022,12 +4026,12 @@ static FAR char *mystrconcat(FAR const char *str, FAR const char *cat) int len; FAR char *answer; - len = strlen(str) + strlen(cat) + 1; - answer = malloc(len); + len = strlen(str) + strlen(cat); + answer = malloc(len + 1); if (answer) { - strlcpy(answer, str, len); - strlcat(answer, cat, len); + strcpy(answer, str); + strcat(answer, cat); } return answer; @@ -4129,7 +4133,6 @@ int basic(FAR const char *script, FILE * in, FILE * out, FILE * err) { fprintf(g_fperr, "line %d not found\n", nextline); } - answer = 1; break; } diff --git a/interpreters/minibasic/script.c b/interpreters/minibasic/script.c index 3e0212464..8d87ad0b8 100644 --- a/interpreters/minibasic/script.c +++ b/interpreters/minibasic/script.c @@ -1,32 +1,42 @@ -/**************************************************************************** - * apps/interpreters/minibasic/script.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ /**************************************************************************** + * apps/interpreters/minibasic/sript.c + * Driver file for MiniBasic. * - * This file was taken from Mini Basic, version 1.0 developed by Malcolm + * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * + * This file was taken from Mini Basic, versino 1.0 developed by Malcolm * McLean, Leeds University. Mini Basic version 1.0 was released the * Creative Commons Attribution license which, from my reading, appears to * be compatible with the NuttX BSD-style license: * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * ****************************************************************************/ /**************************************************************************** @@ -45,7 +55,7 @@ * Private Data ****************************************************************************/ -#ifdef CONFIG_INTERPRETERS_MINIBASIC_TESTSCRIPT +#ifdef CONFIG_INTERPRETER_MINIBASIC_TESTSCRIPT /* Here is a simple script to play with */ static FAR char *script = @@ -147,7 +157,7 @@ int main(int argc, FAR char *argv[]) if (argc == 1) { -#ifdef CONFIG_INTERPRETERS_MINIBASIC_TESTSCRIPT +#ifdef CONFIG_INTERPRETER_MINIBASIC_TESTSCRIPT basic(script, stdin, stdout, stderr); #else fprintf(stderr, "ERROR: Missing argument.\n"); diff --git a/interpreters/mquickjs/.gitignore b/interpreters/mquickjs/.gitignore deleted file mode 100644 index 87708e7fd..000000000 --- a/interpreters/mquickjs/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -*.d -mquickjs/ diff --git a/interpreters/mquickjs/CMakeLists.txt b/interpreters/mquickjs/CMakeLists.txt deleted file mode 100644 index 51d505860..000000000 --- a/interpreters/mquickjs/CMakeLists.txt +++ /dev/null @@ -1,123 +0,0 @@ -# ############################################################################## -# apps/interpreters/mquickjs/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_INTERPRETERS_MQJS) - set(MQJS_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/mquickjs) - - # Prefer local git repo if it exists, otherwise download tarball - if(EXISTS ${MQJS_SOURCE_DIR}/.git) - # Use local git-managed mquickjs - set(MQJS_DIR ${MQJS_SOURCE_DIR}) - message(STATUS "Using local mquickjs git repo: ${MQJS_DIR}") - else() - # Download mquickjs to build directory - FetchContent_Declare( - mquickjs_fetch - URL https://github.com/bellard/mquickjs/archive/refs/heads/main.zip - DOWNLOAD_NO_PROGRESS true - TIMEOUT 30) - - FetchContent_MakeAvailable(mquickjs_fetch) - - # The source directory after FetchContent_MakeAvailable - set(MQJS_DIR ${mquickjs_fetch_SOURCE_DIR}) - message(STATUS "Using downloaded mquickjs: ${MQJS_DIR}") - endif() - - # Detect target architecture for header generation - if(CONFIG_ARCH_64BIT) - set(MQJS_BUILD_FLAGS "-m64") - else() - set(MQJS_BUILD_FLAGS "-m32") - endif() - - include(ExternalProject) - - # Build mqjs_stdlib host tool using mquickjs Makefile - ExternalProject_Add( - mqjs_stdlib_host - SOURCE_DIR ${MQJS_DIR} - BINARY_DIR ${MQJS_DIR} - CONFIGURE_COMMAND "" - BUILD_COMMAND make mqjs_stdlib - INSTALL_COMMAND "" - BUILD_BYPRODUCTS ${MQJS_DIR}/mqjs_stdlib) - - # Generate mqjs_stdlib.h - add_custom_command( - OUTPUT ${MQJS_DIR}/mqjs_stdlib.h - COMMAND ${MQJS_DIR}/mqjs_stdlib ${MQJS_BUILD_FLAGS} > - ${MQJS_DIR}/mqjs_stdlib.h - DEPENDS mqjs_stdlib_host - COMMENT "Generating mqjs_stdlib.h") - - # Generate mquickjs_atom.h - add_custom_command( - OUTPUT ${MQJS_DIR}/mquickjs_atom.h - COMMAND ${MQJS_DIR}/mqjs_stdlib -a ${MQJS_BUILD_FLAGS} > - ${MQJS_DIR}/mquickjs_atom.h - DEPENDS mqjs_stdlib_host - COMMENT "Generating mquickjs_atom.h") - - # Custom target for header generation - add_custom_target(mqjs_headers_gen DEPENDS ${MQJS_DIR}/mqjs_stdlib.h - ${MQJS_DIR}/mquickjs_atom.h) - - # Create mquickjs library - nuttx_add_library(libmquickjs) - target_sources( - libmquickjs - PRIVATE ${MQJS_DIR}/mquickjs.c ${MQJS_DIR}/dtoa.c ${MQJS_DIR}/libm.c - ${MQJS_DIR}/cutils.c ${MQJS_DIR}/readline.c - ${MQJS_DIR}/readline_tty.c) - target_include_directories(libmquickjs PRIVATE ${MQJS_DIR}) - nuttx_export_header(TARGET libmquickjs INCLUDE_DIRECTORIES ${MQJS_DIR}) - - # Ensure headers are generated before building library - add_dependencies(libmquickjs mqjs_headers_gen) - - # Add mquickjs include directory to global include paths - set_property( - TARGET nuttx - APPEND - PROPERTY NUTTX_INCLUDE_DIRECTORIES ${NUTTX_APPS_DIR}/interpreters/mquickjs) - - # Create mqjs NSH application - set(MQJS_PRIORITY ${CONFIG_INTERPRETERS_MQJS_PRIORITY}) - set(MQJS_STACKSIZE ${CONFIG_INTERPRETERS_MQJS_STACKSIZE}) - - nuttx_add_application( - NAME - mqjs - PRIORITY - ${MQJS_PRIORITY} - STACKSIZE - ${MQJS_STACKSIZE} - SRCS - ${MQJS_DIR}/mqjs.c - INCLUDE_DIRECTORIES - ${MQJS_DIR} - DEPENDS - libmquickjs - mqjs_headers_gen) - -endif() diff --git a/interpreters/mquickjs/Kconfig b/interpreters/mquickjs/Kconfig deleted file mode 100644 index 06e8906b7..000000000 --- a/interpreters/mquickjs/Kconfig +++ /dev/null @@ -1,24 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config INTERPRETERS_MQJS - tristate "MicroQuickJS JavaScript interpreter" - default n - -if INTERPRETERS_MQJS - -config INTERPRETERS_MQJS_PRIORITY - int "MicroQuickJS interpreter priority" - default 100 - ---help--- - Task priority of the MicroQuickJS interpreter. - - config INTERPRETERS_MQJS_STACKSIZE - int "MicroQuickJS interpreter stack size" - default 8192 - ---help--- - Size of the stack allocated for MicroQuickJS interpreter. - - endif # INTERPRETERS_MQJS diff --git a/interpreters/mquickjs/Make.defs b/interpreters/mquickjs/Make.defs deleted file mode 100644 index 8850fa7b6..000000000 --- a/interpreters/mquickjs/Make.defs +++ /dev/null @@ -1,30 +0,0 @@ -############################################################################ -# apps/interpreters/mquickjs/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_INTERPRETERS_MQJS),) -CONFIGURED_APPS += $(APPDIR)/interpreters/mquickjs - -# It allows `` import. -CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/interpreters/mquickjs/mquickjs -CXXFLAGS += ${INCDIR_PREFIX}$(APPDIR)/interpreters/mquickjs/mquickjs - -endif diff --git a/interpreters/mquickjs/Makefile b/interpreters/mquickjs/Makefile deleted file mode 100644 index 2c1ed3e49..000000000 --- a/interpreters/mquickjs/Makefile +++ /dev/null @@ -1,92 +0,0 @@ -############################################################################ -# apps/interpreters/mquickjs/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -MQJS_UNPACK = mquickjs -MQJS_ARCHIVE = mquickjs-master.zip -MQJS_URL = https://github.com/bellard/mquickjs/archive/refs/heads/master.zip - -# Determine target word size for header generation -ifeq ($(CONFIG_ARCH_64BIT),y) -MQJS_BUILD_FLAGS = -m64 -else -MQJS_BUILD_FLAGS = -m32 -endif - -CSRCS = $(MQJS_UNPACK)/mquickjs.c \ - $(MQJS_UNPACK)/dtoa.c \ - $(MQJS_UNPACK)/libm.c \ - $(MQJS_UNPACK)/cutils.c \ - $(MQJS_UNPACK)/readline.c \ - $(MQJS_UNPACK)/readline_tty.c - -PROGNAME = mqjs -PRIORITY = $(CONFIG_INTERPRETERS_MQJS_PRIORITY) -STACKSIZE = $(CONFIG_INTERPRETERS_MQJS_STACKSIZE) -MODULE = $(CONFIG_INTERPRETERS_MQJS) -MAINSRC = $(MQJS_UNPACK)/mqjs.c - -# Download archive -$(MQJS_ARCHIVE): - $(Q) echo "Downloading $(MQJS_ARCHIVE)" - $(Q) curl -L $(MQJS_URL) -o $(MQJS_ARCHIVE) - -# Unpack archive -$(MQJS_UNPACK): $(MQJS_ARCHIVE) - $(Q) echo "Unpacking $(MQJS_ARCHIVE) to $(MQJS_UNPACK)" - $(Q) unzip -q -o $(MQJS_ARCHIVE) - $(Q) mv bellard-mquickjs-* $(MQJS_UNPACK) - $(Q) touch $(MQJS_UNPACK) - -# Build host tool via upstream Makefile -$(MQJS_UNPACK)/mqjs_stdlib: - $(Q) echo "Building mquickjs host tool via upstream Makefile" - $(Q) rm -f $(MQJS_UNPACK)/mqjs_stdlib - $(Q) $(MAKE) -C $(MQJS_UNPACK) HOSTCC=$(HOSTCC) mqjs_stdlib - -# Generate stdlib header using built host tool -$(MQJS_UNPACK)/mqjs_stdlib.h: $(MQJS_UNPACK)/mqjs_stdlib - $(Q) echo "Generating mquickjs stdlib header" - $(MQJS_UNPACK)/mqjs_stdlib $(MQJS_BUILD_FLAGS) > $@ - -# Generate atom header using built host tool -$(MQJS_UNPACK)/mquickjs_atom.h: $(MQJS_UNPACK)/mqjs_stdlib - $(Q) echo "Generating mquickjs atom header" - $(MQJS_UNPACK)/mqjs_stdlib -a $(MQJS_BUILD_FLAGS) > $@ - -# Download and unpack only if not a git repository -context:: $(MQJS_UNPACK)/mqjs_stdlib.h $(MQJS_UNPACK)/mquickjs_atom.h - -# Clean up on distclean -distclean:: -ifneq ($(wildcard $(MQJS_UNPACK)/.git),) - $(Q) $(MAKE) -C $(MQJS_UNPACK) clean -else - $(call DELDIR, $(MQJS_UNPACK)) -endif - $(call DELFILE, $(MQJS_ARCHIVE)) - -# Dependencies -$(MQJS_UNPACK)/mquickjs.c: $(MQJS_UNPACK)/mquickjs_atom.h - -include $(APPDIR)/Application.mk diff --git a/interpreters/python/.gitignore b/interpreters/python/.gitignore deleted file mode 100644 index 33efb9cbe..000000000 --- a/interpreters/python/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -/*.zip -/build/ -/install/ -/Python/ -/romfs_cpython_modules.h -/romfs_cpython_modules.img -/config.site -/Setup.local diff --git a/interpreters/python/Kconfig b/interpreters/python/Kconfig deleted file mode 100644 index 752bb08b5..000000000 --- a/interpreters/python/Kconfig +++ /dev/null @@ -1,65 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config INTERPRETERS_CPYTHON - tristate "CPython" - depends on LIB_ZLIB - depends on !LIBC_DLFCN || LIB_LIBFFI - depends on EXPERIMENTAL - default n - ---help--- - Enable the CPython port to NuttX. This is a port of the Python - interpreter to NuttX. Initially, it is tweaked to work with the - RISC-V QEMU virtual board (`rv-virt`). - -if INTERPRETERS_CPYTHON - -config INTERPRETERS_CPYTHON_VERSION - string "Python Version" - default "3.13.0" - -config INTERPRETERS_CPYTHON_STACKSIZE - int "CPython stack size" - default 307200 - ---help--- - This is the stack size allocated when the CPython task runs. - -config INTERPRETERS_CPYTHON_PRIORITY - int "CPython task priority" - default 100 - ---help--- - This is the priority of the CPython task. - -config INTERPRETERS_CPYTHON_PROGNAME - string "CPython name" - default "python" - ---help--- - This is the name of the program that will be used from the nsh. - -config INTERPRETERS_CPYTHON_ENABLE_PIP - bool "Enable bundled pip" - default n - ---help--- - Enable bundling pip into the CPython module image. When enabled, the - build downloads the pip wheel and pre-installs it through a - site-packages .pth entry that points to ensurepip's bundled wheel. - Disable this to skip pip wheel download/integration entirely. - -config INTERPRETERS_CPYTHON_INSTALL_NUTTX_PACKAGE - bool "Install NuttX Python package" - default y - ---help--- - Installs the nuttx-periphery Python package into the CPython module image. - This allows importing the nuttx-periphery package into the CPython interpreter, - which provides a Python interface to the NuttX's peripheral drivers. - -config INTERPRETERS_CPYTHON_PYTHONPATH - string "CPython Python path" - default "/tmp" - ---help--- - This is the Python default search path for modules files. This is - required to be a writable path. - -endif diff --git a/interpreters/python/Make.defs b/interpreters/python/Make.defs deleted file mode 100644 index dceeb5267..000000000 --- a/interpreters/python/Make.defs +++ /dev/null @@ -1,34 +0,0 @@ -############################################################################ -# apps/interpreters/python/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_INTERPRETERS_CPYTHON),) - -CPYTHON_VERSION = $(patsubst "%",%,$(strip $(CONFIG_INTERPRETERS_CPYTHON_VERSION))) -CPYTHON_VERSION_MINOR=$(basename $(CPYTHON_VERSION)) - -EXTRA_LIBPATHS += -L$(APPDIR)/interpreters/python/install/target -EXTRA_LIBS += -lpython$(CPYTHON_VERSION_MINOR) -EXTRA_LIBS += $(APPDIR)/interpreters/python/build/target/Modules/_hacl/libHacl_Hash_SHA2.a -EXTRA_LIBS += $(APPDIR)/interpreters/python/build/target/Modules/expat/libexpat.a - -CONFIGURED_APPS += $(APPDIR)/interpreters/python -endif diff --git a/interpreters/python/Makefile b/interpreters/python/Makefile deleted file mode 100644 index bac4013f8..000000000 --- a/interpreters/python/Makefile +++ /dev/null @@ -1,288 +0,0 @@ -############################################################################ -# apps/interpreters/python/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -CPYTHON_URL ?= "https://github.com/python/cpython/archive" -CPYTHON_VERSION = $(patsubst "%",%,$(strip $(CONFIG_INTERPRETERS_CPYTHON_VERSION))) -CPYTHON_VERSION_MINOR=$(basename $(CPYTHON_VERSION)) -CPYTHON_ZIP = v$(CPYTHON_VERSION).zip - -CPYTHON_UNPACKNAME = Python -UNPACK ?= unzip -q -o - -MACHDEP=nuttx -CONFIG_SITE=${CURDIR}/config.site -SETUP_LOCAL=${CURDIR}/Setup.local -CPYTHON_PATH=$(CURDIR)/$(CPYTHON_UNPACKNAME) - -BUILDIR=$(CURDIR)/build -INSTALLDIR=$(CURDIR)/install -HOSTBUILD=$(BUILDIR)/host -HOSTINSTALL=$(INSTALLDIR)/host -HOSTPYTHON=$(HOSTINSTALL)/bin/python3 -TARGETBUILD=$(BUILDIR)/target -TARGETINSTALL=$(INSTALLDIR)/target -TARGETLIBPYTHON=$(TARGETINSTALL)/libpython$(CPYTHON_VERSION_MINOR).a -TARGETMODULESPACK=$(TARGETBUILD)/lib/python$(shell echo $(CPYTHON_VERSION_MINOR) | tr -d .).zip -TARGETMODULES=$(TARGETINSTALL)/lib/ - -CFLAGS += ${INCDIR_PREFIX}$(CPYTHON_PATH)$(DELIM)Include -CFLAGS += ${INCDIR_PREFIX}$(CPYTHON_PATH)$(DELIM)Test -CFLAGS += ${INCDIR_PREFIX}$(CPYTHON_PATH)$(DELIM)Include$(DELIM)internal -CFLAGS += ${INCDIR_PREFIX}$(APPDIR)$(DELIM)system -CFLAGS += ${INCDIR_PREFIX}$(APPDIR)$(DELIM)system$(DELIM)zlib$(DELIM)zlib -CFLAGS += ${INCDIR_PREFIX}$(TARGETBUILD) -CFLAGS += -Wno-shadow -Wno-undef -Wno-format -Wno-builtin-macro-redefined -CFLAGS += -Wno-type-limits -Wno-implicit-fallthrough -Wno-char-subscripts -CFLAGS += -Wno-sign-compare -Wno-unused-const-variable -Wno-unused-function -CFLAGS += -Wno-unused-variable -Wno-overflow -Wno-unused-but-set-variable -CFLAGS += -Wno-strict-prototypes -Wno-maybe-uninitialized -nostdlib - -DEPPATH += --dep-path $(CPYTHON_UNPACKNAME)$(DELIM)Programs -VPATH += :$(CPYTHON_UNPACKNAME)$(DELIM)Programs - -$(CPYTHON_ZIP): - @echo "Downloading: $(CPYTHON_URL)/$(CPYTHON_ZIP)" - $(Q) $(call DOWNLOAD,$(CPYTHON_URL),$(CPYTHON_ZIP)) - -$(CPYTHON_UNPACKNAME): $(CPYTHON_ZIP) - @echo "Unpacking: $(CPYTHON_ZIP) -> $(CPYTHON_UNPACKNAME)" - $(Q) $(UNPACK) $(CPYTHON_ZIP) - $(Q) mv cpython-$(CPYTHON_VERSION) $(CPYTHON_UNPACKNAME) - @echo "Patching $(CPYTHON_UNPACKNAME)" - $(Q) patch -p1 -d $(CPYTHON_UNPACKNAME) < patch$(DELIM)0001-workaround-newlib-resource.h-limitations.patch - $(Q) patch -p1 -d $(CPYTHON_UNPACKNAME) < patch$(DELIM)0002-fix-various-uint32_t-unsigned-int-type-mismatch-issu.patch - $(Q) patch -p1 -d $(CPYTHON_UNPACKNAME) < patch$(DELIM)0003-reuse-wasm_assets.py-for-generating-an-archive-of-py.patch - $(Q) patch -p1 -d $(CPYTHON_UNPACKNAME) < patch$(DELIM)0004-recognize-nuttx-as-a-supported-OS.patch - $(Q) patch -p1 -d $(CPYTHON_UNPACKNAME) < patch$(DELIM)0005-gh-122907-Fix-Builds-Without-HAVE_DYNAMIC_LOADING-Se.patch - $(Q) patch -p1 -d $(CPYTHON_UNPACKNAME) < patch$(DELIM)0006-change-var-name-to-avoid-conflict-with-nuttx-unused_.patch - $(Q) patch -p1 -d $(CPYTHON_UNPACKNAME) < patch$(DELIM)0007-undef-atexit_register.patch - $(Q) patch -p1 -d $(CPYTHON_UNPACKNAME) < patch$(DELIM)0008-declare-struct-timeval.patch - $(Q) patch -p1 -d $(CPYTHON_UNPACKNAME) < patch$(DELIM)0009-include-nuttx-sys-select-header-to-define-FD_SETSIZE.patch - $(Q) patch -p1 -d $(CPYTHON_UNPACKNAME) < patch$(DELIM)0010-check-for-the-d_ino-member-of-the-structure-dirent.patch - $(Q) patch -p1 -d $(CPYTHON_UNPACKNAME) < patch$(DELIM)0011-avoid-redefinition-warning-if-UNUSED-is-already-defi.patch - $(Q) patch -p1 -d $(CPYTHON_UNPACKNAME) < patch$(DELIM)0012-hack-place-_PyRuntime-structure-into-PSRAM-bss-regio.patch - $(Q) patch -p1 -d $(CPYTHON_UNPACKNAME) < patch$(DELIM)0013-transform-functions-used-by-NuttX-to-lowercase.patch - $(Q) patch -p1 -d $(CPYTHON_UNPACKNAME) < patch$(DELIM)0014-insert-prefix-to-list_length-to-avoid-symbol-collisi.patch - $(Q) patch -p1 -d $(CPYTHON_UNPACKNAME) < patch$(DELIM)0015-keep-ensurepip-in-stdlib-archive.patch - $(Q) patch -p1 -d $(CPYTHON_UNPACKNAME) < patch$(DELIM)0016-fix-timezone-offset-check-when-time-t-is-unsigned.patch - $(Q) patch -p1 -d $(CPYTHON_UNPACKNAME) < patch$(DELIM)0017-stdlib-zip-keep-pydecimal-and-trim-tooling-extras.patch - $(Q) patch -p1 -d $(CPYTHON_UNPACKNAME) < patch$(DELIM)0018-ignore-chmod-on-nuttx-like-wasi.patch - $(Q) patch -p1 -d $(CPYTHON_UNPACKNAME) < patch$(DELIM)0019-undef-get_errno-set_errno-to-avoid-nuttx-macro-coll.patch - $(Q) patch -p1 -d $(CPYTHON_UNPACKNAME) < patch$(DELIM)0020-ctypes-skip-pythonapi-on-nuttx.patch - $(Q) patch -p1 -d $(CPYTHON_UNPACKNAME) < patch$(DELIM)0021-posixmodule-ignore-utime-enosys-on-nuttx.patch - -$(HOSTPYTHON): - mkdir -p $(HOSTBUILD) - mkdir -p $(HOSTINSTALL) - $(Q) ( \ - cd $(HOSTBUILD) && $(CPYTHON_PATH)/configure \ - --with-pydebug \ - --prefix=$(HOSTINSTALL) \ - --disable-test-modules \ - ) - $(MAKE) -C $(HOSTBUILD) install - -# The `config.site` file contains settings that override the configuration -# settings provided by the `configure` script. Depending on the features -# enabled on NuttX, this file may need to be adjusted. - -$(CONFIG_SITE): - $(Q) ( cp $(CONFIG_SITE).in $(CONFIG_SITE)) -ifeq ($(CONFIG_ARCH_HAVE_FORK),y) - @echo "export ac_cv_func_fork=\"yes\"" >> $@ -else - @echo "export ac_cv_func_fork=\"no\"" >> $@ -endif -ifeq ($(CONFIG_SYSTEM_SYSTEM),y) - @echo "export ac_cv_func_system=\"yes\"" >> $@ -else - @echo "export ac_cv_func_system=\"no\"" >> $@ -endif -ifeq ($(CONFIG_NET),y) - @echo "export ac_cv_func_getaddrinfo=\"yes\"" >> $@ - @echo "export ac_cv_func_getnameinfo=\"yes\"" >> $@ -else - @echo "export ac_cv_func_getaddrinfo=\"no\"" >> $@ - @echo "export ac_cv_func_getnameinfo=\"no\"" >> $@ -endif - -# The `Setup.local` file enables or disables Python modules. -# Depending on the features enabled on NuttX, this file may need to be -# adjusted. Please note that the base `Setup.local.in` file only contains -# a section to disable Python modules. Inserting lines to it will disable -# such modules. - -$(SETUP_LOCAL): - $(Q) ( cp $(SETUP_LOCAL).in $(SETUP_LOCAL)) -ifneq ($(CONFIG_ARCH_HAVE_FORK),y) - @echo "_posixsubprocess" >> $@ -endif -ifneq ($(CONFIG_LIBC_DLFCN),y) - @echo "_ctypes" >> $@ -endif -ifneq ($(CONFIG_NET),y) - @echo "_socket" >> $@ -endif - -# For the Python's `configure` script, please consider the following -# when building for NuttX: -# -# Use sed to remove optimization flags from NuttX's CFLAGS because -# Python's configure script requires them in OPT. Having the flags in -# both places causes a conflict. -# -# Also, use -O0 for OPT because -Os is causing problems in -# Python/Modules/getpath.c (issue will be filed soon to track this -# problem). - -ifneq ($(CONFIG_NET),y) -PYTHON_CONFIGURE_EXTRAS = --disable-ipv6 -else -PYTHON_CONFIGURE_EXTRAS = -endif - -$(TARGETBUILD)/Makefile: $(HOSTPYTHON) $(CONFIG_SITE) $(SETUP_LOCAL) - $(Q) mkdir -p $(TARGETBUILD)/Modules - $(Q) mkdir -p $(TARGETMODULES)/python$(CPYTHON_VERSION_MINOR) - $(Q) ( cp Setup.local $(TARGETBUILD)/Modules/Setup.local ) - $(Q) ( \ - cd $(TARGETBUILD); \ - CFLAGS="$(CFLAGS)"; \ - ARCH=$(CONFIG_ARCH); \ - ARCH_CHIP=$(CONFIG_ARCH_CHIP); \ - ARCH="$${ARCH//-/}"; \ - ARCH_CHIP="$${ARCH_CHIP//-/}"; \ - CFLAGS="$$(echo "$${CFLAGS}" | sed 's/-Os //')" \ - CC="$(CC)" \ - CXX="$(CXX)" \ - AR="$(AR)" \ - ARFLAGS=" " \ - MACHDEP="$(MACHDEP)" \ - OPT="-Os" \ - CONFIG_SITE="$(CONFIG_SITE)" \ - $(CPYTHON_PATH)/configure \ - --prefix=${TARGETINSTALL} \ - --disable-shared \ - --host=$${ARCH}-$${ARCH_CHIP}-nuttx \ - --build=$(shell $(CPYTHON_PATH)/config.guess) \ - --with-build-python=${HOSTPYTHON} \ - --without-mimalloc \ - --without-pymalloc \ - --disable-test-modules \ - --with-ensurepip=no \ - $(PYTHON_CONFIGURE_EXTRAS) \ - ) - $(Q) sed -i 's/^#define HAVE_LIBB2 1/\/* #undef HAVE_LIBB2 *\//' $(TARGETBUILD)/pyconfig.h - $(Q) sed -i 's/-lb2//g' $(TARGETBUILD)/Makefile - -BUNDLED_WHEELS_DIR = $(CPYTHON_PATH)/Lib/ensurepip/_bundled -# PyPI downloads use the host system pip, not $(HOSTPYTHON)'s ensurepip bundle: -# pip 24.x vendors urllib3 that breaks on Python 3.13 (zlib.Decompress.unused_data). -HOSTPIP = python3 -m pip - -$(TARGETLIBPYTHON): $(TARGETBUILD)/Makefile -ifneq ($(or $(filter y,$(CONFIG_INTERPRETERS_CPYTHON_ENABLE_PIP)),$(filter y,$(CONFIG_INTERPRETERS_CPYTHON_INSTALL_NUTTX_PACKAGE))),) - $(Q) mkdir -p $(BUNDLED_WHEELS_DIR) -endif -ifeq ($(CONFIG_INTERPRETERS_CPYTHON_ENABLE_PIP),y) - $(Q) ( \ - PIP_WHEEL_VERSION=$$($(HOSTPYTHON) -c "import ensurepip; print(ensurepip._PIP_VERSION)"); \ - PIP_WHEEL=$(BUNDLED_WHEELS_DIR)/pip-$${PIP_WHEEL_VERSION}-py3-none-any.whl; \ - if [ ! -f "$${PIP_WHEEL}" ]; then \ - echo "Fetching pip wheel $${PIP_WHEEL_VERSION} for ensurepip bundle"; \ - $(HOSTPIP) download --only-binary=:all: --no-deps --dest $(BUNDLED_WHEELS_DIR) pip==$${PIP_WHEEL_VERSION}; \ - fi; \ - echo "Pre-compiling pip wheel with build Python (must match embedded CPython version)"; \ - $(HOSTPYTHON) $(CURDIR)/repack_wheel_add_pyc.py --package pip "$${PIP_WHEEL}"; \ - ) -endif -ifeq ($(CONFIG_INTERPRETERS_CPYTHON_INSTALL_NUTTX_PACKAGE),y) - $(Q) ( \ - set -e; \ - NUTTX_WHEEL=$$(ls $(BUNDLED_WHEELS_DIR)/nuttx_periphery-*-py3-none-any.whl 2>/dev/null | head -1 || true); \ - if [ -z "$${NUTTX_WHEEL}" ]; then \ - echo "Fetching latest nuttx-periphery wheel for ensurepip bundle"; \ - $(HOSTPIP) download --only-binary=:all: --no-deps --dest $(BUNDLED_WHEELS_DIR) nuttx-periphery; \ - NUTTX_WHEEL=$$(ls $(BUNDLED_WHEELS_DIR)/nuttx_periphery-*-py3-none-any.whl); \ - fi; \ - echo "Pre-compiling nuttx-periphery wheel with build Python (must match embedded CPython version)"; \ - $(HOSTPYTHON) $(CURDIR)/repack_wheel_add_pyc.py --package nuttx_periphery "$${NUTTX_WHEEL}"; \ - ) -endif - $(MAKE) -C $(TARGETBUILD) regen-frozen - $(MAKE) -C $(TARGETBUILD) libpython$(CPYTHON_VERSION_MINOR).a wasm_stdlib - $(Q) ( cp $(TARGETBUILD)/libpython$(CPYTHON_VERSION_MINOR).a $(TARGETLIBPYTHON) ) - $(Q) $(UNPACK) $(TARGETMODULESPACK) -d $(TARGETMODULES)/python$(CPYTHON_VERSION_MINOR) -ifneq ($(or $(filter y,$(CONFIG_INTERPRETERS_CPYTHON_ENABLE_PIP)),$(filter y,$(CONFIG_INTERPRETERS_CPYTHON_INSTALL_NUTTX_PACKAGE))),) - $(Q) mkdir -p $(TARGETMODULES)/python$(CPYTHON_VERSION_MINOR)/site-packages - $(Q) ( \ - set -e; \ - BUNDLED_DIR=$(TARGETMODULES)/python$(CPYTHON_VERSION_MINOR)/ensurepip/_bundled; \ - SITE_PACKAGES=$(TARGETMODULES)/python$(CPYTHON_VERSION_MINOR)/site-packages; \ - : > "$${SITE_PACKAGES}/bundled_wheels.pth"; \ - for wheel in $${BUNDLED_DIR}/*.whl; do \ - [ -f "$${wheel}" ] || continue; \ - whl_name=$$(basename "$${wheel}"); \ - echo "Pre-installing wheel via zipimport into target sys.path: $${whl_name}"; \ - echo "../ensurepip/_bundled/$${whl_name}" >> "$${SITE_PACKAGES}/bundled_wheels.pth"; \ - done; \ - ) -endif - -MODULE = $(CONFIG_INTERPRETERS_CPYTHON) - -PROGNAME += $(CONFIG_INTERPRETERS_CPYTHON_PROGNAME) -PRIORITY += $(CONFIG_INTERPRETERS_CPYTHON_PRIORITY) -STACKSIZE += $(CONFIG_INTERPRETERS_CPYTHON_STACKSIZE) - -MAINSRC += python_wrapper.c - -checkgenromfs: - @genromfs -h 1>/dev/null 2>&1 || { \ - echo "Host executable genromfs not available in PATH"; \ - echo "You may need to download in from https://romfs.sourceforge.net/"; \ - exit 1; \ - } - -romfs_cpython_modules.img : $(TARGETLIBPYTHON) checkgenromfs - @genromfs -f $@ -d $(TARGETMODULES) -V "ROMFS_Test" || { echo "genromfs failed" ; exit 1 ; } - -romfs_cpython_modules.h : romfs_cpython_modules.img - @xxd -i $< | sed -e "s/^unsigned/static const unsigned/g" >$@ || { echo "xxd of $< failed" ; exit 1 ; } - -context:: $(CPYTHON_UNPACKNAME) - -depend:: romfs_cpython_modules.h - -distclean:: - $(call DELDIR, $(BUILDIR)) - $(call DELDIR, $(INSTALLDIR)) - $(call DELDIR, $(CPYTHON_UNPACKNAME)) - $(call DELFILE, $(CPYTHON_ZIP)) - $(call DELFILE, romfs_cpython_modules.img) - $(call DELFILE, romfs_cpython_modules.h) - $(call DELFILE, config.site) - $(call DELFILE, Setup.local) - -include $(APPDIR)/Application.mk diff --git a/interpreters/python/Setup.local.in b/interpreters/python/Setup.local.in deleted file mode 100644 index d8c27292b..000000000 --- a/interpreters/python/Setup.local.in +++ /dev/null @@ -1,38 +0,0 @@ -# This file gets copied into the Modules/ folder when building -# newlib configurations which do not support dynamic library -# loading. - -*disabled* -_asyncio -_bz2 -_codecs_cn -_codecs_hk -_codecs_iso2022 -_codecs_jp -_codecs_kr -_codecs_tw -_decimal -_elementtree -_heapq -_interpchannels -_interpqueues -_lsprof -_lzma -_multibytecodec -_sqlite3 -_ssl -_statistics -_testbuffer -_testcapi -_testclinic -_testclinic_limited -_testexternalinspection -_testinternalcapi -_testlimitedcapi -_uuid -_xxtestfuzz -_zoneinfo -pwd -readline -resource -xxsubtype diff --git a/interpreters/python/config.site.in b/interpreters/python/config.site.in deleted file mode 100644 index d19337ea6..000000000 --- a/interpreters/python/config.site.in +++ /dev/null @@ -1,37 +0,0 @@ -export MODULE_BUILDTYPE="static" -export ac_cv_file__dev_ptmx="no" -export ac_cv_file__dev_ptc="no" -export ac_cv_buggy_getaddrinfo="no" -export ac_cv_func_getaddrinfo="yes" -export ac_cv_pthread_is_default="yes" -export ac_cv_func_acosh="yes" -export ac_cv_func_asinh="yes" -export ac_cv_func_atanh="yes" -export ac_cv_func_erf="yes" -export ac_cv_func_erfc="yes" -export ac_cv_func_expm1="yes" -export ac_cv_func_log1p="yes" -export ac_cv_func_log2="yes" -export ac_cv_func_clock_gettime="yes" -export ac_cv_header_sys_syscall_h="no" -export ac_cv_func_timegm="yes" -export ac_cv_func_clock="yes" -export ac_cv_func_waitpid="yes" -export ac_cv_func_pipe="yes" -export ac_cv_enable_strict_prototypes_warning="no" -export ac_cv_func_getnameinfo="yes" -export ac_cv_func_poll="yes" -export ac_cv_func_gethostname="yes" -export ac_cv_func_lstat="yes" -export ac_cv_func_readlink="yes" -export ac_cv_func_realpath="yes" -export ac_cv_func_getpid="yes" -export ac_cv_func_utime="yes" -export ac_cv_func_utimes="yes" -export ac_cv_func_getuid="yes" -export ac_cv_func_sysconf="yes" -export ac_cv_func_umask="yes" -export ac_cv_func_ffi_prep_cif_var="yes" -export ac_cv_func_ffi_prep_closure_loc="yes" -export ac_cv_func_ffi_closure_alloc="yes" -export ac_cv_func_utimes="no" diff --git a/interpreters/python/patch/0001-workaround-newlib-resource.h-limitations.patch b/interpreters/python/patch/0001-workaround-newlib-resource.h-limitations.patch deleted file mode 100644 index 3c7866c28..000000000 --- a/interpreters/python/patch/0001-workaround-newlib-resource.h-limitations.patch +++ /dev/null @@ -1,31 +0,0 @@ -From b96f875c54e2d888413a701eb9727d704b995ce0 Mon Sep 17 00:00:00 2001 -From: Ivan Grokhotkov -Date: Tue, 22 Oct 2024 23:58:17 +0200 -Subject: [PATCH 01/14] workaround newlib resource.h limitations - -configure script checks if resource.h is available but doesn't check -if it defines all the necessary functions. - -Temporary workaround until these functions are added to IDF. - -Signed-off-by: Tiago Medicci ---- - Modules/faulthandler.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/Modules/faulthandler.c b/Modules/faulthandler.c -index b62362f2777..327d883f94e 100644 ---- a/Modules/faulthandler.c -+++ b/Modules/faulthandler.c -@@ -968,7 +968,7 @@ faulthandler_suppress_crash_report(void) - SetErrorMode(mode | SEM_NOGPFAULTERRORBOX); - #endif - --#ifdef HAVE_SYS_RESOURCE_H -+#if 0 && defined(HAVE_SYS_RESOURCE_H) - struct rlimit rl; - - /* Disable creation of core dump */ --- -2.50.0 - diff --git a/interpreters/python/patch/0002-fix-various-uint32_t-unsigned-int-type-mismatch-issu.patch b/interpreters/python/patch/0002-fix-various-uint32_t-unsigned-int-type-mismatch-issu.patch deleted file mode 100644 index 8257580de..000000000 --- a/interpreters/python/patch/0002-fix-various-uint32_t-unsigned-int-type-mismatch-issu.patch +++ /dev/null @@ -1,153 +0,0 @@ -From 2c684af739d366dce8392ee2bb9af8248283e323 Mon Sep 17 00:00:00 2001 -From: Ivan Grokhotkov -Date: Wed, 23 Oct 2024 16:48:49 +0200 -Subject: [PATCH 02/14] fix various uint32_t/'unsigned int' type mismatch - issues - -In a few places existing code assumes that uint32_t == unsigned int. -Since in Xtensa and RISC-V bare metal toolchains uint32_t is instead -'unsigned long', the original code fails to build. - -Signed-off-by: Tiago Medicci ---- - Modules/zlibmodule.c | 28 ++++++++++++++-------------- - Objects/typeobject.c | 2 +- - 2 files changed, 15 insertions(+), 15 deletions(-) - -diff --git a/Modules/zlibmodule.c b/Modules/zlibmodule.c -index b115f67f228..034a9420b16 100644 ---- a/Modules/zlibmodule.c -+++ b/Modules/zlibmodule.c -@@ -28,13 +28,13 @@ - On failure, return -1 */ - static inline Py_ssize_t - OutputBuffer_InitAndGrow(_BlocksOutputBuffer *buffer, Py_ssize_t max_length, -- Bytef **next_out, uint32_t *avail_out) -+ Bytef **next_out, unsigned int *avail_out) - { - Py_ssize_t allocated; - - allocated = _BlocksOutputBuffer_InitAndGrow( - buffer, max_length, (void**) next_out); -- *avail_out = (uint32_t) allocated; -+ *avail_out = (unsigned) allocated; - return allocated; - } - -@@ -42,24 +42,24 @@ OutputBuffer_InitAndGrow(_BlocksOutputBuffer *buffer, Py_ssize_t max_length, - On failure, return -1 */ - static inline Py_ssize_t - OutputBuffer_Grow(_BlocksOutputBuffer *buffer, -- Bytef **next_out, uint32_t *avail_out) -+ Bytef **next_out, unsigned int *avail_out) - { - Py_ssize_t allocated; - - allocated = _BlocksOutputBuffer_Grow( - buffer, (void**) next_out, (Py_ssize_t) *avail_out); -- *avail_out = (uint32_t) allocated; -+ *avail_out = (unsigned int) allocated; - return allocated; - } - - static inline Py_ssize_t --OutputBuffer_GetDataSize(_BlocksOutputBuffer *buffer, uint32_t avail_out) -+OutputBuffer_GetDataSize(_BlocksOutputBuffer *buffer, unsigned int avail_out) - { - return _BlocksOutputBuffer_GetDataSize(buffer, (Py_ssize_t) avail_out); - } - - static inline PyObject * --OutputBuffer_Finish(_BlocksOutputBuffer *buffer, uint32_t avail_out) -+OutputBuffer_Finish(_BlocksOutputBuffer *buffer, unsigned int avail_out) - { - return _BlocksOutputBuffer_Finish(buffer, (Py_ssize_t) avail_out); - } -@@ -97,7 +97,7 @@ typedef struct { - static inline Py_ssize_t - OutputBuffer_WindowInitWithSize(_BlocksOutputBuffer *buffer, _Uint32Window *window, - Py_ssize_t init_size, -- Bytef **next_out, uint32_t *avail_out) -+ Bytef **next_out, unsigned int *avail_out) - { - Py_ssize_t allocated = _BlocksOutputBuffer_InitWithSize( - buffer, init_size, (void**) next_out); -@@ -105,7 +105,7 @@ OutputBuffer_WindowInitWithSize(_BlocksOutputBuffer *buffer, _Uint32Window *wind - if (allocated >= 0) { - // the UINT32_MAX sliding window - Py_ssize_t window_size = Py_MIN((size_t)allocated, UINT32_MAX); -- *avail_out = (uint32_t) window_size; -+ *avail_out = (unsigned int) window_size; - - window->left_bytes = allocated - window_size; - window->next_posi = *next_out + window_size; -@@ -119,7 +119,7 @@ OutputBuffer_WindowInitWithSize(_BlocksOutputBuffer *buffer, _Uint32Window *wind - On failure, return value < 0 */ - static inline Py_ssize_t - OutputBuffer_WindowGrow(_BlocksOutputBuffer *buffer, _Uint32Window *window, -- Bytef **next_out, uint32_t *avail_out) -+ Bytef **next_out, unsigned int *avail_out) - { - Py_ssize_t allocated; - -@@ -136,7 +136,7 @@ OutputBuffer_WindowGrow(_BlocksOutputBuffer *buffer, _Uint32Window *window, - Py_ssize_t window_size = Py_MIN((size_t)window->left_bytes, UINT32_MAX); - - *next_out = window->next_posi; -- *avail_out = (uint32_t) window_size; -+ *avail_out = (unsigned int) window_size; - - window->left_bytes -= window_size; - window->next_posi += window_size; -@@ -148,7 +148,7 @@ OutputBuffer_WindowGrow(_BlocksOutputBuffer *buffer, _Uint32Window *window, - // only the first block may > UINT32_MAX - allocated = _BlocksOutputBuffer_Grow( - buffer, (void**) next_out, (Py_ssize_t) *avail_out); -- *avail_out = (uint32_t) allocated; -+ *avail_out = (unsigned int) allocated; - return allocated; - } - -@@ -158,7 +158,7 @@ OutputBuffer_WindowGrow(_BlocksOutputBuffer *buffer, _Uint32Window *window, - On failure, return NULL */ - static inline PyObject * - OutputBuffer_WindowFinish(_BlocksOutputBuffer *buffer, _Uint32Window *window, -- uint32_t avail_out) -+ unsigned avail_out) - { - Py_ssize_t real_avail_out = (Py_ssize_t) avail_out + window->left_bytes; - return _BlocksOutputBuffer_Finish(buffer, real_avail_out); -@@ -1398,7 +1398,7 @@ set_inflate_zdict_ZlibDecompressor(zlibstate *state, ZlibDecompressor *self) - } - - static Py_ssize_t --arrange_output_buffer_with_maximum(uint32_t *avail_out, -+arrange_output_buffer_with_maximum(unsigned int *avail_out, - uint8_t **next_out, - PyObject **buffer, - Py_ssize_t length, -@@ -1430,7 +1430,7 @@ arrange_output_buffer_with_maximum(uint32_t *avail_out, - } - } - -- *avail_out = (uint32_t)Py_MIN((size_t)(length - occupied), UINT32_MAX); -+ *avail_out = (unsigned)Py_MIN((size_t)(length - occupied), UINT32_MAX); - *next_out = (uint8_t *)PyBytes_AS_STRING(*buffer) + occupied; - - return length; -diff --git a/Objects/typeobject.c b/Objects/typeobject.c -index c911c302003..9c640e0ab65 100644 ---- a/Objects/typeobject.c -+++ b/Objects/typeobject.c -@@ -5140,7 +5140,7 @@ is_dunder_name(PyObject *name) - static PyObject * - update_cache(struct type_cache_entry *entry, PyObject *name, unsigned int version_tag, PyObject *value) - { -- _Py_atomic_store_uint32_relaxed(&entry->version, version_tag); -+ _Py_atomic_store_uint32_relaxed((uint32_t*) &entry->version, version_tag); - _Py_atomic_store_ptr_relaxed(&entry->value, value); /* borrowed */ - assert(_PyASCIIObject_CAST(name)->hash != -1); - OBJECT_STAT_INC_COND(type_cache_collisions, entry->name != Py_None && entry->name != name); --- -2.50.0 - diff --git a/interpreters/python/patch/0003-reuse-wasm_assets.py-for-generating-an-archive-of-py.patch b/interpreters/python/patch/0003-reuse-wasm_assets.py-for-generating-an-archive-of-py.patch deleted file mode 100644 index 6e5820410..000000000 --- a/interpreters/python/patch/0003-reuse-wasm_assets.py-for-generating-an-archive-of-py.patch +++ /dev/null @@ -1,43 +0,0 @@ -From 41728277acd7eba4e500d0b4ddd02198b92cf6ac Mon Sep 17 00:00:00 2001 -From: Ivan Grokhotkov -Date: Wed, 23 Oct 2024 16:54:39 +0200 -Subject: [PATCH 03/14] reuse wasm_assets.py for generating an archive of - python lib dir - -wasm_assets.py is a useful script to prepare the smallest possible -package of pre-compiled python stdlib modules. There is very little -wasm-specific there. - -This patch adds nuttx to the supported OS list in the script, as well -as fixes what I think is a bug in path calculation. - -Co-authored-by: Tiago Medicci Serrano -Signed-off-by: Tiago Medicci ---- - Tools/wasm/wasm_assets.py | 3 ++- - 1 file changed, 2 insertions(+), 1 deletion(-) - -diff --git a/Tools/wasm/wasm_assets.py b/Tools/wasm/wasm_assets.py -index ffa5e303412..381d4819c39 100755 ---- a/Tools/wasm/wasm_assets.py -+++ b/Tools/wasm/wasm_assets.py -@@ -99,6 +99,7 @@ - "_sysconfigdata__emscripten_wasm32-emscripten", - "_sysconfigdata__wasi_wasm32-wasi", - "_sysconfigdata__wasi_wasm64-wasi", -+ "_sysconfigdata__nuttx_" - ) - - -@@ -203,7 +204,7 @@ def main() -> None: - relative_prefix = args.prefix.relative_to(pathlib.Path("/")) - args.srcdir = SRCDIR - args.srcdir_lib = SRCDIR_LIB -- args.wasm_root = args.buildroot / relative_prefix -+ args.wasm_root = args.buildroot #/ relative_prefix - args.wasm_stdlib_zip = args.wasm_root / WASM_STDLIB_ZIP - args.wasm_stdlib = args.wasm_root / WASM_STDLIB - args.wasm_dynload = args.wasm_root / WASM_DYNLOAD --- -2.50.0 - diff --git a/interpreters/python/patch/0004-recognize-nuttx-as-a-supported-OS.patch b/interpreters/python/patch/0004-recognize-nuttx-as-a-supported-OS.patch deleted file mode 100644 index aae248a19..000000000 --- a/interpreters/python/patch/0004-recognize-nuttx-as-a-supported-OS.patch +++ /dev/null @@ -1,61 +0,0 @@ -From 9965644a9cee6c85a726d21ff2ed6f1e42445941 Mon Sep 17 00:00:00 2001 -From: Ivan Grokhotkov -Date: Wed, 23 Oct 2024 16:55:53 +0200 -Subject: [PATCH 04/14] recognize *-*-nuttx as a supported OS - -cpython's configure script bails out when cross-compiling for an -unknown OS, so we have to add "nuttx" to the list, even though it -is not used almost anywhere else. - -Co-authored-by: Tiago Medicci Serrano -Signed-off-by: Tiago Medicci ---- - config.sub | 2 +- - configure | 3 +++ - configure.ac | 3 +++ - 3 files changed, 7 insertions(+), 1 deletion(-) - -diff --git a/config.sub b/config.sub -index 1bb6a05dc11..2a87d3e0ddb 100755 ---- a/config.sub -+++ b/config.sub -@@ -1769,7 +1769,7 @@ case $os in - | onefs* | tirtos* | phoenix* | fuchsia* | redox* | bme* \ - | midnightbsd* | amdhsa* | unleashed* | emscripten* | wasi* \ - | nsk* | powerunix* | genode* | zvmoe* | qnx* | emx* | zephyr* \ -- | fiwix* | mlibc* | cos* | mbr* | ironclad* ) -+ | fiwix* | mlibc* | cos* | mbr* | ironclad* | nuttx* ) - ;; - # This one is extra strict with allowed versions - sco3.2v2 | sco3.2v[4-9]* | sco5v6*) -diff --git a/configure b/configure -index 7cdd386c387..6da5e9f3832 100755 ---- a/configure -+++ b/configure -@@ -4527,6 +4527,9 @@ printf "%s\n" "$IPHONEOS_DEPLOYMENT_TARGET" >&6; } - wasm32-*-* | wasm64-*-*) - _host_ident=$host_cpu - ;; -+ *-*-nuttx*) -+ _host_ident=$host_cpu -+ ;; - *) - # for now, limit cross builds to known configurations - MACHDEP="unknown" -diff --git a/configure.ac b/configure.ac -index 24e28a1e2de..80d6738fab5 100644 ---- a/configure.ac -+++ b/configure.ac -@@ -777,6 +777,9 @@ if test "$cross_compiling" = yes; then - wasm32-*-* | wasm64-*-*) - _host_ident=$host_cpu - ;; -+ *-*-nuttx*) -+ _host_ident=$host_cpu -+ ;; - *) - # for now, limit cross builds to known configurations - MACHDEP="unknown" --- -2.50.0 - diff --git a/interpreters/python/patch/0005-gh-122907-Fix-Builds-Without-HAVE_DYNAMIC_LOADING-Se.patch b/interpreters/python/patch/0005-gh-122907-Fix-Builds-Without-HAVE_DYNAMIC_LOADING-Se.patch deleted file mode 100644 index 3d7616b19..000000000 --- a/interpreters/python/patch/0005-gh-122907-Fix-Builds-Without-HAVE_DYNAMIC_LOADING-Se.patch +++ /dev/null @@ -1,190 +0,0 @@ -From d5c061676d7ee6f1fb963bdf79791e37b5b05a36 Mon Sep 17 00:00:00 2001 -From: Eric Snow -Date: Tue, 13 Aug 2024 14:44:57 -0600 -Subject: [PATCH 05/14] gh-122907: Fix Builds Without HAVE_DYNAMIC_LOADING Set - (gh-122952) - -As of 529a160 (gh-118204), building with HAVE_DYNAMIC_LOADING stopped working. This is a minimal fix just to get builds working again. There are actually a number of long-standing deficiencies with HAVE_DYNAMIC_LOADING builds that need to be resolved separately. -(cherry picked from commit ee1b8ce26e700350e47a5f65201097121c41912e) - -Co-authored-by: Eric Snow -Signed-off-by: Tiago Medicci ---- - Include/internal/pycore_importdl.h | 4 ++++ - Lib/importlib/_bootstrap_external.py | 16 ++++++++-------- - ...024-08-12-11-19-37.gh-issue-122907.q68096.rst | 3 +++ - Python/importdl.c | 12 ++++++++---- - Tools/build/check_extension_modules.py | 9 +++++++++ - 5 files changed, 32 insertions(+), 12 deletions(-) - create mode 100644 Misc/NEWS.d/next/Core_and_Builtins/2024-08-12-11-19-37.gh-issue-122907.q68096.rst - -diff --git a/Include/internal/pycore_importdl.h b/Include/internal/pycore_importdl.h -index e5f222b371a..525a16f6b97 100644 ---- a/Include/internal/pycore_importdl.h -+++ b/Include/internal/pycore_importdl.h -@@ -56,9 +56,11 @@ extern int _Py_ext_module_loader_info_init_for_core( - extern int _Py_ext_module_loader_info_init_for_builtin( - struct _Py_ext_module_loader_info *p_info, - PyObject *name); -+#ifdef HAVE_DYNAMIC_LOADING - extern int _Py_ext_module_loader_info_init_from_spec( - struct _Py_ext_module_loader_info *info, - PyObject *spec); -+#endif - - /* The result from running an extension module's init function. */ - struct _Py_ext_module_loader_result { -@@ -87,9 +89,11 @@ extern void _Py_ext_module_loader_result_apply_error( - - /* The module init function. */ - typedef PyObject *(*PyModInitFunction)(void); -+#ifdef HAVE_DYNAMIC_LOADING - extern PyModInitFunction _PyImport_GetModInitFunc( - struct _Py_ext_module_loader_info *info, - FILE *fp); -+#endif - extern int _PyImport_RunModInitFunc( - PyModInitFunction p0, - struct _Py_ext_module_loader_info *info, -diff --git a/Lib/importlib/_bootstrap_external.py b/Lib/importlib/_bootstrap_external.py -index 7742855e8b2..d8c61c92558 100644 ---- a/Lib/importlib/_bootstrap_external.py -+++ b/Lib/importlib/_bootstrap_external.py -@@ -1793,14 +1793,14 @@ def _get_supported_file_loaders(): - - Each item is a tuple (loader, suffixes). - """ -- if sys.platform in {"ios", "tvos", "watchos"}: -- extension_loaders = [(AppleFrameworkLoader, [ -- suffix.replace(".so", ".fwork") -- for suffix in _imp.extension_suffixes() -- ])] -- else: -- extension_loaders = [] -- extension_loaders.append((ExtensionFileLoader, _imp.extension_suffixes())) -+ extension_loaders = [] -+ if hasattr(_imp, 'create_dynamic'): -+ if sys.platform in {"ios", "tvos", "watchos"}: -+ extension_loaders = [(AppleFrameworkLoader, [ -+ suffix.replace(".so", ".fwork") -+ for suffix in _imp.extension_suffixes() -+ ])] -+ extension_loaders.append((ExtensionFileLoader, _imp.extension_suffixes())) - source = SourceFileLoader, SOURCE_SUFFIXES - bytecode = SourcelessFileLoader, BYTECODE_SUFFIXES - return extension_loaders + [source, bytecode] -diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2024-08-12-11-19-37.gh-issue-122907.q68096.rst b/Misc/NEWS.d/next/Core_and_Builtins/2024-08-12-11-19-37.gh-issue-122907.q68096.rst -new file mode 100644 -index 00000000000..88c872f4ef4 ---- /dev/null -+++ b/Misc/NEWS.d/next/Core_and_Builtins/2024-08-12-11-19-37.gh-issue-122907.q68096.rst -@@ -0,0 +1,3 @@ -+Building with ``HAVE_DYNAMIC_LOADING`` now works as well as it did in 3.12. -+Existing deficiences will be addressed separately. -+(See https://github.com/python/cpython/issues/122950.) -diff --git a/Python/importdl.c b/Python/importdl.c -index 7c42d37283c..b1a6fcc8223 100644 ---- a/Python/importdl.c -+++ b/Python/importdl.c -@@ -8,6 +8,8 @@ - #include "pycore_pystate.h" - #include "pycore_runtime.h" - -+#include "pycore_importdl.h" -+ - /* ./configure sets HAVE_DYNAMIC_LOADING if dynamic loading of modules is - supported on this platform. configure will then compile and link in one - of the dynload_*.c files, as appropriate. We will call a function in -@@ -15,8 +17,6 @@ - */ - #ifdef HAVE_DYNAMIC_LOADING - --#include "pycore_importdl.h" -- - #ifdef MS_WINDOWS - extern dl_funcptr _PyImport_FindSharedFuncptrWindows(const char *prefix, - const char *shortname, -@@ -28,6 +28,8 @@ extern dl_funcptr _PyImport_FindSharedFuncptr(const char *prefix, - const char *pathname, FILE *fp); - #endif - -+#endif /* HAVE_DYNAMIC_LOADING */ -+ - - /***********************************/ - /* module info to use when loading */ -@@ -205,6 +207,7 @@ _Py_ext_module_loader_info_init_for_core( - return 0; - } - -+#ifdef HAVE_DYNAMIC_LOADING - int - _Py_ext_module_loader_info_init_from_spec( - struct _Py_ext_module_loader_info *p_info, -@@ -226,6 +229,7 @@ _Py_ext_module_loader_info_init_from_spec( - Py_DECREF(filename); - return err; - } -+#endif /* HAVE_DYNAMIC_LOADING */ - - - /********************************/ -@@ -372,6 +376,7 @@ _Py_ext_module_loader_result_apply_error( - /* getting/running the module init function */ - /********************************************/ - -+#ifdef HAVE_DYNAMIC_LOADING - PyModInitFunction - _PyImport_GetModInitFunc(struct _Py_ext_module_loader_info *info, - FILE *fp) -@@ -406,6 +411,7 @@ _PyImport_GetModInitFunc(struct _Py_ext_module_loader_info *info, - - return (PyModInitFunction)exportfunc; - } -+#endif /* HAVE_DYNAMIC_LOADING */ - - int - _PyImport_RunModInitFunc(PyModInitFunction p0, -@@ -513,5 +519,3 @@ _PyImport_RunModInitFunc(PyModInitFunction p0, - p_res->err = &p_res->_err; - return -1; - } -- --#endif /* HAVE_DYNAMIC_LOADING */ -diff --git a/Tools/build/check_extension_modules.py b/Tools/build/check_extension_modules.py -index 7de35b499da..66b2a262e11 100644 ---- a/Tools/build/check_extension_modules.py -+++ b/Tools/build/check_extension_modules.py -@@ -27,6 +27,7 @@ - import sys - import sysconfig - import warnings -+import _imp - - from importlib._bootstrap import _load as bootstrap_load - from importlib.machinery import BuiltinImporter, ExtensionFileLoader, ModuleSpec -@@ -154,6 +155,11 @@ def __init__(self, cross_compiling: bool = False, strict: bool = False): - self.notavailable = [] - - def check(self): -+ if not hasattr(_imp, 'create_dynamic'): -+ logger.warning( -+ ('Dynamic extensions not supported ' -+ '(HAVE_DYNAMIC_LOADING not defined)'), -+ ) - for modinfo in self.modules: - logger.debug("Checking '%s' (%s)", modinfo.name, self.get_location(modinfo)) - if modinfo.state == ModuleState.DISABLED: -@@ -415,6 +421,9 @@ def check_module_import(self, modinfo: ModuleInfo): - logger.error("%s failed to import: %s", modinfo.name, e) - raise - except Exception as e: -+ if not hasattr(_imp, 'create_dynamic'): -+ logger.warning("Dynamic extension '%s' ignored", modinfo.name) -+ return - logger.exception("Importing extension '%s' failed!", modinfo.name) - raise - --- -2.50.0 - diff --git a/interpreters/python/patch/0006-change-var-name-to-avoid-conflict-with-nuttx-unused_.patch b/interpreters/python/patch/0006-change-var-name-to-avoid-conflict-with-nuttx-unused_.patch deleted file mode 100644 index 74665cebb..000000000 --- a/interpreters/python/patch/0006-change-var-name-to-avoid-conflict-with-nuttx-unused_.patch +++ /dev/null @@ -1,169 +0,0 @@ -From 221e92fa16864f8a590091b643fc40050bab163c Mon Sep 17 00:00:00 2001 -From: Tiago Medicci -Date: Wed, 13 Nov 2024 14:20:36 -0300 -Subject: [PATCH 06/14] change var name to avoid conflict with nuttx - unused_data macro - -Signed-off-by: Tiago Medicci ---- - Modules/zlibmodule.c | 42 +++++++++++++++++++++--------------------- - 1 file changed, 21 insertions(+), 21 deletions(-) - -diff --git a/Modules/zlibmodule.c b/Modules/zlibmodule.c -index 034a9420b16..595d4ad32e9 100644 ---- a/Modules/zlibmodule.c -+++ b/Modules/zlibmodule.c -@@ -213,7 +213,7 @@ typedef struct - { - PyObject_HEAD - z_stream zst; -- PyObject *unused_data; -+ PyObject *unused_data_var; - PyObject *unconsumed_tail; - char eof; - bool is_initialised; -@@ -267,8 +267,8 @@ newcompobject(PyTypeObject *type) - self->eof = 0; - self->is_initialised = 0; - self->zdict = NULL; -- self->unused_data = PyBytes_FromStringAndSize("", 0); -- if (self->unused_data == NULL) { -+ self->unused_data_var = PyBytes_FromStringAndSize("", 0); -+ if (self->unused_data_var == NULL) { - Py_DECREF(self); - return NULL; - } -@@ -708,7 +708,7 @@ Dealloc(compobject *self) - { - PyObject *type = (PyObject *)Py_TYPE(self); - PyThread_free_lock(self->lock); -- Py_XDECREF(self->unused_data); -+ Py_XDECREF(self->unused_data_var); - Py_XDECREF(self->unconsumed_tail); - Py_XDECREF(self->zdict); - PyObject_Free(self); -@@ -803,15 +803,15 @@ zlib_Compress_compress_impl(compobject *self, PyTypeObject *cls, - } - - /* Helper for objdecompress() and flush(). Saves any unconsumed input data in -- self->unused_data or self->unconsumed_tail, as appropriate. */ -+ self->unused_data_var or self->unconsumed_tail, as appropriate. */ - static int - save_unconsumed_input(compobject *self, Py_buffer *data, int err) - { - if (err == Z_STREAM_END) { - /* The end of the compressed data has been reached. Store the leftover -- input data in self->unused_data. */ -+ input data in self->unused_data_var. */ - if (self->zst.avail_in > 0) { -- Py_ssize_t old_size = PyBytes_GET_SIZE(self->unused_data); -+ Py_ssize_t old_size = PyBytes_GET_SIZE(self->unused_data_var); - Py_ssize_t new_size, left_size; - PyObject *new_data; - left_size = (Byte *)data->buf + data->len - self->zst.next_in; -@@ -824,10 +824,10 @@ save_unconsumed_input(compobject *self, Py_buffer *data, int err) - if (new_data == NULL) - return -1; - memcpy(PyBytes_AS_STRING(new_data), -- PyBytes_AS_STRING(self->unused_data), old_size); -+ PyBytes_AS_STRING(self->unused_data_var), old_size); - memcpy(PyBytes_AS_STRING(new_data) + old_size, - self->zst.next_in, left_size); -- Py_SETREF(self->unused_data, new_data); -+ Py_SETREF(self->unused_data_var, new_data); - self->zst.avail_in = 0; - } - } -@@ -1091,7 +1091,7 @@ zlib_Compress_copy_impl(compobject *self, PyTypeObject *cls) - zlib_error(state, self->zst, err, "while copying compression object"); - goto error; - } -- Py_XSETREF(return_value->unused_data, Py_NewRef(self->unused_data)); -+ Py_XSETREF(return_value->unused_data_var, Py_NewRef(self->unused_data_var)); - Py_XSETREF(return_value->unconsumed_tail, Py_NewRef(self->unconsumed_tail)); - Py_XSETREF(return_value->zdict, Py_XNewRef(self->zdict)); - return_value->eof = self->eof; -@@ -1176,7 +1176,7 @@ zlib_Decompress_copy_impl(compobject *self, PyTypeObject *cls) - goto error; - } - -- Py_XSETREF(return_value->unused_data, Py_NewRef(self->unused_data)); -+ Py_XSETREF(return_value->unused_data_var, Py_NewRef(self->unused_data_var)); - Py_XSETREF(return_value->unconsumed_tail, Py_NewRef(self->unconsumed_tail)); - Py_XSETREF(return_value->zdict, Py_XNewRef(self->zdict)); - return_value->eof = self->eof; -@@ -1341,7 +1341,7 @@ typedef struct { - z_stream zst; - PyObject *zdict; - PyThread_type_lock lock; -- PyObject *unused_data; -+ PyObject *unused_data_var; - uint8_t *input_buffer; - Py_ssize_t input_buffer_size; - /* zst>avail_in is only 32 bit, so we store the true length -@@ -1367,7 +1367,7 @@ ZlibDecompressor_dealloc(ZlibDecompressor *self) - inflateEnd(&self->zst); - } - PyMem_Free(self->input_buffer); -- Py_CLEAR(self->unused_data); -+ Py_CLEAR(self->unused_data_var); - Py_CLEAR(self->zdict); - PyObject_Free(self); - Py_DECREF(type); -@@ -1602,12 +1602,12 @@ decompress(ZlibDecompressor *self, uint8_t *data, - self->needs_input = 0; - - if (self->avail_in_real > 0) { -- PyObject *unused_data = PyBytes_FromStringAndSize( -+ PyObject *unused_data_var = PyBytes_FromStringAndSize( - (char *)self->zst.next_in, self->avail_in_real); -- if (unused_data == NULL) { -+ if (unused_data_var == NULL) { - goto error; - } -- Py_XSETREF(self->unused_data, unused_data); -+ Py_XSETREF(self->unused_data_var, unused_data_var); - } - } - else if (self->avail_in_real == 0) { -@@ -1671,7 +1671,7 @@ was less than *max_length* bytes, or because *max_length* was negative), - - Attempting to decompress data after the end of stream is reached raises an - EOFError. Any data found after the end of the stream is ignored and saved in --the unused_data attribute. -+the unused_data_var attribute. - [clinic start generated code]*/ - - static PyObject * -@@ -1739,8 +1739,8 @@ ZlibDecompressor__new__(PyTypeObject *cls, - self->zst.zfree = PyZlib_Free; - self->zst.next_in = NULL; - self->zst.avail_in = 0; -- self->unused_data = PyBytes_FromStringAndSize(NULL, 0); -- if (self->unused_data == NULL) { -+ self->unused_data_var = PyBytes_FromStringAndSize(NULL, 0); -+ if (self->unused_data_var == NULL) { - Py_CLEAR(self); - return NULL; - } -@@ -1806,7 +1806,7 @@ static PyMethodDef ZlibDecompressor_methods[] = { - - #define COMP_OFF(x) offsetof(compobject, x) - static PyMemberDef Decomp_members[] = { -- {"unused_data", _Py_T_OBJECT, COMP_OFF(unused_data), Py_READONLY}, -+ {"unused_data_var", _Py_T_OBJECT, COMP_OFF(unused_data_var), Py_READONLY}, - {"unconsumed_tail", _Py_T_OBJECT, COMP_OFF(unconsumed_tail), Py_READONLY}, - {"eof", Py_T_BOOL, COMP_OFF(eof), Py_READONLY}, - {NULL}, -@@ -1824,7 +1824,7 @@ PyDoc_STRVAR(ZlibDecompressor_needs_input_doc, - static PyMemberDef ZlibDecompressor_members[] = { - {"eof", Py_T_BOOL, offsetof(ZlibDecompressor, eof), - Py_READONLY, ZlibDecompressor_eof__doc__}, -- {"unused_data", Py_T_OBJECT_EX, offsetof(ZlibDecompressor, unused_data), -+ {"unused_data_var", Py_T_OBJECT_EX, offsetof(ZlibDecompressor, unused_data_var), - Py_READONLY, ZlibDecompressor_unused_data__doc__}, - {"needs_input", Py_T_BOOL, offsetof(ZlibDecompressor, needs_input), Py_READONLY, - ZlibDecompressor_needs_input_doc}, --- -2.50.0 - diff --git a/interpreters/python/patch/0007-undef-atexit_register.patch b/interpreters/python/patch/0007-undef-atexit_register.patch deleted file mode 100644 index 57bef770f..000000000 --- a/interpreters/python/patch/0007-undef-atexit_register.patch +++ /dev/null @@ -1,31 +0,0 @@ -From 6ebe2333a7862532aa50e7286db9ea8b9df895c4 Mon Sep 17 00:00:00 2001 -From: Tiago Medicci -Date: Wed, 13 Nov 2024 14:22:04 -0300 -Subject: [PATCH 07/14] undef atexit_register - -Even if not built, nuttx/include/nuttx/atexit.h defines it and this -causes conflicts. - -Signed-off-by: Tiago Medicci ---- - Modules/atexitmodule.c | 4 ++++ - 1 file changed, 4 insertions(+) - -diff --git a/Modules/atexitmodule.c b/Modules/atexitmodule.c -index 297a8d74ba3..1fea72fbc99 100644 ---- a/Modules/atexitmodule.c -+++ b/Modules/atexitmodule.c -@@ -175,6 +175,10 @@ Register a function to be executed upon normal program termination\n\ - \n\ - func is returned to facilitate usage as a decorator."); - -+#ifdef atexit_register -+# undef atexit_register -+#endif -+ - static PyObject * - atexit_register(PyObject *module, PyObject *args, PyObject *kwargs) - { --- -2.50.0 - diff --git a/interpreters/python/patch/0008-declare-struct-timeval.patch b/interpreters/python/patch/0008-declare-struct-timeval.patch deleted file mode 100644 index 07c70119b..000000000 --- a/interpreters/python/patch/0008-declare-struct-timeval.patch +++ /dev/null @@ -1,29 +0,0 @@ -From ce41aed2d663d6a7278b83bcdc2dc0adb65b9f5c Mon Sep 17 00:00:00 2001 -From: Tiago Medicci -Date: Wed, 13 Nov 2024 14:23:34 -0300 -Subject: [PATCH 08/14] declare struct timeval - -Otherwise, build will fail due to redefinition of _PyTime_FromTimeval - -Signed-off-by: Tiago Medicci ---- - Include/internal/pycore_time.h | 2 -- - 1 file changed, 2 deletions(-) - -diff --git a/Include/internal/pycore_time.h b/Include/internal/pycore_time.h -index 205ac5d3781..c30e07f4b4a 100644 ---- a/Include/internal/pycore_time.h -+++ b/Include/internal/pycore_time.h -@@ -58,9 +58,7 @@ extern "C" { - #endif - - --#ifdef __clang__ - struct timeval; --#endif - - #define _SIZEOF_PYTIME_T 8 - --- -2.50.0 - diff --git a/interpreters/python/patch/0009-include-nuttx-sys-select-header-to-define-FD_SETSIZE.patch b/interpreters/python/patch/0009-include-nuttx-sys-select-header-to-define-FD_SETSIZE.patch deleted file mode 100644 index 3f7726aeb..000000000 --- a/interpreters/python/patch/0009-include-nuttx-sys-select-header-to-define-FD_SETSIZE.patch +++ /dev/null @@ -1,28 +0,0 @@ -From 682b331c77974ef5f051b39f30f3a5af4f7789d1 Mon Sep 17 00:00:00 2001 -From: Tiago Medicci -Date: Thu, 14 Nov 2024 13:44:49 -0300 -Subject: [PATCH 09/14] include nuttx sys/select header to define FD_SETSIZE - -Signed-off-by: Tiago Medicci ---- - Modules/selectmodule.c | 4 ++++ - 1 file changed, 4 insertions(+) - -diff --git a/Modules/selectmodule.c b/Modules/selectmodule.c -index 5bd9b7732a4..e9fab839122 100644 ---- a/Modules/selectmodule.c -+++ b/Modules/selectmodule.c -@@ -63,6 +63,10 @@ extern void bzero(void *, int); - #include - #endif - -+#ifdef HAVE_SYS_SELECT_H -+#include -+#endif -+ - #ifdef MS_WINDOWS - # ifndef WIN32_LEAN_AND_MEAN - # define WIN32_LEAN_AND_MEAN --- -2.50.0 - diff --git a/interpreters/python/patch/0010-check-for-the-d_ino-member-of-the-structure-dirent.patch b/interpreters/python/patch/0010-check-for-the-d_ino-member-of-the-structure-dirent.patch deleted file mode 100644 index 897a12e77..000000000 --- a/interpreters/python/patch/0010-check-for-the-d_ino-member-of-the-structure-dirent.patch +++ /dev/null @@ -1,195 +0,0 @@ -From 479f4647bf0c5a841af6a916c21fdef1fa1b5cdf Mon Sep 17 00:00:00 2001 -From: Tiago Medicci -Date: Tue, 3 Dec 2024 17:18:50 -0300 -Subject: [PATCH 10/14] check for the d_ino member of the structure dirent - -Signed-off-by: Tiago Medicci ---- - Modules/clinic/posixmodule.c.h | 2 ++ - Modules/posixmodule.c | 18 ++++++++++++-- - configure | 43 ++++++++++++++++++++++++++++++++++ - configure.ac | 5 ++++ - pyconfig.h.in | 3 +++ - 5 files changed, 69 insertions(+), 2 deletions(-) - -diff --git a/Modules/clinic/posixmodule.c.h b/Modules/clinic/posixmodule.c.h -index 14a6efb9ac9..6e716f77db8 100644 ---- a/Modules/clinic/posixmodule.c.h -+++ b/Modules/clinic/posixmodule.c.h -@@ -11652,6 +11652,7 @@ PyDoc_STRVAR(os_DirEntry_inode__doc__, - #define OS_DIRENTRY_INODE_METHODDEF \ - {"inode", (PyCFunction)os_DirEntry_inode, METH_NOARGS, os_DirEntry_inode__doc__}, - -+#ifdef HAVE_DIRENT_D_INO - static PyObject * - os_DirEntry_inode_impl(DirEntry *self); - -@@ -11660,6 +11661,7 @@ os_DirEntry_inode(DirEntry *self, PyObject *Py_UNUSED(ignored)) - { - return os_DirEntry_inode_impl(self); - } -+#endif - - PyDoc_STRVAR(os_DirEntry___fspath____doc__, - "__fspath__($self, /)\n" -diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c -index 51e34b5f4b7..2aa507aa942 100644 ---- a/Modules/posixmodule.c -+++ b/Modules/posixmodule.c -@@ -15522,7 +15522,9 @@ typedef struct { - #ifdef HAVE_DIRENT_D_TYPE - unsigned char d_type; - #endif -+#ifdef HAVE_DIRENT_D_INO - ino_t d_ino; -+#endif - int dir_fd; - #endif - } DirEntry; -@@ -15821,6 +15823,7 @@ os.DirEntry.inode - Return inode of the entry; cached per entry. - [clinic start generated code]*/ - -+#ifdef HAVE_DIRENT_D_INO - static PyObject * - os_DirEntry_inode_impl(DirEntry *self) - /*[clinic end generated code: output=156bb3a72162440e input=3ee7b872ae8649f0]*/ -@@ -15856,6 +15859,7 @@ os_DirEntry_inode_impl(DirEntry *self) - return PyLong_FromUnsignedLongLong(self->d_ino); - #endif - } -+#endif - - static PyObject * - DirEntry_repr(DirEntry *self) -@@ -15892,7 +15896,9 @@ static PyMethodDef DirEntry_methods[] = { - OS_DIRENTRY_IS_SYMLINK_METHODDEF - OS_DIRENTRY_IS_JUNCTION_METHODDEF - OS_DIRENTRY_STAT_METHODDEF -+#ifdef HAVE_DIRENT_D_INO - OS_DIRENTRY_INODE_METHODDEF -+#endif - OS_DIRENTRY___FSPATH___METHODDEF - {"__class_getitem__", Py_GenericAlias, - METH_O|METH_CLASS, PyDoc_STR("See PEP 585")}, -@@ -16043,7 +16049,10 @@ join_path_filename(const char *path_narrow, const char* filename, Py_ssize_t fil - - static PyObject * - DirEntry_from_posix_info(PyObject *module, path_t *path, const char *name, -- Py_ssize_t name_len, ino_t d_ino -+ Py_ssize_t name_len -+#ifdef HAVE_DIRENT_D_INO -+ , ino_t d_ino -+#endif - #ifdef HAVE_DIRENT_D_TYPE - , unsigned char d_type - #endif -@@ -16095,7 +16104,9 @@ DirEntry_from_posix_info(PyObject *module, path_t *path, const char *name, - #ifdef HAVE_DIRENT_D_TYPE - entry->d_type = d_type; - #endif -+#ifdef HAVE_DIRENT_D_INO - entry->d_ino = d_ino; -+#endif - - return (PyObject *)entry; - -@@ -16248,7 +16259,10 @@ ScandirIterator_iternext(ScandirIterator *iterator) - PyObject *module = PyType_GetModule(Py_TYPE(iterator)); - entry = DirEntry_from_posix_info(module, - &iterator->path, direntp->d_name, -- name_len, direntp->d_ino -+ name_len -+#ifdef HAVE_DIRENT_D_INO -+ , direntp->d_ino -+#endif - #ifdef HAVE_DIRENT_D_TYPE - , direntp->d_type - #endif -diff --git a/configure b/configure -index 6da5e9f3832..c89beb7ef6a 100755 ---- a/configure -+++ b/configure -@@ -27746,6 +27746,49 @@ then : - printf "%s\n" "#define HAVE_DIRENT_D_TYPE 1" >>confdefs.h - - -+fi -+ -+# check if the dirent structure of a d_ino is defined -+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if the dirent structure of a d_ino field" >&5 -+printf %s "checking if the dirent structure of a d_ino field... " >&6; } -+if test ${ac_cv_dirent_d_ino+y} -+then : -+ printf %s "(cached) " >&6 -+else $as_nop -+ -+cat confdefs.h - <<_ACEOF >conftest.$ac_ext -+/* end confdefs.h. */ -+ -+ -+ #include -+ -+ int main(void) { -+ struct dirent entry; -+ return entry.d_ino == 0; -+ } -+ -+ -+_ACEOF -+if ac_fn_c_try_link "$LINENO" -+then : -+ ac_cv_dirent_d_ino=yes -+else $as_nop -+ ac_cv_dirent_d_ino=no -+fi -+rm -f core conftest.err conftest.$ac_objext conftest.beam \ -+ conftest$ac_exeext conftest.$ac_ext -+ -+fi -+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_dirent_d_ino" >&5 -+printf "%s\n" "$ac_cv_dirent_d_ino" >&6; } -+ -+if test "x$ac_cv_dirent_d_ino" = xyes -+then : -+ -+ -+printf "%s\n" "#define HAVE_DIRENT_D_INO 1" >>confdefs.h -+ -+ - fi - - # check if the Linux getrandom() syscall is available -diff --git a/configure.ac b/configure.ac -index 80d6738fab5..40f2f950b36 100644 ---- a/configure.ac -+++ b/configure.ac -@@ -7084,6 +7084,11 @@ AS_VAR_IF([ac_cv_dirent_d_type], [yes], [ - [Define to 1 if the dirent structure has a d_type field]) - ]) - -+AS_VAR_IF([ac_cv_dirent_d_ino], [yes], [ -+ AC_DEFINE([HAVE_DIRENT_D_INO], [1], -+ [Define to 1 if the dirent structure has a d_ino field]) -+]) -+ - # check if the Linux getrandom() syscall is available - AC_CACHE_CHECK([for the Linux getrandom() syscall], [ac_cv_getrandom_syscall], [ - AC_LINK_IFELSE( -diff --git a/pyconfig.h.in b/pyconfig.h.in -index 4d8b1d4f254..4a2ba83a872 100644 ---- a/pyconfig.h.in -+++ b/pyconfig.h.in -@@ -277,6 +277,9 @@ - /* Define to 1 if the dirent structure has a d_type field */ - #undef HAVE_DIRENT_D_TYPE - -+/* Define to 1 if the dirent structure has a d_ino field */ -+#undef HAVE_DIRENT_D_INO -+ - /* Define to 1 if you have the header file, and it defines `DIR'. - */ - #undef HAVE_DIRENT_H --- -2.50.0 - diff --git a/interpreters/python/patch/0011-avoid-redefinition-warning-if-UNUSED-is-already-defi.patch b/interpreters/python/patch/0011-avoid-redefinition-warning-if-UNUSED-is-already-defi.patch deleted file mode 100644 index bade882e2..000000000 --- a/interpreters/python/patch/0011-avoid-redefinition-warning-if-UNUSED-is-already-defi.patch +++ /dev/null @@ -1,26 +0,0 @@ -From deadd332eda6355c6598dc9df5f12b34b870d857 Mon Sep 17 00:00:00 2001 -From: Tiago Medicci -Date: Tue, 10 Dec 2024 12:03:47 -0300 -Subject: [PATCH 11/14] avoid redefinition warning if UNUSED is already defined - ---- - Parser/pegen.h | 2 ++ - 1 file changed, 2 insertions(+) - -diff --git a/Parser/pegen.h b/Parser/pegen.h -index 32c64e7774b..42574456f23 100644 ---- a/Parser/pegen.h -+++ b/Parser/pegen.h -@@ -250,7 +250,9 @@ void * _PyPegen_seq_last_item(asdl_seq *seq); - #define PyPegen_last_item(seq, type) ((type)_PyPegen_seq_last_item((asdl_seq*)seq)) - void * _PyPegen_seq_first_item(asdl_seq *seq); - #define PyPegen_first_item(seq, type) ((type)_PyPegen_seq_first_item((asdl_seq*)seq)) -+#ifndef UNUSED - #define UNUSED(expr) do { (void)(expr); } while (0) -+#endif - #define EXTRA_EXPR(head, tail) head->lineno, (head)->col_offset, (tail)->end_lineno, (tail)->end_col_offset, p->arena - #define EXTRA _start_lineno, _start_col_offset, _end_lineno, _end_col_offset, p->arena - PyObject *_PyPegen_new_type_comment(Parser *, const char *); --- -2.50.0 - diff --git a/interpreters/python/patch/0012-hack-place-_PyRuntime-structure-into-PSRAM-bss-regio.patch b/interpreters/python/patch/0012-hack-place-_PyRuntime-structure-into-PSRAM-bss-regio.patch deleted file mode 100644 index 2f4926679..000000000 --- a/interpreters/python/patch/0012-hack-place-_PyRuntime-structure-into-PSRAM-bss-regio.patch +++ /dev/null @@ -1,54 +0,0 @@ -From 70538c2ec3e59df6ce1e767e53908a9cad361f05 Mon Sep 17 00:00:00 2001 -From: Ivan Grokhotkov -Date: Wed, 23 Oct 2024 16:52:52 +0200 -Subject: [PATCH 12/14] hack: place _PyRuntime structure into PSRAM bss region, - initialize later - -_PyRuntime occupies around 100kB of RAM in .data region, making it -hard to fit the interpreter into the available static RAM. -This patch moves it into PSRAM using section attribute. Normally -we shouldn't need this as we can specify placements in ldfragments, -however in this specific case I couldn't get it to work. -Since the structure is now in .bss, add a function which will assign -it the initial value. - -The proper fix might be to support .data segment on PSRAM in IDF, -as well as to fix whatever ldgen issue prevents this variable from -being moved to PSRAM. - -Co-authored-by: Tiago Medicci Serrano ---- - Python/pylifecycle.c | 11 +++++++++++ - 1 file changed, 11 insertions(+) - -diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c -index 1701a1cd217..93aa808bc03 100644 ---- a/Python/pylifecycle.c -+++ b/Python/pylifecycle.c -@@ -102,12 +102,23 @@ __attribute__(( - _PyRuntimeState _PyRuntime - #if defined(__linux__) && (defined(__GNUC__) || defined(__clang__)) - __attribute__ ((section (".PyRuntime"))) -+#elif defined(ESP_PLATFORM) || defined(__NuttX__) -+__attribute__ ((section (".PyRuntime"))) - #endif - = _PyRuntimeState_INIT(_PyRuntime, _Py_Debug_Cookie); - _Py_COMP_DIAG_POP - - static int runtime_initialized = 0; - -+void _PyRuntime_Early_Init(void) { -+#if defined(ESP_PLATFORM) || defined(__NuttX__) -+ // Normally, _PyRuntime is in .data and is initialized by the C runtime. -+ // This function allows us to place it into external RAM .bss section -+ // and initialize it manually, saving some internal RAM. -+ _PyRuntime = (struct pyruntimestate) _PyRuntimeState_INIT(_PyRuntime, _Py_Debug_Cookie); -+#endif -+} -+ - PyStatus - _PyRuntime_Initialize(void) - { --- -2.50.0 - diff --git a/interpreters/python/patch/0013-transform-functions-used-by-NuttX-to-lowercase.patch b/interpreters/python/patch/0013-transform-functions-used-by-NuttX-to-lowercase.patch deleted file mode 100644 index ed03e2c18..000000000 --- a/interpreters/python/patch/0013-transform-functions-used-by-NuttX-to-lowercase.patch +++ /dev/null @@ -1,33 +0,0 @@ -From 954d39ba94e772940486575e35d586ba1cf738e3 Mon Sep 17 00:00:00 2001 -From: Tiago Medicci -Date: Fri, 31 Jan 2025 14:06:21 -0300 -Subject: [PATCH 13/14] transform functions used by NuttX to lowercase - ---- - Include/pylifecycle.h | 10 ++++++++++ - 1 file changed, 10 insertions(+) - -diff --git a/Include/pylifecycle.h b/Include/pylifecycle.h -index de1bcb1d2cb..044780ee188 100644 ---- a/Include/pylifecycle.h -+++ b/Include/pylifecycle.h -@@ -33,6 +33,16 @@ PyAPI_FUNC(void) _Py_NO_RETURN Py_Exit(int); - PyAPI_FUNC(int) Py_Main(int argc, wchar_t **argv); - PyAPI_FUNC(int) Py_BytesMain(int argc, char **argv); - -+#if defined(__NuttX__) -+#define py_bytesmain Py_BytesMain -+#endif -+ -+void _PyRuntime_Early_Init(void); -+ -+#if defined(__NuttX__) -+#define _pyruntime_early_init _PyRuntime_Early_Init -+#endif -+ - /* In pathconfig.c */ - Py_DEPRECATED(3.11) PyAPI_FUNC(void) Py_SetProgramName(const wchar_t *); - Py_DEPRECATED(3.13) PyAPI_FUNC(wchar_t *) Py_GetProgramName(void); --- -2.50.0 - diff --git a/interpreters/python/patch/0014-insert-prefix-to-list_length-to-avoid-symbol-collisi.patch b/interpreters/python/patch/0014-insert-prefix-to-list_length-to-avoid-symbol-collisi.patch deleted file mode 100644 index 4d24a7cba..000000000 --- a/interpreters/python/patch/0014-insert-prefix-to-list_length-to-avoid-symbol-collisi.patch +++ /dev/null @@ -1,44 +0,0 @@ -From e908a9a52806768b7546f6a5808eeba1a7862238 Mon Sep 17 00:00:00 2001 -From: Tiago Medicci -Date: Mon, 21 Jul 2025 12:04:04 -0300 -Subject: [PATCH 14/14] insert prefix to list_length to avoid symbol collision - on NuttX - ---- - Objects/listobject.c | 6 +++--- - 1 file changed, 3 insertions(+), 3 deletions(-) - -diff --git a/Objects/listobject.c b/Objects/listobject.c -index dc9df3c3614..3e5bb33068b 100644 ---- a/Objects/listobject.c -+++ b/Objects/listobject.c -@@ -627,7 +627,7 @@ list_repr(PyObject *self) - } - - static Py_ssize_t --list_length(PyObject *a) -+py_list_length(PyObject *a) - { - return PyList_GET_SIZE(a); - } -@@ -3502,7 +3502,7 @@ static PyMethodDef list_methods[] = { - }; - - static PySequenceMethods list_as_sequence = { -- list_length, /* sq_length */ -+ py_list_length, /* sq_length */ - list_concat, /* sq_concat */ - list_repeat, /* sq_repeat */ - list_item, /* sq_item */ -@@ -3768,7 +3768,7 @@ list_ass_subscript(PyObject* _self, PyObject* item, PyObject* value) - } - - static PyMappingMethods list_as_mapping = { -- list_length, -+ py_list_length, - list_subscript, - list_ass_subscript - }; --- -2.50.0 - diff --git a/interpreters/python/patch/0015-keep-ensurepip-in-stdlib-archive.patch b/interpreters/python/patch/0015-keep-ensurepip-in-stdlib-archive.patch deleted file mode 100644 index a74e892ef..000000000 --- a/interpreters/python/patch/0015-keep-ensurepip-in-stdlib-archive.patch +++ /dev/null @@ -1,25 +0,0 @@ ---- a/Tools/wasm/wasm_assets.py -+++ b/Tools/wasm/wasm_assets.py -@@ -40,7 +40,6 @@ OMIT_FILES = ( - # regression tests - "test/", - # package management -- "ensurepip/", - "venv/", - # other platforms - "_aix_support.py", -@@ -148,6 +147,13 @@ def create_stdlib_zip( - if entry.name.endswith(".py") or entry.is_dir(): - # writepy() writes .pyc files (bytecode). - pzf.writepy(entry, filterfunc=filterfunc) -+ -+ # Preserve ensurepip wheel payloads so `python -m ensurepip` can -+ # bootstrap pip on targets that consume this stdlib zip archive. -+ bundled_wheels = args.srcdir_lib / "ensurepip" / "_bundled" -+ if bundled_wheels.is_dir(): -+ for wheel in sorted(bundled_wheels.glob("*.whl")): -+ pzf.write(wheel, arcname=f"ensurepip/_bundled/{wheel.name}") - - - def detect_extension_modules(args: argparse.Namespace) -> Dict[str, bool]: - diff --git a/interpreters/python/patch/0016-fix-timezone-offset-check-when-time-t-is-unsigned.patch b/interpreters/python/patch/0016-fix-timezone-offset-check-when-time-t-is-unsigned.patch deleted file mode 100644 index 81924297b..000000000 --- a/interpreters/python/patch/0016-fix-timezone-offset-check-when-time-t-is-unsigned.patch +++ /dev/null @@ -1,21 +0,0 @@ ---- a/Modules/timemodule.c -+++ b/Modules/timemodule.c -@@ -1800,15 +1800,15 @@ static int - static const time_t YEAR = (365 * 24 + 6) * 3600; - time_t t; - struct tm p; -- time_t janzone_t, julyzone_t; -+ long long janzone_t, julyzone_t; - char janname[10], julyname[10]; - t = (time((time_t *)0) / YEAR) * YEAR; - _PyTime_localtime(t, &p); - get_zone(janname, 9, &p); -- janzone_t = -get_gmtoff(t, &p); -+ janzone_t = -(long long)get_gmtoff(t, &p); - janname[9] = '\0'; - t += YEAR/2; - _PyTime_localtime(t, &p); - get_zone(julyname, 9, &p); -- julyzone_t = -get_gmtoff(t, &p); -+ julyzone_t = -(long long)get_gmtoff(t, &p); - julyname[9] = '\0'; diff --git a/interpreters/python/patch/0017-stdlib-zip-keep-pydecimal-and-trim-tooling-extras.patch b/interpreters/python/patch/0017-stdlib-zip-keep-pydecimal-and-trim-tooling-extras.patch deleted file mode 100644 index 333bb983a..000000000 --- a/interpreters/python/patch/0017-stdlib-zip-keep-pydecimal-and-trim-tooling-extras.patch +++ /dev/null @@ -1,35 +0,0 @@ ---- a/Tools/wasm/wasm_assets.py -+++ b/Tools/wasm/wasm_assets.py -@@ -47,13 +47,20 @@ - # webbrowser - "antigravity.py", - "webbrowser.py", -- # Pure Python implementations of C extensions -- "_pydecimal.py", -+ # Pure Python implementations of C extensions. -+ # NOTE: keep "_pydecimal.py" so decimal.py can fall back to it when the -+ # _decimal C extension is not built (NuttX targets do not link libmpdec). - "_pyio.py", - # concurrent threading - "concurrent/futures/thread.py", - # Misc unused or large files - "pydoc_data/", -+ # Tooling/REPL extras not needed on a constrained embedded target. -+ "unittest/", -+ "_pyrepl/", -+ "idlelib/", -+ "turtledemo/", -+ "wsgiref/", - ) - - # Synchronous network I/O and protocols are not supported; for example, -@@ -80,7 +87,8 @@ - "_asyncio": ["asyncio/"], - "_curses": ["curses/"], - "_ctypes": ["ctypes/"], -- "_decimal": ["decimal.py"], -+ # decimal.py is intentionally NOT omitted here: it ships a pure-Python -+ # fallback (_pydecimal) used when the _decimal C ext is unavailable. - "_dbm": ["dbm/ndbm.py"], - "_gdbm": ["dbm/gnu.py"], - "_json": ["json/"], diff --git a/interpreters/python/patch/0018-ignore-chmod-on-nuttx-like-wasi.patch b/interpreters/python/patch/0018-ignore-chmod-on-nuttx-like-wasi.patch deleted file mode 100644 index 4e2afb410..000000000 --- a/interpreters/python/patch/0018-ignore-chmod-on-nuttx-like-wasi.patch +++ /dev/null @@ -1,25 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Tiago Medicci -Date: Thu, 7 May 2026 14:00:00 -0300 -Subject: [PATCH] posixmodule: ignore chmod on NuttX like WASI - -NuttX's tmpfs does not implement chstat, so chmod fails with ENOSYS. -Apply the same workaround already used for WASI: silently succeed -when HAVE_CHMOD is not defined. - ---- - Modules/posixmodule.c | 4 ++-- - 1 file changed, 2 insertions(+), 2 deletions(-) - ---- a/Modules/posixmodule.c -+++ b/Modules/posixmodule.c -@@ -3608,8 +3608,8 @@ - #ifdef HAVE_CHMOD - result = chmod(path->narrow, mode); --#elif defined(__wasi__) -- // WASI SDK 15.0 does not support chmod. -+#elif defined(__wasi__) || defined(__NuttX__) -+ // WASI SDK 15.0 and NuttX do not fully support chmod. - // Ignore missing syscall for now. - result = 0; - #else diff --git a/interpreters/python/patch/0019-undef-get_errno-set_errno-to-avoid-nuttx-macro-coll.patch b/interpreters/python/patch/0019-undef-get_errno-set_errno-to-avoid-nuttx-macro-coll.patch deleted file mode 100644 index 905827466..000000000 --- a/interpreters/python/patch/0019-undef-get_errno-set_errno-to-avoid-nuttx-macro-coll.patch +++ /dev/null @@ -1,17 +0,0 @@ ---- a/Modules/_ctypes/callproc.c -+++ b/Modules/_ctypes/callproc.c -@@ -91,6 +91,14 @@ - #include - #endif - -+/* NuttX errno.h defines get_errno() and set_errno(e) as macros. -+ Undef them so that CPython's static functions of the same name -+ in this file compile without conflict. */ -+#ifdef __NuttX__ -+#undef get_errno -+#undef set_errno -+#endif -+ - #ifdef _Py_MEMORY_SANITIZER - #include - #endif diff --git a/interpreters/python/patch/0020-ctypes-skip-pythonapi-on-nuttx.patch b/interpreters/python/patch/0020-ctypes-skip-pythonapi-on-nuttx.patch deleted file mode 100644 index 99ca460d9..000000000 --- a/interpreters/python/patch/0020-ctypes-skip-pythonapi-on-nuttx.patch +++ /dev/null @@ -1,11 +0,0 @@ ---- a/Lib/ctypes/__init__.py -+++ b/Lib/ctypes/__init__.py -@@ -481,6 +481,8 @@ - pythonapi = PyDLL("libpython%d.%d.so" % _sys.version_info[:2]) - elif _sys.platform == "cygwin": - pythonapi = PyDLL("libpython%d.%d.dll" % _sys.version_info[:2]) -+elif _sys.platform == "nuttx": -+ pythonapi = None - else: - pythonapi = PyDLL(None) - diff --git a/interpreters/python/patch/0021-posixmodule-ignore-utime-enosys-on-nuttx.patch b/interpreters/python/patch/0021-posixmodule-ignore-utime-enosys-on-nuttx.patch deleted file mode 100644 index 664d0f174..000000000 --- a/interpreters/python/patch/0021-posixmodule-ignore-utime-enosys-on-nuttx.patch +++ /dev/null @@ -1,16 +0,0 @@ ---- a/Modules/posixmodule.c -+++ b/Modules/posixmodule.c -@@ -6666,6 +6666,13 @@ - } - #endif - -+#if defined(__NuttX__) -+ if (result == -1 && errno == ENOSYS) { -+ /* SmartFS and other NuttX fs do not implement chstat. */ -+ Py_RETURN_NONE; -+ } -+#endif -+ - if (result < 0) { - path_error(path); - return NULL; diff --git a/interpreters/python/python_wrapper.c b/interpreters/python/python_wrapper.c deleted file mode 100644 index be7454514..000000000 --- a/interpreters/python/python_wrapper.c +++ /dev/null @@ -1,204 +0,0 @@ -/**************************************************************************** - * apps/interpreters/python/python_wrapper.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "romfs_cpython_modules.h" - -#include "Python.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* Configuration settings */ - -#ifndef CONFIG_CPYTHON_ROMFS_RAMDEVNO -# define CONFIG_CPYTHON_ROMFS_RAMDEVNO 1 -#endif - -#ifndef CONFIG_CPYTHON_ROMFS_SECTORSIZE -# define CONFIG_CPYTHON_ROMFS_SECTORSIZE 64 -#endif - -#ifndef CONFIG_CPYTHON_ROMFS_MOUNTPOINT -# define CONFIG_CPYTHON_ROMFS_MOUNTPOINT "/usr/local/lib" -#endif - -#ifdef CONFIG_DISABLE_MOUNTPOINT -# error "Mountpoint support is disabled" -#endif - -#ifndef CONFIG_FS_ROMFS -# error "ROMFS support not enabled" -#endif - -#define NSECTORS(b) (((b)+CONFIG_CPYTHON_ROMFS_SECTORSIZE-1)/CONFIG_CPYTHON_ROMFS_SECTORSIZE) -#define STR_RAMDEVNO(m) #m -#define MKMOUNT_DEVNAME(m) "/dev/ram" STR_RAMDEVNO(m) -#define MOUNT_DEVNAME MKMOUNT_DEVNAME(CONFIG_CPYTHON_ROMFS_RAMDEVNO) - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: check_and_mount_romfs - * - * Description: - * Check if the ROMFS is already mounted, and if not, mount it. - * - * Input Parameters: - * None - * - * Returned Value: - * 0 on success, 1 on failure - * - ****************************************************************************/ - -static int check_and_mount_romfs(void) -{ - int ret = OK; - struct boardioc_romdisk_s desc; - FILE *fp; - char line[256]; - int is_mounted = 0; - - /* Check if the device is already mounted */ - - fp = fopen("/proc/fs/mount", "r"); - if (fp == NULL) - { - printf("ERROR: Failed to open /proc/fs/mount\n"); - UNUSED(desc); - return ret = ERROR; - } - - while (fgets(line, sizeof(line), fp)) - { - if (strstr(line, CONFIG_CPYTHON_ROMFS_MOUNTPOINT) != NULL) - { - is_mounted = 1; - break; - } - } - - fclose(fp); - - if (is_mounted) - { - _info("Device is already mounted at %s\n", - CONFIG_CPYTHON_ROMFS_MOUNTPOINT); - UNUSED(desc); - return ret; - } - - /* Create a RAM disk */ - - desc.minor = CONFIG_CPYTHON_ROMFS_RAMDEVNO; /* Minor device number of the ROM disk. */ - desc.nsectors = NSECTORS(romfs_cpython_modules_img_len); /* The number of sectors in the ROM disk */ - desc.sectsize = CONFIG_CPYTHON_ROMFS_SECTORSIZE; /* The size of one sector in bytes */ - desc.image = (FAR uint8_t *)romfs_cpython_modules_img; /* File system image */ - - ret = boardctl(BOARDIOC_ROMDISK, (uintptr_t)&desc); - - if (ret < 0) - { - printf("ERROR: Failed to create RAM disk: %s\n", strerror(errno)); - return 1; - } - - /* Mount the test file system */ - - _info("Mounting ROMFS filesystem at target=%s with source=%s\n", - CONFIG_CPYTHON_ROMFS_MOUNTPOINT, MOUNT_DEVNAME); - - ret = mount(MOUNT_DEVNAME, CONFIG_CPYTHON_ROMFS_MOUNTPOINT, "romfs", - MS_RDONLY, NULL); - if (ret < 0) - { - printf("ERROR: Mount failed: %s\n", strerror(errno)); - return 1; - } - - return 0; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: python_wrapper_main - ****************************************************************************/ - -int main(int argc, FAR char *argv[]) -{ - int ret; - - ret = check_and_mount_romfs(); - if (ret != 0) - { - return ret; - } - - _pyruntime_early_init(); - - setenv("PYTHONHOME", "/usr/local", 1); - - setenv("PYTHON_BASIC_REPL", "1", 1); - - setenv("PYTHONPATH", CONFIG_INTERPRETERS_CPYTHON_PYTHONPATH, 1); - - return py_bytesmain(argc, argv); -} diff --git a/interpreters/python/repack_wheel_add_pyc.py b/interpreters/python/repack_wheel_add_pyc.py deleted file mode 100644 index ba27f7d07..000000000 --- a/interpreters/python/repack_wheel_add_pyc.py +++ /dev/null @@ -1,150 +0,0 @@ -#!/usr/bin/env python3 -# SPDX-License-Identifier: Apache-2.0 -# -# Repack a wheel in-place: compile package/*.py to legacy sibling *.pyc -# (compileall -b: required for zipimport, which does not read PEP 3147 -# __pycache__/ names), remove the .py sources, and rewrite *.dist-info/RECORD. - -from __future__ import annotations - -import argparse -import base64 -import hashlib -import shutil -import subprocess -import sys -import tempfile -import zipfile -from pathlib import Path - - -def wheel_record_hash(data: bytes) -> str: - digest = hashlib.sha256(data).digest() - return base64.urlsafe_b64encode(digest).decode("ascii").rstrip("=") - - -def wheel_has_py_sources(zf: zipfile.ZipFile, package: str) -> bool: - prefix = f"{package}/" - return any(n.startswith(prefix) and n.endswith(".py") for n in zf.namelist()) - - -def wheel_has_legacy_bytecode(zf: zipfile.ZipFile, package: str) -> bool: - return f"{package}/__init__.pyc" in zf.namelist() - - -def strip_py_sources(pkg_dir: Path, package: str) -> int: - """Remove package/**/*.py after sibling legacy *.pyc exists (compileall -b output).""" - removed = 0 - for path in sorted(pkg_dir.rglob("*.py")): - if not path.is_file(): - continue - pyc = path.with_suffix(".pyc") - if not pyc.is_file(): - rel = path.relative_to(pkg_dir) - raise SystemExit( - f"missing legacy .pyc for {package}/{rel.as_posix()}, " - "refusing to delete source" - ) - path.unlink() - removed += 1 - return removed - - -def rebuild_record(root: Path) -> None: - dist_infos = sorted(root.glob("*.dist-info")) - if len(dist_infos) != 1: - raise SystemExit( - f"expected one *.dist-info, got {[p.name for p in dist_infos]}" - ) - di = dist_infos[0] - record_path = di / "RECORD" - record_rel = f"{di.name}/RECORD" - lines: list[str] = [] - for path in sorted(root.rglob("*")): - if not path.is_file(): - continue - rel = path.relative_to(root).as_posix() - if rel == record_rel: - continue - body = path.read_bytes() - lines.append(f"{rel},sha256={wheel_record_hash(body)},{len(body)}") - lines.append(f"{record_rel},,") - record_path.write_text("\n".join(lines) + "\n", encoding="utf-8") - - -def repack(whl_path: Path, *, package: str, force: bool) -> None: - whl_path = whl_path.resolve() - if not whl_path.is_file(): - raise SystemExit(f"missing wheel: {whl_path}") - - with zipfile.ZipFile(whl_path) as zf: - has_py = wheel_has_py_sources(zf, package) - if not has_py: - if not wheel_has_legacy_bytecode(zf, package): - raise SystemExit( - f"repack_wheel_add_pyc: wheel has no {package}/*.py and no " - f"{package}/__init__.pyc (corrupt or old tool output). " - f"Delete the bundled wheel and rebuild." - ) - if not force: - print( - f"repack_wheel_add_pyc: skip ({package} already bytecode-only): " - f"{whl_path.name}" - ) - return - - tmpdir = tempfile.mkdtemp(prefix=f"{package}-whl-pyc-") - try: - root = Path(tmpdir) - with zipfile.ZipFile(whl_path) as zf: - zf.extractall(root) - - pkg_dir = root / package - if not pkg_dir.is_dir(): - raise SystemExit(f"wheel has no {package}/ top-level package") - - subprocess.run( - [sys.executable, "-m", "compileall", "-q", "-f", "-b", str(pkg_dir)], - cwd=str(root), - check=True, - ) - n_py = strip_py_sources(pkg_dir, package) - rebuild_record(root) - - out_path = whl_path.with_suffix(whl_path.suffix + ".tmp") - with zipfile.ZipFile(out_path, "w", compression=zipfile.ZIP_DEFLATED) as out: - for path in sorted(root.rglob("*")): - if path.is_file(): - arcname = path.relative_to(root).as_posix() - out.write(path, arcname) - - out_path.replace(whl_path) - print( - f"repack_wheel_add_pyc: bytecode-only {package} ({n_py} .py removed) -> " - f"{whl_path.name}" - ) - finally: - shutil.rmtree(tmpdir, ignore_errors=True) - - -def main() -> None: - ap = argparse.ArgumentParser(description=__doc__) - ap.add_argument("wheel", type=Path, help="path to .whl (updated in place)") - ap.add_argument( - "-p", - "--package", - default="pip", - help="top-level package directory inside the wheel (default: pip)", - ) - ap.add_argument( - "-f", - "--force", - action="store_true", - help="repack even if the package is already .pyc-only", - ) - args = ap.parse_args() - repack(args.wheel, package=args.package, force=args.force) - - -if __name__ == "__main__": - main() diff --git a/interpreters/quickjs/0001-Disabled-unsupported-feature-on-NuttX.patch b/interpreters/quickjs/0001-Disabled-unsupported-feature-on-NuttX.patch index 950517090..c89c62f20 100644 --- a/interpreters/quickjs/0001-Disabled-unsupported-feature-on-NuttX.patch +++ b/interpreters/quickjs/0001-Disabled-unsupported-feature-on-NuttX.patch @@ -1,16 +1,37 @@ -commit cb2d8c8e6c8e120c6b09830fbb89487ed1048e3c -Author: wenlingyun1 -Date: Mon Nov 11 11:43:56 2024 +0800 +From a3374db7eca1141ec8a3909ff001f52f3e79d905 Mon Sep 17 00:00:00 2001 +From: Huang Qi +Date: Wed, 10 Mar 2021 16:30:13 +0800 +Subject: [PATCH] Disabled unsupported feature on NuttX. - update quickjs patch - - Signed-off-by: wenlingyun1 +N/A +Signed-off-by: Huang Qi +Change-Id: I4ff1793609b752320d64406deec3c0ed9b4da965 +--- + qjs.c | 2 ++ + quickjs-libc.c | 14 +++++++------- + 2 files changed, 9 insertions(+), 7 deletions(-) + +diff --git a/qjs.c b/qjs.c +index 4dd11f8..a35a500 100644 +--- a/qjs.c ++++ b/qjs.c +@@ -448,8 +448,10 @@ int main(int argc, char **argv) + } + } + ++#ifdef CONFIG_BIGNUM + if (load_jscalc) + bignum_ext = 1; ++#endif + + if (trace_memory) { + js_trace_malloc_init(&trace_data); diff --git a/quickjs-libc.c b/quickjs-libc.c -index 141f79f..67f31e8 100644 +index e8b81e9..858703c 100644 --- a/quickjs-libc.c +++ b/quickjs-libc.c -@@ -3695,10 +3695,10 @@ static const JSCFunctionListEntry js_os_funcs[] = { +@@ -3558,10 +3558,10 @@ static const JSCFunctionListEntry js_os_funcs[] = { JS_CFUNC_MAGIC_DEF("setWriteHandler", 2, js_os_setReadHandler, 1 ), JS_CFUNC_DEF("signal", 2, js_os_signal ), OS_FLAG(SIGINT), @@ -25,7 +46,7 @@ index 141f79f..67f31e8 100644 OS_FLAG(SIGTERM), #if !defined(_WIN32) OS_FLAG(SIGQUIT), -@@ -3710,8 +3710,8 @@ static const JSCFunctionListEntry js_os_funcs[] = { +@@ -3573,8 +3573,8 @@ static const JSCFunctionListEntry js_os_funcs[] = { OS_FLAG(SIGCONT), OS_FLAG(SIGSTOP), OS_FLAG(SIGTSTP), @@ -34,277 +55,17 @@ index 141f79f..67f31e8 100644 + // OS_FLAG(SIGTTIN), + // OS_FLAG(SIGTTOU), #endif - JS_CFUNC_DEF("now", 0, js_os_now ), JS_CFUNC_DEF("setTimeout", 2, js_os_setTimeout ), -@@ -3743,7 +3743,7 @@ static const JSCFunctionListEntry js_os_funcs[] = { - JS_CFUNC_MAGIC_DEF("lstat", 1, js_os_stat, 1 ), + JS_CFUNC_DEF("clearTimeout", 1, js_os_clearTimeout ), +@@ -3603,7 +3603,7 @@ static const JSCFunctionListEntry js_os_funcs[] = { + JS_CFUNC_DEF("realpath", 1, js_os_realpath ), JS_CFUNC_DEF("symlink", 2, js_os_symlink ), JS_CFUNC_DEF("readlink", 1, js_os_readlink ), - JS_CFUNC_DEF("exec", 1, js_os_exec ), + // JS_CFUNC_DEF("exec", 1, js_os_exec ), - JS_CFUNC_DEF("getpid", 0, js_os_getpid ), JS_CFUNC_DEF("waitpid", 2, js_os_waitpid ), OS_FLAG(WNOHANG), -commit 33590bf30396733a5f5365feec47f40a73bdfd5a -Author: wenlingyun1 -Date: Tue May 28 11:16:56 2024 +0800 + JS_CFUNC_DEF("pipe", 0, js_os_pipe ), +-- +2.25.1 - add CMakeLists.txt for building qjsc - - VELAPLATFO-30697 - - Change-Id: Idcb98f8b0b3f7b694b381f9f376202938d562048 - Signed-off-by: wenlingyun1 - -diff --git a/CMakeLists.txt b/CMakeLists.txt -new file mode 100644 -index 0000000..0dc6fd5 ---- /dev/null -+++ b/CMakeLists.txt -@@ -0,0 +1,121 @@ -+cmake_minimum_required(VERSION 3.16) -+project(jsc) -+ -+set(CONFIG_LTO y) -+set(prefix "/usr/local") -+ -+set(QUICKJS_DIR ${CMAKE_CURRENT_LIST_DIR}) -+ -+if(CONFIG_DARWIN) -+ set(CONFIG_CLANG y) -+ set(CONFIG_DEFAULT_AR y) -+endif() -+ -+if(CONFIG_WIN32) -+ if(CONFIG_M32) -+ set(CROSS_PREFIX i686-w64-mingw32-) -+ else() -+ set(CROSS_PREFIX x86_64-w64-mingw32-) -+ endif() -+else() -+ set(CROSS_PREFIX) -+endif() -+ -+set(QUICKJS_COMMON_OPT) -+set(QJSC_OPT) -+if(CONFIG_CLANG) -+ set(HOST_CC clang) -+ set(CC ${CROSS_PREFIX}clang) -+ list(APPEND QUICKJS_COMMON_OPT -g -Wall) -+ list(APPEND QUICKJS_COMMON_OPT -Wextra) -+ list(APPEND QUICKJS_COMMON_OPT -Wno-sign-compare) -+ list(APPEND QUICKJS_COMMON_OPT -Wno-missing-field-initializers) -+ list(APPEND QUICKJS_COMMON_OPT -Wundef -Wuninitialized) -+ list(APPEND QUICKJS_COMMON_OPT -Wunused -Wno-unused-parameter) -+ list(APPEND QUICKJS_COMMON_OPT -Wwrite-strings) -+ list(APPEND QUICKJS_COMMON_OPT -Wchar-subscripts -funsigned-char) -+ if(CONFIG_DEFAULT_AR) -+ set(AR ${CROSS_PREFIX}ar) -+ else() -+ if(CONFIG_LTO) -+ set(AR ${CROSS_PREFIX}llvm-ar) -+ else() -+ set(AR ${CROSS_PREFIX}ar) -+ endif() -+ endif() -+else() -+ set(HOST_CC gcc) -+ set(CC ${CROSS_PREFIX}gcc) -+ list(APPEND QUICKJS_COMMON_OPT -g -Wall) -+ list(APPEND QUICKJS_COMMON_OPT -Wno-array-bounds -Wno-format-truncation) -+ if(CONFIG_LTO) -+ set(AR ${CROSS_PREFIX}gcc-ar) -+ else() -+ set(AR ${CROSS_PREFIX}ar) -+ endif() -+endif() -+ -+set(STRIP ${CROSS_PREFIX}strip) -+ -+if(CONFIG_WERROR) -+ list(APPEND QUICKJS_COMMON_OPT -Werror) -+endif() -+ -+set(QUICKJS_COMMON_DEF) -+set(QUICKJS_DEF) -+set(QJSC_DEF) -+list(APPEND QUICKJS_COMMON_DEF -D_GNU_SOURCE -+ -DCONFIG_VERSION=${QUICKJS_VERSION}) -+ -+if(CONFIG_BIGNUM STREQUAL y) -+ list(APPEND QUICKJS_COMMON_DEF -DCONFIG_BIGNUM) -+endif() -+ -+list(APPEND QJSC_OPT -O2) -+ -+if(CONFIG_LTO) -+ list(APPEND CFLAGS_SMALL -flto) -+ list(APPEND QUICKJS_COMMON_OPT -flto) -+ list(APPEND LDFLAGS -flto) -+endif() -+ -+if(CONFIG_PROFILE) -+ list(APPEND CFLAGS -p) -+ list(APPEND LDFLAGS -p) -+endif() -+ -+if(CONFIG_ASAN) -+ list(APPEND CFLAGS -fsanitize=address -fno-omit-frame-pointer) -+ list(APPEND LDFLAGS -fsanitize=address -fno-omit-frame-pointer) -+endif() -+ -+if(CROSS_PREFIX) -+ set(QJSC_CC gcc) -+ set(QJSC ./host-qjsc) -+else() -+ set(QJSC_CC ${CC}) -+ set(QJSC ./qjsc) -+endif() -+ -+list(APPEND QUICKJS_COMMON_OPT -O2) -+ -+list(APPEND QJSC_OPT ${QUICKJS_COMMON_OPT}) -+ -+list(APPEND QUICKJS_DEF ${QUICKJS_COMMON_DEF}) -+ -+list(APPEND QJSC_DEF ${QUICKJS_COMMON_DEF}) -+list(APPEND QJSC_DEF -DCONFIG_LTO -DCONFIG_CC=\"gcc\" -+ -DCONFIG_PREFIX=\"/usr/local\") -+ -+set(QUICKJS_SRC -+ ${QUICKJS_DIR}/quickjs.c -+ ${QUICKJS_DIR}/libbf.c -+ ${QUICKJS_DIR}/libunicode.c -+ ${QUICKJS_DIR}/libregexp.c -+ ${QUICKJS_DIR}/cutils.c -+ ${QUICKJS_DIR}/quickjs-libc.c) -+add_library(quickjs ${QUICKJS_SRC}) -+target_compile_options(quickjs PRIVATE ${QUICKJS_COMMON_OPT}) -+target_compile_definitions(quickjs PRIVATE ${QUICKJS_DEF}) -+ -+include(qjsc.cmake) -diff --git a/qjsc.cmake b/qjsc.cmake -new file mode 100644 -index 0000000..f64fcbe ---- /dev/null -+++ b/qjsc.cmake -@@ -0,0 +1,119 @@ -+cmake_minimum_required(VERSION 3.16) -+project(qjsc) -+set(CONFIG_LTO y) -+set(prefix "/usr/local") -+ -+set(QUICKJS_DIR ${CMAKE_CURRENT_LIST_DIR}/) -+ -+if(CONFIG_DARWIN) -+ set(CONFIG_CLANG y) -+ set(CONFIG_DEFAULT_AR y) -+endif() -+ -+if(CONFIG_WIN32) -+ if(CONFIG_M32) -+ set(CROSS_PREFIX i686-w64-mingw32-) -+ else() -+ set(CROSS_PREFIX x86_64-w64-mingw32-) -+ endif() -+else() -+ set(CROSS_PREFIX) -+endif() -+ -+set(QUICKJS_COMMON_OPT) -+set(QJSC_OPT) -+if(CONFIG_CLANG) -+ set(HOST_CC clang) -+ set(CC ${CROSS_PREFIX}clang) -+ list(APPEND QUICKJS_COMMON_OPT -g -Wall) -+ list(APPEND QUICKJS_COMMON_OPT -Wextra) -+ list(APPEND QUICKJS_COMMON_OPT -Wno-sign-compare) -+ list(APPEND QUICKJS_COMMON_OPT -Wno-missing-field-initializers) -+ list(APPEND QUICKJS_COMMON_OPT -Wundef -Wuninitialized) -+ list(APPEND QUICKJS_COMMON_OPT -Wunused -Wno-unused-parameter) -+ list(APPEND QUICKJS_COMMON_OPT -Wwrite-strings) -+ list(APPEND QUICKJS_COMMON_OPT -Wchar-subscripts -funsigned-char) -+ if(CONFIG_DEFAULT_AR) -+ set(AR ${CROSS_PREFIX}ar) -+ else() -+ if(CONFIG_LTO) -+ set(AR ${CROSS_PREFIX}llvm-ar) -+ else() -+ set(AR ${CROSS_PREFIX}ar) -+ endif() -+ endif() -+else() -+ set(HOST_CC gcc) -+ set(CC ${CROSS_PREFIX}gcc) -+ list(APPEND QUICKJS_COMMON_OPT -g -Wall) -+ list(APPEND QUICKJS_COMMON_OPT -Wno-array-bounds -Wno-format-truncation) -+ if(CONFIG_LTO) -+ set(AR ${CROSS_PREFIX}gcc-ar) -+ else() -+ set(AR ${CROSS_PREFIX}ar) -+ endif() -+endif() -+ -+set(STRIP ${CROSS_PREFIX}strip) -+ -+if(CONFIG_WERROR) -+ list(APPEND QUICKJS_COMMON_OPT -Werror) -+endif() -+ -+set(QUICKJS_COMMON_DEF) -+set(QUICKJS_DEF) -+set(QJSC_DEF) -+list(APPEND QUICKJS_COMMON_DEF -D_GNU_SOURCE -+ -DCONFIG_VERSION=${QUICKJS_VERSION}) -+ -+if(CONFIG_BIGNUM STREQUAL y) -+ list(APPEND QUICKJS_COMMON_DEF -DCONFIG_BIGNUM) -+endif() -+ -+list(APPEND QJSC_OPT -O2) -+ -+if(CONFIG_LTO) -+ list(APPEND CFLAGS_SMALL -flto) -+ list(APPEND QUICKJS_COMMON_OPT -flto) -+ list(APPEND LDFLAGS -flto) -+endif() -+ -+if(CONFIG_PROFILE) -+ list(APPEND CFLAGS -p) -+ list(APPEND LDFLAGS -p) -+endif() -+ -+if(CONFIG_ASAN) -+ list(APPEND CFLAGS -fsanitize=address -fno-omit-frame-pointer) -+ list(APPEND LDFLAGS -fsanitize=address -fno-omit-frame-pointer) -+endif() -+ -+if(CROSS_PREFIX) -+ set(QJSC_CC gcc) -+ set(QJSC ./host-qjsc) -+else() -+ set(QJSC_CC ${CC}) -+ set(QJSC ./qjsc) -+endif() -+ -+list(APPEND QUICKJS_COMMON_OPT -O2) -+ -+list(APPEND QJSC_OPT ${QUICKJS_COMMON_OPT}) -+ -+list(APPEND QUICKJS_DEF ${QUICKJS_COMMON_DEF}) -+ -+list(APPEND QJSC_DEF ${QUICKJS_COMMON_DEF}) -+list(APPEND QJSC_DEF -DCONFIG_LTO -DCONFIG_CC=\"gcc\" -+ -DCONFIG_PREFIX=\"/usr/local\") -+ -+add_executable(qjsc qjsc.c) -+target_compile_options(qjsc PRIVATE ${QJSC_OPT}) -+target_compile_definitions(qjsc PRIVATE ${QJSC_DEF}) -+ -+target_link_options(qjsc PRIVATE -g -flto) -+target_link_libraries(qjsc quickjs) -+ -+if(UNIX) -+ find_package(Threads) -+ target_link_libraries(quickjs ${CMAKE_DL_LIBS} m Threads::Threads) -+endif() diff --git a/interpreters/quickjs/CMakeLists.txt b/interpreters/quickjs/CMakeLists.txt deleted file mode 100644 index e64c2d0c7..000000000 --- a/interpreters/quickjs/CMakeLists.txt +++ /dev/null @@ -1,166 +0,0 @@ -# ############################################################################## -# apps/interpreters/quickjs/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_INTERPRETERS_QUICKJS) - set(QUICKJS_DIR ${CMAKE_CURRENT_LIST_DIR}/quickjs) - - if(NOT EXISTS ${QUICKJS_DIR}) - set(QUICKJS_URL_BASE https://github.com/bellard/quickjs/archive/) - - FetchContent_Declare( - quickjs_fetch - URL ${QUICKJS_URL_BASE}/6e2e68fd0896957f92eb6c242a2e048c1ef3cae0.zip - SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/quickjs BINARY_DIR - ${CMAKE_BINARY_DIR}/apps/interpreters/quickjs/quickjs - PATCH_COMMAND - patch -p1 -d ${CMAKE_CURRENT_LIST_DIR}/quickjs < - ${CMAKE_CURRENT_LIST_DIR}/0001-Disabled-unsupported-feature-on-NuttX.patch - DOWNLOAD_NO_PROGRESS true - TIMEOUT 30) - - FetchContent_GetProperties(quickjs) - - if(NOT quickjs_fetch_POPULATED) - FetchContent_Populate(quickjs_fetch) - endif() - endif() - - set(CMAKE_C_STANDARD 11) - set(CMAKE_CXX_STANDARD 17) - set(CMAKE_CXX_STANDARD_REQUIRED ON) - include(ExternalProject) - - # add quickjs to global INCLUDE DIR - list(APPEND CFLAGS ${INCDIR_PREFIX}$(APPDIR)/interpreters/quickjs) - list(APPEND CXXFLAGS ${INCDIR_PREFIX}$(APPDIR)/interpreters/quickjs) - set_property( - TARGET nuttx - APPEND - PROPERTY NUTTX_INCLUDE_DIRECTORIES ${NUTTX_APPS_DIR}/interpreters/quickjs) - set(QUICKJS_VERSION "\"2024-02-14\"") - set(QUICKJS_FLAGS) - set(QUICKJS_INCDIR) - set(QUICKJS_CSRCS) - set(QUICKJS_SRCS) - - if(CONFIG_INTERPRETERS_QUICKJS_MINI) - list(APPEND QUICKJS_SRCS qjsmini.c) - endif() - - list( - APPEND - QUICKJS_FLAGS - -Wno-shadow - -Wno-array-bounds - -Wno-incompatible-pointer-types - -Wno-implicit-function-declaration - -Wno-unused-function - -Wno-format - -D__linux__ - -DCONFIG_VERSION=${QUICKJS_VERSION} - -include - alloca.h) - - list(APPEND QUICKJS_FLAGS -Dmp_add=qjs_mp_add -Dmp_sub=qjs_mp_sub - -Dmp_mul=qjs_mp_mul) - - list(APPEND QUICKJS_INCDIR ${QUICKJS_DIR}) - - list( - APPEND - QUICKJS_CSRCS - ${QUICKJS_DIR}/quickjs.c - ${QUICKJS_DIR}/libregexp.c - ${QUICKJS_DIR}/libbf.c - ${QUICKJS_DIR}/libunicode.c - ${QUICKJS_DIR}/cutils.c) - - if(CONFIG_ARCH_ARM) - list(APPEND QUICKJS_FLAGS -DFE_TONEAREST=0x00000000) - list(APPEND QUICKJS_FLAGS -DFE_UPWARD=0x00400000) - list(APPEND QUICKJS_FLAGS -DFE_DOWNWARD=0x00800000) - list(APPEND QUICKJS_FLAGS -DFE_TOWARDZERO=0x00c00000) - endif() - - if(CONFIG_INTERPRETERS_QUICKJS_BIGNUM) - list(APPEND QUICKJS_FLAGS -DCONFIG_BIGNUM) - list(APPEND QUICKJS_CSRCS ${CMAKE_CURRENT_BINARY_DIR}/qjscalc.c) - endif() - - if(CONFIG_INTERPRETERS_QUICKJS_FULL) - add_custom_command( - PRE_BUILD - COMMAND ${CMAKE_CURRENT_BINARY_DIR}/qjsc -c -o - ${CMAKE_CURRENT_BINARY_DIR}/repl.c -m ${QUICKJS_DIR}/repl.js - OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/repl.c - DEPENDS qjsc) - add_custom_command( - PRE_BUILD - COMMAND ${CMAKE_CURRENT_BINARY_DIR}/qjsc -fbignum -c -o - ${CMAKE_CURRENT_BINARY_DIR}/qjscalc.c ${QUICKJS_DIR}/qjscalc.js - OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/qjscalc.c - DEPENDS qjsc) - list(APPEND QUICKJS_SRCS ${QUICKJS_DIR}/qjs.c - ${CMAKE_CURRENT_BINARY_DIR}/repl.c) - list(APPEND QUICKJS_CSRCS ${QUICKJS_DIR}/quickjs-libc.c) - endif() - - nuttx_add_library(libqjs) - target_sources(libqjs PRIVATE ${QUICKJS_CSRCS}) - target_include_directories(libqjs PRIVATE ${QUICKJS_INCDIR}) - target_compile_options(libqjs PRIVATE ${QUICKJS_FLAGS}) - nuttx_export_header(TARGET libqjs INCLUDE_DIRECTORIES ${QUICKJS_DIR}) - - if(NOT CONFIG_INTERPRETERS_QUICKJS_NONE) - set(QJS_PRIORITY ${CONFIG_INTERPRETERS_QUICKJS_PRIORITY}) - set(QJS_STACKSIZE ${CONFIG_INTERPRETERS_QUICKJS_STACKSIZE}) - nuttx_add_application( - NAME - qjs - PRIORITY - ${QJS_PRIORITY} - STACKSIZE - ${QJS_STACKSIZE} - SRCS - ${QUICKJS_SRCS} - INCLUDE_DIRECTORIES - ${QUICKJS_INCDIR} - COMPILE_FLAGS - ${QUICKJS_FLAGS} - DEPENDS - libqjs) - endif() - - set(QUICKJS_LIB - ${CMAKE_CURRENT_BINARY_DIR} - CACHE INTERNAL "") - - ExternalProject_Add( - qjsc - SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/quickjs - BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/ - CMAKE_ARGS -DCONFIG_BIGNUM=${CONFIG_INTERPRETERS_QUICKJS_BIGNUM} - -DQUICKJS_VERSION=${QUICKJS_VERSION} -DAPPDIR=${NUTTX_APPS_DIR} - TEST_COMMAND "" - INSTALL_COMMAND "") - -endif() diff --git a/interpreters/quickjs/Kconfig b/interpreters/quickjs/Kconfig index 43a31c055..8969226cc 100644 --- a/interpreters/quickjs/Kconfig +++ b/interpreters/quickjs/Kconfig @@ -9,27 +9,16 @@ config INTERPRETERS_QUICKJS if INTERPRETERS_QUICKJS -choice - prompt "QuickJS command line interpreter" - default INTERPRETERS_QUICKJS_NONE - -config INTERPRETERS_QUICKJS_NONE - bool "Disable quickjs interpreter" - config INTERPRETERS_QUICKJS_MINI - bool "Minimal quickjs interpreter" - -config INTERPRETERS_QUICKJS_FULL - bool "normal quickjs interpreter" - -endchoice # QuickJS command line interpreter + bool "Minimal interpreter" + default n config INTERPRETERS_QUICKJS_BIGNUM bool "Bignum support" default n ---help--- - It's depend on libatomic, - Not all platform support it. + It's depend on libatomic, + Not all platform support it. config INTERPRETERS_QUICKJS_PRIORITY int "QuickJS interpreter priority" @@ -40,11 +29,11 @@ config INTERPRETERS_QUICKJS_STACKSIZE default 8192 config INTERPRETERS_QUICKJS_EXT_HOOK - bool "External init/destroy hook" + bool "External init/destory hook" default n depends on INTERPRETERS_QUICKJS_MINI ---help--- Since minimal interpreter only support 'console.log', - you can export custom module by implement init/destroy hook. + you can export custom module by implement init/destory hook. -endif # INTERPRETERS_QUICKJS +endif diff --git a/interpreters/quickjs/Make.defs b/interpreters/quickjs/Make.defs index 8a39b8523..c12bef231 100644 --- a/interpreters/quickjs/Make.defs +++ b/interpreters/quickjs/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/interpreters/quickjs/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -24,7 +22,9 @@ ifneq ($(CONFIG_INTERPRETERS_QUICKJS),) CONFIGURED_APPS += $(APPDIR)/interpreters/quickjs # It allows `` import. -CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/interpreters/quickjs -CXXFLAGS += ${INCDIR_PREFIX}$(APPDIR)/interpreters/quickjs +CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" \ + $(APPDIR)/interpreters/quickjs} +CXXFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" \ + $(APPDIR)/interpreters/quickjs} endif diff --git a/interpreters/quickjs/Makefile b/interpreters/quickjs/Makefile index 457cdee35..6b1f89a90 100644 --- a/interpreters/quickjs/Makefile +++ b/interpreters/quickjs/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/interpreters/quickjs/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -22,21 +20,25 @@ include $(APPDIR)/Make.defs -QUICKJS_VERSION = 2024-02-14 -QUICKJS_COMMIT_ID = 6e2e68fd0896957f92eb6c242a2e048c1ef3cae0 -QUICKJS_UNPACK = quickjs -QUICKJS_ARCHIVE = $(QUICKJS_COMMIT_ID).zip -QUICKJS_URL = https://github.com/bellard/quickjs/archive/$(QUICKJS_ARCHIVE) +QUICKJS_VERSION = 2020-11-08 +QUICKJS_UNPACK = quickjs +QUICKJS_TARBALL = quickjs-$(QUICKJS_VERSION).tar.xz +QUICKJS_URL_BASE = https://bellard.org/quickjs/ +QUICKJS_URL = $(QUICKJS_URL_BASE)/$(QUICKJS_TARBALL) CSRCS = quickjs.c libregexp.c libbf.c libunicode.c cutils.c +ifeq ($(CONFIG_INTERPRETERS_QUICKJS_MINI),y) +MAINSRC = qjsmini.c +else +CSRCS += quickjs-libc.c repl.c +MAINSRC = qjs.c +endif + VERSION=\"$(QUICKJS_VERSION)\" -CFLAGS += -Dmp_add=qjs_mp_add -Dmp_sub=qjs_mp_sub -Dmp_mul=qjs_mp_mul CFLAGS += -DCONFIG_VERSION=$(VERSION) -Wno-shadow CFLAGS += -Wno-array-bounds -I$(QUICKJS_UNPACK) -CFLAGS += -Wno-strict-prototypes -Wno-unused-variable -CFLAGS += -Wno-unused-but-set-variable CFLAGS += -D__linux__ -include alloca.h CFLAGS += -Wno-incompatible-pointer-types CFLAGS += -Wno-implicit-function-declaration @@ -56,47 +58,36 @@ CSRCS += qjscalc.c endif VPATH += $(QUICKJS_UNPACK) -DEPPATH += --dep-path $(QUICKJS_UNPACK) -ifneq ($(CONFIG_INTERPRETERS_QUICKJS_NONE),y) PROGNAME = qjs PRIORITY = $(CONFIG_INTERPRETERS_QUICKJS_PRIORITY) STACKSIZE = $(CONFIG_INTERPRETERS_QUICKJS_STACKSIZE) MODULE = $(CONFIG_INTERPRETERS_QUICKJS) -endif -$(QUICKJS_ARCHIVE): - $(Q) echo "Downloading $(QUICKJS_ARCHIVE)" - $(Q) curl -L $(QUICKJS_URL) -o quickjs-$(QUICKJS_ARCHIVE) +$(QUICKJS_TARBALL): + $(Q) echo "Downloading $(QUICKJS_TARBALL)" + $(Q) curl -O -L $(QUICKJS_URL) -$(QUICKJS_UNPACK): $(QUICKJS_ARCHIVE) - $(Q) echo "Unpacking quickjs-$(QUICKJS_ARCHIVE) to $(QUICKJS_UNPACK)" - $(Q) unzip -q -o quickjs-$(QUICKJS_ARCHIVE) - $(Q) mv quickjs-$(QUICKJS_COMMIT_ID) $(QUICKJS_UNPACK) +$(QUICKJS_UNPACK): $(QUICKJS_TARBALL) + $(Q) echo "Unpacking $(QUICKJS_TARBALL) to $(QUICKJS_UNPACK)" + $(Q) tar -Jxf $(QUICKJS_TARBALL) + $(Q) mv quickjs-$(QUICKJS_VERSION) $(QUICKJS_UNPACK) $(Q) patch -d $(QUICKJS_UNPACK) -p1 < 0001-Disabled-unsupported-feature-on-NuttX.patch -ifeq ($(CONFIG_INTERPRETERS_QUICKJS_MINI),y) -MAINSRC = qjsmini.c -endif +$(QUICKJS_UNPACK)/.patch: $(QUICKJS_UNPACK) + $(Q) touch $(QUICKJS_UNPACK)/.patch -ifeq ($(CONFIG_INTERPRETERS_QUICKJS_FULL),y) -CSRCS += quickjs-libc.c repl.c -MAINSRC = qjs.c -endif - -# Download and unpack zipball if no archive found -ifeq ($(wildcard $(QUICKJS_UNPACK)/.*),) -ifeq ($(CONFIG_INTERPRETERS_QUICKJS_FULL),y) -context:: $(QUICKJS_UNPACK) - $(MAKE) -C $(QUICKJS_UNPACK) \ +build_host: $(QUICKJS_UNPACK)/.patch + make -C $(QUICKJS_UNPACK) \ CONFIG_BIGNUM=$(CONFIG_INTERPRETERS_QUICKJS_BIGNUM) -else -context:: $(QUICKJS_UNPACK) -endif -endif + +context:: build_host + +clean:: + $(Q) test ! -d $(QUICKJS_UNPACK) || make -C $(QUICKJS_UNPACK) clean distclean:: $(call DELDIR, $(QUICKJS_UNPACK)) - $(call DELFILE, $(QUICKJS_ARCHIVE)) + $(call DELFILE, $(QUICKJS_TARBALL)) include $(APPDIR)/Application.mk diff --git a/interpreters/quickjs/qjsmini.c b/interpreters/quickjs/qjsmini.c index d7932b81c..45f854629 100644 --- a/interpreters/quickjs/qjsmini.c +++ b/interpreters/quickjs/qjsmini.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/interpreters/quickjs/qjsmini.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -374,7 +372,7 @@ uint8_t *js_load_file(JSContext *ctx, size_t *pbuf_len, const char *filename) js_free(ctx, buf); else free(buf); -fail: + fail: fclose(f); return NULL; } @@ -392,8 +390,7 @@ fail: static int js_eval_file(JSContext *ctx, const char *filename, int module) { uint8_t *buf; - int ret; - int eval_flags; + int ret, eval_flags; size_t buf_len; buf = js_load_file(ctx, &buf_len, filename); @@ -485,7 +482,7 @@ int main(int argc, char *argv[]) malloc_usable_size, }; - int argi; + int optind; char *expr = NULL; int dump_memory = 0; int trace_memory = 0; @@ -493,15 +490,15 @@ int main(int argc, char *argv[]) size_t memory_limit = 0; size_t stack_size = 0; - argi = 1; - while (argi < argc && *argv[argi] == '-') + optind = 1; + while (optind < argc && *argv[optind] == '-') { - char *arg = argv[argi] + 1; + char *arg = argv[optind] + 1; const char *longopt = ""; if (!*arg) break; - argi++; + optind++; if (*arg == '-') { longopt = arg + 1; @@ -532,9 +529,9 @@ int main(int argc, char *argv[]) break; } - if (argi < argc) + if (optind < argc) { - expr = argv[argi++]; + expr = argv[optind++]; break; } @@ -562,25 +559,25 @@ int main(int argc, char *argv[]) if (!strcmp(longopt, "memory-limit")) { - if (argi >= argc) + if (optind >= argc) { fprintf(stderr, "expecting memory limit"); exit(1); } - memory_limit = (size_t)strtod(argv[argi++], NULL); + memory_limit = (size_t)strtod(argv[optind++], NULL); continue; } if (!strcmp(longopt, "stack-size")) { - if (argi >= argc) + if (optind >= argc) { fprintf(stderr, "expecting stack size"); exit(1); } - stack_size = (size_t)strtod(argv[argi++], NULL); + stack_size = (size_t)strtod(argv[optind++], NULL); continue; } @@ -645,10 +642,10 @@ int main(int argc, char *argv[]) goto fail; } } - else if (argi < argc) + else if (optind < argc) { const char *filename; - filename = argv[argi]; + filename = argv[optind]; if (js_eval_file(ctx, filename, 1)) { goto fail; diff --git a/interpreters/toywasm/.gitignore b/interpreters/toywasm/.gitignore deleted file mode 100644 index 630c0dfdb..000000000 --- a/interpreters/toywasm/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -toywasm -*.zip diff --git a/interpreters/toywasm/Kconfig b/interpreters/toywasm/Kconfig deleted file mode 100644 index d849f7ac2..000000000 --- a/interpreters/toywasm/Kconfig +++ /dev/null @@ -1,25 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config INTERPRETERS_TOYWASM - tristate "Toywasm Webassembly Runtime" - default n - - # TOYWASM_ENABLE_WASM_THREADS and TOYWASM_ENABLE_WASI_THREADS - # depends on pthread - # REVISIT: make these Kconfig - depends on !DISABLE_PTHREAD - -if INTERPRETERS_TOYWASM - -config INTERPRETERS_TOYWASM_PRIORITY - int "Toywasm cli priority" - default 100 - -config INTERPRETERS_TOYWASM_STACKSIZE - int "Toywasm cil stack size" - default DEFAULT_TASK_STACKSIZE - -endif diff --git a/interpreters/toywasm/Make.defs b/interpreters/toywasm/Make.defs deleted file mode 100644 index 08f1857c5..000000000 --- a/interpreters/toywasm/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/interpreters/toywasm/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_INTERPRETERS_TOYWASM),) -CONFIGURED_APPS += $(APPDIR)/interpreters/toywasm -endif diff --git a/interpreters/toywasm/Makefile b/interpreters/toywasm/Makefile deleted file mode 100644 index e3bff7582..000000000 --- a/interpreters/toywasm/Makefile +++ /dev/null @@ -1,181 +0,0 @@ -############################################################################ -# apps/interpreters/toywasm/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -PROGNAME = toywasm -PRIORITY = $(CONFIG_INTERPRETERS_TOYWASM_PRIORITY) -STACKSIZE = $(CONFIG_INTERPRETERS_TOYWASM_STACKSIZE) -MODULE = $(CONFIG_INTERPRETERS_TOYWASM) - -# cli -MAINSRC = main.c -CSRCS += str_to_uint.c -CSRCS += repl.c - -# lib -CSRCS += bitmap.c -CSRCS += cconv.c -CSRCS += cell.c -CSRCS += context.c -CSRCS += decode.c -CSRCS += dummy_host_func.c -CSRCS += endian.c -CSRCS += escape.c -CSRCS += exec.c -CSRCS += exec_debug.c -CSRCS += exec_insn_subr.c -CSRCS += expr.c -CSRCS += expr_parser.c -CSRCS += fileio.c -CSRCS += host_instance.c -CSRCS += idalloc.c -CSRCS += import_object.c -CSRCS += insn.c -CSRCS += instance.c -CSRCS += leb128.c -CSRCS += list.c -CSRCS += load_context.c -CSRCS += mem.c -CSRCS += module.c -CSRCS += module_writer.c -CSRCS += name.c -CSRCS += nbio.c -CSRCS += options.c -CSRCS += report.c -CSRCS += restart.c -CSRCS += shared_memory.c -CSRCS += slist.c -CSRCS += timeutil.c -CSRCS += toywasm_config.c -CSRCS += type.c -CSRCS += util.c -CSRCS += validation.c -CSRCS += vec.c -CSRCS += xlog.c - -# TOYWASM_ENABLE_WASM_THREADS -CSRCS += cluster.c -CSRCS += lock.c -CSRCS += suspend.c -CSRCS += waitlist.c -#CSRCS += usched.c - -# libwasi -CSRCS += wasi.c -CSRCS += wasi_abi_clock.c -CSRCS += wasi_abi_environ.c -CSRCS += wasi_abi_fd.c -CSRCS += wasi_abi_path.c -CSRCS += wasi_abi_poll.c -CSRCS += wasi_abi_prestat.c -CSRCS += wasi_abi_proc.c -CSRCS += wasi_abi_random.c -CSRCS += wasi_abi_sched.c -CSRCS += wasi_abi_sock.c -CSRCS += wasi_fdinfo.c -CSRCS += wasi_fdtable.c -CSRCS += wasi_host_dirent.c -CSRCS += wasi_host_fdop.c -CSRCS += wasi_host_pathop.c -CSRCS += wasi_host_subr.c -CSRCS += wasi_path_subr.c -CSRCS += wasi_poll_subr.c -CSRCS += wasi_subr.c -CSRCS += wasi_table.c -CSRCS += wasi_uio.c -CSRCS += wasi_vfs.c -CSRCS += wasi_vfs_impl_host.c - -# TOYWASM_ENABLE_WASI_THREADS -CSRCS += wasi_threads.c - -# libwasi_littlefs TOYWASM_ENABLE_WASI_LITTLEFS -#CSRCS += wasi_littlefs.c -#CSRCS += wasi_littlefs_impl.c -#CSRCS += wasi_littlefs_mount.c -#CSRCS += wasi_littlefs_ops.c -#CSRCS += wasi_vfs_impl_littlefs.c -#CSRCS += lfs.c -#CSRCS += lfs_util.c -#toywasm/libwasi_littlefs/littlefs/lfs.c_CFLAGS += -Wno-shadow -#CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/interpreters/toywasm/toywasm/libwasi_littlefs -#CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/interpreters/toywasm/toywasm/libwasi_littlefs/littlefs -#CFLAGS += -DLFS_THREADSAFE -#VPATH += $(TOYWASM_UNPACK)/libwasi_littlefs -#VPATH += $(TOYWASM_UNPACK)/libwasi_littlefs/littlefs - -# TOYWASM_ENABLE_DYLD -CSRCS += dyld.c -CSRCS += dyld_plt.c -CSRCS += dyld_stats.c - -# TOYWASM_ENABLE_DYLD_DLFCN -CSRCS += dyld_dlfcn.c - -ifeq ($(shell $(CC) --version | grep -i clang),) -CFLAGS += -Wno-maybe-uninitialized -endif -CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/interpreters/toywasm/include -CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/interpreters/toywasm/toywasm/lib -CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/interpreters/toywasm/toywasm/libwasi -CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/interpreters/toywasm/toywasm/libwasi_threads -CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/interpreters/toywasm/toywasm/libdyld - -# Keep the compilation parameters consistent with toywasm mainline -# https://github.com/yamt/toywasm/blob/master/cmake/ToywasmConfig.cmake#L298-L302 - -CFLAGS += -Wno-unknown-warning-option -Wno-unused-but-set-variable -Wno-unused-variable -Wno-return-type - -TOYWASM_VERSION = 2e4474d1af3bf9bc5a4b571be7ee69694f4a8aef -TOYWASM_UNPACK = toywasm -TOYWASM_TARBALL = $(TOYWASM_VERSION).zip -TOYWASM_URL_BASE = https://github.com/yamt/toywasm/archive/ -TOYWASM_URL = $(TOYWASM_URL_BASE)/$(TOYWASM_TARBALL) - -VPATH += $(TOYWASM_UNPACK)/cli -VPATH += $(TOYWASM_UNPACK)/lib -VPATH += $(TOYWASM_UNPACK)/libwasi -VPATH += $(TOYWASM_UNPACK)/libwasi_threads -VPATH += $(TOYWASM_UNPACK)/libdyld -VPATH += src - -$(TOYWASM_TARBALL): - $(Q) echo "Downloading $(TOYWASM_TARBALL)" - $(Q) curl -O -L $(TOYWASM_URL) - -$(TOYWASM_UNPACK): $(TOYWASM_TARBALL) - $(Q) echo "Unpacking $(TOYWASM_TARBALL) to $(TOYWASM_UNPACK)" - $(Q) unzip $(TOYWASM_TARBALL) - $(Q) mv toywasm-$(TOYWASM_VERSION) $(TOYWASM_UNPACK) - $(Q) touch $(TOYWASM_UNPACK) - -# Download and unpack tarball if no git repo found -ifeq ($(wildcard $(TOYWASM_UNPACK)/.git),) -context:: $(TOYWASM_UNPACK) - -distclean:: - $(call DELDIR, $(TOYWASM_UNPACK)) - $(call DELFILE, $(TOYWASM_TARBALL)) -endif - -include $(APPDIR)/Application.mk diff --git a/interpreters/toywasm/include/toywasm_config.h b/interpreters/toywasm/include/toywasm_config.h deleted file mode 100644 index 022a0fa58..000000000 --- a/interpreters/toywasm/include/toywasm_config.h +++ /dev/null @@ -1,54 +0,0 @@ -/**************************************************************************** - * apps/interpreters/toywasm/include/toywasm_config.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#if !defined(_TOYWASM_CONFIG_H) -#define _TOYWASM_CONFIG_H - -#define TOYWASM_USE_SEPARATE_EXECUTE -#define TOYWASM_USE_TAILCALL -#define TOYWASM_SORT_EXPORTS -#define TOYWASM_USE_JUMP_BINARY_SEARCH -#define TOYWASM_JUMP_CACHE2_SIZE 4 -#define TOYWASM_USE_LOCALS_FAST_PATH -#define TOYWASM_USE_LOCALS_CACHE -#define TOYWASM_USE_SEPARATE_LOCALS -#define TOYWASM_USE_SMALL_CELLS -#define TOYWASM_USE_RESULTTYPE_CELLIDX -#define TOYWASM_USE_LOCALTYPE_CELLIDX -#define TOYWASM_ENABLE_HEAP_TRACKING -#define TOYWASM_ENABLE_HEAP_TRACKING_PEAK -#define TOYWASM_ENABLE_WRITER -#define TOYWASM_ENABLE_WASM_SIMD -#define TOYWASM_ENABLE_WASM_EXCEPTION_HANDLING -#define TOYWASM_EXCEPTION_MAX_CELLS 4 -#define TOYWASM_ENABLE_WASM_EXTENDED_CONST -#define TOYWASM_ENABLE_WASM_MULTI_MEMORY -#define TOYWASM_ENABLE_WASM_TAILCALL -#define TOYWASM_ENABLE_WASM_THREADS -#define TOYWASM_ENABLE_WASM_CUSTOM_PAGE_SIZES -#define TOYWASM_ENABLE_WASM_NAME_SECTION -#define TOYWASM_ENABLE_WASI -#define TOYWASM_ENABLE_WASI_THREADS -#define TOYWASM_ENABLE_DYLD -#define TOYWASM_ENABLE_DYLD_DLFCN - -#endif /* !defined(_TOYWASM_CONFIG_H) */ diff --git a/interpreters/toywasm/include/toywasm_version.h b/interpreters/toywasm/include/toywasm_version.h deleted file mode 100644 index b0a0ea3e8..000000000 --- a/interpreters/toywasm/include/toywasm_version.h +++ /dev/null @@ -1,28 +0,0 @@ -/**************************************************************************** - * apps/interpreters/toywasm/include/toywasm_version.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#if !defined(_TOYWASM_VERSION_H) -#define _TOYWASM_VERSION_H - -#define TOYWASM_VERSION "v67.0.0" - -#endif /* !defined(_TOYWASM_VERSION_H) */ diff --git a/interpreters/toywasm/regen.sh b/interpreters/toywasm/regen.sh deleted file mode 100755 index 927666be6..000000000 --- a/interpreters/toywasm/regen.sh +++ /dev/null @@ -1,68 +0,0 @@ -#! /bin/sh -############################################################################ -# apps/interpreters/toywasm/regen.sh -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -# A script to generate a few files for nuttx-apps build. - -REPO=https://github.com/yamt/toywasm -REF=${REF:-master} - -TMP=$(mktemp -d) -trap "rm -rf ${TMP}" 0 -DIR="${TMP}/src" -BUILDDIR="${TMP}/build" - -mkdir -p ${DIR} -git -C ${DIR} init -git -C ${DIR} fetch --tags ${REPO} ${REF} -git -C ${DIR} checkout FETCH_HEAD - -# Note: for this build, TOYWASM_USE_SHORT_ENUMS is only used for -# the "toywasm --version" output. - -cmake -B ${BUILDDIR} \ --DTOYWASM_USE_SHORT_ENUMS=OFF \ --DTOYWASM_ENABLE_WASM_EXCEPTION_HANDLING=ON \ --DTOYWASM_ENABLE_WASM_EXTENDED_CONST=ON \ --DTOYWASM_ENABLE_WASM_MULTI_MEMORY=ON \ --DTOYWASM_ENABLE_WASM_TAILCALL=ON \ --DTOYWASM_ENABLE_WASM_CUSTOM_PAGE_SIZES=ON \ --DTOYWASM_ENABLE_WASM_THREADS=ON \ --DTOYWASM_ENABLE_WASI_THREADS=ON \ --DTOYWASM_ENABLE_DYLD=ON \ --DTOYWASM_ENABLE_DYLD_DLFCN=ON \ -${DIR} - -for fn in \ - include/toywasm_config.h \ - include/toywasm_version.h \ - src/toywasm_config.c; do - - (m4 -DFILENAME=$fn tmpl/license.in - case ${fn} in - *.c) - cat tmpl/c-sections.in - ;; - esac - # remove comments to appease nxstyle - sed -e '/^\/\*/d' ${BUILDDIR}/$(basename $fn)) > ${fn} -done diff --git a/interpreters/toywasm/src/toywasm_config.c b/interpreters/toywasm/src/toywasm_config.c deleted file mode 100644 index 2877e824c..000000000 --- a/interpreters/toywasm/src/toywasm_config.c +++ /dev/null @@ -1,70 +0,0 @@ -/**************************************************************************** - * apps/interpreters/toywasm/src/toywasm_config.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -const char *const toywasm_config_string = -"TOYWASM_USE_SEPARATE_EXECUTE = ON\n" -"TOYWASM_USE_SEPARATE_VALIDATE = OFF\n" -"TOYWASM_USE_TAILCALL = ON\n" -"TOYWASM_FORCE_USE_TAILCALL = OFF\n" -"TOYWASM_USE_SIMD = OFF\n" -"TOYWASM_USE_SHORT_ENUMS = OFF\n" -"TOYWASM_USE_USER_SCHED = OFF\n" -"TOYWASM_ENABLE_TRACING = OFF\n" -"TOYWASM_ENABLE_TRACING_INSN = OFF\n" -"TOYWASM_SORT_EXPORTS = ON\n" -"TOYWASM_USE_JUMP_BINARY_SEARCH = ON\n" -"TOYWASM_USE_JUMP_CACHE = OFF\n" -"TOYWASM_JUMP_CACHE2_SIZE = 4\n" -"TOYWASM_USE_LOCALS_FAST_PATH = ON\n" -"TOYWASM_USE_LOCALS_CACHE = ON\n" -"TOYWASM_USE_SEPARATE_LOCALS = ON\n" -"TOYWASM_USE_SMALL_CELLS = ON\n" -"TOYWASM_USE_RESULTTYPE_CELLIDX = ON\n" -"TOYWASM_USE_LOCALTYPE_CELLIDX = ON\n" -"TOYWASM_PREALLOC_SHARED_MEMORY = OFF\n" -"TOYWASM_ENABLE_HEAP_TRACKING = ON\n" -"TOYWASM_ENABLE_HEAP_TRACKING_PEAK = ON\n" -"TOYWASM_ENABLE_WRITER = ON\n" -"TOYWASM_MAINTAIN_EXPR_END = OFF\n" -"TOYWASM_ENABLE_WASM_EXCEPTION_HANDLING = ON\n" -"TOYWASM_EXCEPTION_MAX_CELLS = 4\n" -"TOYWASM_ENABLE_WASM_SIMD = ON\n" -"TOYWASM_ENABLE_WASM_EXTENDED_CONST = ON\n" -"TOYWASM_ENABLE_WASM_MULTI_MEMORY = ON\n" -"TOYWASM_ENABLE_WASM_TAILCALL = ON\n" -"TOYWASM_ENABLE_WASM_THREADS = ON\n" -"TOYWASM_ENABLE_WASM_CUSTOM_PAGE_SIZES = ON\n" -"TOYWASM_ENABLE_WASM_NAME_SECTION = ON\n" -"TOYWASM_ENABLE_WASI = ON\n" -"TOYWASM_ENABLE_WASI_THREADS = ON\n" -"TOYWASM_ENABLE_WASI_LITTLEFS = OFF\n" -"TOYWASM_ENABLE_LITTLEFS_STATS = OFF\n" -"TOYWASM_ENABLE_DYLD = ON\n" -"TOYWASM_ENABLE_DYLD_DLFCN = ON\n"; diff --git a/interpreters/toywasm/tmpl/c-sections.in b/interpreters/toywasm/tmpl/c-sections.in deleted file mode 100644 index 46a331512..000000000 --- a/interpreters/toywasm/tmpl/c-sections.in +++ /dev/null @@ -1,8 +0,0 @@ -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - diff --git a/interpreters/wamr/.gitignore b/interpreters/wamr/.gitignore index 2a85b17bf..0cb73d0fd 100644 --- a/interpreters/wamr/.gitignore +++ b/interpreters/wamr/.gitignore @@ -1,5 +1,3 @@ *.zip wamr wasm-micro-runtime-* -wamr_external_module_list.h -wamr_external_module_proto.h diff --git a/interpreters/wamr/CMakeLists.txt b/interpreters/wamr/CMakeLists.txt deleted file mode 100644 index f155e61bf..000000000 --- a/interpreters/wamr/CMakeLists.txt +++ /dev/null @@ -1,95 +0,0 @@ -# ############################################################################## -# apps/interpreters/wamr/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_INTERPRETERS_WAMR) - - # ############################################################################ - # Config and Fetch lib - # ############################################################################ - - set(WAMR_DIR ${CMAKE_CURRENT_LIST_DIR}/wamr) - - if(NOT EXISTS ${WAMR_DIR}) - set(WAMR_URL_BASE - https://github.com/bytecodealliance/wasm-micro-runtime/archive/) - - FetchContent_Declare( - wamr_fetch - URL ${WAMR_URL_BASE}/${CONFIG_INTERPRETERS_WAMR_VERSION}.zip SOURCE_DIR - ${CMAKE_CURRENT_LIST_DIR}/wamr BINARY_DIR - ${CMAKE_BINARY_DIR}/apps/interpreters/wamr/wamr - DOWNLOAD_NO_PROGRESS true - TIMEOUT 30) - - FetchContent_GetProperties(wamr_fetch) - - if(NOT wamr_fetch_POPULATED) - FetchContent_Populate(wamr_fetch) - endif() - endif() - - nuttx_add_library(wamr STATIC) - - set_property( - TARGET nuttx - APPEND - PROPERTY NUTTX_INCLUDE_DIRECTORIES - ${CMAKE_CURRENT_SOURCE_DIR}/wamr/core/iwasm/include) - - include(${WAMR_DIR}/product-mini/platforms/nuttx/CMakeLists.txt) - target_sources(wamr PRIVATE ${WAMR_SOURCES}) - target_compile_options(wamr PRIVATE ${WAMR_CFLAGS}) - # the WAMR_INCDIRS and WAMR_DEFINITIONS already exist in the directory domain - nuttx_add_application( - MODULE - ${CONFIG_INTERPRETERS_WAMR} - NAME - iwasm - STACKSIZE - ${CONFIG_INTERPRETERS_WAMR_STACKSIZE} - PRIORITY - ${CONFIG_INTERPRETERS_WAMR_PRIORITY} - SRCS - ${WAMR_DIR}/product-mini/platforms/nuttx/main.c - COMPILE_FLAGS - ${WAMR_CFLAGS} - DEFINITIONS - ${WAMR_DEFINITIONS} - INCLUDE_DIRECTORIES - ${WAMR_INCDIRS} - DEPENDS - wamr) - - if(CONFIG_INTERPRETERS_WAMR_LIBC_NUTTX - OR CONFIG_INTERPRETERS_WAMR_EXTERNAL_MODULE_REGISTRY) - nuttx_append_source_file_properties( - ${WAMR_DIR}/product-mini/platforms/nuttx/main.c COMPILE_FLAGS - -Dwasm_runtime_full_init=wamr_custom_init) - target_sources(wamr PRIVATE wamr_custom_init.c) - endif() - - # Add ${CMAKE_BINARY_DIR}/wamrmod to the include directories - if(CONFIG_INTERPRETERS_WAMR_EXTERNAL_MODULE_REGISTRY) - target_include_directories(wamr PRIVATE ${CMAKE_BINARY_DIR}/wamrmod) - endif() - -endif() diff --git a/interpreters/wamr/Kconfig b/interpreters/wamr/Kconfig index 3811d5381..b7a3a5b2a 100644 --- a/interpreters/wamr/Kconfig +++ b/interpreters/wamr/Kconfig @@ -11,9 +11,9 @@ if INTERPRETERS_WAMR config INTERPRETERS_WAMR_VERSION string "WAMR Version" - default "WAMR-2.1.0" + default "04-15-2021" ---help--- - Version WAMR-09-29-2020 and later (include main) supported. + Version 09-29-2020 and later (include main) supported. config INTERPRETERS_IWASM_TASK bool "Webassembly iwasm task" @@ -29,37 +29,10 @@ config INTERPRETERS_WAMR_STACKSIZE int "Webassembly Micro Runtime stack size" default 8192 -endif # INTERPRETERS_IWASM_TASK +endif config INTERPRETERS_WAMR_AOT bool "Enable AOT" - select ARCH_USE_TEXT_HEAP if ARCH_HAVE_TEXT_HEAP - default n - -config INTERPRETERS_WAMR_AOT_QUICK_ENTRY - bool "Enable AOT quick entry" - default n - depends on INTERPRETERS_WAMR_AOT - ---help--- - Note: This option only works with WAMR 1.3.1 or later. - Enable AOT quick entry to improve performance for call - AOTed function from host side in some cases with simple - signature. - Enable this option will increase the size of runtime, ~8KB. - -config INTERPRETERS_WAMR_AOT_STACK_FRAME - bool "Enable AOT stack frame" - default n - depends on INTERPRETERS_WAMR_AOT - -config INTERPRETERS_WAMR_AOT_WORD_ALIGN_READ - bool "Make WAMR AOT loader use word-aligned read" - default y if ARCH_HAVE_TEXT_HEAP_WORD_ALIGNED_READ - default n - -config INTERPRETERS_WAMR_MEM_DUAL_BUS_MIRROR - bool "Make WAMR AOT loader aware of separate instruction/data memory mapping" - default y if ARCH_HAVE_TEXT_HEAP_SEPARATE_DATA_ADDRESS default n choice @@ -75,23 +48,7 @@ config INTERPRETERS_WAMR_CLASSIC config INTERPRETERS_NONE bool "Disable interpreter" -endchoice # Enable interpreter - -config INTERPRETERS_WAMR_DEBUG_AOT - bool "Enable debugger support for AOT modules" - default n - depends on INTERPRETERS_WAMR_AOT - -config INTERPRETERS_WAMR_DEBUG_INTERP - bool "Enable debugger support in the interpreter" - default n - # Note: It only works with the classic interpreter - depends on INTERPRETERS_WAMR_CLASSIC - # Note: It uses thread-manager internally - depends on INTERPRETERS_WAMR_THREAD_MGR - # Note: It sets up the listening socket with SO_LINGER - depends on NET_TCP - depends on NET_SOLINGER +endchoice config INTERPRETERS_WAMR_LOG bool "Enable log" @@ -101,24 +58,6 @@ config INTERPRETERS_WAMR_LIBC_BUILTIN bool "Enable built-in libc" default n -config INTERPRETERS_WAMR_BUILD_MODULES_FOR_NUTTX - bool "Build WASM modules for NuttX system interface (Experimental)" - default n - depends on INTERPRETERS_WAMR_LIBC_BUILTIN - -config INTERPRETERS_WAMR_LIBC_WASI - bool "Enable WASI libc" - select PSEUDOFS_SOFTLINKS - default n - ---help--- - Note: As of writing this, this works only with main branch of - wasm-micro-runtime. - I.e. INTERPRETERS_WAMR_VERSION="main" - - Note: As of writing this, most of the filesystem operations are - not implemented. (Mainly because of lack of openat family of - the API in NuttX.) - config INTERPRETERS_WAMR_MULTI_MODULE bool "Enable multi module support" default n @@ -127,60 +66,14 @@ config INTERPRETERS_WAMR_MINILOADER bool "Enable mini-loader" default n ---help--- - Mini-loader don't check the integrity of wasm module - -config INTERPRETERS_WAMR_REF_TYPES - bool "Enable reference types support" - default n - -config INTERPRETERS_WAMR_GC - bool "Enable GC support" - default n - -config INTERPRETERS_WAMR_ENABLE_SPEC_TEST - bool "Enable spectest support" - default n - -config INTERPRETERS_WAMR_TAIL_CALL - bool "Enable tail call support" - default n - ---help--- - This only available for WAMR 1.3.0 later (don't include 1.3.0) - -config INTERPRETERS_WAMR_STACK_GUARD_SIZE - int "Custom stack guard size" - default 1024 - ---help--- - Reserve some space in stack as guard to detect stack overflow. - - Please consider this extra stack consumption when deciding the stack - size of your NuttX task on which you run WAMR. - - The default value here (1024) was chosen to match the default value on - the majority of other platforms, including Linux. It also matches - the expections in the WAMR AoT compiler. - On the other hand, it might be a bit larger than what's strictly - necessary, especially for typical NuttX targets. + Mini-loader don't check the integrity of wasm module config INTERPRETERS_WAMR_THREAD_MGR bool "Enable thread manager" default n -config INTERPRETERS_WAMR_LIB_WASI_THREADS - bool "Enable wasi-threads" - default n - ---help--- - See https://github.com/bytecodealliance/wasm-micro-runtime/blob/main/doc/pthread_impls.md - config INTERPRETERS_WAMR_LIB_PTHREAD - bool "Enable lib pthread (legacy)" - default n - ---help--- - See https://github.com/bytecodealliance/wasm-micro-runtime/blob/main/doc/pthread_impls.md - -config INTERPRETERS_WAMR_LIB_PTHREAD_SEMAPHORE - bool "Enable semaphore" - depends on INTERPRETERS_WAMR_LIB_PTHREAD + bool "Enable lib pthread" default n config INTERPRETERS_WAMR_SHARED_MEMORY @@ -191,14 +84,6 @@ config INTERPRETERS_WAMR_BULK_MEMORY bool "Enable bluk memory" default n -config INTERPRETERS_WAMR_ENABLE_EXCE_HANDLING - bool "Enable exception-handling" - default n - -config INTERPRETERS_WAMR_PERF_PROFILING - bool "Enable performance profiling" - default n - config INTERPRETERS_WAMR_MEMORY_PROFILING bool "Enable memory profiling" default n @@ -207,21 +92,8 @@ config INTERPRETERS_WAMR_MEMORY_TRACING bool "Enable memory tracing" default n -config INTERPRETERS_WAMR_DUMP_CALL_STACK - bool "Enable dump call stack (on exception)" - default n - config INTERPRETERS_WAMR_DISABLE_HW_BOUND_CHECK bool "Disable hardware bound check" - default y - ---help--- - This option is currently a no-op because - NuttX doesn't have necessary functionalities. - That is, regardless of this setting, WAMR's HW bounds - check is not available for NuttX. - -config INTERPRETERS_WAMR_LOAD_CUSTOM_SECTIONS - bool "Enable load custom section support" default n config INTERPRETERS_WAMR_CUSTOM_NAME_SECTIONS @@ -238,22 +110,6 @@ config INTERPRETERS_WAMR_GLOBAL_HEAP_POOL_SIZE int "Global heap pool size (in KB)" default 128 -endif # INTERPRETERS_WAMR_GLOBAL_HEAP_POOL - -config INTERPRETERS_WAMR_CONFIGUABLE_BOUNDS_CHECKS - bool "Configuable bounds checks" - default n - ---help--- - Bounds checks enabled by default. With this option, you can - disable bounds checks passing --disable-bounds-checks to - iwasm. - -config INTERPRETERS_WAMR_EXTERNAL_MODULE_REGISTRY - bool "Enable external module registry" - default n - ---help--- - This option enables the support for loading WASM modules from - external libraries, which is useful when you want to extend the - functionality of WAMR without modifying its source code. +endif endif diff --git a/interpreters/wamr/Make.defs b/interpreters/wamr/Make.defs index a7e45544b..020696af7 100644 --- a/interpreters/wamr/Make.defs +++ b/interpreters/wamr/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/interpreters/wamr/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -23,7 +21,9 @@ ifneq ($(CONFIG_INTERPRETERS_WAMR),) CONFIGURED_APPS += $(APPDIR)/interpreters/wamr -CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/interpreters/wamr/wamr/core/iwasm/include -CXXFLAGS += ${INCDIR_PREFIX}$(APPDIR)/interpreters/wamr/wamr/core/iwasm/include +CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" \ + $(APPDIR)/interpreters/wamr/wamr/core/iwasm/include} +CXXFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" \ + $(APPDIR)/interpreters/wamr/wamr/core/iwasm/include} endif diff --git a/interpreters/wamr/Makefile b/interpreters/wamr/Makefile index 4e78fa7bd..95eeb9f88 100644 --- a/interpreters/wamr/Makefile +++ b/interpreters/wamr/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/interpreters/wamr/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -25,14 +23,22 @@ include $(APPDIR)/Make.defs WAMR_VERSION = $(patsubst "%",%,$(strip $(CONFIG_INTERPRETERS_WAMR_VERSION))) WAMR_UNPACK = wamr -WAMR_TARBALL = $(WAMR_VERSION).zip +# Tarball of main branch and tagged release have little difference +# in name after unpack and URL + +ifeq ($(WAMR_VERSION), main) +WAMR_VERSION_STUB = +else +WAMR_VERSION_STUB = WAMR- +endif + +WAMR_TARBALL = $(WAMR_VERSION_STUB)$(WAMR_VERSION).zip WAMR_URL_BASE = https://github.com/bytecodealliance/wasm-micro-runtime/archive/ WAMR_URL = $(WAMR_URL_BASE)/$(WAMR_TARBALL) -include $(WAMR_UNPACK)/product-mini/platforms/nuttx/wamr.mk VPATH += $(WAMR_UNPACK)/product-mini/platforms/nuttx -DEPPATH += --dep-path $(WAMR_UNPACK)/product-mini/platforms/nuttx ifeq ($(CONFIG_INTERPRETERS_IWASM_TASK),y) MAINSRC = main.c @@ -41,23 +47,6 @@ PROGNAME = iwasm PRIORITY = $(CONFIG_INTERPRETERS_WAMR_PRIORITY) STACKSIZE = $(CONFIG_INTERPRETERS_WAMR_STACKSIZE) MODULE = $(CONFIG_INTERPRETERS_WAMR) - -endif - -WAMR_NEED_CUSTOM_INIT = n - -# Check if we need to build custom init code - -ifeq ($(CONFIG_INTERPRETERS_WAMR_EXTERNAL_MODULE_REGISTRY),y) -WAMR_NEED_CUSTOM_INIT = y -endif - -# If we need custom init code, add it to the build -ifeq ($(WAMR_NEED_CUSTOM_INIT),y) -# When the loadable module configuration is enabled,we need to use CELFFLAGS -$(WAMR_UNPACK)/product-mini/platforms/nuttx/main.c_CFLAGS = -Dwasm_runtime_full_init=wamr_custom_init -$(WAMR_UNPACK)/product-mini/platforms/nuttx/main.c_CELFFLAGS = -Dwasm_runtime_full_init=wamr_custom_init -CSRCS += wamr_custom_init.c endif $(WAMR_TARBALL): @@ -67,55 +56,13 @@ $(WAMR_TARBALL): $(WAMR_UNPACK): $(WAMR_TARBALL) $(Q) echo "Unpacking $(WAMR_TARBALL) to $(WAMR_UNPACK)" $(Q) unzip $(WAMR_TARBALL) - $(Q) mv wasm-micro-runtime-$(WAMR_VERSION) $(WAMR_UNPACK) + $(Q) mv wasm-micro-runtime-$(WAMR_VERSION_STUB)$(WAMR_VERSION) $(WAMR_UNPACK) $(Q) touch $(WAMR_UNPACK) -# Register the external WAMR module - -ifeq ($(CONFIG_INTERPRETERS_WAMR_EXTERNAL_MODULE_REGISTRY),y) - -PDATLIST = $(strip $(call RWILDCARD, registry, *.pdat)) -BDATLIST = $(strip $(call RWILDCARD, registry, *.bdat)) - -registry$(DELIM).updated: - $(Q) touch registry$(DELIM).updated - -wamr_external_module_list.h: registry$(DELIM).updated -ifeq ($(BDATLIST),) - $(call DELFILE, wamr_external_module_list.h) - $(Q) touch wamr_external_module_list.h -else - $(call CATFILE, wamr_external_module_list.h, $(BDATLIST)) -endif - -wamr_external_module_proto.h: registry$(DELIM).updated -ifeq ($(PDATLIST),) - $(call DELFILE, wamr_external_module_proto.h) - $(Q) touch wamr_external_module_proto.h -else - $(call CATFILE, wamr_external_module_proto.h, $(PDATLIST)) -endif - -depend:: $(GLUECSRCS) wamr_external_module_list.h wamr_external_module_proto.h -endif # CONFIG_INTERPRETERS_WAMR_EXTERNAL_MODULE_REGISTRY - -clean:: - $(call DELFILE, wamr_external_module_list.h) - $(call DELFILE, wamr_external_module_proto.h) - -clean_context:: - $(call DELFILE, $(BDATLIST)) - $(call DELFILE, $(PDATLIST)) - -# Download and unpack tarball if no git repo found -ifeq ($(wildcard $(WAMR_UNPACK)/.git),) context:: $(WAMR_UNPACK) -endif -distclean:: clean clean_context -ifeq ($(wildcard $(WAMR_UNPACK)/.git),) +distclean:: $(call DELDIR, $(WAMR_UNPACK)) $(call DELFILE, $(WAMR_TARBALL)) -endif include $(APPDIR)/Application.mk diff --git a/interpreters/wamr/Module.mk b/interpreters/wamr/Module.mk deleted file mode 100644 index 4e7de6334..000000000 --- a/interpreters/wamr/Module.mk +++ /dev/null @@ -1,39 +0,0 @@ -############################################################################ -# apps/interpreters/wamr/Module.mk -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -WAMR_MODULE_REGISTRY = $(APPDIR)$(DELIM)interpreters$(DELIM)wamr$(DELIM)registry - -define WAMR_MODULE_REGISTER - $(Q) echo Register WAMR Module: $1 - $(Q) echo "$2," > "$(WAMR_MODULE_REGISTRY)$(DELIM)$1.bdat" - $(Q) echo "bool $2(void);" > "$(WAMR_MODULE_REGISTRY)$(DELIM)$1.pdat" - $(Q) touch "$(WAMR_MODULE_REGISTRY)$(DELIM).updated" -endef - -ifneq ($(WAMR_MODULE_NAME),) -WAMR_MODULE_LIST := $(addprefix $(WAMR_MODULE_REGISTRY)$(DELIM),$(addsuffix .bdat,$(WAMR_MODULE_NAME))) -$(WAMR_MODULE_LIST): $(DEPCONFIG) Makefile - $(call WAMR_MODULE_REGISTER,$(firstword $(WAMR_MODULE_NAME)),$(firstword wamr_module_$(WAMR_MODULE_NAME)_register)) - $(eval WAMR_MODULE_NAME=$(filter-out $(firstword $(WAMR_MODULE_NAME)),$(WAMR_MODULE_NAME))) - -register:: $(WAMR_MODULE_LIST) -endif diff --git a/interpreters/wamr/Toolchain.defs b/interpreters/wamr/Toolchain.defs deleted file mode 100644 index 741728277..000000000 --- a/interpreters/wamr/Toolchain.defs +++ /dev/null @@ -1,96 +0,0 @@ -############################################################################ -# apps/interpreters/wamr/Toolchain.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -# Wamrc toolchain flags - -WRC ?= wamrc - -ifeq ($(CONFIG_ARCH_XTENSA),y) - WTARGET = xtensa -else ifeq ($(CONFIG_ARCH_X86_64),y) - WTARGET = x86_64 -else ifeq ($(CONFIG_ARCH_X86),y) - WTARGET = i386 -else ifeq ($(CONFIG_ARCH_MIPS),y) - WTARGET = mips -else ifeq ($(CONFIG_ARCH_SIM),y) - RCFLAGS += --disable-simd - ifeq ($(CONFIG_SIM_M32),y) - WTARGET = i386 - else - WTARGET = x86_64 - endif -else ifeq ($(LLVM_ARCHTYPE),thumbv7a) - WTARGET = thumbv7 -else ifeq ($(findstring thumb,$(LLVM_ARCHTYPE)),thumb) - - # target triple of thumb may very complex, such as thumbv8m.main+dsp+mve.fp+fp.dp - # so we just use the target name before the first plus sign - - WTARGET = $(shell echo $(LLVM_ARCHTYPE) | cut -d'+' -f1) -else ifeq ($(LLVM_ARCHTYPE),armv7a) - WTARGET = armv7 -endif - -# If WTARGET is not defined, then use the same as LLVM_ARCHTYPE - -ifeq ($(WTARGET),) - WTARGET = $(LLVM_ARCHTYPE) -endif - -# If WCPU is not defined, then use the same as LLVM_CPU - -ifeq ($(WCPU),) - WCPU = $(LLVM_CPUTYPE) -endif - -# If LLVM_ABITYPE is eabihf, then convert it to gnueabihf which is used by wamrc - -ifeq ($(LLVM_ABITYPE),eabihf) - WABITYPE = gnueabihf -else - WABITYPE = $(LLVM_ABITYPE) -endif - -RCFLAGS += --target=$(WTARGET) --target-abi=$(WABITYPE) --cpu=$(WCPU) - -define WAMR_AOT_COMPILE - $(if $(wildcard $(APPDIR)$(DELIM)wasm$(DELIM)*.wo), \ - $(foreach bin,$(wildcard $(APPDIR)$(DELIM)wasm$(DELIM)*.wo), \ - $(eval PROGNAME=$(shell echo $(notdir $(bin)) | cut -d'#' -f1)) \ - $(eval WAMRMODE=$(shell echo $(notdir $(bin)) | cut -d'#' -f5)) \ - $(if $(CONFIG_INTERPRETERS_WAMR_AOT), \ - $(if $(filter AOT,$(WAMRMODE)), \ - $(info Wamrc Generate AoT: $(BINDIR)$(DELIM)wasm$(DELIM)$(PROGNAME).aot) \ - $(shell $(WRC) $(RCFLAGS) -o $(BINDIR)$(DELIM)wasm$(DELIM)$(PROGNAME).aot \ - $(BINDIR)$(DELIM)wasm$(DELIM)$(PROGNAME).wasm > /dev/null), \ - $(if $(filter XIP,$(WAMRMODE)), \ - $(info Wamrc Generate XiP: $(BINDIR)$(DELIM)wasm$(DELIM)$(PROGNAME).xip) \ - $(shell $(WRC) $(RCFLAGS) --enable-indirect-mode --disable-llvm-intrinsics \ - -o $(BINDIR)$(DELIM)wasm$(DELIM)$(PROGNAME).xip \ - $(BINDIR)$(DELIM)wasm$(DELIM)$(PROGNAME).wasm > /dev/null) \ - ) \ - ) \ - ) \ - ) \ - ) -endef diff --git a/interpreters/wamr/registry/.gitignore b/interpreters/wamr/registry/.gitignore deleted file mode 100644 index 3fd3b08fc..000000000 --- a/interpreters/wamr/registry/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -.updated -*.pdat -*.bdat diff --git a/interpreters/wamr/wamr_custom_init.c b/interpreters/wamr/wamr_custom_init.c deleted file mode 100644 index 9c895e0a2..000000000 --- a/interpreters/wamr/wamr_custom_init.c +++ /dev/null @@ -1,84 +0,0 @@ -/**************************************************************************** - * apps/interpreters/wamr/wamr_custom_init.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "wasm_native.h" - -#include "wamr_custom_init.h" - -#ifdef CONFIG_INTERPRETERS_WAMR_EXTERNAL_MODULE_REGISTRY -#include "wamr_external_module_proto.h" -#endif - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -typedef bool (*module_register_t)(void); - -#ifdef CONFIG_INTERPRETERS_WAMR_EXTERNAL_MODULE_REGISTRY -static const module_register_t g_wamr_modules[] = -{ -#include "wamr_external_module_list.h" -}; -#endif - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -bool wamr_custom_init(RuntimeInitArgs *init_args) -{ - bool ret = wasm_runtime_full_init(init_args); - - if (!ret) - { - return ret; - } - - /* Add extra init hook here */ - -#ifdef CONFIG_INTERPRETERS_WAMR_EXTERNAL_MODULE_REGISTRY - for (int i = 0; i < nitems(g_wamr_modules); i++) - { - ret = g_wamr_modules[i](); - if (!ret) - { - return ret; - } - } -#endif - - return ret; -} diff --git a/interpreters/wasm3/Kconfig b/interpreters/wasm3/Kconfig index ab409e519..e3a71a9f6 100644 --- a/interpreters/wasm3/Kconfig +++ b/interpreters/wasm3/Kconfig @@ -25,7 +25,7 @@ config INTERPRETERS_WASM3_FIXEDHEAP int "WASM3 Fixed heap size" default 0 ---help--- - 0 : Use malloc/free instead of internal heap + 0 : Use malloc/free instead of internal heap config INTERPRETERS_WASM3_LOG bool "WASM3 log" @@ -37,6 +37,6 @@ config INTERPRETERS_WASM3_LOG_VERBOSE bool "WASM3 log verbose" default n -endif # INTERPRETERS_WASM3_LOG +endif -endif # INTERPRETERS_WASM3 +endif diff --git a/interpreters/wasm3/Make.defs b/interpreters/wasm3/Make.defs index a78510e7a..4d4802c8d 100644 --- a/interpreters/wasm3/Make.defs +++ b/interpreters/wasm3/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/interpreters/wasm3/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -23,7 +21,9 @@ ifneq ($(CONFIG_INTERPRETERS_WASM3),) CONFIGURED_APPS += $(APPDIR)/interpreters/wasm3 -CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/interpreters/wasm3/wasm3/source -CXXFLAGS += ${INCDIR_PREFIX}$(APPDIR)/interpreters/wasm3/wasm3/source +CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" \ + $(APPDIR)/interpreters/wasm3/wasm3/source} +CXXFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" \ + $(APPDIR)/interpreters/wasm3/wasm3/source} endif diff --git a/interpreters/wasm3/Makefile b/interpreters/wasm3/Makefile index 2c87f9988..e03fbec95 100644 --- a/interpreters/wasm3/Makefile +++ b/interpreters/wasm3/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/interpreters/wasm3/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -70,13 +68,13 @@ $(WASM3_UNPACK): $(WASM3_TARBALL) $(Q) tar xzvf $(WASM3_TARBALL) $(Q) mv wasm3-$(WASM3_VERSION) $(WASM3_UNPACK) -# Download and unpack tarball if no git repo found -ifeq ($(wildcard $(WASM3_UNPACK)/.git),) -context:: $(WASM3_UNPACK) +$(WASM3_UNPACK)/.patch: $(WASM3_UNPACK) + $(Q) touch $(WASM3_UNPACK)/.patch + +context:: $(WASM3_UNPACK)/.patch distclean:: $(call DELDIR, $(WASM3_UNPACK)) $(call DELFILE, $(WASM3_TARBALL)) -endif include $(APPDIR)/Application.mk diff --git a/logging/.gitignore b/logging/.gitignore deleted file mode 100644 index 9e1d2593e..000000000 --- a/logging/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/Kconfig diff --git a/logging/CMakeLists.txt b/logging/CMakeLists.txt deleted file mode 100644 index 99615502a..000000000 --- a/logging/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -# ############################################################################## -# apps/logging/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -nuttx_add_subdirectory() - -nuttx_generate_kconfig(MENUDESC "Logging Utilities") diff --git a/logging/Make.defs b/logging/Make.defs deleted file mode 100644 index ebfb64829..000000000 --- a/logging/Make.defs +++ /dev/null @@ -1,23 +0,0 @@ -############################################################################ -# apps/logging/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(wildcard $(APPDIR)/logging/*/Make.defs) diff --git a/logging/Makefile b/logging/Makefile deleted file mode 100644 index f7971ba95..000000000 --- a/logging/Makefile +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/logging/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -MENUDESC = "Logging Utilities" - -include $(APPDIR)/Directory.mk diff --git a/logging/embedlog/CMakeLists.txt b/logging/embedlog/CMakeLists.txt deleted file mode 100644 index f9684075e..000000000 --- a/logging/embedlog/CMakeLists.txt +++ /dev/null @@ -1,23 +0,0 @@ -# ############################################################################## -# apps/logging/embedlog/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -# TODO diff --git a/logging/embedlog/Make.defs b/logging/embedlog/Make.defs deleted file mode 100644 index 1b59e6ef3..000000000 --- a/logging/embedlog/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/logging/embedlog/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_LOGGING_EMBEDLOG),) -CONFIGURED_APPS += $(APPDIR)/logging/embedlog -endif diff --git a/logging/nxscope/CMakeLists.txt b/logging/nxscope/CMakeLists.txt deleted file mode 100644 index 98594accd..000000000 --- a/logging/nxscope/CMakeLists.txt +++ /dev/null @@ -1,43 +0,0 @@ -# ############################################################################## -# apps/logging/nxscope/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_LOGGING_NXSCOPE) - set(CSRCS nxscope.c nxscope_chan.c nxscope_internals.c) - - if(CONFIG_LOGGING_NXSCOPE_INTF_SERIAL) - list(APPEND CSRCS nxscope_iser.c) - endif() - - if(CONFIG_LOGGING_NXSCOPE_INTF_UDP) - list(APPEND CSRCS nxscope_iudp.c) - endif() - - if(CONFIG_LOGGING_NXSCOPE_INTF_DUMMY) - list(APPEND CSRCS nxscope_idummy.c) - endif() - - if(CONFIG_LOGGING_NXSCOPE_PROTO_SER) - list(APPEND CSRCS nxscope_pser.c) - endif() - - target_sources(apps PRIVATE ${CSRCS}) -endif() diff --git a/logging/nxscope/Kconfig b/logging/nxscope/Kconfig deleted file mode 100644 index bb187ea43..000000000 --- a/logging/nxscope/Kconfig +++ /dev/null @@ -1,69 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config LOGGING_NXSCOPE - bool "NxScope interface" - default n - -if LOGGING_NXSCOPE - -config LOGGING_NXSCOPE_INTF_SERIAL - bool "NxScope serial port interface support" - default n - ---help--- - For details, see logging/nxscope/nxscope_iserial.c - -config LOGGING_NXSCOPE_INTF_UDP - bool "NxScope UDP interface support" - default n - ---help--- - For details, see logging/nxscope/nxscope_iudp.c - -config LOGGING_NXSCOPE_INTF_DUMMY - bool "NxScope dummy interface support" - default n - ---help--- - Useful for debug purposes. For details, see logging/nxscope/nxscope_idummy.c - -config LOGGING_NXSCOPE_PROTO_SER - bool "NxScope default serial protocol support" - default y - ---help--- - For frame details, see logging/nxscope/nxscope_pser.c - -config LOGGING_NXSCOPE_DIVIDER - bool "NxScope support for samples divider" - default n - ---help--- - This option enables interface that allows you to reduce - the rate of samples written to the stream buffer. - -config LOGGING_NXSCOPE_ACKFRAMES - bool "NxScope support for ACK frames" - default n - ---help--- - This option enables ACK frames for set requests - -config LOGGING_NXSCOPE_USERTYPES - bool "NxScope support for user types" - default n - ---help--- - This option enables user-defined frames (see enum nxscope_hdr_id_e) - -config LOGGING_NXSCOPE_CRICHANNELS - bool "NxScope support for critical channels" - default n - ---help--- - Enable the support for non-buffered critical channels - -config LOGGING_NXSCOPE_DISABLE_PUTLOCK - bool "NxScope disable lock in channels put interfaces" - default n - ---help--- - This option disables lock in channels put interfaces. - In that case, the user is responsible for ensuring - thread-safe operations with nxscope_lock/nxscope_unlock functions. - -endif # LOGGING_NXSCOPE diff --git a/logging/nxscope/Make.defs b/logging/nxscope/Make.defs deleted file mode 100644 index 92db87b79..000000000 --- a/logging/nxscope/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/logging/nxscope/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_LOGGING_NXSCOPE),) -CONFIGURED_APPS += $(APPDIR)/logging/nxscope -endif diff --git a/logging/nxscope/Makefile b/logging/nxscope/Makefile deleted file mode 100644 index c8fc05489..000000000 --- a/logging/nxscope/Makefile +++ /dev/null @@ -1,45 +0,0 @@ -############################################################################ -# apps/logging/nxscope/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -# NxScope Library - -CSRCS = nxscope.c nxscope_chan.c nxscope_internals.c - -ifeq ($(CONFIG_LOGGING_NXSCOPE_INTF_SERIAL),y) -CSRCS += nxscope_iser.c -endif - -ifeq ($(CONFIG_LOGGING_NXSCOPE_INTF_DUMMY),y) -CSRCS += nxscope_idummy.c -endif - -ifeq ($(CONFIG_LOGGING_NXSCOPE_INTF_UDP),y) -CSRCS += nxscope_iudp.c -endif - -ifeq ($(CONFIG_LOGGING_NXSCOPE_PROTO_SER),y) -CSRCS += nxscope_pser.c -endif - -include $(APPDIR)/Application.mk diff --git a/logging/nxscope/nxscope.c b/logging/nxscope/nxscope.c deleted file mode 100644 index 094395dd8..000000000 --- a/logging/nxscope/nxscope.c +++ /dev/null @@ -1,1170 +0,0 @@ -/**************************************************************************** - * apps/logging/nxscope/nxscope.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include -#include -#include - -#include - -#include "nxscope_internals.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* NOTE: channel name is always terminated with a null-character */ - -#define CHINFO_DATA_SIZE_MAX (sizeof(struct nxscope_chinfo_s) - \ - sizeof(char *) + CHAN_NAMELEN_MAX + 1) - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: nxscope_frame_send - * - * NOTE: This function assumes that we have exclusive access to the nxscope - * instance - * - ****************************************************************************/ - -static int nxscope_frame_send(FAR struct nxscope_s *s, uint8_t id, - FAR uint8_t *data, size_t dlen) -{ - size_t tx_i = 0; - int ret = OK; - - DEBUGASSERT(s); - DEBUGASSERT(data); - -#ifdef CONFIG_DEBUG_FEATURES - /* Validate TX buffer space */ - - if (s->txbuf_len < dlen + s->proto_cmd->footlen + s->proto_cmd->hdrlen) - { - ret = -ENOBUFS; - _err("ERROR: no space in txbuf %d\n", ret); - goto errout; - } -#endif - - /* Offset for hdr */ - - tx_i = s->proto_cmd->hdrlen; - - /* Copy data */ - - memcpy(&s->txbuf[tx_i], data, dlen); - tx_i += dlen; - - /* Finalize a new frame */ - - ret = PROTO_FRAME_FINAL(s, s->proto_cmd, id, s->txbuf, &tx_i); - if (ret < 0) - { - _err("ERROR: PROTO_FRAME_FINAL failed %d\n", ret); - goto errout; - } - - /* Send frame */ - - ret = INTF_SEND(s, s->intf_cmd, s->txbuf, tx_i); - if (ret < 0) - { - _err("ERROR: INTF_SEND failed %d\n", ret); - } - -errout: - return ret; -} - -/**************************************************************************** - * Name: nxscope_cmninfo_send - * - * NOTE: This function assumes that we have exclusive access to the nxscope - * instance - * - ****************************************************************************/ - -static int nxscope_cmninfo_send(FAR struct nxscope_s *s) -{ - DEBUGASSERT(s); - - return nxscope_frame_send(s, - NXSCOPE_HDRID_CMNINFO, - (FAR uint8_t *)&s->cmninfo, - sizeof(struct nxscope_info_cmn_s)); -} - -/**************************************************************************** - * Name: nxscope_chinfo_send - * - * NOTE: This function assumes that we have exclusive access to the nxscope - * instance - * - ****************************************************************************/ - -static int nxscope_chinfo_send(FAR struct nxscope_s *s, uint8_t ch) -{ - uint8_t data[CHINFO_DATA_SIZE_MAX]; - size_t namelen = 0; - size_t txlen = 0; - size_t tmp = 0; - - DEBUGASSERT(s); - - /* Copy channel info */ - - tmp = sizeof(struct nxscope_chinfo_s) - sizeof(char *); - memcpy(data, &s->chinfo[ch], tmp); - - namelen = strnlen(s->chinfo[ch].name, CHAN_NAMELEN_MAX); - memcpy(&data[tmp], s->chinfo[ch].name, namelen); - - /* Terminate name with a null character */ - - txlen = tmp + namelen + 1; - data[txlen - 1] = '\0'; - - /* Send frame */ - - return nxscope_frame_send(s, NXSCOPE_HDRID_CHINFO, data, txlen); -} - -/**************************************************************************** - * Name: nxscope_enable_req - * - * NOTE: This function assumes that we have exclusive access to the nxscope - * instance - * - ****************************************************************************/ - -static int nxscope_enable_req(FAR struct nxscope_s *s, - FAR struct nxscope_set_frame_s *set, - uint16_t dlen) -{ - FAR struct nxscope_enable_data_s *data = NULL; - int ret = OK; - int i = 0; - - DEBUGASSERT(s); - DEBUGASSERT(set); - - /* Get data */ - - data = (FAR struct nxscope_enable_data_s *) set->data; - - /* Handle set request */ - - switch (set->req) - { - case NXSCOPE_SET_REQ_SINGLE: - { - /* Verify request length */ - - if (dlen != (sizeof(struct nxscope_set_frame_s) + - NXSCOPE_ENABLE_LEN - 1)) - { - _err("ERROR: invalid enable single dlen = %d\n", dlen); - ret = -EINVAL; - goto errout; - } - - /* Validate data */ - - if (data->ch[0].en != 0 && data->ch[0].en != 1) - { - ret = -EINVAL; - goto errout; - } - - if (set->chan > s->cmninfo.chmax) - { - ret = -EINVAL; - goto errout; - } - - /* Write configuration */ - - s->chinfo[set->chan].enable = data->ch[0].en; - - break; - } - - case NXSCOPE_SET_REQ_BULK: - { - /* Verify request length */ - - if (dlen != (sizeof(struct nxscope_set_frame_s) + - NXSCOPE_ENABLE_LEN * s->cmninfo.chmax - 1)) - { - _err("ERROR: invalid enable bulk dlen = %d\n", dlen); - ret = -EINVAL; - goto errout; - } - - /* Validate data */ - - for (i = 0; i < s->cmninfo.chmax; i++) - { - if (data->ch[i].en != 0 && data->ch[i].en != 1) - { - ret = -EINVAL; - goto errout; - } - } - - /* Write configuration */ - - for (i = 0; i < s->cmninfo.chmax; i++) - { - s->chinfo[i].enable = data->ch[i].en; - } - - break; - } - - case NXSCOPE_SET_REQ_ALL: - { - /* Verify request length */ - - if (dlen != (sizeof(struct nxscope_set_frame_s) + - NXSCOPE_ENABLE_LEN - 1)) - { - _err("ERROR: invalid enable all dlen = %d\n", dlen); - ret = -EINVAL; - goto errout; - } - - if (data->ch[0].en != 0 && data->ch[0].en != 1) - { - ret = -EINVAL; - goto errout; - } - - /* Write configuration */ - - for (i = 0; i < s->cmninfo.chmax; i++) - { - s->chinfo[i].enable = data->ch[0].en; - } - - break; - } - - default: - { - _err("ERROR: invalid set->req=%d\n", set->req); - ret = -EINVAL; - break; - } - } - -errout: - return ret; -} - -#ifdef CONFIG_LOGGING_NXSCOPE_DIVIDER -/**************************************************************************** - * Name: nxscope_div_req - * - * NOTE: This function assumes that we have exclusive access to the nxscope - * instance - * - ****************************************************************************/ - -static int nxscope_div_req(FAR struct nxscope_s *s, - FAR struct nxscope_set_frame_s *set, - uint16_t dlen) -{ - FAR struct nxscope_div_data_s *data = NULL; - int ret = OK; - int i = 0; - - DEBUGASSERT(s); - DEBUGASSERT(set); - - /* Get data */ - - data = (FAR struct nxscope_div_data_s *)set->data; - - /* Handle set request */ - - switch (set->req) - { - case NXSCOPE_SET_REQ_SINGLE: - { - /* Verify request length */ - - if (dlen != (sizeof(struct nxscope_set_frame_s) + - NXSCOPE_DIV_LEN - 1)) - { - _err("ERROR: invalid div single dlen = %d\n", dlen); - ret = -EINVAL; - goto errout; - } - - if (set->chan > s->cmninfo.chmax) - { - ret = -EINVAL; - goto errout; - } - - /* Write configuration */ - - s->chinfo[set->chan].div = data->ch[0].div; - - break; - } - - case NXSCOPE_SET_REQ_BULK: - { - /* Verify request length */ - - if (dlen != (sizeof(struct nxscope_set_frame_s) + - NXSCOPE_DIV_LEN * s->cmninfo.chmax - 1)) - { - _err("ERROR: invalid div bulk dlen = %d\n", dlen); - ret = -EINVAL; - goto errout; - } - - /* Write configuration */ - - for (i = 0; i < s->cmninfo.chmax; i++) - { - s->chinfo[i].div = data->ch[i].div; - } - - break; - } - - case NXSCOPE_SET_REQ_ALL: - { - /* Verify request length */ - - if (dlen != (sizeof(struct nxscope_set_frame_s) + - NXSCOPE_DIV_LEN - 1)) - { - _err("ERROR: invalid div all dlen = %d\n", dlen); - ret = -EINVAL; - goto errout; - } - - /* Write configuration */ - - for (i = 0; i < s->cmninfo.chmax; i++) - { - s->chinfo[i].div = data->ch[0].div; - } - - break; - } - - default: - { - _err("ERROR: invalid set->req=%d\n", set->req); - ret = -EINVAL; - break; - } - } - -errout: - return ret; -} -#endif - -/**************************************************************************** - * Name: nxscope_start_set - * - * NOTE: This function assumes that we have exclusive access to the nxscope - * instance - * - ****************************************************************************/ - -static int nxscope_start_set(FAR struct nxscope_s *s, bool start) -{ - int ret = OK; - - s->start = start; - - /* User specific callback */ - - if (s->callbacks != NULL && s->callbacks->start != NULL) - { - ret = s->callbacks->start(s->callbacks->start_priv, start); - if (ret < 0) - { - _err("ERROR: s->callbacks->start failed %d\n", ret); - } - } - - return ret; -} - -/**************************************************************************** - * Name: nxscope_start_req - * - * NOTE: This function assumes that we have exclusive access to the nxscope - * instance - * - ****************************************************************************/ - -static int nxscope_start_req(FAR struct nxscope_s *s, - FAR struct nxscope_start_data_s *data) -{ - int ret = -EINVAL; - - DEBUGASSERT(s); - DEBUGASSERT(data); - - if (data->start == 0 || data->start == 1) - { - _info("data->start=%d\n", data->start); - ret = nxscope_start_set(s, data->start); - } - - return ret; -} - -/**************************************************************************** - * Name: nxscope_stream_reset - * - * NOTE: This function assumes that we have exclusive access to the nxscope - * instance - * - ****************************************************************************/ - -static void nxscope_stream_reset(FAR struct nxscope_s *s) -{ - DEBUGASSERT(s); - - /* Offset for hdr + 1 byte for flags */ - - s->stream_i = s->proto_stream->hdrlen + 1; - - /* Reset flags */ - - s->streambuf[s->proto_stream->hdrlen] = 0; -} - -/**************************************************************************** - * Name: nxscope_stream_empty - * - * NOTE: This function assumes that we have exclusive access to the nxscope - * instance - * - ****************************************************************************/ - -static bool nxscope_stream_empty(FAR struct nxscope_s *s) -{ - DEBUGASSERT(s); - - if (s->stream_i > s->proto_stream->hdrlen + 1) - { - return false; - } - else - { - return true; - } -} - -#ifdef CONFIG_LOGGING_NXSCOPE_ACKFRAMES -/**************************************************************************** - * Name: nxscope_ack - * - * NOTE: This function assumes that we have exclusive access to the nxscope - * instance - * - ****************************************************************************/ - -static void nxscope_ack(FAR struct nxscope_s *s, int ret) -{ - DEBUGASSERT(s); - - nxscope_frame_send(s, NXSCOPE_HDRID_ACK, (FAR uint8_t *)&ret, 4); -} -#endif - -/**************************************************************************** - * Name: nxscope_recv_handle - ****************************************************************************/ - -static int nxscope_recv_handle(FAR struct nxscope_s *s, uint8_t id, - uint16_t dlen, FAR uint8_t *buf) -{ - int ret = OK; - - DEBUGASSERT(s); - DEBUGASSERT(buf); - - nxscope_lock(s); - - switch (id) - { - case NXSCOPE_HDRID_CMNINFO: - { - _info("NXSCOPE_HDRID_CMNINFO\n"); - - /* Verify request length */ - - if (dlen != 0) - { - _err("ERROR: cmninfo request invalid dlen = %d\n", dlen); - goto errout; - } - - /* Send cmninfo response */ - - ret = nxscope_cmninfo_send(s); - - break; - } - - case NXSCOPE_HDRID_CHINFO: - { - FAR uint8_t *ch = buf; - - _info("NXSCOPE_HDRID_CHINFO %d\n", *ch); - - /* Verify request length */ - - if (dlen != 1) - { - _err("ERROR: chinfo request invalid dlen = %d\n", dlen); - goto errout; - } - - /* Send chinfo response */ - - ret = nxscope_chinfo_send(s, *ch); - - break; - } - - case NXSCOPE_HDRID_START: - { - FAR struct nxscope_start_data_s *data = - (FAR struct nxscope_start_data_s *)buf; - - _info("NXSCOPE_HDRID_START\n"); - - /* Verify request length */ - - if (dlen != NXSCOPE_START_LEN) - { - _err("ERROR: start request invalid dlen = %d\n", dlen); - goto errout; - } - - /* Start request */ - - ret = nxscope_start_req(s, data); - -#ifdef CONFIG_LOGGING_NXSCOPE_ACKFRAMES - /* Send ACK */ - - nxscope_ack(s, ret); -#endif - - break; - } - - case NXSCOPE_HDRID_ENABLE: - { - FAR struct nxscope_set_frame_s *data = - (FAR struct nxscope_set_frame_s *)buf; - - _info("NXSCOPE_HDRID_ENABLE\n"); - - /* Enable request */ - - ret = nxscope_enable_req(s, data, dlen); - -#ifdef CONFIG_LOGGING_NXSCOPE_ACKFRAMES - /* Send ACK */ - - nxscope_ack(s, ret); -#endif - - break; - } - - case NXSCOPE_HDRID_DIV: - { -#ifdef CONFIG_LOGGING_NXSCOPE_DIVIDER - FAR struct nxscope_set_frame_s *data = - (FAR struct nxscope_set_frame_s *)buf; - - _info("NXSCOPE_HDRID_DIV\n"); - - /* Divider request */ - - ret = nxscope_div_req(s, data, dlen); -#else - ret = -EPERM; -#endif - -#ifdef CONFIG_LOGGING_NXSCOPE_ACKFRAMES - /* Send ACK */ - - nxscope_ack(s, ret); -#endif - - break; - } - - default: - { - /* User specific commands */ - - if (s->callbacks != NULL && s->callbacks->userid != NULL) - { - ret = s->callbacks->userid(s->callbacks->userid_priv, id, buf); - if (ret < 0) - { - _err("ERROR: s->callbacks->userid failed %d\n", ret); - } - } - else - { - _err("ERROR: unsupported id %d\n", id); - ret = -EINVAL; - } - } - } - -errout: - nxscope_unlock(s); - - return ret; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: nxscope_init - * - * Description: - * Initialize a nxscope instance - * - * Input Parameters: - * s - a pointer to a nxscope instance - * cfg - a pointer to a nxscope configuration data - * - ****************************************************************************/ - -int nxscope_init(FAR struct nxscope_s *s, FAR struct nxscope_cfg_s *cfg) -{ - int ret = OK; - int i = 0; - - DEBUGASSERT(s); - DEBUGASSERT(cfg); - - /* Reset structure */ - - memset(s, 0, sizeof(struct nxscope_s)); - - /* Connect command interface */ - - DEBUGASSERT(cfg->intf_cmd); - DEBUGASSERT(cfg->intf_cmd->ops->send); - DEBUGASSERT(cfg->intf_cmd->ops->recv); - - /* Must be initialized */ - - if (!cfg->intf_cmd->initialized) - { - ret = -EINVAL; - goto errout; - } - - s->intf_cmd = cfg->intf_cmd; - - /* Connect command protocol handler */ - - DEBUGASSERT(cfg->proto_cmd); - DEBUGASSERT(cfg->proto_cmd->ops->frame_get); - DEBUGASSERT(cfg->proto_cmd->ops->frame_final); - - /* Must be initialized */ - - if (!cfg->proto_cmd->initialized) - { - ret = -EINVAL; - goto errout; - } - - s->proto_cmd = cfg->proto_cmd; - - /* Connect stream interface */ - - DEBUGASSERT(cfg->intf_stream); - DEBUGASSERT(cfg->intf_stream->ops->send); - DEBUGASSERT(cfg->intf_stream->ops->recv); - - /* Must be initialized */ - - if (!cfg->intf_stream->initialized) - { - ret = -EINVAL; - goto errout; - } - - s->intf_stream = cfg->intf_stream; - - /* Connect stream protocol handler */ - - DEBUGASSERT(cfg->proto_stream); - DEBUGASSERT(cfg->proto_stream->ops->frame_get); - DEBUGASSERT(cfg->proto_stream->ops->frame_final); - - /* Must be initialized */ - - if (!cfg->proto_stream->initialized) - { - ret = -EINVAL; - goto errout; - } - - s->proto_stream = cfg->proto_stream; - - /* Connect callbacks (optional) */ - - s->callbacks = cfg->callbacks; - - /* Allocate memory for stream buffer */ - - DEBUGASSERT(cfg->streambuf_len > 0); - - s->streambuf = zalloc(cfg->streambuf_len); - if (s->streambuf == NULL) - { - ret = -errno; - _err("ERROR: streambuf zalloc failed %d\n", ret); - goto errout; - } - - s->streambuf_len = cfg->streambuf_len; - - /* Allocate memory for nxscope channels info */ - - DEBUGASSERT(cfg->channels > 0); - - s->chinfo_size = cfg->channels * sizeof(struct nxscope_chinfo_s); - - s->chinfo = zalloc(s->chinfo_size); - if (s->chinfo == NULL) - { - ret = -errno; - _err("ERROR: chinfo zalloc failed %d\n", ret); - goto errout; - } - -#ifdef CONFIG_LOGGING_NXSCOPE_DIVIDER - /* Allocate memory for divider counters */ - - s->cntr = zalloc(cfg->channels * sizeof(uint32_t)); - if (s->cntr == NULL) - { - ret = -errno; - _err("ERROR: cntr zalloc failed %d\n", ret); - goto errout; - } -#endif - - /* Allocate memory for RX buffer */ - - DEBUGASSERT(cfg->rxbuf_len > 0); - s->rxbuf_len = cfg->rxbuf_len; - - s->rxbuf = zalloc(s->rxbuf_len); - if (s->rxbuf == NULL) - { - ret = -errno; - _err("ERROR: rxbuf zalloc failed %d\n", ret); - goto errout; - } - - /* Allocate memory for TX buffer. - * We must fit the longest possible CHINFO response. - */ - - s->txbuf_len = (CHINFO_DATA_SIZE_MAX + s->proto_cmd->footlen + - s->proto_cmd->hdrlen); - s->txbuf = zalloc(s->txbuf_len); - if (s->txbuf == NULL) - { - ret = -errno; - _err("ERROR: txbuf zalloc failed %d\n", ret); - goto errout; - } - -#ifdef CONFIG_LOGGING_NXSCOPE_CRICHANNELS - /* Allocate memory for critical channels buffer */ - - s->cribuf_len = cfg->cribuf_len; - s->cribuf = zalloc(s->cribuf_len); - if (s->cribuf == NULL) - { - ret = -errno; - _err("ERROR: cribuf zalloc failed %d\n", ret); - goto errout; - } -#endif - - /* Initialize lock */ - - ret = pthread_mutex_init(&s->lock, NULL); - if (ret != 0) - { - _err("ERROR: pthread_mutex_init failed %d\n", errno); - goto errout; - } - - /* Reset stream buffer */ - - nxscope_stream_reset(s); - - /* Initialize info data */ - - s->cmninfo.chmax = cfg->channels; - - s->cmninfo.flags = 0; -#ifdef CONFIG_LOGGING_NXSCOPE_DIVIDER - s->cmninfo.flags |= NXSCOPE_FLAGS_DIVIDER_SUPPORT; -#endif -#ifdef CONFIG_LOGGING_NXSCOPE_ACKFRAMES - s->cmninfo.flags |= NXSCOPE_FLAGS_ACK_SUPPORT; -#endif - - s->cmninfo.rx_padding = cfg->rx_padding; - - /* Initialize channels */ - - for (i = 0; i < cfg->channels; i++) - { - s->chinfo[i].name = "\0"; - } - - return OK; - -errout: - - if (s->streambuf != NULL) - { - free(s->streambuf); - } - - if (s->chinfo != NULL) - { - free(s->chinfo); - } - -#ifdef CONFIG_LOGGING_NXSCOPE_DIVIDER - if (s->cntr != NULL) - { - free(s->cntr); - } -#endif - - if (s->rxbuf != NULL) - { - free(s->rxbuf); - } - - if (s->txbuf != NULL) - { - free(s->txbuf); - } - -#ifdef CONFIG_LOGGING_NXSCOPE_CRICHANNELS - if (s->cribuf != NULL) - { - free(s->cribuf); - } -#endif - - return ret; -} - -/**************************************************************************** - * Name: nxscope_deinit - * - * Description: - * De-initialize a nxscope instance - * - * Input Parameters: - * s - a pointer to a nxscope instance - * - ****************************************************************************/ - -void nxscope_deinit(FAR struct nxscope_s *s) -{ - DEBUGASSERT(s); - - /* Free mutex */ - - pthread_mutex_destroy(&s->lock); - - /* Free allocated memory */ - - if (s->streambuf != NULL) - { - free(s->streambuf); - } - - if (s->chinfo != NULL) - { - free(s->chinfo); - } - -#ifdef CONFIG_LOGGING_NXSCOPE_DIVIDER - if (s->cntr != NULL) - { - free(s->cntr); - } -#endif - -#ifdef CONFIG_LOGGING_NXSCOPE_CRICHANNELS - if (s->cribuf != NULL) - { - free(s->cribuf); - } -#endif - - if (s->txbuf != NULL) - { - free(s->txbuf); - } -} - -/**************************************************************************** - * Name: nxscope_lock - * - * Description: - * Lock a nxscope instance - * - * Input Parameters: - * s - a pointer to a nxscope instance - * - ****************************************************************************/ - -void nxscope_lock(FAR struct nxscope_s *s) -{ - DEBUGASSERT(s); - - pthread_mutex_lock(&s->lock); -} - -/**************************************************************************** - * Name: nxscope_unlock - * - * Description: - * Unlock a nxscope instance - * - * Input Parameters: - * s - a pointer to a nxscope instance - * - ****************************************************************************/ - -void nxscope_unlock(FAR struct nxscope_s *s) -{ - DEBUGASSERT(s); - - pthread_mutex_unlock(&s->lock); -} - -/**************************************************************************** - * Name: nxscope_stream - * - * Description: - * Send nxscope stream data. - * - * NOTE: It's the user's responsibility to periodically call this function. - * - * Input Parameters: - * s - a pointer to a nxscope instance - * - ****************************************************************************/ - -int nxscope_stream(FAR struct nxscope_s *s) -{ - int ret = OK; - - DEBUGASSERT(s); - - nxscope_lock(s); - - /* Do nothing if stream not started */ - - if (!s->start) - { - ret = OK; - goto errout; - } - - /* Do nothing if no data */ - - if (nxscope_stream_empty(s)) - { - goto errout; - } - - /* Send stream data */ - - ret = nxscope_stream_send(s, s->streambuf, &s->stream_i); - if (ret < 0) - { - _err("ERROR: nxscope_stream_send failed %d\n", ret); - goto errout; - } - - /* Reset stream buffer */ - - nxscope_stream_reset(s); - -errout: - nxscope_unlock(s); - - return ret; -} - -/**************************************************************************** - * Name: nxscope_recv - * - * Description: - * Receive and handle nxscope protocol data. - * - * NOTE: It's the user's responsibility to periodically call this function. - * - * Input Parameters: - * s - a pointer to a nxscope instance - * - ****************************************************************************/ - -int nxscope_recv(FAR struct nxscope_s *s) -{ - int ret = OK; - size_t size_left = 0; - size_t bytes_left = 0; - struct nxscope_frame_s frame; - - DEBUGASSERT(s); - - do - { - /* Accumulate data until buffer empty */ - - size_left = s->rxbuf_len - s->rxbuf_i; - ret = INTF_RECV(s, s->intf_cmd, &s->rxbuf[s->rxbuf_i], size_left); - if (ret <= 0) - { - break; - } - - s->rxbuf_i += ret; - } - while (1); - - /* Return if no data */ - - if (s->rxbuf_i == 0) - { - goto errout; - } - - /* Get frame */ - - ret = PROTO_FRAME_GET(s, s->proto_cmd, s->rxbuf, s->rxbuf_i, &frame); - if (ret < 0) - { - /* Do not pass err further */ - - ret = OK; - goto errout; - } - - /* Handle frame */ - - ret = nxscope_recv_handle(s, frame.id, (uint16_t)frame.dlen, frame.data); - if (ret < 0) - { - _err("ERROR: nxscope_recv_handle failed %d\n", ret); - goto errout; - } - - /* Keep the remaining data */ - - bytes_left = s->rxbuf_i - frame.drop; - if (bytes_left > 0) - { - memmove(s->rxbuf, &s->rxbuf[frame.drop], bytes_left); - } - -errout: - s->rxbuf_i = bytes_left; - - return ret; -} - -/**************************************************************************** - * Name: nxscope_stream_start - * - * Description: - * Start/stop data stream - * - * Input Parameters: - * s - a pointer to a nxscope instance - * start - start/stop - * - ****************************************************************************/ - -int nxscope_stream_start(FAR struct nxscope_s *s, bool start) -{ - int ret = OK; - - DEBUGASSERT(s); - - nxscope_lock(s); - - _info("force stream_start=%d\n", start); - ret = nxscope_start_set(s, start); - - nxscope_unlock(s); - - return ret; -} diff --git a/logging/nxscope/nxscope_chan.c b/logging/nxscope/nxscope_chan.c deleted file mode 100644 index 5fb9e9b92..000000000 --- a/logging/nxscope/nxscope_chan.c +++ /dev/null @@ -1,1509 +0,0 @@ -/**************************************************************************** - * apps/logging/nxscope/nxscope_chan.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include -#include -#include -#include - -#include - -#include "nxscope_internals.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#ifdef CONFIG_ENDIAN_BIG -# error Big endian not tested -#endif - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -int g_type_size[] = -{ - 0, /* NXSCOPE_TYPE_UNDEF */ - 0, /* NXSCOPE_TYPE_NONE */ - sizeof(uint8_t), /* NXSCOPE_TYPE_UINT8 */ - sizeof(int8_t), /* NXSCOPE_TYPE_INT8 */ - sizeof(uint16_t), /* NXSCOPE_TYPE_UINT16 */ - sizeof(int16_t), /* NXSCOPE_TYPE_INT16 */ - sizeof(uint32_t), /* NXSCOPE_TYPE_UINT32 */ - sizeof(int32_t), /* NXSCOPE_TYPE_INT32 */ - sizeof(uint64_t), /* NXSCOPE_TYPE_UINT64 */ - sizeof(int64_t), /* NXSCOPE_TYPE_INT64 */ - sizeof(float), /* NXSCOPE_TYPE_FLOAT */ - sizeof(double), /* NXSCOPE_TYPE_DOUBLE */ - sizeof(ub8_t), /* NXSCOPE_TYPE_UB8 */ - sizeof(b8_t), /* NXSCOPE_TYPE_B8 */ - sizeof(ub16_t), /* NXSCOPE_TYPE_UB16 */ - sizeof(b16_t), /* NXSCOPE_TYPE_B16 */ - sizeof(ub32_t), /* NXSCOPE_TYPE_UB32 */ - sizeof(b32_t), /* NXSCOPE_TYPE_B32 */ - sizeof(char), /* NXSCOPE_TYPE_CHAR */ -#if 0 - /* Reserved for future use */ - - sizeof(wchar_t), /* NXSCOPE_TYPE_WCHAR */ -#endif - -#ifdef CONFIG_LOGGING_NXSCOPE_USERTYPES - /* User type always last element and always equal to 1B */ - - sizeof(uint8_t), /* NXSCOPE_TYPE_USER */ -#endif -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: nxscope_stream_overflow - * - * NOTE: This function assumes that we have exclusive access to the nxscope - * instance - * - ****************************************************************************/ - -static void nxscope_stream_overflow(FAR struct nxscope_s *s) -{ - DEBUGASSERT(s); - - s->streambuf[s->proto_stream->hdrlen] |= NXSCOPE_STREAM_FLAGS_OVERFLOW; -} - -/**************************************************************************** - * Name: nxscope_ch_validate - ****************************************************************************/ - -static int nxscope_ch_validate(FAR struct nxscope_s *s, uint8_t ch, - uint8_t type, uint8_t d, uint8_t mlen) -{ - union nxscope_chinfo_type_u utype; - size_t next_i = 0; - int ret = OK; - size_t type_size = 0; - - DEBUGASSERT(s); - - /* Do nothing if stream not started */ - - if (!s->start) - { - ret = -EAGAIN; - goto errout; - } - - /* Do nothing if channel not enabled */ - - if (s->chinfo[ch].enable != 1) - { - ret = -EAGAIN; - goto errout; - } - - /* Some additional checks if debug features enabled */ - -#ifdef CONFIG_DEBUG_FEATURES - /* Validate channel */ - - if (ch > s->cmninfo.chmax) - { - _err("ERROR: invalid channel %d\n", ch); - ret = -EINVAL; - goto errout; - } - - /* Validate channel type */ - - if (s->chinfo[ch].type.s.dtype != type) - { - _err("ERROR: invalid channel type %d != %d\n", - s->chinfo[ch].type.u8, type); - ret = -EINVAL; - goto errout; - } - - /* Validate channel vdim */ - - if (s->chinfo[ch].vdim != d) - { - _err("ERROR: invalid channel dim %d\n", d); - ret = -EINVAL; - goto errout; - } - - /* Validate channel metadata size */ - - if (s->chinfo[ch].mlen != mlen) - { - _err("ERROR: invalid channel mlen %d\n", mlen); - ret = -EINVAL; - goto errout; - } -#endif - -#ifdef CONFIG_LOGGING_NXSCOPE_DIVIDER - /* Handle sample rate divider */ - - s->cntr[ch] += 1; - if (s->cntr[ch] % (s->chinfo[ch].div + 1) != 0) - { - ret = -EAGAIN; - goto errout; - } -#endif - - /* Get utype */ - - utype.u8 = type; - - /* Check buffer size */ - -#ifdef CONFIG_LOGGING_NXSCOPE_USERTYPES - if (type >= NXSCOPE_TYPE_USER) - { - type_size = 1; - } - else -#endif - { - type_size = g_type_size[utype.s.dtype]; - } - -#ifdef CONFIG_LOGGING_NXSCOPE_CRICHANNELS - if (utype.s.cri) - { -# ifdef CONFIG_DEBUG_FEATURES - next_i = (s->proto_stream->hdrlen + 1 + type_size * d + mlen + - s->proto_stream->footlen); - - /* Verify the size of the critical channels buffer */ - - if (s->cribuf_len < next_i) - { - _err("ERROR: no space in cribuf %zu < %zu\n", s->cribuf_len, - next_i); - ret = -ENOBUFS; - goto errout; - } - else -# endif - { - /* No more checks needed for critical channel */ - - ret = OK; - goto errout; - } - } -#endif - - next_i = (s->stream_i + 1 + type_size * d + mlen + - s->proto_stream->footlen); - - if (next_i > s->streambuf_len) - { - _err("ERROR: no space for data %zu\n", s->stream_i); - nxscope_stream_overflow(s); - ret = -ENOBUFS; - goto errout; - } - -errout: - return ret; -} - -/**************************************************************************** - * Name: nxscope_put_vector - * - * NOTE: This function assumes that we have exclusive access to the nxscope - * stream buffer - * - * IMPORTANT: Data stored always as little-endian ! - * - ****************************************************************************/ - -static int nxscope_put_vector(FAR uint8_t *buff, uint8_t type, FAR void *val, - uint8_t d) -{ - int i = 0; - int j = 0; - - DEBUGASSERT(buff); - - /* Pack data */ - - switch (type) - { - case NXSCOPE_TYPE_NONE: - { - /* Nothing to do here */ - - break; - } - - case NXSCOPE_TYPE_UINT8: - case NXSCOPE_TYPE_INT8: -#ifdef CONFIG_LOGGING_NXSCOPE_USERTYPES - case NXSCOPE_TYPE_USER: -#endif - { - uint8_t u8 = 0; - - for (i = 0; i < d; i++) - { - DEBUGASSERT(val); - u8 = ((FAR uint8_t *)val)[i]; - - buff[j++] = u8; - } - - break; - } - - case NXSCOPE_TYPE_UINT16: - case NXSCOPE_TYPE_INT16: - case NXSCOPE_TYPE_B8: - case NXSCOPE_TYPE_UB8: - { - uint16_t u16 = 0; - - for (i = 0; i < d; i++) - { - DEBUGASSERT(val); - u16 = htole16(((FAR uint16_t *)val)[i]); - - buff[j++] = ((u16 >> 0) & 0xff); - buff[j++] = ((u16 >> 8) & 0xff); - } - - break; - } - - case NXSCOPE_TYPE_UINT32: - case NXSCOPE_TYPE_INT32: - case NXSCOPE_TYPE_FLOAT: - case NXSCOPE_TYPE_B16: - case NXSCOPE_TYPE_UB16: - { - uint32_t u32 = 0; - - for (i = 0; i < d; i++) - { - DEBUGASSERT(val); - u32 = htole32(((FAR uint32_t *)val)[i]); - - buff[j++] = ((u32 >> 0) & 0xff); - buff[j++] = ((u32 >> 8) & 0xff); - buff[j++] = ((u32 >> 16) & 0xff); - buff[j++] = ((u32 >> 24) & 0xff); - } - - break; - } - - case NXSCOPE_TYPE_UINT64: - case NXSCOPE_TYPE_INT64: - case NXSCOPE_TYPE_DOUBLE: - case NXSCOPE_TYPE_B32: - case NXSCOPE_TYPE_UB32: - { - for (i = 0; i < d; i++) - { - uint64_t u64 = 0; - - DEBUGASSERT(val); - u64 = htole64(((FAR uint64_t *)val)[i]); - - buff[j++] = ((u64 >> 0) & 0xff); - buff[j++] = ((u64 >> 8) & 0xff); - buff[j++] = ((u64 >> 16) & 0xff); - buff[j++] = ((u64 >> 24) & 0xff); - buff[j++] = ((u64 >> 32) & 0xff); - buff[j++] = ((u64 >> 40) & 0xff); - buff[j++] = ((u64 >> 48) & 0xff); - buff[j++] = ((u64 >> 56) & 0xff); - } - - break; - } - - case NXSCOPE_TYPE_CHAR: - { - /* Copy string bytes and fill with '\0' */ - - DEBUGASSERT(val); - - strlcpy((FAR char *)buff, (FAR const char *)val, d); - j += strlen((FAR char *)buff); - memset(&buff[j], '\0', d - j); - j = d; - - break; - } - - default: - { - _err("ERROR: invalid type=%d\n", type); - DEBUGASSERT(0); - } - } - - return j; -} - -/**************************************************************************** - * Name: nxscope_put_meta - * - * NOTE: This function assumes that we have exclusive access to the nxscope - * stream buffer - * - * REVISIT: what about endianness ? - * - ****************************************************************************/ - -static int nxscope_put_meta(FAR uint8_t *buff, FAR uint8_t *meta, - uint8_t mlen) -{ - int i = 0; - - DEBUGASSERT(buff); - - for (i = 0; i < mlen; i++) - { - DEBUGASSERT(meta); - buff[i] = meta[i]; - } - - return mlen; -} - -/**************************************************************************** - * Name: nxscope_put_sample - * - * NOTE: This function assumes that we have exclusive access to the nxscope - * stream buffer - * - ****************************************************************************/ - -static void nxscope_put_sample(FAR uint8_t *buff, FAR size_t *buff_i, - uint8_t type, uint8_t ch, FAR void *val, - uint8_t d, FAR uint8_t *meta, uint8_t mlen) -{ - size_t i = 0; - - /* Channel ID */ - - buff[(*buff_i)++] = ch; - - /* Vector sample data - always little-endian */ - - i = nxscope_put_vector(&buff[*buff_i], type, val, d); - *buff_i += i; - - /* Meta data. - * REVISIT: what about endianness ? - */ - - i = nxscope_put_meta(&buff[*buff_i], meta, mlen); - *buff_i += i; -} - -/**************************************************************************** - * Name: nxscope_put_common_m - ****************************************************************************/ - -static int nxscope_put_common_m(FAR struct nxscope_s *s, uint8_t type, - uint8_t ch, FAR void *val, uint8_t d, - FAR uint8_t *meta, uint8_t mlen) -{ - FAR uint8_t *buff = NULL; - FAR size_t *buff_i = NULL; - int ret = OK; -#ifdef CONFIG_LOGGING_NXSCOPE_CRICHANNELS - size_t tmp = 0; - union nxscope_chinfo_type_u utype; -#endif - - DEBUGASSERT(s); - -#ifndef CONFIG_LOGGING_NXSCOPE_DISABLE_PUTLOCK - nxscope_lock(s); -#endif - - /* Validate data */ - - ret = nxscope_ch_validate(s, ch, type, d, mlen); - if (ret != OK) - { - goto errout; - } - - /* Get buffer to send */ - -#ifdef CONFIG_LOGGING_NXSCOPE_CRICHANNELS - utype.u8 = type; - if (utype.s.cri) - { - /* Dedicated critical channels buffer */ - - buff = s->cribuf; - buff_i = &tmp; - } - else -#endif - { - /* Common stream buffer */ - - buff = s->streambuf; - buff_i = &s->stream_i; - } - - /* Put sample on buffer */ - - nxscope_put_sample(buff, buff_i, type, ch, val, d, meta, mlen); - -#ifdef CONFIG_LOGGING_NXSCOPE_CRICHANNELS - if (utype.s.cri) - { - /* Send data without buffering */ - - ret = nxscope_stream_send(s, buff, buff_i); - if (ret < 0) - { - _err("ERROR: nxscope_stream_send failed %d\n", ret); - goto errout; - } - } -#endif - -errout: -#ifndef CONFIG_LOGGING_NXSCOPE_DISABLE_PUTLOCK - nxscope_unlock(s); -#endif - - return ret; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: nxscope_chan_init - * - * Description: - * Initialize nxscope channel - * - * Input Parameters: - * s - a pointer to a nxscope instance - * ch - a channel id - * name - a channel name - * type - a channel data type (union nxscope_chinfo_type_u) - * vdim - a vector data dimension (vdim=1 for a point) - * mlen - a length of metadata - * - ****************************************************************************/ - -int nxscope_chan_init(FAR struct nxscope_s *s, uint8_t ch, FAR char *name, - uint8_t type, uint8_t vdim, uint8_t mlen) -{ - int ret = OK; - - DEBUGASSERT(s); - DEBUGASSERT(name); - - if (ch > s->cmninfo.chmax) - { - _err("ERROR: invalid channel %d\n", ch); - ret = -EINVAL; - goto errout; - } - - nxscope_lock(s); - -#ifndef CONFIG_LOGGING_NXSCOPE_CRICHANNELS - if (NXSCOPE_IS_CRICHAN(type)) - { - _err("ERROR: cri channels not supported ch=%d\n", ch); - ret = -EINVAL; - goto errout; - } -#endif - - /* Reset channel data */ - - memset(&s->chinfo[ch], 0, sizeof(struct nxscope_chinfo_s)); - - /* Copy channel info */ - - s->chinfo[ch].type.u8 = type; - s->chinfo[ch].vdim = vdim; - s->chinfo[ch].mlen = mlen; - s->chinfo[ch].name = name; - - nxscope_unlock(s); - -errout: - return ret; -} - -/**************************************************************************** - * Name: nxscope_chan_en - * - * Description: - * Enable/disable a given channel - * - * Input Parameters: - * s - a pointer to a nxscope instance - * ch - a channel id - * en - enable/disable - * - ****************************************************************************/ - -int nxscope_chan_en(FAR struct nxscope_s *s, uint8_t ch, bool en) -{ - int ret = OK; - - DEBUGASSERT(s); - - nxscope_lock(s); - - if (ch > s->cmninfo.chmax) - { - _err("ERROR: invalid channel %d\n", ch); - ret = -EINVAL; - goto errout; - } - - if (s->chinfo[ch].type.s.dtype == NXSCOPE_TYPE_UNDEF) - { - _err("ERROR: channel not initialized %d\n", ch); - ret = -EINVAL; - goto errout; - } - - _info("chan_en=%d %d\n", ch, en); - - /* Set enable flag */ - - s->chinfo[ch].enable = en; - -errout: - nxscope_unlock(s); - - return ret; -} - -#ifdef CONFIG_LOGGING_NXSCOPE_DIVIDER -/**************************************************************************** - * Name: nxscope_chan_div - * - * Description: - * Configure divider for a given channel - * - * Input Parameters: - * s - a pointer to a nxscope instance - * ch - a channel id - * div - divider value - starts from 0 - * - ****************************************************************************/ - -int nxscope_chan_div(FAR struct nxscope_s *s, uint8_t ch, uint8_t div) -{ - int ret = OK; - - DEBUGASSERT(s); - - nxscope_lock(s); - - if (ch > s->cmninfo.chmax) - { - _err("ERROR: invalid channel %d\n", ch); - ret = -EINVAL; - goto errout; - } - - _info("chan_div=%d %d\n", ch, div); - - /* Set divider */ - - s->chinfo[ch].div = div; - -errout: - nxscope_unlock(s); - - return ret; -} -#endif - -/**************************************************************************** - * Name: nxscope_chan_all_en - * - * Description: - * Enable/disable all channels - * - * Input Parameters: - * s - a pointer to a nxscope instance - * en - enable/disable - * - ****************************************************************************/ - -int nxscope_chan_all_en(FAR struct nxscope_s *s, bool en) -{ - int ret = OK; - uint8_t i = 0; - - DEBUGASSERT(s); - - for (i = 0; i < s->cmninfo.chmax; i++) - { - ret |= nxscope_chan_en(s, i, en); - } - - return ret; -} - -/**************************************************************************** - * Name: nxscope_put_vXXXX_m - * - * Description: - * Put a vector with metadata on the stream buffer - * - * Input Parameters: - * s - a pointer to a nxscope instance - * ch - a channel id - * val - a pointer to a sample data vector - * d - a dimmention of sample data vector - * meta - a pointer to metadata - * mlen - a length of metadata - * - ****************************************************************************/ - -/**************************************************************************** - * Name: nxscope_put_vuint8_m - ****************************************************************************/ - -int nxscope_put_vuint8_m(FAR struct nxscope_s *s, uint8_t ch, - FAR uint8_t *val, uint8_t d, - FAR uint8_t *meta, uint8_t mlen) -{ - return nxscope_put_common_m(s, NXSCOPE_TYPE_UINT8, - ch, val, d, meta, mlen); -} - -/**************************************************************************** - * Name: nxscope_put_vint8_m - ****************************************************************************/ - -int nxscope_put_vint8_m(FAR struct nxscope_s *s, uint8_t ch, - FAR int8_t *val, uint8_t d, - FAR uint8_t *meta, uint8_t mlen) -{ - return nxscope_put_common_m(s, NXSCOPE_TYPE_INT8, - ch, val, d, meta, mlen); -} - -/**************************************************************************** - * Name: nxscope_put_vuint16_m - ****************************************************************************/ - -int nxscope_put_vuint16_m(FAR struct nxscope_s *s, uint8_t ch, - FAR uint16_t *val, uint8_t d, - FAR uint8_t *meta, uint8_t mlen) -{ - return nxscope_put_common_m(s, NXSCOPE_TYPE_UINT16, - ch, val, d, meta, mlen); -} - -/**************************************************************************** - * Name: nxscope_put_vint16_m - ****************************************************************************/ - -int nxscope_put_vint16_m(FAR struct nxscope_s *s, uint8_t ch, - FAR int16_t *val, uint8_t d, - FAR uint8_t *meta, uint8_t mlen) -{ - return nxscope_put_common_m(s, NXSCOPE_TYPE_INT16, - ch, val, d, meta, mlen); -} - -/**************************************************************************** - * Name: nxscope_put_vuint32_m - ****************************************************************************/ - -int nxscope_put_vuint32_m(FAR struct nxscope_s *s, uint8_t ch, - FAR uint32_t *val, uint8_t d, - FAR uint8_t *meta, uint8_t mlen) -{ - return nxscope_put_common_m(s, NXSCOPE_TYPE_UINT32, - ch, val, d, meta, mlen); -} - -/**************************************************************************** - * Name: nxscope_put_vint32_m - ****************************************************************************/ - -int nxscope_put_vint32_m(FAR struct nxscope_s *s, uint8_t ch, - FAR int32_t *val, uint8_t d, - FAR uint8_t *meta, uint8_t mlen) -{ - return nxscope_put_common_m(s, NXSCOPE_TYPE_INT32, - ch, val, d, meta, mlen); -} - -/**************************************************************************** - * Name: nxscope_put_vuint64_m - ****************************************************************************/ - -int nxscope_put_vuint64_m(FAR struct nxscope_s *s, uint8_t ch, - FAR uint64_t *val, uint8_t d, - FAR uint8_t *meta, uint8_t mlen) -{ - return nxscope_put_common_m(s, NXSCOPE_TYPE_UINT64, - ch, val, d, meta, mlen); -} - -/**************************************************************************** - * Name: nxscope_put_vint64_m - ****************************************************************************/ - -int nxscope_put_vint64_m(FAR struct nxscope_s *s, uint8_t ch, - FAR int64_t *val, uint8_t d, - FAR uint8_t *meta, uint8_t mlen) -{ - return nxscope_put_common_m(s, NXSCOPE_TYPE_INT64, - ch, val, d, meta, mlen); -} - -/**************************************************************************** - * Name: nxscope_put_vfloat_m - ****************************************************************************/ - -int nxscope_put_vfloat_m(FAR struct nxscope_s *s, uint8_t ch, - FAR float *val, uint8_t d, - FAR uint8_t *meta, uint8_t mlen) -{ - return nxscope_put_common_m(s, NXSCOPE_TYPE_FLOAT, - ch, val, d, meta, mlen); -} - -/**************************************************************************** - * Name: nxscope_put_vdouble_m - ****************************************************************************/ - -int nxscope_put_vdouble_m(FAR struct nxscope_s *s, uint8_t ch, - FAR double *val, uint8_t d, - FAR uint8_t *meta, uint8_t mlen) -{ - return nxscope_put_common_m(s, NXSCOPE_TYPE_DOUBLE, - ch, val, d, meta, mlen); -} - -/**************************************************************************** - * Name: nxscope_put_vub8_m - ****************************************************************************/ - -int nxscope_put_vub8_m(FAR struct nxscope_s *s, uint8_t ch, - FAR ub8_t *val, uint8_t d, - FAR uint8_t *meta, uint8_t mlen) -{ - return nxscope_put_common_m(s, NXSCOPE_TYPE_UB8, - ch, val, d, meta, mlen); -} - -/**************************************************************************** - * Name: nxscope_put_vb8_m - ****************************************************************************/ - -int nxscope_put_vb8_m(FAR struct nxscope_s *s, uint8_t ch, - FAR b8_t *val, uint8_t d, - FAR uint8_t *meta, uint8_t mlen) -{ - return nxscope_put_common_m(s, NXSCOPE_TYPE_B8, - ch, val, d, meta, mlen); -} - -/**************************************************************************** - * Name: nxscope_put_vub16_m - ****************************************************************************/ - -int nxscope_put_vub16_m(FAR struct nxscope_s *s, uint8_t ch, - FAR ub16_t *val, uint8_t d, - FAR uint8_t *meta, uint8_t mlen) -{ - return nxscope_put_common_m(s, NXSCOPE_TYPE_UB16, - ch, val, d, meta, mlen); -} - -/**************************************************************************** - * Name: nxscope_put_vb16_m - ****************************************************************************/ - -int nxscope_put_vb16_m(FAR struct nxscope_s *s, uint8_t ch, - FAR b16_t *val, uint8_t d, - FAR uint8_t *meta, uint8_t mlen) -{ - return nxscope_put_common_m(s, NXSCOPE_TYPE_B16, - ch, val, d, meta, mlen); -} - -/**************************************************************************** - * Name: nxscope_put_vub32_m - ****************************************************************************/ - -int nxscope_put_vub32_m(FAR struct nxscope_s *s, uint8_t ch, - FAR ub32_t *val, uint8_t d, - FAR uint8_t *meta, uint8_t mlen) -{ - return nxscope_put_common_m(s, NXSCOPE_TYPE_UB32, - ch, val, d, meta, mlen); -} - -/**************************************************************************** - * Name: nxscope_put_vb32_m - ****************************************************************************/ - -int nxscope_put_vb32_m(FAR struct nxscope_s *s, uint8_t ch, - FAR b32_t *val, uint8_t d, - FAR uint8_t *meta, uint8_t mlen) -{ - return nxscope_put_common_m(s, NXSCOPE_TYPE_B32, - ch, val, d, meta, mlen); -} - -/**************************************************************************** - * Name: nxscope_put_vchar_m - * - * NOTE: if a given string is shorten than initialized channel vdim, - * we put only string bytes + '\0' - * - ****************************************************************************/ - -int nxscope_put_vchar_m(FAR struct nxscope_s *s, uint8_t ch, - FAR char *val, uint8_t d, - FAR uint8_t *meta, uint8_t mlen) -{ - return nxscope_put_common_m(s, NXSCOPE_TYPE_CHAR, - ch, val, d, meta, mlen); -} - -/**************************************************************************** - * Name: nxscope_put_vXXXX - * - * Description: - * Put a vector on the stream buffer - * - * Input Parameters: - * s - a pointer to a nxscope instance - * ch - a channel id - * val - a pointer to a sample data vector - * d - a dimmention of sample data vector - * - ****************************************************************************/ - -/**************************************************************************** - * Name: nxscope_put_vuint8 - ****************************************************************************/ - -int nxscope_put_vuint8(FAR struct nxscope_s *s, uint8_t ch, - FAR uint8_t *val, uint8_t d) -{ - return nxscope_put_vuint8_m(s, ch, val, d, NULL, 0); -} - -/**************************************************************************** - * Name: nxscope_put_vint8 - ****************************************************************************/ - -int nxscope_put_vint8(FAR struct nxscope_s *s, uint8_t ch, - FAR int8_t *val, uint8_t d) -{ - return nxscope_put_vint8_m(s, ch, val, d, NULL, 0); -} - -/**************************************************************************** - * Name: nxscope_put_vuint16 - ****************************************************************************/ - -int nxscope_put_vuint16(FAR struct nxscope_s *s, uint8_t ch, - FAR uint16_t *val, uint8_t d) -{ - return nxscope_put_vuint16_m(s, ch, val, d, NULL, 0); -} - -/**************************************************************************** - * Name: nxscope_put_vint16 - ****************************************************************************/ - -int nxscope_put_vint16(FAR struct nxscope_s *s, uint8_t ch, - FAR int16_t *val, uint8_t d) -{ - return nxscope_put_vint16_m(s, ch, val, d, NULL, 0); -} - -/**************************************************************************** - * Name: nxscope_put_vuint32 - ****************************************************************************/ - -int nxscope_put_vuint32(FAR struct nxscope_s *s, uint8_t ch, - FAR uint32_t *val, uint8_t d) -{ - return nxscope_put_vuint32_m(s, ch, val, d, NULL, 0); -} - -/**************************************************************************** - * Name: nxscope_put_vint32 - ****************************************************************************/ - -int nxscope_put_vint32(FAR struct nxscope_s *s, uint8_t ch, - FAR int32_t *val, uint8_t d) -{ - return nxscope_put_vint32_m(s, ch, val, d, NULL, 0); -} - -/**************************************************************************** - * Name: nxscope_put_vuint64 - ****************************************************************************/ - -int nxscope_put_vuint64(FAR struct nxscope_s *s, uint8_t ch, - FAR uint64_t *val, uint8_t d) -{ - return nxscope_put_vuint64_m(s, ch, val, d, NULL, 0); -} - -/**************************************************************************** - * Name: nxscope_put_vint64 - ****************************************************************************/ - -int nxscope_put_vint64(FAR struct nxscope_s *s, uint8_t ch, - FAR int64_t *val, uint8_t d) -{ - return nxscope_put_vint64_m(s, ch, val, d, NULL, 0); -} - -/**************************************************************************** - * Name: nxscope_put_vfloat - ****************************************************************************/ - -int nxscope_put_vfloat(FAR struct nxscope_s *s, uint8_t ch, - FAR float *val, uint8_t d) -{ - return nxscope_put_vfloat_m(s, ch, val, d, NULL, 0); -} - -/**************************************************************************** - * Name: nxscope_put_vdouble - ****************************************************************************/ - -int nxscope_put_vdouble(FAR struct nxscope_s *s, uint8_t ch, - FAR double *val, uint8_t d) -{ - return nxscope_put_vdouble_m(s, ch, val, d, NULL, 0); -} - -/**************************************************************************** - * Name: nxscope_put_vub8 - ****************************************************************************/ - -int nxscope_put_vub8(FAR struct nxscope_s *s, uint8_t ch, - FAR ub8_t *val, uint8_t d) -{ - return nxscope_put_vub8_m(s, ch, val, d, NULL, 0); -} - -/**************************************************************************** - * Name: nxscope_put_vb8 - ****************************************************************************/ - -int nxscope_put_vb8(FAR struct nxscope_s *s, uint8_t ch, - FAR b8_t *val, uint8_t d) -{ - return nxscope_put_vb8_m(s, ch, val, d, NULL, 0); -} - -/**************************************************************************** - * Name: nxscope_put_vub16 - ****************************************************************************/ - -int nxscope_put_vub16(FAR struct nxscope_s *s, uint8_t ch, - FAR ub16_t *val, uint8_t d) -{ - return nxscope_put_vub16_m(s, ch, val, d, NULL, 0); -} - -/**************************************************************************** - * Name: nxscope_put_vb16 - ****************************************************************************/ - -int nxscope_put_vb16(FAR struct nxscope_s *s, uint8_t ch, - FAR b16_t *val, uint8_t d) -{ - return nxscope_put_vb16_m(s, ch, val, d, NULL, 0); -} - -/**************************************************************************** - * Name: nxscope_put_vub32 - ****************************************************************************/ - -int nxscope_put_vub32(FAR struct nxscope_s *s, uint8_t ch, - FAR ub32_t *val, uint8_t d) -{ - return nxscope_put_vub32_m(s, ch, val, d, NULL, 0); -} - -/**************************************************************************** - * Name: nxscope_put_vb32 - ****************************************************************************/ - -int nxscope_put_vb32(FAR struct nxscope_s *s, uint8_t ch, - FAR b32_t *val, uint8_t d) -{ - return nxscope_put_vb32_m(s, ch, val, d, NULL, 0); -} - -/**************************************************************************** - * Name: nxscope_put_vchar - * - * NOTE: if a given string is shorten than initialized channel vdim, - * we put only string bytes + '\0' - * - ****************************************************************************/ - -int nxscope_put_vchar(FAR struct nxscope_s *s, uint8_t ch, - FAR char *val, uint8_t d) -{ - return nxscope_put_vchar_m(s, ch, val, d, NULL, 0); -} - -/**************************************************************************** - * Name: nxscope_put_XXXX_m - * - * Description: - * Put a point with metadata on the stream buffer - * - * Input Parameters: - * s - a pointer to a nxscope instance - * ch - a channel id - * val - sample data - * meta - a pointer to metadata - * mlen - a length of metadata - * - ****************************************************************************/ - -/**************************************************************************** - * Name: nxscope_put_uint8_m - ****************************************************************************/ - -int nxscope_put_uint8_m(FAR struct nxscope_s *s, uint8_t ch, uint8_t val, - FAR uint8_t *meta, uint8_t mlen) -{ - return nxscope_put_vuint8_m(s, ch, &val, 1, meta, mlen); -} - -/**************************************************************************** - * Name: nxscope_put_int8_m - ****************************************************************************/ - -int nxscope_put_int8_m(FAR struct nxscope_s *s, uint8_t ch, int8_t val, - FAR uint8_t *meta, uint8_t mlen) -{ - return nxscope_put_vint8_m(s, ch, &val, 1, meta, mlen); -} - -/**************************************************************************** - * Name: nxscope_put_uint16_m - ****************************************************************************/ - -int nxscope_put_uint16_m(FAR struct nxscope_s *s, uint8_t ch, uint16_t val, - FAR uint8_t *meta, uint8_t mlen) -{ - return nxscope_put_vuint16_m(s, ch, &val, 1, meta, mlen); -} - -/**************************************************************************** - * Name: nxscope_put_int16_m - ****************************************************************************/ - -int nxscope_put_int16_m(FAR struct nxscope_s *s, uint8_t ch, int16_t val, - FAR uint8_t *meta, uint8_t mlen) -{ - return nxscope_put_vint16_m(s, ch, &val, 1, meta, mlen); -} - -/**************************************************************************** - * Name: nxscope_put_uint32_m - ****************************************************************************/ - -int nxscope_put_uint32_m(FAR struct nxscope_s *s, uint8_t ch, uint32_t val, - FAR uint8_t *meta, uint8_t mlen) -{ - return nxscope_put_vuint32_m(s, ch, &val, 1, meta, mlen); -} - -/**************************************************************************** - * Name: nxscope_put_int32_m - ****************************************************************************/ - -int nxscope_put_int32_m(FAR struct nxscope_s *s, uint8_t ch, int32_t val, - FAR uint8_t *meta, uint8_t mlen) -{ - return nxscope_put_vint32_m(s, ch, &val, 1, meta, mlen); -} - -/**************************************************************************** - * Name: nxscope_put_uint64_m - ****************************************************************************/ - -int nxscope_put_uint64_m(FAR struct nxscope_s *s, uint8_t ch, uint64_t val, - FAR uint8_t *meta, uint8_t mlen) -{ - return nxscope_put_vuint64_m(s, ch, &val, 1, meta, mlen); -} - -/**************************************************************************** - * Name: nxscope_put_int64_m - ****************************************************************************/ - -int nxscope_put_int64_m(FAR struct nxscope_s *s, uint8_t ch, int64_t val, - FAR uint8_t *meta, uint8_t mlen) -{ - return nxscope_put_vint64_m(s, ch, &val, 1, meta, mlen); -} - -/**************************************************************************** - * Name: nxscope_put_float_m - ****************************************************************************/ - -int nxscope_put_float_m(FAR struct nxscope_s *s, uint8_t ch, float val, - FAR uint8_t *meta, uint8_t mlen) -{ - return nxscope_put_vfloat_m(s, ch, &val, 1, meta, mlen); -} - -/**************************************************************************** - * Name: nxscope_put_double_m - ****************************************************************************/ - -int nxscope_put_double_m(FAR struct nxscope_s *s, uint8_t ch, double val, - FAR uint8_t *meta, uint8_t mlen) -{ - return nxscope_put_vdouble_m(s, ch, &val, 1, meta, mlen); -} - -/**************************************************************************** - * Name: nxscope_put_b8_m - ****************************************************************************/ - -int nxscope_put_b8_m(FAR struct nxscope_s *s, uint8_t ch, b8_t val, - FAR uint8_t *meta, uint8_t mlen) -{ - return nxscope_put_vb8_m(s, ch, &val, 1, meta, mlen); -} - -/**************************************************************************** - * Name: nxscope_put_b16_m - ****************************************************************************/ - -int nxscope_put_b16_m(FAR struct nxscope_s *s, uint8_t ch, b16_t val, - FAR uint8_t *meta, uint8_t mlen) -{ - return nxscope_put_vb16_m(s, ch, &val, 1, meta, mlen); -} - -/**************************************************************************** - * Name: nxscope_put_ub8_m - ****************************************************************************/ - -int nxscope_put_ub8_m(FAR struct nxscope_s *s, uint8_t ch, ub8_t val, - FAR uint8_t *meta, uint8_t mlen) -{ - return nxscope_put_vub8_m(s, ch, &val, 1, meta, mlen); -} - -/**************************************************************************** - * Name: nxscope_put_b32_m - ****************************************************************************/ - -int nxscope_put_b32_m(FAR struct nxscope_s *s, uint8_t ch, b32_t val, - FAR uint8_t *meta, uint8_t mlen) -{ - return nxscope_put_vb32_m(s, ch, &val, 1, meta, mlen); -} - -/**************************************************************************** - * Name: nxscope_put_ub16_m - ****************************************************************************/ - -int nxscope_put_ub16_m(FAR struct nxscope_s *s, uint8_t ch, ub16_t val, - FAR uint8_t *meta, uint8_t mlen) -{ - return nxscope_put_vub16_m(s, ch, &val, 1, meta, mlen); -} - -/**************************************************************************** - * Name: nxscope_put_ub32_m - ****************************************************************************/ - -int nxscope_put_ub32_m(FAR struct nxscope_s *s, uint8_t ch, ub32_t val, - FAR uint8_t *meta, uint8_t mlen) -{ - return nxscope_put_vub32_m(s, ch, &val, 1, meta, mlen); -} - -/**************************************************************************** - * Name: nxscope_put_char_m - ****************************************************************************/ - -int nxscope_put_char_m(FAR struct nxscope_s *s, uint8_t ch, char val, - FAR uint8_t *meta, uint8_t mlen) -{ - return nxscope_put_vchar_m(s, ch, &val, 1, meta, mlen); -} - -/**************************************************************************** - * Name: nxscope_put_none_m - * - * Description: - * Put metadata only on the stream buffer - * - * Input Parameters: - * s - a pointer to a nxscope instance - * ch - a channel id - * meta - a pointer to metadata - * mlen - a length of metadata - * - ****************************************************************************/ - -int nxscope_put_none_m(FAR struct nxscope_s *s, uint8_t ch, - FAR uint8_t *meta, uint8_t mlen) -{ - /* Put metadata with vector dim = 0 */ - - return nxscope_put_vuint8_m(s, ch, 0, 0, meta, mlen); -} - -#ifdef CONFIG_LOGGING_NXSCOPE_USERTYPES -/**************************************************************************** - * Name: nxscope_put_user_m - * - * Description: - * Put a user specific data on the stream buffer - * - * Input Parameters: - * s - a pointer to a nxscope instance - * type - a channel type (starts from NXSCOPE_TYPE_USER) - * ch - a channel id - * val - a pointer to a sample data vector - * d - a dimmention of sample data vector - * meta - a pointer to metadata - * mlen - a length of metadata - * - ****************************************************************************/ - -int nxscope_put_user_m(FAR struct nxscope_s *s, uint8_t ch, - uint8_t type, - FAR uint8_t *val, uint8_t d, - FAR uint8_t *meta, uint8_t mlen) -{ - /* User specific type */ - - return nxscope_put_common_m(s, type, ch, val, d, meta, mlen); -} -#endif - -/**************************************************************************** - * Name: nxscope_put_user_m - * - * Description: - * Put a point on the stream buffer - * - * Input Parameters: - * s - a pointer to a nxscope instance - * ch - a channel id - * val - sample data - * - ****************************************************************************/ - -/**************************************************************************** - * Name: nxscope_put_uint8 - ****************************************************************************/ - -int nxscope_put_uint8(FAR struct nxscope_s *s, uint8_t ch, uint8_t val) -{ - return nxscope_put_vuint8(s, ch, &val, 1); -} - -/**************************************************************************** - * Name: nxscope_put_int8 - ****************************************************************************/ - -int nxscope_put_int8(FAR struct nxscope_s *s, uint8_t ch, int8_t val) -{ - return nxscope_put_vint8(s, ch, &val, 1); -} - -/**************************************************************************** - * Name: nxscope_put_uint16 - ****************************************************************************/ - -int nxscope_put_uint16(FAR struct nxscope_s *s, uint8_t ch, uint16_t val) -{ - return nxscope_put_vuint16(s, ch, &val, 1); -} - -/**************************************************************************** - * Name: nxscope_put_int16 - ****************************************************************************/ - -int nxscope_put_int16(FAR struct nxscope_s *s, uint8_t ch, int16_t val) -{ - return nxscope_put_vint16(s, ch, &val, 1); -} - -/**************************************************************************** - * Name: nxscope_put_uint32 - ****************************************************************************/ - -int nxscope_put_uint32(FAR struct nxscope_s *s, uint8_t ch, uint32_t val) -{ - return nxscope_put_vuint32(s, ch, &val, 1); -} - -/**************************************************************************** - * Name: nxscope_put_int32 - ****************************************************************************/ - -int nxscope_put_int32(FAR struct nxscope_s *s, uint8_t ch, int32_t val) -{ - return nxscope_put_vint32(s, ch, &val, 1); -} - -/**************************************************************************** - * Name: nxscope_put_uint64 - ****************************************************************************/ - -int nxscope_put_uint64(FAR struct nxscope_s *s, uint8_t ch, uint64_t val) -{ - return nxscope_put_vuint64(s, ch, &val, 1); -} - -/**************************************************************************** - * Name: nxscope_put_int64 - ****************************************************************************/ - -int nxscope_put_int64(FAR struct nxscope_s *s, uint8_t ch, int64_t val) -{ - return nxscope_put_vint64(s, ch, &val, 1); -} - -/**************************************************************************** - * Name: nxscope_put_float - ****************************************************************************/ - -int nxscope_put_float(FAR struct nxscope_s *s, uint8_t ch, float val) -{ - return nxscope_put_vfloat(s, ch, &val, 1); -} - -/**************************************************************************** - * Name: nxscope_put_double - ****************************************************************************/ - -int nxscope_put_double(FAR struct nxscope_s *s, uint8_t ch, double val) -{ - return nxscope_put_vdouble(s, ch, &val, 1); -} - -/**************************************************************************** - * Name: nxscope_put_ub8 - ****************************************************************************/ - -int nxscope_put_ub8(FAR struct nxscope_s *s, uint8_t ch, ub8_t val) -{ - return nxscope_put_vub8(s, ch, &val, 1); -} - -/**************************************************************************** - * Name: nxscope_put_b8 - ****************************************************************************/ - -int nxscope_put_b8(FAR struct nxscope_s *s, uint8_t ch, b8_t val) -{ - return nxscope_put_vb8(s, ch, &val, 1); -} - -/**************************************************************************** - * Name: nxscope_put_ub16 - ****************************************************************************/ - -int nxscope_put_ub16(FAR struct nxscope_s *s, uint8_t ch, ub16_t val) -{ - return nxscope_put_vub16(s, ch, &val, 1); -} - -/**************************************************************************** - * Name: nxscope_put_b16 - ****************************************************************************/ - -int nxscope_put_b16(FAR struct nxscope_s *s, uint8_t ch, b16_t val) -{ - return nxscope_put_vb16(s, ch, &val, 1); -} - -/**************************************************************************** - * Name: nxscope_put_ub32 - ****************************************************************************/ - -int nxscope_put_ub32(FAR struct nxscope_s *s, uint8_t ch, ub32_t val) -{ - return nxscope_put_vub32(s, ch, &val, 1); -} - -/**************************************************************************** - * Name: nxscope_put_b32 - ****************************************************************************/ - -int nxscope_put_b32(FAR struct nxscope_s *s, uint8_t ch, b32_t val) -{ - return nxscope_put_vb32(s, ch, &val, 1); -} - -/**************************************************************************** - * Name: nxscope_put_char - ****************************************************************************/ - -int nxscope_put_char(FAR struct nxscope_s *s, uint8_t ch, char val) -{ - return nxscope_put_vchar(s, ch, &val, 1); -} diff --git a/logging/nxscope/nxscope_idummy.c b/logging/nxscope/nxscope_idummy.c deleted file mode 100644 index f139ce4dd..000000000 --- a/logging/nxscope/nxscope_idummy.c +++ /dev/null @@ -1,196 +0,0 @@ -/**************************************************************************** - * apps/logging/nxscope/nxscope_idummy.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include -#include -#include - -#include - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -struct nxscope_intf_dummy_s -{ - FAR struct nxscope_dummy_cfg_s *cfg; -}; - -/**************************************************************************** - * Private Function Protototypes - ****************************************************************************/ - -static int nxscope_dummy_send(FAR struct nxscope_intf_s *intf, - FAR uint8_t *buff, int len); -static int nxscope_dummy_recv(FAR struct nxscope_intf_s *intf, - FAR uint8_t *buff, int len); - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static struct nxscope_intf_ops_s g_nxscope_dummy_ops = -{ - nxscope_dummy_send, - nxscope_dummy_recv -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: nxscope_dummy_send - ****************************************************************************/ - -static int nxscope_dummy_send(FAR struct nxscope_intf_s *intf, - FAR uint8_t *buff, int len) -{ - FAR struct nxscope_intf_dummy_s *priv = NULL; - - DEBUGASSERT(intf); - DEBUGASSERT(intf->priv); - - _info("nxscope_dummy_send\n"); - - /* Get priv data */ - - priv = (FAR struct nxscope_intf_dummy_s *)intf->priv; - - UNUSED(priv); - - /* Dump send buffer */ - - lib_dumpbuffer("nxscope_dummy_send", buff, len); - - return OK; -} - -/**************************************************************************** - * Name: nxscope_dummy_recv - ****************************************************************************/ - -static int nxscope_dummy_recv(FAR struct nxscope_intf_s *intf, - FAR uint8_t *buff, int len) -{ - FAR struct nxscope_intf_dummy_s *priv = NULL; - - DEBUGASSERT(intf); - DEBUGASSERT(intf->priv); - - _info("nxscope_dummy_recv\n"); - - /* Get priv data */ - - priv = (FAR struct nxscope_intf_dummy_s *)intf->priv; - - UNUSED(priv); - - /* Dump recv buffer */ - - lib_dumpbuffer("nxscope_dummy_recv", buff, len); - - return OK; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: nxscope_dummy_init - ****************************************************************************/ - -int nxscope_dummy_init(FAR struct nxscope_intf_s *intf, - FAR struct nxscope_dummy_cfg_s *cfg) -{ - FAR struct nxscope_intf_dummy_s *priv = NULL; - int ret = OK; - - DEBUGASSERT(intf); - DEBUGASSERT(cfg); - - _info("nxscope_dummy_init\n"); - - /* Allocate priv data */ - - intf->priv = zalloc(sizeof(struct nxscope_intf_dummy_s)); - if (intf->priv == NULL) - { - _err("ERROR: intf->priv alloc failed %d\n", errno); - ret = -errno; - goto errout; - } - - /* Get priv data */ - - priv = (FAR struct nxscope_intf_dummy_s *)intf->priv; - - /* Connect configuration */ - - priv->cfg = cfg; - - /* Connect ops */ - - intf->ops = &g_nxscope_dummy_ops; - - /* Initialized */ - - intf->initialized = true; - -errout: - return ret; -} - -/**************************************************************************** - * Name: nxscope_dummy_deinit - ****************************************************************************/ - -void nxscope_dummy_deinit(FAR struct nxscope_intf_s *intf) -{ - FAR struct nxscope_intf_dummy_s *priv = NULL; - - DEBUGASSERT(intf); - - _info("nxscope_dummy_deinit\n"); - - /* Get priv data */ - - priv = (FAR struct nxscope_intf_dummy_s *)intf->priv; - - if (priv != NULL) - { - free(priv); - } - - /* Reset structure */ - - memset(intf, 0, sizeof(struct nxscope_intf_s)); -} diff --git a/logging/nxscope/nxscope_internals.c b/logging/nxscope/nxscope_internals.c deleted file mode 100644 index b001b4187..000000000 --- a/logging/nxscope/nxscope_internals.c +++ /dev/null @@ -1,92 +0,0 @@ -/**************************************************************************** - * apps/logging/nxscope/nxscope_internals.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include -#include - -#include - -#include "nxscope_internals.h" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: nxscope_stream_send - * - * Description: - * Send stream buffer - * - * Input Parameters: - * s - a pointer to a nxscope instance - * buff - buffer to send - * buff_i - buffer cursor - * - ****************************************************************************/ - -int nxscope_stream_send(FAR struct nxscope_s *s, FAR uint8_t *buff, - FAR size_t *buff_i) -{ - int ret = OK; - - DEBUGASSERT(s); - DEBUGASSERT(buff); - DEBUGASSERT(buff_i); - - /* Finalize stream frame */ - - if (!s->stream_retry) - { - ret = PROTO_FRAME_FINAL(s, s->proto_stream, - NXSCOPE_HDRID_STREAM, buff, buff_i); - if (ret < 0) - { - _err("ERROR: PROTO_FRAME_FINAL failed %d\n", ret); - goto errout; - } - } - - /* Send stream data */ - - ret = INTF_SEND(s, s->intf_stream, buff, *buff_i); - if (ret < 0) - { - _err("ERROR: INTF_SEND failed %d\n", ret); - s->stream_retry = true; - } - else - { - s->stream_retry = false; - } - -errout: - return ret; -} diff --git a/logging/nxscope/nxscope_internals.h b/logging/nxscope/nxscope_internals.h deleted file mode 100644 index 622268b67..000000000 --- a/logging/nxscope/nxscope_internals.h +++ /dev/null @@ -1,74 +0,0 @@ -/**************************************************************************** - * apps/logging/nxscope/nxscope_internals.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __APPS_LOGGING_NXSCOPE_NXSCOPE_INTERNALS_H -#define __APPS_LOGGING_NXSCOPE_NXSCOPE_INTERNALS_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* Max channel name length */ - -#define CHAN_NAMELEN_MAX (32) - -/* Helpers */ - -#define PROTO_FRAME_FINAL(s, proto, id, buff, i) \ - (s)->proto_stream->ops->frame_final(proto, id, buff, i) -#define PROTO_FRAME_GET(s, proto, buff, i, frame) \ - (s)->proto_stream->ops->frame_get(proto, buff, i, frame) - -#define INTF_SEND(s, intf, buff, i) \ - (s)->intf_stream->ops->send(intf, buff, i) -#define INTF_RECV(s, intf, buff, i) \ - (s)->intf_stream->ops->recv(intf, buff, i) - -/**************************************************************************** - * Public Function Puttypes - ****************************************************************************/ - -/**************************************************************************** - * Name: nxscope_stream_send - * - * Description: - * Send stream buffers - * - * Input Parameters: - * s - a pointer to a nxscope instance - * buff - buffer to send - * buff_i - buffer cursor - * - ****************************************************************************/ - -int nxscope_stream_send(FAR struct nxscope_s *s, FAR uint8_t *buff, - FAR size_t *buff_i); - -#endif /* __APPS_LOGGING_NXSCOPE_NXSCOPE_INTERNALS_H */ diff --git a/logging/nxscope/nxscope_iser.c b/logging/nxscope/nxscope_iser.c deleted file mode 100644 index 492617723..000000000 --- a/logging/nxscope/nxscope_iser.c +++ /dev/null @@ -1,270 +0,0 @@ -/**************************************************************************** - * apps/logging/nxscope/nxscope_iser.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include -#include -#include -#include - -#include - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -struct nxscope_intf_ser_s -{ - FAR struct nxscope_ser_cfg_s *cfg; - int fd; -}; - -/**************************************************************************** - * Private Function Protototypes - ****************************************************************************/ - -static int nxscope_ser_send(FAR struct nxscope_intf_s *intf, - FAR uint8_t *buff, int len); -static int nxscope_ser_recv(FAR struct nxscope_intf_s *intf, - FAR uint8_t *buff, int len); - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static struct nxscope_intf_ops_s g_nxscope_ser_ops = -{ - nxscope_ser_send, - nxscope_ser_recv -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: nxscope_ser_send - ****************************************************************************/ - -static int nxscope_ser_send(FAR struct nxscope_intf_s *intf, - FAR uint8_t *buff, int len) -{ - FAR struct nxscope_intf_ser_s *priv = NULL; - - DEBUGASSERT(intf); - DEBUGASSERT(intf->priv); - - /* Get priv data */ - - priv = (FAR struct nxscope_intf_ser_s *)intf->priv; - - /* Write data */ - - return write(priv->fd, buff, len); -} - -/**************************************************************************** - * Name: nxscope_ser_recv - ****************************************************************************/ - -static int nxscope_ser_recv(FAR struct nxscope_intf_s *intf, - FAR uint8_t *buff, int len) -{ - FAR struct nxscope_intf_ser_s *priv = NULL; - int ret = OK; - - DEBUGASSERT(intf); - DEBUGASSERT(intf->priv); - - /* Get priv data */ - - priv = (FAR struct nxscope_intf_ser_s *)intf->priv; - - /* Read data */ - - ret = read(priv->fd, buff, len); - - if (ret < 0) - { - if (priv->cfg->nonblock && (errno == EAGAIN)) - { - ret = 0; - } - } - - return ret; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: nxscope_ser_init - ****************************************************************************/ - -int nxscope_ser_init(FAR struct nxscope_intf_s *intf, - FAR struct nxscope_ser_cfg_s *cfg) -{ - FAR struct nxscope_intf_ser_s *priv = NULL; - struct termios tio; - int ret = OK; - int flags = 0; - - DEBUGASSERT(intf); - DEBUGASSERT(cfg); - - /* Allocate priv data */ - - intf->priv = zalloc(sizeof(struct nxscope_intf_ser_s)); - if (intf->priv == NULL) - { - _err("ERROR: intf->priv alloc failed %d\n", errno); - ret = -errno; - goto errout; - } - - /* Get priv data */ - - priv = (FAR struct nxscope_intf_ser_s *)intf->priv; - - /* Connect configuration */ - - priv->cfg = (FAR struct nxscope_ser_cfg_s *)cfg; - - /* Connect ops */ - - intf->ops = &g_nxscope_ser_ops; - - /* Open serial port */ - - flags = O_RDWR; - - if (priv->cfg->nonblock) - { - flags |= O_NONBLOCK; - } - -#ifdef CONFIG_SERIAL_REMOVABLE - do - { - /* Try to open the console */ - - priv->fd = open(priv->cfg->path, flags); - if (priv->fd < 0) - { - /* ENOTCONN means that the USB device is not yet connected. - * Anything else is bad. - */ - - if (errno != ENOTCONN) - { - break; - } - - /* Sleep a bit and try again */ - - sleep(1); - } - } - while (priv->fd < 0); -#else - priv->fd = open(priv->cfg->path, flags); -#endif - if (priv->fd < 0) - { - _err("ERROR: failed to open %s %d\n", priv->cfg->path, errno); - ret = -errno; - goto errout; - } - - /* Get the attributes */ - - tcgetattr(priv->fd, &tio); - -#ifdef CONFIG_SERIAL_TERMIOS - if (priv->cfg->baud > 0) - { - /* Configure a baud rate */ - - ret = cfsetspeed(&tio, priv->cfg->baud); - if (ret < 0) - { - _err("ERROR: failed to set baud rate %d\n", errno); - goto errout; - } - } -#endif - - /* Configure RAW mode */ - - cfmakeraw(&tio); - - /* Change the attributes now */ - - tcsetattr(priv->fd, TCSANOW, &tio); - - /* Initialized */ - - intf->initialized = true; - -errout: - return ret; -} - -/**************************************************************************** - * Name: nxscope_ser_deinit - ****************************************************************************/ - -void nxscope_ser_deinit(FAR struct nxscope_intf_s *intf) -{ - FAR struct nxscope_intf_ser_s *priv = NULL; - - DEBUGASSERT(intf); - - /* Get priv data */ - - priv = (FAR struct nxscope_intf_ser_s *)intf->priv; - - /* Close dev */ - - if (priv->fd != -1) - { - close(priv->fd); - } - - if (priv != NULL) - { - free(priv); - } - - /* Reset structure */ - - memset(intf, 0, sizeof(struct nxscope_intf_s)); -} diff --git a/logging/nxscope/nxscope_iudp.c b/logging/nxscope/nxscope_iudp.c deleted file mode 100644 index 5a5e1eed0..000000000 --- a/logging/nxscope/nxscope_iudp.c +++ /dev/null @@ -1,271 +0,0 @@ -/**************************************************************************** - * apps/logging/nxscope/nxscope_iudp.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -struct nxscope_intf_udp_s -{ - FAR struct nxscope_udp_cfg_s *cfg; - int fd; - bool peer_valid; - struct sockaddr_in peer; -}; - -/**************************************************************************** - * Private Function Protototypes - ****************************************************************************/ - -static int nxscope_udp_send(FAR struct nxscope_intf_s *intf, - FAR uint8_t *buff, int len); -static int nxscope_udp_recv(FAR struct nxscope_intf_s *intf, - FAR uint8_t *buff, int len); - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static struct nxscope_intf_ops_s g_nxscope_udp_ops = -{ - nxscope_udp_send, - nxscope_udp_recv -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: nxscope_udp_send - ****************************************************************************/ - -static int nxscope_udp_send(FAR struct nxscope_intf_s *intf, - FAR uint8_t *buff, int len) -{ - FAR struct nxscope_intf_udp_s *priv = NULL; - - DEBUGASSERT(intf); - DEBUGASSERT(intf->priv); - - /* Get priv data */ - - priv = (FAR struct nxscope_intf_udp_s *)intf->priv; - - if (!priv->peer_valid) - { - return -ENOTCONN; - } - - return sendto(priv->fd, buff, len, 0, - (FAR const struct sockaddr *)&priv->peer, - sizeof(priv->peer)); -} - -/**************************************************************************** - * Name: nxscope_udp_recv - ****************************************************************************/ - -static int nxscope_udp_recv(FAR struct nxscope_intf_s *intf, - FAR uint8_t *buff, int len) -{ - FAR struct nxscope_intf_udp_s *priv = NULL; - struct sockaddr_in from; - socklen_t fromlen; - int ret = OK; - - DEBUGASSERT(intf); - DEBUGASSERT(intf->priv); - - /* Get priv data */ - - priv = (FAR struct nxscope_intf_udp_s *)intf->priv; - - fromlen = sizeof(from); - ret = recvfrom(priv->fd, buff, len, 0, (FAR struct sockaddr *)&from, - &fromlen); - - if (ret < 0) - { - if (priv->cfg->nonblock && (errno == EAGAIN || errno == EWOULDBLOCK)) - { - ret = 0; - } - - return ret; - } - - priv->peer = from; - priv->peer_valid = true; - - return ret; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: nxscope_udp_init - ****************************************************************************/ - -int nxscope_udp_init(FAR struct nxscope_intf_s *intf, - FAR struct nxscope_udp_cfg_s *cfg) -{ - FAR struct nxscope_intf_udp_s *priv = NULL; - struct sockaddr_in addr; - int ret = OK; - int flags = 0; - - DEBUGASSERT(intf); - DEBUGASSERT(cfg); - - /* Allocate priv data */ - - intf->priv = zalloc(sizeof(struct nxscope_intf_udp_s)); - if (intf->priv == NULL) - { - _err("ERROR: intf->priv alloc failed %d\n", errno); - ret = -errno; - goto errout; - } - - /* Get priv data */ - - priv = (FAR struct nxscope_intf_udp_s *)intf->priv; - priv->fd = -1; - - /* Connect configuration */ - - priv->cfg = (FAR struct nxscope_udp_cfg_s *)cfg; - - /* Connect ops */ - - intf->ops = &g_nxscope_udp_ops; - - /* Open UDP socket */ - - priv->fd = socket(AF_INET, SOCK_DGRAM, 0); - if (priv->fd < 0) - { - _err("ERROR: failed to create UDP socket %d\n", errno); - ret = -errno; - goto errout; - } - - /* Configure non-blocking if enabled */ - - if (priv->cfg->nonblock) - { - flags = fcntl(priv->fd, F_GETFL, 0); - if (flags < 0) - { - _err("ERROR: failed to get socket flags %d\n", errno); - ret = -errno; - goto errout; - } - - ret = fcntl(priv->fd, F_SETFL, flags | O_NONBLOCK); - if (ret < 0) - { - _err("ERROR: failed to set O_NONBLOCK %d\n", errno); - ret = -errno; - goto errout; - } - } - - memset(&addr, 0, sizeof(addr)); - addr.sin_family = AF_INET; - addr.sin_addr.s_addr = INADDR_ANY; - addr.sin_port = htons(priv->cfg->port); - - ret = bind(priv->fd, (FAR struct sockaddr *)&addr, sizeof(addr)); - if (ret < 0) - { - _err("ERROR: failed to bind UDP port %u errno=%d\n", - priv->cfg->port, - errno); - ret = -errno; - goto errout; - } - - /* Initialized */ - - intf->initialized = true; - return OK; - -errout: - if (priv != NULL && priv->fd >= 0) - { - close(priv->fd); - priv->fd = -1; - } - - return ret; -} - -/**************************************************************************** - * Name: nxscope_udp_deinit - ****************************************************************************/ - -void nxscope_udp_deinit(FAR struct nxscope_intf_s *intf) -{ - FAR struct nxscope_intf_udp_s *priv = NULL; - - DEBUGASSERT(intf); - - /* Get priv data */ - - priv = (FAR struct nxscope_intf_udp_s *)intf->priv; - - if (priv != NULL && priv->fd != -1) - { - close(priv->fd); - } - - if (priv != NULL) - { - free(priv); - } - - /* Reset structure */ - - memset(intf, 0, sizeof(struct nxscope_intf_s)); -} diff --git a/logging/nxscope/nxscope_pser.c b/logging/nxscope/nxscope_pser.c deleted file mode 100644 index 2f8d5ad41..000000000 --- a/logging/nxscope/nxscope_pser.c +++ /dev/null @@ -1,305 +0,0 @@ -/**************************************************************************** - * apps/logging/nxscope/nxscope_pser.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include -#include -#include - -#include - -#include - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define NXSCOPE_HDR_LEN (sizeof(struct nxscope_hdr_s)) -#define NXSCOPE_DATA_START (NXSCOPE_HDR_LEN) -#define NXSCOPE_BASEFRAME_LEN (NXSCOPE_HDR_LEN + NXSCOPE_CRC_LEN) -#define NXSCOPE_HDR_SOF (0x55) -#define NXSCOPE_CRC_LEN (sizeof(uint16_t)) - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/* Nxscope serial protocol frame: - * +--------------------+------------+-------------+ - * | HDR [4B] | frame data | footer [2B] | - * +-----+---------+----+------------+-------------+ - * | SOF | len [1] | id | frame data | crc16 [2] | - * +-----+----+----+----+------------+------+------+ - * | 0 | 1 | 2 | 3 | ... | n+1 | n+2 | - * +-----+----+----+----+------------+------+------+ - * - * [1] - always little-endian - * [2] - always big-endian - */ - -/* Nxscope header */ - -begin_packed_struct struct nxscope_hdr_s -{ - uint8_t sof; /* SOF */ - uint16_t len; /* Frame length */ - uint8_t id; /* Frame ID */ -} end_packed_struct; - -/* Nxscope footer */ - -begin_packed_struct struct nxscope_footer_s -{ - uint16_t crc16; /* check sum (see nxscope_frame_final()) */ -} end_packed_struct; - -/**************************************************************************** - * Private Function Protototypes - ****************************************************************************/ - -static int nxscope_frame_get(FAR struct nxscope_proto_s *p, - FAR uint8_t *buff, size_t len, - FAR struct nxscope_frame_s *frame); -static int nxscope_frame_final(FAR struct nxscope_proto_s *p, - uint8_t id, - FAR uint8_t *buff, FAR size_t *len); - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -static struct nxscope_proto_ops_s g_nxscope_proto_ser_ops = -{ - nxscope_frame_get, - nxscope_frame_final, -}; - -static struct nxscope_proto_s g_nxscope_proto_ser = -{ - false, - NULL, - &g_nxscope_proto_ser_ops, - (size_t)NXSCOPE_HDR_LEN, - (size_t)NXSCOPE_CRC_LEN -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: nxscope_hdr_fill - ****************************************************************************/ - -static void nxscope_hdr_fill(FAR uint8_t *buff, uint8_t id, uint16_t len) -{ - FAR struct nxscope_hdr_s *hdr = NULL; - - DEBUGASSERT(buff); - - hdr = (FAR struct nxscope_hdr_s *)buff; - - hdr->sof = NXSCOPE_HDR_SOF; - - /* Length always as little endian */ - - hdr->len = htole16(len); - hdr->id = id; -} - -/**************************************************************************** - * Name: nxscope_frame_get - ****************************************************************************/ - -static int nxscope_frame_get(FAR struct nxscope_proto_s *p, - FAR uint8_t *buff, size_t len, - FAR struct nxscope_frame_s *frame) -{ - FAR struct nxscope_hdr_s *hdr = NULL; - uint16_t crc = 0; - int ret = OK; - int i = 0; - - DEBUGASSERT(p); - DEBUGASSERT(buff); - DEBUGASSERT(frame); - - UNUSED(p); - - /* Find SOF */ - - for (i = 0; i < len - NXSCOPE_HDR_LEN; i++) - { - hdr = (FAR struct nxscope_hdr_s *)&buff[i]; - - /* Verify SOF */ - - if (hdr->sof == NXSCOPE_HDR_SOF) - { - break; - } - } - - /* Check for no header */ - - if (hdr == NULL) - { - ret = -EINVAL; - goto errout; - } - - /* Check for no SOF in header */ - - if (hdr->sof != NXSCOPE_HDR_SOF) - { - ret = -EINVAL; - goto errout; - } - - /* Verify len - always little-endian */ - - hdr->len = htole16(hdr->len); - - if ((len - i) < hdr->len) - { - ret = -EINVAL; - goto errout; - } - - /* Verify crc16 for the whole frame */ - - crc = crc16xmodem(&buff[i], hdr->len); - if (crc != 0) - { - _err("ERROR: invalid crc16 %d\n", crc); - ret = -EINVAL; - goto errout; - } - - /* Return the frame data */ - - frame->id = hdr->id; - frame->data = &buff[i + NXSCOPE_DATA_START]; - frame->drop = hdr->len + i; - frame->dlen = hdr->len - NXSCOPE_BASEFRAME_LEN; - -errout: - return ret; -} - -/**************************************************************************** - * Name: nxscope_frame_final - ****************************************************************************/ - -static int nxscope_frame_final(FAR struct nxscope_proto_s *p, - uint8_t id, - FAR uint8_t *buff, FAR size_t *len) -{ - uint16_t crc = 0; - int ret = OK; - - DEBUGASSERT(p); - DEBUGASSERT(buff); - DEBUGASSERT(len); - - if (*len <= NXSCOPE_HDR_LEN) - { - /* No data */ - - ret = -ENODATA; - goto errout; - } - - /* Fill hdr */ - - nxscope_hdr_fill(buff, id, *len + NXSCOPE_CRC_LEN); - - /* Add crc16 - always as big-endian. - * - * crc16 xmodem: - * polynominal = 0x1021 - * initial value = 0x0000 - * final xor value = 0x0000 - */ - - crc = crc16xmodem(buff, *len); - -#ifdef CONFIG_ENDIAN_BIG - buff[(*len)++] = (crc >> 0) & 0xff; - buff[(*len)++] = (crc >> 8) & 0xff; -#else - buff[(*len)++] = (crc >> 8) & 0xff; - buff[(*len)++] = (crc >> 0) & 0xff; -#endif - -errout: - return ret; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: nxscope_proto_ser_init - ****************************************************************************/ - -int nxscope_proto_ser_init(FAR struct nxscope_proto_s *proto, FAR void *cfg) -{ - DEBUGASSERT(proto); - - /* cfg argument not used, but kept here for compatibility with - * future protocol implementations. - */ - - UNUSED(cfg); - - /* Just copy protocol data */ - - memcpy(proto, &g_nxscope_proto_ser, sizeof(struct nxscope_proto_s)); - - /* Initialized */ - - proto->initialized = true; - - return OK; -} - -/**************************************************************************** - * Name: nxscope_proto_ser_deinit - ****************************************************************************/ - -void nxscope_proto_ser_deinit(FAR struct nxscope_proto_s *proto) -{ - DEBUGASSERT(proto); - - /* Nothings here */ - - UNUSED(proto); -} diff --git a/lte/.gitignore b/lte/.gitignore deleted file mode 100644 index 99f41601f..000000000 --- a/lte/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/Kconfig - diff --git a/lte/CMakeLists.txt b/lte/CMakeLists.txt deleted file mode 100644 index 44b08a292..000000000 --- a/lte/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -# ############################################################################## -# apps/lte/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -nuttx_add_subdirectory() - -nuttx_generate_kconfig(MENUDESC "LTE Libraries and NSH Add-Ons") diff --git a/lte/Make.defs b/lte/Make.defs deleted file mode 100644 index 70956ea21..000000000 --- a/lte/Make.defs +++ /dev/null @@ -1,23 +0,0 @@ -############################################################################ -# apps/lte/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -include $(wildcard lte/*/Make.defs) diff --git a/lte/Makefile b/lte/Makefile deleted file mode 100644 index 4fe43e7e9..000000000 --- a/lte/Makefile +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/lte/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -MENUDESC = "LTE Libraries and NSH Add-Ons" - -include $(APPDIR)/Directory.mk diff --git a/lte/alt1250/CMakeLists.txt b/lte/alt1250/CMakeLists.txt deleted file mode 100644 index c54f8e1e0..000000000 --- a/lte/alt1250/CMakeLists.txt +++ /dev/null @@ -1,88 +0,0 @@ -# ############################################################################## -# apps/lte/alt1250/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_LTE_ALT1250) - - set(INCDIR - ${CMAKE_CURRENT_LIST_DIR} ${CMAKE_CURRENT_LIST_DIR}/callback_handlers - ${CMAKE_CURRENT_LIST_DIR}/usock_handlers) - - # Application info - - nuttx_add_application( - NAME - ${CONFIG_LTE_ALT1250_PROGNAME} - SRCS - alt1250_main.c - STACKSIZE - ${CONFIG_LTE_ALT1250_STACKSIZE} - PRIORITY - ${CONFIG_LTE_ALT1250_PRIORITY} - INCLUDE_DIRECTORIES - ${INCDIR}) - - set(CSRCS - # Framework source files - alt1250_container.c - alt1250_devevent.c - alt1250_devif.c - alt1250_select.c - alt1250_socket.c - alt1250_usockevent.c - alt1250_usockif.c - alt1250_netdev.c - alt1250_util.c - alt1250_reset_seq.c - alt1250_atcmd.c - # Callback task sources - callback_handlers/alt1250_evt.c - # Usersock request handling source files - usock_handlers/alt1250_sockethdlr.c - usock_handlers/alt1250_closehdlr.c - usock_handlers/alt1250_connecthdlr.c - usock_handlers/alt1250_sendtohdlr.c - usock_handlers/alt1250_recvfromhdlr.c - usock_handlers/alt1250_setsockopthdlr.c - usock_handlers/alt1250_getsockopthdlr.c - usock_handlers/alt1250_getsocknamehdlr.c - usock_handlers/alt1250_getpeernamehdlr.c - usock_handlers/alt1250_bindhdlr.c - usock_handlers/alt1250_listenhdlr.c - usock_handlers/alt1250_accepthdlr.c - usock_handlers/alt1250_ioctlhdlr.c - usock_handlers/alt1250_shutdownhdlr.c - usock_handlers/alt1250_sms.c - # Usersock ioctl LAPI command handling source files - usock_handlers/alt1250_ioctl_ltecmd.c - usock_handlers/alt1250_ioctl_ifreq.c - usock_handlers/alt1250_ioctl_normal.c - usock_handlers/alt1250_ioctl_event.c - usock_handlers/alt1250_ioctl_other.c - usock_handlers/alt1250_ioctl_power.c - usock_handlers/alt1250_ioctl_fwupdate.c - usock_handlers/alt1250_ioctl_denyinetsock.c - usock_handlers/alt1250_ioctl_lwm2m.c) - - nuttx_add_library(alt1250) - target_sources(alt1250 PRIVATE ${CSRCS}) - target_include_directories(alt1250 PRIVATE ${INCDIR}) -endif() diff --git a/lte/alt1250/Kconfig b/lte/alt1250/Kconfig deleted file mode 100644 index 7b12900bf..000000000 --- a/lte/alt1250/Kconfig +++ /dev/null @@ -1,160 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config LTE_ALT1250 - tristate "ALT1250 usrsock daemon" - default n - depends on NET_USRSOCK && MODEM_ALT1250 - select NET_USRSOCK_TCP - select NET_USRSOCK_ICMP - select PIPES - select NET_USRSOCK_OTHER - ---help--- - Enable support for the alt1250 usrsock daemon - -if LTE_ALT1250 -config LTE_ALT1250_PROGNAME - string "alt1250 program name" - default "alt1250" - -config LTE_ALT1250_PRIORITY - int "alt1250 task priority" - default 100 - -config LTE_ALT1250_STACKSIZE - int "alt1250 stack size" - default 2048 - -config LTE_ALT1250_ENABLE_HIBERNATION_MODE - bool "Enable LTE hibernation mode" - default n - depends on PM - ---help--- - Enable LTE hibernation mode to reduce current - consumption during communication standby. - -menu "SMS configuration" - -config LTE_ALT1250_SMS_TOA - bool "Configure type of address of destination address" - default n - ---help--- - Change the type of address of the destination address. - -choice - prompt "Configure Nature of Address Indicator" - depends on LTE_ALT1250_SMS_TOA - -config LTE_ALT1250_SMS_NAI_UNKNOWN - bool "Unkown" - -config LTE_ALT1250_SMS_NAI_INTERNATIONAL - bool "International number" - -config LTE_ALT1250_SMS_NAI_NATIONAL - bool "National number" - -config LTE_ALT1250_SMS_NAI_NETWORK_SPEC - bool "Network specific number" - -config LTE_ALT1250_SMS_NAI_SUBSCRIBER - bool "Subscriber number" - -config LTE_ALT1250_SMS_NAI_ALPANUMERIC - bool "Alphanumeric" - -config LTE_ALT1250_SMS_NAI_ABBREVIATED - bool "Abbreviated number" - -config LTE_ALT1250_SMS_NAI_RESERVED - bool "Reserved for extension" - -endchoice # Configure Nature of Address Indicator - -choice - prompt "Configure Numbering Plan Indicator" - depends on LTE_ALT1250_SMS_TOA - -config LTE_ALT1250_SMS_NPI_UNKNOWN - bool "Unkown" - -config LTE_ALT1250_SMS_NPI_ISDN - bool "ISDN/telephone numbering plan" - -config LTE_ALT1250_SMS_NPI_DATA - bool "Data numbering plan" - -config LTE_ALT1250_SMS_NPI_TELEX - bool "Telex numbering plan" - -config LTE_ALT1250_SMS_NPI_SERVICE_CENTRE_SPEC - bool "Service Centre Specific plan" - -config LTE_ALT1250_SMS_NPI_SERVICE_CENTRE_SPEC2 - bool "Service Centre Specific plan-2" - -config LTE_ALT1250_SMS_NPI_NATIONAL - bool "National numbering plan" - -config LTE_ALT1250_SMS_NPI_PRIVATE - bool "Private numbering plan" - -config LTE_ALT1250_SMS_NPI_ERMES - bool "ERMES numbering plan" - -config LTE_ALT1250_SMS_NPI_RESERVED - bool "Reserved for extension" - -endchoice # Configure Numbering Plan Indicator - -endmenu # SMS configuration - -config LTE_ALT1250_EXTEND_IOCTL - bool "Enabling extended ioctl handler" - default n - -config LTE_ALT1250_LAUNCH_EVENT_TASK - bool "Launches an internal task to handle events" - default y - ---help--- - Launches an internal task to handle the event. - It is also possible to disable this option and handle events with a user task. - If disabled, use lapi_evtinit() and lapi_evtyield(). - -if LTE_ALT1250_LAUNCH_EVENT_TASK - -config LTE_ALT1250_EVENT_TASK_PRIORITY - int "internal task priority" - default 100 - -config LTE_ALT1250_EVENT_TASK_STACKSIZE - int "internal task stack size" - default 2048 - -endif - -config LTE_ALT1250_CONTAINERS - int "Number of containers" - default 10 - range 1 255 - ---help--- - Determines the maximum number of containers. - The container is a buffer used to communicate with the ALT1250 - that contains the relevant information for communication. - Increasing this value may improve the performance during parallel processing. - On the other hand, decreasing this value will reduce the memory usage. - -config LTE_ALT1250_CONTROL_SOCKETS - int "Number of sockets for control" - default 3 - range 1 10 - ---help--- - Determines the maximum number of sockets used for LAPI and SMS. - -config LTE_ALT1250_DEBUG_MSG - bool "Enable debug output messages" - default n - -endif diff --git a/lte/alt1250/Make.defs b/lte/alt1250/Make.defs deleted file mode 100644 index 4b0fbab09..000000000 --- a/lte/alt1250/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/lte/alt1250/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_LTE_ALT1250),) -CONFIGURED_APPS += $(APPDIR)/lte/alt1250 -endif diff --git a/lte/alt1250/Makefile b/lte/alt1250/Makefile deleted file mode 100644 index 7f1ee1e2c..000000000 --- a/lte/alt1250/Makefile +++ /dev/null @@ -1,89 +0,0 @@ -############################################################################ -# apps/lte/alt1250/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -# alt1250 command - -PROGNAME = $(CONFIG_LTE_ALT1250_PROGNAME) -PRIORITY = $(CONFIG_LTE_ALT1250_PRIORITY) -STACKSIZE = $(CONFIG_LTE_ALT1250_STACKSIZE) -MODULE = $(CONFIG_LTE_ALT1250) - -VPATH += callback_handlers usock_handlers -CSRCS = - -# Framework source files - -CSRCS += alt1250_container.c -CSRCS += alt1250_devevent.c -CSRCS += alt1250_devif.c -CSRCS += alt1250_select.c -CSRCS += alt1250_socket.c -CSRCS += alt1250_usockevent.c -CSRCS += alt1250_usockif.c -CSRCS += alt1250_netdev.c -CSRCS += alt1250_util.c -CSRCS += alt1250_reset_seq.c -CSRCS += alt1250_atcmd.c - -# Callback task sources - -CSRCS += alt1250_evt.c - -# Usersock request handling source files - -CSRCS += alt1250_sockethdlr.c -CSRCS += alt1250_closehdlr.c -CSRCS += alt1250_connecthdlr.c -CSRCS += alt1250_sendtohdlr.c -CSRCS += alt1250_recvfromhdlr.c -CSRCS += alt1250_setsockopthdlr.c -CSRCS += alt1250_getsockopthdlr.c -CSRCS += alt1250_getsocknamehdlr.c -CSRCS += alt1250_getpeernamehdlr.c -CSRCS += alt1250_bindhdlr.c -CSRCS += alt1250_listenhdlr.c -CSRCS += alt1250_accepthdlr.c -CSRCS += alt1250_ioctlhdlr.c -CSRCS += alt1250_shutdownhdlr.c -CSRCS += alt1250_sms.c - -# Usersock ioctl LAPI command handling source files - -CSRCS += alt1250_ioctl_ltecmd.c -CSRCS += alt1250_ioctl_ifreq.c -CSRCS += alt1250_ioctl_normal.c -CSRCS += alt1250_ioctl_event.c -CSRCS += alt1250_ioctl_other.c -CSRCS += alt1250_ioctl_power.c -CSRCS += alt1250_ioctl_fwupdate.c -CSRCS += alt1250_ioctl_denyinetsock.c -CSRCS += alt1250_ioctl_lwm2m.c - -MAINSRC = alt1250_main.c - -CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/lte/alt1250 -CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/lte/alt1250/callback_handlers -CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/lte/alt1250/usock_handlers - -include $(APPDIR)/Application.mk diff --git a/lte/alt1250/README.txt b/lte/alt1250/README.txt deleted file mode 100644 index 9ca1c5499..000000000 --- a/lte/alt1250/README.txt +++ /dev/null @@ -1,68 +0,0 @@ -NOTICE: -======= - This document should be opened in a text editor with a width of at least 150 characters. - -alt1250 usrsock daemon -====================== - - This software module is a usrsock daemon in NuttX for ALT1250 modem. - The ALT1250 modem is a modem provided by Sony Semiconductor Israel. And it supports LTE Cat-M1 and NB-IoT network. - - -Implementation Structure -======================== - Call registerd functions - <-------------------------------------------------+ - | -+-------------------------------------------------------------------------------------------------------------------------------- | -------------+ -| alt1250_daemon | | -| ~~~~~~~~~~~~~~ Response | | -| +----------------------------------------------------------------------------------+ | | -| | | | | -| V Response _________________________________________________________ | +--------------------------+ | -| +------------- | usrsock handlers | post process | | +-------------> | Event call back task | | -| | +_____________________________________+_________________+ | | +--> | to an application | | -| | | socket handler | postproc_socket | | | | +--------------------------+ | -| | |D | bind handler | postproc_bind | | | | | -| | |I | listen handler | postproc_listen | <-----+ | | | | -| | |S | . | . | | | | | | -| | |P | . | . | Call | | | | | -| | +-----> |A | . | . | Back | | | Event | | -| | | |T |---------------+---------------------+-----------------| | | | Message | | -| | | |C | ioctl handler | lapi power handler | postproc_XXXX | | | | | | -| | | |H | lapi normal handler | postproc_XXXX | | | | | | -| | | | | lapi ifreq handler | postproc_XXXX | ___________________________________________________________________ | -| | | usrsock | lapi ltecmd handler | postproc_XXXX | | Command Reply | Reset Event | Asynchronous Event | Select Event | | -| | | request | | . | . | |-----------------------------------------------------------------| | -| | | | . | . | | Device event handling | | -| | | +-------------------------------------------------------+ +-----------------------------------------------------------------+ | -| | | | | / | -+-- | - | ---------------------------------- | ------------------ | ------------------------------------ | --------------------------------------+ - | | | Send Command | | Event notify - V | V V | --- /dev/usrsock -- ----------------------------------- /dev/alt1250 ----------------------------------- -+----------------+ +----------------------------------------------------------------------------------+ -| User Sock | | ALT1250 Device Driver | -+----------------+ +----------------------------------------------------------------------------------+ - +---------------------------------------++-----------------------------------------+ - | SPI Driver || GPIO Driver | - +---------------------------------------++-----------------------------------------+ - -Behavior Overview -================= - - Basically, alt1250_daemon receives a request from NutX User Sock and performs the expected processing according to the request. - - Each request is processed by its own "usrsock handler" depending on its type, and the result is returned to the User Sock as a - response. To achieve each of these operations, the "usrsock handler" sends a command to the alt1250 device driver. The post process - function is registerd in the command to process the command response if necessary. - - The command is sent to the ALT1250 via SPI, and the ALT1250 returns a response according to the command to notify alt1250_daemon. - The alt1250_daemon receives the command response from that notification and either returns the response to User Sock or calls the - "post process function" that was registered by the "usrsock handler". "post process" will return a response or send further - commands to ALT1250 depending on the content of the request. - - The ALT1250 may make event notifications, and these notifications are asynchronous. ALT1250 asynchronous events are notified by the - device driver as well as command responses, and when the alt1250_daemon receives them, it passes them to a task for callback to - notify the user application. - diff --git a/lte/alt1250/alt1250_atcmd.c b/lte/alt1250/alt1250_atcmd.c deleted file mode 100644 index 2b4558518..000000000 --- a/lte/alt1250/alt1250_atcmd.c +++ /dev/null @@ -1,986 +0,0 @@ -/**************************************************************************** - * apps/lte/alt1250/alt1250_atcmd.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -#include -#include -#include - -#include "alt1250_dbg.h" -#include "alt1250_daemon.h" -#include "alt1250_atcmd.h" -#include "alt1250_devif.h" -#include "alt1250_postproc.h" -#include "alt1250_container.h" -#include "alt1250_usockevent.h" - -#include - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -struct atcmd_postprocarg_t -{ - atcmd_postproc_t proc; - unsigned long arg; -}; - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static FAR void *atcmd_oargs[3]; -static int atcmd_reply_len; -static struct atcmd_postprocarg_t postproc_argument; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * name: postproc_internal_atcmd - ****************************************************************************/ - -static int postproc_internal_atcmd(FAR struct alt1250_s *dev, - FAR struct alt_container_s *reply, - FAR struct usock_s *usock, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo, - unsigned long arg) -{ - int ret = REP_NO_ACK; - FAR struct atcmd_postprocarg_t *parg = - (FAR struct atcmd_postprocarg_t *)arg; - - dev->recvfrom_processing = false; - - err_alt1250("Internal ATCMD Resp : %s\n", (FAR char *)reply->outparam[0]); - - if (parg->proc != NULL) - { - ret = parg->proc(dev, reply, - (FAR char *)reply->outparam[0], *(FAR int *)reply->outparam[2], - parg->arg, usock_result); - } - - return ret; -} - -/**************************************************************************** - * name: get_m2mrespstr - ****************************************************************************/ - -static FAR const char *get_m2mrespstr(int resp) -{ - FAR const char *ret = NULL; - - switch (resp) - { - case LWM2MSTUB_RESP_CHANGED: - ret = "2.04"; - break; - case LWM2MSTUB_RESP_CONTENT: - ret = "2.05"; - break; - case LWM2MSTUB_RESP_BADREQ: - ret = "4.00"; - break; - case LWM2MSTUB_RESP_UNAUTH: - ret = "4.01"; - break; - case LWM2MSTUB_RESP_NOURI: - ret = "4.04"; - break; - case LWM2MSTUB_RESP_NOTALLOW: - ret = "4.05"; - break; - case LWM2MSTUB_RESP_NOTACCEPT: - ret = "4.06"; - break; - case LWM2MSTUB_RESP_UNSUPPORT: - ret = "4.15"; - break; - case LWM2MSTUB_RESP_INTERNALERROR: - ret = "5.00"; - break; - } - - return ret; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * name: atcmdreply_true_false - ****************************************************************************/ - -int atcmdreply_true_false(FAR struct alt1250_s *dev, - FAR struct alt_container_s *reply, - FAR char *rdata, int len, unsigned long arg, - FAR int32_t *usock_result) -{ - *usock_result = 0; - - if (strcasestr(rdata, "\nTRUE\r")) - { - *usock_result = 1; - } - - return REP_SEND_ACK; -} - -/**************************************************************************** - * name: atcmdreply_ok_error - ****************************************************************************/ - -int atcmdreply_ok_error(FAR struct alt1250_s *dev, - FAR struct alt_container_s *reply, - FAR char *rdata, int len, unsigned long arg, - FAR int32_t *usock_result) -{ - *usock_result = check_atreply_ok(rdata, len, NULL); - return REP_SEND_ACK; -} - -/**************************************************************************** - * name: check_atreply_ok - ****************************************************************************/ - -int check_atreply_ok(FAR char *reply, int len, FAR void *arg) -{ - int ret = ERROR; - - if (strstr(reply, "\nOK\r")) - { - ret = OK; - } - - return ret; -} - -/**************************************************************************** - * name: check_atreply_truefalse - ****************************************************************************/ - -int check_atreply_truefalse(FAR char *reply, int len, FAR void *arg) -{ - int ret = ERROR; - FAR struct atreply_truefalse_s *result = - (FAR struct atreply_truefalse_s *)arg; - - if (check_atreply_ok(reply, len, NULL) == OK) - { - ret = OK; - if (strstr(reply, result->target_str)) - { - result->result = true; - } - else - { - result->result = false; - } - } - - return ret; -} - -/**************************************************************************** - * name: send_internal_at_command - ****************************************************************************/ - -static int send_internal_at_command(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, int16_t usockid, - atcmd_postproc_t proc, unsigned long arg, FAR int32_t *usock_result) -{ - int ret; - - FAR void *inparam[2]; - - inparam[0] = dev->tx_buff; - inparam[1] = (FAR void *)strlen((FAR const char *)dev->tx_buff); - - atcmd_oargs[0] = dev->rx_buff; - atcmd_oargs[1] = (FAR void *)_RX_BUFF_SIZE; - atcmd_oargs[2] = &atcmd_reply_len; - - postproc_argument.proc = proc; - postproc_argument.arg = arg; - - set_container_ids(container, usockid, LTE_CMDID_SENDATCMD); - set_container_argument(container, inparam, nitems(inparam)); - set_container_response(container, atcmd_oargs, nitems(atcmd_oargs)); - set_container_postproc(container, postproc_internal_atcmd, - (unsigned long)&postproc_argument); - - err_alt1250("Internal ATCMD : %s\n", dev->tx_buff); - - ret = altdevice_send_command(dev, dev->altfd, container, usock_result); - if (ret == REP_NO_ACK) - { - /* In case of no error */ - - dev->recvfrom_processing = true; - } - - return ret; -} - -/**************************************************************************** - * name: lwm2mstub_send_reset - ****************************************************************************/ - -int lwm2mstub_send_reset(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container) -{ - int32_t dummy; - snprintf((FAR char *)dev->tx_buff, _TX_BUFF_SIZE, "ATZ\r"); - return send_internal_at_command(dev, container, -1, NULL, 0, &dummy); -} - -/**************************************************************************** - * name: lwm2mstub_send_setenable - ****************************************************************************/ - -int lwm2mstub_send_setenable(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, bool en) -{ - int32_t dummy; - snprintf((FAR char *)dev->tx_buff, _TX_BUFF_SIZE, - "AT%%SETACFG=modem_apps.LWM2M.AppEnable,\"%s\"\r", - en ? "true" : "false"); - return send_internal_at_command(dev, container, -1, NULL, 0, &dummy); -} - -/**************************************************************************** - * name: lwm2mstub_send_getenable - ****************************************************************************/ - -int lwm2mstub_send_getenable(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - FAR int32_t *usock_result) -{ - snprintf((FAR char *)dev->tx_buff, _TX_BUFF_SIZE, - "AT%%GETACFG=modem_apps.LWM2M.AppEnable\r"); - return send_internal_at_command(dev, container, -1, NULL, 0, usock_result); -} - -/**************************************************************************** - * name: lwm2mstub_send_getnamemode - ****************************************************************************/ - -int lwm2mstub_send_getnamemode(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container) -{ - int32_t dummy; - snprintf((FAR char *)dev->tx_buff, _TX_BUFF_SIZE, - "AT%%GETACFG=LWM2M.Config.NameMode\r"); - return send_internal_at_command(dev, container, -1, NULL, 0, &dummy); -} - -/**************************************************************************** - * name: lwm2mstub_send_setnamemode - ****************************************************************************/ - -int lwm2mstub_send_setnamemode(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - int mode) -{ - int32_t dummy; - snprintf((FAR char *)dev->tx_buff, _TX_BUFF_SIZE, - "AT%%SETACFG=LWM2M.Config.NameMode,%d\r", mode); - return send_internal_at_command(dev, container, -1, NULL, 0, &dummy); -} - -/**************************************************************************** - * name: lwm2mstub_send_getversion - ****************************************************************************/ - -int lwm2mstub_send_getversion(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container) -{ - int32_t dummy; - snprintf((FAR char *)dev->tx_buff, _TX_BUFF_SIZE, - "AT%%GETACFG=LWM2M.Config.Version\r"); - return send_internal_at_command(dev, container, -1, NULL, 0, &dummy); -} - -/**************************************************************************** - * name: lwm2mstub_send_setversion - ****************************************************************************/ - -int lwm2mstub_send_setversion(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - bool is_v1_1) -{ - int32_t dummy; - snprintf((FAR char *)dev->tx_buff, _TX_BUFF_SIZE, - "AT%%SETACFG=LWM2M.Config.Version,\"%s\"\r", is_v1_1 ? "1.1" : "1.0"); - return send_internal_at_command(dev, container, -1, NULL, 0, &dummy); -} - -/**************************************************************************** - * name: lwm2mstub_send_getwriteattr - ****************************************************************************/ - -int lwm2mstub_send_getwriteattr(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container) -{ - int32_t dummy; - snprintf((FAR char *)dev->tx_buff, _TX_BUFF_SIZE, - "AT%%GETACFG=LWM2M.HostObjects.HostEnableWriteAttrURCMode\r"); - return send_internal_at_command(dev, container, -1, NULL, 0, &dummy); -} - -/**************************************************************************** - * name: lwm2mstub_send_setwriteattr - ****************************************************************************/ - -int lwm2mstub_send_setwriteattr(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - bool en) -{ - int32_t dummy; - snprintf((FAR char *)dev->tx_buff, _TX_BUFF_SIZE, - "AT%%SETACFG=LWM2M.HostObjects.HostEnableWriteAttrURCMode,\"%s\"\r", - en ? "true" : "false"); - return send_internal_at_command(dev, container, -1, NULL, 0, &dummy); -} - -/**************************************************************************** - * name: lwm2mstub_send_getautoconnect - ****************************************************************************/ - -int lwm2mstub_send_getautoconnect(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container) -{ - int32_t dummy; - snprintf((FAR char *)dev->tx_buff, _TX_BUFF_SIZE, - "AT%%GETACFG=LWM2M.Config.AutoConnect\r"); - return send_internal_at_command(dev, container, -1, NULL, 0, &dummy); -} - -/**************************************************************************** - * name: lwm2mstub_send_setautoconnect - ****************************************************************************/ - -int lwm2mstub_send_setautoconnect(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - bool en) -{ - int32_t dummy; - snprintf((FAR char *)dev->tx_buff, _TX_BUFF_SIZE, - "AT%%SETACFG=LWM2M.Config.AutoConnect,\"%s\"\r", - en ? "true" : "false"); - return send_internal_at_command(dev, container, -1, NULL, 0, &dummy); -} - -/**************************************************************************** - * name: ltenwop_send_getnwop - ****************************************************************************/ - -int ltenwop_send_getnwop(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container) -{ - int32_t dummy; - snprintf((FAR char *)dev->tx_buff, _TX_BUFF_SIZE, - "AT%%NWOPER?\r"); - return send_internal_at_command(dev, container, -1, NULL, 0, &dummy); -} - -/**************************************************************************** - * name: ltenwop_send_setnwoptp - ****************************************************************************/ - -int ltenwop_send_setnwoptp(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container) -{ - int32_t dummy; - snprintf((FAR char *)dev->tx_buff, _TX_BUFF_SIZE, - "AT%%NWOPER=\"TRUPHONE\"\r"); - return send_internal_at_command(dev, container, -1, NULL, 0, &dummy); -} - -/**************************************************************************** - * name: ltesp_send_getscanplan - ****************************************************************************/ - -int ltesp_send_getscanplan(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container) -{ - int32_t dummy; - snprintf((FAR char *)dev->tx_buff, _TX_BUFF_SIZE, - "AT%%GETCFG=\"SCAN_PLAN_EN\"\r"); - return send_internal_at_command(dev, container, -1, NULL, 0, &dummy); -} - -/**************************************************************************** - * name: ltesp_send_setscanplan - ****************************************************************************/ - -int ltesp_send_setscanplan(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - bool enable) -{ - int32_t dummy; - snprintf((FAR char *)dev->tx_buff, _TX_BUFF_SIZE, - "AT%%SETCFG=\"SCAN_PLAN_EN\",\"%s\"\r", (enable ? "1" : "0")); - return send_internal_at_command(dev, container, -1, NULL, 0, &dummy); -} - -/**************************************************************************** - * name: lwm2mstub_send_getqueuemode - ****************************************************************************/ - -int lwm2mstub_send_getqueuemode(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - int16_t usockid, FAR int32_t *ures) -{ - snprintf((FAR char *)dev->tx_buff, _TX_BUFF_SIZE, - "AT%%GETACFG=LWM2M.TransportBindings_1_1.Queue\r"); - return send_internal_at_command(dev, container, usockid, - atcmdreply_true_false, 0, ures); -} - -/**************************************************************************** - * name: lwm2mstub_send_setqueuemode - ****************************************************************************/ - -int lwm2mstub_send_setqueuemode(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - int16_t usockid, FAR int32_t *ures, int en) -{ - snprintf((FAR char *)dev->tx_buff, _TX_BUFF_SIZE, - "AT%%SETACFG=LWM2M.TransportBindings_1_1.Queue,%s\r", - (en == 1) ? "true" : "false"); - return send_internal_at_command(dev, container, usockid, - atcmdreply_ok_error, 0, ures); -} - -/**************************************************************************** - * name: lwm2mstub_send_m2mopev - ****************************************************************************/ - -int lwm2mstub_send_m2mopev(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - int16_t usockid, FAR int32_t *ures, bool en) -{ - snprintf((FAR char *)dev->tx_buff, _TX_BUFF_SIZE, - "AT%%LWM2MOPEV=%c,100\r", en ? '1' : '0'); - return send_internal_at_command(dev, container, usockid, - atcmdreply_ok_error, 0, ures); -} - -/**************************************************************************** - * name: lwm2mstub_send_m2mev - ****************************************************************************/ - -int lwm2mstub_send_m2mev(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - int16_t usockid, FAR int32_t *ures, bool en) -{ - snprintf((FAR char *)dev->tx_buff, _TX_BUFF_SIZE, - "AT%%LWM2MEV=%c\r", en ? '1' : '0'); - return send_internal_at_command(dev, container, usockid, - atcmdreply_ok_error, 0, ures); -} - -/**************************************************************************** - * name: lwm2mstub_send_m2mobjcmd - ****************************************************************************/ - -int lwm2mstub_send_m2mobjcmd(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - int16_t usockid, FAR int32_t *ures, bool en) -{ - snprintf((FAR char *)dev->tx_buff, _TX_BUFF_SIZE, - "AT%%LWM2MOBJCMD=%c\r", en ? '1' : '0'); - return send_internal_at_command(dev, container, usockid, - atcmdreply_ok_error, 0, ures); -} - -/**************************************************************************** - * name: lwm2mstub_send_getepname - ****************************************************************************/ - -int lwm2mstub_send_getepname(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - int16_t usockid, atcmd_postproc_t proc, - unsigned long arg, FAR int32_t *ures) -{ - snprintf((FAR char *)dev->tx_buff, _TX_BUFF_SIZE, - "AT%%GETACFG=LWM2M.Config.Name\r"); - return send_internal_at_command(dev, container, usockid, proc, arg, ures); -} - -/**************************************************************************** - * name: lwm2mstub_send_getsrvinfo - ****************************************************************************/ - -int lwm2mstub_send_getsrvinfo(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - int16_t usockid, atcmd_postproc_t proc, - unsigned long arg, FAR int32_t *ures) -{ - snprintf((FAR char *)dev->tx_buff, _TX_BUFF_SIZE, - "AT%%LWM2MCMD=SERVERSINFO\r"); - return send_internal_at_command(dev, container, usockid, proc, arg, ures); -} - -/**************************************************************************** - * name: lwm2mstub_send_getresource - ****************************************************************************/ - -int lwm2mstub_send_getresource(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - int16_t usockid, atcmd_postproc_t proc, - unsigned long arg, FAR int32_t *ures, - FAR char *resource) -{ - snprintf((FAR char *)dev->tx_buff, _TX_BUFF_SIZE, - "AT%%LWM2MCMD=GET_RESOURCE,%s\r", resource); - return send_internal_at_command(dev, container, usockid, proc, arg, ures); -} - -/**************************************************************************** - * name: lwm2mstub_send_getsupobjs - ****************************************************************************/ - -int lwm2mstub_send_getsupobjs(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - int16_t usockid, atcmd_postproc_t proc, - unsigned long arg, FAR int32_t *ures) -{ - snprintf((FAR char *)dev->tx_buff, _TX_BUFF_SIZE, - "AT%%GETACFG=LWM2M.Config.SupportedObjects\r"); - return send_internal_at_command(dev, container, usockid, proc, arg, ures); -} - -/**************************************************************************** - * name: lwm2mstub_send_getobjdef - ****************************************************************************/ - -int lwm2mstub_send_getobjdef(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - int16_t usockid, atcmd_postproc_t proc, - unsigned long arg, FAR int32_t *ures, - uint16_t objid) -{ - snprintf((FAR char *)dev->tx_buff, _TX_BUFF_SIZE, - "AT%%LWM2MOBJDEF=GET,%d\r", objid); - return send_internal_at_command(dev, container, usockid, proc, - arg, ures); -} - -/**************************************************************************** - * name: lwm2mstub_send_changerat - ****************************************************************************/ - -int lwm2mstub_send_changerat(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - int16_t usockid, FAR int32_t *ures, int rat) -{ - snprintf((FAR char *)dev->tx_buff, _TX_BUFF_SIZE, - "AT%%setacfg=radiom.config.preferred_rat_list,\"%s\"\r", - (rat == LTE_RAT_CATM) ? "CATM" : "NBIOT"); - - return send_internal_at_command(dev, container, usockid, - atcmdreply_ok_error, 0, ures); -} - -/**************************************************************************** - * name: lwm2mstub_send_getrat - ****************************************************************************/ - -int lwm2mstub_send_getrat(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - int16_t usockid, atcmd_postproc_t proc, - unsigned long arg, FAR int32_t *ures) -{ - snprintf((FAR char *)dev->tx_buff, _TX_BUFF_SIZE, - "AT%%getacfg=radiom.config.preferred_rat_list\r"); - return send_internal_at_command(dev, container, usockid, proc, arg, ures); -} - -/**************************************************************************** - * name: lwm2mstub_send_setepname - ****************************************************************************/ - -int lwm2mstub_send_setepname(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - int16_t usockid, FAR int32_t *ures, - FAR const char *epname) -{ - snprintf((FAR char *)dev->tx_buff, _TX_BUFF_SIZE, - "AT%%SETACFG=\"LWM2M.Config.Name\",\"%s\"\r", epname); - return send_internal_at_command(dev, container, usockid, - atcmdreply_ok_error, 0, ures); -} - -/**************************************************************************** - * name: lwm2mstub_send_bsstart - ****************************************************************************/ - -int lwm2mstub_send_bsstart(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - int16_t usockid, atcmd_postproc_t proc, - unsigned long arg, FAR int32_t *ures) -{ - snprintf((FAR char *)dev->tx_buff, _TX_BUFF_SIZE, - "AT%%LWM2MBSCMD=\"START\"\r"); - return send_internal_at_command(dev, container, usockid, proc, arg, ures); -} - -/**************************************************************************** - * name: lwm2mstub_send_bsdelete - ****************************************************************************/ - -int lwm2mstub_send_bsdelete(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - int16_t usockid, atcmd_postproc_t proc, - unsigned long arg, FAR int32_t *ures) -{ - snprintf((FAR char *)dev->tx_buff, _TX_BUFF_SIZE, - "AT%%LWM2MBSCMD=\"DELETE\"\r"); - return send_internal_at_command(dev, container, usockid, proc, arg, ures); -} - -/**************************************************************************** - * name: lwm2mstub_send_bscreateobj0 - ****************************************************************************/ - -int lwm2mstub_send_bscreateobj0(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - int16_t usockid, atcmd_postproc_t proc, - unsigned long arg, FAR int32_t *ures, - FAR struct lwm2mstub_serverinfo_s *info) -{ - int i; - int pos; - - pos = snprintf((FAR char *)dev->tx_buff, _TX_BUFF_SIZE, - "AT%%LWM2MBSCMD=\"CREATE\",0,0,0,\"%s\",1,\"%s\",2,%d", - info->server_uri, info->bootstrap ? "true" : "false", - info->security_mode); - - if (info->security_mode != LWM2MSTUB_SECUREMODE_NOSEC) - { - pos += snprintf((FAR char *)&dev->tx_buff[pos], _TX_BUFF_SIZE - pos, - ",3,\""); - for (i = 0; i < LWM2MSTUB_MAX_DEVID && info->device_id[i]; i++) - { - pos += snprintf((FAR char *)&dev->tx_buff[pos], - _TX_BUFF_SIZE - pos, - "%02x", info->device_id[i]); - } - - pos += snprintf((FAR char *)&dev->tx_buff[pos], _TX_BUFF_SIZE - pos, - "\""); - - pos += snprintf((FAR char *)&dev->tx_buff[pos], _TX_BUFF_SIZE - pos, - ",5,\""); - for (i = 0; i < LWM2MSTUB_MAX_SEQKEY && info->security_key[i]; i++) - { - pos += snprintf((FAR char *)&dev->tx_buff[pos], - _TX_BUFF_SIZE - pos, - "%02x", info->security_key[i]); - } - - pos += snprintf((FAR char *)&dev->tx_buff[pos], _TX_BUFF_SIZE - pos, - "\""); - } - - snprintf((FAR char *)&dev->tx_buff[pos], _TX_BUFF_SIZE - pos, ",10,0\r"); - - return send_internal_at_command(dev, container, usockid, proc, arg, ures); -} - -/**************************************************************************** - * name: lwm2mstub_send_bscreateobj1 - ****************************************************************************/ - -int lwm2mstub_send_bscreateobj1(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - int16_t usockid, atcmd_postproc_t proc, - unsigned long arg, FAR int32_t *ures, - FAR struct lwm2mstub_serverinfo_s *info) -{ - snprintf((FAR char *)dev->tx_buff, _TX_BUFF_SIZE, - "AT%%LWM2MBSCMD=\"CREATE\",1,0,0,0,1,%lu%s\r", info->lifetime, - info->nonip ? ",7,\"N\",22,\"N\"" : ""); - - return send_internal_at_command(dev, container, usockid, proc, arg, ures); -} - -/**************************************************************************** - * name: lwm2mstub_send_bsdone - ****************************************************************************/ - -int lwm2mstub_send_bsdone(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - int16_t usockid, FAR int32_t *ures) -{ - snprintf((FAR char *)dev->tx_buff, _TX_BUFF_SIZE, - "AT%%LWM2MBSCMD=\"DONE\"\r"); - return send_internal_at_command(dev, container, usockid, - atcmdreply_ok_error, 0, ures); -} - -/**************************************************************************** - * name: lwm2mstub_send_setsupobjs - ****************************************************************************/ - -int lwm2mstub_send_setsupobjs(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - int16_t usockid, FAR int32_t *ures, - FAR uint16_t *objids, int objnum) -{ - int pos; - pos = snprintf((FAR char *)dev->tx_buff, _TX_BUFF_SIZE, - "AT%%SETACFG=LWM2M.Config.SupportedObjects,0;1"); - - while (objnum > 0) - { - /* Object 0 and Object 1 is mandatory and default */ - - if (*objids != 0 && *objids != 1) - { - pos += snprintf((FAR char *)&dev->tx_buff[pos], - _TX_BUFF_SIZE - pos, - ";%d", *objids); - } - - objids++; - objnum--; - } - - snprintf((FAR char *)&dev->tx_buff[pos], _TX_BUFF_SIZE - pos, "\r"); - - return send_internal_at_command(dev, container, usockid, - atcmdreply_ok_error, 0, ures); -} - -/**************************************************************************** - * name: lwm2mstub_send_setobjdef - ****************************************************************************/ - -int lwm2mstub_send_setobjdef(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - int16_t usockid, FAR int32_t *ures, - uint16_t objid, int resnum, - FAR struct lwm2mstub_resource_s *resucs) -{ - int pos; - - pos = snprintf((FAR char *)dev->tx_buff, _TX_BUFF_SIZE, - "AT%%LWM2MOBJDEF=SET,%d", objid); - - while (resnum > 0) - { - pos += snprintf((FAR char *)&dev->tx_buff[pos], _TX_BUFF_SIZE - pos, - ",%d,\"%s\",%d,\"%s\"", resucs->res_id, - resucs->operation == LWM2MSTUB_RESOP_READ ? "R" : - resucs->operation == LWM2MSTUB_RESOP_WRITE ? "W" : - resucs->operation == LWM2MSTUB_RESOP_RW ? "RW" : "X", - resucs->inst_type, - resucs->data_type == LWM2MSTUB_RESDATA_NONE ? "NONE" : - resucs->data_type == LWM2MSTUB_RESDATA_STRING ? "STR" : - resucs->data_type == LWM2MSTUB_RESDATA_INT ? "INT" : - resucs->data_type == LWM2MSTUB_RESDATA_UNSIGNED ? "UINT" : - resucs->data_type == LWM2MSTUB_RESDATA_FLOAT ? "FLT" : - resucs->data_type == LWM2MSTUB_RESDATA_BOOL ? "BOOL" : - resucs->data_type == LWM2MSTUB_RESDATA_OPAQUE ? "OPQ" : - resucs->data_type == LWM2MSTUB_RESDATA_TIME ? "TIME" : "OL"); - resucs++; - resnum--; - } - - snprintf((FAR char *)&dev->tx_buff[pos], _TX_BUFF_SIZE - pos, "\r"); - - return send_internal_at_command(dev, container, usockid, - atcmdreply_ok_error, 0, ures); -} - -/**************************************************************************** - * name: lwm2mstub_send_registration - ****************************************************************************/ - -int lwm2mstub_send_registration(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - int16_t usockid, FAR int32_t *ures, int cmd) -{ - snprintf((FAR char *)dev->tx_buff, _TX_BUFF_SIZE, - "AT%%LWM2MCMD=%s\r", - cmd == LWM2MSTUB_CONNECT_REGISTER ? "REGISTER" : - cmd == LWM2MSTUB_CONNECT_DEREGISTER ? "DEREGISTER" : - cmd == LWM2MSTUB_CONNECT_REREGISTER ? "REGISTERUPD" : - "BOOTSTARP"); - - return send_internal_at_command(dev, container, usockid, - atcmdreply_ok_error, 0, ures); -} - -/**************************************************************************** - * name: lwm2mstub_send_evrespwvalue - ****************************************************************************/ - -int lwm2mstub_send_evrespwvalue(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - int16_t usockid, FAR int32_t *ures, - int seq_no, int resp, - FAR struct lwm2mstub_instance_s *inst, - FAR char *retval) -{ - int pos; - FAR const char *resp_str = get_m2mrespstr(resp); - - if (resp_str == NULL) - { - *ures = -EINVAL; - return REP_SEND_ACK; - } - - pos = snprintf((FAR char *)dev->tx_buff, _TX_BUFF_SIZE, - "AT%%LWM2MOBJRSP=%d,\"%s\",\"/%d/%d/%d", seq_no, resp_str, - inst->object_id, inst->object_inst, inst->res_id); - - if (inst->res_inst >= 0) - { - pos += snprintf((FAR char *)&dev->tx_buff[pos], _TX_BUFF_SIZE - pos, - "/%d", inst->res_inst); - } - - snprintf((FAR char *)&dev->tx_buff[pos], _TX_BUFF_SIZE - pos, - "\",\"%s\"\r", retval); - - return send_internal_at_command(dev, container, usockid, - atcmdreply_ok_error, 0, ures); -} - -/**************************************************************************** - * name: lwm2mstub_send_evresponse - ****************************************************************************/ - -int lwm2mstub_send_evresponse(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - int16_t usockid, FAR int32_t *ures, int seq_no, - int resp, - FAR struct lwm2mstub_instance_s *inst) -{ - int pos; - FAR const char *resp_str = get_m2mrespstr(resp); - - if (resp_str == NULL) - { - *ures = -EINVAL; - return REP_SEND_ACK; - } - - pos = snprintf((FAR char *)dev->tx_buff, _TX_BUFF_SIZE, - "AT%%LWM2MOBJRSP=%d,\"%s\",\"/%d/%d/%d", seq_no, resp_str, - inst->object_id, inst->object_inst, inst->res_id); - - if (inst->res_inst >= 0) - { - pos += snprintf((FAR char *)&dev->tx_buff[pos], _TX_BUFF_SIZE - pos, - "/%d", inst->res_inst); - } - - snprintf((FAR char *)&dev->tx_buff[pos], _TX_BUFF_SIZE - pos, "\"\r"); - - return send_internal_at_command(dev, container, usockid, - atcmdreply_ok_error, 0, ures); -} - -/**************************************************************************** - * name: lwm2mstub_send_evrespwoinst - ****************************************************************************/ - -int lwm2mstub_send_evrespwoinst(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - int16_t usockid, FAR int32_t *ures, - int seq_no, int resp) -{ - FAR const char *resp_str = get_m2mrespstr(resp); - - if (resp_str == NULL) - { - *ures = -EINVAL; - return REP_SEND_ACK; - } - - snprintf((FAR char *)dev->tx_buff, _TX_BUFF_SIZE, - "AT%%LWM2MOBJRSP=%d,\"%s\"\r", seq_no, resp_str); - - return send_internal_at_command(dev, container, usockid, - atcmdreply_ok_error, 0, ures); -} - -/**************************************************************************** - * name: lwm2mstub_send_objevent - ****************************************************************************/ - -int lwm2mstub_send_objevent(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - int16_t usockid, FAR int32_t *ures, - FAR char *token, - FAR struct lwm2mstub_instance_s *inst, - FAR char *retval) -{ - int pos; - - pos = snprintf((FAR char *)dev->tx_buff, _TX_BUFF_SIZE, - "AT%%LWM2MOBJEV=\"%s\",,,0,\"/%d/%d", - token, inst->object_id, inst->object_inst); - - if (inst->res_id >= 0) - { - pos += snprintf((FAR char *)&dev->tx_buff[pos], _TX_BUFF_SIZE - pos, - "/%d", inst->res_id); - - if (inst->res_inst >= 0) - { - pos += snprintf((FAR char *)&dev->tx_buff[pos], - _TX_BUFF_SIZE - pos, - "/%d", inst->res_id); - } - } - - snprintf((FAR char *)&dev->tx_buff[pos], _TX_BUFF_SIZE - pos, - "\",\"%s\"\r", retval); - - return send_internal_at_command(dev, container, usockid, - atcmdreply_ok_error, 0, ures); -} diff --git a/lte/alt1250/alt1250_atcmd.h b/lte/alt1250/alt1250_atcmd.h deleted file mode 100644 index 4a9e275e6..000000000 --- a/lte/alt1250/alt1250_atcmd.h +++ /dev/null @@ -1,248 +0,0 @@ -/**************************************************************************** - * apps/lte/alt1250/alt1250_atcmd.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __APPS_LTE_ALT1250_ALT1250_ATCMD_H -#define __APPS_LTE_ALT1250_ALT1250_ATCMD_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include - -#include - -#include "alt1250_dbg.h" -#include "alt1250_devif.h" -#include "alt1250_container.h" - -#include - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -typedef int (*atreply_parser_t)(FAR char *reply, int len, void *arg); -typedef int (*atcmd_postproc_t)(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - FAR char *rdata, int len, unsigned long arg, - FAR int32_t *usock_result); - -struct atreply_truefalse_s -{ - FAR const char *target_str; - bool result; -}; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -int atcmdreply_ok_error(FAR struct alt1250_s *dev, - FAR struct alt_container_s *reply, - FAR char *rdata, int len, unsigned long arg, - FAR int32_t *usock_result); - -int check_atreply_ok(FAR char *reply, int len, void *arg); -int check_atreply_truefalse(FAR char *reply, int len, void *arg); - -int lwm2mstub_send_reset(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container); - -int lwm2mstub_send_getenable(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - FAR int32_t *usock_result); - -int lwm2mstub_send_setenable(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, bool en); - -int lwm2mstub_send_getnamemode(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container); - -int lwm2mstub_send_setnamemode(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - int mode); - -int lwm2mstub_send_getversion(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container); - -int lwm2mstub_send_setversion(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - bool is_v1_1); - -int lwm2mstub_send_getwriteattr(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container); - -int lwm2mstub_send_setwriteattr(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - bool en); - -int lwm2mstub_send_getautoconnect(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container); - -int lwm2mstub_send_setautoconnect(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - bool en); - -int ltenwop_send_getnwop(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container); - -int ltenwop_send_setnwoptp(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container); - -int ltesp_send_getscanplan(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container); - -int ltesp_send_setscanplan(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - bool enable); - -int lwm2mstub_send_getqueuemode(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - int16_t usockid, FAR int32_t *ures); - -int lwm2mstub_send_setqueuemode(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - int16_t usockid, FAR int32_t *ures, int en); - -int lwm2mstub_send_m2mopev(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - int16_t usockid, FAR int32_t *ures, bool en); - -int lwm2mstub_send_m2mobjcmd(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - int16_t usockid, FAR int32_t *ures, bool en); - -int lwm2mstub_send_m2mev(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - int16_t usockid, FAR int32_t *ures, bool en); - -int lwm2mstub_send_getepname(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - int16_t usockid, atcmd_postproc_t proc, - unsigned long arg, FAR int32_t *ures); - -int lwm2mstub_send_getsrvinfo(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - int16_t usockid, atcmd_postproc_t proc, - unsigned long arg, FAR int32_t *ures); - -int lwm2mstub_send_getresource(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - int16_t usockid, atcmd_postproc_t proc, - unsigned long arg, FAR int32_t *ures, - FAR char *resource); - -int lwm2mstub_send_getsupobjs(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - int16_t usockid, atcmd_postproc_t proc, - unsigned long arg, FAR int32_t *ures); - -int lwm2mstub_send_getobjdef(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - int16_t usockid, atcmd_postproc_t proc, - unsigned long arg, FAR int32_t *ures, - uint16_t objid); - -int lwm2mstub_send_setepname(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - int16_t usockid, FAR int32_t *ures, - FAR const char *epname); - -int lwm2mstub_send_bsstart(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - int16_t usockid, atcmd_postproc_t proc, - unsigned long arg, FAR int32_t *ures); - -int lwm2mstub_send_bsdelete(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - int16_t usockid, atcmd_postproc_t proc, - unsigned long arg, FAR int32_t *ures); - -int lwm2mstub_send_bscreateobj0(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - int16_t usockid, atcmd_postproc_t proc, - unsigned long arg, FAR int32_t *ures, - FAR struct lwm2mstub_serverinfo_s *info); - -int lwm2mstub_send_bscreateobj1(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - int16_t usockid, atcmd_postproc_t proc, - unsigned long arg, FAR int32_t *ures, - FAR struct lwm2mstub_serverinfo_s *info); - -int lwm2mstub_send_bsdone(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - int16_t usockid, FAR int32_t *ures); - -int lwm2mstub_send_setsupobjs(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - int16_t usockid, FAR int32_t *ures, - FAR uint16_t *objids, int objnum); - -int lwm2mstub_send_setobjdef(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - int16_t usockid, FAR int32_t *ures, - uint16_t objid, int resnum, - FAR struct lwm2mstub_resource_s *resucs); - -int lwm2mstub_send_registration(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - int16_t usockid, FAR int32_t *ures, int cmd); - -int lwm2mstub_send_evrespwvalue(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - int16_t usockid, FAR int32_t *ures, - int seq_no, int resp, - FAR struct lwm2mstub_instance_s *inst, - FAR char *retval); - -int lwm2mstub_send_evresponse(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - int16_t usockid, FAR int32_t *ures, int seq_no, - int resp, - FAR struct lwm2mstub_instance_s *inst); - -int lwm2mstub_send_evrespwoinst(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - int16_t usockid, FAR int32_t *ures, - int seq_no, int resp); - -int lwm2mstub_send_objevent(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - int16_t usockid, FAR int32_t *ures, - FAR char *token, - FAR struct lwm2mstub_instance_s *inst, - FAR char *retval); - -int lwm2mstub_send_changerat(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - int16_t usockid, FAR int32_t *ures, int rat); - -int lwm2mstub_send_getrat(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - int16_t usockid, atcmd_postproc_t proc, - unsigned long arg, FAR int32_t *ures); - -#endif /* __APPS_LTE_ALT1250_ALT1250_ATCMD_H */ diff --git a/lte/alt1250/alt1250_container.c b/lte/alt1250/alt1250_container.c deleted file mode 100644 index 21ec1b31a..000000000 --- a/lte/alt1250/alt1250_container.c +++ /dev/null @@ -1,188 +0,0 @@ -/**************************************************************************** - * apps/lte/alt1250/alt1250_container.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include - -#include "alt1250_dbg.h" -#include "alt1250_daemon.h" -#include "alt1250_container.h" - -/**************************************************************************** - * Private Data Types - ****************************************************************************/ - -static struct postproc_s postproc_obj[CONFIG_LTE_ALT1250_CONTAINERS]; -static struct alt_container_s container_obj[CONFIG_LTE_ALT1250_CONTAINERS]; -static sq_queue_t free_containers; - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * name: init_containers - ****************************************************************************/ - -void init_containers(void) -{ - int i; - - memset(&container_obj, 0, sizeof(container_obj)); - - sq_init(&free_containers); - - for (i = 0; i < CONFIG_LTE_ALT1250_CONTAINERS; i++) - { - container_obj[i].priv = (unsigned long)&postproc_obj[i]; - sq_addlast(&container_obj[i].node, &free_containers); - } -} - -/**************************************************************************** - * name: container_alloc - ****************************************************************************/ - -FAR struct alt_container_s *container_alloc(void) -{ - FAR struct alt_container_s *ret; - - ret = (FAR struct alt_container_s *)sq_peek(&free_containers); - if (ret) - { - sq_rem(&ret->node, &free_containers); - clear_container(ret); - } - else - { - dbg_alt1250("No more container\n"); - } - - return ret; -} - -/**************************************************************************** - * name: container_free - ****************************************************************************/ - -void container_free(FAR struct alt_container_s *container) -{ - dbg_alt1250("Container free \n", container->cmdid); - - sq_addlast(&container->node, &free_containers); -} - -/**************************************************************************** - * name: set_container_ids - ****************************************************************************/ - -void set_container_ids(FAR struct alt_container_s *container, - int16_t usockid, uint32_t cmdid) -{ - container->sock = usockid; - container->cmdid = cmdid; -} - -/**************************************************************************** - * name: set_container_argument - ****************************************************************************/ - -void set_container_argument(FAR struct alt_container_s *container, - FAR void *argparams[], size_t paramsz) -{ - container->inparam = argparams; - container->inparamlen = paramsz; -} - -/**************************************************************************** - * name: set_container_response - ****************************************************************************/ - -void set_container_response(FAR struct alt_container_s *container, - FAR void *respparams[], size_t paramsz) -{ - container->outparam = respparams; - container->outparamlen = paramsz; -} - -/**************************************************************************** - * name: set_container_postproc - ****************************************************************************/ - -void set_container_postproc(FAR struct alt_container_s *container, - FAR postproc_hdlr_t func, unsigned long arg) -{ - FAR struct postproc_s *pp = (FAR struct postproc_s *)container->priv; - pp->hdlr = func; - pp->priv = arg; -} - -/**************************************************************************** - * name: clear_container - ****************************************************************************/ - -void clear_container(FAR struct alt_container_s *container) -{ - unsigned long priv = container->priv; - memset(container, 0, sizeof(struct alt_container_s)); - container->priv = priv; -} - -/**************************************************************************** - * name: container_free_all - ****************************************************************************/ - -void container_free_all(FAR struct alt_container_s *head) -{ - FAR struct alt_container_s *c; - - while (head) - { - c = head; - head = (FAR struct alt_container_s *)sq_next(&c->node); - container_free(c); - } -} - -/**************************************************************************** - * name: container_pick_listtop - ****************************************************************************/ - -FAR struct alt_container_s *container_pick_listtop( - FAR struct alt_container_s **head) -{ - FAR struct alt_container_s *ret = *head; - - if (ret) - { - *head = (FAR struct alt_container_s *)sq_next(&ret->node); - sq_next(&ret->node) = NULL; - } - - return ret; -} diff --git a/lte/alt1250/alt1250_container.h b/lte/alt1250/alt1250_container.h deleted file mode 100644 index 2e45e12ce..000000000 --- a/lte/alt1250/alt1250_container.h +++ /dev/null @@ -1,76 +0,0 @@ -/**************************************************************************** - * apps/lte/alt1250/alt1250_container.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __APPS_LTE_ALT1250_ALT1250_CONTAINER_H -#define __APPS_LTE_ALT1250_ALT1250_CONTAINER_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -#include "alt1250_postproc.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define CONTAINER_SOCKETID(c) ((c)->sock) -#define CONTAINER_CMDID(c) ((c)->cmdid) -#define CONTAINER_ARGUMENT(c) ((c)->inparam) -#define CONTAINER_ARGSIZE(c) ((c)->inparamlen) -#define CONTAINER_RESPONSE(c) ((c)->outparam) -#define CONTAINER_RESPSIZE(c) ((c)->outparamlen) -#define CONTAINER_RESPRES(c) ((c)->result) -#define CONTAINER_POSTPROC(c) ((FAR struct postproc_s *)(c)->priv) - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -void init_containers(void); - -FAR struct alt_container_s *container_alloc(void); - -void clear_container(FAR struct alt_container_s *container); - -void set_container_ids(FAR struct alt_container_s *container, - int16_t usockid, uint32_t cmdid); - -void set_container_argument(FAR struct alt_container_s *container, - FAR void *inparams[], size_t paramsz); - -void set_container_response(FAR struct alt_container_s *container, - FAR void *outparams[], size_t paramsz); - -void set_container_postproc(FAR struct alt_container_s *container, - FAR postproc_hdlr_t func, unsigned long priv); - -void container_free(FAR struct alt_container_s *container); -void container_free_all(FAR struct alt_container_s *head); - -FAR struct alt_container_s * - container_pick_listtop(FAR struct alt_container_s **head); - -#endif /* __APPS_LTE_ALT1250_ALT1250_CONTAINER_H */ diff --git a/lte/alt1250/alt1250_daemon.h b/lte/alt1250/alt1250_daemon.h deleted file mode 100644 index 45d8a923b..000000000 --- a/lte/alt1250/alt1250_daemon.h +++ /dev/null @@ -1,177 +0,0 @@ -/**************************************************************************** - * apps/lte/alt1250/alt1250_daemon.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __APPS_LTE_ALT1250_ALT1250_DAEMON_H -#define __APPS_LTE_ALT1250_ALT1250_DAEMON_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include "alt1250_socket.h" -#include "alt1250_usockif.h" -#include "alt1250_util.h" -#include "alt1250_fwupdate.h" -#include "alt1250_sms.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* The maximum number of sockets that the ALT1250 modem can open. */ - -#define SOCKET_COUNT 5 - -#define _TX_BUFF_SIZE (1500) -#define _RX_BUFF_SIZE (1500) - -#define ACCEPT_USOCK_REQUEST(dev) (!(dev)->is_usockrcvd && !(dev)->recvfrom_processing) -#define IS_USOCKREQ_RECEIVED(dev) ((dev)->is_usockrcvd) - -#define MODEM_STATE(d) ((d)->modem_state) -#define MODEM_STATE_POFF(d) ((d)->modem_state = MODEM_POWER_OFF) -#define MODEM_STATE_PON(d) ((d)->modem_state = MODEM_POWER_ON) -#define MODEM_STATE_B4PON(d) ((d)->modem_state = MODEM_BEFORE_PON) -#define MODEM_STATE_B4PON_2ND(d) ((d)->modem_state = MODEM_BEFORE_PON_STAGE2) -#define MODEM_STATE_INTENTRST(d) ((d)->modem_state = MODEM_RST_INTENTIONAL) -#define MODEM_STATE_RON(d) ((d)->modem_state = MODEM_RADIO_ON) -#define MODEM_STATE_IS_RON(d) ((d)->modem_state == MODEM_RADIO_ON) -#define MODEM_STATE_IS_POFF(d) ((d)->modem_state == MODEM_POWER_OFF) -#define MODEM_STATE_IS_PON(d) ((d)->modem_state == MODEM_POWER_ON) - -#define MODEM_FWVERSION(d) ((d)->fw_version) - -/**************************************************************************** - * Public Data Types - ****************************************************************************/ - -enum alt1250_state_e -{ - MODEM_POWER_OFF = 0, - MODEM_BEFORE_PON, - MODEM_BEFORE_PON_STAGE2, - MODEM_POWER_ON, - MODEM_RST_INTENTIONAL, - MODEM_RADIO_ON, -}; - -struct usrsock_request_buff_s; - -struct alt1250_s -{ - int usockfd; - int altfd; - int usock_enable; - - int32_t scnt; - int32_t sid; /* Select ID requested to Alt1250 module. - * Negative value indicats no select request */ - FAR sem_t *syncsem; /* Semaphore to synchronize LAPI Caller */ - mqd_t evtq; /* Event queue to communicate "Callback task" */ - struct net_driver_s net_dev; - - enum alt1250_state_e modem_state; - - lte_apn_setting_t apn; - char apn_name[LTE_APN_LEN]; - char user_name[LTE_APN_USER_NAME_LEN]; - char pass[LTE_APN_PASSWD_LEN]; - lte_pdn_t o_pdn; - - struct usock_s sockets[SOCKET_COUNT + CONFIG_LTE_ALT1250_CONTROL_SOCKETS]; - - struct usrsock_request_buff_s usockreq; - bool is_usockrcvd; /* A flag indicates that daemon has already read - * usrsock request */ - bool recvfrom_processing; - - uint8_t tx_buff[_TX_BUFF_SIZE]; - uint8_t rx_buff[_RX_BUFF_SIZE]; - - char fw_version[LTE_VER_NP_PACKAGE_LEN]; - struct update_info_s fwup_info; - - struct sms_info_s sms_info; - bool is_support_lwm2m; - int64_t lwm2m_apply_xid; - bool api_enable; - context_save_cb_t context_cb; - bool is_resuming; - uint32_t quality_report_period; - uint32_t cellinfo_report_period; -}; - -struct alt1250_save_ctx -{ - uint8_t ip_type; - uint8_t auth_type; - uint32_t apn_type; - char apn_name[LTE_APN_LEN]; - char user_name[LTE_APN_USER_NAME_LEN]; - char pass[LTE_APN_PASSWD_LEN]; - - uint32_t d_flags; - -#ifdef CONFIG_NET_IPv4 - in_addr_t d_ipaddr; - in_addr_t d_draddr; - in_addr_t d_netmask; -#endif - -#ifdef CONFIG_NET_IPv6 - net_ipv6addr_t d_ipv6addr; - net_ipv6addr_t d_ipv6draddr; - net_ipv6addr_t d_ipv6netmask; -#endif - - uint16_t checksum; -}; - -/**************************************************************************** - * Public Functions Prototypes - ****************************************************************************/ - -#ifdef CONFIG_LTE_ALT1250_ENABLE_HIBERNATION_MODE -int alt1250_set_api_enable(FAR struct alt1250_s *dev, bool enable); -int alt1250_count_opened_sockets(FAR struct alt1250_s *dev); -int alt1250_is_api_in_progress(FAR struct alt1250_s *dev); -int alt1250_set_context_save_cb(FAR struct alt1250_s *dev, - context_save_cb_t context_cb); -int alt1250_collect_daemon_context(FAR struct alt1250_s *dev); -int alt1250_apply_daemon_context(FAR struct alt1250_s *dev, - FAR struct alt1250_save_ctx *ctx); -#endif - -#endif /* __APPS_LTE_ALT1250_ALT1250_DAEMON_H */ diff --git a/lte/alt1250/alt1250_dbg.h b/lte/alt1250/alt1250_dbg.h deleted file mode 100644 index 0034bea82..000000000 --- a/lte/alt1250/alt1250_dbg.h +++ /dev/null @@ -1,46 +0,0 @@ -/**************************************************************************** - * apps/lte/alt1250/alt1250_dbg.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __APPS_LTE_ALT1250_ALT1250_DBG_H -#define __APPS_LTE_ALT1250_ALT1250_DBG_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#ifdef CONFIG_LTE_ALT1250_DEBUG_MSG -# define err_alt1250(v, ...) nerr(v, ##__VA_ARGS__) -# define dbg_alt1250(v, ...) ninfo(v, ##__VA_ARGS__) -#else -# define err_alt1250(v, ...) -# define dbg_alt1250(v, ...) -#endif - -#endif /* __APPS_LTE_ALT1250_ALT1250_DBG_H */ diff --git a/lte/alt1250/alt1250_devevent.c b/lte/alt1250/alt1250_devevent.c deleted file mode 100644 index cdd2da524..000000000 --- a/lte/alt1250/alt1250_devevent.c +++ /dev/null @@ -1,475 +0,0 @@ -/**************************************************************************** - * apps/lte/alt1250/alt1250_devevent.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include - -#include "alt1250_dbg.h" -#include "alt1250_evt.h" -#include "alt1250_devif.h" -#include "alt1250_devevent.h" -#include "alt1250_postproc.h" -#include "alt1250_container.h" -#include "alt1250_usockif.h" -#include "alt1250_usockevent.h" -#include "alt1250_socket.h" -#include "alt1250_usrsock_hdlr.h" -#include "alt1250_select.h" -#include "alt1250_sms.h" -#include "alt1250_netdev.h" -#include "alt1250_reset_seq.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define IS_PV1_FIRMWARE(d) (!strncmp(MODEM_FWVERSION(d), \ - "RK_02_01_", 9)) -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: handle_replypkt - ****************************************************************************/ - -static int handle_replypkt(FAR struct alt1250_s *dev, - FAR struct alt_container_s *reply, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo) -{ - int ret; - FAR struct usock_s *usock; - FAR struct postproc_s *pp = CONTAINER_POSTPROC(reply); - - usock = usocket_search(dev, CONTAINER_SOCKETID(reply)); - - dbg_alt1250("reply->result: %d\n", CONTAINER_RESPRES(reply)); - - *usock_result = CONTAINER_RESPRES(reply); - *usock_xid = usock ? USOCKET_XID(usock) : -1; - ret = usock ? REP_SEND_ACK : REP_NO_ACK; - - if (pp && pp->hdlr) - { - ret = pp->hdlr(dev, reply, usock, usock_result, usock_xid, ackinfo, - pp->priv); - } - - return ret; -} - -/**************************************************************************** - * Name: perform_alt1250_reply - ****************************************************************************/ - -static int perform_alt1250_reply(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container) -{ - int ret = REP_NO_ACK; - int32_t ack_result = OK; - uint32_t ack_xid = 0; - struct usock_ackinfo_s ackinfo; - - ret = handle_replypkt(dev, container, &ack_result, &ack_xid, &ackinfo); - - if (LTE_IS_ASYNC_CMD(container->cmdid)) - { - ret = REP_NO_ACK; - } - - usock_reply(dev->usockfd, ret, ack_result, ack_xid, &ackinfo); - - return ret; -} - -/**************************************************************************** - * Name: handle_normal_reset - ****************************************************************************/ - -static int handle_normal_reset(FAR struct alt1250_s *dev) -{ - alt1250_clrevtcb(ALT1250_CLRMODE_WO_RESTART); - - dev->recvfrom_processing = false; - dev->lwm2m_apply_xid = -1; - - alt1250_netdev_ifdown(dev); - - usocket_freeall(dev); - - reset_fwupdate_info(dev); - alt1250_reset_sms_info(dev); - reset_usock_device(dev->usockfd); - - return REP_MODEM_RESET; -} - -/**************************************************************************** - * name: handle_intentional_reset - ****************************************************************************/ - -static int handle_intentional_reset(FAR struct alt1250_s *dev) -{ - if (dev->lwm2m_apply_xid >= 0) - { - usockif_sendack(dev->usockfd, 0, (uint32_t)dev->lwm2m_apply_xid, - false); - dev->lwm2m_apply_xid = -1; - } - - alt1250_clrevtcb(ALT1250_CLRMODE_WO_RESTART); - dev->recvfrom_processing = false; - alt1250_netdev_ifdown(dev); - usocket_freeall(dev); - alt1250_reset_sms_info(dev); - reset_usock_device(dev->usockfd); - - MODEM_STATE_PON(dev); - - return REP_NO_ACK; -} - -/**************************************************************************** - * Name: perform_alt1250_resetevt - ****************************************************************************/ - -static int perform_alt1250_resetevt(FAR struct alt1250_s *dev, - FAR struct alt_container_s *rlist) -{ - int ret; - - container_free_all(rlist); - - dev->sid = -1; - - switch (MODEM_STATE(dev)) - { - case MODEM_BEFORE_PON: - ret = handle_poweron_reset(dev); - break; - - case MODEM_BEFORE_PON_STAGE2: - ret = handle_poweron_reset_stage2(dev); - break; - - case MODEM_RST_INTENTIONAL: - ret = handle_intentional_reset(dev); - break; - - default: - ret = handle_normal_reset(dev); - break; - } - - return ret; -} - -#ifdef CONFIG_LTE_ALT1250_ENABLE_HIBERNATION_MODE -/**************************************************************************** - * Name: perform_alt1250_apistopevt - ****************************************************************************/ - -static void perform_alt1250_apistopevt(FAR struct alt1250_s *dev) -{ - int ret = OK; - int w_cnt = 0; - - /* The "ALT1250_EVTBIT_STOPAPI" command isn't supported for PV1 firmware */ - - if (IS_PV1_FIRMWARE(dev)) - { - dbg_alt1250("This firmware doesn't support hibernation mode.\n"); - ret = ERROR; - goto exit; - } - - /* All LTE API/Socket requests must be stopped to enter Suspend mode. */ - - ret = alt1250_set_api_enable(dev, false); - - if (ret < 0) - { - dbg_alt1250("Failed to stop API call.\n"); - ret = ERROR; - goto exit; - } - - /* Application need to context data when LTE function resume from - * hibernation. - */ - - if (!dev->context_cb) - { - dbg_alt1250("Context save callback not registered.\n"); - ret = ERROR; - goto exit; - } - - /* When entering Suspend mode, all Sockets must be closed. */ - - ret = alt1250_count_opened_sockets(dev); - - if (ret < 0) - { - dbg_alt1250("Failed to count opened sockets.\n"); - ret = ERROR; - goto exit; - } - else if (ret > 0) - { - dbg_alt1250("There are opened socket, " - "could not entering hibernation mode.\n"); - ret = ERROR; - goto exit; - } - - /* Refuse to enter Suspend mode if the LTE API already running has not yet - * completed. - */ - - ret = alt1250_is_api_in_progress(dev); - - if (ret < 0) - { - dbg_alt1250("Failed to check API call status.\n"); - ret = ERROR; - goto exit; - } - else if (ret > 0) - { - dbg_alt1250("There are in progress API call, " - "could not entering hibernation mode.\n"); - ret = ERROR; - goto exit; - } - - /* When Wakelock is acquired, Suspend mode is rejected because - * it is not possible to enter Suspend mode. - */ - - w_cnt = altdevice_powercontrol(dev->altfd, LTE_CMDID_COUNTWLOCK); - if (w_cnt == 0) - { - ret = OK; - } - else if (w_cnt > 0) - { - dbg_alt1250("Cannot enter hibernation due to wakelock is aquired.\n"); - ret = -EBUSY; - } - else - { - dbg_alt1250("Failed to get wakelock count.\n"); - ret = w_cnt; - } - -exit: - - if (ret < 0) - { - alt1250_set_api_enable(dev, true); - } - - altdevice_powerresponse(dev->altfd, LTE_CMDID_STOPAPI, ret); -} - -/**************************************************************************** - * Name: perform_alt1250_restartevt - ****************************************************************************/ - -static void perform_alt1250_restartevt(FAR struct alt1250_s *dev) -{ - /* All LTE API/Socket requests must be available. */ - - alt1250_set_api_enable(dev, true); - - altdevice_powerresponse(dev->altfd, LTE_CMDID_RESTARTAPI, OK); -} - -/**************************************************************************** - * Name: perform_alt1250_suspendevt - ****************************************************************************/ - -static void perform_alt1250_suspendevt(FAR struct alt1250_s *dev) -{ - /* TODO: Register Select to be notified by ALT1250 when an event is - * received during Sleep for a Socket in Suspend. - */ - - /* Notify the application of the context data required for resume. */ - - alt1250_collect_daemon_context(dev); - - altdevice_powerresponse(dev->altfd, LTE_CMDID_SUSPEND, 0); -} -#endif - -/**************************************************************************** - * Name: perform_netinfo_report_event - ****************************************************************************/ - -uint64_t perform_netinfo_report_event(FAR struct alt1250_s *dev, - uint64_t bitmap) -{ - uint64_t bit = 0ULL; - FAR void **arg; - FAR lte_netinfo_t *info; - FAR lte_pdn_t *pdn; - - if (alt1250_checkcmdid(LTE_CMDID_REPNETINFO, bitmap, &bit)) - { - arg = alt1250_getevtarg(LTE_CMDID_REPNETINFO); - if (arg && arg[0]) - { - /* arg[0]: Network information (see lte_netinfo_t) */ - - info = (FAR lte_netinfo_t *)arg[0]; - if (info->pdn_num == 0) - { - alt1250_netdev_ifdown(dev); - } - else - { - pdn = &info->pdn_stat[0]; - if (pdn->active == LTE_PDN_ACTIVE) - { - alt1250_netdev_ifup(dev, pdn); - } - else - { - alt1250_netdev_ifdown(dev); - } - } - } - } - - return bit; -} - -/**************************************************************************** - * Public functions - ****************************************************************************/ - -/**************************************************************************** - * Name: perform_alt1250events - ****************************************************************************/ - -int perform_alt1250events(FAR struct alt1250_s *dev) -{ - int ret = OK; - uint64_t bitmap; - uint64_t eventbit; - FAR struct alt_container_s *reply_list; - FAR struct alt_container_s *container; - - ret = altdevice_getevent(dev->altfd, &bitmap, &reply_list); - ASSERT(ret == OK); - - if (bitmap & ALT1250_EVTBIT_RESET) - { - /* Handling reset event */ - - ret = perform_alt1250_resetevt(dev, reply_list); - if (ret != REP_MODEM_RESET) - { - /* No need to send reset event to application - * in case of intentional reset - */ - - bitmap &= ~ALT1250_EVTBIT_RESET; - } - } -#ifdef CONFIG_LTE_ALT1250_ENABLE_HIBERNATION_MODE - else if (bitmap & ALT1250_EVTBIT_STOPAPI) - { - /* Handling API stop request */ - - perform_alt1250_apistopevt(dev); - } - else if (bitmap & ALT1250_EVTBIT_RESTARTAPI) - { - /* Handling API restart request */ - - perform_alt1250_restartevt(dev); - } - else if (bitmap & ALT1250_EVTBIT_SUSPEND) - { - /* Handling Suspend request */ - - perform_alt1250_suspendevt(dev); - } -#endif - else - { - /* Handling reply containers */ - - if (bitmap & ALT1250_EVTBIT_REPLY) - { - while ((container = container_pick_listtop(&reply_list)) != NULL) - { - ret = perform_alt1250_reply(dev, container); - if (IS_NEED_CONTAINER_FREE(ret)) - { - container_free(container); - } - } - - bitmap &= ~ALT1250_EVTBIT_REPLY; - } - - /* Handling select async event */ - - if ((eventbit = perform_select_event(dev, bitmap)) != 0ULL) - { - bitmap &= ~eventbit; - } - - /* Handling sms report event */ - - if ((eventbit = perform_sms_report_event(dev, bitmap)) != 0ULL) - { - bitmap &= ~eventbit; - } - - /* Handling report network information event */ - - perform_netinfo_report_event(dev, bitmap); - - /* Do not clear the bit here to notify the event task */ - } - - if (bitmap) - { - alt1250_evttask_sendmsg(dev, bitmap); - } - - return ret; -} diff --git a/lte/alt1250/alt1250_devevent.h b/lte/alt1250/alt1250_devevent.h deleted file mode 100644 index c4e27aa22..000000000 --- a/lte/alt1250/alt1250_devevent.h +++ /dev/null @@ -1,34 +0,0 @@ -/**************************************************************************** - * apps/lte/alt1250/alt1250_devevent.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __APPS_LTE_ALT1250_ALT1250_DEVEVENT_H -#define __APPS_LTE_ALT1250_ALT1250_DEVEVENT_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "alt1250_daemon.h" - -int perform_alt1250events(FAR struct alt1250_s *dev); - -#endif /* __APPS_LTE_ALT1250_ALT1250_DEVEVENT_H */ diff --git a/lte/alt1250/alt1250_devif.c b/lte/alt1250/alt1250_devif.c deleted file mode 100644 index 39c490667..000000000 --- a/lte/alt1250/alt1250_devif.c +++ /dev/null @@ -1,201 +0,0 @@ -/**************************************************************************** - * apps/lte/alt1250/alt1250_devif.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include -#include -#include -#include - -#include "alt1250_devif.h" -#include "alt1250_usockevent.h" - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * name: ioctl_wrapper - ****************************************************************************/ - -static int ioctl_wrapper(int fd, int cmd, unsigned long arg) -{ - int ret; - - ret = ioctl(fd, cmd, arg); - if (ret < 0) - { - ret = -errno; - } - - return ret; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * name: init_alt1250_device - ****************************************************************************/ - -int init_alt1250_device(void) -{ - return open(DEV_ALT1250, O_RDONLY); -} - -/**************************************************************************** - * name: finalize_alt1250_device - ****************************************************************************/ - -void finalize_alt1250_device(int fd) -{ - close(fd); -} - -/**************************************************************************** - * name: altdevice_exchange_selcontainer - ****************************************************************************/ - -FAR struct alt_container_s *altdevice_exchange_selcontainer(int fd, - FAR struct alt_container_s *container) -{ - ioctl(fd, ALT1250_IOC_EXCHGCONTAINER, &container); - return container; -} - -/**************************************************************************** - * name: altdevice_send_command - ****************************************************************************/ - -int altdevice_send_command(FAR struct alt1250_s *dev, int fd, - FAR struct alt_container_s *container, - FAR int32_t *usock_res) -{ - int ret; - -#ifdef CONFIG_LTE_ALT1250_ENABLE_HIBERNATION_MODE - if (dev->is_resuming) - { - *usock_res = -EOPNOTSUPP; - return REP_SEND_ACK; - } -#endif - - ret = ioctl_wrapper(fd, ALT1250_IOC_SEND, (unsigned long)container); - if (ret < 0) - { - *usock_res = ret; - if (ret == -ENETRESET) - { - ret = REP_SEND_ACK_WOFREE; - } - else - { - ret = REP_SEND_ACK; - } - } - else - { - /* In case of send succeeded */ - - ret = container->outparam ? REP_NO_ACK_WOFREE : REP_NO_ACK; - } - - return ret; -} - -/**************************************************************************** - * name: altdevice_powercontrol - ****************************************************************************/ - -int altdevice_powercontrol(int fd, uint32_t cmd) -{ - struct alt_power_s req; - - req.cmdid = cmd; - return ioctl_wrapper(fd, ALT1250_IOC_POWER, (unsigned long)&req); -} - -#ifdef CONFIG_LTE_ALT1250_ENABLE_HIBERNATION_MODE -/**************************************************************************** - * name: altdevice_powerresponse - ****************************************************************************/ - -int altdevice_powerresponse(int fd, uint32_t cmd, int resp) -{ - struct alt_power_s req; - - req.cmdid = cmd; - req.resp = resp; - return ioctl_wrapper(fd, ALT1250_IOC_POWER, (unsigned long)&req); -} -#endif - -/**************************************************************************** - * name: altdevice_seteventbuff - ****************************************************************************/ - -int altdevice_seteventbuff(int fd, FAR struct alt_evtbuffer_s *buffer) -{ - return (buffer) ? ioctl_wrapper(fd, ALT1250_IOC_SETEVTBUFF, - (unsigned long)buffer) : -EINVAL; -} - -/**************************************************************************** - * name: altdevice_getevent - ****************************************************************************/ - -int altdevice_getevent(int fd, FAR uint64_t *evtbitmap, - FAR struct alt_container_s **replies) -{ - int ret = -EIO; - struct alt_readdata_s dat; - - if (read(fd, &dat, sizeof(struct alt_readdata_s)) - == sizeof(struct alt_readdata_s)) - { - ret = OK; - *evtbitmap = dat.evtbitmap; - *replies = dat.head; - } - - return ret; -} - -/**************************************************************************** - * name: altdevice_reset - ****************************************************************************/ - -void altdevice_reset(int fd) -{ - altdevice_powercontrol(fd, LTE_CMDID_POWEROFF); - usleep(1); - altdevice_powercontrol(fd, LTE_CMDID_POWERON); -} diff --git a/lte/alt1250/alt1250_devif.h b/lte/alt1250/alt1250_devif.h deleted file mode 100644 index 01c689625..000000000 --- a/lte/alt1250/alt1250_devif.h +++ /dev/null @@ -1,57 +0,0 @@ -/**************************************************************************** - * apps/lte/alt1250/alt1250_devif.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __APPS_LTE_ALT1250_ALT1250_DEVIF_H -#define __APPS_LTE_ALT1250_ALT1250_DEVIF_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include "alt1250_daemon.h" - -#define DEV_ALT1250 "/dev/alt1250" - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -int init_alt1250_device(void); -void finalize_alt1250_device(int fd); -FAR struct alt_container_s *altdevice_exchange_selcontainer(int fd, - FAR struct alt_container_s *container); -int altdevice_send_command(FAR struct alt1250_s *dev, int fd, - FAR struct alt_container_s *container, - FAR int32_t *usock_res); -int altdevice_powercontrol(int fd, uint32_t cmd); -int altdevice_seteventbuff(int fd, FAR struct alt_evtbuffer_s *buffers); -int altdevice_getevent(int fd, FAR uint64_t *evtbitmap, - FAR struct alt_container_s **replies); -void altdevice_reset(int fd); -#ifdef CONFIG_LTE_ALT1250_ENABLE_HIBERNATION_MODE -int altdevice_powerresponse(int fd, uint32_t cmd, int resp); -#endif - -#endif /* __APPS_LTE_ALT1250_ALT1250_DEVIF_H */ diff --git a/lte/alt1250/alt1250_main.c b/lte/alt1250/alt1250_main.c deleted file mode 100644 index db40a6bf9..000000000 --- a/lte/alt1250/alt1250_main.c +++ /dev/null @@ -1,495 +0,0 @@ -/**************************************************************************** - * apps/lte/alt1250/alt1250_main.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include -#include -#include -#include - -#include "alt1250_dbg.h" -#include "alt1250_daemon.h" -#include "alt1250_devif.h" -#include "alt1250_devevent.h" -#include "alt1250_usockif.h" -#include "alt1250_usockevent.h" -#include "alt1250_container.h" -#include "alt1250_select.h" -#include "alt1250_usrsock_hdlr.h" -#include "alt1250_evt.h" -#include "alt1250_netdev.h" -#include "alt1250_sms.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define SYNC_CMD_PREFIX "-s" - -#define ALTFDNO (0) -#define USOCKFDNO (1) - -#define SET_POLLIN(fds, fid) \ - do \ - { \ - (fds).fd = (fid); \ - (fds).events = POLLIN; \ - } \ - while (0) - -#define IS_POLLIN(fds) ((fds).revents & POLLIN) - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static struct alt1250_s *g_daemon = NULL; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: notify_to_lapi_caller - ****************************************************************************/ - -static void notify_to_lapi_caller(sem_t *syncsem) -{ - /* has -s (sync) option? */ - - if (syncsem) - { - /* Notify release to lapi waiting for synchronization */ - - sem_post(syncsem); - } -} - -/**************************************************************************** - * Name: initialize_daemon - ****************************************************************************/ - -static int initialize_daemon(FAR struct alt1250_s *dev) -{ - int ret; - - /* Initialize sub-system */ - - /* Event call back task must be started - * before any device files are opened - */ - - ret = alt1250_evttask_start(); - ASSERT(ret > 0); - - dev->altfd = init_alt1250_device(); - ASSERT(dev->altfd >= 0); - - dev->usockfd = init_usock_device(); - ASSERT(dev->usockfd >= 0); - - ret = altdevice_seteventbuff(dev->altfd, init_event_buffer()); - ASSERT(ret >= 0); - - init_containers(); - init_selectcontainer(dev); - alt1250_sms_initcontainer(dev); - alt1250_netdev_register(dev); - - return OK; -} - -/**************************************************************************** - * Name: finalize_daemon - ****************************************************************************/ - -static void finalize_daemon(FAR struct alt1250_s *dev) -{ - alt1250_netdev_unregister(dev); - alt1250_evtdatadestroy(); - finalize_alt1250_device(dev->altfd); - finalize_usock_device(dev->usockfd); - alt1250_evttask_stop(dev); -} - -/**************************************************************************** - * Name: alt1250_loop - ****************************************************************************/ - -static int alt1250_loop(FAR struct alt1250_s *dev) -{ - int ret; - int pw_stat; - struct pollfd fds[2]; - nfds_t nfds; - bool is_running = true; - - initialize_daemon(dev); - - /* Get modem power status. If modem is turned on, it means resuming from - * hibernation mode. - */ - - pw_stat = altdevice_powercontrol(dev->altfd, LTE_CMDID_GET_POWER_STAT); - - dbg_alt1250("Modem power status = %d\n", pw_stat); - - if (pw_stat) - { - dev->is_resuming = true; - } - else - { - dev->is_resuming = false; - } - - notify_to_lapi_caller(dev->syncsem); - - /* Main loop of this daemon */ - - while (is_running) - { - memset(fds, 0, sizeof(fds)); - - SET_POLLIN(fds[ALTFDNO], dev->altfd); - nfds = 1; - - /* if (!dev->is_usockrcvd && !dev->recvfrom_processing) */ - - if (ACCEPT_USOCK_REQUEST(dev)) - { - SET_POLLIN(fds[USOCKFDNO], dev->usockfd); - nfds++; - } - - ret = poll(fds, nfds, -1); - ASSERT(ret > 0); - ret = OK; - - if (IS_POLLIN(fds[ALTFDNO])) - { - ret = perform_alt1250events(dev); - } - - dbg_alt1250("ret: %u, recvfrom_processing: %d," - " IS_POLLIN: %d, is_usockrcvd: %d\n", - ret, dev->recvfrom_processing, - IS_POLLIN(fds[USOCKFDNO]), dev->is_usockrcvd); - - if ((ret != REP_MODEM_RESET) && (!dev->recvfrom_processing) - && (IS_POLLIN(fds[USOCKFDNO]) || dev->is_usockrcvd)) - { - switch (perform_usockrequest(dev)) - { - case REP_SEND_TERM: - is_running = false; - break; - - case REP_NO_CONTAINER: - - /* Do nothing because request could - * not send to modem driver because of - * no more container. To wait for empty container. - */ - - break; - - default: - dev->is_usockrcvd = false; - break; - } - } - } - - finalize_daemon(dev); - - return OK; -} - -#ifdef CONFIG_LTE_ALT1250_ENABLE_HIBERNATION_MODE -/**************************************************************************** - * Name: calc_checksum - ****************************************************************************/ - -static uint16_t calc_checksum(FAR uint8_t *ptr, uint16_t len) -{ - uint32_t ret = 0x00; - uint32_t calctmp = 0x00; - uint16_t i; - - /* Data accumulating */ - - for (i = 0; i < len; i++) - { - calctmp += ptr[i]; - } - - ret = ~((calctmp & 0xffff) + (calctmp >> 16)); - - return (uint16_t)ret; -} -#endif - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -int main(int argc, FAR char *argv[]) -{ - int ret; - FAR char *endptr; - FAR sem_t *syncsem = NULL; - - if (argc > 1) - { - /* The format is "-sXXXXXXXX". - * XXXXXXXXX indicates the pointer address to the semaphore - * that will be posted at the timing when the daemon opens the - * usersock device. - */ - - if (!(strncmp(argv[1], SYNC_CMD_PREFIX, strlen(SYNC_CMD_PREFIX)))) - { - syncsem = (FAR sem_t *)strtol(&argv[1][strlen(SYNC_CMD_PREFIX)], - &endptr, 16); - if (!syncsem || endptr == &argv[1][strlen(SYNC_CMD_PREFIX)] || - *endptr != '\0') - { - return -EINVAL; - } - } - } - - if (g_daemon) - { - fprintf(stderr, "%s is already running! \n", argv[0]); - notify_to_lapi_caller(syncsem); - return -1; - } - - g_daemon = calloc(sizeof(struct alt1250_s), 1); - ASSERT(g_daemon); - - g_daemon->syncsem = syncsem; - g_daemon->evtq = (mqd_t)-1; - g_daemon->sid = -1; - g_daemon->is_usockrcvd = false; - g_daemon->usock_enable = TRUE; - g_daemon->is_support_lwm2m = false; - g_daemon->lwm2m_apply_xid = -1; - g_daemon->api_enable = true; - g_daemon->context_cb = NULL; - MODEM_STATE_POFF(g_daemon); - - reset_fwupdate_info(g_daemon); - - ret = alt1250_loop(g_daemon); - free(g_daemon); - g_daemon = NULL; - - /* Notify lapi that Daemon has finished */ - - notify_to_lapi_caller(syncsem); - - return ret; -} - -#ifdef CONFIG_LTE_ALT1250_ENABLE_HIBERNATION_MODE -int alt1250_set_api_enable(FAR struct alt1250_s *dev, bool enable) -{ - if (!dev) - { - return ERROR; - } - - dev->api_enable = enable; - - return OK; -} - -int alt1250_count_opened_sockets(FAR struct alt1250_s *dev) -{ - int ret = 0; - int i = 0; - FAR struct usock_s *sock; - - if (!dev) - { - return ERROR; - } - - for (i = 0; i < nitems(dev->sockets); i++) - { - sock = &dev->sockets[i]; - if (sock->state != SOCKET_STATE_CLOSED) - { - ret++; - } - } - - return ret; -} - -int alt1250_is_api_in_progress(FAR struct alt1250_s *dev) -{ - if (!dev) - { - return ERROR; - } - - return dev->is_usockrcvd ? 1 : 0; -} - -int alt1250_set_context_save_cb(FAR struct alt1250_s *dev, - context_save_cb_t context_cb) -{ - if (!dev) - { - return ERROR; - } - - dev->context_cb = context_cb; - - return OK; -} - -int alt1250_collect_daemon_context(FAR struct alt1250_s *dev) -{ - struct alt1250_save_ctx ctx; - - if (!dev) - { - return ERROR; - } - - if (!dev->context_cb) - { - return ERROR; - } - - memset(&ctx, 0, sizeof(struct alt1250_save_ctx)); - - /* Copy APN settings */ - - ctx.ip_type = dev->apn.ip_type; - ctx.auth_type = dev->apn.auth_type; - ctx.apn_type = dev->apn.apn_type; - memcpy(ctx.apn_name, dev->apn_name, LTE_APN_LEN); - memcpy(ctx.user_name, dev->user_name, LTE_APN_USER_NAME_LEN); - memcpy(ctx.pass, dev->pass, LTE_APN_PASSWD_LEN); - - /* Copy connection information */ - - ctx.d_flags = dev->net_dev.d_flags; - -#ifdef CONFIG_NET_IPv4 - memcpy(&ctx.d_ipaddr, &dev->net_dev.d_ipaddr, sizeof(in_addr_t)); - memcpy(&ctx.d_draddr, &dev->net_dev.d_draddr, sizeof(in_addr_t)); - memcpy(&ctx.d_netmask, &dev->net_dev.d_netmask, sizeof(in_addr_t)); -#endif -#ifdef CONFIG_NET_IPv6 - memcpy(&ctx.d_ipv6addr, &dev->net_dev.d_ipv6addr, sizeof(net_ipv6addr_t)); - memcpy(&ctx.d_ipv6draddr, - &dev->net_dev.d_ipv6draddr, - sizeof(net_ipv6addr_t)); - memcpy(&ctx.d_ipv6netmask, - &dev->net_dev.d_ipv6netmask, - sizeof(net_ipv6addr_t)); -#endif - - /* Save checksum without checksum for validation */ - - ctx.checksum = calc_checksum((FAR uint8_t *)&ctx, - offsetof(struct alt1250_save_ctx, checksum)); - - /* Call user application callback */ - - dev->context_cb((FAR uint8_t *)&ctx, sizeof(ctx)); - - return OK; -} - -int alt1250_apply_daemon_context(FAR struct alt1250_s *dev, - FAR struct alt1250_save_ctx *ctx) -{ - uint16_t checksum; - - if (!dev) - { - return ERROR; - } - - /* Calc checksum without checksum parameter */ - - checksum = calc_checksum((FAR uint8_t *)ctx, - offsetof(struct alt1250_save_ctx, checksum)); - - if (ctx->checksum != checksum) - { - dbg_alt1250("Saved context is invalid.\n"); - return ERROR; - } - - /* Copy APN settings */ - - dev->apn.ip_type = ctx->ip_type; - dev->apn.auth_type = ctx->auth_type; - dev->apn.apn_type = ctx->apn_type; - memcpy(dev->apn_name, ctx->apn_name, LTE_APN_LEN); - memcpy(dev->user_name, ctx->user_name, LTE_APN_USER_NAME_LEN); - memcpy(dev->pass, ctx->pass, LTE_APN_PASSWD_LEN); - - /* Set APN related pointers */ - - dev->apn.apn = dev->apn_name; - dev->apn.user_name = dev->user_name; - dev->apn.password = dev->pass; - - /* Copy connection information */ - - dev->net_dev.d_flags = ctx->d_flags; - -#ifdef CONFIG_NET_IPv4 - memcpy(&dev->net_dev.d_ipaddr, &ctx->d_ipaddr, sizeof(in_addr_t)); - memcpy(&dev->net_dev.d_draddr, &ctx->d_draddr, sizeof(in_addr_t)); - memcpy(&dev->net_dev.d_netmask, &ctx->d_netmask, sizeof(in_addr_t)); -#endif -#ifdef CONFIG_NET_IPv6 - memcpy(&dev->net_dev.d_ipv6addr, &ctx->d_ipv6addr, sizeof(net_ipv6addr_t)); - memcpy(&dev->net_dev.d_ipv6draddr, - &ctx->d_ipv6draddr, - sizeof(net_ipv6addr_t)); - memcpy(&dev->net_dev.d_ipv6netmask, - &ctx->d_ipv6netmask, - sizeof(net_ipv6addr_t)); -#endif - - return OK; -} -#endif diff --git a/lte/alt1250/alt1250_netdev.c b/lte/alt1250/alt1250_netdev.c deleted file mode 100644 index f0e8719fa..000000000 --- a/lte/alt1250/alt1250_netdev.c +++ /dev/null @@ -1,117 +0,0 @@ -/**************************************************************************** - * apps/lte/alt1250/alt1250_netdev.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include - -#include "alt1250_netdev.h" - -#define ALT1250_SUBNET_MASK 0xFFFFFF00 /* 255.255.255.0 this is dummy */ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * name: alt1250_netdev_register - ****************************************************************************/ - -void alt1250_netdev_register(FAR struct alt1250_s *dev) -{ - netdev_register(&dev->net_dev, NET_LL_ETHERNET); -} - -/**************************************************************************** - * name: alt1250_netdev_unregister - ****************************************************************************/ - -void alt1250_netdev_unregister(FAR struct alt1250_s *dev) -{ - netdev_unregister(&dev->net_dev); -} - -/**************************************************************************** - * name: alt1250_netdev_ifdown - ****************************************************************************/ - -void alt1250_netdev_ifdown(FAR struct alt1250_s *dev) -{ - dev->net_dev.d_flags = ~IFF_UP; -#ifdef CONFIG_NET_IPv4 - memset(&dev->net_dev.d_ipaddr, 0, sizeof(dev->net_dev.d_ipaddr)); - memset(&dev->net_dev.d_draddr, 0, sizeof(dev->net_dev.d_draddr)); - memset(&dev->net_dev.d_netmask, 0, sizeof(dev->net_dev.d_netmask)); -#endif -#ifdef CONFIG_NET_IPv6 - memset(&dev->net_dev.d_ipv6addr, 0, sizeof(dev->net_dev.d_ipv6addr)); -#endif -} - -/**************************************************************************** - * name: alt1250_netdev_ifup - ****************************************************************************/ - -void alt1250_netdev_ifup(FAR struct alt1250_s *dev, FAR lte_pdn_t *pdn) -{ - int i; - - dev->net_dev.d_flags = IFF_UP; - - for (i = 0; i < pdn->ipaddr_num; i++) - { -#ifdef CONFIG_NET_IPv4 - if (LTE_IPTYPE_V4 == pdn->address[i].ip_type) - { - inet_pton(AF_INET, - (FAR const char *)pdn->address[i].address, - (FAR void *)&dev->net_dev.d_ipaddr); - inet_pton(AF_INET, - (FAR const char *)pdn->address[i].address, - (FAR void *)&dev->net_dev.d_draddr); - - /* The following parameters are dummy values because - * they cannot be obtained from alt1250. - */ - - dev->net_dev.d_draddr = htonl((ntohl(dev->net_dev.d_draddr) & - ALT1250_SUBNET_MASK) | 1); - dev->net_dev.d_netmask = htonl(ALT1250_SUBNET_MASK); - } -#endif - -#ifdef CONFIG_NET_IPv6 - if (LTE_IPTYPE_V6 == pdn->address[i].ip_type) - { - inet_pton(AF_INET6, - (FAR const char *)pdn->address[i].address, - (FAR void *)&dev->net_dev.d_ipv6addr); - } -#endif - } -} diff --git a/lte/alt1250/alt1250_netdev.h b/lte/alt1250/alt1250_netdev.h deleted file mode 100644 index 3d9c67f42..000000000 --- a/lte/alt1250/alt1250_netdev.h +++ /dev/null @@ -1,43 +0,0 @@ -/**************************************************************************** - * apps/lte/alt1250/alt1250_netdev.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __APPS_LTE_ALT1250_ALT1250_NETDEV_H -#define __APPS_LTE_ALT1250_ALT1250_NETDEV_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include "alt1250_daemon.h" - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -void alt1250_netdev_register(FAR struct alt1250_s *dev); -void alt1250_netdev_unregister(FAR struct alt1250_s *dev); -void alt1250_netdev_ifdown(FAR struct alt1250_s *dev); -void alt1250_netdev_ifup(FAR struct alt1250_s *dev, FAR lte_pdn_t *pdn); - -#endif /* __APPS_LTE_ALT1250_ALT1250_NETDEV_H */ diff --git a/lte/alt1250/alt1250_postproc.h b/lte/alt1250/alt1250_postproc.h deleted file mode 100644 index 4e4b819fe..000000000 --- a/lte/alt1250/alt1250_postproc.h +++ /dev/null @@ -1,51 +0,0 @@ -/**************************************************************************** - * apps/lte/alt1250/alt1250_postproc.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __APPS_LTE_ALT1250_ALT1250_POSTPROC_H -#define __APPS_LTE_ALT1250_ALT1250_POSTPROC_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -#include "alt1250_daemon.h" -#include "alt1250_usockif.h" - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -typedef CODE int (*postproc_hdlr_t)(FAR struct alt1250_s *dev, - FAR struct alt_container_s *reply, FAR struct usock_s *usock, - FAR int32_t *usock_result, uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo, unsigned long arg); - -struct postproc_s -{ - postproc_hdlr_t hdlr; - unsigned long priv; -}; - -#endif /* __APPS_LTE_ALT1250_ALT1250_POSTPROC_H */ diff --git a/lte/alt1250/alt1250_reset_seq.c b/lte/alt1250/alt1250_reset_seq.c deleted file mode 100644 index f6080887c..000000000 --- a/lte/alt1250/alt1250_reset_seq.c +++ /dev/null @@ -1,443 +0,0 @@ -/**************************************************************************** - * apps/lte/alt1250/alt1250_reset_seq.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -#include -#include -#include -#include -#include - -#include "alt1250_dbg.h" -#include "alt1250_devif.h" -#include "alt1250_devevent.h" -#include "alt1250_postproc.h" -#include "alt1250_container.h" -#include "alt1250_ioctl_subhdlr.h" -#include "alt1250_usrsock_hdlr.h" -#include "alt1250_reset_seq.h" -#include "alt1250_atcmd.h" -#include "alt1250_evt.h" - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -struct reset_arg_s -{ - int seq_no; - unsigned long arg; -}; - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static struct reset_arg_s reset_arg; - -static postproc_hdlr_t ponreset_seq[] = -{ - postproc_fwgetversion, -}; -#define PONRESET_SEQ_NUM nitems(ponreset_seq) - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * name: postproc_ponresetseq - ****************************************************************************/ - -static int postproc_ponresetseq(FAR struct alt1250_s *dev, - FAR struct alt_container_s *reply, - FAR struct usock_s *usock, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo, - unsigned long arg) -{ - int ret = REP_NO_ACK_WOFREE; - FAR struct reset_arg_s *rarg = (FAR struct reset_arg_s *)arg; - ASSERT(rarg->seq_no < PONRESET_SEQ_NUM); - - ponreset_seq[rarg->seq_no](dev, reply, usock, usock_result, usock_xid, - ackinfo, rarg->arg); - rarg->seq_no++; - if (rarg->seq_no == PONRESET_SEQ_NUM) - { - /* On last postproc, container should be free */ - - dev->recvfrom_processing = false; - ret = REP_NO_ACK; - MODEM_STATE_PON(dev); - } - - return ret; -} - -/**************************************************************************** - * name: send_getversion_onreset - ****************************************************************************/ - -static int send_getversion_onreset(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - FAR int32_t *usock_result) -{ - reset_arg.seq_no = 0; - reset_arg.arg = 0; - - set_container_ids(container, -1, LTE_CMDID_GETVER); - set_container_argument(container, NULL, 0); - set_container_response(container, alt1250_getevtarg(LTE_CMDID_GETVER), 2); - set_container_postproc(container, postproc_ponresetseq, - (unsigned long)&reset_arg); - - return altdevice_send_command(dev, dev->altfd, container, usock_result); -} - -/**************************************************************************** - * name: str_toupper_case - ****************************************************************************/ - -static void str_toupper_case(FAR char *data, int len) -{ - int i; - - for (i = 0; i < len; i++) - { - data[i] = (char)toupper(data[i]); - } -} - -/**************************************************************************** - * name: recv_atreply_onreset - ****************************************************************************/ - -static int recv_atreply_onreset(atreply_parser_t parse, - FAR struct alt1250_s *dev, - FAR void *arg) -{ - int ret; - uint64_t bitmap; - struct pollfd fds; - nfds_t nfds; - FAR struct alt_container_s *rlist; - FAR struct alt_container_s *container; - FAR char *reply; - int rlen; - - fds.fd = dev->altfd; - fds.events = POLLIN; - nfds = 1; - - ret = poll(&fds, nfds, -1); - ASSERT(ret > 0); - ASSERT(fds.revents & POLLIN); - - ret = altdevice_getevent(dev->altfd, &bitmap, &rlist); - ASSERT(ret == OK); - - if (bitmap & ALT1250_EVTBIT_RESET) - { - /* Reset is happened again... */ - - container_free_all(rlist); - dev->sid = -1; - - ret = REP_MODEM_RESET; - } - else if (bitmap & ALT1250_EVTBIT_REPLY) - { - container = container_pick_listtop(&rlist); - ASSERT(rlist == NULL); - - reply = (FAR char *)container->outparam[0]; - rlen = *(FAR int *)container->outparam[2]; - - str_toupper_case(reply, rlen); - ret = parse(reply, rlen, arg); - ASSERT(ret == OK); - - ret = REP_NO_ACK; - } - else - { - ASSERT(0); /* Should not be here */ - } - - return ret; -} - -/**************************************************************************** - * name: alt1250_disable_scanplan - ****************************************************************************/ - -static int alt1250_disable_scanplan(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container) -{ - int recv_ret; - struct atreply_truefalse_s t_or_f; - - t_or_f.target_str = "0"; - ltesp_send_getscanplan(dev, container); - recv_ret = recv_atreply_onreset(check_atreply_truefalse, dev, &t_or_f); - if (recv_ret == REP_MODEM_RESET) - { - return recv_ret; - } - - if (!t_or_f.result) - { - ltesp_send_setscanplan(dev, container, false); - recv_ret = recv_atreply_onreset(check_atreply_ok, dev, NULL); - if (recv_ret == REP_MODEM_RESET) - { - return recv_ret; - } - } - - return recv_ret; -} - -/**************************************************************************** - * name: alt1250_lwm2m_ponreset - ****************************************************************************/ - -static int alt1250_lwm2m_ponreset(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container) -{ - int ret = REP_NO_ACK; - int recv_ret; - struct atreply_truefalse_s t_or_f; - int32_t usock_result = OK; - - /* Make sure LwM2M func enabled */ - - t_or_f.target_str = "\nTRUE\r"; - lwm2mstub_send_getenable(dev, container, &usock_result); - if (usock_result == -ENOTSUP) - { - return REP_NO_ACK; - } - - recv_ret = recv_atreply_onreset(check_atreply_truefalse, dev, &t_or_f); - if (recv_ret == REP_MODEM_RESET) - { - return recv_ret; - } - - if (!t_or_f.result) - { - lwm2mstub_send_setenable(dev, container, true); - recv_ret = recv_atreply_onreset(check_atreply_ok, dev, NULL); - if (recv_ret == REP_MODEM_RESET) - { - return recv_ret; - } - - ret = REP_SEND_ACK; - } - - /* Make sure LwM2M AutoConnect is disabled */ - - t_or_f.target_str = "\nFALSE\r"; - lwm2mstub_send_getautoconnect(dev, container); - recv_ret = recv_atreply_onreset(check_atreply_truefalse, dev, &t_or_f); - if (recv_ret == REP_MODEM_RESET) - { - return recv_ret; - } - - if (!t_or_f.result) - { - lwm2mstub_send_setautoconnect(dev, container, false); - recv_ret = recv_atreply_onreset(check_atreply_ok, dev, NULL); - if (recv_ret == REP_MODEM_RESET) - { - return recv_ret; - } - - ret = REP_SEND_ACK; - } - - /* Make sure LwM2M Version is 1.1 */ - - t_or_f.target_str = "\n1.1\r"; - lwm2mstub_send_getversion(dev, container); - recv_ret = recv_atreply_onreset(check_atreply_truefalse, dev, &t_or_f); - if (recv_ret == REP_MODEM_RESET) - { - return recv_ret; - } - - if (!t_or_f.result) - { - lwm2mstub_send_setversion(dev, container, true); - recv_ret = recv_atreply_onreset(check_atreply_ok, dev, NULL); - if (recv_ret == REP_MODEM_RESET) - { - return recv_ret; - } - - ret = REP_SEND_ACK; - } - - /* Make sure LwM2M NameMode is 0:UserName */ - - t_or_f.target_str = "\n0\r"; - lwm2mstub_send_getnamemode(dev, container); - recv_ret = recv_atreply_onreset(check_atreply_truefalse, dev, &t_or_f); - if (recv_ret == REP_MODEM_RESET) - { - return recv_ret; - } - - if (!t_or_f.result) - { - lwm2mstub_send_setnamemode(dev, container, 0); - recv_ret = recv_atreply_onreset(check_atreply_ok, dev, NULL); - if (recv_ret == REP_MODEM_RESET) - { - return recv_ret; - } - - ret = REP_SEND_ACK; - } - - /* Make sure NWOPER is not DEFAULT */ - - t_or_f.target_str = "DEFAULT"; - ltenwop_send_getnwop(dev, container); - recv_ret = recv_atreply_onreset(check_atreply_truefalse, dev, &t_or_f); - if (recv_ret == REP_MODEM_RESET) - { - return recv_ret; - } - - if (t_or_f.result) - { - ltenwop_send_setnwoptp(dev, container); - recv_ret = recv_atreply_onreset(check_atreply_ok, dev, NULL); - if (recv_ret == REP_MODEM_RESET) - { - return recv_ret; - } - - ret = REP_SEND_ACK; - } - - /* Make sure SCAN_PALAN_EN is 0 */ - - recv_ret = alt1250_disable_scanplan(dev, container); - if (recv_ret == REP_MODEM_RESET) - { - return recv_ret; - } - - if (ret == REP_SEND_ACK) - { - /* Force Reset is needed. */ - - altdevice_reset(dev->altfd); - } - - dev->is_support_lwm2m = true; - - return ret; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * name: handle_poweron_reset_stage2 - ****************************************************************************/ - -int handle_poweron_reset_stage2(FAR struct alt1250_s *dev) -{ - int ret; - int32_t unused; - FAR struct alt_container_s *container; - - container = container_alloc(); - ASSERT(container != NULL); - - ret = send_getversion_onreset(dev, container, &unused); - - if (IS_NEED_CONTAINER_FREE(ret)) - { - container_free(container); - } - - if (ret > 0) - { - /* for blocking next usrsock request */ - - ret = REP_MODEM_RESET; - dev->recvfrom_processing = true; - } - - return ret; -} - -/**************************************************************************** - * name: handle_poweron_reset - ****************************************************************************/ - -int handle_poweron_reset(FAR struct alt1250_s *dev) -{ - int ret = REP_MODEM_RESET; - FAR struct alt_container_s *container; - - container = container_alloc(); - ASSERT(container != NULL); - - while (ret == REP_MODEM_RESET) - { - ret = alt1250_lwm2m_ponreset(dev, container); - } - - container_free(container); - - MODEM_STATE_B4PON_2ND(dev); - - if (ret == REP_NO_ACK) - { - /* In this sequence, - * NO_ACK means no force reset. - * In that case, get version is needed to send here. - */ - - handle_poweron_reset_stage2(dev); - ret = REP_MODEM_RESET; - } - - return ret; -} diff --git a/lte/alt1250/alt1250_reset_seq.h b/lte/alt1250/alt1250_reset_seq.h deleted file mode 100644 index d5769522f..000000000 --- a/lte/alt1250/alt1250_reset_seq.h +++ /dev/null @@ -1,43 +0,0 @@ -/**************************************************************************** - * apps/lte/alt1250/alt1250_reset_seq.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __APPS_LTE_ALT1250_ALT1250_RESET_SEQ_H -#define __APPS_LTE_ALT1250_ALT1250_RESET_SEQ_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -#include "alt1250_daemon.h" - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -int handle_poweron_reset(FAR struct alt1250_s *dev); -int handle_poweron_reset_stage2(FAR struct alt1250_s *dev); -int handle_commit_reset(FAR struct alt1250_s *dev); - -#endif /* __APPS_LTE_ALT1250_ALT1250_RESET_SEQ_H */ diff --git a/lte/alt1250/alt1250_select.c b/lte/alt1250/alt1250_select.c deleted file mode 100644 index dd44d38f2..000000000 --- a/lte/alt1250/alt1250_select.c +++ /dev/null @@ -1,370 +0,0 @@ -/**************************************************************************** - * apps/lte/alt1250/alt1250_select.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include - -#include - -#include "alt1250_dbg.h" -#include "alt1250_daemon.h" -#include "alt1250_socket.h" -#include "alt1250_usockif.h" -#include "alt1250_container.h" -#include "alt1250_devif.h" -#include "alt1250_evt.h" -#include "alt1250_usrsock_hdlr.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define SELECT_CONTAINER_MAX (2) -#define SELECT_MODE_NONBLOCK (0) -#define SELECT_MODE_BLOCK (1) -#define SELECT_MODE_BLOCKCANCEL (2) -#define READSET_BIT (1 << 0) -#define WRITESET_BIT (1 << 1) - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -struct select_params_s -{ - int32_t ret; - int32_t err; - int32_t id; - altcom_fd_set readset; - altcom_fd_set writeset; - altcom_fd_set exceptset; -}; - -/**************************************************************************** - * Private Function Prototype - ****************************************************************************/ - -static struct alt_container_s select_container_obj[SELECT_CONTAINER_MAX]; -static FAR struct alt_container_s *g_current_container; -static FAR void *g_selectargs[SELECT_CONTAINER_MAX][6]; -static struct select_params_s g_select_params[SELECT_CONTAINER_MAX]; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * name: send_select_command - ****************************************************************************/ - -static int send_select_command(FAR struct alt1250_s *dev, - int32_t mode, int32_t id, int32_t maxfds, - FAR altcom_fd_set *readset, - FAR altcom_fd_set *writeset, - FAR altcom_fd_set *exceptset) -{ - FAR void *in[7]; - uint16_t used_setbit = 0; - int32_t usock_result; - struct alt_container_s container = - { - 0 - }; - - if (readset) - { - used_setbit |= READSET_BIT; - } - - if (writeset) - { - used_setbit |= WRITESET_BIT; - } - - /* These members are referenced only when sending a command and - * not when receiving a response, so local variables are used. - */ - - in[0] = &mode; - in[1] = &id; - in[2] = &maxfds; - in[3] = &used_setbit; - in[4] = readset; - in[5] = writeset; - in[6] = exceptset; - - set_container_ids(&container, 0, LTE_CMDID_SELECT); - set_container_argument(&container, in, nitems(in)); - - return altdevice_send_command(dev, dev->altfd, &container, &usock_result); -} - -/**************************************************************************** - * Name: select_cancel - ****************************************************************************/ - -static void select_cancel(FAR struct alt1250_s *dev) -{ - int32_t dummy_maxfds = 0; - altcom_fd_set dummy_readset; - altcom_fd_set dummy_writeset; - altcom_fd_set dummy_exceptset; - - if (dev->sid != -1) - { - send_select_command(dev, SELECT_MODE_BLOCKCANCEL, dev->sid, - dummy_maxfds, &dummy_readset, &dummy_writeset, - &dummy_exceptset); - dev->sid = -1; - } -} - -/**************************************************************************** - * name: select_start - ****************************************************************************/ - -static void select_start(FAR struct alt1250_s *dev) -{ - int32_t maxfds = -1; - altcom_fd_set readset; - altcom_fd_set writeset; - altcom_fd_set exceptset; - FAR struct usock_s *usock; - int i; - - dev->sid = (++dev->scnt & 0x7fffffff); - - ALTCOM_FD_ZERO(&readset); - ALTCOM_FD_ZERO(&writeset); - ALTCOM_FD_ZERO(&exceptset); - - for (i = 0; i < SOCKET_COUNT; i++) - { - usock = usocket_search(dev, i); - if (usock && IS_STATE_SELECTABLE(usock)) - { - if (IS_STATE_READABLE(usock)) - { - ALTCOM_FD_SET(USOCKET_ALTSOCKID(usock), &readset); - } - - if (IS_STATE_WRITABLE(usock)) - { - ALTCOM_FD_SET(USOCKET_ALTSOCKID(usock), &writeset); - } - - ALTCOM_FD_SET(USOCKET_ALTSOCKID(usock), &exceptset); - - maxfds = ((maxfds > USOCKET_ALTSOCKID(usock)) ? maxfds : - USOCKET_ALTSOCKID(usock)); - } - } - - if (maxfds != -1) - { - send_select_command(dev, SELECT_MODE_BLOCK, dev->sid, - maxfds + 1, &readset, &writeset, &exceptset); - } -} - -/**************************************************************************** - * name: recv_selectcontainer - ****************************************************************************/ - -static FAR struct alt_container_s *recv_selectcontainer( - FAR struct alt1250_s *dev) -{ - g_current_container = altdevice_exchange_selcontainer(dev->altfd, - g_current_container); - return g_current_container; -} - -/**************************************************************************** - * name: operate_dataavail - ****************************************************************************/ - -static void operate_dataavail(FAR struct alt1250_s *dev, - FAR struct usock_s *usock, - FAR altcom_fd_set *readset, - FAR altcom_fd_set *writeset, - FAR altcom_fd_set *exceptset) -{ - if (IS_STATE_SELECTABLE(usock)) - { - if (ALTCOM_FD_ISSET(USOCKET_ALTSOCKID(usock), exceptset)) - { - dbg_alt1250("exceptset is set. usockid: %d\n", - USOCKET_USOCKID(usock)); - - USOCKET_SET_STATE(usock, SOCKET_STATE_ABORTED); - } - - if (ALTCOM_FD_ISSET(USOCKET_ALTSOCKID(usock), readset)) - { - dbg_alt1250("readset is set. usockid: %d\n", - USOCKET_USOCKID(usock)); - - USOCKET_CLR_SELECTABLE(usock, SELECT_READABLE); - usockif_sendrxready(dev->usockfd, USOCKET_USOCKID(usock)); - } - - if (ALTCOM_FD_ISSET(USOCKET_ALTSOCKID(usock), writeset)) - { - dbg_alt1250("writeset is set. usockid: %d\n", - USOCKET_USOCKID(usock)); - - if (USOCKET_STATE(usock) == SOCKET_STATE_WAITCONN) - { - if (nextstep_check_connectres(dev, usock) == REP_NO_ACK_WOFREE) - { - USOCKET_CLR_SELECTABLE(usock, SELECT_WRITABLE); - } - } - else - { - USOCKET_CLR_SELECTABLE(usock, SELECT_WRITABLE); - usockif_sendtxready(dev->usockfd, USOCKET_USOCKID(usock)); - } - } - } -} - -/**************************************************************************** - * Name: handle_selectevt - ****************************************************************************/ - -static void handle_selectevt(FAR struct alt1250_s *dev, - int32_t altcom_resp, int32_t modem_errno, - int32_t selectreq_id, - FAR altcom_fd_set *readset, - FAR altcom_fd_set *writeset, - FAR altcom_fd_set *exceptset) -{ - int i; - FAR struct usock_s *usock; - - dbg_alt1250("select reply. ret=%ld modem_errno=%ld\n", - altcom_resp, modem_errno); - - if (selectreq_id == dev->sid) - { - altcom_resp = COMBINE_ERRCODE(altcom_resp, modem_errno); - if (altcom_resp >= 0) - { - for (i = 0; i < SOCKET_COUNT; i++) - { - usock = usocket_search(dev, i); - operate_dataavail(dev, usock, readset, writeset, exceptset); - } - - usocket_commitstate(dev); - } - } - - /* For debug */ - - else - { - dbg_alt1250("Select event come wish in no selected. sel_id = %ld\n", - selectreq_id); - } -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * name: perform_select_event - ****************************************************************************/ - -uint64_t perform_select_event(FAR struct alt1250_s *dev, uint64_t bitmap) -{ - uint64_t bit = 0ULL; - - if (alt1250_checkcmdid(LTE_CMDID_SELECT, bitmap, &bit)) - { - FAR struct alt_container_s *selectcontainer - = recv_selectcontainer(dev); - - /* container->outparam[0]: return code - * container->outparam[1]: error code - * container->outparam[2]: select id - * container->outparam[3]: readset - * container->outparam[4]: writeset - * container->outparam[5]: exceptset - */ - - handle_selectevt(dev, - *((FAR int32_t *)selectcontainer->outparam[0]), - *((FAR int32_t *)selectcontainer->outparam[1]), - *((FAR int32_t *)selectcontainer->outparam[2]), - (FAR altcom_fd_set *)(selectcontainer->outparam[3]), - (FAR altcom_fd_set *)(selectcontainer->outparam[4]), - (FAR altcom_fd_set *)(selectcontainer->outparam[5])); - } - - return bit; -} - -/**************************************************************************** - * name: init_selectcontainer - ****************************************************************************/ - -void init_selectcontainer(FAR struct alt1250_s *dev) -{ - int i; - - memset(select_container_obj, 0, sizeof(select_container_obj)); - - for (i = 0; i < SELECT_CONTAINER_MAX; i++) - { - g_selectargs[i][0] = &g_select_params[i].ret; - g_selectargs[i][1] = &g_select_params[i].err; - g_selectargs[i][2] = &g_select_params[i].id; - g_selectargs[i][3] = &g_select_params[i].readset; - g_selectargs[i][4] = &g_select_params[i].writeset; - g_selectargs[i][5] = &g_select_params[i].exceptset; - - select_container_obj[i].outparam = g_selectargs[i]; - select_container_obj[i].outparamlen = nitems(g_selectargs[i]); - } - - altdevice_exchange_selcontainer(dev->altfd, &select_container_obj[0]); - g_current_container = &select_container_obj[1]; -} - -/**************************************************************************** - * name: restart_select - ****************************************************************************/ - -void restart_select(FAR struct alt1250_s *dev) -{ - select_cancel(dev); - select_start(dev); -} diff --git a/lte/alt1250/alt1250_select.h b/lte/alt1250/alt1250_select.h deleted file mode 100644 index c38625534..000000000 --- a/lte/alt1250/alt1250_select.h +++ /dev/null @@ -1,42 +0,0 @@ -/**************************************************************************** - * apps/lte/alt1250/alt1250_select.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __APPS_LTE_ALT1250_ALT1250_SELECT_H -#define __APPS_LTE_ALT1250_ALT1250_SELECT_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include "alt1250_daemon.h" - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -void init_selectcontainer(FAR struct alt1250_s *dev); -uint64_t perform_select_event(FAR struct alt1250_s *dev, uint64_t bitmap); -void restart_select(FAR struct alt1250_s *dev); - -#endif /* __APPS_LTE_ALT1250_ALT1250_SELECT_H */ diff --git a/lte/alt1250/alt1250_socket.c b/lte/alt1250/alt1250_socket.c deleted file mode 100644 index d6eccf710..000000000 --- a/lte/alt1250/alt1250_socket.c +++ /dev/null @@ -1,197 +0,0 @@ -/**************************************************************************** - * apps/lte/alt1250/alt1250_socket.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include -#include - -#include "alt1250_dbg.h" -#include "alt1250_daemon.h" -#include "alt1250_usockif.h" -#include "alt1250_socket.h" -#include "alt1250_select.h" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * name: usocket_search - ****************************************************************************/ - -FAR struct usock_s *usocket_search(FAR struct alt1250_s *dev, int usockid) -{ - FAR struct usock_s *ret = NULL; - - dbg_alt1250("%s usockid: %d\n", __func__, usockid); - - if (usockid >= 0 && usockid < nitems(dev->sockets)) - { - ret = &dev->sockets[usockid]; - } - - return ret; -} - -/**************************************************************************** - * name: usocket_alloc - ****************************************************************************/ - -FAR struct usock_s *usocket_alloc(FAR struct alt1250_s *dev, int16_t type) -{ - int i; - int base; - int array_num; - FAR struct usock_s *sock; - - switch (type) - { - case SOCK_CTRL: - case SOCK_SMS: - base = SOCKET_COUNT; - array_num = CONFIG_LTE_ALT1250_CONTROL_SOCKETS; - break; - - default: - base = 0; - array_num = SOCKET_COUNT; - break; - } - - sock = &dev->sockets[base]; - - for (i = base; i < base + array_num; i++, sock++) - { - if (sock->state == SOCKET_STATE_CLOSED) - { - sock->usockid = i; - sock->altsockid = -1; - sock->state = SOCKET_STATE_PREALLOC; - sock->select_condition = SELECT_WRITABLE | SELECT_READABLE; - dbg_alt1250("allocated usockid: %d, type: %d\n", i, type); - return sock; - } - } - - return NULL; -} - -/**************************************************************************** - * name: usocket_free - ****************************************************************************/ - -void usocket_free(FAR struct usock_s *sock) -{ - sock->state = SOCKET_STATE_CLOSED; -} - -/**************************************************************************** - * name: usocket_freeall - ****************************************************************************/ - -void usocket_freeall(FAR struct alt1250_s *dev) -{ - int i; - FAR struct usock_s *sock; - - for (i = 0; i < nitems(dev->sockets); i++) - { - sock = &dev->sockets[i]; - usocket_free(sock); - } -} - -/**************************************************************************** - * name: usocket_commitstate - ****************************************************************************/ - -void usocket_commitstate(FAR struct alt1250_s *dev) -{ - restart_select(dev); -} - -/**************************************************************************** - * name: usocket_smssock_num - ****************************************************************************/ - -int usocket_smssock_num(FAR struct alt1250_s *dev) -{ - int i; - int num = 0; - FAR struct usock_s *sock; - - for (i = 0; i < nitems(dev->sockets); i++) - { - sock = &dev->sockets[i]; - if (IS_SMS_SOCKET(sock) && sock->state == SOCKET_STATE_PREALLOC) - { - num++; - } - } - - return num; -} - -/**************************************************************************** - * name: usocket_smssock_readready - ****************************************************************************/ - -void usocket_smssock_readready(FAR struct alt1250_s *dev) -{ - int i; - FAR struct usock_s *sock; - - for (i = 0; i < nitems(dev->sockets); i++) - { - sock = &dev->sockets[i]; - if (IS_SMS_SOCKET(sock) && sock->state == SOCKET_STATE_PREALLOC) - { - usockif_sendrxready(dev->usockfd, USOCKET_USOCKID(sock)); - } - } -} - -/**************************************************************************** - * name: usocket_smssock_abort - ****************************************************************************/ - -void usocket_smssock_abort(FAR struct alt1250_s *dev) -{ - int i; - FAR struct usock_s *sock; - - for (i = 0; i < nitems(dev->sockets); i++) - { - sock = &dev->sockets[i]; - if (IS_SMS_SOCKET(sock) && sock->state == SOCKET_STATE_PREALLOC) - { - usockif_sendabort(dev->usockfd, USOCKET_USOCKID(sock)); - } - } -} diff --git a/lte/alt1250/alt1250_socket.h b/lte/alt1250/alt1250_socket.h deleted file mode 100644 index 77b8286ae..000000000 --- a/lte/alt1250/alt1250_socket.h +++ /dev/null @@ -1,288 +0,0 @@ -/**************************************************************************** - * apps/lte/alt1250/alt1250_socket.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __APPS_LTE_ALT1250_ALT1250_SOCKET_H -#define __APPS_LTE_ALT1250_ALT1250_SOCKET_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include - -#include "alt1250_usockif.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define SELECT_WRITABLE (1 << 1) -#define SELECT_READABLE (1 << 2) -#define SELECTABLE_MASK (SELECT_WRITABLE | SELECT_READABLE) - -#define USOCKET_SET_REQUEST(sock, _reqid, _xid) \ - do \ - { \ - (sock)->request.reqid = (_reqid); \ - (sock)->request.xid = (_xid); \ - } \ - while (0) - -#define USOCKET_SET_SOCKTYPE(sock, _domain, _type, _protocol) \ - do \ - { \ - (sock)->domain = (_domain); \ - (sock)->type = (_type); \ - (sock)->protocol = (_protocol); \ - } \ - while (0) - -#define USOCKET_SET_REQADDRLEN(sock, _addrlen) \ - do \ - { \ - (sock)->sock_req.addrbuflen.addr.addrlen = (_addrlen); \ - } \ - while (0) - -#define USOCKET_SET_REQBACKLOG(sock, _backlog) \ - do \ - { \ - (sock)->sock_req.backlog = (_backlog); \ - } \ - while (0) - -#define USOCKET_SET_REQBUFLEN(sock, _buflen) \ - do \ - { \ - (sock)->sock_req.addrbuflen.buflen = (_buflen); \ - } \ - while (0) - -#define USOCKET_SET_REQSOCKOPT(sock, _level, _opt, _optlen) \ - do \ - { \ - (sock)->sock_req.opt.level = (_level); \ - (sock)->sock_req.opt.option = (_opt); \ - (sock)->sock_req.opt.optlen = (_optlen); \ - } \ - while (0) - -#define USOCKET_REQID(sock) ((sock)->request.reqid) -#define USOCKET_XID(sock) ((sock)->request.xid) -#define USOCKET_DOMAIN(sock) ((sock)->domain) -#define USOCKET_TYPE(sock) ((sock)->type) -#define USOCKET_PROTOCOL(sock) ((sock)->protocol) -#define USOCKET_REQADDRLEN(sock) ((sock)->sock_req.addrbuflen.addr.addrlen) -#define USOCKET_REQADDR(sock) ((sock)->sock_req.addrbuflen.addr.addr) -#define USOCKET_REQBACKLOG(sock) ((sock)->sock_req.backlog) -#define USOCKET_REQBUFLEN(sock) ((sock)->sock_req.addrbuflen.buflen) -#define USOCKET_REQOPTLEVEL(sock) ((sock)->sock_req.opt.level) -#define USOCKET_REQOPTOPT(sock) ((sock)->sock_req.opt.option) -#define USOCKET_REQOPTLEN(sock) ((sock)->sock_req.opt.optlen) -#define USOCKET_REQOPTVAL(sock) ((sock)->sock_req.opt.value) -#define USOCKET_STATE(sock) ((sock)->state) -#define USOCKET_ALTSOCKID(sock) ((sock)->altsockid) -#define USOCKET_USOCKID(sock) ((sock)->usockid) -#define USOCKET_REFID(sock) (&(sock)->refids) - -#define USOCKET_REP_RESPONSE(sock) ((sock)->sock_reply.outparams) -#define USOCKET_REP_RESULT(sock) (&(sock)->sock_reply.rep_result) -#define USOCKET_REP_ERRCODE(sock) (&(sock)->sock_reply.rep_errcode) -#define USOCKET_REP_ADDRLEN(sock) \ - (&(sock)->sock_reply.sock_reply_opt.addr.addrlen) -#define USOCKET_REP_ADDR(sock) \ - (&(sock)->sock_reply.sock_reply_opt.addr.addr) -#define USOCKET_REP_OPTLEN(sock) \ - (&(sock)->sock_reply.sock_reply_opt.opt.optlen) -#define USOCKET_REP_OPTVAL(sock) \ - (&(sock)->sock_reply.sock_reply_opt.opt.value[0]) - -#define USOCKET_SET_RESPONSE(sock, n, p) \ - do \ - { \ - int iii = (n); \ - if (iii < _OUTPUT_ARG_MAX) \ - { \ - (sock)->sock_reply.outparams[iii] = (p); \ - } \ - else \ - { \ - PANIC(); \ - } \ - } \ - while(0) - -#define USOCKET_SET_ALTSOCKID(sock, id) \ - do \ - { \ - (sock)->altsockid = (id); \ - } \ - while (0) -#define USOCKET_SET_STATE(sock, st) \ - do \ - { \ - (sock)->state = (st); \ - } \ - while (0) -#define USOCKET_SET_SELECTABLE(sock, rw) \ - do \ - { \ - (sock)->select_condition |= (rw); \ - } \ - while (0) -#define USOCKET_CLR_SELECTABLE(sock, rw) \ - do \ - { \ - (sock)->select_condition &= ~(rw); \ - } \ - while (0) - -#define IS_STATE_SELECTABLE(s) (((s)->state != SOCKET_STATE_CLOSED) \ - && ((s)->state != SOCKET_STATE_PREALLOC) \ - && ((s)->state != SOCKET_STATE_ABORTED) \ - && ((s)->state != SOCKET_STATE_CLOSING) \ - && ((s)->state != SOCKET_STATE_OPEN)) - -#define IS_STATE_READABLE(s) ((s)->select_condition & SELECT_READABLE) -#define IS_STATE_WRITABLE(s) ((s)->select_condition & SELECT_WRITABLE) - -#define IS_SMS_SOCKET(s) ((s)->type == SOCK_SMS) - -#define _OUTPUT_ARG_MAX 7 -#define _OPTVAL_LEN_MAX 16 - -#define usocket_smssock_writeready(d, s) \ - (usockif_sendtxready((d)->usockfd, USOCKET_USOCKID(s))) - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -struct alt1250_s; - -enum socket_state_e -{ - SOCKET_STATE_CLOSED = 0, - SOCKET_STATE_PREALLOC, - SOCKET_STATE_OPEN, - SOCKET_STATE_OPENED, - SOCKET_STATE_CONNECTING, - SOCKET_STATE_WAITCONN, - SOCKET_STATE_CONNECTED, - SOCKET_STATE_ABORTED, - SOCKET_STATE_CLOSING -}; - -struct usock_addr_s -{ - uint32_t addrlen; - struct sockaddr_storage addr; -}; - -struct usock_opt_s -{ - uint32_t optlen; - uint8_t value[_OPTVAL_LEN_MAX]; -}; - -struct usock_s -{ - struct usrsock_request_common_s request; - int16_t domain; - int16_t type; - int16_t protocol; - - enum socket_state_e state; - int select_condition; - int altsockid; - int usockid; - - struct sms_refids_s refids; - - union sock_request_param_u - { - struct - { - /* store the input arguments of connect(), - * recvfrom(), bind(), accept(), getsockname() - */ - - struct usock_addr_s addr; - - /* store the input arguments of sendto(), recvfrom() */ - - uint16_t buflen; - } addrbuflen; - - /* store the input arguments of listen() */ - - uint16_t backlog; - - /* store the input arguments of setsockopt(), getsockopt() */ - - struct - { - int16_t level; - int16_t option; - uint16_t optlen; - uint8_t value[_OPTVAL_LEN_MAX]; - } opt; - } sock_req; - - struct sock_reply_param_s - { - FAR void *outparams[_OUTPUT_ARG_MAX]; - - int rep_result; - int rep_errcode; - - union sock_reply_opt_u - { - /* store the output arguments of recvfrom(), - * accept() ,getsockname() - */ - - struct usock_addr_s addr; - - /* store the input arguments of setsockopt(), getsockopt() */ - - struct usock_opt_s opt; - } sock_reply_opt; - } sock_reply; -}; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -FAR struct usock_s *usocket_search(FAR struct alt1250_s *dev, int usockid); -FAR struct usock_s *usocket_alloc(FAR struct alt1250_s *dev, int16_t type); -void usocket_free(FAR struct usock_s *sock); -void usocket_freeall(FAR struct alt1250_s *dev); -void usocket_commitstate(FAR struct alt1250_s *dev); -int usocket_smssock_num(FAR struct alt1250_s *dev); -void usocket_smssock_readready(FAR struct alt1250_s *dev); -void usocket_smssock_abort(FAR struct alt1250_s *dev); - -#endif /* __APPS_LTE_ALT1250_ALT1250_SOCKET_H */ diff --git a/lte/alt1250/alt1250_usockevent.c b/lte/alt1250/alt1250_usockevent.c deleted file mode 100644 index 5bc76555b..000000000 --- a/lte/alt1250/alt1250_usockevent.c +++ /dev/null @@ -1,150 +0,0 @@ -/**************************************************************************** - * apps/lte/alt1250/alt1250_usockevent.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include - -#include "alt1250_dbg.h" -#include "alt1250_usockevent.h" -#include "alt1250_usrsock_hdlr.h" - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static const usrsock_reqhandler_t handlers[USRSOCK_REQUEST__MAX] = -{ - [USRSOCK_REQUEST_SOCKET] = usockreq_socket, - [USRSOCK_REQUEST_CLOSE] = usockreq_close, - [USRSOCK_REQUEST_CONNECT] = usockreq_connect, - [USRSOCK_REQUEST_SENDTO] = usockreq_sendto, - [USRSOCK_REQUEST_RECVFROM] = usockreq_recvfrom, - [USRSOCK_REQUEST_SETSOCKOPT] = usockreq_setsockopt, - [USRSOCK_REQUEST_GETSOCKOPT] = usockreq_getsockopt, - [USRSOCK_REQUEST_GETSOCKNAME] = usockreq_getsockname, - [USRSOCK_REQUEST_GETPEERNAME] = usockreq_getpeername, - [USRSOCK_REQUEST_BIND] = usockreq_bind, - [USRSOCK_REQUEST_LISTEN] = usockreq_listen, - [USRSOCK_REQUEST_ACCEPT] = usockreq_accept, - [USRSOCK_REQUEST_IOCTL] = usockreq_ioctl, - [USRSOCK_REQUEST_SHUTDOWN] = usockreq_shutdown -}; - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * name: usock_reply - ****************************************************************************/ - -int usock_reply(int ufd, int action_code, int32_t result, - uint32_t xid, FAR struct usock_ackinfo_s *ackinfo) -{ - int ret = OK; - - dbg_alt1250("action code: %08x\n", action_code); - - switch (action_code) - { - case REP_SEND_ACK: - case REP_SEND_ACK_WOFREE: - case REP_SEND_INPROG: - case REP_SEND_TERM: - ret = usockif_sendack(ufd, result, xid, - (action_code == REP_SEND_INPROG)); - break; - - case REP_SEND_DACK: - ret = usockif_senddataack(ufd, result, xid, ackinfo); - break; - - case REP_SEND_ACK_TXREADY: - ret = usockif_sendack(ufd, result, xid, false); - usockif_sendevent(ufd, ackinfo->usockid, USRSOCK_EVENT_SENDTO_READY); - break; - - case REP_SEND_DACK_RXREADY: - ret = usockif_senddataack(ufd, result, xid, ackinfo); - usockif_sendevent(ufd, ackinfo->usockid, - USRSOCK_EVENT_RECVFROM_AVAIL); - break; - } - - return ret; -} - -/**************************************************************************** - * name: perform_usockrequest - ****************************************************************************/ - -int perform_usockrequest(FAR struct alt1250_s *dev) -{ - int ret = OK; - int32_t usock_result; - uint32_t usock_xid; - struct usock_ackinfo_s ackinfo; - - if (!IS_USOCKREQ_RECEIVED(dev)) - { - ret = usockif_readrequest(dev->usockfd, &dev->usockreq); - ASSERT(ret >= 0); - if (IS_IOCTLREQ(dev->usockreq)) - { - ret = usockif_readreqioctl(dev->usockfd, &dev->usockreq); - if (ret < 0) - { - /* In unsupported ioctl command case */ - - usock_reply(dev->usockfd, REP_SEND_ACK_WOFREE, ret, - USOCKREQXID(dev->usockreq), NULL); - return OK; - } - } - - dev->is_usockrcvd = true; - } - - if (!IS_REQID_VALID(dev->usockreq)) - { - ret = REP_SEND_ACK; - usock_result = -EINVAL; - usock_xid = USOCKREQXID(dev->usockreq); - } - else - { - ret = handlers[USOCKREQID(dev->usockreq)](dev, &dev->usockreq, - &usock_result, &usock_xid, - &ackinfo); - } - - ASSERT(ret >= 0); - - usock_reply(dev->usockfd, ret, usock_result, usock_xid, &ackinfo); - - return ret; -} diff --git a/lte/alt1250/alt1250_usockevent.h b/lte/alt1250/alt1250_usockevent.h deleted file mode 100644 index 922f0b3a4..000000000 --- a/lte/alt1250/alt1250_usockevent.h +++ /dev/null @@ -1,76 +0,0 @@ -/**************************************************************************** - * apps/lte/alt1250/alt1250_usockevent.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __APPS_LTE_ALT1250_ALT1250_USOCKEVENT_H -#define __APPS_LTE_ALT1250_ALT1250_USOCKEVENT_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include "alt1250_usockif.h" -#include "alt1250_daemon.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define NEED_CONTAINER_FREE (1<<16) -#define W_CONTAINER_FREE(a) ((a) | NEED_CONTAINER_FREE) -#define WO_CONTAINER_FREE(a) (a) - -#define IS_NEED_CONTAINER_FREE(r) ((r) & NEED_CONTAINER_FREE) - -#define REP_SEND_ACK W_CONTAINER_FREE(1) -#define REP_SEND_ACK_WOFREE WO_CONTAINER_FREE(2) -#define REP_SEND_INPROG W_CONTAINER_FREE(3) -#define REP_SEND_DACK W_CONTAINER_FREE(4) -#define REP_SEND_TERM W_CONTAINER_FREE(5) -#define REP_NO_CONTAINER WO_CONTAINER_FREE(6) -#define REP_NO_ACK W_CONTAINER_FREE(7) -#define REP_NO_ACK_WOFREE WO_CONTAINER_FREE(8) -#define REP_MODEM_RESET WO_CONTAINER_FREE(9) -#define REP_SEND_ACK_TXREADY W_CONTAINER_FREE(10) -#define REP_SEND_DACK_RXREADY W_CONTAINER_FREE(11) - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -typedef int (*usrsock_reqhandler_t)(FAR struct alt1250_s *dev, - FAR struct usrsock_request_buff_s *req, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo); - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -int usock_reply(int ufd, int action_code, int32_t result, - uint32_t xid, FAR struct usock_ackinfo_s *ackinfo); - -int perform_usockrequest(FAR struct alt1250_s *dev); - -#endif /* __APPS_LTE_ALT1250_ALT1250_USOCKEVENT_H */ diff --git a/lte/alt1250/alt1250_usockif.c b/lte/alt1250/alt1250_usockif.c deleted file mode 100644 index ec188775c..000000000 --- a/lte/alt1250/alt1250_usockif.c +++ /dev/null @@ -1,398 +0,0 @@ -/**************************************************************************** - * apps/lte/alt1250/alt1250_usockif.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include -#include -#include -#include - -#include "alt1250_dbg.h" -#include "alt1250_usockif.h" - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * name: write_to_usock - ****************************************************************************/ - -static int write_to_usock(int fd, FAR void *buf, size_t sz) -{ - int ret; - - ret = write(fd, buf, sz); - if (ret < 0) - { - ret = -errno; - } - else if (ret != sz) - { - ret = -ENOSPC; - } - else - { - ret = OK; - } - - return ret; -} - -/**************************************************************************** - * name: send_dataack - ****************************************************************************/ - -static int send_dataack(int fd, uint32_t ackxid, int32_t ackresult, - uint16_t valuelen, uint16_t valuelen_nontrunc, - FAR uint8_t *value_ptr, FAR uint8_t *buf_ptr) -{ - int ret; - struct usrsock_message_datareq_ack_s dataack; - - dataack.reqack.head.msgid = USRSOCK_MESSAGE_RESPONSE_DATA_ACK; - dataack.reqack.head.flags = 0; - dataack.reqack.head.events = 0; - dataack.reqack.xid = ackxid; - dataack.reqack.result = ackresult; - - dataack.valuelen = valuelen; - dataack.valuelen_nontrunc = valuelen_nontrunc; - - ret = write_to_usock(fd, &dataack, sizeof(dataack)); - if (ret < 0) - { - return ret; - } - - if ((valuelen > 0) && (value_ptr != NULL)) - { - ret = write_to_usock(fd, value_ptr, valuelen); - if (ret < 0) - { - return ret; - } - } - - if ((ackresult > 0) && (buf_ptr != NULL)) - { - ret = write_to_usock(fd, buf_ptr, ackresult); - if (ret < 0) - { - return ret; - } - } - - return OK; -} - -/**************************************************************************** - * name: read_wrapper - ****************************************************************************/ - -static int read_wrapper(int fd, FAR void *buf, size_t sz) -{ - int ret; - - ret = read(fd, buf, sz); - if (ret < 0) - { - ret = -errno; - dbg_alt1250("failed to read usersock: %d\n", errno); - return ret; - } - - if (ret != sz) - { - dbg_alt1250("unexpected read size: %d expected: %u\n", ret, sz); - return -EMSGSIZE; - } - - return ret; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * name: init_usock_device - ****************************************************************************/ - -int init_usock_device(void) -{ - return open(DEV_USRSOCK, O_RDWR); -} - -/**************************************************************************** - * name: finalize_usock_device - ****************************************************************************/ - -void finalize_usock_device(int fd) -{ - close(fd); -} - -/**************************************************************************** - * name: reset_usock_device - ****************************************************************************/ - -int reset_usock_device(int fd) -{ - close(fd); - return open(DEV_USRSOCK, O_RDWR); -} - -/**************************************************************************** - * name: usockif_readrequest - ****************************************************************************/ - -int usockif_readrequest(int fd, FAR struct usrsock_request_buff_s *buf) -{ - int ret; - int rsize = 0; - FAR char *pbuf = NULL; - - /* Read common header */ - - ret = read_wrapper(fd, buf, sizeof(struct usrsock_request_common_s)); - if (ret < 0) - { - return ret; - } - - /* Read each request */ - - switch (buf->request.head.reqid) - { - case USRSOCK_REQUEST_SOCKET: - rsize = sizeof(struct usrsock_request_socket_s); - break; - case USRSOCK_REQUEST_CLOSE: - rsize = sizeof(struct usrsock_request_close_s); - break; - case USRSOCK_REQUEST_CONNECT: - rsize = sizeof(struct usrsock_request_connect_s); - break; - case USRSOCK_REQUEST_SENDTO: - rsize = sizeof(struct usrsock_request_sendto_s); - break; - case USRSOCK_REQUEST_RECVFROM: - rsize = sizeof(struct usrsock_request_recvfrom_s); - break; - case USRSOCK_REQUEST_SETSOCKOPT: - rsize = sizeof(struct usrsock_request_setsockopt_s); - break; - case USRSOCK_REQUEST_GETSOCKOPT: - rsize = sizeof(struct usrsock_request_getsockopt_s); - break; - case USRSOCK_REQUEST_GETSOCKNAME: - rsize = sizeof(struct usrsock_request_getsockname_s); - break; - case USRSOCK_REQUEST_GETPEERNAME: - rsize = sizeof(struct usrsock_request_getpeername_s); - break; - case USRSOCK_REQUEST_BIND: - rsize = sizeof(struct usrsock_request_bind_s); - break; - case USRSOCK_REQUEST_LISTEN: - rsize = sizeof(struct usrsock_request_listen_s); - break; - case USRSOCK_REQUEST_ACCEPT: - rsize = sizeof(struct usrsock_request_accept_s); - break; - case USRSOCK_REQUEST_IOCTL: - rsize = sizeof(struct usrsock_request_ioctl_s); - break; - case USRSOCK_REQUEST_SHUTDOWN: - rsize = sizeof(struct usrsock_request_shutdown_s); - break; - default: - dbg_alt1250("unexpected request id: %d\n", buf->request.head.reqid); - return -EINVAL; - break; - } - - pbuf = (FAR char *)buf + sizeof(struct usrsock_request_common_s); - rsize -= sizeof(struct usrsock_request_common_s); - - ret = read_wrapper(fd, pbuf, rsize); - if (ret < 0) - { - return ret; - } - - return sizeof(struct usrsock_request_common_s) + ret; -} - -/**************************************************************************** - * name: usockif_readreqioctl - ****************************************************************************/ - -int usockif_readreqioctl(int fd, FAR struct usrsock_request_buff_s *buf) -{ - FAR struct usrsock_request_ioctl_s *req = &buf->request.ioctl_req; - FAR void *pbuf = &buf->req_ioctl; - int rsize; - - switch (req->cmd) - { - case FIONBIO: - rsize = sizeof(int); - break; - case SIOCLTECMD: - rsize = sizeof(struct lte_ioctl_data_s); - break; - case SIOCSIFFLAGS: - case SIOCGIFFLAGS: - rsize = sizeof(struct ifreq); - break; - case SIOCDENYINETSOCK: - rsize = sizeof(uint8_t); - break; - case SIOCSMSENSTREP: - case SIOCSMSGREFID: - case SIOCSMSSSCA: - rsize = sizeof(struct lte_smsreq_s); - break; - default: - dbg_alt1250("Unsupported command:0x%08lx\n", req->cmd); - return -ENOTTY; - break; - } - - if (req->arglen != rsize) - { - dbg_alt1250("unexpected size: %d, expect: %d\n", req->arglen, rsize); - ASSERT(0); - return -EINVAL; - } - - return read_wrapper(fd, pbuf, rsize); -} - -/**************************************************************************** - * name: usockif_readreqaddr - ****************************************************************************/ - -int usockif_readreqaddr(int fd, FAR struct sockaddr_storage *addr, - size_t sz) -{ - if ((sz != sizeof(struct sockaddr_in)) && - (sz != sizeof(struct sockaddr_in6))) - { - dbg_alt1250("Invalid addrlen: %u\n", sz); - return -EINVAL; - } - - return read_wrapper(fd, addr, sz); -} - -/**************************************************************************** - * name: usockif_readreqsendbuf - ****************************************************************************/ - -int usockif_readreqsendbuf(int fd, FAR uint8_t *sendbuf, size_t sz) -{ - return read_wrapper(fd, sendbuf, sz); -} - -/**************************************************************************** - * name: usockif_readreqoption - ****************************************************************************/ - -int usockif_readreqoption(int fd, FAR uint8_t *option, size_t sz) -{ - return read_wrapper(fd, option, sz); -} - -/**************************************************************************** - * name: usockif_discard - ****************************************************************************/ - -void usockif_discard(int fd, size_t sz) -{ - char dummy; - - /* If the seek is called with the exact size, the seek will - * result in an error. In order to avoid this, the process of - * read is performed after seeking the specified size minus one byte. - */ - - if (lseek(fd, sz - 1, SEEK_CUR) >= 0) - { - read(fd, &dummy, 1); - } -} - -/**************************************************************************** - * name: usockif_sendack - ****************************************************************************/ - -int usockif_sendack(int fd, int32_t usock_result, uint32_t usock_xid, - bool inprogress) -{ - struct usrsock_message_req_ack_s ack; - - ack.head.msgid = USRSOCK_MESSAGE_RESPONSE_ACK; - ack.head.flags = inprogress ? USRSOCK_MESSAGE_FLAG_REQ_IN_PROGRESS : 0; - ack.head.events = 0; - ack.xid = usock_xid; - ack.result = usock_result; - - return write_to_usock(fd, &ack, sizeof(ack)); -} - -/**************************************************************************** - * name: usockif_senddataack - ****************************************************************************/ - -int usockif_senddataack(int fd, int32_t usock_result, uint32_t usock_xid, - FAR struct usock_ackinfo_s *ackinfo) -{ - return send_dataack(fd, usock_xid, usock_result, ackinfo->valuelen, - ackinfo->valuelen_nontrunc, ackinfo->value_ptr, - ackinfo->buf_ptr); -} - -/**************************************************************************** - * name: usockif_sendevent - ****************************************************************************/ - -int usockif_sendevent(int fd, int usockid, int event) -{ - struct usrsock_message_socket_event_s msg; - - msg.head.msgid = USRSOCK_MESSAGE_SOCKET_EVENT; - msg.head.flags = USRSOCK_MESSAGE_FLAG_EVENT; - msg.usockid = usockid; - msg.head.events = event; - - return write_to_usock(fd, &msg, sizeof(msg)); -} diff --git a/lte/alt1250/alt1250_usockif.h b/lte/alt1250/alt1250_usockif.h deleted file mode 100644 index 2ffcc02e4..000000000 --- a/lte/alt1250/alt1250_usockif.h +++ /dev/null @@ -1,131 +0,0 @@ -/**************************************************************************** - * apps/lte/alt1250/alt1250_usockif.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __APPS_LTE_ALT1250_ALT1250_USOCKIF_H -#define __APPS_LTE_ALT1250_ALT1250_USOCKIF_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -#include -#include - -#include - -#define DEV_USRSOCK "/dev/usrsock" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define IS_IOCTLREQ(r) ((r).request.head.reqid == USRSOCK_REQUEST_IOCTL) -#define IS_REQID_VALID(r) ((r).request.head.reqid < USRSOCK_REQUEST__MAX) -#define USOCKREQID(r) ((r).request.head.reqid) -#define USOCKREQXID(r) ((r).request.head.xid) - -#define usockif_sendclose(fff, iii) \ - usockif_sendevent((fff), (iii), USRSOCK_EVENT_REMOTE_CLOSED) - -#define usockif_sendabort(fff, iii) \ - usockif_sendevent((fff), (iii), USRSOCK_EVENT_ABORT) - -#define usockif_sendtxready(fff, iii) \ - usockif_sendevent((fff), (iii), USRSOCK_EVENT_SENDTO_READY) - -#define usockif_sendrxready(fff, iii) \ - usockif_sendevent((fff), (iii), USRSOCK_EVENT_RECVFROM_AVAIL) - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -union usrsock_requests_u -{ - struct usrsock_request_common_s head; - - struct usrsock_request_socket_s sock_req; - struct usrsock_request_close_s close_req; - struct usrsock_request_bind_s bind_req; - struct usrsock_request_connect_s conn_req; - struct usrsock_request_listen_s listen_req; - struct usrsock_request_accept_s accept_req; - struct usrsock_request_sendto_s send_req; - struct usrsock_request_recvfrom_s recv_req; - struct usrsock_request_setsockopt_s sopt_req; - struct usrsock_request_getsockopt_s gopt_req; - struct usrsock_request_getsockname_s name_req; - struct usrsock_request_getpeername_s pname_req; - struct usrsock_request_ioctl_s ioctl_req; - struct usrsock_request_shutdown_s shutdown_req; -}; -#define USOCK_HDR_SIZE sizeof(struct usrsock_request_common_s) - -union usrsock_request_ioctl_u -{ - struct lte_ioctl_data_s ltecmd; - struct ifreq ifreq; - uint8_t sock_type; - struct lte_smsreq_s smsreq; -}; - -struct usrsock_request_buff_s -{ - union usrsock_requests_u request; - union usrsock_request_ioctl_u req_ioctl; -}; - -struct usock_ackinfo_s -{ - uint16_t valuelen; - uint16_t valuelen_nontrunc; - FAR uint8_t *value_ptr; - FAR uint8_t *buf_ptr; - int usockid; -}; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -int init_usock_device(void); -void finalize_usock_device(int fd); -int reset_usock_device(int fd); - -int usockif_readrequest(int fd, FAR struct usrsock_request_buff_s *buf); -int usockif_readreqioctl(int fd, FAR struct usrsock_request_buff_s *buf); -int usockif_readreqaddr(int fd, FAR struct sockaddr_storage *addr, - size_t sz); -int usockif_readreqsendbuf(int fd, FAR uint8_t *sendbuf, size_t sz); -int usockif_readreqoption(int fd, FAR uint8_t *option, size_t sz); - -void usockif_discard(int fd, size_t sz); -int usockif_sendack(int fd, int32_t usock_result, uint32_t usock_xid, - bool inprogress); -int usockif_senddataack(int fd, int32_t usock_result, uint32_t usock_xid, - FAR struct usock_ackinfo_s *ackinfo); -int usockif_sendevent(int fd, int usockid, int event); - -#endif /* __APPS_LTE_ALT1250_ALT1250_USOCKIF_H */ diff --git a/lte/alt1250/alt1250_util.c b/lte/alt1250/alt1250_util.c deleted file mode 100644 index 75fc00a3d..000000000 --- a/lte/alt1250/alt1250_util.c +++ /dev/null @@ -1,71 +0,0 @@ -/**************************************************************************** - * apps/lte/alt1250/alt1250_util.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include - -#include "alt1250_daemon.h" -#include "alt1250_util.h" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: alt1250_saveapn - ****************************************************************************/ - -void alt1250_saveapn(FAR struct alt1250_s *dev, FAR lte_apn_setting_t *apn) -{ - memcpy(&dev->apn, apn, sizeof(lte_apn_setting_t)); - strncpy(dev->apn_name, (FAR const char *)apn->apn, LTE_APN_LEN); - if ((apn->auth_type != LTE_APN_AUTHTYPE_NONE) && (apn->user_name)) - { - strncpy(dev->user_name, (FAR const char *)apn->user_name, - LTE_APN_USER_NAME_LEN); - } - - if ((apn->auth_type != LTE_APN_AUTHTYPE_NONE) && (apn->password)) - { - strncpy(dev->pass, (FAR const char *)apn->password, - LTE_APN_PASSWD_LEN); - } - - dev->apn.apn = dev->apn_name; - dev->apn.user_name = dev->user_name; - dev->apn.password = dev->pass; -} - -/**************************************************************************** - * Name: alt1250_getapn - ****************************************************************************/ - -void alt1250_getapn(FAR struct alt1250_s *dev, FAR lte_apn_setting_t *apn) -{ - memcpy(apn, &dev->apn, sizeof(lte_apn_setting_t)); -} diff --git a/lte/alt1250/alt1250_util.h b/lte/alt1250/alt1250_util.h deleted file mode 100644 index ac60e05aa..000000000 --- a/lte/alt1250/alt1250_util.h +++ /dev/null @@ -1,45 +0,0 @@ -/**************************************************************************** - * apps/lte/alt1250/alt1250_util.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __APPS_LTE_ALT1250_ALT1250_UTIL_H -#define __APPS_LTE_ALT1250_ALT1250_UTIL_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include "alt1250_daemon.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -void alt1250_saveapn(FAR struct alt1250_s *dev, FAR lte_apn_setting_t *apn); -void alt1250_getapn(FAR struct alt1250_s *dev, FAR lte_apn_setting_t *apn); - -#endif /* __APPS_LTE_ALT1250_ALT1250_UTIL_H */ diff --git a/lte/alt1250/callback_handlers/alt1250_evt.c b/lte/alt1250/callback_handlers/alt1250_evt.c deleted file mode 100644 index 59cfe0bed..000000000 --- a/lte/alt1250/callback_handlers/alt1250_evt.c +++ /dev/null @@ -1,2198 +0,0 @@ -/**************************************************************************** - * apps/lte/alt1250/callback_handlers/alt1250_evt.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include "alt1250_dbg.h" -#include "lte/lapi.h" -#include "lte/lte_api.h" - -#include "alt1250_evt.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define TABLE_CONTENT(cid, acid, outp) \ - { .cmdid = LTE_CMDID_##cid, .altcid = APICMDID_##acid, \ - .outparam = outp, .outparamlen = nitems(outp) } - -#define TABLE_CONTENT_NOARG(cid, acid) \ - { .cmdid = LTE_CMDID_##cid, .altcid = APICMDID_##acid, \ - .outparam = NULL, .outparamlen = 0 } - -#define NCBTABLES (8 + ALTCOM_NSOCKET) /* 8 is the maximum number of events */ - -#define IS_REPORT_API(cmdid) \ - ( LTE_ISCMDGRP_EVENT(cmdid) || cmdid == LTE_CMDID_SETRESTART ) - -#define EVTTASK_NAME "lteevt_task" -#define LAPIEVT_QNAME "/lapievt" - -#define clr_evtcb(info) reg_evtcb(info, 0, NULL) -#define search_free_evtcb() search_evtcb(0) - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -static uint64_t lte_set_report_restart_exec_cb(FAR void *cb, - FAR void **cbarg, - FAR bool *set_writable); -#ifdef CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API -static uint64_t lte_radio_on_exec_cb(FAR void *cb, FAR void **cbarg, - FAR bool *set_writable); -static uint64_t lte_radio_off_exec_cb(FAR void *cb, FAR void **cbarg, - FAR bool *set_writable); -#endif /* CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API */ -static uint64_t lte_activate_pdn_exec_cb(FAR void *cb, FAR void **cbarg, - FAR bool *set_writable); -#ifdef CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API -static uint64_t lte_deactivate_pdn_exec_cb(FAR void *cb, FAR void **cbarg, - FAR bool *set_writable); -static uint64_t lte_get_netinfo_exec_cb(FAR void *cb, FAR void **cbarg, - FAR bool *set_writable); -static uint64_t lte_get_imscap_exec_cb(FAR void *cb, FAR void **cbarg, - FAR bool *set_writable); -static uint64_t lte_get_version_exec_cb(FAR void *cb, FAR void **cbarg, - FAR bool *set_writable); -static uint64_t lte_get_phoneno_exec_cb(FAR void *cb, FAR void **cbarg, - FAR bool *set_writable); -static uint64_t lte_get_imsi_exec_cb(FAR void *cb, FAR void **cbarg, - FAR bool *set_writable); -static uint64_t lte_get_imei_exec_cb(FAR void *cb, FAR void **cbarg, - FAR bool *set_writable); -static uint64_t lte_get_pinset_exec_cb(FAR void *cb, FAR void **cbarg, - FAR bool *set_writable); -static uint64_t lte_set_pinenable_exec_cb(FAR void *cb, FAR void **cbarg, - FAR bool *set_writable); -static uint64_t lte_change_pin_exec_cb(FAR void *cb, FAR void **cbarg, - FAR bool *set_writable); -static uint64_t lte_enter_pin_exec_cb(FAR void *cb, FAR void **cbarg, - FAR bool *set_writable); -static uint64_t lte_get_localtime_exec_cb(FAR void *cb, FAR void **cbarg, - FAR bool *set_writable); -static uint64_t lte_get_operator_exec_cb(FAR void *cb, FAR void **cbarg, - FAR bool *set_writable); -static uint64_t lte_get_edrx_exec_cb(FAR void *cb, FAR void **cbarg, - FAR bool *set_writable); -static uint64_t lte_set_edrx_exec_cb(FAR void *cb, FAR void **cbarg, - FAR bool *set_writable); -static uint64_t lte_get_psm_exec_cb(FAR void *cb, FAR void **cbarg, - FAR bool *set_writable); -static uint64_t lte_set_psm_exec_cb(FAR void *cb, FAR void **cbarg, - FAR bool *set_writable); -static uint64_t lte_get_ce_exec_cb(FAR void *cb, FAR void **cbarg, - FAR bool *set_writable); -static uint64_t lte_set_ce_exec_cb(FAR void *cb, FAR void **cbarg, - FAR bool *set_writable); -static uint64_t lte_get_siminfo_exec_cb(FAR void *cb, FAR void **cbarg, - FAR bool *set_writable); -static uint64_t lte_get_current_edrx_exec_cb(FAR void *cb, FAR void **cbarg, - FAR bool *set_writable); -static uint64_t lte_get_current_psm_exec_cb(FAR void *cb, FAR void **cbarg, - FAR bool *set_writable); -static uint64_t lte_get_quality_exec_cb(FAR void *cb, FAR void **cbarg, - FAR bool *set_writable); -#endif /* CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API */ -static uint64_t lte_set_report_netinfo_exec_cb(FAR void *cb, - FAR void **cbarg, - FAR bool *set_writable); -static uint64_t lte_set_report_simstat_exec_cb(FAR void *cb, - FAR void **cbarg, - FAR bool *set_writable); -static uint64_t lte_set_report_localtime_exec_cb(FAR void *cb, - FAR void **cbarg, - FAR bool *set_writable); -static uint64_t lte_set_report_quality_exec_cb(FAR void *cb, - FAR void **cbarg, - FAR bool *set_writable); -static uint64_t lte_set_report_cellinfo_exec_cb(FAR void *cb, - FAR void **cbarg, - FAR bool *set_writable); -static uint64_t tls_config_verify_exec_cb(FAR void *cb, FAR void **cbarg, - FAR bool *set_writable); - -static uint64_t lwm2m_read_evt_cb(FAR void *cb, FAR void **cbarg, - FAR bool *set_writable); -static uint64_t lwm2m_write_evt_cb(FAR void *cb, FAR void **cbarg, - FAR bool *set_writable); -static uint64_t lwm2m_exec_evt_cb(FAR void *cb, FAR void **cbarg, - FAR bool *set_writable); -static uint64_t lwm2m_ovstart_evt_cb(FAR void *cb, FAR void **cbarg, - FAR bool *set_writable); -static uint64_t lwm2m_ovstop_evt_cb(FAR void *cb, FAR void **cbarg, - FAR bool *set_writable); -static uint64_t lwm2m_operation_evt_cb(FAR void *cb, FAR void **cbarg, - FAR bool *set_writable); -static uint64_t lwm2m_fwupdate_evt_cb(FAR void *cb, FAR void **cbarg, - FAR bool *set_writable); - -static FAR void *get_cbfunc(uint32_t cmdid); -static uint64_t alt1250_evt_search(uint32_t cmdid); - -/**************************************************************************** - * Private Data Types - ****************************************************************************/ - -struct cbinfo_s -{ - uint32_t cmdid; - CODE uint64_t (*cb)(FAR void *cb, FAR void **cbarg, - FAR bool *set_writable); -}; - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -#ifdef CONFIG_LTE_ALT1250_LAUNCH_EVENT_TASK -static int g_cbpid; -#endif - -/* event argument for LTE_CMDID_SETRESTART */ - -static uint32_t g_reason; -static void *g_setrestartargs[] = -{ - &g_reason -}; - -/* event argument for LTE_CMDID_GETVER */ - -static int g_getverret; -static lte_version_t g_ver; -static FAR void *g_getverargs[] = -{ - &g_getverret, &g_ver -}; - -#ifdef CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API - -/* event argument for LTE_CMDID_RADIOON */ - -static int g_radioonret; -static FAR void *g_radioonargs[] = -{ - &g_radioonret -}; - -/* event argument for LTE_CMDID_RADIOOFF */ - -static int g_radiooffret; -static FAR void *g_radiooffargs[] = -{ - &g_radiooffret -}; - -#endif /* CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API */ - -/* event argument for LTE_CMDID_ACTPDN */ - -static int g_actpdnret; -static lte_pdn_t g_pdn; -static FAR void *g_actpdnargs[] = -{ - &g_actpdnret, &g_pdn -}; - -#ifdef CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API - -/* event argument for LTE_CMDID_DEACTPDN */ - -static int g_deactpdnret; -static FAR void *g_deactpdnargs[] = -{ - &g_deactpdnret -}; - -/* event argument for LTE_CMDID_GETNETINFO */ - -static int g_getnetinforet; -static lte_pdn_t g_pdninfo[LTE_SESSION_ID_MAX]; -static lte_netinfo_t g_netinfo = -{ - .pdn_stat = g_pdninfo -}; - -static uint8_t g_pdn_num = LTE_SESSION_ID_MAX; -static FAR void *g_netinfoargs[] = -{ - &g_getnetinforet, &g_netinfo, &g_pdn_num -}; - -/* event argument for LTE_CMDID_IMSCAP */ - -static int g_imscapret; -static bool g_imscap; -static FAR void *g_imscapargs[] = -{ - &g_imscapret, &g_imscap -}; - -/* event argument for LTE_CMDID_GETPHONE */ - -static int g_getphoneret; -static uint8_t g_getphoneerrcause; -static char g_phoneno[LTE_PHONENO_LEN]; -#ifndef CONFIG_LTE_LAPI_KEEP_COMPATIBILITY -static size_t g_phonenolen = LTE_PHONENO_LEN; -#endif -static FAR void *g_getphoneargs[] = -{ -#ifdef CONFIG_LTE_LAPI_KEEP_COMPATIBILITY - &g_getphoneret, &g_getphoneerrcause, g_phoneno -#else - &g_getphoneret, &g_getphoneerrcause, g_phoneno, &g_phonenolen -#endif -}; - -/* event argument for LTE_CMDID_GETIMSI */ - -static int g_getimsiret; -static uint8_t g_getimsierrcause; -static char g_imsi[LTE_SIMINFO_IMSI_LEN]; -#ifndef CONFIG_LTE_LAPI_KEEP_COMPATIBILITY -static size_t g_imsilen = LTE_SIMINFO_IMSI_LEN; -#endif -static FAR void *g_getimsiargs[] = -{ -#ifdef CONFIG_LTE_LAPI_KEEP_COMPATIBILITY - &g_getimsiret, &g_getimsierrcause, g_imsi -#else - &g_getimsiret, &g_getimsierrcause, g_imsi, &g_imsilen -#endif -}; - -/* event argument for LTE_CMDID_GETIMEI */ - -static int g_getimeiret; -static char g_imei[LTE_IMEI_LEN]; -#ifndef CONFIG_LTE_LAPI_KEEP_COMPATIBILITY -static size_t g_imeilen = LTE_IMEI_LEN; -#endif -static FAR void *g_getimeiargs[] = -{ -#ifdef CONFIG_LTE_LAPI_KEEP_COMPATIBILITY - &g_getimeiret, g_imei -#else - &g_getimeiret, g_imei, &g_imeilen -#endif -}; - -/* event argument for LTE_CMDID_GETPINSET */ - -static int g_getpinsetret; -static lte_getpin_t g_pinset; -static FAR void *g_getpinsetargs[] = -{ - &g_getpinsetret, &g_pinset -}; - -/* event argument for LTE_CMDID_PINENABLE */ - -static int g_pinenableret; -static uint8_t g_pineattleft; -static FAR void *g_pinenableargs[] = -{ - &g_pinenableret, &g_pineattleft -}; - -/* event argument for LTE_CMDID_CHANGEPIN */ - -static int g_changepinret; -static uint8_t g_chanattleft; -static FAR void *g_changepinargs[] = -{ - &g_changepinret, &g_chanattleft -}; - -/* event argument for LTE_CMDID_ENTERPIN */ - -static int g_enterpinret; -static uint8_t g_entpinsimstat; -static uint8_t g_entpinattleft; -static FAR void *g_enterpinargs[] = -{ - &g_enterpinret, &g_entpinsimstat, &g_entpinattleft -}; - -/* event argument for LTE_CMDID_GETLTIME */ - -static int g_getltimeret; -static lte_localtime_t g_ltime; -static FAR void *g_getltimeargs[] = -{ - &g_getltimeret, &g_ltime -}; - -/* event argument for LTE_CMDID_GETOPER */ - -static int g_getoperret; -static char g_oper[LTE_OPERATOR_LEN]; -#ifndef CONFIG_LTE_LAPI_KEEP_COMPATIBILITY -static size_t g_operlen = LTE_OPERATOR_LEN; -#endif -static FAR void *g_getoperargs[] = -{ -#ifdef CONFIG_LTE_LAPI_KEEP_COMPATIBILITY - &g_getoperret, g_oper -#else - &g_getoperret, g_oper, &g_operlen -#endif -}; - -/* event argument for LTE_CMDID_GETEDRX */ - -static int g_getedrxret; -static lte_edrx_setting_t g_getedrx; -static bool g_is_getedrxevt; -static FAR void *g_getedrxargs[] = -{ - &g_getedrxret, &g_getedrx, &g_is_getedrxevt -}; - -/* event argument for LTE_CMDID_SETEDRX */ - -static int g_setedrxret; -static FAR void *g_setedrxargs[] = -{ - &g_setedrxret -}; - -/* event argument for LTE_CMDID_GETPSM */ - -static int g_getpsmret; -static lte_psm_setting_t g_getpsm; -static bool g_is_getpsmevt; -static FAR void *g_getpsmargs[] = -{ - &g_getpsmret, &g_getpsm, &g_is_getpsmevt -}; - -/* event argument for LTE_CMDID_SETPSM */ - -static int g_setpsmret; -static FAR void *g_setpsmargs[] = -{ - &g_setpsmret -}; - -/* event argument for LTE_CMDID_GETCE */ - -static int g_getceret; -static lte_ce_setting_t g_getce; -static FAR void *g_getceargs[] = -{ - &g_getceret, &g_getce -}; - -/* event argument for LTE_CMDID_SETCE */ - -static int g_setceret; -static FAR void *g_setceargs[] = -{ - &g_setceret -}; - -/* event argument for LTE_CMDID_GETSIMINFO */ - -static int g_setsiminforet; -static lte_siminfo_t g_siminfo; -static FAR void *g_getsiminfoargs[] = -{ - &g_setsiminforet, &g_siminfo -}; - -/* event argument for LTE_CMDID_GETCEDRX */ - -static int g_getcedrxret; -static lte_edrx_setting_t g_getcedrx; -static bool g_is_getcedrxevt; -static FAR void *g_getcedrxargs[] = -{ - &g_getcedrxret, &g_getcedrx, &g_is_getcedrxevt -}; - -/* event argument for LTE_CMDID_GETCPSM */ - -static int g_getcpsmret; -static lte_psm_setting_t g_getcpsm; -static bool g_is_getcpsmevt; -static FAR void *g_getcpsmargs[] = -{ - &g_getcpsmret, &g_getcpsm, &g_is_getcpsmevt -}; - -/* event argument for LTE_CMDID_GETQUAL */ - -static int g_getqualret; -static lte_quality_t g_getqual; -static FAR void *g_getqualargs[] = -{ - &g_getqualret, &g_getqual -}; - -/* event argument for LTE_CMDID_GETCELL */ - -static int g_getcellret; -static lte_neighbor_cell_t g_neighbors[LTE_NEIGHBOR_CELL_MAX]; -static lte_cellinfo_t g_getcell = -{ - .neighbors = g_neighbors -} -; -static FAR void *g_getcellargs[] = -{ - &g_getcellret, &g_getcell -}; - -#endif /* CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API */ - -/* event argument for LTE_CMDID_GETRAT */ - -static int g_getratret; -static FAR void *g_getratargs[] = -{ - &g_getratret -}; - -/* event argument for LTE_CMDID_SETRAT */ - -static int g_setratret; -static FAR void *g_setratargs[] = -{ - &g_setratret -}; - -/* event argument for LTE_CMDID_GETRATINFO */ - -static int g_getratinforet; -static lte_ratinfo_t g_ratinfo; -static FAR void *g_getratinfoargs[] = -{ - &g_getratinforet, &g_ratinfo -}; - -/* event argument for LTE_CMDID_REPNETINFO */ - -static lte_pdn_t g_reppdninfo[LTE_SESSION_ID_MAX]; -static lte_netinfo_t g_repnetinfo = -{ - .pdn_stat = g_reppdninfo -}; - -static uint8_t g_ndnsaddrs; -static struct sockaddr_storage g_dnsaddrs[ALTCOM_DNS_SERVERS]; -static FAR void *g_repnetinfoargs[] = -{ - &g_repnetinfo, &g_ndnsaddrs, g_dnsaddrs -}; - -/* event argument for LTE_CMDID_REPSIMSTAT */ - -static uint32_t g_repsimstat; -static FAR void *g_repsimstatargs[] = -{ - &g_repsimstat -}; - -/* event argument for LTE_CMDID_REPLTIME */ - -static lte_localtime_t g_repltime; -static FAR void *g_repltimeargs[] = -{ - &g_repltime -}; - -/* event argument for LTE_CMDID_REPQUAL */ - -static lte_quality_t g_repqual; -static FAR void *g_repqualargs[] = -{ - &g_repqual -}; - -/* event argument for LTE_CMDID_REPCELL */ - -static lte_neighbor_cell_t g_repneighbors[LTE_NEIGHBOR_CELL_MAX]; -static lte_cellinfo_t g_repcell = -{ - .neighbors = g_repneighbors -}; - -static FAR void *g_repcellargs[] = -{ - &g_repcell -}; - -/* event argument for LTE_CMDID_GETERRINFO */ - -static lte_errinfo_t g_geterrinfo; -static FAR void *g_geterrinfoargs[] = -{ - &g_geterrinfo -}; - -/* event argument for LTE_CMDID_TLS_CONFIG_VERIFY_CALLBACK */ - -static uint32_t g_crt; -static int32_t g_depth; -static FAR void *g_vrfycbargs[] = -{ - &g_crt, &g_depth -}; - -/* event argument for LTE_CMDID_SMS_REPORT_RECV */ - -static uint16_t g_smsmsg_index; -static uint16_t g_smsrecv_sz; -static uint8_t g_sms_maxnum; -static uint8_t g_sms_seqnum; -static struct sms_deliver_msg_max_s g_recvmsg; -static FAR void *g_smsreportargs[] = -{ - &g_smsmsg_index, &g_smsrecv_sz, &g_sms_maxnum, &g_sms_seqnum, &g_recvmsg -}; - -/* event argument for LTE_CMDID_LWM2M_READ_EVT */ - -static struct lwm2mstub_instance_s g_lwm2mread_inst; -static FAR void *g_lwm2mreadargs[] = -{ - NULL, NULL, &g_lwm2mread_inst -}; - -/* event argument for LTE_CMDID_LWM2M_WRITE_EVT */ - -static struct lwm2mstub_instance_s g_lwm2mwrite_inst; -static char g_lwm2mwrite_value[LWM2MSTUB_MAX_WRITE_SIZE]; -static FAR void *g_lwm2mwriteargs[] = -{ - NULL, NULL, &g_lwm2mwrite_inst, g_lwm2mwrite_value, - NULL, (FAR void *)LWM2MSTUB_MAX_WRITE_SIZE -}; - -/* event argument for LTE_CMDID_LWM2M_EXEC_EVT */ - -static struct lwm2mstub_instance_s g_lwm2mexec_inst; -static FAR void *g_lwm2mexecargs[] = -{ - NULL, NULL, &g_lwm2mexec_inst, NULL -}; - -/* event argument for LTE_CMDID_LWM2M_OVSTART_EVT */ - -static struct lwm2mstub_instance_s g_lwm2movstart_inst; -static char g_lwm2movstart_token[LWM2MSTUB_MAX_TOKEN_SIZE]; -static struct lwm2mstub_ovcondition_s g_lwm2movstart_cond; -static FAR void *g_lwm2movstartargs[] = -{ - NULL, NULL, &g_lwm2movstart_inst, g_lwm2movstart_token, - (FAR void *)LWM2MSTUB_MAX_TOKEN_SIZE, &g_lwm2movstart_cond -}; - -/* event argument for LTE_CMDID_LWM2M_OVSTOP_EVT */ - -static struct lwm2mstub_instance_s g_lwm2movstop_inst; -static char g_lwm2movstop_token[LWM2MSTUB_MAX_TOKEN_SIZE]; -static FAR void *g_lwm2movstopargs[] = -{ - NULL, NULL, &g_lwm2movstop_inst, &g_lwm2movstop_token, - (FAR void *)LWM2MSTUB_MAX_TOKEN_SIZE -}; - -/* event argument for LTE_CMDID_LWM2M_SERVEROP_EVT */ - -static struct lwm2mstub_instance_s g_lwm2msrvop_inst; -static FAR void *g_lwm2moperationargs[] = -{ - NULL, NULL, &g_lwm2msrvop_inst -}; - -/* event argument for LTE_CMDID_LWM2M_FWUP_EVT */ - -static FAR void *g_lwm2mfwupargs[] = -{ - NULL -}; - -static struct alt_evtbuffer_s g_evtbuff; -static struct alt_evtbuf_inst_s g_evtbuffers[] = -{ - TABLE_CONTENT(SETRESTART, POWER_ON, g_setrestartargs), - TABLE_CONTENT(GETVER, GET_VERSION, g_getverargs), -#ifdef CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API - TABLE_CONTENT(RADIOON, RADIO_ON, g_radioonargs), - TABLE_CONTENT(RADIOOFF, RADIO_OFF, g_radiooffargs), -#endif /* CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API */ - TABLE_CONTENT(ACTPDN, ACTIVATE_PDN, g_actpdnargs), -#ifdef CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API - TABLE_CONTENT(DEACTPDN, DEACTIVATE_PDN, g_deactpdnargs), - TABLE_CONTENT(GETNETINFO, GET_NETINFO, g_netinfoargs), - TABLE_CONTENT(IMSCAP, GET_IMS_CAP, g_imscapargs), - TABLE_CONTENT(GETPHONE, GET_PHONENO, g_getphoneargs), - TABLE_CONTENT(GETIMSI, GET_IMSI, g_getimsiargs), - TABLE_CONTENT(GETIMEI, GET_IMEI, g_getimeiargs), - TABLE_CONTENT(GETPINSET, GET_PINSET, g_getpinsetargs), - TABLE_CONTENT(PINENABLE, SET_PIN_LOCK, g_pinenableargs), - TABLE_CONTENT(CHANGEPIN, SET_PIN_CODE, g_changepinargs), - TABLE_CONTENT(ENTERPIN, ENTER_PIN, g_enterpinargs), - TABLE_CONTENT(GETLTIME, GET_LTIME, g_getltimeargs), - TABLE_CONTENT(GETOPER, GET_OPERATOR, g_getoperargs), - TABLE_CONTENT(GETEDRX, GET_EDRX, g_getedrxargs), - TABLE_CONTENT(SETEDRX, SET_EDRX, g_setedrxargs), - TABLE_CONTENT(GETPSM, GET_PSM, g_getpsmargs), - TABLE_CONTENT(SETPSM, SET_PSM, g_setpsmargs), - TABLE_CONTENT(GETCE, GET_CE, g_getceargs), - TABLE_CONTENT(SETCE, SET_CE, g_setceargs), - TABLE_CONTENT(GETSIMINFO, GET_SIMINFO, g_getsiminfoargs), - TABLE_CONTENT(GETCEDRX, GET_DYNAMICEDRX, g_getcedrxargs), - TABLE_CONTENT(GETCPSM, GET_DYNAMICPSM, g_getcpsmargs), - TABLE_CONTENT(GETQUAL, GET_QUALITY, g_getqualargs), - TABLE_CONTENT(GETCELL, GET_CELLINFO, g_getcellargs), -#endif /* CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API */ - TABLE_CONTENT(GETRAT, GET_RAT, g_getratargs), - TABLE_CONTENT(SETRAT, SET_RAT, g_setratargs), - TABLE_CONTENT(GETRATINFO, GET_RAT, g_getratinfoargs), - TABLE_CONTENT(REPNETINFO, REPORT_NETINFO, g_repnetinfoargs), - TABLE_CONTENT_NOARG(REPEVT_DUMMY, REPORT_EVT), - TABLE_CONTENT(REPSIMSTAT, UNKNOWN, g_repsimstatargs), - TABLE_CONTENT(REPLTIME, UNKNOWN, g_repltimeargs), - TABLE_CONTENT(REPQUAL, REPORT_QUALITY, g_repqualargs), - TABLE_CONTENT(REPCELL, REPORT_CELLINFO, g_repcellargs), - TABLE_CONTENT(GETERRINFO, ERRINFO, g_geterrinfoargs), - TABLE_CONTENT(TLS_CONFIG_VERIFY, TLS_CONFIG_VERIFY_CALLBACK, - g_vrfycbargs), - TABLE_CONTENT(SMS_REPORT_RECV, SMS_REPORT_RECV, g_smsreportargs), - - /* For Unsolicited event */ - - TABLE_CONTENT_NOARG(LWM2M_URC_DUMMY, URC_EVENT), - TABLE_CONTENT(LWM2M_READ_EVT, UNKNOWN, g_lwm2mreadargs), - TABLE_CONTENT(LWM2M_WRITE_EVT, UNKNOWN, g_lwm2mwriteargs), - TABLE_CONTENT(LWM2M_EXEC_EVT, UNKNOWN, g_lwm2mexecargs), - TABLE_CONTENT(LWM2M_OVSTART_EVT, UNKNOWN, g_lwm2movstartargs), - TABLE_CONTENT(LWM2M_OVSTOP_EVT, UNKNOWN, g_lwm2movstopargs), - TABLE_CONTENT(LWM2M_SERVEROP_EVT, UNKNOWN, g_lwm2moperationargs), - TABLE_CONTENT(LWM2M_FWUP_EVT, UNKNOWN, g_lwm2mfwupargs), - - /* Add the command ID of LTE_CMDID_SELECT to the table so that the driver - * can identify the bitmap of the select event. - * The output parameter is NULL since a container for select is used. - */ - - TABLE_CONTENT_NOARG(SELECT, SOCK_SELECT) -}; - -static struct cbinfo_s g_execbtable[] = -{ - {LTE_CMDID_SETRESTART, lte_set_report_restart_exec_cb}, -#ifdef CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API - {LTE_CMDID_GETVER, lte_get_version_exec_cb}, - {LTE_CMDID_RADIOON, lte_radio_on_exec_cb}, - {LTE_CMDID_RADIOOFF, lte_radio_off_exec_cb}, -#endif /* CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API */ - {LTE_CMDID_ACTPDN, lte_activate_pdn_exec_cb}, -#ifdef CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API - {LTE_CMDID_DEACTPDN, lte_deactivate_pdn_exec_cb}, - {LTE_CMDID_GETNETINFO, lte_get_netinfo_exec_cb}, - {LTE_CMDID_IMSCAP, lte_get_imscap_exec_cb}, - {LTE_CMDID_GETPHONE, lte_get_phoneno_exec_cb}, - {LTE_CMDID_GETIMSI, lte_get_imsi_exec_cb}, - {LTE_CMDID_GETIMEI, lte_get_imei_exec_cb}, - {LTE_CMDID_GETPINSET, lte_get_pinset_exec_cb}, - {LTE_CMDID_PINENABLE, lte_set_pinenable_exec_cb}, - {LTE_CMDID_CHANGEPIN, lte_change_pin_exec_cb}, - {LTE_CMDID_ENTERPIN, lte_enter_pin_exec_cb}, - {LTE_CMDID_GETLTIME, lte_get_localtime_exec_cb}, - {LTE_CMDID_GETOPER, lte_get_operator_exec_cb}, - {LTE_CMDID_GETEDRX, lte_get_edrx_exec_cb}, - {LTE_CMDID_SETEDRX, lte_set_edrx_exec_cb}, - {LTE_CMDID_GETPSM, lte_get_psm_exec_cb}, - {LTE_CMDID_SETPSM, lte_set_psm_exec_cb}, - {LTE_CMDID_GETCE, lte_get_ce_exec_cb}, - {LTE_CMDID_SETCE, lte_set_ce_exec_cb}, - {LTE_CMDID_GETSIMINFO, lte_get_siminfo_exec_cb}, - {LTE_CMDID_GETCEDRX, lte_get_current_edrx_exec_cb}, - {LTE_CMDID_GETCPSM, lte_get_current_psm_exec_cb}, - {LTE_CMDID_GETQUAL, lte_get_quality_exec_cb}, -#endif /* CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API */ - {LTE_CMDID_REPNETINFO, lte_set_report_netinfo_exec_cb}, - {LTE_CMDID_REPSIMSTAT, lte_set_report_simstat_exec_cb}, - {LTE_CMDID_REPLTIME, lte_set_report_localtime_exec_cb}, - {LTE_CMDID_REPQUAL, lte_set_report_quality_exec_cb}, - {LTE_CMDID_REPCELL, lte_set_report_cellinfo_exec_cb}, - {LTE_CMDID_TLS_CONFIG_VERIFY, tls_config_verify_exec_cb}, - {LTE_CMDID_LWM2M_READ_EVT, lwm2m_read_evt_cb}, - {LTE_CMDID_LWM2M_WRITE_EVT, lwm2m_write_evt_cb}, - {LTE_CMDID_LWM2M_EXEC_EVT, lwm2m_exec_evt_cb}, - {LTE_CMDID_LWM2M_OVSTART_EVT, lwm2m_ovstart_evt_cb}, - {LTE_CMDID_LWM2M_OVSTOP_EVT, lwm2m_ovstop_evt_cb}, - {LTE_CMDID_LWM2M_SERVEROP_EVT, lwm2m_operation_evt_cb}, - {LTE_CMDID_LWM2M_FWUP_EVT, lwm2m_fwupdate_evt_cb}, -}; - -static struct cbinfo_s g_cbtable[NCBTABLES]; -static sem_t g_cbtablelock; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static uint64_t lte_set_report_restart_exec_cb(FAR void *cb, - FAR void **cbarg, - FAR bool *set_writable) -{ - restart_report_cb_t callback = (restart_report_cb_t)cb; - FAR uint32_t *param = (FAR uint32_t *)cbarg[0]; - - if (callback) - { - callback(*param); - } - - return 0ULL; -} - -#ifdef CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API - -static uint64_t lte_radio_on_exec_cb(FAR void *cb, FAR void **cbarg, - FAR bool *set_writable) -{ - radio_on_cb_t callback = (radio_on_cb_t)cb; - FAR uint32_t *result = (FAR uint32_t *)cbarg[0]; - - if (callback) - { - callback(*result); - } - - return 0ULL; -} - -static uint64_t lte_radio_off_exec_cb(FAR void *cb, FAR void **cbarg, - FAR bool *set_writable) -{ - radio_off_cb_t callback = (radio_off_cb_t)cb; - FAR uint32_t *result = (FAR uint32_t *)cbarg[0]; - - if (callback) - { - callback(*result); - } - - return 0ULL; -} - -#endif /* CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API */ - -static uint64_t lte_activate_pdn_exec_cb(FAR void *cb, FAR void **cbarg, - FAR bool *set_writable) -{ - activate_pdn_cb_t callback = (activate_pdn_cb_t)cb; - FAR uint32_t *result = (FAR uint32_t *)cbarg[0]; - FAR lte_pdn_t *pdn = (FAR lte_pdn_t *)cbarg[1]; - - if (callback) - { - callback(*result, pdn); - } - - return 0ULL; -} - -#ifdef CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API - -static uint64_t lte_deactivate_pdn_exec_cb(FAR void *cb, FAR void **cbarg, - FAR bool *set_writable) -{ - deactivate_pdn_cb_t callback = (deactivate_pdn_cb_t)cb; - FAR uint32_t *result = (FAR uint32_t *)cbarg[0]; - - if (callback) - { - callback(*result); - } - - return 0ULL; -} - -static uint64_t lte_get_netinfo_exec_cb(FAR void *cb, FAR void **cbarg, - FAR bool *set_writable) -{ - get_netinfo_cb_t callback = (get_netinfo_cb_t)cb; - FAR uint32_t *result = (FAR uint32_t *)cbarg[0]; - FAR lte_netinfo_t *info = (FAR lte_netinfo_t *)cbarg[1]; - - if (callback) - { - callback(*result, info); - } - - return 0ULL; -} - -static uint64_t lte_get_imscap_exec_cb(FAR void *cb, FAR void **cbarg, - FAR bool *set_writable) -{ - get_imscap_cb_t callback = (get_imscap_cb_t)cb; - FAR uint32_t *result = (FAR uint32_t *)cbarg[0]; - FAR bool *imscap = (FAR bool *)cbarg[1]; - - if (callback) - { - callback(*result, *imscap); - } - - return 0ULL; -} - -static uint64_t lte_get_version_exec_cb(FAR void *cb, FAR void **cbarg, - FAR bool *set_writable) -{ - get_ver_cb_t callback = (get_ver_cb_t)cb; - FAR uint32_t *result = (FAR uint32_t *)cbarg[0]; - FAR lte_version_t *version = (FAR lte_version_t *)cbarg[1]; - - if (callback) - { - callback(*result, version); - } - - return 0ULL; -} - -static uint64_t lte_get_phoneno_exec_cb(FAR void *cb, FAR void **cbarg, - FAR bool *set_writable) -{ - get_phoneno_cb_t callback = (get_phoneno_cb_t)cb; - FAR uint32_t *result = (FAR uint32_t *)cbarg[0]; - FAR uint8_t *errcause = (FAR uint8_t *)cbarg[1]; - FAR char *phoneno = (FAR char *)cbarg[2]; - - if (callback) - { - callback(*result, *errcause, phoneno); - } - - return 0ULL; -} - -static uint64_t lte_get_imsi_exec_cb(FAR void *cb, FAR void **cbarg, - FAR bool *set_writable) -{ - get_imsi_cb_t callback = (get_imsi_cb_t)cb; - FAR uint32_t *result = (FAR uint32_t *)cbarg[0]; - FAR uint8_t *errcause = (FAR uint8_t *)cbarg[1]; - FAR char *imsi = (FAR char *)cbarg[2]; - - if (callback) - { - callback(*result, *errcause, imsi); - } - - return 0ULL; -} - -static uint64_t lte_get_imei_exec_cb(FAR void *cb, FAR void **cbarg, - FAR bool *set_writable) -{ - get_imei_cb_t callback = (get_imei_cb_t)cb; - FAR uint32_t *result = (FAR uint32_t *)cbarg[0]; - FAR char *imei = (FAR char *)cbarg[1]; - - if (callback) - { - callback(*result, imei); - } - - return 0ULL; -} - -static uint64_t lte_get_pinset_exec_cb(FAR void *cb, FAR void **cbarg, - FAR bool *set_writable) -{ - get_pinset_cb_t callback = (get_pinset_cb_t)cb; - FAR uint32_t *result = (FAR uint32_t *)cbarg[0]; - FAR lte_getpin_t *pinset = (FAR lte_getpin_t *)cbarg[1]; - - if (callback) - { - callback(*result, pinset); - } - - return 0ULL; -} - -static uint64_t lte_set_pinenable_exec_cb(FAR void *cb, FAR void **cbarg, - FAR bool *set_writable) -{ - set_pinenable_cb_t callback = (set_pinenable_cb_t)cb; - FAR uint32_t *result = (FAR uint32_t *)cbarg[0]; - FAR uint8_t *attemptsleft = (FAR uint8_t *)cbarg[1]; - - if (callback) - { - callback(*result, *attemptsleft); - } - - return 0ULL; -} - -static uint64_t lte_change_pin_exec_cb(FAR void *cb, FAR void **cbarg, - FAR bool *set_writable) -{ - change_pin_cb_t callback = (change_pin_cb_t)cb; - FAR uint32_t *result = (FAR uint32_t *)cbarg[0]; - FAR uint8_t *attemptsleft = (FAR uint8_t *)cbarg[1]; - - if (callback) - { - callback(*result, *attemptsleft); - } - - return 0ULL; -} - -static uint64_t lte_enter_pin_exec_cb(FAR void *cb, FAR void **cbarg, - FAR bool *set_writable) -{ - enter_pin_cb_t callback = (enter_pin_cb_t)cb; - FAR uint32_t *result = (FAR uint32_t *)cbarg[0]; - FAR uint8_t *simstat = (FAR uint8_t *)cbarg[1]; - FAR uint8_t *attemptsleft = (FAR uint8_t *)cbarg[2]; - - if (callback) - { - callback(*result, *simstat, *attemptsleft); - } - - return 0ULL; -} - -static uint64_t lte_get_localtime_exec_cb(FAR void *cb, FAR void **cbarg, - FAR bool *set_writable) -{ - get_localtime_cb_t callback = (get_localtime_cb_t)cb; - FAR uint32_t *result = (FAR uint32_t *)cbarg[0]; - FAR lte_localtime_t *localtime = (FAR lte_localtime_t *)cbarg[1]; - - if (callback) - { - callback(*result, localtime); - } - - return 0ULL; -} - -static uint64_t lte_get_operator_exec_cb(FAR void *cb, FAR void **cbarg, - FAR bool *set_writable) -{ - get_operator_cb_t callback = (get_operator_cb_t)cb; - FAR uint32_t *result = (FAR uint32_t *)cbarg[0]; - FAR char *oper = (FAR char *)cbarg[1]; - - if (callback) - { - callback(*result, oper); - } - - return 0ULL; -} - -static uint64_t lte_get_edrx_exec_cb(FAR void *cb, FAR void **cbarg, - FAR bool *set_writable) -{ - get_edrx_cb_t callback = (get_edrx_cb_t)cb; - FAR uint32_t *result = (FAR uint32_t *)cbarg[0]; - FAR lte_edrx_setting_t *settings = (FAR lte_edrx_setting_t *)cbarg[1]; - FAR bool *is_getedrxevt = (FAR bool *)cbarg[2]; - - if (!(*is_getedrxevt)) - { - return alt1250_evt_search(LTE_CMDID_GETCEDRX); - } - - if (callback) - { - callback(*result, settings); - *is_getedrxevt = false; - } - - return 0ULL; -} - -static uint64_t lte_set_edrx_exec_cb(FAR void *cb, FAR void **cbarg, - FAR bool *set_writable) -{ - set_edrx_cb_t callback = (set_edrx_cb_t)cb; - FAR uint32_t *result = (FAR uint32_t *)cbarg[0]; - - if (callback) - { - callback(*result); - } - - return 0ULL; -} - -static uint64_t lte_get_psm_exec_cb(FAR void *cb, FAR void **cbarg, - FAR bool *set_writable) -{ - get_psm_cb_t callback = (get_psm_cb_t)cb; - FAR uint32_t *result = (FAR uint32_t *)cbarg[0]; - FAR lte_psm_setting_t *settings = (FAR lte_psm_setting_t *)cbarg[1]; - FAR bool *is_getpsmevt = (FAR bool *)cbarg[2]; - - if (!(*is_getpsmevt)) - { - return alt1250_evt_search(LTE_CMDID_GETCPSM); - } - - if (callback) - { - callback(*result, settings); - *is_getpsmevt = false; - } - - return 0ULL; -} - -static uint64_t lte_set_psm_exec_cb(FAR void *cb, FAR void **cbarg, - FAR bool *set_writable) -{ - set_psm_cb_t callback = (set_psm_cb_t)cb; - FAR uint32_t *result = (FAR uint32_t *)cbarg[0]; - - if (callback) - { - callback(*result); - } - - return 0ULL; -} - -static uint64_t lte_get_ce_exec_cb(FAR void *cb, FAR void **cbarg, - FAR bool *set_writable) -{ - get_ce_cb_t callback = (get_ce_cb_t)cb; - FAR uint32_t *result = (FAR uint32_t *)cbarg[0]; - FAR lte_ce_setting_t *settings = (FAR lte_ce_setting_t *)cbarg[1]; - - if (callback) - { - callback(*result, settings); - } - - return 0ULL; -} - -static uint64_t lte_set_ce_exec_cb(FAR void *cb, FAR void **cbarg, - FAR bool *set_writable) -{ - set_ce_cb_t callback = (set_ce_cb_t)cb; - FAR uint32_t *result = (FAR uint32_t *)cbarg[0]; - - if (callback) - { - callback(*result); - } - - return 0ULL; -} - -static uint64_t lte_get_siminfo_exec_cb(FAR void *cb, FAR void **cbarg, - FAR bool *set_writable) -{ - get_siminfo_cb_t callback = (get_siminfo_cb_t)cb; - FAR uint32_t *result = (FAR uint32_t *)cbarg[0]; - FAR lte_siminfo_t *siminfo = (FAR lte_siminfo_t *)cbarg[1]; - - if (callback) - { - callback(*result, siminfo); - } - - return 0ULL; -} - -static uint64_t lte_get_current_edrx_exec_cb(FAR void *cb, FAR void **cbarg, - FAR bool *set_writable) -{ - get_current_edrx_cb_t callback = (get_current_edrx_cb_t)cb; - FAR uint32_t *result = (FAR uint32_t *)cbarg[0]; - FAR lte_edrx_setting_t *settings = (FAR lte_edrx_setting_t *)cbarg[1]; - FAR bool *is_getcedrxevt = (FAR bool *)cbarg[2]; - - if (!(*is_getcedrxevt)) - { - return alt1250_evt_search(LTE_CMDID_GETEDRX); - } - - if (callback) - { - callback(*result, settings); - *is_getcedrxevt = false; - } - - return 0ULL; -} - -static uint64_t lte_get_current_psm_exec_cb(FAR void *cb, FAR void **cbarg, - FAR bool *set_writable) -{ - get_current_psm_cb_t callback = (get_current_psm_cb_t)cb; - FAR uint32_t *result = (FAR uint32_t *)cbarg[0]; - FAR lte_psm_setting_t *settings = (FAR lte_psm_setting_t *)cbarg[1]; - FAR bool *is_getcpsmevt = (FAR bool *)cbarg[2]; - - if (!(*is_getcpsmevt)) - { - return alt1250_evt_search(LTE_CMDID_GETPSM); - } - - if (callback) - { - callback(*result, settings); - *is_getcpsmevt = false; - } - - return 0ULL; -} - -static uint64_t lte_get_quality_exec_cb(FAR void *cb, FAR void **cbarg, - FAR bool *set_writable) -{ - get_quality_cb_t callback = (get_quality_cb_t)cb; - FAR uint32_t *result = (FAR uint32_t *)cbarg[0]; - FAR lte_quality_t *quality = (FAR lte_quality_t *)cbarg[1]; - - if (callback) - { - callback(*result, quality); - } - - return 0ULL; -} - -#endif /* CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API */ - -static uint64_t lte_set_report_netinfo_exec_cb(FAR void *cb, - FAR void **cbarg, - FAR bool *set_writable) -{ - netinfo_report_cb_t callback = (netinfo_report_cb_t)cb; - FAR lte_netinfo_t *info = (FAR lte_netinfo_t *)cbarg[0]; - uint8_t ndnsaddrs = *((FAR uint8_t *)cbarg[1]); - FAR struct sockaddr_storage *dnsaddr = - (FAR struct sockaddr_storage *)cbarg[2]; -#if defined(CONFIG_NETDB_DNSCLIENT) - socklen_t addrlen; - uint8_t i; -#endif - -#if defined(CONFIG_NETDB_DNSCLIENT) - DEBUGASSERT(ndnsaddrs <= ALTCOM_DNS_SERVERS); - - ndnsaddrs = (ndnsaddrs > ALTCOM_DNS_SERVERS) ? - ALTCOM_DNS_SERVERS : ndnsaddrs; - - for (i = 0; (i < ndnsaddrs) && (i < CONFIG_NETDB_DNSSERVER_NAMESERVERS); - i++) - { - addrlen = (dnsaddr[i].ss_family == AF_INET) ? - sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6); - dns_add_nameserver((FAR const struct sockaddr *)&dnsaddr[i], addrlen); - } - - if (info->pdn_num > 0) - { - FAR lte_pdn_t *pdn = &info->pdn_stat[0]; - FAR lte_ipaddr_t *ipaddr = &pdn->address[0]; - - /* ALT1250 can only connect one PDN, so check the first PDN. */ - - if ((pdn->ipaddr_num == 1) && (ipaddr->ip_type == LTE_IPTYPE_V4)) - { - dns_set_queryfamily(AF_INET); - } - else if ((pdn->ipaddr_num == 1) && (ipaddr->ip_type == LTE_IPTYPE_V6)) - { - dns_set_queryfamily(AF_INET6); - } - else - { - dns_set_queryfamily(AF_UNSPEC); - } - } - else - { - dns_set_queryfamily(AF_UNSPEC); - } -#endif - - if (callback) - { - callback(info); - } - - return 0ULL; -} - -static uint64_t lte_set_report_simstat_exec_cb(FAR void *cb, - FAR void **cbarg, - FAR bool *set_writable) -{ - simstat_report_cb_t callback = (simstat_report_cb_t)cb; - FAR uint32_t *simstat = (FAR uint32_t *)cbarg[0]; - - if (callback) - { - callback(*simstat); - } - - return 0ULL; -} - -static uint64_t lte_set_report_localtime_exec_cb(FAR void *cb, - FAR void **cbarg, - FAR bool *set_writable) -{ - localtime_report_cb_t callback = (localtime_report_cb_t)cb; - FAR lte_localtime_t *localtime = (FAR lte_localtime_t *)cbarg[0]; - - if (callback) - { - callback(localtime); - } - - return 0ULL; -} - -static uint64_t lte_set_report_quality_exec_cb(FAR void *cb, - FAR void **cbarg, - - FAR bool *set_writable) -{ - quality_report_cb_t callback = (quality_report_cb_t)cb; - FAR lte_quality_t *quality = (FAR lte_quality_t *)cbarg[0]; - - if (callback) - { - callback(quality); - } - - return 0ULL; -} - -static uint64_t lte_set_report_cellinfo_exec_cb(FAR void *cb, - FAR void **cbarg, - FAR bool *set_writable) -{ - cellinfo_report_cb_t callback = (cellinfo_report_cb_t)cb; - FAR lte_cellinfo_t *cellinfo = (FAR lte_cellinfo_t *)cbarg[0]; - - if (callback) - { - callback(cellinfo); - } - - return 0ULL; -} - -static uint64_t tls_config_verify_exec_cb(FAR void *cb, FAR void **cbarg, - FAR bool *set_writable) -{ - CODE void (*callback)(FAR void **cbarg) = cb; - FAR void *arg[2]; - - uint32_t crt = *((FAR uint32_t *)cbarg[0]); - int32_t depth = *((FAR int32_t *)cbarg[1]); - - arg[0] = &crt; - arg[1] = &depth; - - /* Here, need to set the status of the event argument to "writable". - * The callback function below will send a response command to ALT1250 - * for this event. After receiving the response command, - * ALT1250 may send this event again. - * If the status of the event argument is "not writable", the ALTCOM driver - * will discard this event. - */ - - alt1250_setevtarg_writable(LTE_CMDID_TLS_CONFIG_VERIFY); - *set_writable = true; - - /* Use a callback to pass event arguments. */ - - callback(arg); - - return 0ULL; -} - -static uint64_t lwm2m_read_evt_cb(FAR void *cb, FAR void **cbarg, - FAR bool *set_writable) -{ - lwm2mstub_read_cb_t callback = (lwm2mstub_read_cb_t)cb; - - if (callback) - { - callback((int)cbarg[0], (int)cbarg[1], - (FAR struct lwm2mstub_instance_s *)cbarg[2]); - } - - return 0ULL; -} - -static uint64_t lwm2m_write_evt_cb(FAR void *cb, FAR void **cbarg, - FAR bool *set_writable) -{ - lwm2mstub_write_cb_t callback = (lwm2mstub_write_cb_t)cb; - - if (callback) - { - callback((int)cbarg[0], (int)cbarg[1], - (FAR struct lwm2mstub_instance_s *)cbarg[2], - (FAR char *)cbarg[3], (int)cbarg[4]); - } - - return 0ULL; -} - -static uint64_t lwm2m_exec_evt_cb(FAR void *cb, FAR void **cbarg, - FAR bool *set_writable) -{ - lwm2mstub_exec_cb_t callback = (lwm2mstub_exec_cb_t)cb; - - if (callback) - { - callback((int)cbarg[0], (int)cbarg[1], - (FAR struct lwm2mstub_instance_s *)cbarg[2]); - } - - return 0ULL; -} - -static uint64_t lwm2m_ovstart_evt_cb(FAR void *cb, FAR void **cbarg, - FAR bool *set_writable) -{ - lwm2mstub_ovstart_cb_t callback = (lwm2mstub_ovstart_cb_t)cb; - - if (callback) - { - callback((int)cbarg[0], (int)cbarg[1], - (FAR struct lwm2mstub_instance_s *)cbarg[2], - (FAR char *)cbarg[3], - (FAR struct lwm2mstub_ovcondition_s *)cbarg[5]); - } - - return 0ULL; -} - -static uint64_t lwm2m_ovstop_evt_cb(FAR void *cb, FAR void **cbarg, - FAR bool *set_writable) -{ - lwm2mstub_ovstop_cb_t callback = (lwm2mstub_ovstop_cb_t)cb; - - if (callback) - { - callback((int)cbarg[0], (int)cbarg[1], - (FAR struct lwm2mstub_instance_s *)cbarg[2], - (FAR char *)cbarg[3]); - } - - return 0ULL; -} - -static uint64_t lwm2m_operation_evt_cb(FAR void *cb, FAR void **cbarg, - FAR bool *set_writable) -{ - lwm2mstub_operation_cb_t callback = (lwm2mstub_operation_cb_t)cb; - - if (callback) - { - callback((int)cbarg[0], (int)cbarg[1], - (FAR struct lwm2mstub_instance_s *)cbarg[2]); - } - - return 0ULL; -} - -static uint64_t lwm2m_fwupdate_evt_cb(FAR void *cb, FAR void **cbarg, - FAR bool *set_writable) -{ - lwm2mstub_fwupstate_cb_t callback = (lwm2mstub_fwupstate_cb_t)cb; - - if (callback) - { - callback((int)cbarg[0]); - } - - return 0ULL; -} - -/**************************************************************************** - * Name: evtbuffer_init - ****************************************************************************/ - -static FAR struct alt_evtbuffer_s *evtbuffer_init(void) -{ - int i; - - for (i = 0; i < nitems(g_evtbuffers); i++) - { - nxmutex_init(&g_evtbuffers[i].stat_lock); - g_evtbuffers[i].stat = ALTEVTBUF_ST_WRITABLE; - } - - g_evtbuff.ninst = nitems(g_evtbuffers); - g_evtbuff.inst = g_evtbuffers; - - return &g_evtbuff; -} - -/**************************************************************************** - * Name: clear_callback - ****************************************************************************/ - -static void clear_callback(uint32_t cmdid) -{ - int i; - - sem_wait(&g_cbtablelock); - - for (i = 0; i < nitems(g_cbtable); i++) - { - if (g_cbtable[i].cmdid == cmdid) - { - g_cbtable[i].cmdid = 0; - g_cbtable[i].cb = NULL; - break; - } - } - - sem_post(&g_cbtablelock); -} - -/**************************************************************************** - * Name: errno2result - ****************************************************************************/ - -static void errno2result(FAR int32_t *result_ptr) -{ - if (result_ptr && *result_ptr < 0) - { - if (*result_ptr == -ECANCELED) - { - *result_ptr = LTE_RESULT_CANCEL; - } - else - { - *result_ptr = LTE_RESULT_ERROR; - } - } -} - -/**************************************************************************** - * Name: exec_callback - ****************************************************************************/ - -static uint64_t exec_callback(uint32_t cmdid, - CODE uint64_t (*func)(FAR void *cb, - FAR void **arg, - FAR bool *set_writable), - FAR void **arg, FAR bool *set_writable) -{ - uint64_t evtbitmap = 0ULL; - FAR int32_t *result = NULL; - FAR void *callback = NULL; - - callback = get_cbfunc(cmdid); - if (callback) - { - if (!IS_REPORT_API(cmdid)) - { - /* APIs that have result as a callback argument - * change the value before execution. - */ - - result = (int32_t *)arg[0]; - errno2result(result); - } - - evtbitmap = func(callback, arg, set_writable); - return evtbitmap; - } - - /* When callback is not found, - * GETPSM and GETEDRX, REPNETINFO, REPSIMSTAT, REPLTIME will - * execute func() and update the evtbitmap - */ - - if (cmdid == LTE_CMDID_GETPSM || - cmdid == LTE_CMDID_GETEDRX || - cmdid == LTE_CMDID_REPNETINFO || - cmdid == LTE_CMDID_REPSIMSTAT || - cmdid == LTE_CMDID_REPLTIME) - { - evtbitmap = func(NULL, arg, set_writable); - } - - return evtbitmap; -} - -/**************************************************************************** - * Name: get_evtarg - ****************************************************************************/ - -static FAR void **get_evtarg(int idx) -{ - FAR alt_evtbuf_inst_t *inst = &g_evtbuffers[idx]; - - return inst->outparam; -} - -/**************************************************************************** - * Name: get_cmdid_byidx - ****************************************************************************/ - -static uint32_t get_cmdid_byidx(int idx) -{ - FAR alt_evtbuf_inst_t *inst = &g_evtbuffers[idx]; - - return inst->cmdid; -} - -/**************************************************************************** - * Name: update_evtarg_writable - ****************************************************************************/ - -static void update_evtarg_writable(int idx) -{ - FAR alt_evtbuf_inst_t *inst = &g_evtbuffers[idx]; - - nxmutex_lock(&inst->stat_lock); - - inst->stat = ALTEVTBUF_ST_WRITABLE; - - nxmutex_unlock(&inst->stat_lock); -} - -/**************************************************************************** - * Name: update_evtarg_writableall - ****************************************************************************/ - -static void update_evtarg_writableall(void) -{ - int idx; - - for (idx = 0; idx < nitems(g_evtbuffers); idx++) - { - FAR alt_evtbuf_inst_t *inst = &g_evtbuffers[idx]; - - nxmutex_lock(&inst->stat_lock); - - inst->stat = ALTEVTBUF_ST_WRITABLE; - - nxmutex_unlock(&inst->stat_lock); - } -} - -/**************************************************************************** - * Name: get_execfunc - ****************************************************************************/ - -static FAR void *get_execfunc(int idx) -{ - int i; - uint32_t cmdid; - - cmdid = get_cmdid_byidx(idx); - - for (i = 0; i < nitems(g_execbtable); i++) - { - if (g_execbtable[i].cmdid == cmdid) - { - return g_execbtable[i].cb; - } - } - - return NULL; -} - -/**************************************************************************** - * Name: get_cbfunc - ****************************************************************************/ - -static FAR void *get_cbfunc(uint32_t cmdid) -{ - int i; - FAR void *ret = NULL; - - sem_wait(&g_cbtablelock); - - for (i = 0; i < nitems(g_cbtable); i++) - { - if (g_cbtable[i].cmdid == cmdid) - { - ret = g_cbtable[i].cb; - break; - } - } - - sem_post(&g_cbtablelock); - - return ret; -} - -/**************************************************************************** - * Name: alt1250_search_execcb - ****************************************************************************/ - -static uint64_t alt1250_search_execcb(uint64_t evtbitmap) -{ - int idx; - uint64_t ret = 0ULL; - uint64_t l_evtbitmap = 0ULL; - CODE uint64_t (*func)(FAR void *cb, FAR void **arg, - FAR bool *set_writable); - bool set_writable; - - for (idx = 0; idx < nitems(g_evtbuffers); idx++) - { - if (evtbitmap & (1ULL << idx)) - { - dbg_alt1250("idx=%d\n", idx); - - set_writable = false; - - func = get_execfunc(idx); - l_evtbitmap = exec_callback(g_evtbuffers[idx].cmdid, func, - get_evtarg(idx), &set_writable); - - ret |= l_evtbitmap; - - if (l_evtbitmap == 0ULL) - { - if (LTE_ISCMDGRP_NORMAL(g_evtbuffers[idx].cmdid)) - { - clear_callback(g_evtbuffers[idx].cmdid); - } - } - - if (l_evtbitmap == 0ULL) - { - if (!set_writable) - { - update_evtarg_writable(idx); - } - } - } - } - - dbg_alt1250("evtbitmap=0x%llx\n", ret); - - return ret; -} - -/**************************************************************************** - * Name: alt1250_evt_search - ****************************************************************************/ - -static uint64_t alt1250_evt_search(uint32_t cmdid) -{ - int idx; - - uint64_t evtbitmap = 0ULL; - - for (idx = 0; idx < nitems(g_evtbuffers); idx++) - { - if (g_evtbuffers[idx].cmdid == cmdid) - { - evtbitmap = (1ULL << idx); - } - } - - return evtbitmap; -} - -/**************************************************************************** - * Name: reg_evtcb - ****************************************************************************/ - -static int reg_evtcb(struct cbinfo_s *info, uint32_t cmdid, FAR void *cb) -{ - if (info == NULL) - { - return ERROR; - } - - info->cmdid = cmdid; - info->cb = cb; - - return OK; -} - -/**************************************************************************** - * Name: search_evtcb - ****************************************************************************/ - -static FAR struct cbinfo_s *search_evtcb(uint32_t cmdid) -{ - int i; - - for (i = 0; i < nitems(g_cbtable); i++) - { - if (g_cbtable[i].cmdid == cmdid) - { - return &g_cbtable[i]; - } - } - - return NULL; -} - -/**************************************************************************** - * Name: register_evtcb - ****************************************************************************/ - -static int register_evtcb(uint32_t cmdid, FAR void *cb) -{ - if (search_evtcb(cmdid) == NULL) - { - if (reg_evtcb(search_free_evtcb(), cmdid, cb) == ERROR) - { - return -EBUSY; - } - - return OK; - } - else - { - return IS_REPORT_API(cmdid) ? -EALREADY : -EINPROGRESS; - } -} - -/**************************************************************************** - * Name: clear_evtcb - ****************************************************************************/ - -static int clear_evtcb(uint32_t cmdid) -{ - clr_evtcb(search_evtcb(cmdid)); - return OK; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: alt1250_setevtbuff - ****************************************************************************/ - -FAR struct alt_evtbuffer_s *init_event_buffer(void) -{ - sem_init(&g_cbtablelock, 0, 1); - return evtbuffer_init(); -} - -/**************************************************************************** - * Name: alt1250_evtdatadestroy - ****************************************************************************/ - -int alt1250_evtdatadestroy(void) -{ - sem_destroy(&g_cbtablelock); - - return 0; -} - -/**************************************************************************** - * Name: alt1250_regevtcb - ****************************************************************************/ - -int alt1250_regevtcb(uint32_t cmdid, FAR void *cb) -{ - int ret; - - sem_wait(&g_cbtablelock); - - if (cb == NULL) - { - ret = clear_evtcb(cmdid); - } - else - { - ret = register_evtcb(cmdid, cb); - } - - sem_post(&g_cbtablelock); - - return ret; -} - -/**************************************************************************** - * Name: alt1250_execcb - ****************************************************************************/ - -void alt1250_execcb(uint64_t evtbitmap) -{ - uint64_t l_evtbitmap = 0ULL; - - if (evtbitmap & ALT1250_EVTBIT_RESET) - { - /* call LTE_CMDID_SETRESTART */ - - alt1250_search_execcb(alt1250_evt_search(LTE_CMDID_SETRESTART)); - - update_evtarg_writableall(); - } - else - { - l_evtbitmap = alt1250_search_execcb(evtbitmap); - - if (l_evtbitmap != 0ULL) - { - alt1250_search_execcb(l_evtbitmap); - } - } -} - -/**************************************************************************** - * Name: alt1250_getevtarg - ****************************************************************************/ - -FAR void **alt1250_getevtarg(uint32_t cmdid) -{ - int i; - - for (i = 0; i < nitems(g_evtbuffers); i++) - { - if (g_evtbuffers[i].cmdid == cmdid) - { - return g_evtbuffers[i].outparam; - } - } - - return NULL; -} - -/**************************************************************************** - * Name: alt1250_checkcmdid - ****************************************************************************/ - -bool alt1250_checkcmdid(uint32_t cmdid, uint64_t evtbitmap, - FAR uint64_t *bit) -{ - int idx; - bool ret = false; - - for (idx = 0; idx < nitems(g_evtbuffers); idx++) - { - if (evtbitmap & (1ULL << idx)) - { - dbg_alt1250("idx=%d\n", idx); - - if (g_evtbuffers[idx].cmdid == cmdid) - { - ret = true; - *bit = 1ULL << idx; - break; - } - } - } - - return ret; -} - -/**************************************************************************** - * Name: alt1250_setevtarg_writable - ****************************************************************************/ - -void alt1250_setevtarg_writable(uint32_t cmdid) -{ - int idx; - FAR alt_evtbuf_inst_t *inst = NULL; - - for (idx = 0; idx < nitems(g_evtbuffers); idx++) - { - if (g_evtbuffers[idx].cmdid == cmdid) - { - inst = &g_evtbuffers[idx]; - - nxmutex_lock(&inst->stat_lock); - - inst->stat = ALTEVTBUF_ST_WRITABLE; - - nxmutex_unlock(&inst->stat_lock); - - break; - } - } -} - -/**************************************************************************** - * Name: alt1250_clrevtcb - ****************************************************************************/ - -int alt1250_clrevtcb(uint8_t mode) -{ - int ret = OK; - int i; - - sem_wait(&g_cbtablelock); - - if (mode == ALT1250_CLRMODE_WO_RESTART) - { - for (i = 0; i < nitems(g_cbtable); i++) - { - if (g_cbtable[i].cmdid != LTE_CMDID_SETRESTART) - { - g_cbtable[i].cb = NULL; - g_cbtable[i].cmdid = 0; - } - } - } - else if (mode == ALT1250_CLRMODE_ALL) - { - memset(g_cbtable, 0, sizeof(struct cbinfo_s) * NCBTABLES); - } - else - { - ret = -EINVAL; - } - - sem_post(&g_cbtablelock); - - return ret; -} - -#ifdef CONFIG_LTE_ALT1250_LAUNCH_EVENT_TASK -static int internal_evttask(int argc, FAR char *argv[]) -{ - int ret; - bool is_running = true; - - ret = lapi_evtinit(LAPIEVT_QNAME); - if (ret < 0) - { - dbg_alt1250("lapi_evtinit() failed: %d\n", ret); - goto errout; - } - - while (is_running) - { - ret = lapi_evtyield(-1); - if (ret == 0) - { - dbg_alt1250("lapi_evtyield() finish normaly\n"); - is_running = false; - } - else if (ret < 0) - { - dbg_alt1250("lapi_evtyield() failed: %d\n", ret); - } - } - -errout: - lapi_evtdestoy(); - - return 0; -} -#endif - -static int evt_qsend(FAR mqd_t *mqd, uint64_t evtbitmap) -{ - int ret = ERROR; - - if (*mqd != (mqd_t)-1) - { - ret = mq_send(*mqd, (FAR const char *)&evtbitmap, sizeof(evtbitmap), - 0); - if (ret < 0) - { - ret = -errno; - dbg_alt1250("failed to send mq: %d\n", errno); - } - } - - return ret; -} - -int alt1250_evttask_sendmsg(FAR struct alt1250_s *dev, uint64_t msg) -{ - return evt_qsend(&dev->evtq, msg); -} - -int alt1250_evttask_start(void) -{ -#ifdef CONFIG_LTE_ALT1250_LAUNCH_EVENT_TASK - g_cbpid = task_create(EVTTASK_NAME, CONFIG_LTE_ALT1250_EVENT_TASK_PRIORITY, - CONFIG_LTE_ALT1250_EVENT_TASK_STACKSIZE, - internal_evttask, NULL); - return g_cbpid; -#else - return 1; /* Always success */ -#endif -} - -void alt1250_evttask_stop(FAR struct alt1250_s *dev) -{ - if (alt1250_evttask_sendmsg(dev, 0ULL) == OK) - { -#ifdef CONFIG_LTE_ALT1250_LAUNCH_EVENT_TASK - int stat; - - waitpid(g_cbpid, &stat, WEXITED); -#endif - } - - alt1250_evttask_msgclose(dev); -} - -void alt1250_evttask_msgclose(FAR struct alt1250_s *dev) -{ - if (dev->evtq != (mqd_t)-1) - { - /* FIXME: In case of the event callback task is not launched yet, - * this message may be dropped. - * Now, above behavior is not rescued.. - */ - - mq_close(dev->evtq); - mq_unlink(LAPIEVT_QNAME); - } -} - -int alt1250_evttask_msgconnect(FAR const char *qname, - FAR struct alt1250_s *dev) -{ - int ret = OK; - - alt1250_evttask_msgclose(dev); - - dev->evtq = mq_open(qname, O_WRONLY); - if (dev->evtq == (mqd_t)-1) - { - ret = -errno; - dbg_alt1250("failed to open mq(%s): %d\n", qname, errno); - } - - return ret; -} - -uint32_t alt1250_search_registered_callback(FAR int *index) -{ - uint32_t ret = 0x00; - int i; - - for (i = *index; i < NCBTABLES; i++) - { - if (g_cbtable[i].cb != NULL && IS_LTE_REPORT_EVENT(g_cbtable[i].cmdid)) - { - ret = g_cbtable[i].cmdid; - *index = i; - break; - } - } - - return ret; -} - -int alt1250_get_report_ltecmd(FAR struct alt1250_s *dev, uint32_t cmdid, - FAR struct lte_ioctl_data_s *ltecmd) -{ - int ret = OK; - static int result; - static int32_t param; - static FAR void *inparam[2]; - static FAR void *outparam[1]; - - /* Generate ltecmd: - * cmdid : LAPI command ID - * inparam : Array of input arguments - * (First argument is callback pointer.) - * inparamlen : Size of inparam array - * outparam : Array of output arguments - * (The result parameter only.) - * outparamlen: Size of outparam array - */ - - ltecmd->cmdid = cmdid; - ltecmd->inparam = inparam; - ltecmd->outparam = outparam; - ltecmd->outparamlen = 1; - - inparam[0] = get_cbfunc(cmdid); - outparam[0] = (FAR void *)&result; - - switch (cmdid) - { - case LTE_CMDID_REPNETINFO: - ltecmd->inparamlen = 1; - break; - case LTE_CMDID_REPSIMSTAT: - param = cmdid; - inparam[1] = (FAR void *)¶m; - ltecmd->inparamlen = 2; - break; - case LTE_CMDID_REPLTIME: - param = cmdid; - inparam[1] = (FAR void *)¶m; - ltecmd->inparamlen = 2; - break; - case LTE_CMDID_REPQUAL: - param = dev->quality_report_period; - inparam[1] = (FAR void *)¶m; - ltecmd->inparamlen = 2; - break; - case LTE_CMDID_REPCELL: - param = dev->cellinfo_report_period; - inparam[1] = (FAR void *)¶m; - ltecmd->inparamlen = 2; - break; - default: - ret = -EINVAL; - break; - } - - return ret; -} diff --git a/lte/alt1250/callback_handlers/alt1250_evt.h b/lte/alt1250/callback_handlers/alt1250_evt.h deleted file mode 100644 index 9df097fe8..000000000 --- a/lte/alt1250/callback_handlers/alt1250_evt.h +++ /dev/null @@ -1,75 +0,0 @@ -/**************************************************************************** - * apps/lte/alt1250/callback_handlers/alt1250_evt.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __APPS_LTE_ALT1250_CALLBACK_HANDLERS_ALT1250_EVT_H -#define __APPS_LTE_ALT1250_CALLBACK_HANDLERS_ALT1250_EVT_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "alt1250_daemon.h" -#include "alt1250_util.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* Represents when to clear the callback function */ - -/* Clear callbacks at all */ - -#define ALT1250_CLRMODE_ALL (0) - -/* Clear callbacks without restart callback */ - -#define ALT1250_CLRMODE_WO_RESTART (1) - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -FAR struct alt_evtbuffer_s *init_event_buffer(void); -int alt1250_evtdatadestroy(void); -int alt1250_regevtcb(uint32_t id, FAR void *cb); -void alt1250_execcb(uint64_t evtbitmap); -FAR void **alt1250_getevtarg(uint32_t cmdid); -bool alt1250_checkcmdid(uint32_t cmdid, uint64_t evtbitmap, - FAR uint64_t *bit); -void alt1250_setevtarg_writable(uint32_t cmdid); -int alt1250_clrevtcb(uint8_t mode); - -int alt1250_evttask_start(void); -void alt1250_evttask_stop(FAR struct alt1250_s *dev); -int alt1250_evttask_sendmsg(FAR struct alt1250_s *dev, uint64_t msg); -void alt1250_evttask_msgclose(FAR struct alt1250_s *dev); -int alt1250_evttask_msgconnect(FAR const char *qname, - FAR struct alt1250_s *dev); -uint32_t alt1250_search_registered_callback(FAR int *index); -int alt1250_get_report_ltecmd(FAR struct alt1250_s *dev, uint32_t cmdid, - FAR struct lte_ioctl_data_s *ltecmd); - -#endif /* __APPS_LTE_ALT1250_CALLBACK_HANDLERS_ALT1250_EVT_H */ diff --git a/lte/alt1250/usock_handlers/alt1250_accepthdlr.c b/lte/alt1250/usock_handlers/alt1250_accepthdlr.c deleted file mode 100644 index 4151425d8..000000000 --- a/lte/alt1250/usock_handlers/alt1250_accepthdlr.c +++ /dev/null @@ -1,257 +0,0 @@ -/**************************************************************************** - * apps/lte/alt1250/usock_handlers/alt1250_accepthdlr.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -#include "alt1250_dbg.h" -#include "alt1250_container.h" -#include "alt1250_devif.h" -#include "alt1250_socket.h" -#include "alt1250_usrsock_hdlr.h" -#include "alt1250_usockevent.h" -#include "alt1250_postproc.h" - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * name: postproc_accepterr - ****************************************************************************/ - -static int postproc_accepterr(FAR struct alt1250_s *dev, - FAR struct alt_container_s *reply, - FAR struct usock_s *usock, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo, - unsigned long arg) -{ - int ret = REP_SEND_ACK; - - dbg_alt1250("%s start\n", __func__); - - /* resp[0]: ret code - * resp[1]: error code - */ - - *usock_xid = USOCKET_XID(usock); - *usock_result = -EBUSY; - - return ret; -} - -/**************************************************************************** - * name: send_close_command - ****************************************************************************/ - -static int send_close_command(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - FAR struct usock_s *usock, - int altsock, - FAR int32_t *usock_result) -{ - int idx = 0; - FAR void *inparam[1]; - - /* This member is referenced only when sending a command and - * not when receiving a response, so local variable is used. - */ - - inparam[0] = &altsock; - - USOCKET_SET_RESPONSE(usock, idx++, USOCKET_REP_RESULT(usock)); - USOCKET_SET_RESPONSE(usock, idx++, USOCKET_REP_ERRCODE(usock)); - - set_container_ids(container, USOCKET_USOCKID(usock), LTE_CMDID_CLOSE); - set_container_argument(container, inparam, nitems(inparam)); - set_container_response(container, USOCKET_REP_RESPONSE(usock), idx); - set_container_postproc(container, postproc_accepterr, 0); - - return altdevice_send_command(dev, dev->altfd, container, usock_result); -} - -/**************************************************************************** - * name: postproc_accept - ****************************************************************************/ - -static int postproc_accept(FAR struct alt1250_s *dev, - FAR struct alt_container_s *reply, - FAR struct usock_s *usock, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo, - unsigned long arg) -{ - int ret = REP_SEND_ACK; - int altsock_res; - FAR struct usock_s *accept_sock; - FAR void **resp = CONTAINER_RESPONSE(reply); - - dbg_alt1250("%s start\n", __func__); - - /* resp[0]: socket fd - * resp[1]: error code - * resp[2]: addrlen - * resp[3]: accepted address - */ - - altsock_res = COMBINE_ERRCODE(*(int *)(resp[0]), *(int *)(resp[1])); - if (altsock_res >= 0) - { - USOCKET_SET_SELECTABLE(usock, SELECT_READABLE); - - accept_sock = usocket_alloc(dev, USOCKET_TYPE(usock)); - if (!accept_sock) - { - ret = send_close_command(dev, reply, usock, altsock_res, - usock_result); - *usock_xid = USOCKET_XID(usock); - } - else - { - USOCKET_SET_ALTSOCKID(accept_sock, altsock_res); - USOCKET_SET_STATE(accept_sock, SOCKET_STATE_CONNECTED); - - *usock_result = sizeof(uint16_t); - *usock_xid = USOCKET_XID(usock); - - ackinfo->valuelen = MIN(USOCKET_REQADDRLEN(usock), - *(uint16_t *)(resp[2])); - ackinfo->valuelen_nontrunc = *(uint16_t *)(resp[2]); - ackinfo->value_ptr = resp[3]; - ackinfo->buf_ptr = (FAR uint8_t *)&USOCKET_USOCKID(accept_sock); - - ret = REP_SEND_DACK; - } - - usocket_commitstate(dev); - } - else - { - *usock_result = altsock_res; - *usock_xid = USOCKET_XID(usock); - } - - return ret; -} - -/**************************************************************************** - * name: send_accept_command - ****************************************************************************/ - -static int send_accept_command(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - FAR struct usock_s *usock, - uint16_t addrlen, - FAR int32_t *usock_result) -{ - int idx = 0; - FAR void *inparam[2]; - - /* These members are referenced only when sending a command and - * not when receiving a response, so local variables are used. - */ - - inparam[0] = &USOCKET_ALTSOCKID(usock); - inparam[1] = &addrlen; - - USOCKET_SET_RESPONSE(usock, idx++, USOCKET_REP_RESULT(usock)); - USOCKET_SET_RESPONSE(usock, idx++, USOCKET_REP_ERRCODE(usock)); - USOCKET_SET_RESPONSE(usock, idx++, USOCKET_REP_ADDRLEN(usock)); - USOCKET_SET_RESPONSE(usock, idx++, USOCKET_REP_ADDR(usock)); - - set_container_ids(container, USOCKET_USOCKID(usock), LTE_CMDID_ACCEPT); - set_container_argument(container, inparam, nitems(inparam)); - set_container_response(container, USOCKET_REP_RESPONSE(usock), idx); - set_container_postproc(container, postproc_accept, 0); - - return altdevice_send_command(dev, dev->altfd, container, usock_result); -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * name: usockreq_accept - ****************************************************************************/ - -int usockreq_accept(FAR struct alt1250_s *dev, - FAR struct usrsock_request_buff_s *req, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo) -{ - FAR struct usrsock_request_accept_s *request = &req->request.accept_req; - FAR struct usock_s *usock; - FAR struct alt_container_s *container; - int ret = REP_SEND_ACK_WOFREE; - socklen_t addrlen; - - dbg_alt1250("%s start\n", __func__); - - *usock_result = OK; - *usock_xid = request->head.xid; - - usock = usocket_search(dev, request->usockid); - if (usock == NULL) - { - dbg_alt1250("Failed to get socket context: %u\n", - request->usockid); - *usock_result = -EBADFD; - return REP_SEND_ACK_WOFREE; - } - - USOCKET_SET_REQUEST(usock, request->head.reqid, request->head.xid); - USOCKET_SET_REQADDRLEN(usock, request->max_addrlen); - - container = container_alloc(); - if (container == NULL) - { - dbg_alt1250("no container\n"); - return REP_NO_CONTAINER; - } - - if (USOCKET_DOMAIN(usock) == AF_INET) - { - addrlen = sizeof(struct sockaddr_in); - } - else - { - addrlen = sizeof(struct sockaddr_in6); - } - - ret = send_accept_command(dev, container, usock, addrlen, usock_result); - - if (IS_NEED_CONTAINER_FREE(ret)) - { - container_free(container); - } - - return ret; -} diff --git a/lte/alt1250/usock_handlers/alt1250_bindhdlr.c b/lte/alt1250/usock_handlers/alt1250_bindhdlr.c deleted file mode 100644 index 85a12b0ee..000000000 --- a/lte/alt1250/usock_handlers/alt1250_bindhdlr.c +++ /dev/null @@ -1,186 +0,0 @@ -/**************************************************************************** - * apps/lte/alt1250/usock_handlers/alt1250_bindhdlr.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -#include "alt1250_dbg.h" -#include "alt1250_container.h" -#include "alt1250_socket.h" -#include "alt1250_devif.h" -#include "alt1250_usockevent.h" -#include "alt1250_postproc.h" -#include "alt1250_usrsock_hdlr.h" - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * name: send_bind_command - ****************************************************************************/ - -static int send_bind_command(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - FAR struct usock_s *usock, - FAR int32_t *usock_result) -{ - int idx = 0; - FAR void *inparam[3]; - - /* These members are referenced only when sending a command and - * not when receiving a response, so local variables are used. - */ - - inparam[0] = &USOCKET_ALTSOCKID(usock); - inparam[1] = &USOCKET_REQADDRLEN(usock); - inparam[2] = &USOCKET_REQADDR(usock); - - USOCKET_SET_RESPONSE(usock, idx++, USOCKET_REP_RESULT(usock)); - USOCKET_SET_RESPONSE(usock, idx++, USOCKET_REP_ERRCODE(usock)); - - set_container_ids(container, USOCKET_USOCKID(usock), LTE_CMDID_BIND); - set_container_argument(container, inparam, nitems(inparam)); - set_container_response(container, USOCKET_REP_RESPONSE(usock), idx); - set_container_postproc(container, postproc_sockcommon, 0); - - return altdevice_send_command(dev, dev->altfd, container, usock_result); -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * name: nextstep_bind - ****************************************************************************/ - -int nextstep_bind(FAR struct alt1250_s *dev, - FAR struct alt_container_s *reply, - FAR struct usock_s *usock, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo, - unsigned long arg) -{ - dbg_alt1250("%s start\n", __func__); - - return send_bind_command(dev, reply, usock, usock_result); -} - -/**************************************************************************** - * name: usockreq_bind - ****************************************************************************/ - -int usockreq_bind(FAR struct alt1250_s *dev, - FAR struct usrsock_request_buff_s *req, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo) -{ - FAR struct usrsock_request_bind_s *request = &req->request.bind_req; - FAR struct usock_s *usock; - FAR struct alt_container_s *container; - int ret = REP_SEND_ACK_WOFREE; - - dbg_alt1250("%s start\n", __func__); - - *usock_result = OK; - *usock_xid = request->head.xid; - - usock = usocket_search(dev, request->usockid); - if (usock == NULL) - { - dbg_alt1250("Failed to get socket context: %u\n", - request->usockid); - *usock_result = -EBADFD; - return REP_SEND_ACK_WOFREE; - } - - USOCKET_SET_REQUEST(usock, request->head.reqid, request->head.xid); - USOCKET_SET_REQADDRLEN(usock, request->addrlen); - - switch (USOCKET_STATE(usock)) - { - case SOCKET_STATE_CLOSED: - case SOCKET_STATE_CLOSING: - dbg_alt1250("Unexpected state: %d\n", USOCKET_STATE(usock)); - *usock_result = -EBADFD; - ret = REP_SEND_ACK_WOFREE; - break; - - case SOCKET_STATE_PREALLOC: - container = container_alloc(); - if (container == NULL) - { - dbg_alt1250("no container\n"); - return REP_NO_CONTAINER; - } - - *usock_result = usockif_readreqaddr(dev->usockfd, - &USOCKET_REQADDR(usock), - USOCKET_REQADDRLEN(usock)); - if (*usock_result < 0) - { - container_free(container); - return REP_SEND_ACK; - } - - ret = open_altsocket(dev, container, usock, usock_result); - if (IS_NEED_CONTAINER_FREE(ret)) - { - container_free(container); - } - break; - - default: - container = container_alloc(); - if (container == NULL) - { - dbg_alt1250("no container\n"); - return REP_NO_CONTAINER; - } - - *usock_result = usockif_readreqaddr(dev->usockfd, - &USOCKET_REQADDR(usock), - USOCKET_REQADDRLEN(usock)); - if (*usock_result < 0) - { - container_free(container); - return REP_SEND_ACK; - } - - ret = nextstep_bind(dev, container, usock, usock_result, usock_xid, - ackinfo, 0); - if (IS_NEED_CONTAINER_FREE(ret)) - { - container_free(container); - } - break; - } - - return ret; -} diff --git a/lte/alt1250/usock_handlers/alt1250_closehdlr.c b/lte/alt1250/usock_handlers/alt1250_closehdlr.c deleted file mode 100644 index 6391046df..000000000 --- a/lte/alt1250/usock_handlers/alt1250_closehdlr.c +++ /dev/null @@ -1,201 +0,0 @@ -/**************************************************************************** - * apps/lte/alt1250/usock_handlers/alt1250_closehdlr.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -#include "alt1250_dbg.h" -#include "alt1250_container.h" -#include "alt1250_socket.h" -#include "alt1250_devif.h" -#include "alt1250_usockevent.h" -#include "alt1250_postproc.h" -#include "alt1250_usrsock_hdlr.h" - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * name: send_close_command - ****************************************************************************/ - -static int send_close_command(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - FAR struct usock_s *usock, - FAR int32_t *usock_result) -{ - int idx = 0; - FAR void *inparam[1]; - - /* This member is referenced only when sending a command and - * not when receiving a response, so local variable is used. - */ - - inparam[0] = &USOCKET_ALTSOCKID(usock); - - USOCKET_SET_RESPONSE(usock, idx++, USOCKET_REP_RESULT(usock)); - USOCKET_SET_RESPONSE(usock, idx++, USOCKET_REP_ERRCODE(usock)); - - set_container_ids(container, USOCKET_USOCKID(usock), LTE_CMDID_CLOSE); - set_container_argument(container, inparam, nitems(inparam)); - set_container_response(container, USOCKET_REP_RESPONSE(usock), idx); - set_container_postproc(container, postproc_sockcommon, 0); - - return altdevice_send_command(dev, dev->altfd, container, usock_result); -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * name: postproc_sockcommon - ****************************************************************************/ - -int postproc_sockcommon(FAR struct alt1250_s *dev, - FAR struct alt_container_s *reply, - FAR struct usock_s *usock, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo, - unsigned long arg) -{ - int ret = REP_SEND_ACK; - FAR void **resp = CONTAINER_RESPONSE(reply); - - dbg_alt1250("%s start\n", __func__); - - /* resp[0]: ret code - * resp[1]: error code - */ - - *usock_xid = USOCKET_XID(usock); - *usock_result = COMBINE_ERRCODE(*(FAR int *)resp[0], *(FAR int *)resp[1]); - - switch (USOCKET_REQID(usock)) - { - case USRSOCK_REQUEST_SENDTO: - { - USOCKET_SET_SELECTABLE(usock, SELECT_WRITABLE); - usocket_commitstate(dev); - } - break; - - case USRSOCK_REQUEST_CLOSE: - { - usocket_free(usock); - } - break; - - default: - break; - } - - return ret; -} - -/**************************************************************************** - * name: usockreq_close - ****************************************************************************/ - -int usockreq_close(FAR struct alt1250_s *dev, - FAR struct usrsock_request_buff_s *req, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo) -{ - FAR struct usrsock_request_close_s *request = - &req->request.close_req; - FAR struct usock_s *usock; - FAR struct alt_container_s *container; - int ret = REP_SEND_ACK_WOFREE; - - dbg_alt1250("%s start\n", __func__); - - *usock_result = OK; - *usock_xid = request->head.xid; - - usock = usocket_search(dev, request->usockid); - if (usock == NULL) - { - dbg_alt1250("Failed to get socket context: %u\n", - request->usockid); - *usock_result = -EBADFD; - return REP_SEND_ACK_WOFREE; - } - - USOCKET_SET_REQUEST(usock, request->head.reqid, request->head.xid); - - if (IS_SMS_SOCKET(usock)) - { - ret = alt1250_sms_fin(dev, usock, usock_result); - } - else - { - switch (USOCKET_STATE(usock)) - { - case SOCKET_STATE_CLOSED: - case SOCKET_STATE_CLOSING: - dbg_alt1250("Unexpected state: %d\n", USOCKET_STATE(usock)); - *usock_result = -EBADFD; - ret = REP_SEND_ACK_WOFREE; - break; - - case SOCKET_STATE_PREALLOC: - usocket_free(usock); - ret = REP_SEND_ACK_WOFREE; - break; - - default: - container = container_alloc(); - if (container == NULL) - { - dbg_alt1250("no container\n"); - return REP_NO_CONTAINER; - } - - USOCKET_SET_STATE(usock, SOCKET_STATE_CLOSING); - usocket_commitstate(dev); - - ret = send_close_command(dev, container, usock, usock_result); - - if (IS_NEED_CONTAINER_FREE(ret)) - { - container_free(container); - } - - if (*usock_result < 0) - { - usocket_free(usock); - } - - break; - } - } - - return ret; -} diff --git a/lte/alt1250/usock_handlers/alt1250_connecthdlr.c b/lte/alt1250/usock_handlers/alt1250_connecthdlr.c deleted file mode 100644 index cad728ab3..000000000 --- a/lte/alt1250/usock_handlers/alt1250_connecthdlr.c +++ /dev/null @@ -1,344 +0,0 @@ -/**************************************************************************** - * apps/lte/alt1250/usock_handlers/alt1250_connecthdlr.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -#include "alt1250_dbg.h" -#include "alt1250_container.h" -#include "alt1250_socket.h" -#include "alt1250_devif.h" -#include "alt1250_usockevent.h" -#include "alt1250_postproc.h" -#include "alt1250_usrsock_hdlr.h" - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static int16_t g_request_level = SOL_SOCKET; -static int16_t g_request_option = SO_ERROR; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * name: postproc_connect - ****************************************************************************/ - -static int postproc_getsockopt(FAR struct alt1250_s *dev, - FAR struct alt_container_s *reply, - FAR struct usock_s *usock, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo, - unsigned long arg) -{ - int ret = REP_SEND_ACK; - FAR void **resp = CONTAINER_RESPONSE(reply); - - dbg_alt1250("%s start\n", __func__); - - /* resp[0]: ret code - * resp[1]: error code - * resp[2]: optlen - * resp[3]: optval - */ - - *usock_xid = USOCKET_XID(usock); - *usock_result = COMBINE_ERRCODE(*(FAR int *)resp[0], *(FAR int *)resp[1]); - - if (*usock_result >= 0) - { - *usock_result = *(FAR int32_t *)(resp[3]); - *usock_xid = USOCKET_XID(usock); - - dbg_alt1250("connect result = %d\n", *usock_result); - - if (*usock_result > 0) - { - *usock_result = -(*usock_result); - } - - if (*usock_result == 0) - { - USOCKET_SET_STATE(usock, SOCKET_STATE_CONNECTED); - } - else - { - USOCKET_SET_STATE(usock, SOCKET_STATE_OPENED); - } - } - else - { - USOCKET_SET_STATE(usock, SOCKET_STATE_OPENED); - } - - USOCKET_SET_SELECTABLE(usock, SELECT_WRITABLE); - usocket_commitstate(dev); - - return ret; -} - -/**************************************************************************** - * name: postproc_connect - ****************************************************************************/ - -static int postproc_connect(FAR struct alt1250_s *dev, - FAR struct alt_container_s *reply, - FAR struct usock_s *usock, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo, - unsigned long arg) -{ - int ret = REP_SEND_ACK; - FAR void **resp = CONTAINER_RESPONSE(reply); - - dbg_alt1250("%s start\n", __func__); - - /* resp[0]: ret code - * resp[1]: error code - */ - - *usock_xid = USOCKET_XID(usock); - *usock_result = COMBINE_ERRCODE(*(FAR int *)resp[0], *(FAR int *)resp[1]); - - dbg_alt1250("%s connect result:%d\n", __func__, *usock_result); - - if (*usock_result >= 0) - { - USOCKET_SET_STATE(usock, SOCKET_STATE_CONNECTED); - } - else if (*usock_result == -EINPROGRESS) - { - USOCKET_SET_STATE(usock, SOCKET_STATE_WAITCONN); - ret = REP_NO_ACK; - } - else - { - USOCKET_SET_STATE(usock, SOCKET_STATE_OPENED); - } - - usocket_commitstate(dev); - - return ret; -} - -/**************************************************************************** - * name: send_connect_command - ****************************************************************************/ - -static int send_connect_command(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - FAR struct usock_s *usock, - FAR int32_t *usock_result) -{ - int idx = 0; - FAR void *inparam[3]; - - /* These members are referenced only when sending a command and - * not when receiving a response, so local variables are used. - */ - - inparam[0] = &USOCKET_ALTSOCKID(usock); - inparam[1] = &USOCKET_REQADDRLEN(usock); - inparam[2] = &USOCKET_REQADDR(usock); - - USOCKET_SET_RESPONSE(usock, idx++, USOCKET_REP_RESULT(usock)); - USOCKET_SET_RESPONSE(usock, idx++, USOCKET_REP_ERRCODE(usock)); - - set_container_ids(container, USOCKET_USOCKID(usock), LTE_CMDID_CONNECT); - set_container_argument(container, inparam, nitems(inparam)); - set_container_response(container, USOCKET_REP_RESPONSE(usock), idx); - set_container_postproc(container, postproc_connect, 0); - - return altdevice_send_command(dev, dev->altfd, container, usock_result); -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * name: nextstep_check_connectres - ****************************************************************************/ - -int nextstep_check_connectres(FAR struct alt1250_s *dev, - FAR struct usock_s *usock) -{ - int ret = REP_NO_CONTAINER; - int32_t usock_result; - FAR struct alt_container_s *container; - - dbg_alt1250("%s start\n", __func__); - - container = container_alloc(); - if (container != NULL) - { - ret = send_getsockopt_command(dev, container, usock, - g_request_level, g_request_option, - sizeof(int), &g_request_level, - &g_request_option, postproc_getsockopt, - 0, &usock_result); - } - else - { - /* If there is no container, the state is not - * updated. This guarantees that a select request - * will be sent. When the response is received, - * it can try to acquire a container. There is a - * possibility that the container is free at that - * timing. - */ - - dbg_alt1250("no container\n"); - } - - return ret; -} - -/**************************************************************************** - * name: nextstep_connect - ****************************************************************************/ - -int nextstep_connect(FAR struct alt1250_s *dev, - FAR struct alt_container_s *reply, - FAR struct usock_s *usock, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo, - unsigned long arg) -{ - int ret = REP_SEND_ACK; - - dbg_alt1250("%s start\n", __func__); - - ret = send_connect_command(dev, reply, usock, usock_result); - - if (*usock_result >= 0) - { - USOCKET_SET_STATE(usock, SOCKET_STATE_CONNECTING); - usocket_commitstate(dev); - } - - return ret; -} - -/**************************************************************************** - * usockreq_connect - ****************************************************************************/ - -int usockreq_connect(FAR struct alt1250_s *dev, - FAR struct usrsock_request_buff_s *req, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo) -{ - FAR struct usrsock_request_connect_s *request = &req->request.conn_req; - FAR struct usock_s *usock; - FAR struct alt_container_s *container; - int ret = REP_SEND_ACK_WOFREE; - - dbg_alt1250("%s start\n", __func__); - - *usock_result = OK; - *usock_xid = request->head.xid; - - usock = usocket_search(dev, request->usockid); - if (usock == NULL) - { - dbg_alt1250("Failed to get socket context: %u\n", - request->usockid); - *usock_result = -EBADFD; - return REP_SEND_ACK_WOFREE; - } - - USOCKET_SET_REQUEST(usock, request->head.reqid, request->head.xid); - USOCKET_SET_REQADDRLEN(usock, request->addrlen); - - switch (USOCKET_STATE(usock)) - { - case SOCKET_STATE_CLOSED: - case SOCKET_STATE_CLOSING: - dbg_alt1250("Unexpected state: %d\n", USOCKET_STATE(usock)); - *usock_result = -EBADFD; - ret = REP_SEND_ACK_WOFREE; - break; - - case SOCKET_STATE_PREALLOC: - container = container_alloc(); - if (container == NULL) - { - dbg_alt1250("no container\n"); - return REP_NO_CONTAINER; - } - - *usock_result = usockif_readreqaddr(dev->usockfd, - &USOCKET_REQADDR(usock), - USOCKET_REQADDRLEN(usock)); - if (*usock_result < 0) - { - container_free(container); - return REP_SEND_ACK; - } - - ret = open_altsocket(dev, container, usock, usock_result); - if (IS_NEED_CONTAINER_FREE(ret)) - { - container_free(container); - } - break; - - default: - container = container_alloc(); - if (container == NULL) - { - dbg_alt1250("no container\n"); - return REP_NO_CONTAINER; - } - - *usock_result = usockif_readreqaddr(dev->usockfd, - &USOCKET_REQADDR(usock), - USOCKET_REQADDRLEN(usock)); - if (*usock_result < 0) - { - container_free(container); - return REP_SEND_ACK; - } - - ret = nextstep_connect(dev, container, usock, usock_result, - usock_xid, ackinfo, 0); - if (IS_NEED_CONTAINER_FREE(ret)) - { - container_free(container); - } - break; - } - - return ret; -} diff --git a/lte/alt1250/usock_handlers/alt1250_fwupdate.h b/lte/alt1250/usock_handlers/alt1250_fwupdate.h deleted file mode 100644 index 38281cdc0..000000000 --- a/lte/alt1250/usock_handlers/alt1250_fwupdate.h +++ /dev/null @@ -1,61 +0,0 @@ -/**************************************************************************** - * apps/lte/alt1250/usock_handlers/alt1250_fwupdate.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __APPS_LTE_ALT1250_USOCK_HANDLERS_ALT1250_FWUPDATE_H -#define __APPS_LTE_ALT1250_USOCK_HANDLERS_ALT1250_FWUPDATE_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define LTE_IMAGE_PERT_SIZE (256) - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -struct delta_header_s -{ - uint32_t chunk_code; - uint32_t reserved; - char np_package[LTE_VER_NP_PACKAGE_LEN]; - uint32_t pert_crc; - uint32_t hdr_crc; -}; - -struct update_info_s -{ - int hdr_injected; - int act_injected; - - struct delta_header_s hdr; - char img_pert[LTE_IMAGE_PERT_SIZE]; -}; - -#endif /* __APPS_LTE_ALT1250_USOCK_HANDLERS_ALT1250_FWUPDATE_H */ diff --git a/lte/alt1250/usock_handlers/alt1250_getpeernamehdlr.c b/lte/alt1250/usock_handlers/alt1250_getpeernamehdlr.c deleted file mode 100644 index 5374b06c8..000000000 --- a/lte/alt1250/usock_handlers/alt1250_getpeernamehdlr.c +++ /dev/null @@ -1,61 +0,0 @@ -/**************************************************************************** - * apps/lte/alt1250/usock_handlers/alt1250_getpeernamehdlr.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -#include "alt1250_dbg.h" -#include "alt1250_container.h" -#include "alt1250_socket.h" -#include "alt1250_usockevent.h" -#include "alt1250_postproc.h" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * name: usockreq_getpeername - ****************************************************************************/ - -int usockreq_getpeername(FAR struct alt1250_s *dev, - FAR struct usrsock_request_buff_s *req, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo) -{ - FAR struct usrsock_request_getpeername_s *request = - &req->request.pname_req; - - dbg_alt1250("%s start\n", __func__); - - /* Not support */ - - *usock_result = -ENOTSUP; - *usock_xid = request->head.xid; - - return REP_SEND_ACK_WOFREE; -} diff --git a/lte/alt1250/usock_handlers/alt1250_getsocknamehdlr.c b/lte/alt1250/usock_handlers/alt1250_getsocknamehdlr.c deleted file mode 100644 index 23350cf1a..000000000 --- a/lte/alt1250/usock_handlers/alt1250_getsocknamehdlr.c +++ /dev/null @@ -1,229 +0,0 @@ -/**************************************************************************** - * apps/lte/alt1250/usock_handlers/alt1250_getsocknamehdlr.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -#include "alt1250_dbg.h" -#include "alt1250_container.h" -#include "alt1250_socket.h" -#include "alt1250_devif.h" -#include "alt1250_usockevent.h" -#include "alt1250_postproc.h" -#include "alt1250_usrsock_hdlr.h" - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * name: postproc_getsockname - ****************************************************************************/ - -static int postproc_getsockname(FAR struct alt1250_s *dev, - FAR struct alt_container_s *reply, - FAR struct usock_s *usock, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo, - unsigned long arg) -{ - int ret = REP_SEND_ACK; - FAR void **resp = CONTAINER_RESPONSE(reply); - - dbg_alt1250("%s start\n", __func__); - - /* resp[0]: ret code - * resp[1]: error code - * resp[2]: addrlen - * resp[3]: address - */ - - *usock_xid = USOCKET_XID(usock); - *usock_result = COMBINE_ERRCODE(*(FAR int *)resp[0], *(FAR int *)resp[1]); - - if (*usock_result >= 0) - { - *usock_result = 0; - *usock_xid = USOCKET_XID(usock); - - ackinfo->valuelen = MIN(USOCKET_REQADDRLEN(usock), - *(FAR uint16_t *)(resp[2])); - ackinfo->valuelen_nontrunc = *(FAR uint16_t *)(resp[2]); - ackinfo->value_ptr = resp[3]; - ackinfo->buf_ptr = NULL; - - if (ackinfo->valuelen != 0) - { - ret = REP_SEND_DACK; - } - } - - return ret; -} - -/**************************************************************************** - * name: send_getsockname_command - ****************************************************************************/ - -static int send_getsockname_command(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - FAR struct usock_s *usock, - uint16_t addrlen, - FAR int32_t *usock_result) -{ - int idx = 0; - FAR void *inparam[2]; - - /* These members are referenced only when sending a command and - * not when receiving a response, so local variables are used. - */ - - inparam[0] = &USOCKET_ALTSOCKID(usock); - inparam[1] = &addrlen; - - USOCKET_SET_RESPONSE(usock, idx++, USOCKET_REP_RESULT(usock)); - USOCKET_SET_RESPONSE(usock, idx++, USOCKET_REP_ERRCODE(usock)); - USOCKET_SET_RESPONSE(usock, idx++, USOCKET_REP_ADDRLEN(usock)); - USOCKET_SET_RESPONSE(usock, idx++, USOCKET_REP_ADDR(usock)); - - set_container_ids(container, USOCKET_USOCKID(usock), - LTE_CMDID_GETSOCKNAME); - set_container_argument(container, inparam, nitems(inparam)); - set_container_response(container, USOCKET_REP_RESPONSE(usock), idx); - set_container_postproc(container, postproc_getsockname, 0); - - return altdevice_send_command(dev, dev->altfd, container, usock_result); -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * name: nextstep_getsockname - ****************************************************************************/ - -int nextstep_getsockname(FAR struct alt1250_s *dev, - FAR struct alt_container_s *reply, - FAR struct usock_s *usock, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo, - unsigned long arg) -{ - socklen_t addrlen; - - dbg_alt1250("%s start\n", __func__); - - if (USOCKET_DOMAIN(usock) == AF_INET) - { - addrlen = sizeof(struct sockaddr_in); - } - else - { - addrlen = sizeof(struct sockaddr_in6); - } - - return send_getsockname_command(dev, reply, usock, addrlen, usock_result); -} - -/**************************************************************************** - * name: usockreq_getsockname - ****************************************************************************/ - -int usockreq_getsockname(FAR struct alt1250_s *dev, - FAR struct usrsock_request_buff_s *req, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo) -{ - FAR struct usrsock_request_getsockname_s *request = &req->request.name_req; - FAR struct usock_s *usock; - FAR struct alt_container_s *container; - int ret = REP_SEND_ACK_WOFREE; - - dbg_alt1250("%s start\n", __func__); - - *usock_result = OK; - *usock_xid = request->head.xid; - - usock = usocket_search(dev, request->usockid); - if (usock == NULL) - { - dbg_alt1250("Failed to get socket context: %u\n", - request->usockid); - *usock_result = -EBADFD; - return REP_SEND_ACK_WOFREE; - } - - USOCKET_SET_REQUEST(usock, request->head.reqid, request->head.xid); - USOCKET_SET_REQADDRLEN(usock, request->max_addrlen); - - switch (USOCKET_STATE(usock)) - { - case SOCKET_STATE_CLOSED: - case SOCKET_STATE_CLOSING: - dbg_alt1250("Unexpected state: %d\n", USOCKET_STATE(usock)); - *usock_result = -EBADFD; - ret = REP_SEND_ACK_WOFREE; - break; - - case SOCKET_STATE_PREALLOC: - container = container_alloc(); - if (container == NULL) - { - dbg_alt1250("no container\n"); - return REP_NO_CONTAINER; - } - - ret = open_altsocket(dev, container, usock, usock_result); - if (IS_NEED_CONTAINER_FREE(ret)) - { - container_free(container); - } - break; - - default: - container = container_alloc(); - if (container == NULL) - { - dbg_alt1250("no container\n"); - return REP_NO_CONTAINER; - } - - ret = nextstep_getsockname(dev, container, usock, usock_result, - usock_xid, ackinfo, 0); - if (IS_NEED_CONTAINER_FREE(ret)) - { - container_free(container); - } - break; - } - - return ret; -} - diff --git a/lte/alt1250/usock_handlers/alt1250_getsockopthdlr.c b/lte/alt1250/usock_handlers/alt1250_getsockopthdlr.c deleted file mode 100644 index 2805cd574..000000000 --- a/lte/alt1250/usock_handlers/alt1250_getsockopthdlr.c +++ /dev/null @@ -1,235 +0,0 @@ -/**************************************************************************** - * apps/lte/alt1250/usock_handlers/alt1250_getsockopthdlr.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -#include "alt1250_dbg.h" -#include "alt1250_container.h" -#include "alt1250_socket.h" -#include "alt1250_devif.h" -#include "alt1250_usrsock_hdlr.h" -#include "alt1250_usockevent.h" -#include "alt1250_postproc.h" - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static int postproc_getsockopt(FAR struct alt1250_s *dev, - FAR struct alt_container_s *reply, - FAR struct usock_s *usock, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo, - unsigned long arg) -{ - int ret = REP_SEND_ACK; - FAR void **resp = CONTAINER_RESPONSE(reply); - - dbg_alt1250("%s start\n", __func__); - - /* resp[0]: ret code - * resp[1]: error code - * resp[2]: optlen - * resp[3]: optval - */ - - *usock_xid = USOCKET_XID(usock); - *usock_result = COMBINE_ERRCODE(*(FAR int *)resp[0], *(FAR int *)resp[1]); - - if (*usock_result >= 0) - { - *usock_result = 0; - *usock_xid = USOCKET_XID(usock); - - ackinfo->valuelen = MIN(USOCKET_REQOPTLEN(usock), - *(FAR uint16_t *)(resp[2])); - ackinfo->valuelen_nontrunc = *(FAR uint16_t *)(resp[2]); - ackinfo->value_ptr = resp[3]; - ackinfo->buf_ptr = NULL; - - if (ackinfo->valuelen != 0) - { - ret = REP_SEND_DACK; - } - } - - return ret; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * name: nextstep_getsockopt - ****************************************************************************/ - -int nextstep_getsockopt(FAR struct alt1250_s *dev, - FAR struct alt_container_s *reply, - FAR struct usock_s *usock, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo, - unsigned long arg) -{ - dbg_alt1250("%s start\n", __func__); - - return send_getsockopt_command(dev, reply, usock, - USOCKET_REQOPTLEVEL(usock), - USOCKET_REQOPTOPT(usock), - USOCKET_REQOPTLEN(usock), - &USOCKET_REQOPTLEVEL(usock), - &USOCKET_REQOPTOPT(usock), - postproc_getsockopt, 0, usock_result); -} - -/**************************************************************************** - * name: send_getsockopt_command - ****************************************************************************/ - -int send_getsockopt_command(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - FAR struct usock_s *usock, - int16_t level, - int16_t option, - uint16_t valuelen, - FAR int16_t *requested_level, - FAR int16_t *requested_option, - FAR postproc_hdlr_t func, - unsigned long priv, - FAR int32_t *usock_result) -{ - int idx = 0; - FAR void *inparam[4]; - - /* These members are referenced only when sending a command and - * not when receiving a response, so local variables are used. - */ - - inparam[0] = &USOCKET_ALTSOCKID(usock); - inparam[1] = &level; - inparam[2] = &option; - inparam[3] = &valuelen; - - USOCKET_SET_RESPONSE(usock, idx++, USOCKET_REP_RESULT(usock)); - USOCKET_SET_RESPONSE(usock, idx++, USOCKET_REP_ERRCODE(usock)); - USOCKET_SET_RESPONSE(usock, idx++, USOCKET_REP_OPTLEN(usock)); - USOCKET_SET_RESPONSE(usock, idx++, USOCKET_REP_OPTVAL(usock)); - USOCKET_SET_RESPONSE(usock, idx++, requested_level); - USOCKET_SET_RESPONSE(usock, idx++, requested_option); - - set_container_ids(container, USOCKET_USOCKID(usock), LTE_CMDID_GETSOCKOPT); - set_container_argument(container, inparam, nitems(inparam)); - set_container_response(container, USOCKET_REP_RESPONSE(usock), idx); - set_container_postproc(container, func, priv); - - return altdevice_send_command(dev, dev->altfd, container, usock_result); -} - -/**************************************************************************** - * name: usockreq_getsockopt - ****************************************************************************/ - -int usockreq_getsockopt(FAR struct alt1250_s *dev, - FAR struct usrsock_request_buff_s *req, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo) -{ - FAR struct usrsock_request_getsockopt_s *request = &req->request.gopt_req; - FAR struct usock_s *usock; - FAR struct alt_container_s *container; - int ret = REP_SEND_ACK_WOFREE; - - dbg_alt1250("%s start\n", __func__); - - *usock_result = OK; - *usock_xid = request->head.xid; - - usock = usocket_search(dev, request->usockid); - if (usock == NULL) - { - dbg_alt1250("Failed to get socket context: %u\n", - request->usockid); - *usock_result = -EBADFD; - return REP_SEND_ACK_WOFREE; - } - - if (request->max_valuelen > _OPTVAL_LEN_MAX) - { - *usock_result = -EINVAL; - return REP_SEND_ACK_WOFREE; - } - - USOCKET_SET_REQUEST(usock, request->head.reqid, request->head.xid); - USOCKET_SET_REQSOCKOPT(usock, request->level, request->option, - request->max_valuelen); - - switch (USOCKET_STATE(usock)) - { - case SOCKET_STATE_CLOSED: - case SOCKET_STATE_CLOSING: - dbg_alt1250("Unexpected state: %d\n", USOCKET_STATE(usock)); - *usock_result = -EBADFD; - ret = REP_SEND_ACK_WOFREE; - break; - - case SOCKET_STATE_PREALLOC: - container = container_alloc(); - if (container == NULL) - { - dbg_alt1250("no container\n"); - return REP_NO_CONTAINER; - } - - ret = open_altsocket(dev, container, usock, usock_result); - if (IS_NEED_CONTAINER_FREE(ret)) - { - container_free(container); - } - break; - - default: - container = container_alloc(); - if (container == NULL) - { - dbg_alt1250("no container\n"); - return REP_NO_CONTAINER; - } - - ret = nextstep_getsockopt(dev, container, usock, usock_result, - usock_xid, ackinfo, 0); - if (IS_NEED_CONTAINER_FREE(ret)) - { - container_free(container); - } - break; - } - - return ret; -} diff --git a/lte/alt1250/usock_handlers/alt1250_ioctl_denyinetsock.c b/lte/alt1250/usock_handlers/alt1250_ioctl_denyinetsock.c deleted file mode 100644 index d85ca7ac0..000000000 --- a/lte/alt1250/usock_handlers/alt1250_ioctl_denyinetsock.c +++ /dev/null @@ -1,79 +0,0 @@ -/**************************************************************************** - * apps/lte/alt1250/usock_handlers/alt1250_ioctl_denyinetsock.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -#include "alt1250_dbg.h" -#include "alt1250_container.h" -#include "alt1250_socket.h" -#include "alt1250_devif.h" -#include "alt1250_usockevent.h" -#include "alt1250_postproc.h" -#include "alt1250_usrsock_hdlr.h" -#include "alt1250_netdev.h" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * name: usockreq_ioctl_denyinetsock - ****************************************************************************/ - -int usockreq_ioctl_denyinetsock(FAR struct alt1250_s *dev, - FAR struct usrsock_request_buff_s *req, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo) -{ - uint8_t sock_type = req->req_ioctl.sock_type; - int ret = REP_SEND_ACK_WOFREE; - - dbg_alt1250("%s start\n", __func__); - - *usock_result = OK; - - if (sock_type == DENY_INET_SOCK_ENABLE) - { - /* Block to create INET socket */ - - dev->usock_enable = FALSE; - } - else if (sock_type == DENY_INET_SOCK_DISABLE) - { - /* Allow to create INET socket */ - - dev->usock_enable = TRUE; - } - else - { - dbg_alt1250("unexpected sock_type:0x%02x\n", sock_type); - *usock_result = -EINVAL; - } - - return ret; -} diff --git a/lte/alt1250/usock_handlers/alt1250_ioctl_event.c b/lte/alt1250/usock_handlers/alt1250_ioctl_event.c deleted file mode 100644 index cf7ee532a..000000000 --- a/lte/alt1250/usock_handlers/alt1250_ioctl_event.c +++ /dev/null @@ -1,171 +0,0 @@ -/**************************************************************************** - * apps/lte/alt1250/usock_handlers/alt1250_ioctl_event.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -#include "alt1250_dbg.h" -#include "alt1250_container.h" -#include "alt1250_socket.h" -#include "alt1250_usockevent.h" -#include "alt1250_postproc.h" -#include "alt1250_devif.h" -#include "alt1250_evt.h" -#include "alt1250_ioctl_subhdlr.h" - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * name: send_eventnotice_command - ****************************************************************************/ - -static int send_eventnotice_command(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - FAR struct usock_s *usock, - FAR struct lte_ioctl_data_s *ltecmd, - FAR int32_t *usock_result) -{ - set_container_ids(container, USOCKET_USOCKID(usock), ltecmd->cmdid); - set_container_argument(container, ltecmd->inparam, ltecmd->inparamlen); - set_container_response(container, ltecmd->outparam, ltecmd->outparamlen); - set_container_postproc(container, NULL, 0); - - return altdevice_send_command(dev, dev->altfd, container, usock_result); -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * name: usockreq_ioctl_event - ****************************************************************************/ - -int usockreq_ioctl_event(FAR struct alt1250_s *dev, - FAR struct usrsock_request_buff_s *req, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo) -{ - FAR struct usrsock_request_ioctl_s *request = &req->request.ioctl_req; - FAR struct lte_ioctl_data_s *ltecmd = &req->req_ioctl.ltecmd; - FAR struct usock_s *usock = NULL; - int ret = REP_SEND_ACK_WOFREE; - uint32_t cmdid = LTE_PURE_CMDID(ltecmd->cmdid); - FAR struct alt_container_s *container; - - dbg_alt1250("%s start\n", __func__); - - *usock_result = OK; - *usock_xid = request->head.xid; - - usock = usocket_search(dev, request->usockid); - if (usock == NULL) - { - dbg_alt1250("Failed to get socket context: %u\n", - request->usockid); - *usock_result = -EBADFD; - return REP_SEND_ACK_WOFREE; - } - - ret = alt1250_regevtcb(cmdid, ltecmd->cb); - if (ret < 0) - { - *usock_result = ret; - return REP_SEND_ACK_WOFREE; - } - -#ifdef CONFIG_LTE_ALT1250_ENABLE_HIBERNATION_MODE - if (dev->is_resuming) - { - /* In resuming phase, report API callback can be registered without - * sending modem command. Modem command will be sent in calling - * resume API. - */ - - if (ltecmd->cmdid == LTE_CMDID_REPQUAL) - { - dev->quality_report_period = *((uint32_t *)ltecmd->inparam[1]); - } - else if (ltecmd->cmdid == LTE_CMDID_REPCELL) - { - dev->cellinfo_report_period = *((uint32_t *)ltecmd->inparam[1]); - } - - *usock_result = ret; - return REP_SEND_ACK_WOFREE; - } -#endif - - container = container_alloc(); - if (container == NULL) - { - dbg_alt1250("no container\n"); - alt1250_regevtcb(cmdid, NULL); - return REP_NO_CONTAINER; - } - - USOCKET_SET_REQUEST(usock, request->head.reqid, request->head.xid); - - if (IS_LWM2M_EVENT(cmdid)) - { - ret = send_m2mnotice_command(cmdid, dev, container, usock, ltecmd, - usock_result); - } - else - { - ret = send_eventnotice_command(dev, container, usock, ltecmd, - usock_result); - } - - if (IS_NEED_CONTAINER_FREE(ret)) - { - container_free(container); - } - - if (*usock_result == -ENOSYS) - { - /* -ENOSYS means that there is no composer. - * There are cases where the LAPI command ID group is an event, - * but no composer is needed. - * In that case, it is necessary to send OK to usrsock after - * registering the callback function. - */ - - ret = REP_SEND_ACK_WOFREE; - *usock_result = OK; - } - else if (*usock_result < 0) - { - /* clear callback */ - - alt1250_regevtcb(cmdid, NULL); - } - - return ret; -} diff --git a/lte/alt1250/usock_handlers/alt1250_ioctl_fwupdate.c b/lte/alt1250/usock_handlers/alt1250_ioctl_fwupdate.c deleted file mode 100644 index dfd6c41ae..000000000 --- a/lte/alt1250/usock_handlers/alt1250_ioctl_fwupdate.c +++ /dev/null @@ -1,466 +0,0 @@ -/**************************************************************************** - * apps/lte/alt1250/usock_handlers/alt1250_ioctl_fwupdate.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include - -#include "alt1250_dbg.h" -#include "alt1250_daemon.h" -#include "alt1250_fwupdate.h" -#include "alt1250_container.h" -#include "alt1250_socket.h" -#include "alt1250_usrsock_hdlr.h" -#include "alt1250_devif.h" -#include "alt1250_usockevent.h" -#include "alt1250_postproc.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define DELTA_MAGICNO (('D') + ('T' << 8) + ('F' << 16) + ('W' << 24)) -#define IS_IN_RANGE(a, l, h) (((a) >= (l)) && ((a) < (h))) - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: postprochdlr_fwgetimglen - ****************************************************************************/ - -static int postproc_fwgetimglen(FAR struct alt1250_s *dev, - FAR struct alt_container_s *reply, - FAR struct usock_s *usock, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo, - unsigned long arg) -{ - if (CONTAINER_RESPRES(reply) >= 0) - { - /* When modem returned non-zero value, - * some data have already injected. - * But additional header is not counted. - * Here is adjustement code for it. - */ - - if (dev->fwup_info.act_injected == -1) - { - /* First call */ - - dev->fwup_info.act_injected = CONTAINER_RESPRES(reply); - dev->fwup_info.hdr_injected = (dev->fwup_info.act_injected > 0) ? - sizeof(struct delta_header_s) : 0; - } - else if (dev->fwup_info.act_injected >= LTE_IMAGE_PERT_SIZE) - { - /* Injection is already done until pert area. */ - - if (CONTAINER_RESPRES(reply) == 0) - { - /* Modem should returl non-zero value. - * This is error case because of mis-matched. - */ - - /* Notice: This case can be happened in normal case - * when injection done just until pert area. - * But it can't be rescued. - */ - - dev->fwup_info.hdr_injected = 0; - dev->fwup_info.act_injected = -1; - } - else - { - dev->fwup_info.act_injected = CONTAINER_RESPRES(reply); - } - } - - if (dev->fwup_info.act_injected == -1) - { - CONTAINER_RESPRES(reply) = -ENODATA; - } - else - { - /* Reply size should include header injected size */ - - CONTAINER_RESPRES(reply) = - dev->fwup_info.act_injected + dev->fwup_info.hdr_injected; - } - } - else - { - /* In error case from modem, injection is reset. */ - - dev->fwup_info.hdr_injected = 0; - dev->fwup_info.act_injected = -1; - } - - *usock_result = CONTAINER_RESPRES(reply); - - return REP_SEND_ACK; -} - -/**************************************************************************** - * Name: postprochdlr_fwupdate_injection - ****************************************************************************/ - -static int postproc_fwupdate_injection(FAR struct alt1250_s *dev, - FAR struct alt_container_s *reply, - FAR struct usock_s *usock, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo, - unsigned long arg) -{ - int app_injected = (int)arg; - - if (CONTAINER_RESPRES(reply) < 0) - { - dev->fwup_info.hdr_injected = 0; - dev->fwup_info.act_injected = -1; - } - else if (app_injected >= 0) - { - CONTAINER_RESPRES(reply) = app_injected; - } - - *usock_result = CONTAINER_RESPRES(reply); - - return REP_SEND_ACK; -} - -/**************************************************************************** - * Name: fwupdate_dummy_postproc - ****************************************************************************/ - -static int postproc_fwupdate_dummy(FAR struct alt1250_s *dev, - FAR struct alt_container_s *reply, - FAR struct usock_s *usock, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo, - unsigned long arg) -{ - *usock_result = CONTAINER_RESPRES(reply); - - return REP_SEND_ACK; -} - -/**************************************************************************** - * Name: store_injection_data - ****************************************************************************/ - -static bool store_injection_data(FAR char *dist, FAR int *ofst, int sz, - FAR uint8_t **src, FAR int *len) -{ - bool ret = false; - int rest; - - if (IS_IN_RANGE(*ofst, 0, sz)) - { - rest = sz - *ofst; - rest = (rest > *len) ? *len : rest; - memcpy(&dist[*ofst], *src, rest); - *len -= rest; - *ofst += rest; - *src += rest; - if (*ofst == sz) - { - ret = true; - } - } - - return ret; -} - -/**************************************************************************** - * Name: verify_header_crc32 - ****************************************************************************/ - -static bool verify_header_crc32(FAR struct alt1250_s *dev) -{ - uint32_t crc_result = crc32((uint8_t *)&dev->fwup_info.hdr, - sizeof(struct delta_header_s)); - - return (crc_result == 0); -} - -/**************************************************************************** - * Name: verify_pert_crc32 - ****************************************************************************/ - -static bool verify_pert_crc32(FAR struct alt1250_s *dev) -{ - uint32_t crc_result = crc32((uint8_t *)dev->fwup_info.img_pert, - LTE_IMAGE_PERT_SIZE); - return (crc_result == dev->fwup_info.hdr.pert_crc); -} - -/**************************************************************************** - * Name: fwupdate_header_injection - ****************************************************************************/ - -static int fwupdate_header_injection(FAR struct alt1250_s *dev, - FAR struct lte_ioctl_data_s *cmd, - FAR bool *send_pert) -{ - FAR uint8_t *data = (FAR uint8_t *)cmd->inparam[0]; - int len = *(FAR int *)cmd->inparam[1]; - bool init = *(FAR bool *)cmd->inparam[2]; - bool filled_all; - - if (init) - { - dev->fwup_info.act_injected = 0; - dev->fwup_info.hdr_injected = 0; - } - - *send_pert = false; - - /* Make sure lte_get_version() and - * ltefwupdate_injected_datasize() have been already called. - */ - - if ((dev->fw_version[0] == 'R') && (dev->fw_version[1] == 'K') - && (dev->fwup_info.act_injected != -1) && (len > 0)) - { - /* Check if under header injection phase */ - - if (dev->fwup_info.act_injected == 0) - { - filled_all - = store_injection_data((char *)&dev->fwup_info.hdr, - &dev->fwup_info.hdr_injected, - sizeof(struct delta_header_s), &data, - &len); - if (filled_all) - { - if (!verify_header_crc32(dev) || - (dev->fwup_info.hdr.chunk_code != DELTA_MAGICNO) || - strncmp(dev->fw_version, dev->fwup_info.hdr.np_package, - LTE_VER_NP_PACKAGE_LEN)) - { - /* CRC error or Version mis-match */ - - dbg_alt1250("FWUP: Error CRC Header\n"); - dev->fwup_info.hdr_injected = 0; - dev->fwup_info.act_injected = -1; - return -EINVAL; - } - } - } - - /* Check if under pert injection phase */ - - if ((dev->fwup_info.hdr_injected >= sizeof(struct delta_header_s)) && - (len > 0)) - { - filled_all - = store_injection_data(dev->fwup_info.img_pert, - &dev->fwup_info.act_injected, - LTE_IMAGE_PERT_SIZE, &data, &len); - if (filled_all) - { - if (!verify_pert_crc32(dev)) - { - /* CRC error */ - - dbg_alt1250("FWUP: Error CRC Pertition\n"); - dev->fwup_info.hdr_injected = 0; - dev->fwup_info.act_injected = -1; - return -EINVAL; - } - else - { - *send_pert = true; - } - } - } - - return len; - } - else - { - dbg_alt1250("FWUP: Not initialized.\n"); - return -ENODATA; - } -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * name: usockreq_ioctl_fwupdate - ****************************************************************************/ - -int usockreq_ioctl_fwupdate(FAR struct alt1250_s *dev, - FAR struct usrsock_request_buff_s *req, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo) -{ - FAR struct usrsock_request_ioctl_s *request = &req->request.ioctl_req; - FAR struct lte_ioctl_data_s *ltecmd = &req->req_ioctl.ltecmd; - FAR struct usock_s *usock = NULL; - int ret = REP_SEND_ACK_WOFREE; - FAR struct alt_container_s *container; - postproc_hdlr_t postproc_hdlr = NULL; - bool send_cmd = true; - int postproc_priv = -1; - - dbg_alt1250("%s start\n", __func__); - - *usock_result = OK; - *usock_xid = request->head.xid; - - usock = usocket_search(dev, request->usockid); - if (usock == NULL) - { - dbg_alt1250("Failed to get socket context: %u\n", - request->usockid); - *usock_result = -EBADFD; - return REP_SEND_ACK_WOFREE; - } - - /* FW Update APIs are all synchronouse. */ - - if ((ltecmd->cmdid & LTE_CMDOPT_ASYNC_BIT) || (ltecmd->cb != NULL)) - { - *usock_result = -EINVAL; - return REP_SEND_ACK_WOFREE; - } - - container = container_alloc(); - if (container == NULL) - { - dbg_alt1250("no container\n"); - return REP_NO_CONTAINER; - } - - /* Special operation for each commands */ - - switch (ltecmd->cmdid) - { - case LTE_CMDID_INJECTIMAGE: - { - *usock_result = fwupdate_header_injection(dev, ltecmd, &send_cmd); - if (*usock_result < 0) - { - container_free(container); - return REP_SEND_ACK_WOFREE; - } - else - { - /* That send_cmd is set to true means - * that pert image should be sent. - */ - - if (send_cmd) - { - /* Need to care for reply value as actual injected - * size from application point of view - */ - - postproc_priv - = *(FAR int *)ltecmd->inparam[1] - *usock_result; - ltecmd->inparam[0] = dev->fwup_info.img_pert; - *(FAR int *)ltecmd->inparam[1] = LTE_IMAGE_PERT_SIZE; - *(FAR bool *)ltecmd->inparam[2] = true; - } - else if (*usock_result > 0) - { - send_cmd = true; - } - else /* In case of *result == 0 */ - { - /* No send injecting data to modem, - * but the data is all accepted. - */ - - *usock_result = *(FAR int *)ltecmd->inparam[1]; - container_free(container); - } - - postproc_hdlr = postproc_fwupdate_injection; - } - } - break; - - case LTE_CMDID_GETIMAGELEN: - { - postproc_hdlr = postproc_fwgetimglen; - } - break; - - case LTE_CMDID_EXEUPDATE: - { - /* When execution starts, injection is reset */ - - reset_fwupdate_info(dev); - postproc_hdlr = postproc_fwupdate_dummy; - } - break; - - default: - { - *usock_result = -EINVAL; - container_free(container); - return REP_SEND_ACK_WOFREE; - } - break; - } - - if (send_cmd) - { - USOCKET_SET_REQUEST(usock, request->head.reqid, request->head.xid); - - set_container_ids(container, USOCKET_USOCKID(usock), ltecmd->cmdid); - set_container_argument(container, ltecmd->inparam, ltecmd->inparamlen); - set_container_response(container, ltecmd->outparam, - ltecmd->outparamlen); - set_container_postproc(container, postproc_hdlr, postproc_priv); - - ret = altdevice_send_command(dev, dev->altfd, container, usock_result); - - if (IS_NEED_CONTAINER_FREE(ret)) - { - container_free(container); - } - } - - return ret; -} - -void reset_fwupdate_info(FAR struct alt1250_s *dev) -{ - dev->fwup_info.hdr_injected = 0; - dev->fwup_info.act_injected = -1; - dev->fw_version[0] = '\0'; -} diff --git a/lte/alt1250/usock_handlers/alt1250_ioctl_ifreq.c b/lte/alt1250/usock_handlers/alt1250_ioctl_ifreq.c deleted file mode 100644 index 6a948c653..000000000 --- a/lte/alt1250/usock_handlers/alt1250_ioctl_ifreq.c +++ /dev/null @@ -1,410 +0,0 @@ -/**************************************************************************** - * apps/lte/alt1250/usock_handlers/alt1250_ioctl_ifreq.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include - -#include "alt1250_dbg.h" -#include "alt1250_container.h" -#include "alt1250_socket.h" -#include "alt1250_devif.h" -#include "alt1250_usockevent.h" -#include "alt1250_postproc.h" -#include "alt1250_usrsock_hdlr.h" -#include "alt1250_netdev.h" - -/**************************************************************************** - * Private Function Prototype - ****************************************************************************/ - -static int postproc_radiooff(FAR struct alt1250_s *dev, - FAR struct alt_container_s *reply, - FAR struct usock_s *usock, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo, - unsigned long arg); - -static int postproc_radioon(FAR struct alt1250_s *dev, - FAR struct alt_container_s *reply, - FAR struct usock_s *usock, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo, - unsigned long arg); - -static int postproc_actpdn(FAR struct alt1250_s *dev, - FAR struct alt_container_s *reply, - FAR struct usock_s *usock, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo, - unsigned long arg); - -static int postproc_reportnet(FAR struct alt1250_s *dev, - FAR struct alt_container_s *reply, - FAR struct usock_s *usock, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo, - unsigned long arg); - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * name: send_actpdn_command - ****************************************************************************/ - -static int send_actpdn_command(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - FAR struct usock_s *usock, - FAR int32_t *usock_result) -{ - int idx = 0; - FAR void *inparam[1]; - - /* This member is referenced only when sending a command and - * not when receiving a response, so local variable is used. - */ - - inparam[0] = &dev->apn; - - USOCKET_SET_RESPONSE(usock, idx++, USOCKET_REP_RESULT(usock)); - USOCKET_SET_RESPONSE(usock, idx++, &dev->o_pdn); - - set_container_ids(container, USOCKET_USOCKID(usock), LTE_CMDID_ACTPDN); - set_container_argument(container, inparam, nitems(inparam)); - set_container_response(container, USOCKET_REP_RESPONSE(usock), idx); - set_container_postproc(container, postproc_actpdn, 0); - - return altdevice_send_command(dev, dev->altfd, container, usock_result); -} - -/**************************************************************************** - * name: send_radio_command - ****************************************************************************/ - -static int send_radio_command(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - FAR struct usock_s *usock, - FAR int32_t *usock_result, bool on) -{ - int idx = 0; - - USOCKET_SET_RESPONSE(usock, idx++, USOCKET_REP_RESULT(usock)); - - set_container_ids(container, USOCKET_USOCKID(usock), - on ? LTE_CMDID_RADIOON : LTE_CMDID_RADIOOFF); - set_container_argument(container, NULL, 0); - set_container_response(container, USOCKET_REP_RESPONSE(usock), idx); - set_container_postproc(container, - on ? postproc_radioon : postproc_radiooff, 0); - - return altdevice_send_command(dev, dev->altfd, container, usock_result); -} - -/**************************************************************************** - * name: postproc_radiooff - ****************************************************************************/ - -static int postproc_radiooff(FAR struct alt1250_s *dev, - FAR struct alt_container_s *reply, - FAR struct usock_s *usock, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo, - unsigned long arg) -{ - int ret = REP_SEND_ACK; - FAR void **resp = CONTAINER_RESPONSE(reply); - int altcom_result = *((int *)(resp[0])); - - dbg_alt1250("%s start\n", __func__); - - *usock_result = (CONTAINER_RESPRES(reply) == 0) ? altcom_result : - CONTAINER_RESPRES(reply); - - alt1250_netdev_ifdown(dev); - - return ret; -} - -/**************************************************************************** - * name: postproc_actpdn - ****************************************************************************/ - -static int postproc_actpdn(FAR struct alt1250_s *dev, - FAR struct alt_container_s *reply, - FAR struct usock_s *usock, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo, - unsigned long arg) -{ - int ret = REP_SEND_ACK; - FAR void **resp = CONTAINER_RESPONSE(reply); - int altcom_result = *((int *)(resp[0])); - FAR lte_pdn_t *pdn = resp[1]; - - dbg_alt1250("%s start\n", __func__); - - *usock_result = (CONTAINER_RESPRES(reply) == 0) ? altcom_result : - CONTAINER_RESPRES(reply); - - if (*usock_result == 0) - { - /* After connecting to the LTE network, - * wait for the modem to register the network interface. - */ - - usleep(ALT1250_NETIF_READY_DELAY); - alt1250_netdev_ifup(dev, pdn); - } - - return ret; -} - -/**************************************************************************** - * name: postproc_radioon - ****************************************************************************/ - -static int postproc_radioon(FAR struct alt1250_s *dev, - FAR struct alt_container_s *reply, - FAR struct usock_s *usock, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo, - unsigned long arg) -{ - int ret = REP_SEND_ACK; - FAR void **resp = CONTAINER_RESPONSE(reply); - int altcom_result = *((int *)(resp[0])); - - dbg_alt1250("%s start\n", __func__); - - *usock_result = (CONTAINER_RESPRES(reply) == 0) ? altcom_result : - CONTAINER_RESPRES(reply); - - if (*usock_result == 0) - { - ret = send_reportnet_command(dev, reply, usock, postproc_reportnet, 0, - usock_result); - } - - return ret; -} - -/**************************************************************************** - * name: postproc_reportnet - ****************************************************************************/ - -static int postproc_reportnet(FAR struct alt1250_s *dev, - FAR struct alt_container_s *reply, - FAR struct usock_s *usock, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo, - unsigned long arg) -{ - int ret = REP_SEND_ACK; - FAR void **resp = CONTAINER_RESPONSE(reply); - int altcom_result = *((int *)(resp[0])); - - dbg_alt1250("%s start\n", __func__); - - *usock_result = (CONTAINER_RESPRES(reply) == 0) ? altcom_result : - CONTAINER_RESPRES(reply); - - if (*usock_result == 0) - { - ret = send_actpdn_command(dev, reply, usock, usock_result); - } - - return ret; -} - -/**************************************************************************** - * name: do_ifup - ****************************************************************************/ - -static int do_ifup(FAR struct alt1250_s *dev, - FAR struct usrsock_request_buff_s *req, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo) -{ - FAR struct usrsock_request_ioctl_s *request = - &req->request.ioctl_req; - FAR struct usock_s *usock; - FAR struct alt_container_s *container; - int ret = REP_SEND_ACK_WOFREE; - - *usock_result = OK; - *usock_xid = request->head.xid; - - usock = usocket_search(dev, request->usockid); - if (usock == NULL) - { - dbg_alt1250("Failed to get socket context: %u\n", - request->usockid); - *usock_result = -EBADFD; - return REP_SEND_ACK_WOFREE; - } - - container = container_alloc(); - if (container == NULL) - { - dbg_alt1250("no container\n"); - return REP_NO_CONTAINER; - } - - ret = send_radio_command(dev, container, usock, usock_result, true); - - if (IS_NEED_CONTAINER_FREE(ret)) - { - container_free(container); - } - - return ret; -} - -/**************************************************************************** - * name: do_ifdown - ****************************************************************************/ - -static int do_ifdown(FAR struct alt1250_s *dev, - FAR struct usrsock_request_buff_s *req, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo) -{ - FAR struct usrsock_request_ioctl_s *request = - &req->request.ioctl_req; - FAR struct usock_s *usock; - FAR struct alt_container_s *container; - int ret = REP_SEND_ACK_WOFREE; - - *usock_result = OK; - *usock_xid = request->head.xid; - - usock = usocket_search(dev, request->usockid); - if (usock == NULL) - { - dbg_alt1250("Failed to get socket context: %u\n", - request->usockid); - *usock_result = -EBADFD; - return REP_SEND_ACK_WOFREE; - } - - container = container_alloc(); - if (container == NULL) - { - dbg_alt1250("no container\n"); - return REP_NO_CONTAINER; - } - - ret = send_radio_command(dev, container, usock, usock_result, false); - - if (IS_NEED_CONTAINER_FREE(ret)) - { - container_free(container); - } - - return ret; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * name: send_reportnet_command - ****************************************************************************/ - -int send_reportnet_command(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - FAR struct usock_s *usock, - FAR postproc_hdlr_t func, - unsigned long priv, - FAR int32_t *usock_result) -{ - int idx = 0; - FAR void *inparam[1]; - uint8_t enable = 1; - - /* This member is referenced only when sending a command and - * not when receiving a response, so local variable is used. - */ - - inparam[0] = &enable; - - USOCKET_SET_RESPONSE(usock, idx++, USOCKET_REP_RESULT(usock)); - - set_container_ids(container, USOCKET_USOCKID(usock), LTE_CMDID_REPNETINFO); - set_container_argument(container, inparam, nitems(inparam)); - set_container_response(container, USOCKET_REP_RESPONSE(usock), idx); - set_container_postproc(container, func, priv); - - return altdevice_send_command(dev, dev->altfd, container, usock_result); -} - -/**************************************************************************** - * name: usockreq_ioctl_ifreq - ****************************************************************************/ - -int usockreq_ioctl_ifreq(FAR struct alt1250_s *dev, - FAR struct usrsock_request_buff_s *req, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo) -{ - FAR struct usrsock_request_ioctl_s *request = &req->request.ioctl_req; - FAR struct ifreq *if_req = &req->req_ioctl.ifreq; - int ret = REP_SEND_ACK_WOFREE; - - dbg_alt1250("%s start\n", __func__); - - *usock_result = OK; - *usock_xid = request->head.xid; - - if (!dev->usock_enable) - { - *usock_result = -ENOTTY; - } - else if (if_req->ifr_flags & IFF_UP) - { - ret = do_ifup(dev, req, usock_result, usock_xid, ackinfo); - } - else - { - ret = do_ifdown(dev, req, usock_result, usock_xid, ackinfo); - } - - return ret; -} diff --git a/lte/alt1250/usock_handlers/alt1250_ioctl_ltecmd.c b/lte/alt1250/usock_handlers/alt1250_ioctl_ltecmd.c deleted file mode 100644 index 889f9b41f..000000000 --- a/lte/alt1250/usock_handlers/alt1250_ioctl_ltecmd.c +++ /dev/null @@ -1,124 +0,0 @@ -/**************************************************************************** - * apps/lte/alt1250/usock_handlers/alt1250_ioctl_ltecmd.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -#include "alt1250_dbg.h" -#include "alt1250_container.h" -#include "alt1250_socket.h" -#include "alt1250_usockevent.h" -#include "alt1250_postproc.h" -#include "alt1250_devif.h" -#include "alt1250_evt.h" -#include "alt1250_ioctl_subhdlr.h" - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -extern int usockreq_ioctl_extend(FAR struct alt1250_s *dev, - FAR struct usrsock_request_buff_s *req, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo); - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * name: usockreq_ioctl_ltecmd - ****************************************************************************/ - -int usockreq_ioctl_ltecmd(FAR struct alt1250_s *dev, - FAR struct usrsock_request_buff_s *req, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo) -{ - FAR struct usrsock_request_ioctl_s *request = &req->request.ioctl_req; - FAR struct lte_ioctl_data_s *ltecmd = &req->req_ioctl.ltecmd; - int ret = REP_SEND_ACK_WOFREE; - usrsock_reqhandler_t ioctl_subhdlr = NULL; - - dbg_alt1250("%s start\n", __func__); - - *usock_result = -EINVAL; - *usock_xid = request->head.xid; - -#ifdef CONFIG_LTE_ALT1250_ENABLE_HIBERNATION_MODE - if (dev->is_resuming && - !IS_LTE_REPORT_EVENT(ltecmd->cmdid) && - ltecmd->cmdid != LTE_CMDID_SETEVTCTX && - ltecmd->cmdid != LTE_CMDID_RESUME) - { - dbg_alt1250("Don't allow to call any API in resuming " - "phase.(cmdid=%lx)\n", - ltecmd->cmdid); - return ret; - } -#endif - - if (LTE_ISCMDGRP_NORMAL(ltecmd->cmdid)) - { - ioctl_subhdlr = usockreq_ioctl_normal; - } - else if (LTE_ISCMDGRP_EVENT(ltecmd->cmdid)) - { - ioctl_subhdlr = usockreq_ioctl_event; - } - else if (LTE_ISCMDGRP_NOMDM(ltecmd->cmdid)) - { - ioctl_subhdlr = usockreq_ioctl_other; - } - else if (LTE_ISCMDGRP_POWER(ltecmd->cmdid)) - { - ioctl_subhdlr = usockreq_ioctl_power; - } - else if (LTE_ISCMDGRP_FWUPDATE(ltecmd->cmdid)) - { - ioctl_subhdlr = usockreq_ioctl_fwupdate; - } - else if (LTE_ISCMDGRP_LWM2M(ltecmd->cmdid)) - { - ioctl_subhdlr = usockreq_ioctl_lwm2m; - } -#ifdef CONFIG_LTE_ALT1250_EXTEND_IOCTL - else if (LTE_ISCMDGRP_EXTEND(ltecmd->cmdid)) - { - ioctl_subhdlr = usockreq_ioctl_extend; - } -#endif - - if (ioctl_subhdlr != NULL) - { - ret = ioctl_subhdlr(dev, req, usock_result, usock_xid, ackinfo); - } - - return ret; -} - diff --git a/lte/alt1250/usock_handlers/alt1250_ioctl_lwm2m.c b/lte/alt1250/usock_handlers/alt1250_ioctl_lwm2m.c deleted file mode 100644 index 3e76e43bd..000000000 --- a/lte/alt1250/usock_handlers/alt1250_ioctl_lwm2m.c +++ /dev/null @@ -1,966 +0,0 @@ -/**************************************************************************** - * apps/lte/alt1250/usock_handlers/alt1250_ioctl_lwm2m.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -#include -#include - -#include "alt1250_dbg.h" -#include "alt1250_container.h" -#include "alt1250_atcmd.h" -#include "alt1250_ioctl_subhdlr.h" -#include "alt1250_usrsock_hdlr.h" - -#include - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * name: atcmdreply_getepname - ****************************************************************************/ - -static int atcmdreply_getepname(FAR struct alt1250_s *dev, - FAR struct alt_container_s *reply, - FAR char *rdata, int len, unsigned long arg, - FAR int32_t *usock_result) -{ - char *name; - void **param = (void **)arg; - char *outbuf = (char *)param[0]; - int outbuflen = (int)param[1]; - - *usock_result = check_atreply_ok(rdata, len, NULL); - if (*usock_result == OK) - { - name = strtok_r(rdata, " \r\n", &rdata); - if (name) - { - memset(outbuf, 0, outbuflen); - strncpy(outbuf, name, outbuflen); - *usock_result = outbuf[outbuflen - 1] == 0 - ? strlen(outbuf) : outbuflen; - } - } - - return REP_SEND_ACK; -} - -/**************************************************************************** - * name: strcpy_until - ****************************************************************************/ - -static char strcpy_until(char *dst, int n, char **src, char *delim) -{ - char *tmp = *src; - - if (dst) - { - dst[n - 1] = '\0'; - n--; - } - - while (*tmp && !strchr(delim, *tmp)) - { - if (dst && (n > 0)) - { - *dst++ = *tmp; - n--; - } - - tmp++; - } - - if (dst && (n > 0)) - { - *dst = '\0'; - } - - *src = tmp + 1; - - return *tmp; -} - -/**************************************************************************** - * name: atcmdreply_getsrvinfo_step4 - ****************************************************************************/ - -static int atcmdreply_getsrvinfo_step4(FAR struct alt1250_s *dev, - FAR struct alt_container_s *reply, - FAR char *rdata, int len, unsigned long arg, - FAR int32_t *usock_result) -{ - char *tmp; - int ret = REP_SEND_ACK; - FAR struct lwm2mstub_serverinfo_s *info - = (FAR struct lwm2mstub_serverinfo_s *)(((void **)arg)[0]); - - *usock_result = -EIO; - - if (check_atreply_ok(rdata, len, NULL) == OK) - { - info->object_inst = 0; - - if ((tmp = strstr(rdata, "%LWM2MCMD: ")) != NULL) - { - tmp += strlen("%LWM2MCMD: "); - info->nonip = strstr(tmp, "\"N\"") ? true : false; - - *usock_result = 0; - } - } - - return ret; -} - -/**************************************************************************** - * name: atcmdreply_getsrvinfo_step3 - ****************************************************************************/ - -static int atcmdreply_getsrvinfo_step3(FAR struct alt1250_s *dev, - FAR struct alt_container_s *reply, - FAR char *rdata, int len, unsigned long arg, - FAR int32_t *usock_result) -{ - char *tmp; - int ret = REP_SEND_ACK; - FAR struct lwm2mstub_serverinfo_s *info - = (FAR struct lwm2mstub_serverinfo_s *)(((void **)arg)[0]); - - *usock_result = -EIO; - - if (check_atreply_ok(rdata, len, NULL) == OK) - { - info->object_inst = 0; - - if ((tmp = strstr(rdata, "%LWM2MCMD: ")) != NULL) - { - tmp += strlen("%LWM2MCMD: "); - strcpy_until(NULL, 0, &tmp, ","); - strcpy_until(NULL, 0, &tmp, ","); - strcpy_until(NULL, 0, &tmp, ","); - strcpy_until(NULL, 0, &tmp, ","); - info->security_mode = atoi(tmp); - - ret = lwm2mstub_send_getresource(dev, reply, - CONTAINER_SOCKETID(reply), - atcmdreply_getsrvinfo_step4, - arg, usock_result, "1,0,22"); - } - } - - return ret; -} - -/**************************************************************************** - * name: atcmdreply_getsrvinfo_step2 - ****************************************************************************/ - -static int atcmdreply_getsrvinfo_step2(FAR struct alt1250_s *dev, - FAR struct alt_container_s *reply, - FAR char *rdata, int len, unsigned long arg, - FAR int32_t *usock_result) -{ - char *tmp; - int ret = REP_SEND_ACK; - FAR struct lwm2mstub_serverinfo_s *info - = (FAR struct lwm2mstub_serverinfo_s *)(((void **)arg)[0]); - - *usock_result = -EIO; - - if (check_atreply_ok(rdata, len, NULL) == OK) - { - info->object_inst = 0; - - if ((tmp = strstr(rdata, "%LWM2MCMD: ")) != NULL) - { - tmp += strlen("%LWM2MCMD: "); - info->bootstrap = strstr(tmp, "\"false\"") ? false : true; - - ret = lwm2mstub_send_getresource(dev, reply, - CONTAINER_SOCKETID(reply), - atcmdreply_getsrvinfo_step3, - arg, usock_result, "0,0,2"); - } - } - - return ret; -} - -/**************************************************************************** - * name: atcmdreply_getsrvinfo_step1 - ****************************************************************************/ - -static int atcmdreply_getsrvinfo_step1(FAR struct alt1250_s *dev, - FAR struct alt_container_s *reply, - FAR char *rdata, int len, unsigned long arg, - FAR int32_t *usock_result) -{ - char *tmp; - int ret = REP_SEND_ACK; - - FAR struct lwm2mstub_serverinfo_s *info - = (FAR struct lwm2mstub_serverinfo_s *)(((void **)arg)[0]); - - *usock_result = -EIO; - - /* Expected reply format - * %LWM2MCMD: ,,,, - */ - - if (check_atreply_ok(rdata, len, NULL) == OK) - { - info->object_inst = 0; - info->device_id[0] = '\0'; - info->security_key[0] = '\0'; - - if ((tmp = strstr(rdata, "%LWM2MCMD: ")) != NULL) - { - tmp += strlen("%LWM2MCMD: "); - - strcpy_until(info->server_uri, LWM2MSTUB_MAX_SERVER_NAME, - &tmp, ",\r\n"); - strcpy_until(NULL, 0, &tmp, ",\r\n"); /* Skip Server ID */ - strcpy_until(NULL, 0, &tmp, ",\r\n"); /* Skip Life time */ - strcpy_until(NULL, 0, &tmp, ",\r\n"); /* Skip Binding */ - info->state = atoi(tmp); - - ret = lwm2mstub_send_getresource(dev, reply, - CONTAINER_SOCKETID(reply), - atcmdreply_getsrvinfo_step2, - arg, usock_result, "0,0,1"); - } - } - - return ret; -} - -/**************************************************************************** - * name: atcmdreply_getenobjnum - ****************************************************************************/ - -static int atcmdreply_getenobjnum(FAR struct alt1250_s *dev, - FAR struct alt_container_s *reply, - FAR char *rdata, int len, unsigned long arg, - FAR int32_t *usock_result) -{ - *usock_result = -EIO; - - if (check_atreply_ok(rdata, len, NULL) == OK) - { - *usock_result = 1; - - rdata += 2; /* avoid "\r\n" */ - while (*rdata != '\r') - { - if (*rdata == ';') - { - (*usock_result)++; - } - - rdata++; - } - } - - return REP_SEND_ACK; -} - -/**************************************************************************** - * name: atcmdreply_getenobjects - ****************************************************************************/ - -static int atcmdreply_getenobjects(FAR struct alt1250_s *dev, - FAR struct alt_container_s *reply, - FAR char *rdata, int len, unsigned long arg, - FAR int32_t *usock_result) -{ - int i; - FAR uint16_t *objids = (FAR uint16_t *)(((void **)arg)[0]); - int objnum = (int)(((void **)arg)[1]); - - *usock_result = -EIO; - - if (check_atreply_ok(rdata, len, NULL) == OK) - { - i = 0; - rdata += 2; /* avoid "\r\n" */ - objids[i++] = atoi(rdata); - while (strcpy_until(NULL, 0, &rdata, ";\r\n") == ';' && i < objnum) - { - objids[i++] = atoi(rdata); - } - - *usock_result = i; - } - - return REP_SEND_ACK; -} - -/**************************************************************************** - * name: atcmdreply_getobjresnum - ****************************************************************************/ - -static int atcmdreply_getobjresnum(FAR struct alt1250_s *dev, - FAR struct alt_container_s *reply, - FAR char *rdata, int len, unsigned long arg, - FAR int32_t *usock_result) -{ - char term; - - *usock_result = -ENODEV; - - if (check_atreply_ok(rdata, len, NULL) == OK) - { - *usock_result = -EIO; - if ((rdata = strstr(rdata, "%OBJECTDEF: ")) != NULL) - { - *usock_result = 0; - rdata += strlen("%OBJECTDEF: "); - term = ','; - while (term == ',') - { - if ((term = strcpy_until(NULL, 0, &rdata, ",\r\n")) == ',' - && (term = strcpy_until(NULL, 0, &rdata, ",\r\n")) == ',' - && (term = strcpy_until(NULL, 0, &rdata, ",\r\n")) == ',' - && (term = strcpy_until(NULL, 0, &rdata, ",\r\n")) == ',') - { - /* the commas must be 4 for one resource definitions */ - - (*usock_result)++; - } - } - } - } - - return REP_SEND_ACK; -} - -/**************************************************************************** - * name: resoperation_code - ****************************************************************************/ - -static int resoperation_code(const char *s) -{ - return s[0] == 'W' ? LWM2MSTUB_RESOP_WRITE : - s[0] == 'X' ? LWM2MSTUB_RESOP_EXEC : - s[0] != 'R' ? -1 : - s[1] == 'W' ? LWM2MSTUB_RESOP_RW : LWM2MSTUB_RESOP_READ; -} - -/**************************************************************************** - * name: resdatatype_code - ****************************************************************************/ - -static int resdatatype_code(const char *s) -{ - int ret = -1; - - if (!strcmp(s, "\"none\"")) - { - ret = LWM2MSTUB_RESDATA_NONE; - } - else if (!strcmp(s, "str")) - { - ret = LWM2MSTUB_RESDATA_STRING; - } - else if (!strcmp(s, "int")) - { - ret = LWM2MSTUB_RESDATA_INT; - } - else if (!strcmp(s, "uint")) - { - ret = LWM2MSTUB_RESDATA_UNSIGNED; - } - else if (!strcmp(s, "flt")) - { - ret = LWM2MSTUB_RESDATA_FLOAT; - } - else if (!strcmp(s, "bool")) - { - ret = LWM2MSTUB_RESDATA_BOOL; - } - else if (!strcmp(s, "opq")) - { - ret = LWM2MSTUB_RESDATA_OPAQUE; - } - else if (!strcmp(s, "time")) - { - ret = LWM2MSTUB_RESDATA_TIME; - } - else if (!strcmp(s, "ol")) - { - ret = LWM2MSTUB_RESDATA_OBJLINK; - } - - return ret; -} - -/**************************************************************************** - * name: atcmdreply_getobjdef - ****************************************************************************/ - -static int atcmdreply_getobjdef(FAR struct alt1250_s *dev, - FAR struct alt_container_s *reply, - FAR char *rdata, int len, unsigned long arg, - FAR int32_t *usock_result) -{ - char tmp[8]; - char term; - FAR struct lwm2mstub_resource_s *reses - = (FAR struct lwm2mstub_resource_s *)(((void **)arg)[0]); - int resnum = (int)(((void **)arg)[1]); - - *usock_result = -ENODEV; - - if (check_atreply_ok(rdata, len, NULL) == OK) - { - *usock_result = -EIO; - if ((rdata = strstr(rdata, "%OBJECTDEF: ")) != NULL) - { - *usock_result = 0; - rdata += strlen("%OBJECTDEF: "); - term = strcpy_until(NULL, 0, &rdata, ",\r\n"); - - /* ,,,, */ - - while (term == ',' && *usock_result < resnum) - { - reses[*usock_result].res_id = atoi(rdata); - term = strcpy_until(NULL, 0, &rdata, ",\r\n"); - - term = strcpy_until(tmp, 8, &rdata, ",\r\n"); - reses[*usock_result].operation = resoperation_code(tmp); - - reses[*usock_result].inst_type = atoi(rdata); - term = strcpy_until(NULL, 0, &rdata, ",\r\n"); - - term = strcpy_until(tmp, 8, &rdata, ",\r\n"); - reses[*usock_result].data_type = resdatatype_code(tmp); - - (*usock_result)++; - } - } - } - - return REP_SEND_ACK; -} - -/**************************************************************************** - * name: atcmdreply_getrat - ****************************************************************************/ - -static int atcmdreply_getrat(FAR struct alt1250_s *dev, - FAR struct alt_container_s *reply, - FAR char *rdata, int len, unsigned long arg, - FAR int32_t *usock_result) -{ - *usock_result = -ENODEV; - - if (check_atreply_ok(rdata, len, NULL) == OK) - { - *usock_result = -EIO; - if (strstr(rdata, "CATM") != NULL) - { - *usock_result = LTE_RAT_CATM; - } - else if (strstr(rdata, "NBIOT") != NULL) - { - *usock_result = LTE_RAT_NBIOT; - } - } - - return REP_SEND_ACK; -} - -/**************************************************************************** - * name: atcmdreply_setsrvinfo_step4 - ****************************************************************************/ - -static int atcmdreply_setsrvinfo_step4(FAR struct alt1250_s *dev, - FAR struct alt_container_s *reply, - FAR char *rdata, int len, unsigned long arg, - FAR int32_t *usock_result) -{ - int ret = REP_SEND_ACK; - - *usock_result = -EIO; - - if (check_atreply_ok(rdata, len, NULL) == OK) - { - ret = lwm2mstub_send_bsdone(dev, reply, CONTAINER_SOCKETID(reply), - usock_result); - } - - return ret; -} - -/**************************************************************************** - * name: atcmdreply_setsrvinfo_step3 - ****************************************************************************/ - -static int atcmdreply_setsrvinfo_step3(FAR struct alt1250_s *dev, - FAR struct alt_container_s *reply, - FAR char *rdata, int len, unsigned long arg, - FAR int32_t *usock_result) -{ - int ret = REP_SEND_ACK; - - *usock_result = -EIO; - - if (check_atreply_ok(rdata, len, NULL) == OK) - { - ret = lwm2mstub_send_bscreateobj1(dev, reply, - CONTAINER_SOCKETID(reply), - atcmdreply_setsrvinfo_step4, arg, - usock_result, - (FAR struct lwm2mstub_serverinfo_s *)arg); - } - - return ret; -} - -/**************************************************************************** - * name: atcmdreply_setsrvinfo_step2 - ****************************************************************************/ - -static int atcmdreply_setsrvinfo_step2(FAR struct alt1250_s *dev, - FAR struct alt_container_s *reply, - FAR char *rdata, int len, unsigned long arg, - FAR int32_t *usock_result) -{ - int ret = REP_SEND_ACK; - - *usock_result = -EIO; - - if (check_atreply_ok(rdata, len, NULL) == OK) - { - ret = lwm2mstub_send_bscreateobj0(dev, reply, - CONTAINER_SOCKETID(reply), - atcmdreply_setsrvinfo_step3, arg, - usock_result, - (FAR struct lwm2mstub_serverinfo_s *)arg); - } - - return ret; -} - -/**************************************************************************** - * name: atcmdreply_setsrvinfo_step1 - ****************************************************************************/ - -static int atcmdreply_setsrvinfo_step1(FAR struct alt1250_s *dev, - FAR struct alt_container_s *reply, - FAR char *rdata, int len, unsigned long arg, - FAR int32_t *usock_result) -{ - int ret = REP_SEND_ACK; - - *usock_result = -EIO; - - if (check_atreply_ok(rdata, len, NULL) == OK) - { - ret = lwm2mstub_send_bsdelete(dev, reply, CONTAINER_SOCKETID(reply), - atcmdreply_setsrvinfo_step2, arg, usock_result); - } - - return ret; -} - -/**************************************************************************** - * name: perform_m2m_applysetting - ****************************************************************************/ - -static int perform_m2m_applysetting(FAR struct alt1250_s *dev, - FAR int32_t *usock_result, - uint32_t xid) -{ - dbg_alt1250("%s called\n", __func__); - - if (dev->lwm2m_apply_xid >= 0) - { - *usock_result = -EINPROGRESS; - dbg_alt1250("Apply is in progress\n"); - return REP_SEND_ACK; - } - - *usock_result = OK; - dev->lwm2m_apply_xid = xid; - - MODEM_STATE_INTENTRST(dev); - altdevice_reset(dev->altfd); - - return REP_NO_ACK; /* Ack is replied after received reset event */ -} - -/**************************************************************************** - * name: commands_on_any_state - ****************************************************************************/ - -static int commands_on_any_state(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - FAR struct usock_s *usock, - FAR struct lte_ioctl_data_s *ltecmd, - FAR int32_t *usock_result) -{ - int ret = REP_SEND_ACK; - - switch (ltecmd->cmdid) - { - case LTE_CMDID_LWM2M_GETEP: - ret = lwm2mstub_send_getepname(dev, container, - USOCKET_USOCKID(usock), - atcmdreply_getepname, - (unsigned long)ltecmd->outparam, - usock_result); - break; - - case LTE_CMDID_LWM2M_GETSRVNUM: - *usock_result = -EOPNOTSUPP; - break; - - case LTE_CMDID_LWM2M_GETSRVINFO: - ret = lwm2mstub_send_getsrvinfo(dev, container, - USOCKET_USOCKID(usock), - atcmdreply_getsrvinfo_step1, - (unsigned long)ltecmd->outparam, - usock_result); - break; - - case LTE_CMDID_LWM2M_GETACTIVEOBJNUM: - ret = lwm2mstub_send_getsupobjs(dev, container, - USOCKET_USOCKID(usock), - atcmdreply_getenobjnum, 0, - usock_result); - break; - - case LTE_CMDID_LWM2M_GETACTIVEOBJ: - ret = lwm2mstub_send_getsupobjs(dev, container, - USOCKET_USOCKID(usock), - atcmdreply_getenobjects, - (unsigned long)ltecmd->outparam, - usock_result); - break; - - case LTE_CMDID_LWM2M_GETOBJRESNUM: - ret = lwm2mstub_send_getobjdef(dev, container, - USOCKET_USOCKID(usock), - atcmdreply_getobjresnum, - 0, usock_result, - *((uint16_t *)ltecmd->inparam)); - break; - - case LTE_CMDID_LWM2M_GETOBJRESOURCE: - ret = lwm2mstub_send_getobjdef(dev, container, - USOCKET_USOCKID(usock), - atcmdreply_getobjdef, - (unsigned long)ltecmd->outparam, - usock_result, - *((uint16_t *)ltecmd->inparam)); - break; - - case LTE_CMDID_LWM2M_GETRAT: - ret = lwm2mstub_send_getrat(dev, container, - USOCKET_USOCKID(usock), - atcmdreply_getrat, - (unsigned long)ltecmd->outparam, - usock_result); - break; - - case LTE_CMDID_LWM2M_GETQMODE: - ret = lwm2mstub_send_getqueuemode(dev, container, - USOCKET_USOCKID(usock), - usock_result); - break; - } - - return ret; -} - -/**************************************************************************** - * name: commands_on_poweron_state - ****************************************************************************/ - -static int commands_on_poweron_state(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - FAR struct usock_s *usock, - FAR struct lte_ioctl_data_s *ltecmd, - FAR int32_t *usock_result) -{ - int ret; - - switch (ltecmd->cmdid) - { - case LTE_CMDID_LWM2M_SETEP: - ret = lwm2mstub_send_setepname( - dev, container, USOCKET_USOCKID(usock), - usock_result, (const char *)ltecmd->inparam); - break; - - case LTE_CMDID_LWM2M_SETSRVINFO: - ret = lwm2mstub_send_bsstart( - dev, container, USOCKET_USOCKID(usock), - atcmdreply_setsrvinfo_step1, - (unsigned long)ltecmd->inparam[0], - usock_result); - break; - - case LTE_CMDID_LWM2M_SETACTIVEOBJ: - ret = lwm2mstub_send_setsupobjs( - dev, container, USOCKET_USOCKID(usock), - usock_result, - (uint16_t *)ltecmd->inparam[0], (int)ltecmd->inparam[1]); - break; - - case LTE_CMDID_LWM2M_SETOBJRESOURCE: - ret = lwm2mstub_send_setobjdef( - dev, container, USOCKET_USOCKID(usock), - usock_result, (uint16_t)(uint32_t)ltecmd->inparam[0], - (int)ltecmd->inparam[1], - (struct lwm2mstub_resource_s *)ltecmd->inparam[2]); - break; - - case LTE_CMDID_LWM2M_CHANGERAT: - ret = lwm2mstub_send_changerat(dev, container, - USOCKET_USOCKID(usock), - usock_result, - *((int *)ltecmd->inparam)); - break; - - case LTE_CMDID_LWM2M_SETQMODE: - ret = lwm2mstub_send_setqueuemode(dev, container, - USOCKET_USOCKID(usock), - usock_result, - (int)ltecmd->inparam); - break; - - case LTE_CMDID_LWM2M_APPLY_SETTING: - ret = perform_m2m_applysetting(dev, usock_result, - USOCKET_XID(usock)); - break; - - default: - ret = commands_on_any_state(dev, container, usock, ltecmd, - usock_result); - break; - } - - return ret; -} - -/**************************************************************************** - * name: commands_on_radioon_state - ****************************************************************************/ - -static int commands_on_radioon_state(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - FAR struct usock_s *usock, - FAR struct lte_ioctl_data_s *ltecmd, - FAR int32_t *usock_result) -{ - int ret; - - switch (ltecmd->cmdid) - { - case LTE_CMDID_LWM2M_CONNECT: - ret = lwm2mstub_send_registration( - dev, container, USOCKET_USOCKID(usock), usock_result, - (int)ltecmd->inparam - ); - break; - - case LTE_CMDID_LWM2M_READRESP: - ret = lwm2mstub_send_evrespwvalue( - dev, container, USOCKET_USOCKID(usock), usock_result, - (int)ltecmd->inparam[0], - (int)ltecmd->inparam[1], - (struct lwm2mstub_instance_s *)ltecmd->inparam[2], - (char *)ltecmd->inparam[3] - ); - break; - - case LTE_CMDID_LWM2M_WRITERESP: - ret = lwm2mstub_send_evresponse( - dev, container, USOCKET_USOCKID(usock), usock_result, - (int)ltecmd->inparam[0], - (int)ltecmd->inparam[1], - (struct lwm2mstub_instance_s *)ltecmd->inparam[2] - ); - break; - - case LTE_CMDID_LWM2M_OBSERVERESP: - ret = lwm2mstub_send_evrespwoinst( - dev, container, USOCKET_USOCKID(usock), usock_result, - (int)ltecmd->inparam[0], - (int)ltecmd->inparam[1] - ); - break; - - case LTE_CMDID_LWM2M_EXECRESP: - ret = lwm2mstub_send_evresponse( - dev, container, USOCKET_USOCKID(usock), usock_result, - (int)ltecmd->inparam[0], - (int)ltecmd->inparam[1], - (struct lwm2mstub_instance_s *)ltecmd->inparam[2] - ); - break; - - case LTE_CMDID_LWM2M_OBSERVEUPDATE: - ret = lwm2mstub_send_objevent( - dev, container, USOCKET_USOCKID(usock), usock_result, - (char *)ltecmd->inparam[0], - (struct lwm2mstub_instance_s *)ltecmd->inparam[1], - (char *)ltecmd->inparam[2] - ); - break; - - default: - ret = commands_on_any_state(dev, container, usock, ltecmd, - usock_result); - break; - } - - return ret; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * name: send_m2mnotice_command - ****************************************************************************/ - -int send_m2mnotice_command(uint32_t cmdid, - FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - FAR struct usock_s *usock, - FAR struct lte_ioctl_data_s *ltecmd, - FAR int32_t *ures) -{ - int ret = REP_SEND_ACK; - *ures = OK; - - switch (cmdid) - { - case LTE_CMDID_LWM2M_READ_EVT: - case LTE_CMDID_LWM2M_WRITE_EVT: - case LTE_CMDID_LWM2M_EXEC_EVT: - case LTE_CMDID_LWM2M_OVSTART_EVT: - case LTE_CMDID_LWM2M_OVSTOP_EVT: - - /* TODO: Now unregister any events makes all event notify stop. - * This will be fixed in near future. - */ - - ret = lwm2mstub_send_m2mobjcmd( - dev, container, USOCKET_USOCKID(usock), ures, - (ltecmd->cb != NULL)); - break; - - case LTE_CMDID_LWM2M_SERVEROP_EVT: - ret = lwm2mstub_send_m2mopev( - dev, container, USOCKET_USOCKID(usock), ures, - (ltecmd->cb != NULL)); - break; - - case LTE_CMDID_LWM2M_FWUP_EVT: - ret = lwm2mstub_send_m2mev( - dev, container, USOCKET_USOCKID(usock), ures, - (ltecmd->cb != NULL)); - break; - - default: - *ures = -EINVAL; - break; - } - - return ret; -} - -/**************************************************************************** - * name: usockreq_ioctl_lwm2m - ****************************************************************************/ - -int usockreq_ioctl_lwm2m(FAR struct alt1250_s *dev, - FAR struct usrsock_request_buff_s *req, - FAR int32_t *ures, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo) -{ - FAR struct usrsock_request_ioctl_s *request = &req->request.ioctl_req; - FAR struct lte_ioctl_data_s *ltecmd = &req->req_ioctl.ltecmd; - FAR struct usock_s *usock = NULL; - FAR struct alt_container_s *container; - int ret = REP_SEND_ACK_WOFREE; - - dbg_alt1250("%s called with : %08lx\n", __func__, ltecmd->cmdid); - - *ures = -EOPNOTSUPP; - *usock_xid = request->head.xid; - - if (dev->is_support_lwm2m) - { - usock = usocket_search(dev, request->usockid); - if (usock == NULL) - { - *ures = -EBADFD; - return ret; - } - - container = container_alloc(); - if (container == NULL) - { - return REP_NO_CONTAINER; - } - - *ures = -EINVAL; - ret = REP_SEND_ACK; - USOCKET_SET_REQUEST(usock, request->head.reqid, request->head.xid); - - if (MODEM_STATE_IS_PON(dev)) - { - /* These commands is available just in power on state */ - - ret = commands_on_poweron_state(dev, container, usock, ltecmd, - ures); - } - else if (MODEM_STATE_IS_RON(dev)) - { - ret = commands_on_radioon_state(dev, container, usock, ltecmd, - ures); - } - - if (IS_NEED_CONTAINER_FREE(ret)) - { - container_free(container); - } - } - - return ret; -} diff --git a/lte/alt1250/usock_handlers/alt1250_ioctl_normal.c b/lte/alt1250/usock_handlers/alt1250_ioctl_normal.c deleted file mode 100644 index 90b3a678f..000000000 --- a/lte/alt1250/usock_handlers/alt1250_ioctl_normal.c +++ /dev/null @@ -1,582 +0,0 @@ -/**************************************************************************** - * apps/lte/alt1250/usock_handlers/alt1250_ioctl_normal.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include - -#include "alt1250_dbg.h" -#include "alt1250_container.h" -#include "alt1250_socket.h" -#include "alt1250_usockevent.h" -#include "alt1250_postproc.h" -#include "alt1250_devif.h" -#include "alt1250_evt.h" -#include "alt1250_util.h" -#include "alt1250_ioctl_subhdlr.h" -#include "alt1250_usrsock_hdlr.h" -#include "alt1250_netdev.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define RADIOON_SYNC (0) -#define RADIOON_ASYNC (1) - -#define REPLY_RETCODE(rep, altrep) (((rep) == 0) ? (altrep) : (rep)) - -/* RK_02_01_01_10xxx FW version that does not support logging feature */ - -#define IS_LOG_UNAVAIL_FWVERSION(d) (!strncmp(MODEM_FWVERSION(d), \ - "RK_02_01_01", 11)) - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -#ifdef CONFIG_LTE_ALT1250_ENABLE_HIBERNATION_MODE -static int send_resume_command(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - FAR struct usock_s *usock, - FAR int32_t *usock_result, - int index); -#endif - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * name: postproc_reportnet - ****************************************************************************/ - -static int postproc_reportnet(FAR struct alt1250_s *dev, - FAR struct alt_container_s *reply, - FAR struct usock_s *usock, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo, - unsigned long is_async) -{ - FAR void **resp = CONTAINER_RESPONSE(reply); - int altcom_result = *((int *)(resp[0])); - - dbg_alt1250("%s start\n", __func__); - - *usock_result = REPLY_RETCODE(CONTAINER_RESPRES(reply), altcom_result); - - return (is_async) ? REP_NO_ACK: REP_SEND_ACK; -} - -/**************************************************************************** - * name: postproc_radioon - ****************************************************************************/ - -static int postproc_radioon(FAR struct alt1250_s *dev, - FAR struct alt_container_s *reply, - FAR struct usock_s *usock, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo, - unsigned long arg) -{ - int ret = REP_SEND_ACK; - FAR void **resp = CONTAINER_RESPONSE(reply); - int altcom_result = *((int *)(resp[0])); - - dbg_alt1250("%s start\n", __func__); - - *usock_result = REPLY_RETCODE(CONTAINER_RESPRES(reply), altcom_result); - - if (*usock_result == 0) - { - ret = send_reportnet_command(dev, reply, usock, postproc_reportnet, - arg, usock_result); - - MODEM_STATE_RON(dev); - } - - return ret; -} - -/**************************************************************************** - * name: postproc_actpdn - ****************************************************************************/ - -static int postproc_actpdn(FAR struct alt1250_s *dev, - FAR struct alt_container_s *reply, - FAR struct usock_s *usock, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo, - unsigned long is_async) -{ - FAR void **resp = CONTAINER_RESPONSE(reply); - int altcom_result = *((int *)(resp[0])); - FAR lte_pdn_t *pdn = resp[1]; - - dbg_alt1250("%s start\n", __func__); - - *usock_result = REPLY_RETCODE(CONTAINER_RESPRES(reply), altcom_result); - - if (*usock_result == 0) - { - /* After connecting to the LTE network, - * wait for the modem to register the network interface. - */ - - usleep(ALT1250_NETIF_READY_DELAY); - alt1250_netdev_ifup(dev, pdn); - } - - return (is_async) ? REP_NO_ACK: REP_SEND_ACK; -} - -/**************************************************************************** - * name: postproc_fwgetversion - ****************************************************************************/ - -int postproc_fwgetversion(FAR struct alt1250_s *dev, - FAR struct alt_container_s *reply, - FAR struct usock_s *usock, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo, - unsigned long arg) -{ - FAR void **resp = CONTAINER_RESPONSE(reply); - int altcom_result = *((int *)(resp[0])); - lte_version_t *version = (lte_version_t *)(resp[1]); - - dbg_alt1250("%s start\n", __func__); - - *usock_result = REPLY_RETCODE(CONTAINER_RESPRES(reply), altcom_result); - - if (*usock_result == 0) - { - /* Keep version information on the device context */ - - strncpy(dev->fw_version, version->np_package, LTE_VER_NP_PACKAGE_LEN); - } - - return usock ? REP_SEND_ACK : REP_NO_ACK; -} - -/**************************************************************************** - * name: send_lapi_command - ****************************************************************************/ - -int send_lapi_command(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - FAR struct usock_s *usock, - FAR struct lte_ioctl_data_s *ltecmd, - FAR postproc_hdlr_t hdlr, - unsigned long priv, - FAR int32_t *usock_result) -{ - set_container_ids(container, USOCKET_USOCKID(usock), ltecmd->cmdid); - set_container_argument(container, ltecmd->inparam, ltecmd->inparamlen); - set_container_response(container, ltecmd->outparam, ltecmd->outparamlen); - set_container_postproc(container, hdlr, priv); - - return altdevice_send_command(dev, dev->altfd, container, usock_result); -} - -#ifdef CONFIG_LTE_ALT1250_ENABLE_HIBERNATION_MODE -/**************************************************************************** - * name: postproc_setreport - ****************************************************************************/ - -static int postproc_setreport(FAR struct alt1250_s *dev, - FAR struct alt_container_s *reply, - FAR struct usock_s *usock, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo, - unsigned long arg) -{ - int index = (int)arg + 1; - - /* Register next report command */ - - return send_resume_command(dev, reply, usock, usock_result, index); -} - -/**************************************************************************** - * name: send_getversion_command - ****************************************************************************/ - -static int send_getversion_command(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - FAR struct usock_s *usock, - FAR int32_t *usock_result) -{ - set_container_ids(container, USOCKET_USOCKID(usock), LTE_CMDID_GETVER); - set_container_argument(container, NULL, 0); - set_container_response(container, alt1250_getevtarg(LTE_CMDID_GETVER), 2); - set_container_postproc(container, postproc_fwgetversion, 0); - - return altdevice_send_command(dev, dev->altfd, container, usock_result); -} - -/**************************************************************************** - * name: send_register_command - ****************************************************************************/ - -static int send_register_command(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - FAR struct usock_s *usock, - FAR int32_t *usock_result, - FAR struct lte_ioctl_data_s *ltecmd, - int index) -{ - set_container_ids(container, USOCKET_USOCKID(usock), ltecmd->cmdid); - set_container_argument(container, ltecmd->inparam, ltecmd->inparamlen); - set_container_response(container, ltecmd->outparam, ltecmd->outparamlen); - set_container_postproc(container, postproc_setreport, index); - - return altdevice_send_command(dev, dev->altfd, container, usock_result); -} - -/**************************************************************************** - * name: send_resume_command - ****************************************************************************/ - -static int send_resume_command(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - FAR struct usock_s *usock, - FAR int32_t *usock_result, - int index) -{ - int ret; - int cb_index = index; - uint32_t cmdid; - struct lte_ioctl_data_s ltecmd; - - /* Search report CB from table from index */ - - cmdid = alt1250_search_registered_callback(&cb_index); - if (cmdid != 0x00) - { - ret = alt1250_get_report_ltecmd(dev, cmdid, <ecmd); - if (ret == OK) - { - /* Register report command */ - - ret = send_register_command(dev, container, usock, usock_result, - <ecmd, cb_index); - } - else - { - *usock_result = ret; - ret = REP_SEND_ACK; - } - } - else - { - /* Finally, get firmware version from ALT1250 */ - - ret = send_getversion_command(dev, container, usock, usock_result); - } - - return ret; -} - -/**************************************************************************** - * name: lte_context_resume - ****************************************************************************/ - -static int lte_context_resume(FAR struct alt1250_s *dev, - FAR struct lte_ioctl_data_s *cmd, - FAR struct alt_container_s *container, - FAR struct usock_s *usock, - FAR int32_t *usock_result) -{ - FAR uint8_t *ctx_data = (FAR uint8_t *)cmd->inparam[0]; - int len = *(FAR int *)cmd->inparam[1]; - int ret = REP_SEND_ACK; - int power = 0; - - if (!dev->is_resuming) - { - dbg_alt1250("Modem is not in a resuming mode.\n"); - *usock_result = -EPERM; - goto error; - } - - if (len != sizeof(struct alt1250_save_ctx)) - { - dbg_alt1250("Context data size is invalid(%d!=%d).\n", - sizeof(struct alt1250_save_ctx), len); - *usock_result = -EINVAL; - goto error; - } - - ret = alt1250_apply_daemon_context(dev, - (FAR struct alt1250_save_ctx *) - ctx_data); - if (ret < 0) - { - dbg_alt1250("Failed to apply saved alt1250 context(%d).\n", ret); - *usock_result = -EINVAL; - goto error; - } - - /* Retry mode is released in order to resume reception from ALT 1250. */ - - ret = altdevice_powercontrol(dev->altfd, LTE_CMDID_RETRYDISABLE); - if (ret != OK) - { - dbg_alt1250("Failed to stop retry mode(%d).\n", ret); - *usock_result = ret; - ret = REP_SEND_ACK; - goto error; - } - - /* After the retry mode is disabled, the ALT1250 daemon can receive - * commands from the ALT1250 and the ALT1250 daemon is ready for normal - * operation, so the "is_resuming" flag is disabled. - */ - - dev->is_resuming = false; - - /* If the ALT1250 is not powered on, return Resume as failure. */ - - power = altdevice_powercontrol(dev->altfd, LTE_CMDID_GET_POWER_STAT); - if (!power) - { - dbg_alt1250("Modem is turned off.\n"); - *usock_result = -ENETDOWN; - return REP_SEND_ACK; - } - - /* Register events so that event notifications are made to the - * report-based Callbacks registered in advance with lte_set_report*(). - */ - - ret = send_resume_command(dev, container, usock, usock_result, 0); - - if (*usock_result != OK) - { - dbg_alt1250("Failed to send resume commands.\n"); - } - - return ret; - -error: - altdevice_powercontrol(dev->altfd, LTE_CMDID_POWEROFF); - - /* Resume phase is over */ - - dev->is_resuming = false; - - return ret; -} -#endif - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * name: usockreq_ioctl_normal - ****************************************************************************/ - -int usockreq_ioctl_normal(FAR struct alt1250_s *dev, - FAR struct usrsock_request_buff_s *req, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo) -{ - FAR struct usrsock_request_ioctl_s *request = &req->request.ioctl_req; - FAR struct lte_ioctl_data_s *ltecmd = &req->req_ioctl.ltecmd; - FAR struct usock_s *usock = NULL; - int ret = REP_SEND_ACK_WOFREE; - uint32_t cmdid = LTE_PURE_CMDID(ltecmd->cmdid); - FAR struct alt_container_s *container; - postproc_hdlr_t postproc_hdlr = NULL; - unsigned long priv = 0; - - dbg_alt1250("%s start\n", __func__); - - *usock_result = OK; - *usock_xid = request->head.xid; - - usock = usocket_search(dev, request->usockid); - if (usock == NULL) - { - dbg_alt1250("Failed to get socket context: %u\n", - request->usockid); - *usock_result = -EBADFD; - return REP_SEND_ACK_WOFREE; - } - - container = container_alloc(); - if (container == NULL) - { - dbg_alt1250("no container\n"); - return REP_NO_CONTAINER; - } - - if (LTE_IS_ASYNC_CMD(ltecmd->cmdid) && (ltecmd->cb != NULL)) - { - ret = alt1250_regevtcb(cmdid, ltecmd->cb); - if (ret < 0) - { - container_free(container); - *usock_result = ret; - return REP_SEND_ACK_WOFREE; - } - - ltecmd->outparam = alt1250_getevtarg(cmdid); - - /* The outparam is a array of "*void". - * In asynchronouse API case, the array size is known - * by container in the alt1250 driver. - * So don't need to set the outparamlen here. - */ - } - - switch (cmdid) - { - case LTE_CMDID_ACTPDN: - { - alt1250_saveapn(dev, (FAR lte_apn_setting_t *)ltecmd->inparam[0]); - - /* The handler is set for post process */ - - postproc_hdlr = postproc_actpdn; - priv = LTE_IS_ASYNC_CMD(ltecmd->cmdid); - } - break; - - case LTE_CMDID_DEACTPDN: - { - alt1250_netdev_ifdown(dev); - } - break; - - case LTE_CMDID_TLS_SSL_BIO: - { - /* Override socket id on input parameter from usock file descriptor - * to alt1250 device's socket descriptor - */ - - *(FAR int *)(ltecmd->inparam[5]) = USOCKET_ALTSOCKID(usock); - } - break; - - case LTE_CMDID_GETVER: - { - /* The handler is set for post process, - * but it will be avoided when the command is asynchronouse. - */ - - postproc_hdlr = postproc_fwgetversion; - } - break; - - case LTE_CMDID_RADIOON: - { - /* The handler is set for post process */ - - postproc_hdlr = postproc_radioon; - priv = LTE_IS_ASYNC_CMD(ltecmd->cmdid) ? - RADIOON_ASYNC : RADIOON_SYNC; - } - break; - -#ifdef CONFIG_LTE_ALT1250_ENABLE_HIBERNATION_MODE - case LTE_CMDID_RESUME: - return lte_context_resume(dev, ltecmd, container, usock, - usock_result); -#endif - - case LTE_CMDID_SAVE_LOG: - case LTE_CMDID_GET_LOGLIST: - case LTE_CMDID_LOGOPEN: - case LTE_CMDID_LOGCLOSE: - case LTE_CMDID_LOGREAD: - case LTE_CMDID_LOGLSEEK: - case LTE_CMDID_LOGREMOVE: - { - if (IS_LOG_UNAVAIL_FWVERSION(dev)) - { - container_free(container); - *usock_result = -ENOTSUP; - return REP_SEND_ACK_WOFREE; - } - } - break; - - case LTE_CMDID_RADIOOFF: - { - MODEM_STATE_PON(dev); - alt1250_netdev_ifdown(dev); - } - break; - - default: - break; - } - - USOCKET_SET_REQUEST(usock, request->head.reqid, request->head.xid); - ret = send_lapi_command(dev, container, usock, ltecmd, postproc_hdlr, priv, - usock_result); - - if (IS_NEED_CONTAINER_FREE(ret)) - { - container_free(container); - } - - if (*usock_result < 0) - { - /* In error case, clear callback */ - - if (LTE_IS_ASYNC_CMD(ltecmd->cmdid) && (ltecmd->cb != NULL)) - { - alt1250_regevtcb(cmdid, NULL); - } - } - else if ((ltecmd->cmdid == LTE_CMDID_ACTPDN) || - (cmdid == LTE_CMDID_TLS_SSL_HANDSHAKE)) - { - /* The request from usersock cannot be accepted until the - * response is returned, so the REP_SEND_INPROG is returned - * to delay usock response and make this daemon to be able - * to handle other requests. - */ - - ret = REP_SEND_INPROG; - } - else if (LTE_IS_ASYNC_CMD(ltecmd->cmdid)) - { - ret = REP_SEND_ACK_WOFREE; - } - - return ret; -} diff --git a/lte/alt1250/usock_handlers/alt1250_ioctl_other.c b/lte/alt1250/usock_handlers/alt1250_ioctl_other.c deleted file mode 100644 index 057553a5c..000000000 --- a/lte/alt1250/usock_handlers/alt1250_ioctl_other.c +++ /dev/null @@ -1,251 +0,0 @@ -/**************************************************************************** - * apps/lte/alt1250/usock_handlers/alt1250_ioctl_other.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -#include "alt1250_dbg.h" -#include "alt1250_container.h" -#include "alt1250_socket.h" -#include "alt1250_usockevent.h" -#include "alt1250_postproc.h" -#include "alt1250_devif.h" -#include "alt1250_evt.h" -#include "alt1250_util.h" -#include "alt1250_ioctl_subhdlr.h" - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * name: perform_setrestart - ****************************************************************************/ - -static int perform_setrestart(FAR struct alt1250_s *dev, - FAR struct usrsock_request_buff_s *req, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo) -{ - FAR struct lte_ioctl_data_s *ltecmd = &req->req_ioctl.ltecmd; - - *usock_result = alt1250_regevtcb(ltecmd->cmdid, ltecmd->cb); - - return REP_SEND_ACK_WOFREE; -} - -/**************************************************************************** - * name: perform_seteventctx - ****************************************************************************/ - -static int perform_seteventctx(FAR struct alt1250_s *dev, - FAR struct usrsock_request_buff_s *req, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo) -{ - FAR struct lte_ioctl_data_s *ltecmd = &req->req_ioctl.ltecmd; - FAR struct lte_evtctx_in_s *in = ltecmd->inparam[0]; - FAR struct lte_evtctx_out_s *out = ltecmd->outparam[0]; - - if ((in != NULL) && (in->mqname != NULL) && (out != NULL)) - { - /* No need to check strlen here. - * On current NuttX(v10.1) checks strlen of mssage queue name - * as MAX_MQUEUE_PATH. - */ - - *usock_result = alt1250_evttask_msgconnect(in->mqname, dev); - out->handle = alt1250_execcb; - } - - return REP_SEND_ACK_WOFREE; -} - -/**************************************************************************** - * name: perform_geterrinfo - ****************************************************************************/ - -static int perform_geterrinfo(FAR struct alt1250_s *dev, - FAR struct usrsock_request_buff_s *req, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo) -{ - FAR struct lte_ioctl_data_s *ltecmd = &req->req_ioctl.ltecmd; - - void **arg = alt1250_getevtarg(LTE_CMDID_GETERRINFO); - - if (arg && arg[0] && ltecmd->outparam && ltecmd->outparam[0]) - { - memcpy(ltecmd->outparam[0], arg[0], sizeof(lte_errinfo_t)); - *usock_result = OK; - } - - return REP_SEND_ACK_WOFREE; -} - -/**************************************************************************** - * name: perform_saveapn - ****************************************************************************/ - -static int perform_saveapn(FAR struct alt1250_s *dev, - FAR struct usrsock_request_buff_s *req, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo) -{ - FAR struct lte_ioctl_data_s *ltecmd = &req->req_ioctl.ltecmd; - - if (ltecmd->inparam && ltecmd->inparam[0]) - { - alt1250_saveapn(dev, - (FAR lte_apn_setting_t *)(ltecmd->inparam[0])); - *usock_result = OK; - } - - return REP_SEND_ACK_WOFREE; -} - -/**************************************************************************** - * name: perform_getapn - ****************************************************************************/ - -static int perform_getapn(FAR struct alt1250_s *dev, - FAR struct usrsock_request_buff_s *req, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo) -{ - FAR struct lte_ioctl_data_s *ltecmd = &req->req_ioctl.ltecmd; - - if (ltecmd->outparam && ltecmd->outparam[0]) - { - alt1250_getapn(dev, - (FAR lte_apn_setting_t *)(ltecmd->outparam[0])); - *usock_result = OK; - } - - return REP_SEND_ACK_WOFREE; -} - -#ifdef CONFIG_LTE_ALT1250_ENABLE_HIBERNATION_MODE -/**************************************************************************** - * name: perform_setctxcb - ****************************************************************************/ - -static int perform_setctxcb(FAR struct alt1250_s *dev, - FAR struct usrsock_request_buff_s *req, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo) -{ - FAR struct lte_ioctl_data_s *ltecmd = &req->req_ioctl.ltecmd; - - *usock_result = alt1250_set_context_save_cb(dev, ltecmd->cb); - - return REP_SEND_ACK_WOFREE; -} -#endif - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * name: alt1250_geterrinfo - ****************************************************************************/ - -void alt1250_geterrinfo(FAR lte_errinfo_t *errinfo) -{ - void **arg = alt1250_getevtarg(LTE_CMDID_GETERRINFO); - - if (arg && arg[0]) - { - memcpy(errinfo, arg[0], sizeof(lte_errinfo_t)); - } -} - -/**************************************************************************** - * name: usockreq_ioctl_other - ****************************************************************************/ - -int usockreq_ioctl_other(FAR struct alt1250_s *dev, - FAR struct usrsock_request_buff_s *req, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo) -{ - FAR struct usrsock_request_ioctl_s *request = &req->request.ioctl_req; - FAR struct lte_ioctl_data_s *ltecmd = &req->req_ioctl.ltecmd; - int ret = REP_SEND_ACK_WOFREE; - usrsock_reqhandler_t func = NULL; - - dbg_alt1250("%s start\n", __func__); - - *usock_result = -EINVAL; - *usock_xid = request->head.xid; - - switch (ltecmd->cmdid) - { - case LTE_CMDID_SETRESTART: - func = perform_setrestart; - break; - - case LTE_CMDID_SETEVTCTX: - func = perform_seteventctx; - break; - - case LTE_CMDID_GETERRINFO: - func = perform_geterrinfo; - break; - - case LTE_CMDID_SAVEAPN: - func = perform_saveapn; - break; - - case LTE_CMDID_GETAPN: - func = perform_getapn; - break; - -#ifdef CONFIG_LTE_ALT1250_ENABLE_HIBERNATION_MODE - case LTE_CMDID_SETCTXCB: - func = perform_setctxcb; - break; -#endif - - default: - break; - } - - if (func != NULL) - { - ret = func(dev, req, usock_result, usock_xid, ackinfo); - } - - return ret; -} diff --git a/lte/alt1250/usock_handlers/alt1250_ioctl_power.c b/lte/alt1250/usock_handlers/alt1250_ioctl_power.c deleted file mode 100644 index c910060c1..000000000 --- a/lte/alt1250/usock_handlers/alt1250_ioctl_power.c +++ /dev/null @@ -1,105 +0,0 @@ -/**************************************************************************** - * apps/lte/alt1250/usock_handlers/alt1250_ioctl_power.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -#include "alt1250_dbg.h" -#include "alt1250_container.h" -#include "alt1250_socket.h" -#include "alt1250_usockevent.h" -#include "alt1250_postproc.h" -#include "alt1250_devif.h" -#include "alt1250_evt.h" -#include "alt1250_ioctl_subhdlr.h" -#include "alt1250_usrsock_hdlr.h" -#include "alt1250_netdev.h" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * name: usockreq_ioctl_power - ****************************************************************************/ - -int usockreq_ioctl_power(FAR struct alt1250_s *dev, - FAR struct usrsock_request_buff_s *req, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo) -{ - FAR struct usrsock_request_ioctl_s *request = &req->request.ioctl_req; - FAR struct lte_ioctl_data_s *ltecmd = &req->req_ioctl.ltecmd; - int ret = REP_SEND_ACK_WOFREE; - - dbg_alt1250("%s start\n", __func__); - - *usock_result = OK; - *usock_xid = request->head.xid; - - switch (ltecmd->cmdid) - { - case LTE_CMDID_POWERON: - case LTE_CMDID_TAKEWLOCK: - case LTE_CMDID_GIVEWLOCK: - case LTE_CMDID_COUNTWLOCK: - *usock_result = altdevice_powercontrol(dev->altfd, ltecmd->cmdid); - if (MODEM_STATE_IS_POFF(dev) && ltecmd->cmdid == LTE_CMDID_POWERON) - { - /* For special reset sequence on power-on case */ - - MODEM_STATE_B4PON(dev); - } - break; - - case LTE_CMDID_POWEROFF: - alt1250_clrevtcb(ALT1250_CLRMODE_WO_RESTART); - *usock_result = altdevice_powercontrol(dev->altfd, ltecmd->cmdid); - MODEM_STATE_POFF(dev); - alt1250_netdev_ifdown(dev); - break; - - case LTE_CMDID_FIN: - alt1250_clrevtcb(ALT1250_CLRMODE_ALL); - ret = REP_SEND_TERM; - MODEM_STATE_POFF(dev); - break; - -#ifdef CONFIG_LTE_ALT1250_ENABLE_HIBERNATION_MODE - case LTE_CMDID_RETRYDISABLE: - case LTE_CMDID_GET_POWER_STAT: - *usock_result = altdevice_powercontrol(dev->altfd, ltecmd->cmdid); - break; -#endif - - default: - *usock_result = -EINVAL; - break; - } - - return ret; -} diff --git a/lte/alt1250/usock_handlers/alt1250_ioctl_subhdlr.h b/lte/alt1250/usock_handlers/alt1250_ioctl_subhdlr.h deleted file mode 100644 index fcd3b00f8..000000000 --- a/lte/alt1250/usock_handlers/alt1250_ioctl_subhdlr.h +++ /dev/null @@ -1,101 +0,0 @@ -/**************************************************************************** - * apps/lte/alt1250/usock_handlers/alt1250_ioctl_subhdlr.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __APPS_LTE_ALT1250_USOCK_HANDLERS_ALT1250_IOCTL_SUBHDLR_H -#define __APPS_LTE_ALT1250_USOCK_HANDLERS_ALT1250_IOCTL_SUBHDLR_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include "alt1250_daemon.h" -#include "alt1250_usockif.h" -#include "alt1250_usockevent.h" - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -int usockreq_ioctl_ltecmd(FAR struct alt1250_s *dev, - FAR struct usrsock_request_buff_s *req, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo); - -int usockreq_ioctl_ifreq(FAR struct alt1250_s *dev, - FAR struct usrsock_request_buff_s *req, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo); - -int usockreq_ioctl_normal(FAR struct alt1250_s *dev, - FAR struct usrsock_request_buff_s *req, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo); - -int usockreq_ioctl_event(FAR struct alt1250_s *dev, - FAR struct usrsock_request_buff_s *req, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo); - -int usockreq_ioctl_other(FAR struct alt1250_s *dev, - FAR struct usrsock_request_buff_s *req, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo); - -int usockreq_ioctl_power(FAR struct alt1250_s *dev, - FAR struct usrsock_request_buff_s *req, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo); - -int usockreq_ioctl_fwupdate(FAR struct alt1250_s *dev, - FAR struct usrsock_request_buff_s *req, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo); - -int usockreq_ioctl_denyinetsock(FAR struct alt1250_s *dev, - FAR struct usrsock_request_buff_s *req, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo); - -int send_m2mnotice_command(uint32_t cmdid, - FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - FAR struct usock_s *usock, - FAR struct lte_ioctl_data_s *ltecmd, - FAR int32_t *ures); - -int usockreq_ioctl_lwm2m(FAR struct alt1250_s *dev, - FAR struct usrsock_request_buff_s *req, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo); - -#endif /* __APPS_LTE_ALT1250_USOCK_HANDLERS_ALT1250_IOCTL_SUBHDLR_H */ diff --git a/lte/alt1250/usock_handlers/alt1250_ioctlhdlr.c b/lte/alt1250/usock_handlers/alt1250_ioctlhdlr.c deleted file mode 100644 index 43d638024..000000000 --- a/lte/alt1250/usock_handlers/alt1250_ioctlhdlr.c +++ /dev/null @@ -1,102 +0,0 @@ -/**************************************************************************** - * apps/lte/alt1250/usock_handlers/alt1250_ioctlhdlr.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -#include "alt1250_dbg.h" -#include "alt1250_container.h" -#include "alt1250_socket.h" -#include "alt1250_usockevent.h" -#include "alt1250_postproc.h" -#include "alt1250_ioctl_subhdlr.h" -#include "alt1250_sms.h" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * name: usockreq_ioctl - ****************************************************************************/ - -int usockreq_ioctl(FAR struct alt1250_s *dev, - FAR struct usrsock_request_buff_s *req, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo) -{ - FAR struct usrsock_request_ioctl_s *request = - &req->request.ioctl_req; - FAR struct usock_s *usock; - int ret = REP_SEND_ACK_WOFREE; - usrsock_reqhandler_t ioctl_subhdlr = NULL; - - dbg_alt1250("%s start\n", __func__); - - *usock_result = -EBADFD; - *usock_xid = request->head.xid; - - usock = usocket_search(dev, request->usockid); - if (usock) - { - USOCKET_SET_REQUEST(usock, request->head.reqid, request->head.xid); - - switch (request->cmd) - { - case FIONBIO: - case SIOCGIFFLAGS: - - /* ALT1250 doesn't use this command. Only return OK. */ - - *usock_result = OK; - break; - case SIOCLTECMD: - ioctl_subhdlr = usockreq_ioctl_ltecmd; - break; - case SIOCSIFFLAGS: - ioctl_subhdlr = usockreq_ioctl_ifreq; - break; - case SIOCDENYINETSOCK: - ioctl_subhdlr = usockreq_ioctl_denyinetsock; - break; - case SIOCSMSENSTREP: - case SIOCSMSGREFID: - case SIOCSMSSSCA: - ioctl_subhdlr = usockreq_ioctl_sms; - default: - *usock_result = -EINVAL; - break; - } - - if (ioctl_subhdlr != NULL) - { - ret = ioctl_subhdlr(dev, req, usock_result, usock_xid, ackinfo); - } - } - - return ret; -} diff --git a/lte/alt1250/usock_handlers/alt1250_listenhdlr.c b/lte/alt1250/usock_handlers/alt1250_listenhdlr.c deleted file mode 100644 index 4c66beeaf..000000000 --- a/lte/alt1250/usock_handlers/alt1250_listenhdlr.c +++ /dev/null @@ -1,171 +0,0 @@ -/**************************************************************************** - * apps/lte/alt1250/usock_handlers/alt1250_listenhdlr.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -#include "alt1250_dbg.h" -#include "alt1250_container.h" -#include "alt1250_devif.h" -#include "alt1250_socket.h" -#include "alt1250_usrsock_hdlr.h" -#include "alt1250_usockevent.h" -#include "alt1250_postproc.h" - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * name: send_listen_command - ****************************************************************************/ - -static int send_listen_command(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - FAR struct usock_s *usock, - uint16_t backlog, - FAR int32_t *usock_result) -{ - int idx = 0; - FAR void *inparam[2]; - - /* These members are referenced only when sending a command and - * not when receiving a response, so local variables are used. - */ - - inparam[0] = &USOCKET_ALTSOCKID(usock); - inparam[1] = &backlog; - - USOCKET_SET_RESPONSE(usock, idx++, USOCKET_REP_RESULT(usock)); - USOCKET_SET_RESPONSE(usock, idx++, USOCKET_REP_ERRCODE(usock)); - - set_container_ids(container, USOCKET_USOCKID(usock), LTE_CMDID_LISTEN); - set_container_argument(container, inparam, nitems(inparam)); - set_container_response(container, USOCKET_REP_RESPONSE(usock), idx); - set_container_postproc(container, postproc_sockcommon, 0); - - return altdevice_send_command(dev, dev->altfd, container, usock_result); -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * name: nextstep_listen - ****************************************************************************/ - -int nextstep_listen(FAR struct alt1250_s *dev, - FAR struct alt_container_s *reply, - FAR struct usock_s *usock, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo, - unsigned long arg) -{ - dbg_alt1250("%s start\n", __func__); - - return send_listen_command(dev, reply, usock, USOCKET_REQBACKLOG(usock), - usock_result); -} - -/**************************************************************************** - * name: usockreq_listen - ****************************************************************************/ - -int usockreq_listen(FAR struct alt1250_s *dev, - FAR struct usrsock_request_buff_s *req, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo) -{ - FAR struct usrsock_request_listen_s *request = - &req->request.listen_req; - FAR struct usock_s *usock; - FAR struct alt_container_s *container; - int ret = REP_SEND_ACK_WOFREE; - - dbg_alt1250("%s start\n", __func__); - - *usock_result = OK; - *usock_xid = request->head.xid; - - usock = usocket_search(dev, request->usockid); - if (usock == NULL) - { - dbg_alt1250("Failed to get socket context: %u\n", - request->usockid); - *usock_result = -EBADFD; - return REP_SEND_ACK_WOFREE; - } - - USOCKET_SET_REQUEST(usock, request->head.reqid, request->head.xid); - USOCKET_SET_REQBACKLOG(usock, request->backlog); - - switch (USOCKET_STATE(usock)) - { - case SOCKET_STATE_CLOSED: - case SOCKET_STATE_CLOSING: - dbg_alt1250("Unexpected state: %d\n", USOCKET_STATE(usock)); - *usock_result = -EBADFD; - ret = REP_SEND_ACK_WOFREE; - break; - - case SOCKET_STATE_PREALLOC: - container = container_alloc(); - if (container == NULL) - { - dbg_alt1250("no container\n"); - return REP_NO_CONTAINER; - } - - ret = open_altsocket(dev, container, usock, usock_result); - if (IS_NEED_CONTAINER_FREE(ret)) - { - container_free(container); - } - break; - - default: - container = container_alloc(); - if (container == NULL) - { - dbg_alt1250("no container\n"); - return REP_NO_CONTAINER; - } - - ret = nextstep_listen(dev, container, usock, usock_result, usock_xid, - ackinfo, 0); - if (IS_NEED_CONTAINER_FREE(ret)) - { - container_free(container); - } - break; - } - - return ret; -} - diff --git a/lte/alt1250/usock_handlers/alt1250_recvfromhdlr.c b/lte/alt1250/usock_handlers/alt1250_recvfromhdlr.c deleted file mode 100644 index b2c45f139..000000000 --- a/lte/alt1250/usock_handlers/alt1250_recvfromhdlr.c +++ /dev/null @@ -1,236 +0,0 @@ -/**************************************************************************** - * apps/lte/alt1250/usock_handlers/alt1250_recvfromhdlr.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -#include "alt1250_dbg.h" -#include "alt1250_daemon.h" -#include "alt1250_container.h" -#include "alt1250_devif.h" -#include "alt1250_socket.h" -#include "alt1250_usrsock_hdlr.h" -#include "alt1250_usockevent.h" -#include "alt1250_postproc.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static uint16_t _rx_max_buflen; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * name: postproc_recvfrom - ****************************************************************************/ - -static int postproc_recvfrom(FAR struct alt1250_s *dev, - FAR struct alt_container_s *reply, - FAR struct usock_s *usock, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo, - unsigned long arg) -{ - int ret = REP_SEND_ACK; - FAR void **resp = CONTAINER_RESPONSE(reply); - int rsize; - uint16_t addr_len = *(uint16_t *)(resp[2]); - - dbg_alt1250("%s start\n", __func__); - - dev->recvfrom_processing = false; - - /* resp[0]: recv size - * resp[1]: error code - * resp[2]: address length - * resp[3]: address - * resp[4]: buffer - */ - - rsize = COMBINE_ERRCODE(*(int *)(resp[0]), *(int *)(resp[1])); - - *usock_result = rsize; - *usock_xid = USOCKET_XID(usock); - - dbg_alt1250("recv %d bytes\n", rsize); - - if (rsize >= 0) - { - ackinfo->valuelen = MIN(USOCKET_REQADDRLEN(usock), addr_len); - ackinfo->valuelen_nontrunc = addr_len; /* Total size of addrlen */ - ackinfo->value_ptr = resp[3]; /* Receive from address */ - ackinfo->buf_ptr = resp[4]; /* Actual received data */ - - if ((rsize == 0) && (_rx_max_buflen != 0)) - { - usockif_sendclose(dev->usockfd, USOCKET_USOCKID(usock)); - } - - if ((rsize != 0) || (ackinfo->valuelen != 0)) - { - ret = REP_SEND_DACK; - } - } - - USOCKET_SET_SELECTABLE(usock, SELECT_READABLE); - usocket_commitstate(dev); - - return ret; -} - -/**************************************************************************** - * name: send_recvfrom_command - ****************************************************************************/ - -static int send_recvfrom_command(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - FAR struct usock_s *usock, - int32_t flags, - uint16_t buflen, - int16_t addrlen, - FAR int32_t *usock_result) -{ - int idx = 0; - FAR void *inparam[4]; - - /* These members are referenced only when sending a command and - * not when receiving a response, so local variables are used. - */ - - inparam[0] = &USOCKET_ALTSOCKID(usock); - inparam[1] = &flags; - inparam[2] = &buflen; - inparam[3] = &addrlen; - - USOCKET_SET_RESPONSE(usock, idx++, USOCKET_REP_RESULT(usock)); - USOCKET_SET_RESPONSE(usock, idx++, USOCKET_REP_ERRCODE(usock)); - USOCKET_SET_RESPONSE(usock, idx++, USOCKET_REP_ADDRLEN(usock)); - USOCKET_SET_RESPONSE(usock, idx++, USOCKET_REP_ADDR(usock)); - USOCKET_SET_RESPONSE(usock, idx++, dev->rx_buff); - - set_container_ids(container, USOCKET_USOCKID(usock), LTE_CMDID_RECVFROM); - set_container_argument(container, inparam, nitems(inparam)); - set_container_response(container, USOCKET_REP_RESPONSE(usock), idx++); - set_container_postproc(container, postproc_recvfrom, 0); - - return altdevice_send_command(dev, dev->altfd, container, usock_result); -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * name: usockreq_recvfrom - ****************************************************************************/ - -int usockreq_recvfrom(FAR struct alt1250_s *dev, - FAR struct usrsock_request_buff_s *req, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo) -{ - FAR struct usrsock_request_recvfrom_s *request = &req->request.recv_req; - FAR struct usock_s *usock; - FAR struct alt_container_s *container; - int ret; - socklen_t addrlen; - - dbg_alt1250("%s start\n", __func__); - - *usock_result = OK; - *usock_xid = request->head.xid; - - usock = usocket_search(dev, request->usockid); - if (usock == NULL) - { - dbg_alt1250("Failed to get socket context: %u\n", - request->usockid); - *usock_result = -EBADFD; - return REP_SEND_ACK_WOFREE; - } - - USOCKET_SET_REQUEST(usock, request->head.reqid, request->head.xid); - USOCKET_SET_REQADDRLEN(usock, request->max_addrlen); - USOCKET_SET_REQBUFLEN(usock, request->max_buflen); - - if (IS_SMS_SOCKET(usock)) - { - ret = alt1250_sms_recv(dev, request, usock, usock_result, ackinfo); - } - else - { - /* Check if this socket is connected. */ - - if ((SOCK_STREAM == USOCKET_TYPE(usock)) && - (USOCKET_STATE(usock) != SOCKET_STATE_CONNECTED)) - { - dbg_alt1250("Unexpected state: %d\n", USOCKET_STATE(usock)); - *usock_result = -ENOTCONN; - return REP_SEND_ACK_WOFREE; - } - - container = container_alloc(); - if (container == NULL) - { - dbg_alt1250("no container\n"); - return REP_NO_CONTAINER; - } - - if (USOCKET_DOMAIN(usock) == AF_INET) - { - addrlen = sizeof(struct sockaddr_in); - } - else - { - addrlen = sizeof(struct sockaddr_in6); - } - - _rx_max_buflen = MIN(request->max_buflen, _RX_BUFF_SIZE); - - ret = send_recvfrom_command(dev, container, usock, request->flags, - _rx_max_buflen, addrlen, usock_result); - if (IS_NEED_CONTAINER_FREE(ret)) - { - container_free(container); - } - - if (*usock_result >= 0) - { - dev->recvfrom_processing = true; - } - } - - return ret; -} diff --git a/lte/alt1250/usock_handlers/alt1250_sendtohdlr.c b/lte/alt1250/usock_handlers/alt1250_sendtohdlr.c deleted file mode 100644 index 2894354f2..000000000 --- a/lte/alt1250/usock_handlers/alt1250_sendtohdlr.c +++ /dev/null @@ -1,194 +0,0 @@ -/**************************************************************************** - * apps/lte/alt1250/usock_handlers/alt1250_sendtohdlr.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -#include "alt1250_dbg.h" -#include "alt1250_container.h" -#include "alt1250_socket.h" -#include "alt1250_devif.h" -#include "alt1250_usockevent.h" -#include "alt1250_postproc.h" -#include "alt1250_usrsock_hdlr.h" - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * name: send_sendto_command - ****************************************************************************/ - -static int send_sendto_command(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - FAR struct usock_s *usock, - FAR struct usrsock_request_sendto_s *req, - uint16_t buflen, - FAR struct sockaddr_storage *addr, - FAR int32_t *usock_result) -{ - int idx = 0; - FAR void *inparam[6]; - - /* These members are referenced only when sending a command and - * not when receiving a response, so local variables are used. - */ - - inparam[0] = &USOCKET_ALTSOCKID(usock); - inparam[1] = &req->flags; - inparam[2] = &req->addrlen; - inparam[3] = &buflen; - inparam[4] = addr; - inparam[5] = dev->tx_buff; - - USOCKET_SET_RESPONSE(usock, idx++, USOCKET_REP_RESULT(usock)); - USOCKET_SET_RESPONSE(usock, idx++, USOCKET_REP_ERRCODE(usock)); - - set_container_ids(container, USOCKET_USOCKID(usock), LTE_CMDID_SENDTO); - set_container_argument(container, inparam, nitems(inparam)); - set_container_response(container, USOCKET_REP_RESPONSE(usock), idx); - set_container_postproc(container, postproc_sockcommon, 0); - - return altdevice_send_command(dev, dev->altfd, container, usock_result); -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * name: usockreq_sendto - ****************************************************************************/ - -int usockreq_sendto(FAR struct alt1250_s *dev, - FAR struct usrsock_request_buff_s *req, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo) -{ - FAR struct usrsock_request_sendto_s *request = &req->request.send_req; - FAR struct usock_s *usock; - FAR struct alt_container_s *container; - int ret = REP_SEND_ACK_WOFREE; - struct sockaddr_storage addr; - - dbg_alt1250("%s start\n", __func__); - - *usock_result = OK; - *usock_xid = request->head.xid; - - usock = usocket_search(dev, request->usockid); - if (usock == NULL) - { - dbg_alt1250("Failed to get socket context: %u\n", - request->usockid); - *usock_result = -EBADFD; - return REP_SEND_ACK_WOFREE; - } - - USOCKET_SET_REQUEST(usock, request->head.reqid, request->head.xid); - USOCKET_SET_REQBUFLEN(usock, request->buflen); - - if (IS_SMS_SOCKET(usock)) - { - ret = alt1250_sms_send(dev, request, usock, usock_result); - } - else - { - /* Check if this socket is connected. */ - - if ((SOCK_STREAM == USOCKET_TYPE(usock)) && - (USOCKET_STATE(usock) != SOCKET_STATE_CONNECTED)) - { - dbg_alt1250("Unexpected state: %d\n", USOCKET_STATE(usock)); - *usock_result = -ENOTCONN; - return REP_SEND_ACK_WOFREE; - } - - container = container_alloc(); - if (container == NULL) - { - dbg_alt1250("no container\n"); - return REP_NO_CONTAINER; - } - - if (request->addrlen > 0) - { - /* Read address. */ - - ret = usockif_readreqaddr(dev->usockfd, &addr, request->addrlen); - if (ret < 0) - { - *usock_result = ret; - container_free(container); - return REP_SEND_ACK_WOFREE; - } - } - - /* Check if the request has data. */ - - if (request->buflen > 0) - { - size_t sendlen = MIN(request->buflen, _TX_BUFF_SIZE); - - ret = usockif_readreqsendbuf(dev->usockfd, dev->tx_buff, sendlen); - if (ret < 0) - { - *usock_result = ret; - container_free(container); - return REP_SEND_ACK_WOFREE; - } - - /* If the send size exceeds TX_BUFF_SIZE, - * use seek to discard the exceeded buffer. - */ - - if (request->buflen > sendlen) - { - usockif_discard(dev->usockfd, request->buflen - sendlen); - } - - ret = send_sendto_command(dev, container, usock, request, sendlen, - (request->addrlen > 0 ? &addr : NULL), - usock_result); - if (IS_NEED_CONTAINER_FREE(ret)) - { - container_free(container); - } - } - else if(request->buflen == 0) - { - container_free(container); - ret = REP_SEND_ACK_WOFREE; - *usock_result = 0; - USOCKET_SET_SELECTABLE(usock, SELECT_WRITABLE); - usocket_commitstate(dev); - } - } - - return ret; -} diff --git a/lte/alt1250/usock_handlers/alt1250_setsockopthdlr.c b/lte/alt1250/usock_handlers/alt1250_setsockopthdlr.c deleted file mode 100644 index 247053bed..000000000 --- a/lte/alt1250/usock_handlers/alt1250_setsockopthdlr.c +++ /dev/null @@ -1,193 +0,0 @@ -/**************************************************************************** - * apps/lte/alt1250/usock_handlers/alt1250_setsockopthdlr.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -#include "alt1250_dbg.h" -#include "alt1250_container.h" -#include "alt1250_socket.h" -#include "alt1250_devif.h" -#include "alt1250_usockevent.h" -#include "alt1250_postproc.h" -#include "alt1250_usrsock_hdlr.h" - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * name: send_setsockopt_command - ****************************************************************************/ - -static int send_setsockopt_command(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - FAR struct usock_s *usock, - FAR int32_t *usock_result) -{ - int idx = 0; - FAR void *inparam[5]; - - /* These members are referenced only when sending a command and - * not when receiving a response, so local variables are used. - */ - - inparam[0] = &USOCKET_ALTSOCKID(usock); - inparam[1] = &USOCKET_REQOPTLEVEL(usock); - inparam[2] = &USOCKET_REQOPTOPT(usock); - inparam[3] = &USOCKET_REQOPTLEN(usock); - inparam[4] = USOCKET_REQOPTVAL(usock); - - USOCKET_SET_RESPONSE(usock, idx++, USOCKET_REP_RESULT(usock)); - USOCKET_SET_RESPONSE(usock, idx++, USOCKET_REP_ERRCODE(usock)); - - set_container_ids(container, USOCKET_USOCKID(usock), LTE_CMDID_SETSOCKOPT); - set_container_argument(container, inparam, nitems(inparam)); - set_container_response(container, USOCKET_REP_RESPONSE(usock), idx); - set_container_postproc(container, postproc_sockcommon, 0); - - return altdevice_send_command(dev, dev->altfd, container, usock_result); -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * name: nextstep_setsockopt - ****************************************************************************/ - -int nextstep_setsockopt(FAR struct alt1250_s *dev, - FAR struct alt_container_s *reply, - FAR struct usock_s *usock, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo, - unsigned long arg) -{ - dbg_alt1250("%s start\n", __func__); - - return send_setsockopt_command(dev, reply, usock, usock_result); -} - -/**************************************************************************** - * name: usockreq_setsockopt - ****************************************************************************/ - -int usockreq_setsockopt(FAR struct alt1250_s *dev, - FAR struct usrsock_request_buff_s *req, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo) -{ - FAR struct usrsock_request_setsockopt_s *request = &req->request.sopt_req; - FAR struct usock_s *usock; - FAR struct alt_container_s *container; - int ret = REP_SEND_ACK_WOFREE; - - dbg_alt1250("%s start\n", __func__); - - *usock_result = OK; - *usock_xid = request->head.xid; - - usock = usocket_search(dev, request->usockid); - if (usock == NULL) - { - dbg_alt1250("Failed to get socket context: %u\n", - request->usockid); - *usock_result = -EBADFD; - return REP_SEND_ACK_WOFREE; - } - - if (request->valuelen > _OPTVAL_LEN_MAX) - { - *usock_result = -EINVAL; - return REP_SEND_ACK_WOFREE; - } - - USOCKET_SET_REQUEST(usock, request->head.reqid, request->head.xid); - USOCKET_SET_REQSOCKOPT(usock, request->level, request->option, - request->valuelen); - - switch (USOCKET_STATE(usock)) - { - case SOCKET_STATE_CLOSED: - case SOCKET_STATE_CLOSING: - dbg_alt1250("Unexpected state: %d\n", USOCKET_STATE(usock)); - *usock_result = -EBADFD; - ret = REP_SEND_ACK_WOFREE; - break; - - case SOCKET_STATE_PREALLOC: - container = container_alloc(); - if (container == NULL) - { - dbg_alt1250("no container\n"); - return REP_NO_CONTAINER; - } - - *usock_result = usockif_readreqoption(dev->usockfd, - USOCKET_REQOPTVAL(usock), - USOCKET_REQOPTLEN(usock)); - if (ret < 0) - { - return REP_SEND_ACK; - } - - ret = open_altsocket(dev, container, usock, usock_result); - if (IS_NEED_CONTAINER_FREE(ret)) - { - container_free(container); - } - break; - - default: - container = container_alloc(); - if (container == NULL) - { - dbg_alt1250("no container\n"); - return REP_NO_CONTAINER; - } - - *usock_result = usockif_readreqoption(dev->usockfd, - USOCKET_REQOPTVAL(usock), - USOCKET_REQOPTLEN(usock)); - if (ret < 0) - { - return REP_SEND_ACK; - } - - ret = nextstep_setsockopt(dev, container, usock, usock_result, - usock_xid, ackinfo, 0); - if (IS_NEED_CONTAINER_FREE(ret)) - { - container_free(container); - } - break; - } - - return ret; -} diff --git a/lte/alt1250/usock_handlers/alt1250_shutdownhdlr.c b/lte/alt1250/usock_handlers/alt1250_shutdownhdlr.c deleted file mode 100644 index 30a507c52..000000000 --- a/lte/alt1250/usock_handlers/alt1250_shutdownhdlr.c +++ /dev/null @@ -1,149 +0,0 @@ -/**************************************************************************** - * apps/lte/alt1250/usock_handlers/alt1250_shutdownhdlr.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -#include "alt1250_dbg.h" -#include "alt1250_container.h" -#include "alt1250_devif.h" -#include "alt1250_socket.h" -#include "alt1250_usrsock_hdlr.h" -#include "alt1250_usockevent.h" -#include "alt1250_postproc.h" - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * name: send_shutdown_command - ****************************************************************************/ - -static int send_shutdown_command(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - FAR struct usock_s *usock, int32_t how, - FAR int32_t *usock_result) -{ - int idx = 0; - FAR void *inparam[2]; - - /* These members are referenced only when sending a command and - * not when receiving a response, so local variables are used. - */ - - inparam[0] = &USOCKET_ALTSOCKID(usock); - inparam[1] = &how; - - USOCKET_SET_RESPONSE(usock, idx++, USOCKET_REP_RESULT(usock)); - USOCKET_SET_RESPONSE(usock, idx++, USOCKET_REP_ERRCODE(usock)); - - set_container_ids(container, USOCKET_USOCKID(usock), LTE_CMDID_SHUTDOWN); - set_container_argument(container, inparam, nitems(inparam)); - set_container_response(container, USOCKET_REP_RESPONSE(usock), idx); - set_container_postproc(container, postproc_sockcommon, 0); - - return altdevice_send_command(dev, dev->altfd, container, usock_result); -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * name: usockreq_shutdown - ****************************************************************************/ - -int usockreq_shutdown(FAR struct alt1250_s *dev, - FAR struct usrsock_request_buff_s *req, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo) -{ - FAR struct usrsock_request_shutdown_s *request = - &req->request.shutdown_req; - FAR struct usock_s *usock; - FAR struct alt_container_s *container; - int ret = REP_SEND_ACK_WOFREE; - - dbg_alt1250("%s start\n", __func__); - - *usock_result = OK; - *usock_xid = request->head.xid; - - if (request->how != SHUT_RD && - request->how != SHUT_WR && - request->how != SHUT_RDWR) - { - dbg_alt1250("Invalid parameter: %d\n", request->how); - *usock_result = -EINVAL; - return REP_SEND_ACK_WOFREE; - } - - usock = usocket_search(dev, request->usockid); - if (usock == NULL) - { - dbg_alt1250("Failed to get socket context: %u\n", - request->usockid); - *usock_result = -EBADFD; - return REP_SEND_ACK_WOFREE; - } - - USOCKET_SET_REQUEST(usock, request->head.reqid, request->head.xid); - - switch (USOCKET_STATE(usock)) - { - case SOCKET_STATE_CLOSED: - case SOCKET_STATE_CLOSING: - dbg_alt1250("Unexpected state: %d\n", USOCKET_STATE(usock)); - *usock_result = -EBADFD; - ret = REP_SEND_ACK_WOFREE; - break; - - case SOCKET_STATE_PREALLOC: - *usock_result = OK; - ret = REP_SEND_ACK_WOFREE; - break; - - default: - container = container_alloc(); - if (container == NULL) - { - dbg_alt1250("no container\n"); - return REP_NO_CONTAINER; - } - - ret = send_shutdown_command(dev, container, usock, - request->how, usock_result); - if (IS_NEED_CONTAINER_FREE(ret)) - { - container_free(container); - } - break; - } - - return ret; -} diff --git a/lte/alt1250/usock_handlers/alt1250_sms.c b/lte/alt1250/usock_handlers/alt1250_sms.c deleted file mode 100644 index 5f70beff8..000000000 --- a/lte/alt1250/usock_handlers/alt1250_sms.c +++ /dev/null @@ -1,1052 +0,0 @@ -/**************************************************************************** - * apps/lte/alt1250/usock_handlers/alt1250_sms.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include -#include - -#include "alt1250_dbg.h" -#include "alt1250_container.h" -#include "alt1250_socket.h" -#include "alt1250_devif.h" -#include "alt1250_usockevent.h" -#include "alt1250_postproc.h" -#include "alt1250_usrsock_hdlr.h" -#include "alt1250_sms.h" -#include "alt1250_evt.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#if defined(CONFIG_LTE_ALT1250_SMS_TOA) -# if defined(CONFIG_LTE_ALT1250_SMS_NAI_UNKNOWN) -# define ALT1250_SMS_NAI SMS_NAI_UNKNOWN -# elif defined(CONFIG_LTE_ALT1250_SMS_NAI_INTERNATIONAL) -# define ALT1250_SMS_NAI SMS_NAI_INTERNATIONAL -# elif defined(CONFIG_LTE_ALT1250_SMS_NAI_NATIONAL) -# define ALT1250_SMS_NAI SMS_NAI_NATIONAL -# elif defined(CONFIG_LTE_ALT1250_SMS_NAI_NETWORK_SPEC) -# define ALT1250_SMS_NAI SMS_NAI_NETWORK_SPEC -# elif defined(CONFIG_LTE_ALT1250_SMS_NAI_SUBSCRIBER) -# define ALT1250_SMS_NAI SMS_NAI_SUBSCRIBER -# elif defined(CONFIG_LTE_ALT1250_SMS_NAI_ALPANUMERIC) -# define ALT1250_SMS_NAI SMS_NAI_ALPANUMERIC -# elif defined(CONFIG_LTE_ALT1250_SMS_NAI_ABBREVIATED) -# define ALT1250_SMS_NAI SMS_NAI_ABBREVIATED -# elif defined(CONFIG_LTE_ALT1250_SMS_NAI_RESERVED) -# define ALT1250_SMS_NAI SMS_NAI_RESERVED -# endif -# if defined(CONFIG_LTE_ALT1250_SMS_NPI_UNKNOWN) -# define ALT1250_SMS_NPI SMS_NPI_UNKNOWN -# elif defined(CONFIG_LTE_ALT1250_SMS_NPI_ISDN) -# define ALT1250_SMS_NPI SMS_NPI_ISDN -# elif defined(CONFIG_LTE_ALT1250_SMS_NPI_DATA) -# define ALT1250_SMS_NPI SMS_NPI_DATA -# elif defined(CONFIG_LTE_ALT1250_SMS_NPI_TELEX) -# define ALT1250_SMS_NPI SMS_NPI_TELEX -# elif defined(CONFIG_LTE_ALT1250_SMS_NPI_SERVICE_CENTRE_SPEC) -# define ALT1250_SMS_NPI SMS_NPI_SERVICE_CENTRE_SPEC -# elif defined(CONFIG_LTE_ALT1250_SMS_NPI_SERVICE_CENTRE_SPEC2) -# define ALT1250_SMS_NPI SMS_NPI_SERVICE_CENTRE_SPEC2 -# elif defined(CONFIG_LTE_ALT1250_SMS_NPI_NATIONAL) -# define ALT1250_SMS_NPI SMS_NPI_NATIONAL -# elif defined(CONFIG_LTE_ALT1250_SMS_NPI_PRIVATE) -# define ALT1250_SMS_NPI SMS_NPI_PRIVATE -# elif defined(CONFIG_LTE_ALT1250_SMS_NPI_ERMES) -# define ALT1250_SMS_NPI SMS_NPI_ERMES -# elif defined(CONFIG_LTE_ALT1250_SMS_NPI_RESERVED) -# define ALT1250_SMS_NPI SMS_NPI_RESERVED -# endif -#endif /* CONFIG_LTE_ALT1250_SMS_TOA */ - -/* RK_02_01_01_10xxx FW version that does not support SMS feature */ - -#define IS_SMS_UNAVAIL_FWVERSION(d) (!strncmp(MODEM_FWVERSION(d), \ - "RK_02_01_01", 11)) - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static struct alt_container_s g_sms_container; -static struct postproc_s g_sms_postproc; - -/**************************************************************************** - * Private Functions Prototypes - ****************************************************************************/ - -static int postproc_smsinit(FAR struct alt1250_s *dev, - FAR struct alt_container_s *reply, - FAR struct usock_s *usock, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo, - unsigned long arg); - -static int postproc_smsinit_reopen(FAR struct alt1250_s *dev, - FAR struct alt_container_s *reply, - FAR struct usock_s *usock, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo, - unsigned long arg); - -static int postproc_smsfin(FAR struct alt1250_s *dev, - FAR struct alt_container_s *reply, - FAR struct usock_s *usock, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo, - unsigned long arg); - -static int postproc_smsfin_reopen(FAR struct alt1250_s *dev, - FAR struct alt_container_s *reply, - FAR struct usock_s *usock, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo, - unsigned long arg); - -static int postproc_smssend(FAR struct alt1250_s *dev, - FAR struct alt_container_s *reply, - FAR struct usock_s *usock, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo, - unsigned long arg); - -static int postproc_smsdelete(FAR struct alt1250_s *dev, - FAR struct alt_container_s *reply, - FAR struct usock_s *usock, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo, - unsigned long arg); - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * name: send_smsinit_command - ****************************************************************************/ - -static int send_smsinit_command(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - int usockid, - FAR postproc_hdlr_t func, - FAR int32_t *usock_result) -{ - /* Dummy variable to receive replies by the container. - * No one refers to this address. - */ - - FAR void *dummy_output = NULL; - - clear_container(container); - set_container_ids(container, usockid, LTE_CMDID_SMS_INIT); - set_container_argument(container, NULL, 0); - set_container_response(container, &dummy_output, 1); - set_container_postproc(container, func, 0); - - return altdevice_send_command(dev, dev->altfd, container, usock_result); -} - -/**************************************************************************** - * name: send_smsfin_command - ****************************************************************************/ - -static int send_smsfin_command(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - int usockid, - FAR postproc_hdlr_t func, - FAR int32_t *usock_result) -{ - /* Dummy variable to receive replies by the container. - * No one refers to this address. - */ - - FAR void *dummy_output = NULL; - - clear_container(container); - set_container_ids(container, usockid, LTE_CMDID_SMS_FIN); - set_container_argument(container, NULL, 0); - set_container_response(container, &dummy_output, 1); - set_container_postproc(container, func, 0); - - return altdevice_send_command(dev, dev->altfd, container, usock_result); -} - -/**************************************************************************** - * name: send_smssend_command - ****************************************************************************/ - -static int send_smssend_command(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - FAR struct usock_s *usock, - FAR struct sms_send_msg_s *msg, - FAR uint16_t msg_len, - FAR int32_t *usock_result) -{ - int idx = 0; - - FAR void *inparam[6]; - uint8_t chset = SMS_CHSET_UCS2; - - /* Thease members are referenced only when sending a command and - * not when receiving a response, so local variables are used. - */ - - inparam[0] = msg; - inparam[1] = &msg_len; - inparam[2] = &dev->sms_info.en_status_report; - inparam[3] = &dev->sms_info.dest_scaddr; - inparam[4] = &chset; -#if defined(CONFIG_LTE_ALT1250_SMS_TOA) - inparam[5] = &dev->sms_info.dest_toa; -#else - inparam[5] = NULL; -#endif - - USOCKET_SET_RESPONSE(usock, idx++, USOCKET_REFID(usock)); - USOCKET_SET_RESPONSE(usock, idx++, &USOCKET_REQBUFLEN(usock)); - - set_container_ids(container, USOCKET_USOCKID(usock), LTE_CMDID_SMS_SEND); - set_container_argument(container, inparam, nitems(inparam)); - set_container_response(container, USOCKET_REP_RESPONSE(usock), idx); - set_container_postproc(container, postproc_smssend, 0); - - return altdevice_send_command(dev, dev->altfd, container, usock_result); -} - -/**************************************************************************** - * name: send_smsdelete_command - ****************************************************************************/ - -static int send_smsdelete_command(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - FAR struct usock_s *usock, - uint16_t msg_index, - FAR int32_t *usock_result) -{ - /* Dummy variable to receive replies by the container. - * No one refers to this address. - */ - - FAR void *dummy_output = NULL; - FAR void *inparam[1]; - - /* This member is referenced only when sending a command and - * not when receiving a response, so local variables is used. - */ - - inparam[0] = &msg_index; - - set_container_ids(container, USOCKET_USOCKID(usock), LTE_CMDID_SMS_DELETE); - set_container_argument(container, inparam, nitems(inparam)); - set_container_response(container, &dummy_output, 1); - set_container_postproc(container, postproc_smsdelete, 0); - - return altdevice_send_command(dev, dev->altfd, container, usock_result); -} - -/**************************************************************************** - * name: send_smsreportrecv_command - ****************************************************************************/ - -static int send_smsreportrecv_command(FAR struct alt1250_s *dev, - FAR int32_t *usock_result) -{ - struct alt_container_s container = { - 0 - }; - - set_container_ids(&container, 0, LTE_CMDID_SMS_REPORT_RECV); - - return altdevice_send_command(dev, dev->altfd, &container, usock_result); -} - -/**************************************************************************** - * name: reset_sms_info - ****************************************************************************/ - -void reset_sms_info(FAR struct alt1250_s *dev) -{ - SMS_SET_STATE(&dev->sms_info, SMS_STATE_UNINIT); - dev->sms_info.msg_index = 0; - dev->sms_info.read_msglen = 0; - dev->sms_info.total_msglen = 0; - dev->sms_info.is_first_msg = false; -#if defined(CONFIG_LTE_ALT1250_SMS_TOA) - dev->sms_info.dest_toa = SMS_SET_TOA(ALT1250_SMS_NAI, ALT1250_SMS_NPI); -#endif -} - -/**************************************************************************** - * name: fill_recv_ackinfo - ****************************************************************************/ - -static bool fill_recv_ackinfo(FAR struct alt1250_s *dev, - FAR struct usock_s *usock, - FAR int32_t *usock_result, - FAR struct usock_ackinfo_s *ackinfo) -{ - FAR void **arg; - FAR uint8_t *msg_head; - uint16_t remain_msglen; - - /* arg[0]: sms msg index - * arg[1]: sms msg length - * arg[2]: Maximum number of msg for concatenate sms. - * arg[3]: Current number of msg for concatenate sms. - * arg[4]: sms msg - */ - - arg = alt1250_getevtarg(LTE_CMDID_SMS_REPORT_RECV); - - assert(arg && arg[4]); - - msg_head = (FAR uint8_t *)arg[4]; - remain_msglen = dev->sms_info.msglen - dev->sms_info.read_msglen; - - if (!dev->sms_info.is_first_msg) - { - /* In the case of a concatenated SMS, the header information is only - * given to the first SMS. Therefore, if the SMS is not the first - * one, the header information is shifted and read. - */ - - msg_head += sizeof(struct sms_recv_msg_header_s); - remain_msglen -= sizeof(struct sms_recv_msg_header_s); - } - - *usock_result = MIN(USOCKET_REQBUFLEN(usock), remain_msglen); - - ackinfo->valuelen = 0; - ackinfo->valuelen_nontrunc = 0; - ackinfo->value_ptr = NULL; - ackinfo->buf_ptr = msg_head + dev->sms_info.read_msglen; - - /* return is empty */ - - return (USOCKET_REQBUFLEN(usock) < remain_msglen) ? false : true; -} - -/**************************************************************************** - * name: notify_read_ready - ****************************************************************************/ - -static void notify_read_ready(FAR struct alt1250_s *dev, uint16_t msg_index, - uint16_t msg_len) -{ - dev->sms_info.msg_index = msg_index; - dev->sms_info.msglen = msg_len; - dev->sms_info.read_msglen = 0; - - usocket_smssock_readready(dev); -} - -/**************************************************************************** - * name: notify_abort - ****************************************************************************/ - -static void notify_abort(FAR struct alt1250_s *dev) -{ - reset_sms_info(dev); - usocket_smssock_abort(dev); -} - -/**************************************************************************** - * name: update_concat_size - ****************************************************************************/ - -static void update_concat_size(FAR struct alt1250_s *dev, uint16_t msg_index, - uint16_t msg_len, uint8_t max_num, - uint8_t seq_num, - FAR struct sms_recv_msg_header_s *sms_msg) -{ - int32_t usock_result = OK; - - dev->sms_info.total_msglen += sms_msg->datalen; - - if (max_num == seq_num) - { - /* In case of last of concatenated sms */ - - /* Send only SMS FIN command to avoid receiving the next SMS REPORT - * command. If SMS REPORT response is sent before SMS FIN command - * is sent, unexpected SMS REPORT command may be received. - */ - - send_smsfin_command(dev, &g_sms_container, 0, - postproc_smsfin_reopen, &usock_result); - if (usock_result < 0) - { - notify_abort(dev); - } - else - { - SMS_SET_STATE(&dev->sms_info, SMS_STATE_REOPEN); - - dev->sms_info.is_first_msg = true; - } - } - else - { - send_smsreportrecv_command(dev, &usock_result); - if (usock_result < 0) - { - notify_abort(dev); - } - } -} - -/**************************************************************************** - * name: handle_recvmsg - ****************************************************************************/ - -static void handle_recvmsg(FAR struct alt1250_s *dev, uint16_t msg_index, - uint16_t msg_len, uint8_t max_num, - uint8_t seq_num, - FAR struct sms_recv_msg_header_s *sms_msg) -{ - if (max_num == 0) - { - /* In case of not concatenated sms */ - - dev->sms_info.total_msglen = sms_msg->datalen; - dev->sms_info.is_first_msg = true; - - SMS_SET_STATE(&dev->sms_info, SMS_STATE_READ_READY); - - /* Notify usrsock of the read ready event. */ - - notify_read_ready(dev, msg_index, msg_len); - } - else - { - /* In case of concatenated sms */ - - SMS_SET_STATE(&dev->sms_info, SMS_STATE_CALC_SIZE); - - dev->sms_info.msg_index = msg_index; - - update_concat_size(dev, msg_index, msg_len, max_num, seq_num, sms_msg); - } -} - -/**************************************************************************** - * name: postproc_smsinit - ****************************************************************************/ - -static int postproc_smsinit(FAR struct alt1250_s *dev, - FAR struct alt_container_s *reply, - FAR struct usock_s *usock, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo, - unsigned long arg) -{ - int ret = REP_SEND_ACK_TXREADY; - - dbg_alt1250("%s start\n", __func__); - - *usock_result = CONTAINER_RESPRES(reply); - if (*usock_result < 0) - { - ret = REP_SEND_ACK; - } - else - { - *usock_result = USOCKET_USOCKID(usock); - ackinfo->usockid = USOCKET_USOCKID(usock); - SMS_SET_STATE(&dev->sms_info, SMS_STATE_WAITMSG); - } - - return ret; -} - -/**************************************************************************** - * name: postproc_smsinit_reopen - ****************************************************************************/ - -static int postproc_smsinit_reopen(FAR struct alt1250_s *dev, - FAR struct alt_container_s *reply, - FAR struct usock_s *usock, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo, - unsigned long arg) -{ - dbg_alt1250("%s start\n", __func__); - - *usock_result = CONTAINER_RESPRES(reply); - if (*usock_result >= 0) - { - SMS_SET_STATE(&dev->sms_info, SMS_STATE_WAITMSG_CONCAT); - } - else - { - notify_abort(dev); - } - - return REP_NO_ACK_WOFREE; -} - -/**************************************************************************** - * name: postproc_smsfin - ****************************************************************************/ - -static int postproc_smsfin(FAR struct alt1250_s *dev, - FAR struct alt_container_s *reply, - FAR struct usock_s *usock, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo, - unsigned long arg) -{ - dbg_alt1250("%s start\n", __func__); - - *usock_xid = USOCKET_XID(usock); - *usock_result = CONTAINER_RESPRES(reply); - - usocket_free(usock); - - return REP_SEND_ACK; -} - -/**************************************************************************** - * name: postproc_smsfin_reopen - ****************************************************************************/ - -static int postproc_smsfin_reopen(FAR struct alt1250_s *dev, - FAR struct alt_container_s *reply, - FAR struct usock_s *usock, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo, - unsigned long arg) -{ - dbg_alt1250("%s start\n", __func__); - - if (SMS_STATE(&dev->sms_info) == SMS_STATE_UNINIT) - { - dbg_alt1250("All sms sockets are closed\n"); - } - else - { - send_smsinit_command(dev, reply, 0, postproc_smsinit_reopen, - usock_result); - if (*usock_result < 0) - { - notify_abort(dev); - } - } - - return REP_NO_ACK_WOFREE; -} - -/**************************************************************************** - * name: postproc_smssend - ****************************************************************************/ - -static int postproc_smssend(FAR struct alt1250_s *dev, - FAR struct alt_container_s *reply, - FAR struct usock_s *usock, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo, - unsigned long arg) -{ - int ret = REP_SEND_ACK_TXREADY; - - dbg_alt1250("%s start\n", __func__); - - /* resp[0]: referese ID list */ - - *usock_xid = USOCKET_XID(usock); - *usock_result = CONTAINER_RESPRES(reply); - - if (*usock_result == -EPROTO) - { - lte_errinfo_t errinfo; - alt1250_geterrinfo(&errinfo); - *usock_result = (errinfo.err_indicator & LTE_ERR_INDICATOR_ERRCODE) ? - -errinfo.err_result_code : *usock_result; - } - - ackinfo->usockid = USOCKET_USOCKID(usock); - - return ret; -} - -/**************************************************************************** - * name: postproc_smsdelete - ****************************************************************************/ - -static int postproc_smsdelete(FAR struct alt1250_s *dev, - FAR struct alt_container_s *reply, - FAR struct usock_s *usock, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo, - unsigned long arg) -{ - int ret = REP_SEND_ACK; - - dbg_alt1250("%s start\n", __func__); - - *usock_xid = USOCKET_XID(usock); - *usock_result = CONTAINER_RESPRES(reply); - if (*usock_result >= 0) - { - ret = send_smsreportrecv_command(dev, usock_result); - if (*usock_result >= 0) - { - /* In case of success */ - - ret = REP_SEND_DACK; - fill_recv_ackinfo(dev, usock, usock_result, ackinfo); - - dev->sms_info.is_first_msg = false; - } - } - - return ret; -} - -/**************************************************************************** - * name: sms_report_event - ****************************************************************************/ - -static void sms_report_event(FAR struct alt1250_s *dev, uint16_t msg_index, - uint16_t msg_len, uint8_t max_num, - uint8_t seq_num, - FAR struct sms_recv_msg_header_s *sms_msg) -{ - dbg_alt1250("%s start\n", __func__); - - assert(msg_len >= sizeof(struct sms_recv_msg_header_s)); - - switch (SMS_STATE(&dev->sms_info)) - { - case SMS_STATE_UNINIT: - dbg_alt1250("All sms sockets are closed\n"); - break; - - case SMS_STATE_REOPEN: - dbg_alt1250("Receive report msg in REOPEN state\n"); - break; - - case SMS_STATE_READ_READY: - - /* Notify usrsock of the read ready event. */ - - notify_read_ready(dev, msg_index, msg_len); - break; - - case SMS_STATE_WAITMSG: - handle_recvmsg(dev, msg_index, msg_len, max_num, seq_num, sms_msg); - break; - - case SMS_STATE_WAITMSG_CONCAT: - if (dev->sms_info.msg_index != msg_index) - { - /* In case of unexpected SMS received. - * Therefore, start over from the beginning. - */ - - handle_recvmsg(dev, msg_index, msg_len, max_num, seq_num, - sms_msg); - } - else - { - /* In case of expected concatenated SMS received. */ - - sms_msg->datalen = dev->sms_info.total_msglen; - - SMS_SET_STATE(&dev->sms_info, SMS_STATE_READ_READY); - - /* Notify usrsock of the read ready event. */ - - notify_read_ready(dev, msg_index, msg_len); - } - break; - - case SMS_STATE_CALC_SIZE: - update_concat_size(dev, msg_index, msg_len, max_num, seq_num, - sms_msg); - break; - - default: - dbg_alt1250("Receive report msg in unexpected state: %d\n", - SMS_STATE(&dev->sms_info)); - break; - } -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * name: alt1250_sms_init - ****************************************************************************/ - -int alt1250_sms_init(FAR struct alt1250_s *dev, FAR struct usock_s *usock, - FAR int32_t *usock_result, - FAR struct usock_ackinfo_s *ackinfo) -{ - int ret = REP_SEND_ACK_WOFREE; - FAR struct alt_container_s *container; - - dbg_alt1250("%s start\n", __func__); - - if (IS_SMS_UNAVAIL_FWVERSION(dev)) - { - dbg_alt1250("This ALT1250 FW version does not support SMS.\n"); - *usock_result = -EAFNOSUPPORT; - return REP_SEND_ACK_WOFREE; - } - - if (SMS_STATE(&dev->sms_info) == SMS_STATE_UNINIT) - { - container = container_alloc(); - if (container == NULL) - { - dbg_alt1250("no container\n"); - return REP_NO_CONTAINER; - } - - ret = send_smsinit_command(dev, container, USOCKET_USOCKID(usock), - postproc_smsinit, usock_result); - - if (IS_NEED_CONTAINER_FREE(ret)) - { - container_free(container); - } - } - else - { - ret = REP_SEND_ACK_TXREADY; - ackinfo->usockid = USOCKET_USOCKID(usock); - } - - return ret; -} - -/**************************************************************************** - * name: alt1250_sms_fin - ****************************************************************************/ - -int alt1250_sms_fin(FAR struct alt1250_s *dev, FAR struct usock_s *usock, - FAR int32_t *usock_result) -{ - int ret = REP_SEND_ACK_WOFREE; - FAR struct alt_container_s *container; - - dbg_alt1250("%s start\n", __func__); - - *usock_result = OK; - - if (usocket_smssock_num(dev) == 1) - { - if (SMS_STATE(&dev->sms_info) == SMS_STATE_REOPEN) - { - return REP_NO_CONTAINER; - } - - container = container_alloc(); - if (container == NULL) - { - dbg_alt1250("no container\n"); - return REP_NO_CONTAINER; - } - - ret = send_smsfin_command(dev, container, USOCKET_USOCKID(usock), - postproc_smsfin, usock_result); - - if (IS_NEED_CONTAINER_FREE(ret)) - { - container_free(container); - } - - alt1250_reset_sms_info(dev); - - if (*usock_result < 0) - { - usocket_free(usock); - } - } - else - { - usocket_free(usock); - } - - return ret; -} - -/**************************************************************************** - * name: alt1250_sms_send - ****************************************************************************/ - -int alt1250_sms_send(FAR struct alt1250_s *dev, - FAR struct usrsock_request_sendto_s *req, - FAR struct usock_s *usock, - FAR int32_t *usock_result) -{ - int ret = REP_SEND_ACK_WOFREE; - FAR struct alt_container_s *container; - - dbg_alt1250("%s start\n", __func__); - - if (SMS_STATE(&dev->sms_info) == SMS_STATE_REOPEN) - { - /* Sending the SMS send command now will fail because the - * SMS fin command has already been sent. - * Therefore, return REP_NO_CONTAINER and wait for the status to - * become ready to send. - */ - - return REP_NO_CONTAINER; - } - - container = container_alloc(); - if (container == NULL) - { - dbg_alt1250("no container\n"); - return REP_NO_CONTAINER; - } - - if (req->addrlen > 0) - { - /* Ignore destination address. */ - - usockif_discard(dev->usockfd, req->addrlen); - } - - if (req->buflen > 0 && - req->buflen <= sizeof(struct sms_send_msg_s) + (SMS_MAX_DATALEN * 2)) - { - ret = usockif_readreqsendbuf(dev->usockfd, dev->tx_buff, req->buflen); - if (ret < 0) - { - *usock_result = ret; - container_free(container); - return REP_SEND_ACK_WOFREE; - } - - ret = send_smssend_command(dev, container, usock, - (FAR struct sms_send_msg_s *)dev->tx_buff, - req->buflen, - usock_result); - if (IS_NEED_CONTAINER_FREE(ret)) - { - container_free(container); - } - } - else - { - /* In case of invalid buffer length */ - - *usock_result = -EINVAL; - container_free(container); - ret = REP_SEND_ACK_WOFREE; - } - - return ret; -} - -/**************************************************************************** - * name: alt1250_sms_recv - ****************************************************************************/ - -int alt1250_sms_recv(FAR struct alt1250_s *dev, - FAR struct usrsock_request_recvfrom_s *req, - FAR struct usock_s *usock, - FAR int32_t *usock_result, - FAR struct usock_ackinfo_s *ackinfo) -{ - int ret = REP_SEND_ACK_WOFREE; - FAR struct alt_container_s *container; - - dbg_alt1250("%s start\n", __func__); - - if (SMS_STATE(&dev->sms_info) == SMS_STATE_REOPEN) - { - return REP_NO_CONTAINER; - } - - if (fill_recv_ackinfo(dev, usock, usock_result, ackinfo)) - { - /* In case of buffer is empty */ - - container = container_alloc(); - if (container == NULL) - { - dbg_alt1250("no container\n"); - return REP_NO_CONTAINER; - } - - /* If the application has read all data, - * change the status to SMS_STATE_WAITMSG. - */ - - dev->sms_info.total_msglen -= (dev->sms_info.msglen - - sizeof(struct sms_recv_msg_header_s)); - if (dev->sms_info.total_msglen == 0) - { - SMS_SET_STATE(&dev->sms_info, SMS_STATE_WAITMSG); - } - - /* Delete the SMS in the ALT1250 because one SMS was read. */ - - ret = send_smsdelete_command(dev, container, usock, - dev->sms_info.msg_index, usock_result); - if (IS_NEED_CONTAINER_FREE(ret)) - { - container_free(container); - } - } - else - { - /* In case of buffer is not empty */ - - ret = REP_SEND_DACK_RXREADY; - dev->sms_info.read_msglen += req->max_buflen; - ackinfo->usockid = USOCKET_USOCKID(usock); - } - - return ret; -} - -/**************************************************************************** - * name: usockreq_ioctl_sms - ****************************************************************************/ - -int usockreq_ioctl_sms(FAR struct alt1250_s *dev, - FAR struct usrsock_request_buff_s *req, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo) -{ - FAR struct usrsock_request_ioctl_s *request = &req->request.ioctl_req; - FAR struct lte_smsreq_s *smsreq = &req->req_ioctl.smsreq; - FAR struct usock_s *usock; - int ret = REP_SEND_ACK_WOFREE; - - dbg_alt1250("%s start\n", __func__); - - *usock_result = -EBADFD; - - usock = usocket_search(dev, request->usockid); - if (usock) - { - switch (request->cmd) - { - case SIOCSMSENSTREP: - *usock_result = OK; - dev->sms_info.en_status_report = smsreq->smsru.enable; - break; - - case SIOCSMSGREFID: - *usock_result = OK; - ret = REP_SEND_DACK; - ackinfo->valuelen = sizeof(struct lte_smsreq_s); - ackinfo->valuelen_nontrunc = sizeof(struct lte_smsreq_s); - ackinfo->value_ptr = (FAR uint8_t *)USOCKET_REFID(usock); - ackinfo->buf_ptr = NULL; - break; - - case SIOCSMSSSCA: - *usock_result = OK; - memcpy(&dev->sms_info.dest_scaddr, &smsreq->smsru.scaddr, - sizeof(struct sms_sc_addr_s)); - break; - - default: - *usock_result = -EINVAL; - break; - } - } - - return ret; -} - -/**************************************************************************** - * name: perform_sms_report_event - ****************************************************************************/ - -uint64_t perform_sms_report_event(FAR struct alt1250_s *dev, uint64_t bitmap) -{ - uint64_t bit = 0ULL; - FAR void **arg; - - if (alt1250_checkcmdid(LTE_CMDID_SMS_REPORT_RECV, bitmap, &bit)) - { - arg = alt1250_getevtarg(LTE_CMDID_SMS_REPORT_RECV); - if (arg && arg[0] && arg[1] && arg[2] && arg[3] && arg[4]) - { - /* arg[0]: sms msg index - * arg[1]: sms msg length - * arg[2]: Maximum number of msg for concatenate sms. - * arg[3]: Current number of msg for concatenate sms. - * arg[4]: sms msg - */ - - sms_report_event(dev, *((FAR uint16_t *)arg[0]), - *((FAR uint16_t *)arg[1]), - *((FAR uint8_t *)arg[2]), - *((FAR uint8_t *)arg[3]), - (FAR struct sms_recv_msg_header_s *)arg[4]); - } - - alt1250_setevtarg_writable(LTE_CMDID_SMS_REPORT_RECV); - } - - return bit; -} - -/**************************************************************************** - * name: alt1250_sms_initcontainer - ****************************************************************************/ - -void alt1250_sms_initcontainer(FAR struct alt1250_s *dev) -{ - g_sms_container.priv = (unsigned long)&g_sms_postproc; - clear_container(&g_sms_container); -} - -/**************************************************************************** - * name: alt1250_reset_sms_info - ****************************************************************************/ - -void alt1250_reset_sms_info(FAR struct alt1250_s *dev) -{ - notify_abort(dev); -} diff --git a/lte/alt1250/usock_handlers/alt1250_sms.h b/lte/alt1250/usock_handlers/alt1250_sms.h deleted file mode 100644 index 11f9b4dce..000000000 --- a/lte/alt1250/usock_handlers/alt1250_sms.h +++ /dev/null @@ -1,116 +0,0 @@ -/**************************************************************************** - * apps/lte/alt1250/usock_handlers/alt1250_sms.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __APPS_LTE_ALT1250_USOCK_HANDLERS_ALT1250_SMS_H -#define __APPS_LTE_ALT1250_USOCK_HANDLERS_ALT1250_SMS_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include "alt1250_container.h" -#include "alt1250_postproc.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define SMS_STATE(info) ((info)->sms_state) -#define SMS_MSG_INDEX(info) ((info)->msg_index) - -#define SMS_STATE_STR(ss) \ - ((ss) == SMS_STATE_UNINIT ? "SMS_STATE_UNINIT" : \ - (ss) == SMS_STATE_WAITMSG ? "SMS_STATE_WAITMSG" : \ - (ss) == SMS_STATE_READ_READY ? "SMS_STATE_READ_READY" : \ - (ss) == SMS_STATE_CALC_SIZE ? "SMS_STATE_CALC_SIZE" : \ - (ss) == SMS_STATE_REOPEN ? "SMS_STATE_REOPEN" : \ - (ss) == SMS_STATE_WAITMSG_CONCAT ? "SMS_STATE_WAITMSG_CONCAT" : \ - "ERROR UNKOWN STATE") - -#define SMS_SET_STATE(info, s) { \ - dbg_alt1250("[SMS stat] state: %s -> %s\n", \ - SMS_STATE_STR((info)->sms_state), SMS_STATE_STR(s)); \ - (info)->sms_state = (s); \ -} -#define SMS_SET_MSG_INDEX(info, x) ((info)->msg_index = (x)) - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -enum sms_state_e -{ - SMS_STATE_UNINIT = 0, - SMS_STATE_WAITMSG, - SMS_STATE_READ_READY, - SMS_STATE_CALC_SIZE, - SMS_STATE_REOPEN, - SMS_STATE_WAITMSG_CONCAT -}; - -struct sms_info_s -{ - enum sms_state_e sms_state; - uint16_t msg_index; - unsigned short msglen; - unsigned short read_msglen; - unsigned short total_msglen; - bool is_first_msg; - - bool en_status_report; - struct sms_sc_addr_s dest_scaddr; -#if defined(CONFIG_LTE_ALT1250_SMS_TOA) - uint8_t dest_toa; -#endif -}; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -int alt1250_sms_init(FAR struct alt1250_s *dev, FAR struct usock_s *usock, - FAR int32_t *usock_result, - FAR struct usock_ackinfo_s *ackinfo); -int alt1250_sms_fin(FAR struct alt1250_s *dev, FAR struct usock_s *usock, - FAR int32_t *usock_result); -int alt1250_sms_send(FAR struct alt1250_s *dev, - FAR struct usrsock_request_sendto_s *req, - FAR struct usock_s *usock, - FAR int32_t *usock_result); -int alt1250_sms_recv(FAR struct alt1250_s *dev, - FAR struct usrsock_request_recvfrom_s *req, - FAR struct usock_s *usock, - FAR int32_t *usock_result, - FAR struct usock_ackinfo_s *ackinfo); -int usockreq_ioctl_sms(FAR struct alt1250_s *dev, - FAR struct usrsock_request_buff_s *req, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo); -uint64_t perform_sms_report_event(FAR struct alt1250_s *dev, - uint64_t bitmap); -void alt1250_sms_initcontainer(FAR struct alt1250_s *dev); -void alt1250_reset_sms_info(FAR struct alt1250_s *dev); - -#endif /* __APPS_LTE_ALT1250_USOCK_HANDLERS_ALT1250_SMS_H */ diff --git a/lte/alt1250/usock_handlers/alt1250_sockethdlr.c b/lte/alt1250/usock_handlers/alt1250_sockethdlr.c deleted file mode 100644 index e6046f36e..000000000 --- a/lte/alt1250/usock_handlers/alt1250_sockethdlr.c +++ /dev/null @@ -1,473 +0,0 @@ -/**************************************************************************** - * apps/lte/alt1250/usock_handlers/alt1250_sockethdlr.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -#include "alt1250_dbg.h" -#include "alt1250_container.h" -#include "alt1250_socket.h" -#include "alt1250_devif.h" -#include "alt1250_usockevent.h" -#include "alt1250_postproc.h" -#include "alt1250_usrsock_hdlr.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define IS_SUPPORTED_INET_DOMAIN(d) (((d) == AF_INET) || ((d) == AF_INET6)) - -/**************************************************************************** - * Private Functions Prototypes - ****************************************************************************/ - -static int postproc_getfl(FAR struct alt1250_s *dev, - FAR struct alt_container_s *reply, - FAR struct usock_s *usock, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo, - unsigned long arg); - -static int postproc_setfl(FAR struct alt1250_s *dev, - FAR struct alt_container_s *reply, - FAR struct usock_s *usock, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo, - unsigned long arg); - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * name: send_fctl_command - ****************************************************************************/ - -static int send_fctl_command(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - FAR struct usock_s *usock, - int32_t cmd, - int32_t val, - FAR int32_t *usock_result) -{ - int idx = 0; - FAR void *inparam[3]; - - /* These members are referenced only when sending a command and - * not when receiving a response, so local variables are used. - */ - - inparam[0] = &USOCKET_ALTSOCKID(usock); - inparam[1] = &cmd; - inparam[2] = &val; - - USOCKET_SET_RESPONSE(usock, idx++, USOCKET_REP_RESULT(usock)); - USOCKET_SET_RESPONSE(usock, idx++, USOCKET_REP_ERRCODE(usock)); - - set_container_ids(container, USOCKET_USOCKID(usock), LTE_CMDID_FCNTL); - set_container_argument(container, inparam, nitems(inparam)); - set_container_response(container, USOCKET_REP_RESPONSE(usock), idx); - set_container_postproc(container, cmd == ALTCOM_SETFL ? postproc_setfl : - cmd == ALTCOM_GETFL ? postproc_getfl : NULL, 0); - - return altdevice_send_command(dev, dev->altfd, container, usock_result); -} - -/**************************************************************************** - * name: postproc_setfl - ****************************************************************************/ - -static int postproc_setfl(FAR struct alt1250_s *dev, - FAR struct alt_container_s *reply, - FAR struct usock_s *usock, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo, - unsigned long arg) -{ - int ret = REP_SEND_ACK; - FAR void **resp = CONTAINER_RESPONSE(reply); - - /* resp[0]: command return code - * resp[1]: alt1250 errno - */ - - dbg_alt1250("%s start\n", __func__); - - *usock_xid = USOCKET_XID(usock); - *usock_result = COMBINE_ERRCODE(*(FAR int *)resp[0], *(FAR int *)resp[1]); - - if (*usock_result >= 0) - { - USOCKET_SET_STATE(usock, SOCKET_STATE_OPENED); - usocket_commitstate(dev); - - switch (USOCKET_REQID(usock)) - { - case USRSOCK_REQUEST_SOCKET: - *usock_result = USOCKET_USOCKID(usock); - dbg_alt1250("allocated usockid: %d\n", *usock_result); - break; - - /* Below cases are for SOCK_STREAM type socket - * SOCK_STREAM type socket can not be opend on alt1250 side, - * because of LAPI command. It is also using SOCK_STREAM - * type socket to send ioctl() to communicate with daemon. - * So, on BSD-socket spec, aftre socket() API succeeded, - * connect(), bind(), etc, can be called. And on the call, - * socket on alt1250 side should be fixed, therefore, - * open_altsocket() will be called on those cases. - */ - - case USRSOCK_REQUEST_CONNECT: - ret = nextstep_connect(dev, reply, usock, usock_result, - usock_xid, ackinfo, arg); - break; - - case USRSOCK_REQUEST_BIND: - ret = nextstep_bind(dev, reply, usock, usock_result, - usock_xid, ackinfo, arg); - break; - - case USRSOCK_REQUEST_LISTEN: - ret = nextstep_listen(dev, reply, usock, usock_result, - usock_xid, ackinfo, arg); - break; - - case USRSOCK_REQUEST_SETSOCKOPT: - ret = nextstep_setsockopt(dev, reply, usock, usock_result, - usock_xid, ackinfo, arg); - break; - - case USRSOCK_REQUEST_GETSOCKOPT: - ret = nextstep_getsockopt(dev, reply, usock, usock_result, - usock_xid, ackinfo, arg); - break; - - case USRSOCK_REQUEST_GETSOCKNAME: - ret = nextstep_getsockname(dev, reply, usock, usock_result, - usock_xid, ackinfo, arg); - break; - - default: - dbg_alt1250("unexpected sequence. reqid:0x%02x\n", - USOCKET_REQID(usock)); - *usock_result = -EFAULT; - break; - } - } - else - { - USOCKET_SET_STATE(usock, SOCKET_STATE_PREALLOC); - if (USOCKET_TYPE(usock) == SOCK_DGRAM) - { - usocket_free(usock); - } - - usocket_commitstate(dev); - } - - return ret; -} - -/**************************************************************************** - * name: postproc_getfl - ****************************************************************************/ - -static int postproc_getfl(FAR struct alt1250_s *dev, - FAR struct alt_container_s *reply, - FAR struct usock_s *usock, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo, - unsigned long arg) -{ - int ret = REP_SEND_ACK; - FAR void **resp = CONTAINER_RESPONSE(reply); - - /* resp[0]: command return code - * resp[1]: alt1250 errno - */ - - dbg_alt1250("%s start\n", __func__); - - *usock_xid = USOCKET_XID(usock); - *usock_result = COMBINE_ERRCODE(*(FAR int *)resp[0], *(FAR int *)resp[1]); - - if (*usock_result >= 0) - { - /* Set non-blocking flag of socket fd */ - - *usock_result |= ALTCOM_O_NONBLOCK; - - ret = send_fctl_command(dev, reply, usock, ALTCOM_SETFL, *usock_result, - usock_result); - } - - if (*usock_result < 0) - { - USOCKET_SET_STATE(usock, SOCKET_STATE_PREALLOC); - if (USOCKET_TYPE(usock) == SOCK_DGRAM) - { - /* In DGRAM case, it is a part of socket() API sequence. - * The socket() API is not returned on application layer. - * So, internal socket should be free here. - */ - - usocket_free(usock); - } - - usocket_commitstate(dev); - } - - return ret; -} - -/**************************************************************************** - * name: postproc_socket - ****************************************************************************/ - -static int postproc_socket(FAR struct alt1250_s *dev, - FAR struct alt_container_s *reply, - FAR struct usock_s *usock, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo, - unsigned long arg) -{ - int ret = REP_SEND_ACK; - FAR void **resp = CONTAINER_RESPONSE(reply); - - /* resp[0]: altcom_sockfd - * resp[1]: alt1250 errno - */ - - dbg_alt1250("%s start\n", __func__); - - *usock_xid = USOCKET_XID(usock); - *usock_result = COMBINE_ERRCODE(*(FAR int *)resp[0], *(FAR int *)resp[1]); - - if (*usock_result >= 0) - { - /* In case of success socket allocation */ - - USOCKET_SET_ALTSOCKID(usock, *usock_result); - - ret = send_fctl_command(dev, reply, usock, ALTCOM_GETFL, 0, - usock_result); - } - - if (*usock_result < 0) - { - USOCKET_SET_STATE(usock, SOCKET_STATE_PREALLOC); - if (USOCKET_TYPE(usock) == SOCK_DGRAM) - { - /* In DGRAM case, it is a part of socket() API sequence. - * The socket() API is not returned on application layer. - * So, internal socket should be free here. - */ - - usocket_free(usock); - } - - usocket_commitstate(dev); - } - - return ret; -} - -/**************************************************************************** - * name: send_socket_command - ****************************************************************************/ - -static int send_socket_command(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - FAR struct usock_s *usock, - int16_t domain, - int16_t type, - int16_t protocol, - FAR int32_t *usock_result) -{ - int idx = 0; - FAR void *inparam[3]; - - /* These members are referenced only when sending a command and - * not when receiving a response, so local variables are used. - */ - - inparam[0] = &domain; - inparam[1] = &type; - inparam[2] = &protocol; - - USOCKET_SET_RESPONSE(usock, idx++, USOCKET_REP_RESULT(usock)); - USOCKET_SET_RESPONSE(usock, idx++, USOCKET_REP_ERRCODE(usock)); - - set_container_ids(container, USOCKET_USOCKID(usock), LTE_CMDID_SOCKET); - set_container_argument(container, inparam, nitems(inparam)); - set_container_response(container, USOCKET_REP_RESPONSE(usock), idx); - set_container_postproc(container, postproc_socket, 0); - - return altdevice_send_command(dev, dev->altfd, container, usock_result); -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * name: open_altsocket - ****************************************************************************/ - -int open_altsocket(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - FAR struct usock_s *usock, - FAR int32_t *usock_result) -{ - int ret; - - dbg_alt1250("%s start\n", __func__); - - ret = send_socket_command(dev, container, usock, - USOCKET_DOMAIN(usock), USOCKET_TYPE(usock), - USOCKET_PROTOCOL(usock), - usock_result); - if (*usock_result >= 0) - { - USOCKET_SET_STATE(usock, SOCKET_STATE_OPEN); - usocket_commitstate(dev); - } - - return ret; -} - -/**************************************************************************** - * name: usockreq_socket - ****************************************************************************/ - -int usockreq_socket(FAR struct alt1250_s *dev, - FAR struct usrsock_request_buff_s *req, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo) -{ - FAR struct usrsock_request_socket_s *request = &req->request.sock_req; - FAR struct usock_s *usock; - FAR struct alt_container_s *container; - int ret = REP_SEND_ACK_WOFREE; - - dbg_alt1250("%s start type=%d\n", __func__, request->type); - - *usock_xid = request->head.xid; - - if (!IS_SUPPORTED_INET_DOMAIN(request->domain)) - { - dbg_alt1250("Not support this domain: %u\n", request->domain); - *usock_result = -EAFNOSUPPORT; - return REP_SEND_ACK_WOFREE; - } - else if (!dev->usock_enable && IS_SUPPORTED_INET_DOMAIN(request->domain) && - request->type != SOCK_CTRL) - { - /* If domain is AF_INET while usock_enable is false, - * set usockid to -ENOTSUP to fallback kernel - * network stack. - */ - - *usock_result = -ENOTSUP; - return REP_SEND_ACK_WOFREE; - } - - if (!dev->api_enable) - { - dbg_alt1250("Don't allow to call any API now.\n"); - *usock_result = -EBUSY; - return REP_SEND_ACK_WOFREE; - } - - usock = usocket_alloc(dev, request->type); - if (usock == NULL) - { - dbg_alt1250("socket alloc faild\n"); - *usock_result = -EBUSY; - return REP_SEND_ACK_WOFREE; - } - - *usock_result = USOCKET_USOCKID(usock); - - USOCKET_SET_REQUEST(usock, request->head.reqid, request->head.xid); - USOCKET_SET_SOCKTYPE(usock, request->domain, request->type, - request->protocol); - - switch (request->type) - { - case SOCK_STREAM: - case SOCK_CTRL: - dbg_alt1250("allocated usockid: %d\n", *usock_result); - break; - - case SOCK_SMS: - ret = alt1250_sms_init(dev, usock, usock_result, ackinfo); - if (*usock_result < 0) - { - usocket_free(usock); - } - break; - - case SOCK_DGRAM: - case SOCK_RAW: - dbg_alt1250("allocated usockid: %d\n", *usock_result); - container = container_alloc(); - if (container == NULL) - { - dbg_alt1250("no container\n"); - usocket_free(usock); - return REP_NO_CONTAINER; - } - - ret = open_altsocket(dev, container, usock, usock_result); - if (IS_NEED_CONTAINER_FREE(ret)) - { - container_free(container); - } - - if (*usock_result < 0) - { - usocket_free(usock); - } - break; - - default: - dbg_alt1250("Not support this type: %u\n", request->type); - *usock_result = -EAFNOSUPPORT; - usocket_free(usock); - break; - } - - return ret; -} diff --git a/lte/alt1250/usock_handlers/alt1250_usrsock_hdlr.h b/lte/alt1250/usock_handlers/alt1250_usrsock_hdlr.h deleted file mode 100644 index 5142389fc..000000000 --- a/lte/alt1250/usock_handlers/alt1250_usrsock_hdlr.h +++ /dev/null @@ -1,236 +0,0 @@ -/**************************************************************************** - * apps/lte/alt1250/usock_handlers/alt1250_usrsock_hdlr.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __APPS_LTE_ALT1250_USOCK_HANDLERS_ALT1250_SOCKETHDLR_H -#define __APPS_LTE_ALT1250_USOCK_HANDLERS_ALT1250_SOCKETHDLR_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include "alt1250_daemon.h" -#include "alt1250_usockif.h" -#include "alt1250_usockevent.h" -#include "alt1250_postproc.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define COMBINE_ERRCODE(res, ecode) (((res) < 0) ? -(ecode) : (res)) - -#define ALT1250_NETIF_READY_DELAY (150 * 1000) - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -void reset_fwupdate_info(FAR struct alt1250_s *dev); - -int usockreq_socket(FAR struct alt1250_s *dev, - FAR struct usrsock_request_buff_s *req, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo); - -int usockreq_close(FAR struct alt1250_s *dev, - FAR struct usrsock_request_buff_s *req, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo); - -int usockreq_connect(FAR struct alt1250_s *dev, - FAR struct usrsock_request_buff_s *req, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo); - -int usockreq_sendto(FAR struct alt1250_s *dev, - FAR struct usrsock_request_buff_s *req, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo); - -int usockreq_recvfrom(FAR struct alt1250_s *dev, - FAR struct usrsock_request_buff_s *req, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo); - -int usockreq_setsockopt(FAR struct alt1250_s *dev, - FAR struct usrsock_request_buff_s *req, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo); - -int usockreq_getsockopt(FAR struct alt1250_s *dev, - FAR struct usrsock_request_buff_s *req, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo); - -int usockreq_getsockname(FAR struct alt1250_s *dev, - FAR struct usrsock_request_buff_s *req, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo); - -int usockreq_getpeername(FAR struct alt1250_s *dev, - FAR struct usrsock_request_buff_s *req, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo); - -int usockreq_bind(FAR struct alt1250_s *dev, - FAR struct usrsock_request_buff_s *req, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo); - -int usockreq_listen(FAR struct alt1250_s *dev, - FAR struct usrsock_request_buff_s *req, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo); - -int usockreq_accept(FAR struct alt1250_s *dev, - FAR struct usrsock_request_buff_s *req, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo); - -int usockreq_ioctl(FAR struct alt1250_s *dev, - FAR struct usrsock_request_buff_s *req, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo); - -int usockreq_shutdown(FAR struct alt1250_s *dev, - FAR struct usrsock_request_buff_s *req, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo); - -int open_altsocket(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - FAR struct usock_s *usock, - FAR int32_t *usock_result); - -int nextstep_connect(FAR struct alt1250_s *dev, - FAR struct alt_container_s *reply, - FAR struct usock_s *usock, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo, - unsigned long arg); - -int nextstep_check_connectres(FAR struct alt1250_s *dev, - FAR struct usock_s *usock); - -int nextstep_bind(FAR struct alt1250_s *dev, - FAR struct alt_container_s *reply, - FAR struct usock_s *usock, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo, - unsigned long arg); - -int nextstep_listen(FAR struct alt1250_s *dev, - FAR struct alt_container_s *reply, - FAR struct usock_s *usock, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo, - unsigned long arg); - -int nextstep_setsockopt(FAR struct alt1250_s *dev, - FAR struct alt_container_s *reply, - FAR struct usock_s *usock, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo, - unsigned long arg); - -int nextstep_getsockopt(FAR struct alt1250_s *dev, - FAR struct alt_container_s *reply, - FAR struct usock_s *usock, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo, - unsigned long arg); - -int nextstep_getsockname(FAR struct alt1250_s *dev, - FAR struct alt_container_s *reply, - FAR struct usock_s *usock, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo, - unsigned long arg); - -int postproc_sockcommon(FAR struct alt1250_s *dev, - FAR struct alt_container_s *reply, - FAR struct usock_s *usock, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo, - unsigned long arg); - -int send_getsockopt_command(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - FAR struct usock_s *usock, - int16_t level, - int16_t option, - uint16_t valuelen, - FAR int16_t *requested_level, - FAR int16_t *requested_option, - FAR postproc_hdlr_t func, - unsigned long priv, - FAR int32_t *usock_result); - -int send_reportnet_command(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - FAR struct usock_s *usock, - FAR postproc_hdlr_t func, - unsigned long priv, - FAR int32_t *usock_result); - -int send_lapi_command(FAR struct alt1250_s *dev, - FAR struct alt_container_s *container, - FAR struct usock_s *usock, - FAR struct lte_ioctl_data_s *ltecmd, - FAR postproc_hdlr_t hdlr, - unsigned long priv, - FAR int32_t *usock_result); - -int postproc_fwgetversion(FAR struct alt1250_s *dev, - FAR struct alt_container_s *reply, - FAR struct usock_s *usock, - FAR int32_t *usock_result, - FAR uint32_t *usock_xid, - FAR struct usock_ackinfo_s *ackinfo, - unsigned long arg); - -void alt1250_geterrinfo(FAR lte_errinfo_t *errinfo); - -#endif /* __APPS_LTE_ALT1250_USOCK_HANDLERS_ALT1250_SOCKETHDLR_H */ diff --git a/lte/lapi/CMakeLists.txt b/lte/lapi/CMakeLists.txt deleted file mode 100644 index 45c0d852d..000000000 --- a/lte/lapi/CMakeLists.txt +++ /dev/null @@ -1,40 +0,0 @@ -# ############################################################################## -# apps/lte/lapi/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_LTE_LAPI) - - set(CSRCS - src/lapi_evt.c - src/lapi_firmware.c - src/lapi_net.c - src/lapi_other.c - src/lapi_pdn.c - src/lapi_pin.c - src/lapi_power.c - src/lapi_psave.c - src/lapi_radio.c - src/lapi_sim.c - src/lapi_lwm2m.c - src/lapi_log.c) - - target_sources(apps PRIVATE ${CSRCS}) -endif() diff --git a/lte/lapi/Kconfig b/lte/lapi/Kconfig deleted file mode 100644 index 76125b2b4..000000000 --- a/lte/lapi/Kconfig +++ /dev/null @@ -1,48 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -menuconfig LTE_LAPI - bool "LTE Configuration Library" - default n - ---help--- - Enable the LTE Configuration Library. - -if LTE_LAPI - -config LTE_LAPI_DEBUG_MSG - bool "Enable debug output messages" - default n - depends on DEBUG_NET_ERROR - -config LTE_LAPI_KEEP_COMPATIBILITY - bool "Keep the LTE library compatible." - default n - ---help--- - lte_get_operator_sync, lte_get_imsi_sync, lte_get_imei_sync, lte_get_phoneno_sync, - these functions have changed their specifications to specify the length of the - argument string. Functions in the old spec will be discarded, but enabling this - option makes you be able to use them. - Furthermore, this option will be removed in the near future, and functions in - the old spec will be completely discarded. - -config LTE_LAPI_LOG_ACCESS - bool "Enable the log access API" - default n - ---help--- - Enable these log access APIs: lte_log_open, lte_log_close, - lte_log_read, lte_log_lseek, lte_log_remove. - -config LTE_LAPI_ENABLE_DEPRECATED_API - bool "Enable deprecated API" - default y - ---help--- - If your application does not use the deprecated APIs, - this option can help to reduce memory usage. - Deprecated APIs are asynchronous APIs except lte_activate_pdn. - See include/lte/lte_api.h for a list of asynchronous APIs. - Deprecated APIs will be removed in the future, - please use the synchronous API instead. - -endif # LTE_LAPI diff --git a/lte/lapi/Make.defs b/lte/lapi/Make.defs deleted file mode 100644 index 9fd239fc2..000000000 --- a/lte/lapi/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/lte/lapi/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_LTE_LAPI),) -CONFIGURED_APPS += $(APPDIR)/lte/lapi -endif diff --git a/lte/lapi/Makefile b/lte/lapi/Makefile deleted file mode 100644 index 936206501..000000000 --- a/lte/lapi/Makefile +++ /dev/null @@ -1,29 +0,0 @@ -############################################################################ -# apps/lte/lapi/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -# LTE Lapi Application - -include $(APPDIR)/lte/lapi/src/Make.defs - -include $(APPDIR)/Application.mk diff --git a/lte/lapi/src/Make.defs b/lte/lapi/src/Make.defs deleted file mode 100644 index 4a6816e86..000000000 --- a/lte/lapi/src/Make.defs +++ /dev/null @@ -1,42 +0,0 @@ -############################################################################ -# apps/lte/lapi/src/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_LTE_LAPI),) - -CSRCS = lapi_evt.c \ - lapi_firmware.c \ - lapi_net.c \ - lapi_other.c \ - lapi_pdn.c \ - lapi_pin.c \ - lapi_power.c \ - lapi_psave.c \ - lapi_radio.c \ - lapi_sim.c \ - lapi_lwm2m.c \ - lapi_log.c - -DEPPATH += --dep-path src -VPATH += :src -CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/lte/lapi/src - -endif diff --git a/lte/lapi/src/lapi_dbg.h b/lte/lapi/src/lapi_dbg.h deleted file mode 100644 index ebe02523a..000000000 --- a/lte/lapi/src/lapi_dbg.h +++ /dev/null @@ -1,42 +0,0 @@ -/**************************************************************************** - * apps/lte/lapi/src/lapi_dbg.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __APPS_LTE_LAPI_LAPI_DBG_H -#define __APPS_LTE_LAPI_LAPI_DBG_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#ifdef CONFIG_LTE_LAPI_DEBUG_MSG -# define lapi_printf nerr -#else -# define lapi_printf(v, ...) -#endif - -#endif /* __APPS_LTE_LAPI_LAPI_DBG_H */ diff --git a/lte/lapi/src/lapi_evt.c b/lte/lapi/src/lapi_evt.c deleted file mode 100644 index 3826a5073..000000000 --- a/lte/lapi/src/lapi_evt.c +++ /dev/null @@ -1,204 +0,0 @@ -/**************************************************************************** - * apps/lte/lapi/src/lapi_evt.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "lte/lte_api.h" -#include "lte/lapi.h" - -#include "lapi_dbg.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define EVENT_MAX 64 - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static mqd_t g_mqd; -static struct lte_evtctx_out_s g_evtctx; - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: lapi_evtinit - ****************************************************************************/ - -int lapi_evtinit(FAR const char *mqname) -{ - int ret = OK; - struct mq_attr attr = - { - 0 - }; - - struct lte_evtctx_in_s in; - FAR void *inarg[] = - { - &in - }; - - FAR void *outarg[] = - { - &g_evtctx - }; - - attr.mq_maxmsg = EVENT_MAX; - attr.mq_msgsize = sizeof(uint64_t); - - g_mqd = mq_open(mqname, O_CREAT | O_RDONLY | O_EXCL, 0666, &attr); - if (g_mqd == (mqd_t)-1) - { - lapi_printf("failed to open mq(%s): %d\n", mqname, errno); - return -errno; - } - - in.mqname = mqname; - ret = lapi_req(LTE_CMDID_SETEVTCTX, (FAR void *)inarg, nitems(inarg), - (FAR void *)outarg, nitems(outarg), NULL); - if (ret < 0) - { - lapi_printf("failed to lapi request: %d\n", ret); - mq_close(g_mqd); - mq_unlink(mqname); - } - - return ret; -} - -/**************************************************************************** - * Name: lapi_evtdestoy - ****************************************************************************/ - -void lapi_evtdestoy(void) -{ - mq_close(g_mqd); -} - -/**************************************************************************** - * Name: lapi_evtyield - ****************************************************************************/ - -int lapi_evtyield(int timeout_ms) -{ - int ret; - ssize_t sz; - uint64_t buf; - struct timespec ts; - bool is_exit = false; - - if (timeout_ms >= 0) - { - if (clock_gettime(CLOCK_REALTIME, &ts) != OK) - { - return -errno; - } - - ts.tv_sec += timeout_ms / 1000; - timeout_ms -= timeout_ms / 1000; - ts.tv_nsec += timeout_ms * 1000 * 1000; - } - - while (!is_exit) - { - if (timeout_ms >= 0) - { - sz = mq_timedreceive(g_mqd, (FAR void *)&buf, sizeof(buf), NULL, - &ts); - if (sz < 0) - { - ret = -errno; - if (errno != ETIMEDOUT) - { - lapi_printf("failed to mq_receive: %d\n", errno); - } - - is_exit = true; - continue; - } - } - else - { - sz = mq_receive(g_mqd, (FAR void *)&buf, sizeof(buf), NULL); - if (sz < 0) - { - ret = -errno; - lapi_printf("failed to mq_receive: %d\n", errno); - is_exit = true; - continue; - } - } - - if (buf == 0ULL) - { - ret = OK; - is_exit = true; - } - else - { - g_evtctx.handle(buf); - } - } - - return ret; -} - -/**************************************************************************** - * Name: lapi_evtsend - ****************************************************************************/ - -int lapi_evtsend(uint64_t evtbitmap) -{ - int ret; - - ret = mq_send(g_mqd, (FAR const char *)&evtbitmap, sizeof(evtbitmap), 0); - if (ret < 0) - { - ret = -errno; - lapi_printf("failed to send mq: %d\n", errno); - } - - return ret; -} diff --git a/lte/lapi/src/lapi_firmware.c b/lte/lapi/src/lapi_firmware.c deleted file mode 100644 index 203c4afb7..000000000 --- a/lte/lapi/src/lapi_firmware.c +++ /dev/null @@ -1,169 +0,0 @@ -/**************************************************************************** - * apps/lte/lapi/src/lapi_firmware.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include -#include -#include -#include - -#include "lte/lapi.h" -#include "lte/lte_api.h" -#include "lte/lte_fwupdate.h" - -#include "lapi_dbg.h" - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static int fw_inject_internal(FAR const char *data, int len, bool init) -{ - FAR void *inarg[3] = - { - (FAR void *)data, &len, &init - }; - - int dummy_arg; /* Dummy for blocking API call */ - - if (data == NULL || len < 0) - { - return -EINVAL; - } - - return lapi_req(LTE_CMDID_INJECTIMAGE, - (FAR void *)inarg, nitems(inarg), - (FAR void *)&dummy_arg, 0, NULL); -} - -static int fw_generic_request(int cmdid) -{ - int dummy_arg; /* Dummy for blocking API call */ - - return lapi_req(cmdid, NULL, 0, (FAR void *)&dummy_arg, 0, NULL); -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/* Synchronous APIs */ - -int lte_get_version_sync(FAR lte_version_t *version) -{ - int ret; - int result; - FAR void *outarg[] = - { - &result, version - }; - - if (version == NULL) - { - return -EINVAL; - } - - ret = lapi_req(LTE_CMDID_GETVER, - NULL, 0, - (FAR void *)outarg, nitems(outarg), - NULL); - return (ret == 0) ? result : ret; -} - -int ltefwupdate_initialize(FAR const char *initial_data, int len) -{ - return fw_inject_internal(initial_data, len, true); -} - -int ltefwupdate_injectrest(FAR const char *rest_data, int len) -{ - return fw_inject_internal(rest_data, len, false); -} - -int ltefwupdate_injected_datasize(void) -{ - return fw_generic_request(LTE_CMDID_GETIMAGELEN); -} - -int ltefwupdate_execute(void) -{ - int ret; - - /* If wakelock is not acquired, firmware update - * cannot be performed. - */ - - ret = lte_get_wakelock_count(); - if (ret <= 0) - { - if (ret == 0) - { - lapi_printf("wakelock is not acquired\n"); - ret = -EPERM; - } - - return ret; - } - - return fw_generic_request(LTE_CMDID_EXEUPDATE); -} - -int ltefwupdate_result(void) -{ - return fw_generic_request(LTE_CMDID_GETUPDATERES); -} - -int lte_factory_reset_sync(void) -{ - int ret; - int result; - FAR void *outarg[] = - { - &result - }; - - ret = lapi_req(LTE_CMDID_FACTORY_RESET, - NULL, 0, - (FAR void *)outarg, nitems(outarg), - NULL); - - return ret; -} - -/* Asynchronous APIs */ - -#ifdef CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API - -int lte_get_version(get_ver_cb_t callback) -{ - printf("This API is discarded. Please use lte_get_version_sync().\n"); - return -ENOTSUP; -} -#endif /* CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API */ - diff --git a/lte/lapi/src/lapi_log.c b/lte/lapi/src/lapi_log.c deleted file mode 100644 index 1ddf2e4f2..000000000 --- a/lte/lapi/src/lapi_log.c +++ /dev/null @@ -1,213 +0,0 @@ -/**************************************************************************** - * apps/lte/lapi/src/lapi_log.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include - -#include "lte/lapi.h" -#include "lte/lte_log.h" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: lte_log_collect - ****************************************************************************/ - -int lte_log_collect(FAR char *output_fname, size_t len) -{ - FAR void *inarg[] = - { - (FAR void *)&len - }; - - FAR void *outarg[] = - { - output_fname, (FAR void *)&len - }; - - if ((output_fname != NULL) && (len != LTE_LOG_NAME_LEN)) - { - return -ENOBUFS; - } - - len = LTE_LOG_NAME_LEN; - - return lapi_req(LTE_CMDID_SAVE_LOG, - inarg, nitems(inarg), - outarg, nitems(outarg), - NULL); -} - -/**************************************************************************** - * Name: lte_log_getlist - ****************************************************************************/ - -int lte_log_getlist(size_t listsize, size_t fnamelen, - char list[listsize][fnamelen]) -{ - FAR void *inarg[] = - { - (FAR void *)fnamelen - }; - - FAR void *outarg[] = - { - list, (FAR void *)listsize, (FAR void *)fnamelen - }; - - if ((listsize == 0) || (list == NULL)) - { - return -EINVAL; - } - - if (fnamelen != LTE_LOG_NAME_LEN) - { - return -ENOBUFS; - } - - return lapi_req(LTE_CMDID_GET_LOGLIST, - inarg, nitems(inarg), - outarg, nitems(outarg), - NULL); -} - -#ifdef CONFIG_LTE_LAPI_LOG_ACCESS - -/**************************************************************************** - * Name: lte_log_open - ****************************************************************************/ - -int lte_log_open(FAR const char *filename) -{ - int dummy_arg; /* Dummy for blocking API call */ - FAR void *inarg[] = - { - (FAR void *)filename - }; - - if (filename == NULL) - { - return -EINVAL; - } - - return lapi_req(LTE_CMDID_LOGOPEN, - inarg, nitems(inarg), - (FAR void *)&dummy_arg, 0, - NULL); -} - -/**************************************************************************** - * Name: lte_log_close - ****************************************************************************/ - -int lte_log_close(int fd) -{ - int dummy_arg; /* Dummy for blocking API call */ - FAR void *inarg[] = - { - (FAR void *)fd - }; - - return lapi_req(LTE_CMDID_LOGCLOSE, - inarg, nitems(inarg), - (FAR void *)&dummy_arg, 0, - NULL); -} - -/**************************************************************************** - * Name: lte_log_read - ****************************************************************************/ - -ssize_t lte_log_read(int fd, FAR void *buf, size_t len) -{ - FAR void *inarg[] = - { - (FAR void *)fd, (FAR void *)len - }; - - FAR void *outarg[] = - { - buf, (FAR void *)len - }; - - if ((buf == NULL) || (len == 0)) - { - return -EINVAL; - } - - return lapi_req(LTE_CMDID_LOGREAD, - inarg, nitems(inarg), - outarg, nitems(outarg), - NULL); -} - -/**************************************************************************** - * Name: lte_log_lseek - ****************************************************************************/ - -int lte_log_lseek(int fd, off_t offset, int whence) -{ - int dummy_arg; /* Dummy for blocking API call */ - FAR void *inarg[] = - { - (FAR void *)fd, (FAR void *)&offset, (FAR void *)whence - }; - - return lapi_req(LTE_CMDID_LOGLSEEK, - inarg, nitems(inarg), - (FAR void *)&dummy_arg, 0, - NULL); -} - -/**************************************************************************** - * Name: lte_log_remove - ****************************************************************************/ - -int lte_log_remove(FAR const char *filename) -{ - int dummy_arg; /* Dummy for blocking API call */ - FAR void *inarg[] = - { - (FAR void *)filename - }; - - if (filename == NULL) - { - return -EINVAL; - } - - return lapi_req(LTE_CMDID_LOGREMOVE, - inarg, nitems(inarg), - (FAR void *)&dummy_arg, 0, - NULL); -} - -#endif /* CONFIG_LTE_LAPI_LOG_ACCESS */ diff --git a/lte/lapi/src/lapi_lwm2m.c b/lte/lapi/src/lapi_lwm2m.c deleted file mode 100644 index 889e16018..000000000 --- a/lte/lapi/src/lapi_lwm2m.c +++ /dev/null @@ -1,492 +0,0 @@ -/**************************************************************************** - * apps/lte/lapi/src/lapi_lwm2m.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include -#include -#include -#include - -#include "lte/lapi.h" -#include "lte/lte_api.h" -#include "lte/lte_lwm2m.h" - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: check_instance - ****************************************************************************/ - -static int check_instance(FAR struct lwm2mstub_instance_s *inst) -{ - int ret = OK; - - if (inst->object_id < 0 || inst->object_inst < 0 || inst->res_id < 0) - { - ret = ERROR; - } - - return ret; -} - -/**************************************************************************** - * Name: insert_sort - ****************************************************************************/ - -static void insert_sort(FAR uint16_t *array, int sz) -{ - int i; - int j; - uint16_t tmp; - - for (i = 1; i < sz; i++) - { - j = i; - while (j > 0 && array[j - 1] > array[j]) - { - tmp = array[j - 1]; - array[j - 1] = array[j]; - array[j] = tmp; - j--; - } - } -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: lte_m2m_connection - ****************************************************************************/ - -int lte_m2m_connection(int cmd) -{ - if (cmd < LWM2MSTUB_CONNECT_REGISTER || cmd > LWM2MSTUB_CONNECT_BOOTSTRAP) - { - return -EINVAL; - } - - return lapi_req(LTE_CMDID_LWM2M_CONNECT, (FAR void **)(uintptr_t)cmd, - 1, NULL, 0, NULL); -} - -/**************************************************************************** - * Name: lte_m2m_readresponse - ****************************************************************************/ - -int lte_m2m_readresponse(int seq_no, FAR struct lwm2mstub_instance_s *inst, - int resp, FAR char *readvalue, int len) -{ - FAR void *inarg[5] = { - (FAR void *)(uintptr_t)seq_no, (FAR void *)(uintptr_t)resp, inst, - readvalue, (FAR void *)(uintptr_t)len - }; - - if (!inst || !readvalue || len <= 0 || check_instance(inst) != OK) - { - return -EINVAL; - } - - return lapi_req(LTE_CMDID_LWM2M_READRESP, - (FAR void *)&inarg, 5, NULL, 0, NULL); -} - -/**************************************************************************** - * Name: lte_m2m_writeresponse - ****************************************************************************/ - -int lte_m2m_writeresponse(int seq_no, FAR struct lwm2mstub_instance_s *inst, - int resp) -{ - FAR void *inarg[3] = { - (FAR void *)(uintptr_t)seq_no, (FAR void *)(uintptr_t)resp, inst - }; - - if (!inst || check_instance(inst) != OK) - { - return -EINVAL; - } - - return lapi_req(LTE_CMDID_LWM2M_WRITERESP, - (FAR void *)&inarg, 3, NULL, 0, NULL); -} - -/**************************************************************************** - * Name: lte_m2m_executeresp - ****************************************************************************/ - -int lte_m2m_executeresp(int seq_no, FAR struct lwm2mstub_instance_s *inst, - int resp) -{ - FAR void *inarg[3] = { - (FAR void *)(uintptr_t)seq_no, (FAR void *)(uintptr_t)resp, inst - }; - - if (!inst || check_instance(inst) != OK) - { - return -EINVAL; - } - - return lapi_req(LTE_CMDID_LWM2M_EXECRESP, - (FAR void *)&inarg, 3, NULL, 0, NULL); -} - -/**************************************************************************** - * Name: lte_m2m_observeresp - ****************************************************************************/ - -int lte_m2m_observeresp(int seq_no, int resp) -{ - FAR void *inarg[2] = { - (FAR void *)(uintptr_t)seq_no, (FAR void *)(uintptr_t)resp - }; - - return lapi_req(LTE_CMDID_LWM2M_OBSERVERESP, - (FAR void *)&inarg, 2, NULL, 0, NULL); -} - -/**************************************************************************** - * Name: lte_m2m_observeupdate - ****************************************************************************/ - -int lte_m2m_observeupdate(FAR char *token, - FAR struct lwm2mstub_instance_s *inst, - FAR char *value, int len) -{ - FAR void *inarg[4] = { - token, inst, value, (FAR void *)(uintptr_t)len - }; - - if (!token || !inst || !value || len <= 0) - { - return -EINVAL; - } - - return lapi_req(LTE_CMDID_LWM2M_OBSERVEUPDATE, - (FAR void *)&inarg, 4, NULL, 0, NULL); -} - -/**************************************************************************** - * Name: lte_setm2m_endpointname - ****************************************************************************/ - -int lte_setm2m_endpointname(FAR char *name) -{ - return lapi_req(LTE_CMDID_LWM2M_SETEP, (FAR void **)name, - 1, NULL, 0, NULL); -} - -/**************************************************************************** - * Name: lte_getm2m_endpointname - ****************************************************************************/ - -int lte_getm2m_endpointname(FAR char *name, int len) -{ - FAR void *outarg[2] = { - name, (FAR void *)(uintptr_t)len - }; - - if (!name || len <= 0) - { - return -EINVAL; - } - - return lapi_req(LTE_CMDID_LWM2M_GETEP, NULL, - 0, (FAR void *)&outarg, 2, NULL); -} - -/**************************************************************************** - * Name: lte_getm2m_servernum - ****************************************************************************/ - -int lte_getm2m_servernum(void) -{ - int dummy_arg; /* Dummy for blocking API call */ - return lapi_req(LTE_CMDID_LWM2M_GETSRVNUM, NULL, 0, - (FAR void **)&dummy_arg, 0, NULL); -} - -/**************************************************************************** - * Name: lte_setm2m_servernum - ****************************************************************************/ - -int lte_setm2m_serverinfo(FAR struct lwm2mstub_serverinfo_s *info, int id) -{ - FAR void *inarg[2] = { - info, (FAR void *)(uintptr_t)id - }; - - if (!info) - { - return -EINVAL; - } - - return lapi_req(LTE_CMDID_LWM2M_SETSRVINFO, &inarg, 2, NULL, 0, NULL); -} - -/**************************************************************************** - * Name: lte_getm2m_serverinfo - ****************************************************************************/ - -int lte_getm2m_serverinfo(FAR struct lwm2mstub_serverinfo_s *info, int id) -{ - FAR void *outarg[2] = { - info, (FAR void *)(uintptr_t)id - }; - - if (!info) - { - return -EINVAL; - } - - return lapi_req(LTE_CMDID_LWM2M_GETSRVINFO, NULL, 0, &outarg, 2, NULL); -} - -/**************************************************************************** - * Name: lte_getm2m_enabled_objectnum - ****************************************************************************/ - -int lte_getm2m_enabled_objectnum(void) -{ - int dummy_arg; /* Dummy for blocking API call */ - return lapi_req(LTE_CMDID_LWM2M_GETACTIVEOBJNUM, NULL, 0, - (FAR void *)&dummy_arg, 0, NULL); -} - -/**************************************************************************** - * Name: lte_getm2m_enabled_objects - ****************************************************************************/ - -int lte_getm2m_enabled_objects(FAR uint16_t *objids, int objnum) -{ - FAR void *outarg[2] = { - objids, (FAR void *)(uintptr_t)objnum - }; - - if (!objids || objnum <= 0) - { - return -EINVAL; - } - - return lapi_req(LTE_CMDID_LWM2M_GETACTIVEOBJ, NULL, 0, &outarg, 2, NULL); -} - -/**************************************************************************** - * Name: lte_enablem2m_objects - ****************************************************************************/ - -int lte_enablem2m_objects(FAR uint16_t *objids, int objnum) -{ - FAR void *inarg[2] = { - objids, (FAR void *)(uintptr_t)objnum - }; - - if (!objids || objnum <= 0) - { - return -EINVAL; - } - - insert_sort(objids, objnum); - - return lapi_req(LTE_CMDID_LWM2M_SETACTIVEOBJ, &inarg, 2, NULL, 0, NULL); -} - -/**************************************************************************** - * Name: lte_getm2m_objresourcenum - ****************************************************************************/ - -int lte_getm2m_objresourcenum(uint16_t objid) -{ - int dummy_arg; /* Dummy for blocking API call */ - return lapi_req(LTE_CMDID_LWM2M_GETOBJRESNUM, &objid, 1, - (FAR void *)&dummy_arg, 0, NULL); -} - -/**************************************************************************** - * Name: lte_getm2m_objresourceinfo - ****************************************************************************/ - -int lte_getm2m_objresourceinfo(uint16_t objid, int res_num, - FAR struct lwm2mstub_resource_s *reses) -{ - FAR void *outarg[2] = { - reses, (FAR void *)(uintptr_t)res_num - }; - - if (!reses || res_num <= 0) - { - return -EINVAL; - } - - return lapi_req(LTE_CMDID_LWM2M_GETOBJRESOURCE, - &objid, 1, outarg, 2, NULL); -} - -/**************************************************************************** - * Name: lte_setm2m_rat - ****************************************************************************/ - -int lte_setm2m_rat(int rat) -{ - int dummy_arg; /* Dummy for blocking API call */ - - switch (rat) - { - case LTE_RAT_CATM: - case LTE_RAT_NBIOT: - break; - default: - return -EINVAL; - break; - } - - return lapi_req(LTE_CMDID_LWM2M_CHANGERAT, &rat, 1, - (FAR void *)&dummy_arg, 0, NULL); -} - -/**************************************************************************** - * Name: lte_getm2m_rat - ****************************************************************************/ - -int lte_getm2m_rat(void) -{ - int dummy_arg; /* Dummy for blocking API call */ - return lapi_req(LTE_CMDID_LWM2M_GETRAT, NULL, 0, - (FAR void *)&dummy_arg, 0, NULL); -} - -/**************************************************************************** - * Name: lte_setm2m_objectdefinition - ****************************************************************************/ - -int lte_setm2m_objectdefinition(uint16_t objids, int res_num, - FAR struct lwm2mstub_resource_s *resucs) -{ - FAR void *inarg[3] = { - (FAR void *)(uintptr_t)objids, (FAR void *)(uintptr_t)res_num, resucs - }; - - return lapi_req(LTE_CMDID_LWM2M_SETOBJRESOURCE, inarg, 3, NULL, 0, NULL); -} - -/**************************************************************************** - * Name: lte_apply_m2msetting - ****************************************************************************/ - -int lte_apply_m2msetting(void) -{ - return lapi_req(LTE_CMDID_LWM2M_APPLY_SETTING, NULL, 0, NULL, 0, NULL); -} - -/**************************************************************************** - * Name: lte_set_report_m2mwrite - ****************************************************************************/ - -int lte_set_report_m2mwrite(lwm2mstub_write_cb_t cb) -{ - return lapi_req(LTE_CMDID_LWM2M_WRITE_EVT, NULL, 0, NULL, 0, cb); -} - -/**************************************************************************** - * Name: lte_set_report_m2mread - ****************************************************************************/ - -int lte_set_report_m2mread(lwm2mstub_read_cb_t cb) -{ - return lapi_req(LTE_CMDID_LWM2M_READ_EVT, NULL, 0, NULL, 0, cb); -} - -/**************************************************************************** - * Name: lte_set_report_m2mexec - ****************************************************************************/ - -int lte_set_report_m2mexec(lwm2mstub_exec_cb_t cb) -{ - return lapi_req(LTE_CMDID_LWM2M_EXEC_EVT, NULL, 0, NULL, 0, cb); -} - -/**************************************************************************** - * Name: lte_set_report_m2movstart - ****************************************************************************/ - -int lte_set_report_m2movstart(lwm2mstub_ovstart_cb_t cb) -{ - return lapi_req(LTE_CMDID_LWM2M_OVSTART_EVT, NULL, 0, NULL, 0, cb); -} - -/**************************************************************************** - * Name: lte_set_report_m2movstop - ****************************************************************************/ - -int lte_set_report_m2movstop(lwm2mstub_ovstop_cb_t cb) -{ - return lapi_req(LTE_CMDID_LWM2M_OVSTOP_EVT, NULL, 0, NULL, 0, cb); -} - -/**************************************************************************** - * Name: lte_set_report_m2moperation - ****************************************************************************/ - -int lte_set_report_m2moperation(lwm2mstub_operation_cb_t cb) -{ - return lapi_req(LTE_CMDID_LWM2M_SERVEROP_EVT, NULL, 0, NULL, 0, cb); -} - -/**************************************************************************** - * Name: lte_set_report_m2mfwupdate - ****************************************************************************/ - -int lte_set_report_m2mfwupdate(lwm2mstub_fwupstate_cb_t cb) -{ - return lapi_req(LTE_CMDID_LWM2M_FWUP_EVT, NULL, 0, NULL, 0, cb); -} - -/**************************************************************************** - * Name: lte_getm2m_qmode - ****************************************************************************/ - -bool lte_getm2m_qmode(void) -{ - int dummy_arg; /* Dummy for blocking API call */ - return lapi_req(LTE_CMDID_LWM2M_GETQMODE, NULL, 0, - (FAR void **)&dummy_arg, 0, NULL); -} - -/**************************************************************************** - * Name: lte_set_report_m2mfwupdate - ****************************************************************************/ - -int lte_setm2m_qmode(bool en) -{ - return lapi_req(LTE_CMDID_LWM2M_SETQMODE, - (FAR void **)(uintptr_t)(en ? 1 : 0), 1, NULL, 0, NULL); -} diff --git a/lte/lapi/src/lapi_net.c b/lte/lapi/src/lapi_net.c deleted file mode 100644 index 9eaae54af..000000000 --- a/lte/lapi/src/lapi_net.c +++ /dev/null @@ -1,505 +0,0 @@ -/**************************************************************************** - * apps/lte/lapi/src/lapi_net.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include -#include -#include - -#include "lte/lte_api.h" -#include "lte/lapi.h" - -#include "lapi_dbg.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define CELLINFO_PERIOD_MIN (1) -#define CELLINFO_PERIOD_MAX (4233600) - -#define QUALITY_PERIOD_MIN (1) -#define QUALITY_PERIOD_MAX (4233600) - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static int lte_get_netinfo_inparam_check(uint8_t pdn_num) -{ - if (LTE_SESSION_ID_MIN > pdn_num || LTE_SESSION_ID_MAX < pdn_num) - { - return -EINVAL; - } - - return OK; -} - -static int lte_set_rat_inparam_check(uint8_t rat, bool persistent) -{ - if (rat != LTE_RAT_CATM && - rat != LTE_RAT_NBIOT) - { - lapi_printf("RAT type is invalid [%d].\n", rat); - return -EINVAL; - } - - if (persistent != LTE_ENABLE && - persistent != LTE_DISABLE) - { - lapi_printf("persistent is invalid [%d].\n", persistent); - return -EINVAL; - } - - return OK; -} - -static int lte_set_report_cellinfo_inparam_check( - cellinfo_report_cb_t callback, uint32_t period) -{ - if (callback) - { - if (CELLINFO_PERIOD_MIN > period || CELLINFO_PERIOD_MAX < period) - { - lapi_printf("Invalid parameter.\n"); - return -EINVAL; - } - } - - return OK; -} - -static int lte_set_report_quality_inparam_check(quality_report_cb_t callback, - uint32_t period) -{ - if (callback) - { - if (QUALITY_PERIOD_MIN > period || QUALITY_PERIOD_MAX < period) - { - lapi_printf("Invalid parameter.\n"); - return -EINVAL; - } - } - - return OK; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/* Synchronous APIs */ - -int lte_get_netinfo_sync(uint8_t pdn_num, FAR lte_netinfo_t *info) -{ - int ret; - int result; - FAR void *inarg[] = - { - &pdn_num - }; - - FAR void *outarg[] = - { - &result, info, &pdn_num - }; - - if (lte_get_netinfo_inparam_check(pdn_num) || info == NULL) - { - return -EINVAL; - } - - ret = lapi_req(LTE_CMDID_GETNETINFO, - (FAR void *)inarg, nitems(inarg), - (FAR void *)outarg, nitems(outarg), - NULL); - if (ret == 0) - { - ret = result; - } - - return ret; -} - -int lte_get_localtime_sync(FAR lte_localtime_t *localtime) -{ - int ret; - int result; - FAR void *outarg[] = - { - &result, localtime - }; - - if (localtime == NULL) - { - return -EINVAL; - } - - ret = lapi_req(LTE_CMDID_GETLTIME, - NULL, 0, - (FAR void *)outarg, nitems(outarg), - NULL); - if (ret == 0) - { - ret = result; - } - - return ret; -} - -#ifdef CONFIG_LTE_LAPI_KEEP_COMPATIBILITY -int lte_get_operator_sync(FAR char *oper) -#else -int lte_get_operator_sync(FAR char *oper, size_t len) -#endif -{ - int ret; - int result; - FAR void *outarg[] = - { -#ifdef CONFIG_LTE_LAPI_KEEP_COMPATIBILITY - &result, oper -#else - &result, oper, &len -#endif - }; - - if (oper == NULL) - { - return -EINVAL; - } - - ret = lapi_req(LTE_CMDID_GETOPER, - NULL, 0, - (FAR void *)outarg, nitems(outarg), - NULL); - if (ret == 0) - { - ret = result; - } - - return ret; -} - -int lte_get_quality_sync(FAR lte_quality_t *quality) -{ - int ret; - int result; - FAR void *outarg[] = - { - &result, quality - }; - - if (quality == NULL) - { - return -EINVAL; - } - - ret = lapi_req(LTE_CMDID_GETQUAL, - NULL, 0, - (FAR void *)outarg, nitems(outarg), - NULL); - if (ret == 0) - { - ret = result; - } - - return ret; -} - -int lte_get_cellinfo_sync(FAR lte_cellinfo_t *cellinfo) -{ - int ret; - int result; - FAR void *outarg[] = - { - &result, cellinfo - }; - - if (cellinfo == NULL) - { - return -EINVAL; - } - - ret = lapi_req(LTE_CMDID_GETCELL, - NULL, 0, - (FAR void *)outarg, nitems(outarg), - NULL); - if (ret == 0) - { - ret = result; - } - - return ret; -} - -int lte_get_rat_sync(void) -{ - int ret; - int result; - lte_ratinfo_t ratinfo; - FAR void *outarg[] = - { - &result, &ratinfo - }; - - ret = lapi_req(LTE_CMDID_GETRAT, - NULL, 0, - (FAR void *)outarg, nitems(outarg), - NULL); - if (ret == 0) - { - ret = ratinfo.rat; - } - - return ret; -} - -int lte_set_rat_sync(uint8_t rat, bool persistent) -{ - int ret; - int result; - FAR void *inarg[] = - { - &rat, &persistent - }; - - FAR void *outarg[] = - { - &result - }; - - if (lte_set_rat_inparam_check(rat, persistent)) - { - return -EINVAL; - } - - ret = lapi_req(LTE_CMDID_SETRAT, - (FAR void *)inarg, nitems(inarg), - (FAR void *)outarg, nitems(outarg), - NULL); - if (ret == 0) - { - ret = result; - } - - return ret; -} - -int lte_get_ratinfo_sync(FAR lte_ratinfo_t *info) -{ - int ret; - int result; - FAR void *outarg[] = - { - &result, info - }; - - if (info == NULL) - { - return -EINVAL; - } - - ret = lapi_req(LTE_CMDID_GETRATINFO, - NULL, 0, - (FAR void *)outarg, nitems(outarg), - NULL); - if (ret == 0) - { - ret = result; - } - - return ret; -} - -/* Asynchronous APIs */ - -#ifdef CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API - -int lte_get_netinfo(get_netinfo_cb_t callback) -{ - if (callback == NULL) - { - return -EINVAL; - } - - return lapi_req(LTE_CMDID_GETNETINFO | LTE_CMDOPT_ASYNC_BIT, - NULL, 0, NULL, 0, callback); -} - -int lte_get_localtime(get_localtime_cb_t callback) -{ - if (callback == NULL) - { - return -EINVAL; - } - - return lapi_req(LTE_CMDID_GETLTIME | LTE_CMDOPT_ASYNC_BIT, - NULL, 0, NULL, 0, callback); -} - -int lte_get_operator(get_operator_cb_t callback) -{ - if (callback == NULL) - { - return -EINVAL; - } - - return lapi_req(LTE_CMDID_GETOPER | LTE_CMDOPT_ASYNC_BIT, - NULL, 0, NULL, 0, callback); -} - -int lte_get_quality(get_quality_cb_t callback) -{ - if (callback == NULL) - { - return -EINVAL; - } - - return lapi_req(LTE_CMDID_GETQUAL | LTE_CMDOPT_ASYNC_BIT, - NULL, 0, NULL, 0, callback); -} - -#endif /* CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API */ - -int lte_set_report_netinfo(netinfo_report_cb_t callback) -{ - int ret; - int result; - FAR void *inarg[] = - { - callback - }; - - FAR void *outarg[] = - { - &result - }; - - ret = lapi_req(LTE_CMDID_REPNETINFO, - (FAR void *)inarg, nitems(inarg), - (FAR void *)outarg, nitems(outarg), - callback); - if (ret == 0) - { - ret = result; - } - - return ret; -} - -int lte_set_report_localtime(localtime_report_cb_t callback) -{ - int ret; - int result; - int32_t id = LTE_CMDID_REPLTIME; - FAR void *inarg[] = - { - callback, &id - }; - - FAR void *outarg[] = - { - &result - }; - - ret = lapi_req(LTE_CMDID_REPLTIME, - (FAR void *)inarg, nitems(inarg), - (FAR void *)outarg, nitems(outarg), - callback); - if (ret == 0) - { - ret = result; - } - - return ret; -} - -int lte_set_report_quality(quality_report_cb_t callback, uint32_t period) -{ - int ret; - int result; - FAR void *inarg[] = - { - callback, &period - }; - - FAR void *outarg[] = - { - &result - }; - - if (lte_set_report_quality_inparam_check(callback, period)) - { - return -EINVAL; - } - - ret = lapi_req(LTE_CMDID_REPQUAL, - (FAR void *)inarg, nitems(inarg), - (FAR void *)outarg, nitems(outarg), - callback); - if (ret == 0) - { - ret = result; - } - - return ret; -} - -int lte_set_report_cellinfo(cellinfo_report_cb_t callback, - uint32_t period) -{ - int ret; - int result; - FAR void *inarg[] = - { - callback, &period - }; - - FAR void *outarg[] = - { - &result - }; - - if (lte_set_report_cellinfo_inparam_check(callback, period)) - { - return -EINVAL; - } - - ret = lapi_req(LTE_CMDID_REPCELL, - (FAR void *)inarg, nitems(inarg), - (FAR void *)outarg, nitems(outarg), - callback); - if (ret == 0) - { - ret = result; - } - - return ret; -} diff --git a/lte/lapi/src/lapi_other.c b/lte/lapi/src/lapi_other.c deleted file mode 100644 index 14a0734ec..000000000 --- a/lte/lapi/src/lapi_other.c +++ /dev/null @@ -1,178 +0,0 @@ -/**************************************************************************** - * apps/lte/lapi/src/lapi_other.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include "lte/lte_api.h" -#include "lte/lapi.h" - -#include "lapi_dbg.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define ATCMD_HEADER "AT" -#define ATCMD_HEADER_LEN (2) -#define ATCMD_FOOTER '\r' -#define ATCMD_FOOTER_LEN (1) - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: lapi_req - ****************************************************************************/ - -int lapi_req(uint32_t cmdid, FAR void *inp, size_t ilen, FAR void *outp, - size_t olen, FAR void *cb) -{ - int ret; - int sock; - struct lte_ioctl_data_s cmd; - - sock = socket(NET_SOCK_FAMILY, NET_SOCK_TYPE, NET_SOCK_PROTOCOL); - if (sock < 0) - { - ret = -errno; - lapi_printf("failed to open socket:%d\n", errno); - } - else - { - cmd.cmdid = cmdid; - cmd.inparam = inp; - cmd.inparamlen = ilen; - cmd.outparam = outp; - cmd.outparamlen = olen; - cmd.cb = cb; - - ret = ioctl(sock, SIOCLTECMD, (unsigned long)&cmd); - if (ret < 0) - { - ret = -errno; - lapi_printf("failed to ioctl:%d\n", errno); - } - - close(sock); - } - - return ret; -} - -int lte_data_allow_sync(uint8_t session_id, uint8_t allow, - uint8_t roaming_allow) -{ - lapi_printf("lte_data_allow_sync() is not supported.\n"); - - return -EOPNOTSUPP; -} - -int lte_data_allow(uint8_t session_id, uint8_t allow, - uint8_t roaming_allow, data_allow_cb_t callback) -{ - lapi_printf("lte_data_allow() is not supported.\n"); - - return -EOPNOTSUPP; -} - -int lte_get_errinfo(FAR lte_errinfo_t *info) -{ - int ret; - - FAR void *outarg[] = - { - info - }; - - if (!info) - { - return -EINVAL; - } - - ret = lapi_req(LTE_CMDID_GETERRINFO, - NULL, 0, - (FAR void *)outarg, nitems(outarg), - NULL); - - return ret; -} - -int lte_send_atcmd_sync(FAR const char *cmd, int cmdlen, - FAR char *respbuff, int respbufflen, FAR int *resplen) -{ - int32_t ret; - FAR void *inarg[] = - { - (FAR void *)cmd, (FAR void *)(uintptr_t)cmdlen - }; - - FAR void *outarg[] = - { - respbuff, (FAR void *)(uintptr_t)respbufflen, resplen - }; - - if (!cmd - || (ATCMD_HEADER_LEN + ATCMD_FOOTER_LEN) > cmdlen - || LTE_AT_COMMAND_MAX_LEN < cmdlen - || !respbuff || !respbufflen || !resplen) - { - return -EINVAL; - } - - if (0 != strncmp(cmd, ATCMD_HEADER, ATCMD_HEADER_LEN)) - { - return -EINVAL; - } - - if (ATCMD_FOOTER != cmd[cmdlen - ATCMD_FOOTER_LEN]) - { - return -EINVAL; - } - - ret = lapi_req(LTE_CMDID_SENDATCMD, - (FAR void *)inarg, nitems(inarg), - (FAR void *)outarg, nitems(outarg), - NULL); - - return ret; -} diff --git a/lte/lapi/src/lapi_pdn.c b/lte/lapi/src/lapi_pdn.c deleted file mode 100644 index def048d70..000000000 --- a/lte/lapi/src/lapi_pdn.c +++ /dev/null @@ -1,266 +0,0 @@ -/**************************************************************************** - * apps/lte/lapi/src/lapi_pdn.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include -#include -#include - -#include "lte/lte_api.h" -#include "lte/lapi.h" - -#include "lapi_dbg.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static int lte_activate_pdn_inparam_check(FAR lte_apn_setting_t *apn) -{ - int32_t mask = 0; - - if (!apn) - { - lapi_printf("apn is null.\n"); - return -EINVAL; - } - - if ((!apn->apn) || (strnlen((char *)apn->apn, LTE_APN_LEN) >= LTE_APN_LEN)) - { - lapi_printf("apn is length overflow.\n"); - return -EINVAL; - } - - if ((apn->ip_type < LTE_IPTYPE_V4) || - (apn->ip_type > LTE_IPTYPE_NON)) - { - lapi_printf("ip type is invalid. iptype=%d\n", apn->ip_type); - return -EINVAL; - } - - if ((apn->auth_type < LTE_APN_AUTHTYPE_NONE) || - (apn->auth_type > LTE_APN_AUTHTYPE_CHAP)) - { - lapi_printf("auth type is invalid. authtype=%d\n", apn->auth_type); - return -EINVAL; - } - - if (apn->user_name && apn->password) - { - if (strnlen((FAR char *)apn->user_name, LTE_APN_USER_NAME_LEN) >= - LTE_APN_USER_NAME_LEN) - { - lapi_printf("username is length overflow.\n"); - return -EINVAL; - } - - if (strnlen((FAR char *)apn->password, LTE_APN_PASSWD_LEN) >= - LTE_APN_PASSWD_LEN) - { - lapi_printf("password is length overflow.\n"); - return -EINVAL; - } - } - else - { - if (apn->auth_type != LTE_APN_AUTHTYPE_NONE) - { - lapi_printf("authentication information is invalid.\n"); - return -EINVAL; - } - } - - mask = (LTE_APN_TYPE_DEFAULT | - LTE_APN_TYPE_MMS | LTE_APN_TYPE_SUPL | LTE_APN_TYPE_DUN | - LTE_APN_TYPE_HIPRI | LTE_APN_TYPE_FOTA | LTE_APN_TYPE_IMS | - LTE_APN_TYPE_CBS | LTE_APN_TYPE_IA | LTE_APN_TYPE_EMERGENCY); - if (0 == (apn->apn_type & mask)) - { - lapi_printf("apn type is invalid. apntype=%08ld / mask=%08ld \n", - apn->apn_type, mask); - return -EINVAL; - } - - return OK; -} - -static int lte_deactivate_pdn_inparam_check(uint8_t session_id) -{ - if (LTE_SESSION_ID_MIN > session_id || - LTE_SESSION_ID_MAX < session_id) - { - lapi_printf("Invalid session id %d.\n", session_id); - return -EINVAL; - } - - return OK; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/* Synchronous APIs */ - -int lte_activate_pdn_sync(FAR lte_apn_setting_t *apn, FAR lte_pdn_t *pdn) -{ - int ret; - int result; - FAR void *inarg[] = - { - apn - }; - - FAR void *outarg[] = - { - &result, pdn - }; - - if (lte_activate_pdn_inparam_check(apn) || pdn == NULL) - { - return -EINVAL; - } - - ret = lapi_req(LTE_CMDID_ACTPDN, - (FAR void *)inarg, nitems(inarg), - (FAR void *)outarg, nitems(outarg), - NULL); - if (ret == 0) - { - ret = result; - } - - return ret; -} - -int lte_deactivate_pdn_sync(uint8_t session_id) -{ - int ret; - int result; - FAR void *inarg[] = - { - &session_id - }; - - FAR void *outarg[] = - { - &result - }; - - if (lte_deactivate_pdn_inparam_check(session_id)) - { - return -EINVAL; - } - - ret = lapi_req(LTE_CMDID_DEACTPDN, - (FAR void *)inarg, nitems(inarg), - (FAR void *)outarg, nitems(outarg), - NULL); - if (ret == 0) - { - ret = result; - } - - return ret; -} - -/* Asynchronous APIs */ - -int lte_activate_pdn(FAR lte_apn_setting_t *apn, activate_pdn_cb_t callback) -{ - FAR void *inarg[] = - { - apn - }; - - if (callback == NULL) - { - return -EINVAL; - } - - if (lte_activate_pdn_inparam_check(apn)) - { - return -EINVAL; - } - - return lapi_req(LTE_CMDID_ACTPDN | LTE_CMDOPT_ASYNC_BIT, - (FAR void *)inarg, nitems(inarg), - NULL, 0, callback); -} - -#ifdef CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API - -int lte_deactivate_pdn(uint8_t session_id, deactivate_pdn_cb_t callback) -{ - FAR void *inarg[] = - { - &session_id - }; - - if (callback == NULL) - { - return -EINVAL; - } - - if (lte_deactivate_pdn_inparam_check(session_id)) - { - return -EINVAL; - } - - return lapi_req(LTE_CMDID_DEACTPDN | LTE_CMDOPT_ASYNC_BIT, - (FAR void *)inarg, nitems(inarg), - NULL, 0, callback); -} - -#endif /* CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API */ - -int lte_activate_pdn_cancel(void) -{ - int ret; - int result; - FAR void *outarg[] = - { - &result - }; - - ret = lapi_req(LTE_CMDID_ACTPDNCAN, - NULL, 0, - (FAR void *)outarg, nitems(outarg), - NULL); - if (ret == 0) - { - ret = result; - } - - return ret; -} diff --git a/lte/lapi/src/lapi_pin.c b/lte/lapi/src/lapi_pin.c deleted file mode 100644 index 0a0496fa7..000000000 --- a/lte/lapi/src/lapi_pin.c +++ /dev/null @@ -1,407 +0,0 @@ -/**************************************************************************** - * apps/lte/lapi/src/lapi_pin.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include -#include -#include - -#include "lte/lte_api.h" -#include "lte/lapi.h" - -#include "lapi_dbg.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define SETPIN_TARGETPIN_MIN LTE_TARGET_PIN -#define SETPIN_TARGETPIN_MAX LTE_TARGET_PIN2 - -#define APICMD_SETPINLOCK_PINCODE_LEN 9 - -#define SETPIN_MIN_PIN_LEN (4) -#define SETPIN_MAX_PIN_LEN ((APICMD_SETPINLOCK_PINCODE_LEN) - 1) - -#define APICMD_ENTERPIN_PINCODE_LEN 9 -#define ENTERPIN_MIN_PIN_LEN (4) -#define ENTERPIN_MAX_PIN_LEN ((APICMD_ENTERPIN_PINCODE_LEN) - 1) - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static int lte_change_pin_inparam_check(int8_t target_pin, FAR char *pincode, - FAR char *new_pincode) -{ - uint8_t pinlen = 0; - - if (!pincode || !new_pincode) - { - lapi_printf("Input argument is NULL.\n"); - return -EINVAL; - } - - if (SETPIN_TARGETPIN_MIN > target_pin || SETPIN_TARGETPIN_MAX < target_pin) - { - lapi_printf("Unsupport change type. type:%d\n", target_pin); - return -EINVAL; - } - - pinlen = strnlen(pincode, APICMD_SETPINLOCK_PINCODE_LEN); - if (pinlen < SETPIN_MIN_PIN_LEN || SETPIN_MAX_PIN_LEN < pinlen) - { - return -EINVAL; - } - - pinlen = strnlen(new_pincode, APICMD_SETPINLOCK_PINCODE_LEN); - if (pinlen < SETPIN_MIN_PIN_LEN || SETPIN_MAX_PIN_LEN < pinlen) - { - return -EINVAL; - } - - return OK; -} - -static int lte_enter_pin_inparam_check(FAR char *pincode, - FAR char *new_pincode) -{ - uint8_t pinlen = 0; - - if (!pincode) - { - lapi_printf("Input argument is NULL.\n"); - return -EINVAL; - } - - pinlen = strnlen(pincode, APICMD_SETPINLOCK_PINCODE_LEN); - if (pinlen < ENTERPIN_MIN_PIN_LEN || ENTERPIN_MAX_PIN_LEN < pinlen) - { - lapi_printf("Invalid PIN code length.length:%d\n", pinlen); - return -EINVAL; - } - - if (new_pincode) - { - lapi_printf("lte_enter_pin() doesn't support entering PUK code.\n"); - lapi_printf("lte_enter_pin_sync() doesn't support entering" - " PUK code.\n"); - return -EINVAL; - } - - return OK; -} - -static int lte_set_pinenable_inparam_check(bool enable, FAR char *pincode) -{ - uint8_t pinlen = 0; - - if (!pincode) - { - lapi_printf("Input argument is NULL.\n"); - return -EINVAL; - } - - pinlen = strnlen(pincode, APICMD_SETPINLOCK_PINCODE_LEN); - if (pinlen < SETPIN_MIN_PIN_LEN || SETPIN_MAX_PIN_LEN < pinlen) - { - return -EINVAL; - } - - return OK; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/* Synchronous APIs */ - -int lte_get_pinset_sync(FAR lte_getpin_t *pinset) -{ - int ret; - int result; - FAR void *outarg[] = - { - &result, pinset - }; - - if (pinset == NULL) - { - return -EINVAL; - } - - ret = lapi_req(LTE_CMDID_GETPINSET, - NULL, 0, - (FAR void *)outarg, nitems(outarg), - NULL); - if (ret == 0) - { - ret = result; - } - - return ret; -} - -int lte_set_pinenable_sync(bool enable, FAR char *pincode, - FAR uint8_t *attemptsleft) -{ - int ret; - int result; - FAR void *inarg[] = - { - &enable, pincode - }; - - FAR void *outarg[] = - { - &result, attemptsleft - }; - - if (lte_set_pinenable_inparam_check(enable, pincode) || - attemptsleft == NULL) - { - return -EINVAL; - } - - ret = lapi_req(LTE_CMDID_PINENABLE, - (FAR void *)inarg, nitems(inarg), - (FAR void *)outarg, nitems(outarg), - NULL); - if (ret == 0) - { - ret = result; - } - - return ret; -} - -int lte_change_pin_sync(int8_t target_pin, FAR char *pincode, - FAR char *new_pincode, FAR uint8_t *attemptsleft) -{ - int ret; - int result; - FAR void *inarg[] = - { - &target_pin, pincode, new_pincode - }; - - FAR void *outarg[] = - { - &result, attemptsleft - }; - - if (lte_change_pin_inparam_check(target_pin, pincode, new_pincode) || - attemptsleft == NULL) - { - return -EINVAL; - } - - ret = lapi_req(LTE_CMDID_CHANGEPIN, - (FAR void *)inarg, nitems(inarg), - (FAR void *)outarg, nitems(outarg), - NULL); - if (ret == 0) - { - ret = result; - } - - return ret; -} - -int lte_enter_pin_sync(FAR char *pincode, FAR char *new_pincode, - FAR uint8_t *simstat, FAR uint8_t *attemptsleft) -{ - int ret; - int result; - FAR void *inarg[] = - { - pincode, new_pincode - }; - - FAR void *outarg[] = - { - &result, simstat, attemptsleft - }; - - lte_getpin_t pinset = - { - 0 - }; - - if (lte_enter_pin_inparam_check(pincode, new_pincode) || simstat == NULL || - attemptsleft == NULL) - { - return -EINVAL; - } - - ret = lte_get_pinset_sync(&pinset); - if (ret < 0) - { - lapi_printf("Failed to get pinset.%d\n", ret); - return ret; - } - - if (simstat) - { - *simstat = pinset.status; - } - - if (attemptsleft) - { - if (pinset.status == LTE_PINSTAT_SIM_PUK) - { - *attemptsleft = pinset.puk_attemptsleft; - } - else - { - *attemptsleft = pinset.pin_attemptsleft; - } - } - - if (pinset.enable == LTE_DISABLE) - { - lapi_printf( - "PIN lock is disable. Don't need to run lte_enter_pin_sync().\n"); - return -EPERM; - } - else if (pinset.status != LTE_PINSTAT_SIM_PIN) - { - if (pinset.status == LTE_PINSTAT_SIM_PUK) - { - lapi_printf( - "This SIM is PUK locked. lte_enter_pin_sync() can't be used.\n"); - } - else - { - lapi_printf("PIN is already unlocked. " - "Don't need to run lte_enter_pin_sync(). status:%d\n", - pinset.status); - } - - return -EPERM; - } - - ret = lapi_req(LTE_CMDID_ENTERPIN, - (FAR void *)inarg, nitems(inarg), - (FAR void *)outarg, nitems(outarg), - NULL); - if (ret == 0) - { - ret = result; - } - - return ret; -} - -/* Asynchronous APIs */ - -#ifdef CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API - -int lte_get_pinset(get_pinset_cb_t callback) -{ - if (callback == NULL) - { - return -EINVAL; - } - - return lapi_req(LTE_CMDID_GETPINSET | LTE_CMDOPT_ASYNC_BIT, - NULL, 0, NULL, 0, callback); -} - -int lte_set_pinenable(bool enable, FAR char *pincode, - set_pinenable_cb_t callback) -{ - FAR void *inarg[] = - { - &enable, pincode - }; - - if (callback == NULL) - { - return -EINVAL; - } - - if (lte_set_pinenable_inparam_check(enable, pincode)) - { - return -EINVAL; - } - - return lapi_req(LTE_CMDID_PINENABLE | LTE_CMDOPT_ASYNC_BIT, - (FAR void *)inarg, nitems(inarg), - NULL, 0, callback); -} - -int lte_change_pin(int8_t target_pin, FAR char *pincode, - FAR char *new_pincode, change_pin_cb_t callback) -{ - FAR void *inarg[] = - { - &target_pin, pincode, new_pincode - }; - - if (callback == NULL) - { - return -EINVAL; - } - - if (lte_change_pin_inparam_check(target_pin, pincode, new_pincode)) - { - return -EINVAL; - } - - return lapi_req(LTE_CMDID_CHANGEPIN | LTE_CMDOPT_ASYNC_BIT, - (FAR void *)inarg, nitems(inarg), - NULL, 0, callback); -} - -int lte_enter_pin(FAR char *pincode, FAR char *new_pincode, - enter_pin_cb_t callback) -{ - FAR void *inarg[] = - { - pincode, new_pincode - }; - - if (callback == NULL) - { - return -EINVAL; - } - - if (lte_enter_pin_inparam_check(pincode, new_pincode)) - { - return -EINVAL; - } - - return lapi_req(LTE_CMDID_ENTERPIN | LTE_CMDOPT_ASYNC_BIT, - (FAR void *)inarg, nitems(inarg), - NULL, 0, callback); -} -#endif /* CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API */ - diff --git a/lte/lapi/src/lapi_power.c b/lte/lapi/src/lapi_power.c deleted file mode 100644 index 8f5ea6c14..000000000 --- a/lte/lapi/src/lapi_power.c +++ /dev/null @@ -1,330 +0,0 @@ -/**************************************************************************** - * apps/lte/lapi/src/lapi_power.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "lte/lte_api.h" -#include "lte/lapi.h" - -#include "lapi_dbg.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define DAEMON_NAME "alt1250" -#define DAEMON_PRI 100 -#define DAEMON_STACK_SZ 2048 -#define CMD_PREFIX "-s" -#define ADDR_LEN (strlen(CMD_PREFIX) + 9) /* 32bit + '\0' */ - -#define RETRY_INTERVAL 100 -#define RETRY_OVER 3 - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -int alt1250_main(int argc, FAR char *argv[]); - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static sem_t g_lock = SEM_INITIALIZER(1); -static sem_t g_sync; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: lapi_lock - ****************************************************************************/ - -static inline void lapi_lock(FAR sem_t *lock) -{ - int ret; - - do - { - ret = sem_wait(lock); - } - while (ret == -EINTR); -} - -/**************************************************************************** - * Name: lapi_unlock - ****************************************************************************/ - -static inline void lapi_unlock(FAR sem_t *lock) -{ - sem_post(lock); -} - -/**************************************************************************** - * Name: is_daemon_running - ****************************************************************************/ - -#ifdef CONFIG_MODEM_ALT1250 -static bool is_daemon_running(void) -{ - int sock; - bool is_run = false; - - sock = socket(AF_INET, SOCK_STREAM, 0); - if (sock < 0) - { - if (errno == ENETDOWN) - { - is_run = false; - } - else - { - is_run = true; - } - } - else - { - close(sock); - is_run = true; - } - - return is_run; -} -#endif /* CONFIG_MODEM_ALT1250 */ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: lte_initialize - ****************************************************************************/ - -int lte_initialize(void) -{ - int ret = 0; - -#ifndef CONFIG_MODEM_ALT1250 - /* The modem backend can be kernel-resident (e.g. a built-in modem - * served by kernel side usrsock handler, such as the nRF91). LTE - * commands reach the modem directly via the SIOCLTECMD socket ioctl. - */ - - UNUSED(ret); - return OK; -#else - lapi_lock(&g_lock); - - if (!is_daemon_running()) - { - FAR char *argv[2]; - char addr[ADDR_LEN]; - - sem_init(&g_sync, 0, 0); - - /* address -> ascii */ - - snprintf(addr, ADDR_LEN, "%s%08lx", CMD_PREFIX, - (unsigned long)&g_sync); - - argv[0] = addr; - argv[1] = NULL; /* termination */ - - ret = task_create(DAEMON_NAME, DAEMON_PRI, DAEMON_STACK_SZ, - alt1250_main, argv); - if (ret < 0) - { - ret = -errno; - lapi_printf("failed to create task:%d\n", errno); - } - else - { - ret = 0; - sem_wait(&g_sync); - } - } - else - { - ret = -EALREADY; - } - - lapi_unlock(&g_lock); - - return ret; -#endif -} - -/**************************************************************************** - * Name: lte_finalize - ****************************************************************************/ - -int lte_finalize(void) -{ - int ret = 0; - int count = 0; - - lapi_lock(&g_lock); - - while (count < RETRY_OVER) - { - ret = lapi_req(LTE_CMDID_FIN, NULL, 0, NULL, 0, NULL); - if (ret >= 0) - { - sem_wait(&g_sync); - sem_destroy(&g_sync); - break; - } - - usleep(RETRY_INTERVAL); - count++; - } - - if (ret == -ENETDOWN) - { - ret = -EALREADY; - } - - lapi_unlock(&g_lock); - - return ret; -} - -/**************************************************************************** - * Name: lte_set_report_restart - ****************************************************************************/ - -int lte_set_report_restart(restart_report_cb_t callback) -{ - return lapi_req(LTE_CMDID_SETRESTART, NULL, 0, NULL, 0, callback); -} - -/**************************************************************************** - * Name: lte_power_on - ****************************************************************************/ - -int lte_power_on(void) -{ - return lapi_req(LTE_CMDID_POWERON, NULL, 0, NULL, 0, NULL); -} - -/**************************************************************************** - * Name: lte_power_off - ****************************************************************************/ - -int lte_power_off(void) -{ - int ret; - int count = 0; - - while (count < RETRY_OVER) - { - ret = lapi_req(LTE_CMDID_POWEROFF, NULL, 0, NULL, 0, NULL); - if ((ret >= 0) || (ret == -EALREADY)) - { - break; - } - - usleep(RETRY_INTERVAL); - count++; - } - - return ret; -} - -/**************************************************************************** - * Name: lte_acquire_wakelock - ****************************************************************************/ - -int lte_acquire_wakelock(void) -{ - return lapi_req(LTE_CMDID_TAKEWLOCK, NULL, 0, NULL, 0, NULL); -} - -/**************************************************************************** - * Name: lte_release_wakelock - ****************************************************************************/ - -int lte_release_wakelock(void) -{ - return lapi_req(LTE_CMDID_GIVEWLOCK, NULL, 0, NULL, 0, NULL); -} - -/**************************************************************************** - * Name: lte_get_wakelock_count - ****************************************************************************/ - -int lte_get_wakelock_count(void) -{ - return lapi_req(LTE_CMDID_COUNTWLOCK, NULL, 0, NULL, 0, NULL); -} - -/**************************************************************************** - * Name: lte_set_context_save_cb - ****************************************************************************/ - -int lte_set_context_save_cb(context_save_cb_t callback) -{ - return lapi_req(LTE_CMDID_SETCTXCB, NULL, 0, NULL, 0, callback); -} - -/**************************************************************************** - * Name: lte_hibernation_resume - ****************************************************************************/ - -int lte_hibernation_resume(FAR const uint8_t *res_ctx, int len) -{ - FAR void *inarg[] = - { - (FAR void *)res_ctx, - &len - }; - - int dummy_arg; /* Dummy for blocking API call */ - - if (res_ctx == NULL || len < 0) - { - return -EINVAL; - } - - return lapi_req(LTE_CMDID_RESUME, - (FAR void *)inarg, nitems(inarg), - (FAR void *)&dummy_arg, 0, NULL); -} diff --git a/lte/lapi/src/lapi_psave.c b/lte/lapi/src/lapi_psave.c deleted file mode 100644 index 8bc3aab02..000000000 --- a/lte/lapi/src/lapi_psave.c +++ /dev/null @@ -1,585 +0,0 @@ -/**************************************************************************** - * apps/lte/lapi/src/lapi_psave.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include -#include -#include - -#include "lte/lte_api.h" -#include "lte/lapi.h" - -#include "lapi_dbg.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define ALTCOMBS_EDRX_CYCLE_WBS1_MIN (LTE_EDRX_CYC_512) -#define ALTCOMBS_EDRX_CYCLE_WBS1_MAX (LTE_EDRX_CYC_262144) -#define ALTCOMBS_EDRX_CYCLE_NBS1_MIN (LTE_EDRX_CYC_2048) -#define ALTCOMBS_EDRX_CYCLE_NBS1_MAX (LTE_EDRX_CYC_1048576) -#define ALTCOMBS_EDRX_PTW_WBS1_MIN (LTE_EDRX_PTW_128) -#define ALTCOMBS_EDRX_PTW_WBS1_MAX (LTE_EDRX_PTW_2048) -#define ALTCOMBS_EDRX_PTW_NBS1_MIN (LTE_EDRX_PTW_256) -#define ALTCOMBS_EDRX_PTW_NBS1_MAX (LTE_EDRX_PTW_4096) -#define ALTCOMBS_PSM_UNIT_T3324_MIN (LTE_PSM_T3324_UNIT_2SEC) -#define ALTCOMBS_PSM_UNIT_T3324_MAX (LTE_PSM_T3324_UNIT_6MIN) -#define ALTCOMBS_PSM_UNIT_T3412_MIN (LTE_PSM_T3412_UNIT_2SEC) -#define ALTCOMBS_PSM_UNIT_T3412_MAX (LTE_PSM_T3412_UNIT_320HOUR) -#define ALTCOMBS_EDRX_INVALID (255) - -#define APICMD_EDRX_ACTTYPE_NOTUSE (0) /* eDRX is not running */ -#define APICMD_EDRX_ACTTYPE_ECGSMIOT (1) /* EC-GSM-IoT (A/Gb mode) */ -#define APICMD_EDRX_ACTTYPE_GSM (2) /* GSM (A/Gb mode) */ -#define APICMD_EDRX_ACTTYPE_IU (3) /* UTRAN (Iu mode) */ -#define APICMD_EDRX_ACTTYPE_WBS1 (4) /* E-UTRAN (WB-S1 mode) */ -#define APICMD_EDRX_ACTTYPE_NBS1 (5) /* E-UTRAN (NB-S1 mode) */ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static int lte_set_edrx_inparam_check(FAR lte_edrx_setting_t *settings) -{ - int32_t ret = 0; - - if (!settings) - { - lapi_printf("Input argument is NULL.\n"); - return -EINVAL; - } - - if (settings->act_type != LTE_EDRX_ACTTYPE_WBS1 && - settings->act_type != LTE_EDRX_ACTTYPE_NBS1 && - settings->act_type != LTE_EDRX_ACTTYPE_ECGSMIOT && - settings->act_type != LTE_EDRX_ACTTYPE_GSM && - settings->act_type != LTE_EDRX_ACTTYPE_IU && - settings->act_type != LTE_EDRX_ACTTYPE_NOTUSE) - { - lapi_printf("Input argument act_type is invalid.\n"); - return -EINVAL; - } - - ret = lte_get_rat_sync(); - if (ret < 0 && ret != -ENOTSUP) - { - lapi_printf("Unable to read RAT setting from the device." - " ret: [%ld].\n", - ret); - return ret; - } - else if (ret == -ENOTSUP) - { - /* act_type check for protocol version V1 */ - - if (LTE_EDRX_ACTTYPE_NOTUSE != settings->act_type && - LTE_EDRX_ACTTYPE_WBS1 != settings->act_type) - { - lapi_printf("Operation is not allowed[act_type : %d].\n", - settings->act_type); - return -EPERM; - } - } - else - { - /* act_type check for version V4 or later */ - - if (!((ret == LTE_RAT_CATM - && settings->act_type == LTE_EDRX_ACTTYPE_WBS1) || - (ret == LTE_RAT_NBIOT - && settings->act_type == LTE_EDRX_ACTTYPE_NBS1) || - (settings->act_type == LTE_EDRX_ACTTYPE_NOTUSE))) - { - lapi_printf("Operation is not allowed[act_type : %d," - " RAT : %ld].\n", - settings->act_type, ret); - return -EPERM; - } - } - - if (settings->enable) - { - if (settings->act_type == LTE_EDRX_ACTTYPE_WBS1) - { - if (!(ALTCOMBS_EDRX_CYCLE_WBS1_MIN <= settings->edrx_cycle && - settings->edrx_cycle <= ALTCOMBS_EDRX_CYCLE_WBS1_MAX)) - { - lapi_printf("Input argument edrx_cycle is invalid.\n"); - return -EINVAL; - } - - if (!(ALTCOMBS_EDRX_PTW_WBS1_MIN <= settings->ptw_val && - settings->ptw_val <= ALTCOMBS_EDRX_PTW_WBS1_MAX)) - { - lapi_printf("Input argument ptw is invalid.\n"); - return -EINVAL; - } - } - - if (settings->act_type == LTE_EDRX_ACTTYPE_NBS1) - { - if (!(ALTCOMBS_EDRX_CYCLE_NBS1_MIN <= settings->edrx_cycle && - settings->edrx_cycle <= ALTCOMBS_EDRX_CYCLE_NBS1_MAX)) - { - lapi_printf("Input argument edrx_cycle is invalid.\n"); - return -EINVAL; - } - - if (!(ALTCOMBS_EDRX_PTW_NBS1_MIN <= settings->ptw_val && - settings->ptw_val <= ALTCOMBS_EDRX_PTW_NBS1_MAX)) - { - lapi_printf("Input argument ptw is invalid.\n"); - return -EINVAL; - } - } - } - - return OK; -} - -static int lte_set_psm_inparam_check(FAR lte_psm_setting_t *settings) -{ - if (!settings) - { - lapi_printf("Input argument is NULL.\n"); - return -EINVAL; - } - - if (LTE_ENABLE == settings->enable) - { - if (settings->req_active_time.unit < LTE_PSM_T3324_UNIT_2SEC || - settings->req_active_time.unit > LTE_PSM_T3324_UNIT_DEACT) - { - lapi_printf("Invalid rat_time unit :%d\n", - settings->req_active_time.unit); - return -EINVAL; - } - - if (settings->req_active_time.time_val < LTE_PSM_TIMEVAL_MIN || - settings->req_active_time.time_val > LTE_PSM_TIMEVAL_MAX) - { - lapi_printf("Invalid rat_time time_val :%d\n", - settings->req_active_time.time_val); - return -EINVAL; - } - - if (settings->ext_periodic_tau_time.unit < LTE_PSM_T3412_UNIT_2SEC || - settings->ext_periodic_tau_time.unit > LTE_PSM_T3412_UNIT_DEACT) - { - lapi_printf("Invalid tau_time unit :%d\n", - settings->ext_periodic_tau_time.unit); - return -EINVAL; - } - - if (settings->ext_periodic_tau_time.time_val < LTE_PSM_TIMEVAL_MIN || - settings->ext_periodic_tau_time.time_val > LTE_PSM_TIMEVAL_MAX) - { - lapi_printf("Invalid tau_time time_val :%d\n", - settings->ext_periodic_tau_time.time_val); - return -EINVAL; - } - } - - return OK; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/* Synchronous APIs */ - -int lte_get_edrx_sync(FAR lte_edrx_setting_t *settings) -{ - int ret; - int result; - bool is_edrxevt; - FAR void *outarg[] = - { - &result, settings, &is_edrxevt - }; - - if (settings == NULL) - { - return -EINVAL; - } - - ret = lapi_req(LTE_CMDID_GETEDRX, - NULL, 0, - (FAR void *)outarg, nitems(outarg), - NULL); - if (ret == 0) - { - ret = result; - } - - return ret; -} - -int lte_set_edrx_sync(FAR lte_edrx_setting_t *settings) -{ - int ret; - int result; - FAR void *inarg[] = - { - settings - }; - - FAR void *outarg[] = - { - &result - }; - - ret = lte_set_edrx_inparam_check(settings); - if (ret < 0) - { - return ret; - } - - ret = lapi_req(LTE_CMDID_SETEDRX, - (FAR void *)inarg, nitems(inarg), - (FAR void *)outarg, nitems(outarg), - NULL); - if (ret == 0) - { - ret = result; - } - - return ret; -} - -int lte_get_psm_sync(FAR lte_psm_setting_t *settings) -{ - int ret; - int result; - int32_t id = LTE_CMDID_GETPSM; - bool is_psmevt; - FAR void *inarg[] = - { - &id - }; - - FAR void *outarg[] = - { - &result, settings, &is_psmevt - }; - - if (settings == NULL) - { - return -EINVAL; - } - - ret = lapi_req(LTE_CMDID_GETPSM, - (FAR void *)inarg, nitems(inarg), - (FAR void *)outarg, nitems(outarg), - NULL); - if (ret == 0) - { - ret = result; - } - - return ret; -} - -int lte_set_psm_sync(FAR lte_psm_setting_t *settings) -{ - int ret; - int result; - FAR void *inarg[] = - { - settings - }; - - FAR void *outarg[] = - { - &result - }; - - if (lte_set_psm_inparam_check(settings)) - { - return -EINVAL; - } - - ret = lapi_req(LTE_CMDID_SETPSM, - (FAR void *)inarg, nitems(inarg), - (FAR void *)outarg, nitems(outarg), - NULL); - if (ret == 0) - { - ret = result; - } - - return ret; -} - -int lte_get_ce_sync(FAR lte_ce_setting_t *settings) -{ - int ret; - int result; - FAR void *outarg[] = - { - &result, settings - }; - - if (settings == NULL) - { - return -EINVAL; - } - - ret = lapi_req(LTE_CMDID_GETCE, - NULL, 0, - (FAR void *)outarg, nitems(outarg), - NULL); - if (ret == 0) - { - ret = result; - } - - return ret; -} - -int lte_set_ce_sync(FAR lte_ce_setting_t *settings) -{ - int ret; - int result; - FAR void *inarg[] = - { - settings - }; - - FAR void *outarg[] = - { - &result - }; - - if (settings == NULL) - { - return -EINVAL; - } - - ret = lapi_req(LTE_CMDID_SETCE, - (FAR void *)inarg, nitems(inarg), - (FAR void *)outarg, nitems(outarg), - NULL); - if (ret == 0) - { - ret = result; - } - - return ret; -} - -int lte_get_current_edrx_sync(FAR lte_edrx_setting_t *settings) -{ - int ret; - int result; - bool is_getcedrxevt; - FAR void *outarg[] = - { - &result, settings, &is_getcedrxevt - }; - - if (settings == NULL) - { - return -EINVAL; - } - - ret = lapi_req(LTE_CMDID_GETCEDRX, - NULL, 0, - (FAR void *)outarg, nitems(outarg), - NULL); - if (ret == 0) - { - ret = result; - } - - return ret; -} - -int lte_get_current_psm_sync(FAR lte_psm_setting_t *settings) -{ - int ret; - int result; - bool is_getcpsmevt; - FAR void *outarg[] = - { - &result, settings, &is_getcpsmevt - }; - - if (settings == NULL) - { - return -EINVAL; - } - - ret = lapi_req(LTE_CMDID_GETCPSM, - NULL, 0, - (FAR void *)outarg, nitems(outarg), - NULL); - if (ret == 0) - { - ret = result; - } - - return ret; -} - -/* Asynchronous APIs */ - -#ifdef CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API - -int lte_get_edrx(get_edrx_cb_t callback) -{ - if (callback == NULL) - { - return -EINVAL; - } - - return lapi_req(LTE_CMDID_GETEDRX | LTE_CMDOPT_ASYNC_BIT, - NULL, 0, NULL, 0, callback); -} - -int lte_set_edrx(FAR lte_edrx_setting_t *settings, set_edrx_cb_t callback) -{ - int ret; - FAR void *inarg[] = - { - settings - }; - - if (callback == NULL) - { - return -EINVAL; - } - - ret = lte_set_edrx_inparam_check(settings); - if (ret < 0) - { - return ret; - } - - return lapi_req(LTE_CMDID_SETEDRX | LTE_CMDOPT_ASYNC_BIT, - (FAR void *)inarg, nitems(inarg), - NULL, 0, callback); -} - -int lte_get_psm(get_psm_cb_t callback) -{ - if (callback == NULL) - { - return -EINVAL; - } - - return lapi_req(LTE_CMDID_GETPSM | LTE_CMDOPT_ASYNC_BIT, - NULL, 0, NULL, 0, callback); -} - -int lte_set_psm(FAR lte_psm_setting_t *settings, set_psm_cb_t callback) -{ - FAR void *inarg[] = - { - settings - }; - - if (callback == NULL) - { - return -EINVAL; - } - - if (lte_set_psm_inparam_check(settings)) - { - return -EINVAL; - } - - return lapi_req(LTE_CMDID_SETPSM | LTE_CMDOPT_ASYNC_BIT, - (FAR void *)inarg, nitems(inarg), - NULL, 0, callback); -} - -int lte_get_ce(get_ce_cb_t callback) -{ - if (callback == NULL) - { - return -EINVAL; - } - - return lapi_req(LTE_CMDID_GETCE | LTE_CMDOPT_ASYNC_BIT, - NULL, 0, NULL, 0, callback); -} - -int lte_set_ce(FAR lte_ce_setting_t *settings, set_ce_cb_t callback) -{ - FAR void *inarg[] = - { - settings - }; - - if (settings == NULL || callback == NULL) - { - return -EINVAL; - } - - return lapi_req(LTE_CMDID_SETCE | LTE_CMDOPT_ASYNC_BIT, - (FAR void *)inarg, nitems(inarg), - NULL, 0, callback); -} - -int lte_get_current_edrx(get_current_edrx_cb_t callback) -{ - if (callback == NULL) - { - return -EINVAL; - } - - return lapi_req(LTE_CMDID_GETCEDRX | LTE_CMDOPT_ASYNC_BIT, - NULL, 0, NULL, 0, callback); -} - -int lte_get_dynamic_edrx_param(get_dynamic_edrx_param_cb_t callback) -{ - return lte_get_current_edrx(callback); -} - -int lte_get_current_psm(get_current_psm_cb_t callback) -{ - if (callback == NULL) - { - return -EINVAL; - } - - return lapi_req(LTE_CMDID_GETCPSM | LTE_CMDOPT_ASYNC_BIT, - NULL, 0, NULL, 0, callback); -} - -int lte_get_dynamic_psm_param(get_dynamic_psm_param_cb_t callback) -{ - return lte_get_current_psm(callback); -} -#endif /* CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API */ - diff --git a/lte/lapi/src/lapi_radio.c b/lte/lapi/src/lapi_radio.c deleted file mode 100644 index 09ce0aa05..000000000 --- a/lte/lapi/src/lapi_radio.c +++ /dev/null @@ -1,111 +0,0 @@ -/**************************************************************************** - * apps/lte/lapi/src/lapi_radio.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include -#include - -#include "lte/lte_api.h" -#include "lte/lapi.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -int lte_radio_on_sync(void) -{ - int ret; - int result; - FAR void *outarg[] = - { - &result - }; - - ret = lapi_req(LTE_CMDID_RADIOON, - NULL, 0, - (FAR void *)outarg, nitems(outarg), - NULL); - if (ret == 0) - { - ret = result; - } - - return ret; -} - -int lte_radio_off_sync(void) -{ - int ret; - int result; - FAR void *outarg[] = - { - &result - }; - - ret = lapi_req(LTE_CMDID_RADIOOFF, - NULL, 0, - (FAR void *)outarg, nitems(outarg), - NULL); - if (ret == 0) - { - ret = result; - } - - return ret; -} - -#ifdef CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API - -int lte_radio_on(radio_on_cb_t callback) -{ - if (callback == NULL) - { - return -EINVAL; - } - - return lapi_req(LTE_CMDID_RADIOON | LTE_CMDOPT_ASYNC_BIT, - NULL, 0, NULL, 0, callback); -} - -int lte_radio_off(radio_off_cb_t callback) -{ - if (callback == NULL) - { - return -EINVAL; - } - - return lapi_req(LTE_CMDID_RADIOOFF | LTE_CMDOPT_ASYNC_BIT, - NULL, 0, NULL, 0, callback); -} -#endif /* CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API */ - diff --git a/lte/lapi/src/lapi_sim.c b/lte/lapi/src/lapi_sim.c deleted file mode 100644 index 7de404417..000000000 --- a/lte/lapi/src/lapi_sim.c +++ /dev/null @@ -1,328 +0,0 @@ -/**************************************************************************** - * apps/lte/lapi/src/lapi_sim.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include -#include - -#include "lte/lte_api.h" -#include "lte/lapi.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static int lte_get_siminfo_inparam_check(uint32_t option) -{ - uint32_t mask = 0; - - mask = (LTE_SIMINFO_GETOPT_MCCMNC | - LTE_SIMINFO_GETOPT_SPN | - LTE_SIMINFO_GETOPT_ICCID | - LTE_SIMINFO_GETOPT_IMSI | - LTE_SIMINFO_GETOPT_GID1 | - LTE_SIMINFO_GETOPT_GID2); - - if (0 == (option & mask)) - { - return -EINVAL; - } - - return OK; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/* Synchronous APIs */ - -int lte_get_siminfo_sync(uint32_t option, FAR lte_siminfo_t *siminfo) -{ - int ret; - int result; - FAR void *inarg[] = - { - &option - }; - - FAR void *outarg[] = - { - &result, siminfo - }; - - if (lte_get_siminfo_inparam_check(option) || siminfo == NULL) - { - return -EINVAL; - } - - ret = lapi_req(LTE_CMDID_GETSIMINFO, - (FAR void *)inarg, nitems(inarg), - (FAR void *)outarg, nitems(outarg), - NULL); - if (ret == 0) - { - ret = result; - } - - return ret; -} - -int lte_get_imscap_sync(FAR bool *imscap) -{ - int ret; - int result; - FAR void *outarg[] = - { - &result, imscap - }; - - if (imscap == NULL) - { - return -EINVAL; - } - - ret = lapi_req(LTE_CMDID_IMSCAP, - NULL, 0, - (FAR void *)outarg, nitems(outarg), - NULL); - if (ret == 0) - { - ret = result; - } - - return ret; -} - -#ifdef CONFIG_LTE_LAPI_KEEP_COMPATIBILITY -int lte_get_imsi_sync(FAR char *imsi) -#else -int lte_get_imsi_sync(FAR char *imsi, size_t len) -#endif -{ - int ret; - int result; - uint8_t errcause; - FAR void *outarg[] = - { -#ifdef CONFIG_LTE_LAPI_KEEP_COMPATIBILITY - &result, &errcause, imsi -#else - &result, &errcause, imsi, &len -#endif - }; - - if (imsi == NULL) - { - return -EINVAL; - } - - ret = lapi_req(LTE_CMDID_GETIMSI, - NULL, 0, - (FAR void *)outarg, nitems(outarg), - NULL); - if (ret == 0) - { - ret = result; - } - - return ret; -} - -#ifdef CONFIG_LTE_LAPI_KEEP_COMPATIBILITY -int lte_get_imei_sync(FAR char *imei) -#else -int lte_get_imei_sync(FAR char *imei, size_t len) -#endif -{ - int ret; - int result; - FAR void *outarg[] = - { -#ifdef CONFIG_LTE_LAPI_KEEP_COMPATIBILITY - &result, imei -#else - &result, imei, &len -#endif - }; - - if (imei == NULL) - { - return -EINVAL; - } - - ret = lapi_req(LTE_CMDID_GETIMEI, - NULL, 0, - (FAR void *)outarg, nitems(outarg), - NULL); - if (ret == 0) - { - ret = result; - } - - return ret; -} - -#ifdef CONFIG_LTE_LAPI_KEEP_COMPATIBILITY -int lte_get_phoneno_sync(FAR char *phoneno) -#else -int lte_get_phoneno_sync(FAR char *phoneno, size_t len) -#endif -{ - int ret; - int result; - uint8_t errcause; - FAR void *outarg[] = - { -#ifdef CONFIG_LTE_LAPI_KEEP_COMPATIBILITY - &result, &errcause, phoneno -#else - &result, &errcause, phoneno, &len -#endif - }; - - if (phoneno == NULL) - { - return -EINVAL; - } - - ret = lapi_req(LTE_CMDID_GETPHONE, - NULL, 0, - (FAR void *)outarg, nitems(outarg), - NULL); - if (ret == 0) - { - ret = result; - } - - return ret; -} - -int lte_set_report_simstat(simstat_report_cb_t callback) -{ - int ret; - int result; - int32_t id = LTE_CMDID_REPSIMSTAT; - FAR void *inarg[] = - { - callback, &id - }; - - FAR void *outarg[] = - { - &result - }; - - ret = lapi_req(LTE_CMDID_REPSIMSTAT, - (FAR void *)inarg, nitems(inarg), - (FAR void *)outarg, nitems(outarg), - callback); - if (ret == 0) - { - ret = result; - } - - return ret; -} - -/* Asynchronous APIs */ - -#ifdef CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API - -int lte_get_siminfo(uint32_t option, get_siminfo_cb_t callback) -{ - FAR void *inarg[] = - { - &option - }; - - if (callback == NULL) - { - return -EINVAL; - } - - if (lte_get_siminfo_inparam_check(option)) - { - return -EINVAL; - } - - return lapi_req(LTE_CMDID_GETSIMINFO | LTE_CMDOPT_ASYNC_BIT, - (FAR void *)inarg, nitems(inarg), - NULL, 0, callback); -} - -int lte_get_imscap(get_imscap_cb_t callback) -{ - if (callback == NULL) - { - return -EINVAL; - } - - return lapi_req(LTE_CMDID_IMSCAP | LTE_CMDOPT_ASYNC_BIT, - NULL, 0, NULL, 0, callback); -} - -int lte_get_imsi(get_imsi_cb_t callback) -{ - if (callback == NULL) - { - return -EINVAL; - } - - return lapi_req(LTE_CMDID_GETIMSI | LTE_CMDOPT_ASYNC_BIT, - NULL, 0, NULL, 0, callback); -} - -int lte_get_imei(get_imei_cb_t callback) -{ - if (callback == NULL) - { - return -EINVAL; - } - - return lapi_req(LTE_CMDID_GETIMEI | LTE_CMDOPT_ASYNC_BIT, - NULL, 0, NULL, 0, callback); -} - -int lte_get_phoneno(get_phoneno_cb_t callback) -{ - if (callback == NULL) - { - return -EINVAL; - } - - return lapi_req(LTE_CMDID_GETPHONE | LTE_CMDOPT_ASYNC_BIT, - NULL, 0, NULL, 0, callback); -} -#endif /* CONFIG_LTE_LAPI_ENABLE_DEPRECATED_API */ - diff --git a/math/CMakeLists.txt b/math/CMakeLists.txt deleted file mode 100644 index 1b9defeae..000000000 --- a/math/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -# ############################################################################## -# apps/math/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -nuttx_add_subdirectory() - -nuttx_generate_kconfig(MENUDESC "Math Library Support") diff --git a/math/Make.defs b/math/Make.defs index 33017a5a2..36941e940 100644 --- a/math/Make.defs +++ b/math/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/math/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/math/Makefile b/math/Makefile index e90cc1048..de43fcc19 100644 --- a/math/Makefile +++ b/math/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/math/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/math/gemmlowp/.gitignore b/math/gemmlowp/.gitignore deleted file mode 100644 index 72be90b84..000000000 --- a/math/gemmlowp/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/gemmlowp diff --git a/math/gemmlowp/CMakeLists.txt b/math/gemmlowp/CMakeLists.txt deleted file mode 100644 index b13b12794..000000000 --- a/math/gemmlowp/CMakeLists.txt +++ /dev/null @@ -1,48 +0,0 @@ -# ############################################################################## -# apps/math/gemmlowp/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_MATH_GEMMLOWP) - - # ############################################################################ - # Config and Fetch gemmlowp lib - # ############################################################################ - - set(GEMMLOWP_DIR ${CMAKE_CURRENT_LIST_DIR}/gemmlowp) - - if(NOT EXISTS ${GEMMLOWP_DIR}) - set(GEMMLOWP_URL - https://github.com/google/gemmlowp/archive/719139ce755a0f31cbf1c37f7f98adcc7fc9f425.zip - ) - FetchContent_Declare( - gemmlowp_fetch - URL ${GEMMLOWP_URL} SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/gemmlowp - BINARY_DIR ${CMAKE_BINARY_DIR}/apps/math/gemmlowp/gemmlowp - DOWNLOAD_NO_PROGRESS true - TIMEOUT 30) - - FetchContent_GetProperties(gemmlowp_fetch) - - if(NOT gemmlowp_fetch_POPULATED) - FetchContent_Populate(gemmlowp_fetch) - endif() - endif() -endif() diff --git a/math/gemmlowp/Kconfig b/math/gemmlowp/Kconfig deleted file mode 100644 index b4b4a5a4a..000000000 --- a/math/gemmlowp/Kconfig +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/math/gemmlowp/Kconfig -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -config MATH_GEMMLOWP - bool "Gemmlowp" - default n - ---help--- - Enable gemmlowp. diff --git a/math/gemmlowp/Make.defs b/math/gemmlowp/Make.defs deleted file mode 100644 index a89b55ebb..000000000 --- a/math/gemmlowp/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/math/gemmlowp/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_MATH_GEMMLOWP),) -CONFIGURED_APPS += $(APPDIR)/math/gemmlowp -endif diff --git a/math/gemmlowp/Makefile b/math/gemmlowp/Makefile deleted file mode 100644 index cceda46d5..000000000 --- a/math/gemmlowp/Makefile +++ /dev/null @@ -1,43 +0,0 @@ -############################################################################ -# apps/math/gemmlowp/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -MODULE = $(CONFIG_MATH_GEMMLOWP) - -GEMMLOWP_VER = 719139ce755a0f31cbf1c37f7f98adcc7fc9f425 - -gemmlowp.zip: - $(Q) curl -L https://github.com/google/gemmlowp/archive/$(GEMMLOWP_VER).zip -o gemmlowp.zip - $(Q) unzip -o gemmlowp.zip - $(Q) mv gemmlowp-$(GEMMLOWP_VER) gemmlowp - -# Download and unpack tarball if no git repo found -ifeq ($(wildcard gemmlowp/.git),) -context:: gemmlowp.zip - -distclean:: - $(call DELDIR, gemmlowp) - $(call DELFILE, gemmlowp.zip) -endif - -include $(APPDIR)/Application.mk diff --git a/math/kissfft/.gitignore b/math/kissfft/.gitignore deleted file mode 100644 index 2f47d6a3a..000000000 --- a/math/kissfft/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/kissfft diff --git a/math/kissfft/CMakeLists.txt b/math/kissfft/CMakeLists.txt deleted file mode 100644 index 7273f0e09..000000000 --- a/math/kissfft/CMakeLists.txt +++ /dev/null @@ -1,70 +0,0 @@ -# ############################################################################## -# apps/math/kissfft/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_MATH_KISSFFT) - - # ############################################################################ - # Config and Fetch kissfft lib - # ############################################################################ - - set(KISSFFT_DIR ${CMAKE_CURRENT_LIST_DIR}/kissfft) - - if(NOT EXISTS ${KISSFFT_DIR}) - set(KISSFFT_URL - https://github.com/mborgerding/kissfft/archive/refs/tags/v130.zip) - FetchContent_Declare( - kissfft_fetch - URL ${KISSFFT_URL} SOURCE_DIR ${KISSFFT_DIR} BINARY_DIR - ${CMAKE_BINARY_DIR}/apps/math/kissfft/kissfft - PATCH_COMMAND patch -d ${KISSFFT_DIR} -p1 < - ${CMAKE_CURRENT_LIST_DIR}/kissfft.patch - DOWNLOAD_NO_PROGRESS true - TIMEOUT 30) - - FetchContent_GetProperties(kissfft_fetch) - - if(NOT kissfft_fetch_POPULATED) - FetchContent_Populate(kissfft_fetch) - endif() - endif() - - # ############################################################################ - # Sources - # ############################################################################ - - set(CSRCS ${KISSFFT_DIR}/kiss_fft.c ${KISSFFT_DIR}/tools/kiss_fftr.c) - - # ############################################################################ - # Include Directory - # ############################################################################ - - set(INCDIR ${CMAKE_CURRENT_LIST_DIR}/kissfft) - - # ############################################################################ - # Library Configuration - # ############################################################################ - - nuttx_add_library(kissfft STATIC) - target_sources(kissfft PRIVATE ${CSRCS}) - target_include_directories(kissfft PUBLIC ${INCDIR}) - -endif() diff --git a/math/kissfft/Kconfig b/math/kissfft/Kconfig deleted file mode 100644 index 686c116e6..000000000 --- a/math/kissfft/Kconfig +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/math/kissfft/Kconfig -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -config MATH_KISSFFT - bool "kissfft" - default n - ---help--- - Enable kissfft. diff --git a/math/kissfft/Make.defs b/math/kissfft/Make.defs deleted file mode 100644 index 847608309..000000000 --- a/math/kissfft/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/math/kissfft/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_MATH_KISSFFT),) -CONFIGURED_APPS += $(APPDIR)/math/kissfft -endif diff --git a/math/kissfft/Makefile b/math/kissfft/Makefile deleted file mode 100644 index ff4fe9ee3..000000000 --- a/math/kissfft/Makefile +++ /dev/null @@ -1,47 +0,0 @@ -############################################################################ -# apps/math/kissfft/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -CSRCS += kissfft/tools/kiss_fftr.c -CSRCS += kissfft/kiss_fft.c - -CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/math/kissfft/kissfft - -KISSFFT_VER = 130 -KISSFFT_UNPACK = kissfft - -kissfft.zip: - $(Q) curl -L https://github.com/mborgerding/kissfft/archive/refs/tags/v$(KISSFFT_VER).zip -o kissfft.zip - $(Q) unzip -o kissfft.zip - $(Q) mv kissfft-$(KISSFFT_VER) kissfft - $(Q) patch -d $(KISSFFT_UNPACK) -p1 < kissfft.patch - -# Download and unpack tarball if no git repo found -ifeq ($(wildcard kissfft/.git),) -context:: kissfft.zip -distclean:: - $(call DELDIR, kissfft) - $(call DELFILE, kissfft.zip) -endif - -include $(APPDIR)/Application.mk diff --git a/math/kissfft/kissfft.patch b/math/kissfft/kissfft.patch deleted file mode 100644 index 404d91f9e..000000000 --- a/math/kissfft/kissfft.patch +++ /dev/null @@ -1,116 +0,0 @@ -diff --git a/_kiss_fft_guts.h b/_kiss_fft_guts.h -index ba66144..1a0f4c2 100644 ---- a/_kiss_fft_guts.h -+++ b/_kiss_fft_guts.h -@@ -1,3 +1,6 @@ -+#ifndef _KISS_FFT_GUTS_H -+#define _KISS_FFT_GUTS_H -+ - /* - Copyright (c) 2003-2010, Mark Borgerding - -@@ -135,7 +138,7 @@ struct kiss_fft_state{ - #else - # define KISS_FFT_COS(phase) (kiss_fft_scalar) cos(phase) - # define KISS_FFT_SIN(phase) (kiss_fft_scalar) sin(phase) --# define HALF_OF(x) ((x)*.5) -+# define HALF_OF(x) ((x)*(kiss_fft_scalar).5) - #endif - - #define kf_cexp(x,phase) \ -@@ -162,3 +165,4 @@ struct kiss_fft_state{ - #define KISS_FFT_TMP_ALLOC(nbytes) KISS_FFT_MALLOC(nbytes) - #define KISS_FFT_TMP_FREE(ptr) KISS_FFT_FREE(ptr) - #endif -+#endif // _KISS_FFT_GUTS_H -diff --git a/kiss_fft.c b/kiss_fft.c -index 465d6c9..9133a01 100644 ---- a/kiss_fft.c -+++ b/kiss_fft.c -@@ -375,7 +375,7 @@ void kiss_fft_stride(kiss_fft_cfg st,const kiss_fft_cpx *fin,kiss_fft_cpx *fout, - //It just performs an out-of-place FFT into a temp buffer - kiss_fft_cpx * tmpbuf = (kiss_fft_cpx*)KISS_FFT_TMP_ALLOC( sizeof(kiss_fft_cpx)*st->nfft); - kf_work(tmpbuf,fin,1,in_stride, st->factors,st); -- memcpy(fout,tmpbuf,sizeof(kiss_fft_cpx)*st->nfft); -+ /* memcpy(fout,tmpbuf,sizeof(kiss_fft_cpx)*st->nfft); */ - KISS_FFT_TMP_FREE(tmpbuf); - }else{ - kf_work( fout, fin, 1,in_stride, st->factors,st ); -diff --git a/kiss_fft.h b/kiss_fft.h -index 64c50f4..24e4d0c 100644 ---- a/kiss_fft.h -+++ b/kiss_fft.h -@@ -7,7 +7,7 @@ - #include - - #ifdef __cplusplus --extern "C" { -+extern "C++" { - #endif - - /* -@@ -29,13 +29,13 @@ extern "C" { - #define KISS_FFT_MALLOC(nbytes) _mm_malloc(nbytes,16) - #define KISS_FFT_FREE _mm_free - #else --#define KISS_FFT_MALLOC malloc --#define KISS_FFT_FREE free -+#define KISS_FFT_MALLOC(X) (void*)(0x0) /* Patched. */ -+#define KISS_FFT_FREE(X) /* Patched. */ - #endif - - - #ifdef FIXED_POINT --#include -+#include /* Patched. */ - # if (FIXED_POINT == 32) - # define kiss_fft_scalar int32_t - # else -diff --git a/tools/kiss_fftr.c b/tools/kiss_fftr.c -index b8e238b..0d22a04 100644 ---- a/tools/kiss_fftr.c -+++ b/tools/kiss_fftr.c -@@ -31,7 +31,7 @@ kiss_fftr_cfg kiss_fftr_alloc(int nfft,int inverse_fft,void * mem,size_t * lenme - size_t subsize, memneeded; - - if (nfft & 1) { -- fprintf(stderr,"Real FFT optimization must be even.\n"); -+ /* fprintf(stderr,"Real FFT optimization must be even.\n"); */ - return NULL; - } - nfft >>= 1; -@@ -71,8 +71,8 @@ void kiss_fftr(kiss_fftr_cfg st,const kiss_fft_scalar *timedata,kiss_fft_cpx *fr - kiss_fft_cpx fpnk,fpk,f1k,f2k,tw,tdc; - - if ( st->substate->inverse) { -- fprintf(stderr,"kiss fft usage error: improper alloc\n"); -- exit(1); -+ /* fprintf(stderr,"kiss fft usage error: improper alloc\n"); */ -+ return; /* exit(1); */ - } - - ncfft = st->substate->nfft; -@@ -126,8 +126,8 @@ void kiss_fftri(kiss_fftr_cfg st,const kiss_fft_cpx *freqdata,kiss_fft_scalar *t - int k, ncfft; - - if (st->substate->inverse == 0) { -- fprintf (stderr, "kiss fft usage error: improper alloc\n"); -- exit (1); -+ /* fprintf (stderr, "kiss fft usage error: improper alloc\n"); */ -+ return; /* exit (1); */ - } - - ncfft = st->substate->nfft; -diff --git a/tools/kiss_fftr.h b/tools/kiss_fftr.h -index 72e5a57..b888a28 100644 ---- a/tools/kiss_fftr.h -+++ b/tools/kiss_fftr.h -@@ -3,7 +3,7 @@ - - #include "kiss_fft.h" - #ifdef __cplusplus --extern "C" { -+extern "C++" { - #endif - - diff --git a/math/libtommath/CMakeLists.txt b/math/libtommath/CMakeLists.txt deleted file mode 100644 index 211c755e1..000000000 --- a/math/libtommath/CMakeLists.txt +++ /dev/null @@ -1,147 +0,0 @@ -# ############################################################################## -# apps/math/libtommath/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_MATH_LIBTOMMATH) - - # ############################################################################ - # Config and Fetch Tommath lib - # ############################################################################ - - set(LIBTOMMATH_DIR ${CMAKE_CURRENT_LIST_DIR}/libtommath) - - if(NOT EXISTS ${LIBTOMMATH_DIR}) - set(CONFIG_LIBTOMMATH_URL https://github.com/libtom/libtommath/archive) - FetchContent_Declare( - libtommath_fetch - URL ${CONFIG_LIBTOMMATH_URL}/v${CONFIG_LIBTOMMATH_VERSION}.zip SOURCE_DIR - ${CMAKE_CURRENT_LIST_DIR}/libtommath BINARY_DIR - ${CMAKE_BINARY_DIR}/apps/math/libtommath/libtommath - DOWNLOAD_NO_PROGRESS true - TIMEOUT 30) - - FetchContent_GetProperties(libtommath_fetch) - if(NOT libtommath_fetch_POPULATED) - FetchContent_Populate(libtommath_fetch) - endif() - endif() - - # ############################################################################ - # Flags - # ############################################################################ - - set(CFLAGS -Wno-format) - - # ############################################################################ - # Sources - # ############################################################################ - - file(GLOB CSRCS ${LIBTOMMATH_DIR}/*.c) - - if(CONFIG_LIBTOMMATH_DEMOS) - list(APPEND CSRCS ${LIBTOMMATH_DIR}/demo/shared.c) - endif() - - # ############################################################################ - # Include Directory - # ############################################################################ - - set(INCDIR ${LIBTOMMATH_DIR}) - - # ############################################################################ - # Library Configuration - # ############################################################################ - - nuttx_add_library(libtommath STATIC) - target_compile_options(libtommath PRIVATE ${CFLAGS}) - target_sources(libtommath PRIVATE ${CSRCS}) - target_include_directories(libtommath PRIVATE ${INCDIR}) - - # ############################################################################ - # Applications Configuration - # ############################################################################ - - if(CONFIG_LIBTOMMATH_TEST) - nuttx_add_application( - NAME - ${CONFIG_LIBTOMMATH_TEST_PROGNAME} - STACKSIZE - ${CONFIG_LIBTOMMATH_TEST_STACKSIZE} - PRIORITY - ${CONFIG_LIBTOMMATH_TEST_PRIORITY} - SRCS - ${LIBTOMMATH_DIR}/demo/test.c - INCLUDE_DIRECTORIES - ${INCDIR} - DEPENDS - libtommath) - endif() - - if(CONFIG_LIBTOMMATH_MTEST_OPPONENT) - nuttx_add_application( - NAME - ${CONFIG_LIBTOMMATH_MTEST_OPPONENT_PROGNAME} - STACKSIZE - ${CONFIG_LIBTOMMATH_MTEST_OPPONENT_STACKSIZE} - PRIORITY - ${CONFIG_LIBTOMMATH_MTEST_OPPONENT_PRIORITY} - SRCS - ${LIBTOMMATH_DIR}/demo/mtest_opponent.c - INCLUDE_DIRECTORIES - ${INCDIR} - DEPENDS - libtommath) - endif() - - if(CONFIG_LIBTOMMATH_TIMING) - nuttx_add_application( - NAME - ${CONFIG_LIBTOMMATH_TIMING_PROGNAME} - STACKSIZE - ${CONFIG_LIBTOMMATH_TIMING_STACKSIZE} - PRIORITY - ${CONFIG_LIBTOMMATH_TIMING_PRIORITY} - SRCS - ${LIBTOMMATH_DIR}/demo/timing.c - INCLUDE_DIRECTORIES - ${INCDIR} - DEPENDS - libtommath) - - endif() - - if(CONFIG_LIBTOMMATH_MTEST) - nuttx_add_application( - NAME - ${CONFIG_LIBTOMMATH_MTEST_PROGNAME} - STACKSIZE - ${CONFIG_LIBTOMMATH_MTEST_STACKSIZE} - PRIORITY - ${CONFIG_LIBTOMMATH_MTEST_PRIORITY} - SRCS - ${LIBTOMMATH_DIR}/mtest/mtest.c - INCLUDE_DIRECTORIES - ${INCDIR} - DEPENDS - libtommath) - endif() - -endif() diff --git a/math/libtommath/Kconfig b/math/libtommath/Kconfig index 384707048..b1d44a754 100644 --- a/math/libtommath/Kconfig +++ b/math/libtommath/Kconfig @@ -25,101 +25,77 @@ menuconfig LIBTOMMATH_DEMOS if LIBTOMMATH_DEMOS config LIBTOMMATH_TEST - tristate "LibTomMath Test" - default n - ---help--- - Demo test application for LibTomMath + tristate "LibTomMath Test" + default n + ---help--- + Demo test application for LibTomMath if LIBTOMMATH_TEST config LIBTOMMATH_TEST_PROGNAME - string "Test program name" - default "tommath_test" - ---help--- - LibTomMath test application name + string "Test program name" + default "tommath_test" + ---help--- + LibTomMath test application name config LIBTOMMATH_TEST_PRIORITY - int "Test application priority" - default 100 + int "Test application priority" + default 100 config LIBTOMMATH_TEST_STACKSIZE - int "Test application stack size" - default DEFAULT_TASK_STACKSIZE + int "Test application stack size" + default DEFAULT_TASK_STACKSIZE endif # LIBTOMMATH_TEST -config LIBTOMMATH_MTEST_OPPONENT - tristate "LibTomMath MTest opponent" - default n - ---help--- - Demo mtest opponent application for LibTomMath +config LIBTOMMATH_OPPONENT_MTEST + tristate "LibTomMath MTest" + default n + ---help--- + Demo mtest application for LibTomMath -if LIBTOMMATH_MTEST_OPPONENT +if LIBTOMMATH_OPPONENT_MTEST config LIBTOMMATH_MTEST_OPPONENT_PROGNAME - string "MTest opponent program name" - default "tommath_mtest_opponent" - ---help--- - LibTomMath mtest opponent application name + string "MTest program name" + default "tommath_mtest" + ---help--- + LibTomMath mtest application name config LIBTOMMATH_MTEST_OPPONENT_PRIORITY - int "MTest opponent application priority" - default 100 + int "MTest application priority" + default 100 config LIBTOMMATH_MTEST_OPPONENT_STACKSIZE - int "MTest opponent application stack size" - default DEFAULT_TASK_STACKSIZE + int "MTest application stack size" + default DEFAULT_TASK_STACKSIZE -endif # LIBTOMMATH_MTEST_OPPONENT +endif # LIBTOMMATH_OPPONENT_MTEST config LIBTOMMATH_TIMING - tristate "LibTomMath Timing" - default n - ---help--- - Demo timing test application for LibTomMath + tristate "LibTomMath Timing" + default n + ---help--- + Demo timing test application for LibTomMath if LIBTOMMATH_TIMING config LIBTOMMATH_TIMING_PROGNAME - string "Timing program name" - default "tommath_timing" - ---help--- - LibTomMath test application name + string "Timing program name" + default "tommath_timing" + ---help--- + LibTomMath test application name config LIBTOMMATH_TIMING_PRIORITY - int "Timing application priority" - default 100 + int "Timing application priority" + default 100 config LIBTOMMATH_TIMING_STACKSIZE - int "Timing application stack size" - default DEFAULT_TASK_STACKSIZE + int "Timing application stack size" + default DEFAULT_TASK_STACKSIZE endif # LIBTOMMATH_TIMING endif # LIBTOMMATH_DEMOS -config LIBTOMMATH_MTEST - tristate "LibTomMath MPI Math Library Mtest" - default n - ---help--- - LibTomMath mtest applications for LibTomMath - -if LIBTOMMATH_MTEST - -config LIBTOMMATH_MTEST_PROGNAME - string "Mtest program name" - default "tommath_mtest" - ---help--- - LibTomMath test application name - -config LIBTOMMATH_MTEST_PRIORITY - int "Mtest application priority" - default 100 - -config LIBTOMMATH_MTEST_STACKSIZE - int "Mtest application stack size" - default DEFAULT_TASK_STACKSIZE - -endif # LIBTOMMATH_MTEST - endif # MATH_LIBTOMMATH diff --git a/math/libtommath/Make.defs b/math/libtommath/Make.defs index 61dcb1f65..1aa6e7b7a 100644 --- a/math/libtommath/Make.defs +++ b/math/libtommath/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/math/libtommath/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -20,11 +18,11 @@ # ############################################################################ -ifneq ($(CONFIG_MATH_LIBTOMMATH),) +ifeq ($(CONFIG_MATH_LIBTOMMATH),y) CONFIGURED_APPS += $(APPDIR)/math/libtommath # It allows `` import. -CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/math/libtommath/libtommath -CXXFLAGS += ${INCDIR_PREFIX}$(APPDIR)/math/libtommath/libtommath +CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(APPDIR)/math/libtommath/libtommath} +CXXFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(APPDIR)/math/libtommath/libtommath} endif diff --git a/math/libtommath/Makefile b/math/libtommath/Makefile index 0d9fe26e4..297543e06 100644 --- a/math/libtommath/Makefile +++ b/math/libtommath/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/math/libtommath/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -55,17 +53,14 @@ bn_s_mp_rand_jenkins.c bn_s_mp_rand_platform.c bn_s_mp_reverse.c bn_s_mp_sqr.c b bn_s_mp_sub.c bn_s_mp_toom_mul.c bn_s_mp_toom_sqr.c VPATH += $(LIBTOMMATH_UNPACKNAME) -DEPPATH += --dep-path $(LIBTOMMATH_UNPACKNAME) ifneq ($(CONFIG_LIBTOMMATH_DEMOS),) CSRCS += shared.c VPATH += $(LIBTOMMATH_UNPACKNAME)/demo -DEPPATH += --dep-path $(LIBTOMMATH_UNPACKNAME)/demo ifneq ($(CONFIG_LIBTOMMATH_TEST),) MAINSRC += test.c -MODULE += $(CONFIG_LIBTOMMATH_TEST) PROGNAME += $(CONFIG_LIBTOMMATH_TEST_PROGNAME) PRIORITY += $(CONFIG_LIBTOMMATH_TEST_PRIORITY) STACKSIZE += $(CONFIG_LIBTOMMATH_TEST_STACKSIZE) @@ -74,7 +69,6 @@ endif ifneq ($(CONFIG_LIBTOMMATH_MTEST_OPPONENT),) MAINSRC += mtest_opponent.c -MODULE += $(CONFIG_LIBTOMMATH_MTEST_OPPONENT) PROGNAME += $(CONFIG_LIBTOMMATH_MTEST_OPPONENT_PROGNAME) PRIORITY += $(CONFIG_LIBTOMMATH_MTEST_OPPONENT_PRIORITY) STACKSIZE += $(CONFIG_LIBTOMMATH_MTEST_OPPONENT_STACKSIZE) @@ -83,23 +77,11 @@ endif ifneq ($(CONFIG_LIBTOMMATH_TIMING),) MAINSRC += timing.c -MODULE += $(CONFIG_LIBTOMMATH_TIMING) PROGNAME += $(CONFIG_LIBTOMMATH_TIMING_PROGNAME) PRIORITY += $(CONFIG_LIBTOMMATH_TIMING_PRIORITY) STACKSIZE += $(CONFIG_LIBTOMMATH_TIMING_STACKSIZE) endif -ifneq ($(CONFIG_LIBTOMMATH_MTEST),) -MAINSRC += mtest.c -VPATH += $(LIBTOMMATH_UNPACKNAME)/mtest -DEPPATH += --dep-path $(LIBTOMMATH_UNPACKNAME)/mtest - -MODULE += $(CONFIG_LIBTOMMATH_MTEST) -PROGNAME += $(CONFIG_LIBTOMMATH_MTEST_PROGNAME) -PRIORITY += $(CONFIG_LIBTOMMATH_MTEST_PRIORITY) -STACKSIZE += $(CONFIG_LIBTOMMATH_MTEST_STACKSIZE) -endif - endif # Set up build configuration and environment @@ -121,13 +103,10 @@ $(LIBTOMMATH_UNPACKNAME): $(LIBTOMMATH_ZIP) $(Q) mv libtommath-$(LIBTOMMATH_VERSION) $(LIBTOMMATH_UNPACKNAME) $(Q) touch $(LIBTOMMATH_UNPACKNAME) -# Download and unpack tarball if no git repo found -ifeq ($(wildcard $(LIBTOMMATH_UNPACKNAME)/.git),) context:: $(LIBTOMMATH_UNPACKNAME) distclean:: $(call DELDIR, $(LIBTOMMATH_UNPACKNAME)) $(call DELFILE, $(LIBTOMMATH_ZIP)) -endif include $(APPDIR)/Application.mk diff --git a/math/ruy/.gitignore b/math/ruy/.gitignore deleted file mode 100644 index 8566c611d..000000000 --- a/math/ruy/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/ruy diff --git a/math/ruy/CMakeLists.txt b/math/ruy/CMakeLists.txt deleted file mode 100644 index 79ac2ac2b..000000000 --- a/math/ruy/CMakeLists.txt +++ /dev/null @@ -1,49 +0,0 @@ -# ############################################################################## -# apps/math/ruy/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_MATH_RUY) - - # ############################################################################ - # Config and Fetch ruy lib - # ############################################################################ - - set(RUY_DIR ${CMAKE_CURRENT_LIST_DIR}/ruy) - - if(NOT EXISTS ${RUY_DIR}) - set(RUY_URL - https://github.com/google/ruy/archive/d37128311b445e758136b8602d1bbd2a755e115d.zip - ) - FetchContent_Declare( - ruy_fetch - URL ${RUY_URL} SOURCE_DIR ${RUY_DIR} BINARY_DIR - ${CMAKE_BINARY_DIR}/apps/math/ruy/ruy - DOWNLOAD_NO_PROGRESS true - TIMEOUT 30) - - FetchContent_GetProperties(ruy_fetch) - - if(NOT ruy_fetch_POPULATED) - FetchContent_Populate(ruy_fetch) - endif() - endif() - -endif() diff --git a/math/ruy/Make.defs b/math/ruy/Make.defs deleted file mode 100644 index bd91a3663..000000000 --- a/math/ruy/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/math/ruy/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_MATH_RUY),) -CONFIGURED_APPS += $(APPDIR)/math/ruy -endif diff --git a/math/ruy/Makefile b/math/ruy/Makefile deleted file mode 100644 index 188b81fff..000000000 --- a/math/ruy/Makefile +++ /dev/null @@ -1,44 +0,0 @@ -############################################################################ -# apps/math/ruy/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -RUY_VER = d37128311b445e758136b8602d1bbd2a755e115d - -ruy.zip: - $(Q) curl -L https://github.com/google/ruy/archive/$(RUY_VER).zip -o ruy.zip - $(Q) unzip -o ruy.zip - $(Q) mv ruy-$(RUY_VER) ruy - -# Download and unpack tarball if no git repo found -ifeq ($(wildcard ruy/.git),) -context:: ruy.zip - -distclean:: - $(call DELDIR, ruy) - $(call DELFILE, ruy.zip) -endif - -CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/math/ruy/ruy -CXXFLAGS += ${INCDIR_PREFIX}$(APPDIR)/math/ruy/ruy - -include $(APPDIR)/Application.mk diff --git a/mlearning/CMakeLists.txt b/mlearning/CMakeLists.txt deleted file mode 100644 index 78ba1da4a..000000000 --- a/mlearning/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -# ############################################################################## -# apps/mlearning/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -nuttx_add_subdirectory() - -nuttx_generate_kconfig(MENUDESC "Machine Learning Support") diff --git a/mlearning/Make.defs b/mlearning/Make.defs index 6b5d35fe8..5ad683160 100644 --- a/mlearning/Make.defs +++ b/mlearning/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/mlearning/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/mlearning/Makefile b/mlearning/Makefile index 435024a11..bf7d539bb 100644 --- a/mlearning/Makefile +++ b/mlearning/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/mlearning/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/mlearning/cmsis-nn/.gitignore b/mlearning/cmsis-nn/.gitignore deleted file mode 100644 index 3a811c638..000000000 --- a/mlearning/cmsis-nn/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/cmsis-nn diff --git a/mlearning/cmsis-nn/CMakeLists.txt b/mlearning/cmsis-nn/CMakeLists.txt deleted file mode 100644 index e5997cb35..000000000 --- a/mlearning/cmsis-nn/CMakeLists.txt +++ /dev/null @@ -1,95 +0,0 @@ -# ############################################################################## -# apps/mlearning/cmsis-nn/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_MLEARNING_CMSIS_NN) - - # ############################################################################ - # Config and Fetch CMSIS-NN lib - # ############################################################################ - - set(CMSIS_NN_DIR ${CMAKE_CURRENT_LIST_DIR}/cmsis-nn) - - if(NOT EXISTS ${CMSIS_NN_DIR}) - set(CMSIS_NN_URL - https://github.com/ARM-software/CMSIS-NN/archive/72e1ebf623ab1660a3e14e4e36fdcddce46f1991.zip - ) - FetchContent_Declare( - cmsis_nn_fetch - URL ${CMSIS_NN_URL} SOURCE_DIR ${CMSIS_NN_DIR} BINARY_DIR - ${CMAKE_BINARY_DIR}/apps/mlearning/cmsis-nn/cmsis-nn - DOWNLOAD_NO_PROGRESS true - TIMEOUT 30) - - FetchContent_GetProperties(cmsis_nn_fetch) - - if(NOT cmsis_nn_fetch_POPULATED) - FetchContent_Populate(cmsis_nn_fetch) - endif() - endif() - - # ############################################################################ - # Flags - # ############################################################################ - - set(CFLAGS -Wno-undef -O3) - - # ############################################################################ - # Sources - # ############################################################################ - - file( - GLOB - CMSIS_NN_SRCS - ${CMSIS_NN_DIR}/Source/ActivationFunctions/*.c - ${CMSIS_NN_DIR}/Source/BasicMathFunctions/*.c - ${CMSIS_NN_DIR}/Source/PoolingFunctions/*.c - ${CMSIS_NN_DIR}/Source/ConvolutionFunctions/*.c - ${CMSIS_NN_DIR}/Source/SVDFunctions/*.c - ${CMSIS_NN_DIR}/Source/FullyConnectedFunctions/*.c - ${CMSIS_NN_DIR}/Source/NNSupportFunctions/*.c - ${CMSIS_NN_DIR}/Source/ConcatenationFunctions/*.c - ${CMSIS_NN_DIR}/Source/SoftmaxFunctions/*.c - ${CMSIS_NN_DIR}/Source/LSTMFunctions/*.c - ${CMSIS_NN_DIR}/Source/ReshapeFunctions/*.c) - - set(CMSIS_NN_INCDIR ${CMAKE_CURRENT_LIST_DIR}/cmsis-nn/Include) - - if(CONFIG_ARM_NEON) - list( - REMOVE_ITEM - CMSIS_NN_SRCS - ${CMSIS_NN_DIR}/Source/BasicMathFunctions/arm_elementwise_add_s8.c - ${CMSIS_NN_DIR}/Source/ConvolutionFunctions/arm_convolve_s8.c - ${CMSIS_NN_DIR}/Source/NNSupportFunctions/arm_nn_mat_mult_kernel_s8_s16.c - ${CMSIS_NN_DIR}/Source/NNSupportFunctions/arm_q7_to_q15_with_offset.c) - endif() - - # ############################################################################ - # Library Configuration - # ############################################################################ - - nuttx_add_library(cmsis_nn STATIC) - target_compile_options(cmsis_nn PRIVATE ${CFLAGS}) - target_sources(cmsis_nn PRIVATE ${CMSIS_NN_SRCS}) - target_include_directories(cmsis_nn PUBLIC ${CMSIS_NN_INCDIR}) - -endif() diff --git a/mlearning/cmsis-nn/Kconfig b/mlearning/cmsis-nn/Kconfig deleted file mode 100644 index 1500f7d07..000000000 --- a/mlearning/cmsis-nn/Kconfig +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/mlearning/cmsis-nn/Kconfig -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -config MLEARNING_CMSIS_NN - bool "CMSIS_NN Library" - default n - ---help--- - Enable CMSIS_NN. diff --git a/mlearning/cmsis-nn/Make.defs b/mlearning/cmsis-nn/Make.defs deleted file mode 100644 index 1f14dc090..000000000 --- a/mlearning/cmsis-nn/Make.defs +++ /dev/null @@ -1,27 +0,0 @@ -############################################################################ -# apps/mlearning/cmsis-nn/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_MLEARNING_CMSIS_NN),) -CONFIGURED_APPS += $(APPDIR)/mlearning/cmsis-nn -CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/mlearning/cmsis-nn/cmsis-nn/Include -CXXFLAGS += ${INCDIR_PREFIX}$(APPDIR)/mlearning/cmsis-nn/cmsis-nn/Include -endif diff --git a/mlearning/cmsis-nn/Makefile b/mlearning/cmsis-nn/Makefile deleted file mode 100644 index cd8117275..000000000 --- a/mlearning/cmsis-nn/Makefile +++ /dev/null @@ -1,62 +0,0 @@ -############################################################################ -# apps/mlearning/cmsis-nn/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -CMSIS_NN = cmsis-nn/Source - -CMSIS_NN_VER = 72e1ebf623ab1660a3e14e4e36fdcddce46f1991 - -cmsis-nn.zip: - $(Q) curl -L https://github.com/ARM-software/CMSIS-NN/archive/$(CMSIS_NN_VER).zip -o cmsis-nn.zip - $(Q) unzip -o cmsis-nn.zip - $(Q) mv CMSIS-NN-$(CMSIS_NN_VER) cmsis-nn - -ifeq ($(wildcard cmsis-nn/.git),) -context:: cmsis-nn.zip -distclean:: - $(call DELDIR, cmsis-nn) - $(call DELFILE, cmsis-nn.zip) -endif - -CFLAGS += -Wno-undef - -CSRCS += $(wildcard $(CMSIS_NN)/ActivationFunctions/*.c) -CSRCS += $(wildcard $(CMSIS_NN)/BasicMathFunctions/*.c) -CSRCS += $(wildcard $(CMSIS_NN)/PoolingFunctions/*.c) -CSRCS += $(wildcard $(CMSIS_NN)/ConvolutionFunctions/*.c) -CSRCS += $(wildcard $(CMSIS_NN)/SVDFunctions/*.c) -CSRCS += $(wildcard $(CMSIS_NN)/FullyConnectedFunctions/*.c) -CSRCS += $(wildcard $(CMSIS_NN)/NNSupportFunctions/*.c) -CSRCS += $(wildcard $(CMSIS_NN)/ConcatenationFunctions/*.c) -CSRCS += $(wildcard $(CMSIS_NN)/SoftmaxFunctions/*.c) -CSRCS += $(wildcard $(CMSIS_NN)/LSTMFunctions/*.c) -CSRCS += $(wildcard $(CMSIS_NN)/ReshapeFunctions/*.c) - -ifeq ($(CONFIG_ARM_NEON),y) -EXCLUDED_FILES := arm_elementwise_add_s8.c arm_convolve_s8.c arm_nn_mat_mult_kernel_s8_s16.c arm_q7_to_q15_with_offset.c -CSRCS := $(filter-out $(addprefix $(CMSIS_NN)/BasicMathFunctions/, $(EXCLUDED_FILES)), $(CSRCS)) -CSRCS := $(filter-out $(addprefix $(CMSIS_NN)/NNSupportFunctions/, $(EXCLUDED_FILES)), $(CSRCS)) -CSRCS := $(filter-out $(addprefix $(CMSIS_NN)/ConvolutionFunctions/, $(EXCLUDED_FILES)), $(CSRCS)) -endif - -include $(APPDIR)/Application.mk diff --git a/mlearning/cmsis/.gitignore b/mlearning/cmsis/.gitignore index 9f80d7b9d..20cb71e0e 100644 --- a/mlearning/cmsis/.gitignore +++ b/mlearning/cmsis/.gitignore @@ -1,2 +1 @@ /*.zip -/CMSIS_5 diff --git a/mlearning/cmsis/Kconfig b/mlearning/cmsis/Kconfig index 83ec44616..f33a8cbe1 100644 --- a/mlearning/cmsis/Kconfig +++ b/mlearning/cmsis/Kconfig @@ -16,7 +16,7 @@ if CMSIS config CMSIS_VER string "Default CMSIS version" - default "5.8.0" + default 5.8.0 config CMSIS_DSP bool "CMSIS DSP" @@ -41,11 +41,11 @@ config CMSIS_DSP_ARM_MATH_ROUNDING endif # CMSIS_DSP config CMSIS_NN - bool "CMSIS NN" - default y - depends on CMSIS_DSP - ---help--- - Enable CMSIS-NN: Efficient neural network kernels. + bool "CMSIS NN" + default y + depends on CMSIS_DSP + ---help--- + Enable CMSIS-NN: Efficient neural network kernels. endif # CMSIS diff --git a/mlearning/cmsis/Make.defs b/mlearning/cmsis/Make.defs index 845fa6017..1a726c60e 100644 --- a/mlearning/cmsis/Make.defs +++ b/mlearning/cmsis/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/mlearning/cmsis/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -25,6 +23,6 @@ CONFIGURED_APPS += $(APPDIR)/mlearning/cmsis include $(wildcard $(APPDIR)/mlearning/cmsis/*/Make.defs) -CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/mlearning/cmsis/CMSIS_5/CMSIS/Core/Include/ -CXXFLAGS += ${INCDIR_PREFIX}$(APPDIR)/mlearning/cmsis/CMSIS_5/CMSIS/Core/Include/ +CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(APPDIR)/mlearning/cmsis/CMSIS_5/CMSIS/Core/Include/} +CXXFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(APPDIR)/mlearning/cmsis/CMSIS_5/CMSIS/Core/Include/} endif diff --git a/mlearning/cmsis/Makefile b/mlearning/cmsis/Makefile index 0ddb4b330..dc0881ffe 100644 --- a/mlearning/cmsis/Makefile +++ b/mlearning/cmsis/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/mlearning/cmsis/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -28,13 +26,10 @@ cmsis.zip: $(Q) mv CMSIS_5-$(CONFIG_CMSIS_VER) CMSIS_5 $(Q) patch -p0 < cmsis-nn-support_nnabla.patch -# Download and unpack tarball if no git repo found -ifeq ($(wildcard CMSIS_5/.git),) context:: cmsis.zip distclean:: $(call DELDIR, CMSIS_5) $(call DELFILE, cmsis.zip) -endif include $(APPDIR)/Application.mk diff --git a/mlearning/cmsis/cmsis-nn-support_nnabla.patch b/mlearning/cmsis/cmsis-nn-support_nnabla.patch index 58e3a3d8d..4de8d6872 100644 --- a/mlearning/cmsis/cmsis-nn-support_nnabla.patch +++ b/mlearning/cmsis/cmsis-nn-support_nnabla.patch @@ -11,10 +11,10 @@ to add the following function prototypes: +++ CMSIS_5/CMSIS/NN/Include/arm_nnfunctions_nnabla.h @@ -0,0 +1,217 @@ +/* ++ * Copyright (C) 2010-2018 Arm Limited or its affiliates. All rights reserved. ++ * Copyright 2018 Sony Corporation + * + * SPDX-License-Identifier: Apache-2.0 -+ * SPDX-FileCopyrightText: 2010-2018 Arm Limited or its affiliates. -+ * SPDX-FileCopyrightText: 2018 Sony Corporation + * + * Licensed under the Apache License, Version 2.0 (the License); you may + * not use this file except in compliance with the License. @@ -237,10 +237,10 @@ Sony Corporation added this file to 5.4.0 for these reasons: +++ CMSIS_5/CMSIS/NN/Source/ConvolutionFunctions/arm_convolve_CHW_f32_basic_nonsquare.c @@ -0,0 +1,207 @@ +/* ++ * Copyright (C) 2010-2018 Arm Limited or its affiliates. All rights reserved. ++ * Copyright 2018 Sony Corporation + * + * SPDX-License-Identifier: Apache-2.0 -+ * SPDX-FileCopyrightText: 2010-2018 Arm Limited or its affiliates. -+ * SPDX-FileCopyrightText: 2018 Sony Corporation + * + * Licensed under the Apache License, Version 2.0 (the License); you may + * not use this file except in compliance with the License. @@ -451,10 +451,10 @@ Sony Corporation added this file to 5.4.0 to support the CHW tensor layout +++ CMSIS_5/CMSIS/NN/Source/ConvolutionFunctions/arm_convolve_CHW_q15_basic_nonsquare.c @@ -0,0 +1,231 @@ +/* ++ * Copyright (C) 2010-2018 Arm Limited or its affiliates. All rights reserved. ++ * Copyright 2018 Sony Corporation + * + * SPDX-License-Identifier: Apache-2.0 -+ * SPDX-FileCopyrightText: 2010-2018 Arm Limited or its affiliates. -+ * SPDX-FileCopyrightText: 2018 Sony Corporation + * + * Licensed under the Apache License, Version 2.0 (the License); you may + * not use this file except in compliance with the License. @@ -689,10 +689,10 @@ Sony Corporation added this file to 5.4.0 to support the CHW tensor layout +++ CMSIS_5/CMSIS/NN/Source/ConvolutionFunctions/arm_convolve_CHW_q7_basic_nonsquare.c @@ -0,0 +1,214 @@ +/* ++ * Copyright (C) 2010-2018 Arm Limited or its affiliates. All rights reserved. ++ * Copyright 2018 Sony Corporation + * + * SPDX-License-Identifier: Apache-2.0 -+ * SPDX-FileCopyrightText: 2010-2018 Arm Limited or its affiliates. -+ * SPDX-FileCopyrightText: 2018 Sony Corporation + * + * Licensed under the Apache License, Version 2.0 (the License); you may + * not use this file except in compliance with the License. @@ -910,10 +910,10 @@ Sony Corporation added this file to 5.4.0 to support the CHW tensor layout +++ CMSIS_5/CMSIS/NN/Source/ConvolutionFunctions/arm_nn_CHW_mat_mult_kernel_q7_q15.c @@ -0,0 +1,196 @@ +/* ++ * Copyright (C) 2010-2018 Arm Limited or its affiliates. All rights reserved. ++ * Copyright 2018 Sony Corporation + * + * SPDX-License-Identifier: Apache-2.0 -+ * SPDX-FileCopyrightText: 2010-2018 Arm Limited or its affiliates. -+ * SPDX-FileCopyrightText: 2018 Sony Corporation + * + * Licensed under the Apache License, Version 2.0 (the License); you may + * not use this file except in compliance with the License. diff --git a/mlearning/cmsis/libcmsisdsp/Make.defs b/mlearning/cmsis/libcmsisdsp/Make.defs index df93ea678..d181b64d6 100644 --- a/mlearning/cmsis/libcmsisdsp/Make.defs +++ b/mlearning/cmsis/libcmsisdsp/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/mlearning/cmsis/libcmsisdsp/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -23,6 +21,6 @@ ifneq ($(CONFIG_CMSIS_DSP),) CONFIGURED_APPS += $(APPDIR)/mlearning/cmsis/libcmsisdsp -CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/mlearning/cmsis/CMSIS_5/CMSIS/DSP/Include/ -CXXFLAGS += ${INCDIR_PREFIX}$(APPDIR)/mlearning/cmsis/CMSIS_5/CMSIS/DSP/Include/ +CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(APPDIR)/mlearning/cmsis/CMSIS_5/CMSIS/DSP/Include/} +CXXFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(APPDIR)/mlearning/cmsis/CMSIS_5/CMSIS/DSP/Include/} endif diff --git a/mlearning/cmsis/libcmsisdsp/Makefile b/mlearning/cmsis/libcmsisdsp/Makefile index 141b7cafa..55f9a43a9 100644 --- a/mlearning/cmsis/libcmsisdsp/Makefile +++ b/mlearning/cmsis/libcmsisdsp/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/mlearning/cmsis/libcmsisdsp/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -33,56 +31,530 @@ CFLAGS += -D__FPU_PRESENT=1U CXXFLAGS += -D__FPU_PRESENT=1U endif -CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/mlearning/cmsis/CMSIS_5/CMSIS/DSP/PrivateInclude/ -CXXFLAGS += ${INCDIR_PREFIX}$(APPDIR)/mlearning/cmsis/CMSIS_5/CMSIS/DSP/PrivateInclude/ +CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(APPDIR)/mlearning/cmsis/CMSIS_5/CMSIS/DSP/PrivateInclude/} +CXXFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(APPDIR)/mlearning/cmsis/CMSIS_5/CMSIS/DSP/PrivateInclude/} CMSIS5_DSP := ../CMSIS_5/CMSIS/DSP/Source -CSRCS += SVMFunctions.c -CSRCS += SVMFunctionsF16.c -CSRCS += InterpolationFunctions.c -CSRCS += InterpolationFunctionsF16.c -CSRCS += FastMathFunctions.c -CSRCS += FastMathFunctionsF16.c -CSRCS += FilteringFunctions.c -CSRCS += FilteringFunctionsF16.c -CSRCS += BasicMathFunctions.c -CSRCS += BasicMathFunctionsF16.c -CSRCS += ControllerFunctions.c -CSRCS += SupportFunctions.c -CSRCS += SupportFunctionsF16.c -CSRCS += CommonTables.c -CSRCS += CommonTablesF16.c -CSRCS += DistanceFunctions.c -CSRCS += DistanceFunctionsF16.c -CSRCS += StatisticsFunctions.c -CSRCS += StatisticsFunctionsF16.c -CSRCS += MatrixFunctions.c -CSRCS += MatrixFunctionsF16.c -CSRCS += QuaternionMathFunctions.c -CSRCS += TransformFunctions.c -CSRCS += TransformFunctionsF16.c -CSRCS += BayesFunctions.c -CSRCS += BayesFunctionsF16.c -CSRCS += ComplexMathFunctions.c -CSRCS += ComplexMathFunctionsF16.c +CSRCS += $(CMSIS5_DSP)/SVMFunctions/SVMFunctions.c +CSRCS += $(CMSIS5_DSP)/SVMFunctions/arm_svm_rbf_init_f16.c +CSRCS += $(CMSIS5_DSP)/SVMFunctions/arm_svm_polynomial_predict_f16.c +CSRCS += $(CMSIS5_DSP)/SVMFunctions/arm_svm_linear_init_f32.c +CSRCS += $(CMSIS5_DSP)/SVMFunctions/arm_svm_linear_init_f16.c +CSRCS += $(CMSIS5_DSP)/SVMFunctions/arm_svm_polynomial_init_f32.c +CSRCS += $(CMSIS5_DSP)/SVMFunctions/arm_svm_sigmoid_init_f16.c +CSRCS += $(CMSIS5_DSP)/SVMFunctions/arm_svm_sigmoid_predict_f16.c +CSRCS += $(CMSIS5_DSP)/SVMFunctions/arm_svm_rbf_predict_f32.c +CSRCS += $(CMSIS5_DSP)/SVMFunctions/arm_svm_linear_predict_f16.c +CSRCS += $(CMSIS5_DSP)/SVMFunctions/arm_svm_rbf_predict_f16.c +CSRCS += $(CMSIS5_DSP)/SVMFunctions/SVMFunctionsF16.c +CSRCS += $(CMSIS5_DSP)/SVMFunctions/arm_svm_polynomial_predict_f32.c +CSRCS += $(CMSIS5_DSP)/SVMFunctions/arm_svm_sigmoid_predict_f32.c +CSRCS += $(CMSIS5_DSP)/SVMFunctions/arm_svm_polynomial_init_f16.c +CSRCS += $(CMSIS5_DSP)/SVMFunctions/arm_svm_rbf_init_f32.c +CSRCS += $(CMSIS5_DSP)/SVMFunctions/arm_svm_linear_predict_f32.c +CSRCS += $(CMSIS5_DSP)/SVMFunctions/arm_svm_sigmoid_init_f32.c +CSRCS += $(CMSIS5_DSP)/InterpolationFunctions/arm_spline_interp_f32.c +CSRCS += $(CMSIS5_DSP)/InterpolationFunctions/arm_spline_interp_init_f32.c +CSRCS += $(CMSIS5_DSP)/InterpolationFunctions/arm_bilinear_interp_q31.c +CSRCS += $(CMSIS5_DSP)/InterpolationFunctions/arm_bilinear_interp_q7.c +CSRCS += $(CMSIS5_DSP)/InterpolationFunctions/arm_linear_interp_f32.c +CSRCS += $(CMSIS5_DSP)/InterpolationFunctions/arm_bilinear_interp_q15.c +CSRCS += $(CMSIS5_DSP)/InterpolationFunctions/InterpolationFunctions.c +CSRCS += $(CMSIS5_DSP)/InterpolationFunctions/InterpolationFunctionsF16.c +CSRCS += $(CMSIS5_DSP)/InterpolationFunctions/arm_linear_interp_q7.c +CSRCS += $(CMSIS5_DSP)/InterpolationFunctions/arm_bilinear_interp_f32.c +CSRCS += $(CMSIS5_DSP)/InterpolationFunctions/arm_linear_interp_q31.c +CSRCS += $(CMSIS5_DSP)/InterpolationFunctions/arm_linear_interp_q15.c +CSRCS += $(CMSIS5_DSP)/InterpolationFunctions/arm_bilinear_interp_f16.c +CSRCS += $(CMSIS5_DSP)/InterpolationFunctions/arm_linear_interp_f16.c +CSRCS += $(CMSIS5_DSP)/FastMathFunctions/FastMathFunctions.c +CSRCS += $(CMSIS5_DSP)/FastMathFunctions/arm_sqrt_q15.c +CSRCS += $(CMSIS5_DSP)/FastMathFunctions/arm_sin_q31.c +CSRCS += $(CMSIS5_DSP)/FastMathFunctions/arm_sin_f32.c +CSRCS += $(CMSIS5_DSP)/FastMathFunctions/arm_vlog_f32.c +CSRCS += $(CMSIS5_DSP)/FastMathFunctions/arm_sqrt_q31.c +CSRCS += $(CMSIS5_DSP)/FastMathFunctions/arm_cos_q15.c +CSRCS += $(CMSIS5_DSP)/FastMathFunctions/arm_sin_q15.c +CSRCS += $(CMSIS5_DSP)/FastMathFunctions/arm_vinverse_f16.c +CSRCS += $(CMSIS5_DSP)/FastMathFunctions/arm_vexp_f16.c +CSRCS += $(CMSIS5_DSP)/FastMathFunctions/arm_cos_q31.c +CSRCS += $(CMSIS5_DSP)/FastMathFunctions/arm_cos_f32.c +CSRCS += $(CMSIS5_DSP)/FastMathFunctions/arm_divide_q15.c +CSRCS += $(CMSIS5_DSP)/FastMathFunctions/arm_vlog_f16.c +CSRCS += $(CMSIS5_DSP)/FastMathFunctions/FastMathFunctionsF16.c +CSRCS += $(CMSIS5_DSP)/FastMathFunctions/arm_vexp_f32.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_conv_q15.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_biquad_cascade_df1_q15.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_lms_f32.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_conv_partial_opt_q7.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_lms_init_q31.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_conv_f32.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_biquad_cascade_df2T_init_f16.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_biquad_cascade_stereo_df2T_init_f32.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_iir_lattice_init_q31.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_fir_sparse_q31.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_fir_fast_q15.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_conv_q31.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_fir_q15.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_fir_q7.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_iir_lattice_q31.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_biquad_cascade_df1_init_f32.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_biquad_cascade_df1_q31.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_conv_partial_q7.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_conv_partial_opt_q15.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_fir_sparse_init_q31.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_iir_lattice_init_f32.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_fir_interpolate_f32.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_fir_lattice_f32.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_fir_decimate_init_f32.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_lms_q31.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_conv_opt_q15.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_biquad_cascade_df1_init_q15.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_biquad_cascade_df1_fast_q15.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_fir_fast_q31.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_fir_interpolate_q15.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_fir_f32.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_correlate_fast_q15.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_conv_partial_fast_q15.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_fir_interpolate_init_f32.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_fir_f16.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_biquad_cascade_df1_fast_q31.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_iir_lattice_init_q15.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_lms_norm_q31.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_levinson_durbin_q31.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_biquad_cascade_df2T_f64.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_fir_lattice_init_q15.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_correlate_f32.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_fir_decimate_q15.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_biquad_cascade_stereo_df2T_init_f16.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_conv_q7.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_lms_q15.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_fir_decimate_init_q31.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_conv_partial_fast_opt_q15.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_fir_init_q31.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_lms_norm_init_q31.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_biquad_cascade_df1_f16.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_conv_partial_q15.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_conv_partial_fast_q31.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_lms_norm_q15.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/FilteringFunctions.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_fir_interpolate_init_q15.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_fir_decimate_fast_q15.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_correlate_opt_q15.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_fir_lattice_init_q31.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_correlate_f16.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_biquad_cascade_df1_32x64_q31.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_biquad_cascade_df1_init_q31.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_correlate_q7.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_lms_init_f32.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_fir_init_f16.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_biquad_cascade_df1_f32.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_levinson_durbin_f32.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_fir_decimate_q31.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_correlate_opt_q7.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_iir_lattice_q15.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_biquad_cascade_df2T_f32.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_fir_sparse_init_q15.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_fir_sparse_q15.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_correlate_fast_q31.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_fir_lattice_q31.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_conv_partial_q31.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_biquad_cascade_df1_init_f16.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_fir_sparse_q7.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_levinson_durbin_f16.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_correlate_q15.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_fir_init_q7.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_biquad_cascade_stereo_df2T_f16.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_fir_sparse_init_q7.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_biquad_cascade_stereo_df2T_f32.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_lms_norm_f32.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_fir_decimate_fast_q31.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_lms_norm_init_f32.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_biquad_cascade_df2T_init_f64.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_conv_fast_opt_q15.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_correlate_q31.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_fir_lattice_q15.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_iir_lattice_f32.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_conv_fast_q31.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_biquad_cascade_df2T_f16.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_fir_interpolate_init_q31.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_fir_lattice_init_f32.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_fir_q31.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_fir_init_q15.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_fir_decimate_f32.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_conv_opt_q7.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_fir_decimate_init_q15.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_fir_sparse_init_f32.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_fir_init_f32.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/FilteringFunctionsF16.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_fir_interpolate_q31.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_biquad_cascade_df2T_init_f32.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_lms_init_q15.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_correlate_fast_opt_q15.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_biquad_cascade_df1_32x64_init_q31.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_fir_sparse_f32.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_conv_fast_q15.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_lms_norm_init_q15.c +CSRCS += $(CMSIS5_DSP)/FilteringFunctions/arm_conv_partial_f32.c +CSRCS += $(CMSIS5_DSP)/BasicMathFunctions/arm_scale_f16.c +CSRCS += $(CMSIS5_DSP)/BasicMathFunctions/arm_abs_f32.c +CSRCS += $(CMSIS5_DSP)/BasicMathFunctions/arm_negate_f16.c +CSRCS += $(CMSIS5_DSP)/BasicMathFunctions/arm_negate_q31.c +CSRCS += $(CMSIS5_DSP)/BasicMathFunctions/arm_sub_q7.c +CSRCS += $(CMSIS5_DSP)/BasicMathFunctions/arm_offset_f32.c +CSRCS += $(CMSIS5_DSP)/BasicMathFunctions/arm_xor_u8.c +CSRCS += $(CMSIS5_DSP)/BasicMathFunctions/arm_sub_f32.c +CSRCS += $(CMSIS5_DSP)/BasicMathFunctions/arm_scale_q31.c +CSRCS += $(CMSIS5_DSP)/BasicMathFunctions/arm_clip_f16.c +CSRCS += $(CMSIS5_DSP)/BasicMathFunctions/arm_scale_q15.c +CSRCS += $(CMSIS5_DSP)/BasicMathFunctions/arm_clip_q7.c +CSRCS += $(CMSIS5_DSP)/BasicMathFunctions/arm_add_q15.c +CSRCS += $(CMSIS5_DSP)/BasicMathFunctions/arm_scale_q7.c +CSRCS += $(CMSIS5_DSP)/BasicMathFunctions/arm_mult_q7.c +CSRCS += $(CMSIS5_DSP)/BasicMathFunctions/arm_sub_f16.c +CSRCS += $(CMSIS5_DSP)/BasicMathFunctions/arm_xor_u16.c +CSRCS += $(CMSIS5_DSP)/BasicMathFunctions/arm_negate_q7.c +CSRCS += $(CMSIS5_DSP)/BasicMathFunctions/arm_offset_q15.c +CSRCS += $(CMSIS5_DSP)/BasicMathFunctions/arm_sub_q15.c +CSRCS += $(CMSIS5_DSP)/BasicMathFunctions/arm_not_u8.c +CSRCS += $(CMSIS5_DSP)/BasicMathFunctions/arm_dot_prod_f16.c +CSRCS += $(CMSIS5_DSP)/BasicMathFunctions/arm_shift_q15.c +CSRCS += $(CMSIS5_DSP)/BasicMathFunctions/arm_not_u32.c +CSRCS += $(CMSIS5_DSP)/BasicMathFunctions/BasicMathFunctions.c +CSRCS += $(CMSIS5_DSP)/BasicMathFunctions/arm_shift_q31.c +CSRCS += $(CMSIS5_DSP)/BasicMathFunctions/arm_shift_q7.c +CSRCS += $(CMSIS5_DSP)/BasicMathFunctions/arm_add_q7.c +CSRCS += $(CMSIS5_DSP)/BasicMathFunctions/arm_and_u16.c +CSRCS += $(CMSIS5_DSP)/BasicMathFunctions/arm_offset_f16.c +CSRCS += $(CMSIS5_DSP)/BasicMathFunctions/arm_mult_f32.c +CSRCS += $(CMSIS5_DSP)/BasicMathFunctions/arm_mult_q31.c +CSRCS += $(CMSIS5_DSP)/BasicMathFunctions/arm_negate_f32.c +CSRCS += $(CMSIS5_DSP)/BasicMathFunctions/arm_add_f16.c +CSRCS += $(CMSIS5_DSP)/BasicMathFunctions/arm_and_u32.c +CSRCS += $(CMSIS5_DSP)/BasicMathFunctions/arm_dot_prod_q7.c +CSRCS += $(CMSIS5_DSP)/BasicMathFunctions/arm_dot_prod_f32.c +CSRCS += $(CMSIS5_DSP)/BasicMathFunctions/arm_offset_q7.c +CSRCS += $(CMSIS5_DSP)/BasicMathFunctions/arm_dot_prod_q15.c +CSRCS += $(CMSIS5_DSP)/BasicMathFunctions/arm_abs_q7.c +CSRCS += $(CMSIS5_DSP)/BasicMathFunctions/arm_or_u32.c +CSRCS += $(CMSIS5_DSP)/BasicMathFunctions/arm_offset_q31.c +CSRCS += $(CMSIS5_DSP)/BasicMathFunctions/arm_and_u8.c +CSRCS += $(CMSIS5_DSP)/BasicMathFunctions/arm_sub_q31.c +CSRCS += $(CMSIS5_DSP)/BasicMathFunctions/arm_or_u8.c +CSRCS += $(CMSIS5_DSP)/BasicMathFunctions/arm_clip_q15.c +CSRCS += $(CMSIS5_DSP)/BasicMathFunctions/BasicMathFunctionsF16.c +CSRCS += $(CMSIS5_DSP)/BasicMathFunctions/arm_abs_f16.c +CSRCS += $(CMSIS5_DSP)/BasicMathFunctions/arm_xor_u32.c +CSRCS += $(CMSIS5_DSP)/BasicMathFunctions/arm_negate_q15.c +CSRCS += $(CMSIS5_DSP)/BasicMathFunctions/arm_dot_prod_q31.c +CSRCS += $(CMSIS5_DSP)/BasicMathFunctions/arm_not_u16.c +CSRCS += $(CMSIS5_DSP)/BasicMathFunctions/arm_add_q31.c +CSRCS += $(CMSIS5_DSP)/BasicMathFunctions/arm_mult_q15.c +CSRCS += $(CMSIS5_DSP)/BasicMathFunctions/arm_clip_q31.c +CSRCS += $(CMSIS5_DSP)/BasicMathFunctions/arm_or_u16.c +CSRCS += $(CMSIS5_DSP)/BasicMathFunctions/arm_abs_q31.c +CSRCS += $(CMSIS5_DSP)/BasicMathFunctions/arm_add_f32.c +CSRCS += $(CMSIS5_DSP)/BasicMathFunctions/arm_mult_f16.c +CSRCS += $(CMSIS5_DSP)/BasicMathFunctions/arm_clip_f32.c +CSRCS += $(CMSIS5_DSP)/BasicMathFunctions/arm_abs_q15.c +CSRCS += $(CMSIS5_DSP)/BasicMathFunctions/arm_scale_f32.c +CSRCS += $(CMSIS5_DSP)/ControllerFunctions/ControllerFunctions.c +CSRCS += $(CMSIS5_DSP)/ControllerFunctions/arm_pid_reset_f32.c +CSRCS += $(CMSIS5_DSP)/ControllerFunctions/arm_sin_cos_q31.c +CSRCS += $(CMSIS5_DSP)/ControllerFunctions/arm_pid_init_q31.c +CSRCS += $(CMSIS5_DSP)/ControllerFunctions/arm_sin_cos_f32.c +CSRCS += $(CMSIS5_DSP)/ControllerFunctions/arm_pid_init_q15.c +CSRCS += $(CMSIS5_DSP)/ControllerFunctions/arm_pid_init_f32.c +CSRCS += $(CMSIS5_DSP)/ControllerFunctions/arm_pid_reset_q15.c +CSRCS += $(CMSIS5_DSP)/ControllerFunctions/arm_pid_reset_q31.c +CSRCS += $(CMSIS5_DSP)/SupportFunctions/arm_weighted_sum_f16.c +CSRCS += $(CMSIS5_DSP)/SupportFunctions/SupportFunctions.c +CSRCS += $(CMSIS5_DSP)/SupportFunctions/arm_q31_to_float.c +CSRCS += $(CMSIS5_DSP)/SupportFunctions/arm_sort_f32.c +CSRCS += $(CMSIS5_DSP)/SupportFunctions/arm_float_to_f16.c +CSRCS += $(CMSIS5_DSP)/SupportFunctions/arm_fill_q31.c +CSRCS += $(CMSIS5_DSP)/SupportFunctions/arm_q31_to_q15.c +CSRCS += $(CMSIS5_DSP)/SupportFunctions/arm_q15_to_f16.c +CSRCS += $(CMSIS5_DSP)/SupportFunctions/arm_q15_to_float.c +CSRCS += $(CMSIS5_DSP)/SupportFunctions/arm_copy_f16.c +CSRCS += $(CMSIS5_DSP)/SupportFunctions/arm_fill_f32.c +CSRCS += $(CMSIS5_DSP)/SupportFunctions/arm_weighted_sum_f32.c +CSRCS += $(CMSIS5_DSP)/SupportFunctions/arm_bubble_sort_f32.c +CSRCS += $(CMSIS5_DSP)/SupportFunctions/arm_q31_to_q7.c +CSRCS += $(CMSIS5_DSP)/SupportFunctions/arm_copy_q31.c +CSRCS += $(CMSIS5_DSP)/SupportFunctions/arm_fill_q7.c +CSRCS += $(CMSIS5_DSP)/SupportFunctions/arm_copy_q7.c +CSRCS += $(CMSIS5_DSP)/SupportFunctions/arm_insertion_sort_f32.c +CSRCS += $(CMSIS5_DSP)/SupportFunctions/SupportFunctionsF16.c +CSRCS += $(CMSIS5_DSP)/SupportFunctions/arm_barycenter_f32.c +CSRCS += $(CMSIS5_DSP)/SupportFunctions/arm_sort_init_f32.c +CSRCS += $(CMSIS5_DSP)/SupportFunctions/arm_copy_q15.c +CSRCS += $(CMSIS5_DSP)/SupportFunctions/arm_fill_f16.c +CSRCS += $(CMSIS5_DSP)/SupportFunctions/arm_float_to_q31.c +CSRCS += $(CMSIS5_DSP)/SupportFunctions/arm_bitonic_sort_f32.c +CSRCS += $(CMSIS5_DSP)/SupportFunctions/arm_merge_sort_init_f32.c +CSRCS += $(CMSIS5_DSP)/SupportFunctions/arm_float_to_q7.c +CSRCS += $(CMSIS5_DSP)/SupportFunctions/arm_barycenter_f16.c +CSRCS += $(CMSIS5_DSP)/SupportFunctions/arm_q15_to_q31.c +CSRCS += $(CMSIS5_DSP)/SupportFunctions/arm_f16_to_float.c +CSRCS += $(CMSIS5_DSP)/SupportFunctions/arm_merge_sort_f32.c +CSRCS += $(CMSIS5_DSP)/SupportFunctions/arm_copy_f32.c +CSRCS += $(CMSIS5_DSP)/SupportFunctions/arm_fill_q15.c +CSRCS += $(CMSIS5_DSP)/SupportFunctions/arm_q7_to_q31.c +CSRCS += $(CMSIS5_DSP)/SupportFunctions/arm_selection_sort_f32.c +CSRCS += $(CMSIS5_DSP)/SupportFunctions/arm_float_to_q15.c +CSRCS += $(CMSIS5_DSP)/SupportFunctions/arm_heap_sort_f32.c +CSRCS += $(CMSIS5_DSP)/SupportFunctions/arm_q7_to_float.c +CSRCS += $(CMSIS5_DSP)/SupportFunctions/arm_q7_to_q15.c +CSRCS += $(CMSIS5_DSP)/SupportFunctions/arm_quick_sort_f32.c +CSRCS += $(CMSIS5_DSP)/SupportFunctions/arm_f16_to_q15.c +CSRCS += $(CMSIS5_DSP)/SupportFunctions/arm_q15_to_q7.c +CSRCS += $(CMSIS5_DSP)/CommonTables/arm_common_tables.c +CSRCS += $(CMSIS5_DSP)/CommonTables/arm_mve_tables_f16.c +CSRCS += $(CMSIS5_DSP)/CommonTables/arm_mve_tables.c +CSRCS += $(CMSIS5_DSP)/CommonTables/CommonTablesF16.c +CSRCS += $(CMSIS5_DSP)/CommonTables/arm_const_structs.c +CSRCS += $(CMSIS5_DSP)/CommonTables/arm_common_tables_f16.c +CSRCS += $(CMSIS5_DSP)/CommonTables/CommonTables.c +CSRCS += $(CMSIS5_DSP)/CommonTables/arm_const_structs_f16.c +CSRCS += $(CMSIS5_DSP)/DistanceFunctions/arm_braycurtis_distance_f16.c +CSRCS += $(CMSIS5_DSP)/DistanceFunctions/arm_chebyshev_distance_f16.c +CSRCS += $(CMSIS5_DSP)/DistanceFunctions/arm_cosine_distance_f16.c +CSRCS += $(CMSIS5_DSP)/DistanceFunctions/arm_canberra_distance_f32.c +CSRCS += $(CMSIS5_DSP)/DistanceFunctions/arm_cosine_distance_f32.c +CSRCS += $(CMSIS5_DSP)/DistanceFunctions/arm_cityblock_distance_f16.c +CSRCS += $(CMSIS5_DSP)/DistanceFunctions/arm_canberra_distance_f16.c +CSRCS += $(CMSIS5_DSP)/DistanceFunctions/arm_dice_distance.c +CSRCS += $(CMSIS5_DSP)/DistanceFunctions/arm_boolean_distance.c +CSRCS += $(CMSIS5_DSP)/DistanceFunctions/arm_jensenshannon_distance_f16.c +CSRCS += $(CMSIS5_DSP)/DistanceFunctions/arm_correlation_distance_f32.c +CSRCS += $(CMSIS5_DSP)/DistanceFunctions/arm_russellrao_distance.c +CSRCS += $(CMSIS5_DSP)/DistanceFunctions/arm_braycurtis_distance_f32.c +CSRCS += $(CMSIS5_DSP)/DistanceFunctions/arm_minkowski_distance_f32.c +CSRCS += $(CMSIS5_DSP)/DistanceFunctions/arm_chebyshev_distance_f32.c +CSRCS += $(CMSIS5_DSP)/DistanceFunctions/arm_sokalmichener_distance.c +CSRCS += $(CMSIS5_DSP)/DistanceFunctions/arm_sokalsneath_distance.c +CSRCS += $(CMSIS5_DSP)/DistanceFunctions/arm_rogerstanimoto_distance.c +CSRCS += $(CMSIS5_DSP)/DistanceFunctions/arm_hamming_distance.c +CSRCS += $(CMSIS5_DSP)/DistanceFunctions/arm_kulsinski_distance.c +CSRCS += $(CMSIS5_DSP)/DistanceFunctions/arm_jensenshannon_distance_f32.c +CSRCS += $(CMSIS5_DSP)/DistanceFunctions/arm_euclidean_distance_f16.c +CSRCS += $(CMSIS5_DSP)/DistanceFunctions/arm_cityblock_distance_f32.c +CSRCS += $(CMSIS5_DSP)/DistanceFunctions/DistanceFunctionsF16.c +CSRCS += $(CMSIS5_DSP)/DistanceFunctions/arm_yule_distance.c +CSRCS += $(CMSIS5_DSP)/DistanceFunctions/arm_jaccard_distance.c +CSRCS += $(CMSIS5_DSP)/DistanceFunctions/arm_euclidean_distance_f32.c +CSRCS += $(CMSIS5_DSP)/DistanceFunctions/arm_minkowski_distance_f16.c +CSRCS += $(CMSIS5_DSP)/DistanceFunctions/arm_correlation_distance_f16.c +CSRCS += $(CMSIS5_DSP)/DistanceFunctions/DistanceFunctions.c +CSRCS += $(CMSIS5_DSP)/StatisticsFunctions/arm_max_q15.c +CSRCS += $(CMSIS5_DSP)/StatisticsFunctions/arm_absmax_q15.c +CSRCS += $(CMSIS5_DSP)/StatisticsFunctions/arm_rms_q15.c +CSRCS += $(CMSIS5_DSP)/StatisticsFunctions/arm_std_q15.c +CSRCS += $(CMSIS5_DSP)/StatisticsFunctions/arm_var_f16.c +CSRCS += $(CMSIS5_DSP)/StatisticsFunctions/arm_var_q15.c +CSRCS += $(CMSIS5_DSP)/StatisticsFunctions/arm_min_q31.c +CSRCS += $(CMSIS5_DSP)/StatisticsFunctions/arm_power_f16.c +CSRCS += $(CMSIS5_DSP)/StatisticsFunctions/arm_min_f32.c +CSRCS += $(CMSIS5_DSP)/StatisticsFunctions/arm_power_q15.c +CSRCS += $(CMSIS5_DSP)/StatisticsFunctions/arm_std_q31.c +CSRCS += $(CMSIS5_DSP)/StatisticsFunctions/arm_absmin_f16.c +CSRCS += $(CMSIS5_DSP)/StatisticsFunctions/arm_rms_f32.c +CSRCS += $(CMSIS5_DSP)/StatisticsFunctions/arm_absmax_f32.c +CSRCS += $(CMSIS5_DSP)/StatisticsFunctions/arm_max_q31.c +CSRCS += $(CMSIS5_DSP)/StatisticsFunctions/arm_entropy_f32.c +CSRCS += $(CMSIS5_DSP)/StatisticsFunctions/arm_mean_q15.c +CSRCS += $(CMSIS5_DSP)/StatisticsFunctions/arm_mean_f16.c +CSRCS += $(CMSIS5_DSP)/StatisticsFunctions/arm_std_f16.c +CSRCS += $(CMSIS5_DSP)/StatisticsFunctions/arm_mean_q7.c +CSRCS += $(CMSIS5_DSP)/StatisticsFunctions/arm_logsumexp_f16.c +CSRCS += $(CMSIS5_DSP)/StatisticsFunctions/arm_std_f32.c +CSRCS += $(CMSIS5_DSP)/StatisticsFunctions/arm_power_q7.c +CSRCS += $(CMSIS5_DSP)/StatisticsFunctions/arm_kullback_leibler_f64.c +CSRCS += $(CMSIS5_DSP)/StatisticsFunctions/arm_max_no_idx_f32.c +CSRCS += $(CMSIS5_DSP)/StatisticsFunctions/arm_max_q7.c +CSRCS += $(CMSIS5_DSP)/StatisticsFunctions/StatisticsFunctions.c +CSRCS += $(CMSIS5_DSP)/StatisticsFunctions/arm_logsumexp_f32.c +CSRCS += $(CMSIS5_DSP)/StatisticsFunctions/arm_rms_f16.c +CSRCS += $(CMSIS5_DSP)/StatisticsFunctions/arm_max_f32.c +CSRCS += $(CMSIS5_DSP)/StatisticsFunctions/arm_rms_q31.c +CSRCS += $(CMSIS5_DSP)/StatisticsFunctions/arm_logsumexp_dot_prod_f16.c +CSRCS += $(CMSIS5_DSP)/StatisticsFunctions/arm_mean_q31.c +CSRCS += $(CMSIS5_DSP)/StatisticsFunctions/arm_absmin_q7.c +CSRCS += $(CMSIS5_DSP)/StatisticsFunctions/arm_min_q7.c +CSRCS += $(CMSIS5_DSP)/StatisticsFunctions/arm_absmax_f16.c +CSRCS += $(CMSIS5_DSP)/StatisticsFunctions/arm_absmin_f32.c +CSRCS += $(CMSIS5_DSP)/StatisticsFunctions/arm_logsumexp_dot_prod_f32.c +CSRCS += $(CMSIS5_DSP)/StatisticsFunctions/arm_var_f32.c +CSRCS += $(CMSIS5_DSP)/StatisticsFunctions/arm_kullback_leibler_f32.c +CSRCS += $(CMSIS5_DSP)/StatisticsFunctions/arm_absmin_q31.c +CSRCS += $(CMSIS5_DSP)/StatisticsFunctions/arm_min_f16.c +CSRCS += $(CMSIS5_DSP)/StatisticsFunctions/arm_kullback_leibler_f16.c +CSRCS += $(CMSIS5_DSP)/StatisticsFunctions/arm_absmin_q15.c +CSRCS += $(CMSIS5_DSP)/StatisticsFunctions/arm_absmax_q31.c +CSRCS += $(CMSIS5_DSP)/StatisticsFunctions/arm_entropy_f16.c +CSRCS += $(CMSIS5_DSP)/StatisticsFunctions/arm_var_q31.c +CSRCS += $(CMSIS5_DSP)/StatisticsFunctions/arm_power_f32.c +CSRCS += $(CMSIS5_DSP)/StatisticsFunctions/arm_power_q31.c +CSRCS += $(CMSIS5_DSP)/StatisticsFunctions/arm_max_no_idx_f16.c +CSRCS += $(CMSIS5_DSP)/StatisticsFunctions/arm_mean_f32.c +CSRCS += $(CMSIS5_DSP)/StatisticsFunctions/arm_absmax_q7.c +CSRCS += $(CMSIS5_DSP)/StatisticsFunctions/arm_entropy_f64.c +CSRCS += $(CMSIS5_DSP)/StatisticsFunctions/arm_max_f16.c +CSRCS += $(CMSIS5_DSP)/StatisticsFunctions/arm_min_q15.c +CSRCS += $(CMSIS5_DSP)/StatisticsFunctions/StatisticsFunctionsF16.c +CSRCS += $(CMSIS5_DSP)/MatrixFunctions/arm_mat_ldlt_f64.c +CSRCS += $(CMSIS5_DSP)/MatrixFunctions/arm_mat_add_f32.c +CSRCS += $(CMSIS5_DSP)/MatrixFunctions/arm_mat_solve_lower_triangular_f32.c +CSRCS += $(CMSIS5_DSP)/MatrixFunctions/arm_mat_inverse_f32.c +CSRCS += $(CMSIS5_DSP)/MatrixFunctions/arm_mat_trans_f64.c +CSRCS += $(CMSIS5_DSP)/MatrixFunctions/arm_mat_mult_f32.c +CSRCS += $(CMSIS5_DSP)/MatrixFunctions/arm_mat_inverse_f64.c +CSRCS += $(CMSIS5_DSP)/MatrixFunctions/arm_mat_init_f16.c +CSRCS += $(CMSIS5_DSP)/MatrixFunctions/arm_mat_solve_lower_triangular_f64.c +CSRCS += $(CMSIS5_DSP)/MatrixFunctions/MatrixFunctions.c +CSRCS += $(CMSIS5_DSP)/MatrixFunctions/arm_mat_vec_mult_f32.c +CSRCS += $(CMSIS5_DSP)/MatrixFunctions/MatrixFunctionsF16.c +CSRCS += $(CMSIS5_DSP)/MatrixFunctions/arm_mat_trans_q15.c +CSRCS += $(CMSIS5_DSP)/MatrixFunctions/arm_mat_cmplx_trans_q31.c +CSRCS += $(CMSIS5_DSP)/MatrixFunctions/arm_mat_vec_mult_q31.c +CSRCS += $(CMSIS5_DSP)/MatrixFunctions/arm_mat_sub_f32.c +CSRCS += $(CMSIS5_DSP)/MatrixFunctions/arm_mat_mult_q31.c +CSRCS += $(CMSIS5_DSP)/MatrixFunctions/arm_mat_trans_q7.c +CSRCS += $(CMSIS5_DSP)/MatrixFunctions/arm_mat_mult_f16.c +CSRCS += $(CMSIS5_DSP)/MatrixFunctions/arm_mat_trans_f16.c +CSRCS += $(CMSIS5_DSP)/MatrixFunctions/arm_mat_cmplx_mult_q31.c +CSRCS += $(CMSIS5_DSP)/MatrixFunctions/arm_mat_trans_q31.c +CSRCS += $(CMSIS5_DSP)/MatrixFunctions/arm_mat_trans_f32.c +CSRCS += $(CMSIS5_DSP)/MatrixFunctions/arm_mat_scale_f16.c +CSRCS += $(CMSIS5_DSP)/MatrixFunctions/arm_mat_vec_mult_q7.c +CSRCS += $(CMSIS5_DSP)/MatrixFunctions/arm_mat_ldlt_f32.c +CSRCS += $(CMSIS5_DSP)/MatrixFunctions/arm_mat_solve_lower_triangular_f16.c +CSRCS += $(CMSIS5_DSP)/MatrixFunctions/arm_mat_cmplx_mult_f16.c +CSRCS += $(CMSIS5_DSP)/MatrixFunctions/arm_mat_mult_fast_q15.c +CSRCS += $(CMSIS5_DSP)/MatrixFunctions/arm_mat_cmplx_trans_f16.c +CSRCS += $(CMSIS5_DSP)/MatrixFunctions/arm_mat_solve_upper_triangular_f16.c +CSRCS += $(CMSIS5_DSP)/MatrixFunctions/arm_mat_solve_upper_triangular_f32.c +CSRCS += $(CMSIS5_DSP)/MatrixFunctions/arm_mat_cmplx_mult_q15.c +CSRCS += $(CMSIS5_DSP)/MatrixFunctions/arm_mat_cmplx_mult_f32.c +CSRCS += $(CMSIS5_DSP)/MatrixFunctions/arm_mat_cholesky_f16.c +CSRCS += $(CMSIS5_DSP)/MatrixFunctions/arm_mat_cmplx_trans_f32.c +CSRCS += $(CMSIS5_DSP)/MatrixFunctions/arm_mat_vec_mult_q15.c +CSRCS += $(CMSIS5_DSP)/MatrixFunctions/arm_mat_scale_q31.c +CSRCS += $(CMSIS5_DSP)/MatrixFunctions/arm_mat_cmplx_trans_q15.c +CSRCS += $(CMSIS5_DSP)/MatrixFunctions/arm_mat_sub_f16.c +CSRCS += $(CMSIS5_DSP)/MatrixFunctions/arm_mat_mult_q15.c +CSRCS += $(CMSIS5_DSP)/MatrixFunctions/arm_mat_sub_q31.c +CSRCS += $(CMSIS5_DSP)/MatrixFunctions/arm_mat_mult_f64.c +CSRCS += $(CMSIS5_DSP)/MatrixFunctions/arm_mat_inverse_f16.c +CSRCS += $(CMSIS5_DSP)/MatrixFunctions/arm_mat_solve_upper_triangular_f64.c +CSRCS += $(CMSIS5_DSP)/MatrixFunctions/arm_mat_add_f16.c +CSRCS += $(CMSIS5_DSP)/MatrixFunctions/arm_mat_init_f32.c +CSRCS += $(CMSIS5_DSP)/MatrixFunctions/arm_mat_init_q31.c +CSRCS += $(CMSIS5_DSP)/MatrixFunctions/arm_mat_add_q31.c +CSRCS += $(CMSIS5_DSP)/MatrixFunctions/arm_mat_sub_f64.c +CSRCS += $(CMSIS5_DSP)/MatrixFunctions/arm_mat_init_q15.c +CSRCS += $(CMSIS5_DSP)/MatrixFunctions/arm_mat_mult_fast_q31.c +CSRCS += $(CMSIS5_DSP)/MatrixFunctions/arm_mat_scale_f32.c +CSRCS += $(CMSIS5_DSP)/MatrixFunctions/arm_mat_scale_q15.c +CSRCS += $(CMSIS5_DSP)/MatrixFunctions/arm_mat_cholesky_f64.c +CSRCS += $(CMSIS5_DSP)/MatrixFunctions/arm_mat_cholesky_f32.c +CSRCS += $(CMSIS5_DSP)/MatrixFunctions/arm_mat_vec_mult_f16.c +CSRCS += $(CMSIS5_DSP)/MatrixFunctions/arm_mat_sub_q15.c +CSRCS += $(CMSIS5_DSP)/MatrixFunctions/arm_mat_add_q15.c +CSRCS += $(CMSIS5_DSP)/MatrixFunctions/arm_mat_mult_q7.c +CSRCS += $(CMSIS5_DSP)/QuaternionMathFunctions/QuaternionMathFunctions.c +CSRCS += $(CMSIS5_DSP)/QuaternionMathFunctions/arm_rotation2quaternion_f32.c +CSRCS += $(CMSIS5_DSP)/QuaternionMathFunctions/arm_quaternion_normalize_f32.c +CSRCS += $(CMSIS5_DSP)/QuaternionMathFunctions/arm_quaternion_product_f32.c +CSRCS += $(CMSIS5_DSP)/QuaternionMathFunctions/arm_quaternion_product_single_f32.c +CSRCS += $(CMSIS5_DSP)/QuaternionMathFunctions/arm_quaternion_conjugate_f32.c +CSRCS += $(CMSIS5_DSP)/QuaternionMathFunctions/arm_quaternion_inverse_f32.c +CSRCS += $(CMSIS5_DSP)/QuaternionMathFunctions/arm_quaternion_norm_f32.c +CSRCS += $(CMSIS5_DSP)/QuaternionMathFunctions/arm_quaternion2rotation_f32.c +CSRCS += $(CMSIS5_DSP)/TransformFunctions/arm_bitreversal2.c +CSRCS += $(CMSIS5_DSP)/TransformFunctions/arm_cfft_init_f16.c +CSRCS += $(CMSIS5_DSP)/TransformFunctions/TransformFunctionsF16.c +CSRCS += $(CMSIS5_DSP)/TransformFunctions/arm_cfft_q31.c +CSRCS += $(CMSIS5_DSP)/TransformFunctions/arm_cfft_radix2_f16.c +CSRCS += $(CMSIS5_DSP)/TransformFunctions/arm_dct4_init_f32.c +CSRCS += $(CMSIS5_DSP)/TransformFunctions/arm_dct4_init_q31.c +CSRCS += $(CMSIS5_DSP)/TransformFunctions/arm_rfft_init_q31.c +CSRCS += $(CMSIS5_DSP)/TransformFunctions/arm_cfft_radix4_init_q15.c +CSRCS += $(CMSIS5_DSP)/TransformFunctions/arm_cfft_radix2_f32.c +CSRCS += $(CMSIS5_DSP)/TransformFunctions/arm_rfft_q31.c +CSRCS += $(CMSIS5_DSP)/TransformFunctions/arm_dct4_f32.c +CSRCS += $(CMSIS5_DSP)/TransformFunctions/arm_cfft_init_f32.c +CSRCS += $(CMSIS5_DSP)/TransformFunctions/arm_cfft_radix2_init_f32.c +CSRCS += $(CMSIS5_DSP)/TransformFunctions/arm_cfft_f64.c +CSRCS += $(CMSIS5_DSP)/TransformFunctions/arm_rfft_init_f32.c +CSRCS += $(CMSIS5_DSP)/TransformFunctions/arm_cfft_q15.c +CSRCS += $(CMSIS5_DSP)/TransformFunctions/arm_dct4_q15.c +CSRCS += $(CMSIS5_DSP)/TransformFunctions/arm_dct4_q31.c +CSRCS += $(CMSIS5_DSP)/TransformFunctions/arm_cfft_radix2_q31.c +CSRCS += $(CMSIS5_DSP)/TransformFunctions/arm_rfft_init_q15.c +CSRCS += $(CMSIS5_DSP)/TransformFunctions/arm_dct4_init_q15.c +CSRCS += $(CMSIS5_DSP)/TransformFunctions/arm_rfft_f32.c +CSRCS += $(CMSIS5_DSP)/TransformFunctions/arm_cfft_radix4_q15.c +CSRCS += $(CMSIS5_DSP)/TransformFunctions/arm_cfft_radix2_init_q15.c +CSRCS += $(CMSIS5_DSP)/TransformFunctions/arm_rfft_fast_init_f64.c +CSRCS += $(CMSIS5_DSP)/TransformFunctions/arm_cfft_init_q31.c +CSRCS += $(CMSIS5_DSP)/TransformFunctions/arm_rfft_fast_f64.c +CSRCS += $(CMSIS5_DSP)/TransformFunctions/arm_cfft_f32.c +CSRCS += $(CMSIS5_DSP)/TransformFunctions/arm_cfft_radix4_init_q31.c +CSRCS += $(CMSIS5_DSP)/TransformFunctions/arm_cfft_init_f64.c +CSRCS += $(CMSIS5_DSP)/TransformFunctions/arm_rfft_fast_f32.c +CSRCS += $(CMSIS5_DSP)/TransformFunctions/arm_cfft_radix8_f32.c +CSRCS += $(CMSIS5_DSP)/TransformFunctions/arm_cfft_radix2_q15.c +CSRCS += $(CMSIS5_DSP)/TransformFunctions/arm_bitreversal.c +CSRCS += $(CMSIS5_DSP)/TransformFunctions/arm_cfft_radix4_f32.c +CSRCS += $(CMSIS5_DSP)/TransformFunctions/arm_cfft_radix4_init_f16.c +CSRCS += $(CMSIS5_DSP)/TransformFunctions/arm_cfft_radix4_f16.c +CSRCS += $(CMSIS5_DSP)/TransformFunctions/arm_cfft_f16.c +CSRCS += $(CMSIS5_DSP)/TransformFunctions/arm_cfft_radix4_init_f32.c +CSRCS += $(CMSIS5_DSP)/TransformFunctions/arm_cfft_radix4_q31.c +CSRCS += $(CMSIS5_DSP)/TransformFunctions/TransformFunctions.c +CSRCS += $(CMSIS5_DSP)/TransformFunctions/arm_cfft_radix2_init_q31.c +CSRCS += $(CMSIS5_DSP)/TransformFunctions/arm_cfft_radix2_init_f16.c +CSRCS += $(CMSIS5_DSP)/TransformFunctions/arm_rfft_fast_init_f32.c +CSRCS += $(CMSIS5_DSP)/TransformFunctions/arm_bitreversal_f16.c +CSRCS += $(CMSIS5_DSP)/TransformFunctions/arm_cfft_init_q15.c +CSRCS += $(CMSIS5_DSP)/TransformFunctions/arm_rfft_fast_f16.c +CSRCS += $(CMSIS5_DSP)/TransformFunctions/arm_cfft_radix8_f16.c +CSRCS += $(CMSIS5_DSP)/TransformFunctions/arm_rfft_fast_init_f16.c +CSRCS += $(CMSIS5_DSP)/TransformFunctions/arm_rfft_q15.c +CSRCS += $(CMSIS5_DSP)/BayesFunctions/BayesFunctionsF16.c +CSRCS += $(CMSIS5_DSP)/BayesFunctions/arm_gaussian_naive_bayes_predict_f32.c +CSRCS += $(CMSIS5_DSP)/BayesFunctions/arm_gaussian_naive_bayes_predict_f16.c +CSRCS += $(CMSIS5_DSP)/BayesFunctions/BayesFunctions.c +CSRCS += $(CMSIS5_DSP)/ComplexMathFunctions/arm_cmplx_mag_squared_f16.c +CSRCS += $(CMSIS5_DSP)/ComplexMathFunctions/arm_cmplx_mag_squared_q15.c +CSRCS += $(CMSIS5_DSP)/ComplexMathFunctions/arm_cmplx_mag_squared_q31.c +CSRCS += $(CMSIS5_DSP)/ComplexMathFunctions/arm_cmplx_mult_cmplx_f32.c +CSRCS += $(CMSIS5_DSP)/ComplexMathFunctions/arm_cmplx_conj_q15.c +CSRCS += $(CMSIS5_DSP)/ComplexMathFunctions/arm_cmplx_mult_real_f32.c +CSRCS += $(CMSIS5_DSP)/ComplexMathFunctions/arm_cmplx_mag_q15.c +CSRCS += $(CMSIS5_DSP)/ComplexMathFunctions/arm_cmplx_dot_prod_f32.c +CSRCS += $(CMSIS5_DSP)/ComplexMathFunctions/arm_cmplx_mult_cmplx_f16.c +CSRCS += $(CMSIS5_DSP)/ComplexMathFunctions/arm_cmplx_mult_cmplx_q31.c +CSRCS += $(CMSIS5_DSP)/ComplexMathFunctions/arm_cmplx_mag_q31.c +CSRCS += $(CMSIS5_DSP)/ComplexMathFunctions/arm_cmplx_mult_real_q15.c +CSRCS += $(CMSIS5_DSP)/ComplexMathFunctions/arm_cmplx_dot_prod_q15.c +CSRCS += $(CMSIS5_DSP)/ComplexMathFunctions/arm_cmplx_conj_f16.c +CSRCS += $(CMSIS5_DSP)/ComplexMathFunctions/arm_cmplx_conj_f32.c +CSRCS += $(CMSIS5_DSP)/ComplexMathFunctions/arm_cmplx_mag_squared_f32.c +CSRCS += $(CMSIS5_DSP)/ComplexMathFunctions/arm_cmplx_mult_cmplx_q15.c +CSRCS += $(CMSIS5_DSP)/ComplexMathFunctions/arm_cmplx_dot_prod_q31.c +CSRCS += $(CMSIS5_DSP)/ComplexMathFunctions/ComplexMathFunctions.c +CSRCS += $(CMSIS5_DSP)/ComplexMathFunctions/arm_cmplx_mag_f16.c +CSRCS += $(CMSIS5_DSP)/ComplexMathFunctions/ComplexMathFunctionsF16.c +CSRCS += $(CMSIS5_DSP)/ComplexMathFunctions/arm_cmplx_mult_real_f16.c +CSRCS += $(CMSIS5_DSP)/ComplexMathFunctions/arm_cmplx_dot_prod_f16.c +CSRCS += $(CMSIS5_DSP)/ComplexMathFunctions/arm_cmplx_conj_q31.c +CSRCS += $(CMSIS5_DSP)/ComplexMathFunctions/arm_cmplx_mult_real_q31.c +CSRCS += $(CMSIS5_DSP)/ComplexMathFunctions/arm_cmplx_mag_f32.c -VPATH += $(CMSIS5_DSP)/SVMFunctions -VPATH += $(CMSIS5_DSP)/InterpolationFunctions -VPATH += $(CMSIS5_DSP)/FastMathFunctions -VPATH += $(CMSIS5_DSP)/FilteringFunctions -VPATH += $(CMSIS5_DSP)/BasicMathFunctions -VPATH += $(CMSIS5_DSP)/ControllerFunctions -VPATH += $(CMSIS5_DSP)/SupportFunctions -VPATH += $(CMSIS5_DSP)/CommonTables -VPATH += $(CMSIS5_DSP)/DistanceFunctions -VPATH += $(CMSIS5_DSP)/StatisticsFunctions -VPATH += $(CMSIS5_DSP)/MatrixFunctions -VPATH += $(CMSIS5_DSP)/QuaternionMathFunctions -VPATH += $(CMSIS5_DSP)/TransformFunctions -VPATH += $(CMSIS5_DSP)/BayesFunctions -VPATH += $(CMSIS5_DSP)/ComplexMathFunctions - -CFLAGS += -ffast-math -Wno-shadow -flax-vector-conversions +CFLAGS += -ffast-math -Wno-shadow MODULE = $(CONFIG_CMSIS_DSP) diff --git a/mlearning/cmsis/libcmsisnn/Make.defs b/mlearning/cmsis/libcmsisnn/Make.defs index 5119cdb3d..23314ab42 100644 --- a/mlearning/cmsis/libcmsisnn/Make.defs +++ b/mlearning/cmsis/libcmsisnn/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/mlearning/cmsis/libcmsisnn/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -20,9 +18,9 @@ # ############################################################################ -ifneq ($(CONFIG_CMSIS_NN),) +ifeq ($(CONFIG_CMSIS_NN),y) CONFIGURED_APPS += $(APPDIR)/mlearning/cmsis/libcmsisnn -CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/mlearning/cmsis/CMSIS_5/CMSIS/NN/Include/ -CXXFLAGS += ${INCDIR_PREFIX}$(APPDIR)/mlearning/cmsis/CMSIS_5/CMSIS/NN/Include/ +CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(APPDIR)/mlearning/cmsis/CMSIS_5/CMSIS/NN/Include/} +CXXFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(APPDIR)/mlearning/cmsis/CMSIS_5/CMSIS/NN/Include/} endif diff --git a/mlearning/cmsis/libcmsisnn/Makefile b/mlearning/cmsis/libcmsisnn/Makefile index 63cb79e7c..759b05f4c 100644 --- a/mlearning/cmsis/libcmsisnn/Makefile +++ b/mlearning/cmsis/libcmsisnn/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/mlearning/cmsis/libcmsisnn/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/mlearning/darknet/Kconfig b/mlearning/darknet/Kconfig deleted file mode 100644 index 0e8dd0c04..000000000 --- a/mlearning/darknet/Kconfig +++ /dev/null @@ -1,19 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config DARKNET_YOLO - bool "YOLO: Real-Time Object Detection" - default n - ---help--- - You only look once (YOLO) is a state-of-the-art, - real-time object detection system - -if DARKNET_YOLO - -config DARKNET_YOLO_VER - string "DARKNET YOLO version" - default "master" - -endif # DARKNET_YOLO diff --git a/mlearning/darknet/Make.defs b/mlearning/darknet/Make.defs deleted file mode 100644 index 41c1569e8..000000000 --- a/mlearning/darknet/Make.defs +++ /dev/null @@ -1,28 +0,0 @@ -############################################################################ -# apps/mlearning/darknet/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_DARKNET_YOLO),) -CONFIGURED_APPS += $(APPDIR)/mlearning/darknet - -CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/mlearning/darknet/darknet/include/ -CXXFLAGS += ${INCDIR_PREFIX}$(APPDIR)/mlearning/darknet/darknet/include/ -endif diff --git a/mlearning/darknet/Makefile b/mlearning/darknet/Makefile deleted file mode 100644 index 627245fbd..000000000 --- a/mlearning/darknet/Makefile +++ /dev/null @@ -1,92 +0,0 @@ -############################################################################ -# apps/mlearning/darknet/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -SRC = darknet/src - -CSRCS +=$(SRC)/gemm.c -CSRCS +=$(SRC)/utils.c -CSRCS +=$(SRC)/cuda.c -CSRCS +=$(SRC)/deconvolutional_layer.c -CSRCS +=$(SRC)/convolutional_layer.c -CSRCS +=$(SRC)/list.c -CSRCS +=$(SRC)/image.c -CSRCS +=$(SRC)/activations.c -CSRCS +=$(SRC)/im2col.c -CSRCS +=$(SRC)/col2im.c -CSRCS +=$(SRC)/blas.c -CSRCS +=$(SRC)/crop_layer.c -CSRCS +=$(SRC)/dropout_layer.c -CSRCS +=$(SRC)/maxpool_layer.c -CSRCS +=$(SRC)/softmax_layer.c -CSRCS +=$(SRC)/data.c -CSRCS +=$(SRC)/matrix.c -CSRCS +=$(SRC)/network.c -CSRCS +=$(SRC)/connected_layer.c -CSRCS +=$(SRC)/cost_layer.c -CSRCS +=$(SRC)/parser.c -CSRCS +=$(SRC)/option_list.c -CSRCS +=$(SRC)/detection_layer.c -CSRCS +=$(SRC)/route_layer.c -CSRCS +=$(SRC)/upsample_layer.c -CSRCS +=$(SRC)/box.c -CSRCS +=$(SRC)/normalization_layer.c -CSRCS +=$(SRC)/avgpool_layer.c -CSRCS +=$(SRC)/layer.c -CSRCS +=$(SRC)/local_layer.c -CSRCS +=$(SRC)/shortcut_layer.c -CSRCS +=$(SRC)/logistic_layer.c -CSRCS +=$(SRC)/activation_layer.c -CSRCS +=$(SRC)/rnn_layer.c -CSRCS +=$(SRC)/gru_layer.c -CSRCS +=$(SRC)/crnn_layer.c -CSRCS +=$(SRC)/demo.c -CSRCS +=$(SRC)/batchnorm_layer.c -CSRCS +=$(SRC)/region_layer.c -CSRCS +=$(SRC)/reorg_layer.c -CSRCS +=$(SRC)/tree.c -CSRCS +=$(SRC)/lstm_layer.c -CSRCS +=$(SRC)/l2norm_layer.c -CSRCS +=$(SRC)/yolo_layer.c -CSRCS +=$(SRC)/iseg_layer.c - - -CFLAGS += -Wno-shadow -Wno-strict-prototypes -Wno-unknown-pragmas - -MODULE = $(CONFIG_DARKNET_YOLO) - -darknet.zip: - $(Q) curl -L https://github.com/pjreddie/darknet/archive/refs/heads/$(DARKNET_YOLO_VER).zip -o darknet.zip - $(Q) unzip -o darknet.zip - $(Q) mv darknet-$(DARKNET_YOLO_VER) darknet - -# Download and unpack tarball if no git repo found -ifeq ($(wildcard darknet/.git),) -context:: darknet.zip - -distclean:: - $(call DELDIR, darknet) - $(call DELFILE, darknet.zip) -endif - -include $(APPDIR)/Application.mk diff --git a/mlearning/libnnablart/Kconfig b/mlearning/libnnablart/Kconfig index f1f02d734..77a55b238 100644 --- a/mlearning/libnnablart/Kconfig +++ b/mlearning/libnnablart/Kconfig @@ -15,6 +15,6 @@ if NNABLA_RT config NNABLA_RT_VER string "Default NNABLA Runtime version" - default "1.24.0" + default 1.24.0 endif # NNABLA_RT diff --git a/mlearning/libnnablart/Make.defs b/mlearning/libnnablart/Make.defs index 2f57a0af6..406dbf1d7 100644 --- a/mlearning/libnnablart/Make.defs +++ b/mlearning/libnnablart/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/mlearning/libnnablart/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -20,9 +18,9 @@ # ############################################################################ -ifneq ($(CONFIG_NNABLA_RT),) +ifeq ($(CONFIG_NNABLA_RT),y) CONFIGURED_APPS += $(APPDIR)/mlearning/libnnablart -CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/mlearning/libnnablart/nnabla-c-runtime/include/ -CXXFLAGS += ${INCDIR_PREFIX}$(APPDIR)/mlearning/libnnablart/nnabla-c-runtime/include/ +CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(APPDIR)/mlearning/libnnablart/nnabla-c-runtime/include/} +CXXFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(APPDIR)/mlearning/libnnablart/nnabla-c-runtime/include/} endif diff --git a/mlearning/libnnablart/Makefile b/mlearning/libnnablart/Makefile index 8d7c726c6..058035838 100644 --- a/mlearning/libnnablart/Makefile +++ b/mlearning/libnnablart/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/mlearning/libnnablart/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -22,6 +20,7 @@ include $(APPDIR)/Make.defs +ifeq ($(CONFIG_NNABLA_RT),y) SRC = nnabla-c-runtime/src CSRCS += $(SRC)/functions/utilities/accessor.c @@ -116,13 +115,12 @@ nnabla.zip: $(Q) unzip -o nnabla.zip $(Q) mv nnabla-c-runtime-$(CONFIG_NNABLA_RT_VER) nnabla-c-runtime -# Download and unpack tarball if no git repo found -ifeq ($(wildcard nnabla-c-runtime/.git),) context:: nnabla.zip distclean:: $(call DELDIR, nnabla-c-runtime) $(call DELFILE, nnabla.zip) + endif include $(APPDIR)/Application.mk diff --git a/mlearning/tflite-micro/.gitignore b/mlearning/tflite-micro/.gitignore deleted file mode 100644 index 60853abb5..000000000 --- a/mlearning/tflite-micro/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/tflite-micro \ No newline at end of file diff --git a/mlearning/tflite-micro/0001-dequantize-int8.patch b/mlearning/tflite-micro/0001-dequantize-int8.patch deleted file mode 100644 index 92babecac..000000000 --- a/mlearning/tflite-micro/0001-dequantize-int8.patch +++ /dev/null @@ -1,101 +0,0 @@ -From 0cd2a39a346d84da3002fa7ba4085cfc3c61c8ee Mon Sep 17 00:00:00 2001 -From: jihandong -Date: Mon, 22 Apr 2024 18:14:44 +0800 -Subject: [PATCH 2/2] dequantize int8 - -VELAPLATFO-30990 - -Change-Id: I0e741a72464c7e497425175d2fcd63f14ed6897b -Signed-off-by: jihandong ---- - tensorflow/lite/micro/kernels/dequantize.cc | 21 +++++++++++++++++++ - tensorflow/lite/micro/kernels/dequantize.h | 5 ++++- - .../lite/micro/micro_mutable_op_resolver.h | 6 ++++-- - 3 files changed, 29 insertions(+), 3 deletions(-) - -diff --git a/tensorflow/lite/micro/kernels/dequantize.cc b/tensorflow/lite/micro/kernels/dequantize.cc -index 428c866a..48f50de4 100644 ---- a/tensorflow/lite/micro/kernels/dequantize.cc -+++ b/tensorflow/lite/micro/kernels/dequantize.cc -@@ -76,9 +76,30 @@ TfLiteStatus DequantizeEval(TfLiteContext* context, TfLiteNode* node) { - return kTfLiteOk; - } - -+TfLiteStatus DequantizeEvalInt8(TfLiteContext* context, TfLiteNode* node) { -+ TFLITE_DCHECK(node->user_data != nullptr); -+ DequantizeOpData* data = static_cast(node->user_data); -+ -+ const TfLiteEvalTensor* input = tflite::micro::GetEvalInput(context, node, 0); -+ TfLiteEvalTensor* output = tflite::micro::GetEvalOutput(context, node, 0); -+ -+ TFLITE_DCHECK(input->type == kTfLiteInt8 && output->type == kTfLiteFloat32); -+ reference_ops::Dequantize(data->quantization_params, -+ tflite::micro::GetTensorShape(input), -+ tflite::micro::GetTensorData(input), -+ tflite::micro::GetTensorShape(output), -+ tflite::micro::GetTensorData(output)); -+ return kTfLiteOk; -+} -+ - TFLMRegistration Register_DEQUANTIZE() { - return tflite::micro::RegisterOp(DequantizeInit, DequantizePrepare, - DequantizeEval); - } - -+TFLMRegistration Register_DEQUANTIZE_INT8() { -+ return tflite::micro::RegisterOp(DequantizeInit, DequantizePrepare, -+ DequantizeEvalInt8); -+} -+ - } // namespace tflite -diff --git a/tensorflow/lite/micro/kernels/dequantize.h b/tensorflow/lite/micro/kernels/dequantize.h -index fe6ec169..3dede725 100644 ---- a/tensorflow/lite/micro/kernels/dequantize.h -+++ b/tensorflow/lite/micro/kernels/dequantize.h -@@ -17,8 +17,8 @@ limitations under the License. - #define TENSORFLOW_LITE_MICRO_KERNELS_DEQUANTIZE_H_ - - #include "tensorflow/lite/c/builtin_op_data.h" --#include "tensorflow/lite/c/common.h" - #include "tensorflow/lite/kernels/internal/types.h" -+#include "tensorflow/lite/micro/micro_common.h" - - namespace tflite { - -@@ -33,6 +33,9 @@ struct DequantizeOpData { - - TfLiteStatus DequantizePrepare(TfLiteContext* context, TfLiteNode* node); - -+TFLMRegistration Register_DEQUANTIZE(); -+TFLMRegistration Register_DEQUANTIZE_INT8(); -+ - } // namespace tflite - - #endif // TENSORFLOW_LITE_MICRO_KERNELS_DEQUANTIZE_H_ -diff --git a/tensorflow/lite/micro/micro_mutable_op_resolver.h b/tensorflow/lite/micro/micro_mutable_op_resolver.h -index f5f6e38e..b3e3cbcf 100644 ---- a/tensorflow/lite/micro/micro_mutable_op_resolver.h -+++ b/tensorflow/lite/micro/micro_mutable_op_resolver.h -@@ -26,6 +26,7 @@ limitations under the License. - #include "tensorflow/lite/micro/kernels/add.h" - #include "tensorflow/lite/micro/kernels/conv.h" - #include "tensorflow/lite/micro/kernels/depthwise_conv.h" -+#include "tensorflow/lite/micro/kernels/dequantize.h" - #include "tensorflow/lite/micro/kernels/ethosu.h" - #include "tensorflow/lite/micro/kernels/fully_connected.h" - #include "tensorflow/lite/micro/kernels/micro_ops.h" -@@ -217,8 +218,9 @@ class MicroMutableOpResolver : public MicroOpResolver { - ParseDepthwiseConv2D); - } - -- TfLiteStatus AddDequantize() { -- return AddBuiltin(BuiltinOperator_DEQUANTIZE, tflite::Register_DEQUANTIZE(), -+ TfLiteStatus AddDequantize( -+ const TFLMRegistration& registration = Register_DEQUANTIZE()) { -+ return AddBuiltin(BuiltinOperator_DEQUANTIZE, registration, - ParseDequantize); - } - --- -2.25.1 - diff --git a/mlearning/tflite-micro/0002-quantize-int8.patch b/mlearning/tflite-micro/0002-quantize-int8.patch deleted file mode 100644 index 138eea987..000000000 --- a/mlearning/tflite-micro/0002-quantize-int8.patch +++ /dev/null @@ -1,108 +0,0 @@ -From b7c954c7594b9a39df5604dbadf6e59b6f98b1e9 Mon Sep 17 00:00:00 2001 -From: xinhaiteng -Date: Wed, 24 Apr 2024 09:18:52 +0800 -Subject: [PATCH] tflite: add quantize float32 to int8 operator - -VELAPLATFO-30990 - -Separate the 'Float32 to Int8' implementation of the 'quantize' operator to reduce the code size. - -Change-Id: I83dc809d36587741f3087b25e83e454b30f9626b -Signed-off-by: xinhaiteng ---- - tensorflow/lite/micro/kernels/quantize.cc | 5 +++++ - tensorflow/lite/micro/kernels/quantize.h | 4 ++++ - tensorflow/lite/micro/kernels/quantize_common.cc | 16 ++++++++++++++++ - .../lite/micro/micro_mutable_op_resolver.h | 7 ++++--- - 4 files changed, 29 insertions(+), 3 deletions(-) - -diff --git a/tensorflow/lite/micro/kernels/quantize.cc b/tensorflow/lite/micro/kernels/quantize.cc -index ba11f19b6..a6ff4f055 100644 ---- a/tensorflow/lite/micro/kernels/quantize.cc -+++ b/tensorflow/lite/micro/kernels/quantize.cc -@@ -39,4 +39,9 @@ TFLMRegistration Register_QUANTIZE() { - InitQuantizeReference, PrepareQuantizeReference, EvalQuantizeReference); - } - -+TFLMRegistration Register_QUANTIZE_FLOAT32_INT8() { -+ return tflite::micro::RegisterOp( -+ InitQuantizeReference, PrepareQuantizeReference, EvalQuantizeReferenceFloat32ToInt8); -+} -+ - } // namespace tflite -diff --git a/tensorflow/lite/micro/kernels/quantize.h b/tensorflow/lite/micro/kernels/quantize.h -index ba93809a2..b97e4a2ab 100644 ---- a/tensorflow/lite/micro/kernels/quantize.h -+++ b/tensorflow/lite/micro/kernels/quantize.h -@@ -17,6 +17,7 @@ limitations under the License. - - #include "tensorflow/lite/c/common.h" - #include "tensorflow/lite/kernels/internal/types.h" -+#include "tensorflow/lite/micro/micro_common.h" - - namespace tflite { - -@@ -31,7 +32,10 @@ struct OpDataQuantizeReference { - }; - - TfLiteStatus EvalQuantizeReference(TfLiteContext* context, TfLiteNode* node); -+TfLiteStatus EvalQuantizeReferenceFloat32ToInt8(TfLiteContext* context, TfLiteNode* node); - TfLiteStatus PrepareQuantizeReference(TfLiteContext* context, TfLiteNode* node); -+ -+TFLMRegistration Register_QUANTIZE_FLOAT32_INT8(); - } // namespace tflite - - #endif // TENSORFLOW_LITE_MICRO_KERNELS_QUANTIZE_H_ -diff --git a/tensorflow/lite/micro/kernels/quantize_common.cc b/tensorflow/lite/micro/kernels/quantize_common.cc -index cb04eafce..6bdd0df39 100644 ---- a/tensorflow/lite/micro/kernels/quantize_common.cc -+++ b/tensorflow/lite/micro/kernels/quantize_common.cc -@@ -236,4 +236,20 @@ TfLiteStatus EvalQuantizeReference(TfLiteContext* context, TfLiteNode* node) { - return kTfLiteOk; - } - -+TfLiteStatus EvalQuantizeReferenceFloat32ToInt8(TfLiteContext* context, TfLiteNode* node) { -+ TFLITE_DCHECK(node->user_data != nullptr); -+ auto* data = static_cast(node->user_data); -+ -+ const TfLiteEvalTensor* input = tflite::micro::GetEvalInput(context, node, 0); -+ TfLiteEvalTensor* output = tflite::micro::GetEvalOutput(context, node, 0); -+ -+ TFLITE_DCHECK(input->type == kTfLiteFloat32 && output->type == kTfLiteInt8); -+ reference_ops::AffineQuantize( -+ data->quantization_params, tflite::micro::GetTensorShape(input), -+ tflite::micro::GetTensorData(input), -+ tflite::micro::GetTensorShape(output), -+ tflite::micro::GetTensorData(output)); -+ return kTfLiteOk; -+} -+ - } // namespace tflite -diff --git a/tensorflow/lite/micro/micro_mutable_op_resolver.h b/tensorflow/lite/micro/micro_mutable_op_resolver.h -index b3e3cbcf8..ec8979c4e 100644 ---- a/tensorflow/lite/micro/micro_mutable_op_resolver.h -+++ b/tensorflow/lite/micro/micro_mutable_op_resolver.h -@@ -32,6 +32,7 @@ limitations under the License. - #include "tensorflow/lite/micro/kernels/micro_ops.h" - #include "tensorflow/lite/micro/kernels/mul.h" - #include "tensorflow/lite/micro/kernels/pooling.h" -+#include "tensorflow/lite/micro/kernels/quantize.h" - #include "tensorflow/lite/micro/kernels/reduce.h" - #include "tensorflow/lite/micro/kernels/softmax.h" - #include "tensorflow/lite/micro/kernels/transpose_conv.h" -@@ -481,9 +482,9 @@ class MicroMutableOpResolver : public MicroOpResolver { - ParsePrelu); - } - -- TfLiteStatus AddQuantize() { -- return AddBuiltin(BuiltinOperator_QUANTIZE, Register_QUANTIZE(), -- ParseQuantize); -+ TfLiteStatus AddQuantize( -+ const TFLMRegistration& registration = Register_QUANTIZE()) { -+ return AddBuiltin(BuiltinOperator_QUANTIZE, registration, ParseQuantize); - } - - TfLiteStatus AddReadVariable() { --- -2.25.1 - diff --git a/mlearning/tflite-micro/0003-mean-int8.patch b/mlearning/tflite-micro/0003-mean-int8.patch deleted file mode 100644 index de45afe8b..000000000 --- a/mlearning/tflite-micro/0003-mean-int8.patch +++ /dev/null @@ -1,112 +0,0 @@ -From 9507345939722d4bc2f2791394217680fc5c987b Mon Sep 17 00:00:00 2001 -From: xinhaiteng -Date: Wed, 24 Apr 2024 09:26:54 +0800 -Subject: [PATCH] tflite: add mean-int8 operator - -VELAPLATFO-30990 - -Separate the Int8 implementation of the 'mean' operator to reduce the code size. - -Change-Id: I5eb9e3cc939668b6531ef9e56f7c32090f1de141 -Signed-off-by: xinhaiteng ---- - tensorflow/lite/micro/kernels/reduce.cc | 9 +++++++++ - tensorflow/lite/micro/kernels/reduce.h | 3 +++ - tensorflow/lite/micro/kernels/reduce_common.cc | 16 ++++++++++++++++ - .../lite/micro/micro_mutable_op_resolver.h | 5 +++-- - 4 files changed, 31 insertions(+), 2 deletions(-) - -diff --git a/tensorflow/lite/micro/kernels/reduce.cc b/tensorflow/lite/micro/kernels/reduce.cc -index a689d3b93..090bafc3c 100644 ---- a/tensorflow/lite/micro/kernels/reduce.cc -+++ b/tensorflow/lite/micro/kernels/reduce.cc -@@ -49,6 +49,11 @@ TfLiteStatus EvalMean(TfLiteContext* context, TfLiteNode* node) { - static_cast(node->user_data)); - } - -+TfLiteStatus EvalMeanInt8(TfLiteContext* context, TfLiteNode* node) { -+ return EvalMeanHelperInt8(context, node, -+ static_cast(node->user_data)); -+} -+ - TfLiteStatus EvalMax(TfLiteContext* context, TfLiteNode* node) { - OpDataReduce* op_data = static_cast(node->user_data); - return EvalMaxHelper(context, node, op_data); -@@ -63,6 +68,10 @@ TFLMRegistration Register_MEAN() { - return tflite::micro::RegisterOp(InitReduce, PrepareMeanOrSum, EvalMean); - } - -+TFLMRegistration Register_MEAN_INT8() { -+ return tflite::micro::RegisterOp(InitReduce, PrepareMeanOrSum, EvalMeanInt8); -+} -+ - TFLMRegistration Register_REDUCE_MAX() { - return tflite::micro::RegisterOp(InitReduce, PrepareMax, EvalMax); - } -diff --git a/tensorflow/lite/micro/kernels/reduce.h b/tensorflow/lite/micro/kernels/reduce.h -index 2daeef5fe..0e29b3af8 100644 ---- a/tensorflow/lite/micro/kernels/reduce.h -+++ b/tensorflow/lite/micro/kernels/reduce.h -@@ -50,6 +50,8 @@ TfLiteStatus EvalMaxHelper(TfLiteContext* context, TfLiteNode* node, - OpDataReduce* op_data); - TfLiteStatus EvalMeanHelper(TfLiteContext* context, TfLiteNode* node, - OpDataReduce* op_data); -+TfLiteStatus EvalMeanHelperInt8(TfLiteContext* context, TfLiteNode* node, -+ OpDataReduce* op_data); - TfLiteStatus EvalSumHelper(TfLiteContext* context, TfLiteNode* node, - OpDataReduce* op_data); - -@@ -57,6 +59,7 @@ void ReduceResolveAxis(const int* axis_data, int axis_count, - MeanParams* op_params); - - TFLMRegistration Register_MEAN(); -+TFLMRegistration Register_MEAN_INT8(); - TFLMRegistration Register_REDUCE_MAX(); - TFLMRegistration Register_SUM(); - -diff --git a/tensorflow/lite/micro/kernels/reduce_common.cc b/tensorflow/lite/micro/kernels/reduce_common.cc -index 2c1a92a50..6e4ab1cc9 100644 ---- a/tensorflow/lite/micro/kernels/reduce_common.cc -+++ b/tensorflow/lite/micro/kernels/reduce_common.cc -@@ -236,6 +236,22 @@ TfLiteStatus EvalMeanHelper(TfLiteContext* context, TfLiteNode* node, - return kTfLiteOk; - } - -+TfLiteStatus EvalMeanHelperInt8(TfLiteContext* context, TfLiteNode* node, -+ OpDataReduce* op_data) { -+ const TfLiteEvalTensor* input = tflite::micro::GetEvalInput(context, node, 0); -+ const TfLiteEvalTensor* axis = tflite::micro::GetEvalInput(context, node, 1); -+ -+ int num_axis = static_cast(ElementCount(*axis->dims)); -+ int temp_index[kMaxNumberOfAxis]; -+ int resolved_axis[kMaxNumberOfReducedAxis]; -+ -+ TFLITE_DCHECK(input->type == kTfLiteInt8); -+ TF_LITE_ENSURE_OK( -+ context, EvalIntegerMean(context, node, num_axis, op_data, -+ temp_index, resolved_axis)); -+ return kTfLiteOk; -+} -+ - TfLiteStatus EvalMaxHelper(TfLiteContext* context, TfLiteNode* node, - OpDataReduce* op_data) { - const TfLiteEvalTensor* input = tflite::micro::GetEvalInput(context, node, 0); -diff --git a/tensorflow/lite/micro/micro_mutable_op_resolver.h b/tensorflow/lite/micro/micro_mutable_op_resolver.h -index ec8979c4e..253f83de1 100644 ---- a/tensorflow/lite/micro/micro_mutable_op_resolver.h -+++ b/tensorflow/lite/micro/micro_mutable_op_resolver.h -@@ -432,8 +432,9 @@ class MicroMutableOpResolver : public MicroOpResolver { - ParseMirrorPad); - } - -- TfLiteStatus AddMean() { -- return AddBuiltin(BuiltinOperator_MEAN, Register_MEAN(), ParseReducer); -+ TfLiteStatus AddMean( -+ const TFLMRegistration& registration = Register_MEAN()) { -+ return AddBuiltin(BuiltinOperator_MEAN, registration, ParseReducer); - } - - TfLiteStatus AddMinimum() { --- -2.25.1 - diff --git a/mlearning/tflite-micro/0004-tflite-add-extern-C-to-main-function-to-avoid-c-mang.patch b/mlearning/tflite-micro/0004-tflite-add-extern-C-to-main-function-to-avoid-c-mang.patch deleted file mode 100644 index 84f0bc028..000000000 --- a/mlearning/tflite-micro/0004-tflite-add-extern-C-to-main-function-to-avoid-c-mang.patch +++ /dev/null @@ -1,26 +0,0 @@ -From 971d7129e14c012bb10215cbc7370c3176490617 Mon Sep 17 00:00:00 2001 -From: chao an -Date: Mon, 2 Dec 2024 10:23:12 +0800 -Subject: [PATCH] tflite: add extern "C" to main function to avoid c++ mangling - -Signed-off-by: chao an ---- - tensorflow/lite/micro/examples/hello_world/hello_world_test.cc | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/tensorflow/lite/micro/examples/hello_world/hello_world_test.cc b/tensorflow/lite/micro/examples/hello_world/hello_world_test.cc -index ec23571a..24982e90 100644 ---- a/tensorflow/lite/micro/examples/hello_world/hello_world_test.cc -+++ b/tensorflow/lite/micro/examples/hello_world/hello_world_test.cc -@@ -149,7 +149,7 @@ TfLiteStatus LoadQuantModelAndPerformInference() { - return kTfLiteOk; - } - --int main(int argc, char* argv[]) { -+extern "C" int main(int argc, char* argv[]) { - tflite::InitializeTarget(); - TF_LITE_ENSURE_STATUS(ProfileMemoryAndLatency()); - TF_LITE_ENSURE_STATUS(LoadFloatModelAndPerformInference()); --- -2.34.1 - diff --git a/mlearning/tflite-micro/CMakeLists.txt b/mlearning/tflite-micro/CMakeLists.txt deleted file mode 100644 index e3a2830d1..000000000 --- a/mlearning/tflite-micro/CMakeLists.txt +++ /dev/null @@ -1,252 +0,0 @@ -# ############################################################################## -# apps/mlearning/tflite-micro/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_TFLITEMICRO) - - # ############################################################################ - # Config and Fetch TFLITE-MICRO - # ############################################################################ - - set(TFLITE_MICRO_DIR ${CMAKE_CURRENT_LIST_DIR}/tflite-micro) - - if(NOT EXISTS ${TFLITE_MICRO_DIR}) - set(TFLITE_MICRO_URL - https://github.com/tensorflow/tflite-micro/archive/cfa4c91d1b36c37c7c104b9c664615e59f1abfe3.zip - ) - FetchContent_Declare( - tflite_micro_fetch - URL ${TFLITE_MICRO_URL} SOURCE_DIR ${TFLITE_MICRO_DIR} BINARY_DIR - ${CMAKE_BINARY_DIR}/apps/mlearning/tflite-micro/tflite-micro - PATCH_COMMAND - patch -d ${TFLITE_MICRO_DIR} -p1 < - ${CMAKE_CURRENT_LIST_DIR}/tflite-micro.patch && patch -d - ${TFLITE_MICRO_DIR} -p1 < - ${CMAKE_CURRENT_LIST_DIR}/0001-dequantize-int8.patch && patch -d - ${TFLITE_MICRO_DIR} -p1 < - ${CMAKE_CURRENT_LIST_DIR}/0002-quantize-int8.patch && patch -d - ${TFLITE_MICRO_DIR} -p1 < ${CMAKE_CURRENT_LIST_DIR}/0003-mean-int8.patch - && patch -d ${TFLITE_MICRO_DIR} -p1 < - ${CMAKE_CURRENT_LIST_DIR}/0004-tflite-add-extern-C-to-main-function-to-avoid-c-mang.patch - DOWNLOAD_NO_PROGRESS true - TIMEOUT 30) - - FetchContent_GetProperties(tflite_micro_fetch) - - if(NOT tflite_micro_fetch_POPULATED) - FetchContent_Populate(tflite_micro_fetch) - endif() - endif() - - # ############################################################################ - # Flags - # ############################################################################ - - set(COMMON_FLAGS - -DTF_LITE_STATIC_MEMORY - -DTF_LITE_DISABLE_X86_NEON - -Wno-sign-compare - -Wno-unused-variable - -Wno-undef - -Wno-shadow - -O3) - - if(CONFIG_MLEARNING_CMSIS_NN) - list(APPEND COMMON_FLAGS -DCMSIS_NN) - endif() - - if(CONFIG_TFLITEMICRO_DEBUG) - list(APPEND COMMON_FLAGS -DTF_LITE_SHOW_MEMORY_USE) - list(APPEND COMMON_FLAGS -DTF_LITE_USE_CTIME) - else() - list(APPEND COMMON_FLAGS -DTF_LITE_STRIP_ERROR_STRINGS) - endif() - - # ############################################################################ - # Sources - # ############################################################################ - - file( - GLOB - TFLITE_MICRO_SRCS - ${TFLITE_MICRO_DIR}/tensorflow/lite/micro/kernels/*.cc - ${TFLITE_MICRO_DIR}/tensorflow/lite/c/*.cc - ${TFLITE_MICRO_DIR}/tensorflow/lite/schema/*.cc - ${TFLITE_MICRO_DIR}/tensorflow/lite/core/c/*.cc - ${TFLITE_MICRO_DIR}/tensorflow/lite/kernels/*.cc - ${TFLITE_MICRO_DIR}/tensorflow/lite/kernels/internal/optimized/*.cc - ${TFLITE_MICRO_DIR}/tensorflow/lite/kernels/internal/reference/*.cc - ${TFLITE_MICRO_DIR}/tensorflow/lite/kernels/internal/*.cc - ${TFLITE_MICRO_DIR}/tensorflow/lite/core/api/*.cc - ${TFLITE_MICRO_DIR}/tensorflow/lite/micro/arena_allocator/*.cc - ${TFLITE_MICRO_DIR}/tensorflow/lite/micro/memory_planner/*.cc - ${TFLITE_MICRO_DIR}/tensorflow/lite/micro/*.cc - ${TFLITE_MICRO_DIR}/tensorflow/lite/micro/tflite_bridge/*.cc) - - # Remove test file - list(FILTER TFLITE_MICRO_SRCS EXCLUDE REGEX ".*test.cc") - if(CONFIG_TFLITEMICRO_SYSLOG) - list(FILTER TFLITE_MICRO_SRCS EXCLUDE REGEX "micro_log.cc") - list(APPEND TFLITE_MICRO_SRCS ${CMAKE_CURRENT_LIST_DIR}/tflm_syslog.cc) - endif() - - if(CONFIG_MLEARNING_CMSIS_NN) - list(APPEND COMMON_FLAGS -DCMSIS_NN) - - file(GLOB CMSIS_NN_SRCS - ${TFLITE_MICRO_DIR}/tensorflow/lite/micro/kernels/cmsis_nn/*.cc) - - # Remove the directory and get only filename - set(CMSIS_NN_FILENAMES) - foreach(file ${CMSIS_NN_SRCS}) - get_filename_component(filename ${file} NAME) - list(APPEND CMSIS_NN_FILENAMES ${filename}) - endforeach() - - # Remove files with the same filename without the directory - set(NEW_TFLITE_MICRO_SRCS) - foreach(file ${TFLITE_MICRO_SRCS}) - get_filename_component(filename ${file} NAME) - if(NOT filename IN_LIST CMSIS_NN_FILENAMES) - list(APPEND NEW_TFLITE_MICRO_SRCS ${file}) - endif() - endforeach() - - # ๆทปๅŠ CMSIS_NNๆ–‡ไปถ - list(APPEND NEW_TFLITE_MICRO_SRCS ${CMSIS_NN_SRCS}) - set(TFLITE_MICRO_SRCS ${NEW_TFLITE_MICRO_SRCS}) - - if(CONFIG_ARM_NEON) - list( - APPEND - TFLITE_MICRO_SRCS - ${CMAKE_CURRENT_LIST_DIR}/operators/neon/arm_convolve_s8.c - ${CMAKE_CURRENT_LIST_DIR}/operators/neon/arm_nn_mat_mult_kernel_s8_s16.c - ${CMAKE_CURRENT_LIST_DIR}/operators/neon/arm_q7_to_q15_with_offset.c - ${CMAKE_CURRENT_LIST_DIR}/operators/neon/arm_elementwise_add_s8.c) - endif() - endif() - - # ############################################################################ - # Include Directory - # ############################################################################ - - set(INCDIR - ${NUTTX_APPS_DIR}/math/gemmlowp/gemmlowp - ${NUTTX_APPS_DIR}/math/ruy/ruy - ${NUTTX_APPS_DIR}/math/kissfft/kissfft - ${NUTTX_APPS_DIR}/math/kissfft/kissfft - ${NUTTX_APPS_DIR}/mlearning/tflite-micro/tflite-micro - ${NUTTX_APPS_DIR}/system/flatbuffers/flatbuffers/include) - - if(CONFIG_MLEARNING_CMSIS_NN) - list(APPEND INCDIR ${NUTTX_APPS_DIR}/mlearning/cmsis-nn/cmsis-nn) - list(APPEND INCDIR ${NUTTX_APPS_DIR}/mlearning/cmsis-nn/cmsis-nn/Include) - endif() - - # ############################################################################ - # Library Configuration - # ############################################################################ - - nuttx_add_library(tflite_micro STATIC) - target_compile_options(tflite_micro PRIVATE ${COMMON_FLAGS}) - target_sources(tflite_micro PRIVATE ${TFLITE_MICRO_SRCS}) - target_include_directories(tflite_micro PUBLIC ${INCDIR}) - - # Help function to generate tflite data - # - # TFLM is designed to run on microcontrollers and other platforms without - # dynamic memory allocation and without filesystems. This means that data - # files such as TFLite models and test inputs must be built into the binary. - # - # Historically, data files have been included as cc arrays generated manually - # using `xxd -i ` - - function(tflite_generate_data in out declare) - set(tflm_data_out - ${CMAKE_BINARY_DIR}/apps/mlearning/tflite-micro/tflite-micro/${out}) - if(NOT EXISTS ${tflm_data_out}) - get_filename_component(TFLM_OUT ${tflm_data_out} DIRECTORY) - if(NOT EXISTS ${TFLM_OUT}) - file(MAKE_DIRECTORY ${TFLM_OUT}) - endif() - execute_process(COMMAND xxd -i ${TFLITE_MICRO_DIR}/${in} ${tflm_data_out}) - - # Replace array name - - string(REGEX REPLACE "([/|.])" "_" tflm_data_define - ${TFLITE_MICRO_DIR}/${in}) - string(REPLACE "-" "_" _tflm_data_define ${tflm_data_define}) - file(READ ${tflm_data_out} tflm_contents) - encode_brackets(tflm_contents) - encode_semicolon(tflm_contents) - string(REPLACE ${_tflm_data_define} ${declare} tflm_contents - ${tflm_contents}) - decode_semicolon(tflm_contents) - decode_brackets(tflm_contents) - file(WRITE ${tflm_data_out} "${tflm_contents}") - - endif() - endfunction() - - if(CONFIG_TFLITEMICRO_TOOL) - nuttx_add_application( - NAME - tflm - STACKSIZE - ${CONFIG_TFLITEMICRO_TOOL_STACKSIZE} - PRIORITY - ${CONFIG_TFLITEMICRO_TOOL_PRIORITY} - SRCS - ${CMAKE_CURRENT_LIST_DIR}/tflm_tool.cc - INCLUDE_DIRECTORIES - ${INCDIR} - COMPILE_FLAGS - ${COMMON_FLAGS}) - endif() - - if(CONFIG_TFLITEMICRO_HELLOWORLD) - tflite_generate_data( - tensorflow/lite/micro/examples/hello_world/models/hello_world_float.tflite - tensorflow/lite/micro/examples/hello_world/models/hello_world_float_model_data.h - g_hello_world_float_model_data) - tflite_generate_data( - tensorflow/lite/micro/examples/hello_world/models/hello_world_int8.tflite - tensorflow/lite/micro/examples/hello_world/models/hello_world_int8_model_data.h - g_hello_world_int8_model_data) - - nuttx_add_application( - NAME - tflm_hello - STACKSIZE - ${CONFIG_TFLITEMICRO_HELLOWORLD_STACKSIZE} - PRIORITY - ${CONFIG_TFLITEMICRO_HELLOWORLD_PRIORITY} - SRCS - ${TFLITE_MICRO_DIR}/tensorflow/lite/micro/examples/hello_world/hello_world_test.cc - INCLUDE_DIRECTORIES - ${INCDIR} - ${CMAKE_BINARY_DIR}/apps/mlearning/tflite-micro/tflite-micro - COMPILE_FLAGS - ${COMMON_FLAGS}) - endif() - -endif() diff --git a/mlearning/tflite-micro/Kconfig b/mlearning/tflite-micro/Kconfig deleted file mode 100644 index 359ea5819..000000000 --- a/mlearning/tflite-micro/Kconfig +++ /dev/null @@ -1,84 +0,0 @@ -############################################################################ -# apps/mlearning/tflite-micro/Kconfig -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -config TFLITEMICRO - bool "TFLiteMicro" - default n - depends on SYSTEM_FLATBUFFERS && MATH_GEMMLOWP && MATH_KISSFFT && MATH_RUY - -if TFLITEMICRO -config TFLITEMICRO_DEBUG - bool "Print tflite-micro's debug message" - default n - -config TFLITEMICRO_TOOL - bool "tflite-micro cmdline tool" - default n - -config TFLITEMICRO_SYSLOG - bool "tflite-micro syslog backend" - default n - -if TFLITEMICRO_SYSLOG - -config TFLITEMICRO_SYSLOG_LEVEL - int "tflite-micro syslog level" - default 6 - ---help--- - Syslog level mapping of tflm, This log level mapping is consistent - with the nuttx syslog level, please refer to syslog.h: - - define LOG_EMERG 0 /* System is unusable */ - define LOG_ALERT 1 /* Action must be taken immediately */ - define LOG_CRIT 2 /* Critical conditions */ - define LOG_ERR 3 /* Error conditions */ - define LOG_WARNING 4 /* Warning conditions */ - define LOG_NOTICE 5 /* Normal, but significant, condition */ - define LOG_INFO 6 /* Informational message */ - define LOG_DEBUG 7 /* Debug-level message */ - -endif # TFLITEMICRO_SYSLOG - -if TFLITEMICRO_TOOL -config TFLITEMICRO_TOOL_PRIORITY - int "tflite-micro tool priority" - default 100 - -config TFLITEMICRO_TOOL_STACKSIZE - int "tflite-micro tool stacksize" - default 4096 - -endif # TFLITEMICRO_TOOL - -config TFLITEMICRO_HELLOWORLD - bool "Enable Tflite-micro hello world example" - default n - -if TFLITEMICRO_HELLOWORLD -config TFLITEMICRO_HELLOWORLD_PRIORITY - int "Tflite-micro hello world priority" - default 100 - -config TFLITEMICRO_HELLOWORLD_STACKSIZE - int "Tflite-micro hello world stacksize" - default 4096 - -endif # TFLITEMICRO_HELLOWORLD -endif # TFLITEMICRO diff --git a/mlearning/tflite-micro/Make.defs b/mlearning/tflite-micro/Make.defs deleted file mode 100644 index 2148d663b..000000000 --- a/mlearning/tflite-micro/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/mlearning/tflite-micro/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_TFLITEMICRO),) -CONFIGURED_APPS += $(APPDIR)/mlearning/tflite-micro -endif diff --git a/mlearning/tflite-micro/Makefile b/mlearning/tflite-micro/Makefile deleted file mode 100644 index aba043805..000000000 --- a/mlearning/tflite-micro/Makefile +++ /dev/null @@ -1,119 +0,0 @@ -############################################################################ -# apps/mlearning/tflite-micro/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -CSRCS := -CXXEXT := .cc -CXXSRCS := -COMMON_FLAGS := -TFLM_UNPACK := tflite-micro -TFLM_VER := cfa4c91d1b36c37c7c104b9c664615e59f1abfe3 -TFLM_DIR := $(APPDIR)/mlearning/tflite-micro/$(TFLM_UNPACK) - -tflite-micro.zip: - $(Q) curl -L https://github.com/tensorflow/tflite-micro/archive/$(TFLM_VER).zip -o tflite-micro.zip - $(Q) unzip -o tflite-micro.zip - $(Q) mv tflite-micro-$(TFLM_VER) $(TFLM_UNPACK) - $(Q) patch -d $(TFLM_UNPACK) -p1 < tflite-micro.patch - $(Q) patch -d $(TFLM_UNPACK) -p1 < 0001-dequantize-int8.patch - $(Q) patch -d $(TFLM_UNPACK) -p1 < 0002-quantize-int8.patch - $(Q) patch -d $(TFLM_UNPACK) -p1 < 0003-mean-int8.patch - -# Download and unpack tarball if no git repo found -ifeq ($(wildcard $(TFLM_UNPACK)/.git),) -context:: tflite-micro.zip -distclean:: - $(call DELDIR, $(TFLM_UNPACK)) - $(call DELFILE, tflite-micro.zip) -endif - -COMMON_FLAGS += ${INCDIR_PREFIX}$(TFLM_DIR) -COMMON_FLAGS += ${INCDIR_PREFIX}$(APPDIR)/math/gemmlowp/gemmlowp -COMMON_FLAGS += ${INCDIR_PREFIX}$(APPDIR)/math/kissfft/kissfft -COMMON_FLAGS += ${INCDIR_PREFIX}$(APPDIR)/math/ruy/ruy -COMMON_FLAGS += -Wno-shadow -COMMON_FLAGS += -Wno-sign-compare -COMMON_FLAGS += -Wno-undef -COMMON_FLAGS += -Wno-unused-variable -COMMON_FLAGS += -DTFLITE_EMULATE_FLOAT -COMMON_FLAGS += -DTF_LITE_DISABLE_X86_NEON -ifneq ($(CONFIG_TFLITEMICRO_DEBUG),) -COMMON_FLAGS += -DTF_LITE_SHOW_MEMORY_USE -COMMON_FLAGS += -DTF_LITE_USE_CTIME -else -COMMON_FLAGS += -DTF_LITE_STRIP_ERROR_STRINGS -endif - -# tflite micro -CXXSRCS += $(wildcard $(TFLM_DIR)/tensorflow/lite/c/*.cc) -CXXSRCS += $(wildcard $(TFLM_DIR)/tensorflow/lite/core/c/*.cc) -CXXSRCS += $(wildcard $(TFLM_DIR)/tensorflow/lite/core/api/*.cc) -CXXSRCS += $(wildcard $(TFLM_DIR)/tensorflow/lite/kernels/*.cc) -CXXSRCS += $(wildcard $(TFLM_DIR)/tensorflow/lite/kernels/internal/*.cc) -CXXSRCS += $(wildcard $(TFLM_DIR)/tensorflow/lite/kernels/internal/optimized/*.cc) -CXXSRCS += $(wildcard $(TFLM_DIR)/tensorflow/lite/kernels/internal/reference/*.cc) -CXXSRCS += $(wildcard $(TFLM_DIR)/tensorflow/lite/micro/*.cc) -CXXSRCS += $(wildcard $(TFLM_DIR)/tensorflow/lite/micro/arena_allocator/*.cc) -CXXSRCS += $(wildcard $(TFLM_DIR)/tensorflow/lite/micro/kernels/*.cc) -CXXSRCS += $(wildcard $(TFLM_DIR)/tensorflow/lite/micro/memory_planner/*.cc) -CXXSRCS += $(wildcard $(TFLM_DIR)/tensorflow/lite/micro/tflite_bridge/*.cc) -CXXSRCS += $(wildcard $(TFLM_DIR)/tensorflow/lite/schema/*.cc) -CXXSRCS := $(filter-out %test.cc, $(CXXSRCS)) - -ifneq ($(CONFIG_TFLITEMICRO_SYSLOG),) - CXXSRCS := $(filter-out %micro_log.cc, $(CXXSRCS)) - CXXSRCS += $(wildcard $(CURDIR)/tflm_syslog.cc) -endif - -# cmsis -ifneq ($(CONFIG_MLEARNING_CMSIS_NN),) -COMMON_FLAGS += -DCMSIS_NN -COMMON_FLAGS += ${INCDIR_PREFIX}$(APPDIR)/mlearning/cmsis-nn/cmsis-nn - -CMSIS_NN_SRCS := $(wildcard $(TFLM_DIR)/tensorflow/lite/micro/kernels/cmsis_nn/*.cc) -UNNEEDED_SRCS := $(addprefix $(TFLM_DIR)/tensorflow/lite/micro/kernels/, $(notdir $(CMSIS_NN_SRCS))) -CXXSRCS := $(filter-out $(UNNEEDED_SRCS), $(CXXSRCS)) -CXXSRCS += $(CMSIS_NN_SRCS) - -ifneq ($(CONFIG_ARM_NEON),) -CSRCS += operators/neon/arm_convolve_s8.c -CSRCS += operators/neon/arm_nn_mat_mult_kernel_s8_s16.c -CSRCS += operators/neon/arm_q7_to_q15_with_offset.c -CSRCS += operators/neon/arm_elementwise_add_s8.c -endif -endif - -# extra hardware support. --include $(TFLM_DIR)/tensorflow/lite/micro/nuttx/Makefile - -ifneq ($(CONFIG_TFLITEMICRO_TOOL),) -MAINSRC = tflm_tool.cc -PROGNAME = tflm -PRIORITY = $(CONFIG_TFLITEMICRO_TOOL_PRIORITY) -STACKSIZE = $(CONFIG_TFLITEMICRO_TOOL_STACKSIZE) -endif - -CFLAGS += ${COMMON_FLAGS} -CXXFLAGS += ${COMMON_FLAGS} - -include $(APPDIR)/Application.mk diff --git a/mlearning/tflite-micro/operators/neon/arm_convolve_s8.c b/mlearning/tflite-micro/operators/neon/arm_convolve_s8.c deleted file mode 100644 index 64a3150e1..000000000 --- a/mlearning/tflite-micro/operators/neon/arm_convolve_s8.c +++ /dev/null @@ -1,225 +0,0 @@ -/**************************************************************************** - * apps/mlearning/tflite-micro/operators/neon/arm_convolve_s8.c - * - * SPDX-License-Identifier: Apache-2.0 - * SPDX-FileCopyrightText: 2010-2023 Arm Limited and/or its affiliates - * - * - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include "arm_nnfunctions.h" -#include "arm_nnsupportfunctions.h" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/* Basic s8 convolution function. - * - * Refer header file for details. Optimal use case for the DSP/MVE - * implementation is when input and output channels are multiples of 4 or - * atleast greater than 4. - */ - -arm_cmsis_nn_status -arm_convolve_s8(const cmsis_nn_context *ctx, - const cmsis_nn_conv_params *conv_params, - const cmsis_nn_per_channel_quant_params *quant_params, - const cmsis_nn_dims *input_dims, - const int8_t *input_data, - const cmsis_nn_dims *filter_dims, - const int8_t *filter_data, - const cmsis_nn_dims *bias_dims, - const int32_t *bias_data, - const cmsis_nn_dims *output_dims, - int8_t *output_data) -{ - (void)bias_dims; - - if (ctx->buf == NULL) - { - return ARM_CMSIS_NN_ARG_ERROR; - } - - int16_t *buffer_a = (int16_t *)ctx->buf; - - const int32_t input_batches = input_dims->n; - const uint16_t input_x = input_dims->w; - const uint16_t input_y = input_dims->h; - const uint16_t input_ch = input_dims->c; - const uint16_t kernel_x = filter_dims->w; - const uint16_t kernel_y = filter_dims->h; - const uint16_t output_x = output_dims->w; - const uint16_t output_y = output_dims->h; - const uint16_t output_ch = output_dims->c; - - const uint16_t pad_x = conv_params->padding.w; - const uint16_t pad_y = conv_params->padding.h; - const uint16_t stride_x = conv_params->stride.w; - const uint16_t stride_y = conv_params->stride.h; - const int32_t dilation_x = conv_params->dilation.w; - const int32_t dilation_y = conv_params->dilation.h; - const int32_t out_offset = conv_params->output_offset; - const int32_t out_activation_min = conv_params->activation.min; - const int32_t out_activation_max = conv_params->activation.max; - const int32_t rhs_cols = kernel_x * kernel_y * input_ch; - const int32_t input_offset = conv_params->input_offset; - - int32_t *output_mult = quant_params->multiplier; - int32_t *output_shift = quant_params->shift; - - int i_batch; - for (i_batch = 0; i_batch < input_batches; i_batch++) - { - const int32_t remainder = rhs_cols % 4; - const int32_t aligned_rhs_cols = remainder != 0 ? - rhs_cols + 4 - remainder : rhs_cols; - - /** - * Use Im2col to speed up conv2d calculations. - * Use as a ping-pong buffer for unordered elements. - */ - - int8_t *im2col_buf = (int8_t *)buffer_a + aligned_rhs_cols * 2; - int16_t *im2col_buf_start_s16 = buffer_a; - int8_t *out = output_data; - int32_t lhs_rows = 0; - - /* This part implements the im2col function */ - - for (int i_out_x = 0; i_out_x < output_x; i_out_x++) - { - const int32_t base_idx_x = stride_x * i_out_x - pad_x; - for (int i_out_y = 0; i_out_y < output_y; i_out_y++) - { - const int32_t base_idx_y = stride_y * i_out_y - pad_y; - for (int32_t i_ker_x = 0; i_ker_x < kernel_x; i_ker_x++) - { - int32_t k_x = base_idx_x + dilation_x * i_ker_x; - int32_t k_y = base_idx_y - dilation_y; - for (int32_t i_ker_y = 0; i_ker_y < kernel_y; i_ker_y++) - { - k_y += dilation_y; - arm_memcpy_s8(im2col_buf, - input_data + (k_y * input_x + k_x) * input_ch, - input_ch); - im2col_buf += input_ch; - } - } - - lhs_rows++; - - /* Extend the input data from int8 to int16, and add offset. */ - - arm_q7_to_q15_with_offset(im2col_buf - rhs_cols, - im2col_buf_start_s16, - rhs_cols, - (int16_t)input_offset); - im2col_buf_start_s16 += aligned_rhs_cols; - if (lhs_rows & 2) - { - out = arm_nn_mat_mult_kernel_s8_s16(filter_data, - buffer_a, - output_ch, - output_shift, - output_mult, - out_offset, - out_activation_min, - out_activation_max, - rhs_cols, - aligned_rhs_cols, - bias_data, - out); - - /* counter reset */ - - im2col_buf_start_s16 = buffer_a; - im2col_buf = (int8_t *)buffer_a + (aligned_rhs_cols << 1); - lhs_rows = 0; - } - } - } - - if (lhs_rows != 0) - { - const int8_t *ker_a = filter_data; - int i; - - for (i = 0; i < output_ch; i++) - { - /* Load the accumulator with bias first */ - - uint16_t col_count = rhs_cols / 8; - int32_t sum = 0; - const int16_t *ip_as_col = buffer_a; - int32x4_t res_s32 = vdupq_n_s32(0); - if (bias_data) - { - sum = bias_data[i]; - } - - while (col_count) - { - int8x8_t filter_s8 = vld1_s8(ker_a); - int16x8_t input_s16 = vld1q_s16(ip_as_col); - int16x8_t filter_s16 = vmovl_s8(filter_s8); - ker_a += 8; - ip_as_col += 8; - res_s32 = vmlal_s16(res_s32, - vget_low_s16(input_s16), - vget_low_s16(filter_s16)); - res_s32 = vmlal_s16(res_s32, - vget_high_s16(input_s16), - vget_high_s16(filter_s16)); - col_count--; - } - - sum += vgetq_lane_s32(res_s32, 0); - sum += vgetq_lane_s32(res_s32, 1); - sum += vgetq_lane_s32(res_s32, 2); - sum += vgetq_lane_s32(res_s32, 3); - col_count = rhs_cols % 8; - while (col_count) - { - int8_t ker_a1 = *ker_a++; - int16_t ip_b1 = *ip_as_col++; - sum += ker_a1 * ip_b1; - col_count--; - } - - sum = arm_nn_requantize(sum, - output_mult[i], output_shift[i]); - sum += out_offset; - sum = MAX(sum, out_activation_min); - sum = MIN(sum, out_activation_max); - *out++ = (int8_t)sum; - } - } - - /* Advance to the next batch */ - - input_data += (input_x * input_y * input_ch); - output_data += (output_x * output_y * output_ch); - } - - /* Return to application */ - - return ARM_CMSIS_NN_SUCCESS; -} - diff --git a/mlearning/tflite-micro/operators/neon/arm_elementwise_add_s8.c b/mlearning/tflite-micro/operators/neon/arm_elementwise_add_s8.c deleted file mode 100644 index 82718f94b..000000000 --- a/mlearning/tflite-micro/operators/neon/arm_elementwise_add_s8.c +++ /dev/null @@ -1,172 +0,0 @@ -/**************************************************************************** - * apps/mlearning/tflite-micro/operators/neon/arm_elementwise_add_s8.c - * - * SPDX-License-Identifier: Apache-2.0 - * SPDX-FileCopyrightText: 2010-2023 Arm Limited and/or its affiliates - * - * - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include "arm_nnfunctions.h" -#include "arm_nnsupportfunctions.h" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/* Note: __SHIFT is expected to be <=0 */ - -__STATIC_FORCEINLINE int32x4_t -arm_requantize_neon(const int32x4_t val, - const int32_t multiplier, - const int32_t shift) -{ - int32x4_t dividend = vqrdmulhq_n_s32( - vshlq_s32(val, vdupq_n_s32(LEFT_SHIFT(shift))), multiplier); - int32_t exponent = RIGHT_SHIFT(shift); - int32x4_t shift__ = vdupq_n_s32(-exponent); - int32x4_t fixup__ = vshrq_n_s32(vandq_s32(dividend, shift__), 31); - int32x4_t fixed_up_dividend = vqaddq_s32(dividend, fixup__); - return vrshlq_s32(fixed_up_dividend, shift__); -} - -arm_cmsis_nn_status -arm_elementwise_add_s8(const int8_t *input_1_vect, - const int8_t *input_2_vect, - const int32_t input_1_offset, - const int32_t input_1_mult, - const int32_t input_1_shift, - const int32_t input_2_offset, - const int32_t input_2_mult, - const int32_t input_2_shift, - const int32_t left_shift, - int8_t *output, - const int32_t out_offset, - const int32_t out_mult, - const int32_t out_shift, - const int32_t out_activation_min, - const int32_t out_activation_max, - const int32_t block_size) -{ - int32_t loop_count = block_size / 8; - const int8_t *input_1 = input_1_vect; - const int8_t *input_2 = input_2_vect; - int8_t *output_ = output; - - while (loop_count) - { - int8x8_t res; - int8x8_t input_1_s8; - int8x8_t input_2_s8; - int16x8_t i1_val_16; - int16x8_t input_1_s16; - int16x8_t input_2_s16; - int32x4_t input_1_s16_low; - int32x4_t input_1_s16_high; - int32x4_t input_2_s16_low; - int32x4_t input_2_s16_high; - - input_1_s8 = vld1_s8(input_1); - input_2_s8 = vld1_s8(input_2); - input_1_s16 = vmovl_s8(input_1_s8); - input_2_s16 = vmovl_s8(input_2_s8); - input_1 += 8; - input_2 += 8; - - input_1_s16_low = vaddw_s16( - vdupq_n_s32(input_1_offset), vget_low_s16(input_1_s16)); - input_1_s16_high = vaddw_s16( - vdupq_n_s32(input_1_offset), vget_high_s16(input_1_s16)); - input_2_s16_low = vaddw_s16( - vdupq_n_s32(input_2_offset), vget_low_s16(input_2_s16)); - input_2_s16_high = vaddw_s16( - vdupq_n_s32(input_2_offset), vget_high_s16(input_2_s16)); - - input_1_s16_low = vshlq_s32( - input_1_s16_low, vdupq_n_s32(left_shift)); - input_2_s16_low = vshlq_s32( - input_2_s16_low, vdupq_n_s32(left_shift)); - input_1_s16_high = vshlq_s32( - input_1_s16_high, vdupq_n_s32(left_shift)); - input_2_s16_high = vshlq_s32( - input_2_s16_high, vdupq_n_s32(left_shift)); - - input_1_s16_low = arm_requantize_neon( - input_1_s16_low, input_1_mult, input_1_shift); - input_1_s16_high = arm_requantize_neon( - input_1_s16_high, input_1_mult, input_1_shift); - input_2_s16_low = arm_requantize_neon( - input_2_s16_low, input_2_mult, input_2_shift); - input_2_s16_high = arm_requantize_neon( - input_2_s16_high, input_2_mult, input_2_shift); - - input_1_s16_low = vaddq_s32( - input_1_s16_low, input_2_s16_low); - input_1_s16_high = vaddq_s32( - input_1_s16_high, input_2_s16_high); - - input_1_s16_low = arm_requantize_neon( - input_1_s16_low, out_mult, out_shift); - input_1_s16_high = arm_requantize_neon( - input_1_s16_high, out_mult, out_shift); - - input_1_s16_low = vaddq_s32( - input_1_s16_low, vdupq_n_s32(out_offset)); - input_1_s16_high = vaddq_s32( - input_1_s16_high, vdupq_n_s32(out_offset)); - - input_1_s16_low = vmaxq_s32( - input_1_s16_low, vdupq_n_s32(out_activation_min)); - input_1_s16_high = vmaxq_s32( - input_1_s16_high, vdupq_n_s32(out_activation_min)); - input_1_s16_low = vminq_s32( - input_1_s16_low, vdupq_n_s32(out_activation_max)); - input_1_s16_high = vminq_s32( - input_1_s16_high, vdupq_n_s32(out_activation_max)); - - i1_val_16 = vcombine_s16( - vmovn_s32(input_1_s16_low), vmovn_s32(input_1_s16_high)); - res = vmovn_s16(i1_val_16); - - vst1_s8(output_, res); - output_ += 8; - loop_count--; - } - - loop_count = block_size % 8; - while (loop_count) - { - int32_t a1 = (*input_1++ + input_1_offset) << left_shift; - int32_t a2 = (*input_2++ + input_2_offset) << left_shift; - a1 = arm_nn_requantize(a1, input_1_mult, input_1_shift); - a2 = arm_nn_requantize(a2, input_2_mult, input_2_shift); - - int32_t sum = a1 + a2; - sum = arm_nn_requantize(sum, out_mult, out_shift); - sum += out_offset; - - sum = MAX(sum, out_activation_min); - sum = MIN(sum, out_activation_max); - *output_ = (int8_t) sum; - loop_count--; - output_++; - } - - return (ARM_CMSIS_NN_SUCCESS); -} diff --git a/mlearning/tflite-micro/operators/neon/arm_nn_mat_mult_kernel_s8_s16.c b/mlearning/tflite-micro/operators/neon/arm_nn_mat_mult_kernel_s8_s16.c deleted file mode 100644 index 9d39cd37d..000000000 --- a/mlearning/tflite-micro/operators/neon/arm_nn_mat_mult_kernel_s8_s16.c +++ /dev/null @@ -1,409 +0,0 @@ -/**************************************************************************** - * apps/mlearning/tflite-micro/operators/neon/arm_nn_mat_mult_kernel_s8_s16.c - * - * SPDX-License-Identifier: Apache-2.0 - * SPDX-FileCopyrightText: 2010-2023 Arm Limited and/or its affiliates - * - * - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - ****************************************************************************/ - -/**************************************************************************** - * Project: CMSIS NN Library - * Title: arm_nn_mat_mult_kernel_s8_s16.c - * Description: Matrix-multiplication function for convolution - * - * $Date: 29 May 2023 - * $Revision: V.2.0.0 - * - * Target : Arm(R) M-Profile Architecture - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include "arm_nnfunctions.h" -#include "arm_nnsupportfunctions.h" - -/* Matrix-multiplication function for convolution with per-channel - * requantization. Refer header file for details. - */ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -int8_t *arm_nn_mat_mult_kernel_s8_s16(const int8_t *input_a, - const int16_t *input_b, - const uint16_t output_ch, - const int32_t *out_shift, - const int32_t *out_mult, - const int32_t out_offset, - const int16_t activation_min, - const int16_t activation_max, - const int32_t num_col_a, - const int32_t aligned_num_col_a, - const int32_t *const output_bias, - int8_t *out_0) -{ - int8_t *out_1 = out_0 + output_ch; - const int32_t *bias = output_bias; - - uint16_t row_count = output_ch / 4; - const int8_t *ip_a0 = input_a; - - /* this loop over rows in A */ - - while (row_count) - { - int32_t col_count = num_col_a / 8; - const int16_t *ip_b0 = input_b; - const int16_t *ip_b1 = ip_b0 + aligned_num_col_a; - const int8_t *ip_a[4] = - { - ip_a0, - ip_a0 + num_col_a, - ip_a0 + 2 * num_col_a, - ip_a0 + 3 * num_col_a - }; - - int32_t ch_out[4][2] = - { - 0 - }; - - int32x4_t res[8]; - - for (int i = 0; i < 8; i++) - { - res[i] = vdupq_n_s32(0); - } - - /* Init accumulator with bias for channel N and N + 1 */ - - if (bias) - { - for (int i = 0; i < 4; i++) - { - ch_out[i][0] = *bias; - ch_out[i][1] = *bias++; - } - } - - /* Each time eight int8 data of four filters and eight int16 data - * of two inputs are read.First, the filter data is expanded to - * int16, and then cross-multiplied to obtain eight - * calculation results. - */ - - while (col_count) - { - int8x8_t filter_s8[4]; - int16x8_t input_s16[2]; - int16x8_t filter_s16[4]; - - input_s16[0] = vld1q_s16(ip_b0); - ip_b0 += 8; - input_s16[1] = vld1q_s16(ip_b1); - ip_b1 += 8; - - for (int i = 0; i < 4; i++) - { - filter_s8[i] = vld1_s8(ip_a[i]); - ip_a[i] += 8; - filter_s16[i] = vmovl_s8(filter_s8[i]); - res[i * 2] = vmlal_s16(res[i * 2], - vget_low_s16(filter_s16[i]), - vget_low_s16(input_s16[0])); - res[i * 2 + 1] = vmlal_s16(res[i * 2 + 1], - vget_low_s16(filter_s16[i]), - vget_low_s16(input_s16[1])); - res[i * 2] = vmlal_s16(res[i * 2], - vget_high_s16(filter_s16[i]), - vget_high_s16(input_s16[0])); - res[i * 2 + 1] = vmlal_s16(res[i * 2 + 1], - vget_high_s16(filter_s16[i]), - vget_high_s16(input_s16[1])); - } - - col_count--; - } - - for (int i = 0; i < 4; i++) - { - for (int j = 0; j < 2; j++) - { - ch_out[i][j] += vgetq_lane_s32(res[i * 2 + j], 0); - ch_out[i][j] += vgetq_lane_s32(res[i * 2 + j], 1); - ch_out[i][j] += vgetq_lane_s32(res[i * 2 + j], 2); - ch_out[i][j] += vgetq_lane_s32(res[i * 2 + j], 3); - } - } - - col_count = num_col_a % 8; - while (col_count) /* while over col_count */ - { - int16_t b0 = *ip_b0++; - int16_t b1 = *ip_b1++; - - for (int i = 0; i < 4; i++) - { - int8_t input_remaining = *(ip_a[i]++); - ch_out[i][0] += input_remaining * b0; - ch_out[i][1] += input_remaining * b1; - } - - col_count--; - } - - for (int i = 0; i < 4; i++) - { - ch_out[i][0] = arm_nn_requantize( - ch_out[i][0], *out_mult, *out_shift); - ch_out[i][1] = arm_nn_requantize( - ch_out[i][1], *out_mult, *out_shift); - ch_out[i][0] += out_offset; - ch_out[i][1] += out_offset; - ch_out[i][0] = MAX(ch_out[i][0], activation_min); - ch_out[i][1] = MAX(ch_out[i][1], activation_min); - ch_out[i][0] = MIN(ch_out[i][0], activation_max); - ch_out[i][1] = MIN(ch_out[i][1], activation_max); - *out_0++ = (int8_t)ch_out[i][0]; - *out_1++ = (int8_t)ch_out[i][1]; - out_mult++; - out_shift++; - } - - /* skip row */ - - ip_a0 = ip_a[3]; - row_count--; - } - - row_count = output_ch % 4; - if (row_count >= 2) - { - int32_t col_count = num_col_a / 8; - const int8_t *ip_a1 = ip_a0 + num_col_a; - const int16_t *ip_b0 = input_b; - const int16_t *ip_b1 = ip_b0 + aligned_num_col_a; - int32_t ch_out[2][2] = - { - 0 - }; - - int32x4_t res[4]; - - /* Init accumulator with bias for channel N and N + 1 */ - - if (bias) - { - for (int i = 0; i < 2; i++) - { - ch_out[i][0] = *bias; - ch_out[i][1] = *bias++; - } - } - - for (int i = 0; i < 4; i++) - { - res[i] = vdupq_n_s32(0); - } - - /* Each time eight int8 data of four filters and eight int16 data - * of two inputs are read.First, the filter data is expanded to - * int16, and then cross-multiplied to obtain 8 calculation results. - */ - - while (col_count) - { - int8x8_t filter_s8[2]; - int16x8_t input_s16[2]; - int16x8_t filter_s16[2]; - - filter_s8[0] = vld1_s8(ip_a0); - ip_a0 += 8; - filter_s8[1] = vld1_s8(ip_a1); - ip_a1 += 8; - - input_s16[0] = vld1q_s16(ip_b0); - ip_b0 += 8; - input_s16[1] = vld1q_s16(ip_b1); - ip_b1 += 8; - - for (int i = 0; i < 2; i++) - { - filter_s16[i] = vmovl_s8(filter_s8[i]); - res[i * 2] = vmlal_s16(res[i * 2], - vget_low_s16(filter_s16[i]), - vget_low_s16(input_s16[0])); - res[i * 2 + 1] = vmlal_s16(res[i * 2 + 1], - vget_low_s16(filter_s16[i]), - vget_low_s16(input_s16[1])); - res[i * 2] = vmlal_s16(res[i * 2], - vget_high_s16(filter_s16[i]), - vget_high_s16(input_s16[0])); - res[i * 2 + 1] = vmlal_s16(res[i * 2 + 1], - vget_high_s16(filter_s16[i]), - vget_high_s16(input_s16[1])); - } - - col_count--; - } - - for (int i = 0; i < 2; i++) - { - for (int j = 0; j < 2; j++) - { - ch_out[i][j] += vgetq_lane_s32(res[i * 2 + j], 0); - ch_out[i][j] += vgetq_lane_s32(res[i * 2 + j], 1); - ch_out[i][j] += vgetq_lane_s32(res[i * 2 + j], 2); - ch_out[i][j] += vgetq_lane_s32(res[i * 2 + j], 3); - } - } - - col_count = num_col_a % 8; - while (col_count) /* while over col_count */ - { - int8_t a0 = *ip_a0++; /* filter */ - int8_t a1 = *ip_a1++; - int16_t b0 = *ip_b0++; /* input */ - int16_t b1 = *ip_b1++; - - ch_out[0][0] += a0 * b0; - ch_out[1][1] += a1 * b1; - ch_out[1][0] += a1 * b0; - ch_out[0][1] += a0 * b1; - col_count--; - } - - for (int i = 0; i < 2; i++) - { - ch_out[i][0] = arm_nn_requantize( - ch_out[i][0], *out_mult, *out_shift); - ch_out[i][1] = arm_nn_requantize( - ch_out[i][1], *out_mult, *out_shift); - ch_out[i][0] += out_offset; - ch_out[i][1] += out_offset; - ch_out[i][0] = MAX(ch_out[i][0], activation_min); - ch_out[i][1] = MAX(ch_out[i][1], activation_min); - ch_out[i][0] = MIN(ch_out[i][0], activation_max); - ch_out[i][1] = MIN(ch_out[i][1], activation_max); - *out_0++ = (int8_t)ch_out[i][0]; - *out_1++ = (int8_t)ch_out[i][1]; - out_mult++; - out_shift++; - } - - /* skip row */ - - ip_a0 += num_col_a; - row_count -= 2; - } - - /* compute the last odd numbered row if any */ - - if (output_ch & 0x1) - { - int32_t col_count = num_col_a / 8; - const int16_t *ip_b0 = input_b; - const int16_t *ip_b1 = ip_b0 + aligned_num_col_a; - int32_t ch_out[2] = - { - 0 - }; - - int32x4_t res[2]; - - /* load the bias */ - - if (bias) - { - ch_out[0] = *bias; - ch_out[1] = *bias++; - } - - res[0] = vdupq_n_s32(0); - res[1] = vdupq_n_s32(0); - while (col_count) - { - int8x8_t filter_s8 = vld1_s8(ip_a0); - int16x8_t filter_s16 = vmovl_s8(filter_s8); - int16x8_t input_0_s16 = vld1q_s16(ip_b0); - int16x8_t input_1_s16 = vld1q_s16(ip_b1); - ip_a0 += 8; - ip_b0 += 8; - ip_b1 += 8; - res[0] = vmlal_s16(res[0], - vget_low_s16(filter_s16), - vget_low_s16(input_0_s16)); - res[1] = vmlal_s16(res[1], - vget_low_s16(filter_s16), - vget_low_s16(input_1_s16)); - res[0] = vmlal_s16(res[0], - vget_high_s16(filter_s16), - vget_high_s16(input_0_s16)); - res[1] = vmlal_s16(res[1], - vget_high_s16(filter_s16), - vget_high_s16(input_1_s16)); - col_count--; - } - - ch_out[0] += vgetq_lane_s32(res[0], 0); - ch_out[0] += vgetq_lane_s32(res[0], 1); - ch_out[0] += vgetq_lane_s32(res[0], 2); - ch_out[0] += vgetq_lane_s32(res[0], 3); - - ch_out[1] += vgetq_lane_s32(res[1], 0); - ch_out[1] += vgetq_lane_s32(res[1], 1); - ch_out[1] += vgetq_lane_s32(res[1], 2); - ch_out[1] += vgetq_lane_s32(res[1], 3); - - col_count = num_col_a % 8; - while (col_count) - { - int8_t a0 = *ip_a0++; - int16_t b0 = *ip_b0++; - int16_t b1 = *ip_b1++; - - ch_out[0] += a0 * b0; - ch_out[1] += a0 * b1; - col_count--; - } - - ch_out[0] = arm_nn_requantize( - ch_out[0], *out_mult, *out_shift); - ch_out[0] += out_offset; - ch_out[0] = MAX(ch_out[0], activation_min); - ch_out[0] = MIN(ch_out[0], activation_max); - *out_0++ = (int8_t)ch_out[0]; - - ch_out[1] = arm_nn_requantize( - ch_out[1], *out_mult, *out_shift); - ch_out[1] += out_offset; - ch_out[1] = MAX(ch_out[1], activation_min); - ch_out[1] = MIN(ch_out[1], activation_max); - *out_1++ = (int8_t)ch_out[1]; - - out_mult++; - out_shift++; - } - - out_0 += output_ch; - - /* return the new output pointer with offset */ - - return out_0; -} diff --git a/mlearning/tflite-micro/operators/neon/arm_q7_to_q15_with_offset.c b/mlearning/tflite-micro/operators/neon/arm_q7_to_q15_with_offset.c deleted file mode 100644 index 27349c231..000000000 --- a/mlearning/tflite-micro/operators/neon/arm_q7_to_q15_with_offset.c +++ /dev/null @@ -1,61 +0,0 @@ -/**************************************************************************** - * apps/mlearning/tflite-micro/operators/neon/arm_q7_to_q15_with_offset.c - * - * SPDX-License-Identifier: Apache-2.0 - * SPDX-FileCopyrightText: 2010-2023 Arm Limited and/or its affiliates - * - * - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include "arm_nnsupportfunctions.h" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -void arm_q7_to_q15_with_offset(const int8_t *src, - int16_t *dst, - int32_t block_size, - int16_t offset) -{ - int32_t block_cnt; - - block_cnt = block_size / 8; - int16x8_t offset_s16 = vdupq_n_s16(offset); - while (block_cnt) - { - int8x8_t src_s8 = vld1_s8(src); - int16x8_t src_s16 = vmovl_s8(src_s8); - src += 8; - src_s16 = vaddq_s16(offset_s16, src_s16); - block_cnt--; - vst1q_s16(dst, src_s16); - dst += 8; - } - - block_cnt = block_size % 8; - while (block_cnt > 0) - { - *dst++ = (int16_t)*src++ + offset; - - /* Decrement the loop counter */ - - block_cnt--; - } -} diff --git a/mlearning/tflite-micro/tflite-micro.patch b/mlearning/tflite-micro/tflite-micro.patch deleted file mode 100644 index 7c39ee527..000000000 --- a/mlearning/tflite-micro/tflite-micro.patch +++ /dev/null @@ -1,32 +0,0 @@ -From e6049c8ddd7e36db4993e3c6d8b4e5a7114db2c5 Mon Sep 17 00:00:00 2001 -From: renzhiyuan1 -Date: Mon, 4 Dec 2023 12:30:20 +0800 -Subject: [PATCH] Patch files in tflite-micro - -VELAPLATFO-20049 - -Patch files in tflite-micro - -Change-Id: Ic683fe4f12221d214ca77515c7b9487bb76a923f -Signed-off-by: renzhiyuan1 ---- - signal/src/circular_buffer.cc | 2 ++ - 1 file changed, 2 insertions(+) - -diff --git a/signal/src/circular_buffer.cc b/signal/src/circular_buffer.cc -index 7638d912e..3261be56c 100644 ---- a/signal/src/circular_buffer.cc -+++ b/signal/src/circular_buffer.cc -@@ -19,7 +19,9 @@ limitations under the License. - #include - #include - -+#ifndef ASSERT - #define ASSERT assert -+#endif - - namespace tflite { - namespace tflm_signal { --- -2.25.1 - diff --git a/mlearning/tflite-micro/tflm_syslog.cc b/mlearning/tflite-micro/tflm_syslog.cc deleted file mode 100644 index 9a795eeba..000000000 --- a/mlearning/tflite-micro/tflm_syslog.cc +++ /dev/null @@ -1,68 +0,0 @@ -/**************************************************************************** - * apps/mlearning/tflite-micro/tflm_syslog.cc - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#include "tensorflow/lite/micro/micro_log.h" - -#include -#include - -#if !defined(TF_LITE_STRIP_ERROR_STRINGS) -#include "tensorflow/lite/micro/debug_log.h" -#endif - -#if !defined(TF_LITE_STRIP_ERROR_STRINGS) - -void VMicroPrintf(FAR const char *format, va_list ap) -{ - vsyslog(CONFIG_TFLITEMICRO_SYSLOG_LEVEL, format, ap); -} - -void MicroPrintf(FAR const char *format, ...) -{ - va_list ap; - - /* Let vsyslog do the work */ - - va_start(ap, format); - vsyslog(CONFIG_TFLITEMICRO_SYSLOG_LEVEL, format, ap); - va_end(ap); -} - -int MicroSnprintf(FAR char *buffer, size_t buf_size, FAR const char *format, ...) -{ - va_list ap; - int ret; - - va_start(ap, format); - ret = vsnprintf(buffer, buf_size, format, ap); - va_end(ap); - - return ret; -} - -int MicroVsnprintf(FAR char *buffer, size_t buf_size, - FAR const char *format, va_list vlist) -{ - return vsnprintf(buffer, buf_size, format, vlist); -} - -#endif // !defined(TF_LITE_STRIP_ERROR_STRINGS) diff --git a/mlearning/tflite-micro/tflm_tool.cc b/mlearning/tflite-micro/tflm_tool.cc deleted file mode 100644 index 8edcf45a4..000000000 --- a/mlearning/tflite-micro/tflm_tool.cc +++ /dev/null @@ -1,152 +0,0 @@ -/**************************************************************************** - * apps/mlearning/tflite-micro/tflm_tool.cc - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include - -#include "tensorflow/lite/micro/micro_interpreter.h" -#include "tensorflow/lite/micro/micro_mutable_op_resolver.h" -#include "tensorflow/lite/micro/micro_profiler.h" - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static void usage(void) -{ - printf("\nUtility to use tflite micro on nuttx.\n" - "[ -C ] Compile tflite model into c++ codes.\n" - "[ -E ] Do once evaluation (for profiling).\n" - "[ -i ] Readable model file path.\n" - "[ -o ] Writable c++ file path.\n" - "[ -p ] Prefix of compiled code.\n" - "[ -a ] Arena size (mempool).\n" - "[ -h ] Print this message.\n"); -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -extern "C" int main(int argc, FAR char* argv[]) -{ - const char* modelFileName = nullptr; - const char* codeFileName = nullptr; - const char* prefix = "NXAI"; - bool need_compile = false; - bool need_invoke = false; - int arenaSize = 1024 * 8; - - int ch; - while ((ch = getopt(argc, argv, "CEhi:o:p:a:")) != EOF) - { - switch (ch) - { - case 'C': - need_compile = true; - break; - case 'E': - need_invoke = true; - break; - case 'p': - prefix = optarg; - break; - case 'i': - modelFileName = optarg; - break; - case 'o': - codeFileName = optarg; - break; - case 'a': - arenaSize = strtol(optarg, NULL, 0); - break; - case 'h': - default: - usage(); - return -1; - } - } - - if (!modelFileName || !codeFileName) - { - usage(); - return -1; - } - - std::ifstream ifs(modelFileName, std::ios::binary); - ifs.seekg(0, std::ios::end); - size_t modelSize = ifs.tellg(); - std::unique_ptr pModel(new uint8_t[modelSize]); - - ifs.seekg(0, std::ios::beg); - ifs.read(reinterpret_cast(pModel.get()), modelSize); - ifs.close(); - - /* HACK: can change operators here. */ - - tflite::MicroMutableOpResolver<8> resolver; - resolver.AddConv2D(tflite::Register_CONV_2D_INT8()); - resolver.AddMaxPool2D(tflite::Register_MAX_POOL_2D_INT8()); - resolver.AddQuantize(tflite::Register_QUANTIZE_FLOAT32_INT8()); - resolver.AddDequantize(tflite::Register_DEQUANTIZE_INT8()); - resolver.AddMean(tflite::Register_MEAN_INT8()); - resolver.AddReshape(); - resolver.AddFullyConnected(tflite::Register_FULLY_CONNECTED_INT8()); - resolver.AddSoftmax(tflite::Register_SOFTMAX_INT8()); - - std::unique_ptr pArena(new uint8_t[arenaSize]); - - tflite::MicroProfiler profiler; - tflite::MicroInterpreter interpreter(tflite::GetModel(pModel.get()), - resolver, pArena.get(), arenaSize, nullptr, - reinterpret_cast(&profiler)); - - /* HACK: can add testcases here. */ - - if (need_invoke) - { - interpreter.Invoke(); - profiler.LogCsv(); - profiler.LogTicksPerTagCsv(); - } - - if (need_compile) - { -#ifdef TFLITE_MODEL_COMPILER - std::ofstream ofs(codeFileName); - interpreter.Compile(ofs, prefix); - ofs.close(); -#else - printf("Not supported compiling %s.\n", prefix); -#endif - } - - printf("nxai done!\n"); - return 0; -} \ No newline at end of file diff --git a/industry/modbus/freemodbus/Kconfig b/modbus/Kconfig similarity index 92% rename from industry/modbus/freemodbus/Kconfig rename to modbus/Kconfig index 7c9e834f3..8da277fdf 100644 --- a/industry/modbus/freemodbus/Kconfig +++ b/modbus/Kconfig @@ -4,11 +4,11 @@ # menu "FreeModBus" -config INDUSTRY_MODBUS +config MODBUS bool "Modbus support using FreeModbus" default n -if INDUSTRY_MODBUS +if MODBUS config MB_FUNC_HANDLERS_MAX int "Maximum number of Modbus functions" @@ -20,11 +20,11 @@ config MB_FUNC_HANDLERS_MAX the sum of all enabled functions in this file and custom function handlers. If set to small adding more functions will fail. -config INDUSTRY_MODBUS_SLAVE +config MODBUS_SLAVE bool "Modbus slave support via FreeModBus" default n -if INDUSTRY_MODBUS_SLAVE +if MODBUS_SLAVE config MB_ASCII_ENABLED bool "Modbus ASCII support" default y @@ -144,26 +144,26 @@ config MB_FUNC_READWRITE_HOLDING_ENABLED ---help--- If the Read/Write Multiple Registers function should be enabled. -endif # INDUSTRY_MODBUS_SLAVE +endif # MODBUS_SLAVE -config INDUSTRY_MODBUS_MASTER +config MODBUS_MASTER bool "Modbus Master support via FreeModBus" default n config MB_ASCII_MASTER bool "Modbus ASCII master" default n - depends on INDUSTRY_MODBUS_MASTER + depends on MODBUS_MASTER config MB_RTU_MASTER bool "Modbus RTU master" default n - depends on INDUSTRY_MODBUS_MASTER + depends on MODBUS_MASTER config MB_PORT_HAS_CLOSE bool "Platform close callbacks" default n - depends on INDUSTRY_MODBUS_MASTER + depends on MODBUS_MASTER ---help--- A port which wants to get an callback must select CONFIG_MB_HAS_CLOSE and provide vMBMasterPortClose() as @@ -250,14 +250,5 @@ config MB_MASTER_FUNC_READWRITE_HOLDING_ENABLED If the Read/Write Multiple Registers function should be enabled. endif # MB_ASCII_MASTER || MB_RTU_MASTER -endif # INDUSTRY_MODBUS - -config INDUSTRY_MODBUS_DISABLE_LOG - bool "Disable logging for FreeModBus" - default !FILE_STREAM - ---help--- - Disable all logging features for FreeModBus which can be useful - for small optimized systems without console or log file support. - This also must be enabled when fputs() is not supported. - +endif # MODBUS endmenu # FreeModBus diff --git a/math/ruy/Kconfig b/modbus/Make.defs similarity index 91% rename from math/ruy/Kconfig rename to modbus/Make.defs index 71b4890e2..be64a8f42 100644 --- a/math/ruy/Kconfig +++ b/modbus/Make.defs @@ -1,5 +1,5 @@ ############################################################################ -# apps/math/ruy/Kconfig +# apps/modbus/Make.defs # # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with @@ -18,8 +18,6 @@ # ############################################################################ -config MATH_RUY - bool "Ruy" - default n - ---help--- - Enable ruy. +ifeq ($(CONFIG_MODBUS),y) +CONFIGURED_APPS += $(APPDIR)/modbus +endif diff --git a/industry/modbus/freemodbus/Makefile b/modbus/Makefile similarity index 88% rename from industry/modbus/freemodbus/Makefile rename to modbus/Makefile index dddb6559a..3589d9017 100644 --- a/industry/modbus/freemodbus/Makefile +++ b/modbus/Makefile @@ -1,7 +1,5 @@ ############################################################################ -# apps/industry/modbus/freemodbus/Makefile -# -# SPDX-License-Identifier: Apache-2.0 +# apps/modbus/Makefile # # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with @@ -24,9 +22,9 @@ include $(APPDIR)/Make.defs # FreeModBus Library -ifeq ($(CONFIG_INDUSTRY_MODBUS),y) +ifeq ($(CONFIG_MODBUS),y) - ifeq ($(CONFIG_INDUSTRY_MODBUS_SLAVE),y) + ifeq ($(CONFIG_MODBUS_SLAVE),y) CSRCS += mb.c endif diff --git a/modbus/README.md b/modbus/README.md new file mode 100644 index 000000000..9fe4cc93b --- /dev/null +++ b/modbus/README.md @@ -0,0 +1,121 @@ +# Modbus + +This directory contains a port of last open source version of FreeModBus (BSD +license). The code in this directory is a subset of FreeModBus version 1.5.0 +(June 6, 2010) that can be downloaded in its entirety from +http://developer.berlios.de/project/showfiles.php?group_id=6120. + +Includes extensions to support RTU master mode by Armink(383016632@qq.com): +https://github.com/armink/FreeModbus_Slave-Master-RTT-STM32. Ported to NuttX by +Darcy Gong. + +## Directory Structure / Relation to freemodbus-v1.5.0 + +The original FreeModBus download consists of several directories. This subset +takes only the contents of one directory, `modbus/`, that implements the core +modbus logic and integrates that directory into the NuttX build system. The +mapping between `freemodbus-v1.5.0` and the nuttx directories is shown below: + +``` +--------------------------- ---------------------------------------------- +freemodbus-v1.5.0 NuttX +--------------------------- ---------------------------------------------- +All top level .txt files Not included +demo/ Not included. This directory contains demo + and porting code for a variety of platforms. + The NuttX demo was ported from the LINUX + demo in this directory and can be found at + apps/examples/modbus. +doc/ Not included. This directory contains Doxygen + support files. +modbus/ Included in its entirety in various locations: + ascii apps/modbus/ascii + functions apps/modbus/functions + include apps/include/modbus + mb.c apps/modbus/mb.c + rtu apps/modbus/rtu + tcp apps/modbus/tcp +tools/ Not included. This directory contains Doxygen + tools. +--------------------------- ---------------------------------------------- +``` + +So this directory is equivalent to the `freemodbus-v1.5.0/modbus` directory +except that (1) it may include modifications for the integration with NuttX and +(2) the modbus/include directory was moved to `apps/modbus`. + +The original, unmodified `freemodbus-v1.5.0` was checked in as SVN revision +`4960`. + +The other directory here, `nuttx/`, implements the NuttX modbus interface. It +derives from the `freemodbus-v1.5.0/demo/LINUX/port` directory. + +## Configuration Options + +In the original `freemodbus-v1.5.0` release, the FreeModBus configuration was +controlled by the header file `mbconfig.h`. This header file was eliminated +(post revision `4960`) and the FreeModBus configuration was integrated into the +NuttX configuration system. + +The NuttX-named configuration options that are available include: + +- `CONFIG_MODBUS` โ€“ General ModBus support. +- `CONFIG_MB_ASCII_ENABLED` โ€“ Modbus ASCII support. +- `CONFIG_MB_ASCII_MASTER` โ€“ Modbus ASCII master support. +- `CONFIG_MB_RTU_ENABLED` โ€“ Modbus RTU support. +- `CONFIG_MB_RTU_MASTER` โ€“ Modbus RTU master support. +- `CONFIG_MB_TCP_ENABLED` โ€“ Modbus TCP support. +- `CONFIG_MB_ASCII_TIMEOUT_SEC` โ€“ Character timeout value for Modbus ASCII. The + character timeout value is not fixed for Modbus ASCII and is therefore a + configuration option. It should be set to the maximum expected delay time of + the network. Default: `1`. +- `CONFIG_MB_ASCII_TIMEOUT_WAIT_BEFORE_SEND_MS` โ€“ Timeout to wait in ASCII prior + to enabling transmitter. If defined the function calls `vMBPortSerialDelay` + with the argument `CONFIG_MB_ASCII_TIMEOUT_WAIT_BEFORE_SEND_MS` to allow for a + delay before the serial transmitter is enabled. This is required because some + targets are so fast that there is no time between receiving and transmitting + the frame. If the master is too slow with enabling its receiver then it will + not receive the response correctly. +- `CONFIG_MB_FUNC_HANDLERS_MAX` โ€“ Maximum number of Modbus functions codes the + protocol stack should support. The maximum number of supported Modbus + functions must be greater than the sum of all enabled functions in this file + and custom function handlers. If set too small, adding more functions will + fail. +- `CONFIG_MB_FUNC_OTHER_REP_SLAVEID_BUF` โ€“ Number of bytes which should be + allocated for the Report Slave ID command. This number limits the maximum size + of the additional segment in the report slave id function. See + `eMBSetSlaveID()` for more information on how to set this value. It is only + used if `CONFIG_MB_FUNC_OTHER_REP_SLAVEID_ENABLED` is set to `1`. +- `CONFIG_MB_FUNC_OTHER_REP_SLAVEID_ENABLED` โ€“ If the Report Slave ID function + should be enabled. +- `CONFIG_MB_FUNC_READ_INPUT_ENABLED` โ€“ If the Read Input Registers function + should be enabled. +- `CONFIG_MB_FUNC_READ_HOLDING_ENABLED` โ€“ If the Read Holding Registers function + should be enabled. +- `CONFIG_MB_FUNC_WRITE_HOLDING_ENABLED` โ€“ If the Write Single Register function + should be enabled. +- `CONFIG_MB_FUNC_WRITE_MULTIPLE_HOLDING_ENABLED` โ€“ If the Write Multiple + registers function should be enabled. +- `CONFIG_MB_FUNC_READ_COILS_ENABLED` โ€“ If the Read Coils function should be + enabled. +- `CONFIG_MB_FUNC_WRITE_COIL_ENABLED` โ€“ If the Write Coils function should be + enabled. +- `CONFIG_MB_FUNC_WRITE_MULTIPLE_COILS_ENABLED` โ€“ If the Write Multiple Coils + function should be enabled. +- `CONFIG_MB_FUNC_READ_DISCRETE_INPUTS_ENABLED` โ€“ If the Read Discrete Inputs + function should be enabled. +- `CONFIG_MB_FUNC_READWRITE_HOLDING_ENABLED` โ€“ If the Read/Write Multiple + Registers function should be enabled. + +See also other serial settings, in particular: + +- `CONFIG_SERIAL_TERMIOS` โ€“ Serial driver supports `termios.h` interfaces + (`tcsetattr`, `tcflush`, etc.). If this is not defined, then the terminal + settings (baud, parity, etc.) are not configurable at runtime; serial streams + will not be flushed when closed. + +## Note + +The developer of FreeModBus, Christian Walter, is still developing Modbus +libraries, although they are now commercial. See +http://www.embedded-solutions.at/ for further information. diff --git a/industry/modbus/freemodbus/ascii/Make.defs b/modbus/ascii/Make.defs similarity index 86% rename from industry/modbus/freemodbus/ascii/Make.defs rename to modbus/ascii/Make.defs index c2fcf2218..fb1975938 100644 --- a/industry/modbus/freemodbus/ascii/Make.defs +++ b/modbus/ascii/Make.defs @@ -1,7 +1,5 @@ ############################################################################ -# apps/industry/modbus/freemodbus/ascii/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 +# apps/modbus/functions/Make.defs # # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with @@ -26,6 +24,6 @@ CSRCS += mbascii.c DEPPATH += --dep-path ascii VPATH += :ascii -CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/industry/modbus/freemodbus/ascii +CFLAGS += ${shell $(INCDIR) "$(CC)" $(APPDIR)/modbus/ascii} endif diff --git a/industry/modbus/freemodbus/ascii/mbascii.c b/modbus/ascii/mbascii.c similarity index 95% rename from industry/modbus/freemodbus/ascii/mbascii.c rename to modbus/ascii/mbascii.c index 1ba55f99c..2fdc6d5a0 100644 --- a/industry/modbus/freemodbus/ascii/mbascii.c +++ b/modbus/ascii/mbascii.c @@ -1,8 +1,9 @@ /**************************************************************************** - * apps/industry/modbus/freemodbus/ascii/mbascii.c + * apps/modbus/ascii/mbascii.c * - * SPDX-License-Identifier: BSD-3-Clause - * SPDX-FileCopyrightText: 2006 Christian Walter + * FreeModbus Library: A portable Modbus implementation for Modbus ASCII/RTU. + * Copyright (c) 2006 Christian Walter + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -61,7 +62,7 @@ #define MB_SER_PDU_PDU_OFF 1 /* Offset of Modbus-PDU in Ser-PDU. */ /**************************************************************************** - * Private Typess + * Private Type Definitions ****************************************************************************/ typedef enum @@ -114,6 +115,7 @@ static volatile eMBBytePos eBytePos; static volatile uint8_t *pucSndBufferCur; static volatile uint16_t usSndBufferCount; +static volatile uint8_t ucLRC; static volatile uint8_t ucMBLFCharacter; /**************************************************************************** @@ -128,11 +130,11 @@ static uint8_t prvucMBint8_t2BIN(uint8_t ucCharacter) } else if ((ucCharacter >= 'A') && (ucCharacter <= 'F')) { - return (uint8_t)(ucCharacter - 'A' + 0x0a); + return (uint8_t)(ucCharacter - 'A' + 0x0A); } else { - return 0xff; + return 0xFF; } } @@ -142,9 +144,9 @@ static uint8_t prvucMBBIN2int8_t(uint8_t ucByte) { return (uint8_t)('0' + ucByte); } - else if ((ucByte >= 0x0a) && (ucByte <= 0x0f)) + else if ((ucByte >= 0x0A) && (ucByte <= 0x0F)) { - return (uint8_t)(ucByte - 0x0a + 'A'); + return (uint8_t)(ucByte - 0x0A + 'A'); } else { @@ -239,7 +241,7 @@ eMBErrorCode eMBASCIIReceive(uint8_t *pucRcvAddress, uint8_t **pucFrame, * size of address field and CRC checksum. */ - *pusLength = usRcvBufferPos - MB_SER_PDU_PDU_OFF - MB_SER_PDU_SIZE_LRC; + *pusLength = (uint16_t)(usRcvBufferPos - MB_SER_PDU_PDU_OFF - MB_SER_PDU_SIZE_LRC); /* Return the start of the Modbus PDU to the caller. */ @@ -316,7 +318,6 @@ bool xMBASCIIReceiveFSM(void) */ case STATE_RX_RCV: - /* Enable timer for character timeout. */ vMBPortTimersEnable(); @@ -355,7 +356,7 @@ bool xMBASCIIReceiveFSM(void) eRcvState = STATE_RX_IDLE; - /* Disable previously activated timer due to error state. */ + /* Disable previously activated timer because of error state. */ vMBPortTimersDisable(); } @@ -465,7 +466,7 @@ bool xMBASCIITransmitFSM(void) break; case BYTE_LOW_NIBBLE: - ucByte = prvucMBBIN2int8_t((uint8_t)(*pucSndBufferCur & 0x0f)); + ucByte = prvucMBBIN2int8_t((uint8_t)(*pucSndBufferCur & 0x0F)); xMBPortSerialPutByte((int8_t)ucByte); pucSndBufferCur++; eBytePos = BYTE_HIGH_NIBBLE; @@ -513,7 +514,6 @@ bool xMBASCIITransmitFSM(void) */ case STATE_TX_IDLE: - /* enable receiver/disable transmitter. */ vMBPortSerialEnable(true, false); @@ -530,14 +530,13 @@ bool xMBASCIITimerT1SExpired(void) /* If we have a timeout we go back to the idle state and wait for * the next frame. */ - case STATE_RX_RCV: case STATE_RX_WAIT_EOF: eRcvState = STATE_RX_IDLE; break; default: - DEBUGASSERT(eRcvState == STATE_RX_RCV || eRcvState == STATE_RX_WAIT_EOF); + DEBUGASSERT((eRcvState == STATE_RX_RCV) || (eRcvState == STATE_RX_WAIT_EOF)); break; } diff --git a/industry/modbus/freemodbus/ascii/mbascii.h b/modbus/ascii/mbascii.h similarity index 93% rename from industry/modbus/freemodbus/ascii/mbascii.h rename to modbus/ascii/mbascii.h index 5351de010..71d63117b 100644 --- a/industry/modbus/freemodbus/ascii/mbascii.h +++ b/modbus/ascii/mbascii.h @@ -1,8 +1,9 @@ /**************************************************************************** - * apps/industry/modbus/ascii/mbascii.h + * apps/modbus/ascii/mbascii.h * - * SPDX-License-Identifier: BSD-3-Clause - * SPDX-FileCopyrightText: 2006 Christian Walter + * FreeModbus Library: A portable Modbus implementation for Modbus ASCII/RTU. + * Copyright (c) 2006 Christian Walter + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/industry/modbus/freemodbus/functions/Make.defs b/modbus/functions/Make.defs similarity index 88% rename from industry/modbus/freemodbus/functions/Make.defs rename to modbus/functions/Make.defs index 7c53d5bfc..75e3c009a 100644 --- a/industry/modbus/freemodbus/functions/Make.defs +++ b/modbus/functions/Make.defs @@ -1,7 +1,5 @@ ############################################################################ -# apps/industry/modbus/freemodbus/functions/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 +# apps/modbus/nuttx/Make.defs # # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with @@ -33,4 +31,4 @@ endif DEPPATH += --dep-path functions VPATH += :functions -CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/industry/modbus/freemodbus/functions +CFLAGS += ${shell $(INCDIR) "$(CC)" $(APPDIR)/modbus/functions} diff --git a/industry/modbus/freemodbus/functions/mbfunccoils.c b/modbus/functions/mbfunccoils.c similarity index 98% rename from industry/modbus/freemodbus/functions/mbfunccoils.c rename to modbus/functions/mbfunccoils.c index b742de064..0be07d56f 100644 --- a/industry/modbus/freemodbus/functions/mbfunccoils.c +++ b/modbus/functions/mbfunccoils.c @@ -1,8 +1,9 @@ /**************************************************************************** * apps/functions/mbfunccoils.c * - * SPDX-License-Identifier: BSD-3-Clause - * SPDX-FileCopyrightText: 2006 Christian Walter + * FreeModbus Library: A portable Modbus implementation for Modbus ASCII/RTU. + * Copyright (c) 2006 Christian Walter + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/industry/modbus/freemodbus/functions/mbfunccoils_m.c b/modbus/functions/mbfunccoils_m.c similarity index 98% rename from industry/modbus/freemodbus/functions/mbfunccoils_m.c rename to modbus/functions/mbfunccoils_m.c index ca59e4caf..710504268 100644 --- a/industry/modbus/freemodbus/functions/mbfunccoils_m.c +++ b/modbus/functions/mbfunccoils_m.c @@ -1,8 +1,9 @@ /**************************************************************************** - * apps/industry/modbus/functions/mbfunccoils_m.c + * apps/modbus/functions/mbfunccoils_m.c * - * SPDX-License-Identifier: BSD-3-Clause - * SPDX-FileCopyrightText: 2013 Armink + * FreeModbus Library: A portable Modbus implementation for Modbus ASCII/RTU. + * Copyright (C) 2013 Armink + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/industry/modbus/freemodbus/functions/mbfuncdiag.c b/modbus/functions/mbfuncdiag.c similarity index 82% rename from industry/modbus/freemodbus/functions/mbfuncdiag.c rename to modbus/functions/mbfuncdiag.c index c9add6fd4..ded0ca488 100644 --- a/industry/modbus/freemodbus/functions/mbfuncdiag.c +++ b/modbus/functions/mbfuncdiag.c @@ -1,8 +1,9 @@ /**************************************************************************** - * apps/industry/modbus/functions/mbfuncdiag.c + * apps/functions/mbfuncdiag.c * - * SPDX-License-Identifier: BSD-3-Clause - * SPDX-FileCopyrightText: 2006 Christian Walter + * FreeModbus Library: A portable Modbus implementation for Modbus ASCII/RTU. + * Copyright (c) 2006 Christian Walter + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -27,7 +28,3 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ diff --git a/industry/modbus/freemodbus/functions/mbfuncdisc.c b/modbus/functions/mbfuncdisc.c similarity index 97% rename from industry/modbus/freemodbus/functions/mbfuncdisc.c rename to modbus/functions/mbfuncdisc.c index 3f2907277..058bdd643 100644 --- a/industry/modbus/freemodbus/functions/mbfuncdisc.c +++ b/modbus/functions/mbfuncdisc.c @@ -1,8 +1,9 @@ /**************************************************************************** * apps/functions/mbfuncdisc.c * - * SPDX-License-Identifier: BSD-3-Clause - * SPDX-FileCopyrightText: 2006 Christian Walter + * FreeModbus Library: A portable Modbus implementation for Modbus ASCII/RTU. + * Copyright (c) 2006 Christian Walter + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/industry/modbus/freemodbus/functions/mbfuncdisc_m.c b/modbus/functions/mbfuncdisc_m.c similarity index 97% rename from industry/modbus/freemodbus/functions/mbfuncdisc_m.c rename to modbus/functions/mbfuncdisc_m.c index 770ab899d..24b620cb7 100644 --- a/industry/modbus/freemodbus/functions/mbfuncdisc_m.c +++ b/modbus/functions/mbfuncdisc_m.c @@ -1,8 +1,9 @@ /**************************************************************************** - * apps/industry/modbus/functions/mbfuncdisc_m.c + * apps/modbus/functions/mbfuncdisc_m.c * - * SPDX-License-Identifier: BSD-3-Clause - * SPDX-FileCopyrightText: 2013 Armink + * FreeModbus Library: A portable Modbus implementation for Modbus ASCII/RTU. + * Copyright (C) 2013 Armink + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/industry/modbus/freemodbus/functions/mbfuncholding.c b/modbus/functions/mbfuncholding.c similarity index 98% rename from industry/modbus/freemodbus/functions/mbfuncholding.c rename to modbus/functions/mbfuncholding.c index 964db7a79..1f8b99898 100644 --- a/industry/modbus/freemodbus/functions/mbfuncholding.c +++ b/modbus/functions/mbfuncholding.c @@ -1,8 +1,9 @@ /**************************************************************************** * apps/functions/mbfuncholding.c * - * SPDX-License-Identifier: BSD-3-Clause - * SPDX-FileCopyrightText: 2006 Christian Walter + * FreeModbus Library: A portable Modbus implementation for Modbus ASCII/RTU. + * Copyright (c) 2006 Christian Walter + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/industry/modbus/freemodbus/functions/mbfuncholding_m.c b/modbus/functions/mbfuncholding_m.c similarity index 99% rename from industry/modbus/freemodbus/functions/mbfuncholding_m.c rename to modbus/functions/mbfuncholding_m.c index 59be35b26..040782563 100644 --- a/industry/modbus/freemodbus/functions/mbfuncholding_m.c +++ b/modbus/functions/mbfuncholding_m.c @@ -1,8 +1,9 @@ /**************************************************************************** - * apps/industry/modbus/functions/mbfuncholding_m.c + * apps/modbus/functions/mbfuncholding_m.c * - * SPDX-License-Identifier: BSD-3-Clause - * SPDX-FileCopyrightText: 2013 Armink + * FreeModbus Library: A portable Modbus implementation for Modbus ASCII/RTU. + * Copyright (C) 2013 Armink + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/industry/modbus/freemodbus/functions/mbfuncinput.c b/modbus/functions/mbfuncinput.c similarity index 96% rename from industry/modbus/freemodbus/functions/mbfuncinput.c rename to modbus/functions/mbfuncinput.c index 3874cf966..73eebb056 100644 --- a/industry/modbus/freemodbus/functions/mbfuncinput.c +++ b/modbus/functions/mbfuncinput.c @@ -1,8 +1,9 @@ /**************************************************************************** * apps/functions/mbfuncinput.c * - * SPDX-License-Identifier: BSD-3-Clause - * SPDX-FileCopyrightText: 2006 Christian Walter + * FreeModbus Library: A portable Modbus implementation for Modbus ASCII/RTU. + * Copyright (c) 2006 Christian Walter + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/industry/modbus/freemodbus/functions/mbfuncinput_m.c b/modbus/functions/mbfuncinput_m.c similarity index 97% rename from industry/modbus/freemodbus/functions/mbfuncinput_m.c rename to modbus/functions/mbfuncinput_m.c index 2d4799037..b9577a5cb 100644 --- a/industry/modbus/freemodbus/functions/mbfuncinput_m.c +++ b/modbus/functions/mbfuncinput_m.c @@ -1,8 +1,9 @@ /**************************************************************************** - * apps/industry/modbus/functions/mbfuncinput_m.c + * apps/modbus/functions/mbfuncinput_m.c * - * SPDX-License-Identifier: BSD-3-Clause - * SPDX-FileCopyrightText: 2013 Armink + * FreeModbus Library: A portable Modbus implementation for Modbus ASCII/RTU. + * Copyright (C) 2013 Armink + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/industry/modbus/freemodbus/functions/mbfuncother.c b/modbus/functions/mbfuncother.c similarity index 95% rename from industry/modbus/freemodbus/functions/mbfuncother.c rename to modbus/functions/mbfuncother.c index ede3fae0c..b0ebaaa59 100644 --- a/industry/modbus/freemodbus/functions/mbfuncother.c +++ b/modbus/functions/mbfuncother.c @@ -1,8 +1,9 @@ /**************************************************************************** * apps/functions/mbfuncother.c * - * SPDX-License-Identifier: BSD-3-Clause - * SPDX-FileCopyrightText: 2006 Christian Walter + * FreeModbus Library: A portable Modbus implementation for Modbus ASCII/RTU. + * Copyright (c) 2006 Christian Walter + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/industry/modbus/freemodbus/functions/mbutils.c b/modbus/functions/mbutils.c similarity index 96% rename from industry/modbus/freemodbus/functions/mbutils.c rename to modbus/functions/mbutils.c index 816fbe8b2..3db155eb0 100644 --- a/industry/modbus/freemodbus/functions/mbutils.c +++ b/modbus/functions/mbutils.c @@ -1,8 +1,9 @@ /**************************************************************************** * apps/functions/mbutils.c * - * SPDX-License-Identifier: BSD-3-Clause - * SPDX-FileCopyrightText: 2006 Christian Walter + * FreeModbus Library: A portable Modbus implementation for Modbus ASCII/RTU. + * Copyright (c) 2006 Christian Walter + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/industry/modbus/freemodbus/mb.c b/modbus/mb.c similarity index 98% rename from industry/modbus/freemodbus/mb.c rename to modbus/mb.c index 3d4b9bf5a..7a8155779 100644 --- a/industry/modbus/freemodbus/mb.c +++ b/modbus/mb.c @@ -1,8 +1,9 @@ /**************************************************************************** - * apps/industry/modbus/mb.c + * apps/modbus/mb.c * - * SPDX-License-Identifier: BSD-3-Clause - * SPDX-FileCopyrightText: 2006 Christian Walter + * FreeModbus Library: A portable Modbus implementation for Modbus ASCII/RTU. + * Copyright (c) 2006 Christian Walter + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/industry/modbus/freemodbus/mb_m.c b/modbus/mb_m.c similarity index 97% rename from industry/modbus/freemodbus/mb_m.c rename to modbus/mb_m.c index 108fdf678..336181136 100644 --- a/industry/modbus/freemodbus/mb_m.c +++ b/modbus/mb_m.c @@ -1,8 +1,8 @@ /**************************************************************************** * FreeModbus Library: A portable Modbus implementation for Modbus ASCII/RTU. * - * SPDX-License-Identifier: BSD-3-Clause - * SPDX-FileCopyrightText: 2013 Armink + * Copyright (C) 2013 Armink + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -429,13 +429,6 @@ eMBErrorCode eMBMasterPoll(void) vMBMasterRunResRelease(); break; - - case EV_MASTER_PROCESS_SUCCESS: - case EV_MASTER_ERROR_RESPOND_TIMEOUT: - case EV_MASTER_ERROR_RECEIVE_DATA: - case EV_MASTER_ERROR_EXECUTE_FUNCTION: - default: - break; } } diff --git a/industry/modbus/freemodbus/nuttx/Make.defs b/modbus/nuttx/Make.defs similarity index 85% rename from industry/modbus/freemodbus/nuttx/Make.defs rename to modbus/nuttx/Make.defs index 1c3413ce3..8cb6f633f 100644 --- a/industry/modbus/freemodbus/nuttx/Make.defs +++ b/modbus/nuttx/Make.defs @@ -1,7 +1,5 @@ ############################################################################ -# apps/industry/modbus/freemodbus/nuttx/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 +# apps/modbus/nuttx/Make.defs # # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with @@ -22,7 +20,7 @@ CSRCS += portother.c -ifeq ($(CONFIG_INDUSTRY_MODBUS_SLAVE),y) +ifeq ($(CONFIG_MODBUS_SLAVE),y) CSRCS += portevent.c portserial.c porttimer.c endif @@ -32,4 +30,4 @@ endif DEPPATH += --dep-path nuttx VPATH += :nuttx -CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/industry/modbus/freemodbus/nuttx +CFLAGS += ${shell $(INCDIR) "$(CC)" $(APPDIR)/modbus/nuttx} diff --git a/industry/modbus/freemodbus/nuttx/port.h b/modbus/nuttx/port.h similarity index 87% rename from industry/modbus/freemodbus/nuttx/port.h rename to modbus/nuttx/port.h index 149cefad2..90fadab60 100644 --- a/industry/modbus/freemodbus/nuttx/port.h +++ b/modbus/nuttx/port.h @@ -1,8 +1,9 @@ /**************************************************************************** - * apps/industry/modbus/nuttx/port.h + * apps/modbus/nuttx/port.h * - * SPDX-License-Identifier: BSD-3-Clause - * SPDX-FileCopyrightText: 2006 Christian Walter + * FreeModbus Library: NuttX Port + * Copyright (c) 2006 Christian Walter + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -28,8 +29,8 @@ * ****************************************************************************/ -#ifndef __APPS_INDUSTRY_MODBUS_NUTTX_PORT_H -#define __APPS_INDUSTRY_MODBUS_NUTTX_PORT_H +#ifndef __APPS_MODBUS_NUTTX_PORT_H +#define __APPS_MODBUS_NUTTX_PORT_H /**************************************************************************** * Included Files @@ -79,12 +80,8 @@ typedef enum void vMBPortEnterCritical(void); void vMBPortExitCritical(void); -#ifndef CONFIG_INDUSTRY_MODBUS_DISABLE_LOG void vMBPortLog(eMBPortLogLevel eLevel, const char *szModule, - const char *szFmt, ...) printf_like(3, 4); -#else -# define vMBPortLog(l, m, c, ...) -#endif + const char *szFmt, ...); void vMBPortTimerPoll(void); bool xMBPortSerialPoll(void); bool xMBPortSerialSetTimeout(uint32_t dwTimeoutMs); @@ -93,7 +90,7 @@ bool xMBPortSerialSetTimeout(uint32_t dwTimeoutMs); void vMBMasterPortEnterCritical(void); void vMBMasterPortExitCritical(void); void vMBMasterPortLog(eMBPortLogLevel eLevel, const char *szModule, - const char *szFmt, ...) printf_like(3, 4); + const char *szFmt, ...); void vMBMasterPortTimerPoll(void); bool xMBMasterPortSerialPoll(void); bool xMBMasterPortSerialSetTimeout(uint32_t dwTimeoutMs); @@ -103,4 +100,4 @@ bool xMBPortSerialSetTimeout(uint32_t dwTimeoutMs); } #endif -#endif /* __APPS_INDUSTRY_MODBUS_NUTTX_PORT_H */ +#endif /* __APPS_MODBUS_NUTTX_PORT_H */ diff --git a/industry/modbus/freemodbus/nuttx/portevent.c b/modbus/nuttx/portevent.c similarity index 95% rename from industry/modbus/freemodbus/nuttx/portevent.c rename to modbus/nuttx/portevent.c index d9d31072d..d45c8bad6 100644 --- a/industry/modbus/freemodbus/nuttx/portevent.c +++ b/modbus/nuttx/portevent.c @@ -1,8 +1,9 @@ /**************************************************************************** - * apps/industry/modbus/nuttx/portevent.c + * apps/modbus/nuttx/portevent.c * - * SPDX-License-Identifier: BSD-3-Clause - * SPDX-FileCopyrightText: 2006 Christian Walter + * FreeModbus Library: NuttX Port + * Copyright (c) 2006 Christian Walter + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/industry/modbus/freemodbus/nuttx/portevent_m.c b/modbus/nuttx/portevent_m.c similarity index 92% rename from industry/modbus/freemodbus/nuttx/portevent_m.c rename to modbus/nuttx/portevent_m.c index 90d0c0e6e..cc7dd824e 100644 --- a/industry/modbus/freemodbus/nuttx/portevent_m.c +++ b/modbus/nuttx/portevent_m.c @@ -1,9 +1,10 @@ /**************************************************************************** - * apps/industry/modbus/nuttx/portevent_m.c + * apps/modbus/nuttx/portevent_m.c * - * SPDX-License-Identifier: BSD-3-Clause - * SPDX-FileCopyrightText: 2006 Christian Walter - * SPDX-FileCopyrightText: 2016 Vytautas Lukenskas + * FreeModbus Library: NuttX Modbus Master Port + * Original work (c) 2006 Christian Walter + * Modified work (c) 2016 Vytautas Lukenskas + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -93,7 +94,7 @@ bool xMBMasterPortEventPost(eMBMasterEventType eEvent) return true; } -bool xMBMasterPortEventGet(eMBMasterEventType *eEvent) +bool xMBMasterPortEventGet(eMBMasterEventType * eEvent) { bool xEventHappened = false; @@ -101,6 +102,7 @@ bool xMBMasterPortEventGet(eMBMasterEventType *eEvent) if (eQueuedEvent & ~(WAITER_EVENTS)) { + /* Fetch events by priority */ if (eQueuedEvent & EV_MASTER_READY) @@ -134,9 +136,9 @@ bool xMBMasterPortEventGet(eMBMasterEventType *eEvent) else { /* Poll the serial device. The serial device timeouts if no characters - * have been received within for t3.5 during an active transmission or - * if nothing happens within a specified amount of time. Both timeouts - * are configured from the timer init functions. + * have been received within for t3.5 during an active transmission or if + * nothing happens within a specified amount of time. Both timeouts are + * configured from the timer init functions. */ xMBMasterPortSerialPoll(); @@ -186,7 +188,6 @@ bool xMBMasterRunResTake(int32_t lTimeOut) { return false; } - return true; } else @@ -197,7 +198,6 @@ bool xMBMasterRunResTake(int32_t lTimeOut) { return false; } - return true; } } @@ -227,7 +227,7 @@ void vMBMasterRunResRelease(void) */ void vMBMasterErrorCBRespondTimeout(uint8_t ucDestAddress, - const uint8_t *pucPDUData, + const uint8_t * pucPDUData, uint16_t usPDULength) { xMBMasterPortEventPost(EV_MASTER_ERROR_RESPOND_TIMEOUT); @@ -243,7 +243,7 @@ void vMBMasterErrorCBRespondTimeout(uint8_t ucDestAddress, */ void vMBMasterErrorCBReceiveData(uint8_t ucDestAddress, - const uint8_t *pudPDUData, + const uint8_t * pudPDUData, uint16_t usPDULength) { xMBMasterPortEventPost(EV_MASTER_ERROR_RECEIVE_DATA); @@ -259,7 +259,7 @@ void vMBMasterErrorCBReceiveData(uint8_t ucDestAddress, */ void vMBMasterErrorCBExecuteFunction(uint8_t ucDestAddress, - const uint8_t *pucPDUData, + const uint8_t * pucPDUData, uint16_t usPDULength) { xMBMasterPortEventPost(EV_MASTER_ERROR_EXECUTE_FUNCTION); @@ -274,8 +274,7 @@ void vMBMasterCBRequestSuccess(void) xMBMasterPortEventPost(EV_MASTER_PROCESS_SUCCESS); } -/* This function will wait for Modbus Master request finish - * and return result. +/* This function will wait for Modbus Master request finish and return result. */ eMBMasterReqErrCode eMBMasterWaitRequestFinish(void) @@ -304,7 +303,6 @@ eMBMasterReqErrCode eMBMasterWaitRequestFinish(void) { eErrStatus = MB_MRE_EXE_FUN; } - eQueuedEvent &= ~WAITER_EVENTS; } diff --git a/industry/modbus/freemodbus/nuttx/portother.c b/modbus/nuttx/portother.c similarity index 83% rename from industry/modbus/freemodbus/nuttx/portother.c rename to modbus/nuttx/portother.c index b6c4731d9..a2e0070a0 100644 --- a/industry/modbus/freemodbus/nuttx/portother.c +++ b/modbus/nuttx/portother.c @@ -1,8 +1,9 @@ /**************************************************************************** - * apps/industry/modbus/nuttx/portother.c + * apps/modbus/nuttx/portother.c * - * SPDX-License-Identifier: BSD-3-Clause - * SPDX-FileCopyrightText: 2006 Christian Walter + * FreeModbus Library: NuttX Port + * Copyright (c) 2006 Christian Walter + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -73,22 +74,17 @@ void vMBPortLogFile(FILE * fNewLogFile) fLogFile = fNewLogFile; } -#ifndef CONFIG_INDUSTRY_MODBUS_DISABLE_LOG -void vMBPortLog(eMBPortLogLevel eLevel, const char * szModule, - const char * szFmt, ...) +void vMBPortLog(eMBPortLogLevel eLevel, const char * szModule, const char * szFmt, ...) { char szBuf[512]; int i; va_list args; FILE *fOutput = fLogFile == NULL ? stderr : fLogFile; - static const char *arszLevel2Str[] = - { - "ERROR", "WARN", "INFO", "DEBUG" - }; + static const char *arszLevel2Str[] = { "ERROR", "WARN", "INFO", "DEBUG" }; + + i = snprintf(szBuf, NELEMS(szBuf), "%s: %s: ", arszLevel2Str[eLevel], szModule); - i = snprintf(szBuf, NELEMS(szBuf), "%s: %s: ", - arszLevel2Str[eLevel], szModule); if (i != 0) { va_start(args, szFmt); @@ -104,15 +100,13 @@ void vMBPortLog(eMBPortLogLevel eLevel, const char * szModule, } } } -#endif void vMBPortEnterCritical(void) { int ret = pthread_mutex_lock(&xLock); if (ret != 0) { - vMBPortLog(MB_LOG_ERROR, "OTHER", - "Locking primitive failed: %d\n", ret); + vMBPortLog(MB_LOG_ERROR, "OTHER", "Locking primitive failed: %d\n", ret); } } @@ -121,7 +115,6 @@ void vMBPortExitCritical(void) int ret = pthread_mutex_unlock(&xLock); if (ret != 0) { - vMBPortLog(MB_LOG_ERROR, - "OTHER", "Locking primitive failed: %d\n", ret); + vMBPortLog(MB_LOG_ERROR, "OTHER", "Locking primitive failed: %d\n", ret); } } diff --git a/industry/modbus/freemodbus/nuttx/portother_m.c b/modbus/nuttx/portother_m.c similarity index 93% rename from industry/modbus/freemodbus/nuttx/portother_m.c rename to modbus/nuttx/portother_m.c index 9ee337f2a..befb28a89 100644 --- a/industry/modbus/freemodbus/nuttx/portother_m.c +++ b/modbus/nuttx/portother_m.c @@ -1,8 +1,9 @@ /**************************************************************************** - * apps/industry/modbus/nuttx/portother_m.c + * apps/modbus/nuttx/portother_m.c * - * SPDX-License-Identifier: BSD-3-Clause - * SPDX-FileCopyrightText: 2006 Christian Walter + * FreeModbus Library: NuttX Port + * Copyright (c) 2006 Christian Walter + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -83,10 +84,7 @@ void vMBMasterPortLog(eMBPortLogLevel eLevel, const char * szModule, va_list args; FILE *fOutput = fLogFile == NULL ? stderr : fLogFile; - static const char *arszLevel2Str[] = - { - "ERROR", "WARN", "INFO", "DEBUG" - }; + static const char *arszLevel2Str[] = { "ERROR", "WARN", "INFO", "DEBUG" }; i = snprintf(szBuf, NELEMS(szBuf), "%s: %s: ", arszLevel2Str[eLevel], szModule); diff --git a/industry/modbus/freemodbus/nuttx/portserial.c b/modbus/nuttx/portserial.c similarity index 91% rename from industry/modbus/freemodbus/nuttx/portserial.c rename to modbus/nuttx/portserial.c index 4cb502aa5..c8241cfb0 100644 --- a/industry/modbus/freemodbus/nuttx/portserial.c +++ b/modbus/nuttx/portserial.c @@ -1,8 +1,9 @@ /**************************************************************************** - * apps/industry/modbus/nuttx/portserial.c + * apps/modbus/nuttx/portserial.c * - * SPDX-License-Identifier: BSD-3-Clause - * SPDX-FileCopyrightText: 2006 Christian Walter + * FreeModbus Library: NuttX Port + * Copyright (c) 2006 Christian Walter + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -44,7 +45,10 @@ #include #include #include -#include + +#ifdef CONFIG_SERIAL_TERMIOS +# include +#endif #include "port.h" @@ -74,7 +78,9 @@ static uint8_t ucBuffer[BUF_SIZE]; static int uiRxBufferPos; static int uiTxBufferPos; +#ifdef CONFIG_SERIAL_TERMIOS static struct termios xOldTIO; +#endif /**************************************************************************** * Private Function Prototypes @@ -176,7 +182,9 @@ void vMBPortSerialEnable(bool bEnableRx, bool bEnableTx) if (bEnableRx) { +#ifdef CONFIG_SERIAL_TERMIOS tcflush(iSerialFd, TCIFLUSH); +#endif uiRxBufferPos = 0; bRxEnabled = true; } @@ -201,7 +209,10 @@ bool xMBPortSerialInit(uint8_t ucPort, speed_t ulBaudRate, { char szDevice[16]; bool bStatus = true; + +#ifdef CONFIG_SERIAL_TERMIOS struct termios xNewTIO; +#endif snprintf(szDevice, 16, "/dev/ttyS%d", ucPort); @@ -211,10 +222,11 @@ bool xMBPortSerialInit(uint8_t ucPort, speed_t ulBaudRate, szDevice, errno); bStatus = false; } + +#ifdef CONFIG_SERIAL_TERMIOS else if (tcgetattr(iSerialFd, &xOldTIO) != 0) { - vMBPortLog(MB_LOG_ERROR, - "SER-INIT", "Can't get settings from port %s: %d\n", + vMBPortLog(MB_LOG_ERROR, "SER-INIT", "Can't get settings from port %s: %d\n", szDevice, errno); } else @@ -261,24 +273,22 @@ bool xMBPortSerialInit(uint8_t ucPort, speed_t ulBaudRate, * * (1) In NuttX, cfset[i|o]speed always return OK so failures will * really only be reported when tcsetattr() is called. - * (2) NuttX does not support separate input and output speeds so - * it is not necessary to call both cfsetispeed() and + * (2) NuttX does not support separate input and output speeds so it + * is not necessary to call both cfsetispeed() and * cfsetospeed(), and * (3) In NuttX, the input value to cfiset[i|o]speed is not - * encoded, but is the absolute baud value. The following - * might not be + * encoded, but is the absolute baud value. The following might + * not be */ if (cfsetispeed(&xNewTIO, ulBaudRate) != 0 /* || cfsetospeed(&xNewTIO, ulBaudRate) != 0 */) { - vMBPortLog(MB_LOG_ERROR, "SER-INIT", - "Can't set baud rate %ld for port %s: %d\n", + vMBPortLog(MB_LOG_ERROR, "SER-INIT", "Can't set baud rate %ld for port %s: %d\n", ulBaudRate, szDevice, errno); } else if (tcsetattr(iSerialFd, TCSANOW, &xNewTIO) != 0) { - vMBPortLog(MB_LOG_ERROR, - "SER-INIT", "Can't set settings for port %s: %d\n", + vMBPortLog(MB_LOG_ERROR, "SER-INIT", "Can't set settings for port %s: %d\n", szDevice, errno); } else @@ -288,6 +298,7 @@ bool xMBPortSerialInit(uint8_t ucPort, speed_t ulBaudRate, } } } +#endif return bStatus; } @@ -310,7 +321,9 @@ void vMBPortClose(void) { if (iSerialFd != -1) { +#ifdef CONFIG_SERIAL_TERMIOS tcsetattr(iSerialFd, TCSANOW, &xOldTIO); +#endif close(iSerialFd); iSerialFd = -1; } @@ -346,8 +359,7 @@ bool xMBPortSerialPoll(void) } else { - vMBPortLog(MB_LOG_ERROR, - "SER-POLL", "read failed on serial device: %d\n", + vMBPortLog(MB_LOG_ERROR, "SER-POLL", "read failed on serial device: %d\n", errno); bStatus = false; } @@ -364,8 +376,7 @@ bool xMBPortSerialPoll(void) if (!prvbMBPortSerialWrite(&ucBuffer[0], uiTxBufferPos)) { - vMBPortLog(MB_LOG_ERROR, - "SER-POLL", "write failed on serial device: %d\n", + vMBPortLog(MB_LOG_ERROR, "SER-POLL", "write failed on serial device: %d\n", errno); bStatus = false; } diff --git a/industry/modbus/freemodbus/nuttx/portserial_m.c b/modbus/nuttx/portserial_m.c similarity index 92% rename from industry/modbus/freemodbus/nuttx/portserial_m.c rename to modbus/nuttx/portserial_m.c index d7fc25526..30dd1c215 100644 --- a/industry/modbus/freemodbus/nuttx/portserial_m.c +++ b/modbus/nuttx/portserial_m.c @@ -1,9 +1,10 @@ /**************************************************************************** - * apps/industry/modbus/nuttx/portserial_m.c + * apps/modbus/nuttx/portserial_m.c * - * SPDX-License-Identifier: BSD-3-Clause - * SPDX-FileCopyrightText: 2006 Christian Walter - * SPDX-FileCopyrightText: 2016 Vytautas Lukenskas + * FreeModbus Library: NuttX Modbus Master Port + * Original work (c) 2006 Christian Walter + * Modified work (c) 2016 Vytautas Lukenskas + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -45,7 +46,10 @@ #include #include #include -#include + +#ifdef CONFIG_SERIAL_TERMIOS +# include +#endif #include "port.h" @@ -78,7 +82,9 @@ static uint8_t ucBuffer[BUF_SIZE]; static int uiRxBufferPos; static int uiTxBufferPos; +#ifdef CONFIG_SERIAL_TERMIOS static struct termios xOldTIO; +#endif /**************************************************************************** * Private Function Prototypes @@ -86,8 +92,7 @@ static struct termios xOldTIO; static bool prvbMBMasterPortSerialRead(uint8_t *pucBuffer, uint16_t usNBytes, uint16_t *usNBytesRead); -static bool prvbMBMasterPortSerialWrite(uint8_t *pucBuffer, - uint16_t usNBytes); +static bool prvbMBMasterPortSerialWrite(uint8_t *pucBuffer, uint16_t usNBytes); /**************************************************************************** * Private Functions @@ -142,8 +147,7 @@ static bool prvbMBMasterPortSerialRead(uint8_t *pucBuffer, uint16_t usNBytes, return bResult; } -static bool prvbMBMasterPortSerialWrite(uint8_t *pucBuffer, - uint16_t usNBytes) +static bool prvbMBMasterPortSerialWrite(uint8_t *pucBuffer, uint16_t usNBytes) { ssize_t res; size_t left = (size_t) usNBytes; @@ -182,7 +186,9 @@ void vMBMasterPortSerialEnable(bool bEnableRx, bool bEnableTx) if (bEnableRx) { +#ifdef CONFIG_SERIAL_TERMIOS tcflush(iSerialFd, TCIFLUSH); +#endif uiRxBufferPos = 0; bRxEnabled = true; } @@ -207,7 +213,10 @@ bool xMBMasterPortSerialInit(uint8_t ucPort, speed_t ulBaudRate, { char szDevice[16]; bool bStatus = true; + +#ifdef CONFIG_SERIAL_TERMIOS struct termios xNewTIO; +#endif snprintf(szDevice, 16, "/dev/ttyS%d", ucPort); @@ -218,6 +227,8 @@ bool xMBMasterPortSerialInit(uint8_t ucPort, speed_t ulBaudRate, szDevice, errno); bStatus = false; } + +#ifdef CONFIG_SERIAL_TERMIOS else if (tcgetattr(iSerialFd, &xOldTIO) != 0) { vMBMasterPortLog(MB_LOG_ERROR, "SER-INIT", @@ -269,12 +280,12 @@ bool xMBMasterPortSerialInit(uint8_t ucPort, speed_t ulBaudRate, * * (1) In NuttX, cfset[i|o]speed always return OK so failures will * really only be reported when tcsetattr() is called. - * (2) NuttX does not support separate input and output speeds so - * it is not necessary to call both cfsetispeed() and + * (2) NuttX does not support separate input and output speeds so it + * is not necessary to call both cfsetispeed() and * cfsetospeed(), and * (3) In NuttX, the input value to cfiset[i|o]speed is not - * encoded, but is the absolute baud value. The following - * might not be + * encoded, but is the absolute baud value. The following might + * not be */ if (cfsetispeed(&xNewTIO, ulBaudRate) != 0 /* || cfsetospeed(&xNewTIO, ulBaudRate) != 0 */) @@ -296,6 +307,7 @@ bool xMBMasterPortSerialInit(uint8_t ucPort, speed_t ulBaudRate, } } } +#endif return bStatus; } @@ -314,17 +326,19 @@ bool xMBMasterPortSerialSetTimeout(uint32_t ulNewTimeoutMs) return true; } -void vMBMasterPortClose(void) +void vMBMasterPortClose( void ) { if (iSerialFd != -1) { +#ifdef CONFIG_SERIAL_TERMIOS tcsetattr(iSerialFd, TCSANOW, &xOldTIO); +#endif close(iSerialFd); iSerialFd = -1; } } -bool xMBMasterPortSerialPoll(void) +bool xMBMasterPortSerialPoll( void ) { bool bStatus = true; uint16_t usBytesRead; diff --git a/industry/modbus/freemodbus/nuttx/porttimer.c b/modbus/nuttx/porttimer.c similarity index 92% rename from industry/modbus/freemodbus/nuttx/porttimer.c rename to modbus/nuttx/porttimer.c index d09561f4b..c3115868f 100644 --- a/industry/modbus/freemodbus/nuttx/porttimer.c +++ b/modbus/nuttx/porttimer.c @@ -1,8 +1,9 @@ /**************************************************************************** - * apps/industry/modbus/nuttx/porttimer.c + * apps/modbus/nuttx/porttimer.c * - * SPDX-License-Identifier: BSD-3-Clause - * SPDX-FileCopyrightText: 2006 Christian Walter + * FreeModbus Library: NuttX Port + * Copyright (c) 2006 Christian Walter + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -67,12 +68,12 @@ bool xMBPortTimersInit(uint16_t usTim1Timerout50us) return xMBPortSerialSetTimeout(ulTimeOut); } -void xMBPortTimersClose(void) +void xMBPortTimersClose() { /* Does not use any hardware resources. */ } -void vMBPortTimerPoll(void) +void vMBPortTimerPoll() { uint32_t ulDeltaMS; struct timeval xTimeCur; @@ -100,7 +101,7 @@ void vMBPortTimerPoll(void) } } -void vMBPortTimersEnable(void) +void vMBPortTimersEnable() { int res = gettimeofday(&xTimeLast, NULL); @@ -108,7 +109,7 @@ void vMBPortTimersEnable(void) bTimeoutEnable = true; } -void vMBPortTimersDisable(void) +void vMBPortTimersDisable() { bTimeoutEnable = false; } diff --git a/industry/modbus/freemodbus/nuttx/porttimer_m.c b/modbus/nuttx/porttimer_m.c similarity index 89% rename from industry/modbus/freemodbus/nuttx/porttimer_m.c rename to modbus/nuttx/porttimer_m.c index 8d9f3f3af..af595f12a 100644 --- a/industry/modbus/freemodbus/nuttx/porttimer_m.c +++ b/modbus/nuttx/porttimer_m.c @@ -1,9 +1,10 @@ /**************************************************************************** - * apps/industry/modbus/nuttx/porttimer_m.c + * apps/modbus/nuttx/porttimer_m.c * - * SPDX-License-Identifier: BSD-3-Clause - * SPDX-FileCopyrightText: 2006 Christian Walter - * SPDX-FileCopyrightText: 2016 Vytautas Lukenskas + * FreeModbus Library: NuttX Modbus Master Port + * Original work (c) 2006 Christian Walter + * Modified work (c) 2016 Vytautas Lukenskas + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -74,7 +75,7 @@ bool bTimeoutEnable; /* timeout is active */ * Private Functions ****************************************************************************/ -void vMBMasterPortTimersEnable(void) +void vMBMasterPortTimersEnable( void ) { int res = gettimeofday(&xTimeLast, NULL); @@ -113,33 +114,33 @@ bool xMBMasterPortTimersInit(uint16_t usTimeOut50us) return xMBMasterPortSerialSetTimeout(ulTimeOut); } -void xMBMasterPortTimersClose(void) +void xMBMasterPortTimersClose() { /* Does not use any hardware resources. */ } -INLINE void vMBMasterPortTimersT35Enable(void) +INLINE void vMBMasterPortTimersT35Enable( void ) { vMBMasterPortTimersEnable(); ulTimeOut = ulTimeoutT35; vMBMasterSetCurTimerMode(MB_TMODE_T35); } -INLINE void vMBMasterPortTimersConvertDelayEnable(void) +INLINE void vMBMasterPortTimersConvertDelayEnable( void ) { vMBMasterPortTimersEnable(); ulTimeOut = ulTimeoutConvertDelay; vMBMasterSetCurTimerMode(MB_TMODE_CONVERT_DELAY); } -INLINE void vMBMasterPortTimersRespondTimeoutEnable(void) +INLINE void vMBMasterPortTimersRespondTimeoutEnable( void ) { vMBMasterPortTimersEnable(); ulTimeOut = ulTimeoutResponse; - vMBMasterSetCurTimerMode(MB_TMODE_RESPOND_TIMEOUT); + vMBMasterSetCurTimerMode( MB_TMODE_RESPOND_TIMEOUT ); } -void vMBMasterPortTimerPoll(void) +void vMBMasterPortTimerPoll( void ) { uint32_t ulDeltaMS; struct timeval xTimeCur; @@ -167,7 +168,7 @@ void vMBMasterPortTimerPoll(void) } } -void vMBMasterPortTimersDisable(void) +void vMBMasterPortTimersDisable() { bTimeoutEnable = false; } diff --git a/industry/modbus/freemodbus/rtu/Make.defs b/modbus/rtu/Make.defs similarity index 88% rename from industry/modbus/freemodbus/rtu/Make.defs rename to modbus/rtu/Make.defs index 46656017d..5051c6c40 100644 --- a/industry/modbus/freemodbus/rtu/Make.defs +++ b/modbus/rtu/Make.defs @@ -1,7 +1,5 @@ ############################################################################ -# apps/industry/modbus/freemodbus/rtu/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 +# apps/modbus/rtu/Make.defs # # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with @@ -40,6 +38,6 @@ endif DEPPATH += --dep-path rtu VPATH += :rtu -CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/industry/modbus/freemodbus/rtu +CFLAGS += ${shell $(INCDIR) "$(CC)" $(APPDIR)/modbus/rtu} endif diff --git a/industry/modbus/freemodbus/rtu/mbcrc.c b/modbus/rtu/mbcrc.c similarity index 96% rename from industry/modbus/freemodbus/rtu/mbcrc.c rename to modbus/rtu/mbcrc.c index df16f13e0..5996f6408 100644 --- a/industry/modbus/freemodbus/rtu/mbcrc.c +++ b/modbus/rtu/mbcrc.c @@ -1,8 +1,9 @@ /**************************************************************************** - * apps/industry/modbus/rtu/mbcrc.c + * apps/modbus/rtu/mbcrc.c * - * SPDX-License-Identifier: BSD-3-Clause - * SPDX-FileCopyrightText: 2006 Christian Walter + * FreeModbus Library: A portable Modbus implementation for Modbus ASCII/RTU. + * Copyright (c) 2006 Christian Walter + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/industry/modbus/freemodbus/rtu/mbcrc.h b/modbus/rtu/mbcrc.h similarity index 92% rename from industry/modbus/freemodbus/rtu/mbcrc.h rename to modbus/rtu/mbcrc.h index 56d3db5f8..707feb8ef 100644 --- a/industry/modbus/freemodbus/rtu/mbcrc.h +++ b/modbus/rtu/mbcrc.h @@ -1,8 +1,9 @@ /**************************************************************************** * apps/modutils/rtu/mbcrc.h * - * SPDX-License-Identifier: BSD-3-Clause - * SPDX-FileCopyrightText: 2006 Christian Walter + * FreeModbus Library: A portable Modbus implementation for Modbus ASCII/RTU. + * Copyright (c) 2006 Christian Walter + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/industry/modbus/freemodbus/rtu/mbrtu.c b/modbus/rtu/mbrtu.c similarity index 98% rename from industry/modbus/freemodbus/rtu/mbrtu.c rename to modbus/rtu/mbrtu.c index ead36d164..eb0d57d62 100644 --- a/industry/modbus/freemodbus/rtu/mbrtu.c +++ b/modbus/rtu/mbrtu.c @@ -1,8 +1,9 @@ /**************************************************************************** - * apps/industry/modbus/rtu/mbrtu.c + * apps/modbus/rtu/mbrtu.c * - * SPDX-License-Identifier: BSD-3-Clause - * SPDX-FileCopyrightText: 2006 Christian Walter + * FreeModbus Library: A portable Modbus implementation for Modbus ASCII/RTU. + * Copyright (c) 2006 Christian Walter + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -57,7 +58,7 @@ #define MB_SER_PDU_PDU_OFF 1 /* Offset of Modbus-PDU in Ser-PDU. */ /**************************************************************************** - * Private Typess + * Private Type Definitions ****************************************************************************/ typedef enum diff --git a/industry/modbus/freemodbus/rtu/mbrtu.h b/modbus/rtu/mbrtu.h similarity index 93% rename from industry/modbus/freemodbus/rtu/mbrtu.h rename to modbus/rtu/mbrtu.h index ff31a1844..7ef009f17 100644 --- a/industry/modbus/freemodbus/rtu/mbrtu.h +++ b/modbus/rtu/mbrtu.h @@ -1,8 +1,9 @@ /**************************************************************************** - * apps/industry/modbus/rtu/mbrtu.h + * apps/modbus/rtu/mbrtu.h * - * SPDX-License-Identifier: BSD-3-Clause - * SPDX-FileCopyrightText: 2006 Christian Walter + * FreeModbus Library: A portable Modbus implementation for Modbus ASCII/RTU. + * Copyright (c) 2006 Christian Walter + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/industry/modbus/freemodbus/rtu/mbrtu_m.c b/modbus/rtu/mbrtu_m.c similarity index 98% rename from industry/modbus/freemodbus/rtu/mbrtu_m.c rename to modbus/rtu/mbrtu_m.c index 4a67a0508..d835b5a7f 100644 --- a/industry/modbus/freemodbus/rtu/mbrtu_m.c +++ b/modbus/rtu/mbrtu_m.c @@ -1,8 +1,9 @@ /**************************************************************************** - * apps/industry/modbus/rtu/mbrtu_m.c + * apps/modbus/rtu/mbrtu_m.c * - * SPDX-License-Identifier: BSD-3-Clause - * SPDX-FileCopyrightText: 2013 China Beijing Armink + * FreeModbus Library: A portable Modbus implementation for Modbus ASCII/RTU. + * Copyright (c) 2013 China Beijing Armink + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -64,7 +65,7 @@ #define MB_SER_PDU_PDU_OFF 1 /* Offset of Modbus-PDU in Ser-PDU. */ /**************************************************************************** - * Private Typess + * Private Type Definitions ****************************************************************************/ typedef enum @@ -277,7 +278,7 @@ bool xMBMasterRTUReceiveFSM(void) /* Always read the character. */ - xMBMasterPortSerialGetByte((int8_t *) & ucByte); + xMBMasterPortSerialGetByte((uint8_t *) & ucByte); switch (eRcvState) { @@ -396,10 +397,6 @@ bool xMBMasterRTUTransmitFSM(void) } } break; - - case STATE_M_TX_XFWR: - default: - break; } return xNeedPoll; diff --git a/industry/modbus/freemodbus/rtu/mbrtu_m.h b/modbus/rtu/mbrtu_m.h similarity index 92% rename from industry/modbus/freemodbus/rtu/mbrtu_m.h rename to modbus/rtu/mbrtu_m.h index b59652b59..2a58a3130 100644 --- a/industry/modbus/freemodbus/rtu/mbrtu_m.h +++ b/modbus/rtu/mbrtu_m.h @@ -1,8 +1,9 @@ /**************************************************************************** - * apps/industry/modbus/rtu/mbrtu_m.h + * apps/modbus/rtu/mbrtu_m.h * - * SPDX-License-Identifier: BSD-3-Clause - * SPDX-FileCopyrightText: 2013 China Beijing Armink + * FreeModbus Library: A portable Modbus implementation for Modbus ASCII/RTU. + * Copyright (c) 2013 China Beijing Armink + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/industry/modbus/freemodbus/tcp/Make.defs b/modbus/tcp/Make.defs similarity index 87% rename from industry/modbus/freemodbus/tcp/Make.defs rename to modbus/tcp/Make.defs index 281a9a5be..f38291084 100644 --- a/industry/modbus/freemodbus/tcp/Make.defs +++ b/modbus/tcp/Make.defs @@ -1,7 +1,5 @@ ############################################################################ -# apps/industry/modbus/freemodbus/tcp/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 +# apps/modbus/tcp/Make.defs # # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with @@ -26,6 +24,6 @@ CSRCS += mbtcp.c DEPPATH += --dep-path tcp VPATH += :tcp -CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/industry/modbus/freemodbus/tcp +CFLAGS += ${shell $(INCDIR) "$(CC)" $(APPDIR)/modbus/tcp} endif diff --git a/industry/modbus/freemodbus/tcp/mbtcp.c b/modbus/tcp/mbtcp.c similarity index 96% rename from industry/modbus/freemodbus/tcp/mbtcp.c rename to modbus/tcp/mbtcp.c index 6957effb9..67d503ec7 100644 --- a/industry/modbus/freemodbus/tcp/mbtcp.c +++ b/modbus/tcp/mbtcp.c @@ -1,8 +1,9 @@ /**************************************************************************** - * apps/industry/modbus/tcp/mbtcp.c + * apps/modbus/tcp/mbtcp.c * - * SPDX-License-Identifier: BSD-3-Clause - * SPDX-FileCopyrightText: 2006 Christian Walter + * FreeModbus Library: A portable Modbus implementation for Modbus ASCII/RTU. + * Copyright (c) 2006 Christian Walter + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/industry/modbus/freemodbus/tcp/mbtcp.h b/modbus/tcp/mbtcp.h similarity index 93% rename from industry/modbus/freemodbus/tcp/mbtcp.h rename to modbus/tcp/mbtcp.h index 26e380cb9..b44de01f1 100644 --- a/industry/modbus/freemodbus/tcp/mbtcp.h +++ b/modbus/tcp/mbtcp.h @@ -1,8 +1,9 @@ /**************************************************************************** - * apps/industry/modbus/tcp/mbtcp.h + * apps/modbus/tcp/mbtcp.h * - * SPDX-License-Identifier: BSD-3-Clause - * SPDX-FileCopyrightText: 2006 Christian Walter + * FreeModbus Library: A portable Modbus implementation for Modbus ASCII/RTU. + * Copyright (c) 2006 Christian Walter + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/netutils/CMakeLists.txt b/netutils/CMakeLists.txt deleted file mode 100644 index e950ed6ff..000000000 --- a/netutils/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -# ############################################################################## -# apps/netutils/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -nuttx_add_subdirectory() - -nuttx_generate_kconfig(MENUDESC "Network Utilities") diff --git a/netutils/Make.defs b/netutils/Make.defs index bd7c0e0cc..d08431e24 100644 --- a/netutils/Make.defs +++ b/netutils/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/netutils/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/netutils/Makefile b/netutils/Makefile index 87fb891a1..6ec7c1884 100644 --- a/netutils/Makefile +++ b/netutils/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/netutils/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/netutils/README.md b/netutils/README.md new file mode 100644 index 000000000..3ddf9a93f --- /dev/null +++ b/netutils/README.md @@ -0,0 +1,138 @@ +# Network Utilities + +## Contents + +- uIP Applications +- Other Network Applications +- Tips for Using Telnetd +- Tips for Using DHCPC + +## uIP Applications + +This directory contains most of the network applications contained under the +`uIP-1.0` apps directory. As the uIP `apps/README.md` says, these applications +_are not all heavily tested_. These uIP-based apps include: + +- `dhcpc` โ€“ Dynamic Host Configuration Protocol (DHCP) client. See + `apps/include/netutils/dhcpc.h` for interface information. + +- `smtp` โ€“ Simple Mail Transfer Protocol (SMTP) client. See + `apps/include/netutils/smtp.h` for interface information. + +- `webclient` โ€“ HTTP web client. See `apps/include/netutils/webclient.h` for + interface information. + +- `webserver` โ€“ HTTP web server. See `apps/include/netutils/httpd.h` for + interface information. + +You may find additional information on these apps in the uIP forum accessible +through: http://www.sics.se/~adam/uip/index.php/Main_Page. Some of these (such +as the uIP web server) have grown some additional functionality due primarily to +NuttX user contributions. + +## Other Network Applications + +Additional applications that were not part of uIP (but which are highly +influenced by uIP) include: + +- `dhcpd` โ€“ Dynamic Host Configuration Protocol (DHCP) server. See + `apps/include/netutils/dhcpd.h` for interface information. + +- `discover` โ€“ This daemon is useful for discovering devices in local networks, + especially with DHCP configured devices. It listens for UDP broadcasts which + also can include a device class so that groups of devices can be discovered. + It is also possible to address all classes with a kind of broadcast discover. + (Contributed by Max Holtzberg). + +- `esp8266` โ€“ An ESP8266 networking layer contributed by Pierre-Noel Bouteville. + +- `json` โ€“ cJSON is an ultra-lightweight, portable, single-file, + simple-as-can-be ANSI-C compliant JSON parser, under MIT license. Embeddable + Lightweight XML-RPC Server discussed at + http://www.drdobbs.com/web-development/an-embeddable-lightweight-xml-rpc-server/184405364. + + This code was taken from http://sourceforge.net/projects/cjson/ and adapted + for NuttX by Darcy Gong. + +- `tftpc` โ€“ TFTP client. See `apps/include/netutils/tftp.h` for interface + information. + +- `telnetc` โ€“ This is a port of libtelnet to NuttX. This is a public domain + Telnet client library available from + https://github.com/seanmiddleditch/libtelnet modified for use with NuttX. + Original Authors: Sean Middleditch , Jack Kelly + and Katherine Flavel + +- `telnetd` โ€“ TELNET server. This is the Telnet logic adapted from uIP and + generalized for use as the front end to any shell. The telnet daemon creates + sessions that are _wrapped_ as character devices and mapped to `stdin`, + `stdout` and `stderr`. Now the telnet session can be inherited by spawned + tasks. + +- `ftpc` โ€“ FTP client. See `apps/include/netutils/ftpc.h` for interface + information. + +- `ftpd` โ€“ FTP server. See `apps/include/netutils/ftpd.h` for interface + information. + +- `ntpclient` โ€“ This is a fragmentary NTP client. It neither well-tested nor + mature nor complete at this point in time. + +- `thttpd` โ€“ This is a port of Jef Poskanzer's THTTPD HTPPD server. See + http://acme.com/software/thttpd/ for general THTTPD information. See + `apps/include/netutils/thttpd.h` for interface information. Applications using + this `thttpd` will need to provide the following definitions in the + `defconfig` file to select the appropriate `netutils` libraries: + + ```conf + CONFIG_NETUTILS_NETLIB=y + CONFIG_NETUTILS_THTTPD=y + ``` + +- `xmlrpc` โ€“ The Embeddable Lightweight XML-RPC Server discussed at + http://www.drdobbs.com/web-development/an-embeddable-lightweight-xml-rpc-server/184405364 + +- `ping` โ€“ This is an unfinished implementation of ping and ping6 using raw + sockets. It is not yet hooked into the configuration or build systems. + + Current `ping`/`ping6` logic in NSH makes illegal calls into the OS in order + to implement `ping`/`ping6`. One correct implementation would be to use raw + sockets to implement `ping`/`ping6` as a user application. This is a first cut + at such an implementation. + +## Tips for Using Telnetd + +Telnetd is set up to be the front end for a shell. The primary use of Telnetd in +NuttX is to support the NuttShell (NSH) Telnet front end. See +`apps/include/netutils/telnetd.h` for information about how to incorporate +Telnetd into your custom applications. + +To enable and link the Telnetd daemon, you need to include the following in in +your defconfig file: + +```conf +CONFIG_NETUTILS_NETLIB=y +CONFIG_NETUTILS_TELNETD=y +``` + +Also if the Telnet console is enabled, make sure that you have the following set +in the NuttX configuration file or else the performance will be very bad +(because there will be only one character per TCP transfer): + +- `CONFIG_STDIO_BUFFER_SIZE` โ€“ Some value `>= 64`. +- `CONFIG_STDIO_LINEBUFFER=y` โ€“ Since Telnetd is line oriented, line buffering + is optimal. + +## Tips for Using DHCPC + +If you use DHCPC/D, then some special configuration network options are +required. These include: + +- `CONFIG_NET=y` +- `CONFIG_NET_UDP=y` โ€“ UDP support is required for DHCP (as well as various + other UDP-related configuration settings). +- `CONFIG_NET_BROADCAST=y` โ€“ UDP broadcast support is needed. +- `CONFIG_NET_ETH_PKTSIZE=650` or larger. The client must be prepared to receive + DHCP messages of up to `576` bytes (excluding Ethernet, IP or UDP headers and + FCS). **Note**: Note that the actual MTU setting will depend upon the specific + link protocol. Here Ethernet is indicated. diff --git a/netutils/bare/Kconfig b/netutils/bare/Kconfig deleted file mode 100644 index 2f0fa3df2..000000000 --- a/netutils/bare/Kconfig +++ /dev/null @@ -1,22 +0,0 @@ -config NETUTILS_BARE - bool "Binary Application Record Encoding (BARE)" - default n - depends on ALLOW_MIT_COMPONENTS - ---help--- - BARE is a simple binary representation for structured - application data. - - See https://baremessages.org/ - - cbare is an MIT-licensed I/O agnostic C implementation of the - BARE message encoding that is used when this option is enabled. - -if NETUTILS_BARE - -config NETUTILS_BARE_TEST - bool "Enable baretest" - default n - ---help--- - Enable baretest -- BARE test application. - -endif diff --git a/netutils/bare/Make.defs b/netutils/bare/Make.defs deleted file mode 100644 index 9a6b4f538..000000000 --- a/netutils/bare/Make.defs +++ /dev/null @@ -1,27 +0,0 @@ -############################################################################ -# apps/netutils/bare/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_NETUTILS_BARE),) -CONFIGURED_APPS += $(APPDIR)/netutils/bare -CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/netutils/bare/cbare/src -CXXFLAGS += ${INCDIR_PREFIX}$(APPDIR)/netutils/bare/cbare/src -endif diff --git a/netutils/bare/Makefile b/netutils/bare/Makefile deleted file mode 100644 index e851edf15..000000000 --- a/netutils/bare/Makefile +++ /dev/null @@ -1,58 +0,0 @@ -############################################################################ -# apps/netutils/bare/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -BARE_CBARE_DIR = cbare - -DEPPATH += --dep-path $(BARE_CBARE_DIR)$(DELIM)src -VPATH += :$(BARE_CBARE_DIR)$(DELIM)src - -CFLAGS += -I$(BARE_CBARE_DIR)/src - -CSRCS = $(BARE_CBARE_DIR)/src/alloc.c -CSRCS += $(BARE_CBARE_DIR)/src/cbare.c -CSRCS += $(BARE_CBARE_DIR)/src/die.c - -ifneq ($(CONFIG_NETUTILS_BARE_TEST),) - -PROGNAME = baretest -PRIORITY = 100 -STACKSIZE = 2048 -MODULE = y - -MAINSRC = $(BARE_CBARE_DIR)/test/baretest.c - -endif - -$(BARE_CBARE_DIR): - $(Q) echo "Cloning cbare repo..." - $(Q) git clone --depth=1 https://git.sr.ht/~fsx/cbare - $(Q) patch -p1 --directory=cbare < cbare_porting_for_nuttx.patch - $(Q) touch $(BARE_CBARE_DIR) - -context:: $(BARE_CBARE_DIR) - -distclean:: - $(call DELDIR, $(BARE_CBARE_DIR)) - -include $(APPDIR)/Application.mk diff --git a/netutils/bare/cbare_porting_for_nuttx.patch b/netutils/bare/cbare_porting_for_nuttx.patch deleted file mode 100644 index 73d16f7fd..000000000 --- a/netutils/bare/cbare_porting_for_nuttx.patch +++ /dev/null @@ -1,28 +0,0 @@ -diff --git i/src/cbare.c w/src/cbare.c -index 208639f..a3081fb 100644 ---- i/src/cbare.c -+++ w/src/cbare.c -@@ -4,7 +4,9 @@ - #include "cbare.h" - #include "utf8.h" - -+#ifndef UNUSED - #define UNUSED(x) (void)(x) -+#endif - - enum { - U8SZ = 1, -diff --git i/test/baretest.c w/test/baretest.c -index 1561f4c..9df740f 100644 ---- i/test/baretest.c -+++ w/test/baretest.c -@@ -10,7 +10,9 @@ - #include "alloc.h" - #include "die.h" - -+#ifndef UNUSED - #define UNUSED(x) (void)(x) -+#endif - - #define ARRLEN(a) sizeof(a)/sizeof(a[0]) - diff --git a/netutils/chat/CMakeLists.txt b/netutils/chat/CMakeLists.txt deleted file mode 100644 index eb847a453..000000000 --- a/netutils/chat/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -# ############################################################################## -# apps/netutils/chat/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_NETUTILS_CHAT) - target_sources(apps PRIVATE chat.c) -endif() diff --git a/netutils/chat/Make.defs b/netutils/chat/Make.defs index db5c13717..d6f4ad348 100644 --- a/netutils/chat/Make.defs +++ b/netutils/chat/Make.defs @@ -1,8 +1,6 @@ ############################################################################ # apps/netutils/chat/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -20,6 +18,6 @@ # ############################################################################ -ifneq ($(CONFIG_NETUTILS_CHAT),) +ifeq ($(CONFIG_NETUTILS_CHAT),y) CONFIGURED_APPS += $(APPDIR)/netutils/chat endif diff --git a/netutils/chat/Makefile b/netutils/chat/Makefile index 1c461c852..61b61b7fc 100644 --- a/netutils/chat/Makefile +++ b/netutils/chat/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/netutils/chat/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/netutils/chat/chat.c b/netutils/chat/chat.c index 94f79c500..df42aa537 100644 --- a/netutils/chat/chat.c +++ b/netutils/chat/chat.c @@ -1,10 +1,9 @@ /**************************************************************************** * apps/netutils/chat/chat.c * - * SPDX-License-Identifier: BSD-3-Clause - * SPDX-FileCopyrightText: 2016 Vladimir Komendantskiy. All rights reserved. - * SPDX-FileContributor: Vladimir Komendantskiy - * SPDX-FileContributor: Max Nekludov + * Copyright (C) 2016 Vladimir Komendantskiy. All rights reserved. + * Author: Vladimir Komendantskiy + * Partly based on code by Max Nekludov * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -45,7 +44,7 @@ #include #include -#include +#include #include #include #include @@ -62,7 +61,7 @@ #define CHAT_TOKEN_SIZE 128 /**************************************************************************** - * Private types + * Pivate types ****************************************************************************/ /* Type of singly-linked list of tokens */ @@ -108,8 +107,6 @@ static int chat_tokenise(FAR struct chat *priv, int tok_on_delimiter(void) { - FAR struct chat_token *newtok; - if (!tok_pos && !quoted && !no_termin) { /* a) the first character in the script is a delimiter or @@ -124,29 +121,9 @@ static int chat_tokenise(FAR struct chat *priv, /* Terminate the temporary */ tok_str[tok_pos] = '\0'; - newtok = malloc(sizeof(struct chat_token)); - if (newtok == NULL) - { - /* out of memory */ - - return -ENOMEM; - } - - /* Copy the temporary */ - - newtok->string = strdup(tok_str); - if (newtok->string == NULL) - { - free(newtok); - return -ENOMEM; - } - - newtok->no_termin = no_termin; - newtok->next = NULL; - if (tok) { - tok->next = newtok; + tok->next = malloc(sizeof(struct chat_token)); /* The terminated token becomes previous */ @@ -156,10 +133,26 @@ static int chat_tokenise(FAR struct chat *priv, { /* There was no previous token */ - *first_tok = newtok; + *first_tok = malloc(sizeof(struct chat_token)); tok = *first_tok; } + if (!tok) + { + /* out of memory */ + + return -ENOMEM; + } + + /* Copy the temporary */ + + tok->string = strdup(tok_str); + tok->no_termin = no_termin; + + /* Initialize the next token */ + + tok->next = NULL; + /* Reset the buffer position */ tok_pos = 0; @@ -339,7 +332,7 @@ static int chat_internalise(FAR struct chat *priv, if (rhs) { - len = strlen(tok->string) + 1; + len = strlen(tok->string); if (!tok->no_termin) { /* Add space for the line terminator */ @@ -347,13 +340,13 @@ static int chat_internalise(FAR struct chat *priv, len += 2; } - line->rhs = malloc(len); + line->rhs = malloc(len + 1); if (line->rhs) { /* Copy the token and add the line terminator as appropriate */ - snprintf(line->rhs, len, - tok->no_termin ? "%s" : "%s\r\n", tok->string); + sprintf(line->rhs, tok->no_termin ? "%s" : "%s\r\n", + tok->string); } else { @@ -499,7 +492,7 @@ static void chat_flush(FAR struct chat *priv) char c; ninfo("starting\n"); - while (chat_readb(priv, &c, 0) == 0); + while (chat_readb(priv, (FAR char *) &c, 0) == 0); ninfo("done\n"); } diff --git a/netutils/chat/chat.h b/netutils/chat/chat.h index 4c9a91268..61fcef637 100644 --- a/netutils/chat/chat.h +++ b/netutils/chat/chat.h @@ -1,9 +1,8 @@ /**************************************************************************** * apps/netutils/chat/chat.h * - * SPDX-License-Identifier: BSD-3-Clause - * SPDX-FileCopyrightText: 2016 Vladimir Komendantskiy. All rights reserved. - * SPDX-FileContributor: Vladimir Komendantskiy + * Copyright (C) 2016 Vladimir Komendantskiy. All rights reserved. + * Author: Vladimir Komendantskiy * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/netutils/cjson/CMakeLists.txt b/netutils/cjson/CMakeLists.txt deleted file mode 100644 index 315326793..000000000 --- a/netutils/cjson/CMakeLists.txt +++ /dev/null @@ -1,65 +0,0 @@ -# ############################################################################## -# apps/netutils/cjson/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_NETUTILS_CJSON) - - if(NOT CONFIG_NETUTILS_CJSON_URL) - set(CONFIG_NETUTILS_CJSON_URL - "https://github.com/DaveGamble/cJSON/archive/refs/tags") - endif() - - if(NOT CONFIG_NETUTILS_CJSON_VERSION) - set(CONFIG_NETUTILS_CJSON_VERSION "1.7.10") - endif() - - if(NOT EXISTS ${CMAKE_CURRENT_LIST_DIR}/cJSON) - FetchContent_Declare( - cJSON - DOWNLOAD_NAME "v${CONFIG_NETUTILS_CJSON_VERSION}.tar.gz" - DOWNLOAD_DIR ${CMAKE_CURRENT_LIST_DIR} - URL "${CONFIG_NETUTILS_CJSON_URL}/v${CONFIG_NETUTILS_CJSON_VERSION}.tar.gz" - SOURCE_DIR - ${CMAKE_CURRENT_LIST_DIR}/cJSON - BINARY_DIR - ${NUTTX_APPS_BINDIR}/netutils/cjson/cJSON - DOWNLOAD_NO_PROGRESS true - TIMEOUT 30) - - FetchContent_GetProperties(cJSON) - - if(NOT cJSON_POPULATED) - FetchContent_Populate(cJSON) - endif() - endif() - - if(NOT EXISTS ${NUTTX_APPS_BINDIR}/include/netutils/cJSON.h - OR NOT EXISTS ${NUTTX_APPS_BINDIR}/include/netutils/cJSON_Utils.h) - file(MAKE_DIRECTORY ${NUTTX_APPS_BINDIR}/include/netutils) - file(CREATE_LINK ${CMAKE_CURRENT_LIST_DIR}/cJSON/cJSON.h - ${NUTTX_APPS_BINDIR}/include/netutils/cJSON.h SYMBOLIC) - file(CREATE_LINK ${CMAKE_CURRENT_LIST_DIR}/cJSON/cJSON_Utils.h - ${NUTTX_APPS_BINDIR}/include/netutils/cJSON_Utils.h SYMBOLIC) - endif() - - target_sources(apps PRIVATE cJSON/cJSON.c cJSON/cJSON_Utils.c) - -endif() diff --git a/netutils/cjson/Kconfig b/netutils/cjson/Kconfig index 05773f157..46d9a4c9c 100644 --- a/netutils/cjson/Kconfig +++ b/netutils/cjson/Kconfig @@ -14,34 +14,10 @@ if NETUTILS_CJSON config NETUTILS_CJSON_URL string "URL where cJSON library can be downloaded" - default "https://github.com/DaveGamble/cJSON/archive/refs/tags" + default "https://github.com/DaveGamble/cJSON/archive" config NETUTILS_CJSON_VERSION string "Version number" default "1.7.12" -config NETUTILS_CJSON_TEST - bool "Enable cJSON test" - default n - -if NETUTILS_CJSON_TEST - -config CJSON_UNITY_TEST_DIR - string "cJSON test directory" - default "/data" - -config CJSON_TEST_PRIORITY - int "task priority" - default 100 - -config CJSON_TEST_STACKSIZE - int "stack size" - default 102400 - -config CJSON_NESTING_LIMIT - int "NESTING_LIMIT" - default 100 - -endif # NETUTILS_CJSON_TEST - -endif # NETUTILS_CJSON +endif diff --git a/netutils/cjson/Make.defs b/netutils/cjson/Make.defs index e8f6d6d80..0e4237261 100644 --- a/netutils/cjson/Make.defs +++ b/netutils/cjson/Make.defs @@ -1,8 +1,6 @@ ############################################################################# # apps/netutils/cjson/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -20,6 +18,6 @@ # ############################################################################# -ifneq ($(CONFIG_NETUTILS_CJSON),) +ifeq ($(CONFIG_NETUTILS_CJSON),y) CONFIGURED_APPS += $(APPDIR)/netutils/cjson endif diff --git a/netutils/cjson/Makefile b/netutils/cjson/Makefile index 050e5cf86..8bbb1ee27 100644 --- a/netutils/cjson/Makefile +++ b/netutils/cjson/Makefile @@ -1,8 +1,6 @@ ############################################################################# # apps/netutils/cjson/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -28,13 +26,13 @@ include $(APPDIR)/Make.defs WD := ${shell echo $(CURDIR) | sed -e 's/ /\\ /g'} -CONFIG_NETUTILS_CJSON_URL ?= "https://github.com/DaveGamble/cJSON/archive/refs/tags" +CONFIG_NETUTILS_CJSON_URL ?= "https://github.com/DaveGamble/cJSON/archive" CONFIG_NETUTILS_CJSON_VERSION ?= "1.7.10" CJSON_VERSION = $(patsubst "%",%,$(strip $(CONFIG_NETUTILS_CJSON_VERSION))) CJSON_TARBALL = v$(CJSON_VERSION).tar.gz -CJSON_UNPACKNAME = cJSON +CJSON_UNPACKNAME = cJSON-$(CJSON_VERSION) UNPACK ?= tar -zxf CJSON_UNPACKDIR = $(WD)/$(CJSON_UNPACKNAME) @@ -42,14 +40,12 @@ CJSON_SRCDIR = $(CJSON_UNPACKNAME) APPS_INCDIR = $(APPDIR)$(DELIM)include$(DELIM)netutils -CFLAGS += ${INCDIR_PREFIX}$(APPS_INCDIR) +CFLAGS += ${shell $(INCDIR) "$(CC)" $(APPS_INCDIR)} CFLAGS += -DCJSON_INCLUDE_CONFIG_H CSRCS = $(CJSON_SRCDIR)$(DELIM)cJSON.c CSRCS += $(CJSON_SRCDIR)$(DELIM)cJSON_Utils.c -# Download and unpack tarball if no git repo found -ifeq ($(wildcard $(CJSON_UNPACKNAME)/.git),) $(CJSON_TARBALL): @echo "Downloading: $(CJSON_TARBALL)" $(Q) curl -O -L $(CONFIG_NETUTILS_CJSON_URL)/$(CJSON_TARBALL) @@ -57,30 +53,7 @@ $(CJSON_TARBALL): $(CJSON_UNPACKNAME): $(CJSON_TARBALL) @echo "Unpacking: $(CJSON_TARBALL) -> $(CJSON_UNPACKNAME)" $(Q) $(UNPACK) $(CJSON_TARBALL) - $(Q) mv cJSON-$(CJSON_VERSION) $(CJSON_UNPACKNAME) $(Q) touch $(CJSON_UNPACKNAME) -endif - -ifneq ($(CONFIG_NETUTILS_CJSON_TEST),) -PROGNAME += cjson_test -MAINSRC += $(CJSON_SRCDIR)$(DELIM)test.c - -UNITY_CJSONTESTS := parse_examples parse_number parse_hex4 parse_string parse_array \ - parse_object parse_value print_string print_number print_array print_object \ - print_value cjson_add parse_with_opts compare_tests readme_examples minify_tests \ - misc_tests json_patch_tests old_utils_tests misc_utils_tests -UNITY_CJSONTESTCS := $(foreach n, $(UNITY_CJSONTESTS), $(CJSON_SRCDIR)$(DELIM)tests$(DELIM)$(n).c) -CJSONTEST_MAIN := $(foreach n, $(UNITY_CJSONTESTS), cjson_$(n)) -PROGNAME += $(CJSONTEST_MAIN) -MAINSRC += $(UNITY_CJSONTESTCS) - -CSRCS += $(CJSON_SRCDIR)/tests/unity_setup.c -CFLAGS += -Wno-unused-function -CFLAGS += -DCJSON_NESTING_LIMIT=CONFIG_CJSON_NESTING_LIMIT - -PRIORITY = $(CONFIG_CJSON_TEST_PRIORITY) -STACKSIZE = $(CONFIG_CJSON_TEST_STACKSIZE) -endif $(CJSON_SRCDIR)$(DELIM)cJSON.h: $(CJSON_UNPACKNAME) @@ -95,10 +68,8 @@ $(APPS_INCDIR)$(DELIM)cJSON_Utils.h: $(CJSON_SRCDIR)$(DELIM)cJSON_Utils.h context:: $(APPS_INCDIR)$(DELIM)cJSON.h $(APPS_INCDIR)$(DELIM)cJSON_Utils.h distclean:: -ifeq ($(wildcard $(CJSON_UNPACKNAME)/.git),) $(call DELDIR, $(CJSON_UNPACKNAME)) $(call DELFILE, $(CJSON_TARBALL)) -endif $(call DELFILE, $(APPDIR)/include/netutils/cJSON.h) $(call DELFILE, $(APPDIR)/include/netutils/cJSON_Utils.h) diff --git a/netutils/cmux/CMakeLists.txt b/netutils/cmux/CMakeLists.txt deleted file mode 100644 index a28163d3c..000000000 --- a/netutils/cmux/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -# ############################################################################## -# apps/netutils/cmux/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_NETUTILS_CMUX) - target_sources(apps PRIVATE cmux.c) -endif() diff --git a/netutils/cmux/Kconfig b/netutils/cmux/Kconfig deleted file mode 100644 index fbca73656..000000000 --- a/netutils/cmux/Kconfig +++ /dev/null @@ -1,18 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config NETUTILS_CMUX - bool "Cmux tool" - default n - ---help--- - Enable the CMUX (GSM 07.10) multiplexing protocol utility. - CMUX allows multiplexing multiple virtual serial connections - over a single physical serial link, commonly used with GSM/LTE - modems to simultaneously handle AT commands, data connections, - and other communication channels. - -if NETUTILS_CMUX - -endif # NETUTILS_CMUX diff --git a/netutils/cmux/Make.defs b/netutils/cmux/Make.defs deleted file mode 100644 index 9ce89f18f..000000000 --- a/netutils/cmux/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/netutils/cmux/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_NETUTILS_CMUX),) -CONFIGURED_APPS += $(APPDIR)/netutils/cmux -endif diff --git a/netutils/cmux/cmux.c b/netutils/cmux/cmux.c deleted file mode 100644 index 47cee955f..000000000 --- a/netutils/cmux/cmux.c +++ /dev/null @@ -1,824 +0,0 @@ -/**************************************************************************** - * apps/netutils/cmux/cmux.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "netutils/chat.h" -#include "netutils/cmux.h" -#include "cmux.h" - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -#define CMUX_MIN_FRAME_LEN (5) -#define CMUX_FRAME_PREFIX (5) -#define CMUX_FRAME_POSFIX (2) - -#define CMUX_TASK_NAME ("cmux") -#define CMUX_THREAD_PRIOR (100) -#define CMUX_THREAD_STACK_SIZE (3072) - -#define cmux_inc_buffer(buf, p) \ - p++; \ - if (p == buf->endp) \ - p = buf->data; - -#define cmux_buffer_length(buf) \ - ((buf->readp > buf->writep) ? (CMUX_BUFFER_SZ - (buf->readp - buf->writep)) : (buf->writep - buf->readp)) - -#define cmux_buffer_free(buf) \ - ((buf->readp > buf->writep) ? (buf->readp - buf->writep) : (CMUX_BUFFER_SZ - (buf->writep - buf->readp))) - -struct cmux_ctl_s -{ - int fd; - int total_ports; - struct cmux_parse_s *parse; - struct cmux_channel_s *channels; - struct cmux_stream_buffer_s *stream; -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: cmux_calulate_fcs - * - * Description: - * Calculate the frame checking sequence. - * - ****************************************************************************/ - -static unsigned char cmux_calulate_fcs(const unsigned char *input, int count) -{ - return crc8rohcpart(input, count, 0x00); -} - -/**************************************************************************** - * Name: cmux_parse_create - * - * Description: - * Create a circular buffer to receive incoming packets. - * - ****************************************************************************/ - -static struct cmux_stream_buffer_s *cmux_stream_buffer_create(void) -{ - struct cmux_stream_buffer_s *cmux_buffer = - malloc(sizeof(struct cmux_stream_buffer_s)); - if (cmux_buffer) - { - memset(cmux_buffer, 0, sizeof(struct cmux_stream_buffer_s)); - cmux_buffer->readp = cmux_buffer->data; - cmux_buffer->writep = cmux_buffer->data; - cmux_buffer->endp = cmux_buffer->data + CMUX_BUFFER_SZ; - } - - return cmux_buffer; -} - -/**************************************************************************** - * Name: cmux_buffer_write - * - * Description: - * Write the input frames to the circular buffer. - * - ****************************************************************************/ - -static int cmux_buffer_write(struct cmux_stream_buffer_s *cmux_buffer, - const char *input, int length) -{ - int c = cmux_buffer->endp - cmux_buffer->writep; - - length = MIN(length, cmux_buffer_free(cmux_buffer)); - if (length > c) - { - memcpy(cmux_buffer->writep, input, c); - memcpy(cmux_buffer->data, input + c, length - c); - cmux_buffer->writep = cmux_buffer->data + (length - c); - } - else - { - memcpy(cmux_buffer->writep, input, length); - cmux_buffer->writep += length; - if (cmux_buffer->writep == cmux_buffer->endp) - { - cmux_buffer->writep = cmux_buffer->data; - } - } - - return length; -} - -/**************************************************************************** - * Name: cmux_parse_reset - * - * Description: - * Reset data buffer and parse struct. - * - ****************************************************************************/ - -static void cmux_parse_reset(struct cmux_parse_s *cmux_parse) -{ - if (cmux_parse) - { - memset(cmux_parse->data, 0x00, CMUX_BUFFER_SZ); - memset(cmux_parse, 0x00, sizeof(struct cmux_parse_s)); - } -} - -static int cmux_decode_frame(struct cmux_stream_buffer_s *cmux_buffer, - struct cmux_parse_s *cmux_parse) -{ - /* Minimal length to CMUX Frame : address, type, length, FCS and flag */ - - int length = CMUX_MIN_FRAME_LEN; - unsigned char *data = NULL; - unsigned char fcs = CMUX_FCS_MAX_VALUE; - int end = 0; - - if (!cmux_buffer || !cmux_parse) - { - return -EACCES; - } - - while (cmux_buffer_length(cmux_buffer) >= CMUX_MIN_FRAME_LEN) - { - cmux_buffer->flag_found = 0; - length = CMUX_MIN_FRAME_LEN; - - while (!cmux_buffer->flag_found && - cmux_buffer_length(cmux_buffer) > 0) - { - if (*cmux_buffer->readp == CMUX_OPEN_FLAG) - { - cmux_buffer->flag_found = 1; - } - - cmux_inc_buffer(cmux_buffer, cmux_buffer->readp); - } - - if (!cmux_buffer->flag_found) - { - return ERROR; - } - - while (cmux_buffer_length(cmux_buffer) > 0 && - (*cmux_buffer->readp == CMUX_OPEN_FLAG)) - { - cmux_inc_buffer(cmux_buffer, cmux_buffer->readp); - } - - if (cmux_buffer_length(cmux_buffer) < length) - { - return ERROR; - } - - data = cmux_buffer->readp; - fcs = CMUX_FCS_MAX_VALUE; - cmux_parse->address = ((*data & - CMUX_ADDR_FIELD_CHECK) >> 2); - fcs = crc8rohcincr(*data, fcs); - cmux_inc_buffer(cmux_buffer, data); - - cmux_parse->control = *data; - fcs = crc8rohcincr(*data, fcs); - cmux_inc_buffer(cmux_buffer, data); - - cmux_parse->data_length = (*data & - CMUX_LENGTH_FIELD_OPERATOR) >> 1; - fcs = crc8rohcincr(*data, fcs); - - /* EA bit, should always have the value 1 */ - - if (!(*data & 1)) - { - cmux_buffer->readp = data; - cmux_buffer->flag_found = 0; - continue; - } - - length += cmux_parse->data_length; - if (!(cmux_buffer_length(cmux_buffer) >= length)) - { - return ERROR; - } - - cmux_inc_buffer(cmux_buffer, data); - if (cmux_parse->data_length > 0 && - cmux_parse->data_length < CMUX_BUFFER_SZ) - { - end = cmux_buffer->endp - data; - if (cmux_parse->data_length > end) - { - memcpy(cmux_parse->data, data, end); - memcpy(cmux_parse->data + end, cmux_buffer->data, - cmux_parse->data_length - end); - data = cmux_buffer->data + - (cmux_parse->data_length - end); - } - else - { - memcpy(cmux_parse->data, data, cmux_parse->data_length); - data += cmux_parse->data_length; - if (data == cmux_buffer->endp) - { - data = cmux_buffer->data; - } - } - - if (CMUX_FRAME_TYPE(CMUX_FRAME_TYPE_UI, cmux_parse)) - { - int i; - for (i = 0; i < cmux_parse->data_length; i++) - { - fcs = crc8rohcincr(cmux_parse->data[i], fcs); - } - } - } - - if (crc8rohcincr(*data, fcs) != CMUX_FCS_OPERATOR) - { - cmux_buffer->dropped_count++; - cmux_buffer->readp = data; - cmux_parse_reset(cmux_parse); - continue; - } - - cmux_inc_buffer(cmux_buffer, data); - if (*data != CMUX_CLOSE_FLAG) - { - cmux_buffer->readp = data; - cmux_buffer->dropped_count++; - cmux_parse_reset(cmux_parse); - continue; - } - - cmux_buffer->received_count++; - cmux_inc_buffer(cmux_buffer, data); - cmux_buffer->readp = data; - return OK; - } - - return ERROR; -} - -/**************************************************************************** - * Name: cmux_encode_frame - * - * Description: - * Encode a buffer to the CMUX protocol. - * - ****************************************************************************/ - -static int cmux_encode_frame(int fd, int channel, char *buffer, - int frame_size, unsigned char type) -{ - int prefix_len = 4; - unsigned char frame_prefix[CMUX_FRAME_PREFIX] = { - CMUX_OPEN_FLAG, (CMUX_ADDR_FIELD_BIT_EA | CMUX_ADDR_FIELD_BIT_CR), - 0x00, 0x00, 0x00 - }; - - unsigned char frame_posfix[CMUX_FRAME_POSFIX] = { - CMUX_FCS_MAX_VALUE, - CMUX_CLOSE_FLAG - }; - - frame_prefix[CMUX_BIT1] = (frame_prefix[CMUX_BIT1] | - ((CMUX_ADDR_FIELD_OPERATOR & (unsigned char)channel) << 2)); - - frame_prefix[CMUX_BIT2] = type; - - if (frame_size <= CMUX_FRAME_MAX_SIZE) - { - frame_prefix[CMUX_BIT3] = CMUX_ADDR_FIELD_BIT_EA | (frame_size << 1); - prefix_len = 4; - } - else - { - frame_prefix[CMUX_BIT3] = (frame_size << 1) & - CMUX_LENGTH_FIELD_OPERATOR; - frame_prefix[CMUX_BIT4] = CMUX_ADDR_FIELD_BIT_EA | - ((frame_size >> 7) << 1); - prefix_len = 5; - } - - frame_posfix[CMUX_BIT0] = cmux_calulate_fcs(frame_prefix + 1, - prefix_len - 1); - - int ret = write(fd, frame_prefix, prefix_len); - if (ret != prefix_len) - { - return ERROR; - } - - if (frame_size > 0 && buffer != NULL) - { - ret = write(fd, buffer, frame_size); - if (ret != frame_size) - { - ninfo("Failed to write buffer (wrote %d, expected %d)\n", - ret, frame_size); - return ERROR; - } - } - - ret = write(fd, frame_posfix, CMUX_FRAME_POSFIX); - if (ret != CMUX_FRAME_POSFIX) - { - return ERROR; - } - - return OK; -} - -/**************************************************************************** - * Name: cmux_open_pseudo_tty - * - * Description: - * Open pseudo-terminals according to the number of channels. - * - ****************************************************************************/ - -static int cmux_open_pseudo_tty(struct cmux_channel_s *channel, - int total_channels) -{ - int ret = 0; - struct termios options; - - if (!channel) - { - return -EACCES; - } - - options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); - options.c_iflag &= ~(INLCR | ICRNL | IGNCR); - - options.c_oflag &= ~OPOST; - options.c_oflag &= ~OLCUC; - options.c_oflag &= ~ONLRET; - options.c_oflag &= ~ONOCR; - options.c_oflag &= ~OCRNL; - - for (int i = 0; i < total_channels; i++) - { - ret = openpty(&channel[i].master_fd, &channel[i].slave_fd, - (FAR char *)&channel[i].slave_path, &options, NULL); - if (ret < 0) - { - perror("Failed to open pseudo terminal \n"); - break; - } - else - { - ninfo("Open pseudo tty name: %s\n", channel[i].slave_path); - - channel[i].dlci = i + 1; - channel[i].active = true; - channel[i].last_activity = time(NULL); - } - } - - return ret; -} - -/**************************************************************************** - * Name: cmux_open_channels - * - * Description: - * Open the controller and the logic channels. - * - ****************************************************************************/ - -static int cmux_open_channels(int fd, int total_channels) -{ - int ret = 0; - for (int i = 0; i < total_channels; i++) - { - ret = cmux_encode_frame(fd, i, - NULL, 0x00, - (CMUX_FRAME_TYPE_SABM | CMUX_CONTROL_FIELD_BIT_PF)); - if (ret != OK) - { - perror("ERROR: Failed to open channel\n"); - break; - } - - sleep(1); - } - - return ret; -} - -/**************************************************************************** - * Name: cmux_extract - * - * Description: - * Extract a frame from the circular buffer according - * to the input and length. - * - ****************************************************************************/ - -static int cmux_extract(struct cmux_ctl_s *ctl, char *input, int len) -{ - int ret; - int frames_extracted = 0; - - if (!input) - { - return ERROR; - } - - ret = cmux_buffer_write(ctl->stream, input, len); - if (ret < 0) - { - return ret; - } - - while (cmux_decode_frame(ctl->stream, ctl->parse) >= 0) - { - if (CMUX_FRAME_TYPE(CMUX_FRAME_TYPE_UI, ctl->parse) || - CMUX_FRAME_TYPE(CMUX_FRAME_TYPE_UIH, ctl->parse)) - { - if (ctl->parse->address > 0) - { - /* Logic channel */ - - ret = write(ctl->channels[ctl->parse->address].master_fd, - ctl->parse->data, - ctl->parse->data_length); - - if (ret != ctl->parse->data_length) - { - ninfo("Frame length less than expected\n"); - continue; - } - } - else - { - /* Control channel */ - } - } - else - { - switch ((ctl->parse->control & ~CMUX_CONTROL_FIELD_BIT_PF)) - { - case CMUX_FRAME_TYPE_UA: - ninfo("Frame type: UA \n"); - - break; - case CMUX_FRAME_TYPE_DM: - ninfo("Frame type: DM \n"); - if (ctl->channels[ctl->parse->address].active) - { - ctl->channels[ctl->parse->address].active = 0; - } - - break; - case CMUX_FRAME_TYPE_DISC: - ninfo("Frame type: DISC \n"); - - if (ctl->channels[ctl->parse->address].active) - { - ctl->channels[ctl->parse->address].active = false; - ret = cmux_encode_frame(ctl->fd, - ctl->parse->address, NULL, 0x00, - (CMUX_FRAME_TYPE_UA | CMUX_CONTROL_FIELD_BIT_PF)); - } - else - { - ret = cmux_encode_frame(ctl->fd, - ctl->parse->address, NULL, 0x00, - (CMUX_FRAME_TYPE_DM | CMUX_CONTROL_FIELD_BIT_PF)); - } - - if (ret < 0) - { - nwarn("Failed to encode the frame. Address (%d) \n", - ctl->parse->address); - } - - break; - case CMUX_FRAME_TYPE_SABM: - ninfo("Frame type: SABM\n"); - - if (!ctl->channels[ctl->parse->address].active) - { - if (!ctl->parse->address) - { - ninfo("Control channel opened.\n"); - } - else - { - ninfo("Logical channel %d opened.\n", - ctl->parse->address); - } - } - else - { - nwarn("Even though channel %d was already closed.\n", - ctl->parse->address); - } - - ctl->channels[ctl->parse->address].active = 1; - ret = cmux_encode_frame(ctl->fd, - ctl->parse->address, NULL, 0x00, - (CMUX_FRAME_TYPE_UA | CMUX_CONTROL_FIELD_BIT_PF)); - if (ret < 0) - { - nwarn("Failed to encode the frame. Address (%d) \n", - ctl->parse->address); - } - - break; - default: - ninfo("Frame type: UNKNOWN\n"); - break; - } - } - - frames_extracted++; - } - - cmux_parse_reset(ctl->parse); - - return frames_extracted; -} - -/**************************************************************************** - * Name: cmux_protocol_send - * - * Description: - * Send encoded messages to a specific address. - * - ****************************************************************************/ - -static int cmux_send(struct cmux_ctl_s *ctl, char *buffer, - int length, int address) -{ - int ret; - if (!buffer) - { - return ERROR; - } - - ret = cmux_encode_frame(ctl->fd, - address, - buffer, - length, CMUX_FRAME_TYPE_UIH); - return ret; -} - -/**************************************************************************** - * Name: cmux_thread - * - * Description: - * Start cmux thread. - * - ****************************************************************************/ - -static void *cmux_thread(void *args) -{ - struct cmux_ctl_s *ctl = (struct cmux_ctl_s *)args; - int ret = 0; - fd_set rfds; - struct timeval timeout; - char buffer[CMUX_BUFFER_SZ]; - - while (true) - { - FD_ZERO(&rfds); - FD_SET(ctl->fd, &rfds); - - int max_fd = ctl->fd; - for (int i = 0; i < ctl->total_ports; i++) - { - if (ctl->channels[i].active) - { - FD_SET(ctl->channels[i].master_fd, &rfds); - FD_SET(ctl->channels[i].slave_fd, &rfds); - - if (ctl->channels[i].master_fd > max_fd) - { - max_fd = ctl->channels[i].master_fd; - } - - if (ctl->channels[i].slave_fd > max_fd) - { - max_fd = ctl->channels[i].slave_fd; - } - } - } - - timeout.tv_usec = 100; - timeout.tv_sec = 0; - - ret = select(max_fd + 1, &rfds, NULL, NULL, &timeout); - if (ret > 0) - { - if (FD_ISSET(ctl->fd, &rfds)) - { - int bytes_read = read(ctl->fd, buffer, sizeof(buffer) - 1); - if (bytes_read > 0) - { - buffer[bytes_read] = '\0'; - ret = cmux_extract(ctl, buffer, bytes_read); - if (ret < 0) - { - perror("ERROR: Failed to extract frames \n"); - } - } - } - - for (int i = 0; i < ctl->total_ports; i++) - { - if (ctl->channels[i].active && - FD_ISSET(ctl->channels[i].master_fd, &rfds)) - { - memset(buffer, 0, sizeof(buffer)); - int bytes_read = read(ctl->channels[i].master_fd, - buffer, sizeof(buffer) - 1); - if (bytes_read > 0) - { - ret = cmux_send(ctl, buffer, bytes_read, i); - if (ret < 0) - { - nwarn("WANING: Retransmit from pty/%d\n", i); - } - } - } - } - } - } - - return NULL; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: cmux_create - * - * Description: - * Create CMUX context. - * - ****************************************************************************/ - -int cmux_create(struct cmux_settings_s *settings) -{ - int ret = 0; - struct chat_ctl ctl; - struct cmux_ctl_s *cmux_ctl = NULL; - pthread_t cmux_thread_id; - struct sched_param param; - pthread_attr_t attr; - - cmux_ctl = malloc(sizeof(struct cmux_ctl_s)); - if (!cmux_ctl) - { - perror("ERROR: Failed to allocate memory for CMUX daemon\n"); - ret = -ENOMEM; - return ret; - } - - memset(cmux_ctl, 0, sizeof(struct cmux_ctl_s)); - cmux_ctl->fd = open(settings->tty_name, O_RDWR | O_NONBLOCK); - if (cmux_ctl->fd < 0) - { - perror("ERROR: Unable to open file %s\n"); - goto exit; - } - - ctl.echo = false; - ctl.verbose = false; - ctl.fd = cmux_ctl->fd; - ctl.timeout = 30; - - ret = chat(&ctl, settings->script); - if (ret < 0) - { - perror("ERROR:Failed to run cmux script\n"); - goto exit; - } - - cmux_ctl->channels = malloc(sizeof(struct cmux_channel_s) * - settings->total_channels); - if (!cmux_ctl->channels) - { - perror("ERROR:Failed to allocate memory to channels\n"); - ret = -ENOMEM; - goto exit; - } - - cmux_ctl->parse = malloc(sizeof(struct cmux_parse_s)); - if (!cmux_ctl->parse) - { - perror("ERROR: Failed to allocate memory to parse\n"); - ret = -ENOMEM; - goto exit; - } - - cmux_parse_reset(cmux_ctl->parse); - - ret = cmux_open_pseudo_tty(cmux_ctl->channels, settings->total_channels); - if (ret < 0) - { - perror("ERROR: Failed to open pseudo tty.\n"); - goto exit; - } - - cmux_ctl->stream = cmux_stream_buffer_create(); - if (cmux_ctl->stream == NULL) - { - perror("ERROR: Failed to allocate memory to stream\n"); - ret = -ENOMEM; - goto exit; - } - - ret = cmux_open_channels(cmux_ctl->fd, settings->total_channels); - if (ret < 0) - { - perror("ERROR: Failed to open virtual channels.\n"); - goto exit; - } - - cmux_ctl->total_ports = settings->total_channels; - - pthread_attr_init(&attr); - param.sched_priority = CMUX_THREAD_PRIOR; - pthread_attr_setschedparam(&attr, ¶m); - pthread_attr_setstacksize(&attr, CMUX_THREAD_STACK_SIZE); - - ret = pthread_create(&cmux_thread_id, &attr, cmux_thread, cmux_ctl); - - return ret; - -exit: - - if (cmux_ctl->channels) - { - for (int i = 0; i < settings->total_channels; i++) - { - if (cmux_ctl->channels[i].master_fd > 0) - { - close(cmux_ctl->channels[i].master_fd); - } - - if (cmux_ctl->channels[i].slave_fd > 0) - { - close(cmux_ctl->channels[i].slave_fd); - } - } - - free(cmux_ctl->channels); - } - - if (cmux_ctl->stream) - { - free(cmux_ctl->stream); - } - - close(cmux_ctl->fd); - - return ret; -} diff --git a/netutils/cmux/cmux.h b/netutils/cmux/cmux.h deleted file mode 100644 index 7758f83b5..000000000 --- a/netutils/cmux/cmux.h +++ /dev/null @@ -1,233 +0,0 @@ -/**************************************************************************** - * apps/netutils/cmux/cmux.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __APPS_NETUTILS_CMUX_H -#define __APPS_NETUTILS_CMUX_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include -#include - -#define CMUX_BIT0 (0) -#define CMUX_BIT1 (1) -#define CMUX_BIT2 (2) -#define CMUX_BIT3 (3) -#define CMUX_BIT4 (4) -#define CMUX_BIT5 (5) -#define CMUX_BIT6 (6) -#define CMUX_BIT7 (7) - -#define CMUX_BUFFER_SZ (1024) -#define CMUX_CHANNEL_NAME_SZ (64) -#define CMUX_FRAME_MAX_SIZE (127) - -/** - * Mux Frame - * - * | Open flag | - * | 1 octed | - * | 0xF9 | - * ______________________ - * Address - * | 1 octet | - * | ---------- | - * ______________________ - * Control - * | 1 octet | - * | ---------- | - * ______________________ - * Length - * | 1-2 octet | - * | --------- | - * ______________________ - * Information - * | Multiples octets | - * | ---------------- | - * ______________________ - * | FCS | - * | 1 octed | - * | --------- | - * ______________________ - * | Close flag | - * | 1 octed | - * | 0xF9 | - * - */ - -/* Flag Field - Each frame begins and ends with a flag sequence octet. */ - -#define CMUX_OPEN_FLAG (0xF9) -#define CMUX_CLOSE_FLAG (0xF9) - -/** - * Address Field - * - * |Bit 1 |Bit 2 |Bit 3 |Bit 4 |Bit 5 |Bit 6 |Bit 7 |Bit 8 - * |ADDR_FIELD_BIT_EA | C/R | | | | DLCI | | - */ - -/* EA bit extends the range of the address field. - * When the EA bit is set to 1 in an octet, it signifies that this octet - * is the last octet of the length field. - * When the EA bit is set to 0, it signifies that another - * octet of the address field follows. - */ - -#define CMUX_ADDR_FIELD_BIT_EA (CMUX_BIT1) -#define CMUX_ADDR_FIELD_OPERATOR (0x3F) -#define CMUX_ADDR_FIELD_CHECK (0xFC) - -/** - * The C/R (command/response) bit identifies the frame as - * either a command or a response. - * ______________________________ - * ________| Direction| CR Value - * Command | T.E -> U.E | 1 - * Command | T.E <- U.E | 0 - * ______________________________ - * Response | T.E -> U.E | 1 - * Response | T.E <- U.E | 0 - */ - -#define CMUX_ADDR_FIELD_BIT_CR (CMUX_BIT2) - -/* Control field - * |Bit 1 |Bit 2| Bit 3 |Bit 4 |Bit 5 |Bit 6 |Bit 7 |Bit 8 - * - - - - PF - - - - * P/F (Poll/Final) - * - The Poll bit set to 1 shall be used by one station to solicit poll - * a response or sequence of responses from the other station. - * - The final bit set to 1 shall be used by a station to indicate - * the response frame transmitted as the result of a - * soliciting (poll) command. - */ - -/* Poll/Final */ - -#define CMUX_CONTROL_FIELD_BIT_PF (0x10) - -/* Set Asynchronous Balanced Mode : establish DLC between T.E and U.E */ - -#define CMUX_FRAME_TYPE_SABM (0x2F) - -/* Unnumbered Acknowledgement: is a response to SABM or DISC frame */ - -#define CMUX_FRAME_TYPE_UA (0x63) - -/* Disconnected Mode : frame is used to report a status where the station - * is logically disconnected from the data link. When in disconnected mode, - * no commands are accepted until the disconnected mode is terminated by - * the receipt of a SABM command. If a DISC command is received while - * in disconnected mode, a DM response is sent - */ - -#define CMUX_FRAME_TYPE_DM (0x0F) - -/* Disconnect : is a command frame and is used to close down DLC. */ - -#define CMUX_FRAME_TYPE_DISC (0x43) - -/* Unnumbered Information with Header check : - * command/response sends user data at either station - */ - -#define CMUX_FRAME_TYPE_UIH (0xEF) - -/* Unnumbered Information */ - -#define CMUX_FRAME_TYPE_UI (0x03) - -#define CMUX_FRAME_TYPE(type, frame) ((frame->control & ~CMUX_CONTROL_FIELD_BIT_PF) == type) - -/* | U.E | <--------- SABM (DLC 1) ------------- | T.E - * | | ---------- U.A (Response) ------------> | - * | Multiplexer | <---------- DISC (Close DLC 1) ------------ | Recv - * | | <----------- UA(Response) ----------- | - */ - -/* Note : Some manufactures doesn't support UI frame. */ - -/* Length Field - * |Bit 1 |Bit 2| Bit 3 |Bit 4 |Bit 5 |Bit 6 |Bit 7 |Bit 8 - * E/A L1 L2 L3 L4 L5 L6 L7 - * - L1 - L7 : The L1 to L7 bits indicate the length of the - * following data field for the information field less than 128 bytes - * - EA bit = 1 in an octet, it signifies that this octet - * is the last octet of the length field. - * - EA bit = 0, it signifies that a second octet of - * the length field follows. - * The total length of the length field is 15 bits in that case. - */ - -#define CMUX_LENGTH_FIELD_MAX_VALUE (0x7F) -#define CMUX_LENGTH_FIELD_OPERATOR (0xFE) - -/* Information Field - * The information field is the payload of the frame and carries the - * user data and any convergence layer information. - * The field is octet structured and only presents in UIH frames. - */ - -/* FSC field - * In the case of the UIH frame, the contents of the information field shall - * not be included in the FCS calculation. FCS is calculated on the contents - * of the address, control and length fields only. This means that only the - * delivery to the correct DLCI is protected, but not the information. - */ - -#define CMUX_FCS_MAX_VALUE (0xFF) -#define CMUX_FCS_OPERATOR (0xCF) -struct cmux_parse_s -{ - unsigned char address; /* Reserved to address filed */ - unsigned char control; /* Reserved to control field */ - int data_length; /* Reserved to data length field */ - unsigned char data[CMUX_BUFFER_SZ]; /* Reserved to information field */ -}; - -struct cmux_stream_buffer_s -{ - unsigned char data[CMUX_BUFFER_SZ]; /* Buffer to hold incoming packets. */ - unsigned char *readp; /* Pointer to read buffer */ - unsigned char *writep; /* Pointer to write buffer */ - unsigned char *endp; /* Pointer to end of buffer */ - int flag_found; /* Detected open flag */ - unsigned long received_count; /* Counter to received packets */ - unsigned long dropped_count; /* Counter to dropped packets */ -}; - -struct cmux_channel_s -{ - int master_fd; /* Master pseudo terminal */ - int slave_fd; /* Slave pseudo terminal */ - int dlci; /* Data Link Connection Identifier */ - char slave_path[CMUX_CHANNEL_NAME_SZ]; /* Path do slave (/dev/pts/X) */ - bool active; /* Flag to check if the channel is active */ - time_t last_activity; /* Timestamp to last packet sent/received */ -}; - -#endif /* __APPS_NETUTILS_CMUX_H */ \ No newline at end of file diff --git a/netutils/codecs/CMakeLists.txt b/netutils/codecs/CMakeLists.txt deleted file mode 100644 index ee93eacd2..000000000 --- a/netutils/codecs/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -# ############################################################################## -# apps/netutils/codecs/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_NETUTILS_CODECS) - target_sources(apps PRIVATE urldecode.c base64.c md5.c) -endif() diff --git a/netutils/codecs/Kconfig b/netutils/codecs/Kconfig index 08f5ed816..baa88bb8e 100644 --- a/netutils/codecs/Kconfig +++ b/netutils/codecs/Kconfig @@ -16,8 +16,7 @@ config CODECS_BASE64 default n ---help--- Enables support for the following interfaces: base64_encode(), - base64_decode(), base64w_encode(), base64w_decode(), - base64url_encode(), and base64url_decode(), + base64_decode(), base64w_encode(), and base64w_decode(), Contributed NuttX by Darcy Gong. @@ -27,7 +26,7 @@ config CODECS_HASH_MD5 ---help--- Enables support for the following interfaces: md5_init(), md5_update(), md5_final(), md5_transform(), md5_sum() and - md5_hash() + md5_hash() Contributed NuttX by Darcy Gong. diff --git a/netutils/codecs/Make.defs b/netutils/codecs/Make.defs index b17090ec2..315f04ea1 100644 --- a/netutils/codecs/Make.defs +++ b/netutils/codecs/Make.defs @@ -1,8 +1,5 @@ -############################################################################# # apps/netutils/codecs/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -20,6 +17,6 @@ # ############################################################################ -ifneq ($(CONFIG_NETUTILS_CODECS),) +ifeq ($(CONFIG_NETUTILS_CODECS),y) CONFIGURED_APPS += $(APPDIR)/netutils/codecs endif diff --git a/netutils/codecs/Makefile b/netutils/codecs/Makefile index b6a1dee89..68b3bba9b 100644 --- a/netutils/codecs/Makefile +++ b/netutils/codecs/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/netutils/codecs/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/netutils/codecs/base64.c b/netutils/codecs/base64.c index 731283857..442a06bad 100644 --- a/netutils/codecs/base64.c +++ b/netutils/codecs/base64.c @@ -1,10 +1,10 @@ /**************************************************************************** * apps/netutils/codecs/base64.c * - * SPDX-License-Identifier: BSD-3-Clause - * SPDX-FileCopyrightText: 2012, 2018 Gregory Nutt. All rights reserved. - * SPDX-FileCopyrightText: 2005, Jouni Malinen - * SPDX-FileContributor: Darcy Gong + * This file is part of the NuttX RTOS: + * + * Copyright (C) 2012, 2018 Gregory Nutt. All rights reserved. + * Author: Darcy Gong * * Reference: * @@ -55,7 +55,6 @@ #include #include -#include #include #include "netutils/base64.h" @@ -318,150 +317,4 @@ FAR void *base64w_decode(FAR const void *src, size_t len, FAR void *dst, return _base64_decode(src, len, dst, out_len, true); } -/**************************************************************************** - * Name: base64url_val - ****************************************************************************/ - -static int base64url_val(char c) -{ - if (c >= 'A' && c <= 'Z') - { - return c - 'A'; - } - - if (c >= 'a' && c <= 'z') - { - return c - 'a' + 26; - } - - if (c >= '0' && c <= '9') - { - return c - '0' + 52; - } - - if (c == '-') - { - return 62; - } - - if (c == '_') - { - return 63; - } - - return -1; -} - -/**************************************************************************** - * Name: base64url_encode - * - * Description: - * Encode binary data as unpadded base64url (RFC 4648 section 5). - * - ****************************************************************************/ - -int base64url_encode(FAR const void *src, size_t len, FAR char *dst, - size_t dstlen) -{ - FAR const uint8_t *in = src; - uint32_t acc = 0; - size_t i; - size_t o = 0; - int bits = 0; - - static const char g_base64url[] = - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"; - - for (i = 0; i < len; i++) - { - acc = (acc << 8) | in[i]; - bits += 8; - - while (bits >= 6) - { - if (o + 1 >= dstlen) - { - return -E2BIG; - } - - bits -= 6; - dst[o++] = g_base64url[(acc >> bits) & 0x3f]; - } - } - - if (bits > 0) - { - if (o + 1 >= dstlen) - { - return -E2BIG; - } - - dst[o++] = g_base64url[(acc << (6 - bits)) & 0x3f]; - } - - if (o >= dstlen) - { - return -E2BIG; - } - - dst[o] = '\0'; - return 0; -} - -/**************************************************************************** - * Name: base64url_decode - * - * Description: - * Decode unpadded base64url (RFC 4648 section 5). - * - ****************************************************************************/ - -int base64url_decode(FAR const char *src, FAR void *dst, size_t dstmax, - FAR size_t *out_len) -{ - FAR uint8_t *out = dst; - uint32_t acc = 0; - size_t o = 0; - int bits = 0; - int v; - - *out_len = 0; - - while (*src != '\0') - { - if (*src == '$' || *src == ':') - { - break; - } - - v = base64url_val(*src++); - if (v < 0) - { - return -EINVAL; - } - - acc = (acc << 6) | (uint32_t)v; - bits += 6; - - if (bits >= 8) - { - bits -= 8; - if (o >= dstmax) - { - return -E2BIG; - } - - out[o++] = (uint8_t)((acc >> bits) & 0xff); - } - } - - if (bits >= 6) - { - return -EINVAL; - } - - *out_len = o; - return 0; -} - #endif /* CONFIG_CODECS_BASE64 */ diff --git a/netutils/codecs/md5.c b/netutils/codecs/md5.c index dade6abd1..694e50f60 100644 --- a/netutils/codecs/md5.c +++ b/netutils/codecs/md5.c @@ -1,26 +1,11 @@ /**************************************************************************** * apps/netutils/codecs/md5.c * - * SPDX-License-Identifier: Apache-2.0 + * This file is part of the NuttX RTOS: * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Darcy Gong * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** * Reference: * * This code implements the MD5 message-digest algorithm. @@ -40,6 +25,33 @@ * * See README and COPYING for more details. * + * And is re-released under the NuttX modified BSD license: + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + * ****************************************************************************/ /**************************************************************************** @@ -52,8 +64,6 @@ #include #include #include -#include -#include #include "netutils/md5.h" @@ -74,11 +84,7 @@ /* This is the central step in the MD5 algorithm. */ # define MD5STEP(f, w, x, y, z, data, s) \ - (w += f(x, y, z) + data, w = w<>(32-s), w += x) - -/* Encoding Memory Block Size */ - -#define MD5_BUFSIZE 1024 + ( w += f(x, y, z) + data, w = w<>(32-s), w += x ) /**************************************************************************** * Private Functions @@ -177,7 +183,7 @@ void md5_update(struct md5_context_s *ctx, unsigned char const *buf, memcpy(p, buf, t); byte_reverse(ctx->in, 16); - md5_transform(ctx->buf, (uint32_t *)ctx->in); + md5_transform(ctx->buf, (uint32_t *) ctx->in); buf += t; len -= t; } @@ -188,7 +194,7 @@ void md5_update(struct md5_context_s *ctx, unsigned char const *buf, { memcpy(ctx->in, buf, 64); byte_reverse(ctx->in, 16); - md5_transform(ctx->buf, (uint32_t *)ctx->in); + md5_transform(ctx->buf, (uint32_t *) ctx->in); buf += 64; len -= 64; } @@ -235,7 +241,7 @@ void md5_final(unsigned char digest[16], struct md5_context_s *ctx) memset(p, 0, count); byte_reverse(ctx->in, 16); - md5_transform(ctx->buf, (uint32_t *)ctx->in); + md5_transform(ctx->buf, (uint32_t *) ctx->in); /* Now fill the next block with 56 bytes */ @@ -255,7 +261,7 @@ void md5_final(unsigned char digest[16], struct md5_context_s *ctx) ((uint32_t *)ctx->in)[14] = ctx->bits[0]; ((uint32_t *)ctx->in)[15] = ctx->bits[1]; - md5_transform(ctx->buf, (uint32_t *)ctx->in); + md5_transform(ctx->buf, (uint32_t *) ctx->in); byte_reverse((unsigned char *)ctx->buf, 4); memcpy(digest, ctx->buf, 16); memset(ctx, 0, sizeof(struct md5_context_s)); /* In case it's sensitive */ @@ -393,66 +399,11 @@ char *md5_hash(const uint8_t * addr, const size_t len) md5_sum(addr, len, digest); for (i = 0; i < 16; i++) { - snprintf(&hash[i * 2], 33 - i * 2, "%02x", digest[i]); + sprintf(&hash[i * 2], "%02x", digest[i]); } hash[32] = 0; return hash; } -/**************************************************************************** - * Name: md5_file - * - * Description: - * MD5 hash for a file - * - * Input Parameters: - * path: File Path - * mac : Buffer for the hash - * - ****************************************************************************/ - -int md5_file(const char *path, uint8_t *mac) -{ - int fd; - int ret; - unsigned char *buf; - MD5_CTX ctx; - - fd = open(path, O_RDONLY); - if (fd < 0) - { - return -errno; - } - - buf = malloc(MD5_BUFSIZE); - if (buf == NULL) - { - ret = -ENOMEM; - goto out; - } - - md5_init(&ctx); - - while (1) - { - /* Block calculation md5 */ - - ret = read(fd, buf, MD5_BUFSIZE); - if (ret <= 0) - { - ret = ret < 0 ? -errno : 0; - break; - } - - md5_update(&ctx, buf, ret); - } - - md5_final(mac, &ctx); - free(buf); -out: - close(fd); - return ret; -} - #endif /* CONFIG_CODECS_HASH_MD5 */ diff --git a/netutils/codecs/urldecode.c b/netutils/codecs/urldecode.c index 5328f311b..1e1a105fe 100644 --- a/netutils/codecs/urldecode.c +++ b/netutils/codecs/urldecode.c @@ -1,22 +1,35 @@ /**************************************************************************** * apps/netutils/codecs/urldecode.c * - * SPDX-License-Identifier: Apache-2.0 + * This file is part of the NuttX RTOS: * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Darcy Gong * - * http://www.apache.org/licenses/LICENSE-2.0 + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. * ****************************************************************************/ diff --git a/netutils/connectedhomeip/.gitignore b/netutils/connectedhomeip/.gitignore deleted file mode 100644 index d04100c9b..000000000 --- a/netutils/connectedhomeip/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/connectedhomeip -/inipp -/nlassert -/nlio -/nlunit-test -/pigweed diff --git a/netutils/connectedhomeip/0001-chip-add-compile-support-for-NuttX.patch b/netutils/connectedhomeip/0001-chip-add-compile-support-for-NuttX.patch deleted file mode 100644 index b755b9353..000000000 --- a/netutils/connectedhomeip/0001-chip-add-compile-support-for-NuttX.patch +++ /dev/null @@ -1,514 +0,0 @@ -From faaac5060c5e5f9ab23344d776b44440ca3f1706 Mon Sep 17 00:00:00 2001 -From: zhanghongyu -Date: Tue, 31 Oct 2023 11:01:50 +0800 -Subject: [PATCH] chip: add compile support for NuttX - -VELAPLATFO-11575 - -config/nuttx/chip-gn/BUILD.gn is the most important script, will output libchipnuttx.a file, -this file include all chip symbol we need. - -The reference documentation for matter compilation -https://xiaomi.f.mioffice.cn/docx/doxk4GkrddACeNZokDg618UjZZb - -Change-Id: Icbf140eb348dfa2ad769f76deac0abdc32618025 -Signed-off-by: zhanghongyu ---- - build/config/compiler/BUILD.gn | 9 +++ - config/nuttx/README.md | 8 +++ - config/nuttx/chip-gn/.gn | 29 ++++++++++ - config/nuttx/chip-gn/BUILD.gn | 57 +++++++++++++++++++ - config/nuttx/chip-gn/args.gni | 32 +++++++++++ - config/nuttx/chip-gn/toolchain/BUILD.gn | 33 +++++++++++ - examples/lighting-app/linux/main.cpp | 2 +- - scripts/codegen.py | 1 + - src/inet/BUILD.gn | 5 ++ - src/lib/core/CHIPError.h | 8 +-- - src/platform/BUILD.gn | 8 +++ - src/platform/Linux/BUILD.gn | 2 +- - src/platform/Linux/CHIPLinuxStorage.cpp | 2 +- - src/platform/Linux/ConnectivityUtils.cpp | 7 ++- - src/platform/Linux/ConnectivityUtils.h | 4 ++ - .../Linux/DiagnosticDataProviderImpl.cpp | 4 ++ - src/platform/Linux/Logging.cpp | 4 ++ - src/platform/Linux/PlatformManagerImpl.cpp | 4 ++ - src/platform/device.gni | 12 +++- - 19 files changed, 220 insertions(+), 11 deletions(-) - create mode 100644 config/nuttx/README.md - create mode 100644 config/nuttx/chip-gn/.gn - create mode 100644 config/nuttx/chip-gn/BUILD.gn - create mode 100644 config/nuttx/chip-gn/args.gni - create mode 100644 config/nuttx/chip-gn/toolchain/BUILD.gn - -diff --git a/build/config/compiler/BUILD.gn b/build/config/compiler/BUILD.gn -index b6ad67a649..1a590984a5 100644 ---- a/build/config/compiler/BUILD.gn -+++ b/build/config/compiler/BUILD.gn -@@ -271,6 +271,15 @@ config("strict_warnings") { - - cflags_cc = [ "-Wnon-virtual-dtor" ] - -+ if (current_os == "nuttx") { -+ cflags -= [ -+ "-Wshadow", -+ ] -+ cflags_cc -= [ -+ "-Wnon-virtual-dtor", -+ ] -+ } -+ - configs = [] - ldflags = [] - -diff --git a/config/nuttx/README.md b/config/nuttx/README.md -new file mode 100644 -index 0000000000..3cbdfc264e ---- /dev/null -+++ b/config/nuttx/README.md -@@ -0,0 +1,8 @@ -+# Nuttx build and configuration files -+ -+This directory contains build scripts and common configuration files used by -+CHIP Nuttx applications. It is structured as follows: -+ -+| File/Folder | Contents | -+| ----------- | ----------------------------------------------------------------------------------------------------------------------------------- | -+| chip-gn | GN project used to build selected CHIP libraries with the _nuttx_ platform integration layer | -diff --git a/config/nuttx/chip-gn/.gn b/config/nuttx/chip-gn/.gn -new file mode 100644 -index 0000000000..7233a3062b ---- /dev/null -+++ b/config/nuttx/chip-gn/.gn -@@ -0,0 +1,29 @@ -+# Copyright (c) 2020 Project CHIP Authors -+# -+# Licensed under the Apache License, Version 2.0 (the "License"); -+# you may not use this file except in compliance with the License. -+# You may obtain a copy of the License at -+# -+# http://www.apache.org/licenses/LICENSE-2.0 -+# -+# Unless required by applicable law or agreed to in writing, software -+# distributed under the License is distributed on an "AS IS" BASIS, -+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+# See the License for the specific language governing permissions and -+# limitations under the License. -+ -+import("//build_overrides/build.gni") -+import("//build_overrides/chip.gni") -+ -+# The location of the build configuration file. -+buildconfig = "${build_root}/config/BUILDCONFIG.gn" -+ -+# CHIP uses angle bracket includes. -+check_system_includes = true -+ -+default_args = { -+ target_cpu = "" -+ target_os = "nuttx" -+ -+ import("${chip_root}/config/nuttx/chip-gn/args.gni") -+} -diff --git a/config/nuttx/chip-gn/BUILD.gn b/config/nuttx/chip-gn/BUILD.gn -new file mode 100644 -index 0000000000..c4b94ab171 ---- /dev/null -+++ b/config/nuttx/chip-gn/BUILD.gn -@@ -0,0 +1,57 @@ -+# Copyright (c) 2020 Project CHIP Authors -+# -+# Licensed under the Apache License, Version 2.0 (the "License"); -+# you may not use this file except in compliance with the License. -+# You may obtain a copy of the License at -+# -+# http://www.apache.org/licenses/LICENSE-2.0 -+# -+# Unless required by applicable law or agreed to in writing, software -+# distributed under the License is distributed on an "AS IS" BASIS, -+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+# See the License for the specific language governing permissions and -+# limitations under the License. -+ -+import("//build_overrides/build.gni") -+import("//build_overrides/chip.gni") -+ -+import("${chip_root}/build/chip/tests.gni") -+ -+assert(current_os == "nuttx") -+ -+declare_args() { -+ chip_build_example_providers = false -+ chip_example_lighting = false -+} -+ -+static_library("nuttx") { -+ output_name = "libchipnuttx" -+ -+ public_deps = [ -+ "${chip_root}/examples/platform/linux:app-main", -+ "${chip_root}/src/lib", -+ ] -+ -+ if (chip_build_tests) { -+ public_deps += [ "${chip_root}/src:tests" ] -+ } -+ -+ if (chip_build_example_providers) { -+ public_deps += [ "${chip_root}/examples/providers:device_info_provider" ] -+ } -+ -+ if (chip_example_lighting) { -+ public_deps += [ -+ "${chip_root}/examples/lighting-app/lighting-common", -+ "${chip_root}/examples/lighting-app/lighting-common:lighting-manager", -+ ] -+ } -+ -+ output_dir = "${root_out_dir}/lib" -+ -+ complete_static_lib = true -+} -+ -+group("default") { -+ deps = [ ":nuttx" ] -+} -diff --git a/config/nuttx/chip-gn/args.gni b/config/nuttx/chip-gn/args.gni -new file mode 100644 -index 0000000000..480dc26e9f ---- /dev/null -+++ b/config/nuttx/chip-gn/args.gni -@@ -0,0 +1,32 @@ -+# Copyright (c) 2020 Project CHIP Authors -+# -+# Licensed under the Apache License, Version 2.0 (the "License"); -+# you may not use this file except in compliance with the License. -+# You may obtain a copy of the License at -+# -+# http://www.apache.org/licenses/LICENSE-2.0 -+# -+# Unless required by applicable law or agreed to in writing, software -+# distributed under the License is distributed on an "AS IS" BASIS, -+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+# See the License for the specific language governing permissions and -+# limitations under the License. -+ -+import("//build_overrides/chip.gni") -+ -+import("${chip_root}/src/crypto/crypto.gni") -+ -+chip_device_platform = "nuttx" -+ -+chip_build_tests = false -+ -+chip_project_config_include = "" -+chip_system_project_config_include = "" -+chip_ble_project_config_include = "" -+ -+chip_crypto = "mbedtls" -+chip_external_mbedtls = true -+ -+custom_toolchain = "${chip_root}/config/nuttx/chip-gn/toolchain:nuttx" -+ -+pw_build_PIP_CONSTRAINTS = [ "${chip_root}/scripts/setup/constraints.txt" ] -diff --git a/config/nuttx/chip-gn/toolchain/BUILD.gn b/config/nuttx/chip-gn/toolchain/BUILD.gn -new file mode 100644 -index 0000000000..576d96f607 ---- /dev/null -+++ b/config/nuttx/chip-gn/toolchain/BUILD.gn -@@ -0,0 +1,33 @@ -+# Copyright (c) 2020 Project CHIP Authors -+# -+# Licensed under the Apache License, Version 2.0 (the "License"); -+# you may not use this file except in compliance with the License. -+# You may obtain a copy of the License at -+# -+# http://www.apache.org/licenses/LICENSE-2.0 -+# -+# Unless required by applicable law or agreed to in writing, software -+# distributed under the License is distributed on an "AS IS" BASIS, -+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+# See the License for the specific language governing permissions and -+# limitations under the License. -+ -+import("//build/toolchain/gcc_toolchain.gni") -+import("//build_overrides/build.gni") -+ -+declare_args() { -+ nuttx_ar = "" -+ nuttx_cc = "" -+ nuttx_cxx = "" -+} -+ -+gcc_toolchain("nuttx") { -+ ar = nuttx_ar -+ cc = nuttx_cc -+ cxx = nuttx_cxx -+ -+ toolchain_args = { -+ current_os = "nuttx" -+ is_clang = false -+ } -+} -diff --git a/examples/lighting-app/linux/main.cpp b/examples/lighting-app/linux/main.cpp -index 3bd27fddc0..21535c3bcd 100644 ---- a/examples/lighting-app/linux/main.cpp -+++ b/examples/lighting-app/linux/main.cpp -@@ -93,7 +93,7 @@ void ApplicationShutdown() - } - } - --int main(int argc, char * argv[]) -+extern "C" int main(int argc, char * argv[]) - { - if (ChipLinuxAppInit(argc, argv) != 0) - { -diff --git a/scripts/codegen.py b/scripts/codegen.py -index 1f679ea614..1c6a1b1883 100755 ---- a/scripts/codegen.py -+++ b/scripts/codegen.py -@@ -15,6 +15,7 @@ - - import logging - import sys -+sys.path.append('py_matter_idl') - - import click - -diff --git a/src/inet/BUILD.gn b/src/inet/BUILD.gn -index 3f81be8964..966aff5c08 100644 ---- a/src/inet/BUILD.gn -+++ b/src/inet/BUILD.gn -@@ -148,4 +148,9 @@ static_library("inet") { - } - - cflags = [ "-Wconversion" ] -+ if (current_os == "nuttx") { -+ cflags -= [ -+ "-Wconversion", -+ ] -+ } - } -diff --git a/src/lib/core/CHIPError.h b/src/lib/core/CHIPError.h -index 1b621a694f..e67ce24eb9 100644 ---- a/src/lib/core/CHIPError.h -+++ b/src/lib/core/CHIPError.h -@@ -374,13 +374,13 @@ public: - * - * This template ensures that the numeric value is constant and well-formed. - */ -- template -+ template - struct SdkErrorConstant - { - static_assert(FitsInField(kSdkPartLength, to_underlying(PART)), "part is too large"); -- static_assert(FitsInField(kSdkCodeLength, CODE), "code is too large"); -- static_assert(MakeInteger(PART, CODE) != 0, "value is zero"); -- static constexpr StorageType value = MakeInteger(PART, CODE); -+ static_assert(FitsInField(kSdkCodeLength, SCODE), "code is too large"); -+ static_assert(MakeInteger(PART, SCODE) != 0, "value is zero"); -+ static constexpr StorageType value = MakeInteger(PART, SCODE); - }; - }; - -diff --git a/src/platform/BUILD.gn b/src/platform/BUILD.gn -index 7a7b6a81e6..4c3e2b2e30 100644 ---- a/src/platform/BUILD.gn -+++ b/src/platform/BUILD.gn -@@ -297,6 +297,12 @@ if (chip_device_platform != "none" && chip_device_platform != "external") { - } else if (chip_device_platform == "stm32") { - device_layer_target_define = "STM32" - defines += [ "CHIP_DEVICE_LAYER_TARGET=stm32" ] -+ } else if (chip_device_platform == "nuttx") { -+ device_layer_target_define = "LINUX" -+ defines += [ -+ "CHIP_DEVICE_LAYER_TARGET=Linux", -+ "CHIP_DEVICE_CONFIG_ENABLE_WIFI=${chip_enable_wifi}", -+ ] - } else { - device_layer_target_define = "" - } -@@ -559,6 +565,8 @@ if (chip_device_platform != "none") { - _platform_target = "ASR" - } else if (chip_device_platform == "stm32") { - _platform_target = "stm32" -+ } else if (chip_device_platform == "nuttx") { -+ _platform_target = "Linux" - } else { - assert(false, "Unknown chip_device_platform: ${chip_device_platform}") - } -diff --git a/src/platform/Linux/BUILD.gn b/src/platform/Linux/BUILD.gn -index a2cfa6b39c..f746a999a8 100644 ---- a/src/platform/Linux/BUILD.gn -+++ b/src/platform/Linux/BUILD.gn -@@ -20,7 +20,7 @@ import("${build_root}/config/linux/pkg_config.gni") - import("${chip_root}/src/lib/core/core.gni") - import("${chip_root}/src/platform/device.gni") - --assert(chip_device_platform == "linux") -+assert(chip_device_platform == "linux" || chip_device_platform == "nuttx") - - if (chip_use_pw_logging) { - import("//build_overrides/pigweed.gni") -diff --git a/src/platform/Linux/CHIPLinuxStorage.cpp b/src/platform/Linux/CHIPLinuxStorage.cpp -index 9a8afb59d7..52a8b778ce 100644 ---- a/src/platform/Linux/CHIPLinuxStorage.cpp -+++ b/src/platform/Linux/CHIPLinuxStorage.cpp -@@ -198,7 +198,7 @@ CHIP_ERROR ChipLinuxStorage::WriteValue(const char * key, uint32_t val) - { - char buf[32]; - -- snprintf(buf, sizeof(buf), "%d", val); -+ snprintf(buf, sizeof(buf), "%" PRIu32, val); - - return WriteValueStr(key, buf); - } -diff --git a/src/platform/Linux/ConnectivityUtils.cpp b/src/platform/Linux/ConnectivityUtils.cpp -index 2924d48612..7d5ce7e163 100644 ---- a/src/platform/Linux/ConnectivityUtils.cpp -+++ b/src/platform/Linux/ConnectivityUtils.cpp -@@ -27,10 +27,15 @@ - - #include - #include -+#ifdef __NuttX__ -+#include -+#include -+#else - #include - #include - #include - #include -+#endif - #include - #include - #include -@@ -688,7 +693,7 @@ CHIP_ERROR ConnectivityUtils::GetEthPHYRate(const char * ifname, app::Clusters:: - pHYRate = EmberAfPHYRateEnum::EMBER_ZCL_PHY_RATE_ENUM_RATE400_G; - break; - default: -- ChipLogError(DeviceLayer, "Undefined speed! (%d)\n", speed); -+ ChipLogError(DeviceLayer, "Undefined speed! (%" PRIu32 ")\n", speed); - err = CHIP_ERROR_READ_FAILED; - break; - }; -diff --git a/src/platform/Linux/ConnectivityUtils.h b/src/platform/Linux/ConnectivityUtils.h -index e4884e935b..bd79ba44a3 100644 ---- a/src/platform/Linux/ConnectivityUtils.h -+++ b/src/platform/Linux/ConnectivityUtils.h -@@ -26,8 +26,12 @@ - #include - #include - -+#ifdef __NuttX__ -+#include -+#else - #include /* for "caddr_t" et al */ - #include -+#endif - - namespace chip { - namespace DeviceLayer { -diff --git a/src/platform/Linux/DiagnosticDataProviderImpl.cpp b/src/platform/Linux/DiagnosticDataProviderImpl.cpp -index f102b47b65..22bf514a47 100644 ---- a/src/platform/Linux/DiagnosticDataProviderImpl.cpp -+++ b/src/platform/Linux/DiagnosticDataProviderImpl.cpp -@@ -35,10 +35,14 @@ - #include - #include - #include -+#ifdef __NuttX__ -+#include -+#else - #include - #include - #include - #include -+#endif - #include - #include - #include -diff --git a/src/platform/Linux/Logging.cpp b/src/platform/Linux/Logging.cpp -index 28a19a6a30..6617afd54e 100644 ---- a/src/platform/Linux/Logging.cpp -+++ b/src/platform/Linux/Logging.cpp -@@ -49,7 +49,11 @@ void ENFORCE_FORMAT(3, 0) LogV(const char * module, uint8_t category, const char - flockfile(stdout); - - printf("[%" PRIu64 ".%06" PRIu64 "][%lld:%lld] CHIP:%s: ", static_cast(tv.tv_sec), static_cast(tv.tv_usec), -+#ifdef __NuttX__ -+ static_cast(getpid()), static_cast(gettid()), module); -+#else - static_cast(syscall(SYS_getpid)), static_cast(syscall(SYS_gettid)), module); -+#endif - vprintf(msg, v); - printf("\n"); - fflush(stdout); -diff --git a/src/platform/Linux/PlatformManagerImpl.cpp b/src/platform/Linux/PlatformManagerImpl.cpp -index a1c83faf29..5a9afb1204 100644 ---- a/src/platform/Linux/PlatformManagerImpl.cpp -+++ b/src/platform/Linux/PlatformManagerImpl.cpp -@@ -27,8 +27,12 @@ - #include - #include - #include -+#ifdef __NuttX__ -+#include -+#else - #include - #include -+#endif - #include - #include - #include -diff --git a/src/platform/device.gni b/src/platform/device.gni -index cf1dc07325..a9fc1b02d6 100644 ---- a/src/platform/device.gni -+++ b/src/platform/device.gni -@@ -40,6 +40,8 @@ if (chip_device_platform == "auto") { - chip_device_platform = "webos" - } else if (current_os == "zephyr") { - chip_device_platform = "zephyr" -+ } else if (current_os == "nuttx") { -+ chip_device_platform = "nuttx" - } else { - chip_device_platform = "none" - } -@@ -89,7 +91,8 @@ declare_args() { - chip_device_platform == "ameba" || chip_device_platform == "webos" || - chip_device_platform == "cc32xx" || chip_device_platform == "mw320" || - chip_device_platform == "beken" || chip_device_platform == "mt793x" || -- chip_device_platform == "asr" || chip_device_platform == "openiotsdk") { -+ chip_device_platform == "asr" || chip_device_platform == "openiotsdk" || -+ chip_device_platform == "nuttx") { - chip_mdns = "minimal" - } else if (chip_device_platform == "darwin" || - chip_device_platform == "cc13x2_26x2" || -@@ -104,7 +107,8 @@ declare_args() { - # Enable Subscription persistence / resumption for CI and supported platforms - if (chip_device_platform == "darwin" || chip_device_platform == "linux" || - chip_device_platform == "esp32" || chip_device_platform == "fake" || -- chip_device_platform == "efr32" || chip_device_platform == "SiWx917") { -+ chip_device_platform == "efr32" || chip_device_platform == "SiWx917" || -+ chip_device_platform == "nuttx") { - chip_persist_subscriptions = true - } else { - chip_persist_subscriptions = false -@@ -185,6 +189,8 @@ if (chip_device_platform == "cc13x2_26x2") { - _chip_device_layer = "openiotsdk" - } else if (chip_device_platform == "asr") { - _chip_device_layer = "ASR" -+} else if (chip_device_platform == "nuttx") { -+ _chip_device_layer = "Linux" - } else if (chip_device_platform == "stm32") { - _chip_device_layer = "stm32" - } -@@ -257,5 +263,5 @@ assert( - chip_device_platform == "bl702" || chip_device_platform == "bl702l" || - chip_device_platform == "mt793x" || chip_device_platform == "SiWx917" || - chip_device_platform == "openiotsdk" || chip_device_platform == "asr" || -- chip_device_platform == "stm32", -+ chip_device_platform == "stm32" || chip_device_platform == "nuttx", - "Please select a valid value for chip_device_platform") --- -2.25.1 - diff --git a/netutils/connectedhomeip/CMakeLists.txt b/netutils/connectedhomeip/CMakeLists.txt deleted file mode 100644 index 1031b4727..000000000 --- a/netutils/connectedhomeip/CMakeLists.txt +++ /dev/null @@ -1,367 +0,0 @@ -# ############################################################################## -# apps/netutils/connectedhomeip/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_MATTER) - - include(ExternalProject) - - function(chip_download_and_patch) - - # parse arguments into variables - - nuttx_parse_function_args( - FUNC - chip_download_and_patch - ONE_VALUE - NAME - URL - SOURCE_DIR - BINARY_DIR - TIMEOUT - MULTI_VALUE - PATCH_LIST - ARGN - ${ARGN}) - - if(NOT EXISTS ${SOURCE_DIR}) - FetchContent_Declare( - ${NAME}_fetch - URL ${URL} SOURCE_DIR ${SOURCE_DIR} BINARY_DIR ${BINARY_DIR} - DOWNLOAD_NO_PROGRESS true - TIMEOUT ${TIMEOUT}) - - FetchContent_GetProperties(${NAME}_fetch) - - if(NOT ${NAME}_fetch_POPULATED) - FetchContent_Populate(${NAME}_fetch) - endif() - - if(PATCH_LIST) - foreach(PATCH ${PATCH_LIST}) - execute_process(COMMAND sh -c "patch -p1 < ${PATCH}" - WORKING_DIRECTORY ${SOURCE_DIR}) - endforeach() - endif() - - endif() - - endfunction() - - get_filename_component( - CHIP_ROOT ${NUTTX_APPS_DIR}/netutils/connectedhomeip/connectedhomeip - REALPATH) - - chip_download_and_patch( - NAME - chip - URL - https://github.com/project-chip/connectedhomeip/archive/refs/tags/v1.2.0.1.zip - SOURCE_DIR - ${CMAKE_CURRENT_LIST_DIR}/connectedhomeip - BINARY_DIR - ${CMAKE_BINARY_DIR}/apps/netutils/connectedhomeip - TIMEOUT - 90 - PATCH_LIST - ${CMAKE_CURRENT_SOURCE_DIR}/0001-chip-add-compile-support-for-NuttX.patch) - - chip_download_and_patch( - NAME - pigweed - URL - https://github.com/google/pigweed/archive/1f12d06f51.zip - SOURCE_DIR - ${CMAKE_CURRENT_LIST_DIR}/pigweed - BINARY_DIR - ${CMAKE_BINARY_DIR}/apps/netutils/connectedhomeip - TIMEOUT - 90) - - chip_download_and_patch( - NAME - nlio - URL - https://github.com/nestlabs/nlio/archive/refs/tags/1.1.8.zip - SOURCE_DIR - ${CMAKE_CURRENT_LIST_DIR}/nlio - BINARY_DIR - ${CMAKE_BINARY_DIR}/apps/netutils/connectedhomeip - TIMEOUT - 30) - - chip_download_and_patch( - NAME - nlassert - URL - https://github.com/nestlabs/nlassert/archive/refs/tags/1.1.8.zip - SOURCE_DIR - ${CMAKE_CURRENT_LIST_DIR}/nlassert - BINARY_DIR - ${CMAKE_BINARY_DIR}/apps/netutils/connectedhomeip - TIMEOUT - 30) - - chip_download_and_patch( - NAME - nlunit-test - URL - https://github.com/nestlabs/nlunit-test/archive/refs/tags/1.0.9.zip - SOURCE_DIR - ${CMAKE_CURRENT_LIST_DIR}/nlunit-test - BINARY_DIR - ${CMAKE_BINARY_DIR}/apps/netutils/connectedhomeip - TIMEOUT - 30) - - chip_download_and_patch( - NAME - inipp - URL - https://github.com/mcmtroffaes/inipp/archive/refs/tags/1.0.12.zip - SOURCE_DIR - ${CMAKE_CURRENT_LIST_DIR}/inipp - BINARY_DIR - ${CMAKE_BINARY_DIR}/apps/netutils/connectedhomeip - TIMEOUT - 30) - - get_filename_component(GN_ROOT_TARGET ${CHIP_ROOT}/config/nuttx/chip-gn - REALPATH) - get_filename_component(COMMON_CMAKE_SOURCE_DIR - ${CHIP_ROOT}/config/common/cmake REALPATH) - - include(${COMMON_CMAKE_SOURCE_DIR}/chip_gn_args.cmake) - include(${COMMON_CMAKE_SOURCE_DIR}/chip_gn.cmake) - - set(nuttx_include_dirs) - get_target_property(include_dirs nuttx NUTTX_CXX_INCLUDE_DIRECTORIES) - if(include_dirs) - list(APPEND nuttx_include_dirs ${include_dirs}) - endif() - list(APPEND nuttx_include_dirs ${NUTTX_DIR}/include - ${CMAKE_BINARY_DIR}/include) - list(APPEND nuttx_include_dirs ${NUTTX_APPS_BINDIR}/include/mbedtls) - - set(MATTER_INCDIR - ${nuttx_include_dirs} - ${CMAKE_BINARY_DIR}/apps/netutils/connectedhomeip/gen/include - ${NUTTX_APPS_DIR}/include - ${NUTTX_APPS_DIR}/netutils/jsoncpp/jsoncpp/include - inipp - nlio/include - nlassert/include - connectedhomeip/src - connectedhomeip/src/include - connectedhomeip/src/lib/dnssd - connectedhomeip/src/app/util/mock/include - connectedhomeip/zzz_generated - connectedhomeip/zzz_generated/lighting-app - connectedhomeip/zzz_generated/app-common - connectedhomeip/src/platform/Linux - connectedhomeip/examples/platform/linux - connectedhomeip/examples/lighting-app/lighting-common/include) - - set(gn_depens mbedtls) - set(MATTER_FLAGS - -DCHIP_HAVE_CONFIG_H - -std=${CONFIG_CXX_STANDARD} - -Wno-undef - -DCHIP_ADDRESS_RESOLVE_IMPL_INCLUDE_HEADER= - ) - - set(EXTERNAL_MATTER_INCDIR) - - foreach(estring ${MATTER_INCDIR}) - list(APPEND EXTERNAL_MATTER_INCDIR "\"${estring}\"") - endforeach() - - matter_add_gn_arg_string("nuttx_ar" ${CMAKE_AR}) - matter_add_gn_arg_string("nuttx_cc" ${CMAKE_C_COMPILER}) - matter_add_gn_arg_string("nuttx_cxx" ${CMAKE_CXX_COMPILER}) - matter_add_flags("-D__NuttX__ ") - - if(CONFIG_ARCH_SIM) - if(CONFIG_SIM_M32) - matter_add_gn_arg_string("target_cpu" "x86") - else() - matter_add_gn_arg_string("target_cpu" "x86_64") - endif() - - elseif(CONFIG_ARCH_ARM) - matter_add_gn_arg_string("target_cpu" "arm") - elseif(CONFIG_ARCH_RISCV) - matter_add_gn_arg_string("target_cpu" "riscv") - matter_add_gn_arg_string("riscv_arch" "${ARCHTYPE}${ARCHCPUEXTFLAGS}") - - if(CONFIG_ARCH_DPFPU) - matter_add_gn_arg_string("riscv_abi" "${ARCHABITYPE}d") - elseif(CONFIG_ARCH_FPU) - matter_add_gn_arg_string("riscv_abi" "${ARCHABITYPE}f") - else() - matter_add_gn_arg_string("riscv_abi" "${ARCHABITYPE}") - endif() - - if(CONFIG_ARCH_RV32) - if(${ARCHCPUEXTFLAGS} STREQUAL imc) - matter_add_gn_arg_string("riscv_cpu" "sifive-e20") - elseif(${ARCHCPUEXTFLAGS} STREQUAL imac) - matter_add_gn_arg_string("riscv_cpu" "sifive-e31") - elseif(${ARCHCPUEXTFLAGS} STREQUAL imafc) - matter_add_gn_arg_string("riscv_cpu" "sifive-e76") - endif() - else() - if(${ARCHCPUEXTFLAGS} STREQUAL imac) - matter_add_gn_arg_string("riscv_cpu" "sifive-s51") - elseif(${ARCHCPUEXTFLAGS} STREQUAL imafdc) - matter_add_gn_arg_string("riscv_cpu" "sifive-u54") - endif() - endif() - - if(CONFIG_ARCH_RV64) - matter_add_flags("-mcmodel=medany") - endif() - endif() - - matter_add_gn_arg_bool("chip_inet_config_enable_ipv4" CONFIG_NET_IPv4) - matter_add_gn_arg_bool("enable_eventlist_attribute" true) - matter_add_gn_arg_bool("chip_enable_ble") - matter_add_gn_arg_bool("chip_example_lighting" true) - matter_add_gn_arg_bool("chip_config_network_layer_ble") - if(NOT CONFIG_MATTER_LOG) - matter_add_gn_arg_bool("chip_error_logging") - matter_add_gn_arg_bool("chip_progress_logging") - matter_add_gn_arg_bool("chip_detail_logging") - matter_add_gn_arg_bool("chip_automation_logging") - matter_add_gn_arg_bool("chip_pw_tokenizer_logging") - matter_add_gn_arg_bool("chip_use_pw_logging") - endif() - - matter_get_compiler_flags_from_targets(nuttx) - matter_common_gn_args(PROJECT_CONFIG_INC_DIR ${EXTERNAL_MATTER_INCDIR}) - - matter_generate_args_tmp_file() - - matter_build( - chip - LIB_SHELL - ${CONFIG_CHIP_LIB_SHELL} - LIB_PW_RPC - ${CONFIG_CHIP_PW_RPC} - LIB_TESTS - ${CONFIG_CHIP_BUILD_TESTS} - LIB_MBEDTLS - GN_DEPENDENCIES - ${gn_depens}) - - add_custom_command( - OUTPUT connectedhomeip/third_party/pigweed/repo - COMMAND rm ${CHIP_ROOT}/third_party/pigweed/repo -rf - COMMAND ln -s ${NUTTX_APPS_DIR}/netutils/connectedhomeip/pigweed - ${CHIP_ROOT}/third_party/pigweed/repo) - - add_custom_target(chippigweed ALL - DEPENDS connectedhomeip/third_party/pigweed/repo) - ExternalProject_Add_StepDependencies(chip-gn configure chippigweed) - - add_custom_command( - OUTPUT ${CHIP_ROOT}/build_overrides/pigweed_environment.gni - COMMAND touch ${CHIP_ROOT}/build_overrides/pigweed_environment.gni) - - add_custom_target( - chipnpigweedenv ALL - DEPENDS ${CHIP_ROOT}/build_overrides/pigweed_environment.gni) - ExternalProject_Add_StepDependencies(chip-gn configure chipnpigweedenv) - add_dependencies(chippigweed chipnpigweedenv) - - add_custom_command( - OUTPUT connectedhomeip/third_party/nlassert/repo - COMMAND rm ${CHIP_ROOT}/third_party/nlassert/repo -rf - COMMAND ln -s ${NUTTX_APPS_DIR}/netutils/connectedhomeip/nlassert - ${CHIP_ROOT}/third_party/nlassert/repo) - - add_custom_target(chipnlassert ALL - DEPENDS connectedhomeip/third_party/nlassert/repo) - ExternalProject_Add_StepDependencies(chip-gn configure chipnlassert) - - add_custom_command( - OUTPUT connectedhomeip/third_party/nlio/repo - COMMAND rm ${CHIP_ROOT}/third_party/nlio/repo -rf - COMMAND ln -s ${NUTTX_APPS_DIR}/netutils/connectedhomeip/nlio - ${CHIP_ROOT}/third_party/nlio/repo) - - add_custom_target(chipnlio ALL DEPENDS connectedhomeip/third_party/nlio/repo) - ExternalProject_Add_StepDependencies(chip-gn configure chipnlio) - - add_custom_command( - OUTPUT connectedhomeip/third_party/nlunit-test/repo - COMMAND rm ${CHIP_ROOT}/third_party/nlunit-test/repo -rf - COMMAND ln -s ${NUTTX_APPS_DIR}/netutils/connectedhomeip/nlunit-test - ${CHIP_ROOT}/third_party/nlunit-test/repo) - - add_custom_target(chipnlunit-test ALL - DEPENDS connectedhomeip/third_party/nlunit-test/repo) - ExternalProject_Add_StepDependencies(chip-gn configure chipnlunit-test) - - add_custom_command( - OUTPUT connectedhomeip/third_party/jsoncpp/repo - COMMAND rm -rf ${CHIP_ROOT}/third_party/jsoncpp/repo - COMMAND ln -s ${NUTTX_APPS_DIR}/netutils/jsoncpp/jsoncpp - ${CHIP_ROOT}/third_party/jsoncpp/repo) - - add_custom_target(chipjsoncpp ALL - DEPENDS connectedhomeip/third_party/jsoncpp/repo) - ExternalProject_Add_StepDependencies(chip-gn configure chipjsoncpp) - - set(DEMOSRC - ${CHIP_ROOT}/examples/lighting-app/linux/main.cpp - ${CHIP_ROOT}/examples/lighting-app/linux/LightingAppCommandDelegate.cpp) - - nuttx_add_application( - NAME - matter - SRCS - ${DEMOSRC} - INCLUDE_DIRECTORIES - ${MATTER_INCDIR} - COMPILE_FLAGS - ${MATTER_FLAGS} - DEPENDS - chip-gn - mbedtls - STACKSIZE - 16384 - PRIORITY - 100) - - add_custom_command( - OUTPUT ${CMAKE_BINARY_DIR}/apps/netutils/connectedhomeip/lib/libchipnuttx.a - COMMAND echo generate libchipnuttx.a) - add_custom_target( - libchipnuttx ALL - DEPENDS ${CMAKE_BINARY_DIR}/apps/netutils/connectedhomeip/lib/libchipnuttx.a - ) - add_dependencies(libchipnuttx chip-gn) - - nuttx_add_extra_library( - ${CMAKE_BINARY_DIR}/apps/netutils/connectedhomeip/lib/libchipnuttx.a) - -endif() diff --git a/netutils/connectedhomeip/Kconfig b/netutils/connectedhomeip/Kconfig deleted file mode 100644 index 59fe6a3e7..000000000 --- a/netutils/connectedhomeip/Kconfig +++ /dev/null @@ -1,20 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config MATTER - bool "Connected Home over IP (CHIP)" - default n - ---help--- - Enable the Connected Home over IP (CHIP) - -if MATTER - -config MATTER_LOG - bool "Build matter with logs" - default n - ---help--- - To reduce flash size, logs are not opened by default - -endif diff --git a/netutils/cwebsocket/0001-Porting-the-code-for-NuttX.patch b/netutils/cwebsocket/0001-Porting-the-code-for-NuttX.patch deleted file mode 100644 index dc3348b04..000000000 --- a/netutils/cwebsocket/0001-Porting-the-code-for-NuttX.patch +++ /dev/null @@ -1,1737 +0,0 @@ -From 3898d4b6601f951f630f615098f5546f7184fe90 Mon Sep 17 00:00:00 2001 -From: SPRESENSE <41312067+SPRESENSE@users.noreply.github.com> -Date: Fri, 19 Apr 2019 17:40:58 +0900 -Subject: [PATCH 1/2] Porting the code for NuttX - ---- - cwebsocket/src/cwebsocket/client.c | 801 +++++++++++++++++++---------- - cwebsocket/src/cwebsocket/client.h | 177 ++++++- - cwebsocket/src/cwebsocket/common.c | 29 +- - cwebsocket/src/cwebsocket/common.h | 68 ++- - 4 files changed, 752 insertions(+), 323 deletions(-) - -diff --git a/cwebsocket/src/cwebsocket/client.c b/cwebsocket/src/cwebsocket/client.c -index 09f7a06..50747f0 100755 ---- a/cwebsocket/src/cwebsocket/client.c -+++ b/cwebsocket/src/cwebsocket/client.c -@@ -24,116 +24,198 @@ - - #include "client.h" - --void cwebsocket_client_init(cwebsocket_client *websocket, cwebsocket_subprotocol *subprotocols[], int subprotocol_len) { -+/* for NUTTX */ -+extern int getaddrinfo(const char *nodename, const char *servname, -+ const struct addrinfo *hints, struct addrinfo **res); -+extern void freeaddrinfo(struct addrinfo *res); -+extern int ws_sscanf(FAR const char *buf, FAR const char *fmt, ...); -+ -+int cwebsocket_client_init(cwebsocket_client *websocket, cwebsocket_subprotocol **subprotocols, int subprotocol_len) { -+ if (subprotocol_len > WEBSOCKET_SUBPROTOCOL_MAX) -+ return -1; - websocket->fd = 0; - websocket->retry = 0; - websocket->uri = '\0'; - websocket->flags = 0; - websocket->state = WEBSOCKET_STATE_CLOSED; -+ websocket->proxy_addr = NULL; -+ websocket->proxy_port = NULL; -+ websocket->headers = NULL; -+ websocket->num_headers = 0; - websocket->subprotocol_len = subprotocol_len; - int i; - for(i=0; iname); -+ WS_DEBUG("client_init: loading subprotocol %s\n", subprotocols[i]->name); -+ - websocket->subprotocols[i] = subprotocols[i]; - } -- const rlim_t kStackSize = CWS_STACK_SIZE_MIN * 1024 * 1024; -- struct rlimit rl; -- int result; -- result = getrlimit(RLIMIT_STACK, &rl); -- if (result == 0) { -- if (rl.rlim_cur < kStackSize) { -- rl.rlim_cur = kStackSize; -- result = setrlimit(RLIMIT_STACK, &rl); -- if(result != 0) { -- syslog(LOG_CRIT, "cwebsocket_client_init: unable to set stack space"); -- exit(1); -- } -- } -+ websocket->subprotocol = websocket->subprotocols[0]; -+ return 0; -+} -+ -+void cwebsocket_client_set_proxy(cwebsocket_client *websocket, char *proxy_addr, char *proxy_port) -+{ -+ if (strlen(proxy_addr) > 0 && strlen(proxy_port) > 0){ -+ websocket->flags |= WEBSOCKET_FLAG_PROXY; -+ websocket->proxy_addr = proxy_addr; -+ websocket->proxy_port = proxy_port; -+ }else { -+ WS_DEBUG("client_set_proxy: invalid proxy_addr\n"); -+ } -+} -+void cwebsocket_client_unset_proxy(cwebsocket_client *websocket) -+{ -+ if (websocket->flags & WEBSOCKET_FLAG_PROXY){ -+ websocket->proxy_addr = NULL; -+ websocket->proxy_port = NULL; -+ websocket->flags |= ~WEBSOCKET_FLAG_PROXY; - } -- getrlimit(RLIMIT_STACK, &rl); -- syslog(LOG_DEBUG, "cwebsocket_client_init: stack limit min=%ld, max=%ld\n", rl.rlim_cur, rl.rlim_max); - } - - void cwebsocket_client_parse_uri(cwebsocket_client *websocket, const char *uri, - char *hostname, char *port, char *resource, char *querystring) { - -- if(sscanf(uri, "ws://%[^:]:%[^/]%[^?]%s", hostname, port, resource, querystring) == 4) { -+ if(ws_sscanf(uri, "ws://%[^:]:%[^/]%[^?]%s", hostname, port, resource, querystring) == 4) { - return; - } -- else if(sscanf(uri, "ws://%[^:]:%[^/]%s", hostname, port, resource) == 3) { -+ else if(ws_sscanf(uri, "ws://%[^:]:%[^/]%s", hostname, port, resource) == 3) { - strcpy(querystring, ""); - return; - } -- else if(sscanf(uri, "ws://%[^:]:%[^/]%s", hostname, port, resource) == 2) { -- strcpy(resource, "/"); -+ else if(ws_sscanf(uri, "ws://%[^:]:%[^/]%s", hostname, port, resource) == 2) { -+ strncpy(resource, "/", strlen("/")); - strcpy(querystring, ""); - return; - } -- else if(sscanf(uri, "ws://%[^/]%s", hostname, resource) == 2) { -- strcpy(port, "80"); -+ else if(ws_sscanf(uri, "ws://%[^/]%s", hostname, resource) == 2) { -+ strncpy(port, "80", strlen("80")); - strcpy(querystring, ""); - return; - } -- else if(sscanf(uri, "ws://%[^/]", hostname) == 1) { -- strcpy(port, "80"); -- strcpy(resource, "/"); -+ else if(ws_sscanf(uri, "ws://%[^/]", hostname) == 1) { -+ strncpy(port, "80", strlen("80")); -+ strncpy(resource, "/", strlen("/")); - strcpy(querystring, ""); - return; - } - #ifdef ENABLE_SSL -- else if(sscanf(uri, "wss://%[^:]:%[^/]%[^?]%s", hostname, port, resource, querystring) == 4) { -+ else if(ws_sscanf(uri, "wss://%[^:]:%[^/]%[^?]%s", hostname, port, resource, querystring) == 4) { - websocket->flags |= WEBSOCKET_FLAG_SSL; - return; - } -- else if(sscanf(uri, "wss://%[^:]:%[^/]%s", hostname, port, resource) == 3) { -+ else if(ws_sscanf(uri, "wss://%[^:]:%[^/]%s", hostname, port, resource) == 3) { - strcpy(querystring, ""); - websocket->flags |= WEBSOCKET_FLAG_SSL; - return; - } -- else if(sscanf(uri, "wss://%[^:]:%[^/]%s", hostname, port, resource) == 2) { -- strcpy(resource, "/"); -+ else if(ws_sscanf(uri, "wss://%[^:]:%[^/]%s", hostname, port, resource) == 2) { -+ strncpy(resource, "/", strlen("/")); - strcpy(querystring, ""); - websocket->flags |= WEBSOCKET_FLAG_SSL; - return; - } -- else if(sscanf(uri, "wss://%[^/]%s", hostname, resource) == 2) { -- strcpy(port, "443"); -+ else if(ws_sscanf(uri, "wss://%[^/]%s", hostname, resource) == 2) { -+ strncpy(port, "443", strlen("443")); - strcpy(querystring, ""); - websocket->flags |= WEBSOCKET_FLAG_SSL; - return; - } -- else if(sscanf(uri, "wss://%[^/]", hostname) == 1) { -- strcpy(port, "443"); -- strcpy(resource, "/"); -+ else if(ws_sscanf(uri, "wss://%[^/]", hostname) == 1) { -+ strncpy(port, "443", strlen("443")); -+ strncpy(resource, "/", strlen("/")); - strcpy(querystring, ""); - websocket->flags |= WEBSOCKET_FLAG_SSL; - return; - } - #endif - else if(strstr(uri, "wss://") > 0) { -- syslog(LOG_CRIT, "cwebsocket_client_parse_uri: recompile with SSL support to use a secure connection"); -+ WS_DEBUG("client_parse_uri: recompile with SSL support to use a secure connection"); - exit(1); - } - else { -- syslog(LOG_CRIT, "cwebsocket_client_parse_uri: invalid websocket URL\n"); -+ WS_DEBUG("client_parse_uri: invalid websocket URL : %s\n", uri); - exit(1); - } - } - -+ -+int cwebsocket_client_ssl_init(cwebsocket_client *websocket, char *cert_name, char *cli_cert, char *cli_key, char *passphrase) { -+#ifdef ENABLE_SSL -+ int ret= 0; -+ -+ WS_DEBUG("client_connect: using secure (SSL) connection\n"); -+ -+ mbedtls_net_init( &websocket->ssl_net_ctx ); -+ mbedtls_ssl_init( &websocket->ssl ); -+ mbedtls_ssl_config_init( &websocket->conf ); -+ mbedtls_x509_crt_init( &websocket->cacert ); -+ mbedtls_ctr_drbg_init( &websocket->ctr_drbg ); -+ mbedtls_entropy_init( &websocket->entropy ); -+ -+ if( ( ret = mbedtls_ctr_drbg_seed( &websocket->ctr_drbg, NULL, &websocket->entropy, -+ (const unsigned char *) "ssl_client1", -+ strlen( "ssl_client1" ) ) ) != 0 ) -+ { -+ WS_DEBUG(" failed\n ! mbedtls_ctr_drbg_seed returned %d\n", ret ); -+ return -1; -+ } -+ ret = mbedtls_x509_crt_parse_file( &websocket->cacert, cert_name ); -+ if( ret != 0 ) -+ { -+ WS_DEBUG("nothing file = -0x%x\n", -ret); -+ return -1; -+ } -+ -+ if( ( ret = mbedtls_ssl_config_defaults( &websocket->conf, -+ MBEDTLS_SSL_IS_CLIENT, -+ MBEDTLS_SSL_TRANSPORT_STREAM, -+ MBEDTLS_SSL_PRESET_DEFAULT ) ) != 0 ) -+ { -+ WS_DEBUG(" failed\n ! mbedtls_ssl_config_defaults returned -0x%x\n\n", ret ); -+ return -1; -+ } -+ -+ /* OPTIONAL is not optimal for security, -+ * but makes interop easier in this simplified example */ -+ mbedtls_ssl_conf_authmode( &websocket->conf, MBEDTLS_SSL_VERIFY_OPTIONAL ); -+ mbedtls_ssl_conf_ca_chain( &websocket->conf, &websocket->cacert, NULL ); -+ mbedtls_ssl_conf_rng( &websocket->conf, NULL, &websocket->ctr_drbg ); -+ -+ if (cli_cert != NULL && cli_key != NULL){ -+ ret = mbedtls_x509_crt_parse_file(&websocket->clicert, cli_cert); -+ if (ret == 0) { -+ ret = mbedtls_pk_parse_keyfile(&websocket->pkey, cli_key, passphrase); -+ if (ret != 0) { -+ WS_DEBUG("Private Key not found\n"); -+ return -1; -+ } -+ } else { -+ WS_DEBUG("Client certificate not found\n"); -+ return -1; -+ } -+ mbedtls_ssl_conf_own_cert(&websocket->conf, &websocket->clicert, &websocket->pkey); -+ } -+ -+ return ret; -+#else -+ return -1; -+#endif -+} -+ - int cwebsocket_client_connect(cwebsocket_client *websocket) { - - if(websocket->state & WEBSOCKET_STATE_CONNECTED) { -- syslog(LOG_CRIT, "cwebsocket_client_connect: socket already connected"); -+ WS_DEBUG("client_connect: socket already connected"); - return -1; - } - - if(websocket->state & WEBSOCKET_STATE_CONNECTING) { -- syslog(LOG_CRIT, "cwebsocket_client_connect: socket already connecting"); -+ WS_DEBUG("client_connect: socket already connecting"); - return -1; - } - - if(websocket->state & WEBSOCKET_STATE_OPEN) { -- syslog(LOG_CRIT, "cwebsocket_client_connect: socket already open"); -+ WS_DEBUG("client_connect: socket already open"); - return -1; - } - -@@ -154,24 +236,35 @@ int cwebsocket_client_connect(cwebsocket_client *websocket) { - #else - websocket->state = WEBSOCKET_STATE_CONNECTING; - #endif -- -+#ifdef ENABLE_SSL -+ uint32_t flags; -+ int ret; -+#endif - char hostname[100]; - char port[6]; - char resource[256]; - char querystring[256]; -+ -+ memset(hostname, 0, 100); -+ memset(port, 0, 6); -+ memset(resource, 0, 256); -+ memset(querystring, 0, 100); -+ - cwebsocket_client_parse_uri(websocket, websocket->uri, hostname, port, resource, querystring); - -- syslog(LOG_DEBUG, "cwebsocket_client_connect: hostname=%s, port=%s, resource=%s, querystring=%s, secure=%i\n", -+ WS_DEBUG ("client_connect: hostname=%s, port=%s, resource=%s, querystring=%s, secure=%i\n", - hostname, port, resource, querystring, (websocket->flags & WEBSOCKET_FLAG_SSL)); - -- char handshake[1024]; -- struct addrinfo hints, *servinfo; -+ char handshake[CWS_HANDSHAKE_BUFFER_MAX]; -+ struct addrinfo hints, *servinfo; -+ time_t Tick0 = 0; -+ time(&Tick0); - - memset(&hints, 0, sizeof hints); - hints.ai_family = AF_INET; - hints.ai_socktype = SOCK_STREAM; - -- srand(time(NULL)); -+ srand(Tick0); - char nonce[16]; - static const char alphanum[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvwxyz"; - int i; -@@ -180,100 +273,178 @@ int cwebsocket_client_connect(cwebsocket_client *websocket) { - } - char *seckey = cwebsocket_base64_encode((const unsigned char *)nonce, sizeof(nonce)); - -- snprintf(handshake, 1024, -- "GET %s%s HTTP/1.1\r\n" -- "Host: %s:%s\r\n" -- "Upgrade: WebSocket\r\n" -- "Connection: Upgrade\r\n" -- "Sec-WebSocket-Key: %s\r\n" -- "Sec-WebSocket-Version: 13\r\n" -+ snprintf(handshake, CWS_HANDSHAKE_BUFFER_MAX, -+ "GET %s%s HTTP/1.1\r\n" -+ "Host: %s:%s\r\n" -+ "Upgrade: WebSocket\r\n" -+ "Connection: Upgrade\r\n" -+ "Sec-WebSocket-Key: %s\r\n" -+ "Sec-WebSocket-Version: 13\r\n" - ,resource, querystring, hostname, port, seckey); - -+ if((websocket->headers != NULL) && (websocket->num_headers > 0)) { -+ for(i = 0; i < websocket->num_headers; i++) { -+ strncat(handshake, websocket->headers[i], (CWS_HANDSHAKE_BUFFER_MAX - strlen(handshake))); -+ strncat(handshake, "\r\n", (CWS_HANDSHAKE_BUFFER_MAX - strlen(handshake))); -+ } -+ } -+ - if(websocket->subprotocol_len > 0) { -- strcat(handshake, "Sec-WebSocket-Protocol: "); -+ strncat(handshake, "Sec-WebSocket-Protocol: ", (CWS_HANDSHAKE_BUFFER_MAX - strlen(handshake))); - for(i=0; isubprotocol_len; i++) { -- strcat(handshake, websocket->subprotocols[i]->name); -+ strncat(handshake, websocket->subprotocols[i]->name, (CWS_HANDSHAKE_BUFFER_MAX - strlen(handshake))); - if(isubprotocol_len) { -- strcat(handshake, " "); -+ strncat(handshake, " ", (CWS_HANDSHAKE_BUFFER_MAX - strlen(handshake))); - } - else { -- strcat(handshake, "\r\n"); -+ strncat(handshake, "\r\n", (CWS_HANDSHAKE_BUFFER_MAX - strlen(handshake))); - } - } -+ strncat(handshake, "\r\n", (CWS_HANDSHAKE_BUFFER_MAX - strlen(handshake))); - } - -- strcat(handshake, "\r\n"); -+ strncat(handshake, "\r\n", (CWS_HANDSHAKE_BUFFER_MAX - strlen(handshake))); - -- if(getaddrinfo(hostname, port, &hints, &servinfo) != 0 ) { -- freeaddrinfo(servinfo); -- const char *errmsg = "invalid hostname or IP"; -- syslog(LOG_ERR, "cwebsocket_client_connect: %s", errmsg); -- cwebsocket_client_onerror(websocket, errmsg); -- return -1; -- } -+ if(websocket->flags & WEBSOCKET_FLAG_SSL) { -+#ifdef ENABLE_SSL -+ if( ( ret = mbedtls_ssl_setup( &websocket->ssl, &websocket->conf ) ) != 0 ) -+ { -+ WS_DEBUG( " failed\n ! mbedtls_ssl_setup returned -0x%x\n\n", -ret ); -+ goto fail; -+ } -+ if(websocket->flags & WEBSOCKET_FLAG_PROXY) { -+ /* SSL On / Proxy On -+ Execute CONNECT command of non-secure message after connecting to proxy server. -+ */ -+ if( ( ret = mbedtls_net_connect( &websocket->ssl_net_ctx, websocket->proxy_addr, -+ websocket->proxy_port, MBEDTLS_NET_PROTO_TCP ) ) != 0 ) -+ { -+ WS_DEBUG(" failed\n ! mbedtls_net_connect proxy returned %d\n\n", ret ); -+ goto fail; -+ } -+ if(websocket->flags & WEBSOCKET_FLAG_PROXY) { -+ char proxy_connect[CWS_HANDSHAKE_BUFFER_MAX]; -+ -+ snprintf(proxy_connect, CWS_HANDSHAKE_BUFFER_MAX, -+ "CONNECT %s:%s HTTP/1.1\r\n" -+ "Host: %s\r\n" -+ , hostname, port, hostname); -+ strncat(proxy_connect, "\r\n", (CWS_HANDSHAKE_BUFFER_MAX - strlen(proxy_connect))); -+ if(write(websocket->ssl_net_ctx.fd, proxy_connect, strlen(proxy_connect)) == -1) { -+ WS_DEBUG("proxy_client_write: NG A\n"); -+ goto fail; -+ } -+ if(cwebsocket_client_read_handshake(websocket, seckey, websocket->flags) == -1) { -+ WS_DEBUG("proxy_client_read_handshake for SSL: %s\n", seckey); -+ goto fail; -+ } -+ } -+ }else{ -+ /* SSL On / Proxy OFF -+ Connecting to websocket server. -+ */ -+ if( ( ret = mbedtls_net_connect( &websocket->ssl_net_ctx, hostname, -+ port, MBEDTLS_NET_PROTO_TCP ) ) != 0 ) -+ { -+ WS_DEBUG(" failed\n ! mbedtls_net_connect returned %d\n\n", ret ); -+ goto fail; -+ } -+ } - -- websocket->fd = socket(servinfo->ai_family, servinfo->ai_socktype, servinfo->ai_protocol); -- if(websocket->fd < 0) { -- freeaddrinfo(servinfo); -- syslog(LOG_ERR, "cwebsocket_client_connect: %s", strerror(errno)); -- cwebsocket_client_onerror(websocket, strerror(errno)); -- return -1; -- } -+ mbedtls_ssl_set_bio( &websocket->ssl, &websocket->ssl_net_ctx, NULL, NULL, NULL); - -- if(connect(websocket->fd, servinfo->ai_addr, servinfo->ai_addrlen) != 0 ) { -- syslog(LOG_ERR, "cwebsocket_client_connect: %s", strerror(errno)); -- cwebsocket_client_onerror(websocket, strerror(errno)); -- websocket->state = WEBSOCKET_STATE_CLOSED; -- if(websocket->retry > 0) { -- sleep(websocket->retry); -- cwebsocket_client_connect(websocket); -+ while( ( ret = mbedtls_ssl_handshake( &websocket->ssl ) ) != 0 ) -+ { -+ if( ret != MBEDTLS_ERR_SSL_WANT_READ && ret != MBEDTLS_ERR_SSL_WANT_WRITE ) -+ { -+ WS_DEBUG(" failed\n ! mbedtls_ssl_handshake returned -0x%x\n\n", -ret ); -+ goto fail; -+ } - } -- return -1; -- } -- freeaddrinfo(servinfo); -+ websocket->fd = websocket->ssl_net_ctx.fd; - -- int optval = 1; -- if(setsockopt(websocket->fd, SOL_SOCKET, SO_KEEPALIVE, &optval, sizeof optval) == -1) { -- syslog(LOG_ERR, "cwebsocket_client_connect: %s", strerror(errno)); -- cwebsocket_client_onerror(websocket, strerror(errno)); -- return -1; -- } -+ /* In real life, we probably want to bail out when ret != 0 */ -+ if( ( flags = mbedtls_ssl_get_verify_result( &websocket->ssl ) ) != 0 ) -+ { -+ char vrfy_buf[512]; - --#ifdef ENABLE_SSL -+ mbedtls_x509_crt_verify_info( vrfy_buf, sizeof( vrfy_buf ), " ! ", flags ); - -- websocket->ssl = NULL; -- websocket->sslctx = NULL; -+ WS_DEBUG("%s\n", vrfy_buf ); - -- if(websocket->flags & WEBSOCKET_FLAG_SSL) { -- -- syslog(LOG_DEBUG, "cwebsocket_client_connect: using secure (SSL) connection"); -+ } -+ else -+ WS_DEBUG(" certificate ok\n"); -+#endif -+ }else { -+ if(websocket->flags & WEBSOCKET_FLAG_PROXY) { -+ if(getaddrinfo(websocket->proxy_addr, websocket->proxy_port, &hints, &servinfo) != 0 ) { -+ freeaddrinfo(servinfo); -+ const char *errmsg = "invalid hostname or IP"; -+ WS_DEBUG("client_proxy_connect: %s", websocket->proxy_addr); -+ cwebsocket_client_onerror(websocket, errmsg); -+ goto fail; -+ } -+ }else { -+ if(getaddrinfo(hostname, port, &hints, &servinfo) != 0 ) { -+ freeaddrinfo(servinfo); -+ const char *errmsg = "invalid hostname or IP"; -+ WS_DEBUG("client_non_proxy_connect: %s", errmsg); -+ cwebsocket_client_onerror(websocket, errmsg); -+ goto fail; -+ } -+ } - -- SSL_load_error_strings(); -- SSL_library_init(); -+ websocket->fd = socket(servinfo->ai_family, servinfo->ai_socktype, servinfo->ai_protocol); -+ if(websocket->fd < 0) { -+ freeaddrinfo(servinfo); -+ goto fail; -+ } - -- websocket->sslctx = SSL_CTX_new(SSLv23_client_method()); -- if(websocket->sslctx == NULL) { -- ERR_print_errors_fp(stderr); -- return -1; -- } -+ if(connect(websocket->fd, servinfo->ai_addr, servinfo->ai_addrlen) != 0 ) { -+ freeaddrinfo(servinfo); -+ websocket->state = WEBSOCKET_STATE_CLOSED; -+ if(websocket->retry > 0) { -+ usleep(websocket->retry * 1000); -+ cwebsocket_client_connect(websocket); -+ } -+ goto fail; -+ } -+ freeaddrinfo(servinfo); - -- websocket->ssl = SSL_new(websocket->sslctx); -- if(websocket->ssl == NULL) { -- ERR_print_errors_fp(stderr); -- return -1; -- } -+ int optval = 1; -+ if(setsockopt(websocket->fd, SOL_SOCKET, SO_KEEPALIVE, &optval, sizeof optval) == -1) { -+ goto fail; -+ } -+ struct timeval tv; -+ tv.tv_sec = 1; /* 1 second Timeout */ -+ tv.tv_usec = 0; - -- if(!SSL_set_fd(websocket->ssl, websocket->fd)) { -- ERR_print_errors_fp(stderr); -- return -1; -- } -+ if(setsockopt(websocket->fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(struct timeval)) == -1) { -+ goto fail; -+ } - -- if(SSL_connect(websocket->ssl) != 1) { -- ERR_print_errors_fp(stderr); -- return -1; -- } -+ if(websocket->flags & WEBSOCKET_FLAG_PROXY) { -+ /* SSL Off / Proxy On -+ Execute CONNECT command after connecting to proxy server. -+ */ -+ char proxy_connect[CWS_HANDSHAKE_BUFFER_MAX]; -+ -+ snprintf(proxy_connect, CWS_HANDSHAKE_BUFFER_MAX, -+ "CONNECT %s:%s HTTP/1.1\r\n" -+ "Host: %s\r\n" -+ , hostname, port, hostname); -+ strncat(proxy_connect, "\r\n", (CWS_HANDSHAKE_BUFFER_MAX - strlen(proxy_connect))); -+ if(write(websocket->fd, proxy_connect, strlen(proxy_connect)) == -1) { -+ WS_DEBUG("proxy_client_write: NG\n"); -+ goto fail; -+ } -+ if(cwebsocket_client_read_handshake(websocket, seckey, websocket->flags) == -1) { -+ WS_DEBUG("proxy_client_read_handshake: %s\n", seckey); -+ goto fail; -+ } -+ } - } --#endif - - #ifdef ENABLE_THREADS - pthread_mutex_lock(&websocket->lock); -@@ -284,17 +455,16 @@ int cwebsocket_client_connect(cwebsocket_client *websocket) { - #endif - - if(cwebsocket_client_write(websocket, handshake, strlen(handshake)) == -1) { -- syslog(LOG_ERR, "cwebsocket_client_connect: %s", strerror(errno)); -- cwebsocket_client_onerror(websocket, strerror(errno)); -- return -1; -+ WS_DEBUG("client_connect: NG\n"); -+ goto fail; - } - -- if(cwebsocket_client_read_handshake(websocket, seckey) == -1) { -- syslog(LOG_ERR, "cwebsocket_client_connect: %s", strerror(errno)); -- cwebsocket_client_onerror(websocket, strerror(errno)); -- return -1; -+ if(cwebsocket_client_read_handshake(websocket, seckey, 0) == -1) { -+ WS_DEBUG("client_connect: %s\n", seckey); -+ goto fail; - } - -+ free(seckey); - #ifdef ENABLE_THREADS - pthread_mutex_lock(&websocket->lock); - websocket->state = WEBSOCKET_STATE_OPEN; -@@ -306,11 +476,15 @@ int cwebsocket_client_connect(cwebsocket_client *websocket) { - cwebsocket_client_onopen(websocket); - - return 0; -+fail: -+ free(seckey); -+ cwebsocket_client_close(websocket, 1009, "connect failed"); -+ return -1; - } - - int cwebsocket_client_handshake_handler(cwebsocket_client *websocket, const char *handshake_response, char *seckey) { - uint8_t flags = 0; -- syslog(LOG_DEBUG, "cwebsocket_client_handshake_handler: handshake response: \n%s\n", handshake_response); -+ WS_DEBUG("client_handshake_handler: handshake response: \n%s\n", handshake_response); - char *ptr = NULL, *token = NULL; - for(token = strtok((char *)handshake_response, "\r\n"); token != NULL; token = strtok(NULL, "\r\n")) { - if(*token == 'H' && *(token+1) == 'T' && *(token+2) == 'T' && *(token+3) == 'P') { -@@ -324,20 +498,21 @@ int cwebsocket_client_handshake_handler(cwebsocket_client *websocket, const char - } else { - ptr = strchr(token, ' '); - if(ptr == NULL) { -- syslog(LOG_ERR, "cwebsocket_client_handshake_handler: invalid HTTP header sent: %s", token); -+ WS_DEBUG("client_handshake_handler: invalid HTTP header sent: %s\n", token); - cwebsocket_client_onerror(websocket, "invalid HTTP header sent"); - return -1; - } - *ptr = '\0'; - if(strcasecmp(token, "Upgrade:") == 0) { -- if(strcasecmp(ptr+1, "websocket") != 0) { -+ -+ if(strncasecmp(ptr+1, "websocket", strlen("websocket") -1) != 0) { - cwebsocket_client_onerror(websocket, "cwebsocket_client_handshake_handler: invalid HTTP upgrade header"); - return -1; - } - flags |= CWS_HANDSHAKE_HAS_UPGRADE; - } - if(strcasecmp(token, "Connection:") == 0) { -- if(strcasecmp(ptr+1, "upgrade") != 0) { -+ if(strncasecmp(ptr+1, "upgrade", strlen("upgrade") -1) != 0) { - cwebsocket_client_onerror(websocket, "cwebsocket_client_handshake_handler: invalid HTTP connection header"); - return -1; - } -@@ -346,27 +521,24 @@ int cwebsocket_client_handshake_handler(cwebsocket_client *websocket, const char - if(strcasecmp(token, "Sec-WebSocket-Protocol:") == 0) { - int i; - for(i=0; isubprotocol_len; i++) { -- if(strcasecmp(ptr+1, websocket->subprotocols[i]->name) == 0) { -+ if(strncasecmp(ptr+1, websocket->subprotocols[i]->name, strlen(websocket->subprotocols[i]->name) -1) == 0) { - websocket->subprotocol = websocket->subprotocols[i]; -- syslog(LOG_DEBUG, "cwebsocket_client_handshake_handler: setting subprotocol to %s", websocket->subprotocol->name); -+ WS_DEBUG("client_handshake_handler: setting subprotocol to %s\n", websocket->subprotocol->name); - } - } - } - if(strcasecmp(token, "Sec-WebSocket-Accept:") == 0) { - char* response = cwebsocket_create_key_challenge_response(seckey); -- if(strcmp(ptr+1, response) != 0) { -- free(seckey); -+ if(strncmp(ptr+1, response, strlen(response) -1) != 0) { - if(websocket->subprotocol->onerror != NULL) { - char errmsg[255]; - sprintf(errmsg, "cwebsocket_client_handshake_handler: Sec-WebSocket-Accept header does not match computed sha1/base64 response. expected=%s, actual=%s", response, ptr+1); - cwebsocket_client_onerror(websocket, errmsg); -- free(response); -- return -1; - } -+ free(response); - return -1; - } - free(response); -- free(seckey); - flags |= CWS_HANDSHAKE_HAS_ACCEPT; - } - } -@@ -377,11 +549,11 @@ int cwebsocket_client_handshake_handler(cwebsocket_client *websocket, const char - cwebsocket_client_close(websocket, 1002, "invalid websocket HTTP headers"); - return -1; - } -- syslog(LOG_DEBUG, "cwebsocket_client_handshake_handler: handshake successful"); -+ WS_DEBUG("client_handshake_handler: handshake successful\n"); - return 0; - } - --int cwebsocket_client_read_handshake(cwebsocket_client *websocket, char *seckey) { -+int cwebsocket_client_read_handshake(cwebsocket_client *websocket, char *seckey, int flags) { - - int byte, tmplen = 0; - uint32_t bytes_read = 0; -@@ -394,12 +566,11 @@ int cwebsocket_client_read_handshake(cwebsocket_client *websocket, char *seckey) - - if(byte == 0) return -1; - if(byte == -1) { -- syslog(LOG_ERR, "cwebsocket_client_read_handshake: %s", strerror(errno)); -- cwebsocket_client_onerror(websocket, strerror(errno)); -+ WS_DEBUG("client_read_handshake: %s", strerror(errno)); - return -1; - } - if(bytes_read == CWS_HANDSHAKE_BUFFER_MAX) { -- syslog(LOG_ERR, "cwebsocket_client_read_handshake: handshake response too large. CWS_HANDSHAKE_BUFFER_MAX = %i bytes.", CWS_HANDSHAKE_BUFFER_MAX); -+ WS_DEBUG("client_read_handshake: handshake response too large. CWS_HANDSHAKE_BUFFER_MAX = %i bytes.", CWS_HANDSHAKE_BUFFER_MAX); - cwebsocket_client_onerror(websocket, "handshake response too large"); - return -1; - } -@@ -414,22 +585,62 @@ int cwebsocket_client_read_handshake(cwebsocket_client *websocket, char *seckey) - memcpy(buf, data, tmplen); - buf[tmplen+1] = '\0'; - -- return cwebsocket_client_handshake_handler(websocket, buf, seckey); -+ if(flags & WEBSOCKET_FLAG_PROXY) { -+ return cwebsocket_proxy_client_handshake_handler(websocket, buf); -+ } else { -+ return cwebsocket_client_handshake_handler(websocket, buf, seckey); -+ } -+} -+ -+int cwebsocket_proxy_client_handshake_handler(cwebsocket_client *websocket, const char *handshake_response) { -+ uint8_t flags = 0; -+ WS_DEBUG("proxy_client_handshake_handler: handshake response: \n%s\n", handshake_response); -+ char *ptr = NULL, *token = NULL; -+ -+ /* -+ The response code from the proxy server allows only 200. -+ */ -+ for(token = strtok((char *)handshake_response, "\r\n"); token != NULL; token = strtok(NULL, "\r\n")) { -+ if(*token == 'H' && *(token+1) == 'T' && *(token+2) == 'T' && *(token+3) == 'P') { -+ ptr = strchr(token, ' '); -+ ptr = strchr(ptr+1, ' '); -+ *ptr = '\0'; -+ if((websocket->flags & WEBSOCKET_FLAG_PROXY) && (strcmp(token, "HTTP/1.1 200") == 0 || strcmp(token, "HTTP/1.0 200") == 0)) { -+ WS_DEBUG("client_handshake_handler: proxy handshake successful\n"); -+ return 0; -+ } -+ } else { -+ ptr = strchr(token, ' '); -+ if(ptr == NULL) { -+ WS_DEBUG("client_handshake_handler: invalid HTTP header sent: %s\n", token); -+ cwebsocket_client_onerror(websocket, "invalid HTTP header sent"); -+ return -1; -+ } -+ *ptr = '\0'; -+ } -+ } -+ if(((flags & CWS_HANDSHAKE_HAS_UPGRADE) == 0) || ((flags & CWS_HANDSHAKE_HAS_CONNECTION) == 0) || -+ ((flags & CWS_HANDSHAKE_HAS_ACCEPT) == 0)) { -+ // TODO send http error code (500?) -+ cwebsocket_client_close(websocket, 1002, "invalid websocket HTTP headers"); -+ return -1; -+ } -+ WS_DEBUG("client_handshake_handler: handshake successful\n"); -+ return 0; - } - - void cwebsocket_client_listen(cwebsocket_client *websocket) { - while(websocket->state & WEBSOCKET_STATE_OPEN) { -- syslog(LOG_DEBUG, "cwebsocket_client_listen: calling cwebsocket_client_read_data"); -+ WS_DEBUG("client_listen: calling cwebsocket_client_read_data"); - cwebsocket_client_read_data(websocket); - } -- syslog(LOG_DEBUG, "cwebsocket_client_listen: shutting down"); -+ WS_DEBUG("client_listen: shutting down"); - } - - #ifdef ENABLE_THREADS - void *cwebsocket_client_onmessage_thread(void *ptr) { - cwebsocket_client_thread_args *args = (cwebsocket_client_thread_args *)ptr; - cwebsocket_client_onmessage(args->socket, args->message); -- //free(args->message->payload); - free(args->message); - free(ptr); - return NULL; -@@ -452,28 +663,23 @@ int cwebsocket_client_send_control_frame(cwebsocket_client *websocket, opcode co - control_frame[4] = masking_key[2]; - control_frame[5] = masking_key[3]; - if(code & CLOSE) { -- uint16_t close_code = 1000; - if(payload_len >= 2) { - if(payload_len > 2) { -- char parsed_payload[payload_len]; -- memcpy(parsed_payload, &payload[0], payload_len); -- parsed_payload[payload_len] = '\0'; -- close_code = (control_frame[6] << 8) + control_frame[7]; - int i; - for(i=0; istate & WEBSOCKET_STATE_OPEN)) { - - if(bytes_read >= CWS_DATA_BUFFER_MAX) { -- syslog(LOG_ERR, "cwebsocket_client_read_data: frame too large. RECEIVE_BUFFER_MAX = %i bytes. bytes_read=%i, header_length=%i", -+ WS_DEBUG("client_read_data: frame too large. RECEIVE_BUFFER_MAX = %i bytes. bytes_read=%i, header_length=%i", - CWS_DATA_BUFFER_MAX, bytes_read, header_length); - cwebsocket_client_close(websocket, 1009, "frame too large"); -+ free(data); - return -1; - } - -@@ -532,11 +739,11 @@ int cwebsocket_client_read_data(cwebsocket_client *websocket) { - char *errmsg = "server closed the connection"; - cwebsocket_client_onerror(websocket, errmsg); - cwebsocket_client_close(websocket, 1006, errmsg); -+ free(data); - return -1; - } - if(byte == -1) { -- syslog(LOG_ERR, "cwebsocket_client_read_data: error reading frame: %s", strerror(errno)); -- cwebsocket_client_onerror(websocket, strerror(errno)); -+ free(data); - return -1; - } - bytes_read++; -@@ -553,8 +760,9 @@ int cwebsocket_client_read_data(cwebsocket_client *websocket) { - - if(frame.mask == 1) { - const char *errmsg = "received masked frame from server"; -- syslog(LOG_CRIT, "cwebsocket_client_read_data: %s", errmsg); -+ WS_DEBUG("client_read_data: %s", errmsg); - cwebsocket_client_onerror(websocket, errmsg); -+ free(data); - return -1; - } - -@@ -596,113 +804,137 @@ int cwebsocket_client_read_data(cwebsocket_client *websocket) { - - char *payload = malloc(sizeof(char) * payload_length+1); - if(payload == NULL) { -- perror("out of memory"); -- exit(-1); -+ WS_DEBUG("client_read_data: payload out of memory"); -+ cwebsocket_client_close(websocket, 1009, "out of memory"); -+ free(data); -+ return -1; - } - memcpy(payload, &data[header_length], payload_length); - payload[payload_length] = '\0'; - free(data); -+ data = NULL; - - size_t utf8_code_points = 0; - if(utf8_count_code_points((uint8_t *)payload, &utf8_code_points)) { -- syslog(LOG_ERR, "cwebsocket_client_read_data: received %lld byte malformed utf8 text payload: %s", payload_length, payload); -+ WS_DEBUG("client_read_data: received %lld byte malformed utf8 text payload: %s", payload_length, payload); - cwebsocket_client_onerror(websocket, "received malformed utf8 payload"); -+ free(payload); - return -1; - } - -- syslog(LOG_DEBUG, "cwebsocket_client_read_data: received %lld byte text payload: %s", payload_length, payload); -+ WS_DEBUG("client_read_data: received %lld byte text payload: %s", payload_length, payload); - - if(websocket->subprotocol != NULL && websocket->subprotocol->onmessage != NULL) { - - #ifdef ENABLE_THREADS -- cwebsocket_message *message = malloc(sizeof(cwebsocket_message)); -+ cwebsocket_dsp_message *message = malloc(sizeof(cwebsocket_dsp_message)); - if(message == NULL) { -- perror("out of memory"); -- exit(-1); -+ WS_DEBUG("client_read_data: text message out of memory"); -+ cwebsocket_client_close(websocket, 1009, "out of memory"); -+ free(payload); -+ return -1; - } -- memset(message, 0, sizeof(cwebsocket_message)); -+ memset(message, 0, sizeof(cwebsocket_dsp_message)); - message->opcode = frame.opcode; -- message->payload_len = frame.payload_len; -+ message->payload_len = payload_length; - message->payload = payload; - - cwebsocket_client_thread_args *args = malloc(sizeof(cwebsocket_client_thread_args)); - if(args == NULL) { -- perror("out of memory"); -- exit(-1); -+ WS_DEBUG ("client_read_data: text args out of memory"); -+ cwebsocket_client_close(websocket, 1009, "out of memory"); -+ free(payload); -+ return -1; - } - memset(args, 0, sizeof(cwebsocket_client_thread_args)); - args->socket = websocket; - args->message = message; - - if(pthread_create(&websocket->thread, NULL, cwebsocket_client_onmessage_thread, (void *)args) == -1) { -- syslog(LOG_ERR, "cwebsocket_client_read_data: %s", strerror(errno)); -- cwebsocket_client_onerror(websocket, strerror(errno)); -- return -1; -+ free(payload); -+ free(message); -+ free(args); -+ return -1; - } -+ free(payload); - return bytes_read; - #else -- cwebsocket_message message = {0}; -+ cwebsocket_dsp_message message = {0}; - message.opcode = frame.opcode; -- message.payload_len = frame.payload_len; -+ message.payload_len = payload_length; - message.payload = payload; -- cwebsocket_client_onmessage(websocket, &message); -- //free(payload); -- return bytes_read; -+ cwebsocket_client_onmessage(websocket, &message); -+ free(payload); -+ return bytes_read; - #endif - } - -- syslog(LOG_WARNING, "cwebsocket_client_read_data: onmessage callback undefined"); -+ WS_DEBUG("client_read_data: onmessage callback undefined\n"); -+ free(payload); - return bytes_read; - } - else if(frame.fin && frame.opcode == BINARY_FRAME) { - -- syslog(LOG_DEBUG, "cwebsocket_client_read_data: received BINARY payload. bytes=%lld", payload_length); -+ WS_DEBUG("client_read_data: received BINARY payload. bytes=%lld\n", payload_length); - - char *payload = malloc(sizeof(char) * payload_length); - if(payload == NULL) { - perror("out of memory"); -+ free(data); - exit(-1); - } - memcpy(payload, &data[header_length], payload_length); - free(data); -+ data = NULL; - - if(websocket->subprotocol->onmessage != NULL) { - - #ifdef ENABLE_THREADS -- cwebsocket_message *message = malloc(sizeof(cwebsocket_message)); -+ cwebsocket_dsp_message *message = malloc(sizeof(cwebsocket_dsp_message)); - if(message == NULL) { -- perror("out of memory"); -- exit(-1); -+ WS_DEBUG("client_read_data: binary message out of memory"); -+ cwebsocket_client_close(websocket, 1009, "out of memory"); -+ free(payload); -+ return -1; - } - message->opcode = frame.opcode; -- message->payload_len = frame.payload_len; -+ message->payload_len = payload_length; - message->payload = payload; - - cwebsocket_client_thread_args *args = malloc(sizeof(cwebsocket_client_thread_args)); -+ if(args == NULL) { -+ WS_DEBUG("client_read_data: binary args out of memory"); -+ cwebsocket_client_close(websocket, 1009, "out of memory"); -+ return -1; -+ } - args->socket = websocket; - args->message = message; - - if(pthread_create(&websocket->thread, NULL, cwebsocket_client_onmessage_thread, (void *)args) == -1) { -- syslog(LOG_ERR, "cwebsocket_client_read_data: %s", strerror(errno)); -- cwebsocket_client_onerror(websocket, strerror(errno)); -+ free(payload); -+ free(message); -+ free(args); - return -1; - } -+ free(payload); - return bytes_read; - #else -- cwebsocket_message message; -+ cwebsocket_dsp_message message; - message.opcode = frame.opcode; -- message.payload_len = frame.payload_len; -+ message.payload_len = payload_length; - message.payload = payload; -- websocket->subprotocol->onmessage(websocket, &message); -+ cwebsocket_client_onmessage(websocket, &message); - free(payload); - return bytes_read; - #endif - } -- syslog(LOG_WARNING, "cwebsocket_client_read_data: onmessage callback undefined"); -+ WS_DEBUG("client_read_data: onmessage callback undefined"); -+ free(payload); - return bytes_read; - } - else if(frame.opcode == CONTINUATION) { -- syslog(LOG_DEBUG, "cwebsocket_client_read_data: received CONTINUATION opcode"); -+ WS_DEBUG("client_read_data: onmessage callback undefined"); -+ free(data); - return 0; - } - else if(frame.opcode == PING) { -@@ -713,20 +945,22 @@ int cwebsocket_client_read_data(cwebsocket_client *websocket) { - cwebsocket_client_close(websocket, 1002, "control frames must not exceed 125 bytes"); - return -1; - } -- syslog(LOG_DEBUG, "cwebsocket_client_read_data: received PING control frame"); -+ WS_DEBUG("client_read_data: received PING control frame"); - uint8_t payload[payload_length]; - memcpy(payload, &data[header_length], payload_length); - payload[payload_length] = '\0'; - free(data); -- return cwebsocket_client_send_control_frame(websocket, 0x0A, "PONG", payload, payload_length); -+ return cwebsocket_client_send_control_frame(websocket, PONG, "PONG", payload, payload_length); - } - else if(frame.opcode == PONG) { -- syslog(LOG_DEBUG, "cwebsocket_client_read_data: received PONG control frame"); -+ WS_DEBUG("client_read_data: received PONG control frame"); -+ free(data); - return 0; - } - else if(frame.opcode == CLOSE) { - if(frame.payload_len > 125) { - cwebsocket_client_close(websocket, 1002, "control frames must not exceed 125 bytes"); -+ free(data); - return -1; - } - int code = 0; -@@ -739,7 +973,7 @@ int cwebsocket_client_read_data(cwebsocket_client *websocket) { - memcpy(payload, &data[header_length], (payload_length) * sizeof(uint8_t)); - payload[payload_length] = '\0'; - free(data); -- syslog(LOG_DEBUG, "cwebsocket_client_read_data: received CLOSE control frame. payload_length=%lld, code=%i, reason=%s", payload_length, code, payload); -+ WS_DEBUG("client_read_data: received CLOSE control frame. payload_length=%lld, code=%i, reason=%s", payload_length, code, payload); - cwebsocket_client_close(websocket, code, NULL); - return 0; - } -@@ -747,7 +981,7 @@ int cwebsocket_client_read_data(cwebsocket_client *websocket) { - free(data); - char closemsg[50]; - sprintf(closemsg, "received unsupported opcode: %#04x", frame.opcode); -- syslog(LOG_ERR, "cwebsocket_client_read_data: %s", closemsg); -+ WS_DEBUG("client_read_data: %s", closemsg); - cwebsocket_print_frame(&frame); - cwebsocket_client_onerror(websocket, closemsg); - cwebsocket_client_close(websocket, 1002, closemsg); -@@ -756,25 +990,26 @@ int cwebsocket_client_read_data(cwebsocket_client *websocket) { - - void cwebsocket_client_create_masking_key(uint8_t *masking_key) { - uint8_t mask_bit; -- struct timeval tv; -- gettimeofday(&tv, NULL); -- srand(tv.tv_usec * tv.tv_sec); -+ time_t Tick0 = 0; -+ -+ time(&Tick0); -+ srand(Tick0); - mask_bit = rand(); - memcpy(masking_key, &mask_bit, 4); - } - --ssize_t cwebsocket_client_write_data(cwebsocket_client *websocket, const char *data, uint64_t payload_len, opcode code) { -+int cwebsocket_client_write_data(cwebsocket_client *websocket, const char *data, uint64_t payload_len, opcode code) { - - if((websocket->state & WEBSOCKET_STATE_OPEN) == 0) { -- syslog(LOG_DEBUG, "cwebsocket_client_write_data: websocket closed"); -+ WS_DEBUG("client_write_data: websocket closed"); - cwebsocket_client_onerror(websocket, "websocket closed"); - return -1; - } - -- uint32_t header_length = 6 + (payload_len > 125 ? 2 : 0) + (payload_len > 0xffff ? 8 : 0); -+ uint32_t header_length = 6 + (payload_len > 125 ? 2 : 0) + (payload_len > 0xffff ? 6 : 0); - uint8_t masking_key[4]; - uint8_t header[header_length]; -- ssize_t bytes_written; -+ int bytes_written; - - cwebsocket_client_create_masking_key(masking_key); - header[0] = (code | 0x80); -@@ -808,7 +1043,7 @@ ssize_t cwebsocket_client_write_data(cwebsocket_client *websocket, const char *d - header[13] = masking_key[3]; - } - else { -- syslog(LOG_CRIT, "cwebsocket_client_write_data: frame too large"); -+ WS_DEBUG("client_write_data: frame too large"); - cwebsocket_client_close(websocket, 1009, "frame too large"); - return -1; - } -@@ -827,74 +1062,86 @@ ssize_t cwebsocket_client_write_data(cwebsocket_client *websocket, const char *d - bytes_written = cwebsocket_client_write(websocket, framebuf, frame_length); - - if(bytes_written == -1) { -- syslog(LOG_ERR, "cwebsocket_client_write_data: error: %s", strerror(errno)); -- cwebsocket_client_onerror(websocket, strerror(errno)); -+ WS_DEBUG("client_write_data: error: %d", bytes_written); - return -1; - } - -- syslog(LOG_DEBUG, "cwebsocket_client_write_data: bytes_written=%zu, frame_length=%i, payload_len=%lld, payload=%s\n", -+ WS_DEBUG("client_write_data: bytes_written=%zu, frame_length=%i, payload_len=%lld, payload=%s\n", - bytes_written, frame_length, (long long)payload_len, data); - - return bytes_written; - } - - void cwebsocket_client_close(cwebsocket_client *websocket, uint16_t code, const char *message) { -+ int code32 = 0; - -- if((websocket->state & WEBSOCKET_STATE_OPEN) == 0 || websocket->fd < 1) { -+ if(websocket->state == 0) { - return; - } - --#ifdef ENABLE_THREADS -- pthread_mutex_lock(&websocket->lock); -- websocket->state = WEBSOCKET_STATE_CLOSING; -- pthread_mutex_unlock(&websocket->lock); -+#ifdef ENABLE_SSL -+ if((websocket->state & WEBSOCKET_STATE_OPEN) != 0) { - #else -- websocket->state = WEBSOCKET_STATE_CLOSING; -+ if((websocket->state & WEBSOCKET_STATE_OPEN) != 0 && websocket->fd > 0) { - #endif - -- syslog(LOG_DEBUG, "cwebsocket_client_close: code=%i, message=%s\n", code, message); -+#ifdef ENABLE_THREADS -+ pthread_mutex_lock(&websocket->lock); -+ websocket->state = WEBSOCKET_STATE_CLOSING; -+ pthread_mutex_unlock(&websocket->lock); -+#else -+ websocket->state = WEBSOCKET_STATE_CLOSING; -+#endif - -- int code32 = 0; -- if(code > 0) { -- code = code ? htons(code) : htons(1005); -- int message_len = (message == NULL) ? 0 : strlen(message) + 2; -- uint8_t close_frame[message_len]; -- close_frame[0] = code & 0xFF; -- close_frame[1] = (code >> 8); -- code32 = (close_frame[0] << 8) + (close_frame[1]); -- int i; -- for(i=0; i 0) { -+ code = code ? htons(code) : htons(1005); -+ int message_len = (message == NULL) ? 2 : strlen(message) + 2; -+ uint8_t close_frame[message_len]; -+ close_frame[0] = code & 0xFF; -+ close_frame[1] = (code >> 8); -+ code32 = (close_frame[0] << 8) + (close_frame[1]); -+ int i; -+ for(i=0; issl != NULL) { -- SSL_shutdown(websocket->ssl); -- SSL_free(websocket->ssl); -- } -- if(websocket->sslctx != NULL) { -- SSL_CTX_free(websocket->sslctx); -- } --#else -- if(shutdown(websocket->fd, SHUT_WR) == -1) { -- syslog(LOG_ERR, "cwebsocket_client_close: unable to shutdown websocket: %s", strerror(errno)); -- } -- char buf[1]; -- while(read(websocket->fd, buf, 1) > 0) { buf[0] = '\0'; } -- if(close(websocket->fd) == -1) { -- syslog(LOG_ERR, "cwebsocket_client_close: error closing websocket: %s\n", strerror(errno)); -- cwebsocket_client_onclose(websocket, 1011, strerror(errno)); -+ if(websocket->flags & WEBSOCKET_FLAG_SSL) { -+ WS_DEBUG("ssl_client_close: code=%i, message=%s\n", code, message); -+ -+ mbedtls_ssl_close_notify( &websocket->ssl ); -+ -+ mbedtls_net_free( &websocket->ssl_net_ctx ); -+ mbedtls_x509_crt_free( &websocket->cacert ); -+ mbedtls_ssl_free( &websocket->ssl ); -+ mbedtls_ssl_config_free( &websocket->conf ); -+ mbedtls_ctr_drbg_free( &websocket->ctr_drbg ); -+ mbedtls_entropy_free( &websocket->entropy ); -+ }else { -+#endif -+ if(shutdown(websocket->fd, SHUT_WR) == -1) { -+ WS_DEBUG("cwebsocket_client_close: unable to shutdown websocket: %s", strerror(errno)); -+ } -+ char buf[1]; -+ while(read(websocket->fd, buf, 1) > 0) { buf[0] = '\0'; } -+ if(close(websocket->fd) == -1) { -+ WS_DEBUG("cwebsocket_client_close: error closing websocket: %s\n", strerror(errno)); -+ } -+#ifdef ENABLE_SSL - } -- websocket->fd = 0; - #endif -- - cwebsocket_client_onclose(websocket, code32, message); - -+ websocket->fd = 0; -+ - #ifdef ENABLE_THREADS - pthread_mutex_lock(&websocket->lock); - websocket->state = WEBSOCKET_STATE_CLOSED; -@@ -904,7 +1151,6 @@ void cwebsocket_client_close(cwebsocket_client *websocket, uint16_t code, const - websocket->state = WEBSOCKET_STATE_CLOSED; - #endif - -- syslog(LOG_DEBUG, "cwebsocket_client_close: websocket closed\n"); - websocket->state = 0; - - if(websocket->flags & WEBSOCKET_FLAG_AUTORECONNECT) { -@@ -912,33 +1158,33 @@ void cwebsocket_client_close(cwebsocket_client *websocket, uint16_t code, const - } - } - --ssize_t inline cwebsocket_client_read(cwebsocket_client *websocket, void *buf, int len) { -+ssize_t cwebsocket_client_read(cwebsocket_client *websocket, void *buf, int len) { - #ifdef ENABLE_SSL - return (websocket->flags & WEBSOCKET_FLAG_SSL) ? -- SSL_read(websocket->ssl, buf, len) : -+ mbedtls_ssl_read(&websocket->ssl, buf, len ) : - read(websocket->fd, buf, len); - #else - return read(websocket->fd, buf, len); - #endif - } - --ssize_t inline cwebsocket_client_write(cwebsocket_client *websocket, void *buf, int len) { -+ssize_t cwebsocket_client_write(cwebsocket_client *websocket, void *buf, int len) { - #ifdef ENABLE_THREADS - ssize_t bytes_written; - pthread_mutex_lock(&websocket->write_lock); -- #ifdef USESSL -- bytes_written = (websocket->flags & WEBSOCKET_FLAG_SSL) ? -- SSL_write(websocket->ssl, buf, len) : -- write(websocket->fd, buf, len); -- #else -- bytes_written = write(websocket->fd, buf, len); -- #endif -+#ifdef ENABLE_SSL -+ bytes_written = (websocket->flags & WEBSOCKET_FLAG_SSL) ? -+ mbedtls_ssl_write(&websocket->ssl, buf, len ) : -+ write(websocket->fd, buf, len); -+#else -+ bytes_written = write(websocket->fd, buf, len); -+#endif - pthread_mutex_unlock(&websocket->write_lock); - return bytes_written; - #else - #ifdef ENABLE_SSL - return (websocket->flags & WEBSOCKET_FLAG_SSL) ? -- SSL_write(websocket->ssl, buf, len) : -+ mbedtls_ssl_write(&websocket->ssl, buf, len) : - write(websocket->fd, buf, len); - #else - return write(websocket->fd, buf, len); -@@ -952,20 +1198,41 @@ void cwebsocket_client_onopen(cwebsocket_client *websocket) { - } - } - --void cwebsocket_client_onmessage(cwebsocket_client *websocket, cwebsocket_message *message) { -+void cwebsocket_client_onmessage(cwebsocket_client *websocket, cwebsocket_dsp_message *message) { - if(websocket->subprotocol != NULL && websocket->subprotocol->onmessage != NULL) { -- websocket->subprotocol->onmessage(websocket, message); -+ uint64_t len; -+ websocket->message.opcode = message->opcode; -+ -+ for (len = 0; len < message->payload_len; len += MAX_CHUNK_SIZE){ -+ if (len + MAX_CHUNK_SIZE > message->payload_len){ -+ websocket->message.chunk_len = (message->payload_len - len); -+ memcpy(websocket->message.payload, &message->payload[len], (message->payload_len - len)); -+ websocket->message.payload[(message->payload_len - len)] = '\0'; -+ } else { -+ websocket->message.chunk_len = MAX_CHUNK_SIZE; -+ memcpy(websocket->message.payload, &message->payload[len], MAX_CHUNK_SIZE); -+ websocket->message.payload[MAX_CHUNK_SIZE] = '\0'; -+ } -+ websocket->message.chunk_pos = len; -+ websocket->message.payload_len = message->payload_len; -+ websocket->subprotocol->onmessage(websocket); -+ } - } - } - - void cwebsocket_client_onclose(cwebsocket_client *websocket, int code, const char *message) { - if(websocket->subprotocol != NULL && websocket->subprotocol->onclose != NULL) { -- websocket->subprotocol->onclose(websocket, code, message); -+ strncpy(websocket->message.payload, message, MAX_CHUNK_SIZE); -+ websocket->code = code; -+ websocket->message.payload_len = strlen(message); -+ websocket->subprotocol->onclose(websocket); - } - } - - void cwebsocket_client_onerror(cwebsocket_client *websocket, const char *error) { - if(websocket->subprotocol != NULL && websocket->subprotocol->onerror != NULL) { -- websocket->subprotocol->onerror(websocket, error); -+ strncpy(websocket->message.payload, error, MAX_CHUNK_SIZE); -+ websocket->message.payload_len = strlen(error); -+ websocket->subprotocol->onerror(websocket); - } - } -diff --git a/cwebsocket/src/cwebsocket/client.h b/cwebsocket/src/cwebsocket/client.h -index 0c4d57c..d11dc0b 100755 ---- a/cwebsocket/src/cwebsocket/client.h -+++ b/cwebsocket/src/cwebsocket/client.h -@@ -26,65 +26,212 @@ - #define CWEBSOCKET_CLIENT_H - - #include -+#include -+#include - #include --#include --#include --#include -+#include -+#include "sys/socket.h" -+#include "netdb.h" -+#include "arpa/inet.h" - #include "common.h" - -+#ifdef ENABLE_THREADS -+#include "pthread.h" -+#endif -+ -+/** -+ * @file client.h -+ * @brief WebSocket API -+ */ -+ -+/** -+ * @ingroup lteiftop -+ * @defgroup netwebsocket WebSocket -+ * @brief WebSocket interface -+ * @{ -+ */ -+ - #define WEBSOCKET_FLAG_AUTORECONNECT (1 << 1) -+#define WEBSOCKET_FLAG_PROXY (1 << 5) -+ -+#define WEBSOCKET_SUBPROTOCOL_MAX 4 - - #ifdef __cplusplus - extern "C" { - #endif - -+/** -+ * @defgroup websockcomstr Structure for common interface -+ * Data structure for common interface -+ * @{ -+ */ -+ - typedef struct _cwebsocket { - int fd; - int retry; - char *uri; - uint8_t flags; - uint8_t state; -+ char *proxy_addr; -+ char *proxy_port; -+ char **headers; -+ int num_headers; - #ifdef ENABLE_SSL -- SSL_CTX *sslctx; -- SSL *ssl; -+ mbedtls_ssl_context ssl; -+ mbedtls_net_context ssl_net_ctx; -+ mbedtls_ssl_config conf; -+ mbedtls_x509_crt cacert; -+ mbedtls_x509_crt clicert; -+ mbedtls_pk_context pkey; -+ mbedtls_entropy_context entropy; -+ mbedtls_ctr_drbg_context ctr_drbg; - #endif - #ifdef ENABLE_THREADS - pthread_t thread; - pthread_mutex_t lock; - pthread_mutex_t write_lock; - #endif -+ cwebsocket_app_message message; -+ int code; - size_t subprotocol_len; - cwebsocket_subprotocol *subprotocol; -- cwebsocket_subprotocol *subprotocols[]; -+ cwebsocket_subprotocol *subprotocols[WEBSOCKET_SUBPROTOCOL_MAX]; - } cwebsocket_client; - - typedef struct { - cwebsocket_client *socket; -- cwebsocket_message *message; -+ cwebsocket_dsp_message *message; - } cwebsocket_client_thread_args; - - // "public" --void cwebsocket_client_init(cwebsocket_client *websocket, cwebsocket_subprotocol *subprotocols[], int subprotocol_len); -+ -+/** -+ * @brief Initialized the client connection on a websocket -+ * -+ * @param[in] websocket : Data structure for common interface -+ * @param[in] subprotocols : The array information for sub protocol -+ * @param[in] subprotocol_len : Actual size of the subprotocol. -+ * -+ * @retval On success, 0 is returned. On error, -1 is returned. -+ * -+ * @detail Initialized the client connection on a websocket -+ * -+ */ -+int cwebsocket_client_init(cwebsocket_client *websocket, cwebsocket_subprotocol **subprotocols, int subprotocol_len); -+ -+/** -+ * @brief Initialized the ssl information on a websocket -+ * -+ * @param[in] websocket : Data structure for common interface -+ * @param[in] cert_name : Certificate name in file system -+ * @param[in] pers : Personalization data (Device specific identifiers) -+ * (Can be NULL) -+ * -+ * @retval On success, 0 is returned. On error, -1 is returned. -+ * -+ * @detail Initialized the ssl information on a websocket -+ * -+ */ -+int cwebsocket_client_ssl_init(cwebsocket_client *websocket, char *cert_name, char *cli_cert, char *cli_key, char *passphrase); -+ -+/** -+ * @brief Conneted to the websocket server -+ * -+ * @param[in] websocket : Data structure for common interface.(Set the server name to the uri) -+ * -+ * @retval On success, 0 is returned. On error, -1 is returned. -+ * -+ * @detail Conneted to the websocket server -+ * -+ */ - int cwebsocket_client_connect(cwebsocket_client *websocket); -+/** -+ * @brief Read the packet data from the websocket server -+ * -+ * @param[in] websocket : Data structure for common interface. -+ * -+ * @retval On success, Read() shall return the length of the message in bytes. On error, -1 is returned. -+ * On finish, 0 is returne. -+ * -+ * @detail Read the packet data from the websocket server -+ * -+ */ - int cwebsocket_client_read_data(cwebsocket_client *websocket); --ssize_t cwebsocket_client_write_data(cwebsocket_client *websocket, const char *data, uint64_t len, opcode code); --void cwebsocket_client_run(cwebsocket_client *websocket); -+ -+/** -+ * @brief Wrote the packet data to the websocket server -+ * -+ * @param[in] websocket : Data structure for common interface. -+ * -+ * @retval On success, Write() shall return the length of the message in bytes. On error, -1 is returned. -+ * -+ * @detail Wrote the packet data to the websocket server -+ * -+ */ -+int cwebsocket_client_write_data(cwebsocket_client *websocket, const char *data, uint64_t len, opcode code); -+ -+/** -+ * @brief Closed the websocket session to server -+ * -+ * @param[in] websocket : Data structure for common interface. -+ * @param[in] code : Closed code. (Refer to chapter 7.4 of RFC6455.) -+ * @param[in] reason : Closed reason. -+ * -+ * @retval Nothing -+ * -+ * @detail Closed the websocket session to server -+ * -+ */ -+ - void cwebsocket_client_close(cwebsocket_client *websocket, uint16_t code, const char *reason); --void cwebsocket_client_listen(cwebsocket_client *websocket); -+ -+/** -+ * @brief Set the proxy address for websocket -+ * -+ * @param[in] websocket : Data structure for common interface. -+ * @param[in] proxy_addr : Proxy address. -+ * @param[in] proxy_port : Proxy port. -+ * -+ * @retval Nothing -+ * -+ * @detail Set the proxy address for websocket -+ * -+ */ -+void cwebsocket_client_set_proxy(cwebsocket_client *websocket, char *proxy_addr, char *proxy_port); -+ -+/** -+ * @brief Released the proxy features for websocket -+ * -+ * @param[in] websocket : Data structure for common interface. -+ * -+ * @retval Nothing -+ * -+ * @detail Released the proxy address for websocket -+ * -+ */ -+void cwebsocket_client_unset_proxy(cwebsocket_client *websocket); - - // "private" -+void cwebsocket_client_run(cwebsocket_client *websocket); -+void cwebsocket_client_listen(cwebsocket_client *websocket); - void cwebsocket_client_parse_uri(cwebsocket_client *websocket, const char *uri, char *hostname, char *port, char *resource, char *querystring); - int cwebsocket_client_handshake_handler(cwebsocket_client *websocket, const char *handshake_response, char *seckey); --int cwebsocket_client_read_handshake(cwebsocket_client *websocket, char *seckey); -+int cwebsocket_client_read_handshake(cwebsocket_client *websocket, char *seckey, int flags); - int cwebsocket_client_send_control_frame(cwebsocket_client *websocket, opcode opcode, const char *frame_type, uint8_t *payload, int payload_len); - void cwebsocket_client_create_masking_key(uint8_t *masking_key); --ssize_t inline cwebsocket_client_read(cwebsocket_client *websocket, void *buf, int len); --ssize_t inline cwebsocket_client_write(cwebsocket_client *websocket, void *buf, int len); -+int cwebsocket_client_read(cwebsocket_client *websocket, void *buf, int len); -+int cwebsocket_client_write(cwebsocket_client *websocket, void *buf, int len); -+ - void cwebsocket_client_onopen(cwebsocket_client *websocket); --void cwebsocket_client_onmessage(cwebsocket_client *websocket, cwebsocket_message *message); -+void cwebsocket_client_onmessage(cwebsocket_client *websocket, cwebsocket_dsp_message *message); - void cwebsocket_client_onclose(cwebsocket_client *websocket, int code, const char *message); - void cwebsocket_client_onerror(cwebsocket_client *websocket, const char *error); - -+ssize_t cwebsocket_proxy_client_write(int fd, void *buf, int len); -+int cwebsocket_proxy_client_handshake_handler(cwebsocket_client *websocket, const char *handshake_response); -+int cwebsocket_proxy_client_read_handshake(cwebsocket_client *websocket); -+/**@}*/ -+ - #ifdef __cplusplus - } - #endif -diff --git a/cwebsocket/src/cwebsocket/common.c b/cwebsocket/src/cwebsocket/common.c -index 931bb17..e271ae1 100644 ---- a/cwebsocket/src/cwebsocket/common.c -+++ b/cwebsocket/src/cwebsocket/common.c -@@ -23,25 +23,26 @@ - */ - - #include "common.h" -+#include "mbedtls/base64.h" -+#include "mbedtls/sha1.h" -+ - - char* cwebsocket_base64_encode(const unsigned char *input, int length) { -- BIO *bmem, *b64; -- BUF_MEM *bptr; -- b64 = BIO_new(BIO_f_base64()); -- bmem = BIO_new(BIO_s_mem()); -- b64 = BIO_push(b64, bmem); -- BIO_write(b64, input, length); -- BIO_flush(b64); -- BIO_get_mem_ptr(b64, &bptr); -- char *buff = (char *)malloc(bptr->length); -- memcpy(buff, bptr->data, bptr->length-1); -- buff[bptr->length-1] = '\0'; -- BIO_free_all(b64); -+ -+ unsigned char buffer[128]; -+ size_t olen; -+ -+ mbedtls_base64_encode(buffer, sizeof( buffer ), &olen, input, length ); -+ -+ char *buff = (char *)malloc(olen); -+ memcpy(buff, buffer, olen-1); -+ buff[olen-1] = '\0'; -+ - return buff; - } - - void cwebsocket_print_frame(cwebsocket_frame *frame) { -- syslog(LOG_DEBUG, "cwebsocket_print_frame: fin=%i, rsv1=%i, rsv2=%i, rsv3=%i, opcode=%#04x, mask=%i, payload_len=%lld\n", -+ WS_DEBUG("print_frame: fin=%i, rsv1=%i, rsv2=%i, rsv3=%i, opcode=%#04x, mask=%i, payload_len=%lld\n", - frame->fin, frame->rsv1, frame->rsv2, frame->rsv3, frame->opcode, frame->mask, frame->payload_len); - } - -@@ -53,6 +54,6 @@ char* cwebsocket_create_key_challenge_response(const char *seckey) { - memcpy(sha1buf, seckey, seckey_len); - memcpy(&sha1buf[seckey_len], GUID, 36); - unsigned char sha1_bytes[20]; -- SHA1((const unsigned char *)sha1buf, total_len, sha1_bytes); -+ mbedtls_sha1((const unsigned char *)sha1buf, total_len, sha1_bytes); - return cwebsocket_base64_encode((const unsigned char *)sha1_bytes, sizeof(sha1_bytes)); - } -diff --git a/cwebsocket/src/cwebsocket/common.h b/cwebsocket/src/cwebsocket/common.h -index d6d28c3..faeb8ff 100644 ---- a/cwebsocket/src/cwebsocket/common.h -+++ b/cwebsocket/src/cwebsocket/common.h -@@ -28,31 +28,36 @@ - #include - #include - #include --#include - #include --#include --#include --#include --#include --#include --#include --#include --#include --#include --#include --#include --#include --#include -+ - #include "utf8.h" - -+#include "sys/socket.h" -+ - #ifdef HAVE_CONFIG_H - #include "../../config.h" - #endif - -+//#define ENABLE_WEBSOCKET_DEBUG -+ -+#ifdef ENABLE_WEBSOCKET_DEBUG -+#define WS_DEBUG(...) printf(__VA_ARGS__) -+#else -+#define WS_DEBUG(...) -+#endif -+ -+//#define ENABLE_SSL -+ - #ifdef ENABLE_SSL -- #include -- #include -- #include -+#include "mbedtls/config.h" -+#include "mbedtls/ssl.h" -+#include "mbedtls/net.h" -+#include "mbedtls/entropy.h" -+#include "mbedtls/ctr_drbg.h" -+#include "mbedtls/error.h" -+#if defined(MBEDTLS_SSL_CACHE_C) -+#include "mbedtls/ssl_cache.h" -+#endif - #endif - - #if defined(__linux__) -@@ -72,11 +77,11 @@ - (char)(((p & ((uint64_t)0xff << 48)) >> 48) & 0xff), (char)(((p & ((uint64_t)0xff << 56)) >> 56) & 0xff) } - - #ifndef CWS_HANDSHAKE_BUFFER_MAX -- #define CWS_HANDSHAKE_BUFFER_MAX 256 // bytes -+ #define CWS_HANDSHAKE_BUFFER_MAX 1024 // bytes - #endif - - #ifndef CWS_DATA_BUFFER_MAX -- #define CWS_DATA_BUFFER_MAX 65543 // bytes -+ #define CWS_DATA_BUFFER_MAX 4096 // bytes - #endif - - #ifndef CWS_STACK_SIZE_MIN -@@ -103,10 +108,9 @@ - extern "C" { - #endif - --typedef enum { -- TRUE, -- FALSE --} bool; -+#define MAX_CHUNK_SIZE 256 -+ -+typedef int ssize_t; - - typedef enum { - CONTINUATION = 0x00, -@@ -132,20 +136,30 @@ typedef struct { - uint32_t opcode; - uint64_t payload_len; - char *payload; --} cwebsocket_message; -+} cwebsocket_dsp_message; -+ -+typedef struct { -+ uint32_t opcode; -+ uint64_t payload_len; -+ uint64_t chunk_len; -+ uint64_t chunk_pos; -+ char payload[MAX_CHUNK_SIZE + 1]; -+} cwebsocket_app_message; - - typedef struct { - char *name; - void (*onopen)(void *arg); -- void (*onmessage)(void *arg, cwebsocket_message *message); -- void (*onclose)(void *arg, int code, const char *message); -- void (*onerror)(void *arg, const char *error); -+ void (*onmessage)(void *arg); -+ void (*onclose)(void *arg); -+ void (*onerror)(void *arg); - } cwebsocket_subprotocol; - - char* cwebsocket_create_key_challenge_response(const char *seckey); - char* cwebsocket_base64_encode(const unsigned char *input, int length); - void cwebsocket_print_frame(cwebsocket_frame *frame); - -+void ws_thread_new( const char *pcName, void( *pxThread )( void *pvParameters ), void *pvArg, int iStackSize, int iPriority); -+ - #ifdef __cplusplus - } - #endif --- -2.37.1 - diff --git a/netutils/cwebsocket/0002-Revert-dsp_message-and-app_message-to-original.patch b/netutils/cwebsocket/0002-Revert-dsp_message-and-app_message-to-original.patch deleted file mode 100644 index 4856b16a1..000000000 --- a/netutils/cwebsocket/0002-Revert-dsp_message-and-app_message-to-original.patch +++ /dev/null @@ -1,186 +0,0 @@ -From 73f37c25e822864d9a07d1c61c0372a3b432e524 Mon Sep 17 00:00:00 2001 -From: SPRESENSE <41312067+SPRESENSE@users.noreply.github.com> -Date: Fri, 1 May 2020 14:10:35 +0900 -Subject: [PATCH 2/2] Revert dsp_message and app_message to original - ---- - cwebsocket/src/cwebsocket/client.c | 39 +++++++----------------------- - cwebsocket/src/cwebsocket/client.h | 5 ++-- - cwebsocket/src/cwebsocket/common.h | 20 +++------------ - 3 files changed, 15 insertions(+), 49 deletions(-) - -diff --git a/cwebsocket/src/cwebsocket/client.c b/cwebsocket/src/cwebsocket/client.c -index 50747f0..082b451 100755 ---- a/cwebsocket/src/cwebsocket/client.c -+++ b/cwebsocket/src/cwebsocket/client.c -@@ -827,14 +827,14 @@ int cwebsocket_client_read_data(cwebsocket_client *websocket) { - if(websocket->subprotocol != NULL && websocket->subprotocol->onmessage != NULL) { - - #ifdef ENABLE_THREADS -- cwebsocket_dsp_message *message = malloc(sizeof(cwebsocket_dsp_message)); -+ cwebsocket_message *message = malloc(sizeof(cwebsocket_message)); - if(message == NULL) { - WS_DEBUG("client_read_data: text message out of memory"); - cwebsocket_client_close(websocket, 1009, "out of memory"); - free(payload); - return -1; - } -- memset(message, 0, sizeof(cwebsocket_dsp_message)); -+ memset(message, 0, sizeof(cwebsocket_message)); - message->opcode = frame.opcode; - message->payload_len = payload_length; - message->payload = payload; -@@ -859,7 +859,7 @@ int cwebsocket_client_read_data(cwebsocket_client *websocket) { - free(payload); - return bytes_read; - #else -- cwebsocket_dsp_message message = {0}; -+ cwebsocket_message message = {0}; - message.opcode = frame.opcode; - message.payload_len = payload_length; - message.payload = payload; -@@ -890,7 +890,7 @@ int cwebsocket_client_read_data(cwebsocket_client *websocket) { - if(websocket->subprotocol->onmessage != NULL) { - - #ifdef ENABLE_THREADS -- cwebsocket_dsp_message *message = malloc(sizeof(cwebsocket_dsp_message)); -+ cwebsocket_message *message = malloc(sizeof(cwebsocket_message)); - if(message == NULL) { - WS_DEBUG("client_read_data: binary message out of memory"); - cwebsocket_client_close(websocket, 1009, "out of memory"); -@@ -919,7 +919,7 @@ int cwebsocket_client_read_data(cwebsocket_client *websocket) { - free(payload); - return bytes_read; - #else -- cwebsocket_dsp_message message; -+ cwebsocket_message message; - message.opcode = frame.opcode; - message.payload_len = payload_length; - message.payload = payload; -@@ -1198,41 +1198,20 @@ void cwebsocket_client_onopen(cwebsocket_client *websocket) { - } - } - --void cwebsocket_client_onmessage(cwebsocket_client *websocket, cwebsocket_dsp_message *message) { -+void cwebsocket_client_onmessage(cwebsocket_client *websocket, cwebsocket_message *message) { - if(websocket->subprotocol != NULL && websocket->subprotocol->onmessage != NULL) { -- uint64_t len; -- websocket->message.opcode = message->opcode; -- -- for (len = 0; len < message->payload_len; len += MAX_CHUNK_SIZE){ -- if (len + MAX_CHUNK_SIZE > message->payload_len){ -- websocket->message.chunk_len = (message->payload_len - len); -- memcpy(websocket->message.payload, &message->payload[len], (message->payload_len - len)); -- websocket->message.payload[(message->payload_len - len)] = '\0'; -- } else { -- websocket->message.chunk_len = MAX_CHUNK_SIZE; -- memcpy(websocket->message.payload, &message->payload[len], MAX_CHUNK_SIZE); -- websocket->message.payload[MAX_CHUNK_SIZE] = '\0'; -- } -- websocket->message.chunk_pos = len; -- websocket->message.payload_len = message->payload_len; -- websocket->subprotocol->onmessage(websocket); -- } -+ websocket->subprotocol->onmessage(websocket, message); - } - } - - void cwebsocket_client_onclose(cwebsocket_client *websocket, int code, const char *message) { - if(websocket->subprotocol != NULL && websocket->subprotocol->onclose != NULL) { -- strncpy(websocket->message.payload, message, MAX_CHUNK_SIZE); -- websocket->code = code; -- websocket->message.payload_len = strlen(message); -- websocket->subprotocol->onclose(websocket); -+ websocket->subprotocol->onclose(websocket, code, message); - } - } - - void cwebsocket_client_onerror(cwebsocket_client *websocket, const char *error) { - if(websocket->subprotocol != NULL && websocket->subprotocol->onerror != NULL) { -- strncpy(websocket->message.payload, error, MAX_CHUNK_SIZE); -- websocket->message.payload_len = strlen(error); -- websocket->subprotocol->onerror(websocket); -+ websocket->subprotocol->onerror(websocket, error); - } - } -diff --git a/cwebsocket/src/cwebsocket/client.h b/cwebsocket/src/cwebsocket/client.h -index d11dc0b..1bad957 100755 ---- a/cwebsocket/src/cwebsocket/client.h -+++ b/cwebsocket/src/cwebsocket/client.h -@@ -91,7 +91,6 @@ typedef struct _cwebsocket { - pthread_mutex_t lock; - pthread_mutex_t write_lock; - #endif -- cwebsocket_app_message message; - int code; - size_t subprotocol_len; - cwebsocket_subprotocol *subprotocol; -@@ -100,7 +99,7 @@ typedef struct _cwebsocket { - - typedef struct { - cwebsocket_client *socket; -- cwebsocket_dsp_message *message; -+ cwebsocket_message *message; - } cwebsocket_client_thread_args; - - // "public" -@@ -223,7 +222,7 @@ int cwebsocket_client_read(cwebsocket_client *websocket, void *buf, int len); - int cwebsocket_client_write(cwebsocket_client *websocket, void *buf, int len); - - void cwebsocket_client_onopen(cwebsocket_client *websocket); --void cwebsocket_client_onmessage(cwebsocket_client *websocket, cwebsocket_dsp_message *message); -+void cwebsocket_client_onmessage(cwebsocket_client *websocket, cwebsocket_message *message); - void cwebsocket_client_onclose(cwebsocket_client *websocket, int code, const char *message); - void cwebsocket_client_onerror(cwebsocket_client *websocket, const char *error); - -diff --git a/cwebsocket/src/cwebsocket/common.h b/cwebsocket/src/cwebsocket/common.h -index faeb8ff..1141639 100644 ---- a/cwebsocket/src/cwebsocket/common.h -+++ b/cwebsocket/src/cwebsocket/common.h -@@ -108,8 +108,6 @@ - extern "C" { - #endif - --#define MAX_CHUNK_SIZE 256 -- - typedef int ssize_t; - - typedef enum { -@@ -136,30 +134,20 @@ typedef struct { - uint32_t opcode; - uint64_t payload_len; - char *payload; --} cwebsocket_dsp_message; -- --typedef struct { -- uint32_t opcode; -- uint64_t payload_len; -- uint64_t chunk_len; -- uint64_t chunk_pos; -- char payload[MAX_CHUNK_SIZE + 1]; --} cwebsocket_app_message; -+} cwebsocket_message; - - typedef struct { - char *name; - void (*onopen)(void *arg); -- void (*onmessage)(void *arg); -- void (*onclose)(void *arg); -- void (*onerror)(void *arg); -+ void (*onmessage)(void *arg, cwebsocket_message *message); -+ void (*onclose)(void *arg, int code, const char *message); -+ void (*onerror)(void *arg, const char *error); - } cwebsocket_subprotocol; - - char* cwebsocket_create_key_challenge_response(const char *seckey); - char* cwebsocket_base64_encode(const unsigned char *input, int length); - void cwebsocket_print_frame(cwebsocket_frame *frame); - --void ws_thread_new( const char *pcName, void( *pxThread )( void *pvParameters ), void *pvArg, int iStackSize, int iPriority); -- - #ifdef __cplusplus - } - #endif --- -2.37.1 - diff --git a/netutils/cwebsocket/Kconfig b/netutils/cwebsocket/Kconfig deleted file mode 100644 index d5ec05f66..000000000 --- a/netutils/cwebsocket/Kconfig +++ /dev/null @@ -1,15 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config CWEBSOCKET - bool "WebSocket Client Library" - default n - depends on ALLOW_MIT_COMPONENTS - select LIBC_SCANSET - ---help--- - Enable WebSocket Client Library. - WebSocket Client Library is provided from https://github.com/jeremyhahn/cwebsocket - and licensed under MIT. - diff --git a/netutils/cwebsocket/Make.defs b/netutils/cwebsocket/Make.defs deleted file mode 100644 index c08da360d..000000000 --- a/netutils/cwebsocket/Make.defs +++ /dev/null @@ -1,28 +0,0 @@ -############################################################################ -# apps/netutils/cwebsocket/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_CWEBSOCKET),) -CONFIGURED_APPS += $(APPDIR)/netutils/cwebsocket - -CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/netutils/cwebsocket/cwebsocket -CXXFLAGS += ${INCDIR_PREFIX}$(APPDIR)/netutils/cwebsocket/cwebsocket -endif diff --git a/netutils/cwebsocket/Makefile b/netutils/cwebsocket/Makefile deleted file mode 100644 index c9e6bbcd3..000000000 --- a/netutils/cwebsocket/Makefile +++ /dev/null @@ -1,50 +0,0 @@ -############################################################################ -# apps/netutils/cwebsocket/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -SRC = cwebsocket/src/cwebsocket - -CSRCS += $(SRC)/client.c -CSRCS += $(SRC)/common.c -CSRCS += $(SRC)/utf8.c - -CFLAGS += -DENABLE_SSL -CFLAGS += -Wno-shadow -Wno-strict-prototypes -Wno-unknown-pragmas - -cwebsocket.zip: - $(Q) curl -L https://codeload.github.com/jeremyhahn/cwebsocket/zip/refs/heads/master -o cwebsocket.zip - $(Q) unzip cwebsocket.zip - $(Q) mv cwebsocket-master cwebsocket - $(Q) patch -Np1 < 0001-Porting-the-code-for-NuttX.patch - $(Q) patch -Np1 < 0002-Revert-dsp_message-and-app_message-to-original.patch - -# Download and unpack tarball if no git repo found -ifeq ($(wildcard cwebsocket/.git),) -context:: cwebsocket.zip - -distclean:: - $(call DELDIR, cwebsocket) - $(call DELFILE, cwebsocket.zip) -endif - -include $(APPDIR)/Application.mk diff --git a/netutils/dhcp6c/CMakeLists.txt b/netutils/dhcp6c/CMakeLists.txt deleted file mode 100644 index 63b061cce..000000000 --- a/netutils/dhcp6c/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -# ############################################################################## -# apps/netutils/dhcp6c/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_NETUTILS_DHCP6C) - target_sources(apps PRIVATE dhcp6c.c) -endif() diff --git a/netutils/dhcp6c/Kconfig b/netutils/dhcp6c/Kconfig deleted file mode 100644 index a565f6a1c..000000000 --- a/netutils/dhcp6c/Kconfig +++ /dev/null @@ -1,18 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config NETUTILS_DHCP6C - bool "DHCPv6 client" - default n - depends on NET_IPv6 - depends on NET_UDP && NET_UDP_CHECKSUMS - -if NETUTILS_DHCP6C - -config NETUTILS_DHCP6C_REQUEST_TIMEOUT - int "Default single request timeout in second" - default 6 - -endif diff --git a/netutils/dhcp6c/Make.defs b/netutils/dhcp6c/Make.defs deleted file mode 100644 index 120d94f78..000000000 --- a/netutils/dhcp6c/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/netutils/dhcp6c/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifeq ($(CONFIG_NETUTILS_DHCP6C), y) -CONFIGURED_APPS += $(APPDIR)/netutils/dhcp6c -endif diff --git a/netutils/dhcp6c/Makefile b/netutils/dhcp6c/Makefile deleted file mode 100644 index e7be145f3..000000000 --- a/netutils/dhcp6c/Makefile +++ /dev/null @@ -1,29 +0,0 @@ -############################################################################ -# apps/netutils/dhcp6c/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -ifeq ($(CONFIG_NETUTILS_DHCP6C),y) -CSRCS += dhcp6c.c -endif - -include $(APPDIR)/Application.mk diff --git a/netutils/dhcp6c/dhcp6c.c b/netutils/dhcp6c/dhcp6c.c deleted file mode 100644 index 3989bee0c..000000000 --- a/netutils/dhcp6c/dhcp6c.c +++ /dev/null @@ -1,1963 +0,0 @@ -/**************************************************************************** - * apps/netutils/dhcp6c/dhcp6c.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "netutils/netlib.h" -#include "netutils/dhcp6c.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define DHCPV6_ALL_RELAYS {{{0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02}}} -#define DHCPV6_CLIENT_PORT 546 -#define DHCPV6_SERVER_PORT 547 -#define DHCPV6_DUID_LLADDR 3 -#define DHCPV6_REQ_DELAY 1 - -#define dhcpv6_for_each_option(_o, start, end, otype, olen, odata)\ - for ((_o) = (FAR uint8_t *)(start); (_o) + 4 <= (FAR uint8_t *)(end) &&\ - ((otype) = (_o)[0] << 8 | (_o)[1]) && ((odata) = (FAR void *)&(_o)[4]) &&\ - ((olen) = (_o)[2] << 8 | (_o)[3]) + (odata) <= (FAR uint8_t *)(end); \ - (_o) += 4 + ((_o)[2] << 8 | (_o)[3])) - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -enum dhcpv6_opt_e -{ - DHCPV6_OPT_CLIENTID = 1, - DHCPV6_OPT_SERVERID = 2, - DHCPV6_OPT_IA_NA = 3, - DHCPV6_OPT_IA_ADDR = 5, - DHCPV6_OPT_ORO = 6, - DHCPV6_OPT_PREF = 7, - DHCPV6_OPT_ELAPSED = 8, - DHCPV6_OPT_RELAY_MSG = 9, - DHCPV6_OPT_AUTH = 11, - DHCPV6_OPT_STATUS = 13, - DHCPV6_OPT_RAPID_COMMIT = 14, - DHCPV6_OPT_RECONF_MESSAGE = 19, - DHCPV6_OPT_RECONF_ACCEPT = 20, - DHCPV6_OPT_DNS_SERVERS = 23, - DHCPV6_OPT_DNS_DOMAIN = 24, - DHCPV6_OPT_IA_PD = 25, - DHCPV6_OPT_IA_PREFIX = 26, - DHCPV6_OPT_INFO_REFRESH = 32, - DHCPV6_OPT_FQDN = 39, - DHCPV6_OPT_NTP_SERVER = 56, - DHCPV6_OPT_SIP_SERVER_D = 21, - DHCPV6_OPT_SIP_SERVER_A = 22, -}; - -enum dhcpv6_opt_npt_e -{ - NTP_SRV_ADDR = 1, - NTP_MC_ADDR = 2, - NTP_SRV_FQDN = 3 -}; - -enum dhcpv6_msg_e -{ - DHCPV6_MSG_UNKNOWN = 0, - DHCPV6_MSG_SOLICIT = 1, - DHCPV6_MSG_ADVERT = 2, - DHCPV6_MSG_REQUEST = 3, - DHCPV6_MSG_RENEW = 5, - DHCPV6_MSG_REBIND = 6, - DHCPV6_MSG_REPLY = 7, - DHCPV6_MSG_RELEASE = 8, - DHCPV6_MSG_DECLINE = 9, - DHCPV6_MSG_RECONF = 10, - DHCPV6_MSG_INFO_REQ = 11, - DHCPV6_MSG_MAX -}; - -enum dhcpv6_status_e -{ - DHCPV6_NOADDRSAVAIL = 2, - DHCPV6_NOPREFIXAVAIL = 6 -}; - -enum dhcpv6_mode_e -{ - DHCPV6_UNKNOWN, - DHCPV6_STATELESS, - DHCPV6_STATEFUL -}; - -enum dhcpv6_state_e -{ - STATE_CLIENT_ID, - STATE_SERVER_ID, - STATE_SERVER_CAND, - STATE_ORO, - STATE_DNS, - STATE_SEARCH, - STATE_IA_NA, - STATE_IA_PD, - STATE_CUSTOM_OPTS, - STATE_SNTP_IP, - STATE_SNTP_FQDN, - STATE_SIP_IP, - STATE_SIP_FQDN, - STATE_MAX -}; - -enum dhcp6c_ia_mode_e -{ - IA_MODE_NONE, - IA_MODE_TRY, - IA_MODE_FORCE, -}; - -/* DHCPV6 Protocol Headers */ - -begin_packed_struct struct dhcpv6_header_s -{ - uint8_t msg_type; - uint8_t tr_id[3]; -} end_packed_struct; - -begin_packed_struct struct dhcpv6_ia_hdr_s -{ - uint16_t type; - uint16_t len; - uint32_t iaid; - uint32_t t1; - uint32_t t2; -} end_packed_struct; - -begin_packed_struct struct dhcpv6_ia_addr_s -{ - uint16_t type; - uint16_t len; - struct in6_addr addr; - uint32_t preferred; - uint32_t valid; -} end_packed_struct; - -begin_packed_struct struct dhcpv6_ia_prefix_s -{ - uint16_t type; - uint16_t len; - uint32_t preferred; - uint32_t valid; - uint8_t prefix; - struct in6_addr addr; -} end_packed_struct; - -struct dhcpv6_server_cand_s -{ - bool has_noaddravail; - bool wants_reconfigure; - int16_t preference; - uint8_t duid_len; - uint8_t duid[130]; -}; - -struct dhcp6c_retx_s -{ - bool delay; - uint8_t init_timeo; - uint16_t max_timeo; - char name[8]; - int(*handler_reply)(FAR void *handle, enum dhcpv6_msg_e orig, - FAR const void *opt, FAR const void *end, - uint32_t elapsed); - int(*handler_finish)(FAR void *handle, uint32_t elapsed); -}; - -struct dhcp6c_state_s -{ - pthread_t thread; - bool cancel; - dhcp6c_callback_t callback; - int sockfd; - int urandom_fd; - int ifindex; - time_t t1; - time_t t2; - time_t t3; - bool request_prefix; - enum dhcp6c_ia_mode_e ia_mode; - bool accept_reconfig; - FAR uint8_t *state_data[STATE_MAX]; - size_t state_len[STATE_MAX]; -}; - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -static int dhcp6c_handle_reconfigure(FAR void *handle, - enum dhcpv6_msg_e orig, - FAR const void *opt, - FAR const void *end, - uint32_t elapsed); -static int dhcp6c_handle_advert(FAR void *handle, enum dhcpv6_msg_e orig, - FAR const void *opt, FAR const void *end, - uint32_t elapsed); -static int dhcp6c_commit_advert(FAR void *handle, uint32_t elapsed); -static int dhcp6c_handle_reply(FAR void *handle, enum dhcpv6_msg_e orig, - FAR const void *opt, FAR const void *end, - uint32_t elapsed); -static int dhcp6c_handle_rebind_reply(FAR void *handle, - enum dhcpv6_msg_e orig, - FAR const void *opt, - FAR const void *end, - uint32_t elapsed); - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/* RFC 3315 - 5.5 Timeout and Delay values */ - -static const struct dhcp6c_retx_s g_dhcp6c_retx[DHCPV6_MSG_MAX] = -{ - {false, 1, 120, "", dhcp6c_handle_reconfigure, NULL}, - {true, 1, 120, "SOLICIT", dhcp6c_handle_advert, dhcp6c_commit_advert}, - {0}, - {true, 1, 30, "REQUEST", dhcp6c_handle_reply, NULL}, - {0}, - {false, 10, 600, "RENEW", dhcp6c_handle_reply, NULL}, - {false, 10, 600, "REBIND", dhcp6c_handle_rebind_reply, NULL}, - {0}, - {false, 1, 600, "RELEASE", NULL, NULL}, - {false, 1, 3, "DECLINE", NULL, NULL}, - {0}, - {true, 1, 120, "INFOREQ", dhcp6c_handle_reply, NULL}, -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static uint64_t dhcp6c_get_milli_time(void) -{ - struct timespec t; - - clock_gettime(CLOCK_MONOTONIC, &t); - - return t.tv_sec * MSEC_PER_SEC + t.tv_nsec / USEC_PER_SEC; -} - -static FAR uint8_t *dhcp6c_resize_state(FAR void *handle, - enum dhcpv6_state_e state, - ssize_t len) -{ - FAR struct dhcp6c_state_s *pdhcp6c = (FAR struct dhcp6c_state_s *)handle; - FAR uint8_t *n; - - if (len == 0) - { - return pdhcp6c->state_data[state] + pdhcp6c->state_len[state]; - } - - n = realloc(pdhcp6c->state_data[state], pdhcp6c->state_len[state] + len); - if (n != NULL || pdhcp6c->state_len[state] + len == 0) - { - pdhcp6c->state_data[state] = n; - n += pdhcp6c->state_len[state]; - pdhcp6c->state_len[state] += len; - } - - return n; -} - -static void dhcp6c_clear_state(FAR void *handle, enum dhcpv6_state_e state) -{ - FAR struct dhcp6c_state_s *pdhcp6c = (FAR struct dhcp6c_state_s *)handle; - - pdhcp6c->state_len[state] = 0; -} - -static void dhcp6c_add_state(FAR void *handle, enum dhcpv6_state_e state, - FAR const void *data, size_t len) -{ - FAR uint8_t *n = dhcp6c_resize_state(handle, state, len); - - if (n != NULL) - { - memcpy(n, data, len); - } -} - -static size_t dhcp6c_remove_state(FAR void *handle, - enum dhcpv6_state_e state, - size_t offset, size_t len) -{ - FAR struct dhcp6c_state_s *pdhcp6c = (FAR struct dhcp6c_state_s *)handle; - FAR uint8_t *data = pdhcp6c->state_data[state]; - ssize_t len_after = pdhcp6c->state_len[state] - (offset + len); - - if (len_after < 0) - { - return pdhcp6c->state_len[state]; - } - - memmove(data + offset, data + offset + len, len_after); - - return pdhcp6c->state_len[state] -= len; -} - -static bool dhcp6c_commit_state(FAR void *handle, enum dhcpv6_state_e state, - size_t old_len) -{ - FAR struct dhcp6c_state_s *pdhcp6c = (FAR struct dhcp6c_state_s *)handle; - size_t new_len = pdhcp6c->state_len[state] - old_len; - FAR uint8_t *old_data = pdhcp6c->state_data[state]; - FAR uint8_t *new_data = old_data + old_len; - bool upd = false; - - if (new_len != 0 || old_len != 0) - { - upd = (new_len != old_len) || - (memcmp(old_data, new_data, new_len) != 0); - - memmove(old_data, new_data, new_len); - dhcp6c_resize_state(handle, state, -old_len); - } - - return upd; -} - -static FAR void *dhcp6c_get_state(FAR void *handle, - enum dhcpv6_state_e state, - FAR size_t *len) -{ - FAR struct dhcp6c_state_s *pdhcp6c = (FAR struct dhcp6c_state_s *)handle; - - *len = pdhcp6c->state_len[state]; - return pdhcp6c->state_data[state]; -} - -static void dhcp6c_get_result(FAR void *handle, - FAR struct dhcp6c_state *presult) -{ - FAR struct dhcp6c_state_s *pdhcp6c = (FAR struct dhcp6c_state_s *)handle; - size_t s_len; - FAR uint8_t *s_data; - uint16_t olen; - uint16_t otype; - FAR uint8_t *ite; - FAR uint8_t *odata; - FAR struct dhcpv6_ia_addr_s *addr; - FAR struct dhcpv6_ia_prefix_s *pd; - FAR struct in6_addr *dns; - char addr_str[INET6_ADDRSTRLEN]; - - if (handle == NULL || presult == NULL) - { - return; - } - - s_data = dhcp6c_get_state(handle, STATE_IA_NA, &s_len); - dhcpv6_for_each_option(ite, s_data, s_data + s_len, otype, olen, odata) - { - addr = (FAR void *)(odata - 4); - memcpy(&presult->addr, &addr->addr, sizeof(presult->addr)); - inet_ntop(AF_INET6, &presult->addr, addr_str, sizeof(addr_str)); - ninfo("IA_NA %s for iface %i\n", addr_str, pdhcp6c->ifindex); - } - - s_data = dhcp6c_get_state(handle, STATE_IA_PD, &s_len); - dhcpv6_for_each_option(ite, s_data, s_data + s_len, otype, olen, odata) - { - pd = (FAR void *)(odata - 4); - memcpy(&presult->pd, &pd->addr, sizeof(presult->pd)); - presult->pl = pd->prefix; - netlib_prefix2ipv6netmask(presult->pl, &presult->netmask); - inet_ntop(AF_INET6, &presult->pd, addr_str, sizeof(addr_str)); - ninfo("IA_PD %s for iface %i\n", addr_str, pdhcp6c->ifindex); - inet_ntop(AF_INET6, &presult->netmask, addr_str, sizeof(addr_str)); - ninfo("netmask %s for iface %i\n", addr_str, pdhcp6c->ifindex); - } - - dns = dhcp6c_get_state(handle, STATE_DNS, &s_len); - memcpy(&presult->dns, dns, sizeof(presult->dns)); - inet_ntop(AF_INET6, &presult->dns, addr_str, sizeof(addr_str)); - ninfo("DNS server %s for iface %i\n", addr_str, pdhcp6c->ifindex); - - presult->t1 = pdhcp6c->t1; - presult->t2 = pdhcp6c->t2; - ninfo("T1:%"PRIu32" T2:%"PRIu32" for iface %i\n", presult->t1, presult->t2, - pdhcp6c->ifindex); -} - -static void dhcp6c_switch_process(FAR void *handle, FAR const char *name) -{ - FAR struct dhcp6c_state_s *pdhcp6c = (FAR struct dhcp6c_state_s *)handle; - struct dhcp6c_state result; - - ninfo("Process switch to %s\n", name); - - /* Delete lost prefixes and user opts */ - - dhcp6c_clear_state(handle, STATE_CUSTOM_OPTS); - - if (pdhcp6c->callback != NULL) - { - memset(&result, 0, sizeof(result)); - dhcp6c_get_result(pdhcp6c, &result); - pdhcp6c->callback(&result); - } -} - -static void dhcp6c_remove_addrs(FAR void *handle) -{ - FAR struct dhcp6c_state_s *pdhcp6c = (FAR struct dhcp6c_state_s *)handle; - size_t ia_na_len; - FAR uint8_t *ite; - FAR uint8_t *odata; - FAR uint8_t *ia_na = dhcp6c_get_state(handle, STATE_IA_NA, &ia_na_len); - uint16_t otype; - uint16_t olen; - FAR struct dhcpv6_ia_addr_s *addr; - char addr_str[INET6_ADDRSTRLEN]; - - dhcpv6_for_each_option(ite, ia_na, ia_na + ia_na_len, otype, olen, odata) - { - addr = (FAR void *)(odata - 4); - inet_ntop(AF_INET6, &addr->addr, addr_str, sizeof(addr_str)); - ninfo("removing address %s/128 for iface %i\n", - addr_str, pdhcp6c->ifindex); - } -} - -static void dhcp6c_set_iov(FAR struct iovec *piov, - FAR void *base, size_t len) -{ - piov->iov_base = base; - piov->iov_len = len; -} - -static void dhcp6c_send(FAR void *handle, enum dhcpv6_msg_e type, - uint8_t trid[3], uint32_t ecs) -{ - FAR struct dhcp6c_state_s *pdhcp6c = (FAR struct dhcp6c_state_s *)handle; - char fqdn_buf[256]; - struct - { - uint16_t type; - uint16_t len; - uint8_t flags; - uint8_t data[256]; - } fqdn; - - size_t fqdn_len; - size_t cl_id_len; - FAR void *cl_id; - size_t srv_id_len; - FAR void *srv_id; - size_t ia_pd_len; - FAR void *ia_pd; - struct dhcpv6_ia_hdr_s hdr_ia_pd; - struct dhcpv6_ia_prefix_s pref; - size_t ia_na_len; - FAR void *ia_na; - struct dhcpv6_ia_hdr_s hdr_ia_na; - struct - { - uint16_t type; - uint16_t length; - } reconf_accept; - - uint16_t oro_refresh; - size_t oro_len; - FAR void *oro; - struct - { - uint8_t type; - uint8_t trid[3]; - uint16_t elapsed_type; - uint16_t elapsed_len; - uint16_t elapsed_value; - uint16_t oro_type; - uint16_t oro_len; - } hdr; - - struct iovec iov[11]; - size_t cnt; - struct sockaddr_in6 dest = - { - AF_INET6, htons(DHCPV6_SERVER_PORT), - 0, DHCPV6_ALL_RELAYS, pdhcp6c->ifindex - }; - - struct msghdr msg; - - /* Build FQDN */ - - gethostname(fqdn_buf, sizeof(fqdn_buf)); - fqdn_len = 5 + dn_comp(fqdn_buf, fqdn.data, sizeof(fqdn.data), NULL, NULL); - fqdn.type = htons(DHCPV6_OPT_FQDN); - fqdn.len = htons(fqdn_len - 4); - fqdn.flags = 0; - - /* Build Client ID */ - - cl_id = dhcp6c_get_state(handle, STATE_CLIENT_ID, &cl_id_len); - - /* Build Server ID */ - - srv_id = dhcp6c_get_state(handle, STATE_SERVER_ID, &srv_id_len); - - /* Build IA_PDs */ - - ia_pd = dhcp6c_get_state(handle, STATE_IA_PD, &ia_pd_len); - hdr_ia_pd.type = htons(DHCPV6_OPT_IA_PD); - hdr_ia_pd.len = htons(sizeof(hdr_ia_pd) - 4 + ia_pd_len); - hdr_ia_pd.iaid = 1; - hdr_ia_pd.t1 = 0; - hdr_ia_pd.t2 = 0; - pref.type = htons(DHCPV6_OPT_IA_PREFIX); - pref.len = htons(25); - pref.prefix = pdhcp6c->request_prefix; - - if (ia_pd_len == 0 && pdhcp6c->request_prefix && - (type == DHCPV6_MSG_SOLICIT || type == DHCPV6_MSG_REQUEST)) - { - ia_pd = &pref; - ia_pd_len = sizeof(pref); - } - - /* Build IA_NAs */ - - ia_na = dhcp6c_get_state(handle, STATE_IA_NA, &ia_na_len); - hdr_ia_na.type = htons(DHCPV6_OPT_IA_NA); - hdr_ia_na.len = htons(sizeof(hdr_ia_na) - 4 + ia_na_len); - hdr_ia_na.iaid = 1; - hdr_ia_na.t1 = 0; - hdr_ia_na.t2 = 0; - - /* Reconfigure Accept */ - - reconf_accept.type = htons(DHCPV6_OPT_RECONF_ACCEPT); - reconf_accept.length = 0; - - /* Request Information Refresh */ - - oro_refresh = htons(DHCPV6_OPT_INFO_REFRESH); - - /* Prepare Header */ - - oro = dhcp6c_get_state(handle, STATE_ORO, &oro_len); - hdr.type = type; - hdr.trid[0] = trid[0]; - hdr.trid[1] = trid[1]; - hdr.trid[2] = trid[2]; - hdr.elapsed_type = htons(DHCPV6_OPT_ELAPSED); - hdr.elapsed_len = htons(2); - hdr.elapsed_value = htons((ecs > 0xffff) ? 0xffff : ecs); - hdr.oro_type = htons(DHCPV6_OPT_ORO); - hdr.oro_len = htons(oro_len); - - /* Prepare iov */ - - dhcp6c_set_iov(&iov[0], &hdr, sizeof(hdr)); - dhcp6c_set_iov(&iov[1], oro, oro_len); - dhcp6c_set_iov(&iov[2], &oro_refresh, 0); - dhcp6c_set_iov(&iov[3], cl_id, cl_id_len); - dhcp6c_set_iov(&iov[4], srv_id, srv_id_len); - dhcp6c_set_iov(&iov[5], &reconf_accept, 0); - dhcp6c_set_iov(&iov[6], &fqdn, fqdn_len); - dhcp6c_set_iov(&iov[7], &hdr_ia_na, sizeof(hdr_ia_na)); - dhcp6c_set_iov(&iov[8], ia_na, ia_na_len); - dhcp6c_set_iov(&iov[9], &hdr_ia_pd, sizeof(hdr_ia_pd)); - dhcp6c_set_iov(&iov[10], ia_pd, ia_pd_len); - - cnt = nitems(iov); - if (type == DHCPV6_MSG_INFO_REQ) - { - cnt = 5; - iov[2].iov_len = sizeof(oro_refresh); - hdr.oro_len = htons(oro_len + sizeof(oro_refresh)); - } - else if (!pdhcp6c->request_prefix) - { - cnt = 9; - } - - /* Disable IAs if not used */ - - if (type == DHCPV6_MSG_SOLICIT) - { - iov[5].iov_len = sizeof(reconf_accept); - } - else if (type != DHCPV6_MSG_REQUEST) - { - if (ia_na_len == 0) - { - iov[7].iov_len = 0; - } - - if (ia_pd_len == 0) - { - iov[9].iov_len = 0; - } - } - - if (pdhcp6c->ia_mode == IA_MODE_NONE) - { - iov[7].iov_len = 0; - } - - msg.msg_name = &dest; - msg.msg_namelen = sizeof(dest); - msg.msg_iov = iov; - msg.msg_iovlen = cnt; - msg.msg_control = NULL; - msg.msg_controllen = 0; - msg.msg_flags = 0; - - sendmsg(pdhcp6c->sockfd, &msg, 0); -} - -static int64_t dhcp6c_rand_delay(FAR void *handle, int64_t time) -{ - FAR struct dhcp6c_state_s *pdhcp6c = (FAR struct dhcp6c_state_s *)handle; - int random; - - read(pdhcp6c->urandom_fd, &random, sizeof(random)); - return (time * (random % 1000)) / 10000; -} - -static bool dhcp6c_response_is_valid(FAR void *handle, FAR const void *buf, - ssize_t len, - const uint8_t transaction[3], - enum dhcpv6_msg_e type) -{ - FAR struct dhcp6c_state_s *pdhcp6c = (FAR struct dhcp6c_state_s *)handle; - FAR const struct dhcpv6_header_s *rep = buf; - FAR uint8_t *ite; - FAR uint8_t *end; - FAR uint8_t *odata; - uint16_t otype; - uint16_t olen; - bool clientid_ok = false; - bool serverid_ok = false; - size_t client_id_len; - size_t server_id_len; - FAR void *client_id; - FAR void *server_id; - - if (len < sizeof(*rep) || - memcmp(rep->tr_id, transaction, sizeof(rep->tr_id)) != 0) - { - return false; - } - - if (type == DHCPV6_MSG_SOLICIT) - { - if (rep->msg_type != DHCPV6_MSG_ADVERT && - rep->msg_type != DHCPV6_MSG_REPLY) - { - return false; - } - } - else if (type == DHCPV6_MSG_UNKNOWN) - { - if (!pdhcp6c->accept_reconfig || - rep->msg_type != DHCPV6_MSG_RECONF) - { - return false; - } - } - else if (rep->msg_type != DHCPV6_MSG_REPLY) - { - return false; - } - - end = ((FAR uint8_t *)buf) + len; - client_id = dhcp6c_get_state(handle, STATE_CLIENT_ID, &client_id_len); - server_id = dhcp6c_get_state(handle, STATE_SERVER_ID, &server_id_len); - - dhcpv6_for_each_option(ite, &rep[1], end, otype, olen, odata) - { - if (otype == DHCPV6_OPT_CLIENTID) - { - clientid_ok = (olen + 4u == client_id_len) && - (memcmp((odata - 4), client_id, client_id_len) == 0); - } - else if (otype == DHCPV6_OPT_SERVERID) - { - serverid_ok = (olen + 4u == server_id_len) && - (memcmp((odata - 4), server_id, server_id_len) == 0); - } - } - - return clientid_ok && (serverid_ok || server_id_len == 0); -} - -static int dhcp6c_command(FAR void *handle, enum dhcpv6_msg_e type) -{ - FAR struct dhcp6c_state_s *pdhcp6c = (FAR struct dhcp6c_state_s *)handle; - const int buf_length = 1536; - FAR uint8_t *buf = (FAR uint8_t *)malloc(buf_length); - uint32_t timeout = CONFIG_NETUTILS_DHCP6C_REQUEST_TIMEOUT < 3 ? 3 : - CONFIG_NETUTILS_DHCP6C_REQUEST_TIMEOUT; - FAR const struct dhcp6c_retx_s *retx = &g_dhcp6c_retx[type]; - uint64_t start; - uint64_t round_start; - uint64_t round_end; - uint64_t elapsed; - uint8_t trid[3]; - ssize_t len = -1; - int64_t rto = 0; - - if (buf == NULL) - { - return -1; - } - - if (retx->delay) - { - struct timespec ts; - ts.tv_sec = 0; - ts.tv_nsec = dhcp6c_rand_delay(handle, 10 * DHCPV6_REQ_DELAY); - nanosleep(&ts, NULL); - } - - if (type == DHCPV6_MSG_RELEASE || type == DHCPV6_MSG_DECLINE) - { - timeout = 3; - } - else if (type == DHCPV6_MSG_UNKNOWN) - { - timeout = pdhcp6c->t1; - } - else if (type == DHCPV6_MSG_RENEW) - { - timeout = pdhcp6c->t2 - pdhcp6c->t1; - } - else if (type == DHCPV6_MSG_REBIND) - { - timeout = pdhcp6c->t3 - pdhcp6c->t2; - } - - if (timeout == 0) - { - len = -1; - goto end; - } - - ninfo("Sending %s (timeout %"PRIu32" s)\n", retx->name, timeout); - start = dhcp6c_get_milli_time(); - round_start = start; - - /* Generate transaction ID */ - - read(pdhcp6c->urandom_fd, trid, sizeof(trid)); - - do - { - rto = (rto == 0) ? (retx->init_timeo * MSEC_PER_SEC + - dhcp6c_rand_delay(handle, retx->init_timeo * MSEC_PER_SEC)) : - (2 * rto + dhcp6c_rand_delay(handle, rto)); - - if (rto >= retx->max_timeo * MSEC_PER_SEC) - { - rto = retx->max_timeo * MSEC_PER_SEC + - dhcp6c_rand_delay(handle, retx->max_timeo * MSEC_PER_SEC); - } - - /* Calculate end for this round and elapsed time */ - - round_end = round_start + rto; - elapsed = round_start - start; - - /* Don't wait too long */ - - if (round_end - start > timeout * MSEC_PER_SEC) - { - round_end = timeout * MSEC_PER_SEC + start; - } - - /* Built and send package */ - - if (type != DHCPV6_MSG_UNKNOWN) - { - dhcp6c_send(handle, type, trid, elapsed / 10); - } - - /* Receive rounds */ - - for (; len < 0 && round_start < round_end; - round_start = dhcp6c_get_milli_time()) - { - /* Set timeout for receiving */ - - uint64_t t = round_end - round_start; - struct timeval retime = - { - t / MSEC_PER_SEC, (t % MSEC_PER_SEC) * MSEC_PER_SEC - }; - - /* check for dhcp6c_close */ - - if (pdhcp6c->cancel) - { - len = -1; - goto end; - } - - setsockopt(pdhcp6c->sockfd, SOL_SOCKET, SO_RCVTIMEO, - &retime, sizeof(retime)); - - /* Receive cycle */ - - len = recv(pdhcp6c->sockfd, buf, buf_length, 0); - if (type != DHCPV6_MSG_UNKNOWN) - { - ninfo("%s[type:%d] recv len[%d]\n", __func__, type, len); - } - - if (!dhcp6c_response_is_valid(handle, buf, len, trid, type)) - { - len = -1; - } - - if (len > 0) - { - FAR uint8_t *opt = &buf[4]; - FAR uint8_t *opt_end = opt + len - 4; - - round_start = dhcp6c_get_milli_time(); - elapsed = round_start - start; - ninfo("Got a valid reply after %ums\n", (unsigned)elapsed); - - if (retx->handler_reply != NULL) - { - len = retx->handler_reply(handle, type, opt, - opt_end, elapsed / MSEC_PER_SEC); - } - } - } - - if (retx->handler_finish != NULL) - { - len = retx->handler_finish(handle, elapsed / MSEC_PER_SEC); - } - } - while (len < 0 && elapsed / MSEC_PER_SEC < timeout); - -end: - free(buf); - return len; -} - -static int dhcp6c_poll_reconfigure(FAR void *handle) -{ - int ret = dhcp6c_command(handle, DHCPV6_MSG_UNKNOWN); - if (ret != -1) - { - ret = dhcp6c_command(handle, ret); - } - - return ret; -} - -/* Collect all advertised servers */ - -static int dhcp6c_handle_advert(FAR void *handle, enum dhcpv6_msg_e orig, - FAR const void *opt, FAR const void *end, - uint32_t elapsed) -{ - FAR struct dhcp6c_state_s *pdhcp6c = (FAR struct dhcp6c_state_s *)handle; - uint16_t olen; - uint16_t otype; - FAR uint8_t *ite0; - FAR uint8_t *odata; - struct dhcpv6_server_cand_s cand; - - memset(&cand, 0, sizeof(cand)); - dhcpv6_for_each_option(ite0, opt, end, otype, olen, odata) - { - if (otype == DHCPV6_OPT_SERVERID && olen <= 130) - { - memcpy(cand.duid, odata, olen); - cand.duid_len = olen; - } - else if (otype == DHCPV6_OPT_STATUS && olen >= 2 && !odata[0] - && odata[1] == DHCPV6_NOADDRSAVAIL) - { - if (pdhcp6c->ia_mode == IA_MODE_FORCE) - { - return -1; - } - else - { - cand.has_noaddravail = true; - cand.preference -= 1000; - } - } - else if (otype == DHCPV6_OPT_STATUS && olen >= 2 && !odata[0] - && odata[1] == DHCPV6_NOPREFIXAVAIL) - { - cand.preference -= 2000; - } - else if (otype == DHCPV6_OPT_PREF && olen >= 1 && - cand.preference >= 0) - { - cand.preference = odata[1]; - } - else if (otype == DHCPV6_OPT_RECONF_ACCEPT) - { - cand.wants_reconfigure = true; - } - else if (otype == DHCPV6_OPT_IA_PD && pdhcp6c->request_prefix) - { - FAR struct dhcpv6_ia_hdr_s *h = (FAR void *)odata; - FAR uint8_t *oend = odata + olen; - FAR uint8_t *ite1; - FAR uint8_t *d; - - dhcpv6_for_each_option(ite1, &h[1], oend, otype, olen, d) - { - if (otype == DHCPV6_OPT_IA_PREFIX) - { - cand.preference += 2000; - } - else if (otype == DHCPV6_OPT_STATUS && - olen >= 2 && d[0] == 0 && - d[1] == DHCPV6_NOPREFIXAVAIL) - { - cand.preference -= 2000; - } - } - } - } - - if (cand.duid_len > 0) - { - dhcp6c_add_state(handle, STATE_SERVER_CAND, &cand, sizeof(cand)); - } - - return 0; -} - -static int dhcp6c_commit_advert(FAR void *handle, uint32_t elapsed) -{ - FAR struct dhcp6c_state_s *pdhcp6c = (FAR struct dhcp6c_state_s *)handle; - size_t cand_len; - FAR struct dhcpv6_server_cand_s *c = NULL; - FAR struct dhcpv6_server_cand_s *cand = dhcp6c_get_state(handle, - STATE_SERVER_CAND, - &cand_len); - bool retry = false; - - for (size_t i = 0; i < cand_len / sizeof(*c); ++i) - { - if (cand[i].has_noaddravail) - { - retry = true; - } - - if (c == NULL || c->preference < cand[i].preference) - { - c = &cand[i]; - } - } - - if (retry && pdhcp6c->ia_mode == IA_MODE_TRY) - { - /* We give it a second try without the IA_NA */ - - pdhcp6c->ia_mode = IA_MODE_NONE; - return dhcp6c_command(handle, DHCPV6_MSG_SOLICIT); - } - - if (c != NULL) - { - uint16_t hdr[2] = - { - htons(DHCPV6_OPT_SERVERID), htons(c->duid_len) - }; - - dhcp6c_add_state(handle, STATE_SERVER_ID, hdr, sizeof(hdr)); - dhcp6c_add_state(handle, STATE_SERVER_ID, c->duid, c->duid_len); - pdhcp6c->accept_reconfig = c->wants_reconfigure; - } - - dhcp6c_clear_state(handle, STATE_SERVER_CAND); - - if (c == NULL) - { - return -1; - } - else if (pdhcp6c->request_prefix || pdhcp6c->ia_mode != IA_MODE_NONE) - { - return DHCPV6_STATEFUL; - } - else - { - return DHCPV6_STATELESS; - } -} - -static time_t dhcp6c_parse_ia(FAR void *handle, FAR void *opt, FAR void *end) -{ - uint32_t timeout = UINT32_MAX; - uint16_t otype; - uint16_t olen; - uint16_t stype; - uint16_t slen; - FAR uint8_t *ite0; - FAR uint8_t *odata; - FAR uint8_t *sdata; - - /* Update address IA */ - - dhcpv6_for_each_option(ite0, opt, end, otype, olen, odata) - { - if (otype == DHCPV6_OPT_IA_PREFIX) - { - FAR struct dhcpv6_ia_prefix_s *prefix = (FAR void *)(odata - 4); - FAR struct dhcpv6_ia_prefix_s *local = NULL; - uint32_t valid; - uint32_t pref; - size_t pd_len; - FAR uint8_t *pd; - FAR uint8_t *ite1; - - if (olen + 4u < sizeof(*prefix)) - { - continue; - } - - olen = sizeof(*prefix); - valid = ntohl(prefix->valid); - pref = ntohl(prefix->preferred); - - if (pref > valid) - { - continue; - } - - /* Search matching IA */ - - pd = dhcp6c_get_state(handle, STATE_IA_PD, &pd_len); - dhcpv6_for_each_option(ite1, pd, pd + pd_len, - stype, slen, sdata) - { - if (memcmp(sdata + 8, odata + 8, - sizeof(local->addr) + 1) == 0) - { - local = (FAR void *)(sdata - 4); - } - } - - if (local != NULL) - { - local->preferred = prefix->preferred; - local->valid = prefix->valid; - } - else - { - dhcp6c_add_state(handle, STATE_IA_PD, prefix, olen); - } - - if (timeout > valid) - { - timeout = valid; - } - } - else if (otype == DHCPV6_OPT_IA_ADDR) - { - FAR struct dhcpv6_ia_addr_s *addr = (FAR void *)(odata - 4); - FAR struct dhcpv6_ia_addr_s *local = NULL; - uint32_t pref; - uint32_t valid; - size_t na_len; - FAR uint8_t *na; - FAR uint8_t *ite1; - - if (olen + 4u < sizeof(*addr)) - { - continue; - } - - olen = sizeof(*addr); - pref = ntohl(addr->preferred); - valid = ntohl(addr->valid); - - if (pref > valid) - { - continue; - } - - /* Search matching IA */ - - na = dhcp6c_get_state(handle, STATE_IA_NA, &na_len); - dhcpv6_for_each_option(ite1, na, na + na_len, - stype, slen, sdata) - { - if (memcmp(sdata, odata, sizeof(local->addr)) == 0) - { - local = (FAR void *)(sdata - 4); - } - } - - if (local != NULL) - { - local->preferred = addr->preferred; - local->valid = addr->valid; - } - else - { - dhcp6c_add_state(handle, STATE_IA_NA, addr, olen); - } - - if (timeout > valid) - { - timeout = valid; - } - } - } - - return timeout; -} - -static int dhcp6c_handle_reply(FAR void *handle, enum dhcpv6_msg_e orig, - FAR const void *opt, FAR const void *end, - uint32_t elapsed) -{ - FAR struct dhcp6c_state_s *pdhcp6c = (FAR struct dhcp6c_state_s *)handle; - uint16_t otype; - uint16_t olen; - FAR uint8_t *ite0; - FAR uint8_t *odata; - bool have_update = false; - size_t ia_na_len; - size_t ia_pd_len; - size_t dns_len; - size_t search_len; - size_t sntp_ip_len; - size_t sntp_dns_len; - size_t sip_ip_len; - size_t sip_fqdn_len; - FAR uint8_t *ia_na = dhcp6c_get_state(handle, STATE_IA_NA, &ia_na_len); - FAR uint8_t *ia_pd = dhcp6c_get_state(handle, STATE_IA_PD, &ia_pd_len); - FAR uint8_t *ia_end; - pdhcp6c->t1 = UINT32_MAX; - pdhcp6c->t2 = UINT32_MAX; - pdhcp6c->t3 = UINT32_MAX; - - dhcp6c_get_state(handle, STATE_DNS, &dns_len); - dhcp6c_get_state(handle, STATE_SEARCH, &search_len); - dhcp6c_get_state(handle, STATE_SNTP_IP, &sntp_ip_len); - dhcp6c_get_state(handle, STATE_SNTP_FQDN, &sntp_dns_len); - dhcp6c_get_state(handle, STATE_SIP_IP, &sip_ip_len); - dhcp6c_get_state(handle, STATE_SIP_FQDN, &sip_fqdn_len); - - /* Decrease valid and preferred lifetime of prefixes */ - - dhcpv6_for_each_option(ite0, ia_pd, ia_pd + ia_pd_len, otype, olen, odata) - { - FAR struct dhcpv6_ia_prefix_s *p = (FAR void *)(odata - 4); - uint32_t valid = ntohl(p->valid); - uint32_t pref = ntohl(p->preferred); - - if (valid != UINT32_MAX) - { - p->valid = (valid < elapsed) ? 0 : htonl(valid - elapsed); - } - - if (pref != UINT32_MAX) - { - p->preferred = (pref < elapsed) ? 0 : htonl(pref - elapsed); - } - } - - /* Decrease valid and preferred lifetime of addresses */ - - dhcpv6_for_each_option(ite0, ia_na, ia_na + ia_na_len, otype, olen, odata) - { - FAR struct dhcpv6_ia_addr_s *p = (FAR void *)(odata - 4); - uint32_t valid = ntohl(p->valid); - uint32_t pref = ntohl(p->preferred); - - if (valid != UINT32_MAX) - { - p->valid = (valid < elapsed) ? 0 : htonl(valid - elapsed); - } - - if (pref != UINT32_MAX) - { - p->preferred = (pref < elapsed) ? 0 : htonl(pref - elapsed); - } - } - - /* Parse and find all matching IAs */ - - dhcpv6_for_each_option(ite0, opt, end, otype, olen, odata) - { - if ((otype == DHCPV6_OPT_IA_PD || otype == DHCPV6_OPT_IA_NA) - && olen > sizeof(struct dhcpv6_ia_hdr_s)) - { - FAR struct dhcpv6_ia_hdr_s *ia_hdr = (FAR void *)(odata - 4); - time_t l_t1 = ntohl(ia_hdr->t1); - time_t l_t2 = ntohl(ia_hdr->t2); - uint16_t stype; - uint16_t slen; - FAR uint8_t *ite1; - FAR uint8_t *sdata; - time_t n; - - /* Test ID and T1-T2 validity */ - - if (ia_hdr->iaid != 1 || l_t2 < l_t1) - { - continue; - } - - /* Test status and bail if error */ - - dhcpv6_for_each_option(ite1, &ia_hdr[1], odata + olen, - stype, slen, sdata) - { - if (stype == DHCPV6_OPT_STATUS && slen >= 2 && - (sdata[0] || sdata[1])) - { - continue; - } - } - - /* Update times */ - - if (l_t1 > 0 && pdhcp6c->t1 > l_t1) - { - pdhcp6c->t1 = l_t1; - } - - if (l_t2 > 0 && pdhcp6c->t2 > l_t2) - { - pdhcp6c->t2 = l_t2; - } - - /* Always report update in case we have IA_PDs so that - * the state-script is called with updated times - */ - - if (otype == DHCPV6_OPT_IA_PD && pdhcp6c->request_prefix) - { - have_update = true; - } - - n = dhcp6c_parse_ia(handle, &ia_hdr[1], odata + olen); - if (n < pdhcp6c->t1) - { - pdhcp6c->t1 = n; - } - - if (n < pdhcp6c->t2) - { - pdhcp6c->t2 = n; - } - - if (n < pdhcp6c->t3) - { - pdhcp6c->t3 = n; - } - } - else if (otype == DHCPV6_OPT_DNS_SERVERS) - { - if (olen % 16 == 0) - { - dhcp6c_add_state(handle, STATE_DNS, odata, olen); - } - } - else if (otype == DHCPV6_OPT_DNS_DOMAIN) - { - dhcp6c_add_state(handle, STATE_SEARCH, odata, olen); - } - else if (otype == DHCPV6_OPT_NTP_SERVER) - { - uint16_t stype; - uint16_t slen; - FAR uint8_t *sdata; - FAR uint8_t *ite1; - - /* Test status and bail if error */ - - dhcpv6_for_each_option(ite1, odata, odata + olen, - stype, slen, sdata) - { - if (slen == 16 && - (stype == NTP_MC_ADDR || stype == NTP_SRV_ADDR)) - { - dhcp6c_add_state(handle, STATE_SNTP_IP, sdata, slen); - } - else if (slen > 0 && stype == NTP_SRV_FQDN) - { - dhcp6c_add_state(handle, STATE_SNTP_FQDN, sdata, slen); - } - } - } - else if (otype == DHCPV6_OPT_SIP_SERVER_A) - { - if (olen == 16) - { - dhcp6c_add_state(handle, STATE_SIP_IP, odata, olen); - } - } - else if (otype == DHCPV6_OPT_SIP_SERVER_D) - { - dhcp6c_add_state(handle, STATE_SIP_FQDN, odata, olen); - } - else if (otype == DHCPV6_OPT_INFO_REFRESH && olen >= 4) - { - uint32_t refresh = ntohl(*((FAR uint32_t *)odata)); - if (refresh < (uint32_t)pdhcp6c->t1) - { - pdhcp6c->t1 = refresh; - } - } - else if (otype != DHCPV6_OPT_CLIENTID && otype != DHCPV6_OPT_SERVERID) - { - dhcp6c_add_state(handle, STATE_CUSTOM_OPTS, (odata - 4), olen + 4); - } - } - - if (opt != NULL) - { - size_t new_ia_pd_len; - size_t new_ia_na_len; - have_update |= dhcp6c_commit_state(handle, STATE_DNS, dns_len); - have_update |= dhcp6c_commit_state(handle, STATE_SEARCH, search_len); - have_update |= dhcp6c_commit_state(handle, STATE_SNTP_IP, - sntp_ip_len); - have_update |= dhcp6c_commit_state(handle, STATE_SNTP_FQDN, - sntp_dns_len); - have_update |= dhcp6c_commit_state(handle, STATE_SIP_IP, sip_ip_len); - have_update |= dhcp6c_commit_state(handle, STATE_SIP_FQDN, - sip_fqdn_len); - dhcp6c_get_state(handle, STATE_IA_PD, &new_ia_pd_len); - dhcp6c_get_state(handle, STATE_IA_NA, &new_ia_na_len); - have_update |= (new_ia_pd_len != ia_pd_len) || - (new_ia_na_len != ia_na_len); - } - - /* Delete prefixes with 0 valid-time */ - - ia_pd = dhcp6c_get_state(handle, STATE_IA_PD, &ia_pd_len); - ia_end = ia_pd + ia_pd_len; - dhcpv6_for_each_option(ite0, ia_pd, ia_end, otype, olen, odata) - { - FAR struct dhcpv6_ia_prefix_s *p = (FAR void *)(odata - 4); - while (!p->valid) - { - ia_end = ia_pd + dhcp6c_remove_state(handle, STATE_IA_PD, - (FAR uint8_t *)p - ia_pd, olen + 4); - have_update = true; - } - } - - /* Delete addresses with 0 valid-time */ - - ia_na = dhcp6c_get_state(handle, STATE_IA_NA, &ia_na_len); - ia_end = ia_na + ia_na_len; - dhcpv6_for_each_option(ite0, ia_na, ia_end, otype, olen, odata) - { - FAR struct dhcpv6_ia_addr_s *p = (FAR void *)(odata - 4); - while (!p->valid) - { - ia_end = ia_na + dhcp6c_remove_state(handle, STATE_IA_NA, - (FAR uint8_t *)p - ia_na, olen + 4); - have_update = true; - } - } - - return have_update; -} - -static int dhcp6c_handle_reconfigure(FAR void *handle, - enum dhcpv6_msg_e orig, - FAR const void *opt, - FAR const void *end, - uint32_t elapsed) -{ - FAR struct dhcp6c_state_s *pdhcp6c = (FAR struct dhcp6c_state_s *)handle; - uint16_t otype; - uint16_t olen; - FAR uint8_t *odata; - FAR uint8_t *ite; - uint8_t msg = DHCPV6_MSG_RENEW; - - /* TODO: should verify the reconfigure message */ - - dhcpv6_for_each_option(ite, opt, end, otype, olen, odata) - { - if (otype == DHCPV6_OPT_RECONF_MESSAGE && olen == 1 && - (odata[0] == DHCPV6_MSG_RENEW || - odata[0] == DHCPV6_MSG_INFO_REQ)) - { - msg = odata[0]; - } - } - - pdhcp6c->t1 -= elapsed; - pdhcp6c->t2 -= elapsed; - pdhcp6c->t3 -= elapsed; - - if (pdhcp6c->t1 < 0) - { - pdhcp6c->t1 = 0; - } - - if (pdhcp6c->t2 < 0) - { - pdhcp6c->t2 = 0; - } - - if (pdhcp6c->t3 < 0) - { - pdhcp6c->t3 = 0; - } - - dhcp6c_handle_reply(handle, DHCPV6_MSG_UNKNOWN, NULL, NULL, elapsed); - - return msg; -} - -static int dhcp6c_handle_rebind_reply(FAR void *handle, - enum dhcpv6_msg_e orig, - FAR const void *opt, - FAR const void *end, - uint32_t elapsed) -{ - dhcp6c_handle_advert(handle, orig, opt, end, elapsed); - if (dhcp6c_commit_advert(handle, elapsed) < 0) - { - return -1; - } - - return dhcp6c_handle_reply(handle, orig, opt, end, elapsed); -} - -static int dhcp6c_single_request(FAR void *args) -{ - FAR struct dhcp6c_state_s *pdhcp6c = (FAR struct dhcp6c_state_s *)args; - FAR const char *process = NULL; - enum dhcpv6_mode_e mode; - enum dhcpv6_msg_e type; - int ret = -1; - - dhcp6c_clear_state(pdhcp6c, STATE_SERVER_ID); - dhcp6c_clear_state(pdhcp6c, STATE_SERVER_CAND); - dhcp6c_clear_state(pdhcp6c, STATE_IA_PD); - dhcp6c_clear_state(pdhcp6c, STATE_SNTP_IP); - dhcp6c_clear_state(pdhcp6c, STATE_SNTP_FQDN); - dhcp6c_clear_state(pdhcp6c, STATE_SIP_IP); - dhcp6c_clear_state(pdhcp6c, STATE_SIP_FQDN); - dhcp6c_clear_state(pdhcp6c, STATE_CUSTOM_OPTS); - ret = dhcp6c_command(pdhcp6c, DHCPV6_MSG_SOLICIT); - if (ret < 0) - { - return -1; - } - else if (ret == DHCPV6_STATELESS) - { - mode = DHCPV6_STATELESS; - type = DHCPV6_MSG_INFO_REQ; - process = "informed"; - } - else - { - mode = DHCPV6_STATEFUL; - type = DHCPV6_MSG_REQUEST; - process = "bound"; - } - - ret = dhcp6c_command(pdhcp6c, type); - if (ret >= 0) - { - ret = mode; - dhcp6c_switch_process(pdhcp6c, process); - } - - return ret; -} - -static int dhcp6c_lease(FAR void *args, uint8_t type) -{ - FAR struct dhcp6c_state_s *pdhcp6c = (FAR struct dhcp6c_state_s *)args; - enum dhcpv6_mode_e mode = (enum dhcpv6_mode_e)type; - size_t ia_pd_len; - size_t ia_na_len; - size_t ia_pd_new; - size_t ia_na_new; - size_t server_id_len; - int ret = -1; - - if (mode == DHCPV6_STATELESS) - { - /* Stateless mode */ - - while (!pdhcp6c->cancel) - { - /* Wait for T1 to expire or until we get a reconfigure */ - - ret = dhcp6c_poll_reconfigure(pdhcp6c); - if (ret >= 0) - { - dhcp6c_switch_process(pdhcp6c, "informed"); - } - - if (pdhcp6c->cancel) - { - break; - } - - /* Information-Request */ - - ret = dhcp6c_command(pdhcp6c, DHCPV6_MSG_INFO_REQ); - if (ret < 0) - { - nerr("DHCPV6_MSG_INFO_REQ error\n"); - break; - } - else - { - dhcp6c_switch_process(pdhcp6c, "informed"); - } - } - } - else - { - /* Stateful mode */ - - while (!pdhcp6c->cancel) - { - /* Renew Cycle - * Wait for T1 to expire or until we get a reconfigure - */ - - ret = dhcp6c_poll_reconfigure(pdhcp6c); - if (ret >= 0) - { - dhcp6c_switch_process(pdhcp6c, "updated"); - } - - if (pdhcp6c->cancel) - { - break; - } - - dhcp6c_get_state(pdhcp6c, STATE_IA_PD, &ia_pd_len); - dhcp6c_get_state(pdhcp6c, STATE_IA_NA, &ia_na_len); - - /* If we have any IAs, send renew, otherwise request */ - - if (ia_pd_len == 0 && ia_na_len == 0) - ret = dhcp6c_command(pdhcp6c, DHCPV6_MSG_REQUEST); - else - ret = dhcp6c_command(pdhcp6c, DHCPV6_MSG_RENEW); - - if (pdhcp6c->cancel) - { - break; - } - - if (ret >= 0) - { - /* Publish updates */ - - dhcp6c_switch_process(pdhcp6c, "updated"); - } - else - { - /* Remove binding */ - - dhcp6c_clear_state(pdhcp6c, STATE_SERVER_ID); - - /* If we have IAs, try rebind otherwise restart */ - - ret = dhcp6c_command(pdhcp6c, DHCPV6_MSG_REBIND); - dhcp6c_get_state(pdhcp6c, STATE_IA_PD, &ia_pd_new); - dhcp6c_get_state(pdhcp6c, STATE_IA_NA, &ia_na_new); - - /* We lost all our IAs, restart */ - - if (ret < 0 || (ia_pd_new == 0 && ia_pd_len) || - (ia_na_new == 0 && ia_na_len)) - { - break; - } - else if (ret >= 0) - { - dhcp6c_switch_process(pdhcp6c, "rebound"); - } - } - } - } - - dhcp6c_get_state(pdhcp6c, STATE_IA_PD, &ia_pd_len); - dhcp6c_get_state(pdhcp6c, STATE_IA_NA, &ia_na_len); - dhcp6c_get_state(pdhcp6c, STATE_SERVER_ID, &server_id_len); - - /* Add all prefixes to lost prefixes */ - - dhcp6c_clear_state(pdhcp6c, STATE_IA_PD); - dhcp6c_switch_process(pdhcp6c, "unbound"); - - /* Remove assigned addresses */ - - if (ia_na_len > 0) - { - dhcp6c_remove_addrs(pdhcp6c); - } - - if (server_id_len > 0 && (ia_pd_len > 0 || ia_na_len > 0)) - { - dhcp6c_command(pdhcp6c, DHCPV6_MSG_RELEASE); - } - - return ret; -} - -static FAR void *dhcp6c_run(FAR void *args) -{ - FAR struct dhcp6c_state_s *pdhcp6c = (FAR struct dhcp6c_state_s *)args; - int ret; - - while (!pdhcp6c->cancel) - { - ret = dhcp6c_single_request(pdhcp6c); - if (ret > 0) - { - dhcp6c_lease(pdhcp6c, ret); - } - } - - return 0; -} - -static FAR void *dhcp6c_precise_open(FAR const char *ifname, - enum dhcp6c_ia_mode_e ia_mode, - bool request_pd, - uint16_t opt[], int cnt) -{ - FAR struct dhcp6c_state_s *pdhcp6c; - struct sockaddr_in6 client_addr; - struct ifreq ifr; - size_t client_id_len; - int val = 1; - uint16_t oro[] = - { - htons(DHCPV6_OPT_DNS_SERVERS), - htons(DHCPV6_OPT_DNS_DOMAIN), - htons(DHCPV6_OPT_NTP_SERVER), - htons(DHCPV6_OPT_SIP_SERVER_A), - htons(DHCPV6_OPT_SIP_SERVER_D) - }; - - pdhcp6c = malloc(sizeof(struct dhcp6c_state_s)); - if (pdhcp6c == NULL) - { - return NULL; - } - - memset(pdhcp6c, 0, sizeof(*pdhcp6c)); - pdhcp6c->urandom_fd = open("/dev/urandom", O_CLOEXEC | O_RDONLY); - if (pdhcp6c->urandom_fd < 0) - { - free(pdhcp6c); - return NULL; - } - - pdhcp6c->sockfd = socket(AF_INET6, SOCK_DGRAM | SOCK_CLOEXEC, IPPROTO_UDP); - if (pdhcp6c->sockfd < 0) - { - close(pdhcp6c->urandom_fd); - free(pdhcp6c); - return NULL; - } - - /* Detect interface */ - - strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); - if (ioctl(pdhcp6c->sockfd, SIOCGIFINDEX, &ifr)) - { - close(pdhcp6c->urandom_fd); - close(pdhcp6c->sockfd); - free(pdhcp6c); - return NULL; - } - - pdhcp6c->ifindex = ifr.ifr_ifindex; - - /* Create client DUID */ - - dhcp6c_get_state(pdhcp6c, STATE_CLIENT_ID, &client_id_len); - if (client_id_len == 0) - { - uint8_t duid[14] = - { - 0, DHCPV6_OPT_CLIENTID, 0, 10, 0, - DHCPV6_DUID_LLADDR, 0, 1 - }; - - uint8_t zero[ETHER_ADDR_LEN]; - struct ifreq ifs[100]; - FAR struct ifreq *ifp; - FAR struct ifreq *ifend; - struct ifconf ifc; - - ioctl(pdhcp6c->sockfd, SIOCGIFHWADDR, &ifr); - memcpy(&duid[8], ifr.ifr_hwaddr.sa_data, ETHER_ADDR_LEN); - memset(zero, 0, sizeof(zero)); - ifc.ifc_req = ifs; - ifc.ifc_len = sizeof(ifs); - - if (memcmp(&duid[8], zero, ETHER_ADDR_LEN) == 0 && - ioctl(pdhcp6c->sockfd, SIOCGIFCONF, &ifc) >= 0) - { - /* If our interface doesn't have an address... */ - - ifend = ifs + (ifc.ifc_len / sizeof(struct ifreq)); - for (ifp = ifc.ifc_req; ifp < ifend && - memcmp(&duid[8], zero, 6) == 0; ifp++) - { - memcpy(ifr.ifr_name, ifp->ifr_name, - sizeof(ifr.ifr_name)); - ioctl(pdhcp6c->sockfd, SIOCGIFHWADDR, &ifr); - memcpy(&duid[8], ifr.ifr_hwaddr.sa_data, - ETHER_ADDR_LEN); - } - } - - dhcp6c_add_state(pdhcp6c, STATE_CLIENT_ID, duid, sizeof(duid)); - } - - /* Create ORO */ - - dhcp6c_add_state(pdhcp6c, STATE_ORO, oro, sizeof(oro)); - - /* Configure IPv6-options */ - - setsockopt(pdhcp6c->sockfd, IPPROTO_IPV6, IPV6_V6ONLY, &val, sizeof(val)); - setsockopt(pdhcp6c->sockfd, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val)); - setsockopt(pdhcp6c->sockfd, SOL_SOCKET, SO_BINDTODEVICE, ifname, - strlen(ifname)); - - memset(&client_addr, 0, sizeof(client_addr)); - client_addr.sin6_family = AF_INET6; - client_addr.sin6_port = htons(DHCPV6_CLIENT_PORT); - - if (bind(pdhcp6c->sockfd, (struct sockaddr *)&client_addr, - sizeof(client_addr)) != 0) - { - close(pdhcp6c->urandom_fd); - close(pdhcp6c->sockfd); - free(pdhcp6c); - return NULL; - } - - pdhcp6c->thread = 0; - pdhcp6c->cancel = false; - pdhcp6c->t1 = 0; - pdhcp6c->t2 = 0; - pdhcp6c->t3 = 0; - pdhcp6c->request_prefix = request_pd; - switch (ia_mode) - { - case IA_MODE_NONE: - case IA_MODE_TRY: - case IA_MODE_FORCE: - break; - default: - ia_mode = IA_MODE_TRY; - break; - } - - pdhcp6c->ia_mode = ia_mode; - pdhcp6c->accept_reconfig = false; - if (opt != NULL && cnt > 0) - { - uint16_t opttype; - for (int i = 0; i < cnt; i++) - { - opttype = htons(opt[i]); - dhcp6c_add_state(pdhcp6c, STATE_ORO, &opttype, 2); - } - } - - return pdhcp6c; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -FAR void *dhcp6c_open(FAR const char *interface) -{ - return dhcp6c_precise_open(interface, IA_MODE_TRY, true, NULL, 0); -} - -int dhcp6c_request(FAR void *handle, FAR struct dhcp6c_state *presult) -{ - int ret; - - if (handle == NULL) - { - return ERROR; - } - - ret = dhcp6c_single_request(handle); - if (ret >= 0) - { - dhcp6c_get_result(handle, presult); - return OK; - } - else - { - return ERROR; - } -} - -int dhcp6c_request_async(FAR void *handle, dhcp6c_callback_t callback) -{ - FAR struct dhcp6c_state_s *pdhcp6c = (FAR struct dhcp6c_state_s *)handle; - int ret; - - if (handle == NULL) - { - return ERROR; - } - - if (pdhcp6c->thread) - { - nerr("DHCP6C thread already running\n"); - return ERROR; - } - - pdhcp6c->callback = callback; - ret = pthread_create(&pdhcp6c->thread, NULL, dhcp6c_run, pdhcp6c); - if (ret != 0) - { - nerr("Failed to start the DHCP6C thread\n"); - return ERROR; - } - - return OK; -} - -void dhcp6c_cancel(FAR void *handle) -{ - FAR struct dhcp6c_state_s *pdhcp6c = (FAR struct dhcp6c_state_s *)handle; - sighandler_t old; - int ret; - - if (pdhcp6c != NULL) - { - pdhcp6c->cancel = true; - if (pdhcp6c->thread) - { - old = signal(SIGQUIT, SIG_IGN); - - /* Signal the dhcp6c_run */ - - ret = pthread_kill(pdhcp6c->thread, SIGQUIT); - if (ret != 0) - { - nerr("pthread_kill DHCP6C thread\n"); - } - - /* Wait for the end of dhcp6c_run */ - - ret = pthread_join(pdhcp6c->thread, NULL); - if (ret != 0) - { - nerr("pthread_join DHCP6C thread\n"); - } - - pdhcp6c->thread = 0; - signal(SIGQUIT, old); - } - } -} - -void dhcp6c_close(FAR void *handle) -{ - FAR struct dhcp6c_state_s *pdhcp6c = (FAR struct dhcp6c_state_s *)handle; - - if (pdhcp6c != NULL) - { - dhcp6c_cancel(pdhcp6c); - if (pdhcp6c->urandom_fd > 0) - { - close(pdhcp6c->urandom_fd); - } - - if (pdhcp6c->sockfd > 0) - { - close(pdhcp6c->sockfd); - } - - for (int i = 0; i < STATE_MAX; i++) - { - if (pdhcp6c->state_data[i] != NULL) - { - free(pdhcp6c->state_data[i]); - } - } - - free(pdhcp6c); - } -} diff --git a/netutils/dhcpc/CMakeLists.txt b/netutils/dhcpc/CMakeLists.txt deleted file mode 100644 index 7bc2ba17e..000000000 --- a/netutils/dhcpc/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -# ############################################################################## -# apps/netutils/dhcpc/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_NETUTILS_DHCPC) - target_sources(apps PRIVATE dhcpc.c) -endif() diff --git a/netutils/dhcpc/Kconfig b/netutils/dhcpc/Kconfig index 009ecaa9b..8c2cf4c74 100644 --- a/netutils/dhcpc/Kconfig +++ b/netutils/dhcpc/Kconfig @@ -6,8 +6,8 @@ config NETUTILS_DHCPC bool "DHCP client" default n - depends on NET_UDP - select NET_BINDTODEVICE if !NET_UDP_NO_STACK + depends on NET_UDP && NET_BROADCAST && NET_IPv4 + select NET_UDP_BINDTODEVICE if !NET_UDP_NO_STACK ---help--- Enable support for the DHCP client. @@ -17,9 +17,9 @@ config NETUTILS_DHCPC_HOST_NAME string "DHCP client host name" default "nuttx" -config NETUTILS_DHCPC_RECV_TIMEOUT_MS - int "Number of receive timeout in millisecond" - default 3000 +config NETUTILS_DHCPC_RECV_TIMEOUT + int "Number of receive timeout in second" + default 3 ---help--- This is the timeout value when dhcp client receives response @@ -32,53 +32,10 @@ config NETUTILS_DHCPC_RETRIES config NETUTILS_DHCPC_BOOTP_FLAGS hex "Flags of Bootstrap" - default 0x0000 if !NET_IPFORWARD - default 0x8000 if NET_IPFORWARD + default 0x8000 ---help--- This setting to set the BOOTP broadcast flags. Reference RFC1542: Clarifications and Extensions for the Bootstrap Protocol. - Note: We're not always able to receive unicast traffic before - being fully configured, e.g. with forward enabled. Then we need - to enable the broadcast flag under these situations. - -config NETUTILS_DHCPC_RELEASE_RETRIES - int "DHCP Release send retries" - default 3 - ---help--- - Number of times to retry sending DHCPRELEASE message if sendto() fails. - Default is 3 attempts. - -config NETUTILS_DHCPC_RELEASE_TRANSMISSION_DELAY_MS - int "DHCP Release transmission delay (milliseconds)" - default 10 - ---help--- - Delay in milliseconds used for: - 1. Between DHCPRELEASE retry attempts when sendto() fails - 2. To ensure packet transmission before socket closure (if IP clearing enabled) - Since UDP is connectionless, this delay gives the network stack - time to actually send the packet. Set to 0 to disable delays - (not recommended). Default is 10ms. - -config NETUTILS_DHCPC_RELEASE_ENSURE_TRANSMISSION - bool "Ensure DHCP Release message transmission" - default y - ---help--- - Add a delay after successfully sending DHCPRELEASE message to ensure - the packet is actually transmitted before the function returns. - Since DHCP RELEASE has no ACK response from server, this delay helps - ensure the release message reaches the server before closing the socket. - Uses the same delay value as CONFIG_NETUTILS_DHCPC_RELEASE_TRANSMISSION_DELAY_MS. - -config NETUTILS_DHCPC_RELEASE_CLEAR_IP - bool "Clear IP address after DHCP release" - default n - ---help--- - Clear all network configuration from the interface after sending - DHCPRELEASE message. This includes IP address, subnet mask, default - gateway. RFC 2131 doesn't mandate immediate clearing, so this is - disabled by default to maintain connectivity. - Enable this for scenarios where complete network reset is required. - endif diff --git a/netutils/dhcpc/Make.defs b/netutils/dhcpc/Make.defs index 84be9ecdc..3f67024ad 100644 --- a/netutils/dhcpc/Make.defs +++ b/netutils/dhcpc/Make.defs @@ -1,8 +1,5 @@ -############################################################################ # apps/netutils/dhcpc/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -20,6 +17,6 @@ # ############################################################################ -ifneq ($(CONFIG_NETUTILS_DHCPC),) +ifeq ($(CONFIG_NETUTILS_DHCPC),y) CONFIGURED_APPS += $(APPDIR)/netutils/dhcpc endif diff --git a/netutils/dhcpc/Makefile b/netutils/dhcpc/Makefile index 43b62a53c..4eaea283a 100644 --- a/netutils/dhcpc/Makefile +++ b/netutils/dhcpc/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/netutils/dhcpc/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/netutils/dhcpc/dhcpc.c b/netutils/dhcpc/dhcpc.c index a449c96ca..8df922165 100644 --- a/netutils/dhcpc/dhcpc.c +++ b/netutils/dhcpc/dhcpc.c @@ -1,11 +1,14 @@ /**************************************************************************** * apps/netutils/dhcpc/dhcpc.c * - * SPDX-License-Identifier: BSD-3-Clause - * SPDX-FileCopyrightText: 2007, 2009, 2011-2012 Gregory Nutt. - * SPDX-FileCopyrightText: 2005, Swedish Institute of Computer Science - * SPDX-FileContributor: Gregory Nutt - * SPDX-FileContributor: Adam Dunkels + * Copyright (C) 2007, 2009, 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Based heavily on portions of uIP: + * + * Author: Adam Dunkels + * Copyright (c) 2005, Swedish Institute of Computer Science + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -48,12 +51,11 @@ #include #include #include -#include +#include #include #include #include -#include #include "netutils/dhcpc.h" #include "netutils/netlib.h" @@ -91,15 +93,11 @@ #define DHCP_OPTION_ROUTER 3 #define DHCP_OPTION_DNS_SERVER 6 #define DHCP_OPTION_HOST_NAME 12 -#define DHCP_OPTION_NTP_SERVER 42 #define DHCP_OPTION_REQ_IPADDR 50 #define DHCP_OPTION_LEASE_TIME 51 #define DHCP_OPTION_MSG_TYPE 53 #define DHCP_OPTION_SERVER_ID 54 #define DHCP_OPTION_REQ_LIST 55 -#define DHCP_OPTION_T1_TIME 58 -#define DHCP_OPTION_T2_TIME 59 -#define DHCP_OPTION_CLIENT_ID 61 #define DHCP_OPTION_END 255 #define BUFFER_SIZE 256 @@ -133,7 +131,6 @@ struct dhcpc_state_s { FAR const char *interface; int sockfd; - uint8_t xid[4]; struct in_addr ipaddr; struct in_addr serverid; struct dhcp_msg packet; @@ -148,6 +145,11 @@ struct dhcpc_state_s * Private Data ****************************************************************************/ +static const uint8_t xid[4] = +{ + 0xad, 0xde, 0x12, 0x23 +}; + static const uint8_t magic_cookie[4] = { 99, 130, 83, 99 @@ -197,25 +199,13 @@ static FAR uint8_t *dhcpc_addreqipaddr(FAR struct in_addr *ipaddr, return optptr + 4; } -static FAR uint8_t *dhcpc_addclientid(FAR uint8_t *clientid, - FAR uint8_t len, - FAR uint8_t *optptr) -{ - *optptr++ = DHCP_OPTION_CLIENT_ID; - *optptr++ = 1 + len; - *optptr++ = 0x1; - memcpy(optptr, clientid, len); - return optptr + len; -} - static FAR uint8_t *dhcpc_addreqoptions(FAR uint8_t *optptr) { *optptr++ = DHCP_OPTION_REQ_LIST; - *optptr++ = 4; + *optptr++ = 3; *optptr++ = DHCP_OPTION_SUBNET_MASK; *optptr++ = DHCP_OPTION_ROUTER; *optptr++ = DHCP_OPTION_DNS_SERVER; - *optptr++ = DHCP_OPTION_NTP_SERVER; return optptr; } @@ -232,7 +222,7 @@ static FAR uint8_t *dhcpc_addend(FAR uint8_t *optptr) static int dhcpc_sendmsg(FAR struct dhcpc_state_s *pdhcpc, FAR struct dhcpc_state *presult, int msgtype) { - char hostname[HOST_NAME_MAX + 1]; + char hostname[HOST_NAME_MAX]; struct sockaddr_in addr; FAR uint8_t *pend; in_addr_t serverid = INADDR_BROADCAST; @@ -244,7 +234,7 @@ static int dhcpc_sendmsg(FAR struct dhcpc_state_s *pdhcpc, pdhcpc->packet.op = DHCP_REQUEST; pdhcpc->packet.htype = DHCP_HTYPE_ETHERNET; pdhcpc->packet.hlen = pdhcpc->maclen; - memcpy(pdhcpc->packet.xid, pdhcpc->xid, 4); + memcpy(pdhcpc->packet.xid, xid, 4); memcpy(pdhcpc->packet.chaddr, pdhcpc->macaddr, pdhcpc->maclen); memset(&pdhcpc->packet.chaddr[pdhcpc->maclen], 0, 16 - pdhcpc->maclen); memcpy(pdhcpc->packet.options, magic_cookie, sizeof(magic_cookie)); @@ -258,7 +248,7 @@ static int dhcpc_sendmsg(FAR struct dhcpc_state_s *pdhcpc, if (gethostname(hostname, sizeof(hostname)) || (0 == strlen(hostname))) { - strlcpy(hostname, CONFIG_NETUTILS_DHCPC_HOST_NAME, sizeof(hostname)); + strncpy(hostname, CONFIG_NETUTILS_DHCPC_HOST_NAME, HOST_NAME_MAX); } /* Handle the message specific settings */ @@ -268,12 +258,8 @@ static int dhcpc_sendmsg(FAR struct dhcpc_state_s *pdhcpc, /* Broadcast DISCOVER message to all servers */ case DHCPDISCOVER: - /* Socket binded to INADDR_ANY is not intended to receive unicast - * traffic before being fully configured, at least dhclient - * configured with socket-only won't do so on Linux and BSDs. - * We can sometimes receive unicast traffic before being fully - * configured, it's good, but not always, so we need to set the - * broadcast flag under some situations. + /* REVISIT: We don't need the broadcast flag since we can receive + * unicast traffic before being fully configured. */ /* Broadcast bit. */ @@ -282,12 +268,14 @@ static int dhcpc_sendmsg(FAR struct dhcpc_state_s *pdhcpc, pend = dhcpc_addhostname(hostname, pend); pend = dhcpc_addreqoptions(pend); - pend = dhcpc_addclientid(pdhcpc->macaddr, pdhcpc->maclen, pend); break; /* Send REQUEST message to the server that sent the *first* OFFER */ case DHCPREQUEST: + /* REVISIT: We don't need the broadcast flag since we can receive + * unicast traffic before being fully configured. + */ /* Broadcast bit. */ @@ -296,7 +284,6 @@ static int dhcpc_sendmsg(FAR struct dhcpc_state_s *pdhcpc, pend = dhcpc_addhostname(hostname, pend); pend = dhcpc_addserverid(&pdhcpc->serverid, pend); pend = dhcpc_addreqipaddr(&pdhcpc->ipaddr, pend); - pend = dhcpc_addclientid(pdhcpc->macaddr, pdhcpc->maclen, pend); break; /* Send DECLINE message to the server that sent the *last* OFFER */ @@ -307,18 +294,7 @@ static int dhcpc_sendmsg(FAR struct dhcpc_state_s *pdhcpc, serverid = presult->serverid.s_addr; break; - /* Send RELEASE message to the server to relinquish the lease */ - - case DHCPRELEASE: - - memcpy(pdhcpc->packet.ciaddr, &presult->ipaddr.s_addr, 4); - pend = dhcpc_addserverid(&presult->serverid, pend); - pend = dhcpc_addclientid(pdhcpc->macaddr, pdhcpc->maclen, pend); - serverid = presult->serverid.s_addr; - break; - default: - errno = EINVAL; return ERROR; } @@ -344,7 +320,6 @@ static uint8_t dhcpc_parseoptions(FAR struct dhcpc_state *presult, { FAR uint8_t *end = optptr + len; uint8_t type = 0; - uint16_t tmp[2]; while (optptr < end) { @@ -380,32 +355,11 @@ static uint8_t dhcpc_parseoptions(FAR struct dhcpc_state *presult, case DHCP_OPTION_DNS_SERVER: - /* Get the DNS server addresses in network order. - * DHCP option 6 can contain multiple DNS server addresses, - * each 4 bytes long. - */ + /* Get the DNS server address in network order */ - if (optptr + 2 <= end) + if (optptr + 6 <= end) { - uint8_t optlen = *(optptr + 1); - uint8_t num_dns = optlen / 4; - uint8_t i; - - /* Limit to configured maximum */ - - if (num_dns > CONFIG_NETDB_DNSSERVER_NAMESERVERS) - { - num_dns = CONFIG_NETDB_DNSSERVER_NAMESERVERS; - } - - presult->num_dnsaddr = 0; - for (i = 0; i < num_dns && (optptr + 2 + i * 4 + 4) <= end; - i++) - { - memcpy(&presult->dnsaddr[i].s_addr, optptr + 2 + i * 4, - 4); - presult->num_dnsaddr++; - } + memcpy(&presult->dnsaddr.s_addr, optptr + 2, 4); } else { @@ -413,39 +367,6 @@ static uint8_t dhcpc_parseoptions(FAR struct dhcpc_state *presult, } break; - case DHCP_OPTION_NTP_SERVER: - - /* Get the NTP server addresses in network order. - * DHCP option 42 can contain multiple IPv4 addresses, - * each 4 bytes long. - */ - - if (optptr + 2 <= end) - { - uint8_t optlen = *(optptr + 1); - uint8_t num_ntp = optlen / 4; - uint8_t i; - - if (num_ntp > CONFIG_NETUTILS_DHCPC_NTP_SERVERS) - { - num_ntp = CONFIG_NETUTILS_DHCPC_NTP_SERVERS; - } - - presult->num_ntpaddr = 0; - for (i = 0; i < num_ntp && (optptr + 2 + i * 4 + 4) <= end; - i++) - { - memcpy(&presult->ntpaddr[i].s_addr, optptr + 2 + i * 4, - 4); - presult->num_ntpaddr++; - } - } - else - { - nerr("Packet too short (NTP address missing)\n"); - } - break; - case DHCP_OPTION_MSG_TYPE: /* Get message type */ @@ -480,6 +401,7 @@ static uint8_t dhcpc_parseoptions(FAR struct dhcpc_state *presult, if (optptr + 6 <= end) { + uint16_t tmp[2]; memcpy(tmp, optptr + 2, 4); presult->lease_time = ((uint32_t)ntohs(tmp[0])) << 16 | (uint32_t)ntohs(tmp[1]); @@ -490,38 +412,6 @@ static uint8_t dhcpc_parseoptions(FAR struct dhcpc_state *presult, } break; - case DHCP_OPTION_T1_TIME: - - /* Get renewal (T1) time (in seconds) in host order */ - - if (optptr + 6 <= end) - { - memcpy(tmp, optptr + 2, 4); - presult->renewal_time = ((uint32_t)ntohs(tmp[0])) << 16 | - (uint32_t)ntohs(tmp[1]); - } - else - { - nerr("Packet too short (renewal time missing)\n"); - } - break; - - case DHCP_OPTION_T2_TIME: - - /* Get rebinding (T2) time (in seconds) in host order */ - - if (optptr + 6 <= end) - { - memcpy(tmp, optptr + 2, 4); - presult->rebinding_time = ((uint32_t)ntohs(tmp[0])) << 16 | - (uint32_t)ntohs(tmp[1]); - } - else - { - nerr("Packet too short (rebinding time missing)\n"); - } - break; - case DHCP_OPTION_END: return type; } @@ -545,7 +435,7 @@ static uint8_t dhcpc_parsemsg(FAR struct dhcpc_state_s *pdhcpc, int buflen, FAR struct dhcpc_state *presult) { if (buflen >= 44 && pdhcpc->packet.op == DHCP_REPLY && - memcmp(pdhcpc->packet.xid, pdhcpc->xid, 4) == 0 && + memcmp(pdhcpc->packet.xid, xid, sizeof(xid)) == 0 && memcmp(pdhcpc->packet.chaddr, pdhcpc->macaddr, pdhcpc->maclen) == 0) { @@ -568,16 +458,8 @@ static void *dhcpc_run(void *args) struct dhcpc_state result; int ret; -#ifndef CONFIG_ENABLE_ALL_SIGNALS - pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); - pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL); -#endif - while (1) { -#ifndef CONFIG_ENABLE_ALL_SIGNALS - pthread_testcancel(); -#endif ret = dhcpc_request(pdhcpc, &result); if (ret == OK) { @@ -638,21 +520,13 @@ FAR void *dhcpc_open(FAR const char *interface, FAR const void *macaddr, /* Initialize the allocated structure */ memset(pdhcpc, 0, sizeof(struct dhcpc_state_s)); - - /* RFC2131: A DHCP client MUST choose 'xid's in such a - * way as to minimize the chance of using an 'xid' identical to one - * used by another client. - */ - - arc4random_buf(pdhcpc->xid, 4); - pdhcpc->interface = interface; pdhcpc->maclen = maclen; memcpy(pdhcpc->macaddr, macaddr, pdhcpc->maclen); /* Create a UDP socket */ - pdhcpc->sockfd = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0); + pdhcpc->sockfd = socket(PF_INET, SOCK_DGRAM, 0); if (pdhcpc->sockfd < 0) { ninfo("socket handle %d\n", pdhcpc->sockfd); @@ -678,8 +552,8 @@ FAR void *dhcpc_open(FAR const char *interface, FAR const void *macaddr, /* Configure for read timeouts */ - tv.tv_sec = CONFIG_NETUTILS_DHCPC_RECV_TIMEOUT_MS / 1000; - tv.tv_usec = (CONFIG_NETUTILS_DHCPC_RECV_TIMEOUT_MS % 1000) * 1000; + tv.tv_sec = CONFIG_NETUTILS_DHCPC_RECV_TIMEOUT; + tv.tv_usec = 0; ret = setsockopt(pdhcpc->sockfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(struct timeval)); @@ -691,14 +565,14 @@ FAR void *dhcpc_open(FAR const char *interface, FAR const void *macaddr, return NULL; } -#ifdef CONFIG_NET_BINDTODEVICE +#ifdef CONFIG_NET_UDP_BINDTODEVICE /* Bind socket to interface, because UDP packets have to be sent to the * broadcast address at a moment when it is not possible to decide the * target network device using the local or remote address (which is, * by definition and purpose of DHCP, undefined yet). */ - ret = setsockopt(pdhcpc->sockfd, SOL_SOCKET, SO_BINDTODEVICE, + ret = setsockopt(pdhcpc->sockfd, IPPROTO_UDP, UDP_BINDTODEVICE, pdhcpc->interface, strlen(pdhcpc->interface)); if (ret < 0) { @@ -744,9 +618,7 @@ void dhcpc_close(FAR void *handle) void dhcpc_cancel(FAR void *handle) { struct dhcpc_state_s *pdhcpc = (struct dhcpc_state_s *)handle; -#ifdef CONFIG_ENABLE_ALL_SIGNALS sighandler_t old; -#endif int ret; if (pdhcpc) @@ -755,7 +627,6 @@ void dhcpc_cancel(FAR void *handle) if (pdhcpc->thread) { -#ifdef CONFIG_ENABLE_ALL_SIGNALS old = signal(SIGQUIT, SIG_IGN); /* Signal the dhcpc_run */ @@ -765,9 +636,6 @@ void dhcpc_cancel(FAR void *handle) { nerr("ERROR: pthread_kill DHCPC thread\n"); } -#else - pthread_cancel(pdhcpc->thread); -#endif /* Wait for the end of dhcpc_run */ @@ -778,9 +646,7 @@ void dhcpc_cancel(FAR void *handle) } pdhcpc->thread = 0; -#ifdef CONFIG_ENABLE_ALL_SIGNALS signal(SIGQUIT, old); -#endif } } } @@ -793,28 +659,22 @@ int dhcpc_request(FAR void *handle, FAR struct dhcpc_state *presult) { FAR struct dhcpc_state_s *pdhcpc = (FAR struct dhcpc_state_s *)handle; struct in_addr oldaddr; + struct in_addr newaddr; ssize_t result; uint8_t msgtype; int retries; int state; - clock_t start; - memset(presult, 0, sizeof(*presult)); - - /* RFC2131: For example, a client may choose a different, - * random initial 'xid' each time the client is rebooted, and - * subsequently use sequential 'xid's until the next reboot. - */ - - pdhcpc->xid[3]++; - - /* Save the currently assigned IP address. It should be INADDR_ANY - * if this is the initial request, or a valid IP if this is a renewal. - */ + /* Save the currently assigned IP address (should be INADDR_ANY) */ oldaddr.s_addr = 0; netlib_get_ipv4addr(pdhcpc->interface, &oldaddr); + /* Set the IP address to INADDR_ANY. */ + + newaddr.s_addr = INADDR_ANY; + netlib_set_ipv4addr(pdhcpc->interface, &newaddr); + /* Loop sending the DISCOVER up to CONFIG_NETUTILS_DHCPC_RETRIES * times */ @@ -832,7 +692,6 @@ int dhcpc_request(FAR void *handle, FAR struct dhcpc_state *presult) { if (pdhcpc->cancel) { - errno = EINTR; return ERROR; } @@ -848,54 +707,48 @@ int dhcpc_request(FAR void *handle, FAR struct dhcpc_state *presult) /* Get the DHCPOFFER response */ - start = clock(); - do + result = recv(pdhcpc->sockfd, &pdhcpc->packet, + sizeof(struct dhcp_msg), 0); + if (result >= 0) { - result = recv(pdhcpc->sockfd, &pdhcpc->packet, - sizeof(struct dhcp_msg), 0); - if (result >= 0) + msgtype = dhcpc_parsemsg(pdhcpc, result, presult); + if (msgtype == DHCPOFFER) { - msgtype = dhcpc_parsemsg(pdhcpc, result, presult); - if (msgtype == DHCPOFFER) - { - /* Save the servid from the presult so that it is not - * clobbered by a new OFFER. - */ + /* Save the servid from the presult so that it is not + * clobbered by a new OFFER. + */ - ninfo("Received OFFER from %08" PRIx32 "\n", - (uint32_t)ntohl(presult->serverid.s_addr)); - pdhcpc->ipaddr.s_addr = presult->ipaddr.s_addr; - pdhcpc->serverid.s_addr = presult->serverid.s_addr; + ninfo("Received OFFER from %08" PRIx32 "\n", + (uint32_t)ntohl(presult->serverid.s_addr)); + pdhcpc->ipaddr.s_addr = presult->ipaddr.s_addr; + pdhcpc->serverid.s_addr = presult->serverid.s_addr; - /* Temporarily use the address offered by the server - * and break out of the loop. - */ + /* Temporarily use the address offered by the server + * and break out of the loop. + */ - netlib_set_ipv4addr(pdhcpc->interface, - &presult->ipaddr); - state = STATE_HAVE_OFFER; - } - } - - /* An error has occurred. If this was a timeout error (meaning - * that nothing was received on this socket for a long period - * of time). Then loop and send the DISCOVER command again. - */ - - else if (errno != EAGAIN && errno != EINTR) - { - /* An error other than a timeout was received -- error out */ - - return ERROR; + netlib_set_ipv4addr(pdhcpc->interface, + &presult->ipaddr); + state = STATE_HAVE_OFFER; } } - while (state == STATE_INITIAL && TICK2MSEC(clock() - start) < - CONFIG_NETUTILS_DHCPC_RECV_TIMEOUT_MS); + + /* An error has occurred. If this was a timeout error (meaning + * that nothing was received on this socket for a long period + * of time). Then loop and send the DISCOVER command again. + */ + + else if (errno != EAGAIN) + { + /* An error other than a timeout was received -- error out */ + + return ERROR; + } } while (state == STATE_INITIAL && retries < CONFIG_NETUTILS_DHCPC_RETRIES); - /* If no DHCPOFFER received here, error out */ + /* If no DHCPOFFER recveived here, error out */ if (state == STATE_INITIAL) { @@ -911,7 +764,6 @@ int dhcpc_request(FAR void *handle, FAR struct dhcpc_state *presult) { if (pdhcpc->cancel) { - errno = EINTR; return ERROR; } @@ -929,131 +781,98 @@ int dhcpc_request(FAR void *handle, FAR struct dhcpc_state *presult) /* Get the ACK/NAK response to the REQUEST (or timeout) */ - start = clock(); - do + result = recv(pdhcpc->sockfd, &pdhcpc->packet, + sizeof(struct dhcp_msg), 0); + if (result >= 0) { - result = recv(pdhcpc->sockfd, &pdhcpc->packet, - sizeof(struct dhcp_msg), 0); - if (result >= 0) - { - /* Parse the response */ + /* Parse the response */ - msgtype = dhcpc_parsemsg(pdhcpc, result, presult); + msgtype = dhcpc_parsemsg(pdhcpc, result, presult); - /* The ACK response means that the server has accepted - * our request and we have the lease. - */ - - if (msgtype == DHCPACK) - { - ninfo("Received ACK\n"); - state = STATE_HAVE_LEASE; - } - - /* NAK means the server has refused our request */ - - else if (msgtype == DHCPNAK) - { - ninfo("Received NAK\n"); - oldaddr.s_addr = INADDR_ANY; - netlib_set_ipv4addr(pdhcpc->interface, &oldaddr); - errno = ECONNREFUSED; - return ERROR; - } - - /* If we get any OFFERs from other servers, then decline - * them now and continue waiting for the ACK from the server - * that we requested from. - */ - - else if (msgtype == DHCPOFFER && - pdhcpc->serverid.s_addr != presult->serverid.s_addr) - { - ninfo("Received another OFFER, send DECLINE\n"); - dhcpc_sendmsg(pdhcpc, presult, DHCPDECLINE); - } - - /* Otherwise, it is something that we do not recognize */ - - else - { - ninfo("Ignoring msgtype=%d\n", msgtype); - } - } - - /* An error has occurred. If this was a timeout error (meaning - * that nothing was received on this socket for a long period of - * time). Then break out and send the DISCOVER command again - * (at most 3 times). + /* The ACK response means that the server has accepted + * our request and we have the lease. */ - else if (errno != EAGAIN && errno != EINTR) + if (msgtype == DHCPACK) { - /* An error other than a timeout was received */ + ninfo("Received ACK\n"); + state = STATE_HAVE_LEASE; + } - netlib_set_ipv4addr(pdhcpc->interface, &oldaddr); - return ERROR; + /* NAK means the server has refused our request. Break out of + * this loop with state == STATE_HAVE_OFFER and send DISCOVER + * again + */ + + else if (msgtype == DHCPNAK) + { + ninfo("Received NAK\n"); + break; + } + + /* If we get any OFFERs from other servers, then decline + * them now and continue waiting for the ACK from the server + * that we requested from. + */ + + else if (msgtype == DHCPOFFER) + { + ninfo("Received another OFFER, send DECLINE\n"); + dhcpc_sendmsg(pdhcpc, presult, DHCPDECLINE); + } + + /* Otherwise, it is something that we do not recognize */ + + else + { + ninfo("Ignoring msgtype=%d\n", msgtype); } } - while (state == STATE_HAVE_OFFER && TICK2MSEC(clock() - start) < - CONFIG_NETUTILS_DHCPC_RECV_TIMEOUT_MS); + + /* An error has occurred. If this was a timeout error (meaning + * that nothing was received on this socket for a long period of + * time). Then break out and send the DISCOVER command again + * (at most 3 times). + */ + + else if (errno != EAGAIN) + { + /* An error other than a timeout was received */ + + netlib_set_ipv4addr(pdhcpc->interface, &oldaddr); + return ERROR; + } } while (state == STATE_HAVE_OFFER && retries < CONFIG_NETUTILS_DHCPC_RETRIES); - /* If no DHCPLEASE received here, error out */ + /* If no DHCPLEASE recveived here, error out */ if (state != STATE_HAVE_LEASE) { return ERROR; } - ninfo("Got IP address %u.%u.%u.%u\n", - ip4_addr1(presult->ipaddr.s_addr), - ip4_addr2(presult->ipaddr.s_addr), - ip4_addr3(presult->ipaddr.s_addr), - ip4_addr4(presult->ipaddr.s_addr)); - ninfo("Got netmask %u.%u.%u.%u\n", - ip4_addr1(presult->netmask.s_addr), - ip4_addr2(presult->netmask.s_addr), - ip4_addr3(presult->netmask.s_addr), - ip4_addr4(presult->netmask.s_addr)); - - /* Print all DNS servers received */ - - if (presult->num_dnsaddr > 0) - { - uint8_t i; - for (i = 0; i < presult->num_dnsaddr; i++) - { - ninfo("Got DNS server %d: %u.%u.%u.%u\n", i, - ip4_addr1(presult->dnsaddr[i].s_addr), - ip4_addr2(presult->dnsaddr[i].s_addr), - ip4_addr3(presult->dnsaddr[i].s_addr), - ip4_addr4(presult->dnsaddr[i].s_addr)); - } - } - - /* Print all NTP servers received */ - - if (presult->num_ntpaddr > 0) - { - uint8_t i; - for (i = 0; i < presult->num_ntpaddr; i++) - { - ninfo("Got NTP server %d: %u.%u.%u.%u\n", i, - ip4_addr1(presult->ntpaddr[i].s_addr), - ip4_addr2(presult->ntpaddr[i].s_addr), - ip4_addr3(presult->ntpaddr[i].s_addr), - ip4_addr4(presult->ntpaddr[i].s_addr)); - } - } - - ninfo("Got default router %u.%u.%u.%u\n", - ip4_addr1(presult->default_router.s_addr), - ip4_addr2(presult->default_router.s_addr), - ip4_addr3(presult->default_router.s_addr), - ip4_addr4(presult->default_router.s_addr)); + ninfo("Got IP address %d.%d.%d.%d\n", + (int)((presult->ipaddr.s_addr) & 0xff), + (int)((presult->ipaddr.s_addr >> 8) & 0xff), + (int)((presult->ipaddr.s_addr >> 16) & 0xff), + (int)((presult->ipaddr.s_addr >> 24) & 0xff)); + ninfo("Got netmask %d.%d.%d.%d\n", + (int)((presult->netmask.s_addr) & 0xff), + (int)((presult->netmask.s_addr >> 8) & 0xff), + (int)((presult->netmask.s_addr >> 16) & 0xff), + (int)((presult->netmask.s_addr >> 24) & 0xff)); + ninfo("Got DNS server %d.%d.%d.%d\n", + (int)((presult->dnsaddr.s_addr) & 0xff), + (int)((presult->dnsaddr.s_addr >> 8) & 0xff), + (int)((presult->dnsaddr.s_addr >> 16) & 0xff), + (int)((presult->dnsaddr.s_addr >> 24) & 0xff)); + ninfo("Got default router %d.%d.%d.%d\n", + (int)((presult->default_router.s_addr) & 0xff), + (int)((presult->default_router.s_addr >> 8) & 0xff), + (int)((presult->default_router.s_addr >> 16) & 0xff), + (int)((presult->default_router.s_addr >> 24) & 0xff)); ninfo("Lease expires in %" PRId32 " seconds\n", presult->lease_time); return OK; } @@ -1069,127 +888,22 @@ int dhcpc_request_async(FAR void *handle, dhcpc_callback_t callback) if (!handle || !callback) { - errno = EINVAL; return ERROR; } if (pdhcpc->thread) { nerr("ERROR: DHCPC thread already running\n"); - errno = EALREADY; return ERROR; } pdhcpc->callback = callback; - pdhcpc->cancel = 0; ret = pthread_create(&pdhcpc->thread, NULL, dhcpc_run, pdhcpc); if (ret != 0) { nerr("ERROR: Failed to start the DHCPC thread\n"); - errno = ret; return ERROR; } return OK; } - -/**************************************************************************** - * Name: dhcpc_release - ****************************************************************************/ - -int dhcpc_release(FAR void *handle, FAR struct dhcpc_state *presult) -{ - FAR struct dhcpc_state_s *pdhcpc = (FAR struct dhcpc_state_s *)handle; - int ret; - int retries = 0; -#ifdef CONFIG_NETUTILS_DHCPC_RELEASE_CLEAR_IP - struct in_addr zero_addr; -#endif - - if (!handle || !presult) - { - errno = EINVAL; - return ERROR; - } - - /* Check that we have valid IP address and server ID to release */ - - if (presult->ipaddr.s_addr == 0 || presult->serverid.s_addr == 0) - { - errno = EINVAL; - return ERROR; - } - - /* Increment transaction ID for the release message */ - - pdhcpc->xid[3]++; - - /* Send DHCPRELEASE message to the server with retry mechanism. - * According to RFC 2131, no response is expected from the server. - */ - - for (; ; ) - { - ret = dhcpc_sendmsg(pdhcpc, presult, DHCPRELEASE); - if (ret > 0) - { - ninfo("DHCPRELEASE message sent successfully (%d bytes)\n", ret); - break; - } - else - { - retries++; - nerr("Failed send DHCPRELEASE (attempt %d/%d), ret=%d, errno=%d\n", - retries, CONFIG_NETUTILS_DHCPC_RELEASE_RETRIES, ret, errno); - - if (retries >= CONFIG_NETUTILS_DHCPC_RELEASE_RETRIES) - { - nerr("ERROR: Failed to send DHCPRELEASE after %d attempts\n", - CONFIG_NETUTILS_DHCPC_RELEASE_RETRIES); - return ERROR; - } - - usleep(1000 * CONFIG_NETUTILS_DHCPC_RELEASE_TRANSMISSION_DELAY_MS); - } - } - -#ifdef CONFIG_NETUTILS_DHCPC_RELEASE_ENSURE_TRANSMISSION - /* Ensure the DHCPRELEASE packet has time to be transmitted. - * Since DHCP RELEASE has no ACK response and UDP is connectionless, - * we use a delay to give the network stack time to actually send - * the packet before the function returns. - */ - - usleep(1000 * CONFIG_NETUTILS_DHCPC_RELEASE_TRANSMISSION_DELAY_MS); -#endif - -#ifdef CONFIG_NETUTILS_DHCPC_RELEASE_CLEAR_IP - /* Clear all network configuration that was obtained via DHCP */ - - zero_addr.s_addr = INADDR_ANY; - - ret = netlib_set_ipv4addr(pdhcpc->interface, &zero_addr); - if (ret < 0) - { - nwarn("Warning: Failed clear IP address from interface (errno=%d)\n", - errno); - } - - ret = netlib_set_ipv4netmask(pdhcpc->interface, &zero_addr); - if (ret < 0) - { - nwarn("Warning: Failed clear netmask from interface (errno=%d)\n", - errno); - } - - ret = netlib_set_dripv4addr(pdhcpc->interface, &zero_addr); - if (ret < 0) - { - nwarn("Warning: Failed clear gateway from interface (errno=%d)\n", - errno); - } -#endif - - ninfo("DHCP released successfully\n"); - return OK; -} diff --git a/netutils/dhcpd/CMakeLists.txt b/netutils/dhcpd/CMakeLists.txt deleted file mode 100644 index 5c859f230..000000000 --- a/netutils/dhcpd/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -# ############################################################################## -# apps/netutils/dhcpd/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_NETUTILS_DHCPD AND CONFIG_NET_UDP) - target_sources(apps PRIVATE dhcpd.c) -endif() diff --git a/netutils/dhcpd/Kconfig b/netutils/dhcpd/Kconfig index 0c1d0b24a..c595b079a 100644 --- a/netutils/dhcpd/Kconfig +++ b/netutils/dhcpd/Kconfig @@ -6,7 +6,7 @@ config NETUTILS_DHCPD bool "DHCP server" default n - depends on NET_UDP + depends on NET_UDP && NET_IPv4 ---help--- Enable support for the DHCP server. diff --git a/netutils/dhcpd/Make.defs b/netutils/dhcpd/Make.defs index 7b676ed33..2d5da4562 100644 --- a/netutils/dhcpd/Make.defs +++ b/netutils/dhcpd/Make.defs @@ -1,8 +1,5 @@ -############################################################################ # apps/netutils/dhcpd/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -20,6 +17,6 @@ # ############################################################################ -ifneq ($(CONFIG_NETUTILS_DHCPD),) +ifeq ($(CONFIG_NETUTILS_DHCPD),y) CONFIGURED_APPS += $(APPDIR)/netutils/dhcpd endif diff --git a/netutils/dhcpd/Makefile b/netutils/dhcpd/Makefile index 41e2f971c..be43f4209 100644 --- a/netutils/dhcpd/Makefile +++ b/netutils/dhcpd/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/netutils/dhcpd/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/netutils/dhcpd/dhcpd.c b/netutils/dhcpd/dhcpd.c index 5d909a2e6..31e26904f 100644 --- a/netutils/dhcpd/dhcpd.c +++ b/netutils/dhcpd/dhcpd.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/netutils/dhcpd/dhcpd.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -40,17 +38,15 @@ # define OK (0) #else # include /* NuttX configuration */ -# include /* For nerr, info */ +# include /* For nerr, info */ # include /* For CONFIG_CPP_HAVE_WARNING */ # include "netutils/dhcpd.h" /* Advertised DHCPD APIs */ #endif #include #include -#include #include -#include #include #include #include @@ -191,8 +187,6 @@ # define HAVE_LEASE_TIME 1 #endif -#define g_state (*g_dhcpd_daemon.ds_data) - /**************************************************************************** * Private Types ****************************************************************************/ @@ -276,24 +270,10 @@ struct dhcpd_state_s struct dhcpd_daemon_s { - uint8_t ds_state; /* See enum dhcpd_daemon_e */ - pid_t ds_pid; /* Task ID of the DHCPD daemon */ - FAR struct dhcpd_state_s *ds_data; /* DHCPD daemon data */ -}; - -struct dhcpd_config_s -{ - in_addr_t ds_startip; - in_addr_t ds_endip; -#ifdef HAVE_ROUTERIP - in_addr_t ds_routerip; -#endif -#ifdef HAVE_NETMASK - in_addr_t ds_netmask; -#endif -#ifdef HAVE_DNSIP - in_addr_t ds_dnsip; -#endif + uint8_t ds_state; /* See enum dhcpd_daemon_e */ + sem_t ds_lock; /* Used to protect the whole structure */ + sem_t ds_sync; /* Used to synchronize start and stop events */ + pid_t ds_pid; /* Task ID of the DHCPD daemon */ }; /**************************************************************************** @@ -305,6 +285,8 @@ static const uint8_t g_magiccookie[4] = 99, 130, 83, 99 }; +static struct dhcpd_state_s g_state; + /* This type describes the state of the DHCPD client daemon. Only one * instance of the DHCPD daemon is permitted in this implementation. This * limitation is due only to this global data structure. @@ -313,23 +295,9 @@ static const uint8_t g_magiccookie[4] = static struct dhcpd_daemon_s g_dhcpd_daemon = { DHCPD_NOT_RUNNING, - -1, - NULL -}; - -static struct dhcpd_config_s g_dhcpd_config = -{ - CONFIG_NETUTILS_DHCPD_STARTIP, - CONFIG_NETUTILS_DHCP_OPTION_ENDIP, -#ifdef HAVE_ROUTERIP - CONFIG_NETUTILS_DHCPD_ROUTERIP, -#endif -#ifdef HAVE_NETMASK - CONFIG_NETUTILS_DHCPD_NETMASK, -#endif -#ifdef HAVE_DNSIP - CONFIG_NETUTILS_DHCPD_DNSIP -#endif + SEM_INITIALIZER(1), + SEM_INITIALIZER(0), + -1 }; /**************************************************************************** @@ -340,8 +308,7 @@ static struct dhcpd_config_s g_dhcpd_config = * Name: dhcpd_arpupdate ****************************************************************************/ -#ifndef CONFIG_NETUTILS_DHCPD_IGNOREBROADCAST -# ifndef CONFIG_NETUTILS_DHCPD_HOST +#ifndef CONFIG_NETUTILS_DHCPD_HOST static inline void dhcpd_arpupdate(FAR uint8_t *ipaddr, FAR uint8_t *hwaddr) { struct sockaddr_in inaddr; @@ -356,11 +323,10 @@ static inline void dhcpd_arpupdate(FAR uint8_t *ipaddr, FAR uint8_t *hwaddr) /* Update the ARP table */ - netlib_set_arpmapping(&inaddr, hwaddr, NULL); + netlib_set_arpmapping(&inaddr, hwaddr); } -# else -# define dhcpd_arpupdate(ipaddr,hwaddr) -# endif +#else +# define dhcpd_arpupdate(ipaddr,hwaddr) #endif /**************************************************************************** @@ -368,7 +334,7 @@ static inline void dhcpd_arpupdate(FAR uint8_t *ipaddr, FAR uint8_t *hwaddr) ****************************************************************************/ #ifdef CONFIG_NETUTILS_DHCPD_HOST -# define dhcpd_time() time(0) +# define dhcpd_time() time(0) #elif defined(HAVE_LEASE_TIME) static time_t dhcpd_time(void) { @@ -383,7 +349,7 @@ static time_t dhcpd_time(void) return ret; } #else -# define dhcpd_time() (0) +# define dhcpd_time() (0) #endif /**************************************************************************** @@ -404,7 +370,7 @@ static inline bool dhcpd_leaseexpired(struct lease_s *lease) } } #else -# define dhcpd_leaseexpired(lease) (false) +# define dhcpd_leaseexpired(lease) (false) #endif /**************************************************************************** @@ -418,11 +384,11 @@ struct lease_s *dhcpd_setlease(const uint8_t *mac, * ipaddr must be in host order! */ - int ndx = ipaddr - g_dhcpd_config.ds_startip; + int ndx = ipaddr - CONFIG_NETUTILS_DHCPD_STARTIP; struct lease_s *ret = NULL; ninfo("ipaddr: %08" PRIx32 " ipaddr: %08" PRIx32 " ndx: %d MAX: %d\n", - (uint32_t)ipaddr, (uint32_t)g_dhcpd_config.ds_startip, ndx, + (uint32_t)ipaddr, (uint32_t)CONFIG_NETUTILS_DHCPD_STARTIP, ndx, CONFIG_NETUTILS_DHCPD_MAXLEASES); /* Verify that the address offset is within the supported range */ @@ -449,7 +415,7 @@ static inline in_addr_t dhcp_leaseipaddr(FAR struct lease_s *lease) /* Return IP address in host order */ return (in_addr_t)(lease - g_state.ds_leases) + - g_dhcpd_config.ds_startip; + CONFIG_NETUTILS_DHCPD_STARTIP; } /**************************************************************************** @@ -477,11 +443,11 @@ static FAR struct lease_s *dhcpd_findbymac(FAR const uint8_t *mac) static FAR struct lease_s *dhcpd_findbyipaddr(in_addr_t ipaddr) { - if (ipaddr >= g_dhcpd_config.ds_startip && - ipaddr <= g_dhcpd_config.ds_endip) + if (ipaddr >= CONFIG_NETUTILS_DHCPD_STARTIP && + ipaddr <= CONFIG_NETUTILS_DHCP_OPTION_ENDIP) { FAR struct lease_s *lease = - &g_state.ds_leases[ipaddr - g_dhcpd_config.ds_startip]; + &g_state.ds_leases[ipaddr - CONFIG_NETUTILS_DHCPD_STARTIP]; if (lease->allocated > 0) { return lease; @@ -500,8 +466,8 @@ static in_addr_t dhcpd_allocipaddr(void) struct lease_s *lease = NULL; in_addr_t ipaddr, startaddr; - ipaddr = startaddr = g_dhcpd_config.ds_startip; - for (; ipaddr <= g_dhcpd_config.ds_endip; ipaddr++) + ipaddr = startaddr = CONFIG_NETUTILS_DHCPD_STARTIP; + for (; ipaddr <= CONFIG_NETUTILS_DHCP_OPTION_ENDIP; ipaddr++) { /* Skip over address ending in 0 or 255 */ @@ -661,7 +627,7 @@ static inline bool dhcpd_parseoptions(void) if (optlen >= 6 && optlen < remaining) { memcpy(&tmp, &ptr[DHCPD_OPTION_DATA], 4); - g_state.ds_optleasetime = ntohl(tmp); + g_state.ds_optleasetime = (time_t)ntohl(tmp); } break; @@ -712,8 +678,8 @@ static inline bool dhcpd_verifyreqip(void) * range */ - if (g_state.ds_optreqip >= g_dhcpd_config.ds_startip && - g_state.ds_optreqip <= g_dhcpd_config.ds_endip) + if (g_state.ds_optreqip >= CONFIG_NETUTILS_DHCPD_STARTIP && + g_state.ds_optreqip <= CONFIG_NETUTILS_DHCP_OPTION_ENDIP) { /* And verify that the lease has not already been taken or offered * (unless the lease/offer is expired, then the address is free game). @@ -898,17 +864,17 @@ static inline int dhcpd_socket(FAR const char *interface) } #endif -#ifdef CONFIG_NET_BINDTODEVICE +#ifdef CONFIG_NET_UDP_BINDTODEVICE /* Bind socket to interface, because UDP packets have to be sent to the * broadcast address at a moment when it is not possible to decide the * target network device using the local or remote address (which is, * by definition and purpose of DHCP, undefined yet). */ - if (setsockopt(sockfd, SOL_SOCKET, SO_BINDTODEVICE, + if (setsockopt(sockfd, IPPROTO_UDP, UDP_BINDTODEVICE, interface, strlen(interface)) < 0) { - ninfo("ERROR: setsockopt SO_BINDTODEVICE failed: %d\n", errno); + ninfo("ERROR: setsockopt UDP_BINDTODEVICE failed: %d\n", errno); close(sockfd); return ERROR; } @@ -1016,7 +982,7 @@ static int dhcpd_sendpacket(int sockfd, int bbroadcast) #endif /* Create a socket to respond with a packet to the client. We - * cannot reuse the listener socket because it is not bound correctly + * cannot re-use the listener socket because it is not bound correctly */ /* Then send the response to the DHCP client port at that address */ @@ -1046,7 +1012,7 @@ static inline int dhcpd_sendoffer(int sockfd, in_addr_t ipaddr, in_addr_t netaddr; #ifdef HAVE_DNSIP uint32_t dnsaddr; - dnsaddr = htonl(g_dhcpd_config.ds_dnsip); + dnsaddr = htonl(CONFIG_NETUTILS_DHCPD_DNSIP); #endif /* IP address is in host order */ @@ -1066,11 +1032,11 @@ static inline int dhcpd_sendoffer(int sockfd, in_addr_t ipaddr, dhcpd_addoption32(DHCP_OPTION_LEASE_TIME, htonl(leasetime)); #ifdef HAVE_NETMASK dhcpd_addoption32(DHCP_OPTION_SUBNET_MASK, - htonl(g_dhcpd_config.ds_netmask)); + htonl(CONFIG_NETUTILS_DHCPD_NETMASK)); #endif #ifdef HAVE_ROUTERIP dhcpd_addoption32(DHCP_OPTION_ROUTER, - htonl(g_dhcpd_config.ds_routerip)); + htonl(CONFIG_NETUTILS_DHCPD_ROUTERIP)); #endif #ifdef HAVE_DNSIP dhcp_addoption32p(DHCP_OPTION_DNS_SERVER, (FAR uint8_t *)&dnsaddr); @@ -1108,7 +1074,7 @@ int dhcpd_sendack(int sockfd, in_addr_t ipaddr) in_addr_t netaddr; #ifdef HAVE_DNSIP uint32_t dnsaddr; - dnsaddr = htonl(g_dhcpd_config.ds_dnsip); + dnsaddr = htonl(CONFIG_NETUTILS_DHCPD_DNSIP); #endif /* Initialize the ACK response */ @@ -1130,11 +1096,11 @@ int dhcpd_sendack(int sockfd, in_addr_t ipaddr) dhcpd_addoption32(DHCP_OPTION_LEASE_TIME, htonl(leasetime)); #ifdef HAVE_NETMASK dhcpd_addoption32(DHCP_OPTION_SUBNET_MASK, - htonl(g_dhcpd_config.ds_netmask)); + htonl(CONFIG_NETUTILS_DHCPD_NETMASK)); #endif #ifdef HAVE_ROUTERIP dhcpd_addoption32(DHCP_OPTION_ROUTER, - htonl(g_dhcpd_config.ds_routerip)); + htonl(CONFIG_NETUTILS_DHCPD_ROUTERIP)); #endif #ifdef HAVE_DNSIP dhcp_addoption32p(DHCP_OPTION_DNS_SERVER, (FAR uint8_t *)&dnsaddr); @@ -1350,8 +1316,8 @@ static inline int dhcpd_request(int sockfd) * maybe requested before the last shutdown, lease again. */ - else if (g_state.ds_optreqip >= g_dhcpd_config.ds_startip && - g_state.ds_optreqip <= g_dhcpd_config.ds_endip) + else if (g_state.ds_optreqip >= CONFIG_NETUTILS_DHCPD_STARTIP && + g_state.ds_optreqip <= CONFIG_NETUTILS_DHCP_OPTION_ENDIP) { ipaddr = g_state.ds_optreqip; response = DHCPACK; @@ -1404,7 +1370,7 @@ static inline int dhcpd_decline(void) lease = dhcpd_findbymac(g_state.ds_inpacket.chaddr); if (lease) { - /* Disassociate the IP from the MAC, but prevent reused of this + /* Disassociate the IP from the MAC, but prevent re-used of this * address for a period of time. */ @@ -1456,7 +1422,7 @@ static inline int dhcpd_openlistener(FAR const char *interface) /* Get the IP address of the selected device */ - strlcpy(req.ifr_name, interface, IFNAMSIZ); + strncpy(req.ifr_name, interface, IFNAMSIZ); ret = ioctl(sockfd, SIOCGIFADDR, (unsigned long)&req); if (ret < 0) { @@ -1494,76 +1460,10 @@ static inline int dhcpd_openlistener(FAR const char *interface) * Name: dhcpd_task_run ****************************************************************************/ -#ifndef CONFIG_BUILD_KERNEL static int dhcpd_task_run(int argc, char **argv) { return dhcpd_run(argv[1]); } -#endif - -/**************************************************************************** - * Name: dhcpd_get_pid - * - * Description: - * Use /proc filesystem to get dhcpd process PID - * - * Returned Value: - * PID of dhcpd process on success, -1 on failure - * - ****************************************************************************/ - -#if !defined(CONFIG_BUILD_KERNEL) || defined(CONFIG_SCHED_WAITPID) -static pid_t dhcpd_get_pid(void) -{ - pid_t pid = -1; - -#if !defined(CONFIG_BUILD_KERNEL) - pid = g_dhcpd_daemon.ds_pid; -#elif defined(CONFIG_SYSTEM_POPEN) - FAR FILE *fp; - char line[32]; - - fp = popen(("pidof dhcpd"), "r"); - if (fp == NULL) - { - return -errno; - } - - if (fgets(line, sizeof(line), fp) != NULL) - { - pid = atoi(line); - } - - pclose(fp); -#endif - - return pid; -} -#endif - -/**************************************************************************** - * Name: dhcpd_signal_handler - * - * Description: - * Signal handler for CONFIG_NETUTILS_DHCPD_SIGWAKEUP - * This function allows dhcpd_stop to terminate dhcpd daemon - * - * Input Parameters: - * signo - Signal number - * info - Signal information - * ctx - Signal context - * - ****************************************************************************/ - -#ifdef CONFIG_ENABLE_ALL_SIGNALS -static void -dhcpd_signal_handler(int signo, FAR siginfo_t *info, FAR void *ctx) -{ - /* Set global flag to indicate stop request */ - - g_dhcpd_daemon.ds_state = DHCPD_STOP_REQUESTED; -} -#endif /**************************************************************************** * Public Functions @@ -1575,10 +1475,7 @@ dhcpd_signal_handler(int signo, FAR siginfo_t *info, FAR void *ctx) int dhcpd_run(FAR const char *interface) { -#ifdef CONFIG_ENABLE_ALL_SIGNALS - struct sigaction act; -#endif - int sockfd = -1; + int sockfd; int nbytes; ninfo("Started\n"); @@ -1590,34 +1487,23 @@ int dhcpd_run(FAR const char *interface) return OK; } - /* Initialize everything to zero */ - - g_dhcpd_daemon.ds_data = malloc(sizeof(struct dhcpd_state_s)); - if (g_dhcpd_daemon.ds_data == NULL) - { - return -ENOMEM; - } - - memset(g_dhcpd_daemon.ds_data, 0, sizeof(struct dhcpd_state_s)); - /* Update the pid if running in daemon mode */ g_dhcpd_daemon.ds_pid = getpid(); - /* Install signal handler for CONFIG_NETUTILS_DHCPD_SIGWAKEUP */ - -#ifdef CONFIG_ENABLE_ALL_SIGNALS - memset(&act, 0, sizeof(act)); - act.sa_sigaction = dhcpd_signal_handler; - act.sa_flags = SA_SIGINFO; - sigaction(CONFIG_NETUTILS_DHCPD_SIGWAKEUP, &act, NULL); -#endif /* Indicate that we have started */ g_dhcpd_daemon.ds_state = DHCPD_RUNNING; + sem_post(&g_dhcpd_daemon.ds_sync); + + /* Initialize everything to zero */ + + memset(&g_state, 0, sizeof(struct dhcpd_state_s)); + /* Now loop indefinitely, reading packets from the DHCP server socket */ + sockfd = -1; while (g_dhcpd_daemon.ds_state != DHCPD_STOP_REQUESTED) { /* Create a socket to listen for requests from DHCP clients */ @@ -1698,10 +1584,9 @@ int dhcpd_run(FAR const char *interface) } } - free(g_dhcpd_daemon.ds_data); - g_dhcpd_daemon.ds_data = NULL; g_dhcpd_daemon.ds_pid = -1; g_dhcpd_daemon.ds_state = DHCPD_STOPPED; + sem_post(&g_dhcpd_daemon.ds_sync); return OK; } @@ -1718,7 +1603,6 @@ int dhcpd_run(FAR const char *interface) * ****************************************************************************/ -#ifndef CONFIG_BUILD_KERNEL int dhcpd_start(FAR const char *interface) { FAR char *argv[2]; @@ -1729,13 +1613,17 @@ int dhcpd_start(FAR const char *interface) /* Is the DHCPD in a non-running state? */ - if (dhcpd_get_pid() < 0) + sem_wait(&g_dhcpd_daemon.ds_lock); + if (g_dhcpd_daemon.ds_state == DHCPD_NOT_RUNNING || + g_dhcpd_daemon.ds_state == DHCPD_STOPPED) { /* Start the DHCPD daemon */ - pid = task_create("dhcpd", CONFIG_NETUTILS_DHCPD_PRIORITY, - CONFIG_NETUTILS_DHCPD_STACKSIZE, dhcpd_task_run, - argv); + g_dhcpd_daemon.ds_state = DHCPD_STARTED; + pid = + task_create("DHCPD daemon", CONFIG_NETUTILS_DHCPD_PRIORITY, + CONFIG_NETUTILS_DHCPD_STACKSIZE, dhcpd_task_run, + argv); /* Handle failures to start the DHCPD daemon */ @@ -1743,14 +1631,24 @@ int dhcpd_start(FAR const char *interface) { int errval = errno; + g_dhcpd_daemon.ds_state = DHCPD_STOPPED; nerr("ERROR: Failed to start the DHCPD daemon: %d\n", errval); + sem_post(&g_dhcpd_daemon.ds_lock); return -errval; } + + /* Wait for any daemon state change */ + + do + { + sem_wait(&g_dhcpd_daemon.ds_sync); + } + while (g_dhcpd_daemon.ds_state == DHCPD_STARTED); } + sem_post(&g_dhcpd_daemon.ds_lock); return OK; } -#endif /**************************************************************************** * Name: dhcpd_stop @@ -1764,108 +1662,43 @@ int dhcpd_start(FAR const char *interface) * ****************************************************************************/ -#ifdef CONFIG_SCHED_WAITPID int dhcpd_stop(void) { - pid_t pid; + int ret; /* Is the DHCPD in a running state? */ - pid = dhcpd_get_pid(); - if (pid >= 0) + sem_wait(&g_dhcpd_daemon.ds_lock); + if (g_dhcpd_daemon.ds_state == DHCPD_STARTED || + g_dhcpd_daemon.ds_state == DHCPD_RUNNING) { /* Yes.. request that the daemon stop. */ - if (kill(pid, CONFIG_NETUTILS_DHCPD_SIGWAKEUP) < 0) - { - nerr("ERROR: kill pid %d failed: %d\n", pid, errno); - return -errno; - } + g_dhcpd_daemon.ds_state = DHCPD_STOP_REQUESTED; - /* Wait for the DHCPD client to respond to the stop request */ + /* Wait for any daemon state change */ - if (waitpid(pid, NULL, 0) < 0) + do { - nerr("ERROR: waitpid failed: %d\n", errno); - return -errno; + /* Signal the DHCPD client */ + + ret = kill(g_dhcpd_daemon.ds_pid, + CONFIG_NETUTILS_DHCPD_SIGWAKEUP); + + if (ret < 0) + { + nerr("ERROR: kill pid %d failed: %d\n", + g_dhcpd_daemon.ds_pid, errno); + break; + } + + /* Wait for the DHCPD client to respond to the stop request */ + + sem_wait(&g_dhcpd_daemon.ds_sync); } + while (g_dhcpd_daemon.ds_state == DHCPD_STOP_REQUESTED); } + sem_post(&g_dhcpd_daemon.ds_lock); return OK; } -#endif - -/**************************************************************************** - * Name: dhcpd_set_startip - * - * Description: - * Set start IP for DHCPD - * - * Returned Value: - * OK - * - ****************************************************************************/ - -int dhcpd_set_startip(in_addr_t startip) -{ - g_dhcpd_config.ds_startip = startip; - g_dhcpd_config.ds_endip = startip + CONFIG_NETUTILS_DHCPD_MAXLEASES - 1; - return OK; -} - -#ifdef HAVE_ROUTERIP -/**************************************************************************** - * Name: dhcpd_set_routerip - * - * Description: - * Set Router IP for DHCPD - * - * Returned Value: - * OK - * - ****************************************************************************/ - -int dhcpd_set_routerip(in_addr_t routerip) -{ - g_dhcpd_config.ds_routerip = routerip; - return OK; -} -#endif - -#ifdef HAVE_NETMASK -/**************************************************************************** - * Name: dhcpd_set_netmask - * - * Description: - * Set Netmask for DHCPD - * - * Returned Value: - * OK - * - ****************************************************************************/ - -int dhcpd_set_netmask(in_addr_t netmask) -{ - g_dhcpd_config.ds_netmask = netmask; - return OK; -} -#endif - -#ifdef HAVE_DNSIP -/**************************************************************************** - * Name: dhcpd_set_dnsip - * - * Description: - * Set DNS for DHCPD - * - * Returned Value: - * OK - * - ****************************************************************************/ - -int dhcpd_set_dnsip(in_addr_t dnsip) -{ - g_dhcpd_config.ds_dnsip = dnsip; - return OK; -} -#endif diff --git a/netutils/discover/CMakeLists.txt b/netutils/discover/CMakeLists.txt deleted file mode 100644 index 32337dcbf..000000000 --- a/netutils/discover/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -# ############################################################################## -# apps/netutils/discover/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_NETUTILS_DISCOVER) - target_sources(apps PRIVATE discover.c) -endif() diff --git a/netutils/discover/Make.defs b/netutils/discover/Make.defs index 95a7a9b45..ba4287fea 100644 --- a/netutils/discover/Make.defs +++ b/netutils/discover/Make.defs @@ -1,8 +1,5 @@ -############################################################################ # apps/netutils/discover/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -20,6 +17,6 @@ # ############################################################################ -ifneq ($(CONFIG_NETUTILS_DISCOVER),) +ifeq ($(CONFIG_NETUTILS_DISCOVER),y) CONFIGURED_APPS += $(APPDIR)/netutils/discover endif diff --git a/netutils/discover/Makefile b/netutils/discover/Makefile index 43bd51b7c..e38c97571 100644 --- a/netutils/discover/Makefile +++ b/netutils/discover/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/netutils/discover/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/netutils/discover/README.md b/netutils/discover/README.md new file mode 100644 index 000000000..f5516a7e3 --- /dev/null +++ b/netutils/discover/README.md @@ -0,0 +1,8 @@ +# Network Utilities / `discover` + +This daemon is useful for discovering devices in local networks, especially with +DHCP configured devices. It listens for UDP broadcasts which also can include a +device class so that groups of devices can be discovered. It is also possible to +address all classes with a kind of broadcast discover. + +See `nuttx/tools/discover.py` for a client example. diff --git a/netutils/discover/discover.c b/netutils/discover/discover.c index ba11fbe87..a45699d75 100644 --- a/netutils/discover/discover.c +++ b/netutils/discover/discover.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/netutils/discover/discover.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -24,7 +22,7 @@ * Included Files ****************************************************************************/ -#include +#include #include #include #include @@ -138,7 +136,7 @@ static inline void discover_initresponse(void); * Private Functions ****************************************************************************/ -static inline void discover_initresponse(void) +static inline void discover_initresponse() { int chk = 0; int i; @@ -146,8 +144,8 @@ static inline void discover_initresponse(void) g_state.response[0] = DISCOVER_PROTO_ID; g_state.response[1] = DISCOVER_RESPONSE; - strlcpy((char *)&g_state.response[2], g_state.info.description, - DISCOVER_RESPONSE_SIZE - 2); + strncpy((char *) &g_state.response[2], g_state.info.description, + DISCOVER_RESPONSE_SIZE - 3); for (i = 0; i < DISCOVER_RESPONSE_SIZE - 1; i++) { @@ -163,7 +161,7 @@ static int discover_daemon(int argc, char *argv[]) { int sockfd = -1; int nbytes; - socklen_t addrlen = sizeof(struct sockaddr_in); + int addrlen = sizeof(struct sockaddr_in); struct sockaddr_in srcaddr; /* memset(&g_state, 0, sizeof(struct discover_state_s)); */ @@ -189,7 +187,8 @@ static int discover_daemon(int argc, char *argv[]) /* Read the next packet */ nbytes = recvfrom(sockfd, &g_state.request, sizeof(g_state.request), 0, - (struct sockaddr *)&srcaddr, &addrlen); + (struct sockaddr *) &srcaddr, + (socklen_t *) &addrlen); if (nbytes < 0) { /* On errors (other EINTR), close the socket and try again */ @@ -209,8 +208,7 @@ static int discover_daemon(int argc, char *argv[]) continue; } - ninfo("Received discover from %08" PRIx32 "\n", - srcaddr.sin_addr.s_addr); + ninfo("Received discover from %08lx'\n", srcaddr.sin_addr.s_addr); discover_respond(&srcaddr.sin_addr.s_addr); } @@ -285,7 +283,7 @@ static inline int discover_respond(in_addr_t *ipaddr) return ret; } -static inline int discover_socket(void) +static inline int discover_socket() { int sockfd; #if defined(HAVE_SO_REUSEADDR) || defined(HAVE_SO_BROADCAST) @@ -307,7 +305,7 @@ static inline int discover_socket(void) #ifdef HAVE_SO_REUSEADDR optval = 1; ret = setsockopt(sockfd, SOL_SOCKET, - SO_REUSEADDR, &optval, sizeof(int)); + SO_REUSEADDR, (void *)&optval, sizeof(int)); if (ret < 0) { nerr("ERROR: setsockopt SO_REUSEADDR failed: %d\n", errno); @@ -319,7 +317,7 @@ static inline int discover_socket(void) #ifdef HAVE_SO_BROADCAST optval = 1; ret = setsockopt(sockfd, SOL_SOCKET, - SO_BROADCAST, &optval, sizeof(int)); + SO_BROADCAST, (void *)&optval, sizeof(int)); if (ret < 0) { nerr("ERROR: setsockopt SO_BROADCAST failed: %d\n", errno); @@ -331,7 +329,7 @@ static inline int discover_socket(void) return sockfd; } -static inline int discover_openlistener(void) +static inline int discover_openlistener() { struct sockaddr_in addr; struct ifreq req; @@ -349,7 +347,7 @@ static inline int discover_openlistener(void) /* Get the IP address of the selected device */ - strlcpy(req.ifr_name, CONFIG_DISCOVER_INTERFACE, IFNAMSIZ); + strncpy(req.ifr_name, CONFIG_DISCOVER_INTERFACE, IFNAMSIZ); ret = ioctl(sockfd, SIOCGIFADDR, (unsigned long)&req); if (ret < 0) { @@ -359,7 +357,7 @@ static inline int discover_openlistener(void) } g_state.serverip = ((struct sockaddr_in *)&req.ifr_addr)->sin_addr.s_addr; - ninfo("serverip: %08" PRIx32 "\n", ntohl(g_state.serverip)); + ninfo("serverip: %08lx\n", ntohl(g_state.serverip)); /* Bind the socket to a local port. We have to bind to INADDRY_ANY to * receive broadcast messages. diff --git a/netutils/dropbear/.gitignore b/netutils/dropbear/.gitignore deleted file mode 100644 index 1dc4834a1..000000000 --- a/netutils/dropbear/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/dropbear -/*.zip -*.o -.built -.depend -Make.dep diff --git a/netutils/dropbear/CMakeLists.txt b/netutils/dropbear/CMakeLists.txt deleted file mode 100644 index c429a2a0d..000000000 --- a/netutils/dropbear/CMakeLists.txt +++ /dev/null @@ -1,256 +0,0 @@ -# ############################################################################## -# apps/netutils/dropbear/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_NETUTILS_DROPBEAR) - - set(DROPBEAR_COMMIT "${CONFIG_NETUTILS_DROPBEAR_COMMIT}") - string(REPLACE "\"" "" DROPBEAR_COMMIT "${DROPBEAR_COMMIT}") - - set(DROPBEAR_ZIP "${DROPBEAR_COMMIT}.zip") - set(DROPBEAR_URL "https://github.com/mkj/dropbear/archive") - set(DROPBEAR_UNPACKNAME "dropbear") - - if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${DROPBEAR_UNPACKNAME}") - if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${DROPBEAR_ZIP}") - message(STATUS "Downloading Dropbear: ${DROPBEAR_URL}/${DROPBEAR_ZIP}") - file(DOWNLOAD "${DROPBEAR_URL}/${DROPBEAR_ZIP}" - "${CMAKE_CURRENT_SOURCE_DIR}/${DROPBEAR_ZIP}") - endif() - message(STATUS "Unpacking Dropbear: ${DROPBEAR_ZIP}") - execute_process( - COMMAND unzip -q -o "${DROPBEAR_ZIP}" - WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" - RESULT_VARIABLE result) - if(result EQUAL 0) - file(RENAME "${CMAKE_CURRENT_SOURCE_DIR}/dropbear-${DROPBEAR_COMMIT}" - "${CMAKE_CURRENT_SOURCE_DIR}/${DROPBEAR_UNPACKNAME}") - execute_process( - COMMAND - patch -s -N -l -p1 -d "${DROPBEAR_UNPACKNAME}" -i - "${CMAKE_CURRENT_SOURCE_DIR}/patch/0001-guard-platform-declarations.patch" - WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") - execute_process( - COMMAND - patch -s -N -l -p1 -d "${DROPBEAR_UNPACKNAME}" -i - "${CMAKE_CURRENT_SOURCE_DIR}/patch/0002-use-nuttx-passwd-auth.patch" - WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") - execute_process( - COMMAND - patch -s -N -l -p1 -d "${DROPBEAR_UNPACKNAME}" -i - "${CMAKE_CURRENT_SOURCE_DIR}/patch/0003-allow-localoptions-to-override-tracking-malloc.patch" - WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") - execute_process( - COMMAND - patch -s -N -l -p1 -d "${DROPBEAR_UNPACKNAME}" -i - "${CMAKE_CURRENT_SOURCE_DIR}/patch/0004-use-nuttx-unused-macro.patch" - WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") - message(STATUS "Generating default_options_guard.h") - execute_process( - COMMAND - sh - "${CMAKE_CURRENT_SOURCE_DIR}/${DROPBEAR_UNPACKNAME}/src/ifndef_wrapper.sh" - INPUT_FILE - "${CMAKE_CURRENT_SOURCE_DIR}/${DROPBEAR_UNPACKNAME}/src/default_options.h" - OUTPUT_FILE - "${CMAKE_CURRENT_SOURCE_DIR}/${DROPBEAR_UNPACKNAME}/src/default_options_guard.h" - WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") - endif() - endif() - - set(PROGNAME "${CONFIG_NETUTILS_DROPBEAR_PROGNAME}") - string(REPLACE "\"" "" PROGNAME "${PROGNAME}") - - set(DROPBEAR_SRCS - dropbear_nshsession.c - port/nuttx_auth.c - port/dropbear_utils.c - dropbear/src/dbutil.c - dropbear/src/buffer.c - dropbear/src/dbhelpers.c - dropbear/src/bignum.c - dropbear/src/signkey.c - dropbear/src/dbrandom.c - dropbear/src/queue.c - dropbear/src/atomicio.c - dropbear/src/compat.c - dropbear/src/fake-rfc2553.c - dropbear/src/curve25519.c - dropbear/src/chachapoly.c - dropbear/src/ltc_prng.c - dropbear/src/ecc.c - dropbear/src/ecdsa.c - dropbear/src/crypto_desc.c - dropbear/src/dbmalloc.c - dropbear/src/gensignkey.c - dropbear/src/common-session.c - dropbear/src/packet.c - dropbear/src/common-algo.c - dropbear/src/common-kex.c - dropbear/src/common-channel.c - dropbear/src/common-chansession.c - dropbear/src/termcodes.c - dropbear/src/tcp-accept.c - dropbear/src/listener.c - dropbear/src/process-packet.c - dropbear/src/common-runopts.c - dropbear/src/circbuffer.c - dropbear/src/list.c - dropbear/src/netio.c - dropbear/src/gcm.c - dropbear/src/kex-x25519.c - dropbear/src/svr-kex.c - dropbear/src/svr-auth.c - dropbear/src/svr-authpasswd.c - dropbear/src/svr-session.c - dropbear/src/svr-service.c - dropbear/src/svr-runopts.c - dropbear/src/svr-tcpfwd.c - dropbear/src/svr-forward.c - dropbear/src/svr-streamfwd.c - dropbear/src/svr-authpam.c) - - file(GLOB LIBTOMMATH_SRCS CONFIGURE_DEPENDS - "${CMAKE_CURRENT_SOURCE_DIR}/dropbear/libtommath/*.c") - list(APPEND DROPBEAR_SRCS ${LIBTOMMATH_SRCS}) - - file(GLOB_RECURSE LIBTOMCRYPT_SRCS CONFIGURE_DEPENDS - "${CMAKE_CURRENT_SOURCE_DIR}/dropbear/libtomcrypt/src/*.c") - list(FILTER LIBTOMCRYPT_SRCS EXCLUDE REGEX ".*/prngs/sober128tab\\.c$") - - # Drop the bundled libtomcrypt HMAC modules replaced by the NuttX adapter. - list(FILTER LIBTOMCRYPT_SRCS EXCLUDE REGEX ".*/mac/hmac/hmac_init\\.c$") - list(FILTER LIBTOMCRYPT_SRCS EXCLUDE REGEX ".*/mac/hmac/hmac_process\\.c$") - list(FILTER LIBTOMCRYPT_SRCS EXCLUDE REGEX ".*/mac/hmac/hmac_done\\.c$") - list(APPEND DROPBEAR_SRCS port/dropbear_ltc_hmac_sha256.c) - - # Replace the bundled chacha20-poly1305 with the /dev/crypto adapter. - list(REMOVE_ITEM DROPBEAR_SRCS dropbear/src/chachapoly.c) - list(APPEND DROPBEAR_SRCS port/dropbear_chachapoly.c) - - list(APPEND DROPBEAR_SRCS ${LIBTOMCRYPT_SRCS}) - - if(CONFIG_NETUTILS_DROPBEAR_SCP) - list(APPEND DROPBEAR_SRCS dropbear/src/scpmisc.c port/nuttx_scp.c) - endif() - - nuttx_add_application( - NAME - ${PROGNAME} - SRCS - ${DROPBEAR_SRCS} - dropbear_main.c - STACKSIZE - ${CONFIG_NETUTILS_DROPBEAR_STACKSIZE} - PRIORITY - ${CONFIG_NETUTILS_DROPBEAR_PRIORITY} - DEPENDS - ${DROPBEAR_UNPACKNAME}) - - if(CONFIG_NETUTILS_DROPBEAR_SCP) - nuttx_add_application( - NAME - scp - SRCS - dropbear/src/scp.c - STACKSIZE - ${CONFIG_NETUTILS_DROPBEAR_SCP_STACKSIZE} - PRIORITY - ${CONFIG_NETUTILS_DROPBEAR_SCP_PRIORITY} - DEPENDS - ${DROPBEAR_UNPACKNAME}) - endif() - - target_include_directories( - ${PROGNAME} - PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} - ${CMAKE_CURRENT_SOURCE_DIR}/port - ${CMAKE_CURRENT_SOURCE_DIR}/dropbear - ${CMAKE_CURRENT_SOURCE_DIR}/dropbear/src - ${CMAKE_CURRENT_SOURCE_DIR}/dropbear/libtomcrypt/src/headers - ${CMAKE_CURRENT_SOURCE_DIR}/dropbear/libtommath - ${CMAKE_CURRENT_SOURCE_DIR}/../../nshlib) - - if(CONFIG_NETUTILS_DROPBEAR_SCP) - target_include_directories( - scp - PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/port - ${CMAKE_CURRENT_SOURCE_DIR}/dropbear - ${CMAKE_CURRENT_SOURCE_DIR}/dropbear/src) - endif() - - if(CONFIG_NETUTILS_DROPBEAR_COMPRESSION) - target_include_directories( - ${PROGNAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../system/zlib/zlib) - endif() - - target_compile_definitions( - ${PROGNAME} - PRIVATE LOCALOPTIONS_H_EXISTS=1 - DROPBEAR_NUTTX=1 - DROPBEAR_NUTTX_PASSWD=1 - base64_encode=dropbear_ltc_base64_encode - base64_decode=dropbear_ltc_base64_decode - ecc_make_key=dropbear_ltc_ecc_make_key) - - if(CONFIG_NETUTILS_DROPBEAR_SCP) - target_compile_definitions( - scp PRIVATE LOCALOPTIONS_H_EXISTS=1 DROPBEAR_NUTTX=1 - DROPBEAR_NUTTX_PASSWD=1) - endif() - - set_source_files_properties( - dropbear_nshsession.c - PROPERTIES COMPILE_DEFINITIONS - "Channel=dropbear_channel;ChanType=dropbear_chantype") - - if(CONFIG_NETUTILS_DROPBEAR_SCP) - set_source_files_properties( - dropbear/src/scp.c - PROPERTIES - COMPILE_DEFINITIONS - "xmalloc=dropbear_scp_xmalloc;xrealloc=dropbear_scp_xrealloc;xfree=dropbear_scp_xfree;execvp=dropbear_scp_execvp" - ) - set_source_files_properties( - dropbear/src/scpmisc.c - PROPERTIES - COMPILE_DEFINITIONS - "xmalloc=dropbear_scp_xmalloc;xrealloc=dropbear_scp_xrealloc;xfree=dropbear_scp_xfree" - ) - endif() - - # LTC_SOURCE must be set only for libtomcrypt sources. - set_source_files_properties(${LIBTOMCRYPT_SRCS} PROPERTIES COMPILE_DEFINITIONS - LTC_SOURCE=1) - - target_compile_options(${PROGNAME} PRIVATE -Wno-pointer-sign -Wno-format) - - if(CONFIG_NETUTILS_DROPBEAR_SCP) - target_compile_options( - scp - PRIVATE -Wno-pointer-sign -Wno-format -include - ${CMAKE_CURRENT_SOURCE_DIR}/port/nuttx_scp.h - -Wno-strict-prototypes) - endif() - - target_sources(apps PRIVATE ${DROPBEAR_SRCS}) - -endif() diff --git a/netutils/dropbear/Kconfig b/netutils/dropbear/Kconfig deleted file mode 100644 index 99066ee2e..000000000 --- a/netutils/dropbear/Kconfig +++ /dev/null @@ -1,157 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -menuconfig NETUTILS_DROPBEAR - tristate "Dropbear SSH server" - default n - depends on NET && NET_TCP - depends on !DISABLE_PSEUDOFS_OPERATIONS - depends on !DISABLE_PTHREAD - depends on SCHED_WAITPID - depends on SCHED_HAVE_PARENT - depends on SCHED_CHILD_STATUS - depends on NSH_LIBRARY - depends on FSUTILS_PASSWD - depends on PSEUDOTERM - depends on SERIAL - depends on DEV_URANDOM - depends on LIBC_NETDB - depends on LIBC_GAISTRERROR - depends on CRYPTO - depends on CRYPTO_RANDOM_POOL - depends on ALLOW_BSD_COMPONENTS - depends on CRYPTO_CRYPTODEV - depends on CRYPTO_CRYPTODEV_SOFTWARE_CRYPTO - ---help--- - Enable a minimal Dropbear SSH server port for NuttX. This initial - port is based on the ESP-IDF MCU test port and provides a single - foreground SSH server process with SSH sessions backed by NSH. - - The port computes the hmac-sha2-256 packet MAC through the NuttX - crypto device (/dev/crypto, CRYPTO_SHA2_256_HMAC) instead of the - bundled libtomcrypt implementation, which is dropped from the - build. The SHA-256 hash descriptor itself stays in the - application: Dropbear's key derivation clones partially-updated - hash states (hashkeys() in common-kex.c), which cannot be - represented by a kernel crypto session. - - The port also implements the chacha20-poly1305@openssh.com cipher - through the NuttX crypto device (/dev/crypto), using the - CRYPTO_CHACHA20_DJB and CRYPTO_POLY1305 algorithms instead of - the bundled libtomcrypt implementation, which is dropped from - the build. - -if NETUTILS_DROPBEAR - -config NETUTILS_DROPBEAR_STACKSIZE - int "Dropbear main stack size" - default 65536 - ---help--- - Stack size for the Dropbear server built-in. - This is architecture-specific, so adjust it according to your setup. - -config NETUTILS_DROPBEAR_PRIORITY - int "Dropbear main priority" - default 100 - -config NETUTILS_DROPBEAR_SHELL_PRIORITY - int "Dropbear NSH session priority" - default 100 - -config NETUTILS_DROPBEAR_PROGNAME - string "Dropbear program name" - default "dropbear" - ---help--- - This is the name of the program that will be used when the NSH ELF - program is installed. - -config NETUTILS_DROPBEAR_LISTEN_RETRIES - int "Dropbear listen retries" - default 0 - ---help--- - Number of times to retry listen setup when no listen socket could - be opened. Zero means to retry forever. - -config NETUTILS_DROPBEAR_LISTEN_RETRY_MAX - int "Dropbear maximum listen retry interval" - default 120 - range 1 3600 - ---help--- - Maximum number of seconds to wait between listen setup retries. - The retry delay starts at one second and doubles until it reaches - this value. - -config NETUTILS_DROPBEAR_SHELL_STACKSIZE - int "Dropbear NSH session task stack size" - default 8192 - -config NETUTILS_DROPBEAR_SCP - bool "Enable scp remote copy helper" - default y - depends on PIPES - ---help--- - Build Dropbear's scp program and allow SSH exec requests so a host - scp client can copy files to and from NuttX using the legacy scp - protocol. This does not build a full SSH client for initiating scp - transfers from the target. - -config NETUTILS_DROPBEAR_SCP_STACKSIZE - int "Dropbear scp stack size" - default 32768 - depends on NETUTILS_DROPBEAR_SCP - -config NETUTILS_DROPBEAR_SCP_PRIORITY - int "Dropbear scp priority" - default 100 - depends on NETUTILS_DROPBEAR_SCP - -config NETUTILS_DROPBEAR_PORT - int "Dropbear listen port" - default 2222 - -config NETUTILS_DROPBEAR_HOSTKEY_PATH - string "Dropbear ECDSA P-256 host key path" - default "/etc/dropbear/dropbear_ecdsa_host_key" - ---help--- - Path to the persistent ECDSA P-256 host key used by the Dropbear - server. The file is stored in Dropbear's native host key format. - -config NETUTILS_DROPBEAR_GENERATE_HOSTKEY - bool "Generate host key if missing" - default y - ---help--- - Pass -R so Dropbear generates an ECDSA P-256 host key on demand and - persists it at NETUTILS_DROPBEAR_HOSTKEY_PATH when it does not exist. - Product builds can disable this and provision the host key - externally (loaded with -r). - -config NETUTILS_DROPBEAR_COMPRESSION - bool "Enable SSH compression (zlib)" - default n - depends on LIB_ZLIB - ---help--- - Enable zlib compression for SSH sessions. Requires the zlib - library (LIB_ZLIB). When disabled, Dropbear is built with - DISABLE_ZLIB and negotiates no compression. - - WARNING: each session allocates a zlib deflate state of about - 256 KiB (DROPBEAR_ZLIB_WINDOW_BITS=15, DROPBEAR_ZLIB_MEM_LEVEL=8), - and the state is allocated even for the delayed zlib@openssh.com - method, right after key exchange. - -config NETUTILS_DROPBEAR_SYSLOG - bool "Log via syslog" - default n - ---help--- - Route Dropbear log messages through syslog(). When disabled, - Dropbear is built with DISABLE_SYSLOG. - -config NETUTILS_DROPBEAR_COMMIT - string "Dropbear upstream commit" - default "54ef47adf8c99b422be6a8f694f2866e62f88b9e" - ---help--- - Upstream Dropbear (mkj/dropbear) commit to download and build. - -endif diff --git a/netutils/dropbear/Make.defs b/netutils/dropbear/Make.defs deleted file mode 100644 index 9fcb635f7..000000000 --- a/netutils/dropbear/Make.defs +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# apps/netutils/dropbear/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -ifneq ($(CONFIG_NETUTILS_DROPBEAR),) -CONFIGURED_APPS += $(APPDIR)/netutils/dropbear -endif diff --git a/netutils/dropbear/Makefile b/netutils/dropbear/Makefile deleted file mode 100644 index f36398088..000000000 --- a/netutils/dropbear/Makefile +++ /dev/null @@ -1,205 +0,0 @@ -############################################################################ -# apps/netutils/dropbear/Makefile -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. The -# ASF licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the -# License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -############################################################################ - -include $(APPDIR)/Make.defs - -ifneq ($(CONFIG_NETUTILS_DROPBEAR),) - -DROPBEAR_COMMIT = $(patsubst "%",%,$(strip $(CONFIG_NETUTILS_DROPBEAR_COMMIT))) -DROPBEAR_ZIP = $(DROPBEAR_COMMIT).zip -DROPBEAR_UNPACKNAME = dropbear -DROPBEAR_URL = https://github.com/mkj/dropbear/archive -UNPACK ?= unzip -q -o -ifeq ($(CONFIG_HOST_MACOS),y) -PATCH ?= gpatch -else -PATCH ?= patch -endif - -MODULE = $(CONFIG_NETUTILS_DROPBEAR) -PROGNAME = $(CONFIG_NETUTILS_DROPBEAR_PROGNAME) -PRIORITY = $(CONFIG_NETUTILS_DROPBEAR_PRIORITY) -STACKSIZE = $(CONFIG_NETUTILS_DROPBEAR_STACKSIZE) - -ifneq ($(CONFIG_NETUTILS_DROPBEAR_SCP),) -PROGNAME += scp -PRIORITY += $(CONFIG_NETUTILS_DROPBEAR_SCP_PRIORITY) -STACKSIZE += $(CONFIG_NETUTILS_DROPBEAR_SCP_STACKSIZE) -endif - -CFLAGS += ${INCDIR_PREFIX}"$(APPDIR)$(DELIM)netutils$(DELIM)dropbear" -CFLAGS += ${INCDIR_PREFIX}"$(APPDIR)$(DELIM)netutils$(DELIM)dropbear$(DELIM)port" -CFLAGS += ${INCDIR_PREFIX}"$(APPDIR)$(DELIM)netutils$(DELIM)dropbear$(DELIM)dropbear" -CFLAGS += ${INCDIR_PREFIX}"$(APPDIR)$(DELIM)netutils$(DELIM)dropbear$(DELIM)dropbear$(DELIM)src" -CFLAGS += ${INCDIR_PREFIX}"$(APPDIR)$(DELIM)netutils$(DELIM)dropbear$(DELIM)dropbear$(DELIM)libtomcrypt$(DELIM)src$(DELIM)headers" -CFLAGS += ${INCDIR_PREFIX}"$(APPDIR)$(DELIM)netutils$(DELIM)dropbear$(DELIM)dropbear$(DELIM)libtommath" -CFLAGS += ${INCDIR_PREFIX}"$(APPDIR)$(DELIM)nshlib" - -ifneq ($(CONFIG_NETUTILS_DROPBEAR_COMPRESSION),) -CFLAGS += ${INCDIR_PREFIX}"$(APPDIR)$(DELIM)system$(DELIM)zlib$(DELIM)zlib" -endif - -CFLAGS += ${DEFINE_PREFIX}LOCALOPTIONS_H_EXISTS=1 -CFLAGS += ${DEFINE_PREFIX}DROPBEAR_NUTTX=1 -CFLAGS += ${DEFINE_PREFIX}DROPBEAR_NUTTX_PASSWD=1 -CFLAGS += -Wno-pointer-sign -Wno-format - -dropbear_nshsession.c_CFLAGS += ${DEFINE_PREFIX}Channel=dropbear_channel -dropbear_nshsession.c_CFLAGS += ${DEFINE_PREFIX}ChanType=dropbear_chantype - -CSRCS = dropbear_nshsession.c -CSRCS += port/nuttx_auth.c -CSRCS += port/dropbear_utils.c - -CSRCS += \ - dropbear/src/dbutil.c \ - dropbear/src/buffer.c \ - dropbear/src/dbhelpers.c \ - dropbear/src/bignum.c \ - dropbear/src/signkey.c \ - dropbear/src/dbrandom.c \ - dropbear/src/queue.c \ - dropbear/src/atomicio.c \ - dropbear/src/compat.c \ - dropbear/src/fake-rfc2553.c \ - dropbear/src/curve25519.c \ - dropbear/src/chachapoly.c \ - dropbear/src/ltc_prng.c \ - dropbear/src/ecc.c \ - dropbear/src/ecdsa.c \ - dropbear/src/crypto_desc.c \ - dropbear/src/dbmalloc.c \ - dropbear/src/gensignkey.c \ - dropbear/src/common-session.c \ - dropbear/src/packet.c \ - dropbear/src/common-algo.c \ - dropbear/src/common-kex.c \ - dropbear/src/common-channel.c \ - dropbear/src/common-chansession.c \ - dropbear/src/termcodes.c \ - dropbear/src/tcp-accept.c \ - dropbear/src/listener.c \ - dropbear/src/process-packet.c \ - dropbear/src/common-runopts.c \ - dropbear/src/circbuffer.c \ - dropbear/src/list.c \ - dropbear/src/netio.c \ - dropbear/src/gcm.c \ - dropbear/src/kex-x25519.c \ - dropbear/src/svr-kex.c \ - dropbear/src/svr-auth.c \ - dropbear/src/svr-authpasswd.c \ - dropbear/src/svr-session.c \ - dropbear/src/svr-service.c \ - dropbear/src/svr-runopts.c \ - dropbear/src/svr-tcpfwd.c \ - dropbear/src/svr-forward.c \ - dropbear/src/svr-streamfwd.c \ - dropbear/src/svr-authpam.c - -TOMMATH_SRCS = $(shell if [ -d "$(DROPBEAR_UNPACKNAME)/libtommath" ]; then find "$(DROPBEAR_UNPACKNAME)/libtommath" -name "*.c"; fi) -TOMCRYPT_SRCS = $(shell if [ -d "$(DROPBEAR_UNPACKNAME)/libtomcrypt/src" ]; then find "$(DROPBEAR_UNPACKNAME)/libtomcrypt/src" -name "*.c" ! -name "sober128tab.c"; fi) - -# Drop the bundled libtomcrypt HMAC modules replaced by the NuttX adapter. - -TOMCRYPT_SRCS := $(filter-out \ - %/mac/hmac/hmac_init.c \ - %/mac/hmac/hmac_process.c \ - %/mac/hmac/hmac_done.c, \ - $(TOMCRYPT_SRCS)) - -CSRCS += port/dropbear_ltc_hmac_sha256.c - -# Replace the bundled chacha20-poly1305 with the /dev/crypto adapter. - -CSRCS := $(filter-out dropbear/src/chachapoly.c,$(CSRCS)) -CSRCS += port/dropbear_chachapoly.c - -CSRCS += $(TOMMATH_SRCS) -CSRCS += $(TOMCRYPT_SRCS) - -ifneq ($(CONFIG_NETUTILS_DROPBEAR_SCP),) -CSRCS += dropbear/src/scpmisc.c -CSRCS += port/nuttx_scp.c -endif - -# Match the ESP-IDF port behavior: LTC_SOURCE is only for libtomcrypt sources. -$(foreach src,$(TOMCRYPT_SRCS),$(eval $(src)_CFLAGS += ${DEFINE_PREFIX}LTC_SOURCE=1)) - -# Avoid duplicate symbols when NuttX/apps also provide these APIs. -# Apply to all dropbear sources so libtomcrypt definitions and dropbear -# callers (e.g. signkey.c) use the same renamed symbols. -CFLAGS += ${DEFINE_PREFIX}base64_encode=dropbear_ltc_base64_encode -CFLAGS += ${DEFINE_PREFIX}base64_decode=dropbear_ltc_base64_decode -CFLAGS += ${DEFINE_PREFIX}ecc_make_key=dropbear_ltc_ecc_make_key - -MAINSRC = dropbear_main.c - -ifneq ($(CONFIG_NETUTILS_DROPBEAR_SCP),) -MAINSRC += dropbear/src/scp.c - -dropbear/src/scp.c_CFLAGS += ${DEFINE_PREFIX}xmalloc=dropbear_scp_xmalloc -dropbear/src/scp.c_CFLAGS += ${DEFINE_PREFIX}xrealloc=dropbear_scp_xrealloc -dropbear/src/scp.c_CFLAGS += ${DEFINE_PREFIX}xfree=dropbear_scp_xfree -dropbear/src/scp.c_CFLAGS += ${DEFINE_PREFIX}execvp=dropbear_scp_execvp -dropbear/src/scp.c_CFLAGS += -include port/nuttx_scp.h -dropbear/src/scp.c_CFLAGS += -Wno-strict-prototypes - -dropbear/src/scpmisc.c_CFLAGS += ${DEFINE_PREFIX}xmalloc=dropbear_scp_xmalloc -dropbear/src/scpmisc.c_CFLAGS += ${DEFINE_PREFIX}xrealloc=dropbear_scp_xrealloc -dropbear/src/scpmisc.c_CFLAGS += ${DEFINE_PREFIX}xfree=dropbear_scp_xfree -endif - -$(DROPBEAR_ZIP): - @echo "Downloading: $(DROPBEAR_ZIP)" - $(Q) curl -L -o $(DROPBEAR_ZIP) $(DROPBEAR_URL)/$(DROPBEAR_ZIP) - -$(DROPBEAR_UNPACKNAME): $(DROPBEAR_ZIP) - @echo "Unpacking: $(DROPBEAR_ZIP) -> $(DROPBEAR_UNPACKNAME)" - $(Q) $(UNPACK) $(DROPBEAR_ZIP) - $(Q) rm -rf $(DROPBEAR_UNPACKNAME) - $(Q) mv dropbear-$(DROPBEAR_COMMIT) $(DROPBEAR_UNPACKNAME) - @echo "Patching $(DROPBEAR_UNPACKNAME)" - $(Q) $(PATCH) -s -N -l -p1 -d $(DROPBEAR_UNPACKNAME) -i $(APPDIR)$(DELIM)netutils$(DELIM)dropbear$(DELIM)patch$(DELIM)0001-guard-platform-declarations.patch; true - $(Q) $(PATCH) -s -N -l -p1 -d $(DROPBEAR_UNPACKNAME) -i $(APPDIR)$(DELIM)netutils$(DELIM)dropbear$(DELIM)patch$(DELIM)0002-use-nuttx-passwd-auth.patch; true - $(Q) $(PATCH) -s -N -l -p1 -d $(DROPBEAR_UNPACKNAME) -i $(APPDIR)$(DELIM)netutils$(DELIM)dropbear$(DELIM)patch$(DELIM)0003-allow-localoptions-to-override-tracking-malloc.patch; true - $(Q) $(PATCH) -s -N -l -p1 -d $(DROPBEAR_UNPACKNAME) -i $(APPDIR)$(DELIM)netutils$(DELIM)dropbear$(DELIM)patch$(DELIM)0004-use-nuttx-unused-macro.patch; true - @echo "Generating default_options_guard.h" - $(Q) sh $(DROPBEAR_UNPACKNAME)$(DELIM)src$(DELIM)ifndef_wrapper.sh \ - < $(DROPBEAR_UNPACKNAME)$(DELIM)src$(DELIM)default_options.h \ - > $(DROPBEAR_UNPACKNAME)$(DELIM)src$(DELIM)default_options_guard.h - $(Q) touch $(DROPBEAR_UNPACKNAME) - -ifeq ($(wildcard $(DROPBEAR_UNPACKNAME)/.git),) -context:: $(DROPBEAR_UNPACKNAME) - -clean:: - $(call DELFILE, port$(DELIM)*.o) - -distclean:: - $(call DELDIR, $(DROPBEAR_UNPACKNAME)) - $(call DELFILE, $(DROPBEAR_ZIP)) -endif - -endif - -include $(APPDIR)/Application.mk diff --git a/netutils/dropbear/dropbear_main.c b/netutils/dropbear/dropbear_main.c deleted file mode 100644 index 798ba2b55..000000000 --- a/netutils/dropbear/dropbear_main.c +++ /dev/null @@ -1,329 +0,0 @@ -/**************************************************************************** - * apps/netutils/dropbear/dropbear_main.c - * - * SPDX-License-Identifier: Apache-2.0 - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include -#include -#include -#include - -#include "includes.h" -#include "algo.h" -#include "crypto_desc.h" -#define dropbear_main dropbear_multi_entry -#include "dbutil.h" -#undef dropbear_main -#include "dbrandom.h" -#include "netio.h" -#include "runopts.h" -#include "session.h" -#include "signkey.h" -#include "gensignkey.h" -#include "ssh.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define DROPBEAR_PORT_STRING_HELPER(n) #n -#define DROPBEAR_PORT_STRING(n) DROPBEAR_PORT_STRING_HELPER(n) - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -typedef void (*dropbear_exit_handler_t)(int exitcode, FAR const char *format, - va_list param) ATTRIB_NORETURN; - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static jmp_buf g_session_exit_jmp; -static int g_session_exitcode; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static void dropbear_session_exit(int exitcode, FAR const char *format, - va_list param) noreturn_function; -static void dropbear_session_exit(int exitcode, FAR const char *format, - va_list param) -{ - char exitmsg[150]; - char fullmsg[300]; - char fromaddr[60]; - int signal_pipe[2]; - - vsnprintf(exitmsg, sizeof(exitmsg), format, param); - - fromaddr[0] = '\0'; - - if (svr_ses.addrstring != NULL) - { - snprintf(fromaddr, sizeof(fromaddr), " from <%s>", svr_ses.addrstring); - } - - if (!ses.init_done) - { - snprintf(fullmsg, sizeof(fullmsg), "Early exit%s: %s", fromaddr, - exitmsg); - } - else if (ses.authstate.authdone) - { - snprintf(fullmsg, sizeof(fullmsg), "Exit (%s)%s: %s", - ses.authstate.pw_name, fromaddr, exitmsg); - } - else if (ses.authstate.pw_name != NULL) - { - snprintf(fullmsg, sizeof(fullmsg), - "Exit before auth%s: (user '%s', %u fails): %s", - fromaddr, ses.authstate.pw_name, ses.authstate.failcount, - exitmsg); - } - else - { - snprintf(fullmsg, sizeof(fullmsg), "Exit before auth%s: %s", fromaddr, - exitmsg); - } - - dropbear_log(LOG_INFO, "%s", fullmsg); - - signal_pipe[0] = ses.signal_pipe[0]; - signal_pipe[1] = ses.signal_pipe[1]; - session_cleanup(); - - if (signal_pipe[0] > STDERR_FILENO) - { - m_close(signal_pipe[0]); - } - - if (signal_pipe[1] > STDERR_FILENO && signal_pipe[1] != signal_pipe[0]) - { - m_close(signal_pipe[1]); - } - - memset(&ses, 0, sizeof(ses)); - memset(&svr_ses, 0, sizeof(svr_ses)); - - g_session_exitcode = exitcode; - longjmp(g_session_exit_jmp, 1); - - while (1) - { - } -} - -static void dropbear_setup(FAR const char *port) -{ - /* Load the host key with -r so it lives in the persistent (epoch 0) - * allocation rather than being created lazily inside a per-session malloc - * epoch (-R), which would free it when the first session ends and leave a - * dangling svr_opts.hostkey for the next connection. - */ - - FAR char *argv[] = - { - "dropbear", - "-F", - "-p", - (FAR char *)port, - "-r", - CONFIG_NETUTILS_DROPBEAR_HOSTKEY_PATH, - NULL - }; - - _dropbear_exit = svr_dropbear_exit; - _dropbear_log = svr_dropbear_log; - - disallow_core(); - svr_getopts(6, argv); - seedrandom(); - crypto_init(); - -#ifdef CONFIG_NETUTILS_DROPBEAR_GENERATE_HOSTKEY - /* Generate the ECDSA host key now if it is missing. signkey_generate() - * with skip_exist=1 silently succeeds when the file already exists. - */ - - if (signkey_generate(DROPBEAR_SIGNKEY_ECDSA_NISTP256, 0, - CONFIG_NETUTILS_DROPBEAR_HOSTKEY_PATH, 1) - == DROPBEAR_FAILURE) - { - dropbear_exit("failed to generate host key"); - } -#endif - - load_all_hostkeys(); - - if (dropbear_auth_initialize() < 0) - { - dropbear_exit("failed to initialize password auth"); - } -} - -static void dropbear_run_session(int childsock) -{ - dropbear_exit_handler_t saved_exit; - - saved_exit = _dropbear_exit; - _dropbear_exit = dropbear_session_exit; - - m_malloc_set_epoch(1); - - if (setjmp(g_session_exit_jmp) == 0) - { - svr_session(childsock, -1); - } - - m_malloc_free_epoch(1, 1); - m_malloc_set_epoch(0); - - _dropbear_exit = saved_exit; - - if (g_session_exitcode != EXIT_SUCCESS) - { - dropbear_log(LOG_WARNING, "session exited with status %d", - g_session_exitcode); - } -} - -static size_t dropbear_listen_sockets(FAR int *socks, size_t sockcount, - FAR int *maxfd) -{ - FAR char *errstring = NULL; - size_t sockpos = 0; - unsigned int i; - - for (i = 0; i < svr_opts.portcount; i++) - { - int nsock; - unsigned int n; - - nsock = dropbear_listen(svr_opts.addresses[i], svr_opts.ports[i], - &socks[sockpos], sockcount - sockpos, - &errstring, maxfd, svr_opts.interface); - - if (nsock < 0) - { - dropbear_log(LOG_WARNING, "failed listening on '%s': %s", - svr_opts.ports[i], - errstring != NULL ? errstring : "unknown error"); - m_free(errstring); - errstring = NULL; - continue; - } - - for (n = 0; n < (unsigned int)nsock; n++) - { - set_sock_priority(socks[sockpos + n], DROPBEAR_PRIO_LOWDELAY); - } - - sockpos += (size_t)nsock; - } - - return sockpos; -} - -static size_t dropbear_wait_listen_sockets(FAR int *socks, size_t sockcount, - FAR int *maxfd) -{ - int retries = 0; - int retry_delay = 1; - - while (1) - { - size_t count; - - *maxfd = -1; - count = dropbear_listen_sockets(socks, sockcount, maxfd); - - if (count > 0) - { - return count; - } - -#if CONFIG_NETUTILS_DROPBEAR_LISTEN_RETRIES > 0 - if (retries++ >= CONFIG_NETUTILS_DROPBEAR_LISTEN_RETRIES) - { - dropbear_exit("no listening ports available"); - } -#else - retries++; -#endif - - dropbear_log(LOG_WARNING, "Retry %d in %d seconds...", retries, - retry_delay); - sleep(retry_delay); - - retry_delay *= 2; - - if (retry_delay > CONFIG_NETUTILS_DROPBEAR_LISTEN_RETRY_MAX) - { - retry_delay = CONFIG_NETUTILS_DROPBEAR_LISTEN_RETRY_MAX; - } - } -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -int main(int argc, FAR char *argv[]) -{ - FAR const char *port = DROPBEAR_PORT_STRING(CONFIG_NETUTILS_DROPBEAR_PORT); - int listensocks[MAX_LISTEN_ADDR]; - int maxfd = -1; - - if (argc > 1) - { - port = argv[1]; - } - - dropbear_setup(port); - - dropbear_wait_listen_sockets(listensocks, MAX_LISTEN_ADDR, &maxfd); - - printf("dropbear: listening on port %s\n", port); - - while (1) - { - struct sockaddr_storage remoteaddr; - socklen_t remoteaddrlen = sizeof(remoteaddr); - FAR char *remote_host = NULL; - FAR char *remote_port = NULL; - int childsock; - - childsock = accept(listensocks[0], (FAR struct sockaddr *)&remoteaddr, - &remoteaddrlen); - - if (childsock < 0) - { - continue; - } - - getaddrstring(&remoteaddr, &remote_host, &remote_port, 0); - dropbear_log(LOG_INFO, "connection from %s:%s", - remote_host != NULL ? remote_host : "?", - remote_port != NULL ? remote_port : "?"); - m_free(remote_host); - m_free(remote_port); - - seedrandom(); - dropbear_run_session(childsock); - close(childsock); - } - - return EXIT_SUCCESS; -} diff --git a/netutils/dropbear/dropbear_nshsession.c b/netutils/dropbear/dropbear_nshsession.c deleted file mode 100644 index 0af7e68ea..000000000 --- a/netutils/dropbear/dropbear_nshsession.c +++ /dev/null @@ -1,829 +0,0 @@ -/**************************************************************************** - * apps/netutils/dropbear/dropbear_nshsession.c - * - * SPDX-License-Identifier: Apache-2.0 - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include "includes.h" -#include "channel.h" -#include "chansession.h" -#include "dbutil.h" -#include "session.h" - -#include "nsh.h" -#include "nsh_console.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -struct dropbear_nshsession_s -{ - int pty_readfd; - int pty_writefd; - pid_t nsh_pid; - volatile bool done; - pthread_t waiter; - bool waiter_started; - bool have_winsize; - bool has_pty; - struct winsize win; -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static int dropbear_nsh_main(int argc, FAR char *argv[]) -{ - FAR struct console_stdio_s *pstate; - int ret; - - pstate = nsh_newconsole(true); - if (pstate == NULL) - { - dropbear_log(LOG_WARNING, "failed to create NSH console"); - return -ENOMEM; - } - - ret = nsh_session(pstate, NSH_LOGIN_NONE, argc, argv); - dropbear_log(LOG_INFO, "NSH session exited: %d", ret); - - nsh_exit(&pstate->cn_vtbl, ret); - return ret; -} - -static FAR void *dropbear_nsh_waiter(FAR void *arg) -{ - FAR struct dropbear_nshsession_s *sess = arg; - unsigned char ch = 0; - int status; - int ret; - - ret = waitpid(sess->nsh_pid, &status, 0); - if (ret < 0) - { - dropbear_log(LOG_WARNING, "NSH session wait failed: %s", - strerror(errno)); - } - - sess->nsh_pid = -1; - sess->done = true; - - /* Match Dropbear's SIGCHLD wakeup path. The session loop checks channel - * close conditions when this pipe becomes readable. - */ - - if (ses.signal_pipe[1] >= 0) - { - write(ses.signal_pipe[1], &ch, sizeof(ch)); - } - - return NULL; -} - -static int dropbear_newchansess(FAR struct dropbear_channel *channel) -{ - FAR struct dropbear_nshsession_s *sess; - - sess = m_malloc(sizeof(*sess)); - memset(sess, 0, sizeof(*sess)); - sess->pty_readfd = -1; - sess->pty_writefd = -1; - sess->nsh_pid = -1; - - channel->typedata = sess; - channel->prio = DROPBEAR_PRIO_LOWDELAY; - return 0; -} - -static int dropbear_sesscheckclose(FAR struct dropbear_channel *channel) -{ - FAR struct dropbear_nshsession_s *sess = channel->typedata; - - return sess != NULL && sess->done; -} - -static int dropbear_setup_spawn_attrs(FAR posix_spawnattr_t *attr, - FAR const char **errmsg) -{ - struct sched_param param; - int rc; - - param.sched_priority = CONFIG_NETUTILS_DROPBEAR_SHELL_PRIORITY; - *errmsg = "spawn priority setup"; - rc = posix_spawnattr_setschedparam(attr, ¶m); - if (rc != 0) - { - return rc; - } - - *errmsg = "spawn stack setup"; - rc = posix_spawnattr_setstacksize( - attr, CONFIG_NETUTILS_DROPBEAR_SHELL_STACKSIZE); - if (rc != 0) - { - return rc; - } - - *errmsg = "spawn flags setup"; - return posix_spawnattr_setflags(attr, POSIX_SPAWN_SETSCHEDPARAM); -} - -static int -dropbear_setup_spawn_stdio(FAR posix_spawn_file_actions_t *actions, - int slavefd) -{ - static const int stdio_fds[] = - { - STDIN_FILENO, - STDOUT_FILENO, - STDERR_FILENO - }; - - int i; - int rc; - - for (i = 0; i < nitems(stdio_fds); i++) - { - rc = posix_spawn_file_actions_adddup2(actions, slavefd, stdio_fds[i]); - if (rc != 0) - { - return rc; - } - } - - return 0; -} - -#ifdef CONFIG_NETUTILS_DROPBEAR_SCP -static int -dropbear_setup_spawn_stdio3(FAR posix_spawn_file_actions_t *actions, - int stdinfd, int stdoutfd, int stderrfd) -{ - int rc; - - rc = posix_spawn_file_actions_adddup2(actions, stdinfd, STDIN_FILENO); - if (rc != 0) - { - return rc; - } - - rc = posix_spawn_file_actions_adddup2(actions, stdoutfd, STDOUT_FILENO); - if (rc != 0) - { - return rc; - } - - return posix_spawn_file_actions_adddup2(actions, stderrfd, STDERR_FILENO); -} -#endif /* CONFIG_NETUTILS_DROPBEAR_SCP */ - -static int -dropbear_setup_spawn_close(FAR posix_spawn_file_actions_t *actions, - int fd) -{ - if (fd <= STDERR_FILENO) - { - return 0; - } - - return posix_spawn_file_actions_addclose(actions, fd); -} - -static void dropbear_close_fd(FAR int *fd) -{ - if (*fd >= 0) - { - close(*fd); - *fd = -1; - } -} - -static int dropbear_start_nsh(FAR struct dropbear_channel *channel, - FAR struct dropbear_nshsession_s *sess) -{ - posix_spawn_file_actions_t actions; - posix_spawnattr_t attr; - FAR const char *errmsg; - int masterfd; - int slavefd; - int writefd; - int rc; - - if (sess->nsh_pid >= 0) - { - dropbear_log(LOG_WARNING, "NSH session already running"); - return DROPBEAR_FAILURE; - } - - rc = openpty(&masterfd, &slavefd, NULL, NULL, - sess->have_winsize ? &sess->win : NULL); - if (rc < 0) - { - dropbear_log(LOG_WARNING, "openpty failed: %s", strerror(errno)); - return DROPBEAR_FAILURE; - } - - writefd = dup(masterfd); - if (writefd < 0) - { - dropbear_log(LOG_WARNING, "pty dup failed: %s", strerror(errno)); - close(masterfd); - close(slavefd); - return DROPBEAR_FAILURE; - } - - rc = posix_spawn_file_actions_init(&actions); - if (rc != 0) - { - dropbear_log(LOG_WARNING, "spawn actions init failed: %s", - strerror(rc)); - close(masterfd); - close(writefd); - close(slavefd); - return DROPBEAR_FAILURE; - } - - rc = posix_spawnattr_init(&attr); - if (rc != 0) - { - dropbear_log(LOG_WARNING, "spawn attr init failed: %s", strerror(rc)); - goto err_with_actions; - } - - rc = dropbear_setup_spawn_attrs(&attr, &errmsg); - if (rc != 0) - { - dropbear_log(LOG_WARNING, "%s failed: %s", errmsg, strerror(rc)); - goto err_with_attr; - } - - rc = dropbear_setup_spawn_stdio(&actions, slavefd); - if (rc != 0) - { - dropbear_log(LOG_WARNING, "spawn stdio setup failed: %s", - strerror(rc)); - goto err_with_attr; - } - - rc = dropbear_setup_spawn_close(&actions, masterfd); - if (rc != 0) - { - dropbear_log(LOG_WARNING, "spawn master close setup failed: %s", - strerror(rc)); - goto err_with_attr; - } - - rc = dropbear_setup_spawn_close(&actions, writefd); - if (rc != 0) - { - dropbear_log(LOG_WARNING, "spawn write close setup failed: %s", - strerror(rc)); - goto err_with_attr; - } - - rc = dropbear_setup_spawn_close(&actions, slavefd); - if (rc != 0) - { - dropbear_log(LOG_WARNING, "spawn slave close setup failed: %s", - strerror(rc)); - goto err_with_attr; - } - - sess->nsh_pid = task_spawn("dropbear nsh", dropbear_nsh_main, &actions, - &attr, NULL, NULL); - if (sess->nsh_pid < 0) - { - dropbear_log(LOG_WARNING, "failed to create NSH task: %s", - strerror(-sess->nsh_pid)); - goto err_with_attr; - } - - close(slavefd); - slavefd = -1; - - rc = pthread_create(&sess->waiter, NULL, dropbear_nsh_waiter, sess); - if (rc != 0) - { - dropbear_log(LOG_WARNING, "failed to create NSH waiter: %s", - strerror(rc)); - close(masterfd); - close(writefd); - masterfd = -1; - writefd = -1; - kill(sess->nsh_pid, SIGTERM); - waitpid(sess->nsh_pid, NULL, 0); - sess->nsh_pid = -1; - goto err_with_attr; - } - - sess->waiter_started = true; - sess->has_pty = true; - sess->pty_readfd = masterfd; - sess->pty_writefd = writefd; - - channel->readfd = masterfd; - channel->writefd = writefd; - channel->bidir_fd = 0; - - setnonblocking(channel->readfd); - setnonblocking(channel->writefd); - ses.maxfd = MAX(ses.maxfd, channel->readfd); - ses.maxfd = MAX(ses.maxfd, channel->writefd); - - posix_spawnattr_destroy(&attr); - posix_spawn_file_actions_destroy(&actions); - - dropbear_log(LOG_INFO, "NSH PTY session started"); - return DROPBEAR_SUCCESS; - -err_with_attr: - posix_spawnattr_destroy(&attr); - -err_with_actions: - posix_spawn_file_actions_destroy(&actions); - - if (masterfd >= 0) - { - close(masterfd); - } - - if (writefd >= 0) - { - close(writefd); - } - - if (slavefd >= 0) - { - close(slavefd); - } - - sess->nsh_pid = -1; - return DROPBEAR_FAILURE; -} - -#ifdef CONFIG_NETUTILS_DROPBEAR_SCP -static int dropbear_start_exec(FAR struct dropbear_channel *channel, - FAR struct dropbear_nshsession_s *sess, - FAR char *cmd) -{ - posix_spawn_file_actions_t actions; - posix_spawnattr_t attr; - FAR const char *errmsg; - FAR char * const argv[] = - { - "-c", - cmd, - NULL - }; - - int inpipe[2] = - { - -1, - -1 - }; - - int outpipe[2] = - { - -1, - -1 - }; - - int errpipe[2] = - { - -1, - -1 - }; - - int rc; - - if (sess->nsh_pid >= 0) - { - dropbear_log(LOG_WARNING, "NSH exec already running"); - return DROPBEAR_FAILURE; - } - - if (pipe(inpipe) < 0 || pipe(outpipe) < 0 || pipe(errpipe) < 0) - { - dropbear_log(LOG_WARNING, "exec pipe setup failed: %s", - strerror(errno)); - goto err_with_pipes; - } - - rc = posix_spawn_file_actions_init(&actions); - if (rc != 0) - { - dropbear_log(LOG_WARNING, "spawn actions init failed: %s", - strerror(rc)); - goto err_with_pipes; - } - - rc = posix_spawnattr_init(&attr); - if (rc != 0) - { - dropbear_log(LOG_WARNING, "spawn attr init failed: %s", strerror(rc)); - goto err_with_actions; - } - - rc = dropbear_setup_spawn_attrs(&attr, &errmsg); - if (rc != 0) - { - dropbear_log(LOG_WARNING, "%s failed: %s", errmsg, strerror(rc)); - goto err_with_attr; - } - - rc = dropbear_setup_spawn_stdio3(&actions, inpipe[0], outpipe[1], - errpipe[1]); - if (rc != 0) - { - dropbear_log(LOG_WARNING, "spawn stdio setup failed: %s", - strerror(rc)); - goto err_with_attr; - } - - rc = dropbear_setup_spawn_close(&actions, inpipe[0]); - if (rc != 0) - { - dropbear_log(LOG_WARNING, "spawn stdin close setup failed: %s", - strerror(rc)); - goto err_with_attr; - } - - rc = dropbear_setup_spawn_close(&actions, inpipe[1]); - if (rc != 0) - { - dropbear_log(LOG_WARNING, "spawn stdin writer close setup failed: %s", - strerror(rc)); - goto err_with_attr; - } - - rc = dropbear_setup_spawn_close(&actions, outpipe[0]); - if (rc != 0) - { - dropbear_log(LOG_WARNING, "spawn stdout reader close setup failed: %s", - strerror(rc)); - goto err_with_attr; - } - - rc = dropbear_setup_spawn_close(&actions, outpipe[1]); - if (rc != 0) - { - dropbear_log(LOG_WARNING, "spawn stdout close setup failed: %s", - strerror(rc)); - goto err_with_attr; - } - - rc = dropbear_setup_spawn_close(&actions, errpipe[0]); - if (rc != 0) - { - dropbear_log(LOG_WARNING, "spawn stderr reader close setup failed: %s", - strerror(rc)); - goto err_with_attr; - } - - rc = dropbear_setup_spawn_close(&actions, errpipe[1]); - if (rc != 0) - { - dropbear_log(LOG_WARNING, "spawn stderr close setup failed: %s", - strerror(rc)); - goto err_with_attr; - } - - sess->nsh_pid = task_spawn("dropbear exec", dropbear_nsh_main, &actions, - &attr, argv, NULL); - if (sess->nsh_pid < 0) - { - dropbear_log(LOG_WARNING, "failed to create NSH exec task: %s", - strerror(-sess->nsh_pid)); - goto err_with_attr; - } - - dropbear_close_fd(&inpipe[0]); - dropbear_close_fd(&outpipe[1]); - dropbear_close_fd(&errpipe[1]); - - rc = pthread_create(&sess->waiter, NULL, dropbear_nsh_waiter, sess); - if (rc != 0) - { - dropbear_log(LOG_WARNING, "failed to create NSH exec waiter: %s", - strerror(rc)); - dropbear_close_fd(&inpipe[1]); - dropbear_close_fd(&outpipe[0]); - dropbear_close_fd(&errpipe[0]); - kill(sess->nsh_pid, SIGTERM); - waitpid(sess->nsh_pid, NULL, 0); - sess->nsh_pid = -1; - goto err_with_attr; - } - - sess->waiter_started = true; - sess->has_pty = false; - sess->pty_readfd = -1; - sess->pty_writefd = -1; - - channel->readfd = outpipe[0]; - channel->writefd = inpipe[1]; - channel->errfd = errpipe[0]; - channel->bidir_fd = 0; - - setnonblocking(channel->readfd); - setnonblocking(channel->writefd); - setnonblocking(channel->errfd); - ses.maxfd = MAX(ses.maxfd, channel->readfd); - ses.maxfd = MAX(ses.maxfd, channel->writefd); - ses.maxfd = MAX(ses.maxfd, channel->errfd); - - posix_spawnattr_destroy(&attr); - posix_spawn_file_actions_destroy(&actions); - - dropbear_log(LOG_INFO, "NSH exec started: %s", cmd); - return DROPBEAR_SUCCESS; - -err_with_attr: - posix_spawnattr_destroy(&attr); - -err_with_actions: - posix_spawn_file_actions_destroy(&actions); - -err_with_pipes: - dropbear_close_fd(&inpipe[0]); - dropbear_close_fd(&inpipe[1]); - dropbear_close_fd(&outpipe[0]); - dropbear_close_fd(&outpipe[1]); - dropbear_close_fd(&errpipe[0]); - dropbear_close_fd(&errpipe[1]); - sess->nsh_pid = -1; - return DROPBEAR_FAILURE; -} -#endif /* CONFIG_NETUTILS_DROPBEAR_SCP */ - -static void dropbear_parse_winsize(FAR struct dropbear_nshsession_s *sess) -{ - unsigned int cols = buf_getint(ses.payload); - unsigned int rows = buf_getint(ses.payload); - unsigned int width = buf_getint(ses.payload); - unsigned int height = buf_getint(ses.payload); - - sess->win.ws_col = cols; - sess->win.ws_row = rows; - sess->win.ws_xpixel = width; - sess->win.ws_ypixel = height; - sess->have_winsize = true; - - if (sess->pty_readfd >= 0) - { - ioctl(sess->pty_readfd, TIOCSWINSZ, (unsigned long)&sess->win); - } -} - -static int dropbear_handle_pty_req(FAR struct dropbear_nshsession_s *sess) -{ - unsigned int len; - FAR char *term; - FAR char *modes; - - term = buf_getstring(ses.payload, &len); - dropbear_parse_winsize(sess); - modes = buf_getstring(ses.payload, &len); - - m_free(term); - m_free(modes); - return DROPBEAR_SUCCESS; -} - -static int dropbear_signal_from_name(FAR const char *name) -{ - int i; - - for (i = 0; signames[i].name != NULL; i++) - { - if (strcmp(name, signames[i].name) == 0) - { - return signames[i].signal; - } - } - - return -EINVAL; -} - -static int dropbear_write_terminal_signal( - FAR struct dropbear_nshsession_s *sess, - int signo) -{ -#ifdef CONFIG_TTY_SIGINT - unsigned char ch; - ssize_t nwritten; - - if (signo == SIGINT && sess->has_pty && sess->pty_writefd >= 0) - { - ch = CONFIG_TTY_SIGINT_CHAR; - nwritten = write(sess->pty_writefd, &ch, sizeof(ch)); - if (nwritten == sizeof(ch)) - { - return DROPBEAR_SUCCESS; - } - - dropbear_log(LOG_WARNING, "SSH terminal INT failed: %s", - strerror(errno)); - return DROPBEAR_FAILURE; - } -#endif - - return DROPBEAR_FAILURE; -} - -static int dropbear_handle_signal(FAR struct dropbear_nshsession_s *sess) -{ - unsigned int len; - FAR char *name; - int signo; - int ret; - - name = buf_getstring(ses.payload, &len); - signo = dropbear_signal_from_name(name); - if (signo < 0) - { - dropbear_log(LOG_WARNING, "unsupported SSH signal '%s'", name); - m_free(name); - return DROPBEAR_FAILURE; - } - - ret = dropbear_write_terminal_signal(sess, signo); - if (ret == DROPBEAR_SUCCESS) - { - dropbear_log(LOG_INFO, "SSH signal '%s' sent to PTY", name); - m_free(name); - return DROPBEAR_SUCCESS; - } - - if (sess->nsh_pid <= 0) - { - dropbear_log(LOG_WARNING, "SSH signal '%s' has no NSH session", name); - m_free(name); - return DROPBEAR_FAILURE; - } - - ret = kill(sess->nsh_pid, signo); - if (ret < 0) - { - dropbear_log(LOG_WARNING, "SSH signal '%s' failed: %s", - name, strerror(errno)); - m_free(name); - return DROPBEAR_FAILURE; - } - - dropbear_log(LOG_INFO, "SSH signal '%s' sent to NSH session", name); - m_free(name); - return DROPBEAR_SUCCESS; -} - -static void dropbear_chansessionrequest(FAR struct dropbear_channel *channel) -{ - unsigned int typelen; - FAR char *type = buf_getstring(ses.payload, &typelen); - unsigned char wantreply = buf_getbool(ses.payload); - FAR struct dropbear_nshsession_s *sess = channel->typedata; - int ret = DROPBEAR_FAILURE; - - TRACE(("dropbear_chansessionrequest: type='%s'", type)) - - if (strcmp(type, "pty-req") == 0) - { - ret = dropbear_handle_pty_req(sess); - } - else if (strcmp(type, "shell") == 0) - { - ret = dropbear_start_nsh(channel, sess); - } - else if (strcmp(type, "exec") == 0) - { -#ifdef CONFIG_NETUTILS_DROPBEAR_SCP - unsigned int cmdlen; - FAR char *cmd; - - cmd = buf_getstring(ses.payload, &cmdlen); - ret = dropbear_start_exec(channel, sess, cmd); - m_free(cmd); -#else - dropbear_log(LOG_WARNING, "SSH exec requests are not supported"); -#endif - } - else if (strcmp(type, "window-change") == 0) - { - dropbear_parse_winsize(sess); - ret = DROPBEAR_SUCCESS; - } - else if (strcmp(type, "signal") == 0) - { - ret = dropbear_handle_signal(sess); - } - else if (strcmp(type, "break") == 0) - { - ret = DROPBEAR_SUCCESS; - } - else - { - TRACE(("dropbear_chansessionrequest: unhandled type '%s'", type)) - } - - if (wantreply) - { - if (ret == DROPBEAR_SUCCESS) - { - send_msg_channel_success(channel); - } - else - { - send_msg_channel_failure(channel); - } - } - - m_free(type); -} - -static void -dropbear_closechansess(FAR const struct dropbear_channel *channel) -{ - FAR struct dropbear_nshsession_s *sess = channel->typedata; - - if (sess != NULL) - { - sess->done = true; - } -} - -static void -dropbear_cleanupchansess(FAR const struct dropbear_channel *channel) -{ - FAR struct dropbear_nshsession_s *sess = channel->typedata; - - if (sess == NULL) - { - return; - } - - sess->done = true; - - if (sess->nsh_pid > 0) - { - kill(sess->nsh_pid, SIGTERM); - } - - if (sess->waiter_started) - { - pthread_join(sess->waiter, NULL); - sess->waiter_started = false; - } - - m_free(sess); -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/* Chansession lifecycle hooks invoked from svr-session.c. Upstream - * svr-chansession.c uses these to set up and reap the global childpids[] / - * SIGCHLD machinery; the NSH bridge tracks each session's child through its - * own waiter thread (dropbear_nsh_waiter), so both are no-ops here. - */ - -void svr_chansessinitialise(void) -{ -} - -void svr_chansess_checksignal(void) -{ -} - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -const struct dropbear_chantype svrchansess = -{ - "session", - dropbear_newchansess, - dropbear_sesscheckclose, - dropbear_chansessionrequest, - dropbear_closechansess, - dropbear_cleanupchansess, -}; diff --git a/netutils/dropbear/patch/0001-guard-platform-declarations.patch b/netutils/dropbear/patch/0001-guard-platform-declarations.patch deleted file mode 100644 index 7eb1dfcd2..000000000 --- a/netutils/dropbear/patch/0001-guard-platform-declarations.patch +++ /dev/null @@ -1,26 +0,0 @@ ---- a/src/dbutil.c -+++ b/src/dbutil.c -@@ -66,6 +66,10 @@ - #include "session.h" - #include "atomicio.h" - -+#ifdef DROPBEAR_NUTTX -+int execv(const char *path, char * const argv[]); -+#endif -+ - #define MAX_FMT 100 - - static void generic_dropbear_exit(int exitcode, const char* format, ---- a/src/signkey.h -+++ b/src/signkey.h -@@ -150,9 +150,9 @@ - void buf_put_sign(buffer* buf, sign_key *key, enum signature_type sigtype, const buffer *data_buf); - #if DROPBEAR_SIGNKEY_VERIFY - int buf_verify(buffer * buf, sign_key *key, enum signature_type expect_sigtype, const buffer *data_buf); - int sk_buf_verify(buffer * buf, sign_key *key, enum signature_type expect_sigtype, const buffer *data_buf, char* app, unsigned int applen); --char * sign_key_fingerprint(const unsigned char* keyblob, unsigned int keybloblen); - #endif -+char * sign_key_fingerprint(const unsigned char* keyblob, unsigned int keybloblen); - int cmp_base64_key(const unsigned char* keyblob, unsigned int keybloblen, - const unsigned char* algoname, unsigned int algolen, - const buffer * line, char ** fingerprint); diff --git a/netutils/dropbear/patch/0002-use-nuttx-passwd-auth.patch b/netutils/dropbear/patch/0002-use-nuttx-passwd-auth.patch deleted file mode 100644 index 5e71d73da..000000000 --- a/netutils/dropbear/patch/0002-use-nuttx-passwd-auth.patch +++ /dev/null @@ -1,87 +0,0 @@ ---- a/src/svr-authpasswd.c -+++ b/src/svr-authpasswd.c -@@ -33,6 +33,77 @@ - - #if DROPBEAR_SVR_PASSWORD_AUTH - -+#if DROPBEAR_NUTTX_PASSWD -+ -+/* Process a password auth request, sending success or failure messages as -+ * appropriate */ -+void svr_auth_password(int valid_user) { -+ -+ char * password = NULL; -+ unsigned int passwordlen; -+ unsigned int changepw; -+ int auth_ok = 0; -+ -+ /* check if client wants to change password */ -+ changepw = buf_getbool(ses.payload); -+ if (changepw) { -+ /* not implemented by this server */ -+ send_msg_userauth_failure(0, 1); -+ return; -+ } -+ -+ password = buf_getstring(ses.payload, &passwordlen); -+ if (valid_user && passwordlen <= DROPBEAR_MAX_PASSWORD_LEN && -+ strlen(password) == passwordlen) { -+ auth_ok = dropbear_verify_password(ses.authstate.pw_name, password); -+ } -+ m_burn(password, passwordlen); -+ m_free(password); -+ -+ /* After we have got the payload contents we can exit if the username -+ is invalid. Invalid users have already been logged. */ -+ if (!valid_user) { -+ send_msg_userauth_failure(0, 1); -+ return; -+ } -+ -+ if (passwordlen > DROPBEAR_MAX_PASSWORD_LEN) { -+ dropbear_log(LOG_WARNING, -+ "Too-long password attempt for '%s' from %s", -+ ses.authstate.pw_name, -+ svr_ses.addrstring); -+ send_msg_userauth_failure(0, 1); -+ return; -+ } -+ -+ if (auth_ok == DROPBEAR_SUCCESS) { -+ if (svr_opts.multiauthmethod && (ses.authstate.authtypes & ~AUTH_TYPE_PASSWORD)) { -+ /* successful password authentication, but extra auth required */ -+ dropbear_log(LOG_NOTICE, -+ "Password auth succeeded for '%s' from %s, extra auth required", -+ ses.authstate.pw_name, -+ svr_ses.addrstring); -+ ses.authstate.authtypes &= ~AUTH_TYPE_PASSWORD; /* password auth ok, delete the method flag */ -+ send_msg_userauth_failure(1, 0); /* Send partial success */ -+ } else { -+ /* successful authentication */ -+ dropbear_log(LOG_NOTICE, -+ "Password auth succeeded for '%s' from %s", -+ ses.authstate.pw_name, -+ svr_ses.addrstring); -+ send_msg_userauth_success(); -+ } -+ } else { -+ dropbear_log(LOG_WARNING, -+ "Bad password attempt for '%s' from %s", -+ ses.authstate.pw_name, -+ svr_ses.addrstring); -+ send_msg_userauth_failure(0, 1); -+ } -+} -+ -+#else -+ - /* not constant time when strings are differing lengths. - string content isn't leaked, and crypt hashes are predictable length. */ - static int constant_time_strcmp(const char* a, const char* b) { -@@ -131,4 +202,6 @@ - } - } - -+#endif /* DROPBEAR_NUTTX_PASSWD */ -+ - #endif diff --git a/netutils/dropbear/patch/0003-allow-localoptions-to-override-tracking-malloc.patch b/netutils/dropbear/patch/0003-allow-localoptions-to-override-tracking-malloc.patch deleted file mode 100644 index b1dc3e52c..000000000 --- a/netutils/dropbear/patch/0003-allow-localoptions-to-override-tracking-malloc.patch +++ /dev/null @@ -1,24 +0,0 @@ ---- a/src/sysoptions.h -+++ b/src/sysoptions.h -@@ -183,7 +183,9 @@ defined(__has_feature) - #define LTC_ECC521 - #endif - --#define DROPBEAR_LTC_PRNG (DROPBEAR_ECC) -+#ifndef DROPBEAR_LTC_PRNG -+#define DROPBEAR_LTC_PRNG (DROPBEAR_ECC) -+#endif - - /* RSA can be vulnerable to timing attacks which use the time required for - * signing to guess the private key. Blinding avoids this attack, though makes -@@ -436,7 +438,9 @@ defined(__has_feature) - #define DROPBEAR_CLIENT_TCP_FAST_OPEN 0 - #endif - --#define DROPBEAR_TRACKING_MALLOC (DROPBEAR_FUZZ) -+#ifndef DROPBEAR_TRACKING_MALLOC -+#define DROPBEAR_TRACKING_MALLOC (DROPBEAR_FUZZ) -+#endif - - /* Used to work around Memory Sanitizer false positives */ - #if defined(__has_feature) diff --git a/netutils/dropbear/patch/0004-use-nuttx-unused-macro.patch b/netutils/dropbear/patch/0004-use-nuttx-unused-macro.patch deleted file mode 100644 index 2ea588057..000000000 --- a/netutils/dropbear/patch/0004-use-nuttx-unused-macro.patch +++ /dev/null @@ -1,202 +0,0 @@ ---- a/src/compat.c -+++ b/src/compat.c -@@ -89,6 +89,6 @@ - #ifndef HAVE_GETUSERSHELL - static char **curshell, **shells, *strings; --static char **initshells(); -+static char **initshells(void); - #endif - - #ifndef HAVE_STRLCPY -@@ -234,7 +234,7 @@ - curshell = initshells(); - } - --static char **initshells() { -+static char **initshells(void) { - static const char *okshells[] = { COMPAT_USER_SHELLS, NULL }; - register char **sp, *cp; - register FILE *fp; ---- a/src/common-algo.c -+++ b/src/common-algo.c -@@ -39,16 +39,25 @@ - /* This file (algo.c) organises the ciphers which can be used, and is used to - * decide which ciphers/hashes/compression/signing to use during key exchange*/ - --static int void_cipher(const unsigned char* in, unsigned char* out, -- unsigned long len, void* UNUSED(cipher_state)) { -+static int void_cipher(const unsigned char* in, unsigned char* out, -+ unsigned long len, void* cipher_state) { -+ UNUSED(cipher_state); -+ - if (in != out) { - memmove(out, in, len); - } - return CRYPT_OK; - } - --static int void_start(int UNUSED(cipher), const unsigned char* UNUSED(IV), -- const unsigned char* UNUSED(key), -- int UNUSED(keylen), int UNUSED(num_rounds), void* UNUSED(cipher_state)) { -+static int void_start(int cipher, const unsigned char* IV, -+ const unsigned char* key, -+ int keylen, int num_rounds, void* cipher_state) { -+ UNUSED(cipher); -+ UNUSED(IV); -+ UNUSED(key); -+ UNUSED(keylen); -+ UNUSED(num_rounds); -+ UNUSED(cipher_state); -+ - return CRYPT_OK; - } - ---- a/src/common-channel.c -+++ b/src/common-channel.c -@@ -410,7 +410,9 @@ - - #ifndef HAVE_WRITEV - static int writechannel_fallback(struct Channel* channel, int fd, circbuffer *cbuf, -- const unsigned char *UNUSED(moredata), unsigned int *morelen) { -+ const unsigned char *moredata, unsigned int *morelen) { -+ UNUSED(moredata); -+ - - unsigned char *circ_p1, *circ_p2; - unsigned int circ_len1, circ_len2; ---- a/src/dbutil.c -+++ b/src/dbutil.c -@@ -138,7 +138,9 @@ - } - --static void generic_dropbear_log(int UNUSED(priority), const char* format, -+static void generic_dropbear_log(int priority, const char* format, - va_list param) { -+ UNUSED(priority); -+ - - char printbuf[1024]; - ---- a/src/netio.c -+++ b/src/netio.c -@@ -47,7 +47,10 @@ - } - } - --static void cancel_callback(int result, int sock, void* UNUSED(data), const char* UNUSED(errstring)) { -+static void cancel_callback(int result, int sock, void* data, const char* errstring) { -+ UNUSED(data); -+ UNUSED(errstring); -+ - if (result == DROPBEAR_SUCCESS) - { - m_close(sock); ---- a/src/ltc_prng.c -+++ b/src/ltc_prng.c -@@ -32,8 +32,10 @@ - @param prng [out] The PRNG state to initialize - @return CRYPT_OK if successful - */ --int dropbear_prng_start(prng_state* UNUSED(prng)) -+int dropbear_prng_start(prng_state* prng) - { -+ UNUSED(prng); -+ - return CRYPT_OK; - } - -@@ -44,8 +46,12 @@ - @param prng PRNG state to update - @return CRYPT_OK if successful - */ --int dropbear_prng_add_entropy(const unsigned char* UNUSED(in), unsigned long UNUSED(inlen), prng_state* UNUSED(prng)) -+int dropbear_prng_add_entropy(const unsigned char* in, unsigned long inlen, prng_state* prng) - { -+ UNUSED(in); -+ UNUSED(inlen); -+ UNUSED(prng); -+ - return CRYPT_OK; - } - -@@ -54,8 +60,10 @@ - @param prng The PRNG to make active - @return CRYPT_OK if successful - */ --int dropbear_prng_ready(prng_state* UNUSED(prng)) -+int dropbear_prng_ready(prng_state* prng) - { -+ UNUSED(prng); -+ - return CRYPT_OK; - } - -@@ -66,8 +74,10 @@ - @param prng The active PRNG to read from - @return Number of octets read - */ --unsigned long dropbear_prng_read(unsigned char* out, unsigned long outlen, prng_state* UNUSED(prng)) -+unsigned long dropbear_prng_read(unsigned char* out, unsigned long outlen, prng_state* prng) - { -+ UNUSED(prng); -+ - LTC_ARGCHK(out != NULL); - genrandom(out, outlen); - return outlen; -@@ -78,8 +88,10 @@ - @param prng The PRNG to terminate - @return CRYPT_OK if successful - */ --int dropbear_prng_done(prng_state* UNUSED(prng)) -+int dropbear_prng_done(prng_state* prng) - { -+ UNUSED(prng); -+ - return CRYPT_OK; - } - -@@ -90,8 +102,11 @@ - @param prng The PRNG to export - @return CRYPT_OK if successful - */ --int dropbear_prng_export(unsigned char* UNUSED(out), unsigned long* outlen, prng_state* UNUSED(prng)) -+int dropbear_prng_export(unsigned char* out, unsigned long* outlen, prng_state* prng) - { -+ UNUSED(out); -+ UNUSED(prng); -+ - LTC_ARGCHK(outlen != NULL); - - *outlen = 0; -@@ -105,8 +120,12 @@ - @param prng The PRNG to import - @return CRYPT_OK if successful - */ --int dropbear_prng_import(const unsigned char* UNUSED(in), unsigned long UNUSED(inlen), prng_state* UNUSED(prng)) -+int dropbear_prng_import(const unsigned char* in, unsigned long inlen, prng_state* prng) - { -+ UNUSED(in); -+ UNUSED(inlen); -+ UNUSED(prng); -+ - return CRYPT_OK; - } - ---- a/src/chachapoly.c -+++ b/src/chachapoly.c -@@ -43,9 +43,13 @@ - const struct dropbear_cipher dropbear_chachapoly = - {&dummy, CHACHA20_KEY_LEN*2, CHACHA20_BLOCKSIZE}; - --static int dropbear_chachapoly_start(int UNUSED(cipher), const unsigned char* UNUSED(IV), -+static int dropbear_chachapoly_start(int cipher, const unsigned char* IV, - const unsigned char *key, int keylen, -- int UNUSED(num_rounds), dropbear_chachapoly_state *state) { -+ int num_rounds, dropbear_chachapoly_state *state) { -+ UNUSED(cipher); -+ UNUSED(IV); -+ UNUSED(num_rounds); -+ - int err; - - TRACE2(("enter dropbear_chachapoly_start")) diff --git a/netutils/dropbear/port/config.h b/netutils/dropbear/port/config.h deleted file mode 100644 index 0f5355fd7..000000000 --- a/netutils/dropbear/port/config.h +++ /dev/null @@ -1,20 +0,0 @@ -/**************************************************************************** - * apps/netutils/dropbear/port/config.h - * - * SPDX-License-Identifier: Apache-2.0 - ****************************************************************************/ - -#ifndef __APPS_NETUTILS_DROPBEAR_PORT_CONFIG_H -#define __APPS_NETUTILS_DROPBEAR_PORT_CONFIG_H - -/* Dropbear looks for a file named config.h. Keep this wrapper name stable; - * NuttX-specific autoconf replacements live in nuttx_config.h. - */ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "nuttx_config.h" - -#endif /* __APPS_NETUTILS_DROPBEAR_PORT_CONFIG_H */ diff --git a/netutils/dropbear/port/dropbear_chachapoly.c b/netutils/dropbear/port/dropbear_chachapoly.c deleted file mode 100644 index f670d14ca..000000000 --- a/netutils/dropbear/port/dropbear_chachapoly.c +++ /dev/null @@ -1,389 +0,0 @@ -/**************************************************************************** - * apps/netutils/dropbear/port/dropbear_chachapoly.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/* chacha20-poly1305@openssh.com backed by the NuttX crypto device. - * - * The SSH construction (see OpenSSH PROTOCOL.chacha20poly1305) uses the - * original DJB ChaCha20 parameterization: a 64-bit block counter in state - * words 12..13 and a 64-bit nonce (the packet sequence number, big endian) - * in words 14..15. This maps to the kernel CRYPTO_CHACHA20_DJB transform, - * whose 16-byte IV is loaded verbatim into words 12..15 as a 64-bit - * little-endian counter followed by the 64-bit nonce. The Poly1305 tag is - * computed with the kernel CRYPTO_POLY1305 transform, keyed with the first - * keystream block (counter 0) of the main key, as the protocol requires. - */ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "includes.h" - -#include -#include -#include -#include - -#include - -#include "algo.h" -#include "dbutil.h" -#include "chachapoly.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define CHACHA20_KEY_LEN 32 -#define CHACHA20_BLOCKSIZE 8 -#define CHACHA20_IV_LEN 16 -#define POLY1305_KEY_LEN 32 -#define POLY1305_TAG_LEN 16 - -/* The keystream comes from the NuttX crypto device, so each upstream - * chacha_state is unused and its input[] buffer just stores the 32-byte key, - * keeping the upstream header unpatched. - */ - -#define KEY_MAIN(s) ((FAR unsigned char *)(s)->chacha.input) -#define KEY_HEADER(s) ((FAR unsigned char *)(s)->header.input) - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static const struct ltc_cipher_descriptor g_dropbear_chachapoly_dummy = -{ - .name = NULL -}; - -static const struct dropbear_hash g_dropbear_chachapoly_mac = -{ - NULL, - POLY1305_KEY_LEN, - POLY1305_TAG_LEN -}; - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -const struct dropbear_cipher dropbear_chachapoly = -{ - &g_dropbear_chachapoly_dummy, - CHACHA20_KEY_LEN * 2, - CHACHA20_BLOCKSIZE -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/* Open a fresh /dev/crypto session descriptor. NuttX file descriptors are - * owned by the task group, so the fd is never cached across calls: each - * operation opens it in the task that uses it and closes it when done. - */ - -static int dropbear_cryptodev_open(void) -{ - int fd; - int cfd; - - fd = open("/dev/crypto", O_RDWR); - if (fd < 0) - { - return -1; - } - - if (ioctl(fd, CRIOGET, &cfd) < 0) - { - close(fd); - return -1; - } - - close(fd); - - /* Keep the descriptor out of the NSH shells Dropbear forks and execs for - * each SSH session. - */ - - if (fcntl(cfd, F_SETFD, FD_CLOEXEC) < 0) - { - close(cfd); - return -1; - } - - return cfd; -} - -/* One ChaCha20 (DJB layout) pass: encrypt/decrypt len bytes with the given - * 64-bit block counter and the packet sequence number as nonce. - */ - -static int dropbear_chacha(int cfd, FAR const unsigned char *key, - unsigned int seq, uint64_t counter, - FAR const unsigned char *in, - FAR unsigned char *out, size_t len) -{ - struct session_op session; - struct crypt_op cryp; - unsigned char iv[CHACHA20_IV_LEN]; - int ret = CRYPT_ERROR; - int i; - - /* IV = 64-bit little-endian block counter || 64-bit nonce. The nonce is - * the packet sequence number stored big endian, as OpenSSH does. - */ - - for (i = 0; i < 8; i++) - { - iv[i] = (unsigned char)(counter >> (8 * i)); - } - - STORE64H((uint64_t)seq, iv + 8); - - memset(&session, 0, sizeof(session)); - session.cipher = CRYPTO_CHACHA20_DJB; - session.key = (caddr_t)key; - session.keylen = CHACHA20_KEY_LEN; - if (ioctl(cfd, CIOCGSESSION, &session) < 0) - { - return CRYPT_ERROR; - } - - memset(&cryp, 0, sizeof(cryp)); - cryp.ses = session.ses; - cryp.op = COP_ENCRYPT; - cryp.len = len; - cryp.src = (caddr_t)in; - cryp.dst = (caddr_t)out; - cryp.iv = (caddr_t)iv; - cryp.ivlen = sizeof(iv); - if (ioctl(cfd, CIOCCRYPT, &cryp) == 0) - { - ret = CRYPT_OK; - } - - ioctl(cfd, CIOCFSESSION, &session.ses); - return ret; -} - -static int dropbear_poly1305(int cfd, FAR const unsigned char *key, - FAR const unsigned char *in, size_t len, - FAR unsigned char *tag) -{ - struct session_op session; - struct crypt_op cryp; - int ret = CRYPT_ERROR; - - memset(&session, 0, sizeof(session)); - session.mac = CRYPTO_POLY1305; - session.mackey = (caddr_t)key; - session.mackeylen = POLY1305_KEY_LEN; - if (ioctl(cfd, CIOCGSESSION, &session) < 0) - { - return CRYPT_ERROR; - } - - /* Plain (non-HMAC) MACs are driven in two steps through /dev/crypto: - * COP_FLAG_UPDATE feeds the data, then a final call without the flag - * writes out the tag. - */ - - memset(&cryp, 0, sizeof(cryp)); - cryp.ses = session.ses; - cryp.op = COP_ENCRYPT; - cryp.flags = COP_FLAG_UPDATE; - cryp.len = len; - cryp.src = (caddr_t)in; - if (ioctl(cfd, CIOCCRYPT, &cryp) == 0) - { - cryp.flags = 0; - cryp.len = 0; - cryp.src = NULL; - cryp.mac = (caddr_t)tag; - if (ioctl(cfd, CIOCCRYPT, &cryp) == 0) - { - ret = CRYPT_OK; - } - } - - ioctl(cfd, CIOCFSESSION, &session.ses); - return ret; -} - -static int dropbear_chachapoly_start(int cipher, - FAR const unsigned char *iv, - FAR const unsigned char *key, - int keylen, int num_rounds, - FAR void *cipher_state) -{ - FAR dropbear_chachapoly_state *state = cipher_state; - int cfd; - - UNUSED(cipher); - UNUSED(iv); - - if (keylen != CHACHA20_KEY_LEN * 2 || num_rounds != 0) - { - return CRYPT_ERROR; - } - - /* Validate that the crypto device is reachable at cipher setup. */ - - cfd = dropbear_cryptodev_open(); - if (cfd < 0) - { - return CRYPT_ERROR; - } - - close(cfd); - - memcpy(KEY_MAIN(state), key, CHACHA20_KEY_LEN); - memcpy(KEY_HEADER(state), key + CHACHA20_KEY_LEN, CHACHA20_KEY_LEN); - return CRYPT_OK; -} - -static int dropbear_chachapoly_crypt(unsigned int seq, - FAR const unsigned char *in, - FAR unsigned char *out, - unsigned long len, unsigned long taglen, - FAR void *cipher_state, - int direction) -{ - FAR dropbear_chachapoly_state *state = cipher_state; - unsigned char key[POLY1305_KEY_LEN]; - unsigned char tag[POLY1305_TAG_LEN]; - unsigned char zero[POLY1305_KEY_LEN]; - int cfd; - int ret = CRYPT_ERROR; - - if (len < 4 || taglen != POLY1305_TAG_LEN) - { - return CRYPT_ERROR; - } - - cfd = dropbear_cryptodev_open(); - if (cfd < 0) - { - return CRYPT_ERROR; - } - - /* Poly1305 key = first keystream block of the main key at counter 0 */ - - memset(zero, 0, sizeof(zero)); - if (dropbear_chacha(cfd, KEY_MAIN(state), seq, 0, zero, key, - sizeof(key)) != CRYPT_OK) - { - goto out; - } - - if (direction == LTC_DECRYPT) - { - if (dropbear_poly1305(cfd, key, in, len, tag) != CRYPT_OK) - { - goto out; - } - - if (constant_time_memcmp(in + len, tag, sizeof(tag)) != 0) - { - goto out; - } - } - - /* Packet length: header key, counter 0. Payload: main key, counter 1. */ - - if (dropbear_chacha(cfd, KEY_HEADER(state), seq, 0, in, out, 4) != - CRYPT_OK) - { - goto out; - } - - if (dropbear_chacha(cfd, KEY_MAIN(state), seq, 1, in + 4, out + 4, - len - 4) != CRYPT_OK) - { - goto out; - } - - if (direction == LTC_ENCRYPT) - { - if (dropbear_poly1305(cfd, key, out, len, out + len) != CRYPT_OK) - { - goto out; - } - } - - ret = CRYPT_OK; - -out: - close(cfd); - zeromem(key, sizeof(key)); - zeromem(tag, sizeof(tag)); - return ret; -} - -static int -dropbear_chachapoly_getlength(unsigned int seq, FAR const unsigned char *in, - FAR unsigned int *outlen, unsigned long len, - FAR void *cipher_state) -{ - FAR dropbear_chachapoly_state *state = cipher_state; - unsigned char buf[4]; - int cfd; - int ret; - - if (len < sizeof(buf)) - { - return CRYPT_ERROR; - } - - cfd = dropbear_cryptodev_open(); - if (cfd < 0) - { - return CRYPT_ERROR; - } - - ret = dropbear_chacha(cfd, KEY_HEADER(state), seq, 0, in, buf, - sizeof(buf)); - close(cfd); - if (ret != CRYPT_OK) - { - return CRYPT_ERROR; - } - - LOAD32H(*outlen, buf); - return CRYPT_OK; -} - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -const struct dropbear_cipher_mode dropbear_mode_chachapoly = -{ - dropbear_chachapoly_start, - NULL, - NULL, - dropbear_chachapoly_crypt, - dropbear_chachapoly_getlength, - &g_dropbear_chachapoly_mac -}; diff --git a/netutils/dropbear/port/dropbear_ltc_hmac_sha256.c b/netutils/dropbear/port/dropbear_ltc_hmac_sha256.c deleted file mode 100644 index dda511d5f..000000000 --- a/netutils/dropbear/port/dropbear_ltc_hmac_sha256.c +++ /dev/null @@ -1,255 +0,0 @@ -/**************************************************************************** - * apps/netutils/dropbear/port/dropbear_ltc_hmac_sha256.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/* LibTomCrypt-compatible incremental HMAC API backed by a - * CRYPTO_SHA2_256_HMAC /dev/crypto session (hmac-sha2-256, the only MAC the - * NuttX Dropbear configuration enables): init opens the session, process - * feeds data with COP_FLAG_UPDATE, done reads the tag and frees the session. - */ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "includes.h" - -#include -#include -#include -#include -#include -#include - -#include - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define DROPBEAR_HMAC_SHA256_DIGESTLEN 32 -#define DROPBEAR_HMAC_SHA256_BLOCKLEN 64 - -/* Stash the process-local /dev/crypto descriptor and session id in the - * unused md hash-state buffer so the upstream hmac_state needs no patch. - */ - -static_assert(sizeof(int) + sizeof(uint32_t) <= sizeof(hash_state), - "cryptodev state does not fit in hmac_state.md"); - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static int dropbear_hmac_cryptodev_open(void) -{ - int fd; - int cfd; - - fd = open("/dev/crypto", O_RDWR); - if (fd < 0) - { - return -1; - } - - if (ioctl(fd, CRIOGET, &cfd) < 0) - { - close(fd); - return -1; - } - - close(fd); - - if (fcntl(cfd, F_SETFD, FD_CLOEXEC) < 0) - { - close(cfd); - return -1; - } - - return cfd; -} - -static int dropbear_hmac_hash_is_sha256(int hash) -{ - int ret; - - ret = hash_is_valid(hash); - if (ret != CRYPT_OK) - { - return ret; - } - - if (hash_descriptor[hash].hashsize != DROPBEAR_HMAC_SHA256_DIGESTLEN || - hash_descriptor[hash].blocksize != DROPBEAR_HMAC_SHA256_BLOCKLEN) - { - return CRYPT_INVALID_HASH; - } - - return CRYPT_OK; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -int hmac_init(hmac_state *hmac, int hash, const unsigned char *key, - unsigned long keylen) -{ - struct session_op session; - int cfd; - int ret; - - LTC_ARGCHK(hmac != NULL); - LTC_ARGCHK(key != NULL); - - if (keylen == 0 || keylen > INT_MAX) - { - return CRYPT_INVALID_KEYSIZE; - } - - ret = dropbear_hmac_hash_is_sha256(hash); - if (ret != CRYPT_OK) - { - return ret; - } - - zeromem(hmac, sizeof(*hmac)); - cfd = dropbear_hmac_cryptodev_open(); - if (cfd < 0) - { - return CRYPT_ERROR; - } - - memset(&session, 0, sizeof(session)); - session.mac = CRYPTO_SHA2_256_HMAC; - session.mackey = (caddr_t)key; - session.mackeylen = (int)keylen; - if (ioctl(cfd, CIOCGSESSION, &session) < 0) - { - close(cfd); - zeromem(hmac, sizeof(*hmac)); - return CRYPT_ERROR; - } - - memcpy(&hmac->md, &cfd, sizeof(cfd)); - memcpy((FAR uint8_t *)&hmac->md + sizeof(cfd), - &session.ses, sizeof(session.ses)); - hmac->hash = hash; - return CRYPT_OK; -} - -int hmac_process(hmac_state *hmac, const unsigned char *in, - unsigned long inlen) -{ - struct crypt_op cryp; - uint32_t ses; - int cfd; - int ret; - - LTC_ARGCHK(hmac != NULL); - LTC_ARGCHK(in != NULL || inlen == 0); - - ret = dropbear_hmac_hash_is_sha256(hmac->hash); - if (ret != CRYPT_OK) - { - return ret; - } - - if (inlen > UINT_MAX) - { - return CRYPT_OVERFLOW; - } - - memcpy(&cfd, &hmac->md, sizeof(cfd)); - memcpy(&ses, (FAR uint8_t *)&hmac->md + sizeof(cfd), sizeof(ses)); - if (cfd < 0) - { - return CRYPT_ERROR; - } - - memset(&cryp, 0, sizeof(cryp)); - cryp.ses = ses; - cryp.op = COP_ENCRYPT; - cryp.flags = COP_FLAG_UPDATE; - cryp.len = (unsigned int)inlen; - cryp.src = (caddr_t)in; - if (ioctl(cfd, CIOCCRYPT, &cryp) < 0) - { - return CRYPT_ERROR; - } - - return CRYPT_OK; -} - -int hmac_done(hmac_state *hmac, unsigned char *out, unsigned long *outlen) -{ - unsigned char digest[DROPBEAR_HMAC_SHA256_DIGESTLEN]; - struct crypt_op cryp; - unsigned long copylen; - uint32_t ses; - int cfd; - int ret = CRYPT_ERROR; - - LTC_ARGCHK(hmac != NULL); - LTC_ARGCHK(out != NULL); - LTC_ARGCHK(outlen != NULL); - - memcpy(&cfd, &hmac->md, sizeof(cfd)); - memcpy(&ses, (FAR uint8_t *)&hmac->md + sizeof(cfd), sizeof(ses)); - if (cfd < 0) - { - goto out; - } - - ret = dropbear_hmac_hash_is_sha256(hmac->hash); - if (ret != CRYPT_OK) - { - goto out; - } - - memset(&cryp, 0, sizeof(cryp)); - cryp.ses = ses; - cryp.op = COP_ENCRYPT; - cryp.len = 0; - cryp.src = (caddr_t)digest; - cryp.mac = (caddr_t)digest; - if (ioctl(cfd, CIOCCRYPT, &cryp) < 0) - { - ret = CRYPT_ERROR; - goto out; - } - - copylen = MIN(*outlen, DROPBEAR_HMAC_SHA256_DIGESTLEN); - memcpy(out, digest, copylen); - *outlen = copylen; - ret = CRYPT_OK; - -out: - if (cfd >= 0) - { - ioctl(cfd, CIOCFSESSION, &ses); - close(cfd); - } - - zeromem(digest, sizeof(digest)); - zeromem(hmac, sizeof(*hmac)); - return ret; -} diff --git a/netutils/dropbear/port/dropbear_utils.c b/netutils/dropbear/port/dropbear_utils.c deleted file mode 100644 index 73619cbe7..000000000 --- a/netutils/dropbear/port/dropbear_utils.c +++ /dev/null @@ -1,149 +0,0 @@ -/**************************************************************************** - * apps/netutils/dropbear/port/dropbear_utils.c - * - * SPDX-License-Identifier: Apache-2.0 - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "dropbear_utils.h" - -#include -#include -#include -#include -#include - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static int dropbear_hex_value(char ch) -{ - if (ch >= '0' && ch <= '9') - { - return ch - '0'; - } - - if (ch >= 'a' && ch <= 'f') - { - return ch - 'a' + 10; - } - - if (ch >= 'A' && ch <= 'F') - { - return ch - 'A' + 10; - } - - return -1; -} - -static int dropbear_try_mkdir(FAR const char *path) -{ - if (mkdir(path, 0700) < 0 && errno != EEXIST) - { - return -errno; - } - - return OK; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -void dropbear_hex_encode(FAR char *dst, FAR const uint8_t *src, - size_t srclen) -{ - static const char hex[] = "0123456789abcdef"; - size_t i; - - for (i = 0; i < srclen; i++) - { - dst[i * 2] = hex[src[i] >> 4]; - dst[i * 2 + 1] = hex[src[i] & 0x0f]; - } - - dst[srclen * 2] = '\0'; -} - -int dropbear_hex_decode(FAR const char *src, size_t srclen, - FAR uint8_t *dst, size_t dstlen) -{ - size_t i; - - if (srclen != dstlen * 2) - { - return -EINVAL; - } - - for (i = 0; i < dstlen; i++) - { - int hi = dropbear_hex_value(src[i * 2]); - int lo = dropbear_hex_value(src[i * 2 + 1]); - - if (hi < 0 || lo < 0) - { - return -EINVAL; - } - - dst[i] = (uint8_t)((hi << 4) | lo); - } - - return OK; -} - -int dropbear_try_prepare_parent(FAR const char *path) -{ - char dir[PATH_MAX]; - struct stat st; - FAR char *slash; - FAR char *p; - int ret; - - if (strlcpy(dir, path, sizeof(dir)) >= sizeof(dir)) - { - return -ENAMETOOLONG; - } - - slash = strrchr(dir, '/'); - if (slash == NULL || slash == dir) - { - return OK; - } - - *slash = '\0'; - if (stat(dir, &st) == 0) - { - return OK; - } - - for (p = dir + 1; *p != '\0'; p++) - { - if (*p == '/') - { - *p = '\0'; - ret = dropbear_try_mkdir(dir); - if (ret < 0) - { - return ret; - } - - *p = '/'; - } - } - - return dropbear_try_mkdir(dir); -} - -#ifndef CONFIG_SCHED_USER_IDENTITY -int dropbear_getgroups(int size, gid_t list[]) -{ - (void)size; - (void)list; - set_errno(ENOSYS); - return ERROR; -} -#endif diff --git a/netutils/dropbear/port/dropbear_utils.h b/netutils/dropbear/port/dropbear_utils.h deleted file mode 100644 index 3e7d2722e..000000000 --- a/netutils/dropbear/port/dropbear_utils.h +++ /dev/null @@ -1,31 +0,0 @@ -/**************************************************************************** - * apps/netutils/dropbear/port/dropbear_utils.h - * - * SPDX-License-Identifier: Apache-2.0 - ****************************************************************************/ - -#ifndef __APPS_NETUTILS_DROPBEAR_PORT_DROPBEAR_UTILS_H -#define __APPS_NETUTILS_DROPBEAR_PORT_DROPBEAR_UTILS_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "config.h" - -#include -#include - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -void dropbear_hex_encode(FAR char *dst, FAR const uint8_t *src, - size_t srclen); - -int dropbear_hex_decode(FAR const char *src, size_t srclen, - FAR uint8_t *dst, size_t dstlen); - -int dropbear_try_prepare_parent(FAR const char *path); - -#endif /* __APPS_NETUTILS_DROPBEAR_PORT_DROPBEAR_UTILS_H */ diff --git a/netutils/dropbear/port/localoptions.h b/netutils/dropbear/port/localoptions.h deleted file mode 100644 index 28ac5a3b5..000000000 --- a/netutils/dropbear/port/localoptions.h +++ /dev/null @@ -1,81 +0,0 @@ -/**************************************************************************** - * apps/netutils/dropbear/port/localoptions.h - * - * SPDX-License-Identifier: Apache-2.0 - ****************************************************************************/ - -#ifndef __APPS_NETUTILS_DROPBEAR_PORT_LOCALOPTIONS_H -#define __APPS_NETUTILS_DROPBEAR_PORT_LOCALOPTIONS_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define DROPBEAR_TRACKING_MALLOC 1 - -/* Persist the native Dropbear ECDSA host key at the configured path. */ - -#define ECDSA_PRIV_FILENAME CONFIG_NETUTILS_DROPBEAR_HOSTKEY_PATH - -#define DROPBEAR_SVR_DROP_PRIVS 0 - -#ifdef CONFIG_SCHED_USER_IDENTITY -# define DROPBEAR_SVR_MULTIUSER 1 -#else -# define DROPBEAR_SVR_MULTIUSER 0 -#endif - -#define DROPBEAR_SVR_PASSWORD_AUTH 1 -#define DROPBEAR_SVR_PUBKEY_AUTH 0 -#define DROPBEAR_SVR_PUBKEY_OPTIONS 0 - -#define DROPBEAR_REEXEC 0 -#define DROPBEAR_SMALL_CODE 1 -#define DROPBEAR_USER_ALGO_LIST 0 - -#define DROPBEAR_X11FWD 0 -#define DROPBEAR_SVR_AGENTFWD 0 -#define DROPBEAR_SVR_LOCALTCPFWD 0 -#define DROPBEAR_SVR_REMOTETCPFWD 0 -#define DROPBEAR_SVR_LOCALSTREAMFWD 0 -#define DROPBEAR_SVR_REMOTESTREAMFWD 0 - -#define DROPBEAR_DSS 0 -#define DROPBEAR_RSA 0 -#define DROPBEAR_ECDSA 1 -#define DROPBEAR_ED25519 0 -#define DROPBEAR_SK_KEYS 0 -#define DROPBEAR_ECC_256 1 -#define DROPBEAR_ECC_384 0 -#define DROPBEAR_ECC_521 0 - -#define DROPBEAR_AES128 1 -#define DROPBEAR_AES256 0 -#define DROPBEAR_CHACHA20POLY1305 1 -#define DROPBEAR_ENABLE_CBC_MODE 0 -#define DROPBEAR_ENABLE_GCM_MODE 0 - -#define DROPBEAR_SHA1_HMAC 0 -#define DROPBEAR_SHA2_256_HMAC 1 -#define DROPBEAR_SHA2_512_HMAC 0 -#define DROPBEAR_SHA1_96_HMAC 0 - -#define DROPBEAR_CURVE25519 1 -#define DROPBEAR_DH_GROUP14_SHA1 0 -#define DROPBEAR_DH_GROUP14_SHA256 0 -#define DROPBEAR_DH_GROUP16 0 -#define DROPBEAR_DH_GROUP1 0 -#define DROPBEAR_ECDH 0 -#define DROPBEAR_SNTRUP761 0 -#define DROPBEAR_MLKEM768 0 - -#define DROPBEAR_DEFAULT_CLI_AUTHKEY "/etc/dropbear/authorized_keys" -#define DROPBEAR_SFTPSERVER 0 - -#endif /* __APPS_NETUTILS_DROPBEAR_PORT_LOCALOPTIONS_H */ diff --git a/netutils/dropbear/port/nuttx_auth.c b/netutils/dropbear/port/nuttx_auth.c deleted file mode 100644 index 83becdcae..000000000 --- a/netutils/dropbear/port/nuttx_auth.c +++ /dev/null @@ -1,109 +0,0 @@ -/**************************************************************************** - * apps/netutils/dropbear/port/nuttx_auth.c - * - * SPDX-License-Identifier: Apache-2.0 - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "config.h" - -#include -#include -#include -#include -#include -#include - -#include "fsutils/passwd.h" - -#include "dbutil.h" - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static struct passwd g_dropbear_pw; -static char g_dropbear_name[64]; -static char g_dropbear_dir[] = "/"; -static char g_dropbear_shell[] = "/bin/sh"; -static char g_dropbear_password_marker[] = "x"; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static FAR struct passwd *dropbear_fill_pw(FAR const char *name, uid_t uid) -{ - memset(&g_dropbear_pw, 0, sizeof(g_dropbear_pw)); - - snprintf(g_dropbear_name, sizeof(g_dropbear_name), "%s", name); - - g_dropbear_pw.pw_uid = uid; - g_dropbear_pw.pw_gid = 0; - g_dropbear_pw.pw_name = g_dropbear_name; - g_dropbear_pw.pw_passwd = g_dropbear_password_marker; - g_dropbear_pw.pw_gecos = g_dropbear_name; - g_dropbear_pw.pw_dir = g_dropbear_dir; - g_dropbear_pw.pw_shell = g_dropbear_shell; - - return &g_dropbear_pw; -} - -FAR struct passwd *dropbear_getpwuid(uid_t uid) -{ - return dropbear_fill_pw("root", uid); -} - -FAR struct passwd *dropbear_getpwnam(FAR const char *name) -{ - if (name == NULL || name[0] == '\0') - { - return NULL; - } - - return dropbear_fill_pw(name, 0); -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -uid_t dropbear_getuid(void) -{ - return 0; -} - -uid_t dropbear_geteuid(void) -{ - return 0; -} - -int dropbear_auth_initialize(void) -{ - dropbear_log(LOG_INFO, "using NuttX passwd auth at %s", - CONFIG_FSUTILS_PASSWD_PATH); - return OK; -} - -int dropbear_verify_password(FAR const char *username, - FAR const char *password) -{ - int ret; - - ret = passwd_verify(username, password); - if (PASSWORD_VERIFY_MATCH(ret)) - { - return DROPBEAR_SUCCESS; - } - - if (PASSWORD_VERIFY_ERROR(ret) && ret != -ENOENT) - { - dropbear_log(LOG_WARNING, "passwd_verify failed for '%s': %d", - username, ret); - } - - return DROPBEAR_FAILURE; -} diff --git a/netutils/dropbear/port/nuttx_config.h b/netutils/dropbear/port/nuttx_config.h deleted file mode 100644 index d91709d1e..000000000 --- a/netutils/dropbear/port/nuttx_config.h +++ /dev/null @@ -1,142 +0,0 @@ -/**************************************************************************** - * apps/netutils/dropbear/port/nuttx_config.h - * - * SPDX-License-Identifier: Apache-2.0 - ****************************************************************************/ - -#ifndef __APPS_NETUTILS_DROPBEAR_PORT_NUTTX_CONFIG_H -#define __APPS_NETUTILS_DROPBEAR_PORT_NUTTX_CONFIG_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include -#include - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define DROPBEAR_SERVER 1 -#define BUNDLED_LIBTOM 1 -#define DISABLE_LASTLOG 1 -#define DISABLE_PAM 1 -#define DISABLE_PUTUTLINE 1 -#define DISABLE_PUTUTXLINE 1 -#define DISABLE_UTMP 1 -#define DISABLE_UTMPX 1 -#define DISABLE_WTMP 1 -#define DISABLE_WTMPX 1 - -#ifndef CONFIG_NETUTILS_DROPBEAR_SYSLOG -# define DISABLE_SYSLOG 1 -#endif - -#ifndef CONFIG_NETUTILS_DROPBEAR_COMPRESSION -# define DISABLE_ZLIB 1 -#endif - -#define DROPBEAR_FUZZ 0 -#define DROPBEAR_PLUGIN 0 - -#define HAVE_BASENAME 1 -#define HAVE_CLOCK_GETTIME 1 -#define HAVE_CONST_GAI_STRERROR_PROTO 1 -#define HAVE_CRYPT 1 -#define HAVE_DECL_HTOLE64 1 -#define HAVE_ENDIAN_H 1 -#define HAVE_EXPLICIT_BZERO 1 -#define HAVE_FREEADDRINFO 1 -#define HAVE_GAI_STRERROR 1 -#define HAVE_GETADDRINFO 1 -#define HAVE_GETNAMEINFO 1 -#define HAVE_GETRANDOM 1 -#define HAVE_INTTYPES_H 1 -#define HAVE_LIBGEN_H 1 -#define HAVE_NETDB_H 1 -#define HAVE_NETINET_IN_H 1 -#define HAVE_NETINET_TCP_H 1 -#define HAVE_PATHS_H 1 -#define HAVE_PUTENV 1 -#define HAVE_STATIC_ASSERT 1 -#define HAVE_STDINT_H 1 -#define HAVE_STDIO_H 1 -#define HAVE_STDLIB_H 1 -#define HAVE_STRINGS_H 1 -#define HAVE_STRING_H 1 -#define HAVE_STRLCAT 1 -#define HAVE_STRLCPY 1 -#define HAVE_STRUCT_ADDRINFO 1 -#define HAVE_STRUCT_IN6_ADDR 1 -#define HAVE_STRUCT_SOCKADDR_IN6 1 -#define HAVE_STRUCT_SOCKADDR_STORAGE 1 -#define HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY 1 -#define HAVE_SYS_RANDOM_H 1 -#define HAVE_SYS_SELECT_H 1 -#define HAVE_SYS_SOCKET_H 1 -#define HAVE_SYS_STAT_H 1 -#define HAVE_SYS_TYPES_H 1 -#define HAVE_SYS_UIO_H 1 -#define HAVE_SYS_WAIT_H 1 -#define HAVE_UINT16_T 1 -#define HAVE_UINT32_T 1 -#define HAVE_UINT8_T 1 -#define HAVE_U_INT16_T 1 -#define HAVE_U_INT32_T 1 -#define HAVE_U_INT8_T 1 -#define HAVE_UNDERSCORE_STATIC_ASSERT 1 -#define HAVE_UNISTD_H 1 -/* NuttX exposes writev(), but keep this port on Dropbear's simpler write() - * path until the SSH-to-NSH channel bridge is validated with vectored - * writes. - */ - -#undef HAVE_WRITEV -#define STDC_HEADERS 1 - -#define PACKAGE_BUGREPORT "" -#define PACKAGE_NAME "" -#define PACKAGE_STRING "" -#define PACKAGE_TARNAME "" -#define PACKAGE_URL "" -#define PACKAGE_VERSION "" - -#define SELECT_TYPE_ARG1 int -#define SELECT_TYPE_ARG234 (fd_set *) -#define SELECT_TYPE_ARG5 (struct timeval *) - -#ifndef PF_UNIX -# define PF_UNIX AF_UNIX -#endif - -#ifndef GRND_NONBLOCK -# define GRND_NONBLOCK O_NONBLOCK -#endif - -#define IPPORT_RESERVED 1024 - -#define getuid dropbear_getuid -#define geteuid dropbear_geteuid -#define getpwuid dropbear_getpwuid -#define getpwnam dropbear_getpwnam -uid_t getuid(void); -uid_t geteuid(void); -struct passwd *getpwuid(uid_t uid); -struct passwd *getpwnam(const char *name); -int dropbear_auth_initialize(void); -int dropbear_verify_password(const char *username, const char *password); - -#ifndef CONFIG_SCHED_USER_IDENTITY -/* NuttX has no supplementary-group support, so getgroups() does not exist. */ - -int dropbear_getgroups(int size, gid_t list[]); - -# define getgroups dropbear_getgroups -#endif - -#endif /* __APPS_NETUTILS_DROPBEAR_PORT_NUTTX_CONFIG_H */ diff --git a/netutils/dropbear/port/nuttx_scp.c b/netutils/dropbear/port/nuttx_scp.c deleted file mode 100644 index 6d7606abe..000000000 --- a/netutils/dropbear/port/nuttx_scp.c +++ /dev/null @@ -1,49 +0,0 @@ -/**************************************************************************** - * apps/netutils/dropbear/port/nuttx_scp.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include "nuttx_scp.h" - -#include -#include - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/* scp only runs in server mode (-t/-f) on NuttX; execvp would only be - * reached in client mode to spawn a local ssh, which is not supported. - */ - -int dropbear_scp_execvp(FAR const char *file, FAR char * const argv[]) -{ - (void)file; - (void)argv; - - set_errno(ENOSYS); - return ERROR; -} diff --git a/netutils/dropbear/port/nuttx_scp.h b/netutils/dropbear/port/nuttx_scp.h deleted file mode 100644 index c5edf799a..000000000 --- a/netutils/dropbear/port/nuttx_scp.h +++ /dev/null @@ -1,39 +0,0 @@ -/**************************************************************************** - * apps/netutils/dropbear/port/nuttx_scp.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __APPS_NETUTILS_DROPBEAR_PORT_NUTTX_SCP_H -#define __APPS_NETUTILS_DROPBEAR_PORT_NUTTX_SCP_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -int dropbear_scp_execvp(FAR const char *file, FAR char * const argv[]); - -#endif /* __APPS_NETUTILS_DROPBEAR_PORT_NUTTX_SCP_H */ diff --git a/netutils/esp8266/CMakeLists.txt b/netutils/esp8266/CMakeLists.txt deleted file mode 100644 index b9232cc60..000000000 --- a/netutils/esp8266/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -# ############################################################################## -# apps/netutils/esp8266/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_NETUTILS_ESP8266) - target_sources(apps PRIVATE esp8266.c) -endif() diff --git a/netutils/esp8266/Make.defs b/netutils/esp8266/Make.defs index 6f9a2f463..d378f3d70 100644 --- a/netutils/esp8266/Make.defs +++ b/netutils/esp8266/Make.defs @@ -1,8 +1,5 @@ -############################################################################ # apps/netutils/esp8266/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -20,6 +17,6 @@ # ############################################################################ -ifneq ($(CONFIG_NETUTILS_ESP8266),) +ifeq ($(CONFIG_NETUTILS_ESP8266),y) CONFIGURED_APPS += $(APPDIR)/netutils/esp8266 endif diff --git a/netutils/esp8266/Makefile b/netutils/esp8266/Makefile index faf0f91a3..357bcb83e 100644 --- a/netutils/esp8266/Makefile +++ b/netutils/esp8266/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/netutils/esp8266/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/netutils/esp8266/esp8266.c b/netutils/esp8266/esp8266.c index 051dd15fc..163b486d0 100644 --- a/netutils/esp8266/esp8266.c +++ b/netutils/esp8266/esp8266.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/netutils/esp8266/esp8266.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -39,12 +37,10 @@ #include #include #include -#include -#include +#include #include #include -#include #include "netutils/esp8266.h" @@ -57,15 +53,15 @@ #define NETAPP_IPCONFIG_MAC_OFFSET (20) #ifndef CONFIG_NETUTILS_ESP8266_MAXTXLEN -# define CONFIG_NETUTILS_ESP8266_MAXTXLEN 256 +# define CONFIG_NETUTILS_ESP8266_MAXTXLEN 256 #endif #ifndef CONFIG_NETUTILS_ESP8266_MAXRXLEN -# define CONFIG_NETUTILS_ESP8266_MAXRXLEN 256 +# define CONFIG_NETUTILS_ESP8266_MAXRXLEN 256 #endif #if (CONFIG_NETUTILS_ESP8266_MAXRXLEN < CONFIG_NETUTILS_ESP8266_WORKER_BUF_LEN) -# error "CONFIG_NETUTILS_ESP8266_WORKER_BUF_LEN would be bigger than CONFIG_NETUTILS_ESP8266_MAXRXLEN" +# error "CONFIG_NETUTILS_ESP8266_WORKER_BUF_LEN would be bigger than CONFIG_NETUTILS_ESP8266_MAXRXLEN" #endif #define BUF_CMD_LEN CONFIG_NETUTILS_ESP8266_MAXTXLEN @@ -149,7 +145,7 @@ typedef struct /* ESP Got only One ip + 1 for NULL that indicate end of list */ - in_addr_t *h_addr_list_buf[2]; + in_addr_t * h_addr_list_buf[2]; in_addr_t in_addr; } lesp_state_t; @@ -315,7 +311,7 @@ static lesp_socket_t *get_sock(int sockfd) if (((unsigned int)sockfd) >= SOCKET_NBR) { errno = EINVAL; - ninfo("Esp8266 invalid sockfd %d\n", sockfd); + ninfo("Esp8266 invalid sockfd\n", sockfd); return NULL; } @@ -1062,7 +1058,8 @@ static int lesp_parse_cwjap_ans_line(char *ptr, lesp_ap_t *ap) case 1: ptr++; /* Remove first '"' */ *(ptr_next - 1) = '\0'; - strlcpy(ap->ssid, ptr, LESP_SSID_SIZE + 1); + strncpy(ap->ssid, ptr, LESP_SSID_SIZE); + ap->ssid[LESP_SSID_SIZE] = '\0'; break; case 2: @@ -1123,7 +1120,6 @@ static int lesp_parse_cwjap_ans_line(char *ptr, lesp_ap_t *ap) * "FreeWifi" => ssid * -90 => rssi * "00:07:cb:07:b6:00" => mac - * 1 => channel * * Note: Content of ptr is modified and string in ap point into ptr string. * @@ -1188,7 +1184,8 @@ static int lesp_parse_cwlap_ans_line(char *ptr, lesp_ap_t *ap) case 2: ptr++; /* Remove first '"' */ *(ptr_next - 1) = '\0'; - strlcpy(ap->ssid, ptr, LESP_SSID_SIZE + 1); + strncpy(ap->ssid, ptr, LESP_SSID_SIZE); + ap->ssid[LESP_SSID_SIZE] = '\0'; break; case 3: @@ -1221,14 +1218,6 @@ static int lesp_parse_cwlap_ans_line(char *ptr, lesp_ap_t *ap) } } break; - - case 5: - { - int i = atoi(ptr); - - ap->channel = i; - } - break; } ptr = ptr_next + 1; @@ -1531,70 +1520,6 @@ int lesp_initialize(void) return 0; } -/**************************************************************************** - * Name: lesp_finalize - * - * Description: - * finalize Esp8266 class. - * - destroy worker thread - * - close port - * - * Input Parameters: - * None - * - * Returned Value: - * 0 on success, -1 in case of error. - * - ****************************************************************************/ - -int lesp_finalize(void) -{ - int i; - - ninfo("Finalizing Esp8266...\n"); - - pthread_mutex_lock(&g_lesp_state.mutex); - - if (!g_lesp_state.is_initialized) - { - pthread_mutex_unlock(&g_lesp_state.mutex); - ninfo("Esp8266 already finalized\n"); - return 0; - } - - pthread_mutex_lock(&g_lesp_state.worker.mutex); - - for (i = 0; i < SOCKET_NBR; i++) - { - if ((g_lesp_state.sockets[i].flags & FLAGS_SOCK_USED) != 0) - { - nerr("ERROR: Exist opened socket\n"); - pthread_mutex_unlock(&g_lesp_state.worker.mutex); - pthread_mutex_unlock(&g_lesp_state.mutex); - return -1; - } - } - - /* Destroy worker thread */ - - g_lesp_state.worker.running = false; - pthread_kill(g_lesp_state.worker.thread, SIGTERM); - pthread_join(g_lesp_state.worker.thread, NULL); - - if (g_lesp_state.fd > 0) - { - close(g_lesp_state.fd); - g_lesp_state.fd = -1; - } - - g_lesp_state.is_initialized = false; - - pthread_mutex_unlock(&g_lesp_state.worker.mutex); - pthread_mutex_unlock(&g_lesp_state.mutex); - - return 0; -} - /**************************************************************************** * Name: lesp_soft_reset * @@ -1844,7 +1769,7 @@ int lesp_get_net(lesp_mode_t mode, in_addr_t *ip, { ninfo("Read:%s\n", g_lesp_state.bufans); - ret = lesp_parse_cipxxx_ans_line(g_lesp_state.bufans, gw); + ret = lesp_parse_cipxxx_ans_line(g_lesp_state.bufans, mask); if (ret < 0) { nerr("ERROR: Line badly formed.\n"); @@ -1912,15 +1837,19 @@ int lesp_set_net(lesp_mode_t mode, in_addr_t ip, if (ret >= 0) { - ret = lesp_ask_ans_ok(LESP_TIMEOUT_MS, "AT+CIP%s_CUR=\"%u.%u.%u.%u\"," - "\"%u.%u.%u.%u\",\"%u.%u.%u.%u\"\r\n", + ret = lesp_ask_ans_ok(LESP_TIMEOUT_MS, "AT+CIP%s_CUR=\"%d.%d.%d.%d\"," + "\"%d.%d.%d.%d\",\"%d.%d.%d.%d\"\r\n", (mode == LESP_MODE_STATION) ? "STA" : "AP", - ip4_addr1(ip), ip4_addr2(ip), - ip4_addr3(ip), ip4_addr4(ip), - ip4_addr1(gateway), ip4_addr2(gateway), - ip4_addr3(gateway), ip4_addr4(gateway), - ip4_addr1(mask), ip4_addr2(mask), - ip4_addr3(mask), ip4_addr4(mask)); + *((uint8_t *)&(ip)+0), *((uint8_t *)&(ip)+1), + *((uint8_t *)&(ip)+2), *((uint8_t *)&(ip)+3), + *((uint8_t *)&(gateway)+0), + *((uint8_t *)&(gateway)+1), + *((uint8_t *)&(gateway)+2), + *((uint8_t *)&(gateway)+3), + *((uint8_t *)&(mask)+0), + *((uint8_t *)&(mask)+1), + *((uint8_t *)&(mask)+2), + *((uint8_t *)&(mask)+3)); } pthread_mutex_unlock(&g_lesp_state.mutex); @@ -2252,7 +2181,7 @@ int lesp_socket(int domain, int type, int protocol) * close socket creates with lesp_socket. * * Input Parameters: - * sockfd Socket descriptor returned by socket() + * sockfd : socket indentifer. * * Returned Value: * A 0 on success; -1 on error. @@ -2356,7 +2285,7 @@ int lesp_connect(int sockfd, FAR const struct sockaddr *addr, socklen_t addrlen) { int ret = 0; - const char *proto_str = ""; + const char *proto_str; lesp_socket_t *sock; struct sockaddr_in *in; unsigned short port; @@ -2409,9 +2338,9 @@ int lesp_connect(int sockfd, FAR const struct sockaddr *addr, if (ret >= 0) { ret = lesp_ask_ans_ok(LESP_TIMEOUT_MS, "AT+CIPSTART=%d,\"%s\"," - "\"%u.%u.%u.%u\",%d\r\n", sockfd, proto_str, - ip4_addr1(ip), ip4_addr2(ip), - ip4_addr3(ip), ip4_addr4(ip), + "\"%d.%d.%d.%d\",%d\r\n", sockfd, proto_str, + *((uint8_t *)&ip + 0), *((uint8_t *)&ip +1), + *((uint8_t *)&ip + 2), *((uint8_t *)&ip + 3), port); if (ret < 0) { diff --git a/netutils/ftpc/CMakeLists.txt b/netutils/ftpc/CMakeLists.txt deleted file mode 100644 index 073e22c3c..000000000 --- a/netutils/ftpc/CMakeLists.txt +++ /dev/null @@ -1,66 +0,0 @@ -# ############################################################################## -# apps/netutils/ftpc/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_NETUTILS_FTPC) - set(CSRCS) - - # FTP connection management - - list(APPEND CSRCS ftpc_connect.c ftpc_disconnect.c) - - # FTP commands - - list( - APPEND - CSRCS - ftpc_cdup.c - ftpc_chdir.c - ftpc_chmod.c - ftpc_filesize.c - ftpc_filetime.c - ftpc_help.c - ftpc_idle.c - ftpc_listdir.c - ftpc_login.c - ftpc_mkdir.c - ftpc_noop.c - ftpc_rpwd.c - ftpc_quit.c - ftpc_rename.c - ftpc_rmdir.c - ftpc_unlink.c - ftpc_cmd.c) - - # FTP transfers - - list(APPEND CSRCS ftpc_getfile.c ftpc_putfile.c ftpc_transfer.c) - - # FTP responses - - list(APPEND CSRCS ftpc_response.c ftpc_getreply.c) - - # FTP helpers - list(APPEND CSRCS ftpc_utils.c ftpc_socket.c) - - target_sources(apps PRIVATE ${CSRCS}) - -endif() diff --git a/netutils/ftpc/Make.defs b/netutils/ftpc/Make.defs index df47acf29..867f85bd8 100644 --- a/netutils/ftpc/Make.defs +++ b/netutils/ftpc/Make.defs @@ -1,8 +1,5 @@ -############################################################################ # apps/netutils/ftpc/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -20,6 +17,6 @@ # ############################################################################ -ifneq ($(CONFIG_NETUTILS_FTPC),) +ifeq ($(CONFIG_NETUTILS_FTPC),y) CONFIGURED_APPS += $(APPDIR)/netutils/ftpc endif diff --git a/netutils/ftpc/Makefile b/netutils/ftpc/Makefile index 8a7ee81f9..16e2850d1 100644 --- a/netutils/ftpc/Makefile +++ b/netutils/ftpc/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/netutils/ftpc/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/netutils/ftpc/README.md b/netutils/ftpc/README.md new file mode 100644 index 000000000..b84980720 --- /dev/null +++ b/netutils/ftpc/README.md @@ -0,0 +1,81 @@ +# Network Utilities / `ftpc` FTP Client + +## FTP Commands + +- `ABOR` โ€“ abort a file transfer +- `ACCT` โ€“ send account information +- `APPE` โ€“ append to a remote file +- `CDUP` โ€“ CWD to the parent of the current directory +- `CWD` โ€“ change working directory +- `DELE` โ€“ delete a remote file +- `HELP` โ€“ return help on using the server +- `LIST` โ€“ list remote files +- `MDTM` โ€“ return the modification time of a file +- `MKD` โ€“ make a remote directory +- `MLSD` โ€“ Standardized directory listing (instead of `LIST`) +- `MLST` โ€“ Standardized object listing (instead of `LIST`) +- `MODE` โ€“ set transfer mode +- `NLST` โ€“ name list of remote directory +- `NOOP` โ€“ do nothing +- `PASS` โ€“ send password +- `PASV` โ€“ enter passive mode +- `PORT` โ€“ open a data port +- `PWD` โ€“ print working directory +- `QUIT` โ€“ terminate the connection +- `REIN` โ€“ reinitialize the connection +- `RETR` โ€“ retrieve a remote file +- `REST` โ€“ Sets the point at which a file transfer should start +- `RMD` โ€“ remove a remote directory +- `RNFR` โ€“ rename from +- `RNTO` โ€“ rename to +- `SITE` โ€“ site-specific commands +- `SIZE` โ€“ return the size of a file +- `STOR` โ€“ store a file on the remote host +- `STOU` โ€“ store a file uniquely +- `STRU` โ€“ set file transfer structure +- `STAT` โ€“ return server status +- `SYST` โ€“ return system type +- `TYPE` โ€“ set transfer type +- `USER` โ€“ send username + +## FTP Replies + +- `110` โ€“ Restart marker reply. +- `120` โ€“ Service ready in nnn minutes. +- `125` โ€“ Data connection already open; transfer starting. +- `150` โ€“ File status okay; about to open data connection. +- `200` โ€“ Command okay. +- `202` โ€“ Command not implemented, superfluous at this site. +- `211` โ€“ System status, or system help reply. +- `212` โ€“ Directory status. +- `213` โ€“ File status. +- `214` โ€“ Help message. +- `215` โ€“ NAME system type. +- `220` โ€“ Service ready for new user. +- `221` โ€“ Service closing control connection. +- `225` โ€“ Data connection open; no transfer in progress. +- `226` โ€“ Closing data connection. +- `227` โ€“ Entering Passive Mode (`h1`, `h2`, `h3`, `h4`, `p1`, `p2`). +- `230` โ€“ User logged in, proceed. +- `250` โ€“ Requested file action okay, completed. +- `257` โ€“ `PATHNAME` created. +- `331` โ€“ User name okay, need password. +- `332` โ€“ Need account for login. +- `350` โ€“ Requested file action pending further information. +- `421` โ€“ Service not available, closing control connection. +- `425` โ€“ Can't open data connection. +- `426` โ€“ Connection closed; transfer aborted. +- `450` โ€“ Requested file action not taken. +- `451` โ€“ Requested action aborted: local error in processing. +- `452` โ€“ Requested action not taken. +- `500` โ€“ Syntax error, command unrecognized. +- `501` โ€“ Syntax error in parameters or arguments. +- `502` โ€“ Command not implemented. +- `503` โ€“ Bad sequence of commands. +- `504` โ€“ Command not implemented for that parameter. +- `530` โ€“ Not logged in. +- `532` โ€“ Need account for storing files. +- `550` โ€“ Requested action not taken. +- `551` โ€“ Requested action aborted: page type unknown. +- `552` โ€“ Requested file action aborted. +- `553` โ€“ Requested action not taken. diff --git a/netutils/ftpc/ftpc_cdup.c b/netutils/ftpc/ftpc_cdup.c index 695991856..25eee2283 100644 --- a/netutils/ftpc/ftpc_cdup.c +++ b/netutils/ftpc/ftpc_cdup.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/netutils/ftpc/ftpc_cdup.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/netutils/ftpc/ftpc_chdir.c b/netutils/ftpc/ftpc_chdir.c index fcfba68ed..de356ed8e 100644 --- a/netutils/ftpc/ftpc_chdir.c +++ b/netutils/ftpc/ftpc_chdir.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/netutils/ftpc/ftpc_chdir.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/netutils/ftpc/ftpc_chmod.c b/netutils/ftpc/ftpc_chmod.c index d9b490b0a..6e949ee0e 100644 --- a/netutils/ftpc/ftpc_chmod.c +++ b/netutils/ftpc/ftpc_chmod.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/netutils/ftpc/ftpc_chmod.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -26,7 +24,7 @@ #include "ftpc_config.h" -#include +#include #include "netutils/ftpc.h" #include "ftpc_internal.h" diff --git a/netutils/ftpc/ftpc_cmd.c b/netutils/ftpc/ftpc_cmd.c index 1e3ff9ea8..08d307041 100644 --- a/netutils/ftpc/ftpc_cmd.c +++ b/netutils/ftpc/ftpc_cmd.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/netutils/ftpc/ftpc_cmd.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -30,7 +28,7 @@ #include #include #include -#include +#include #include "ftpc_internal.h" diff --git a/netutils/ftpc/ftpc_config.h b/netutils/ftpc/ftpc_config.h index 9ac5e08ed..ff429f1d7 100644 --- a/netutils/ftpc/ftpc_config.h +++ b/netutils/ftpc/ftpc_config.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/netutils/ftpc/ftpc_config.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/netutils/ftpc/ftpc_connect.c b/netutils/ftpc/ftpc_connect.c index f28c40b61..1fae79ef7 100644 --- a/netutils/ftpc/ftpc_connect.c +++ b/netutils/ftpc/ftpc_connect.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/netutils/ftpc/ftpc_connect.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -30,7 +28,7 @@ #include #include #include -#include +#include #include @@ -108,11 +106,6 @@ SESSION ftpc_connect(FAR union ftpc_sockaddr_u *server) */ session->homeldir = strdup(ftpc_lpwd()); - if (session->homeldir == NULL) - { - nerr("ERROR: Failed to allocate local home directory\n"); - goto errout_with_alloc; - } /* And (Re-)connect to the server */ @@ -283,10 +276,5 @@ int ftpc_reconnect(FAR struct ftpc_session_s *session) errout_with_socket: ftpc_sockclose(&session->cmd); errout: - if (WDOG_ISACTIVE(&session->wdog)) - { - wd_cancel(&session->wdog); - } - return ERROR; } diff --git a/netutils/ftpc/ftpc_disconnect.c b/netutils/ftpc/ftpc_disconnect.c index 794b1a06b..60224ffe7 100644 --- a/netutils/ftpc/ftpc_disconnect.c +++ b/netutils/ftpc/ftpc_disconnect.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/netutils/ftpc/ftpc_disconnect.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/netutils/ftpc/ftpc_filesize.c b/netutils/ftpc/ftpc_filesize.c index 67df7da3d..2593eac04 100644 --- a/netutils/ftpc/ftpc_filesize.c +++ b/netutils/ftpc/ftpc_filesize.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/netutils/ftpc/ftpc_filesize.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/netutils/ftpc/ftpc_filetime.c b/netutils/ftpc/ftpc_filetime.c index 8a9611803..5f3ab5e81 100644 --- a/netutils/ftpc/ftpc_filetime.c +++ b/netutils/ftpc/ftpc_filetime.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/netutils/ftpc/ftpc_filetime.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/netutils/ftpc/ftpc_getfile.c b/netutils/ftpc/ftpc_getfile.c index 3ca989a80..968ff6286 100644 --- a/netutils/ftpc/ftpc_getfile.c +++ b/netutils/ftpc/ftpc_getfile.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/netutils/ftpc/ftpc_getfile.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -27,12 +25,11 @@ #include "ftpc_config.h" #include -#include #include #include #include #include -#include +#include #include #include "netutils/ftpc.h" @@ -98,7 +95,7 @@ static int ftpc_recvinit(struct ftpc_session_s *session, * transfer should start. This must come after PORT or PASV commands. */ - ret = ftpc_cmd(session, "REST %" PRIdOFF, offset); + ret = ftpc_cmd(session, "REST %ld", offset); if (ret < 0) { nwarn("WARNING: REST command failed: %d\n", errno); diff --git a/netutils/ftpc/ftpc_getreply.c b/netutils/ftpc/ftpc_getreply.c index e63e0ed2b..f964f74b1 100644 --- a/netutils/ftpc/ftpc_getreply.c +++ b/netutils/ftpc/ftpc_getreply.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/netutils/ftpc/ftpc_getreply.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -28,7 +26,7 @@ #include #include -#include +#include #include "ftpc_internal.h" @@ -240,7 +238,7 @@ int fptc_getreply(struct ftpc_session_s *session) { /* Multi-line response */ - strlcpy(tmp, session->reply, sizeof(tmp)); + strncpy(tmp, session->reply, 3); do { if (ftpc_gets(session) == -1) diff --git a/netutils/ftpc/ftpc_help.c b/netutils/ftpc/ftpc_help.c index b1c777f4a..fcf28190d 100644 --- a/netutils/ftpc/ftpc_help.c +++ b/netutils/ftpc/ftpc_help.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/netutils/ftpc/ftpc_help.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/netutils/ftpc/ftpc_idle.c b/netutils/ftpc/ftpc_idle.c index dd5ab5c23..eea2c054b 100644 --- a/netutils/ftpc/ftpc_idle.c +++ b/netutils/ftpc/ftpc_idle.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/netutils/ftpc/ftpc_idle.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -26,7 +24,7 @@ #include "ftpc_config.h" -#include +#include #include "netutils/ftpc.h" #include "ftpc_internal.h" diff --git a/netutils/ftpc/ftpc_internal.h b/netutils/ftpc/ftpc_internal.h index 70e9bb7b9..5cce95a64 100644 --- a/netutils/ftpc/ftpc_internal.h +++ b/netutils/ftpc/ftpc_internal.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/netutils/ftpc/ftpc_internal.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -228,8 +226,7 @@ EXTERN int ftpc_relogin(FAR struct ftpc_session_s *session); /* FTP helpers */ EXTERN void ftpc_reset(struct ftpc_session_s *session); -EXTERN int ftpc_cmd(struct ftpc_session_s *session, const char *cmd, ...) - printf_like(2, 3); +EXTERN int ftpc_cmd(struct ftpc_session_s *session, const char *cmd, ...); EXTERN int fptc_getreply(struct ftpc_session_s *session); EXTERN FAR const char *ftpc_lpwd(void); EXTERN int ftpc_xfrmode(struct ftpc_session_s *session, uint8_t xfrmode); @@ -255,7 +252,7 @@ EXTERN void ftpc_sockcopy(FAR struct ftpc_socket_s *dest, /* Socket I/O helpers */ EXTERN int ftpc_sockprintf(FAR struct ftpc_socket_s *sock, - const char *fmt, ...) printf_like(2, 3); + const char *fmt, ...); EXTERN void ftpc_timeout(wdparm_t arg); /* Transfer helpers */ diff --git a/netutils/ftpc/ftpc_listdir.c b/netutils/ftpc/ftpc_listdir.c index 01ef7dd3a..44c7c9c44 100644 --- a/netutils/ftpc/ftpc_listdir.c +++ b/netutils/ftpc/ftpc_listdir.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/netutils/ftpc/ftpc_listdir.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -33,7 +31,7 @@ #include #include #include -#include +#include #include "netutils/ftpc.h" @@ -257,7 +255,6 @@ FAR struct ftpc_dirlist_s *ftpc_listdir(SESSION handle, FAR char *tmpfname; bool iscurrdir; unsigned int nnames; - unsigned int i; int allocsize; int ret; @@ -366,17 +363,6 @@ FAR struct ftpc_dirlist_s *ftpc_listdir(SESSION handle, ftpc_nlstparse(filestream, ftpc_addname, dirlist); DEBUGASSERT(nnames == dirlist->nnames); - - for (i = 0; i < dirlist->nnames; i++) - { - if (dirlist->name[i] == NULL) - { - nerr("ERROR: Failed to allocate directory name\n"); - ftpc_dirfree(dirlist); - dirlist = NULL; - break; - } - } } errout: diff --git a/netutils/ftpc/ftpc_login.c b/netutils/ftpc/ftpc_login.c index 80a97044a..7691ae44d 100644 --- a/netutils/ftpc/ftpc_login.c +++ b/netutils/ftpc/ftpc_login.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/netutils/ftpc/ftpc_login.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -28,7 +26,7 @@ #include #include -#include +#include #include "netutils/ftpc.h" @@ -172,10 +170,6 @@ int ftpc_relogin(FAR struct ftpc_session_s *session) if (session->homerdir != NULL) { session->currdir = strdup(session->homerdir); - if (session->currdir == NULL) - { - return -ENOMEM; - } } /* If the user has requested a special start up directory, then change to diff --git a/netutils/ftpc/ftpc_mkdir.c b/netutils/ftpc/ftpc_mkdir.c index 53817a378..c065e34eb 100644 --- a/netutils/ftpc/ftpc_mkdir.c +++ b/netutils/ftpc/ftpc_mkdir.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/netutils/ftpc/ftpc_mkdir.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/netutils/ftpc/ftpc_noop.c b/netutils/ftpc/ftpc_noop.c index bc72985b9..f96a4c989 100644 --- a/netutils/ftpc/ftpc_noop.c +++ b/netutils/ftpc/ftpc_noop.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/netutils/ftpc/ftpc_noop.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/netutils/ftpc/ftpc_putfile.c b/netutils/ftpc/ftpc_putfile.c index a0ea6bc3e..5b51c39c2 100644 --- a/netutils/ftpc/ftpc_putfile.c +++ b/netutils/ftpc/ftpc_putfile.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/netutils/ftpc/ftpc_putfile.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -28,14 +26,13 @@ #include #include -#include #include #include #include #include #include #include -#include +#include #include "netutils/ftpc.h" @@ -266,7 +263,7 @@ static int ftpc_sendfile(struct ftpc_session_s *session, const char *path, if (session->offset > 0) { - ret = ftpc_cmd(session, "REST %" PRIdOFF, session->offset); + ret = ftpc_cmd(session, "REST %ld", session->offset); session->size = session->offset; } diff --git a/netutils/ftpc/ftpc_quit.c b/netutils/ftpc/ftpc_quit.c index 28e5acd86..0669e1d95 100644 --- a/netutils/ftpc/ftpc_quit.c +++ b/netutils/ftpc/ftpc_quit.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/netutils/ftpc/ftpc_quit.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/netutils/ftpc/ftpc_rename.c b/netutils/ftpc/ftpc_rename.c index 8b3e761ff..90c1f2efc 100644 --- a/netutils/ftpc/ftpc_rename.c +++ b/netutils/ftpc/ftpc_rename.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/netutils/ftpc/ftpc_rename.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/netutils/ftpc/ftpc_response.c b/netutils/ftpc/ftpc_response.c index ac2040e39..eb3811636 100644 --- a/netutils/ftpc/ftpc_response.c +++ b/netutils/ftpc/ftpc_response.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/netutils/ftpc/ftpc_response.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/netutils/ftpc/ftpc_rmdir.c b/netutils/ftpc/ftpc_rmdir.c index b8db51dc1..f2f90bffc 100644 --- a/netutils/ftpc/ftpc_rmdir.c +++ b/netutils/ftpc/ftpc_rmdir.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/netutils/ftpc/ftpc_rmdir.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/netutils/ftpc/ftpc_rpwd.c b/netutils/ftpc/ftpc_rpwd.c index c2673b20e..fce28e621 100644 --- a/netutils/ftpc/ftpc_rpwd.c +++ b/netutils/ftpc/ftpc_rpwd.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/netutils/ftpc/ftpc_rpwd.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -28,7 +26,7 @@ #include #include -#include +#include #include "netutils/ftpc.h" diff --git a/netutils/ftpc/ftpc_socket.c b/netutils/ftpc/ftpc_socket.c index 4a769a3d3..974bd1212 100644 --- a/netutils/ftpc/ftpc_socket.c +++ b/netutils/ftpc/ftpc_socket.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/netutils/ftpc/ftpc_socket.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -31,7 +29,7 @@ #include #include #include -#include +#include #include #include "ftpc_internal.h" @@ -262,8 +260,7 @@ int ftpc_sockaccept(FAR struct ftpc_socket_s *acceptor, } addrlen = sizeof(addr); - sock->sd = accept4(acceptor->sd, (struct sockaddr *)&addr, &addrlen, - SOCK_CLOEXEC); + sock->sd = accept(acceptor->sd, (struct sockaddr *)&addr, &addrlen); if (sock->sd == -1) { nerr("ERROR: accept() failed: %d\n", errno); diff --git a/netutils/ftpc/ftpc_transfer.c b/netutils/ftpc/ftpc_transfer.c index b6ef5a65c..3517e30e2 100644 --- a/netutils/ftpc/ftpc_transfer.c +++ b/netutils/ftpc/ftpc_transfer.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/netutils/ftpc/ftpc_transfer.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -35,7 +33,7 @@ #include #include #include -#include +#include #include #include "netutils/ftpc.h" @@ -249,10 +247,7 @@ static FAR char *ftpc_abspath(FAR struct ftpc_session_s *session, else if (relpath[1] == '/') { - if (asprintf(&ptr, "%s%s", homedir, &relpath[1]) < 0) - { - ptr = NULL; - } + asprintf(&ptr, "%s%s", homedir, &relpath[1]); } /* Hmmm... this pretty much guaranteed to fail */ @@ -269,10 +264,7 @@ static FAR char *ftpc_abspath(FAR struct ftpc_session_s *session, else if (strncmp(relpath, "./", 2) == 0) { - if (asprintf(&ptr, "%s%s", curdir, relpath + 1) < 0) - { - ptr = NULL; - } + asprintf(&ptr, "%s%s", curdir, relpath + 1); } /* Check for an absolute path */ @@ -286,10 +278,7 @@ static FAR char *ftpc_abspath(FAR struct ftpc_session_s *session, else { - if (asprintf(&ptr, "%s/%s", curdir, relpath) < 0) - { - ptr = NULL; - } + asprintf(&ptr, "%s/%s", curdir, relpath); } return ptr; diff --git a/netutils/ftpc/ftpc_unlink.c b/netutils/ftpc/ftpc_unlink.c index 42ba48d48..2d99d1962 100644 --- a/netutils/ftpc/ftpc_unlink.c +++ b/netutils/ftpc/ftpc_unlink.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/netutils/ftpc/ftpc_unlink.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/netutils/ftpc/ftpc_utils.c b/netutils/ftpc/ftpc_utils.c index 829aa8672..23e461fc0 100644 --- a/netutils/ftpc/ftpc_utils.c +++ b/netutils/ftpc/ftpc_utils.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/netutils/ftpc/ftpc_utils.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The diff --git a/netutils/ftpd/CMakeLists.txt b/netutils/ftpd/CMakeLists.txt deleted file mode 100644 index c8e742a09..000000000 --- a/netutils/ftpd/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -# ############################################################################## -# apps/netutils/ftpd/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_NETUTILS_FTPD) - target_sources(apps PRIVATE ftpd.c) -endif() diff --git a/netutils/ftpd/Kconfig b/netutils/ftpd/Kconfig index b49d4ab71..07f4cda6d 100644 --- a/netutils/ftpd/Kconfig +++ b/netutils/ftpd/Kconfig @@ -13,17 +13,7 @@ config NETUTILS_FTPD if NETUTILS_FTPD config FTPD_WORKERSTACKSIZE - int "FTPD server thread stack size" + int "FTPD client thread stack size" default DEFAULT_TASK_STACKSIZE -config FTPD_LOGIN_PASSWD - bool "Verify FTPD server login with encrypted password file" - default n - depends on FSUTILS_PASSWD - ---help--- - Use the content of an encrypted password file to verify user - credentials. This option requires that you have selected - CONFIG_FSUTILS_PASSWD to enable the access methods of - apps/fsutils/passwd. - endif diff --git a/netutils/ftpd/Make.defs b/netutils/ftpd/Make.defs index 21ed7f819..59ebd84ff 100644 --- a/netutils/ftpd/Make.defs +++ b/netutils/ftpd/Make.defs @@ -1,8 +1,5 @@ -############################################################################ # apps/netutils/ftpd/Make.defs # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The @@ -20,6 +17,6 @@ # ############################################################################ -ifneq ($(CONFIG_NETUTILS_FTPD),) +ifeq ($(CONFIG_NETUTILS_FTPD),y) CONFIGURED_APPS += $(APPDIR)/netutils/ftpd endif diff --git a/netutils/ftpd/Makefile b/netutils/ftpd/Makefile index 244f740d1..2a61453fe 100644 --- a/netutils/ftpd/Makefile +++ b/netutils/ftpd/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/netutils/ftpd/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/netutils/ftpd/ftpd.c b/netutils/ftpd/ftpd.c index c62d9ca73..5d341b75c 100644 --- a/netutils/ftpd/ftpd.c +++ b/netutils/ftpd/ftpd.c @@ -1,11 +1,14 @@ /**************************************************************************** * apps/netutils/ftpd/ftpd.c * - * SPDX-License-Identifier: BSD-3-Clause - * SPDX-FileCopyrightText: 2012, 2015, 2020 Gregory Nutt. - * SPDX-FileCopyrightText: hwport.com. All rights reserved. - * SPDX-FileContributor: Gregory Nutt - * SPDX-FileContributor: Jaehyuk Cho + * Copyright (C) 2012, 2015, 2020 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Includes original code as well as logic adapted from hwport_ftpd, written + * by Jaehyuk Cho which is released under a BSD license. + * + * Copyright (C) hwport.com. All rights reserved. + * Author: Jaehyuk Cho * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -48,7 +51,6 @@ #include #include #include -#include #include #include #include @@ -58,14 +60,10 @@ #include #include #include -#include +#include #include -#ifdef CONFIG_FTPD_LOGIN_PASSWD -# include "fsutils/passwd.h" -#endif - #include "netutils/ftpd.h" #include "ftpd.h" @@ -77,42 +75,41 @@ /* Account functions */ static FAR struct ftpd_account_s *ftpd_account_new(FAR const char *user, - uint8_t accountflags); + uint8_t accountflags); static void ftpd_account_free(FAR struct ftpd_account_s *account); -static int ftpd_account_setpassword(FAR struct ftpd_account_s *account, - FAR const char *passwd); -static int ftpd_account_add(FAR struct ftpd_server_s *server, - FAR struct ftpd_account_s *account); -static int ftpd_account_sethome(FAR struct ftpd_account_s *account, - FAR const char *home); +static int ftpd_account_setpassword(FAR struct ftpd_account_s *account, + FAR const char *passwd); +static int ftpd_account_add(FAR struct ftpd_server_s *server, + FAR struct ftpd_account_s *account); +static int ftpd_account_sethome(FAR struct ftpd_account_s *account, + FAR const char *home); static FAR struct ftpd_account_s * -ftpd_account_search_user(FAR struct ftpd_session_s *session, - FAR const char *user); -static bool ftpd_account_login(FAR struct ftpd_session_s *session, - FAR const char *user, FAR const char *passwd); + ftpd_account_search_user(FAR struct ftpd_session_s *session, + FAR const char *user); +static FAR struct ftpd_account_s * + ftpd_account_login(FAR struct ftpd_session_s *session, + FAR const char *user, FAR const char *passwd); /* Parsing functions */ static FAR char *ftpd_strtok(bool skipspace, FAR const char *delimiters, - FAR char **str); + FAR char **str); static FAR char *ftpd_strtok_alloc(bool skipspace, - FAR const char *delimiters, - FAR const char **str); + FAR const char *delimiters, FAR const char **str); /* Socket helpers */ -static int ftpd_rxpoll(int sd, int timeout); -static int ftpd_txpoll(int sd, int timeout); -static int ftpd_accept(int sd, FAR void *addr, FAR socklen_t *addrlen, - int timeout); +static int ftpd_rxpoll(int sd, int timeout); +static int ftpd_txpoll(int sd, int timeout); +static int ftpd_accept(int sd, FAR void *addr, FAR socklen_t *addrlen, + int timeout); static ssize_t ftpd_recv(int sd, FAR void *data, size_t size, int timeout); static ssize_t ftpd_send(int sd, FAR const void *data, size_t size, - int timeout); -static ssize_t ftpd_response(int sd, int timeout, FAR const char *fmt, ...) - printf_like(3, 4); + int timeout); +static ssize_t ftpd_response(int sd, int timeout, FAR const char *fmt, ...); -static int ftpd_dataopen(FAR struct ftpd_session_s *session); -static int ftpd_dataclose(FAR struct ftpd_session_s *session); +static int ftpd_dataopen(FAR struct ftpd_session_s *session); +static int ftpd_dataclose(FAR struct ftpd_session_s *session); static FAR struct ftpd_server_s *ftpd_openserver(int port, sa_family_t family); @@ -122,29 +119,28 @@ static int ftpd_pathignore(FAR struct ftpd_pathnode_s *currpath); static void ftpd_nodefree(FAR struct ftpd_pathnode_s *node); static FAR struct ftpd_pathnode_s *ftpd_path2node(FAR const char *path); static FAR char *ftpd_node2path(FAR struct ftpd_pathnode_s *node, - bool strip); + bool strip); static FAR struct ftpd_pathnode_s * -ftpd_nodeappend(FAR struct ftpd_pathnode_s *head, - FAR struct ftpd_pathnode_s *node, bool override); -static int ftpd_getpath(FAR struct ftpd_session_s *session, - FAR const char *path, FAR char **abspath, - FAR char **workpath); + ftpd_nodeappend(FAR struct ftpd_pathnode_s *head, + FAR struct ftpd_pathnode_s *node, bool override); +static int ftpd_getpath(FAR struct ftpd_session_s *session, + FAR const char *path, FAR char **abspath, + FAR char **workpath); /* Command helpers */ -static int ftpd_changedir(FAR struct ftpd_session_s *session, - FAR const char *rempath); +static int ftpd_changedir(FAR struct ftpd_session_s *session, + FAR const char *rempath); static off_t ftpd_offsatoi(FAR const char *filename, off_t offset); static int ftpd_stream(FAR struct ftpd_session_s *session, int cmdtype); static uint8_t ftpd_listoption(FAR char **param); -static int ftpd_listbuffer(FAR struct ftpd_session_s *session, - FAR char *path, FAR struct stat *st, - FAR char *buffer, size_t buflen, - unsigned int option); -static int fptd_listscan(FAR struct ftpd_session_s *session, - FAR char *path, unsigned int option); -static int ftpd_list(FAR struct ftpd_session_s *session, - unsigned int option); +static int ftpd_listbuffer(FAR struct ftpd_session_s *session, + FAR char *path, FAR struct stat *st, FAR char *buffer, + size_t buflen, unsigned int opton); +static int fptd_listscan(FAR struct ftpd_session_s *session, + FAR char *path, unsigned int opton); +static int ftpd_list(FAR struct ftpd_session_s *session, + unsigned int opton); /* Command handlers */ @@ -186,8 +182,8 @@ static int ftpd_command(FAR struct ftpd_session_s *session); /* Worker thread */ -static int ftpd_startworker(pthread_startroutine_t handler, FAR void *arg, - size_t stacksize); +static int ftpd_startworker(pthread_startroutine_t handler, FAR void *arg, + size_t stacksize); static void ftpd_freesession(FAR struct ftpd_session_s *session); static void ftpd_workersetup(FAR struct ftpd_session_s *session); static FAR void *ftpd_worker(FAR void *arg); @@ -288,21 +284,21 @@ static FAR struct ftpd_account_s *ftpd_account_new(FAR const char *user, /* Get the size of the allocation */ - if (user == NULL) + allocsize = sizeof(struct ftpd_account_s); + if (!user) { usersize = 0; } else { - usersize = strlen(user) + 1; + usersize = strlen(user); + allocsize += usersize + 1; } - allocsize = sizeof(struct ftpd_account_s) + usersize; - /* Allocate the account and user string */ ret = (struct ftpd_account_s *)zalloc(allocsize); - if (ret == NULL) + if (!ret) { nerr("ERROR: Failed to allocate account\n"); return NULL; @@ -312,10 +308,10 @@ static FAR struct ftpd_account_s *ftpd_account_new(FAR const char *user, ret->flags = accountflags; - if (user != NULL) + if (user) { ret->user = (FAR char *)&ret[1]; - strlcpy(ret->user, user, usersize); + strcpy(ret->user, user); } return ret; @@ -332,26 +328,26 @@ static void ftpd_account_free(FAR struct ftpd_account_s *account) /* Back up to the first entry in the list */ - while (account->blink != NULL) + while (account->blink) { account = account->blink; } /* Then free the entire list */ - while (account != NULL) + while (account) { prev = account; account = account->flink; /* Free the home path and the password */ - if (prev->home != NULL) + if (prev->home) { free(prev->home); } - if (prev->password != NULL) + if (prev->password) { free(prev->password); } @@ -367,7 +363,7 @@ static void ftpd_account_free(FAR struct ftpd_account_s *account) ****************************************************************************/ static int ftpd_account_setpassword(FAR struct ftpd_account_s *account, - FAR const char *passwd) + FAR const char *passwd) { FAR char *temp; DEBUGASSERT(account); @@ -375,10 +371,10 @@ static int ftpd_account_setpassword(FAR struct ftpd_account_s *account, /* Make of copy of the password string (if it is non-null) */ temp = NULL; - if (passwd != NULL) + if (passwd) { temp = strdup(passwd); - if (temp == NULL) + if (!temp) { return -ENOMEM; } @@ -386,7 +382,7 @@ static int ftpd_account_setpassword(FAR struct ftpd_account_s *account, /* Free any existing password string */ - if (account->password != NULL) + if (account->password) { free(account->password); } @@ -411,7 +407,7 @@ static int ftpd_account_add(FAR struct ftpd_server_s *server, /* Find the beginning of the list */ head = account; - while (head->blink != NULL) + while (head->blink) { head = head->blink; } @@ -419,14 +415,14 @@ static int ftpd_account_add(FAR struct ftpd_server_s *server, /* Find the tail of the list */ tail = account; - while (tail->flink != NULL) + while (tail->flink) { tail = tail->flink; } /* Handle the case where the list is empty */ - if (server->head == NULL) + if (!server->head) { server->head = head; } @@ -449,15 +445,15 @@ static int ftpd_account_sethome(FAR struct ftpd_account_s *account, { FAR char *temp; - DEBUGASSERT(account != NULL); + DEBUGASSERT(account); /* Make a copy of the home path string (unless it is NULL) */ temp = NULL; - if (home != NULL) + if (home) { temp = strdup(home); - if (temp == NULL) + if (!temp) { return -ENOMEM; } @@ -465,7 +461,7 @@ static int ftpd_account_sethome(FAR struct ftpd_account_s *account, /* Free any existing home path string */ - if (account->home != NULL) + if (account->home) { free(account->home); } @@ -485,26 +481,26 @@ ftpd_account_search_user(FAR struct ftpd_session_s *session, FAR const char *user) { FAR struct ftpd_account_s *newaccount = NULL; - FAR const struct ftpd_account_s *account; + FAR struct ftpd_account_s *account; uint8_t accountflags; account = session->head; - while (account != NULL) + while (account) { accountflags = account->flags; /* Check if the account has a user */ - if (account->user == NULL) + if (!account->user) { /* No.. The account has no user, was a user name provided? */ - if (user == NULL) + if (!user) { - /* No.. create the account */ + /* Yes.. create the account */ newaccount = ftpd_account_new(NULL, accountflags); - if (newaccount != NULL) + if (newaccount) { if (ftpd_account_setpassword(newaccount, account->password) < 0) @@ -525,7 +521,7 @@ ftpd_account_search_user(FAR struct ftpd_session_s *session, /* Was a user name provided? */ - else if (user != NULL) + else if (user) { /* Check if matches the user name on the account */ @@ -534,7 +530,7 @@ ftpd_account_search_user(FAR struct ftpd_session_s *session, /* Yes.. create the account */ newaccount = ftpd_account_new(account->user, accountflags); - if (newaccount != NULL) + if (newaccount) { if (ftpd_account_setpassword(newaccount, account->password) != 0) @@ -566,50 +562,27 @@ ftpd_account_search_user(FAR struct ftpd_session_s *session, * Name: ftpd_account_login ****************************************************************************/ -static bool ftpd_account_login(FAR struct ftpd_session_s *session, - FAR const char *user, FAR const char *passwd) +static FAR struct ftpd_account_s * +ftpd_account_login(FAR struct ftpd_session_s *session, + FAR const char *user, FAR const char *passwd) { - FAR char *home = NULL; - uint8_t flags; + FAR struct ftpd_account_s *account; + bool pwvalid; + FAR char *home; -#if defined(CONFIG_FTPD_LOGIN_PASSWD) - if (user != NULL && passwd != NULL && - PASSWORD_VERIFY_MATCH(passwd_verify(user, passwd))) + account = ftpd_account_search_user(session, user); + if (!account) { - flags = FTPD_ACCOUNTFLAG_ADMIN; + return NULL; } - else -#endif + + if (!account->password) { - FAR struct ftpd_account_s *account = NULL; - bool pwvalid; - - account = ftpd_account_search_user(session, user); - if (account == NULL) + if (!passwd) { - return false; + pwvalid = true; } - - if (account->password == NULL) - { - if (passwd == NULL) - { - pwvalid = true; - } - else if (passwd[0] == '\0') - { - pwvalid = true; - } - else - { - pwvalid = false; - } - } - else if (passwd == NULL) - { - pwvalid = false; - } - else if (strcmp(passwd, (FAR const char *)account->password) == 0) + else if (passwd[0] == '\0') { pwvalid = true; } @@ -617,74 +590,49 @@ static bool ftpd_account_login(FAR struct ftpd_session_s *session, { pwvalid = false; } - - if (!pwvalid) - { - ftpd_account_free(account); - return false; - } - - if (account->home != NULL) - { - home = strdup(account->home); - if (home == NULL) - { - ftpd_account_free(account); - return false; - } - } - - flags = account->flags; - - ftpd_account_free(account); + } + else if (!passwd) + { + pwvalid = false; + } + else if (strcmp(passwd, (FAR const char *)account->password) == 0) + { + pwvalid = true; + } + else + { + pwvalid = false; } - if (home == NULL) + if (!pwvalid) + { + ftpd_account_free(account); + return NULL; + } + + home = account->home; + if (!home) { home = getenv("HOME"); - if (home == NULL) - { - home = strdup("/"); - } - else - { - home = strdup(home); - } - - if (home == NULL) - { - return false; - } } - if ((flags & FTPD_ACCOUNTFLAG_ADMIN) != 0) + if ((account->flags & FTPD_ACCOUNTFLAG_ADMIN) != 0) { /* admin user */ session->home = strdup("/"); - if (session->home == NULL) - { - free(home); - return false; - } - - session->work = home; + session->work = strdup(!home ? "/" : home); } else { /* normal user */ - session->home = home; + session->home = strdup(!home ? "/" : home); session->work = strdup("/"); - if (session->work == NULL) - { - free(home); - session->home = NULL; - return false; - } } - return true; + ftpd_account_free(account); + return account; } /**************************************************************************** @@ -802,7 +750,7 @@ static FAR char *ftpd_strtok_alloc(bool skipspace, tokenlen = (size_t)(right - left); ret = (FAR char *)malloc(tokenlen + 1); - if (ret != NULL) + if (ret) { if (tokenlen > 0) { @@ -935,7 +883,7 @@ static int ftpd_accept(int sd, FAR void *addr, FAR socklen_t *addrlen, /* Accept the connection -- waiting if necessary */ - acceptsd = accept4(sd, (FAR struct sockaddr *)addr, addrlen, SOCK_CLOEXEC); + acceptsd = accept(sd, (FAR struct sockaddr *)addr, addrlen); if (acceptsd < 0) { int errval = errno; @@ -1010,7 +958,7 @@ static ssize_t ftpd_send(int sd, FAR const void *data, size_t size, ret = send(sd, data, size, 0); if (ret < 0) { - int errval = errno; + ssize_t errval = errno; nerr("ERROR: send() failed: %d\n", errval); return -errval; } @@ -1027,13 +975,12 @@ static ssize_t ftpd_response(int sd, int timeout, FAR const char *fmt, ...) FAR char *buffer; ssize_t bytessent; va_list ap; - int ret; va_start(ap, fmt); - ret = vasprintf(&buffer, fmt, ap); + vasprintf(&buffer, fmt, ap); va_end(ap); - if (ret < 0) + if (!buffer) { return -ENOMEM; } @@ -1176,7 +1123,7 @@ static FAR struct ftpd_server_s *ftpd_openserver(int port, /* Allocate the server instance */ server = (FAR struct ftpd_server_s *)zalloc(sizeof(struct ftpd_server_s)); - if (server == NULL) + if (!server) { nerr("ERROR: Failed to allocate server\n"); return NULL; @@ -1265,7 +1212,7 @@ static int ftpd_pathignore(FAR struct ftpd_pathnode_s *currpath) FAR struct ftpd_pathnode_s *node; size_t namelen; - namelen = currpath->name == NULL ? 0 : strlen(currpath->name); + namelen = !currpath->name ? 0 : strlen(currpath->name); if (namelen == 0) { @@ -1282,11 +1229,11 @@ static int ftpd_pathignore(FAR struct ftpd_pathnode_s *currpath) currpath->ignore = true; node = currpath->blink; - while (node != NULL) + while (node) { if (!node->ignore) { - namelen = node->name == NULL ? 0 : strlen(node->name); + namelen = !node->name ? 0 : strlen(node->name); if (namelen > 0) { @@ -1319,12 +1266,12 @@ static void ftpd_nodefree(FAR struct ftpd_pathnode_s *node) { FAR struct ftpd_pathnode_s *prev; - while (node != NULL) + while (node) { prev = node; node = node->flink; - if (prev->name != NULL) + if (prev->name) { free(prev->name); } @@ -1344,7 +1291,7 @@ static FAR struct ftpd_pathnode_s *ftpd_path2node(FAR const char *path) FAR struct ftpd_pathnode_s *newnode; FAR char *name; - if (path == NULL) + if (!path) { return NULL; } @@ -1352,7 +1299,7 @@ static FAR struct ftpd_pathnode_s *ftpd_path2node(FAR const char *path) while (path[0] != '\0') { name = ftpd_strtok_alloc(false, "/\\", &path); - if (name == NULL) + if (!name) { break; } @@ -1364,7 +1311,7 @@ static FAR struct ftpd_pathnode_s *ftpd_path2node(FAR const char *path) newnode = (FAR struct ftpd_pathnode_s *) malloc(sizeof(struct ftpd_pathnode_s)); - if (newnode == NULL) + if (!newnode) { free(name); ftpd_nodefree(head); @@ -1376,7 +1323,7 @@ static FAR struct ftpd_pathnode_s *ftpd_path2node(FAR const char *path) newnode->ignore = false; newnode->name = name; - if (tail == NULL) + if (!tail) { head = newnode; } @@ -1398,23 +1345,22 @@ static FAR struct ftpd_pathnode_s *ftpd_path2node(FAR const char *path) ****************************************************************************/ static FAR char *ftpd_node2path(FAR struct ftpd_pathnode_s *node, - bool strip) + bool strip) { FAR struct ftpd_pathnode_s *node1; FAR struct ftpd_pathnode_s *node2; FAR char *path; - size_t allocsize; - size_t namelen; - size_t next; + FAR size_t allocsize; + FAR size_t namelen; - if (node == NULL) + if (!node) { return NULL; } allocsize = 0; node1 = node; - while (node1 != NULL) + while (node1) { if (strip) { @@ -1426,18 +1372,18 @@ static FAR char *ftpd_node2path(FAR struct ftpd_pathnode_s *node, } node2 = node1->flink; - while (strip && node2 != NULL) + while (strip && node2) { if (!node2->ignore) { - break; + break; } node2 = node2->flink; } - namelen = node1->name == NULL ? 0 : strlen(node1->name); - if (node2 == NULL) + namelen = !node1->name ? 0 : strlen(node1->name); + if (!node2) { if (namelen <= 0) { @@ -1445,7 +1391,7 @@ static FAR char *ftpd_node2path(FAR struct ftpd_pathnode_s *node, } else { - allocsize += namelen + 1; + allocsize += namelen +1; } } else @@ -1457,16 +1403,16 @@ static FAR char *ftpd_node2path(FAR struct ftpd_pathnode_s *node, } path = (FAR char *)malloc(allocsize); - if (path == NULL) + if (!path) { return NULL; } - next = 0; + allocsize = 0; node1 = node; - while (node1 != NULL) + while (node1) { - if (strip) + if (strip != 0) { if (node1->ignore) { @@ -1476,7 +1422,7 @@ static FAR char *ftpd_node2path(FAR struct ftpd_pathnode_s *node, } node2 = node1->flink; - while (strip && node2 != NULL) + while (strip && node2) { if (!node2->ignore) { @@ -1486,26 +1432,25 @@ static FAR char *ftpd_node2path(FAR struct ftpd_pathnode_s *node, node2 = node2->flink; } - namelen = node1->name == NULL ? 0 : strlen(node1->name); + namelen = !node1->name ? 0 : strlen(node1->name); - if (node2 == NULL) + if (!node2) { if (namelen <= 0) { - snprintf(&path[next], allocsize - next, "/"); + allocsize += sprintf(&path[allocsize], "/"); } else { - snprintf(&path[next], allocsize - next, "%s", node1->name); + allocsize += sprintf(&path[allocsize], "%s", node1->name); } } else { - snprintf(&path[next], allocsize - next, "%s%s", node1->name, "/"); + allocsize += sprintf(&path[allocsize], "%s%s", node1->name, "/"); } node1 = node1->flink; - next += strlen(&path[next]); } return path; @@ -1523,16 +1468,16 @@ ftpd_nodeappend(FAR struct ftpd_pathnode_s *head, if (override) { - if (node != NULL && node->name != NULL && strlen(node->name) <= 0) + if (node && node->name && strlen(node->name) <= 0) { ftpd_nodefree(head); head = NULL; } } - if (head == NULL) + if (!head) { - if (node != NULL) + if (node) { node->blink = NULL; } @@ -1541,7 +1486,7 @@ ftpd_nodeappend(FAR struct ftpd_pathnode_s *head, node = NULL; } - if (node != NULL) + if (node) { temp = head; while (temp->flink) @@ -1556,7 +1501,7 @@ ftpd_nodeappend(FAR struct ftpd_pathnode_s *head, /* clear ignore */ temp = head; - while (temp != NULL) + while (temp) { temp->ignore = false; temp = temp->flink; @@ -1565,7 +1510,7 @@ ftpd_nodeappend(FAR struct ftpd_pathnode_s *head, /* restrip */ temp = head; - while (temp != NULL) + while (temp) { ftpd_pathignore(temp); temp = temp->flink; @@ -1588,18 +1533,18 @@ static int ftpd_getpath(FAR struct ftpd_session_s *session, FAR char *abspath_local; FAR char *workpath_local; - if (abspath != NULL) + if (abspath) { *abspath = NULL; } - if (workpath != NULL) + if (workpath) { *workpath = NULL; } - worknode = ftpd_path2node(session->work == NULL ? "" : session->work); - if (worknode == NULL) + worknode = ftpd_path2node(!session->work ? "" : session->work); + if (!worknode) { return -ENOMEM; } @@ -1608,14 +1553,14 @@ static int ftpd_getpath(FAR struct ftpd_session_s *session, worknode = ftpd_nodeappend(worknode, appendnode, true); workpath_local = ftpd_node2path(worknode, 1); - if (workpath_local == NULL) + if (!workpath_local) { ftpd_nodefree(worknode); return -ENOMEM; } abspath_node = ftpd_path2node(!session->home ? "" : session->home); - if (abspath_node == NULL) + if (!abspath_node) { free(workpath_local); ftpd_nodefree(worknode); @@ -1626,7 +1571,7 @@ static int ftpd_getpath(FAR struct ftpd_session_s *session, abspath_node = ftpd_nodeappend(abspath_node, appendnode, false); abspath_local = ftpd_node2path(abspath_node, 1); - if (abspath_local == NULL) + if (!abspath_local) { free(workpath_local); ftpd_nodefree(abspath_node); @@ -1634,7 +1579,7 @@ static int ftpd_getpath(FAR struct ftpd_session_s *session, return -ENOMEM; } - if (workpath == NULL) + if (!workpath) { free(workpath_local); } @@ -1643,7 +1588,7 @@ static int ftpd_getpath(FAR struct ftpd_session_s *session, *workpath = workpath_local; } - if (abspath == NULL) + if (!abspath) { free(abspath_local); } @@ -1682,20 +1627,24 @@ static int ftpd_changedir(FAR struct ftpd_session_s *session, ret = stat(abspath, &st); if (ret < 0) { + ret = -errno; + free(workpath); free(abspath); - return ftpd_response(session->cmd.sd, session->txtimeout, - g_respfmt2, 550, ' ', rempath, - ": No such file or directory"); + ftpd_response(session->cmd.sd, session->txtimeout, + g_respfmt2, 550, ' ', rempath, + ": No such file or directory"); + return ret; } if (S_ISDIR(st.st_mode) == 0) { free(workpath); free(abspath); - return ftpd_response(session->cmd.sd, session->txtimeout, - g_respfmt2, 550, ' ', rempath, - ": No such file or directory"); + ftpd_response(session->cmd.sd, session->txtimeout, + g_respfmt2, 550, ' ', rempath, + ": No such file or directory"); + return -ENOTDIR; } free(abspath); @@ -1722,7 +1671,7 @@ static off_t ftpd_offsatoi(FAR const char *filename, off_t offset) int ch; outstream = fopen(filename, "r"); - if (outstream == NULL) + if (!outstream) { int errval = errno; nerr("ERROR: Failed to open %s: %d\n", filename, errval); @@ -1793,6 +1742,7 @@ static int ftpd_stream(FAR struct ftpd_session_s *session, int cmdtype) size_t wantsize; ssize_t rdbytes; ssize_t wrbytes; + off_t pos = 0; int errval = 0; int ret; @@ -1834,6 +1784,9 @@ static int ftpd_stream(FAR struct ftpd_session_s *session, int cmdtype) #if defined(O_LARGEFILE) oflags |= O_LARGEFILE; #endif +#if defined(O_BINARY) + oflags |= O_BINARY; +#endif /* Are we creating the file? */ @@ -1921,6 +1874,8 @@ static int ftpd_stream(FAR struct ftpd_session_s *session, int cmdtype) ret = -errval; goto errout_with_session; } + + pos += (off_t)seekoffs; } /* Send success message */ @@ -1978,7 +1933,7 @@ static int ftpd_stream(FAR struct ftpd_session_s *session, int cmdtype) if (rdbytes < 0) { - nerr("ERROR: Read failed: rdbytes=%zu errval=%d\n", + nerr("ERROR: Read failed: rdbytes=%d errval=%d\n", rdbytes, errval); ftpd_response(session->cmd.sd, session->txtimeout, g_respfmt1, 550, ' ', "Data read error !"); @@ -2076,13 +2031,17 @@ static int ftpd_stream(FAR struct ftpd_session_s *session, int cmdtype) if (wrbytes != ((ssize_t)buflen)) { - nerr("ERROR: Write failed: wrbytes=%zu errval=%d\n", + nerr("ERROR: Write failed: wrbytes=%d errval=%d\n", wrbytes, errval); ftpd_response(session->cmd.sd, session->txtimeout, g_respfmt1, 550, ' ', "Data send error !"); - ret = -errval; - break; + ret = -errval; + break; } + + /* Get the next file offset */ + + pos += (off_t)wrbytes; } errout_with_session:; @@ -2167,16 +2126,14 @@ static uint8_t ftpd_listoption(FAR char **param) static int ftpd_listbuffer(FAR struct ftpd_session_s *session, FAR char *path, FAR struct stat *st, FAR char *buffer, - size_t buflen, unsigned int option) + size_t buflen, unsigned int opton) { - UNUSED(session); - FAR char *name; size_t offset = 0; name = basename(path); - if ((option & FTPD_LISTOPTION_L) != 0) + if ((opton & FTPD_LISTOPTION_L) != 0) { FAR const char *str; struct tm tm; @@ -2327,11 +2284,11 @@ static int ftpd_listbuffer(FAR struct ftpd_session_s *session, /* time */ - memcpy(&tm, localtime(&st->st_mtime), sizeof(tm)); + memcpy(&tm, localtime((FAR const time_t *)&st->st_mtime), sizeof(tm)); offset += snprintf(&buffer[offset], buflen - offset, " %s %2u", g_monthtab[tm.tm_mon], tm.tm_mday); now = time(0); - if (now - st->st_mtime > 60 * 60 * 24 * 180) + if ((now - st->st_mtime) > (time_t)(60 * 60 * 24 * 180)) { offset += snprintf(&buffer[offset], buflen - offset, " %5u", tm.tm_year + 1900); @@ -2355,10 +2312,10 @@ static int ftpd_listbuffer(FAR struct ftpd_session_s *session, int namelen; temp = (FAR char *)malloc(PATH_MAX + 1); - if (temp != NULL) + if (temp) { namelen = readlink(path, temp, PATH_MAX); - if (namelen != -1) + if (namelen != (-1))\ { temp[namelen] = '\0'; } @@ -2389,7 +2346,7 @@ static int ftpd_listbuffer(FAR struct ftpd_session_s *session, ****************************************************************************/ static int fptd_listscan(FAR struct ftpd_session_s *session, FAR char *path, - unsigned int option) + unsigned int opton) { FAR char *temp; DIR *dir; @@ -2406,7 +2363,7 @@ static int fptd_listscan(FAR struct ftpd_session_s *session, FAR char *path, if (!S_ISDIR(st.st_mode)) { ret = ftpd_listbuffer(session, path, &st, session->data.buffer, - session->data.buflen, option); + session->data.buflen, opton); if (ret == 0) { ret = ftpd_response(session->data.sd, session->txtimeout, @@ -2417,7 +2374,7 @@ static int fptd_listscan(FAR struct ftpd_session_s *session, FAR char *path, } dir = opendir(path); - if (dir == NULL) + if (!dir) { int errval = errno; nerr("ERROR: opendir() failed: %d\n", errval); @@ -2427,21 +2384,21 @@ static int fptd_listscan(FAR struct ftpd_session_s *session, FAR char *path, for (; ; ) { entry = readdir(dir); - if (entry == NULL) + if (!entry) { break; } if (entry->d_name[0] == '.') { - if ((option & FTPD_LISTOPTION_A) == 0) + if ((opton & FTPD_LISTOPTION_A) == 0) { continue; } } - ret = asprintf(&temp, "%s/%s", path, entry->d_name); - if (ret < 0) + asprintf(&temp, "%s/%s", path, entry->d_name); + if (!temp) { continue; } @@ -2454,7 +2411,7 @@ static int fptd_listscan(FAR struct ftpd_session_s *session, FAR char *path, } ret = ftpd_listbuffer(session, temp, &st, session->data.buffer, - session->data.buflen, option); + session->data.buflen, opton); if (ret >= 0) { ret = ftpd_response(session->data.sd, session->txtimeout, @@ -2476,7 +2433,7 @@ static int fptd_listscan(FAR struct ftpd_session_s *session, FAR char *path, * Name: ftpd_list ****************************************************************************/ -static int ftpd_list(FAR struct ftpd_session_s *session, unsigned int option) +static int ftpd_list(FAR struct ftpd_session_s *session, unsigned int opton) { FAR char *abspath; int ret; @@ -2484,7 +2441,7 @@ static int ftpd_list(FAR struct ftpd_session_s *session, unsigned int option) ret = ftpd_getpath(session, session->param, &abspath, NULL); if (ret >= 0) { - ret = fptd_listscan(session, abspath, option); + ret = fptd_listscan(session, abspath, opton); free(abspath); } @@ -2506,13 +2463,13 @@ static int ftpd_command_user(FAR struct ftpd_session_s *session) /* Free session strings */ - if (session->user != NULL) + if (session->user) { free(session->user); session->user = NULL; } - if (session->renamefrom != NULL) + if (session->renamefrom) { free(session->renamefrom); session->renamefrom = NULL; @@ -2521,7 +2478,7 @@ static int ftpd_command_user(FAR struct ftpd_session_s *session) /* Set up the new user */ session->user = strdup(session->param); - if (session->user == NULL) + if (!session->user) { return ftpd_response(session->cmd.sd, session->txtimeout, g_respfmt1, 451, ' ', "Memory exhausted !"); @@ -2531,42 +2488,37 @@ static int ftpd_command_user(FAR struct ftpd_session_s *session) /* If there is no account information, then no login is required. */ - if (session->head == NULL) + if (!session->head) { FAR char *home; - home = getenv("HOME"); - session->loggedin = false; - session->home = strdup(home == NULL ? "/" : home); - session->work = strdup("/"); - if (session->home == NULL || session->work == NULL) - { - free(session->home); - free(session->work); - session->home = NULL; - session->work = NULL; + home = getenv("HOME"); + session->curr = NULL; + session->home = strdup(!home ? "/" : home); + session->work = strdup("/"); - return ftpd_response(session->cmd.sd, session->txtimeout, - g_respfmt1, 451, ' ', - "Memory exhausted !"); + ret = ftpd_response(session->cmd.sd, session->txtimeout, + g_respfmt1, 230, ' ', "Login successful."); + if (ret < 0) + { + session->curr = NULL; } - return ftpd_response(session->cmd.sd, session->txtimeout, - g_respfmt1, 230, ' ', "Login successful."); + return ret; } - /* Try to login with no password. This will work if no password is + /* Try to login with no password. This willwork if no password is * required for the account. */ - session->loggedin = ftpd_account_login(session, session->param, NULL); - if (session->loggedin) + session->curr = ftpd_account_login(session, session->param, NULL); + if (session->curr) { ret = ftpd_response(session->cmd.sd, session->txtimeout, g_respfmt1, 230, ' ', "Login successful."); if (ret < 0) { - session->loggedin = false; + session->curr = NULL; } return ret; @@ -2587,21 +2539,20 @@ static int ftpd_command_pass(FAR struct ftpd_session_s *session) { int ret; - if (session->user == NULL) + if (!session->user) { return ftpd_response(session->cmd.sd, session->txtimeout, g_respfmt1, 530, ' ', "Please login with USER !"); } - session->loggedin = ftpd_account_login(session, session->user, - session->param); - if (session->loggedin) + session->curr = ftpd_account_login(session, session->user, session->param); + if (session->curr) { ret = ftpd_response(session->cmd.sd, session->txtimeout, g_respfmt1, 230, ' ', "Login successful."); if (ret < 0) { - session->loggedin = false; + session->curr = NULL; } return ret; @@ -2916,7 +2867,7 @@ static int ftpd_command_eprt(FAR struct ftpd_session_s *session) for (index = 0; index < count && *str != '\0'; index++) { field[index] = ftpd_strtok_alloc(true, ",|)", &str); - if (field[index] == NULL) + if (!field[index]) { break; } @@ -2931,14 +2882,15 @@ static int ftpd_command_eprt(FAR struct ftpd_session_s *session) { for (index = 0; index < count; index++) { - if (field[index] != NULL) + if (field[index]) { free(field[index]); } } ftpd_response(session->cmd.sd, session->txtimeout, - g_respfmt1, 502, ' ', "EPRT command not implemented !"); + g_respfmt1, 502, ' ', + "EPRT command not implemented !"); return -EINVAL; } @@ -2975,7 +2927,7 @@ static int ftpd_command_eprt(FAR struct ftpd_session_s *session) for (index = 0; index < count; index++) { - if (field[index] != NULL) + if (field[index]) { free(field[index]); } @@ -2984,7 +2936,8 @@ static int ftpd_command_eprt(FAR struct ftpd_session_s *session) if (family == AF_UNSPEC) { ftpd_response(session->cmd.sd, session->txtimeout, - g_respfmt1, 502, ' ', "EPRT command not implemented !"); + g_respfmt1, 502, ' ', + "EPRT command not implemented !"); return -EINVAL; } @@ -3000,7 +2953,14 @@ static int ftpd_command_pwd(FAR struct ftpd_session_s *session) { FAR const char *workpath; - workpath = session->work == NULL ? "" : session->work; + if (!session->work) + { + workpath = ""; + } + else + { + workpath = session->work; + } return ftpd_response(session->cmd.sd, session->txtimeout, "%03u%c\"%s\" is current directory.\r\n", @@ -3399,7 +3359,7 @@ static int ftpd_command_epsv(FAR struct ftpd_session_s *session) if (ret < 0) { ret = ftpd_response(session->cmd.sd, session->txtimeout, - g_respfmt1, 500, ' ', "EPSV listen fail !"); + g_respfmt1, 500, ' ', "EPSV listen fail !"); ftpd_dataclose(session); return ret; } @@ -3450,7 +3410,7 @@ static int ftpd_command_epsv(FAR struct ftpd_session_s *session) static int ftpd_command_list(FAR struct ftpd_session_s *session) { - uint8_t option = FTPD_LISTOPTION_L; + uint8_t opton = FTPD_LISTOPTION_L; int ret; ret = ftpd_dataopen(session); @@ -3468,8 +3428,8 @@ static int ftpd_command_list(FAR struct ftpd_session_s *session) return ret; } - option |= ftpd_listoption((char **)(&session->param)); - ftpd_list(session, option); + opton |= ftpd_listoption((char **)(&session->param)); + ftpd_list(session, opton); ret = ftpd_response(session->cmd.sd, session->txtimeout, g_respfmt1, 226, ' ', "Transfer complete"); @@ -3484,7 +3444,7 @@ static int ftpd_command_list(FAR struct ftpd_session_s *session) static int ftpd_command_nlst(FAR struct ftpd_session_s *session) { - uint8_t option = 0; + uint8_t opton = 0; int ret; ret = ftpd_dataopen(session); @@ -3502,8 +3462,8 @@ static int ftpd_command_nlst(FAR struct ftpd_session_s *session) return ret; } - option |= ftpd_listoption((char **)(&session->param)); - ftpd_list(session, option); + opton |= ftpd_listoption((char **)(&session->param)); + ftpd_list(session, opton); ret = ftpd_response(session->cmd.sd, session->txtimeout, g_respfmt1, 226, ' ', "Transfer complete"); @@ -3598,7 +3558,7 @@ static int ftpd_command_size(FAR struct ftpd_session_s *session) } outstream = fopen(path, "r"); - if (outstream == NULL) + if (!outstream) { ret = -errno; ftpd_response(session->cmd.sd, session->txtimeout, @@ -3665,7 +3625,7 @@ static int ftpd_command_rnfr(FAR struct ftpd_session_s *session) struct stat st; int ret; - if (session->renamefrom != NULL) + if (session->renamefrom) { free(session->renamefrom); session->renamefrom = NULL; @@ -3704,7 +3664,7 @@ static int ftpd_command_rnto(FAR struct ftpd_session_s *session) FAR char *abspath; int ret; - if (session->renamefrom == NULL) + if (!session->renamefrom) { ftpd_response(session->cmd.sd, session->txtimeout, g_respfmt1, 550, ' ', "RNTO error !"); @@ -3768,7 +3728,11 @@ static int ftpd_command_appe(FAR struct ftpd_session_s *session) static int ftpd_command_rest(FAR struct ftpd_session_s *session) { +#ifdef CONFIG_HAVE_LONG_LONG session->restartpos = (off_t)atoll(session->param); +#else + session->restartpos = (off_t)atoi(session->param); +#endif session->flags |= FTPD_SESSIONFLAG_RESTARTPOS; return ftpd_response(session->cmd.sd, session->txtimeout, @@ -3819,7 +3783,7 @@ static int ftpd_command_mdtm(FAR struct ftpd_session_s *session) free(abspath); - gmtime_r(&st.st_mtime, &tm); + memcpy(&tm, gmtime(&st.st_mtime), sizeof(tm)); return ftpd_response(session->cmd.sd, session->txtimeout, "%03u%c%04u%02u%02u%02u%02u%02u\r\n", 213, ' ', tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, @@ -3870,7 +3834,7 @@ static int ftpd_command_opts(FAR struct ftpd_session_s *session) } lang = getenv("LANG"); - if (lang != NULL) + if (lang) { if (strcasestr(lang, "UTF8") || strcasestr(lang, "UTF-8")) { @@ -3924,9 +3888,9 @@ static int ftpd_command_help(FAR struct ftpd_session_s *session) int ret; index = 0; - while (g_ftpdhelp[index] != NULL) + while (g_ftpdhelp[index]) { - if (index == 0 || g_ftpdhelp[index + 1] == NULL) + if (index == 0 || !g_ftpdhelp[index + 1]) { ret = ftpd_response(session->cmd.sd, session->txtimeout, g_respfmt1, 214, @@ -3960,7 +3924,7 @@ static int ftpd_command(FAR struct ftpd_session_s *session) /* Search the command table for a matching command */ - for (index = 0; g_ftpdcmdtab[index].command != NULL; index++) + for (index = 0; g_ftpdcmdtab[index].command; index++) { /* Does the command string match this entry? */ @@ -3972,7 +3936,7 @@ static int ftpd_command(FAR struct ftpd_session_s *session) { /* Yes... Check if the user is logged in */ - if (!session->loggedin && (session->head != NULL)) + if (!session->curr && session->head) { return ftpd_response(session->cmd.sd, session->txtimeout, g_respfmt1, 530, ' ', @@ -3982,7 +3946,7 @@ static int ftpd_command(FAR struct ftpd_session_s *session) /* Check if there is a handler for the command */ - if (g_ftpdcmdtab[index].handler != NULL) + if (g_ftpdcmdtab[index].handler) { /* Yess.. invoke the command handler. */ @@ -4068,22 +4032,22 @@ static void ftpd_freesession(FAR struct ftpd_session_s *session) { /* Free resources */ - if (session->renamefrom != NULL) + if (session->renamefrom) { free(session->renamefrom); } - if (session->work != NULL) + if (session->work) { free(session->work); } - if (session->home != NULL) + if (session->home) { free(session->home); } - if (session->user != NULL) + if (session->user) { free(session->user); } @@ -4093,14 +4057,14 @@ static void ftpd_freesession(FAR struct ftpd_session_s *session) close(session->fd); } - if (session->data.buffer != NULL) + if (session->data.buffer) { free(session->data.buffer); } ftpd_dataclose(session); - if (session->cmd.buffer != NULL) + if (session->cmd.buffer) { free(session->cmd.buffer); } @@ -4119,8 +4083,6 @@ static void ftpd_freesession(FAR struct ftpd_session_s *session) static void ftpd_workersetup(FAR struct ftpd_session_s *session) { - UNUSED(session); - #if defined(CONFIG_NET_HAVE_IPTOS) || defined(CONFIG_NET_HAVE_OOBINLINE) int temp; #endif @@ -4168,7 +4130,7 @@ static FAR void *ftpd_worker(FAR void *arg) /* Send the welcoming message */ ret = ftpd_response(session->cmd.sd, session->txtimeout, - g_respfmt1, 220, ' ', CONFIG_FTPD_SERVERID); + g_respfmt1, 220, ' ', CONFIG_FTPD_SERVERID); if (ret < 0) { nerr("ERROR: ftpd_response() failed: %d\n", ret); @@ -4285,9 +4247,7 @@ static FAR void *ftpd_worker(FAR void *arg) * used to run the server. * * Input Parameters: - * port - The port that the server will listen to. - * family - The type of INET family to use when opening the socket. - * AF_INET and AF_INET6 are supported. + * None * * Returned Value: * On success, a non-NULL handle is returned that can be used to reference @@ -4295,11 +4255,15 @@ static FAR void *ftpd_worker(FAR void *arg) * ****************************************************************************/ -FTPD_SESSION ftpd_open(int port, sa_family_t family) +FTPD_SESSION ftpd_open(sa_family_t family) { FAR struct ftpd_server_s *server; - server = ftpd_openserver(port, family); + server = ftpd_openserver(21, family); + if (!server) + { + server = ftpd_openserver(2211, family); + } return (FTPD_SESSION)server; } @@ -4337,7 +4301,7 @@ int ftpd_adduser(FTPD_SESSION handle, uint8_t accountflags, DEBUGASSERT(handle); newaccount = ftpd_account_new(user, accountflags); - if (newaccount == NULL) + if (!newaccount) { nerr("ERROR: Failed to allocate memory to the account\n"); ret = -ENOMEM; @@ -4411,7 +4375,7 @@ int ftpd_session(FTPD_SESSION handle, int timeout) session = (FAR struct ftpd_session_s *) zalloc(sizeof(struct ftpd_session_s)); - if (session == NULL) + if (!session) { nerr("ERROR: Failed to allocate session\n"); ret = -ENOMEM; @@ -4422,13 +4386,13 @@ int ftpd_session(FTPD_SESSION handle, int timeout) session->server = server; session->head = server->head; - session->loggedin = false; + session->curr = NULL; session->flags = 0; session->txtimeout = -1; session->rxtimeout = -1; - session->cmd.sd = -1; - session->cmd.addrlen = sizeof(session->cmd.addr); - session->cmd.buflen = CONFIG_FTPD_CMDBUFFERSIZE; + session->cmd.sd = (int)(-1); + session->cmd.addrlen = (socklen_t)sizeof(session->cmd.addr); + session->cmd.buflen = (size_t)CONFIG_FTPD_CMDBUFFERSIZE; session->cmd.buffer = NULL; session->command = NULL; session->param = NULL; @@ -4447,7 +4411,7 @@ int ftpd_session(FTPD_SESSION handle, int timeout) /* Allocate a command buffer */ session->cmd.buffer = (FAR char *)malloc(session->cmd.buflen); - if (session->cmd.buffer == NULL) + if (!session->cmd.buffer) { nerr("ERROR: Failed to allocate command buffer\n"); ret = -ENOMEM; @@ -4457,7 +4421,7 @@ int ftpd_session(FTPD_SESSION handle, int timeout) /* Allocate a data buffer */ session->data.buffer = (FAR char *)malloc(session->data.buflen); - if (session->data.buffer == NULL) + if (!session->data.buffer) { nerr("ERROR: Failed to allocate data buffer\n"); ret = -ENOMEM; diff --git a/netutils/ftpd/ftpd.h b/netutils/ftpd/ftpd.h index 5acea4a28..92805aad8 100644 --- a/netutils/ftpd/ftpd.h +++ b/netutils/ftpd/ftpd.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/netutils/ftpd/ftpd.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -91,8 +89,8 @@ union ftpd_sockaddr_u struct ftpd_account_s { - FAR struct ftpd_account_s *blink; - FAR struct ftpd_account_s *flink; + struct ftpd_account_s *blink; + struct ftpd_account_s *flink; uint8_t flags; /* See FTPD_ACCOUNTFLAG_* definitions */ FAR char *user; /* User name */ FAR char *password; /* Un-encrypted password */ @@ -105,8 +103,8 @@ struct ftpd_server_s { int sd; /* Listen socket descriptor */ union ftpd_sockaddr_u addr; /* Listen address */ - FAR struct ftpd_account_s *head; /* Head of a list of accounts */ - FAR struct ftpd_account_s *tail; /* Tail of a list of accounts */ + struct ftpd_account_s *head; /* Head of a list of accounts */ + struct ftpd_account_s *tail; /* Tail of a list of accounts */ }; struct ftpd_stream_s @@ -120,12 +118,12 @@ struct ftpd_stream_s struct ftpd_session_s { - FAR const struct ftpd_server_s *server; - FAR const struct ftpd_account_s *head; - bool loggedin; - uint8_t flags; /* See TPD_SESSIONFLAG_* definitions */ - int rxtimeout; - int txtimeout; + FAR struct ftpd_server_s *server; + FAR struct ftpd_account_s *head; + FAR struct ftpd_account_s *curr; + uint8_t flags; /* See TPD_SESSIONFLAG_* definitions */ + int rxtimeout; + int txtimeout; /* Command */ @@ -151,7 +149,7 @@ struct ftpd_session_s FAR char *renamefrom; }; -typedef int (*ftpd_cmdhandler_t)(FAR struct ftpd_session_s *); +typedef int (*ftpd_cmdhandler_t)(struct ftpd_session_s *); struct ftpd_cmd_s { diff --git a/netutils/iperf/CMakeLists.txt b/netutils/iperf/CMakeLists.txt deleted file mode 100644 index a566030c7..000000000 --- a/netutils/iperf/CMakeLists.txt +++ /dev/null @@ -1,40 +0,0 @@ -# ############################################################################## -# apps/netutils/iperf/CMakeLists.txt -# -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed to the Apache Software Foundation (ASF) under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. The ASF licenses this -# file to you under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# -# ############################################################################## - -if(CONFIG_NETUTILS_IPERF) - - # iperf example! built-in application info - - nuttx_add_application( - NAME - ${CONFIG_NETUTILS_IPERF_PROGNAME} - SRCS - iperf_main.c - STACKSIZE - ${CONFIG_NETUTILS_IPERF_STACKSIZE} - PRIORITY - ${CONFIG_NETUTILS_IPERF_PRIORITY}) - - # Iperf Example - - target_sources(apps PRIVATE iperf.c) -endif() diff --git a/netutils/iperf/Kconfig b/netutils/iperf/Kconfig index cec02e768..3cebb9c68 100644 --- a/netutils/iperf/Kconfig +++ b/netutils/iperf/Kconfig @@ -2,7 +2,7 @@ # For a description of the syntax of this configuration file, # see the file kconfig-language.txt in the NuttX tools repository. # - + config NETUTILS_IPERF bool "iperf example" default n @@ -14,7 +14,7 @@ config NETUTILS_IPERF Enable the \"iperf example\" if NETUTILS_IPERF - + config NETUTILS_IPERF_PROGNAME string "Program name" default "iperf" @@ -31,13 +31,7 @@ config NETUTILS_IPERF_STACKSIZE default DEFAULT_TASK_STACKSIZE config NETUTILS_IPERFTEST_DEVNAME - string "iperf Network device" - default "wlan0" if DRIVERS_IEEE80211 - default "wpan0" if NET_6LOWPAN - default "sl0" if NET_SLIP - default "tun0" if NET_TUN - default "can0" if NET_CAN - default "eth0" if NET_ETHERNET - default "lo" # if NET_LOOPBACK + string "Wi-Fi Network device" + default "wlan0" endif diff --git a/netutils/iperf/Make.defs b/netutils/iperf/Make.defs index 893564b3f..0e1213682 100644 --- a/netutils/iperf/Make.defs +++ b/netutils/iperf/Make.defs @@ -1,7 +1,6 @@ ############################################################################ # apps/netutils/iperf/Make.defs -# -# SPDX-License-Identifier: Apache-2.0 +# Adds selected applications to apps/ build # # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with diff --git a/netutils/iperf/Makefile b/netutils/iperf/Makefile index 148026ecc..9db5e0cc5 100644 --- a/netutils/iperf/Makefile +++ b/netutils/iperf/Makefile @@ -1,8 +1,6 @@ ############################################################################ # apps/netutils/iperf/Makefile # -# SPDX-License-Identifier: Apache-2.0 -# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. The diff --git a/netutils/iperf/README.md b/netutils/iperf/README.md new file mode 100644 index 000000000..89d95feb1 --- /dev/null +++ b/netutils/iperf/README.md @@ -0,0 +1,94 @@ +Overview +================================================================ + +This is a NuttX port of the ESP-IDF iperf example. [1] + +It doesn't support all features in standard iperf. +It's supposed to be compatible with iperf version 2.x. [2] + +[1] https://github.com/espressif/esp-idf/tree/master/examples/wifi/iperf +[2] https://sourceforge.net/projects/iperf2/ + +Configuring NuttX to use your Wireless Router (aka Access Point) +================================================================ + + Since you are already in the root of NuttX/ repository, execute + make menuconfig to define your Wireless Router and your password: + + $ make menuconfig + + Browser the menus this way: + + Application Configuration ---> + Network Utilities ---> + Networking Configuration ---> + WAPI Configuration ---> + (myApSSID) SSID + (mySSIDpassphrase) Passprhase + + Replace the SSID from myApSSID with your wireless router name and + the Passprhase with your WiFi password. + + Exit and save your configuration. + +iperf Test Example +=================================== + +To set up, do `make menuconfig` and select the Apps > netutils > iperf example. By default, NuttX will the be the client +which sends data; and the host computer (Linux, macOS, or Windows) will be the server. + +Set up networking so the NuttX computer can ping the host, and the host can ping NuttX. Now you are ready to run the +test. + +If you are using a wireless network card, you must first connect to the router: + +On host: + + $ iperf -s -p 5471 -i 1 -w 416K + ------------------------------------------------------------ + Server listening on TCP port 5471 + TCP window size: 416 KByte + ------------------------------------------------------------ + +On NuttX: + + nsh> iperf -c 192.168.1.181 -p 5471 -i 1 -t 10 + mode=tcp-client sip=192.168.1.198:5001, dip=192.168.1.181:5471, interval=1, time=10 + + Interval Bandwidth + + 0- 1 sec, 0.39 Mbits/sec + 1- 2 sec, 0.26 Mbits/sec + 2- 3 sec, 0.39 Mbits/sec + 3- 4 sec, 0.26 Mbits/sec + 4- 5 sec, 0.26 Mbits/sec + 5- 6 sec, 0.26 Mbits/sec + 6- 7 sec, 0.26 Mbits/sec + 7- 8 sec, 0.26 Mbits/sec + 8- 9 sec, 0.26 Mbits/sec + 9- 10 sec, 0.26 Mbits/sec + 0- 10 sec, 0.28 Mbits/sec + +Now on the host you should see something like: + + $ iperf -s -p 5471 -i 1 -w 416K + ------------------------------------------------------------ + Server listening on TCP port 5471 + TCP window size: 416 KByte + ------------------------------------------------------------ + [ 5] local 192.168.1.181 port 5471 connected with 192.168.1.198 port 4210 + [ 5] 0.0- 1.0 sec 60.8 KBytes 498 Kbits/sec + [ 5] 1.0- 2.0 sec 34.9 KBytes 286 Kbits/sec + [ 5] 2.0- 3.0 sec 33.7 KBytes 276 Kbits/sec + [ 5] 3.0- 4.0 sec 33.4 KBytes 274 Kbits/sec + [ 5] 4.0- 5.0 sec 32.0 KBytes 262 Kbits/sec + [ 5] 5.0- 6.0 sec 32.0 KBytes 262 Kbits/sec + [ 5] 6.0- 7.0 sec 33.4 KBytes 274 Kbits/sec + [ 5] 7.0- 8.0 sec 32.0 KBytes 262 Kbits/sec + [ 5] 8.0- 9.0 sec 32.0 KBytes 262 Kbits/sec + [ 5] 9.0-10.0 sec 33.4 KBytes 274 Kbits/sec + [ 5] 0.0-10.3 sec 368 KBytes 292 Kbits/sec + + +This will tell you the link speed in Kbits/sec โ€“ kilobits per second. If you want kilobytes, divide by 8. + diff --git a/netutils/iperf/iperf.c b/netutils/iperf/iperf.c index 97ebf639f..44b362c70 100644 --- a/netutils/iperf/iperf.c +++ b/netutils/iperf/iperf.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/netutils/iperf/iperf.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -24,20 +22,13 @@ * Included Files ****************************************************************************/ -#include -#include -#include -#include -#include -#include -#include -#include -#include #include #include -#include -#include - +#include +#include +#include +#include +#include #include "iperf.h" /**************************************************************************** @@ -48,8 +39,9 @@ #define IPERF_TRAFFIC_TASK_PRIORITY 100 #define IPERF_TRAFFIC_TASK_STACK 4096 #define IPERF_REPORT_TASK_NAME "iperf_report" -#define IPERF_REPORT_TASK_PRIORITY 101 +#define IPERF_REPORT_TASK_PRIORITY 100 #define IPERF_REPORT_TASK_STACK 4096 +#define IPERF_REPORT_TASK_NAME "iperf_report" #define IPERF_UDP_TX_LEN (1472) #define IPERF_UDP_RX_LEN (16 << 10) @@ -65,12 +57,11 @@ struct iperf_ctrl_t { - FAR struct iperf_ctrl_t *flink; struct iperf_cfg_t cfg; bool finish; uintmax_t total_len; uint32_t buffer_len; - FAR uint8_t *buffer; + uint8_t *buffer; uint32_t sockfd; }; @@ -81,39 +72,31 @@ struct iperf_udp_pkt_t uint32_t usec; }; -typedef CODE int (*iperf_client_func_t)(FAR struct iperf_ctrl_t *ctrl, - FAR struct sockaddr *addr, - socklen_t addrlen); -typedef CODE int (*iperf_server_func_t)(FAR struct iperf_ctrl_t *ctrl, - FAR struct sockaddr *addr, - socklen_t addrlen, - FAR struct sockaddr *remote_addr); - /**************************************************************************** * Private Data ****************************************************************************/ -static pthread_mutex_t g_iperf_ctrl_mutex = PTHREAD_MUTEX_INITIALIZER; -static sq_queue_t g_iperf_ctrl_list; +static bool s_iperf_is_running = false; +static struct iperf_ctrl_t s_iperf_ctrl; /**************************************************************************** * Private Functions Prototypes ****************************************************************************/ -inline static bool iperf_is_udp_client(FAR struct iperf_ctrl_t *ctrl); -inline static bool iperf_is_udp_server(FAR struct iperf_ctrl_t *ctrl); -inline static bool iperf_is_tcp_client(FAR struct iperf_ctrl_t *ctrl); -inline static bool iperf_is_tcp_server(FAR struct iperf_ctrl_t *ctrl); +inline static bool iperf_is_udp_client(void); +inline static bool iperf_is_udp_server(void); +inline static bool iperf_is_tcp_client(void); +inline static bool iperf_is_tcp_server(void); static int iperf_get_socket_error_code(int sockfd); -static int iperf_show_socket_error_reason(FAR const char *str, int sockfd); -static void iperf_report_task(FAR void *arg); -static int iperf_start_report(FAR struct iperf_ctrl_t *ctrl); -static int iperf_run_tcp_server(FAR struct iperf_ctrl_t *ctrl); -static int iperf_run_udp_server(FAR struct iperf_ctrl_t *ctrl); -static int iperf_run_udp_client(FAR struct iperf_ctrl_t *ctrl); -static int iperf_run_tcp_client(FAR struct iperf_ctrl_t *ctrl); -static void iperf_task_traffic(FAR void *arg); -static uint32_t iperf_get_buffer_len(FAR struct iperf_ctrl_t *ctrl); +static int iperf_show_socket_error_reason(const char *str, int sockfd); +static void iperf_report_task(void *arg); +static int iperf_start_report(void); +static int iperf_run_tcp_server(void); +static int iperf_run_udp_server(void); +static int iperf_run_udp_client(void); +static int iperf_run_tcp_client(void); +static void iperf_task_traffic(void *arg); +static uint32_t iperf_get_buffer_len(void); /**************************************************************************** * Private Functions @@ -127,10 +110,10 @@ static uint32_t iperf_get_buffer_len(FAR struct iperf_ctrl_t *ctrl); * ****************************************************************************/ -inline static bool iperf_is_udp_client(FAR struct iperf_ctrl_t *ctrl) +inline static bool iperf_is_udp_client(void) { - return ((ctrl->cfg.flag & IPERF_FLAG_CLIENT) - && (ctrl->cfg.flag & IPERF_FLAG_UDP)); + return ((s_iperf_ctrl.cfg.flag & IPERF_FLAG_CLIENT) + && (s_iperf_ctrl.cfg.flag & IPERF_FLAG_UDP)); } /**************************************************************************** @@ -141,10 +124,10 @@ inline static bool iperf_is_udp_client(FAR struct iperf_ctrl_t *ctrl) * ****************************************************************************/ -inline static bool iperf_is_udp_server(FAR struct iperf_ctrl_t *ctrl) +inline static bool iperf_is_udp_server(void) { - return ((ctrl->cfg.flag & IPERF_FLAG_SERVER) - && (ctrl->cfg.flag & IPERF_FLAG_UDP)); + return ((s_iperf_ctrl.cfg.flag & IPERF_FLAG_SERVER) + && (s_iperf_ctrl.cfg.flag & IPERF_FLAG_UDP)); } /**************************************************************************** @@ -155,10 +138,10 @@ inline static bool iperf_is_udp_server(FAR struct iperf_ctrl_t *ctrl) * ****************************************************************************/ -inline static bool iperf_is_tcp_client(FAR struct iperf_ctrl_t *ctrl) +inline static bool iperf_is_tcp_client(void) { - return ((ctrl->cfg.flag & IPERF_FLAG_CLIENT) - && (ctrl->cfg.flag & IPERF_FLAG_TCP)); + return ((s_iperf_ctrl.cfg.flag & IPERF_FLAG_CLIENT) + && (s_iperf_ctrl.cfg.flag & IPERF_FLAG_TCP)); } /**************************************************************************** @@ -169,10 +152,10 @@ inline static bool iperf_is_tcp_client(FAR struct iperf_ctrl_t *ctrl) * ****************************************************************************/ -inline static bool iperf_is_tcp_server(FAR struct iperf_ctrl_t *ctrl) +inline static bool iperf_is_tcp_server(void) { - return ((ctrl->cfg.flag & IPERF_FLAG_SERVER) - && (ctrl->cfg.flag & IPERF_FLAG_TCP)); + return ((s_iperf_ctrl.cfg.flag & IPERF_FLAG_SERVER) + && (s_iperf_ctrl.cfg.flag & IPERF_FLAG_TCP)); } /**************************************************************************** @@ -196,61 +179,18 @@ static int iperf_get_socket_error_code(int sockfd) * ****************************************************************************/ -static int iperf_show_socket_error_reason(FAR const char *str, int sockfd) +static int iperf_show_socket_error_reason(const char *str, int sockfd) { int err = errno; if (err != 0) { - printf("%s error, error code: %d, reason: %s\n", + printf("%s error, error code: %d, reason: %s", str, err, strerror(err)); } return err; } -/**************************************************************************** - * Name: iperf_print_addr - * - * Description: - * Print addr info - * - ****************************************************************************/ - -static void iperf_print_addr(FAR const char *str, FAR struct sockaddr *addr) -{ - switch (addr->sa_family) - { -#ifdef CONFIG_NET_IPv4 - case AF_INET: - { - FAR struct sockaddr_in *inaddr = (FAR struct sockaddr_in *)addr; - printf("%s: %s:%d\n", str, - inet_ntoa(inaddr->sin_addr), htons(inaddr->sin_port)); - return; - } -#endif - - case AF_LOCAL: - { - FAR struct sockaddr_un *unaddr = (FAR struct sockaddr_un *)addr; - printf("%s: path=%s\n", str, unaddr->sun_path); - return; - } - - case AF_RPMSG: - { - FAR struct sockaddr_rpmsg *rpaddr = - (FAR struct sockaddr_rpmsg *)addr; - printf("%s: cpu=%s,name=%s\n", str, - rpaddr->rp_cpu, rpaddr->rp_name); - return; - } - - default: - assert(false); /* shouldn't happen */ - } -} - /**************************************************************************** * Name: ts_sec * @@ -285,19 +225,16 @@ static double ts_diff(const struct timespec *a, const struct timespec *b) * ****************************************************************************/ -static void iperf_report_task(FAR void *arg) +static void iperf_report_task(void *arg) { - FAR struct iperf_ctrl_t *ctrl = arg; - uint32_t interval = ctrl->cfg.interval; - uint32_t time = ctrl->cfg.time; + uint32_t interval = s_iperf_ctrl.cfg.interval; + uint32_t time = s_iperf_ctrl.cfg.time; struct timespec now; struct timespec start; uintmax_t now_len; int ret; - prctl(PR_SET_NAME, IPERF_REPORT_TASK_NAME); - - now_len = ctrl->total_len; + now_len = s_iperf_ctrl.total_len; ret = clock_gettime(CLOCK_MONOTONIC, &now); if (ret != 0) { @@ -307,7 +244,7 @@ static void iperf_report_task(FAR void *arg) start = now; printf("\n%19s %16s %18s\n", "Interval", "Transfer", "Bandwidth\n"); - while (!ctrl->finish) + while (!s_iperf_ctrl.finish) { uintmax_t last_len; struct timespec last; @@ -315,7 +252,7 @@ static void iperf_report_task(FAR void *arg) sleep(interval); last_len = now_len; last = now; - now_len = ctrl->total_len; + now_len = s_iperf_ctrl.total_len; ret = clock_gettime(CLOCK_MONOTONIC, &now); if (ret != 0) { @@ -326,10 +263,9 @@ static void iperf_report_task(FAR void *arg) printf("%7.2lf-%7.2lf sec %10ju Bytes %7.2f Mbits/sec\n", ts_diff(&last, &start), ts_diff(&now, &start), - now_len -last_len, - (((now_len - last_len) * 8) / 1000000.0) / - ts_diff(&now, &last) - ); + now_len, + (((double)(now_len - last_len) * 8) / + ts_diff(&now, &last) / 1e6)); if (time != 0 && ts_diff(&now, &start) >= time) { break; @@ -342,12 +278,11 @@ static void iperf_report_task(FAR void *arg) ts_diff(&start, &start), ts_diff(&now, &start), now_len, - ((now_len * 8) / 1000000.0) / - ts_diff(&now, &start) - ); + (((double)now_len * 8) / + ts_diff(&now, &start) / 1e6)); } - ctrl->finish = true; + s_iperf_ctrl.finish = true; pthread_exit(NULL); } @@ -360,20 +295,20 @@ static void iperf_report_task(FAR void *arg) * ****************************************************************************/ -static int iperf_start_report(FAR struct iperf_ctrl_t *ctrl) +static int iperf_start_report(void) { + int ret; + pthread_t thread; struct sched_param param; pthread_attr_t attr; - pthread_t thread; - int ret; pthread_attr_init(&attr); param.sched_priority = IPERF_REPORT_TASK_PRIORITY; pthread_attr_setschedparam(&attr, ¶m); pthread_attr_setstacksize(&attr, IPERF_REPORT_TASK_STACK); - ret = pthread_create(&thread, &attr, (FAR void *)iperf_report_task, - ctrl); + ret = pthread_create(&thread, &attr, (void *)iperf_report_task, + IPERF_REPORT_TASK_NAME); if (ret != 0) { printf("iperf_thread: pthread_create failed: %d, %s\n", @@ -387,116 +322,27 @@ static int iperf_start_report(FAR struct iperf_ctrl_t *ctrl) } /**************************************************************************** - * Name: iperf_run_server + * Name: iperf_run_tcp_server * * Description: - * Start a server + * Start tcp server * ****************************************************************************/ -static int iperf_run_server(FAR struct iperf_ctrl_t *ctrl, - iperf_server_func_t server_func) -{ - if (ctrl->cfg.flag & IPERF_FLAG_LOCAL) - { - struct sockaddr_un addr; - struct sockaddr_un remote_addr; - - addr.sun_family = AF_LOCAL; - strlcpy(addr.sun_path, ctrl->cfg.path, sizeof(addr.sun_path)); - - return server_func(ctrl, (FAR struct sockaddr *)&addr, sizeof(addr), - (FAR struct sockaddr *)&remote_addr); - } - else if (ctrl->cfg.flag & IPERF_FLAG_RPMSG) - { - struct sockaddr_rpmsg addr; - struct sockaddr_rpmsg remote_addr; - - addr.rp_family = AF_RPMSG; - strlcpy(addr.rp_cpu, ctrl->cfg.host, sizeof(addr.rp_cpu)); - strlcpy(addr.rp_name, ctrl->cfg.path, sizeof(addr.rp_name)); - - return server_func(ctrl, (FAR struct sockaddr *)&addr, sizeof(addr), - (FAR struct sockaddr *)&remote_addr); - } - else - { - struct sockaddr_in addr; - struct sockaddr_in remote_addr; - - addr.sin_family = AF_INET; - addr.sin_port = htons(ctrl->cfg.sport); - addr.sin_addr.s_addr = ctrl->cfg.sip; - - return server_func(ctrl, (FAR struct sockaddr *)&addr, sizeof(addr), - (FAR struct sockaddr *)&remote_addr); - } -} - -/**************************************************************************** - * Name: iperf_run_client - * - * Description: - * Start a client - * - ****************************************************************************/ - -static int iperf_run_client(FAR struct iperf_ctrl_t *ctrl, - iperf_client_func_t client_func) -{ - if (ctrl->cfg.flag & IPERF_FLAG_LOCAL) - { - struct sockaddr_un addr; - - addr.sun_family = AF_LOCAL; - strlcpy(addr.sun_path, ctrl->cfg.path, sizeof(addr.sun_path)); - - return client_func(ctrl, (FAR struct sockaddr *)&addr, sizeof(addr)); - } - else if (ctrl->cfg.flag & IPERF_FLAG_RPMSG) - { - struct sockaddr_rpmsg addr; - - addr.rp_family = AF_RPMSG; - strlcpy(addr.rp_cpu, ctrl->cfg.host, sizeof(addr.rp_cpu)); - strlcpy(addr.rp_name, ctrl->cfg.path, sizeof(addr.rp_name)); - - return client_func(ctrl, (FAR struct sockaddr *)&addr, sizeof(addr)); - } - else - { - struct sockaddr_in addr; - - addr.sin_family = AF_INET; - addr.sin_port = htons(ctrl->cfg.dport); - addr.sin_addr.s_addr = ctrl->cfg.dip; - - return client_func(ctrl, (FAR struct sockaddr *)&addr, sizeof(addr)); - } -} - -/**************************************************************************** - * Name: iperf_tcp_server - * - * Description: - * The main tcp server logic - * - ****************************************************************************/ - -static int iperf_tcp_server(FAR struct iperf_ctrl_t *ctrl, - FAR struct sockaddr *addr, socklen_t addrlen, - FAR struct sockaddr *remote_addr) +static int iperf_run_tcp_server(void) { + socklen_t addr_len = sizeof(struct sockaddr); + struct sockaddr_in remote_addr; + struct sockaddr_in addr; int actual_recv = 0; int want_recv = 0; - FAR uint8_t *buffer; + uint8_t *buffer; int listen_socket; struct timeval t; int sockfd; int opt; - listen_socket = socket(addr->sa_family, SOCK_STREAM, IPPROTO_TCP); + listen_socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (listen_socket < 0) { iperf_show_socket_error_reason("tcp server create", listen_socket); @@ -504,7 +350,10 @@ static int iperf_tcp_server(FAR struct iperf_ctrl_t *ctrl, } setsockopt(listen_socket, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)); - if (bind(listen_socket, addr, addrlen) != 0) + addr.sin_family = AF_INET; + addr.sin_port = htons(s_iperf_ctrl.cfg.sport); + addr.sin_addr.s_addr = s_iperf_ctrl.cfg.sip; + if (bind(listen_socket, (struct sockaddr *)&addr, sizeof(addr)) != 0) { iperf_show_socket_error_reason("tcp server bind", listen_socket); close(listen_socket); @@ -518,13 +367,14 @@ static int iperf_tcp_server(FAR struct iperf_ctrl_t *ctrl, return -1; } - buffer = ctrl->buffer; - want_recv = ctrl->buffer_len; - while (!ctrl->finish) + buffer = s_iperf_ctrl.buffer; + want_recv = s_iperf_ctrl.buffer_len; + while (!s_iperf_ctrl.finish) { /* TODO need to change to non-block mode */ - sockfd = accept4(listen_socket, remote_addr, &addrlen, SOCK_CLOEXEC); + sockfd = accept(listen_socket, (struct sockaddr *)&remote_addr, + &addr_len); if (sockfd < 0) { iperf_show_socket_error_reason("tcp server listen", listen_socket); @@ -533,133 +383,52 @@ static int iperf_tcp_server(FAR struct iperf_ctrl_t *ctrl, } else { - iperf_print_addr("accept", remote_addr); - iperf_start_report(ctrl); + printf("accept: %s,%d\n", inet_ntoa(remote_addr.sin_addr), + htons(remote_addr.sin_port)); + iperf_start_report(); t.tv_sec = IPERF_SOCKET_RX_TIMEOUT; - t.tv_usec = 0; setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &t, sizeof(t)); } - while (!ctrl->finish) + while (!s_iperf_ctrl.finish) { actual_recv = recv(sockfd, buffer, want_recv, 0); if (actual_recv == 0) { - iperf_print_addr("closed by the peer", remote_addr); + printf("closed by the peer: %s,%d\n", + inet_ntoa(remote_addr.sin_addr), + htons(remote_addr.sin_port)); /* Note: unlike the original iperf, this implementation * exits after finishing a single connection. */ - ctrl->finish = true; + s_iperf_ctrl.finish = true; break; } else if (actual_recv < 0) { iperf_show_socket_error_reason("tcp server recv", listen_socket); - ctrl->finish = true; + s_iperf_ctrl.finish = true; break; } else { - ctrl->total_len += actual_recv; + s_iperf_ctrl.total_len += actual_recv; } } close(sockfd); } - ctrl->finish = true; + s_iperf_ctrl.finish = true; close(listen_socket); return 0; } -/**************************************************************************** - * Name: iperf_run_tcp_server - * - * Description: - * Start tcp server - * - ****************************************************************************/ - -static int iperf_run_tcp_server(FAR struct iperf_ctrl_t *ctrl) -{ - return iperf_run_server(ctrl, iperf_tcp_server); -} - -/**************************************************************************** - * Name: iperf_udp_server - * - * Description: - * The main udp server logic - * - ****************************************************************************/ - -static int iperf_udp_server(FAR struct iperf_ctrl_t *ctrl, - FAR struct sockaddr *addr, socklen_t addrlen, - FAR struct sockaddr *remote_addr) -{ - int actual_recv = 0; - struct timeval t; - int want_recv = 0; - FAR uint8_t *buffer; - int sockfd; - int opt; - bool udp_recv_start = true; - - sockfd = socket(addr->sa_family, SOCK_DGRAM, IPPROTO_UDP); - if (sockfd < 0) - { - iperf_show_socket_error_reason("udp server create", sockfd); - return -1; - } - - setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)); - - if (bind(sockfd, addr, addrlen) != 0) - { - iperf_show_socket_error_reason("udp server bind", sockfd); - return -1; - } - - buffer = ctrl->buffer; - want_recv = ctrl->buffer_len; - printf("want recv=%d\n", want_recv); - - t.tv_sec = IPERF_SOCKET_RX_TIMEOUT; - t.tv_usec = 0; - setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &t, sizeof(t)); - - while (!ctrl->finish) - { - actual_recv = recvfrom(sockfd, buffer, want_recv, 0, - remote_addr, &addrlen); - if (actual_recv < 0) - { - iperf_show_socket_error_reason("udp server recv", sockfd); - } - else - { - if (udp_recv_start == true) - { - iperf_print_addr("accept", remote_addr); - iperf_start_report(ctrl); - udp_recv_start = false; - } - - ctrl->total_len += actual_recv; - } - } - - ctrl->finish = true; - close(sockfd); - - return 0; -} - /**************************************************************************** * Name: iperf_run_udp_server * @@ -668,23 +437,85 @@ static int iperf_udp_server(FAR struct iperf_ctrl_t *ctrl, * ****************************************************************************/ -static int iperf_run_udp_server(FAR struct iperf_ctrl_t *ctrl) +static int iperf_run_udp_server(void) { - return iperf_run_server(ctrl, iperf_udp_server); + socklen_t addr_len = sizeof(struct sockaddr_in); + struct sockaddr_in addr; + int actual_recv = 0; + struct timeval t; + int want_recv = 0; + uint8_t *buffer; + int sockfd; + int opt; + bool udp_recv_start = true; + + sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); + if (sockfd < 0) + { + iperf_show_socket_error_reason("udp server create", sockfd); + return -1; + } + + setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)); + + addr.sin_family = AF_INET; + addr.sin_port = htons(s_iperf_ctrl.cfg.sport); + addr.sin_addr.s_addr = s_iperf_ctrl.cfg.sip; + if (bind(sockfd, (struct sockaddr *)&addr, sizeof(addr)) != 0) + { + iperf_show_socket_error_reason("udp server bind", sockfd); + return -1; + } + + addr.sin_family = AF_INET; + addr.sin_port = htons(s_iperf_ctrl.cfg.sport); + addr.sin_addr.s_addr = s_iperf_ctrl.cfg.sip; + + buffer = s_iperf_ctrl.buffer; + want_recv = s_iperf_ctrl.buffer_len; + printf("want recv=%d", want_recv); + + t.tv_sec = IPERF_SOCKET_RX_TIMEOUT; + setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &t, sizeof(t)); + + while (!s_iperf_ctrl.finish) + { + actual_recv = recvfrom(sockfd, buffer, want_recv, 0, + (struct sockaddr *)&addr, &addr_len); + if (actual_recv < 0) + { + iperf_show_socket_error_reason("udp server recv", sockfd); + } + else + { + if (udp_recv_start == true) + { + iperf_start_report(); + udp_recv_start = false; + } + + s_iperf_ctrl.total_len += actual_recv; + } + } + + s_iperf_ctrl.finish = true; + close(sockfd); + + return 0; } /**************************************************************************** - * Name: iperf_udp_client + * Name: iperf_run_udp_client * * Description: - * The main udp client logic + * Start udp client * ****************************************************************************/ -static int iperf_udp_client(FAR struct iperf_ctrl_t *ctrl, - FAR struct sockaddr *addr, socklen_t addrlen) +static int iperf_run_udp_client(void) { - FAR struct iperf_udp_pkt_t *udp; + struct sockaddr_in addr; + struct iperf_udp_pkt_t *udp; int actual_send = 0; bool retry = false; uint32_t delay = 1; @@ -695,7 +526,7 @@ static int iperf_udp_client(FAR struct iperf_ctrl_t *ctrl, int err; int id; - sockfd = socket(addr->sa_family, SOCK_DGRAM, IPPROTO_UDP); + sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); if (sockfd < 0) { iperf_show_socket_error_reason("udp client create", sockfd); @@ -704,13 +535,17 @@ static int iperf_udp_client(FAR struct iperf_ctrl_t *ctrl, setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)); - iperf_start_report(ctrl); - buffer = ctrl->buffer; - udp = (FAR struct iperf_udp_pkt_t *)buffer; - want_send = ctrl->buffer_len; + addr.sin_family = AF_INET; + addr.sin_port = htons(s_iperf_ctrl.cfg.dport); + addr.sin_addr.s_addr = s_iperf_ctrl.cfg.dip; + + iperf_start_report(); + buffer = s_iperf_ctrl.buffer; + udp = (struct iperf_udp_pkt_t *)buffer; + want_send = s_iperf_ctrl.buffer_len; id = 0; - while (!ctrl->finish) + while (!s_iperf_ctrl.finish) { if (false == retry) { @@ -720,7 +555,8 @@ static int iperf_udp_client(FAR struct iperf_ctrl_t *ctrl, } retry = false; - actual_send = sendto(sockfd, buffer, want_send, 0, addr, addrlen); + actual_send = sendto(sockfd, buffer, want_send, 0, + (struct sockaddr *)&addr, sizeof(addr)); if (actual_send != want_send) { @@ -738,83 +574,17 @@ static int iperf_udp_client(FAR struct iperf_ctrl_t *ctrl, } else { - printf("udp client send abort: err=%d\n", err); + printf("udp client send abort: err=%d", err); break; } } else { - ctrl->total_len += actual_send; + s_iperf_ctrl.total_len += actual_send; } } - ctrl->finish = true; - close(sockfd); - - return 0; -} - -/**************************************************************************** - * Name: iperf_run_udp_client - * - * Description: - * Start udp client - * - ****************************************************************************/ - -static int iperf_run_udp_client(FAR struct iperf_ctrl_t *ctrl) -{ - return iperf_run_client(ctrl, iperf_udp_client); -} - -/**************************************************************************** - * Name: iperf_tcp_client - * - * Description: - * The main tcp client logic - * - ****************************************************************************/ - -static int iperf_tcp_client(FAR struct iperf_ctrl_t *ctrl, - FAR struct sockaddr *addr, socklen_t addrlen) -{ - FAR uint8_t *buffer; - int actual_send = 0; - int want_send = 0; - int sockfd; - - sockfd = socket(addr->sa_family, SOCK_STREAM, IPPROTO_TCP); - if (sockfd < 0) - { - iperf_show_socket_error_reason("tcp client create", sockfd); - return -1; - } - - if (connect(sockfd, addr, addrlen) < 0) - { - iperf_show_socket_error_reason("tcp client connect", sockfd); - return -1; - } - - iperf_start_report(ctrl); - buffer = ctrl->buffer; - want_send = ctrl->buffer_len; - - while (!ctrl->finish) - { - actual_send = send(sockfd, buffer, want_send, 0); - if (actual_send <= 0) - { - iperf_show_socket_error_reason("tcp client send", sockfd); - break; - } - else - { - ctrl->total_len += actual_send; - } - } - - ctrl->finish = true; + s_iperf_ctrl.finish = true; close(sockfd); return 0; @@ -828,9 +598,54 @@ static int iperf_tcp_client(FAR struct iperf_ctrl_t *ctrl, * ****************************************************************************/ -static int iperf_run_tcp_client(FAR struct iperf_ctrl_t *ctrl) +static int iperf_run_tcp_client(void) { - return iperf_run_client(ctrl, iperf_tcp_client); + struct sockaddr_in remote_addr; + int actual_send = 0; + int want_send = 0; + uint8_t *buffer; + int sockfd; + + sockfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); + if (sockfd < 0) + { + iperf_show_socket_error_reason("tcp client create", sockfd); + return -1; + } + + memset(&remote_addr, 0, sizeof(remote_addr)); + remote_addr.sin_family = AF_INET; + remote_addr.sin_port = htons(s_iperf_ctrl.cfg.dport); + remote_addr.sin_addr.s_addr = s_iperf_ctrl.cfg.dip; + if (connect(sockfd, (struct sockaddr *)&remote_addr, + sizeof(remote_addr)) < 0) + { + iperf_show_socket_error_reason("tcp client connect", sockfd); + return -1; + } + + iperf_start_report(); + buffer = s_iperf_ctrl.buffer; + want_send = s_iperf_ctrl.buffer_len; + + while (!s_iperf_ctrl.finish) + { + actual_send = send(sockfd, buffer, want_send, 0); + if (actual_send <= 0) + { + iperf_show_socket_error_reason("tcp client send", sockfd); + break; + } + else + { + s_iperf_ctrl.total_len += actual_send; + } + } + + s_iperf_ctrl.finish = true; + close(sockfd); + + return 0; } /**************************************************************************** @@ -841,27 +656,23 @@ static int iperf_run_tcp_client(FAR struct iperf_ctrl_t *ctrl) * ****************************************************************************/ -static void iperf_task_traffic(FAR void *arg) +static void iperf_task_traffic(void *arg) { - FAR struct iperf_ctrl_t *ctrl = arg; - - prctl(PR_SET_NAME, IPERF_TRAFFIC_TASK_NAME); - - if (iperf_is_udp_client(ctrl)) + if (iperf_is_udp_client()) { - iperf_run_udp_client(ctrl); + iperf_run_udp_client(); } - else if (iperf_is_udp_server(ctrl)) + else if (iperf_is_udp_server()) { - iperf_run_udp_server(ctrl); + iperf_run_udp_server(); } - else if (iperf_is_tcp_client(ctrl)) + else if (iperf_is_tcp_client()) { - iperf_run_tcp_client(ctrl); + iperf_run_tcp_client(); } - else if (iperf_is_tcp_server(ctrl)) + else if (iperf_is_tcp_server()) { - iperf_run_tcp_server(ctrl); + iperf_run_tcp_server(); } else { @@ -870,28 +681,29 @@ static void iperf_task_traffic(FAR void *arg) assert(false); } - if (ctrl->buffer) + if (s_iperf_ctrl.buffer) { - free(ctrl->buffer); - ctrl->buffer = NULL; + free(s_iperf_ctrl.buffer); + s_iperf_ctrl.buffer = NULL; } - printf("iperf exit\n"); + printf("iperf exit"); + s_iperf_is_running = false; pthread_exit(NULL); } -static uint32_t iperf_get_buffer_len(FAR struct iperf_ctrl_t *ctrl) +static uint32_t iperf_get_buffer_len(void) { - if (iperf_is_udp_client(ctrl)) + if (iperf_is_udp_client()) { return IPERF_UDP_TX_LEN; } - else if (iperf_is_udp_server(ctrl)) + else if (iperf_is_udp_server()) { return IPERF_UDP_RX_LEN; } - else if (iperf_is_tcp_client(ctrl)) + else if (iperf_is_tcp_client()) { return IPERF_TCP_TX_LEN; } @@ -915,57 +727,54 @@ static uint32_t iperf_get_buffer_len(FAR struct iperf_ctrl_t *ctrl) * ****************************************************************************/ -int iperf_start(FAR struct iperf_cfg_t *cfg) +int iperf_start(struct iperf_cfg_t *cfg) { - struct iperf_ctrl_t ctrl; - struct sched_param param; - pthread_attr_t attr; - pthread_t thread; - FAR void *retval; int ret; + void *retval; + struct sched_param param; + pthread_t thread; + pthread_attr_t attr; if (!cfg) { return -1; } - memset(&ctrl, 0, sizeof(ctrl)); - memcpy(&ctrl.cfg, cfg, sizeof(*cfg)); - ctrl.finish = false; - ctrl.buffer_len = iperf_get_buffer_len(&ctrl); - ctrl.buffer = (FAR uint8_t *)malloc(ctrl.buffer_len); - if (ctrl.buffer == NULL) + if (s_iperf_is_running) + { + printf("iperf is running\n"); + return -1; + } + + memset(&s_iperf_ctrl, 0, sizeof(s_iperf_ctrl)); + memcpy(&s_iperf_ctrl.cfg, cfg, sizeof(*cfg)); + s_iperf_is_running = true; + s_iperf_ctrl.finish = false; + s_iperf_ctrl.buffer_len = iperf_get_buffer_len(); + s_iperf_ctrl.buffer = (uint8_t *)malloc(s_iperf_ctrl.buffer_len); + if (!s_iperf_ctrl.buffer) { printf("create buffer: not enough memory\n"); return -1; } - memset(ctrl.buffer, 0, ctrl.buffer_len); + memset(s_iperf_ctrl.buffer, 0, s_iperf_ctrl.buffer_len); pthread_attr_init(&attr); param.sched_priority = IPERF_TRAFFIC_TASK_PRIORITY; pthread_attr_setschedparam(&attr, ¶m); pthread_attr_setstacksize(&attr, IPERF_TRAFFIC_TASK_STACK); - ret = pthread_create(&thread, &attr, (FAR void *)iperf_task_traffic, - &ctrl); + ret = pthread_create(&thread, &attr, (void *)iperf_task_traffic, + IPERF_TRAFFIC_TASK_NAME); if (ret != 0) { printf("iperf_task_traffic: create task failed: %d\n", ret); - free(ctrl.buffer); - ctrl.buffer = NULL; + free(s_iperf_ctrl.buffer); + s_iperf_ctrl.buffer = NULL; return -1; } - pthread_mutex_lock(&g_iperf_ctrl_mutex); - sq_addlast((FAR sq_entry_t *)&ctrl, &g_iperf_ctrl_list); - pthread_mutex_unlock(&g_iperf_ctrl_mutex); - pthread_join(thread, &retval); - - pthread_mutex_lock(&g_iperf_ctrl_mutex); - sq_rem((FAR sq_entry_t *)&ctrl, &g_iperf_ctrl_list); - pthread_mutex_unlock(&g_iperf_ctrl_mutex); - return 0; } @@ -979,20 +788,16 @@ int iperf_start(FAR struct iperf_cfg_t *cfg) int iperf_stop(void) { - FAR struct iperf_ctrl_t *ctrl; - FAR sq_entry_t *tmp; - FAR sq_entry_t *p; - - pthread_mutex_lock(&g_iperf_ctrl_mutex); - - sq_for_every_safe(&g_iperf_ctrl_list, p, tmp) + if (s_iperf_is_running) { - ctrl = (FAR struct iperf_ctrl_t *)p; - ctrl->finish = true; - sq_rem(p, &g_iperf_ctrl_list); + s_iperf_ctrl.finish = true; } - pthread_mutex_unlock(&g_iperf_ctrl_mutex); + while (s_iperf_is_running) + { + printf("wait current iperf to stop ...\n"); + usleep(300 * 1000); + } return 0; } diff --git a/netutils/iperf/iperf.h b/netutils/iperf/iperf.h index 86739cd5f..f4e56da06 100644 --- a/netutils/iperf/iperf.h +++ b/netutils/iperf/iperf.h @@ -1,8 +1,6 @@ /**************************************************************************** * apps/netutils/iperf/iperf.h * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -46,12 +44,10 @@ extern "C" * Pre-processor Definitions ****************************************************************************/ -#define IPERF_FLAG_CLIENT (1 << 0) +#define IPERF_FLAG_CLIENT (1) #define IPERF_FLAG_SERVER (1 << 1) -#define IPERF_FLAG_TCP (1 << 2) -#define IPERF_FLAG_UDP (1 << 3) -#define IPERF_FLAG_LOCAL (1 << 4) -#define IPERF_FLAG_RPMSG (1 << 5) +#define IPERF_FLAG_TCP (1 << 2) +#define IPERF_FLAG_UDP (1 << 3) /**************************************************************************** * Public Types @@ -66,8 +62,6 @@ struct iperf_cfg_t uint16_t sport; uint32_t interval; uint32_t time; - FAR const char *host; /* host name (dip) or rpmsg cpu */ - FAR const char *path; /* local path or rpmsg name */ }; /**************************************************************************** @@ -82,7 +76,7 @@ struct iperf_cfg_t * ****************************************************************************/ -int iperf_start(FAR struct iperf_cfg_t *cfg); +int iperf_start(struct iperf_cfg_t *cfg); /**************************************************************************** * Name: iperf_stop diff --git a/netutils/iperf/iperf_main.c b/netutils/iperf/iperf_main.c index b87a122bc..cfbffbc1c 100644 --- a/netutils/iperf/iperf_main.c +++ b/netutils/iperf/iperf_main.c @@ -1,8 +1,6 @@ /**************************************************************************** * apps/netutils/iperf/iperf_main.c * - * SPDX-License-Identifier: Apache-2.0 - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The @@ -25,15 +23,12 @@ ****************************************************************************/ #include - +#include #include #include -#include -#include - +#include "netutils/netlib.h" #include "argtable3.h" #include "iperf.h" -#include "netutils/netlib.h" /**************************************************************************** * Pre-processor Definitions @@ -55,17 +50,14 @@ struct wifi_iperf_t { - FAR struct arg_str *ip; - FAR struct arg_lit *server; - FAR struct arg_lit *udp; - FAR struct arg_str *local; - FAR struct arg_str *rpmsg; - FAR struct arg_str *bind; - FAR struct arg_int *port; - FAR struct arg_int *interval; - FAR struct arg_int *time; - FAR struct arg_lit *abort; - FAR struct arg_end *end; + struct arg_str *ip; + struct arg_lit *server; + struct arg_lit *udp; + struct arg_int *port; + struct arg_int *interval; + struct arg_int *time; + struct arg_lit *abort; + struct arg_end *end; }; /**************************************************************************** @@ -80,56 +72,25 @@ struct wifi_iperf_t * ****************************************************************************/ -static void iperf_showusage(FAR const char *progname, - FAR struct wifi_iperf_t *args, int exitcode) +static void iperf_showusage(FAR const char *progname, int exitcode) { - printf("USAGE: %s [-sua] [-c ] [-p ] [-i ] " - "[-t